@roarkanalytics/sdk 2.21.1 → 2.21.2
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 +8 -0
- package/README.md +69 -46
- package/api-promise.d.mts +1 -46
- package/api-promise.d.mts.map +1 -1
- package/api-promise.d.ts +1 -46
- package/api-promise.d.ts.map +1 -1
- package/api-promise.js +3 -81
- package/api-promise.js.map +1 -1
- package/api-promise.mjs +1 -79
- package/api-promise.mjs.map +1 -1
- package/client.d.mts +25 -30
- package/client.d.mts.map +1 -1
- package/client.d.ts +25 -30
- package/client.d.ts.map +1 -1
- package/client.js +150 -132
- package/client.js.map +1 -1
- package/client.mjs +145 -104
- package/client.mjs.map +1 -1
- package/core/api-promise.d.mts +46 -0
- package/core/api-promise.d.mts.map +1 -0
- package/core/api-promise.d.ts +46 -0
- package/core/api-promise.d.ts.map +1 -0
- package/core/api-promise.js +74 -0
- package/core/api-promise.js.map +1 -0
- package/core/api-promise.mjs +70 -0
- package/core/api-promise.mjs.map +1 -0
- package/core/error.d.mts +46 -0
- package/core/error.d.mts.map +1 -0
- package/core/error.d.ts +46 -0
- package/core/error.d.ts.map +1 -0
- package/core/error.js +113 -0
- package/core/error.js.map +1 -0
- package/core/error.mjs +97 -0
- package/core/error.mjs.map +1 -0
- package/core/resource.d.mts +6 -0
- package/core/resource.d.mts.map +1 -0
- package/core/resource.d.ts +6 -0
- package/core/resource.d.ts.map +1 -0
- package/core/resource.js +11 -0
- package/core/resource.js.map +1 -0
- package/core/resource.mjs +7 -0
- package/core/resource.mjs.map +1 -0
- package/core/uploads.d.mts +3 -0
- package/core/uploads.d.mts.map +1 -0
- package/core/uploads.d.ts +3 -0
- package/core/uploads.d.ts.map +1 -0
- package/core/uploads.js +6 -0
- package/core/uploads.js.map +1 -0
- package/core/uploads.mjs +2 -0
- package/core/uploads.mjs.map +1 -0
- package/error.d.mts +1 -46
- package/error.d.mts.map +1 -1
- package/error.d.ts +1 -46
- package/error.d.ts.map +1 -1
- package/error.js +3 -110
- package/error.js.map +1 -1
- package/error.mjs +1 -96
- package/error.mjs.map +1 -1
- package/index.d.mts +6 -6
- package/index.d.ts +3 -3
- package/index.js +3 -3
- package/index.js.map +1 -1
- package/index.mjs +3 -3
- package/internal/builtin-types.d.mts +11 -3
- package/internal/builtin-types.d.mts.map +1 -1
- package/internal/builtin-types.d.ts +11 -3
- package/internal/builtin-types.d.ts.map +1 -1
- package/internal/detect-platform.js +3 -3
- package/internal/detect-platform.js.map +1 -1
- package/internal/detect-platform.mjs +3 -3
- package/internal/detect-platform.mjs.map +1 -1
- package/internal/errors.d.mts.map +1 -1
- package/internal/errors.d.ts.map +1 -1
- package/internal/errors.js +17 -2
- package/internal/errors.js.map +1 -1
- package/internal/errors.mjs +15 -0
- package/internal/errors.mjs.map +1 -1
- package/internal/headers.d.mts +1 -2
- package/internal/headers.d.mts.map +1 -1
- package/internal/headers.d.ts +1 -2
- package/internal/headers.d.ts.map +1 -1
- package/internal/headers.js +7 -5
- package/internal/headers.js.map +1 -1
- package/internal/headers.mjs +7 -5
- package/internal/headers.mjs.map +1 -1
- package/internal/parse.d.mts +3 -1
- package/internal/parse.d.mts.map +1 -1
- package/internal/parse.d.ts +3 -1
- package/internal/parse.d.ts.map +1 -1
- package/internal/parse.js +33 -21
- package/internal/parse.js.map +1 -1
- package/internal/parse.mjs +33 -20
- package/internal/parse.mjs.map +1 -1
- package/internal/qs/formats.d.mts +1 -0
- package/internal/qs/formats.d.mts.map +1 -1
- package/internal/qs/formats.d.ts +1 -0
- package/internal/qs/formats.d.ts.map +1 -1
- package/internal/qs/formats.js +4 -2
- package/internal/qs/formats.js.map +1 -1
- package/internal/qs/formats.mjs +2 -1
- package/internal/qs/formats.mjs.map +1 -1
- package/internal/qs/stringify.d.mts.map +1 -1
- package/internal/qs/stringify.d.ts.map +1 -1
- package/internal/qs/stringify.js +16 -19
- package/internal/qs/stringify.js.map +1 -1
- package/internal/qs/stringify.mjs +17 -19
- package/internal/qs/stringify.mjs.map +1 -1
- package/internal/qs/utils.d.mts +1 -0
- package/internal/qs/utils.d.mts.map +1 -1
- package/internal/qs/utils.d.ts +1 -0
- package/internal/qs/utils.d.ts.map +1 -1
- package/internal/qs/utils.js +22 -21
- package/internal/qs/utils.js.map +1 -1
- package/internal/qs/utils.mjs +12 -12
- package/internal/qs/utils.mjs.map +1 -1
- package/internal/request-options.d.mts +43 -2
- package/internal/request-options.d.mts.map +1 -1
- package/internal/request-options.d.ts +43 -2
- package/internal/request-options.d.ts.map +1 -1
- package/internal/request-options.js +1 -26
- package/internal/request-options.js.map +1 -1
- package/internal/request-options.mjs +0 -24
- package/internal/request-options.mjs.map +1 -1
- package/internal/shim-types.d.mts +11 -22
- package/internal/shim-types.d.mts.map +1 -0
- package/internal/shim-types.d.ts +11 -22
- package/internal/shim-types.d.ts.map +1 -0
- package/internal/shim-types.js +4 -0
- package/internal/shim-types.js.map +1 -0
- package/internal/shim-types.mjs +3 -0
- package/internal/shim-types.mjs.map +1 -0
- package/internal/shims.d.mts +7 -48
- package/internal/shims.d.mts.map +1 -1
- package/internal/shims.d.ts +7 -48
- package/internal/shims.d.ts.map +1 -1
- package/internal/shims.js +21 -30
- package/internal/shims.js.map +1 -1
- package/internal/shims.mjs +16 -23
- package/internal/shims.mjs.map +1 -1
- package/internal/to-file.d.mts +45 -0
- package/internal/to-file.d.mts.map +1 -0
- package/internal/to-file.d.ts +45 -0
- package/internal/to-file.d.ts.map +1 -0
- package/internal/to-file.js +91 -0
- package/internal/to-file.js.map +1 -0
- package/internal/to-file.mjs +88 -0
- package/internal/to-file.mjs.map +1 -0
- package/internal/tslib.js +81 -0
- package/internal/tslib.mjs +17 -0
- package/internal/types.d.mts +14 -13
- package/internal/types.d.mts.map +1 -1
- package/internal/types.d.ts +14 -13
- package/internal/types.d.ts.map +1 -1
- package/internal/uploads.d.mts +16 -47
- package/internal/uploads.d.mts.map +1 -1
- package/internal/uploads.d.ts +16 -47
- package/internal/uploads.d.ts.map +1 -1
- package/internal/uploads.js +41 -108
- package/internal/uploads.js.map +1 -1
- package/internal/uploads.mjs +39 -108
- package/internal/uploads.mjs.map +1 -1
- package/internal/utils/base64.d.mts.map +1 -1
- package/internal/utils/base64.d.ts.map +1 -1
- package/internal/utils/base64.js +13 -8
- package/internal/utils/base64.js.map +1 -1
- package/internal/utils/base64.mjs +13 -8
- package/internal/utils/base64.mjs.map +1 -1
- package/internal/utils/bytes.d.mts +4 -0
- package/internal/utils/bytes.d.mts.map +1 -0
- package/internal/utils/bytes.d.ts +4 -0
- package/internal/utils/bytes.d.ts.map +1 -0
- package/internal/utils/bytes.js +31 -0
- package/internal/utils/bytes.js.map +1 -0
- package/internal/utils/bytes.mjs +26 -0
- package/internal/utils/bytes.mjs.map +1 -0
- package/internal/utils/env.d.mts.map +1 -1
- package/internal/utils/env.d.ts.map +1 -1
- package/internal/utils/env.js.map +1 -1
- package/internal/utils/env.mjs.map +1 -1
- package/internal/utils/log.d.mts +35 -2
- package/internal/utils/log.d.mts.map +1 -1
- package/internal/utils/log.d.ts +35 -2
- package/internal/utils/log.d.ts.map +1 -1
- package/internal/utils/log.js +62 -24
- package/internal/utils/log.js.map +1 -1
- package/internal/utils/log.mjs +58 -22
- package/internal/utils/log.mjs.map +1 -1
- package/internal/utils/path.d.mts +15 -0
- package/internal/utils/path.d.mts.map +1 -0
- package/internal/utils/path.d.ts +15 -0
- package/internal/utils/path.d.ts.map +1 -0
- package/internal/utils/path.js +79 -0
- package/internal/utils/path.js.map +1 -0
- package/internal/utils/path.mjs +74 -0
- package/internal/utils/path.mjs.map +1 -0
- package/internal/utils/sleep.d.mts.map +1 -1
- package/internal/utils/sleep.d.ts.map +1 -1
- package/internal/utils/uuid.d.mts +1 -1
- package/internal/utils/uuid.d.mts.map +1 -1
- package/internal/utils/uuid.d.ts +1 -1
- package/internal/utils/uuid.d.ts.map +1 -1
- package/internal/utils/uuid.js +10 -6
- package/internal/utils/uuid.js.map +1 -1
- package/internal/utils/uuid.mjs +9 -5
- package/internal/utils/uuid.mjs.map +1 -1
- package/internal/utils/values.d.mts +4 -1
- package/internal/utils/values.d.mts.map +1 -1
- package/internal/utils/values.d.ts +4 -1
- package/internal/utils/values.d.ts.map +1 -1
- package/internal/utils/values.js +21 -9
- package/internal/utils/values.js.map +1 -1
- package/internal/utils/values.mjs +14 -4
- package/internal/utils/values.mjs.map +1 -1
- package/internal/utils.js +7 -20
- package/internal/utils.js.map +1 -1
- package/package.json +31 -13
- package/resource.d.mts +1 -5
- package/resource.d.mts.map +1 -1
- package/resource.d.ts +1 -5
- package/resource.d.ts.map +1 -1
- package/resource.js +3 -8
- package/resource.js.map +1 -1
- package/resource.mjs +1 -6
- package/resource.mjs.map +1 -1
- package/resources/call.d.mts +17 -7
- package/resources/call.d.mts.map +1 -1
- package/resources/call.d.ts +17 -7
- package/resources/call.d.ts.map +1 -1
- package/resources/call.js +6 -5
- package/resources/call.js.map +1 -1
- package/resources/call.mjs +6 -5
- package/resources/call.mjs.map +1 -1
- package/resources/evaluation.d.mts +20 -8
- package/resources/evaluation.d.mts.map +1 -1
- package/resources/evaluation.d.ts +20 -8
- package/resources/evaluation.d.ts.map +1 -1
- package/resources/evaluation.js +5 -4
- package/resources/evaluation.js.map +1 -1
- package/resources/evaluation.mjs +5 -4
- package/resources/evaluation.mjs.map +1 -1
- package/resources/health.d.mts +2 -2
- package/resources/health.d.ts +2 -2
- package/resources/health.js +1 -1
- package/resources/health.js.map +1 -1
- package/resources/health.mjs +1 -1
- package/resources/integrations.d.mts +39 -6
- package/resources/integrations.d.mts.map +1 -1
- package/resources/integrations.d.ts +39 -6
- package/resources/integrations.d.ts.map +1 -1
- package/resources/integrations.js +26 -1
- package/resources/integrations.js.map +1 -1
- package/resources/integrations.mjs +26 -1
- package/resources/integrations.mjs.map +1 -1
- package/resources/metric.d.mts +2 -2
- package/resources/metric.d.ts +2 -2
- package/resources/metric.js +1 -1
- package/resources/metric.js.map +1 -1
- package/resources/metric.mjs +1 -1
- package/resources/persona.d.mts +45 -8
- package/resources/persona.d.mts.map +1 -1
- package/resources/persona.d.ts +45 -8
- package/resources/persona.d.ts.map +1 -1
- package/resources/persona.js +29 -3
- package/resources/persona.js.map +1 -1
- package/resources/persona.mjs +29 -3
- package/resources/persona.mjs.map +1 -1
- package/resources/simulation.d.mts +51 -5
- package/resources/simulation.d.mts.map +1 -1
- package/resources/simulation.d.ts +51 -5
- package/resources/simulation.d.ts.map +1 -1
- package/resources/simulation.js +45 -4
- package/resources/simulation.js.map +1 -1
- package/resources/simulation.mjs +45 -4
- package/resources/simulation.mjs.map +1 -1
- package/resources.d.mts +2 -0
- package/resources.d.mts.map +1 -0
- package/resources.d.ts +2 -0
- package/resources.d.ts.map +1 -0
- package/resources.js +5 -0
- package/resources.js.map +1 -0
- package/resources.mjs +2 -0
- package/resources.mjs.map +1 -0
- package/src/api-promise.ts +2 -92
- package/src/client.ts +207 -116
- package/src/core/README.md +3 -0
- package/src/core/api-promise.ts +92 -0
- package/src/core/error.ts +130 -0
- package/src/core/resource.ts +11 -0
- package/src/core/uploads.ts +2 -0
- package/src/error.ts +2 -130
- package/src/index.ts +3 -3
- package/src/internal/README.md +3 -0
- package/src/internal/builtin-types.ts +14 -0
- package/src/internal/detect-platform.ts +3 -3
- package/src/internal/errors.ts +11 -0
- package/src/internal/headers.ts +9 -8
- package/src/internal/parse.ts +43 -28
- package/src/internal/qs/formats.ts +2 -1
- package/src/internal/qs/stringify.ts +17 -20
- package/src/internal/qs/utils.ts +14 -14
- package/src/internal/request-options.ts +55 -31
- package/src/internal/shim-types.ts +26 -0
- package/src/internal/shims.ts +20 -58
- package/src/internal/to-file.ts +154 -0
- package/src/internal/types.ts +14 -17
- package/src/internal/uploads.ts +60 -180
- package/src/internal/utils/base64.ts +14 -11
- package/src/internal/utils/bytes.ts +32 -0
- package/src/internal/utils/log.ts +100 -23
- package/src/internal/utils/path.ts +88 -0
- package/src/internal/utils/uuid.ts +10 -6
- package/src/internal/utils/values.ts +16 -5
- package/src/resource.ts +2 -11
- package/src/resources/call.ts +12 -11
- package/src/resources/evaluation.ts +12 -11
- package/src/resources/health.ts +2 -2
- package/src/resources/integrations.ts +31 -6
- package/src/resources/metric.ts +2 -2
- package/src/resources/persona.ts +36 -10
- package/src/resources/simulation.ts +49 -8
- package/src/resources.ts +1 -0
- package/src/uploads.ts +2 -1
- package/src/version.ts +1 -1
- package/uploads.d.mts +1 -1
- package/uploads.d.mts.map +1 -1
- package/uploads.d.ts +1 -1
- package/uploads.d.ts.map +1 -1
- package/uploads.js +3 -3
- package/uploads.js.map +1 -1
- package/uploads.mjs +1 -1
- package/uploads.mjs.map +1 -1
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -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/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/shim-types.d.ts +0 -28
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
import { castToError } from '../internal/errors';
|
|
4
|
+
|
|
5
|
+
export class RoarkError extends Error {}
|
|
6
|
+
|
|
7
|
+
export class APIError<
|
|
8
|
+
TStatus extends number | undefined = number | undefined,
|
|
9
|
+
THeaders extends Headers | undefined = Headers | undefined,
|
|
10
|
+
TError extends Object | undefined = Object | undefined,
|
|
11
|
+
> extends RoarkError {
|
|
12
|
+
/** HTTP status for the response that caused the error */
|
|
13
|
+
readonly status: TStatus;
|
|
14
|
+
/** HTTP headers for the response that caused the error */
|
|
15
|
+
readonly headers: THeaders;
|
|
16
|
+
/** JSON body of the response that caused the error */
|
|
17
|
+
readonly error: TError;
|
|
18
|
+
|
|
19
|
+
constructor(status: TStatus, error: TError, message: string | undefined, headers: THeaders) {
|
|
20
|
+
super(`${APIError.makeMessage(status, error, message)}`);
|
|
21
|
+
this.status = status;
|
|
22
|
+
this.headers = headers;
|
|
23
|
+
this.error = error;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
private static makeMessage(status: number | undefined, error: any, message: string | undefined) {
|
|
27
|
+
const msg =
|
|
28
|
+
error?.message ?
|
|
29
|
+
typeof error.message === 'string' ?
|
|
30
|
+
error.message
|
|
31
|
+
: JSON.stringify(error.message)
|
|
32
|
+
: error ? JSON.stringify(error)
|
|
33
|
+
: message;
|
|
34
|
+
|
|
35
|
+
if (status && msg) {
|
|
36
|
+
return `${status} ${msg}`;
|
|
37
|
+
}
|
|
38
|
+
if (status) {
|
|
39
|
+
return `${status} status code (no body)`;
|
|
40
|
+
}
|
|
41
|
+
if (msg) {
|
|
42
|
+
return msg;
|
|
43
|
+
}
|
|
44
|
+
return '(no status code or body)';
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
static generate(
|
|
48
|
+
status: number | undefined,
|
|
49
|
+
errorResponse: Object | undefined,
|
|
50
|
+
message: string | undefined,
|
|
51
|
+
headers: Headers | undefined,
|
|
52
|
+
): APIError {
|
|
53
|
+
if (!status || !headers) {
|
|
54
|
+
return new APIConnectionError({ message, cause: castToError(errorResponse) });
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const error = errorResponse as Record<string, any>;
|
|
58
|
+
|
|
59
|
+
if (status === 400) {
|
|
60
|
+
return new BadRequestError(status, error, message, headers);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (status === 401) {
|
|
64
|
+
return new AuthenticationError(status, error, message, headers);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (status === 403) {
|
|
68
|
+
return new PermissionDeniedError(status, error, message, headers);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (status === 404) {
|
|
72
|
+
return new NotFoundError(status, error, message, headers);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (status === 409) {
|
|
76
|
+
return new ConflictError(status, error, message, headers);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (status === 422) {
|
|
80
|
+
return new UnprocessableEntityError(status, error, message, headers);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (status === 429) {
|
|
84
|
+
return new RateLimitError(status, error, message, headers);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (status >= 500) {
|
|
88
|
+
return new InternalServerError(status, error, message, headers);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return new APIError(status, error, message, headers);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export class APIUserAbortError extends APIError<undefined, undefined, undefined> {
|
|
96
|
+
constructor({ message }: { message?: string } = {}) {
|
|
97
|
+
super(undefined, undefined, message || 'Request was aborted.', undefined);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export class APIConnectionError extends APIError<undefined, undefined, undefined> {
|
|
102
|
+
constructor({ message, cause }: { message?: string | undefined; cause?: Error | undefined }) {
|
|
103
|
+
super(undefined, undefined, message || 'Connection error.', undefined);
|
|
104
|
+
// in some environments the 'cause' property is already declared
|
|
105
|
+
// @ts-ignore
|
|
106
|
+
if (cause) this.cause = cause;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export class APIConnectionTimeoutError extends APIConnectionError {
|
|
111
|
+
constructor({ message }: { message?: string } = {}) {
|
|
112
|
+
super({ message: message ?? 'Request timed out.' });
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export class BadRequestError extends APIError<400, Headers> {}
|
|
117
|
+
|
|
118
|
+
export class AuthenticationError extends APIError<401, Headers> {}
|
|
119
|
+
|
|
120
|
+
export class PermissionDeniedError extends APIError<403, Headers> {}
|
|
121
|
+
|
|
122
|
+
export class NotFoundError extends APIError<404, Headers> {}
|
|
123
|
+
|
|
124
|
+
export class ConflictError extends APIError<409, Headers> {}
|
|
125
|
+
|
|
126
|
+
export class UnprocessableEntityError extends APIError<422, Headers> {}
|
|
127
|
+
|
|
128
|
+
export class RateLimitError extends APIError<429, Headers> {}
|
|
129
|
+
|
|
130
|
+
export class InternalServerError extends APIError<number, Headers> {}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
import type { Roark } from '../client';
|
|
4
|
+
|
|
5
|
+
export abstract class APIResource {
|
|
6
|
+
protected _client: Roark;
|
|
7
|
+
|
|
8
|
+
constructor(client: Roark) {
|
|
9
|
+
this._client = client;
|
|
10
|
+
}
|
|
11
|
+
}
|
package/src/error.ts
CHANGED
|
@@ -1,130 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { castToError } from './internal/errors';
|
|
4
|
-
|
|
5
|
-
export class RoarkError extends Error {}
|
|
6
|
-
|
|
7
|
-
export class APIError<
|
|
8
|
-
TStatus extends number | undefined = number | undefined,
|
|
9
|
-
THeaders extends Headers | undefined = Headers | undefined,
|
|
10
|
-
TError extends Object | undefined = Object | undefined,
|
|
11
|
-
> extends RoarkError {
|
|
12
|
-
/** HTTP status for the response that caused the error */
|
|
13
|
-
readonly status: TStatus;
|
|
14
|
-
/** HTTP headers for the response that caused the error */
|
|
15
|
-
readonly headers: THeaders;
|
|
16
|
-
/** JSON body of the response that caused the error */
|
|
17
|
-
readonly error: TError;
|
|
18
|
-
|
|
19
|
-
constructor(status: TStatus, error: TError, message: string | undefined, headers: THeaders) {
|
|
20
|
-
super(`${APIError.makeMessage(status, error, message)}`);
|
|
21
|
-
this.status = status;
|
|
22
|
-
this.headers = headers;
|
|
23
|
-
this.error = error;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
private static makeMessage(status: number | undefined, error: any, message: string | undefined) {
|
|
27
|
-
const msg =
|
|
28
|
-
error?.message ?
|
|
29
|
-
typeof error.message === 'string' ?
|
|
30
|
-
error.message
|
|
31
|
-
: JSON.stringify(error.message)
|
|
32
|
-
: error ? JSON.stringify(error)
|
|
33
|
-
: message;
|
|
34
|
-
|
|
35
|
-
if (status && msg) {
|
|
36
|
-
return `${status} ${msg}`;
|
|
37
|
-
}
|
|
38
|
-
if (status) {
|
|
39
|
-
return `${status} status code (no body)`;
|
|
40
|
-
}
|
|
41
|
-
if (msg) {
|
|
42
|
-
return msg;
|
|
43
|
-
}
|
|
44
|
-
return '(no status code or body)';
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
static generate(
|
|
48
|
-
status: number | undefined,
|
|
49
|
-
errorResponse: Object | undefined,
|
|
50
|
-
message: string | undefined,
|
|
51
|
-
headers: Headers | undefined,
|
|
52
|
-
): APIError {
|
|
53
|
-
if (!status || !headers) {
|
|
54
|
-
return new APIConnectionError({ message, cause: castToError(errorResponse) });
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const error = errorResponse as Record<string, any>;
|
|
58
|
-
|
|
59
|
-
if (status === 400) {
|
|
60
|
-
return new BadRequestError(status, error, message, headers);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (status === 401) {
|
|
64
|
-
return new AuthenticationError(status, error, message, headers);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (status === 403) {
|
|
68
|
-
return new PermissionDeniedError(status, error, message, headers);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (status === 404) {
|
|
72
|
-
return new NotFoundError(status, error, message, headers);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (status === 409) {
|
|
76
|
-
return new ConflictError(status, error, message, headers);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (status === 422) {
|
|
80
|
-
return new UnprocessableEntityError(status, error, message, headers);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (status === 429) {
|
|
84
|
-
return new RateLimitError(status, error, message, headers);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if (status >= 500) {
|
|
88
|
-
return new InternalServerError(status, error, message, headers);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return new APIError(status, error, message, headers);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export class APIUserAbortError extends APIError<undefined, undefined, undefined> {
|
|
96
|
-
constructor({ message }: { message?: string } = {}) {
|
|
97
|
-
super(undefined, undefined, message || 'Request was aborted.', undefined);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export class APIConnectionError extends APIError<undefined, undefined, undefined> {
|
|
102
|
-
constructor({ message, cause }: { message?: string | undefined; cause?: Error | undefined }) {
|
|
103
|
-
super(undefined, undefined, message || 'Connection error.', undefined);
|
|
104
|
-
// in some environments the 'cause' property is already declared
|
|
105
|
-
// @ts-ignore
|
|
106
|
-
if (cause) this.cause = cause;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
export class APIConnectionTimeoutError extends APIConnectionError {
|
|
111
|
-
constructor({ message }: { message?: string } = {}) {
|
|
112
|
-
super({ message: message ?? 'Request timed out.' });
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export class BadRequestError extends APIError<400, Headers> {}
|
|
117
|
-
|
|
118
|
-
export class AuthenticationError extends APIError<401, Headers> {}
|
|
119
|
-
|
|
120
|
-
export class PermissionDeniedError extends APIError<403, Headers> {}
|
|
121
|
-
|
|
122
|
-
export class NotFoundError extends APIError<404, Headers> {}
|
|
123
|
-
|
|
124
|
-
export class ConflictError extends APIError<409, Headers> {}
|
|
125
|
-
|
|
126
|
-
export class UnprocessableEntityError extends APIError<422, Headers> {}
|
|
127
|
-
|
|
128
|
-
export class RateLimitError extends APIError<429, Headers> {}
|
|
129
|
-
|
|
130
|
-
export class InternalServerError extends APIError<number, Headers> {}
|
|
1
|
+
/** @deprecated Import from ./core/error instead */
|
|
2
|
+
export * from './core/error';
|
package/src/index.ts
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
export { Roark as default } from './client';
|
|
4
4
|
|
|
5
|
-
export { type Uploadable, toFile } from './uploads';
|
|
6
|
-
export { APIPromise } from './api-promise';
|
|
5
|
+
export { type Uploadable, toFile } from './core/uploads';
|
|
6
|
+
export { APIPromise } from './core/api-promise';
|
|
7
7
|
export { Roark, type ClientOptions } from './client';
|
|
8
8
|
export {
|
|
9
9
|
RoarkError,
|
|
@@ -19,4 +19,4 @@ export {
|
|
|
19
19
|
InternalServerError,
|
|
20
20
|
PermissionDeniedError,
|
|
21
21
|
UnprocessableEntityError,
|
|
22
|
-
} from './error';
|
|
22
|
+
} from './core/error';
|
|
@@ -39,9 +39,23 @@ type _HeadersInit = RequestInit['headers'];
|
|
|
39
39
|
*/
|
|
40
40
|
type _BodyInit = RequestInit['body'];
|
|
41
41
|
|
|
42
|
+
/**
|
|
43
|
+
* An alias to the builtin `Array<T>` type so we can
|
|
44
|
+
* easily alias it in import statements if there are name clashes.
|
|
45
|
+
*/
|
|
46
|
+
type _Array<T> = Array<T>;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* An alias to the builtin `Record<K, T>` type so we can
|
|
50
|
+
* easily alias it in import statements if there are name clashes.
|
|
51
|
+
*/
|
|
52
|
+
type _Record<K extends keyof any, T> = Record<K, T>;
|
|
53
|
+
|
|
42
54
|
export type {
|
|
55
|
+
_Array as Array,
|
|
43
56
|
_BodyInit as BodyInit,
|
|
44
57
|
_HeadersInit as HeadersInit,
|
|
58
|
+
_Record as Record,
|
|
45
59
|
_RequestInfo as RequestInfo,
|
|
46
60
|
_RequestInit as RequestInit,
|
|
47
61
|
_Response as Response,
|
|
@@ -85,10 +85,10 @@ const getPlatformProperties = (): PlatformProperties => {
|
|
|
85
85
|
return {
|
|
86
86
|
'X-Stainless-Lang': 'js',
|
|
87
87
|
'X-Stainless-Package-Version': VERSION,
|
|
88
|
-
'X-Stainless-OS': normalizePlatform((globalThis as any).process.platform),
|
|
89
|
-
'X-Stainless-Arch': normalizeArch((globalThis as any).process.arch),
|
|
88
|
+
'X-Stainless-OS': normalizePlatform((globalThis as any).process.platform ?? 'unknown'),
|
|
89
|
+
'X-Stainless-Arch': normalizeArch((globalThis as any).process.arch ?? 'unknown'),
|
|
90
90
|
'X-Stainless-Runtime': 'node',
|
|
91
|
-
'X-Stainless-Runtime-Version': (globalThis as any).process.version,
|
|
91
|
+
'X-Stainless-Runtime-Version': (globalThis as any).process.version ?? 'unknown',
|
|
92
92
|
};
|
|
93
93
|
}
|
|
94
94
|
|
package/src/internal/errors.ts
CHANGED
|
@@ -14,6 +14,17 @@ export function isAbortError(err: unknown) {
|
|
|
14
14
|
export const castToError = (err: any): Error => {
|
|
15
15
|
if (err instanceof Error) return err;
|
|
16
16
|
if (typeof err === 'object' && err !== null) {
|
|
17
|
+
try {
|
|
18
|
+
if (Object.prototype.toString.call(err) === '[object Error]') {
|
|
19
|
+
// @ts-ignore - not all envs have native support for cause yet
|
|
20
|
+
const error = new Error(err.message, err.cause ? { cause: err.cause } : {});
|
|
21
|
+
if (err.stack) error.stack = err.stack;
|
|
22
|
+
// @ts-ignore - not all envs have native support for cause yet
|
|
23
|
+
if (err.cause && !error.cause) error.cause = err.cause;
|
|
24
|
+
if (err.name) error.name = err.name;
|
|
25
|
+
return error;
|
|
26
|
+
}
|
|
27
|
+
} catch {}
|
|
17
28
|
try {
|
|
18
29
|
return new Error(JSON.stringify(err));
|
|
19
30
|
} catch {}
|
package/src/internal/headers.ts
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
+
import { isReadonlyArray } from './utils/values';
|
|
4
|
+
|
|
3
5
|
type HeaderValue = string | undefined | null;
|
|
4
6
|
export type HeadersLike =
|
|
5
7
|
| Headers
|
|
6
|
-
| readonly [
|
|
8
|
+
| readonly HeaderValue[][]
|
|
7
9
|
| Record<string, HeaderValue | readonly HeaderValue[]>
|
|
8
10
|
| undefined
|
|
9
11
|
| null
|
|
10
12
|
| NullableHeaders;
|
|
11
13
|
|
|
12
|
-
const brand_privateNullableHeaders = Symbol('brand.privateNullableHeaders');
|
|
14
|
+
const brand_privateNullableHeaders = /* @__PURE__ */ Symbol('brand.privateNullableHeaders');
|
|
13
15
|
|
|
14
16
|
/**
|
|
15
17
|
* @internal
|
|
@@ -25,8 +27,6 @@ export type NullableHeaders = {
|
|
|
25
27
|
nulls: Set<string>;
|
|
26
28
|
};
|
|
27
29
|
|
|
28
|
-
const isArray = Array.isArray as (val: unknown) => val is readonly unknown[];
|
|
29
|
-
|
|
30
30
|
function* iterateHeaders(headers: HeadersLike): IterableIterator<readonly [string, string | null]> {
|
|
31
31
|
if (!headers) return;
|
|
32
32
|
|
|
@@ -40,10 +40,10 @@ function* iterateHeaders(headers: HeadersLike): IterableIterator<readonly [strin
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
let shouldClear = false;
|
|
43
|
-
let iter: Iterable<readonly
|
|
43
|
+
let iter: Iterable<readonly (HeaderValue | readonly HeaderValue[])[]>;
|
|
44
44
|
if (headers instanceof Headers) {
|
|
45
45
|
iter = headers.entries();
|
|
46
|
-
} else if (
|
|
46
|
+
} else if (isReadonlyArray(headers)) {
|
|
47
47
|
iter = headers;
|
|
48
48
|
} else {
|
|
49
49
|
shouldClear = true;
|
|
@@ -51,7 +51,8 @@ function* iterateHeaders(headers: HeadersLike): IterableIterator<readonly [strin
|
|
|
51
51
|
}
|
|
52
52
|
for (let row of iter) {
|
|
53
53
|
const name = row[0];
|
|
54
|
-
|
|
54
|
+
if (typeof name !== 'string') throw new TypeError('expected header name to be a string');
|
|
55
|
+
const values = isReadonlyArray(row[1]) ? row[1] : [row[1]];
|
|
55
56
|
let didClear = false;
|
|
56
57
|
for (const value of values) {
|
|
57
58
|
if (value === undefined) continue;
|
|
@@ -70,8 +71,8 @@ function* iterateHeaders(headers: HeadersLike): IterableIterator<readonly [strin
|
|
|
70
71
|
export const buildHeaders = (newHeaders: HeadersLike[]): NullableHeaders => {
|
|
71
72
|
const targetHeaders = new Headers();
|
|
72
73
|
const nullHeaders = new Set<string>();
|
|
73
|
-
const seenHeaders = new Set<string>();
|
|
74
74
|
for (const headers of newHeaders) {
|
|
75
|
+
const seenHeaders = new Set<string>();
|
|
75
76
|
for (const [name, value] of iterateHeaders(headers)) {
|
|
76
77
|
const lowerName = name.toLowerCase();
|
|
77
78
|
if (!seenHeaders.has(lowerName)) {
|
package/src/internal/parse.ts
CHANGED
|
@@ -2,40 +2,55 @@
|
|
|
2
2
|
|
|
3
3
|
import type { FinalRequestOptions } from './request-options';
|
|
4
4
|
import { type Roark } from '../client';
|
|
5
|
-
import {
|
|
5
|
+
import { formatRequestDetails, loggerFor } from './utils/log';
|
|
6
6
|
|
|
7
7
|
export type APIResponseProps = {
|
|
8
8
|
response: Response;
|
|
9
9
|
options: FinalRequestOptions;
|
|
10
10
|
controller: AbortController;
|
|
11
|
+
requestLogID: string;
|
|
12
|
+
retryOfRequestLogID: string | undefined;
|
|
13
|
+
startTime: number;
|
|
11
14
|
};
|
|
12
15
|
|
|
13
16
|
export async function defaultParseResponse<T>(client: Roark, props: APIResponseProps): Promise<T> {
|
|
14
|
-
const { response } = props;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
17
|
+
const { response, requestLogID, retryOfRequestLogID, startTime } = props;
|
|
18
|
+
const body = await (async () => {
|
|
19
|
+
// fetch refuses to read the body when the status code is 204.
|
|
20
|
+
if (response.status === 204) {
|
|
21
|
+
return null as T;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (props.options.__binaryResponse) {
|
|
25
|
+
return response as unknown as T;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const contentType = response.headers.get('content-type');
|
|
29
|
+
const mediaType = contentType?.split(';')[0]?.trim();
|
|
30
|
+
const isJSON = mediaType?.includes('application/json') || mediaType?.endsWith('+json');
|
|
31
|
+
if (isJSON) {
|
|
32
|
+
const contentLength = response.headers.get('content-length');
|
|
33
|
+
if (contentLength === '0') {
|
|
34
|
+
// if there is no content we can't do anything
|
|
35
|
+
return undefined as T;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const json = await response.json();
|
|
39
|
+
return json as T;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const text = await response.text();
|
|
43
|
+
return text as unknown as T;
|
|
44
|
+
})();
|
|
45
|
+
loggerFor(client).debug(
|
|
46
|
+
`[${requestLogID}] response parsed`,
|
|
47
|
+
formatRequestDetails({
|
|
48
|
+
retryOfRequestLogID,
|
|
49
|
+
url: response.url,
|
|
50
|
+
status: response.status,
|
|
51
|
+
body,
|
|
52
|
+
durationMs: Date.now() - startTime,
|
|
53
|
+
}),
|
|
54
|
+
);
|
|
55
|
+
return body;
|
|
41
56
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { Format } from './types';
|
|
2
2
|
|
|
3
3
|
export const default_format: Format = 'RFC3986';
|
|
4
|
+
export const default_formatter = (v: PropertyKey) => String(v);
|
|
4
5
|
export const formatters: Record<Format, (str: PropertyKey) => string> = {
|
|
5
6
|
RFC1738: (v: PropertyKey) => String(v).replace(/%20/g, '+'),
|
|
6
|
-
RFC3986:
|
|
7
|
+
RFC3986: default_formatter,
|
|
7
8
|
};
|
|
8
9
|
export const RFC1738 = 'RFC1738';
|
|
9
10
|
export const RFC3986 = 'RFC3986';
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { encode, is_buffer, maybe_map } from './utils';
|
|
2
|
-
import { default_format, formatters } from './formats';
|
|
1
|
+
import { encode, is_buffer, maybe_map, has } from './utils';
|
|
2
|
+
import { default_format, default_formatter, formatters } from './formats';
|
|
3
3
|
import type { NonNullableProperties, StringifyOptions } from './types';
|
|
4
|
-
|
|
5
|
-
const has = Object.prototype.hasOwnProperty;
|
|
4
|
+
import { isArray } from '../utils/values';
|
|
6
5
|
|
|
7
6
|
const array_prefix_generators = {
|
|
8
7
|
brackets(prefix: PropertyKey) {
|
|
@@ -17,13 +16,11 @@ const array_prefix_generators = {
|
|
|
17
16
|
},
|
|
18
17
|
};
|
|
19
18
|
|
|
20
|
-
const is_array = Array.isArray;
|
|
21
|
-
const push = Array.prototype.push;
|
|
22
19
|
const push_to_array = function (arr: any[], value_or_array: any) {
|
|
23
|
-
push.apply(arr,
|
|
20
|
+
Array.prototype.push.apply(arr, isArray(value_or_array) ? value_or_array : [value_or_array]);
|
|
24
21
|
};
|
|
25
22
|
|
|
26
|
-
|
|
23
|
+
let toISOString;
|
|
27
24
|
|
|
28
25
|
const defaults = {
|
|
29
26
|
addQueryPrefix: false,
|
|
@@ -38,11 +35,11 @@ const defaults = {
|
|
|
38
35
|
encoder: encode,
|
|
39
36
|
encodeValuesOnly: false,
|
|
40
37
|
format: default_format,
|
|
41
|
-
formatter:
|
|
38
|
+
formatter: default_formatter,
|
|
42
39
|
/** @deprecated */
|
|
43
40
|
indices: false,
|
|
44
41
|
serializeDate(date) {
|
|
45
|
-
return
|
|
42
|
+
return (toISOString ??= Function.prototype.call.bind(Date.prototype.toISOString))(date);
|
|
46
43
|
},
|
|
47
44
|
skipNulls: false,
|
|
48
45
|
strictNullHandling: false,
|
|
@@ -105,7 +102,7 @@ function inner_stringify(
|
|
|
105
102
|
obj = filter(prefix, obj);
|
|
106
103
|
} else if (obj instanceof Date) {
|
|
107
104
|
obj = serializeDate?.(obj);
|
|
108
|
-
} else if (generateArrayPrefix === 'comma' &&
|
|
105
|
+
} else if (generateArrayPrefix === 'comma' && isArray(obj)) {
|
|
109
106
|
obj = maybe_map(obj, function (value) {
|
|
110
107
|
if (value instanceof Date) {
|
|
111
108
|
return serializeDate?.(value);
|
|
@@ -148,14 +145,14 @@ function inner_stringify(
|
|
|
148
145
|
}
|
|
149
146
|
|
|
150
147
|
let obj_keys;
|
|
151
|
-
if (generateArrayPrefix === 'comma' &&
|
|
148
|
+
if (generateArrayPrefix === 'comma' && isArray(obj)) {
|
|
152
149
|
// we need to join elements in
|
|
153
150
|
if (encodeValuesOnly && encoder) {
|
|
154
151
|
// @ts-expect-error values only
|
|
155
152
|
obj = maybe_map(obj, encoder);
|
|
156
153
|
}
|
|
157
154
|
obj_keys = [{ value: obj.length > 0 ? obj.join(',') || null : void undefined }];
|
|
158
|
-
} else if (
|
|
155
|
+
} else if (isArray(filter)) {
|
|
159
156
|
obj_keys = filter;
|
|
160
157
|
} else {
|
|
161
158
|
const keys = Object.keys(obj);
|
|
@@ -165,9 +162,9 @@ function inner_stringify(
|
|
|
165
162
|
const encoded_prefix = encodeDotInKeys ? String(prefix).replace(/\./g, '%2E') : String(prefix);
|
|
166
163
|
|
|
167
164
|
const adjusted_prefix =
|
|
168
|
-
commaRoundTrip &&
|
|
165
|
+
commaRoundTrip && isArray(obj) && obj.length === 1 ? encoded_prefix + '[]' : encoded_prefix;
|
|
169
166
|
|
|
170
|
-
if (allowEmptyArrays &&
|
|
167
|
+
if (allowEmptyArrays && isArray(obj) && obj.length === 0) {
|
|
171
168
|
return adjusted_prefix + '[]';
|
|
172
169
|
}
|
|
173
170
|
|
|
@@ -184,7 +181,7 @@ function inner_stringify(
|
|
|
184
181
|
// @ts-ignore
|
|
185
182
|
const encoded_key = allowDots && encodeDotInKeys ? (key as any).replace(/\./g, '%2E') : key;
|
|
186
183
|
const key_prefix =
|
|
187
|
-
|
|
184
|
+
isArray(obj) ?
|
|
188
185
|
typeof generateArrayPrefix === 'function' ?
|
|
189
186
|
generateArrayPrefix(adjusted_prefix, encoded_key)
|
|
190
187
|
: adjusted_prefix
|
|
@@ -205,7 +202,7 @@ function inner_stringify(
|
|
|
205
202
|
skipNulls,
|
|
206
203
|
encodeDotInKeys,
|
|
207
204
|
// @ts-ignore
|
|
208
|
-
generateArrayPrefix === 'comma' && encodeValuesOnly &&
|
|
205
|
+
generateArrayPrefix === 'comma' && encodeValuesOnly && isArray(obj) ? null : encoder,
|
|
209
206
|
filter,
|
|
210
207
|
sort,
|
|
211
208
|
allowDots,
|
|
@@ -244,7 +241,7 @@ function normalize_stringify_options(
|
|
|
244
241
|
|
|
245
242
|
let format = default_format;
|
|
246
243
|
if (typeof opts.format !== 'undefined') {
|
|
247
|
-
if (!has
|
|
244
|
+
if (!has(formatters, opts.format)) {
|
|
248
245
|
throw new TypeError('Unknown format option provided.');
|
|
249
246
|
}
|
|
250
247
|
format = opts.format;
|
|
@@ -252,7 +249,7 @@ function normalize_stringify_options(
|
|
|
252
249
|
const formatter = formatters[format];
|
|
253
250
|
|
|
254
251
|
let filter = defaults.filter;
|
|
255
|
-
if (typeof opts.filter === 'function' ||
|
|
252
|
+
if (typeof opts.filter === 'function' || isArray(opts.filter)) {
|
|
256
253
|
filter = opts.filter;
|
|
257
254
|
}
|
|
258
255
|
|
|
@@ -316,7 +313,7 @@ export function stringify(object: any, opts: StringifyOptions = {}) {
|
|
|
316
313
|
if (typeof options.filter === 'function') {
|
|
317
314
|
filter = options.filter;
|
|
318
315
|
obj = filter('', obj);
|
|
319
|
-
} else if (
|
|
316
|
+
} else if (isArray(options.filter)) {
|
|
320
317
|
filter = options.filter;
|
|
321
318
|
obj_keys = filter;
|
|
322
319
|
}
|