@jskit-ai/auth-provider-local-db-core 0.1.196 → 0.1.197

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
+ - 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`.
5
6
  - Each table migration has a companion that Knex runs just before it, `auth_local_db_initial-collation`, `auth_local_db_oauth-collation`, `auth_local_db_protection-collation`, `auth_local_db_used_passes-collation` and `auth_local_db_users_second_factors-collation` (run `npm run db:migrate`): on MySQL and MariaDB each creates its migration's tables in the collation of `auth_local_users` (or `users`), not the database's default. On a database whose default differs from its tables', `auth_local_db_users_second_factors` failed (errno 150) and left an empty, unrecorded `auth_local_second_factors`, after recording `auth_local_used_passes` in the database's default; the next migrate creates the first again with its key to `auth_local_users`, converts the second keeping its rows, and adds the key a second try recorded without. A database whose tables match its default changes nothing. No released migration changed.
6
7
  - A user's waiting email change, in the new nullable column `auth_local_users.pending_email` (migration `auth_local_db_users_pending_email`; run `npm run db:migrate`), behind the backend contract's `pendingEmail`, `users.updatePendingEmail` and `users.updateEmail`. Changing the email clears the waiting change and sets `email_verified_at`, which the link sent to the address proves; an email another account has is refused with `auth.local.accounts.exists`.
7
8
  - Sessions keep where and when they were last seen, in the new nullable columns `auth_local_sessions.ip`, `user_agent` and `last_seen_at` (migration `auth_local_db_sessions_metadata`; run `npm run db:migrate`), behind the backend contract's session fields and `sessions.touch`. `auth.local.sessions.listForUser(userId, options)` answers an account's sessions that are neither revoked nor expired, the newest first, every one of them in one read, each with `ip`, `userAgent` and `lastSeenAt`, and refuses a missing id with a `TypeError`: for an application's list of a person's sessions, its own or an operator's.
@@ -0,0 +1,20 @@
1
+ // The invitation a provider sign-in started from, kept with its attempt until the sign-in ends; null for one started
2
+ // without an invitation.
3
+ const OAUTH_ATTEMPTS_TABLE = "auth_local_oauth_attempts";
4
+ const COLUMN_NAME = "invitation_token";
5
+
6
+ exports.up = async function up(knex) {
7
+ if (!(await knex.schema.hasColumn(OAUTH_ATTEMPTS_TABLE, COLUMN_NAME))) {
8
+ await knex.schema.alterTable(OAUTH_ATTEMPTS_TABLE, (table) => {
9
+ table.text(COLUMN_NAME).nullable();
10
+ });
11
+ }
12
+ };
13
+
14
+ exports.down = async function down(knex) {
15
+ if (await knex.schema.hasColumn(OAUTH_ATTEMPTS_TABLE, COLUMN_NAME)) {
16
+ await knex.schema.alterTable(OAUTH_ATTEMPTS_TABLE, (table) => {
17
+ table.dropColumn(COLUMN_NAME);
18
+ });
19
+ }
20
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jskit-ai/auth-provider-local-db-core",
3
- "version": "0.1.196",
3
+ "version": "0.1.197",
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.40",
15
- "@jskit-ai/resource-core": "0.1.221"
14
+ "@jskit-ai/auth-provider-local-core": "0.2.41",
15
+ "@jskit-ai/resource-core": "0.1.222"
16
16
  },
17
17
  "peerDependencies": {
18
- "@jskit-ai/auth-core": "0.2.34",
19
- "@jskit-ai/database-runtime": "0.1.280",
20
- "@jskit-ai/kernel": "0.2.30",
21
- "@jskit-ai/resource-runtime": "0.2.44"
18
+ "@jskit-ai/auth-core": "0.2.35",
19
+ "@jskit-ai/database-runtime": "0.1.281",
20
+ "@jskit-ai/kernel": "0.2.31",
21
+ "@jskit-ai/resource-runtime": "0.2.45"
22
22
  },
23
23
  "description": "Database-backed local auth storage backend for JSKIT local auth.",
24
24
  "jskit": {
@@ -153,6 +153,7 @@ function mapOAuthAttempt(record) {
153
153
  nonce: text(record.nonce),
154
154
  codeVerifier: text(record.codeVerifier),
155
155
  returnTo: text(record.returnTo),
156
+ invitationToken: text(record.invitationToken),
156
157
  createdAt: readDateTime(record.createdAt),
157
158
  expiresAt: readDateTime(record.expiresAt)
158
159
  };
@@ -254,6 +255,7 @@ function oauthAttemptRecord(input = {}) {
254
255
  nonce: text(input.nonce),
255
256
  codeVerifier: text(input.codeVerifier),
256
257
  returnTo: text(input.returnTo),
258
+ invitationToken: input.invitationToken ? String(input.invitationToken) : null,
257
259
  expiresAt: requiredDateTime(input.expiresAt),
258
260
  createdAt: requiredDateTime(input.createdAt)
259
261
  };
@@ -117,6 +117,8 @@ const localAuthOAuthAttemptResource = defineTableResource({
117
117
  nonce: text,
118
118
  codeVerifier: text,
119
119
  returnTo: text,
120
+ // The invitation a sign-in started from, for its end; null for one started without.
121
+ invitationToken: { ...text, nullable: true },
120
122
  expiresAt: dateTime,
121
123
  createdAt: dateTime
122
124
  },
@@ -270,8 +270,8 @@ test("identities and provider sign-in attempts: links by provider subject, and a
270
270
  const created = await backend.withTransaction((tx) => tx.oauthAttempts.create(attempt("key-one", "2026-12-01T00:00:00.000Z")));
271
271
  assert.deepEqual(created, {
272
272
  browserKeyHash: "key-one", provider: "google", intent: "login", userId: "", state: "state-key-one", nonce: "nonce",
273
- codeVerifier: "verifier", returnTo: "/home", createdAt: CREATED, expiresAt: "2026-12-01T00:00:00.000Z"
274
- }, "an attempt without a user keeps none");
273
+ codeVerifier: "verifier", returnTo: "/home", invitationToken: "", createdAt: CREATED, expiresAt: "2026-12-01T00:00:00.000Z"
274
+ }, "an attempt without a user or an invitation keeps neither");
275
275
  await backend.withTransaction((tx) => tx.oauthAttempts.create(attempt("key-link", "2026-12-01T00:00:00.000Z", { intent: "link", userId: "usr_ada" })));
276
276
 
277
277
  const taken = await Promise.all([1, 2, 3].map(() => backend.withTransaction((tx) => tx.oauthAttempts.take("key-one"))));
@@ -279,6 +279,9 @@ test("identities and provider sign-in attempts: links by provider subject, and a
279
279
  assert.equal(await backend.withTransaction((tx) => tx.oauthAttempts.take("key-one")), null);
280
280
  assert.equal(await backend.withTransaction((tx) => tx.oauthAttempts.take("")), null);
281
281
  assert.equal((await backend.withTransaction((tx) => tx.oauthAttempts.take("key-link"))).userId, "usr_ada");
282
+ await backend.withTransaction((tx) => tx.oauthAttempts.create(attempt("key-invite", "2026-12-01T00:00:00.000Z", { invitationToken: "inv-1" })));
283
+ assert.equal((await backend.withTransaction((tx) => tx.oauthAttempts.take("key-invite"))).invitationToken, "inv-1",
284
+ "a sign-in started from an invitation keeps it");
282
285
 
283
286
  await backend.withTransaction(async (tx) => {
284
287
  await tx.oauthAttempts.create(attempt("key-old", "2026-11-01T00:00:00.000Z"));
@@ -161,6 +161,7 @@ test("a database the released migrations left half-migrated recovers on the next
161
161
  // The state the refused key left, as dogandgroom's database measured it.
162
162
  assert.deepEqual(await recorded(knex), [
163
163
  ...EARLY,
164
+ "auth_local_db_oauth_invitation.cjs",
164
165
  "auth_local_db_sessions_metadata.cjs",
165
166
  "auth_local_db_used_passes.cjs",
166
167
  "auth_local_db_users_disabled_message.cjs",
@@ -18,8 +18,10 @@ test("provider sign-in and linking store identities and single-use attempts in t
18
18
  const { knex, backend } = await openSqliteLocalAuth(t);
19
19
  const service = createService({ backend, oauthProviders: [oidcProviderEntry(issuer)], profileProjector: noAppProfiles });
20
20
 
21
- const { input, request } = await approveAtProvider(service);
21
+ const { input, request } = await approveAtProvider(service, { invitationToken: "inv-1" });
22
22
  assert.equal((await knex(LOCAL_AUTH_DB_TABLES.oauthAttempts).count({ count: "*" }))[0].count, 1);
23
+ assert.equal((await knex(LOCAL_AUTH_DB_TABLES.oauthAttempts).first("invitation_token")).invitation_token, "inv-1",
24
+ "the attempt keeps the invitation its sign-in started from");
23
25
  const result = await service.oauthComplete(input, request);
24
26
  assert.equal((await knex(LOCAL_AUTH_DB_TABLES.oauthAttempts).count({ count: "*" }))[0].count, 0);
25
27
  await assert.rejects(service.oauthComplete(input, request), { code: "auth.local.oauth.expired" });
@@ -5,6 +5,7 @@ import { createTestResourceRuntime } from "@jskit-ai/resource-runtime/test";
5
5
  import { defineTableResource } from "@jskit-ai/resource-core/shared/tableResource";
6
6
  import initialMigration from "../../migrations/auth_local_db_initial.cjs";
7
7
  import oauthMigration from "../../migrations/auth_local_db_oauth.cjs";
8
+ import oauthInvitationMigration from "../../migrations/auth_local_db_oauth_invitation.cjs";
8
9
  import protectionMigration from "../../migrations/auth_local_db_protection.cjs";
9
10
  import sessionsMetadataMigration from "../../migrations/auth_local_db_sessions_metadata.cjs";
10
11
  import usedPassesMigration from "../../migrations/auth_local_db_used_passes.cjs";
@@ -18,6 +19,7 @@ import { AuthLocalDatabaseBackendProvider } from "../../src/server/providers/Aut
18
19
  const LOCAL_AUTH_MIGRATIONS = Object.freeze([
19
20
  initialMigration,
20
21
  oauthMigration,
22
+ oauthInvitationMigration,
21
23
  protectionMigration,
22
24
  sessionsMetadataMigration,
23
25
  usedPassesMigration,