@segment/action-destinations 3.268.1-staging.5 → 3.269.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 (61) hide show
  1. package/dist/destinations/amazon-amc/generated-types.d.ts +12 -0
  2. package/dist/destinations/amazon-amc/generated-types.js.map +1 -0
  3. package/dist/destinations/{amazon-ads → amazon-amc}/index.d.ts +2 -2
  4. package/dist/destinations/amazon-amc/index.js +221 -0
  5. package/dist/destinations/amazon-amc/index.js.map +1 -0
  6. package/dist/destinations/amazon-amc/syncAudiencesToDSP/generated-types.d.ts +15 -0
  7. package/dist/destinations/amazon-amc/syncAudiencesToDSP/generated-types.js.map +1 -0
  8. package/dist/destinations/amazon-amc/syncAudiencesToDSP/index.js +179 -0
  9. package/dist/destinations/amazon-amc/syncAudiencesToDSP/index.js.map +1 -0
  10. package/dist/destinations/amazon-amc/types.d.ts +47 -0
  11. package/dist/destinations/amazon-amc/types.js.map +1 -0
  12. package/dist/destinations/{amazon-ads → amazon-amc}/utils.d.ts +6 -0
  13. package/dist/destinations/amazon-amc/utils.js +25 -0
  14. package/dist/destinations/amazon-amc/utils.js.map +1 -0
  15. package/dist/destinations/attio/api/index.d.ts +13 -0
  16. package/dist/destinations/attio/api/index.js +7 -0
  17. package/dist/destinations/attio/api/index.js.map +1 -1
  18. package/dist/destinations/attio/assertRecord/generated-types.d.ts +3 -0
  19. package/dist/destinations/attio/assertRecord/index.js +16 -1
  20. package/dist/destinations/attio/assertRecord/index.js.map +1 -1
  21. package/dist/destinations/attio/common-fields.d.ts +3 -0
  22. package/dist/destinations/attio/common-fields.js +30 -0
  23. package/dist/destinations/attio/common-fields.js.map +1 -0
  24. package/dist/destinations/attio/groupWorkspace/generated-types.d.ts +3 -0
  25. package/dist/destinations/attio/groupWorkspace/index.js +31 -1
  26. package/dist/destinations/attio/groupWorkspace/index.js.map +1 -1
  27. package/dist/destinations/attio/identifyUser/generated-types.d.ts +3 -0
  28. package/dist/destinations/attio/identifyUser/index.js +31 -1
  29. package/dist/destinations/attio/identifyUser/index.js.map +1 -1
  30. package/dist/destinations/blackbaud-raisers-edge-nxt/utils/index.d.ts +1 -1
  31. package/dist/destinations/customerio/utils.d.ts +1 -0
  32. package/dist/destinations/customerio/utils.js +4 -1
  33. package/dist/destinations/customerio/utils.js.map +1 -1
  34. package/dist/destinations/engage/utils/track.d.ts +17 -17
  35. package/dist/destinations/index.js +1 -1
  36. package/dist/destinations/index.js.map +1 -1
  37. package/dist/destinations/klaviyo/upsertProfile/index.js +11 -4
  38. package/dist/destinations/klaviyo/upsertProfile/index.js.map +1 -1
  39. package/dist/destinations/stackadapt/index.js +1 -1
  40. package/dist/destinations/stackadapt/index.js.map +1 -1
  41. package/dist/destinations/tiktok-conversions/formatter.js +13 -1
  42. package/dist/destinations/tiktok-conversions/formatter.js.map +1 -1
  43. package/dist/destinations/tiktok-offline-conversions/formatter.js +13 -1
  44. package/dist/destinations/tiktok-offline-conversions/formatter.js.map +1 -1
  45. package/package.json +4 -4
  46. package/dist/destinations/amazon-ads/generated-types.d.ts +0 -3
  47. package/dist/destinations/amazon-ads/generated-types.js.map +0 -1
  48. package/dist/destinations/amazon-ads/index.js +0 -87
  49. package/dist/destinations/amazon-ads/index.js.map +0 -1
  50. package/dist/destinations/amazon-ads/syncAudiences/generated-types.d.ts +0 -2
  51. package/dist/destinations/amazon-ads/syncAudiences/generated-types.js.map +0 -1
  52. package/dist/destinations/amazon-ads/syncAudiences/index.js +0 -15
  53. package/dist/destinations/amazon-ads/syncAudiences/index.js.map +0 -1
  54. package/dist/destinations/amazon-ads/types.d.ts +0 -22
  55. package/dist/destinations/amazon-ads/types.js.map +0 -1
  56. package/dist/destinations/amazon-ads/utils.js +0 -18
  57. package/dist/destinations/amazon-ads/utils.js.map +0 -1
  58. /package/dist/destinations/{amazon-ads → amazon-amc}/generated-types.js +0 -0
  59. /package/dist/destinations/{amazon-ads/syncAudiences → amazon-amc/syncAudiencesToDSP}/generated-types.js +0 -0
  60. /package/dist/destinations/{amazon-ads/syncAudiences → amazon-amc/syncAudiencesToDSP}/index.d.ts +0 -0
  61. /package/dist/destinations/{amazon-ads → amazon-amc}/types.js +0 -0
