@segment/action-destinations 3.438.0 → 3.439.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/dist/destinations/criteo-audiences/addUserToAudience/generated-types.d.ts +1 -0
  2. package/dist/destinations/criteo-audiences/addUserToAudience/index.js +7 -0
  3. package/dist/destinations/criteo-audiences/addUserToAudience/index.js.map +1 -1
  4. package/dist/destinations/criteo-audiences/removeUserFromAudience/generated-types.d.ts +1 -0
  5. package/dist/destinations/criteo-audiences/removeUserFromAudience/index.js +7 -0
  6. package/dist/destinations/criteo-audiences/removeUserFromAudience/index.js.map +1 -1
  7. package/dist/destinations/google-enhanced-conversions/functions.d.ts +1 -1
  8. package/dist/destinations/google-enhanced-conversions/functions.js +1 -1
  9. package/dist/destinations/google-enhanced-conversions/uploadCallConversion/index.js +2 -2
  10. package/dist/destinations/google-enhanced-conversions/uploadCallConversion2/index.js +2 -2
  11. package/dist/destinations/google-enhanced-conversions/uploadClickConversion/index.js +2 -2
  12. package/dist/destinations/google-enhanced-conversions/uploadClickConversion2/index.js +2 -2
  13. package/dist/destinations/google-enhanced-conversions/userList/index.js +3 -3
  14. package/dist/destinations/google-enhanced-conversions/userList/index.js.map +1 -1
  15. package/dist/destinations/linkedin-audiences/{api/index.d.ts → api.d.ts} +3 -3
  16. package/dist/destinations/linkedin-audiences/{api/index.js → api.js} +2 -2
  17. package/dist/destinations/linkedin-audiences/api.js.map +1 -0
  18. package/dist/destinations/linkedin-audiences/updateAudience/fields.d.ts +2 -0
  19. package/dist/destinations/linkedin-audiences/updateAudience/fields.js +126 -0
  20. package/dist/destinations/linkedin-audiences/updateAudience/fields.js.map +1 -0
  21. package/dist/destinations/linkedin-audiences/updateAudience/functions.d.ts +5 -0
  22. package/dist/destinations/linkedin-audiences/updateAudience/functions.js +112 -0
  23. package/dist/destinations/linkedin-audiences/updateAudience/functions.js.map +1 -0
  24. package/dist/destinations/linkedin-audiences/updateAudience/index.js +5 -232
  25. package/dist/destinations/linkedin-audiences/updateAudience/index.js.map +1 -1
  26. package/dist/destinations/ms-bing-ads-audiences/index.js +1 -1
  27. package/dist/destinations/ms-bing-ads-audiences/index.js.map +1 -1
  28. package/dist/destinations/ms-bing-ads-audiences/syncAudiences/fields.js +13 -17
  29. package/dist/destinations/ms-bing-ads-audiences/syncAudiences/fields.js.map +1 -1
  30. package/dist/destinations/snap-audiences/constants.d.ts +2 -0
  31. package/dist/destinations/snap-audiences/constants.js +6 -0
  32. package/dist/destinations/snap-audiences/constants.js.map +1 -0
  33. package/dist/destinations/snap-audiences/index.js +24 -40
  34. package/dist/destinations/snap-audiences/index.js.map +1 -1
  35. package/dist/destinations/snap-audiences/syncAudience/constants.d.ts +5 -0
  36. package/dist/destinations/snap-audiences/syncAudience/constants.js +9 -0
  37. package/dist/destinations/snap-audiences/syncAudience/constants.js.map +1 -0
  38. package/dist/destinations/snap-audiences/syncAudience/fields.d.ts +2 -0
  39. package/dist/destinations/snap-audiences/syncAudience/fields.js +90 -0
  40. package/dist/destinations/snap-audiences/syncAudience/fields.js.map +1 -0
  41. package/dist/destinations/snap-audiences/syncAudience/functions.d.ts +5 -0
  42. package/dist/destinations/snap-audiences/syncAudience/functions.js +119 -0
  43. package/dist/destinations/snap-audiences/syncAudience/functions.js.map +1 -0
  44. package/dist/destinations/snap-audiences/syncAudience/generated-types.d.ts +2 -1
  45. package/dist/destinations/snap-audiences/syncAudience/index.js +6 -146
  46. package/dist/destinations/snap-audiences/syncAudience/index.js.map +1 -1
  47. package/dist/destinations/snap-audiences/syncAudience/types.d.ts +18 -0
  48. package/dist/destinations/snap-audiences/syncAudience/types.js.map +1 -0
  49. package/dist/destinations/snap-audiences/types.d.ts +19 -0
  50. package/dist/destinations/snap-audiences/types.js.map +1 -0
  51. package/dist/destinations/stackadapt-audiences/common-constants.d.ts +2 -0
  52. package/dist/destinations/stackadapt-audiences/common-constants.js +6 -0
  53. package/dist/destinations/stackadapt-audiences/common-constants.js.map +1 -0
  54. package/dist/destinations/stackadapt-audiences/common-functions.d.ts +0 -7
  55. package/dist/destinations/stackadapt-audiences/common-functions.js +0 -193
  56. package/dist/destinations/stackadapt-audiences/common-functions.js.map +1 -1
  57. package/dist/destinations/stackadapt-audiences/common-types.d.ts +15 -0
  58. package/dist/destinations/stackadapt-audiences/{forwardProfile/generated-types.js → common-types.js} +1 -1
  59. package/dist/destinations/stackadapt-audiences/common-types.js.map +1 -0
  60. package/dist/destinations/stackadapt-audiences/{constants.js → forwardAudienceEvent/constants.js} +1 -22
  61. package/dist/destinations/stackadapt-audiences/forwardAudienceEvent/constants.js.map +1 -0
  62. package/dist/destinations/stackadapt-audiences/forwardAudienceEvent/fields.d.ts +1 -0
  63. package/dist/destinations/stackadapt-audiences/forwardAudienceEvent/fields.js +184 -1
  64. package/dist/destinations/stackadapt-audiences/forwardAudienceEvent/fields.js.map +1 -1
  65. package/dist/destinations/stackadapt-audiences/forwardAudienceEvent/functions.d.ts +6 -0
  66. package/dist/destinations/stackadapt-audiences/forwardAudienceEvent/functions.js +184 -0
  67. package/dist/destinations/stackadapt-audiences/forwardAudienceEvent/functions.js.map +1 -0
  68. package/dist/destinations/stackadapt-audiences/forwardAudienceEvent/generated-types.d.ts +0 -3
  69. package/dist/destinations/stackadapt-audiences/forwardAudienceEvent/index.js +4 -5
  70. package/dist/destinations/stackadapt-audiences/forwardAudienceEvent/index.js.map +1 -1
  71. package/dist/destinations/stackadapt-audiences/{types.d.ts → forwardAudienceEvent/types.d.ts} +0 -15
  72. package/dist/destinations/{yonoma/sendEvent/generated-types.js → stackadapt-audiences/forwardAudienceEvent/types.js} +1 -1
  73. package/dist/destinations/stackadapt-audiences/forwardAudienceEvent/types.js.map +1 -0
  74. package/dist/destinations/stackadapt-audiences/index.d.ts +1 -1
  75. package/dist/destinations/stackadapt-audiences/index.js +5 -7
  76. package/dist/destinations/stackadapt-audiences/index.js.map +1 -1
  77. package/dist/destinations/yonoma/index.js +0 -2
  78. package/dist/destinations/yonoma/index.js.map +1 -1
  79. package/dist/destinations/yonoma/trackEvent/generated-types.d.ts +24 -3
  80. package/dist/destinations/yonoma/trackEvent/index.js +140 -16
  81. package/dist/destinations/yonoma/trackEvent/index.js.map +1 -1
  82. package/dist/destinations/yonoma/trackEvent/types.d.ts +24 -3
  83. package/dist/destinations/yonoma/trackPageView/generated-types.d.ts +23 -7
  84. package/dist/destinations/yonoma/trackPageView/index.js +133 -50
  85. package/dist/destinations/yonoma/trackPageView/index.js.map +1 -1
  86. package/dist/destinations/yonoma/trackPageView/types.d.ts +22 -4
  87. package/dist/destinations/yonoma/upsertContact/generated-types.d.ts +25 -3
  88. package/dist/destinations/yonoma/upsertContact/index.js +153 -21
  89. package/dist/destinations/yonoma/upsertContact/index.js.map +1 -1
  90. package/dist/destinations/yonoma/upsertContact/types.d.ts +26 -4
  91. package/package.json +2 -2
  92. package/dist/destinations/linkedin-audiences/api/index.js.map +0 -1
  93. package/dist/destinations/snap-audiences/syncAudience/utils.d.ts +0 -8
  94. package/dist/destinations/snap-audiences/syncAudience/utils.js +0 -61
  95. package/dist/destinations/snap-audiences/syncAudience/utils.js.map +0 -1
  96. package/dist/destinations/stackadapt-audiences/common-fields.d.ts +0 -2
  97. package/dist/destinations/stackadapt-audiences/common-fields.js +0 -227
  98. package/dist/destinations/stackadapt-audiences/common-fields.js.map +0 -1
  99. package/dist/destinations/stackadapt-audiences/constants.js.map +0 -1
  100. package/dist/destinations/stackadapt-audiences/forwardProfile/generated-types.d.ts +0 -26
  101. package/dist/destinations/stackadapt-audiences/forwardProfile/generated-types.js.map +0 -1
  102. package/dist/destinations/stackadapt-audiences/forwardProfile/index.d.ts +0 -5
  103. package/dist/destinations/stackadapt-audiences/forwardProfile/index.js +0 -140
  104. package/dist/destinations/stackadapt-audiences/forwardProfile/index.js.map +0 -1
  105. package/dist/destinations/stackadapt-audiences/types.js.map +0 -1
  106. package/dist/destinations/yonoma/sendEvent/constants.d.ts +0 -1
  107. package/dist/destinations/yonoma/sendEvent/constants.js +0 -5
  108. package/dist/destinations/yonoma/sendEvent/constants.js.map +0 -1
  109. package/dist/destinations/yonoma/sendEvent/functions.d.ts +0 -1
  110. package/dist/destinations/yonoma/sendEvent/functions.js +0 -19
  111. package/dist/destinations/yonoma/sendEvent/functions.js.map +0 -1
  112. package/dist/destinations/yonoma/sendEvent/generated-types.d.ts +0 -13
  113. package/dist/destinations/yonoma/sendEvent/generated-types.js.map +0 -1
  114. package/dist/destinations/yonoma/sendEvent/index.d.ts +0 -5
  115. package/dist/destinations/yonoma/sendEvent/index.js +0 -103
  116. package/dist/destinations/yonoma/sendEvent/index.js.map +0 -1
  117. package/dist/destinations/yonoma/sendEvent/types.d.ts +0 -10
  118. package/dist/destinations/yonoma/sendEvent/types.js.map +0 -1
  119. /package/dist/destinations/{stackadapt-audiences → snap-audiences/syncAudience}/types.js +0 -0
  120. /package/dist/destinations/{yonoma/sendEvent → snap-audiences}/types.js +0 -0
  121. /package/dist/destinations/stackadapt-audiences/{constants.d.ts → forwardAudienceEvent/constants.d.ts} +0 -0
