@jskit-ai/auth-provider-local-db-core 0.1.158 → 0.1.160

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/CHANGELOG.md CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ - `auth.local.recovery.consumeForUser(userId, { ...options, idPrefix })` consumes only the user's open tokens whose id starts with `idPrefix`, such as `"rec_"` for a password reset's, and requires it (a `TypeError` without one). It consumed every open token of the user, so an app's new sign-in link (its own `magic_…` tokens) cancelled an outstanding password reset, and a reset its links. The prefix is compared exactly, never as a LIKE pattern, through the recovery table's new server-only `idPrefix` filter. The backend's `recovery.consumeForUser(userId, { idPrefix })` takes it too.
6
+ - `auth.local.sessions.update(sessionId, changes, { ...options, onlyIf })` changes the session only while it still has the `onlyIf` values (`userId`, `purpose`, `revokedAt`; others are refused), compared in the one UPDATE, and answers null, writing nothing, when it is missing or no longer matches. An app promotes a sign-in link's session with `onlyIf: { userId, purpose: "recovery", revokedAt: null }` instead of updating it unconditionally and checking afterwards. Its tests run on SQLite, MariaDB/MySQL and PostgreSQL (`tokenKinds*.test.js`; the PostgreSQL one in CI's PostgreSQL job).
7
+ - Its table resources declare the foreign keys their migrations create (`foreignKeys`), so json-rest-api 3.1.0 can skip the visibility query a system-context read makes for a record such a key guarantees exists. `jskit test --databases` checks each against an app's test database: auth_local_sessions.user_id and auth_local_recovery.user_id to auth_local_users. `localAuthRecords.mysql.test.js` proves the declarations match the migrations on MariaDB.
5
8
  - The owner APIs (`auth.local.accounts`, `auth.local.sessions`, `auth.local.recovery`) hand their records only the caller's transaction, with the feature's system context: a caller's other settings no longer ride into every read and write the records make.
6
9
  - `@jskit-ai/database-runtime` and `@jskit-ai/resource-runtime` are peer dependencies, required and at the same versions, where they were dependencies: its accounts, sessions and sign-in records are table resources, and the app holds one copy of the table runtime that every package shares, as it does the kernel. npm installs a required peer as it installed the dependency, so an app installs the same packages and versions; a release whose versions disagree now fails the install with ERESOLVE instead of nesting a second copy.
7
10
  - `auth.local.accounts.create` (and the database backend's `users.create`) refuses a duplicate account with a `ConflictError` (409) coded `auth.local.accounts.exists`, carrying the database error as its `cause`, where it threw a plain `Error("Local auth user already exists.")` with no code.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jskit-ai/auth-provider-local-db-core",
3
- "version": "0.1.158",
3
+ "version": "0.1.160",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "test": "jskit test"
@@ -11,14 +11,14 @@
11
11
  "./server/types": "./src/server/types.js"
12
12
  },
13
13
  "dependencies": {
14
- "@jskit-ai/auth-provider-local-core": "0.2.17",
15
- "@jskit-ai/resource-core": "0.1.205"
14
+ "@jskit-ai/auth-provider-local-core": "0.2.18",
15
+ "@jskit-ai/resource-core": "0.1.206"
16
16
  },
17
17
  "peerDependencies": {
18
- "@jskit-ai/auth-core": "0.2.14",
19
- "@jskit-ai/database-runtime": "0.1.263",
20
- "@jskit-ai/kernel": "0.2.14",
21
- "@jskit-ai/resource-runtime": "0.2.12"
18
+ "@jskit-ai/auth-core": "0.2.15",
19
+ "@jskit-ai/database-runtime": "0.1.264",
20
+ "@jskit-ai/kernel": "0.2.15",
21
+ "@jskit-ai/resource-runtime": "0.2.14"
22
22
  },
23
23
  "description": "Database-backed local auth storage backend for JSKIT local auth.",
