@segment/action-destinations 3.262.0-staging.1 → 3.263.0-staging-6ab80714d

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 (238) hide show
  1. package/dist/destinations/amazon-ads/generated-types.d.ts +0 -9
  2. package/dist/destinations/amazon-ads/index.d.ts +2 -2
  3. package/dist/destinations/amazon-ads/index.js +3 -180
  4. package/dist/destinations/amazon-ads/index.js.map +1 -1
  5. package/dist/destinations/amazon-ads/syncAudiences/generated-types.d.ts +0 -19
  6. package/dist/destinations/amazon-ads/syncAudiences/index.js +7 -170
  7. package/dist/destinations/amazon-ads/syncAudiences/index.js.map +1 -1
  8. package/dist/destinations/braze/updateUserProfile/__snapshots__/snapshot.test.d.ts +1 -0
  9. package/dist/destinations/braze/updateUserProfile/__snapshots__/snapshot.test.js +184 -0
  10. package/dist/destinations/braze/updateUserProfile/__snapshots__/snapshot.test.js.map +1 -0
  11. package/dist/destinations/chartmogul/index.js +1 -1
  12. package/dist/destinations/chartmogul/index.js.map +1 -1
  13. package/dist/destinations/customerio/utils.d.ts +1 -1
  14. package/dist/destinations/display-video-360/addToAudience/index.js +1 -2
  15. package/dist/destinations/display-video-360/addToAudience/index.js.map +1 -1
  16. package/dist/destinations/engage/sendgrid/previewApiLookup/api-lookups.d.ts +2 -5
  17. package/dist/destinations/engage/sendgrid/previewApiLookup/api-lookups.js +18 -98
  18. package/dist/destinations/engage/sendgrid/previewApiLookup/api-lookups.js.map +1 -1
  19. package/dist/destinations/engage/utils/EngageActionPerformer.js +2 -17
  20. package/dist/destinations/engage/utils/EngageActionPerformer.js.map +1 -1
  21. package/dist/destinations/engage/utils/operationTracking/OperationFinallyHooks.d.ts +0 -3
  22. package/dist/destinations/engage/utils/operationTracking/OperationFinallyHooks.js +0 -15
  23. package/dist/destinations/engage/utils/operationTracking/OperationFinallyHooks.js.map +1 -1
  24. package/dist/destinations/engage/utils/track.d.ts +17 -20
  25. package/dist/destinations/gameball/index.js +1 -1
  26. package/dist/destinations/gameball/index.js.map +1 -1
  27. package/dist/destinations/google-enhanced-conversions/functions.js.map +1 -1
  28. package/dist/destinations/hubspot/upsertCompany/index.js +10 -1
  29. package/dist/destinations/hubspot/upsertCompany/index.js.map +1 -1
  30. package/dist/destinations/hubspot/upsertCustomObjectRecord/index.js +4 -4
  31. package/dist/destinations/hubspot/upsertCustomObjectRecord/index.js.map +1 -1
  32. package/dist/destinations/index.js +3 -0
  33. package/dist/destinations/index.js.map +1 -1
  34. package/dist/destinations/inleads-ai/common-fields.d.ts +3 -0
  35. package/dist/destinations/inleads-ai/common-fields.js +238 -0
  36. package/dist/destinations/inleads-ai/common-fields.js.map +1 -0
  37. package/dist/destinations/inleads-ai/contants.d.ts +4 -0
  38. package/dist/destinations/inleads-ai/contants.js +8 -0
  39. package/dist/destinations/inleads-ai/contants.js.map +1 -0
  40. package/dist/destinations/inleads-ai/generated-types.d.ts +3 -0
  41. package/dist/destinations/inleads-ai/generated-types.js.map +1 -0
  42. package/dist/destinations/inleads-ai/group/generated-types.d.ts +44 -0
  43. package/dist/destinations/inleads-ai/group/generated-types.js.map +1 -0
  44. package/dist/destinations/{responsys/asyncMergePetRecords → inleads-ai/group}/index.d.ts +1 -1
  45. package/dist/destinations/inleads-ai/group/index.js +76 -0
  46. package/dist/destinations/inleads-ai/group/index.js.map +1 -0
  47. package/dist/destinations/inleads-ai/identify/generated-types.d.ts +46 -0
  48. package/dist/destinations/inleads-ai/identify/generated-types.js +3 -0
  49. package/dist/destinations/inleads-ai/identify/generated-types.js.map +1 -0
  50. package/dist/destinations/inleads-ai/identify/index.d.ts +5 -0
  51. package/dist/destinations/inleads-ai/identify/index.js +120 -0
  52. package/dist/destinations/inleads-ai/identify/index.js.map +1 -0
  53. package/dist/destinations/inleads-ai/index.d.ts +4 -0
  54. package/dist/destinations/inleads-ai/index.js +67 -0
  55. package/dist/destinations/inleads-ai/index.js.map +1 -0
  56. package/dist/destinations/inleads-ai/track/generated-types.d.ts +45 -0
  57. package/dist/destinations/inleads-ai/track/generated-types.js +3 -0
  58. package/dist/destinations/inleads-ai/track/generated-types.js.map +1 -0
  59. package/dist/destinations/inleads-ai/track/index.d.ts +5 -0
  60. package/dist/destinations/inleads-ai/track/index.js +64 -0
  61. package/dist/destinations/inleads-ai/track/index.js.map +1 -0
  62. package/dist/destinations/kameleoon/group/generated-types.d.ts +12 -0
  63. package/dist/destinations/kameleoon/group/generated-types.js +3 -0
  64. package/dist/destinations/kameleoon/group/generated-types.js.map +1 -0
  65. package/dist/destinations/kameleoon/group/index.d.ts +5 -0
  66. package/dist/destinations/kameleoon/group/index.js +94 -0
  67. package/dist/destinations/kameleoon/group/index.js.map +1 -0
  68. package/dist/destinations/kameleoon/identify/generated-types.d.ts +11 -0
  69. package/dist/destinations/kameleoon/identify/generated-types.js +3 -0
  70. package/dist/destinations/kameleoon/identify/generated-types.js.map +1 -0
  71. package/dist/destinations/kameleoon/identify/index.d.ts +5 -0
  72. package/dist/destinations/kameleoon/identify/index.js +87 -0
  73. package/dist/destinations/kameleoon/identify/index.js.map +1 -0
  74. package/dist/destinations/kameleoon/index.js +15 -9
  75. package/dist/destinations/kameleoon/index.js.map +1 -1
  76. package/dist/destinations/kameleoon/logEvent/generated-types.d.ts +2 -0
  77. package/dist/destinations/kameleoon/logEvent/index.js +13 -1
  78. package/dist/destinations/kameleoon/logEvent/index.js.map +1 -1
  79. package/dist/destinations/kameleoon/page/generated-types.d.ts +15 -0
  80. package/dist/destinations/kameleoon/page/generated-types.js +3 -0
  81. package/dist/destinations/kameleoon/page/generated-types.js.map +1 -0
  82. package/dist/destinations/kameleoon/page/index.d.ts +5 -0
  83. package/dist/destinations/kameleoon/page/index.js +99 -0
  84. package/dist/destinations/kameleoon/page/index.js.map +1 -0
  85. package/dist/destinations/klaviyo/functions.d.ts +4 -7
  86. package/dist/destinations/klaviyo/functions.js +1 -80
  87. package/dist/destinations/klaviyo/functions.js.map +1 -1
  88. package/dist/destinations/klaviyo/removeProfile/index.js +0 -2
  89. package/dist/destinations/klaviyo/removeProfile/index.js.map +1 -1
  90. package/dist/destinations/klaviyo/removeProfileToList/generated-types.d.ts +4 -0
  91. package/dist/destinations/klaviyo/removeProfileToList/generated-types.js +3 -0
  92. package/dist/destinations/klaviyo/removeProfileToList/generated-types.js.map +1 -0
  93. package/dist/destinations/{responsys/asyncMergeProfileListMembers → klaviyo/removeProfileToList}/index.d.ts +1 -1
  94. package/dist/destinations/klaviyo/removeProfileToList/index.js +42 -0
  95. package/dist/destinations/klaviyo/removeProfileToList/index.js.map +1 -0
  96. package/dist/destinations/klaviyo/types.d.ts +0 -97
  97. package/dist/destinations/klaviyo/upsertProfile/index.js +19 -29
  98. package/dist/destinations/klaviyo/upsertProfile/index.js.map +1 -1
  99. package/dist/destinations/koala/identify/index.js +6 -1
  100. package/dist/destinations/koala/identify/index.js.map +1 -1
  101. package/dist/destinations/liveramp-audiences/audienceEnteredS3/index.js +2 -2
  102. package/dist/destinations/liveramp-audiences/audienceEnteredS3/index.js.map +1 -1
  103. package/dist/destinations/liveramp-audiences/audienceEnteredSftp/index.js +2 -2
  104. package/dist/destinations/liveramp-audiences/audienceEnteredSftp/index.js.map +1 -1
  105. package/dist/destinations/marketo-static-lists/addToList/index.js +2 -4
  106. package/dist/destinations/marketo-static-lists/addToList/index.js.map +1 -1
  107. package/dist/destinations/moloco-rmp/index.js +2 -2
  108. package/dist/destinations/responsys/index.js +6 -2
  109. package/dist/destinations/responsys/index.js.map +1 -1
  110. package/dist/destinations/responsys/sendAudience/generated-types.d.ts +1 -1
  111. package/dist/destinations/responsys/sendAudience/index.js +14 -4
  112. package/dist/destinations/responsys/sendAudience/index.js.map +1 -1
  113. package/dist/destinations/responsys/sendCustomTraits/generated-types.d.ts +1 -1
  114. package/dist/destinations/responsys/sendCustomTraits/index.js +14 -4
  115. package/dist/destinations/responsys/sendCustomTraits/index.js.map +1 -1
  116. package/dist/destinations/responsys/utils.d.ts +2 -2
  117. package/dist/destinations/responsys/utils.js +21 -5
  118. package/dist/destinations/responsys/utils.js.map +1 -1
  119. package/dist/destinations/salesforce/generated-types.d.ts +2 -0
  120. package/dist/destinations/salesforce/index.d.ts +1 -1
  121. package/dist/destinations/salesforce/index.js +22 -10
  122. package/dist/destinations/salesforce/index.js.map +1 -1
  123. package/dist/destinations/salesforce/sf-operations.d.ts +3 -1
  124. package/dist/destinations/salesforce/sf-operations.js +25 -0
  125. package/dist/destinations/salesforce/sf-operations.js.map +1 -1
  126. package/dist/destinations/segment/segment-properties.js +2 -2
  127. package/dist/destinations/segment/segment-properties.js.map +1 -1
  128. package/dist/destinations/snap-conversions-api/_tests_/capiV3tests.js +5 -82
  129. package/dist/destinations/snap-conversions-api/_tests_/capiV3tests.js.map +1 -1
  130. package/dist/destinations/snap-conversions-api/_tests_/index.test.js +420 -488
  131. package/dist/destinations/snap-conversions-api/_tests_/index.test.js.map +1 -1
  132. package/dist/destinations/snap-conversions-api/index.js +42 -42
  133. package/dist/destinations/snap-conversions-api/index.js.map +1 -1
  134. package/dist/destinations/snap-conversions-api/reportConversionEvent/generated-types.d.ts +97 -18
  135. package/dist/destinations/snap-conversions-api/reportConversionEvent/index.js +7 -29
  136. package/dist/destinations/snap-conversions-api/reportConversionEvent/index.js.map +1 -1
  137. package/dist/destinations/snap-conversions-api/reportConversionEvent/snap-capi-input-fields-deprecated.d.ts +31 -0
  138. package/dist/destinations/snap-conversions-api/reportConversionEvent/snap-capi-input-fields-deprecated.js +174 -0
  139. package/dist/destinations/snap-conversions-api/reportConversionEvent/snap-capi-input-fields-deprecated.js.map +1 -0
  140. package/dist/destinations/snap-conversions-api/reportConversionEvent/snap-capi-input-fields-v3.d.ts +16 -0
  141. package/dist/destinations/snap-conversions-api/reportConversionEvent/snap-capi-input-fields-v3.js +640 -0
  142. package/dist/destinations/snap-conversions-api/reportConversionEvent/snap-capi-input-fields-v3.js.map +1 -0
  143. package/dist/destinations/snap-conversions-api/reportConversionEvent/snap-capi-v3.d.ts +0 -4
  144. package/dist/destinations/snap-conversions-api/reportConversionEvent/snap-capi-v3.js +593 -119
  145. package/dist/destinations/snap-conversions-api/reportConversionEvent/snap-capi-v3.js.map +1 -1
  146. package/dist/destinations/snap-conversions-api/reportConversionEvent/utils.d.ts +3 -4
  147. package/dist/destinations/snap-conversions-api/reportConversionEvent/utils.js +6 -1
  148. package/dist/destinations/snap-conversions-api/reportConversionEvent/utils.js.map +1 -1
  149. package/dist/destinations/spiffy/generated-types.d.ts +5 -0
  150. package/dist/destinations/spiffy/generated-types.js +3 -0
  151. package/dist/destinations/spiffy/generated-types.js.map +1 -0
  152. package/dist/destinations/spiffy/index.d.ts +4 -0
  153. package/dist/destinations/spiffy/index.js +62 -0
  154. package/dist/destinations/spiffy/index.js.map +1 -0
  155. package/dist/destinations/spiffy/send/generated-types.d.ts +8 -0
  156. package/dist/destinations/spiffy/send/generated-types.js +3 -0
  157. package/dist/destinations/spiffy/send/generated-types.js.map +1 -0
  158. package/dist/destinations/spiffy/send/index.d.ts +5 -0
  159. package/dist/destinations/spiffy/send/index.js +42 -0
  160. package/dist/destinations/spiffy/send/index.js.map +1 -0
  161. package/dist/destinations/stackadapt/forwardEvent/generated-types.d.ts +4 -4
  162. package/dist/destinations/stackadapt/forwardEvent/index.js +11 -7
  163. package/dist/destinations/stackadapt/forwardEvent/index.js.map +1 -1
  164. package/dist/destinations/tiktok-conversions/common_fields.d.ts +2 -0
  165. package/dist/destinations/tiktok-conversions/common_fields.js +244 -0
  166. package/dist/destinations/tiktok-conversions/common_fields.js.map +1 -0
  167. package/dist/destinations/{tiktok-offline-conversions/reportOfflineEvent → tiktok-conversions}/formatter.js +11 -11
  168. package/dist/destinations/tiktok-conversions/formatter.js.map +1 -0
  169. package/dist/destinations/tiktok-conversions/index.js +163 -75
  170. package/dist/destinations/tiktok-conversions/index.js.map +1 -1
  171. package/dist/destinations/tiktok-conversions/reportWebEvent/generated-types.d.ts +12 -4
  172. package/dist/destinations/tiktok-conversions/reportWebEvent/index.d.ts +1 -1
  173. package/dist/destinations/tiktok-conversions/reportWebEvent/index.js +5 -233
  174. package/dist/destinations/tiktok-conversions/reportWebEvent/index.js.map +1 -1
  175. package/dist/destinations/tiktok-conversions/utils.d.ts +4 -0
  176. package/dist/destinations/tiktok-conversions/utils.js +65 -0
  177. package/dist/destinations/tiktok-conversions/utils.js.map +1 -0
  178. package/dist/destinations/trackey/group.types.d.ts +11 -0
  179. package/dist/destinations/trackey/group.types.js +3 -0
  180. package/dist/destinations/trackey/group.types.js.map +1 -0
  181. package/dist/destinations/trackey/identify.types.d.ts +11 -0
  182. package/dist/destinations/trackey/identify.types.js +3 -0
  183. package/dist/destinations/trackey/identify.types.js.map +1 -0
  184. package/dist/destinations/trackey/track.types.d.ts +12 -0
  185. package/dist/destinations/trackey/track.types.js +3 -0
  186. package/dist/destinations/trackey/track.types.js.map +1 -0
  187. package/dist/destinations/xtremepush/generated-types.d.ts +4 -0
  188. package/dist/destinations/xtremepush/generated-types.js +3 -0
  189. package/dist/destinations/xtremepush/generated-types.js.map +1 -0
  190. package/dist/destinations/xtremepush/identify/generated-types.d.ts +14 -0
  191. package/dist/destinations/xtremepush/identify/generated-types.js +3 -0
  192. package/dist/destinations/xtremepush/identify/generated-types.js.map +1 -0
  193. package/dist/destinations/xtremepush/identify/index.d.ts +5 -0
  194. package/dist/destinations/xtremepush/identify/index.js +87 -0
  195. package/dist/destinations/xtremepush/identify/index.js.map +1 -0
  196. package/dist/destinations/xtremepush/index.d.ts +4 -0
  197. package/dist/destinations/xtremepush/index.js +66 -0
  198. package/dist/destinations/xtremepush/index.js.map +1 -0
  199. package/dist/destinations/xtremepush/track/generated-types.d.ts +15 -0
  200. package/dist/destinations/xtremepush/track/generated-types.js +3 -0
  201. package/dist/destinations/xtremepush/track/generated-types.js.map +1 -0
  202. package/dist/destinations/xtremepush/track/index.d.ts +5 -0
  203. package/dist/destinations/xtremepush/track/index.js +95 -0
  204. package/dist/destinations/xtremepush/track/index.js.map +1 -0
  205. package/dist/destinations/yahoo-audiences/createCustomerNode/generated-types.d.ts +4 -0
  206. package/dist/destinations/yahoo-audiences/createCustomerNode/generated-types.js +3 -0
  207. package/dist/destinations/yahoo-audiences/createCustomerNode/generated-types.js.map +1 -0
  208. package/dist/destinations/yahoo-audiences/createCustomerNode/index.d.ts +5 -0
  209. package/dist/destinations/yahoo-audiences/createCustomerNode/index.js +26 -0
  210. package/dist/destinations/yahoo-audiences/createCustomerNode/index.js.map +1 -0
  211. package/dist/destinations/yahoo-audiences/createSegment/generated-types.d.ts +6 -0
  212. package/dist/destinations/yahoo-audiences/createSegment/generated-types.js +3 -0
  213. package/dist/destinations/yahoo-audiences/createSegment/generated-types.js.map +1 -0
  214. package/dist/destinations/yahoo-audiences/createSegment/index.d.ts +5 -0
  215. package/dist/destinations/yahoo-audiences/createSegment/index.js +38 -0
  216. package/dist/destinations/yahoo-audiences/createSegment/index.js.map +1 -0
  217. package/dist/destinations/yahoo-audiences/utils.d.ts +4 -0
  218. package/dist/destinations/yahoo-audiences/utils.js +30 -0
  219. package/dist/destinations/yahoo-audiences/utils.js.map +1 -0
  220. package/package.json +3 -3
  221. package/dist/destinations/responsys/asyncMergePetRecords/generated-types.d.ts +0 -14
  222. package/dist/destinations/responsys/asyncMergePetRecords/generated-types.js.map +0 -1
  223. package/dist/destinations/responsys/asyncMergePetRecords/index.js +0 -113
  224. package/dist/destinations/responsys/asyncMergePetRecords/index.js.map +0 -1
  225. package/dist/destinations/responsys/asyncMergeProfileListMembers/generated-types.d.ts +0 -20
  226. package/dist/destinations/responsys/asyncMergeProfileListMembers/generated-types.js.map +0 -1
  227. package/dist/destinations/responsys/asyncMergeProfileListMembers/index.js +0 -174
  228. package/dist/destinations/responsys/asyncMergeProfileListMembers/index.js.map +0 -1
  229. package/dist/destinations/responsys/rsp-operations.d.ts +0 -14
  230. package/dist/destinations/responsys/rsp-operations.js +0 -33
  231. package/dist/destinations/responsys/rsp-operations.js.map +0 -1
  232. package/dist/destinations/responsys/rsp-properties.d.ts +0 -4
  233. package/dist/destinations/responsys/rsp-properties.js +0 -27
  234. package/dist/destinations/responsys/rsp-properties.js.map +0 -1
  235. package/dist/destinations/tiktok-offline-conversions/reportOfflineEvent/formatter.js.map +0 -1
  236. package/dist/destinations/{responsys/asyncMergePetRecords → inleads-ai}/generated-types.js +0 -0
  237. package/dist/destinations/{responsys/asyncMergeProfileListMembers → inleads-ai/group}/generated-types.js +0 -0
  238. package/dist/destinations/{tiktok-offline-conversions/reportOfflineEvent → tiktok-conversions}/formatter.d.ts +1 -1