@@ -0,0 +1,5 @@
1
+ import type { Payload } from './generated-types';
2
+ import { RequestClient, MultiStatusResponse } from '@segment/actions-core';
3
+ export declare function send(request: RequestClient, payload: Payload[]): Promise<MultiStatusResponse>;
4
+ export declare const normalize: (identifier: string) => string;
5
+ export declare const normalizePhone: (phone: string) => string;
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizePhone = exports.normalize = void 0;
4
+ exports.send = send;
5
+ const hashing_utils_1 = require("../../../lib/hashing-utils");
6
+ const actions_core_1 = require("@segment/actions-core");
7
+ const constants_1 = require("./constants");
8
+ async function send(request, payload) {
9
+ const payloads = payload.map((p, index) => ({ ...p, index }));
10
+ const { external_audience_id } = payload[0];
11
+ const multiStatusResponse = new actions_core_1.MultiStatusResponse();
12
+ const batches = payloads.reduce((acc, p) => {
13
+ const hasValue = Boolean(p.email || p.phone || p.advertising_id);
14
+ if (!hasValue) {
15
+ multiStatusResponse.setErrorResponseAtIndex(p.index, {
16
+ status: 400,
17
+ errortype: 'PAYLOAD_VALIDATION_FAILED',
18
+ errormessage: 'One of "email" or "phone" or "Mobile Advertising ID" is required.'
19
+ });
20
+ return acc;
21
+ }
22
+ const isAdd = Boolean(p.props[p.audienceKey]);
23
+ if (p.email) {
24
+ (isAdd ? acc.addEmail.opPayloads : acc.removeEmail.opPayloads).push(p);
25
+ }
26
+ if (p.phone) {
27
+ (isAdd ? acc.addPhone.opPayloads : acc.removePhone.opPayloads).push(p);
28
+ }
29
+ if (p.advertising_id) {
30
+ (isAdd ? acc.addMAID.opPayloads : acc.removeMAID.opPayloads).push(p);
31
+ }
32
+ return acc;
33
+ }, {
34
+ addEmail: { opPayloads: [], operationType: { method: 'POST', type: constants_1.SCHEMA_TYPES.EMAIL } },
35
+ addPhone: { opPayloads: [], operationType: { method: 'POST', type: constants_1.SCHEMA_TYPES.PHONE } },
36
+ addMAID: { opPayloads: [], operationType: { method: 'POST', type: constants_1.SCHEMA_TYPES.MAID } },
37
+ removeEmail: { opPayloads: [], operationType: { method: 'DELETE', type: constants_1.SCHEMA_TYPES.EMAIL } },
38
+ removePhone: { opPayloads: [], operationType: { method: 'DELETE', type: constants_1.SCHEMA_TYPES.PHONE } },
39
+ removeMAID: { opPayloads: [], operationType: { method: 'DELETE', type: constants_1.SCHEMA_TYPES.MAID } },
40
+ });
41
+ const url = `https://adsapi.snapchat.com/v1/segments/${external_audience_id}/users`;
42
+ await Promise.all(Object.entries(batches)
43
+ .filter(([, batch]) => batch.opPayloads.length > 0)
44
+ .map(async ([, batch]) => {
45
+ const { opPayloads, operationType: { type, method } } = batch;
46
+ const json = buildJSON(opPayloads, type);
47
+ try {
48
+ await request(url, { method, json });
49
+ opPayloads.forEach((p) => {
50
+ const existingResponse = multiStatusResponse.getResponseAtIndex(p.index)?.value();
51
+ const status = existingResponse?.status;
52
+ if (typeof status === 'number' && (status < 200 || status >= 300)) {
53
+ return;
54
+ }
55
+ multiStatusResponse.setSuccessResponseAtIndex(p.index, {
56
+ status: 200,
57
+ sent: json.users[p.index],
58
+ body: JSON.stringify(p)
59
+ });
60
+ });
61
+ }
62
+ catch (error) {
63
+ for (const p of opPayloads) {
64
+ multiStatusResponse.setErrorResponseAtIndex(p.index, {
65
+ status: error?.response?.status || 400,
66
+ errortype: 'BAD_REQUEST',
67
+ errormessage: error.message || 'Unknown error',
68
+ sent: json.users[p.index],
69
+ body: JSON.stringify(p)
70
+ });
71
+ }
72
+ }
73
+ }));
74
+ return multiStatusResponse;
75
+ }
76
+ function buildJSON(payloads, type) {
77
+ const seen = new Set();
78
+ const data = payloads.reduce((acc, p) => {
79
+ let value;
80
+ if (type === constants_1.SCHEMA_TYPES.EMAIL && p.email) {
81
+ value = (0, hashing_utils_1.processHashing)(p.email, 'sha256', 'hex', exports.normalize);
82
+ }
83
+ else if (type === constants_1.SCHEMA_TYPES.PHONE && p.phone) {
84
+ value = (0, hashing_utils_1.processHashing)(p.phone, 'sha256', 'hex', exports.normalizePhone);
85
+ }
86
+ else if (type === constants_1.SCHEMA_TYPES.MAID && p.advertising_id) {
87
+ value = (0, hashing_utils_1.processHashing)(p.advertising_id, 'sha256', 'hex', exports.normalize);
88
+ }
89
+ if (value && !seen.has(value)) {
90
+ seen.add(value);
91
+ acc.push([value]);
92
+ }
93
+ return acc;
94
+ }, []);
95
+ return {
96
+ users: [
97
+ {
98
+ schema: [type],
99
+ data
100
+ }
101
+ ]
102
+ };
103
+ }
104
+ const normalize = (identifier) => {
105
+ return identifier.trim().toLowerCase();
106
+ };
107
+ exports.normalize = normalize;
108
+ const normalizePhone = (phone) => {
109
+ let normalizedPhone = phone.replace(/[\s()+-]/g, '');
110
+ if (normalizedPhone.startsWith('00')) {
111
+ normalizedPhone = normalizedPhone.substring(2);
112
+ }
113
+ if (normalizedPhone.startsWith('0')) {
114
+ normalizedPhone = normalizedPhone.substring(1);
115
+ }
116
+ return normalizedPhone;
117
+ };
118
+ exports.normalizePhone = normalizePhone;
119
+ //# sourceMappingURL=functions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"functions.js","sourceRoot":"","sources":["../../../../src/destinations/snap-audiences/syncAudience/functions.ts"],"names":[],"mappings":";;;AAMA,oBA6EC;AAlFD,8DAA2D;AAC3D,wDAA0E;AAE1E,2CAA0C;AAEnC,KAAK,UAAU,IAAI,CAAC,OAAsB,EAAE,OAAkB;IACnE,MAAM,QAAQ,GAAuB,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAA;IACjF,MAAM,EAAE,oBAAoB,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;IAC3C,MAAM,mBAAmB,GAAG,IAAI,kCAAmB,EAAE,CAAA;IACrD,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,CAC7B,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE;QACT,MAAM,QAAQ,GAAG,OAAO,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,cAAc,CAAC,CAAA;QAChE,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,mBAAmB,CAAC,uBAAuB,CAAC,CAAC,CAAC,KAAK,EAAE;gBACnD,MAAM,EAAE,GAAG;gBACX,SAAS,EAAE,2BAA2B;gBACtC,YAAY,EAAE,mEAAmE;aAClF,CAAC,CAAA;YACF,OAAO,GAAG,CAAA;QACZ,CAAC;QAED,MAAM,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAA;QAE7C,IAAI,CAAC,CAAC,KAAK,EAAE,CAAC;YACZ,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,W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string;
9
8
  email?: string;
