Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support for multiple zap urls #3825

Merged
merged 3 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 };
266 changes: 266 additions & 0 deletions test/integrations/destinations/zapier/processor/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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'],
yashasvibajpai marked this conversation as resolved.
Show resolved Hide resolved
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',
},
},
],
},
},
},
];
Loading