@@ -1,12 +1,3 @@
1
1
  export interface Settings {
2
2
  region: string;
3
3
  }
4
- export interface AudienceSettings {
5
- description: string;
6
- countryCode?: string;
7
- externalAudienceId: string;
8
- cpmCents?: number;
9
- currency?: string;
10
- ttl?: number;
11
- advertiserId: string;
12
- }
@@ -1,4 +1,4 @@
1
1
  import type { AudienceDestinationDefinition } from '@segment/actions-core';
2
- import type { Settings, AudienceSettings } from './generated-types';
3
- declare const destination: AudienceDestinationDefinition<Settings, AudienceSettings>;
2
+ import type { Settings } from './generated-types';
3
+ declare const destination: AudienceDestinationDefinition<Settings>;
4
4
  export default destination;
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const actions_core_1 = require("@segment/actions-core");
7
- const utils_1 = require("./utils");
8
7
  const syncAudiences_1 = __importDefault(require("./syncAudiences"));
9
8
  const destination = {
10
9
  name: 'Amazon Ads',
@@ -21,15 +20,12 @@ const destination = {
21
20
  { label: 'Europe (EU)', value: 'https://advertising-api-eu.amazon.com' },
22
21
  { label: 'Far East (FE)', value: 'https://advertising-api-fe.amazon.com' }
23
22
  ],
24
- default: 'https://advertising-api.amazon.com',
23
+ default: 'North America (NA)',
25
24
  type: 'string',
26
25
  required: true
27
26
  }
