@molecule/api-resource-user 1.7.5 → 1.8.0
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 +250 -30
- package/dist/handlers/create.d.ts.map +1 -1
- package/dist/handlers/create.js +5 -5
- package/dist/handlers/create.js.map +1 -1
- package/dist/index.d.ts +42 -29
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +42 -29
- package/dist/index.js.map +1 -1
- package/dist/provisioning.d.ts +245 -0
- package/dist/provisioning.d.ts.map +1 -0
- package/dist/provisioning.js +585 -0
- package/dist/provisioning.js.map +1 -0
- package/dist/schema.d.ts +11 -0
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +11 -0
- package/dist/schema.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,585 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Programmatic user provisioning for trusted server code.
|
|
3
|
+
*
|
|
4
|
+
* `provisionUser(resource, input)` writes the `users` row AND its same-id `usersSecrets` row
|
|
5
|
+
* through the bonded database and password providers, so a seed script, a migration, or a
|
|
6
|
+
* service-account bootstrap never hand-writes the two-table credential plumbing:
|
|
7
|
+
*
|
|
8
|
+
* - **One id keys BOTH rows.** `usersSecrets.id` IS the user's id. A credential row written
|
|
9
|
+
* under another id inserts fine and is then never found again — login answers "invalid
|
|
10
|
+
* credentials" while `GET /users/me` still answers 200.
|
|
11
|
+
* - **Props are validated ONCE, before the identity lookup.** The resource schema does the
|
|
12
|
+
* parsing, including any `transform`/`default` a caller's schema adds
|
|
13
|
+
* (`createSchema().extend({ username: z.string().toLowerCase() })`). The account is looked up
|
|
14
|
+
* by the value the schema actually produces, and that same value is what gets stored — so two
|
|
15
|
+
* `EDITOR` provisioning calls find one `editor` account instead of inserting a second row.
|
|
16
|
+
* - **No session.** No device row, no JWT, no `authorization.set`: provisioning an account
|
|
17
|
+
* never signs anyone in, and the caller keeps whatever auth flow it already has.
|
|
18
|
+
* - **No password unless you supply one.** Omit `password` for a content author or service
|
|
19
|
+
* account that must not be able to log in — the credential row is written WITHOUT a
|
|
20
|
+
* `passwordHash` (the OAuth-only shape `logIn` refuses a password for). Nothing is generated,
|
|
21
|
+
* nothing is returned, and there is no default password.
|
|
22
|
+
* - **Idempotent by username or email.** An account that already exists is answered
|
|
23
|
+
* `{ status: 'existing' }` and nothing is written — credentials included: a supplied password
|
|
24
|
+
* is applied only to the row THIS call creates, never to an existing account. (A seed whose
|
|
25
|
+
* email matches a real user's must never hand over that account.)
|
|
26
|
+
* - **Atomic where the database supports it.** The two writes run inside
|
|
27
|
+
* `withTransaction()`, so a bond with interactive transactions (SQLite, PostgreSQL, MySQL)
|
|
28
|
+
* commits both rows or neither. On a bond without them (Cloudflare D1, where
|
|
29
|
+
* `pool.transaction` is absent) the writes are sequential and a failed second write leaves the
|
|
30
|
+
* user row in place; that case is answered by a distinct `{ status: 'partial', id, recovery }`
|
|
31
|
+
* result, and `provisionUser(resource, { props, password, completeId: id })` completes it. A
|
|
32
|
+
* retry WITHOUT `completeId` answers `existing` and does NOT repair anything (password reset
|
|
33
|
+
* cannot either: it updates the `usersSecrets` row, which does not exist).
|
|
34
|
+
*
|
|
35
|
+
* TRUSTED SERVER CALLERS ONLY. This is not a request handler: it takes props directly and
|
|
36
|
+
* validates them against the resource schema, so mounting it on a route would be a
|
|
37
|
+
* mass-assignment hole. Create accounts from a seed or migration on the server — never from a
|
|
38
|
+
* public endpoint.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* import { provisionUser } from '@molecule/api-resource-user'
|
|
43
|
+
*
|
|
44
|
+
* // A content-only author: no password is stored and no login is possible.
|
|
45
|
+
* const author = await provisionUser(
|
|
46
|
+
* { name: 'User', tableName: 'users' },
|
|
47
|
+
* { props: { username: 'editor', name: 'Editorial Team' } },
|
|
48
|
+
* )
|
|
49
|
+
* if (author.status === 'failed') throw new Error(author.error)
|
|
50
|
+
* if (author.status === 'partial') {
|
|
51
|
+
* // The id is the proof of ownership; the props identify the same account.
|
|
52
|
+
* await provisionUser(
|
|
53
|
+
* { name: 'User', tableName: 'users' },
|
|
54
|
+
* { props: { username: 'editor' }, completeId: author.id },
|
|
55
|
+
* )
|
|
56
|
+
* }
|
|
57
|
+
* const authorId = author.id // stable across re-runs: the second call says 'existing'
|
|
58
|
+
*
|
|
59
|
+
* // A service account that may actually sign in (password from the environment, never a literal).
|
|
60
|
+
* await provisionUser(
|
|
61
|
+
* { name: 'User', tableName: 'users' },
|
|
62
|
+
* { props: { username: 'sync-service', email: 'sync@example.com' }, password: process.env.SYNC_PASSWORD },
|
|
63
|
+
* )
|
|
64
|
+
* ```
|
|
65
|
+
*
|
|
66
|
+
* @module
|
|
67
|
+
*/
|
|
68
|
+
import { v4 as uuid } from 'uuid';
|
|
69
|
+
import { getLogger } from '@molecule/api-bond';
|
|
70
|
+
import { create as storeCreate, findById, findOne, getPool, hasPool, updateMany, withTransaction, } from '@molecule/api-database';
|
|
71
|
+
import { t } from '@molecule/api-i18n';
|
|
72
|
+
import { hash } from '@molecule/api-password';
|
|
73
|
+
import { utilities } from '@molecule/api-resource';
|
|
74
|
+
import { MAX_PASSWORD_LENGTH, MIN_PASSWORD_LENGTH, propsSchema } from './schema.js';
|
|
75
|
+
import { normalizeEmail } from './utilities/normalizeEmail.js';
|
|
76
|
+
import { stripSensitiveUserColumns } from './utilities/stripSensitiveUserColumns.js';
|
|
77
|
+
import { USERNAME_RE } from './utilities/username.js';
|
|
78
|
+
const logger = getLogger();
|
|
79
|
+
/** Longest username `provisionUser` will store, matching the signup handler's cap. */
|
|
80
|
+
const MAX_USERNAME_LENGTH = 255;
|
|
81
|
+
/** Longest email `provisionUser` will store, matching the signup handler's cap. */
|
|
82
|
+
const MAX_EMAIL_LENGTH = 1023;
|
|
83
|
+
/**
|
|
84
|
+
* Builds a `failed` result, omitting `id` when this call wrote no user row.
|
|
85
|
+
* @param reason - Which step failed.
|
|
86
|
+
* @param errorKey - The stable error key.
|
|
87
|
+
* @param error - The diagnostic message.
|
|
88
|
+
* @param id - The id of a user row this call created, when one exists.
|
|
89
|
+
* @returns The failure result.
|
|
90
|
+
*/
|
|
91
|
+
const failed = (reason, errorKey, error, id) => {
|
|
92
|
+
const failure = { status: 'failed', reason, errorKey, error };
|
|
93
|
+
return id ? { ...failure, id } : failure;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Turns a thrown value into the diagnostic string a result carries.
|
|
97
|
+
* @param error - The thrown value.
|
|
98
|
+
* @returns The message, or a stringified value.
|
|
99
|
+
*/
|
|
100
|
+
const messageOf = (error) => error instanceof Error ? error.message : String(error);
|
|
101
|
+
/**
|
|
102
|
+
* Whether the bonded database can run the two writes in one transaction.
|
|
103
|
+
*
|
|
104
|
+
* `withTransaction()` throws on Cloudflare D1, whose pool deliberately leaves `transaction`
|
|
105
|
+
* undefined; the shared API documents that check. A store bonded without a pool has the same
|
|
106
|
+
* sequential shape.
|
|
107
|
+
* @returns `true` when `withTransaction()` will work here.
|
|
108
|
+
*/
|
|
109
|
+
const supportsTransactions = () => {
|
|
110
|
+
if (!hasPool())
|
|
111
|
+
return false;
|
|
112
|
+
try {
|
|
113
|
+
return typeof getPool().transaction === 'function';
|
|
114
|
+
}
|
|
115
|
+
catch (_error) {
|
|
116
|
+
// `hasPool()` said a pool exists, so a throw here means the bond is unusable; refusing the
|
|
117
|
+
// transaction is the safe answer and the sequential path reports the real failure.
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* Reads an existing account's credential row and answers `existing`.
|
|
123
|
+
*
|
|
124
|
+
* Reads only whether a `passwordHash` is present — never the hash, and never a write.
|
|
125
|
+
* @param tableName - The users table name (its secrets table is `${tableName}Secrets`).
|
|
126
|
+
* @param row - The existing `users` row.
|
|
127
|
+
* @returns An `existing` result, or a `lookupFailed` result when the credential row cannot be read.
|
|
128
|
+
*/
|
|
129
|
+
const existingAccount = async (tableName, row) => {
|
|
130
|
+
let secrets;
|
|
131
|
+
try {
|
|
132
|
+
secrets = await findById(`${tableName}Secrets`, row.id);
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
logger.error('Failed to read a user credential row while provisioning', {
|
|
136
|
+
error,
|
|
137
|
+
userId: row.id,
|
|
138
|
+
});
|
|
139
|
+
return failed('lookupFailed', 'user.error.failedToReadUser', t('user.error.failedToReadUser'), row.id);
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
status: 'existing',
|
|
143
|
+
id: row.id,
|
|
144
|
+
props: stripSensitiveUserColumns(row),
|
|
145
|
+
hasPassword: Boolean(secrets?.passwordHash),
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
/**
|
|
149
|
+
* The condition that matches ONLY the hashless credential state this call observed.
|
|
150
|
+
*
|
|
151
|
+
* A real bond returns `null` for a NULL column (SQLite, D1, PostgreSQL and MySQL alike), while an
|
|
152
|
+
* abstract provider may omit the key entirely; both mean SQL `IS NULL`. Any other falsy value is
|
|
153
|
+
* matched by equality, so an empty string is a distinct observed state rather than silently
|
|
154
|
+
* treated as NULL — the conditional write then replaces exactly what was read, or nothing.
|
|
155
|
+
* @param observed - The `passwordHash` value read from the credential row.
|
|
156
|
+
* @returns The `passwordHash` filter for a compare-and-swap update.
|
|
157
|
+
*/
|
|
158
|
+
const observedHashlessCondition = (observed) => observed === undefined || observed === null
|
|
159
|
+
? { field: 'passwordHash', operator: 'is_null' }
|
|
160
|
+
: { field: 'passwordHash', operator: '=', value: observed };
|
|
161
|
+
/**
|
|
162
|
+
* Finishes a provisioning this caller started: writes the credential row a `partial` result
|
|
163
|
+
* could not, or adds the password the caller tried to store.
|
|
164
|
+
*
|
|
165
|
+
* The `id` is the ownership proof — only the call that created the row has it. The account must
|
|
166
|
+
* still be identified by the supplied props and must not be OAuth-linked, and a stored password
|
|
167
|
+
* is NEVER replaced (an account that already has one is answered `existing`).
|
|
168
|
+
*
|
|
169
|
+
* The credential write is CONDITIONAL on the state this call read (a compare-and-swap through the
|
|
170
|
+
* shared `updateMany`): a concurrent completion, or a password reset, that wrote a hash while this
|
|
171
|
+
* call was hashing makes the condition match no row, so that credential survives. The result then
|
|
172
|
+
* reports the state that is actually stored — `completed` is only ever returned for a write THIS
|
|
173
|
+
* call made.
|
|
174
|
+
* @param tableName - The users table name (its secrets table is `${tableName}Secrets`).
|
|
175
|
+
* @param completeId - The id from the earlier `partial` result.
|
|
176
|
+
* @param username - The validated username the caller supplied, if any.
|
|
177
|
+
* @param email - The normalized email the caller supplied, if any.
|
|
178
|
+
* @param password - The password to store, when the account should be able to sign in.
|
|
179
|
+
* @returns A `completed` result (or `existing` when there is nothing to write), else a typed failure.
|
|
180
|
+
*/
|
|
181
|
+
const completeProvisioning = async ({ tableName, completeId, username, email, password, }) => {
|
|
182
|
+
let row;
|
|
183
|
+
try {
|
|
184
|
+
row = await findById(tableName, completeId);
|
|
185
|
+
}
|
|
186
|
+
catch (error) {
|
|
187
|
+
logger.error('Failed to read the account named by completeId', { error, userId: completeId });
|
|
188
|
+
return failed('lookupFailed', 'user.error.failedToReadUser', t('user.error.failedToReadUser'));
|
|
189
|
+
}
|
|
190
|
+
if (!row) {
|
|
191
|
+
return failed('completeTargetMissing', 'user.error.badRequest', t('user.error.badRequest', undefined, {
|
|
192
|
+
defaultValue: 'No account exists with the id supplied as completeId.',
|
|
193
|
+
}));
|
|
194
|
+
}
|
|
195
|
+
const storedUsername = typeof row.username === 'string' ? row.username : undefined;
|
|
196
|
+
const storedEmail = normalizeEmail(typeof row.email === 'string' ? row.email : undefined);
|
|
197
|
+
if ((username !== undefined && storedUsername !== username) ||
|
|
198
|
+
(email !== undefined && storedEmail !== email)) {
|
|
199
|
+
return failed('completeIdentityMismatch', 'user.error.badRequest', t('user.error.badRequest', undefined, {
|
|
200
|
+
defaultValue: 'The supplied username or email does not identify the completeId account.',
|
|
201
|
+
}));
|
|
202
|
+
}
|
|
203
|
+
if (row.oauthServer) {
|
|
204
|
+
return failed('completeNotOwned', 'user.error.badRequest', t('user.error.badRequest', undefined, {
|
|
205
|
+
defaultValue: 'The completeId account signs in through OAuth; its credentials are not provisioned here.',
|
|
206
|
+
}));
|
|
207
|
+
}
|
|
208
|
+
let secrets;
|
|
209
|
+
try {
|
|
210
|
+
secrets = await findById(`${tableName}Secrets`, completeId);
|
|
211
|
+
}
|
|
212
|
+
catch (error) {
|
|
213
|
+
logger.error('Failed to read a credential row while completing provisioning', {
|
|
214
|
+
error,
|
|
215
|
+
userId: completeId,
|
|
216
|
+
});
|
|
217
|
+
return failed('lookupFailed', 'user.error.failedToReadUser', t('user.error.failedToReadUser'), completeId);
|
|
218
|
+
}
|
|
219
|
+
const props = stripSensitiveUserColumns(row);
|
|
220
|
+
// The credential state this call OBSERVED, captured before hashing. The conditional write below
|
|
221
|
+
// must match what was read here, never a value re-read off the row later — a provider is free to
|
|
222
|
+
// hand back a live row object, and another writer may have changed it in between.
|
|
223
|
+
const observedPasswordHash = secrets?.passwordHash;
|
|
224
|
+
// A stored password is authoritative: never overwrite it, even with the completeId token.
|
|
225
|
+
if (observedPasswordHash) {
|
|
226
|
+
return { status: 'existing', id: completeId, props, hasPassword: true };
|
|
227
|
+
}
|
|
228
|
+
// A credential row with no hash is the complete shape for a content-only author.
|
|
229
|
+
if (secrets && password === undefined) {
|
|
230
|
+
return { status: 'existing', id: completeId, props, hasPassword: false };
|
|
231
|
+
}
|
|
232
|
+
let passwordHash;
|
|
233
|
+
if (password !== undefined) {
|
|
234
|
+
try {
|
|
235
|
+
passwordHash = await hash(password);
|
|
236
|
+
}
|
|
237
|
+
catch (error) {
|
|
238
|
+
logger.error('Failed to hash a provisioned user password', { error, userId: completeId });
|
|
239
|
+
return failed('credentialsFailed', 'user.error.failedToHashPassword', t('user.error.failedToHashPassword'), completeId);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
const secretsTable = `${tableName}Secrets`;
|
|
243
|
+
const credentialRow = passwordHash === undefined ? { id: completeId } : { id: completeId, passwordHash };
|
|
244
|
+
/**
|
|
245
|
+
* Reads the credential row back and answers with the state that is ACTUALLY committed.
|
|
246
|
+
*
|
|
247
|
+
* Reached only when a write lost: a concurrent completion or a password reset wrote first, so
|
|
248
|
+
* this call installed nothing. `completed` is never returned here — it would claim a write that
|
|
249
|
+
* did not happen — and the winning credential is never touched.
|
|
250
|
+
* @returns The honest outcome for the stored state.
|
|
251
|
+
*/
|
|
252
|
+
const reportCommittedCredential = async () => {
|
|
253
|
+
let current;
|
|
254
|
+
try {
|
|
255
|
+
current = await findById(secretsTable, completeId);
|
|
256
|
+
}
|
|
257
|
+
catch (error) {
|
|
258
|
+
logger.error('Failed to re-read a credential row after a concurrent write', {
|
|
259
|
+
error,
|
|
260
|
+
userId: completeId,
|
|
261
|
+
});
|
|
262
|
+
return failed('lookupFailed', 'user.error.failedToReadUser', t('user.error.failedToReadUser'), completeId);
|
|
263
|
+
}
|
|
264
|
+
if (!current) {
|
|
265
|
+
// The row is gone: the account's credential row is still missing and this call did not
|
|
266
|
+
// write it, so a partial result with its recovery pointer remains the honest answer.
|
|
267
|
+
return {
|
|
268
|
+
status: 'partial',
|
|
269
|
+
reason: 'credentialsFailed',
|
|
270
|
+
errorKey: 'user.error.failedToCreateUser',
|
|
271
|
+
error: `The ${secretsTable} row changed while this call was completing it.`,
|
|
272
|
+
id: completeId,
|
|
273
|
+
recovery: { id: completeId, passwordRequired: password !== undefined },
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
logger.warn('A concurrent write changed the credential row while completing provisioning', {
|
|
277
|
+
userId: completeId,
|
|
278
|
+
hasPassword: Boolean(current.passwordHash),
|
|
279
|
+
});
|
|
280
|
+
return {
|
|
281
|
+
status: 'existing',
|
|
282
|
+
id: completeId,
|
|
283
|
+
props,
|
|
284
|
+
hasPassword: Boolean(current.passwordHash),
|
|
285
|
+
};
|
|
286
|
+
};
|
|
287
|
+
if (secrets) {
|
|
288
|
+
// Compare-and-swap: replace ONLY the hashless state this call read. A completion or a reset
|
|
289
|
+
// that wrote a hash while this call was hashing makes the condition match no row, so the
|
|
290
|
+
// credential that won survives — an unconditional update would overwrite it.
|
|
291
|
+
let swapped;
|
|
292
|
+
try {
|
|
293
|
+
swapped = await updateMany(secretsTable, [
|
|
294
|
+
{ field: 'id', operator: '=', value: completeId },
|
|
295
|
+
observedHashlessCondition(observedPasswordHash),
|
|
296
|
+
], { passwordHash });
|
|
297
|
+
}
|
|
298
|
+
catch (error) {
|
|
299
|
+
logger.error('Failed to complete a provisioned user credential row', {
|
|
300
|
+
error,
|
|
301
|
+
userId: completeId,
|
|
302
|
+
});
|
|
303
|
+
return failed('credentialsFailed', password === undefined
|
|
304
|
+
? 'user.error.failedToCreateUser'
|
|
305
|
+
: 'user.error.failedToHashPassword', messageOf(error), completeId);
|
|
306
|
+
}
|
|
307
|
+
if (swapped?.affected !== 1)
|
|
308
|
+
return await reportCommittedCredential();
|
|
309
|
+
return { status: 'completed', id: completeId, props, hasPassword: passwordHash !== undefined };
|
|
310
|
+
}
|
|
311
|
+
// No credential row was observed. Two completions can both read that, so the credential table's
|
|
312
|
+
// primary key decides the winner; the loser reports the committed state instead of claiming a
|
|
313
|
+
// write it did not make, and never replaces the winner's hash.
|
|
314
|
+
try {
|
|
315
|
+
const stored = await storeCreate(secretsTable, credentialRow);
|
|
316
|
+
if (!stored?.affected)
|
|
317
|
+
throw new Error(`Failed to write the ${secretsTable} row.`);
|
|
318
|
+
}
|
|
319
|
+
catch (error) {
|
|
320
|
+
logger.error('Failed to complete a provisioned user credential row', {
|
|
321
|
+
error,
|
|
322
|
+
userId: completeId,
|
|
323
|
+
});
|
|
324
|
+
return await reportCommittedCredential();
|
|
325
|
+
}
|
|
326
|
+
return { status: 'completed', id: completeId, props, hasPassword: passwordHash !== undefined };
|
|
327
|
+
};
|
|
328
|
+
/**
|
|
329
|
+
* Creates a user record and its same-id credential record for a trusted server caller, without
|
|
330
|
+
* creating a session.
|
|
331
|
+
*
|
|
332
|
+
* The props are validated ONCE by the resource schema — this package's `propsSchema` unless
|
|
333
|
+
* `schema` is supplied — before the existing-account lookup, so any `transform`/`default` in a
|
|
334
|
+
* caller's schema decides the stored and the looked-up username/email. The user row and its
|
|
335
|
+
* `usersSecrets` row are then written under ONE freshly minted id, inside a transaction when the
|
|
336
|
+
* bonded database supports one. With no `password`, the credential row carries no `passwordHash`
|
|
337
|
+
* at all — the account cannot log in, and there is no default, generated, or returned password.
|
|
338
|
+
*
|
|
339
|
+
* Existing accounts are found by `username` or `email` and returned unchanged (`status:
|
|
340
|
+
* 'existing'`), which makes re-running a seed safe; a supplied password is never applied to an
|
|
341
|
+
* existing account. Where the bond has no interactive transactions and the credential write
|
|
342
|
+
* fails, the result is `{ status: 'partial', id, recovery }` — pass that id back as `completeId`
|
|
343
|
+
* (with the same identity props and the same password) to finish it.
|
|
344
|
+
*
|
|
345
|
+
* Use {@link createResource} when the app constrains or extends user props; omit it otherwise.
|
|
346
|
+
* The `tableName` convention is the one every handler in this package uses: the credential table
|
|
347
|
+
* is `${tableName}Secrets`.
|
|
348
|
+
*
|
|
349
|
+
* @param resource - The user resource configuration: `{ name, tableName, schema? }`.
|
|
350
|
+
* @param resource.name - The resource name used in error messages.
|
|
351
|
+
* @param resource.tableName - The database table for users.
|
|
352
|
+
* @param resource.schema - Optional schema validated before the write. Defaults to `propsSchema`.
|
|
353
|
+
* @param input - The account to provision.
|
|
354
|
+
* @param input.props - The SAFE user props to store (never a secret column).
|
|
355
|
+
* @param input.password - Optional plaintext password to hash into the credential row. Omit it
|
|
356
|
+
* for a content-only author, which then has no password and cannot log in.
|
|
357
|
+
* @param input.completeId - The id from an earlier `partial` result; finishes that provisioning.
|
|
358
|
+
* @returns `{ status: 'created' | 'completed' | 'existing', id, props, hasPassword }` on success,
|
|
359
|
+
* `{ status: 'partial', reason, errorKey, error, id, recovery }` when a user row was written but
|
|
360
|
+
* its credentials were not, or `{ status: 'failed', reason, errorKey, error, id? }` otherwise.
|
|
361
|
+
* @example
|
|
362
|
+
* ```ts
|
|
363
|
+
* const author = await provisionUser({ name: 'User', tableName: 'users' }, {
|
|
364
|
+
* props: { username: 'editor', name: 'Editorial Team' },
|
|
365
|
+
* })
|
|
366
|
+
* if (author.status === 'failed') throw new Error(author.error)
|
|
367
|
+
* await create('articles', { id: articleId, authorId: author.id, title, body })
|
|
368
|
+
* ```
|
|
369
|
+
*/
|
|
370
|
+
export const provisionUser = async ({ name, tableName, schema = propsSchema }, { props, password, completeId }) => {
|
|
371
|
+
// Password policy FIRST: the same bounds signup enforces, checked before any write so a
|
|
372
|
+
// refused password leaves no half-provisioned account behind.
|
|
373
|
+
if (password !== undefined) {
|
|
374
|
+
if (typeof password !== 'string') {
|
|
375
|
+
return failed('invalidPassword', 'user.error.passwordRequired', t('user.error.passwordRequired'));
|
|
376
|
+
}
|
|
377
|
+
if (password.length > MAX_PASSWORD_LENGTH) {
|
|
378
|
+
return failed('invalidPassword', 'user.error.passwordTooLong', t('user.error.passwordTooLong', undefined, {
|
|
379
|
+
defaultValue: `Password must be at most ${MAX_PASSWORD_LENGTH} characters`,
|
|
380
|
+
}));
|
|
381
|
+
}
|
|
382
|
+
if (password.length < MIN_PASSWORD_LENGTH) {
|
|
383
|
+
return failed('invalidPassword', 'user.error.passwordTooShort', t('user.error.passwordTooShort', undefined, {
|
|
384
|
+
defaultValue: `Password must be at least ${MIN_PASSWORD_LENGTH} characters`,
|
|
385
|
+
}));
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
// The identity is normalized the way signup stores it BEFORE validation, so the schema both
|
|
389
|
+
// sees the same value signup would and decides any further transform (a caller's
|
|
390
|
+
// `z.string().toLowerCase()`, say). Copying this pre-step keeps the stored column and every
|
|
391
|
+
// later lookup on the same value; the schema's own parsing is never re-implemented here.
|
|
392
|
+
const candidateProps = { ...props };
|
|
393
|
+
if (candidateProps.username === undefined || candidateProps.username === null) {
|
|
394
|
+
delete candidateProps.username;
|
|
395
|
+
}
|
|
396
|
+
else {
|
|
397
|
+
const trimmed = String(candidateProps.username).trim().substring(0, MAX_USERNAME_LENGTH);
|
|
398
|
+
if (trimmed)
|
|
399
|
+
candidateProps.username = trimmed;
|
|
400
|
+
else
|
|
401
|
+
delete candidateProps.username;
|
|
402
|
+
}
|
|
403
|
+
if (candidateProps.email === undefined ||
|
|
404
|
+
candidateProps.email === null ||
|
|
405
|
+
candidateProps.email === '') {
|
|
406
|
+
delete candidateProps.email;
|
|
407
|
+
}
|
|
408
|
+
else {
|
|
409
|
+
candidateProps.email = normalizeEmail(String(candidateProps.email))?.substring(0, MAX_EMAIL_LENGTH);
|
|
410
|
+
}
|
|
411
|
+
// The server controls id and timestamps: the caller cannot smuggle its own. They are set
|
|
412
|
+
// BEFORE validation because the resource schema (`basePropsSchema`) requires them.
|
|
413
|
+
const id = uuid();
|
|
414
|
+
const now = new Date().toISOString();
|
|
415
|
+
let validated;
|
|
416
|
+
try {
|
|
417
|
+
validated = utilities.getValidProps({
|
|
418
|
+
name,
|
|
419
|
+
schema: schema,
|
|
420
|
+
props: { ...candidateProps, id, createdAt: now, updatedAt: now },
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
catch (error) {
|
|
424
|
+
return failed('invalidProps', 'resource.error.unknownError', messageOf(error));
|
|
425
|
+
}
|
|
426
|
+
// The identity is read from the VALIDATED props — the exact values the schema produced and the
|
|
427
|
+
// values this call will store.
|
|
428
|
+
const username = typeof validated.username === 'string' && validated.username.length > 0
|
|
429
|
+
? validated.username
|
|
430
|
+
: undefined;
|
|
431
|
+
const email = normalizeEmail(typeof validated.email === 'string' ? validated.email : undefined);
|
|
432
|
+
if (!username && !email) {
|
|
433
|
+
return failed('identityRequired', 'user.error.badRequest', t('user.error.badRequest', undefined, {
|
|
434
|
+
defaultValue: 'Provisioning needs a username or an email to identify the account.',
|
|
435
|
+
}));
|
|
436
|
+
}
|
|
437
|
+
if (username && !USERNAME_RE.test(username)) {
|
|
438
|
+
return failed('invalidUsername', 'user.error.usernameInvalid', t('user.error.usernameInvalid'));
|
|
439
|
+
}
|
|
440
|
+
if (completeId !== undefined) {
|
|
441
|
+
return await completeProvisioning({ tableName, completeId, username, email, password });
|
|
442
|
+
}
|
|
443
|
+
// Look for an existing account BEFORE writing — a re-run returns it instead of creating a
|
|
444
|
+
// second one, and an existing account's credentials are never touched.
|
|
445
|
+
let byUsername = null;
|
|
446
|
+
let byEmail = null;
|
|
447
|
+
try {
|
|
448
|
+
if (username) {
|
|
449
|
+
byUsername = await findOne(tableName, [
|
|
450
|
+
{ field: 'username', operator: '=', value: username },
|
|
451
|
+
]);
|
|
452
|
+
}
|
|
453
|
+
if (email) {
|
|
454
|
+
byEmail = await findOne(tableName, [{ field: 'email', operator: '=', value: email }]);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
catch (error) {
|
|
458
|
+
logger.error('Failed to look up an existing user while provisioning', { error });
|
|
459
|
+
return failed('lookupFailed', 'user.error.failedToReadUser', t('user.error.failedToReadUser'));
|
|
460
|
+
}
|
|
461
|
+
if (byUsername && byEmail && byUsername.id !== byEmail.id) {
|
|
462
|
+
return failed('conflict', 'user.error.badRequest', t('user.error.badRequest', undefined, {
|
|
463
|
+
defaultValue: 'The username and the email belong to two different existing accounts.',
|
|
464
|
+
}));
|
|
465
|
+
}
|
|
466
|
+
const existing = byUsername ?? byEmail;
|
|
467
|
+
if (existing) {
|
|
468
|
+
return await existingAccount(tableName, existing);
|
|
469
|
+
}
|
|
470
|
+
// A concurrent provision may have won the insert (the email column is UNIQUE). Resolve that to
|
|
471
|
+
// the row that now exists rather than reporting a failure a retry would not reproduce.
|
|
472
|
+
const resolveEmailRace = async () => {
|
|
473
|
+
if (!email)
|
|
474
|
+
return null;
|
|
475
|
+
try {
|
|
476
|
+
const raced = await findOne(tableName, [{ field: 'email', operator: '=', value: email }]);
|
|
477
|
+
if (raced)
|
|
478
|
+
return await existingAccount(tableName, raced);
|
|
479
|
+
}
|
|
480
|
+
catch (error) {
|
|
481
|
+
logger.warn('Failed to re-check an email after a refused user insert', { error });
|
|
482
|
+
}
|
|
483
|
+
return null;
|
|
484
|
+
};
|
|
485
|
+
// Hash BEFORE the write: a hashing failure must leave no row behind, and the hash is what the
|
|
486
|
+
// credential row stores (the plaintext is never persisted or returned).
|
|
487
|
+
let passwordHash;
|
|
488
|
+
if (password !== undefined) {
|
|
489
|
+
try {
|
|
490
|
+
passwordHash = await hash(password);
|
|
491
|
+
}
|
|
492
|
+
catch (error) {
|
|
493
|
+
logger.error('Failed to hash a provisioned user password', { error });
|
|
494
|
+
return failed('credentialsFailed', 'user.error.failedToHashPassword', t('user.error.failedToHashPassword'));
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
const userRow = { ...validated, id, createdAt: now, updatedAt: now };
|
|
498
|
+
if (username === undefined)
|
|
499
|
+
delete userRow.username;
|
|
500
|
+
else
|
|
501
|
+
userRow.username = username;
|
|
502
|
+
if (email === undefined)
|
|
503
|
+
delete userRow.email;
|
|
504
|
+
else
|
|
505
|
+
userRow.email = email;
|
|
506
|
+
const secretRow = passwordHash === undefined ? { id } : { id, passwordHash };
|
|
507
|
+
const secretsTable = `${tableName}Secrets`;
|
|
508
|
+
if (supportsTransactions()) {
|
|
509
|
+
// Both rows or neither: a credential failure rolls the user row back, so no partial account
|
|
510
|
+
// is left for the caller to repair.
|
|
511
|
+
// A mutable holder: the stage is written inside the transaction callback, and TypeScript's
|
|
512
|
+
// control-flow analysis narrows a plain `let` to its initializer at the catch below.
|
|
513
|
+
const state = { stage: 'user' };
|
|
514
|
+
try {
|
|
515
|
+
await withTransaction(async () => {
|
|
516
|
+
state.stage = 'user';
|
|
517
|
+
const userResult = await storeCreate(tableName, userRow);
|
|
518
|
+
if (!userResult?.affected)
|
|
519
|
+
throw new Error(`Failed to insert data into ${tableName}.`);
|
|
520
|
+
state.stage = 'credentials';
|
|
521
|
+
const secretResult = await storeCreate(secretsTable, secretRow);
|
|
522
|
+
if (!secretResult?.affected)
|
|
523
|
+
throw new Error(`Failed to insert the ${secretsTable} row.`);
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
catch (error) {
|
|
527
|
+
if (state.stage === 'credentials') {
|
|
528
|
+
logger.error('Failed to store a provisioned user credential row', { error, userId: id });
|
|
529
|
+
// The hash (when one was supplied) is already computed: what failed is the row write.
|
|
530
|
+
return failed('credentialsFailed', 'user.error.failedToCreateUser', messageOf(error));
|
|
531
|
+
}
|
|
532
|
+
const raced = await resolveEmailRace();
|
|
533
|
+
if (raced)
|
|
534
|
+
return raced;
|
|
535
|
+
logger.error('Failed to insert a provisioned user row', { error, userId: id });
|
|
536
|
+
return failed('userNotCreated', 'resource.error.unableToCreate', messageOf(error));
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
else {
|
|
540
|
+
// No interactive transactions on this bond (D1). The user row commits on its own, so a
|
|
541
|
+
// credential failure is reported as `partial` with the id that repairs it — never as
|
|
542
|
+
// success, and never as a plain failure that hides the row.
|
|
543
|
+
let userResult;
|
|
544
|
+
try {
|
|
545
|
+
userResult = await storeCreate(tableName, userRow);
|
|
546
|
+
}
|
|
547
|
+
catch (error) {
|
|
548
|
+
const raced = await resolveEmailRace();
|
|
549
|
+
if (raced)
|
|
550
|
+
return raced;
|
|
551
|
+
logger.error('Failed to insert a provisioned user row', { error, userId: id });
|
|
552
|
+
return failed('userNotCreated', 'resource.error.unableToCreate', messageOf(error));
|
|
553
|
+
}
|
|
554
|
+
if (!userResult?.affected) {
|
|
555
|
+
const raced = await resolveEmailRace();
|
|
556
|
+
if (raced)
|
|
557
|
+
return raced;
|
|
558
|
+
// No affected row means no user row exists: there is nothing to repair.
|
|
559
|
+
return failed('userNotCreated', 'resource.error.unableToCreate', t('resource.error.unableToCreate', { name }, { defaultValue: `Unable to create ${name}.` }));
|
|
560
|
+
}
|
|
561
|
+
try {
|
|
562
|
+
const secretResult = await storeCreate(secretsTable, secretRow);
|
|
563
|
+
if (!secretResult?.affected)
|
|
564
|
+
throw new Error(`Failed to insert the ${secretsTable} row.`);
|
|
565
|
+
}
|
|
566
|
+
catch (error) {
|
|
567
|
+
logger.error('Failed to store a provisioned user credential row', { error, userId: id });
|
|
568
|
+
return {
|
|
569
|
+
status: 'partial',
|
|
570
|
+
reason: 'credentialsFailed',
|
|
571
|
+
errorKey: 'user.error.failedToCreateUser',
|
|
572
|
+
error: messageOf(error),
|
|
573
|
+
id,
|
|
574
|
+
recovery: { id, passwordRequired: password !== undefined },
|
|
575
|
+
};
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
return {
|
|
579
|
+
status: 'created',
|
|
580
|
+
id,
|
|
581
|
+
props: stripSensitiveUserColumns(userRow),
|
|
582
|
+
hasPassword: passwordHash !== undefined,
|
|
583
|
+
};
|
|
584
|
+
};
|
|
585
|
+
//# sourceMappingURL=provisioning.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provisioning.js","sourceRoot":"","sources":["../src/provisioning.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkEG;AAEH,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAA;AAGjC,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAE9C,OAAO,EACL,MAAM,IAAI,WAAW,EACrB,QAAQ,EACR,OAAO,EACP,OAAO,EACP,OAAO,EACP,UAAU,EACV,eAAe,GAChB,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EAAE,CAAC,EAAE,MAAM,oBAAoB,CAAA;AACtC,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAA;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAElD,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAEnF,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAA;AAC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AAyB,CAAC,OAAO,CAAyB;QACjE,WAAW,EAAE,YAAY,KAAK,SAAS;KACxC,CAAA;AACH,CAAC,CAAA"}
|
package/dist/schema.d.ts
CHANGED
|
@@ -16,6 +16,17 @@ export declare const MAX_BIO_LENGTH = 1000;
|
|
|
16
16
|
* Larger avatars must be hosted elsewhere and referenced by URL.
|
|
17
17
|
*/
|
|
18
18
|
export declare const MAX_AVATAR_LENGTH: number;
|
|
19
|
+
/**
|
|
20
|
+
* Shortest password the package accepts, for signup (`handlers.create`), password changes and
|
|
21
|
+
* programmatic provisioning alike — one policy, checked by every write path.
|
|
22
|
+
*/
|
|
23
|
+
export declare const MIN_PASSWORD_LENGTH = 8;
|
|
24
|
+
/**
|
|
25
|
+
* Longest password the package accepts (in characters), for signup (`handlers.create`),
|
|
26
|
+
* password changes and programmatic provisioning alike. bcrypt reads only the first 72 BYTES,
|
|
27
|
+
* so this cap is a request-size bound rather than a strength claim.
|
|
28
|
+
*/
|
|
29
|
+
export declare const MAX_PASSWORD_LENGTH = 1024;
|
|
19
30
|
/**
|
|
20
31
|
* Creates a full schema for user props.
|
|
21
32
|
*
|
package/dist/schema.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAIvB;;GAEG;AACH,eAAO,MAAM,cAAc,OAAO,CAAA;AAElC;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,QAAa,CAAA;AAE3C;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY,GACvB,YAAY,SAAS,SAAS,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,GAAG,SAAS,GAAG,SAAS,EAC3E,QAAQ,SAAS,SAAS,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,GAAG,SAAS,GAAG,SAAS,EACvE,UAAU;IAC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C1F,eAAO,MAAM,qBAAqB;;;;iBAMtB,CAAA;AAEZ;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAA;AAEnE;;GAEG;AACH,eAAO,MAAM,0BAA0B;;iBAI3B,CAAA;AAEZ;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,0BAA0B,CAAC,CAAA;AAE7E;;GAEG;AACH,eAAO,MAAM,gCAAgC;;;iBAKjC,CAAA;AAEZ;;GAEG;AACH,MAAM,MAAM,0BAA0B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gCAAgC,CAAC,CAAA;AAEzF,qFAAqF;AACrF,eAAO,MAAM,aAAa;;;;;;iBAqBxB,CAAA;AAEF;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAA;AAEnD;;GAEG;AACH,OAAO,EAAE,CAAC,EAAE,CAAA"}
|
package/dist/schema.js
CHANGED
|
@@ -17,6 +17,17 @@ export const MAX_BIO_LENGTH = 1000;
|
|
|
17
17
|
* Larger avatars must be hosted elsewhere and referenced by URL.
|
|
18
18
|
*/
|
|
19
19
|
export const MAX_AVATAR_LENGTH = 256 * 1024;
|
|
20
|
+
/**
|
|
21
|
+
* Shortest password the package accepts, for signup (`handlers.create`), password changes and
|
|
22
|
+
* programmatic provisioning alike — one policy, checked by every write path.
|
|
23
|
+
*/
|
|
24
|
+
export const MIN_PASSWORD_LENGTH = 8;
|
|
25
|
+
/**
|
|
26
|
+
* Longest password the package accepts (in characters), for signup (`handlers.create`),
|
|
27
|
+
* password changes and programmatic provisioning alike. bcrypt reads only the first 72 BYTES,
|
|
28
|
+
* so this cap is a request-size bound rather than a strength claim.
|
|
29
|
+
*/
|
|
30
|
+
export const MAX_PASSWORD_LENGTH = 1024;
|
|
20
31
|
/**
|
|
21
32
|
* Creates a full schema for user props.
|
|
22
33
|
*
|