@molecule/api-resource-user 1.6.0 → 1.7.1
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 +226 -44
- package/dist/handlers/create.d.ts +19 -5
- package/dist/handlers/create.d.ts.map +1 -1
- package/dist/handlers/create.js +20 -5
- package/dist/handlers/create.js.map +1 -1
- package/dist/handlers/del.d.ts +2 -2
- package/dist/handlers/del.d.ts.map +1 -1
- package/dist/handlers/del.js +1 -1
- package/dist/handlers/del.js.map +1 -1
- package/dist/handlers/forgotPassword.d.ts +2 -2
- package/dist/handlers/forgotPassword.d.ts.map +1 -1
- package/dist/handlers/forgotPassword.js +2 -2
- package/dist/handlers/forgotPassword.js.map +1 -1
- package/dist/handlers/logIn.d.ts +13 -6
- package/dist/handlers/logIn.d.ts.map +1 -1
- package/dist/handlers/logIn.js +13 -6
- package/dist/handlers/logIn.js.map +1 -1
- package/dist/handlers/logInOAuth.d.ts +8 -4
- package/dist/handlers/logInOAuth.d.ts.map +1 -1
- package/dist/handlers/logInOAuth.js +9 -5
- package/dist/handlers/logInOAuth.js.map +1 -1
- package/dist/handlers/payments/billingPortal.d.ts +3 -0
- package/dist/handlers/payments/billingPortal.d.ts.map +1 -1
- package/dist/handlers/payments/billingPortal.js +10 -3
- package/dist/handlers/payments/billingPortal.js.map +1 -1
- package/dist/handlers/payments/handlePaymentNotification.d.ts +2 -2
- package/dist/handlers/payments/handlePaymentNotification.d.ts.map +1 -1
- package/dist/handlers/payments/handlePaymentNotification.js +2 -2
- package/dist/handlers/payments/handlePaymentNotification.js.map +1 -1
- package/dist/handlers/payments/verifyPayment.d.ts +5 -2
- package/dist/handlers/payments/verifyPayment.d.ts.map +1 -1
- package/dist/handlers/payments/verifyPayment.js +10 -3
- package/dist/handlers/payments/verifyPayment.js.map +1 -1
- package/dist/handlers/read.d.ts +2 -2
- package/dist/handlers/read.d.ts.map +1 -1
- package/dist/handlers/read.js +1 -1
- package/dist/handlers/read.js.map +1 -1
- package/dist/handlers/readSelf.d.ts +2 -2
- package/dist/handlers/readSelf.d.ts.map +1 -1
- package/dist/handlers/readSelf.js +1 -1
- package/dist/handlers/readSelf.js.map +1 -1
- package/dist/handlers/resetPassword.d.ts +2 -1
- package/dist/handlers/resetPassword.d.ts.map +1 -1
- package/dist/handlers/resetPassword.js +2 -1
- package/dist/handlers/resetPassword.js.map +1 -1
- package/dist/handlers/update.d.ts +19 -4
- package/dist/handlers/update.d.ts.map +1 -1
- package/dist/handlers/update.js +19 -4
- package/dist/handlers/update.js.map +1 -1
- package/dist/handlers/updatePassword.d.ts +12 -2
- package/dist/handlers/updatePassword.d.ts.map +1 -1
- package/dist/handlers/updatePassword.js +12 -2
- package/dist/handlers/updatePassword.js.map +1 -1
- package/dist/handlers/updatePlan.d.ts +6 -2
- package/dist/handlers/updatePlan.d.ts.map +1 -1
- package/dist/handlers/updatePlan.js +11 -3
- package/dist/handlers/updatePlan.js.map +1 -1
- package/dist/handlers/verifyTwoFactor.d.ts +2 -2
- package/dist/handlers/verifyTwoFactor.d.ts.map +1 -1
- package/dist/handlers/verifyTwoFactor.js +2 -2
- package/dist/handlers/verifyTwoFactor.js.map +1 -1
- package/dist/index.d.ts +86 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +86 -0
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +38 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utilities/payments.d.ts +29 -0
- package/dist/utilities/payments.d.ts.map +1 -0
- package/dist/utilities/payments.js +47 -0
- package/dist/utilities/payments.js.map +1 -0
- package/package.json +1 -1
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-
|
|
6
|
+
Generated: 2026-10-21T08:49:08.924Z
|
|
7
7
|
-->
|
|
8
8
|
|
|
9
9
|
# @molecule/api-resource-user
|
|
@@ -73,6 +73,93 @@ res.status(statusCode).send(body)
|
|
|
73
73
|
Monkey-patching `res.json` to re-shape a handler's answer intercepts nothing the handler
|
|
74
74
|
produces, so the request it was meant to answer is left unanswered and hangs.
|
|
75
75
|
|
|
76
|
+
**Re-shaping a success answer (RealWorld's `{ user: { …, token } }`, say)? Read the token from
|
|
77
|
+
`result.body.accessToken` — it is in the BODY.** The `Authorization` response header carries
|
|
78
|
+
the same token prefixed with the mount's scheme (`Bearer <token>`), so it is not the raw value
|
|
79
|
+
a client sends back. Type the result from the handler — do not cast `body` to `unknown`, which
|
|
80
|
+
hides the success branch — and narrow on the body's own keys:
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
const result = await handlers.logIn(resource)(req, res)
|
|
84
|
+
if (!('accessToken' in result.body)) {
|
|
85
|
+
// 400/403/500 `{ error, errorKey }`, or 206 `{ twoFactorRequired: true }` — send as built.
|
|
86
|
+
res.status(result.statusCode).send(result.body)
|
|
87
|
+
return
|
|
88
|
+
}
|
|
89
|
+
// `props` and `user` are the SAFE columns (secret columns stripped); accessToken is the token.
|
|
90
|
+
const { props, accessToken } = result.body
|
|
91
|
+
res.status(200).json({ user: { ...props, token: accessToken } })
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
**Constructing a handler: `schema` is optional.** Every factory accepts
|
|
95
|
+
`{ name, tableName, schema? }`. `schema` is a Zod object (anything exposing `safeParse`)
|
|
96
|
+
and only `handlers.create` / `handlers.logInOAuth` use it — both default to this package's
|
|
97
|
+
`propsSchema`. `handlers.update` validates with its own update schema; login and the
|
|
98
|
+
read/write handlers never validate props. The smallest correct wiring, with every import
|
|
99
|
+
spelled out:
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
import { createRequestHandler } from '@molecule/api-resource'
|
|
103
|
+
import { createResource, handlers } from '@molecule/api-resource-user'
|
|
104
|
+
|
|
105
|
+
// Omit `schema`: create() validates new users with this package's propsSchema.
|
|
106
|
+
const signUp = createRequestHandler(handlers.create({ name: 'User', tableName: 'users' }))
|
|
107
|
+
const signIn = createRequestHandler(handlers.logIn({ name: 'User', tableName: 'users' }))
|
|
108
|
+
|
|
109
|
+
// A constrained schema, when the app restricts oauthServer / planKey.
|
|
110
|
+
const users = createResource({ oauthServers: ['google', 'github'] as const })
|
|
111
|
+
const signUpConstrained = createRequestHandler(handlers.create(users))
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
`schema: {}` (or any object without `safeParse`) is NOT a schema: the first request
|
|
115
|
+
answers 400 `resource.error.unknownError` with
|
|
116
|
+
`TypeError: schema.safeParse is not a function`, and no row is written. Omit `schema`
|
|
117
|
+
instead of stubbing it.
|
|
118
|
+
|
|
119
|
+
**Exact responses of the sign-up and sign-in handlers** (the body shapes the routes send;
|
|
120
|
+
a handler returns `{ statusCode, body }` and the mount applies it):
|
|
121
|
+
|
|
122
|
+
- `create` (`POST /api/users`, flat body): 201 `{ props, accessToken, user }` (`user` equals
|
|
123
|
+
`props`, secret columns stripped); 400 `user.error.usernameInvalid` /
|
|
124
|
+
`user.error.bodyNestedUnderUser` / `user.error.passwordRequired` /
|
|
125
|
+
`user.error.passwordTooLong` / `user.error.passwordTooShort` / `user.error.emailInvalid` /
|
|
126
|
+
`user.error.badRequest`, or `resource.error.unknownError` when props fail the schema;
|
|
127
|
+
403 `user.error.usernameUnavailable` / `user.error.emailAlreadyRegistered`;
|
|
128
|
+
500 `user.error.failedToHashPassword` / `user.error.failedToCreateSession`.
|
|
129
|
+
- `logIn` (`POST /api/users/log-in`): 200 `{ props, accessToken, user }`; 206
|
|
130
|
+
`{ twoFactorRequired: true }`; 403 `user.error.invalidCredentials` /
|
|
131
|
+
`user.error.invalidTwoFactorToken`; 500 `user.error.failedToCreateSession` /
|
|
132
|
+
`user.error.twoFactorVerificationUnavailable` / `user.error.loginFailed`. Bad credentials
|
|
133
|
+
are 403, not 401 or 422.
|
|
134
|
+
|
|
135
|
+
**A JWT you sign yourself is NOT a session.** `verifyMiddleware` accepts a token only when
|
|
136
|
+
the bonded `@molecule/api-jwt` provider verifies it AND its `deviceId` names an ACTIVE row
|
|
137
|
+
in `devices`; anything else — another secret or algorithm, or an invented/placeholder
|
|
138
|
+
`deviceId` — is answered 401 on every request (a request with no credential at all answers
|
|
139
|
+
`{"errors":{"token":["is missing"]}}`). Mint sessions with `authorization.set()` after
|
|
140
|
+
`device.createOrUpdate()` (the sequence above) and mount `verifyMiddleware` once in front of
|
|
141
|
+
the routes — never hand-roll auth middleware or a second token scheme.
|
|
142
|
+
|
|
143
|
+
**Changing the EMAIL or the PASSWORD requires the CURRENT password — there is no opt-out.**
|
|
144
|
+
`handlers.update` (`PATCH /users/:id`) takes profile fields; when the body changes (or
|
|
145
|
+
clears) `email` on an account that has a password, the SAME flat body must also carry that
|
|
146
|
+
account's `currentPassword`. Missing → 400 `user.error.currentPasswordRequired`; wrong → 403
|
|
147
|
+
`user.error.currentPasswordIncorrect`. A real change resets `emailVerified` to `false`
|
|
148
|
+
server-side (the new address is unproven), and `emailVerified` is NEVER read from the body.
|
|
149
|
+
An OAuth-only account (no `passwordHash`) has no password to present, so its provider-backed
|
|
150
|
+
session is the credential. `handlers.updatePassword` (`PATCH /users/:id/password`) requires
|
|
151
|
+
`newPassword` (8–1024 characters) and, on a password account, `currentPassword` as well —
|
|
152
|
+
same 400/403 codes; it answers 200 `{ success: true }`, clears any outstanding reset token,
|
|
153
|
+
and revokes every OTHER device while the caller's own session keeps working.
|
|
154
|
+
|
|
155
|
+
Do NOT work around either gate by storing, caching or replaying the user's password, by
|
|
156
|
+
sending an invented `currentPassword`, or by writing `email` around the handler with the
|
|
157
|
+
datastore: the password is the re-authentication factor that stops a hijacked session from
|
|
158
|
+
moving the account-recovery address. If a wire format (e.g. RealWorld's token-only
|
|
159
|
+
`PUT /user`) cannot collect the current password, that flow is simply unsupported as written
|
|
160
|
+
— have the client ask for it in a re-authentication step, or route sign-in and account
|
|
161
|
+
changes through the auth pages (`useAuth()`). There is no supported bypass to add.
|
|
162
|
+
|
|
76
163
|
> **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
|
|
77
164
|
> It is written to be read by coding agents as much as by people, and is generated from this
|
|
78
165
|
> package's source — edit `src/index.ts` JSDoc, not this file.
|
|
@@ -1067,8 +1154,22 @@ Creates a user with username and password. Validates username uniqueness and ema
|
|
|
1067
1154
|
hashes the password into a separate secrets table, creates a session device via the bonded
|
|
1068
1155
|
DeviceService, and sets JWT authorization on the response.
|
|
1069
1156
|
|
|
1157
|
+
**`schema` is optional — omit it and this package's `propsSchema` validates the row.**
|
|
1158
|
+
It must be a Zod object (anything exposing `safeParse`): pass
|
|
1159
|
+
`createResource({ oauthServers, planKeys })` or your own extended schema only when the
|
|
1160
|
+
app constrains or extends user props. A stub such as `schema: {}` is not a schema — the
|
|
1161
|
+
FIRST request answers 400 `resource.error.unknownError` with
|
|
1162
|
+
`TypeError: schema.safeParse is not a function`, after no row has been written.
|
|
1163
|
+
|
|
1164
|
+
Statuses: 201 `{ props, accessToken, user }`; 400 `user.error.usernameInvalid` /
|
|
1165
|
+
`user.error.bodyNestedUnderUser` / `user.error.passwordRequired` /
|
|
1166
|
+
`user.error.passwordTooLong` / `user.error.passwordTooShort` / `user.error.emailInvalid` /
|
|
1167
|
+
`user.error.badRequest`, or `resource.error.unknownError` when props fail the schema;
|
|
1168
|
+
403 `user.error.usernameUnavailable` / `user.error.emailAlreadyRegistered`;
|
|
1169
|
+
500 `user.error.failedToHashPassword` / `user.error.failedToCreateSession`.
|
|
1170
|
+
|
|
1070
1171
|
```typescript
|
|
1071
|
-
function create({ name, tableName, schema }: types.
|
|
1172
|
+
function create({ name, tableName, schema = propsSchema }: types.HandlerResource): (
|
|
1072
1173
|
req: CreateRequest,
|
|
1073
1174
|
res: MoleculeResponse,
|
|
1074
1175
|
) => Promise<
|
|
@@ -1088,12 +1189,12 @@ function create({ name, tableName, schema }: types.Resource<unknown>): (
|
|
|
1088
1189
|
>
|
|
1089
1190
|
```
|
|
1090
1191
|
|
|
1091
|
-
- `resource` — The user resource configuration
|
|
1092
|
-
- `resource.name` — The resource name.
|
|
1192
|
+
- `resource` — The user resource configuration: `{ name, tableName, schema? }`.
|
|
1193
|
+
- `resource.name` — The resource name used in error messages.
|
|
1093
1194
|
- `resource.tableName` — The database table name for users.
|
|
1094
|
-
- `resource.schema` —
|
|
1195
|
+
- `resource.schema` — Optional Zod schema for the created user props. Defaults to `propsSchema`.
|
|
1095
1196
|
|
|
1096
|
-
**Returns:** A request handler that responds with `{ statusCode: 201, body: { props } }` on success.
|
|
1197
|
+
**Returns:** A request handler that responds with `{ statusCode: 201, body: { props, accessToken, user } }` on success.
|
|
1097
1198
|
|
|
1098
1199
|
##### `handlers.del(resource)`
|
|
1099
1200
|
|
|
@@ -1113,7 +1214,7 @@ function del({
|
|
|
1113
1214
|
name: _name,
|
|
1114
1215
|
tableName,
|
|
1115
1216
|
schema: _schema,
|
|
1116
|
-
}: types.
|
|
1217
|
+
}: types.HandlerResource): (
|
|
1117
1218
|
req: MoleculeRequest,
|
|
1118
1219
|
) => Promise<
|
|
1119
1220
|
| { statusCode: number; body: { error: string; errorKey: string; props?: undefined } }
|
|
@@ -1124,7 +1225,7 @@ function del({
|
|
|
1124
1225
|
- `resource` — The user resource configuration (name, tableName, schema).
|
|
1125
1226
|
- `resource.name` — The resource name.
|
|
1126
1227
|
- `resource.tableName` — The database table name for users.
|
|
1127
|
-
- `resource.schema` —
|
|
1228
|
+
- `resource.schema` — Optional. Ignored — deletion does not validate props.
|
|
1128
1229
|
|
|
1129
1230
|
**Returns:** A request handler that responds with `{ statusCode: 200, body: { props: { id } } }` on success.
|
|
1130
1231
|
|
|
@@ -1151,7 +1252,7 @@ function forgotPassword({
|
|
|
1151
1252
|
name: _name,
|
|
1152
1253
|
tableName,
|
|
1153
1254
|
schema: _schema,
|
|
1154
|
-
}: types.
|
|
1255
|
+
}: types.HandlerResource): (
|
|
1155
1256
|
req: ForgotPasswordRequest,
|
|
1156
1257
|
) => Promise<
|
|
1157
1258
|
| { statusCode: number; body: { error: string; errorKey: string; success?: undefined } }
|
|
@@ -1162,7 +1263,7 @@ function forgotPassword({
|
|
|
1162
1263
|
- `resource` — The user resource configuration (name, tableName, schema).
|
|
1163
1264
|
- `resource.name` — The resource name.
|
|
1164
1265
|
- `resource.tableName` — The database table name for users.
|
|
1165
|
-
- `resource.schema` —
|
|
1266
|
+
- `resource.schema` — Optional. Ignored — the reset flow reads and writes secrets directly.
|
|
1166
1267
|
|
|
1167
1268
|
**Returns:** A request handler that responds with `{ statusCode: 200, body: { success: true } }`.
|
|
1168
1269
|
|
|
@@ -1190,8 +1291,15 @@ authentication (1-hour expiry), and optional two-factor verification via `@molec
|
|
|
1190
1291
|
On success, creates/updates a device via the bonded DeviceService, sets JWT authorization,
|
|
1191
1292
|
and notifies other devices about the new login.
|
|
1192
1293
|
|
|
1294
|
+
`schema` is optional and NOT used here: login reads stored rows and compares credentials, so
|
|
1295
|
+
there are no props to validate. Statuses: 200 `{ props, accessToken, user }`; 206
|
|
1296
|
+
`{ twoFactorRequired: true }` when the account has 2FA enabled and no `twoFactorToken` was
|
|
1297
|
+
sent; 403 `user.error.invalidCredentials` (wrong password / unknown account / spent reset
|
|
1298
|
+
token) or `user.error.invalidTwoFactorToken`; 500 `user.error.failedToCreateSession` /
|
|
1299
|
+
`user.error.twoFactorVerificationUnavailable` / `user.error.loginFailed`.
|
|
1300
|
+
|
|
1193
1301
|
```typescript
|
|
1194
|
-
function logIn({
|
|
1302
|
+
function logIn({ tableName }: types.HandlerResource): (
|
|
1195
1303
|
req: LogInRequest,
|
|
1196
1304
|
res: MoleculeResponse,
|
|
1197
1305
|
) => Promise<
|
|
@@ -1231,12 +1339,12 @@ function logIn({ name: _name, tableName, schema: _schema }: types.Resource<unkno
|
|
|
1231
1339
|
>
|
|
1232
1340
|
```
|
|
1233
1341
|
|
|
1234
|
-
- `resource` — The user resource configuration
|
|
1235
|
-
- `resource.name` — The resource name.
|
|
1342
|
+
- `resource` — The user resource configuration: `{ name, tableName, schema? }`.
|
|
1343
|
+
- `resource.name` — The resource name (unused by this handler).
|
|
1236
1344
|
- `resource.tableName` — The database table name for users.
|
|
1237
|
-
- `resource.schema` —
|
|
1345
|
+
- `resource.schema` — Optional. Ignored — login validates credentials, not props.
|
|
1238
1346
|
|
|
1239
|
-
**Returns:** A request handler that responds with `{ statusCode: 200, body: { props } }` on success, or `{ statusCode: 206, body: { twoFactorRequired: true } }` when 2FA is needed.
|
|
1347
|
+
**Returns:** A request handler that responds with `{ statusCode: 200, body: { props, accessToken, user } }` on success, or `{ statusCode: 206, body: { twoFactorRequired: true } }` when 2FA is needed.
|
|
1240
1348
|
|
|
1241
1349
|
##### `handlers.LogInOAuthRequest`
|
|
1242
1350
|
|
|
@@ -1261,8 +1369,12 @@ Logs in or creates a user via OAuth. Verifies the authorization code with the bo
|
|
|
1261
1369
|
provider (`get('oauth', serverName)`), then either finds an existing user by oauthServer+oauthId
|
|
1262
1370
|
or creates a new one with a unique username. Sets JWT authorization and creates a session device.
|
|
1263
1371
|
|
|
1372
|
+
`schema` is optional and defaults to this package's `propsSchema`; supply one only when the
|
|
1373
|
+
app constrains or extends user props. It must expose `safeParse` — a stub fails the OAuth
|
|
1374
|
+
account-creation request with 400 `resource.error.unknownError`.
|
|
1375
|
+
|
|
1264
1376
|
```typescript
|
|
1265
|
-
function logInOAuth({ name, tableName, schema }: types.
|
|
1377
|
+
function logInOAuth({ name, tableName, schema = propsSchema }: types.HandlerResource): (
|
|
1266
1378
|
req: LogInOAuthRequest,
|
|
1267
1379
|
res: MoleculeResponse,
|
|
1268
1380
|
) => Promise<
|
|
@@ -1286,10 +1398,10 @@ function logInOAuth({ name, tableName, schema }: types.Resource<unknown>): (
|
|
|
1286
1398
|
>
|
|
1287
1399
|
```
|
|
1288
1400
|
|
|
1289
|
-
- `resource` — The user resource configuration
|
|
1290
|
-
- `resource.name` — The resource name.
|
|
1401
|
+
- `resource` — The user resource configuration: `{ name, tableName, schema? }`.
|
|
1402
|
+
- `resource.name` — The resource name used in error messages.
|
|
1291
1403
|
- `resource.tableName` — The database table name for users.
|
|
1292
|
-
- `resource.schema` —
|
|
1404
|
+
- `resource.schema` — Optional Zod schema validated when a new OAuth account is created. Defaults to `propsSchema`.
|
|
1293
1405
|
|
|
1294
1406
|
**Returns:** A request handler that responds with `{ statusCode: 200, body: { props } }` on success.
|
|
1295
1407
|
|
|
@@ -1370,6 +1482,9 @@ The user is returned to the APP origin on exit (never the API origin, whose
|
|
|
1370
1482
|
host holds no session cookie); an app-relative `returnPath` in the request
|
|
1371
1483
|
body sends them back to the exact page they opened the portal from.
|
|
1372
1484
|
|
|
1485
|
+
`@molecule/api-payments` is an OPTIONAL peer: its helpers are loaded lazily per
|
|
1486
|
+
request, so importing this package never requires the payments core to be installed.
|
|
1487
|
+
|
|
1373
1488
|
```typescript
|
|
1374
1489
|
function billingPortal(): (req: MoleculeRequest) => Promise<
|
|
1375
1490
|
| {
|
|
@@ -1403,7 +1518,7 @@ function handlePaymentNotification({
|
|
|
1403
1518
|
name,
|
|
1404
1519
|
tableName,
|
|
1405
1520
|
schema: _schema,
|
|
1406
|
-
}: types.
|
|
1521
|
+
}: types.HandlerResource): (
|
|
1407
1522
|
req: MoleculeRequest,
|
|
1408
1523
|
) => Promise<{ statusCode: number; body: string } | { statusCode: number; body: { error: string } }>
|
|
1409
1524
|
```
|
|
@@ -1411,7 +1526,7 @@ function handlePaymentNotification({
|
|
|
1411
1526
|
- `resource` — The user resource configuration (name, tableName, schema).
|
|
1412
1527
|
- `resource.name` — The resource name.
|
|
1413
1528
|
- `resource.tableName` — The database table name for users.
|
|
1414
|
-
- `resource.schema` —
|
|
1529
|
+
- `resource.schema` — Optional. Ignored — notifications validate with `updatePlanPropsSchema`.
|
|
1415
1530
|
|
|
1416
1531
|
**Returns:** A request handler for payment provider notifications.
|
|
1417
1532
|
|
|
@@ -1427,8 +1542,11 @@ provider name from the `:provider` route parameter and dispatches based on `veri
|
|
|
1427
1542
|
On successful verification, updates the user's plan (planKey, planExpiresAt, planAutoRenews)
|
|
1428
1543
|
and stores the payment record via the bonded PaymentRecordService.
|
|
1429
1544
|
|
|
1545
|
+
`@molecule/api-payments` is an OPTIONAL peer: the config-error helper is loaded lazily in
|
|
1546
|
+
the catch, so importing this package never requires the payments core to be installed.
|
|
1547
|
+
|
|
1430
1548
|
```typescript
|
|
1431
|
-
function verifyPayment({ name, tableName, schema: _schema }: types.
|
|
1549
|
+
function verifyPayment({ name, tableName, schema: _schema }: types.HandlerResource): (
|
|
1432
1550
|
req: MoleculeRequest,
|
|
1433
1551
|
) => Promise<
|
|
1434
1552
|
| { statusCode: number; body: { error: string; errorKey: string; props?: undefined } }
|
|
@@ -1450,7 +1568,7 @@ function verifyPayment({ name, tableName, schema: _schema }: types.Resource<unkn
|
|
|
1450
1568
|
- `resource` — The user resource configuration (name, tableName, schema).
|
|
1451
1569
|
- `resource.name` — The resource name.
|
|
1452
1570
|
- `resource.tableName` — The database table name for users.
|
|
1453
|
-
- `resource.schema` —
|
|
1571
|
+
- `resource.schema` — Optional. Ignored — plan fields are written directly after provider verification.
|
|
1454
1572
|
|
|
1455
1573
|
**Returns:** A request handler for payment verification.
|
|
1456
1574
|
|
|
@@ -1465,7 +1583,7 @@ function read({
|
|
|
1465
1583
|
name: _name,
|
|
1466
1584
|
tableName,
|
|
1467
1585
|
schema: _schema,
|
|
1468
|
-
}: types.
|
|
1586
|
+
}: types.HandlerResource): (
|
|
1469
1587
|
req: MoleculeRequest,
|
|
1470
1588
|
res: MoleculeResponse,
|
|
1471
1589
|
) => Promise<{ statusCode: number; body: Record<string, unknown> }>
|
|
@@ -1474,7 +1592,7 @@ function read({
|
|
|
1474
1592
|
- `resource` — The user resource configuration (name, tableName, schema).
|
|
1475
1593
|
- `resource.name` — The resource name.
|
|
1476
1594
|
- `resource.tableName` — The database table name for users.
|
|
1477
|
-
- `resource.schema` —
|
|
1595
|
+
- `resource.schema` — Optional. Ignored — reads do not validate props.
|
|
1478
1596
|
|
|
1479
1597
|
**Returns:** A request handler that responds with `{ statusCode: 200, body: { props, plan?, twoFactorEnabled? } }`.
|
|
1480
1598
|
|
|
@@ -1502,13 +1620,13 @@ NEVER gets this field: exposing that token to JavaScript would defeat the cookie
|
|
|
1502
1620
|
```typescript
|
|
1503
1621
|
function readSelf({
|
|
1504
1622
|
tableName,
|
|
1505
|
-
}: types.
|
|
1623
|
+
}: types.HandlerResource): (
|
|
1506
1624
|
_req: MoleculeRequest,
|
|
1507
1625
|
res: MoleculeResponse,
|
|
1508
1626
|
) => Promise<{ statusCode: number; body: Record<string, unknown> }>
|
|
1509
1627
|
```
|
|
1510
1628
|
|
|
1511
|
-
- `resource` — The user resource configuration
|
|
1629
|
+
- `resource` — The user resource configuration: `{ name, tableName, schema? }` (`name` and `schema` are optional here).
|
|
1512
1630
|
- `resource.tableName` — The database table name for users.
|
|
1513
1631
|
|
|
1514
1632
|
**Returns:** A request handler responding `{ statusCode: 200, body: { props, plan?, twoFactorEnabled?, accessToken? } }`, or 401 when unauthenticated.
|
|
@@ -1561,7 +1679,7 @@ function resetPassword({
|
|
|
1561
1679
|
name: _name,
|
|
1562
1680
|
tableName,
|
|
1563
1681
|
schema: _schema,
|
|
1564
|
-
}: types.
|
|
1682
|
+
}: types.HandlerResource): (
|
|
1565
1683
|
req: ResetPasswordRequest,
|
|
1566
1684
|
) => Promise<
|
|
1567
1685
|
| { statusCode: number; body: { error: string; errorKey: string; success?: undefined } }
|
|
@@ -1571,6 +1689,7 @@ function resetPassword({
|
|
|
1571
1689
|
|
|
1572
1690
|
- `resource` — The user resource configuration (name, tableName, schema).
|
|
1573
1691
|
- `resource.tableName` — The database table name for users.
|
|
1692
|
+
- `resource.schema` — Optional. Ignored — the reset flow writes the password hash directly.
|
|
1574
1693
|
|
|
1575
1694
|
**Returns:** A request handler that responds with `{ statusCode: 200, body: { success: true } }` on success.
|
|
1576
1695
|
|
|
@@ -1579,11 +1698,24 @@ function resetPassword({
|
|
|
1579
1698
|
Updates a user's profile fields (username, name, email). Validates username format
|
|
1580
1699
|
(alphanumeric, max 255 chars), email format, and uniqueness of both fields against
|
|
1581
1700
|
other users before delegating to the resource update utility.
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1701
|
+
`schema` is optional and NOT used here: this handler validates the partial update with the
|
|
1702
|
+
package's own `extendedUpdatePropsSchema` (username, name, email, avatar, bio, plus
|
|
1703
|
+
`oauthData`), so callers need not invent one. Statuses: 200 updated props; 400 for an invalid
|
|
1704
|
+
username/email, an oversized avatar/bio, a malformed `oauthData`, a missing `currentPassword`,
|
|
1705
|
+
or no updatable fields; 403 `user.error.usernameUnavailable` / `user.error.emailAlreadyRegistered`
|
|
1706
|
+
/ `user.error.currentPasswordIncorrect`; 500 `user.error.failedToUpdateUser`.
|
|
1707
|
+
|
|
1708
|
+
**A change to `email` is re-authenticated.** On an account that has a password, changing OR
|
|
1709
|
+
clearing the address requires that account's `currentPassword` in the same flat body — 400
|
|
1710
|
+
`user.error.currentPasswordRequired` when it is missing, 403
|
|
1711
|
+
`user.error.currentPasswordIncorrect` when it does not match. A real change sets
|
|
1712
|
+
`emailVerified` to `false` server-side (the new address is unproven; the flag is never read
|
|
1713
|
+
from the body). An OAuth-only account has no password hash, so its provider-backed session is
|
|
1714
|
+
the credential. Do NOT skip the gate by writing `email` through the datastore instead: return
|
|
1715
|
+
the 400 and let the client collect the current password (a re-authentication step).
|
|
1716
|
+
|
|
1717
|
+
```typescript
|
|
1718
|
+
function update({ name, tableName }: types.HandlerResource): (req: MoleculeRequest) => Promise<
|
|
1587
1719
|
| { statusCode: number; body: { error: string; errorKey: string; props?: undefined } }
|
|
1588
1720
|
| {
|
|
1589
1721
|
statusCode: number
|
|
@@ -1596,10 +1728,10 @@ function update({ name, tableName, schema: _schema }: types.Resource<unknown>):
|
|
|
1596
1728
|
>
|
|
1597
1729
|
```
|
|
1598
1730
|
|
|
1599
|
-
- `resource` — The user resource configuration
|
|
1600
|
-
- `resource.name` — The resource name.
|
|
1731
|
+
- `resource` — The user resource configuration: `{ name, tableName, schema? }`.
|
|
1732
|
+
- `resource.name` — The resource name used in error messages.
|
|
1601
1733
|
- `resource.tableName` — The database table name for users.
|
|
1602
|
-
- `resource.schema` —
|
|
1734
|
+
- `resource.schema` — Optional. Ignored — updates validate with this package's update schema.
|
|
1603
1735
|
|
|
1604
1736
|
**Returns:** A request handler that responds with the updated user props on success.
|
|
1605
1737
|
|
|
@@ -1622,21 +1754,31 @@ Updates a user's password. If the user already has a password hash, the current
|
|
|
1622
1754
|
must be provided and verified first. The new password is hashed via `@molecule/api-password`
|
|
1623
1755
|
and stored in the secrets table.
|
|
1624
1756
|
|
|
1757
|
+
**Body and results.** The flat body needs `newPassword` (8–1024 characters) and, on an
|
|
1758
|
+
account that ALREADY has a password (the password-signup case), `currentPassword` too —
|
|
1759
|
+
there is no variant that changes a password account's password from `newPassword` alone.
|
|
1760
|
+
Missing current password → 400 `user.error.currentPasswordRequired`; wrong → 403
|
|
1761
|
+
`user.error.currentPasswordIncorrect`; an invalid new password is 400
|
|
1762
|
+
`user.error.newPasswordRequired` / `user.error.passwordTooShort` /
|
|
1763
|
+
`user.error.passwordTooLong`. Only an account with no password hash (OAuth-only) may omit
|
|
1764
|
+
`currentPassword`. Success is 200 `{ success: true }` and also clears any outstanding reset
|
|
1765
|
+
token. Never cache or replay the login password to satisfy this check.
|
|
1766
|
+
|
|
1625
1767
|
**Every OTHER session is revoked; the caller's own is kept.** The device rows of all other
|
|
1626
1768
|
devices are deleted, so a stolen token on another device dies — but the device this request
|
|
1627
1769
|
arrived on stays, and the token that made the request (the `Authorization` header the client
|
|
1628
1770
|
is holding) keeps working. A RealWorld-style suite changes the password and then keeps using
|
|
1629
1771
|
the same token for the next request; revoking the caller too is what answered its second
|
|
1630
1772
|
`PUT /user` with 401 (xr-flash-m167, ~2 min lost). Do not fold a per-user secret into the
|
|
1631
|
-
|
|
1632
|
-
|
|
1773
|
+
|
|
1774
|
+
_(description truncated — read the full text in `node_modules/@molecule/api-resource-user/dist/handlers/updatePassword.d.ts`.)_
|
|
1633
1775
|
|
|
1634
1776
|
```typescript
|
|
1635
1777
|
function updatePassword({
|
|
1636
1778
|
name: _name,
|
|
1637
1779
|
tableName,
|
|
1638
1780
|
schema: _schema,
|
|
1639
|
-
}: types.
|
|
1781
|
+
}: types.HandlerResource): (
|
|
1640
1782
|
req: UpdatePasswordRequest,
|
|
1641
1783
|
res?: MoleculeResponse,
|
|
1642
1784
|
) => Promise<
|
|
@@ -1648,7 +1790,7 @@ function updatePassword({
|
|
|
1648
1790
|
- `resource` — The user resource configuration (name, tableName, schema).
|
|
1649
1791
|
- `resource.name` — The resource name.
|
|
1650
1792
|
- `resource.tableName` — The database table name for users.
|
|
1651
|
-
- `resource.schema` —
|
|
1793
|
+
- `resource.schema` — Optional. Ignored — this handler writes the password hash directly.
|
|
1652
1794
|
|
|
1653
1795
|
**Returns:** A request handler that responds with `{ statusCode: 200, body: { success: true } }` on success.
|
|
1654
1796
|
|
|
@@ -1680,8 +1822,12 @@ cross-platform subscription cancellation when switching providers. Returns a che
|
|
|
1680
1822
|
(status 201) for new subscriptions, or directly updates the user record for in-place changes
|
|
1681
1823
|
and free plan downgrades.
|
|
1682
1824
|
|
|
1825
|
+
`@molecule/api-payments` is an OPTIONAL peer: its `isConfigNotConfiguredError` helper is
|
|
1826
|
+
loaded lazily inside the catch, so an app that installs no payments package can still import
|
|
1827
|
+
(and boot) this resource — the free-plan path and every non-payment route keep working.
|
|
1828
|
+
|
|
1683
1829
|
```typescript
|
|
1684
|
-
function updatePlan({ name, tableName, schema: _schema }: types.
|
|
1830
|
+
function updatePlan({ name, tableName, schema: _schema }: types.HandlerResource): (
|
|
1685
1831
|
req: UpdatePlanRequest,
|
|
1686
1832
|
) => Promise<
|
|
1687
1833
|
| { statusCode: number; body: { error: string; errorKey: string; props?: undefined } }
|
|
@@ -1700,7 +1846,7 @@ function updatePlan({ name, tableName, schema: _schema }: types.Resource<unknown
|
|
|
1700
1846
|
- `resource` — The user resource configuration (name, tableName, schema).
|
|
1701
1847
|
- `resource.name` — The resource name.
|
|
1702
1848
|
- `resource.tableName` — The database table name for users.
|
|
1703
|
-
- `resource.schema` —
|
|
1849
|
+
- `resource.schema` — Optional. Ignored — plan updates validate with `updatePlanPropsSchema`.
|
|
1704
1850
|
|
|
1705
1851
|
**Returns:** A request handler for plan updates.
|
|
1706
1852
|
|
|
@@ -1726,7 +1872,7 @@ Handles two-factor authentication lifecycle via `@molecule/api-two-factor`:
|
|
|
1726
1872
|
- `disable`: Verifies a TOTP token against the active secret, then deactivates 2FA.
|
|
1727
1873
|
|
|
1728
1874
|
```typescript
|
|
1729
|
-
function verifyTwoFactor({ name: _name, tableName, schema: _schema }: types.
|
|
1875
|
+
function verifyTwoFactor({ name: _name, tableName, schema: _schema }: types.HandlerResource): (
|
|
1730
1876
|
req: VerifyTwoFactorRequest,
|
|
1731
1877
|
) => Promise<
|
|
1732
1878
|
| { statusCode: number; body: { error: string; errorKey: string; twoFactorEnabled?: undefined } }
|
|
@@ -1751,7 +1897,7 @@ function verifyTwoFactor({ name: _name, tableName, schema: _schema }: types.Reso
|
|
|
1751
1897
|
- `resource` — The user resource configuration (name, tableName, schema).
|
|
1752
1898
|
- `resource.name` — The resource name.
|
|
1753
1899
|
- `resource.tableName` — The database table name for users.
|
|
1754
|
-
- `resource.schema` —
|
|
1900
|
+
- `resource.schema` — Optional. Ignored — 2FA state is written to the secrets table directly.
|
|
1755
1901
|
|
|
1756
1902
|
**Returns:** A request handler for two-factor authentication operations.
|
|
1757
1903
|
|
|
@@ -1856,6 +2002,42 @@ An object describing the `user` resource.
|
|
|
1856
2002
|
type Resource<T = unknown> = resourceTypes.Resource<T>
|
|
1857
2003
|
```
|
|
1858
2004
|
|
|
2005
|
+
##### `types.HandlerResource`
|
|
2006
|
+
|
|
2007
|
+
Configuration accepted by every user handler factory (`handlers.create`,
|
|
2008
|
+
`handlers.logIn`, `handlers.update`, …).
|
|
2009
|
+
|
|
2010
|
+
`name` and `tableName` are the caller's to supply, because an app may mount the
|
|
2011
|
+
user resource on its own table. `schema` is OPTIONAL — no factory requires you
|
|
2012
|
+
to invent one:
|
|
2013
|
+
|
|
2014
|
+
- `handlers.create` and `handlers.logInOAuth` validate the props they write and
|
|
2015
|
+
default to this package's {@link propsSchema} when `schema` is omitted.
|
|
2016
|
+
- `handlers.update` validates with the package's `updatePropsSchema` and ignores
|
|
2017
|
+
a supplied `schema`.
|
|
2018
|
+
- The remaining handlers read/write rows directly and never look at `schema`.
|
|
2019
|
+
|
|
2020
|
+
Omission is NOT "no validation": the handlers that validate use
|
|
2021
|
+
{@link propsSchema}. Pass `createResource({ oauthServers, planKeys })` (or the
|
|
2022
|
+
`resource` export) when the app constrains `oauthServer` / `planKey`, and pass
|
|
2023
|
+
your own extended Zod object only when you add fields.
|
|
2024
|
+
|
|
2025
|
+
```typescript
|
|
2026
|
+
interface HandlerResource {
|
|
2027
|
+
/** The resource name used in error messages (e.g. `'User'`). */
|
|
2028
|
+
name: string
|
|
2029
|
+
/** The database table name for users. */
|
|
2030
|
+
tableName: string
|
|
2031
|
+
/**
|
|
2032
|
+
* Optional Zod schema validated by `handlers.create` / `handlers.logInOAuth`.
|
|
2033
|
+
* Defaults to {@link propsSchema}. Must expose `safeParse`; a stub object is not
|
|
2034
|
+
* a schema and the first request answers 400 `resource.error.unknownError` with
|
|
2035
|
+
* `TypeError: schema.safeParse is not a function`.
|
|
2036
|
+
*/
|
|
2037
|
+
schema?: unknown
|
|
2038
|
+
}
|
|
2039
|
+
```
|
|
2040
|
+
|
|
1859
2041
|
#### `utilities`
|
|
1860
2042
|
|
|
1861
2043
|
Re-exported as a namespace — reach every member below through it (e.g. `utilities.<name>`).
|
|
@@ -11,13 +11,27 @@ export interface CreateRequest extends MoleculeRequest {
|
|
|
11
11
|
* Creates a user with username and password. Validates username uniqueness and email format,
|
|
12
12
|
* hashes the password into a separate secrets table, creates a session device via the bonded
|
|
13
13
|
* DeviceService, and sets JWT authorization on the response.
|
|
14
|
-
*
|
|
15
|
-
*
|
|
14
|
+
*
|
|
15
|
+
* **`schema` is optional — omit it and this package's `propsSchema` validates the row.**
|
|
16
|
+
* It must be a Zod object (anything exposing `safeParse`): pass
|
|
17
|
+
* `createResource({ oauthServers, planKeys })` or your own extended schema only when the
|
|
18
|
+
* app constrains or extends user props. A stub such as `schema: {}` is not a schema — the
|
|
19
|
+
* FIRST request answers 400 `resource.error.unknownError` with
|
|
20
|
+
* `TypeError: schema.safeParse is not a function`, after no row has been written.
|
|
21
|
+
*
|
|
22
|
+
* Statuses: 201 `{ props, accessToken, user }`; 400 `user.error.usernameInvalid` /
|
|
23
|
+
* `user.error.bodyNestedUnderUser` / `user.error.passwordRequired` /
|
|
24
|
+
* `user.error.passwordTooLong` / `user.error.passwordTooShort` / `user.error.emailInvalid` /
|
|
25
|
+
* `user.error.badRequest`, or `resource.error.unknownError` when props fail the schema;
|
|
26
|
+
* 403 `user.error.usernameUnavailable` / `user.error.emailAlreadyRegistered`;
|
|
27
|
+
* 500 `user.error.failedToHashPassword` / `user.error.failedToCreateSession`.
|
|
28
|
+
* @param resource - The user resource configuration: `{ name, tableName, schema? }`.
|
|
29
|
+
* @param resource.name - The resource name used in error messages.
|
|
16
30
|
* @param resource.tableName - The database table name for users.
|
|
17
|
-
* @param resource.schema -
|
|
18
|
-
* @returns A request handler that responds with `{ statusCode: 201, body: { props } }` on success.
|
|
31
|
+
* @param resource.schema - Optional Zod schema for the created user props. Defaults to `propsSchema`.
|
|
32
|
+
* @returns A request handler that responds with `{ statusCode: 201, body: { props, accessToken, user } }` on success.
|
|
19
33
|
*/
|
|
20
|
-
export declare const create: ({ name, tableName, schema }: types.
|
|
34
|
+
export declare const create: ({ name, tableName, schema }: types.HandlerResource) => (req: CreateRequest, res: MoleculeResponse) => Promise<{
|
|
21
35
|
statusCode: number;
|
|
22
36
|
body: {
|
|
23
37
|
error: string;
|
|
@@ -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;
|
|
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"}
|
package/dist/handlers/create.js
CHANGED
|
@@ -5,6 +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
9
|
import { normalizeEmail } from '../utilities/normalizeEmail.js';
|
|
9
10
|
import { stripSensitiveUserColumns } from '../utilities/stripSensitiveUserColumns.js';
|
|
10
11
|
import { isNestedBody, USERNAME_RE } from '../utilities/username.js';
|
|
@@ -14,13 +15,27 @@ const logger = getLogger();
|
|
|
14
15
|
* Creates a user with username and password. Validates username uniqueness and email format,
|
|
15
16
|
* hashes the password into a separate secrets table, creates a session device via the bonded
|
|
16
17
|
* DeviceService, and sets JWT authorization on the response.
|
|
17
|
-
*
|
|
18
|
-
*
|
|
18
|
+
*
|
|
19
|
+
* **`schema` is optional — omit it and this package's `propsSchema` validates the row.**
|
|
20
|
+
* It must be a Zod object (anything exposing `safeParse`): pass
|
|
21
|
+
* `createResource({ oauthServers, planKeys })` or your own extended schema only when the
|
|
22
|
+
* app constrains or extends user props. A stub such as `schema: {}` is not a schema — the
|
|
23
|
+
* FIRST request answers 400 `resource.error.unknownError` with
|
|
24
|
+
* `TypeError: schema.safeParse is not a function`, after no row has been written.
|
|
25
|
+
*
|
|
26
|
+
* Statuses: 201 `{ props, accessToken, user }`; 400 `user.error.usernameInvalid` /
|
|
27
|
+
* `user.error.bodyNestedUnderUser` / `user.error.passwordRequired` /
|
|
28
|
+
* `user.error.passwordTooLong` / `user.error.passwordTooShort` / `user.error.emailInvalid` /
|
|
29
|
+
* `user.error.badRequest`, or `resource.error.unknownError` when props fail the schema;
|
|
30
|
+
* 403 `user.error.usernameUnavailable` / `user.error.emailAlreadyRegistered`;
|
|
31
|
+
* 500 `user.error.failedToHashPassword` / `user.error.failedToCreateSession`.
|
|
32
|
+
* @param resource - The user resource configuration: `{ name, tableName, schema? }`.
|
|
33
|
+
* @param resource.name - The resource name used in error messages.
|
|
19
34
|
* @param resource.tableName - The database table name for users.
|
|
20
|
-
* @param resource.schema -
|
|
21
|
-
* @returns A request handler that responds with `{ statusCode: 201, body: { props } }` on success.
|
|
35
|
+
* @param resource.schema - Optional Zod schema for the created user props. Defaults to `propsSchema`.
|
|
36
|
+
* @returns A request handler that responds with `{ statusCode: 201, body: { props, accessToken, user } }` on success.
|
|
22
37
|
*/
|
|
23
|
-
export const create = ({ name, tableName, schema }) => {
|
|
38
|
+
export const create = ({ name, tableName, schema = propsSchema }) => {
|
|
24
39
|
const createResource = resourceCreate({
|
|
25
40
|
name,
|
|
26
41
|
tableName,
|
|
@@ -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;AAEjC,OAAO,EAAE,GAAG,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AACjE,OAAO,EAAE,MAAM,IAAI,WAAW,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAA;AACvE,OAAO,EAAE,CAAC,EAAE,MAAM,oBAAoB,CAAA;AACtC,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAA;AAE7C,OAAO,EAAE,MAAM,IAAI,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAGjE,OAAO,KAAK,aAAa,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"create.js","sourceRoot":"","sources":["../../src/handlers/create.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAA;AAEjC,OAAO,EAAE,GAAG,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AACjE,OAAO,EAAE,MAAM,IAAI,WAAW,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAA;AACvE,OAAO,EAAE,CAAC,EAAE,MAAM,oBAAoB,CAAA;AACtC,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAA;AAE7C,OAAO,EAAE,MAAM,IAAI,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAGjE,OAAO,KAAK,aAAa,MAAM,qBAAqB,CAAA;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAE1C,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAA;AAC/D,OAAO,EAAE,yBAAyB,EAAE,MAAM,2CAA2C,CAAA;AAC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E,UAAU,EAAE,EAAE,CAAC;qBAC9E,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAA;gBAClB,SAAS;qBACN,QAAQ,CAAC;oBACR,MAAM,EAAE,EAAE;oBACV,KAAK,EAAE,KAAK,CAAC,KAAK,IAAI,SAAS;oBAC/B,IAAI,EAAE,KAAK,CAAC,IAAI,IAAI,SAAS;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"}
|
package/dist/handlers/del.d.ts
CHANGED
|
@@ -14,10 +14,10 @@ import type * as types from '../types.js';
|
|
|
14
14
|
* @param resource - The user resource configuration (name, tableName, schema).
|
|
15
15
|
* @param resource.name - The resource name.
|
|
16
16
|
* @param resource.tableName - The database table name for users.
|
|
17
|
-
* @param resource.schema -
|
|
17
|
+
* @param resource.schema - Optional. Ignored — deletion does not validate props.
|
|
18
18
|
* @returns A request handler that responds with `{ statusCode: 200, body: { props: { id } } }` on success.
|
|
19
19
|
*/
|
|
20
|
-
export declare const del: ({ name: _name, tableName, schema: _schema }: types.
|
|
20
|
+
export declare const del: ({ name: _name, tableName, schema: _schema }: types.HandlerResource) => (req: MoleculeRequest) => Promise<{
|
|
21
21
|
statusCode: number;
|
|
22
22
|
body: {
|
|
23
23
|
error: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"del.d.ts","sourceRoot":"","sources":["../../src/handlers/del.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAG7D,OAAO,KAAK,KAAK,KAAK,MAAM,aAAa,CAAA;AAKzC;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,GAAG,GAAI,6CAA6C,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"del.d.ts","sourceRoot":"","sources":["../../src/handlers/del.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAG7D,OAAO,KAAK,KAAK,KAAK,MAAM,aAAa,CAAA;AAKzC;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,GAAG,GAAI,6CAA6C,KAAK,CAAC,eAAe,MACtE,KAAK,eAAe;;;;;;;;;;;;;;;;EAmDnC,CAAA"}
|