28
27
  },
29
28
  testAuthentication: async (request, { auth }) => {
30
- if (!process.env.ACTIONS_AMAZON_ADS_CLIENT_ID) {
31
- throw new actions_core_1.IntegrationError('Missing amazon API client ID', 'MISSING_REQUIRED_FIELD', 400);
32
- }
33
29
  if (!auth?.accessToken) {
34
30
  throw new actions_core_1.InvalidAuthenticationError('Please authenticate via Oauth before enabling the destination.');
35
31
  }
@@ -72,188 +68,15 @@ const destination = {
72
68
  extendRequest({ auth }) {
73
69
  return {
74
70
  headers: {
75
- authorization: `Bearer ${auth?.accessToken}`,
76
- 'Amazon-Advertising-API-ClientID': process.env.ACTIONS_AMAZON_ADS_CLIENT_ID || ''
71
+ authorization: `Bearer ${auth?.accessToken}`
77
72
  }
78
73
  };
79
74
  },
80
- audienceFields: {
81
- description: {
82
- type: 'string',
83
- label: 'Description',
84
- required: true,
85
- description: 'The audience description. Must be an alphanumeric, non-null string between 0 to 1000 characters in length.'
86
- },
87
- countryCode: {
88
- type: 'string',
89
- label: 'Country Code',
90
- required: false,
91
- description: 'A String value representing ISO 3166-1 alpha-2 country code for the members in this audience.'
92
- },
93
- externalAudienceId: {
94
- type: 'string',
95
- label: 'External Audience Id',
96
- required: true,
97
- description: 'The user-defined audience identifier.'
98
- },
99
- cpmCents: {
100
- label: 'CPM Cents',
101
- type: 'number',
102
- description: `Cost per thousand impressions (CPM) in cents. For example, $1.00 = 100 cents.`
103
- },
104
- currency: {
105
- label: 'Currency',
106
- type: 'string',
107
- description: `The price paid. Base units depend on the currency. As an example, USD should be reported as Dollars.Cents, whereas JPY should be reported as a whole number of Yen. All provided values will be rounded to two digits with toFixed(2)`
108
- },
109
- ttl: {
110
- type: 'number',
111
- label: 'Time-to-live',
112
- required: false,
113
- description: 'Time-to-live in seconds. The amount of time the record is associated with the audience.'
114
- },
115
- advertiserId: {
116
- label: 'Advertiser ID',
117
- description: 'Advertiser Id',
118
- type: 'string',
119
- required: true
120
- }
121
- },
75
+ audienceFields: {},
122
76
  audienceConfig: {
123
77
  mode: {
124
78
  type: 'synced',
125
79
  full_audience_sync: false
126
- },
127
- async createAudience(request, createAudienceInput) {
128
- const { audienceName, statsContext } = createAudienceInput;
129
- const endpoint = createAudienceInput.settings.region;
130
- const description = createAudienceInput.audienceSettings?.description;
131
- const advertiser_id = createAudienceInput.audienceSettings?.advertiserId;
132
- const external_audience_id = createAudienceInput.audienceSettings?.externalAudienceId;
133
- const country_code = createAudienceInput.audienceSettings?.countryCode;
134
- const ttl = createAudienceInput.audienceSettings?.ttl;
135
- const currency = createAudienceInput.audienceSettings?.currency;
136
- const cpm_cents = createAudienceInput.audienceSettings?.cpmCents;
137
- const { statsClient, tags: statsTags } = statsContext || {};
138
- const statsName = 'createAmazonAudience';
139
- statsTags?.push(`slug:${destination.slug}`);
140
- statsClient?.incr(`${statsName}.intialise`, 1, statsTags);
141
- if (!advertiser_id) {
142
- throw new actions_core_1.IntegrationError('Missing advertiserId value', 'MISSING_REQUIRED_FIELD', 400);
143
- }
144
- if (!description) {
145
- throw new actions_core_1.IntegrationError('Missing Description value', 'MISSING_REQUIRED_FIELD', 400);
146
- }
147
- if (!external_audience_id) {
148
- throw new actions_core_1.IntegrationError('Missing External Audience Id value', 'MISSING_REQUIRED_FIELD', 400);
149
- }
150
- if (!audienceName) {
151
- throw new actions_core_1.IntegrationError('Missing Audience name value', 'MISSING_REQUIRED_FIELD', 400);
152
- }
153
- const payload = {
154
- name: audienceName,
155
- description: description,
156
- targetResource: {
157
- advertiserId: advertiser_id
158
- },
159
- metadata: {
160
- externalAudienceId: external_audience_id
161
- }
162
- };
163
- if (country_code) {
164
- payload.countryCode = country_code;
165
- }
166
- if (ttl) {
167
- payload.metadata.ttl = ttl;
168
- }
169
- if (cpm_cents && currency) {
170
- payload.metadata.audienceFees = [];
171
- payload.metadata?.audienceFees.push({
172
- currency,
173
- cpmCents: cpm_cents
174
- });
175
- }
176
- statsTags?.push(`slug:${destination.slug}`);
177
- statsClient?.incr(`${statsName}.call`, 1, statsTags);
178
- try {
179
- let payloadString = JSON.stringify(payload);
180
- const regex = /"advertiserId":"(\d+)"/;
181
- payloadString = payloadString.replace(regex, '"advertiserId":$1');
182
- const response = await request(`${endpoint}/amc/audiences/metadata`, {
183
- method: 'POST',
184
- body: payloadString,
185
- headers: {
186
- 'Content-Type': 'application/vnd.amcaudiences.v1+json'
187
- }
188
- });
189
- const r = await response.json();
190
- const externalId = r?.audienceId;
191
- if (!externalId) {
192
- statsClient?.incr(`${statsName}.error`, 1, statsTags);
193
- throw new actions_core_1.IntegrationError('Invalid response from create audience request', 'INVALID_RESPONSE', 400);
194
- }
195
- statsClient?.incr(`${statsName}.success`, 1, statsTags);
196
- return {
197
- externalId
198
- };
199
- }
200
- catch (e) {
201
- if (e instanceof utils_1.AmazonAdsError) {
202
- const message = JSON.parse(e.response?.data?.message || '');
203
- statsTags?.push(`error:${message}`);
204
- statsClient?.incr(`${statsName}.error`, 1, statsTags);
205
- throw new actions_core_1.APIError(message, e.response?.status);
206
- }
207
- else if (e instanceof actions_core_1.IntegrationError) {
208
- statsTags?.push(`error:${e.message}`);
209
- statsClient?.incr(`${statsName}.error`, 1, statsTags);
210
- throw new actions_core_1.APIError(e.message, 400);
211
- }
212
- else {
213
- statsTags?.push(`error:${e}`);
214
- statsClient?.incr(`${statsName}.error`, 1, statsTags);
215
- throw e;
216
- }
217
- }
218
- },
219
- async getAudience(request, getAudienceInput) {
220
- const { statsContext } = getAudienceInput;
221
- const audience_id = getAudienceInput.externalId;
222
- const endpoint = getAudienceInput.settings.region;
223
- const { statsClient, tags: statsTags } = statsContext || {};
224
- const statsName = 'getAudience';
225
- statsTags?.push(`slug:${destination.slug}`);
226
- statsClient?.incr(`${statsName}.call`, 1, statsTags);
227
- if (!audience_id) {
228
- throw new actions_core_1.IntegrationError('Missing audience_id value', 'MISSING_REQUIRED_FIELD', 400);
229
- }
230
- try {
231
- const response = await request(`${endpoint}/amc/audiences/metadata/${audience_id}`, {
232
- method: 'GET'
233
- });
234
- const r = await response.json();
235
- const externalId = r?.audienceId;
236
- if (externalId != getAudienceInput.externalId) {
237
- statsClient?.incr(`${statsName}.error`, 1, statsTags);
238
- throw new actions_core_1.IntegrationError("Unable to verify ownership over audience. Segment Audience ID doesn't match Amazon Ads ID.", 'INVALID_REQUEST_DATA', 400);
239
- }
240
- statsClient?.incr(`${statsName}.success`, 1, statsTags);
241
- return {
242
- externalId
243
- };
244
- }
245
- catch (e) {
246
- if (e instanceof utils_1.AmazonAdsError) {
247
- const message = JSON.parse(e.response?.data?.message || '');
248
- throw new actions_core_1.APIError(message, e.response?.status);
249
- }
250
- else if (e instanceof actions_core_1.IntegrationError) {
251
- throw new actions_core_1.APIError(e.message, 400);
252
- }
253
- else {
254
- throw e;
255
- }
256
- }
257
80
  }
258
81
  },
259
82
  actions: {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/destinations/amazon-ads/index.ts"],"names":[],"mappings":";;;;;AACA,wDAA0G;AAG1G,mCAAyD;AAEzD,oEAA2C;AAE3C,MAAM,WAAW,GAA8D;IAC7E,IAAI,EAAE,YAAY;IAClB,IAAI,EAAE,oBAAoB;IAC1B,IAAI,EAAE,OAAO;IAEb,cAAc,EAAE;QACd,MAAM,EAAE,QAAQ;QAChB,MAAM,EAAE;YACN,MAAM,EAAE;gBACN,KAAK,EAAE,QAAQ;gBACf,WAAW,EAAE,6CAA6C;gBAC1D,OAAO,EAAE;oBACP,EAAE,KAAK,EAAE,oBAAoB,EAAE,KAAK,EAAE,oCAAoC,EAAE;oBAC5E,EAAE,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,uCAAuC,EAAE;oBACxE,EAAE,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,uCAAuC,EAAE;iBAC3E;gBACD,OAAO,EAAE,oCAAoC;gBAC7C,IAAI,EAAE,QAAQ;gBACd,QAAQ,EAAE,IAAI;aACf;SACF;QACD,kBAAkB,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE;YAC9C,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,4BAA4B,EAAE;gBAC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AqB,EAChC,GAAG,CACJ,CAAA;iBACF;gBAED,MAAM,IAAI,+BAAgB,CACxB,+CAA+C,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,EAC5E,yBAAU,CAAC,oBAAoB,EAC/B,GAAG,CACJ,CAAA;aACF;YAED,OAAO,EAAE,WAAW,EAAE,GAAG,EAAE,IAAI,EAAE,YAAY,EAAE,CAAA;QACjD,CAAC;KACF;IACD,aAAa,CAAC,EAAE,IAAI,EAAE;QACpB,OAAO;YACL,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,IAAI,EAAE,WAAW,EAAE;aAC7C;SACF,CAAA;IACH,CAAC;IAED,cAAc,EAAE,EAAE;IAElB,cAAc,EAAE;QACd,IAAI,EAAE;YACJ,IAAI,EAAE,QAAQ;YACd,kBAAkB,EAAE,KAAK;SAC1B;KAWF;IACD,OAAO,EAAE;QACP,aAAa,EAAb,uBAAa;KACd;CACF,CAAA;AAED,kBAAe,WAAW,CAAA"}
@@ -1,21 +1,2 @@
1
1
  export interface Payload {
2
- records: {
3
- externalUserId: string;
4
- action: string;
5
- countryCode?: string;
6
- measurements?: {
7
- [k: string]: unknown;
8
- };
9
- hashedPII: {
10
- firstname?: string;
11
- address?: string;
12
- phone?: string;
13
- city?: string;
14
- state?: string;
15
- email?: string;
16
- lastname?: string;
17
- postal?: string;
18
- }[];
19
- }[];
20
- audienceId: number;
21
2
  }
@@ -1,178 +1,15 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
2
  Object.defineProperty(exports, "__esModule", { value: true });
22
- const actions_core_1 = require("@segment/actions-core");
23
- const utils_1 = require("../utils");
24
- const crypto = __importStar(require("crypto"));
25
3
  const action = {
26
- title: 'Sync Audience',
4
+ title: 'Sync Audiences',
27
5
  description: 'Sync audiences from Segment to Amazon Ads Audience.',
28
- defaultSubscription: 'event = "Audience Entered" or event = "Audience Exited"',
29
- fields: {
30
- records: {
31
- label: 'Records',
32
- description: 'Records to create and upload audiences to Amazon DSP.',
33
- type: 'object',
34
- multiple: true,
35
- required: true,
36
- properties: {
37
- externalUserId: {
38
- label: 'External User ID',
39
- description: 'This is an external user identifier defined by data providers.',
40
- type: 'string',
41
- required: true
42
- },
43
- action: {
44
- label: 'User Action',
45
- description: 'A specific key used to define action type.',
46
- type: 'string',
47
- required: true,
48
- choices: [
49
- { label: `Create`, value: 'CREATE' },
50
- { label: 'Delete', value: 'DELETE' }
51
- ],
52
- default: 'CREATE'
53
- },
54
- countryCode: {
55
- label: 'Country Code',
56
- description: 'A String value representing ISO 3166-1 alpha-2 country code for the members in this audience.',
57
- type: 'string'
58
- },
59
- measurements: {
60
- label: 'Measurements',
61
- type: 'object'
62
- },
63
- hashedPII: {
64
- label: `hashed PII`,
65
- description: 'List of hashed personally-identifiable information records to be matched with Amazon identities for future use. All inputs must be properly normalized and SHA-256 hashed.',
66
- type: 'object',
67
- required: true,
68
- multiple: true,
69
- properties: {
70
- firstname: {
71
- label: 'Measurements',
72
- type: 'string'
73
- },
74
- address: {
75
- label: 'Measurements',
76
- type: 'string'
77
- },
78
- phone: {
79
- label: 'Measurements',
80
- type: 'string'
81
- },
82
- city: {
83
- label: 'Measurements',
84
- type: 'string'
85
- },
86
- state: {
87
- label: 'Measurements',
88
- type: 'string'
89
- },
90
- email: {
91
- label: 'Measurements',
92
- type: 'string'
93
- },
94
- lastname: {
95
- label: 'Measurements',
96
- type: 'string'
97
- },
98
- postal: {
99
- label: 'Measurements',
100
- type: 'string'
101
- }
102
- }
103
- }
104
- }
105
- },
106
- audienceId: {
107
- label: 'Audience ID',
108
- type: 'number',
109
- required: true,
110
- description: 'An number value representing the Amazon audience identifier. This is the identifier that is returned during audience creation.'
111
- }
112
- },
113
- perform: (request, { settings, payload, statsContext }) => {
114
- return processPayload(request, settings, payload, statsContext);
115
- }
116
- };
117
- async function processPayload(request, settings, payload, statsContext) {
118
- if (!payload.audienceId) {
119
- throw new actions_core_1.PayloadValidationError('Audience ID is required.');
120
- }
121
- const { statsClient, tags: statsTags } = statsContext || {};
122
- const statsName = 'syncAmazonAudience';
123
- statsClient?.incr(`${statsName}.intialise`, 1, statsTags);
124
- try {
125
- for (const record of payload.records) {
126
- for (const pii of record.hashedPII) {
127
- for (const key in pii) {
128
- if (pii[key] !== undefined) {
129
- pii[key] = await normalizeAndHash(pii[key]);
130
- }
131
- }
132
- }
133
- }
134
- const response = await request(`${settings.region}/amc/audiences/records`, {
135
- method: 'POST',
136
- json: payload,
137
- headers: {
138
- 'Content-Type': 'application/vnd.amcaudiences.v1+json'
139
- }
6
+ fields: {},
7
+ perform: (request, data) => {
8
+ return request('https://example.com', {
9
+ method: 'post',
10
+ json: data.payload
140
11
  });
141
- statsClient?.incr(`${statsName}.success`, 1, statsTags);
142
- const result = await response.json();
143
- const jobRequestId = result?.jobRequestId;
144
- statsTags?.push(`jobRequestId:${jobRequestId}`);
145
- statsClient?.incr(`${statsName}.success`, 1, statsTags);
146
- if (!jobRequestId) {
147
- throw new actions_core_1.IntegrationError('Invalid response from upload audinece record call', 'INVALID_RESPONSE', 400);
148
- }
149
- return {
150
- result
151
- };
152
- }
153
- catch (e) {
154
- if (e instanceof utils_1.AmazonAdsError) {
155
- const message = JSON.parse(e.response?.data?.message || '');
156
- statsTags?.push(`error:${message}`);
157
- statsClient?.incr(`${statsName}.error`, 1, statsTags);
158
- throw new actions_core_1.APIError(message, e.response?.status);
159
- }
160
- else if (e instanceof actions_core_1.IntegrationError) {
161
- statsTags?.push(`error:${e.message}`);
162
- statsClient?.incr(`${statsName}.error`, 1, statsTags);
163
- throw new actions_core_1.APIError(e.message, 400);
164
- }
165
- else {
166
- statsTags?.push(`error:${e}`);
167
- statsClient?.incr(`${statsName}.error`, 1, statsTags);
168
- throw e;
169
- }
170
12
  }
171
- }
172
- async function normalizeAndHash(data) {
173
- const normalizedData = data.toLowerCase().trim();
174
- const sha256Hash = crypto.createHash('sha256').update(normalizedData).digest('hex');
175
- return sha256Hash;
176
- }
13
+ };
177
14
  exports.default = action;
178
15
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/amazon-ads/syncAudiences/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AACA,wDAA0F;AAG1F,oCAAyC;AACzC,+CAAgC;AAEhC,MAAM,MAAM,GAAwC;IAClD,KAAK,EAAE,eAAe;IACtB,WAAW,EAAE,qDAAqD;IAClE,mBAAmB,EAAE,yDAAyD;IAC9E,MAAM,EAAE;QACN,OAAO,EAAE;YACP,KAAK,EAAE,SAAS;YAChB,WAAW,EAAE,uDAAuD;YACpE,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,IAAI;YACd,QAAQ,EAAE,IAAI;YACd,UAAU,EAAE;gBACV,cAAc,EAAE;oBACd,KAAK,EAAE,kBAAkB;oBACzB,WAAW,EAAE,gEAAgE;oBAC7E,IAAI,EAAE,QAAQ;oBACd,QAAQ,EAAE,IAAI;iBACf;gBACD,MAAM,EAAE;oBACN,KAAK,EAAE,aAAa;oBACpB,WAAW,EAAE,4CAA4C;oBACzD,IAAI,EAAE,QAAQ;oBACd,QAAQ,EAAE,IAAI;oBACd,OAAO,EAAE;wB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CAAC,CAAA;YACrD,MAAM,CAAC,CAAA;SACR;KACF;AACH,CAAC;AAED,KAAK,UAAU,gBAAgB,CAAC,IAAY;IAE1C,MAAM,cAAc,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,CAAA;IAEhD,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IAEnF,OAAO,UAAU,CAAA;AACnB,CAAC;AAED,kBAAe,MAAM,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/amazon-ads/syncAudiences/index.ts"],"names":[],"mappings":";;AAIA,MAAM,MAAM,GAAwC;IAClD,KAAK,EAAE,gBAAgB;IACvB,WAAW,EAAE,qDAAqD;IAClE,MAAM,EAAE,EAAE;IACV,OAAO,EAAE,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE;QACzB,OAAO,OAAO,CAAC,qBAAqB,EAAE;YACpC,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,IAAI,CAAC,OAAO;SACnB,CAAC,CAAA;IACJ,CAAC;CACF,CAAA;AAED,kBAAe,MAAM,CAAA"}
@@ -0,0 +1,184 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const actions_core_1 = require("@segment/actions-core");
7
+ const test_data_1 = require("../../../../lib/test-data");
8
+ const index_1 = __importDefault(require("../../index"));
9
+ const nock_1 = __importDefault(require("nock"));
10
+ const testDestination = actions_core_1.createTestIntegration(index_1.default);
11
+ const actionSlug = 'updateUserProfile';
12
+ const destinationSlug = 'Braze';
13
+ const seedName = `${destinationSlug}#${actionSlug}`;
14
+ const receivedAt = '2021-08-03T17:40:04.055Z';
15
+ const settings = {
16
+ app_id: 'my-app-id',
17
+ api_key: 'my-api-key',
18
+ endpoint: 'https://rest.iad-01.braze.com'
19
+ };
20
+ describe(`Testing snapshot for ${destinationSlug}'s ${actionSlug} destination action:`, () => {
21
+ it('required fields', async () => {
22
+ const action = index_1.default.actions[actionSlug];
23
+ const [eventData, settingsData] = test_data_1.generateTestData(seedName, index_1.default, action, true);
24
+ nock_1.default(/.*/).persist().get(/.*/).reply(200);
25
+ nock_1.default(/.*/).persist().post(/.*/).reply(200);
26
+ nock_1.default(/.*/).persist().put(/.*/).reply(200);
27
+ const event = actions_core_1.createTestEvent({
28
+ properties: eventData
29
+ });
30
+ const responses = await testDestination.testAction(actionSlug, {
31
+ event: event,
32
+ mapping: event.properties,
33
+ settings: settingsData,
34
+ auth: undefined
35
+ });
36
+ const request = responses[0].request;
37
+ const rawBody = await request.text();
38
+ try {
39
+ const json = JSON.parse(rawBody);
40
+ expect(json).toMatchSnapshot();
41
+ return;
42
+ }
43
+ catch (err) {
44
+ expect(rawBody).toMatchSnapshot();
45
+ }
46
+ expect(request.headers).toMatchSnapshot();
47
+ });
48
+ it('all fields', async () => {
49
+ const action = index_1.default.actions[actionSlug];
50
+ const [eventData, settingsData] = test_data_1.generateTestData(seedName, index_1.default, action, false);
51
+ nock_1.default(/.*/).persist().get(/.*/).reply(200);
52
+ nock_1.default(/.*/).persist().post(/.*/).reply(200);
53
+ nock_1.default(/.*/).persist().put(/.*/).reply(200);
54
+ const event = actions_core_1.createTestEvent({
55
+ properties: eventData
56
+ });
57
+ const responses = await testDestination.testAction(actionSlug, {
58
+ event: event,
59
+ mapping: event.properties,
60
+ settings: settingsData,
61
+ auth: undefined
62
+ });
63
+ const request = responses[0].request;
64
+ const rawBody = await request.text();
65
+ try {
66
+ const json = JSON.parse(rawBody);
67
+ expect(json).toMatchSnapshot();
68
+ return;
69
+ }
70
+ catch (err) {
71
+ expect(rawBody).toMatchSnapshot();
72
+ }
73
+ });
74
+ it('it should work with batched events', async () => {
75
+ nock_1.default('https://rest.iad-01.braze.com').post('/users/track').reply(200, {});
76
+ const events = [
77
+ actions_core_1.createTestEvent({
78
+ event: 'Test Event 1',
79
+ type: 'track',
80
+ receivedAt,
81
+ properties: {}
82
+ }),
83
+ actions_core_1.createTestEvent({
84
+ event: 'Test Event 2',
85
+ type: 'track',
86
+ receivedAt,
87
+ properties: {}
88
+ })
89
+ ];
90
+ const responses = await testDestination.testBatchAction(actionSlug, {
91
+ events,
92
+ useDefaultMappings: true,
93
+ mapping: {
94
+ external_id: {
95
+ '@path': '$.userId'
96
+ },
97
+ user_alias: {},
98
+ braze_id: {
99
+ '@path': '$.properties.braze_id'
100
+ },
101
+ name: {
102
+ '@path': '$.event'
103
+ },
104
+ time: {
105
+ '@path': '$.receivedAt'
106
+ },
107
+ properties: {
108
+ '@path': '$.properties'
109
+ },
110
+ products: {
111
+ '@path': '$.properties.products'
112
+ },
113
+ enable_batching: true,
114
+ _update_existing_only: true
115
+ },
116
+ settings: {
117
+ ...settings
118
+ }
119
+ });
120
+ expect(responses.length).toBe(1);
121
+ expect(responses[0].status).toBe(200);
122
+ expect(responses[0].options.headers).toMatchSnapshot();
123
+ expect(responses[0].options.json).toMatchSnapshot();
124
+ });
125
+ it('it should work with a single batched events', async () => {
126
+ nock_1.default('https://rest.iad-01.braze.com').post('/users/track').reply(200, {});
127
+ const events = [
128
+ actions_core_1.createTestEvent({
129
+ event: 'Test Event 1',
130
+ type: 'track',
131
+ receivedAt,
132
+ properties: {
133
+ products: [
134
+ {
135
+ quantity: 1,
136
+ product_id: 'Bowflex Treadmill 10',
137
+ price: 100
138
+ },
139
+ {
140
+ quantity: 2,
141
+ product_id: 'Bowflex Treadmill 20',
142
+ price: 200
143
+ }
144
+ ]
145
+ }
146
+ })
147
+ ];
148
+ const responses = await testDestination.testBatchAction(actionSlug, {
149
+ events,
150
+ useDefaultMappings: true,
151
+ mapping: {
152
+ external_id: {
153
+ '@path': '$.userId'
154
+ },
155
+ user_alias: {},
156
+ braze_id: {
157
+ '@path': '$.properties.braze_id'
158
+ },
159
+ name: {
160
+ '@path': '$.event'
161
+ },
162
+ time: {
163
+ '@path': '$.receivedAt'
164
+ },
165
+ properties: {
166
+ '@path': '$.properties'
167
+ },
168
+ products: {
169
+ '@path': '$.properties.products'
170
+ },
171
+ enable_batching: true,
172
+ _update_existing_only: true
173
+ },
174
+ settings: {
175
+ ...settings
176
+ }
177
+ });
178
+ expect(responses.length).toBe(1);
179
+ expect(responses[0].status).toBe(200);
180
+ expect(responses[0].options.headers).toMatchSnapshot();
181
+ expect(responses[0].options.json).toMatchSnapshot();
182
+ });
183
+ });
184
+ //# sourceMappingURL=snapshot.test.js.map