@jskit-ai/auth-provider-local-db-core 0.1.202 → 0.1.203

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,7 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ - Local auth's `accountStateOf({ userId })` runs on the database backend as one select of the users table (SQLite, MariaDB/MySQL and PostgreSQL), changing no row.
5
6
  - The users repository answers `findAllByEmail(email)`, every account with the email: one or none, since the users table's email is unique. Local auth's service keys act as a user by email through it.
6
7
  - The migration `auth_local_db_sign_in_facts` adds nullable `sign_in_ip` and `sign_in_user_agent` columns to `auth_local_sessions` (where a session was signed in from, written once at its creation) and nullable `password_changed_at` and `email_changed_at` timestamps to `auth_local_users` (set by `updatePassword`, a reset or a change, and by a used email-change link). Run `npm run db:migrate`. Rows from before it keep null: their sessions answer no sign-in address or browser, so an action that asks for them makes their people sign in again. The owner APIs carry them: `auth.local.sessions.create` takes `signInIp` and `signInUserAgent`, sessions answer them, accounts answer `passwordChangedAt` and `emailChangedAt`, and `auth.local.accounts.updatePassword` sets `passwordChangedAt`.
7
8
  - The migration `auth_local_db_oauth_invitation` adds a nullable `invitation_token` text column to `auth_local_oauth_attempts`, where a provider sign-in started from an invitation keeps its token until the sign-in ends. Run `npm run db:migrate`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jskit-ai/auth-provider-local-db-core",
3
- "version": "0.1.202",
3
+ "version": "0.1.203",
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.45",
15
- "@jskit-ai/resource-core": "0.1.225"
14
+ "@jskit-ai/auth-provider-local-core": "0.2.46",
15
+ "@jskit-ai/resource-core": "0.1.226"
16
16
  },
17
17
  "peerDependencies": {
18
- "@jskit-ai/auth-core": "0.2.39",
19
- "@jskit-ai/database-runtime": "0.1.285",
20
- "@jskit-ai/kernel": "0.2.34",
21
- "@jskit-ai/resource-runtime": "0.2.49"
18
+ "@jskit-ai/auth-core": "0.2.40",
19
+ "@jskit-ai/database-runtime": "0.1.286",
20
+ "@jskit-ai/kernel": "0.2.35",
21
+ "@jskit-ai/resource-runtime": "0.2.50"
22
22
  },
23
23
  "description": "Database-backed local auth storage backend for JSKIT local auth.",
24
24
  "jskit": {
@@ -41,6 +41,43 @@ function secondFactorCases(open, { database = false, skip = false } = {}) {
41
41
  assert.match(factor.secret_sealed, /^v1\./u);
42
42
  });
43
43
 
44
+ test("accountStateOf reads the named account in one statement and writes nothing (database backend)", { skip }, async (t) => {
45
+ if (database) requireTestDatabase(process.env);
46
+ const { knex, backend } = await open(t, "da_local_account_state");
47
+ const at = "2026-11-13T10:00:00.000Z";
48
+ await backend.withTransaction(async (tx) => {
49
+ await tx.users.create({ id: "usr_ada", email: "ada@example.com", displayName: "Ada", password: {}, createdAt: at });
50
+ await tx.users.create({ id: "usr_off", email: "off@example.com", displayName: "Off", password: {}, disabled: true, createdAt: at });
51
+ await tx.secondFactors.save({
52
+ userId: "usr_ada", secretSealed: "v1.nonce.body.tag", confirmedAt: at, lastUsedStep: 0, recoveryCodes: ["hash-one"],
53
+ failures: 2, lastFailedAt: at, lockedUntil: "", createdAt: at, updatedAt: at
54
+ });
55
+ });
56
+ const { options } = secondFactorServiceOptions();
57
+ const service = createLocalAuthService({ ...options, backend });
58
+ const stored = async () => JSON.stringify([
59
+ await knex(LOCAL_AUTH_DB_TABLES.users).orderBy("id").select(),
60
+ await knex(LOCAL_AUTH_DB_TABLES.secondFactors).select()
61
+ ]);
62
+ const before = await stored();
63
+ const statements = [];
64
+ const record = ({ sql }) => statements.push(String(sql).trim());
65
+ knex.on("query", record);
66
+ const states = [];
67
+ for (const userId of ["usr_ada", "usr_off", "usr_missing"]) {
68
+ statements.length = 0;
69
+ states.push(await service.accountStateOf({ userId }));
70
+ // A transaction's own BEGIN, COMMIT or SAVEPOINT aside, one statement: a read of the account.
71
+ const sent = statements.filter((sql) => !/^(begin|commit|rollback|start transaction|savepoint|release savepoint)\b/iu.test(sql));
72
+ assert.equal(sent.length, 1, `${userId}: ${JSON.stringify(statements)}`);
73
+ assert.match(sent[0], /^select\b/iu);
74
+ assert.ok(sent[0].includes(LOCAL_AUTH_DB_TABLES.users), sent[0]);
75
+ }
76
+ knex.removeListener("query", record);
77
+ assert.deepEqual(states, ["active", "disabled", "missing"]);
78
+ assert.equal(await stored(), before, "no account or factor changed: the two failures still count");
79
+ });
80
+
44
81
  test("the second factor migration runs again, goes down and up, and deleting an account deletes its factor", { skip }, async (t) => {
45
82
  if (database) requireTestDatabase(process.env);
46
83
  const { knex, backend } = await open(t, "da_local_2fa_migration");