@w6w/sdk 0.6.0 → 0.9.8

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.
Files changed (120) hide show
  1. package/README.md +166 -16
  2. package/dist/mod.d.ts +7 -5
  3. package/dist/mod.d.ts.map +1 -1
  4. package/dist/mod.js +1 -0
  5. package/dist/mod.js.map +1 -1
  6. package/dist/src/client.d.ts +11 -2
  7. package/dist/src/client.d.ts.map +1 -1
  8. package/dist/src/client.js +12 -2
  9. package/dist/src/client.js.map +1 -1
  10. package/dist/src/config.d.ts +83 -6
  11. package/dist/src/config.d.ts.map +1 -1
  12. package/dist/src/config.js +40 -4
  13. package/dist/src/config.js.map +1 -1
  14. package/dist/src/connections.d.ts +3 -2
  15. package/dist/src/connections.d.ts.map +1 -1
  16. package/dist/src/connections.js +7 -2
  17. package/dist/src/connections.js.map +1 -1
  18. package/dist/src/console/api-calls.d.ts +4 -3
  19. package/dist/src/console/api-calls.d.ts.map +1 -1
  20. package/dist/src/console/api-calls.js +4 -3
  21. package/dist/src/console/api-calls.js.map +1 -1
  22. package/dist/src/console/apps.d.ts +181 -8
  23. package/dist/src/console/apps.d.ts.map +1 -1
  24. package/dist/src/console/apps.js +67 -12
  25. package/dist/src/console/apps.js.map +1 -1
  26. package/dist/src/console/auth.d.ts +43 -3
  27. package/dist/src/console/auth.d.ts.map +1 -1
  28. package/dist/src/console/auth.js +23 -4
  29. package/dist/src/console/auth.js.map +1 -1
  30. package/dist/src/console/commerce.d.ts +428 -0
  31. package/dist/src/console/commerce.d.ts.map +1 -0
  32. package/dist/src/console/commerce.js +220 -0
  33. package/dist/src/console/commerce.js.map +1 -0
  34. package/dist/src/console/dashboard.d.ts +8 -0
  35. package/dist/src/console/dashboard.d.ts.map +1 -1
  36. package/dist/src/console/dashboard.js.map +1 -1
  37. package/dist/src/console/endpoints.d.ts +57 -2
  38. package/dist/src/console/endpoints.d.ts.map +1 -1
  39. package/dist/src/console/endpoints.js.map +1 -1
  40. package/dist/src/console/functions.d.ts +35 -4
  41. package/dist/src/console/functions.d.ts.map +1 -1
  42. package/dist/src/console/functions.js +13 -0
  43. package/dist/src/console/functions.js.map +1 -1
  44. package/dist/src/console/mod.d.ts +22 -7
  45. package/dist/src/console/mod.d.ts.map +1 -1
  46. package/dist/src/console/mod.js +16 -1
  47. package/dist/src/console/mod.js.map +1 -1
  48. package/dist/src/console/otp.d.ts +127 -0
  49. package/dist/src/console/otp.d.ts.map +1 -0
  50. package/dist/src/console/otp.js +118 -0
  51. package/dist/src/console/otp.js.map +1 -0
  52. package/dist/src/console/reliability.d.ts +101 -6
  53. package/dist/src/console/reliability.d.ts.map +1 -1
  54. package/dist/src/console/reliability.js +16 -5
  55. package/dist/src/console/reliability.js.map +1 -1
  56. package/dist/src/console/step-tests.d.ts +7 -1
  57. package/dist/src/console/step-tests.d.ts.map +1 -1
  58. package/dist/src/console/step-tests.js +1 -1
  59. package/dist/src/console/step-tests.js.map +1 -1
  60. package/dist/src/console/subscriptions.d.ts +38 -16
  61. package/dist/src/console/subscriptions.d.ts.map +1 -1
  62. package/dist/src/console/subscriptions.js +7 -13
  63. package/dist/src/console/subscriptions.js.map +1 -1
  64. package/dist/src/console/tenant-login-flags.d.ts +106 -0
  65. package/dist/src/console/tenant-login-flags.d.ts.map +1 -0
  66. package/dist/src/console/tenant-login-flags.js +113 -0
  67. package/dist/src/console/tenant-login-flags.js.map +1 -0
  68. package/dist/src/console/tenant-oauth-apps.d.ts +75 -14
  69. package/dist/src/console/tenant-oauth-apps.d.ts.map +1 -1
  70. package/dist/src/console/tenant-oauth-apps.js +37 -11
  71. package/dist/src/console/tenant-oauth-apps.js.map +1 -1
  72. package/dist/src/console/tokens.d.ts +2 -0
  73. package/dist/src/console/tokens.d.ts.map +1 -1
  74. package/dist/src/console/tokens.js.map +1 -1
  75. package/dist/src/console/workflows.d.ts +14 -0
  76. package/dist/src/console/workflows.d.ts.map +1 -1
  77. package/dist/src/console/workflows.js +13 -0
  78. package/dist/src/console/workflows.js.map +1 -1
  79. package/dist/src/documents.d.ts +9 -5
  80. package/dist/src/documents.d.ts.map +1 -1
  81. package/dist/src/documents.js +6 -3
  82. package/dist/src/documents.js.map +1 -1
  83. package/dist/src/functions.d.ts +149 -1
  84. package/dist/src/functions.d.ts.map +1 -1
  85. package/dist/src/functions.js +145 -0
  86. package/dist/src/functions.js.map +1 -1
  87. package/dist/src/http.d.ts +58 -10
  88. package/dist/src/http.d.ts.map +1 -1
  89. package/dist/src/http.js +82 -11
  90. package/dist/src/http.js.map +1 -1
  91. package/dist/src/me.d.ts +3 -2
  92. package/dist/src/me.d.ts.map +1 -1
  93. package/dist/src/me.js +7 -2
  94. package/dist/src/me.js.map +1 -1
  95. package/dist/src/run.d.ts +11 -2
  96. package/dist/src/run.d.ts.map +1 -1
  97. package/dist/src/run.js +11 -2
  98. package/dist/src/run.js.map +1 -1
  99. package/dist/src/server/mod.d.ts +100 -0
  100. package/dist/src/server/mod.d.ts.map +1 -0
  101. package/dist/src/server/mod.js +121 -0
  102. package/dist/src/server/mod.js.map +1 -0
  103. package/dist/src/team.d.ts +204 -0
  104. package/dist/src/team.d.ts.map +1 -0
  105. package/dist/src/team.js +161 -0
  106. package/dist/src/team.js.map +1 -0
  107. package/dist/src/types.d.ts +143 -10
  108. package/dist/src/types.d.ts.map +1 -1
  109. package/dist/src/types.js +27 -0
  110. package/dist/src/types.js.map +1 -1
  111. package/dist/src/vars.d.ts +5 -3
  112. package/dist/src/vars.d.ts.map +1 -1
  113. package/dist/src/vars.js +14 -4
  114. package/dist/src/vars.js.map +1 -1
  115. package/dist/src/version.js +1 -1
  116. package/dist/src/workflows.d.ts +261 -9
  117. package/dist/src/workflows.d.ts.map +1 -1
  118. package/dist/src/workflows.js +246 -7
  119. package/dist/src/workflows.js.map +1 -1
  120. package/package.json +5 -1
