@molecule/api-resource-user 1.11.0 → 1.11.2
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 +26 -17
- package/dist/handlers/readSelf.d.ts +3 -1
- package/dist/handlers/readSelf.d.ts.map +1 -1
- package/dist/handlers/readSelf.js +5 -2
- package/dist/handlers/readSelf.js.map +1 -1
- package/dist/index.d.ts +13 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -5
- package/dist/index.js.map +1 -1
- package/dist/routes.d.ts +6 -0
- package/dist/routes.d.ts.map +1 -1
- package/dist/routes.js +7 -0
- package/dist/routes.js.map +1 -1
- package/dist/scaffold-router.d.ts +5 -1
- package/dist/scaffold-router.d.ts.map +1 -1
- package/dist/scaffold-router.js +9 -5
- package/dist/scaffold-router.js.map +1 -1
- package/package.json +2 -2
- package/src/scaffold-router.ts +28 -18
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-
|
|
6
|
+
Generated: 2026-11-24T08:40:50.887Z
|
|
7
7
|
-->
|
|
8
8
|
|
|
9
9
|
# @molecule/api-resource-user
|
|
@@ -208,6 +208,10 @@ changes through the auth pages (`useAuth()`). There is no supported bypass to ad
|
|
|
208
208
|
## Quick Start
|
|
209
209
|
|
|
210
210
|
```ts
|
|
211
|
+
// The routes it mounts (under /api) answer:
|
|
212
|
+
// POST /users, POST /users/log-in → { props, accessToken, user }; bad credentials → 403, not 401
|
|
213
|
+
// GET /users/me → { props, user }; signed out → 401
|
|
214
|
+
|
|
211
215
|
// Extend safely: a display field in Props, a secret in SecretProps.
|
|
212
216
|
// propsSchema: { …, timezone: z.string().optional() } // safe → client
|
|
213
217
|
// secretPropsSchema: { …, passwordResetToken: z.string().optional() } // server-only, usersSecrets
|
|
@@ -228,7 +232,7 @@ router.get('/me/timezone', async (req, res) => {
|
|
|
228
232
|
## Installation
|
|
229
233
|
|
|
230
234
|
```bash
|
|
231
|
-
npm install @molecule/api-resource-user @molecule/api-bond @molecule/api-config @molecule/api-database @molecule/api-
|
|
235
|
+
npm install @molecule/api-resource-user @molecule/api-bond @molecule/api-config @molecule/api-database @molecule/api-i18n @molecule/api-jwt @molecule/api-locales-user @molecule/api-locales-user-payments @molecule/api-password @molecule/api-rate-limit @molecule/api-resource @molecule/api-resource-device @molecule/api-secrets express uuid zod
|
|
232
236
|
npm install -D @types/express
|
|
233
237
|
```
|
|
234
238
|
|
|
@@ -974,6 +978,7 @@ const routes: (
|
|
|
974
978
|
| { method: 'get'; path: string; middlewares: string[]; handler: string; optional?: undefined }
|
|
975
979
|
| { method: 'patch'; path: string; middlewares: string[]; handler: string; optional?: undefined }
|
|
976
980
|
| { method: 'delete'; path: string; middlewares: string[]; handler: string; optional?: undefined }
|
|
981
|
+
| { method: 'patch'; path: string; middlewares: string[]; handler: string; optional: string }
|
|
977
982
|
)[]
|
|
978
983
|
```
|
|
979
984
|
|
|
@@ -2222,9 +2227,9 @@ function readSelf({
|
|
|
2222
2227
|
```
|
|
2223
2228
|
|
|
2224
2229
|
- `resource` — The user resource configuration: `{ name, tableName, schema? }` (`name` and `schema` are optional here).
|
|
2225
|
-
- `resource.tableName` — The database table name for users.
|
|
2230
|
+
- `resource.tableName` — The database table name for users. The user comes back as both `props` and `user` (the same object), the shape sign-up and log-in answer with, so one reader serves all three.
|
|
2226
2231
|
|
|
2227
|
-
**Returns:** A request handler responding `{ statusCode: 200, body: { props, plan?, twoFactorEnabled?, accessToken? } }`, or 401 when unauthenticated.
|
|
2232
|
+
**Returns:** A request handler responding `{ statusCode: 200, body: { props, user, plan?, twoFactorEnabled?, accessToken? } }`, or 401 when unauthenticated.
|
|
2228
2233
|
|
|
2229
2234
|
##### `handlers.RESET_TOKEN_TTL_MS`
|
|
2230
2235
|
|
|
@@ -2833,19 +2838,19 @@ Peer dependencies:
|
|
|
2833
2838
|
- `@molecule/api-bond` ^1.0.1
|
|
2834
2839
|
- `@molecule/api-config` ^1.0.1
|
|
2835
2840
|
- `@molecule/api-database` ^1.2.2
|
|
2836
|
-
- `@molecule/api-entitlements` ^1.0.1
|
|
2841
|
+
- `@molecule/api-entitlements` ^1.0.1 _(optional)_
|
|
2837
2842
|
- `@molecule/api-i18n` ^1.0.1
|
|
2838
2843
|
- `@molecule/api-jwt` ^1.0.1
|
|
2839
2844
|
- `@molecule/api-locales-user` ^1.0.1
|
|
2840
2845
|
- `@molecule/api-locales-user-payments` ^1.0.1
|
|
2841
2846
|
- `@molecule/api-password` ^1.0.1
|
|
2842
|
-
- `@molecule/api-payments` ^1.1.0
|
|
2843
|
-
- `@molecule/api-push-notifications` ^1.0.1
|
|
2847
|
+
- `@molecule/api-payments` ^1.1.0 _(optional)_
|
|
2848
|
+
- `@molecule/api-push-notifications` ^1.0.1 _(optional)_
|
|
2844
2849
|
- `@molecule/api-rate-limit` ^1.0.1
|
|
2845
2850
|
- `@molecule/api-resource` ^1.0.1
|
|
2846
2851
|
- `@molecule/api-resource-device` ^1.1.4
|
|
2847
2852
|
- `@molecule/api-secrets` ^1.0.1
|
|
2848
|
-
- `@molecule/api-two-factor` ^1.0.1
|
|
2853
|
+
- `@molecule/api-two-factor` ^1.0.1 _(optional)_
|
|
2849
2854
|
- `express` ^5.0.0
|
|
2850
2855
|
|
|
2851
2856
|
### Environment Variables
|
|
@@ -2860,19 +2865,19 @@ Peer dependencies:
|
|
|
2860
2865
|
- `@molecule/api-bond`
|
|
2861
2866
|
- `@molecule/api-config`
|
|
2862
2867
|
- `@molecule/api-database`
|
|
2863
|
-
- `@molecule/api-entitlements`
|
|
2868
|
+
- `@molecule/api-entitlements` _(optional)_
|
|
2864
2869
|
- `@molecule/api-i18n`
|
|
2865
2870
|
- `@molecule/api-jwt`
|
|
2866
2871
|
- `@molecule/api-locales-user`
|
|
2867
2872
|
- `@molecule/api-locales-user-payments`
|
|
2868
2873
|
- `@molecule/api-password`
|
|
2869
|
-
- `@molecule/api-payments`
|
|
2870
|
-
- `@molecule/api-push-notifications`
|
|
2874
|
+
- `@molecule/api-payments` _(optional)_
|
|
2875
|
+
- `@molecule/api-push-notifications` _(optional)_
|
|
2871
2876
|
- `@molecule/api-rate-limit`
|
|
2872
2877
|
- `@molecule/api-resource`
|
|
2873
2878
|
- `@molecule/api-resource-device`
|
|
2874
2879
|
- `@molecule/api-secrets`
|
|
2875
|
-
- `@molecule/api-two-factor`
|
|
2880
|
+
- `@molecule/api-two-factor` _(optional)_
|
|
2876
2881
|
- `express`
|
|
2877
2882
|
- `uuid`
|
|
2878
2883
|
- `zod`
|
|
@@ -2965,13 +2970,16 @@ login / signup / logout — do NOT hand-roll those against the raw routes. The r
|
|
|
2965
2970
|
client method; call them with raw `http.*`. Use these EXACT paths — a weak model guesses
|
|
2966
2971
|
`/api/auth/*` or `/api/user` (singular), and neither exists:
|
|
2967
2972
|
|
|
2968
|
-
- `POST /api/users/forgot-password` — request a reset email (body `{ email }`)
|
|
2969
|
-
|
|
2970
|
-
|
|
2973
|
+
- `POST /api/users/forgot-password` — request a reset email (body `{ email }`) · `POST
|
|
2974
|
+
/api/users/reset-password` — confirm with the emailed token (body `{ token, password }`).
|
|
2975
|
+
A scaffold mounts these two (`emailsRouter`) only with an email provider; mounted without
|
|
2976
|
+
one, forgot-password answers 501 `user.error.passwordResetUnavailable`
|
|
2971
2977
|
- `PATCH /api/users/:id` — update profile fields (name, username, email, bio); NOT `PUT /api/user`
|
|
2972
2978
|
- `PATCH /api/users/:id/password` — change password · `DELETE /api/users/:id` — delete account
|
|
2973
2979
|
- `PATCH /api/users/:id/plan` — update the subscription plan (a paid plan with no
|
|
2974
|
-
existing subscription answers 201 `{ checkoutUrl }`; send the browser there)
|
|
2980
|
+
existing subscription answers 201 `{ checkoutUrl }`; send the browser there). This and
|
|
2981
|
+
the two payment routes below come with a payments provider (`paymentsRouter`), and
|
|
2982
|
+
`POST /api/users/:id/verify-two-factor` with a two-factor provider (`twoFactorRouter`)
|
|
2975
2983
|
- `POST /api/users/:id/verify-payment/:provider` — confirm a purchase server-side
|
|
2976
2984
|
(body/query `subscriptionId`); the provider returns the buyer to the APP's
|
|
2977
2985
|
`/plan-updated?provider=…&sessionId=…`, and THAT page calls this from the app
|
|
@@ -2982,7 +2990,8 @@ client method; call them with raw `http.*`. Use these EXACT paths — a weak mod
|
|
|
2982
2990
|
billing portal (update card, invoices, cancel); responds `{ url }`, optional body
|
|
2983
2991
|
`{ returnPath }` to come back to a specific app page. 404 `user.payment.noBillingAccount`
|
|
2984
2992
|
when the user has no customer record yet
|
|
2985
|
-
- `GET /api/users/me` — the current user (session restore)
|
|
2993
|
+
- `GET /api/users/me` — the current user `{ props, user }` (session restore), 401 when signed
|
|
2994
|
+
out · `GET /api/users/:id` — read one
|
|
2986
2995
|
The full, authoritative route list is the `routes` export (see `routes.ts`).
|
|
2987
2996
|
|
|
2988
2997
|
## E2E Tests
|
|
@@ -21,7 +21,9 @@ import type * as types from '../types.js';
|
|
|
21
21
|
* NEVER gets this field: exposing that token to JavaScript would defeat the cookie.
|
|
22
22
|
* @param resource - The user resource configuration: `{ name, tableName, schema? }` (`name` and `schema` are optional here).
|
|
23
23
|
* @param resource.tableName - The database table name for users.
|
|
24
|
-
*
|
|
24
|
+
* The user comes back as both `props` and `user` (the same object), the shape sign-up and log-in
|
|
25
|
+
* answer with, so one reader serves all three.
|
|
26
|
+
* @returns A request handler responding `{ statusCode: 200, body: { props, user, plan?, twoFactorEnabled?, accessToken? } }`, or 401 when unauthenticated.
|
|
25
27
|
*/
|
|
26
28
|
export declare const readSelf: ({ tableName }: types.HandlerResource) => (_req: MoleculeRequest, res: MoleculeResponse) => Promise<{
|
|
27
29
|
statusCode: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readSelf.d.ts","sourceRoot":"","sources":["../../src/handlers/readSelf.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAG/E,OAAO,KAAK,KAAK,KAAK,MAAM,aAAa,CAAA;AAMzC
|
|
1
|
+
{"version":3,"file":"readSelf.d.ts","sourceRoot":"","sources":["../../src/handlers/readSelf.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAG/E,OAAO,KAAK,KAAK,KAAK,MAAM,aAAa,CAAA;AAMzC;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,QAAQ,GAAI,eAAe,KAAK,CAAC,eAAe,MAC7C,MAAM,eAAe,EAAE,KAAK,gBAAgB;;;EA8D3D,CAAA"}
|
|
@@ -26,7 +26,9 @@ const logger = getLogger();
|
|
|
26
26
|
* NEVER gets this field: exposing that token to JavaScript would defeat the cookie.
|
|
27
27
|
* @param resource - The user resource configuration: `{ name, tableName, schema? }` (`name` and `schema` are optional here).
|
|
28
28
|
* @param resource.tableName - The database table name for users.
|
|
29
|
-
*
|
|
29
|
+
* The user comes back as both `props` and `user` (the same object), the shape sign-up and log-in
|
|
30
|
+
* answer with, so one reader serves all three.
|
|
31
|
+
* @returns A request handler responding `{ statusCode: 200, body: { props, user, plan?, twoFactorEnabled?, accessToken? } }`, or 401 when unauthenticated.
|
|
30
32
|
*/
|
|
31
33
|
export const readSelf = ({ tableName }) => {
|
|
32
34
|
return async (_req, res) => {
|
|
@@ -55,7 +57,8 @@ export const readSelf = ({ tableName }) => {
|
|
|
55
57
|
};
|
|
56
58
|
}
|
|
57
59
|
const plan = await getPlan(user);
|
|
58
|
-
const
|
|
60
|
+
const props = stripSensitiveUserColumns(user);
|
|
61
|
+
const body = { props, user: props };
|
|
59
62
|
if (plan) {
|
|
60
63
|
body.plan = plan;
|
|
61
64
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readSelf.js","sourceRoot":"","sources":["../../src/handlers/readSelf.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAA;AACjD,OAAO,EAAE,CAAC,EAAE,MAAM,oBAAoB,CAAA;AAGtC,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAA;AAE3D,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAA;AACjD,OAAO,EAAE,yBAAyB,EAAE,MAAM,2CAA2C,CAAA;AAErF,MAAM,MAAM,GAAG,SAAS,EAAE,CAAA;AAE1B
|
|
1
|
+
{"version":3,"file":"readSelf.js","sourceRoot":"","sources":["../../src/handlers/readSelf.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAA;AACjD,OAAO,EAAE,CAAC,EAAE,MAAM,oBAAoB,CAAA;AAGtC,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAA;AAE3D,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAA;AACjD,OAAO,EAAE,yBAAyB,EAAE,MAAM,2CAA2C,CAAA;AAErF,MAAM,MAAM,GAAG,SAAS,EAAE,CAAA;AAE1B;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,EAAE,SAAS,EAAyB,EAAE,EAAE;IAC/D,OAAO,KAAK,EAAE,IAAqB,EAAE,GAAqB,EAAE,EAAE;QAC5D,IAAI,CAAC;YACH,MAAM,MAAM,GAAI,GAAG,CAAC,MAAM,CAAC,OAA2C,EAAE,MAAM,CAAA;YAC9E,IAAI,CAAC,MAAM,EAAE,CAA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AAC,gBAAgB,GAAG,IAAI,CAAC,gBAAgB,IAAI,KAAK,CAAA;oBACtD,IAAI,CAAC,mBAAmB,GAAG,OAAO,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAA;gBACpE,CAAC;YACH,CAAC;YAAC,OAAO,MAAM,EAAE,CAAC;gBAChB,2EAA2E;gBAC3E,qDAAqD;YACvD,CAAC;YAED,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,EAAE,CAAA;QAClC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;YACnB,OAAO;gBACL,UAAU,EAAE,GAAG;gBACf,IAAI,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,6BAA6B,CAAC,EAAE,QAAQ,EAAE,6BAA6B,EAAE;aAC3F,CAAA;QACH,CAAC;IACH,CAAC,CAAA;AACH,CAAC,CAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -277,13 +277,16 @@
|
|
|
277
277
|
* login / signup / logout — do NOT hand-roll those against the raw routes. The rest have NO
|
|
278
278
|
* client method; call them with raw `http.*`. Use these EXACT paths — a weak model guesses
|
|
279
279
|
* `/api/auth/*` or `/api/user` (singular), and neither exists:
|
|
280
|
-
* - `POST /api/users/forgot-password` — request a reset email (body `{ email }`)
|
|
281
|
-
* `
|
|
282
|
-
*
|
|
280
|
+
* - `POST /api/users/forgot-password` — request a reset email (body `{ email }`) · `POST
|
|
281
|
+
* /api/users/reset-password` — confirm with the emailed token (body `{ token, password }`).
|
|
282
|
+
* A scaffold mounts these two (`emailsRouter`) only with an email provider; mounted without
|
|
283
|
+
* one, forgot-password answers 501 `user.error.passwordResetUnavailable`
|
|
283
284
|
* - `PATCH /api/users/:id` — update profile fields (name, username, email, bio); NOT `PUT /api/user`
|
|
284
285
|
* - `PATCH /api/users/:id/password` — change password · `DELETE /api/users/:id` — delete account
|
|
285
286
|
* - `PATCH /api/users/:id/plan` — update the subscription plan (a paid plan with no
|
|
286
|
-
* existing subscription answers 201 `{ checkoutUrl }`; send the browser there)
|
|
287
|
+
* existing subscription answers 201 `{ checkoutUrl }`; send the browser there). This and
|
|
288
|
+
* the two payment routes below come with a payments provider (`paymentsRouter`), and
|
|
289
|
+
* `POST /api/users/:id/verify-two-factor` with a two-factor provider (`twoFactorRouter`)
|
|
287
290
|
* - `POST /api/users/:id/verify-payment/:provider` — confirm a purchase server-side
|
|
288
291
|
* (body/query `subscriptionId`); the provider returns the buyer to the APP's
|
|
289
292
|
* `/plan-updated?provider=…&sessionId=…`, and THAT page calls this from the app
|
|
@@ -294,11 +297,16 @@
|
|
|
294
297
|
* billing portal (update card, invoices, cancel); responds `{ url }`, optional body
|
|
295
298
|
* `{ returnPath }` to come back to a specific app page. 404 `user.payment.noBillingAccount`
|
|
296
299
|
* when the user has no customer record yet
|
|
297
|
-
* - `GET /api/users/me` — the current user (session restore)
|
|
300
|
+
* - `GET /api/users/me` — the current user `{ props, user }` (session restore), 401 when signed
|
|
301
|
+
* out · `GET /api/users/:id` — read one
|
|
298
302
|
* The full, authoritative route list is the `routes` export (see `routes.ts`).
|
|
299
303
|
*
|
|
300
304
|
* @example
|
|
301
305
|
* ```ts
|
|
306
|
+
* // The routes it mounts (under /api) answer:
|
|
307
|
+
* // POST /users, POST /users/log-in → { props, accessToken, user }; bad credentials → 403, not 401
|
|
308
|
+
* // GET /users/me → { props, user }; signed out → 401
|
|
309
|
+
*
|
|
302
310
|
* // Extend safely: a display field in Props, a secret in SecretProps.
|
|
303
311
|
* // propsSchema: { …, timezone: z.string().optional() } // safe → client
|
|
304
312
|
* // secretPropsSchema: { …, passwordResetToken: z.string().optional() } // server-only, usersSecrets
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6VG;AAEH,cAAc,eAAe,CAAA;AAC7B,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,eAAe,CAAA;AAC7B,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
|
@@ -277,13 +277,16 @@
|
|
|
277
277
|
* login / signup / logout — do NOT hand-roll those against the raw routes. The rest have NO
|
|
278
278
|
* client method; call them with raw `http.*`. Use these EXACT paths — a weak model guesses
|
|
279
279
|
* `/api/auth/*` or `/api/user` (singular), and neither exists:
|
|
280
|
-
* - `POST /api/users/forgot-password` — request a reset email (body `{ email }`)
|
|
281
|
-
* `
|
|
282
|
-
*
|
|
280
|
+
* - `POST /api/users/forgot-password` — request a reset email (body `{ email }`) · `POST
|
|
281
|
+
* /api/users/reset-password` — confirm with the emailed token (body `{ token, password }`).
|
|
282
|
+
* A scaffold mounts these two (`emailsRouter`) only with an email provider; mounted without
|
|
283
|
+
* one, forgot-password answers 501 `user.error.passwordResetUnavailable`
|
|
283
284
|
* - `PATCH /api/users/:id` — update profile fields (name, username, email, bio); NOT `PUT /api/user`
|
|
284
285
|
* - `PATCH /api/users/:id/password` — change password · `DELETE /api/users/:id` — delete account
|
|
285
286
|
* - `PATCH /api/users/:id/plan` — update the subscription plan (a paid plan with no
|
|
286
|
-
* existing subscription answers 201 `{ checkoutUrl }`; send the browser there)
|
|
287
|
+
* existing subscription answers 201 `{ checkoutUrl }`; send the browser there). This and
|
|
288
|
+
* the two payment routes below come with a payments provider (`paymentsRouter`), and
|
|
289
|
+
* `POST /api/users/:id/verify-two-factor` with a two-factor provider (`twoFactorRouter`)
|
|
287
290
|
* - `POST /api/users/:id/verify-payment/:provider` — confirm a purchase server-side
|
|
288
291
|
* (body/query `subscriptionId`); the provider returns the buyer to the APP's
|
|
289
292
|
* `/plan-updated?provider=…&sessionId=…`, and THAT page calls this from the app
|
|
@@ -294,11 +297,16 @@
|
|
|
294
297
|
* billing portal (update card, invoices, cancel); responds `{ url }`, optional body
|
|
295
298
|
* `{ returnPath }` to come back to a specific app page. 404 `user.payment.noBillingAccount`
|
|
296
299
|
* when the user has no customer record yet
|
|
297
|
-
* - `GET /api/users/me` — the current user (session restore)
|
|
300
|
+
* - `GET /api/users/me` — the current user `{ props, user }` (session restore), 401 when signed
|
|
301
|
+
* out · `GET /api/users/:id` — read one
|
|
298
302
|
* The full, authoritative route list is the `routes` export (see `routes.ts`).
|
|
299
303
|
*
|
|
300
304
|
* @example
|
|
301
305
|
* ```ts
|
|
306
|
+
* // The routes it mounts (under /api) answer:
|
|
307
|
+
* // POST /users, POST /users/log-in → { props, accessToken, user }; bad credentials → 403, not 401
|
|
308
|
+
* // GET /users/me → { props, user }; signed out → 401
|
|
309
|
+
*
|
|
302
310
|
* // Extend safely: a display field in Props, a secret in SecretProps.
|
|
303
311
|
* // propsSchema: { …, timezone: z.string().optional() } // safe → client
|
|
304
312
|
* // secretPropsSchema: { …, passwordResetToken: z.string().optional() } // server-only, usersSecrets
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6VG;AAEH,cAAc,eAAe,CAAA;AAC7B,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,eAAe,CAAA;AAC7B,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/routes.d.ts
CHANGED
|
@@ -40,5 +40,11 @@ export declare const routes: ({
|
|
|
40
40
|
middlewares: string[];
|
|
41
41
|
handler: string;
|
|
42
42
|
optional?: undefined;
|
|
43
|
+
} | {
|
|
44
|
+
method: "patch";
|
|
45
|
+
path: string;
|
|
46
|
+
middlewares: string[];
|
|
47
|
+
handler: string;
|
|
48
|
+
optional: string;
|
|
43
49
|
})[];
|
|
44
50
|
//# sourceMappingURL=routes.d.ts.map
|
package/dist/routes.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,MAAM
|
|
1
|
+
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAwIlB,CAAA"}
|
package/dist/routes.js
CHANGED
|
@@ -42,17 +42,21 @@ export const routes = [
|
|
|
42
42
|
// `:id`. [M1-1] under the in-memory-token model logout MUST clear the httpOnly
|
|
43
43
|
// cookie, else cookie-restore re-logs-in on the next load.
|
|
44
44
|
{ method: 'post', path: '/users/logout', middlewares: ['auth'], handler: 'logout' },
|
|
45
|
+
// Password reset by email — the reset link is sent by the bonded email transport, so
|
|
46
|
+
// these routes come with one ('emails'): without it forgot-password can only answer 501.
|
|
45
47
|
{
|
|
46
48
|
method: 'post',
|
|
47
49
|
path: '/users/forgot-password',
|
|
48
50
|
middlewares: ['rateLimitAuth'],
|
|
49
51
|
handler: 'forgotPassword',
|
|
52
|
+
optional: 'emails',
|
|
50
53
|
},
|
|
51
54
|
{
|
|
52
55
|
method: 'post',
|
|
53
56
|
path: '/users/reset-password',
|
|
54
57
|
middlewares: ['rateLimitAuth'],
|
|
55
58
|
handler: 'resetPassword',
|
|
59
|
+
optional: 'emails',
|
|
56
60
|
},
|
|
57
61
|
// Current user — session restore. MUST precede `/users/:id` so `me` isn't
|
|
58
62
|
// matched as an `:id`. Cookie-authed (`auth`, not `authSelf` — there is no
|
|
@@ -76,6 +80,8 @@ export const routes = [
|
|
|
76
80
|
path: '/users/:id/verify-two-factor',
|
|
77
81
|
middlewares: ['authSelf', 'rateLimitTwoFactor'],
|
|
78
82
|
handler: 'verifyTwoFactor',
|
|
83
|
+
// Set-up and checks go through the bonded two-factor provider (@molecule/api-two-factor).
|
|
84
|
+
optional: 'two-factor',
|
|
79
85
|
},
|
|
80
86
|
// Plans
|
|
81
87
|
{
|
|
@@ -83,6 +89,7 @@ export const routes = [
|
|
|
83
89
|
path: '/users/:id/plan',
|
|
84
90
|
middlewares: ['authSelf'],
|
|
85
91
|
handler: 'updatePlan',
|
|
92
|
+
optional: 'payments',
|
|
86
93
|
},
|
|
87
94
|
// Payment verification — GET (redirect callbacks, e.g. Stripe Checkout). [M3-1]
|
|
88
95
|
// authSelf like the POST + molecule-dev's router: the plan is granted to `:id` and the
|
package/dist/routes.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes.js","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,OAAO;IACP,EAAE,MAAM,EAAE,MAAe,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE;IAC/E;QACE,MAAM,EAAE,MAAe;QACvB,IAAI,EAAE,eAAe;QACrB,WAAW,EAAE,CAAC,eAAe,CAAC;QAC9B,OAAO,EAAE,OAAO;KACjB;IACD,0EAA0E;IAC1E,2EAA2E;IAC3E,2EAA2E;IAC3E,wDAAwD;IACxD,EAAE;IACF,yEAAyE;IACzE,yEAAyE;IACzE,qEAAqE;IACrE,yEAAyE;IACz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,MAAM,EAAE,MAAe;QACvB,IAAI,EAAE,uCAAuC;QAC7C,WAAW,EAAE,CAAC,4BAA4B,CAAC;QAC3C,OAAO,EAAE,2BAA2B;QACpC,QAAQ,EAAE,UAAU;KACrB;CACF,CAAA"}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
declare const router: import("express-serve-static-core").Router;
|
|
2
2
|
/** OAuth initiation and credential exchange routes. */
|
|
3
3
|
export declare const oauthRouter: import("express-serve-static-core").Router;
|
|
4
|
-
/**
|
|
4
|
+
/** Password reset by email: the bonded email transport sends the reset link. */
|
|
5
|
+
export declare const emailsRouter: import("express-serve-static-core").Router;
|
|
6
|
+
/** Two-factor set-up, enabling and disabling, checked by the bonded two-factor provider. */
|
|
7
|
+
export declare const twoFactorRouter: import("express-serve-static-core").Router;
|
|
8
|
+
/** Plan changes, authenticated billing routes and the provider webhook. */
|
|
5
9
|
export declare const paymentsRouter: import("express-serve-static-core").Router;
|
|
6
10
|
export default router;
|
|
7
11
|
//# sourceMappingURL=scaffold-router.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scaffold-router.d.ts","sourceRoot":"","sources":["../src/scaffold-router.ts"],"names":[],"mappings":"AAKA,QAAA,MAAM,MAAM,4CAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"scaffold-router.d.ts","sourceRoot":"","sources":["../src/scaffold-router.ts"],"names":[],"mappings":"AAKA,QAAA,MAAM,MAAM,4CAAW,CAAA;AAyCvB,uDAAuD;AACvD,eAAO,MAAM,WAAW,4CAAW,CAAA;AAYnC,gFAAgF;AAChF,eAAO,MAAM,YAAY,4CAAW,CAAA;AAYpC,4FAA4F;AAC5F,eAAO,MAAM,eAAe,4CAAW,CAAA;AAQvC,2EAA2E;AAC3E,eAAO,MAAM,cAAc,4CAAW,CAAA;AAoBtC,eAAe,MAAM,CAAA"}
|
package/dist/scaffold-router.js
CHANGED
|
@@ -26,23 +26,27 @@ router.post('/users/log-in', rateLimitAuth, async (req, res) => {
|
|
|
26
26
|
res.status(result.statusCode).json(result.body);
|
|
27
27
|
});
|
|
28
28
|
router.post('/users/logout', auth, createRequestHandler(handlers.logout()));
|
|
29
|
-
router.post('/users/forgot-password', rateLimitAuth, createRequestHandler(handlers.forgotPassword(resource)));
|
|
30
|
-
router.post('/users/reset-password', rateLimitAuth, createRequestHandler(handlers.resetPassword(resource)));
|
|
31
29
|
// Keep current-user lookup before the parameterized route.
|
|
32
30
|
router.get('/users/me', auth, createRequestHandler(handlers.readSelf(resource)));
|
|
33
31
|
router.get('/users/:id', authSelf, createRequestHandler(handlers.read(resource)));
|
|
34
32
|
router.patch('/users/:id', authSelf, createRequestHandler(handlers.update(resource)));
|
|
35
33
|
router.delete('/users/:id', authSelf, createRequestHandler(handlers.del(resource)));
|
|
36
34
|
router.patch('/users/:id/password', authSelf, createRequestHandler(handlers.updatePassword(resource)));
|
|
37
|
-
router.post('/users/:id/verify-two-factor', authSelf, rateLimitTwoFactor, createRequestHandler(handlers.verifyTwoFactor(resource)));
|
|
38
|
-
router.patch('/users/:id/plan', authSelf, createRequestHandler(handlers.updatePlan(resource)));
|
|
39
35
|
// Feature routers are mounted by the app when the corresponding provider is installed.
|
|
40
36
|
/** OAuth initiation and credential exchange routes. */
|
|
41
37
|
export const oauthRouter = Router();
|
|
42
38
|
oauthRouter.get('/users/oauth/:provider', rateLimitAuth, createRequestHandler(handlers.oauthAuthorize()));
|
|
43
39
|
oauthRouter.post('/users/log-in/oauth', rateLimitAuth, createRequestHandler(handlers.logInOAuth(resource)));
|
|
44
|
-
/**
|
|
40
|
+
/** Password reset by email: the bonded email transport sends the reset link. */
|
|
41
|
+
export const emailsRouter = Router();
|
|
42
|
+
emailsRouter.post('/users/forgot-password', rateLimitAuth, createRequestHandler(handlers.forgotPassword(resource)));
|
|
43
|
+
emailsRouter.post('/users/reset-password', rateLimitAuth, createRequestHandler(handlers.resetPassword(resource)));
|
|
44
|
+
/** Two-factor set-up, enabling and disabling, checked by the bonded two-factor provider. */
|
|
45
|
+
export const twoFactorRouter = Router();
|
|
46
|
+
twoFactorRouter.post('/users/:id/verify-two-factor', authSelf, rateLimitTwoFactor, createRequestHandler(handlers.verifyTwoFactor(resource)));
|
|
47
|
+
/** Plan changes, authenticated billing routes and the provider webhook. */
|
|
45
48
|
export const paymentsRouter = Router();
|
|
49
|
+
paymentsRouter.patch('/users/:id/plan', authSelf, createRequestHandler(handlers.updatePlan(resource)));
|
|
46
50
|
const verifyPayment = createRequestHandler(handlers.verifyPayment(resource));
|
|
47
51
|
paymentsRouter.get('/users/:id/verify-payment/:provider', authSelf, verifyPayment);
|
|
48
52
|
paymentsRouter.post('/users/:id/verify-payment/:provider', authSelf, verifyPayment);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scaffold-router.js","sourceRoot":"","sources":["../src/scaffold-router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAEhC,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAA;AAE7E,MAAM,MAAM,GAAG,MAAM,EAAE,CAAA;AACvB,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;AACxC,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;AACtC,MAAM,IAAI,GAAG,WAAW,CAAC,IAAI,EAAE,CAAA;AAC/B,MAAM,QAAQ,GAAG,WAAW,CAAC,QAAQ,EAAE,CAAA;AACvC,MAAM,aAAa,GAAG,WAAW,CAAC,SAAS,CAAC;IAC1C,KAAK,EAAE,MAAM;IACb,WAAW,EAAE,CAAC,WAAW,CAAC,eAAe,EAAE,WAAW,CAAC,eAAe,CAAC;CACxE,CAAC,CAAA;AACF,MAAM,kBAAkB,GAAG,WAAW,CAAC,SAAS,CAAC;I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AQ,CAAC,CAAC,CACvD,CAAA;AAED,4FAA4F;AAC5F,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,EAAE,CAAA;AACvC,eAAe,CAAC,IAAI,CAClB,8BAA8B,EAC9B,QAAQ,EACR,kBAAkB,EAClB,oBAAoB,CAAC,QAAQ,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC,CACzD,CAAA;AAED,2EAA2E;AAC3E,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,EAAE,CAAA;AACtC,cAAc,CAAC,KAAK,CAClB,iBAAiB,EACjB,QAAQ,EACR,oBAAoB,CAAC,QAAQ,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CACpD,CAAA;AACD,MAAM,aAAa,GAAG,oBAAoB,CAAC,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAA;AAC5E,cAAc,CAAC,GAAG,CAAC,qCAAqC,EAAE,QAAQ,EAAE,aAAa,CAAC,CAAA;AAClF,cAAc,CAAC,IAAI,CAAC,qCAAqC,EAAE,QAAQ,EAAE,aAAa,CAAC,CAAA;AACnF,cAAc,CAAC,IAAI,CACjB,qCAAqC,EACrC,QAAQ,EACR,oBAAoB,CAAC,QAAQ,CAAC,aAAa,EAAE,CAAC,CAC/C,CAAA;AACD,cAAc,CAAC,IAAI,CACjB,uCAAuC,EACvC,WAAW,CAAC,0BAA0B,EAAE,EACxC,oBAAoB,CAAC,QAAQ,CAAC,yBAAyB,CAAC,QAAQ,CAAC,CAAC,CACnE,CAAA;AAED,eAAe,MAAM,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molecule/api-resource-user",
|
|
3
|
-
"version": "1.11.
|
|
3
|
+
"version": "1.11.2",
|
|
4
4
|
"description": "User registration, login, JWT sessions",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@molecule/api-bond": "1.0.4",
|
|
38
38
|
"@molecule/api-config": "1.0.4",
|
|
39
|
-
"@molecule/api-locales-user": "1.2.
|
|
39
|
+
"@molecule/api-locales-user": "1.2.1",
|
|
40
40
|
"@molecule/api-locales-user-payments": "1.0.5",
|
|
41
41
|
"@molecule/api-payments": "1.2.3",
|
|
42
42
|
"@molecule/api-push-notifications": "1.2.0",
|
package/src/scaffold-router.ts
CHANGED
|
@@ -31,16 +31,6 @@ router.post('/users/log-in', rateLimitAuth, async (req, res) => {
|
|
|
31
31
|
})
|
|
32
32
|
|
|
33
33
|
router.post('/users/logout', auth, createRequestHandler(handlers.logout()))
|
|
34
|
-
router.post(
|
|
35
|
-
'/users/forgot-password',
|
|
36
|
-
rateLimitAuth,
|
|
37
|
-
createRequestHandler(handlers.forgotPassword(resource)),
|
|
38
|
-
)
|
|
39
|
-
router.post(
|
|
40
|
-
'/users/reset-password',
|
|
41
|
-
rateLimitAuth,
|
|
42
|
-
createRequestHandler(handlers.resetPassword(resource)),
|
|
43
|
-
)
|
|
44
34
|
|
|
45
35
|
// Keep current-user lookup before the parameterized route.
|
|
46
36
|
router.get('/users/me', auth, createRequestHandler(handlers.readSelf(resource)))
|
|
@@ -52,13 +42,6 @@ router.patch(
|
|
|
52
42
|
authSelf,
|
|
53
43
|
createRequestHandler(handlers.updatePassword(resource)),
|
|
54
44
|
)
|
|
55
|
-
router.post(
|
|
56
|
-
'/users/:id/verify-two-factor',
|
|
57
|
-
authSelf,
|
|
58
|
-
rateLimitTwoFactor,
|
|
59
|
-
createRequestHandler(handlers.verifyTwoFactor(resource)),
|
|
60
|
-
)
|
|
61
|
-
router.patch('/users/:id/plan', authSelf, createRequestHandler(handlers.updatePlan(resource)))
|
|
62
45
|
|
|
63
46
|
// Feature routers are mounted by the app when the corresponding provider is installed.
|
|
64
47
|
/** OAuth initiation and credential exchange routes. */
|
|
@@ -74,8 +57,35 @@ oauthRouter.post(
|
|
|
74
57
|
createRequestHandler(handlers.logInOAuth(resource)),
|
|
75
58
|
)
|
|
76
59
|
|
|
77
|
-
/**
|
|
60
|
+
/** Password reset by email: the bonded email transport sends the reset link. */
|
|
61
|
+
export const emailsRouter = Router()
|
|
62
|
+
emailsRouter.post(
|
|
63
|
+
'/users/forgot-password',
|
|
64
|
+
rateLimitAuth,
|
|
65
|
+
createRequestHandler(handlers.forgotPassword(resource)),
|
|
66
|
+
)
|
|
67
|
+
emailsRouter.post(
|
|
68
|
+
'/users/reset-password',
|
|
69
|
+
rateLimitAuth,
|
|
70
|
+
createRequestHandler(handlers.resetPassword(resource)),
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
/** Two-factor set-up, enabling and disabling, checked by the bonded two-factor provider. */
|
|
74
|
+
export const twoFactorRouter = Router()
|
|
75
|
+
twoFactorRouter.post(
|
|
76
|
+
'/users/:id/verify-two-factor',
|
|
77
|
+
authSelf,
|
|
78
|
+
rateLimitTwoFactor,
|
|
79
|
+
createRequestHandler(handlers.verifyTwoFactor(resource)),
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
/** Plan changes, authenticated billing routes and the provider webhook. */
|
|
78
83
|
export const paymentsRouter = Router()
|
|
84
|
+
paymentsRouter.patch(
|
|
85
|
+
'/users/:id/plan',
|
|
86
|
+
authSelf,
|
|
87
|
+
createRequestHandler(handlers.updatePlan(resource)),
|
|
88
|
+
)
|
|
79
89
|
const verifyPayment = createRequestHandler(handlers.verifyPayment(resource))
|
|
80
90
|
paymentsRouter.get('/users/:id/verify-payment/:provider', authSelf, verifyPayment)
|
|
81
91
|
paymentsRouter.post('/users/:id/verify-payment/:provider', authSelf, verifyPayment)
|