@segment/actions-core 1.3.0-next.1 → 2.0.1
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 +4 -3
- package/dist/cjs/create-request-client.js +24 -14
- package/dist/cjs/create-request-client.js.map +1 -0
- package/dist/cjs/create-test-event.d.ts +2 -0
- package/dist/cjs/create-test-event.js +45 -0
- package/dist/cjs/create-test-event.js.map +1 -0
- package/dist/cjs/create-test-integration.d.ts +36 -0
- package/dist/cjs/create-test-integration.js +34 -0
- package/dist/cjs/create-test-integration.js.map +1 -0
- package/dist/cjs/dayjs.js +1 -1
- package/dist/cjs/dayjs.js.map +1 -0
- package/dist/cjs/defaults.js +1 -1
- package/dist/cjs/defaults.js.map +1 -0
- package/dist/cjs/destination-kit/action.d.ts +7 -5
- package/dist/cjs/destination-kit/action.js +27 -30
- package/dist/cjs/destination-kit/action.js.map +1 -0
- package/dist/cjs/destination-kit/fields-to-jsonschema.js +1 -1
- package/dist/cjs/destination-kit/fields-to-jsonschema.js.map +1 -0
- package/dist/cjs/destination-kit/index.d.ts +10 -5
- package/dist/cjs/destination-kit/index.js +6 -14
- package/dist/cjs/destination-kit/index.js.map +1 -0
- package/dist/cjs/destination-kit/step.d.ts +1 -1
- package/dist/cjs/destination-kit/step.js +1 -1
- package/dist/cjs/destination-kit/step.js.map +1 -0
- package/dist/cjs/destination-kit/types.d.ts +3 -19
- package/dist/cjs/destination-kit/types.js +1 -1
- package/dist/cjs/destination-kit/types.js.map +1 -0
- package/dist/cjs/errors.js +1 -1
- package/dist/cjs/errors.js.map +1 -0
- package/dist/cjs/fetch.d.ts +3 -0
- package/dist/cjs/fetch.js +29 -0
- package/dist/cjs/fetch.js.map +1 -0
- package/dist/cjs/get.js +1 -1
- package/dist/cjs/get.js.map +1 -0
- package/dist/cjs/index.d.ts +7 -2
- package/dist/cjs/index.js +16 -2
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/json-object.js +1 -1
- package/dist/cjs/json-object.js.map +1 -0
- package/dist/cjs/map-values.d.ts +7 -0
- package/dist/cjs/map-values.js +16 -0
- package/dist/cjs/map-values.js.map +1 -0
- package/dist/cjs/mapping-kit/index.js +1 -1
- package/dist/cjs/mapping-kit/index.js.map +1 -0
- package/dist/cjs/mapping-kit/is-directive.js +1 -1
- package/dist/cjs/mapping-kit/is-directive.js.map +1 -0
- package/dist/cjs/mapping-kit/placeholders.js +1 -1
- package/dist/cjs/mapping-kit/placeholders.js.map +1 -0
- package/dist/cjs/mapping-kit/validate.js +1 -1
- package/dist/cjs/mapping-kit/validate.js.map +1 -0
- package/dist/cjs/middleware/add-basic-auth-header.d.ts +3 -0
- package/dist/cjs/middleware/add-basic-auth-header.js +21 -0
- package/dist/cjs/middleware/add-basic-auth-header.js.map +1 -0
- package/dist/cjs/omit.js +1 -1
- package/dist/cjs/omit.js.map +1 -0
- package/dist/cjs/real-type-of.js +1 -1
- package/dist/cjs/real-type-of.js.map +1 -0
- package/dist/cjs/remove-undefined.js +1 -1
- package/dist/cjs/remove-undefined.js.map +1 -0
- package/dist/cjs/request-client.d.ts +95 -0
- package/dist/cjs/request-client.js +227 -0
- package/dist/cjs/request-client.js.map +1 -0
- package/dist/cjs/segment-event.js +1 -1
- package/dist/cjs/segment-event.js.map +1 -0
- package/dist/cjs/time.js +1 -1
- package/dist/cjs/time.js.map +1 -0
- package/dist/esm/create-request-client.d.ts +4 -3
- package/dist/esm/create-request-client.js +24 -14
- package/dist/esm/create-request-client.js.map +1 -0
- package/dist/esm/create-test-event.d.ts +2 -0
- package/dist/esm/create-test-event.js +41 -0
- package/dist/esm/create-test-event.js.map +1 -0
- package/dist/esm/create-test-integration.d.ts +36 -0
- package/dist/esm/create-test-integration.js +30 -0
- package/dist/esm/create-test-integration.js.map +1 -0
- package/dist/esm/dayjs.js +1 -1
- package/dist/esm/dayjs.js.map +1 -0
- package/dist/esm/defaults.js +1 -1
- package/dist/esm/defaults.js.map +1 -0
- package/dist/esm/destination-kit/action.d.ts +7 -5
- package/dist/esm/destination-kit/action.js +27 -30
- package/dist/esm/destination-kit/action.js.map +1 -0
- package/dist/esm/destination-kit/fields-to-jsonschema.js +1 -1
- package/dist/esm/destination-kit/fields-to-jsonschema.js.map +1 -0
- package/dist/esm/destination-kit/index.d.ts +10 -5
- package/dist/esm/destination-kit/index.js +6 -14
- package/dist/esm/destination-kit/index.js.map +1 -0
- package/dist/esm/destination-kit/step.d.ts +1 -1
- package/dist/esm/destination-kit/step.js +1 -1
- package/dist/esm/destination-kit/step.js.map +1 -0
- package/dist/esm/destination-kit/types.d.ts +3 -19
- package/dist/esm/destination-kit/types.js +1 -1
- package/dist/esm/destination-kit/types.js.map +1 -0
- package/dist/esm/errors.js +1 -1
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/fetch.d.ts +3 -0
- package/dist/esm/fetch.js +5 -0
- package/dist/esm/fetch.js.map +1 -0
- package/dist/esm/get.js +1 -1
- package/dist/esm/get.js.map +1 -0
- package/dist/esm/index.d.ts +7 -2
- package/dist/esm/index.js +5 -1
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/json-object.js +1 -1
- package/dist/esm/json-object.js.map +1 -0
- package/dist/esm/map-values.d.ts +7 -0
- package/dist/esm/map-values.js +12 -0
- package/dist/esm/map-values.js.map +1 -0
- package/dist/esm/mapping-kit/index.js +1 -1
- package/dist/esm/mapping-kit/index.js.map +1 -0
- package/dist/esm/mapping-kit/is-directive.js +1 -1
- package/dist/esm/mapping-kit/is-directive.js.map +1 -0
- package/dist/esm/mapping-kit/placeholders.js +1 -1
- package/dist/esm/mapping-kit/placeholders.js.map +1 -0
- package/dist/esm/mapping-kit/validate.js +1 -1
- package/dist/esm/mapping-kit/validate.js.map +1 -0
- package/dist/esm/middleware/add-basic-auth-header.d.ts +3 -0
- package/dist/esm/middleware/add-basic-auth-header.js +16 -0
- package/dist/esm/middleware/add-basic-auth-header.js.map +1 -0
- package/dist/esm/omit.js +1 -1
- package/dist/esm/omit.js.map +1 -0
- package/dist/esm/real-type-of.js +1 -1
- package/dist/esm/real-type-of.js.map +1 -0
- package/dist/esm/remove-undefined.js +1 -1
- package/dist/esm/remove-undefined.js.map +1 -0
- package/dist/esm/request-client.d.ts +95 -0
- package/dist/esm/request-client.js +199 -0
- package/dist/esm/request-client.js.map +1 -0
- package/dist/esm/segment-event.js +1 -1
- package/dist/esm/segment-event.js.map +1 -0
- package/dist/esm/time.js +1 -1
- package/dist/esm/time.js.map +1 -0
- package/package.json +9 -7
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.TimeoutError = exports.HTTPError = void 0;
|
|
26
|
+
const abort_controller_1 = __importDefault(require("abort-controller"));
|
|
27
|
+
const ts_custom_error_1 = require("ts-custom-error");
|
|
28
|
+
const fetch_1 = __importStar(require("./fetch"));
|
|
29
|
+
const real_type_of_1 = require("./real-type-of");
|
|
30
|
+
// We need the loose definition of "object" to iterate over things like `[object Headers]`
|
|
31
|
+
const isObjectLike = (value) => {
|
|
32
|
+
return value !== null && typeof value === 'object';
|
|
33
|
+
};
|
|
34
|
+
/** Merges two sets of headers intelligently */
|
|
35
|
+
function mergeHeaders(source1, source2) {
|
|
36
|
+
const result = new fetch_1.Headers(source1 || {});
|
|
37
|
+
const source = new fetch_1.Headers(source2 || {});
|
|
38
|
+
source.forEach((value, key) => {
|
|
39
|
+
// `value` may be the string `undefined` when the source is a Headers object
|
|
40
|
+
if (value === 'undefined') {
|
|
41
|
+
result.delete(key);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
result.set(key, value);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
/** Deeply merge multiple objects or arrays. Arrays get concatenated. */
|
|
50
|
+
function merge(...sources) {
|
|
51
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
52
|
+
let result = {};
|
|
53
|
+
let headers = {};
|
|
54
|
+
for (const source of sources) {
|
|
55
|
+
if (Array.isArray(source)) {
|
|
56
|
+
if (!Array.isArray(result)) {
|
|
57
|
+
result = [];
|
|
58
|
+
}
|
|
59
|
+
// Concatenate arrays (e.g. hooks)
|
|
60
|
+
result = [...result, ...source];
|
|
61
|
+
}
|
|
62
|
+
else if (isObjectLike(source)) {
|
|
63
|
+
// eslint-disable-next-line prefer-const
|
|
64
|
+
for (let [key, value] of Object.entries(source)) {
|
|
65
|
+
// Recurse over objects
|
|
66
|
+
if (isObjectLike(value) && key in result) {
|
|
67
|
+
value = merge(result[key], value);
|
|
68
|
+
}
|
|
69
|
+
// Update the key's value in our copy
|
|
70
|
+
result[key] = value;
|
|
71
|
+
}
|
|
72
|
+
// Merge headers more carefully to handle duplicates
|
|
73
|
+
if (isObjectLike(source.headers)) {
|
|
74
|
+
headers = mergeHeaders(headers, source.headers);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// Assign after we've merged all the headers because they are handled specially
|
|
78
|
+
result.headers = headers;
|
|
79
|
+
}
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Validates and merges request options
|
|
84
|
+
*/
|
|
85
|
+
function mergeOptions(...sources) {
|
|
86
|
+
for (const source of sources) {
|
|
87
|
+
if (!real_type_of_1.isObject(source)) {
|
|
88
|
+
throw new TypeError(`The 'options' argument must be an object`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return merge({}, ...sources);
|
|
92
|
+
}
|
|
93
|
+
function getRequestMethod(method) {
|
|
94
|
+
return method.toUpperCase();
|
|
95
|
+
}
|
|
96
|
+
/** Error thrown when a response has a non-2xx response. */
|
|
97
|
+
class HTTPError extends ts_custom_error_1.CustomError {
|
|
98
|
+
constructor(response, request, options) {
|
|
99
|
+
var _a, _b;
|
|
100
|
+
super((_a = response.statusText) !== null && _a !== void 0 ? _a : String((_b = response.status) !== null && _b !== void 0 ? _b : 'Unknown response error'));
|
|
101
|
+
this.response = response;
|
|
102
|
+
this.request = request;
|
|
103
|
+
this.options = options;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
exports.HTTPError = HTTPError;
|
|
107
|
+
/** Error thrown when a request is aborted because of a client timeout. */
|
|
108
|
+
class TimeoutError extends ts_custom_error_1.CustomError {
|
|
109
|
+
constructor(request, options) {
|
|
110
|
+
super(`Request timed out`);
|
|
111
|
+
this.request = request;
|
|
112
|
+
this.options = options;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
exports.TimeoutError = TimeoutError;
|
|
116
|
+
/**
|
|
117
|
+
* Given a request, reject the request when a timeout is exceeded
|
|
118
|
+
*/
|
|
119
|
+
function timeoutFetch(request, abortController, options) {
|
|
120
|
+
return new Promise((resolve, reject) => {
|
|
121
|
+
const timer = setTimeout(() => {
|
|
122
|
+
if (abortController) {
|
|
123
|
+
abortController.abort();
|
|
124
|
+
}
|
|
125
|
+
reject(new TimeoutError(request, options));
|
|
126
|
+
}, options.timeout);
|
|
127
|
+
void fetch_1.default(request)
|
|
128
|
+
.then(resolve)
|
|
129
|
+
.catch(reject)
|
|
130
|
+
.then(() => clearTimeout(timer));
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
class RequestClient {
|
|
134
|
+
constructor(url, options = {}) {
|
|
135
|
+
this.setOptions(url, options);
|
|
136
|
+
}
|
|
137
|
+
setOptions(url, options) {
|
|
138
|
+
var _a, _b;
|
|
139
|
+
this.options = {
|
|
140
|
+
...options,
|
|
141
|
+
method: getRequestMethod((_a = options.method) !== null && _a !== void 0 ? _a : 'get'),
|
|
142
|
+
throwHttpErrors: options.throwHttpErrors !== false,
|
|
143
|
+
timeout: (_b = options.timeout) !== null && _b !== void 0 ? _b : 10000
|
|
144
|
+
};
|
|
145
|
+
// Timeout support. Use our own abort controller so consumers can pass in their own `signal`
|
|
146
|
+
// if they wish to use timeouts alongside other logic to abort a request
|
|
147
|
+
this.abortController = new abort_controller_1.default();
|
|
148
|
+
if (this.options.signal) {
|
|
149
|
+
// Listen to consumer abort events to also abort our internal controller
|
|
150
|
+
this.options.signal.addEventListener('abort', () => {
|
|
151
|
+
this.abortController.abort();
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
// Use our internal abort controller for fetch
|
|
155
|
+
this.options.signal = this.abortController.signal;
|
|
156
|
+
// Construct a request object to send to the Fetch API
|
|
157
|
+
this.request = new fetch_1.Request(url, this.options);
|
|
158
|
+
// Parse search params and merge them with the request URL
|
|
159
|
+
if (this.options.searchParams) {
|
|
160
|
+
// The type is a bit too restrictive, since you can pass in other primitives like `{ foo: 1, bar: true }`
|
|
161
|
+
const searchParams = new URLSearchParams(this.options.searchParams);
|
|
162
|
+
const url = new URL(this.request.url);
|
|
163
|
+
url.search = searchParams.toString();
|
|
164
|
+
// Update the request object with the new url including the search params
|
|
165
|
+
this.request = new fetch_1.Request(new fetch_1.Request(url.toString(), this.request), this.options);
|
|
166
|
+
}
|
|
167
|
+
// Automatically handle json header + stringification as a convenience when using `json` option
|
|
168
|
+
if (this.options.json !== undefined) {
|
|
169
|
+
this.options.body = JSON.stringify(this.options.json);
|
|
170
|
+
this.request.headers.set('content-type', 'application/json');
|
|
171
|
+
this.request = new fetch_1.Request(this.request, { body: this.options.body });
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
async executeRequest() {
|
|
175
|
+
var _a;
|
|
176
|
+
let response = await this.fetch();
|
|
177
|
+
for (const hook of (_a = this.options.afterResponse) !== null && _a !== void 0 ? _a : []) {
|
|
178
|
+
const modifiedResponse = await hook(this.request, this.options, response.clone());
|
|
179
|
+
if (modifiedResponse instanceof fetch_1.Response) {
|
|
180
|
+
response = modifiedResponse;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
// Automatically attempt to parse json responses, matching the content-type
|
|
184
|
+
const contentType = response.headers.get('content-type');
|
|
185
|
+
if (contentType === null || contentType === void 0 ? void 0 : contentType.includes('application/json')) {
|
|
186
|
+
try {
|
|
187
|
+
// call `.json` on a clone, to prevent `TypeError: body used already` in callers
|
|
188
|
+
response.data = await response.clone().json();
|
|
189
|
+
}
|
|
190
|
+
catch (_error) {
|
|
191
|
+
// Ignore the error
|
|
192
|
+
response.data = null;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
if (!response.ok && this.options.throwHttpErrors) {
|
|
196
|
+
throw new HTTPError(response, this.request, this.options);
|
|
197
|
+
}
|
|
198
|
+
return response;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Make a fetch request, running all beforeRequest hooks, and optionally wrap in a timeout
|
|
202
|
+
*/
|
|
203
|
+
async fetch() {
|
|
204
|
+
var _a;
|
|
205
|
+
for (const hook of (_a = this.options.beforeRequest) !== null && _a !== void 0 ? _a : []) {
|
|
206
|
+
const newOptions = await hook({ ...this.options });
|
|
207
|
+
if (newOptions && real_type_of_1.isObject(newOptions)) {
|
|
208
|
+
this.setOptions(this.request.url, mergeOptions(this.options, newOptions));
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
if (this.options.timeout === false) {
|
|
212
|
+
return fetch_1.default(this.request.clone());
|
|
213
|
+
}
|
|
214
|
+
return timeoutFetch(this.request.clone(), this.abortController, this.options);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Creates a new instance of the fetch request client,
|
|
219
|
+
* optionally with default configuration to apply to all requests made with the client
|
|
220
|
+
*/
|
|
221
|
+
function createInstance(defaults = {}) {
|
|
222
|
+
const client = (url, options = {}) => new RequestClient(url, mergeOptions(defaults, options)).executeRequest();
|
|
223
|
+
client.extend = (newDefaults) => createInstance(mergeOptions(defaults, newDefaults));
|
|
224
|
+
return client;
|
|
225
|
+
}
|
|
226
|
+
exports.default = createInstance;
|
|
227
|
+
//# sourceMappingURL=request-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-client.js","sourceRoot":"","sources":["../../src/request-client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wEAA8C;AAC9C,qDAA6C;AAC7C,iDAA2D;AAC3D,iDAAyC;AAoFzC,0FAA0F;AAC1F,MAAM,YAAY,GAAG,CAAC,KAAc,EAAuC,EAAE;IAC3E,OAAO,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAA;AACpD,CAAC,CAAA;AAED,+CAA+C;AAC/C,SAAS,YAAY,CAAC,OAA+B,EAAE,OAA+B;IACpF,MAAM,MAAM,GAAG,IAAI,eAAO,CAAC,OAAO,IAAI,EAAE,CAAC,CAAA;IACzC,MAAM,MAAM,GAAG,IAAI,eAAO,CAAC,OAAO,IAAI,EAAE,CAAC,CAAA;IAE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KAAK,KAAK,EAAE;YAClC,OAAO,eAAK,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAA;SACnC;QAED,OAAO,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,IAAI,CAAC,eAAe,EAAE,IAAI,CAAC,OAAO,CAAC,CAAA;IAC/E,CAAC;CACF;AAED;;;GAGG;AACH,SAAwB,cAAc,CAAC,WAA8B,EAAE;IACrE,MAAM,MAAM,GAAG,CAAC,GAAW,EAAE,UAA0B,EAAE,EAAE,EAAE,CAC3D,IAAI,aAAa,CAAC,GAAG,EAAE,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC,cAAc,EAAE,CAAA;IAC1E,MAAM,CAAC,MAAM,GAAG,CAAC,WAA8B,EAAE,EAAE,CAAC,cAAc,CAAC,YAAY,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAA;IACvG,OAAO,MAAM,CAAA;AACf,CAAC;AALD,iCAKC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
//# sourceMappingURL=
|
|
3
|
+
//# sourceMappingURL=segment-event.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"segment-event.js","sourceRoot":"","sources":["../../src/segment-event.ts"],"names":[],"mappings":""}
|
package/dist/cjs/time.js
CHANGED
|
@@ -15,4 +15,4 @@ function duration(start, stop) {
|
|
|
15
15
|
return Number(stop - start) / 1000000;
|
|
16
16
|
}
|
|
17
17
|
exports.duration = duration;
|
|
18
|
-
//# sourceMappingURL=
|
|
18
|
+
//# sourceMappingURL=time.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"time.js","sourceRoot":"","sources":["../../src/time.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,SAAgB,IAAI;IAClB,OAAO,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,CAAA;AAChC,CAAC;AAFD,oBAEC;AAED;;GAEG;AACH,SAAgB,QAAQ,CAAC,KAAa,EAAE,IAAY;IAClD,OAAO,MAAM,CAAC,IAAI,GAAG,KAAK,CAAC,GAAG,OAAO,CAAA;AACvC,CAAC;AAFD,4BAEC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AllRequestOptions, RequestOptions } from './request-client';
|
|
2
|
+
export declare type RequestClient = ReturnType<typeof createRequestClient>;
|
|
2
3
|
/**
|
|
3
|
-
* Creates a
|
|
4
|
+
* Creates a request client instance with Segment's default configuration + custom options
|
|
4
5
|
*/
|
|
5
|
-
export default function createRequestClient(...
|
|
6
|
+
export default function createRequestClient(...requestOptions: AllRequestOptions[]): (url: string, options?: RequestOptions | undefined) => Promise<import("./request-client").ModifiedResponse>;
|
|
@@ -1,18 +1,28 @@
|
|
|
1
|
-
import
|
|
1
|
+
import addBasicAuthHeader from './middleware/add-basic-auth-header';
|
|
2
|
+
import createInstance from './request-client';
|
|
3
|
+
const baseClient = createInstance({
|
|
4
|
+
timeout: 10000,
|
|
5
|
+
headers: {
|
|
6
|
+
'user-agent': 'Segment'
|
|
7
|
+
},
|
|
8
|
+
beforeRequest: [
|
|
9
|
+
// Automatically handle username/password -> basic auth header
|
|
10
|
+
addBasicAuthHeader
|
|
11
|
+
]
|
|
12
|
+
});
|
|
2
13
|
/**
|
|
3
|
-
* Creates a
|
|
14
|
+
* Creates a request client instance with Segment's default configuration + custom options
|
|
4
15
|
*/
|
|
5
|
-
export default function createRequestClient(...
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
16
|
+
export default function createRequestClient(...requestOptions) {
|
|
17
|
+
let client = baseClient;
|
|
18
|
+
// TODO include `data` bundle in before/after hooks
|
|
19
|
+
// TODO expose before/after hooks to destination definition and action definition?
|
|
20
|
+
for (const options of (requestOptions !== null && requestOptions !== void 0 ? requestOptions : [])) {
|
|
21
|
+
client = client.extend(options);
|
|
22
|
+
}
|
|
23
|
+
// Limit request client interface and handle basic auth scheme
|
|
24
|
+
return (url, options) => {
|
|
25
|
+
return client(url, options);
|
|
14
26
|
};
|
|
15
|
-
const client = got.extend(defaultOptions, ...options);
|
|
16
|
-
return client;
|
|
17
27
|
}
|
|
18
|
-
//# sourceMappingURL=
|
|
28
|
+
//# sourceMappingURL=create-request-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-request-client.js","sourceRoot":"","sources":["../../src/create-request-client.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,MAAM,oCAAoC,CAAA;AACnE,OAAO,cAAqD,MAAM,kBAAkB,CAAA;AAEpF,MAAM,UAAU,GAAG,cAAc,CAAC;IAChC,OAAO,EAAE,KAAK;IACd,OAAO,EAAE;QACP,YAAY,EAAE,SAAS;KACxB;IACD,aAAa,EAAE;QACb,8DAA8D;QAC9D,kBAAkB;KACnB;CACF,CAAC,CAAA;AAIF;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,mBAAmB,CAAC,GAAG,cAAmC;IAChF,IAAI,MAAM,GAAG,UAAU,CAAA;IAEvB,mDAAmD;IACnD,kFAAkF;IAClF,KAAK,MAAM,OAAO,IAAI,CAAC,cAAc,aAAd,cAAc,cAAd,cAAc,GAAI,EAAE,CAAC,EAAE;QAC5C,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;KAChC;IAED,8DAA8D;IAC9D,OAAO,CAAC,GAAW,EAAE,OAAwB,EAAE,EAAE;QAC/C,OAAO,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;IAC7B,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
2
|
+
export function createTestEvent(event = {}) {
|
|
3
|
+
return {
|
|
4
|
+
anonymousId: uuidv4(),
|
|
5
|
+
context: {
|
|
6
|
+
ip: '8.8.8.8',
|
|
7
|
+
library: {
|
|
8
|
+
name: 'analytics.js',
|
|
9
|
+
version: '2.11.1'
|
|
10
|
+
},
|
|
11
|
+
locale: 'en-US',
|
|
12
|
+
location: {
|
|
13
|
+
city: 'San Francisco',
|
|
14
|
+
country: 'United States',
|
|
15
|
+
latitude: 40.2964197,
|
|
16
|
+
longitude: -76.9411617,
|
|
17
|
+
speed: 0
|
|
18
|
+
},
|
|
19
|
+
page: {
|
|
20
|
+
path: '/academy/',
|
|
21
|
+
referrer: '',
|
|
22
|
+
search: '',
|
|
23
|
+
title: 'Analytics Academy',
|
|
24
|
+
url: 'https://segment.com/academy/'
|
|
25
|
+
},
|
|
26
|
+
timezone: 'Europe/Amsterdam',
|
|
27
|
+
userAgent: 'Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1'
|
|
28
|
+
},
|
|
29
|
+
event: 'Test Event',
|
|
30
|
+
messageId: uuidv4(),
|
|
31
|
+
properties: {},
|
|
32
|
+
receivedAt: new Date().toISOString(),
|
|
33
|
+
sentAt: new Date().toISOString(),
|
|
34
|
+
timestamp: new Date().toISOString(),
|
|
35
|
+
traits: {},
|
|
36
|
+
type: 'track',
|
|
37
|
+
userId: 'user1234',
|
|
38
|
+
...event
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=create-test-event.js.map
|
|
@@ -0,0 +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,MAAM,CAAA;AAGnC,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"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Destination } from './destination-kit';
|
|
2
|
+
import type { DestinationDefinition } from './destination-kit';
|
|
3
|
+
import type { JSONObject } from './json-object';
|
|
4
|
+
import type { SegmentEvent } from './segment-event';
|
|
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
|
+
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
|
+
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
|
+
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
|
+
useDefaultMappings?: boolean;
|
|
28
|
+
}
|
|
29
|
+
declare class TestDestination<T> extends Destination<T> {
|
|
30
|
+
responses: Destination['responses'];
|
|
31
|
+
constructor(destination: DestinationDefinition<T>);
|
|
32
|
+
/** Testing method that runs an action e2e while allowing slightly more flexible inputs */
|
|
33
|
+
testAction(action: string, { event, mapping, settings, useDefaultMappings }: InputData<T>): Promise<Destination['responses']>;
|
|
34
|
+
}
|
|
35
|
+
export declare function createTestIntegration<T>(destination: DestinationDefinition<T>): TestDestination<T>;
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { createTestEvent } from './create-test-event';
|
|
2
|
+
import { Destination } from './destination-kit';
|
|
3
|
+
import { mapValues } from './map-values';
|
|
4
|
+
class TestDestination extends Destination {
|
|
5
|
+
constructor(destination) {
|
|
6
|
+
super(destination);
|
|
7
|
+
this.responses = [];
|
|
8
|
+
}
|
|
9
|
+
/** Testing method that runs an action e2e while allowing slightly more flexible inputs */
|
|
10
|
+
async testAction(action, { event, mapping, settings, useDefaultMappings }) {
|
|
11
|
+
mapping = mapping !== null && mapping !== void 0 ? mapping : {};
|
|
12
|
+
if (useDefaultMappings) {
|
|
13
|
+
const fields = this.definition.actions[action].fields;
|
|
14
|
+
const defaultMappings = mapValues(fields, 'default');
|
|
15
|
+
mapping = { ...defaultMappings, ...mapping };
|
|
16
|
+
}
|
|
17
|
+
await super.executeAction(action, {
|
|
18
|
+
event: createTestEvent(event),
|
|
19
|
+
mapping,
|
|
20
|
+
settings: settings !== null && settings !== void 0 ? settings : {}
|
|
21
|
+
});
|
|
22
|
+
const responses = this.responses;
|
|
23
|
+
this.responses = [];
|
|
24
|
+
return responses;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export function createTestIntegration(destination) {
|
|
28
|
+
return new TestDestination(destination);
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=create-test-integration.js.map
|
|
@@ -0,0 +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;IAED,0FAA0F;IAC1F,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,EAAE,CAAA;SAC7C;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"}
|
package/dist/esm/dayjs.js
CHANGED
|
@@ -2,4 +2,4 @@ import dayjs from 'dayjs';
|
|
|
2
2
|
import utc from 'dayjs/plugin/utc';
|
|
3
3
|
dayjs.extend(utc);
|
|
4
4
|
export default dayjs;
|
|
5
|
-
//# sourceMappingURL=
|
|
5
|
+
//# sourceMappingURL=dayjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dayjs.js","sourceRoot":"","sources":["../../src/dayjs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,GAAG,MAAM,kBAAkB,CAAA;AAElC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;AAEjB,eAAe,KAAK,CAAA"}
|
package/dist/esm/defaults.js
CHANGED
|
@@ -8,4 +8,4 @@ export function defaultValues(fields) {
|
|
|
8
8
|
}
|
|
9
9
|
return obj;
|
|
10
10
|
}
|
|
11
|
-
//# sourceMappingURL=
|
|
11
|
+
//# sourceMappingURL=defaults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaults.js","sourceRoot":"","sources":["../../src/defaults.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,aAAa,CAAC,MAA+B;IAC3D,MAAM,GAAG,GAAoC,EAAE,CAAA;IAE/C,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE;QACvC,MAAM,YAAY,GAAI,MAAM,CAAC,KAAK,CAAiB,CAAC,OAAO,CAAA;QAC3D,IAAI,OAAO,YAAY,KAAK,WAAW,EAAE;YACvC,GAAG,CAAC,KAAK,CAAC,GAAG,YAAY,CAAA;SAC1B;KACF;IAED,OAAO,GAAG,CAAA;AACZ,CAAC"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import Ajv from 'ajv';
|
|
3
3
|
import { EventEmitter } from 'events';
|
|
4
|
-
import
|
|
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 { InputField, RequestExtension } from './types';
|
|
8
|
-
|
|
7
|
+
import type { AutocompleteResponse, InputField, RequestExtension } from './types';
|
|
8
|
+
declare type MaybePromise<T> = T | Promise<T>;
|
|
9
|
+
declare type RequestClient = ReturnType<typeof createRequestClient>;
|
|
10
|
+
export declare type RequestFn<Settings, Payload, Return = any> = (request: RequestClient, data: ExecuteInput<Settings, Payload>) => MaybePromise<Return>;
|
|
9
11
|
export interface ActionDefinition<Settings, Payload = any> {
|
|
10
12
|
/** The unique identifier for the action, e.g. `postToChannel` */
|
|
11
13
|
/** The display title of the action */
|
|
@@ -34,7 +36,7 @@ export interface ActionDefinition<Settings, Payload = any> {
|
|
|
34
36
|
* This is likely going to change as we productionalize the data model and definition object
|
|
35
37
|
*/
|
|
36
38
|
autocompleteFields?: {
|
|
37
|
-
[K in keyof Payload]?: RequestFn<Settings, Payload>;
|
|
39
|
+
[K in keyof Payload]?: RequestFn<Settings, Payload, AutocompleteResponse>;
|
|
38
40
|
};
|
|
39
41
|
/**
|
|
40
42
|
* Register fields that should be executed, cached and provided
|
|
@@ -72,7 +74,7 @@ declare type ExecuteInputField = 'payload' | 'settings';
|
|
|
72
74
|
*/
|
|
73
75
|
export declare class Action<Settings, Payload extends JSONLikeObject> extends EventEmitter {
|
|
74
76
|
readonly steps: Steps<Settings, Payload>;
|
|
75
|
-
private
|
|
77
|
+
private extendRequest;
|
|
76
78
|
private autocompleteCache;
|
|
77
79
|
constructor(definition: ActionDefinition<Settings, Payload>, extendRequest?: RequestExtension<Settings, Payload>);
|
|
78
80
|
execute(data: ExecuteInput<Settings, Payload>): Promise<StepResult[]>;
|
|
@@ -46,14 +46,14 @@ export class Validate extends Step {
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
/**
|
|
49
|
-
* Request handles delivering a payload to an external API. It uses the `
|
|
49
|
+
* Request handles delivering a payload to an external API. It uses the `fetch` API under the hood.
|
|
50
50
|
*
|
|
51
51
|
* The callback should be able to return the raw request instead of needing to do `return response.data` etc.
|
|
52
52
|
*/
|
|
53
53
|
class Request extends Step {
|
|
54
|
-
constructor(
|
|
54
|
+
constructor(extendRequest, requestFn) {
|
|
55
55
|
super();
|
|
56
|
-
this.
|
|
56
|
+
this.extendRequest = extendRequest;
|
|
57
57
|
this.requestFn = requestFn;
|
|
58
58
|
}
|
|
59
59
|
async executeStep(data) {
|
|
@@ -68,32 +68,30 @@ class Request extends Step {
|
|
|
68
68
|
return response.body;
|
|
69
69
|
}
|
|
70
70
|
createRequestClient(data) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
(response)
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
]
|
|
88
|
-
}
|
|
71
|
+
var _a, _b;
|
|
72
|
+
// TODO turn `extendRequest` into a beforeRequest hook
|
|
73
|
+
const options = (_b = (_a = this.extendRequest) === null || _a === void 0 ? void 0 : _a.call(this, data)) !== null && _b !== void 0 ? _b : {};
|
|
74
|
+
const client = createRequestClient(options, {
|
|
75
|
+
afterResponse: [
|
|
76
|
+
// Keep track of the request(s) associated with a response
|
|
77
|
+
(request, options, response) => {
|
|
78
|
+
// TODO figure out the types here...
|
|
79
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
80
|
+
const modifiedResponse = response.clone();
|
|
81
|
+
modifiedResponse.request = request;
|
|
82
|
+
modifiedResponse.options = options;
|
|
83
|
+
this.emit('response', modifiedResponse);
|
|
84
|
+
return modifiedResponse;
|
|
85
|
+
}
|
|
86
|
+
]
|
|
89
87
|
});
|
|
90
88
|
return client;
|
|
91
89
|
}
|
|
92
90
|
}
|
|
93
91
|
// CachedRequest is like Request but cached. Next question.
|
|
94
92
|
class CachedRequest extends Request {
|
|
95
|
-
constructor(
|
|
96
|
-
super(
|
|
93
|
+
constructor(extension, config) {
|
|
94
|
+
super(extension);
|
|
97
95
|
this.keyFn = config.key;
|
|
98
96
|
this.valueFn = config.value;
|
|
99
97
|
this.as = config.as;
|
|
@@ -115,7 +113,7 @@ class CachedRequest extends Request {
|
|
|
115
113
|
v = await this.valueFn(request, data);
|
|
116
114
|
}
|
|
117
115
|
catch (e) {
|
|
118
|
-
if (get(e, 'response.
|
|
116
|
+
if (get(e, 'response.status') === 404) {
|
|
119
117
|
v = undefined;
|
|
120
118
|
}
|
|
121
119
|
else {
|
|
@@ -143,12 +141,11 @@ export class Action extends EventEmitter {
|
|
|
143
141
|
const step = new MapInput();
|
|
144
142
|
this.steps.push(step);
|
|
145
143
|
this.autocompleteCache = {};
|
|
146
|
-
this.requestExtensions = [];
|
|
147
144
|
if (extendRequest) {
|
|
148
145
|
// This must come before we load the definition because
|
|
149
146
|
// it instantiates "steps" with whatever request extensions
|
|
150
147
|
// are defined at that moment in time
|
|
151
|
-
this.
|
|
148
|
+
this.extendRequest = extendRequest;
|
|
152
149
|
}
|
|
153
150
|
this.loadDefinition(definition);
|
|
154
151
|
}
|
|
@@ -168,7 +165,7 @@ export class Action extends EventEmitter {
|
|
|
168
165
|
pagination: {}
|
|
169
166
|
};
|
|
170
167
|
}
|
|
171
|
-
const step = new Request(this.
|
|
168
|
+
const step = new Request(this.extendRequest, this.autocompleteCache[field]);
|
|
172
169
|
return step.executeStep(data);
|
|
173
170
|
}
|
|
174
171
|
loadDefinition(definition) {
|
|
@@ -197,13 +194,13 @@ export class Action extends EventEmitter {
|
|
|
197
194
|
this.autocompleteCache[field] = callback;
|
|
198
195
|
}
|
|
199
196
|
request(requestFn) {
|
|
200
|
-
const step = new Request(this.
|
|
197
|
+
const step = new Request(this.extendRequest, requestFn);
|
|
201
198
|
step.on('response', (response) => this.emit('response', response));
|
|
202
199
|
this.steps.push(step);
|
|
203
200
|
}
|
|
204
201
|
cachedRequest(config) {
|
|
205
|
-
const step = new CachedRequest(this.
|
|
202
|
+
const step = new CachedRequest(this.extendRequest, config);
|
|
206
203
|
this.steps.push(step);
|
|
207
204
|
}
|
|
208
205
|
}
|
|
209
|
-
//# sourceMappingURL=
|
|
206
|
+
//# sourceMappingURL=action.js.map
|