@segment/actions-shared 1.97.0 → 1.98.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/dist/engage/utils/AggregateError.d.ts +14 -0
  2. package/dist/engage/utils/AggregateError.js +26 -0
  3. package/dist/engage/utils/AggregateError.js.map +1 -0
  4. package/dist/engage/utils/EngageActionPerformer.d.ts +42 -0
  5. package/dist/engage/utils/EngageActionPerformer.js +148 -0
  6. package/dist/engage/utils/EngageActionPerformer.js.map +1 -0
  7. package/dist/engage/utils/EngageLogger.d.ts +18 -0
  8. package/dist/engage/utils/EngageLogger.js +52 -0
  9. package/dist/engage/utils/EngageLogger.js.map +1 -0
  10. package/dist/engage/utils/EngageStats.d.ts +18 -0
  11. package/dist/engage/utils/EngageStats.js +95 -0
  12. package/dist/engage/utils/EngageStats.js.map +1 -0
  13. package/dist/engage/utils/IntegrationErrorWrapper.d.ts +12 -0
  14. package/dist/engage/utils/IntegrationErrorWrapper.js +31 -0
  15. package/dist/engage/utils/IntegrationErrorWrapper.js.map +1 -0
  16. package/dist/engage/utils/MessageSendPerformer.d.ts +65 -0
  17. package/dist/engage/utils/MessageSendPerformer.js +211 -0
  18. package/dist/engage/utils/MessageSendPerformer.js.map +1 -0
  19. package/dist/engage/utils/Profile.d.ts +6 -0
  20. package/dist/engage/utils/Profile.js +3 -0
  21. package/dist/engage/utils/Profile.js.map +1 -0
  22. package/dist/engage/utils/ResponseError.d.ts +25 -0
  23. package/dist/engage/utils/ResponseError.js +22 -0
  24. package/dist/engage/utils/ResponseError.js.map +1 -0
  25. package/dist/engage/utils/getProfileApiEndpoint.d.ts +2 -0
  26. package/dist/engage/utils/getProfileApiEndpoint.js +10 -0
  27. package/dist/engage/utils/getProfileApiEndpoint.js.map +1 -0
  28. package/dist/engage/utils/index.d.ts +14 -0
  29. package/dist/engage/utils/index.js +27 -0
  30. package/dist/engage/utils/index.js.map +1 -0
  31. package/dist/engage/utils/isDestinationActionService.d.ts +1 -0
  32. package/dist/engage/utils/isDestinationActionService.js +8 -0
  33. package/dist/engage/utils/isDestinationActionService.js.map +1 -0
  34. package/dist/engage/utils/isRetryableError.d.ts +2 -0
  35. package/dist/engage/utils/isRetryableError.js +33 -0
  36. package/dist/engage/utils/isRetryableError.js.map +1 -0
  37. package/dist/engage/utils/operationTracking/GenericMethodDecorator.d.ts +1 -0
  38. package/dist/engage/utils/operationTracking/GenericMethodDecorator.js +3 -0
  39. package/dist/engage/utils/operationTracking/GenericMethodDecorator.js.map +1 -0
  40. package/dist/engage/utils/operationTracking/OperationDecorator.d.ts +46 -0
  41. package/dist/engage/utils/operationTracking/OperationDecorator.js +46 -0
  42. package/dist/engage/utils/operationTracking/OperationDecorator.js.map +1 -0
  43. package/dist/engage/utils/operationTracking/OperationDuration.d.ts +12 -0
  44. package/dist/engage/utils/operationTracking/OperationDuration.js +23 -0
  45. package/dist/engage/utils/operationTracking/OperationDuration.js.map +1 -0
  46. package/dist/engage/utils/operationTracking/OperationErrorHandler.d.ts +12 -0
  47. package/dist/engage/utils/operationTracking/OperationErrorHandler.js +35 -0
  48. package/dist/engage/utils/operationTracking/OperationErrorHandler.js.map +1 -0
  49. package/dist/engage/utils/operationTracking/OperationFinallyHooks.d.ts +14 -0
  50. package/dist/engage/utils/operationTracking/OperationFinallyHooks.js +31 -0
  51. package/dist/engage/utils/operationTracking/OperationFinallyHooks.js.map +1 -0
  52. package/dist/engage/utils/operationTracking/OperationLogger.d.ts +31 -0
  53. package/dist/engage/utils/operationTracking/OperationLogger.js +104 -0
  54. package/dist/engage/utils/operationTracking/OperationLogger.js.map +1 -0
  55. package/dist/engage/utils/operationTracking/OperationStats.d.ts +39 -0
  56. package/dist/engage/utils/operationTracking/OperationStats.js +130 -0
  57. package/dist/engage/utils/operationTracking/OperationStats.js.map +1 -0
  58. package/dist/engage/utils/operationTracking/OperationTree.d.ts +23 -0
  59. package/dist/engage/utils/operationTracking/OperationTree.js +49 -0
  60. package/dist/engage/utils/operationTracking/OperationTree.js.map +1 -0
  61. package/dist/engage/utils/operationTracking/TrackedError.d.ts +6 -0
  62. package/dist/engage/utils/operationTracking/TrackedError.js +3 -0
  63. package/dist/engage/utils/operationTracking/TrackedError.js.map +1 -0
  64. package/dist/engage/utils/operationTracking/index.d.ts +10 -0
  65. package/dist/engage/utils/operationTracking/index.js +23 -0
  66. package/dist/engage/utils/operationTracking/index.js.map +1 -0
  67. package/dist/engage/utils/operationTracking/wrapTryCatchFinallyPromisable.d.ts +21 -0
  68. package/dist/engage/utils/operationTracking/wrapTryCatchFinallyPromisable.js +99 -0
  69. package/dist/engage/utils/operationTracking/wrapTryCatchFinallyPromisable.js.map +1 -0
  70. package/dist/engage/utils/testUtils.d.ts +6 -0
  71. package/dist/engage/utils/testUtils.js +27 -0
  72. package/dist/engage/utils/testUtils.js.map +1 -0
  73. package/dist/engage/utils/track.d.ts +52 -0
  74. package/dist/engage/utils/track.js +9 -0
  75. package/dist/engage/utils/track.js.map +1 -0
  76. package/dist/index.d.ts +1 -0
  77. package/dist/index.js +1 -0
  78. package/dist/index.js.map +1 -1
  79. package/package.json +3 -3
