@readme/api-core 7.0.0-alpha.6 → 7.0.0-beta.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/chunk-ASE5F2OQ.js +587 -0
- package/dist/chunk-ASE5F2OQ.js.map +1 -0
- package/dist/chunk-HGLVXDVZ.cjs +587 -0
- package/dist/chunk-HGLVXDVZ.cjs.map +1 -0
- package/dist/index.cjs +11 -434
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +8 -431
- package/dist/index.js.map +1 -1
- package/dist/lib/index.cjs +15 -0
- package/dist/lib/index.cjs.map +1 -0
- package/dist/lib/index.d.cts +62 -0
- package/dist/lib/index.d.ts +62 -0
- package/dist/lib/index.js +15 -0
- package/dist/lib/index.js.map +1 -0
- package/package.json +9 -4
- package/src/lib/index.ts +3 -1
- package/src/lib/prepareParams.ts +4 -2
- package/tsup.config.ts +8 -2
|
@@ -0,0 +1,587 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;// src/lib/getJSONSchemaDefaults.ts
|
|
2
|
+
var _jsonschematraverse = require('json-schema-traverse'); var _jsonschematraverse2 = _interopRequireDefault(_jsonschematraverse);
|
|
3
|
+
function getJSONSchemaDefaults(jsonSchemas) {
|
|
4
|
+
return jsonSchemas.map(({ type: payloadType, schema: jsonSchema }) => {
|
|
5
|
+
const defaults = {};
|
|
6
|
+
_jsonschematraverse2.default.call(void 0,
|
|
7
|
+
jsonSchema,
|
|
8
|
+
(schema, pointer, rootSchema, parentPointer, parentKeyword, parentSchema, indexProperty) => {
|
|
9
|
+
if (!pointer.startsWith("/properties/")) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
if (Array.isArray(_optionalChain([parentSchema, 'optionalAccess', _ => _.required])) && _optionalChain([parentSchema, 'optionalAccess', _2 => _2.required, 'access', _3 => _3.includes, 'call', _4 => _4(String(indexProperty))])) {
|
|
13
|
+
if (schema.type === "object" && indexProperty) {
|
|
14
|
+
defaults[indexProperty] = {};
|
|
15
|
+
}
|
|
16
|
+
let destination = defaults;
|
|
17
|
+
if (parentPointer) {
|
|
18
|
+
parentPointer.replace(/\/properties/g, "").split("/").forEach((subSchema) => {
|
|
19
|
+
if (subSchema === "") {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
destination = _optionalChain([destination, 'optionalAccess', _5 => _5[subSchema]]) || {};
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
if (schema.default !== void 0) {
|
|
26
|
+
if (indexProperty !== void 0) {
|
|
27
|
+
destination[indexProperty] = schema.default;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
);
|
|
33
|
+
if (!Object.keys(defaults).length) {
|
|
34
|
+
return {};
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
// @todo should we filter out empty and undefined objects from here with `remove-undefined-objects`?
|
|
38
|
+
[payloadType]: defaults
|
|
39
|
+
};
|
|
40
|
+
}).reduce((prev, next) => Object.assign(prev, next));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// src/lib/parseResponse.ts
|
|
44
|
+
var _utils = require('oas/utils');
|
|
45
|
+
async function parseResponse(response) {
|
|
46
|
+
const contentType = response.headers.get("Content-Type");
|
|
47
|
+
const isJSON = contentType && (_utils.matchesMimeType.json(contentType) || _utils.matchesMimeType.wildcard(contentType));
|
|
48
|
+
const responseBody = await response.text();
|
|
49
|
+
let data = responseBody;
|
|
50
|
+
if (isJSON) {
|
|
51
|
+
try {
|
|
52
|
+
data = JSON.parse(responseBody);
|
|
53
|
+
} catch (e) {
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
data,
|
|
58
|
+
status: response.status,
|
|
59
|
+
headers: response.headers,
|
|
60
|
+
res: response
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// src/lib/prepareAuth.ts
|
|
65
|
+
function prepareAuth(authKey, operation) {
|
|
66
|
+
if (authKey.length === 0) {
|
|
67
|
+
return {};
|
|
68
|
+
}
|
|
69
|
+
const preparedAuth = {};
|
|
70
|
+
const security = operation.getSecurity();
|
|
71
|
+
if (security.length === 0) {
|
|
72
|
+
return {};
|
|
73
|
+
}
|
|
74
|
+
if (security.every((s) => Object.keys(s).length > 1)) {
|
|
75
|
+
throw new Error(
|
|
76
|
+
"Sorry, this operation currently requires multiple forms of authentication which this library doesn't yet support."
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
const usableSecurity = security.map((s) => {
|
|
80
|
+
return Object.keys(s).length === 1 ? s : false;
|
|
81
|
+
}).filter(Boolean);
|
|
82
|
+
const usableSecuritySchemes = usableSecurity.map((s) => Object.keys(s)).reduce((prev, next) => prev.concat(next), []);
|
|
83
|
+
const preparedSecurity = operation.prepareSecurity();
|
|
84
|
+
if (authKey.length >= 2) {
|
|
85
|
+
if (!("Basic" in preparedSecurity)) {
|
|
86
|
+
throw new Error("Multiple auth tokens were supplied for this endpoint but only a single token is needed.");
|
|
87
|
+
}
|
|
88
|
+
const schemes2 = preparedSecurity.Basic.filter((s) => usableSecuritySchemes.includes(s._key));
|
|
89
|
+
if (!schemes2.length) {
|
|
90
|
+
throw new Error(
|
|
91
|
+
"Credentials for Basic Authentication were supplied but this operation requires another form of auth in that case, which this library does not yet support. This operation does, however, allow supplying a single auth token."
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
const scheme2 = schemes2.shift();
|
|
95
|
+
preparedAuth[scheme2._key] = {
|
|
96
|
+
user: authKey[0],
|
|
97
|
+
pass: authKey.length === 2 ? authKey[1] : ""
|
|
98
|
+
};
|
|
99
|
+
return preparedAuth;
|
|
100
|
+
}
|
|
101
|
+
const usableScheme = usableSecuritySchemes[0];
|
|
102
|
+
const schemes = Object.entries(preparedSecurity).map(([, ps]) => ps.filter((s) => usableScheme === s._key)).reduce((prev, next) => prev.concat(next), []);
|
|
103
|
+
const scheme = schemes.shift();
|
|
104
|
+
switch (scheme.type) {
|
|
105
|
+
case "http":
|
|
106
|
+
if (scheme.scheme === "basic") {
|
|
107
|
+
preparedAuth[scheme._key] = {
|
|
108
|
+
user: authKey[0],
|
|
109
|
+
pass: authKey.length === 2 ? authKey[1] : ""
|
|
110
|
+
};
|
|
111
|
+
} else if (scheme.scheme === "bearer") {
|
|
112
|
+
preparedAuth[scheme._key] = authKey[0];
|
|
113
|
+
}
|
|
114
|
+
break;
|
|
115
|
+
case "oauth2":
|
|
116
|
+
preparedAuth[scheme._key] = authKey[0];
|
|
117
|
+
break;
|
|
118
|
+
case "apiKey":
|
|
119
|
+
if (scheme.in === "query" || scheme.in === "header" || scheme.in === "cookie") {
|
|
120
|
+
preparedAuth[scheme._key] = authKey[0];
|
|
121
|
+
}
|
|
122
|
+
break;
|
|
123
|
+
default:
|
|
124
|
+
throw new Error(
|
|
125
|
+
`Sorry, this API currently uses a security scheme, ${scheme.type}, which this library doesn't yet support.`
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
return preparedAuth;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// src/lib/prepareParams.ts
|
|
132
|
+
var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
|
|
133
|
+
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
134
|
+
var _stream = require('stream'); var _stream2 = _interopRequireDefault(_stream);
|
|
135
|
+
var _caseless = require('caseless'); var _caseless2 = _interopRequireDefault(_caseless);
|
|
136
|
+
var _parserjs = require('datauri/parser.js'); var _parserjs2 = _interopRequireDefault(_parserjs);
|
|
137
|
+
var _syncjs = require('datauri/sync.js'); var _syncjs2 = _interopRequireDefault(_syncjs);
|
|
138
|
+
|
|
139
|
+
// node_modules/get-stream/source/contents.js
|
|
140
|
+
var getStreamContents = async (stream2, { init, convertChunk, getSize, truncateChunk, addChunk, getFinalChunk, finalize }, { maxBuffer = Number.POSITIVE_INFINITY } = {}) => {
|
|
141
|
+
if (!isAsyncIterable(stream2)) {
|
|
142
|
+
throw new Error("The first argument must be a Readable, a ReadableStream, or an async iterable.");
|
|
143
|
+
}
|
|
144
|
+
const state = init();
|
|
145
|
+
state.length = 0;
|
|
146
|
+
try {
|
|
147
|
+
for await (const chunk of stream2) {
|
|
148
|
+
const chunkType = getChunkType(chunk);
|
|
149
|
+
const convertedChunk = convertChunk[chunkType](chunk, state);
|
|
150
|
+
appendChunk({ convertedChunk, state, getSize, truncateChunk, addChunk, maxBuffer });
|
|
151
|
+
}
|
|
152
|
+
appendFinalChunk({ state, convertChunk, getSize, truncateChunk, addChunk, getFinalChunk, maxBuffer });
|
|
153
|
+
return finalize(state);
|
|
154
|
+
} catch (error) {
|
|
155
|
+
error.bufferedData = finalize(state);
|
|
156
|
+
throw error;
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
var appendFinalChunk = ({ state, getSize, truncateChunk, addChunk, getFinalChunk, maxBuffer }) => {
|
|
160
|
+
const convertedChunk = getFinalChunk(state);
|
|
161
|
+
if (convertedChunk !== void 0) {
|
|
162
|
+
appendChunk({ convertedChunk, state, getSize, truncateChunk, addChunk, maxBuffer });
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
var appendChunk = ({ convertedChunk, state, getSize, truncateChunk, addChunk, maxBuffer }) => {
|
|
166
|
+
const chunkSize = getSize(convertedChunk);
|
|
167
|
+
const newLength = state.length + chunkSize;
|
|
168
|
+
if (newLength <= maxBuffer) {
|
|
169
|
+
addNewChunk(convertedChunk, state, addChunk, newLength);
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
const truncatedChunk = truncateChunk(convertedChunk, maxBuffer - state.length);
|
|
173
|
+
if (truncatedChunk !== void 0) {
|
|
174
|
+
addNewChunk(truncatedChunk, state, addChunk, maxBuffer);
|
|
175
|
+
}
|
|
176
|
+
throw new MaxBufferError();
|
|
177
|
+
};
|
|
178
|
+
var addNewChunk = (convertedChunk, state, addChunk, newLength) => {
|
|
179
|
+
state.contents = addChunk(convertedChunk, state, newLength);
|
|
180
|
+
state.length = newLength;
|
|
181
|
+
};
|
|
182
|
+
var isAsyncIterable = (stream2) => typeof stream2 === "object" && stream2 !== null && typeof stream2[Symbol.asyncIterator] === "function";
|
|
183
|
+
var getChunkType = (chunk) => {
|
|
184
|
+
const typeOfChunk = typeof chunk;
|
|
185
|
+
if (typeOfChunk === "string") {
|
|
186
|
+
return "string";
|
|
187
|
+
}
|
|
188
|
+
if (typeOfChunk !== "object" || chunk === null) {
|
|
189
|
+
return "others";
|
|
190
|
+
}
|
|
191
|
+
if (_optionalChain([globalThis, 'access', _6 => _6.Buffer, 'optionalAccess', _7 => _7.isBuffer, 'call', _8 => _8(chunk)])) {
|
|
192
|
+
return "buffer";
|
|
193
|
+
}
|
|
194
|
+
const prototypeName = objectToString.call(chunk);
|
|
195
|
+
if (prototypeName === "[object ArrayBuffer]") {
|
|
196
|
+
return "arrayBuffer";
|
|
197
|
+
}
|
|
198
|
+
if (prototypeName === "[object DataView]") {
|
|
199
|
+
return "dataView";
|
|
200
|
+
}
|
|
201
|
+
if (Number.isInteger(chunk.byteLength) && Number.isInteger(chunk.byteOffset) && objectToString.call(chunk.buffer) === "[object ArrayBuffer]") {
|
|
202
|
+
return "typedArray";
|
|
203
|
+
}
|
|
204
|
+
return "others";
|
|
205
|
+
};
|
|
206
|
+
var { toString: objectToString } = Object.prototype;
|
|
207
|
+
var MaxBufferError = (_class = class extends Error {
|
|
208
|
+
__init() {this.name = "MaxBufferError"}
|
|
209
|
+
constructor() {
|
|
210
|
+
super("maxBuffer exceeded");_class.prototype.__init.call(this);;
|
|
211
|
+
}
|
|
212
|
+
}, _class);
|
|
213
|
+
|
|
214
|
+
// node_modules/get-stream/source/utils.js
|
|
215
|
+
var noop = () => void 0;
|
|
216
|
+
var throwObjectStream = (chunk) => {
|
|
217
|
+
throw new Error(`Streams in object mode are not supported: ${String(chunk)}`);
|
|
218
|
+
};
|
|
219
|
+
var getLengthProp = (convertedChunk) => convertedChunk.length;
|
|
220
|
+
|
|
221
|
+
// node_modules/get-stream/source/array-buffer.js
|
|
222
|
+
async function getStreamAsArrayBuffer(stream2, options) {
|
|
223
|
+
return getStreamContents(stream2, arrayBufferMethods, options);
|
|
224
|
+
}
|
|
225
|
+
var initArrayBuffer = () => ({ contents: new ArrayBuffer(0) });
|
|
226
|
+
var useTextEncoder = (chunk) => textEncoder.encode(chunk);
|
|
227
|
+
var textEncoder = new TextEncoder();
|
|
228
|
+
var useUint8Array = (chunk) => new Uint8Array(chunk);
|
|
229
|
+
var useUint8ArrayWithOffset = (chunk) => new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength);
|
|
230
|
+
var truncateArrayBufferChunk = (convertedChunk, chunkSize) => convertedChunk.slice(0, chunkSize);
|
|
231
|
+
var addArrayBufferChunk = (convertedChunk, { contents, length: previousLength }, length) => {
|
|
232
|
+
const newContents = hasArrayBufferResize() ? resizeArrayBuffer(contents, length) : resizeArrayBufferSlow(contents, length);
|
|
233
|
+
new Uint8Array(newContents).set(convertedChunk, previousLength);
|
|
234
|
+
return newContents;
|
|
235
|
+
};
|
|
236
|
+
var resizeArrayBufferSlow = (contents, length) => {
|
|
237
|
+
if (length <= contents.byteLength) {
|
|
238
|
+
return contents;
|
|
239
|
+
}
|
|
240
|
+
const arrayBuffer = new ArrayBuffer(getNewContentsLength(length));
|
|
241
|
+
new Uint8Array(arrayBuffer).set(new Uint8Array(contents), 0);
|
|
242
|
+
return arrayBuffer;
|
|
243
|
+
};
|
|
244
|
+
var resizeArrayBuffer = (contents, length) => {
|
|
245
|
+
if (length <= contents.maxByteLength) {
|
|
246
|
+
contents.resize(length);
|
|
247
|
+
return contents;
|
|
248
|
+
}
|
|
249
|
+
const arrayBuffer = new ArrayBuffer(length, { maxByteLength: getNewContentsLength(length) });
|
|
250
|
+
new Uint8Array(arrayBuffer).set(new Uint8Array(contents), 0);
|
|
251
|
+
return arrayBuffer;
|
|
252
|
+
};
|
|
253
|
+
var getNewContentsLength = (length) => SCALE_FACTOR ** Math.ceil(Math.log(length) / Math.log(SCALE_FACTOR));
|
|
254
|
+
var SCALE_FACTOR = 2;
|
|
255
|
+
var finalizeArrayBuffer = ({ contents, length }) => hasArrayBufferResize() ? contents : contents.slice(0, length);
|
|
256
|
+
var hasArrayBufferResize = () => "resize" in ArrayBuffer.prototype;
|
|
257
|
+
var arrayBufferMethods = {
|
|
258
|
+
init: initArrayBuffer,
|
|
259
|
+
convertChunk: {
|
|
260
|
+
string: useTextEncoder,
|
|
261
|
+
buffer: useUint8Array,
|
|
262
|
+
arrayBuffer: useUint8Array,
|
|
263
|
+
dataView: useUint8ArrayWithOffset,
|
|
264
|
+
typedArray: useUint8ArrayWithOffset,
|
|
265
|
+
others: throwObjectStream
|
|
266
|
+
},
|
|
267
|
+
getSize: getLengthProp,
|
|
268
|
+
truncateChunk: truncateArrayBufferChunk,
|
|
269
|
+
addChunk: addArrayBufferChunk,
|
|
270
|
+
getFinalChunk: noop,
|
|
271
|
+
finalize: finalizeArrayBuffer
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
// node_modules/get-stream/source/buffer.js
|
|
275
|
+
async function getStreamAsBuffer(stream2, options) {
|
|
276
|
+
if (!("Buffer" in globalThis)) {
|
|
277
|
+
throw new Error("getStreamAsBuffer() is only supported in Node.js");
|
|
278
|
+
}
|
|
279
|
+
try {
|
|
280
|
+
return arrayBufferToNodeBuffer(await getStreamAsArrayBuffer(stream2, options));
|
|
281
|
+
} catch (error) {
|
|
282
|
+
if (error.bufferedData !== void 0) {
|
|
283
|
+
error.bufferedData = arrayBufferToNodeBuffer(error.bufferedData);
|
|
284
|
+
}
|
|
285
|
+
throw error;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
var arrayBufferToNodeBuffer = (arrayBuffer) => globalThis.Buffer.from(arrayBuffer);
|
|
289
|
+
|
|
290
|
+
// src/lib/prepareParams.ts
|
|
291
|
+
var _lodashmerge = require('lodash.merge'); var _lodashmerge2 = _interopRequireDefault(_lodashmerge);
|
|
292
|
+
var _removeundefinedobjects = require('remove-undefined-objects'); var _removeundefinedobjects2 = _interopRequireDefault(_removeundefinedobjects);
|
|
293
|
+
var specialHeaders = ["accept", "authorization"];
|
|
294
|
+
function digestParameters(parameters) {
|
|
295
|
+
return parameters.reduce((prev, param) => {
|
|
296
|
+
if ("$ref" in param || "allOf" in param || "anyOf" in param || "oneOf" in param) {
|
|
297
|
+
throw new Error("The OpenAPI document for this operation wasn't dereferenced before processing.");
|
|
298
|
+
} else if (param.name in prev) {
|
|
299
|
+
throw new Error(
|
|
300
|
+
`The operation you are using has the same parameter, ${param.name}, spread across multiple entry points. We unfortunately can't handle this right now.`
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
return Object.assign(prev, { [param.name]: param });
|
|
304
|
+
}, {});
|
|
305
|
+
}
|
|
306
|
+
function isEmpty(obj) {
|
|
307
|
+
return [Object, Array].includes((obj || {}).constructor) && !Object.entries(obj || {}).length;
|
|
308
|
+
}
|
|
309
|
+
function isObject(thing) {
|
|
310
|
+
if (thing instanceof _stream2.default.Readable) {
|
|
311
|
+
return false;
|
|
312
|
+
}
|
|
313
|
+
return typeof thing === "object" && thing !== null && !Array.isArray(thing);
|
|
314
|
+
}
|
|
315
|
+
function isPrimitive(obj) {
|
|
316
|
+
return obj === null || typeof obj === "number" || typeof obj === "string";
|
|
317
|
+
}
|
|
318
|
+
function merge(src, target) {
|
|
319
|
+
if (Array.isArray(target)) {
|
|
320
|
+
return target;
|
|
321
|
+
} else if (!isObject(target)) {
|
|
322
|
+
return target;
|
|
323
|
+
}
|
|
324
|
+
return _lodashmerge2.default.call(void 0, src, target);
|
|
325
|
+
}
|
|
326
|
+
function processFile(paramName, file) {
|
|
327
|
+
if (typeof file === "string") {
|
|
328
|
+
const resolvedFile = _path2.default.resolve(file);
|
|
329
|
+
return new Promise((resolve, reject) => {
|
|
330
|
+
_fs2.default.stat(resolvedFile, async (err) => {
|
|
331
|
+
if (err) {
|
|
332
|
+
if (err.code === "ENOENT") {
|
|
333
|
+
return resolve(void 0);
|
|
334
|
+
}
|
|
335
|
+
return reject(err);
|
|
336
|
+
}
|
|
337
|
+
const fileMetadata = await _syncjs2.default.call(void 0, resolvedFile);
|
|
338
|
+
const payloadFilename = encodeURIComponent(_path2.default.basename(resolvedFile));
|
|
339
|
+
return resolve({
|
|
340
|
+
paramName,
|
|
341
|
+
base64: _optionalChain([fileMetadata, 'optionalAccess', _9 => _9.content, 'optionalAccess', _10 => _10.replace, 'call', _11 => _11(";base64", `;name=${payloadFilename};base64`)]),
|
|
342
|
+
filename: payloadFilename,
|
|
343
|
+
buffer: fileMetadata.buffer
|
|
344
|
+
});
|
|
345
|
+
});
|
|
346
|
+
});
|
|
347
|
+
} else if (file instanceof _stream2.default.Readable) {
|
|
348
|
+
return getStreamAsBuffer(file).then((buffer) => {
|
|
349
|
+
const filePath = file.path;
|
|
350
|
+
const parser = new (0, _parserjs2.default)();
|
|
351
|
+
const base64 = parser.format(filePath, buffer).content;
|
|
352
|
+
const payloadFilename = encodeURIComponent(_path2.default.basename(filePath));
|
|
353
|
+
return {
|
|
354
|
+
paramName,
|
|
355
|
+
base64: _optionalChain([base64, 'optionalAccess', _12 => _12.replace, 'call', _13 => _13(";base64", `;name=${payloadFilename};base64`)]),
|
|
356
|
+
filename: payloadFilename,
|
|
357
|
+
buffer
|
|
358
|
+
};
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
return Promise.reject(
|
|
362
|
+
new TypeError(
|
|
363
|
+
paramName ? `The data supplied for the \`${paramName}\` request body parameter is not a file handler that we support.` : "The data supplied for the request body payload is not a file handler that we support."
|
|
364
|
+
)
|
|
365
|
+
);
|
|
366
|
+
}
|
|
367
|
+
async function prepareParams(operation, body, metadata) {
|
|
368
|
+
let metadataIntersected = false;
|
|
369
|
+
const digestedParameters = digestParameters(operation.getParameters());
|
|
370
|
+
const jsonSchema = operation.getParametersAsJSONSchema();
|
|
371
|
+
metadata = _removeundefinedobjects2.default.call(void 0, metadata);
|
|
372
|
+
if (!jsonSchema && (body !== void 0 || metadata !== void 0)) {
|
|
373
|
+
let throwNoParamsError = true;
|
|
374
|
+
if (body !== void 0) {
|
|
375
|
+
if (typeof body === "object" && body !== null && !Array.isArray(body)) {
|
|
376
|
+
if (Object.keys(body).length <= 2) {
|
|
377
|
+
const bodyParams = _caseless2.default.call(void 0, body);
|
|
378
|
+
if (specialHeaders.some((header) => bodyParams.has(header))) {
|
|
379
|
+
throwNoParamsError = false;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
if (throwNoParamsError) {
|
|
385
|
+
throw new Error(
|
|
386
|
+
"You supplied metadata and/or body data for this operation but it doesn't have any documented parameters or request payloads. If you think this is an error please contact support for the API you're using."
|
|
387
|
+
);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
const jsonSchemaDefaults = jsonSchema ? getJSONSchemaDefaults(jsonSchema) : {};
|
|
391
|
+
const params = jsonSchemaDefaults;
|
|
392
|
+
if (typeof body !== "undefined") {
|
|
393
|
+
if (Array.isArray(body) || isPrimitive(body)) {
|
|
394
|
+
params.body = merge(params.body, body);
|
|
395
|
+
} else if (typeof metadata === "undefined") {
|
|
396
|
+
const headerParams = _caseless2.default.call(void 0, {});
|
|
397
|
+
Object.entries(digestedParameters).forEach(([paramName, param]) => {
|
|
398
|
+
if (param.in === "header") {
|
|
399
|
+
headerParams.set(paramName, "");
|
|
400
|
+
}
|
|
401
|
+
});
|
|
402
|
+
specialHeaders.forEach((header) => {
|
|
403
|
+
if (!headerParams.has(header)) {
|
|
404
|
+
headerParams.set(header, "");
|
|
405
|
+
}
|
|
406
|
+
});
|
|
407
|
+
const intersection = Object.keys(body).filter((value) => {
|
|
408
|
+
if (Object.keys(digestedParameters).includes(value)) {
|
|
409
|
+
return true;
|
|
410
|
+
} else if (headerParams.has(value)) {
|
|
411
|
+
return true;
|
|
412
|
+
}
|
|
413
|
+
return false;
|
|
414
|
+
}).length;
|
|
415
|
+
if (intersection && intersection / Object.keys(body).length > 0.25) {
|
|
416
|
+
metadataIntersected = true;
|
|
417
|
+
metadata = merge(params.body, body);
|
|
418
|
+
body = void 0;
|
|
419
|
+
} else {
|
|
420
|
+
params.body = merge(params.body, body);
|
|
421
|
+
}
|
|
422
|
+
} else {
|
|
423
|
+
params.body = merge(params.body, body);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
if (!operation.hasRequestBody()) {
|
|
427
|
+
delete params.body;
|
|
428
|
+
} else {
|
|
429
|
+
if (!("body" in params))
|
|
430
|
+
params.body = {};
|
|
431
|
+
const payloadJsonSchema = jsonSchema.find((js) => js.type === "body");
|
|
432
|
+
if (payloadJsonSchema) {
|
|
433
|
+
if (!params.files)
|
|
434
|
+
params.files = {};
|
|
435
|
+
const conversions = [];
|
|
436
|
+
if (_optionalChain([payloadJsonSchema, 'access', _14 => _14.schema, 'optionalAccess', _15 => _15.properties])) {
|
|
437
|
+
Object.entries(_optionalChain([payloadJsonSchema, 'access', _16 => _16.schema, 'optionalAccess', _17 => _17.properties])).filter(([, schema]) => _optionalChain([schema, 'optionalAccess', _18 => _18.format]) === "binary").filter(([prop]) => Object.keys(params.body).includes(prop)).forEach(([prop]) => {
|
|
438
|
+
conversions.push(processFile(prop, params.body[prop]));
|
|
439
|
+
});
|
|
440
|
+
} else if (_optionalChain([payloadJsonSchema, 'access', _19 => _19.schema, 'optionalAccess', _20 => _20.type]) === "string") {
|
|
441
|
+
if (_optionalChain([payloadJsonSchema, 'access', _21 => _21.schema, 'optionalAccess', _22 => _22.format]) === "binary") {
|
|
442
|
+
conversions.push(processFile(void 0, params.body));
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
await Promise.all(conversions).then((fileMetadata) => fileMetadata.filter(Boolean)).then((fm) => {
|
|
446
|
+
fm.forEach((fileMetadata) => {
|
|
447
|
+
if (!fileMetadata) {
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
if (fileMetadata.paramName) {
|
|
451
|
+
params.body[fileMetadata.paramName] = fileMetadata.base64;
|
|
452
|
+
} else {
|
|
453
|
+
params.body = fileMetadata.base64;
|
|
454
|
+
}
|
|
455
|
+
if (fileMetadata.buffer && _optionalChain([params, 'optionalAccess', _23 => _23.files])) {
|
|
456
|
+
params.files[fileMetadata.filename] = fileMetadata.buffer;
|
|
457
|
+
}
|
|
458
|
+
});
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
if (operation.isFormUrlEncoded()) {
|
|
463
|
+
params.formData = merge(params.formData, params.body);
|
|
464
|
+
delete params.body;
|
|
465
|
+
}
|
|
466
|
+
if (typeof metadata !== "undefined") {
|
|
467
|
+
if (!("cookie" in params))
|
|
468
|
+
params.cookie = {};
|
|
469
|
+
if (!("header" in params))
|
|
470
|
+
params.header = {};
|
|
471
|
+
if (!("path" in params))
|
|
472
|
+
params.path = {};
|
|
473
|
+
if (!("query" in params))
|
|
474
|
+
params.query = {};
|
|
475
|
+
Object.entries(digestedParameters).forEach(([paramName, param]) => {
|
|
476
|
+
let value;
|
|
477
|
+
let metadataHeaderParam;
|
|
478
|
+
if (typeof metadata === "object" && !isEmpty(metadata)) {
|
|
479
|
+
if (paramName in metadata) {
|
|
480
|
+
value = metadata[paramName];
|
|
481
|
+
metadataHeaderParam = paramName;
|
|
482
|
+
} else if (param.in === "header") {
|
|
483
|
+
metadataHeaderParam = Object.keys(metadata).find((k) => k.toLowerCase() === paramName.toLowerCase()) || "";
|
|
484
|
+
value = metadata[metadataHeaderParam];
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
if (value === void 0) {
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
490
|
+
switch (param.in) {
|
|
491
|
+
case "path":
|
|
492
|
+
params.path[paramName] = value;
|
|
493
|
+
if (_optionalChain([metadata, 'optionalAccess', _24 => _24[paramName]]))
|
|
494
|
+
delete metadata[paramName];
|
|
495
|
+
break;
|
|
496
|
+
case "query":
|
|
497
|
+
params.query[paramName] = value;
|
|
498
|
+
if (_optionalChain([metadata, 'optionalAccess', _25 => _25[paramName]]))
|
|
499
|
+
delete metadata[paramName];
|
|
500
|
+
break;
|
|
501
|
+
case "header":
|
|
502
|
+
params.header[paramName.toLowerCase()] = value;
|
|
503
|
+
if (metadataHeaderParam && _optionalChain([metadata, 'optionalAccess', _26 => _26[metadataHeaderParam]]))
|
|
504
|
+
delete metadata[metadataHeaderParam];
|
|
505
|
+
break;
|
|
506
|
+
case "cookie":
|
|
507
|
+
params.cookie[paramName] = value;
|
|
508
|
+
if (_optionalChain([metadata, 'optionalAccess', _27 => _27[paramName]]))
|
|
509
|
+
delete metadata[paramName];
|
|
510
|
+
break;
|
|
511
|
+
default:
|
|
512
|
+
}
|
|
513
|
+
if (metadataIntersected && operation.isFormUrlEncoded()) {
|
|
514
|
+
if (paramName in params.formData) {
|
|
515
|
+
delete params.formData[paramName];
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
});
|
|
519
|
+
if (!isEmpty(metadata)) {
|
|
520
|
+
if (typeof metadata === "object") {
|
|
521
|
+
specialHeaders.forEach((headerName) => {
|
|
522
|
+
const headerParam = Object.keys(metadata || {}).find((m) => m.toLowerCase() === headerName);
|
|
523
|
+
if (headerParam) {
|
|
524
|
+
if (typeof metadata === "object") {
|
|
525
|
+
if (typeof params.header === "object") {
|
|
526
|
+
params.header[headerName] = metadata[headerParam];
|
|
527
|
+
}
|
|
528
|
+
delete metadata[headerParam];
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
if (operation.isFormUrlEncoded()) {
|
|
534
|
+
params.formData = merge(params.formData, metadata);
|
|
535
|
+
} else {
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
["body", "cookie", "files", "formData", "header", "path", "query"].forEach((type) => {
|
|
540
|
+
if (type in params && isEmpty(params[type])) {
|
|
541
|
+
delete params[type];
|
|
542
|
+
}
|
|
543
|
+
});
|
|
544
|
+
return params;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
// src/lib/prepareServer.ts
|
|
548
|
+
function stripTrailingSlash(url) {
|
|
549
|
+
if (url[url.length - 1] === "/") {
|
|
550
|
+
return url.slice(0, -1);
|
|
551
|
+
}
|
|
552
|
+
return url;
|
|
553
|
+
}
|
|
554
|
+
function prepareServer(spec, url, variables = {}) {
|
|
555
|
+
let serverIdx;
|
|
556
|
+
const sanitizedUrl = stripTrailingSlash(url);
|
|
557
|
+
(spec.api.servers || []).forEach((server, i) => {
|
|
558
|
+
if (server.url === sanitizedUrl) {
|
|
559
|
+
serverIdx = i;
|
|
560
|
+
}
|
|
561
|
+
});
|
|
562
|
+
if (serverIdx) {
|
|
563
|
+
return {
|
|
564
|
+
selected: serverIdx,
|
|
565
|
+
variables
|
|
566
|
+
};
|
|
567
|
+
} else if (Object.keys(variables).length) {
|
|
568
|
+
} else {
|
|
569
|
+
const server = spec.splitVariables(url);
|
|
570
|
+
if (server) {
|
|
571
|
+
return {
|
|
572
|
+
selected: server.selected,
|
|
573
|
+
variables: server.variables
|
|
574
|
+
};
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
return false;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
|
|
581
|
+
|
|
582
|
+
|
|
583
|
+
|
|
584
|
+
|
|
585
|
+
|
|
586
|
+
exports.getJSONSchemaDefaults = getJSONSchemaDefaults; exports.parseResponse = parseResponse; exports.prepareAuth = prepareAuth; exports.prepareParams = prepareParams; exports.prepareServer = prepareServer;
|
|
587
|
+
//# sourceMappingURL=chunk-HGLVXDVZ.cjs.map
|