@segment/action-destinations 3.265.0-staging-ab210811a → 3.265.0-staging-d627b1d69
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.
- package/dist/destinations/amazon-ads/generated-types.d.ts +9 -0
- package/dist/destinations/amazon-ads/index.d.ts +2 -2
- package/dist/destinations/amazon-ads/index.js +180 -3
- package/dist/destinations/amazon-ads/index.js.map +1 -1
- package/dist/destinations/amazon-ads/syncAudiences/generated-types.d.ts +11 -0
- package/dist/destinations/amazon-ads/syncAudiences/index.js +236 -7
- package/dist/destinations/amazon-ads/syncAudiences/index.js.map +1 -1
- package/dist/destinations/amazon-ads/types.d.ts +25 -0
- package/dist/destinations/engage/sendgrid/Profile.d.ts +6 -0
- package/dist/destinations/{responsys-cloud/types.js → engage/sendgrid/Profile.js} +1 -1
- package/dist/destinations/engage/sendgrid/Profile.js.map +1 -0
- package/dist/destinations/engage/sendgrid/previewApiLookup/api-lookups.d.ts +21 -0
- package/dist/destinations/engage/sendgrid/previewApiLookup/api-lookups.js +174 -0
- package/dist/destinations/engage/sendgrid/previewApiLookup/api-lookups.js.map +1 -0
- package/dist/destinations/engage/utils/track.d.ts +10 -10
- package/dist/destinations/index.js.map +1 -1
- package/dist/destinations/mixpanel/utils.d.ts +13 -0
- package/dist/destinations/mixpanel/utils.js +117 -0
- package/dist/destinations/mixpanel/utils.js.map +1 -0
- package/dist/destinations/moloco-rmp/common/convert.js +29 -17
- package/dist/destinations/moloco-rmp/common/convert.js.map +1 -1
- package/dist/destinations/xtremepush/identify/index.js +2 -2
- package/dist/destinations/xtremepush/identify/index.js.map +1 -1
- package/dist/destinations/xtremepush/index.js.map +1 -1
- package/dist/destinations/xtremepush/track/index.js +2 -2
- package/dist/destinations/xtremepush/track/index.js.map +1 -1
- package/package.json +2 -2
- package/dist/destinations/responsys-cloud/generated-types.d.ts +0 -20
- package/dist/destinations/responsys-cloud/generated-types.js +0 -3
- package/dist/destinations/responsys-cloud/generated-types.js.map +0 -1
- package/dist/destinations/responsys-cloud/index.d.ts +0 -4
- package/dist/destinations/responsys-cloud/index.js +0 -207
- package/dist/destinations/responsys-cloud/index.js.map +0 -1
- package/dist/destinations/responsys-cloud/sendAudience/generated-types.d.ts +0 -16
- package/dist/destinations/responsys-cloud/sendAudience/generated-types.js +0 -3
- package/dist/destinations/responsys-cloud/sendAudience/generated-types.js.map +0 -1
- package/dist/destinations/responsys-cloud/sendAudience/index.d.ts +0 -5
- package/dist/destinations/responsys-cloud/sendAudience/index.js +0 -109
- package/dist/destinations/responsys-cloud/sendAudience/index.js.map +0 -1
- package/dist/destinations/responsys-cloud/sendCustomTraits/generated-types.d.ts +0 -11
- package/dist/destinations/responsys-cloud/sendCustomTraits/generated-types.js +0 -3
- package/dist/destinations/responsys-cloud/sendCustomTraits/generated-types.js.map +0 -1
- package/dist/destinations/responsys-cloud/sendCustomTraits/index.d.ts +0 -5
- package/dist/destinations/responsys-cloud/sendCustomTraits/index.js +0 -72
- package/dist/destinations/responsys-cloud/sendCustomTraits/index.js.map +0 -1
- package/dist/destinations/responsys-cloud/shared_properties.d.ts +0 -3
- package/dist/destinations/responsys-cloud/shared_properties.js +0 -19
- package/dist/destinations/responsys-cloud/shared_properties.js.map +0 -1
- package/dist/destinations/responsys-cloud/types.d.ts +0 -38
- package/dist/destinations/responsys-cloud/types.js.map +0 -1
- package/dist/destinations/responsys-cloud/upsertListMember/generated-types.d.ts +0 -14
- package/dist/destinations/responsys-cloud/upsertListMember/generated-types.js +0 -3
- package/dist/destinations/responsys-cloud/upsertListMember/generated-types.js.map +0 -1
- package/dist/destinations/responsys-cloud/upsertListMember/index.d.ts +0 -5
- package/dist/destinations/responsys-cloud/upsertListMember/index.js +0 -85
- package/dist/destinations/responsys-cloud/upsertListMember/index.js.map +0 -1
- package/dist/destinations/responsys-cloud/utils.d.ts +0 -20
- package/dist/destinations/responsys-cloud/utils.js +0 -179
- package/dist/destinations/responsys-cloud/utils.js.map +0 -1
|
@@ -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;
|
|
@@ -4,6 +4,7 @@ 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");
|
|
7
8
|
const syncAudiences_1 = __importDefault(require("./syncAudiences"));
|
|
8
9
|
const destination = {
|
|
9
10
|
name: 'Amazon Ads',
|
|
@@ -20,12 +21,15 @@ const destination = {
|
|
|
20
21
|
{ label: 'Europe (EU)', value: 'https://advertising-api-eu.amazon.com' },
|
|
21
22
|
{ label: 'Far East (FE)', value: 'https://advertising-api-fe.amazon.com' }
|
|
22
23
|
],
|
|
23
|
-
default: '
|
|
24
|
+
default: 'https://advertising-api.amazon.com',
|
|
24
25
|
type: 'string',
|
|
25
26
|
required: true
|
|
26
27
|
}
|
|
27
28
|
},
|
|
28
29
|
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
|
+
}
|
|
29
33
|
if (!auth?.accessToken) {
|
|
30
34
|
throw new actions_core_1.InvalidAuthenticationError('Please authenticate via Oauth before enabling the destination.');
|
|
31
35
|
}
|
|
@@ -68,15 +72,188 @@ const destination = {
|
|
|
68
72
|
extendRequest({ auth }) {
|
|
69
73
|
return {
|
|
70
74
|
headers: {
|
|
71
|
-
authorization: `Bearer ${auth?.accessToken}
|
|
75
|
+
authorization: `Bearer ${auth?.accessToken}`,
|
|
76
|
+
'Amazon-Advertising-API-ClientID': process.env.ACTIONS_AMAZON_ADS_CLIENT_ID || ''
|
|
72
77
|
}
|
|
73
78
|
};
|
|
74
79
|
},
|
|
75
|
-
audienceFields: {
|
|
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: true,
|
|
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
|
+
},
|
|
76
122
|
audienceConfig: {
|
|
77
123
|
mode: {
|
|
78
124
|
type: 'synced',
|
|
79
125
|
full_audience_sync: false
|
|
126
|
+
},
|
|
127
|
+
async createAudience(request, createAudienceInput) {
|
|
128
|
+
const { audienceName, statsContext } = createAudienceInput;
|
|
129
|
+
const { statsClient, tags: statsTags } = statsContext || {};
|
|
130
|
+
const statsName = 'createAmazonAudience';
|
|
131
|
+
statsTags?.push(`slug:${destination.slug}`);
|
|
132
|
+
statsClient?.incr(`${statsName}.intialise`, 1, statsTags);
|
|
133
|
+
const endpoint = createAudienceInput.settings.region;
|
|
134
|
+
const description = createAudienceInput.audienceSettings?.description;
|
|
135
|
+
const advertiser_id = createAudienceInput.audienceSettings?.advertiserId;
|
|
136
|
+
const external_audience_id = createAudienceInput.audienceSettings?.externalAudienceId;
|
|
137
|
+
const country_code = createAudienceInput.audienceSettings?.countryCode;
|
|
138
|
+
const ttl = createAudienceInput.audienceSettings?.ttl;
|
|
139
|
+
const currency = createAudienceInput.audienceSettings?.currency;
|
|
140
|
+
const cpm_cents = createAudienceInput.audienceSettings?.cpmCents;
|
|
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
|
+
countryCode: country_code
|
|
163
|
+
};
|
|
164
|
+
if (ttl) {
|
|
165
|
+
payload.metadata.ttl = ttl;
|
|
166
|
+
}
|
|
167
|
+
if (cpm_cents && currency) {
|
|
168
|
+
payload.metadata.audienceFees = [];
|
|
169
|
+
payload.metadata?.audienceFees.push({
|
|
170
|
+
currency,
|
|
171
|
+
cpmCents: cpm_cents
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
statsTags?.push(`slug:${destination.slug}`);
|
|
175
|
+
statsClient?.incr(`${statsName}.call`, 1, statsTags);
|
|
176
|
+
try {
|
|
177
|
+
let payloadString = JSON.stringify(payload);
|
|
178
|
+
const regex = /"advertiserId":"(\d+)"/;
|
|
179
|
+
payloadString = payloadString.replace(regex, '"advertiserId":$1');
|
|
180
|
+
const response = await request(`${endpoint}/amc/audiences/metadata`, {
|
|
181
|
+
method: 'POST',
|
|
182
|
+
body: payloadString,
|
|
183
|
+
headers: {
|
|
184
|
+
'Content-Type': 'application/vnd.amcaudiences.v1+json'
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
const res = await response.text();
|
|
188
|
+
const resString = res.replace(/"audienceId":(\d+)/, '"audienceId":"$1"');
|
|
189
|
+
const externalId = JSON.parse(resString)['audienceId'];
|
|
190
|
+
if (!externalId) {
|
|
191
|
+
statsClient?.incr(`${statsName}.error`, 1, statsTags);
|
|
192
|
+
throw new actions_core_1.IntegrationError('Invalid response from create audience request', 'INVALID_RESPONSE', 400);
|
|
193
|
+
}
|
|
194
|
+
statsClient?.incr(`${statsName}.success`, 1, statsTags);
|
|
195
|
+
return {
|
|
196
|
+
externalId
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
catch (e) {
|
|
200
|
+
if (e instanceof utils_1.AmazonAdsError) {
|
|
201
|
+
const message = JSON.parse(e.response?.data?.message || '');
|
|
202
|
+
statsTags?.push(`error:${message}`);
|
|
203
|
+
statsClient?.incr(`${statsName}.error`, 1, statsTags);
|
|
204
|
+
throw new actions_core_1.APIError(message, e.response?.status);
|
|
205
|
+
}
|
|
206
|
+
else if (e instanceof actions_core_1.IntegrationError) {
|
|
207
|
+
statsClient?.incr(`${statsName}.error`, 1, statsTags);
|
|
208
|
+
statsTags?.push(`error:${e.message}`);
|
|
209
|
+
throw new actions_core_1.APIError(e.message, 400);
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
statsTags?.push(`error:${e}`);
|
|
213
|
+
statsClient?.incr(`${statsName}.error`, 1, statsTags);
|
|
214
|
+
throw e;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
async getAudience(request, getAudienceInput) {
|
|
219
|
+
const { statsContext } = getAudienceInput;
|
|
220
|
+
const audience_id = getAudienceInput.externalId;
|
|
221
|
+
const endpoint = getAudienceInput.settings.region;
|
|
222
|
+
const { statsClient, tags: statsTags } = statsContext || {};
|
|
223
|
+
const statsName = 'getAudience';
|
|
224
|
+
statsTags?.push(`slug:${destination.slug}`);
|
|
225
|
+
statsClient?.incr(`${statsName}.call`, 1, statsTags);
|
|
226
|
+
if (!audience_id) {
|
|
227
|
+
throw new actions_core_1.IntegrationError('Missing audience_id value', 'MISSING_REQUIRED_FIELD', 400);
|
|
228
|
+
}
|
|
229
|
+
try {
|
|
230
|
+
const response = await request(`${endpoint}/amc/audiences/metadata/${audience_id}`, {
|
|
231
|
+
method: 'GET'
|
|
232
|
+
});
|
|
233
|
+
const res = await response.text();
|
|
234
|
+
const resString = res.replace(/"audienceId":(\d+)/, '"audienceId":"$1"');
|
|
235
|
+
const externalId = JSON.parse(resString)['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
|
+
}
|
|
80
257
|
}
|
|
81
258
|
},
|
|
82
259
|
actions: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/destinations/amazon-ads/index.ts"],"names":[],"mappings":";;;;;AACA,
|
|
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;g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;
|
|
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;
|
|
2
13
|
}
|
|
@@ -1,15 +1,244 @@
|
|
|
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");
|
|
5
|
+
const crypto_1 = require("crypto");
|
|
3
6
|
const action = {
|
|
4
|
-
title: 'Sync
|
|
7
|
+
title: 'Sync Audience',
|
|
5
8
|
description: 'Sync audiences from Segment to Amazon Ads Audience.',
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
defaultSubscription: 'event = "Audience Entered" or event = "Audience Exited"',
|
|
10
|
+
fields: {
|
|
11
|
+
event_name: {
|
|
12
|
+
label: 'Event Name',
|
|
13
|
+
description: 'The name of the current Segment event.',
|
|
14
|
+
type: 'string',
|
|
15
|
+
unsafe_hidden: true,
|
|
16
|
+
default: {
|
|
17
|
+
'@path': '$.event'
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
externalUserId: {
|
|
21
|
+
label: 'External User ID',
|
|
22
|
+
description: 'This is an external user identifier defined by data providers.',
|
|
23
|
+
type: 'string',
|
|
24
|
+
required: true,
|
|
25
|
+
default: { '@path': '$.userId' }
|
|
26
|
+
},
|
|
27
|
+
email: {
|
|
28
|
+
label: 'Email',
|
|
29
|
+
description: 'User email address. Vaule will be hashed before sending to Amazon.',
|
|
30
|
+
type: 'string',
|
|
31
|
+
required: false,
|
|
32
|
+
default: {
|
|
33
|
+
'@if': {
|
|
34
|
+
exists: { '@path': '$.context.properties.email' },
|
|
35
|
+
then: { '@path': '$.context.properties.email' },
|
|
36
|
+
else: { '@path': '$.properties.email' }
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
firstName: {
|
|
41
|
+
label: 'First name',
|
|
42
|
+
description: 'User first name. Vaue will be hashed before sending to Amazon.',
|
|
43
|
+
type: 'string',
|
|
44
|
+
required: false,
|
|
45
|
+
default: {
|
|
46
|
+
'@if': {
|
|
47
|
+
exists: { '@path': '$.context.properties.first_name' },
|
|
48
|
+
then: { '@path': '$.context.properties.first_name' },
|
|
49
|
+
else: { '@path': '$.properties.first_name' }
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
lastName: {
|
|
54
|
+
label: 'Last name',
|
|
55
|
+
description: 'User Last name. Vaue will be hashed before sending to Amazon.',
|
|
56
|
+
type: 'string',
|
|
57
|
+
required: false,
|
|
58
|
+
default: {
|
|
59
|
+
'@if': {
|
|
60
|
+
exists: { '@path': '$.context.properties.last_name' },
|
|
61
|
+
then: { '@path': '$.context.properties.last_name' },
|
|
62
|
+
else: { '@path': '$.properties.last_name' }
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
phone: {
|
|
67
|
+
label: 'Phone',
|
|
68
|
+
description: 'Phone Number. Vaue will be hashed before sending to Amazon.',
|
|
69
|
+
type: 'string',
|
|
70
|
+
required: false,
|
|
71
|
+
default: {
|
|
72
|
+
'@if': {
|
|
73
|
+
exists: { '@path': '$.context.properties.phone' },
|
|
74
|
+
then: { '@path': '$.context.properties.phone' },
|
|
75
|
+
else: { '@path': '$.properties.phone' }
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
postal: {
|
|
80
|
+
label: 'Postal',
|
|
81
|
+
description: 'POstal Code. Vaue will be hashed before sending to Amazon.',
|
|
82
|
+
type: 'string',
|
|
83
|
+
required: false,
|
|
84
|
+
default: {
|
|
85
|
+
'@if': {
|
|
86
|
+
exists: { '@path': '$.context.properties.postal' },
|
|
87
|
+
then: { '@path': '$.context.properties.postal' },
|
|
88
|
+
else: { '@path': '$.properties.postal' }
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
state: {
|
|
93
|
+
label: 'Postal',
|
|
94
|
+
description: 'State Code. Vaue will be hashed before sending to Amazon.',
|
|
95
|
+
type: 'string',
|
|
96
|
+
required: false,
|
|
97
|
+
default: {
|
|
98
|
+
'@if': {
|
|
99
|
+
exists: { '@path': '$.context.properties.state' },
|
|
100
|
+
then: { '@path': '$.context.properties.state' },
|
|
101
|
+
else: { '@path': '$.properties.state' }
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
city: {
|
|
106
|
+
label: 'City',
|
|
107
|
+
description: 'City name. Vaue will be hashed before sending to Amazon.',
|
|
108
|
+
type: 'string',
|
|
109
|
+
required: false,
|
|
110
|
+
default: {
|
|
111
|
+
'@if': {
|
|
112
|
+
exists: { '@path': '$.context.properties.city' },
|
|
113
|
+
then: { '@path': '$.context.properties.city' },
|
|
114
|
+
else: { '@path': '$.properties.city' }
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
address: {
|
|
119
|
+
label: 'Address',
|
|
120
|
+
description: 'Address Code. Value will be hashed before sending to Amazon.',
|
|
121
|
+
type: 'string',
|
|
122
|
+
required: false,
|
|
123
|
+
default: {
|
|
124
|
+
'@if': {
|
|
125
|
+
exists: { '@path': '$.context.properties.address' },
|
|
126
|
+
then: { '@path': '$.context.properties.address' },
|
|
127
|
+
else: { '@path': '$.properties.address' }
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
audienceId: {
|
|
132
|
+
label: 'Audience ID',
|
|
133
|
+
type: 'string',
|
|
134
|
+
required: true,
|
|
135
|
+
description: 'An number value representing the Amazon audience identifier. This is the identifier that is returned during audience creation.',
|
|
136
|
+
default: {
|
|
137
|
+
'@path': '$.context.personas.external_audience_id'
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
perform: (request, { settings, payload, statsContext, audienceSettings }) => {
|
|
142
|
+
return processPayload(request, settings, [payload], statsContext, audienceSettings);
|
|
143
|
+
},
|
|
144
|
+
performBatch: (request, { settings, payload: payloads, statsContext, audienceSettings }) => {
|
|
145
|
+
return processPayload(request, settings, payloads, statsContext, audienceSettings);
|
|
12
146
|
}
|
|
13
147
|
};
|
|
148
|
+
async function processPayload(request, settings, payload, statsContext, audienceSettings) {
|
|
149
|
+
const { statsClient, tags: statsTags } = statsContext || {};
|
|
150
|
+
const statsName = 'syncAmazonAdsAudience';
|
|
151
|
+
statsClient?.incr(`${statsName}.intialise`, 1, statsTags);
|
|
152
|
+
if (payload.length && !payload[0].audienceId) {
|
|
153
|
+
throw new actions_core_1.PayloadValidationError('Audience ID is required.');
|
|
154
|
+
}
|
|
155
|
+
try {
|
|
156
|
+
const payloadRecord = createPayloadToUploadRecords(payload, audienceSettings);
|
|
157
|
+
const payloadString = JSON.stringify(payloadRecord).replace(/"audienceId":"(\d+)"/, '"audienceId":$1');
|
|
158
|
+
const response = await request(`${settings.region}/amc/audiences/records`, {
|
|
159
|
+
method: 'POST',
|
|
160
|
+
body: payloadString,
|
|
161
|
+
headers: {
|
|
162
|
+
'Content-Type': 'application/vnd.amcaudiences.v1+json'
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
const result = await response.json();
|
|
166
|
+
const jobRequestId = result?.jobRequestId;
|
|
167
|
+
statsTags?.push(`jobRequestId:${jobRequestId}`);
|
|
168
|
+
statsClient?.incr(`${statsName}.success`, 1, statsTags);
|
|
169
|
+
if (!jobRequestId) {
|
|
170
|
+
throw new actions_core_1.IntegrationError('Invalid response from upload audinece record call', 'INVALID_RESPONSE', 400);
|
|
171
|
+
}
|
|
172
|
+
return {
|
|
173
|
+
result
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
catch (e) {
|
|
177
|
+
if (e instanceof utils_1.AmazonAdsError) {
|
|
178
|
+
const message = JSON.parse(e.response?.data?.message || '');
|
|
179
|
+
statsTags?.push(`error:${message}`);
|
|
180
|
+
statsClient?.incr(`${statsName}.error`, 1, statsTags);
|
|
181
|
+
throw new actions_core_1.APIError(message, e.response?.status);
|
|
182
|
+
}
|
|
183
|
+
else if (e instanceof actions_core_1.IntegrationError) {
|
|
184
|
+
statsTags?.push(`error:${e.message}`);
|
|
185
|
+
statsClient?.incr(`${statsName}.error`, 1, statsTags);
|
|
186
|
+
throw new actions_core_1.APIError(e.message, 400);
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
statsTags?.push(`error:${e}`);
|
|
190
|
+
statsClient?.incr(`${statsName}.error`, 1, statsTags);
|
|
191
|
+
throw e;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
function createPayloadToUploadRecords(payloads, audienceSettings) {
|
|
196
|
+
const records = [];
|
|
197
|
+
const { audienceId } = payloads[0];
|
|
198
|
+
payloads.forEach((payload) => {
|
|
199
|
+
const hashedPII = {};
|
|
200
|
+
if (payload.firstName) {
|
|
201
|
+
hashedPII.firstname = normalizeAndHash(payload.firstName);
|
|
202
|
+
}
|
|
203
|
+
if (payload.lastName) {
|
|
204
|
+
hashedPII.lastname = normalizeAndHash(payload.lastName);
|
|
205
|
+
}
|
|
206
|
+
if (payload.address) {
|
|
207
|
+
hashedPII.address = normalizeAndHash(payload.address);
|
|
208
|
+
}
|
|
209
|
+
if (payload.postal) {
|
|
210
|
+
hashedPII.postal = normalizeAndHash(payload.postal);
|
|
211
|
+
}
|
|
212
|
+
if (payload.phone) {
|
|
213
|
+
hashedPII.phone = normalizeAndHash(payload.phone);
|
|
214
|
+
}
|
|
215
|
+
if (payload.city) {
|
|
216
|
+
hashedPII.city = normalizeAndHash(payload.city);
|
|
217
|
+
}
|
|
218
|
+
if (payload.state) {
|
|
219
|
+
hashedPII.state = normalizeAndHash(payload.state);
|
|
220
|
+
}
|
|
221
|
+
if (payload.email) {
|
|
222
|
+
hashedPII.email = normalizeAndHash(payload.email);
|
|
223
|
+
}
|
|
224
|
+
const payloadRecord = {
|
|
225
|
+
externalUserId: payload.externalUserId,
|
|
226
|
+
countryCode: audienceSettings.countryCode,
|
|
227
|
+
action: payload.event_name == 'Audience Entered' ? 'CREATE' : 'DELETE',
|
|
228
|
+
hashedPII: [hashedPII]
|
|
229
|
+
};
|
|
230
|
+
records.push(payloadRecord);
|
|
231
|
+
});
|
|
232
|
+
return {
|
|
233
|
+
records: records,
|
|
234
|
+
audienceId: audienceId
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
function normalizeAndHash(data) {
|
|
238
|
+
const normalizedData = data.toLowerCase().trim();
|
|
239
|
+
const hash = crypto_1.createHash('sha256');
|
|
240
|
+
hash.update(normalizedData);
|
|
241
|
+
return hash.digest('hex');
|
|
242
|
+
}
|
|
14
243
|
exports.default = action;
|
|
15
244
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/amazon-ads/syncAudiences/index.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/amazon-ads/syncAudiences/index.ts"],"names":[],"mappings":";;AACA,wDAA0F;AAG1F,oCAAyC;AACzC,mCAAmC;AAGnC,MAAM,MAAM,GAAwC;IAClD,KAAK,EAAE,eAAe;IACtB,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,QAA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
};
|
|
22
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":"Profile.js","sourceRoot":"","sources":["../../../../src/destinations/engage/sendgrid/Profile.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { InputField } from '@segment/actions-core';
|
|
2
|
+
import { RequestClient } from '@segment/actions-core';
|
|
3
|
+
import { Logger, StatsClient, DataFeedCache } from '@segment/actions-core/destination-kit';
|
|
4
|
+
import type { Settings } from '../generated-types';
|
|
5
|
+
import { Profile } from '../Profile';
|
|
6
|
+
export declare type ApiLookupConfig = {
|
|
7
|
+
id?: string | undefined;
|
|
8
|
+
name: string;
|
|
9
|
+
url: string;
|
|
10
|
+
method: string;
|
|
11
|
+
cacheTtl: number;
|
|
12
|
+
body?: string | undefined;
|
|
13
|
+
headers?: object | undefined;
|
|
14
|
+
responseType: string;
|
|
15
|
+
};
|
|
16
|
+
export declare const getRequestId: ({ method, url, body, headers }: ApiLookupConfig) => string;
|
|
17
|
+
export declare const getCachedResponse: ({ responseType }: ApiLookupConfig, requestId: string, dataFeedCache: DataFeedCache, datafeedTags: string[]) => Promise<any>;
|
|
18
|
+
export declare const performApiLookup: (request: RequestClient, apiLookupConfig: ApiLookupConfig, profile: Profile, statsClient: StatsClient | undefined, tags: string[], settings: Settings, logger?: Logger | undefined, dataFeedCache?: DataFeedCache | undefined) => Promise<any>;
|
|
19
|
+
export declare const apiLookupActionFields: Record<string, InputField>;
|
|
20
|
+
export declare const apiLookupLiquidKey = "lookups";
|
|
21
|
+
export declare const FLAGON_NAME_DATA_FEEDS = "is-datafeeds-enabled";
|