@w6w/sdk 0.5.0 → 0.6.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 (44) hide show
  1. package/README.md +20 -17
  2. package/dist/mod.d.ts +4 -0
  3. package/dist/mod.d.ts.map +1 -1
  4. package/dist/mod.js +2 -0
  5. package/dist/mod.js.map +1 -1
  6. package/dist/src/client.d.ts +26 -3
  7. package/dist/src/client.d.ts.map +1 -1
  8. package/dist/src/client.js +28 -3
  9. package/dist/src/client.js.map +1 -1
  10. package/dist/src/config.js +1 -1
  11. package/dist/src/config.js.map +1 -1
  12. package/dist/src/console/aliases.d.ts +137 -0
  13. package/dist/src/console/aliases.d.ts.map +1 -0
  14. package/dist/src/console/aliases.js +113 -0
  15. package/dist/src/console/aliases.js.map +1 -0
  16. package/dist/src/console/auth.d.ts +202 -4
  17. package/dist/src/console/auth.d.ts.map +1 -1
  18. package/dist/src/console/auth.js +154 -4
  19. package/dist/src/console/auth.js.map +1 -1
  20. package/dist/src/console/endpoints.d.ts +23 -5
  21. package/dist/src/console/endpoints.d.ts.map +1 -1
  22. package/dist/src/console/endpoints.js.map +1 -1
  23. package/dist/src/console/mod.d.ts +12 -2
  24. package/dist/src/console/mod.d.ts.map +1 -1
  25. package/dist/src/console/mod.js +10 -0
  26. package/dist/src/console/mod.js.map +1 -1
  27. package/dist/src/console/passkeys.d.ts +246 -0
  28. package/dist/src/console/passkeys.d.ts.map +1 -0
  29. package/dist/src/console/passkeys.js +192 -0
  30. package/dist/src/console/passkeys.js.map +1 -0
  31. package/dist/src/endpoints.d.ts +75 -0
  32. package/dist/src/endpoints.d.ts.map +1 -0
  33. package/dist/src/endpoints.js +47 -0
  34. package/dist/src/endpoints.js.map +1 -0
  35. package/dist/src/functions.d.ts +88 -0
  36. package/dist/src/functions.d.ts.map +1 -0
  37. package/dist/src/functions.js +56 -0
  38. package/dist/src/functions.js.map +1 -0
  39. package/dist/src/run.d.ts +8 -3
  40. package/dist/src/run.d.ts.map +1 -1
  41. package/dist/src/run.js +3 -2
  42. package/dist/src/run.js.map +1 -1
  43. package/dist/src/version.js +1 -1
  44. package/package.json +1 -1