package/README.md CHANGED
@@ -10,7 +10,9 @@ The package is authored as runtime-neutral TypeScript against Web standards (`fe
10
10
  `URL`, `AbortController`), so the same build runs under Node 18+, Deno and Bun.
11
11
 
12
12
  - **License:** MIT (see [LICENSE](./LICENSE)).
13
- - **Version:** `0.2.1`.
13
+ - **Version:** `0.9.8`.
14
+ - **Guides:** [docs.w6w.io/clients/node](https://docs.w6w.io/clients/node/), with a
15
+ [full reference](https://docs.w6w.io/clients/node/reference/).
14
16
 
15
17
  ## Install
16
18
 
@@ -26,9 +28,9 @@ JSR (the TypeScript source, published verbatim):
26
28
  deno add jsr:@w6w/sdk
27
29
  ```
28
30
 
29
- Both registries publish the **same version at the same time** — `@w6w/sdk`, `@w6w/cli` and the
30
- Python `w6w` package share one version number and are released together. A given version means the
31
- same set of operations in every language.
31
+ Both registries publish the **same version at the same time** — `@w6w/sdk`, `@w6w/cli`, `@w6w/react`
32
+ and the Python `w6w` package share one version number and are released together. A given version
33
+ means the same set of operations in every language.
32
34
 
33
35
  ## Quick start
34
36
 
@@ -37,7 +39,7 @@ import { isActionRun, isFunctionRun, isWorkflowRun, W6WClient } from "@w6w/sdk";
37
39
 
38
40
  const client = new W6WClient(); // reads W6W_BASE_URL and W6W_TOKEN
39
41
 
40
- // Who am I, and what versions am I talking to?
42
+ // Who am I? (`me.versions.wrapper` is this SDK's version.)
41
43
  const me = await client.me();
42
44
 
43
45
  // What can I run? `run` is addressed by a `conn_…` / `fn_…` / `ep_…` / `wf_…`
@@ -50,7 +52,7 @@ const workflows = await client.workflows.list();
50
52
 
51
53
  A `conn_…` id resolves to an app action. `run` returns a `kind`-tagged envelope — narrow it with
52
54
  `isActionRun` / `isFunctionRun` / `isWorkflowRun` before reading a field, since the three arms use
53
- different field names on purpose (`value` vs `output` vs `runId`+`status`):
55
+ different fields (`output` for an action or a function, `runId`+`status` for a workflow):
54
56
 
55
57
  ```ts
56
58
  const env = await client.run({
@@ -59,7 +61,7 @@ const env = await client.run({
59
61
  payload: { channel: "#general", text: "Hello from @w6w/sdk" },
60
62
  });
61
63
 
62
- if (isActionRun(env)) console.log(env.value); // the action's return value
64
+ if (isActionRun(env)) console.log(env.output); // the action's return value
63
65
  ```
64
66
 
65
67
  ### Run a function or an endpoint
@@ -109,6 +111,57 @@ const v = await client.vars.create({ name: "sender_email", type: "string", value
109
111
  await client.vars.update(v.id, { value: "c@d.e" });
110
112
  ```
111
113
 
114
+ Documents belong to a project: pass `{ project: "prj_…" }` as the last argument, or set `project` on
115
+ the client. Without either, your account's default project is used. Vars belong to the account.
116
+
117
+ ### Functions, Endpoints and workflow definitions
118
+
119
+ ```ts
120
+ // Run by key or id. `functions.run` returns the Function's output directly.
121
+ const out = await client.functions.run("send-welcome-email", { payload: { to: "a@example.com" } });
122
+ const res = await client.endpoints.run("signup", { payload: { email: "a@example.com" } });
123
+
124
+ // Cancel a run. The answer is the run's status at that moment.
125
+ await client.workflows.cancel("run_01H…");
126
+
127
+ // Read, edit and save a definition, refusing to overwrite someone else's save.
128
+ const { workflow, updatedAt } = await client.workflows.get("wf_01H…");
129
+ await client.workflows.update("wf_01H…", { ...workflow, description: "Sends the welcome email" }, {
130
+ ifUnmodifiedSince: updatedAt,
131
+ });
132
+ ```
133
+
134
+ `functions.list/get/create/update/delete` and `workflows.create/archive/delete` complete the
135
+ lifecycle. A Function or workflow must be archived before it can be deleted
136
+ (`409 function_not_archived` / `409 workflow_not_archived`).
137
+
138
+ ### Team
139
+
140
+ ```ts
141
+ const members = await client.team.members();
142
+ const { redemptionLink } = await client.team.invite({ email: "dev@example.com", role: "member" });
143
+ ```
144
+
145
+ Reading the roster and open invites works for any member. `invite`, `revokeInvite`, `setRole` and
146
+ `removeMember` need the `owner` or `admin` role.
147
+
148
+ ### A route the SDK doesn't wrap
149
+
150
+ `client.request()` sends any request with the client's own base URL, token and headers, and raises
151
+ the same `ApiError`. Build the path with the `path` tag, which percent-encodes each value:
152
+
153
+ ```ts
154
+ import { path } from "@w6w/sdk";
155
+
156
+ const { status, body } = await client.request<{ run: { status: string } }>({
157
+ method: "GET",
158
+ path: path`/runs/${runId}`,
159
+ });
160
+ ```
161
+
162
+ Every call also takes an `AbortSignal` as `signal`; an aborted call raises `ApiError` with `status`
163
+ `0` and code `cancelled`.
164
+
112
165
  ## Configuration
113
166
 
114
167
  Two environment variables, both read only at client construction:
@@ -133,6 +186,51 @@ const client = new W6WClient();
133
186
  const other = new W6WClient({ baseUrl: "https://api.example.com", token: "…" });
134
187
  ```
135
188
 
189
+ ### The four options a host embedding w6w needs
190
+
191
+ Both variables stay plain strings. These four constructor options cover the cases a host — a partner
192
+ embedding w6w inside its own product, a backend juggling tenants — actually runs into, and none of
193
+ them has an environment-variable spelling:
194
+
195
+ | Option | Meaning |
196
+ | ----------------------- | -------------------------------------------------------------------------------------------------- |
197
+ | `token` | A bearer token, **or a supplier function** called per request (see below). |
198
+ | `refreshOnUnauthorized` | Opt in to a single recovery retry when a request fails `401` / `unauthorized`. `false` by default. |
199
+ | `onUnauthorized` | Called with the terminal `401` `ApiError`, at most once per call. |
200
+ | `headers` | Default headers sent with every request. |
201
+
202
+ ```ts
203
+ const client = new W6WClient({
204
+ baseUrl: "https://api.example.com",
205
+ // Called (and awaited) per request — never cached from construction.
206
+ token: () => readTenantToken(),
207
+ refreshOnUnauthorized: true, // one retry when the server answers 401
208
+ onUnauthorized: (err) => redirectToLogin(err), // …and what to do when that did not help
209
+ headers: { "X-W6W-Tenant": tenantId }, // your own gateway/authorizer header
210
+ });
211
+ ```
212
+
213
+ **A token supplier is how a host mints or rotates a credential out of band.** `token` takes a
214
+ `string` — sent verbatim on every call, exactly as before — or a `TokenProvider` function returning
215
+ one, which is called **per request** rather than resolved once at construction, so a token that
216
+ changes between calls is picked up without rebuilding the client. Requests in flight
217
+ **concurrently** on one client share ONE supplier call (and its result); nothing is cached once it
218
+ settles, so memoize the supplier yourself if minting is expensive. A nullish or blank result is
219
+ treated exactly like a missing static token: a `ConfigError` naming `W6W_TOKEN`, never a request
220
+ sent with no credential.
221
+
222
+ **`refreshOnUnauthorized` opts in to one recovery.** Off by default, and the behaviour before the
223
+ option existed. When a request fails `401` with `{code: "unauthorized"}` and `token` is a function,
224
+ the supplier is called once more with `{forceRefresh: true}` and, if that yields a usable value, the
225
+ **same** request is re-sent once. Nothing else is ever retried — not a second time, not another
226
+ status, and never a `requireAuth: false` request. `onUnauthorized` receives the terminal `401` error
227
+ — after a failed recovery, or immediately when recovery is off or the token is a plain string — at
228
+ most once per call, and never on success.
229
+
230
+ **`headers` is the base every per-request `headers` option builds on.** A per-request header with
231
+ the same name wins, and neither can displace the `authorization` bearer or the `content-type` the
232
+ client sets for a JSON body.
233
+
136
234
  ### `W6W_BASE_URL` is an origin
137
235
 
138
236
  The API is served at the **root** of its own host — `https://api.example.com/vars`, not `…/api/vars`
@@ -163,6 +261,10 @@ Sent as `Authorization: Bearer <token>` on **every** request — there are no an
163
261
  this API. A client with no token can still be constructed (so tools that only print help or a
164
262
  version work offline); the configuration error naming `W6W_TOKEN` surfaces on the first request.
165
263
 
264
+ The variable is a plain string only. A credential that has to change between requests is spelled in
265
+ the constructor — `token: () => …`, [above](#the-four-options-a-host-embedding-w6w-needs) — never in
266
+ the environment.
267
+
166
268
  ## Errors
167
269
 
168
270
  Two error types, and the difference between them is diagnostic:
@@ -178,23 +280,71 @@ Classify by `status`, and by a **prefix** of `code` (`unknown_*`, `invalid_*`, `
178
280
  by an exhaustive list of codes, which the server extends freely. Note that a `424` means the target
179
281
  app or its upstream vendor failed, not that w6w did; it is passed through untouched.
180
282
 
181
- Nothing is retried, no token is refreshed, and a `401` has no side effect beyond the raised error.
283
+ Nothing is retried, no token is refreshed, and a `401` has no side effect beyond the raised error —
284
+ unless you opted in with `refreshOnUnauthorized`, which retries the failed request exactly once (see
285
+ [the four options a host embedding w6w needs](#the-four-options-a-host-embedding-w6w-needs)).
286
+
287
+ ## Embedding for enterprise tenants
288
+
289
+ If you are a partner embedding w6w inside your OWN product, your backend mints a short-lived,
290
+ per-user w6w token with one call — `exchangeToken`, from a **separate** entry point,
291
+ `@w6w/sdk/server`, never from `@w6w/sdk` itself:
292
+
293
+ ```ts
294
+ import { exchangeToken } from "@w6w/sdk/server";
295
+ ```
296
+
297
+ This is a backend-only function: it takes your tenant's `clientId`/`clientSecret`, which must never
298
+ reach a browser or a mobile client. A typical route on your OWN backend — never called directly from
299
+ your frontend — looks like this:
300
+
301
+ ```ts
302
+ // Your backend, e.g. POST /api/w6w-token
303
+ app.post("/api/w6w-token", async (req, res) => {
304
+ const session = await readPartnerSession(req); // YOUR auth, not w6w's
305
+
306
+ // Exchange trusts whatever `account` it is given — w6w has no way to verify
307
+ // it against your own data, so YOU derive it from YOUR OWN membership data,
308
+ // never from an unauthenticated client input (a query param, a request body
309
+ // field a browser could set).
310
+ const account = await yourOwnMembershipLookup(session.userId);
311
+
312
+ const { token, expiresIn } = await exchangeToken({
313
+ baseUrl: process.env.W6W_BASE_URL!,
314
+ clientId: process.env.W6W_TENANT_CLIENT_ID!,
315
+ clientSecret: process.env.W6W_TENANT_CLIENT_SECRET!, // never sent to the browser
316
+ subject: session.userId,
317
+ account,
318
+ });
319
+
320
+ res.json({ token, expiresAt: Date.now() + expiresIn * 1000 });
321
+ });
322
+ ```
323
+
324
+ Your frontend calls `/api/w6w-token`, gets `{ token, expiresAt }`, and uses `token` as `W6W_TOKEN`/a
325
+ bearer for the rest of the session — the tenant secret itself never leaves your backend. Credentials
326
+ travel only as an HTTP `Authorization: Basic base64(clientId:clientSecret)` header — never in the
327
+ request body, the URL or a query string — and every malformed input (a blank
328
+ `clientId`/`clientSecret`/`subject`, a `clientId` containing `:`, a non-latin-1
329
+ `clientId`/`clientSecret`) raises a local `ConfigError` before any network call. The
330
+ [embedding guide](https://docs.w6w.io/clients/node/embedding/) walks through token caching and
331
+ refresh end to end; [`../docs/sdk-surface.md`](../docs/sdk-surface.md) "Server-only subpath —
332
+ `@w6w/sdk/server`" pins the contract in both languages.
182
333
 
183
334
  ## The surface
184
335
 
185
336
  What operations exist is not decided in this repo. It is defined by the shared machine-readable
186
- contract **`endpoints.json`**, which all three w6w wrappers implement and which each one's
187
- conformance test reads directly — the same file, never a vendored copy. An operation missing from a
188
- wrapper is a failing test, not a preference.
337
+ contract **`endpoints.json`**, which every contract lane (this SDK, the CLI and the Python client)
338
+ implements and which each one's conformance test reads directly — the same file, never a vendored
339
+ copy. An operation missing from a wrapper is a failing test, not a preference.
189
340
 
190
- Some operations are marked `planned` in that contract: they are implemented and unit-tested here,
191
- but the corresponding server route is not live yet, so calling them against a server today returns
192
- `404`. The marker records **server** readiness, not wrapper completeness.
341
+ An operation marked `planned` in that contract is implemented and unit-tested here ahead of its
342
+ server route. The marker records **server** readiness, not wrapper completeness.
193
343
 
194
344
  ## Versioning
195
345
 
196
- The version is a shared fact across all three wrappers, so a release may go out for this package
197
- even when nothing in it changed — a divergent version is far more expensive than an empty release.
346
+ The version is a shared fact across all four packages, so a release may go out for this package even
347
+ when nothing in it changed — a divergent version is far more expensive than an empty release.
198
348
 
199
349
  Below `1.0.0`, **breaking changes may land in a minor bump.** That grace ends at `1.0.0`; do not
200
350
  plan around it.
package/dist/mod.d.ts CHANGED
@@ -17,8 +17,8 @@
17
17
  export { VERSION } from "./src/version.ts";
18
18
  export { W6WClient } from "./src/client.ts";
19
19
  export { ApiError, ConfigError } from "./src/errors.ts";
20
- export { BASE_PATH, type FetchLike, joinBaseUrl, type ResolvedConfig, type W6WClientOptions, } from "./src/config.ts";
21
- export type { HttpMethod, HttpResponse, QueryParams, RequestOptions } from "./src/http.ts";
20
+ export { BASE_PATH, type FetchLike, joinBaseUrl, type ResolvedConfig, type TokenProvider, type W6WClientOptions, } from "./src/config.ts";
21
+ export type { CallOptions, HttpMethod, HttpResponse, QueryParams, RequestOptions, } from "./src/http.ts";
22
22
  export { path } from "./src/http.ts";
23
23
  export { DocumentsApi } from "./src/documents.ts";
24
24
  export type { DocumentCreateInput, DocumentOptions, DocumentPatch, DocumentsHost, } from "./src/documents.ts";
@@ -30,12 +30,14 @@ export { ConnectionsApi } from "./src/connections.ts";
30
30
  export type { ConnectionsHost } from "./src/connections.ts";
31
31
  export { WorkflowsApi } from "./src/workflows.ts";
32
32
  export { FunctionsApi } from "./src/functions.ts";
33
- export type { FunctionRunOptions, FunctionsHost } from "./src/functions.ts";
33
+ export type { FunctionDefinition, FunctionDetail, FunctionRunOptions, FunctionsHost, } from "./src/functions.ts";
34
34
  export { EndpointsApi } from "./src/endpoints.ts";
35
35
  export type { EndpointRunOptions, EndpointsHost } from "./src/endpoints.ts";
36
- export type { WorkflowListOptions, WorkflowRunOptions, WorkflowRunResult, WorkflowsHost, } from "./src/workflows.ts";
36
+ export { TeamApi } from "./src/team.ts";
37
+ export type { TeamHost, TeamInvite, TeamInviteInput, TeamInviteWithLink, TeamMember, } from "./src/team.ts";
38
+ export type { WorkflowDefinition, WorkflowDetail, WorkflowListOptions, WorkflowRunOptions, WorkflowRunResult, WorkflowSaveResult, WorkflowsHost, WorkflowWriteOptions, } from "./src/workflows.ts";
37
39
  export { runUrn } from "./src/run.ts";
38
40
  export type { RunHost, RunInput } from "./src/run.ts";
39
41
  export { isActionRun, isFunctionRun, isTerminalRunStatus, isWorkflowRun } from "./src/types.ts";
40
- export type { ActionRunEnvelope, ConnectionState, ConnectionSummary, Doc, DocFormat, FunctionRunEnvelope, Me, RunEnvelope, RunResult, RunStatus, StepError, UnknownRunEnvelope, Var, VarType, WorkflowRunEnvelope, WorkflowStatus, WorkflowSummary, } from "./src/types.ts";
42
+ export type { ActionRunEnvelope, ConnectionAppMeta, ConnectionState, ConnectionSummary, Doc, DocFormat, FunctionRunEnvelope, FunctionSummary, InvocationFrame, Me, RunEnvelope, RunResult, RunStatus, StepError, UnknownRunEnvelope, Var, VarType, WorkflowRunEnvelope, WorkflowStatus, WorkflowSummary, } from "./src/types.ts";
41
43
  //# sourceMappingURL=mod.d.ts.map
package/dist/mod.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,OAA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B,cAAc,EACd,eAAe,GAChB,MAAM,gBAAgB,CAAC"}
package/dist/mod.js CHANGED
@@ -40,6 +40,7 @@ export { ConnectionsApi } from "./src/connections.js";
40
40
  export { WorkflowsApi } from "./src/workflows.js";
41
41
  export { FunctionsApi } from "./src/functions.js";
42
42
  export { EndpointsApi } from "./src/endpoints.js";
43
+ export { TeamApi } from "./src/team.js";
43
44
  // Execution (T2.1.5): the URN-addressed `run`. `client.run(input)` is a method
44
45
  // on the client, so what is exported is its host interface, its input type and
45
46
  // the standalone function the client delegates to.
package/dist/mod.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"mod.js","sourceRoot":"","sources":["../mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,8EAA8E;AAC9E,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EACL,SAAS,EAET,WAAW,GAGZ,MAAM,iBAAiB,CAAC;AAEzB,8EAA8E;AAC9E,+EAA+E;AAC/E,8EAA8E;AAC9E,iEAAiE;AACjE,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAErC,2EAA2E;AAC3E,0EAA0E;AAC1E,2EAA2E;AAC3E,sCAAsC;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAOlD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAGxC,gFAAgF;AAChF,gFAAgF;AAChF,wEAAwE;AACxE,gFAAgF;AAChF,6CAA6C;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEtC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,YAAY,EA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EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAmBxC,+EAA+E;AAC/E,+EAA+E;AAC/E,mDAAmD;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAGtC,+EAA+E;AAC/E,8EAA8E;AAC9E,gFAAgF;AAChF,uEAAuE;AACvE,wEAAwE;AACxE,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC"}
@@ -18,8 +18,9 @@ import { type ResolvedConfig, type W6WClientOptions } from "./config.ts";
18
18
  import { ConnectionsApi } from "./connections.ts";
19
19
  import { ConsoleApi } from "./console/mod.ts";
20
20
  import { DocumentsApi } from "./documents.ts";
21
- import { type HttpResponse, type RequestOptions } from "./http.ts";
21
+ import { type CallOptions, type HttpResponse, type RequestOptions } from "./http.ts";
22
22
  import { type RunInput } from "./run.ts";
23
+ import { TeamApi } from "./team.ts";
23
24
  import type { Me, RunEnvelope } from "./types.ts";
24
25
  import { VarsApi } from "./vars.ts";
25
26
  import { EndpointsApi } from "./endpoints.ts";
@@ -128,6 +129,13 @@ export declare class W6WClient {
128
129
  * exactly like `vars` and `connections`.
129
130
  */
130
131
  readonly console: ConsoleApi;
132
+ /**
133
+ * The caller's account team: `members`, `invite`, `invites`, `revokeInvite`,
134
+ * `setRole`, `removeMember`. Not project-scoped — team membership is
135
+ * account-wide — and constructed with the transport only, exactly like
136
+ * `vars` and `connections`.
137
+ */
138
+ readonly team: TeamApi;
131
139
  /**
132
140
  * @param options - Explicit configuration; anything omitted falls back to the environment.
133
141
  * @throws {ConfigError} When no base URL is configured, or the host has no `fetch`.
@@ -143,11 +151,12 @@ export declare class W6WClient {
143
151
  * `versions.wrapper`, this package's own version, which is filled in and
144
152
  * never overwrites a key the server supplied.
145
153
  *
154
+ * @param options - Optional per-call transport options (`signal` to abort).
146
155
  * @returns The caller's identity.
147
156
  * @throws {ConfigError} When no token is configured.
148
157
  * @throws {ApiError} On any non-2xx, e.g. a `401` when the token is rejected.
149
158
  */
150
- me(): Promise<Me>;
159
+ me(options?: CallOptions): Promise<Me>;
151
160
  /**
152
161
  * Run whatever a URN addresses — a connection action, a function, an endpoint
153
162
  * or a workflow — and get back the kind-tagged envelope.
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAGL,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACtB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,OAAO,EAAE,KAAK,YAAY,EAAW,KAAK,cAAc,EAAE,MAAM,WAAW,CAAC;AAE5E,OAAO,EAAE,KAAK,QAAQ,EAAU,MAAM,UAAU,CAAC;AACjD,OAAO,KAAK,EAAE,EAAE,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,SAAS;;IACpB;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;IAEhC;;;;OAIG;IACH,QAAQ,CAAC,SAAS,EAAE,YAAY,CAAC;IAEjC;;;;;OAKG;IACH,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAEvB;;;;OAIG;IACH,QAAQ,CAAC,WAAW,EAAE,cAAc,CAAC;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} from "./http.js";
23
23
  import { fetchMe } from "./me.js";
24
24
  import { runUrn } from "./run.js";
25
+ import { TeamApi } from "./team.js";
25
26
  import { VarsApi } from "./vars.js";
26
27
  import { EndpointsApi } from "./endpoints.js";
27
28
  import { FunctionsApi } from "./functions.js";
@@ -128,6 +129,13 @@ export class W6WClient {
128
129
  * exactly like `vars` and `connections`.
129
130
  */
130
131
  console;
132
+ /**
133
+ * The caller's account team: `members`, `invite`, `invites`, `revokeInvite`,
134
+ * `setRole`, `removeMember`. Not project-scoped — team membership is
135
+ * account-wide — and constructed with the transport only, exactly like
136
+ * `vars` and `connections`.
137
+ */
138
+ team;
131
139
  #fetch;
132
140
  /**
133
141
  * @param options - Explicit configuration; anything omitted falls back to the environment.
@@ -160,6 +168,7 @@ export class W6WClient {
160
168
  this.functions = new FunctionsApi(this);
161
169
  this.endpoints = new EndpointsApi(this);
162
170
  this.console = new ConsoleApi(this);
171
+ this.team = new TeamApi(this);
163
172
  }
164
173
  /**
165
174
  * Who this client's credential says you are, plus the versions of the
@@ -171,12 +180,13 @@ export class W6WClient {
171
180
  * `versions.wrapper`, this package's own version, which is filled in and
172
181
  * never overwrites a key the server supplied.
173
182
  *
183
+ * @param options - Optional per-call transport options (`signal` to abort).
174
184
  * @returns The caller's identity.
175
185
  * @throws {ConfigError} When no token is configured.
176
186
  * @throws {ApiError} On any non-2xx, e.g. a `401` when the token is rejected.
177
187
  */
178
- me() {
179
- return fetchMe(this);
188
+ me(options) {
189
+ return fetchMe(this, options);
180
190
  }
181
191
  /**
182
192
  * Run whatever a URN addresses — a connection action, a function, an endpoint
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAEL,aAAa,GAGd,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,kBA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C,MAAM,EAAE,OAAO,CAAC,CAAC;IACvD,CAAC;CACF"}
@@ -8,6 +8,7 @@
8
8
  *
9
9
  * @module
10
10
  */
11
+ import { type ApiError } from "./errors.ts";
11
12
  /**
12
13
  * The API's base path, from the shared contract's `basePath`
13
14
  * (`packages/wrappers/endpoints.json`).
@@ -31,6 +32,28 @@ export declare const BASE_PATH = "";
31
32
  * narrower one), while a fake only has to accept a URL string.
32
33
  */
33
34
  export type FetchLike = (input: string, init?: RequestInit) => Promise<Response>;
35
+ /**
36
+ * A per-request token supplier.
37
+ *
38
+ * Called **per request** — never cached after it settles, never resolved once
39
+ * at construction — so a host can rotate or mint a token out-of-band (a tenant
40
+ * exchange, a short-lived partner credential) and have the very next call pick
41
+ * it up. Requests that are in flight **concurrently** on one client share ONE
42
+ * supplier call (and its result); a request that starts after it settled calls
43
+ * the supplier again. Memoize the supplier yourself if minting is expensive.
44
+ * `ctx.forceRefresh` is set to `true` exactly once, on the single
45
+ * recovery retry a `401`/`unauthorized` triggers (`docs/implementation.md`
46
+ * §3); every ordinary per-request resolution omits it. A `string` `token` is
47
+ * the degenerate case of this shape — it behaves exactly as before.
48
+ *
49
+ * May return synchronously or return a `Promise`; either is awaited before the
50
+ * bearer is attached. A nullish or blank (after trimming) result is treated
51
+ * exactly like a nullish/blank static token — a {@linkcode ConfigError}, never
52
+ * a request sent with no credential.
53
+ */
54
+ export type TokenProvider = (ctx?: {
55
+ forceRefresh?: boolean;
56
+ }) => string | null | undefined | Promise<string | null | undefined>;
34
57
  /** Constructor options for a client. Every field is optional. */
35
58
  export interface W6WClientOptions {
36
59
  /**
@@ -42,8 +65,40 @@ export interface W6WClientOptions {
42
65
  * Overrides `W6W_BASE_URL`.
43
66
  */
44
67
  baseUrl?: string;
45
- /** Bearer token, sent on every request. Overrides `W6W_TOKEN`. */
46
- token?: string;
68
+ /**
69
+ * Bearer token, resolved on **every** request — not just once at
70
+ * construction. A plain `string` is sent verbatim on every call, exactly as
71
+ * before; a {@linkcode TokenProvider} function is called (and awaited)
72
+ * per request (concurrent requests share one in-flight call), so a host can hand back a token minted or rotated after
73
+ * this client was constructed. Overrides `W6W_TOKEN`, which stays a plain
74
+ * string (there is no environment-variable spelling of a supplier).
75
+ */
76
+ token?: string | TokenProvider;
77
+ /**
78
+ * Opt in to a single, one-shot recovery when a request fails with
79
+ * `401`/`unauthorized`: `token` (which must be a function for this to do
80
+ * anything) is called once more with `{forceRefresh: true}`, and if that
81
+ * yields a usable value the SAME request is re-sent once with it. Off
82
+ * (`false`) by default — the behaviour before this option existed. Never
83
+ * retries a second time, never retries any other status or code, and never
84
+ * applies to a `requireAuth: false` request.
85
+ */
86
+ refreshOnUnauthorized?: boolean;
87
+ /**
88
+ * Called with the terminal `401`/`unauthorized` {@linkcode ApiError} of a
89
+ * bearer request — after a failed recovery retry, or immediately when
90
+ * recovery is off or not possible (a static `token`) — at most once per
91
+ * call. Never called on success, never called twice, and never called for a
92
+ * `requireAuth: false` request.
93
+ */
94
+ onUnauthorized?: (error: ApiError) => void;
95
+ /**
96
+ * Default headers sent with every request. This is the **base** every
97
+ * per-request `headers` option builds on: a per-request header with the
98
+ * same name wins, and neither can ever displace the bearer this transport
99
+ * attaches (`authorization`) or the `content-type` it sets for a JSON body.
100
+ */
101
+ headers?: Record<string, string>;
47
102
  /**
48
103
  * Default project id for the project-scoped operations — `documents.*` and
49
104
  * `workflows.list`, which read it too.
@@ -69,8 +124,14 @@ export interface ResolvedConfig {
69
124
  * value that is not an absolute `http(s)` URL with a host.
70
125
  */
71
126
  readonly baseUrl: string;
72
- /** The bearer token, or `null` when none was configured. */
73
- readonly token: string | null;
127
+ /** The bearer token or supplier, or `null` when none was configured. */
128
+ readonly token: string | TokenProvider | null;
129
+ /** Opt-in one-shot 401 recovery. Defaults to `false`. */
130
+ readonly refreshOnUnauthorized: boolean;
131
+ /** Terminal-401 callback, or `null` when none was configured. */
132
+ readonly onUnauthorized: ((error: ApiError) => void) | null;
133
+ /** Default headers sent with every request. Defaults to `{}`. */
134
+ readonly headers: Record<string, string>;
74
135
  /** Default project id, or `null`. */
75
136
  readonly project: string | null;
76
137
  }
@@ -146,14 +207,30 @@ export declare function resolveConfig(options?: W6WClientOptions): ResolvedConfi
146
207
  * There are no anonymous operations in this surface
147
208
  * (`docs/implementation.md` §2).
148
209
  *
210
+ * **Resolved per call, never cached after it settles.** When `config.token` is
211
+ * a {@linkcode TokenProvider} it is called (and its result awaited) right here —
212
+ * a plain string is the degenerate case that needs no call at all. Ordinary
213
+ * calls (`ctx?.forceRefresh` not `true`) that overlap on one `config` share ONE
214
+ * in-flight supplier call; the slot is dropped when it settles, on success or
215
+ * failure, so nothing is cached. A forced refresh neither joins nor fills that
216
+ * slot. `ctx` is
217
+ * forwarded verbatim to the provider; passing `{forceRefresh: true}` is the
218
+ * one and only seam `request()`'s recovery retry uses (`docs/implementation.md`
219
+ * §3) — ordinary resolution never passes it.
220
+ *
149
221
  * A blank token counts as no token, for the same reason a blank base URL does:
150
222
  * `W6W_TOKEN=` is how a shell or a Dockerfile spells "I meant to set this and
151
223
  * did not", and `Authorization: Bearer ` would turn that into an opaque 401
152
- * instead of the one message that explains it.
224
+ * instead of the one message that explains it. The same rule applies to
225
+ * whatever a provider returns: nullish or blank is treated exactly like a
226
+ * nullish/blank static token — the error never echoes the value either way.
153
227
  *
154
228
  * @param config - The resolved configuration.
229
+ * @param ctx - Forwarded to a function-typed `token`; unused for a string one.
155
230
  * @returns The configured token, verbatim.
156
231
  * @throws {ConfigError} When no non-blank token is configured.
157
232
  */
158
- export declare function requireToken(config: ResolvedConfig): string;
233
+ export declare function requireToken(config: ResolvedConfig, ctx?: {
234
+ forceRefresh?: boolean;
235
+ }): Promise<string>;
159
236
  //# sourceMappingURL=config.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAKH;;;;;;;;;GASG;AACH,eAAO,MAAM,SAAS,KA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,MAAM,EAAE,MAAM,CAAC,CAAC;IACzC,qCAAqC;IACrC,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACjC;AAeD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAuBlD;AAkBD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,aAAa,CAAC,OAAO,GAAE,gBAAqB,GAAG,cAAc,CAY5E;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,cAAc,EACtB,GAAG,CAAC,EAAE;IAAE,YAAY,CAAC,EAAE,OAAO,CAAA;CAAE,GAC/B,OAAO,CAAC,MAAM,CAAC,CAajB"}
@@ -138,6 +138,9 @@ export function resolveConfig(options = {}) {
138
138
  // never answer differently for the same input.
139
139
  baseUrl: joinBaseUrl(options.baseUrl ?? readEnv(ENV_BASE_URL) ?? ""),
140
140
  token: options.token ?? readEnv(ENV_TOKEN) ?? null,
141
+ refreshOnUnauthorized: options.refreshOnUnauthorized ?? false,
142
+ onUnauthorized: options.onUnauthorized ?? null,
143
+ headers: options.headers ?? {},
141
144
  project: options.project ?? null,
142
145
  };
143
146
  }
@@ -149,21 +152,54 @@ export function resolveConfig(options = {}) {
149
152
  * There are no anonymous operations in this surface
150
153
  * (`docs/implementation.md` §2).
151
154
  *
155
+ * **Resolved per call, never cached after it settles.** When `config.token` is
156
+ * a {@linkcode TokenProvider} it is called (and its result awaited) right here —
157
+ * a plain string is the degenerate case that needs no call at all. Ordinary
158
+ * calls (`ctx?.forceRefresh` not `true`) that overlap on one `config` share ONE
159
+ * in-flight supplier call; the slot is dropped when it settles, on success or
160
+ * failure, so nothing is cached. A forced refresh neither joins nor fills that
161
+ * slot. `ctx` is
162
+ * forwarded verbatim to the provider; passing `{forceRefresh: true}` is the
163
+ * one and only seam `request()`'s recovery retry uses (`docs/implementation.md`
164
+ * §3) — ordinary resolution never passes it.
165
+ *
152
166
  * A blank token counts as no token, for the same reason a blank base URL does:
153
167
  * `W6W_TOKEN=` is how a shell or a Dockerfile spells "I meant to set this and
154
168
  * did not", and `Authorization: Bearer ` would turn that into an opaque 401
155
- * instead of the one message that explains it.
169
+ * instead of the one message that explains it. The same rule applies to
170
+ * whatever a provider returns: nullish or blank is treated exactly like a
171
+ * nullish/blank static token — the error never echoes the value either way.
156
172
  *
157
173
  * @param config - The resolved configuration.
174
+ * @param ctx - Forwarded to a function-typed `token`; unused for a string one.
158
175
  * @returns The configured token, verbatim.
159
176
  * @throws {ConfigError} When no non-blank token is configured.
160
177
  */
161
- export function requireToken(config) {
162
- if (config.token === null || config.token.trim().length === 0) {
178
+ export function requireToken(config, ctx) {
179
+ if (typeof config.token !== "function" || ctx?.forceRefresh === true) {
180
+ return resolveToken(config, ctx);
181
+ }
182
+ const pending = inflightTokens.get(config);
183
+ if (pending)
184
+ return pending;
185
+ const flight = resolveToken(config, ctx);
186
+ inflightTokens.set(config, flight);
187
+ const clear = () => {
188
+ if (inflightTokens.get(config) === flight)
189
+ inflightTokens.delete(config);
190
+ };
191
+ flight.then(clear, clear);
192
+ return flight;
193
+ }
194
+ /** One in-flight ordinary supplier call per config (never a module-level slot). */
195
+ const inflightTokens = new WeakMap();
196
+ async function resolveToken(config, ctx) {
197
+ const raw = typeof config.token === "function" ? await config.token(ctx) : config.token;
198
+ if (raw === null || raw === undefined || raw.trim().length === 0) {
163
199
  throw new ConfigError("No w6w API token is configured. Pass one to the client " +
164
200
  '(new W6WClient({ token: "…" })) or set the ' +
165
201
  `${ENV_TOKEN} environment variable. Every w6w API operation is authenticated.`);
166
202
  }
167
- return config.token;
203
+ return raw;
168
204
  }
169
205
  //# sourceMappingURL=config.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;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