Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:rudderlabs/rudder-transformer in…
Browse files Browse the repository at this point in the history
…to chore.format-standard
  • Loading branch information
Sai Sankeerth committed Feb 26, 2024
2 parents 6418d7b + 41f4078 commit fe4fcea
Show file tree
Hide file tree
Showing 64 changed files with 571 additions and 45 deletions.
6 changes: 6 additions & 0 deletions src/adapters/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,24 @@ const fireHTTPStats = (clientResponse, startTime, statTags) => {
const destType = statTags.destType ? statTags.destType : '';
const feature = statTags.feature ? statTags.feature : '';
const endpointPath = statTags.endpointPath ? statTags.endpointPath : '';
const requestMethod = statTags.requestMethod ? statTags.requestMethod : '';
const module = statTags.module ? statTags.module : '';
const statusCode = clientResponse.success ? clientResponse.response.status : '';
stats.timing('outgoing_request_latency', startTime, {
feature,
destType,
endpointPath,
requestMethod,
module
});
stats.counter('outgoing_request_count', 1, {
feature,
destType,
endpointPath,
success: clientResponse.success,
statusCode,
requestMethod,
module
});
};

Expand Down
38 changes: 28 additions & 10 deletions src/cdk/v2/destinations/intercom/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,20 @@ const searchContact = async (message, destination) => {
const headers = getHeaders(destination);
const baseEndPoint = getBaseEndpoint(destination);
const endpoint = `${baseEndPoint}/${SEARCH_CONTACT_ENDPOINT}`;
const response = await httpPOST(endpoint, data, {
headers,
destType: 'intercom',
feature: 'transformation',
});
const response = await httpPOST(
endpoint,
data,
{
headers,
},
{
destType: 'intercom',
feature: 'transformation',
endpointPath: '/contacts/search',
requestMethod: 'POST',
module: 'router',
},
);
const processedUserResponse = processAxiosResponse(response);
if (isHttpStatusSuccess(processedUserResponse.status)) {
return processedUserResponse.response?.data.length > 0
Expand Down Expand Up @@ -280,11 +289,20 @@ const createOrUpdateCompany = async (payload, destination) => {
const finalPayload = JSON.stringify(removeUndefinedAndNullValues(payload));
const baseEndPoint = getBaseEndpoint(destination);
const endpoint = `${baseEndPoint}/${CREATE_OR_UPDATE_COMPANY_ENDPOINT}`;
const response = await httpPOST(endpoint, finalPayload, {
headers,
destType: 'intercom',
feature: 'transformation',
});
const response = await httpPOST(
endpoint,
finalPayload,
{
headers,
},
{
destType: 'intercom',
feature: 'transformation',
endpointPath: '/companies',
requestMethod: 'POST',
module: 'router',
},
);

const processedResponse = processAxiosResponse(response);
if (isHttpStatusSuccess(processedResponse.status)) {
Expand Down
6 changes: 4 additions & 2 deletions src/cdk/v2/destinations/reddit/procWorkflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,14 @@ steps:
- name: customFields
condition: $.outputs.prepareTrackPayload.eventType.tracking_type === "Purchase"
reference: "https://ads-api.reddit.com/docs/v2/#tag/Conversions/paths/~1api~1v2.0~1conversions~1events~1%7Baccount_id%7D/post"
template: |
const revenue_in_cents = .message.properties.revenue ? Math.round(Number(.message.properties.revenue)*100)
const customFields = .message.().({
"currency": .properties.currency,
"value_decimal": .properties.revenue !== undefined ? Number(.properties.revenue) : undefined,
"value_decimal": revenue_in_cents ? revenue_in_cents / 100,
"item_count": (Array.isArray(.properties.products) && .properties.products.length) || (.properties.itemCount && Number(.properties.itemCount)),
"value": .properties.revenue !== undefined ? Number(.properties.revenue)*100 : undefined,
"value": revenue_in_cents,
"conversion_id": .properties.conversionId || .messageId,
});
$.removeUndefinedAndNullValues(customFields)
Expand Down
4 changes: 2 additions & 2 deletions src/util/prometheus.js
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ class Prometheus {
name: 'outgoing_request_count',
help: 'Outgoing HTTP requests count',
type: 'counter',
labelNames: ['feature', 'destType', 'endpointPath', 'success', 'statusCode'],
labelNames: ['feature', 'destType', 'endpointPath', 'success', 'statusCode', 'requestMethod' , 'module'],
},

// Gauges
Expand Down Expand Up @@ -573,7 +573,7 @@ class Prometheus {
name: 'outgoing_request_latency',
help: 'Outgoing HTTP requests duration in seconds',
type: 'histogram',
labelNames: ['feature', 'destType', 'endpointPath'],
labelNames: ['feature', 'destType', 'endpointPath', 'requestMethod', 'module'],
},
{
name: 'http_request_duration',
Expand Down
12 changes: 12 additions & 0 deletions src/v0/destinations/active_campaign/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ const syncContact = async (contactPayload, category, destination) => {
destType: 'active_campaign',
feature: 'transformation',
endpointPath: endPoint,
requestMethod: 'POST',
module: 'router',
});
if (res.success === false) {
errorHandler(res, 'Failed to create new contact');
Expand Down Expand Up @@ -129,6 +131,8 @@ const customTagProcessor = async (message, category, destination, contactId) =>
destType: 'active_campaign',
feature: 'transformation',
endpointPath: `/api/3/tags`,
requestMethod: 'GET',
module: 'router',
});
promises.push(resp);
}
Expand Down Expand Up @@ -253,6 +257,8 @@ const customFieldProcessor = async (message, category, destination) => {
destType: 'active_campaign',
feature: 'transformation',
endpointPath: `/api/3/fields`,
requestMethod: 'GET',
module: 'router',
});
promises.push(resp);
}
Expand Down Expand Up @@ -351,6 +357,8 @@ const customListProcessor = async (message, category, destination, contactId) =>
destType: 'active_campaign',
feature: 'transformation',
endpointPath: mergeListWithContactUrl,
requestMethod: 'POST',
module: 'router',
});
promises.push(res);
}
Expand Down Expand Up @@ -409,6 +417,8 @@ const screenRequestHandler = async (message, category, destination) => {
destType: 'active_campaign',
feature: 'transformation',
endpointPath: `/api/3/eventTrackingEvents`,
requestMethod: 'GET',
module: 'router',
});
if (res.success === false) {
errorHandler(res, 'Failed to retrieve events');
Expand Down Expand Up @@ -473,6 +483,8 @@ const trackRequestHandler = async (message, category, destination) => {
destType: 'active_campaign',
feature: 'transformation',
endpointPath: `/api/3/eventTrackingEvents`,
requestMethod: 'GET',
module: 'router',
});

