@molecule/api-resource-user 1.10.3 → 1.10.4
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 +5 -2
- package/dist/scaffold-router.d.ts +7 -0
- package/dist/scaffold-router.d.ts.map +1 -0
- package/dist/scaffold-router.js +52 -0
- package/dist/scaffold-router.js.map +1 -0
- package/package.json +10 -6
- package/src/scaffold-router.ts +93 -0
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-21T05:13:13.396Z
|
|
7
7
|
-->
|
|
8
8
|
|
|
9
9
|
# @molecule/api-resource-user
|
|
@@ -228,7 +228,8 @@ router.get('/me/timezone', async (req, res) => {
|
|
|
228
228
|
## Installation
|
|
229
229
|
|
|
230
230
|
```bash
|
|
231
|
-
npm install @molecule/api-resource-user @molecule/api-bond @molecule/api-config @molecule/api-database @molecule/api-entitlements @molecule/api-i18n @molecule/api-jwt @molecule/api-locales-user @molecule/api-locales-user-payments @molecule/api-password @molecule/api-payments @molecule/api-push-notifications @molecule/api-rate-limit @molecule/api-resource @molecule/api-resource-device @molecule/api-secrets @molecule/api-two-factor uuid zod
|
|
231
|
+
npm install @molecule/api-resource-user @molecule/api-bond @molecule/api-config @molecule/api-database @molecule/api-entitlements @molecule/api-i18n @molecule/api-jwt @molecule/api-locales-user @molecule/api-locales-user-payments @molecule/api-password @molecule/api-payments @molecule/api-push-notifications @molecule/api-rate-limit @molecule/api-resource @molecule/api-resource-device @molecule/api-secrets @molecule/api-two-factor express uuid zod
|
|
232
|
+
npm install -D @types/express
|
|
232
233
|
```
|
|
233
234
|
|
|
234
235
|
## API
|
|
@@ -2831,6 +2832,7 @@ Peer dependencies:
|
|
|
2831
2832
|
- `@molecule/api-resource-device` ^1.1.4
|
|
2832
2833
|
- `@molecule/api-secrets` ^1.0.1
|
|
2833
2834
|
- `@molecule/api-two-factor` ^1.0.1
|
|
2835
|
+
- `express` ^5.0.0
|
|
2834
2836
|
|
|
2835
2837
|
### Environment Variables
|
|
2836
2838
|
|
|
@@ -2857,6 +2859,7 @@ Peer dependencies:
|
|
|
2857
2859
|
- `@molecule/api-resource-device`
|
|
2858
2860
|
- `@molecule/api-secrets`
|
|
2859
2861
|
- `@molecule/api-two-factor`
|
|
2862
|
+
- `express`
|
|
2860
2863
|
- `uuid`
|
|
2861
2864
|
- `zod`
|
|
2862
2865
|
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
declare const router: import("express-serve-static-core").Router;
|
|
2
|
+
/** OAuth initiation and credential exchange routes. */
|
|
3
|
+
export declare const oauthRouter: import("express-serve-static-core").Router;
|
|
4
|
+
/** Authenticated billing routes and the provider webhook. */
|
|
5
|
+
export declare const paymentsRouter: import("express-serve-static-core").Router;
|
|
6
|
+
export default router;
|
|
7
|
+
//# sourceMappingURL=scaffold-router.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scaffold-router.d.ts","sourceRoot":"","sources":["../src/scaffold-router.ts"],"names":[],"mappings":"AAKA,QAAA,MAAM,MAAM,4CAAW,CAAA;AA0DvB,uDAAuD;AACvD,eAAO,MAAM,WAAW,4CAAW,CAAA;AAYnC,6DAA6D;AAC7D,eAAO,MAAM,cAAc,4CAAW,CAAA;AAetC,eAAe,MAAM,CAAA"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Router } from 'express';
|
|
2
|
+
import { createRequestHandler } from '@molecule/api-resource';
|
|
3
|
+
import { authorizers, handlers, resource } from '@molecule/api-resource-user';
|
|
4
|
+
const router = Router();
|
|
5
|
+
const create = handlers.create(resource);
|
|
6
|
+
const logIn = handlers.logIn(resource);
|
|
7
|
+
const auth = authorizers.auth();
|
|
8
|
+
const authSelf = authorizers.authSelf();
|
|
9
|
+
const rateLimitAuth = authorizers.rateLimit({
|
|
10
|
+
scope: 'auth',
|
|
11
|
+
accountFrom: [authorizers.loginAccountKey, authorizers.emailAccountKey],
|
|
12
|
+
});
|
|
13
|
+
const rateLimitTwoFactor = authorizers.rateLimit({
|
|
14
|
+
scope: '2fa',
|
|
15
|
+
max: 5,
|
|
16
|
+
accountFrom: [authorizers.paramIdAccountKey],
|
|
17
|
+
});
|
|
18
|
+
// Edit paths, incoming fields and JSON here. The account services own passwords,
|
|
19
|
+
// credential checks, device sessions, and user storage.
|
|
20
|
+
router.post('/users', async (req, res) => {
|
|
21
|
+
const result = await create(req, res);
|
|
22
|
+
res.status(result.statusCode).json(result.body);
|
|
23
|
+
});
|
|
24
|
+
router.post('/users/log-in', rateLimitAuth, async (req, res) => {
|
|
25
|
+
const result = await logIn(req, res);
|
|
26
|
+
res.status(result.statusCode).json(result.body);
|
|
27
|
+
});
|
|
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
|
+
// Keep current-user lookup before the parameterized route.
|
|
32
|
+
router.get('/users/me', auth, createRequestHandler(handlers.readSelf(resource)));
|
|
33
|
+
router.get('/users/:id', authSelf, createRequestHandler(handlers.read(resource)));
|
|
34
|
+
router.patch('/users/:id', authSelf, createRequestHandler(handlers.update(resource)));
|
|
35
|
+
router.delete('/users/:id', authSelf, createRequestHandler(handlers.del(resource)));
|
|
36
|
+
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
|
+
// Feature routers are mounted by the app when the corresponding provider is installed.
|
|
40
|
+
/** OAuth initiation and credential exchange routes. */
|
|
41
|
+
export const oauthRouter = Router();
|
|
42
|
+
oauthRouter.get('/users/oauth/:provider', rateLimitAuth, createRequestHandler(handlers.oauthAuthorize()));
|
|
43
|
+
oauthRouter.post('/users/log-in/oauth', rateLimitAuth, createRequestHandler(handlers.logInOAuth(resource)));
|
|
44
|
+
/** Authenticated billing routes and the provider webhook. */
|
|
45
|
+
export const paymentsRouter = Router();
|
|
46
|
+
const verifyPayment = createRequestHandler(handlers.verifyPayment(resource));
|
|
47
|
+
paymentsRouter.get('/users/:id/verify-payment/:provider', authSelf, verifyPayment);
|
|
48
|
+
paymentsRouter.post('/users/:id/verify-payment/:provider', authSelf, verifyPayment);
|
|
49
|
+
paymentsRouter.post('/users/:id/billing-portal/:provider', authSelf, createRequestHandler(handlers.billingPortal()));
|
|
50
|
+
paymentsRouter.post('/users/payment-notification/:provider', authorizers.requireWebhookAuthenticity(), createRequestHandler(handlers.handlePaymentNotification(resource)));
|
|
51
|
+
export default router;
|
|
52
|
+
//# sourceMappingURL=scaffold-router.js.map
|
|
@@ -0,0 +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,QAA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EACxB,aAAa,EACb,oBAAoB,CAAC,QAAQ,CAAC,cAAc,EAAE,CAAC,CAChD,CAAA;AACD,WAAW,CAAC,IAAI,CACd,qBAAqB,EACrB,aAAa,EACb,oBAAoB,CAAC,QAAQ,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CACpD,CAAA;AAED,6DAA6D;AAC7D,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,EAAE,CAAA;AACtC,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,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molecule/api-resource-user",
|
|
3
|
-
"version": "1.10.
|
|
4
|
-
"description": "User
|
|
3
|
+
"version": "1.10.4",
|
|
4
|
+
"description": "User registration, login, JWT sessions",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
"files": [
|
|
20
20
|
"dist",
|
|
21
21
|
"src/__setup__",
|
|
22
|
+
"src/scaffold-router.ts",
|
|
22
23
|
"README.md"
|
|
23
24
|
],
|
|
24
25
|
"keywords": [
|
|
@@ -35,13 +36,15 @@
|
|
|
35
36
|
"devDependencies": {
|
|
36
37
|
"@molecule/api-bond": "1.0.4",
|
|
37
38
|
"@molecule/api-config": "1.0.4",
|
|
38
|
-
"@molecule/api-locales-user": "1.1.
|
|
39
|
-
"@molecule/api-locales-user-payments": "1.0.
|
|
39
|
+
"@molecule/api-locales-user": "1.1.4",
|
|
40
|
+
"@molecule/api-locales-user-payments": "1.0.5",
|
|
40
41
|
"@molecule/api-payments": "1.2.3",
|
|
41
|
-
"@molecule/api-push-notifications": "1.0
|
|
42
|
+
"@molecule/api-push-notifications": "1.2.0",
|
|
42
43
|
"@molecule/api-rate-limit": "1.0.4",
|
|
43
44
|
"@molecule/api-two-factor": "1.0.2",
|
|
45
|
+
"@types/express": "5.0.6",
|
|
44
46
|
"@types/node": "26.6.5",
|
|
47
|
+
"express": "5.3.0",
|
|
45
48
|
"typescript": "6.0.3",
|
|
46
49
|
"vitest": "4.1.12"
|
|
47
50
|
},
|
|
@@ -61,7 +64,8 @@
|
|
|
61
64
|
"@molecule/api-resource": "^1.0.1",
|
|
62
65
|
"@molecule/api-resource-device": "^1.1.4",
|
|
63
66
|
"@molecule/api-secrets": "^1.0.1",
|
|
64
|
-
"@molecule/api-two-factor": "^1.0.1"
|
|
67
|
+
"@molecule/api-two-factor": "^1.0.1",
|
|
68
|
+
"express": "^5.0.0"
|
|
65
69
|
},
|
|
66
70
|
"peerDependenciesMeta": {
|
|
67
71
|
"@molecule/api-entitlements": {
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { Router } from 'express'
|
|
2
|
+
|
|
3
|
+
import { createRequestHandler } from '@molecule/api-resource'
|
|
4
|
+
import { authorizers, handlers, resource } from '@molecule/api-resource-user'
|
|
5
|
+
|
|
6
|
+
const router = Router()
|
|
7
|
+
const create = handlers.create(resource)
|
|
8
|
+
const logIn = handlers.logIn(resource)
|
|
9
|
+
const auth = authorizers.auth()
|
|
10
|
+
const authSelf = authorizers.authSelf()
|
|
11
|
+
const rateLimitAuth = authorizers.rateLimit({
|
|
12
|
+
scope: 'auth',
|
|
13
|
+
accountFrom: [authorizers.loginAccountKey, authorizers.emailAccountKey],
|
|
14
|
+
})
|
|
15
|
+
const rateLimitTwoFactor = authorizers.rateLimit({
|
|
16
|
+
scope: '2fa',
|
|
17
|
+
max: 5,
|
|
18
|
+
accountFrom: [authorizers.paramIdAccountKey],
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
// Edit paths, incoming fields and JSON here. The account services own passwords,
|
|
22
|
+
// credential checks, device sessions, and user storage.
|
|
23
|
+
router.post('/users', async (req, res) => {
|
|
24
|
+
const result = await create(req, res)
|
|
25
|
+
res.status(result.statusCode).json(result.body)
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
router.post('/users/log-in', rateLimitAuth, async (req, res) => {
|
|
29
|
+
const result = await logIn(req, res)
|
|
30
|
+
res.status(result.statusCode).json(result.body)
|
|
31
|
+
})
|
|
32
|
+
|
|
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
|
+
|
|
45
|
+
// Keep current-user lookup before the parameterized route.
|
|
46
|
+
router.get('/users/me', auth, createRequestHandler(handlers.readSelf(resource)))
|
|
47
|
+
router.get('/users/:id', authSelf, createRequestHandler(handlers.read(resource)))
|
|
48
|
+
router.patch('/users/:id', authSelf, createRequestHandler(handlers.update(resource)))
|
|
49
|
+
router.delete('/users/:id', authSelf, createRequestHandler(handlers.del(resource)))
|
|
50
|
+
router.patch(
|
|
51
|
+
'/users/:id/password',
|
|
52
|
+
authSelf,
|
|
53
|
+
createRequestHandler(handlers.updatePassword(resource)),
|
|
54
|
+
)
|
|
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
|
+
|
|
63
|
+
// Feature routers are mounted by the app when the corresponding provider is installed.
|
|
64
|
+
/** OAuth initiation and credential exchange routes. */
|
|
65
|
+
export const oauthRouter = Router()
|
|
66
|
+
oauthRouter.get(
|
|
67
|
+
'/users/oauth/:provider',
|
|
68
|
+
rateLimitAuth,
|
|
69
|
+
createRequestHandler(handlers.oauthAuthorize()),
|
|
70
|
+
)
|
|
71
|
+
oauthRouter.post(
|
|
72
|
+
'/users/log-in/oauth',
|
|
73
|
+
rateLimitAuth,
|
|
74
|
+
createRequestHandler(handlers.logInOAuth(resource)),
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
/** Authenticated billing routes and the provider webhook. */
|
|
78
|
+
export const paymentsRouter = Router()
|
|
79
|
+
const verifyPayment = createRequestHandler(handlers.verifyPayment(resource))
|
|
80
|
+
paymentsRouter.get('/users/:id/verify-payment/:provider', authSelf, verifyPayment)
|
|
81
|
+
paymentsRouter.post('/users/:id/verify-payment/:provider', authSelf, verifyPayment)
|
|
82
|
+
paymentsRouter.post(
|
|
83
|
+
'/users/:id/billing-portal/:provider',
|
|
84
|
+
authSelf,
|
|
85
|
+
createRequestHandler(handlers.billingPortal()),
|
|
86
|
+
)
|
|
87
|
+
paymentsRouter.post(
|
|
88
|
+
'/users/payment-notification/:provider',
|
|
89
|
+
authorizers.requireWebhookAuthenticity(),
|
|
90
|
+
createRequestHandler(handlers.handlePaymentNotification(resource)),
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
export default router
|