@w6w/sdk 0.5.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 (132) hide show
  1. package/README.md +185 -32
  2. package/dist/mod.d.ts +10 -4
  3. package/dist/mod.d.ts.map +1 -1
  4. package/dist/mod.js +3 -0
  5. package/dist/mod.js.map +1 -1
  6. package/dist/src/client.d.ts +37 -5
  7. package/dist/src/client.d.ts.map +1 -1
  8. package/dist/src/client.js +40 -5
  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 +41 -5
  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/aliases.d.ts +137 -0
  19. package/dist/src/console/aliases.d.ts.map +1 -0
  20. package/dist/src/console/aliases.js +113 -0
  21. package/dist/src/console/aliases.js.map +1 -0
  22. package/dist/src/console/api-calls.d.ts +4 -3
  23. package/dist/src/console/api-calls.d.ts.map +1 -1
  24. package/dist/src/console/api-calls.js +4 -3
  25. package/dist/src/console/api-calls.js.map +1 -1
  26. package/dist/src/console/apps.d.ts +181 -8
  27. package/dist/src/console/apps.d.ts.map +1 -1
  28. package/dist/src/console/apps.js +67 -12
  29. package/dist/src/console/apps.js.map +1 -1
  30. package/dist/src/console/auth.d.ts +245 -7
  31. package/dist/src/console/auth.d.ts.map +1 -1
  32. package/dist/src/console/auth.js +177 -8
  33. package/dist/src/console/auth.js.map +1 -1
  34. package/dist/src/console/commerce.d.ts +428 -0
  35. package/dist/src/console/commerce.d.ts.map +1 -0
  36. package/dist/src/console/commerce.js +220 -0
  37. package/dist/src/console/commerce.js.map +1 -0
  38. package/dist/src/console/dashboard.d.ts +8 -0
  39. package/dist/src/console/dashboard.d.ts.map +1 -1
  40. package/dist/src/console/dashboard.js.map +1 -1
  41. package/dist/src/console/endpoints.d.ts +79 -6
  42. package/dist/src/console/endpoints.d.ts.map +1 -1
  43. package/dist/src/console/endpoints.js.map +1 -1
  44. package/dist/src/console/functions.d.ts +35 -4
  45. package/dist/src/console/functions.d.ts.map +1 -1
  46. package/dist/src/console/functions.js +13 -0
  47. package/dist/src/console/functions.js.map +1 -1
  48. package/dist/src/console/mod.d.ts +32 -7
  49. package/dist/src/console/mod.d.ts.map +1 -1
  50. package/dist/src/console/mod.js +26 -1
  51. package/dist/src/console/mod.js.map +1 -1
  52. package/dist/src/console/otp.d.ts +127 -0
  53. package/dist/src/console/otp.d.ts.map +1 -0
  54. package/dist/src/console/otp.js +118 -0
  55. package/dist/src/console/otp.js.map +1 -0
  56. package/dist/src/console/passkeys.d.ts +246 -0
  57. package/dist/src/console/passkeys.d.ts.map +1 -0
  58. package/dist/src/console/passkeys.js +192 -0
  59. package/dist/src/console/passkeys.js.map +1 -0
  60. package/dist/src/console/reliability.d.ts +101 -6
  61. package/dist/src/console/reliability.d.ts.map +1 -1
  62. package/dist/src/console/reliability.js +16 -5
  63. package/dist/src/console/reliability.js.map +1 -1
  64. package/dist/src/console/step-tests.d.ts +7 -1
  65. package/dist/src/console/step-tests.d.ts.map +1 -1
  66. package/dist/src/console/step-tests.js +1 -1
  67. package/dist/src/console/step-tests.js.map +1 -1
  68. package/dist/src/console/subscriptions.d.ts +38 -16
  69. package/dist/src/console/subscriptions.d.ts.map +1 -1
  70. package/dist/src/console/subscriptions.js +7 -13
  71. package/dist/src/console/subscriptions.js.map +1 -1
  72. package/dist/src/console/tenant-login-flags.d.ts +106 -0
  73. package/dist/src/console/tenant-login-flags.d.ts.map +1 -0
  74. package/dist/src/console/tenant-login-flags.js +113 -0
  75. package/dist/src/console/tenant-login-flags.js.map +1 -0
  76. package/dist/src/console/tenant-oauth-apps.d.ts +75 -14
  77. package/dist/src/console/tenant-oauth-apps.d.ts.map +1 -1
  78. package/dist/src/console/tenant-oauth-apps.js +37 -11
  79. package/dist/src/console/tenant-oauth-apps.js.map +1 -1
  80. package/dist/src/console/tokens.d.ts +2 -0
  81. package/dist/src/console/tokens.d.ts.map +1 -1
  82. package/dist/src/console/tokens.js.map +1 -1
  83. package/dist/src/console/workflows.d.ts +14 -0
  84. package/dist/src/console/workflows.d.ts.map +1 -1
  85. package/dist/src/console/workflows.js +13 -0
  86. package/dist/src/console/workflows.js.map +1 -1
  87. package/dist/src/documents.d.ts +9 -5
  88. package/dist/src/documents.d.ts.map +1 -1
  89. package/dist/src/documents.js +6 -3
  90. package/dist/src/documents.js.map +1 -1
  91. package/dist/src/endpoints.d.ts +75 -0
  92. package/dist/src/endpoints.d.ts.map +1 -0
  93. package/dist/src/endpoints.js +47 -0
  94. package/dist/src/endpoints.js.map +1 -0
  95. package/dist/src/functions.d.ts +236 -0
  96. package/dist/src/functions.d.ts.map +1 -0
  97. package/dist/src/functions.js +201 -0
  98. package/dist/src/functions.js.map +1 -0
  99. package/dist/src/http.d.ts +58 -10
  100. package/dist/src/http.d.ts.map +1 -1
  101. package/dist/src/http.js +82 -11
  102. package/dist/src/http.js.map +1 -1
  103. package/dist/src/me.d.ts +3 -2
  104. package/dist/src/me.d.ts.map +1 -1
  105. package/dist/src/me.js +7 -2
  106. package/dist/src/me.js.map +1 -1
  107. package/dist/src/run.d.ts +19 -5
  108. package/dist/src/run.d.ts.map +1 -1
  109. package/dist/src/run.js +14 -4
  110. package/dist/src/run.js.map +1 -1
  111. package/dist/src/server/mod.d.ts +100 -0
  112. package/dist/src/server/mod.d.ts.map +1 -0
  113. package/dist/src/server/mod.js +121 -0
  114. package/dist/src/server/mod.js.map +1 -0
  115. package/dist/src/team.d.ts +204 -0
  116. package/dist/src/team.d.ts.map +1 -0
  117. package/dist/src/team.js +161 -0
  118. package/dist/src/team.js.map +1 -0
  119. package/dist/src/types.d.ts +143 -10
  120. package/dist/src/types.d.ts.map +1 -1
  121. package/dist/src/types.js +27 -0
  122. package/dist/src/types.js.map +1 -1
  123. package/dist/src/vars.d.ts +5 -3
  124. package/dist/src/vars.d.ts.map +1 -1
  125. package/dist/src/vars.js +14 -4
  126. package/dist/src/vars.js.map +1 -1
  127. package/dist/src/version.js +1 -1
  128. package/dist/src/workflows.d.ts +261 -9
  129. package/dist/src/workflows.d.ts.map +1 -1
  130. package/dist/src/workflows.js +246 -7
  131. package/dist/src/workflows.js.map +1 -1
  132. package/package.json +5 -1
