@molecule/api-resource-user 1.8.8 → 1.10.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 +298 -14
- package/dist/accounts.d.ts +162 -0
- package/dist/accounts.d.ts.map +1 -0
- package/dist/accounts.js +209 -0
- package/dist/accounts.js.map +1 -0
- package/dist/authorization.d.ts +2 -1
- package/dist/authorization.d.ts.map +1 -1
- package/dist/authorization.js +7 -12
- package/dist/authorization.js.map +1 -1
- package/dist/index.d.ts +26 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +26 -12
- package/dist/index.js.map +1 -1
- package/dist/profiles.d.ts +32 -0
- package/dist/profiles.d.ts.map +1 -0
- package/dist/profiles.js +37 -0
- package/dist/profiles.js.map +1 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@ AUTO-GENERATED — DO NOT EDIT THIS FILE.
|
|
|
3
3
|
Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
|
|
4
4
|
Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
|
|
5
5
|
To change this document, edit the module-level JSDoc in src/index.ts.
|
|
6
|
-
Generated: 2026-11-
|
|
6
|
+
Generated: 2026-11-12T14:00:15.375Z
|
|
7
7
|
-->
|
|
8
8
|
|
|
9
9
|
# @molecule/api-resource-user
|
|
@@ -39,18 +39,20 @@ finish it with `provisionUser(..., { props, completeId: id })` — a retry witho
|
|
|
39
39
|
answers `existing` and repairs nothing. **TRUSTED SERVER CALLERS ONLY:** it takes props
|
|
40
40
|
directly, so a public endpoint built on it is a mass-assignment hole.
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
`
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
**Your own sign-up and sign-in routes call
|
|
43
|
+
`createAccount({ username, email, password }, { req, res })` and {@link signIn}:** each
|
|
44
|
+
resolves to `{ ok, user, token }`, and `token` is the session.
|
|
45
|
+
Never call `sign()`, `hash()` or `compare()` for accounts yourself.
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
store). Set `AUTH_SCHEME=Token` (or `verifyMiddleware({ scheme: 'Token' })`): every route
|
|
50
|
-
accepts it, `logIn`/`create` return `accessToken`, `GET /users/me` echoes it, and a password
|
|
51
|
-
change revokes every OTHER device but keeps the caller's own session.
|
|
47
|
+
HTTP path: `handlers.create`, `handlers.logIn`, `handlers.updatePassword`. One secret:
|
|
48
|
+
`findById('usersSecrets', userId)`.
|
|
52
49
|
|
|
53
|
-
**
|
|
50
|
+
**Token API (`Authorization: Token <jwt>`)? CONFIGURATION,
|
|
51
|
+
never a credentials table of your own** (`usersSecrets.passwordHash` is the store): set
|
|
52
|
+
`AUTH_SCHEME=Token` (or `verifyMiddleware({ scheme: 'Token' })`) — every route accepts it,
|
|
53
|
+
`logIn`/`create` return `accessToken`, `GET /users/me` echoes it, and a password change
|
|
54
|
+
revokes every OTHER device but keeps the
|
|
55
|
+
caller's own session.
|
|
54
56
|
|
|
55
57
|
**`handlers.*` return `{ statusCode, headers?, body }` and never write to `res`** — not through
|
|
56
58
|
`res.json`, not through `res.send`, not through `res.end`. The mounted routes apply that object
|
|
@@ -66,6 +68,10 @@ res.status(statusCode).send(body)
|
|
|
66
68
|
Monkey-patching `res.json` to re-shape a handler's answer intercepts nothing the handler
|
|
67
69
|
produces, so the request it was meant to answer is left unanswered and hangs.
|
|
68
70
|
|
|
71
|
+
**Generated full-stack apps:** mlcl derives the app-auth composition root from this API contract; keep that bond and use its shared HTTP client.
|
|
72
|
+
Header-only mounts discard a session inherited from a cookie-enabled mount before
|
|
73
|
+
verifying the header, including when that header is invalid or its device was revoked.
|
|
74
|
+
|
|
69
75
|
**Adapt envelopes with `createRequestHandler(handler, options)` from
|
|
70
76
|
`@molecule/api-resource` 1.1 or newer.** Keep `handlers.create(resource)` and
|
|
71
77
|
`handlers.logIn(resource)` as the handler. `mapRequest: (req) =>
|
|
@@ -115,8 +121,8 @@ import { createRequestHandler } from '@molecule/api-resource'
|
|
|
115
121
|
import { createResource, handlers } from '@molecule/api-resource-user'
|
|
116
122
|
|
|
117
123
|
// Omit `schema`: create() validates new users with this package's propsSchema.
|
|
118
|
-
const
|
|
119
|
-
const
|
|
124
|
+
const signUpRoute = createRequestHandler(handlers.create({ name: 'User', tableName: 'users' }))
|
|
125
|
+
const signInRoute = createRequestHandler(handlers.logIn({ name: 'User', tableName: 'users' }))
|
|
120
126
|
|
|
121
127
|
// A constrained schema, when the app restricts oauthServer / planKey.
|
|
122
128
|
const users = createResource({ oauthServers: ['google', 'github'] as const })
|
|
@@ -229,6 +235,105 @@ npm install @molecule/api-resource-user @molecule/api-bond @molecule/api-config
|
|
|
229
235
|
|
|
230
236
|
### Interfaces
|
|
231
237
|
|
|
238
|
+
#### `SessionContext`
|
|
239
|
+
|
|
240
|
+
The request a session is being issued in. The session's `Authorization` response header (and
|
|
241
|
+
its cookie, where the mount allows one) is set on `res`.
|
|
242
|
+
|
|
243
|
+
```typescript
|
|
244
|
+
interface SessionContext {
|
|
245
|
+
req: MoleculeRequest
|
|
246
|
+
res: MoleculeResponse
|
|
247
|
+
}
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
#### `AccountSession`
|
|
251
|
+
|
|
252
|
+
A signed-in account: the safe user row and its session token.
|
|
253
|
+
|
|
254
|
+
```typescript
|
|
255
|
+
interface AccountSession {
|
|
256
|
+
ok: true
|
|
257
|
+
/** The user's row with every secret column stripped — safe to send to the client. */
|
|
258
|
+
user: types.Props
|
|
259
|
+
/**
|
|
260
|
+
* The session token, signed by the bonded JWT provider and bound to a device row. The client
|
|
261
|
+
* sends it back as `Authorization: <scheme> <token>`; `verifyMiddleware` accepts it.
|
|
262
|
+
*/
|
|
263
|
+
token: string
|
|
264
|
+
}
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
#### `AccountFailure`
|
|
268
|
+
|
|
269
|
+
An account call that signed no one in, as values an app maps to its own error body.
|
|
270
|
+
|
|
271
|
+
```typescript
|
|
272
|
+
interface AccountFailure {
|
|
273
|
+
ok: false
|
|
274
|
+
/** The cause, for a `switch`. */
|
|
275
|
+
reason: AccountFailureReason
|
|
276
|
+
/** The input field the cause is about, or null when it is not about one field. */
|
|
277
|
+
field: 'username' | 'email' | 'password' | 'twoFactorToken' | null
|
|
278
|
+
/** A sentence for the person, in the request's locale. */
|
|
279
|
+
message: string
|
|
280
|
+
/** The status this package's own route answers with, as a starting point. */
|
|
281
|
+
statusCode: number
|
|
282
|
+
/** This package's stable error key (`user.error.usernameUnavailable`). */
|
|
283
|
+
errorKey: string
|
|
284
|
+
}
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
#### `CreateAccountInput`
|
|
288
|
+
|
|
289
|
+
The fields a person may choose when signing up. Anything else is ignored, never stored.
|
|
290
|
+
|
|
291
|
+
```typescript
|
|
292
|
+
interface CreateAccountInput {
|
|
293
|
+
username?: string
|
|
294
|
+
email?: string
|
|
295
|
+
name?: string
|
|
296
|
+
password: string
|
|
297
|
+
/** A label for the session's device row ("Chrome on macOS"). */
|
|
298
|
+
deviceName?: string
|
|
299
|
+
}
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
#### `SignInInput`
|
|
303
|
+
|
|
304
|
+
What a person signs in with: a username or an email, and the password.
|
|
305
|
+
|
|
306
|
+
```typescript
|
|
307
|
+
interface SignInInput {
|
|
308
|
+
username?: string
|
|
309
|
+
email?: string
|
|
310
|
+
password: string
|
|
311
|
+
/** The current code, when the account has two-factor on. */
|
|
312
|
+
twoFactorToken?: string
|
|
313
|
+
/** A label for the session's device row. */
|
|
314
|
+
deviceName?: string
|
|
315
|
+
}
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
#### `PublicProfile`
|
|
319
|
+
|
|
320
|
+
User columns safe to display beside content. Account and credential fields are excluded.
|
|
321
|
+
|
|
322
|
+
```typescript
|
|
323
|
+
interface PublicProfile {
|
|
324
|
+
/** The user's canonical id. */
|
|
325
|
+
id: string
|
|
326
|
+
/** The public username, when set. */
|
|
327
|
+
username: string | null
|
|
328
|
+
/** The public display name, when set. */
|
|
329
|
+
name: string | null
|
|
330
|
+
/** The public biography, when set. */
|
|
331
|
+
bio: string | null
|
|
332
|
+
/** The public avatar URL, when set. */
|
|
333
|
+
avatar: string | null
|
|
334
|
+
}
|
|
335
|
+
```
|
|
336
|
+
|
|
232
337
|
#### `ProvisionUserInput`
|
|
233
338
|
|
|
234
339
|
Input accepted by {@link provisionUser}.
|
|
@@ -305,6 +410,34 @@ interface UserRequestHandlerMap {
|
|
|
305
410
|
|
|
306
411
|
### Types
|
|
307
412
|
|
|
413
|
+
#### `AccountFailureReason`
|
|
414
|
+
|
|
415
|
+
Why an account call did not sign anyone in.
|
|
416
|
+
|
|
417
|
+
```typescript
|
|
418
|
+
type AccountFailureReason =
|
|
419
|
+
| 'username-invalid'
|
|
420
|
+
| 'username-taken'
|
|
421
|
+
| 'email-invalid'
|
|
422
|
+
| 'email-taken'
|
|
423
|
+
| 'password-required'
|
|
424
|
+
| 'password-too-short'
|
|
425
|
+
| 'password-too-long'
|
|
426
|
+
| 'invalid-credentials'
|
|
427
|
+
| 'two-factor-required'
|
|
428
|
+
| 'two-factor-invalid'
|
|
429
|
+
| 'invalid'
|
|
430
|
+
| 'unavailable'
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
#### `AccountResult`
|
|
434
|
+
|
|
435
|
+
What {@link createAccount} and {@link signIn} resolve to.
|
|
436
|
+
|
|
437
|
+
```typescript
|
|
438
|
+
type AccountResult = AccountSession | AccountFailure
|
|
439
|
+
```
|
|
440
|
+
|
|
308
441
|
#### `ProvisionUserProps`
|
|
309
442
|
|
|
310
443
|
Safe user props accepted by {@link provisionUser} — the `users` table's columns without the
|
|
@@ -519,6 +652,150 @@ type Session = z.infer<typeof sessionSchema>
|
|
|
519
652
|
|
|
520
653
|
### Functions
|
|
521
654
|
|
|
655
|
+
#### `createAccount(input, context, resource)`
|
|
656
|
+
|
|
657
|
+
Creates an account from a sign-up form and signs it in.
|
|
658
|
+
|
|
659
|
+
Call it from a route of your own when the API's contract is not this package's
|
|
660
|
+
(`POST /users` with a `{ user: … }` envelope, say), and map the result:
|
|
661
|
+
|
|
662
|
+
```typescript
|
|
663
|
+
import { createAccount } from '@molecule/api-resource-user'
|
|
664
|
+
|
|
665
|
+
router.post('/users', async (req, res) => {
|
|
666
|
+
const { username, email, password } = req.body.user ?? {}
|
|
667
|
+
const account = await createAccount({ username, email, password }, { req, res })
|
|
668
|
+
if (!account.ok)
|
|
669
|
+
return res.status(422).json({ errors: { [account.field ?? 'account']: [account.message] } })
|
|
670
|
+
res.status(201).json({ user: { ...account.user, token: account.token } })
|
|
671
|
+
})
|
|
672
|
+
```
|
|
673
|
+
|
|
674
|
+
It is `handlers.create` as a function: only `username`, `email` and `name` are taken from the
|
|
675
|
+
input (nothing a caller adds is stored), the password is length-checked and hashed by the bonded
|
|
676
|
+
`@molecule/api-password` provider into `usersSecrets`, a device row is created and the token is
|
|
677
|
+
signed by the bonded `@molecule/api-jwt` provider — so it is a session `verifyMiddleware`
|
|
678
|
+
accepts. The `Authorization` response header (and the session cookie, where the mount allows
|
|
679
|
+
one) is set on `res` as the mounted route sets it.
|
|
680
|
+
|
|
681
|
+
```typescript
|
|
682
|
+
function createAccount(
|
|
683
|
+
input: CreateAccountInput,
|
|
684
|
+
context: SessionContext,
|
|
685
|
+
resource?: types.HandlerResource,
|
|
686
|
+
): Promise<AccountResult>
|
|
687
|
+
```
|
|
688
|
+
|
|
689
|
+
- `input` — What the person entered.
|
|
690
|
+
- `context` — The current `{ req, res }`; the session header is set on `res`.
|
|
691
|
+
- `resource` — The users resource, when the app renamed the table. Defaults to `users`.
|
|
692
|
+
|
|
693
|
+
**Returns:** The signed-in account, or why none was created.
|
|
694
|
+
|
|
695
|
+
#### `signIn(input, context, resource)`
|
|
696
|
+
|
|
697
|
+
Checks a username or email and password, and signs the person in.
|
|
698
|
+
|
|
699
|
+
```typescript
|
|
700
|
+
import { signIn } from '@molecule/api-resource-user'
|
|
701
|
+
|
|
702
|
+
router.post('/users/login', async (req, res) => {
|
|
703
|
+
const { email, password } = req.body.user ?? {}
|
|
704
|
+
const account = await signIn({ email, password }, { req, res })
|
|
705
|
+
if (!account.ok) return res.status(401).json({ errors: { credentials: ['invalid'] } })
|
|
706
|
+
res.json({ user: { ...account.user, token: account.token } })
|
|
707
|
+
})
|
|
708
|
+
```
|
|
709
|
+
|
|
710
|
+
It is `handlers.logIn` as a function, with nothing weakened: an unknown account and a wrong
|
|
711
|
+
password take the same time and give the same `invalid-credentials`, the comparison is the
|
|
712
|
+
bonded hasher's, an account with two-factor on answers `two-factor-required` until
|
|
713
|
+
`twoFactorToken` is sent, and the session is device-bound, so sign-out and a password change
|
|
714
|
+
revoke it. A password-reset token is not accepted here; use the reset routes for that.
|
|
715
|
+
|
|
716
|
+
```typescript
|
|
717
|
+
function signIn(
|
|
718
|
+
input: SignInInput,
|
|
719
|
+
context: SessionContext,
|
|
720
|
+
resource?: types.HandlerResource,
|
|
721
|
+
): Promise<AccountResult>
|
|
722
|
+
```
|
|
723
|
+
|
|
724
|
+
- `input` — The credentials.
|
|
725
|
+
- `context` — The current `{ req, res }`; the session header is set on `res`.
|
|
726
|
+
- `resource` — The users resource, when the app renamed the table. Defaults to `users`.
|
|
727
|
+
|
|
728
|
+
**Returns:** The signed-in account, or why no one was signed in.
|
|
729
|
+
|
|
730
|
+
#### `checkPassword(userId, password, resource)`
|
|
731
|
+
|
|
732
|
+
Whether `password` is the account's current password — for a step that re-asks for it
|
|
733
|
+
(confirming a deletion, changing an email in a route of your own).
|
|
734
|
+
|
|
735
|
+
The comparison is the bonded `@molecule/api-password` provider's, against the hash in
|
|
736
|
+
`usersSecrets`. An account with no password (OAuth-only) and an unknown id answer `false` after
|
|
737
|
+
a comparison against a throwaway hash, so the answer's timing does not say which it was.
|
|
738
|
+
Never compare hashes or passwords yourself.
|
|
739
|
+
|
|
740
|
+
```typescript
|
|
741
|
+
function checkPassword(
|
|
742
|
+
userId: string,
|
|
743
|
+
password: string,
|
|
744
|
+
resource?: types.HandlerResource,
|
|
745
|
+
): Promise<boolean>
|
|
746
|
+
```
|
|
747
|
+
|
|
748
|
+
- `userId` — The account's id (`users.id`, which is also its `usersSecrets.id`).
|
|
749
|
+
- `password` — The password the person entered.
|
|
750
|
+
- `resource` — The users resource, when the app renamed the table. Defaults to `users`.
|
|
751
|
+
|
|
752
|
+
**Returns:** True only when the password matches.
|
|
753
|
+
|
|
754
|
+
#### `issueSession(userId, context, options)`
|
|
755
|
+
|
|
756
|
+
Signs in an account you have ALREADY authenticated some other way (a verified invite link, a
|
|
757
|
+
single sign-on callback) and returns its session token.
|
|
758
|
+
|
|
759
|
+
It creates the device row and has the bonded JWT provider sign a token bound to it — the two
|
|
760
|
+
steps a session is. A token signed any other way names no device and is answered 401 by
|
|
761
|
+
`verifyMiddleware` on every request. For a username or email and password use {@link signIn},
|
|
762
|
+
which checks them first; this function checks nothing.
|
|
763
|
+
|
|
764
|
+
```typescript
|
|
765
|
+
function issueSession(
|
|
766
|
+
userId: string,
|
|
767
|
+
context: SessionContext,
|
|
768
|
+
options?: { deviceName?: string },
|
|
769
|
+
): Promise<string>
|
|
770
|
+
```
|
|
771
|
+
|
|
772
|
+
- `userId` — The authenticated account's id.
|
|
773
|
+
- `context` — The current `{ req, res }`; the session header is set on `res`.
|
|
774
|
+
- `options` — An optional label for the session's device row.
|
|
775
|
+
|
|
776
|
+
**Returns:** The session token.
|
|
777
|
+
|
|
778
|
+
#### `getPublicProfiles(userIds, resource)`
|
|
779
|
+
|
|
780
|
+
Load the public profiles for a collection in one database query.
|
|
781
|
+
|
|
782
|
+
Pass every user id from the page once, then join by id while projecting the response.
|
|
783
|
+
Repeated ids are deduplicated; absent users have no map entry. An empty input does no I/O.
|
|
784
|
+
Nothing is cached between calls, so a later profile update is visible immediately.
|
|
785
|
+
The resource option supports an application's renamed users table with the same columns.
|
|
786
|
+
|
|
787
|
+
```typescript
|
|
788
|
+
function getPublicProfiles(
|
|
789
|
+
userIds: readonly string[],
|
|
790
|
+
resource?: Pick<HandlerResource, 'tableName'>,
|
|
791
|
+
): Promise<Map<string, PublicProfile>>
|
|
792
|
+
```
|
|
793
|
+
|
|
794
|
+
- `userIds` — Canonical user ids referenced by the collection.
|
|
795
|
+
- `resource` — Users resource; defaults to the package's `users` table.
|
|
796
|
+
|
|
797
|
+
**Returns:** Public profiles keyed by id, without email, plan, OAuth or secret fields.
|
|
798
|
+
|
|
522
799
|
#### `provisionUser(resource, input)`
|
|
523
800
|
|
|
524
801
|
Creates a user record and its same-id credential record for a trusted server caller, without
|
|
@@ -1216,7 +1493,8 @@ interface VerifyMiddlewareOptions {
|
|
|
1216
1493
|
*
|
|
1217
1494
|
* Pass `false` for a token-only JSON API. Then the cookie is not a credential here:
|
|
1218
1495
|
* the middleware does not resolve a session from it (and drops one an earlier, laxer
|
|
1219
|
-
* mount already resolved from it
|
|
1496
|
+
* mount already resolved from it, even when a supplied header fails verification),
|
|
1497
|
+
* and {@link set} does not write it either — so a
|
|
1220
1498
|
* client that keeps a cookie jar (an HTTP test runner, `curl -b`) never picks up a
|
|
1221
1499
|
* session it should not have, and stops answering 200 on the step its spec calls
|
|
1222
1500
|
* "no auth".
|
|
@@ -2707,3 +2985,9 @@ by one. A box you can't check is an integration bug to fix — not a skip:
|
|
|
2707
2985
|
- [ ] Authenticated-only screens are unreachable when logged out (redirect to
|
|
2708
2986
|
login or an explicit denial — never a blank page).
|
|
2709
2987
|
- [ ] A profile/account edit (e.g. display name) persists across a reload.
|
|
2988
|
+
|
|
2989
|
+
**Public profiles for a list:** call `getPublicProfiles(userIds)` once for the page,
|
|
2990
|
+
then join its map by canonical id. It reads only public display columns in one query,
|
|
2991
|
+
deduplicates repeated ids, omits missing users and does no I/O for an empty page.
|
|
2992
|
+
Never serialize a complete account row beside public content: email, OAuth and plan fields
|
|
2993
|
+
are not public profile data. A renamed users table uses `getPublicProfiles(ids, { tableName })`.
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plain account and session functions for routes an app writes itself.
|
|
3
|
+
*
|
|
4
|
+
* `handlers.*` answer HTTP (`{ statusCode, body }`) in this package's own wire shape. An API with
|
|
5
|
+
* its own contract — its own paths, envelopes, status codes or error bodies — needs the same work
|
|
6
|
+
* as values it can map: {@link createAccount}, {@link signIn}, {@link checkPassword} and
|
|
7
|
+
* {@link issueSession}. They run the SAME code the mounted routes run (validation, the bonded
|
|
8
|
+
* password hasher and its constant-time comparison, two-factor, the device-bound session signed
|
|
9
|
+
* through the bonded JWT provider), so an app never hashes a password, compares one, or signs a
|
|
10
|
+
* token itself.
|
|
11
|
+
*
|
|
12
|
+
* @module
|
|
13
|
+
*/
|
|
14
|
+
import type { MoleculeRequest, MoleculeResponse } from '@molecule/api-resource';
|
|
15
|
+
import type * as types from './types.js';
|
|
16
|
+
/** Why an account call did not sign anyone in. */
|
|
17
|
+
export type AccountFailureReason = 'username-invalid' | 'username-taken' | 'email-invalid' | 'email-taken' | 'password-required' | 'password-too-short' | 'password-too-long' | 'invalid-credentials' | 'two-factor-required' | 'two-factor-invalid' | 'invalid' | 'unavailable';
|
|
18
|
+
/**
|
|
19
|
+
* The request a session is being issued in. The session's `Authorization` response header (and
|
|
20
|
+
* its cookie, where the mount allows one) is set on `res`.
|
|
21
|
+
*/
|
|
22
|
+
export interface SessionContext {
|
|
23
|
+
req: MoleculeRequest;
|
|
24
|
+
res: MoleculeResponse;
|
|
25
|
+
}
|
|
26
|
+
/** A signed-in account: the safe user row and its session token. */
|
|
27
|
+
export interface AccountSession {
|
|
28
|
+
ok: true;
|
|
29
|
+
/** The user's row with every secret column stripped — safe to send to the client. */
|
|
30
|
+
user: types.Props;
|
|
31
|
+
/**
|
|
32
|
+
* The session token, signed by the bonded JWT provider and bound to a device row. The client
|
|
33
|
+
* sends it back as `Authorization: <scheme> <token>`; `verifyMiddleware` accepts it.
|
|
34
|
+
*/
|
|
35
|
+
token: string;
|
|
36
|
+
}
|
|
37
|
+
/** An account call that signed no one in, as values an app maps to its own error body. */
|
|
38
|
+
export interface AccountFailure {
|
|
39
|
+
ok: false;
|
|
40
|
+
/** The cause, for a `switch`. */
|
|
41
|
+
reason: AccountFailureReason;
|
|
42
|
+
/** The input field the cause is about, or null when it is not about one field. */
|
|
43
|
+
field: 'username' | 'email' | 'password' | 'twoFactorToken' | null;
|
|
44
|
+
/** A sentence for the person, in the request's locale. */
|
|
45
|
+
message: string;
|
|
46
|
+
/** The status this package's own route answers with, as a starting point. */
|
|
47
|
+
statusCode: number;
|
|
48
|
+
/** This package's stable error key (`user.error.usernameUnavailable`). */
|
|
49
|
+
errorKey: string;
|
|
50
|
+
}
|
|
51
|
+
/** What {@link createAccount} and {@link signIn} resolve to. */
|
|
52
|
+
export type AccountResult = AccountSession | AccountFailure;
|
|
53
|
+
/** The fields a person may choose when signing up. Anything else is ignored, never stored. */
|
|
54
|
+
export interface CreateAccountInput {
|
|
55
|
+
username?: string;
|
|
56
|
+
email?: string;
|
|
57
|
+
name?: string;
|
|
58
|
+
password: string;
|
|
59
|
+
/** A label for the session's device row ("Chrome on macOS"). */
|
|
60
|
+
deviceName?: string;
|
|
61
|
+
}
|
|
62
|
+
/** What a person signs in with: a username or an email, and the password. */
|
|
63
|
+
export interface SignInInput {
|
|
64
|
+
username?: string;
|
|
65
|
+
email?: string;
|
|
66
|
+
password: string;
|
|
67
|
+
/** The current code, when the account has two-factor on. */
|
|
68
|
+
twoFactorToken?: string;
|
|
69
|
+
/** A label for the session's device row. */
|
|
70
|
+
deviceName?: string;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Creates an account from a sign-up form and signs it in.
|
|
74
|
+
*
|
|
75
|
+
* Call it from a route of your own when the API's contract is not this package's
|
|
76
|
+
* (`POST /users` with a `{ user: … }` envelope, say), and map the result:
|
|
77
|
+
*
|
|
78
|
+
* ```typescript
|
|
79
|
+
* import { createAccount } from '@molecule/api-resource-user'
|
|
80
|
+
*
|
|
81
|
+
* router.post('/users', async (req, res) => {
|
|
82
|
+
* const { username, email, password } = req.body.user ?? {}
|
|
83
|
+
* const account = await createAccount({ username, email, password }, { req, res })
|
|
84
|
+
* if (!account.ok)
|
|
85
|
+
* return res.status(422).json({ errors: { [account.field ?? 'account']: [account.message] } })
|
|
86
|
+
* res.status(201).json({ user: { ...account.user, token: account.token } })
|
|
87
|
+
* })
|
|
88
|
+
* ```
|
|
89
|
+
*
|
|
90
|
+
* It is `handlers.create` as a function: only `username`, `email` and `name` are taken from the
|
|
91
|
+
* input (nothing a caller adds is stored), the password is length-checked and hashed by the bonded
|
|
92
|
+
* `@molecule/api-password` provider into `usersSecrets`, a device row is created and the token is
|
|
93
|
+
* signed by the bonded `@molecule/api-jwt` provider — so it is a session `verifyMiddleware`
|
|
94
|
+
* accepts. The `Authorization` response header (and the session cookie, where the mount allows
|
|
95
|
+
* one) is set on `res` as the mounted route sets it.
|
|
96
|
+
*
|
|
97
|
+
* @param input - What the person entered.
|
|
98
|
+
* @param context - The current `{ req, res }`; the session header is set on `res`.
|
|
99
|
+
* @param resource - The users resource, when the app renamed the table. Defaults to `users`.
|
|
100
|
+
* @returns The signed-in account, or why none was created.
|
|
101
|
+
*/
|
|
102
|
+
export declare function createAccount(input: CreateAccountInput, context: SessionContext, resource?: types.HandlerResource): Promise<AccountResult>;
|
|
103
|
+
/**
|
|
104
|
+
* Checks a username or email and password, and signs the person in.
|
|
105
|
+
*
|
|
106
|
+
* ```typescript
|
|
107
|
+
* import { signIn } from '@molecule/api-resource-user'
|
|
108
|
+
*
|
|
109
|
+
* router.post('/users/login', async (req, res) => {
|
|
110
|
+
* const { email, password } = req.body.user ?? {}
|
|
111
|
+
* const account = await signIn({ email, password }, { req, res })
|
|
112
|
+
* if (!account.ok) return res.status(401).json({ errors: { credentials: ['invalid'] } })
|
|
113
|
+
* res.json({ user: { ...account.user, token: account.token } })
|
|
114
|
+
* })
|
|
115
|
+
* ```
|
|
116
|
+
*
|
|
117
|
+
* It is `handlers.logIn` as a function, with nothing weakened: an unknown account and a wrong
|
|
118
|
+
* password take the same time and give the same `invalid-credentials`, the comparison is the
|
|
119
|
+
* bonded hasher's, an account with two-factor on answers `two-factor-required` until
|
|
120
|
+
* `twoFactorToken` is sent, and the session is device-bound, so sign-out and a password change
|
|
121
|
+
* revoke it. A password-reset token is not accepted here; use the reset routes for that.
|
|
122
|
+
*
|
|
123
|
+
* @param input - The credentials.
|
|
124
|
+
* @param context - The current `{ req, res }`; the session header is set on `res`.
|
|
125
|
+
* @param resource - The users resource, when the app renamed the table. Defaults to `users`.
|
|
126
|
+
* @returns The signed-in account, or why no one was signed in.
|
|
127
|
+
*/
|
|
128
|
+
export declare function signIn(input: SignInInput, context: SessionContext, resource?: types.HandlerResource): Promise<AccountResult>;
|
|
129
|
+
/**
|
|
130
|
+
* Whether `password` is the account's current password — for a step that re-asks for it
|
|
131
|
+
* (confirming a deletion, changing an email in a route of your own).
|
|
132
|
+
*
|
|
133
|
+
* The comparison is the bonded `@molecule/api-password` provider's, against the hash in
|
|
134
|
+
* `usersSecrets`. An account with no password (OAuth-only) and an unknown id answer `false` after
|
|
135
|
+
* a comparison against a throwaway hash, so the answer's timing does not say which it was.
|
|
136
|
+
* Never compare hashes or passwords yourself.
|
|
137
|
+
*
|
|
138
|
+
* @param userId - The account's id (`users.id`, which is also its `usersSecrets.id`).
|
|
139
|
+
* @param password - The password the person entered.
|
|
140
|
+
* @param resource - The users resource, when the app renamed the table. Defaults to `users`.
|
|
141
|
+
* @returns True only when the password matches.
|
|
142
|
+
*/
|
|
143
|
+
export declare function checkPassword(userId: string, password: string, resource?: types.HandlerResource): Promise<boolean>;
|
|
144
|
+
/**
|
|
145
|
+
* Signs in an account you have ALREADY authenticated some other way (a verified invite link, a
|
|
146
|
+
* single sign-on callback) and returns its session token.
|
|
147
|
+
*
|
|
148
|
+
* It creates the device row and has the bonded JWT provider sign a token bound to it — the two
|
|
149
|
+
* steps a session is. A token signed any other way names no device and is answered 401 by
|
|
150
|
+
* `verifyMiddleware` on every request. For a username or email and password use {@link signIn},
|
|
151
|
+
* which checks them first; this function checks nothing.
|
|
152
|
+
*
|
|
153
|
+
* @param userId - The authenticated account's id.
|
|
154
|
+
* @param context - The current `{ req, res }`; the session header is set on `res`.
|
|
155
|
+
* @param options - An optional label for the session's device row.
|
|
156
|
+
* @returns The session token.
|
|
157
|
+
* @throws {Error} When no device service is bonded or the device row cannot be written.
|
|
158
|
+
*/
|
|
159
|
+
export declare function issueSession(userId: string, context: SessionContext, options?: {
|
|
160
|
+
deviceName?: string;
|
|
161
|
+
}): Promise<string>;
|
|
162
|
+
//# sourceMappingURL=accounts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accounts.d.ts","sourceRoot":"","sources":["../src/accounts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAMH,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAM/E,OAAO,KAAK,KAAK,KAAK,MAAM,YAAY,CAAA;AAOxC,kDAAkD;AAClD,MAAM,MAAM,oBAAoB,GAC5B,kBAAkB,GAClB,gBAAgB,GAChB,eAAe,GACf,aAAa,GACb,mBAAmB,GACnB,oBAAoB,GACpB,mBAAmB,GACnB,qBAAqB,GACrB,qBAAqB,GACrB,oBAAoB,GACpB,SAAS,GACT,aAAa,CAAA;AAEjB;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,GAAG,EAAE,eAAe,CAAA;IACpB,GAAG,EAAE,gBAAgB,CAAA;CACtB;AAED,oEAAoE;AACpE,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,IAAI,CAAA;IACR,qFAAqF;IACrF,IAAI,EAAE,KAAK,CAAC,KAAK,CAAA;IACjB;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAA;CACd;AAED,0FAA0F;AAC1F,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,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;AAID;;;;;;;;;;;;;GAaG;AACH,wBAAsB,aAAa,CACjC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,QAAQ,GAAE,KAAK,CAAC,eAAuB,GACtC,OAAO,CAAC,OAAO,CAAC,CAkBlB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,cAAc,EACvB,OAAO,CAAC,EAAE;IAAE,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,GAChC,OAAO,CAAC,MAAM,CAAC,CAajB"}
|
package/dist/accounts.js
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plain account and session functions for routes an app writes itself.
|
|
3
|
+
*
|
|
4
|
+
* `handlers.*` answer HTTP (`{ statusCode, body }`) in this package's own wire shape. An API with
|
|
5
|
+
* its own contract — its own paths, envelopes, status codes or error bodies — needs the same work
|
|
6
|
+
* as values it can map: {@link createAccount}, {@link signIn}, {@link checkPassword} and
|
|
7
|
+
* {@link issueSession}. They run the SAME code the mounted routes run (validation, the bonded
|
|
8
|
+
* password hasher and its constant-time comparison, two-factor, the device-bound session signed
|
|
9
|
+
* through the bonded JWT provider), so an app never hashes a password, compares one, or signs a
|
|
10
|
+
* token itself.
|
|
11
|
+
*
|
|
12
|
+
* @module
|
|
13
|
+
*/
|
|
14
|
+
import { get, getLogger } from '@molecule/api-bond';
|
|
15
|
+
import { findById } from '@molecule/api-database';
|
|
16
|
+
import { t } from '@molecule/api-i18n';
|
|
17
|
+
import { compare, hash } from '@molecule/api-password';
|
|
18
|
+
import * as authorization from './authorization.js';
|
|
19
|
+
import { create } from './handlers/create.js';
|
|
20
|
+
import { logIn } from './handlers/logIn.js';
|
|
21
|
+
const logger = getLogger();
|
|
22
|
+
/** The users table the functions use unless told otherwise — the one this package's routes use. */
|
|
23
|
+
const USERS = { name: 'User', tableName: 'users' };
|
|
24
|
+
const FAILURES = {
|
|
25
|
+
'user.error.usernameInvalid': { reason: 'username-invalid', field: 'username' },
|
|
26
|
+
'user.error.usernameUnavailable': { reason: 'username-taken', field: 'username' },
|
|
27
|
+
'user.error.emailInvalid': { reason: 'email-invalid', field: 'email' },
|
|
28
|
+
'user.error.emailAlreadyRegistered': { reason: 'email-taken', field: 'email' },
|
|
29
|
+
'user.error.passwordRequired': { reason: 'password-required', field: 'password' },
|
|
30
|
+
'user.error.passwordTooShort': { reason: 'password-too-short', field: 'password' },
|
|
31
|
+
'user.error.passwordTooLong': { reason: 'password-too-long', field: 'password' },
|
|
32
|
+
'user.error.invalidCredentials': { reason: 'invalid-credentials', field: null },
|
|
33
|
+
'user.error.invalidTwoFactorToken': { reason: 'two-factor-invalid', field: 'twoFactorToken' },
|
|
34
|
+
};
|
|
35
|
+
/** The request the handler reads, with only the fields this call names as its body. */
|
|
36
|
+
function withBody(req, body) {
|
|
37
|
+
// The prototype chain is kept: the session writer reads the real request.
|
|
38
|
+
return Object.create(req, {
|
|
39
|
+
body: { value: body, enumerable: true, writable: true, configurable: true },
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/** A handler's answer as an {@link AccountResult}. */
|
|
43
|
+
function asResult(answer) {
|
|
44
|
+
const body = (answer.body ?? {});
|
|
45
|
+
if (typeof body.accessToken === 'string' && body.props && typeof body.props === 'object')
|
|
46
|
+
return { ok: true, user: body.props, token: body.accessToken };
|
|
47
|
+
if (answer.statusCode === 206 || body.twoFactorRequired === true)
|
|
48
|
+
return {
|
|
49
|
+
ok: false,
|
|
50
|
+
reason: 'two-factor-required',
|
|
51
|
+
field: 'twoFactorToken',
|
|
52
|
+
message: t('user.error.twoFactorRequired', undefined, {
|
|
53
|
+
defaultValue: 'A two-factor code is required.',
|
|
54
|
+
}),
|
|
55
|
+
statusCode: 206,
|
|
56
|
+
errorKey: 'user.twoFactorRequired',
|
|
57
|
+
};
|
|
58
|
+
const errorKey = typeof body.errorKey === 'string' ? body.errorKey : '';
|
|
59
|
+
const known = FAILURES[errorKey];
|
|
60
|
+
return {
|
|
61
|
+
ok: false,
|
|
62
|
+
reason: known?.reason ?? (answer.statusCode >= 500 ? 'unavailable' : 'invalid'),
|
|
63
|
+
field: known?.field ?? null,
|
|
64
|
+
message: typeof body.error === 'string' ? body.error : '',
|
|
65
|
+
statusCode: answer.statusCode,
|
|
66
|
+
errorKey,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Creates an account from a sign-up form and signs it in.
|
|
71
|
+
*
|
|
72
|
+
* Call it from a route of your own when the API's contract is not this package's
|
|
73
|
+
* (`POST /users` with a `{ user: … }` envelope, say), and map the result:
|
|
74
|
+
*
|
|
75
|
+
* ```typescript
|
|
76
|
+
* import { createAccount } from '@molecule/api-resource-user'
|
|
77
|
+
*
|
|
78
|
+
* router.post('/users', async (req, res) => {
|
|
79
|
+
* const { username, email, password } = req.body.user ?? {}
|
|
80
|
+
* const account = await createAccount({ username, email, password }, { req, res })
|
|
81
|
+
* if (!account.ok)
|
|
82
|
+
* return res.status(422).json({ errors: { [account.field ?? 'account']: [account.message] } })
|
|
83
|
+
* res.status(201).json({ user: { ...account.user, token: account.token } })
|
|
84
|
+
* })
|
|
85
|
+
* ```
|
|
86
|
+
*
|
|
87
|
+
* It is `handlers.create` as a function: only `username`, `email` and `name` are taken from the
|
|
88
|
+
* input (nothing a caller adds is stored), the password is length-checked and hashed by the bonded
|
|
89
|
+
* `@molecule/api-password` provider into `usersSecrets`, a device row is created and the token is
|
|
90
|
+
* signed by the bonded `@molecule/api-jwt` provider — so it is a session `verifyMiddleware`
|
|
91
|
+
* accepts. The `Authorization` response header (and the session cookie, where the mount allows
|
|
92
|
+
* one) is set on `res` as the mounted route sets it.
|
|
93
|
+
*
|
|
94
|
+
* @param input - What the person entered.
|
|
95
|
+
* @param context - The current `{ req, res }`; the session header is set on `res`.
|
|
96
|
+
* @param resource - The users resource, when the app renamed the table. Defaults to `users`.
|
|
97
|
+
* @returns The signed-in account, or why none was created.
|
|
98
|
+
*/
|
|
99
|
+
export async function createAccount(input, context, resource = USERS) {
|
|
100
|
+
const { req, res } = context;
|
|
101
|
+
const body = {
|
|
102
|
+
...(input.username === undefined ? {} : { username: input.username }),
|
|
103
|
+
...(input.email === undefined ? {} : { email: input.email }),
|
|
104
|
+
...(input.name === undefined ? {} : { name: input.name }),
|
|
105
|
+
...(input.deviceName === undefined ? {} : { deviceName: input.deviceName }),
|
|
106
|
+
password: input.password,
|
|
107
|
+
};
|
|
108
|
+
return asResult(await create(resource)(withBody(req, body), res));
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Checks a username or email and password, and signs the person in.
|
|
112
|
+
*
|
|
113
|
+
* ```typescript
|
|
114
|
+
* import { signIn } from '@molecule/api-resource-user'
|
|
115
|
+
*
|
|
116
|
+
* router.post('/users/login', async (req, res) => {
|
|
117
|
+
* const { email, password } = req.body.user ?? {}
|
|
118
|
+
* const account = await signIn({ email, password }, { req, res })
|
|
119
|
+
* if (!account.ok) return res.status(401).json({ errors: { credentials: ['invalid'] } })
|
|
120
|
+
* res.json({ user: { ...account.user, token: account.token } })
|
|
121
|
+
* })
|
|
122
|
+
* ```
|
|
123
|
+
*
|
|
124
|
+
* It is `handlers.logIn` as a function, with nothing weakened: an unknown account and a wrong
|
|
125
|
+
* password take the same time and give the same `invalid-credentials`, the comparison is the
|
|
126
|
+
* bonded hasher's, an account with two-factor on answers `two-factor-required` until
|
|
127
|
+
* `twoFactorToken` is sent, and the session is device-bound, so sign-out and a password change
|
|
128
|
+
* revoke it. A password-reset token is not accepted here; use the reset routes for that.
|
|
129
|
+
*
|
|
130
|
+
* @param input - The credentials.
|
|
131
|
+
* @param context - The current `{ req, res }`; the session header is set on `res`.
|
|
132
|
+
* @param resource - The users resource, when the app renamed the table. Defaults to `users`.
|
|
133
|
+
* @returns The signed-in account, or why no one was signed in.
|
|
134
|
+
*/
|
|
135
|
+
export async function signIn(input, context, resource = USERS) {
|
|
136
|
+
const { req, res } = context;
|
|
137
|
+
const body = {
|
|
138
|
+
...(input.username === undefined ? {} : { username: input.username }),
|
|
139
|
+
...(input.email === undefined ? {} : { email: input.email }),
|
|
140
|
+
...(input.twoFactorToken === undefined ? {} : { twoFactorToken: input.twoFactorToken }),
|
|
141
|
+
...(input.deviceName === undefined ? {} : { deviceName: input.deviceName }),
|
|
142
|
+
password: input.password,
|
|
143
|
+
};
|
|
144
|
+
return asResult(await logIn(resource)(withBody(req, body), res));
|
|
145
|
+
}
|
|
146
|
+
let dummyHash;
|
|
147
|
+
/**
|
|
148
|
+
* Whether `password` is the account's current password — for a step that re-asks for it
|
|
149
|
+
* (confirming a deletion, changing an email in a route of your own).
|
|
150
|
+
*
|
|
151
|
+
* The comparison is the bonded `@molecule/api-password` provider's, against the hash in
|
|
152
|
+
* `usersSecrets`. An account with no password (OAuth-only) and an unknown id answer `false` after
|
|
153
|
+
* a comparison against a throwaway hash, so the answer's timing does not say which it was.
|
|
154
|
+
* Never compare hashes or passwords yourself.
|
|
155
|
+
*
|
|
156
|
+
* @param userId - The account's id (`users.id`, which is also its `usersSecrets.id`).
|
|
157
|
+
* @param password - The password the person entered.
|
|
158
|
+
* @param resource - The users resource, when the app renamed the table. Defaults to `users`.
|
|
159
|
+
* @returns True only when the password matches.
|
|
160
|
+
*/
|
|
161
|
+
export async function checkPassword(userId, password, resource = USERS) {
|
|
162
|
+
if (typeof password !== 'string' || password === '')
|
|
163
|
+
return false;
|
|
164
|
+
let stored = null;
|
|
165
|
+
try {
|
|
166
|
+
const secrets = await findById(`${resource.tableName}Secrets`, userId);
|
|
167
|
+
stored = typeof secrets?.passwordHash === 'string' ? secrets.passwordHash : null;
|
|
168
|
+
}
|
|
169
|
+
catch (error) {
|
|
170
|
+
logger.error('checkPassword: the credential row could not be read', error);
|
|
171
|
+
}
|
|
172
|
+
if (stored !== null)
|
|
173
|
+
return compare(password, stored);
|
|
174
|
+
try {
|
|
175
|
+
dummyHash ??= hash('molecule-dummy-password');
|
|
176
|
+
await compare(password, await dummyHash);
|
|
177
|
+
}
|
|
178
|
+
catch (_error) {
|
|
179
|
+
// The throwaway comparison only equalises timing; its failure changes no answer.
|
|
180
|
+
dummyHash = undefined;
|
|
181
|
+
}
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Signs in an account you have ALREADY authenticated some other way (a verified invite link, a
|
|
186
|
+
* single sign-on callback) and returns its session token.
|
|
187
|
+
*
|
|
188
|
+
* It creates the device row and has the bonded JWT provider sign a token bound to it — the two
|
|
189
|
+
* steps a session is. A token signed any other way names no device and is answered 401 by
|
|
190
|
+
* `verifyMiddleware` on every request. For a username or email and password use {@link signIn},
|
|
191
|
+
* which checks them first; this function checks nothing.
|
|
192
|
+
*
|
|
193
|
+
* @param userId - The authenticated account's id.
|
|
194
|
+
* @param context - The current `{ req, res }`; the session header is set on `res`.
|
|
195
|
+
* @param options - An optional label for the session's device row.
|
|
196
|
+
* @returns The session token.
|
|
197
|
+
* @throws {Error} When no device service is bonded or the device row cannot be written.
|
|
198
|
+
*/
|
|
199
|
+
export async function issueSession(userId, context, options) {
|
|
200
|
+
const { req, res } = context;
|
|
201
|
+
const deviceId = await get('device')?.createOrUpdate(userId, options?.deviceName || 'Unknown');
|
|
202
|
+
if (!deviceId)
|
|
203
|
+
throw new Error('issueSession: the session device could not be created (is the device service bonded?)');
|
|
204
|
+
const token = authorization.set(req, res, { userId, deviceId });
|
|
205
|
+
if (!token)
|
|
206
|
+
throw new Error('issueSession: the bonded JWT provider signed no token');
|
|
207
|
+
return token;
|
|
208
|
+
}
|
|
209
|
+
//# sourceMappingURL=accounts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accounts.js","sourceRoot":"","sources":["../src/accounts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AACnD,OAAO,EAAE,QAAQ,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F,OAAO,KAAK,CAAA;AACd,CAAC"}
|
package/dist/authorization.d.ts
CHANGED
|
@@ -237,7 +237,8 @@ export interface VerifyMiddlewareOptions {
|
|
|
237
237
|
*
|
|
238
238
|
* Pass `false` for a token-only JSON API. Then the cookie is not a credential here:
|
|
239
239
|
* the middleware does not resolve a session from it (and drops one an earlier, laxer
|
|
240
|
-
* mount already resolved from it
|
|
240
|
+
* mount already resolved from it, even when a supplied header fails verification),
|
|
241
|
+
* and {@link set} does not write it either — so a
|
|
241
242
|
* client that keeps a cookie jar (an HTTP test runner, `curl -b`) never picks up a
|
|
242
243
|
* session it should not have, and stops answering 200 on the step its spec calls
|
|
243
244
|
* "no auth".
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authorization.d.ts","sourceRoot":"","sources":["../src/authorization.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,OAAO,cAAc,CAAA;AAMrB,OAAO,KAAK,EACV,eAAe,EACf,sBAAsB,EACtB,gBAAgB,EACjB,MAAM,wBAAwB,CAAA;AAE/B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAwB1C;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,iBAAiB,GAAI,MAAM,MAAM,KAAG,MACP,CAAA;AA4B1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,eAAO,MAAM,oBAAoB,QAAO;IACtC,MAAM,EAAE,OAAO,CAAA;IACf,QAAQ,EAAE,KAAK,GAAG,MAAM,CAAA;IACxB,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,IAAI,EAAE,MAAM,CAAA;CAQb,CAAA;AAuBD;;;GAGG;AACH,eAAO,MAAM,mBAAmB,WAAW,CAAA;AAE3C;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,eAAe,CAAA;AAElD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,qBAAqB,cAAc,CAAA;AAuChD;;;;;;;;;GASG;AACH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CAAA;CAChB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,gBAAgB,GAC1B,UAAU,uBAAuB,KAAG,sBAqHpC,CAAA"}
|
package/dist/authorization.js
CHANGED
|
@@ -549,6 +549,13 @@ export const verifyMiddleware = (options) => async (req, res, next) => {
|
|
|
549
549
|
res.locals[AUTH_SCHEME_LOCALS_KEY] = scheme;
|
|
550
550
|
const allowCookieSession = options?.allowCookieSession ?? scheme.toLowerCase() === DEFAULT_AUTH_SCHEME.toLowerCase();
|
|
551
551
|
res.locals[ALLOW_COOKIE_SESSION_LOCALS_KEY] = allowCookieSession;
|
|
552
|
+
// Enforce this mount's policy before attempting a header credential. A later failure
|
|
553
|
+
// (invalid signature, missing device or revoked device) must not leave the earlier
|
|
554
|
+
// cookie session authenticated. Header-resolved sessions retain their existing policy.
|
|
555
|
+
if (!allowCookieSession && res.locals[AUTH_SESSION_SOURCE_LOCALS_KEY] === 'cookie') {
|
|
556
|
+
delete res.locals.session;
|
|
557
|
+
delete res.locals[AUTH_SESSION_SOURCE_LOCALS_KEY];
|
|
558
|
+
}
|
|
552
559
|
// Get token from Authorization header, falling back to the `token`
|
|
553
560
|
// cookie that `set()` writes alongside the header. The JSDoc above
|
|
554
561
|
// promises this fallback for browser clients; without it the cookie
|
|
@@ -569,18 +576,6 @@ export const verifyMiddleware = (options) => async (req, res, next) => {
|
|
|
569
576
|
const token = headerToken ??
|
|
570
577
|
(allowCookieSession && typeof cookieToken === 'string' && cookieToken ? cookieToken : null);
|
|
571
578
|
if (!token) {
|
|
572
|
-
// A token-only mount accepts NOTHING from the cookie — not even a session an
|
|
573
|
-
// earlier, laxer mount already resolved out of it. The scaffold mounts
|
|
574
|
-
// `verifyMiddleware` twice (server.ts's `preApiRouter` runs first, then
|
|
575
|
-
// App/router.ts), and the first one runs for every `/api` request: without
|
|
576
|
-
// this the app's own routes would still read `res.locals.session` off the
|
|
577
|
-
// cookie and answer 200 where the spec says 401. A header-resolved session is
|
|
578
|
-
// left alone — that client sent its credentials, which is what a token-only
|
|
579
|
-
// API accepts.
|
|
580
|
-
if (!allowCookieSession && res.locals[AUTH_SESSION_SOURCE_LOCALS_KEY] === 'cookie') {
|
|
581
|
-
delete res.locals.session;
|
|
582
|
-
delete res.locals[AUTH_SESSION_SOURCE_LOCALS_KEY];
|
|
583
|
-
}
|
|
584
579
|
return next();
|
|
585
580
|
}
|
|
586
581
|
// Try to verify the token.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authorization.js","sourceRoot":"","sources":["../src/authorization.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,0EAA0E;AAC1E,gFAAgF;AAChF,oCAAoC;AACpC,OAAO,cAAc,CAAA;AACrB,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAA;AAEjC,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AACnD,OAAO,EAAE,GAAG,IAAI,SAAS,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,mBAAmB,CAAA;AASrE,MAAM,MAAM,GAAG,SAAS,EAAE,CAAA;AAE1B,MAAM,iBAAiB,GAAG,GAAW,EAAE;IACrC,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,SAAS,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC,IAAI,IAAI,GAAG,EAAE,GAAG,EAAE,CAAA,CAAC,aAAa;IACrF,CAAC;IAAC,OAAO,MAAM,EAAE,CAAC;QAChB,wEAAwE;QACxE,OAAO,IAAI,GAAG,EAAE,GAAG,EAAE,CAAA,CAAC,qBAAqB;IAC7C,CAAC;AACH,CAAC,CAAA;AAED,MAAM,YAAY,GAAG,GAAY,EAAE;IACjC,IAAI,CAAC;QACH,OAAO,SAAS,CAAC,UAAU,CAAC,KAAK,YAAY,CAAA;IAC/C,CAAC;IAAC,OAAO,M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@
|
|
|
29
29
|
* answers `existing` and repairs nothing. **TRUSTED SERVER CALLERS ONLY:** it takes props
|
|
30
30
|
* directly, so a public endpoint built on it is a mass-assignment hole.
|
|
31
31
|
*
|
|
32
|
-
*
|
|
33
|
-
* `
|
|
34
|
-
*
|
|
35
|
-
*
|
|
32
|
+
* **Your own sign-up and sign-in routes call
|
|
33
|
+
* `createAccount({ username, email, password }, { req, res })` and {@link signIn}:** each
|
|
34
|
+
* resolves to `{ ok, user, token }`, and `token` is the session.
|
|
35
|
+
* Never call `sign()`, `hash()` or `compare()` for accounts yourself.
|
|
36
36
|
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* store). Set `AUTH_SCHEME=Token` (or `verifyMiddleware({ scheme: 'Token' })`): every route
|
|
40
|
-
* accepts it, `logIn`/`create` return `accessToken`, `GET /users/me` echoes it, and a password
|
|
41
|
-
* change revokes every OTHER device but keeps the caller's own session.
|
|
37
|
+
* HTTP path: `handlers.create`, `handlers.logIn`, `handlers.updatePassword`. One secret:
|
|
38
|
+
* `findById('usersSecrets', userId)`.
|
|
42
39
|
*
|
|
43
|
-
* **
|
|
40
|
+
* **Token API (`Authorization: Token <jwt>`)? CONFIGURATION,
|
|
41
|
+
* never a credentials table of your own** (`usersSecrets.passwordHash` is the store): set
|
|
42
|
+
* `AUTH_SCHEME=Token` (or `verifyMiddleware({ scheme: 'Token' })`) — every route accepts it,
|
|
43
|
+
* `logIn`/`create` return `accessToken`, `GET /users/me` echoes it, and a password change
|
|
44
|
+
* revokes every OTHER device but keeps the
|
|
45
|
+
* caller's own session.
|
|
44
46
|
*
|
|
45
47
|
* **`handlers.*` return `{ statusCode, headers?, body }` and never write to `res`** — not through
|
|
46
48
|
* `res.json`, not through `res.send`, not through `res.end`. The mounted routes apply that object
|
|
@@ -56,6 +58,10 @@
|
|
|
56
58
|
* Monkey-patching `res.json` to re-shape a handler's answer intercepts nothing the handler
|
|
57
59
|
* produces, so the request it was meant to answer is left unanswered and hangs.
|
|
58
60
|
*
|
|
61
|
+
* **Generated full-stack apps:** mlcl derives the app-auth composition root from this API contract; keep that bond and use its shared HTTP client.
|
|
62
|
+
* Header-only mounts discard a session inherited from a cookie-enabled mount before
|
|
63
|
+
* verifying the header, including when that header is invalid or its device was revoked.
|
|
64
|
+
*
|
|
59
65
|
* **Adapt envelopes with `createRequestHandler(handler, options)` from
|
|
60
66
|
* `@molecule/api-resource` 1.1 or newer.** Keep `handlers.create(resource)` and
|
|
61
67
|
* `handlers.logIn(resource)` as the handler. `mapRequest: (req) =>
|
|
@@ -105,8 +111,8 @@
|
|
|
105
111
|
* import { createResource, handlers } from '@molecule/api-resource-user'
|
|
106
112
|
*
|
|
107
113
|
* // Omit `schema`: create() validates new users with this package's propsSchema.
|
|
108
|
-
* const
|
|
109
|
-
* const
|
|
114
|
+
* const signUpRoute = createRequestHandler(handlers.create({ name: 'User', tableName: 'users' }))
|
|
115
|
+
* const signInRoute = createRequestHandler(handlers.logIn({ name: 'User', tableName: 'users' }))
|
|
110
116
|
*
|
|
111
117
|
* // A constrained schema, when the app restricts oauthServer / planKey.
|
|
112
118
|
* const users = createResource({ oauthServers: ['google', 'github'] as const })
|
|
@@ -322,13 +328,21 @@
|
|
|
322
328
|
* login or an explicit denial — never a blank page).
|
|
323
329
|
* - [ ] A profile/account edit (e.g. display name) persists across a reload.
|
|
324
330
|
*
|
|
331
|
+
* **Public profiles for a list:** call `getPublicProfiles(userIds)` once for the page,
|
|
332
|
+
* then join its map by canonical id. It reads only public display columns in one query,
|
|
333
|
+
* deduplicates repeated ids, omits missing users and does no I/O for an empty page.
|
|
334
|
+
* Never serialize a complete account row beside public content: email, OAuth and plan fields
|
|
335
|
+
* are not public profile data. A renamed users table uses `getPublicProfiles(ids, { tableName })`.
|
|
336
|
+
*
|
|
325
337
|
* @module
|
|
326
338
|
*/
|
|
339
|
+
export * from './accounts.js';
|
|
327
340
|
export * as authorization from './authorization.js';
|
|
328
341
|
export * as authorizers from './authorizers/index.js';
|
|
329
342
|
export * from './browser-guard.js';
|
|
330
343
|
export * as handlers from './handlers/index.js';
|
|
331
344
|
export * from './i18n.js';
|
|
345
|
+
export * from './profiles.js';
|
|
332
346
|
export * from './provisioning.js';
|
|
333
347
|
export * from './requestHandlerMap.js';
|
|
334
348
|
export * from './resource.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiVG;AAEH,cAAc,eAAe,CAAA;AAC7B,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAA;AACnD,OAAO,KAAK,WAAW,MAAM,wBAAwB,CAAA;AACrD,cAAc,oBAAoB,CAAA;AAClC,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAA;AAC/C,cAAc,WAAW,CAAA;AACzB,cAAc,eAAe,CAAA;AAC7B,cAAc,mBAAmB,CAAA;AACjC,cAAc,wBAAwB,CAAA;AACtC,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AACnC,OAAO,KAAK,SAAS,MAAM,sBAAsB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -29,18 +29,20 @@
|
|
|
29
29
|
* answers `existing` and repairs nothing. **TRUSTED SERVER CALLERS ONLY:** it takes props
|
|
30
30
|
* directly, so a public endpoint built on it is a mass-assignment hole.
|
|
31
31
|
*
|
|
32
|
-
*
|
|
33
|
-
* `
|
|
34
|
-
*
|
|
35
|
-
*
|
|
32
|
+
* **Your own sign-up and sign-in routes call
|
|
33
|
+
* `createAccount({ username, email, password }, { req, res })` and {@link signIn}:** each
|
|
34
|
+
* resolves to `{ ok, user, token }`, and `token` is the session.
|
|
35
|
+
* Never call `sign()`, `hash()` or `compare()` for accounts yourself.
|
|
36
36
|
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* store). Set `AUTH_SCHEME=Token` (or `verifyMiddleware({ scheme: 'Token' })`): every route
|
|
40
|
-
* accepts it, `logIn`/`create` return `accessToken`, `GET /users/me` echoes it, and a password
|
|
41
|
-
* change revokes every OTHER device but keeps the caller's own session.
|
|
37
|
+
* HTTP path: `handlers.create`, `handlers.logIn`, `handlers.updatePassword`. One secret:
|
|
38
|
+
* `findById('usersSecrets', userId)`.
|
|
42
39
|
*
|
|
43
|
-
* **
|
|
40
|
+
* **Token API (`Authorization: Token <jwt>`)? CONFIGURATION,
|
|
41
|
+
* never a credentials table of your own** (`usersSecrets.passwordHash` is the store): set
|
|
42
|
+
* `AUTH_SCHEME=Token` (or `verifyMiddleware({ scheme: 'Token' })`) — every route accepts it,
|
|
43
|
+
* `logIn`/`create` return `accessToken`, `GET /users/me` echoes it, and a password change
|
|
44
|
+
* revokes every OTHER device but keeps the
|
|
45
|
+
* caller's own session.
|
|
44
46
|
*
|
|
45
47
|
* **`handlers.*` return `{ statusCode, headers?, body }` and never write to `res`** — not through
|
|
46
48
|
* `res.json`, not through `res.send`, not through `res.end`. The mounted routes apply that object
|
|
@@ -56,6 +58,10 @@
|
|
|
56
58
|
* Monkey-patching `res.json` to re-shape a handler's answer intercepts nothing the handler
|
|
57
59
|
* produces, so the request it was meant to answer is left unanswered and hangs.
|
|
58
60
|
*
|
|
61
|
+
* **Generated full-stack apps:** mlcl derives the app-auth composition root from this API contract; keep that bond and use its shared HTTP client.
|
|
62
|
+
* Header-only mounts discard a session inherited from a cookie-enabled mount before
|
|
63
|
+
* verifying the header, including when that header is invalid or its device was revoked.
|
|
64
|
+
*
|
|
59
65
|
* **Adapt envelopes with `createRequestHandler(handler, options)` from
|
|
60
66
|
* `@molecule/api-resource` 1.1 or newer.** Keep `handlers.create(resource)` and
|
|
61
67
|
* `handlers.logIn(resource)` as the handler. `mapRequest: (req) =>
|
|
@@ -105,8 +111,8 @@
|
|
|
105
111
|
* import { createResource, handlers } from '@molecule/api-resource-user'
|
|
106
112
|
*
|
|
107
113
|
* // Omit `schema`: create() validates new users with this package's propsSchema.
|
|
108
|
-
* const
|
|
109
|
-
* const
|
|
114
|
+
* const signUpRoute = createRequestHandler(handlers.create({ name: 'User', tableName: 'users' }))
|
|
115
|
+
* const signInRoute = createRequestHandler(handlers.logIn({ name: 'User', tableName: 'users' }))
|
|
110
116
|
*
|
|
111
117
|
* // A constrained schema, when the app restricts oauthServer / planKey.
|
|
112
118
|
* const users = createResource({ oauthServers: ['google', 'github'] as const })
|
|
@@ -322,13 +328,21 @@
|
|
|
322
328
|
* login or an explicit denial — never a blank page).
|
|
323
329
|
* - [ ] A profile/account edit (e.g. display name) persists across a reload.
|
|
324
330
|
*
|
|
331
|
+
* **Public profiles for a list:** call `getPublicProfiles(userIds)` once for the page,
|
|
332
|
+
* then join its map by canonical id. It reads only public display columns in one query,
|
|
333
|
+
* deduplicates repeated ids, omits missing users and does no I/O for an empty page.
|
|
334
|
+
* Never serialize a complete account row beside public content: email, OAuth and plan fields
|
|
335
|
+
* are not public profile data. A renamed users table uses `getPublicProfiles(ids, { tableName })`.
|
|
336
|
+
*
|
|
325
337
|
* @module
|
|
326
338
|
*/
|
|
339
|
+
export * from './accounts.js';
|
|
327
340
|
export * as authorization from './authorization.js';
|
|
328
341
|
export * as authorizers from './authorizers/index.js';
|
|
329
342
|
export * from './browser-guard.js';
|
|
330
343
|
export * as handlers from './handlers/index.js';
|
|
331
344
|
export * from './i18n.js';
|
|
345
|
+
export * from './profiles.js';
|
|
332
346
|
export * from './provisioning.js';
|
|
333
347
|
export * from './requestHandlerMap.js';
|
|
334
348
|
export * from './resource.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiVG;AAEH,cAAc,eAAe,CAAA;AAC7B,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAA;AACnD,OAAO,KAAK,WAAW,MAAM,wBAAwB,CAAA;AACrD,cAAc,oBAAoB,CAAA;AAClC,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAA;AAC/C,cAAc,WAAW,CAAA;AACzB,cAAc,eAAe,CAAA;AAC7B,cAAc,mBAAmB,CAAA;AACjC,cAAc,wBAAwB,CAAA;AACtC,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AACnC,OAAO,KAAK,SAAS,MAAM,sBAAsB,CAAA"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public user profiles loaded once for a collection, through the bonded store.
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
5
|
+
import type { HandlerResource } from './types.js';
|
|
6
|
+
/** User columns safe to display beside content. Account and credential fields are excluded. */
|
|
7
|
+
export interface PublicProfile {
|
|
8
|
+
/** The user's canonical id. */
|
|
9
|
+
id: string;
|
|
10
|
+
/** The public username, when set. */
|
|
11
|
+
username: string | null;
|
|
12
|
+
/** The public display name, when set. */
|
|
13
|
+
name: string | null;
|
|
14
|
+
/** The public biography, when set. */
|
|
15
|
+
bio: string | null;
|
|
16
|
+
/** The public avatar URL, when set. */
|
|
17
|
+
avatar: string | null;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Load the public profiles for a collection in one database query.
|
|
21
|
+
*
|
|
22
|
+
* Pass every user id from the page once, then join by id while projecting the response.
|
|
23
|
+
* Repeated ids are deduplicated; absent users have no map entry. An empty input does no I/O.
|
|
24
|
+
* Nothing is cached between calls, so a later profile update is visible immediately.
|
|
25
|
+
* The resource option supports an application's renamed users table with the same columns.
|
|
26
|
+
*
|
|
27
|
+
* @param userIds - Canonical user ids referenced by the collection.
|
|
28
|
+
* @param resource - Users resource; defaults to the package's `users` table.
|
|
29
|
+
* @returns Public profiles keyed by id, without email, plan, OAuth or secret fields.
|
|
30
|
+
*/
|
|
31
|
+
export declare function getPublicProfiles(userIds: readonly string[], resource?: Pick<HandlerResource, 'tableName'>): Promise<Map<string, PublicProfile>>;
|
|
32
|
+
//# sourceMappingURL=profiles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profiles.d.ts","sourceRoot":"","sources":["../src/profiles.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAEjD,+FAA+F;AAC/F,MAAM,WAAW,aAAa;IAC5B,+BAA+B;IAC/B,EAAE,EAAE,MAAM,CAAA;IACV,qCAAqC;IACrC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,yCAAyC;IACzC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;IACnB,sCAAsC;IACtC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;IAClB,uCAAuC;IACvC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;CACtB;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,SAAS,MAAM,EAAE,EAC1B,QAAQ,GAAE,IAAI,CAAC,eAAe,EAAE,WAAW,CAA0B,GACpE,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,CAmBrC"}
|
package/dist/profiles.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public user profiles loaded once for a collection, through the bonded store.
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
5
|
+
import { findMany } from '@molecule/api-database';
|
|
6
|
+
/**
|
|
7
|
+
* Load the public profiles for a collection in one database query.
|
|
8
|
+
*
|
|
9
|
+
* Pass every user id from the page once, then join by id while projecting the response.
|
|
10
|
+
* Repeated ids are deduplicated; absent users have no map entry. An empty input does no I/O.
|
|
11
|
+
* Nothing is cached between calls, so a later profile update is visible immediately.
|
|
12
|
+
* The resource option supports an application's renamed users table with the same columns.
|
|
13
|
+
*
|
|
14
|
+
* @param userIds - Canonical user ids referenced by the collection.
|
|
15
|
+
* @param resource - Users resource; defaults to the package's `users` table.
|
|
16
|
+
* @returns Public profiles keyed by id, without email, plan, OAuth or secret fields.
|
|
17
|
+
*/
|
|
18
|
+
export async function getPublicProfiles(userIds, resource = { tableName: 'users' }) {
|
|
19
|
+
const ids = [...new Set(userIds)];
|
|
20
|
+
if (ids.length === 0)
|
|
21
|
+
return new Map();
|
|
22
|
+
const rows = await findMany(resource.tableName, {
|
|
23
|
+
where: [{ field: 'id', operator: 'in', value: ids }],
|
|
24
|
+
select: ['id', 'username', 'name', 'bio', 'avatar'],
|
|
25
|
+
});
|
|
26
|
+
return new Map(rows.map((row) => [
|
|
27
|
+
row.id,
|
|
28
|
+
{
|
|
29
|
+
id: row.id,
|
|
30
|
+
username: row.username ?? null,
|
|
31
|
+
name: row.name ?? null,
|
|
32
|
+
bio: row.bio ?? null,
|
|
33
|
+
avatar: row.avatar ?? null,
|
|
34
|
+
},
|
|
35
|
+
]));
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=profiles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profiles.js","sourceRoot":"","sources":["../src/profiles.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAA;AAkBjD;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,OAA0B,EAC1B,WAA+C,EAAE,SAAS,EAAE,OAAO,EAAE;IAErE,MAAM,GAAG,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC,CAAA;IACjC,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,GAAG,EAAE,CAAA;IACtC,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAgB,QAAQ,CAAC,SAAS,EAAE;QAC7D,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC;QACpD,MAAM,EAAE,CAAC,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAC;KACpD,CAAC,CAAA;IACF,OAAO,IAAI,GAAG,CACZ,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC;QAChB,GAAG,CAAC,EAAE;QACN;YACE,EAAE,EAAE,GAAG,CAAC,EAAE;YACV,QAAQ,EAAE,GAAG,CAAC,QAAQ,IAAI,IAAI;YAC9B,IAAI,EAAE,GAAG,CAAC,IAAI,IAAI,IAAI;YACtB,GAAG,EAAE,GAAG,CAAC,GAAG,IAAI,IAAI;YACpB,MAAM,EAAE,GAAG,CAAC,MAAM,IAAI,IAAI;SAC3B;KACF,CAAC,CACH,CAAA;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molecule/api-resource-user",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0",
|
|
4
4
|
"description": "User resource types and schema for molecule.dev.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@molecule/api-bond": "1.0.4",
|
|
37
37
|
"@molecule/api-config": "1.0.4",
|
|
38
|
-
"@molecule/api-locales-user": "1.1.
|
|
38
|
+
"@molecule/api-locales-user": "1.1.1",
|
|
39
39
|
"@molecule/api-locales-user-payments": "1.0.3",
|
|
40
40
|
"@molecule/api-payments": "1.2.3",
|
|
41
41
|
"@molecule/api-push-notifications": "1.0.3",
|