@segment/actions-core 2.0.3-next.0 → 2.1.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-request-client.d.ts +0 -3
- package/dist/cjs/create-request-client.js +0 -7
- package/dist/cjs/create-request-client.js.map +1 -1
- package/dist/cjs/create-test-event.js +1 -1
- package/dist/cjs/create-test-event.js.map +1 -1
- package/dist/cjs/create-test-integration.d.ts +0 -19
- package/dist/cjs/create-test-integration.js +0 -1
- package/dist/cjs/create-test-integration.js.map +1 -1
- package/dist/cjs/destination-kit/action.d.ts +7 -37
- package/dist/cjs/destination-kit/action.js +28 -52
- package/dist/cjs/destination-kit/action.js.map +1 -1
- package/dist/cjs/destination-kit/fields-to-jsonschema.js +80 -12
- package/dist/cjs/destination-kit/fields-to-jsonschema.js.map +1 -1
- package/dist/cjs/destination-kit/index.d.ts +0 -10
- package/dist/cjs/destination-kit/index.js +13 -8
- package/dist/cjs/destination-kit/index.js.map +1 -1
- package/dist/cjs/destination-kit/step.d.ts +0 -12
- package/dist/cjs/destination-kit/step.js +0 -7
- package/dist/cjs/destination-kit/step.js.map +1 -1
- package/dist/cjs/destination-kit/types.d.ts +31 -9
- package/dist/cjs/errors.d.ts +15 -5
- package/dist/cjs/errors.js +22 -8
- package/dist/cjs/errors.js.map +1 -1
- package/dist/cjs/fetch.js +0 -1
- package/dist/cjs/fetch.js.map +1 -1
- package/dist/cjs/get.d.ts +0 -4
- package/dist/cjs/get.js +1 -11
- package/dist/cjs/get.js.map +1 -1
- package/dist/cjs/index.d.ts +2 -2
- package/dist/cjs/index.js +4 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/map-values.d.ts +1 -5
- package/dist/cjs/map-values.js +0 -5
- package/dist/cjs/map-values.js.map +1 -1
- package/dist/cjs/mapping-kit/index.d.ts +0 -6
- package/dist/cjs/mapping-kit/index.js +0 -87
- package/dist/cjs/mapping-kit/index.js.map +1 -1
- package/dist/cjs/mapping-kit/is-directive.js +0 -1
- package/dist/cjs/mapping-kit/is-directive.js.map +1 -1
- package/dist/cjs/mapping-kit/placeholders.d.ts +0 -3
- package/dist/cjs/mapping-kit/placeholders.js +0 -8
- package/dist/cjs/mapping-kit/placeholders.js.map +1 -1
- package/dist/cjs/mapping-kit/validate.js +0 -84
- package/dist/cjs/mapping-kit/validate.js.map +1 -1
- package/dist/cjs/middleware/after-response/prepare-headers.js +0 -3
- package/dist/cjs/middleware/after-response/prepare-headers.js.map +1 -1
- package/dist/cjs/middleware/after-response/prepare-response.js +0 -4
- package/dist/cjs/middleware/after-response/prepare-response.js.map +1 -1
- package/dist/cjs/omit.d.ts +0 -3
- package/dist/cjs/omit.js +0 -3
- package/dist/cjs/omit.js.map +1 -1
- package/dist/cjs/real-type-of.d.ts +0 -5
- package/dist/cjs/real-type-of.js +0 -5
- package/dist/cjs/real-type-of.js.map +1 -1
- package/dist/cjs/request-client.d.ts +0 -53
- package/dist/cjs/request-client.js +4 -48
- package/dist/cjs/request-client.js.map +1 -1
- package/dist/cjs/segment-event.d.ts +0 -40
- package/dist/cjs/time.d.ts +0 -6
- package/dist/cjs/time.js +0 -6
- package/dist/cjs/time.js.map +1 -1
- package/dist/cjs/types.d.ts +0 -4
- package/dist/esm/create-request-client.d.ts +0 -3
- package/dist/esm/create-request-client.js +0 -7
- package/dist/esm/create-request-client.js.map +1 -1
- package/dist/esm/create-test-event.js +1 -1
- package/dist/esm/create-test-event.js.map +1 -1
- package/dist/esm/create-test-integration.d.ts +0 -19
- package/dist/esm/create-test-integration.js +0 -1
- package/dist/esm/create-test-integration.js.map +1 -1
- package/dist/esm/destination-kit/action.d.ts +7 -37
- package/dist/esm/destination-kit/action.js +28 -52
- package/dist/esm/destination-kit/action.js.map +1 -1
- package/dist/esm/destination-kit/fields-to-jsonschema.js +80 -12
- package/dist/esm/destination-kit/fields-to-jsonschema.js.map +1 -1
- package/dist/esm/destination-kit/index.d.ts +0 -10
- package/dist/esm/destination-kit/index.js +12 -7
- package/dist/esm/destination-kit/index.js.map +1 -1
- package/dist/esm/destination-kit/step.d.ts +0 -12
- package/dist/esm/destination-kit/step.js +0 -7
- package/dist/esm/destination-kit/step.js.map +1 -1
- package/dist/esm/destination-kit/types.d.ts +31 -9
- package/dist/esm/errors.d.ts +15 -5
- package/dist/esm/errors.js +18 -6
- package/dist/esm/errors.js.map +1 -1
- package/dist/esm/fetch.js +0 -1
- package/dist/esm/fetch.js.map +1 -1
- package/dist/esm/get.d.ts +0 -4
- package/dist/esm/get.js +1 -11
- package/dist/esm/get.js.map +1 -1
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/map-values.d.ts +1 -5
- package/dist/esm/map-values.js +0 -5
- package/dist/esm/map-values.js.map +1 -1
- package/dist/esm/mapping-kit/index.d.ts +0 -6
- package/dist/esm/mapping-kit/index.js +1 -88
- package/dist/esm/mapping-kit/index.js.map +1 -1
- package/dist/esm/mapping-kit/is-directive.js +0 -1
- package/dist/esm/mapping-kit/is-directive.js.map +1 -1
- package/dist/esm/mapping-kit/placeholders.d.ts +0 -3
- package/dist/esm/mapping-kit/placeholders.js +0 -8
- package/dist/esm/mapping-kit/placeholders.js.map +1 -1
- package/dist/esm/mapping-kit/validate.js +0 -84
- package/dist/esm/mapping-kit/validate.js.map +1 -1
- package/dist/esm/middleware/after-response/prepare-headers.js +0 -3
- package/dist/esm/middleware/after-response/prepare-headers.js.map +1 -1
- package/dist/esm/middleware/after-response/prepare-response.js +0 -4
- package/dist/esm/middleware/after-response/prepare-response.js.map +1 -1
- package/dist/esm/omit.d.ts +0 -3
- package/dist/esm/omit.js +0 -3
- package/dist/esm/omit.js.map +1 -1
- package/dist/esm/real-type-of.d.ts +0 -5
- package/dist/esm/real-type-of.js +0 -5
- package/dist/esm/real-type-of.js.map +1 -1
- package/dist/esm/request-client.d.ts +0 -53
- package/dist/esm/request-client.js +4 -48
- package/dist/esm/request-client.js.map +1 -1
- package/dist/esm/segment-event.d.ts +0 -40
- package/dist/esm/time.d.ts +0 -6
- package/dist/esm/time.js +0 -6
- package/dist/esm/time.js.map +1 -1
- package/dist/esm/types.d.ts +0 -4
- package/package.json +16 -11
- package/dist/cjs/dayjs.d.ts +0 -2
- package/dist/cjs/dayjs.js +0 -10
- package/dist/cjs/dayjs.js.map +0 -1
- package/dist/esm/dayjs.d.ts +0 -2
- package/dist/esm/dayjs.js +0 -5
- package/dist/esm/dayjs.js.map +0 -1
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
import { AllRequestOptions, RequestOptions } from './request-client';
|
|
2
2
|
import type { ModifiedResponse } from './types';
|
|
3
3
|
export declare type RequestClient = ReturnType<typeof createRequestClient>;
|
|
4
|
-
/**
|
|
5
|
-
* Creates a request client instance with Segment's default configuration + custom options
|
|
6
|
-
*/
|
|
7
4
|
export default function createRequestClient(...requestOptions: AllRequestOptions[]): <Data = unknown>(url: string, options?: RequestOptions | undefined) => Promise<ModifiedResponse<Data>>;
|
|
@@ -13,22 +13,15 @@ const baseClient = request_client_1.default({
|
|
|
13
13
|
'user-agent': 'Segment'
|
|
14
14
|
},
|
|
15
15
|
beforeRequest: [
|
|
16
|
-
// Automatically handle username/password -> basic auth header
|
|
17
16
|
add_basic_auth_header_1.default
|
|
18
17
|
],
|
|
19
18
|
afterResponse: [prepare_response_1.default, prepare_headers_1.default]
|
|
20
19
|
});
|
|
21
|
-
/**
|
|
22
|
-
* Creates a request client instance with Segment's default configuration + custom options
|
|
23
|
-
*/
|
|
24
20
|
function createRequestClient(...requestOptions) {
|
|
25
21
|
let client = baseClient;
|
|
26
|
-
// TODO include `data` bundle in before/after hooks
|
|
27
|
-
// TODO expose before/after hooks to destination definition and action definition?
|
|
28
22
|
for (const options of requestOptions !== null && requestOptions !== void 0 ? requestOptions : []) {
|
|
29
23
|
client = client.extend(options);
|
|
30
24
|
}
|
|
31
|
-
// Limit request client interface and handle basic auth scheme
|
|
32
25
|
return (url, options) => {
|
|
33
26
|
return client(url, options);
|
|
34
27
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-request-client.js","sourceRoot":"","sources":["../../src/create-request-client.ts"],"names":[],"mappings":";;;;;AAAA,8GAAkF;AAClF,kGAAwE;AACxE,oGAA0E;AAC1E,sEAAoF;AAGpF,MAAM,UAAU,GAAG,wBAAc,CAAC;IAChC,OAAO,EAAE,KAAK;IACd,OAAO,EAAE;QACP,YAAY,EAAE,SAAS;KACxB;IACD,aAAa,EAAE;
|
|
1
|
+
{"version":3,"file":"create-request-client.js","sourceRoot":"","sources":["../../src/create-request-client.ts"],"names":[],"mappings":";;;;;AAAA,8GAAkF;AAClF,kGAAwE;AACxE,oGAA0E;AAC1E,sEAAoF;AAGpF,MAAM,UAAU,GAAG,wBAAc,CAAC;IAChC,OAAO,EAAE,KAAK;IACd,OAAO,EAAE;QACP,YAAY,EAAE,SAAS;KACxB;IACD,aAAa,EAAE;QAEb,+BAAkB;KACnB;IACD,aAAa,EAAE,CAAC,0BAAe,EAAE,yBAAc,CAAC;CACjD,CAAC,CAAA;AAOF,SAAwB,mBAAmB,CAAC,GAAG,cAAmC;IAChF,IAAI,MAAM,GAAG,UAAU,CAAA;IAIvB,KAAK,MAAM,OAAO,IAAI,cAAc,aAAd,cAAc,cAAd,cAAc,GAAI,EAAE,EAAE;QAC1C,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;KAChC;IAGD,OAAO,CAAiB,GAAW,EAAE,OAAwB,EAAE,EAAE;QAC/D,OAAO,MAAM,CAAyB,GAAG,EAAE,OAAO,CAAC,CAAA;IACrD,CAAC,CAAA;AACH,CAAC;AAbD,sCAaC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createTestEvent = void 0;
|
|
4
|
-
const uuid_1 = require("uuid");
|
|
4
|
+
const uuid_1 = require("@lukeed/uuid");
|
|
5
5
|
function createTestEvent(event = {}) {
|
|
6
6
|
return {
|
|
7
7
|
anonymousId: uuid_1.v4(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-test-event.js","sourceRoot":"","sources":["../../src/create-test-event.ts"],"names":[],"mappings":";;;AAAA
|
|
1
|
+
{"version":3,"file":"create-test-event.js","sourceRoot":"","sources":["../../src/create-test-event.ts"],"names":[],"mappings":";;;AAAA,uCAA2C;AAG3C,SAAgB,eAAe,CAAC,QAA+B,EAAE;IAC/D,OAAO;QACL,WAAW,EAAE,SAAM,EAAE;QACrB,OAAO,EAAE;YACP,EAAE,EAAE,SAAS;YACb,OAAO,EAAE;gBACP,IAAI,EAAE,cAAc;gBACpB,OAAO,EAAE,QAAQ;aAClB;YACD,MAAM,EAAE,OAAO;YACf,QAAQ,EAAE;gBACR,IAAI,EAAE,eAAe;gBACrB,OAAO,EAAE,eAAe;gBACxB,QAAQ,EAAE,UAAU;gBACpB,SAAS,EAAE,CAAC,UAAU;gBACtB,KAAK,EAAE,CAAC;aACT;YACD,IAAI,EAAE;gBACJ,IAAI,EAAE,WAAW;gBACjB,QAAQ,EAAE,EAAE;gBACZ,MAAM,EAAE,EAAE;gBACV,KAAK,EAAE,mBAAmB;gBAC1B,GAAG,EAAE,8BAA8B;aACpC;YACD,QAAQ,EAAE,kBAAkB;YAC5B,SAAS,EACP,uIAAuI;SAC1I;QACD,KAAK,EAAE,YAAY;QACnB,SAAS,EAAE,SAAM,EAAE;QACnB,UAAU,EAAE,EAAE;QACd,UAAU,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QACpC,MAAM,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QAChC,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QACnC,MAAM,EAAE,EAAE;QACV,IAAI,EAAE,OAAO;QACb,MAAM,EAAE,UAAU;QAClB,GAAG,KAAK;KACT,CAAA;AACH,CAAC;AAvCD,0CAuCC"}
|
|
@@ -3,33 +3,14 @@ import type { DestinationDefinition } from './destination-kit';
|
|
|
3
3
|
import type { JSONObject } from './json-object';
|
|
4
4
|
import type { SegmentEvent } from './segment-event';
|
|
5
5
|
interface InputData<Settings> {
|
|
6
|
-
/**
|
|
7
|
-
* The Segment event. You can use `createTestEvent` if you want
|
|
8
|
-
* to construct an event from partial data.
|
|
9
|
-
*/
|
|
10
6
|
event?: Partial<SegmentEvent>;
|
|
11
|
-
/**
|
|
12
|
-
* The raw input - this is what customers define. It may include
|
|
13
|
-
* literal values as well as mapping-kit directives.
|
|
14
|
-
*/
|
|
15
7
|
mapping?: JSONObject;
|
|
16
|
-
/**
|
|
17
|
-
* The settings for a destination instance. Includes things like
|
|
18
|
-
* `apiKey` or `subdomain`. Any fields that are used across all actions
|
|
19
|
-
* in a destination.
|
|
20
|
-
*/
|
|
21
8
|
settings?: Settings;
|
|
22
|
-
/**
|
|
23
|
-
* Whether or not to use default mappings in the test.
|
|
24
|
-
* Set to `false` or omit if you want to explicitly provide the raw input.
|
|
25
|
-
* Set to `true` if you want to test the defaultMappings (along with any mapping passed in)
|
|
26
|
-
*/
|
|
27
9
|
useDefaultMappings?: boolean;
|
|
28
10
|
}
|
|
29
11
|
declare class TestDestination<T> extends Destination<T> {
|
|
30
12
|
responses: Destination['responses'];
|
|
31
13
|
constructor(destination: DestinationDefinition<T>);
|
|
32
|
-
/** Testing method that runs an action e2e while allowing slightly more flexible inputs */
|
|
33
14
|
testAction(action: string, { event, mapping, settings, useDefaultMappings }: InputData<T>): Promise<Destination['responses']>;
|
|
34
15
|
}
|
|
35
16
|
export declare function createTestIntegration<T>(destination: DestinationDefinition<T>): TestDestination<T>;
|
|
@@ -9,7 +9,6 @@ class TestDestination extends destination_kit_1.Destination {
|
|
|
9
9
|
super(destination);
|
|
10
10
|
this.responses = [];
|
|
11
11
|
}
|
|
12
|
-
/** Testing method that runs an action e2e while allowing slightly more flexible inputs */
|
|
13
12
|
async testAction(action, { event, mapping, settings, useDefaultMappings }) {
|
|
14
13
|
mapping = mapping !== null && mapping !== void 0 ? mapping : {};
|
|
15
14
|
if (useDefaultMappings) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-test-integration.js","sourceRoot":"","sources":["../../src/create-test-integration.ts"],"names":[],"mappings":";;;AAAA,2DAAqD;AACrD,uDAA+C;AAC/C,6CAAwC;AA8BxC,MAAM,eAAmB,SAAQ,6BAAc;IAG7C,YAAY,WAAqC;QAC/C,KAAK,CAAC,WAAW,CAAC,CAAA;QAHpB,cAAS,GAA6B,EAAE,CAAA;IAIxC,CAAC;
|
|
1
|
+
{"version":3,"file":"create-test-integration.js","sourceRoot":"","sources":["../../src/create-test-integration.ts"],"names":[],"mappings":";;;AAAA,2DAAqD;AACrD,uDAA+C;AAC/C,6CAAwC;AA8BxC,MAAM,eAAmB,SAAQ,6BAAc;IAG7C,YAAY,WAAqC;QAC/C,KAAK,CAAC,WAAW,CAAC,CAAA;QAHpB,cAAS,GAA6B,EAAE,CAAA;IAIxC,CAAC;IAGD,KAAK,CAAC,UAAU,CACd,MAAc,EACd,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAgB;QAE9D,OAAO,GAAG,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,EAAE,CAAA;QAEvB,IAAI,kBAAkB,EAAE;YACtB,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,CAAA;YACrD,MAAM,eAAe,GAAG,sBAAS,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;YACpD,OAAO,GAAG,EAAE,GAAG,eAAe,EAAE,GAAG,OAAO,EAAgB,CAAA;SAC3D;QAED,MAAM,KAAK,CAAC,aAAa,CAAC,MAAM,EAAE;YAChC,KAAK,EAAE,mCAAe,CAAC,KAAK,CAAC;YAC7B,OAAO;YACP,QAAQ,EAAE,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAK,EAAQ;SAChC,CAAC,CAAA;QAEF,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAA;QAChC,IAAI,CAAC,SAAS,GAAG,EAAE,CAAA;QAEnB,OAAO,SAAS,CAAA;IAClB,CAAC;CACF;AAED,SAAgB,qBAAqB,CAAI,WAAqC;IAC5E,OAAO,IAAI,eAAe,CAAC,WAAW,CAAC,CAAA;AACzC,CAAC;AAFD,sDAEC"}
|
|
@@ -4,44 +4,19 @@ import { EventEmitter } from 'events';
|
|
|
4
4
|
import createRequestClient from '../create-request-client';
|
|
5
5
|
import { JSONLikeObject } from '../json-object';
|
|
6
6
|
import { ExecuteInput, Step, StepResult, Steps } from './step';
|
|
7
|
-
import type {
|
|
7
|
+
import type { DynamicFieldResponse, InputField, RequestExtension } from './types';
|
|
8
8
|
declare type MaybePromise<T> = T | Promise<T>;
|
|
9
9
|
declare type RequestClient = ReturnType<typeof createRequestClient>;
|
|
10
10
|
export declare type RequestFn<Settings, Payload, Return = any> = (request: RequestClient, data: ExecuteInput<Settings, Payload>) => MaybePromise<Return>;
|
|
11
11
|
export interface ActionDefinition<Settings, Payload = any> {
|
|
12
|
-
/** The unique identifier for the action, e.g. `postToChannel` */
|
|
13
|
-
/** The display title of the action */
|
|
14
12
|
title: string;
|
|
15
|
-
/** The display description of the action */
|
|
16
13
|
description: string;
|
|
17
|
-
/** Whether the action is recommended for quick setup */
|
|
18
|
-
recommended?: boolean;
|
|
19
|
-
/** An optional fql query that will be used to prepopulate the action when it is first set up */
|
|
20
14
|
defaultSubscription?: string;
|
|
21
|
-
/** Whether or not this action should be visible/configurable in the UI */
|
|
22
15
|
hidden?: boolean;
|
|
23
|
-
/**
|
|
24
|
-
* The fields used to perform the action. These fields should match what the partner API expects.
|
|
25
|
-
*
|
|
26
|
-
* This is a set of JSON Schema properties right now.
|
|
27
|
-
* We may eventually auto-generate the JSON Schema from a definition object
|
|
28
|
-
* instead of requiring devs to build and modify JSON Schema directly.
|
|
29
|
-
*
|
|
30
|
-
* Plus, JSON Schema cannot fully represent our action or field definitions
|
|
31
|
-
* without many custom keywords.
|
|
32
|
-
*/
|
|
33
16
|
fields: Record<string, InputField>;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
* This is likely going to change as we productionalize the data model and definition object
|
|
37
|
-
*/
|
|
38
|
-
autocompleteFields?: {
|
|
39
|
-
[K in keyof Payload]?: RequestFn<Settings, Payload, AutocompleteResponse>;
|
|
17
|
+
dynamicFields?: {
|
|
18
|
+
[K in keyof Payload]?: RequestFn<Settings, Payload, DynamicFieldResponse>;
|
|
40
19
|
};
|
|
41
|
-
/**
|
|
42
|
-
* Register fields that should be executed, cached and provided
|
|
43
|
-
* to the action's `perform` function
|
|
44
|
-
*/
|
|
45
20
|
cachedFields?: {
|
|
46
21
|
[field: string]: {
|
|
47
22
|
key: (data: ExecuteInput<Settings, Payload>) => string;
|
|
@@ -50,7 +25,6 @@ export interface ActionDefinition<Settings, Payload = any> {
|
|
|
50
25
|
negative?: boolean;
|
|
51
26
|
};
|
|
52
27
|
};
|
|
53
|
-
/** The operation to perform when this action is triggered */
|
|
54
28
|
perform: RequestFn<Settings, Payload>;
|
|
55
29
|
}
|
|
56
30
|
export declare class Validate<Settings, Payload> extends Step<Settings, Payload> {
|
|
@@ -59,7 +33,7 @@ export declare class Validate<Settings, Payload> extends Step<Settings, Payload>
|
|
|
59
33
|
constructor(field: ExecuteInputField, schema: object);
|
|
60
34
|
executeStep(data: ExecuteInput<Settings, Payload>): Promise<string>;
|
|
61
35
|
}
|
|
62
|
-
interface
|
|
36
|
+
interface ExecuteDynamicFieldInput<Settings, Payload> {
|
|
63
37
|
settings: Settings;
|
|
64
38
|
payload: Payload;
|
|
65
39
|
cachedFields: {
|
|
@@ -68,20 +42,16 @@ interface ExecuteAutocompleteInput<Settings, Payload> {
|
|
|
68
42
|
page?: string;
|
|
69
43
|
}
|
|
70
44
|
declare type ExecuteInputField = 'payload' | 'settings';
|
|
71
|
-
/**
|
|
72
|
-
* Action is the beginning step for all partner actions. Entrypoints always start with the
|
|
73
|
-
* MapAndValidateInput step.
|
|
74
|
-
*/
|
|
75
45
|
export declare class Action<Settings, Payload extends JSONLikeObject> extends EventEmitter {
|
|
76
46
|
readonly steps: Steps<Settings, Payload>;
|
|
77
47
|
private extendRequest;
|
|
78
|
-
private
|
|
48
|
+
private dynamicFieldCache;
|
|
79
49
|
constructor(definition: ActionDefinition<Settings, Payload>, extendRequest?: RequestExtension<Settings, Payload>);
|
|
80
50
|
execute(data: ExecuteInput<Settings, Payload>): Promise<StepResult[]>;
|
|
81
|
-
|
|
51
|
+
executeDynamicField(field: string, data: ExecuteDynamicFieldInput<Settings, Payload>): any;
|
|
82
52
|
private loadDefinition;
|
|
83
53
|
private validatePayload;
|
|
84
|
-
private
|
|
54
|
+
private dynamicField;
|
|
85
55
|
private request;
|
|
86
56
|
private cachedRequest;
|
|
87
57
|
}
|
|
@@ -4,9 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.Action = exports.Validate = void 0;
|
|
7
|
-
// @ts-ignore no types
|
|
8
7
|
const ajv_human_errors_1 = require("@segment/ajv-human-errors");
|
|
9
8
|
const ajv_1 = __importDefault(require("ajv"));
|
|
9
|
+
const dayjs_1 = __importDefault(require("dayjs"));
|
|
10
10
|
const events_1 = require("events");
|
|
11
11
|
const node_cache_1 = __importDefault(require("node-cache"));
|
|
12
12
|
const create_request_client_1 = __importDefault(require("../create-request-client"));
|
|
@@ -17,47 +17,45 @@ const fetch_1 = require("../fetch");
|
|
|
17
17
|
const step_1 = require("./step");
|
|
18
18
|
class MapInput extends step_1.Step {
|
|
19
19
|
executeStep(data) {
|
|
20
|
-
// Transforms the initial payload (event) + action settings (from `subscriptions[0].mapping`)
|
|
21
|
-
// into input data that the action can use to talk to partner apis
|
|
22
20
|
if (data.mapping) {
|
|
23
|
-
// Technically we can't know whether or not `transform` returns the exact shape of Payload here, hence the casting
|
|
24
|
-
// It will be validated in subsequent steps
|
|
25
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
26
21
|
data.payload = mapping_kit_1.transform(data.mapping, data.payload);
|
|
27
22
|
}
|
|
28
23
|
return Promise.resolve('MapInput completed');
|
|
29
24
|
}
|
|
30
25
|
}
|
|
26
|
+
const ajv = new ajv_1.default({
|
|
27
|
+
coerceTypes: true,
|
|
28
|
+
allErrors: true,
|
|
29
|
+
verbose: true,
|
|
30
|
+
removeAdditional: true,
|
|
31
|
+
jsonPointers: true
|
|
32
|
+
});
|
|
33
|
+
ajv.addFormat('password', () => true);
|
|
34
|
+
ajv.addFormat('text', () => true);
|
|
35
|
+
ajv.addFormat('date-like', (data) => {
|
|
36
|
+
let date = dayjs_1.default(data);
|
|
37
|
+
if (String(Number(data)) === data) {
|
|
38
|
+
if (data.length === 13) {
|
|
39
|
+
date = dayjs_1.default(Number(data));
|
|
40
|
+
}
|
|
41
|
+
date = dayjs_1.default.unix(Number(data));
|
|
42
|
+
}
|
|
43
|
+
return date.isValid();
|
|
44
|
+
});
|
|
31
45
|
class Validate extends step_1.Step {
|
|
32
46
|
constructor(field, schema) {
|
|
33
47
|
super();
|
|
34
48
|
this.field = field;
|
|
35
|
-
const ajv = new ajv_1.default({
|
|
36
|
-
// Coerce types to be a bit more liberal.
|
|
37
|
-
coerceTypes: true,
|
|
38
|
-
// Return all validation errors, not just the first.
|
|
39
|
-
allErrors: true,
|
|
40
|
-
// Include reference to schema and data in error values.
|
|
41
|
-
verbose: true,
|
|
42
|
-
// Use a more parse-able format for JSON paths.
|
|
43
|
-
jsonPointers: true
|
|
44
|
-
});
|
|
45
49
|
this.validate = ajv.compile(schema);
|
|
46
50
|
}
|
|
47
51
|
executeStep(data) {
|
|
48
52
|
if (!this.validate(data[this.field])) {
|
|
49
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
50
53
|
throw new ajv_human_errors_1.AggregateAjvError(this.validate.errors);
|
|
51
54
|
}
|
|
52
55
|
return Promise.resolve('Validate completed');
|
|
53
56
|
}
|
|
54
57
|
}
|
|
55
58
|
exports.Validate = Validate;
|
|
56
|
-
/**
|
|
57
|
-
* Request handles delivering a payload to an external API. It uses the `fetch` API under the hood.
|
|
58
|
-
*
|
|
59
|
-
* The callback should be able to return the raw request instead of needing to do `return response.data` etc.
|
|
60
|
-
*/
|
|
61
59
|
class Request extends step_1.Step {
|
|
62
60
|
constructor(extendRequest, requestFn) {
|
|
63
61
|
super();
|
|
@@ -71,26 +69,17 @@ class Request extends step_1.Step {
|
|
|
71
69
|
}
|
|
72
70
|
const requestClient = this.createRequestClient(data);
|
|
73
71
|
const response = await this.requestFn(requestClient, data);
|
|
74
|
-
/**
|
|
75
|
-
* Try to use the parsed response `.data` or `.content` string
|
|
76
|
-
* @see {@link ../middleware/after-response/prepare-response.ts}
|
|
77
|
-
*/
|
|
78
72
|
if (response instanceof fetch_1.Response) {
|
|
79
73
|
return (_a = response.data) !== null && _a !== void 0 ? _a : response.content;
|
|
80
74
|
}
|
|
81
|
-
// otherwise, we don't really know what this is, so return as-is
|
|
82
75
|
return response;
|
|
83
76
|
}
|
|
84
77
|
createRequestClient(data) {
|
|
85
78
|
var _a, _b;
|
|
86
|
-
// TODO turn `extendRequest` into a beforeRequest hook
|
|
87
79
|
const options = (_b = (_a = this.extendRequest) === null || _a === void 0 ? void 0 : _a.call(this, data)) !== null && _b !== void 0 ? _b : {};
|
|
88
80
|
const client = create_request_client_1.default(options, {
|
|
89
81
|
afterResponse: [
|
|
90
|
-
// Keep track of the request(s) associated with a response
|
|
91
82
|
(request, options, response) => {
|
|
92
|
-
// TODO figure out the types here...
|
|
93
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
94
83
|
const modifiedResponse = response;
|
|
95
84
|
modifiedResponse.request = request;
|
|
96
85
|
modifiedResponse.options = options;
|
|
@@ -102,7 +91,6 @@ class Request extends step_1.Step {
|
|
|
102
91
|
return client;
|
|
103
92
|
}
|
|
104
93
|
}
|
|
105
|
-
// CachedRequest is like Request but cached. Next question.
|
|
106
94
|
class CachedRequest extends Request {
|
|
107
95
|
constructor(extension, config) {
|
|
108
96
|
super(extension);
|
|
@@ -134,31 +122,20 @@ class CachedRequest extends Request {
|
|
|
134
122
|
throw e;
|
|
135
123
|
}
|
|
136
124
|
}
|
|
137
|
-
// Only cache if value is not negative *or* negative option is set. Negative caching is off by
|
|
138
|
-
// default because the common cases are: A) auth token generation, which should never be
|
|
139
|
-
// negative, and B) create-or-update patterns, where the resource should exist after the first
|
|
140
|
-
// negative value.
|
|
141
125
|
if ((v !== null && v !== undefined) || this.negative) {
|
|
142
126
|
this.cache.set(k, v);
|
|
143
127
|
}
|
|
144
128
|
return 'cache miss';
|
|
145
129
|
}
|
|
146
130
|
}
|
|
147
|
-
/**
|
|
148
|
-
* Action is the beginning step for all partner actions. Entrypoints always start with the
|
|
149
|
-
* MapAndValidateInput step.
|
|
150
|
-
*/
|
|
151
131
|
class Action extends events_1.EventEmitter {
|
|
152
132
|
constructor(definition, extendRequest) {
|
|
153
133
|
super();
|
|
154
134
|
this.steps = new step_1.Steps();
|
|
155
135
|
const step = new MapInput();
|
|
156
136
|
this.steps.push(step);
|
|
157
|
-
this.
|
|
137
|
+
this.dynamicFieldCache = {};
|
|
158
138
|
if (extendRequest) {
|
|
159
|
-
// This must come before we load the definition because
|
|
160
|
-
// it instantiates "steps" with whatever request extensions
|
|
161
|
-
// are defined at that moment in time
|
|
162
139
|
this.extendRequest = extendRequest;
|
|
163
140
|
}
|
|
164
141
|
this.loadDefinition(definition);
|
|
@@ -171,15 +148,14 @@ class Action extends events_1.EventEmitter {
|
|
|
171
148
|
}
|
|
172
149
|
return results;
|
|
173
150
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
if (!this.autocompleteCache[field]) {
|
|
151
|
+
executeDynamicField(field, data) {
|
|
152
|
+
if (!this.dynamicFieldCache[field]) {
|
|
177
153
|
return {
|
|
178
154
|
data: [],
|
|
179
155
|
pagination: {}
|
|
180
156
|
};
|
|
181
157
|
}
|
|
182
|
-
const step = new Request(this.extendRequest, this.
|
|
158
|
+
const step = new Request(this.extendRequest, this.dynamicFieldCache[field]);
|
|
183
159
|
return step.executeStep(data);
|
|
184
160
|
}
|
|
185
161
|
loadDefinition(definition) {
|
|
@@ -187,8 +163,8 @@ class Action extends events_1.EventEmitter {
|
|
|
187
163
|
if (definition.fields) {
|
|
188
164
|
this.validatePayload(definition.fields);
|
|
189
165
|
}
|
|
190
|
-
Object.entries((_a = definition.
|
|
191
|
-
this.
|
|
166
|
+
Object.entries((_a = definition.dynamicFields) !== null && _a !== void 0 ? _a : {}).forEach(([field, callback]) => {
|
|
167
|
+
this.dynamicField(field, callback);
|
|
192
168
|
});
|
|
193
169
|
Object.entries((_b = definition.cachedFields) !== null && _b !== void 0 ? _b : {}).forEach(([field, cacheConfig]) => {
|
|
194
170
|
this.cachedRequest({
|
|
@@ -204,8 +180,8 @@ class Action extends events_1.EventEmitter {
|
|
|
204
180
|
const step = new Validate('payload', fields_to_jsonschema_1.fieldsToJsonSchema(fields));
|
|
205
181
|
this.steps.push(step);
|
|
206
182
|
}
|
|
207
|
-
|
|
208
|
-
this.
|
|
183
|
+
dynamicField(field, callback) {
|
|
184
|
+
this.dynamicFieldCache[field] = callback;
|
|
209
185
|
}
|
|
210
186
|
request(requestFn) {
|
|
211
187
|
const step = new Request(this.extendRequest, requestFn);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"action.js","sourceRoot":"","sources":["../../../src/destination-kit/action.ts"],"names":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"action.js","sourceRoot":"","sources":["../../../src/destination-kit/action.ts"],"names":[],"mappings":";;;;;;AACA,gEAA6D;AAC7D,8CAAqB;AACrB,kDAAyB;AACzB,mCAAqC;AACrC,4DAAkC;AAClC,qFAA0D;AAC1D,gCAA4B;AAE5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I,CAAC,CAAA;IACvB,CAAC;IAEO,YAAY,CAAC,KAAa,EAAE,QAAsC;QACxE,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,GAAG,QAAQ,CAAA;IAC1C,CAAC;IAEO,OAAO,CAAC,SAAuC;QACrD,MAAM,IAAI,GAAG,IAAI,OAAO,CAAoB,IAAI,CAAC,aAAa,EAAE,SAAS,CAAC,CAAA;QAC1E,IAAI,CAAC,EAAE,CAAC,UAAU,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAA;QAClE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACvB,CAAC;IAEO,aAAa,CAAC,MAA8C;QAClE,MAAM,IAAI,GAAG,IAAI,aAAa,CAAC,IAAI,CAAC,aAAa,EAAE,MAAM,CAAC,CAAA;QAC1D,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACvB,CAAC;CACF;AAzFD,wBAyFC"}
|
|
@@ -1,15 +1,63 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.jsonSchemaToFields = exports.fieldsToJsonSchema = void 0;
|
|
4
|
+
function toJsonSchemaType(type) {
|
|
5
|
+
switch (type) {
|
|
6
|
+
case 'string':
|
|
7
|
+
case 'text':
|
|
8
|
+
case 'password':
|
|
9
|
+
return 'string';
|
|
10
|
+
case 'datetime':
|
|
11
|
+
return ['string', 'number'];
|
|
12
|
+
default:
|
|
13
|
+
return type;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
4
16
|
function fieldsToJsonSchema(fields = {}) {
|
|
5
17
|
const required = [];
|
|
6
18
|
const properties = {};
|
|
7
|
-
for (const key of Object.
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
19
|
+
for (const [key, field] of Object.entries(fields)) {
|
|
20
|
+
const schemaType = toJsonSchemaType(field.type);
|
|
21
|
+
let schema = {
|
|
22
|
+
title: field.label,
|
|
23
|
+
description: field.description,
|
|
24
|
+
type: schemaType,
|
|
25
|
+
format: field.format,
|
|
26
|
+
default: field.default
|
|
27
|
+
};
|
|
28
|
+
if (field.type === 'datetime') {
|
|
29
|
+
schema.format = 'date-like';
|
|
30
|
+
schema.tsType = 'string | number';
|
|
31
|
+
}
|
|
32
|
+
else if (field.type === 'password') {
|
|
33
|
+
schema.format = 'password';
|
|
34
|
+
}
|
|
35
|
+
else if (field.type === 'text') {
|
|
36
|
+
schema.format = 'text';
|
|
37
|
+
}
|
|
38
|
+
if (field.dynamic) {
|
|
39
|
+
schema.autocomplete = true;
|
|
40
|
+
schema.dynamic = true;
|
|
41
|
+
}
|
|
42
|
+
if (field.allowNull) {
|
|
43
|
+
schema.type = [].concat(schemaType, 'null');
|
|
44
|
+
if (typeof schema.tsType === 'string' && !schema.tsType.includes('null')) {
|
|
45
|
+
schema.tsType += ' | null';
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (field.multiple) {
|
|
49
|
+
schema.items = { type: schemaType };
|
|
50
|
+
schema.type = 'array';
|
|
51
|
+
}
|
|
52
|
+
if (schemaType === 'object' && field.properties) {
|
|
53
|
+
if (field.multiple) {
|
|
54
|
+
schema.items = fieldsToJsonSchema(field.properties);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
schema = { ...schema, ...fieldsToJsonSchema(field.properties) };
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
properties[key] = schema;
|
|
13
61
|
if (field.required) {
|
|
14
62
|
required.push(key);
|
|
15
63
|
}
|
|
@@ -23,16 +71,36 @@ function fieldsToJsonSchema(fields = {}) {
|
|
|
23
71
|
};
|
|
24
72
|
}
|
|
25
73
|
exports.fieldsToJsonSchema = fieldsToJsonSchema;
|
|
74
|
+
function extractType(schema) {
|
|
75
|
+
var _a;
|
|
76
|
+
if (schema.type === 'array') {
|
|
77
|
+
return (_a = schema.items) === null || _a === void 0 ? void 0 : _a.type;
|
|
78
|
+
}
|
|
79
|
+
if (Array.isArray(schema.type)) {
|
|
80
|
+
return schema.type.find((t) => t !== 'null');
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
return schema.type;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
26
86
|
function jsonSchemaToFields(schema = {}) {
|
|
27
|
-
var _a, _b;
|
|
87
|
+
var _a, _b, _c, _d;
|
|
28
88
|
const requiredFields = (_a = schema.required) !== null && _a !== void 0 ? _a : [];
|
|
29
89
|
const properties = (_b = schema.properties) !== null && _b !== void 0 ? _b : {};
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
90
|
+
const fields = {};
|
|
91
|
+
for (const [key, property] of Object.entries(properties)) {
|
|
92
|
+
const field = {
|
|
93
|
+
label: (_c = property.title) !== null && _c !== void 0 ? _c : '',
|
|
94
|
+
description: (_d = property.description) !== null && _d !== void 0 ? _d : '',
|
|
95
|
+
default: property.default,
|
|
96
|
+
type: extractType(schema),
|
|
97
|
+
allowNull: Array.isArray(property.type) ? property.type.includes('null') : property.type === 'null',
|
|
98
|
+
multiple: schema.type === 'array',
|
|
99
|
+
required: requiredFields.includes(key)
|
|
100
|
+
};
|
|
101
|
+
fields[key] = field;
|
|
34
102
|
}
|
|
35
|
-
return
|
|
103
|
+
return fields;
|
|
36
104
|
}
|
|
37
105
|
exports.jsonSchemaToFields = jsonSchemaToFields;
|
|
38
106
|
//# sourceMappingURL=fields-to-jsonschema.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fields-to-jsonschema.js","sourceRoot":"","sources":["../../../src/destination-kit/fields-to-jsonschema.ts"],"names":[],"mappings":";;;AAGA,SAAgB,kBAAkB,CAAC,SAAqC,EAAE;IACxE,MAAM,QAAQ,GAAa,EAAE,CAAA;IAC7B,MAAM,UAAU,GAAgC,EAAE,CAAA;IAEl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;IAED,OAAO,MAAM,CAAA;AACf,CAAC;AApBD,gDAoBC"}
|
|
@@ -23,17 +23,12 @@ interface PartnerActions<Settings, Payload extends JSONLikeObject> {
|
|
|
23
23
|
[key: string]: Action<Settings, Payload>;
|
|
24
24
|
}
|
|
25
25
|
export interface DestinationDefinition<Settings = unknown> {
|
|
26
|
-
/** The name of the destination */
|
|
27
26
|
name: string;
|
|
28
|
-
/** An optional function to extend requests sent from the destination (including all actions) */
|
|
29
27
|
extendRequest?: RequestExtension<Settings>;
|
|
30
|
-
/** Optional authentication configuration */
|
|
31
28
|
authentication?: AuthenticationScheme<Settings>;
|
|
32
|
-
/** Actions */
|
|
33
29
|
actions: {
|
|
34
30
|
[key: string]: ActionDefinition<Settings>;
|
|
35
31
|
};
|
|
36
|
-
/** Subscription presets automatically applied in quick setup */
|
|
37
32
|
presets?: Subscription[];
|
|
38
33
|
}
|
|
39
34
|
export interface Subscription {
|
|
@@ -51,7 +46,6 @@ interface Authentication<Settings> {
|
|
|
51
46
|
testAuthentication: (request: RequestClient, input: TestAuthSettings<Settings>) => Promise<unknown> | unknown;
|
|
52
47
|
}
|
|
53
48
|
export interface CustomAuthentication<Settings> extends Authentication<Settings> {
|
|
54
|
-
/** Typically used for "API Key" authentication. */
|
|
55
49
|
scheme: 'custom';
|
|
56
50
|
}
|
|
57
51
|
export interface BasicAuthentication<Settings> extends Authentication<Settings> {
|
|
@@ -80,10 +74,6 @@ export declare class Destination<Settings = JSONObject> {
|
|
|
80
74
|
private partnerAction;
|
|
81
75
|
protected executeAction(actionSlug: string, { event, mapping, settings }: EventInput<Settings>): Promise<StepResult[]>;
|
|
82
76
|
private onSubscription;
|
|
83
|
-
/**
|
|
84
|
-
* Note: Until we move subscriptions upstream (into int-consumer) we've opted
|
|
85
|
-
* to have failures abort the set of subscriptions and get potentially retried by centrifuge
|
|
86
|
-
*/
|
|
87
77
|
onEvent(event: SegmentEvent, settings: JSONObject, onComplete?: (stats: SubscriptionStats) => void): Promise<StepResult[]>;
|
|
88
78
|
private getSubscriptions;
|
|
89
79
|
private getDestinationSettings;
|
|
@@ -5,13 +5,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.Destination = exports.jsonSchemaToFields = exports.fieldsToJsonSchema = void 0;
|
|
7
7
|
const fab5_subscriptions_1 = require("@segment/fab5-subscriptions");
|
|
8
|
+
const ts_custom_error_1 = require("ts-custom-error");
|
|
8
9
|
const action_1 = require("./action");
|
|
9
10
|
const time_1 = require("../time");
|
|
10
11
|
const fields_to_jsonschema_1 = require("./fields-to-jsonschema");
|
|
11
12
|
Object.defineProperty(exports, "fieldsToJsonSchema", { enumerable: true, get: function () { return fields_to_jsonschema_1.fieldsToJsonSchema; } });
|
|
12
13
|
Object.defineProperty(exports, "jsonSchemaToFields", { enumerable: true, get: function () { return fields_to_jsonschema_1.jsonSchemaToFields; } });
|
|
13
|
-
const errors_1 = require("../errors");
|
|
14
14
|
const create_request_client_1 = __importDefault(require("../create-request-client"));
|
|
15
|
+
class UnsupportedActionError extends ts_custom_error_1.CustomError {
|
|
16
|
+
constructor(action) {
|
|
17
|
+
super(`"${action}" is not a supported cloud-mode action.`);
|
|
18
|
+
this.ignored = true;
|
|
19
|
+
this.status = 'UNSUPPORTED_EVENT_TYPE';
|
|
20
|
+
this.retry = false;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
15
23
|
class Destination {
|
|
16
24
|
constructor(destination) {
|
|
17
25
|
var _a;
|
|
@@ -21,7 +29,6 @@ class Destination {
|
|
|
21
29
|
this.actions = {};
|
|
22
30
|
this.authentication = destination.authentication;
|
|
23
31
|
this.responses = [];
|
|
24
|
-
// Convert to complete JSON Schema
|
|
25
32
|
if ((_a = this.authentication) === null || _a === void 0 ? void 0 : _a.fields) {
|
|
26
33
|
this.settingsSchema = fields_to_jsonschema_1.fieldsToJsonSchema(this.authentication.fields);
|
|
27
34
|
}
|
|
@@ -61,7 +68,7 @@ class Destination {
|
|
|
61
68
|
executeAction(actionSlug, { event, mapping, settings }) {
|
|
62
69
|
const action = this.actions[actionSlug];
|
|
63
70
|
if (!action) {
|
|
64
|
-
throw new
|
|
71
|
+
throw new UnsupportedActionError(actionSlug);
|
|
65
72
|
}
|
|
66
73
|
return action.execute({
|
|
67
74
|
cachedFields: {},
|
|
@@ -99,6 +106,9 @@ class Destination {
|
|
|
99
106
|
catch (error) {
|
|
100
107
|
state = 'errored';
|
|
101
108
|
results = [{ error }];
|
|
109
|
+
if (error.name === 'AggregateAjvError' || error.name === 'ValidationError') {
|
|
110
|
+
error.status = 400;
|
|
111
|
+
}
|
|
102
112
|
throw error;
|
|
103
113
|
}
|
|
104
114
|
finally {
|
|
@@ -119,10 +129,6 @@ class Destination {
|
|
|
119
129
|
});
|
|
120
130
|
}
|
|
121
131
|
}
|
|
122
|
-
/**
|
|
123
|
-
* Note: Until we move subscriptions upstream (into int-consumer) we've opted
|
|
124
|
-
* to have failures abort the set of subscriptions and get potentially retried by centrifuge
|
|
125
|
-
*/
|
|
126
132
|
async onEvent(event, settings, onComplete) {
|
|
127
133
|
const subscriptions = this.getSubscriptions(settings);
|
|
128
134
|
const destinationSettings = this.getDestinationSettings(settings);
|
|
@@ -133,7 +139,6 @@ class Destination {
|
|
|
133
139
|
getSubscriptions(settings) {
|
|
134
140
|
const { subscription, subscriptions } = settings;
|
|
135
141
|
let parsedSubscriptions;
|
|
136
|
-
// To support event tester we need to parse and validate multiple subscriptions from the settings
|
|
137
142
|
if (subscription) {
|
|
138
143
|
parsedSubscriptions = [subscription];
|
|
139
144
|
}
|