@@ -0,0 +1,127 @@
1
+ /**
2
+ * `client.console.otp.*` — email one-time-code sign-in, a third standalone
3
+ * login option beside password and passkey (T2.1.3).
4
+ *
5
+ * **Studio-internal, not the published partner contract.** This namespace
6
+ * lives under the `console` subpath export (`@w6w/sdk/console`), excluded from
7
+ * `endpoints.json` and from the root barrel (`mod.ts`) — see `docs/console.md`.
8
+ * `@w6w/sdk`'s instance-state mechanism pin still applies here exactly as it
9
+ * does to every other namespace (`docs/implementation.md` §MECHANISM PIN —
10
+ * instance state, never globals): this class holds no state of its own beyond
11
+ * the injected host, so two clients in one process never share a credential.
12
+ *
13
+ * **All three methods are PUBLIC — the login screen has no token.** Mirrors
14
+ * `console.passkeys`'s login pair exactly: each passes `requireAuth: false`,
15
+ * without which a tokenless client (the normal case at `/login`, before any
16
+ * session exists) would hit `requireToken`'s `ConfigError` before `fetch` is
17
+ * ever called. Wire pins are T2.1.1's contract §Wire pins, above its
18
+ * `requireTenantAdmin`-guarded `/tenant/login-flags` pair (see
19
+ * `./tenant-login-flags.ts`).
20
+ *
21
+ * **`OtpVerifyResponse` is a type ALIAS of `PasskeyAuthenticationVerifyResponse`,
22
+ * not a second declaration of the same four fields.** The server's
23
+ * `POST /auth/otp/verify` answers a byte-identical body to
24
+ * `id/passkey-login.ts`'s own verify route (T2.1.1's wire pin: "byte-shape
25
+ * identical to `id/user-login.ts`'s and `id/passkey-login.ts`'s"), and the
26
+ * passkey names (`PasskeyUser`, `PasskeyAuthenticationVerifyResponse`) are
27
+ * published and cannot be renamed — a third copy of the same shape would be a
28
+ * third thing to drift out of sync with the other two.
29
+ *
30
+ * @module
31
+ */
32
+ import { type HttpResponse, type RequestOptions } from "../http.ts";
33
+ import type { PasskeyAuthenticationVerifyResponse } from "./passkeys.ts";
34
+ /**
35
+ * The slice of `W6WClient` this namespace needs: the transport, and nothing
36
+ * else. Structural rather than a concrete client type, so the namespace stays
37
+ * independently constructible in a test and this module never imports the
38
+ * client back — mirrors `PasskeysHost` in `./passkeys.ts`.
39
+ */
40
+ export interface OtpHost {
41
+ /** Perform one request. */
42
+ request<T>(options: RequestOptions): Promise<HttpResponse<T>>;
43
+ }
44
+ /**
45
+ * Which sign-in methods this tenant currently offers — `GET
46
+ * /auth/login-providers` (T2.1.1's wire pin). Read by `/login` to decide what
47
+ * to render; see `packages/studio/src/lib/login-providers.ts`'s
48
+ * `providerVisibility`, the one place that decision is made.
49
+ */
50
+ export interface LoginProviders {
51
+ password: boolean;
52
+ passkey: boolean;
53
+ otp: boolean;
54
+ }
55
+ /**
56
+ * The user identity `verifyCode` mints a session for — the SAME shape
57
+ * `PasskeyAuthenticationVerifyResponse` already declares (see this module's
58
+ * header). A type alias, not a reuse of `console.auth`'s `LoginResponse`:
59
+ * that type's `user` does not carry `role`/`tenant`/`emailVerified`.
60
+ */
61
+ export type OtpVerifyResponse = PasskeyAuthenticationVerifyResponse;
62
+ /**
63
+ * The `console.otp` namespace on a `W6WClient`.
64
+ *
65
+ * @example
66
+ * ```ts
67
+ * const client = new W6WClient({ baseUrl: "https://api.example.com" }); // no token — see below
68
+ * const { providers } = { providers: await client.console.otp.loginProviders() };
69
+ * if (providers.otp) {
70
+ * await client.console.otp.requestCode({ email: "alice@example.com" });
71
+ * const { token } = await client.console.otp.verifyCode({
72
+ * email: "alice@example.com",
73
+ * code: "123456",
74
+ * });
75
+ * }
76
+ * ```
77
+ */
78
+ export declare class OtpApi {
79
+ #private;
80
+ /**
81
+ * @param host - The client this namespace issues requests through.
82
+ */
83
+ constructor(host: OtpHost);
84
+ /**
85
+ * Which sign-in methods this tenant currently offers.
86
+ *
87
+ * PUBLIC — sends no bearer, even on a client that already holds one
88
+ * (`requireAuth: false`). The `/login` screen calls this before any session
89
+ * exists, so a tokenless client must be able to reach it.
90
+ *
91
+ * @returns `{ password, passkey, otp }`, unwrapped from the `providers` envelope.
92
+ */
93
+ loginProviders(): Promise<LoginProviders>;
94
+ /**
95
+ * Request a one-time sign-in code by email.
96
+ *
97
+ * PUBLIC — sends no bearer (`requireAuth: false`). Answers `202 {ok: true}`
98
+ * ALWAYS, whether or not a user exists with that email (T2.1.1's wire pin)
99
+ * — this method discards that body and resolves `void`, since there is
100
+ * nothing informative in it for the caller to act on.
101
+ *
102
+ * @param input - The email to send the code to.
103
+ * @throws {ApiError} `403 otp_disabled` when the tenant's `otp_enabled` is
104
+ * false; `400 invalid_body` for a non-object/non-string body.
105
+ */
106
+ requestCode(input: {
107
+ email: string;
108
+ }): Promise<void>;
109
+ /**
110
+ * Verify a one-time code and mint a session — a standalone alternative to
111
+ * a password, not a second factor, exactly like `console.passkeys`'s
112
+ * `authenticationVerify` (HITL-5 there).
113
+ *
114
+ * PUBLIC — sends no bearer (`requireAuth: false`).
115
+ *
116
+ * @param input - The email the code was requested for, and the code itself.
117
+ * @returns The token, the caller's identity, and the token's lifetime.
118
+ * @throws {ApiError} `401 otp_rejected` for every failure mode (T2.1.1's
119
+ * wire pin) — an unknown email, an expired code, a wrong code and a
120
+ * spent code are all indistinguishable to the caller.
121
+ */
122
+ verifyCode(input: {
123
+ email: string;
124
+ code: string;
125
+ }): Promise<OtpVerifyResponse>;
126
+ }
127
+ //# sourceMappingURL=otp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"otp.d.ts","sourceRoot":"","sources":["../../../src/console/otp.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,cAAc,EAAE,MAAM,YAAY,CAAC;AAEpE,OAAO,KAAK,EAAE,mCAAmC,EAAE,MAAM,eAAe,CAAC;AAEzE;;;;;GAKG;AACH,MAAM,WAAW,OAAO;IACtB,2BAA2B;IAC3B,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;CAC/D;AAED;;;;;GAKG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,GAAG,EAAE,OAAO,CAAC;CACd;AAED;;;;;GAKG;AACH,MAAM,MAAM,iBAAiB,GAAG,mCAAmC,CAAC;AAEpE;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,MAAM;;IAGjB;;OAEG;gBACS,IAAI,EAAE,OAAO;IAIzB;;;;;;;;OAQG;IACG,cAAc,IAAI,OAAO,CAAC,cAAc,CAAC;IAS/C;;;;;;;;;;;OAWG;IACG,WAAW,CAAC,KAAK,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAS1D;;;;;;;;;;;;OAYG;IACG,UAAU,CAAC,KAAK,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,iBAAiB,CAAC;CASrF"}
@@ -0,0 +1,118 @@
1
+ /**
2
+ * `client.console.otp.*` — email one-time-code sign-in, a third standalone
3
+ * login option beside password and passkey (T2.1.3).
4
+ *
5
+ * **Studio-internal, not the published partner contract.** This namespace
6
+ * lives under the `console` subpath export (`@w6w/sdk/console`), excluded from
7
+ * `endpoints.json` and from the root barrel (`mod.ts`) — see `docs/console.md`.
8
+ * `@w6w/sdk`'s instance-state mechanism pin still applies here exactly as it
9
+ * does to every other namespace (`docs/implementation.md` §MECHANISM PIN —
10
+ * instance state, never globals): this class holds no state of its own beyond
11
+ * the injected host, so two clients in one process never share a credential.
12
+ *
13
+ * **All three methods are PUBLIC — the login screen has no token.** Mirrors
14
+ * `console.passkeys`'s login pair exactly: each passes `requireAuth: false`,
15
+ * without which a tokenless client (the normal case at `/login`, before any
16
+ * session exists) would hit `requireToken`'s `ConfigError` before `fetch` is
17
+ * ever called. Wire pins are T2.1.1's contract §Wire pins, above its
18
+ * `requireTenantAdmin`-guarded `/tenant/login-flags` pair (see
19
+ * `./tenant-login-flags.ts`).
20
+ *
21
+ * **`OtpVerifyResponse` is a type ALIAS of `PasskeyAuthenticationVerifyResponse`,
22
+ * not a second declaration of the same four fields.** The server's
23
+ * `POST /auth/otp/verify` answers a byte-identical body to
24
+ * `id/passkey-login.ts`'s own verify route (T2.1.1's wire pin: "byte-shape
25
+ * identical to `id/user-login.ts`'s and `id/passkey-login.ts`'s"), and the
26
+ * passkey names (`PasskeyUser`, `PasskeyAuthenticationVerifyResponse`) are
27
+ * published and cannot be renamed — a third copy of the same shape would be a
28
+ * third thing to drift out of sync with the other two.
29
+ *
30
+ * @module
31
+ */
32
+ import {} from "../http.js";
33
+ import { unwrap } from "../types.js";
34
+ /**
35
+ * The `console.otp` namespace on a `W6WClient`.
36
+ *
37
+ * @example
38
+ * ```ts
39
+ * const client = new W6WClient({ baseUrl: "https://api.example.com" }); // no token — see below
40
+ * const { providers } = { providers: await client.console.otp.loginProviders() };
41
+ * if (providers.otp) {
42
+ * await client.console.otp.requestCode({ email: "alice@example.com" });
43
+ * const { token } = await client.console.otp.verifyCode({
44
+ * email: "alice@example.com",
45
+ * code: "123456",
46
+ * });
47
+ * }
48
+ * ```
49
+ */
50
+ export class OtpApi {
51
+ #host;
52
+ /**
53
+ * @param host - The client this namespace issues requests through.
54
+ */
55
+ constructor(host) {
56
+ this.#host = host;
57
+ }
58
+ /**
59
+ * Which sign-in methods this tenant currently offers.
60
+ *
61
+ * PUBLIC — sends no bearer, even on a client that already holds one
62
+ * (`requireAuth: false`). The `/login` screen calls this before any session
63
+ * exists, so a tokenless client must be able to reach it.
64
+ *
65
+ * @returns `{ password, passkey, otp }`, unwrapped from the `providers` envelope.
66
+ */
67
+ async loginProviders() {
68
+ const res = await this.#host.request({
69
+ method: "GET",
70
+ path: "/auth/login-providers",
71
+ requireAuth: false,
72
+ });
73
+ return unwrap(res, "providers");
74
+ }
75
+ /**
76
+ * Request a one-time sign-in code by email.
77
+ *
78
+ * PUBLIC — sends no bearer (`requireAuth: false`). Answers `202 {ok: true}`
79
+ * ALWAYS, whether or not a user exists with that email (T2.1.1's wire pin)
80
+ * — this method discards that body and resolves `void`, since there is
81
+ * nothing informative in it for the caller to act on.
82
+ *
83
+ * @param input - The email to send the code to.
84
+ * @throws {ApiError} `403 otp_disabled` when the tenant's `otp_enabled` is
85
+ * false; `400 invalid_body` for a non-object/non-string body.
86
+ */
87
+ async requestCode(input) {
88
+ await this.#host.request({
89
+ method: "POST",
90
+ path: "/auth/otp/request",
91
+ body: input,
92
+ requireAuth: false,
93
+ });
94
+ }
95
+ /**
96
+ * Verify a one-time code and mint a session — a standalone alternative to
97
+ * a password, not a second factor, exactly like `console.passkeys`'s
98
+ * `authenticationVerify` (HITL-5 there).
99
+ *
100
+ * PUBLIC — sends no bearer (`requireAuth: false`).
101
+ *
102
+ * @param input - The email the code was requested for, and the code itself.
103
+ * @returns The token, the caller's identity, and the token's lifetime.
104
+ * @throws {ApiError} `401 otp_rejected` for every failure mode (T2.1.1's
105
+ * wire pin) — an unknown email, an expired code, a wrong code and a
106
+ * spent code are all indistinguishable to the caller.
107
+ */
108
+ async verifyCode(input) {
109
+ const res = await this.#host.request({
110
+ method: "POST",
111
+ path: "/auth/otp/verify",
112
+ body: input,
113
+ requireAuth: false,
114
+ });
115
+ return res.body;
116
+ }
117
+ }
118
+ //# sourceMappingURL=otp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"otp.js","sourceRoot":"","sources":["../../../src/console/otp.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,EAA0C,MAAM,YAAY,CAAC;AACpE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAkCrC;;;;;;;;;;;;;;;GAeG;AACH,MAAM,OAAO,MAAM;IACR,KAAK,CAAU;IAExB;;OAEG;IACH,YAAY,IAAa;QACvB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,cAAc;QAClB,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAU;YAC5C,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,uBAAuB;YAC7B,WAAW,EAAE,KAAK;SACnB,CAAC,CAAC;QACH,OAAO,MAAM,CAAiB,GAAG,EAAE,WAAW,CAAC,CAAC;IAClD,CAAC;IAED;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,WAAW,CAAC,KAAwB;QACxC,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAU;YAChC,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,mBAAmB;YACzB,IAAI,EAAE,KAAK;YACX,WAAW,EAAE,KAAK;SACnB,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,KAAK,CAAC,UAAU,CAAC,KAAsC;QACrD,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAoB;YACtD,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,kBAAkB;YACxB,IAAI,EAAE,KAAK;YACX,WAAW,EAAE,KAAK;SACnB,CAAC,CAAC;QACH,OAAO,GAAG,CAAC,IAAI,CAAC;IAClB,CAAC;CACF"}
@@ -0,0 +1,246 @@
1
+ /**
2
+ * `client.console.passkeys.*` — WebAuthn passkey management and login for
3
+ * self-serve Studio users (T1.1.5).
4
+ *
5
+ * **Studio-internal, not the published partner contract.** This namespace
6
+ * lives under the `console` subpath export (`@w6w/sdk/console`), excluded from
7
+ * `endpoints.json` and from the root barrel (`mod.ts`) — see `docs/console.md`
8
+ * and HITL-1 in this task's contract. `@w6w/sdk`'s instance-state mechanism
9
+ * pin still applies here exactly as it does to every other namespace
10
+ * (`docs/implementation.md` §MECHANISM PIN — instance state, never globals):
11
+ * this class holds no state of its own beyond the injected host, so two
12
+ * clients in one process never share a credential.
13
+ *
14
+ * **Who this is for (HITL-3).** Passkeys belong to self-serve Studio users
15
+ * only; a partner-tenant user's IdP owns its identity. No eligibility logic
16
+ * lives here — the server enforces it (`PasskeyNotEligibleError`), and this
17
+ * module is a plain transport shim over whatever it decides.
18
+ *
19
+ * **Two routes, four methods, split by who is authenticated.** The management
20
+ * quartet (`registrationOptions`, `registrationVerify`, `list`, `revoke`) is
21
+ * GUARDED, mirroring `packages/server/packages/api/data/passkeys.ts`'s own
22
+ * doc comment ("Registered BELOW the auth guard"). The login pair
23
+ * (`authenticationOptions`, `authenticationVerify`) is PUBLIC, mirroring
24
+ * `packages/server/packages/api/id/passkey-login.ts`'s own doc comment ("BOTH
25
+ * routes are PUBLIC and UNAUTHENTICATED by construction") — discoverable
26
+ * credentials, no identifier in the request body (P1). Each of those two
27
+ * methods passes `requireAuth: false`, the same mechanism
28
+ * `console.auth.login`/`signup`/`checkAccountSlug` rely on: without it a
29
+ * tokenless client (the normal case at the login screen, before any session
30
+ * exists) would hit `requireToken`'s `ConfigError` before `fetch` is ever
31
+ * called.
32
+ *
33
+ * **`authenticationVerify` mints a session, the same way `login` does
34
+ * (HITL-5).** A verified passkey assertion is a standalone alternative to a
35
+ * password, not a second factor — so its response is token-bearing, exactly
36
+ * like `console.auth.login`'s. It is a SEPARATE type from `LoginResponse`
37
+ * (`./auth.ts`), not a reuse: the server route is byte-shape-identical to
38
+ * `user-login.ts`'s login body (`id/passkey-login.ts`'s own doc comment) which
39
+ * carries `role`, `tenant` and `emailVerified` on `user` — fields
40
+ * `console.auth`'s `LoginResponse.user` does not declare.
41
+ *
42
+ * **WebAuthn ceremony payloads (`options`/`response`) are opaque JSON, typed
43
+ * as `Record<string, unknown>`, never as `@simplewebauthn/*` types.** This
44
+ * package has no dependency on `@simplewebauthn` (browser or server) and
45
+ * adding one only to type two pass-through fields would be a new dependency
46
+ * for zero behavioural gain — `inputs.touch` for this task explicitly
47
+ * excludes `package.json`. A caller passes the browser's own
48
+ * `PublicKeyCredentialCreationOptionsJSON`/`...RequestOptionsJSON` (from
49
+ * `options`) into `navigator.credentials.create()`/`.get()` (or a helper such
50
+ * as `@simplewebauthn/browser`'s `startRegistration`/`startAuthentication`)
51
+ * and forwards what comes back as `response` — this module never inspects
52
+ * either shape, only relays it.
53
+ *
54
+ * @module
55
+ */
56
+ import { type HttpResponse, type RequestOptions } from "../http.ts";
57
+ /**
58
+ * The slice of `W6WClient` this namespace needs: the transport, and nothing
59
+ * else. Structural rather than a concrete client type, so the namespace stays
60
+ * independently constructible in a test and this module never imports the
61
+ * client back — mirrors `TokensHost` in `./tokens.ts`.
62
+ */
63
+ export interface PasskeysHost {
64
+ /** Perform one request. */
65
+ request<T>(options: RequestOptions): Promise<HttpResponse<T>>;
66
+ }
67
+ /**
68
+ * A stored passkey, as the server exposes it. **Never the public key or the
69
+ * counter** — `packages/server/packages/api/data/passkeys.ts`'s own
70
+ * `WirePasskey`/`toWirePasskey()` state the identical invariant server-side.
71
+ */
72
+ export interface Passkey {
73
+ /** Server-issued id. */
74
+ id: string;
75
+ /** Caller-chosen label (empty string when none was given at registration). */
76
+ label: string;
77
+ /** ISO-8601 timestamp. */
78
+ createdAt: string;
79
+ /** ISO-8601 timestamp of the credential's last successful authentication, or `null`. */
80
+ lastUsedAt: string | null;
81
+ /** WebAuthn transport hints reported at registration (e.g. `"internal"`, `"hybrid"`). */
82
+ transports: string[];
83
+ }
84
+ /**
85
+ * A fresh WebAuthn ceremony challenge — the shared result shape of
86
+ * `POST /me/passkeys/options` (`data/passkeys.ts:118-130`) and
87
+ * `POST /auth/passkey/options` (`id/passkey-login.ts:63-71`). Flat, no
88
+ * envelope key.
89
+ */
90
+ export interface PasskeyCeremonyOptions {
91
+ /**
92
+ * WebAuthn ceremony options, opaque JSON forwarded verbatim to
93
+ * `navigator.credentials.create()`/`.get()` (or a browser WebAuthn helper).
94
+ * This package never inspects its shape — see this module's header.
95
+ */
96
+ options: Record<string, unknown>;
97
+ /** Single-use challenge token. Echo it back on the paired verify call. */
98
+ challengeToken: string;
99
+ }
100
+ /** The body `registrationVerify` sends (`POST /me/passkeys`, `data/passkeys.ts:132-164`). */
101
+ export interface RegistrationVerifyInput {
102
+ /** The token returned by the paired `registrationOptions()` call. */
103
+ challengeToken: string;
104
+ /**
105
+ * The browser's `RegistrationResponseJSON`, opaque JSON — see this
106
+ * module's header.
107
+ */
108
+ response: Record<string, unknown>;
109
+ /** Caller-chosen label for the new passkey. */
110
+ label?: string;
111
+ }
112
+ /** The body `authenticationVerify` sends (`POST /auth/passkey/verify`, `id/passkey-login.ts:73-110`). */
113
+ export interface AuthenticationVerifyInput {
114
+ /** The token returned by the paired `authenticationOptions()` call. */
115
+ challengeToken: string;
116
+ /**
117
+ * The browser's `AuthenticationResponseJSON`, opaque JSON — see this
118
+ * module's header.
119
+ */
120
+ response: Record<string, unknown>;
121
+ }
122
+ /**
123
+ * The user identity `authenticationVerify` mints a session for, as
124
+ * `id/passkey-login.ts` returns it — BYTE-SHAPE IDENTICAL to
125
+ * `console.auth`'s `LoginResponse.user`'s sibling in `user-login.ts`, but
126
+ * carrying more fields (`role`, `tenant`, `emailVerified`), which is why this
127
+ * is a separate type rather than a reuse of `./auth.ts`'s `User`.
128
+ */
129
+ export interface PasskeyUser {
130
+ /** The user's email, or its `userId` when no email is on file. */
131
+ username: string;
132
+ /** Always `"user"` for a passkey login (`id/passkey-login.ts:100`). */
133
+ role: string;
134
+ /** The tenant the session is minted in. */
135
+ tenant: string;
136
+ emailVerified: boolean;
137
+ }
138
+ /**
139
+ * `POST /auth/passkey/verify` → 200 (`id/passkey-login.ts:96-105`). Mints a
140
+ * session exactly like `console.auth.login` does (HITL-5) — a verified
141
+ * passkey assertion is a standalone alternative to a password, not a second
142
+ * factor.
143
+ */
144
+ export interface PasskeyAuthenticationVerifyResponse {
145
+ token: string;
146
+ user: PasskeyUser;
147
+ expiresIn: number;
148
+ }
149
+ /**
150
+ * The `console.passkeys` namespace on a `W6WClient`.
151
+ *
152
+ * @example
153
+ * ```ts
154
+ * // Registration (authenticated).
155
+ * const { options, challengeToken } = await client.console.passkeys.registrationOptions();
156
+ * const response = await startRegistration({ optionsJSON: options }); // e.g. @simplewebauthn/browser
157
+ * const passkey = await client.console.passkeys.registrationVerify({ challengeToken, response });
158
+ *
159
+ * // Login (public — works on a tokenless client).
160
+ * const opts = await client.console.passkeys.authenticationOptions();
161
+ * const assertion = await startAuthentication({ optionsJSON: opts.options });
162
+ * const { token } = await client.console.passkeys.authenticationVerify({
163
+ * challengeToken: opts.challengeToken,
164
+ * response: assertion,
165
+ * });
166
+ * ```
167
+ */
168
+ export declare class PasskeysApi {
169
+ #private;
170
+ /**
171
+ * @param host - The client this namespace issues requests through.
172
+ */
173
+ constructor(host: PasskeysHost);
174
+ /**
175
+ * A fresh registration challenge, scoped to the caller's own identity.
176
+ *
177
+ * AUTHENTICATED — the default `requireAuth` applies.
178
+ *
179
+ * @returns The ceremony options and a single-use challenge token.
180
+ * @throws {ApiError} `400 passkey_not_configured`, `403 passkey_not_eligible`.
181
+ */
182
+ registrationOptions(): Promise<PasskeyCeremonyOptions>;
183
+ /**
184
+ * Verify a registration ceremony and store the credential.
185
+ *
186
+ * AUTHENTICATED — the default `requireAuth` applies.
187
+ *
188
+ * @param input - The challenge token from `registrationOptions()`, the browser's ceremony
189
+ * response, and an optional caller-chosen label.
190
+ * @returns The stored passkey's metadata, unwrapped from the `passkey` envelope.
191
+ * @throws {ApiError} `400 passkey_registration_failed`, `403 passkey_not_eligible`,
192
+ * `409 passkey_already_registered`.
193
+ */
194
+ registrationVerify(input: RegistrationVerifyInput): Promise<Passkey>;
195
+ /**
196
+ * A fresh authentication challenge. No identifier is sent or accepted —
197
+ * discoverable credentials only (P1): the owner is resolved server-side
198
+ * from the assertion itself, never from anything this call sends.
199
+ *
200
+ * PUBLIC — sends no bearer, even on a client that already holds one
201
+ * (`requireAuth: false`). Without it, the login screen (the normal case:
202
+ * no session exists yet) could never call this method at all — a tokenless
203
+ * client would hit `requireToken`'s `ConfigError` before `fetch` is ever
204
+ * called.
205
+ *
206
+ * @returns The ceremony options and a single-use challenge token.
207
+ * @throws {ApiError} `400 passkey_not_configured`.
208
+ */
209
+ authenticationOptions(): Promise<PasskeyCeremonyOptions>;
210
+ /**
211
+ * Verify an authentication (login) ceremony and mint a session — the same
212
+ * way `console.auth.login` does (HITL-5).
213
+ *
214
+ * PUBLIC — sends no bearer, even on a client that already holds one
215
+ * (`requireAuth: false`). Every failure mode past a malformed body is the
216
+ * same `401 passkey_rejected` (P9): unknown credential, revoked credential,
217
+ * wrong kind, bad signature, counter regression, and a spent/invalid
218
+ * challenge are indistinguishable to the caller.
219
+ *
220
+ * @param input - The challenge token from `authenticationOptions()` and the browser's ceremony
221
+ * response.
222
+ * @returns The token, the caller's identity, and the token's lifetime.
223
+ * @throws {ApiError} `401 passkey_rejected` on any verification failure.
224
+ */
225
+ authenticationVerify(input: AuthenticationVerifyInput): Promise<PasskeyAuthenticationVerifyResponse>;
226
+ /**
227
+ * List the caller's own passkeys.
228
+ *
229
+ * AUTHENTICATED — the default `requireAuth` applies.
230
+ *
231
+ * @returns The caller's passkeys, unwrapped from the `passkeys` envelope. Never the empty array
232
+ * collapsed to `undefined` — an empty account gets `[]`.
233
+ */
234
+ list(): Promise<Passkey[]>;
235
+ /**
236
+ * Revoke (delete) one of the caller's own passkeys.
237
+ *
238
+ * AUTHENTICATED — the default `requireAuth` applies.
239
+ *
240
+ * @param id - The passkey id.
241
+ * @returns Nothing: the server answers `204` with no body.
242
+ * @throws {ApiError} `404 passkey_not_found`.
243
+ */
244
+ revoke(id: string): Promise<void>;
245
+ }
246
+ //# sourceMappingURL=passkeys.d.ts.map
@@ -0,0 +1 @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