@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.
Files changed (59) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +131 -0
  3. package/dist/mod.d.ts +37 -0
  4. package/dist/mod.d.ts.map +1 -0
  5. package/dist/mod.js +51 -0
  6. package/dist/mod.js.map +1 -0
  7. package/dist/src/client.d.ts +134 -0
  8. package/dist/src/client.d.ts.map +1 -0
  9. package/dist/src/client.js +165 -0
  10. package/dist/src/client.js.map +1 -0
  11. package/dist/src/config.d.ts +151 -0
  12. package/dist/src/config.d.ts.map +1 -0
  13. package/dist/src/config.js +161 -0
  14. package/dist/src/config.js.map +1 -0
  15. package/dist/src/connections.d.ts +58 -0
  16. package/dist/src/connections.d.ts.map +1 -0
  17. package/dist/src/connections.js +52 -0
  18. package/dist/src/connections.js.map +1 -0
  19. package/dist/src/documents.d.ts +168 -0
  20. package/dist/src/documents.d.ts.map +1 -0
  21. package/dist/src/documents.js +178 -0
  22. package/dist/src/documents.js.map +1 -0
  23. package/dist/src/env.d.ts +61 -0
  24. package/dist/src/env.d.ts.map +1 -0
  25. package/dist/src/env.js +73 -0
  26. package/dist/src/env.js.map +1 -0
  27. package/dist/src/errors.d.ts +79 -0
  28. package/dist/src/errors.d.ts.map +1 -0
  29. package/dist/src/errors.js +88 -0
  30. package/dist/src/errors.js.map +1 -0
  31. package/dist/src/http.d.ts +130 -0
  32. package/dist/src/http.d.ts.map +1 -0
  33. package/dist/src/http.js +150 -0
  34. package/dist/src/http.js.map +1 -0
  35. package/dist/src/me.d.ts +53 -0
  36. package/dist/src/me.d.ts.map +1 -0
  37. package/dist/src/me.js +77 -0
  38. package/dist/src/me.js.map +1 -0
  39. package/dist/src/run.d.ts +92 -0
  40. package/dist/src/run.d.ts.map +1 -0
  41. package/dist/src/run.js +83 -0
  42. package/dist/src/run.js.map +1 -0
  43. package/dist/src/types.d.ts +362 -0
  44. package/dist/src/types.d.ts.map +1 -0
  45. package/dist/src/types.js +109 -0
  46. package/dist/src/types.js.map +1 -0
  47. package/dist/src/vars.d.ts +149 -0
  48. package/dist/src/vars.d.ts.map +1 -0
  49. package/dist/src/vars.js +149 -0
  50. package/dist/src/vars.js.map +1 -0
  51. package/dist/src/version.d.ts +14 -0
  52. package/dist/src/version.d.ts.map +1 -0
  53. package/dist/src/version.js +14 -0
  54. package/dist/src/version.js.map +1 -0
  55. package/dist/src/workflows.d.ts +180 -0
  56. package/dist/src/workflows.d.ts.map +1 -0
  57. package/dist/src/workflows.js +160 -0
  58. package/dist/src/workflows.js.map +1 -0
  59. package/package.json +36 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 w6w-io
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,131 @@
1
+ # @w6w/sdk
2
+
3
+ The TypeScript client for the [w6w](https://w6w.dev) HTTP API.
4
+
5
+ It is a **thin** client: transport, auth, error mapping, and typed request/response shapes. No
6
+ business logic, no client-side polling, no hidden retries. If something useful needs two calls
7
+ composed, that composition belongs in the API, not here.
8
+
9
+ The package is authored as runtime-neutral TypeScript against Web standards (`fetch`, `Headers`,
10
+ `URL`, `AbortController`), so the same build runs under Node 18+, Deno and Bun.
11
+
12
+ - **License:** MIT (see [LICENSE](./LICENSE)).
13
+ - **Version:** `0.1.0`.
14
+
15
+ ## Install
16
+
17
+ npm (compiled ESM + type declarations):
18
+
19
+ ```bash
20
+ npm install @w6w/sdk
21
+ ```
22
+
23
+ JSR (the TypeScript source, published verbatim):
24
+
25
+ ```bash
26
+ deno add jsr:@w6w/sdk
27
+ ```
28
+
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.
32
+
33
+ ## Configuration
34
+
35
+ Two environment variables, both read only at client construction:
36
+
37
+ | Variable | Meaning | Required |
38
+ | -------------- | ------------------------------------------------------------------------------------------------------------------------------------- | -------- |
39
+ | `W6W_BASE_URL` | The **origin** of your w6w server, e.g. `https://api.example.com`. The API's base path is appended by the client — do not include it. | Yes |
40
+ | `W6W_TOKEN` | The bearer token, sent as `Authorization: Bearer <token>` on every request. | Yes |
41
+
42
+ Explicit constructor arguments always win over the environment, and credentials are **instance
43
+ state**: two clients in one process can hold different tokens and point at different servers with no
44
+ interference. There is no default base URL — a client built without one and without `W6W_BASE_URL`
45
+ raises a configuration error naming the variable.
46
+
47
+ ```ts
48
+ import { W6wClient } from "@w6w/sdk";
49
+
50
+ // Everything from the environment.
51
+ const client = new W6wClient();
52
+
53
+ // Explicit arguments override W6W_BASE_URL and W6W_TOKEN.
54
+ const other = new W6wClient({ baseUrl: "https://api.example.com", token: "…" });
55
+ ```
56
+
57
+ ### `W6W_BASE_URL` is an origin
58
+
59
+ The client appends the API's base path (`/api`) itself, and never doubles it — so a value that
60
+ already carries the prefix is left alone, and trailing slashes never matter:
61
+
62
+ | `W6W_BASE_URL` | Requests go to |
63
+ | ----------------------------- | ------------------------------- |
64
+ | `https://api.example.com` | `https://api.example.com/api/…` |
65
+ | `https://api.example.com/` | `https://api.example.com/api/…` |
66
+ | `https://api.example.com///` | `https://api.example.com/api/…` |
67
+ | `https://api.example.com/api` | `https://api.example.com/api/…` |
68
+
69
+ A variable that is **set but empty** — or whitespace-only — counts as **unset**, in both variables.
70
+ `W6W_BASE_URL=` is how a shell or a Dockerfile spells "I meant to set this and did not", so it
71
+ raises the same configuration error as an absent one rather than quietly producing a relative URL.
72
+ An empty string passed _explicitly_ to the constructor is likewise an error, and does not fall back
73
+ to the environment.
74
+
75
+ ### `W6W_TOKEN`
76
+
77
+ Sent as `Authorization: Bearer <token>` on **every** request — there are no anonymous operations on
78
+ this API. A client with no token can still be constructed (so tools that only print help or a
79
+ version work offline); the configuration error naming `W6W_TOKEN` surfaces on the first request.
80
+
81
+ ## Errors
82
+
83
+ Two error types, and the difference between them is diagnostic:
84
+
85
+ - **`ConfigError`** — the client never got as far as a request: no base URL, or no token.
86
+ - **`ApiError`** — carries `status`, `code`, `message` and `raw` (the parsed response body, kept
87
+ because an error body carries fields the message drops). It covers exactly three cases: a
88
+ transport failure (`status: 0`, code `network_error`), a non-JSON body on a failing status (code
89
+ `bad_response`, with a snippet of what actually came back — usually a proxy's HTML error page),
90
+ and the server's own error envelope (its `code` and `message`, verbatim).
91
+
92
+ Classify by `status`, and by a **prefix** of `code` (`unknown_*`, `invalid_*`, `*_exists`) — never
93
+ by an exhaustive list of codes, which the server extends freely. Note that a `424` means the target
94
+ app or its upstream vendor failed, not that w6w did; it is passed through untouched.
95
+
96
+ Nothing is retried, no token is refreshed, and a `401` has no side effect beyond the raised error.
97
+
98
+ ## The surface
99
+
100
+ What operations exist is not decided in this repo. It is defined by the shared machine-readable
101
+ contract **`endpoints.json`**, which all three w6w wrappers implement and which each one's
102
+ conformance test reads directly — the same file, never a vendored copy. An operation missing from a
103
+ wrapper is a failing test, not a preference.
104
+
105
+ Some operations are marked `planned` in that contract: they are implemented and unit-tested here,
106
+ but the corresponding server route is not live yet, so calling them against a server today returns
107
+ `404`. The marker records **server** readiness, not wrapper completeness.
108
+
109
+ ## Versioning
110
+
111
+ The version is a shared fact across all three wrappers, so a release may go out for this package
112
+ even when nothing in it changed — a divergent version is far more expensive than an empty release.
113
+
114
+ Below `1.0.0`, **breaking changes may land in a minor bump.** That grace ends at `1.0.0`; do not
115
+ plan around it.
116
+
117
+ ## Development
118
+
119
+ The gates are Deno tasks. They need no network and no server:
120
+
121
+ ```bash
122
+ deno task check # typecheck mod.ts, src/ and tests/
123
+ deno task lint
124
+ deno task fmt:check
125
+ deno task test # every test runs against a mocked transport
126
+ deno task cov # test with coverage, then report it
127
+ ```
128
+
129
+ Tests **never** require a live server. The npm `dist/` build (`npm run build`, i.e.
130
+ `tsc -p tsconfig.build.json`) runs in CI only; `src/*.ts` is the single authored source for both
131
+ registries.
package/dist/mod.d.ts ADDED
@@ -0,0 +1,37 @@
1
+ /**
2
+ * `@w6w/sdk` — the package barrel.
3
+ *
4
+ * This file is the package's single public entry point. `deno.json` exports it to
5
+ * JSR as `./mod.ts` (TypeScript source, verbatim) and `tsconfig.build.json`
6
+ * compiles it to `dist/mod.js` + `dist/mod.d.ts` for npm. One authored source
7
+ * tree, two registries (D7).
8
+ *
9
+ * **Every operation module must be re-exported here.** A module that is not
10
+ * re-exported from this barrel is not part of the published surface: JSR and npm
11
+ * consumers can only reach what this file exports, and the conformance runner
12
+ * walks the client built from these exports. Adding an operation therefore means
13
+ * adding its export line here in the same change.
14
+ *
15
+ * @module
16
+ */
17
+ export { VERSION } from "./src/version.ts";
18
+ export { W6wClient } from "./src/client.ts";
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";
22
+ export { path } from "./src/http.ts";
23
+ export { DocumentsApi } from "./src/documents.ts";
24
+ export type { DocumentCreateInput, DocumentOptions, DocumentPatch, DocumentsHost, } from "./src/documents.ts";
25
+ export { VarsApi } from "./src/vars.ts";
26
+ export type { VarCreateInput, VarPatch, VarsHost } from "./src/vars.ts";
27
+ export { fetchMe } from "./src/me.ts";
28
+ export type { MeHost } from "./src/me.ts";
29
+ export { ConnectionsApi } from "./src/connections.ts";
30
+ export type { ConnectionsHost } from "./src/connections.ts";
31
+ export { WorkflowsApi } from "./src/workflows.ts";
32
+ export type { WorkflowListOptions, WorkflowRunOptions, WorkflowRunResult, WorkflowsHost, } from "./src/workflows.ts";
33
+ export { runUrn } from "./src/run.ts";
34
+ export type { RunHost, RunInput } from "./src/run.ts";
35
+ export { isActionRun, isFunctionRun, isTerminalRunStatus, isWorkflowRun } from "./src/types.ts";
36
+ export type { ActionRunEnvelope, ConnectionState, ConnectionSummary, Doc, DocFormat, FunctionRunEnvelope, Me, RunEnvelope, RunResult, RunStatus, StepError, UnknownRunEnvelope, Var, VarType, WorkflowRunEnvelope, WorkflowStatus, WorkflowSummary, } from "./src/types.ts";
37
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAG3C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EACL,SAAS,EACT,KAAK,SAAS,EACd,WAAW,EACX,KAAK,cAAc,EACnB,KAAK,gBAAgB,GACtB,MAAM,iBAAiB,CAAC;AACzB,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAK3F,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAMrC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,YAAY,EACV,mBAAmB,EACnB,eAAe,EACf,aAAa,EACb,aAAa,GACd,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,YAAY,EAAE,cAAc,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAOxE,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,YAAY,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,YAAY,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,YAAY,EACV,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,EACjB,aAAa,GACd,MAAM,oBAAoB,CAAC;AAK5B,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAOtD,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAEhG,YAAY,EACV,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,GAAG,EACH,SAAS,EACT,mBAAmB,EACnB,EAAE,EACF,WAAW,EACX,SAAS,EACT,SAAS,EACT,SAAS,EACT,kBAAkB,EAClB,GAAG,EACH,OAAO,EACP,mBAAmB,EACnB,cAAc,EACd,eAAe,GAChB,MAAM,gBAAgB,CAAC"}
package/dist/mod.js ADDED
@@ -0,0 +1,51 @@
1
+ /**
2
+ * `@w6w/sdk` — the package barrel.
3
+ *
4
+ * This file is the package's single public entry point. `deno.json` exports it to
5
+ * JSR as `./mod.ts` (TypeScript source, verbatim) and `tsconfig.build.json`
6
+ * compiles it to `dist/mod.js` + `dist/mod.d.ts` for npm. One authored source
7
+ * tree, two registries (D7).
8
+ *
9
+ * **Every operation module must be re-exported here.** A module that is not
10
+ * re-exported from this barrel is not part of the published surface: JSR and npm
11
+ * consumers can only reach what this file exports, and the conformance runner
12
+ * walks the client built from these exports. Adding an operation therefore means
13
+ * adding its export line here in the same change.
14
+ *
15
+ * @module
16
+ */
17
+ export { VERSION } from "./src/version.js";
18
+ // Transport core (T2.1.2): the client, its configuration and the error model.
19
+ export { W6wClient } from "./src/client.js";
20
+ export { ApiError, ConfigError } from "./src/errors.js";
21
+ export { BASE_PATH, joinBaseUrl, } from "./src/config.js";
22
+ // Exported because `W6wClient.request` is public: a host reaching an endpoint
23
+ // this version does not model yet must have the same encoding-at-interpolation
24
+ // tag the operation modules use, or it will concatenate a caller value into a
25
+ // path by hand — the one bug the encoding pin exists to prevent.
26
+ export { path } from "./src/http.js";
27
+ // Asset operations (T2.1.3): documents and vars. The namespace classes are
28
+ // exported alongside their input types because a host that types a helper
29
+ // around `client.documents` needs to name them; they are reached through a
30
+ // client, never constructed directly.
31
+ export { DocumentsApi } from "./src/documents.js";
32
+ export { VarsApi } from "./src/vars.js";
33
+ // Identity and discovery (T2.1.4): `me`, plus the two list operations that make
34
+ // a `conn_…` / `wf_…` id discoverable in the first place (D4). `me` is a method
35
+ // on the client, so what is exported here is its host interface and the
36
+ // standalone function the client delegates to — a host wiring its own transport
37
+ // can call it without constructing a client.
38
+ export { fetchMe } from "./src/me.js";
39
+ export { ConnectionsApi } from "./src/connections.js";
40
+ export { WorkflowsApi } from "./src/workflows.js";
41
+ // Execution (T2.1.5): the URN-addressed `run`. `client.run(input)` is a method
42
+ // on the client, so what is exported is its host interface, its input type and
43
+ // the standalone function the client delegates to.
44
+ export { runUrn } from "./src/run.js";
45
+ // The `kind` discriminators. Exported deliberately and not as an afterthought:
46
+ // `RunEnvelope`'s fourth arm is open (so an unknown `kind` can be handed back
47
+ // rather than raised), and an open union means a bare `env.kind === "workflow"`
48
+ // check does NOT narrow — `env.status` would come out `unknown`. These
49
+ // predicates are how a caller, and the CLI, get typed access to an arm.
50
+ export { isActionRun, isFunctionRun, isTerminalRunStatus, isWorkflowRun } from "./src/types.js";
51
+ //# sourceMappingURL=mod.js.map
@@ -0,0 +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;AAQlD,+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"}
@@ -0,0 +1,134 @@
1
+ /**
2
+ * `W6wClient` — the object every operation hangs off.
3
+ *
4
+ * It holds three things and no behaviour of its own: the resolved
5
+ * configuration, the transport, and (from T2.1.3 onward) the operation
6
+ * namespaces. All of it is **instance** state.
7
+ *
8
+ * That is a mechanism pin, not a style choice (`docs/implementation.md` §2).
9
+ * The browser client this package transcribes keeps its token in a mutable
10
+ * module variable, which is fine for one page and an outright bug for a
11
+ * server-side SDK: two clients in one process would share one credential, so a
12
+ * host juggling tenants would silently issue requests as whichever tenant
13
+ * constructed a client last. Nothing in `src/` holds mutable module state.
14
+ *
15
+ * @module
16
+ */
17
+ import { type ResolvedConfig, type W6wClientOptions } from "./config.ts";
18
+ import { ConnectionsApi } from "./connections.ts";
19
+ import { DocumentsApi } from "./documents.ts";
20
+ import { type HttpResponse, type RequestOptions } from "./http.ts";
21
+ import { type RunInput } from "./run.ts";
22
+ import type { Me, RunEnvelope } from "./types.ts";
23
+ import { VarsApi } from "./vars.ts";
24
+ import { WorkflowsApi } from "./workflows.ts";
25
+ /**
26
+ * A client for the w6w HTTP API.
27
+ *
28
+ * Construction resolves configuration once — explicit arguments first, then the
29
+ * environment (`W6W_BASE_URL`, `W6W_TOKEN`) — and never consults the
30
+ * environment again. A missing base URL raises here; a missing token raises on
31
+ * the first request, so a CLI can print `--help` offline.
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * // From the environment.
36
+ * const client = new W6wClient();
37
+ *
38
+ * // Explicit, overriding the environment. Two clients, two credentials, one
39
+ * // process — no interference.
40
+ * const other = new W6wClient({ baseUrl: "https://api.example.com", token: "t_2" });
41
+ * ```
42
+ */
43
+ export declare class W6wClient {
44
+ #private;
45
+ /**
46
+ * The resolved base URL, credential and default project. Exposed read-only
47
+ * so a host can log *which server* it is talking to without re-deriving the
48
+ * join rule.
49
+ */
50
+ readonly config: ResolvedConfig;
51
+ /**
52
+ * The document store: `list`, `get`, `getByKey`, `create`, `update`,
53
+ * `delete`. Project-scoped — every call accepts an optional `project` that
54
+ * overrides this client's default.
55
+ */
56
+ readonly documents: DocumentsApi;
57
+ /**
58
+ * Typed variables: `list`, `get`, `getByName`, `create`, `update`, `delete`.
59
+ * **No `project` option anywhere** — variables are scoped by tenant/subject
60
+ * only, and the namespace is constructed without this client's configuration
61
+ * so it cannot reach a default scope to send (`docs/implementation.md` §7).
62
+ */
63
+ readonly vars: VarsApi;
64
+ /**
65
+ * Connections: `list` only in this version. Read-only on purpose — creating
66
+ * or testing a connection is an interactive, secret-handling flow that
67
+ * `endpoints.json` puts out of scope for v0.1.0.
68
+ */
69
+ readonly connections: ConnectionsApi;
70
+ /**
71
+ * Workflows: `list` and `run`. `list` is project-scoped and accepts an
72
+ * optional `project` that overrides this client's default; `run` is addressed
73
+ * by `wf_…` id and takes `wait`, `variables` and `trigger`.
74
+ */
75
+ readonly workflows: WorkflowsApi;
76
+ /**
77
+ * @param options - Explicit configuration; anything omitted falls back to the environment.
78
+ * @throws {ConfigError} When no base URL is configured, or the host has no `fetch`.
79
+ */
80
+ constructor(options?: W6wClientOptions);
81
+ /**
82
+ * Who this client's credential says you are, plus the versions of the
83
+ * components that answered.
84
+ *
85
+ * A method on the client rather than a namespace, because that is the symbol
86
+ * `endpoints.json` names (`client.me()`). The response body is flat and
87
+ * carries no envelope; the only thing added to it locally is
88
+ * `versions.wrapper`, this package's own version, which is filled in and
89
+ * never overwrites a key the server supplied.
90
+ *
91
+ * @returns The caller's identity.
92
+ * @throws {ConfigError} When no token is configured.
93
+ * @throws {ApiError} On any non-2xx, e.g. a `401` when the token is rejected.
94
+ */
95
+ me(): Promise<Me>;
96
+ /**
97
+ * Run whatever a URN addresses — a connection action, a function, an endpoint
98
+ * or a workflow — and get back the kind-tagged envelope.
99
+ *
100
+ * A method on the client rather than a namespace, because that is the symbol
101
+ * `endpoints.json` names (`client.run(input)`). It is the dispatching
102
+ * counterpart to `workflows.run`, which stays separate because `?wait=`,
103
+ * `variables` and `trigger` have no slot in this three-field shape (D4).
104
+ *
105
+ * Discriminate the result with `isActionRun` / `isFunctionRun` /
106
+ * `isWorkflowRun`; a `kind` this version has never heard of is handed back
107
+ * verbatim rather than raised.
108
+ *
109
+ * `POST /api/run` (verified live 2026-07-28).
110
+ *
111
+ * @param input - The URN, an optional `action`, and the payload.
112
+ * @returns The `RunEnvelope`, exactly as it arrived.
113
+ * @throws {ConfigError} When no token is configured.
114
+ * @throws {ApiError} On any non-2xx, e.g. `404` for an unresolvable URN or
115
+ * `424` when the target app failed during execute.
116
+ */
117
+ run(input: RunInput): Promise<RunEnvelope>;
118
+ /**
119
+ * Perform one request against this client's server, with this client's
120
+ * credential.
121
+ *
122
+ * This is the seam the operation modules are built on; it is public so a host
123
+ * can also reach an endpoint this version does not model yet, rather than
124
+ * constructing a second client by hand. It returns the status alongside the
125
+ * body — a `202` is success on this API.
126
+ *
127
+ * @param options - The request to make.
128
+ * @returns The status and parsed body.
129
+ * @throws {ConfigError} When no token is configured.
130
+ * @throws {ApiError} On a transport failure, a non-JSON error body, or an error envelope.
131
+ */
132
+ request<T>(options: RequestOptions): Promise<HttpResponse<T>>;
133
+ }
134
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +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,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;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;IAErC;;;;OAIG;IACH,QAAQ,CAAC,SAAS,EAAE,YAAY,CAAC;IAIjC;;;OAGG;gBACS,OAAO,GAAE,gBAAqB;IA4B1C;;;;;;;;;;;;;OAaG;IACH,EAAE,IAAI,OAAO,CAAC,EAAE,CAAC;IAIjB;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,GAAG,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC;IAI1C;;;;;;;;;;;;;OAaG;IACH,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;CAG9D"}
@@ -0,0 +1,165 @@
1
+ /**
2
+ * `W6wClient` — the object every operation hangs off.
3
+ *
4
+ * It holds three things and no behaviour of its own: the resolved
5
+ * configuration, the transport, and (from T2.1.3 onward) the operation
6
+ * namespaces. All of it is **instance** state.
7
+ *
8
+ * That is a mechanism pin, not a style choice (`docs/implementation.md` §2).
9
+ * The browser client this package transcribes keeps its token in a mutable
10
+ * module variable, which is fine for one page and an outright bug for a
11
+ * server-side SDK: two clients in one process would share one credential, so a
12
+ * host juggling tenants would silently issue requests as whichever tenant
13
+ * constructed a client last. Nothing in `src/` holds mutable module state.
14
+ *
15
+ * @module
16
+ */
17
+ import { resolveConfig, } from "./config.js";
18
+ import { ConnectionsApi } from "./connections.js";
19
+ import { DocumentsApi } from "./documents.js";
20
+ import { ConfigError } from "./errors.js";
21
+ import { request } from "./http.js";
22
+ import { fetchMe } from "./me.js";
23
+ import { runUrn } from "./run.js";
24
+ import { VarsApi } from "./vars.js";
25
+ import { WorkflowsApi } from "./workflows.js";
26
+ /**
27
+ * A client for the w6w HTTP API.
28
+ *
29
+ * Construction resolves configuration once — explicit arguments first, then the
30
+ * environment (`W6W_BASE_URL`, `W6W_TOKEN`) — and never consults the
31
+ * environment again. A missing base URL raises here; a missing token raises on
32
+ * the first request, so a CLI can print `--help` offline.
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * // From the environment.
37
+ * const client = new W6wClient();
38
+ *
39
+ * // Explicit, overriding the environment. Two clients, two credentials, one
40
+ * // process — no interference.
41
+ * const other = new W6wClient({ baseUrl: "https://api.example.com", token: "t_2" });
42
+ * ```
43
+ */
44
+ export class W6wClient {
45
+ /**
46
+ * The resolved base URL, credential and default project. Exposed read-only
47
+ * so a host can log *which server* it is talking to without re-deriving the
48
+ * join rule.
49
+ */
50
+ config;
51
+ /**
52
+ * The document store: `list`, `get`, `getByKey`, `create`, `update`,
53
+ * `delete`. Project-scoped — every call accepts an optional `project` that
54
+ * overrides this client's default.
55
+ */
56
+ documents;
57
+ /**
58
+ * Typed variables: `list`, `get`, `getByName`, `create`, `update`, `delete`.
59
+ * **No `project` option anywhere** — variables are scoped by tenant/subject
60
+ * only, and the namespace is constructed without this client's configuration
61
+ * so it cannot reach a default scope to send (`docs/implementation.md` §7).
62
+ */
63
+ vars;
64
+ /**
65
+ * Connections: `list` only in this version. Read-only on purpose — creating
66
+ * or testing a connection is an interactive, secret-handling flow that
67
+ * `endpoints.json` puts out of scope for v0.1.0.
68
+ */
69
+ connections;
70
+ /**
71
+ * Workflows: `list` and `run`. `list` is project-scoped and accepts an
72
+ * optional `project` that overrides this client's default; `run` is addressed
73
+ * by `wf_…` id and takes `wait`, `variables` and `trigger`.
74
+ */
75
+ workflows;
76
+ #fetch;
77
+ /**
78
+ * @param options - Explicit configuration; anything omitted falls back to the environment.
79
+ * @throws {ConfigError} When no base URL is configured, or the host has no `fetch`.
80
+ */
81
+ constructor(options = {}) {
82
+ this.config = resolveConfig(options);
83
+ if (options.fetch) {
84
+ this.#fetch = options.fetch;
85
+ }
86
+ else {
87
+ const global = globalThis.fetch;
88
+ if (typeof global !== "function") {
89
+ throw new ConfigError("This runtime has no global fetch. Pass an implementation " +
90
+ "(new W6wClient({ fetch })) or run on Node 18+, Deno or Bun.");
91
+ }
92
+ // Bound, so the default keeps working when it is called as a bare
93
+ // function reference rather than as a method of the global object.
94
+ this.#fetch = global.bind(globalThis);
95
+ }
96
+ // Namespaces are per-instance and hold this client, so they inherit its
97
+ // credential and base URL — never a module-level one. `vars` and
98
+ // `connections` are handed the transport only; `documents` and `workflows`
99
+ // additionally see the configuration, because they are the project-scoped
100
+ // half of the surface and have a default project to apply.
101
+ this.documents = new DocumentsApi(this);
102
+ this.vars = new VarsApi(this);
103
+ this.connections = new ConnectionsApi(this);
104
+ this.workflows = new WorkflowsApi(this);
105
+ }
106
+ /**
107
+ * Who this client's credential says you are, plus the versions of the
108
+ * components that answered.
109
+ *
110
+ * A method on the client rather than a namespace, because that is the symbol
111
+ * `endpoints.json` names (`client.me()`). The response body is flat and
112
+ * carries no envelope; the only thing added to it locally is
113
+ * `versions.wrapper`, this package's own version, which is filled in and
114
+ * never overwrites a key the server supplied.
115
+ *
116
+ * @returns The caller's identity.
117
+ * @throws {ConfigError} When no token is configured.
118
+ * @throws {ApiError} On any non-2xx, e.g. a `401` when the token is rejected.
119
+ */
120
+ me() {
121
+ return fetchMe(this);
122
+ }
123
+ /**
124
+ * Run whatever a URN addresses — a connection action, a function, an endpoint
125
+ * or a workflow — and get back the kind-tagged envelope.
126
+ *
127
+ * A method on the client rather than a namespace, because that is the symbol
128
+ * `endpoints.json` names (`client.run(input)`). It is the dispatching
129
+ * counterpart to `workflows.run`, which stays separate because `?wait=`,
130
+ * `variables` and `trigger` have no slot in this three-field shape (D4).
131
+ *
132
+ * Discriminate the result with `isActionRun` / `isFunctionRun` /
133
+ * `isWorkflowRun`; a `kind` this version has never heard of is handed back
134
+ * verbatim rather than raised.
135
+ *
136
+ * `POST /api/run` (verified live 2026-07-28).
137
+ *
138
+ * @param input - The URN, an optional `action`, and the payload.
139
+ * @returns The `RunEnvelope`, exactly as it arrived.
140
+ * @throws {ConfigError} When no token is configured.
141
+ * @throws {ApiError} On any non-2xx, e.g. `404` for an unresolvable URN or
142
+ * `424` when the target app failed during execute.
143
+ */
144
+ run(input) {
145
+ return runUrn(this, input);
146
+ }
147
+ /**
148
+ * Perform one request against this client's server, with this client's
149
+ * credential.
150
+ *
151
+ * This is the seam the operation modules are built on; it is public so a host
152
+ * can also reach an endpoint this version does not model yet, rather than
153
+ * constructing a second client by hand. It returns the status alongside the
154
+ * body — a `202` is success on this API.
155
+ *
156
+ * @param options - The request to make.
157
+ * @returns The status and parsed body.
158
+ * @throws {ConfigError} When no token is configured.
159
+ * @throws {ApiError} On a transport failure, a non-JSON error body, or an error envelope.
160
+ */
161
+ request(options) {
162
+ return request(this.config, this.#fetch, options);
163
+ }
164
+ }
165
+ //# sourceMappingURL=client.js.map
@@ -0,0 +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,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAqB,OAAO,EAAuB,MAAM,WAAW,CAAC;AAC5E,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAiB,MAAM,EAAE,MAAM,UAAU,CAAC;AAEjD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,OAAO,SAAS;IACpB;;;;OAIG;IACM,MAAM,CAAiB;IAEhC;;;;OAIG;IACM,SAAS,CAAe;IAEjC;;;;;OAKG;IACM,IAAI,CAAU;IAEvB;;;;OAIG;IACM,WAAW,CAAiB;IAErC;;;;OAIG;IACM,SAAS,CAAe;IAExB,MAAM,CAAY;IAE3B;;;OAGG;IACH,YAAY,UAA4B,EAAE;QACxC,IAAI,CAAC,MAAM,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;QACrC,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;YAClB,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;QAC9B,CAAC;aAAM,CAAC;YACN,MAAM,MAAM,GAAG,UAAU,CAAC,KAAK,CAAC;YAChC,IAAI,OAAO,MAAM,KAAK,UAAU,EAAE,CAAC;gBACjC,MAAM,IAAI,WAAW,CACnB,2DAA2D;oBACzD,6DAA6D,CAChE,CAAC;YACJ,CAAC;YACD,kEAAkE;YAClE,mEAAmE;YACnE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACxC,CAAC;QAED,wEAAwE;QACxE,iEAAiE;QACjE,2EAA2E;QAC3E,0EAA0E;QAC1E,2DAA2D;QAC3D,IAAI,CAAC,SAAS,GAAG,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC;QACxC,IAAI,CAAC,IAAI,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;QAC9B,IAAI,CAAC,WAAW,GAAG,IAAI,cAAc,CAAC,IAAI,CAAC,CAAC;QAC5C,IAAI,CAAC,SAAS,GAAG,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC;IAC1C,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,EAAE;QACA,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,CAAC;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,GAAG,CAAC,KAAe;QACjB,OAAO,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC7B,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,OAAO,CAAI,OAAuB;QAChC,OAAO,OAAO,CAAI,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACvD,CAAC;CACF"}