@@ -0,0 +1,12 @@
1
+ export interface Settings {
2
+ region: string;
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
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generated-types.js","sourceRoot":"","sources":["../../../src/destinations/amazon-amc/generated-types.ts"],"names":[],"mappings":""}
@@ -1,4 +1,4 @@
1
1
  import type { AudienceDestinationDefinition } from '@segment/actions-core';
2
- import type { Settings } from './generated-types';
3
- declare const destination: AudienceDestinationDefinition<Settings>;
2
+ import type { Settings, AudienceSettings } from './generated-types';
3
+ declare const destination: AudienceDestinationDefinition<Settings, AudienceSettings>;
4
4
  export default destination;
@@ -0,0 +1,221 @@
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 utils_1 = require("./utils");
8
+ const syncAudiencesToDSP_1 = __importDefault(require("./syncAudiencesToDSP"));
9
+ const destination = {
10
+ name: 'Amazon AMC (Actions)',
11
+ slug: 'actions-amazon-amc',
12
+ mode: 'cloud',
13
+ authentication: {
14
+ scheme: 'oauth2',
15
+ fields: {
16
+ region: {
17
+ label: 'Region',
18
+ description: 'Region for API Endpoint, either NA, EU, FE.',
19
+ choices: [
20
+ { label: 'North America (NA)', value: 'https://advertising-api.amazon.com' },
21
+ { label: 'Europe (EU)', value: 'https://advertising-api-eu.amazon.com' },
22
+ { label: 'Far East (FE)', value: 'https://advertising-api-fe.amazon.com' }
23
+ ],
24
+ default: 'https://advertising-api.amazon.com',
25
+ type: 'string',
26
+ required: true
27
+ }
28
+ },
29
+ testAuthentication: async (request, { auth, settings }) => {
30
+ if (!auth?.accessToken) {
31
+ throw new actions_core_1.InvalidAuthenticationError('Please authenticate via Oauth before enabling the destination.');
32
+ }
33
+ try {
34
+ await request(`${settings.region}/v2/profiles`, {
35
+ method: 'GET'
36
+ });
37
+ }
38
+ catch (e) {
39
+ const error = e;
40
+ if (error.message === 'Unauthorized') {
41
+ throw new actions_core_1.InvalidAuthenticationError('Invalid Amazon Oauth access token. Please reauthenticate to retrieve a valid access token before enabling the destination.');
42
+ }
43
+ throw e;
44
+ }
45
+ },
46
+ refreshAccessToken: async (request, { auth, settings }) => {
47
+ const endpoint = utils_1.AUTHORIZATION_URL[`${settings.region}`];
48
+ try {
49
+ const res = await request(endpoint, {
50
+ method: 'POST',
51
+ body: new URLSearchParams({
52
+ refresh_token: auth.refreshToken,
53
+ client_id: auth.clientId,
54
+ client_secret: auth.clientSecret,
55
+ grant_type: 'refresh_token'
56
+ }),
57
+ headers: {
58
+ authorization: ''
59
+ }
60
+ });
61
+ return { accessToken: res.data.access_token };
62
+ }
63
+ catch (e) {
64
+ const error = e;
65
+ if (error.response?.data?.error === 'invalid_grant') {
66
+ throw new actions_core_1.InvalidAuthenticationError(`Invalid Authentication: Your refresh token is invalid or expired. Please re-authenticate to fetch a new refresh token.`, actions_core_1.ErrorCodes.REFRESH_TOKEN_EXPIRED);
67
+ }
68
+ throw new actions_core_1.InvalidAuthenticationError(`Failed to fetch a new access token. Reason: ${error.response?.data?.error}`, actions_core_1.ErrorCodes.OAUTH_REFRESH_FAILED);
69
+ }
70
+ }
71
+ },
72
+ extendRequest({ auth }) {
73
+ return {
74
+ headers: {
75
+ authorization: `Bearer ${auth?.accessToken}`,
76
+ 'Amazon-Advertising-API-ClientID': process.env.ACTIONS_AMAZON_ADS_CLIENT_ID || '',
77
+ 'Content-Type': 'application/vnd.amcaudiences.v1+json'
78
+ }
79
+ };
80
+ },
81
+ audienceFields: {
82
+ description: {
83
+ type: 'string',
84
+ label: 'Description',
85
+ required: true,
86
+ description: 'The audience description. Must be an alphanumeric, non-null string between 0 to 1000 characters in length.'
87
+ },
88
+ countryCode: {
89
+ type: 'string',
90
+ label: 'Country Code',
91
+ required: true,
92
+ description: 'A String value representing ISO 3166-1 alpha-2 country code for the members in this audience.'
93
+ },
94
+ externalAudienceId: {
95
+ type: 'string',
96
+ label: 'External Audience Id',
97
+ required: true,
98
+ description: 'The user-defined audience identifier.'
99
+ },
100
+ cpmCents: {
101
+ label: 'CPM Cents',
102
+ type: 'number',
103
+ description: `Cost per thousand impressions (CPM) in cents. For example, $1.00 = 100 cents.`
104
+ },
105
+ currency: {
106
+ label: 'Currency',
107
+ type: 'string',
108
+ 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).Refer [Aamzon Ads Documentation](https://advertising.amazon.com/API/docs/en-us/amc-advertiser-audience#tag/Audience-Metadata/operation/CreateAudienceMetadataV2) to view supported Currency`
109
+ },
110
+ ttl: {
111
+ type: 'number',
112
+ label: 'Time-to-live',
113
+ required: false,
114
+ description: 'Time-to-live in seconds. The amount of time the record is associated with the audience.'
115
+ },
116
+ advertiserId: {
117
+ label: 'Advertiser ID',
118
+ description: 'Advertiser Id',
119
+ type: 'string',
120
+ required: true
121
+ }
122
+ },
123
+ audienceConfig: {
124
+ mode: {
125
+ type: 'synced',
126
+ full_audience_sync: false
127
+ },
128
+ async createAudience(request, createAudienceInput) {
129
+ const { audienceName, audienceSettings } = createAudienceInput;
130
+ const endpoint = createAudienceInput.settings.region;
131
+ const description = audienceSettings?.description;
132
+ const advertiser_id = audienceSettings?.advertiserId;
133
+ const external_audience_id = audienceSettings?.externalAudienceId;
134
+ const country_code = audienceSettings?.countryCode;
135
+ const ttl = audienceSettings?.ttl;
136
+ const currency = audienceSettings?.currency;
137
+ const cpm_cents = audienceSettings?.cpmCents;
138
+ if (!advertiser_id) {
139
+ throw new actions_core_1.IntegrationError('Missing advertiserId Value', 'MISSING_REQUIRED_FIELD', 400);
140
+ }
141
+ if (!description) {
142
+ throw new actions_core_1.IntegrationError('Missing description Value', 'MISSING_REQUIRED_FIELD', 400);
143
+ }
144
+ if (!external_audience_id) {
145
+ throw new actions_core_1.IntegrationError('Missing externalAudienceId Value', 'MISSING_REQUIRED_FIELD', 400);
146
+ }
147
+ if (!audienceName) {
148
+ throw new actions_core_1.IntegrationError('Missing audienceName Value', 'MISSING_REQUIRED_FIELD', 400);
149
+ }
150
+ if (!country_code) {
151
+ throw new actions_core_1.IntegrationError('Missing countryCode 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
+ countryCode: country_code
163
+ };
164
+ if (ttl) {
165
+ const timeToLive = Number(ttl);
166
+ if (!timeToLive) {
167
+ throw new actions_core_1.IntegrationError('TTL:-String can not be converted to Number', 'INVALID_TTL_VALUE', 400);
168
+ }
169
+ payload.metadata.ttl = timeToLive;
170
+ }
171
+ if (cpm_cents && currency) {
172
+ if (!utils_1.CURRENCY.includes(currency)) {
173
+ throw new actions_core_1.IntegrationError('Invalid Currency Value', 'INVALID_CURRENCY_VALUE', 400);
174
+ }
175
+ const cpmCents = Number(cpm_cents);
176
+ if (!cpmCents) {
177
+ throw new actions_core_1.IntegrationError('CPM_CENTS:-String can not be converted to Number', 'INVALID_CPMCENTS_VALUE', 400);
178
+ }
179
+ payload.metadata.audienceFees = [];
180
+ payload.metadata?.audienceFees.push({
181
+ currency,
182
+ cpmCents: cpmCents
183
+ });
184
+ }
185
+ let payloadString = JSON.stringify(payload);
186
+ payloadString = payloadString.replace(utils_1.REGEX_ADVERTISERID, '"advertiserId":$1');
187
+ const response = await request(`${endpoint}/amc/audiences/metadata`, {
188
+ method: 'POST',
189
+ body: payloadString,
190
+ headers: {
191
+ 'Content-Type': 'application/vnd.amcaudiences.v1+json'
192
+ }
193
+ });
194
+ const res = await response.text();
195
+ const resp = utils_1.extractNumberAndSubstituteWithStringValue(res, utils_1.REGEX_AUDIENCEID, '"audienceId":"$1"');
196
+ return {
197
+ externalId: resp.audienceId
198
+ };
199
+ },
200
+ async getAudience(request, getAudienceInput) {
201
+ const audience_id = getAudienceInput.externalId;
202
+ const endpoint = getAudienceInput.settings.region;
203
+ if (!audience_id) {
204
+ throw new actions_core_1.IntegrationError('Missing audienceId value', 'MISSING_REQUIRED_FIELD', 400);
205
+ }
206
+ const response = await request(`${endpoint}/amc/audiences/metadata/${audience_id}`, {
207
+ method: 'GET'
208
+ });
209
+ const res = await response.text();
210
+ const resp = utils_1.extractNumberAndSubstituteWithStringValue(res, utils_1.REGEX_AUDIENCEID, '"audienceId":"$1"');
211
+ return {
212
+ externalId: resp.audienceId
213
+ };
214
+ }
215
+ },
216
+ actions: {
217
+ syncAudiencesToDSP: syncAudiencesToDSP_1.default
218
+ }
219
+ };
220
+ exports.default = destination;
221
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/destinations/amazon-amc/index.ts"],"names":[],"mappings":";;;;;AACA,wDAAgG;AAGhG,mCAOgB;AAEhB,8EAAqD;AAErD,MAAM,WAAW,GAA8D;IAC7E,IAAI,EAAE,sBAAsB;IAC5B,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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,EAAE;QACP,kBAAkB,EAAlB,4BAAkB;KACnB;CACF,CAAA;AAED,kBAAe,WAAW,CAAA"}
@@ -0,0 +1,15 @@
1
+ export interface Payload {
2
+ event_name?: string;
3
+ externalUserId: string;
4
+ email?: string;
5
+ firstName?: string;
6
+ lastName?: string;
7
+ phone?: string;
8
+ postal?: string;
9
+ state?: string;
10
+ city?: string;
11
+ address?: string;
12
+ audienceId: string;
13
+ enable_batching: boolean;
14
+ batch_size?: number;
15
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generated-types.js","sourceRoot":"","sources":["../../../../src/destinations/amazon-amc/syncAudiencesToDSP/generated-types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,179 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("../utils");
4
+ const crypto_1 = require("crypto");
5
+ const action = {
6
+ title: 'Sync Audiences to DSP',
7
+ description: 'Sync audiences from Segment to Amazon Ads Audience.',
8
+ defaultSubscription: 'event = "Audience Entered" or event = "Audience Exited"',
9
+ fields: {
10
+ event_name: {
11
+ label: 'Event Name',
12
+ description: 'The name of the current Segment event.',
13
+ type: 'string',
14
+ unsafe_hidden: true,
15
+ default: {
16
+ '@path': '$.event'
17
+ }
18
+ },
19
+ externalUserId: {
20
+ label: 'External User ID',
21
+ description: 'This is an external user identifier defined by data providers.',
22
+ type: 'string',
23
+ required: true,
24
+ default: { '@path': '$.userId' }
25
+ },
26
+ email: {
27
+ label: 'Email',
28
+ description: 'User email address. Vaule will be hashed before sending to Amazon.',
29
+ type: 'string',
30
+ required: false,
31
+ default: { '@path': '$.properties.email' }
32
+ },
33
+ firstName: {
34
+ label: 'First name',
35
+ description: 'User first name. Value will be hashed before sending to Amazon.',
36
+ type: 'string',
37
+ required: false,
38
+ default: { '@path': '$.properties.first_name' }
39
+ },
40
+ lastName: {
41
+ label: 'Last name',
42
+ description: 'User Last name. Value will be hashed before sending to Amazon.',
43
+ type: 'string',
44
+ required: false,
45
+ default: { '@path': '$.properties.last_name' }
46
+ },
47
+ phone: {
48
+ label: 'Phone',
49
+ description: 'Phone Number. Value will be hashed before sending to Amazon.',
50
+ type: 'string',
51
+ required: false,
52
+ default: { '@path': '$.properties.phone' }
53
+ },
54
+ postal: {
55
+ label: 'Postal',
56
+ description: 'POstal Code. Value will be hashed before sending to Amazon.',
57
+ type: 'string',
58
+ required: false,
59
+ default: { '@path': '$.properties.postal' }
60
+ },
61
+ state: {
62
+ label: 'Postal',
63
+ description: 'State Code. Value will be hashed before sending to Amazon.',
64
+ type: 'string',
65
+ required: false,
66
+ default: { '@path': '$.properties.state' }
67
+ },
68
+ city: {
69
+ label: 'City',
70
+ description: 'City name. Value will be hashed before sending to Amazon.',
71
+ type: 'string',
72
+ required: false,
73
+ default: { '@path': '$.properties.city' }
74
+ },
75
+ address: {
76
+ label: 'Address',
77
+ description: 'Address Code. Value will be hashed before sending to Amazon.',
78
+ type: 'string',
79
+ required: false,
80
+ default: { '@path': '$.properties.address' }
81
+ },
82
+ audienceId: {
83
+ label: 'Audience ID',
84
+ type: 'string',
85
+ required: true,
86
+ unsafe_hidden: true,
87
+ description: 'A number value representing the Amazon audience identifier. This is the identifier that is returned during audience creation.',
88
+ default: {
89
+ '@path': '$.context.personas.external_audience_id'
90
+ }
91
+ },
92
+ enable_batching: {
93
+ label: 'Enable Batching',
94
+ description: 'When enabled,segment will send data in batching',
95
+ type: 'boolean',
96
+ required: true,
97
+ default: true
98
+ },
99
+ batch_size: {
100
+ label: 'Batch Size',
101
+ description: 'Maximum number of events to include in each batch. Actual batch sizes may be lower.',
102
+ type: 'number',
103
+ unsafe_hidden: true,
104
+ required: false,
105
+ default: 10000
106
+ }
107
+ },
108
+ perform: (request, { settings, payload, audienceSettings }) => {
109
+ return processPayload(request, settings, [payload], audienceSettings);
110
+ },
111
+ performBatch: (request, { settings, payload: payloads, audienceSettings }) => {
112
+ return processPayload(request, settings, payloads, audienceSettings);
113
+ }
114
+ };
115
+ async function processPayload(request, settings, payload, audienceSettings) {
116
+ const payloadRecord = createPayloadToUploadRecords(payload, audienceSettings);
117
+ const payloadString = JSON.stringify(payloadRecord).replace(/"audienceId":"(\d+)"/, '"audienceId":$1');
118
+ const response = await request(`${settings.region}/amc/audiences/records`, {
119
+ method: 'POST',
120
+ body: payloadString,
121
+ headers: {
122
+ 'Content-Type': 'application/vnd.amcaudiences.v1+json'
123
+ }
124
+ });
125
+ const result = response.data;
126
+ return {
127
+ result
128
+ };
129
+ }
130
+ function createPayloadToUploadRecords(payloads, audienceSettings) {
131
+ const records = [];
132
+ const { audienceId } = payloads[0];
133
+ payloads.forEach((payload) => {
134
+ const hashedPII = {};
135
+ if (payload.firstName) {
136
+ hashedPII.firstname = normalizeAndHash(payload.firstName);
137
+ }
138
+ if (payload.lastName) {
139
+ hashedPII.lastname = normalizeAndHash(payload.lastName);
140
+ }
141
+ if (payload.address) {
142
+ hashedPII.address = normalizeAndHash(payload.address);
143
+ }
144
+ if (payload.postal) {
145
+ hashedPII.postal = normalizeAndHash(payload.postal);
146
+ }
147
+ if (payload.phone) {
148
+ hashedPII.phone = normalizeAndHash(payload.phone);
149
+ }
150
+ if (payload.city) {
151
+ hashedPII.city = normalizeAndHash(payload.city);
152
+ }
153
+ if (payload.state) {
154
+ hashedPII.state = normalizeAndHash(payload.state);
155
+ }
156
+ if (payload.email) {
157
+ hashedPII.email = normalizeAndHash(payload.email);
158
+ }
159
+ const payloadRecord = {
160
+ externalUserId: payload.externalUserId,
161
+ countryCode: audienceSettings.countryCode,
162
+ action: payload.event_name == 'Audience Entered' ? utils_1.CONSTANTS.CREATE : utils_1.CONSTANTS.DELETE,
163
+ hashedPII: [hashedPII]
164
+ };
165
+ records.push(payloadRecord);
166
+ });
167
+ return {
168
+ records: records,
169
+ audienceId: audienceId
170
+ };
171
+ }
172
+ function normalizeAndHash(data) {
173
+ const normalizedData = data.toLowerCase().trim();
174
+ const hash = crypto_1.createHash('sha256');
175
+ hash.update(normalizedData);
176
+ return hash.digest('hex');
177
+ }
178
+ exports.default = action;
179
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/amazon-amc/syncAudiencesToDSP/index.ts"],"names":[],"mappings":";;AAGA,oCAAyD;AACzD,mCAAmC;AAGnC,MAAM,MAAM,GAAwC;IAClD,KAAK,EAAE,uBAAuB;IAC9B,WAAW,EAAE,qDAAqD;IAClE,mBAAmB,EAAE,yDAAyD;IAC9E,MAAM,EAAE;QACN,UAAU,EAAE;YACV,KAAK,EAAE,YAAY;YACnB,WAAW,EAAE,wCAAwC;YACrD,IAAI,EAAE,QAAQ;YACd,aAAa,EAAE,IAAI;YACnB,OAAO,EAAE;gBACP,OAAO,EAAE,SAAS;aACnB;SACF;QACD,cAAc,EAAE;YACd,KAAK,EAAE,kBAAkB;YACzB,WAAW,EAAE,gEAAgE;YAC7E,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,IAAI;YACd,OAAO,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE;SACjC;QACD,KAAK,EAAE;YACL,KAAK,EAAE,OAAO;YACd,WAAW,EAAE,oEAAoE;YACjF,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,KAAK;YACf,OAAO,EAAE,EAAE,OAAO,EAAE,oBAAoB,EAAE;SAC3C;QACD,SAAS,EAAE;YACT,KAAK,EAAE,YAAY;YACnB,WAAW,EAAE,iEAAiE;YAC9E,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,KAAK;YACf,OAAO,EAAE,EAAE,OAAO,EAAE,yBAAyB,EAAE;SAChD;QACD,QAAQ,EAAE;YACR,KAAK,EAAE,WAAW;YAClB,WAAW,EAAE,gEAAgE;YAC7E,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,KAAK;YACf,OAAO,EAAE,EAAE,OAAO,EAAE,wBAAwB,EAAE;SAC/C;QACD,KAAK,EAAE;YACL,KAAK,EAAE,OAAO;YACd,WAAW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ACtF,SAAS,EAAE,CAAC,SAAS,CAAC;SACvB,CAAA;QACD,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,CAAA;IAC7B,CAAC,CAAC,CAAA;IAEF,OAAO;QACL,OAAO,EAAE,OAAO;QAChB,UAAU,EAAE,UAAU;KACvB,CAAA;AACH,CAAC;AAED,SAAS,gBAAgB,CAAC,IAAY;IAEpC,MAAM,cAAc,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,CAAA;IAEhD,MAAM,IAAI,GAAG,mBAAU,CAAC,QAAQ,CAAC,CAAA;IACjC,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,CAAA;IAC3B,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AAC3B,CAAC;AAED,kBAAe,MAAM,CAAA"}
@@ -0,0 +1,47 @@
1
+ import { HTTPError } from '@segment/actions-core';
2
+ export interface RefreshTokenResponse {
3
+ access_token: string;
4
+ scope: string;
5
+ expires_in: number;
6
+ token_type: string;
7
+ }
8
+ export declare class AmazonTestAuthenticationError extends HTTPError {
9
+ response: Response & {
10
+ data: {
11
+ message: string;
12
+ };
13
+ };
14
+ }
15
+ export declare class AmazonRefreshTokenError extends HTTPError {
16
+ response: Response & {
17
+ data: {
18
+ error: string;
19
+ error_description: string;
20
+ };
21
+ };
22
+ }
23
+ export interface HashedPIIObject {
24
+ firstname?: string;
25
+ lastname?: string;
26
+ phone?: string;
27
+ city?: string;
28
+ state?: string;
29
+ postal?: string;
30
+ email?: string;
31
+ address?: string;
32
+ }
33
+ export interface AudienceRecord {
34
+ hashedPII: HashedPIIObject[];
35
+ externalUserId: string;
36
+ countryCode: string;
37
+ action: string;
38
+ }
39
+ export interface TargetResourceRecords {
40
+ connectionId: string;
41
+ targetTypes: string[];
42
+ }
43
+ export interface AudienceRecordPayload {
44
+ records: AudienceRecord[];
45
+ targetResource: TargetResourceRecords;
46
+ audienceId: number;
47
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/destinations/amazon-amc/types.ts"],"names":[],"mappings":";;;AAAA,wDAAiD;AASjD,MAAa,6BAA8B,SAAQ,wBAAS;CAM3D;AAND,sEAMC;AAED,MAAa,uBAAwB,SAAQ,wBAAS;CAOrD;AAPD,0DAOC"}
@@ -23,9 +23,15 @@ export interface AudiencePayload {
23
23
  }[];
24
24
  };
25
25
  }
26
+ export interface RecordsResponseType {
27
+ jobRequestId: string;
28
+ }
26
29
  export declare const AUTHORIZATION_URL: any;
27
30
  export declare const CONSTANTS: {
28
31
  CREATE: string;
29
32
  DELETE: string;
30
33
  };
31
34
  export declare const CURRENCY: string[];
35
+ export declare const REGEX_AUDIENCEID: RegExp;
36
+ export declare const REGEX_ADVERTISERID: RegExp;
37
+ export declare function extractNumberAndSubstituteWithStringValue(responseString: string, regex: any, substituteWith: string): any;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extractNumberAndSubstituteWithStringValue = exports.REGEX_ADVERTISERID = exports.REGEX_AUDIENCEID = exports.CURRENCY = exports.CONSTANTS = exports.AUTHORIZATION_URL = exports.AmazonAdsError = void 0;
4
+ const actions_core_1 = require("@segment/actions-core");
5
+ class AmazonAdsError extends actions_core_1.HTTPError {
6
+ }
7
+ exports.AmazonAdsError = AmazonAdsError;
8
+ exports.AUTHORIZATION_URL = {
9
+ 'https://advertising-api.amazon.com': 'https://api.amazon.com',
10
+ 'https://advertising-api-eu.amazon.com': 'https://api.amazon.co.uk',
11
+ 'https://advertising-api-fe.amazon.com': 'https://api.amazon.co.jp'
12
+ };
13
+ exports.CONSTANTS = {
14
+ CREATE: 'CREATE',
15
+ DELETE: 'DELETE'
16
+ };
17
+ exports.CURRENCY = ['USD', 'CAD', 'JPY', 'GBP', 'EUR', 'SAR', 'AUD', 'AED', 'CNY', 'MXN', 'INR', 'SEK', 'TRY'];
18
+ exports.REGEX_AUDIENCEID = /"audienceId":(\d+)/;
19
+ exports.REGEX_ADVERTISERID = /"advertiserId":"(\d+)"/;
20
+ function extractNumberAndSubstituteWithStringValue(responseString, regex, substituteWith) {
21
+ const resString = responseString.replace(regex, substituteWith);
22
+ return JSON.parse(resString);
23
+ }
24
+ exports.extractNumberAndSubstituteWithStringValue = extractNumberAndSubstituteWithStringValue;
25
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/destinations/amazon-amc/utils.ts"],"names":[],"mappings":";;;AAAA,wDAAiD;AAEjD,MAAa,cAAe,SAAQ,wBAAS;CAO5C;AAPD,wCAOC;AAsBY,QAAA,iBAAiB,GAAQ;IACpC,oCAAoC,EAAE,wBAAwB;IAC9D,uCAAuC,EAAE,0BAA0B;IACnE,uCAAuC,EAAE,0BAA0B;CACpE,CAAA;AACY,QAAA,SAAS,GAAG;IACvB,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;CACjB,CAAA;AACY,QAAA,QAAQ,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAA;AAEtG,QAAA,gBAAgB,GAAG,oBAAoB,CAAA;AACvC,QAAA,kBAAkB,GAAG,wBAAwB,CAAA;AAE1D,SAAgB,yCAAyC,CAAC,cAAsB,EAAE,KAAU,EAAE,cAAsB;IAClH,MAAM,SAAS,GAAG,cAAc,CAAC,OAAO,CAAC,KAAK,EAAE,cAAc,CAAC,CAAA;IAC/D,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAA;AAC9B,CAAC;AAHD,8FAGC"}
@@ -1,5 +1,14 @@
1
1
  import { RequestClient, RequestOptions } from '@segment/actions-core';
2
2
  import { ModifiedResponse } from '@segment/actions-core';
3
+ export declare type SimpleValue = string | number | boolean;
4
+ declare type BatchAssertion = {
5
+ object: string;
6
+ mode: 'create-or-update';
7
+ matching_attribute: string;
8
+ multiselect_values: 'append';
9
+ values: Record<string, null | SimpleValue | Array<SimpleValue> | BatchAssertion | Array<BatchAssertion>>;
10
+ received_at: string;
11
+ };
3
12
  export declare type AssertResponse = {
4
13
  data: {
5
14
  id: {
@@ -25,6 +34,10 @@ export declare class AttioClient {
25
34
  values: Record<string, unknown>;
26
35
  requestOptions?: Partial<RequestOptions>;
27
36
  }): Promise<ModifiedResponse<AssertResponse>>;
37
+ batchAssert({ assertions, requestOptions }: {
38
+ assertions: Array<BatchAssertion>;
39
+ requestOptions?: Partial<RequestOptions>;
40
+ }): Promise<ModifiedResponse<AssertResponse>>;
28
41
  listObjects(): Promise<Array<ObjectResponse>>;
29
42
  }
30
43
  export {};
@@ -18,6 +18,13 @@ class AttioClient {
18
18
  ...requestOptions
19
19
  });
20
20
  }
21
+ async batchAssert({ assertions, requestOptions }) {
22
+ return await this.request(`${this.api_url}/v2/batch/records`, {
23
+ method: 'put',
24
+ json: { assertions },
25
+ ...requestOptions
26
+ });
27
+ }
21
28
  async listObjects() {
22
29
  const response = await this.request(`${this.api_url}/v2/objects`);
23
30
  const objects = get_1.default(response, 'data.data', []);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/attio/api/index.ts"],"names":[],"mappings":";;;;;;AAEA,qDAA4B;AAC5B,2DAAkC;AAmBlC,MAAa,WAAW;IAItB,YAAY,OAAsB;QAChC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,OAAO,GAAG,uBAAuB,CAAA;IACxC,CAAC;IAWD,KAAK,CAAC,YAAY,CAAC,EACjB,kBAAkB,EAClB,MAAM,EACN,MAAM,EACN,cAAc,EAMf;QACC,OAAO,MAAM,IAAI,CAAC,OAAO,CACvB,GAAG,IAAI,CAAC,OAAO,eAAe,MAAM,sCAAsC,kBAAkB,iCAAiC,EAC7H;YACE,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,EAAE;YAC1B,GAAG,cAAc;SAClB,CACF,CAAA;IACH,CAAC;IAKD,KAAK,CAAC,WAAW;QACf,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,OAAO,aAAa,CAAC,CAAA;QACjE,MAAM,OAAO,GAA0B,aAAG,CAAC,QAAQ,EAAE,WAAW,EAAE,EAAE,CAAC,CAAA;QAErE,OAAO,gBAAM,CAAC,OAAO,EAAE,eAAe,CAAC,CAAA;IACzC,CAAC;CACF;AAhDD,kCAgDC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/attio/api/index.ts"],"names":[],"mappings":";;;;;;AAEA,qDAA4B;AAC5B,2DAAkC;AA8BlC,MAAa,WAAW;IAItB,YAAY,OAAsB;QAChC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,OAAO,GAAG,uBAAuB,CAAA;IACxC,CAAC;IAWD,KAAK,CAAC,YAAY,CAAC,EACjB,kBAAkB,EAClB,MAAM,EACN,MAAM,EACN,cAAc,EAMf;QACC,OAAO,MAAM,IAAI,CAAC,OAAO,CACvB,GAAG,IAAI,CAAC,OAAO,eAAe,MAAM,sCAAsC,kBAAkB,iCAAiC,EAC7H;YACE,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,EAAE;YAC1B,GAAG,cAAc;SAClB,CACF,CAAA;IACH,CAAC;IAQD,KAAK,CAAC,WAAW,CAAC,EAChB,UAAU,EACV,cAAc,EAIf;QACC,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,OAAO,mBAAmB,EAAE;YAC5D,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,EAAE,UAAU,EAAE;YACpB,GAAG,cAAc;SAClB,CAAC,CAAA;IACJ,CAAC;IAKD,KAAK,CAAC,WAAW;QACf,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,OAAO,aAAa,CAAC,CAAA;QACjE,MAAM,OAAO,GAA0B,aAAG,CAAC,QAAQ,EAAE,WAAW,EAAE,EAAE,CAAC,CAAA;QAErE,OAAO,gBAAM,CAAC,OAAO,EAAE,eAAe,CAAC,CAAA;IACzC,CAAC;CACF;AApED,kCAoEC"}
@@ -4,4 +4,7 @@ export interface Payload {
4
4
  attributes?: {
5
5
  [k: string]: unknown;
6
6
  };
7
+ enable_batching?: boolean;
8
+ batch_size?: number;
9
+ received_at?: string | number;
7
10
  }