Skip to content

Commit

Permalink
chore: small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
anantjain45823 committed Sep 19, 2024
1 parent 51f92d4 commit da7d2f8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/v0/destinations/amazon_audience/config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const CREATE_USERS_URL = 'https://advertising-api.amazon.com/dp/records/hashed/';
const ASSOCIATE_USERS_URL = 'https://advertising-api.amazon.com/dp/records/hashed/';
const ASSOCIATE_USERS_URL = 'https://advertising-api.amazon.com/v2/dp/audience';
const MAX_PAYLOAD_SIZE_IN_BYTES = 4000000;
const DESTINATION = 'amazon_audience';
module.exports = { CREATE_USERS_URL, MAX_PAYLOAD_SIZE_IN_BYTES, ASSOCIATE_USERS_URL, DESTINATION };
53 changes: 34 additions & 19 deletions src/v0/destinations/amazon_audience/networkHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,32 +69,32 @@ const responseHandler = (responseParams) => {
};
};

const makeRequest = async (url, data, headers, metadata, method) => {
const { httpResponse } = await handleHttpRequest(
method,
url,
data,
{ headers },
{
destType: 'amazon_audience',
feature: 'proxy',
endpointPath: '/records/hashed',
requestMethod: 'POST',
module: 'dataDelivery',
metadata,
},
);
const makeRequest = async (url, data, headers, metadata, method, args) => {
const { httpResponse } = await handleHttpRequest(method, url, data, { headers }, args);
return httpResponse;
};

const amazonAudienceProxyRequest = async (request) => {
const { body, metadata } = request;
const { headers } = request;
const { JSON } = body;
const { createUsers, associateUsers } = JSON;
const { createUsers, associateUsers } = body.JSON;

// step 1: Create users
const firstResponse = await makeRequest(CREATE_USERS_URL, createUsers, headers, metadata, 'post');
const firstResponse = await makeRequest(
CREATE_USERS_URL,
createUsers,
headers,
metadata,
'post',
{
destType: 'amazon_audience',
feature: 'proxy',
requestMethod: 'POST',
module: 'dataDelivery',
endpointPath: '/records/hashed',
metadata,
},
);
// validate response success
if (!firstResponse.success && !isHttpStatusSuccess(firstResponse?.response?.status)) {
amazonAudienceRespHandler(
Expand All @@ -107,7 +107,22 @@ const amazonAudienceProxyRequest = async (request) => {
}
// we are returning above in case of failure because if first step is not executed then there is no sense of executing second step
// step2: Associate Users to Audience Id
return makeRequest(ASSOCIATE_USERS_URL, associateUsers, headers, metadata, 'patch');
const secondResponse = await makeRequest(
ASSOCIATE_USERS_URL,
associateUsers,
headers,
metadata,
'patch',
{
destType: 'amazon_audience',
feature: 'proxy',
requestMethod: 'PATCH',
module: 'dataDelivery',
endpointPath: '/v2/dp/audience',
metadata,
},
);
return secondResponse;
};
// eslint-disable-next-line @typescript-eslint/naming-convention
class networkHandler {
Expand Down
5 changes: 2 additions & 3 deletions test/integrations/destinations/amazon_audience/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,14 @@ export const networkCallsData = [
httpRes: {
data: {
requestId: 'dummy request id',
jobId: 'dummy job id',
},
status: 200,
},
},
{
description: 'successful step 2',
httpReq: {
url: 'https://advertising-api.amazon.com/dp/records/hashed/',
url: 'https://advertising-api.amazon.com/v2/dp/audience',
data: {
patches: [
{
Expand Down Expand Up @@ -69,7 +68,7 @@ export const networkCallsData = [
{
description: 'unsuccessful step 2',
httpReq: {
url: 'https://advertising-api.amazon.com/dp/records/hashed/',
url: 'https://advertising-api.amazon.com/v2/dp/audience',
data: {
patches: [
{
Expand Down

0 comments on commit da7d2f8

Please sign in to comment.