Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

chore(deps): bump MikroORM from 7.2.8 to 7.2.12 with better-sqlite3 13.2.0 and kysely 0.29.9

Maurice6905729ab6f0
diff --git a/package-lock.json b/package-lock.json
index 0a96375bd..51c6a9561 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -5572,13 +5572,13 @@
"license": "MIT"
},
"node_modules/@mikro-orm/cli": {
- "version": "7.2.8",
- "resolved": "https://registry.npmjs.org/@mikro-orm/cli/-/cli-7.2.8.tgz",
- "integrity": "sha512-JTgHO79ijaMUlwAnOvsCvWr6BmttDUtwVeui8fiOD31pL/P2BVnG0NPg/qGBWxaqJa76vebdQ5RWQN+deUllvA==",
+ "version": "7.2.12",
+ "resolved": "https://registry.npmjs.org/@mikro-orm/cli/-/cli-7.2.12.tgz",
+ "integrity": "sha512-TgJ9sSbMRkbt0igkpCkD3jl5aVIxPCVI5abtIxexPDhnuiJReYackEii8kxDSFC4Jrf3X+TfBTwhYmSyTGUOYQ==",
"license": "MIT",
"dependencies": {
- "@mikro-orm/core": "7.2.8",
- "mikro-orm": "7.2.8",
+ "@mikro-orm/core": "7.2.12",
+ "mikro-orm": "7.2.12",
"yargs": "18.2.0"
},
"bin": {
@@ -5622,9 +5622,9 @@
}
},
"node_modules/@mikro-orm/core": {
- "version": "7.2.8",
- "resolved": "https://registry.npmjs.org/@mikro-orm/core/-/core-7.2.8.tgz",
- "integrity": "sha512-9E7wApevmNrqswey8pVT65nyBz1ejOafcdyHV2aKU9FmxnWr/MbfOVNlnpMe6D3+r+wsrVyx3dBJ0mHqTYQTCw==",
+ "version": "7.2.12",
+ "resolved": "https://registry.npmjs.org/@mikro-orm/core/-/core-7.2.12.tgz",
+ "integrity": "sha512-UspxelHzHcWLb06IP6JBNLGa9p0fNc5PWchpQhuhs+RFBCELgMy2Vysr0QzDJD0/t3m986WXzrlgbTZkhHY3HQ==",
"license": "MIT",
"engines": {
"node": ">= 22.17.0"
@@ -5642,34 +5642,34 @@
}
},
"node_modules/@mikro-orm/entity-generator": {
- "version": "7.2.8",
- "resolved": "https://registry.npmjs.org/@mikro-orm/entity-generator/-/entity-generator-7.2.8.tgz",
- "integrity": "sha512-WbFD5XietmrGvphIT+6HHDJKx9tlepLKQeZA8qy0kTNpayXsiAze0FiVM1NMJpJvIuJlhiSCJKXikJ2ZEPQbjw==",
+ "version": "7.2.12",
+ "resolved": "https://registry.npmjs.org/@mikro-orm/entity-generator/-/entity-generator-7.2.12.tgz",
+ "integrity": "sha512-fHcDqvS0y5vvaKIf5XKApdoQbsEOB4Aft/SltlvIGWXp7xXI/PXPaUaQ4dyb0SMvbXOAu8QdorL/ZddtGB/42Q==",
"dev": true,
"license": "MIT",
"dependencies": {
- "@mikro-orm/sql": "7.2.8"
+ "@mikro-orm/sql": "7.2.12"
},
"engines": {
"node": ">= 22.17.0"
},
"peerDependencies": {
- "@mikro-orm/core": "7.2.8"
+ "@mikro-orm/core": "7.2.12"
}
},
"node_modules/@mikro-orm/migrations": {
- "version": "7.2.8",
- "resolved": "https://registry.npmjs.org/@mikro-orm/migrations/-/migrations-7.2.8.tgz",
- "integrity": "sha512-6yw3/qW0fpuPwfnq9LxXaEtkaq21dngPoP4jpKMd9EzdUvChZmmNtqxHHl2Mp9e7+K/ihFKH9jd9wNgK7Y6iNA==",
+ "version": "7.2.12",
+ "resolved": "https://registry.npmjs.org/@mikro-orm/migrations/-/migrations-7.2.12.tgz",
+ "integrity": "sha512-s+dp+2PIhdKvHMUNR9jDmnoe5GTFtiWtyS4QfN4VV+fg3aYgCJ/TzR6zccxAwCqIjarHbVRXptliAzGqZ+DXVQ==",
"license": "MIT",
"dependencies": {
- "@mikro-orm/sql": "7.2.8"
+ "@mikro-orm/sql": "7.2.12"
},
"engines": {
"node": ">= 22.17.0"
},
"peerDependencies": {
- "@mikro-orm/core": "7.2.8"
+ "@mikro-orm/core": "7.2.12"
}
},
"node_modules/@mikro-orm/nestjs": {
@@ -5688,13 +5688,13 @@
}
},
"node_modules/@mikro-orm/postgresql": {
- "version": "7.2.8",
- "resolved": "https://registry.npmjs.org/@mikro-orm/postgresql/-/postgresql-7.2.8.tgz",
- "integrity": "sha512-spAGvR8xfXGK0+mwsAsN3Kt5cg2Ge3DgXT3rNOeA7IxaBXpl+NMwXu5cSWes4jHlhWKJ4jzXyTo6xH+we9fbNA==",
+ "version": "7.2.12",
+ "resolved": "https://registry.npmjs.org/@mikro-orm/postgresql/-/postgresql-7.2.12.tgz",
+ "integrity": "sha512-YSZFJH8vRhwuGC979l0SMMdtYYtUDqKwJhcfL9iYpzIYHZWg9HghGh11ZzeQMo7f/zve5uMIRq/dKF8eakYyQA==",
"license": "MIT",
"dependencies": {
- "@mikro-orm/sql": "7.2.8",
- "kysely": "0.29.8",
+ "@mikro-orm/sql": "7.2.12",
+ "kysely": "0.29.9",
"pg": "8.23.1",
"pg-cursor": "2.22.1",
"postgres-array": "3.0.4",
@@ -5705,51 +5705,51 @@
"node": ">= 22.17.0"
},
"peerDependencies": {
- "@mikro-orm/core": "7.2.8"
+ "@mikro-orm/core": "7.2.12"
}
},
"node_modules/@mikro-orm/seeder": {
- "version": "7.2.8",
- "resolved": "https://registry.npmjs.org/@mikro-orm/seeder/-/seeder-7.2.8.tgz",
- "integrity": "sha512-MtyFnkZPB8OoOwkRZRsRtvg8lE5IhwefUF8tOnqSjLBChpBKqrg+P4hdm+dRuot8a7l190HkctlBHmKIBri7Og==",
+ "version": "7.2.12",
+ "resolved": "https://registry.npmjs.org/@mikro-orm/seeder/-/seeder-7.2.12.tgz",
+ "integrity": "sha512-knUSwchPZ8MQajKzwA9uINsby3YYPaCJwNL8GR8L+mi0B/t2KMtgSZB2+nw+gBJFjFMGNy4/cz3TwqdSUzwCuw==",
"license": "MIT",
"engines": {
"node": ">= 22.17.0"
},
"peerDependencies": {
- "@mikro-orm/core": "7.2.8"
+ "@mikro-orm/core": "7.2.12"
}
},
"node_modules/@mikro-orm/sql": {
- "version": "7.2.8",
- "resolved": "https://registry.npmjs.org/@mikro-orm/sql/-/sql-7.2.8.tgz",
- "integrity": "sha512-551INWnMri4veRmOVcGeM4hCn559OgXzxhZqWmVYeF5RDpavlVPBbYdiPaBd7NIOssPEG+LkcDH7lt2l67U4PQ==",
+ "version": "7.2.12",
+ "resolved": "https://registry.npmjs.org/@mikro-orm/sql/-/sql-7.2.12.tgz",
+ "integrity": "sha512-5utXJeoNyVLfuLUvb+N+Kz9zZZJeLLS5OtcuoAHajcd+n+/49Jma7i+c9+Yq2DwceuUlxorIthjVpXiB2ncqvw==",
"license": "MIT",
"dependencies": {
- "kysely": "0.29.8"
+ "kysely": "0.29.9"
},
"engines": {
"node": ">= 22.17.0"
},
"peerDependencies": {
- "@mikro-orm/core": "7.2.8"
+ "@mikro-orm/core": "7.2.12"
}
},
"node_modules/@mikro-orm/sqlite": {
- "version": "7.2.8",
- "resolved": "https://registry.npmjs.org/@mikro-orm/sqlite/-/sqlite-7.2.8.tgz",
- "integrity": "sha512-N5Z64HwRD1LY3Zi369IxVLEXdJUjElOr3APXSR8czmYTZtcaY6A/8bk1+kgYX19LiF3lwFY80xmxZnCrtx1eOg==",
+ "version": "7.2.12",
+ "resolved": "https://registry.npmjs.org/@mikro-orm/sqlite/-/sqlite-7.2.12.tgz",
+ "integrity": "sha512-zFUQlg/xTNzGnXYRroM6gV4j/zllnngZTIs+LhPDwzgCiwm7PCdb5o/+zcFVbI3GYBamheqGv8uKamRPFyT2BA==",
"license": "MIT",
"dependencies": {
- "@mikro-orm/sql": "7.2.8",
- "better-sqlite3": "13.0.3",
- "kysely": "0.29.8"
+ "@mikro-orm/sql": "7.2.12",
+ "better-sqlite3": "13.2.0",
+ "kysely": "0.29.9"
},
"engines": {
"node": ">= 22.17.0"
},
"peerDependencies": {
- "@mikro-orm/core": "7.2.8"
+ "@mikro-orm/core": "7.2.12"
}
},
"node_modules/@modelcontextprotocol/sdk": {
@@ -12120,10 +12120,9 @@
"license": "MIT"
},
"node_modules/better-sqlite3": {
- "version": "13.0.3",
- "resolved": "https://registry.npmjs.org/better-sqlite3/-/better-sqlite3-13.0.3.tgz",
- "integrity": "sha512-RbOBxmLBG8uvFUc15X9+9SFemKcQ0WBuISBVkpuiaUB2qblC8UWlHEjdWVoZ8AdhSwmoEgsiXKfopX0CQxaACQ==",
- "hasInstallScript": true,
+ "version": "13.2.0",
+ "resolved": "https://registry.npmjs.org/better-sqlite3/-/better-sqlite3-13.2.0.tgz",
+ "integrity": "sha512-Z8Q/9x/uNyKxA1v4FNodyItRVRw1TeKBrmj32JhxhR0ceNcBY+wMobt/Bv7M7TzwPAXjnZRtNaEsATnUZSKWZQ==",
"license": "MIT",
"dependencies": {
"node-addon-api": "^8.0.0"
@@ -16898,9 +16897,9 @@
}
},
"node_modules/kysely": {
- "version": "0.29.8",
- "resolved": "https://registry.npmjs.org/kysely/-/kysely-0.29.8.tgz",
- "integrity": "sha512-ixHU1H4R+LeC5Y0nAhYgiGRFpFRHm2DXKEmJSs/vbes9sKXyssyzxzE/NYiOJX5fY0BL28biCre3GqlCqUwyXQ==",
+ "version": "0.29.9",
+ "resolved": "https://registry.npmjs.org/kysely/-/kysely-0.29.9.tgz",
+ "integrity": "sha512-K48ErswC3MlIcBqR0pYIIEl+n9rIgwxgzaM1FxKHMXn7egxr1NHj7bCeF98mXl9A3/QoL5I7mo5S/mLXgeDgGA==",
"license": "MIT",
"engines": {
"node": ">=22.0.0"
@@ -18491,9 +18490,9 @@
}
},
"node_modules/mikro-orm": {
- "version": "7.2.8",
- "resolved": "https://registry.npmjs.org/mikro-orm/-/mikro-orm-7.2.8.tgz",
- "integrity": "sha512-gipORQuQA91QG9BbrATOHg8/JAYdk7wG5lyfW8M8zfq5FHNn3HzHCz6OzcUAEfEXyXT3TSKchZwiyqRPxkYXTA==",
+ "version": "7.2.12",
+ "resolved": "https://registry.npmjs.org/mikro-orm/-/mikro-orm-7.2.12.tgz",
+ "integrity": "sha512-bQS8hTh52AZnoSjFnD23BcMuu1KSGW3u/kTnMpI7ISn0RauzIYA7rxT8BO1tXeokx1W+6cCtFH8pe3JLtfcf0w==",
"license": "MIT",
"engines": {
"node": ">= 22.17.0"
@@ -25555,14 +25554,14 @@
"dependencies": {
"@aws-lite/client": "^0.24.1",
"@aws-lite/s3": "^0.2.7",
- "@mikro-orm/cli": "^7.2.7",
- "@mikro-orm/core": "^7.2.7",
- "@mikro-orm/migrations": "^7.2.7",
+ "@mikro-orm/cli": "^7.2.12",
+ "@mikro-orm/core": "^7.2.12",
+ "@mikro-orm/migrations": "^7.2.12",
"@mikro-orm/nestjs": "^7.1.0",
- "@mikro-orm/postgresql": "^7.2.7",
- "@mikro-orm/seeder": "^7.2.7",
- "@mikro-orm/sql": "^7.2.1",
- "@mikro-orm/sqlite": "^7.2.7",
+ "@mikro-orm/postgresql": "^7.2.12",
+ "@mikro-orm/seeder": "^7.2.12",
+ "@mikro-orm/sql": "^7.2.12",
+ "@mikro-orm/sqlite": "^7.2.12",
"@modelcontextprotocol/sdk": "^1.32.2",
"@nestjs/common": "^11.2.12",
"@nestjs/config": "^4.0.4",
@@ -25576,7 +25575,7 @@
"@trek/shared": "*",
"archiver": "^6.0.2",
"bcryptjs": "^2.4.3",
- "better-sqlite3": "^13.0.3",
+ "better-sqlite3": "^13.2.0",
"compression": "^1.8.2",
"cookie-parser": "^1.4.7",
"cors": "^2.8.6",
@@ -25590,7 +25589,7 @@
"jimp": "^1.7.0",
"json5": "^2.2.3",
"jsonwebtoken": "^9.0.3",
- "kysely": "^0.29.6",
+ "kysely": "^0.29.9",
"mime-types": "^3.0.2",
"multer": "^2.5.0",
"nestjs-zod": "^5.6.0",
@@ -25615,7 +25614,7 @@
"devDependencies": {
"@aws-lite/s3-types": "^0.2.8",
"@eslint/js": "^10.0.1",
- "@mikro-orm/entity-generator": "^7.2.7",
+ "@mikro-orm/entity-generator": "^7.2.12",
"@nestjs/testing": "^11.2.12",
"@swc/core": "^1.16.22",
"@trivago/prettier-plugin-sort-imports": "^6.0.2",
diff --git a/server/package.json b/server/package.json
index 8b04d0517..f98faab15 100644
--- a/server/package.json
+++ b/server/package.json
@@ -65,14 +65,14 @@
"dependencies": {
"@aws-lite/client": "^0.24.1",
"@aws-lite/s3": "^0.2.7",
- "@mikro-orm/cli": "^7.2.7",
- "@mikro-orm/core": "^7.2.7",
- "@mikro-orm/migrations": "^7.2.7",
+ "@mikro-orm/cli": "^7.2.12",
+ "@mikro-orm/core": "^7.2.12",
+ "@mikro-orm/migrations": "^7.2.12",
"@mikro-orm/nestjs": "^7.1.0",
- "@mikro-orm/postgresql": "^7.2.7",
- "@mikro-orm/seeder": "^7.2.7",
- "@mikro-orm/sql": "^7.2.1",
- "@mikro-orm/sqlite": "^7.2.7",
+ "@mikro-orm/postgresql": "^7.2.12",
+ "@mikro-orm/seeder": "^7.2.12",
+ "@mikro-orm/sql": "^7.2.12",
+ "@mikro-orm/sqlite": "^7.2.12",
"@modelcontextprotocol/sdk": "^1.32.2",
"@nestjs/common": "^11.2.12",
"@nestjs/config": "^4.0.4",
@@ -86,7 +86,7 @@
"@trek/shared": "*",
"archiver": "^6.0.2",
"bcryptjs": "^2.4.3",
- "better-sqlite3": "^13.0.3",
+ "better-sqlite3": "^13.2.0",
"compression": "^1.8.2",
"cookie-parser": "^1.4.7",
"cors": "^2.8.6",
@@ -100,7 +100,7 @@
"jimp": "^1.7.0",
"json5": "^2.2.3",
"jsonwebtoken": "^9.0.3",
- "kysely": "^0.29.6",
+ "kysely": "^0.29.9",
"mime-types": "^3.0.2",
"multer": "^2.5.0",
"nestjs-zod": "^5.6.0",
@@ -125,7 +125,7 @@
"devDependencies": {
"@aws-lite/s3-types": "^0.2.8",
"@eslint/js": "^10.0.1",
- "@mikro-orm/entity-generator": "^7.2.7",
+ "@mikro-orm/entity-generator": "^7.2.12",
"@nestjs/testing": "^11.2.12",
"@swc/core": "^1.16.22",
"@trivago/prettier-plugin-sort-imports": "^6.0.2",
diff --git a/server/src/db/repositories/OauthConsents.repository.ts b/server/src/db/repositories/OauthConsents.repository.ts
index fbc908c57..204b955da 100644
--- a/server/src/db/repositories/OauthConsents.repository.ts
+++ b/server/src/db/repositories/OauthConsents.repository.ts
@@ -1,5 +1,6 @@
-import { currentTimestamp } from '../dialect/sql-functions';
+import { currentTimestampKysely } from '../dialect/kysely-functions';
import { OauthConsents } from '../entities/OauthConsents.entity';
+import type { DB } from '../kysely/db';
import { type AssertRowKeys } from './_shared/rows';
import { TrekRepository } from './_shared/trek-repository';
@@ -63,27 +64,17 @@ export class OauthConsentsRepository extends TrekRepository<OauthConsents> {
/**
* `INSERT OR REPLACE INTO oauth_consents (client_id, user_id, scopes,
* updated_at) VALUES (?, ?, ?, CURRENT_TIMESTAMP)` —
- * **security-sensitive** (authorization grant). `em.upsert` with
- * `onConflictFields: ['client', 'user']` (the RELATION properties, not
- * their `persist(false)` mirrors — `Settings.repository.ts::upsertForUser`'s
- * precedent) against the entity's own `uniques: [{ properties: ['client',
- * 'user'] }]` — the natural key the migration's `UNIQUE(client_id,
- * user_id)` declares, verified against the migration before choosing this
- * over a delete+insert fallback (task brief ruling).
+ * **security-sensitive** (authorization grant). Written with Kysely's
+ * `onConflict` on the migration's `UNIQUE(client_id, user_id)`, so the
+ * client goes in as the `client_id` column value it is. `em.upsert` would
+ * read it through the `client` relation, which points at
+ * `oauth_clients.client_id` rather than the primary key: MikroORM takes a
+ * bare value there for the target's primary key, and the referenced value
+ * as a plain object for the data of a new `OauthClients` entity.
*
- * `updated_at` is explicit in the payload, not left to the column's
- * `defaultRaw('CURRENT_TIMESTAMP')`: a default only fires on INSERT, and
- * `em.upsert`'s `'merge'` action updates ONLY the fields present in the
- * payload on a conflict (verified against the installed 7.2.1 behaviour
- * and the MikroORM docs: "values generated by property `onCreate` hooks…
- * are automatically excluded from the merge clause") — the legacy
- * statement's `INSERT OR REPLACE` always re-writes `updated_at` to
- * `CURRENT_TIMESTAMP` regardless of whether the row existed (SQLite's
- * `OR REPLACE` deletes-then-inserts, so there is no "update" branch to
- * distinguish), so this repository stamps it explicitly on every call
- * through `currentTimestamp(platform)`, matching that unconditional
- * behaviour rather than relying on a default that would only cover the
- * insert half.
+ * `updated_at` is stamped on every call, on the insert and on the update
+ * half alike: the legacy `INSERT OR REPLACE` always rewrote it, and a
+ * column default would only cover the insert.
*
* Named `upsertGrant`, not `upsert` — `EntityRepository#upsert` already
* exists with an incompatible signature (`(entityOrData, options) =>
@@ -91,20 +82,22 @@ export class OauthConsentsRepository extends TrekRepository<OauthConsents> {
* hide the base method, the same collision `Users.repository.ts::insertUser`
* avoided with `create`.
*
- * One more divergence from the legacy statement (Task 7 review, B-I1),
+ * One divergence from the legacy statement (Task 7 review, B-I1),
* unobservable and strictly better: the legacy `INSERT OR REPLACE`
* deletes-then-inserts, so a re-consent always assigned a NEW surrogate
- * `id`; `em.upsert` with `onConflictAction: 'merge'` keeps the existing
- * one. `oauth_consents` has only `id`/`client_id`/`user_id`/`scopes`/
- * `updated_at` and nothing reads `id`, so this is unobservable — and it
- * avoids the FK churn a delete+insert would otherwise cause if anything
- * ever did reference this row's surrogate key.
+ * `id`; the update on conflict keeps the existing one. `oauth_consents` has
+ * only `id`/`client_id`/`user_id`/`scopes`/`updated_at` and nothing reads
+ * `id`, so this is unobservable, and it avoids the FK churn a
+ * delete+insert would cause if anything ever referenced this row's
+ * surrogate key.
*/
async upsertGrant(clientId: string, userId: number, scopes: string): Promise<void> {
const platform = this.getEntityManager().getPlatform();
- await this.upsert(
- { client: clientId, user: userId, scopes, updated_at: currentTimestamp(platform) },
- { onConflictFields: ['client', 'user'], onConflictAction: 'merge' },
- );
+ const now = currentTimestampKysely(platform);
+ await this.kysely<Pick<DB, 'oauth_consents'>>()
+ .insertInto('oauth_consents')
+ .values({ client_id: clientId, user_id: userId, scopes, updated_at: now })
+ .onConflict((oc) => oc.columns(['client_id', 'user_id']).doUpdateSet({ scopes, updated_at: now }))
+ .execute();
}
}
diff --git a/server/src/db/repositories/OauthTokens.repository.ts b/server/src/db/repositories/OauthTokens.repository.ts
index eac360f45..382f8cb64 100644
--- a/server/src/db/repositories/OauthTokens.repository.ts
+++ b/server/src/db/repositories/OauthTokens.repository.ts
@@ -2,6 +2,7 @@ import { columnRef, currentTimestamp } from '../dialect/sql-functions';
import { OauthTokens } from '../entities/OauthTokens.entity';
import type { DB } from '../kysely/db';
import type { DbTimestamp } from '../types';
+import { oauthClientRef } from './_shared/oauth-client-ref';
import { type AssertRowKeys } from './_shared/rows';
import { TrekRepository } from './_shared/trek-repository';
@@ -178,7 +179,7 @@ export class OauthTokensRepository extends TrekRepository<OauthTokens> {
*/
async insertToken(row: NewOauthTokenRow): Promise<void> {
await this.insert({
- client: row.client_id,
+ client: oauthClientRef(row.client_id),
user: row.user_id,
access_token_hash: row.access_token_hash,
refresh_token_hash: row.refresh_token_hash,
diff --git a/server/src/db/repositories/_shared/oauth-client-ref.ts b/server/src/db/repositories/_shared/oauth-client-ref.ts
new file mode 100644
index 000000000..2bf9df89b
--- /dev/null
+++ b/server/src/db/repositories/_shared/oauth-client-ref.ts
@@ -0,0 +1,21 @@
+import type { OauthClients } from '../../entities/OauthClients.entity';
+import type { Ref } from '@mikro-orm/core';
+
+/**
+ * The value an `oauth_tokens` or `oauth_consents` row writes for its `client`
+ * relation, from the client's public `client_id`.
+ *
+ * That relation points at `oauth_clients.client_id`, the unique natural key,
+ * not at the primary key `id` (`referencedColumnNames('client_id')` in both
+ * entities). Given a bare string, MikroORM reads it as the target's primary key
+ * and refuses the write, because it cannot know the `client_id` of that row
+ * without loading it. Given the referenced property itself, it writes that
+ * value to the column as it is.
+ *
+ * The typings only know a relation as an entity, a reference or a primary key,
+ * so the plain object is handed over as the reference it stands for.
+ */
+export function oauthClientRef(clientId: string): Ref<OauthClients> {
+ const referenced: Pick<OauthClients, 'client_id'> = { client_id: clientId };
+ return referenced as unknown as Ref<OauthClients>;
+}
diff --git a/server/tests/integration/admin.test.ts b/server/tests/integration/admin.test.ts
index 8ab79fa6f..68de41656 100644
--- a/server/tests/integration/admin.test.ts
+++ b/server/tests/integration/admin.test.ts
@@ -37,6 +37,7 @@ import { VacayPlanMembers } from '../../src/db/entities/VacayPlanMembers.entity'
import { VacayPlans } from '../../src/db/entities/VacayPlans.entity';
import { VisitedCountries } from '../../src/db/entities/VisitedCountries.entity';
import { VisitedRegions } from '../../src/db/entities/VisitedRegions.entity';
+import { oauthClientRef } from '../../src/db/repositories/_shared/oauth-client-ref';
import { dbNow } from '../../src/db/types/db-timestamp.type';
import { authCookie } from '../helpers/auth';
import { makeBucketListItem, markCountryVisited } from '../helpers/factories/atlas';
@@ -278,14 +279,14 @@ describe('Admin user management', () => {
client_secret_hash: 'h',
});
await insertRow(orm, OauthTokens, {
- client: 'cid-admin-test',
+ client: oauthClientRef('cid-admin-test'),
user: target.id,
access_token_hash: 'ath-admin',
refresh_token_hash: 'rth-admin',
access_token_expires_at: dbNow(new Date(Date.now() + 60 * 60 * 1000)),
refresh_token_expires_at: dbNow(new Date(Date.now() + 30 * 24 * 60 * 60 * 1000)),
});
- await insertRow(orm, OauthConsents, { client: 'cid-admin-test', user: target.id });
+ await insertRow(orm, OauthConsents, { client: oauthClientRef('cid-admin-test'), user: target.id });
// vacay_plans.owner_id (CASCADE): target owns a vacation plan
const vacayPlanId = (await makeVacayPlan(orm, target.id)).id;
diff --git a/server/tests/integration/auth.test.ts b/server/tests/integration/auth.test.ts
index 7c02caef4..a3d1541a2 100644
--- a/server/tests/integration/auth.test.ts
+++ b/server/tests/integration/auth.test.ts
@@ -39,6 +39,7 @@ import { VacayPlanMembers } from '../../src/db/entities/VacayPlanMembers.entity'
import { VacayPlans } from '../../src/db/entities/VacayPlans.entity';
import { VisitedCountries } from '../../src/db/entities/VisitedCountries.entity';
import { VisitedRegions } from '../../src/db/entities/VisitedRegions.entity';
+import { oauthClientRef } from '../../src/db/repositories/_shared/oauth-client-ref';
import { dbNow } from '../../src/db/types';
import { authCookie, authHeader } from '../helpers/auth';
import { makeBucketListItem, markCountryVisited } from '../helpers/factories/atlas';
@@ -810,14 +811,14 @@ describe('Account deletion', () => {
client_secret_hash: 'h',
});
await insertRow(orm, OauthTokens, {
- client: 'cid-auth-test',
+ client: oauthClientRef('cid-auth-test'),
user: target.id,
access_token_hash: 'ath-auth',
refresh_token_hash: 'rth-auth',
access_token_expires_at: dbNow(new Date(Date.now() + 3600_000)),
refresh_token_expires_at: dbNow(new Date(Date.now() + 30 * 86_400_000)),
});
- await insertRow(orm, OauthConsents, { client: 'cid-auth-test', user: target.id });
+ await insertRow(orm, OauthConsents, { client: oauthClientRef('cid-auth-test'), user: target.id });
// vacay_plans.owner_id (CASCADE): target owns a vacation plan
const vacayPlanId = await insertRow(orm, VacayPlans, { owner: target.id });
diff --git a/server/tests/unit/db/repositories/OauthClients.repository.test.ts b/server/tests/unit/db/repositories/OauthClients.repository.test.ts
index 82e495b26..27c4476d8 100644
--- a/server/tests/unit/db/repositories/OauthClients.repository.test.ts
+++ b/server/tests/unit/db/repositories/OauthClients.repository.test.ts
@@ -2,6 +2,7 @@ import { SqliteEngine } from '../../../../src/db/engine/sqlite/sqlite-engine';
import { OauthClients } from '../../../../src/db/entities/OauthClients.entity';
import { OauthTokens } from '../../../../src/db/entities/OauthTokens.entity';
import type { OauthClientsRepository } from '../../../../src/db/repositories/OauthClients.repository';
+import { oauthClientRef } from '../../../../src/db/repositories/_shared/oauth-client-ref';
import { dbNow } from '../../../../src/db/types';
import { withRequestContext } from '../../../../src/nest/database/request-context';
import { UnitOfWork } from '../../../../src/nest/database/unit-of-work';
@@ -351,7 +352,7 @@ describe('OauthClientsRepository', () => {
async function holdToken(clientId: string): Promise<void> {
const { user } = createUser(testDb);
await insertRow(t, OauthTokens, {
- client: clientId,
+ client: oauthClientRef(clientId),
user: user.id,
access_token_hash: `acc-${clientId}`,
refresh_token_hash: `ref-${clientId}`,
diff --git a/server/tests/unit/db/repositories/OauthConsents.repository.test.ts b/server/tests/unit/db/repositories/OauthConsents.repository.test.ts
index 792574db2..fd2f814d7 100644
--- a/server/tests/unit/db/repositories/OauthConsents.repository.test.ts
+++ b/server/tests/unit/db/repositories/OauthConsents.repository.test.ts
@@ -2,6 +2,7 @@ import { SqliteEngine } from '../../../../src/db/engine/sqlite/sqlite-engine';
import { OauthClients } from '../../../../src/db/entities/OauthClients.entity';
import { OauthConsents } from '../../../../src/db/entities/OauthConsents.entity';
import type { OauthConsentsRepository } from '../../../../src/db/repositories/OauthConsents.repository';
+import { oauthClientRef } from '../../../../src/db/repositories/_shared/oauth-client-ref';
import { withRequestContext } from '../../../../src/nest/database/request-context';
import { UnitOfWork } from '../../../../src/nest/database/unit-of-work';
import { createSnapshotTestDb } from '../../../helpers/db-mock';
@@ -61,7 +62,7 @@ describe('OauthConsentsRepository', () => {
it('OAUTHCONSENTREPO-002: returns the stored scopes JSON text', async () => {
const { user } = createUser(testDb);
await seedClient(user.id, 'proto-2');
- await insertRow(t, OauthConsents, { client: 'proto-2', user: user.id, scopes: '["trips:read"]' });
+ await insertRow(t, OauthConsents, { client: oauthClientRef('proto-2'), user: user.id, scopes: '["trips:read"]' });
expect(await consents.findScopes('proto-2', user.id)).toEqual({ scopes: '["trips:read"]' });
});
});
@@ -127,7 +128,7 @@ describe('OauthConsentsRepository', () => {
it("OAUTHCONSENTREPO-007: findScopes then a raw write on the same transaction connection — the raw write survives the transaction's closing flush", async () => {
const { user } = createUser(testDb);
await seedClient(user.id, 'proto-7');
- await insertRow(t, OauthConsents, { client: 'proto-7', user: user.id, scopes: '["a"]' });
+ await insertRow(t, OauthConsents, { client: oauthClientRef('proto-7'), user: user.id, scopes: '["a"]' });
await withRequestContext(t.orm, async () => {
await uow.transactional(async () => {
diff --git a/server/tests/unit/db/repositories/OauthTokens.repository.test.ts b/server/tests/unit/db/repositories/OauthTokens.repository.test.ts
index 545705e23..04f900890 100644
--- a/server/tests/unit/db/repositories/OauthTokens.repository.test.ts
+++ b/server/tests/unit/db/repositories/OauthTokens.repository.test.ts
@@ -3,6 +3,7 @@ import { OauthClients } from '../../../../src/db/entities/OauthClients.entity';
import { OauthConsents } from '../../../../src/db/entities/OauthConsents.entity';
import { OauthTokens } from '../../../../src/db/entities/OauthTokens.entity';
import type { OauthTokensRepository } from '../../../../src/db/repositories/OauthTokens.repository';
+import { oauthClientRef } from '../../../../src/db/repositories/_shared/oauth-client-ref';
import { dbNow } from '../../../../src/db/types';
import { withRequestContext } from '../../../../src/nest/database/request-context';
import { UnitOfWork } from '../../../../src/nest/database/unit-of-work';
@@ -75,7 +76,7 @@ async function seedToken(
}> = {},
): Promise<number> {
const id = await insertRow(t, OauthTokens, {
- client: overrides.clientId as string,
+ client: oauthClientRef(overrides.clientId as string),
user: overrides.userId as number,
access_token_hash: overrides.accessHash ?? `acc-${Math.random().toString(36).slice(2)}`,
refresh_token_hash: overrides.refreshHash ?? `ref-${Math.random().toString(36).slice(2)}`,
diff --git a/server/tests/unit/nest/oauth.service.test.ts b/server/tests/unit/nest/oauth.service.test.ts
index c7fb0b4f8..b69d98aaa 100644
--- a/server/tests/unit/nest/oauth.service.test.ts
+++ b/server/tests/unit/nest/oauth.service.test.ts
@@ -22,6 +22,7 @@ import type { OauthClientsRepository } from '../../../src/db/repositories/OauthC
import type { OauthConsentsRepository } from '../../../src/db/repositories/OauthConsents.repository';
import type { OauthTokensRepository } from '../../../src/db/repositories/OauthTokens.repository';
import type { UsersRepository } from '../../../src/db/repositories/Users.repository';
+import { oauthClientRef } from '../../../src/db/repositories/_shared/oauth-client-ref';
import { dbNow } from '../../../src/db/types';
import { revokeUserSessionsForClient } from '../../../src/mcp/sessionManager';
import type { AddonsService } from '../../../src/nest/addons/addons.service';
@@ -1646,7 +1647,7 @@ describe('admin OAuth sessions', () => {
const { user } = createUser(testDb);
await insertRow(t, OauthClients, { client_id: 'c1', client_secret_hash: 'hash', name: 'Client' });
await insertRow(t, OauthTokens, {
- client: 'c1',
+ client: oauthClientRef('c1'),
user: user.id,
access_token_hash: 'ahash',
refresh_token_hash: 'rhash',