@@ -0,0 +1,88 @@
1
+ /**
2
+ * `client.functions.*` — run a Function by the name you gave it.
3
+ *
4
+ * A Function is a canonical, vendor-stable interface bound to one swappable app
5
+ * Action. Before this namespace existed, calling one meant the URN operation:
6
+ *
7
+ * ```ts
8
+ * await client.run({ urn: "fn_a9b39917-cd4e-4eea-ab89-c3d079684193", payload });
9
+ * ```
10
+ *
11
+ * — an opaque id, buried inside an object, for a Function the user named
12
+ * `send-email`. `client.run` is still the right tool when the caller is
13
+ * *dispatching* something whose kind it does not know; it is the wrong tool for
14
+ * "call my send-email Function", which is what this is:
15
+ *
16
+ * ```ts
17
+ * await client.functions.run("send-email", { payload: { to, subject, html } });
18
+ * ```
19
+ *
20
+ * The name is the FIRST argument, matching `workflows.run(id, opts?)` — the
21
+ * namespace already shaped this way — so all three runnable kinds read alike.
22
+ *
23
+ * ID OR KEY, one argument. The server's `/functions/{idOrKey}/invoke` accepts
24
+ * either, because the two shapes cannot collide: an id carries a kind prefix and
25
+ * therefore an underscore, and a key is kebab-case, which forbids one. So this
26
+ * takes no flag and no prefix to say which you meant — pass whichever you have.
27
+ */
28
+ import type { ResolvedConfig } from "./config.ts";
29
+ import { type HttpResponse, type RequestOptions } from "./http.ts";
30
+ /**
31
+ * What this namespace needs from the client — the same narrow seam
32
+ * `WorkflowsApi` takes, so it is constructible in a test and this module never
33
+ * imports the client back.
34
+ */
35
+ export interface FunctionsHost {
36
+ /** The resolved configuration. */
37
+ readonly config: ResolvedConfig;
38
+ /** Perform one request. */
39
+ request<T>(options: RequestOptions): Promise<HttpResponse<T>>;
40
+ }
41
+ /** Per-call options for `functions.run`. */
42
+ export interface FunctionRunOptions {
43
+ /**
44
+ * The Function's canonical inputs, by input key.
45
+ *
46
+ * Named `payload` rather than `inputs` so every runnable kind in this SDK
47
+ * takes the same word — the wire spells it `inputs` for a Function and
48
+ * `input` for an Endpoint, and reconciling that is exactly the job of a
49
+ * wrapper. Defaults to `{}` rather than being omitted: the server's parameter
50
+ * schemas are written against an object, and `{}` says "no input" where an
51
+ * absent key says "I forgot".
52
+ */
53
+ payload?: Record<string, unknown>;
54
+ }
55
+ /**
56
+ * The `functions` namespace on a `W6WClient`.
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * const output = await client.functions.run("send-email", {
61
+ * payload: { to: "ada@example.com", subject: "Hi", html: "<p>Hello</p>" },
62
+ * });
63
+ * ```
64
+ */
65
+ export declare class FunctionsApi {
66
+ #private;
67
+ /**
68
+ * @param host - The client this namespace issues requests through.
69
+ */
70
+ constructor(host: FunctionsHost);
71
+ /**
72
+ * Run one Function and return its output.
73
+ *
74
+ * Returns the Function's OUTPUT, not an envelope. `client.run` returns a
75
+ * `kind`-discriminated envelope because the caller does not know what the URN
76
+ * will resolve to; here the kind is in the method name, so the discriminant
77
+ * would be a field the caller has to unwrap to learn nothing.
78
+ *
79
+ * @param name - The Function's key (`"send-email"`) or its `fn_…` id. Percent-encoded into the path.
80
+ * @param options - `payload`, the Function's canonical inputs.
81
+ * @returns The Function's output, unwrapped from the `output` envelope.
82
+ * @throws {ApiError} `404 unknown_function` when no Function of that name exists for the caller.
83
+ * @throws {ApiError} `422 function_incomplete` when the Function has no runnable `impl`.
84
+ * @throws {ApiError} `bad_response` when a success body carries no `output` key at all.
85
+ */
86
+ run(name: string, options?: FunctionRunOptions): Promise<unknown>;
87
+ }
88
+ //# sourceMappingURL=functions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"functions.d.ts","sourceRoot":"","sources":["../../src/functions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,OAAO,EAAE,KAAK,YAAY,EAAQ,KAAK,cAAc,EAAE,MAAM,WAAW,CAAC;AAEzE;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,kCAAkC;IAClC,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;IAChC,2BAA2B;IAC3B,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;CAC/D;AAED,4CAA4C;AAC5C,MAAM,WAAW,kBAAkB;IACjC;;;;;;;;;OASG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED;;;;;;;;;GASG;AACH,qBAAa,YAAY;;IAGvB;;OAEG;gBACS,IAAI,EAAE,aAAa;IAI/B;;;;;;;;;;;;;;OAcG;IACG,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,OAAO,CAAC;CAyBxE"}
@@ -0,0 +1,56 @@
1
+ import { ApiError } from "./errors.js";
2
+ import { path } from "./http.js";
3
+ /**
4
+ * The `functions` namespace on a `W6WClient`.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * const output = await client.functions.run("send-email", {
9
+ * payload: { to: "ada@example.com", subject: "Hi", html: "<p>Hello</p>" },
10
+ * });
11
+ * ```
12
+ */
13
+ export class FunctionsApi {
14
+ #host;
15
+ /**
16
+ * @param host - The client this namespace issues requests through.
17
+ */
18
+ constructor(host) {
19
+ this.#host = host;
20
+ }
21
+ /**
22
+ * Run one Function and return its output.
23
+ *
24
+ * Returns the Function's OUTPUT, not an envelope. `client.run` returns a
25
+ * `kind`-discriminated envelope because the caller does not know what the URN
26
+ * will resolve to; here the kind is in the method name, so the discriminant
27
+ * would be a field the caller has to unwrap to learn nothing.
28
+ *
29
+ * @param name - The Function's key (`"send-email"`) or its `fn_…` id. Percent-encoded into the path.
30
+ * @param options - `payload`, the Function's canonical inputs.
31
+ * @returns The Function's output, unwrapped from the `output` envelope.
32
+ * @throws {ApiError} `404 unknown_function` when no Function of that name exists for the caller.
33
+ * @throws {ApiError} `422 function_incomplete` when the Function has no runnable `impl`.
34
+ * @throws {ApiError} `bad_response` when a success body carries no `output` key at all.
35
+ */
36
+ async run(name, options) {
37
+ const res = await this.#host.request({
38
+ method: "POST",
39
+ path: path `/functions/${name}/invoke`,
40
+ body: { inputs: options?.payload ?? {} },
41
+ });
42
+ // Deliberately NOT `unwrap(res, "output")`. That helper treats `null` as
43
+ // "the server did not send what it promised" — correct for a `documents` or
44
+ // `vars` envelope, where null is never a document. It is wrong here: a
45
+ // Function's output is an OPAQUE pass-through, and an action that returns
46
+ // nothing yields `{"output": null}`, which is a successful run and not a
47
+ // malformed response. So the guard is PRESENCE of the key, not truthiness
48
+ // of the value.
49
+ const body = res.body;
50
+ if (typeof body !== "object" || body === null || !("output" in body)) {
51
+ throw new ApiError(res.status, "bad_response", `Server returned a ${res.status} with no "output" in the response body.`, body);
52
+ }
53
+ return body.output;
54
+ }
55
+ }
56
+ //# sourceMappingURL=functions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"functions.js","sourceRoot":"","sources":["../../src/functions.ts"],"names":[],"mappings":"AA4BA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAqB,IAAI,EAAuB,MAAM,WAAW,CAAC;AA6BzE;;;;;;;;;GASG;AACH,MAAM,OAAO,YAAY;IACd,KAAK,CAAgB;IAE9B;;OAEG;IACH,YAAY,IAAmB;QAC7B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;IAED;;;;;;;;;;;;;;OAcG;IACH,KAAK,CAAC,GAAG,CAAC,IAAY,EAAE,OAA4B;QAClD,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAU;YAC5C,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,IAAI,CAAA,cAAc,IAAI,SAAS;YACrC,IAAI,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,IAAI,EAAE,EAAE;SACzC,CAAC,CAAC;QAEH,yEAAyE;QACzE,4EAA4E;QAC5E,uEAAuE;QACvE,0EAA0E;QAC1E,yEAAyE;QACzE,0EAA0E;QAC1E,gBAAgB;QAChB,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;QACtB,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,IAAI,CAAC,CAAC,QAAQ,IAAI,IAAI,CAAC,EAAE,CAAC;YACrE,MAAM,IAAI,QAAQ,CAChB,GAAG,CAAC,MAAM,EACV,cAAc,EACd,qBAAqB,GAAG,CAAC,MAAM,yCAAyC,EACxE,IAAI,CACL,CAAC;QACJ,CAAC;QACD,OAAQ,IAA4B,CAAC,MAAM,CAAC;IAC9C,CAAC;CACF"}
package/dist/src/run.d.ts CHANGED
@@ -2,8 +2,9 @@
2
2
  * `client.run({urn, action, payload})` — run anything a URN addresses.
