@timbereye/sdk 0.0.0-stage → 0.2.0
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 +123 -0
- package/LICENSE +202 -0
- package/README.md +346 -2
- package/dist/cjs/case.d.ts +23 -0
- package/dist/cjs/case.js +54 -0
- package/dist/cjs/client.d.ts +98 -0
- package/dist/cjs/client.js +132 -0
- package/dist/cjs/errors.d.ts +63 -0
- package/dist/cjs/errors.js +107 -0
- package/dist/cjs/generated/schema.d.ts +14862 -0
- package/dist/cjs/generated/schema.js +6 -0
- package/dist/cjs/http.d.ts +104 -0
- package/dist/cjs/http.js +253 -0
- package/dist/cjs/index.d.ts +14 -0
- package/dist/cjs/index.js +29 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/pagination.d.ts +31 -0
- package/dist/cjs/pagination.js +52 -0
- package/dist/cjs/resources.d.ts +11195 -0
- package/dist/cjs/resources.js +506 -0
- package/dist/cjs/runtime.d.ts +20 -0
- package/dist/cjs/runtime.js +74 -0
- package/dist/cjs/types.d.ts +649 -0
- package/dist/cjs/types.js +2 -0
- package/dist/cjs/units.d.ts +26 -0
- package/dist/cjs/units.js +45 -0
- package/dist/cjs/webhooks.d.ts +67 -0
- package/dist/cjs/webhooks.js +213 -0
- package/dist/esm/case.d.ts +23 -0
- package/dist/esm/case.js +47 -0
- package/dist/esm/client.d.ts +98 -0
- package/dist/esm/client.js +128 -0
- package/dist/esm/errors.d.ts +63 -0
- package/dist/esm/errors.js +93 -0
- package/dist/esm/generated/schema.d.ts +14862 -0
- package/dist/esm/generated/schema.js +5 -0
- package/dist/esm/http.d.ts +104 -0
- package/dist/esm/http.js +247 -0
- package/dist/esm/index.d.ts +14 -0
- package/dist/esm/index.js +6 -0
- package/dist/esm/pagination.d.ts +31 -0
- package/dist/esm/pagination.js +49 -0
- package/dist/esm/resources.d.ts +11195 -0
- package/dist/esm/resources.js +503 -0
- package/dist/esm/runtime.d.ts +20 -0
- package/dist/esm/runtime.js +46 -0
- package/dist/esm/types.d.ts +649 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/units.d.ts +26 -0
- package/dist/esm/units.js +38 -0
- package/dist/esm/webhooks.d.ts +67 -0
- package/dist/esm/webhooks.js +208 -0
- package/package.json +51 -5
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export type ErrorType = "invalid_request_error" | "authentication_error" | "permission_error" | "rate_limit_error" | "api_error";
|
|
2
|
+
export interface ErrorInit {
|
|
3
|
+
message: string;
|
|
4
|
+
type?: string;
|
|
5
|
+
code?: string | null;
|
|
6
|
+
param?: string | null;
|
|
7
|
+
requestId?: string | null;
|
|
8
|
+
status?: number;
|
|
9
|
+
docUrl?: string | null;
|
|
10
|
+
existingId?: string | null;
|
|
11
|
+
}
|
|
12
|
+
/** Base class of everything the SDK throws on purpose. */
|
|
13
|
+
export declare class TimbereyeError extends Error {
|
|
14
|
+
/** The API's error `type`, or a client-side marker for errors raised in the SDK. */
|
|
15
|
+
readonly type: string;
|
|
16
|
+
/** Stable machine-readable code. Unknown codes may appear within v1: treat them as the generic case. */
|
|
17
|
+
readonly code: string | null;
|
|
18
|
+
/** The request field at fault, with dots for nesting (`defaults.length_m`). Wire names, not camelCase. */
|
|
19
|
+
readonly param: string | null;
|
|
20
|
+
/** The `Request-Id` of the failed request. Quote it to support. */
|
|
21
|
+
readonly requestId: string | null;
|
|
22
|
+
/** HTTP status, or undefined when no response was received. */
|
|
23
|
+
readonly status: number | undefined;
|
|
24
|
+
readonly docUrl: string | null;
|
|
25
|
+
/** For `external_ref_in_use`: the open group that already has the reference (`grp_…`). */
|
|
26
|
+
readonly existingId: string | null;
|
|
27
|
+
constructor(init: ErrorInit);
|
|
28
|
+
}
|
|
29
|
+
/** 400, 404, 409, 412, 413, 422. */
|
|
30
|
+
export declare class InvalidRequestError extends TimbereyeError {
|
|
31
|
+
}
|
|
32
|
+
/** 401. */
|
|
33
|
+
export declare class AuthenticationError extends TimbereyeError {
|
|
34
|
+
}
|
|
35
|
+
/** 403. */
|
|
36
|
+
export declare class PermissionError extends TimbereyeError {
|
|
37
|
+
}
|
|
38
|
+
/** 429. `retryAfterSeconds` is the server's `Retry-After`, when sent. */
|
|
39
|
+
export declare class RateLimitError extends TimbereyeError {
|
|
40
|
+
retryAfterSeconds: number | null;
|
|
41
|
+
}
|
|
42
|
+
/** 5xx. */
|
|
43
|
+
export declare class ApiError extends TimbereyeError {
|
|
44
|
+
}
|
|
45
|
+
/** No usable response: DNS, connection reset, TLS, or the body could not be read. */
|
|
46
|
+
export declare class ConnectionError extends TimbereyeError {
|
|
47
|
+
readonly cause: unknown;
|
|
48
|
+
constructor(message: string, cause?: unknown, type?: string);
|
|
49
|
+
}
|
|
50
|
+
/** The per-attempt `timeoutMs` elapsed. */
|
|
51
|
+
export declare class TimeoutError extends ConnectionError {
|
|
52
|
+
constructor(timeoutMs: number);
|
|
53
|
+
}
|
|
54
|
+
/** The caller's `AbortSignal` fired. Never retried. */
|
|
55
|
+
export declare class AbortError extends TimbereyeError {
|
|
56
|
+
constructor();
|
|
57
|
+
}
|
|
58
|
+
/** A webhook failed verification. `code` says why. */
|
|
59
|
+
export declare class WebhookSignatureError extends TimbereyeError {
|
|
60
|
+
constructor(code: string, message: string);
|
|
61
|
+
}
|
|
62
|
+
/** Build the error for a non-2xx response. `body` is the parsed JSON, if the body was JSON. */
|
|
63
|
+
export declare function errorFromResponse(status: number, body: unknown, requestIdHeader: string | null): TimbereyeError;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/** Base class of everything the SDK throws on purpose. */
|
|
2
|
+
export class TimbereyeError extends Error {
|
|
3
|
+
constructor(init) {
|
|
4
|
+
super(init.message);
|
|
5
|
+
this.name = new.target.name;
|
|
6
|
+
this.type = init.type ?? "client_error";
|
|
7
|
+
this.code = init.code ?? null;
|
|
8
|
+
this.param = init.param ?? null;
|
|
9
|
+
this.requestId = init.requestId ?? null;
|
|
10
|
+
this.status = init.status;
|
|
11
|
+
this.docUrl = init.docUrl ?? null;
|
|
12
|
+
this.existingId = init.existingId ?? null;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/** 400, 404, 409, 412, 413, 422. */
|
|
16
|
+
export class InvalidRequestError extends TimbereyeError {
|
|
17
|
+
}
|
|
18
|
+
/** 401. */
|
|
19
|
+
export class AuthenticationError extends TimbereyeError {
|
|
20
|
+
}
|
|
21
|
+
/** 403. */
|
|
22
|
+
export class PermissionError extends TimbereyeError {
|
|
23
|
+
}
|
|
24
|
+
/** 429. `retryAfterSeconds` is the server's `Retry-After`, when sent. */
|
|
25
|
+
export class RateLimitError extends TimbereyeError {
|
|
26
|
+
constructor() {
|
|
27
|
+
super(...arguments);
|
|
28
|
+
this.retryAfterSeconds = null;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/** 5xx. */
|
|
32
|
+
export class ApiError extends TimbereyeError {
|
|
33
|
+
}
|
|
34
|
+
/** No usable response: DNS, connection reset, TLS, or the body could not be read. */
|
|
35
|
+
export class ConnectionError extends TimbereyeError {
|
|
36
|
+
constructor(message, cause, type = "connection_error") {
|
|
37
|
+
super({ message, type });
|
|
38
|
+
this.cause = cause;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/** The per-attempt `timeoutMs` elapsed. */
|
|
42
|
+
export class TimeoutError extends ConnectionError {
|
|
43
|
+
constructor(timeoutMs) {
|
|
44
|
+
super(`Request timed out after ${timeoutMs} ms`, undefined, "timeout_error");
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/** The caller's `AbortSignal` fired. Never retried. */
|
|
48
|
+
export class AbortError extends TimbereyeError {
|
|
49
|
+
constructor() {
|
|
50
|
+
super({ message: "Request aborted", type: "abort_error" });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/** A webhook failed verification. `code` says why. */
|
|
54
|
+
export class WebhookSignatureError extends TimbereyeError {
|
|
55
|
+
constructor(code, message) {
|
|
56
|
+
super({ message, type: "webhook_signature_error", code });
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const BY_TYPE = {
|
|
60
|
+
invalid_request_error: InvalidRequestError,
|
|
61
|
+
authentication_error: AuthenticationError,
|
|
62
|
+
permission_error: PermissionError,
|
|
63
|
+
rate_limit_error: RateLimitError,
|
|
64
|
+
api_error: ApiError,
|
|
65
|
+
};
|
|
66
|
+
function typeFromStatus(status) {
|
|
67
|
+
if (status === 401)
|
|
68
|
+
return "authentication_error";
|
|
69
|
+
if (status === 403)
|
|
70
|
+
return "permission_error";
|
|
71
|
+
if (status === 429)
|
|
72
|
+
return "rate_limit_error";
|
|
73
|
+
if (status >= 500)
|
|
74
|
+
return "api_error";
|
|
75
|
+
return "invalid_request_error";
|
|
76
|
+
}
|
|
77
|
+
/** Build the error for a non-2xx response. `body` is the parsed JSON, if the body was JSON. */
|
|
78
|
+
export function errorFromResponse(status, body, requestIdHeader) {
|
|
79
|
+
const e = body?.error;
|
|
80
|
+
const err = e && typeof e === "object" ? e : {};
|
|
81
|
+
const type = typeof err.type === "string" && err.type in BY_TYPE ? err.type : typeFromStatus(status);
|
|
82
|
+
const Cls = BY_TYPE[type] ?? TimbereyeError;
|
|
83
|
+
return new Cls({
|
|
84
|
+
message: typeof err.message === "string" ? err.message : `Request failed with status ${status}`,
|
|
85
|
+
type,
|
|
86
|
+
code: typeof err.code === "string" ? err.code : null,
|
|
87
|
+
param: typeof err.param === "string" ? err.param : null,
|
|
88
|
+
requestId: typeof err.request_id === "string" ? err.request_id : requestIdHeader,
|
|
89
|
+
docUrl: typeof err.doc_url === "string" ? err.doc_url : null,
|
|
90
|
+
existingId: typeof err.existing_id === "string" ? err.existing_id : null,
|
|
91
|
+
status,
|
|
92
|
+
});
|
|
93
|
+
}
|