Skip to content

Commit

Permalink
Merge branch 'develop' into fix.pinterest_tag_single_product
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsSudip authored Oct 24, 2024
2 parents f781a84 + 8f18e1a commit 31a963f
Show file tree
Hide file tree
Showing 7 changed files with 633 additions and 19 deletions.
20 changes: 7 additions & 13 deletions src/cdk/v2/destinations/zapier/procWorkflow.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
bindings:
- name: EventType
path: ../../../../constants
- name: getHashFromArray
- name: getHashFromArrayWithDuplicate
path: ../../../../v0/util/index
- name: defaultRequestConfig
path: ../../../../v0/util
- path: ./utils

steps:
- name: validateInput
Expand All @@ -15,18 +14,18 @@ steps:
- name: prepareContext
template: |
$.context.messageType = .message.type.toLowerCase();
$.context.endpoint = .destination.Config.zapUrl;
$.context.endpoint = [.destination.Config.zapUrl];
- name: trackEndpoint
condition: $.context.messageType === {{$.EventType.TRACK}}
template: |
const trackEventsMap = $.getHashFromArray(.destination.Config.trackEventsToZap);
const trackEventsMap = $.getHashFromArrayWithDuplicate(.destination.Config.trackEventsToZap);
const eventName = .message.event.toLowerCase();
(eventName && trackEventsMap[eventName]) ?
($.context.endpoint = trackEventsMap[eventName])
else:
name: endpointForOthers
template: |
const pageScreenEventsMap = $.getHashFromArray(.destination.Config.pageScreenEventsToZap);
const pageScreenEventsMap = $.getHashFromArrayWithDuplicate(.destination.Config.pageScreenEventsToZap);
const pageName = .message.name.toLowerCase();
(pageName && pageScreenEventsMap[pageName]) ?
($.context.endpoint = pageScreenEventsMap[pageName])
Expand All @@ -37,10 +36,5 @@ steps:
else:
name: buildResponseForProcessTransformation
template: |
const response = $.defaultRequestConfig();
response.body.JSON = .message;
response.endpoint = $.context.endpoint;
response.headers = {
"content-type": "application/json"
};
response
const responseList = $.buildResponseList(.message, $.context.endpoint)
responseList
15 changes: 15 additions & 0 deletions src/cdk/v2/destinations/zapier/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const { defaultRequestConfig } = require('../../../../v0/util');

const buildResponseList = (payload, endpointList) => {
const responseList = [];
endpointList.forEach((endpoint) => {
const response = defaultRequestConfig();
response.body.JSON = payload;
response.endpoint = endpoint;
response.headers = { 'content-type': 'application/json' };
responseList.push(response);
});
return responseList;
};

module.exports = { buildResponseList };
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* eslint-disable no-param-reassign */

const get = require('get-value');
const { cloneDeep } = require('lodash');
const { cloneDeep, isNumber } = require('lodash');
const { InstrumentationError, ConfigurationError } = require('@rudderstack/integrations-lib');
const isString = require('lodash/isString');
const {
constructPayload,
defaultRequestConfig,
Expand Down Expand Up @@ -35,7 +36,18 @@ const updateMappingJson = (mapping) => {
const responseBuilder = async (metadata, message, { Config }, payload) => {
const response = defaultRequestConfig();
const { event } = message;
const filteredCustomerId = removeHyphens(Config.customerId);
const { subAccount } = Config;
let { customerId, loginCustomerId } = Config;
if (isNumber(customerId)) {
customerId = customerId.toString();
}
if (isNumber(loginCustomerId)) {
loginCustomerId = loginCustomerId.toString();
}
if (!isString(customerId) || !isString(loginCustomerId)) {
throw new InstrumentationError('customerId and loginCustomerId should be a string or number');
}
const filteredCustomerId = removeHyphens(customerId);
response.endpoint = `${BASE_ENDPOINT}/${filteredCustomerId}:uploadConversionAdjustments`;
response.body.JSON = payload;
const accessToken = getAccessToken(metadata, 'access_token');
Expand All @@ -45,9 +57,9 @@ const responseBuilder = async (metadata, message, { Config }, payload) => {
'developer-token': getValueFromMessage(metadata, 'secret.developer_token'),
};
response.params = { event, customerId: filteredCustomerId };
if (Config.subAccount)
if (Config.loginCustomerId) {
const filteredLoginCustomerId = removeHyphens(Config.loginCustomerId);
if (subAccount)
if (loginCustomerId) {
const filteredLoginCustomerId = removeHyphens(loginCustomerId);
response.headers['login-customer-id'] = filteredLoginCustomerId;
} else throw new ConfigurationError(`LoginCustomerId is required as subAccount is true.`);

Expand Down
6 changes: 5 additions & 1 deletion src/v0/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const {
} = require('@rudderstack/integrations-lib');

const { JsonTemplateEngine, PathType } = require('@rudderstack/json-template-engine');
const isString = require('lodash/isString');
const logger = require('../../logger');
const stats = require('../../util/stats');
const { DestCanonicalNames, DestHandlerMap } = require('../../constants/destinationCanonicalNames');
Expand Down Expand Up @@ -1622,7 +1623,7 @@ function isHttpStatusRetryable(status) {
function generateUUID() {
return crypto.randomUUID({
disableEntropyCache: true,
}); /* using disableEntropyCache as true to not cache the generated uuids.
}); /* using disableEntropyCache as true to not cache the generated uuids.
For more Info https://nodejs.org/api/crypto.html#cryptorandomuuidoptions:~:text=options%20%3CObject%3E-,disableEntropyCache,-%3Cboolean%3E%20By
*/
}
Expand All @@ -1646,6 +1647,9 @@ function isAppleFamily(platform) {
}

function removeHyphens(str) {
if (!isString(str)) {
return str;
}
return str.replace(/-/g, '');
}

Expand Down
16 changes: 16 additions & 0 deletions src/v0/util/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const {
validateEventAndLowerCaseConversion,
groupRouterTransformEvents,
isAxiosError,
removeHyphens,
} = require('./index');
const exp = require('constants');

Expand Down Expand Up @@ -968,3 +969,18 @@ describe('isAxiosError', () => {
expect(isAxiosError(error)).toBe(false);
});
});

describe('removeHyphens', () => {
const data = [
{ input: 'hello-w--orld', expected: 'helloworld' },
{ input: '', expected: '' },
{ input: null, expected: null },
{ input: undefined, expected: undefined },
{ input: 12345, expected: 12345 },
];
it('should remove hyphens from string else return the input as it is', () => {
data.forEach(({ input, expected }) => {
expect(removeHyphens(input)).toBe(expected);
});
});
});
Loading

0 comments on commit 31a963f

Please sign in to comment.