@dashai/sdk 0.7.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 +21 -0
- package/README.md +377 -0
- package/dist/auth/client.cjs +185 -0
- package/dist/auth/client.cjs.map +1 -0
- package/dist/auth/client.d.cts +137 -0
- package/dist/auth/client.d.ts +137 -0
- package/dist/auth/client.js +175 -0
- package/dist/auth/client.js.map +1 -0
- package/dist/auth/middleware.cjs +352 -0
- package/dist/auth/middleware.cjs.map +1 -0
- package/dist/auth/middleware.d.cts +90 -0
- package/dist/auth/middleware.d.ts +90 -0
- package/dist/auth/middleware.js +343 -0
- package/dist/auth/middleware.js.map +1 -0
- package/dist/auth/server.cjs +445 -0
- package/dist/auth/server.cjs.map +1 -0
- package/dist/auth/server.d.cts +170 -0
- package/dist/auth/server.d.ts +170 -0
- package/dist/auth/server.js +432 -0
- package/dist/auth/server.js.map +1 -0
- package/dist/auth/types.cjs +31 -0
- package/dist/auth/types.cjs.map +1 -0
- package/dist/auth/types.d.cts +163 -0
- package/dist/auth/types.d.ts +163 -0
- package/dist/auth/types.js +29 -0
- package/dist/auth/types.js.map +1 -0
- package/dist/deps/index.cjs +117 -0
- package/dist/deps/index.cjs.map +1 -0
- package/dist/deps/index.d.cts +93 -0
- package/dist/deps/index.d.ts +93 -0
- package/dist/deps/index.js +112 -0
- package/dist/deps/index.js.map +1 -0
- package/dist/errors-BV75u7b9.d.cts +207 -0
- package/dist/errors-BV75u7b9.d.ts +207 -0
- package/dist/index.cjs +721 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +171 -0
- package/dist/index.d.ts +171 -0
- package/dist/index.js +703 -0
- package/dist/index.js.map +1 -0
- package/dist/query/index.cjs +621 -0
- package/dist/query/index.cjs.map +1 -0
- package/dist/query/index.d.cts +800 -0
- package/dist/query/index.d.ts +800 -0
- package/dist/query/index.js +617 -0
- package/dist/query/index.js.map +1 -0
- package/dist/react/index.cjs +199 -0
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.d.cts +117 -0
- package/dist/react/index.d.ts +117 -0
- package/dist/react/index.js +195 -0
- package/dist/react/index.js.map +1 -0
- package/dist/types-BLNQ1S1C.d.cts +396 -0
- package/dist/types-BLNQ1S1C.d.ts +396 -0
- package/package.json +109 -0
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error model for @dashai/sdk.
|
|
3
|
+
*
|
|
4
|
+
* The backend speaks a structured error envelope:
|
|
5
|
+
*
|
|
6
|
+
* {
|
|
7
|
+
* "code": "ROW_NOT_FOUND",
|
|
8
|
+
* "message": "Row 123 not found in tasks",
|
|
9
|
+
* "retriable": false,
|
|
10
|
+
* "context": { ... }
|
|
11
|
+
* }
|
|
12
|
+
*
|
|
13
|
+
* This module wraps that envelope in a typed `DashwiseError` plus a small
|
|
14
|
+
* set of subclasses for the codes consumers most commonly want to branch
|
|
15
|
+
* on (network errors, auth failures, row-not-found, contract violations).
|
|
16
|
+
*
|
|
17
|
+
* Anything not matched by a specific subclass becomes a plain
|
|
18
|
+
* `DashwiseError` carrying the raw `code`. Branch on `.code` for codes
|
|
19
|
+
* we don't have a class for; use `instanceof` for the common cases.
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* Known error codes. Not exhaustive — the backend emits many codes
|
|
23
|
+
* specific to individual modules / endpoints. Use these constants when
|
|
24
|
+
* you want compile-time safety; otherwise treat `err.code` as a string.
|
|
25
|
+
*
|
|
26
|
+
* The list is curated to the codes a module author is most likely to
|
|
27
|
+
* branch on. Adding a new code here is a non-breaking change.
|
|
28
|
+
*/
|
|
29
|
+
declare const DashwiseErrorCode: {
|
|
30
|
+
readonly UNAUTHENTICATED: "UNAUTHENTICATED";
|
|
31
|
+
readonly FORBIDDEN: "FORBIDDEN";
|
|
32
|
+
readonly TOKEN_EXPIRED: "TOKEN_EXPIRED";
|
|
33
|
+
readonly INSTALLATION_NOT_FOUND: "INSTALLATION_NOT_FOUND";
|
|
34
|
+
readonly INSTALLATION_MODE_UNSUPPORTED: "INSTALLATION_MODE_UNSUPPORTED";
|
|
35
|
+
readonly CONTRACT_VIOLATION: "CONTRACT_VIOLATION";
|
|
36
|
+
readonly FIELD_NOT_READABLE: "FIELD_NOT_READABLE";
|
|
37
|
+
readonly FILTER_OP_UNKNOWN: "FILTER_OP_UNKNOWN";
|
|
38
|
+
readonly OPERATION_NOT_ALLOWED: "OPERATION_NOT_ALLOWED";
|
|
39
|
+
readonly DEPENDENCY_NOT_DECLARED: "DEPENDENCY_NOT_DECLARED";
|
|
40
|
+
readonly TABLE_NOT_IN_CONTRACT: "TABLE_NOT_IN_CONTRACT";
|
|
41
|
+
readonly PROVIDER_TABLE_MISSING: "PROVIDER_TABLE_MISSING";
|
|
42
|
+
readonly OPERATION_NOT_ALLOWED_BY_PROVIDER: "OPERATION_NOT_ALLOWED_BY_PROVIDER";
|
|
43
|
+
readonly LINK_FIELD_NOT_FOUND: "LINK_FIELD_NOT_FOUND";
|
|
44
|
+
readonly NOT_A_LINK_FIELD: "NOT_A_LINK_FIELD";
|
|
45
|
+
readonly JOIN_NOT_LINKED: "JOIN_NOT_LINKED";
|
|
46
|
+
readonly ACTION_NOT_EXPOSED: "ACTION_NOT_EXPOSED";
|
|
47
|
+
readonly ACTION_NOT_DECLARED: "ACTION_NOT_DECLARED";
|
|
48
|
+
readonly ACTION_INPUT_INVALID: "ACTION_INPUT_INVALID";
|
|
49
|
+
readonly ACTION_OUTPUT_INVALID: "ACTION_OUTPUT_INVALID";
|
|
50
|
+
readonly ACTION_RATE_LIMITED: "ACTION_RATE_LIMITED";
|
|
51
|
+
readonly ACTION_EXECUTION_FAILED: "ACTION_EXECUTION_FAILED";
|
|
52
|
+
readonly ROW_NOT_FOUND: "ROW_NOT_FOUND";
|
|
53
|
+
readonly TABLE_NOT_FOUND: "TABLE_NOT_FOUND";
|
|
54
|
+
readonly VALIDATION_FAILED: "VALIDATION_FAILED";
|
|
55
|
+
readonly ROW_LIMIT_EXCEEDED: "ROW_LIMIT_EXCEEDED";
|
|
56
|
+
readonly STORAGE_LIMIT_EXCEEDED: "STORAGE_LIMIT_EXCEEDED";
|
|
57
|
+
readonly OUTBOUND_NOT_ALLOWED: "OUTBOUND_NOT_ALLOWED";
|
|
58
|
+
readonly OUTBOUND_CONCURRENCY_LIMITED: "OUTBOUND_CONCURRENCY_LIMITED";
|
|
59
|
+
readonly NETWORK_ERROR: "NETWORK_ERROR";
|
|
60
|
+
readonly TIMEOUT: "TIMEOUT";
|
|
61
|
+
readonly INTERNAL_ERROR: "INTERNAL_ERROR";
|
|
62
|
+
};
|
|
63
|
+
type DashwiseErrorCode = (typeof DashwiseErrorCode)[keyof typeof DashwiseErrorCode];
|
|
64
|
+
/**
|
|
65
|
+
* Base class for every error thrown by @dashai/sdk. Carries the
|
|
66
|
+
* structured envelope from the backend (or a synthetic one for
|
|
67
|
+
* client-side failures like network errors / timeouts).
|
|
68
|
+
*
|
|
69
|
+
* Always thrown — never returned as a value. The async client methods
|
|
70
|
+
* `.list()` / `.get()` etc. reject with one of these on failure.
|
|
71
|
+
*/
|
|
72
|
+
declare class DashwiseError extends Error {
|
|
73
|
+
readonly code: string;
|
|
74
|
+
readonly status: number;
|
|
75
|
+
readonly retriable: boolean;
|
|
76
|
+
readonly context: Record<string, unknown> | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* Backend-issued trace anchor (Phase 6 slice 6.2, 2026-05-19).
|
|
79
|
+
* Mirrors the `x-request-id` response header. Populated whenever
|
|
80
|
+
* the backend's `RuntimeQueryController` (or any future endpoint
|
|
81
|
+
* that echoes the header) is the origin of this error. `null` when
|
|
82
|
+
* the failure is client-side (NetworkError / TimeoutError — the
|
|
83
|
+
* request never reached the server, so there's no server-issued
|
|
84
|
+
* ID to surface).
|
|
85
|
+
*
|
|
86
|
+
* Use this as a debugging trace anchor when filing a bug against a
|
|
87
|
+
* specific failed query — the matching row in `module_query_log`
|
|
88
|
+
* carries the full backend context (ast_hash, error_code,
|
|
89
|
+
* duration_ms, etc.).
|
|
90
|
+
*/
|
|
91
|
+
readonly requestId: string | null;
|
|
92
|
+
constructor(code: string, message: string, options?: {
|
|
93
|
+
status?: number;
|
|
94
|
+
retriable?: boolean;
|
|
95
|
+
context?: Record<string, unknown>;
|
|
96
|
+
cause?: unknown;
|
|
97
|
+
/**
|
|
98
|
+
* Phase 6 slice 6.2: backend `x-request-id` response header,
|
|
99
|
+
* captured by the transport before throwing. Pass `undefined`
|
|
100
|
+
* (or omit) for client-side errors that never hit the server.
|
|
101
|
+
*/
|
|
102
|
+
requestId?: string | null;
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
/** Network-level failure (DNS, connection refused, TLS, fetch threw). */
|
|
106
|
+
declare class NetworkError extends DashwiseError {
|
|
107
|
+
constructor(message: string, cause?: unknown);
|
|
108
|
+
}
|
|
109
|
+
/** Request exceeded the configured timeout (`timeoutMs`). */
|
|
110
|
+
declare class TimeoutError extends DashwiseError {
|
|
111
|
+
constructor(message: string, timeoutMs: number);
|
|
112
|
+
}
|
|
113
|
+
/** 401 — token missing/invalid. */
|
|
114
|
+
declare class UnauthenticatedError extends DashwiseError {
|
|
115
|
+
constructor(message?: string, requestId?: string | null);
|
|
116
|
+
}
|
|
117
|
+
/** 403 — caller lacks the role/scope for this operation. */
|
|
118
|
+
declare class ForbiddenError extends DashwiseError {
|
|
119
|
+
constructor(message: string, context?: Record<string, unknown>, requestId?: string | null);
|
|
120
|
+
}
|
|
121
|
+
/** 404 — `GET /db/<table>/<id>` for a missing or soft-deleted row. */
|
|
122
|
+
declare class RowNotFoundError extends DashwiseError {
|
|
123
|
+
constructor(message: string, context?: Record<string, unknown>, requestId?: string | null);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Schema-level rejection: dep contract violated, table not exposed, field
|
|
127
|
+
* not readable, filter op not allowed. Covers the family of "you asked for
|
|
128
|
+
* something the manifest doesn't permit" errors.
|
|
129
|
+
*/
|
|
130
|
+
declare class ContractViolationError extends DashwiseError {
|
|
131
|
+
constructor(message: string, context?: Record<string, unknown>, requestId?: string | null);
|
|
132
|
+
}
|
|
133
|
+
/** 422-ish — request body failed validation. Inspect `context` for field-level errors. */
|
|
134
|
+
declare class ValidationError extends DashwiseError {
|
|
135
|
+
constructor(message: string, context?: Record<string, unknown>, requestId?: string | null);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* 404 — the caller's `module.json#dependencies` doesn't declare a
|
|
139
|
+
* dependency on the requested provider module, OR the declared dep
|
|
140
|
+
* exists but its `reads[]` block doesn't include the requested table.
|
|
141
|
+
*
|
|
142
|
+
* Either way the fix is on the **caller's** side: update the manifest
|
|
143
|
+
* to declare the dep / add the table to `reads[]`, then re-publish.
|
|
144
|
+
*
|
|
145
|
+
* Covers both `DEPENDENCY_NOT_DECLARED` and `TABLE_NOT_IN_CONTRACT` —
|
|
146
|
+
* inspect `err.code` to distinguish if you need different UX per case.
|
|
147
|
+
*/
|
|
148
|
+
declare class DependencyContractError extends DashwiseError {
|
|
149
|
+
constructor(code: string, message: string, context?: Record<string, unknown>, requestId?: string | null);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* 404 — the provider's physical table no longer exists. This means the
|
|
153
|
+
* provider published a version that dropped the table while the
|
|
154
|
+
* consumer's installation still pinned the old contract. Recovery is
|
|
155
|
+
* on the **provider's** side (republish with the table) or the
|
|
156
|
+
* workspace admin's (downgrade the provider, or upgrade the consumer
|
|
157
|
+
* to a version whose `dependencies[]` no longer references it).
|
|
158
|
+
*/
|
|
159
|
+
declare class ProviderTableMissingError extends DashwiseError {
|
|
160
|
+
constructor(message: string, context?: Record<string, unknown>, requestId?: string | null);
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* 403 — the provider's `exposes.operations.<verb>.allowed` is explicitly
|
|
164
|
+
* `false` for the requested verb. Distinct from `OPERATION_NOT_ALLOWED`
|
|
165
|
+
* (which is the **owner's** own-table policy) — `OPERATION_NOT_ALLOWED_BY_PROVIDER`
|
|
166
|
+
* is the provider opting out of letting depending modules use a verb.
|
|
167
|
+
*
|
|
168
|
+
* No caller-side fix; either the provider needs to flip the gate, or
|
|
169
|
+
* the consumer needs to find a different way to satisfy the use case.
|
|
170
|
+
*/
|
|
171
|
+
declare class OperationNotAllowedByProviderError extends DashwiseError {
|
|
172
|
+
constructor(message: string, context?: Record<string, unknown>, requestId?: string | null);
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* 400 — `.join()` / `.leftJoin()` referenced a target the manifest
|
|
176
|
+
* can't resolve. Covers the three sub-cases above; inspect
|
|
177
|
+
* `err.code` to distinguish.
|
|
178
|
+
*
|
|
179
|
+
* Author-side fix in every case: either correct the slug, or pass
|
|
180
|
+
* an explicit `on` argument to bypass link-field inference.
|
|
181
|
+
*/
|
|
182
|
+
declare class JoinError extends DashwiseError {
|
|
183
|
+
constructor(code: string, message: string, context?: Record<string, unknown>, requestId?: string | null);
|
|
184
|
+
}
|
|
185
|
+
interface BackendErrorEnvelope {
|
|
186
|
+
code?: string;
|
|
187
|
+
message?: string;
|
|
188
|
+
retriable?: boolean;
|
|
189
|
+
context?: Record<string, unknown>;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Build a typed `DashwiseError` from the backend's response envelope.
|
|
193
|
+
*
|
|
194
|
+
* The mapping picks the most specific subclass for codes we have a class
|
|
195
|
+
* for; everything else becomes a plain `DashwiseError` carrying the raw
|
|
196
|
+
* code. This keeps the type set small while still letting consumers
|
|
197
|
+
* branch on string codes when they want to.
|
|
198
|
+
*
|
|
199
|
+
* Phase 6 slice 6.2 (2026-05-19): accepts an optional `requestId` —
|
|
200
|
+
* the backend's `x-request-id` response header — and threads it onto
|
|
201
|
+
* every produced error so consumers can use it as a debugging trace
|
|
202
|
+
* anchor. Default `null` for backward compat; the transport always
|
|
203
|
+
* passes it through.
|
|
204
|
+
*/
|
|
205
|
+
declare function fromBackendEnvelope(status: number, envelope: BackendErrorEnvelope | null, requestId?: string | null): DashwiseError;
|
|
206
|
+
|
|
207
|
+
export { ContractViolationError as C, DependencyContractError as D, ForbiddenError as F, JoinError as J, NetworkError as N, OperationNotAllowedByProviderError as O, ProviderTableMissingError as P, RowNotFoundError as R, TimeoutError as T, UnauthenticatedError as U, ValidationError as V, DashwiseError as a, DashwiseErrorCode as b, fromBackendEnvelope as f };
|