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