@w6w/sdk 0.4.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.
- package/README.md +24 -21
- package/dist/mod.d.ts +6 -2
- package/dist/mod.d.ts.map +1 -1
- package/dist/mod.js +4 -2
- package/dist/mod.js.map +1 -1
- package/dist/src/client.d.ts +32 -9
- package/dist/src/client.d.ts.map +1 -1
- package/dist/src/client.js +33 -8
- package/dist/src/client.js.map +1 -1
- package/dist/src/config.d.ts +2 -2
- package/dist/src/config.js +3 -3
- package/dist/src/config.js.map +1 -1
- package/dist/src/connections.d.ts +2 -2
- package/dist/src/connections.js +1 -1
- package/dist/src/console/aliases.d.ts +137 -0
- package/dist/src/console/aliases.d.ts.map +1 -0
- package/dist/src/console/aliases.js +113 -0
- package/dist/src/console/aliases.js.map +1 -0
- package/dist/src/console/api-calls.d.ts +2 -2
- package/dist/src/console/api-calls.js +1 -1
- package/dist/src/console/apps.d.ts +4 -4
- package/dist/src/console/apps.js +3 -3
- package/dist/src/console/auth.d.ts +204 -6
- package/dist/src/console/auth.d.ts.map +1 -1
- package/dist/src/console/auth.js +155 -5
- package/dist/src/console/auth.js.map +1 -1
- package/dist/src/console/connections.d.ts +2 -2
- package/dist/src/console/connections.js +1 -1
- package/dist/src/console/dashboard.d.ts +2 -2
- package/dist/src/console/dashboard.js +1 -1
- package/dist/src/console/endpoints.d.ts +25 -7
- package/dist/src/console/endpoints.d.ts.map +1 -1
- package/dist/src/console/endpoints.js +1 -1
- package/dist/src/console/endpoints.js.map +1 -1
- package/dist/src/console/functions.d.ts +2 -2
- package/dist/src/console/functions.js +1 -1
- package/dist/src/console/mod.d.ts +15 -5
- package/dist/src/console/mod.d.ts.map +1 -1
- package/dist/src/console/mod.js +12 -2
- package/dist/src/console/mod.js.map +1 -1
- package/dist/src/console/passkeys.d.ts +246 -0
- package/dist/src/console/passkeys.d.ts.map +1 -0
- package/dist/src/console/passkeys.js +192 -0
- package/dist/src/console/passkeys.js.map +1 -0
- package/dist/src/console/projects.d.ts +2 -2
- package/dist/src/console/projects.js +1 -1
- package/dist/src/console/reliability.d.ts +2 -2
- package/dist/src/console/reliability.js +1 -1
- package/dist/src/console/saved-tests.d.ts +3 -3
- package/dist/src/console/saved-tests.js +2 -2
- package/dist/src/console/schedules.d.ts +2 -2
- package/dist/src/console/schedules.js +1 -1
- package/dist/src/console/step-tests.d.ts +3 -3
- package/dist/src/console/step-tests.js +2 -2
- package/dist/src/console/subscriptions.d.ts +2 -2
- package/dist/src/console/subscriptions.js +1 -1
- package/dist/src/console/tenant-oauth-apps.d.ts +2 -2
- package/dist/src/console/tenant-oauth-apps.js +1 -1
- package/dist/src/console/tokens.d.ts +2 -2
- package/dist/src/console/tokens.js +1 -1
- package/dist/src/console/vault.d.ts +2 -2
- package/dist/src/console/vault.js +1 -1
- package/dist/src/console/workflows.d.ts +2 -2
- package/dist/src/console/workflows.js +1 -1
- package/dist/src/documents.d.ts +2 -2
- package/dist/src/documents.js +1 -1
- package/dist/src/endpoints.d.ts +75 -0
- package/dist/src/endpoints.d.ts.map +1 -0
- package/dist/src/endpoints.js +47 -0
- package/dist/src/endpoints.js.map +1 -0
- package/dist/src/functions.d.ts +88 -0
- package/dist/src/functions.d.ts.map +1 -0
- package/dist/src/functions.js +56 -0
- package/dist/src/functions.js.map +1 -0
- package/dist/src/me.d.ts +2 -2
- package/dist/src/me.js +1 -1
- package/dist/src/run.d.ts +9 -4
- package/dist/src/run.d.ts.map +1 -1
- package/dist/src/run.js +3 -2
- package/dist/src/run.js.map +1 -1
- package/dist/src/vars.d.ts +2 -2
- package/dist/src/vars.js +1 -1
- package/dist/src/version.js +1 -1
- package/dist/src/workflows.d.ts +2 -2
- package/dist/src/workflows.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `client.console.aliases.*` — account-scoped alias management
|
|
3
|
+
* (`list`/`get`/`upsert`/`delete`) for the names `run`'s URN dispatch
|
|
4
|
+
* resolves alongside its four `conn_…`/`wf_…`/`fn_…`/`ep_…` arms
|
|
5
|
+
* (`src/run.ts`).
|
|
6
|
+
*
|
|
7
|
+
* **Studio-internal, not the published partner contract.** This namespace
|
|
8
|
+
* lives under the `console` subpath export (`@w6w/sdk/console`), excluded
|
|
9
|
+
* from `endpoints.json` and from the root barrel (`mod.ts`) — see
|
|
10
|
+
* `docs/console.md` and HITL-2 in this project's contract. This surface is
|
|
11
|
+
* **new**: unlike `console.functions`/`console.endpoints`, there is no
|
|
12
|
+
* pre-existing `studio/src/api/client.ts` alias code being relocated here —
|
|
13
|
+
* Studio never had alias CRUD before this project. `@w6w/sdk`'s
|
|
14
|
+
* instance-state mechanism pin still applies here exactly as it does to
|
|
15
|
+
* every other namespace (`docs/implementation.md` §MECHANISM PIN — instance
|
|
16
|
+
* state, never globals): this class holds no state of its own beyond the
|
|
17
|
+
* injected host, so two clients in one process never share a credential.
|
|
18
|
+
*
|
|
19
|
+
* **`invoke`/`run` is deliberately NOT modeled here.** The base
|
|
20
|
+
* `client.run({urn: aliasName, payload})` (already-published surface,
|
|
21
|
+
* `endpoints.json`-named, exported from the root `mod.ts`) already reaches
|
|
22
|
+
* an alias's target — an alias name is one of `run`'s runnable `urn` arms,
|
|
23
|
+
* alongside `conn_…`/`wf_…`/`fn_…`/`ep_…` (`src/run.ts`). Adding a duplicate
|
|
24
|
+
* `console.aliases.invoke` would give a caller two ways to reach the same
|
|
25
|
+
* route — the exact anti-duplication defect `console/functions.ts:15-26`
|
|
26
|
+
* flags for Functions, applied here with alias/`run` substituted for
|
|
27
|
+
* function/`run`; `console.endpoints`/`console.workflows` follow the same
|
|
28
|
+
* precedent. No invoke method lives here, and none should be added later
|
|
29
|
+
* without re-litigating this reasoning.
|
|
30
|
+
*
|
|
31
|
+
* @module
|
|
32
|
+
*/
|
|
33
|
+
import { path } from "../http.js";
|
|
34
|
+
import { unwrap } from "../types.js";
|
|
35
|
+
/**
|
|
36
|
+
* The `console.aliases` namespace on a `W6WClient`.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* const aliases = await client.console.aliases.list();
|
|
41
|
+
* const alias = await client.console.aliases.get(aliases[0].id);
|
|
42
|
+
* await client.console.aliases.upsert({ ...alias, description: "Send email" });
|
|
43
|
+
* await client.console.aliases.delete(alias.id);
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export class AliasesApi {
|
|
47
|
+
#host;
|
|
48
|
+
/**
|
|
49
|
+
* @param host - The client this namespace issues requests through.
|
|
50
|
+
*/
|
|
51
|
+
constructor(host) {
|
|
52
|
+
this.#host = host;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* List the caller's aliases.
|
|
56
|
+
*
|
|
57
|
+
* @returns The aliases, unwrapped from the `aliases` envelope.
|
|
58
|
+
*/
|
|
59
|
+
async list() {
|
|
60
|
+
const res = await this.#host.request({ method: "GET", path: "/aliases" });
|
|
61
|
+
return unwrap(res, "aliases");
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Fetch one alias's stored definition.
|
|
65
|
+
*
|
|
66
|
+
* No server-computed field to splice in — unlike
|
|
67
|
+
* {@linkcode FunctionsApi.get}'s `valid` merge, this returns
|
|
68
|
+
* `unwrap<AliasDef>(res, "alias")` plainly.
|
|
69
|
+
*
|
|
70
|
+
* @param id - The alias's `id`.
|
|
71
|
+
* @returns The alias definition, unwrapped from the `alias` envelope.
|
|
72
|
+
* @throws {ApiError} `404 unknown_alias` when there is no such id.
|
|
73
|
+
*/
|
|
74
|
+
async get(id) {
|
|
75
|
+
const res = await this.#host.request({ method: "GET", path: path `/aliases/${id}` });
|
|
76
|
+
return unwrap(res, "alias");
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Register (create or overwrite) an alias definition.
|
|
80
|
+
*
|
|
81
|
+
* `definition` is the whole definition, sent verbatim as the request body
|
|
82
|
+
* — not wrapped in an envelope key.
|
|
83
|
+
*
|
|
84
|
+
* @param definition - The whole alias definition, forwarded verbatim.
|
|
85
|
+
* @returns The new/updated alias's id and name.
|
|
86
|
+
* @throws {ApiError} `400 invalid_alias` — structurally invalid body.
|
|
87
|
+
* @throws {ApiError} `409 alias_conflict` — another `(tenant,subject)` owns this id.
|
|
88
|
+
* @throws {ApiError} `409 alias_name_conflict` — another alias already owns this name.
|
|
89
|
+
* @throws {ApiError} `409 alias_name_immutable` — `name` changed on an already-stored alias (HITL-3).
|
|
90
|
+
*/
|
|
91
|
+
async upsert(definition) {
|
|
92
|
+
const res = await this.#host.request({
|
|
93
|
+
method: "POST",
|
|
94
|
+
path: "/aliases",
|
|
95
|
+
body: definition,
|
|
96
|
+
});
|
|
97
|
+
return unwrap(res, "alias");
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Delete an alias.
|
|
101
|
+
*
|
|
102
|
+
* Returns nothing: the server's `{ok: true}` carries no information a
|
|
103
|
+
* caller can use, mirroring `console.vault.delete`/`console.projects.delete`
|
|
104
|
+
* in this same package.
|
|
105
|
+
*
|
|
106
|
+
* @param id - The alias's `id`.
|
|
107
|
+
* @throws {ApiError} `404 unknown_alias` when there is no such id.
|
|
108
|
+
*/
|
|
109
|
+
async delete(id) {
|
|
110
|
+
await this.#host.request({ method: "DELETE", path: path `/aliases/${id}` });
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=aliases.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aliases.js","sourceRoot":"","sources":["../../../src/console/aliases.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,EAAqB,IAAI,EAAuB,MAAM,YAAY,CAAC;AAC1E,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AA4CrC;;;;;;;;;;GAUG;AACH,MAAM,OAAO,UAAU;IACZ,KAAK,CAAc;IAE5B;;OAEG;IACH,YAAY,IAAiB;QAC3B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,IAAI;QACR,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAU,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC;QACnF,OAAO,MAAM,CAAiB,GAAG,EAAE,SAAS,CAAC,CAAC;IAChD,CAAC;IAED;;;;;;;;;;OAUG;IACH,KAAK,CAAC,GAAG,CAAC,EAAU;QAClB,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAU,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,CAAA,YAAY,EAAE,EAAE,EAAE,CAAC,CAAC;QAC7F,OAAO,MAAM,CAAW,GAAG,EAAE,OAAO,CAAC,CAAC;IACxC,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,KAAK,CAAC,MAAM,CAAC,UAAoB;QAC/B,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAU;YAC5C,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,UAAU;YAChB,IAAI,EAAE,UAAU;SACjB,CAAC,CAAC;QACH,OAAO,MAAM,CAA+B,GAAG,EAAE,OAAO,CAAC,CAAC;IAC5D,CAAC;IAED;;;;;;;;;OASG;IACH,KAAK,CAAC,MAAM,CAAC,EAAU;QACrB,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,CAAA,YAAY,EAAE,EAAE,EAAE,CAAC,CAAC;IACtF,CAAC;CACF"}
|
|
@@ -30,7 +30,7 @@ import type { HttpResponse, RequestOptions } from "../http.ts";
|
|
|
30
30
|
import type { ApiCallRecord } from "./apps.ts";
|
|
31
31
|
export type { ApiCallRecord } from "./apps.ts";
|
|
32
32
|
/**
|
|
33
|
-
* The slice of `
|
|
33
|
+
* The slice of `W6WClient` this namespace needs: the transport, and nothing
|
|
34
34
|
* else. Structural rather than a concrete client type, so the namespace stays
|
|
35
35
|
* independently constructible in a test and this module never imports the
|
|
36
36
|
* client back — mirrors `VarsHost` in `../vars.ts`.
|
|
@@ -54,7 +54,7 @@ export interface ApiCallsFilter {
|
|
|
54
54
|
limit?: number;
|
|
55
55
|
}
|
|
56
56
|
/**
|
|
57
|
-
* The `console.apiCalls` namespace on a `
|
|
57
|
+
* The `console.apiCalls` namespace on a `W6WClient`.
|
|
58
58
|
*
|
|
59
59
|
* @example
|
|
60
60
|
* ```ts
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
*/
|
|
62
62
|
import { type HttpResponse, type RequestOptions } from "../http.ts";
|
|
63
63
|
/**
|
|
64
|
-
* The slice of `
|
|
64
|
+
* The slice of `W6WClient` this namespace needs: the transport, and nothing
|
|
65
65
|
* else. Structural rather than a concrete client type, so the namespace stays
|
|
66
66
|
* independently constructible in a test and this module never imports the
|
|
67
67
|
* client back — mirrors `VarsHost` in `../vars.ts`.
|
|
@@ -446,7 +446,7 @@ export interface UpsertOAuthConfigInput {
|
|
|
446
446
|
extra?: Record<string, unknown>;
|
|
447
447
|
}
|
|
448
448
|
/**
|
|
449
|
-
* The `console.apps` namespace on a `
|
|
449
|
+
* The `console.apps` namespace on a `W6WClient`.
|
|
450
450
|
*
|
|
451
451
|
* @example
|
|
452
452
|
* ```ts
|
|
@@ -577,7 +577,7 @@ export declare class AppsApi {
|
|
|
577
577
|
* URL for the caller to open.
|
|
578
578
|
*
|
|
579
579
|
* No studio-page caller, but this method's shape must exactly match
|
|
580
|
-
* `
|
|
580
|
+
* `W6WApi.startAppOAuthFlow`'s signature on the `@w6w/ui` facade
|
|
581
581
|
* (`packages/ui/src/provider.tsx:110-114`), which calls it.
|
|
582
582
|
*
|
|
583
583
|
* @param appId - The app id.
|
|
@@ -639,7 +639,7 @@ export declare class AppsApi {
|
|
|
639
639
|
/**
|
|
640
640
|
* Invoke one of an app's actions.
|
|
641
641
|
*
|
|
642
|
-
* This method's shape must exactly match `
|
|
642
|
+
* This method's shape must exactly match `W6WApi.invokeAction`'s signature on
|
|
643
643
|
* the `@w6w/ui` facade (`packages/ui/src/provider.tsx`). It now models the
|
|
644
644
|
* WHOLE of that `opts` — `project` and `state` included.
|
|
645
645
|
*
|
package/dist/src/console/apps.js
CHANGED
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
import { path } from "../http.js";
|
|
63
63
|
import { unwrap } from "../types.js";
|
|
64
64
|
/**
|
|
65
|
-
* The `console.apps` namespace on a `
|
|
65
|
+
* The `console.apps` namespace on a `W6WClient`.
|
|
66
66
|
*
|
|
67
67
|
* @example
|
|
68
68
|
* ```ts
|
|
@@ -264,7 +264,7 @@ export class AppsApi {
|
|
|
264
264
|
* URL for the caller to open.
|
|
265
265
|
*
|
|
266
266
|
* No studio-page caller, but this method's shape must exactly match
|
|
267
|
-
* `
|
|
267
|
+
* `W6WApi.startAppOAuthFlow`'s signature on the `@w6w/ui` facade
|
|
268
268
|
* (`packages/ui/src/provider.tsx:110-114`), which calls it.
|
|
269
269
|
*
|
|
270
270
|
* @param appId - The app id.
|
|
@@ -345,7 +345,7 @@ export class AppsApi {
|
|
|
345
345
|
/**
|
|
346
346
|
* Invoke one of an app's actions.
|
|
347
347
|
*
|
|
348
|
-
* This method's shape must exactly match `
|
|
348
|
+
* This method's shape must exactly match `W6WApi.invokeAction`'s signature on
|
|
349
349
|
* the `@w6w/ui` facade (`packages/ui/src/provider.tsx`). It now models the
|
|
350
350
|
* WHOLE of that `opts` — `project` and `state` included.
|
|
351
351
|
*
|
|
@@ -43,11 +43,29 @@
|
|
|
43
43
|
* handlers, not assumed) — every method here returns `res.body` directly and
|
|
44
44
|
* never calls this package's `unwrap()` helper.
|
|
45
45
|
*
|
|
46
|
+
* **T1.1.4's seven `/me/*` methods added here (profile, contact
|
|
47
|
+
* change-and-confirm, promote, remove, password).** Registered BELOW the auth
|
|
48
|
+
* guard (`packages/server/packages/api/data/me.ts`'s own doc comment) — every
|
|
49
|
+
* one of the seven is AUTHENTICATED, the default `requireAuth`, unlike
|
|
50
|
+
* `login`/`signup`/`checkAccountSlug` above. `removeContact` and
|
|
51
|
+
* `promoteContact` are not in this task's pinned method list but are added
|
|
52
|
+
* per HITL-7 ("if T1.1.4 ships routes for adding / removing / promoting a
|
|
53
|
+
* secondary contact, they get methods here too") — both routes exist on the
|
|
54
|
+
* merged branch (`data/me.ts:135-154`).
|
|
55
|
+
*
|
|
56
|
+
* **`UserProfile.hasPassword` is a RENAME of the wire's `passwordSet`, not an
|
|
57
|
+
* invented field.** `GET /me/profile` answers `passwordSet` (`data/me.ts:9`,
|
|
58
|
+
* `packages/bll/signup.ts:555`, derived server-side from
|
|
59
|
+
* `password_hash !== null` — the hash itself never appears). HITL-10 needs
|
|
60
|
+
* this fact under a name Studio's "Set a password"/"Change password" fork
|
|
61
|
+
* reads directly; `toUserProfile()` below performs the rename from the exact
|
|
62
|
+
* value the wire sent, never a default and never computed from anything else.
|
|
63
|
+
*
|
|
46
64
|
* @module
|
|
47
65
|
*/
|
|
48
|
-
import type
|
|
66
|
+
import { type HttpResponse, type RequestOptions } from "../http.ts";
|
|
49
67
|
/**
|
|
50
|
-
* The slice of `
|
|
68
|
+
* The slice of `W6WClient` this namespace needs: the transport, and nothing
|
|
51
69
|
* else. Structural rather than a concrete client type, so the namespace stays
|
|
52
70
|
* independently constructible in a test and this module never imports the
|
|
53
71
|
* client back — mirrors `ReliabilityHost` in `./reliability.ts`.
|
|
@@ -153,11 +171,103 @@ export interface ConsoleMe {
|
|
|
153
171
|
versions?: Record<string, string>;
|
|
154
172
|
}
|
|
155
173
|
/**
|
|
156
|
-
*
|
|
174
|
+
* One of the caller's own contact addresses (email or phone), as `GET /me/profile`
|
|
175
|
+
* lists it (`packages/bll/signup.ts`'s `ProfileContact`, `data/me.ts:9-12`).
|
|
176
|
+
*/
|
|
177
|
+
export interface ProfileContact {
|
|
178
|
+
id: string;
|
|
179
|
+
kind: "email" | "phone";
|
|
180
|
+
value: string;
|
|
181
|
+
/** ISO-8601 timestamp, or `null` while unverified. */
|
|
182
|
+
verifiedAt: string | null;
|
|
183
|
+
}
|
|
184
|
+
/** One of the caller's registered login methods (`data/me.ts:9-12`). */
|
|
185
|
+
export interface ProfileLoginMethod {
|
|
186
|
+
id: string;
|
|
187
|
+
/** e.g. `"password"`, `"passkey"`. */
|
|
188
|
+
kind: string;
|
|
189
|
+
label: string;
|
|
190
|
+
/** ISO-8601 timestamp. */
|
|
191
|
+
createdAt: string;
|
|
192
|
+
/** ISO-8601 timestamp, or `null` if never used. */
|
|
193
|
+
lastUsedAt: string | null;
|
|
194
|
+
}
|
|
195
|
+
/** A pending, unconfirmed contact-change request (`data/me.ts:9-12`). */
|
|
196
|
+
export interface ProfilePendingChange {
|
|
197
|
+
id: string;
|
|
198
|
+
method: "email" | "phone";
|
|
199
|
+
value: string;
|
|
200
|
+
/** ISO-8601 timestamp; the pending row is unusable past this point. */
|
|
201
|
+
expiresAt: string;
|
|
202
|
+
/** ISO-8601 timestamp. */
|
|
203
|
+
createdAt: string;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* The `users` row and its dependent state, as `GET`/`PATCH /me/profile`,
|
|
207
|
+
* `POST /me/contacts/confirm` and `POST /me/contacts/:id/primary` all return
|
|
208
|
+
* it (`data/me.ts:6-19`). Every method on this namespace that returns a
|
|
209
|
+
* profile returns THIS shape, mapped from the wire's `passwordSet` — see this
|
|
210
|
+
* module's header for why {@linkcode UserProfile.hasPassword} is a rename,
|
|
211
|
+
* not an invented field.
|
|
212
|
+
*/
|
|
213
|
+
export interface UserProfile {
|
|
214
|
+
userId: string;
|
|
215
|
+
tenant: string;
|
|
216
|
+
displayName: string;
|
|
217
|
+
email: string | null;
|
|
218
|
+
emailVerified: boolean;
|
|
219
|
+
/**
|
|
220
|
+
* Whether the caller already has a local password. Read straight off the
|
|
221
|
+
* wire's `passwordSet` (`packages/bll/signup.ts:555`) — never defaulted,
|
|
222
|
+
* never computed client-side. Drives HITL-10's "Set a password" (`false`)
|
|
223
|
+
* vs "Change password" (`true`) fork.
|
|
224
|
+
*/
|
|
225
|
+
hasPassword: boolean;
|
|
226
|
+
contacts: ProfileContact[];
|
|
227
|
+
loginMethods: ProfileLoginMethod[];
|
|
228
|
+
pending: ProfilePendingChange[];
|
|
229
|
+
}
|
|
230
|
+
/** The body `updateProfile` sends (`PATCH /me/profile`, `data/me.ts:53-71`). */
|
|
231
|
+
export interface UpdateProfileInput {
|
|
232
|
+
displayName: string;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* The body `requestContactChange` sends (`POST /me/contacts/change`,
|
|
236
|
+
* `data/me.ts:73-98`). Parks a pending change; does not confirm it.
|
|
237
|
+
*/
|
|
238
|
+
export interface RequestContactChangeInput {
|
|
239
|
+
method: "email" | "phone";
|
|
240
|
+
value: string;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* The body `confirmContactChange` sends (`POST /me/contacts/confirm`,
|
|
244
|
+
* `data/me.ts:100-133`). Consumes the code sent to `requestContactChange`'s
|
|
245
|
+
* `value`.
|
|
246
|
+
*/
|
|
247
|
+
export interface ConfirmContactChangeInput {
|
|
248
|
+
method: "email" | "phone";
|
|
249
|
+
code: string;
|
|
250
|
+
/** Promote the newly-confirmed contact to primary in the same call (D3). */
|
|
251
|
+
promote?: boolean;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* The body `setPassword` sends (`POST /me/password`, `data/me.ts:156-184`).
|
|
255
|
+
* One method for HITL-10's set-and-change: `currentPassword` is a field, not
|
|
256
|
+
* a second method, because the merged route is the single `POST /me/password`
|
|
257
|
+
* — not two routes.
|
|
258
|
+
*/
|
|
259
|
+
export interface SetPasswordInput {
|
|
260
|
+
newPassword: string;
|
|
261
|
+
/** Required by the server when the caller already has a password (`hasPassword: true`); omit
|
|
262
|
+
* for the first-time "set a password" case. */
|
|
263
|
+
currentPassword?: string;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* The `console.auth` namespace on a `W6WClient`.
|
|
157
267
|
*
|
|
158
268
|
* @example
|
|
159
269
|
* ```ts
|
|
160
|
-
* const { token } = await client.console.auth.login("user", "pass");
|
|
270
|
+
* const { token } = await client.console.auth.login("user@example.com", "pass");
|
|
161
271
|
* const me = await client.console.auth.getMe();
|
|
162
272
|
* if (me.tenantAdmin) { // tenant-admin surface
|
|
163
273
|
* }
|
|
@@ -175,12 +285,15 @@ export declare class AuthApi {
|
|
|
175
285
|
* PUBLIC — sends no bearer, even on a client that already holds one
|
|
176
286
|
* (`requireAuth: false`).
|
|
177
287
|
*
|
|
178
|
-
* @param
|
|
288
|
+
* @param identifier - The login identifier, normally the account's email. The
|
|
289
|
+
* platform operator credential (`AUTH_USERNAME`) is NOT email-shaped and is a
|
|
290
|
+
* legitimate value here — never validate this as an email (DECISIONS.md HITL-1).
|
|
291
|
+
* It is sent as the `email` key: the server resolves `body.email ?? body.username`.
|
|
179
292
|
* @param password - The account password.
|
|
180
293
|
* @returns The token, the caller's identity, and the token's lifetime.
|
|
181
294
|
* @throws {ApiError} On any non-2xx, e.g. `401` for invalid credentials.
|
|
182
295
|
*/
|
|
183
|
-
login(
|
|
296
|
+
login(identifier: string, password: string): Promise<LoginResponse>;
|
|
184
297
|
/**
|
|
185
298
|
* Self-serve signup: creates the user and mints a `role: "user"` session.
|
|
186
299
|
*
|
|
@@ -237,5 +350,90 @@ export declare class AuthApi {
|
|
|
237
350
|
* @throws {ApiError} On any non-2xx, e.g. `401` when the bearer is missing or expired.
|
|
238
351
|
*/
|
|
239
352
|
getMe(): Promise<ConsoleMe>;
|
|
353
|
+
/**
|
|
354
|
+
* Read the caller's own profile — the real `users` row, including
|
|
355
|
+
* {@linkcode UserProfile.hasPassword}. Distinct from `getMe()`, which reads
|
|
356
|
+
* session claims: this reads the actual database row (`data/me.ts:43-51`).
|
|
357
|
+
*
|
|
358
|
+
* AUTHENTICATED — the default `requireAuth` applies.
|
|
359
|
+
*
|
|
360
|
+
* @returns The caller's profile.
|
|
361
|
+
* @throws {ApiError} `404 no_user_profile` when there is no `users` row for this principal.
|
|
362
|
+
*/
|
|
363
|
+
getProfile(): Promise<UserProfile>;
|
|
364
|
+
/**
|
|
365
|
+
* Patch the caller's display name.
|
|
366
|
+
*
|
|
367
|
+
* AUTHENTICATED — the default `requireAuth` applies.
|
|
368
|
+
*
|
|
369
|
+
* @param input - The new display name.
|
|
370
|
+
* @returns The updated profile (`data/me.ts:53-71`).
|
|
371
|
+
* @throws {ApiError} `400 invalid_body`/`invalid_display_name`.
|
|
372
|
+
*/
|
|
373
|
+
updateProfile(input: UpdateProfileInput): Promise<UserProfile>;
|
|
374
|
+
/**
|
|
375
|
+
* Park a pending email/phone change and send its confirmation code. Does
|
|
376
|
+
* NOT confirm the change — see {@linkcode confirmContactChange}.
|
|
377
|
+
*
|
|
378
|
+
* AUTHENTICATED — the default `requireAuth` applies.
|
|
379
|
+
*
|
|
380
|
+
* @param input - The contact method and the new value.
|
|
381
|
+
* @returns Nothing: the server answers `202` with `{ok: true}`, which carries no information a
|
|
382
|
+
* caller can use (`data/me.ts:73-98`).
|
|
383
|
+
* @throws {ApiError} `400 invalid_body`/`invalid_email`, `409 email_taken`.
|
|
384
|
+
*/
|
|
385
|
+
requestContactChange(input: RequestContactChangeInput): Promise<void>;
|
|
386
|
+
/**
|
|
387
|
+
* Consume the code from {@linkcode requestContactChange} and confirm the
|
|
388
|
+
* pending change. Optionally promotes the newly-confirmed contact to
|
|
389
|
+
* primary in the same call (D3).
|
|
390
|
+
*
|
|
391
|
+
* AUTHENTICATED — the default `requireAuth` applies.
|
|
392
|
+
*
|
|
393
|
+
* @param input - The contact method, the code, and an optional promote flag.
|
|
394
|
+
* @returns The updated profile (`data/me.ts:100-133`).
|
|
395
|
+
* @throws {ApiError} `400 invalid_body`/`invalid_code`, `404 contact_not_found`.
|
|
396
|
+
*/
|
|
397
|
+
confirmContactChange(input: ConfirmContactChangeInput): Promise<UserProfile>;
|
|
398
|
+
/**
|
|
399
|
+
* Remove one of the caller's own (non-primary) contacts. Added per HITL-7
|
|
400
|
+
* — `DELETE /me/contacts/:id` exists on the merged branch (`data/me.ts:135-144`).
|
|
401
|
+
*
|
|
402
|
+
* AUTHENTICATED — the default `requireAuth` applies.
|
|
403
|
+
*
|
|
404
|
+
* @param id - The contact id.
|
|
405
|
+
* @returns Nothing: the server answers `{ok: true}`, which carries no information a caller can
|
|
406
|
+
* use, mirroring `console.projects.delete`/`console.schedules.delete` in this same package.
|
|
407
|
+
* @throws {ApiError} `404 contact_not_found`.
|
|
408
|
+
*/
|
|
409
|
+
removeContact(id: string): Promise<void>;
|
|
410
|
+
/**
|
|
411
|
+
* Promote one of the caller's own secondary contacts to primary. Added per
|
|
412
|
+
* HITL-7 — `POST /me/contacts/:id/primary` exists on the merged branch
|
|
413
|
+
* (`data/me.ts:146-154`).
|
|
414
|
+
*
|
|
415
|
+
* AUTHENTICATED — the default `requireAuth` applies.
|
|
416
|
+
*
|
|
417
|
+
* @param id - The contact id.
|
|
418
|
+
* @returns The updated profile.
|
|
419
|
+
* @throws {ApiError} `404 contact_not_found`, `403 contact_not_verified`.
|
|
420
|
+
*/
|
|
421
|
+
promoteContact(id: string): Promise<UserProfile>;
|
|
422
|
+
/**
|
|
423
|
+
* Set or change the caller's password (HITL-10) — one method, since the
|
|
424
|
+
* merged route is the single `POST /me/password`, not two. Omit
|
|
425
|
+
* `currentPassword` for the first-time "set a password" case
|
|
426
|
+
* (`hasPassword: false`); the server requires it once a password already
|
|
427
|
+
* exists.
|
|
428
|
+
*
|
|
429
|
+
* AUTHENTICATED — the default `requireAuth` applies.
|
|
430
|
+
*
|
|
431
|
+
* @param input - The new password, plus the current one when required.
|
|
432
|
+
* @returns Nothing: the server answers `{ok: true}`, which carries no information a caller can
|
|
433
|
+
* use (`data/me.ts:156-184`).
|
|
434
|
+
* @throws {ApiError} `400 invalid_body`/`invalid_password`/`current_password_required`,
|
|
435
|
+
* `403 invalid_current_password`.
|
|
436
|
+
*/
|
|
437
|
+
setPassword(input: SetPasswordInput): Promise<void>;
|
|
240
438
|
}
|
|
241
439
|
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../src/console/auth.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../src/console/auth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgEG;AAEH,OAAO,EAAE,KAAK,YAAY,EAAQ,KAAK,cAAc,EAAE,MAAM,YAAY,CAAC;AAE1E;;;;;GAKG;AACH,MAAM,WAAW,QAAQ;IACvB,2BAA2B;IAC3B,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;CAC/D;AAED,qFAAqF;AACrF,MAAM,WAAW,IAAI;IACnB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,qDAAqD;AACrD,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,IAAI,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,wFAAwF;AACxF,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,8EAA8E;IAC9E,aAAa,EAAE,OAAO,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,uFAAuF;AACvF,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,IAA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MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI9C;;;;;;;;;;OAUG;IACG,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAStD;;;;;;;;;;;;;;OAcG;IACG,WAAW,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;CAO1D"}
|
package/dist/src/console/auth.js
CHANGED
|
@@ -43,14 +43,38 @@
|
|
|
43
43
|
* handlers, not assumed) — every method here returns `res.body` directly and
|
|
44
44
|
* never calls this package's `unwrap()` helper.
|
|
45
45
|
*
|
|
46
|
+
* **T1.1.4's seven `/me/*` methods added here (profile, contact
|
|
47
|
+
* change-and-confirm, promote, remove, password).** Registered BELOW the auth
|
|
48
|
+
* guard (`packages/server/packages/api/data/me.ts`'s own doc comment) — every
|
|
49
|
+
* one of the seven is AUTHENTICATED, the default `requireAuth`, unlike
|
|
50
|
+
* `login`/`signup`/`checkAccountSlug` above. `removeContact` and
|
|
51
|
+
* `promoteContact` are not in this task's pinned method list but are added
|
|
52
|
+
* per HITL-7 ("if T1.1.4 ships routes for adding / removing / promoting a
|
|
53
|
+
* secondary contact, they get methods here too") — both routes exist on the
|
|
54
|
+
* merged branch (`data/me.ts:135-154`).
|
|
55
|
+
*
|
|
56
|
+
* **`UserProfile.hasPassword` is a RENAME of the wire's `passwordSet`, not an
|
|
57
|
+
* invented field.** `GET /me/profile` answers `passwordSet` (`data/me.ts:9`,
|
|
58
|
+
* `packages/bll/signup.ts:555`, derived server-side from
|
|
59
|
+
* `password_hash !== null` — the hash itself never appears). HITL-10 needs
|
|
60
|
+
* this fact under a name Studio's "Set a password"/"Change password" fork
|
|
61
|
+
* reads directly; `toUserProfile()` below performs the rename from the exact
|
|
62
|
+
* value the wire sent, never a default and never computed from anything else.
|
|
63
|
+
*
|
|
46
64
|
* @module
|
|
47
65
|
*/
|
|
66
|
+
import { path } from "../http.js";
|
|
67
|
+
/** `passwordSet` → `hasPassword`. The one hop between the wire and {@linkcode UserProfile}. */
|
|
68
|
+
function toUserProfile(wire) {
|
|
69
|
+
const { passwordSet, ...rest } = wire;
|
|
70
|
+
return { ...rest, hasPassword: passwordSet };
|
|
71
|
+
}
|
|
48
72
|
/**
|
|
49
|
-
* The `console.auth` namespace on a `
|
|
73
|
+
* The `console.auth` namespace on a `W6WClient`.
|
|
50
74
|
*
|
|
51
75
|
* @example
|
|
52
76
|
* ```ts
|
|
53
|
-
* const { token } = await client.console.auth.login("user", "pass");
|
|
77
|
+
* const { token } = await client.console.auth.login("user@example.com", "pass");
|
|
54
78
|
* const me = await client.console.auth.getMe();
|
|
55
79
|
* if (me.tenantAdmin) { // tenant-admin surface
|
|
56
80
|
* }
|
|
@@ -70,16 +94,19 @@ export class AuthApi {
|
|
|
70
94
|
* PUBLIC — sends no bearer, even on a client that already holds one
|
|
71
95
|
* (`requireAuth: false`).
|
|
72
96
|
*
|
|
73
|
-
* @param
|
|
97
|
+
* @param identifier - The login identifier, normally the account's email. The
|
|
98
|
+
* platform operator credential (`AUTH_USERNAME`) is NOT email-shaped and is a
|
|
99
|
+
* legitimate value here — never validate this as an email (DECISIONS.md HITL-1).
|
|
100
|
+
* It is sent as the `email` key: the server resolves `body.email ?? body.username`.
|
|
74
101
|
* @param password - The account password.
|
|
75
102
|
* @returns The token, the caller's identity, and the token's lifetime.
|
|
76
103
|
* @throws {ApiError} On any non-2xx, e.g. `401` for invalid credentials.
|
|
77
104
|
*/
|
|
78
|
-
async login(
|
|
105
|
+
async login(identifier, password) {
|
|
79
106
|
const res = await this.#host.request({
|
|
80
107
|
method: "POST",
|
|
81
108
|
path: "/auth/login",
|
|
82
|
-
body: {
|
|
109
|
+
body: { email: identifier, password },
|
|
83
110
|
requireAuth: false,
|
|
84
111
|
});
|
|
85
112
|
return res.body;
|
|
@@ -169,5 +196,128 @@ export class AuthApi {
|
|
|
169
196
|
});
|
|
170
197
|
return res.body;
|
|
171
198
|
}
|
|
199
|
+
/**
|
|
200
|
+
* Read the caller's own profile — the real `users` row, including
|
|
201
|
+
* {@linkcode UserProfile.hasPassword}. Distinct from `getMe()`, which reads
|
|
202
|
+
* session claims: this reads the actual database row (`data/me.ts:43-51`).
|
|
203
|
+
*
|
|
204
|
+
* AUTHENTICATED — the default `requireAuth` applies.
|
|
205
|
+
*
|
|
206
|
+
* @returns The caller's profile.
|
|
207
|
+
* @throws {ApiError} `404 no_user_profile` when there is no `users` row for this principal.
|
|
208
|
+
*/
|
|
209
|
+
async getProfile() {
|
|
210
|
+
const res = await this.#host.request({ method: "GET", path: "/me/profile" });
|
|
211
|
+
return toUserProfile(res.body);
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Patch the caller's display name.
|
|
215
|
+
*
|
|
216
|
+
* AUTHENTICATED — the default `requireAuth` applies.
|
|
217
|
+
*
|
|
218
|
+
* @param input - The new display name.
|
|
219
|
+
* @returns The updated profile (`data/me.ts:53-71`).
|
|
220
|
+
* @throws {ApiError} `400 invalid_body`/`invalid_display_name`.
|
|
221
|
+
*/
|
|
222
|
+
async updateProfile(input) {
|
|
223
|
+
const res = await this.#host.request({
|
|
224
|
+
method: "PATCH",
|
|
225
|
+
path: "/me/profile",
|
|
226
|
+
body: input,
|
|
227
|
+
});
|
|
228
|
+
return toUserProfile(res.body);
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Park a pending email/phone change and send its confirmation code. Does
|
|
232
|
+
* NOT confirm the change — see {@linkcode confirmContactChange}.
|
|
233
|
+
*
|
|
234
|
+
* AUTHENTICATED — the default `requireAuth` applies.
|
|
235
|
+
*
|
|
236
|
+
* @param input - The contact method and the new value.
|
|
237
|
+
* @returns Nothing: the server answers `202` with `{ok: true}`, which carries no information a
|
|
238
|
+
* caller can use (`data/me.ts:73-98`).
|
|
239
|
+
* @throws {ApiError} `400 invalid_body`/`invalid_email`, `409 email_taken`.
|
|
240
|
+
*/
|
|
241
|
+
async requestContactChange(input) {
|
|
242
|
+
await this.#host.request({
|
|
243
|
+
method: "POST",
|
|
244
|
+
path: "/me/contacts/change",
|
|
245
|
+
body: input,
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Consume the code from {@linkcode requestContactChange} and confirm the
|
|
250
|
+
* pending change. Optionally promotes the newly-confirmed contact to
|
|
251
|
+
* primary in the same call (D3).
|
|
252
|
+
*
|
|
253
|
+
* AUTHENTICATED — the default `requireAuth` applies.
|
|
254
|
+
*
|
|
255
|
+
* @param input - The contact method, the code, and an optional promote flag.
|
|
256
|
+
* @returns The updated profile (`data/me.ts:100-133`).
|
|
257
|
+
* @throws {ApiError} `400 invalid_body`/`invalid_code`, `404 contact_not_found`.
|
|
258
|
+
*/
|
|
259
|
+
async confirmContactChange(input) {
|
|
260
|
+
const res = await this.#host.request({
|
|
261
|
+
method: "POST",
|
|
262
|
+
path: "/me/contacts/confirm",
|
|
263
|
+
body: input,
|
|
264
|
+
});
|
|
265
|
+
return toUserProfile(res.body);
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Remove one of the caller's own (non-primary) contacts. Added per HITL-7
|
|
269
|
+
* — `DELETE /me/contacts/:id` exists on the merged branch (`data/me.ts:135-144`).
|
|
270
|
+
*
|
|
271
|
+
* AUTHENTICATED — the default `requireAuth` applies.
|
|
272
|
+
*
|
|
273
|
+
* @param id - The contact id.
|
|
274
|
+
* @returns Nothing: the server answers `{ok: true}`, which carries no information a caller can
|
|
275
|
+
* use, mirroring `console.projects.delete`/`console.schedules.delete` in this same package.
|
|
276
|
+
* @throws {ApiError} `404 contact_not_found`.
|
|
277
|
+
*/
|
|
278
|
+
async removeContact(id) {
|
|
279
|
+
await this.#host.request({ method: "DELETE", path: path `/me/contacts/${id}` });
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Promote one of the caller's own secondary contacts to primary. Added per
|
|
283
|
+
* HITL-7 — `POST /me/contacts/:id/primary` exists on the merged branch
|
|
284
|
+
* (`data/me.ts:146-154`).
|
|
285
|
+
*
|
|
286
|
+
* AUTHENTICATED — the default `requireAuth` applies.
|
|
287
|
+
*
|
|
288
|
+
* @param id - The contact id.
|
|
289
|
+
* @returns The updated profile.
|
|
290
|
+
* @throws {ApiError} `404 contact_not_found`, `403 contact_not_verified`.
|
|
291
|
+
*/
|
|
292
|
+
async promoteContact(id) {
|
|
293
|
+
const res = await this.#host.request({
|
|
294
|
+
method: "POST",
|
|
295
|
+
path: path `/me/contacts/${id}/primary`,
|
|
296
|
+
body: {},
|
|
297
|
+
});
|
|
298
|
+
return toUserProfile(res.body);
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Set or change the caller's password (HITL-10) — one method, since the
|
|
302
|
+
* merged route is the single `POST /me/password`, not two. Omit
|
|
303
|
+
* `currentPassword` for the first-time "set a password" case
|
|
304
|
+
* (`hasPassword: false`); the server requires it once a password already
|
|
305
|
+
* exists.
|
|
306
|
+
*
|
|
307
|
+
* AUTHENTICATED — the default `requireAuth` applies.
|
|
308
|
+
*
|
|
309
|
+
* @param input - The new password, plus the current one when required.
|
|
310
|
+
* @returns Nothing: the server answers `{ok: true}`, which carries no information a caller can
|
|
311
|
+
* use (`data/me.ts:156-184`).
|
|
312
|
+
* @throws {ApiError} `400 invalid_body`/`invalid_password`/`current_password_required`,
|
|
313
|
+
* `403 invalid_current_password`.
|
|
314
|
+
*/
|
|
315
|
+
async setPassword(input) {
|
|
316
|
+
await this.#host.request({
|
|
317
|
+
method: "POST",
|
|
318
|
+
path: "/me/password",
|
|
319
|
+
body: input,
|
|
320
|
+
});
|
|
321
|
+
}
|
|
172
322
|
}
|
|
173
323
|
//# sourceMappingURL=auth.js.map
|