From c912bed363411d26c129ee0684ac99bae89b5439 Mon Sep 17 00:00:00 2001 From: Aanshi Lahoti Date: Wed, 25 Sep 2024 12:15:45 +0530 Subject: [PATCH 1/5] feat: added multiplexing for zapUrls --- .../v2/destinations/zapier/procWorkflow.yaml | 20 +-- src/cdk/v2/destinations/zapier/utils.js | 15 ++ .../destinations/zapier/processor/data.ts | 145 ++++++++++++++++++ 3 files changed, 167 insertions(+), 13 deletions(-) create mode 100644 src/cdk/v2/destinations/zapier/utils.js diff --git a/src/cdk/v2/destinations/zapier/procWorkflow.yaml b/src/cdk/v2/destinations/zapier/procWorkflow.yaml index c14c57378c..6fc2e660f0 100644 --- a/src/cdk/v2/destinations/zapier/procWorkflow.yaml +++ b/src/cdk/v2/destinations/zapier/procWorkflow.yaml @@ -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 @@ -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]) @@ -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, { "content-type": "application/json" }) + responseList diff --git a/src/cdk/v2/destinations/zapier/utils.js b/src/cdk/v2/destinations/zapier/utils.js new file mode 100644 index 0000000000..e52887f0d6 --- /dev/null +++ b/src/cdk/v2/destinations/zapier/utils.js @@ -0,0 +1,15 @@ +const { defaultRequestConfig } = require('../../../../v0/util'); + +const buildResponseList = (payload, endpointList, headers) => { + const responseList = []; + endpointList.forEach((endpoint) => { + const response = defaultRequestConfig(); + response.body.JSON = payload; + response.endpoint = endpoint; + response.headers = headers; + responseList.push(response); + }); + return responseList; +}; + +module.exports = { buildResponseList }; diff --git a/test/integrations/destinations/zapier/processor/data.ts b/test/integrations/destinations/zapier/processor/data.ts index b938f68dc5..9065d06dca 100644 --- a/test/integrations/destinations/zapier/processor/data.ts +++ b/test/integrations/destinations/zapier/processor/data.ts @@ -643,6 +643,62 @@ export const data = [ response: { status: 200, body: [ + { + output: { + version: '1', + type: 'REST', + method: 'POST', + endpoint: 'def.zap-hook', + headers: { + 'content-type': 'application/json', + }, + params: {}, + body: { + JSON: { + event: 'def', + userId: 'identified user id', + type: 'track', + anonymousId: 'anon-id-new', + context: { + traits: { + trait1: 'new-val', + }, + ip: '14.5.67.21', + library: { + name: 'http', + }, + }, + properties: { + abc: '123', + key: { + abc: 123, + }, + array: [ + { + abc: 123, + }, + { + def: 123, + }, + ], + }, + timestamp: '2020-02-02T00:23:09.544Z', + originalTimestamp: '2020-04-17T14:42:44.724Z', + sentAt: '2020-04-17T14:42:44.724Z', + }, + JSON_ARRAY: {}, + XML: {}, + FORM: {}, + }, + files: {}, + userId: '', + }, + statusCode: 200, + metadata: { + destinationId: 'destId', + workspaceId: 'wspId', + }, + }, { output: { version: '1', @@ -703,4 +759,93 @@ export const data = [ }, }, }, + { + name: 'zapier', + description: 'Test 5', + feature: 'processor', + module: 'destination', + version: 'v0', + input: { + request: { + body: [ + { + message: { + event: 'def', + userId: 'identified user id', + type: 'track', + anonymousId: 'anon-id-new', + timestamp: '2020-02-02T00:23:09.544Z', + originalTimestamp: '2020-04-17T14:42:44.724Z', + sentAt: '2020-04-17T14:42:44.724Z', + }, + metadata: { + destinationId: 'destId', + workspaceId: 'wspId', + }, + destination: { + DestinationDefinition: { + Config: { + cdkV2Enabled: true, + }, + }, + Config: { + zapUrl: 'abcd.zap-hook', + trackEventsToZap: [ + { + from: 'def', + to: ['def.zap-hook', 'ghi.zap-hook'], + }, + ], + pageScreenEventsToZap: [{}], + }, + Enabled: true, + Transformations: [], + IsProcessorEnabled: true, + }, + }, + ], + method: 'POST', + }, + }, + output: { + response: { + status: 200, + body: [ + { + output: { + version: '1', + type: 'REST', + method: 'POST', + endpoint: ['def.zap-hook', 'ghi.zap-hook'], + headers: { + 'content-type': 'application/json', + }, + params: {}, + body: { + JSON: { + event: 'def', + userId: 'identified user id', + type: 'track', + anonymousId: 'anon-id-new', + timestamp: '2020-02-02T00:23:09.544Z', + originalTimestamp: '2020-04-17T14:42:44.724Z', + sentAt: '2020-04-17T14:42:44.724Z', + }, + JSON_ARRAY: {}, + XML: {}, + FORM: {}, + }, + files: {}, + userId: '', + }, + statusCode: 200, + metadata: { + destinationId: 'destId', + workspaceId: 'wspId', + }, + }, + ], + }, + }, + }, ]; From fa87463249658c4a5ab31a7722c23306860f82d3 Mon Sep 17 00:00:00 2001 From: Sai Sankeerth Date: Wed, 25 Sep 2024 15:41:42 +0530 Subject: [PATCH 2/5] fix: ignore yaml files in eslint check --- .eslintignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.eslintignore b/.eslintignore index ce54730f4b..6d0f830cc9 100644 --- a/.eslintignore +++ b/.eslintignore @@ -10,6 +10,8 @@ dist/ *.md *.test.js *.test.ts +*.yaml +*.yml src/util/lodash-es-core.js **/ivm*.js **/custom*.js From d14fc7f932038bf1dd22e868c7dfdd3cf9bfc9d7 Mon Sep 17 00:00:00 2001 From: Sai Sankeerth Date: Wed, 25 Sep 2024 16:00:18 +0530 Subject: [PATCH 3/5] fix: parser error for eslintignore while running prettier --- .prettierrc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.prettierrc b/.prettierrc index 09dcf1c1e8..19582c2368 100644 --- a/.prettierrc +++ b/.prettierrc @@ -3,5 +3,6 @@ "tabWidth": 2, "semi": true, "singleQuote": true, - "printWidth": 100 + "printWidth": 100, + "overrides": [{ "files": "*eslintignore", "options": { "parser": "yaml" } }] } From e87860222d7606b7185972b62fc1d6d115aa5b0b Mon Sep 17 00:00:00 2001 From: Aanshi Lahoti Date: Tue, 8 Oct 2024 17:11:34 +0530 Subject: [PATCH 4/5] chore: updated headers --- src/cdk/v2/destinations/zapier/procWorkflow.yaml | 2 +- src/cdk/v2/destinations/zapier/utils.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cdk/v2/destinations/zapier/procWorkflow.yaml b/src/cdk/v2/destinations/zapier/procWorkflow.yaml index 6fc2e660f0..d7a5429129 100644 --- a/src/cdk/v2/destinations/zapier/procWorkflow.yaml +++ b/src/cdk/v2/destinations/zapier/procWorkflow.yaml @@ -36,5 +36,5 @@ steps: else: name: buildResponseForProcessTransformation template: | - const responseList = $.buildResponseList(.message, $.context.endpoint, { "content-type": "application/json" }) + const responseList = $.buildResponseList(.message, $.context.endpoint) responseList diff --git a/src/cdk/v2/destinations/zapier/utils.js b/src/cdk/v2/destinations/zapier/utils.js index e52887f0d6..43de6e58dd 100644 --- a/src/cdk/v2/destinations/zapier/utils.js +++ b/src/cdk/v2/destinations/zapier/utils.js @@ -1,12 +1,12 @@ const { defaultRequestConfig } = require('../../../../v0/util'); -const buildResponseList = (payload, endpointList, headers) => { +const buildResponseList = (payload, endpointList) => { const responseList = []; endpointList.forEach((endpoint) => { const response = defaultRequestConfig(); response.body.JSON = payload; response.endpoint = endpoint; - response.headers = headers; + response.headers = { 'content-type': 'application/json' }; responseList.push(response); }); return responseList; From ff4bb9cfc58f8fab604ff3c0640b60d292565dd0 Mon Sep 17 00:00:00 2001 From: Aanshi Lahoti Date: Tue, 8 Oct 2024 20:00:53 +0530 Subject: [PATCH 5/5] chore: test case added for page call --- .../destinations/zapier/processor/data.ts | 123 +++++++++++++++++- 1 file changed, 122 insertions(+), 1 deletion(-) diff --git a/test/integrations/destinations/zapier/processor/data.ts b/test/integrations/destinations/zapier/processor/data.ts index 9065d06dca..b4f5a2a8c5 100644 --- a/test/integrations/destinations/zapier/processor/data.ts +++ b/test/integrations/destinations/zapier/processor/data.ts @@ -760,8 +760,10 @@ export const data = [ }, }, { + id: 'Test 5', name: 'zapier', - description: 'Test 5', + description: 'Track call with Multiplexing', + scenario: 'Framework+Business', feature: 'processor', module: 'destination', version: 'v0', @@ -848,4 +850,123 @@ export const data = [ }, }, }, + { + id: 'Test 6', + name: 'zapier', + description: 'Page call with Multiplexing', + scenario: 'Framework+Business', + feature: 'processor', + module: 'destination', + version: 'v0', + input: { + request: { + body: [ + { + message: { + name: 'abc_page_test', + userId: 'identified user id', + type: 'page', + anonymousId: 'anon-id-new', + properties: { + abc: '123', + key: { + abc: 123, + }, + array: [ + { + abc: 123, + }, + { + def: 123, + }, + ], + }, + timestamp: '2020-02-02T00:23:09.544Z', + originalTimestamp: '2020-04-17T14:42:44.724Z', + sentAt: '2020-04-17T14:42:44.724Z', + }, + metadata: { + destinationId: 'destId', + workspaceId: 'wspId', + }, + destination: { + DestinationDefinition: { + Config: { + cdkV2Enabled: true, + }, + }, + Config: { + zapUrl: 'abcd.zap-hook', + trackEventsToZap: [{}], + pageScreenEventsToZap: [ + { + from: 'abc_page_test', + to: ['page.zap-hook', 'ghi.zap-hook'], + }, + ], + }, + Enabled: true, + Transformations: [], + IsProcessorEnabled: true, + }, + }, + ], + method: 'POST', + }, + }, + output: { + response: { + status: 200, + body: [ + { + output: { + version: '1', + type: 'REST', + method: 'POST', + endpoint: ['page.zap-hook', 'ghi.zap-hook'], + headers: { + 'content-type': 'application/json', + }, + params: {}, + body: { + JSON: { + name: 'abc_page_test', + userId: 'identified user id', + type: 'page', + anonymousId: 'anon-id-new', + properties: { + abc: '123', + key: { + abc: 123, + }, + array: [ + { + abc: 123, + }, + { + def: 123, + }, + ], + }, + timestamp: '2020-02-02T00:23:09.544Z', + originalTimestamp: '2020-04-17T14:42:44.724Z', + sentAt: '2020-04-17T14:42:44.724Z', + }, + JSON_ARRAY: {}, + XML: {}, + FORM: {}, + }, + files: {}, + userId: '', + }, + statusCode: 200, + metadata: { + destinationId: 'destId', + workspaceId: 'wspId', + }, + }, + ], + }, + }, + }, ];