@molecule/api-resource-user 1.8.4 → 1.8.5

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-11-06T17:41:37.981Z
6
+ Generated: 2026-11-06T22:35:09.204Z
7
7
  -->
8
8
 
9
9
  # @molecule/api-resource-user
@@ -66,6 +66,16 @@ res.status(statusCode).send(body)
66
66
  Monkey-patching `res.json` to re-shape a handler's answer intercepts nothing the handler
67
67
  produces, so the request it was meant to answer is left unanswered and hangs.
68
68
 
69
+ **Adapt envelopes with `createRequestHandler(handler, options)` from
70
+ `@molecule/api-resource` 1.1 or newer.** Keep `handlers.create(resource)` and
71
+ `handlers.logIn(resource)` as the handler. `mapRequest: (req) =>
72
+ ({ body: req.body?.account })` unwraps this API's account envelope before the
73
+ existing validation runs. `mapResponse` can return `{ ...result, body }`
74
+ for a successful result; preserve errors, the 206 two-factor response and
75
+ session headers. Both mappings may be async. Read that package's adapter
76
+ example for the full wiring, including early validation responses. Keep
77
+ route rate limits and authorization around the configured wrapper.
78
+
69
79
  **Re-shaping a success answer (RealWorld's `{ user: { …, token } }`, say)? Read the token from
70
80
  `result.body.accessToken` — it is in the BODY.** The `Authorization` response header carries
71
81
  the same token prefixed with the mount's scheme (`Bearer <token>`), so it is not the raw value
@@ -2620,9 +2630,12 @@ token until the cache expires — a check right after logout still answers 200.
2620
2630
  `invalidateDeviceExistsCache(deviceId)` (or `invalidateAllDeviceExistsCache()`) after the
2621
2631
  delete; the built-in log-out route already does.
2622
2632
 
2623
- On the CLIENT, the bearer token is held IN MEMORY only — a `localStorage` copy is
2624
- XSS-exfiltratable and is forbidden. The session is restored after a reload via the
2625
- httpOnly cookie + `GET /users/me`; don't persist the token yourself.
2633
+ On the CLIENT, use the bonded `@molecule/app-auth` client as the session store.
2634
+ `AuthClientConfig.storage` selects persistence. A cookie API can use `storage:
2635
+ 'memory'` and restore through the httpOnly cookie + `GET /users/me`. A header-only
2636
+ API sets no session cookie; the browser client's default or an explicit
2637
+ `createBrowserStorageAdapter()` retains its token across reloads. Keep that
2638
+ choice in the shared auth configuration, rather than adding another token store.
2626
2639
 
2627
2640
  **Client-facing endpoints** (mounted under the app's `/api` prefix → `/api/users/...`).
2628
2641
  The auth CLIENT (`useAuth()` → `login` / `register` / `logout` / `refresh`) already wraps
@@ -2663,8 +2676,9 @@ by one. A box you can't check is an integration bug to fix — not a skip:
2663
2676
  in its payload; never mock the flow or modify production code to expose it.
2664
2677
  - [ ] Logging out and logging back in with the same credentials reaches the same
2665
2678
  account and its data.
2666
- - [ ] The session survives a full page reload (restored via the httpOnly cookie +
2667
- `GET /users/me` — never from a token persisted in localStorage).
2679
+ - [ ] The session survives a full page reload through the configured shared client:
2680
+ a cookie API restores via the httpOnly cookie + `GET /users/me`; a header-only
2681
+ API uses its configured storage adapter.
2668
2682
  - [ ] A wrong password shows a visible error and does NOT authenticate.
2669
2683
  - [ ] Authenticated-only screens are unreachable when logged out (redirect to
2670
2684
  login or an explicit denial — never a blank page).
package/dist/index.d.ts CHANGED
@@ -56,6 +56,16 @@
56
56
  * Monkey-patching `res.json` to re-shape a handler's answer intercepts nothing the handler
57
57
  * produces, so the request it was meant to answer is left unanswered and hangs.
58
58
  *
59
+ * **Adapt envelopes with `createRequestHandler(handler, options)` from
60
+ * `@molecule/api-resource` 1.1 or newer.** Keep `handlers.create(resource)` and
61
+ * `handlers.logIn(resource)` as the handler. `mapRequest: (req) =>
62
+ * ({ body: req.body?.account })` unwraps this API's account envelope before the
63
+ * existing validation runs. `mapResponse` can return `{ ...result, body }`
64
+ * for a successful result; preserve errors, the 206 two-factor response and
65
+ * session headers. Both mappings may be async. Read that package's adapter
66
+ * example for the full wiring, including early validation responses. Keep
67
+ * route rate limits and authorization around the configured wrapper.
68
+ *
59
69
  * **Re-shaping a success answer (RealWorld's `{ user: { …, token } }`, say)? Read the token from
60
70
  * `result.body.accessToken` — it is in the BODY.** The `Authorization` response header carries
61
71
  * the same token prefixed with the mount's scheme (`Bearer <token>`), so it is not the raw value
@@ -234,9 +244,12 @@
234
244
  * `invalidateDeviceExistsCache(deviceId)` (or `invalidateAllDeviceExistsCache()`) after the
235
245
  * delete; the built-in log-out route already does.
236
246
  *
237
- * On the CLIENT, the bearer token is held IN MEMORY only — a `localStorage` copy is
238
- * XSS-exfiltratable and is forbidden. The session is restored after a reload via the
239
- * httpOnly cookie + `GET /users/me`; don't persist the token yourself.
247
+ * On the CLIENT, use the bonded `@molecule/app-auth` client as the session store.
248
+ * `AuthClientConfig.storage` selects persistence. A cookie API can use `storage:
249
+ * 'memory'` and restore through the httpOnly cookie + `GET /users/me`. A header-only
250
+ * API sets no session cookie; the browser client's default or an explicit
251
+ * `createBrowserStorageAdapter()` retains its token across reloads. Keep that
252
+ * choice in the shared auth configuration, rather than adding another token store.
240
253
  *
241
254
  * **Client-facing endpoints** (mounted under the app's `/api` prefix → `/api/users/...`).
242
255
  * The auth CLIENT (`useAuth()` → `login` / `register` / `logout` / `refresh`) already wraps
@@ -289,8 +302,9 @@
289
302
  * in its payload; never mock the flow or modify production code to expose it.
290
303
  * - [ ] Logging out and logging back in with the same credentials reaches the same
291
304
  * account and its data.
292
- * - [ ] The session survives a full page reload (restored via the httpOnly cookie +
293
- * `GET /users/me` — never from a token persisted in localStorage).
305
+ * - [ ] The session survives a full page reload through the configured shared client:
306
+ * a cookie API restores via the httpOnly cookie + `GET /users/me`; a header-only
307
+ * API uses its configured storage adapter.
294
308
  * - [ ] A wrong password shows a visible error and does NOT authenticate.
295
309
  * - [ ] Authenticated-only screens are unreachable when logged out (redirect to
296
310
  * login or an explicit denial — never a blank page).
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2SG;AAEH,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAA;AACnD,OAAO,KAAK,WAAW,MAAM,wBAAwB,CAAA;AACrD,cAAc,oBAAoB,CAAA;AAClC,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAA;AAC/C,cAAc,WAAW,CAAA;AACzB,cAAc,mBAAmB,CAAA;AACjC,cAAc,wBAAwB,CAAA;AACtC,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AACnC,OAAO,KAAK,SAAS,MAAM,sBAAsB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyTG;AAEH,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAA;AACnD,OAAO,KAAK,WAAW,MAAM,wBAAwB,CAAA;AACrD,cAAc,oBAAoB,CAAA;AAClC,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAA;AAC/C,cAAc,WAAW,CAAA;AACzB,cAAc,mBAAmB,CAAA;AACjC,cAAc,wBAAwB,CAAA;AACtC,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,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
@@ -56,6 +56,16 @@
56
56
  * Monkey-patching `res.json` to re-shape a handler's answer intercepts nothing the handler
57
57
  * produces, so the request it was meant to answer is left unanswered and hangs.
58
58
  *
59
+ * **Adapt envelopes with `createRequestHandler(handler, options)` from
60
+ * `@molecule/api-resource` 1.1 or newer.** Keep `handlers.create(resource)` and
61
+ * `handlers.logIn(resource)` as the handler. `mapRequest: (req) =>
62
+ * ({ body: req.body?.account })` unwraps this API's account envelope before the
63
+ * existing validation runs. `mapResponse` can return `{ ...result, body }`
64
+ * for a successful result; preserve errors, the 206 two-factor response and
65
+ * session headers. Both mappings may be async. Read that package's adapter
66
+ * example for the full wiring, including early validation responses. Keep
67
+ * route rate limits and authorization around the configured wrapper.
68
+ *
59
69
  * **Re-shaping a success answer (RealWorld's `{ user: { …, token } }`, say)? Read the token from
60
70
  * `result.body.accessToken` — it is in the BODY.** The `Authorization` response header carries
61
71
  * the same token prefixed with the mount's scheme (`Bearer <token>`), so it is not the raw value
@@ -234,9 +244,12 @@
234
244
  * `invalidateDeviceExistsCache(deviceId)` (or `invalidateAllDeviceExistsCache()`) after the
235
245
  * delete; the built-in log-out route already does.
236
246
  *
237
- * On the CLIENT, the bearer token is held IN MEMORY only — a `localStorage` copy is
238
- * XSS-exfiltratable and is forbidden. The session is restored after a reload via the
239
- * httpOnly cookie + `GET /users/me`; don't persist the token yourself.
247
+ * On the CLIENT, use the bonded `@molecule/app-auth` client as the session store.
248
+ * `AuthClientConfig.storage` selects persistence. A cookie API can use `storage:
249
+ * 'memory'` and restore through the httpOnly cookie + `GET /users/me`. A header-only
250
+ * API sets no session cookie; the browser client's default or an explicit
251
+ * `createBrowserStorageAdapter()` retains its token across reloads. Keep that
252
+ * choice in the shared auth configuration, rather than adding another token store.
240
253
  *
241
254
  * **Client-facing endpoints** (mounted under the app's `/api` prefix → `/api/users/...`).
242
255
  * The auth CLIENT (`useAuth()` → `login` / `register` / `logout` / `refresh`) already wraps
@@ -289,8 +302,9 @@
289
302
  * in its payload; never mock the flow or modify production code to expose it.
290
303
  * - [ ] Logging out and logging back in with the same credentials reaches the same
291
304
  * account and its data.
292
- * - [ ] The session survives a full page reload (restored via the httpOnly cookie +
293
- * `GET /users/me` — never from a token persisted in localStorage).
305
+ * - [ ] The session survives a full page reload through the configured shared client:
306
+ * a cookie API restores via the httpOnly cookie + `GET /users/me`; a header-only
307
+ * API uses its configured storage adapter.
294
308
  * - [ ] A wrong password shows a visible error and does NOT authenticate.
295
309
  * - [ ] Authenticated-only screens are unreachable when logged out (redirect to
296
310
  * login or an explicit denial — never a blank page).
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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CAAA;AACtC,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AACnC,OAAO,KAAK,SAAS,MAAM,sBAAsB,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@molecule/api-resource-user",
3
- "version": "1.8.4",
3
+ "version": "1.8.5",
4
4
  "description": "User resource types and schema for molecule.dev.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",