10
9
  advertising_id?: string;
11
10
  enable_batching: boolean;
11
+ max_batch_size: number;
12
+ batch_keys?: string[];
12
13
  }
@@ -1,158 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const actions_core_1 = require("@segment/actions-core");
4
- const utils_1 = require("./utils");
3
+ const fields_1 = require("./fields");
4
+ const functions_1 = require("./functions");
5
5
  const action = {
6
6
  title: 'Sync Audience',
7
- description: 'Sync users to Snap',
7
+ description: 'Sync Engage Audiences to Snap',
8
8
  defaultSubscription: 'type = "track"',
9
- fields: {
10
- external_audience_id: {
11
- type: 'string',
12
- label: 'External Audience ID',
13
- description: 'Unique Audience Identifier returned by the createAudience() function call.',
14
- required: true,
15
- unsafe_hidden: true,
16
- default: {
17
- '@path': '$.context.personas.external_audience_id'
18
- }
19
- },
20
- audienceKey: {
21
- type: 'string',
22
- label: 'Audience Key',
23
- description: 'Audience key.',
24
- required: true,
25
- unsafe_hidden: true,
26
- default: {
27
- '@path': '$.context.personas.computation_key'
28
- }
29
- },
30
- props: {
31
- label: 'Properties object',
32
- description: 'A computed object for track events.',
33
- type: 'object',
34
- required: true,
35
- unsafe_hidden: true,
36
- default: { '@path': '$.properties' }
37
- },
38
- schema_type: {
39
- type: 'string',
40
- choices: [
41
- { value: 'MOBILE_AD_ID_SHA256', label: 'Mobile ID' },
42
- { value: 'PHONE_SHA256', label: 'Phone' },
43
- { value: 'EMAIL_SHA256', label: 'Email' }
44
- ],
45
- label: 'External ID Type',
46
- required: true,
47
- description: 'Choose the type of identifier to use when adding users to Snap.',
48
- default: 'EMAIL_SHA256',
49
- disabledInputMethods: ['literal', 'variable', 'function', 'freeform', 'enrichment']
50
- },
51
- phone: {
52
- label: 'Phone',
53
- description: "If using phone as the identifier, an additional setup step is required when connecting the Destination to the Audience. Please ensure that 'phone' is configured as an additional identifier in the Audience settings tab.",
54
- type: 'string',
55
- required: false,
56
- default: { '@path': '$.properties.phone' },
57
- depends_on: {
58
- match: 'all',
59
- conditions: [
60
- {
61
- fieldKey: 'schema_type',
62
- operator: 'is',
63
- value: 'PHONE_SHA256'
64
- }
65
- ]
66
- },
67
- category: 'hashedPII'
68
- },
69
- email: {
70
- label: 'Email',
71
- description: "The user's email address.",
72
- type: 'string',
73
- required: false,
74
- default: { '@path': '$.context.traits.email' },
75
- depends_on: {
76
- match: 'all',
77
- conditions: [
78
- {
79
- fieldKey: 'schema_type',
80
- operator: 'is',
81
- value: 'EMAIL_SHA256'
82
- }
83
- ]
84
- },
85
- category: 'hashedPII'
86
- },
87
- advertising_id: {
88
- label: 'Mobile Advertising ID',
89
- description: "If using Mobile Ad ID as the identifier, an additional setup step is required when connecting the Destination to the Audience. Please ensure that 'ios.idfa' and 'android.idfa' are configured as an additional identifier in the Audience settings tab.",
90
- type: 'string',
91
- required: false,
92
- default: {
93
- '@path': '$.context.device.advertisingId'
94
- },
95
- depends_on: {
96
- match: 'all',
97
- conditions: [
98
- {
99
- fieldKey: 'schema_type',
100
- operator: 'is',
101
- value: 'MOBILE_AD_ID_SHA256'
102
- }
103
- ]
104
- },
105
- category: 'hashedPII'
106
- },
107
- enable_batching: {
108
- label: 'Enable Batching',
109
- description: 'When enabled, events will be batched before being sent to Snap.',
110
- type: 'boolean',
111
- required: true,
112
- default: true
113
- }
114
- },
9
+ fields: fields_1.fields,
115
10
  perform: async (request, { payload }) => {
116
- return processPayload(request, [payload]);
11
+ return (0, functions_1.send)(request, [payload]);
117
12
  },
118
13
  performBatch: async (request, { payload }) => {
119
- return processPayload(request, payload);
14
+ return (0, functions_1.send)(request, payload);
120
15
  }
121
16
  };
