Skip to content

Commit f79dfe7

Browse files
SankeerthSai Sankeerth
Sankeerth
and
Sai Sankeerth
authored
feat: support for multiple zap urls (#3825)
* feat: support for multiple zap urls * fix: update endpoint to array * fix: use forEach instead of map, remove unused dependency --------- Co-authored-by: Sai Sankeerth <[email protected]>
1 parent 741f0c6 commit f79dfe7

File tree

3 files changed

+288
-13
lines changed

3 files changed

+288
-13
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
bindings:
22
- name: EventType
33
path: ../../../../constants
4-
- name: getHashFromArray
4+
- name: getHashFromArrayWithDuplicate
55
path: ../../../../v0/util/index
6-
- name: defaultRequestConfig
7-
path: ../../../../v0/util
6+
- path: ./utils
87

98
steps:
109
- name: validateInput
@@ -15,18 +14,18 @@ steps:
1514
- name: prepareContext
1615
template: |
1716
$.context.messageType = .message.type.toLowerCase();
18-
$.context.endpoint = .destination.Config.zapUrl;
17+
$.context.endpoint = [.destination.Config.zapUrl];
1918
- name: trackEndpoint
2019
condition: $.context.messageType === {{$.EventType.TRACK}}
2120
template: |
22-
const trackEventsMap = $.getHashFromArray(.destination.Config.trackEventsToZap);
21+
const trackEventsMap = $.getHashFromArrayWithDuplicate(.destination.Config.trackEventsToZap);
2322
const eventName = .message.event.toLowerCase();
2423
(eventName && trackEventsMap[eventName]) ?
2524
($.context.endpoint = trackEventsMap[eventName])
2625
else:
2726
name: endpointForOthers
2827
template: |
29-
const pageScreenEventsMap = $.getHashFromArray(.destination.Config.pageScreenEventsToZap);
28+
const pageScreenEventsMap = $.getHashFromArrayWithDuplicate(.destination.Config.pageScreenEventsToZap);
3029
const pageName = .message.name.toLowerCase();
3130
(pageName && pageScreenEventsMap[pageName]) ?
3231
($.context.endpoint = pageScreenEventsMap[pageName])
@@ -37,10 +36,5 @@ steps:
3736
else:
3837
name: buildResponseForProcessTransformation
3938
template: |
40-
const response = $.defaultRequestConfig();
41-
response.body.JSON = .message;
42-
response.endpoint = $.context.endpoint;
43-
response.headers = {
44-
"content-type": "application/json"
45-
};
46-
response
39+
const responseList = $.buildResponseList(.message, $.context.endpoint)
40+
responseList
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const { defaultRequestConfig } = require('../../../../v0/util');
2+
3+
const buildResponseList = (payload, endpointList) => {
4+
const responseList = [];
5+
endpointList.forEach((endpoint) => {
6+
const response = defaultRequestConfig();
7+
response.body.JSON = payload;
8+
response.endpoint = endpoint;
9+
response.headers = { 'content-type': 'application/json' };
10+
responseList.push(response);
11+
});
12+
return responseList;
13+
};
14+
15+
module.exports = { buildResponseList };

test/integrations/destinations/zapier/processor/data.ts

+266
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,62 @@ export const data = [
643643
response: {
644644
status: 200,
645645
body: [
646+
{
647+
output: {
648+
version: '1',
649+
type: 'REST',
650+
method: 'POST',
651+
endpoint: 'def.zap-hook',
652+
headers: {
653+
'content-type': 'application/json',
654+
},
655+
params: {},
656+
body: {
657+
JSON: {
658+
event: 'def',
659+
userId: 'identified user id',
660+
type: 'track',
661+
anonymousId: 'anon-id-new',
662+
context: {
663+
traits: {
664+
trait1: 'new-val',
665+
},
666+
ip: '14.5.67.21',
667+
library: {
668+
name: 'http',
669+
},
670+
},
671+
properties: {
672+
abc: '123',
673+
key: {
674+
abc: 123,
675+
},
676+
array: [
677+
{
678+
abc: 123,
679+
},
680+
{
681+
def: 123,
682+
},
683+
],
684+
},
685+
timestamp: '2020-02-02T00:23:09.544Z',
686+
originalTimestamp: '2020-04-17T14:42:44.724Z',
687+
sentAt: '2020-04-17T14:42:44.724Z',
688+
},
689+
JSON_ARRAY: {},
690+
XML: {},
691+
FORM: {},
692+
},
693+
files: {},
694+
userId: '',
695+
},
696+
statusCode: 200,
697+
metadata: {
698+
destinationId: 'destId',
699+
workspaceId: 'wspId',
700+
},
701+
},
646702
{
647703
output: {
648704
version: '1',
@@ -703,4 +759,214 @@ export const data = [
703759
},
704760
},
705761
},
762+
{
763+
id: 'Test 5',
764+
name: 'zapier',
765+
description: 'Track call with Multiplexing',
766+
scenario: 'Framework+Business',
767+
feature: 'processor',
768+
module: 'destination',
769+
version: 'v0',
770+
input: {
771+
request: {
772+
body: [
773+
{
774+
message: {
775+
event: 'def',
776+
userId: 'identified user id',
777+
type: 'track',
778+
anonymousId: 'anon-id-new',
779+
timestamp: '2020-02-02T00:23:09.544Z',
780+
originalTimestamp: '2020-04-17T14:42:44.724Z',
781+
sentAt: '2020-04-17T14:42:44.724Z',
782+
},
783+
metadata: {
784+
destinationId: 'destId',
785+
workspaceId: 'wspId',
786+
},
787+
destination: {
788+
DestinationDefinition: {
789+
Config: {
790+
cdkV2Enabled: true,
791+
},
792+
},
793+
Config: {
794+
zapUrl: 'abcd.zap-hook',
795+
trackEventsToZap: [
796+
{
797+
from: 'def',
798+
to: ['def.zap-hook', 'ghi.zap-hook'],
799+
},
800+
],
801+
pageScreenEventsToZap: [{}],
802+
},
803+
Enabled: true,
804+
Transformations: [],
805+
IsProcessorEnabled: true,
806+
},
807+
},
808+
],
809+
method: 'POST',
810+
},
811+
},
812+
output: {
813+
response: {
814+
status: 200,
815+
body: [
816+
{
817+
output: {
818+
version: '1',
819+
type: 'REST',
820+
method: 'POST',
821+
endpoint: ['def.zap-hook', 'ghi.zap-hook'],
822+
headers: {
823+
'content-type': 'application/json',
824+
},
825+
params: {},
826+
body: {
827+
JSON: {
828+
event: 'def',
829+
userId: 'identified user id',
830+
type: 'track',
831+
anonymousId: 'anon-id-new',
832+
timestamp: '2020-02-02T00:23:09.544Z',
833+
originalTimestamp: '2020-04-17T14:42:44.724Z',
834+
sentAt: '2020-04-17T14:42:44.724Z',
835+
},
836+
JSON_ARRAY: {},
837+
XML: {},
838+
FORM: {},
839+
},
840+
files: {},
841+
userId: '',
842+
},
843+
statusCode: 200,
844+
metadata: {
845+
destinationId: 'destId',
846+
workspaceId: 'wspId',
847+
},
848+
},
849+
],
850+
},
851+
},
852+
},
853+
{
854+
id: 'Test 6',
855+
name: 'zapier',
856+
description: 'Page call with Multiplexing',
857+
scenario: 'Framework+Business',
858+
feature: 'processor',
859+
module: 'destination',
860+
version: 'v0',
861+
input: {
862+
request: {
863+
body: [
864+
{
865+
message: {
866+
name: 'abc_page_test',
867+
userId: 'identified user id',
868+
type: 'page',
869+
anonymousId: 'anon-id-new',
870+
properties: {
871+
abc: '123',
872+
key: {
873+
abc: 123,
874+
},
875+
array: [
876+
{
877+
abc: 123,
878+
},
879+
{
880+
def: 123,
881+
},
882+
],
883+
},
884+
timestamp: '2020-02-02T00:23:09.544Z',
885+
originalTimestamp: '2020-04-17T14:42:44.724Z',
886+
sentAt: '2020-04-17T14:42:44.724Z',
887+
},
888+
metadata: {
889+
destinationId: 'destId',
890+
workspaceId: 'wspId',
891+
},
892+
destination: {
893+
DestinationDefinition: {
894+
Config: {
895+
cdkV2Enabled: true,
896+
},
897+
},
898+
Config: {
899+
zapUrl: 'abcd.zap-hook',
900+
trackEventsToZap: [{}],
901+
pageScreenEventsToZap: [
902+
{
903+
from: 'abc_page_test',
904+
to: ['page.zap-hook', 'ghi.zap-hook'],
905+
},
906+
],
907+
},
908+
Enabled: true,
909+
Transformations: [],
910+
IsProcessorEnabled: true,
911+
},
912+
},
913+
],
914+
method: 'POST',
915+
},
916+
},
917+
output: {
918+
response: {
919+
status: 200,
920+
body: [
921+
{
922+
output: {
923+
version: '1',
924+
type: 'REST',
925+
method: 'POST',
926+
endpoint: ['page.zap-hook', 'ghi.zap-hook'],
927+
headers: {
928+
'content-type': 'application/json',
929+
},
930+
params: {},
931+
body: {
932+
JSON: {
933+
name: 'abc_page_test',
934+
userId: 'identified user id',
935+
type: 'page',
936+
anonymousId: 'anon-id-new',
937+
properties: {
938+
abc: '123',
939+
key: {
940+
abc: 123,
941+
},
942+
array: [
943+
{
944+
abc: 123,
945+
},
946+
{
947+
def: 123,
948+
},
949+
],
950+
},
951+
timestamp: '2020-02-02T00:23:09.544Z',
952+
originalTimestamp: '2020-04-17T14:42:44.724Z',
953+
sentAt: '2020-04-17T14:42:44.724Z',
954+
},
955+
JSON_ARRAY: {},
956+
XML: {},
957+
FORM: {},
958+
},
959+
files: {},
960+
userId: '',
961+
},
962+
statusCode: 200,
963+
metadata: {
964+
destinationId: 'destId',
965+
workspaceId: 'wspId',
966+
},
967+
},
968+
],
969+
},
970+
},
971+
},
706972
];

0 commit comments

Comments
 (0)