@molecule/api-resource-user 1.11.8 → 1.11.10
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 +72 -12
- package/dist/authorization.d.ts.map +1 -1
- package/dist/authorization.js +2 -2
- package/dist/authorization.js.map +1 -1
- package/dist/authorizers/rateLimit.d.ts +20 -0
- package/dist/authorizers/rateLimit.d.ts.map +1 -1
- package/dist/authorizers/rateLimit.js +53 -9
- package/dist/authorizers/rateLimit.js.map +1 -1
- package/dist/handlers/create.d.ts.map +1 -1
- package/dist/handlers/create.js +2 -2
- package/dist/handlers/create.js.map +1 -1
- package/dist/handlers/del.d.ts +4 -0
- package/dist/handlers/del.d.ts.map +1 -1
- package/dist/handlers/del.js +4 -0
- package/dist/handlers/del.js.map +1 -1
- package/dist/handlers/logInOAuth.d.ts.map +1 -1
- package/dist/handlers/logInOAuth.js +2 -3
- package/dist/handlers/logInOAuth.js.map +1 -1
- package/dist/handlers/payments/verifyPayment.d.ts +3 -2
- package/dist/handlers/payments/verifyPayment.d.ts.map +1 -1
- package/dist/handlers/payments/verifyPayment.js +20 -13
- package/dist/handlers/payments/verifyPayment.js.map +1 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -1
- package/dist/index.js.map +1 -1
- package/dist/provisioning.d.ts.map +1 -1
- package/dist/provisioning.js +2 -2
- package/dist/provisioning.js.map +1 -1
- package/dist/requestHandlerMap.d.ts +2 -0
- package/dist/requestHandlerMap.d.ts.map +1 -1
- package/dist/requestHandlerMap.js +3 -8
- package/dist/requestHandlerMap.js.map +1 -1
- package/dist/routes.d.ts.map +1 -1
- package/dist/routes.js +11 -6
- package/dist/routes.js.map +1 -1
- package/dist/scaffold-router.d.ts.map +1 -1
- package/dist/scaffold-router.js +9 -10
- package/dist/scaffold-router.js.map +1 -1
- package/package.json +12 -4
- package/src/__setup__/users.sql +5 -5
- package/src/__setup__/usersSecrets.sql +2 -1
- package/src/scaffold-router.ts +19 -7
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.10",
|
|
4
4
|
"description": "User registration, login, JWT sessions",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -30,7 +30,6 @@
|
|
|
30
30
|
],
|
|
31
31
|
"license": "Apache-2.0",
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"uuid": "14.0.3",
|
|
34
33
|
"zod": "4.6.7"
|
|
35
34
|
},
|
|
36
35
|
"devDependencies": {
|
|
@@ -40,7 +39,7 @@
|
|
|
40
39
|
"@molecule/api-locales-user-payments": "1.0.6",
|
|
41
40
|
"@molecule/api-payments": "1.2.3",
|
|
42
41
|
"@molecule/api-push-notifications": "1.2.0",
|
|
43
|
-
"@molecule/api-rate-limit": "1.0
|
|
42
|
+
"@molecule/api-rate-limit": "1.1.0",
|
|
44
43
|
"@molecule/api-two-factor": "1.0.2",
|
|
45
44
|
"@types/express": "5.0.6",
|
|
46
45
|
"@types/node": "26.6.5",
|
|
@@ -60,7 +59,7 @@
|
|
|
60
59
|
"@molecule/api-password": "^1.0.1",
|
|
61
60
|
"@molecule/api-payments": "^1.2.0",
|
|
62
61
|
"@molecule/api-push-notifications": "^1.0.1",
|
|
63
|
-
"@molecule/api-rate-limit": "^1.0
|
|
62
|
+
"@molecule/api-rate-limit": "^1.1.0",
|
|
64
63
|
"@molecule/api-resource": "^1.3.0",
|
|
65
64
|
"@molecule/api-resource-device": "^1.1.4",
|
|
66
65
|
"@molecule/api-secrets": "^1.0.1",
|
|
@@ -77,12 +76,21 @@
|
|
|
77
76
|
"@molecule/api-emails": {
|
|
78
77
|
"optional": true
|
|
79
78
|
},
|
|
79
|
+
"@molecule/api-locales-user": {
|
|
80
|
+
"optional": true
|
|
81
|
+
},
|
|
80
82
|
"@molecule/api-push-notifications": {
|
|
81
83
|
"optional": true
|
|
82
84
|
},
|
|
83
85
|
"@molecule/api-payments": {
|
|
84
86
|
"optional": true
|
|
85
87
|
},
|
|
88
|
+
"@molecule/api-rate-limit": {
|
|
89
|
+
"optional": true
|
|
90
|
+
},
|
|
91
|
+
"@molecule/api-resource-device": {
|
|
92
|
+
"optional": true
|
|
93
|
+
},
|
|
86
94
|
"@molecule/api-resource-payment": {
|
|
87
95
|
"optional": true
|
|
88
96
|
},
|
package/src/__setup__/users.sql
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
CREATE TABLE IF NOT EXISTS "users" (
|
|
2
|
-
"id" uuid
|
|
2
|
+
"id" uuid PRIMARY KEY NOT NULL,
|
|
3
3
|
"createdAt" timestamptz DEFAULT current_timestamp NOT NULL,
|
|
4
4
|
"updatedAt" timestamptz DEFAULT current_timestamp NOT NULL,
|
|
5
5
|
"username" varchar(255),
|
|
@@ -8,15 +8,15 @@ CREATE TABLE IF NOT EXISTS "users" (
|
|
|
8
8
|
"emailVerified" boolean DEFAULT false NOT NULL,
|
|
9
9
|
"avatar" text,
|
|
10
10
|
"bio" text,
|
|
11
|
-
"twoFactorEnabled" boolean DEFAULT false,
|
|
11
|
+
"twoFactorEnabled" boolean DEFAULT false NOT NULL,
|
|
12
12
|
"oauthServer" text,
|
|
13
13
|
"oauthId" text,
|
|
14
14
|
"oauthData" jsonb,
|
|
15
15
|
"planKey" text,
|
|
16
16
|
"planExpiresAt" timestamptz,
|
|
17
|
-
"planAutoRenews" boolean DEFAULT false
|
|
17
|
+
"planAutoRenews" boolean DEFAULT false NOT NULL
|
|
18
18
|
);
|
|
19
19
|
CREATE INDEX IF NOT EXISTS "users_createdAt_index" ON "users" ("createdAt");
|
|
20
20
|
CREATE INDEX IF NOT EXISTS "users_updatedAt_index" ON "users" ("updatedAt");
|
|
21
|
-
CREATE INDEX IF NOT EXISTS "
|
|
22
|
-
CREATE INDEX IF NOT EXISTS "
|
|
21
|
+
CREATE UNIQUE INDEX IF NOT EXISTS "users_username_unique" ON "users" ("username");
|
|
22
|
+
CREATE UNIQUE INDEX IF NOT EXISTS "users_oauth_identity_unique" ON "users" ("oauthServer", "oauthId");
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
CREATE TABLE IF NOT EXISTS "usersSecrets" (
|
|
2
|
-
"id" uuid
|
|
2
|
+
"id" uuid PRIMARY KEY NOT NULL,
|
|
3
3
|
"passwordHash" text,
|
|
4
4
|
"passwordResetToken" text,
|
|
5
5
|
"passwordResetTokenAt" timestamptz,
|
|
@@ -7,3 +7,4 @@ CREATE TABLE IF NOT EXISTS "usersSecrets" (
|
|
|
7
7
|
"twoFactorSecret" text,
|
|
8
8
|
"lastTwoFactorTimeStep" integer
|
|
9
9
|
);
|
|
10
|
+
CREATE UNIQUE INDEX IF NOT EXISTS "usersSecrets_password_reset_token_unique" ON "usersSecrets" ("passwordResetToken");
|
package/src/scaffold-router.ts
CHANGED
|
@@ -8,10 +8,8 @@ const create = handlers.create(resource)
|
|
|
8
8
|
const logIn = handlers.logIn(resource)
|
|
9
9
|
const auth = authorizers.auth()
|
|
10
10
|
const authSelf = authorizers.authSelf()
|
|
11
|
-
const rateLimitAuth = authorizers.
|
|
12
|
-
|
|
13
|
-
accountFrom: [authorizers.loginAccountKey, authorizers.emailAccountKey],
|
|
14
|
-
})
|
|
11
|
+
const rateLimitAuth = authorizers.rateLimitAuth
|
|
12
|
+
const rateLimitEmailChange = authorizers.rateLimitEmailChange
|
|
15
13
|
const rateLimitTwoFactor = authorizers.rateLimit({
|
|
16
14
|
scope: '2fa',
|
|
17
15
|
max: 5,
|
|
@@ -35,11 +33,17 @@ router.post('/users/logout', auth, createRequestHandler(handlers.logout()))
|
|
|
35
33
|
// Keep current-user lookup before the parameterized route.
|
|
36
34
|
router.get('/users/me', auth, createRequestHandler(handlers.readSelf(resource)))
|
|
37
35
|
router.get('/users/:id', authSelf, createRequestHandler(handlers.read(resource)))
|
|
38
|
-
router.patch(
|
|
36
|
+
router.patch(
|
|
37
|
+
'/users/:id',
|
|
38
|
+
authSelf,
|
|
39
|
+
rateLimitEmailChange,
|
|
40
|
+
createRequestHandler(handlers.update(resource)),
|
|
41
|
+
)
|
|
39
42
|
router.delete('/users/:id', authSelf, createRequestHandler(handlers.del(resource)))
|
|
40
43
|
router.patch(
|
|
41
44
|
'/users/:id/password',
|
|
42
45
|
authSelf,
|
|
46
|
+
rateLimitAuth,
|
|
43
47
|
createRequestHandler(handlers.updatePassword(resource)),
|
|
44
48
|
)
|
|
45
49
|
|
|
@@ -88,17 +92,25 @@ twoFactorRouter.post(
|
|
|
88
92
|
* provider.
|
|
89
93
|
*/
|
|
90
94
|
export const paymentsRouter = Router()
|
|
95
|
+
const rateLimitBilling = authorizers.rateLimitBilling
|
|
91
96
|
paymentsRouter.patch(
|
|
92
97
|
'/users/:id/plan',
|
|
93
98
|
authSelf,
|
|
99
|
+
rateLimitBilling,
|
|
94
100
|
createRequestHandler(handlers.updatePlan(resource)),
|
|
95
101
|
)
|
|
96
102
|
const verifyPayment = createRequestHandler(handlers.verifyPayment(resource))
|
|
97
|
-
paymentsRouter.get('/users/:id/verify-payment/:provider', authSelf, verifyPayment)
|
|
98
|
-
paymentsRouter.post(
|
|
103
|
+
paymentsRouter.get('/users/:id/verify-payment/:provider', authSelf, rateLimitBilling, verifyPayment)
|
|
104
|
+
paymentsRouter.post(
|
|
105
|
+
'/users/:id/verify-payment/:provider',
|
|
106
|
+
authSelf,
|
|
107
|
+
rateLimitBilling,
|
|
108
|
+
verifyPayment,
|
|
109
|
+
)
|
|
99
110
|
paymentsRouter.post(
|
|
100
111
|
'/users/:id/billing-portal/:provider',
|
|
101
112
|
authSelf,
|
|
113
|
+
rateLimitBilling,
|
|
102
114
|
createRequestHandler(handlers.billingPortal()),
|
|
103
115
|
)
|
|
104
116
|
paymentsRouter.post(
|