Skip to content

Commit

Permalink
chore: add endpoint labels (#2944)
Browse files Browse the repository at this point in the history
* chore: add endpoint labelsx1

* chore: add endpoint labelsx2

* Update src/v0/destinations/active_campaign/transform.js

Co-authored-by: Sudip Paul <[email protected]>

* Update src/v0/destinations/active_campaign/transform.js

Co-authored-by: Sankeerth <[email protected]>

* chore: fix monday path

---------

Co-authored-by: Sudip Paul <[email protected]>
Co-authored-by: Sankeerth <[email protected]>
  • Loading branch information
3 people authored Jan 3, 2024
1 parent 48e4036 commit 8a245a2
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/v0/destinations/active_campaign/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ const responseBuilderSimple = (payload, category, destination) => {
};

const syncContact = async (contactPayload, category, destination) => {
const endpoint = `${destination.Config.apiUrl}${category.endPoint}`;
const { endPoint } = category;
const endpoint = `${destination.Config.apiUrl}${endPoint}`;
const requestData = {
contact: contactPayload,
};
Expand All @@ -60,6 +61,7 @@ const syncContact = async (contactPayload, category, destination) => {
const res = await httpPOST(endpoint, requestData, requestOptions, {
destType: 'active_campaign',
feature: 'transformation',
endpointPath: endPoint,
});
if (res.success === false) {
errorHandler(res, 'Failed to create new contact');
Expand All @@ -78,6 +80,7 @@ const customTagProcessor = async (message, category, destination, contactId) =>
let endpoint;
let requestOptions;
let requestData;
const { tagEndPoint, mergeTagWithContactUrl } = category;
// Here we extract the tags which are to be mapped to the created contact from the message
const msgTags = get(message?.context?.traits, 'tags') || get(message?.traits, 'tags');

Expand All @@ -89,13 +92,14 @@ const customTagProcessor = async (message, category, destination, contactId) =>
// Step - 1
// Fetch already created tags from dest, so that we avoid duplicate tag creation request
// Ref - https://developers.activecampaign.com/reference/retrieve-all-tags
endpoint = `${destination.Config.apiUrl}${`${category.tagEndPoint}?limit=100`}`;
endpoint = `${destination.Config.apiUrl}${`${tagEndPoint}?limit=100`}`;
requestOptions = {
headers: getHeader(destination),
};
res = await httpGET(endpoint, requestOptions, {
destType: 'active_campaign',
feature: 'transformation',
tagEndPoint,
});
if (res.success === false) {
errorHandler(res, 'Failed to fetch already created tags');
Expand All @@ -117,9 +121,7 @@ const customTagProcessor = async (message, category, destination, contactId) =>
if (parseInt(get(res, TOTAL_RECORDS_KEY), 10) > 100) {
const limit = Math.floor(parseInt(get(res, TOTAL_RECORDS_KEY), 10) / 100);
for (let i = 0; i < limit; i += 1) {
endpoint = `${destination.Config.apiUrl}${category.tagEndPoint}?limit=100&offset=${
100 * (i + 1)
}`;
endpoint = `${destination.Config.apiUrl}${tagEndPoint}?limit=100&offset=${100 * (i + 1)}`;
requestOptions = {
headers: getHeader(destination),
};
Expand Down Expand Up @@ -153,7 +155,7 @@ const customTagProcessor = async (message, category, destination, contactId) =>
if (tagsToBeCreated.length > 0) {
await Promise.all(
tagsToBeCreated.map(async (tag) => {
endpoint = `${destination.Config.apiUrl}${category.tagEndPoint}`;
endpoint = `${destination.Config.apiUrl}${tagEndPoint}`;
requestData = {
tag: {
tag,
Expand Down Expand Up @@ -182,7 +184,7 @@ const customTagProcessor = async (message, category, destination, contactId) =>
// Ref - https://developers.activecampaign.com/reference/create-contact-tag
const responsesArr = await Promise.all(
tagIds.map(async (tagId) => {
endpoint = `${destination.Config.apiUrl}${category.mergeTagWithContactUrl}`;
endpoint = `${destination.Config.apiUrl}${mergeTagWithContactUrl}`;
requestData = {
contactTag: {
contact: contactId,
Expand All @@ -207,6 +209,7 @@ const customTagProcessor = async (message, category, destination, contactId) =>

const customFieldProcessor = async (message, category, destination) => {
const responseStaging = [];
const { fieldEndPoint } = category;
// Step - 1
// Extract the custom field info from the message
const fieldInfo = get(message?.context?.traits, 'fieldInfo') || get(message.traits, 'fieldInfo');
Expand All @@ -219,7 +222,7 @@ const customFieldProcessor = async (message, category, destination) => {
// Step - 2
// Get the existing field data from dest and store it in responseStaging
// Ref - https://developers.activecampaign.com/reference/retrieve-fields
let endpoint = `${destination.Config.apiUrl}${category.fieldEndPoint}?limit=100`;
let endpoint = `${destination.Config.apiUrl}${fieldEndPoint}?limit=100`;
const requestOptions = {
headers: {
'Api-Token': destination.Config.apiKey,
Expand All @@ -228,6 +231,7 @@ const customFieldProcessor = async (message, category, destination) => {
const res = await httpGET(endpoint, requestOptions, {
destType: 'active_campaign',
feature: 'transformation',
fieldEndPoint,
});
if (res.success === false) {
errorHandler(res, 'Failed to get existing field data');
Expand All @@ -238,9 +242,7 @@ const customFieldProcessor = async (message, category, destination) => {
const limit = Math.floor(parseInt(get(res, TOTAL_RECORDS_KEY), 10) / 100);
if (parseInt(get(res, TOTAL_RECORDS_KEY), 10) > 100) {
for (let i = 0; i < limit; i += 1) {
endpoint = `${destination.Config.apiUrl}${category.fieldEndPoint}?limit=100&offset=${
100 * (i + 1)
}`;
endpoint = `${destination.Config.apiUrl}${fieldEndPoint}?limit=100&offset=${100 * (i + 1)}`;
const requestOpt = {
headers: {
'Api-Token': destination.Config.apiKey,
Expand Down Expand Up @@ -308,6 +310,7 @@ const customFieldProcessor = async (message, category, destination) => {
};

const customListProcessor = async (message, category, destination, contactId) => {
const { mergeListWithContactUrl } = category;
// Here we extract the list info from the message
const listInfo = get(message?.context?.traits, 'lists')
? get(message.context.traits, 'lists')
Expand All @@ -331,7 +334,7 @@ const customListProcessor = async (message, category, destination, contactId) =>
// eslint-disable-next-line no-restricted-syntax
for (const li of listArr) {
if (li.status === 'subscribe' || li.status === 'unsubscribe') {
const endpoint = `${destination.Config.apiUrl}${category.mergeListWithContactUrl}`;
const endpoint = `${destination.Config.apiUrl}${mergeListWithContactUrl}`;
const requestData = {
contactList: {
list: li.id,
Expand All @@ -345,6 +348,7 @@ const customListProcessor = async (message, category, destination, contactId) =>
const res = httpPOST(endpoint, requestData, requestOptions, {
destType: 'active_campaign',
feature: 'transformation',
endpointPath: mergeListWithContactUrl,
});
promises.push(res);
}
Expand Down
1 change: 1 addition & 0 deletions src/v0/destinations/af/deleteUsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const deleteUser = async (config, endpoint, body, identityType, identityValue) =
{
destType: 'af',
feature: 'deleteUsers',
endpointPath: `appsflyer.com/api/gdpr/v1/opendsr_requests`,
},
);
const handledDelResponse = processAxiosResponse(response);
Expand Down
2 changes: 2 additions & 0 deletions src/v0/destinations/am/deleteUsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const userDeletionHandler = async (userAttributes, config) => {
// Ref : https://www.docs.developers.amplitude.com/analytics/apis/user-privacy-api/#response
const batchEvents = getUserIdBatches(userAttributes, DELETE_MAX_BATCH_SIZE);
const url = 'https://amplitude.com/api/2/deletions/users';
const endpointPath = '/api/2/deletions/users';
await Promise.all(
batchEvents.map(async (batch) => {
const data = {
Expand All @@ -41,6 +42,7 @@ const userDeletionHandler = async (userAttributes, config) => {
const resp = await httpPOST(url, data, requestOptions, {
destType: 'am',
feature: 'deleteUsers',
endpointPath,
});
const handledDelResponse = processAxiosResponse(resp);
if (!isHttpStatusSuccess(handledDelResponse.status)) {
Expand Down
1 change: 1 addition & 0 deletions src/v0/destinations/ga/deleteUsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ const userDeletionHandler = async (userAttributes, config, rudderDestInfo) => {
{
destType: 'ga',
feature: 'deleteUsers',
endpointPath: '/userDeletion/userDeletionRequests:upsert',
},
);
// process the response to know about refreshing scenario
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const getConversionActionId = async (method, headers, params) => {
{
destType: 'google_adwords_enhanced_conversions',
feature: 'proxy',
endpointPath: `/googleAds:searchStream`,
},
);
if (!isHttpStatusSuccess(gaecConversionActionIdResponse.status)) {
Expand Down Expand Up @@ -96,6 +97,7 @@ const ProxyRequest = async (request) => {
const { httpResponse: response } = await handleHttpRequest('constructor', requestBody, {
destType: 'google_adwords_enhanced_conversions',
feature: 'proxy',
endpointPath: `/googleAds:uploadOfflineUserData`,
});
return response;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const createJob = async (endpoint, headers, payload) => {
{
destType: 'google_adwords_offline_conversions',
feature: 'proxy',
endpointPath: `/create`,
},
);
createJobResponse = processAxiosResponse(createJobResponse);
Expand All @@ -57,6 +58,7 @@ const addConversionToJob = async (endpoint, headers, jobId, payload) => {
{
destType: 'google_adwords_offline_conversions',
feature: 'proxy',
endpointPath: `/addOperations`,
},
);
addConversionToJobResponse = processAxiosResponse(addConversionToJobResponse);
Expand All @@ -80,6 +82,7 @@ const runTheJob = async (endpoint, headers, payload, jobId) => {
{
destType: 'google_adwords_offline_conversions',
feature: 'proxy',
endpointPath: `/run`,
},
);
return executeJobResponse;
Expand All @@ -106,6 +109,7 @@ const getConversionCustomVariable = async (headers, params) => {
let searchStreamResponse = await httpPOST(endpoint, data, requestOptions, {
destType: 'google_adwords_offline_conversions',
feature: 'proxy',
endpointPath: `/searchStream`,
});
searchStreamResponse = processAxiosResponse(searchStreamResponse);
if (!isHttpStatusSuccess(searchStreamResponse.status)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const getConversionActionId = async (headers, params) => {
let searchStreamResponse = await httpPOST(endpoint, data, requestOptions, {
destType: 'google_adwords_offline_conversions',
feature: 'transformation',
endpointPath: `/googleAds:searchStream`,
});
searchStreamResponse = processAxiosResponse(searchStreamResponse);
if (!isHttpStatusSuccess(searchStreamResponse.status)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const createJob = async (endpoint, customerId, listId, headers, method) => {
const response = await httpSend(jobCreatingRequest, {
destType: 'google_adwords_remarketing_lists',
feature: 'proxy',
endpointPath: '/customers/create',
});
return response;
};
Expand All @@ -57,6 +58,7 @@ const addUserToJob = async (endpoint, headers, method, jobId, body) => {
const response = await httpSend(secondRequest, {
destType: 'google_adwords_remarketing_lists',
feature: 'proxy',
endpointPath: '/addOperations',
});
return response;
};
Expand All @@ -78,6 +80,7 @@ const runTheJob = async (endpoint, headers, method, jobId) => {
const response = await httpSend(thirdRequest, {
destType: 'google_adwords_remarketing_lists',
feature: 'proxy',
endpointPath: '/run',
});
return response;
};
Expand Down
1 change: 1 addition & 0 deletions src/v0/destinations/intercom/deleteUsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const userDeletionHandler = async (userAttributes, config) => {
const resp = await httpPOST(url, data, requestOptions, {
destType: 'intercom',
feature: 'deleteUsers',
endpointPath: '/user_delete_requests',
});
const handledDelResponse = processAxiosResponse(resp);
if (!isHttpStatusSuccess(handledDelResponse.status) && handledDelResponse.status !== 404) {
Expand Down
1 change: 1 addition & 0 deletions src/v0/destinations/marketo/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ const sendPostRequest = async (url, data, options) => {
const clientResponse = await httpPOST(url, data, options, {
destType: 'marketo',
feature: 'transformation',
endpointPath: `/v1/leads`,
});
const processedResponse = processAxiosResponse(clientResponse);
return processedResponse;
Expand Down
1 change: 1 addition & 0 deletions src/v0/destinations/monday/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ const getBoardDetails = async (url, boardID, apiToken) => {
{
destType: 'monday',
feature: 'transformation',
endpointPath: '/v2',
},
);
const boardDetailsResponse = processAxiosResponse(clientResponse);
Expand Down

0 comments on commit 8a245a2

Please sign in to comment.