@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
package/dist/cjs/time.js
CHANGED
|
@@ -1,16 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.duration = exports.time = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Gets hrtime for logging/metrics.
|
|
6
|
-
*/
|
|
7
4
|
function time() {
|
|
8
5
|
return process.hrtime.bigint();
|
|
9
6
|
}
|
|
10
7
|
exports.time = time;
|
|
11
|
-
/**
|
|
12
|
-
* Calculates the duration in decimal milliseconds for logging/metrics purposes.
|
|
13
|
-
*/
|
|
14
8
|
function duration(start, stop) {
|
|
15
9
|
return Number(stop - start) / 1000000;
|
|
16
10
|
}
|
package/dist/cjs/time.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time.js","sourceRoot":"","sources":["../../src/time.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"time.js","sourceRoot":"","sources":["../../src/time.ts"],"names":[],"mappings":";;;AAGA,SAAgB,IAAI;IAClB,OAAO,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,CAAA;AAChC,CAAC;AAFD,oBAEC;AAKD,SAAgB,QAAQ,CAAC,KAAa,EAAE,IAAY;IAClD,OAAO,MAAM,CAAC,IAAI,GAAG,KAAK,CAAC,GAAG,OAAO,CAAA;AACvC,CAAC;AAFD,4BAEC"}
|
package/dist/cjs/types.d.ts
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
/** A modified response object that is handled by the `prepareResponse` hook */
|
|
2
1
|
export interface ModifiedResponse<T = unknown> extends Response {
|
|
3
|
-
/** The raw response content as a string – same as `await response.text()` */
|
|
4
2
|
content: string;
|
|
5
|
-
/** The parsed content string into a JavaScript object, if applicable */
|
|
6
3
|
data: unknown extends T ? undefined | unknown : T;
|
|
7
|
-
/** The headers object with a shortcut method to get headers as an object */
|
|
8
4
|
headers: Headers & {
|
|
9
5
|
toJSON: () => Record<string, string>;
|
|
10
6
|
};
|
|
@@ -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>>;
|
|
@@ -8,22 +8,15 @@ const baseClient = createInstance({
|
|
|
8
8
|
'user-agent': 'Segment'
|
|
9
9
|
},
|
|
10
10
|
beforeRequest: [
|
|
11
|
-
// Automatically handle username/password -> basic auth header
|
|
12
11
|
addBasicAuthHeader
|
|
13
12
|
],
|
|
14
13
|
afterResponse: [prepareResponse, prepareHeaders]
|
|
15
14
|
});
|
|
16
|
-
/**
|
|
17
|
-
* Creates a request client instance with Segment's default configuration + custom options
|
|
18
|
-
*/
|
|
19
15
|
export default function createRequestClient(...requestOptions) {
|
|
20
16
|
let client = baseClient;
|
|
21
|
-
// TODO include `data` bundle in before/after hooks
|
|
22
|
-
// TODO expose before/after hooks to destination definition and action definition?
|
|
23
17
|
for (const options of requestOptions !== null && requestOptions !== void 0 ? requestOptions : []) {
|
|
24
18
|
client = client.extend(options);
|
|
25
19
|
}
|
|
26
|
-
// Limit request client interface and handle basic auth scheme
|
|
27
20
|
return (url, options) => {
|
|
28
21
|
return client(url, options);
|
|
29
22
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-request-client.js","sourceRoot":"","sources":["../../src/create-request-client.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,MAAM,mDAAmD,CAAA;AAClF,OAAO,cAAc,MAAM,6CAA6C,CAAA;AACxE,OAAO,eAAe,MAAM,8CAA8C,CAAA;AAC1E,OAAO,cAAqD,MAAM,kBAAkB,CAAA;AAGpF,MAAM,UAAU,GAAG,cAAc,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,OAAO,kBAAkB,MAAM,mDAAmD,CAAA;AAClF,OAAO,cAAc,MAAM,6CAA6C,CAAA;AACxE,OAAO,eAAe,MAAM,8CAA8C,CAAA;AAC1E,OAAO,cAAqD,MAAM,kBAAkB,CAAA;AAGpF,MAAM,UAAU,GAAG,cAAc,CAAC;IAChC,OAAO,EAAE,KAAK;IACd,OAAO,EAAE;QACP,YAAY,EAAE,SAAS;KACxB;IACD,aAAa,EAAE;QAEb,kBAAkB;KACnB;IACD,aAAa,EAAE,CAAC,eAAe,EAAE,cAAc,CAAC;CACjD,CAAC,CAAA;AAOF,MAAM,CAAC,OAAO,UAAU,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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-test-event.js","sourceRoot":"","sources":["../../src/create-test-event.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"create-test-event.js","sourceRoot":"","sources":["../../src/create-test-event.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,cAAc,CAAA;AAG3C,MAAM,UAAU,eAAe,CAAC,QAA+B,EAAE;IAC/D,OAAO;QACL,WAAW,EAAE,MAAM,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,MAAM,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"}
|
|
@@ -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>;
|
|
@@ -6,7 +6,6 @@ class TestDestination extends Destination {
|
|
|
6
6
|
super(destination);
|
|
7
7
|
this.responses = [];
|
|
8
8
|
}
|
|
9
|
-
/** Testing method that runs an action e2e while allowing slightly more flexible inputs */
|
|
10
9
|
async testAction(action, { event, mapping, settings, useDefaultMappings }) {
|
|
11
10
|
mapping = mapping !== null && mapping !== void 0 ? mapping : {};
|
|
12
11
|
if (useDefaultMappings) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-test-integration.js","sourceRoot":"","sources":["../../src/create-test-integration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AA8BxC,MAAM,eAAmB,SAAQ,WAAc;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,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AA8BxC,MAAM,eAAmB,SAAQ,WAAc;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,SAAS,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,eAAe,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,MAAM,UAAU,qBAAqB,CAAI,WAAqC;IAC5E,OAAO,IAAI,eAAe,CAAC,WAAW,CAAC,CAAA;AACzC,CAAC"}
|
|
@@ -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
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
// @ts-ignore no types
|
|
2
1
|
import { AggregateAjvError } from '@segment/ajv-human-errors';
|
|
3
2
|
import Ajv from 'ajv';
|
|
3
|
+
import dayjs from 'dayjs';
|
|
4
4
|
import { EventEmitter } from 'events';
|
|
5
5
|
import NodeCache from 'node-cache';
|
|
6
6
|
import createRequestClient from '../create-request-client';
|
|
@@ -11,46 +11,44 @@ import { Response } from '../fetch';
|
|
|
11
11
|
import { Step, Steps } from './step';
|
|
12
12
|
class MapInput extends Step {
|
|
13
13
|
executeStep(data) {
|
|
14
|
-
// Transforms the initial payload (event) + action settings (from `subscriptions[0].mapping`)
|
|
15
|
-
// into input data that the action can use to talk to partner apis
|
|
16
14
|
if (data.mapping) {
|
|
17
|
-
// Technically we can't know whether or not `transform` returns the exact shape of Payload here, hence the casting
|
|
18
|
-
// It will be validated in subsequent steps
|
|
19
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
20
15
|
data.payload = transform(data.mapping, data.payload);
|
|
21
16
|
}
|
|
22
17
|
return Promise.resolve('MapInput completed');
|
|
23
18
|
}
|
|
24
19
|
}
|
|
20
|
+
const ajv = new Ajv({
|
|
21
|
+
coerceTypes: true,
|
|
22
|
+
allErrors: true,
|
|
23
|
+
verbose: true,
|
|
24
|
+
removeAdditional: true,
|
|
25
|
+
jsonPointers: true
|
|
26
|
+
});
|
|
27
|
+
ajv.addFormat('password', () => true);
|
|
28
|
+
ajv.addFormat('text', () => true);
|
|
29
|
+
ajv.addFormat('date-like', (data) => {
|
|
30
|
+
let date = dayjs(data);
|
|
31
|
+
if (String(Number(data)) === data) {
|
|
32
|
+
if (data.length === 13) {
|
|
33
|
+
date = dayjs(Number(data));
|
|
34
|
+
}
|
|
35
|
+
date = dayjs.unix(Number(data));
|
|
36
|
+
}
|
|
37
|
+
return date.isValid();
|
|
38
|
+
});
|
|
25
39
|
export class Validate extends Step {
|
|
26
40
|
constructor(field, schema) {
|
|
27
41
|
super();
|
|
28
42
|
this.field = field;
|
|
29
|
-
const ajv = new Ajv({
|
|
30
|
-
// Coerce types to be a bit more liberal.
|
|
31
|
-
coerceTypes: true,
|
|
32
|
-
// Return all validation errors, not just the first.
|
|
33
|
-
allErrors: true,
|
|
34
|
-
// Include reference to schema and data in error values.
|
|
35
|
-
verbose: true,
|
|
36
|
-
// Use a more parse-able format for JSON paths.
|
|
37
|
-
jsonPointers: true
|
|
38
|
-
});
|
|
39
43
|
this.validate = ajv.compile(schema);
|
|
40
44
|
}
|
|
41
45
|
executeStep(data) {
|
|
42
46
|
if (!this.validate(data[this.field])) {
|
|
43
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
44
47
|
throw new AggregateAjvError(this.validate.errors);
|
|
45
48
|
}
|
|
46
49
|
return Promise.resolve('Validate completed');
|
|
47
50
|
}
|
|
48
51
|
}
|
|
49
|
-
/**
|
|
50
|
-
* Request handles delivering a payload to an external API. It uses the `fetch` API under the hood.
|
|
51
|
-
*
|
|
52
|
-
* The callback should be able to return the raw request instead of needing to do `return response.data` etc.
|
|
53
|
-
*/
|
|
54
52
|
class Request extends Step {
|
|
55
53
|
constructor(extendRequest, requestFn) {
|
|
56
54
|
super();
|
|
@@ -64,26 +62,17 @@ class Request extends Step {
|
|
|
64
62
|
}
|
|
65
63
|
const requestClient = this.createRequestClient(data);
|
|
66
64
|
const response = await this.requestFn(requestClient, data);
|
|
67
|
-
/**
|
|
68
|
-
* Try to use the parsed response `.data` or `.content` string
|
|
69
|
-
* @see {@link ../middleware/after-response/prepare-response.ts}
|
|
70
|
-
*/
|
|
71
65
|
if (response instanceof Response) {
|
|
72
66
|
return (_a = response.data) !== null && _a !== void 0 ? _a : response.content;
|
|
73
67
|
}
|
|
74
|
-
// otherwise, we don't really know what this is, so return as-is
|
|
75
68
|
return response;
|
|
76
69
|
}
|
|
77
70
|
createRequestClient(data) {
|
|
78
71
|
var _a, _b;
|
|
79
|
-
// TODO turn `extendRequest` into a beforeRequest hook
|
|
80
72
|
const options = (_b = (_a = this.extendRequest) === null || _a === void 0 ? void 0 : _a.call(this, data)) !== null && _b !== void 0 ? _b : {};
|
|
81
73
|
const client = createRequestClient(options, {
|
|
82
74
|
afterResponse: [
|
|
83
|
-
// Keep track of the request(s) associated with a response
|
|
84
75
|
(request, options, response) => {
|
|
85
|
-
// TODO figure out the types here...
|
|
86
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
87
76
|
const modifiedResponse = response;
|
|
88
77
|
modifiedResponse.request = request;
|
|
89
78
|
modifiedResponse.options = options;
|
|
@@ -95,7 +84,6 @@ class Request extends Step {
|
|
|
95
84
|
return client;
|
|
96
85
|
}
|
|
97
86
|
}
|
|
98
|
-
// CachedRequest is like Request but cached. Next question.
|
|
99
87
|
class CachedRequest extends Request {
|
|
100
88
|
constructor(extension, config) {
|
|
101
89
|
super(extension);
|
|
@@ -127,31 +115,20 @@ class CachedRequest extends Request {
|
|
|
127
115
|
throw e;
|
|
128
116
|
}
|
|
129
117
|
}
|
|
130
|
-
// Only cache if value is not negative *or* negative option is set. Negative caching is off by
|
|
131
|
-
// default because the common cases are: A) auth token generation, which should never be
|
|
132
|
-
// negative, and B) create-or-update patterns, where the resource should exist after the first
|
|
133
|
-
// negative value.
|
|
134
118
|
if ((v !== null && v !== undefined) || this.negative) {
|
|
135
119
|
this.cache.set(k, v);
|
|
136
120
|
}
|
|
137
121
|
return 'cache miss';
|
|
138
122
|
}
|
|
139
123
|
}
|
|
140
|
-
/**
|
|
141
|
-
* Action is the beginning step for all partner actions. Entrypoints always start with the
|
|
142
|
-
* MapAndValidateInput step.
|
|
143
|
-
*/
|
|
144
124
|
export class Action extends EventEmitter {
|
|
145
125
|
constructor(definition, extendRequest) {
|
|
146
126
|
super();
|
|
147
127
|
this.steps = new Steps();
|
|
148
128
|
const step = new MapInput();
|
|
149
129
|
this.steps.push(step);
|
|
150
|
-
this.
|
|
130
|
+
this.dynamicFieldCache = {};
|
|
151
131
|
if (extendRequest) {
|
|
152
|
-
// This must come before we load the definition because
|
|
153
|
-
// it instantiates "steps" with whatever request extensions
|
|
154
|
-
// are defined at that moment in time
|
|
155
132
|
this.extendRequest = extendRequest;
|
|
156
133
|
}
|
|
157
134
|
this.loadDefinition(definition);
|
|
@@ -164,15 +141,14 @@ export class Action extends EventEmitter {
|
|
|
164
141
|
}
|
|
165
142
|
return results;
|
|
166
143
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
if (!this.autocompleteCache[field]) {
|
|
144
|
+
executeDynamicField(field, data) {
|
|
145
|
+
if (!this.dynamicFieldCache[field]) {
|
|
170
146
|
return {
|
|
171
147
|
data: [],
|
|
172
148
|
pagination: {}
|
|
173
149
|
};
|
|
174
150
|
}
|
|
175
|
-
const step = new Request(this.extendRequest, this.
|
|
151
|
+
const step = new Request(this.extendRequest, this.dynamicFieldCache[field]);
|
|
176
152
|
return step.executeStep(data);
|
|
177
153
|
}
|
|
178
154
|
loadDefinition(definition) {
|
|
@@ -180,8 +156,8 @@ export class Action extends EventEmitter {
|
|
|
180
156
|
if (definition.fields) {
|
|
181
157
|
this.validatePayload(definition.fields);
|
|
182
158
|
}
|
|
183
|
-
Object.entries((_a = definition.
|
|
184
|
-
this.
|
|
159
|
+
Object.entries((_a = definition.dynamicFields) !== null && _a !== void 0 ? _a : {}).forEach(([field, callback]) => {
|
|
160
|
+
this.dynamicField(field, callback);
|
|
185
161
|
});
|
|
186
162
|
Object.entries((_b = definition.cachedFields) !== null && _b !== void 0 ? _b : {}).forEach(([field, cacheConfig]) => {
|
|
187
163
|
this.cachedRequest({
|
|
@@ -197,8 +173,8 @@ export class Action extends EventEmitter {
|
|
|
197
173
|
const step = new Validate('payload', fieldsToJsonSchema(fields));
|
|
198
174
|
this.steps.push(step);
|
|
199
175
|
}
|
|
200
|
-
|
|
201
|
-
this.
|
|
176
|
+
dynamicField(field, callback) {
|
|
177
|
+
this.dynamicFieldCache[field] = callback;
|
|
202
178
|
}
|
|
203
179
|
request(requestFn) {
|
|
204
180
|
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,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,GAAG,MAAM,KAAK,CAAA;AACrB,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AACrC,OAAO,SAAS,MAAM,YAAY,CAAA;AAClC,OAAO,mBAAmB,MAAM,0BAA0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,UAAU,CAAC,OAAO,CAAC,CAAA;SACjC;IACH,CAAC;IAEO,eAAe,CAAC,MAAkC;QACxD,MAAM,IAAI,GAAG,IAAI,QAAQ,CAAC,SAAS,EAAE,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAA;QAChE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,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"}
|
|
@@ -1,12 +1,60 @@
|
|
|
1
|
+
function toJsonSchemaType(type) {
|
|
2
|
+
switch (type) {
|
|
3
|
+
case 'string':
|
|
4
|
+
case 'text':
|
|
5
|
+
case 'password':
|
|
6
|
+
return 'string';
|
|
7
|
+
case 'datetime':
|
|
8
|
+
return ['string', 'number'];
|
|
9
|
+
default:
|
|
10
|
+
return type;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
1
13
|
export function fieldsToJsonSchema(fields = {}) {
|
|
2
14
|
const required = [];
|
|
3
15
|
const properties = {};
|
|
4
|
-
for (const key of Object.
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
16
|
+
for (const [key, field] of Object.entries(fields)) {
|
|
17
|
+
const schemaType = toJsonSchemaType(field.type);
|
|
18
|
+
let schema = {
|
|
19
|
+
title: field.label,
|
|
20
|
+
description: field.description,
|
|
21
|
+
type: schemaType,
|
|
22
|
+
format: field.format,
|
|
23
|
+
default: field.default
|
|
24
|
+
};
|
|
25
|
+
if (field.type === 'datetime') {
|
|
26
|
+
schema.format = 'date-like';
|
|
27
|
+
schema.tsType = 'string | number';
|
|
28
|
+
}
|
|
29
|
+
else if (field.type === 'password') {
|
|
30
|
+
schema.format = 'password';
|
|
31
|
+
}
|
|
32
|
+
else if (field.type === 'text') {
|
|
33
|
+
schema.format = 'text';
|
|
34
|
+
}
|
|
35
|
+
if (field.dynamic) {
|
|
36
|
+
schema.autocomplete = true;
|
|
37
|
+
schema.dynamic = true;
|
|
38
|
+
}
|
|
39
|
+
if (field.allowNull) {
|
|
40
|
+
schema.type = [].concat(schemaType, 'null');
|
|
41
|
+
if (typeof schema.tsType === 'string' && !schema.tsType.includes('null')) {
|
|
42
|
+
schema.tsType += ' | null';
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (field.multiple) {
|
|
46
|
+
schema.items = { type: schemaType };
|
|
47
|
+
schema.type = 'array';
|
|
48
|
+
}
|
|
49
|
+
if (schemaType === 'object' && field.properties) {
|
|
50
|
+
if (field.multiple) {
|
|
51
|
+
schema.items = fieldsToJsonSchema(field.properties);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
schema = { ...schema, ...fieldsToJsonSchema(field.properties) };
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
properties[key] = schema;
|
|
10
58
|
if (field.required) {
|
|
11
59
|
required.push(key);
|
|
12
60
|
}
|
|
@@ -19,15 +67,35 @@ export function fieldsToJsonSchema(fields = {}) {
|
|
|
19
67
|
required
|
|
20
68
|
};
|
|
21
69
|
}
|
|
70
|
+
function extractType(schema) {
|
|
71
|
+
var _a;
|
|
72
|
+
if (schema.type === 'array') {
|
|
73
|
+
return (_a = schema.items) === null || _a === void 0 ? void 0 : _a.type;
|
|
74
|
+
}
|
|
75
|
+
if (Array.isArray(schema.type)) {
|
|
76
|
+
return schema.type.find((t) => t !== 'null');
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
return schema.type;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
22
82
|
export function jsonSchemaToFields(schema = {}) {
|
|
23
|
-
var _a, _b;
|
|
83
|
+
var _a, _b, _c, _d;
|
|
24
84
|
const requiredFields = (_a = schema.required) !== null && _a !== void 0 ? _a : [];
|
|
25
85
|
const properties = (_b = schema.properties) !== null && _b !== void 0 ? _b : {};
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
86
|
+
const fields = {};
|
|
87
|
+
for (const [key, property] of Object.entries(properties)) {
|
|
88
|
+
const field = {
|
|
89
|
+
label: (_c = property.title) !== null && _c !== void 0 ? _c : '',
|
|
90
|
+
description: (_d = property.description) !== null && _d !== void 0 ? _d : '',
|
|
91
|
+
default: property.default,
|
|
92
|
+
type: extractType(schema),
|
|
93
|
+
allowNull: Array.isArray(property.type) ? property.type.includes('null') : property.type === 'null',
|
|
94
|
+
multiple: schema.type === 'array',
|
|
95
|
+
required: requiredFields.includes(key)
|
|
96
|
+
};
|
|
97
|
+
fields[key] = field;
|
|
30
98
|
}
|
|
31
|
-
return
|
|
99
|
+
return fields;
|
|
32
100
|
}
|
|
33
101
|
//# 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,MAAM,UAAU,kBAAkB,CAAC,SAAqC,EAAE;IACxE,MAAM,QAAQ,GAAa,EAAE,CAAA;IAC7B,MAAM,UAAU,GAAgC,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AAA;KACpB;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
|
|
@@ -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;
|