3
3
  *
4
4
  * One POST, one kind-tagged body, no envelope key. The URN resolves over the
5
- * four runnable arms — `conn_…`, `wf_…`, `fn_…`, `ep_…` (D16) — and the answer
6
- * says which one it hit:
5
+ * `conn_…`, `wf_…`, `fn_…` and `ep_…` arms (D16), and, additionally, an
6
+ * account-scoped alias name (kebab-slug, `_`-free, which is why no flag is
7
+ * needed to disambiguate the two) — and the answer says which one it hit:
7
8
  *
8
9
  * | `kind` | Field | HTTP |
9
10
  * |---|---|---|
@@ -63,7 +64,11 @@ export interface RunHost {
63
64
  * uses it for its `wf_…` id.)
64
65
  */
65
66
  export interface RunInput {
66
- /** What to run: `conn_…`, `wf_…`, `fn_…` or `ep_…`. */
67
+ /**
68
+ * What to run: `conn_…`, `wf_…`, `fn_…`, `ep_…`, or, additionally, an
69
+ * account-scoped alias name (kebab-slug, `_`-free, which is why no flag is
70
+ * needed to disambiguate the two).
71
+ */
67
72
  urn: string;
68
73
  /**
69
74
  * Which action to invoke. Optional, because a workflow, function or endpoint
@@ -1 +1 @@
1
- {"version":3,"file":"run.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G;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,+DAA+D;IAC/D,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,MAAM,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC,CA8BjF"}
package/dist/src/run.js CHANGED
@@ -2,8 +2,9 @@
2
2
  * `client.run({urn, action, payload})` — run anything a URN addresses.
3
3
  *
4
4
  * One POST, one kind-tagged body, no envelope key. The URN resolves over the
5
- * four runnable arms — `conn_…`, `wf_…`, `fn_…`, `ep_…` (D16) — and the answer
6
- * says which one it hit:
5
+ * `conn_…`, `wf_…`, `fn_…` and `ep_…` arms (D16), and, additionally, an
6
+ * account-scoped alias name (kebab-slug, `_`-free, which is why no flag is
7
+ * needed to disambiguate the two) — and the answer says which one it hit:
7
8
  *
8
9
  * | `kind` | Field | HTTP |
9
10
  * |---|---|---|
@@ -1 +1 @@
1
- {"version":3,"file":"run.js","sourceRoot":"","sources":["../../src/run.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAoCvC;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,IAAa,EAAE,KAAe;IACzD,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,OAAO,CAAU;QACtC,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,MAAM;QACZ,IAAI,EAAE;YACJ,GAAG,EAAE,KAAK,CAAC,GAAG;YACd,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,oEAAoE;YACpE,0EAA0E;YAC1E,mBAAmB;YACnB,OAAO,EAAE,KAAK,CAAC,OAAO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AG,CAAC,MAAM,uCAAuC,EACtE,IAAI,CACL,CAAC;IACJ,CAAC;IACD,qEAAqE;IACrE,yEAAyE;IACzE,wBAAwB;IACxB,OAAO,IAAmB,CAAC;AAC7B,CAAC"}
@@ -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.5.0";
13
+ export const VERSION = "0.6.0";
14
14
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@w6w/sdk",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
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": {