@segment/actions-core 3.168.1-staging-ee75d3cad.0 → 3.168.2-async
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/cjs/create-test-integration.d.ts +9 -3
- package/dist/cjs/create-test-integration.js +31 -0
- package/dist/cjs/create-test-integration.js.map +1 -1
- package/dist/cjs/destination-kit/action.d.ts +68 -10
- package/dist/cjs/destination-kit/action.js +287 -41
- package/dist/cjs/destination-kit/action.js.map +1 -1
- package/dist/cjs/destination-kit/index.d.ts +24 -5
- package/dist/cjs/destination-kit/index.js +51 -17
- package/dist/cjs/destination-kit/index.js.map +1 -1
- package/dist/cjs/destination-kit/types.d.ts +0 -15
- package/dist/cjs/destination-kit/types.js.map +1 -1
- package/dist/cjs/index.d.ts +2 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/create-test-integration.d.ts +9 -3
- package/dist/esm/create-test-integration.js +31 -0
- package/dist/esm/create-test-integration.js.map +1 -1
- package/dist/esm/destination-kit/action.d.ts +68 -10
- package/dist/esm/destination-kit/action.js +286 -41
- package/dist/esm/destination-kit/action.js.map +1 -1
- package/dist/esm/destination-kit/index.d.ts +24 -5
- package/dist/esm/destination-kit/index.js +52 -18
- package/dist/esm/destination-kit/index.js.map +1 -1
- package/dist/esm/destination-kit/types.d.ts +0 -15
- package/dist/esm/destination-kit/types.js.map +1 -1
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +4 -5
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { StateContext, Destination, TransactionContext } from './destination-kit';
|
|
2
|
-
import type { DestinationDefinition, StatsContext, Logger, EngageDestinationCache, RequestFn, SubscriptionMetadata } from './destination-kit';
|
|
2
|
+
import type { DestinationDefinition, StatsContext, Logger, EngageDestinationCache, RequestFn, SubscriptionMetadata, PollPayload, PollResponse } from './destination-kit';
|
|
3
3
|
import type { JSONObject } from './json-object';
|
|
4
4
|
import type { SegmentEvent } from './segment-event';
|
|
5
5
|
import { AuthTokens } from './destination-kit/parse-settings';
|
|
6
6
|
import { Features } from './mapping-kit';
|
|
7
|
-
import { ExecuteDynamicFieldInput } from './destination-kit/action';
|
|
7
|
+
import { ExecuteDynamicFieldInput, AsyncBatchResponse } from './destination-kit/action';
|
|
8
8
|
import { DynamicFieldResponse, Result } from './destination-kit/types';
|
|
9
9
|
interface InputData<Settings> {
|
|
10
10
|
event?: Partial<SegmentEvent>;
|
|
@@ -24,11 +24,17 @@ declare class TestDestination<T, AudienceSettings = any> extends Destination<T,
|
|
|
24
24
|
responses: Destination['responses'];
|
|
25
25
|
results: Result[];
|
|
26
26
|
constructor(destination: DestinationDefinition<T>);
|
|
27
|
-
testDynamicField(action: string, fieldKey: string, data: ExecuteDynamicFieldInput<T, object>, dynamicFn?: RequestFn<any, any, DynamicFieldResponse, AudienceSettings>): Promise<
|
|
27
|
+
testDynamicField(action: string, fieldKey: string, data: ExecuteDynamicFieldInput<T, object>, dynamicFn?: RequestFn<any, any, DynamicFieldResponse, AudienceSettings>): Promise<DynamicFieldResponse>;
|
|
28
28
|
testAction(action: string, { event, mapping, settings, useDefaultMappings, auth, features, statsContext, logger, engageDestinationCache, transactionContext, stateContext, subscriptionMetadata }: InputData<T>): Promise<Destination['responses']>;
|
|
29
29
|
testBatchAction(action: string, { events, mapping, settings, useDefaultMappings, auth, features, statsContext, logger, engageDestinationCache, transactionContext, stateContext, subscriptionMetadata }: Omit<InputData<T>, 'event'> & {
|
|
30
30
|
events?: SegmentEvent[];
|
|
31
31
|
}): Promise<Destination['responses']>;
|
|
32
|
+
testAsyncBatchAction(action: string, { events, mapping, settings, auth, features, statsContext, logger, engageDestinationCache, transactionContext, stateContext, subscriptionMetadata }: Omit<InputData<T>, 'event'> & {
|
|
33
|
+
events?: SegmentEvent[];
|
|
34
|
+
}): Promise<AsyncBatchResponse>;
|
|
35
|
+
testAsyncPollAction(action: string, { pollPayload, settings, features, statsContext, logger, transactionContext, stateContext, subscriptionMetadata }: {
|
|
36
|
+
pollPayload: PollPayload;
|
|
37
|
+
} & Omit<InputData<T>, 'event' | 'mapping' | 'useDefaultMappings'>): Promise<PollResponse>;
|
|
32
38
|
}
|
|
33
39
|
export declare function createTestIntegration<T>(destination: DestinationDefinition<T>): TestDestination<T>;
|
|
34
40
|
export {};
|
|
@@ -72,6 +72,37 @@ class TestDestination extends destination_kit_1.Destination {
|
|
|
72
72
|
this.responses = [];
|
|
73
73
|
return responses;
|
|
74
74
|
}
|
|
75
|
+
async testAsyncBatchAction(action, { events, mapping, settings, auth, features, statsContext, logger, engageDestinationCache, transactionContext, stateContext, subscriptionMetadata }) {
|
|
76
|
+
mapping = mapping ?? {};
|
|
77
|
+
if (!events || !events.length) {
|
|
78
|
+
events = [{ type: 'track' }];
|
|
79
|
+
}
|
|
80
|
+
return await super.executeAsyncBatch(action, {
|
|
81
|
+
events: events.map((event) => (0, create_test_event_1.createTestEvent)(event)),
|
|
82
|
+
mapping,
|
|
83
|
+
settings: settings ?? {},
|
|
84
|
+
auth,
|
|
85
|
+
features: features ?? {},
|
|
86
|
+
statsContext: statsContext ?? {},
|
|
87
|
+
logger: logger ?? {},
|
|
88
|
+
engageDestinationCache: engageDestinationCache ?? {},
|
|
89
|
+
transactionContext: transactionContext ?? {},
|
|
90
|
+
stateContext: stateContext ?? {},
|
|
91
|
+
subscriptionMetadata: subscriptionMetadata ?? {}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
async testAsyncPollAction(action, { pollPayload, settings, features, statsContext, logger, transactionContext, stateContext, subscriptionMetadata }) {
|
|
95
|
+
return super.executeAsyncPoll(action, {
|
|
96
|
+
pollPayload,
|
|
97
|
+
settings: settings ?? {},
|
|
98
|
+
features: features ?? {},
|
|
99
|
+
statsContext: statsContext ?? {},
|
|
100
|
+
logger: logger ?? {},
|
|
101
|
+
transactionContext: transactionContext ?? {},
|
|
102
|
+
stateContext: stateContext ?? {},
|
|
103
|
+
subscriptionMetadata: subscriptionMetadata ?? {}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
75
106
|
}
|
|
76
107
|
function createTestIntegration(destination) {
|
|
77
108
|
return new TestDestination(destination);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-test-integration.js","sourceRoot":"","sources":["../../src/create-test-integration.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"create-test-integration.js","sourceRoot":"","sources":["../../src/create-test-integration.ts"],"names":[],"mappings":";;AAoPA,sDAEC;AAtPD,2DAAqD;AACrD,uDAAiF;AACjF,6CAAwC;AAmBxC,MAAM,IAAI,GAAG,GAAG,EAAE,GAAE,CAAC,CAAA;AAwCrB,MAAM,eAA2C,SAAQ,6BAAgC;IAIvF,YAAY,WAAqC;QAC/C,KAAK,CAAC,WAAW,CAAC,CAAA;QAJpB,cAAS,GAA6B,EAAE,CAAA;QACxC,YAAO,GAAa,EAAE,CAAA;IAItB,CAAC;IAED,KAAK,CAAC,gBAAgB,CACpB,MAAc,EACd,QAAgB,EAChB,IAAyC,EACzC,SAAuE;QAEvE,OAAO,MAAM,KAAK,CAAC,mBAAmB,CAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,CAAC,CAAA;IAC3E,CAAC;IAGD,KAAK,CAAC,UAAU,CACd,MAAc,EACd,EACE,KAAK,EACL,OAAO,EACP,QAAQ,EACR,kBAAkB,EAClB,IAAI,EACJ,QAAQ,EACR,YAAY,EACZ,MAAM,EACN,sBAAsB,EACtB,kBAAkB,EAClB,YAAY,EACZ,oBAAoB,EACP;QAEf,IAAI,CAAC,OAAO,GAAG,EAAE,CAAA;QACjB,OAAO,GAAG,OAAO,IAAI,EAAE,CAAA;QAEvB,IAAI,kBAAkB,EAAE,CAAC;YACvB,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,CAAA;YACrD,MAAM,eAAe,GAA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AAI,eAAe,CAAC,WAAW,CAAC,CAAA;AACzC,CAAC"}
|
|
@@ -2,7 +2,7 @@ import { EventEmitter } from 'events';
|
|
|
2
2
|
import createRequestClient from '../create-request-client';
|
|
3
3
|
import { JSONLikeObject, JSONObject } from '../json-object';
|
|
4
4
|
import { InputData, Features } from '../mapping-kit';
|
|
5
|
-
import type { DynamicFieldResponse, InputField, RequestExtension, ExecuteInput, Result, SyncModeDefinition, DynamicFieldContext, ActionDestinationSuccessResponseType, ActionDestinationErrorResponseType, ResultMultiStatusNode, AudienceMembership
|
|
5
|
+
import type { DynamicFieldResponse, InputField, RequestExtension, ExecuteInput, Result, SyncModeDefinition, DynamicFieldContext, ActionDestinationSuccessResponseType, ActionDestinationErrorResponseType, ResultMultiStatusNode, AudienceMembership } from './types';
|
|
6
6
|
import type { JSONSchema4 } from 'json-schema';
|
|
7
7
|
import { AuthTokens } from './parse-settings';
|
|
8
8
|
import { Logger, StatsContext, Personas, TransactionContext, StateContext, EngageDestinationCache, SubscriptionMetadata } from './index';
|
|
@@ -28,13 +28,26 @@ export interface BaseActionDefinition {
|
|
|
28
28
|
defaultSubscription?: string;
|
|
29
29
|
hidden?: boolean;
|
|
30
30
|
fields: ActionFields;
|
|
31
|
-
pollFields?: ActionFields;
|
|
32
31
|
}
|
|
33
32
|
type HookValueTypes = string | boolean | number | Array<string | boolean | number>;
|
|
34
33
|
type GenericActionHookValues = Record<string, HookValueTypes>;
|
|
35
34
|
type IsArray<T> = T extends (infer U)[] ? U : never;
|
|
36
35
|
type PerformBatchResponse = MaybePromise<MultiStatusResponse> | MaybePromise<unknown>;
|
|
37
|
-
export
|
|
36
|
+
export type AsyncBatchResponse = {
|
|
37
|
+
jobId?: string;
|
|
38
|
+
status: number;
|
|
39
|
+
multiStatusResponse: MultiStatusResponse;
|
|
40
|
+
};
|
|
41
|
+
export type PollPayload = {
|
|
42
|
+
jobId: string;
|
|
43
|
+
};
|
|
44
|
+
export type PollResponse = {
|
|
45
|
+
jobId: string;
|
|
46
|
+
status: number;
|
|
47
|
+
pollStatus: 'IN_PROGRESS' | 'COMPLETED' | 'FAILED' | 'ERROR';
|
|
48
|
+
multiStatusResponse?: MultiStatusResponse;
|
|
49
|
+
};
|
|
50
|
+
export interface ActionDefinition<Settings, Payload = any, AudienceSettings = any, GeneratedActionHookInputs = any, GeneratedActionHookOutputs = any> extends BaseActionDefinition {
|
|
38
51
|
dynamicFields?: {
|
|
39
52
|
[K in keyof Payload]?: IsArray<Payload[K]> extends never ? Payload[K] extends object | undefined ? {
|
|
40
53
|
[ObjectProperty in keyof NonNullable<Payload[K]> | '__keys__' | '__values__']?: RequestFn<Settings, Payload, DynamicFieldResponse, AudienceSettings>;
|
|
@@ -44,7 +57,21 @@ export interface ActionDefinition<Settings, Payload = any, AudienceSettings = an
|
|
|
44
57
|
};
|
|
45
58
|
perform: RequestFn<Settings, Payload, any, AudienceSettings, any, AudienceMembership>;
|
|
46
59
|
performBatch?: RequestFn<Settings, Payload[], PerformBatchResponse, AudienceSettings, any, AudienceMembership[]>;
|
|
47
|
-
|
|
60
|
+
hooks?: {
|
|
61
|
+
[K in ActionHookType]?: ActionHookDefinition<Settings, Payload, AudienceSettings, NonNullable<GeneratedActionHookInputs>, NonNullable<GeneratedActionHookOutputs>>;
|
|
62
|
+
};
|
|
63
|
+
syncMode?: SyncModeDefinition;
|
|
64
|
+
}
|
|
65
|
+
export interface AsyncActionDefinition<Settings, Payload = any, AudienceSettings = any, GeneratedActionHookInputs = any, GeneratedActionHookOutputs = any> extends BaseActionDefinition {
|
|
66
|
+
dynamicFields?: {
|
|
67
|
+
[K in keyof Payload]?: IsArray<Payload[K]> extends never ? Payload[K] extends object | undefined ? {
|
|
68
|
+
[ObjectProperty in keyof NonNullable<Payload[K]> | '__keys__' | '__values__']?: RequestFn<Settings, Payload, DynamicFieldResponse, AudienceSettings>;
|
|
69
|
+
} : RequestFn<Settings, Payload, DynamicFieldResponse, AudienceSettings> : IsArray<Payload[K]> extends object ? {
|
|
70
|
+
[ObjectProperty in keyof NonNullable<IsArray<Payload[K]>> | '__keys__' | '__values__']?: RequestFn<Settings, Payload, DynamicFieldResponse, AudienceSettings>;
|
|
71
|
+
} : never;
|
|
72
|
+
};
|
|
73
|
+
performBatch: RequestFn<Settings, Payload[], AsyncBatchResponse, AudienceSettings, any, AudienceMembership[]>;
|
|
74
|
+
performPoll: RequestFn<Settings, PollPayload, PollResponse, AudienceSettings>;
|
|
48
75
|
hooks?: {
|
|
49
76
|
[K in ActionHookType]?: ActionHookDefinition<Settings, Payload, AudienceSettings, NonNullable<GeneratedActionHookInputs>, NonNullable<GeneratedActionHookOutputs>>;
|
|
50
77
|
};
|
|
@@ -102,20 +129,29 @@ interface ExecuteBundle<T = unknown, Data = unknown, AudienceSettings = any, Act
|
|
|
102
129
|
subscriptionMetadata?: SubscriptionMetadata;
|
|
103
130
|
signal?: AbortSignal;
|
|
104
131
|
}
|
|
105
|
-
|
|
106
|
-
|
|
132
|
+
interface PollBundle<T = unknown> {
|
|
133
|
+
data: PollPayload;
|
|
134
|
+
settings: T;
|
|
135
|
+
auth: AuthTokens | undefined;
|
|
136
|
+
features?: Features | undefined;
|
|
137
|
+
statsContext?: StatsContext | undefined;
|
|
138
|
+
logger?: Logger | undefined;
|
|
139
|
+
transactionContext?: TransactionContext;
|
|
140
|
+
stateContext?: StateContext;
|
|
141
|
+
subscriptionMetadata?: SubscriptionMetadata;
|
|
142
|
+
signal?: AbortSignal;
|
|
143
|
+
}
|
|
144
|
+
export declare class Action<Settings, Payload extends JSONLikeObject, AudienceSettings = any> extends EventEmitter {
|
|
145
|
+
readonly definition: ActionDefinition<Settings, Payload, AudienceSettings, unknown, unknown>;
|
|
107
146
|
readonly destinationName: string;
|
|
108
147
|
readonly schema?: JSONSchema4;
|
|
109
|
-
readonly pollSchema?: JSONSchema4;
|
|
110
148
|
readonly hookSchemas?: Record<string, JSONSchema4>;
|
|
111
149
|
readonly hasBatchSupport: boolean;
|
|
112
150
|
readonly hasHookSupport: boolean;
|
|
113
|
-
readonly hasPollSupport: boolean;
|
|
114
151
|
private extendRequest;
|
|
115
|
-
constructor(destinationName: string, definition: ActionDefinition<Settings, Payload, AudienceSettings, unknown, unknown
|
|
152
|
+
constructor(destinationName: string, definition: ActionDefinition<Settings, Payload, AudienceSettings, unknown, unknown>, extendRequest?: RequestExtension<Settings, any>);
|
|
116
153
|
execute(bundle: ExecuteBundle<Settings, InputData | undefined, AudienceSettings>): Promise<Result[]>;
|
|
117
154
|
executeBatch(bundle: ExecuteBundle<Settings, InputData[], AudienceSettings>): Promise<ResultMultiStatusNode[]>;
|
|
118
|
-
executePoll(bundle: ExecuteBundle<Settings, InputData | undefined, AudienceSettings>): Promise<AsyncPollResponseType>;
|
|
119
155
|
private extractFieldContextAndHandler;
|
|
120
156
|
executeDynamicField(field: string, data: ExecuteDynamicFieldInput<Settings, Payload, AudienceSettings>, dynamicFn?: RequestFn<Settings, Payload, DynamicFieldResponse, AudienceSettings>): Promise<DynamicFieldResponse>;
|
|
121
157
|
executeHook(hookType: ActionHookType, data: ExecuteInput<Settings, Payload, AudienceSettings>): Promise<ActionHookResponse<any>>;
|
|
@@ -135,6 +171,26 @@ export declare class ActionDestinationErrorResponse {
|
|
|
135
171
|
constructor(data: ActionDestinationErrorResponseType);
|
|
136
172
|
value(): ActionDestinationErrorResponseType;
|
|
137
173
|
}
|
|
174
|
+
export declare class AsyncAction<Settings, Payload extends JSONLikeObject, AudienceSettings = any> extends EventEmitter {
|
|
175
|
+
readonly definition: AsyncActionDefinition<Settings, Payload, AudienceSettings, unknown, unknown>;
|
|
176
|
+
readonly destinationName: string;
|
|
177
|
+
readonly schema?: JSONSchema4;
|
|
178
|
+
readonly hookSchemas?: Record<string, JSONSchema4>;
|
|
179
|
+
readonly hasHookSupport: boolean;
|
|
180
|
+
private extendRequest;
|
|
181
|
+
constructor(destinationName: string, definition: AsyncActionDefinition<Settings, Payload, AudienceSettings, unknown, unknown>, extendRequest?: RequestExtension<Settings, any>);
|
|
182
|
+
executeBatch(bundle: ExecuteBundle<Settings, InputData[], AudienceSettings>): Promise<AsyncBatchResponse>;
|
|
183
|
+
executePoll(bundle: PollBundle<Settings>): Promise<PollResponse>;
|
|
184
|
+
private extractFieldContextAndHandler;
|
|
185
|
+
executeDynamicField(field: string, data: ExecuteDynamicFieldInput<Settings, Payload, AudienceSettings>, dynamicFn?: RequestFn<Settings, Payload, DynamicFieldResponse, AudienceSettings>): Promise<DynamicFieldResponse>;
|
|
186
|
+
executeHook(hookType: ActionHookType, data: ExecuteInput<Settings, Payload, AudienceSettings>): Promise<ActionHookResponse<any>>;
|
|
187
|
+
private performRequest;
|
|
188
|
+
private createRequestClient;
|
|
189
|
+
private afterResponse;
|
|
190
|
+
private parseResponse;
|
|
191
|
+
private parseBatchError;
|
|
192
|
+
private fillMultiStatusWithErrorResponse;
|
|
193
|
+
}
|
|
138
194
|
export declare class MultiStatusResponse {
|
|
139
195
|
private responses;
|
|
140
196
|
length(): number;
|
|
@@ -149,5 +205,7 @@ export declare class MultiStatusResponse {
|
|
|
149
205
|
isErrorResponseAtIndex(index: number): boolean;
|
|
150
206
|
getResponseAtIndex(index: number): ActionDestinationSuccessResponse | ActionDestinationErrorResponse;
|
|
151
207
|
getAllResponses(): (ActionDestinationSuccessResponse | ActionDestinationErrorResponse)[];
|
|
208
|
+
get successCount(): number;
|
|
209
|
+
get errorCount(): number;
|
|
152
210
|
}
|
|
153
211
|
export {};
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.MultiStatusResponse = exports.ActionDestinationErrorResponse = exports.ActionDestinationSuccessResponse = exports.Action = exports.hookTypeStrings = void 0;
|
|
6
|
+
exports.MultiStatusResponse = exports.AsyncAction = exports.ActionDestinationErrorResponse = exports.ActionDestinationSuccessResponse = exports.Action = exports.hookTypeStrings = void 0;
|
|
7
7
|
const events_1 = require("events");
|
|
8
8
|
const create_request_client_1 = __importDefault(require("../create-request-client"));
|
|
9
9
|
const mapping_kit_1 = require("../mapping-kit");
|
|
@@ -28,13 +28,9 @@ class Action extends events_1.EventEmitter {
|
|
|
28
28
|
this.extendRequest = extendRequest;
|
|
29
29
|
this.hasBatchSupport = typeof definition.performBatch === 'function';
|
|
30
30
|
this.hasHookSupport = definition.hooks !== undefined;
|
|
31
|
-
this.hasPollSupport = typeof definition.pollStatus === 'function';
|
|
32
31
|
if (Object.keys(definition.fields ?? {}).length) {
|
|
33
32
|
this.schema = (0, fields_to_jsonschema_1.fieldsToJsonSchema)(definition.fields);
|
|
34
33
|
}
|
|
35
|
-
if (Object.keys(definition.pollFields ?? {}).length) {
|
|
36
|
-
this.pollSchema = (0, fields_to_jsonschema_1.fieldsToJsonSchema)(definition.pollFields);
|
|
37
|
-
}
|
|
38
34
|
if (definition.hooks) {
|
|
39
35
|
for (const hookName in definition.hooks) {
|
|
40
36
|
const hook = definition.hooks[hookName];
|
|
@@ -265,42 +261,6 @@ class Action extends events_1.EventEmitter {
|
|
|
265
261
|
}
|
|
266
262
|
return multiStatusResponse;
|
|
267
263
|
}
|
|
268
|
-
async executePoll(bundle) {
|
|
269
|
-
if (!this.hasPollSupport || !this.definition.pollStatus) {
|
|
270
|
-
throw new errors_1.IntegrationError('This action does not support polling.', 'NotImplemented', 501);
|
|
271
|
-
}
|
|
272
|
-
const payload = bundle.data;
|
|
273
|
-
if (!this.pollSchema) {
|
|
274
|
-
throw new errors_1.IntegrationError('Poll fields must be defined for polling operations.', 'NotImplemented', 501);
|
|
275
|
-
}
|
|
276
|
-
const validationSchema = this.pollSchema;
|
|
277
|
-
const pollPayload = (0, remove_empty_values_1.removeEmptyValues)(payload, validationSchema, true);
|
|
278
|
-
const schemaKey = `${this.destinationName}:${this.definition.title}:poll`;
|
|
279
|
-
(0, schema_validation_1.validateSchema)(pollPayload, validationSchema, {
|
|
280
|
-
schemaKey,
|
|
281
|
-
statsContext: bundle.statsContext,
|
|
282
|
-
exempt: ['dynamicAuthSettings']
|
|
283
|
-
});
|
|
284
|
-
const dataBundle = {
|
|
285
|
-
rawData: bundle.data,
|
|
286
|
-
rawMapping: bundle.mapping,
|
|
287
|
-
settings: bundle.settings,
|
|
288
|
-
payload: pollPayload,
|
|
289
|
-
auth: bundle.auth,
|
|
290
|
-
features: bundle.features,
|
|
291
|
-
statsContext: bundle.statsContext,
|
|
292
|
-
logger: bundle.logger,
|
|
293
|
-
engageDestinationCache: bundle.engageDestinationCache,
|
|
294
|
-
transactionContext: bundle.transactionContext,
|
|
295
|
-
stateContext: bundle.stateContext,
|
|
296
|
-
audienceSettings: bundle.audienceSettings,
|
|
297
|
-
subscriptionMetadata: bundle.subscriptionMetadata,
|
|
298
|
-
signal: bundle?.signal
|
|
299
|
-
};
|
|
300
|
-
const requestClient = this.createRequestClient(dataBundle);
|
|
301
|
-
const pollResponse = await this.definition.pollStatus(requestClient, dataBundle);
|
|
302
|
-
return pollResponse;
|
|
303
|
-
}
|
|
304
264
|
extractFieldContextAndHandler(field) {
|
|
305
265
|
const arrayRegex = /(.*)\.\[(\d+)\]\.(.*)/;
|
|
306
266
|
const objectRegex = /(.*)\.(.*)/;
|
|
@@ -420,6 +380,286 @@ class ActionDestinationErrorResponse {
|
|
|
420
380
|
}
|
|
421
381
|
}
|
|
422
382
|
exports.ActionDestinationErrorResponse = ActionDestinationErrorResponse;
|
|
383
|
+
class AsyncAction extends events_1.EventEmitter {
|
|
384
|
+
constructor(destinationName, definition, extendRequest) {
|
|
385
|
+
super();
|
|
386
|
+
this.definition = definition;
|
|
387
|
+
this.destinationName = destinationName;
|
|
388
|
+
this.extendRequest = extendRequest;
|
|
389
|
+
this.hasHookSupport = definition.hooks !== undefined;
|
|
390
|
+
if (Object.keys(definition.fields ?? {}).length) {
|
|
391
|
+
this.schema = (0, fields_to_jsonschema_1.fieldsToJsonSchema)(definition.fields);
|
|
392
|
+
}
|
|
393
|
+
if (definition.hooks) {
|
|
394
|
+
for (const hookName in definition.hooks) {
|
|
395
|
+
const hook = definition.hooks[hookName];
|
|
396
|
+
if (hook?.inputFields) {
|
|
397
|
+
if (!this.hookSchemas) {
|
|
398
|
+
this.hookSchemas = {};
|
|
399
|
+
}
|
|
400
|
+
const castedInputFields = {};
|
|
401
|
+
for (const key in hook.inputFields) {
|
|
402
|
+
const field = hook.inputFields[key];
|
|
403
|
+
if (field.dynamic) {
|
|
404
|
+
castedInputFields[key] = {
|
|
405
|
+
...field,
|
|
406
|
+
dynamic: true
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
else {
|
|
410
|
+
castedInputFields[key] = {
|
|
411
|
+
...field,
|
|
412
|
+
dynamic: false
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
this.hookSchemas[hookName] = (0, fields_to_jsonschema_1.fieldsToJsonSchema)(castedInputFields);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
async executeBatch(bundle) {
|
|
422
|
+
const mapping = bundle.mapping;
|
|
423
|
+
let payloads = (0, mapping_kit_1.transformBatch)(mapping, bundle.data, bundle.statsContext);
|
|
424
|
+
const batchPayloadLength = payloads.length;
|
|
425
|
+
const multiStatusResponse = new MultiStatusResponse();
|
|
426
|
+
const invalidPayloadIndices = new Set();
|
|
427
|
+
if (this.schema) {
|
|
428
|
+
const schema = this.schema;
|
|
429
|
+
const validationOptions = {
|
|
430
|
+
schemaKey: `${this.destinationName}:${this.definition.title}`,
|
|
431
|
+
throwIfInvalid: true,
|
|
432
|
+
statsContext: bundle.statsContext,
|
|
433
|
+
exempt: ['dynamicAuthSettings']
|
|
434
|
+
};
|
|
435
|
+
{
|
|
436
|
+
const filteredPayload = [];
|
|
437
|
+
for (let i = 0; i < payloads.length; i++) {
|
|
438
|
+
const payload = (0, remove_empty_values_1.removeEmptyValues)(payloads[i], schema);
|
|
439
|
+
try {
|
|
440
|
+
(0, schema_validation_1.validateSchema)(payload, schema, validationOptions);
|
|
441
|
+
}
|
|
442
|
+
catch (e) {
|
|
443
|
+
multiStatusResponse.setErrorResponseAtIndex(i, {
|
|
444
|
+
status: 400,
|
|
445
|
+
errortype: errors_1.ErrorCodes.PAYLOAD_VALIDATION_FAILED,
|
|
446
|
+
errormessage: e.message
|
|
447
|
+
});
|
|
448
|
+
invalidPayloadIndices.add(i);
|
|
449
|
+
bundle.statsContext?.statsClient?.incr('action.multistatus_discard', 1, bundle.statsContext?.tags);
|
|
450
|
+
continue;
|
|
451
|
+
}
|
|
452
|
+
filteredPayload.push(payload);
|
|
453
|
+
}
|
|
454
|
+
payloads = filteredPayload;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
let hookOutputs = {};
|
|
458
|
+
if (this.definition.hooks) {
|
|
459
|
+
for (const hookType in this.definition.hooks) {
|
|
460
|
+
const hookOutputValues = bundle.mapping?.[hookType];
|
|
461
|
+
if (hookOutputValues) {
|
|
462
|
+
hookOutputs = { ...hookOutputs, [hookType]: hookOutputValues };
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
if (payloads.length === 0) {
|
|
467
|
+
return { jobId: undefined, status: 200, multiStatusResponse };
|
|
468
|
+
}
|
|
469
|
+
const syncModeVal = this.definition.syncMode ? bundle.mapping?.['__segment_internal_sync_mode'] : undefined;
|
|
470
|
+
const syncMode = isSyncMode(syncModeVal) ? syncModeVal : undefined;
|
|
471
|
+
const matchingKey = bundle.mapping?.['__segment_internal_matching_key'];
|
|
472
|
+
const audienceMembership = bundle.data.map((d) => (0, audience_membership_1.resolveAudienceMembership)(d, syncMode));
|
|
473
|
+
const data = {
|
|
474
|
+
rawData: bundle.data,
|
|
475
|
+
rawMapping: bundle.mapping,
|
|
476
|
+
settings: bundle.settings,
|
|
477
|
+
audienceSettings: bundle.audienceSettings,
|
|
478
|
+
payload: payloads,
|
|
479
|
+
audienceMembership,
|
|
480
|
+
auth: bundle.auth,
|
|
481
|
+
features: bundle.features,
|
|
482
|
+
statsContext: bundle.statsContext,
|
|
483
|
+
logger: bundle.logger,
|
|
484
|
+
engageDestinationCache: bundle.engageDestinationCache,
|
|
485
|
+
transactionContext: bundle.transactionContext,
|
|
486
|
+
stateContext: bundle.stateContext,
|
|
487
|
+
subscriptionMetadata: bundle.subscriptionMetadata,
|
|
488
|
+
hookOutputs,
|
|
489
|
+
syncMode,
|
|
490
|
+
matchingKey: matchingKey ? String(matchingKey) : undefined,
|
|
491
|
+
signal: bundle?.signal
|
|
492
|
+
};
|
|
493
|
+
const requestClient = this.createRequestClient(data);
|
|
494
|
+
let performBatchResponse;
|
|
495
|
+
try {
|
|
496
|
+
performBatchResponse = await this.definition.performBatch(requestClient, data);
|
|
497
|
+
}
|
|
498
|
+
catch (error) {
|
|
499
|
+
this.parseBatchError(error, {
|
|
500
|
+
multiStatusResponse,
|
|
501
|
+
invalidPayloadIndices,
|
|
502
|
+
batchPayloadLength,
|
|
503
|
+
filteredPayloads: payloads
|
|
504
|
+
});
|
|
505
|
+
const errorStatus = error?.response?.status ?? error?.status ?? 500;
|
|
506
|
+
return { jobId: undefined, status: errorStatus, multiStatusResponse };
|
|
507
|
+
}
|
|
508
|
+
const { jobId, status, multiStatusResponse: batchMultiStatus } = performBatchResponse;
|
|
509
|
+
let resultsReadIndex = 0;
|
|
510
|
+
for (let i = 0; i < batchPayloadLength; i++) {
|
|
511
|
+
if (invalidPayloadIndices.has(i)) {
|
|
512
|
+
continue;
|
|
513
|
+
}
|
|
514
|
+
const response = batchMultiStatus.getResponseAtIndex(resultsReadIndex++);
|
|
515
|
+
if (!response) {
|
|
516
|
+
multiStatusResponse.setErrorResponseAtIndex(i, {
|
|
517
|
+
status: 500,
|
|
518
|
+
errormessage: 'MultiStatusResponse is missing a response at the specified index',
|
|
519
|
+
errortype: errors_1.ErrorCodes.PAYLOAD_VALIDATION_FAILED
|
|
520
|
+
});
|
|
521
|
+
bundle.statsContext?.statsClient?.incr('action.multistatus_discard', 1, bundle.statsContext?.tags);
|
|
522
|
+
continue;
|
|
523
|
+
}
|
|
524
|
+
if (response instanceof ActionDestinationErrorResponse) {
|
|
525
|
+
multiStatusResponse.setErrorResponseAtIndex(i, response.value());
|
|
526
|
+
bundle.statsContext?.statsClient?.incr('destination.multistatus_discard', 1, bundle.statsContext?.tags);
|
|
527
|
+
continue;
|
|
528
|
+
}
|
|
529
|
+
multiStatusResponse.setSuccessResponseAtIndex(i, response.value());
|
|
530
|
+
}
|
|
531
|
+
return { jobId, status, multiStatusResponse };
|
|
532
|
+
}
|
|
533
|
+
async executePoll(bundle) {
|
|
534
|
+
const dataBundle = {
|
|
535
|
+
rawData: bundle.data,
|
|
536
|
+
settings: bundle.settings,
|
|
537
|
+
payload: bundle.data,
|
|
538
|
+
auth: bundle.auth,
|
|
539
|
+
features: bundle.features,
|
|
540
|
+
statsContext: bundle.statsContext,
|
|
541
|
+
logger: bundle.logger,
|
|
542
|
+
transactionContext: bundle.transactionContext,
|
|
543
|
+
stateContext: bundle.stateContext,
|
|
544
|
+
subscriptionMetadata: bundle.subscriptionMetadata,
|
|
545
|
+
signal: bundle?.signal
|
|
546
|
+
};
|
|
547
|
+
const requestClient = this.createRequestClient(dataBundle);
|
|
548
|
+
return this.definition.performPoll(requestClient, dataBundle);
|
|
549
|
+
}
|
|
550
|
+
extractFieldContextAndHandler(field) {
|
|
551
|
+
const arrayRegex = /(.*)\.\[(\d+)\]\.(.*)/;
|
|
552
|
+
const objectRegex = /(.*)\.(.*)/;
|
|
553
|
+
let dynamicHandlerPath = field;
|
|
554
|
+
let dynamicFieldContext;
|
|
555
|
+
const match = arrayRegex.exec(field) || objectRegex.exec(field);
|
|
556
|
+
if (match) {
|
|
557
|
+
const [, parent, indexOrChild, child] = match;
|
|
558
|
+
if (child) {
|
|
559
|
+
dynamicFieldContext = { selectedArrayIndex: parseInt(indexOrChild, 10) };
|
|
560
|
+
dynamicHandlerPath = `${parent}.${child}`;
|
|
561
|
+
}
|
|
562
|
+
else {
|
|
563
|
+
const parentFetcher = this.definition.dynamicFields?.[parent];
|
|
564
|
+
if (parentFetcher && !(indexOrChild in parentFetcher)) {
|
|
565
|
+
dynamicHandlerPath = `${parent}.__values__`;
|
|
566
|
+
dynamicFieldContext = { selectedKey: indexOrChild };
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
return { dynamicHandlerPath, dynamicFieldContext };
|
|
571
|
+
}
|
|
572
|
+
async executeDynamicField(field, data, dynamicFn) {
|
|
573
|
+
if (dynamicFn && typeof dynamicFn === 'function') {
|
|
574
|
+
return (await this.performRequest(dynamicFn, { ...data }));
|
|
575
|
+
}
|
|
576
|
+
const { dynamicHandlerPath, dynamicFieldContext } = this.extractFieldContextAndHandler(field);
|
|
577
|
+
const fn = (0, get_1.get)(this.definition.dynamicFields, dynamicHandlerPath);
|
|
578
|
+
if (typeof fn !== 'function') {
|
|
579
|
+
return Promise.resolve({
|
|
580
|
+
choices: [],
|
|
581
|
+
nextPage: '',
|
|
582
|
+
error: {
|
|
583
|
+
message: `No dynamic field named ${field} found.`,
|
|
584
|
+
code: '404'
|
|
585
|
+
}
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
return (await this.performRequest(fn, { ...data, dynamicFieldContext }));
|
|
589
|
+
}
|
|
590
|
+
async executeHook(hookType, data) {
|
|
591
|
+
if (!this.hasHookSupport) {
|
|
592
|
+
throw new errors_1.IntegrationError('This action does not support any hooks.', 'NotImplemented', 501);
|
|
593
|
+
}
|
|
594
|
+
const hookFn = this.definition.hooks?.[hookType]?.performHook;
|
|
595
|
+
if (!hookFn) {
|
|
596
|
+
throw new errors_1.IntegrationError(`Missing implementation for hook: ${hookType}.`, 'NotImplemented', 501);
|
|
597
|
+
}
|
|
598
|
+
if (this.hookSchemas?.[hookType]) {
|
|
599
|
+
const schema = this.hookSchemas[hookType];
|
|
600
|
+
(0, schema_validation_1.validateSchema)(data.hookInputs, schema, {
|
|
601
|
+
exempt: ['dynamicAuthSettings']
|
|
602
|
+
});
|
|
603
|
+
}
|
|
604
|
+
return (await this.performRequest(hookFn, data));
|
|
605
|
+
}
|
|
606
|
+
async performRequest(requestFn, data) {
|
|
607
|
+
const requestClient = this.createRequestClient(data);
|
|
608
|
+
const response = await requestFn(requestClient, data);
|
|
609
|
+
return this.parseResponse(response);
|
|
610
|
+
}
|
|
611
|
+
createRequestClient(data) {
|
|
612
|
+
const options = this.extendRequest?.(data) ?? {};
|
|
613
|
+
return (0, create_request_client_1.default)(options, {
|
|
614
|
+
afterResponse: [this.afterResponse.bind(this)],
|
|
615
|
+
statsContext: data.statsContext,
|
|
616
|
+
signal: data?.signal
|
|
617
|
+
});
|
|
618
|
+
}
|
|
619
|
+
afterResponse(request, options, response) {
|
|
620
|
+
const modifiedResponse = response;
|
|
621
|
+
modifiedResponse.request = request;
|
|
622
|
+
modifiedResponse.options = options;
|
|
623
|
+
this.emit('response', modifiedResponse);
|
|
624
|
+
return modifiedResponse;
|
|
625
|
+
}
|
|
626
|
+
parseResponse(response) {
|
|
627
|
+
if (response instanceof fetch_1.Response) {
|
|
628
|
+
return response.data ?? response.content;
|
|
629
|
+
}
|
|
630
|
+
return response;
|
|
631
|
+
}
|
|
632
|
+
parseBatchError(error, input) {
|
|
633
|
+
if (error instanceof request_client_1.HTTPError) {
|
|
634
|
+
this.fillMultiStatusWithErrorResponse({ ...input, status: error.response.status, errormessage: error.message });
|
|
635
|
+
return;
|
|
636
|
+
}
|
|
637
|
+
if (error instanceof errors_1.IntegrationError) {
|
|
638
|
+
this.fillMultiStatusWithErrorResponse({ ...input, status: error.status ?? 400, errormessage: error.message });
|
|
639
|
+
return;
|
|
640
|
+
}
|
|
641
|
+
if (error instanceof errors_1.RetryableError || error instanceof errors_1.InvalidAuthenticationError) {
|
|
642
|
+
this.fillMultiStatusWithErrorResponse({ ...input, status: error.status, errormessage: error.message });
|
|
643
|
+
return;
|
|
644
|
+
}
|
|
645
|
+
throw error;
|
|
646
|
+
}
|
|
647
|
+
fillMultiStatusWithErrorResponse(input) {
|
|
648
|
+
const { multiStatusResponse, batchPayloadLength, status, errormessage, filteredPayloads } = input;
|
|
649
|
+
let payloadReadIndex = 0;
|
|
650
|
+
for (let i = 0; i < batchPayloadLength; i++) {
|
|
651
|
+
if (input.invalidPayloadIndices.has(i)) {
|
|
652
|
+
continue;
|
|
653
|
+
}
|
|
654
|
+
multiStatusResponse.setErrorResponseAtIndex(i, {
|
|
655
|
+
status,
|
|
656
|
+
errormessage,
|
|
657
|
+
sent: filteredPayloads ? filteredPayloads[payloadReadIndex++] : {}
|
|
658
|
+
});
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
exports.AsyncAction = AsyncAction;
|
|
423
663
|
class MultiStatusResponse {
|
|
424
664
|
constructor() {
|
|
425
665
|
this.responses = [];
|
|
@@ -480,6 +720,12 @@ class MultiStatusResponse {
|
|
|
480
720
|
getAllResponses() {
|
|
481
721
|
return this.responses;
|
|
482
722
|
}
|
|
723
|
+
get successCount() {
|
|
724
|
+
return this.responses.filter((r) => r instanceof ActionDestinationSuccessResponse).length;
|
|
725
|
+
}
|
|
726
|
+
get errorCount() {
|
|
727
|
+
return this.responses.filter((r) => r instanceof ActionDestinationErrorResponse).length;
|
|
728
|
+
}
|
|
483
729
|
}
|
|
484
730
|
exports.MultiStatusResponse = MultiStatusResponse;
|
|
485
731
|
//# sourceMappingURL=action.js.map
|