@shardflux/sdk 0.5.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/LICENSE +202 -0
- package/README.md +162 -0
- package/dist/audit.d.ts +74 -0
- package/dist/audit.js +49 -0
- package/dist/cell.d.ts +195 -0
- package/dist/cell.js +408 -0
- package/dist/client.d.ts +212 -0
- package/dist/client.js +238 -0
- package/dist/egress.d.ts +152 -0
- package/dist/egress.js +37 -0
- package/dist/errors.d.ts +57 -0
- package/dist/errors.js +73 -0
- package/dist/generated/app-api.d.ts +23479 -0
- package/dist/generated/app-api.js +5 -0
- package/dist/generated/cell-api.d.ts +1832 -0
- package/dist/generated/cell-api.js +5 -0
- package/dist/http.d.ts +39 -0
- package/dist/http.js +121 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.js +13 -0
- package/dist/secrets.d.ts +100 -0
- package/dist/secrets.js +56 -0
- package/dist/templates.d.ts +328 -0
- package/dist/templates.js +117 -0
- package/dist/tokens.d.ts +35 -0
- package/dist/tokens.js +61 -0
- package/dist/tools.d.ts +91 -0
- package/dist/tools.js +313 -0
- package/dist/usage.d.ts +60 -0
- package/dist/usage.js +45 -0
- package/dist/volumes.d.ts +108 -0
- package/dist/volumes.js +120 -0
- package/dist/workspace.d.ts +70 -0
- package/dist/workspace.js +113 -0
- package/package.json +56 -0
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { components as AppComponents } from './generated/app-api.js';
|
|
2
|
+
import type { components as CellComponents } from './generated/cell-api.js';
|
|
3
|
+
export type AppErrorBody = AppComponents['schemas']['ErrorBody'];
|
|
4
|
+
export type AppErrorCode = AppErrorBody['error']['code'];
|
|
5
|
+
export type CellErrorCode = CellComponents['schemas']['ErrorCode'];
|
|
6
|
+
/** Closed error codes of the application API and the cell gateway (both published in OpenAPI). */
|
|
7
|
+
export type ErrorCode = AppErrorCode | CellErrorCode;
|
|
8
|
+
export interface ErrorBodyLike {
|
|
9
|
+
error: {
|
|
10
|
+
code: string;
|
|
11
|
+
message: string;
|
|
12
|
+
request_id: string;
|
|
13
|
+
retryable: boolean;
|
|
14
|
+
operation_id?: string;
|
|
15
|
+
details?: Record<string, unknown>;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export declare function isErrorBody(v: unknown): v is ErrorBodyLike;
|
|
19
|
+
/** A structured error from the application API or a cell gateway (contracts §3). */
|
|
20
|
+
export declare class ShardfluxApiError extends Error {
|
|
21
|
+
readonly status: number;
|
|
22
|
+
readonly code: ErrorCode;
|
|
23
|
+
readonly requestId: string;
|
|
24
|
+
readonly retryable: boolean;
|
|
25
|
+
readonly details: Record<string, unknown> | undefined;
|
|
26
|
+
readonly operationId: string | undefined;
|
|
27
|
+
readonly source: 'api' | 'cell';
|
|
28
|
+
readonly retryAfterSeconds: number | undefined;
|
|
29
|
+
constructor(status: number, body: ErrorBodyLike, source: 'api' | 'cell', retryAfterSeconds?: number);
|
|
30
|
+
}
|
|
31
|
+
/** The response was not the documented shape (e.g. a proxy error page). */
|
|
32
|
+
export declare class ShardfluxProtocolError extends Error {
|
|
33
|
+
readonly status: number;
|
|
34
|
+
constructor(message: string, status: number);
|
|
35
|
+
}
|
|
36
|
+
type Operation = AppComponents['schemas']['Operation'];
|
|
37
|
+
/**
|
|
38
|
+
* Waiting for an operation ran out of time. The operation keeps running server side:
|
|
39
|
+
* resume with `cloud.workspaces.waitForOperation(err.operationId)` or call open() again
|
|
40
|
+
* (it returns the same operation while it is active).
|
|
41
|
+
*/
|
|
42
|
+
export declare class OperationTimeoutError extends Error {
|
|
43
|
+
readonly operationId: string;
|
|
44
|
+
readonly workspaceId: string | null;
|
|
45
|
+
readonly lastState: Operation['state'];
|
|
46
|
+
readonly lastReason: string | null;
|
|
47
|
+
readonly waitedMs: number;
|
|
48
|
+
constructor(op: Operation, waitedMs: number);
|
|
49
|
+
}
|
|
50
|
+
/** The operation reached `failed` or `canceled`. */
|
|
51
|
+
export declare class OperationFailedError extends Error {
|
|
52
|
+
readonly operation: Operation;
|
|
53
|
+
readonly operationId: string;
|
|
54
|
+
readonly errorCode: string | null;
|
|
55
|
+
constructor(op: Operation);
|
|
56
|
+
}
|
|
57
|
+
export {};
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export function isErrorBody(v) {
|
|
2
|
+
if (typeof v !== 'object' || v === null || !('error' in v))
|
|
3
|
+
return false;
|
|
4
|
+
const e = v.error;
|
|
5
|
+
return typeof e === 'object' && e !== null && typeof e.code === 'string' && typeof e.message === 'string';
|
|
6
|
+
}
|
|
7
|
+
/** A structured error from the application API or a cell gateway (contracts §3). */
|
|
8
|
+
export class ShardfluxApiError extends Error {
|
|
9
|
+
status;
|
|
10
|
+
code;
|
|
11
|
+
requestId;
|
|
12
|
+
retryable;
|
|
13
|
+
details;
|
|
14
|
+
operationId;
|
|
15
|
+
source;
|
|
16
|
+
retryAfterSeconds;
|
|
17
|
+
constructor(status, body, source, retryAfterSeconds) {
|
|
18
|
+
super(body.error.message);
|
|
19
|
+
this.name = 'ShardfluxApiError';
|
|
20
|
+
this.status = status;
|
|
21
|
+
this.code = body.error.code;
|
|
22
|
+
this.requestId = body.error.request_id;
|
|
23
|
+
this.retryable = body.error.retryable;
|
|
24
|
+
this.details = body.error.details;
|
|
25
|
+
this.operationId = body.error.operation_id;
|
|
26
|
+
this.source = source;
|
|
27
|
+
this.retryAfterSeconds = retryAfterSeconds;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/** The response was not the documented shape (e.g. a proxy error page). */
|
|
31
|
+
export class ShardfluxProtocolError extends Error {
|
|
32
|
+
status;
|
|
33
|
+
constructor(message, status) {
|
|
34
|
+
super(message);
|
|
35
|
+
this.name = 'ShardfluxProtocolError';
|
|
36
|
+
this.status = status;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Waiting for an operation ran out of time. The operation keeps running server side:
|
|
41
|
+
* resume with `cloud.workspaces.waitForOperation(err.operationId)` or call open() again
|
|
42
|
+
* (it returns the same operation while it is active).
|
|
43
|
+
*/
|
|
44
|
+
export class OperationTimeoutError extends Error {
|
|
45
|
+
operationId;
|
|
46
|
+
workspaceId;
|
|
47
|
+
lastState;
|
|
48
|
+
lastReason;
|
|
49
|
+
waitedMs;
|
|
50
|
+
constructor(op, waitedMs) {
|
|
51
|
+
super(`Operation ${op.id} (${op.kind}) is still ${op.state}${op.state_reason ? ` (${op.state_reason})` : ''} after ${Math.round(waitedMs)} ms; it continues server side.`);
|
|
52
|
+
this.name = 'OperationTimeoutError';
|
|
53
|
+
this.operationId = op.id;
|
|
54
|
+
this.workspaceId = op.workspace_id;
|
|
55
|
+
this.lastState = op.state;
|
|
56
|
+
this.lastReason = op.state_reason ?? null;
|
|
57
|
+
this.waitedMs = waitedMs;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/** The operation reached `failed` or `canceled`. */
|
|
61
|
+
export class OperationFailedError extends Error {
|
|
62
|
+
operation;
|
|
63
|
+
operationId;
|
|
64
|
+
errorCode;
|
|
65
|
+
constructor(op) {
|
|
66
|
+
const code = typeof op.error?.code === 'string' ? op.error.code : null;
|
|
67
|
+
super(`Operation ${op.id} (${op.kind}) ${op.state}${code ? `: ${code}` : ''}`);
|
|
68
|
+
this.name = 'OperationFailedError';
|
|
69
|
+
this.operation = op;
|
|
70
|
+
this.operationId = op.id;
|
|
71
|
+
this.errorCode = code;
|
|
72
|
+
}
|
|
73
|
+
}
|