24
24
  "jskit": {
@@ -41,6 +41,24 @@ function text(value) {
41
41
  return String(value || "");
42
42
  }
43
43
 
44
+ // A session's conditional update compares only whose session it is and where it stands.
45
+ const SESSION_CONDITIONS = Object.freeze(["userId", "purpose", "revokedAt"]);
46
+
47
+ function requireSessionConditions(onlyIf) {
48
+ if (!onlyIf || typeof onlyIf !== "object" || Array.isArray(onlyIf) || Object.keys(onlyIf).length < 1 ||
49
+ Object.keys(onlyIf).some((key) => !SESSION_CONDITIONS.includes(key))) {
50
+ throw new TypeError(`auth.local.sessions.update() takes onlyIf with ${SESSION_CONDITIONS.join(", ")} only.`);
51
+ }
52
+ }
53
+
54
+ // A user's recovery tokens are of a kind by the start of their ids: a password reset's are `rec_`, an app's own
55
+ // kinds (such as a sign-in link) have prefixes of their own.
56
+ function requireIdPrefix(idPrefix) {
57
+ if (typeof idPrefix !== "string" || !idPrefix) {
58
+ throw new TypeError("auth.local.recovery.consumeForUser() takes the idPrefix of the tokens it consumes, such as \"rec_\".");
59
+ }
60
+ }
61
+
44
62
  function readPassword(record) {
45
63
  return {
46
64
  algorithm: text(record.passwordAlgorithm),
@@ -354,7 +372,9 @@ function sessionRecords(sessions, options) {
354
372
  return mapSession(await findOne(sessions, "tokenHash", tokenHash, options));
355
373
  },
356
374
  // Only a session's purpose and expiry change, as when a magic-link session becomes a normal one.
357
- async update(sessionId, { purpose, expiresAt, ...rest } = {}) {
375
+ // updateOptions.onlyIf changes it only while it still has those values (userId, purpose, revokedAt: null), in
376
+ // the UPDATE itself: a session that is missing or no longer matches answers null, with nothing written.
377
+ async update(sessionId, { purpose, expiresAt, ...rest } = {}, { onlyIf } = {}) {
358
378
  if (Object.keys(rest).length > 0) {
359
379
  throw new TypeError("auth.local.sessions.update() changes a session's purpose and expiresAt only.");
360
380
  }
@@ -365,7 +385,11 @@ function sessionRecords(sessions, options) {
365
385
  if (expiresAt !== undefined) {
366
386
  changes.expiresAt = requiredDateTime(expiresAt);
367
387
  }
368
- return mapSession(await patchExisting(sessions, sessionId, changes, options));
388
+ if (onlyIf === undefined) {
389
+ return mapSession(await patchExisting(sessions, sessionId, changes, options));
390
+ }
391
+ requireSessionConditions(onlyIf);
392
+ return mapSession(await patchExisting(sessions, sessionId, changes, { ...options, onlyIf }));
369
393
  },
370
394
  async revoke(sessionId) {
371
395
  const existing = await findById(sessions, sessionId, options);
@@ -424,13 +448,16 @@ function recoveryRecords(recovery, options) {
424
448
  missing: "skip"
425
449
  }));
426
450
  },
427
- async consumeForUser(userId) {
451
+ // The user's unused tokens of one kind (consumeOptions.idPrefix), never their others: a new sign-in link leaves
452
+ // an open password reset usable, and the other way round.
453
+ async consumeForUser(userId, { idPrefix } = {}) {
454
+ requireIdPrefix(idPrefix);
428
455
  const owner = text(userId);
429
456
  if (!owner) {
430
457
  return 0;
431
458
  }
432
459
  const usedAt = requiredDateTime();
433
- return recovery.patchWhere({ userId: owner }, { usedAt, updatedAt: usedAt }, {
460
+ return recovery.patchWhere({ userId: owner, idPrefix }, { usedAt, updatedAt: usedAt }, {
434
461
  ...options,
435
462
  onlyIf: { usedAt: null },
436
463
  returning: "count"
@@ -621,7 +648,8 @@ function createLocalDbOwners({ resources, identities, context }) {
621
648
  });
622
649
  const sessions = Object.freeze({
623
650
  create: (input, options = {}) => records(options).sessions.create(input),
624
- update: (sessionId, changes, options = {}) => records(options).sessions.update(sessionId, changes),
651
+ // options.onlyIf (userId, purpose, revokedAt) changes the session only while it still matches, or answers null.
652
+ update: (sessionId, changes, { onlyIf, ...options } = {}) => records(options).sessions.update(sessionId, changes, { onlyIf }),
625
653
  revoke: (sessionId, options = {}) => records(options).sessions.revoke(sessionId),
626
654
  // options.exceptSessionId keeps that session.
627
655
  revokeForUser: (userId, { exceptSessionId, ...options } = {}) => records(options).sessions.revokeForUser(userId, { exceptSessionId }),
@@ -631,7 +659,8 @@ function createLocalDbOwners({ resources, identities, context }) {
631
659
  create: (input, options = {}) => records(options).recovery.create(input),
632
660
  findByTokenHash: (tokenHash, options = {}) => records(options).recovery.findByTokenHash(tokenHash),
633
661
  consume: (tokenId, options = {}) => records(options).recovery.consume(tokenId),
634
- consumeForUser: (userId, options = {}) => records(options).recovery.consumeForUser(userId)
662
+ // options.idPrefix names the kind of token consumed, such as "rec_" for a password reset's.
663
+ consumeForUser: (userId, { idPrefix, ...options } = {}) => records(options).recovery.consumeForUser(userId, { idPrefix })
635
664
  });
636
665
 
637
666
  return Object.freeze({
@@ -18,6 +18,12 @@ const password = Object.freeze({
18
18
  // Rows that expire by a time, inclusive.
19
19
  const expiresAtOrBefore = Object.freeze({ type: "dateTime", actualField: "expiresAt", filterOperator: "<=" });
20
20
 
21
+ // Rows whose id starts with the text, compared as the column compares text and never as a LIKE pattern, which would
22
+ // read the `_` of a prefix such as `rec_` as any character.
23
+ function idStartsWith(query, prefix, { column }) {
24
+ query.whereRaw("substr(??, 1, ?) = ?", [column("id"), prefix.length, prefix]);
25
+ }
26
+
21
27
  // auth_local_users: one row per local account, keyed by its text id.
22
28
  const localAuthUserResource = defineTableResource({
23
29
  name: "localAuthUsers",
@@ -39,6 +45,7 @@ const localAuthSessionResource = defineTableResource({
39
45
  name: "localAuthSessions",
40
46
  tableName: "auth_local_sessions",
41
47
  ownership: "public",
48
+ foreignKeys: [{ columns: ["userId"], referencedTableName: "auth_local_users" }],
42
49
  schema: {
43
50
  userId: searchableText,
44
51
  tokenHash: searchableText,
@@ -60,6 +67,7 @@ const localAuthRecoveryResource = defineTableResource({
60
67
  name: "localAuthRecovery",
61
68
  tableName: "auth_local_recovery",
62
69
  ownership: "public",
70
+ foreignKeys: [{ columns: ["userId"], referencedTableName: "auth_local_users" }],
63
71
  schema: {
64
72
  userId: searchableText,
65
73
  tokenHash: searchableText,
@@ -67,6 +75,10 @@ const localAuthRecoveryResource = defineTableResource({
67
75
  usedAt: optionalDateTime,
68
76
  createdAt: dateTime,
69
77
  updatedAt: dateTime
78
+ },
79
+ searchSchema: {
80
+ // One kind of token, such as a password reset's (`rec_`).
81
+ idPrefix: { type: "string", applyFilter: idStartsWith }
70
82
  }
71
83
  });
72
84
 
@@ -1,7 +1,9 @@
1
1
  import assert from "node:assert/strict";
2
2
  import test from "node:test";
3
3
  import { requireTestDatabase } from "@jskit-ai/database-runtime/server/testDatabases";
4
+ import { checkForeignKeys } from "@jskit-ai/resource-runtime/server";
4
5
  import { expectEveryTableOwned } from "@jskit-ai/resource-runtime/test";
6
+ import { LOCAL_AUTH_RESOURCES } from "../src/server/lib/localAuthResources.js";
5
7
  import { LOCAL_AUTH_INFRASTRUCTURE_TABLES } from "../src/server/lib/index.js";
6
8
  import { openLocalAuthDatabase } from "./support/mysqlLocalAuth.js";
7
9
 
@@ -228,8 +230,8 @@ test("recovery: create, find by token hash, consume once, and consume a user's o
228
230
  await tx.recovery.create(token("rec_three", { usedAt: "2026-11-02T00:00:00.000Z" }));
229
231
  });
230
232
  assert.equal((await backend.withTransaction((tx) => tx.recovery.findByTokenHash("hash-rec_three"))).usedAt, "2026-11-02T00:00:00.000Z");
231
- assert.equal(await backend.withTransaction((tx) => tx.recovery.consumeForUser("usr_ada")), 1, "only rec_two was open");
232
- assert.equal(await backend.withTransaction((tx) => tx.recovery.consumeForUser("usr_ada")), 0);
233
+ assert.equal(await backend.withTransaction((tx) => tx.recovery.consumeForUser("usr_ada", { idPrefix: "rec_" })), 1, "only rec_two was open");
234
+ assert.equal(await backend.withTransaction((tx) => tx.recovery.consumeForUser("usr_ada", { idPrefix: "rec_" })), 0);
233
235
  assert.equal((await backend.withTransaction((tx) => tx.recovery.findByTokenHash("hash-rec_three"))).usedAt, "2026-11-02T00:00:00.000Z");
234
236
  });
235
237
 
@@ -445,7 +447,7 @@ test("the owner APIs answer as the backend does and join a caller's transaction,
445
447
  });
446
448
  assert.equal(await sessions.revokeForUser("usr_ada", { exceptSessionId: "ses_kept" }), 2, "ses_live and ses_old");
447
449
  assert.equal(await sessions.deleteExpired("2026-11-08T00:00:00.000Z"), 1);
448
- assert.equal(await recovery.consumeForUser("usr_ada"), 1);
450
+ assert.equal(await recovery.consumeForUser("usr_ada", { idPrefix: "rec_" }), 1);
449
451
  const verified = await accounts.markEmailVerified("usr_ada");
450
452
  assert.equal((await accounts.markEmailVerified("usr_ada")).emailVerifiedAt, verified.emailVerifiedAt);
451
453
  assert.equal(await accounts.updatePassword("usr_missing", NEXT_PASSWORD), null);
@@ -458,3 +460,9 @@ test("every local sign-in table is a table resource or one of LOCAL_AUTH_INFRAST
458
460
  await expectEveryTableOwned({ knex, runtime: resourceRuntime, infrastructureTables: LOCAL_AUTH_INFRASTRUCTURE_TABLES, environment: process.env });
459
461
  await assert.rejects(expectEveryTableOwned({ knex, runtime: resourceRuntime, environment: process.env }), /Tables no feature owns: auth_local_identities\./u);
460
462
  });
463
+
464
+ test("the local sign-in table resources declare exactly the foreign keys the migrations create", async (context) => {
465
+ const { knex } = await openLocalAuthDatabase(context, "da_local_keys");
466
+ const tables = LOCAL_AUTH_RESOURCES.map((resource) => resource.tableName);
467
+ assert.deepEqual(await checkForeignKeys({ knex, resources: LOCAL_AUTH_RESOURCES, tables }), { missing: [], undeclared: [] });
468
+ });
@@ -96,5 +96,5 @@ test("sessions.deleteExpired deletes the sessions expired by then and keeps the
96
96
  });
97
97
  assert.equal((await recovery.findByTokenHash("recovery-hash")).id, token.id);
98
98
  assert.notEqual((await recovery.consume("rec_owner")).usedAt, "");
99
- assert.equal(await recovery.consumeForUser("usr_sessions"), 0);
99
+ assert.equal(await recovery.consumeForUser("usr_sessions", { idPrefix: "rec_" }), 0);
100
100
  });
@@ -108,7 +108,7 @@ test("DB local auth backend implements the storage repository contract", async (
108
108
  assert.equal(recovery.usedAt, "");
109
109
  assert.equal((await tx.recovery.findByTokenHash("recovery-token-hash")).id, "rec_db_contract");
110
110
  assert.notEqual((await tx.recovery.consume("rec_db_contract")).usedAt, "");
111
- assert.equal(await tx.recovery.consumeForUser("usr_db_contract"), 0);
111
+ assert.equal(await tx.recovery.consumeForUser("usr_db_contract", { idPrefix: "rec_" }), 0);
112
112
  });
113
113
 
114
114
  assert.equal(transactions.count, 1);
@@ -0,0 +1,40 @@
1
+ import knexLib from "knex";
2
+ import { requireTestDatabase } from "@jskit-ai/database-runtime/server/testDatabases";
3
+ import { LOCAL_AUTH_MIGRATIONS, startLocalAuthRecords } from "./localAuthRuntime.js";
4
+
5
+ // Local sign-in's tables in a PostgreSQL schema of the test's own in TEST_DB_NAME, named after it with the test's
6
+ // suffix and dropped after the test, with the provider started as an application starts it, as mysqlLocalAuth.js
7
+ // does on MariaDB/MySQL.
8
+
9
+ // A PostgreSQL test on a run for another database, such as CI's MariaDB run, is left to the PostgreSQL run.
10
+ const POSTGRES_ELSEWHERE = process.env.DB_CLIENT && process.env.DB_CLIENT !== "pg"
11
+ ? `a PostgreSQL test, on a ${process.env.DB_CLIENT} run`
12
+ : false;
13
+
14
+ /**
15
+ * @param {import("node:test").TestContext} context
16
+ * @param {string} suffix
17
+ */
18
+ async function openPostgresLocalAuth(context, suffix) {
19
+ const database = requireTestDatabase(process.env);
20
+ const schema = `${database}_${suffix}_${process.pid}`;
21
+ if (schema.length > 63) throw new Error(`Test schema name ${schema} is longer than PostgreSQL's 63 characters.`);
22
+ const connection = { host: process.env.DB_HOST, port: Number(process.env.DB_PORT) || 5432, user: process.env.DB_USER, password: process.env.DB_PASSWORD, database };
23
+ const admin = knexLib({ client: "pg", connection, pool: { min: 0, max: 1 } });
24
+ await admin.raw("DROP SCHEMA IF EXISTS ?? CASCADE", [schema]);
25
+ await admin.raw("CREATE SCHEMA ??", [schema]);
26
+ const knex = knexLib({ client: "pg", connection, searchPath: [schema], pool: { min: 0, max: 6 } });
27
+ context.after(async () => {
28
+ try {
29
+ await knex.destroy();
30
+ await admin.raw("DROP SCHEMA IF EXISTS ?? CASCADE", [schema]);
31
+ } finally {
32
+ await admin.destroy();
33
+ }
34
+ });
35
+ for (const migration of LOCAL_AUTH_MIGRATIONS) await migration.up(knex);
36
+
37
+ return Object.freeze({ knex, ...(await startLocalAuthRecords(knex)) });
38
+ }
39
+
40
+ export { POSTGRES_ELSEWHERE, openPostgresLocalAuth };
@@ -0,0 +1,101 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+ import { countQueries, requireTestDatabase } from "@jskit-ai/database-runtime/server/testDatabases";
4
+
5
+ // Through the owner APIs, on SQLite, MariaDB/MySQL and PostgreSQL alike: auth.local.recovery consuming one kind of a
6
+ // user's tokens, and auth.local.sessions promoting a session only while it is still the user's recovery session.
7
+
8
+ const PASSWORD = Object.freeze({ algorithm: "scrypt", version: "1", salt: "salt-one", hash: "hash-one" });
9
+ const CREATED = "2026-11-01T08:00:00.000Z";
10
+ const LATER = "2026-12-01T00:00:00.000Z";
11
+
12
+ async function createAccounts(accounts) {
13
+ for (const id of ["usr_ada", "usr_bob"]) {
14
+ await accounts.create({ id, email: `${id}@example.com`, displayName: id, password: PASSWORD, createdAt: CREATED });
15
+ }
16
+ }
17
+
18
+ /**
19
+ * Registers the tests on the records `open(context, suffix)` answers, as startLocalAuthRecords() gives them.
20
+ * @param {(context: import("node:test").TestContext, suffix: string) => Promise<any>} open
21
+ * @param {{ database?: boolean, skip?: string | false }} [options] `database`: the records need TEST_DB_NAME.
22
+ */
23
+ function tokenKindCases(open, { database = false, skip = false } = {}) {
24
+ test("consumeForUser consumes the user's open tokens of one kind: a sign-in link leaves a password reset open, and the other way round", { skip }, async (context) => {
25
+ if (database) requireTestDatabase(process.env);
26
+ const { accounts, recovery, inCallerTransaction } = await open(context, "da_local_kinds");
27
+ await createAccounts(accounts);
28
+ const token = (id, userId = "usr_ada") => recovery.create({ id, userId, tokenHash: `hash-${id}`, expiresAt: LATER, createdAt: CREATED });
29
+ const stillOpen = async (...ids) => Promise.all(ids.map(async (id) => (await recovery.findByTokenHash(`hash-${id}`)).usedAt === ""));
30
+ // A password reset, two sign-in links, another user's link, and an id a LIKE 'rec_%' would also take.
31
+ for (const id of ["rec_reset", "magic_one", "magic_two", "recXother"]) await token(id);
32
+ await token("magic_bob", "usr_bob");
33
+
34
+ // A new sign-in link consumes the user's earlier links only.
35
+ assert.equal(await recovery.consumeForUser("usr_ada", { idPrefix: "magic_" }), 2);
36
+ assert.deepEqual(await stillOpen("rec_reset", "magic_one", "magic_two", "recXother", "magic_bob"), [true, false, false, true, true]);
37
+ assert.equal(await recovery.consumeForUser("usr_ada", { idPrefix: "magic_" }), 0);
38
+
39
+ // A completed reset consumes the user's resets only, in the caller's transaction, whose rollback undoes it.
40
+ await token("magic_three");
41
+ const abort = new Error("Abort the reset");
42
+ await assert.rejects(inCallerTransaction(async (options) => {
43
+ assert.equal(await recovery.consumeForUser("usr_ada", { ...options, idPrefix: "rec_" }), 1);
44
+ throw abort;
45
+ }), (error) => error === abort);
46
+ assert.deepEqual(await stillOpen("rec_reset"), [true], "the rolled-back consume is gone");
47
+ assert.equal(await recovery.consumeForUser("usr_ada", { idPrefix: "rec_" }), 1);
48
+ assert.deepEqual(await stillOpen("rec_reset", "magic_three", "recXother", "magic_bob"), [false, true, true, true]);
49
+
50
+ for (const options of [undefined, {}, { idPrefix: "" }, { idPrefix: 1 }]) {
51
+ await assert.rejects(recovery.consumeForUser("usr_ada", options), {
52
+ name: "TypeError",
53
+ message: "auth.local.recovery.consumeForUser() takes the idPrefix of the tokens it consumes, such as \"rec_\"."
54
+ });
55
+ }
56
+ });
57
+
58
+ test("sessions.update with onlyIf promotes a session in one UPDATE only while it is still the user's unrevoked recovery session", { skip }, async (context) => {
59
+ if (database) requireTestDatabase(process.env);
60
+ const { knex, accounts, sessions, backend, inCallerTransaction } = await open(context, "da_local_promote");
61
+ await createAccounts(accounts);
62
+ const session = (id) => sessions.create({ id, userId: "usr_ada", tokenHash: `hash-${id}`, purpose: "recovery", expiresAt: LATER, createdAt: CREATED });
63
+ const promote = (id, userId, options = {}) => sessions.update(id, { purpose: "normal", expiresAt: LATER }, {
64
+ ...options,
65
+ onlyIf: { userId, purpose: "recovery", revokedAt: null }
66
+ });
67
+ const stored = (id) => backend.withTransaction((tx) => tx.sessions.findById(id));
68
+ const created = await session("ses_recovery");
69
+
70
+ assert.equal(await promote("ses_recovery", "usr_bob"), null, "another user's session is not promoted");
71
+ const abort = new Error("Abort the promotion");
72
+ await assert.rejects(inCallerTransaction(async (options) => {
73
+ assert.equal((await promote("ses_recovery", "usr_ada", options)).purpose, "normal");
74
+ throw abort;
75
+ }), (error) => error === abort);
76
+ assert.deepEqual(await stored("ses_recovery"), created, "the rolled-back promotion is gone");
77
+
78
+ const { result, queries } = await countQueries(knex, () => promote("ses_recovery", "usr_ada"));
79
+ assert.deepEqual(result, { ...created, purpose: "normal" });
80
+ const updates = queries.filter((sql) => /^update/iu.test(sql));
81
+ assert.equal(updates.length, 1);
82
+ const where = updates[0].split(/ where /iu)[1];
83
+ for (const column of ["user_id", "purpose", "revoked_at"]) assert.match(where, new RegExp(column, "u"), "the UPDATE compares the conditions");
84
+ assert.equal(await promote("ses_recovery", "usr_ada"), null, "a promoted session is no recovery session");
85
+
86
+ await session("ses_revoked");
87
+ await sessions.revoke("ses_revoked");
88
+ assert.equal(await promote("ses_revoked", "usr_ada"), null, "a revoked session is not promoted");
89
+ assert.equal((await stored("ses_revoked")).purpose, "recovery");
90
+ assert.equal(await promote("ses_missing", "usr_ada"), null);
91
+
92
+ for (const onlyIf of [{}, { tokenHash: "hash-ses_recovery" }, null, ["userId"]]) {
93
+ await assert.rejects(sessions.update("ses_recovery", { purpose: "normal" }, { onlyIf }), {
94
+ name: "TypeError",
95
+ message: "auth.local.sessions.update() takes onlyIf with userId, purpose, revokedAt only."
96
+ });
97
+ }
98
+ });
99
+ }
100
+
101
+ export { tokenKindCases };
@@ -0,0 +1,4 @@
1
+ import { openLocalAuthDatabase } from "./support/mysqlLocalAuth.js";
2
+ import { tokenKindCases } from "./support/tokenKindCases.js";
3
+
4
+ tokenKindCases(openLocalAuthDatabase, { database: true });
@@ -0,0 +1,4 @@
1
+ import { POSTGRES_ELSEWHERE, openPostgresLocalAuth } from "./support/postgresLocalAuth.js";
2
+ import { tokenKindCases } from "./support/tokenKindCases.js";
3
+
4
+ tokenKindCases(openPostgresLocalAuth, { database: true, skip: POSTGRES_ELSEWHERE });
@@ -0,0 +1,4 @@
1
+ import { openSqliteLocalAuth } from "./support/localAuthRuntime.js";
2
+ import { tokenKindCases } from "./support/tokenKindCases.js";
3
+
4
+ tokenKindCases((context) => openSqliteLocalAuth(context));