122
17
  exports.default = action;
123
- const processPayload = async (request, payload) => {
124
- const { external_audience_id, schema_type } = payload[0];
125
- const { enteredAudience, exitedAudience } = (0, utils_1.sortPayload)(payload);
126
- if (enteredAudience.length === 0 && exitedAudience.length === 0) {
127
- throw new actions_core_1.PayloadValidationError(`No ${(0, utils_1.validationError)(schema_type)} identifier present in payload(s)`);
128
- }
129
- const requests = [];
130
- if (enteredAudience.length > 0) {
131
- requests.push(request(`https://adsapi.snapchat.com/v1/segments/${external_audience_id}/users`, {
132
- method: 'post',
133
- json: {
134
- users: [
135
- {
136
- schema: [`${schema_type}`],
137
- data: enteredAudience
138
- }
139
- ]
140
- }
141
- }));
142
- }
143
- if (exitedAudience.length > 0) {
144
- requests.push(request(`https://adsapi.snapchat.com/v1/segments/${external_audience_id}/users`, {
145
- method: 'delete',
146
- json: {
147
- users: [
148
- {
149
- schema: [`${schema_type}`],
150
- data: exitedAudience
151
- }
152
- ]
153
- }
154
- }));
155
- }
156
- return await Promise.all(requests);
157
- };
158
18
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/snap-audiences/syncAudience/index.ts"],"names":[],"mappings":";;AACA,wDAA8D;AAG9D,mCAAsD;AAEtD,MAAM,MAAM,GAAwC;IAClD,KAAK,EAAE,eAAe;IACtB,WAAW,EAAE,oBAAoB;IACjC,mBAAmB,EAAE,gBAAgB;IACrC,MAAM,EAAE;QACN,oBAAoB,EAAE;YACpB,IAAI,EAAE,QAAQ;YACd,KAAK,EAAE,sBAAsB;YAC7B,WAAW,EAAE,4EAA4E;YACzF,QAAQ,EAAE,IAAI;YACd,aAAa,EAAE,IAAI;YACnB,OAAO,EAAE;gBACP,OAAO,EAAE,yCAAyC;aACnD;SACF;QACD,WAAW,EAAE;YACX,IAAI,EAAE,QAAQ;YACd,KAAK,EAAE,cAAc;YACrB,WAAW,EAAE,eAAe;YAC5B,QAAQ,EAAE,IAAI;YACd,aAAa,EAAE,IAAI;YACnB,OAAO,EAAE;gBACP,OAAO,EAAE,oCAAoC;aAC9C;SACF;QACD,KAAK,EAAE;YACL,KAAK,EAAE,mBAAmB;YAC1B,WAAW,EAAE,qCAAqC;YAClD,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,IAAI;YACd,aAAa,EAAE,IAAI;YACnB,OAAO,E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IAED,MAAM,QAAQ,GAAG,EAAE,CAAA;IAEnB,IAAI,eAAe,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC/B,QAAQ,CAAC,IAAI,CACX,OAAO,CAAC,2CAA2C,oBAAoB,QAAQ,EAAE;YAC/E,MAAM,EAAE,MAAM;YACd,IAAI,EAAE;gBACJ,KAAK,EAAE;oBACL;wBACE,MAAM,EAAE,CAAC,GAAG,WAAW,EAAE,CAAC;wBAC1B,IAAI,EAAE,eAAe;qBACtB;iBACF;aACF;SACF,CAAC,CACH,CAAA;IACH,CAAC;IAED,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC9B,QAAQ,CAAC,IAAI,CACX,OAAO,CAAC,2CAA2C,oBAAoB,QAAQ,EAAE;YAC/E,MAAM,EAAE,QAAQ;YAChB,IAAI,EAAE;gBACJ,KAAK,EAAE;oBACL;wBACE,MAAM,EAAE,CAAC,GAAG,WAAW,EAAE,CAAC;wBAC1B,IAAI,EAAE,cAAc;qBACrB;iBACF;aACF;SACF,CAAC,CACH,CAAA;IACH,CAAC;IAED,OAAO,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;AACpC,CAAC,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/snap-audiences/syncAudience/index.ts"],"names":[],"mappings":";;AAGA,qCAAiC;AACjC,2CAAkC;AAElC,MAAM,MAAM,GAAwC;IAClD,KAAK,EAAE,eAAe;IACtB,WAAW,EAAE,+BAA+B;IAC5C,mBAAmB,EAAE,gBAAgB;IACrC,MAAM,EAAN,eAAM;IACN,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;QACtC,OAAO,IAAA,gBAAI,EAAC,OAAO,EAAE,CAAC,OAAO,CAAC,CAAC,CAAA;IACjC,CAAC;IACD,YAAY,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;QAC3C,OAAO,IAAA,gBAAI,EAAC,OAAO,EAAE,OAAO,CAAC,CAAA;IAC/B,CAAC;CACF,CAAA;AAED,kBAAe,MAAM,CAAA"}
@@ -0,0 +1,18 @@
1
+ import { Payload } from './generated-types';
2
+ import { SCHEMA_TYPES } from './constants';
3
+ export interface PayloadWithIndex extends Payload {
4
+ index: number;
5
+ }
6
+ export interface OperationType {
7
+ method: 'POST' | 'DELETE';
8
+ type: SchemaType;
9
+ }
10
+ export interface AddRemoveUsersJSON {
11
+ users: [
12
+ {
13
+ schema: ["EMAIL_SHA256"] | ["PHONE_SHA256"] | ["MOBILE_AD_ID_SHA256"];
14
+ data: [string][];
15
+ }
16
+ ];
17
+ }
18
+ export type SchemaType = typeof SCHEMA_TYPES[keyof typeof SCHEMA_TYPES];
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/destinations/snap-audiences/syncAudience/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,19 @@
1
+ export interface RefreshTokenResponse {
2
+ access_token: string;
3
+ }
4
+ export interface SnapAudienceResponse {
5
+ segments: {
6
+ segment: {
7
+ id: string;
8
+ };
9
+ }[];
10
+ }
11
+ export interface CreateAudienceReq {
12
+ segments: {
13
+ name: string;
14
+ source_type: string;
15
+ ad_account_id: string;
16
+ description: string;
17
+ retention_in_days: number;
18
+ }[];
19
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/destinations/snap-audiences/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export declare const EXTERNAL_PROVIDER = "segment_io";
2
+ export declare const GQL_ENDPOINT = "https://api.stackadapt.com/graphql";
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GQL_ENDPOINT = exports.EXTERNAL_PROVIDER = void 0;
4
+ exports.EXTERNAL_PROVIDER = 'segment_io';
5
+ exports.GQL_ENDPOINT = 'https://api.stackadapt.com/graphql';
6
+ //# sourceMappingURL=common-constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common-constants.js","sourceRoot":"","sources":["../../../src/destinations/stackadapt-audiences/common-constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,iBAAiB,GAAG,YAAY,CAAA;AAEhC,QAAA,YAAY,GAAG,oCAAoC,CAAA"}
@@ -1,8 +1 @@
1
- import { RequestClient } from '@segment/actions-core';
2
- import { Settings } from './generated-types';
3
- import type { Payload as AudiencePayload } from './forwardAudienceEvent/generated-types';
4
- import type { Payload as RegularPayload } from './forwardProfile/generated-types';
5
- export declare function send(request: RequestClient, payloads: RegularPayload[] | AudiencePayload[], settings: Settings, isAudience: boolean): Promise<import("@segment/actions-core").ModifiedResponse<unknown>>;
6
1
  export declare function sha256hash(data: string): string;
7
- export declare function stringifyJsonWithEscapedQuotes(value: unknown): string;
8
- export declare function stringifyMappingSchemaForGraphQL(value: unknown): string;
@@ -1,203 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.send = send;
4
3
  exports.sha256hash = sha256hash;
5
- exports.stringifyJsonWithEscapedQuotes = stringifyJsonWithEscapedQuotes;
6
- exports.stringifyMappingSchemaForGraphQL = stringifyMappingSchemaForGraphQL;
7
- const constants_1 = require("./constants");
8
4
  const crypto_1 = require("crypto");
9
- async function send(request, payloads, settings, isAudience) {
10
- const fieldTypes = getDefaultFieldTypes();
11
- const fieldsToMap = getDefaultFieldsToMap();
12
- const advertiserId = settings.advertiser_id;
13
- const marketingStatus = payloads[0].marketing_status;
14
- const profileUpdates = payloads.map((p) => {
15
- const { user_id, standard_traits: { birth_date, birth_day, birth_month, birth_year, ...restStandardTraits } = {}, custom_traits, email } = p;
16
- const segment_computation_key = isAudience ? p.segment_computation_key : undefined;
17
- const segment_computation_id = isAudience ? p.segment_computation_id : undefined;
18
- const traits_or_props = isAudience ? p.traits_or_props : undefined;
19
- if (isAudience && custom_traits) {
20
- delete custom_traits[segment_computation_key];
21
- delete custom_traits[segment_computation_id];
22
- }
23
- let date;
24
- if (birth_date) {
25
- date = new Date(birth_date);
26
- }
27
- const profile = {
28
- userId: user_id,
29
- email,
30
- ...restStandardTraits,
31
- birth_day: (date ? date.getDate() : birth_day) ?? undefined,
32
- birth_month: (date ? date.getMonth() + 1 : birth_month) ?? undefined,
33
- birth_year: (date ? date.getFullYear() : birth_year) ?? undefined,
34
- ...custom_traits
35
- };
36
- if (isAudience && traits_or_props && segment_computation_key && segment_computation_id) {
37
- profile.audienceId = segment_computation_id;
38
- profile.audienceName = segment_computation_key;
39
- profile.action = traits_or_props[segment_computation_key] ? 'enter' : 'exit';
40
- }
41
- if (!isAudience && p.previous_id) {
42
- profile.previous_id = p.previous_id;
43
- }
44
- updateFieldsToMapAndFieldTypes(fieldsToMap, fieldTypes, custom_traits);
45
- return profile;
46
- });
47
- const mappings = getProfileMappings(Array.from(fieldsToMap), fieldTypes);
48
- const profiles = stringifyJsonWithEscapedQuotes(profileUpdates);
49
- const mutation = `mutation {
50
- upsertProfiles(
51
- input: {
52
- advertiserId: ${advertiserId},
53
- externalProvider: "${constants_1.EXTERNAL_PROVIDER}",
54
- syncId: "${sha256hash(profiles)}",
55
- profiles: "${profiles}"
56
- }
57
- ) {
58
- userErrors {
59
- message
60
- }
61
- }
62
- upsertProfileMapping(
63
- input: {
64
- advertiserId: ${advertiserId},
65
- mappingSchemaV2: ${mappings},
66
- isOptedIn: ${marketingStatus === constants_1.MarketingStatus.OPT_IN},
67
- mappableType: "${constants_1.EXTERNAL_PROVIDER}"
68
- }
69
- ) {
70
- userErrors {
71
- message
72
- }
73
- }
74
- ${isAudience ? audienceMutation(advertiserId, stringifyMappingSchemaForGraphQL(constants_1.MAPPING_SCHEMA)) : ""}
75
- }`;
76
- return await request(constants_1.GQL_ENDPOINT, {
77
- body: JSON.stringify({ query: mutation })
78
- });
79
- }
80
5
  function sha256hash(data) {
81
6
  const hash = (0, crypto_1.createHash)('sha256');
82
7
  hash.update(data);
83
8
  return hash.digest('hex');
84
9
  }
85
- function audienceMutation(advertiserId, audienceMapping) {
86
- return `upsertExternalAudienceMapping(
87
- input: {
88
- advertiserId: ${advertiserId},
89
- mappingSchema: ${audienceMapping},
90
- mappableType: "${constants_1.EXTERNAL_PROVIDER}"
91
- }
92
- ) {
93
- userErrors {
94
- message
95
- }
96
- }`;
97
- }
98
- function updateFieldsToMapAndFieldTypes(fieldsToMap, fieldTypes, customTraits = {}) {
99
- return Object.keys(customTraits).reduce((acc, key) => {
100
- const value = customTraits[key];
101
- if (key === '' || value === '') {
102
- return acc;
103
- }
104
- acc[key] = value;
105
- const standardFields = getDefaultFieldsToMap();
106
- if (!standardFields.has(key)) {
107
- fieldsToMap.add(key);
108
- if (value || value === 0) {
109
- const type = getType(value);
110
- if (fieldTypes[key] && fieldTypes[key] !== type) {
111
- fieldTypes[key] = 'STRING';
112
- }
113
- else {
114
- fieldTypes[key] = type;
115
- }
116
- }
117
- }
118
- return acc;
119
- }, {});
120
- }
121
- function getProfileMappings(customFields, fieldTypes) {
122
- const mappingSchema = [];
123
- for (const field of customFields) {
124
- const fieldConfig = constants_1.PROFILE_DEFAULT_FIELDS.find((f) => f.key === field);
125
- if (fieldConfig) {
126
- let destinationKey;
127
- switch (fieldConfig.key) {
128
- case 'user_id':
129
- destinationKey = 'external_id';
130
- break;
131
- default:
132
- destinationKey = fieldConfig.key;
133
- }
134
- mappingSchema.push({
135
- incomingKey: field,
136
- destinationKey,
137
- label: fieldConfig.label,
138
- type: fieldConfig.type.toUpperCase(),
139
- isPii: fieldConfig.isPii || false
140
- });
141
- }
142
- else {
143
- mappingSchema.push({
144
- incomingKey: field,
145
- destinationKey: field,
146
- label: generateLabel(field),
147
- type: fieldTypes[field] ?? 'STRING',
148
- isPii: false
149
- });
150
- }
151
- }
152
- return stringifyMappingSchemaForGraphQL(mappingSchema);
153
- }
154
- function generateLabel(field) {
155
- let label = field
156
- .replace(/_/g, ' ')
157
- .trim()
158
- .replace(/\b\w/g, (str) => str.toUpperCase());
159
- if (field.startsWith('audience')) {
160
- label = `External ${label}`;
161
- }
162
- return label;
163
- }
164
- function getType(value) {
165
- if (isDateStr(value))
166
- return 'DATE';
167
- return (typeof value).toUpperCase();
168
- }
169
- function isDateStr(value) {
170
- if (typeof value !== 'string')
171
- return false;
172
- const datePatterns = [
173
- /^\d{4}-\d{2}-\d{2}/,
174
- /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/,
175
- /^\d{1,2}\/\d{1,2}\/\d{4}/,
176
- /^\d{1,2}-\d{1,2}-\d{4}/
177
- ];
178
- const hasDatePattern = datePatterns.some(pattern => pattern.test(value));
179
- if (!hasDatePattern)
180
- return false;
181
- const parsed = Date.parse(value);
182
- return !isNaN(parsed);
183
- }
184
- function stringifyJsonWithEscapedQuotes(value) {
185
- const jsonString = JSON.stringify(value);
186
- return jsonString.replace(/"/g, '\\"');
187
- }
188
- function stringifyMappingSchemaForGraphQL(value) {
189
- let jsonString = JSON.stringify(value);
190
- jsonString = jsonString.replace(/"type":"([^"]+)"/g, (_, typeValue) => `type:${typeValue.toUpperCase()}`);
191
- jsonString = jsonString.replace(/"([a-zA-Z_][a-zA-Z0-9_]*)"\s*:/g, '$1:');
192
- return jsonString;
193
- }
194
- const getDefaultFieldsToMap = () => {
195
- return new Set(constants_1.PROFILE_DEFAULT_FIELDS.map(field => field.key));
196
- };
197
- const getDefaultFieldTypes = () => {
198
- return constants_1.PROFILE_DEFAULT_FIELDS.reduce((acc, field) => {
199
- acc[field.key] = field.type.toUpperCase();
200
- return acc;
201
- }, {});
202
- };
203
10
  //# sourceMappingURL=common-functions.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"common-functions.js","sourceRoot":"","sources":["../../../src/destinations/stackadapt-audiences/common-functions.ts"],"names":[],"mappings":";;AASA,oBA+FC;AAED,gCAIC;AA4HD,wEAKC;AAGD,4EAWC;AA3PD,2CAA0I;AAK1I,mCAAmC;AAE5B,KA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KAAK,CAAC,CAAC;IAGzC,OAAO,UAAU,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AACzC,CAAC;AAGD,SAAgB,gCAAgC,CAAC,KAAc;IAC7D,IAAI,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;IAGtC,UAAU,GAAG,UAAU,CAAC,OAAO,CAAC,mBAAmB,EAAE,CAAC,CAAC,EAAE,SAAiB,EAAE,EAAE,CAC5E,QAAQ,SAAS,CAAC,WAAW,EAAE,EAAE,CAAC,CAAA;IAGpC,UAAU,GAAG,UAAU,CAAC,OAAO,CAAC,iCAAiC,EAAE,KAAK,CAAC,CAAC;IAE1E,OAAO,UAAU,CAAA;AACnB,CAAC;AAED,MAAM,qBAAqB,GAAG,GAAgB,EAAE;IAC9C,OAAO,IAAI,GAAG,CAAC,kCAAsB,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAA;AAChE,CAAC,CAAA;AAED,MAAM,oBAAoB,GAAG,GAA2B,EAAE;IACxD,OAAO,kCAAsB,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;QAClD,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE,CAAA;QACzC,OAAO,GAAG,CAAA;IACZ,CAAC,EAAE,EAA4B,CAAC,CAAA;AAClC,CAAC,CAAA"}
1
+ {"version":3,"file":"common-functions.js","sourceRoot":"","sources":["../../../src/destinations/stackadapt-audiences/common-functions.ts"],"names":[],"mappings":";;AAGA,gCAIC;AAND,mCAAmC;AAEnC,SAAgB,UAAU,CAAC,IAAY;IACrC,MAAM,IAAI,GAAG,IAAA,mBAAU,EAAC,QAAQ,CAAC,CAAA;IACjC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IACjB,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AAC3B,CAAC"}
@@ -0,0 +1,15 @@
1
+ export interface AdvertiserScopesResponse {
2
+ data: {
3
+ tokenInfo: {
4
+ scopesByAdvertiser: {
5
+ nodes: {
6
+ advertiser: {
7
+ id: string;
8
+ name: string;
9
+ };
10
+ scopes: string[];
11
+ }[];
12
+ };
13
+ };
14
+ };
15
+ }
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=generated-types.js.map
3
+ //# sourceMappingURL=common-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common-types.js","sourceRoot":"","sources":["../../../src/destinations/stackadapt-audiences/common-types.ts"],"names":[],"mappings":""}