From 83e96e49ceb830a71efc00b27a95f560c79a4a47 Mon Sep 17 00:00:00 2001 From: Sai Sankeerth Date: Tue, 22 Oct 2024 17:35:19 +0530 Subject: [PATCH 1/3] feat: support for multiple zap urls --- .../v2/destinations/zapier/procWorkflow.yaml | 16 +- src/cdk/v2/destinations/zapier/utils.js | 12 + .../destinations/zapier/processor/data.ts | 266 ++++++++++++++++++ 3 files changed, 284 insertions(+), 10 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..05f3d6c403 100644 --- a/src/cdk/v2/destinations/zapier/procWorkflow.yaml +++ b/src/cdk/v2/destinations/zapier/procWorkflow.yaml @@ -1,10 +1,11 @@ bindings: - name: EventType path: ../../../../constants - - name: getHashFromArray + - name: getHashFromArrayWithDuplicate path: ../../../../v0/util/index - name: defaultRequestConfig path: ../../../../v0/util + - path: ./utils steps: - name: validateInput @@ -19,14 +20,14 @@ steps: - 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 +38,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 diff --git a/src/cdk/v2/destinations/zapier/utils.js b/src/cdk/v2/destinations/zapier/utils.js new file mode 100644 index 0000000000..33c849b832 --- /dev/null +++ b/src/cdk/v2/destinations/zapier/utils.js @@ -0,0 +1,12 @@ +const { defaultRequestConfig } = require('../../../../v0/util'); + +const buildResponseList = (payload, endpointList) => + endpointList.map((endpoint) => { + const response = defaultRequestConfig(); + response.body.JSON = payload; + response.endpoint = endpoint; + response.headers = { 'content-type': 'application/json' }; + return response; + }); + +module.exports = { buildResponseList }; diff --git a/test/integrations/destinations/zapier/processor/data.ts b/test/integrations/destinations/zapier/processor/data.ts index b938f68dc5..b4f5a2a8c5 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,214 @@ export const data = [ }, }, }, + { + id: 'Test 5', + name: 'zapier', + description: 'Track call with Multiplexing', + scenario: 'Framework+Business', + 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', + }, + }, + ], + }, + }, + }, + { + 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', + }, + }, + ], + }, + }, + }, ]; From b8c91c47287bf8d3a79ac83651a92f3f17479302 Mon Sep 17 00:00:00 2001 From: Sai Sankeerth Date: Tue, 22 Oct 2024 17:44:01 +0530 Subject: [PATCH 2/3] fix: update endpoint to array --- src/cdk/v2/destinations/zapier/procWorkflow.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cdk/v2/destinations/zapier/procWorkflow.yaml b/src/cdk/v2/destinations/zapier/procWorkflow.yaml index 05f3d6c403..04a925a655 100644 --- a/src/cdk/v2/destinations/zapier/procWorkflow.yaml +++ b/src/cdk/v2/destinations/zapier/procWorkflow.yaml @@ -16,7 +16,7 @@ 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: | From c025b075b4e127ac09c1758bc9bd70bd6e52d2b0 Mon Sep 17 00:00:00 2001 From: Sai Sankeerth Date: Tue, 22 Oct 2024 18:11:39 +0530 Subject: [PATCH 3/3] fix: use forEach instead of map, remove unused dependency --- src/cdk/v2/destinations/zapier/procWorkflow.yaml | 2 -- src/cdk/v2/destinations/zapier/utils.js | 9 ++++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/cdk/v2/destinations/zapier/procWorkflow.yaml b/src/cdk/v2/destinations/zapier/procWorkflow.yaml index 04a925a655..d7a5429129 100644 --- a/src/cdk/v2/destinations/zapier/procWorkflow.yaml +++ b/src/cdk/v2/destinations/zapier/procWorkflow.yaml @@ -3,8 +3,6 @@ bindings: path: ../../../../constants - name: getHashFromArrayWithDuplicate path: ../../../../v0/util/index - - name: defaultRequestConfig - path: ../../../../v0/util - path: ./utils steps: diff --git a/src/cdk/v2/destinations/zapier/utils.js b/src/cdk/v2/destinations/zapier/utils.js index 33c849b832..43de6e58dd 100644 --- a/src/cdk/v2/destinations/zapier/utils.js +++ b/src/cdk/v2/destinations/zapier/utils.js @@ -1,12 +1,15 @@ const { defaultRequestConfig } = require('../../../../v0/util'); -const buildResponseList = (payload, endpointList) => - endpointList.map((endpoint) => { +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' }; - return response; + responseList.push(response); }); + return responseList; +}; module.exports = { buildResponseList };