@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/src/error.ts
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
2
2
|
|
3
|
-
import { castToError } from './
|
3
|
+
import { castToError, Headers } from './core';
|
4
4
|
|
5
|
-
export class
|
5
|
+
export class RoarkError extends Error {}
|
6
6
|
|
7
7
|
export class APIError<
|
8
8
|
TStatus extends number | undefined = number | undefined,
|
9
9
|
THeaders extends Headers | undefined = Headers | undefined,
|
10
10
|
TError extends Object | undefined = Object | undefined,
|
11
|
-
> extends
|
11
|
+
> extends RoarkError {
|
12
12
|
/** HTTP status for the response that caused the error */
|
13
13
|
readonly status: TStatus;
|
14
14
|
/** HTTP headers for the response that caused the error */
|
package/src/index.ts
CHANGED
@@ -1,12 +1,177 @@
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
2
2
|
|
3
|
-
|
3
|
+
import { type Agent } from './_shims/index';
|
4
|
+
import * as Core from './core';
|
5
|
+
import * as Errors from './error';
|
6
|
+
import * as Uploads from './uploads';
|
7
|
+
import * as API from './resources/index';
|
8
|
+
import { CallCreateParams, CallCreateResponse, Calls } from './resources/calls';
|
4
9
|
|
5
|
-
export
|
6
|
-
|
7
|
-
|
10
|
+
export interface ClientOptions {
|
11
|
+
/**
|
12
|
+
* JWT token for authentication
|
13
|
+
*/
|
14
|
+
bearerToken?: string | undefined;
|
15
|
+
|
16
|
+
/**
|
17
|
+
* Override the default base URL for the API, e.g., "https://api.example.com/v2/"
|
18
|
+
*
|
19
|
+
* Defaults to process.env['ROARK_BASE_URL'].
|
20
|
+
*/
|
21
|
+
baseURL?: string | null | undefined;
|
22
|
+
|
23
|
+
/**
|
24
|
+
* The maximum amount of time (in milliseconds) that the client should wait for a response
|
25
|
+
* from the server before timing out a single request.
|
26
|
+
*
|
27
|
+
* Note that request timeouts are retried by default, so in a worst-case scenario you may wait
|
28
|
+
* much longer than this timeout before the promise succeeds or fails.
|
29
|
+
*/
|
30
|
+
timeout?: number | undefined;
|
31
|
+
|
32
|
+
/**
|
33
|
+
* An HTTP agent used to manage HTTP(S) connections.
|
34
|
+
*
|
35
|
+
* If not provided, an agent will be constructed by default in the Node.js environment,
|
36
|
+
* otherwise no agent is used.
|
37
|
+
*/
|
38
|
+
httpAgent?: Agent | undefined;
|
39
|
+
|
40
|
+
/**
|
41
|
+
* Specify a custom `fetch` function implementation.
|
42
|
+
*
|
43
|
+
* If not provided, we use `node-fetch` on Node.js and otherwise expect that `fetch` is
|
44
|
+
* defined globally.
|
45
|
+
*/
|
46
|
+
fetch?: Core.Fetch | undefined;
|
47
|
+
|
48
|
+
/**
|
49
|
+
* The maximum number of times that the client will retry a request in case of a
|
50
|
+
* temporary failure, like a network error or a 5XX error from the server.
|
51
|
+
*
|
52
|
+
* @default 2
|
53
|
+
*/
|
54
|
+
maxRetries?: number | undefined;
|
55
|
+
|
56
|
+
/**
|
57
|
+
* Default headers to include with every request to the API.
|
58
|
+
*
|
59
|
+
* These can be removed in individual requests by explicitly setting the
|
60
|
+
* header to `undefined` or `null` in request options.
|
61
|
+
*/
|
62
|
+
defaultHeaders?: Core.Headers | undefined;
|
63
|
+
|
64
|
+
/**
|
65
|
+
* Default query parameters to include with every request to the API.
|
66
|
+
*
|
67
|
+
* These can be removed in individual requests by explicitly setting the
|
68
|
+
* param to `undefined` in request options.
|
69
|
+
*/
|
70
|
+
defaultQuery?: Core.DefaultQuery | undefined;
|
71
|
+
}
|
72
|
+
|
73
|
+
/**
|
74
|
+
* API Client for interfacing with the Roark API.
|
75
|
+
*/
|
76
|
+
export class Roark extends Core.APIClient {
|
77
|
+
bearerToken: string;
|
78
|
+
|
79
|
+
private _options: ClientOptions;
|
80
|
+
|
81
|
+
/**
|
82
|
+
* API Client for interfacing with the Roark API.
|
83
|
+
*
|
84
|
+
* @param {string | undefined} [opts.bearerToken=process.env['ROARK_API_BEARER_TOKEN'] ?? undefined]
|
85
|
+
* @param {string} [opts.baseURL=process.env['ROARK_BASE_URL'] ?? https://customer.api.roark.ai] - Override the default base URL for the API.
|
86
|
+
* @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
|
87
|
+
* @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
|
88
|
+
* @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
|
89
|
+
* @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
|
90
|
+
* @param {Core.Headers} opts.defaultHeaders - Default headers to include with every request to the API.
|
91
|
+
* @param {Core.DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API.
|
92
|
+
*/
|
93
|
+
constructor({
|
94
|
+
baseURL = Core.readEnv('ROARK_BASE_URL'),
|
95
|
+
bearerToken = Core.readEnv('ROARK_API_BEARER_TOKEN'),
|
96
|
+
...opts
|
97
|
+
}: ClientOptions = {}) {
|
98
|
+
if (bearerToken === undefined) {
|
99
|
+
throw new Errors.RoarkError(
|
100
|
+
"The ROARK_API_BEARER_TOKEN environment variable is missing or empty; either provide it, or instantiate the Roark client with an bearerToken option, like new Roark({ bearerToken: 'My Bearer Token' }).",
|
101
|
+
);
|
102
|
+
}
|
103
|
+
|
104
|
+
const options: ClientOptions = {
|
105
|
+
bearerToken,
|
106
|
+
...opts,
|
107
|
+
baseURL: baseURL || `https://customer.api.roark.ai`,
|
108
|
+
};
|
109
|
+
|
110
|
+
super({
|
111
|
+
baseURL: options.baseURL!,
|
112
|
+
timeout: options.timeout ?? 60000 /* 1 minute */,
|
113
|
+
httpAgent: options.httpAgent,
|
114
|
+
maxRetries: options.maxRetries,
|
115
|
+
fetch: options.fetch,
|
116
|
+
});
|
117
|
+
|
118
|
+
this._options = options;
|
119
|
+
|
120
|
+
this.bearerToken = bearerToken;
|
121
|
+
}
|
122
|
+
|
123
|
+
calls: API.Calls = new API.Calls(this);
|
124
|
+
|
125
|
+
protected override defaultQuery(): Core.DefaultQuery | undefined {
|
126
|
+
return this._options.defaultQuery;
|
127
|
+
}
|
128
|
+
|
129
|
+
protected override defaultHeaders(opts: Core.FinalRequestOptions): Core.Headers {
|
130
|
+
return {
|
131
|
+
...super.defaultHeaders(opts),
|
132
|
+
...this._options.defaultHeaders,
|
133
|
+
};
|
134
|
+
}
|
135
|
+
|
136
|
+
protected override authHeaders(opts: Core.FinalRequestOptions): Core.Headers {
|
137
|
+
return { Authorization: `Bearer ${this.bearerToken}` };
|
138
|
+
}
|
139
|
+
|
140
|
+
static Roark = this;
|
141
|
+
static DEFAULT_TIMEOUT = 60000; // 1 minute
|
142
|
+
|
143
|
+
static RoarkError = Errors.RoarkError;
|
144
|
+
static APIError = Errors.APIError;
|
145
|
+
static APIConnectionError = Errors.APIConnectionError;
|
146
|
+
static APIConnectionTimeoutError = Errors.APIConnectionTimeoutError;
|
147
|
+
static APIUserAbortError = Errors.APIUserAbortError;
|
148
|
+
static NotFoundError = Errors.NotFoundError;
|
149
|
+
static ConflictError = Errors.ConflictError;
|
150
|
+
static RateLimitError = Errors.RateLimitError;
|
151
|
+
static BadRequestError = Errors.BadRequestError;
|
152
|
+
static AuthenticationError = Errors.AuthenticationError;
|
153
|
+
static InternalServerError = Errors.InternalServerError;
|
154
|
+
static PermissionDeniedError = Errors.PermissionDeniedError;
|
155
|
+
static UnprocessableEntityError = Errors.UnprocessableEntityError;
|
156
|
+
|
157
|
+
static toFile = Uploads.toFile;
|
158
|
+
static fileFromPath = Uploads.fileFromPath;
|
159
|
+
}
|
160
|
+
|
161
|
+
Roark.Calls = Calls;
|
162
|
+
export declare namespace Roark {
|
163
|
+
export type RequestOptions = Core.RequestOptions;
|
164
|
+
|
165
|
+
export {
|
166
|
+
Calls as Calls,
|
167
|
+
type CallCreateResponse as CallCreateResponse,
|
168
|
+
type CallCreateParams as CallCreateParams,
|
169
|
+
};
|
170
|
+
}
|
171
|
+
|
172
|
+
export { toFile, fileFromPath } from './uploads';
|
8
173
|
export {
|
9
|
-
|
174
|
+
RoarkError,
|
10
175
|
APIError,
|
11
176
|
APIConnectionError,
|
12
177
|
APIConnectionTimeoutError,
|
@@ -20,3 +185,5 @@ export {
|
|
20
185
|
PermissionDeniedError,
|
21
186
|
UnprocessableEntityError,
|
22
187
|
} from './error';
|
188
|
+
|
189
|
+
export default Roark;
|
package/src/resource.ts
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
2
2
|
|
3
|
-
import type {
|
3
|
+
import type { Roark } from './index';
|
4
4
|
|
5
5
|
export class APIResource {
|
6
|
-
protected _client:
|
6
|
+
protected _client: Roark;
|
7
7
|
|
8
|
-
constructor(client:
|
8
|
+
constructor(client: Roark) {
|
9
9
|
this._client = client;
|
10
10
|
}
|
11
11
|
}
|
package/src/resources/calls.ts
CHANGED
@@ -1,14 +1,13 @@
|
|
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 { RequestOptions } from '../internal/request-options';
|
4
|
+
import * as Core from '../core';
|
6
5
|
|
7
6
|
export class Calls extends APIResource {
|
8
7
|
/**
|
9
8
|
* Upload a call recording.
|
10
9
|
*/
|
11
|
-
create(body: CallCreateParams, options?: RequestOptions): APIPromise<CallCreateResponse> {
|
10
|
+
create(body: CallCreateParams, options?: Core.RequestOptions): Core.APIPromise<CallCreateResponse> {
|
12
11
|
return this._client.post('/call', { body, ...options });
|
13
12
|
}
|
14
13
|
}
|
@@ -0,0 +1,50 @@
|
|
1
|
+
// @ts-ignore
|
2
|
+
import * as types from '../_shims/node-types';
|
3
|
+
import { setShims } from '../_shims/registry';
|
4
|
+
import { getRuntime } from '../_shims/node-runtime';
|
5
|
+
setShims(getRuntime());
|
6
|
+
|
7
|
+
declare module '../_shims/manual-types' {
|
8
|
+
export namespace manual {
|
9
|
+
// @ts-ignore
|
10
|
+
export type Agent = types.Agent;
|
11
|
+
// @ts-ignore
|
12
|
+
export import fetch = types.fetch;
|
13
|
+
// @ts-ignore
|
14
|
+
export type Request = types.Request;
|
15
|
+
// @ts-ignore
|
16
|
+
export type RequestInfo = types.RequestInfo;
|
17
|
+
// @ts-ignore
|
18
|
+
export type RequestInit = types.RequestInit;
|
19
|
+
// @ts-ignore
|
20
|
+
export type Response = types.Response;
|
21
|
+
// @ts-ignore
|
22
|
+
export type ResponseInit = types.ResponseInit;
|
23
|
+
// @ts-ignore
|
24
|
+
export type ResponseType = types.ResponseType;
|
25
|
+
// @ts-ignore
|
26
|
+
export type BodyInit = types.BodyInit;
|
27
|
+
// @ts-ignore
|
28
|
+
export type Headers = types.Headers;
|
29
|
+
// @ts-ignore
|
30
|
+
export type HeadersInit = types.HeadersInit;
|
31
|
+
// @ts-ignore
|
32
|
+
export type BlobPropertyBag = types.BlobPropertyBag;
|
33
|
+
// @ts-ignore
|
34
|
+
export type FilePropertyBag = types.FilePropertyBag;
|
35
|
+
// @ts-ignore
|
36
|
+
export type FileFromPathOptions = types.FileFromPathOptions;
|
37
|
+
// @ts-ignore
|
38
|
+
export import FormData = types.FormData;
|
39
|
+
// @ts-ignore
|
40
|
+
export import File = types.File;
|
41
|
+
// @ts-ignore
|
42
|
+
export import Blob = types.Blob;
|
43
|
+
// @ts-ignore
|
44
|
+
export type Readable = types.Readable;
|
45
|
+
// @ts-ignore
|
46
|
+
export type FsReadStream = types.FsReadStream;
|
47
|
+
// @ts-ignore
|
48
|
+
export import ReadableStream = types.ReadableStream;
|
49
|
+
}
|
50
|
+
}
|
package/src/shims/web.ts
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
// @ts-ignore
|
2
|
+
import * as types from '../_shims/web-types';
|
3
|
+
import { setShims } from '../_shims/registry';
|
4
|
+
import { getRuntime } from '../_shims/web-runtime';
|
5
|
+
setShims(getRuntime({ manuallyImported: true }));
|
6
|
+
|
7
|
+
declare module '../_shims/manual-types' {
|
8
|
+
export namespace manual {
|
9
|
+
// @ts-ignore
|
10
|
+
export type Agent = types.Agent;
|
11
|
+
// @ts-ignore
|
12
|
+
export import fetch = types.fetch;
|
13
|
+
// @ts-ignore
|
14
|
+
export type Request = types.Request;
|
15
|
+
// @ts-ignore
|
16
|
+
export type RequestInfo = types.RequestInfo;
|
17
|
+
// @ts-ignore
|
18
|
+
export type RequestInit = types.RequestInit;
|
19
|
+
// @ts-ignore
|
20
|
+
export type Response = types.Response;
|
21
|
+
// @ts-ignore
|
22
|
+
export type ResponseInit = types.ResponseInit;
|
23
|
+
// @ts-ignore
|
24
|
+
export type ResponseType = types.ResponseType;
|
25
|
+
// @ts-ignore
|
26
|
+
export type BodyInit = types.BodyInit;
|
27
|
+
// @ts-ignore
|
28
|
+
export type Headers = types.Headers;
|
29
|
+
// @ts-ignore
|
30
|
+
export type HeadersInit = types.HeadersInit;
|
31
|
+
// @ts-ignore
|
32
|
+
export type BlobPropertyBag = types.BlobPropertyBag;
|
33
|
+
// @ts-ignore
|
34
|
+
export type FilePropertyBag = types.FilePropertyBag;
|
35
|
+
// @ts-ignore
|
36
|
+
export type FileFromPathOptions = types.FileFromPathOptions;
|
37
|
+
// @ts-ignore
|
38
|
+
export import FormData = types.FormData;
|
39
|
+
// @ts-ignore
|
40
|
+
export import File = types.File;
|
41
|
+
// @ts-ignore
|
42
|
+
export import Blob = types.Blob;
|
43
|
+
// @ts-ignore
|
44
|
+
export type Readable = types.Readable;
|
45
|
+
// @ts-ignore
|
46
|
+
export type FsReadStream = types.FsReadStream;
|
47
|
+
// @ts-ignore
|
48
|
+
export import ReadableStream = types.ReadableStream;
|
49
|
+
}
|
50
|
+
}
|
package/src/tsconfig.json
CHANGED
package/src/uploads.ts
CHANGED
@@ -1 +1,255 @@
|
|
1
|
-
|
1
|
+
import { type RequestOptions } from './core';
|
2
|
+
import {
|
3
|
+
FormData,
|
4
|
+
File,
|
5
|
+
type Blob,
|
6
|
+
type FilePropertyBag,
|
7
|
+
getMultipartRequestOptions,
|
8
|
+
type FsReadStream,
|
9
|
+
isFsReadStream,
|
10
|
+
} from './_shims/index';
|
11
|
+
import { MultipartBody } from './_shims/MultipartBody';
|
12
|
+
export { fileFromPath } from './_shims/index';
|
13
|
+
|
14
|
+
type BlobLikePart = string | ArrayBuffer | ArrayBufferView | BlobLike | Uint8Array | DataView;
|
15
|
+
export type BlobPart = string | ArrayBuffer | ArrayBufferView | Blob | Uint8Array | DataView;
|
16
|
+
|
17
|
+
/**
|
18
|
+
* Typically, this is a native "File" class.
|
19
|
+
*
|
20
|
+
* We provide the {@link toFile} utility to convert a variety of objects
|
21
|
+
* into the File class.
|
22
|
+
*
|
23
|
+
* For convenience, you can also pass a fetch Response, or in Node,
|
24
|
+
* the result of fs.createReadStream().
|
25
|
+
*/
|
26
|
+
export type Uploadable = FileLike | ResponseLike | FsReadStream;
|
27
|
+
|
28
|
+
/**
|
29
|
+
* Intended to match web.Blob, node.Blob, node-fetch.Blob, etc.
|
30
|
+
*/
|
31
|
+
export interface BlobLike {
|
32
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/size) */
|
33
|
+
readonly size: number;
|
34
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/type) */
|
35
|
+
readonly type: string;
|
36
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/text) */
|
37
|
+
text(): Promise<string>;
|
38
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/slice) */
|
39
|
+
slice(start?: number, end?: number): BlobLike;
|
40
|
+
// unfortunately @types/node-fetch@^2.6.4 doesn't type the arrayBuffer method
|
41
|
+
}
|
42
|
+
|
43
|
+
/**
|
44
|
+
* Intended to match web.File, node.File, node-fetch.File, etc.
|
45
|
+
*/
|
46
|
+
export interface FileLike extends BlobLike {
|
47
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/File/lastModified) */
|
48
|
+
readonly lastModified: number;
|
49
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/File/name) */
|
50
|
+
readonly name: string;
|
51
|
+
}
|
52
|
+
|
53
|
+
/**
|
54
|
+
* Intended to match web.Response, node.Response, node-fetch.Response, etc.
|
55
|
+
*/
|
56
|
+
export interface ResponseLike {
|
57
|
+
url: string;
|
58
|
+
blob(): Promise<BlobLike>;
|
59
|
+
}
|
60
|
+
|
61
|
+
export const isResponseLike = (value: any): value is ResponseLike =>
|
62
|
+
value != null &&
|
63
|
+
typeof value === 'object' &&
|
64
|
+
typeof value.url === 'string' &&
|
65
|
+
typeof value.blob === 'function';
|
66
|
+
|
67
|
+
export const isFileLike = (value: any): value is FileLike =>
|
68
|
+
value != null &&
|
69
|
+
typeof value === 'object' &&
|
70
|
+
typeof value.name === 'string' &&
|
71
|
+
typeof value.lastModified === 'number' &&
|
72
|
+
isBlobLike(value);
|
73
|
+
|
74
|
+
/**
|
75
|
+
* The BlobLike type omits arrayBuffer() because @types/node-fetch@^2.6.4 lacks it; but this check
|
76
|
+
* adds the arrayBuffer() method type because it is available and used at runtime
|
77
|
+
*/
|
78
|
+
export const isBlobLike = (value: any): value is BlobLike & { arrayBuffer(): Promise<ArrayBuffer> } =>
|
79
|
+
value != null &&
|
80
|
+
typeof value === 'object' &&
|
81
|
+
typeof value.size === 'number' &&
|
82
|
+
typeof value.type === 'string' &&
|
83
|
+
typeof value.text === 'function' &&
|
84
|
+
typeof value.slice === 'function' &&
|
85
|
+
typeof value.arrayBuffer === 'function';
|
86
|
+
|
87
|
+
export const isUploadable = (value: any): value is Uploadable => {
|
88
|
+
return isFileLike(value) || isResponseLike(value) || isFsReadStream(value);
|
89
|
+
};
|
90
|
+
|
91
|
+
export type ToFileInput = Uploadable | Exclude<BlobLikePart, string> | AsyncIterable<BlobLikePart>;
|
92
|
+
|
93
|
+
/**
|
94
|
+
* Helper for creating a {@link File} to pass to an SDK upload method from a variety of different data formats
|
95
|
+
* @param value the raw content of the file. Can be an {@link Uploadable}, {@link BlobLikePart}, or {@link AsyncIterable} of {@link BlobLikePart}s
|
96
|
+
* @param {string=} name the name of the file. If omitted, toFile will try to determine a file name from bits if possible
|
97
|
+
* @param {Object=} options additional properties
|
98
|
+
* @param {string=} options.type the MIME type of the content
|
99
|
+
* @param {number=} options.lastModified the last modified timestamp
|
100
|
+
* @returns a {@link File} with the given properties
|
101
|
+
*/
|
102
|
+
export async function toFile(
|
103
|
+
value: ToFileInput | PromiseLike<ToFileInput>,
|
104
|
+
name?: string | null | undefined,
|
105
|
+
options?: FilePropertyBag | undefined,
|
106
|
+
): Promise<FileLike> {
|
107
|
+
// If it's a promise, resolve it.
|
108
|
+
value = await value;
|
109
|
+
|
110
|
+
// If we've been given a `File` we don't need to do anything
|
111
|
+
if (isFileLike(value)) {
|
112
|
+
return value;
|
113
|
+
}
|
114
|
+
|
115
|
+
if (isResponseLike(value)) {
|
116
|
+
const blob = await value.blob();
|
117
|
+
name ||= new URL(value.url).pathname.split(/[\\/]/).pop() ?? 'unknown_file';
|
118
|
+
|
119
|
+
// we need to convert the `Blob` into an array buffer because the `Blob` class
|
120
|
+
// that `node-fetch` defines is incompatible with the web standard which results
|
121
|
+
// in `new File` interpreting it as a string instead of binary data.
|
122
|
+
const data = isBlobLike(blob) ? [(await blob.arrayBuffer()) as any] : [blob];
|
123
|
+
|
124
|
+
return new File(data, name, options);
|
125
|
+
}
|
126
|
+
|
127
|
+
const bits = await getBytes(value);
|
128
|
+
|
129
|
+
name ||= getName(value) ?? 'unknown_file';
|
130
|
+
|
131
|
+
if (!options?.type) {
|
132
|
+
const type = (bits[0] as any)?.type;
|
133
|
+
if (typeof type === 'string') {
|
134
|
+
options = { ...options, type };
|
135
|
+
}
|
136
|
+
}
|
137
|
+
|
138
|
+
return new File(bits, name, options);
|
139
|
+
}
|
140
|
+
|
141
|
+
async function getBytes(value: ToFileInput): Promise<Array<BlobPart>> {
|
142
|
+
let parts: Array<BlobPart> = [];
|
143
|
+
if (
|
144
|
+
typeof value === 'string' ||
|
145
|
+
ArrayBuffer.isView(value) || // includes Uint8Array, Buffer, etc.
|
146
|
+
value instanceof ArrayBuffer
|
147
|
+
) {
|
148
|
+
parts.push(value);
|
149
|
+
} else if (isBlobLike(value)) {
|
150
|
+
parts.push(await value.arrayBuffer());
|
151
|
+
} else if (
|
152
|
+
isAsyncIterableIterator(value) // includes Readable, ReadableStream, etc.
|
153
|
+
) {
|
154
|
+
for await (const chunk of value) {
|
155
|
+
parts.push(chunk as BlobPart); // TODO, consider validating?
|
156
|
+
}
|
157
|
+
} else {
|
158
|
+
throw new Error(
|
159
|
+
`Unexpected data type: ${typeof value}; constructor: ${value?.constructor
|
160
|
+
?.name}; props: ${propsForError(value)}`,
|
161
|
+
);
|
162
|
+
}
|
163
|
+
|
164
|
+
return parts;
|
165
|
+
}
|
166
|
+
|
167
|
+
function propsForError(value: any): string {
|
168
|
+
const props = Object.getOwnPropertyNames(value);
|
169
|
+
return `[${props.map((p) => `"${p}"`).join(', ')}]`;
|
170
|
+
}
|
171
|
+
|
172
|
+
function getName(value: any): string | undefined {
|
173
|
+
return (
|
174
|
+
getStringFromMaybeBuffer(value.name) ||
|
175
|
+
getStringFromMaybeBuffer(value.filename) ||
|
176
|
+
// For fs.ReadStream
|
177
|
+
getStringFromMaybeBuffer(value.path)?.split(/[\\/]/).pop()
|
178
|
+
);
|
179
|
+
}
|
180
|
+
|
181
|
+
const getStringFromMaybeBuffer = (x: string | Buffer | unknown): string | undefined => {
|
182
|
+
if (typeof x === 'string') return x;
|
183
|
+
if (typeof Buffer !== 'undefined' && x instanceof Buffer) return String(x);
|
184
|
+
return undefined;
|
185
|
+
};
|
186
|
+
|
187
|
+
const isAsyncIterableIterator = (value: any): value is AsyncIterableIterator<unknown> =>
|
188
|
+
value != null && typeof value === 'object' && typeof value[Symbol.asyncIterator] === 'function';
|
189
|
+
|
190
|
+
export const isMultipartBody = (body: any): body is MultipartBody =>
|
191
|
+
body && typeof body === 'object' && body.body && body[Symbol.toStringTag] === 'MultipartBody';
|
192
|
+
|
193
|
+
/**
|
194
|
+
* Returns a multipart/form-data request if any part of the given request body contains a File / Blob value.
|
195
|
+
* Otherwise returns the request as is.
|
196
|
+
*/
|
197
|
+
export const maybeMultipartFormRequestOptions = async <T = Record<string, unknown>>(
|
198
|
+
opts: RequestOptions<T>,
|
199
|
+
): Promise<RequestOptions<T | MultipartBody>> => {
|
200
|
+
if (!hasUploadableValue(opts.body)) return opts;
|
201
|
+
|
202
|
+
const form = await createForm(opts.body);
|
203
|
+
return getMultipartRequestOptions(form, opts);
|
204
|
+
};
|
205
|
+
|
206
|
+
export const multipartFormRequestOptions = async <T = Record<string, unknown>>(
|
207
|
+
opts: RequestOptions<T>,
|
208
|
+
): Promise<RequestOptions<T | MultipartBody>> => {
|
209
|
+
const form = await createForm(opts.body);
|
210
|
+
return getMultipartRequestOptions(form, opts);
|
211
|
+
};
|
212
|
+
|
213
|
+
export const createForm = async <T = Record<string, unknown>>(body: T | undefined): Promise<FormData> => {
|
214
|
+
const form = new FormData();
|
215
|
+
await Promise.all(Object.entries(body || {}).map(([key, value]) => addFormValue(form, key, value)));
|
216
|
+
return form;
|
217
|
+
};
|
218
|
+
|
219
|
+
const hasUploadableValue = (value: unknown): boolean => {
|
220
|
+
if (isUploadable(value)) return true;
|
221
|
+
if (Array.isArray(value)) return value.some(hasUploadableValue);
|
222
|
+
if (value && typeof value === 'object') {
|
223
|
+
for (const k in value) {
|
224
|
+
if (hasUploadableValue((value as any)[k])) return true;
|
225
|
+
}
|
226
|
+
}
|
227
|
+
return false;
|
228
|
+
};
|
229
|
+
|
230
|
+
const addFormValue = async (form: FormData, key: string, value: unknown): Promise<void> => {
|
231
|
+
if (value === undefined) return;
|
232
|
+
if (value == null) {
|
233
|
+
throw new TypeError(
|
234
|
+
`Received null for "${key}"; to pass null in FormData, you must use the string 'null'`,
|
235
|
+
);
|
236
|
+
}
|
237
|
+
|
238
|
+
// TODO: make nested formats configurable
|
239
|
+
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
|
240
|
+
form.append(key, String(value));
|
241
|
+
} else if (isUploadable(value)) {
|
242
|
+
const file = await toFile(value);
|
243
|
+
form.append(key, file as File);
|
244
|
+
} else if (Array.isArray(value)) {
|
245
|
+
await Promise.all(value.map((entry) => addFormValue(form, key + '[]', entry)));
|
246
|
+
} else if (typeof value === 'object') {
|
247
|
+
await Promise.all(
|
248
|
+
Object.entries(value).map(([name, prop]) => addFormValue(form, `${key}[${name}]`, prop)),
|
249
|
+
);
|
250
|
+
} else {
|
251
|
+
throw new TypeError(
|
252
|
+
`Invalid value given to form, expected a string, number, boolean, object, Array, File or Blob but got ${value} instead`,
|
253
|
+
);
|
254
|
+
}
|
255
|
+
};
|
package/src/version.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export const VERSION = '0.1.0-alpha.
|
1
|
+
export const VERSION = '0.1.0-alpha.3'; // x-release-please-version
|