@segment/actions-core 3.168.1-staging-550687e79.0 → 3.168.1-staging-28f91b239.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/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 +70 -10
- package/dist/cjs/destination-kit/action.js +290 -42
- package/dist/cjs/destination-kit/action.js.map +1 -1
- package/dist/cjs/destination-kit/event-emitter-types.d.ts +1 -0
- package/dist/cjs/destination-kit/event-emitter-types.js +3 -0
- package/dist/cjs/destination-kit/event-emitter-types.js.map +1 -0
- package/dist/cjs/destination-kit/index.d.ts +28 -8
- package/dist/cjs/destination-kit/index.js +53 -18
- 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/errors.d.ts +5 -0
- package/dist/cjs/errors.js +8 -1
- package/dist/cjs/errors.js.map +1 -1
- package/dist/cjs/index.d.ts +3 -3
- package/dist/cjs/index.js +3 -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 +70 -10
- package/dist/esm/destination-kit/action.js +289 -42
- package/dist/esm/destination-kit/action.js.map +1 -1
- package/dist/esm/destination-kit/event-emitter-types.d.ts +1 -0
- package/dist/esm/destination-kit/event-emitter-types.js +2 -0
- package/dist/esm/destination-kit/event-emitter-types.js.map +1 -0
- package/dist/esm/destination-kit/index.d.ts +28 -8
- package/dist/esm/destination-kit/index.js +54 -19
- 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/errors.d.ts +5 -0
- package/dist/esm/errors.js +6 -0
- package/dist/esm/errors.js.map +1 -1
- package/dist/esm/index.d.ts +3 -3
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +3 -4
|
@@ -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;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oBAAoB,EAC0E;QAEhG,OAAO,KAAK,CAAC,gBAAgB,CAAC,MAAM,EAAE;YACpC,WAAW;YACX,QAAQ,EAAE,QAAQ,IAAK,EAAQ;YAC/B,QAAQ,EAAE,QAAQ,IAAI,EAAE;YACxB,YAAY,EAAE,YAAY,IAAK,EAAmB;YAClD,MAAM,EAAE,MAAM,IAAK,EAAa;YAChC,kBAAkB,EAAE,kBAAkB,IAAK,EAAyB;YACpE,YAAY,EAAE,YAAY,IAAK,EAAmB;YAClD,oBAAoB,EAAE,oBAAoB,IAAK,EAA2B;SAC3E,CAAC,CAAA;IACJ,CAAC;CACF;AAED,SAAgB,qBAAqB,CAAI,WAAqC;IAC5E,OAAO,IAAI,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,28 @@ 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
|
-
|
|
36
|
+
type PollJobStatus = 'IN_PROGRESS' | 'SUCCEEDED' | 'FAILED' | 'RETRYABLE_ERROR';
|
|
37
|
+
export type AsyncBatchResponse = {
|
|
38
|
+
jobId?: string;
|
|
39
|
+
status: number;
|
|
40
|
+
multiStatusResponse: MultiStatusResponse;
|
|
41
|
+
};
|
|
42
|
+
export type PollPayload = {
|
|
43
|
+
jobId: string;
|
|
44
|
+
uploadCount: number;
|
|
45
|
+
};
|
|
46
|
+
export type PollResponse = {
|
|
47
|
+
jobId: string;
|
|
48
|
+
status: number;
|
|
49
|
+
jobStatus: PollJobStatus;
|
|
50
|
+
multiStatusResponse?: MultiStatusResponse;
|
|
51
|
+
};
|
|
52
|
+
export interface ActionDefinition<Settings, Payload = any, AudienceSettings = any, GeneratedActionHookInputs = any, GeneratedActionHookOutputs = any> extends BaseActionDefinition {
|
|
38
53
|
dynamicFields?: {
|
|
39
54
|
[K in keyof Payload]?: IsArray<Payload[K]> extends never ? Payload[K] extends object | undefined ? {
|
|
40
55
|
[ObjectProperty in keyof NonNullable<Payload[K]> | '__keys__' | '__values__']?: RequestFn<Settings, Payload, DynamicFieldResponse, AudienceSettings>;
|
|
@@ -44,7 +59,21 @@ export interface ActionDefinition<Settings, Payload = any, AudienceSettings = an
|
|
|
44
59
|
};
|
|
45
60
|
perform: RequestFn<Settings, Payload, any, AudienceSettings, any, AudienceMembership>;
|
|
46
61
|
performBatch?: RequestFn<Settings, Payload[], PerformBatchResponse, AudienceSettings, any, AudienceMembership[]>;
|
|
47
|
-
|
|
62
|
+
hooks?: {
|
|
63
|
+
[K in ActionHookType]?: ActionHookDefinition<Settings, Payload, AudienceSettings, NonNullable<GeneratedActionHookInputs>, NonNullable<GeneratedActionHookOutputs>>;
|
|
64
|
+
};
|
|
65
|
+
syncMode?: SyncModeDefinition;
|
|
66
|
+
}
|
|
67
|
+
export interface AsyncActionDefinition<Settings, Payload = any, AudienceSettings = any, GeneratedActionHookInputs = any, GeneratedActionHookOutputs = any> extends BaseActionDefinition {
|
|
68
|
+
dynamicFields?: {
|
|
69
|
+
[K in keyof Payload]?: IsArray<Payload[K]> extends never ? Payload[K] extends object | undefined ? {
|
|
70
|
+
[ObjectProperty in keyof NonNullable<Payload[K]> | '__keys__' | '__values__']?: RequestFn<Settings, Payload, DynamicFieldResponse, AudienceSettings>;
|
|
71
|
+
} : RequestFn<Settings, Payload, DynamicFieldResponse, AudienceSettings> : IsArray<Payload[K]> extends object ? {
|
|
72
|
+
[ObjectProperty in keyof NonNullable<IsArray<Payload[K]>> | '__keys__' | '__values__']?: RequestFn<Settings, Payload, DynamicFieldResponse, AudienceSettings>;
|
|
73
|
+
} : never;
|
|
74
|
+
};
|
|
75
|
+
performBatch: RequestFn<Settings, Payload[], AsyncBatchResponse, AudienceSettings, any, AudienceMembership[]>;
|
|
76
|
+
performPoll: RequestFn<Settings, PollPayload, PollResponse, AudienceSettings>;
|
|
48
77
|
hooks?: {
|
|
49
78
|
[K in ActionHookType]?: ActionHookDefinition<Settings, Payload, AudienceSettings, NonNullable<GeneratedActionHookInputs>, NonNullable<GeneratedActionHookOutputs>>;
|
|
50
79
|
};
|
|
@@ -102,20 +131,29 @@ interface ExecuteBundle<T = unknown, Data = unknown, AudienceSettings = any, Act
|
|
|
102
131
|
subscriptionMetadata?: SubscriptionMetadata;
|
|
103
132
|
signal?: AbortSignal;
|
|
104
133
|
}
|
|
105
|
-
|
|
106
|
-
|
|
134
|
+
interface PollBundle<T = unknown> {
|
|
135
|
+
data: PollPayload;
|
|
136
|
+
settings: T;
|
|
137
|
+
auth: AuthTokens | undefined;
|
|
138
|
+
features?: Features | undefined;
|
|
139
|
+
statsContext?: StatsContext | undefined;
|
|
140
|
+
logger?: Logger | undefined;
|
|
141
|
+
transactionContext?: TransactionContext;
|
|
142
|
+
stateContext?: StateContext;
|
|
143
|
+
subscriptionMetadata?: SubscriptionMetadata;
|
|
144
|
+
signal?: AbortSignal;
|
|
145
|
+
}
|
|
146
|
+
export declare class Action<Settings, Payload extends JSONLikeObject, AudienceSettings = any> extends EventEmitter {
|
|
147
|
+
readonly definition: ActionDefinition<Settings, Payload, AudienceSettings, unknown, unknown>;
|
|
107
148
|
readonly destinationName: string;
|
|
108
149
|
readonly schema?: JSONSchema4;
|
|
109
|
-
readonly pollSchema?: JSONSchema4;
|
|
110
150
|
readonly hookSchemas?: Record<string, JSONSchema4>;
|
|
111
151
|
readonly hasBatchSupport: boolean;
|
|
112
152
|
readonly hasHookSupport: boolean;
|
|
113
|
-
readonly hasPollSupport: boolean;
|
|
114
153
|
private extendRequest;
|
|
115
|
-
constructor(destinationName: string, definition: ActionDefinition<Settings, Payload, AudienceSettings, unknown, unknown
|
|
154
|
+
constructor(destinationName: string, definition: ActionDefinition<Settings, Payload, AudienceSettings, unknown, unknown>, extendRequest?: RequestExtension<Settings, any>);
|
|
116
155
|
execute(bundle: ExecuteBundle<Settings, InputData | undefined, AudienceSettings>): Promise<Result[]>;
|
|
117
156
|
executeBatch(bundle: ExecuteBundle<Settings, InputData[], AudienceSettings>): Promise<ResultMultiStatusNode[]>;
|
|
118
|
-
executePoll(bundle: ExecuteBundle<Settings, InputData | undefined, AudienceSettings>): Promise<AsyncPollResponseType>;
|
|
119
157
|
private extractFieldContextAndHandler;
|
|
120
158
|
executeDynamicField(field: string, data: ExecuteDynamicFieldInput<Settings, Payload, AudienceSettings>, dynamicFn?: RequestFn<Settings, Payload, DynamicFieldResponse, AudienceSettings>): Promise<DynamicFieldResponse>;
|
|
121
159
|
executeHook(hookType: ActionHookType, data: ExecuteInput<Settings, Payload, AudienceSettings>): Promise<ActionHookResponse<any>>;
|
|
@@ -135,6 +173,26 @@ export declare class ActionDestinationErrorResponse {
|
|
|
135
173
|
constructor(data: ActionDestinationErrorResponseType);
|
|
136
174
|
value(): ActionDestinationErrorResponseType;
|
|
137
175
|
}
|
|
176
|
+
export declare class AsyncAction<Settings, Payload extends JSONLikeObject, AudienceSettings = any> extends EventEmitter {
|
|
177
|
+
readonly definition: AsyncActionDefinition<Settings, Payload, AudienceSettings, unknown, unknown>;
|
|
178
|
+
readonly destinationName: string;
|
|
179
|
+
readonly schema?: JSONSchema4;
|
|
180
|
+
readonly hookSchemas?: Record<string, JSONSchema4>;
|
|
181
|
+
readonly hasHookSupport: boolean;
|
|
182
|
+
private extendRequest;
|
|
183
|
+
constructor(destinationName: string, definition: AsyncActionDefinition<Settings, Payload, AudienceSettings, unknown, unknown>, extendRequest?: RequestExtension<Settings, any>);
|
|
184
|
+
executeBatch(bundle: ExecuteBundle<Settings, InputData[], AudienceSettings>): Promise<AsyncBatchResponse>;
|
|
185
|
+
executePoll(bundle: PollBundle<Settings>): Promise<PollResponse>;
|
|
186
|
+
private extractFieldContextAndHandler;
|
|
187
|
+
executeDynamicField(field: string, data: ExecuteDynamicFieldInput<Settings, Payload, AudienceSettings>, dynamicFn?: RequestFn<Settings, Payload, DynamicFieldResponse, AudienceSettings>): Promise<DynamicFieldResponse>;
|
|
188
|
+
executeHook(hookType: ActionHookType, data: ExecuteInput<Settings, Payload, AudienceSettings>): Promise<ActionHookResponse<any>>;
|
|
189
|
+
private performRequest;
|
|
190
|
+
private createRequestClient;
|
|
191
|
+
private afterResponse;
|
|
192
|
+
private parseResponse;
|
|
193
|
+
private parseBatchError;
|
|
194
|
+
private fillMultiStatusWithErrorResponse;
|
|
195
|
+
}
|
|
138
196
|
export declare class MultiStatusResponse {
|
|
139
197
|
private responses;
|
|
140
198
|
length(): number;
|
|
@@ -149,5 +207,7 @@ export declare class MultiStatusResponse {
|
|
|
149
207
|
isErrorResponseAtIndex(index: number): boolean;
|
|
150
208
|
getResponseAtIndex(index: number): ActionDestinationSuccessResponse | ActionDestinationErrorResponse;
|
|
151
209
|
getAllResponses(): (ActionDestinationSuccessResponse | ActionDestinationErrorResponse)[];
|
|
210
|
+
get successCount(): number;
|
|
211
|
+
get errorCount(): number;
|
|
152
212
|
}
|
|
153
213
|
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];
|
|
@@ -171,7 +167,9 @@ class Action extends events_1.EventEmitter {
|
|
|
171
167
|
const syncModeVal = this.definition.syncMode ? bundle.mapping?.['__segment_internal_sync_mode'] : undefined;
|
|
172
168
|
const syncMode = isSyncMode(syncModeVal) ? syncModeVal : undefined;
|
|
173
169
|
const matchingKey = bundle.mapping?.['__segment_internal_matching_key'];
|
|
174
|
-
const audienceMembership = bundle.data
|
|
170
|
+
const audienceMembership = bundle.data
|
|
171
|
+
.map((d) => (0, audience_membership_1.resolveAudienceMembership)(d, syncMode))
|
|
172
|
+
.filter((_, i) => !invalidPayloadIndices.has(i));
|
|
175
173
|
const data = {
|
|
176
174
|
rawData: bundle.data,
|
|
177
175
|
rawMapping: bundle.mapping,
|
|
@@ -265,42 +263,6 @@ class Action extends events_1.EventEmitter {
|
|
|
265
263
|
}
|
|
266
264
|
return multiStatusResponse;
|
|
267
265
|
}
|
|
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
266
|
extractFieldContextAndHandler(field) {
|
|
305
267
|
const arrayRegex = /(.*)\.\[(\d+)\]\.(.*)/;
|
|
306
268
|
const objectRegex = /(.*)\.(.*)/;
|
|
@@ -420,6 +382,286 @@ class ActionDestinationErrorResponse {
|
|
|
420
382
|
}
|
|
421
383
|
}
|
|
422
384
|
exports.ActionDestinationErrorResponse = ActionDestinationErrorResponse;
|
|
385
|
+
class AsyncAction extends events_1.EventEmitter {
|
|
386
|
+
constructor(destinationName, definition, extendRequest) {
|
|
387
|
+
super();
|
|
388
|
+
this.definition = definition;
|
|
389
|
+
this.destinationName = destinationName;
|
|
390
|
+
this.extendRequest = extendRequest;
|
|
391
|
+
this.hasHookSupport = definition.hooks !== undefined;
|
|
392
|
+
if (Object.keys(definition.fields ?? {}).length) {
|
|
393
|
+
this.schema = (0, fields_to_jsonschema_1.fieldsToJsonSchema)(definition.fields);
|
|
394
|
+
}
|
|
395
|
+
if (definition.hooks) {
|
|
396
|
+
for (const hookName in definition.hooks) {
|
|
397
|
+
const hook = definition.hooks[hookName];
|
|
398
|
+
if (hook?.inputFields) {
|
|
399
|
+
if (!this.hookSchemas) {
|
|
400
|
+
this.hookSchemas = {};
|
|
401
|
+
}
|
|
402
|
+
const castedInputFields = {};
|
|
403
|
+
for (const key in hook.inputFields) {
|
|
404
|
+
const field = hook.inputFields[key];
|
|
405
|
+
if (field.dynamic) {
|
|
406
|
+
castedInputFields[key] = {
|
|
407
|
+
...field,
|
|
408
|
+
dynamic: true
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
else {
|
|
412
|
+
castedInputFields[key] = {
|
|
413
|
+
...field,
|
|
414
|
+
dynamic: false
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
this.hookSchemas[hookName] = (0, fields_to_jsonschema_1.fieldsToJsonSchema)(castedInputFields);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
async executeBatch(bundle) {
|
|
424
|
+
const mapping = bundle.mapping;
|
|
425
|
+
let payloads = (0, mapping_kit_1.transformBatch)(mapping, bundle.data, bundle.statsContext);
|
|
426
|
+
const batchPayloadLength = payloads.length;
|
|
427
|
+
const multiStatusResponse = new MultiStatusResponse();
|
|
428
|
+
const invalidPayloadIndices = new Set();
|
|
429
|
+
if (this.schema) {
|
|
430
|
+
const schema = this.schema;
|
|
431
|
+
const validationOptions = {
|
|
432
|
+
schemaKey: `${this.destinationName}:${this.definition.title}`,
|
|
433
|
+
throwIfInvalid: true,
|
|
434
|
+
statsContext: bundle.statsContext,
|
|
435
|
+
exempt: ['dynamicAuthSettings']
|
|
436
|
+
};
|
|
437
|
+
{
|
|
438
|
+
const filteredPayload = [];
|
|
439
|
+
for (let i = 0; i < payloads.length; i++) {
|
|
440
|
+
const payload = (0, remove_empty_values_1.removeEmptyValues)(payloads[i], schema);
|
|
441
|
+
try {
|
|
442
|
+
(0, schema_validation_1.validateSchema)(payload, schema, validationOptions);
|
|
443
|
+
}
|
|
444
|
+
catch (e) {
|
|
445
|
+
multiStatusResponse.setErrorResponseAtIndex(i, {
|
|
446
|
+
status: 400,
|
|
447
|
+
errortype: errors_1.ErrorCodes.PAYLOAD_VALIDATION_FAILED,
|
|
448
|
+
errormessage: e.message
|
|
449
|
+
});
|
|
450
|
+
invalidPayloadIndices.add(i);
|
|
451
|
+
bundle.statsContext?.statsClient?.incr('action.multistatus_discard', 1, bundle.statsContext?.tags);
|
|
452
|
+
continue;
|
|
453
|
+
}
|
|
454
|
+
filteredPayload.push(payload);
|
|
455
|
+
}
|
|
456
|
+
payloads = filteredPayload;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
let hookOutputs = {};
|
|
460
|
+
if (this.definition.hooks) {
|
|
461
|
+
for (const hookType in this.definition.hooks) {
|
|
462
|
+
const hookOutputValues = bundle.mapping?.[hookType];
|
|
463
|
+
if (hookOutputValues) {
|
|
464
|
+
hookOutputs = { ...hookOutputs, [hookType]: hookOutputValues };
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
if (payloads.length === 0) {
|
|
469
|
+
return { jobId: undefined, status: 200, multiStatusResponse };
|
|
470
|
+
}
|
|
471
|
+
const syncModeVal = this.definition.syncMode ? bundle.mapping?.['__segment_internal_sync_mode'] : undefined;
|
|
472
|
+
const syncMode = isSyncMode(syncModeVal) ? syncModeVal : undefined;
|
|
473
|
+
const matchingKey = bundle.mapping?.['__segment_internal_matching_key'];
|
|
474
|
+
const audienceMembership = bundle.data.map((d) => (0, audience_membership_1.resolveAudienceMembership)(d, syncMode));
|
|
475
|
+
const data = {
|
|
476
|
+
rawData: bundle.data,
|
|
477
|
+
rawMapping: bundle.mapping,
|
|
478
|
+
settings: bundle.settings,
|
|
479
|
+
audienceSettings: bundle.audienceSettings,
|
|
480
|
+
payload: payloads,
|
|
481
|
+
audienceMembership,
|
|
482
|
+
auth: bundle.auth,
|
|
483
|
+
features: bundle.features,
|
|
484
|
+
statsContext: bundle.statsContext,
|
|
485
|
+
logger: bundle.logger,
|
|
486
|
+
engageDestinationCache: bundle.engageDestinationCache,
|
|
487
|
+
transactionContext: bundle.transactionContext,
|
|
488
|
+
stateContext: bundle.stateContext,
|
|
489
|
+
subscriptionMetadata: bundle.subscriptionMetadata,
|
|
490
|
+
hookOutputs,
|
|
491
|
+
syncMode,
|
|
492
|
+
matchingKey: matchingKey ? String(matchingKey) : undefined,
|
|
493
|
+
signal: bundle?.signal
|
|
494
|
+
};
|
|
495
|
+
const requestClient = this.createRequestClient(data);
|
|
496
|
+
let performBatchResponse;
|
|
497
|
+
try {
|
|
498
|
+
performBatchResponse = await this.definition.performBatch(requestClient, data);
|
|
499
|
+
}
|
|
500
|
+
catch (error) {
|
|
501
|
+
this.parseBatchError(error, {
|
|
502
|
+
multiStatusResponse,
|
|
503
|
+
invalidPayloadIndices,
|
|
504
|
+
batchPayloadLength,
|
|
505
|
+
filteredPayloads: payloads
|
|
506
|
+
});
|
|
507
|
+
const errorStatus = error?.response?.status ?? error?.status ?? 500;
|
|
508
|
+
return { jobId: undefined, status: errorStatus, multiStatusResponse };
|
|
509
|
+
}
|
|
510
|
+
const { jobId, status, multiStatusResponse: batchMultiStatus } = performBatchResponse;
|
|
511
|
+
let resultsReadIndex = 0;
|
|
512
|
+
for (let i = 0; i < batchPayloadLength; i++) {
|
|
513
|
+
if (invalidPayloadIndices.has(i)) {
|
|
514
|
+
continue;
|
|
515
|
+
}
|
|
516
|
+
const response = batchMultiStatus.getResponseAtIndex(resultsReadIndex++);
|
|
517
|
+
if (!response) {
|
|
518
|
+
multiStatusResponse.setErrorResponseAtIndex(i, {
|
|
519
|
+
status: 500,
|
|
520
|
+
errormessage: 'MultiStatusResponse is missing a response at the specified index',
|
|
521
|
+
errortype: errors_1.ErrorCodes.PAYLOAD_VALIDATION_FAILED
|
|
522
|
+
});
|
|
523
|
+
bundle.statsContext?.statsClient?.incr('action.multistatus_discard', 1, bundle.statsContext?.tags);
|
|
524
|
+
continue;
|
|
525
|
+
}
|
|
526
|
+
if (response instanceof ActionDestinationErrorResponse) {
|
|
527
|
+
multiStatusResponse.setErrorResponseAtIndex(i, response.value());
|
|
528
|
+
bundle.statsContext?.statsClient?.incr('destination.multistatus_discard', 1, bundle.statsContext?.tags);
|
|
529
|
+
continue;
|
|
530
|
+
}
|
|
531
|
+
multiStatusResponse.setSuccessResponseAtIndex(i, response.value());
|
|
532
|
+
}
|
|
533
|
+
return { jobId, status, multiStatusResponse };
|
|
534
|
+
}
|
|
535
|
+
async executePoll(bundle) {
|
|
536
|
+
const dataBundle = {
|
|
537
|
+
rawData: bundle.data,
|
|
538
|
+
settings: bundle.settings,
|
|
539
|
+
payload: bundle.data,
|
|
540
|
+
auth: bundle.auth,
|
|
541
|
+
features: bundle.features,
|
|
542
|
+
statsContext: bundle.statsContext,
|
|
543
|
+
logger: bundle.logger,
|
|
544
|
+
transactionContext: bundle.transactionContext,
|
|
545
|
+
stateContext: bundle.stateContext,
|
|
546
|
+
subscriptionMetadata: bundle.subscriptionMetadata,
|
|
547
|
+
signal: bundle?.signal
|
|
548
|
+
};
|
|
549
|
+
const requestClient = this.createRequestClient(dataBundle);
|
|
550
|
+
return this.definition.performPoll(requestClient, dataBundle);
|
|
551
|
+
}
|
|
552
|
+
extractFieldContextAndHandler(field) {
|
|
553
|
+
const arrayRegex = /(.*)\.\[(\d+)\]\.(.*)/;
|
|
554
|
+
const objectRegex = /(.*)\.(.*)/;
|
|
555
|
+
let dynamicHandlerPath = field;
|
|
556
|
+
let dynamicFieldContext;
|
|
557
|
+
const match = arrayRegex.exec(field) || objectRegex.exec(field);
|
|
558
|
+
if (match) {
|
|
559
|
+
const [, parent, indexOrChild, child] = match;
|
|
560
|
+
if (child) {
|
|
561
|
+
dynamicFieldContext = { selectedArrayIndex: parseInt(indexOrChild, 10) };
|
|
562
|
+
dynamicHandlerPath = `${parent}.${child}`;
|
|
563
|
+
}
|
|
564
|
+
else {
|
|
565
|
+
const parentFetcher = this.definition.dynamicFields?.[parent];
|
|
566
|
+
if (parentFetcher && !(indexOrChild in parentFetcher)) {
|
|
567
|
+
dynamicHandlerPath = `${parent}.__values__`;
|
|
568
|
+
dynamicFieldContext = { selectedKey: indexOrChild };
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
return { dynamicHandlerPath, dynamicFieldContext };
|
|
573
|
+
}
|
|
574
|
+
async executeDynamicField(field, data, dynamicFn) {
|
|
575
|
+
if (dynamicFn && typeof dynamicFn === 'function') {
|
|
576
|
+
return (await this.performRequest(dynamicFn, { ...data }));
|
|
577
|
+
}
|
|
578
|
+
const { dynamicHandlerPath, dynamicFieldContext } = this.extractFieldContextAndHandler(field);
|
|
579
|
+
const fn = (0, get_1.get)(this.definition.dynamicFields, dynamicHandlerPath);
|
|
580
|
+
if (typeof fn !== 'function') {
|
|
581
|
+
return Promise.resolve({
|
|
582
|
+
choices: [],
|
|
583
|
+
nextPage: '',
|
|
584
|
+
error: {
|
|
585
|
+
message: `No dynamic field named ${field} found.`,
|
|
586
|
+
code: '404'
|
|
587
|
+
}
|
|
588
|
+
});
|
|
589
|
+
}
|
|
590
|
+
return (await this.performRequest(fn, { ...data, dynamicFieldContext }));
|
|
591
|
+
}
|
|
592
|
+
async executeHook(hookType, data) {
|
|
593
|
+
if (!this.hasHookSupport) {
|
|
594
|
+
throw new errors_1.IntegrationError('This action does not support any hooks.', 'NotImplemented', 501);
|
|
595
|
+
}
|
|
596
|
+
const hookFn = this.definition.hooks?.[hookType]?.performHook;
|
|
597
|
+
if (!hookFn) {
|
|
598
|
+
throw new errors_1.IntegrationError(`Missing implementation for hook: ${hookType}.`, 'NotImplemented', 501);
|
|
599
|
+
}
|
|
600
|
+
if (this.hookSchemas?.[hookType]) {
|
|
601
|
+
const schema = this.hookSchemas[hookType];
|
|
602
|
+
(0, schema_validation_1.validateSchema)(data.hookInputs, schema, {
|
|
603
|
+
exempt: ['dynamicAuthSettings']
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
return (await this.performRequest(hookFn, data));
|
|
607
|
+
}
|
|
608
|
+
async performRequest(requestFn, data) {
|
|
609
|
+
const requestClient = this.createRequestClient(data);
|
|
610
|
+
const response = await requestFn(requestClient, data);
|
|
611
|
+
return this.parseResponse(response);
|
|
612
|
+
}
|
|
613
|
+
createRequestClient(data) {
|
|
614
|
+
const options = this.extendRequest?.(data) ?? {};
|
|
615
|
+
return (0, create_request_client_1.default)(options, {
|
|
616
|
+
afterResponse: [this.afterResponse.bind(this)],
|
|
617
|
+
statsContext: data.statsContext,
|
|
618
|
+
signal: data?.signal
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
afterResponse(request, options, response) {
|
|
622
|
+
const modifiedResponse = response;
|
|
623
|
+
modifiedResponse.request = request;
|
|
624
|
+
modifiedResponse.options = options;
|
|
625
|
+
this.emit('response', modifiedResponse);
|
|
626
|
+
return modifiedResponse;
|
|
627
|
+
}
|
|
628
|
+
parseResponse(response) {
|
|
629
|
+
if (response instanceof fetch_1.Response) {
|
|
630
|
+
return response.data ?? response.content;
|
|
631
|
+
}
|
|
632
|
+
return response;
|
|
633
|
+
}
|
|
634
|
+
parseBatchError(error, input) {
|
|
635
|
+
if (error instanceof request_client_1.HTTPError) {
|
|
636
|
+
this.fillMultiStatusWithErrorResponse({ ...input, status: error.response.status, errormessage: error.message });
|
|
637
|
+
return;
|
|
638
|
+
}
|
|
639
|
+
if (error instanceof errors_1.IntegrationError) {
|
|
640
|
+
this.fillMultiStatusWithErrorResponse({ ...input, status: error.status ?? 400, errormessage: error.message });
|
|
641
|
+
return;
|
|
642
|
+
}
|
|
643
|
+
if (error instanceof errors_1.RetryableError || error instanceof errors_1.InvalidAuthenticationError) {
|
|
644
|
+
this.fillMultiStatusWithErrorResponse({ ...input, status: error.status, errormessage: error.message });
|
|
645
|
+
return;
|
|
646
|
+
}
|
|
647
|
+
throw error;
|
|
648
|
+
}
|
|
649
|
+
fillMultiStatusWithErrorResponse(input) {
|
|
650
|
+
const { multiStatusResponse, batchPayloadLength, status, errormessage, filteredPayloads } = input;
|
|
651
|
+
let payloadReadIndex = 0;
|
|
652
|
+
for (let i = 0; i < batchPayloadLength; i++) {
|
|
653
|
+
if (input.invalidPayloadIndices.has(i)) {
|
|
654
|
+
continue;
|
|
655
|
+
}
|
|
656
|
+
multiStatusResponse.setErrorResponseAtIndex(i, {
|
|
657
|
+
status,
|
|
658
|
+
errormessage,
|
|
659
|
+
sent: filteredPayloads ? filteredPayloads[payloadReadIndex++] : {}
|
|
660
|
+
});
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
exports.AsyncAction = AsyncAction;
|
|
423
665
|
class MultiStatusResponse {
|
|
424
666
|
constructor() {
|
|
425
667
|
this.responses = [];
|
|
@@ -480,6 +722,12 @@ class MultiStatusResponse {
|
|
|
480
722
|
getAllResponses() {
|
|
481
723
|
return this.responses;
|
|
482
724
|
}
|
|
725
|
+
get successCount() {
|
|
726
|
+
return this.responses.filter((r) => r instanceof ActionDestinationSuccessResponse).length;
|
|
727
|
+
}
|
|
728
|
+
get errorCount() {
|
|
729
|
+
return this.responses.filter((r) => r instanceof ActionDestinationErrorResponse).length;
|
|
730
|
+
}
|
|
483
731
|
}
|
|
484
732
|
exports.MultiStatusResponse = MultiStatusResponse;
|
|
485
733
|
//# sourceMappingURL=action.js.map
|