if (res.success === false) {
Expand Down
3 changes: 3 additions & 0 deletions src/v0/destinations/af/deleteUsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ const deleteUser = async (config, endpoint, body, identityType, identityValue) =
destType: 'af',
feature: 'deleteUsers',
endpointPath: `appsflyer.com/api/gdpr/v1/opendsr_requests`,
requestMethod: 'POST',
module: 'deletion',
},
);
const handledDelResponse = processAxiosResponse(response);
Expand All @@ -48,6 +50,7 @@ const deleteUser = async (config, endpoint, body, identityType, identityValue) =
handledDelResponse.status,
{
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(handledDelResponse.status),
[tags.TAG_NAMES.STATUS]: handledDelResponse.status,
},
handledDelResponse,
);
Expand Down
3 changes: 3 additions & 0 deletions src/v0/destinations/am/deleteUsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ const userDeletionHandler = async (userAttributes, config) => {
destType: 'am',
feature: 'deleteUsers',
endpointPath,
requestMethod: 'POST',
module: 'deletion',
});
const handledDelResponse = processAxiosResponse(resp);
if (!isHttpStatusSuccess(handledDelResponse.status)) {
Expand All @@ -51,6 +53,7 @@ const userDeletionHandler = async (userAttributes, config) => {
handledDelResponse.status,
{
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(handledDelResponse.status),
[tags.TAG_NAMES.STATUS]: handledDelResponse.status,
},
handledDelResponse,
);
Expand Down
9 changes: 8 additions & 1 deletion src/v0/destinations/braze/braze.util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,14 @@ describe('dedup utility tests', () => {
},
timeout: 10000,
},
{ destType: 'braze', feature: 'transformation' },
{
destType: 'braze',
feature: 'transformation',
endpointPath: '/users/export/ids',
feature: 'transformation',
module: 'router',
requestMethod: 'POST',
},
);
});

