@segment/action-destinations 3.214.0 → 3.216.3-staging.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/actions-pardot/pa-operations.d.ts +2 -2
- package/dist/destinations/actions-pardot/pa-operations.js +2 -1
- package/dist/destinations/actions-pardot/pa-operations.js.map +1 -1
- package/dist/destinations/actions-pardot/prospects/index.js +2 -2
- package/dist/destinations/actions-pardot/prospects/index.js.map +1 -1
- package/dist/destinations/airship/utilities.js +1 -0
- package/dist/destinations/airship/utilities.js.map +1 -1
- package/dist/destinations/amplitude/identifyUser/generated-types.d.ts +4 -0
- package/dist/destinations/amplitude/identifyUser/index.js +5 -3
- package/dist/destinations/amplitude/identifyUser/index.js.map +1 -1
- package/dist/destinations/amplitude/logEvent/generated-types.d.ts +4 -0
- package/dist/destinations/amplitude/logEvent/index.js +5 -3
- package/dist/destinations/amplitude/logEvent/index.js.map +1 -1
- package/dist/destinations/amplitude/logEventV2/generated-types.d.ts +4 -0
- package/dist/destinations/amplitude/logEventV2/index.js +5 -3
- package/dist/destinations/amplitude/logEventV2/index.js.map +1 -1
- package/dist/destinations/amplitude/logPurchase/generated-types.d.ts +4 -0
- package/dist/destinations/amplitude/logPurchase/index.js +5 -3
- package/dist/destinations/amplitude/logPurchase/index.js.map +1 -1
- package/dist/destinations/amplitude/properties.d.ts +2 -0
- package/dist/destinations/amplitude/properties.js +23 -0
- package/dist/destinations/amplitude/properties.js.map +1 -0
- package/dist/destinations/amplitude/user-agent.d.ts +5 -1
- package/dist/destinations/amplitude/user-agent.js +3 -3
- package/dist/destinations/amplitude/user-agent.js.map +1 -1
- package/dist/destinations/emarsys/upsertContact/generated-types.d.ts +0 -3
- package/dist/destinations/emarsys/upsertContact/index.js +1 -14
- package/dist/destinations/emarsys/upsertContact/index.js.map +1 -1
- package/dist/destinations/engage/sendgrid/sendEmail/SendEmailPerformer.d.ts +1 -0
- package/dist/destinations/engage/sendgrid/sendEmail/SendEmailPerformer.js +8 -1
- package/dist/destinations/engage/sendgrid/sendEmail/SendEmailPerformer.js.map +1 -1
- package/dist/destinations/engage/twilio/utils/PhoneMessageSender.js +2 -0
- package/dist/destinations/engage/twilio/utils/PhoneMessageSender.js.map +1 -1
- package/dist/destinations/engage/utils/EngageStats.js +4 -0
- package/dist/destinations/engage/utils/EngageStats.js.map +1 -1
- package/dist/destinations/engage/utils/MessageSendPerformer.js +3 -0
- package/dist/destinations/engage/utils/MessageSendPerformer.js.map +1 -1
- package/dist/destinations/google-enhanced-conversions/postConversion/index.js +2 -1
- package/dist/destinations/google-enhanced-conversions/postConversion/index.js.map +1 -1
- package/dist/destinations/google-enhanced-conversions/uploadCallConversion/index.js +1 -0
- package/dist/destinations/google-enhanced-conversions/uploadCallConversion/index.js.map +1 -1
- package/dist/destinations/google-enhanced-conversions/uploadClickConversion/index.js +1 -0
- package/dist/destinations/google-enhanced-conversions/uploadClickConversion/index.js.map +1 -1
- package/dist/destinations/google-enhanced-conversions/uploadConversionAdjustment/index.js +4 -0
- package/dist/destinations/google-enhanced-conversions/uploadConversionAdjustment/index.js.map +1 -1
- package/dist/destinations/google-sheets/postSheet/index.js +4 -4
- package/dist/destinations/google-sheets/postSheet/index.js.map +1 -1
- package/dist/destinations/google-sheets/postSheet/operations.d.ts +2 -2
- package/dist/destinations/google-sheets/postSheet/operations.js +8 -5
- package/dist/destinations/google-sheets/postSheet/operations.js.map +1 -1
- package/dist/destinations/hubspot/api/index.d.ts +6 -5
- package/dist/destinations/hubspot/api/index.js +19 -6
- package/dist/destinations/hubspot/api/index.js.map +1 -1
- package/dist/destinations/hubspot/sendCustomBehavioralEvent/index.js +5 -1
- package/dist/destinations/hubspot/sendCustomBehavioralEvent/index.js.map +1 -1
- package/dist/destinations/hubspot/upsertCompany/index.js +6 -5
- package/dist/destinations/hubspot/upsertCompany/index.js.map +1 -1
- package/dist/destinations/hubspot/upsertContact/index.js +9 -7
- package/dist/destinations/hubspot/upsertContact/index.js.map +1 -1
- package/dist/destinations/index.js +1 -0
- package/dist/destinations/index.js.map +1 -1
- package/dist/destinations/intercom/groupIdentifyContact/index.js +9 -1
- package/dist/destinations/intercom/groupIdentifyContact/index.js.map +1 -1
- package/dist/destinations/intercom/identifyContact/index.js +9 -1
- package/dist/destinations/intercom/identifyContact/index.js.map +1 -1
- package/dist/destinations/intercom/trackEvent/index.js +3 -2
- package/dist/destinations/intercom/trackEvent/index.js.map +1 -1
- package/dist/destinations/intercom/util.d.ts +2 -2
- package/dist/destinations/intercom/util.js +2 -1
- package/dist/destinations/intercom/util.js.map +1 -1
- package/dist/destinations/klaviyo/config.d.ts +1 -0
- package/dist/destinations/klaviyo/config.js +5 -0
- package/dist/destinations/klaviyo/config.js.map +1 -0
- package/dist/destinations/klaviyo/index.js +10 -4
- package/dist/destinations/klaviyo/index.js.map +1 -1
- package/dist/destinations/klaviyo/types.d.ts +33 -0
- package/dist/destinations/klaviyo/types.js +8 -0
- package/dist/destinations/klaviyo/types.js.map +1 -0
- package/dist/destinations/klaviyo/upsertProfile/generated-types.d.ts +23 -0
- package/dist/destinations/klaviyo/upsertProfile/generated-types.js +3 -0
- package/dist/destinations/klaviyo/upsertProfile/generated-types.js.map +1 -0
- package/dist/destinations/klaviyo/upsertProfile/index.d.ts +5 -0
- package/dist/destinations/klaviyo/upsertProfile/index.js +162 -0
- package/dist/destinations/klaviyo/upsertProfile/index.js.map +1 -0
- package/dist/destinations/linkedin-audiences/updateAudience/index.js +15 -9
- package/dist/destinations/linkedin-audiences/updateAudience/index.js.map +1 -1
- package/dist/destinations/liveramp-audiences/audienceEnteredSftp/sftp.d.ts +4 -1
- package/dist/destinations/liveramp-audiences/audienceEnteredSftp/sftp.js +17 -2
- package/dist/destinations/liveramp-audiences/audienceEnteredSftp/sftp.js.map +1 -1
- package/dist/destinations/mixpanel/mixpanel-properties.js +49 -0
- package/dist/destinations/mixpanel/mixpanel-properties.js.map +1 -1
- package/dist/destinations/mixpanel/mixpanel-types.d.ts +7 -0
- package/dist/destinations/mixpanel/trackEvent/functions.js +6 -0
- package/dist/destinations/mixpanel/trackEvent/functions.js.map +1 -1
- package/dist/destinations/mixpanel/trackEvent/generated-types.d.ts +10 -0
- package/dist/destinations/mixpanel/trackPurchase/generated-types.d.ts +10 -0
- package/dist/destinations/salesforce/account/index.js +7 -7
- package/dist/destinations/salesforce/account/index.js.map +1 -1
- package/dist/destinations/salesforce/cases/index.js +7 -7
- package/dist/destinations/salesforce/cases/index.js.map +1 -1
- package/dist/destinations/salesforce/contact/index.js +7 -7
- package/dist/destinations/salesforce/contact/index.js.map +1 -1
- package/dist/destinations/salesforce/customObject/index.js +7 -7
- package/dist/destinations/salesforce/customObject/index.js.map +1 -1
- package/dist/destinations/salesforce/lead/index.js +7 -7
- package/dist/destinations/salesforce/lead/index.js.map +1 -1
- package/dist/destinations/salesforce/opportunity/index.js +7 -7
- package/dist/destinations/salesforce/opportunity/index.js.map +1 -1
- package/dist/destinations/salesforce/sf-operations.d.ts +6 -6
- package/dist/destinations/salesforce/sf-operations.js +45 -27
- package/dist/destinations/salesforce/sf-operations.js.map +1 -1
- package/dist/destinations/salesforce-marketing-cloud/apiEvent/index.js +2 -1
- package/dist/destinations/salesforce-marketing-cloud/apiEvent/index.js.map +1 -1
- package/dist/destinations/salesforce-marketing-cloud/contact/index.js +2 -1
- package/dist/destinations/salesforce-marketing-cloud/contact/index.js.map +1 -1
- package/dist/destinations/salesforce-marketing-cloud/contactDataExtension/index.js +4 -4
- package/dist/destinations/salesforce-marketing-cloud/contactDataExtension/index.js.map +1 -1
- package/dist/destinations/salesforce-marketing-cloud/dataExtension/index.js +4 -4
- package/dist/destinations/salesforce-marketing-cloud/dataExtension/index.js.map +1 -1
- package/dist/destinations/salesforce-marketing-cloud/sfmc-operations.d.ts +2 -2
- package/dist/destinations/salesforce-marketing-cloud/sfmc-operations.js +2 -1
- package/dist/destinations/salesforce-marketing-cloud/sfmc-operations.js.map +1 -1
- package/dist/destinations/segment/sendTrack/generated-types.d.ts +3 -0
- package/dist/destinations/segment/sendTrack/index.js +5 -1
- package/dist/destinations/segment/sendTrack/index.js.map +1 -1
- package/dist/destinations/segment-profiles/errors.d.ts +10 -10
- package/dist/destinations/segment-profiles/errors.js +11 -11
- package/dist/destinations/segment-profiles/errors.js.map +1 -1
- package/dist/destinations/segment-profiles/segment-properties.d.ts +0 -10
- package/dist/destinations/segment-profiles/segment-properties.js +1 -58
- package/dist/destinations/segment-profiles/segment-properties.js.map +1 -1
- package/dist/destinations/segment-profiles/sendSubscription/index.js +162 -137
- package/dist/destinations/segment-profiles/sendSubscription/index.js.map +1 -1
- package/dist/destinations/segment-profiles/sendSubscription/subscription-properties.d.ts +15 -0
- package/dist/destinations/segment-profiles/sendSubscription/subscription-properties.js +85 -0
- package/dist/destinations/segment-profiles/sendSubscription/subscription-properties.js.map +1 -0
- package/dist/destinations/the-trade-desk-crm/awsClient.d.ts +1 -0
- package/dist/destinations/the-trade-desk-crm/awsClient.js +1 -0
- package/dist/destinations/the-trade-desk-crm/awsClient.js.map +1 -1
- package/dist/destinations/the-trade-desk-crm/functions.d.ts +1 -0
- package/dist/destinations/the-trade-desk-crm/functions.js +57 -9
- package/dist/destinations/the-trade-desk-crm/functions.js.map +1 -1
- package/dist/destinations/the-trade-desk-crm/index.d.ts +2 -13
- package/dist/destinations/the-trade-desk-crm/index.js +21 -14
- package/dist/destinations/the-trade-desk-crm/index.js.map +1 -1
- package/dist/destinations/the-trade-desk-crm/properties.d.ts +2 -0
- package/dist/destinations/the-trade-desk-crm/properties.js +22 -5
- package/dist/destinations/the-trade-desk-crm/properties.js.map +1 -1
- package/dist/destinations/the-trade-desk-crm/syncAudience/generated-types.d.ts +3 -2
- package/dist/destinations/the-trade-desk-crm/syncAudience/index.js +2 -1
- package/dist/destinations/the-trade-desk-crm/syncAudience/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.upsertRows = void 0;
|
|
4
4
|
const actions_core_1 = require("@segment/actions-core");
|
|
5
|
-
function upsertRows(request, subdomain, payloads) {
|
|
5
|
+
function upsertRows(request, subdomain, payloads, statsContext) {
|
|
6
6
|
const { key, id } = payloads[0];
|
|
7
7
|
if (!key && !id) {
|
|
8
8
|
throw new actions_core_1.IntegrationError(`In order to send an event to a data extension either Data Extension ID or Data Extension Key must be defined.`, 'Misconfigured required field', 400);
|
|
@@ -14,6 +14,7 @@ function upsertRows(request, subdomain, payloads) {
|
|
|
14
14
|
values: payload.values
|
|
15
15
|
});
|
|
16
16
|
});
|
|
17
|
+
statsContext?.statsClient?.incr('oauth_app_api_call', 1, [...statsContext?.tags, `endpoint:data-extension`]);
|
|
17
18
|
if (key) {
|
|
18
19
|
return request(`https://${subdomain}.rest.marketingcloudapis.com/hub/v1/dataevents/key:${key}/rowset`, {
|
|
19
20
|
method: 'POST',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sfmc-operations.js","sourceRoot":"","sources":["../../../src/destinations/salesforce-marketing-cloud/sfmc-operations.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"sfmc-operations.js","sourceRoot":"","sources":["../../../src/destinations/salesforce-marketing-cloud/sfmc-operations.ts"],"names":[],"mappings":";;;AAAA,wDAAqF;AAIrF,SAAgB,UAAU,CACxB,OAAsB,EACtB,SAAiB,EACjB,QAAkE,EAClE,YAA2B;IAE3B,MAAM,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAA;IAC/B,IAAI,CAAC,GAAG,IAAI,CAAC,EAAE,EAAE;QACf,MAAM,IAAI,+BAAgB,CACxB,+GAA+G,EAC/G,8BAA8B,EAC9B,GAAG,CACJ,CAAA;KACF;IACD,MAAM,IAAI,GAA0B,EAAE,CAAA;IACtC,QAAQ,CAAC,OAAO,CAAC,CAAC,OAA6D,EAAE,EAAE;QACjF,IAAI,CAAC,IAAI,CAAC;YACR,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,MAAM,EAAE,OAAO,CAAC,MAAM;SACvB,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IACF,YAAY,EAAE,WAAW,EAAE,IAAI,CAAC,oBAAoB,EAAE,CAAC,EAAE,CAAC,GAAG,YAAY,EAAE,IAAI,EAAE,yBAAyB,CAAC,CAAC,CAAA;IAC5G,IAAI,GAAG,EAAE;QACP,OAAO,OAAO,CAAC,WAAW,SAAS,sDAAsD,GAAG,SAAS,EAAE;YACrG,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,IAAI;SACX,CAAC,CAAA;KACH;SAAM;QACL,OAAO,OAAO,CAAC,WAAW,SAAS,kDAAkD,EAAE,SAAS,EAAE;YAChG,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,IAAI;SACX,CAAC,CAAA;KACH;AACH,CAAC;AAjCD,gCAiCC"}
|
|
@@ -25,7 +25,8 @@ const action = {
|
|
|
25
25
|
user_agent: segment_properties_1.user_agent,
|
|
26
26
|
timezone: segment_properties_1.timezone,
|
|
27
27
|
group_id: segment_properties_1.group_id,
|
|
28
|
-
properties: segment_properties_1.properties
|
|
28
|
+
properties: segment_properties_1.properties,
|
|
29
|
+
traits: segment_properties_1.traits
|
|
29
30
|
},
|
|
30
31
|
perform: (request, { payload, settings, features, statsContext }) => {
|
|
31
32
|
if (!payload.anonymous_id && !payload.user_id) {
|
|
@@ -37,6 +38,9 @@ const action = {
|
|
|
37
38
|
timestamp: payload?.timestamp,
|
|
38
39
|
event: payload?.event_name,
|
|
39
40
|
context: {
|
|
41
|
+
traits: {
|
|
42
|
+
...payload?.traits
|
|
43
|
+
},
|
|
40
44
|
app: payload?.application,
|
|
41
45
|
campaign: payload?.campaign_parameters,
|
|
42
46
|
device: payload?.device,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/segment/sendTrack/index.ts"],"names":[],"mappings":";;AAGA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/segment/sendTrack/index.ts"],"names":[],"mappings":"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"}
|
|
@@ -12,13 +12,13 @@ export declare class SegmentPublicAPIError extends HTTPError {
|
|
|
12
12
|
}
|
|
13
13
|
export declare const MissingUserOrAnonymousIdThrowableError: PayloadValidationError;
|
|
14
14
|
export declare const InvalidEndpointSelectedThrowableError: PayloadValidationError;
|
|
15
|
-
export declare const
|
|
16
|
-
export declare const
|
|
17
|
-
export declare const
|
|
18
|
-
export declare const
|
|
19
|
-
export declare const
|
|
20
|
-
export declare const
|
|
21
|
-
export declare const
|
|
22
|
-
export declare const
|
|
23
|
-
export declare const
|
|
24
|
-
export declare const
|
|
15
|
+
export declare const MissingExternalIdsError: PayloadValidationError;
|
|
16
|
+
export declare const MissingEmailIfEmailSubscriptionIsPresentError: PayloadValidationError;
|
|
17
|
+
export declare const MissingPhoneIfSmsOrWhatsappSubscriptionIsPresentError: PayloadValidationError;
|
|
18
|
+
export declare const MissingSubscriptionStatusesError: PayloadValidationError;
|
|
19
|
+
export declare const MissingEmailSubscriptionIfSubscriptionGroupsIsPresentError: PayloadValidationError;
|
|
20
|
+
export declare const InvalidSubscriptionStatusError: PayloadValidationError;
|
|
21
|
+
export declare const InvalidGroupSubscriptionStatusError: PayloadValidationError;
|
|
22
|
+
export declare const MissingAndroidPushTokenIfAndroidPushSubscriptionIsPresentError: PayloadValidationError;
|
|
23
|
+
export declare const MissingIosPushTokenIfIosPushSubscriptionIsPresentError: PayloadValidationError;
|
|
24
|
+
export declare const InvalidSubsriptionStatusError: PayloadValidationError;
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.InvalidSubsriptionStatusError = exports.MissingIosPushTokenIfIosPushSubscriptionIsPresentError = exports.MissingAndroidPushTokenIfAndroidPushSubscriptionIsPresentError = exports.InvalidGroupSubscriptionStatusError = exports.InvalidSubscriptionStatusError = exports.MissingEmailSubscriptionIfSubscriptionGroupsIsPresentError = exports.MissingSubscriptionStatusesError = exports.MissingPhoneIfSmsOrWhatsappSubscriptionIsPresentError = exports.MissingEmailIfEmailSubscriptionIsPresentError = exports.MissingExternalIdsError = exports.InvalidEndpointSelectedThrowableError = exports.MissingUserOrAnonymousIdThrowableError = exports.SegmentPublicAPIError = void 0;
|
|
4
4
|
const actions_core_1 = require("@segment/actions-core");
|
|
5
5
|
class SegmentPublicAPIError extends actions_core_1.HTTPError {
|
|
6
6
|
}
|
|
7
7
|
exports.SegmentPublicAPIError = SegmentPublicAPIError;
|
|
8
8
|
exports.MissingUserOrAnonymousIdThrowableError = new actions_core_1.PayloadValidationError('Either `Anonymous ID` or `User ID` must be defined.');
|
|
9
9
|
exports.InvalidEndpointSelectedThrowableError = new actions_core_1.PayloadValidationError('A valid endpoint must be selected. Please check your Segment settings.');
|
|
10
|
-
exports.
|
|
11
|
-
exports.
|
|
12
|
-
exports.
|
|
13
|
-
exports.
|
|
14
|
-
exports.
|
|
15
|
-
exports.
|
|
16
|
-
exports.
|
|
17
|
-
exports.
|
|
18
|
-
exports.
|
|
19
|
-
exports.
|
|
10
|
+
exports.MissingExternalIdsError = new actions_core_1.PayloadValidationError('Either `Email` or `Phone` or `Android_Push_Token` or `Ios_Push_Token` must be defined.');
|
|
11
|
+
exports.MissingEmailIfEmailSubscriptionIsPresentError = new actions_core_1.PayloadValidationError('A valid `Email` must be defined for `Email_Subscription`.');
|
|
12
|
+
exports.MissingPhoneIfSmsOrWhatsappSubscriptionIsPresentError = new actions_core_1.PayloadValidationError('A valid `Phone` must be defined for `Sms_Subscription` or `Whatsapp_Subscription`.');
|
|
13
|
+
exports.MissingSubscriptionStatusesError = new actions_core_1.PayloadValidationError('If any of `Email`, `Phone`, `Android_Push_Token` or `Ios_Push_Token` is present, `Email_Subscription` or `Sms_Subscription` or `Whatsapp_Subscription` or `Ios_Push_Subscription` or `Android_Push_Subscription` must be defined.');
|
|
14
|
+
exports.MissingEmailSubscriptionIfSubscriptionGroupsIsPresentError = new actions_core_1.PayloadValidationError('`Email_Subscription` must be defined if Subscription Groups are present.');
|
|
15
|
+
exports.InvalidSubscriptionStatusError = new actions_core_1.PayloadValidationError('Invalid Subscription Status in `Email_Subscription` or `Sms_Subscription` or `Whatsapp_Subscription` or `Android_Push_Subscription` or `Ios_Push_Subscription`.');
|
|
16
|
+
exports.InvalidGroupSubscriptionStatusError = new actions_core_1.PayloadValidationError('Invalid Subscription Status for subscription groups.');
|
|
17
|
+
exports.MissingAndroidPushTokenIfAndroidPushSubscriptionIsPresentError = new actions_core_1.PayloadValidationError('A valid `Android_Push_Token` must be defined for `Android_Push_Subscription`.');
|
|
18
|
+
exports.MissingIosPushTokenIfIosPushSubscriptionIsPresentError = new actions_core_1.PayloadValidationError('A valid `Ios_Push_Token` must be defined for `Ios_Push_Subscription`.');
|
|
19
|
+
exports.InvalidSubsriptionStatusError = new actions_core_1.PayloadValidationError('Invalid Subscription Status.');
|
|
20
20
|
//# sourceMappingURL=errors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/destinations/segment-profiles/errors.ts"],"names":[],"mappings":";;;AAAA,wDAAyE;AAEzE,MAAa,qBAAsB,SAAQ,wBAAS;CAUnD;AAVD,sDAUC;AAEY,QAAA,sCAAsC,GAAG,IAAI,qCAAsB,CAC9E,qDAAqD,CACtD,CAAA;AAEY,QAAA,qCAAqC,GAAG,IAAI,qCAAsB,CAC7E,wEAAwE,CACzE,CAAA;AAEY,QAAA,
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/destinations/segment-profiles/errors.ts"],"names":[],"mappings":";;;AAAA,wDAAyE;AAEzE,MAAa,qBAAsB,SAAQ,wBAAS;CAUnD;AAVD,sDAUC;AAEY,QAAA,sCAAsC,GAAG,IAAI,qCAAsB,CAC9E,qDAAqD,CACtD,CAAA;AAEY,QAAA,qCAAqC,GAAG,IAAI,qCAAsB,CAC7E,wEAAwE,CACzE,CAAA;AAEY,QAAA,uBAAuB,GAAG,IAAI,qCAAsB,CAC/D,wFAAwF,CACzF,CAAA;AAEY,QAAA,6CAA6C,GAAG,IAAI,qCAAsB,CACrF,2DAA2D,CAC5D,CAAA;AAEY,QAAA,qDAAqD,GAAG,IAAI,qCAAsB,CAC7F,oFAAoF,CACrF,CAAA;AAEY,QAAA,gCAAgC,GAAG,IAAI,qCAAsB,CACxE,mOAAmO,CACpO,CAAA;AAEY,QAAA,0DAA0D,GAAG,IAAI,qCAAsB,CAClG,0EAA0E,CAC3E,CAAA;AAEY,QAAA,8BAA8B,GAAG,IAAI,qCAAsB,CACtE,iKAAiK,CAClK,CAAA;AAEY,QAAA,mCAAmC,GAAG,IAAI,qCAAsB,CAC3E,sDAAsD,CACvD,CAAA;AAEY,QAAA,8DAA8D,GAAG,IAAI,qCAAsB,CACtG,+EAA+E,CAChF,CAAA;AAEY,QAAA,sDAAsD,GAAG,IAAI,qCAAsB,CAC9F,uEAAuE,CACxE,CAAA;AAEY,QAAA,6BAA6B,GAAG,IAAI,qCAAsB,CAAC,8BAA8B,CAAC,CAAA"}
|
|
@@ -4,13 +4,3 @@ export declare const anonymous_id: InputField;
|
|
|
4
4
|
export declare const group_id: InputField;
|
|
5
5
|
export declare const traits: InputField;
|
|
6
6
|
export declare const engage_space: InputField;
|
|
7
|
-
export declare const email: InputField;
|
|
8
|
-
export declare const phone: InputField;
|
|
9
|
-
export declare const android_push_token: InputField;
|
|
10
|
-
export declare const ios_push_token: InputField;
|
|
11
|
-
export declare const email_subscription_status: InputField;
|
|
12
|
-
export declare const sms_subscription_status: InputField;
|
|
13
|
-
export declare const whatsapp_subscription_status: InputField;
|
|
14
|
-
export declare const android_push_subscription_status: InputField;
|
|
15
|
-
export declare const ios_push_subscription_status: InputField;
|
|
16
|
-
export declare const subscription_groups: InputField;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.engage_space = exports.traits = exports.group_id = exports.anonymous_id = exports.user_id = void 0;
|
|
4
4
|
exports.user_id = {
|
|
5
5
|
label: 'User ID',
|
|
6
6
|
description: 'Unique identifier for the user in your database. A userId or an anonymousId is required.',
|
|
@@ -30,61 +30,4 @@ exports.engage_space = {
|
|
|
30
30
|
required: true,
|
|
31
31
|
dynamic: true
|
|
32
32
|
};
|
|
33
|
-
exports.email = {
|
|
34
|
-
label: 'Email',
|
|
35
|
-
description: 'Email of the user',
|
|
36
|
-
type: 'string'
|
|
37
|
-
};
|
|
38
|
-
exports.phone = {
|
|
39
|
-
label: 'Phone',
|
|
40
|
-
description: 'Phone number of the user',
|
|
41
|
-
type: 'string'
|
|
42
|
-
};
|
|
43
|
-
exports.android_push_token = {
|
|
44
|
-
label: 'Android Push Token',
|
|
45
|
-
description: 'Android Push Token of the user',
|
|
46
|
-
type: 'string'
|
|
47
|
-
};
|
|
48
|
-
exports.ios_push_token = {
|
|
49
|
-
label: 'Ios Push Token',
|
|
50
|
-
description: 'Ios Push Token of the user',
|
|
51
|
-
type: 'string'
|
|
52
|
-
};
|
|
53
|
-
exports.email_subscription_status = {
|
|
54
|
-
label: 'Email Subscription Status',
|
|
55
|
-
description: 'Global status of the email subscription. True is subscribed, false is unsubscribed and null|undefined is did-not-subscribe.',
|
|
56
|
-
type: 'string',
|
|
57
|
-
allowNull: true
|
|
58
|
-
};
|
|
59
|
-
exports.sms_subscription_status = {
|
|
60
|
-
label: 'SMS Subscription Status',
|
|
61
|
-
description: 'Global status of the SMS subscription. True is subscribed, false is unsubscribed and null|undefined is did-not-subscribe.',
|
|
62
|
-
type: 'string',
|
|
63
|
-
allowNull: true
|
|
64
|
-
};
|
|
65
|
-
exports.whatsapp_subscription_status = {
|
|
66
|
-
label: 'WhatsApp Subscription Status',
|
|
67
|
-
description: 'Global status of the WhatsApp subscription. True is subscribed, false is unsubscribed and null is did-not-subscribe.',
|
|
68
|
-
type: 'string',
|
|
69
|
-
allowNull: true
|
|
70
|
-
};
|
|
71
|
-
exports.android_push_subscription_status = {
|
|
72
|
-
label: 'Android Push Subscription Status',
|
|
73
|
-
description: 'Global status of the android push subscription. True is subscribed, false is unsubscribed and null is did-not-subscribe.',
|
|
74
|
-
type: 'string',
|
|
75
|
-
allowNull: true
|
|
76
|
-
};
|
|
77
|
-
exports.ios_push_subscription_status = {
|
|
78
|
-
label: 'Ios Push Subscription Status',
|
|
79
|
-
description: 'Global status of the ios push subscription. True is subscribed, false is unsubscribed and null is did-not-subscribe.',
|
|
80
|
-
type: 'string',
|
|
81
|
-
allowNull: true
|
|
82
|
-
};
|
|
83
|
-
exports.subscription_groups = {
|
|
84
|
-
label: 'Subscription Groups',
|
|
85
|
-
description: 'Subscription status for the groups. Object containing group names as keys and statuses as values',
|
|
86
|
-
type: 'object',
|
|
87
|
-
additionalProperties: true,
|
|
88
|
-
defaultObjectUI: 'keyvalue'
|
|
89
|
-
};
|
|
90
33
|
//# sourceMappingURL=segment-properties.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"segment-properties.js","sourceRoot":"","sources":["../../../src/destinations/segment-profiles/segment-properties.ts"],"names":[],"mappings":";;;AAEa,QAAA,OAAO,GAAe;IACjC,KAAK,EAAE,SAAS;IAChB,WAAW,EAAE,0FAA0F;IACvG,IAAI,EAAE,QAAQ;CACf,CAAA;AAEY,QAAA,YAAY,GAAe;IACtC,KAAK,EAAE,cAAc;IACrB,WAAW,EACT,kJAAkJ;IACpJ,IAAI,EAAE,QAAQ;CACf,CAAA;AAEY,QAAA,QAAQ,GAAe;IAClC,KAAK,EAAE,UAAU;IACjB,WAAW,EAAE,oDAAoD;IACjE,IAAI,EAAE,QAAQ;CACf,CAAA;AAEY,QAAA,MAAM,GAAe;IAChC,KAAK,EAAE,QAAQ;IACf,WAAW,EAAE,0EAA0E;IACvF,IAAI,EAAE,QAAQ;IACd,eAAe,EAAE,UAAU;IAC3B,oBAAoB,EAAE,IAAI;CAC3B,CAAA;AAEY,QAAA,YAAY,GAAe;IACtC,KAAK,EAAE,eAAe;IACtB,WAAW,EACT,sSAAsS;IACxS,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,IAAI;IACd,OAAO,EAAE,IAAI;CACd,CAAA
|
|
1
|
+
{"version":3,"file":"segment-properties.js","sourceRoot":"","sources":["../../../src/destinations/segment-profiles/segment-properties.ts"],"names":[],"mappings":";;;AAEa,QAAA,OAAO,GAAe;IACjC,KAAK,EAAE,SAAS;IAChB,WAAW,EAAE,0FAA0F;IACvG,IAAI,EAAE,QAAQ;CACf,CAAA;AAEY,QAAA,YAAY,GAAe;IACtC,KAAK,EAAE,cAAc;IACrB,WAAW,EACT,kJAAkJ;IACpJ,IAAI,EAAE,QAAQ;CACf,CAAA;AAEY,QAAA,QAAQ,GAAe;IAClC,KAAK,EAAE,UAAU;IACjB,WAAW,EAAE,oDAAoD;IACjE,IAAI,EAAE,QAAQ;CACf,CAAA;AAEY,QAAA,MAAM,GAAe;IAChC,KAAK,EAAE,QAAQ;IACf,WAAW,EAAE,0EAA0E;IACvF,IAAI,EAAE,QAAQ;IACd,eAAe,EAAE,UAAU;IAC3B,oBAAoB,EAAE,IAAI;CAC3B,CAAA;AAEY,QAAA,YAAY,GAAe;IACtC,KAAK,EAAE,eAAe;IACtB,WAAW,EACT,sSAAsS;IACxS,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,IAAI;IACd,OAAO,EAAE,IAAI;CACd,CAAA"}
|
|
@@ -1,167 +1,194 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
3
|
+
const subscription_properties_1 = require("./subscription-properties");
|
|
4
4
|
const errors_1 = require("../errors");
|
|
5
5
|
const helperFunctions_1 = require("../helperFunctions");
|
|
6
6
|
const properties_1 = require("../properties");
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
const subscriptionStatusConfig = [
|
|
8
|
+
{ status: 'SUBSCRIBED', matchingStatuses: ['true', 'subscribed'] },
|
|
9
|
+
{ status: 'UNSUBSCRIBED', matchingStatuses: ['false', 'unsubscribed'] },
|
|
10
|
+
{ status: 'DID-NOT-SUBSCRIBE', matchingStatuses: ['did-not-subscribe', 'did_not_subscribe'] }
|
|
11
|
+
];
|
|
12
|
+
const supportedChannels = [
|
|
13
|
+
{
|
|
14
|
+
field: 'email',
|
|
15
|
+
externalId: 'email',
|
|
16
|
+
subscriptionFields: ['email_subscription_status'],
|
|
17
|
+
channels: ['EMAIL'],
|
|
18
|
+
groups: true
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
field: 'phone',
|
|
22
|
+
externalId: 'phone',
|
|
23
|
+
subscriptionFields: ['sms_subscription_status', 'whatsapp_subscription_status'],
|
|
24
|
+
channels: ['SMS', 'WHATSAPP'],
|
|
25
|
+
groups: false
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
field: 'android_push_token',
|
|
29
|
+
externalId: 'android.push_token',
|
|
30
|
+
subscriptionFields: ['android_push_subscription_status'],
|
|
31
|
+
channels: ['ANDROID_PUSH'],
|
|
32
|
+
groups: false
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
field: 'ios_push_token',
|
|
36
|
+
externalId: 'ios.push_token',
|
|
37
|
+
subscriptionFields: ['ios_push_subscription_status'],
|
|
38
|
+
channels: ['IOS_PUSH'],
|
|
39
|
+
groups: false
|
|
10
40
|
}
|
|
11
|
-
|
|
12
|
-
|
|
41
|
+
];
|
|
42
|
+
const INVALID_SUBSCRIPTION_STATUS = 'INVALID';
|
|
43
|
+
const getStatus = (subscriptionStatus) => {
|
|
44
|
+
const tempSubscriptionStatus = subscriptionStatus?.trim().toLowerCase();
|
|
45
|
+
if (!tempSubscriptionStatus) {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
const status = subscriptionStatusConfig.find(({ matchingStatuses }) => matchingStatuses.indexOf(tempSubscriptionStatus) > -1);
|
|
49
|
+
if (status) {
|
|
50
|
+
return status.status;
|
|
51
|
+
}
|
|
52
|
+
return INVALID_SUBSCRIPTION_STATUS;
|
|
53
|
+
};
|
|
54
|
+
const enrichExternalIds = (payload, externalIds) => {
|
|
55
|
+
for (const channel of supportedChannels) {
|
|
56
|
+
const field = payload[channel.field];
|
|
57
|
+
if (field != undefined) {
|
|
58
|
+
externalIds.push({
|
|
59
|
+
id: field,
|
|
60
|
+
type: channel.externalId,
|
|
61
|
+
collection: 'users',
|
|
62
|
+
encoding: 'none'
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return externalIds;
|
|
67
|
+
};
|
|
68
|
+
const enrichMessagingSubscriptions = (payload, messagingSubscriptions) => {
|
|
69
|
+
for (const channel of supportedChannels) {
|
|
70
|
+
const field = payload[channel.field];
|
|
71
|
+
for (const [index, subscriptionField] of channel.subscriptionFields.entries()) {
|
|
72
|
+
const subscriptionValue = payload[subscriptionField];
|
|
73
|
+
const subscription = formatToMessagingSubscription(field, channel.channels[index], subscriptionValue);
|
|
74
|
+
if (subscription && channel.groups) {
|
|
75
|
+
if (payload.subscription_groups &&
|
|
76
|
+
typeof payload.subscription_groups === 'object' &&
|
|
77
|
+
Object.keys(payload.subscription_groups).length > 0) {
|
|
78
|
+
const formattedGroups = Object.entries(payload.subscription_groups)
|
|
79
|
+
.filter(([name, status]) => name !== undefined && status !== undefined)
|
|
80
|
+
.map(([name, status]) => ({
|
|
81
|
+
name: String(name),
|
|
82
|
+
status: getStatus(String(status))
|
|
83
|
+
}));
|
|
84
|
+
subscription.groups = formattedGroups;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (subscription)
|
|
88
|
+
messagingSubscriptions.push(subscription);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return messagingSubscriptions;
|
|
92
|
+
};
|
|
93
|
+
const validateSubscriptions = (payload, statsClient, tags) => {
|
|
94
|
+
if (!(payload.email || payload.phone || payload.android_push_token || payload.ios_push_token)) {
|
|
95
|
+
tags?.push(`type:missing_external_ids`);
|
|
96
|
+
statsClient?.incr('validation_error', 1, tags);
|
|
97
|
+
throw errors_1.MissingExternalIdsError;
|
|
13
98
|
}
|
|
14
99
|
if (!(payload.email_subscription_status ||
|
|
15
100
|
payload.whatsapp_subscription_status ||
|
|
16
101
|
payload.sms_subscription_status ||
|
|
17
102
|
payload.android_push_subscription_status ||
|
|
18
103
|
payload.ios_push_subscription_status)) {
|
|
19
|
-
|
|
104
|
+
tags?.push(`type:missing_subscription_status`);
|
|
105
|
+
statsClient?.incr('validation_error', 1, tags);
|
|
106
|
+
throw errors_1.MissingSubscriptionStatusesError;
|
|
20
107
|
}
|
|
21
108
|
if (!payload.email && payload.email_subscription_status) {
|
|
22
|
-
|
|
109
|
+
tags?.push(`type:missing_email_but_subscription_exists`);
|
|
110
|
+
statsClient?.incr('validation_error', 1, tags);
|
|
111
|
+
throw errors_1.MissingEmailIfEmailSubscriptionIsPresentError;
|
|
23
112
|
}
|
|
24
|
-
if (payload.subscription_groups &&
|
|
25
|
-
|
|
113
|
+
if (payload.subscription_groups &&
|
|
114
|
+
!payload.email_subscription_status &&
|
|
115
|
+
Object.keys(payload.subscription_groups).length > 0) {
|
|
116
|
+
tags?.push(`type:missing_email_but_subscription_groups_exists`);
|
|
117
|
+
statsClient?.incr('validation_error', 1, tags);
|
|
118
|
+
throw errors_1.MissingEmailSubscriptionIfSubscriptionGroupsIsPresentError;
|
|
26
119
|
}
|
|
27
120
|
if (!payload.phone && (payload.sms_subscription_status || payload.whatsapp_subscription_status)) {
|
|
28
|
-
|
|
121
|
+
tags?.push(`type:missing_phone_but_subscription_exists`);
|
|
122
|
+
statsClient?.incr('validation_error', 1, tags);
|
|
123
|
+
throw errors_1.MissingPhoneIfSmsOrWhatsappSubscriptionIsPresentError;
|
|
29
124
|
}
|
|
30
125
|
if (!payload.android_push_token && payload.android_push_subscription_status) {
|
|
31
|
-
|
|
126
|
+
tags?.push(`type:missing_android_push_but_subscription_exists`);
|
|
127
|
+
statsClient?.incr('validation_error', 1, tags);
|
|
128
|
+
throw errors_1.MissingAndroidPushTokenIfAndroidPushSubscriptionIsPresentError;
|
|
32
129
|
}
|
|
33
130
|
if (!payload.ios_push_token && payload.ios_push_subscription_status) {
|
|
34
|
-
|
|
131
|
+
tags?.push(`type:missing_ios_push_but_subscription_exists`);
|
|
132
|
+
statsClient?.incr('validation_error', 1, tags);
|
|
133
|
+
throw errors_1.MissingIosPushTokenIfIosPushSubscriptionIsPresentError;
|
|
35
134
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
(payload.sms_subscription_status &&
|
|
40
|
-
|
|
41
|
-
(payload.whatsapp_subscription_status &&
|
|
42
|
-
|
|
43
|
-
(payload.ios_push_subscription_status &&
|
|
44
|
-
|
|
45
|
-
(payload.android_push_subscription_status
|
|
46
|
-
|
|
47
|
-
|
|
135
|
+
if (payload.email_subscription_status &&
|
|
136
|
+
getStatus(payload.email_subscription_status) == INVALID_SUBSCRIPTION_STATUS &&
|
|
137
|
+
payload.sms_subscription_status &&
|
|
138
|
+
getStatus(payload.sms_subscription_status) == INVALID_SUBSCRIPTION_STATUS &&
|
|
139
|
+
payload.whatsapp_subscription_status &&
|
|
140
|
+
getStatus(payload.whatsapp_subscription_status) == INVALID_SUBSCRIPTION_STATUS &&
|
|
141
|
+
payload.ios_push_subscription_status &&
|
|
142
|
+
getStatus(payload.ios_push_subscription_status) == INVALID_SUBSCRIPTION_STATUS &&
|
|
143
|
+
payload.android_push_subscription_status &&
|
|
144
|
+
getStatus(payload.android_push_subscription_status) == INVALID_SUBSCRIPTION_STATUS) {
|
|
145
|
+
tags?.push(`type:invalid_subscription_value`);
|
|
146
|
+
statsClient?.incr('validation_error', 1, tags);
|
|
147
|
+
throw errors_1.InvalidSubscriptionStatusError;
|
|
48
148
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
149
|
+
};
|
|
150
|
+
const formatToMessagingSubscription = (key, type, status) => {
|
|
151
|
+
const tempStatus = getStatus(status);
|
|
152
|
+
if (tempStatus) {
|
|
153
|
+
return {
|
|
154
|
+
key,
|
|
155
|
+
type,
|
|
156
|
+
status: tempStatus
|
|
157
|
+
};
|
|
56
158
|
}
|
|
159
|
+
return undefined;
|
|
57
160
|
};
|
|
58
161
|
const action = {
|
|
59
162
|
title: 'Send Subscriptions',
|
|
60
163
|
description: 'Send an identify call to Segment’s tracking API. This is used to get user channel subscription data into Engage.',
|
|
61
164
|
defaultSubscription: 'type = "identify"',
|
|
62
165
|
fields: {
|
|
63
|
-
engage_space:
|
|
64
|
-
user_id:
|
|
65
|
-
anonymous_id:
|
|
66
|
-
email:
|
|
67
|
-
email_subscription_status:
|
|
68
|
-
subscription_groups:
|
|
69
|
-
phone:
|
|
70
|
-
sms_subscription_status:
|
|
71
|
-
whatsapp_subscription_status:
|
|
72
|
-
android_push_token:
|
|
73
|
-
android_push_subscription_status:
|
|
74
|
-
ios_push_token:
|
|
75
|
-
ios_push_subscription_status:
|
|
76
|
-
traits:
|
|
166
|
+
engage_space: subscription_properties_1.engage_space,
|
|
167
|
+
user_id: subscription_properties_1.user_id,
|
|
168
|
+
anonymous_id: subscription_properties_1.anonymous_id,
|
|
169
|
+
email: subscription_properties_1.email,
|
|
170
|
+
email_subscription_status: subscription_properties_1.email_subscription_status,
|
|
171
|
+
subscription_groups: subscription_properties_1.subscription_groups,
|
|
172
|
+
phone: subscription_properties_1.phone,
|
|
173
|
+
sms_subscription_status: subscription_properties_1.sms_subscription_status,
|
|
174
|
+
whatsapp_subscription_status: subscription_properties_1.whatsapp_subscription_status,
|
|
175
|
+
android_push_token: subscription_properties_1.android_push_token,
|
|
176
|
+
android_push_subscription_status: subscription_properties_1.android_push_subscription_status,
|
|
177
|
+
ios_push_token: subscription_properties_1.ios_push_token,
|
|
178
|
+
ios_push_subscription_status: subscription_properties_1.ios_push_subscription_status,
|
|
179
|
+
traits: subscription_properties_1.traits
|
|
77
180
|
},
|
|
78
181
|
perform: (request, { payload, settings, features, statsContext }) => {
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
status: getStatus(status?.trim().toLowerCase())
|
|
86
|
-
});
|
|
87
|
-
};
|
|
88
|
-
const getStatus = (subscriptionStatus) => {
|
|
89
|
-
if (subscriptionStatus === 'true' || subscriptionStatus === 'subscribed') {
|
|
90
|
-
return 'subscribed';
|
|
91
|
-
}
|
|
92
|
-
if (subscriptionStatus === 'false' || subscriptionStatus === 'unsubscribed') {
|
|
93
|
-
return 'unsubscribed';
|
|
94
|
-
}
|
|
95
|
-
if (subscriptionStatus === null || !subscriptionStatus || subscriptionStatus === '') {
|
|
96
|
-
return 'did_not_subscribe';
|
|
97
|
-
}
|
|
98
|
-
throw errors_1.InvalidSubscriptionStatusThrowableError;
|
|
99
|
-
};
|
|
100
|
-
const messaging_subscriptions = [];
|
|
101
|
-
if (payload?.email) {
|
|
102
|
-
if (payload.email_subscription_status) {
|
|
103
|
-
const emailSubscription = {
|
|
104
|
-
key: payload.email,
|
|
105
|
-
type: 'EMAIL',
|
|
106
|
-
status: getStatus(payload.email_subscription_status?.trim().toLowerCase())
|
|
107
|
-
};
|
|
108
|
-
if (payload.subscription_groups && typeof payload.subscription_groups === 'object') {
|
|
109
|
-
const formattedGroups = Object.entries(payload.subscription_groups)
|
|
110
|
-
.filter(([name, status]) => name !== undefined && status !== undefined)
|
|
111
|
-
.map(([name, status]) => ({
|
|
112
|
-
name: String(name),
|
|
113
|
-
status: getStatus(String(status).trim().toLowerCase())
|
|
114
|
-
}));
|
|
115
|
-
emailSubscription.groups = formattedGroups;
|
|
116
|
-
}
|
|
117
|
-
messaging_subscriptions.push(emailSubscription);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
payload?.phone &&
|
|
121
|
-
payload?.sms_subscription_status !== undefined &&
|
|
122
|
-
addMessagingSubscription(payload.phone, 'SMS', payload.sms_subscription_status);
|
|
123
|
-
payload?.phone &&
|
|
124
|
-
payload?.whatsapp_subscription_status !== undefined &&
|
|
125
|
-
addMessagingSubscription(payload.phone, 'WHATSAPP', payload.whatsapp_subscription_status);
|
|
126
|
-
payload?.android_push_token &&
|
|
127
|
-
payload?.android_push_subscription_status !== undefined &&
|
|
128
|
-
addMessagingSubscription(payload.android_push_token, 'ANDROID_PUSH', payload.android_push_subscription_status);
|
|
129
|
-
payload?.ios_push_token &&
|
|
130
|
-
payload?.ios_push_subscription_status !== undefined &&
|
|
131
|
-
addMessagingSubscription(payload.ios_push_token, 'IOS_PUSH', payload.ios_push_subscription_status);
|
|
132
|
-
const externalIds = [];
|
|
133
|
-
if (payload?.email) {
|
|
134
|
-
externalIds.push({
|
|
135
|
-
id: payload.email,
|
|
136
|
-
type: 'email',
|
|
137
|
-
collection: 'users',
|
|
138
|
-
encoding: 'none'
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
if (payload?.phone) {
|
|
142
|
-
externalIds.push({
|
|
143
|
-
id: payload.phone,
|
|
144
|
-
type: 'phone',
|
|
145
|
-
collection: 'users',
|
|
146
|
-
encoding: 'none'
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
if (payload?.android_push_token) {
|
|
150
|
-
externalIds.push({
|
|
151
|
-
id: payload.android_push_token,
|
|
152
|
-
type: 'android_push',
|
|
153
|
-
collection: 'users',
|
|
154
|
-
encoding: 'none'
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
if (payload?.ios_push_token) {
|
|
158
|
-
externalIds.push({
|
|
159
|
-
id: payload.ios_push_token,
|
|
160
|
-
type: 'ios_push',
|
|
161
|
-
collection: 'users',
|
|
162
|
-
encoding: 'none'
|
|
163
|
-
});
|
|
182
|
+
const statsClient = statsContext?.statsClient;
|
|
183
|
+
const tags = statsContext?.tags;
|
|
184
|
+
tags?.push(`action:sendSubscription`);
|
|
185
|
+
if (!settings.endpoint || !(settings.endpoint in properties_1.SEGMENT_ENDPOINTS)) {
|
|
186
|
+
statsClient?.incr('invalid_endpoint', 1, tags);
|
|
187
|
+
throw errors_1.InvalidEndpointSelectedThrowableError;
|
|
164
188
|
}
|
|
189
|
+
validateSubscriptions(payload, statsClient, tags);
|
|
190
|
+
const externalIds = enrichExternalIds(payload, []);
|
|
191
|
+
const messagingSubscriptions = enrichMessagingSubscriptions(payload, []);
|
|
165
192
|
const subscriptionPayload = {
|
|
166
193
|
userId: payload?.user_id,
|
|
167
194
|
anonymousId: payload?.anonymous_id,
|
|
@@ -169,19 +196,17 @@ const action = {
|
|
|
169
196
|
...payload?.traits
|
|
170
197
|
},
|
|
171
198
|
context: {
|
|
172
|
-
messaging_subscriptions,
|
|
199
|
+
messaging_subscriptions: messagingSubscriptions,
|
|
173
200
|
externalIds,
|
|
174
|
-
messaging_subscriptions_retl
|
|
201
|
+
messaging_subscriptions_retl: true
|
|
175
202
|
},
|
|
176
203
|
integrations: {
|
|
177
204
|
All: false
|
|
178
205
|
}
|
|
179
206
|
};
|
|
180
|
-
|
|
181
|
-
throw errors_1.InvalidEndpointSelectedThrowableError;
|
|
182
|
-
}
|
|
207
|
+
statsClient?.incr('success', 1, tags);
|
|
183
208
|
if (features && features['actions-segment-profiles-tapi-internal-enabled']) {
|
|
184
|
-
|
|
209
|
+
statsClient?.incr('tapi_internal', 1, tags);
|
|
185
210
|
const payload = { ...subscriptionPayload, type: 'identify' };
|
|
186
211
|
return { batch: [payload] };
|
|
187
212
|
}
|