@roarkanalytics/sdk 2.20.0 → 2.21.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/CHANGELOG.md +16 -0
- package/README.md +83 -45
- package/api-promise.d.mts +47 -0
- package/api-promise.d.mts.map +1 -0
- package/api-promise.d.ts +47 -0
- package/api-promise.d.ts.map +1 -0
- package/api-promise.js +84 -0
- package/api-promise.js.map +1 -0
- package/api-promise.mjs +80 -0
- package/api-promise.mjs.map +1 -0
- package/client.d.mts +201 -0
- package/client.d.mts.map +1 -0
- package/client.d.ts +201 -0
- package/client.d.ts.map +1 -0
- package/client.js +454 -0
- package/client.js.map +1 -0
- package/client.mjs +427 -0
- package/client.mjs.map +1 -0
- package/error.d.mts +47 -0
- package/error.d.mts.map +1 -0
- package/error.d.ts +1 -1
- package/error.d.ts.map +1 -1
- package/error.js +2 -2
- package/error.js.map +1 -1
- package/error.mjs +1 -1
- package/error.mjs.map +1 -1
- package/index.d.mts +4 -130
- package/index.d.mts.map +1 -0
- package/index.d.ts +4 -130
- package/index.d.ts.map +1 -1
- package/index.js +10 -128
- package/index.js.map +1 -1
- package/index.mjs +4 -102
- package/index.mjs.map +1 -1
- package/internal/builtin-types.d.mts +65 -0
- package/internal/builtin-types.d.mts.map +1 -0
- package/internal/builtin-types.d.ts +65 -0
- package/internal/builtin-types.d.ts.map +1 -0
- package/internal/builtin-types.js +4 -0
- package/internal/builtin-types.js.map +1 -0
- package/internal/builtin-types.mjs +3 -0
- package/internal/builtin-types.mjs.map +1 -0
- package/internal/detect-platform.d.mts +15 -0
- package/internal/detect-platform.d.mts.map +1 -0
- package/internal/detect-platform.d.ts +15 -0
- package/internal/detect-platform.d.ts.map +1 -0
- package/internal/detect-platform.js +162 -0
- package/internal/detect-platform.js.map +1 -0
- package/internal/detect-platform.mjs +157 -0
- package/internal/detect-platform.mjs.map +1 -0
- package/internal/errors.d.mts +3 -0
- package/internal/errors.d.mts.map +1 -0
- package/internal/errors.d.ts +3 -0
- package/internal/errors.d.ts.map +1 -0
- package/internal/errors.js +26 -0
- package/internal/errors.js.map +1 -0
- package/internal/errors.mjs +21 -0
- package/internal/errors.mjs.map +1 -0
- package/internal/headers.d.mts +21 -0
- package/internal/headers.d.mts.map +1 -0
- package/internal/headers.d.ts +21 -0
- package/internal/headers.d.ts.map +1 -0
- package/internal/headers.js +77 -0
- package/internal/headers.js.map +1 -0
- package/internal/headers.mjs +72 -0
- package/internal/headers.mjs.map +1 -0
- package/internal/parse.d.mts +10 -0
- package/internal/parse.d.mts.map +1 -0
- package/internal/parse.d.ts +10 -0
- package/internal/parse.d.ts.map +1 -0
- package/internal/parse.js +28 -0
- package/internal/parse.js.map +1 -0
- package/internal/parse.mjs +24 -0
- package/internal/parse.mjs.map +1 -0
- package/internal/polyfill/crypto.node.d.ts +10 -0
- package/internal/polyfill/crypto.node.js +11 -0
- package/internal/polyfill/crypto.node.mjs +2 -0
- package/internal/polyfill/file.node.d.ts +9 -0
- package/internal/polyfill/file.node.js +17 -0
- package/internal/polyfill/file.node.mjs +9 -0
- package/internal/qs/formats.d.mts +6 -0
- package/internal/qs/formats.d.mts.map +1 -0
- package/internal/qs/formats.d.ts.map +1 -1
- package/internal/qs/index.d.mts +10 -0
- package/internal/qs/index.d.mts.map +1 -0
- package/internal/qs/index.d.ts.map +1 -1
- package/internal/qs/stringify.d.mts +3 -0
- package/internal/qs/stringify.d.mts.map +1 -0
- package/internal/qs/stringify.d.ts.map +1 -1
- package/internal/qs/types.d.mts +57 -0
- package/internal/qs/types.d.mts.map +1 -0
- package/internal/qs/utils.d.mts +14 -0
- package/internal/qs/utils.d.mts.map +1 -0
- package/internal/qs/utils.d.ts.map +1 -1
- package/internal/request-options.d.mts +34 -0
- package/internal/request-options.d.mts.map +1 -0
- package/internal/request-options.d.ts +34 -0
- package/internal/request-options.d.ts.map +1 -0
- package/internal/request-options.js +39 -0
- package/internal/request-options.js.map +1 -0
- package/internal/request-options.mjs +34 -0
- package/internal/request-options.mjs.map +1 -0
- package/internal/shim-types.d.mts +28 -0
- package/internal/shim-types.d.ts +28 -0
- package/internal/shims.d.mts +61 -0
- package/internal/shims.d.mts.map +1 -0
- package/internal/shims.d.ts +61 -0
- package/internal/shims.d.ts.map +1 -0
- package/internal/shims.js +101 -0
- package/internal/shims.js.map +1 -0
- package/internal/shims.mjs +92 -0
- package/internal/shims.mjs.map +1 -0
- package/internal/types.d.mts +68 -0
- package/internal/types.d.mts.map +1 -0
- package/internal/types.d.ts +68 -0
- package/internal/types.d.ts.map +1 -0
- package/internal/types.js +4 -0
- package/internal/types.js.map +1 -0
- package/internal/types.mjs +3 -0
- package/internal/types.mjs.map +1 -0
- package/internal/uploads.d.mts +73 -0
- package/internal/uploads.d.mts.map +1 -0
- package/internal/uploads.d.ts +73 -0
- package/internal/uploads.d.ts.map +1 -0
- package/internal/uploads.js +208 -0
- package/internal/uploads.js.map +1 -0
- package/internal/uploads.mjs +200 -0
- package/internal/uploads.mjs.map +1 -0
- package/internal/utils/base64.d.mts +3 -0
- package/internal/utils/base64.d.mts.map +1 -0
- package/internal/utils/base64.d.ts +3 -0
- package/internal/utils/base64.d.ts.map +1 -0
- package/internal/utils/base64.js +33 -0
- package/internal/utils/base64.js.map +1 -0
- package/internal/utils/base64.mjs +28 -0
- package/internal/utils/base64.mjs.map +1 -0
- package/internal/utils/env.d.mts +9 -0
- package/internal/utils/env.d.mts.map +1 -0
- package/internal/utils/env.d.ts +9 -0
- package/internal/utils/env.d.ts.map +1 -0
- package/internal/utils/env.js +22 -0
- package/internal/utils/env.js.map +1 -0
- package/internal/utils/env.mjs +18 -0
- package/internal/utils/env.mjs.map +1 -0
- package/internal/utils/log.d.mts +4 -0
- package/internal/utils/log.d.mts.map +1 -0
- package/internal/utils/log.d.ts +4 -0
- package/internal/utils/log.d.ts.map +1 -0
- package/internal/utils/log.js +47 -0
- package/internal/utils/log.js.map +1 -0
- package/internal/utils/log.mjs +43 -0
- package/internal/utils/log.mjs.map +1 -0
- package/internal/utils/sleep.d.mts +2 -0
- package/internal/utils/sleep.d.mts.map +1 -0
- package/internal/utils/sleep.d.ts +2 -0
- package/internal/utils/sleep.d.ts.map +1 -0
- package/internal/utils/sleep.js +7 -0
- package/internal/utils/sleep.js.map +1 -0
- package/internal/utils/sleep.mjs +3 -0
- package/internal/utils/sleep.mjs.map +1 -0
- package/internal/utils/uuid.d.mts +5 -0
- package/internal/utils/uuid.d.mts.map +1 -0
- package/internal/utils/uuid.d.ts +5 -0
- package/internal/utils/uuid.d.ts.map +1 -0
- package/internal/utils/uuid.js +15 -0
- package/internal/utils/uuid.js.map +1 -0
- package/internal/utils/uuid.mjs +11 -0
- package/internal/utils/uuid.mjs.map +1 -0
- package/internal/utils/values.d.mts +15 -0
- package/internal/utils/values.d.mts.map +1 -0
- package/internal/utils/values.d.ts +15 -0
- package/internal/utils/values.d.ts.map +1 -0
- package/internal/utils/values.js +100 -0
- package/internal/utils/values.js.map +1 -0
- package/internal/utils/values.mjs +84 -0
- package/internal/utils/values.mjs.map +1 -0
- package/internal/utils.d.mts +7 -0
- package/internal/utils.d.mts.map +1 -0
- package/internal/utils.d.ts +7 -0
- package/internal/utils.d.ts.map +1 -0
- package/{_shims/auto/runtime-bun.js → internal/utils.js} +8 -5
- package/internal/utils.js.map +1 -0
- package/internal/utils.mjs +8 -0
- package/internal/utils.mjs.map +1 -0
- package/package.json +83 -66
- package/resource.d.mts +6 -0
- package/resource.d.mts.map +1 -0
- package/resource.d.ts +2 -2
- package/resource.d.ts.map +1 -1
- package/resource.js.map +1 -1
- package/resource.mjs.map +1 -1
- package/resources/call.d.mts +1197 -0
- package/resources/call.d.mts.map +1 -0
- package/resources/call.d.ts +13 -24
- package/resources/call.d.ts.map +1 -1
- package/resources/call.js +15 -15
- package/resources/call.js.map +1 -1
- package/resources/call.mjs +15 -15
- package/resources/call.mjs.map +1 -1
- package/resources/evaluation.d.mts +1295 -0
- package/resources/evaluation.d.mts.map +1 -0
- package/resources/evaluation.d.ts +13 -26
- package/resources/evaluation.d.ts.map +1 -1
- package/resources/evaluation.js +13 -13
- package/resources/evaluation.js.map +1 -1
- package/resources/evaluation.mjs +13 -13
- package/resources/evaluation.mjs.map +1 -1
- package/resources/health.d.mts +29 -0
- package/resources/health.d.mts.map +1 -0
- package/resources/health.d.ts +3 -2
- package/resources/health.d.ts.map +1 -1
- package/resources/health.js.map +1 -1
- package/resources/health.mjs.map +1 -1
- package/resources/index.d.mts +8 -0
- package/resources/index.d.mts.map +1 -0
- package/resources/index.d.ts.map +1 -1
- package/resources/integrations.d.mts +81 -0
- package/resources/integrations.d.mts.map +1 -0
- package/resources/integrations.d.ts +8 -40
- package/resources/integrations.d.ts.map +1 -1
- package/resources/integrations.js +0 -25
- package/resources/integrations.js.map +1 -1
- package/resources/integrations.mjs +0 -25
- package/resources/integrations.mjs.map +1 -1
- package/resources/metric.d.mts +75 -0
- package/resources/metric.d.mts.map +1 -0
- package/resources/metric.d.ts +3 -2
- package/resources/metric.d.ts.map +1 -1
- package/resources/metric.js.map +1 -1
- package/resources/metric.mjs.map +1 -1
- package/resources/persona.d.mts +491 -0
- package/resources/persona.d.mts.map +1 -0
- package/resources/persona.d.ts +13 -51
- package/resources/persona.d.ts.map +1 -1
- package/resources/persona.js +10 -26
- package/resources/persona.js.map +1 -1
- package/resources/persona.mjs +10 -26
- package/resources/persona.mjs.map +1 -1
- package/resources/simulation.d.mts +756 -0
- package/resources/simulation.d.mts.map +1 -0
- package/resources/simulation.d.ts +11 -58
- package/resources/simulation.d.ts.map +1 -1
- package/resources/simulation.js +13 -43
- package/resources/simulation.js.map +1 -1
- package/resources/simulation.mjs +13 -43
- package/resources/simulation.mjs.map +1 -1
- package/src/api-promise.ts +92 -0
- package/src/client.ts +751 -0
- package/src/error.ts +1 -1
- package/src/index.ts +4 -307
- package/src/internal/builtin-types.ts +79 -0
- package/src/internal/detect-platform.ts +196 -0
- package/src/internal/errors.ts +22 -0
- package/src/internal/headers.ts +96 -0
- package/src/internal/parse.ts +41 -0
- package/src/internal/polyfill/crypto.node.d.ts +10 -0
- package/src/internal/polyfill/crypto.node.js +11 -0
- package/src/internal/polyfill/crypto.node.mjs +2 -0
- package/src/internal/polyfill/file.node.d.ts +9 -0
- package/src/internal/polyfill/file.node.js +17 -0
- package/src/internal/polyfill/file.node.mjs +9 -0
- package/src/internal/request-options.ts +67 -0
- package/src/internal/shim-types.d.ts +28 -0
- package/src/internal/shims.ts +145 -0
- package/src/internal/types.ts +98 -0
- package/src/internal/uploads.ts +307 -0
- package/src/internal/utils/base64.ts +37 -0
- package/src/internal/utils/env.ts +18 -0
- package/src/internal/utils/log.ts +49 -0
- package/src/internal/utils/sleep.ts +3 -0
- package/src/internal/utils/uuid.ts +13 -0
- package/src/internal/utils/values.ts +94 -0
- package/src/internal/utils.ts +8 -0
- package/src/resource.ts +2 -2
- package/src/resources/call.ts +22 -42
- package/src/resources/evaluation.ts +25 -42
- package/src/resources/health.ts +3 -2
- package/src/resources/integrations.ts +10 -34
- package/src/resources/metric.ts +3 -2
- package/src/resources/persona.ts +22 -61
- package/src/resources/simulation.ts +22 -84
- package/src/tsconfig.json +2 -2
- package/src/uploads.ts +1 -255
- package/src/version.ts +1 -1
- package/uploads.d.mts +2 -0
- package/uploads.d.mts.map +1 -0
- package/uploads.d.ts +1 -74
- package/uploads.d.ts.map +1 -1
- package/uploads.js +3 -168
- package/uploads.js.map +1 -1
- package/uploads.mjs +1 -157
- package/uploads.mjs.map +1 -1
- package/version.d.mts +2 -0
- package/version.d.mts.map +1 -0
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
- package/_shims/MultipartBody.d.ts +0 -9
- package/_shims/MultipartBody.d.ts.map +0 -1
- package/_shims/MultipartBody.js +0 -16
- package/_shims/MultipartBody.js.map +0 -1
- package/_shims/MultipartBody.mjs +0 -12
- package/_shims/MultipartBody.mjs.map +0 -1
- package/_shims/README.md +0 -46
- package/_shims/auto/runtime-bun.d.ts +0 -5
- package/_shims/auto/runtime-bun.d.ts.map +0 -1
- package/_shims/auto/runtime-bun.js.map +0 -1
- package/_shims/auto/runtime-bun.mjs +0 -2
- package/_shims/auto/runtime-bun.mjs.map +0 -1
- package/_shims/auto/runtime-node.d.ts +0 -5
- package/_shims/auto/runtime-node.d.ts.map +0 -1
- package/_shims/auto/runtime-node.js +0 -21
- package/_shims/auto/runtime-node.js.map +0 -1
- package/_shims/auto/runtime-node.mjs +0 -2
- package/_shims/auto/runtime-node.mjs.map +0 -1
- package/_shims/auto/runtime.d.ts +0 -5
- package/_shims/auto/runtime.d.ts.map +0 -1
- package/_shims/auto/runtime.js +0 -21
- package/_shims/auto/runtime.js.map +0 -1
- package/_shims/auto/runtime.mjs +0 -2
- package/_shims/auto/runtime.mjs.map +0 -1
- package/_shims/auto/types-node.d.ts +0 -5
- package/_shims/auto/types-node.d.ts.map +0 -1
- package/_shims/auto/types-node.js +0 -21
- package/_shims/auto/types-node.js.map +0 -1
- package/_shims/auto/types-node.mjs +0 -2
- package/_shims/auto/types-node.mjs.map +0 -1
- package/_shims/auto/types.d.ts +0 -101
- package/_shims/auto/types.js +0 -3
- package/_shims/auto/types.mjs +0 -3
- package/_shims/bun-runtime.d.ts +0 -6
- package/_shims/bun-runtime.d.ts.map +0 -1
- package/_shims/bun-runtime.js +0 -14
- package/_shims/bun-runtime.js.map +0 -1
- package/_shims/bun-runtime.mjs +0 -10
- package/_shims/bun-runtime.mjs.map +0 -1
- package/_shims/index.d.ts +0 -83
- package/_shims/index.js +0 -17
- package/_shims/index.mjs +0 -11
- package/_shims/manual-types.d.ts +0 -12
- package/_shims/manual-types.js +0 -3
- package/_shims/manual-types.mjs +0 -3
- package/_shims/node-runtime.d.ts +0 -3
- package/_shims/node-runtime.d.ts.map +0 -1
- package/_shims/node-runtime.js +0 -89
- package/_shims/node-runtime.js.map +0 -1
- package/_shims/node-runtime.mjs +0 -56
- package/_shims/node-runtime.mjs.map +0 -1
- package/_shims/node-types.d.ts +0 -42
- package/_shims/node-types.js +0 -3
- package/_shims/node-types.mjs +0 -3
- package/_shims/registry.d.ts +0 -37
- package/_shims/registry.d.ts.map +0 -1
- package/_shims/registry.js +0 -41
- package/_shims/registry.js.map +0 -1
- package/_shims/registry.mjs +0 -37
- package/_shims/registry.mjs.map +0 -1
- package/_shims/web-runtime.d.ts +0 -5
- package/_shims/web-runtime.d.ts.map +0 -1
- package/_shims/web-runtime.js +0 -78
- package/_shims/web-runtime.js.map +0 -1
- package/_shims/web-runtime.mjs +0 -71
- package/_shims/web-runtime.mjs.map +0 -1
- package/_shims/web-types.d.ts +0 -83
- package/_shims/web-types.js +0 -3
- package/_shims/web-types.mjs +0 -3
- package/core.d.ts +0 -255
- package/core.d.ts.map +0 -1
- package/core.js +0 -929
- package/core.js.map +0 -1
- package/core.mjs +0 -897
- package/core.mjs.map +0 -1
- package/resources.d.ts +0 -2
- package/resources.d.ts.map +0 -1
- package/resources.js +0 -18
- package/resources.js.map +0 -1
- package/resources.mjs +0 -2
- package/resources.mjs.map +0 -1
- package/shims/node.d.ts +0 -30
- package/shims/node.d.ts.map +0 -1
- package/shims/node.js +0 -31
- package/shims/node.js.map +0 -1
- package/shims/node.mjs +0 -5
- package/shims/node.mjs.map +0 -1
- package/shims/web.d.ts +0 -26
- package/shims/web.d.ts.map +0 -1
- package/shims/web.js +0 -31
- package/shims/web.js.map +0 -1
- package/shims/web.mjs +0 -5
- package/shims/web.mjs.map +0 -1
- package/src/_shims/MultipartBody.ts +0 -9
- package/src/_shims/README.md +0 -46
- package/src/_shims/auto/runtime-bun.ts +0 -4
- package/src/_shims/auto/runtime-node.ts +0 -4
- package/src/_shims/auto/runtime.ts +0 -4
- package/src/_shims/auto/types-node.ts +0 -4
- package/src/_shims/auto/types.d.ts +0 -101
- package/src/_shims/auto/types.js +0 -3
- package/src/_shims/auto/types.mjs +0 -3
- package/src/_shims/bun-runtime.ts +0 -14
- package/src/_shims/index.d.ts +0 -83
- package/src/_shims/index.js +0 -17
- package/src/_shims/index.mjs +0 -11
- package/src/_shims/manual-types.d.ts +0 -12
- package/src/_shims/manual-types.js +0 -3
- package/src/_shims/manual-types.mjs +0 -3
- package/src/_shims/node-runtime.ts +0 -81
- package/src/_shims/node-types.d.ts +0 -42
- package/src/_shims/node-types.js +0 -3
- package/src/_shims/node-types.mjs +0 -3
- package/src/_shims/registry.ts +0 -67
- package/src/_shims/web-runtime.ts +0 -103
- package/src/_shims/web-types.d.ts +0 -83
- package/src/_shims/web-types.js +0 -3
- package/src/_shims/web-types.mjs +0 -3
- package/src/core.ts +0 -1242
- package/src/resources.ts +0 -1
- package/src/shims/node.ts +0 -50
- package/src/shims/web.ts +0 -50
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
import { type RequestOptions } from './request-options';
|
|
2
|
+
import type { FilePropertyBag, Fetch } from './builtin-types';
|
|
3
|
+
import { isFsReadStreamLike, type FsReadStreamLike } from './shims';
|
|
4
|
+
import type { Roark } from '../client';
|
|
5
|
+
import './polyfill/file.node.js';
|
|
6
|
+
|
|
7
|
+
type BlobLikePart = string | ArrayBuffer | ArrayBufferView | BlobLike | DataView;
|
|
8
|
+
type BlobPart = string | ArrayBuffer | ArrayBufferView | Blob | DataView;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Typically, this is a native "File" class.
|
|
12
|
+
*
|
|
13
|
+
* We provide the {@link toFile} utility to convert a variety of objects
|
|
14
|
+
* into the File class.
|
|
15
|
+
*
|
|
16
|
+
* For convenience, you can also pass a fetch Response, or in Node,
|
|
17
|
+
* the result of fs.createReadStream().
|
|
18
|
+
*/
|
|
19
|
+
export type Uploadable = FileLike | ResponseLike | FsReadStreamLike;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Intended to match DOM Blob, node-fetch Blob, node:buffer Blob, etc.
|
|
23
|
+
* Don't add arrayBuffer here, node-fetch doesn't have it
|
|
24
|
+
*/
|
|
25
|
+
interface BlobLike {
|
|
26
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/size) */
|
|
27
|
+
readonly size: number;
|
|
28
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/type) */
|
|
29
|
+
readonly type: string;
|
|
30
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/text) */
|
|
31
|
+
text(): Promise<string>;
|
|
32
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/slice) */
|
|
33
|
+
slice(start?: number, end?: number): BlobLike;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* This check adds the arrayBuffer() method type because it is available and used at runtime
|
|
38
|
+
*/
|
|
39
|
+
const isBlobLike = (value: any): value is BlobLike & { arrayBuffer(): Promise<ArrayBuffer> } =>
|
|
40
|
+
value != null &&
|
|
41
|
+
typeof value === 'object' &&
|
|
42
|
+
typeof value.size === 'number' &&
|
|
43
|
+
typeof value.type === 'string' &&
|
|
44
|
+
typeof value.text === 'function' &&
|
|
45
|
+
typeof value.slice === 'function' &&
|
|
46
|
+
typeof value.arrayBuffer === 'function';
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Intended to match DOM File, node:buffer File, undici File, etc.
|
|
50
|
+
*/
|
|
51
|
+
interface FileLike extends BlobLike {
|
|
52
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/File/lastModified) */
|
|
53
|
+
readonly lastModified: number;
|
|
54
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/File/name) */
|
|
55
|
+
readonly name: string;
|
|
56
|
+
}
|
|
57
|
+
declare var FileClass: {
|
|
58
|
+
prototype: FileLike;
|
|
59
|
+
new (fileBits: BlobPart[], fileName: string, options?: FilePropertyBag): FileLike;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* This check adds the arrayBuffer() method type because it is available and used at runtime
|
|
64
|
+
*/
|
|
65
|
+
const isFileLike = (value: any): value is FileLike & { arrayBuffer(): Promise<ArrayBuffer> } =>
|
|
66
|
+
value != null &&
|
|
67
|
+
typeof value === 'object' &&
|
|
68
|
+
typeof value.name === 'string' &&
|
|
69
|
+
typeof value.lastModified === 'number' &&
|
|
70
|
+
isBlobLike(value);
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Intended to match DOM Response, node-fetch Response, undici Response, etc.
|
|
74
|
+
*/
|
|
75
|
+
export interface ResponseLike {
|
|
76
|
+
url: string;
|
|
77
|
+
blob(): Promise<BlobLike>;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const isResponseLike = (value: any): value is ResponseLike =>
|
|
81
|
+
value != null &&
|
|
82
|
+
typeof value === 'object' &&
|
|
83
|
+
typeof value.url === 'string' &&
|
|
84
|
+
typeof value.blob === 'function';
|
|
85
|
+
|
|
86
|
+
const isUploadable = (value: any): value is Uploadable => {
|
|
87
|
+
return isFileLike(value) || isResponseLike(value) || isFsReadStreamLike(value);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
type ToFileInput = Uploadable | Exclude<BlobLikePart, string> | AsyncIterable<BlobLikePart>;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Construct a `File` instance. This is used to ensure a helpful error is thrown
|
|
94
|
+
* for environments that don't define a global `File` yet and so that we don't
|
|
95
|
+
* accidentally rely on a global `File` type in our annotations.
|
|
96
|
+
*/
|
|
97
|
+
function makeFile(fileBits: BlobPart[], fileName: string, options?: FilePropertyBag): FileLike {
|
|
98
|
+
const File = (globalThis as any).File as typeof FileClass | undefined;
|
|
99
|
+
if (typeof File === 'undefined') {
|
|
100
|
+
throw new Error('`File` is not defined as a global which is required for file uploads');
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return new File(fileBits, fileName, options);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Helper for creating a {@link File} to pass to an SDK upload method from a variety of different data formats
|
|
108
|
+
* @param value the raw content of the file. Can be an {@link Uploadable}, {@link BlobLikePart}, or {@link AsyncIterable} of {@link BlobLikePart}s
|
|
109
|
+
* @param {string=} name the name of the file. If omitted, toFile will try to determine a file name from bits if possible
|
|
110
|
+
* @param {Object=} options additional properties
|
|
111
|
+
* @param {string=} options.type the MIME type of the content
|
|
112
|
+
* @param {number=} options.lastModified the last modified timestamp
|
|
113
|
+
* @returns a {@link File} with the given properties
|
|
114
|
+
*/
|
|
115
|
+
export async function toFile(
|
|
116
|
+
value: ToFileInput | PromiseLike<ToFileInput>,
|
|
117
|
+
name?: string | null | undefined,
|
|
118
|
+
options?: FilePropertyBag | undefined,
|
|
119
|
+
): Promise<FileLike> {
|
|
120
|
+
// If it's a promise, resolve it.
|
|
121
|
+
value = await value;
|
|
122
|
+
|
|
123
|
+
// If we've been given a `File` we don't need to do anything
|
|
124
|
+
if (isFileLike(value)) {
|
|
125
|
+
const File = (globalThis as any).File as typeof FileClass | undefined;
|
|
126
|
+
if (File && value instanceof File) {
|
|
127
|
+
return value;
|
|
128
|
+
}
|
|
129
|
+
return makeFile([await value.arrayBuffer()], value.name);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (isResponseLike(value)) {
|
|
133
|
+
const blob = await value.blob();
|
|
134
|
+
name ||= new URL(value.url).pathname.split(/[\\/]/).pop() ?? 'unknown_file';
|
|
135
|
+
|
|
136
|
+
return makeFile(await getBytes(blob), name, options);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const parts = await getBytes(value);
|
|
140
|
+
|
|
141
|
+
name ||= getName(value) ?? 'unknown_file';
|
|
142
|
+
|
|
143
|
+
if (!options?.type) {
|
|
144
|
+
const type = parts.find((part) => typeof part === 'object' && 'type' in part && part.type);
|
|
145
|
+
if (typeof type === 'string') {
|
|
146
|
+
options = { ...options, type };
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return makeFile(parts, name, options);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export async function getBytes(
|
|
154
|
+
value: Uploadable | BlobLikePart | AsyncIterable<BlobLikePart>,
|
|
155
|
+
): Promise<Array<BlobPart>> {
|
|
156
|
+
let parts: Array<BlobPart> = [];
|
|
157
|
+
if (
|
|
158
|
+
typeof value === 'string' ||
|
|
159
|
+
ArrayBuffer.isView(value) || // includes Uint8Array, Buffer, etc.
|
|
160
|
+
value instanceof ArrayBuffer
|
|
161
|
+
) {
|
|
162
|
+
parts.push(value);
|
|
163
|
+
} else if (isBlobLike(value)) {
|
|
164
|
+
parts.push(value instanceof Blob ? value : await value.arrayBuffer());
|
|
165
|
+
} else if (
|
|
166
|
+
isAsyncIterableIterator(value) // includes Readable, ReadableStream, etc.
|
|
167
|
+
) {
|
|
168
|
+
for await (const chunk of value) {
|
|
169
|
+
parts.push(...(await getBytes(chunk as BlobLikePart))); // TODO, consider validating?
|
|
170
|
+
}
|
|
171
|
+
} else {
|
|
172
|
+
const constructor = value?.constructor?.name;
|
|
173
|
+
throw new Error(
|
|
174
|
+
`Unexpected data type: ${typeof value}${
|
|
175
|
+
constructor ? `; constructor: ${constructor}` : ''
|
|
176
|
+
}${propsForError(value)}`,
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return parts;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function propsForError(value: unknown): string {
|
|
184
|
+
if (typeof value !== 'object' || value === null) return '';
|
|
185
|
+
const props = Object.getOwnPropertyNames(value);
|
|
186
|
+
return `; props: [${props.map((p) => `"${p}"`).join(', ')}]`;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function getName(value: unknown): string | undefined {
|
|
190
|
+
return (
|
|
191
|
+
(typeof value === 'object' &&
|
|
192
|
+
value !== null &&
|
|
193
|
+
(('name' in value && String(value.name)) ||
|
|
194
|
+
('filename' in value && String(value.filename)) ||
|
|
195
|
+
('path' in value && String(value.path).split(/[\\/]/).pop()))) ||
|
|
196
|
+
undefined
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const isAsyncIterableIterator = (value: any): value is AsyncIterableIterator<unknown> =>
|
|
201
|
+
value != null && typeof value === 'object' && typeof value[Symbol.asyncIterator] === 'function';
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Returns a multipart/form-data request if any part of the given request body contains a File / Blob value.
|
|
205
|
+
* Otherwise returns the request as is.
|
|
206
|
+
*/
|
|
207
|
+
export const maybeMultipartFormRequestOptions = async (
|
|
208
|
+
opts: RequestOptions,
|
|
209
|
+
fetch: Roark | Fetch,
|
|
210
|
+
): Promise<RequestOptions> => {
|
|
211
|
+
if (!hasUploadableValue(opts.body)) return opts;
|
|
212
|
+
|
|
213
|
+
return { ...opts, body: await createForm(opts.body, fetch) };
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
type MultipartFormRequestOptions = Omit<RequestOptions, 'body'> & { body: unknown };
|
|
217
|
+
|
|
218
|
+
export const multipartFormRequestOptions = async (
|
|
219
|
+
opts: MultipartFormRequestOptions,
|
|
220
|
+
fetch: Roark | Fetch,
|
|
221
|
+
): Promise<RequestOptions> => {
|
|
222
|
+
return { ...opts, body: await createForm(opts.body, fetch) };
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
const supportsFormDataMap = new WeakMap<Fetch, Promise<boolean>>();
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* node-fetch doesn't support the global FormData object in recent node versions. Instead of sending
|
|
229
|
+
* properly-encoded form data, it just stringifies the object, resulting in a request body of "[object FormData]".
|
|
230
|
+
* This function detects if the fetch function provided supports the global FormData object to avoid
|
|
231
|
+
* confusing error messages later on.
|
|
232
|
+
*/
|
|
233
|
+
function supportsFormData(fetchObject: Roark | Fetch): Promise<boolean> {
|
|
234
|
+
const fetch: Fetch = typeof fetchObject === 'function' ? fetchObject : (fetchObject as any).fetch;
|
|
235
|
+
const cached = supportsFormDataMap.get(fetch);
|
|
236
|
+
if (cached) return cached;
|
|
237
|
+
const promise = (async () => {
|
|
238
|
+
try {
|
|
239
|
+
const FetchResponse = (
|
|
240
|
+
'Response' in fetch ?
|
|
241
|
+
fetch.Response
|
|
242
|
+
: (await fetch('data:,')).constructor) as typeof Response;
|
|
243
|
+
const data = new FormData();
|
|
244
|
+
if (data.toString() === (await new FetchResponse(data).text())) {
|
|
245
|
+
return false;
|
|
246
|
+
}
|
|
247
|
+
return true;
|
|
248
|
+
} catch {
|
|
249
|
+
// avoid false negatives
|
|
250
|
+
return true;
|
|
251
|
+
}
|
|
252
|
+
})();
|
|
253
|
+
supportsFormDataMap.set(fetch, promise);
|
|
254
|
+
return promise;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export const createForm = async <T = Record<string, unknown>>(
|
|
258
|
+
body: T | undefined,
|
|
259
|
+
fetch: Roark | Fetch,
|
|
260
|
+
): Promise<FormData> => {
|
|
261
|
+
if (!(await supportsFormData(fetch))) {
|
|
262
|
+
throw new TypeError(
|
|
263
|
+
'The provided fetch function does not support file uploads with the current global FormData class.',
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
const form = new FormData();
|
|
267
|
+
await Promise.all(Object.entries(body || {}).map(([key, value]) => addFormValue(form, key, value)));
|
|
268
|
+
return form;
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
const hasUploadableValue = (value: unknown): boolean => {
|
|
272
|
+
if (isUploadable(value)) return true;
|
|
273
|
+
if (Array.isArray(value)) return value.some(hasUploadableValue);
|
|
274
|
+
if (value && typeof value === 'object') {
|
|
275
|
+
for (const k in value) {
|
|
276
|
+
if (hasUploadableValue((value as any)[k])) return true;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return false;
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
const addFormValue = async (form: FormData, key: string, value: unknown): Promise<void> => {
|
|
283
|
+
if (value === undefined) return;
|
|
284
|
+
if (value == null) {
|
|
285
|
+
throw new TypeError(
|
|
286
|
+
`Received null for "${key}"; to pass null in FormData, you must use the string 'null'`,
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// TODO: make nested formats configurable
|
|
291
|
+
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
|
|
292
|
+
form.append(key, String(value));
|
|
293
|
+
} else if (isUploadable(value)) {
|
|
294
|
+
const file = await toFile(value);
|
|
295
|
+
form.append(key, file as any);
|
|
296
|
+
} else if (Array.isArray(value)) {
|
|
297
|
+
await Promise.all(value.map((entry) => addFormValue(form, key + '[]', entry)));
|
|
298
|
+
} else if (typeof value === 'object') {
|
|
299
|
+
await Promise.all(
|
|
300
|
+
Object.entries(value).map(([name, prop]) => addFormValue(form, `${key}[${name}]`, prop)),
|
|
301
|
+
);
|
|
302
|
+
} else {
|
|
303
|
+
throw new TypeError(
|
|
304
|
+
`Invalid value given to form, expected a string, number, boolean, object, Array, File or Blob but got ${value} instead`,
|
|
305
|
+
);
|
|
306
|
+
}
|
|
307
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
import { RoarkError } from '../../error';
|
|
4
|
+
|
|
5
|
+
export const toBase64 = (data: string | Uint8Array | null | undefined): string => {
|
|
6
|
+
if (!data) return '';
|
|
7
|
+
|
|
8
|
+
if (typeof data === 'string') {
|
|
9
|
+
data = new (globalThis as any).TextEncoder().encode(data);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (typeof (globalThis as any).Buffer !== 'undefined') {
|
|
13
|
+
return (globalThis as any).Buffer.from(data).toString('base64');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (typeof btoa !== 'undefined') {
|
|
17
|
+
return btoa(String.fromCharCode.apply(null, data as any));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
throw new RoarkError('Cannot generate base64 string; Expected `Buffer` or `btoa` to be defined');
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const fromBase64 = (str: string): Uint8Array => {
|
|
24
|
+
if (typeof (globalThis as any).Buffer !== 'undefined') {
|
|
25
|
+
return new Uint8Array((globalThis as any).Buffer.from(str, 'base64'));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (typeof atob !== 'undefined') {
|
|
29
|
+
return new Uint8Array(
|
|
30
|
+
atob(str)
|
|
31
|
+
.split('')
|
|
32
|
+
.map((c) => c.charCodeAt(0)),
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
throw new RoarkError('Cannot decode base64 string; Expected `Buffer` or `atob` to be defined');
|
|
37
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Read an environment variable.
|
|
5
|
+
*
|
|
6
|
+
* Trims beginning and trailing whitespace.
|
|
7
|
+
*
|
|
8
|
+
* Will return undefined if the environment variable doesn't exist or cannot be accessed.
|
|
9
|
+
*/
|
|
10
|
+
export const readEnv = (env: string): string | undefined => {
|
|
11
|
+
if (typeof (globalThis as any).process !== 'undefined') {
|
|
12
|
+
return (globalThis as any).process.env?.[env]?.trim() ?? undefined;
|
|
13
|
+
}
|
|
14
|
+
if (typeof (globalThis as any).Deno !== 'undefined') {
|
|
15
|
+
return (globalThis as any).Deno.env?.get?.(env)?.trim();
|
|
16
|
+
}
|
|
17
|
+
return undefined;
|
|
18
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
import type { LogLevel, Logger } from '../../client';
|
|
4
|
+
import { type Roark } from '../../client';
|
|
5
|
+
|
|
6
|
+
const levelNumbers = {
|
|
7
|
+
off: 0,
|
|
8
|
+
error: 200,
|
|
9
|
+
warn: 300,
|
|
10
|
+
info: 400,
|
|
11
|
+
debug: 500,
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
function noop() {}
|
|
15
|
+
|
|
16
|
+
function logFn(logger: Logger | undefined, clientLevel: LogLevel | undefined, level: keyof Logger) {
|
|
17
|
+
if (!logger || levelNumbers[level] > levelNumbers[clientLevel!]!) {
|
|
18
|
+
return noop;
|
|
19
|
+
} else {
|
|
20
|
+
// Don't wrap logger functions, we want the stacktrace intact!
|
|
21
|
+
return logger[level].bind(logger);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
let lastLogger: { deref(): Logger } | undefined;
|
|
26
|
+
let lastLevel: LogLevel | undefined;
|
|
27
|
+
let lastLevelLogger: Logger;
|
|
28
|
+
|
|
29
|
+
export function logger(client: Roark): Logger {
|
|
30
|
+
let { logger, logLevel: clientLevel } = client;
|
|
31
|
+
if (lastLevel === clientLevel && (logger === lastLogger || logger === lastLogger?.deref())) {
|
|
32
|
+
return lastLevelLogger;
|
|
33
|
+
}
|
|
34
|
+
const levelLogger = {
|
|
35
|
+
error: logFn(logger, clientLevel, 'error'),
|
|
36
|
+
warn: logFn(logger, clientLevel, 'warn'),
|
|
37
|
+
info: logFn(logger, clientLevel, 'info'),
|
|
38
|
+
debug: logFn(logger, clientLevel, 'debug'),
|
|
39
|
+
};
|
|
40
|
+
const { WeakRef } = globalThis as any;
|
|
41
|
+
lastLogger =
|
|
42
|
+
logger ?
|
|
43
|
+
WeakRef ? new WeakRef(logger)
|
|
44
|
+
: { deref: () => logger }
|
|
45
|
+
: undefined;
|
|
46
|
+
lastLevel = clientLevel;
|
|
47
|
+
lastLevelLogger = levelLogger;
|
|
48
|
+
return levelLogger;
|
|
49
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
import { crypto } from '../polyfill/crypto.node';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* https://stackoverflow.com/a/2117523
|
|
7
|
+
*/
|
|
8
|
+
export function uuid4() {
|
|
9
|
+
if (crypto.randomUUID) return crypto.randomUUID();
|
|
10
|
+
return '10000000-1000-4000-8000-100000000000'.replace(/[018]/g, (c) =>
|
|
11
|
+
(+c ^ (crypto.getRandomValues(new Uint8Array(1))[0]! & (15 >> (+c / 4)))).toString(16),
|
|
12
|
+
);
|
|
13
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
import { RoarkError } from '../../error';
|
|
4
|
+
|
|
5
|
+
// https://url.spec.whatwg.org/#url-scheme-string
|
|
6
|
+
const startsWithSchemeRegexp = /^[a-z][a-z0-9+.-]*:/i;
|
|
7
|
+
|
|
8
|
+
export const isAbsoluteURL = (url: string): boolean => {
|
|
9
|
+
return startsWithSchemeRegexp.test(url);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/** Returns an object if the given value isn't an object, otherwise returns as-is */
|
|
13
|
+
export function maybeObj(x: unknown): object {
|
|
14
|
+
if (typeof x !== 'object') {
|
|
15
|
+
return {};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return x ?? {};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// https://stackoverflow.com/a/34491287
|
|
22
|
+
export function isEmptyObj(obj: Object | null | undefined): boolean {
|
|
23
|
+
if (!obj) return true;
|
|
24
|
+
for (const _k in obj) return false;
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// https://eslint.org/docs/latest/rules/no-prototype-builtins
|
|
29
|
+
export function hasOwn(obj: Object, key: string): boolean {
|
|
30
|
+
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function isObj(obj: unknown): obj is Record<string, unknown> {
|
|
34
|
+
return obj != null && typeof obj === 'object' && !Array.isArray(obj);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const ensurePresent = <T>(value: T | null | undefined): T => {
|
|
38
|
+
if (value == null) {
|
|
39
|
+
throw new RoarkError(`Expected a value to be given but received ${value} instead.`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return value;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const validatePositiveInteger = (name: string, n: unknown): number => {
|
|
46
|
+
if (typeof n !== 'number' || !Number.isInteger(n)) {
|
|
47
|
+
throw new RoarkError(`${name} must be an integer`);
|
|
48
|
+
}
|
|
49
|
+
if (n < 0) {
|
|
50
|
+
throw new RoarkError(`${name} must be a positive integer`);
|
|
51
|
+
}
|
|
52
|
+
return n;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export const coerceInteger = (value: unknown): number => {
|
|
56
|
+
if (typeof value === 'number') return Math.round(value);
|
|
57
|
+
if (typeof value === 'string') return parseInt(value, 10);
|
|
58
|
+
|
|
59
|
+
throw new RoarkError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export const coerceFloat = (value: unknown): number => {
|
|
63
|
+
if (typeof value === 'number') return value;
|
|
64
|
+
if (typeof value === 'string') return parseFloat(value);
|
|
65
|
+
|
|
66
|
+
throw new RoarkError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export const coerceBoolean = (value: unknown): boolean => {
|
|
70
|
+
if (typeof value === 'boolean') return value;
|
|
71
|
+
if (typeof value === 'string') return value === 'true';
|
|
72
|
+
return Boolean(value);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export const maybeCoerceInteger = (value: unknown): number | undefined => {
|
|
76
|
+
if (value === undefined) {
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
return coerceInteger(value);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export const maybeCoerceFloat = (value: unknown): number | undefined => {
|
|
83
|
+
if (value === undefined) {
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
return coerceFloat(value);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export const maybeCoerceBoolean = (value: unknown): boolean | undefined => {
|
|
90
|
+
if (value === undefined) {
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
return coerceBoolean(value);
|
|
94
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
export * from './utils/values';
|
|
4
|
+
export * from './utils/base64';
|
|
5
|
+
export * from './utils/env';
|
|
6
|
+
export * from './utils/log';
|
|
7
|
+
export * from './utils/uuid';
|
|
8
|
+
export * from './utils/sleep';
|
package/src/resource.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
-
import type { Roark } from './
|
|
3
|
+
import type { Roark } from './client';
|
|
4
4
|
|
|
5
|
-
export
|
|
5
|
+
export class APIResource {
|
|
6
6
|
protected _client: Roark;
|
|
7
7
|
|
|
8
8
|
constructor(client: Roark) {
|
package/src/resources/call.ts
CHANGED
|
@@ -1,47 +1,39 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
3
|
import { APIResource } from '../resource';
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
4
|
+
import { APIPromise } from '../api-promise';
|
|
5
|
+
import { RequestOptions } from '../internal/request-options';
|
|
6
6
|
|
|
7
7
|
export class Call extends APIResource {
|
|
8
8
|
/**
|
|
9
9
|
* Create a new call with recording, transcript, agents, and customers
|
|
10
10
|
*/
|
|
11
|
-
create(body: CallCreateParams, options?:
|
|
11
|
+
create(body: CallCreateParams, options?: RequestOptions): APIPromise<CallCreateResponse> {
|
|
12
12
|
return this._client.post('/v1/call', { body, ...options });
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Returns a paginated list of calls for the authenticated project.
|
|
17
17
|
*/
|
|
18
|
-
list(query?: CallListParams, options?: Core.RequestOptions): Core.APIPromise<CallListResponse>;
|
|
19
|
-
list(options?: Core.RequestOptions): Core.APIPromise<CallListResponse>;
|
|
20
18
|
list(
|
|
21
|
-
query: CallListParams |
|
|
22
|
-
options?:
|
|
23
|
-
):
|
|
24
|
-
if (isRequestOptions(query)) {
|
|
25
|
-
return this.list({}, query);
|
|
26
|
-
}
|
|
19
|
+
query: CallListParams | null | undefined = {},
|
|
20
|
+
options?: RequestOptions,
|
|
21
|
+
): APIPromise<CallListResponse> {
|
|
27
22
|
return this._client.get('/v1/call', { query, ...options });
|
|
28
23
|
}
|
|
29
24
|
|
|
30
25
|
/**
|
|
31
26
|
* Retrieve an existing call by its unique identifier
|
|
32
27
|
*/
|
|
33
|
-
|
|
34
|
-
return this._client.get(`/v1/call/${
|
|
28
|
+
getByID(callID: string, options?: RequestOptions): APIPromise<CallGetByIDResponse> {
|
|
29
|
+
return this._client.get(`/v1/call/${callID}`, options);
|
|
35
30
|
}
|
|
36
31
|
|
|
37
32
|
/**
|
|
38
33
|
* Fetch all evaluation run results for a specific call.
|
|
39
34
|
*/
|
|
40
|
-
listEvaluationRuns(
|
|
41
|
-
|
|
42
|
-
options?: Core.RequestOptions,
|
|
43
|
-
): Core.APIPromise<CallListEvaluationRunsResponse> {
|
|
44
|
-
return this._client.get(`/v1/call/${callId}/evaluation-run`, options);
|
|
35
|
+
listEvaluationRuns(callID: string, options?: RequestOptions): APIPromise<CallListEvaluationRunsResponse> {
|
|
36
|
+
return this._client.get(`/v1/call/${callID}/evaluation-run`, options);
|
|
45
37
|
}
|
|
46
38
|
|
|
47
39
|
/**
|
|
@@ -49,31 +41,19 @@ export class Call extends APIResource {
|
|
|
49
41
|
* system-generated and custom metrics. Only returns successfully computed metrics.
|
|
50
42
|
*/
|
|
51
43
|
listMetrics(
|
|
52
|
-
|
|
53
|
-
query
|
|
54
|
-
options?:
|
|
55
|
-
):
|
|
56
|
-
|
|
57
|
-
listMetrics(
|
|
58
|
-
callId: string,
|
|
59
|
-
query: CallListMetricsParams | Core.RequestOptions = {},
|
|
60
|
-
options?: Core.RequestOptions,
|
|
61
|
-
): Core.APIPromise<CallListMetricsResponse> {
|
|
62
|
-
if (isRequestOptions(query)) {
|
|
63
|
-
return this.listMetrics(callId, {}, query);
|
|
64
|
-
}
|
|
65
|
-
return this._client.get(`/v1/call/${callId}/metrics`, { query, ...options });
|
|
44
|
+
callID: string,
|
|
45
|
+
query: CallListMetricsParams | null | undefined = {},
|
|
46
|
+
options?: RequestOptions,
|
|
47
|
+
): APIPromise<CallListMetricsResponse> {
|
|
48
|
+
return this._client.get(`/v1/call/${callID}/metrics`, { query, ...options });
|
|
66
49
|
}
|
|
67
50
|
|
|
68
51
|
/**
|
|
69
52
|
* Fetch detailed sentiment analysis results for a specific call, including
|
|
70
53
|
* emotional tone, key phrases, and sentiment scores.
|
|
71
54
|
*/
|
|
72
|
-
listSentimentRuns(
|
|
73
|
-
|
|
74
|
-
options?: Core.RequestOptions,
|
|
75
|
-
): Core.APIPromise<CallListSentimentRunsResponse> {
|
|
76
|
-
return this._client.get(`/v1/call/${callId}/sentiment-run`, options);
|
|
55
|
+
listSentimentRuns(callID: string, options?: RequestOptions): APIPromise<CallListSentimentRunsResponse> {
|
|
56
|
+
return this._client.get(`/v1/call/${callID}/sentiment-run`, options);
|
|
77
57
|
}
|
|
78
58
|
}
|
|
79
59
|
|
|
@@ -227,7 +207,7 @@ export namespace CallListResponse {
|
|
|
227
207
|
/**
|
|
228
208
|
* Custom properties associated with the call
|
|
229
209
|
*/
|
|
230
|
-
properties?:
|
|
210
|
+
properties?: Record<string, unknown> | null;
|
|
231
211
|
|
|
232
212
|
/**
|
|
233
213
|
* Pre-signed URL to the call recording (expires in 1 hour)
|
|
@@ -392,7 +372,7 @@ export namespace CallGetByIDResponse {
|
|
|
392
372
|
/**
|
|
393
373
|
* Custom properties associated with the call
|
|
394
374
|
*/
|
|
395
|
-
properties?:
|
|
375
|
+
properties?: Record<string, unknown> | null;
|
|
396
376
|
|
|
397
377
|
/**
|
|
398
378
|
* Pre-signed URL to the call recording (expires in 1 hour)
|
|
@@ -955,7 +935,7 @@ export interface CallCreateParams {
|
|
|
955
935
|
* Custom properties to include with the call. These can be used for filtering and
|
|
956
936
|
* will show in the call details page
|
|
957
937
|
*/
|
|
958
|
-
properties?:
|
|
938
|
+
properties?: Record<string, unknown>;
|
|
959
939
|
|
|
960
940
|
/**
|
|
961
941
|
* URL of source stereo recording. Must be accessible. Can be a signed URL.
|
|
@@ -1387,12 +1367,12 @@ export namespace CallCreateParams {
|
|
|
1387
1367
|
/**
|
|
1388
1368
|
* Parameters provided to the tool during invocation
|
|
1389
1369
|
*/
|
|
1390
|
-
parameters:
|
|
1370
|
+
parameters: Record<string, ToolInvocation.UnionMember0 | unknown>;
|
|
1391
1371
|
|
|
1392
1372
|
/**
|
|
1393
1373
|
* Result returned by the tool after execution. Can be a string or a JSON object
|
|
1394
1374
|
*/
|
|
1395
|
-
result: string |
|
|
1375
|
+
result: string | Record<string, unknown>;
|
|
1396
1376
|
|
|
1397
1377
|
/**
|
|
1398
1378
|
* Offset in milliseconds from the start of the call when the tool was invoked
|