@roarkanalytics/sdk 0.1.0-alpha.1 → 0.1.0-alpha.3
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +16 -0
- package/LICENSE +1 -1
- package/README.md +48 -85
- package/_shims/MultipartBody.d.ts +9 -0
- package/_shims/MultipartBody.d.ts.map +1 -0
- package/_shims/MultipartBody.js +16 -0
- package/_shims/MultipartBody.js.map +1 -0
- package/_shims/MultipartBody.mjs +12 -0
- package/_shims/MultipartBody.mjs.map +1 -0
- package/_shims/README.md +46 -0
- package/_shims/auto/runtime-bun.d.ts +5 -0
- package/_shims/auto/runtime-bun.d.ts.map +1 -0
- package/{internal/utils.js → _shims/auto/runtime-bun.js} +5 -8
- package/_shims/auto/runtime-bun.js.map +1 -0
- package/_shims/auto/runtime-bun.mjs +2 -0
- package/_shims/auto/runtime-bun.mjs.map +1 -0
- package/_shims/auto/runtime-node.d.ts +5 -0
- package/_shims/auto/runtime-node.d.ts.map +1 -0
- package/_shims/auto/runtime-node.js +21 -0
- package/_shims/auto/runtime-node.js.map +1 -0
- package/_shims/auto/runtime-node.mjs +2 -0
- package/_shims/auto/runtime-node.mjs.map +1 -0
- package/_shims/auto/runtime.d.ts +5 -0
- package/_shims/auto/runtime.d.ts.map +1 -0
- package/_shims/auto/runtime.js +21 -0
- package/_shims/auto/runtime.js.map +1 -0
- package/_shims/auto/runtime.mjs +2 -0
- package/_shims/auto/runtime.mjs.map +1 -0
- package/_shims/auto/types-node.d.ts +5 -0
- package/_shims/auto/types-node.d.ts.map +1 -0
- package/_shims/auto/types-node.js +21 -0
- package/_shims/auto/types-node.js.map +1 -0
- package/_shims/auto/types-node.mjs +2 -0
- package/_shims/auto/types-node.mjs.map +1 -0
- package/_shims/auto/types.d.ts +101 -0
- package/_shims/auto/types.js +3 -0
- package/_shims/auto/types.mjs +3 -0
- package/_shims/bun-runtime.d.ts +6 -0
- package/_shims/bun-runtime.d.ts.map +1 -0
- package/_shims/bun-runtime.js +14 -0
- package/_shims/bun-runtime.js.map +1 -0
- package/_shims/bun-runtime.mjs +10 -0
- package/_shims/bun-runtime.mjs.map +1 -0
- package/_shims/index.d.ts +81 -0
- package/_shims/index.js +13 -0
- package/_shims/index.mjs +7 -0
- package/_shims/manual-types.d.ts +12 -0
- package/_shims/manual-types.js +3 -0
- package/_shims/manual-types.mjs +3 -0
- package/_shims/node-runtime.d.ts +3 -0
- package/_shims/node-runtime.d.ts.map +1 -0
- package/_shims/node-runtime.js +89 -0
- package/_shims/node-runtime.js.map +1 -0
- package/_shims/node-runtime.mjs +56 -0
- package/_shims/node-runtime.mjs.map +1 -0
- package/_shims/node-types.d.ts +42 -0
- package/_shims/node-types.js +3 -0
- package/_shims/node-types.mjs +3 -0
- package/_shims/registry.d.ts +37 -0
- package/_shims/registry.d.ts.map +1 -0
- package/_shims/registry.js +41 -0
- package/_shims/registry.js.map +1 -0
- package/_shims/registry.mjs +37 -0
- package/_shims/registry.mjs.map +1 -0
- package/_shims/web-runtime.d.ts +5 -0
- package/_shims/web-runtime.d.ts.map +1 -0
- package/_shims/web-runtime.js +78 -0
- package/_shims/web-runtime.js.map +1 -0
- package/_shims/web-runtime.mjs +71 -0
- package/_shims/web-runtime.mjs.map +1 -0
- package/_shims/web-types.d.ts +83 -0
- package/_shims/web-types.js +3 -0
- package/_shims/web-types.mjs +3 -0
- package/core.d.ts +241 -0
- package/core.d.ts.map +1 -0
- package/core.js +908 -0
- package/core.js.map +1 -0
- package/core.mjs +876 -0
- package/core.mjs.map +1 -0
- package/error.d.ts +3 -3
- package/error.d.ts.map +1 -1
- package/error.js +6 -6
- package/error.js.map +1 -1
- package/error.mjs +3 -3
- package/error.mjs.map +1 -1
- package/index.d.mts +109 -5
- package/index.d.ts +109 -5
- package/index.d.ts.map +1 -1
- package/index.js +103 -11
- package/index.js.map +1 -1
- package/index.mjs +77 -5
- package/index.mjs.map +1 -1
- package/package.json +66 -82
- package/resource.d.ts +3 -3
- package/resource.d.ts.map +1 -1
- package/resource.js.map +1 -1
- package/resource.mjs.map +1 -1
- package/resources/calls.d.ts +2 -3
- package/resources/calls.d.ts.map +1 -1
- package/resources/calls.js.map +1 -1
- package/resources/calls.mjs.map +1 -1
- package/resources/index.d.ts.map +1 -1
- package/shims/node.d.ts +30 -0
- package/shims/node.d.ts.map +1 -0
- package/shims/node.js +31 -0
- package/shims/node.js.map +1 -0
- package/shims/node.mjs +5 -0
- package/shims/node.mjs.map +1 -0
- package/shims/web.d.ts +26 -0
- package/shims/web.d.ts.map +1 -0
- package/shims/web.js +31 -0
- package/shims/web.js.map +1 -0
- package/shims/web.mjs +5 -0
- package/shims/web.mjs.map +1 -0
- package/src/_shims/MultipartBody.ts +9 -0
- package/src/_shims/README.md +46 -0
- package/src/_shims/auto/runtime-bun.ts +4 -0
- package/src/_shims/auto/runtime-node.ts +4 -0
- package/src/_shims/auto/runtime.ts +4 -0
- package/src/_shims/auto/types-node.ts +4 -0
- package/src/_shims/auto/types.d.ts +101 -0
- package/src/_shims/auto/types.js +3 -0
- package/src/_shims/auto/types.mjs +3 -0
- package/src/_shims/bun-runtime.ts +14 -0
- package/src/_shims/index.d.ts +81 -0
- package/src/_shims/index.js +13 -0
- package/src/_shims/index.mjs +7 -0
- package/src/_shims/manual-types.d.ts +12 -0
- package/src/_shims/manual-types.js +3 -0
- package/src/_shims/manual-types.mjs +3 -0
- package/src/_shims/node-runtime.ts +81 -0
- package/src/_shims/node-types.d.ts +42 -0
- package/src/_shims/node-types.js +3 -0
- package/src/_shims/node-types.mjs +3 -0
- package/src/_shims/registry.ts +67 -0
- package/src/_shims/web-runtime.ts +103 -0
- package/src/_shims/web-types.d.ts +83 -0
- package/src/_shims/web-types.js +3 -0
- package/src/_shims/web-types.mjs +3 -0
- package/src/core.ts +1200 -0
- package/src/error.ts +3 -3
- package/src/index.ts +172 -5
- package/src/resource.ts +3 -3
- package/src/resources/calls.ts +2 -3
- package/src/shims/node.ts +50 -0
- package/src/shims/web.ts +50 -0
- package/src/tsconfig.json +2 -2
- package/src/uploads.ts +255 -1
- package/src/version.ts +1 -1
- package/uploads.d.ts +74 -1
- package/uploads.d.ts.map +1 -1
- package/uploads.js +168 -3
- package/uploads.js.map +1 -1
- package/uploads.mjs +157 -1
- package/uploads.mjs.map +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
- package/api-promise.d.mts +0 -47
- package/api-promise.d.mts.map +0 -1
- package/api-promise.d.ts +0 -47
- package/api-promise.d.ts.map +0 -1
- package/api-promise.js +0 -84
- package/api-promise.js.map +0 -1
- package/api-promise.mjs +0 -80
- package/api-promise.mjs.map +0 -1
- package/client.d.mts +0 -186
- package/client.d.mts.map +0 -1
- package/client.d.ts +0 -186
- package/client.d.ts.map +0 -1
- package/client.js +0 -449
- package/client.js.map +0 -1
- package/client.mjs +0 -422
- package/client.mjs.map +0 -1
- package/error.d.mts +0 -47
- package/error.d.mts.map +0 -1
- package/index.d.mts.map +0 -1
- package/internal/builtin-types.d.mts +0 -65
- package/internal/builtin-types.d.mts.map +0 -1
- package/internal/builtin-types.d.ts +0 -65
- package/internal/builtin-types.d.ts.map +0 -1
- package/internal/builtin-types.js +0 -4
- package/internal/builtin-types.js.map +0 -1
- package/internal/builtin-types.mjs +0 -3
- package/internal/builtin-types.mjs.map +0 -1
- package/internal/detect-platform.d.mts +0 -15
- package/internal/detect-platform.d.mts.map +0 -1
- package/internal/detect-platform.d.ts +0 -15
- package/internal/detect-platform.d.ts.map +0 -1
- package/internal/detect-platform.js +0 -162
- package/internal/detect-platform.js.map +0 -1
- package/internal/detect-platform.mjs +0 -157
- package/internal/detect-platform.mjs.map +0 -1
- package/internal/errors.d.mts +0 -3
- package/internal/errors.d.mts.map +0 -1
- package/internal/errors.d.ts +0 -3
- package/internal/errors.d.ts.map +0 -1
- package/internal/errors.js +0 -26
- package/internal/errors.js.map +0 -1
- package/internal/errors.mjs +0 -21
- package/internal/errors.mjs.map +0 -1
- package/internal/headers.d.mts +0 -21
- package/internal/headers.d.mts.map +0 -1
- package/internal/headers.d.ts +0 -21
- package/internal/headers.d.ts.map +0 -1
- package/internal/headers.js +0 -77
- package/internal/headers.js.map +0 -1
- package/internal/headers.mjs +0 -72
- package/internal/headers.mjs.map +0 -1
- package/internal/parse.d.mts +0 -10
- package/internal/parse.d.mts.map +0 -1
- package/internal/parse.d.ts +0 -10
- package/internal/parse.d.ts.map +0 -1
- package/internal/parse.js +0 -28
- package/internal/parse.js.map +0 -1
- package/internal/parse.mjs +0 -24
- package/internal/parse.mjs.map +0 -1
- package/internal/polyfill/crypto.node.d.ts +0 -10
- package/internal/polyfill/crypto.node.js +0 -11
- package/internal/polyfill/crypto.node.mjs +0 -2
- package/internal/polyfill/file.node.d.ts +0 -9
- package/internal/polyfill/file.node.js +0 -17
- package/internal/polyfill/file.node.mjs +0 -9
- package/internal/request-options.d.mts +0 -34
- package/internal/request-options.d.mts.map +0 -1
- package/internal/request-options.d.ts +0 -34
- package/internal/request-options.d.ts.map +0 -1
- package/internal/request-options.js +0 -39
- package/internal/request-options.js.map +0 -1
- package/internal/request-options.mjs +0 -34
- package/internal/request-options.mjs.map +0 -1
- package/internal/shim-types.d.mts +0 -28
- package/internal/shim-types.d.ts +0 -28
- package/internal/shims.d.mts +0 -61
- package/internal/shims.d.mts.map +0 -1
- package/internal/shims.d.ts +0 -61
- package/internal/shims.d.ts.map +0 -1
- package/internal/shims.js +0 -101
- package/internal/shims.js.map +0 -1
- package/internal/shims.mjs +0 -92
- package/internal/shims.mjs.map +0 -1
- package/internal/types.d.mts +0 -68
- package/internal/types.d.mts.map +0 -1
- package/internal/types.d.ts +0 -68
- package/internal/types.d.ts.map +0 -1
- package/internal/types.js +0 -4
- package/internal/types.js.map +0 -1
- package/internal/types.mjs +0 -3
- package/internal/types.mjs.map +0 -1
- package/internal/uploads.d.mts +0 -73
- package/internal/uploads.d.mts.map +0 -1
- package/internal/uploads.d.ts +0 -73
- package/internal/uploads.d.ts.map +0 -1
- package/internal/uploads.js +0 -208
- package/internal/uploads.js.map +0 -1
- package/internal/uploads.mjs +0 -200
- package/internal/uploads.mjs.map +0 -1
- package/internal/utils/base64.d.mts +0 -3
- package/internal/utils/base64.d.mts.map +0 -1
- package/internal/utils/base64.d.ts +0 -3
- package/internal/utils/base64.d.ts.map +0 -1
- package/internal/utils/base64.js +0 -33
- package/internal/utils/base64.js.map +0 -1
- package/internal/utils/base64.mjs +0 -28
- package/internal/utils/base64.mjs.map +0 -1
- package/internal/utils/env.d.mts +0 -9
- package/internal/utils/env.d.mts.map +0 -1
- package/internal/utils/env.d.ts +0 -9
- package/internal/utils/env.d.ts.map +0 -1
- package/internal/utils/env.js +0 -22
- package/internal/utils/env.js.map +0 -1
- package/internal/utils/env.mjs +0 -18
- package/internal/utils/env.mjs.map +0 -1
- package/internal/utils/log.d.mts +0 -4
- package/internal/utils/log.d.mts.map +0 -1
- package/internal/utils/log.d.ts +0 -4
- package/internal/utils/log.d.ts.map +0 -1
- package/internal/utils/log.js +0 -47
- package/internal/utils/log.js.map +0 -1
- package/internal/utils/log.mjs +0 -43
- package/internal/utils/log.mjs.map +0 -1
- package/internal/utils/sleep.d.mts +0 -2
- package/internal/utils/sleep.d.mts.map +0 -1
- package/internal/utils/sleep.d.ts +0 -2
- package/internal/utils/sleep.d.ts.map +0 -1
- package/internal/utils/sleep.js +0 -7
- package/internal/utils/sleep.js.map +0 -1
- package/internal/utils/sleep.mjs +0 -3
- package/internal/utils/sleep.mjs.map +0 -1
- package/internal/utils/uuid.d.mts +0 -5
- package/internal/utils/uuid.d.mts.map +0 -1
- package/internal/utils/uuid.d.ts +0 -5
- package/internal/utils/uuid.d.ts.map +0 -1
- package/internal/utils/uuid.js +0 -15
- package/internal/utils/uuid.js.map +0 -1
- package/internal/utils/uuid.mjs +0 -11
- package/internal/utils/uuid.mjs.map +0 -1
- package/internal/utils/values.d.mts +0 -15
- package/internal/utils/values.d.mts.map +0 -1
- package/internal/utils/values.d.ts +0 -15
- package/internal/utils/values.d.ts.map +0 -1
- package/internal/utils/values.js +0 -100
- package/internal/utils/values.js.map +0 -1
- package/internal/utils/values.mjs +0 -84
- package/internal/utils/values.mjs.map +0 -1
- package/internal/utils.d.mts +0 -7
- package/internal/utils.d.mts.map +0 -1
- package/internal/utils.d.ts +0 -7
- package/internal/utils.d.ts.map +0 -1
- package/internal/utils.js.map +0 -1
- package/internal/utils.mjs +0 -8
- package/internal/utils.mjs.map +0 -1
- package/resource.d.mts +0 -6
- package/resource.d.mts.map +0 -1
- package/resources/calls.d.mts +0 -85
- package/resources/calls.d.mts.map +0 -1
- package/resources/index.d.mts +0 -2
- package/resources/index.d.mts.map +0 -1
- package/src/api-promise.ts +0 -92
- package/src/client.ts +0 -646
- package/src/internal/builtin-types.ts +0 -79
- package/src/internal/detect-platform.ts +0 -196
- package/src/internal/errors.ts +0 -22
- package/src/internal/headers.ts +0 -96
- package/src/internal/parse.ts +0 -41
- package/src/internal/polyfill/crypto.node.d.ts +0 -10
- package/src/internal/polyfill/crypto.node.js +0 -11
- package/src/internal/polyfill/crypto.node.mjs +0 -2
- package/src/internal/polyfill/file.node.d.ts +0 -9
- package/src/internal/polyfill/file.node.js +0 -17
- package/src/internal/polyfill/file.node.mjs +0 -9
- package/src/internal/request-options.ts +0 -67
- package/src/internal/shim-types.d.ts +0 -28
- package/src/internal/shims.ts +0 -145
- package/src/internal/types.ts +0 -98
- package/src/internal/uploads.ts +0 -307
- package/src/internal/utils/base64.ts +0 -37
- package/src/internal/utils/env.ts +0 -18
- package/src/internal/utils/log.ts +0 -49
- package/src/internal/utils/sleep.ts +0 -3
- package/src/internal/utils/uuid.ts +0 -13
- package/src/internal/utils/values.ts +0 -94
- package/src/internal/utils.ts +0 -8
- package/uploads.d.mts +0 -2
- package/uploads.d.mts.map +0 -1
- package/version.d.mts +0 -2
- package/version.d.mts.map +0 -1
package/internal/uploads.js
DELETED
@@ -1,208 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.createForm = exports.multipartFormRequestOptions = exports.maybeMultipartFormRequestOptions = exports.getBytes = exports.toFile = void 0;
|
4
|
-
const shims_1 = require("./shims.js");
|
5
|
-
require("./polyfill/file.node.js");
|
6
|
-
/**
|
7
|
-
* This check adds the arrayBuffer() method type because it is available and used at runtime
|
8
|
-
*/
|
9
|
-
const isBlobLike = (value) => value != null &&
|
10
|
-
typeof value === 'object' &&
|
11
|
-
typeof value.size === 'number' &&
|
12
|
-
typeof value.type === 'string' &&
|
13
|
-
typeof value.text === 'function' &&
|
14
|
-
typeof value.slice === 'function' &&
|
15
|
-
typeof value.arrayBuffer === 'function';
|
16
|
-
/**
|
17
|
-
* This check adds the arrayBuffer() method type because it is available and used at runtime
|
18
|
-
*/
|
19
|
-
const isFileLike = (value) => value != null &&
|
20
|
-
typeof value === 'object' &&
|
21
|
-
typeof value.name === 'string' &&
|
22
|
-
typeof value.lastModified === 'number' &&
|
23
|
-
isBlobLike(value);
|
24
|
-
const isResponseLike = (value) => value != null &&
|
25
|
-
typeof value === 'object' &&
|
26
|
-
typeof value.url === 'string' &&
|
27
|
-
typeof value.blob === 'function';
|
28
|
-
const isUploadable = (value) => {
|
29
|
-
return isFileLike(value) || isResponseLike(value) || (0, shims_1.isFsReadStreamLike)(value);
|
30
|
-
};
|
31
|
-
/**
|
32
|
-
* Construct a `File` instance. This is used to ensure a helpful error is thrown
|
33
|
-
* for environments that don't define a global `File` yet and so that we don't
|
34
|
-
* accidentally rely on a global `File` type in our annotations.
|
35
|
-
*/
|
36
|
-
function makeFile(fileBits, fileName, options) {
|
37
|
-
const File = globalThis.File;
|
38
|
-
if (typeof File === 'undefined') {
|
39
|
-
throw new Error('`File` is not defined as a global which is required for file uploads');
|
40
|
-
}
|
41
|
-
return new File(fileBits, fileName, options);
|
42
|
-
}
|
43
|
-
/**
|
44
|
-
* Helper for creating a {@link File} to pass to an SDK upload method from a variety of different data formats
|
45
|
-
* @param value the raw content of the file. Can be an {@link Uploadable}, {@link BlobLikePart}, or {@link AsyncIterable} of {@link BlobLikePart}s
|
46
|
-
* @param {string=} name the name of the file. If omitted, toFile will try to determine a file name from bits if possible
|
47
|
-
* @param {Object=} options additional properties
|
48
|
-
* @param {string=} options.type the MIME type of the content
|
49
|
-
* @param {number=} options.lastModified the last modified timestamp
|
50
|
-
* @returns a {@link File} with the given properties
|
51
|
-
*/
|
52
|
-
async function toFile(value, name, options) {
|
53
|
-
// If it's a promise, resolve it.
|
54
|
-
value = await value;
|
55
|
-
// If we've been given a `File` we don't need to do anything
|
56
|
-
if (isFileLike(value)) {
|
57
|
-
const File = globalThis.File;
|
58
|
-
if (File && value instanceof File) {
|
59
|
-
return value;
|
60
|
-
}
|
61
|
-
return makeFile([await value.arrayBuffer()], value.name);
|
62
|
-
}
|
63
|
-
if (isResponseLike(value)) {
|
64
|
-
const blob = await value.blob();
|
65
|
-
name || (name = new URL(value.url).pathname.split(/[\\/]/).pop() ?? 'unknown_file');
|
66
|
-
return makeFile(await getBytes(blob), name, options);
|
67
|
-
}
|
68
|
-
const parts = await getBytes(value);
|
69
|
-
name || (name = getName(value) ?? 'unknown_file');
|
70
|
-
if (!options?.type) {
|
71
|
-
const type = parts.find((part) => typeof part === 'object' && 'type' in part && part.type);
|
72
|
-
if (typeof type === 'string') {
|
73
|
-
options = { ...options, type };
|
74
|
-
}
|
75
|
-
}
|
76
|
-
return makeFile(parts, name, options);
|
77
|
-
}
|
78
|
-
exports.toFile = toFile;
|
79
|
-
async function getBytes(value) {
|
80
|
-
let parts = [];
|
81
|
-
if (typeof value === 'string' ||
|
82
|
-
ArrayBuffer.isView(value) || // includes Uint8Array, Buffer, etc.
|
83
|
-
value instanceof ArrayBuffer) {
|
84
|
-
parts.push(value);
|
85
|
-
}
|
86
|
-
else if (isBlobLike(value)) {
|
87
|
-
parts.push(value instanceof Blob ? value : await value.arrayBuffer());
|
88
|
-
}
|
89
|
-
else if (isAsyncIterableIterator(value) // includes Readable, ReadableStream, etc.
|
90
|
-
) {
|
91
|
-
for await (const chunk of value) {
|
92
|
-
parts.push(...(await getBytes(chunk))); // TODO, consider validating?
|
93
|
-
}
|
94
|
-
}
|
95
|
-
else {
|
96
|
-
const constructor = value?.constructor?.name;
|
97
|
-
throw new Error(`Unexpected data type: ${typeof value}${constructor ? `; constructor: ${constructor}` : ''}${propsForError(value)}`);
|
98
|
-
}
|
99
|
-
return parts;
|
100
|
-
}
|
101
|
-
exports.getBytes = getBytes;
|
102
|
-
function propsForError(value) {
|
103
|
-
if (typeof value !== 'object' || value === null)
|
104
|
-
return '';
|
105
|
-
const props = Object.getOwnPropertyNames(value);
|
106
|
-
return `; props: [${props.map((p) => `"${p}"`).join(', ')}]`;
|
107
|
-
}
|
108
|
-
function getName(value) {
|
109
|
-
return ((typeof value === 'object' &&
|
110
|
-
value !== null &&
|
111
|
-
(('name' in value && String(value.name)) ||
|
112
|
-
('filename' in value && String(value.filename)) ||
|
113
|
-
('path' in value && String(value.path).split(/[\\/]/).pop()))) ||
|
114
|
-
undefined);
|
115
|
-
}
|
116
|
-
const isAsyncIterableIterator = (value) => value != null && typeof value === 'object' && typeof value[Symbol.asyncIterator] === 'function';
|
117
|
-
/**
|
118
|
-
* Returns a multipart/form-data request if any part of the given request body contains a File / Blob value.
|
119
|
-
* Otherwise returns the request as is.
|
120
|
-
*/
|
121
|
-
const maybeMultipartFormRequestOptions = async (opts, fetch) => {
|
122
|
-
if (!hasUploadableValue(opts.body))
|
123
|
-
return opts;
|
124
|
-
return { ...opts, body: await (0, exports.createForm)(opts.body, fetch) };
|
125
|
-
};
|
126
|
-
exports.maybeMultipartFormRequestOptions = maybeMultipartFormRequestOptions;
|
127
|
-
const multipartFormRequestOptions = async (opts, fetch) => {
|
128
|
-
return { ...opts, body: await (0, exports.createForm)(opts.body, fetch) };
|
129
|
-
};
|
130
|
-
exports.multipartFormRequestOptions = multipartFormRequestOptions;
|
131
|
-
const supportsFormDataMap = new WeakMap();
|
132
|
-
/**
|
133
|
-
* node-fetch doesn't support the global FormData object in recent node versions. Instead of sending
|
134
|
-
* properly-encoded form data, it just stringifies the object, resulting in a request body of "[object FormData]".
|
135
|
-
* This function detects if the fetch function provided supports the global FormData object to avoid
|
136
|
-
* confusing error messages later on.
|
137
|
-
*/
|
138
|
-
function supportsFormData(fetchObject) {
|
139
|
-
const fetch = typeof fetchObject === 'function' ? fetchObject : fetchObject.fetch;
|
140
|
-
const cached = supportsFormDataMap.get(fetch);
|
141
|
-
if (cached)
|
142
|
-
return cached;
|
143
|
-
const promise = (async () => {
|
144
|
-
try {
|
145
|
-
const FetchResponse = ('Response' in fetch ?
|
146
|
-
fetch.Response
|
147
|
-
: (await fetch('data:,')).constructor);
|
148
|
-
const data = new FormData();
|
149
|
-
if (data.toString() === (await new FetchResponse(data).text())) {
|
150
|
-
return false;
|
151
|
-
}
|
152
|
-
return true;
|
153
|
-
}
|
154
|
-
catch {
|
155
|
-
// avoid false negatives
|
156
|
-
return true;
|
157
|
-
}
|
158
|
-
})();
|
159
|
-
supportsFormDataMap.set(fetch, promise);
|
160
|
-
return promise;
|
161
|
-
}
|
162
|
-
const createForm = async (body, fetch) => {
|
163
|
-
if (!(await supportsFormData(fetch))) {
|
164
|
-
throw new TypeError('The provided fetch function does not support file uploads with the current global FormData class.');
|
165
|
-
}
|
166
|
-
const form = new FormData();
|
167
|
-
await Promise.all(Object.entries(body || {}).map(([key, value]) => addFormValue(form, key, value)));
|
168
|
-
return form;
|
169
|
-
};
|
170
|
-
exports.createForm = createForm;
|
171
|
-
const hasUploadableValue = (value) => {
|
172
|
-
if (isUploadable(value))
|
173
|
-
return true;
|
174
|
-
if (Array.isArray(value))
|
175
|
-
return value.some(hasUploadableValue);
|
176
|
-
if (value && typeof value === 'object') {
|
177
|
-
for (const k in value) {
|
178
|
-
if (hasUploadableValue(value[k]))
|
179
|
-
return true;
|
180
|
-
}
|
181
|
-
}
|
182
|
-
return false;
|
183
|
-
};
|
184
|
-
const addFormValue = async (form, key, value) => {
|
185
|
-
if (value === undefined)
|
186
|
-
return;
|
187
|
-
if (value == null) {
|
188
|
-
throw new TypeError(`Received null for "${key}"; to pass null in FormData, you must use the string 'null'`);
|
189
|
-
}
|
190
|
-
// TODO: make nested formats configurable
|
191
|
-
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
|
192
|
-
form.append(key, String(value));
|
193
|
-
}
|
194
|
-
else if (isUploadable(value)) {
|
195
|
-
const file = await toFile(value);
|
196
|
-
form.append(key, file);
|
197
|
-
}
|
198
|
-
else if (Array.isArray(value)) {
|
199
|
-
await Promise.all(value.map((entry) => addFormValue(form, key + '[]', entry)));
|
200
|
-
}
|
201
|
-
else if (typeof value === 'object') {
|
202
|
-
await Promise.all(Object.entries(value).map(([name, prop]) => addFormValue(form, `${key}[${name}]`, prop)));
|
203
|
-
}
|
204
|
-
else {
|
205
|
-
throw new TypeError(`Invalid value given to form, expected a string, number, boolean, object, Array, File or Blob but got ${value} instead`);
|
206
|
-
}
|
207
|
-
};
|
208
|
-
//# sourceMappingURL=uploads.js.map
|
package/internal/uploads.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"uploads.js","sourceRoot":"","sources":["../src/internal/uploads.ts"],"names":[],"mappings":";;;AAEA,sCAAoE;AAEpE,mCAAiC;AA+BjC;;GAEG;AACH,MAAM,UAAU,GAAG,CAAC,KAAU,EAA+D,EAAE,CAC7F,KAAK,IAAI,IAAI;IACb,OAAO,KAAK,KAAK,QAAQ;IACzB,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ;IAC9B,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ;IAC9B,OAAO,KAAK,CAAC,IAAI,KAAK,UAAU;IAChC,OAAO,KAAK,CAAC,KAAK,KAAK,UAAU;IACjC,OAAO,KAAK,CAAC,WAAW,KAAK,UAAU,CAAC;AAgB1C;;GAEG;AACH,MAAM,UAAU,GAAG,CAAC,KAAU,EAA+D,EAAE,CAC7F,KAAK,IAAI,IAAI;IACb,OAAO,KAAK,KAAK,QAAQ;IACzB,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CAAC;KAChF;SAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QACpC,MAAM,OAAO,CAAC,GAAG,CACf,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI,IAAI,GAAG,EAAE,IAAI,CAAC,CAAC,CACzF,CAAC;KACH;SAAM;QACL,MAAM,IAAI,SAAS,CACjB,wGAAwG,KAAK,UAAU,CACxH,CAAC;KACH;AACH,CAAC,CAAC"}
|
package/internal/uploads.mjs
DELETED
@@ -1,200 +0,0 @@
|
|
1
|
-
import { isFsReadStreamLike } from "./shims.mjs";
|
2
|
-
import "./polyfill/file.node.mjs";
|
3
|
-
/**
|
4
|
-
* This check adds the arrayBuffer() method type because it is available and used at runtime
|
5
|
-
*/
|
6
|
-
const isBlobLike = (value) => value != null &&
|
7
|
-
typeof value === 'object' &&
|
8
|
-
typeof value.size === 'number' &&
|
9
|
-
typeof value.type === 'string' &&
|
10
|
-
typeof value.text === 'function' &&
|
11
|
-
typeof value.slice === 'function' &&
|
12
|
-
typeof value.arrayBuffer === 'function';
|
13
|
-
/**
|
14
|
-
* This check adds the arrayBuffer() method type because it is available and used at runtime
|
15
|
-
*/
|
16
|
-
const isFileLike = (value) => value != null &&
|
17
|
-
typeof value === 'object' &&
|
18
|
-
typeof value.name === 'string' &&
|
19
|
-
typeof value.lastModified === 'number' &&
|
20
|
-
isBlobLike(value);
|
21
|
-
const isResponseLike = (value) => value != null &&
|
22
|
-
typeof value === 'object' &&
|
23
|
-
typeof value.url === 'string' &&
|
24
|
-
typeof value.blob === 'function';
|
25
|
-
const isUploadable = (value) => {
|
26
|
-
return isFileLike(value) || isResponseLike(value) || isFsReadStreamLike(value);
|
27
|
-
};
|
28
|
-
/**
|
29
|
-
* Construct a `File` instance. This is used to ensure a helpful error is thrown
|
30
|
-
* for environments that don't define a global `File` yet and so that we don't
|
31
|
-
* accidentally rely on a global `File` type in our annotations.
|
32
|
-
*/
|
33
|
-
function makeFile(fileBits, fileName, options) {
|
34
|
-
const File = globalThis.File;
|
35
|
-
if (typeof File === 'undefined') {
|
36
|
-
throw new Error('`File` is not defined as a global which is required for file uploads');
|
37
|
-
}
|
38
|
-
return new File(fileBits, fileName, options);
|
39
|
-
}
|
40
|
-
/**
|
41
|
-
* Helper for creating a {@link File} to pass to an SDK upload method from a variety of different data formats
|
42
|
-
* @param value the raw content of the file. Can be an {@link Uploadable}, {@link BlobLikePart}, or {@link AsyncIterable} of {@link BlobLikePart}s
|
43
|
-
* @param {string=} name the name of the file. If omitted, toFile will try to determine a file name from bits if possible
|
44
|
-
* @param {Object=} options additional properties
|
45
|
-
* @param {string=} options.type the MIME type of the content
|
46
|
-
* @param {number=} options.lastModified the last modified timestamp
|
47
|
-
* @returns a {@link File} with the given properties
|
48
|
-
*/
|
49
|
-
export async function toFile(value, name, options) {
|
50
|
-
// If it's a promise, resolve it.
|
51
|
-
value = await value;
|
52
|
-
// If we've been given a `File` we don't need to do anything
|
53
|
-
if (isFileLike(value)) {
|
54
|
-
const File = globalThis.File;
|
55
|
-
if (File && value instanceof File) {
|
56
|
-
return value;
|
57
|
-
}
|
58
|
-
return makeFile([await value.arrayBuffer()], value.name);
|
59
|
-
}
|
60
|
-
if (isResponseLike(value)) {
|
61
|
-
const blob = await value.blob();
|
62
|
-
name || (name = new URL(value.url).pathname.split(/[\\/]/).pop() ?? 'unknown_file');
|
63
|
-
return makeFile(await getBytes(blob), name, options);
|
64
|
-
}
|
65
|
-
const parts = await getBytes(value);
|
66
|
-
name || (name = getName(value) ?? 'unknown_file');
|
67
|
-
if (!options?.type) {
|
68
|
-
const type = parts.find((part) => typeof part === 'object' && 'type' in part && part.type);
|
69
|
-
if (typeof type === 'string') {
|
70
|
-
options = { ...options, type };
|
71
|
-
}
|
72
|
-
}
|
73
|
-
return makeFile(parts, name, options);
|
74
|
-
}
|
75
|
-
export async function getBytes(value) {
|
76
|
-
let parts = [];
|
77
|
-
if (typeof value === 'string' ||
|
78
|
-
ArrayBuffer.isView(value) || // includes Uint8Array, Buffer, etc.
|
79
|
-
value instanceof ArrayBuffer) {
|
80
|
-
parts.push(value);
|
81
|
-
}
|
82
|
-
else if (isBlobLike(value)) {
|
83
|
-
parts.push(value instanceof Blob ? value : await value.arrayBuffer());
|
84
|
-
}
|
85
|
-
else if (isAsyncIterableIterator(value) // includes Readable, ReadableStream, etc.
|
86
|
-
) {
|
87
|
-
for await (const chunk of value) {
|
88
|
-
parts.push(...(await getBytes(chunk))); // TODO, consider validating?
|
89
|
-
}
|
90
|
-
}
|
91
|
-
else {
|
92
|
-
const constructor = value?.constructor?.name;
|
93
|
-
throw new Error(`Unexpected data type: ${typeof value}${constructor ? `; constructor: ${constructor}` : ''}${propsForError(value)}`);
|
94
|
-
}
|
95
|
-
return parts;
|
96
|
-
}
|
97
|
-
function propsForError(value) {
|
98
|
-
if (typeof value !== 'object' || value === null)
|
99
|
-
return '';
|
100
|
-
const props = Object.getOwnPropertyNames(value);
|
101
|
-
return `; props: [${props.map((p) => `"${p}"`).join(', ')}]`;
|
102
|
-
}
|
103
|
-
function getName(value) {
|
104
|
-
return ((typeof value === 'object' &&
|
105
|
-
value !== null &&
|
106
|
-
(('name' in value && String(value.name)) ||
|
107
|
-
('filename' in value && String(value.filename)) ||
|
108
|
-
('path' in value && String(value.path).split(/[\\/]/).pop()))) ||
|
109
|
-
undefined);
|
110
|
-
}
|
111
|
-
const isAsyncIterableIterator = (value) => value != null && typeof value === 'object' && typeof value[Symbol.asyncIterator] === 'function';
|
112
|
-
/**
|
113
|
-
* Returns a multipart/form-data request if any part of the given request body contains a File / Blob value.
|
114
|
-
* Otherwise returns the request as is.
|
115
|
-
*/
|
116
|
-
export const maybeMultipartFormRequestOptions = async (opts, fetch) => {
|
117
|
-
if (!hasUploadableValue(opts.body))
|
118
|
-
return opts;
|
119
|
-
return { ...opts, body: await createForm(opts.body, fetch) };
|
120
|
-
};
|
121
|
-
export const multipartFormRequestOptions = async (opts, fetch) => {
|
122
|
-
return { ...opts, body: await createForm(opts.body, fetch) };
|
123
|
-
};
|
124
|
-
const supportsFormDataMap = new WeakMap();
|
125
|
-
/**
|
126
|
-
* node-fetch doesn't support the global FormData object in recent node versions. Instead of sending
|
127
|
-
* properly-encoded form data, it just stringifies the object, resulting in a request body of "[object FormData]".
|
128
|
-
* This function detects if the fetch function provided supports the global FormData object to avoid
|
129
|
-
* confusing error messages later on.
|
130
|
-
*/
|
131
|
-
function supportsFormData(fetchObject) {
|
132
|
-
const fetch = typeof fetchObject === 'function' ? fetchObject : fetchObject.fetch;
|
133
|
-
const cached = supportsFormDataMap.get(fetch);
|
134
|
-
if (cached)
|
135
|
-
return cached;
|
136
|
-
const promise = (async () => {
|
137
|
-
try {
|
138
|
-
const FetchResponse = ('Response' in fetch ?
|
139
|
-
fetch.Response
|
140
|
-
: (await fetch('data:,')).constructor);
|
141
|
-
const data = new FormData();
|
142
|
-
if (data.toString() === (await new FetchResponse(data).text())) {
|
143
|
-
return false;
|
144
|
-
}
|
145
|
-
return true;
|
146
|
-
}
|
147
|
-
catch {
|
148
|
-
// avoid false negatives
|
149
|
-
return true;
|
150
|
-
}
|
151
|
-
})();
|
152
|
-
supportsFormDataMap.set(fetch, promise);
|
153
|
-
return promise;
|
154
|
-
}
|
155
|
-
export const createForm = async (body, fetch) => {
|
156
|
-
if (!(await supportsFormData(fetch))) {
|
157
|
-
throw new TypeError('The provided fetch function does not support file uploads with the current global FormData class.');
|
158
|
-
}
|
159
|
-
const form = new FormData();
|
160
|
-
await Promise.all(Object.entries(body || {}).map(([key, value]) => addFormValue(form, key, value)));
|
161
|
-
return form;
|
162
|
-
};
|
163
|
-
const hasUploadableValue = (value) => {
|
164
|
-
if (isUploadable(value))
|
165
|
-
return true;
|
166
|
-
if (Array.isArray(value))
|
167
|
-
return value.some(hasUploadableValue);
|
168
|
-
if (value && typeof value === 'object') {
|
169
|
-
for (const k in value) {
|
170
|
-
if (hasUploadableValue(value[k]))
|
171
|
-
return true;
|
172
|
-
}
|
173
|
-
}
|
174
|
-
return false;
|
175
|
-
};
|
176
|
-
const addFormValue = async (form, key, value) => {
|
177
|
-
if (value === undefined)
|
178
|
-
return;
|
179
|
-
if (value == null) {
|
180
|
-
throw new TypeError(`Received null for "${key}"; to pass null in FormData, you must use the string 'null'`);
|
181
|
-
}
|
182
|
-
// TODO: make nested formats configurable
|
183
|
-
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
|
184
|
-
form.append(key, String(value));
|
185
|
-
}
|
186
|
-
else if (isUploadable(value)) {
|
187
|
-
const file = await toFile(value);
|
188
|
-
form.append(key, file);
|
189
|
-
}
|
190
|
-
else if (Array.isArray(value)) {
|
191
|
-
await Promise.all(value.map((entry) => addFormValue(form, key + '[]', entry)));
|
192
|
-
}
|
193
|
-
else if (typeof value === 'object') {
|
194
|
-
await Promise.all(Object.entries(value).map(([name, prop]) => addFormValue(form, `${key}[${name}]`, prop)));
|
195
|
-
}
|
196
|
-
else {
|
197
|
-
throw new TypeError(`Invalid value given to form, expected a string, number, boolean, object, Array, File or Blob but got ${value} instead`);
|
198
|
-
}
|
199
|
-
};
|
200
|
-
//# sourceMappingURL=uploads.mjs.map
|
package/internal/uploads.mjs.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"uploads.mjs","sourceRoot":"","sources":["../src/internal/uploads.ts"],"names":[],"mappings":"OAEO,EAAE,kBAAkB,EAAyB;;AAiCpD;;GAEG;AACH,MAAM,UAAU,GAAG,CAAC,KAAU,EAA+D,EAAE,CAC7F,KAAK,IAAI,IAAI;IACb,OAAO,KAAK,KAAK,QAAQ;IACzB,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ;IAC9B,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ;IAC9B,OAAO,KAAK,CAAC,IAAI,KAAK,UAAU;IAChC,OAAO,KAAK,C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,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;KAChF;SAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QACpC,MAAM,OAAO,CAAC,GAAG,CACf,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI,IAAI,GAAG,EAAE,IAAI,CAAC,CAAC,CACzF,CAAC;KACH;SAAM;QACL,MAAM,IAAI,SAAS,CACjB,wGAAwG,KAAK,UAAU,CACxH,CAAC;KACH;AACH,CAAC,CAAC"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"base64.d.mts","sourceRoot":"","sources":["../../src/internal/utils/base64.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,QAAQ,SAAU,MAAM,GAAG,UAAU,GAAG,IAAI,GAAG,SAAS,KAAG,MAgBvE,CAAC;AAEF,eAAO,MAAM,UAAU,QAAS,MAAM,KAAG,UAcxC,CAAC"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"base64.d.ts","sourceRoot":"","sources":["../../src/internal/utils/base64.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,QAAQ,SAAU,MAAM,GAAG,UAAU,GAAG,IAAI,GAAG,SAAS,KAAG,MAgBvE,CAAC;AAEF,eAAO,MAAM,UAAU,QAAS,MAAM,KAAG,UAcxC,CAAC"}
|
package/internal/utils/base64.js
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
-
exports.fromBase64 = exports.toBase64 = void 0;
|
5
|
-
const error_1 = require("../../error.js");
|
6
|
-
const toBase64 = (data) => {
|
7
|
-
if (!data)
|
8
|
-
return '';
|
9
|
-
if (typeof data === 'string') {
|
10
|
-
data = new globalThis.TextEncoder().encode(data);
|
11
|
-
}
|
12
|
-
if (typeof globalThis.Buffer !== 'undefined') {
|
13
|
-
return globalThis.Buffer.from(data).toString('base64');
|
14
|
-
}
|
15
|
-
if (typeof btoa !== 'undefined') {
|
16
|
-
return btoa(String.fromCharCode.apply(null, data));
|
17
|
-
}
|
18
|
-
throw new error_1.PetstoreError('Cannot generate base64 string; Expected `Buffer` or `btoa` to be defined');
|
19
|
-
};
|
20
|
-
exports.toBase64 = toBase64;
|
21
|
-
const fromBase64 = (str) => {
|
22
|
-
if (typeof globalThis.Buffer !== 'undefined') {
|
23
|
-
return new Uint8Array(globalThis.Buffer.from(str, 'base64'));
|
24
|
-
}
|
25
|
-
if (typeof atob !== 'undefined') {
|
26
|
-
return new Uint8Array(atob(str)
|
27
|
-
.split('')
|
28
|
-
.map((c) => c.charCodeAt(0)));
|
29
|
-
}
|
30
|
-
throw new error_1.PetstoreError('Cannot decode base64 string; Expected `Buffer` or `atob` to be defined');
|
31
|
-
};
|
32
|
-
exports.fromBase64 = fromBase64;
|
33
|
-
//# sourceMappingURL=base64.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"base64.js","sourceRoot":"","sources":["../../src/internal/utils/base64.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;AAEtF,0CAA4C;AAErC,MAAM,QAAQ,GAAG,CAAC,IAA4C,EAAU,EAAE;IAC/E,IAAI,CAAC,IAAI;QAAE,OAAO,EAAE,CAAC;IAErB,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QAC5B,IAAI,GAAG,IAAK,UAAkB,CAAC,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;KAC3D;IAED,IAAI,OAAQ,UAAkB,CAAC,MAAM,KAAK,WAAW,EAAE;QACrD,OAAQ,UAAkB,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;KACjE;IAED,IAAI,OAAO,IAAI,KAAK,WAAW,EAAE;QAC/B,OAAO,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,IAAI,EAAE,IAAW,CAAC,CAAC,CAAC;KAC3D;IAED,MAAM,IAAI,qBAAa,CAAC,0EAA0E,CAAC,CAAC;AACtG,CAAC,CAAC;AAhBW,QAAA,QAAQ,YAgBnB;AAEK,MAAM,UAAU,GAAG,CAAC,GAAW,EAAc,EAAE;IACpD,IAAI,OAAQ,UAAkB,CAAC,MAAM,KAAK,WAAW,EAAE;QACrD,OAAO,IAAI,UAAU,CAAE,UAAkB,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC;KACvE;IAED,IAAI,OAAO,IAAI,KAAK,WAAW,EAAE;QAC/B,OAAO,IAAI,UAAU,CACnB,IAAI,CAAC,GAAG,CAAC;aACN,KAAK,CAAC,EAAE,CAAC;aACT,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAC/B,CAAC;KACH;IAED,MAAM,IAAI,qBAAa,CAAC,wEAAwE,CAAC,CAAC;AACpG,CAAC,CAAC;AAdW,QAAA,UAAU,cAcrB"}
|
@@ -1,28 +0,0 @@
|
|
1
|
-
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
2
|
-
import { PetstoreError } from "../../error.mjs";
|
3
|
-
export const toBase64 = (data) => {
|
4
|
-
if (!data)
|
5
|
-
return '';
|
6
|
-
if (typeof data === 'string') {
|
7
|
-
data = new globalThis.TextEncoder().encode(data);
|
8
|
-
}
|
9
|
-
if (typeof globalThis.Buffer !== 'undefined') {
|
10
|
-
return globalThis.Buffer.from(data).toString('base64');
|
11
|
-
}
|
12
|
-
if (typeof btoa !== 'undefined') {
|
13
|
-
return btoa(String.fromCharCode.apply(null, data));
|
14
|
-
}
|
15
|
-
throw new PetstoreError('Cannot generate base64 string; Expected `Buffer` or `btoa` to be defined');
|
16
|
-
};
|
17
|
-
export const fromBase64 = (str) => {
|
18
|
-
if (typeof globalThis.Buffer !== 'undefined') {
|
19
|
-
return new Uint8Array(globalThis.Buffer.from(str, 'base64'));
|
20
|
-
}
|
21
|
-
if (typeof atob !== 'undefined') {
|
22
|
-
return new Uint8Array(atob(str)
|
23
|
-
.split('')
|
24
|
-
.map((c) => c.charCodeAt(0)));
|
25
|
-
}
|
26
|
-
throw new PetstoreError('Cannot decode base64 string; Expected `Buffer` or `atob` to be defined');
|
27
|
-
};
|
28
|
-
//# sourceMappingURL=base64.mjs.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"base64.mjs","sourceRoot":"","sources":["../../src/internal/utils/base64.ts"],"names":[],"mappings":"AAAA,sFAAsF;OAE/E,EAAE,aAAa,EAAE;AAExB,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,IAA4C,EAAU,EAAE;IAC/E,IAAI,CAAC,IAAI;QAAE,OAAO,EAAE,CAAC;IAErB,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QAC5B,IAAI,GAAG,IAAK,UAAkB,CAAC,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;KAC3D;IAED,IAAI,OAAQ,UAAkB,CAAC,MAAM,KAAK,WAAW,EAAE;QACrD,OAAQ,UAAkB,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;KACjE;IAED,IAAI,OAAO,IAAI,KAAK,WAAW,EAAE;QAC/B,OAAO,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,IAAI,EAAE,IAAW,CAAC,CAAC,CAAC;KAC3D;IAED,MAAM,IAAI,aAAa,CAAC,0EAA0E,CAAC,CAAC;AACtG,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,GAAW,EAAc,EAAE;IACpD,IAAI,OAAQ,UAAkB,CAAC,MAAM,KAAK,WAAW,EAAE;QACrD,OAAO,IAAI,UAAU,CAAE,UAAkB,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC;KACvE;IAED,IAAI,OAAO,IAAI,KAAK,WAAW,EAAE;QAC/B,OAAO,IAAI,UAAU,CACnB,IAAI,CAAC,GAAG,CAAC;aACN,KAAK,CAAC,EAAE,CAAC;aACT,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAC/B,CAAC;KACH;IAED,MAAM,IAAI,aAAa,CAAC,wEAAwE,CAAC,CAAC;AACpG,CAAC,CAAC"}
|
package/internal/utils/env.d.mts
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Read an environment variable.
|
3
|
-
*
|
4
|
-
* Trims beginning and trailing whitespace.
|
5
|
-
*
|
6
|
-
* Will return undefined if the environment variable doesn't exist or cannot be accessed.
|
7
|
-
*/
|
8
|
-
export declare const readEnv: (env: string) => string | undefined;
|
9
|
-
//# sourceMappingURL=env.d.mts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"env.d.mts","sourceRoot":"","sources":["../../src/internal/utils/env.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,eAAO,MAAM,OAAO,QAAS,MAAM,KAAG,MAAM,GAAG,SAQ9C,CAAC"}
|
package/internal/utils/env.d.ts
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Read an environment variable.
|
3
|
-
*
|
4
|
-
* Trims beginning and trailing whitespace.
|
5
|
-
*
|
6
|
-
* Will return undefined if the environment variable doesn't exist or cannot be accessed.
|
7
|
-
*/
|
8
|
-
export declare const readEnv: (env: string) => string | undefined;
|
9
|
-
//# sourceMappingURL=env.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../src/internal/utils/env.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,eAAO,MAAM,OAAO,QAAS,MAAM,KAAG,MAAM,GAAG,SAQ9C,CAAC"}
|
package/internal/utils/env.js
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
-
exports.readEnv = void 0;
|
5
|
-
/**
|
6
|
-
* Read an environment variable.
|
7
|
-
*
|
8
|
-
* Trims beginning and trailing whitespace.
|
9
|
-
*
|
10
|
-
* Will return undefined if the environment variable doesn't exist or cannot be accessed.
|
11
|
-
*/
|
12
|
-
const readEnv = (env) => {
|
13
|
-
if (typeof globalThis.process !== 'undefined') {
|
14
|
-
return globalThis.process.env?.[env]?.trim() ?? undefined;
|
15
|
-
}
|
16
|
-
if (typeof globalThis.Deno !== 'undefined') {
|
17
|
-
return globalThis.Deno.env?.get?.(env)?.trim();
|
18
|
-
}
|
19
|
-
return undefined;
|
20
|
-
};
|
21
|
-
exports.readEnv = readEnv;
|
22
|
-
//# sourceMappingURL=env.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"env.js","sourceRoot":"","sources":["../../src/internal/utils/env.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;AAEtF;;;;;;GAMG;AACI,MAAM,OAAO,GAAG,CAAC,GAAW,EAAsB,EAAE;IACzD,IAAI,OAAQ,UAAkB,CAAC,OAAO,KAAK,WAAW,EAAE;QACtD,OAAQ,UAAkB,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,IAAI,SAAS,CAAC;KACpE;IACD,IAAI,OAAQ,UAAkB,CAAC,IAAI,KAAK,WAAW,EAAE;QACnD,OAAQ,UAAkB,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,CAAC;KACzD;IACD,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AARW,QAAA,OAAO,WAQlB"}
|
package/internal/utils/env.mjs
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
2
|
-
/**
|
3
|
-
* Read an environment variable.
|
4
|
-
*
|
5
|
-
* Trims beginning and trailing whitespace.
|
6
|
-
*
|
7
|
-
* Will return undefined if the environment variable doesn't exist or cannot be accessed.
|
8
|
-
*/
|
9
|
-
export const readEnv = (env) => {
|
10
|
-
if (typeof globalThis.process !== 'undefined') {
|
11
|
-
return globalThis.process.env?.[env]?.trim() ?? undefined;
|
12
|
-
}
|
13
|
-
if (typeof globalThis.Deno !== 'undefined') {
|
14
|
-
return globalThis.Deno.env?.get?.(env)?.trim();
|
15
|
-
}
|
16
|
-
return undefined;
|
17
|
-
};
|
18
|
-
//# sourceMappingURL=env.mjs.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"env.mjs","sourceRoot":"","sources":["../../src/internal/utils/env.ts"],"names":[],"mappings":"AAAA,sFAAsF;AAEtF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,GAAW,EAAsB,EAAE;IACzD,IAAI,OAAQ,UAAkB,CAAC,OAAO,KAAK,WAAW,EAAE;QACtD,OAAQ,UAAkB,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,IAAI,SAAS,CAAC;KACpE;IACD,IAAI,OAAQ,UAAkB,CAAC,IAAI,KAAK,WAAW,EAAE;QACnD,OAAQ,UAAkB,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,CAAC;KACzD;IACD,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC"}
|
package/internal/utils/log.d.mts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"log.d.mts","sourceRoot":"","sources":["../../src/internal/utils/log.ts"],"names":[],"mappings":"OAEO,KAAK,EAAY,MAAM,EAAE;OACzB,EAAE,KAAK,QAAQ,EAAE;AAyBxB,wBAAgB,MAAM,CAAC,MAAM,EAAE,QAAQ,GAAG,MAAM,CAoB/C"}
|
package/internal/utils/log.d.ts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../../src/internal/utils/log.ts"],"names":[],"mappings":"OAEO,KAAK,EAAY,MAAM,EAAE;OACzB,EAAE,KAAK,QAAQ,EAAE;AAyBxB,wBAAgB,MAAM,CAAC,MAAM,EAAE,QAAQ,GAAG,MAAM,CAoB/C"}
|