@readme/api-core 7.0.0-beta.0 → 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-PWY7T36C.js → chunk-ASE5F2OQ.js} +154 -2
- package/dist/chunk-ASE5F2OQ.js.map +1 -0
- package/dist/{chunk-TOMHUGQA.cjs → chunk-HGLVXDVZ.cjs} +167 -15
- package/dist/chunk-HGLVXDVZ.cjs.map +1 -0
- package/dist/index.cjs +5 -5
- package/dist/index.js +1 -1
- package/dist/lib/index.cjs +2 -2
- package/dist/lib/index.js +1 -1
- package/package.json +4 -4
- package/src/lib/prepareParams.ts +2 -0
- package/tsup.config.ts +6 -0
- package/dist/chunk-PWY7T36C.js.map +0 -1
- package/dist/chunk-TOMHUGQA.cjs.map +0 -1
|
@@ -135,7 +135,159 @@ import stream from "stream";
|
|
|
135
135
|
import caseless from "caseless";
|
|
136
136
|
import DatauriParser from "datauri/parser.js";
|
|
137
137
|
import datauri from "datauri/sync.js";
|
|
138
|
-
|
|
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 (globalThis.Buffer?.isBuffer(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 extends Error {
|
|
208
|
+
name = "MaxBufferError";
|
|
209
|
+
constructor() {
|
|
210
|
+
super("maxBuffer exceeded");
|
|
211
|
+
}
|
|
212
|
+
};
|
|
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
|
|
139
291
|
import lodashMerge from "lodash.merge";
|
|
140
292
|
import removeUndefinedObjects from "remove-undefined-objects";
|
|
141
293
|
var specialHeaders = ["accept", "authorization"];
|
|
@@ -432,4 +584,4 @@ export {
|
|
|
432
584
|
prepareParams,
|
|
433
585
|
prepareServer
|
|
434
586
|
};
|
|
435
|
-
//# sourceMappingURL=chunk-
|
|
587
|
+
//# sourceMappingURL=chunk-ASE5F2OQ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/getJSONSchemaDefaults.ts","../src/lib/parseResponse.ts","../src/lib/prepareAuth.ts","../src/lib/prepareParams.ts","../node_modules/get-stream/source/contents.js","../node_modules/get-stream/source/utils.js","../node_modules/get-stream/source/array-buffer.js","../node_modules/get-stream/source/buffer.js","../src/lib/prepareServer.ts"],"sourcesContent":["import type { SchemaWrapper } from 'oas/operation/get-parameters-as-json-schema';\nimport type { SchemaObject } from 'oas/rmoas.types';\n\nimport traverse from 'json-schema-traverse';\n\n/**\n * Run through a JSON Schema object and compose up an object containing default data for any schema\n * property that is required and also has a defined default.\n *\n * Code partially adapted from the `json-schema-default` package but modified to only return\n * defaults of required properties.\n *\n * @todo This is a good candidate to be moved into a core `oas` library method.\n * @see {@link https://github.com/mdornseif/json-schema-default}\n */\nexport default function getJSONSchemaDefaults(jsonSchemas: SchemaWrapper[]) {\n return jsonSchemas\n .map(({ type: payloadType, schema: jsonSchema }) => {\n const defaults: Record<string, unknown> = {};\n traverse(\n jsonSchema,\n (\n schema: SchemaObject,\n pointer: string,\n rootSchema: SchemaObject,\n parentPointer?: string,\n parentKeyword?: string,\n parentSchema?: SchemaObject,\n indexProperty?: string | number,\n ) => {\n if (!pointer.startsWith('/properties/')) {\n return;\n }\n\n if (Array.isArray(parentSchema?.required) && parentSchema?.required.includes(String(indexProperty))) {\n if (schema.type === 'object' && indexProperty) {\n defaults[indexProperty] = {};\n }\n\n let destination = defaults;\n if (parentPointer) {\n // To map nested objects correct we need to pick apart the parent pointer.\n parentPointer\n .replace(/\\/properties/g, '')\n .split('/')\n .forEach((subSchema: string) => {\n if (subSchema === '') {\n return;\n }\n\n destination = (destination?.[subSchema] as Record<string, unknown>) || {};\n });\n }\n\n if (schema.default !== undefined) {\n if (indexProperty !== undefined) {\n destination[indexProperty] = schema.default;\n }\n }\n }\n },\n );\n\n if (!Object.keys(defaults).length) {\n return {};\n }\n\n return {\n // @todo should we filter out empty and undefined objects from here with `remove-undefined-objects`?\n [payloadType]: defaults,\n };\n })\n .reduce((prev, next) => Object.assign(prev, next));\n}\n","import { matchesMimeType } from 'oas/utils';\n\nexport default async function parseResponse<HTTPStatus extends number = number>(response: Response) {\n const contentType = response.headers.get('Content-Type');\n const isJSON = contentType && (matchesMimeType.json(contentType) || matchesMimeType.wildcard(contentType));\n\n const responseBody = await response.text();\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let data: any = responseBody;\n if (isJSON) {\n try {\n data = JSON.parse(responseBody);\n } catch (e) {\n // If our JSON parsing failed then we can just return plaintext instead.\n }\n }\n\n return {\n data,\n status: response.status as HTTPStatus,\n headers: response.headers,\n res: response,\n };\n}\n","/* eslint-disable no-underscore-dangle */\nimport type Operation from 'oas/operation';\nimport type { KeyedSecuritySchemeObject } from 'oas/rmoas.types';\n\nexport default function prepareAuth(authKey: (number | string)[], operation: Operation) {\n if (authKey.length === 0) {\n return {};\n }\n\n const preparedAuth: Record<\n string,\n | string\n | number\n | {\n pass: string | number;\n user: string | number;\n }\n > = {};\n\n const security = operation.getSecurity();\n if (security.length === 0) {\n // If there's no auth configured on this operation, don't prepare anything (even if it was\n // supplied by the user).\n return {};\n }\n\n // Does this operation require multiple forms of auth?\n if (security.every(s => Object.keys(s).length > 1)) {\n throw new Error(\n \"Sorry, this operation currently requires multiple forms of authentication which this library doesn't yet support.\",\n );\n }\n\n // Since we can only handle single auth security configurations, let's pull those out. This code\n // is a bit opaque but `security` here may look like `[{ basic: [] }, { oauth2: [], basic: []}]`\n // and are filtering it down to only single-auth requirements of `[{ basic: [] }]`.\n const usableSecurity = security\n .map(s => {\n return Object.keys(s).length === 1 ? s : false;\n })\n .filter(Boolean);\n\n const usableSecuritySchemes = usableSecurity.map(s => Object.keys(s)).reduce((prev, next) => prev.concat(next), []);\n const preparedSecurity = operation.prepareSecurity();\n\n // If we have two auth tokens present let's look for Basic Auth in their configuration.\n if (authKey.length >= 2) {\n // If this operation doesn't support HTTP Basic auth but we have two tokens, that's a paddlin.\n if (!('Basic' in preparedSecurity)) {\n throw new Error('Multiple auth tokens were supplied for this endpoint but only a single token is needed.');\n }\n\n // If we have two auth keys for Basic Auth but Basic isn't a usable security scheme (maybe it's\n // part of an AND or auth configuration -- which we don't support) then we need to error out.\n const schemes = preparedSecurity.Basic.filter(s => usableSecuritySchemes.includes(s._key));\n if (!schemes.length) {\n throw new Error(\n '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.',\n );\n }\n\n const scheme = schemes.shift() as KeyedSecuritySchemeObject;\n preparedAuth[scheme._key] = {\n user: authKey[0],\n pass: authKey.length === 2 ? authKey[1] : '',\n };\n\n return preparedAuth;\n }\n\n // If we know we don't need to use HTTP Basic auth because we have a username+password then we\n // can pick the first usable security scheme available and try to use that. This might not always\n // be the auth scheme that the user wants, but we don't have any other way for the user to tell\n // us what they want with the current `sdk.auth()` API.\n const usableScheme = usableSecuritySchemes[0];\n const schemes = Object.entries(preparedSecurity)\n .map(([, ps]) => ps.filter(s => usableScheme === s._key))\n .reduce((prev, next) => prev.concat(next), []);\n\n const scheme = schemes.shift() as KeyedSecuritySchemeObject;\n switch (scheme.type) {\n case 'http':\n if (scheme.scheme === 'basic') {\n preparedAuth[scheme._key] = {\n user: authKey[0],\n pass: authKey.length === 2 ? authKey[1] : '',\n };\n } else if (scheme.scheme === 'bearer') {\n preparedAuth[scheme._key] = authKey[0];\n }\n break;\n\n case 'oauth2':\n preparedAuth[scheme._key] = authKey[0];\n break;\n\n case 'apiKey':\n if (scheme.in === 'query' || scheme.in === 'header' || scheme.in === 'cookie') {\n preparedAuth[scheme._key] = authKey[0];\n }\n break;\n\n default:\n throw new Error(\n `Sorry, this API currently uses a security scheme, ${scheme.type}, which this library doesn't yet support.`,\n );\n }\n\n return preparedAuth;\n}\n","import type { ReadStream } from 'node:fs';\nimport type Operation from 'oas/operation';\nimport type { ParameterObject, SchemaObject } from 'oas/rmoas.types';\n\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport stream from 'node:stream';\n\nimport caseless from 'caseless';\nimport DatauriParser from 'datauri/parser.js';\nimport datauri from 'datauri/sync.js';\n// `get-stream` is included in our bundle, see `tsup.config.ts`\n// eslint-disable-next-line import/no-extraneous-dependencies\nimport { getStreamAsBuffer } from 'get-stream';\nimport lodashMerge from 'lodash.merge';\nimport removeUndefinedObjects from 'remove-undefined-objects';\n\nimport getJSONSchemaDefaults from './getJSONSchemaDefaults.js';\n\n// These headers are normally only defined by the OpenAPI definition but we allow the user to\n// manually supply them in their `metadata` parameter if they wish.\nconst specialHeaders = ['accept', 'authorization'];\n\n/**\n * Extract all available parameters from an operations Parameter Object into a digestable array\n * that we can use to apply to the request.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameterObject}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#parameterObject}\n */\nfunction digestParameters(parameters: ParameterObject[]): Record<string, ParameterObject> {\n return parameters.reduce((prev, param) => {\n if ('$ref' in param || 'allOf' in param || 'anyOf' in param || 'oneOf' in param) {\n throw new Error(\"The OpenAPI document for this operation wasn't dereferenced before processing.\");\n } else if (param.name in prev) {\n throw new Error(\n `The operation you are using has the same parameter, ${param.name}, spread across multiple entry points. We unfortunately can't handle this right now.`,\n );\n }\n\n return Object.assign(prev, { [param.name]: param });\n }, {});\n}\n\n// https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore#_isempty\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction isEmpty(obj: any) {\n return [Object, Array].includes((obj || {}).constructor) && !Object.entries(obj || {}).length;\n}\n\nfunction isObject(thing: unknown) {\n if (thing instanceof stream.Readable) {\n return false;\n }\n\n return typeof thing === 'object' && thing !== null && !Array.isArray(thing);\n}\n\nfunction isPrimitive(obj: unknown) {\n return obj === null || typeof obj === 'number' || typeof obj === 'string';\n}\n\nfunction merge(src: unknown, target: unknown) {\n if (Array.isArray(target)) {\n // @todo we need to add support for merging array defaults with array body/metadata arguments\n return target;\n } else if (!isObject(target)) {\n return target;\n }\n\n return lodashMerge(src, target);\n}\n\n/**\n * Ingest a file path or readable stream into a common object that we can later use to process it\n * into a parameters object for making an API request.\n *\n */\nfunction processFile(\n paramName: string | undefined,\n file: string | ReadStream,\n): Promise<{ base64?: string; buffer?: Buffer; filename: string; paramName?: string } | undefined> {\n if (typeof file === 'string') {\n // In order to support relative pathed files, we need to attempt to resolve them.\n const resolvedFile = path.resolve(file);\n\n return new Promise((resolve, reject) => {\n fs.stat(resolvedFile, async err => {\n if (err) {\n if (err.code === 'ENOENT') {\n // It's less than ideal for us to handle files that don't exist like this but because\n // `file` is a string it might actually be the full text contents of the file and not\n // actually a path.\n //\n // We also can't really regex to see if `file` *looks*` like a path because one should be\n // able to pass in a relative `owlbert.png` (instead of `./owlbert.png`) and though that\n // doesn't *look* like a path, it is one that should still work.\n return resolve(undefined);\n }\n\n return reject(err);\n }\n\n const fileMetadata = await datauri(resolvedFile);\n const payloadFilename = encodeURIComponent(path.basename(resolvedFile));\n\n return resolve({\n paramName,\n base64: fileMetadata?.content?.replace(';base64', `;name=${payloadFilename};base64`),\n filename: payloadFilename,\n buffer: fileMetadata.buffer,\n });\n });\n });\n } else if (file instanceof stream.Readable) {\n return getStreamAsBuffer(file).then(buffer => {\n const filePath = file.path as string;\n const parser = new DatauriParser();\n const base64 = parser.format(filePath, buffer).content;\n const payloadFilename = encodeURIComponent(path.basename(filePath));\n\n return {\n paramName,\n base64: base64?.replace(';base64', `;name=${payloadFilename};base64`),\n filename: payloadFilename,\n buffer,\n };\n });\n }\n\n return Promise.reject(\n new TypeError(\n paramName\n ? `The data supplied for the \\`${paramName}\\` request body parameter is not a file handler that we support.`\n : 'The data supplied for the request body payload is not a file handler that we support.',\n ),\n );\n}\n\n/**\n * With potentially supplied body and/or metadata we need to run through them against a given API\n * operation to see what's what and prepare any available parameters to be used in an API request\n * with `@readme/oas-to-har`.\n *\n */\nexport default async function prepareParams(operation: Operation, body?: unknown, metadata?: Record<string, unknown>) {\n let metadataIntersected = false;\n const digestedParameters = digestParameters(operation.getParameters());\n const jsonSchema = operation.getParametersAsJSONSchema();\n\n /**\n * It might be common for somebody to run `sdk.findPetsByStatus({ status: 'available' }, {})`, in\n * which case we want to filter out the second (metadata) parameter and treat the first parameter\n * as the metadata instead. If we don't do this, their supplied `status` metadata will be treated\n * as a body parameter, and because there's no `status` body parameter, and no supplied metadata\n * (because it's an empty object), the request won't send a payload.\n *\n * @see {@link https://github.com/readmeio/api/issues/449}\n */\n // eslint-disable-next-line no-param-reassign\n metadata = removeUndefinedObjects(metadata);\n\n if (!jsonSchema && (body !== undefined || metadata !== undefined)) {\n let throwNoParamsError = true;\n\n // If this operation doesn't have any parameters for us to transform to JSON Schema but they've\n // sent us either an `Accept` or `Authorization` header (or both) we should let them do that.\n // We should, however, only do this check for the `body` parameter as if they've sent this\n // request both `body` and `metadata` we can reject it outright as the operation won't have any\n // body data.\n if (body !== undefined) {\n if (typeof body === 'object' && body !== null && !Array.isArray(body)) {\n if (Object.keys(body).length <= 2) {\n const bodyParams = caseless(body);\n\n if (specialHeaders.some(header => bodyParams.has(header))) {\n throwNoParamsError = false;\n }\n }\n }\n }\n\n if (throwNoParamsError) {\n throw new Error(\n \"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.\",\n );\n }\n }\n\n const jsonSchemaDefaults = jsonSchema ? getJSONSchemaDefaults(jsonSchema) : {};\n\n const params: {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n body?: any;\n cookie?: Record<string, string | number | boolean>;\n files?: Record<string, Buffer>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n formData?: any;\n header?: Record<string, string | number | boolean>;\n path?: Record<string, string | number | boolean>;\n query?: Record<string, string | number | boolean>;\n server?: {\n selected: number;\n variables: Record<string, string | number>;\n };\n } = jsonSchemaDefaults;\n\n // If a body argument was supplied we need to do a bit of work to see if it's actually a body\n // argument or metadata because the library lets you supply either a body, metadata, or body with\n // metadata.\n if (typeof body !== 'undefined') {\n if (Array.isArray(body) || isPrimitive(body)) {\n // If the body param is an array or a primitive then we know it's absolutely a body because\n // metadata can only ever be undefined or an object.\n params.body = merge(params.body, body);\n } else if (typeof metadata === 'undefined') {\n // No metadata was explicitly provided so we need to analyze the body to determine if it's a\n // body or should be actually be treated as metadata.\n const headerParams = caseless({});\n Object.entries(digestedParameters).forEach(([paramName, param]) => {\n // Headers are sent case-insensitive so we need to make sure that we're properly\n // matching them when detecting what our incoming payload looks like.\n if (param.in === 'header') {\n headerParams.set(paramName, '');\n }\n });\n\n // `Accept` and `Authorization` headers can't be defined as normal parameters but we should\n // always allow the user to supply them if they wish.\n specialHeaders.forEach(header => {\n if (!headerParams.has(header)) {\n headerParams.set(header, '');\n }\n });\n\n const intersection = Object.keys(body as NonNullable<unknown>).filter(value => {\n if (Object.keys(digestedParameters).includes(value)) {\n return true;\n } else if (headerParams.has(value)) {\n return true;\n }\n\n return false;\n }).length;\n\n // If more than 25% of the body intersects with the parameters that we've got on hand, then\n // we should treat it as a metadata object and organize into parameters.\n if (intersection && intersection / Object.keys(body as NonNullable<unknown>).length > 0.25) {\n /* eslint-disable no-param-reassign */\n metadataIntersected = true;\n metadata = merge(params.body, body) as Record<string, unknown>;\n body = undefined;\n /* eslint-enable no-param-reassign */\n } else {\n // For all other cases, we should just treat the supplied body as a body.\n params.body = merge(params.body, body);\n }\n } else {\n // Body and metadata were both supplied.\n params.body = merge(params.body, body);\n }\n }\n\n if (!operation.hasRequestBody()) {\n // If this operation doesn't have any documented request body then we shouldn't be sending\n // anything.\n delete params.body;\n } else {\n if (!('body' in params)) params.body = {};\n\n // We need to retrieve the request body for this operation to search for any `binary` format\n // data that the user wants to send so we know what we need to prepare for the final API\n // request.\n const payloadJsonSchema = jsonSchema.find(js => js.type === 'body');\n if (payloadJsonSchema) {\n if (!params.files) params.files = {};\n\n const conversions = [];\n\n // @todo add support for `type: array`, `oneOf` and `anyOf`\n if (payloadJsonSchema.schema?.properties) {\n Object.entries(payloadJsonSchema.schema?.properties)\n .filter(([, schema]: [string, SchemaObject]) => schema?.format === 'binary')\n .filter(([prop]) => Object.keys(params.body).includes(prop))\n .forEach(([prop]) => {\n conversions.push(processFile(prop, params.body[prop]));\n });\n } else if (payloadJsonSchema.schema?.type === 'string') {\n if (payloadJsonSchema.schema?.format === 'binary') {\n conversions.push(processFile(undefined, params.body));\n }\n }\n\n await Promise.all(conversions)\n .then(fileMetadata => fileMetadata.filter(Boolean))\n .then(fm => {\n fm.forEach(fileMetadata => {\n if (!fileMetadata) {\n // If we don't have any metadata here it's because the file we have is likely\n // the full string content of the file so since we don't have any filenames to\n // work with we shouldn't do any additional handling to the `body` or `files`\n // parameters.\n return;\n }\n\n if (fileMetadata.paramName) {\n params.body[fileMetadata.paramName] = fileMetadata.base64;\n } else {\n params.body = fileMetadata.base64;\n }\n\n if (fileMetadata.buffer && params?.files) {\n params.files[fileMetadata.filename] = fileMetadata.buffer;\n }\n });\n });\n }\n }\n\n // Form data should be placed within `formData` instead of `body` for it to properly get picked\n // up by `fetch-har`.\n if (operation.isFormUrlEncoded()) {\n params.formData = merge(params.formData, params.body);\n delete params.body;\n }\n\n // Only spend time trying to organize metadata into parameters if we were able to digest\n // parameters out of the operation schema. If we couldn't digest anything, but metadata was\n // supplied then we wouldn't know how to send it in the request!\n if (typeof metadata !== 'undefined') {\n if (!('cookie' in params)) params.cookie = {};\n if (!('header' in params)) params.header = {};\n if (!('path' in params)) params.path = {};\n if (!('query' in params)) params.query = {};\n\n Object.entries(digestedParameters).forEach(([paramName, param]) => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let value: any;\n let metadataHeaderParam;\n if (typeof metadata === 'object' && !isEmpty(metadata)) {\n if (paramName in metadata) {\n value = metadata[paramName];\n metadataHeaderParam = paramName;\n } else if (param.in === 'header') {\n // Headers are sent case-insensitive so we need to make sure that we're properly\n // matching them when detecting what our incoming payload looks like.\n metadataHeaderParam = Object.keys(metadata).find(k => k.toLowerCase() === paramName.toLowerCase()) || '';\n value = metadata[metadataHeaderParam];\n }\n }\n\n if (value === undefined) {\n return;\n }\n\n /* eslint-disable no-param-reassign */\n switch (param.in) {\n case 'path':\n (params.path as NonNullable<typeof params.path>)[paramName] = value;\n if (metadata?.[paramName]) delete metadata[paramName];\n break;\n case 'query':\n (params.query as NonNullable<typeof params.query>)[paramName] = value;\n if (metadata?.[paramName]) delete metadata[paramName];\n break;\n case 'header':\n (params.header as NonNullable<typeof params.header>)[paramName.toLowerCase()] = value;\n if (metadataHeaderParam && metadata?.[metadataHeaderParam]) delete metadata[metadataHeaderParam];\n break;\n case 'cookie':\n (params.cookie as NonNullable<typeof params.cookie>)[paramName] = value;\n if (metadata?.[paramName]) delete metadata[paramName];\n break;\n default: // no-op\n }\n /* eslint-enable no-param-reassign */\n\n // Because a user might have sent just a metadata object, we want to make sure that we filter\n // out anything that they sent that is a parameter from also being sent as part of a form\n // data payload for `x-www-form-urlencoded` requests.\n if (metadataIntersected && operation.isFormUrlEncoded()) {\n if (paramName in params.formData) {\n delete params.formData[paramName];\n }\n }\n });\n\n // If there's any leftover metadata that hasn't been moved into form data for this request we\n // need to move it or else it'll get tossed.\n if (!isEmpty(metadata)) {\n if (typeof metadata === 'object') {\n // If the user supplied an `accept` or `authorization` header themselves we should allow it\n // through. Normally these headers are automatically handled by `@readme/oas-to-har` but in\n // the event that maybe the user wants to return XML for an API that normally returns JSON\n // or specify a custom auth header (maybe we can't handle their auth case right) this is the\n // only way with this library that they can do that.\n specialHeaders.forEach(headerName => {\n const headerParam = Object.keys(metadata || {}).find(m => m.toLowerCase() === headerName);\n if (headerParam) {\n // this if-statement below is a typeguard\n if (typeof metadata === 'object') {\n // this if-statement below is a typeguard\n if (typeof params.header === 'object') {\n params.header[headerName] = metadata[headerParam] as string;\n }\n // eslint-disable-next-line no-param-reassign\n delete metadata[headerParam];\n }\n }\n });\n }\n\n if (operation.isFormUrlEncoded()) {\n params.formData = merge(params.formData, metadata);\n } else {\n // Any other remaining unused metadata will be unused because we don't know where to place\n // it in the request.\n }\n }\n }\n\n (['body', 'cookie', 'files', 'formData', 'header', 'path', 'query'] as const).forEach((type: keyof typeof params) => {\n if (type in params && isEmpty(params[type])) {\n delete params[type];\n }\n });\n\n return params;\n}\n","export const getStreamContents = async (stream, {init, convertChunk, getSize, truncateChunk, addChunk, getFinalChunk, finalize}, {maxBuffer = Number.POSITIVE_INFINITY} = {}) => {\n\tif (!isAsyncIterable(stream)) {\n\t\tthrow new Error('The first argument must be a Readable, a ReadableStream, or an async iterable.');\n\t}\n\n\tconst state = init();\n\tstate.length = 0;\n\n\ttry {\n\t\tfor await (const chunk of stream) {\n\t\t\tconst chunkType = getChunkType(chunk);\n\t\t\tconst convertedChunk = convertChunk[chunkType](chunk, state);\n\t\t\tappendChunk({convertedChunk, state, getSize, truncateChunk, addChunk, maxBuffer});\n\t\t}\n\n\t\tappendFinalChunk({state, convertChunk, getSize, truncateChunk, addChunk, getFinalChunk, maxBuffer});\n\t\treturn finalize(state);\n\t} catch (error) {\n\t\terror.bufferedData = finalize(state);\n\t\tthrow error;\n\t}\n};\n\nconst appendFinalChunk = ({state, getSize, truncateChunk, addChunk, getFinalChunk, maxBuffer}) => {\n\tconst convertedChunk = getFinalChunk(state);\n\tif (convertedChunk !== undefined) {\n\t\tappendChunk({convertedChunk, state, getSize, truncateChunk, addChunk, maxBuffer});\n\t}\n};\n\nconst appendChunk = ({convertedChunk, state, getSize, truncateChunk, addChunk, maxBuffer}) => {\n\tconst chunkSize = getSize(convertedChunk);\n\tconst newLength = state.length + chunkSize;\n\n\tif (newLength <= maxBuffer) {\n\t\taddNewChunk(convertedChunk, state, addChunk, newLength);\n\t\treturn;\n\t}\n\n\tconst truncatedChunk = truncateChunk(convertedChunk, maxBuffer - state.length);\n\n\tif (truncatedChunk !== undefined) {\n\t\taddNewChunk(truncatedChunk, state, addChunk, maxBuffer);\n\t}\n\n\tthrow new MaxBufferError();\n};\n\nconst addNewChunk = (convertedChunk, state, addChunk, newLength) => {\n\tstate.contents = addChunk(convertedChunk, state, newLength);\n\tstate.length = newLength;\n};\n\nconst isAsyncIterable = stream => typeof stream === 'object' && stream !== null && typeof stream[Symbol.asyncIterator] === 'function';\n\nconst getChunkType = chunk => {\n\tconst typeOfChunk = typeof chunk;\n\n\tif (typeOfChunk === 'string') {\n\t\treturn 'string';\n\t}\n\n\tif (typeOfChunk !== 'object' || chunk === null) {\n\t\treturn 'others';\n\t}\n\n\t// eslint-disable-next-line n/prefer-global/buffer\n\tif (globalThis.Buffer?.isBuffer(chunk)) {\n\t\treturn 'buffer';\n\t}\n\n\tconst prototypeName = objectToString.call(chunk);\n\n\tif (prototypeName === '[object ArrayBuffer]') {\n\t\treturn 'arrayBuffer';\n\t}\n\n\tif (prototypeName === '[object DataView]') {\n\t\treturn 'dataView';\n\t}\n\n\tif (\n\t\tNumber.isInteger(chunk.byteLength)\n\t\t&& Number.isInteger(chunk.byteOffset)\n\t\t&& objectToString.call(chunk.buffer) === '[object ArrayBuffer]'\n\t) {\n\t\treturn 'typedArray';\n\t}\n\n\treturn 'others';\n};\n\nconst {toString: objectToString} = Object.prototype;\n\nexport class MaxBufferError extends Error {\n\tname = 'MaxBufferError';\n\n\tconstructor() {\n\t\tsuper('maxBuffer exceeded');\n\t}\n}\n","export const identity = value => value;\n\nexport const noop = () => undefined;\n\nexport const getContentsProp = ({contents}) => contents;\n\nexport const throwObjectStream = chunk => {\n\tthrow new Error(`Streams in object mode are not supported: ${String(chunk)}`);\n};\n\nexport const getLengthProp = convertedChunk => convertedChunk.length;\n","import {getStreamContents} from './contents.js';\nimport {noop, throwObjectStream, getLengthProp} from './utils.js';\n\nexport async function getStreamAsArrayBuffer(stream, options) {\n\treturn getStreamContents(stream, arrayBufferMethods, options);\n}\n\nconst initArrayBuffer = () => ({contents: new ArrayBuffer(0)});\n\nconst useTextEncoder = chunk => textEncoder.encode(chunk);\nconst textEncoder = new TextEncoder();\n\nconst useUint8Array = chunk => new Uint8Array(chunk);\n\nconst useUint8ArrayWithOffset = chunk => new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength);\n\nconst truncateArrayBufferChunk = (convertedChunk, chunkSize) => convertedChunk.slice(0, chunkSize);\n\n// `contents` is an increasingly growing `Uint8Array`.\nconst addArrayBufferChunk = (convertedChunk, {contents, length: previousLength}, length) => {\n\tconst newContents = hasArrayBufferResize() ? resizeArrayBuffer(contents, length) : resizeArrayBufferSlow(contents, length);\n\tnew Uint8Array(newContents).set(convertedChunk, previousLength);\n\treturn newContents;\n};\n\n// Without `ArrayBuffer.resize()`, `contents` size is always a power of 2.\n// This means its last bytes are zeroes (not stream data), which need to be\n// trimmed at the end with `ArrayBuffer.slice()`.\nconst resizeArrayBufferSlow = (contents, length) => {\n\tif (length <= contents.byteLength) {\n\t\treturn contents;\n\t}\n\n\tconst arrayBuffer = new ArrayBuffer(getNewContentsLength(length));\n\tnew Uint8Array(arrayBuffer).set(new Uint8Array(contents), 0);\n\treturn arrayBuffer;\n};\n\n// With `ArrayBuffer.resize()`, `contents` size matches exactly the size of\n// the stream data. It does not include extraneous zeroes to trim at the end.\n// The underlying `ArrayBuffer` does allocate a number of bytes that is a power\n// of 2, but those bytes are only visible after calling `ArrayBuffer.resize()`.\nconst resizeArrayBuffer = (contents, length) => {\n\tif (length <= contents.maxByteLength) {\n\t\tcontents.resize(length);\n\t\treturn contents;\n\t}\n\n\tconst arrayBuffer = new ArrayBuffer(length, {maxByteLength: getNewContentsLength(length)});\n\tnew Uint8Array(arrayBuffer).set(new Uint8Array(contents), 0);\n\treturn arrayBuffer;\n};\n\n// Retrieve the closest `length` that is both >= and a power of 2\nconst getNewContentsLength = length => SCALE_FACTOR ** Math.ceil(Math.log(length) / Math.log(SCALE_FACTOR));\n\nconst SCALE_FACTOR = 2;\n\nconst finalizeArrayBuffer = ({contents, length}) => hasArrayBufferResize() ? contents : contents.slice(0, length);\n\n// `ArrayBuffer.slice()` is slow. When `ArrayBuffer.resize()` is available\n// (Node >=20.0.0, Safari >=16.4 and Chrome), we can use it instead.\n// eslint-disable-next-line no-warning-comments\n// TODO: remove after dropping support for Node 20.\n// eslint-disable-next-line no-warning-comments\n// TODO: use `ArrayBuffer.transferToFixedLength()` instead once it is available\nconst hasArrayBufferResize = () => 'resize' in ArrayBuffer.prototype;\n\nconst arrayBufferMethods = {\n\tinit: initArrayBuffer,\n\tconvertChunk: {\n\t\tstring: useTextEncoder,\n\t\tbuffer: useUint8Array,\n\t\tarrayBuffer: useUint8Array,\n\t\tdataView: useUint8ArrayWithOffset,\n\t\ttypedArray: useUint8ArrayWithOffset,\n\t\tothers: throwObjectStream,\n\t},\n\tgetSize: getLengthProp,\n\ttruncateChunk: truncateArrayBufferChunk,\n\taddChunk: addArrayBufferChunk,\n\tgetFinalChunk: noop,\n\tfinalize: finalizeArrayBuffer,\n};\n","import {getStreamAsArrayBuffer} from './array-buffer.js';\n\nexport async function getStreamAsBuffer(stream, options) {\n\tif (!('Buffer' in globalThis)) {\n\t\tthrow new Error('getStreamAsBuffer() is only supported in Node.js');\n\t}\n\n\ttry {\n\t\treturn arrayBufferToNodeBuffer(await getStreamAsArrayBuffer(stream, options));\n\t} catch (error) {\n\t\tif (error.bufferedData !== undefined) {\n\t\t\terror.bufferedData = arrayBufferToNodeBuffer(error.bufferedData);\n\t\t}\n\n\t\tthrow error;\n\t}\n}\n\n// eslint-disable-next-line n/prefer-global/buffer\nconst arrayBufferToNodeBuffer = arrayBuffer => globalThis.Buffer.from(arrayBuffer);\n","import type Oas from 'oas';\n\nfunction stripTrailingSlash(url: string) {\n if (url[url.length - 1] === '/') {\n return url.slice(0, -1);\n }\n\n return url;\n}\n\n/**\n * With an SDK server config and an instance of OAS we should extract and prepare the server and\n * any server variables to be supplied to `@readme/oas-to-har`.\n *\n */\nexport default function prepareServer(spec: Oas, url: string, variables: Record<string, string | number> = {}) {\n let serverIdx;\n const sanitizedUrl = stripTrailingSlash(url);\n (spec.api.servers || []).forEach((server, i) => {\n if (server.url === sanitizedUrl) {\n serverIdx = i;\n }\n });\n\n // If we were able to find the passed in server in the OAS servers, we should use that! If we\n // couldn't and server variables were passed in we should try our best to handle that, otherwise\n // we should ignore the passed in server and use whever the default from the OAS is.\n if (serverIdx) {\n return {\n selected: serverIdx,\n variables,\n };\n } else if (Object.keys(variables).length) {\n // @todo we should run `oas.replaceUrl(url)` and pass that unto `@readme/oas-to-har`\n } else {\n const server = spec.splitVariables(url);\n if (server) {\n return {\n selected: server.selected,\n variables: server.variables,\n };\n }\n\n // @todo we should pass `url` directly into `@readme/oas-to-har` as the base URL\n }\n\n return false;\n}\n"],"mappings":";AAGA,OAAO,cAAc;AAYN,SAAR,sBAAuC,aAA8B;AAC1E,SAAO,YACJ,IAAI,CAAC,EAAE,MAAM,aAAa,QAAQ,WAAW,MAAM;AAClD,UAAM,WAAoC,CAAC;AAC3C;AAAA,MACE;AAAA,MACA,CACE,QACA,SACA,YACA,eACA,eACA,cACA,kBACG;AACH,YAAI,CAAC,QAAQ,WAAW,cAAc,GAAG;AACvC;AAAA,QACF;AAEA,YAAI,MAAM,QAAQ,cAAc,QAAQ,KAAK,cAAc,SAAS,SAAS,OAAO,aAAa,CAAC,GAAG;AACnG,cAAI,OAAO,SAAS,YAAY,eAAe;AAC7C,qBAAS,aAAa,IAAI,CAAC;AAAA,UAC7B;AAEA,cAAI,cAAc;AAClB,cAAI,eAAe;AAEjB,0BACG,QAAQ,iBAAiB,EAAE,EAC3B,MAAM,GAAG,EACT,QAAQ,CAAC,cAAsB;AAC9B,kBAAI,cAAc,IAAI;AACpB;AAAA,cACF;AAEA,4BAAe,cAAc,SAAS,KAAiC,CAAC;AAAA,YAC1E,CAAC;AAAA,UACL;AAEA,cAAI,OAAO,YAAY,QAAW;AAChC,gBAAI,kBAAkB,QAAW;AAC/B,0BAAY,aAAa,IAAI,OAAO;AAAA,YACtC;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,QAAI,CAAC,OAAO,KAAK,QAAQ,EAAE,QAAQ;AACjC,aAAO,CAAC;AAAA,IACV;AAEA,WAAO;AAAA;AAAA,MAEL,CAAC,WAAW,GAAG;AAAA,IACjB;AAAA,EACF,CAAC,EACA,OAAO,CAAC,MAAM,SAAS,OAAO,OAAO,MAAM,IAAI,CAAC;AACrD;;;ACzEA,SAAS,uBAAuB;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: 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; }
|
|
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
2
|
var _jsonschematraverse = require('json-schema-traverse'); var _jsonschematraverse2 = _interopRequireDefault(_jsonschematraverse);
|
|
3
3
|
function getJSONSchemaDefaults(jsonSchemas) {
|
|
4
4
|
return jsonSchemas.map(({ type: payloadType, schema: jsonSchema }) => {
|
|
@@ -135,7 +135,159 @@ var _stream = require('stream'); var _stream2 = _interopRequireDefault(_stream);
|
|
|
135
135
|
var _caseless = require('caseless'); var _caseless2 = _interopRequireDefault(_caseless);
|
|
136
136
|
var _parserjs = require('datauri/parser.js'); var _parserjs2 = _interopRequireDefault(_parserjs);
|
|
137
137
|
var _syncjs = require('datauri/sync.js'); var _syncjs2 = _interopRequireDefault(_syncjs);
|
|
138
|
-
|
|
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
|
|
139
291
|
var _lodashmerge = require('lodash.merge'); var _lodashmerge2 = _interopRequireDefault(_lodashmerge);
|
|
140
292
|
var _removeundefinedobjects = require('remove-undefined-objects'); var _removeundefinedobjects2 = _interopRequireDefault(_removeundefinedobjects);
|
|
141
293
|
var specialHeaders = ["accept", "authorization"];
|
|
@@ -186,21 +338,21 @@ function processFile(paramName, file) {
|
|
|
186
338
|
const payloadFilename = encodeURIComponent(_path2.default.basename(resolvedFile));
|
|
187
339
|
return resolve({
|
|
188
340
|
paramName,
|
|
189
|
-
base64: _optionalChain([fileMetadata, 'optionalAccess',
|
|
341
|
+
base64: _optionalChain([fileMetadata, 'optionalAccess', _9 => _9.content, 'optionalAccess', _10 => _10.replace, 'call', _11 => _11(";base64", `;name=${payloadFilename};base64`)]),
|
|
190
342
|
filename: payloadFilename,
|
|
191
343
|
buffer: fileMetadata.buffer
|
|
192
344
|
});
|
|
193
345
|
});
|
|
194
346
|
});
|
|
195
347
|
} else if (file instanceof _stream2.default.Readable) {
|
|
196
|
-
return
|
|
348
|
+
return getStreamAsBuffer(file).then((buffer) => {
|
|
197
349
|
const filePath = file.path;
|
|
198
350
|
const parser = new (0, _parserjs2.default)();
|
|
199
351
|
const base64 = parser.format(filePath, buffer).content;
|
|
200
352
|
const payloadFilename = encodeURIComponent(_path2.default.basename(filePath));
|
|
201
353
|
return {
|
|
202
354
|
paramName,
|
|
203
|
-
base64: _optionalChain([base64, 'optionalAccess',
|
|
355
|
+
base64: _optionalChain([base64, 'optionalAccess', _12 => _12.replace, 'call', _13 => _13(";base64", `;name=${payloadFilename};base64`)]),
|
|
204
356
|
filename: payloadFilename,
|
|
205
357
|
buffer
|
|
206
358
|
};
|
|
@@ -281,12 +433,12 @@ async function prepareParams(operation, body, metadata) {
|
|
|
281
433
|
if (!params.files)
|
|
282
434
|
params.files = {};
|
|
283
435
|
const conversions = [];
|
|
284
|
-
if (_optionalChain([payloadJsonSchema, 'access',
|
|
285
|
-
Object.entries(_optionalChain([payloadJsonSchema, 'access',
|
|
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]) => {
|
|
286
438
|
conversions.push(processFile(prop, params.body[prop]));
|
|
287
439
|
});
|
|
288
|
-
} else if (_optionalChain([payloadJsonSchema, 'access',
|
|
289
|
-
if (_optionalChain([payloadJsonSchema, 'access',
|
|
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") {
|
|
290
442
|
conversions.push(processFile(void 0, params.body));
|
|
291
443
|
}
|
|
292
444
|
}
|
|
@@ -300,7 +452,7 @@ async function prepareParams(operation, body, metadata) {
|
|
|
300
452
|
} else {
|
|
301
453
|
params.body = fileMetadata.base64;
|
|
302
454
|
}
|
|
303
|
-
if (fileMetadata.buffer && _optionalChain([params, 'optionalAccess',
|
|
455
|
+
if (fileMetadata.buffer && _optionalChain([params, 'optionalAccess', _23 => _23.files])) {
|
|
304
456
|
params.files[fileMetadata.filename] = fileMetadata.buffer;
|
|
305
457
|
}
|
|
306
458
|
});
|
|
@@ -338,22 +490,22 @@ async function prepareParams(operation, body, metadata) {
|
|
|
338
490
|
switch (param.in) {
|
|
339
491
|
case "path":
|
|
340
492
|
params.path[paramName] = value;
|
|
341
|
-
if (_optionalChain([metadata, 'optionalAccess',
|
|
493
|
+
if (_optionalChain([metadata, 'optionalAccess', _24 => _24[paramName]]))
|
|
342
494
|
delete metadata[paramName];
|
|
343
495
|
break;
|
|
344
496
|
case "query":
|
|
345
497
|
params.query[paramName] = value;
|
|
346
|
-
if (_optionalChain([metadata, 'optionalAccess',
|
|
498
|
+
if (_optionalChain([metadata, 'optionalAccess', _25 => _25[paramName]]))
|
|
347
499
|
delete metadata[paramName];
|
|
348
500
|
break;
|
|
349
501
|
case "header":
|
|
350
502
|
params.header[paramName.toLowerCase()] = value;
|
|
351
|
-
if (metadataHeaderParam && _optionalChain([metadata, 'optionalAccess',
|
|
503
|
+
if (metadataHeaderParam && _optionalChain([metadata, 'optionalAccess', _26 => _26[metadataHeaderParam]]))
|
|
352
504
|
delete metadata[metadataHeaderParam];
|
|
353
505
|
break;
|
|
354
506
|
case "cookie":
|
|
355
507
|
params.cookie[paramName] = value;
|
|
356
|
-
if (_optionalChain([metadata, 'optionalAccess',
|
|
508
|
+
if (_optionalChain([metadata, 'optionalAccess', _27 => _27[paramName]]))
|
|
357
509
|
delete metadata[paramName];
|
|
358
510
|
break;
|
|
359
511
|
default:
|
|
@@ -432,4 +584,4 @@ function prepareServer(spec, url, variables = {}) {
|
|
|
432
584
|
|
|
433
585
|
|
|
434
586
|
exports.getJSONSchemaDefaults = getJSONSchemaDefaults; exports.parseResponse = parseResponse; exports.prepareAuth = prepareAuth; exports.prepareParams = prepareParams; exports.prepareServer = prepareServer;
|
|
435
|
-
//# sourceMappingURL=chunk-
|
|
587
|
+
//# sourceMappingURL=chunk-HGLVXDVZ.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/getJSONSchemaDefaults.ts","../src/lib/parseResponse.ts","../src/lib/prepareAuth.ts","../src/lib/prepareParams.ts","../node_modules/get-stream/source/contents.js","../node_modules/get-stream/source/utils.js","../node_modules/get-stream/source/array-buffer.js","../node_modules/get-stream/source/buffer.js","../src/lib/prepareServer.ts"],"names":["schemes","scheme","stream"],"mappings":";AAGA,OAAO,cAAc;AAYN,SAAR,sBAAuC,aAA8B;AAC1E,SAAO,YACJ,IAAI,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AAC,QAAQ,UAAU,SAAS,YAAY,UAAU,QAAQ,OAAO,EAAY,QAAQ,CAAC,SAA8B;AACnH,QAAI,QAAQ,UAAU,QAAQ,OAAO,IAAI,CAAC,GAAG;AAC3C,aAAO,OAAO,IAAI;AAAA,IACpB;AAAA,EACF,CAAC;AAED,SAAO;AACT;;;AK1aA,SAAS,mBAAmB,KAAa;AACvC,MAAI,IAAI,IAAI,SAAS,CAAC,MAAM,KAAK;AAC/B,WAAO,IAAI,MAAM,GAAG,EAAE;AAAA,EACxB;AAEA,SAAO;AACT;AAOe,SAAR,cAA+B,MAAW,KAAa,YAA6C,CAAC,GAAG;AAC7G,MAAI;AACJ,QAAM,eAAe,mBAAmB,GAAG;AAC3C,GAAC,KAAK,IAAI,WAAW,CAAC,GAAG,QAAQ,CAAC,QAAQ,MAAM;AAC9C,QAAI,OAAO,QAAQ,cAAc;AAC/B,kBAAY;AAAA,IACd;AAAA,EACF,CAAC;AAKD,MAAI,WAAW;AACb,WAAO;AAAA,MACL,UAAU;AAAA,MACV;AAAA,IACF;AAAA,EACF,WAAW,OAAO,KAAK,SAAS,EAAE,QAAQ;AAAA,EAE1C,OAAO;AACL,UAAM,SAAS,KAAK,eAAe,GAAG;AACtC,QAAI,QAAQ;AACV,aAAO;AAAA,QACL,UAAU,OAAO;AAAA,QACjB,WAAW,OAAO;AAAA,MACpB;AAAA,IACF;AAAA,EAGF;AAEA,SAAO;AACT","sourcesContent":["import type { SchemaWrapper } from 'oas/operation/get-parameters-as-json-schema';\nimport type { SchemaObject } from 'oas/rmoas.types';\n\nimport traverse from 'json-schema-traverse';\n\n/**\n * Run through a JSON Schema object and compose up an object containing default data for any schema\n * property that is required and also has a defined default.\n *\n * Code partially adapted from the `json-schema-default` package but modified to only return\n * defaults of required properties.\n *\n * @todo This is a good candidate to be moved into a core `oas` library method.\n * @see {@link https://github.com/mdornseif/json-schema-default}\n */\nexport default function getJSONSchemaDefaults(jsonSchemas: SchemaWrapper[]) {\n return jsonSchemas\n .map(({ type: payloadType, schema: jsonSchema }) => {\n const defaults: Record<string, unknown> = {};\n traverse(\n jsonSchema,\n (\n schema: SchemaObject,\n pointer: string,\n rootSchema: SchemaObject,\n parentPointer?: string,\n parentKeyword?: string,\n parentSchema?: SchemaObject,\n indexProperty?: string | number,\n ) => {\n if (!pointer.startsWith('/properties/')) {\n return;\n }\n\n if (Array.isArray(parentSchema?.required) && parentSchema?.required.includes(String(indexProperty))) {\n if (schema.type === 'object' && indexProperty) {\n defaults[indexProperty] = {};\n }\n\n let destination = defaults;\n if (parentPointer) {\n // To map nested objects correct we need to pick apart the parent pointer.\n parentPointer\n .replace(/\\/properties/g, '')\n .split('/')\n .forEach((subSchema: string) => {\n if (subSchema === '') {\n return;\n }\n\n destination = (destination?.[subSchema] as Record<string, unknown>) || {};\n });\n }\n\n if (schema.default !== undefined) {\n if (indexProperty !== undefined) {\n destination[indexProperty] = schema.default;\n }\n }\n }\n },\n );\n\n if (!Object.keys(defaults).length) {\n return {};\n }\n\n return {\n // @todo should we filter out empty and undefined objects from here with `remove-undefined-objects`?\n [payloadType]: defaults,\n };\n })\n .reduce((prev, next) => Object.assign(prev, next));\n}\n","import { matchesMimeType } from 'oas/utils';\n\nexport default async function parseResponse<HTTPStatus extends number = number>(response: Response) {\n const contentType = response.headers.get('Content-Type');\n const isJSON = contentType && (matchesMimeType.json(contentType) || matchesMimeType.wildcard(contentType));\n\n const responseBody = await response.text();\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let data: any = responseBody;\n if (isJSON) {\n try {\n data = JSON.parse(responseBody);\n } catch (e) {\n // If our JSON parsing failed then we can just return plaintext instead.\n }\n }\n\n return {\n data,\n status: response.status as HTTPStatus,\n headers: response.headers,\n res: response,\n };\n}\n","/* eslint-disable no-underscore-dangle */\nimport type Operation from 'oas/operation';\nimport type { KeyedSecuritySchemeObject } from 'oas/rmoas.types';\n\nexport default function prepareAuth(authKey: (number | string)[], operation: Operation) {\n if (authKey.length === 0) {\n return {};\n }\n\n const preparedAuth: Record<\n string,\n | string\n | number\n | {\n pass: string | number;\n user: string | number;\n }\n > = {};\n\n const security = operation.getSecurity();\n if (security.length === 0) {\n // If there's no auth configured on this operation, don't prepare anything (even if it was\n // supplied by the user).\n return {};\n }\n\n // Does this operation require multiple forms of auth?\n if (security.every(s => Object.keys(s).length > 1)) {\n throw new Error(\n \"Sorry, this operation currently requires multiple forms of authentication which this library doesn't yet support.\",\n );\n }\n\n // Since we can only handle single auth security configurations, let's pull those out. This code\n // is a bit opaque but `security` here may look like `[{ basic: [] }, { oauth2: [], basic: []}]`\n // and are filtering it down to only single-auth requirements of `[{ basic: [] }]`.\n const usableSecurity = security\n .map(s => {\n return Object.keys(s).length === 1 ? s : false;\n })\n .filter(Boolean);\n\n const usableSecuritySchemes = usableSecurity.map(s => Object.keys(s)).reduce((prev, next) => prev.concat(next), []);\n const preparedSecurity = operation.prepareSecurity();\n\n // If we have two auth tokens present let's look for Basic Auth in their configuration.\n if (authKey.length >= 2) {\n // If this operation doesn't support HTTP Basic auth but we have two tokens, that's a paddlin.\n if (!('Basic' in preparedSecurity)) {\n throw new Error('Multiple auth tokens were supplied for this endpoint but only a single token is needed.');\n }\n\n // If we have two auth keys for Basic Auth but Basic isn't a usable security scheme (maybe it's\n // part of an AND or auth configuration -- which we don't support) then we need to error out.\n const schemes = preparedSecurity.Basic.filter(s => usableSecuritySchemes.includes(s._key));\n if (!schemes.length) {\n throw new Error(\n '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.',\n );\n }\n\n const scheme = schemes.shift() as KeyedSecuritySchemeObject;\n preparedAuth[scheme._key] = {\n user: authKey[0],\n pass: authKey.length === 2 ? authKey[1] : '',\n };\n\n return preparedAuth;\n }\n\n // If we know we don't need to use HTTP Basic auth because we have a username+password then we\n // can pick the first usable security scheme available and try to use that. This might not always\n // be the auth scheme that the user wants, but we don't have any other way for the user to tell\n // us what they want with the current `sdk.auth()` API.\n const usableScheme = usableSecuritySchemes[0];\n const schemes = Object.entries(preparedSecurity)\n .map(([, ps]) => ps.filter(s => usableScheme === s._key))\n .reduce((prev, next) => prev.concat(next), []);\n\n const scheme = schemes.shift() as KeyedSecuritySchemeObject;\n switch (scheme.type) {\n case 'http':\n if (scheme.scheme === 'basic') {\n preparedAuth[scheme._key] = {\n user: authKey[0],\n pass: authKey.length === 2 ? authKey[1] : '',\n };\n } else if (scheme.scheme === 'bearer') {\n preparedAuth[scheme._key] = authKey[0];\n }\n break;\n\n case 'oauth2':\n preparedAuth[scheme._key] = authKey[0];\n break;\n\n case 'apiKey':\n if (scheme.in === 'query' || scheme.in === 'header' || scheme.in === 'cookie') {\n preparedAuth[scheme._key] = authKey[0];\n }\n break;\n\n default:\n throw new Error(\n `Sorry, this API currently uses a security scheme, ${scheme.type}, which this library doesn't yet support.`,\n );\n }\n\n return preparedAuth;\n}\n","import type { ReadStream } from 'node:fs';\nimport type Operation from 'oas/operation';\nimport type { ParameterObject, SchemaObject } from 'oas/rmoas.types';\n\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport stream from 'node:stream';\n\nimport caseless from 'caseless';\nimport DatauriParser from 'datauri/parser.js';\nimport datauri from 'datauri/sync.js';\n// `get-stream` is included in our bundle, see `tsup.config.ts`\n// eslint-disable-next-line import/no-extraneous-dependencies\nimport { getStreamAsBuffer } from 'get-stream';\nimport lodashMerge from 'lodash.merge';\nimport removeUndefinedObjects from 'remove-undefined-objects';\n\nimport getJSONSchemaDefaults from './getJSONSchemaDefaults.js';\n\n// These headers are normally only defined by the OpenAPI definition but we allow the user to\n// manually supply them in their `metadata` parameter if they wish.\nconst specialHeaders = ['accept', 'authorization'];\n\n/**\n * Extract all available parameters from an operations Parameter Object into a digestable array\n * that we can use to apply to the request.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameterObject}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#parameterObject}\n */\nfunction digestParameters(parameters: ParameterObject[]): Record<string, ParameterObject> {\n return parameters.reduce((prev, param) => {\n if ('$ref' in param || 'allOf' in param || 'anyOf' in param || 'oneOf' in param) {\n throw new Error(\"The OpenAPI document for this operation wasn't dereferenced before processing.\");\n } else if (param.name in prev) {\n throw new Error(\n `The operation you are using has the same parameter, ${param.name}, spread across multiple entry points. We unfortunately can't handle this right now.`,\n );\n }\n\n return Object.assign(prev, { [param.name]: param });\n }, {});\n}\n\n// https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore#_isempty\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction isEmpty(obj: any) {\n return [Object, Array].includes((obj || {}).constructor) && !Object.entries(obj || {}).length;\n}\n\nfunction isObject(thing: unknown) {\n if (thing instanceof stream.Readable) {\n return false;\n }\n\n return typeof thing === 'object' && thing !== null && !Array.isArray(thing);\n}\n\nfunction isPrimitive(obj: unknown) {\n return obj === null || typeof obj === 'number' || typeof obj === 'string';\n}\n\nfunction merge(src: unknown, target: unknown) {\n if (Array.isArray(target)) {\n // @todo we need to add support for merging array defaults with array body/metadata arguments\n return target;\n } else if (!isObject(target)) {\n return target;\n }\n\n return lodashMerge(src, target);\n}\n\n/**\n * Ingest a file path or readable stream into a common object that we can later use to process it\n * into a parameters object for making an API request.\n *\n */\nfunction processFile(\n paramName: string | undefined,\n file: string | ReadStream,\n): Promise<{ base64?: string; buffer?: Buffer; filename: string; paramName?: string } | undefined> {\n if (typeof file === 'string') {\n // In order to support relative pathed files, we need to attempt to resolve them.\n const resolvedFile = path.resolve(file);\n\n return new Promise((resolve, reject) => {\n fs.stat(resolvedFile, async err => {\n if (err) {\n if (err.code === 'ENOENT') {\n // It's less than ideal for us to handle files that don't exist like this but because\n // `file` is a string it might actually be the full text contents of the file and not\n // actually a path.\n //\n // We also can't really regex to see if `file` *looks*` like a path because one should be\n // able to pass in a relative `owlbert.png` (instead of `./owlbert.png`) and though that\n // doesn't *look* like a path, it is one that should still work.\n return resolve(undefined);\n }\n\n return reject(err);\n }\n\n const fileMetadata = await datauri(resolvedFile);\n const payloadFilename = encodeURIComponent(path.basename(resolvedFile));\n\n return resolve({\n paramName,\n base64: fileMetadata?.content?.replace(';base64', `;name=${payloadFilename};base64`),\n filename: payloadFilename,\n buffer: fileMetadata.buffer,\n });\n });\n });\n } else if (file instanceof stream.Readable) {\n return getStreamAsBuffer(file).then(buffer => {\n const filePath = file.path as string;\n const parser = new DatauriParser();\n const base64 = parser.format(filePath, buffer).content;\n const payloadFilename = encodeURIComponent(path.basename(filePath));\n\n return {\n paramName,\n base64: base64?.replace(';base64', `;name=${payloadFilename};base64`),\n filename: payloadFilename,\n buffer,\n };\n });\n }\n\n return Promise.reject(\n new TypeError(\n paramName\n ? `The data supplied for the \\`${paramName}\\` request body parameter is not a file handler that we support.`\n : 'The data supplied for the request body payload is not a file handler that we support.',\n ),\n );\n}\n\n/**\n * With potentially supplied body and/or metadata we need to run through them against a given API\n * operation to see what's what and prepare any available parameters to be used in an API request\n * with `@readme/oas-to-har`.\n *\n */\nexport default async function prepareParams(operation: Operation, body?: unknown, metadata?: Record<string, unknown>) {\n let metadataIntersected = false;\n const digestedParameters = digestParameters(operation.getParameters());\n const jsonSchema = operation.getParametersAsJSONSchema();\n\n /**\n * It might be common for somebody to run `sdk.findPetsByStatus({ status: 'available' }, {})`, in\n * which case we want to filter out the second (metadata) parameter and treat the first parameter\n * as the metadata instead. If we don't do this, their supplied `status` metadata will be treated\n * as a body parameter, and because there's no `status` body parameter, and no supplied metadata\n * (because it's an empty object), the request won't send a payload.\n *\n * @see {@link https://github.com/readmeio/api/issues/449}\n */\n // eslint-disable-next-line no-param-reassign\n metadata = removeUndefinedObjects(metadata);\n\n if (!jsonSchema && (body !== undefined || metadata !== undefined)) {\n let throwNoParamsError = true;\n\n // If this operation doesn't have any parameters for us to transform to JSON Schema but they've\n // sent us either an `Accept` or `Authorization` header (or both) we should let them do that.\n // We should, however, only do this check for the `body` parameter as if they've sent this\n // request both `body` and `metadata` we can reject it outright as the operation won't have any\n // body data.\n if (body !== undefined) {\n if (typeof body === 'object' && body !== null && !Array.isArray(body)) {\n if (Object.keys(body).length <= 2) {\n const bodyParams = caseless(body);\n\n if (specialHeaders.some(header => bodyParams.has(header))) {\n throwNoParamsError = false;\n }\n }\n }\n }\n\n if (throwNoParamsError) {\n throw new Error(\n \"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.\",\n );\n }\n }\n\n const jsonSchemaDefaults = jsonSchema ? getJSONSchemaDefaults(jsonSchema) : {};\n\n const params: {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n body?: any;\n cookie?: Record<string, string | number | boolean>;\n files?: Record<string, Buffer>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n formData?: any;\n header?: Record<string, string | number | boolean>;\n path?: Record<string, string | number | boolean>;\n query?: Record<string, string | number | boolean>;\n server?: {\n selected: number;\n variables: Record<string, string | number>;\n };\n } = jsonSchemaDefaults;\n\n // If a body argument was supplied we need to do a bit of work to see if it's actually a body\n // argument or metadata because the library lets you supply either a body, metadata, or body with\n // metadata.\n if (typeof body !== 'undefined') {\n if (Array.isArray(body) || isPrimitive(body)) {\n // If the body param is an array or a primitive then we know it's absolutely a body because\n // metadata can only ever be undefined or an object.\n params.body = merge(params.body, body);\n } else if (typeof metadata === 'undefined') {\n // No metadata was explicitly provided so we need to analyze the body to determine if it's a\n // body or should be actually be treated as metadata.\n const headerParams = caseless({});\n Object.entries(digestedParameters).forEach(([paramName, param]) => {\n // Headers are sent case-insensitive so we need to make sure that we're properly\n // matching them when detecting what our incoming payload looks like.\n if (param.in === 'header') {\n headerParams.set(paramName, '');\n }\n });\n\n // `Accept` and `Authorization` headers can't be defined as normal parameters but we should\n // always allow the user to supply them if they wish.\n specialHeaders.forEach(header => {\n if (!headerParams.has(header)) {\n headerParams.set(header, '');\n }\n });\n\n const intersection = Object.keys(body as NonNullable<unknown>).filter(value => {\n if (Object.keys(digestedParameters).includes(value)) {\n return true;\n } else if (headerParams.has(value)) {\n return true;\n }\n\n return false;\n }).length;\n\n // If more than 25% of the body intersects with the parameters that we've got on hand, then\n // we should treat it as a metadata object and organize into parameters.\n if (intersection && intersection / Object.keys(body as NonNullable<unknown>).length > 0.25) {\n /* eslint-disable no-param-reassign */\n metadataIntersected = true;\n metadata = merge(params.body, body) as Record<string, unknown>;\n body = undefined;\n /* eslint-enable no-param-reassign */\n } else {\n // For all other cases, we should just treat the supplied body as a body.\n params.body = merge(params.body, body);\n }\n } else {\n // Body and metadata were both supplied.\n params.body = merge(params.body, body);\n }\n }\n\n if (!operation.hasRequestBody()) {\n // If this operation doesn't have any documented request body then we shouldn't be sending\n // anything.\n delete params.body;\n } else {\n if (!('body' in params)) params.body = {};\n\n // We need to retrieve the request body for this operation to search for any `binary` format\n // data that the user wants to send so we know what we need to prepare for the final API\n // request.\n const payloadJsonSchema = jsonSchema.find(js => js.type === 'body');\n if (payloadJsonSchema) {\n if (!params.files) params.files = {};\n\n const conversions = [];\n\n // @todo add support for `type: array`, `oneOf` and `anyOf`\n if (payloadJsonSchema.schema?.properties) {\n Object.entries(payloadJsonSchema.schema?.properties)\n .filter(([, schema]: [string, SchemaObject]) => schema?.format === 'binary')\n .filter(([prop]) => Object.keys(params.body).includes(prop))\n .forEach(([prop]) => {\n conversions.push(processFile(prop, params.body[prop]));\n });\n } else if (payloadJsonSchema.schema?.type === 'string') {\n if (payloadJsonSchema.schema?.format === 'binary') {\n conversions.push(processFile(undefined, params.body));\n }\n }\n\n await Promise.all(conversions)\n .then(fileMetadata => fileMetadata.filter(Boolean))\n .then(fm => {\n fm.forEach(fileMetadata => {\n if (!fileMetadata) {\n // If we don't have any metadata here it's because the file we have is likely\n // the full string content of the file so since we don't have any filenames to\n // work with we shouldn't do any additional handling to the `body` or `files`\n // parameters.\n return;\n }\n\n if (fileMetadata.paramName) {\n params.body[fileMetadata.paramName] = fileMetadata.base64;\n } else {\n params.body = fileMetadata.base64;\n }\n\n if (fileMetadata.buffer && params?.files) {\n params.files[fileMetadata.filename] = fileMetadata.buffer;\n }\n });\n });\n }\n }\n\n // Form data should be placed within `formData` instead of `body` for it to properly get picked\n // up by `fetch-har`.\n if (operation.isFormUrlEncoded()) {\n params.formData = merge(params.formData, params.body);\n delete params.body;\n }\n\n // Only spend time trying to organize metadata into parameters if we were able to digest\n // parameters out of the operation schema. If we couldn't digest anything, but metadata was\n // supplied then we wouldn't know how to send it in the request!\n if (typeof metadata !== 'undefined') {\n if (!('cookie' in params)) params.cookie = {};\n if (!('header' in params)) params.header = {};\n if (!('path' in params)) params.path = {};\n if (!('query' in params)) params.query = {};\n\n Object.entries(digestedParameters).forEach(([paramName, param]) => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let value: any;\n let metadataHeaderParam;\n if (typeof metadata === 'object' && !isEmpty(metadata)) {\n if (paramName in metadata) {\n value = metadata[paramName];\n metadataHeaderParam = paramName;\n } else if (param.in === 'header') {\n // Headers are sent case-insensitive so we need to make sure that we're properly\n // matching them when detecting what our incoming payload looks like.\n metadataHeaderParam = Object.keys(metadata).find(k => k.toLowerCase() === paramName.toLowerCase()) || '';\n value = metadata[metadataHeaderParam];\n }\n }\n\n if (value === undefined) {\n return;\n }\n\n /* eslint-disable no-param-reassign */\n switch (param.in) {\n case 'path':\n (params.path as NonNullable<typeof params.path>)[paramName] = value;\n if (metadata?.[paramName]) delete metadata[paramName];\n break;\n case 'query':\n (params.query as NonNullable<typeof params.query>)[paramName] = value;\n if (metadata?.[paramName]) delete metadata[paramName];\n break;\n case 'header':\n (params.header as NonNullable<typeof params.header>)[paramName.toLowerCase()] = value;\n if (metadataHeaderParam && metadata?.[metadataHeaderParam]) delete metadata[metadataHeaderParam];\n break;\n case 'cookie':\n (params.cookie as NonNullable<typeof params.cookie>)[paramName] = value;\n if (metadata?.[paramName]) delete metadata[paramName];\n break;\n default: // no-op\n }\n /* eslint-enable no-param-reassign */\n\n // Because a user might have sent just a metadata object, we want to make sure that we filter\n // out anything that they sent that is a parameter from also being sent as part of a form\n // data payload for `x-www-form-urlencoded` requests.\n if (metadataIntersected && operation.isFormUrlEncoded()) {\n if (paramName in params.formData) {\n delete params.formData[paramName];\n }\n }\n });\n\n // If there's any leftover metadata that hasn't been moved into form data for this request we\n // need to move it or else it'll get tossed.\n if (!isEmpty(metadata)) {\n if (typeof metadata === 'object') {\n // If the user supplied an `accept` or `authorization` header themselves we should allow it\n // through. Normally these headers are automatically handled by `@readme/oas-to-har` but in\n // the event that maybe the user wants to return XML for an API that normally returns JSON\n // or specify a custom auth header (maybe we can't handle their auth case right) this is the\n // only way with this library that they can do that.\n specialHeaders.forEach(headerName => {\n const headerParam = Object.keys(metadata || {}).find(m => m.toLowerCase() === headerName);\n if (headerParam) {\n // this if-statement below is a typeguard\n if (typeof metadata === 'object') {\n // this if-statement below is a typeguard\n if (typeof params.header === 'object') {\n params.header[headerName] = metadata[headerParam] as string;\n }\n // eslint-disable-next-line no-param-reassign\n delete metadata[headerParam];\n }\n }\n });\n }\n\n if (operation.isFormUrlEncoded()) {\n params.formData = merge(params.formData, metadata);\n } else {\n // Any other remaining unused metadata will be unused because we don't know where to place\n // it in the request.\n }\n }\n }\n\n (['body', 'cookie', 'files', 'formData', 'header', 'path', 'query'] as const).forEach((type: keyof typeof params) => {\n if (type in params && isEmpty(params[type])) {\n delete params[type];\n }\n });\n\n return params;\n}\n","export const getStreamContents = async (stream, {init, convertChunk, getSize, truncateChunk, addChunk, getFinalChunk, finalize}, {maxBuffer = Number.POSITIVE_INFINITY} = {}) => {\n\tif (!isAsyncIterable(stream)) {\n\t\tthrow new Error('The first argument must be a Readable, a ReadableStream, or an async iterable.');\n\t}\n\n\tconst state = init();\n\tstate.length = 0;\n\n\ttry {\n\t\tfor await (const chunk of stream) {\n\t\t\tconst chunkType = getChunkType(chunk);\n\t\t\tconst convertedChunk = convertChunk[chunkType](chunk, state);\n\t\t\tappendChunk({convertedChunk, state, getSize, truncateChunk, addChunk, maxBuffer});\n\t\t}\n\n\t\tappendFinalChunk({state, convertChunk, getSize, truncateChunk, addChunk, getFinalChunk, maxBuffer});\n\t\treturn finalize(state);\n\t} catch (error) {\n\t\terror.bufferedData = finalize(state);\n\t\tthrow error;\n\t}\n};\n\nconst appendFinalChunk = ({state, getSize, truncateChunk, addChunk, getFinalChunk, maxBuffer}) => {\n\tconst convertedChunk = getFinalChunk(state);\n\tif (convertedChunk !== undefined) {\n\t\tappendChunk({convertedChunk, state, getSize, truncateChunk, addChunk, maxBuffer});\n\t}\n};\n\nconst appendChunk = ({convertedChunk, state, getSize, truncateChunk, addChunk, maxBuffer}) => {\n\tconst chunkSize = getSize(convertedChunk);\n\tconst newLength = state.length + chunkSize;\n\n\tif (newLength <= maxBuffer) {\n\t\taddNewChunk(convertedChunk, state, addChunk, newLength);\n\t\treturn;\n\t}\n\n\tconst truncatedChunk = truncateChunk(convertedChunk, maxBuffer - state.length);\n\n\tif (truncatedChunk !== undefined) {\n\t\taddNewChunk(truncatedChunk, state, addChunk, maxBuffer);\n\t}\n\n\tthrow new MaxBufferError();\n};\n\nconst addNewChunk = (convertedChunk, state, addChunk, newLength) => {\n\tstate.contents = addChunk(convertedChunk, state, newLength);\n\tstate.length = newLength;\n};\n\nconst isAsyncIterable = stream => typeof stream === 'object' && stream !== null && typeof stream[Symbol.asyncIterator] === 'function';\n\nconst getChunkType = chunk => {\n\tconst typeOfChunk = typeof chunk;\n\n\tif (typeOfChunk === 'string') {\n\t\treturn 'string';\n\t}\n\n\tif (typeOfChunk !== 'object' || chunk === null) {\n\t\treturn 'others';\n\t}\n\n\t// eslint-disable-next-line n/prefer-global/buffer\n\tif (globalThis.Buffer?.isBuffer(chunk)) {\n\t\treturn 'buffer';\n\t}\n\n\tconst prototypeName = objectToString.call(chunk);\n\n\tif (prototypeName === '[object ArrayBuffer]') {\n\t\treturn 'arrayBuffer';\n\t}\n\n\tif (prototypeName === '[object DataView]') {\n\t\treturn 'dataView';\n\t}\n\n\tif (\n\t\tNumber.isInteger(chunk.byteLength)\n\t\t&& Number.isInteger(chunk.byteOffset)\n\t\t&& objectToString.call(chunk.buffer) === '[object ArrayBuffer]'\n\t) {\n\t\treturn 'typedArray';\n\t}\n\n\treturn 'others';\n};\n\nconst {toString: objectToString} = Object.prototype;\n\nexport class MaxBufferError extends Error {\n\tname = 'MaxBufferError';\n\n\tconstructor() {\n\t\tsuper('maxBuffer exceeded');\n\t}\n}\n","export const identity = value => value;\n\nexport const noop = () => undefined;\n\nexport const getContentsProp = ({contents}) => contents;\n\nexport const throwObjectStream = chunk => {\n\tthrow new Error(`Streams in object mode are not supported: ${String(chunk)}`);\n};\n\nexport const getLengthProp = convertedChunk => convertedChunk.length;\n","import {getStreamContents} from './contents.js';\nimport {noop, throwObjectStream, getLengthProp} from './utils.js';\n\nexport async function getStreamAsArrayBuffer(stream, options) {\n\treturn getStreamContents(stream, arrayBufferMethods, options);\n}\n\nconst initArrayBuffer = () => ({contents: new ArrayBuffer(0)});\n\nconst useTextEncoder = chunk => textEncoder.encode(chunk);\nconst textEncoder = new TextEncoder();\n\nconst useUint8Array = chunk => new Uint8Array(chunk);\n\nconst useUint8ArrayWithOffset = chunk => new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength);\n\nconst truncateArrayBufferChunk = (convertedChunk, chunkSize) => convertedChunk.slice(0, chunkSize);\n\n// `contents` is an increasingly growing `Uint8Array`.\nconst addArrayBufferChunk = (convertedChunk, {contents, length: previousLength}, length) => {\n\tconst newContents = hasArrayBufferResize() ? resizeArrayBuffer(contents, length) : resizeArrayBufferSlow(contents, length);\n\tnew Uint8Array(newContents).set(convertedChunk, previousLength);\n\treturn newContents;\n};\n\n// Without `ArrayBuffer.resize()`, `contents` size is always a power of 2.\n// This means its last bytes are zeroes (not stream data), which need to be\n// trimmed at the end with `ArrayBuffer.slice()`.\nconst resizeArrayBufferSlow = (contents, length) => {\n\tif (length <= contents.byteLength) {\n\t\treturn contents;\n\t}\n\n\tconst arrayBuffer = new ArrayBuffer(getNewContentsLength(length));\n\tnew Uint8Array(arrayBuffer).set(new Uint8Array(contents), 0);\n\treturn arrayBuffer;\n};\n\n// With `ArrayBuffer.resize()`, `contents` size matches exactly the size of\n// the stream data. It does not include extraneous zeroes to trim at the end.\n// The underlying `ArrayBuffer` does allocate a number of bytes that is a power\n// of 2, but those bytes are only visible after calling `ArrayBuffer.resize()`.\nconst resizeArrayBuffer = (contents, length) => {\n\tif (length <= contents.maxByteLength) {\n\t\tcontents.resize(length);\n\t\treturn contents;\n\t}\n\n\tconst arrayBuffer = new ArrayBuffer(length, {maxByteLength: getNewContentsLength(length)});\n\tnew Uint8Array(arrayBuffer).set(new Uint8Array(contents), 0);\n\treturn arrayBuffer;\n};\n\n// Retrieve the closest `length` that is both >= and a power of 2\nconst getNewContentsLength = length => SCALE_FACTOR ** Math.ceil(Math.log(length) / Math.log(SCALE_FACTOR));\n\nconst SCALE_FACTOR = 2;\n\nconst finalizeArrayBuffer = ({contents, length}) => hasArrayBufferResize() ? contents : contents.slice(0, length);\n\n// `ArrayBuffer.slice()` is slow. When `ArrayBuffer.resize()` is available\n// (Node >=20.0.0, Safari >=16.4 and Chrome), we can use it instead.\n// eslint-disable-next-line no-warning-comments\n// TODO: remove after dropping support for Node 20.\n// eslint-disable-next-line no-warning-comments\n// TODO: use `ArrayBuffer.transferToFixedLength()` instead once it is available\nconst hasArrayBufferResize = () => 'resize' in ArrayBuffer.prototype;\n\nconst arrayBufferMethods = {\n\tinit: initArrayBuffer,\n\tconvertChunk: {\n\t\tstring: useTextEncoder,\n\t\tbuffer: useUint8Array,\n\t\tarrayBuffer: useUint8Array,\n\t\tdataView: useUint8ArrayWithOffset,\n\t\ttypedArray: useUint8ArrayWithOffset,\n\t\tothers: throwObjectStream,\n\t},\n\tgetSize: getLengthProp,\n\ttruncateChunk: truncateArrayBufferChunk,\n\taddChunk: addArrayBufferChunk,\n\tgetFinalChunk: noop,\n\tfinalize: finalizeArrayBuffer,\n};\n","import {getStreamAsArrayBuffer} from './array-buffer.js';\n\nexport async function getStreamAsBuffer(stream, options) {\n\tif (!('Buffer' in globalThis)) {\n\t\tthrow new Error('getStreamAsBuffer() is only supported in Node.js');\n\t}\n\n\ttry {\n\t\treturn arrayBufferToNodeBuffer(await getStreamAsArrayBuffer(stream, options));\n\t} catch (error) {\n\t\tif (error.bufferedData !== undefined) {\n\t\t\terror.bufferedData = arrayBufferToNodeBuffer(error.bufferedData);\n\t\t}\n\n\t\tthrow error;\n\t}\n}\n\n// eslint-disable-next-line n/prefer-global/buffer\nconst arrayBufferToNodeBuffer = arrayBuffer => globalThis.Buffer.from(arrayBuffer);\n","import type Oas from 'oas';\n\nfunction stripTrailingSlash(url: string) {\n if (url[url.length - 1] === '/') {\n return url.slice(0, -1);\n }\n\n return url;\n}\n\n/**\n * With an SDK server config and an instance of OAS we should extract and prepare the server and\n * any server variables to be supplied to `@readme/oas-to-har`.\n *\n */\nexport default function prepareServer(spec: Oas, url: string, variables: Record<string, string | number> = {}) {\n let serverIdx;\n const sanitizedUrl = stripTrailingSlash(url);\n (spec.api.servers || []).forEach((server, i) => {\n if (server.url === sanitizedUrl) {\n serverIdx = i;\n }\n });\n\n // If we were able to find the passed in server in the OAS servers, we should use that! If we\n // couldn't and server variables were passed in we should try our best to handle that, otherwise\n // we should ignore the passed in server and use whever the default from the OAS is.\n if (serverIdx) {\n return {\n selected: serverIdx,\n variables,\n };\n } else if (Object.keys(variables).length) {\n // @todo we should run `oas.replaceUrl(url)` and pass that unto `@readme/oas-to-har`\n } else {\n const server = spec.splitVariables(url);\n if (server) {\n return {\n selected: server.selected,\n variables: server.variables,\n };\n }\n\n // @todo we should pass `url` directly into `@readme/oas-to-har` as the base URL\n }\n\n return false;\n}\n"]}
|
package/dist/index.cjs
CHANGED
|
@@ -6,7 +6,7 @@ var _chunkNVFSP2R3cjs = require('./chunk-NVFSP2R3.cjs');
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _chunkHGLVXDVZcjs = require('./chunk-HGLVXDVZ.cjs');
|
|
10
10
|
|
|
11
11
|
// src/index.ts
|
|
12
12
|
var _oastohar = require('@readme/oas-to-har'); var _oastohar2 = _interopRequireDefault(_oastohar);
|
|
@@ -48,15 +48,15 @@ var APICore = (_class = class {
|
|
|
48
48
|
return this.fetchOperation(operation, body, metadata);
|
|
49
49
|
}
|
|
50
50
|
async fetchOperation(operation, body, metadata) {
|
|
51
|
-
return
|
|
51
|
+
return _chunkHGLVXDVZcjs.prepareParams.call(void 0, operation, body, metadata).then((params) => {
|
|
52
52
|
const data = { ...params };
|
|
53
53
|
if (this.server) {
|
|
54
|
-
const preparedServer =
|
|
54
|
+
const preparedServer = _chunkHGLVXDVZcjs.prepareServer.call(void 0, this.spec, this.server.url, this.server.variables);
|
|
55
55
|
if (preparedServer) {
|
|
56
56
|
data.server = preparedServer;
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
-
const har = _oastohar2.default.call(void 0, this.spec, operation, data,
|
|
59
|
+
const har = _oastohar2.default.call(void 0, this.spec, operation, data, _chunkHGLVXDVZcjs.prepareAuth.call(void 0, this.auth, operation));
|
|
60
60
|
let timeoutSignal;
|
|
61
61
|
const init = {};
|
|
62
62
|
if (this.config.timeout) {
|
|
@@ -69,7 +69,7 @@ var APICore = (_class = class {
|
|
|
69
69
|
init,
|
|
70
70
|
userAgent: this.userAgent
|
|
71
71
|
}).then(async (res) => {
|
|
72
|
-
const parsed = await
|
|
72
|
+
const parsed = await _chunkHGLVXDVZcjs.parseResponse.call(void 0, res);
|
|
73
73
|
if (res.status >= 400 && res.status <= 599) {
|
|
74
74
|
throw new (0, _chunkNVFSP2R3cjs.FetchError)(
|
|
75
75
|
parsed.status,
|
package/dist/index.js
CHANGED
package/dist/lib/index.cjs
CHANGED
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _chunkHGLVXDVZcjs = require('../chunk-HGLVXDVZ.cjs');
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
exports.getJSONSchemaDefaults =
|
|
14
|
+
exports.getJSONSchemaDefaults = _chunkHGLVXDVZcjs.getJSONSchemaDefaults; exports.parseResponse = _chunkHGLVXDVZcjs.parseResponse; exports.prepareAuth = _chunkHGLVXDVZcjs.prepareAuth; exports.prepareParams = _chunkHGLVXDVZcjs.prepareParams; exports.prepareServer = _chunkHGLVXDVZcjs.prepareServer;
|
|
15
15
|
//# sourceMappingURL=index.cjs.map
|
package/dist/lib/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@readme/api-core",
|
|
3
|
-
"version": "7.0.0-beta.
|
|
3
|
+
"version": "7.0.0-beta.1",
|
|
4
4
|
"description": "The magic behind `api` 🧙",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"type": "module",
|
|
@@ -49,7 +49,6 @@
|
|
|
49
49
|
"caseless": "^0.12.0",
|
|
50
50
|
"datauri": "^4.1.0",
|
|
51
51
|
"fetch-har": "^11.0.1",
|
|
52
|
-
"get-stream": "^8.0.1",
|
|
53
52
|
"json-schema-to-ts": "^2.9.2",
|
|
54
53
|
"json-schema-traverse": "^1.0.0",
|
|
55
54
|
"lodash.merge": "^4.6.2",
|
|
@@ -57,15 +56,16 @@
|
|
|
57
56
|
"remove-undefined-objects": "^5.0.0"
|
|
58
57
|
},
|
|
59
58
|
"devDependencies": {
|
|
60
|
-
"@api/test-utils": "^7.0.0-beta.
|
|
59
|
+
"@api/test-utils": "^7.0.0-beta.1",
|
|
61
60
|
"@readme/oas-examples": "^5.12.0",
|
|
62
61
|
"@types/caseless": "^0.12.3",
|
|
63
62
|
"@types/lodash.merge": "^4.6.7",
|
|
64
63
|
"@vitest/coverage-v8": "^0.34.4",
|
|
65
64
|
"fetch-mock": "^9.11.0",
|
|
65
|
+
"get-stream": "^8.0.1",
|
|
66
66
|
"typescript": "^5.2.2",
|
|
67
67
|
"vitest": "^0.34.5"
|
|
68
68
|
},
|
|
69
69
|
"prettier": "@readme/eslint-config/prettier",
|
|
70
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "e31539d88b5af53ed7be05495329de1c2a70c93f"
|
|
71
71
|
}
|
package/src/lib/prepareParams.ts
CHANGED
|
@@ -9,6 +9,8 @@ import stream from 'node:stream';
|
|
|
9
9
|
import caseless from 'caseless';
|
|
10
10
|
import DatauriParser from 'datauri/parser.js';
|
|
11
11
|
import datauri from 'datauri/sync.js';
|
|
12
|
+
// `get-stream` is included in our bundle, see `tsup.config.ts`
|
|
13
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
12
14
|
import { getStreamAsBuffer } from 'get-stream';
|
|
13
15
|
import lodashMerge from 'lodash.merge';
|
|
14
16
|
import removeUndefinedObjects from 'remove-undefined-objects';
|
package/tsup.config.ts
CHANGED
|
@@ -11,5 +11,11 @@ export default defineConfig((options: Options) => ({
|
|
|
11
11
|
...config,
|
|
12
12
|
|
|
13
13
|
entry: ['src/errors/fetchError.ts', 'src/lib/index.ts', 'src/index.ts'],
|
|
14
|
+
noExternal: [
|
|
15
|
+
// `get-stream` is ESM-only and we need to build for CommonJS,
|
|
16
|
+
// so including it here means that its (tree-shaken!) source code
|
|
17
|
+
// will be included directly in our dist outputs.
|
|
18
|
+
'get-stream',
|
|
19
|
+
],
|
|
14
20
|
silent: !options.watch,
|
|
15
21
|
}));
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/lib/getJSONSchemaDefaults.ts","../src/lib/parseResponse.ts","../src/lib/prepareAuth.ts","../src/lib/prepareParams.ts","../src/lib/prepareServer.ts"],"sourcesContent":["import type { SchemaWrapper } from 'oas/operation/get-parameters-as-json-schema';\nimport type { SchemaObject } from 'oas/rmoas.types';\n\nimport traverse from 'json-schema-traverse';\n\n/**\n * Run through a JSON Schema object and compose up an object containing default data for any schema\n * property that is required and also has a defined default.\n *\n * Code partially adapted from the `json-schema-default` package but modified to only return\n * defaults of required properties.\n *\n * @todo This is a good candidate to be moved into a core `oas` library method.\n * @see {@link https://github.com/mdornseif/json-schema-default}\n */\nexport default function getJSONSchemaDefaults(jsonSchemas: SchemaWrapper[]) {\n return jsonSchemas\n .map(({ type: payloadType, schema: jsonSchema }) => {\n const defaults: Record<string, unknown> = {};\n traverse(\n jsonSchema,\n (\n schema: SchemaObject,\n pointer: string,\n rootSchema: SchemaObject,\n parentPointer?: string,\n parentKeyword?: string,\n parentSchema?: SchemaObject,\n indexProperty?: string | number,\n ) => {\n if (!pointer.startsWith('/properties/')) {\n return;\n }\n\n if (Array.isArray(parentSchema?.required) && parentSchema?.required.includes(String(indexProperty))) {\n if (schema.type === 'object' && indexProperty) {\n defaults[indexProperty] = {};\n }\n\n let destination = defaults;\n if (parentPointer) {\n // To map nested objects correct we need to pick apart the parent pointer.\n parentPointer\n .replace(/\\/properties/g, '')\n .split('/')\n .forEach((subSchema: string) => {\n if (subSchema === '') {\n return;\n }\n\n destination = (destination?.[subSchema] as Record<string, unknown>) || {};\n });\n }\n\n if (schema.default !== undefined) {\n if (indexProperty !== undefined) {\n destination[indexProperty] = schema.default;\n }\n }\n }\n },\n );\n\n if (!Object.keys(defaults).length) {\n return {};\n }\n\n return {\n // @todo should we filter out empty and undefined objects from here with `remove-undefined-objects`?\n [payloadType]: defaults,\n };\n })\n .reduce((prev, next) => Object.assign(prev, next));\n}\n","import { matchesMimeType } from 'oas/utils';\n\nexport default async function parseResponse<HTTPStatus extends number = number>(response: Response) {\n const contentType = response.headers.get('Content-Type');\n const isJSON = contentType && (matchesMimeType.json(contentType) || matchesMimeType.wildcard(contentType));\n\n const responseBody = await response.text();\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let data: any = responseBody;\n if (isJSON) {\n try {\n data = JSON.parse(responseBody);\n } catch (e) {\n // If our JSON parsing failed then we can just return plaintext instead.\n }\n }\n\n return {\n data,\n status: response.status as HTTPStatus,\n headers: response.headers,\n res: response,\n };\n}\n","/* eslint-disable no-underscore-dangle */\nimport type Operation from 'oas/operation';\nimport type { KeyedSecuritySchemeObject } from 'oas/rmoas.types';\n\nexport default function prepareAuth(authKey: (number | string)[], operation: Operation) {\n if (authKey.length === 0) {\n return {};\n }\n\n const preparedAuth: Record<\n string,\n | string\n | number\n | {\n pass: string | number;\n user: string | number;\n }\n > = {};\n\n const security = operation.getSecurity();\n if (security.length === 0) {\n // If there's no auth configured on this operation, don't prepare anything (even if it was\n // supplied by the user).\n return {};\n }\n\n // Does this operation require multiple forms of auth?\n if (security.every(s => Object.keys(s).length > 1)) {\n throw new Error(\n \"Sorry, this operation currently requires multiple forms of authentication which this library doesn't yet support.\",\n );\n }\n\n // Since we can only handle single auth security configurations, let's pull those out. This code\n // is a bit opaque but `security` here may look like `[{ basic: [] }, { oauth2: [], basic: []}]`\n // and are filtering it down to only single-auth requirements of `[{ basic: [] }]`.\n const usableSecurity = security\n .map(s => {\n return Object.keys(s).length === 1 ? s : false;\n })\n .filter(Boolean);\n\n const usableSecuritySchemes = usableSecurity.map(s => Object.keys(s)).reduce((prev, next) => prev.concat(next), []);\n const preparedSecurity = operation.prepareSecurity();\n\n // If we have two auth tokens present let's look for Basic Auth in their configuration.\n if (authKey.length >= 2) {\n // If this operation doesn't support HTTP Basic auth but we have two tokens, that's a paddlin.\n if (!('Basic' in preparedSecurity)) {\n throw new Error('Multiple auth tokens were supplied for this endpoint but only a single token is needed.');\n }\n\n // If we have two auth keys for Basic Auth but Basic isn't a usable security scheme (maybe it's\n // part of an AND or auth configuration -- which we don't support) then we need to error out.\n const schemes = preparedSecurity.Basic.filter(s => usableSecuritySchemes.includes(s._key));\n if (!schemes.length) {\n throw new Error(\n '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.',\n );\n }\n\n const scheme = schemes.shift() as KeyedSecuritySchemeObject;\n preparedAuth[scheme._key] = {\n user: authKey[0],\n pass: authKey.length === 2 ? authKey[1] : '',\n };\n\n return preparedAuth;\n }\n\n // If we know we don't need to use HTTP Basic auth because we have a username+password then we\n // can pick the first usable security scheme available and try to use that. This might not always\n // be the auth scheme that the user wants, but we don't have any other way for the user to tell\n // us what they want with the current `sdk.auth()` API.\n const usableScheme = usableSecuritySchemes[0];\n const schemes = Object.entries(preparedSecurity)\n .map(([, ps]) => ps.filter(s => usableScheme === s._key))\n .reduce((prev, next) => prev.concat(next), []);\n\n const scheme = schemes.shift() as KeyedSecuritySchemeObject;\n switch (scheme.type) {\n case 'http':\n if (scheme.scheme === 'basic') {\n preparedAuth[scheme._key] = {\n user: authKey[0],\n pass: authKey.length === 2 ? authKey[1] : '',\n };\n } else if (scheme.scheme === 'bearer') {\n preparedAuth[scheme._key] = authKey[0];\n }\n break;\n\n case 'oauth2':\n preparedAuth[scheme._key] = authKey[0];\n break;\n\n case 'apiKey':\n if (scheme.in === 'query' || scheme.in === 'header' || scheme.in === 'cookie') {\n preparedAuth[scheme._key] = authKey[0];\n }\n break;\n\n default:\n throw new Error(\n `Sorry, this API currently uses a security scheme, ${scheme.type}, which this library doesn't yet support.`,\n );\n }\n\n return preparedAuth;\n}\n","import type { ReadStream } from 'node:fs';\nimport type Operation from 'oas/operation';\nimport type { ParameterObject, SchemaObject } from 'oas/rmoas.types';\n\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport stream from 'node:stream';\n\nimport caseless from 'caseless';\nimport DatauriParser from 'datauri/parser.js';\nimport datauri from 'datauri/sync.js';\nimport { getStreamAsBuffer } from 'get-stream';\nimport lodashMerge from 'lodash.merge';\nimport removeUndefinedObjects from 'remove-undefined-objects';\n\nimport getJSONSchemaDefaults from './getJSONSchemaDefaults.js';\n\n// These headers are normally only defined by the OpenAPI definition but we allow the user to\n// manually supply them in their `metadata` parameter if they wish.\nconst specialHeaders = ['accept', 'authorization'];\n\n/**\n * Extract all available parameters from an operations Parameter Object into a digestable array\n * that we can use to apply to the request.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameterObject}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#parameterObject}\n */\nfunction digestParameters(parameters: ParameterObject[]): Record<string, ParameterObject> {\n return parameters.reduce((prev, param) => {\n if ('$ref' in param || 'allOf' in param || 'anyOf' in param || 'oneOf' in param) {\n throw new Error(\"The OpenAPI document for this operation wasn't dereferenced before processing.\");\n } else if (param.name in prev) {\n throw new Error(\n `The operation you are using has the same parameter, ${param.name}, spread across multiple entry points. We unfortunately can't handle this right now.`,\n );\n }\n\n return Object.assign(prev, { [param.name]: param });\n }, {});\n}\n\n// https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore#_isempty\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction isEmpty(obj: any) {\n return [Object, Array].includes((obj || {}).constructor) && !Object.entries(obj || {}).length;\n}\n\nfunction isObject(thing: unknown) {\n if (thing instanceof stream.Readable) {\n return false;\n }\n\n return typeof thing === 'object' && thing !== null && !Array.isArray(thing);\n}\n\nfunction isPrimitive(obj: unknown) {\n return obj === null || typeof obj === 'number' || typeof obj === 'string';\n}\n\nfunction merge(src: unknown, target: unknown) {\n if (Array.isArray(target)) {\n // @todo we need to add support for merging array defaults with array body/metadata arguments\n return target;\n } else if (!isObject(target)) {\n return target;\n }\n\n return lodashMerge(src, target);\n}\n\n/**\n * Ingest a file path or readable stream into a common object that we can later use to process it\n * into a parameters object for making an API request.\n *\n */\nfunction processFile(\n paramName: string | undefined,\n file: string | ReadStream,\n): Promise<{ base64?: string; buffer?: Buffer; filename: string; paramName?: string } | undefined> {\n if (typeof file === 'string') {\n // In order to support relative pathed files, we need to attempt to resolve them.\n const resolvedFile = path.resolve(file);\n\n return new Promise((resolve, reject) => {\n fs.stat(resolvedFile, async err => {\n if (err) {\n if (err.code === 'ENOENT') {\n // It's less than ideal for us to handle files that don't exist like this but because\n // `file` is a string it might actually be the full text contents of the file and not\n // actually a path.\n //\n // We also can't really regex to see if `file` *looks*` like a path because one should be\n // able to pass in a relative `owlbert.png` (instead of `./owlbert.png`) and though that\n // doesn't *look* like a path, it is one that should still work.\n return resolve(undefined);\n }\n\n return reject(err);\n }\n\n const fileMetadata = await datauri(resolvedFile);\n const payloadFilename = encodeURIComponent(path.basename(resolvedFile));\n\n return resolve({\n paramName,\n base64: fileMetadata?.content?.replace(';base64', `;name=${payloadFilename};base64`),\n filename: payloadFilename,\n buffer: fileMetadata.buffer,\n });\n });\n });\n } else if (file instanceof stream.Readable) {\n return getStreamAsBuffer(file).then(buffer => {\n const filePath = file.path as string;\n const parser = new DatauriParser();\n const base64 = parser.format(filePath, buffer).content;\n const payloadFilename = encodeURIComponent(path.basename(filePath));\n\n return {\n paramName,\n base64: base64?.replace(';base64', `;name=${payloadFilename};base64`),\n filename: payloadFilename,\n buffer,\n };\n });\n }\n\n return Promise.reject(\n new TypeError(\n paramName\n ? `The data supplied for the \\`${paramName}\\` request body parameter is not a file handler that we support.`\n : 'The data supplied for the request body payload is not a file handler that we support.',\n ),\n );\n}\n\n/**\n * With potentially supplied body and/or metadata we need to run through them against a given API\n * operation to see what's what and prepare any available parameters to be used in an API request\n * with `@readme/oas-to-har`.\n *\n */\nexport default async function prepareParams(operation: Operation, body?: unknown, metadata?: Record<string, unknown>) {\n let metadataIntersected = false;\n const digestedParameters = digestParameters(operation.getParameters());\n const jsonSchema = operation.getParametersAsJSONSchema();\n\n /**\n * It might be common for somebody to run `sdk.findPetsByStatus({ status: 'available' }, {})`, in\n * which case we want to filter out the second (metadata) parameter and treat the first parameter\n * as the metadata instead. If we don't do this, their supplied `status` metadata will be treated\n * as a body parameter, and because there's no `status` body parameter, and no supplied metadata\n * (because it's an empty object), the request won't send a payload.\n *\n * @see {@link https://github.com/readmeio/api/issues/449}\n */\n // eslint-disable-next-line no-param-reassign\n metadata = removeUndefinedObjects(metadata);\n\n if (!jsonSchema && (body !== undefined || metadata !== undefined)) {\n let throwNoParamsError = true;\n\n // If this operation doesn't have any parameters for us to transform to JSON Schema but they've\n // sent us either an `Accept` or `Authorization` header (or both) we should let them do that.\n // We should, however, only do this check for the `body` parameter as if they've sent this\n // request both `body` and `metadata` we can reject it outright as the operation won't have any\n // body data.\n if (body !== undefined) {\n if (typeof body === 'object' && body !== null && !Array.isArray(body)) {\n if (Object.keys(body).length <= 2) {\n const bodyParams = caseless(body);\n\n if (specialHeaders.some(header => bodyParams.has(header))) {\n throwNoParamsError = false;\n }\n }\n }\n }\n\n if (throwNoParamsError) {\n throw new Error(\n \"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.\",\n );\n }\n }\n\n const jsonSchemaDefaults = jsonSchema ? getJSONSchemaDefaults(jsonSchema) : {};\n\n const params: {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n body?: any;\n cookie?: Record<string, string | number | boolean>;\n files?: Record<string, Buffer>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n formData?: any;\n header?: Record<string, string | number | boolean>;\n path?: Record<string, string | number | boolean>;\n query?: Record<string, string | number | boolean>;\n server?: {\n selected: number;\n variables: Record<string, string | number>;\n };\n } = jsonSchemaDefaults;\n\n // If a body argument was supplied we need to do a bit of work to see if it's actually a body\n // argument or metadata because the library lets you supply either a body, metadata, or body with\n // metadata.\n if (typeof body !== 'undefined') {\n if (Array.isArray(body) || isPrimitive(body)) {\n // If the body param is an array or a primitive then we know it's absolutely a body because\n // metadata can only ever be undefined or an object.\n params.body = merge(params.body, body);\n } else if (typeof metadata === 'undefined') {\n // No metadata was explicitly provided so we need to analyze the body to determine if it's a\n // body or should be actually be treated as metadata.\n const headerParams = caseless({});\n Object.entries(digestedParameters).forEach(([paramName, param]) => {\n // Headers are sent case-insensitive so we need to make sure that we're properly\n // matching them when detecting what our incoming payload looks like.\n if (param.in === 'header') {\n headerParams.set(paramName, '');\n }\n });\n\n // `Accept` and `Authorization` headers can't be defined as normal parameters but we should\n // always allow the user to supply them if they wish.\n specialHeaders.forEach(header => {\n if (!headerParams.has(header)) {\n headerParams.set(header, '');\n }\n });\n\n const intersection = Object.keys(body as NonNullable<unknown>).filter(value => {\n if (Object.keys(digestedParameters).includes(value)) {\n return true;\n } else if (headerParams.has(value)) {\n return true;\n }\n\n return false;\n }).length;\n\n // If more than 25% of the body intersects with the parameters that we've got on hand, then\n // we should treat it as a metadata object and organize into parameters.\n if (intersection && intersection / Object.keys(body as NonNullable<unknown>).length > 0.25) {\n /* eslint-disable no-param-reassign */\n metadataIntersected = true;\n metadata = merge(params.body, body) as Record<string, unknown>;\n body = undefined;\n /* eslint-enable no-param-reassign */\n } else {\n // For all other cases, we should just treat the supplied body as a body.\n params.body = merge(params.body, body);\n }\n } else {\n // Body and metadata were both supplied.\n params.body = merge(params.body, body);\n }\n }\n\n if (!operation.hasRequestBody()) {\n // If this operation doesn't have any documented request body then we shouldn't be sending\n // anything.\n delete params.body;\n } else {\n if (!('body' in params)) params.body = {};\n\n // We need to retrieve the request body for this operation to search for any `binary` format\n // data that the user wants to send so we know what we need to prepare for the final API\n // request.\n const payloadJsonSchema = jsonSchema.find(js => js.type === 'body');\n if (payloadJsonSchema) {\n if (!params.files) params.files = {};\n\n const conversions = [];\n\n // @todo add support for `type: array`, `oneOf` and `anyOf`\n if (payloadJsonSchema.schema?.properties) {\n Object.entries(payloadJsonSchema.schema?.properties)\n .filter(([, schema]: [string, SchemaObject]) => schema?.format === 'binary')\n .filter(([prop]) => Object.keys(params.body).includes(prop))\n .forEach(([prop]) => {\n conversions.push(processFile(prop, params.body[prop]));\n });\n } else if (payloadJsonSchema.schema?.type === 'string') {\n if (payloadJsonSchema.schema?.format === 'binary') {\n conversions.push(processFile(undefined, params.body));\n }\n }\n\n await Promise.all(conversions)\n .then(fileMetadata => fileMetadata.filter(Boolean))\n .then(fm => {\n fm.forEach(fileMetadata => {\n if (!fileMetadata) {\n // If we don't have any metadata here it's because the file we have is likely\n // the full string content of the file so since we don't have any filenames to\n // work with we shouldn't do any additional handling to the `body` or `files`\n // parameters.\n return;\n }\n\n if (fileMetadata.paramName) {\n params.body[fileMetadata.paramName] = fileMetadata.base64;\n } else {\n params.body = fileMetadata.base64;\n }\n\n if (fileMetadata.buffer && params?.files) {\n params.files[fileMetadata.filename] = fileMetadata.buffer;\n }\n });\n });\n }\n }\n\n // Form data should be placed within `formData` instead of `body` for it to properly get picked\n // up by `fetch-har`.\n if (operation.isFormUrlEncoded()) {\n params.formData = merge(params.formData, params.body);\n delete params.body;\n }\n\n // Only spend time trying to organize metadata into parameters if we were able to digest\n // parameters out of the operation schema. If we couldn't digest anything, but metadata was\n // supplied then we wouldn't know how to send it in the request!\n if (typeof metadata !== 'undefined') {\n if (!('cookie' in params)) params.cookie = {};\n if (!('header' in params)) params.header = {};\n if (!('path' in params)) params.path = {};\n if (!('query' in params)) params.query = {};\n\n Object.entries(digestedParameters).forEach(([paramName, param]) => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let value: any;\n let metadataHeaderParam;\n if (typeof metadata === 'object' && !isEmpty(metadata)) {\n if (paramName in metadata) {\n value = metadata[paramName];\n metadataHeaderParam = paramName;\n } else if (param.in === 'header') {\n // Headers are sent case-insensitive so we need to make sure that we're properly\n // matching them when detecting what our incoming payload looks like.\n metadataHeaderParam = Object.keys(metadata).find(k => k.toLowerCase() === paramName.toLowerCase()) || '';\n value = metadata[metadataHeaderParam];\n }\n }\n\n if (value === undefined) {\n return;\n }\n\n /* eslint-disable no-param-reassign */\n switch (param.in) {\n case 'path':\n (params.path as NonNullable<typeof params.path>)[paramName] = value;\n if (metadata?.[paramName]) delete metadata[paramName];\n break;\n case 'query':\n (params.query as NonNullable<typeof params.query>)[paramName] = value;\n if (metadata?.[paramName]) delete metadata[paramName];\n break;\n case 'header':\n (params.header as NonNullable<typeof params.header>)[paramName.toLowerCase()] = value;\n if (metadataHeaderParam && metadata?.[metadataHeaderParam]) delete metadata[metadataHeaderParam];\n break;\n case 'cookie':\n (params.cookie as NonNullable<typeof params.cookie>)[paramName] = value;\n if (metadata?.[paramName]) delete metadata[paramName];\n break;\n default: // no-op\n }\n /* eslint-enable no-param-reassign */\n\n // Because a user might have sent just a metadata object, we want to make sure that we filter\n // out anything that they sent that is a parameter from also being sent as part of a form\n // data payload for `x-www-form-urlencoded` requests.\n if (metadataIntersected && operation.isFormUrlEncoded()) {\n if (paramName in params.formData) {\n delete params.formData[paramName];\n }\n }\n });\n\n // If there's any leftover metadata that hasn't been moved into form data for this request we\n // need to move it or else it'll get tossed.\n if (!isEmpty(metadata)) {\n if (typeof metadata === 'object') {\n // If the user supplied an `accept` or `authorization` header themselves we should allow it\n // through. Normally these headers are automatically handled by `@readme/oas-to-har` but in\n // the event that maybe the user wants to return XML for an API that normally returns JSON\n // or specify a custom auth header (maybe we can't handle their auth case right) this is the\n // only way with this library that they can do that.\n specialHeaders.forEach(headerName => {\n const headerParam = Object.keys(metadata || {}).find(m => m.toLowerCase() === headerName);\n if (headerParam) {\n // this if-statement below is a typeguard\n if (typeof metadata === 'object') {\n // this if-statement below is a typeguard\n if (typeof params.header === 'object') {\n params.header[headerName] = metadata[headerParam] as string;\n }\n // eslint-disable-next-line no-param-reassign\n delete metadata[headerParam];\n }\n }\n });\n }\n\n if (operation.isFormUrlEncoded()) {\n params.formData = merge(params.formData, metadata);\n } else {\n // Any other remaining unused metadata will be unused because we don't know where to place\n // it in the request.\n }\n }\n }\n\n (['body', 'cookie', 'files', 'formData', 'header', 'path', 'query'] as const).forEach((type: keyof typeof params) => {\n if (type in params && isEmpty(params[type])) {\n delete params[type];\n }\n });\n\n return params;\n}\n","import type Oas from 'oas';\n\nfunction stripTrailingSlash(url: string) {\n if (url[url.length - 1] === '/') {\n return url.slice(0, -1);\n }\n\n return url;\n}\n\n/**\n * With an SDK server config and an instance of OAS we should extract and prepare the server and\n * any server variables to be supplied to `@readme/oas-to-har`.\n *\n */\nexport default function prepareServer(spec: Oas, url: string, variables: Record<string, string | number> = {}) {\n let serverIdx;\n const sanitizedUrl = stripTrailingSlash(url);\n (spec.api.servers || []).forEach((server, i) => {\n if (server.url === sanitizedUrl) {\n serverIdx = i;\n }\n });\n\n // If we were able to find the passed in server in the OAS servers, we should use that! If we\n // couldn't and server variables were passed in we should try our best to handle that, otherwise\n // we should ignore the passed in server and use whever the default from the OAS is.\n if (serverIdx) {\n return {\n selected: serverIdx,\n variables,\n };\n } else if (Object.keys(variables).length) {\n // @todo we should run `oas.replaceUrl(url)` and pass that unto `@readme/oas-to-har`\n } else {\n const server = spec.splitVariables(url);\n if (server) {\n return {\n selected: server.selected,\n variables: server.variables,\n };\n }\n\n // @todo we should pass `url` directly into `@readme/oas-to-har` as the base URL\n }\n\n return false;\n}\n"],"mappings":";AAGA,OAAO,cAAc;AAYN,SAAR,sBAAuC,aAA8B;AAC1E,SAAO,YACJ,IAAI,CAAC,EAAE,MAAM,aAAa,QAAQ,WAAW,MAAM;AAClD,UAAM,WAAoC,CAAC;AAC3C;AAAA,MACE;AAAA,MACA,CACE,QACA,SACA,YACA,eACA,eACA,cACA,kBACG;AACH,YAAI,CAAC,QAAQ,WAAW,cAAc,GAAG;AACvC;AAAA,QACF;AAEA,YAAI,MAAM,QAAQ,cAAc,QAAQ,KAAK,cAAc,SAAS,SAAS,OAAO,aAAa,CAAC,GAAG;AACnG,cAAI,OAAO,SAAS,YAAY,eAAe;AAC7C,qBAAS,aAAa,IAAI,CAAC;AAAA,UAC7B;AAEA,cAAI,cAAc;AAClB,cAAI,eAAe;AAEjB,0BACG,QAAQ,iBAAiB,EAAE,EAC3B,MAAM,GAAG,EACT,QAAQ,CAAC,cAAsB;AAC9B,kBAAI,cAAc,IAAI;AACpB;AAAA,cACF;AAEA,4BAAe,cAAc,SAAS,KAAiC,CAAC;AAAA,YAC1E,CAAC;AAAA,UACL;AAEA,cAAI,OAAO,YAAY,QAAW;AAChC,gBAAI,kBAAkB,QAAW;AAC/B,0BAAY,aAAa,IAAI,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QAAQ,OAAO,EAAY,QAAQ,CAAC,SAA8B;AACnH,QAAI,QAAQ,UAAU,QAAQ,OAAO,IAAI,CAAC,GAAG;AAC3C,aAAO,OAAO,IAAI;AAAA,IACpB;AAAA,EACF,CAAC;AAED,SAAO;AACT;;;ACxaA,SAAS,mBAAmB,KAAa;AACvC,MAAI,IAAI,IAAI,SAAS,CAAC,MAAM,KAAK;AAC/B,WAAO,IAAI,MAAM,GAAG,EAAE;AAAA,EACxB;AAEA,SAAO;AACT;AAOe,SAAR,cAA+B,MAAW,KAAa,YAA6C,CAAC,GAAG;AAC7G,MAAI;AACJ,QAAM,eAAe,mBAAmB,GAAG;AAC3C,GAAC,KAAK,IAAI,WAAW,CAAC,GAAG,QAAQ,CAAC,QAAQ,MAAM;AAC9C,QAAI,OAAO,QAAQ,cAAc;AAC/B,kBAAY;AAAA,IACd;AAAA,EACF,CAAC;AAKD,MAAI,WAAW;AACb,WAAO;AAAA,MACL,UAAU;AAAA,MACV;AAAA,IACF;AAAA,EACF,WAAW,OAAO,KAAK,SAAS,EAAE,QAAQ;AAAA,EAE1C,OAAO;AACL,UAAM,SAAS,KAAK,eAAe,GAAG;AACtC,QAAI,QAAQ;AACV,aAAO;AAAA,QACL,UAAU,OAAO;AAAA,QACjB,WAAW,OAAO;AAAA,MACpB;AAAA,IACF;AAAA,EAGF;AAEA,SAAO;AACT;","names":["schemes","scheme"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/lib/getJSONSchemaDefaults.ts","../src/lib/parseResponse.ts","../src/lib/prepareAuth.ts","../src/lib/prepareParams.ts","../src/lib/prepareServer.ts"],"names":["schemes","scheme"],"mappings":";AAGA,OAAO,cAAc;AAYN,SAAR,sBAAuC,aAA8B;AAC1E,SAAO,YACJ,IAAI,CAAC,EAAE,MAAM,aAAa,QAAQ,WAAW,MAAM;AAClD,UAAM,WAAoC,CAAC;AAC3C;AAAA,MACE;AAAA,MACA,CACE,QACA,SACA,YACA,eACA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1C,OAAO;AACL,UAAM,SAAS,KAAK,eAAe,GAAG;AACtC,QAAI,QAAQ;AACV,aAAO;AAAA,QACL,UAAU,OAAO;AAAA,QACjB,WAAW,OAAO;AAAA,MACpB;AAAA,IACF;AAAA,EAGF;AAEA,SAAO;AACT","sourcesContent":["import type { SchemaWrapper } from 'oas/operation/get-parameters-as-json-schema';\nimport type { SchemaObject } from 'oas/rmoas.types';\n\nimport traverse from 'json-schema-traverse';\n\n/**\n * Run through a JSON Schema object and compose up an object containing default data for any schema\n * property that is required and also has a defined default.\n *\n * Code partially adapted from the `json-schema-default` package but modified to only return\n * defaults of required properties.\n *\n * @todo This is a good candidate to be moved into a core `oas` library method.\n * @see {@link https://github.com/mdornseif/json-schema-default}\n */\nexport default function getJSONSchemaDefaults(jsonSchemas: SchemaWrapper[]) {\n return jsonSchemas\n .map(({ type: payloadType, schema: jsonSchema }) => {\n const defaults: Record<string, unknown> = {};\n traverse(\n jsonSchema,\n (\n schema: SchemaObject,\n pointer: string,\n rootSchema: SchemaObject,\n parentPointer?: string,\n parentKeyword?: string,\n parentSchema?: SchemaObject,\n indexProperty?: string | number,\n ) => {\n if (!pointer.startsWith('/properties/')) {\n return;\n }\n\n if (Array.isArray(parentSchema?.required) && parentSchema?.required.includes(String(indexProperty))) {\n if (schema.type === 'object' && indexProperty) {\n defaults[indexProperty] = {};\n }\n\n let destination = defaults;\n if (parentPointer) {\n // To map nested objects correct we need to pick apart the parent pointer.\n parentPointer\n .replace(/\\/properties/g, '')\n .split('/')\n .forEach((subSchema: string) => {\n if (subSchema === '') {\n return;\n }\n\n destination = (destination?.[subSchema] as Record<string, unknown>) || {};\n });\n }\n\n if (schema.default !== undefined) {\n if (indexProperty !== undefined) {\n destination[indexProperty] = schema.default;\n }\n }\n }\n },\n );\n\n if (!Object.keys(defaults).length) {\n return {};\n }\n\n return {\n // @todo should we filter out empty and undefined objects from here with `remove-undefined-objects`?\n [payloadType]: defaults,\n };\n })\n .reduce((prev, next) => Object.assign(prev, next));\n}\n","import { matchesMimeType } from 'oas/utils';\n\nexport default async function parseResponse<HTTPStatus extends number = number>(response: Response) {\n const contentType = response.headers.get('Content-Type');\n const isJSON = contentType && (matchesMimeType.json(contentType) || matchesMimeType.wildcard(contentType));\n\n const responseBody = await response.text();\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let data: any = responseBody;\n if (isJSON) {\n try {\n data = JSON.parse(responseBody);\n } catch (e) {\n // If our JSON parsing failed then we can just return plaintext instead.\n }\n }\n\n return {\n data,\n status: response.status as HTTPStatus,\n headers: response.headers,\n res: response,\n };\n}\n","/* eslint-disable no-underscore-dangle */\nimport type Operation from 'oas/operation';\nimport type { KeyedSecuritySchemeObject } from 'oas/rmoas.types';\n\nexport default function prepareAuth(authKey: (number | string)[], operation: Operation) {\n if (authKey.length === 0) {\n return {};\n }\n\n const preparedAuth: Record<\n string,\n | string\n | number\n | {\n pass: string | number;\n user: string | number;\n }\n > = {};\n\n const security = operation.getSecurity();\n if (security.length === 0) {\n // If there's no auth configured on this operation, don't prepare anything (even if it was\n // supplied by the user).\n return {};\n }\n\n // Does this operation require multiple forms of auth?\n if (security.every(s => Object.keys(s).length > 1)) {\n throw new Error(\n \"Sorry, this operation currently requires multiple forms of authentication which this library doesn't yet support.\",\n );\n }\n\n // Since we can only handle single auth security configurations, let's pull those out. This code\n // is a bit opaque but `security` here may look like `[{ basic: [] }, { oauth2: [], basic: []}]`\n // and are filtering it down to only single-auth requirements of `[{ basic: [] }]`.\n const usableSecurity = security\n .map(s => {\n return Object.keys(s).length === 1 ? s : false;\n })\n .filter(Boolean);\n\n const usableSecuritySchemes = usableSecurity.map(s => Object.keys(s)).reduce((prev, next) => prev.concat(next), []);\n const preparedSecurity = operation.prepareSecurity();\n\n // If we have two auth tokens present let's look for Basic Auth in their configuration.\n if (authKey.length >= 2) {\n // If this operation doesn't support HTTP Basic auth but we have two tokens, that's a paddlin.\n if (!('Basic' in preparedSecurity)) {\n throw new Error('Multiple auth tokens were supplied for this endpoint but only a single token is needed.');\n }\n\n // If we have two auth keys for Basic Auth but Basic isn't a usable security scheme (maybe it's\n // part of an AND or auth configuration -- which we don't support) then we need to error out.\n const schemes = preparedSecurity.Basic.filter(s => usableSecuritySchemes.includes(s._key));\n if (!schemes.length) {\n throw new Error(\n '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.',\n );\n }\n\n const scheme = schemes.shift() as KeyedSecuritySchemeObject;\n preparedAuth[scheme._key] = {\n user: authKey[0],\n pass: authKey.length === 2 ? authKey[1] : '',\n };\n\n return preparedAuth;\n }\n\n // If we know we don't need to use HTTP Basic auth because we have a username+password then we\n // can pick the first usable security scheme available and try to use that. This might not always\n // be the auth scheme that the user wants, but we don't have any other way for the user to tell\n // us what they want with the current `sdk.auth()` API.\n const usableScheme = usableSecuritySchemes[0];\n const schemes = Object.entries(preparedSecurity)\n .map(([, ps]) => ps.filter(s => usableScheme === s._key))\n .reduce((prev, next) => prev.concat(next), []);\n\n const scheme = schemes.shift() as KeyedSecuritySchemeObject;\n switch (scheme.type) {\n case 'http':\n if (scheme.scheme === 'basic') {\n preparedAuth[scheme._key] = {\n user: authKey[0],\n pass: authKey.length === 2 ? authKey[1] : '',\n };\n } else if (scheme.scheme === 'bearer') {\n preparedAuth[scheme._key] = authKey[0];\n }\n break;\n\n case 'oauth2':\n preparedAuth[scheme._key] = authKey[0];\n break;\n\n case 'apiKey':\n if (scheme.in === 'query' || scheme.in === 'header' || scheme.in === 'cookie') {\n preparedAuth[scheme._key] = authKey[0];\n }\n break;\n\n default:\n throw new Error(\n `Sorry, this API currently uses a security scheme, ${scheme.type}, which this library doesn't yet support.`,\n );\n }\n\n return preparedAuth;\n}\n","import type { ReadStream } from 'node:fs';\nimport type Operation from 'oas/operation';\nimport type { ParameterObject, SchemaObject } from 'oas/rmoas.types';\n\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport stream from 'node:stream';\n\nimport caseless from 'caseless';\nimport DatauriParser from 'datauri/parser.js';\nimport datauri from 'datauri/sync.js';\nimport { getStreamAsBuffer } from 'get-stream';\nimport lodashMerge from 'lodash.merge';\nimport removeUndefinedObjects from 'remove-undefined-objects';\n\nimport getJSONSchemaDefaults from './getJSONSchemaDefaults.js';\n\n// These headers are normally only defined by the OpenAPI definition but we allow the user to\n// manually supply them in their `metadata` parameter if they wish.\nconst specialHeaders = ['accept', 'authorization'];\n\n/**\n * Extract all available parameters from an operations Parameter Object into a digestable array\n * that we can use to apply to the request.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameterObject}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#parameterObject}\n */\nfunction digestParameters(parameters: ParameterObject[]): Record<string, ParameterObject> {\n return parameters.reduce((prev, param) => {\n if ('$ref' in param || 'allOf' in param || 'anyOf' in param || 'oneOf' in param) {\n throw new Error(\"The OpenAPI document for this operation wasn't dereferenced before processing.\");\n } else if (param.name in prev) {\n throw new Error(\n `The operation you are using has the same parameter, ${param.name}, spread across multiple entry points. We unfortunately can't handle this right now.`,\n );\n }\n\n return Object.assign(prev, { [param.name]: param });\n }, {});\n}\n\n// https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore#_isempty\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction isEmpty(obj: any) {\n return [Object, Array].includes((obj || {}).constructor) && !Object.entries(obj || {}).length;\n}\n\nfunction isObject(thing: unknown) {\n if (thing instanceof stream.Readable) {\n return false;\n }\n\n return typeof thing === 'object' && thing !== null && !Array.isArray(thing);\n}\n\nfunction isPrimitive(obj: unknown) {\n return obj === null || typeof obj === 'number' || typeof obj === 'string';\n}\n\nfunction merge(src: unknown, target: unknown) {\n if (Array.isArray(target)) {\n // @todo we need to add support for merging array defaults with array body/metadata arguments\n return target;\n } else if (!isObject(target)) {\n return target;\n }\n\n return lodashMerge(src, target);\n}\n\n/**\n * Ingest a file path or readable stream into a common object that we can later use to process it\n * into a parameters object for making an API request.\n *\n */\nfunction processFile(\n paramName: string | undefined,\n file: string | ReadStream,\n): Promise<{ base64?: string; buffer?: Buffer; filename: string; paramName?: string } | undefined> {\n if (typeof file === 'string') {\n // In order to support relative pathed files, we need to attempt to resolve them.\n const resolvedFile = path.resolve(file);\n\n return new Promise((resolve, reject) => {\n fs.stat(resolvedFile, async err => {\n if (err) {\n if (err.code === 'ENOENT') {\n // It's less than ideal for us to handle files that don't exist like this but because\n // `file` is a string it might actually be the full text contents of the file and not\n // actually a path.\n //\n // We also can't really regex to see if `file` *looks*` like a path because one should be\n // able to pass in a relative `owlbert.png` (instead of `./owlbert.png`) and though that\n // doesn't *look* like a path, it is one that should still work.\n return resolve(undefined);\n }\n\n return reject(err);\n }\n\n const fileMetadata = await datauri(resolvedFile);\n const payloadFilename = encodeURIComponent(path.basename(resolvedFile));\n\n return resolve({\n paramName,\n base64: fileMetadata?.content?.replace(';base64', `;name=${payloadFilename};base64`),\n filename: payloadFilename,\n buffer: fileMetadata.buffer,\n });\n });\n });\n } else if (file instanceof stream.Readable) {\n return getStreamAsBuffer(file).then(buffer => {\n const filePath = file.path as string;\n const parser = new DatauriParser();\n const base64 = parser.format(filePath, buffer).content;\n const payloadFilename = encodeURIComponent(path.basename(filePath));\n\n return {\n paramName,\n base64: base64?.replace(';base64', `;name=${payloadFilename};base64`),\n filename: payloadFilename,\n buffer,\n };\n });\n }\n\n return Promise.reject(\n new TypeError(\n paramName\n ? `The data supplied for the \\`${paramName}\\` request body parameter is not a file handler that we support.`\n : 'The data supplied for the request body payload is not a file handler that we support.',\n ),\n );\n}\n\n/**\n * With potentially supplied body and/or metadata we need to run through them against a given API\n * operation to see what's what and prepare any available parameters to be used in an API request\n * with `@readme/oas-to-har`.\n *\n */\nexport default async function prepareParams(operation: Operation, body?: unknown, metadata?: Record<string, unknown>) {\n let metadataIntersected = false;\n const digestedParameters = digestParameters(operation.getParameters());\n const jsonSchema = operation.getParametersAsJSONSchema();\n\n /**\n * It might be common for somebody to run `sdk.findPetsByStatus({ status: 'available' }, {})`, in\n * which case we want to filter out the second (metadata) parameter and treat the first parameter\n * as the metadata instead. If we don't do this, their supplied `status` metadata will be treated\n * as a body parameter, and because there's no `status` body parameter, and no supplied metadata\n * (because it's an empty object), the request won't send a payload.\n *\n * @see {@link https://github.com/readmeio/api/issues/449}\n */\n // eslint-disable-next-line no-param-reassign\n metadata = removeUndefinedObjects(metadata);\n\n if (!jsonSchema && (body !== undefined || metadata !== undefined)) {\n let throwNoParamsError = true;\n\n // If this operation doesn't have any parameters for us to transform to JSON Schema but they've\n // sent us either an `Accept` or `Authorization` header (or both) we should let them do that.\n // We should, however, only do this check for the `body` parameter as if they've sent this\n // request both `body` and `metadata` we can reject it outright as the operation won't have any\n // body data.\n if (body !== undefined) {\n if (typeof body === 'object' && body !== null && !Array.isArray(body)) {\n if (Object.keys(body).length <= 2) {\n const bodyParams = caseless(body);\n\n if (specialHeaders.some(header => bodyParams.has(header))) {\n throwNoParamsError = false;\n }\n }\n }\n }\n\n if (throwNoParamsError) {\n throw new Error(\n \"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.\",\n );\n }\n }\n\n const jsonSchemaDefaults = jsonSchema ? getJSONSchemaDefaults(jsonSchema) : {};\n\n const params: {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n body?: any;\n cookie?: Record<string, string | number | boolean>;\n files?: Record<string, Buffer>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n formData?: any;\n header?: Record<string, string | number | boolean>;\n path?: Record<string, string | number | boolean>;\n query?: Record<string, string | number | boolean>;\n server?: {\n selected: number;\n variables: Record<string, string | number>;\n };\n } = jsonSchemaDefaults;\n\n // If a body argument was supplied we need to do a bit of work to see if it's actually a body\n // argument or metadata because the library lets you supply either a body, metadata, or body with\n // metadata.\n if (typeof body !== 'undefined') {\n if (Array.isArray(body) || isPrimitive(body)) {\n // If the body param is an array or a primitive then we know it's absolutely a body because\n // metadata can only ever be undefined or an object.\n params.body = merge(params.body, body);\n } else if (typeof metadata === 'undefined') {\n // No metadata was explicitly provided so we need to analyze the body to determine if it's a\n // body or should be actually be treated as metadata.\n const headerParams = caseless({});\n Object.entries(digestedParameters).forEach(([paramName, param]) => {\n // Headers are sent case-insensitive so we need to make sure that we're properly\n // matching them when detecting what our incoming payload looks like.\n if (param.in === 'header') {\n headerParams.set(paramName, '');\n }\n });\n\n // `Accept` and `Authorization` headers can't be defined as normal parameters but we should\n // always allow the user to supply them if they wish.\n specialHeaders.forEach(header => {\n if (!headerParams.has(header)) {\n headerParams.set(header, '');\n }\n });\n\n const intersection = Object.keys(body as NonNullable<unknown>).filter(value => {\n if (Object.keys(digestedParameters).includes(value)) {\n return true;\n } else if (headerParams.has(value)) {\n return true;\n }\n\n return false;\n }).length;\n\n // If more than 25% of the body intersects with the parameters that we've got on hand, then\n // we should treat it as a metadata object and organize into parameters.\n if (intersection && intersection / Object.keys(body as NonNullable<unknown>).length > 0.25) {\n /* eslint-disable no-param-reassign */\n metadataIntersected = true;\n metadata = merge(params.body, body) as Record<string, unknown>;\n body = undefined;\n /* eslint-enable no-param-reassign */\n } else {\n // For all other cases, we should just treat the supplied body as a body.\n params.body = merge(params.body, body);\n }\n } else {\n // Body and metadata were both supplied.\n params.body = merge(params.body, body);\n }\n }\n\n if (!operation.hasRequestBody()) {\n // If this operation doesn't have any documented request body then we shouldn't be sending\n // anything.\n delete params.body;\n } else {\n if (!('body' in params)) params.body = {};\n\n // We need to retrieve the request body for this operation to search for any `binary` format\n // data that the user wants to send so we know what we need to prepare for the final API\n // request.\n const payloadJsonSchema = jsonSchema.find(js => js.type === 'body');\n if (payloadJsonSchema) {\n if (!params.files) params.files = {};\n\n const conversions = [];\n\n // @todo add support for `type: array`, `oneOf` and `anyOf`\n if (payloadJsonSchema.schema?.properties) {\n Object.entries(payloadJsonSchema.schema?.properties)\n .filter(([, schema]: [string, SchemaObject]) => schema?.format === 'binary')\n .filter(([prop]) => Object.keys(params.body).includes(prop))\n .forEach(([prop]) => {\n conversions.push(processFile(prop, params.body[prop]));\n });\n } else if (payloadJsonSchema.schema?.type === 'string') {\n if (payloadJsonSchema.schema?.format === 'binary') {\n conversions.push(processFile(undefined, params.body));\n }\n }\n\n await Promise.all(conversions)\n .then(fileMetadata => fileMetadata.filter(Boolean))\n .then(fm => {\n fm.forEach(fileMetadata => {\n if (!fileMetadata) {\n // If we don't have any metadata here it's because the file we have is likely\n // the full string content of the file so since we don't have any filenames to\n // work with we shouldn't do any additional handling to the `body` or `files`\n // parameters.\n return;\n }\n\n if (fileMetadata.paramName) {\n params.body[fileMetadata.paramName] = fileMetadata.base64;\n } else {\n params.body = fileMetadata.base64;\n }\n\n if (fileMetadata.buffer && params?.files) {\n params.files[fileMetadata.filename] = fileMetadata.buffer;\n }\n });\n });\n }\n }\n\n // Form data should be placed within `formData` instead of `body` for it to properly get picked\n // up by `fetch-har`.\n if (operation.isFormUrlEncoded()) {\n params.formData = merge(params.formData, params.body);\n delete params.body;\n }\n\n // Only spend time trying to organize metadata into parameters if we were able to digest\n // parameters out of the operation schema. If we couldn't digest anything, but metadata was\n // supplied then we wouldn't know how to send it in the request!\n if (typeof metadata !== 'undefined') {\n if (!('cookie' in params)) params.cookie = {};\n if (!('header' in params)) params.header = {};\n if (!('path' in params)) params.path = {};\n if (!('query' in params)) params.query = {};\n\n Object.entries(digestedParameters).forEach(([paramName, param]) => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let value: any;\n let metadataHeaderParam;\n if (typeof metadata === 'object' && !isEmpty(metadata)) {\n if (paramName in metadata) {\n value = metadata[paramName];\n metadataHeaderParam = paramName;\n } else if (param.in === 'header') {\n // Headers are sent case-insensitive so we need to make sure that we're properly\n // matching them when detecting what our incoming payload looks like.\n metadataHeaderParam = Object.keys(metadata).find(k => k.toLowerCase() === paramName.toLowerCase()) || '';\n value = metadata[metadataHeaderParam];\n }\n }\n\n if (value === undefined) {\n return;\n }\n\n /* eslint-disable no-param-reassign */\n switch (param.in) {\n case 'path':\n (params.path as NonNullable<typeof params.path>)[paramName] = value;\n if (metadata?.[paramName]) delete metadata[paramName];\n break;\n case 'query':\n (params.query as NonNullable<typeof params.query>)[paramName] = value;\n if (metadata?.[paramName]) delete metadata[paramName];\n break;\n case 'header':\n (params.header as NonNullable<typeof params.header>)[paramName.toLowerCase()] = value;\n if (metadataHeaderParam && metadata?.[metadataHeaderParam]) delete metadata[metadataHeaderParam];\n break;\n case 'cookie':\n (params.cookie as NonNullable<typeof params.cookie>)[paramName] = value;\n if (metadata?.[paramName]) delete metadata[paramName];\n break;\n default: // no-op\n }\n /* eslint-enable no-param-reassign */\n\n // Because a user might have sent just a metadata object, we want to make sure that we filter\n // out anything that they sent that is a parameter from also being sent as part of a form\n // data payload for `x-www-form-urlencoded` requests.\n if (metadataIntersected && operation.isFormUrlEncoded()) {\n if (paramName in params.formData) {\n delete params.formData[paramName];\n }\n }\n });\n\n // If there's any leftover metadata that hasn't been moved into form data for this request we\n // need to move it or else it'll get tossed.\n if (!isEmpty(metadata)) {\n if (typeof metadata === 'object') {\n // If the user supplied an `accept` or `authorization` header themselves we should allow it\n // through. Normally these headers are automatically handled by `@readme/oas-to-har` but in\n // the event that maybe the user wants to return XML for an API that normally returns JSON\n // or specify a custom auth header (maybe we can't handle their auth case right) this is the\n // only way with this library that they can do that.\n specialHeaders.forEach(headerName => {\n const headerParam = Object.keys(metadata || {}).find(m => m.toLowerCase() === headerName);\n if (headerParam) {\n // this if-statement below is a typeguard\n if (typeof metadata === 'object') {\n // this if-statement below is a typeguard\n if (typeof params.header === 'object') {\n params.header[headerName] = metadata[headerParam] as string;\n }\n // eslint-disable-next-line no-param-reassign\n delete metadata[headerParam];\n }\n }\n });\n }\n\n if (operation.isFormUrlEncoded()) {\n params.formData = merge(params.formData, metadata);\n } else {\n // Any other remaining unused metadata will be unused because we don't know where to place\n // it in the request.\n }\n }\n }\n\n (['body', 'cookie', 'files', 'formData', 'header', 'path', 'query'] as const).forEach((type: keyof typeof params) => {\n if (type in params && isEmpty(params[type])) {\n delete params[type];\n }\n });\n\n return params;\n}\n","import type Oas from 'oas';\n\nfunction stripTrailingSlash(url: string) {\n if (url[url.length - 1] === '/') {\n return url.slice(0, -1);\n }\n\n return url;\n}\n\n/**\n * With an SDK server config and an instance of OAS we should extract and prepare the server and\n * any server variables to be supplied to `@readme/oas-to-har`.\n *\n */\nexport default function prepareServer(spec: Oas, url: string, variables: Record<string, string | number> = {}) {\n let serverIdx;\n const sanitizedUrl = stripTrailingSlash(url);\n (spec.api.servers || []).forEach((server, i) => {\n if (server.url === sanitizedUrl) {\n serverIdx = i;\n }\n });\n\n // If we were able to find the passed in server in the OAS servers, we should use that! If we\n // couldn't and server variables were passed in we should try our best to handle that, otherwise\n // we should ignore the passed in server and use whever the default from the OAS is.\n if (serverIdx) {\n return {\n selected: serverIdx,\n variables,\n };\n } else if (Object.keys(variables).length) {\n // @todo we should run `oas.replaceUrl(url)` and pass that unto `@readme/oas-to-har`\n } else {\n const server = spec.splitVariables(url);\n if (server) {\n return {\n selected: server.selected,\n variables: server.variables,\n };\n }\n\n // @todo we should pass `url` directly into `@readme/oas-to-har` as the base URL\n }\n\n return false;\n}\n"]}
|