@segment/actions-core 2.0.3-next.0 → 2.1.0-next.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 +0 -30
- package/dist/cjs/destination-kit/action.js +0 -38
- package/dist/cjs/destination-kit/action.js.map +1 -1
- package/dist/cjs/destination-kit/fields-to-jsonschema.js +0 -2
- 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 +3 -6
- 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 +0 -4
- 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/map-values.d.ts +0 -4
- 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 +0 -30
- package/dist/esm/destination-kit/action.js +0 -38
- package/dist/esm/destination-kit/action.js.map +1 -1
- package/dist/esm/destination-kit/fields-to-jsonschema.js +0 -2
- 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 +3 -6
- 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 +0 -4
- 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/map-values.d.ts +0 -4
- 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 +15 -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
|
@@ -26,18 +26,14 @@ exports.TimeoutError = exports.HTTPError = void 0;
|
|
|
26
26
|
const abort_controller_1 = __importDefault(require("abort-controller"));
|
|
27
27
|
const ts_custom_error_1 = require("ts-custom-error");
|
|
28
28
|
const fetch_1 = __importStar(require("./fetch"));
|
|
29
|
-
const omit_1 = require("./omit");
|
|
30
29
|
const real_type_of_1 = require("./real-type-of");
|
|
31
|
-
// We need the loose definition of "object" to iterate over things like `[object Headers]`
|
|
32
30
|
const isObjectLike = (value) => {
|
|
33
31
|
return value !== null && typeof value === 'object';
|
|
34
32
|
};
|
|
35
|
-
/** Merges two sets of headers intelligently */
|
|
36
33
|
function mergeHeaders(source1, source2) {
|
|
37
34
|
const result = new fetch_1.Headers(source1 || {});
|
|
38
35
|
const source = new fetch_1.Headers(source2 || {});
|
|
39
36
|
source.forEach((value, key) => {
|
|
40
|
-
// `value` may be the string `undefined` when the source is a Headers object
|
|
41
37
|
if (value === 'undefined') {
|
|
42
38
|
result.delete(key);
|
|
43
39
|
}
|
|
@@ -47,9 +43,7 @@ function mergeHeaders(source1, source2) {
|
|
|
47
43
|
});
|
|
48
44
|
return result;
|
|
49
45
|
}
|
|
50
|
-
/** Deeply merge multiple objects or arrays. Arrays get concatenated. */
|
|
51
46
|
function merge(...sources) {
|
|
52
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
53
47
|
let result = {};
|
|
54
48
|
let headers = {};
|
|
55
49
|
for (const source of sources) {
|
|
@@ -57,32 +51,23 @@ function merge(...sources) {
|
|
|
57
51
|
if (!Array.isArray(result)) {
|
|
58
52
|
result = [];
|
|
59
53
|
}
|
|
60
|
-
// Concatenate arrays (e.g. hooks)
|
|
61
54
|
result = [...result, ...source];
|
|
62
55
|
}
|
|
63
56
|
else if (isObjectLike(source)) {
|
|
64
|
-
// eslint-disable-next-line prefer-const
|
|
65
57
|
for (let [key, value] of Object.entries(source)) {
|
|
66
|
-
// Recurse over objects
|
|
67
58
|
if (isObjectLike(value) && key in result) {
|
|
68
59
|
value = merge(result[key], value);
|
|
69
60
|
}
|
|
70
|
-
// Update the key's value in our copy
|
|
71
61
|
result[key] = value;
|
|
72
62
|
}
|
|
73
|
-
// Merge headers more carefully to handle duplicates
|
|
74
63
|
if (isObjectLike(source.headers)) {
|
|
75
64
|
headers = mergeHeaders(headers, source.headers);
|
|
76
65
|
}
|
|
77
66
|
}
|
|
78
|
-
// Assign after we've merged all the headers because they are handled specially
|
|
79
67
|
result.headers = headers;
|
|
80
68
|
}
|
|
81
69
|
return result;
|
|
82
70
|
}
|
|
83
|
-
/**
|
|
84
|
-
* Validates and merges request options
|
|
85
|
-
*/
|
|
86
71
|
function mergeOptions(...sources) {
|
|
87
72
|
for (const source of sources) {
|
|
88
73
|
if (!real_type_of_1.isObject(source)) {
|
|
@@ -94,7 +79,6 @@ function mergeOptions(...sources) {
|
|
|
94
79
|
function getRequestMethod(method) {
|
|
95
80
|
return method.toUpperCase();
|
|
96
81
|
}
|
|
97
|
-
/** Error thrown when a response has a non-2xx response. */
|
|
98
82
|
class HTTPError extends ts_custom_error_1.CustomError {
|
|
99
83
|
constructor(response, request, options) {
|
|
100
84
|
var _a, _b;
|
|
@@ -105,7 +89,6 @@ class HTTPError extends ts_custom_error_1.CustomError {
|
|
|
105
89
|
}
|
|
106
90
|
}
|
|
107
91
|
exports.HTTPError = HTTPError;
|
|
108
|
-
/** Error thrown when a request is aborted because of a client timeout. */
|
|
109
92
|
class TimeoutError extends ts_custom_error_1.CustomError {
|
|
110
93
|
constructor(request, options) {
|
|
111
94
|
super(`Request timed out`);
|
|
@@ -114,9 +97,6 @@ class TimeoutError extends ts_custom_error_1.CustomError {
|
|
|
114
97
|
}
|
|
115
98
|
}
|
|
116
99
|
exports.TimeoutError = TimeoutError;
|
|
117
|
-
/**
|
|
118
|
-
* Given a request, reject the request when a timeout is exceeded
|
|
119
|
-
*/
|
|
120
100
|
function timeoutFetch(request, abortController, options) {
|
|
121
101
|
return new Promise((resolve, reject) => {
|
|
122
102
|
const timer = setTimeout(() => {
|
|
@@ -143,41 +123,24 @@ class RequestClient {
|
|
|
143
123
|
throwHttpErrors: options.throwHttpErrors !== false,
|
|
144
124
|
timeout: (_b = options.timeout) !== null && _b !== void 0 ? _b : 10000
|
|
145
125
|
};
|
|
146
|
-
// Timeout support. Use our own abort controller so consumers can pass in their own `signal`
|
|
147
|
-
// if they wish to use timeouts alongside other logic to abort a request
|
|
148
126
|
this.abortController = new abort_controller_1.default();
|
|
149
127
|
if (this.options.signal) {
|
|
150
|
-
// Listen to consumer abort events to also abort our internal controller
|
|
151
128
|
this.options.signal.addEventListener('abort', () => {
|
|
152
129
|
this.abortController.abort();
|
|
153
130
|
});
|
|
154
131
|
}
|
|
155
|
-
// Use our internal abort controller for fetch
|
|
156
132
|
this.options.signal = this.abortController.signal;
|
|
157
|
-
this.
|
|
158
|
-
'json',
|
|
159
|
-
'password',
|
|
160
|
-
'searchParams',
|
|
161
|
-
'throwHttpErrors',
|
|
162
|
-
'timeout',
|
|
163
|
-
'username'
|
|
164
|
-
]);
|
|
165
|
-
// Construct a request object to send to the Fetch API
|
|
166
|
-
this.request = new fetch_1.Request(url, this.cleanedOptions);
|
|
167
|
-
// Parse search params and merge them with the request URL
|
|
133
|
+
this.request = new fetch_1.Request(url, this.options);
|
|
168
134
|
if (this.options.searchParams) {
|
|
169
|
-
// The type is a bit too restrictive, since you can pass in other primitives like `{ foo: 1, bar: true }`
|
|
170
135
|
const searchParams = new URLSearchParams(this.options.searchParams);
|
|
171
136
|
const url = new URL(this.request.url);
|
|
172
137
|
url.search = searchParams.toString();
|
|
173
|
-
|
|
174
|
-
this.request = new fetch_1.Request(new fetch_1.Request(url.toString(), this.request), this.cleanedOptions);
|
|
138
|
+
this.request = new fetch_1.Request(new fetch_1.Request(url.toString(), this.request), this.options);
|
|
175
139
|
}
|
|
176
|
-
// Automatically handle json header + stringification as a convenience when using `json` option
|
|
177
140
|
if (this.options.json !== undefined) {
|
|
178
|
-
this.
|
|
141
|
+
this.options.body = JSON.stringify(this.options.json);
|
|
179
142
|
this.request.headers.set('content-type', 'application/json');
|
|
180
|
-
this.request = new fetch_1.Request(this.request, { body: this.
|
|
143
|
+
this.request = new fetch_1.Request(this.request, { body: this.options.body });
|
|
181
144
|
}
|
|
182
145
|
}
|
|
183
146
|
async executeRequest() {
|
|
@@ -194,9 +157,6 @@ class RequestClient {
|
|
|
194
157
|
}
|
|
195
158
|
return response;
|
|
196
159
|
}
|
|
197
|
-
/**
|
|
198
|
-
* Make a fetch request, running all beforeRequest hooks, and optionally wrap in a timeout
|
|
199
|
-
*/
|
|
200
160
|
async fetch() {
|
|
201
161
|
var _a;
|
|
202
162
|
for (const hook of (_a = this.options.beforeRequest) !== null && _a !== void 0 ? _a : []) {
|
|
@@ -211,10 +171,6 @@ class RequestClient {
|
|
|
211
171
|
return timeoutFetch(this.request.clone(), this.abortController, this.options);
|
|
212
172
|
}
|
|
213
173
|
}
|
|
214
|
-
/**
|
|
215
|
-
* Creates a new instance of the fetch request client,
|
|
216
|
-
* optionally with default configuration to apply to all requests made with the client
|
|
217
|
-
*/
|
|
218
174
|
function createInstance(defaults = {}) {
|
|
219
175
|
const client = (url, options = {}) => new RequestClient(url, mergeOptions(defaults, options)).executeRequest();
|
|
220
176
|
client.extend = (newDefaults) => createInstance(mergeOptions(defaults, newDefaults));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request-client.js","sourceRoot":"","sources":["../../src/request-client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wEAA8C;AAC9C,qDAA6C;AAC7C,iDAA2D;AAC3D,
|
|
1
|
+
{"version":3,"file":"request-client.js","sourceRoot":"","sources":["../../src/request-client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wEAA8C;AAC9C,qDAA6C;AAC7C,iDAA2D;AAC3D,iDAAyC;AAmFzC,MAAM,YAAY,GAAG,CAAC,KAA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OAAO,CAAC,CAAC,CAAC,cAAc,EAAK,CAAA;IAC7E,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"}
|
|
@@ -22,9 +22,6 @@ export declare type Options = {
|
|
|
22
22
|
};
|
|
23
23
|
interface AnalyticsContext {
|
|
24
24
|
page?: {
|
|
25
|
-
/**
|
|
26
|
-
* {@link https://github.com/segmentio/analytics.js-integrations/blob/2d5c637c022d2661c23449aed237d0d546bf062d/integrations/segmentio/lib/index.js#L151}
|
|
27
|
-
*/
|
|
28
25
|
path?: string;
|
|
29
26
|
referrer?: string;
|
|
30
27
|
search?: string;
|
|
@@ -32,54 +29,26 @@ interface AnalyticsContext {
|
|
|
32
29
|
url?: string;
|
|
33
30
|
};
|
|
34
31
|
metrics?: CompactMetric[];
|
|
35
|
-
/**
|
|
36
|
-
* {@link https://github.com/segmentio/analytics.js-integrations/blob/2d5c637c022d2661c23449aed237d0d546bf062d/integrations/segmentio/lib/index.js#L285}
|
|
37
|
-
*/
|
|
38
32
|
userAgent?: string;
|
|
39
|
-
/**
|
|
40
|
-
* {@link https://github.com/segmentio/analytics.js-integrations/blob/2d5c637c022d2661c23449aed237d0d546bf062d/integrations/segmentio/lib/index.js#L286-L289}
|
|
41
|
-
*/
|
|
42
33
|
locale?: string;
|
|
43
|
-
/**
|
|
44
|
-
* {@link https://github.com/segmentio/analytics.js-integrations/blob/2d5c637c022d2661c23449aed237d0d546bf062d/integrations/segmentio/lib/index.js#L290-L291}
|
|
45
|
-
*/
|
|
46
34
|
library?: {
|
|
47
35
|
name: string;
|
|
48
36
|
version: string;
|
|
49
37
|
};
|
|
50
|
-
/**
|
|
51
|
-
* {@link https://github.com/segmentio/analytics.js-integrations/blob/2d5c637c022d2661c23449aed237d0d546bf062d/integrations/segmentio/lib/index.js#L292-L301}
|
|
52
|
-
*/
|
|
53
38
|
traits?: {
|
|
54
39
|
crossDomainId: string;
|
|
55
40
|
};
|
|
56
|
-
/**
|
|
57
|
-
* utm params
|
|
58
|
-
* {@link https://github.com/segmentio/analytics.js-integrations/blob/2d5c637c022d2661c23449aed237d0d546bf062d/integrations/segmentio/lib/index.js#L303-L305}
|
|
59
|
-
* {@link https://github.com/segmentio/utm-params/blob/master/lib/index.js#L49}
|
|
60
|
-
*/
|
|
61
41
|
campaign?: {
|
|
62
|
-
/**
|
|
63
|
-
* This can also come from the "utm_campaign" param
|
|
64
|
-
*
|
|
65
|
-
* {@link https://github.com/segmentio/utm-params/blob/master/lib/index.js#L40}
|
|
66
|
-
*/
|
|
67
42
|
name: string;
|
|
68
43
|
term: string;
|
|
69
44
|
source: string;
|
|
70
45
|
medium: string;
|
|
71
46
|
content: string;
|
|
72
47
|
};
|
|
73
|
-
/**
|
|
74
|
-
* {@link https://github.com/segmentio/analytics.js-integrations/blob/2d5c637c022d2661c23449aed237d0d546bf062d/integrations/segmentio/lib/index.js#L415}
|
|
75
|
-
*/
|
|
76
48
|
referrer?: {
|
|
77
49
|
btid?: string;
|
|
78
50
|
urid?: string;
|
|
79
51
|
};
|
|
80
|
-
/**
|
|
81
|
-
* {@link https://github.com/segmentio/analytics.js-integrations/blob/2d5c637c022d2661c23449aed237d0d546bf062d/integrations/segmentio/lib/index.js#L322}
|
|
82
|
-
*/
|
|
83
52
|
amp?: {
|
|
84
53
|
id: string;
|
|
85
54
|
};
|
|
@@ -104,18 +73,9 @@ export interface SegmentEvent {
|
|
|
104
73
|
groupId?: ID;
|
|
105
74
|
previousId?: ID;
|
|
106
75
|
event?: string;
|
|
107
|
-
/**
|
|
108
|
-
* {@link https://github.com/segmentio/analytics.js-integrations/blob/2d5c637c022d2661c23449aed237d0d546bf062d/integrations/segmentio/lib/index.js#L284}
|
|
109
|
-
*/
|
|
110
76
|
writeKey?: string;
|
|
111
77
|
receivedAt?: Date | string;
|
|
112
|
-
/**
|
|
113
|
-
* {@link https://github.com/segmentio/analytics.js-integrations/blob/2d5c637c022d2661c23449aed237d0d546bf062d/integrations/segmentio/lib/index.js#L151}
|
|
114
|
-
*/
|
|
115
78
|
sentAt?: Date | string;
|
|
116
|
-
/**
|
|
117
|
-
* {@link https://github.com/segmentio/analytics.js-integrations/blob/2d5c637c022d2661c23449aed237d0d546bf062d/integrations/segmentio/lib/index.js#L311-L320}
|
|
118
|
-
*/
|
|
119
79
|
_metadata?: {
|
|
120
80
|
failedInitializations?: unknown[];
|
|
121
81
|
bundled?: string[];
|
package/dist/cjs/time.d.ts
CHANGED
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,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"}
|
|
@@ -9,39 +9,14 @@ 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
|
-
* Temporary way to "register" autocomplete fields.
|
|
36
|
-
* This is likely going to change as we productionalize the data model and definition object
|
|
37
|
-
*/
|
|
38
17
|
autocompleteFields?: {
|
|
39
18
|
[K in keyof Payload]?: RequestFn<Settings, Payload, AutocompleteResponse>;
|
|
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> {
|
|
@@ -68,10 +42,6 @@ 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;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @ts-ignore no types
|
|
2
1
|
import { AggregateAjvError } from '@segment/ajv-human-errors';
|
|
3
2
|
import Ajv from 'ajv';
|
|
4
3
|
import { EventEmitter } from 'events';
|
|
@@ -11,12 +10,7 @@ import { Response } from '../fetch';
|
|
|
11
10
|
import { Step, Steps } from './step';
|
|
12
11
|
class MapInput extends Step {
|
|
13
12
|
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
13
|
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
14
|
data.payload = transform(data.mapping, data.payload);
|
|
21
15
|
}
|
|
22
16
|
return Promise.resolve('MapInput completed');
|
|
@@ -27,30 +21,20 @@ export class Validate extends Step {
|
|
|
27
21
|
super();
|
|
28
22
|
this.field = field;
|
|
29
23
|
const ajv = new Ajv({
|
|
30
|
-
// Coerce types to be a bit more liberal.
|
|
31
24
|
coerceTypes: true,
|
|
32
|
-
// Return all validation errors, not just the first.
|
|
33
25
|
allErrors: true,
|
|
34
|
-
// Include reference to schema and data in error values.
|
|
35
26
|
verbose: true,
|
|
36
|
-
// Use a more parse-able format for JSON paths.
|
|
37
27
|
jsonPointers: true
|
|
38
28
|
});
|
|
39
29
|
this.validate = ajv.compile(schema);
|
|
40
30
|
}
|
|
41
31
|
executeStep(data) {
|
|
42
32
|
if (!this.validate(data[this.field])) {
|
|
43
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
44
33
|
throw new AggregateAjvError(this.validate.errors);
|
|
45
34
|
}
|
|
46
35
|
return Promise.resolve('Validate completed');
|
|
47
36
|
}
|
|
48
37
|
}
|
|
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
38
|
class Request extends Step {
|
|
55
39
|
constructor(extendRequest, requestFn) {
|
|
56
40
|
super();
|
|
@@ -64,26 +48,17 @@ class Request extends Step {
|
|
|
64
48
|
}
|
|
65
49
|
const requestClient = this.createRequestClient(data);
|
|
66
50
|
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
51
|
if (response instanceof Response) {
|
|
72
52
|
return (_a = response.data) !== null && _a !== void 0 ? _a : response.content;
|
|
73
53
|
}
|
|
74
|
-
// otherwise, we don't really know what this is, so return as-is
|
|
75
54
|
return response;
|
|
76
55
|
}
|
|
77
56
|
createRequestClient(data) {
|
|
78
57
|
var _a, _b;
|
|
79
|
-
// TODO turn `extendRequest` into a beforeRequest hook
|
|
80
58
|
const options = (_b = (_a = this.extendRequest) === null || _a === void 0 ? void 0 : _a.call(this, data)) !== null && _b !== void 0 ? _b : {};
|
|
81
59
|
const client = createRequestClient(options, {
|
|
82
60
|
afterResponse: [
|
|
83
|
-
// Keep track of the request(s) associated with a response
|
|
84
61
|
(request, options, response) => {
|
|
85
|
-
// TODO figure out the types here...
|
|
86
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
87
62
|
const modifiedResponse = response;
|
|
88
63
|
modifiedResponse.request = request;
|
|
89
64
|
modifiedResponse.options = options;
|
|
@@ -95,7 +70,6 @@ class Request extends Step {
|
|
|
95
70
|
return client;
|
|
96
71
|
}
|
|
97
72
|
}
|
|
98
|
-
// CachedRequest is like Request but cached. Next question.
|
|
99
73
|
class CachedRequest extends Request {
|
|
100
74
|
constructor(extension, config) {
|
|
101
75
|
super(extension);
|
|
@@ -127,20 +101,12 @@ class CachedRequest extends Request {
|
|
|
127
101
|
throw e;
|
|
128
102
|
}
|
|
129
103
|
}
|
|
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
104
|
if ((v !== null && v !== undefined) || this.negative) {
|
|
135
105
|
this.cache.set(k, v);
|
|
136
106
|
}
|
|
137
107
|
return 'cache miss';
|
|
138
108
|
}
|
|
139
109
|
}
|
|
140
|
-
/**
|
|
141
|
-
* Action is the beginning step for all partner actions. Entrypoints always start with the
|
|
142
|
-
* MapAndValidateInput step.
|
|
143
|
-
*/
|
|
144
110
|
export class Action extends EventEmitter {
|
|
145
111
|
constructor(definition, extendRequest) {
|
|
146
112
|
super();
|
|
@@ -149,9 +115,6 @@ export class Action extends EventEmitter {
|
|
|
149
115
|
this.steps.push(step);
|
|
150
116
|
this.autocompleteCache = {};
|
|
151
117
|
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
118
|
this.extendRequest = extendRequest;
|
|
156
119
|
}
|
|
157
120
|
this.loadDefinition(definition);
|
|
@@ -164,7 +127,6 @@ export class Action extends EventEmitter {
|
|
|
164
127
|
}
|
|
165
128
|
return results;
|
|
166
129
|
}
|
|
167
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
168
130
|
executeAutocomplete(field, data) {
|
|
169
131
|
if (!this.autocompleteCache[field]) {
|
|
170
132
|
return {
|
|
@@ -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,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AACrC,O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C,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"}
|
|
@@ -3,10 +3,8 @@ export function fieldsToJsonSchema(fields = {}) {
|
|
|
3
3
|
const properties = {};
|
|
4
4
|
for (const key of Object.keys(fields)) {
|
|
5
5
|
const field = fields[key];
|
|
6
|
-
// Remove the `required` property from fields because it'll get lifted up into an array of required keys
|
|
7
6
|
properties[key] = Object.assign({}, field);
|
|
8
7
|
delete properties[key].required;
|
|
9
|
-
// Grab all the field keys with `required: true`
|
|
10
8
|
if (field.required) {
|
|
11
9
|
required.push(key);
|
|
12
10
|
}
|