@segment/action-destinations 3.132.1-intercom-fix.12 → 3.132.1-staging.183
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/actable-predictive/index.js +1 -1
- package/dist/destinations/actable-predictive/index.js.map +1 -1
- package/dist/destinations/actable-predictive/sendCustomEvent/index.js +13 -13
- package/dist/destinations/actable-predictive/sendCustomEvent/index.js.map +1 -1
- package/dist/destinations/actable-predictive/sendEmailEvent/index.js +20 -20
- package/dist/destinations/actable-predictive/sendEmailEvent/index.js.map +1 -1
- package/dist/destinations/actable-predictive/sendTransactionEvent/index.js +28 -28
- package/dist/destinations/actable-predictive/sendTransactionEvent/index.js.map +1 -1
- package/dist/destinations/actable-predictive/sendWebEvent/index.js +25 -25
- package/dist/destinations/actable-predictive/sendWebEvent/index.js.map +1 -1
- package/dist/destinations/actions-bingads/functions.d.ts +0 -0
- package/dist/destinations/actions-bingads/functions.js +2 -0
- package/dist/destinations/actions-bingads/functions.js.map +1 -0
- package/dist/destinations/actions-bingads/generated-types.d.ts +10 -0
- package/dist/destinations/actions-bingads/generated-types.js +3 -0
- package/dist/destinations/actions-bingads/generated-types.js.map +1 -0
- package/dist/destinations/actions-bingads/index.d.ts +4 -0
- package/dist/destinations/actions-bingads/index.js +77 -0
- package/dist/destinations/actions-bingads/index.js.map +1 -0
- package/dist/destinations/actions-bingads/offlineConversions/formatter.d.ts +8 -0
- package/dist/destinations/actions-bingads/offlineConversions/formatter.js +33 -0
- package/dist/destinations/actions-bingads/offlineConversions/formatter.js.map +1 -0
- package/dist/destinations/actions-bingads/offlineConversions/generated-types.d.ts +7 -0
- package/dist/destinations/actions-bingads/offlineConversions/generated-types.js +3 -0
- package/dist/destinations/actions-bingads/offlineConversions/generated-types.js.map +1 -0
- package/dist/destinations/actions-bingads/offlineConversions/index.d.ts +5 -0
- package/dist/destinations/actions-bingads/offlineConversions/index.js +131 -0
- package/dist/destinations/actions-bingads/offlineConversions/index.js.map +1 -0
- package/dist/destinations/braze/trackEvent/generated-types.d.ts +0 -1
- package/dist/destinations/braze/trackEvent/index.js +35 -11
- package/dist/destinations/braze/trackEvent/index.js.map +1 -1
- package/dist/destinations/braze/trackPurchase/index.js +43 -2
- package/dist/destinations/braze/trackPurchase/index.js.map +1 -1
- package/dist/destinations/braze-cohorts/cohortChanges.d.ts +10 -0
- package/dist/destinations/braze-cohorts/cohortChanges.js +3 -0
- package/dist/destinations/braze-cohorts/cohortChanges.js.map +1 -0
- package/dist/destinations/clevertap/userDelete/index.js +4 -4
- package/dist/destinations/clevertap/userDelete/index.js.map +1 -1
- package/dist/destinations/cordial/addContactToList/generated-types.d.ts +3 -1
- package/dist/destinations/cordial/addContactToList/index.js +2 -7
- package/dist/destinations/cordial/addContactToList/index.js.map +1 -1
- package/dist/destinations/cordial/addProductToCart/generated-types.d.ts +3 -1
- package/dist/destinations/cordial/addProductToCart/index.js +3 -8
- package/dist/destinations/cordial/addProductToCart/index.js.map +1 -1
- package/dist/destinations/cordial/cordial-client.d.ts +11 -0
- package/dist/destinations/cordial/cordial-client.js +36 -8
- package/dist/destinations/cordial/cordial-client.js.map +1 -1
- package/dist/destinations/cordial/createContactactivity/generated-types.d.ts +3 -1
- package/dist/destinations/cordial/createContactactivity/index.js +2 -7
- package/dist/destinations/cordial/createContactactivity/index.js.map +1 -1
- package/dist/destinations/cordial/generated-types.d.ts +1 -0
- package/dist/destinations/cordial/identities-fields.d.ts +3 -0
- package/dist/destinations/cordial/identities-fields.js +28 -0
- package/dist/destinations/cordial/identities-fields.js.map +1 -0
- package/dist/destinations/cordial/index.js +10 -2
- package/dist/destinations/cordial/index.js.map +1 -1
- package/dist/destinations/cordial/mergeContacts/generated-types.d.ts +5 -0
- package/dist/destinations/cordial/mergeContacts/generated-types.js +3 -0
- package/dist/destinations/cordial/mergeContacts/generated-types.js.map +1 -0
- package/dist/destinations/cordial/mergeContacts/index.d.ts +5 -0
- package/dist/destinations/cordial/mergeContacts/index.js +40 -0
- package/dist/destinations/cordial/mergeContacts/index.js.map +1 -0
- package/dist/destinations/cordial/removeContactFromList/generated-types.d.ts +3 -1
- package/dist/destinations/cordial/removeContactFromList/index.js +2 -7
- package/dist/destinations/cordial/removeContactFromList/index.js.map +1 -1
- package/dist/destinations/cordial/removeProductFromCart/generated-types.d.ts +3 -1
- package/dist/destinations/cordial/removeProductFromCart/index.js +2 -7
- package/dist/destinations/cordial/removeProductFromCart/index.js.map +1 -1
- package/dist/destinations/cordial/upsertContact/generated-types.d.ts +3 -1
- package/dist/destinations/cordial/upsertContact/index.js +2 -7
- package/dist/destinations/cordial/upsertContact/index.js.map +1 -1
- package/dist/destinations/cordial/upsertOrder/generated-types.d.ts +3 -1
- package/dist/destinations/cordial/upsertOrder/index.js +10 -15
- package/dist/destinations/cordial/upsertOrder/index.js.map +1 -1
- package/dist/destinations/emarsys/addToContactList/generated-types.d.ts +5 -0
- package/dist/destinations/emarsys/addToContactList/generated-types.js +3 -0
- package/dist/destinations/emarsys/addToContactList/generated-types.js.map +1 -0
- package/dist/destinations/emarsys/addToContactList/index.d.ts +5 -0
- package/dist/destinations/emarsys/addToContactList/index.js +116 -0
- package/dist/destinations/emarsys/addToContactList/index.js.map +1 -0
- package/dist/destinations/emarsys/emarsys-helper.d.ts +63 -0
- package/dist/destinations/emarsys/emarsys-helper.js +88 -0
- package/dist/destinations/emarsys/emarsys-helper.js.map +1 -0
- package/dist/destinations/emarsys/generated-types.d.ts +4 -0
- package/dist/destinations/emarsys/generated-types.js +3 -0
- package/dist/destinations/emarsys/generated-types.js.map +1 -0
- package/dist/destinations/emarsys/index.d.ts +4 -0
- package/dist/destinations/emarsys/index.js +60 -0
- package/dist/destinations/emarsys/index.js.map +1 -0
- package/dist/destinations/emarsys/removeFromContactList/generated-types.d.ts +5 -0
- package/dist/destinations/emarsys/removeFromContactList/generated-types.js +3 -0
- package/dist/destinations/emarsys/removeFromContactList/generated-types.js.map +1 -0
- package/dist/destinations/emarsys/removeFromContactList/index.d.ts +5 -0
- package/dist/destinations/emarsys/removeFromContactList/index.js +115 -0
- package/dist/destinations/emarsys/removeFromContactList/index.js.map +1 -0
- package/dist/destinations/emarsys/triggerEvent/generated-types.d.ts +8 -0
- package/dist/destinations/emarsys/triggerEvent/generated-types.js +3 -0
- package/dist/destinations/emarsys/triggerEvent/generated-types.js.map +1 -0
- package/dist/destinations/emarsys/triggerEvent/index.d.ts +5 -0
- package/dist/destinations/emarsys/triggerEvent/index.js +126 -0
- package/dist/destinations/emarsys/triggerEvent/index.js.map +1 -0
- package/dist/destinations/emarsys/upsertContact/generated-types.d.ts +9 -0
- package/dist/destinations/emarsys/upsertContact/generated-types.js +3 -0
- package/dist/destinations/emarsys/upsertContact/generated-types.js.map +1 -0
- package/dist/destinations/emarsys/upsertContact/index.d.ts +5 -0
- package/dist/destinations/emarsys/upsertContact/index.js +129 -0
- package/dist/destinations/emarsys/upsertContact/index.js.map +1 -0
- package/dist/destinations/engage-messaging-twilio/sendSms/sms-sender.d.ts +5 -0
- package/dist/destinations/engage-messaging-twilio/sendSms/sms-sender.js +1 -0
- package/dist/destinations/engage-messaging-twilio/sendSms/sms-sender.js.map +1 -1
- package/dist/destinations/engage-messaging-twilio/sendWhatsApp/generated-types.d.ts +1 -0
- package/dist/destinations/engage-messaging-twilio/sendWhatsApp/index.js +8 -0
- package/dist/destinations/engage-messaging-twilio/sendWhatsApp/index.js.map +1 -1
- package/dist/destinations/engage-messaging-twilio/sendWhatsApp/whatsapp-sender.d.ts +6 -0
- package/dist/destinations/engage-messaging-twilio/sendWhatsApp/whatsapp-sender.js +5 -1
- package/dist/destinations/engage-messaging-twilio/sendWhatsApp/whatsapp-sender.js.map +1 -1
- package/dist/destinations/engage-messaging-twilio/utils/message-sender.d.ts +1 -0
- package/dist/destinations/engage-messaging-twilio/utils/message-sender.js +1 -1
- package/dist/destinations/engage-messaging-twilio/utils/message-sender.js.map +1 -1
- package/dist/destinations/google-sheets-partner/constants.d.ts +3 -0
- package/dist/destinations/google-sheets-partner/constants.js +7 -0
- package/dist/destinations/google-sheets-partner/constants.js.map +1 -0
- package/dist/destinations/google-sheets-partner/generated-types.d.ts +2 -0
- package/dist/destinations/google-sheets-partner/generated-types.js +3 -0
- package/dist/destinations/google-sheets-partner/generated-types.js.map +1 -0
- package/dist/destinations/google-sheets-partner/googleapis/index.d.ts +17 -0
- package/dist/destinations/google-sheets-partner/googleapis/index.js +34 -0
- package/dist/destinations/google-sheets-partner/googleapis/index.js.map +1 -0
- package/dist/destinations/google-sheets-partner/index.d.ts +4 -0
- package/dist/destinations/google-sheets-partner/index.js +43 -0
- package/dist/destinations/google-sheets-partner/index.js.map +1 -0
- package/dist/destinations/google-sheets-partner/postSheet/generated-types.d.ts +11 -0
- package/dist/destinations/google-sheets-partner/postSheet/generated-types.js +3 -0
- package/dist/destinations/google-sheets-partner/postSheet/generated-types.js.map +1 -0
- package/dist/destinations/google-sheets-partner/postSheet/index.d.ts +5 -0
- package/dist/destinations/google-sheets-partner/postSheet/index.js +79 -0
- package/dist/destinations/google-sheets-partner/postSheet/index.js.map +1 -0
- package/dist/destinations/google-sheets-partner/postSheet/operations.d.ts +10 -0
- package/dist/destinations/google-sheets-partner/postSheet/operations.js +96 -0
- package/dist/destinations/google-sheets-partner/postSheet/operations.js.map +1 -0
- package/dist/destinations/index.js +3 -0
- package/dist/destinations/index.js.map +1 -1
- package/dist/destinations/livelike-cloud/trackEvent/generated-types.d.ts +1 -1
- package/dist/destinations/livelike-cloud/trackEvent/index.js +6 -12
- package/dist/destinations/livelike-cloud/trackEvent/index.js.map +1 -1
- package/dist/destinations/mixpanel/index.js +1 -1
- package/dist/destinations/mixpanel/mixpanel-properties.js.map +1 -1
- package/dist/destinations/mixpanel/trackEvent/functions.js +1 -1
- package/dist/destinations/mixpanel/trackEvent/functions.js.map +1 -1
- package/dist/destinations/mixpanel/trackEvent/index.js.map +1 -1
- package/dist/destinations/mixpanel/trackPurchase/index.js.map +1 -1
- package/dist/destinations/salesforce/sf-properties.d.ts +1 -0
- package/dist/destinations/salesforce/sf-properties.js.map +1 -1
- package/dist/destinations/saleswings/index.js +1 -1
- package/dist/destinations/saleswings/index.js.map +1 -1
- package/dist/destinations/segment/segment-properties.js +1 -2
- package/dist/destinations/segment/segment-properties.js.map +1 -1
- package/dist/destinations/segment/sendTrack/generated-types.d.ts +1 -1
- package/dist/destinations/tiktok-audiences/api/index.d.ts +11 -0
- package/dist/destinations/tiktok-audiences/api/index.js +38 -0
- package/dist/destinations/tiktok-audiences/api/index.js.map +1 -0
- package/dist/destinations/tiktok-audiences/constants.d.ts +2 -0
- package/dist/destinations/tiktok-audiences/constants.js +6 -0
- package/dist/destinations/tiktok-audiences/constants.js.map +1 -0
- package/dist/destinations/tiktok-audiences/generated-types.d.ts +3 -0
- package/dist/destinations/tiktok-audiences/generated-types.js +3 -0
- package/dist/destinations/tiktok-audiences/generated-types.js.map +1 -0
- package/dist/destinations/tiktok-audiences/index.d.ts +4 -0
- package/dist/destinations/tiktok-audiences/index.js +35 -0
- package/dist/destinations/tiktok-audiences/index.js.map +1 -0
- package/dist/destinations/tiktok-audiences/types.d.ts +33 -0
- package/dist/destinations/tiktok-audiences/types.js +3 -0
- package/dist/destinations/tiktok-audiences/types.js.map +1 -0
- package/dist/destinations/tiktok-audiences/updateAudience/generated-types.d.ts +9 -0
- package/dist/destinations/tiktok-audiences/updateAudience/generated-types.js +3 -0
- package/dist/destinations/tiktok-audiences/updateAudience/generated-types.js.map +1 -0
- package/dist/destinations/tiktok-audiences/updateAudience/index.d.ts +5 -0
- package/dist/destinations/tiktok-audiences/updateAudience/index.js +160 -0
- package/dist/destinations/tiktok-audiences/updateAudience/index.js.map +1 -0
- package/package.json +2 -2
- package/dist/destinations/braze/utils.d.ts +0 -6
- package/dist/destinations/braze/utils.js +0 -81
- package/dist/destinations/braze/utils.js.map +0 -1
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getContactLists = exports.getFields = exports.getEvents = exports.createWsseHeader = exports.API_BASE = exports.API_PATH = exports.API_HOST = void 0;
|
|
4
|
+
const actions_core_1 = require("@segment/actions-core");
|
|
5
|
+
const crypto_1 = require("crypto");
|
|
6
|
+
exports.API_HOST = 'https://api.emarsys.net';
|
|
7
|
+
exports.API_PATH = '/api/v2/';
|
|
8
|
+
exports.API_BASE = `${exports.API_HOST}${exports.API_PATH}`;
|
|
9
|
+
const createWsseHeader = (settings) => {
|
|
10
|
+
if (!settings.api_user || !settings.api_password) {
|
|
11
|
+
throw new actions_core_1.IntegrationError('Username and password must be specified.');
|
|
12
|
+
}
|
|
13
|
+
const nonce = crypto_1.randomBytes(16).toString('hex');
|
|
14
|
+
const hash = crypto_1.createHash('sha1');
|
|
15
|
+
const ts = new Date().toISOString();
|
|
16
|
+
const secret = nonce + ts + settings.api_password;
|
|
17
|
+
const secret_hash = Buffer.from(hash.update(secret).digest('hex')).toString('base64');
|
|
18
|
+
const auth_header = `UsernameToken Username="${settings.api_user}", PasswordDigest="${secret_hash}", Nonce="${nonce}", Created="${ts}"`;
|
|
19
|
+
return auth_header;
|
|
20
|
+
};
|
|
21
|
+
exports.createWsseHeader = createWsseHeader;
|
|
22
|
+
const getEvents = async (request) => {
|
|
23
|
+
const data = await request(`${exports.API_BASE}event`);
|
|
24
|
+
const choices = [];
|
|
25
|
+
if (data && data.content) {
|
|
26
|
+
const api_data = JSON.parse(data.content);
|
|
27
|
+
if (api_data && api_data.replyCode !== undefined && api_data.replyCode == 0) {
|
|
28
|
+
if (api_data.data && Array.isArray(api_data.data) && api_data.data.length > 0) {
|
|
29
|
+
for (let a = 0; a < api_data.data.length; a++) {
|
|
30
|
+
choices.push({
|
|
31
|
+
label: api_data.data[a].name,
|
|
32
|
+
value: api_data.data[a].id
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const events = {
|
|
39
|
+
choices: choices
|
|
40
|
+
};
|
|
41
|
+
return events;
|
|
42
|
+
};
|
|
43
|
+
exports.getEvents = getEvents;
|
|
44
|
+
const getFields = async (request) => {
|
|
45
|
+
const data = await request(`${exports.API_BASE}field/translate/en`);
|
|
46
|
+
const choices = [];
|
|
47
|
+
if (data && data.content) {
|
|
48
|
+
const api_data = JSON.parse(data.content);
|
|
49
|
+
if (api_data && api_data.replyCode !== undefined && api_data.replyCode == 0) {
|
|
50
|
+
if (api_data.data && Array.isArray(api_data.data) && api_data.data.length > 0) {
|
|
51
|
+
for (let a = 0; a < api_data.data.length; a++) {
|
|
52
|
+
choices.push({
|
|
53
|
+
label: api_data.data[a].name,
|
|
54
|
+
value: api_data.data[a].id
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const fields = {
|
|
61
|
+
choices: choices
|
|
62
|
+
};
|
|
63
|
+
return fields;
|
|
64
|
+
};
|
|
65
|
+
exports.getFields = getFields;
|
|
66
|
+
const getContactLists = async (request) => {
|
|
67
|
+
const data = await request(`${exports.API_BASE}contactlist`);
|
|
68
|
+
const choices = [];
|
|
69
|
+
if (data && data.content) {
|
|
70
|
+
const api_data = JSON.parse(data.content);
|
|
71
|
+
if (api_data && api_data.replyCode !== undefined && api_data.replyCode == 0) {
|
|
72
|
+
if (api_data.data && Array.isArray(api_data.data) && api_data.data.length > 0) {
|
|
73
|
+
for (let a = 0; a < api_data.data.length; a++) {
|
|
74
|
+
choices.push({
|
|
75
|
+
label: api_data.data[a].name,
|
|
76
|
+
value: api_data.data[a].id
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const lists = {
|
|
83
|
+
choices: choices
|
|
84
|
+
};
|
|
85
|
+
return lists;
|
|
86
|
+
};
|
|
87
|
+
exports.getContactLists = getContactLists;
|
|
88
|
+
//# sourceMappingURL=emarsys-helper.js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AAC,MAAM,EAAE,CAAC,EAAE,EAAE;oBAC7C,OAAO,CAAC,IAAI,CAAC;wBACX,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI;wBAC5B,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE;qBAC3B,CAAC,CAAA;iBACH;aACF;SACF;KACF;IACD,MAAM,KAAK,GAAG;QACZ,OAAO,EAAE,OAAO;KACjB,CAAA;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AApBY,QAAA,eAAe,mBAoB3B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generated-types.js","sourceRoot":"","sources":["../../../src/destinations/emarsys/generated-types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,60 @@
|
|
|
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 addToContactList_1 = __importDefault(require("./addToContactList"));
|
|
7
|
+
const removeFromContactList_1 = __importDefault(require("./removeFromContactList"));
|
|
8
|
+
const triggerEvent_1 = __importDefault(require("./triggerEvent"));
|
|
9
|
+
const upsertContact_1 = __importDefault(require("./upsertContact"));
|
|
10
|
+
const emarsys_helper_1 = require("./emarsys-helper");
|
|
11
|
+
const destination = {
|
|
12
|
+
name: 'Emarsys',
|
|
13
|
+
slug: 'actions-emarsys',
|
|
14
|
+
mode: 'cloud',
|
|
15
|
+
authentication: {
|
|
16
|
+
scheme: 'custom',
|
|
17
|
+
fields: {
|
|
18
|
+
api_user: {
|
|
19
|
+
label: 'API username',
|
|
20
|
+
description: 'Your Emarsys API username',
|
|
21
|
+
type: 'string',
|
|
22
|
+
required: true
|
|
23
|
+
},
|
|
24
|
+
api_password: {
|
|
25
|
+
label: 'API password',
|
|
26
|
+
description: 'Your Emarsys API password.',
|
|
27
|
+
type: 'password',
|
|
28
|
+
required: true
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
testAuthentication: async (request) => {
|
|
32
|
+
const data = await request(`${emarsys_helper_1.API_BASE}settings`);
|
|
33
|
+
if (data && data.content) {
|
|
34
|
+
const api_data = JSON.parse(data.content);
|
|
35
|
+
if (api_data && api_data.replyCode !== undefined && api_data.replyCode == 0) {
|
|
36
|
+
if (api_data.data && api_data.data.id) {
|
|
37
|
+
if (api_data.data.id > 0) {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
throw new Error('Authentication failed');
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
actions: {
|
|
47
|
+
upsertContact: upsertContact_1.default,
|
|
48
|
+
addToContactList: addToContactList_1.default,
|
|
49
|
+
removeFromContactList: removeFromContactList_1.default,
|
|
50
|
+
triggerEvent: triggerEvent_1.default
|
|
51
|
+
},
|
|
52
|
+
extendRequest: ({ settings }) => {
|
|
53
|
+
return {
|
|
54
|
+
headers: { 'X-WSSE': emarsys_helper_1.createWsseHeader(settings) },
|
|
55
|
+
responseType: 'json'
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
exports.default = destination;
|
|
60
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/destinations/emarsys/index.ts"],"names":[],"mappings":";;;;;AAEA,0EAAiD;AACjD,oFAA2D;AAC3D,kEAAyC;AACzC,oEAA2C;AAC3C,qDAA6D;AAE7D,MAAM,WAAW,GAAoC;IACnD,IAAI,EAAE,SAAS;IACf,IAAI,EAAE,iBAAiB;IACvB,IAAI,EAAE,OAAO;IAEb,cAAc,EAAE;QACd,MAAM,EAAE,QAAQ;QAChB,MAAM,EAAE;YACN,QAAQ,EAAE;gBAC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
{"version":3,"file":"generated-types.js","sourceRoot":"","sources":["../../../../src/destinations/emarsys/removeFromContactList/generated-types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const actions_core_1 = require("@segment/actions-core");
|
|
4
|
+
const emarsys_helper_1 = require("../emarsys-helper");
|
|
5
|
+
const action = {
|
|
6
|
+
title: 'Remove from Contact List',
|
|
7
|
+
description: 'Remove a contact from a contact list.',
|
|
8
|
+
fields: {
|
|
9
|
+
contactlistid: {
|
|
10
|
+
label: 'Id of the contact list',
|
|
11
|
+
description: 'The Id of the contactlist',
|
|
12
|
+
type: 'integer',
|
|
13
|
+
required: true,
|
|
14
|
+
dynamic: true
|
|
15
|
+
},
|
|
16
|
+
key_field: {
|
|
17
|
+
label: 'Key field',
|
|
18
|
+
description: 'The field to use to find the contact',
|
|
19
|
+
type: 'string',
|
|
20
|
+
required: true,
|
|
21
|
+
dynamic: true
|
|
22
|
+
},
|
|
23
|
+
key_value: {
|
|
24
|
+
label: 'Key value',
|
|
25
|
+
description: 'Value for the key field used to find the contact. E.g. the email address ',
|
|
26
|
+
type: 'string',
|
|
27
|
+
required: true,
|
|
28
|
+
dynamic: false
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
dynamicFields: {
|
|
32
|
+
contactlistid: async (request) => {
|
|
33
|
+
return emarsys_helper_1.getContactLists(request);
|
|
34
|
+
},
|
|
35
|
+
key_field: async (request) => {
|
|
36
|
+
return emarsys_helper_1.getFields(request);
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
perform: async (request, data) => {
|
|
40
|
+
if (!data?.payload?.key_field)
|
|
41
|
+
throw new actions_core_1.IntegrationError('Missing key field');
|
|
42
|
+
if (!data?.payload?.key_value)
|
|
43
|
+
throw new actions_core_1.IntegrationError('Missing key value');
|
|
44
|
+
data.payload.contactlistid = parseInt(data.payload.contactlistid.toString().replace(/[^0-9]/g, ''));
|
|
45
|
+
if (data.payload.contactlistid > 0) {
|
|
46
|
+
const payload = {
|
|
47
|
+
contactlistid: data.payload.contactlistid,
|
|
48
|
+
key_id: data.payload.key_field,
|
|
49
|
+
external_ids: [data.payload.key_value]
|
|
50
|
+
};
|
|
51
|
+
const response = await request(`${emarsys_helper_1.API_BASE}contactlist/${data.payload.contactlistid}/delete`, {
|
|
52
|
+
method: 'post',
|
|
53
|
+
json: payload,
|
|
54
|
+
throwHttpErrors: false
|
|
55
|
+
});
|
|
56
|
+
switch (response?.status) {
|
|
57
|
+
case 200:
|
|
58
|
+
try {
|
|
59
|
+
const body = await response.json();
|
|
60
|
+
if (body.replyCode === 0)
|
|
61
|
+
return response;
|
|
62
|
+
else
|
|
63
|
+
throw new actions_core_1.IntegrationError('Something went wrong while removing from contact list');
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
throw new actions_core_1.IntegrationError('Invalid JSON response');
|
|
67
|
+
}
|
|
68
|
+
case 400:
|
|
69
|
+
throw new actions_core_1.IntegrationError('The contact could not be removed from the contact list');
|
|
70
|
+
case 429:
|
|
71
|
+
throw new actions_core_1.RetryableError('Rate limit reached.');
|
|
72
|
+
default:
|
|
73
|
+
throw new actions_core_1.RetryableError('There seems to be an API issue.');
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
throw new actions_core_1.IntegrationError('ContactlistId must be >0');
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
performBatch: async (request, data) => {
|
|
81
|
+
if (data && data.payload && Array.isArray(data.payload)) {
|
|
82
|
+
const batches = {};
|
|
83
|
+
data.payload.forEach((payload) => {
|
|
84
|
+
if (!batches[`${payload.contactlistid}-${payload.key_field}`]) {
|
|
85
|
+
batches[`${payload.contactlistid}-${payload.key_field}`] = {
|
|
86
|
+
contactlistid: payload.contactlistid,
|
|
87
|
+
key_id: payload.key_field,
|
|
88
|
+
external_ids: []
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
batches[`${payload.contactlistid}-${payload.key_field}`].external_ids.push(payload.key_value);
|
|
92
|
+
});
|
|
93
|
+
const requests = [];
|
|
94
|
+
for (const key in batches) {
|
|
95
|
+
const batch = batches[key];
|
|
96
|
+
const payload = {
|
|
97
|
+
key_id: batch.key_id,
|
|
98
|
+
external_ids: batch.external_ids
|
|
99
|
+
};
|
|
100
|
+
const response = request(`${emarsys_helper_1.API_BASE}contactlist/${batch.contactlistid}/delete`, {
|
|
101
|
+
method: 'post',
|
|
102
|
+
json: payload,
|
|
103
|
+
throwHttpErrors: false
|
|
104
|
+
});
|
|
105
|
+
requests.push(response);
|
|
106
|
+
}
|
|
107
|
+
if (requests.length > 0) {
|
|
108
|
+
return Promise.all(requests);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return 0;
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
exports.default = action;
|
|
115
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/emarsys/removeFromContactList/index.ts"],"names":[],"mappings":";;AAAA,wDAAwE;AAIxE,sDAO0B;AAE1B,MAAM,MAAM,GAAwC;IAClD,KAAK,EAAE,0BAA0B;IACjC,WAAW,EAAE,uCAAuC;IACpD,MAAM,EAAE;QACN,aAAa,EAAE;YACb,KAAK,EAAE,wBAAwB;YAC/B,WAAW,EAAE,2BAA2B;YACxC,IAAI,EAAE,SAAS;YACf,QAAQ,EAAE,IAAI;YACd,OAAO,EAAE,IAAI;SACd;QACD,SAAS,EAAE;YACT,KAAK,EAAE,WAAW;YAClB,WAAW,EAAE,sCAAsC;YACnD,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,IAAI;YACd,OAAO,EAAE,IAAI;SACd;QACD,SAAS,EAAE;YACT,KAAK,EAAE,WAAW;YAClB,WAAW,EAAE,4EAA4E;YACzF,IAAI,EAAE,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C,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;YAC/F,CAAC,CAAC,CAAA;YAEF,MAAM,QAAQ,GAAG,EAAE,CAAA;YACnB,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE;gBACzB,MAAM,KAAK,GAA+B,OAAO,CAAC,GAAG,CAAC,CAAA;gBACtD,MAAM,OAAO,GAA0B;oBACrC,MAAM,EAAE,KAAK,CAAC,MAAM;oBACpB,YAAY,EAAE,KAAK,CAAC,YAAY;iBACjC,CAAA;gBACD,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,yBAAQ,eAAe,KAAK,CAAC,aAAa,SAAS,EAAE;oBAC/E,MAAM,EAAE,MAAM;oBACd,IAAI,EAAE,OAAO;oBACb,eAAe,EAAE,KAAK;iBACvB,CAAC,CAAA;gBACF,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;aACxB;YACD,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE;gBACvB,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;aAC7B;SACF;QACD,OAAO,CAAC,CAAA;IACV,CAAC;CACF,CAAA;AAED,kBAAe,MAAM,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generated-types.js","sourceRoot":"","sources":["../../../../src/destinations/emarsys/triggerEvent/generated-types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const emarsys_helper_1 = require("../emarsys-helper");
|
|
4
|
+
const actions_core_1 = require("@segment/actions-core");
|
|
5
|
+
const actions_core_2 = require("@segment/actions-core");
|
|
6
|
+
const action = {
|
|
7
|
+
title: 'Trigger Event',
|
|
8
|
+
description: 'Trigger an external event on the Emarsys platform to launch automation programs. Note: You can only pass objects to event_payload (no literals, no arrays).',
|
|
9
|
+
fields: {
|
|
10
|
+
eventid: {
|
|
11
|
+
label: 'Id of the external event',
|
|
12
|
+
description: 'The Id of the external event',
|
|
13
|
+
type: 'integer',
|
|
14
|
+
required: true,
|
|
15
|
+
dynamic: true
|
|
16
|
+
},
|
|
17
|
+
key_field: {
|
|
18
|
+
label: 'Key field',
|
|
19
|
+
description: 'The field to use to find the contact',
|
|
20
|
+
type: 'string',
|
|
21
|
+
required: true,
|
|
22
|
+
dynamic: true
|
|
23
|
+
},
|
|
24
|
+
key_value: {
|
|
25
|
+
label: 'Key value',
|
|
26
|
+
description: 'Value for the key field used to find the contact. E.g. the email address ',
|
|
27
|
+
type: 'string',
|
|
28
|
+
required: true,
|
|
29
|
+
dynamic: false
|
|
30
|
+
},
|
|
31
|
+
event_payload: {
|
|
32
|
+
label: 'Event payload',
|
|
33
|
+
description: 'A JSON object that will be passed to the Emarsys template engine and can be used for personalization',
|
|
34
|
+
type: 'object',
|
|
35
|
+
required: false,
|
|
36
|
+
allowNull: true
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
dynamicFields: {
|
|
40
|
+
eventid: async (request) => {
|
|
41
|
+
return emarsys_helper_1.getEvents(request);
|
|
42
|
+
},
|
|
43
|
+
key_field: async (request) => {
|
|
44
|
+
return emarsys_helper_1.getFields(request);
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
perform: async (request, data) => {
|
|
48
|
+
if (!data?.payload?.key_field)
|
|
49
|
+
throw new actions_core_1.IntegrationError('Missing key field');
|
|
50
|
+
if (!data?.payload?.key_value)
|
|
51
|
+
throw new actions_core_1.IntegrationError('Missing key value');
|
|
52
|
+
data.payload.eventid = parseInt(data.payload.eventid.toString().replace(/[^0-9]/g, ''));
|
|
53
|
+
if (data.payload.eventid > 0) {
|
|
54
|
+
const payload = {
|
|
55
|
+
key_id: data.payload.key_field,
|
|
56
|
+
external_id: data.payload.key_value,
|
|
57
|
+
data: data.payload.event_payload ?? null
|
|
58
|
+
};
|
|
59
|
+
const response = await request(`${emarsys_helper_1.API_BASE}event/${data.payload.eventid}/trigger`, {
|
|
60
|
+
method: 'post',
|
|
61
|
+
json: payload,
|
|
62
|
+
throwHttpErrors: false
|
|
63
|
+
});
|
|
64
|
+
switch (response?.status) {
|
|
65
|
+
case 200:
|
|
66
|
+
try {
|
|
67
|
+
const body = await response.json();
|
|
68
|
+
if (body.replyCode === 0)
|
|
69
|
+
return response;
|
|
70
|
+
else
|
|
71
|
+
throw new actions_core_1.IntegrationError('Something went wrong while triggering the event');
|
|
72
|
+
}
|
|
73
|
+
catch (err) {
|
|
74
|
+
throw new actions_core_1.IntegrationError('Invalid JSON response');
|
|
75
|
+
}
|
|
76
|
+
case 400:
|
|
77
|
+
throw new actions_core_1.IntegrationError('The event could not be triggered');
|
|
78
|
+
case 429:
|
|
79
|
+
throw new actions_core_2.RetryableError('Rate limit reached.');
|
|
80
|
+
default:
|
|
81
|
+
throw new actions_core_2.RetryableError('There seems to be an API issue.');
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
throw new actions_core_1.IntegrationError('eventid must be >0');
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
performBatch: async (request, data) => {
|
|
89
|
+
if (data && data.payload && Array.isArray(data.payload)) {
|
|
90
|
+
const batches = {};
|
|
91
|
+
data.payload.forEach((payload) => {
|
|
92
|
+
if (!batches[`${payload.eventid}-${payload.key_field}`]) {
|
|
93
|
+
batches[`${payload.eventid}-${payload.key_field}`] = {
|
|
94
|
+
event_id: payload.eventid,
|
|
95
|
+
key_id: payload.key_field,
|
|
96
|
+
keys: []
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
batches[`${payload.eventid}-${payload.key_field}`].keys.push({
|
|
100
|
+
external_id: payload.key_value,
|
|
101
|
+
data: payload.event_payload ?? null
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
const requests = [];
|
|
105
|
+
for (const key in batches) {
|
|
106
|
+
const batch = batches[key];
|
|
107
|
+
const payload = {
|
|
108
|
+
key_id: batch.key_id,
|
|
109
|
+
contacts: batch.keys
|
|
110
|
+
};
|
|
111
|
+
const response = request(`${emarsys_helper_1.API_BASE}event/${batch.event_id}/trigger`, {
|
|
112
|
+
method: 'post',
|
|
113
|
+
json: payload,
|
|
114
|
+
throwHttpErrors: false
|
|
115
|
+
});
|
|
116
|
+
requests.push(response);
|
|
117
|
+
}
|
|
118
|
+
if (requests.length > 0) {
|
|
119
|
+
return Promise.all(requests);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return 0;
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
exports.default = action;
|
|
126
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/emarsys/triggerEvent/index.ts"],"names":[],"mappings":";;AAGA,sDAS0B;AAC1B,wDAAwD;AACxD,wDAAsD;AAEtD,MAAM,MAAM,GAAwC;IAClD,KAAK,EAAE,eAAe;IACtB,WAAW,EACT,6JAA6J;IAC/J,MAAM,EAAE;QACN,OAAO,EAAE;YACP,KAAK,EAAE,0BAA0B;YACjC,WAAW,EAAE,8BAA8B;YAC3C,IAAI,EAAE,SAAS;YACf,QAAQ,EAAE,IAAI;YACd,OAAO,EAAE,IAAI;SACd;QACD,SAAS,EAAE;YACT,KAAK,EAAE,WAAW;YAClB,WAAW,EAAE,sCAAsC;YACnD,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,IAAI;YACd,OAAO,EAAE,IAAI;SACd;QACD,SAAS,EAAE;YACT,KAAK,EAAE,WAAW;YAClB,WAAW,EAAE,2EAA2E;YACxF,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,IAAI;YACd,OAAO,EAAE,KAAK;SACf;QACD,aAAa,EAAE;YACb,KAAK,EAAE,eAAe;YACtB,WAAW,EACT,sGAAsG;YACxG,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,KAAK;YACf,SA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AAW,EAAE,OAAO,CAAC,SAAS;oBAC9B,IAAI,EAAG,OAAO,CAAC,aAAkC,IAAI,IAAI;iBAC1D,CAAC,CAAA;YACJ,CAAC,CAAC,CAAA;YAEF,MAAM,QAAQ,GAAG,EAAE,CAAA;YACnB,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE;gBACzB,MAAM,KAAK,GAAgC,OAAO,CAAC,GAAG,CAAC,CAAA;gBACvD,MAAM,OAAO,GAA4B;oBACvC,MAAM,EAAE,KAAK,CAAC,MAAM;oBACpB,QAAQ,EAAE,KAAK,CAAC,IAAI;iBACrB,CAAA;gBACD,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,yBAAQ,SAAS,KAAK,CAAC,QAAQ,UAAU,EAAE;oBACrE,MAAM,EAAE,MAAM;oBACd,IAAI,EAAE,OAAO;oBACb,eAAe,EAAE,KAAK;iBACvB,CAAC,CAAA;gBACF,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;aACxB;YACD,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE;gBACvB,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;aAC7B;SACF;QACD,OAAO,CAAC,CAAA;IACV,CAAC;CACF,CAAA;AAED,kBAAe,MAAM,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generated-types.js","sourceRoot":"","sources":["../../../../src/destinations/emarsys/upsertContact/generated-types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const emarsys_helper_1 = require("../emarsys-helper");
|
|
4
|
+
const actions_core_1 = require("@segment/actions-core");
|
|
5
|
+
const actions_core_2 = require("@segment/actions-core");
|
|
6
|
+
const action = {
|
|
7
|
+
title: 'Upsert Contact',
|
|
8
|
+
description: 'Insert or update a contact on the Emarsys platform',
|
|
9
|
+
fields: {
|
|
10
|
+
key_field: {
|
|
11
|
+
label: 'Key field',
|
|
12
|
+
description: 'The field to use to find the contact',
|
|
13
|
+
type: 'string',
|
|
14
|
+
required: true,
|
|
15
|
+
dynamic: true
|
|
16
|
+
},
|
|
17
|
+
key_value: {
|
|
18
|
+
label: 'Key value',
|
|
19
|
+
description: 'Value for the key field used to find the contact. E.g. the email address ',
|
|
20
|
+
type: 'string',
|
|
21
|
+
required: true,
|
|
22
|
+
dynamic: false
|
|
23
|
+
},
|
|
24
|
+
write_field: {
|
|
25
|
+
label: 'Fields to write',
|
|
26
|
+
description: 'Use the emarsys field id (number) as key and set a value (string) (static, function or event variable)',
|
|
27
|
+
type: 'object',
|
|
28
|
+
required: true,
|
|
29
|
+
properties: {
|
|
30
|
+
1: {
|
|
31
|
+
label: 'Given name',
|
|
32
|
+
type: 'string'
|
|
33
|
+
},
|
|
34
|
+
2: {
|
|
35
|
+
label: 'Last name',
|
|
36
|
+
type: 'string'
|
|
37
|
+
},
|
|
38
|
+
3: {
|
|
39
|
+
label: 'Email',
|
|
40
|
+
type: 'string'
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
default: {
|
|
44
|
+
1: { '@path': '$.traits.firstName' },
|
|
45
|
+
2: { '@path': '$.traits.lastName' },
|
|
46
|
+
3: { '@path': '$.traits.email' }
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
dynamicFields: {
|
|
51
|
+
key_field: async (request) => {
|
|
52
|
+
return emarsys_helper_1.getFields(request);
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
perform: async (request, data) => {
|
|
56
|
+
const contact = {};
|
|
57
|
+
if (!data?.payload?.key_field)
|
|
58
|
+
throw new actions_core_1.IntegrationError('Missing key field');
|
|
59
|
+
if (!data?.payload?.key_value)
|
|
60
|
+
throw new actions_core_1.IntegrationError('Missing key value');
|
|
61
|
+
contact[data.payload.key_field] = data.payload.key_value;
|
|
62
|
+
Object.assign(contact, data.payload.write_field);
|
|
63
|
+
const payload = {
|
|
64
|
+
key_id: data.payload.key_field,
|
|
65
|
+
contacts: [contact]
|
|
66
|
+
};
|
|
67
|
+
const response = await request(`${emarsys_helper_1.API_BASE}contact/?create_if_not_exists=1`, {
|
|
68
|
+
method: 'put',
|
|
69
|
+
json: payload,
|
|
70
|
+
throwHttpErrors: false
|
|
71
|
+
});
|
|
72
|
+
switch (response?.status) {
|
|
73
|
+
case 200:
|
|
74
|
+
try {
|
|
75
|
+
const body = await response.json();
|
|
76
|
+
if (body.replyCode === 0)
|
|
77
|
+
return response;
|
|
78
|
+
else
|
|
79
|
+
throw new actions_core_1.IntegrationError('Something went wrong while upserting the contact');
|
|
80
|
+
}
|
|
81
|
+
catch (err) {
|
|
82
|
+
throw new actions_core_1.IntegrationError('Invalid JSON response');
|
|
83
|
+
}
|
|
84
|
+
case 400:
|
|
85
|
+
throw new actions_core_1.IntegrationError('Contact could not be upserted');
|
|
86
|
+
case 429:
|
|
87
|
+
throw new actions_core_2.RetryableError('Rate limit reached.');
|
|
88
|
+
default:
|
|
89
|
+
throw new actions_core_2.RetryableError('There seems to be an API issue.');
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
performBatch: async (request, data) => {
|
|
93
|
+
if (data && data.payload && Array.isArray(data.payload)) {
|
|
94
|
+
const batches = {};
|
|
95
|
+
data.payload.forEach((payload) => {
|
|
96
|
+
if (!batches[`${payload.key_field}`]) {
|
|
97
|
+
batches[`${payload.key_field}`] = {
|
|
98
|
+
key_id: payload.key_field,
|
|
99
|
+
contacts: []
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
let contact = {};
|
|
103
|
+
contact[payload.key_field] = payload.key_value;
|
|
104
|
+
contact = Object.assign(contact, payload.write_field);
|
|
105
|
+
batches[`${payload.key_field}`].contacts.push(contact);
|
|
106
|
+
});
|
|
107
|
+
const requests = [];
|
|
108
|
+
for (const key in batches) {
|
|
109
|
+
const batch = batches[key];
|
|
110
|
+
const payload = {
|
|
111
|
+
key_id: batch.key_id,
|
|
112
|
+
contacts: batch.contacts
|
|
113
|
+
};
|
|
114
|
+
const response = request(`${emarsys_helper_1.API_BASE}contact/?create_if_not_exists=1`, {
|
|
115
|
+
method: 'put',
|
|
116
|
+
json: payload,
|
|
117
|
+
throwHttpErrors: false
|
|
118
|
+
});
|
|
119
|
+
requests.push(response);
|
|
120
|
+
}
|
|
121
|
+
if (requests.length > 0) {
|
|
122
|
+
return Promise.all(requests);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return 0;
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
exports.default = action;
|
|
129
|
+
//# sourceMappingURL=index.js.map
|