@molecule/api-resource-user 1.7.4 → 1.8.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 CHANGED
@@ -3,7 +3,7 @@ AUTO-GENERATED — DO NOT EDIT THIS FILE.
3
3
  Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
4
4
  Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
5
5
  To change this document, edit the module-level JSDoc in src/index.ts.
6
- Generated: 2026-10-23T11:01:24.075Z
6
+ Generated: 2026-10-25T22:46:46.920Z
7
7
  -->
8
8
 
9
9
  # @molecule/api-resource-user
@@ -23,35 +23,26 @@ The `user` resource types, schema, and definition.
23
23
  **`usersSecrets.id` IS the user's id — the value of `users.id`, never a fresh uuid.** The DDL
24
24
  declares it `UNIQUE PRIMARY KEY` with no foreign key, so nothing enforces it: a row written
25
25
  under another id is never found again — login answers "invalid credentials" while
26
- `GET /api/users/me` still answers 200. A hand-written signup writes both rows:
27
- `const id = uuid(); await create('users', { ...props, id }); await create('usersSecrets', { id, passwordHash: await hash(password) })`.
28
-
29
- Prefer not to hand-write that — `handlers.create` (signup: both rows, hash via
30
- `@molecule/api-password`, session device), `handlers.logIn` (reads `usersSecrets` by the user's
31
- id), `handlers.updatePassword`, `handlers.forgotPassword` / `handlers.resetPassword`. To touch
32
- one secret yourself use the datastore on the same key — `findById('usersSecrets', userId)` (or
33
- `${tableName}Secrets` for a custom `tableName`) — never SQL.
34
-
35
- **Issuing a session yourself (the sequence is device, then session — two calls, and the first
36
- RETURNS the id):** the middleware accepts both `Authorization: Bearer <jwt>` and
37
- `Authorization: Token <jwt>` (RealWorld's scheme), but only for a token whose `deviceId` names
38
- an ACTIVE row in `devices` — a JWT you `sign()` with an invented `deviceId` is answered 401 on
39
- every route.
40
-
41
- ```typescript
42
- import { get } from '@molecule/api-bond'
43
- import { authorization } from '@molecule/api-resource-user'
44
- import type { DeviceService } from '@molecule/api-resource-device'
45
-
46
- const deviceId = await get<DeviceService>('device')?.createOrUpdate(userId, deviceName)
47
- const token = authorization.set(req, res, { userId, deviceId })
48
- ```
49
-
50
- `get<DeviceService>('device')` is the typed accessor (never hand-type a
51
- `get<{ createOrUpdate(): … }>('device')` generic: a wrong one still compiles and leaves the
52
- field you invented — `device.id` — `undefined`), and `createOrUpdate` RESOLVES TO THE DEVICE ID
53
- STRING, not to a row. `set()` throws when `deviceId` is missing rather than mint a token every
54
- later request answers 401.
26
+ `GET /api/users/me` still answers 200.
27
+
28
+ **Server code that creates accounts — a seed, a migration, a content author, a service
29
+ account — uses `provisionUser`, never hand-written rows.** `provisionUser({ name, tableName },
30
+ { props, password? })` validates the props with the resource schema (once, before the identity
31
+ lookup, so a schema `transform` decides the stored username/email), writes the `users` row and
32
+ its same-id `usersSecrets` row through the bonded providers — in one transaction where the
33
+ database supports one — and returns `{ status: 'created' | 'completed' | 'existing', id, props,
34
+ hasPassword }` with NO device, JWT or session. Omit `password` for a content-only author that
35
+ cannot log in (no `passwordHash` is written). It is idempotent by `username`/`email` and never
36
+ changes an existing account's credentials. Where the bond has no transactions (Cloudflare D1) a
37
+ credential-row failure leaves the user row and answers `{ status: 'partial', id, recovery }`;
38
+ finish it with `provisionUser(..., { props, completeId: id })` — a retry without `completeId`
39
+ answers `existing` and repairs nothing. **TRUSTED SERVER CALLERS ONLY:** it takes props
40
+ directly, so a public endpoint built on it is a mass-assignment hole.
41
+
42
+ For the HTTP path use `handlers.create` (signup), `handlers.logIn`, `handlers.updatePassword`,
43
+ `handlers.forgotPassword` / `handlers.resetPassword`. To touch one secret yourself use the
44
+ datastore on the same key — `findById('usersSecrets', userId)` (or `${tableName}Secrets` for a
45
+ custom `tableName`) — never SQL.
55
46
 
56
47
  **RealWorld-style token API (`Authorization: Token <jwt>`)? CONFIGURATION on this same auth
57
48
  path — never a credentials table of your own** (`usersSecrets.passwordHash` is the password
@@ -116,6 +107,27 @@ answers 400 `resource.error.unknownError` with
116
107
  `TypeError: schema.safeParse is not a function`, and no row is written. Omit `schema`
117
108
  instead of stubbing it.
118
109
 
110
+ **Issuing a session yourself (the sequence is device, then session — two calls, and the first
111
+ RETURNS the id):** the middleware accepts both `Authorization: Bearer <jwt>` and
112
+ `Authorization: Token <jwt>` (RealWorld's scheme), but only for a token whose `deviceId` names
113
+ an ACTIVE row in `devices` — a JWT you `sign()` with an invented `deviceId` is answered 401 on
114
+ every route.
115
+
116
+ ```typescript
117
+ import { get } from '@molecule/api-bond'
118
+ import { authorization } from '@molecule/api-resource-user'
119
+ import type { DeviceService } from '@molecule/api-resource-device'
120
+
121
+ const deviceId = await get<DeviceService>('device')?.createOrUpdate(userId, deviceName)
122
+ const token = authorization.set(req, res, { userId, deviceId })
123
+ ```
124
+
125
+ `get<DeviceService>('device')` is the typed accessor (never hand-type a
126
+ `get<{ createOrUpdate(): … }>('device')` generic: a wrong one still compiles and leaves the
127
+ field you invented — `device.id` — `undefined`), and `createOrUpdate` RESOLVES TO THE DEVICE ID
128
+ STRING, not to a row. `set()` throws when `deviceId` is missing rather than mint a token every
129
+ later request answers 401.
130
+
119
131
  **Exact responses of the sign-up and sign-in handlers** (the body shapes the routes send;
120
132
  a handler returns `{ statusCode, body }` and the mount applies it):
121
133
 
@@ -194,6 +206,37 @@ npm install @molecule/api-resource-user @molecule/api-bond @molecule/api-config
194
206
 
195
207
  ### Interfaces
196
208
 
209
+ #### `ProvisionUserInput`
210
+
211
+ Input accepted by {@link provisionUser}.
212
+
213
+ ```typescript
214
+ interface ProvisionUserInput {
215
+ /**
216
+ * The account's SAFE props (`username`, `name`, `email`, `bio`, …). Validated by the
217
+ * resource schema; never a secret column. At least one of `username` / `email` is required —
218
+ * that pair is what makes repeated provisioning find the account it created.
219
+ */
220
+ props: ProvisionUserProps
221
+ /**
222
+ * Optional plaintext password for an account that must be able to sign in. OMIT it for a
223
+ * content author or service account that must not log in: no hash is written, and `logIn`
224
+ * refuses password authentication for the account. The value is hashed through the bonded
225
+ * password provider and never stored, logged, or returned.
226
+ */
227
+ password?: string
228
+ /**
229
+ * Completes a provisioning that returned `{ status: 'partial' }`: the exact `id` from that
230
+ * result, which is the proof that this caller created the account. The supplied `props` must
231
+ * identify that same account, it must not be OAuth-linked, and it must not already carry a
232
+ * stored password (an existing password is never overwritten). A concurrent completion or a
233
+ * password reset that already wrote a hash is reported as `existing`, never replaced. Omit this
234
+ * for a normal call.
235
+ */
236
+ completeId?: string
237
+ }
238
+ ```
239
+
197
240
  #### `UserRequestHandlerMap`
198
241
 
199
242
  Shape of the user request-handler map produced by `createRequestHandlerMap`.
@@ -239,6 +282,124 @@ interface UserRequestHandlerMap {
239
282
 
240
283
  ### Types
241
284
 
285
+ #### `ProvisionUserProps`
286
+
287
+ Safe user props accepted by {@link provisionUser} — the `users` table's columns without the
288
+ server-controlled `id` / `createdAt` / `updatedAt` (this call sets those).
289
+
290
+ The index signature lets an app pass the extra columns of its OWN resource schema
291
+ (`handlerResource.schema`); the schema still decides what is kept.
292
+
293
+ ```typescript
294
+ type ProvisionUserProps = Omit<types.Props, 'createdAt' | 'id' | 'updatedAt'> &
295
+ Record<string, unknown>
296
+ ```
297
+
298
+ #### `ProvisionUserFailureReason`
299
+
300
+ Why {@link provisionUser} could not complete.
301
+
302
+ ```typescript
303
+ type ProvisionUserFailureReason =
304
+ /** Neither `props.username` nor `props.email` was supplied, so no account can be found on a re-run. */
305
+ | 'identityRequired'
306
+ /** `props.username` breaks the signup rule (letters, digits, dots, hyphens, underscores). */
307
+ | 'invalidUsername'
308
+ /** `password` is outside the signup bounds (8–1024 characters). */
309
+ | 'invalidPassword'
310
+ /** The datastore could not answer "does this account already exist" (or could not read its credentials). */
311
+ | 'lookupFailed'
312
+ /** `username` and `email` resolve to two DIFFERENT existing accounts. */
313
+ | 'conflict'
314
+ /** The props failed the resource schema, so nothing was written. */
315
+ | 'invalidProps'
316
+ /** The `users` insert reported no affected row and no racing account was found. */
317
+ | 'userNotCreated'
318
+ /** The user row was written but its `usersSecrets` row (or the password hash) failed. */
319
+ | 'credentialsFailed'
320
+ /** `completeId` names no account in this resource's table. */
321
+ | 'completeTargetMissing'
322
+ /** The supplied username/email does not identify the account named by `completeId`. */
323
+ | 'completeIdentityMismatch'
324
+ /** The account named by `completeId` has an OAuth identity, so its credentials are not ours to add. */
325
+ | 'completeNotOwned'
326
+ ```
327
+
328
+ #### `ProvisionUserResult`
329
+
330
+ The outcome of a {@link provisionUser} call.
331
+
332
+ `created`, `completed` and `existing` carry the account's id (the value of `usersSecrets.id`)
333
+ and its sanitized `users` row. `partial` says the user row was written and its credential row
334
+ was not; `failed` says the call did not complete (and carries `id` only when a user row it
335
+ wrote may still exist).
336
+
337
+ ```typescript
338
+ type ProvisionUserResult =
339
+ | {
340
+ /** The account was created by this call. */
341
+ status: 'created'
342
+ /** The user id — the same value stored as `usersSecrets.id`. */
343
+ id: string
344
+ /** The sanitized user row (`users` columns; secret columns stripped). */
345
+ props: SafeProps
346
+ /** Whether a password credential was stored for this new account. */
347
+ hasPassword: boolean
348
+ }
349
+ | {
350
+ /** A partial provisioning named by `completeId` was finished by this call. */
351
+ status: 'completed'
352
+ /** The existing account's id. */
353
+ id: string
354
+ /** The existing account's sanitized user row. */
355
+ props: SafeProps
356
+ /** Whether a password credential is stored for the account now. */
357
+ hasPassword: boolean
358
+ }
359
+ | {
360
+ /** The account already existed for the supplied username/email; nothing was written. */
361
+ status: 'existing'
362
+ /** The existing account's id. */
363
+ id: string
364
+ /** The existing account's sanitized user row. */
365
+ props: SafeProps
366
+ /** Whether the EXISTING account has a stored password hash (never the hash itself). */
367
+ hasPassword: boolean
368
+ }
369
+ | {
370
+ /** The user row was written; its credential row was not. */
371
+ status: 'partial'
372
+ /** The step that failed. */
373
+ reason: 'credentialsFailed'
374
+ /** A stable, translated key for the failure (switch on `reason`, not on `error`). */
375
+ errorKey: string
376
+ /** Diagnostic text for the server log — not a client-facing string. */
377
+ error: string
378
+ /** The id of the account this call created. Pass it back as `completeId` to finish it. */
379
+ id: string
380
+ /**
381
+ * What completing the row needs: whether the original call supplied a password (so the
382
+ * caller knows to supply it again — the plaintext was never stored).
383
+ */
384
+ recovery: { id: string; passwordRequired: boolean }
385
+ }
386
+ | {
387
+ /** Provisioning did not complete and left no row this call wrote. */
388
+ status: 'failed'
389
+ /** Which step failed. */
390
+ reason: ProvisionUserFailureReason
391
+ /** A stable, translated key for the failure (switch on `reason`, not on `error`). */
392
+ errorKey: string
393
+ /** Diagnostic text for the server log — not a client-facing string. */
394
+ error: string
395
+ /**
396
+ * Present when a user row this call wrote may still exist, or when this call was completing
397
+ * the account named by `completeId` (so the caller can retry the same id).
398
+ */
399
+ id?: string
400
+ }
401
+ ```
402
+
242
403
  #### `Props`
243
404
 
244
405
  User props type inferred from schema — the row shape of the `users` table, which holds no
@@ -335,6 +496,46 @@ type Session = z.infer<typeof sessionSchema>
335
496
 
336
497
  ### Functions
337
498
 
499
+ #### `provisionUser(resource, input)`
500
+
501
+ Creates a user record and its same-id credential record for a trusted server caller, without
502
+ creating a session.
503
+
504
+ The props are validated ONCE by the resource schema — this package's `propsSchema` unless
505
+ `schema` is supplied — before the existing-account lookup, so any `transform`/`default` in a
506
+ caller's schema decides the stored and the looked-up username/email. The user row and its
507
+ `usersSecrets` row are then written under ONE freshly minted id, inside a transaction when the
508
+ bonded database supports one. With no `password`, the credential row carries no `passwordHash`
509
+ at all — the account cannot log in, and there is no default, generated, or returned password.
510
+
511
+ Existing accounts are found by `username` or `email` and returned unchanged (`status:
512
+ 'existing'`), which makes re-running a seed safe; a supplied password is never applied to an
513
+ existing account. Where the bond has no interactive transactions and the credential write
514
+ fails, the result is `{ status: 'partial', id, recovery }` — pass that id back as `completeId`
515
+ (with the same identity props and the same password) to finish it.
516
+
517
+ Use {@link createResource} when the app constrains or extends user props; omit it otherwise.
518
+ The `tableName` convention is the one every handler in this package uses: the credential table
519
+ is `${tableName}Secrets`.
520
+
521
+ ```typescript
522
+ function provisionUser(
523
+ { name, tableName, schema = propsSchema }: types.HandlerResource,
524
+ { props, password, completeId }: ProvisionUserInput,
525
+ ): Promise<ProvisionUserResult>
526
+ ```
527
+
528
+ - `resource` — The user resource configuration: `{ name, tableName, schema? }`.
529
+ - `resource.name` — The resource name used in error messages.
530
+ - `resource.tableName` — The database table for users.
531
+ - `resource.schema` — Optional schema validated before the write. Defaults to `propsSchema`.
532
+ - `input` — The account to provision.
533
+ - `input.props` — The SAFE user props to store (never a secret column).
534
+ - `input.password` — Optional plaintext password to hash into the credential row. Omit it for a content-only author, which then has no password and cannot log in.
535
+ - `input.completeId` — The id from an earlier `partial` result; finishes that provisioning.
536
+
537
+ **Returns:** `{ status: 'created' | 'completed' | 'existing', id, props, hasPassword }` on success, `{ status: 'partial', reason, errorKey, error, id, recovery }` when a user row was written but its credentials were not, or `{ status: 'failed', reason, errorKey, error, id? }` otherwise.
538
+
338
539
  #### `createRequestHandlerMap(createRequestHandler)`
339
540
 
340
541
  Creates the full request handler map for the User resource.
@@ -490,6 +691,25 @@ Larger avatars must be hosted elsewhere and referenced by URL.
490
691
  const MAX_AVATAR_LENGTH: number
491
692
  ```
492
693
 
694
+ #### `MIN_PASSWORD_LENGTH`
695
+
696
+ Shortest password the package accepts, for signup (`handlers.create`), password changes and
697
+ programmatic provisioning alike — one policy, checked by every write path.
698
+
699
+ ```typescript
700
+ const MIN_PASSWORD_LENGTH: 8
701
+ ```
702
+
703
+ #### `MAX_PASSWORD_LENGTH`
704
+
705
+ Longest password the package accepts (in characters), for signup (`handlers.create`),
706
+ password changes and programmatic provisioning alike. bcrypt reads only the first 72 BYTES,
707
+ so this cap is a request-size bound rather than a strength claim.
708
+
709
+ ```typescript
710
+ const MAX_PASSWORD_LENGTH: 1024
711
+ ```
712
+
493
713
  #### `propsSchema`
494
714
 
495
715
  Default schema for user props.
@@ -1794,7 +2014,7 @@ devices are deleted, so a stolen token on another device dies — but the device
1794
2014
  arrived on stays, and the token that made the request (the `Authorization` header the client
1795
2015
  is holding) keeps working. A RealWorld-style suite changes the password and then keeps using
1796
2016
  the same token for the next request; revoking the caller too is what answered its second
1797
- `PUT /user` with 401 (xr-flash-m167, ~2 min lost). Do not fold a per-user secret into the
2017
+ `PUT /user` with 401. Do not fold a per-user secret into the
1798
2018
 
1799
2019
  _(description truncated — read the full text in `node_modules/@molecule/api-resource-user/dist/handlers/updatePassword.d.ts`.)_
1800
2020
 
@@ -1 +1 @@
1
- {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../src/handlers/create.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAM/E,OAAO,KAAK,KAAK,KAAK,MAAM,aAAa,CAAA;AAQzC,mFAAmF;AACnF,MAAM,WAAW,aAAc,SAAQ,eAAe;IACpD,IAAI,EAAE,KAAK,CAAC,WAAW,GAAG;QACxB,QAAQ,CAAC,EAAE,MAAM,CAAA;QACjB,UAAU,CAAC,EAAE,MAAM,CAAA;KACpB,CAAA;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,MAAM,GAAI,6BAA2C,KAAK,CAAC,eAAe,MAOvE,KAAK,aAAa,EAAE,KAAK,gBAAgB;;;;;aAvBJ,CAAC;;;;;;;;;;;;;;;;EAuQrD,CAAA"}
1
+ {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../src/handlers/create.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAM/E,OAAO,KAAK,KAAK,KAAK,MAAM,aAAa,CAAA;AAQzC,mFAAmF;AACnF,MAAM,WAAW,aAAc,SAAQ,eAAe;IACpD,IAAI,EAAE,KAAK,CAAC,WAAW,GAAG;QACxB,QAAQ,CAAC,EAAE,MAAM,CAAA;QACjB,UAAU,CAAC,EAAE,MAAM,CAAA;KACpB,CAAA;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,MAAM,GAAI,6BAA2C,KAAK,CAAC,eAAe,MAOvE,KAAK,aAAa,EAAE,KAAK,gBAAgB;;;;;aAvB9C,CAAC;;;;;;;;;;;;;;;;EAuQX,CAAA"}
@@ -5,7 +5,7 @@ import { t } from '@molecule/api-i18n';
5
5
  import { hash } from '@molecule/api-password';
6
6
  import { create as resourceCreate } from '@molecule/api-resource';
7
7
  import * as authorization from '../authorization.js';
8
- import { propsSchema } from '../schema.js';
8
+ import { MAX_PASSWORD_LENGTH, MIN_PASSWORD_LENGTH, propsSchema } from '../schema.js';
9
9
  import { normalizeEmail } from '../utilities/normalizeEmail.js';
10
10
  import { stripSensitiveUserColumns } from '../utilities/stripSensitiveUserColumns.js';
11
11
  import { isNestedBody, USERNAME_RE } from '../utilities/username.js';
@@ -97,23 +97,23 @@ export const create = ({ name, tableName, schema = propsSchema }) => {
97
97
  },
98
98
  };
99
99
  }
100
- if (body.password.length > 1024) {
100
+ if (body.password.length > MAX_PASSWORD_LENGTH) {
101
101
  return {
102
102
  statusCode: 400,
103
103
  body: {
104
104
  error: t('user.error.passwordTooLong', undefined, {
105
- defaultValue: 'Password must be at most 1024 characters',
105
+ defaultValue: `Password must be at most ${MAX_PASSWORD_LENGTH} characters`,
106
106
  }),
107
107
  errorKey: 'user.error.passwordTooLong',
108
108
  },
109
109
  };
110
110
  }
111
- if (body.password.length < 8) {
111
+ if (body.password.length < MIN_PASSWORD_LENGTH) {
112
112
  return {
113
113
  statusCode: 400,
114
114
  body: {
115
115
  error: t('user.error.passwordTooShort', undefined, {
116
- defaultValue: 'Password must be at least 8 characters',
116
+ defaultValue: `Password must be at least ${MIN_PASSWORD_LENGTH} characters`,
117
117
  }),
118
118
  errorKey: 'user.error.passwordTooShort',
119
119
  },
@@ -1 +1 @@
1
- {"version":3,"file":"create.js","sourceRoot":"","sources":["../../src/handlers/create.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAA;AA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iBAC9B,CAAC;qBACD,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAA;gBAElB,oEAAoE;gBACpE,iEAAiE;gBACjE,sEAAsE;gBACtE,mEAAmE;gBACnE,MAAM,IAAI,GAAG,yBAAyB,CACpC,CAAC,eAAe,CAAC,IAAI,EAAE,KAAK,IAAI,EAAE,EAAE,EAAE,GAAG,KAAK,EAAE,CAA4B,CAC7E,CAAA;gBACD,OAAO;oBACL,UAAU,EAAE,GAAG;oBACf,IAAI,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE;iBACzC,CAAA;YACH,CAAC;iBAAM,CAAC;gBACN,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAA;YACrD,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;YACnB,OAAO;gBACL,UAAU,EAAE,GAAG;gBACf,IAAI,EAAE;oBACJ,KAAK,EAAE,CAAC,CAAC,kCAAkC,CAAC;oBAC5C,QAAQ,EAAE,kCAAkC;iBAC7C;aACF,CAAA;QACH,CAAC;IACH,CAAC,CAAA;AACH,CAAC,CAAA"}
@@ -27,7 +27,7 @@ export interface UpdatePasswordRequest extends MoleculeRequest {
27
27
  * arrived on stays, and the token that made the request (the `Authorization` header the client
28
28
  * is holding) keeps working. A RealWorld-style suite changes the password and then keeps using
29
29
  * the same token for the next request; revoking the caller too is what answered its second
30
- * `PUT /user` with 401 (xr-flash-m167, ~2 min lost). Do not fold a per-user secret into the
30
+ * `PUT /user` with 401. Do not fold a per-user secret into the
31
31
  * JWT: the device row is the revocation lever. A caller with no session (a handler invoked
32
32
  * outside a request) falls back to revoking every device.
33
33
  * @param resource - The user resource configuration (name, tableName, schema).
@@ -25,7 +25,7 @@ const logger = getLogger();
25
25
  * arrived on stays, and the token that made the request (the `Authorization` header the client
26
26
  * is holding) keeps working. A RealWorld-style suite changes the password and then keeps using
27
27
  * the same token for the next request; revoking the caller too is what answered its second
28
- * `PUT /user` with 401 (xr-flash-m167, ~2 min lost). Do not fold a per-user secret into the
28
+ * `PUT /user` with 401. Do not fold a per-user secret into the
29
29
  * JWT: the device row is the revocation lever. A caller with no session (a handler invoked
30
30
  * outside a request) falls back to revoking every device.
31
31
  * @param resource - The user resource configuration (name, tableName, schema).
package/dist/index.d.ts CHANGED
@@ -13,35 +13,26 @@
13
13
  * **`usersSecrets.id` IS the user's id — the value of `users.id`, never a fresh uuid.** The DDL
14
14
  * declares it `UNIQUE PRIMARY KEY` with no foreign key, so nothing enforces it: a row written
15
15
  * under another id is never found again — login answers "invalid credentials" while
16
- * `GET /api/users/me` still answers 200. A hand-written signup writes both rows:
17
- * `const id = uuid(); await create('users', { ...props, id }); await create('usersSecrets', { id, passwordHash: await hash(password) })`.
18
- *
19
- * Prefer not to hand-write that — `handlers.create` (signup: both rows, hash via
20
- * `@molecule/api-password`, session device), `handlers.logIn` (reads `usersSecrets` by the user's
21
- * id), `handlers.updatePassword`, `handlers.forgotPassword` / `handlers.resetPassword`. To touch
22
- * one secret yourself use the datastore on the same key — `findById('usersSecrets', userId)` (or
23
- * `${tableName}Secrets` for a custom `tableName`) — never SQL.
24
- *
25
- * **Issuing a session yourself (the sequence is device, then session — two calls, and the first
26
- * RETURNS the id):** the middleware accepts both `Authorization: Bearer <jwt>` and
27
- * `Authorization: Token <jwt>` (RealWorld's scheme), but only for a token whose `deviceId` names
28
- * an ACTIVE row in `devices` — a JWT you `sign()` with an invented `deviceId` is answered 401 on
29
- * every route.
30
- *
31
- * ```typescript
32
- * import { get } from '@molecule/api-bond'
33
- * import { authorization } from '@molecule/api-resource-user'
34
- * import type { DeviceService } from '@molecule/api-resource-device'
35
- *
36
- * const deviceId = await get<DeviceService>('device')?.createOrUpdate(userId, deviceName)
37
- * const token = authorization.set(req, res, { userId, deviceId })
38
- * ```
39
- *
40
- * `get<DeviceService>('device')` is the typed accessor (never hand-type a
41
- * `get<{ createOrUpdate(): … }>('device')` generic: a wrong one still compiles and leaves the
42
- * field you invented — `device.id` — `undefined`), and `createOrUpdate` RESOLVES TO THE DEVICE ID
43
- * STRING, not to a row. `set()` throws when `deviceId` is missing rather than mint a token every
44
- * later request answers 401.
16
+ * `GET /api/users/me` still answers 200.
17
+ *
18
+ * **Server code that creates accounts — a seed, a migration, a content author, a service
19
+ * account — uses `provisionUser`, never hand-written rows.** `provisionUser({ name, tableName },
20
+ * { props, password? })` validates the props with the resource schema (once, before the identity
21
+ * lookup, so a schema `transform` decides the stored username/email), writes the `users` row and
22
+ * its same-id `usersSecrets` row through the bonded providers — in one transaction where the
23
+ * database supports one — and returns `{ status: 'created' | 'completed' | 'existing', id, props,
24
+ * hasPassword }` with NO device, JWT or session. Omit `password` for a content-only author that
25
+ * cannot log in (no `passwordHash` is written). It is idempotent by `username`/`email` and never
26
+ * changes an existing account's credentials. Where the bond has no transactions (Cloudflare D1) a
27
+ * credential-row failure leaves the user row and answers `{ status: 'partial', id, recovery }`;
28
+ * finish it with `provisionUser(..., { props, completeId: id })` — a retry without `completeId`
29
+ * answers `existing` and repairs nothing. **TRUSTED SERVER CALLERS ONLY:** it takes props
30
+ * directly, so a public endpoint built on it is a mass-assignment hole.
31
+ *
32
+ * For the HTTP path use `handlers.create` (signup), `handlers.logIn`, `handlers.updatePassword`,
33
+ * `handlers.forgotPassword` / `handlers.resetPassword`. To touch one secret yourself use the
34
+ * datastore on the same key — `findById('usersSecrets', userId)` (or `${tableName}Secrets` for a
35
+ * custom `tableName`) — never SQL.
45
36
  *
46
37
  * **RealWorld-style token API (`Authorization: Token <jwt>`)? CONFIGURATION on this same auth
47
38
  * path — never a credentials table of your own** (`usersSecrets.passwordHash` is the password
@@ -106,6 +97,27 @@
106
97
  * `TypeError: schema.safeParse is not a function`, and no row is written. Omit `schema`
107
98
  * instead of stubbing it.
108
99
  *
100
+ * **Issuing a session yourself (the sequence is device, then session — two calls, and the first
101
+ * RETURNS the id):** the middleware accepts both `Authorization: Bearer <jwt>` and
102
+ * `Authorization: Token <jwt>` (RealWorld's scheme), but only for a token whose `deviceId` names
103
+ * an ACTIVE row in `devices` — a JWT you `sign()` with an invented `deviceId` is answered 401 on
104
+ * every route.
105
+ *
106
+ * ```typescript
107
+ * import { get } from '@molecule/api-bond'
108
+ * import { authorization } from '@molecule/api-resource-user'
109
+ * import type { DeviceService } from '@molecule/api-resource-device'
110
+ *
111
+ * const deviceId = await get<DeviceService>('device')?.createOrUpdate(userId, deviceName)
112
+ * const token = authorization.set(req, res, { userId, deviceId })
113
+ * ```
114
+ *
115
+ * `get<DeviceService>('device')` is the typed accessor (never hand-type a
116
+ * `get<{ createOrUpdate(): … }>('device')` generic: a wrong one still compiles and leaves the
117
+ * field you invented — `device.id` — `undefined`), and `createOrUpdate` RESOLVES TO THE DEVICE ID
118
+ * STRING, not to a row. `set()` throws when `deviceId` is missing rather than mint a token every
119
+ * later request answers 401.
120
+ *
109
121
  * **Exact responses of the sign-up and sign-in handlers** (the body shapes the routes send;
110
122
  * a handler returns `{ statusCode, body }` and the mount applies it):
111
123
  * - `create` (`POST /api/users`, flat body): 201 `{ props, accessToken, user }` (`user` equals
@@ -285,6 +297,7 @@ export * as authorizers from './authorizers/index.js';
285
297
  export * from './browser-guard.js';
286
298
  export * as handlers from './handlers/index.js';
287
299
  export * from './i18n.js';
300
+ export * from './provisioning.js';
288
301
  export * from './requestHandlerMap.js';
289
302
  export * from './resource.js';
290
303
  export * from './routes.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AACnC,OAAO,KAAK,SAAS,MAAM,sBAAsB,CAAA"}
package/dist/index.js CHANGED
@@ -13,35 +13,26 @@
13
13
  * **`usersSecrets.id` IS the user's id — the value of `users.id`, never a fresh uuid.** The DDL
14
14
  * declares it `UNIQUE PRIMARY KEY` with no foreign key, so nothing enforces it: a row written
15
15
  * under another id is never found again — login answers "invalid credentials" while
16
- * `GET /api/users/me` still answers 200. A hand-written signup writes both rows:
17
- * `const id = uuid(); await create('users', { ...props, id }); await create('usersSecrets', { id, passwordHash: await hash(password) })`.
18
- *
19
- * Prefer not to hand-write that — `handlers.create` (signup: both rows, hash via
20
- * `@molecule/api-password`, session device), `handlers.logIn` (reads `usersSecrets` by the user's
21
- * id), `handlers.updatePassword`, `handlers.forgotPassword` / `handlers.resetPassword`. To touch
22
- * one secret yourself use the datastore on the same key — `findById('usersSecrets', userId)` (or
23
- * `${tableName}Secrets` for a custom `tableName`) — never SQL.
24
- *
25
- * **Issuing a session yourself (the sequence is device, then session — two calls, and the first
26
- * RETURNS the id):** the middleware accepts both `Authorization: Bearer <jwt>` and
27
- * `Authorization: Token <jwt>` (RealWorld's scheme), but only for a token whose `deviceId` names
28
- * an ACTIVE row in `devices` — a JWT you `sign()` with an invented `deviceId` is answered 401 on
29
- * every route.
30
- *
31
- * ```typescript
32
- * import { get } from '@molecule/api-bond'
33
- * import { authorization } from '@molecule/api-resource-user'
34
- * import type { DeviceService } from '@molecule/api-resource-device'
35
- *
36
- * const deviceId = await get<DeviceService>('device')?.createOrUpdate(userId, deviceName)
37
- * const token = authorization.set(req, res, { userId, deviceId })
38
- * ```
39
- *
40
- * `get<DeviceService>('device')` is the typed accessor (never hand-type a
41
- * `get<{ createOrUpdate(): … }>('device')` generic: a wrong one still compiles and leaves the
42
- * field you invented — `device.id` — `undefined`), and `createOrUpdate` RESOLVES TO THE DEVICE ID
43
- * STRING, not to a row. `set()` throws when `deviceId` is missing rather than mint a token every
44
- * later request answers 401.
16
+ * `GET /api/users/me` still answers 200.
17
+ *
18
+ * **Server code that creates accounts — a seed, a migration, a content author, a service
19
+ * account — uses `provisionUser`, never hand-written rows.** `provisionUser({ name, tableName },
20
+ * { props, password? })` validates the props with the resource schema (once, before the identity
21
+ * lookup, so a schema `transform` decides the stored username/email), writes the `users` row and
22
+ * its same-id `usersSecrets` row through the bonded providers — in one transaction where the
23
+ * database supports one — and returns `{ status: 'created' | 'completed' | 'existing', id, props,
24
+ * hasPassword }` with NO device, JWT or session. Omit `password` for a content-only author that
25
+ * cannot log in (no `passwordHash` is written). It is idempotent by `username`/`email` and never
26
+ * changes an existing account's credentials. Where the bond has no transactions (Cloudflare D1) a
27
+ * credential-row failure leaves the user row and answers `{ status: 'partial', id, recovery }`;
28
+ * finish it with `provisionUser(..., { props, completeId: id })` — a retry without `completeId`
29
+ * answers `existing` and repairs nothing. **TRUSTED SERVER CALLERS ONLY:** it takes props
30
+ * directly, so a public endpoint built on it is a mass-assignment hole.
31
+ *
32
+ * For the HTTP path use `handlers.create` (signup), `handlers.logIn`, `handlers.updatePassword`,
33
+ * `handlers.forgotPassword` / `handlers.resetPassword`. To touch one secret yourself use the
34
+ * datastore on the same key — `findById('usersSecrets', userId)` (or `${tableName}Secrets` for a
35
+ * custom `tableName`) — never SQL.
45
36
  *
46
37
  * **RealWorld-style token API (`Authorization: Token <jwt>`)? CONFIGURATION on this same auth
47
38
  * path — never a credentials table of your own** (`usersSecrets.passwordHash` is the password
@@ -106,6 +97,27 @@
106
97
  * `TypeError: schema.safeParse is not a function`, and no row is written. Omit `schema`
107
98
  * instead of stubbing it.
108
99
  *
100
+ * **Issuing a session yourself (the sequence is device, then session — two calls, and the first
101
+ * RETURNS the id):** the middleware accepts both `Authorization: Bearer <jwt>` and
102
+ * `Authorization: Token <jwt>` (RealWorld's scheme), but only for a token whose `deviceId` names
103
+ * an ACTIVE row in `devices` — a JWT you `sign()` with an invented `deviceId` is answered 401 on
104
+ * every route.
105
+ *
106
+ * ```typescript
107
+ * import { get } from '@molecule/api-bond'
108
+ * import { authorization } from '@molecule/api-resource-user'
109
+ * import type { DeviceService } from '@molecule/api-resource-device'
110
+ *
111
+ * const deviceId = await get<DeviceService>('device')?.createOrUpdate(userId, deviceName)
112
+ * const token = authorization.set(req, res, { userId, deviceId })
113
+ * ```
114
+ *
115
+ * `get<DeviceService>('device')` is the typed accessor (never hand-type a
116
+ * `get<{ createOrUpdate(): … }>('device')` generic: a wrong one still compiles and leaves the
117
+ * field you invented — `device.id` — `undefined`), and `createOrUpdate` RESOLVES TO THE DEVICE ID
118
+ * STRING, not to a row. `set()` throws when `deviceId` is missing rather than mint a token every
119
+ * later request answers 401.
120
+ *
109
121
  * **Exact responses of the sign-up and sign-in handlers** (the body shapes the routes send;
110
122
  * a handler returns `{ statusCode, body }` and the mount applies it):
111
123
  * - `create` (`POST /api/users`, flat body): 201 `{ props, accessToken, user }` (`user` equals
@@ -285,6 +297,7 @@ export * as authorizers from './authorizers/index.js';
285
297
  export * from './browser-guard.js';
286
298
  export * as handlers from './handlers/index.js';
287
299
  export * from './i18n.js';
300
+ export * from './provisioning.js';
288
301
  export * from './requestHandlerMap.js';
289
302
  export * from './resource.js';
290
303
  export * from './routes.js';