@nxgt/janus 0.3.0 → 0.4.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 +40 -4
- package/dist/auth/index.d.ts +1 -1
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/port/types.d.ts +70 -2
- package/dist/auth/port/types.d.ts.map +1 -1
- package/dist/auth/users.d.ts.map +1 -1
- package/dist/chunks/{index-8tksqzkr.js → index-thtyq7a9.js} +13 -2
- package/dist/chunks/{index-8tksqzkr.js.map → index-thtyq7a9.js.map} +3 -3
- package/dist/conformance/cases/outage.d.ts.map +1 -1
- package/dist/conformance/cases/tokens.d.ts.map +1 -1
- package/dist/conformance/cases/users.d.ts.map +1 -1
- package/dist/conformance/fixtures.d.ts.map +1 -1
- package/dist/conformance/index.js +109 -3
- package/dist/conformance/index.js.map +6 -6
- package/dist/index.js +6 -3
- package/dist/index.js.map +4 -4
- package/docs/README.md +1 -1
- package/docs/guide/adapters.md +124 -3
- package/docs/guide/vocabulary.md +3 -1
- package/docs/roadmap.md +14 -5
- package/docs/troubleshooting.md +16 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -396,6 +396,38 @@ adapter. `assertStores(store, where)` is the check `janus()` runs on it, for an
|
|
|
396
396
|
adapter that wants to fail as early. The six rules an adapter keeps are
|
|
397
397
|
written on the port's types.
|
|
398
398
|
|
|
399
|
+
The port already holds what one-time codes need, before any flow uses it: a
|
|
400
|
+
user's `secondFactor` (a TOTP secret, or `null`; the core will seal it before
|
|
401
|
+
a store sees it, once the second factor ships), a token's `codeHash` and
|
|
402
|
+
`attempts`, and `TokenStore.countAttempt`, which counts one attempt in one
|
|
403
|
+
conditional write:
|
|
404
|
+
|
|
405
|
+
```ts
|
|
406
|
+
import { createMemoryStores, mintId } from '@nxgt/janus';
|
|
407
|
+
|
|
408
|
+
const { tokens } = createMemoryStores();
|
|
409
|
+
const tokenHash = 'a'.repeat(64); // the core stores sha256 of the secret
|
|
410
|
+
await tokens.insertToken({
|
|
411
|
+
tokenHash,
|
|
412
|
+
kind: 'signInCode',
|
|
413
|
+
userId: mintId(),
|
|
414
|
+
address: 'ada@example.test',
|
|
415
|
+
codeHash: 'c'.repeat(64),
|
|
416
|
+
attempts: 0,
|
|
417
|
+
expiresAt: new Date(Date.now() + 10 * 60_000),
|
|
418
|
+
spentAt: null,
|
|
419
|
+
createdAt: new Date(),
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
await tokens.countAttempt(tokenHash, 'signInCode'); // { …, attempts: 1 }
|
|
423
|
+
await tokens.countAttempt(tokenHash, 'verifyEmail'); // null: no token of that kind
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
An adapter written against `@nxgt/janus` 0.3 does not compile against this
|
|
427
|
+
port until it implements `countAttempt`, and `janus()` refuses it at wiring —
|
|
428
|
+
[Writing an adapter](docs/guide/adapters.md#tokenstorecountattempt) has the
|
|
429
|
+
contract.
|
|
430
|
+
|
|
399
431
|
### Permissions — `@nxgt/janus/permissions`
|
|
400
432
|
|
|
401
433
|
```ts
|
|
@@ -506,7 +538,7 @@ describeJanusStores({
|
|
|
506
538
|
});
|
|
507
539
|
```
|
|
508
540
|
|
|
509
|
-
There are
|
|
541
|
+
There are 44 cases. They cover:
|
|
510
542
|
- round-trip, byte for byte — including every edge character the core lets
|
|
511
543
|
through (control characters, U+FFFF, a surrogate pair);
|
|
512
544
|
- uniqueness, as a constraint: of twenty concurrent inserts of one login,
|
|
@@ -517,9 +549,13 @@ There are 38 cases. They cover:
|
|
|
517
549
|
- pagination;
|
|
518
550
|
- sessions;
|
|
519
551
|
- one-time tokens: of twenty concurrent redemptions, exactly one succeeds;
|
|
552
|
+
of twenty concurrent `countAttempt` calls, each answers a distinct count,
|
|
553
|
+
and none is counted once a racing redemption spent the token;
|
|
554
|
+
- a user's second factor: round-trip, kept by a patch that does not name it,
|
|
555
|
+
removed by one that names `null`;
|
|
520
556
|
- deletion: a user's logins are freed, and every session and token of theirs
|
|
521
557
|
goes, with a replay answering `false` or `0` rather than failing;
|
|
522
|
-
- **outages**, one case for each of the
|
|
558
|
+
- **outages**, one case for each of the twelve methods whose honest answer can
|
|
523
559
|
be "nothing".
|
|
524
560
|
|
|
525
561
|
The suite imports no test framework and no assertion library. It runs under
|
|
@@ -655,13 +691,13 @@ could not answer: that is a denial made of an outage.
|
|
|
655
691
|
|
|
656
692
|
## Type safety, counted
|
|
657
693
|
|
|
658
|
-
**
|
|
694
|
+
**One hundred and three plausible mistakes, one hundred and three refused at compile time — and
|
|
659
695
|
two gaps, named.**
|
|
660
696
|
|
|
661
697
|
The lists are typechecked and never run, with one `@ts-expect-error` per
|
|
662
698
|
mistake beside the shapes that must keep compiling:
|
|
663
699
|
`test/types/refusals.ts` (fourteen, on the shared vocabulary),
|
|
664
|
-
`test/types/port.ts` (
|
|
700
|
+
`test/types/port.ts` (twenty-one, on the identity stores' port, from the point
|
|
665
701
|
of view of the person implementing it), `test/types/auth.ts` (twenty, on
|
|
666
702
|
`janus()`, from the point of view of the application) and `test/types/permissions.ts` (forty-eight, on the
|
|
667
703
|
permission model and the questions asked of it). The rule
|
package/dist/auth/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { bunHasher, scryptHasher } from './hashers';
|
|
|
3
3
|
export { janus } from './janus';
|
|
4
4
|
export { assertStores } from './port/assert-stores';
|
|
5
5
|
export { createMemoryStores } from './port/memory';
|
|
6
|
-
export type { JanusStores, Json, JsonObject, PasswordRecord, SessionId, SessionRecord, SessionStore, StoreCapabilities, TokenKind, TokenRecord, TokenStore, UserPageRequest, UserPatch, UserRecord, UserStore, } from './port/types';
|
|
6
|
+
export type { JanusStores, Json, JsonObject, PasswordRecord, SecondFactorRecord, SessionId, SessionRecord, SessionStore, StoreCapabilities, TokenKind, TokenRecord, TokenStore, UserPageRequest, UserPatch, UserRecord, UserStore, } from './port/types';
|
|
7
7
|
export type { StandardSchemaV1 } from './standard-schema';
|
|
8
8
|
export type { Authenticated, Checked, EmailOf, HeaderRecord, IssuedToken, Janus, LoginOf, PasswordApi, RequestLike, RequiredStringKeys, ResetPasswordApi, Session, SharedApi, SignedIn, TypeApi, TypesOf, User, UserBase, UserOf, UserRef, UserTypeApi, VerifyEmailApi, WriteOptions, } from './types';
|
|
9
9
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/auth/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACX,YAAY,EACZ,UAAU,EACV,WAAW,EACX,eAAe,EACf,SAAS,EACT,cAAc,EACd,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,UAAU,EACV,cAAc,GACd,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,YAAY,EACX,WAAW,EACX,IAAI,EACJ,UAAU,EACV,cAAc,EACd,SAAS,EACT,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,SAAS,EACT,WAAW,EACX,UAAU,EACV,eAAe,EACf,SAAS,EACT,UAAU,EACV,SAAS,GACT,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,YAAY,EACX,aAAa,EACb,OAAO,EACP,OAAO,EACP,YAAY,EACZ,WAAW,EACX,KAAK,EACL,OAAO,EACP,WAAW,EACX,WAAW,EACX,kBAAkB,EAClB,gBAAgB,EAChB,OAAO,EACP,SAAS,EACT,QAAQ,EACR,OAAO,EACP,OAAO,EACP,IAAI,EACJ,QAAQ,EACR,MAAM,EACN,OAAO,EACP,WAAW,EACX,cAAc,EACd,YAAY,GACZ,MAAM,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACX,YAAY,EACZ,UAAU,EACV,WAAW,EACX,eAAe,EACf,SAAS,EACT,cAAc,EACd,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,UAAU,EACV,cAAc,GACd,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,YAAY,EACX,WAAW,EACX,IAAI,EACJ,UAAU,EACV,cAAc,EACd,kBAAkB,EAClB,SAAS,EACT,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,SAAS,EACT,WAAW,EACX,UAAU,EACV,eAAe,EACf,SAAS,EACT,UAAU,EACV,SAAS,GACT,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,YAAY,EACX,aAAa,EACb,OAAO,EACP,OAAO,EACP,YAAY,EACZ,WAAW,EACX,KAAK,EACL,OAAO,EACP,WAAW,EACX,WAAW,EACX,kBAAkB,EAClB,gBAAgB,EAChB,OAAO,EACP,SAAS,EACT,QAAQ,EACR,OAAO,EACP,OAAO,EACP,IAAI,EACJ,QAAQ,EACR,MAAM,EACN,OAAO,EACP,WAAW,EACX,cAAc,EACd,YAAY,GACZ,MAAM,SAAS,CAAC"}
|
|
@@ -84,6 +84,31 @@ export interface PasswordRecord {
|
|
|
84
84
|
readonly hash: string;
|
|
85
85
|
readonly updatedAt: Date;
|
|
86
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* A second factor, as the store holds it: a TOTP secret.
|
|
89
|
+
*
|
|
90
|
+
* **The secret is opaque to a store.** Once the second factor ships, the core
|
|
91
|
+
* will seal it with a key the application holds before a store ever sees it,
|
|
92
|
+
* so a dump of the users cannot produce a code. A store keeps the string byte
|
|
93
|
+
* for byte, like a password hash, and never parses it.
|
|
94
|
+
*/
|
|
95
|
+
export interface SecondFactorRecord {
|
|
96
|
+
/** How the codes are made. `'totp'`, the codes of an authenticator app, is the only one. */
|
|
97
|
+
readonly method: 'totp';
|
|
98
|
+
/** The secret, opaque to a store: kept byte for byte. */
|
|
99
|
+
readonly secret: string;
|
|
100
|
+
/**
|
|
101
|
+
* When the user proved their app holds the secret, with a first code — or
|
|
102
|
+
* `null` while the enrolment waits for it. A second factor is asked for at
|
|
103
|
+
* sign-in only once confirmed.
|
|
104
|
+
*/
|
|
105
|
+
readonly confirmedAt: Date | null;
|
|
106
|
+
/**
|
|
107
|
+
* The time step of the last code accepted, or `null` before the first. A
|
|
108
|
+
* code of this step or an earlier one is refused, so a code works once.
|
|
109
|
+
*/
|
|
110
|
+
readonly lastStep: number | null;
|
|
111
|
+
}
|
|
87
112
|
/**
|
|
88
113
|
* A user, as a store holds it.
|
|
89
114
|
*
|
|
@@ -122,6 +147,8 @@ export interface UserRecord {
|
|
|
122
147
|
readonly logins: readonly string[];
|
|
123
148
|
/** `null` when the user has no password. */
|
|
124
149
|
readonly password: PasswordRecord | null;
|
|
150
|
+
/** `null` when the user has no second factor. */
|
|
151
|
+
readonly secondFactor: SecondFactorRecord | null;
|
|
125
152
|
/**
|
|
126
153
|
* When the user proved they hold their current e-mail, or `null`. The core
|
|
127
154
|
* sets it back to `null` in the same write that changes the e-mail.
|
|
@@ -166,6 +193,7 @@ export interface UserPatch {
|
|
|
166
193
|
readonly fields?: JsonObject;
|
|
167
194
|
readonly logins?: readonly string[];
|
|
168
195
|
readonly password?: PasswordRecord | null;
|
|
196
|
+
readonly secondFactor?: SecondFactorRecord | null;
|
|
169
197
|
readonly emailVerifiedAt?: Date | null;
|
|
170
198
|
}
|
|
171
199
|
/** Which users a page lists, where it starts, and how much of it to read. */
|
|
@@ -328,8 +356,16 @@ export interface SessionStore {
|
|
|
328
356
|
*/
|
|
329
357
|
deleteExpiredSessions?(before: Date): Promise<number>;
|
|
330
358
|
}
|
|
331
|
-
/**
|
|
332
|
-
|
|
359
|
+
/**
|
|
360
|
+
* What a one-time token is for. A token redeemed for another purpose is
|
|
361
|
+
* unknown.
|
|
362
|
+
*
|
|
363
|
+
* - `verifyEmail`, `resetPassword`: a link sent by e-mail.
|
|
364
|
+
* - `secondFactor`: the challenge a sign-in answers when the user has a second
|
|
365
|
+
* factor, redeemed with a code from their app.
|
|
366
|
+
* - `signInCode`: a code sent by e-mail to sign in without a password.
|
|
367
|
+
*/
|
|
368
|
+
export type TokenKind = 'verifyEmail' | 'resetPassword' | 'secondFactor' | 'signInCode';
|
|
333
369
|
/** A one-time token, as a store holds it: its hash, never its secret. */
|
|
334
370
|
export interface TokenRecord {
|
|
335
371
|
/** `sha256` of the token's secret, hex. Unique across the store. */
|
|
@@ -338,6 +374,19 @@ export interface TokenRecord {
|
|
|
338
374
|
readonly userId: Id;
|
|
339
375
|
/** The e-mail the token was sent to — the one a verification marks verified. */
|
|
340
376
|
readonly address: string;
|
|
377
|
+
/**
|
|
378
|
+
* For a token redeemed with a code — `signInCode` — the code's hash, keyed
|
|
379
|
+
* by the token's secret, so the tokens alone do not reveal it. `null` for
|
|
380
|
+
* every other kind: the core writes it so, and a store keeps what it is
|
|
381
|
+
* given.
|
|
382
|
+
*/
|
|
383
|
+
readonly codeHash: string | null;
|
|
384
|
+
/**
|
|
385
|
+
* How many codes were tried against it: `0` at insertion, and one more on
|
|
386
|
+
* every {@link TokenStore.countAttempt}. What bounds guessing a six-digit
|
|
387
|
+
* code.
|
|
388
|
+
*/
|
|
389
|
+
readonly attempts: number;
|
|
341
390
|
readonly expiresAt: Date;
|
|
342
391
|
/** `null` until spent. Once set, never changes. */
|
|
343
392
|
readonly spentAt: Date | null;
|
|
@@ -370,6 +419,25 @@ export interface TokenStore {
|
|
|
370
419
|
* job, after the call, so a lapsed token can never be retried.
|
|
371
420
|
*/
|
|
372
421
|
consumeToken(tokenHash: string, kind: TokenKind, at: Date): Promise<TokenRecord | null>;
|
|
422
|
+
/**
|
|
423
|
+
* Counts one attempt at a code against a token, and answers the token **as
|
|
424
|
+
* it is after this call**.
|
|
425
|
+
*
|
|
426
|
+
* - An **unspent** token of this `kind` has `attempts` one higher, and is
|
|
427
|
+
* answered with it. Twenty concurrent calls answer twenty distinct
|
|
428
|
+
* counts: one conditional write, never a read followed by a write — a
|
|
429
|
+
* count two guesses both read is a guess for free.
|
|
430
|
+
* - A **spent** token is answered as it is, and nothing is written.
|
|
431
|
+
* - `null` means no token of this `kind` has this hash.
|
|
432
|
+
*
|
|
433
|
+
* A **lapsed** token is counted all the same, or answered `null` by a store
|
|
434
|
+
* that already dropped it — as for `consumeToken`, comparing `expiresAt` is
|
|
435
|
+
* the core's job, after the call.
|
|
436
|
+
*
|
|
437
|
+
* Whether the count is past the limit, and whether the code matches, is the
|
|
438
|
+
* core's decision, after the call; spending the token is `consumeToken`.
|
|
439
|
+
*/
|
|
440
|
+
countAttempt(tokenHash: string, kind: TokenKind): Promise<TokenRecord | null>;
|
|
373
441
|
/**
|
|
374
442
|
* Deletes every token of one user, spent or not, and answers how many.
|
|
375
443
|
* What deleting a user calls: a token holds the e-mail it was sent to, which
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/auth/port/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyDG;AAEH,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAE/D;;;;;;;;GAQG;AACH,MAAM,MAAM,IAAI,GACb,MAAM,GACN,MAAM,GACN,OAAO,GACP,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OAAO,EAaZ,MAAM,WAAW,CAAC;AAInB,OAAO,KAAK,EAEX,WAAW,EACX,gBAAgB,EAChB,WAAW,EACX,cAAc,EACd,MAAM,SAAS,CAAC;AAEjB,KAAK,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAErC,mGAAmG;AACnG,MAAM,MAAM,UAAU,GAAG,WAAW,CAAC,OAAO,EAAE,KAAK,CAAC,GACnD,WAAW,CAAC,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,GACnC,cAAc,CAAC,OAAO,CAAC,GACvB,gBAAgB,CAAC,OAAO,CAAC,CAAC;AAE3B,wBAAgB,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,YAAY,GAAG,UAAU,
|
|
1
|
+
{"version":3,"file":"users.d.ts","sourceRoot":"","sources":["../../src/auth/users.ts"],"names":[],"mappings":"AASA,OAAO,EAAkB,KAAK,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7D,OAAO,EACN,KAAK,OAAO,EACZ,KAAK,OAAO,EAaZ,MAAM,WAAW,CAAC;AAInB,OAAO,KAAK,EAEX,WAAW,EACX,gBAAgB,EAChB,WAAW,EACX,cAAc,EACd,MAAM,SAAS,CAAC;AAEjB,KAAK,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAErC,mGAAmG;AACnG,MAAM,MAAM,UAAU,GAAG,WAAW,CAAC,OAAO,EAAE,KAAK,CAAC,GACnD,WAAW,CAAC,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,GACnC,cAAc,CAAC,OAAO,CAAC,GACvB,gBAAgB,CAAC,OAAO,CAAC,CAAC;AAE3B,wBAAgB,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,YAAY,GAAG,UAAU,CAibxE"}
|
|
@@ -155,6 +155,7 @@ function applyPatch(stored, patch) {
|
|
|
155
155
|
fields: patch.fields ?? stored.fields,
|
|
156
156
|
logins: patch.logins ?? stored.logins,
|
|
157
157
|
password: patch.password === undefined ? stored.password : patch.password,
|
|
158
|
+
secondFactor: patch.secondFactor === undefined ? stored.secondFactor : patch.secondFactor,
|
|
158
159
|
emailVerifiedAt: patch.emailVerifiedAt === undefined ? stored.emailVerifiedAt : patch.emailVerifiedAt,
|
|
159
160
|
version: stored.version + 1,
|
|
160
161
|
updatedAt: patch.updatedAt
|
|
@@ -250,6 +251,16 @@ function memoryTokenStore() {
|
|
|
250
251
|
}
|
|
251
252
|
return before;
|
|
252
253
|
},
|
|
254
|
+
async countAttempt(tokenHash, kind) {
|
|
255
|
+
const stored = byTokenHash.get(tokenHash);
|
|
256
|
+
if (stored === undefined || stored.kind !== kind)
|
|
257
|
+
return null;
|
|
258
|
+
if (stored.spentAt !== null)
|
|
259
|
+
return copy(stored);
|
|
260
|
+
const counted = { ...stored, attempts: stored.attempts + 1 };
|
|
261
|
+
byTokenHash.set(tokenHash, counted);
|
|
262
|
+
return copy(counted);
|
|
263
|
+
},
|
|
253
264
|
async deleteUserTokens(userId) {
|
|
254
265
|
let deleted = 0;
|
|
255
266
|
for (const [tokenHash, stored] of byTokenHash) {
|
|
@@ -265,5 +276,5 @@ function memoryTokenStore() {
|
|
|
265
276
|
|
|
266
277
|
export { mintId2, isId2, mintedAt2, createMemoryStores2 };
|
|
267
278
|
|
|
268
|
-
//# debugId=
|
|
269
|
-
//# sourceMappingURL=index-
|
|
279
|
+
//# debugId=A6E6F8D3147D2C5864756E2164756E21
|
|
280
|
+
//# sourceMappingURL=index-thtyq7a9.js.map
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
"sources": ["../src/ids/id.ts", "../src/auth/port/memory.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"/**\n * An id — of a user, a session: a UUIDv7, lowercase, hyphenated.\n *\n * **The core mints it, not the store**, and that decision pays for itself three\n * times over:\n *\n * - A UUIDv7 leads with a 48-bit millisecond timestamp, so ids sort in\n * creation order as strings. The pagination cursor is therefore *the last\n * id* — one index on the id, and the ordering is already total. A\n * store-minted id would need a `createdAt` index plus the id as a tiebreak,\n * because a timestamp alone is not a total order, and an opaque cursor per\n * adapter.\n * - `insertUser` becomes **idempotent under retry**: the id is decided\n * before the call, so a retry after a timeout writes the same row rather\n * than a second user.\n * - Every adapter reports the same shape, so moving an application from one\n * adapter to another is a copy rather than a rewrite of every stored\n * reference.\n *\n * The price, stated plainly: an adapter cannot reuse an existing numeric primary\n * key. It gets a `uuid` column, or a 36-character string, and the monotonic\n * prefix gives it the index locality a UUIDv4 destroys.\n */\nexport type Id = string;\n\nconst HEX: readonly string[] = Array.from({ length: 256 }, (_, i) =>\n\ti.toString(16).padStart(2, '0'),\n);\n\nlet lastMs = -1;\nlet sequence = 0;\n\n/**\n * The 12-bit sequence UUIDv7 keeps for ordering inside one millisecond.\n *\n * RFC 9562 calls this the \"replace leftmost random bits with an increased clock\n * precision\" method. Without it, two ids minted in the same millisecond order\n * by their random tail — still a total order, which is all the port requires,\n * but not creation order, and \"newest first\" would then be wrong for anything\n * created in a burst. A signup storm is exactly such a burst.\n */\nconst SEQUENCE_MAX = 0xfff;\n\n/**\n * A fresh id.\n *\n * Strictly increasing: within one millisecond it uses the sequence, and if that\n * overflows — more than 4096 ids in a millisecond, which no real\n * application reaches — it borrows the next millisecond rather than repeating\n * one. Across processes the 62 random bits of the tail are what keep two machines\n * apart.\n */\nexport function mintId(now: number = Date.now()): Id {\n\tlet ms = now;\n\n\tif (ms === lastMs) {\n\t\tsequence += 1;\n\t\tif (sequence > SEQUENCE_MAX) {\n\t\t\t// Borrow from the next millisecond. This keeps ids strictly\n\t\t\t// increasing at the cost of a timestamp a hair ahead of the clock,\n\t\t\t// which is the right trade: a repeated id would break the cursor.\n\t\t\tms = lastMs + 1;\n\t\t\tsequence = 0;\n\t\t}\n\t} else if (ms > lastMs) {\n\t\tsequence = 0;\n\t} else {\n\t\t// The clock went backwards — an NTP step, or a container resumed. Hold\n\t\t// the last millisecond and keep counting, so ids stay ordered even\n\t\t// though they stop matching the wall clock for a moment.\n\t\tms = lastMs;\n\t\tsequence += 1;\n\t\tif (sequence > SEQUENCE_MAX) {\n\t\t\tms = lastMs + 1;\n\t\t\tsequence = 0;\n\t\t}\n\t}\n\n\tlastMs = ms;\n\n\tconst bytes = new Uint8Array(16);\n\tcrypto.getRandomValues(bytes.subarray(8));\n\n\tbytes[0] = (ms / 2 ** 40) & 0xff;\n\tbytes[1] = (ms / 2 ** 32) & 0xff;\n\tbytes[2] = (ms / 2 ** 24) & 0xff;\n\tbytes[3] = (ms / 2 ** 16) & 0xff;\n\tbytes[4] = (ms / 2 ** 8) & 0xff;\n\tbytes[5] = ms & 0xff;\n\t// Version 7 in the high nibble, the sequence's top 4 bits below it.\n\tbytes[6] = 0x70 | ((sequence >> 8) & 0x0f);\n\tbytes[7] = sequence & 0xff;\n\t// Variant 10 in the two high bits of byte 8; the rest of it stays random.\n\tbytes[8] = 0x80 | ((bytes[8] as number) & 0x3f);\n\n\treturn `${HEX[bytes[0] as number]}${HEX[bytes[1] as number]}${HEX[bytes[2] as number]}${HEX[bytes[3] as number]}-${HEX[bytes[4] as number]}${HEX[bytes[5] as number]}-${HEX[bytes[6] as number]}${HEX[bytes[7] as number]}-${HEX[bytes[8] as number]}${HEX[bytes[9] as number]}-${HEX[bytes[10] as number]}${HEX[bytes[11] as number]}${HEX[bytes[12] as number]}${HEX[bytes[13] as number]}${HEX[bytes[14] as number]}${HEX[bytes[15] as number]}`;\n}\n\nconst UUID_V7 =\n\t/^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;\n\n/**\n * Whether this string is an id this package could have minted.\n *\n * Used by an adapter to answer `null` for a malformed id **without reaching the\n * store**: an id arrives off a URL, and one of the wrong shape is \"no such\n * user\", not an outage and not a query. Rejecting it here also keeps a\n * hand-written id out of a store that would then hold something the cursor\n * cannot order.\n */\nexport function isId(value: string): boolean {\n\treturn UUID_V7.test(value);\n}\n\n/**\n * When this id was minted, from the id itself.\n *\n * Offered because the timestamp is *in* the id, so a `createdAt` column is a\n * convenience rather than the truth — and an adapter that loses one can still\n * answer. It is not a substitute for `createdAt`: the sequence may have borrowed\n * a millisecond, and a clock that stepped backwards is held rather than\n * followed, so this is accurate to the millisecond and no further.\n */\nexport function mintedAt(id: Id): Date {\n\tconst hex = id.replace(/-/g, '').slice(0, 12);\n\treturn new Date(Number.parseInt(hex, 16));\n}\n",
|
|
6
|
-
"import { NotFoundError, StoreConflict } from '../../errors/janus-error';\nimport type { Id } from '../../ids/id';\nimport type {\n\tJanusStores,\n\tSessionId,\n\tSessionRecord,\n\tSessionStore,\n\tTokenRecord,\n\tTokenStore,\n\tUserPatch,\n\tUserRecord,\n\tUserStore,\n} from './types';\n\n/**\n * The reference implementation of the store port, in memory.\n *\n * **Shipped and documented, not a test helper.** It is what a consumer uses in\n * their own unit tests, and what an adapter author compares against when a\n * conformance case they do not understand turns red. So it keeps the six rules\n * for real rather than approximately:\n *\n * - uniqueness is a constraint — an index checked and written inside the same\n * synchronous step, which is what atomic means on one event loop;\n * - `consumeToken` reads and writes with no `await` between the two, so twenty\n * concurrent calls see exactly one unspent token;\n * - every record is **copied in and copied out**, so a caller that mutates what\n * it passed or what it got back cannot reach the store — the in-memory\n * version of \"bytes round-trip\";\n * - a patch applies only the fields it names, and only the fields the port\n * declares: a stray `version` or `id` in a patch from JavaScript is ignored,\n * not written.\n *\n * Every method is `async` even though none waits on anything: a caller that\n * forgot an `await` must fail here the way it would against a real database.\n */\nexport function createMemoryStores(): JanusStores {\n\treturn {\n\t\tusers: memoryUserStore(),\n\t\tsessions: memorySessionStore(),\n\t\ttokens: memoryTokenStore(),\n\t};\n}\n\nconst copy = <T>(value: T): T => structuredClone(value);\n\n/** The unique key of one login. `\\u0000` cannot occur in a type name the core accepts. */\nconst keyOf = (type: string, login: string): string => `${type}\\u0000${login}`;\n\nfunction memoryUserStore(): UserStore {\n\tconst byId = new Map<Id, UserRecord>();\n\t// The unique index: (type, login) key → the id holding it.\n\tconst byLogin = new Map<string, Id>();\n\n\t/** The first of `logins` held by a user of `type` other than `id`. */\n\tconst takenBy = (\n\t\ttype: string,\n\t\tlogins: readonly string[],\n\t\tid: Id,\n\t): string | undefined =>\n\t\tlogins.find((login) => {\n\t\t\tconst holder = byLogin.get(keyOf(type, login));\n\t\t\treturn holder !== undefined && holder !== id;\n\t\t});\n\n\tconst taken = (operation: string, type: string, login: string) =>\n\t\tnew StoreConflict(\n\t\t\t'login',\n\t\t\t`${operation}: the login is taken by another ${type}`,\n\t\t\t{ login, userType: type, operation },\n\t\t);\n\n\treturn {\n\t\tasync insertUser(record) {\n\t\t\tconst stored = byId.get(record.id);\n\t\t\tif (stored !== undefined) return copy(stored);\n\n\t\t\tconst collision = takenBy(record.type, record.logins, record.id);\n\t\t\tif (collision !== undefined) {\n\t\t\t\tthrow taken('insertUser', record.type, collision);\n\t\t\t}\n\n\t\t\tconst written = copy(record);\n\t\t\tbyId.set(written.id, written);\n\t\t\tfor (const login of written.logins) {\n\t\t\t\tbyLogin.set(keyOf(written.type, login), written.id);\n\t\t\t}\n\n\t\t\treturn copy(written);\n\t\t},\n\n\t\tasync findUser(id) {\n\t\t\tconst stored = byId.get(id);\n\t\t\treturn stored === undefined ? null : copy(stored);\n\t\t},\n\n\t\tasync findUserByLogin(type, login) {\n\t\t\tconst id = byLogin.get(keyOf(type, login));\n\t\t\tconst stored = id === undefined ? undefined : byId.get(id);\n\t\t\treturn stored === undefined ? null : copy(stored);\n\t\t},\n\n\t\tasync listUsers({ type, after, limit }) {\n\t\t\t// A Map keeps insertion order, not id order: a retried insert or an\n\t\t\t// id minted on another machine can land out of sequence.\n\t\t\tconst ids = [...byId.values()]\n\t\t\t\t.filter((user) => user.type === type)\n\t\t\t\t.map((user) => user.id)\n\t\t\t\t.filter((id) => after === null || id > after)\n\t\t\t\t.sort();\n\t\t\tconst pageIds = ids.slice(0, limit);\n\t\t\tconst last = pageIds.at(-1);\n\n\t\t\treturn {\n\t\t\t\titems: pageIds.map((id) => copy(byId.get(id) as UserRecord)),\n\t\t\t\tnextCursor: ids.length > limit && last !== undefined ? last : null,\n\t\t\t};\n\t\t},\n\n\t\tasync updateUser(id, patch, ifVersion) {\n\t\t\tconst stored = byId.get(id);\n\n\t\t\tif (stored === undefined) {\n\t\t\t\tthrow new NotFoundError('updateUser: no user has this id', {\n\t\t\t\t\tuserId: id,\n\t\t\t\t\toperation: 'updateUser',\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (stored.version !== ifVersion) {\n\t\t\t\tthrow new StoreConflict(\n\t\t\t\t\t'version',\n\t\t\t\t\t`updateUser: expected version ${ifVersion}, found ${stored.version}`,\n\t\t\t\t\t{\n\t\t\t\t\t\tuserId: id,\n\t\t\t\t\t\texpectedVersion: ifVersion,\n\t\t\t\t\t\tactualVersion: stored.version,\n\t\t\t\t\t\toperation: 'updateUser',\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (patch.logins !== undefined) {\n\t\t\t\tconst collision = takenBy(stored.type, patch.logins, id);\n\t\t\t\tif (collision !== undefined) {\n\t\t\t\t\tthrow taken('updateUser', stored.type, collision);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst written = applyPatch(stored, copy(patch));\n\n\t\t\tbyId.set(id, written);\n\t\t\tif (patch.logins !== undefined) {\n\t\t\t\tfor (const login of stored.logins) {\n\t\t\t\t\tbyLogin.delete(keyOf(stored.type, login));\n\t\t\t\t}\n\t\t\t\tfor (const login of written.logins) {\n\t\t\t\t\tbyLogin.set(keyOf(written.type, login), id);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn copy(written);\n\t\t},\n\n\t\tasync deleteUser(id) {\n\t\t\tconst stored = byId.get(id);\n\t\t\tif (stored === undefined) return false;\n\n\t\t\tbyId.delete(id);\n\t\t\tfor (const login of stored.logins) {\n\t\t\t\tbyLogin.delete(keyOf(stored.type, login));\n\t\t\t}\n\t\t\treturn true;\n\t\t},\n\t};\n}\n\n/**\n * The record a patch produces: the fields it names, replaced whole; the fields\n * it does not name, untouched.\n *\n * Reads each field by name rather than spreading the patch, so a key the port\n * does not declare — `version`, `id`, `type`, `createdAt`, or a `snake_case`\n * typo from JavaScript — never reaches the record. A key present as\n * `undefined` is absent, never an erasure.\n */\nfunction applyPatch(stored: UserRecord, patch: UserPatch): UserRecord {\n\treturn {\n\t\t...stored,\n\t\tschemaVersion: patch.schemaVersion ?? stored.schemaVersion,\n\t\tactive: patch.active ?? stored.active,\n\t\tfields: patch.fields ?? stored.fields,\n\t\tlogins: patch.logins ?? stored.logins,\n\t\tpassword: patch.password === undefined ? stored.password : patch.password,\n\t\temailVerifiedAt:\n\t\t\tpatch.emailVerifiedAt === undefined\n\t\t\t\t? stored.emailVerifiedAt\n\t\t\t\t: patch.emailVerifiedAt,\n\t\tversion: stored.version + 1,\n\t\tupdatedAt: patch.updatedAt,\n\t};\n}\n\nfunction memorySessionStore(): SessionStore {\n\tconst byId = new Map<SessionId, SessionRecord>();\n\tconst byTokenHash = new Map<string, SessionId>();\n\n\tconst revoke = (id: SessionId, stored: SessionRecord, at: Date): void => {\n\t\tbyId.set(id, { ...stored, revokedAt: new Date(at) });\n\t};\n\n\treturn {\n\t\tasync insertSession(record) {\n\t\t\tif (byId.has(record.id)) return;\n\n\t\t\tconst written = copy(record);\n\t\t\tbyId.set(written.id, written);\n\t\t\tbyTokenHash.set(written.tokenHash, written.id);\n\t\t},\n\n\t\tasync findSessionByTokenHash(tokenHash) {\n\t\t\tconst id = byTokenHash.get(tokenHash);\n\t\t\tconst stored = id === undefined ? undefined : byId.get(id);\n\t\t\treturn stored === undefined ? null : copy(stored);\n\t\t},\n\n\t\tasync extendSession(id, expiresAt) {\n\t\t\tconst stored = byId.get(id);\n\t\t\tif (stored === undefined || stored.revokedAt !== null) return null;\n\n\t\t\tconst written: SessionRecord = {\n\t\t\t\t...stored,\n\t\t\t\texpiresAt: new Date(expiresAt),\n\t\t\t};\n\t\t\tbyId.set(id, written);\n\t\t\treturn copy(written);\n\t\t},\n\n\t\tasync revokeSession(id, at) {\n\t\t\tconst stored = byId.get(id);\n\t\t\tif (stored === undefined) return false;\n\n\t\t\tif (stored.revokedAt === null) revoke(id, stored, at);\n\t\t\treturn true;\n\t\t},\n\n\t\tasync revokeUserSessions(userId, at, except) {\n\t\t\tlet revoked = 0;\n\n\t\t\tfor (const [id, stored] of byId) {\n\t\t\t\tif (\n\t\t\t\t\tstored.userId === userId &&\n\t\t\t\t\tstored.revokedAt === null &&\n\t\t\t\t\tid !== except\n\t\t\t\t) {\n\t\t\t\t\trevoke(id, stored, at);\n\t\t\t\t\trevoked += 1;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn revoked;\n\t\t},\n\n\t\tasync deleteUserSessions(userId) {\n\t\t\tlet deleted = 0;\n\n\t\t\tfor (const [id, stored] of byId) {\n\t\t\t\tif (stored.userId === userId) {\n\t\t\t\t\tbyId.delete(id);\n\t\t\t\t\tbyTokenHash.delete(stored.tokenHash);\n\t\t\t\t\tdeleted += 1;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn deleted;\n\t\t},\n\n\t\tasync deleteExpiredSessions(before) {\n\t\t\tlet deleted = 0;\n\n\t\t\tfor (const [id, stored] of byId) {\n\t\t\t\tif (stored.expiresAt.getTime() <= before.getTime()) {\n\t\t\t\t\tbyId.delete(id);\n\t\t\t\t\tbyTokenHash.delete(stored.tokenHash);\n\t\t\t\t\tdeleted += 1;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn deleted;\n\t\t},\n\t};\n}\n\nfunction memoryTokenStore(): TokenStore {\n\tconst byTokenHash = new Map<string, TokenRecord>();\n\n\treturn {\n\t\tasync insertToken(record) {\n\t\t\tif (byTokenHash.has(record.tokenHash)) return;\n\t\t\tbyTokenHash.set(record.tokenHash, copy(record));\n\t\t},\n\n\t\tasync consumeToken(tokenHash, kind, at) {\n\t\t\t// No `await` between this read and the write below: on one event loop\n\t\t\t// that is what makes the pair a single conditional write.\n\t\t\tconst stored = byTokenHash.get(tokenHash);\n\t\t\tif (stored === undefined || stored.kind !== kind) return null;\n\n\t\t\tconst before = copy(stored);\n\t\t\tif (stored.spentAt === null) {\n\t\t\t\tbyTokenHash.set(tokenHash, { ...stored, spentAt: new Date(at) });\n\t\t\t}\n\n\t\t\treturn before;\n\t\t},\n\n\t\tasync deleteUserTokens(userId) {\n\t\t\tlet deleted = 0;\n\n\t\t\tfor (const [tokenHash, stored] of byTokenHash) {\n\t\t\t\tif (stored.userId === userId) {\n\t\t\t\t\tbyTokenHash.delete(tokenHash);\n\t\t\t\t\tdeleted += 1;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn deleted;\n\t\t},\n\t};\n}\n"
|
|
6
|
+
"import { NotFoundError, StoreConflict } from '../../errors/janus-error';\nimport type { Id } from '../../ids/id';\nimport type {\n\tJanusStores,\n\tSessionId,\n\tSessionRecord,\n\tSessionStore,\n\tTokenRecord,\n\tTokenStore,\n\tUserPatch,\n\tUserRecord,\n\tUserStore,\n} from './types';\n\n/**\n * The reference implementation of the store port, in memory.\n *\n * **Shipped and documented, not a test helper.** It is what a consumer uses in\n * their own unit tests, and what an adapter author compares against when a\n * conformance case they do not understand turns red. So it keeps the six rules\n * for real rather than approximately:\n *\n * - uniqueness is a constraint — an index checked and written inside the same\n * synchronous step, which is what atomic means on one event loop;\n * - `consumeToken` reads and writes with no `await` between the two, so twenty\n * concurrent calls see exactly one unspent token;\n * - every record is **copied in and copied out**, so a caller that mutates what\n * it passed or what it got back cannot reach the store — the in-memory\n * version of \"bytes round-trip\";\n * - a patch applies only the fields it names, and only the fields the port\n * declares: a stray `version` or `id` in a patch from JavaScript is ignored,\n * not written.\n *\n * Every method is `async` even though none waits on anything: a caller that\n * forgot an `await` must fail here the way it would against a real database.\n */\nexport function createMemoryStores(): JanusStores {\n\treturn {\n\t\tusers: memoryUserStore(),\n\t\tsessions: memorySessionStore(),\n\t\ttokens: memoryTokenStore(),\n\t};\n}\n\nconst copy = <T>(value: T): T => structuredClone(value);\n\n/** The unique key of one login. `\\u0000` cannot occur in a type name the core accepts. */\nconst keyOf = (type: string, login: string): string => `${type}\\u0000${login}`;\n\nfunction memoryUserStore(): UserStore {\n\tconst byId = new Map<Id, UserRecord>();\n\t// The unique index: (type, login) key → the id holding it.\n\tconst byLogin = new Map<string, Id>();\n\n\t/** The first of `logins` held by a user of `type` other than `id`. */\n\tconst takenBy = (\n\t\ttype: string,\n\t\tlogins: readonly string[],\n\t\tid: Id,\n\t): string | undefined =>\n\t\tlogins.find((login) => {\n\t\t\tconst holder = byLogin.get(keyOf(type, login));\n\t\t\treturn holder !== undefined && holder !== id;\n\t\t});\n\n\tconst taken = (operation: string, type: string, login: string) =>\n\t\tnew StoreConflict(\n\t\t\t'login',\n\t\t\t`${operation}: the login is taken by another ${type}`,\n\t\t\t{ login, userType: type, operation },\n\t\t);\n\n\treturn {\n\t\tasync insertUser(record) {\n\t\t\tconst stored = byId.get(record.id);\n\t\t\tif (stored !== undefined) return copy(stored);\n\n\t\t\tconst collision = takenBy(record.type, record.logins, record.id);\n\t\t\tif (collision !== undefined) {\n\t\t\t\tthrow taken('insertUser', record.type, collision);\n\t\t\t}\n\n\t\t\tconst written = copy(record);\n\t\t\tbyId.set(written.id, written);\n\t\t\tfor (const login of written.logins) {\n\t\t\t\tbyLogin.set(keyOf(written.type, login), written.id);\n\t\t\t}\n\n\t\t\treturn copy(written);\n\t\t},\n\n\t\tasync findUser(id) {\n\t\t\tconst stored = byId.get(id);\n\t\t\treturn stored === undefined ? null : copy(stored);\n\t\t},\n\n\t\tasync findUserByLogin(type, login) {\n\t\t\tconst id = byLogin.get(keyOf(type, login));\n\t\t\tconst stored = id === undefined ? undefined : byId.get(id);\n\t\t\treturn stored === undefined ? null : copy(stored);\n\t\t},\n\n\t\tasync listUsers({ type, after, limit }) {\n\t\t\t// A Map keeps insertion order, not id order: a retried insert or an\n\t\t\t// id minted on another machine can land out of sequence.\n\t\t\tconst ids = [...byId.values()]\n\t\t\t\t.filter((user) => user.type === type)\n\t\t\t\t.map((user) => user.id)\n\t\t\t\t.filter((id) => after === null || id > after)\n\t\t\t\t.sort();\n\t\t\tconst pageIds = ids.slice(0, limit);\n\t\t\tconst last = pageIds.at(-1);\n\n\t\t\treturn {\n\t\t\t\titems: pageIds.map((id) => copy(byId.get(id) as UserRecord)),\n\t\t\t\tnextCursor: ids.length > limit && last !== undefined ? last : null,\n\t\t\t};\n\t\t},\n\n\t\tasync updateUser(id, patch, ifVersion) {\n\t\t\tconst stored = byId.get(id);\n\n\t\t\tif (stored === undefined) {\n\t\t\t\tthrow new NotFoundError('updateUser: no user has this id', {\n\t\t\t\t\tuserId: id,\n\t\t\t\t\toperation: 'updateUser',\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (stored.version !== ifVersion) {\n\t\t\t\tthrow new StoreConflict(\n\t\t\t\t\t'version',\n\t\t\t\t\t`updateUser: expected version ${ifVersion}, found ${stored.version}`,\n\t\t\t\t\t{\n\t\t\t\t\t\tuserId: id,\n\t\t\t\t\t\texpectedVersion: ifVersion,\n\t\t\t\t\t\tactualVersion: stored.version,\n\t\t\t\t\t\toperation: 'updateUser',\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (patch.logins !== undefined) {\n\t\t\t\tconst collision = takenBy(stored.type, patch.logins, id);\n\t\t\t\tif (collision !== undefined) {\n\t\t\t\t\tthrow taken('updateUser', stored.type, collision);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst written = applyPatch(stored, copy(patch));\n\n\t\t\tbyId.set(id, written);\n\t\t\tif (patch.logins !== undefined) {\n\t\t\t\tfor (const login of stored.logins) {\n\t\t\t\t\tbyLogin.delete(keyOf(stored.type, login));\n\t\t\t\t}\n\t\t\t\tfor (const login of written.logins) {\n\t\t\t\t\tbyLogin.set(keyOf(written.type, login), id);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn copy(written);\n\t\t},\n\n\t\tasync deleteUser(id) {\n\t\t\tconst stored = byId.get(id);\n\t\t\tif (stored === undefined) return false;\n\n\t\t\tbyId.delete(id);\n\t\t\tfor (const login of stored.logins) {\n\t\t\t\tbyLogin.delete(keyOf(stored.type, login));\n\t\t\t}\n\t\t\treturn true;\n\t\t},\n\t};\n}\n\n/**\n * The record a patch produces: the fields it names, replaced whole; the fields\n * it does not name, untouched.\n *\n * Reads each field by name rather than spreading the patch, so a key the port\n * does not declare — `version`, `id`, `type`, `createdAt`, or a `snake_case`\n * typo from JavaScript — never reaches the record. A key present as\n * `undefined` is absent, never an erasure.\n */\nfunction applyPatch(stored: UserRecord, patch: UserPatch): UserRecord {\n\treturn {\n\t\t...stored,\n\t\tschemaVersion: patch.schemaVersion ?? stored.schemaVersion,\n\t\tactive: patch.active ?? stored.active,\n\t\tfields: patch.fields ?? stored.fields,\n\t\tlogins: patch.logins ?? stored.logins,\n\t\tpassword: patch.password === undefined ? stored.password : patch.password,\n\t\tsecondFactor:\n\t\t\tpatch.secondFactor === undefined\n\t\t\t\t? stored.secondFactor\n\t\t\t\t: patch.secondFactor,\n\t\temailVerifiedAt:\n\t\t\tpatch.emailVerifiedAt === undefined\n\t\t\t\t? stored.emailVerifiedAt\n\t\t\t\t: patch.emailVerifiedAt,\n\t\tversion: stored.version + 1,\n\t\tupdatedAt: patch.updatedAt,\n\t};\n}\n\nfunction memorySessionStore(): SessionStore {\n\tconst byId = new Map<SessionId, SessionRecord>();\n\tconst byTokenHash = new Map<string, SessionId>();\n\n\tconst revoke = (id: SessionId, stored: SessionRecord, at: Date): void => {\n\t\tbyId.set(id, { ...stored, revokedAt: new Date(at) });\n\t};\n\n\treturn {\n\t\tasync insertSession(record) {\n\t\t\tif (byId.has(record.id)) return;\n\n\t\t\tconst written = copy(record);\n\t\t\tbyId.set(written.id, written);\n\t\t\tbyTokenHash.set(written.tokenHash, written.id);\n\t\t},\n\n\t\tasync findSessionByTokenHash(tokenHash) {\n\t\t\tconst id = byTokenHash.get(tokenHash);\n\t\t\tconst stored = id === undefined ? undefined : byId.get(id);\n\t\t\treturn stored === undefined ? null : copy(stored);\n\t\t},\n\n\t\tasync extendSession(id, expiresAt) {\n\t\t\tconst stored = byId.get(id);\n\t\t\tif (stored === undefined || stored.revokedAt !== null) return null;\n\n\t\t\tconst written: SessionRecord = {\n\t\t\t\t...stored,\n\t\t\t\texpiresAt: new Date(expiresAt),\n\t\t\t};\n\t\t\tbyId.set(id, written);\n\t\t\treturn copy(written);\n\t\t},\n\n\t\tasync revokeSession(id, at) {\n\t\t\tconst stored = byId.get(id);\n\t\t\tif (stored === undefined) return false;\n\n\t\t\tif (stored.revokedAt === null) revoke(id, stored, at);\n\t\t\treturn true;\n\t\t},\n\n\t\tasync revokeUserSessions(userId, at, except) {\n\t\t\tlet revoked = 0;\n\n\t\t\tfor (const [id, stored] of byId) {\n\t\t\t\tif (\n\t\t\t\t\tstored.userId === userId &&\n\t\t\t\t\tstored.revokedAt === null &&\n\t\t\t\t\tid !== except\n\t\t\t\t) {\n\t\t\t\t\trevoke(id, stored, at);\n\t\t\t\t\trevoked += 1;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn revoked;\n\t\t},\n\n\t\tasync deleteUserSessions(userId) {\n\t\t\tlet deleted = 0;\n\n\t\t\tfor (const [id, stored] of byId) {\n\t\t\t\tif (stored.userId === userId) {\n\t\t\t\t\tbyId.delete(id);\n\t\t\t\t\tbyTokenHash.delete(stored.tokenHash);\n\t\t\t\t\tdeleted += 1;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn deleted;\n\t\t},\n\n\t\tasync deleteExpiredSessions(before) {\n\t\t\tlet deleted = 0;\n\n\t\t\tfor (const [id, stored] of byId) {\n\t\t\t\tif (stored.expiresAt.getTime() <= before.getTime()) {\n\t\t\t\t\tbyId.delete(id);\n\t\t\t\t\tbyTokenHash.delete(stored.tokenHash);\n\t\t\t\t\tdeleted += 1;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn deleted;\n\t\t},\n\t};\n}\n\nfunction memoryTokenStore(): TokenStore {\n\tconst byTokenHash = new Map<string, TokenRecord>();\n\n\treturn {\n\t\tasync insertToken(record) {\n\t\t\tif (byTokenHash.has(record.tokenHash)) return;\n\t\t\tbyTokenHash.set(record.tokenHash, copy(record));\n\t\t},\n\n\t\tasync consumeToken(tokenHash, kind, at) {\n\t\t\t// No `await` between this read and the write below: on one event loop\n\t\t\t// that is what makes the pair a single conditional write.\n\t\t\tconst stored = byTokenHash.get(tokenHash);\n\t\t\tif (stored === undefined || stored.kind !== kind) return null;\n\n\t\t\tconst before = copy(stored);\n\t\t\tif (stored.spentAt === null) {\n\t\t\t\tbyTokenHash.set(tokenHash, { ...stored, spentAt: new Date(at) });\n\t\t\t}\n\n\t\t\treturn before;\n\t\t},\n\n\t\tasync countAttempt(tokenHash, kind) {\n\t\t\t// The same single conditional write as consumeToken: no `await`\n\t\t\t// between the read and the write.\n\t\t\tconst stored = byTokenHash.get(tokenHash);\n\t\t\tif (stored === undefined || stored.kind !== kind) return null;\n\t\t\tif (stored.spentAt !== null) return copy(stored);\n\n\t\t\tconst counted = { ...stored, attempts: stored.attempts + 1 };\n\t\t\tbyTokenHash.set(tokenHash, counted);\n\t\t\treturn copy(counted);\n\t\t},\n\n\t\tasync deleteUserTokens(userId) {\n\t\t\tlet deleted = 0;\n\n\t\t\tfor (const [tokenHash, stored] of byTokenHash) {\n\t\t\t\tif (stored.userId === userId) {\n\t\t\t\t\tbyTokenHash.delete(tokenHash);\n\t\t\t\t\tdeleted += 1;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn deleted;\n\t\t},\n\t};\n}\n"
|
|
7
7
|
],
|
|
8
|
-
"mappings": ";;;;;;AAyBA,IAAM,MAAyB,MAAM,KAAK,EAAE,QAAQ,IAAI,GAAG,CAAC,GAAG,MAC9D,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,CAC/B;AAEA,IAAI,SAAS;AACb,IAAI,WAAW;AA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AAO,YAAY,MAAM;AAAA,QAC5B,YAAY,IAAI,WAAW,KAAK,QAAQ,SAAS,IAAI,KAAK,EAAE,EAAE,CAAC;AAAA,MAChE;AAAA,MAEA,OAAO;AAAA;AAAA,SAGF,aAAY,CAAC,WAAW,MAAM;AAAA,MAGnC,MAAM,SAAS,YAAY,IAAI,SAAS;AAAA,MACxC,IAAI,WAAW,aAAa,OAAO,SAAS;AAAA,QAAM,OAAO;AAAA,MACzD,IAAI,OAAO,YAAY;AAAA,QAAM,OAAO,KAAK,MAAM;AAAA,MAE/C,MAAM,UAAU,KAAK,QAAQ,UAAU,OAAO,WAAW,EAAE;AAAA,MAC3D,YAAY,IAAI,WAAW,OAAO;AAAA,MAClC,OAAO,KAAK,OAAO;AAAA;AAAA,SAGd,iBAAgB,CAAC,QAAQ;AAAA,MAC9B,IAAI,UAAU;AAAA,MAEd,YAAY,WAAW,WAAW,aAAa;AAAA,QAC9C,IAAI,OAAO,WAAW,QAAQ;AAAA,UAC7B,YAAY,OAAO,SAAS;AAAA,UAC5B,WAAW;AAAA,QACZ;AAAA,MACD;AAAA,MAEA,OAAO;AAAA;AAAA,EAET;AAAA;",
|
|
9
|
+
"debugId": "A6E6F8D3147D2C5864756E2164756E21",
|
|
10
10
|
"names": []
|
|
11
11
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"outage.d.ts","sourceRoot":"","sources":["../../../src/conformance/cases/outage.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAe,eAAe,EAAc,MAAM,UAAU,CAAC;AA4DzE,eAAO,MAAM,WAAW,EAAE,SAAS,eAAe,
|
|
1
|
+
{"version":3,"file":"outage.d.ts","sourceRoot":"","sources":["../../../src/conformance/cases/outage.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAe,eAAe,EAAc,MAAM,UAAU,CAAC;AA4DzE,eAAO,MAAM,WAAW,EAAE,SAAS,eAAe,EA8EjD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../../../src/conformance/cases/tokens.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAIhD,eAAO,MAAM,eAAe,EAAE,SAAS,eAAe,
|
|
1
|
+
{"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../../../src/conformance/cases/tokens.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAIhD,eAAO,MAAM,eAAe,EAAE,SAAS,eAAe,EA4UrD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"users.d.ts","sourceRoot":"","sources":["../../../src/conformance/cases/users.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"users.d.ts","sourceRoot":"","sources":["../../../src/conformance/cases/users.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAYhD,eAAO,MAAM,cAAc,EAAE,SAAS,eAAe,EA8hBpD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fixtures.d.ts","sourceRoot":"","sources":["../../src/conformance/fixtures.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,aAAa,EACb,WAAW,EACX,UAAU,EACV,MAAM,oBAAoB,CAAC;AAG5B;;;;GAIG;AAEH,eAAO,MAAM,EAAE,GAAI,KAAK,MAAM,KAAG,IAAqB,CAAC;AAKvD,wBAAgB,UAAU,CAAC,SAAS,GAAE,OAAO,CAAC,UAAU,CAAM,GAAG,UAAU,
|
|
1
|
+
{"version":3,"file":"fixtures.d.ts","sourceRoot":"","sources":["../../src/conformance/fixtures.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,aAAa,EACb,WAAW,EACX,UAAU,EACV,MAAM,oBAAoB,CAAC;AAG5B;;;;GAIG;AAEH,eAAO,MAAM,EAAE,GAAI,KAAK,MAAM,KAAG,IAAqB,CAAC;AAKvD,wBAAgB,UAAU,CAAC,SAAS,GAAE,OAAO,CAAC,UAAU,CAAM,GAAG,UAAU,CAoB1E;AAED,wBAAgB,aAAa,CAC5B,SAAS,GAAE,OAAO,CAAC,aAAa,CAAM,GACpC,aAAa,CAWf;AAED,wBAAgB,WAAW,CAAC,SAAS,GAAE,OAAO,CAAC,WAAW,CAAM,GAAG,WAAW,CAa7E"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
mintId2,
|
|
3
3
|
createMemoryStores2
|
|
4
|
-
} from "../chunks/index-
|
|
4
|
+
} from "../chunks/index-thtyq7a9.js";
|
|
5
5
|
import {
|
|
6
6
|
JanusError2,
|
|
7
7
|
StoreFailure2,
|
|
@@ -113,6 +113,7 @@ function userRecord(overrides = {}) {
|
|
|
113
113
|
hash: "$scrypt$ln=17,r=8,p=1$c2FsdA==$a2V5",
|
|
114
114
|
updatedAt: at("2026-01-01T00:00:00.000Z")
|
|
115
115
|
},
|
|
116
|
+
secondFactor: null,
|
|
116
117
|
emailVerifiedAt: null,
|
|
117
118
|
version: 0,
|
|
118
119
|
createdAt: at("2026-01-01T00:00:00.000Z"),
|
|
@@ -138,6 +139,8 @@ function tokenRecord(overrides = {}) {
|
|
|
138
139
|
kind: "resetPassword",
|
|
139
140
|
userId: mintId2(),
|
|
140
141
|
address: fresh(),
|
|
142
|
+
codeHash: null,
|
|
143
|
+
attempts: 0,
|
|
141
144
|
expiresAt: at("2099-01-01T00:00:00.000Z"),
|
|
142
145
|
spentAt: null,
|
|
143
146
|
createdAt: at("2026-01-01T00:00:00.000Z"),
|
|
@@ -184,6 +187,7 @@ var outageCases = [
|
|
|
184
187
|
outage("sessions", "revokeSession", ({ stores }) => stores.sessions.revokeSession(session.id, now), seed),
|
|
185
188
|
outage("sessions", "revokeUserSessions", ({ stores }) => stores.sessions.revokeUserSessions(user.id, now), seed),
|
|
186
189
|
outage("tokens", "consumeToken", ({ stores }) => stores.tokens.consumeToken(token.tokenHash, "resetPassword", now), seed),
|
|
190
|
+
outage("tokens", "countAttempt", ({ stores }) => stores.tokens.countAttempt(token.tokenHash, "resetPassword"), seed),
|
|
187
191
|
outage("users", "deleteUser", ({ stores }) => stores.users.deleteUser(user.id), seed),
|
|
188
192
|
outage("sessions", "deleteUserSessions", ({ stores }) => stores.sessions.deleteUserSessions(user.id), seed),
|
|
189
193
|
outage("tokens", "deleteUserTokens", ({ stores }) => stores.tokens.deleteUserTokens(user.id), seed)
|
|
@@ -378,6 +382,76 @@ var tokenStoreCases = [
|
|
|
378
382
|
isNull(await stores.tokens.consumeToken("0".repeat(64), "resetPassword", at("2026-02-01T00:00:00.000Z")), "consumeToken for an unknown hash");
|
|
379
383
|
}
|
|
380
384
|
},
|
|
385
|
+
{
|
|
386
|
+
id: "tokens.countAttempt",
|
|
387
|
+
group: group2,
|
|
388
|
+
name: "counts an attempt at a code, and answers the token as it is after the call",
|
|
389
|
+
async run({ stores }) {
|
|
390
|
+
const record = tokenRecord({
|
|
391
|
+
kind: "signInCode",
|
|
392
|
+
codeHash: "c".repeat(64)
|
|
393
|
+
});
|
|
394
|
+
await stores.tokens.insertToken(record);
|
|
395
|
+
equal(await stores.tokens.countAttempt(record.tokenHash, "signInCode"), { ...record, attempts: 1 }, "countAttempt the first time should answer the token with attempts 1, codeHash as written");
|
|
396
|
+
equal(await stores.tokens.countAttempt(record.tokenHash, "signInCode"), { ...record, attempts: 2 }, "countAttempt the second time should answer attempts 2");
|
|
397
|
+
equal(await stores.tokens.consumeToken(record.tokenHash, "signInCode", at("2026-02-01T00:00:00.000Z")), { ...record, attempts: 2 }, "consumeToken should answer the attempts counted, and spend the token");
|
|
398
|
+
}
|
|
399
|
+
},
|
|
400
|
+
{
|
|
401
|
+
id: "tokens.countAttemptConcurrency",
|
|
402
|
+
group: group2,
|
|
403
|
+
name: "gives twenty concurrent attempts twenty distinct counts — one conditional write, never a read then a write",
|
|
404
|
+
async run({ stores }) {
|
|
405
|
+
const record = tokenRecord({ kind: "secondFactor" });
|
|
406
|
+
await stores.tokens.insertToken(record);
|
|
407
|
+
const answers = await Promise.all(Array.from({ length: 20 }, () => stores.tokens.countAttempt(record.tokenHash, "secondFactor")));
|
|
408
|
+
equal(answers.map((answer) => answer?.attempts).sort((a, b) => (a ?? 0) - (b ?? 0)), Array.from({ length: 20 }, (_, index) => index + 1), "countAttempt: twenty concurrent calls should answer 1 to 20, each once — two guesses reading one count is a guess for free");
|
|
409
|
+
}
|
|
410
|
+
},
|
|
411
|
+
{
|
|
412
|
+
id: "tokens.countAttemptRace",
|
|
413
|
+
group: group2,
|
|
414
|
+
name: "never counts an attempt once the token is spent, when attempts and a redemption race",
|
|
415
|
+
async run({ stores }) {
|
|
416
|
+
const record = tokenRecord({ kind: "signInCode" });
|
|
417
|
+
await stores.tokens.insertToken(record);
|
|
418
|
+
const now = at("2026-02-01T00:00:00.000Z");
|
|
419
|
+
const count = () => stores.tokens.countAttempt(record.tokenHash, "signInCode");
|
|
420
|
+
const answers = await Promise.all([
|
|
421
|
+
...Array.from({ length: 10 }, count),
|
|
422
|
+
stores.tokens.consumeToken(record.tokenHash, "signInCode", now),
|
|
423
|
+
...Array.from({ length: 10 }, count)
|
|
424
|
+
]);
|
|
425
|
+
const final = await stores.tokens.consumeToken(record.tokenHash, "signInCode", now);
|
|
426
|
+
if (final === null) {
|
|
427
|
+
throw new Error("consumeToken after the race should answer the token");
|
|
428
|
+
}
|
|
429
|
+
const counted = answers.slice(0, 10).concat(answers.slice(11)).filter((answer) => answer !== null && answer.spentAt === null).map((answer) => answer?.attempts ?? 0).sort((a, b) => a - b);
|
|
430
|
+
equal(counted, Array.from({ length: final.attempts }, (_, index) => index + 1), "countAttempt: the attempts answered unspent should be 1 to the final count, each once");
|
|
431
|
+
equal(answers.filter((answer) => answer !== null && answer.spentAt !== null).every((answer) => answer?.attempts === final.attempts), true, "countAttempt: every answer after the spend should carry the final count — an attempt counted on a spent token is one the limit never saw");
|
|
432
|
+
}
|
|
433
|
+
},
|
|
434
|
+
{
|
|
435
|
+
id: "tokens.countAttemptSpent",
|
|
436
|
+
group: group2,
|
|
437
|
+
name: "does not count an attempt at a spent token, nor at a token of another kind, nor at none",
|
|
438
|
+
async run({ stores }) {
|
|
439
|
+
const spent = tokenRecord({
|
|
440
|
+
kind: "signInCode",
|
|
441
|
+
attempts: 3,
|
|
442
|
+
spentAt: at("2026-01-02T00:00:00.000Z")
|
|
443
|
+
});
|
|
444
|
+
const other = tokenRecord({ kind: "resetPassword" });
|
|
445
|
+
await stores.tokens.insertToken(spent);
|
|
446
|
+
await stores.tokens.insertToken(other);
|
|
447
|
+
for (const call of ["first", "second"]) {
|
|
448
|
+
equal(await stores.tokens.countAttempt(spent.tokenHash, "signInCode"), spent, `countAttempt on a spent token, the ${call} time, should answer it as it is: attempts still 3, nothing written`);
|
|
449
|
+
}
|
|
450
|
+
isNull(await stores.tokens.countAttempt(other.tokenHash, "signInCode"), "countAttempt for a resetPassword token counted as signInCode");
|
|
451
|
+
equal(await stores.tokens.consumeToken(other.tokenHash, "resetPassword", at("2026-02-01T00:00:00.000Z")), other, "countAttempt of the other kind should not have counted: attempts still 0");
|
|
452
|
+
isNull(await stores.tokens.countAttempt("0".repeat(64), "signInCode"), "countAttempt for an unknown hash");
|
|
453
|
+
}
|
|
454
|
+
},
|
|
381
455
|
{
|
|
382
456
|
id: "tokens.lapsed",
|
|
383
457
|
group: group2,
|
|
@@ -434,6 +508,12 @@ var tokenStoreCases = [
|
|
|
434
508
|
];
|
|
435
509
|
// src/conformance/cases/users.ts
|
|
436
510
|
var group3 = "users";
|
|
511
|
+
var secondFactor = {
|
|
512
|
+
method: "totp",
|
|
513
|
+
secret: "v1.2026-09.aXY.Y2lwaGVydGV4dA",
|
|
514
|
+
confirmedAt: null,
|
|
515
|
+
lastStep: null
|
|
516
|
+
};
|
|
437
517
|
var userStoreCases = [
|
|
438
518
|
{
|
|
439
519
|
id: "users.roundTrip",
|
|
@@ -594,6 +674,11 @@ var userStoreCases = [
|
|
|
594
674
|
async run({ stores }) {
|
|
595
675
|
const record = userRecord({
|
|
596
676
|
fields: { email: "kept@example.test", plan: "pro" },
|
|
677
|
+
secondFactor: {
|
|
678
|
+
...secondFactor,
|
|
679
|
+
confirmedAt: at("2026-01-03T00:00:00.000Z"),
|
|
680
|
+
lastStep: 59000000
|
|
681
|
+
},
|
|
597
682
|
emailVerifiedAt: at("2026-01-02T00:00:00.000Z")
|
|
598
683
|
});
|
|
599
684
|
await stores.users.insertUser(record);
|
|
@@ -603,7 +688,7 @@ var userStoreCases = [
|
|
|
603
688
|
schemaVersion: "2",
|
|
604
689
|
version: 1,
|
|
605
690
|
updatedAt: at("2026-02-01T00:00:00.000Z")
|
|
606
|
-
}, "updateUser naming only schemaVersion should leave active, fields, logins, password and emailVerifiedAt untouched");
|
|
691
|
+
}, "updateUser naming only schemaVersion should leave active, fields, logins, password, secondFactor and emailVerifiedAt untouched");
|
|
607
692
|
}
|
|
608
693
|
},
|
|
609
694
|
{
|
|
@@ -619,6 +704,27 @@ var userStoreCases = [
|
|
|
619
704
|
isNull(removed.password, "updateUser with password: null should remove the password");
|
|
620
705
|
}
|
|
621
706
|
},
|
|
707
|
+
{
|
|
708
|
+
id: "users.secondFactorSlot",
|
|
709
|
+
group: group3,
|
|
710
|
+
name: "round-trips a second factor, keeps it when a patch does not name it, and removes it when the patch names null",
|
|
711
|
+
async run({ stores }) {
|
|
712
|
+
const record = userRecord({ secondFactor });
|
|
713
|
+
equal(await stores.users.insertUser(record), record, "insertUser should answer a pending second factor as written: confirmedAt and lastStep null");
|
|
714
|
+
const confirmed = {
|
|
715
|
+
...secondFactor,
|
|
716
|
+
confirmedAt: at("2026-02-01T00:00:00.000Z"),
|
|
717
|
+
lastStep: 59000000
|
|
718
|
+
};
|
|
719
|
+
equal((await stores.users.updateUser(record.id, {
|
|
720
|
+
updatedAt: at("2026-02-01T00:00:00.000Z"),
|
|
721
|
+
secondFactor: confirmed
|
|
722
|
+
}, 0)).secondFactor, confirmed, "updateUser naming secondFactor should replace it whole");
|
|
723
|
+
equal((await stores.users.updateUser(record.id, { updatedAt: at("2026-02-02T00:00:00.000Z") }, 1)).secondFactor, confirmed, "updateUser not naming secondFactor should keep it");
|
|
724
|
+
equal((await stores.users.findUser(record.id))?.secondFactor, confirmed, "findUser should answer the second factor as written");
|
|
725
|
+
isNull((await stores.users.updateUser(record.id, { updatedAt: at("2026-02-03T00:00:00.000Z"), secondFactor: null }, 2)).secondFactor, "updateUser with secondFactor: null should remove the second factor");
|
|
726
|
+
}
|
|
727
|
+
},
|
|
622
728
|
{
|
|
623
729
|
id: "users.loginsMove",
|
|
624
730
|
group: group3,
|
|
@@ -1132,5 +1238,5 @@ export {
|
|
|
1132
1238
|
userStoreCases
|
|
1133
1239
|
};
|
|
1134
1240
|
|
|
1135
|
-
//# debugId=
|
|
1241
|
+
//# debugId=0A8EAAB684A6875C64756E2164756E21
|
|
1136
1242
|
//# sourceMappingURL=index.js.map
|