@@ -0,0 +1,211 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.MessageSendPerformer = exports.SendabilityStatus = void 0;
10
+ const EngageActionPerformer_1 = require("./EngageActionPerformer");
11
+ const isRetryableError_1 = require("./isRetryableError");
12
+ const AggregateError_1 = require("./AggregateError");
13
+ const getProfileApiEndpoint_1 = require("./getProfileApiEndpoint");
14
+ const track_1 = require("./track");
15
+ const actions_core_1 = require("@segment/actions-core");
16
+ var SendabilityStatus;
17
+ (function (SendabilityStatus) {
18
+ SendabilityStatus["ShouldSend"] = "should_send";
19
+ SendabilityStatus["NotSubscribed"] = "not_subscribed";
20
+ SendabilityStatus["NoSupportedExternalIds"] = "no_supported_ids";
21
+ SendabilityStatus["InvalidSubscriptionStatus"] = "invalid_subscription_status";
22
+ SendabilityStatus["SendDisabled"] = "send_disabled";
23
+ })(SendabilityStatus = exports.SendabilityStatus || (exports.SendabilityStatus = {}));
24
+ class MessageSendPerformer extends EngageActionPerformer_1.EngageActionPerformer {
25
+ async doPerform() {
26
+ const res = this.forAllRecepients((recepient) => this.sendToRecepient(recepient));
27
+ if (this.executeInput.features) {
28
+ this.logInfo('Feature flags:' + JSON.stringify(this.executeInput.features));
29
+ }
30
+ this.statsEventDeliveryTs();
31
+ return res;
32
+ }
33
+ getStaticMembersOfThisClass() {
34
+ return this.constructor;
35
+ }
36
+ isExternalIdSubscribed(extId) {
37
+ const staticMems = this.getStaticMembersOfThisClass();
38
+ const subStatus = extId.subscriptionStatus?.toString()?.toLowerCase();
39
+ const isOptOutModel = this.payload.sendBasedOnOptOut ? true : false;
40
+ if (!subStatus)
41
+ return isOptOutModel;
42
+ if (staticMems.sendableStatuses.includes(subStatus))
43
+ return true;
44
+ if (staticMems.nonSendableStatuses.includes(subStatus))
45
+ return false;
46
+ return undefined;
47
+ }
48
+ convertSubscriptionStatusText(subVal) {
49
+ if (subVal == undefined) {
50
+ return 'unknown';
51
+ }
52
+ if (subVal == '') {
53
+ return 'did_not_subscribe';
54
+ }
55
+ return subVal;
56
+ }
57
+ getSendabilityPayload() {
58
+ if (!this.payload.send) {
59
+ return { sendabilityStatus: SendabilityStatus.SendDisabled };
60
+ }
61
+ const supportedExtIdsWithSub = this.payload.externalIds
62
+ ?.filter((extId) => this.isSupportedExternalId(extId))
63
+ .map((extId) => ({
64
+ extId,
65
+ isSubscribed: this.isExternalIdSubscribed(extId)
66
+ }));
67
+ this.payload.sendBasedOnOptOut
68
+ ? this.currentOperation?.tags.push('SubscriptionOptOutType:' + true)
69
+ : this.currentOperation?.tags.push('SubscriptionOptOutType:' + false);
70
+ if (!supportedExtIdsWithSub || !supportedExtIdsWithSub.length)
71
+ return {
72
+ sendabilityStatus: SendabilityStatus.NoSupportedExternalIds
73
+ };
74
+ this.currentOperation?.tags.push('subscription_status:' + this.convertSubscriptionStatusText(supportedExtIdsWithSub[0]?.extId?.subscriptionStatus));
75
+ const invalidSubStatuses = supportedExtIdsWithSub.filter((e) => e.isSubscribed === undefined).map((e) => e.extId);
76
+ const shouldSendExtIds = supportedExtIdsWithSub.filter((e) => e.isSubscribed === true).map((e) => e.extId);
77
+ if (!shouldSendExtIds.length) {
78
+ return invalidSubStatuses.length == 0
79
+ ? {
80
+ sendabilityStatus: SendabilityStatus.NotSubscribed
81
+ }
82
+ : {
83
+ sendabilityStatus: SendabilityStatus.InvalidSubscriptionStatus,
84
+ invalid: invalidSubStatuses
85
+ };
86
+ }
87
+ if (shouldSendExtIds.length) {
88
+ const subWithIds = shouldSendExtIds.filter((extId) => extId.id);
89
+ return {
90
+ sendabilityStatus: subWithIds.length > 0 ? SendabilityStatus.ShouldSend : SendabilityStatus.NoSupportedExternalIds,
91
+ recepients: subWithIds.length > 0 ? subWithIds : shouldSendExtIds,
92
+ invalid: invalidSubStatuses
93
+ };
94
+ }
95
+ if (invalidSubStatuses.length)
96
+ return {
97
+ sendabilityStatus: SendabilityStatus.InvalidSubscriptionStatus,
98
+ invalid: invalidSubStatuses
99
+ };
100
+ return {
101
+ sendabilityStatus: SendabilityStatus.NoSupportedExternalIds,
102
+ recepients: supportedExtIdsWithSub.map((e) => e.extId)
103
+ };
104
+ }
105
+ getRecepients() {
106
+ const sendabilityPayload = this.getSendabilityPayload();
107
+ const shouldSend = sendabilityPayload.sendabilityStatus === SendabilityStatus.ShouldSend;
108
+ this.currentOperation?.tags.push('sendability_status:' + sendabilityPayload.sendabilityStatus);
109
+ this.currentOperation?.logs.push(shouldSend
110
+ ? `Sending message to recepients (${sendabilityPayload.recepients?.length}): ${sendabilityPayload.recepients
111
+ ?.map((r) => this.redactPii(r.id))
112
+ .join(', ')}})`
113
+ : `Not sending message because ${sendabilityPayload.sendabilityStatus?.toUpperCase()}. Recepients (${sendabilityPayload.recepients?.length})`);
114
+ return sendabilityPayload.sendabilityStatus == SendabilityStatus.ShouldSend
115
+ ? sendabilityPayload.recepients || []
116
+ : [];
117
+ }
118
+ beforePerform() {
119
+ if (!this.settings.region && this.getDefaultSettingsRegion) {
120
+ this.settings.region = this.getDefaultSettingsRegion();
121
+ }
122
+ Object.assign(this.logDetails, {
123
+ externalIds: this.payload.externalIds?.map((eid) => ({ ...eid, id: this.redactPii(eid.id) })),
124
+ shouldSend: this.payload.send,
125
+ settings_region: this.settings.region,
126
+ sourceId: this.settings.sourceId,
127
+ spaceId: this.settings.spaceId,
128
+ messageId: this.executeInput['rawData']?.messageId,
129
+ channelType: this.getChannelType()
130
+ });
131
+ if ('userId' in this.payload)
132
+ this.logDetails.userId = this.payload.userId;
133
+ if (this.executeInput.statsContext?.tags) {
134
+ for (const item of this.executeInput.statsContext?.tags) {
135
+ if (item.includes('delivery_attempt') || item.includes('replay')) {
136
+ this.logDetails[item.split(':')[0]] = item.split(':')[1];
137
+ }
138
+ }
139
+ }
140
+ }
141
+ statsEventDeliveryTs() {
142
+ const eventOccurredTS = this.payload?.eventOccurredTS;
143
+ if (typeof eventOccurredTS === 'number') {
144
+ this.statsHistogram('eventDeliveryTS', Date.now() - new Date(eventOccurredTS).getTime());
145
+ }
146
+ }
147
+ async forAllRecepients(sendToRecepient) {
148
+ const recepients = this.getRecepients();
149
+ await this.beforeSend?.(recepients);
150
+ const results = (await Promise.allSettled(recepients.map((recepient) => sendToRecepient(recepient)))).map((r, i) => ({
151
+ recepient: recepients[i],
152
+ status: r.status,
153
+ ...(r.status === 'rejected' ? { error: r.reason } : { result: r.value })
154
+ }));
155
+ return this.aggregateSendResults(results);
156
+ }
157
+ aggregateSendResults(sendResults) {
158
+ if (!sendResults.length) {
159
+ return;
160
+ }
161
+ if (sendResults.length === 1) {
162
+ if (sendResults[0].status === 'rejected') {
163
+ throw sendResults[0].error;
164
+ }
165
+ else {
166
+ return sendResults[0].result;
167
+ }
168
+ }
169
+ const fulfilled = sendResults.filter((sr) => sr.status === 'fulfilled');
170
+ if (fulfilled.length) {
171
+ return fulfilled.map((sr) => sr.result);
172
+ }
173
+ const rejected = sendResults.filter((sr) => sr.status === 'rejected');
174
+ if (rejected.every((r) => isRetryableError_1.isRetryableError(r.error))) {
175
+ throw AggregateError_1.AggregateError.create({
176
+ errors: rejected.map((r) => r.error),
177
+ message: (msg) => 'Failed to send to all subscribed recepients (retryable):' + msg
178
+ });
179
+ }
180
+ const firstNonRetryable = rejected.find((r) => !isRetryableError_1.isRetryableError(r.error))?.error;
181
+ throw AggregateError_1.AggregateError.create({
182
+ errors: rejected.map((r) => r.error),
183
+ takeCodeAndStatusFromError: firstNonRetryable,
184
+ message: (msg) => 'Failed to send to all subscribed recepients (non-retryable):' + msg
185
+ });
186
+ }
187
+ async getProfileTraits() {
188
+ if (this.payload.traitEnrichment)
189
+ return this.payload?.traits || {};
190
+ if (!this.payload.userId) {
191
+ throw new actions_core_1.PayloadValidationError('No userId provided and no traits provided');
192
+ }
193
+ const endpoint = getProfileApiEndpoint_1.getProfileApiEndpoint(this.settings.profileApiEnvironment, this.settings.region);
194
+ const encodedProfileId = encodeURIComponent(this.payload.userId);
195
+ const response = await this.request(`${endpoint}/v1/spaces/${this.settings.spaceId}/collections/users/profiles/user_id:${encodedProfileId}/traits?limit=200`, {
196
+ headers: {
197
+ authorization: `Basic ${Buffer.from(this.settings.profileApiAccessToken + ':').toString('base64')}`,
198
+ 'content-type': 'application/json'
199
+ }
200
+ });
201
+ const body = await response.json();
202
+ return body.traits;
203
+ }
204
+ }
205
+ MessageSendPerformer.nonSendableStatuses = ['unsubscribed', 'false'];
206
+ MessageSendPerformer.sendableStatuses = ['subscribed', 'true'];
207
+ __decorate([
208
+ track_1.track()
209
+ ], MessageSendPerformer.prototype, "getProfileTraits", null);
210
+ exports.MessageSendPerformer = MessageSendPerformer;
211
+ //# sourceMappingURL=MessageSendPerformer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MessageSendPerformer.js","sourceRoot":"","sources":["../../../src/engage/utils/MessageSendPerformer.ts"],"names":[],"mappings":";;;;;;;;;AAGA,mEAA+D;AAC/D,yDAAqD;AACrD,qDAAiD;AAEjD,mEAAuE;AACvE,mCAA+B;AAC/B,wDAA8D;AAE9D,IAAY,iBAqBX;AArBD,WAAY,iBAAiB;IAI3B,+CAA0B,CAAA;IAI1B,qDAAgC,CAAA;IAIhC,gEAA2C,CAAA;IAI3C,8EAAyD,CAAA;IAIzD,mDAA8B,CAAA;AAChC,CAAC,EArBW,iBAAiB,GAAjB,yBAAiB,KAAjB,yBAAiB,QAqB5B;AAyDD,MAAsB,oBAGpB,SAAQ,6CAA0C;IAClD,KAAK,CAAC,SAAS;QAEb,MAAM,GAAG,GAAG,IAAI,CAAC,gBAAgB,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC,CAAA;QAEjF,IAAI,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE;YAC9B,IAAI,CAAC,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAA;SAC5E;QAGD,IAAI,CAAC,oBAAoB,EAAE,CAAA;QAC3B,OAAO,GAAG,CAAA;IACZ,CAAC;IAeD,2BAA2B;QAGzB,OAAO,IAAI,CAAC,WAA8B,CAAA;IAC5C,CAAC;IAKD,sBAAsB,CAAC,KAAsB;QAC3C,MAAM,UAAU,GAAG,IAAI,CAAC,2B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O,CAAC,CAAA;AAC/C,qCAAgB,GAAG,CAAC,YAAY,EAAE,MAAM,CAAC,CAAA;AA2OzD;IADC,aAAK,EAAE;4DAqBP;AAxRH,oDAyRC"}
@@ -0,0 +1,6 @@
1
+ export interface Profile {
2
+ user_id?: string;
3
+ anonymous_id?: string;
4
+ email?: string;
5
+ traits: Record<string, any>;
6
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=Profile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Profile.js","sourceRoot":"","sources":["../../../src/engage/utils/Profile.ts"],"names":[],"mappings":""}
@@ -0,0 +1,25 @@
1
+ import { HTTPError } from '@segment/actions-core/request-client';
2
+ export interface ResponseError extends HTTPError {
3
+ response: HTTPError['response'] & {
4
+ data: {
5
+ code: string | number;
6
+ message: string;
7
+ more_info: string;
8
+ status?: number;
9
+ statusCode?: number;
10
+ errors?: {
11
+ message: string;
12
+ }[];
13
+ };
14
+ headers?: Response['headers'];
15
+ };
16
+ code?: string;
17
+ status?: number;
18
+ retry?: boolean;
19
+ }
20
+ export interface ErrorDetails {
21
+ message: string;
22
+ code: string;
23
+ status?: number;
24
+ }
25
+ export declare function getErrorDetails(error: any): ErrorDetails;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getErrorDetails = void 0;
4
+ function getErrorDetails(error) {
5
+ const respError = error;
6
+ const status = respError.status || respError.response?.status;
7
+ const code = respError.code || respError.response?.data?.code;
8
+ const message = [
9
+ respError.name || respError.constructor?.name,
10
+ respError.message,
11
+ respError.response?.statusText && !respError.message.includes(respError.response?.statusText)
12
+ ? respError.response?.statusText
13
+ : undefined,
14
+ respError?.response?.data?.message,
15
+ respError?.response?.data?.errors?.[0]?.message
16
+ ]
17
+ .filter(Boolean)
18
+ .join('; ');
19
+ return { status, code: code?.toString(), message };
20
+ }
21
+ exports.getErrorDetails = getErrorDetails;
22
+ //# sourceMappingURL=ResponseError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ResponseError.js","sourceRoot":"","sources":["../../../src/engage/utils/ResponseError.ts"],"names":[],"mappings":";;;AA4BA,SAAgB,eAAe,CAAC,KAAU;IAGxC,MAAM,SAAS,GAAG,KAAsB,CAAA;IAGxC,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,IAAI,SAAS,CAAC,QAAQ,EAAE,MAAM,CAAA;IAI7D,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,IAAI,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,CAAA;IAE7D,MAAM,OAAO,GAAG;QACd,SAAS,CAAC,IAAI,IAAI,SAAS,CAAC,WAAW,EAAE,IAAI;QAC7C,SAAS,CAAC,OAAO;QACjB,SAAS,CAAC,QAAQ,EAAE,UAAU,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,QAAQ,EAAE,UAAU,CAAC;YAC3F,CAAC,CAAC,SAAS,CAAC,QAAQ,EAAE,UAAU;YAChC,CAAC,CAAC,SAAS;QAGb,SAAS,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO;QAClC,SAAS,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO;KAChD;SACE,MAAM,CAAC,OAAO,CAAC;SACf,IAAI,CAAC,IAAI,CAAC,CAAA;IACb,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,OAAO,EAAE,CAAA;AACpD,CAAC;AA1BD,0CA0BC"}
@@ -0,0 +1,2 @@
1
+ export declare const getProfileApiEndpoint: (environment: string, region?: Region | undefined) => string;
2
+ export declare type Region = 'us-west-2' | 'eu-west-1';
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getProfileApiEndpoint = void 0;
4
+ const getProfileApiEndpoint = (environment, region) => {
5
+ const domainName = region === 'eu-west-1' ? 'profiles.euw1.segment' : 'profiles.segment';
6
+ const topLevelName = environment === 'production' ? 'com' : 'build';
7
+ return `https://${domainName}.${topLevelName}`;
8
+ };
9
+ exports.getProfileApiEndpoint = getProfileApiEndpoint;
10
+ //# sourceMappingURL=getProfileApiEndpoint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getProfileApiEndpoint.js","sourceRoot":"","sources":["../../../src/engage/utils/getProfileApiEndpoint.ts"],"names":[],"mappings":";;;AACO,MAAM,qBAAqB,GAAG,CAAC,WAAmB,EAAE,MAAe,EAAU,EAAE;IACpF,MAAM,UAAU,GAAG,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,uBAAuB,CAAC,CAAC,CAAC,kBAAkB,CAAA;IACxF,MAAM,YAAY,GAAG,WAAW,KAAK,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAA;IACnE,OAAO,WAAW,UAAU,IAAI,YAAY,EAAE,CAAA;AAChD,CAAC,CAAA;AAJY,QAAA,qBAAqB,yBAIjC"}
@@ -0,0 +1,14 @@
1
+ export * from './operationTracking';
2
+ export * from './AggregateError';
3
+ export * from './EngageActionPerformer';
4
+ export * from './EngageLogger';
5
+ export * from './EngageStats';
6
+ export * from './getProfileApiEndpoint';
7
+ export * from './IntegrationErrorWrapper';
8
+ export * from './isDestinationActionService';
9
+ export * from './isRetryableError';
10
+ export * from './MessageSendPerformer';
11
+ export * from './Profile';
12
+ export * from './ResponseError';
13
+ export * from './testUtils';
14
+ export * from './track';
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./operationTracking"), exports);
14
+ __exportStar(require("./AggregateError"), exports);
15
+ __exportStar(require("./EngageActionPerformer"), exports);
16
+ __exportStar(require("./EngageLogger"), exports);
17
+ __exportStar(require("./EngageStats"), exports);
18
+ __exportStar(require("./getProfileApiEndpoint"), exports);
19
+ __exportStar(require("./IntegrationErrorWrapper"), exports);
20
+ __exportStar(require("./isDestinationActionService"), exports);
21
+ __exportStar(require("./isRetryableError"), exports);
22
+ __exportStar(require("./MessageSendPerformer"), exports);
23
+ __exportStar(require("./Profile"), exports);
24
+ __exportStar(require("./ResponseError"), exports);
25
+ __exportStar(require("./testUtils"), exports);
26
+ __exportStar(require("./track"), exports);
27
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/engage/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,sDAAmC;AACnC,mDAAgC;AAChC,0DAAuC;AACvC,iDAA8B;AAC9B,gDAA6B;AAC7B,0DAAuC;AACvC,4DAAyC;AACzC,+DAA4C;AAC5C,qDAAkC;AAClC,yDAAsC;AACtC,4CAAyB;AACzB,kDAA+B;AAC/B,8CAA2B;AAC3B,0CAAuB"}
@@ -0,0 +1 @@
1
+ export declare function isDestinationActionService(): boolean;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isDestinationActionService = void 0;
4
+ function isDestinationActionService() {
5
+ return (process.env.DESTINATIONS_ACTION_SERVICE === 'true' || process.env.SERVICE_NAME === 'destination-actions-service');
6
+ }
7
+ exports.isDestinationActionService = isDestinationActionService;
8
+ //# sourceMappingURL=isDestinationActionService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isDestinationActionService.js","sourceRoot":"","sources":["../../../src/engage/utils/isDestinationActionService.ts"],"names":[],"mappings":";;;AAAA,SAAgB,0BAA0B;IAExC,OAAO,CACL,OAAO,CAAC,GAAG,CAAC,2BAA2B,KAAK,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,YAAY,KAAK,6BAA6B,CACjH,CAAA;AACH,CAAC;AALD,gEAKC"}
@@ -0,0 +1,2 @@
1
+ export declare function isRetryableError(error: any): boolean;
2
+ export declare function isRetryableStatus(status?: number): boolean;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isRetryableStatus = exports.isRetryableError = void 0;
4
+ const ResponseError_1 = require("./ResponseError");
5
+ function isRetryableError(error) {
6
+ return isRetryableStatus(ResponseError_1.getErrorDetails(error).status);
7
+ }
8
+ exports.isRetryableError = isRetryableError;
9
+ function isRetryableStatus(status) {
10
+ let result = true;
11
+ const statusGroup = status === undefined ? undefined : Math.floor(status / 100);
12
+ switch (statusGroup) {
13
+ case 2:
14
+ case 4:
15
+ result = false;
16
+ break;
17
+ default:
18
+ result = true;
19
+ }
20
+ switch (status) {
21
+ case 408:
22
+ case 423:
23
+ case 429:
24
+ result = true;
25
+ break;
26
+ case 501:
27
+ result = false;
28
+ break;
29
+ }
30
+ return result;
31
+ }
32
+ exports.isRetryableStatus = isRetryableStatus;
33
+ //# sourceMappingURL=isRetryableError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isRetryableError.js","sourceRoot":"","sources":["../../../src/engage/utils/isRetryableError.ts"],"names":[],"mappings":";;;AAAA,mDAAiD;AAGjD,SAAgB,gBAAgB,CAAC,KAAU;IACzC,OAAO,iBAAiB,CAAC,+BAAe,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAA;AACzD,CAAC;AAFD,4CAEC;AAED,SAAgB,iBAAiB,CAAC,MAAe;IAE/C,IAAI,MAAM,GAAG,IAAI,CAAA;IACjB,MAAM,WAAW,GAAG,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,GAAG,CAAC,CAAA;IAC/E,QAAQ,WAAW,EAAE;QACnB,KAAK,CAAC,CAAC;QACP,KAAK,CAAC;YACJ,MAAM,GAAG,KAAK,CAAA;YACd,MAAK;QACP;YAEE,MAAM,GAAG,IAAI,CAAA;KAChB;IACD,QAAQ,MAAM,EAAE;QACd,KAAK,GAAG,CAAC;QACT,KAAK,GAAG,CAAC;QACT,KAAK,GAAG;YACN,MAAM,GAAG,IAAI,CAAA;YACb,MAAK;QACP,KAAK,GAAG;YACN,MAAM,GAAG,KAAK,CAAA;YACd,MAAK;KAGR;IACD,OAAO,MAAM,CAAA;AACf,CAAC;AA1BD,8CA0BC"}
@@ -0,0 +1 @@
1
+ export declare type GenericMethodDecorator<TFunc extends (this: any, ...args: any[]) => any = (this: any, ...args: any) => any> = (target: ThisParameterType<TFunc>, propertyKey: string, descriptor: TypedPropertyDescriptor<TFunc>) => TypedPropertyDescriptor<TFunc> | void;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=GenericMethodDecorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GenericMethodDecorator.js","sourceRoot":"","sources":["../../../../src/engage/utils/operationTracking/GenericMethodDecorator.ts"],"names":[],"mappings":""}
@@ -0,0 +1,46 @@
1
+ import { GenericMethodDecorator } from './GenericMethodDecorator';
2
+ import { OperationDuration } from './OperationDuration';
3
+ import { OperationErrorHandler } from './OperationErrorHandler';
4
+ import { OperationFinallyHooks } from './OperationFinallyHooks';
5
+ import { OperationTree } from './OperationTree';
6
+ import { FuncFromTryCatchFinallyContext, TryCatchFinallyContext, TryCatchFinallyHook } from './wrapTryCatchFinallyPromisable';
7
+ export interface DecoratorArgs {
8
+ operation?: string;
9
+ [key: string]: any;
10
+ }
11
+ export declare type OperationHookContext<TContext extends TryCatchFinallyContext = TryCatchFinallyContext, TDecoratorArgs extends DecoratorArgs = DecoratorArgs> = TContext & {
12
+ decoratorArgs?: TDecoratorArgs;
13
+ };
14
+ export interface OperationHookProvider<TContext extends OperationHookContext = OperationHookContext, TDecoratorUtils = {}> {
15
+ getTryCatchFinallyHook(ctx: TContext): TryCatchFinallyHook<TContext>;
16
+ getDecoratorUtils?(): TDecoratorUtils;
17
+ }
18
+ export declare type UnionToIntersection<TUnion> = (TUnion extends any ? (k: TUnion) => void : never) extends (k: infer I) => void ? I : never;
19
+ export declare type ContextFromHookProviders<TProviders extends OperationHookProvider[]> = TProviders extends OperationHookProvider<infer TContext>[] ? UnionToIntersection<TContext> : TryCatchFinallyContext;
20
+ export declare type DecoratorArgsFromContext<TContext extends TryCatchFinallyContext> = TContext extends {
21
+ decoratorArgs?: infer TDecoratorArgs;
22
+ } ? TDecoratorArgs : DecoratorArgs;
23
+ export declare type DecoratorArgsFromHookProviders<TProviders extends OperationHookProvider[]> = DecoratorArgsFromContext<ContextFromHookProviders<TProviders>>;
24
+ export declare type DecoratorUtilsFromHookProviders<TProviders extends OperationHookProvider[]> = TProviders extends OperationHookProvider<any, infer TDecoratorUtils>[] ? UnionToIntersection<TDecoratorUtils> : {};
25
+ export declare type FuncFromHookProviders<TProviders extends OperationHookProvider[]> = FuncFromTryCatchFinallyContext<ContextFromHookProviders<TProviders>>;
26
+ export declare class OperationDecorator {
27
+ static createDecoratorFactory<TOperationHookProviders extends OperationHookProvider[]>(...hookProviders: TOperationHookProviders): ((decoratorArgs?: DecoratorArgsFromHookProviders<TOperationHookProviders>) => GenericMethodDecorator<FuncFromHookProviders<TOperationHookProviders>>) & DecoratorUtilsFromHookProviders<TOperationHookProviders> & {
28
+ _contextType: ContextFromHookProviders<TOperationHookProviders>;
29
+ };
30
+ static createDecoratorFactoryWithDefault<TOperationHookProviders extends OperationHookProvider[]>(...customHookProviders: TOperationHookProviders): ((decoratorArgs?: DecoratorArgsFromContext<ContextFromHookProviders<[typeof OperationErrorHandler, typeof OperationTree, typeof OperationDuration, typeof OperationFinallyHooks, ...TOperationHookProviders]>> | undefined) => GenericMethodDecorator<FuncFromTryCatchFinallyContext<ContextFromHookProviders<[typeof OperationErrorHandler, typeof OperationTree, typeof OperationDuration, typeof OperationFinallyHooks, ...TOperationHookProviders]>>>) & DecoratorUtilsFromHookProviders<[typeof OperationErrorHandler, typeof OperationTree, typeof OperationDuration, typeof OperationFinallyHooks, ...TOperationHookProviders]> & {
31
+ _contextType: ContextFromHookProviders<[typeof OperationErrorHandler, typeof OperationTree, typeof OperationDuration, typeof OperationFinallyHooks, ...TOperationHookProviders]>;
32
+ };
33
+ static getOperationName<TContext extends TryCatchFinallyContext>(ctx: TContext): string | undefined;
34
+ }
35
+ export declare type OperationDecoratorContext<TContext extends TryCatchFinallyContext = TryCatchFinallyContext> = TContext & {
36
+ decoratorOf?: {
37
+ classProto: any;
38
+ methodName: string;
39
+ descriptor: TypedPropertyDescriptor<any>;
40
+ originalMethod: FuncFromTryCatchFinallyContext<TContext>;
41
+ };
42
+ decoratorArgs?: DecoratorArgsFromContext<TContext> & DecoratorArgs;
43
+ };
44
+ export declare type ContextFromDecorator<TDecorator> = TDecorator extends {
45
+ _contextType: infer TContext;
46
+ } ? TContext : never;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OperationDecorator = void 0;
4
+ const OperationDuration_1 = require("./OperationDuration");
5
+ const OperationErrorHandler_1 = require("./OperationErrorHandler");
6
+ const OperationFinallyHooks_1 = require("./OperationFinallyHooks");
7
+ const OperationTree_1 = require("./OperationTree");
8
+ const wrapTryCatchFinallyPromisable_1 = require("./wrapTryCatchFinallyPromisable");
9
+ class OperationDecorator {
10
+ static createDecoratorFactory(...hookProviders) {
11
+ const decorator = (decoratorArgs) => {
12
+ return function (classProto, methodName, descriptor) {
13
+ const originalMethod = descriptor.value;
14
+ if (!(originalMethod instanceof Function))
15
+ throw new Error('Track decorator can only be applied to class methods');
16
+ const decoratorOf = {
17
+ classProto,
18
+ methodName,
19
+ descriptor,
20
+ originalMethod
21
+ };
22
+ descriptor.value = wrapTryCatchFinallyPromisable_1.wrapTryCatchFinallyPromisable(originalMethod, (ctx) => {
23
+ ctx.decoratorOf = decoratorOf;
24
+ ctx.decoratorArgs = decoratorArgs;
25
+ return hookProviders.map((h) => h.getTryCatchFinallyHook(ctx));
26
+ });
27
+ };
28
+ };
29
+ const decoratorUtils = {};
30
+ for (const hookProvider of hookProviders) {
31
+ Object.assign(decoratorUtils, hookProvider.getDecoratorUtils?.() || {});
32
+ }
33
+ return Object.assign(decorator, decoratorUtils);
34
+ }
35
+ static createDecoratorFactoryWithDefault(...customHookProviders) {
36
+ return OperationDecorator.createDecoratorFactory(OperationErrorHandler_1.OperationErrorHandler, OperationTree_1.OperationTree, OperationDuration_1.OperationDuration, OperationFinallyHooks_1.OperationFinallyHooks, ...customHookProviders);
37
+ }
38
+ static getOperationName(ctx) {
39
+ const ctxDecorated = ctx;
40
+ return (ctxDecorated.decoratorArgs?.operation ||
41
+ ctxDecorated.decoratorOf?.methodName ||
42
+ ctxDecorated.decoratorOf?.originalMethod?.name);
43
+ }
44
+ }
45
+ exports.OperationDecorator = OperationDecorator;
46
+ //# sourceMappingURL=OperationDecorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OperationDecorator.js","sourceRoot":"","sources":["../../../../src/engage/utils/operationTracking/OperationDecorator.ts"],"names":[],"mappings":";;;AAEA,2DAAuD;AACvD,mEAA+D;AAC/D,mEAA+D;AAC/D,mDAA+C;AAC/C,mFAKwC;AAmFxC,MAAa,kBAAkB;IAO7B,MAAM,CAAC,sBAAsB,CAC3B,GAAG,aAAsC;QAUzC,MAAM,SAAS,GAAG,CAAC,aAA8B,EAAiC,EAAE;YAClF,OAAO,UAAU,UAAU,EAAE,UAAU,EAAE,UAAU;gBACjD,MAAM,cAAc,GAAG,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,CAAC;CACF;AA1ED,gDA0EC"}
@@ -0,0 +1,12 @@
1
+ import { TryCatchFinallyContext, TryCatchFinallyHook } from './wrapTryCatchFinallyPromisable';
2
+ export declare type OperationDurationContext<TContext extends TryCatchFinallyContext = TryCatchFinallyContext> = TContext & {
3
+ start?: number;
4
+ duration?: number;
5
+ };
6
+ export declare class OperationDuration {
7
+ static getTryCatchFinallyHook(_ctx: OperationDurationContext): TryCatchFinallyHook<OperationDurationContext>;
8
+ static getPriority(): number;
9
+ static onTry(ctx: OperationDurationContext): void;
10
+ static onFinally(ctx: OperationDurationContext): void;
11
+ static getDuration<TContext extends OperationDurationContext>(ctx: TContext): number | undefined;
12
+ }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OperationDuration = void 0;
4
+ class OperationDuration {
5
+ static getTryCatchFinallyHook(_ctx) {
6
+ return this;
7
+ }
8
+ static getPriority() {
9
+ return -1000;
10
+ }
11
+ static onTry(ctx) {
12
+ ctx.start = Date.now();
13
+ }
14
+ static onFinally(ctx) {
15
+ if (ctx.start !== undefined)
16
+ ctx.duration = Date.now() - ctx.start;
17
+ }
18
+ static getDuration(ctx) {
19
+ return ctx.duration;
20
+ }
21
+ }
22
+ exports.OperationDuration = OperationDuration;
23
+ //# sourceMappingURL=OperationDuration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OperationDuration.js","sourceRoot":"","sources":["../../../../src/engage/utils/operationTracking/OperationDuration.ts"],"names":[],"mappings":";;;AAOA,MAAa,iBAAiB;IAC5B,MAAM,CAAC,sBAAsB,CAAC,IAA8B;QAC1D,OAAO,IAAI,CAAA;IACb,CAAC;IACD,MAAM,CAAC,WAAW;QAChB,OAAO,CAAC,IAAI,CAAA;IACd,CAAC;IACD,MAAM,CAAC,KAAK,CAAC,GAA6B;QACxC,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;IACxB,CAAC;IAED,MAAM,CAAC,SAAS,CAAC,GAA6B;QAC5C,IAAI,GAAG,CAAC,KAAK,KAAK,SAAS;YAAE,GAAG,CAAC,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,GAAG,CAAC,KAAK,CAAA;IACpE,CAAC;IACD,MAAM,CAAC,WAAW,CAA4C,GAAa;QACzE,OAAO,GAAG,CAAC,QAAQ,CAAA;IACrB,CAAC;CACF;AAjBD,8CAiBC"}
@@ -0,0 +1,12 @@
1
+ import { TrackedError } from './TrackedError';
2
+ import { TryCatchFinallyContext, TryCatchFinallyHook } from './wrapTryCatchFinallyPromisable';
3
+ export declare type OperationErrorHandlerContext<TContext extends TryCatchFinallyContext = TryCatchFinallyContext> = TContext & {
4
+ decoratorArgs?: {
5
+ onError?: (ctx: OperationErrorHandlerContext<TContext>) => void;
6
+ };
7
+ };
8
+ export declare class OperationErrorHandler {
9
+ static getTryCatchFinallyHook(_ctx: OperationErrorHandlerContext): TryCatchFinallyHook<OperationErrorHandlerContext>;
10
+ static onCatch(ctx: OperationErrorHandlerContext): void;
11
+ static wrap<TContext extends OperationErrorHandlerContext = OperationErrorHandlerContext>(originalError: unknown, getWrapper: (e: unknown) => unknown | undefined, ctx?: TContext): TrackedError<TryCatchFinallyContext<(this: any, ...args: any[]) => any>> | undefined;
12
+ }
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OperationErrorHandler = void 0;
4
+ class OperationErrorHandler {
5
+ static getTryCatchFinallyHook(_ctx) {
6
+ return this;
7
+ }
8
+ static onCatch(ctx) {
9
+ const dArgs = ctx.decoratorArgs;
10
+ ctx.error = this.wrap(ctx.error, () => {
11
+ dArgs?.onError?.apply(this, [ctx]);
12
+ return ctx.error;
13
+ }, ctx);
14
+ }
15
+ static wrap(originalError, getWrapper, ctx) {
16
+ const wrapper = getWrapper(originalError);
17
+ if (wrapper && originalError !== wrapper)
18
+ wrapper.underlyingError = originalError;
19
+ const trackedError = wrapper;
20
+ if (!trackedError)
21
+ return;
22
+ if (!ctx)
23
+ return;
24
+ if (!trackedError.trackedContext)
25
+ trackedError.trackedContext = ctx;
26
+ const trackedContextProp = Object.getOwnPropertyDescriptor(trackedError, 'trackedContext');
27
+ if (trackedContextProp?.enumerable) {
28
+ trackedContextProp.enumerable = false;
29
+ Object.defineProperty(trackedError, 'trackedContext', trackedContextProp);
30
+ }
31
+ return wrapper;
32
+ }
33
+ }
34
+ exports.OperationErrorHandler = OperationErrorHandler;
35
+ //# sourceMappingURL=OperationErrorHandler.js.map