Expand Down
5 changes: 4 additions & 1 deletion src/v0/destinations/braze/deleteUsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const userDeletionHandler = async (userAttributes, config) => {
// Endpoints different for different data centers.
// DOC: https://www.braze.com/docs/user_guide/administrative/access_braze/braze_instances/
let endPoint;
const endpointPath = '/users/delete'; // TODO: to handle for destinations dynamically by extracting from endpoint
const endpointPath = '/users/delete';
const dataCenterArr = dataCenter.trim().split('-');
if (dataCenterArr[0].toLowerCase() === 'eu') {
endPoint = 'https://rest.fra-01.braze.eu/users/delete';
Expand All @@ -46,6 +46,8 @@ const userDeletionHandler = async (userAttributes, config) => {
destType: 'braze',
feature: 'deleteUsers',
endpointPath,
requestMethod: 'POST',
module: 'deletion',
});
const handledDelResponse = processAxiosResponse(resp);
if (!isHttpStatusSuccess(handledDelResponse.status) && handledDelResponse.status !== 404) {
Expand All @@ -54,6 +56,7 @@ const userDeletionHandler = async (userAttributes, config) => {
handledDelResponse.status,
{
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(handledDelResponse.status),
[tags.TAG_NAMES.STATUS]: handledDelResponse.status,
},
handledDelResponse,
);
Expand Down
3 changes: 3 additions & 0 deletions src/v0/destinations/braze/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ async function processIdentify(message, destination) {
{
destType: 'braze',
feature: 'transformation',
requestMethod: 'POST',
module: 'router',
endpointPath: '/users/identify',
},
);
if (!isHttpStatusSuccess(brazeIdentifyResp.status)) {
Expand Down
3 changes: 3 additions & 0 deletions src/v0/destinations/braze/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ const BrazeDedupUtility = {
{
destType: 'braze',
feature: 'transformation',
requestMethod: 'POST',
module: 'router',
endpointPath: '/users/export/ids',
},
);
stats.counter('braze_lookup_failure_count', 1, {
Expand Down
2 changes: 2 additions & 0 deletions src/v0/destinations/canny/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ const retrieveUserId = async (apiKey, message) => {
destType: 'canny',
feature: 'transformation',
endpointPath: `/v1/users/retrieve`,
requestMethod: 'POST',
module: 'processor',
},
);
logger.debug(response);
Expand Down
3 changes: 3 additions & 0 deletions src/v0/destinations/clevertap/deleteUsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ const userDeletionHandler = async (userAttributes, config) => {
destType: 'clevertap',
feature: 'deleteUsers',
endpointPath,
requestMethod: 'POST',
module: 'deletion',
},
);
const handledDelResponse = processAxiosResponse(deletionResponse);
Expand All @@ -62,6 +64,7 @@ const userDeletionHandler = async (userAttributes, config) => {
handledDelResponse.status,
{
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(handledDelResponse.status),
[tags.TAG_NAMES.STATUS]: handledDelResponse.status,
},
handledDelResponse,
);
Expand Down
9 changes: 7 additions & 2 deletions src/v0/destinations/clevertap/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,21 @@ const responseWrapper = (payload, destination) => {
}
*
}
* This function stringify the payload attributes if it's an array or objects.
* This function stringify the payload attributes if it's an array or objects. The keys that are not stringified are present in the `stringifyExcludeList` array.
* @param {*} payload
* @returns
* return the final payload after converting to the relevant data-types.
*/
const convertObjectAndArrayToString = (payload, event) => {
const finalPayload = {};
const stringifyExcludeList = ['category-unsubscribe', 'category-resubscribe'];
if (payload) {
Object.keys(payload).forEach((key) => {
if (payload[key] && (Array.isArray(payload[key]) || typeof payload[key] === 'object')) {
if (
payload[key] &&
(Array.isArray(payload[key]) || typeof payload[key] === 'object') &&
!stringifyExcludeList.includes(key)
) {
finalPayload[key] = JSON.stringify(payload[key]);
} else {
finalPayload[key] = payload[key];
Expand Down
3 changes: 3 additions & 0 deletions src/v0/destinations/clickup/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ const retrieveCustomFields = async (listId, apiToken) => {
const customFieldsResponse = await httpGET(endpoint, requestOptions, {
destType: 'clickup',
feature: 'transformation',
endpointPath: '/list/listId/field',
requestMethod: 'GET',
module: 'router',
});
const processedCustomFieldsResponse = processAxiosResponse(customFieldsResponse);

Expand Down
3 changes: 3 additions & 0 deletions src/v0/destinations/custify/deleteUsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ const userDeletionHandler = async (userAttributes, config) => {
const deletionResponse = await httpDELETE(requestUrl, requestOptions, {
destType: 'custify',
feature: 'deleteUsers',
requestMethod: 'DELETE',
endpointPath: '/people',
module: 'deletion',
});
const processedDeletionRequest = processAxiosResponse(deletionResponse);
if (processedDeletionRequest.status !== 200 && processedDeletionRequest.status !== 404) {
Expand Down
2 changes: 2 additions & 0 deletions src/v0/destinations/custify/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ const createUpdateCompany = async (companyPayload, Config) => {
destType: 'custify',
feature: 'transformation',
endpointPath: `/company`,
requestMethod: 'POST',
module: 'router',
},
);
const processedCompanyResponse = processAxiosResponse(companyResponse);
Expand Down
8 changes: 7 additions & 1 deletion src/v0/destinations/delighted/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,13 @@ const userValidity = async (channel, Config, userId) => {
},
params: paramsdata,
},
{ destType: 'delighted', feature: 'transformation' },
{
destType: 'delighted',
feature: 'transformation',
requestMethod: 'GET',
endpointPath: '/people.json',
module: 'router',
},
);
if (response && response.data && response.status === 200 && Array.isArray(response.data)) {
return response.data.length > 0;
Expand Down
16 changes: 14 additions & 2 deletions src/v0/destinations/drip/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ const userExists = async (Config, id) => {
'Content-Type': JSON_MIME_TYPE,
},
},
{ destType: 'drip', feature: 'transformation' },
{
destType: 'drip',
feature: 'transformation',
requestMethod: 'GET',
endpointPath: '/subscribers/id',
module: 'router',
},
);
if (response && response.status) {
return response.status === 200;
Expand Down Expand Up @@ -70,7 +76,13 @@ const createUpdateUser = async (finalpayload, Config, basicAuth) => {
'Content-Type': JSON_MIME_TYPE,
},
},
{ destType: 'drip', feature: 'transformation' },
{
destType: 'drip',
feature: 'transformation',
requestMethod: 'POST',
endpointPath: '/subscribers',
module: 'router',
},
);
if (response) {
return response.status === 200 || response.status === 201;
Expand Down
Loading

0 comments on commit fe4fcea

Please sign in to comment.