@w6w/sdk 0.1.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 +131 -0
- package/dist/mod.d.ts +37 -0
- package/dist/mod.d.ts.map +1 -0
- package/dist/mod.js +51 -0
- package/dist/mod.js.map +1 -0
- package/dist/src/client.d.ts +134 -0
- package/dist/src/client.d.ts.map +1 -0
- package/dist/src/client.js +165 -0
- package/dist/src/client.js.map +1 -0
- package/dist/src/config.d.ts +151 -0
- package/dist/src/config.d.ts.map +1 -0
- package/dist/src/config.js +161 -0
- package/dist/src/config.js.map +1 -0
- package/dist/src/connections.d.ts +58 -0
- package/dist/src/connections.d.ts.map +1 -0
- package/dist/src/connections.js +52 -0
- package/dist/src/connections.js.map +1 -0
- package/dist/src/documents.d.ts +168 -0
- package/dist/src/documents.d.ts.map +1 -0
- package/dist/src/documents.js +178 -0
- package/dist/src/documents.js.map +1 -0
- package/dist/src/env.d.ts +61 -0
- package/dist/src/env.d.ts.map +1 -0
- package/dist/src/env.js +73 -0
- package/dist/src/env.js.map +1 -0
- package/dist/src/errors.d.ts +79 -0
- package/dist/src/errors.d.ts.map +1 -0
- package/dist/src/errors.js +88 -0
- package/dist/src/errors.js.map +1 -0
- package/dist/src/http.d.ts +130 -0
- package/dist/src/http.d.ts.map +1 -0
- package/dist/src/http.js +150 -0
- package/dist/src/http.js.map +1 -0
- package/dist/src/me.d.ts +53 -0
- package/dist/src/me.d.ts.map +1 -0
- package/dist/src/me.js +77 -0
- package/dist/src/me.js.map +1 -0
- package/dist/src/run.d.ts +92 -0
- package/dist/src/run.d.ts.map +1 -0
- package/dist/src/run.js +83 -0
- package/dist/src/run.js.map +1 -0
- package/dist/src/types.d.ts +362 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +109 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/vars.d.ts +149 -0
- package/dist/src/vars.d.ts.map +1 -0
- package/dist/src/vars.js +149 -0
- package/dist/src/vars.js.map +1 -0
- package/dist/src/version.d.ts +14 -0
- package/dist/src/version.d.ts.map +1 -0
- package/dist/src/version.js +14 -0
- package/dist/src/version.js.map +1 -0
- package/dist/src/workflows.d.ts +180 -0
- package/dist/src/workflows.d.ts.map +1 -0
- package/dist/src/workflows.js +160 -0
- package/dist/src/workflows.js.map +1 -0
- package/package.json +36 -0
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wire types, transcribed — plus the one envelope reader every operation uses.
|
|
3
|
+
*
|
|
4
|
+
* The shapes below are **transcribed** from `docs/implementation.md` §5 (which
|
|
5
|
+
* reads them off the studio's API types), not imported or vendored from it: this
|
|
6
|
+
* package publishes to npm and JSR and cannot depend on a private workspace
|
|
7
|
+
* source. Field names are the wire's, verbatim — no camel/snake drift, no
|
|
8
|
+
* renaming, no "nicer" aliases. A client that quietly renames a wire field makes
|
|
9
|
+
* every error message and every documentation example wrong.
|
|
10
|
+
*
|
|
11
|
+
* Unknown fields are **tolerated, never rejected**: these are `interface`s, so a
|
|
12
|
+
* field the server adds tomorrow simply arrives and is ignored by an older
|
|
13
|
+
* client. Nothing here validates a response against a closed schema.
|
|
14
|
+
*
|
|
15
|
+
* Every exported member carries an explicit type — JSR publishes this file as
|
|
16
|
+
* TypeScript source and rejects inferred public types ("no slow types",
|
|
17
|
+
* `docs/implementation.md` §1).
|
|
18
|
+
*
|
|
19
|
+
* @module
|
|
20
|
+
*/
|
|
21
|
+
import type { HttpResponse } from "./http.ts";
|
|
22
|
+
/**
|
|
23
|
+
* A document's format hint.
|
|
24
|
+
*
|
|
25
|
+
* A **hint only**: it does not gate the content, which the server stores
|
|
26
|
+
* verbatim and never parses. Defaults to `"text"` server-side when a create
|
|
27
|
+
* omits it.
|
|
28
|
+
*/
|
|
29
|
+
export type DocFormat = "text" | "markdown" | "yaml" | "html" | "json";
|
|
30
|
+
/**
|
|
31
|
+
* A document — a keyed blob of text in a project's document store.
|
|
32
|
+
*
|
|
33
|
+
* `id` is the server-issued `doc_…` handle used for update and delete; `key` is
|
|
34
|
+
* the human-chosen name used at create time (and by `documents.getByKey`).
|
|
35
|
+
* `key` is **immutable** — it is not in any patch body
|
|
36
|
+
* (`docs/implementation.md` §7).
|
|
37
|
+
*
|
|
38
|
+
* Timestamps are ISO-8601 **strings**, exactly as they arrive. They are not
|
|
39
|
+
* parsed into `Date`: date parsing is a policy that would have to be identical
|
|
40
|
+
* in three languages and reversible for round-trips, so the wrappers adopt it
|
|
41
|
+
* together or not at all.
|
|
42
|
+
*/
|
|
43
|
+
export interface Doc {
|
|
44
|
+
/** Server-issued id, `doc_…`. Addresses update and delete. */
|
|
45
|
+
id: string;
|
|
46
|
+
/** Caller-chosen key: non-empty, ≤128 characters, unique per scope + project. */
|
|
47
|
+
key: string;
|
|
48
|
+
/** Raw text. Stored verbatim and never parsed by the server. */
|
|
49
|
+
content: string;
|
|
50
|
+
/** Format hint. */
|
|
51
|
+
format: DocFormat;
|
|
52
|
+
/** Free-text description; `""` when unset. */
|
|
53
|
+
description: string;
|
|
54
|
+
/** ISO-8601 timestamp. */
|
|
55
|
+
createdAt: string;
|
|
56
|
+
/** ISO-8601 timestamp. */
|
|
57
|
+
updatedAt: string;
|
|
58
|
+
}
|
|
59
|
+
/** A variable's declared type. `value` is validated against it **server-side**. */
|
|
60
|
+
export type VarType = "string" | "number" | "boolean" | "json";
|
|
61
|
+
/**
|
|
62
|
+
* A typed variable, scoped by tenant/subject.
|
|
63
|
+
*
|
|
64
|
+
* `value` is **`unknown`** on purpose: it is whatever the declared
|
|
65
|
+
* {@linkcode VarType} allows, including an arbitrary JSON document, and a
|
|
66
|
+
* wrapper that modelled its internals would be wrong for someone. Narrow it at
|
|
67
|
+
* the call site after checking `type`.
|
|
68
|
+
*/
|
|
69
|
+
export interface Var {
|
|
70
|
+
/** Server-issued id, `var_…`. Addresses update and delete. */
|
|
71
|
+
id: string;
|
|
72
|
+
/** Caller-chosen name, matching `^[a-z_][a-z0-9_]*$`. Immutable. */
|
|
73
|
+
name: string;
|
|
74
|
+
/** Declared type. */
|
|
75
|
+
type: VarType;
|
|
76
|
+
/** The value, opaque pass-through. */
|
|
77
|
+
value: unknown;
|
|
78
|
+
/** Free-text description; `""` when unset. */
|
|
79
|
+
description: string;
|
|
80
|
+
/** ISO-8601 timestamp. */
|
|
81
|
+
createdAt: string;
|
|
82
|
+
/** ISO-8601 timestamp. */
|
|
83
|
+
updatedAt: string;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Who the caller is, plus the versions of the components that answered.
|
|
87
|
+
*
|
|
88
|
+
* The body is **flat**: the identity fields sit at the top level, with no
|
|
89
|
+
* wrapping object around them. That is the contract, not an accident of this
|
|
90
|
+
* transcription — `client.me()` calls `/auth/me`, the server's real identity
|
|
91
|
+
* handler, whose live consumer is the studio, so a nested envelope would break
|
|
92
|
+
* that consumer (`docs/endpoints.md` §1, D15). Nothing in this file unwraps a
|
|
93
|
+
* `me` response, because there is nothing to unwrap.
|
|
94
|
+
*
|
|
95
|
+
* The four identity fields mirror the server's principal.
|
|
96
|
+
*/
|
|
97
|
+
export interface Me {
|
|
98
|
+
/** Tenant the caller belongs to. */
|
|
99
|
+
tenant: string;
|
|
100
|
+
/** The authenticated subject (a user or a machine principal). */
|
|
101
|
+
subject: string;
|
|
102
|
+
/** Account the caller is acting in. */
|
|
103
|
+
account: string;
|
|
104
|
+
/** The caller's role within that account. */
|
|
105
|
+
role: string;
|
|
106
|
+
/**
|
|
107
|
+
* Component versions, e.g. `{composition: "server@1a2b3c4 …", wrapper: "0.1.0"}`.
|
|
108
|
+
*
|
|
109
|
+
* **Optional and open.** It may be absent entirely (an older server), and it
|
|
110
|
+
* may carry keys this release has never heard of — so it is typed as a string
|
|
111
|
+
* map and never as a closed record: adding a key server-side must not break an
|
|
112
|
+
* installed client. `wrapper` is filled in by this package from its own
|
|
113
|
+
* `VERSION` (`src/me.ts`); the server cannot know it.
|
|
114
|
+
*/
|
|
115
|
+
versions?: Record<string, string>;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Lifecycle state of a connection.
|
|
119
|
+
*
|
|
120
|
+
* A closed union because it is the server's own enum and a caller switches on
|
|
121
|
+
* it; unknown *fields* are tolerated everywhere in this file, but a new state
|
|
122
|
+
* would be a server change that the wrapper version-bumps with.
|
|
123
|
+
*/
|
|
124
|
+
export type ConnectionState = "pending" | "connected" | "needs_refresh" | "broken" | "revoked";
|
|
125
|
+
/**
|
|
126
|
+
* A connection, as the list route projects it.
|
|
127
|
+
*
|
|
128
|
+
* **Two fields the stored record has are deliberately absent here**: the secret
|
|
129
|
+
* material and its last-refresh timestamp are redacted server-side and never
|
|
130
|
+
* reach a client. Declaring them would promise a caller a field that can never
|
|
131
|
+
* arrive — and would invite exactly the code path (`if (c.…)`) that this
|
|
132
|
+
* omission makes impossible to write (`docs/endpoints.md` §2).
|
|
133
|
+
*
|
|
134
|
+
* Timestamps are ISO-8601 strings, exactly as they arrive; `lastTestOk` and
|
|
135
|
+
* `lastTestedAt` are `null` until the connection has been tested once.
|
|
136
|
+
*/
|
|
137
|
+
export interface ConnectionSummary {
|
|
138
|
+
/** Server-issued id, `conn_…`. This is the handle a URN addresses. */
|
|
139
|
+
id: string;
|
|
140
|
+
/** The app this connection authenticates against, e.g. `"sendgrid"`. */
|
|
141
|
+
appId: string;
|
|
142
|
+
/** Which of the app's auth methods this connection uses. */
|
|
143
|
+
authKey: string;
|
|
144
|
+
/** The subject that owns the connection. */
|
|
145
|
+
owner: string;
|
|
146
|
+
/** Human-chosen label. */
|
|
147
|
+
displayName: string;
|
|
148
|
+
/** Lifecycle state. */
|
|
149
|
+
state: ConnectionState;
|
|
150
|
+
/** Non-secret profile data the app captured at connect time; opaque pass-through. */
|
|
151
|
+
profile: Record<string, unknown>;
|
|
152
|
+
/** Result of the last connection test; `null` when it has never been tested. */
|
|
153
|
+
lastTestOk: boolean | null;
|
|
154
|
+
/** ISO-8601 timestamp of the last test, or `null`. */
|
|
155
|
+
lastTestedAt: string | null;
|
|
156
|
+
/** ISO-8601 timestamp. */
|
|
157
|
+
createdAt: string;
|
|
158
|
+
/** ISO-8601 timestamp. */
|
|
159
|
+
updatedAt: string;
|
|
160
|
+
}
|
|
161
|
+
/** Lifecycle state of a workflow: an editable draft, or a published live one. */
|
|
162
|
+
export type WorkflowStatus = "draft" | "active";
|
|
163
|
+
/**
|
|
164
|
+
* A workflow definition, as the list route projects it.
|
|
165
|
+
*
|
|
166
|
+
* `name` is the stable slug the workflow was registered under; `displayName` is
|
|
167
|
+
* the label a human reads. Both are present on the wire and neither is derived
|
|
168
|
+
* from the other, so both are kept.
|
|
169
|
+
*/
|
|
170
|
+
export interface WorkflowSummary {
|
|
171
|
+
/** Server-issued id, `wf_…`. This is the handle a URN addresses. */
|
|
172
|
+
id: string;
|
|
173
|
+
/** Stable slug, e.g. `"welcome-email"`. */
|
|
174
|
+
name: string;
|
|
175
|
+
/** Human-readable label. */
|
|
176
|
+
displayName: string;
|
|
177
|
+
/** Free-text description; `""` when unset. */
|
|
178
|
+
description: string;
|
|
179
|
+
/** Lifecycle state. */
|
|
180
|
+
status: WorkflowStatus;
|
|
181
|
+
/** Free-form labels. */
|
|
182
|
+
tags: string[];
|
|
183
|
+
/** Total number of runs this workflow has accumulated. */
|
|
184
|
+
runCount: number;
|
|
185
|
+
/** ISO-8601 timestamp. */
|
|
186
|
+
updatedAt: string;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Lifecycle state of a run.
|
|
190
|
+
*
|
|
191
|
+
* `queued` and `running` are in-flight; `succeeded`, `failed` and `canceled`
|
|
192
|
+
* are terminal (see {@linkcode isTerminalRunStatus}). **`failed` is a status,
|
|
193
|
+
* not an error**: a run that failed comes back as a normal `200` carrying this
|
|
194
|
+
* value, and no operation in this package raises on it
|
|
195
|
+
* (`docs/implementation.md` §4).
|
|
196
|
+
*/
|
|
197
|
+
export type RunStatus = "queued" | "running" | "succeeded" | "failed" | "canceled";
|
|
198
|
+
/** One step's failure inside a run. `error` is opaque pass-through. */
|
|
199
|
+
export interface StepError {
|
|
200
|
+
/** Id of the step that failed. */
|
|
201
|
+
stepId: string;
|
|
202
|
+
/** Whatever the step reported; shape belongs to the app, not to this client. */
|
|
203
|
+
error: unknown;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* A workflow run: the handle, its state, and the result when it has one.
|
|
207
|
+
*
|
|
208
|
+
* A `202` body carries only `runId` + `status` — the run is queued or still
|
|
209
|
+
* going — while a `200` additionally carries `output`, `error` and `steps`.
|
|
210
|
+
* The optional fields are optional for exactly that reason.
|
|
211
|
+
*
|
|
212
|
+
* `output`, `error` and the values in `steps` are **opaque pass-through**
|
|
213
|
+
* (`unknown`): they come from user workflows and vendor apps, and a client that
|
|
214
|
+
* modelled their internals would be wrong for someone. `steps` is a map **keyed
|
|
215
|
+
* by step id**, not an array (`docs/implementation.md` §5).
|
|
216
|
+
*/
|
|
217
|
+
export interface RunResult {
|
|
218
|
+
/** Server-issued run handle, `run_…`. Present on every response, queued included. */
|
|
219
|
+
runId: string;
|
|
220
|
+
/** Where the run has got to. */
|
|
221
|
+
status: RunStatus;
|
|
222
|
+
/** The run's output when it finished; absent while it is still going. */
|
|
223
|
+
output?: unknown;
|
|
224
|
+
/** The run-level error when it failed; absent otherwise. Data, never a raised exception. */
|
|
225
|
+
error?: unknown;
|
|
226
|
+
/** Per-step state, keyed by step id. `{}` when the server sent none. */
|
|
227
|
+
steps: Record<string, unknown>;
|
|
228
|
+
/** Per-step failures, when the server reports them. */
|
|
229
|
+
stepErrors?: StepError[];
|
|
230
|
+
}
|
|
231
|
+
/** `run` resolved a `conn_…` URN and executed an app action. HTTP `200`. */
|
|
232
|
+
export interface ActionRunEnvelope {
|
|
233
|
+
kind: "action";
|
|
234
|
+
/** The action's return value. Opaque pass-through. */
|
|
235
|
+
value: unknown;
|
|
236
|
+
}
|
|
237
|
+
/** `run` resolved a `fn_…` / `ep_…` URN and executed it. HTTP `200`. */
|
|
238
|
+
export interface FunctionRunEnvelope {
|
|
239
|
+
kind: "function";
|
|
240
|
+
/** The function's output. Opaque pass-through. */
|
|
241
|
+
output: unknown;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* `run` resolved a `wf_…` URN and enqueued a workflow run. HTTP `202`.
|
|
245
|
+
*
|
|
246
|
+
* `202` is **success**: the run is queued, and `runId` is how the caller follows
|
|
247
|
+
* it. There is no `?wait=` on this operation — use `workflows.run` for that (D4).
|
|
248
|
+
*/
|
|
249
|
+
export interface WorkflowRunEnvelope {
|
|
250
|
+
kind: "workflow";
|
|
251
|
+
/** Server-issued run handle. */
|
|
252
|
+
runId: string;
|
|
253
|
+
/** Where the run has got to; `"queued"` immediately after dispatch. */
|
|
254
|
+
status: RunStatus;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* A `kind` this release has never heard of, handed back verbatim.
|
|
258
|
+
*
|
|
259
|
+
* The server may grow a fourth `kind` before the wrappers do — a purely
|
|
260
|
+
* additive change on the one operation whose entire job is dispatch. This arm
|
|
261
|
+
* is what keeps that additive change from becoming a hard breakage for every
|
|
262
|
+
* user of an installed version: the parsed body is returned as it arrived,
|
|
263
|
+
* `kind` and all sibling fields intact, and nothing raises
|
|
264
|
+
* (`docs/implementation.md` §5).
|
|
265
|
+
*/
|
|
266
|
+
export type UnknownRunEnvelope = {
|
|
267
|
+
kind: string;
|
|
268
|
+
} & Record<string, unknown>;
|
|
269
|
+
/**
|
|
270
|
+
* What `client.run()` returns: three known arms plus an open one.
|
|
271
|
+
*
|
|
272
|
+
* `value` (action) and `output` (function) are **deliberately different names**
|
|
273
|
+
* for the two synchronous arms and are never normalised into one field — the
|
|
274
|
+
* discrimination is the point (D3).
|
|
275
|
+
*
|
|
276
|
+
* **The union is open, and narrowing on `kind` alone does not work.** Because
|
|
277
|
+
* the fourth arm admits any `kind: string`, a bare `env.kind === "workflow"`
|
|
278
|
+
* check leaves `env.status` typed `unknown` under `--strict`, not `RunStatus`.
|
|
279
|
+
* That is a property of the open union, not a bug in it: closing the union would
|
|
280
|
+
* make an unknown `kind` unrepresentable and the pinned "return the raw
|
|
281
|
+
* envelope" behaviour un-typeable. Use the guards below, which narrow properly:
|
|
282
|
+
*
|
|
283
|
+
* @example
|
|
284
|
+
* ```ts
|
|
285
|
+
* const env = await client.run({ urn: "wf_01HQ" });
|
|
286
|
+
* if (isActionRun(env)) console.log(env.value);
|
|
287
|
+
* else if (isFunctionRun(env)) console.log(env.output);
|
|
288
|
+
* else if (isWorkflowRun(env)) console.log(env.runId, env.status);
|
|
289
|
+
* else console.log("a kind this SDK version does not know:", env.kind, env);
|
|
290
|
+
* ```
|
|
291
|
+
*/
|
|
292
|
+
export type RunEnvelope = ActionRunEnvelope | FunctionRunEnvelope | WorkflowRunEnvelope | UnknownRunEnvelope;
|
|
293
|
+
/**
|
|
294
|
+
* Is this the `action` arm? Narrows to {@linkcode ActionRunEnvelope}, so
|
|
295
|
+
* `env.value` is reachable and typed inside the branch.
|
|
296
|
+
*
|
|
297
|
+
* @param env - Any envelope `run` returned.
|
|
298
|
+
* @returns `true` when `kind` is `"action"`.
|
|
299
|
+
*/
|
|
300
|
+
export declare function isActionRun(env: RunEnvelope): env is ActionRunEnvelope;
|
|
301
|
+
/**
|
|
302
|
+
* Is this the `function` arm? Narrows to {@linkcode FunctionRunEnvelope}, so
|
|
303
|
+
* `env.output` is reachable and typed inside the branch.
|
|
304
|
+
*
|
|
305
|
+
* @param env - Any envelope `run` returned.
|
|
306
|
+
* @returns `true` when `kind` is `"function"`.
|
|
307
|
+
*/
|
|
308
|
+
export declare function isFunctionRun(env: RunEnvelope): env is FunctionRunEnvelope;
|
|
309
|
+
/**
|
|
310
|
+
* Is this the `workflow` arm? Narrows to {@linkcode WorkflowRunEnvelope}, so
|
|
311
|
+
* `env.runId` and `env.status` are reachable and typed inside the branch.
|
|
312
|
+
*
|
|
313
|
+
* @param env - Any envelope `run` returned.
|
|
314
|
+
* @returns `true` when `kind` is `"workflow"`.
|
|
315
|
+
*/
|
|
316
|
+
export declare function isWorkflowRun(env: RunEnvelope): env is WorkflowRunEnvelope;
|
|
317
|
+
/**
|
|
318
|
+
* Has a run reached a state it will not leave?
|
|
319
|
+
*
|
|
320
|
+
* Exported because it is the same question `workflows.run`'s `terminal` flag
|
|
321
|
+
* answers, and a caller polling a `202` handle on its own schedule needs it
|
|
322
|
+
* too. It reads the **run's** status rather than an HTTP code: a `202` can carry
|
|
323
|
+
* `queued` or `running`, and the answer is about the run, not the transport.
|
|
324
|
+
*
|
|
325
|
+
* @param status - A run status.
|
|
326
|
+
* @returns `true` for `succeeded`, `failed` and `canceled`.
|
|
327
|
+
*/
|
|
328
|
+
export declare function isTerminalRunStatus(status: RunStatus): boolean;
|
|
329
|
+
/**
|
|
330
|
+
* Read one payload out of the server's envelope, or fail loudly.
|
|
331
|
+
*
|
|
332
|
+
* The server wraps every asset body under a key — `{documents: […]}`,
|
|
333
|
+
* `{document: …}`, `{vars: […]}`, `{var: …}` — and the wrapper's contract is to
|
|
334
|
+
* hand the caller the payload, never the wrapper (`docs/implementation.md` §6).
|
|
335
|
+
*
|
|
336
|
+
* A `2xx` body **missing** that key is a `bad_response`-class bug and raises,
|
|
337
|
+
* rather than returning `undefined`. That is the pinned behaviour, and the
|
|
338
|
+
* reason is worth keeping next to the code: three wrappers each returning a
|
|
339
|
+
* silent `undefined` here would turn a server regression into a `TypeError`
|
|
340
|
+
* thrown somewhere in the caller's code, minutes later, with nothing pointing
|
|
341
|
+
* back at the response that caused it.
|
|
342
|
+
*
|
|
343
|
+
* This is the *only* place an operation module inspects a body's shape. It is
|
|
344
|
+
* not schema validation: extra keys are ignored, and the payload itself is cast,
|
|
345
|
+
* never checked.
|
|
346
|
+
*
|
|
347
|
+
* A key present but carrying **`null`** counts as missing, for exactly the same
|
|
348
|
+
* reason: `{"document": null}` resolved `documents.get()` to `null` typed `Doc`
|
|
349
|
+
* (measured), which is precisely the deferred `TypeError` in the caller that the
|
|
350
|
+
* paragraph above says this function exists to prevent. The check is therefore
|
|
351
|
+
* `!= null`, not `!== undefined`. The python lane stops the same body one level
|
|
352
|
+
* further in (`unwrap_object`); what both lanes agree on is that it raises
|
|
353
|
+
* `bad_response` with the status still in hand, rather than reaching the caller.
|
|
354
|
+
*
|
|
355
|
+
* @param res - The response returned by the transport.
|
|
356
|
+
* @param key - The envelope key to read, e.g. `"document"`, `"vars"`.
|
|
357
|
+
* @returns The unwrapped payload.
|
|
358
|
+
* @throws {ApiError} `bad_response` when the body is not an object, or lacks the
|
|
359
|
+
* key, or the key is `null`.
|
|
360
|
+
*/
|
|
361
|
+
export declare function unwrap<T>(res: HttpResponse<unknown>, key: string): T;
|
|
362
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAE9C;;;;;;GAMG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAEvE;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,GAAG;IAClB,8DAA8D;IAC9D,EAAE,EAAE,MAAM,CAAC;IACX,iFAAiF;IACjF,GAAG,EAAE,MAAM,CAAC;IACZ,gEAAgE;IAChE,OAAO,EAAE,MAAM,CAAC;IAChB,mBAAmB;IACnB,MAAM,EAAE,SAAS,CAAC;IAClB,8CAA8C;IAC9C,WAAW,EAAE,MAAM,CAAC;IACpB,0BAA0B;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,0BAA0B;IAC1B,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,mFAAmF;AACnF,MAAM,MAAM,OAAO,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,G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G,CAAC,CAcpE"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wire types, transcribed — plus the one envelope reader every operation uses.
|
|
3
|
+
*
|
|
4
|
+
* The shapes below are **transcribed** from `docs/implementation.md` §5 (which
|
|
5
|
+
* reads them off the studio's API types), not imported or vendored from it: this
|
|
6
|
+
* package publishes to npm and JSR and cannot depend on a private workspace
|
|
7
|
+
* source. Field names are the wire's, verbatim — no camel/snake drift, no
|
|
8
|
+
* renaming, no "nicer" aliases. A client that quietly renames a wire field makes
|
|
9
|
+
* every error message and every documentation example wrong.
|
|
10
|
+
*
|
|
11
|
+
* Unknown fields are **tolerated, never rejected**: these are `interface`s, so a
|
|
12
|
+
* field the server adds tomorrow simply arrives and is ignored by an older
|
|
13
|
+
* client. Nothing here validates a response against a closed schema.
|
|
14
|
+
*
|
|
15
|
+
* Every exported member carries an explicit type — JSR publishes this file as
|
|
16
|
+
* TypeScript source and rejects inferred public types ("no slow types",
|
|
17
|
+
* `docs/implementation.md` §1).
|
|
18
|
+
*
|
|
19
|
+
* @module
|
|
20
|
+
*/
|
|
21
|
+
import { ApiError } from "./errors.js";
|
|
22
|
+
/**
|
|
23
|
+
* Is this the `action` arm? Narrows to {@linkcode ActionRunEnvelope}, so
|
|
24
|
+
* `env.value` is reachable and typed inside the branch.
|
|
25
|
+
*
|
|
26
|
+
* @param env - Any envelope `run` returned.
|
|
27
|
+
* @returns `true` when `kind` is `"action"`.
|
|
28
|
+
*/
|
|
29
|
+
export function isActionRun(env) {
|
|
30
|
+
return env.kind === "action";
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Is this the `function` arm? Narrows to {@linkcode FunctionRunEnvelope}, so
|
|
34
|
+
* `env.output` is reachable and typed inside the branch.
|
|
35
|
+
*
|
|
36
|
+
* @param env - Any envelope `run` returned.
|
|
37
|
+
* @returns `true` when `kind` is `"function"`.
|
|
38
|
+
*/
|
|
39
|
+
export function isFunctionRun(env) {
|
|
40
|
+
return env.kind === "function";
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Is this the `workflow` arm? Narrows to {@linkcode WorkflowRunEnvelope}, so
|
|
44
|
+
* `env.runId` and `env.status` are reachable and typed inside the branch.
|
|
45
|
+
*
|
|
46
|
+
* @param env - Any envelope `run` returned.
|
|
47
|
+
* @returns `true` when `kind` is `"workflow"`.
|
|
48
|
+
*/
|
|
49
|
+
export function isWorkflowRun(env) {
|
|
50
|
+
return env.kind === "workflow";
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Has a run reached a state it will not leave?
|
|
54
|
+
*
|
|
55
|
+
* Exported because it is the same question `workflows.run`'s `terminal` flag
|
|
56
|
+
* answers, and a caller polling a `202` handle on its own schedule needs it
|
|
57
|
+
* too. It reads the **run's** status rather than an HTTP code: a `202` can carry
|
|
58
|
+
* `queued` or `running`, and the answer is about the run, not the transport.
|
|
59
|
+
*
|
|
60
|
+
* @param status - A run status.
|
|
61
|
+
* @returns `true` for `succeeded`, `failed` and `canceled`.
|
|
62
|
+
*/
|
|
63
|
+
export function isTerminalRunStatus(status) {
|
|
64
|
+
return status === "succeeded" || status === "failed" || status === "canceled";
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Read one payload out of the server's envelope, or fail loudly.
|
|
68
|
+
*
|
|
69
|
+
* The server wraps every asset body under a key — `{documents: […]}`,
|
|
70
|
+
* `{document: …}`, `{vars: […]}`, `{var: …}` — and the wrapper's contract is to
|
|
71
|
+
* hand the caller the payload, never the wrapper (`docs/implementation.md` §6).
|
|
72
|
+
*
|
|
73
|
+
* A `2xx` body **missing** that key is a `bad_response`-class bug and raises,
|
|
74
|
+
* rather than returning `undefined`. That is the pinned behaviour, and the
|
|
75
|
+
* reason is worth keeping next to the code: three wrappers each returning a
|
|
76
|
+
* silent `undefined` here would turn a server regression into a `TypeError`
|
|
77
|
+
* thrown somewhere in the caller's code, minutes later, with nothing pointing
|
|
78
|
+
* back at the response that caused it.
|
|
79
|
+
*
|
|
80
|
+
* This is the *only* place an operation module inspects a body's shape. It is
|
|
81
|
+
* not schema validation: extra keys are ignored, and the payload itself is cast,
|
|
82
|
+
* never checked.
|
|
83
|
+
*
|
|
84
|
+
* A key present but carrying **`null`** counts as missing, for exactly the same
|
|
85
|
+
* reason: `{"document": null}` resolved `documents.get()` to `null` typed `Doc`
|
|
86
|
+
* (measured), which is precisely the deferred `TypeError` in the caller that the
|
|
87
|
+
* paragraph above says this function exists to prevent. The check is therefore
|
|
88
|
+
* `!= null`, not `!== undefined`. The python lane stops the same body one level
|
|
89
|
+
* further in (`unwrap_object`); what both lanes agree on is that it raises
|
|
90
|
+
* `bad_response` with the status still in hand, rather than reaching the caller.
|
|
91
|
+
*
|
|
92
|
+
* @param res - The response returned by the transport.
|
|
93
|
+
* @param key - The envelope key to read, e.g. `"document"`, `"vars"`.
|
|
94
|
+
* @returns The unwrapped payload.
|
|
95
|
+
* @throws {ApiError} `bad_response` when the body is not an object, or lacks the
|
|
96
|
+
* key, or the key is `null`.
|
|
97
|
+
*/
|
|
98
|
+
export function unwrap(res, key) {
|
|
99
|
+
const body = res.body;
|
|
100
|
+
if (typeof body === "object" && body !== null) {
|
|
101
|
+
const value = body[key];
|
|
102
|
+
// Both arms are load-bearing: absent AND null are "the server did not send
|
|
103
|
+
// what it promised", and only one of them used to be caught.
|
|
104
|
+
if (value !== undefined && value !== null)
|
|
105
|
+
return value;
|
|
106
|
+
}
|
|
107
|
+
throw new ApiError(res.status, "bad_response", `Server returned a ${res.status} with no "${key}" in the response body.`, body);
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAqSvC;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAC,GAAgB;IAC1C,OAAO,GAAG,CAAC,IAAI,KAAK,QAAQ,CAAC;AAC/B,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAAC,GAAgB;IAC5C,OAAO,GAAG,CAAC,IAAI,KAAK,UAAU,CAAC;AACjC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAAC,GAAgB;IAC5C,OAAO,GAAG,CAAC,IAAI,KAAK,UAAU,CAAC;AACjC,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAAiB;IACnD,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,UAAU,CAAC;AAChF,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,UAAU,MAAM,CAAI,GAA0B,EAAE,GAAW;IAC/D,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;IACtB,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;QAC9C,MAAM,KAAK,GAAI,IAAgC,CAAC,GAAG,CAAC,CAAC;QACrD,2EAA2E;QAC3E,6DAA6D;QAC7D,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI;YAAE,OAAO,KAAU,CAAC;IAC/D,CAAC;IACD,MAAM,IAAI,QAAQ,CAChB,GAAG,CAAC,MAAM,EACV,cAAc,EACd,qBAAqB,GAAG,CAAC,MAAM,aAAa,GAAG,yBAAyB,EACxE,IAAI,CACL,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `client.vars.*` — typed variables, addressed the way the server addresses
|
|
3
|
+
* them.
|
|
4
|
+
*
|
|
5
|
+
* Six operations, one HTTP call each. **Create by `name`, read by id or by
|
|
6
|
+
* name, update and delete by id** (`docs/implementation.md` §7, D6 amended by
|
|
7
|
+
* D12). No client-side list-then-filter: `getByName` targets a real route,
|
|
8
|
+
* `GET /vars/by-name/{name}` (verified live 2026-07-28).
|
|
9
|
+
*
|
|
10
|
+
* **There is no scoping query parameter on any variable operation, and this
|
|
11
|
+
* module cannot invent one.** Variables are scoped by tenant/subject only; the
|
|
12
|
+
* server's `vars` routes read no such parameter and the table has no column for
|
|
13
|
+
* it, while every document route does — so the two asset surfaces are
|
|
14
|
+
* deliberately asymmetric (`docs/implementation.md` §7, and `src/documents.ts`
|
|
15
|
+
* for the other half). The asymmetry is enforced structurally rather than by
|
|
16
|
+
* discipline: {@linkcode VarsHost} exposes the transport and **not** the
|
|
17
|
+
* client's resolved configuration, so nothing in this file can reach a default
|
|
18
|
+
* scope to send even by accident. Adding the parameter later, once the server
|
|
19
|
+
* honours it, is purely additive; adding it now would be an argument the server
|
|
20
|
+
* ignores — a lie that typechecks.
|
|
21
|
+
*
|
|
22
|
+
* @module
|
|
23
|
+
*/
|
|
24
|
+
import { type HttpResponse, type RequestOptions } from "./http.ts";
|
|
25
|
+
import { type Var, type VarType } from "./types.ts";
|
|
26
|
+
/**
|
|
27
|
+
* The slice of `W6wClient` this namespace needs: the transport, and nothing
|
|
28
|
+
* else. Structural rather than a concrete client type, so the namespace stays
|
|
29
|
+
* independently constructible in a test and this module never imports the
|
|
30
|
+
* client back.
|
|
31
|
+
*/
|
|
32
|
+
export interface VarsHost {
|
|
33
|
+
/** Perform one request. */
|
|
34
|
+
request<T>(options: RequestOptions): Promise<HttpResponse<T>>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The body of `vars.create`.
|
|
38
|
+
*
|
|
39
|
+
* Addressed by `name`, because that is how the server addresses a create (D6).
|
|
40
|
+
*/
|
|
41
|
+
export interface VarCreateInput {
|
|
42
|
+
/** Must match `^[a-z_][a-z0-9_]*$` (`400 invalid_name`); unique (`409 var_exists`). */
|
|
43
|
+
name: string;
|
|
44
|
+
/** The declared type. */
|
|
45
|
+
type: VarType;
|
|
46
|
+
/** The value, validated server-side against `type` (`400 invalid_value`). */
|
|
47
|
+
value: unknown;
|
|
48
|
+
/** Free text. */
|
|
49
|
+
description?: string;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The body of `vars.update`. Every field is optional; an omitted field is left
|
|
53
|
+
* alone.
|
|
54
|
+
*
|
|
55
|
+
* **`name` is deliberately absent.** The server's PATCH body has no `name` and
|
|
56
|
+
* the name is immutable, so there is no field here to put one in — the type is
|
|
57
|
+
* what enforces it, not a comment.
|
|
58
|
+
*
|
|
59
|
+
* A `value` sent **without** a `type` is validated against the variable's
|
|
60
|
+
* existing type.
|
|
61
|
+
*/
|
|
62
|
+
export interface VarPatch {
|
|
63
|
+
/** Replacement type. */
|
|
64
|
+
type?: VarType;
|
|
65
|
+
/** Replacement value. */
|
|
66
|
+
value?: unknown;
|
|
67
|
+
/** Replacement description. */
|
|
68
|
+
description?: string;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The `vars` namespace on a `W6wClient`.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* const v = await client.vars.create({ name: "sender_email", type: "string", value: "a@b.c" });
|
|
76
|
+
* await client.vars.update(v.id, { value: "c@d.e" });
|
|
77
|
+
* await client.vars.delete(v.id);
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
export declare class VarsApi {
|
|
81
|
+
#private;
|
|
82
|
+
/**
|
|
83
|
+
* @param host - The client this namespace issues requests through.
|
|
84
|
+
*/
|
|
85
|
+
constructor(host: VarsHost);
|
|
86
|
+
/**
|
|
87
|
+
* List the caller's variables.
|
|
88
|
+
*
|
|
89
|
+
* @returns The variables, unwrapped from the `vars` envelope.
|
|
90
|
+
* @throws {ApiError} On any non-2xx.
|
|
91
|
+
*/
|
|
92
|
+
list(): Promise<Var[]>;
|
|
93
|
+
/**
|
|
94
|
+
* Fetch one variable by its server-issued id.
|
|
95
|
+
*
|
|
96
|
+
* @param id - The `var_…` id.
|
|
97
|
+
* @returns The variable.
|
|
98
|
+
* @throws {ApiError} `404 unknown_var` when there is no such id.
|
|
99
|
+
*/
|
|
100
|
+
get(id: string): Promise<Var>;
|
|
101
|
+
/**
|
|
102
|
+
* Fetch one variable by the `name` its author chose.
|
|
103
|
+
*
|
|
104
|
+
* The name is percent-encoded at interpolation by the `path` tag. The server's
|
|
105
|
+
* own rule (`^[a-z_][a-z0-9_]*$`) contains nothing that needs encoding — but
|
|
106
|
+
* that rule is the *server's* to enforce, and this method encodes rather than
|
|
107
|
+
* validates: a name the server accepts is sent as-is (encoded), and a name it
|
|
108
|
+
* rejects comes back as `400 invalid_name` from the one place that owns the
|
|
109
|
+
* rule, instead of as a client-side error that would go stale the moment the
|
|
110
|
+
* rule changed.
|
|
111
|
+
*
|
|
112
|
+
* @param name - The variable name, sent encoded and otherwise untouched.
|
|
113
|
+
* @returns The variable.
|
|
114
|
+
* @throws {ApiError} `404 unknown_var` when there is no such name.
|
|
115
|
+
*/
|
|
116
|
+
getByName(name: string): Promise<Var>;
|
|
117
|
+
/**
|
|
118
|
+
* Create a typed variable under a caller-chosen name.
|
|
119
|
+
*
|
|
120
|
+
* @param input - `name`, `type` and `value` are required.
|
|
121
|
+
* @returns The created variable (the server answers `201`).
|
|
122
|
+
* @throws {ApiError} `409 var_exists` on a duplicate name — the code reaches the caller intact.
|
|
123
|
+
*/
|
|
124
|
+
create(input: VarCreateInput): Promise<Var>;
|
|
125
|
+
/**
|
|
126
|
+
* Patch a variable's type, value or description.
|
|
127
|
+
*
|
|
128
|
+
* Addressed by id, never by name, and the name itself cannot be changed.
|
|
129
|
+
*
|
|
130
|
+
* @param id - The `var_…` id.
|
|
131
|
+
* @param patch - The fields to change; omitted fields are left alone.
|
|
132
|
+
* @returns The updated variable.
|
|
133
|
+
* @throws {ApiError} `404 unknown_var` when there is no such id.
|
|
134
|
+
*/
|
|
135
|
+
update(id: string, patch: VarPatch): Promise<Var>;
|
|
136
|
+
/**
|
|
137
|
+
* Delete a variable.
|
|
138
|
+
*
|
|
139
|
+
* Returns nothing: the server's `{ok: true}` carries no information a caller
|
|
140
|
+
* can use. Deleting an unknown id is `404 unknown_var`, **not** a silent
|
|
141
|
+
* success — the delete is not idempotent and this method does not pretend
|
|
142
|
+
* otherwise.
|
|
143
|
+
*
|
|
144
|
+
* @param id - The `var_…` id.
|
|
145
|
+
* @throws {ApiError} `404 unknown_var` when there is no such id.
|
|
146
|
+
*/
|
|
147
|
+
delete(id: string): Promise<void>;
|
|
148
|
+
}
|
|
149
|
+
//# sourceMappingURL=vars.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vars.d.ts","sourceRoot":"","sources":["../../src/vars.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,KAAK,YAAY,EAAQ,KAAK,cAAc,EAAE,MAAM,WAAW,CAAC;AACzE,OAAO,EAAU,KAAK,GAAG,EAAE,KAAK,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5D;;;;;GAKG;AACH,MAAM,WAAW,QAAQ;IACvB,2BAA2B;IAC3B,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;CAC/D;AAED;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,uFAAuF;IACvF,IAAI,EAAE,MAAM,CAAC;IACb,yBAAyB;IACzB,IAAI,EAAE,OAAO,CAAC;IACd,6EAA6E;IAC7E,KAAK,EAAE,OAAO,CAAC;IACf,iBAAiB;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;;;;;GAUG;AACH,MAAM,WAAW,QAAQ;IACvB,wBAAwB;IACxB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,yBAAyB;IACzB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,+BAA+B;IAC/B,WAA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