@w6w/sdk 0.1.0 → 0.1.1

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/README.md CHANGED
@@ -10,7 +10,7 @@ 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.1.0`.
13
+ - **Version:** `0.1.1`.
14
14
 
15
15
  ## Install
16
16
 
@@ -30,6 +30,82 @@ Both registries publish the **same version at the same time** — `@w6w/sdk`, `@
30
30
  Python `w6w` package share one version number and are released together. A given version means the
31
31
  same set of operations in every language.
32
32
 
33
+ ## Quick start
34
+
35
+ ```ts
36
+ import { W6wClient, isActionRun, isFunctionRun, isWorkflowRun } from "@w6w/sdk";
37
+
38
+ const client = new W6wClient(); // reads W6W_BASE_URL and W6W_TOKEN
39
+
40
+ // Who am I, and what versions am I talking to?
41
+ const me = await client.me();
42
+
43
+ // What can I run? `run` is addressed by a `conn_…` / `fn_…` / `ep_…` / `wf_…`
44
+ // id — these are how you discover one.
45
+ const connections = await client.connections.list();
46
+ const workflows = await client.workflows.list();
47
+ ```
48
+
49
+ ### Run a connection action
50
+
51
+ A `conn_…` id resolves to an app action. `run` returns a `kind`-tagged envelope —
52
+ narrow it with `isActionRun` / `isFunctionRun` / `isWorkflowRun` before reading a field, since the
53
+ three arms use different field names on purpose (`value` vs `output` vs `runId`+`status`):
54
+
55
+ ```ts
56
+ const env = await client.run({
57
+ urn: connections[0].id, // "conn_…"
58
+ action: "send_message", // which of the app's actions to invoke
59
+ payload: { channel: "#general", text: "Hello from @w6w/sdk" },
60
+ });
61
+
62
+ if (isActionRun(env)) console.log(env.value); // the action's return value
63
+ ```
64
+
65
+ ### Run a function or an endpoint
66
+
67
+ `fn_…` and `ep_…` ids run the same way — no `action`, since a function or endpoint has exactly one
68
+ operation:
69
+
70
+ ```ts
71
+ const env = await client.run({ urn: "fn_normalize_address", payload: { address: "1 Infinite Loop" } });
72
+ if (isFunctionRun(env)) console.log(env.output);
73
+ ```
74
+
75
+ ### Run a workflow
76
+
77
+ Two ways to start a `wf_…` run. `client.run()` dispatches it like anything else and always answers
78
+ `202` (queued) — use it when you're treating workflows the same as any other runnable URN:
79
+
80
+ ```ts
81
+ const env = await client.run({ urn: workflows[0].id, payload: { customerId: "cus_1" } });
82
+ if (isWorkflowRun(env)) console.log(env.runId, env.status); // "queued"
83
+ ```
84
+
85
+ `workflows.run` is the typed path, and the only one that can wait for the result server-side:
86
+
87
+ ```ts
88
+ const run = await client.workflows.run(workflows[0].id, {
89
+ wait: true,
90
+ variables: { customerId: "cus_1" },
91
+ });
92
+
93
+ // A failed run is data, not a thrown error — `run.terminal` tells you it's done.
94
+ if (run.terminal && run.status === "failed") console.error(run.error);
95
+ else if (run.terminal) console.log(run.output);
96
+ ```
97
+
98
+ ### Documents and vars
99
+
100
+ ```ts
101
+ const doc = await client.documents.create({ key: "welcome", content: "# Hi" });
102
+ await client.documents.update(doc.id, { content: "# Hello" });
103
+ await client.documents.delete(doc.id);
104
+
105
+ const v = await client.vars.create({ name: "sender_email", type: "string", value: "a@b.c" });
106
+ await client.vars.update(v.id, { value: "c@d.e" });
107
+ ```
108
+
33
109
  ## Configuration
34
110
 
35
111
  Two environment variables, both read only at client construction:
@@ -10,5 +10,5 @@
10
10
  * this file as TypeScript source and rejects inferred public types ("no slow
11
11
  * types").
12
12
  */
13
- export const VERSION = "0.1.0";
13
+ export const VERSION = "0.1.1";
14
14
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@w6w/sdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Typed client for the w6w HTTP API. Thin transport, auth and error mapping — nothing else.",
5
5
  "license": "MIT",
6
6
  "repository": {