@segment/actions-core 2.3.2-alpha.2 → 3.0.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 +3 -1
- package/dist/cjs/create-test-integration.js +3 -2
- package/dist/cjs/create-test-integration.js.map +1 -1
- package/dist/cjs/destination-kit/action.d.ts +20 -20
- package/dist/cjs/destination-kit/action.js +47 -114
- package/dist/cjs/destination-kit/action.js.map +1 -1
- package/dist/cjs/destination-kit/fields-to-jsonschema.d.ts +4 -2
- package/dist/cjs/destination-kit/fields-to-jsonschema.js.map +1 -1
- package/dist/cjs/destination-kit/index.d.ts +19 -9
- package/dist/cjs/destination-kit/index.js +52 -17
- package/dist/cjs/destination-kit/index.js.map +1 -1
- package/dist/cjs/destination-kit/parse-settings.d.ts +9 -0
- package/dist/cjs/destination-kit/parse-settings.js +32 -0
- package/dist/cjs/destination-kit/parse-settings.js.map +1 -0
- package/dist/cjs/destination-kit/types.d.ts +15 -2
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/mapping-kit/index.d.ts +1 -1
- package/dist/cjs/mapping-kit/index.js +5 -5
- package/dist/cjs/mapping-kit/index.js.map +1 -1
- package/dist/cjs/schema-validation.d.ts +1 -0
- package/dist/cjs/schema-validation.js +42 -0
- package/dist/cjs/schema-validation.js.map +1 -0
- package/dist/esm/create-test-integration.d.ts +3 -1
- package/dist/esm/create-test-integration.js +3 -2
- package/dist/esm/create-test-integration.js.map +1 -1
- package/dist/esm/destination-kit/action.d.ts +20 -20
- package/dist/esm/destination-kit/action.js +46 -112
- package/dist/esm/destination-kit/action.js.map +1 -1
- package/dist/esm/destination-kit/fields-to-jsonschema.d.ts +4 -2
- package/dist/esm/destination-kit/fields-to-jsonschema.js.map +1 -1
- package/dist/esm/destination-kit/index.d.ts +19 -9
- package/dist/esm/destination-kit/index.js +54 -19
- package/dist/esm/destination-kit/index.js.map +1 -1
- package/dist/esm/destination-kit/parse-settings.d.ts +9 -0
- package/dist/esm/destination-kit/parse-settings.js +26 -0
- package/dist/esm/destination-kit/parse-settings.js.map +1 -0
- package/dist/esm/destination-kit/types.d.ts +15 -2
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/mapping-kit/index.d.ts +1 -1
- package/dist/esm/mapping-kit/index.js +5 -5
- package/dist/esm/mapping-kit/index.js.map +1 -1
- package/dist/esm/schema-validation.d.ts +1 -0
- package/dist/esm/schema-validation.js +35 -0
- package/dist/esm/schema-validation.js.map +1 -0
- package/package.json +2 -2
- package/dist/cjs/destination-kit/step.d.ts +0 -23
- package/dist/cjs/destination-kit/step.js +0 -47
- package/dist/cjs/destination-kit/step.js.map +0 -1
- package/dist/esm/destination-kit/step.d.ts +0 -23
- package/dist/esm/destination-kit/step.js +0 -42
- package/dist/esm/destination-kit/step.js.map +0 -1
|
@@ -2,16 +2,18 @@ import { Destination } from './destination-kit';
|
|
|
2
2
|
import type { DestinationDefinition } from './destination-kit';
|
|
3
3
|
import type { JSONObject } from './json-object';
|
|
4
4
|
import type { SegmentEvent } from './segment-event';
|
|
5
|
+
import { AuthTokens } from './destination-kit/parse-settings';
|
|
5
6
|
interface InputData<Settings> {
|
|
6
7
|
event?: Partial<SegmentEvent>;
|
|
7
8
|
mapping?: JSONObject;
|
|
8
9
|
settings?: Settings;
|
|
9
10
|
useDefaultMappings?: boolean;
|
|
11
|
+
auth?: AuthTokens;
|
|
10
12
|
}
|
|
11
13
|
declare class TestDestination<T> extends Destination<T> {
|
|
12
14
|
responses: Destination['responses'];
|
|
13
15
|
constructor(destination: DestinationDefinition<T>);
|
|
14
|
-
testAction(action: string, { event, mapping, settings, useDefaultMappings }: InputData<T>): Promise<Destination['responses']>;
|
|
16
|
+
testAction(action: string, { event, mapping, settings, useDefaultMappings, auth }: InputData<T>): Promise<Destination['responses']>;
|
|
15
17
|
}
|
|
16
18
|
export declare function createTestIntegration<T>(destination: DestinationDefinition<T>): TestDestination<T>;
|
|
17
19
|
export {};
|
|
@@ -9,7 +9,7 @@ class TestDestination extends destination_kit_1.Destination {
|
|
|
9
9
|
super(destination);
|
|
10
10
|
this.responses = [];
|
|
11
11
|
}
|
|
12
|
-
async testAction(action, { event, mapping, settings, useDefaultMappings }) {
|
|
12
|
+
async testAction(action, { event, mapping, settings, useDefaultMappings, auth }) {
|
|
13
13
|
mapping = mapping ?? {};
|
|
14
14
|
if (useDefaultMappings) {
|
|
15
15
|
const fields = this.definition.actions[action].fields;
|
|
@@ -19,7 +19,8 @@ class TestDestination extends destination_kit_1.Destination {
|
|
|
19
19
|
await super.executeAction(action, {
|
|
20
20
|
event: create_test_event_1.createTestEvent(event),
|
|
21
21
|
mapping,
|
|
22
|
-
settings: settings ?? {}
|
|
22
|
+
settings: settings ?? {},
|
|
23
|
+
auth
|
|
23
24
|
});
|
|
24
25
|
const responses = this.responses;
|
|
25
26
|
this.responses = [];
|
|
@@ -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;
|
|
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;AAgCxC,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,EAAE,IAAI,EAAgB;QAEpE,OAAO,GAAG,OAAO,IAAI,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,IAAK,EAAQ;YAC/B,IAAI;SACL,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"}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import Ajv from 'ajv';
|
|
3
2
|
import { EventEmitter } from 'events';
|
|
4
3
|
import createRequestClient from '../create-request-client';
|
|
5
|
-
import { JSONLikeObject } from '../json-object';
|
|
6
|
-
import {
|
|
7
|
-
import type {
|
|
4
|
+
import { JSONLikeObject, JSONObject } from '../json-object';
|
|
5
|
+
import type { DynamicFieldResponse, InputField, RequestExtension, ExecuteInput, Result } from './types';
|
|
6
|
+
import type { JSONSchema4 } from 'json-schema';
|
|
7
|
+
import { AuthTokens } from './parse-settings';
|
|
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
12
|
title: string;
|
|
13
13
|
description: string;
|
|
14
|
+
platform?: 'cloud' | 'web';
|
|
14
15
|
defaultSubscription?: string;
|
|
15
16
|
hidden?: boolean;
|
|
16
17
|
fields: Record<string, InputField>;
|
|
@@ -19,28 +20,27 @@ export interface ActionDefinition<Settings, Payload = any> {
|
|
|
19
20
|
};
|
|
20
21
|
perform: RequestFn<Settings, Payload>;
|
|
21
22
|
}
|
|
22
|
-
export declare class Validate<Settings, Payload> extends Step<Settings, Payload> {
|
|
23
|
-
field: ExecuteInputField;
|
|
24
|
-
validate: Ajv.ValidateFunction;
|
|
25
|
-
constructor(field: ExecuteInputField, schema: object);
|
|
26
|
-
executeStep(data: ExecuteInput<Settings, Payload>): Promise<string>;
|
|
27
|
-
}
|
|
28
23
|
interface ExecuteDynamicFieldInput<Settings, Payload> {
|
|
29
24
|
settings: Settings;
|
|
30
25
|
payload: Payload;
|
|
31
26
|
page?: string;
|
|
32
27
|
}
|
|
33
|
-
declare type ExecuteInputField = 'payload' | 'settings';
|
|
34
28
|
export declare class Action<Settings, Payload extends JSONLikeObject> extends EventEmitter {
|
|
35
|
-
readonly
|
|
29
|
+
readonly definition: ActionDefinition<Settings, Payload>;
|
|
30
|
+
readonly destinationName: string;
|
|
31
|
+
readonly schema?: JSONSchema4;
|
|
36
32
|
private extendRequest;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
33
|
+
constructor(destinationName: string, definition: ActionDefinition<Settings, Payload>, extendRequest?: RequestExtension<Settings, Payload>);
|
|
34
|
+
execute(bundle: {
|
|
35
|
+
data: unknown;
|
|
36
|
+
settings: Settings;
|
|
37
|
+
mapping: JSONObject;
|
|
38
|
+
auth: AuthTokens | undefined;
|
|
39
|
+
}): Promise<Result[]>;
|
|
40
|
+
executeDynamicField(field: string, data: ExecuteDynamicFieldInput<Settings, Payload>): unknown;
|
|
41
|
+
private performRequest;
|
|
42
|
+
private createRequestClient;
|
|
43
|
+
private afterResponse;
|
|
44
|
+
private parseResponse;
|
|
45
45
|
}
|
|
46
46
|
export {};
|
|
@@ -3,142 +3,75 @@ 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.Action =
|
|
7
|
-
const ajv_human_errors_1 = require("@segment/ajv-human-errors");
|
|
8
|
-
const ajv_1 = __importDefault(require("ajv"));
|
|
9
|
-
const dayjs_1 = __importDefault(require("dayjs"));
|
|
6
|
+
exports.Action = void 0;
|
|
10
7
|
const events_1 = require("events");
|
|
11
8
|
const create_request_client_1 = __importDefault(require("../create-request-client"));
|
|
12
9
|
const mapping_kit_1 = require("../mapping-kit");
|
|
13
10
|
const fields_to_jsonschema_1 = require("./fields-to-jsonschema");
|
|
14
11
|
const fetch_1 = require("../fetch");
|
|
15
|
-
const
|
|
16
|
-
class MapInput extends step_1.Step {
|
|
17
|
-
executeStep(data) {
|
|
18
|
-
if (data.mapping) {
|
|
19
|
-
data.payload = mapping_kit_1.transform(data.mapping, data.payload);
|
|
20
|
-
}
|
|
21
|
-
return Promise.resolve('MapInput completed');
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
const ajv = new ajv_1.default({
|
|
25
|
-
coerceTypes: true,
|
|
26
|
-
allErrors: true,
|
|
27
|
-
verbose: true,
|
|
28
|
-
removeAdditional: true,
|
|
29
|
-
jsonPointers: true
|
|
30
|
-
});
|
|
31
|
-
ajv.addFormat('password', () => true);
|
|
32
|
-
ajv.addFormat('text', () => true);
|
|
33
|
-
ajv.addFormat('date-like', (data) => {
|
|
34
|
-
let date = dayjs_1.default(data);
|
|
35
|
-
if (String(Number(data)) === data) {
|
|
36
|
-
if (data.length === 13) {
|
|
37
|
-
date = dayjs_1.default(Number(data));
|
|
38
|
-
}
|
|
39
|
-
date = dayjs_1.default.unix(Number(data));
|
|
40
|
-
}
|
|
41
|
-
return date.isValid();
|
|
42
|
-
});
|
|
43
|
-
class Validate extends step_1.Step {
|
|
44
|
-
constructor(field, schema) {
|
|
45
|
-
super();
|
|
46
|
-
this.field = field;
|
|
47
|
-
this.validate = ajv.compile(schema);
|
|
48
|
-
}
|
|
49
|
-
executeStep(data) {
|
|
50
|
-
if (!this.validate(data[this.field])) {
|
|
51
|
-
throw new ajv_human_errors_1.AggregateAjvError(this.validate.errors);
|
|
52
|
-
}
|
|
53
|
-
return Promise.resolve('Validate completed');
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
exports.Validate = Validate;
|
|
57
|
-
class Request extends step_1.Step {
|
|
58
|
-
constructor(extendRequest, requestFn) {
|
|
59
|
-
super();
|
|
60
|
-
this.extendRequest = extendRequest;
|
|
61
|
-
this.requestFn = requestFn;
|
|
62
|
-
}
|
|
63
|
-
async executeStep(data) {
|
|
64
|
-
if (!this.requestFn) {
|
|
65
|
-
return '';
|
|
66
|
-
}
|
|
67
|
-
const requestClient = this.createRequestClient(data);
|
|
68
|
-
const response = await this.requestFn(requestClient, data);
|
|
69
|
-
if (response instanceof fetch_1.Response) {
|
|
70
|
-
return response.data ?? response.content;
|
|
71
|
-
}
|
|
72
|
-
return response;
|
|
73
|
-
}
|
|
74
|
-
createRequestClient(data) {
|
|
75
|
-
const options = this.extendRequest?.(data) ?? {};
|
|
76
|
-
const client = create_request_client_1.default(options, {
|
|
77
|
-
afterResponse: [
|
|
78
|
-
(request, options, response) => {
|
|
79
|
-
const modifiedResponse = response;
|
|
80
|
-
modifiedResponse.request = request;
|
|
81
|
-
modifiedResponse.options = options;
|
|
82
|
-
this.emit('response', modifiedResponse);
|
|
83
|
-
return modifiedResponse;
|
|
84
|
-
}
|
|
85
|
-
]
|
|
86
|
-
});
|
|
87
|
-
return client;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
12
|
+
const schema_validation_1 = require("../schema-validation");
|
|
90
13
|
class Action extends events_1.EventEmitter {
|
|
91
|
-
constructor(definition, extendRequest) {
|
|
14
|
+
constructor(destinationName, definition, extendRequest) {
|
|
92
15
|
super();
|
|
93
|
-
this.
|
|
94
|
-
|
|
95
|
-
this.
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
this.extendRequest = extendRequest;
|
|
16
|
+
this.definition = definition;
|
|
17
|
+
this.destinationName = destinationName;
|
|
18
|
+
this.extendRequest = extendRequest;
|
|
19
|
+
if (Object.keys(definition.fields ?? {}).length) {
|
|
20
|
+
this.schema = fields_to_jsonschema_1.fieldsToJsonSchema(definition.fields);
|
|
99
21
|
}
|
|
100
|
-
this.loadDefinition(definition);
|
|
101
22
|
}
|
|
102
|
-
async execute(
|
|
103
|
-
const results =
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
23
|
+
async execute(bundle) {
|
|
24
|
+
const results = [];
|
|
25
|
+
const payload = mapping_kit_1.transform(bundle.mapping, bundle.data);
|
|
26
|
+
results.push({ output: 'Mappings resolved' });
|
|
27
|
+
if (this.schema) {
|
|
28
|
+
schema_validation_1.validateSchema(payload, this.schema, `${this.destinationName}:${this.definition.title}`);
|
|
29
|
+
results.push({ output: 'Payload validated' });
|
|
107
30
|
}
|
|
31
|
+
const dataBundle = {
|
|
32
|
+
rawData: bundle.data,
|
|
33
|
+
rawMapping: bundle.mapping,
|
|
34
|
+
settings: bundle.settings,
|
|
35
|
+
payload,
|
|
36
|
+
auth: bundle.auth
|
|
37
|
+
};
|
|
38
|
+
const output = await this.performRequest(this.definition.perform, dataBundle);
|
|
39
|
+
results.push({ output: output });
|
|
108
40
|
return results;
|
|
109
41
|
}
|
|
110
42
|
executeDynamicField(field, data) {
|
|
111
|
-
|
|
43
|
+
const fn = this.definition.dynamicFields?.[field];
|
|
44
|
+
if (typeof fn !== 'function') {
|
|
112
45
|
return {
|
|
113
46
|
data: [],
|
|
114
47
|
pagination: {}
|
|
115
48
|
};
|
|
116
49
|
}
|
|
117
|
-
|
|
118
|
-
return step.executeStep(data);
|
|
50
|
+
return this.performRequest(fn, data);
|
|
119
51
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
Object.entries(definition.dynamicFields ?? {}).forEach(([field, callback]) => {
|
|
125
|
-
this.dynamicField(field, callback);
|
|
126
|
-
});
|
|
127
|
-
if (definition.perform) {
|
|
128
|
-
this.request(definition.perform);
|
|
129
|
-
}
|
|
52
|
+
async performRequest(requestFn, data) {
|
|
53
|
+
const requestClient = this.createRequestClient(data);
|
|
54
|
+
const response = await requestFn(requestClient, data);
|
|
55
|
+
return this.parseResponse(response);
|
|
130
56
|
}
|
|
131
|
-
|
|
132
|
-
const
|
|
133
|
-
|
|
57
|
+
createRequestClient(data) {
|
|
58
|
+
const options = this.extendRequest?.(data) ?? {};
|
|
59
|
+
return create_request_client_1.default(options, {
|
|
60
|
+
afterResponse: [this.afterResponse.bind(this)]
|
|
61
|
+
});
|
|
134
62
|
}
|
|
135
|
-
|
|
136
|
-
|
|
63
|
+
afterResponse(request, options, response) {
|
|
64
|
+
const modifiedResponse = response;
|
|
65
|
+
modifiedResponse.request = request;
|
|
66
|
+
modifiedResponse.options = options;
|
|
67
|
+
this.emit('response', modifiedResponse);
|
|
68
|
+
return modifiedResponse;
|
|
137
69
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
70
|
+
parseResponse(response) {
|
|
71
|
+
if (response instanceof fetch_1.Response) {
|
|
72
|
+
return response.data ?? response.content;
|
|
73
|
+
}
|
|
74
|
+
return response;
|
|
142
75
|
}
|
|
143
76
|
}
|
|
144
77
|
exports.Action = Action;
|
|
@@ -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"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,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,gBAAgB,CAAC,CAAA;QACvC,OAAO,gBAAgB,CAAA;IACzB,CAAC;IAEO,aAAa,CAAC,QAAiB;QAKrC,IAAI,QAAQ,YAAY,gBAAQ,EAAE;YAChC,OAAQ,QAA6B,CAAC,IAAI,IAAK,QAA6B,CAAC,OAAO,CAAA;SACrF;QAGD,OAAO,QAAQ,CAAA;IACjB,CAAC;CACF;AAnHD,wBAmHC"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import { JSONSchema4 } from 'json-schema';
|
|
2
|
-
import type { InputField } from './types';
|
|
3
|
-
|
|
2
|
+
import type { InputField, Optional } from './types';
|
|
3
|
+
declare type MinimalInputField = Optional<InputField, 'description'>;
|
|
4
|
+
export declare function fieldsToJsonSchema(fields?: Record<string, MinimalInputField>): JSONSchema4;
|
|
5
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fields-to-jsonschema.js","sourceRoot":"","sources":["../../../src/destination-kit/fields-to-jsonschema.ts"],"names":[],"mappings":";;;AAGA,SAAS,gBAAgB,CAAC,IAAmB;IAC3C,QAAQ,IAAI,EAAE;QACZ,KAAK,QAAQ,CAAC;QACd,KAAK,MAAM,CAAC;QACZ,KAAK,UAAU;YACb,OAAO,QAAQ,CAAA;QACjB,KAAK,UAAU;YACb,OAAO,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAA;QAC7B;YACE,OAAO,IAAI,CAAA;KACd;AACH,CAAC;
|
|
1
|
+
{"version":3,"file":"fields-to-jsonschema.js","sourceRoot":"","sources":["../../../src/destination-kit/fields-to-jsonschema.ts"],"names":[],"mappings":";;;AAGA,SAAS,gBAAgB,CAAC,IAAmB;IAC3C,QAAQ,IAAI,EAAE;QACZ,KAAK,QAAQ,CAAC;QACd,KAAK,MAAM,CAAC;QACZ,KAAK,UAAU;YACb,OAAO,QAAQ,CAAA;QACjB,KAAK,UAAU;YACb,OAAO,CAAC,QAAQ,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QAAQ,CAAC,MAAM,CAAC,EAAE;gBACxE,MAAM,CAAC,MAAM,IAAI,SAAS,CAAA;aAC3B;SACF;QAED,IAAI,KAAK,CAAC,QAAQ,EAAE;YAClB,MAAM,CAAC,KAAK,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,CAAA;YACnC,MAAM,CAAC,IAAI,GAAG,OAAO,CAAA;SACtB;QAID,IAAI,UAAU,KAAK,QAAQ,IAAI,KAAK,CAAC,UAAU,EAAE;YAC/C,IAAI,KAAK,CAAC,QAAQ,EAAE;gBAClB,MAAM,CAAC,KAAK,GAAG,kBAAkB,CAAC,KAAK,CAAC,UAAU,CAAC,CAAA;aACpD;iBAAM;gBACL,MAAM,GAAG,EAAE,GAAG,MAAM,EAAE,GAAG,kBAAkB,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,CAAA;aAChE;SACF;QAED,UAAU,CAAC,GAAG,CAAC,GAAG,MAAM,CAAA;QAGxB,IAAI,KAAK,CAAC,QAAQ,EAAE;YAClB,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;SACnB;KACF;IAED,OAAO;QACL,OAAO,EAAE,gCAAgC;QACzC,IAAI,EAAE,QAAQ;QACd,oBAAoB,EAAE,KAAK;QAC3B,UAAU;QACV,QAAQ;KACT,CAAA;AACH,CAAC;AApED,gDAoEC"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { JSONSchema4 } from 'json-schema';
|
|
1
|
+
import type { JSONSchema4 } from 'json-schema';
|
|
2
2
|
import { Action, ActionDefinition, RequestFn } from './action';
|
|
3
|
-
import { ExecuteInput, StepResult } from './step';
|
|
4
3
|
import { JSONLikeObject, JSONObject } from '../json-object';
|
|
5
4
|
import { SegmentEvent } from '../segment-event';
|
|
6
5
|
import { fieldsToJsonSchema } from './fields-to-jsonschema';
|
|
7
6
|
import { RequestClient } from '../create-request-client';
|
|
8
7
|
import type { ModifiedResponse } from '../types';
|
|
9
|
-
import type { InputField, RequestExtension } from './types';
|
|
8
|
+
import type { InputField, RequestExtension, ExecuteInput, Result } from './types';
|
|
10
9
|
import type { AllRequestOptions } from '../request-client';
|
|
10
|
+
import { AuthTokens } from './parse-settings';
|
|
11
11
|
export type { ActionDefinition, ExecuteInput, RequestFn };
|
|
12
12
|
export { fieldsToJsonSchema };
|
|
13
13
|
export interface SubscriptionStats {
|
|
@@ -17,7 +17,7 @@ export interface SubscriptionStats {
|
|
|
17
17
|
subscribe: string;
|
|
18
18
|
state: string;
|
|
19
19
|
input: JSONLikeObject;
|
|
20
|
-
output:
|
|
20
|
+
output: Result[] | null;
|
|
21
21
|
}
|
|
22
22
|
interface PartnerActions<Settings, Payload extends JSONLikeObject> {
|
|
23
23
|
[key: string]: Action<Settings, Payload>;
|
|
@@ -39,7 +39,7 @@ export interface Subscription {
|
|
|
39
39
|
subscribe: string;
|
|
40
40
|
mapping?: JSONObject;
|
|
41
41
|
}
|
|
42
|
-
export interface OAuth2ClientCredentials {
|
|
42
|
+
export interface OAuth2ClientCredentials extends AuthTokens {
|
|
43
43
|
clientId: string;
|
|
44
44
|
clientSecret: string;
|
|
45
45
|
}
|
|
@@ -49,6 +49,11 @@ export interface RefreshAccessTokenResult {
|
|
|
49
49
|
}
|
|
50
50
|
interface AuthSettings<Settings> {
|
|
51
51
|
settings: Settings;
|
|
52
|
+
auth: AuthTokens;
|
|
53
|
+
}
|
|
54
|
+
interface RefreshAuthSettings<Settings> {
|
|
55
|
+
settings: Settings;
|
|
56
|
+
auth: OAuth2ClientCredentials;
|
|
52
57
|
}
|
|
53
58
|
interface Authentication<Settings> {
|
|
54
59
|
scheme: 'basic' | 'custom' | 'oauth2';
|
|
@@ -63,13 +68,14 @@ export interface BasicAuthentication<Settings> extends Authentication<Settings>
|
|
|
63
68
|
}
|
|
64
69
|
export interface OAuth2Authentication<Settings> extends Authentication<Settings> {
|
|
65
70
|
scheme: 'oauth2';
|
|
66
|
-
refreshAccessToken?: (request: RequestClient, input:
|
|
71
|
+
refreshAccessToken?: (request: RequestClient, input: RefreshAuthSettings<Settings>) => Promise<RefreshAccessTokenResult>;
|
|
67
72
|
}
|
|
68
73
|
export declare type AuthenticationScheme<Settings = any> = BasicAuthentication<Settings> | CustomAuthentication<Settings> | OAuth2Authentication<Settings>;
|
|
69
74
|
interface EventInput<Settings> {
|
|
70
75
|
readonly event: SegmentEvent;
|
|
71
76
|
readonly mapping: JSONObject;
|
|
72
77
|
readonly settings: Settings;
|
|
78
|
+
readonly auth?: AuthTokens;
|
|
73
79
|
}
|
|
74
80
|
export interface DecoratedResponse extends ModifiedResponse {
|
|
75
81
|
request: Request;
|
|
@@ -85,11 +91,15 @@ export declare class Destination<Settings = JSONObject> {
|
|
|
85
91
|
readonly settingsSchema?: JSONSchema4;
|
|
86
92
|
constructor(destination: DestinationDefinition<Settings>);
|
|
87
93
|
testAuthentication(settings: Settings): Promise<void>;
|
|
88
|
-
refreshAccessToken(settings: Settings,
|
|
94
|
+
refreshAccessToken(settings: Settings, oauthData: OAuth2ClientCredentials): Promise<RefreshAccessTokenResult> | undefined;
|
|
89
95
|
private partnerAction;
|
|
90
|
-
protected executeAction(actionSlug: string, { event, mapping, settings }: EventInput<Settings>): Promise<
|
|
96
|
+
protected executeAction(actionSlug: string, { event, mapping, settings, auth }: EventInput<Settings>): Promise<Result[]>;
|
|
91
97
|
private onSubscription;
|
|
92
|
-
onEvent(event: SegmentEvent, settings: JSONObject,
|
|
98
|
+
onEvent(event: SegmentEvent, settings: JSONObject, options?: {
|
|
99
|
+
onTokenRefresh?: (tokens: RefreshAccessTokenResult) => void;
|
|
100
|
+
onComplete?: (stats: SubscriptionStats) => void;
|
|
101
|
+
}): Promise<Result[]>;
|
|
102
|
+
private onEventInternal;
|
|
93
103
|
private getSubscriptions;
|
|
94
104
|
private getDestinationSettings;
|
|
95
105
|
}
|
|
@@ -10,7 +10,11 @@ const time_1 = require("../time");
|
|
|
10
10
|
const fields_to_jsonschema_1 = require("./fields-to-jsonschema");
|
|
11
11
|
Object.defineProperty(exports, "fieldsToJsonSchema", { enumerable: true, get: function () { return fields_to_jsonschema_1.fieldsToJsonSchema; } });
|
|
12
12
|
const create_request_client_1 = __importDefault(require("../create-request-client"));
|
|
13
|
+
const schema_validation_1 = require("../schema-validation");
|
|
13
14
|
const errors_1 = require("../errors");
|
|
15
|
+
const parse_settings_1 = require("./parse-settings");
|
|
16
|
+
const RETRY_ATTEMPTS = 2;
|
|
17
|
+
const OAUTH2_SCHEME = 'oauth2';
|
|
14
18
|
class Destination {
|
|
15
19
|
constructor(destination) {
|
|
16
20
|
this.definition = destination;
|
|
@@ -27,10 +31,12 @@ class Destination {
|
|
|
27
31
|
}
|
|
28
32
|
}
|
|
29
33
|
async testAuthentication(settings) {
|
|
30
|
-
const
|
|
34
|
+
const destinationSettings = this.getDestinationSettings(settings);
|
|
35
|
+
const auth = parse_settings_1.getAuthData(settings);
|
|
36
|
+
const data = { settings: destinationSettings, auth };
|
|
37
|
+
const context = { settings: destinationSettings, payload: {}, auth };
|
|
31
38
|
if (this.settingsSchema) {
|
|
32
|
-
|
|
33
|
-
await step.executeStep(context);
|
|
39
|
+
schema_validation_1.validateSchema(settings, this.settingsSchema, `${this.name}:settings`);
|
|
34
40
|
}
|
|
35
41
|
if (!this.authentication?.testAuthentication) {
|
|
36
42
|
return;
|
|
@@ -38,26 +44,30 @@ class Destination {
|
|
|
38
44
|
const options = this.extendRequest?.(context) ?? {};
|
|
39
45
|
const requestClient = create_request_client_1.default(options);
|
|
40
46
|
try {
|
|
41
|
-
await this.authentication.testAuthentication(requestClient,
|
|
47
|
+
await this.authentication.testAuthentication(requestClient, data);
|
|
42
48
|
}
|
|
43
49
|
catch (error) {
|
|
44
50
|
throw new Error('Credentials are invalid');
|
|
45
51
|
}
|
|
46
52
|
}
|
|
47
|
-
refreshAccessToken(settings,
|
|
48
|
-
if (this.authentication?.scheme !==
|
|
53
|
+
refreshAccessToken(settings, oauthData) {
|
|
54
|
+
if (this.authentication?.scheme !== OAUTH2_SCHEME) {
|
|
49
55
|
throw new errors_1.IntegrationError('refreshAccessToken is only valid with oauth2 authentication scheme', 'NotImplemented', 501);
|
|
50
56
|
}
|
|
51
|
-
const context = {
|
|
57
|
+
const context = {
|
|
58
|
+
settings,
|
|
59
|
+
payload: {},
|
|
60
|
+
auth: parse_settings_1.getAuthData(settings)
|
|
61
|
+
};
|
|
52
62
|
const options = this.extendRequest?.(context) ?? {};
|
|
53
63
|
const requestClient = create_request_client_1.default(options);
|
|
54
64
|
if (!this.authentication?.refreshAccessToken) {
|
|
55
65
|
return undefined;
|
|
56
66
|
}
|
|
57
|
-
return this.authentication.refreshAccessToken(requestClient, { settings }
|
|
67
|
+
return this.authentication.refreshAccessToken(requestClient, { settings, auth: oauthData });
|
|
58
68
|
}
|
|
59
69
|
partnerAction(slug, definition) {
|
|
60
|
-
const action = new action_1.Action(definition, this.extendRequest);
|
|
70
|
+
const action = new action_1.Action(this.name, definition, this.extendRequest);
|
|
61
71
|
action.on('response', (response) => {
|
|
62
72
|
if (response) {
|
|
63
73
|
this.responses.push(response);
|
|
@@ -66,24 +76,26 @@ class Destination {
|
|
|
66
76
|
this.actions[slug] = action;
|
|
67
77
|
return this;
|
|
68
78
|
}
|
|
69
|
-
executeAction(actionSlug, { event, mapping, settings }) {
|
|
79
|
+
executeAction(actionSlug, { event, mapping, settings, auth }) {
|
|
70
80
|
const action = this.actions[actionSlug];
|
|
71
81
|
if (!action) {
|
|
72
82
|
return Promise.resolve([]);
|
|
73
83
|
}
|
|
74
84
|
return action.execute({
|
|
75
85
|
mapping,
|
|
76
|
-
|
|
77
|
-
settings
|
|
86
|
+
data: event,
|
|
87
|
+
settings,
|
|
88
|
+
auth
|
|
78
89
|
});
|
|
79
90
|
}
|
|
80
|
-
async onSubscription(subscription, event, settings, onComplete) {
|
|
91
|
+
async onSubscription(subscription, event, settings, auth, onComplete) {
|
|
81
92
|
const subscriptionStartedAt = time_1.time();
|
|
82
93
|
const actionSlug = subscription.partnerAction;
|
|
83
94
|
const input = {
|
|
84
95
|
event,
|
|
85
96
|
mapping: subscription.mapping || {},
|
|
86
|
-
settings
|
|
97
|
+
settings,
|
|
98
|
+
auth
|
|
87
99
|
};
|
|
88
100
|
let state = 'pending';
|
|
89
101
|
let results = null;
|
|
@@ -135,10 +147,33 @@ class Destination {
|
|
|
135
147
|
});
|
|
136
148
|
}
|
|
137
149
|
}
|
|
138
|
-
async onEvent(event, settings,
|
|
150
|
+
async onEvent(event, settings, options) {
|
|
151
|
+
for (let i = 0; i < RETRY_ATTEMPTS; i++) {
|
|
152
|
+
try {
|
|
153
|
+
return await this.onEventInternal(event, settings, options?.onComplete);
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
const statusCode = error?.status ?? error?.response?.status ?? 500;
|
|
157
|
+
if (!(statusCode === 401 && this.authentication?.scheme === OAUTH2_SCHEME)) {
|
|
158
|
+
throw error;
|
|
159
|
+
}
|
|
160
|
+
const destinationSettings = this.getDestinationSettings(settings);
|
|
161
|
+
const oauthSettings = parse_settings_1.getOAuth2Data(settings);
|
|
162
|
+
const newTokens = await this.refreshAccessToken(destinationSettings, oauthSettings);
|
|
163
|
+
if (!newTokens) {
|
|
164
|
+
throw new errors_1.InvalidAuthenticationError('Failed to refresh access token');
|
|
165
|
+
}
|
|
166
|
+
settings = parse_settings_1.updateOAuthSettings(settings, newTokens);
|
|
167
|
+
options?.onTokenRefresh?.(newTokens);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
throw new errors_1.InvalidAuthenticationError();
|
|
171
|
+
}
|
|
172
|
+
async onEventInternal(event, settings, onComplete) {
|
|
139
173
|
const subscriptions = this.getSubscriptions(settings);
|
|
140
174
|
const destinationSettings = this.getDestinationSettings(settings);
|
|
141
|
-
const
|
|
175
|
+
const authData = parse_settings_1.getAuthData(settings);
|
|
176
|
+
const promises = subscriptions.map((subscription) => this.onSubscription(subscription, event, destinationSettings, authData, onComplete));
|
|
142
177
|
const results = await Promise.all(promises);
|
|
143
178
|
return [].concat(...results);
|
|
144
179
|
}
|
|
@@ -157,7 +192,7 @@ class Destination {
|
|
|
157
192
|
return parsedSubscriptions;
|
|
158
193
|
}
|
|
159
194
|
getDestinationSettings(settings) {
|
|
160
|
-
const { subcription, subscriptions, ...otherSettings } = settings;
|
|
195
|
+
const { subcription, subscriptions, oauth, ...otherSettings } = settings;
|
|
161
196
|
return otherSettings;
|
|
162
197
|
}
|
|
163
198
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/destination-kit/index.ts"],"names":[],"mappings":";;;;;;AAAA,oEAAgF;AAEhF,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/destination-kit/index.ts"],"names":[],"mappings":";;;;;;AAAA,oEAAgF;AAEhF,qCAA8D;AAC9D,kCAAwC;AAGxC,iEAA2D;AAUlD,mGAVA,yCAAkB,OAUA;AAT3B,qFAA6E;AAC7E,4DAAqD;AAIrD,sCAAwE;AACxE,qDAA8F;AAK9F,MAAM,cAAc,GAAG,CAAC,CAAA;AACxB,MAAM,aAAa,GAAG,QAAQ,CAAA;AAgI9B,MAAa,WAAW;IAUtB,YAAY,WAA4C;QACtD,IAAI,CAAC,UAAU,GAAG,WAAW,CAAA;QAC7B,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC,IAAI,CAAA;QAC5B,IAAI,CAAC,aAAa,GAAG,WAAW,CAAC,aAAa,CAAA;QAC9C,IAAI,CAAC,OAAO,GAAG,EAAE,CAAA;QACjB,IAAI,CAAC,cAAc,GAAG,WAAW,CAAC,cAAc,CAAA;QAChD,IAAI,CAAC,SAAS,GAAG,EAAE,CAAA;QAGnB,IAAI,IAAI,CAAC,cAAc,EAAE,MAAM,EAAE;YAC/B,IAAI,CAAC,cAAc,GAAG,yCAAkB,CAAC,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,CAAA;SACrE;QAED,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,IAAI,CAA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Y,EAAE,aAAa,EAAE,GAAG,QAAQ,CAAA;QAChD,IAAI,mBAA4B,CAAA;QAEhC,IAAI,YAAY,EAAE;YAChB,mBAAmB,GAAG,CAAC,YAAY,CAAC,CAAA;SACrC;aAAM,IAAI,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE;YACvC,mBAAmB,GAAG,aAAa,CAAA;SACpC;aAAM;YACL,mBAAmB,GAAG,EAAE,CAAA;SACzB;QAED,OAAO,mBAAqC,CAAA;IAC9C,CAAC;IAEO,sBAAsB,CAAC,QAAoB;QACjD,MAAM,EAAE,WAAW,EAAE,aAAa,EAAE,KAAK,EAAE,GAAG,aAAa,EAAE,GAAG,QAAQ,CAAA;QACxE,OAAO,aAAoC,CAAA;IAC7C,CAAC;CACF;AApQD,kCAoQC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { OAuth2ClientCredentials, RefreshAccessTokenResult } from '.';
|
|
2
|
+
import { JSONObject } from '../json-object';
|
|
3
|
+
export interface AuthTokens {
|
|
4
|
+
accessToken: string;
|
|
5
|
+
refreshToken: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function getAuthData(settings: JSONObject): AuthTokens;
|
|
8
|
+
export declare function getOAuth2Data(settings: JSONObject): OAuth2ClientCredentials;
|
|
9
|
+
export declare function updateOAuthSettings(settings: JSONObject, oauthData: RefreshAccessTokenResult): JSONObject;
|