From 97f5a6bad6aa204d7925b71c9a3ba31b7732c3b3 Mon Sep 17 00:00:00 2001 From: le king fu Date: Mon, 19 Oct 2026 22:11:49 -0400 Subject: [PATCH 1/4] fix(security): whitelist sync data columns and check ownership of references POST /api/sync copied the client's `data` into `.set()` for list, task and tag updates, so an authenticated client could rewrite `userId` (moving its rows into another account), `id`, `createdAt` or `deletedAt`. Task-tag links, task `listId`/`parentId` and list creation did not check that the referenced rows belong to the caller. - web/src/lib/syncData.ts: one zod schema per entity and action. Unknown keys are stripped rather than rejected, because the app marks its outbox as synced on HTTP 200 and a skipped operation would be lost. Strings are truncated to the mobile limits (notes 10000). Null maps to undefined for NOT NULL columns. - processOperation writes only the parsed output; taskTag create and delete verify the task and the tag; task create/update verify listId; parentId and list create ids are refused when taken by another account (a missing parent passes, since initialMerge can push a subtask before its parent). - vitest 4.1 (vitest 5 requires @types/node >= 22, web is on 20) with tests built from the payloads the app sends today. - REVIEW.md: rules and pitfall updated, npm test added, syncData.ts in the Haut table (review-levels.py --check passes). Refs #142 Co-Authored-By: Claude Opus 5.5 --- REVIEW.md | 10 +- scripts/review-levels.py | 2 +- web/package-lock.json | 1564 ++++++++++++++++++++++++++++++++- web/package.json | 6 +- web/src/app/api/sync/route.ts | 95 +- web/src/lib/syncData.test.ts | 188 ++++ web/src/lib/syncData.ts | 76 ++ 7 files changed, 1883 insertions(+), 58 deletions(-) create mode 100644 web/src/lib/syncData.test.ts create mode 100644 web/src/lib/syncData.ts diff --git a/REVIEW.md b/REVIEW.md index ef78214..183d7ac 100644 --- a/REVIEW.md +++ b/REVIEW.md @@ -27,7 +27,7 @@ Motifs : chemins depuis la racine. `*` ne traverse jamais un `/` ; `**/` vaut z | Motif | Condition | Zone | |---|---|---| | `src/lib/{authToken,logtoConfig,validation}.ts`, `web/src/lib/{auth,logto,api}.ts`, `web/src/middleware.ts`, `web/src/app/api/logto/**`, `web/src/app/auth/**` | toujours | Authentification | -| `web/src/app/api/**`, `web/src/lib/{validators,rateLimit,ws}.ts`, `web/server.ts` | toujours | API et isolation des comptes | +| `web/src/app/api/**`, `web/src/lib/{validators,syncData,rateLimit,ws}.ts`, `web/server.ts` | toujours | API et isolation des comptes | | `src/services/syncClient.ts`, `src/db/repository/outbox.ts` | toujours | Sync | | `src/db/{schema,client}.ts`, `src/db/migrations/**`, `web/src/db/{schema,client,seed}.ts`, `web/src/db/migrations/**`, `drizzle.config.ts`, `web/drizzle.config.ts`, `sql-transformer.js` | toujours | Migrations et données | | `app/_layout.tsx` | le diff touche les migrations (`useMigrations`), `LogtoProvider`, le jeton (`setTokenGetter`) ou les appels de sync (`fullSync`, `cleanOutbox`) | Migrations et données, Authentification, Sync | @@ -90,7 +90,8 @@ Chaque règle cite sa source. Elles valent quel que soit le niveau : une PR norm ### API et isolation des comptes - Toute lecture et toute écriture filtrent sur `userId = auth.userId` ; une mise à jour ou une suppression vérifie d'abord la propriété (`verifyOwnership`). Une jointure (étiquettes d'une tâche) vérifie la propriété des deux côtés. — `web/src/app/api/sync/route.ts`, `web/src/app/api/tasks/[id]/route.ts` -- Le corps est validé par un schéma zod `.strict()`. `data` d'une opération de sync est un `z.record(z.unknown())` : une route ne le recopie jamais tel quel dans un `.set()` ou un `.values()`, elle choisit ses colonnes, sans quoi un client peut écrire `userId` ou `id`. — `web/src/lib/validators.ts`, `web/src/app/api/sync/route.ts` +- Le corps est validé par un schéma zod `.strict()`. Exception : `data` d'une opération de sync passe par un schéma par entité et par action (`web/src/lib/syncData.ts`), sans `.strict()` : les clés hors liste sont retirées, pas rejetées, parce que l'app marque son outbox comme synchronisée dès que le push répond 200 et qu'une opération `skipped` serait perdue. Ces schémas ne nomment jamais `id`, `userId`, `createdAt`, `updatedAt` ni `deletedAt`, et `processOperation` n'écrit que leur sortie. Une colonne ajoutée côté app l'est aussi dans le schéma, sinon elle est ignorée en silence. — `web/src/lib/syncData.ts`, `web/src/app/api/sync/route.ts`, #142 +- Une référence reçue du client (`listId`, `parentId`, `tagId`, l'id d'une liste créée) est vérifiée contre le compte de l'appelant avant l'écriture. `parentId` et l'id d'une création refusent seulement un id pris par un autre compte, sans exiger que la ligne existe : `initialMerge` pousse tout en un lot, une sous-tâche peut arriver avant son parent. — `web/src/app/api/sync/route.ts`, #142 - Limites de débit par utilisateur et par catégorie (`sync`, `create`, `read`, `ws-ticket`) ; une route ajoutée en prend une. Le store est en mémoire : il repart à zéro à chaque redémarrage. — `web/src/lib/rateLimit.ts` - WebSocket : ticket à usage unique de 30 s, origines autorisées listées, revalidation toutes les 15 min ; aucun paramètre de requête de `/ws` n'est journalisé. — `web/src/lib/ws.ts`, `web/src/app/api/ws-ticket/route.ts`, `web/server.ts` - Une route de diagnostic (`/api/debug`) ne renvoie que les données de la session qui l'appelle, jamais de secret ni de valeur de cookie. — `web/src/app/api/debug/route.ts` @@ -165,20 +166,21 @@ Companion web, depuis `web/` : ```bash npm ci +npm test # vitest : schémas de données de sync (web/src/lib/syncData.test.ts) npx tsc --noEmit npm run lint npm run build ``` - Comparer deux exports : `(cd && find . -type f | sort | xargs sha256sum)` sur l'arbre de base deux fois (déterminisme), puis sur la PR ; même nombre de fichiers et mêmes empreintes, ou une différence expliquée. -- Un `npm test` ne compte qu'après une sonde : une vérification volontairement rouge doit le faire sortir en code non nul (`smoke FAIL`, sortie 1). +- Un `npm test` ne compte qu'après une sonde : une vérification volontairement rouge doit le faire sortir en code non nul (`smoke FAIL`, sortie 1 ; côté `web/`, une assertion de vitest volontairement fausse, sortie 1). - Ce que ces commandes ne prouvent pas : le comportement sur un appareil (widget, notifications, connexion Logto, sync réelle), qui se teste sur un build de développement ; le site déployé, qui se vérifie après le déploiement manuel. ## Pièges de revue - **Tests verts, build cassé.** Le smoke test ne charge ni Babel ni Metro : seul l'export Expo prouve le bundle (PR #118). — `STATE.md` (2026-09-25) - **Le Bearer ouvre le middleware.** Une route d'API qui oublie `requireAuth()` n'est pas protégée par le middleware dès que la requête porte un `Bearer`, même invalide. Lire le début de chaque route ajoutée. — `web/src/middleware.ts` -- **`...data` dans un `.set()`.** Le code de sync recopie aujourd'hui `data` dans les mises à jour de listes, de tâches et d'étiquettes, et le lien tâche-étiquette ne vérifie la propriété ni de la tâche ni de l'étiquette : une PR qui touche `processOperation` ne doit pas étendre ce motif. Correctif suivi dans #142. — `web/src/app/api/sync/route.ts`, #142 +- **`...data` dans un `.set()`.** Jusqu'à #142, le code de sync recopiait `data` dans les mises à jour, et un client pouvait écrire `userId`. Une PR qui touche `processOperation` passe `data` par un schéma de `syncData.ts` avant tout `.set()` ou `.values()`, et un `...d` n'y est acceptable que sur la sortie d'un de ces schémas. — `web/src/app/api/sync/route.ts`, #142 - **Le serveur n'a pas d'`updatedAt` sur les étiquettes.** `createdAt` sert de date de changement au pull : une étiquette renommée n'est pas renvoyée à l'app. — revue de la PR #58, `web/src/app/api/sync/route.ts` - **Polling, pas de requêtes vivantes.** Les écrans relisent SQLite toutes les 500 ms ; un état global de tâches ajouté contourne cette convention. — `CLAUDE.md` « Conventions » - **Widget headless.** `widgetState.ts` reste léger (pas de DB, de drizzle ni de date-fns), le smoke test verrouille son graphe d'import ; un import ajouté rallonge le cold start de chaque tap. — `CLAUDE.md` « Widget Android » diff --git a/scripts/review-levels.py b/scripts/review-levels.py index 35ca906..2845cd2 100755 --- a/scripts/review-levels.py +++ b/scripts/review-levels.py @@ -39,7 +39,7 @@ HIGH_ALWAYS = [ "src/lib/{authToken,logtoConfig,validation}.ts", "web/src/lib/{auth,logto,api}.ts", "web/src/middleware.ts", "web/src/app/api/logto/**", "web/src/app/auth/**", - "web/src/app/api/**", "web/src/lib/{validators,rateLimit,ws}.ts", "web/server.ts", + "web/src/app/api/**", "web/src/lib/{validators,syncData,rateLimit,ws}.ts", "web/server.ts", "src/services/syncClient.ts", "src/db/repository/outbox.ts", "src/db/{schema,client}.ts", "src/db/migrations/**", "web/src/db/{schema,client,seed}.ts", "web/src/db/migrations/**", diff --git a/web/package-lock.json b/web/package-lock.json index 7b42fca..afa7702 100644 --- a/web/package-lock.json +++ b/web/package-lock.json @@ -33,7 +33,8 @@ "eslint": "^9", "eslint-config-next": "16.2.2", "tailwindcss": "^4", - "typescript": "^5" + "typescript": "^5", + "vitest": "^4.1.12" } }, "node_modules/@alloc/quick-lru": { @@ -2189,6 +2190,278 @@ "node": ">=12.4.0" } }, + "node_modules/@oxc-project/types": { + "version": "0.154.0", + "resolved": "https://registry.npmjs.org/@oxc-project/types/-/types-0.154.0.tgz", + "integrity": "sha512-KYOUGQFlLWR+s4QMV2Q9ko38TZm7EdO87Qm7rvZLqk/webse/cDjtyxKhg/47l0byCbs/k46LT8qc4PKjAikzA==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/oxc-project" + } + }, + "node_modules/@rolldown/binding-android-arm-eabi": { + "version": "1.2.14", + "resolved": "https://registry.npmjs.org/@rolldown/binding-android-arm-eabi/-/binding-android-arm-eabi-1.2.14.tgz", + "integrity": "sha512-aWR+XKH9+rW7m5fWq/5360J3mHycrx/o6xZM2DQFdJnTMdyP7/WzxPjhtLbVWdKo2y612/4U1bWqb3HQhiF7vg==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-android-arm64": { + "version": "1.2.14", + "resolved": "https://registry.npmjs.org/@rolldown/binding-android-arm64/-/binding-android-arm64-1.2.14.tgz", + "integrity": "sha512-QiVxHofl6A8lQU7WAtOUY4QMVZXohxwz7WJJoeh8NBEUyKfIkMRKhYyq8az/1RypNiIXzNTtiS6KwHz0erxYRQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-darwin-arm64": { + "version": "1.2.14", + "resolved": "https://registry.npmjs.org/@rolldown/binding-darwin-arm64/-/binding-darwin-arm64-1.2.14.tgz", + "integrity": "sha512-lTQOzHuBIooh3jIr5XINQkjPGEuGy+Dsy0meXDr6Sjty0b99kYgGh4uBC/8mJX1T0kC8d6S0aPP1Y+bHkh6aBw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-darwin-x64": { + "version": "1.2.14", + "resolved": "https://registry.npmjs.org/@rolldown/binding-darwin-x64/-/binding-darwin-x64-1.2.14.tgz", + "integrity": "sha512-hyMKEGatjmBYCs/Q4sbIcL/GqpFEqsX3wc+HYVQ/85A4rxc1o7rPm4DUI4GV4k/h0ITddwFSGpqQunI14GXjTA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-freebsd-x64": { + "version": "1.2.14", + "resolved": "https://registry.npmjs.org/@rolldown/binding-freebsd-x64/-/binding-freebsd-x64-1.2.14.tgz", + "integrity": "sha512-u371GbXoVXrEgP20PwzoGNOdAOqAMhzo19JzzY+V4YmmnC+DTOoqdbMu+O+54emM59Mik/UdrtWgcuEDKWRPKA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-arm-gnueabihf": { + "version": "1.2.14", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm-gnueabihf/-/binding-linux-arm-gnueabihf-1.2.14.tgz", + "integrity": "sha512-BqwKsdZQf6EqVWr8fv2MrDYzAvOZ7+NYFSJESRGs87fkseEhs0TU9TXgRJTkZoRRkxTizyEg1LKUXfU3/78uqg==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-arm64-gnu": { + "version": "1.2.14", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm64-gnu/-/binding-linux-arm64-gnu-1.2.14.tgz", + "integrity": "sha512-SD9kY8M009x/7s57Z1dgUVlP5+uYBgKQK0Tkr1WIWngrtUJmRCW1RJFMY7QDla2khXhmg2i5Io7MUjcmZNZ/KQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-arm64-musl": { + "version": "1.2.14", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm64-musl/-/binding-linux-arm64-musl-1.2.14.tgz", + "integrity": "sha512-BJ2CL19M6uuWesMgnqJzgxoI+N+eV7b0A9O9vLV42y+gitC41fNa8KElau1tHVzuLWX5GzEuxMPhAO0tQXQMkg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-ppc64-gnu": { + "version": "1.2.14", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-ppc64-gnu/-/binding-linux-ppc64-gnu-1.2.14.tgz", + "integrity": "sha512-4+Kl8daPV8NDHaD7mfCcc1pRM+Qg7ab8DyMm5FG5WoZgv4h2i3KFN1CybYBNbQqmuYm7ftJLvmMI1eHYJ22S/Q==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-s390x-gnu": { + "version": "1.2.14", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-s390x-gnu/-/binding-linux-s390x-gnu-1.2.14.tgz", + "integrity": "sha512-V/h8ePq1fKDrmtFMz6xcCN3DKvuvMRrwwD1q0PkBeeo4DpK64biaKvqWGVxqCeYKqeRk7gE7/iKPxLCn08O97A==", + "cpu": [ + "s390x" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-x64-gnu": { + "version": "1.2.14", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-x64-gnu/-/binding-linux-x64-gnu-1.2.14.tgz", + "integrity": "sha512-WxalXzgrLVpKC93xfpaJ3gCXUWzeCr+FRCbDVD2mUAy4L6Vo3lNVz0epUEUpxPWJkLNYUwM4OSIikv36OJ9mLg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-x64-musl": { + "version": "1.2.14", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-x64-musl/-/binding-linux-x64-musl-1.2.14.tgz", + "integrity": "sha512-3G3tnAmTpdk9jO3GQtyHXqeFD2SlecfTws/Y3M2mmj9nMBwwuLT4kur8sZKeu7ENUHSpVO3cIsm5A52LEWWwlg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-openharmony-arm64": { + "version": "1.2.14", + "resolved": "https://registry.npmjs.org/@rolldown/binding-openharmony-arm64/-/binding-openharmony-arm64-1.2.14.tgz", + "integrity": "sha512-qyr5XiNGxm2ytx17vvtcJ9nXn6v1gENETi503bJx3OGwZ1tSonj7BosxbMa/xeAfSl5iS9X6KjEWYXLu6v1L7Q==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openharmony" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-win32-arm64-msvc": { + "version": "1.2.14", + "resolved": "https://registry.npmjs.org/@rolldown/binding-win32-arm64-msvc/-/binding-win32-arm64-msvc-1.2.14.tgz", + "integrity": "sha512-oA4o5o0S2yB199YyYXDzKUv1Z56Rc+mgOjwm7Z/vJ9Z8igiDPYvoOuDyo6g7AK/ZaF09nPhDKVnGBcYHO11GXA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-win32-x64-msvc": { + "version": "1.2.14", + "resolved": "https://registry.npmjs.org/@rolldown/binding-win32-x64-msvc/-/binding-win32-x64-msvc-1.2.14.tgz", + "integrity": "sha512-9mE94bf2GZUaR/fUSXCMpBoWkctu421Mi0ORpm4zqfbkjKep7RxzPFa5etcGs5h+2KApoWBOA/hAJa/7saGgEQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/pluginutils": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@rolldown/pluginutils/-/pluginutils-1.0.1.tgz", + "integrity": "sha512-2j9bGt5Jh8hj+vPtgzPtl72j0yRxHAyumoo6TNfAjsLB04UtpSvPbPcDcBMxz7n+9CYB0c1GxQFxYRg2jimqGw==", + "dev": true, + "license": "MIT" + }, "node_modules/@rtsao/scc": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@rtsao/scc/-/scc-1.1.0.tgz", @@ -2206,6 +2479,13 @@ "pnpm": "^10.0.0" } }, + "node_modules/@standard-schema/spec": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@standard-schema/spec/-/spec-1.1.0.tgz", + "integrity": "sha512-l2aFy5jALhniG5HgqrD6jXLi/rUWrKvqN/qJx6yoJsgKhblVd+iqqU4RCXavm/jPityDo5TCvKMnpjKnOriy0w==", + "dev": true, + "license": "MIT" + }, "node_modules/@swc/helpers": { "version": "0.5.15", "resolved": "https://registry.npmjs.org/@swc/helpers/-/helpers-0.5.15.tgz", @@ -2497,6 +2777,24 @@ "tslib": "^2.4.0" } }, + "node_modules/@types/chai": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/@types/chai/-/chai-5.2.3.tgz", + "integrity": "sha512-Mw558oeA9fFbv65/y4mHtXDs9bPnFMZAL/jxdPFUpOHHIXX91mcgEHbS5Lahr+pwZFR8A7GQleRWeI6cGFC2UA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/deep-eql": "*", + "assertion-error": "^2.0.1" + } + }, + "node_modules/@types/deep-eql": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/@types/deep-eql/-/deep-eql-4.0.2.tgz", + "integrity": "sha512-c9h9dVVMigMPc4bwTvC5dxqtqJZwQPePsWjPlpSOnojbor6pGqdk541lfA7AqFQr5pB1BRdq0juY9db81BwyFw==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/estree": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.8.tgz", @@ -3132,6 +3430,92 @@ "win32" ] }, + "node_modules/@vitest/expect": { + "version": "4.1.12", + "resolved": "https://registry.npmjs.org/@vitest/expect/-/expect-4.1.12.tgz", + "integrity": "sha512-vFlTt+YEu9WBpNjdGayNmlMVzrWPi1+sv853/7t2FU7hpO5gAFBKHzQmkCq5Xjpr+evegF2994LQT3hF3mRlqQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@standard-schema/spec": "^1.1.0", + "@types/chai": "^5.2.2", + "@vitest/spy": "4.1.12", + "@vitest/utils": "4.1.12", + "chai": "^6.2.2", + "tinyrainbow": "^3.1.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/pretty-format": { + "version": "4.1.12", + "resolved": "https://registry.npmjs.org/@vitest/pretty-format/-/pretty-format-4.1.12.tgz", + "integrity": "sha512-XW9O8+Mxx4VpCtkYdMJLZQQwsVryP9wk7cPKDxtXFfwSak6yRh5+2fep/Y0XF/ElBvJHq8bcYdi6aeuai0opZA==", + "dev": true, + "license": "MIT", + "dependencies": { + "tinyrainbow": "^3.1.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/runner": { + "version": "4.1.12", + "resolved": "https://registry.npmjs.org/@vitest/runner/-/runner-4.1.12.tgz", + "integrity": "sha512-NKlVKCr5QnCe8jijdMnmkpHHU+WTqiLFR6G0pHji9uRjXK9xJl1k1nTw6F3pOOj2PDcsDt2GKQMI7wIsaT491w==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vitest/utils": "4.1.12", + "pathe": "^2.0.3" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/snapshot": { + "version": "4.1.12", + "resolved": "https://registry.npmjs.org/@vitest/snapshot/-/snapshot-4.1.12.tgz", + "integrity": "sha512-ko1y1Qgb/slzQ9mr+b89Cuqud8WG1TKtsPD8r7ZUBdvVOGt85Af2HwCqHujrhwJq95hs/9RM7fcAPg57o1vlzw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vitest/pretty-format": "4.1.12", + "@vitest/utils": "4.1.12", + "magic-string": "^0.30.21", + "pathe": "^2.0.3" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/spy": { + "version": "4.1.12", + "resolved": "https://registry.npmjs.org/@vitest/spy/-/spy-4.1.12.tgz", + "integrity": "sha512-RGq9x4JNGNTZHEJxvN0oSiJjeSCExm0n2gZKKJZHY9cX5AVA6M7VJILBT3ZJ/tJ/0J9uWT7fETV9/btoi//vSg==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/utils": { + "version": "4.1.12", + "resolved": "https://registry.npmjs.org/@vitest/utils/-/utils-4.1.12.tgz", + "integrity": "sha512-Q3awXrwOfEV+qc3WmO5ONyE0yO7Q1gQ9/oyHxGLZ/pl7N3NO/ZztqQwKLuwMkV+CA1JYSIeO3gkHnRDIo4AVaA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vitest/pretty-format": "4.1.12", + "convert-source-map": "^2.0.0", + "tinyrainbow": "^3.1.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, "node_modules/acorn": { "version": "8.16.0", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.16.0.tgz", @@ -3365,6 +3749,16 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/assertion-error": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-2.0.1.tgz", + "integrity": "sha512-Izi8RQcffqCeNVgFigKli1ssklIbpHnCYc6AknXGYoB6grJqyeby7jv12JUQgmTAnIDnbck1uxksT4dzN3PWBA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + } + }, "node_modules/ast-types-flow": { "version": "0.0.8", "resolved": "https://registry.npmjs.org/ast-types-flow/-/ast-types-flow-0.0.8.tgz", @@ -3612,6 +4006,16 @@ ], "license": "CC-BY-4.0" }, + "node_modules/chai": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/chai/-/chai-6.3.0.tgz", + "integrity": "sha512-XWAtwJ6OHO+tj0EKCs0Y2UamnyOxseZWltU4x2U2wh8g4AigdjwvtUjvLP2tqkA/avxHEtzxNaqGq/YGNwckKg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + } + }, "node_modules/chalk": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", @@ -4163,6 +4567,13 @@ "node": ">= 0.4" } }, + "node_modules/es-module-lexer": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-2.3.2.tgz", + "integrity": "sha512-poHGpORABojJJucnV9KbOavETW8lBVnphkW77ER5/BQ5Fz7oXSoCNek7IH3vR5nRjdsEz926ibFYX8KtLQmdyw==", + "dev": true, + "license": "MIT" + }, "node_modules/es-object-atoms": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz", @@ -4684,6 +5095,16 @@ "node": ">=4.0" } }, + "node_modules/estree-walker": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-3.0.3.tgz", + "integrity": "sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/estree": "^1.0.0" + } + }, "node_modules/esutils": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", @@ -4694,6 +5115,16 @@ "node": ">=0.10.0" } }, + "node_modules/expect-type": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/expect-type/-/expect-type-1.4.0.tgz", + "integrity": "sha512-KfYbmpRm0VbLjEvVa9yGwCi9GI34xvi7A/HXYWQO65CSD2u3MczUJSuwXKFIxlGsgBQizV9q5J9NHj4VG0n+pA==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=12.0.0" + } + }, "node_modules/fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", @@ -6258,9 +6689,9 @@ "license": "MIT" }, "node_modules/nanoid": { - "version": "3.3.11", - "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.11.tgz", - "integrity": "sha512-N8SpfPUnUp1bK+PMYW8qSWdl9U+wwNWI4QKxOYDy9JAro3WMX7p2OeVRF9v+347pnakNevPmiHhNmZ2HbFA76w==", + "version": "3.3.20", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.20.tgz", + "integrity": "sha512-uKdg2G3GNCKQn9byYOpxbGqrT2fGO5KRt5J/8b3pok8rT6qxGWF6hxMyJiEYtAf+FVyYuD9hRaDqX5uPFYJ4ZQ==", "funding": [ { "type": "github", @@ -6528,6 +6959,20 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/obug": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/obug/-/obug-2.2.1.tgz", + "integrity": "sha512-XrsrhT5sybtKI6wakr2SPOlGZWWYbUXZ7a0jT8/QOeAPau+1X/bSegNe5YR75oJmEZQbKningirmGOEJCIk61Q==", + "dev": true, + "funding": [ + "https://github.com/sponsors/sxzz", + "https://opencollective.com/debug" + ], + "license": "MIT", + "engines": { + "node": ">=12.20.0" + } + }, "node_modules/optionator": { "version": "0.9.4", "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.4.tgz", @@ -6636,6 +7081,13 @@ "dev": true, "license": "MIT" }, + "node_modules/pathe": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/pathe/-/pathe-2.0.3.tgz", + "integrity": "sha512-WUjGcAqP1gQacoQe+OBJsFA7Ld4DyXuUIjZ5cc75cLHvJ7dtNsTugphxIADwspS+AraAUePCKrSVtPLFj/F88w==", + "dev": true, + "license": "MIT" + }, "node_modules/pg": { "version": "8.20.0", "resolved": "https://registry.npmjs.org/pg/-/pg-8.20.0.tgz", @@ -6755,9 +7207,9 @@ } }, "node_modules/postcss": { - "version": "8.5.8", - "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.8.tgz", - "integrity": "sha512-OW/rX8O/jXnm82Ey1k44pObPtdblfiuWnrd8X7GJ7emImCOstunGbXUpp7HdBrFQX6rJzn3sPT397Wp5aCwCHg==", + "version": "8.5.31", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.31.tgz", + "integrity": "sha512-YUbWYCgErwnMAVkjUnYa+KlMBzGpHwiIt/DE7f0G33AuX2LH9UcTk6KgWxd3zRU+pN3u/C+Xl3EnMLM4Hea7Sg==", "dev": true, "funding": [ { @@ -6775,9 +7227,9 @@ ], "license": "MIT", "dependencies": { - "nanoid": "^3.3.11", + "nanoid": "^3.3.20", "picocolors": "^1.1.1", - "source-map-js": "^1.2.1" + "source-map-js": "^1.2.2" }, "engines": { "node": "^10 || ^12 || >=14" @@ -7041,6 +7493,40 @@ "node": ">=0.10.0" } }, + "node_modules/rolldown": { + "version": "1.2.14", + "resolved": "https://registry.npmjs.org/rolldown/-/rolldown-1.2.14.tgz", + "integrity": "sha512-eTBTTqMR6uHKLgcUqpJP8ntzDI6V4LYA8negAMBEI7gkgVvOdrx6VsvS2Ym+83KhOPdLCHWJu0w7UQFJZhHKNw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@oxc-project/types": "=0.154.0", + "@rolldown/pluginutils": "^1.0.0" + }, + "bin": { + "rolldown": "bin/cli.mjs" + }, + "engines": { + "node": "^20.19.0 || >=22.12.0" + }, + "optionalDependencies": { + "@rolldown/binding-android-arm-eabi": "1.2.14", + "@rolldown/binding-android-arm64": "1.2.14", + "@rolldown/binding-darwin-arm64": "1.2.14", + "@rolldown/binding-darwin-x64": "1.2.14", + "@rolldown/binding-freebsd-x64": "1.2.14", + "@rolldown/binding-linux-arm-gnueabihf": "1.2.14", + "@rolldown/binding-linux-arm64-gnu": "1.2.14", + "@rolldown/binding-linux-arm64-musl": "1.2.14", + "@rolldown/binding-linux-ppc64-gnu": "1.2.14", + "@rolldown/binding-linux-s390x-gnu": "1.2.14", + "@rolldown/binding-linux-x64-gnu": "1.2.14", + "@rolldown/binding-linux-x64-musl": "1.2.14", + "@rolldown/binding-openharmony-arm64": "1.2.14", + "@rolldown/binding-win32-arm64-msvc": "1.2.14", + "@rolldown/binding-win32-x64-msvc": "1.2.14" + } + }, "node_modules/run-parallel": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", @@ -7342,6 +7828,13 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/siginfo": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/siginfo/-/siginfo-2.0.0.tgz", + "integrity": "sha512-ybx0WO1/8bSBLEWXZvEd7gMW3Sn3JFlW3TvX1nREbDLRNQNaeNN8WK0meBwPdAaOI7TtRRRJn/Es1zhrrCHu7g==", + "dev": true, + "license": "ISC" + }, "node_modules/source-map": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", @@ -7353,9 +7846,9 @@ } }, "node_modules/source-map-js": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.1.tgz", - "integrity": "sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==", + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.2.tgz", + "integrity": "sha512-KGj/8Y43x35aZVDtt+J4mK1hoLGHULMYfSkODJNQjNDC3oW1PqPoxMwo0pLUsWM/UEGzON/NxeHywEfNXNP3Vw==", "license": "BSD-3-Clause", "engines": { "node": ">=0.10.0" @@ -7388,6 +7881,20 @@ "dev": true, "license": "MIT" }, + "node_modules/stackback": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/stackback/-/stackback-0.0.2.tgz", + "integrity": "sha512-1XMJE5fQo1jGH6Y/7ebnwPOBEkIEnT4QF32d5R1+VXdXveM0IBMJt8zfaxX1P3QhVwrYe+576+jkANtSS2mBbw==", + "dev": true, + "license": "MIT" + }, + "node_modules/std-env": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/std-env/-/std-env-4.3.0.tgz", + "integrity": "sha512-OtU/EgQ1kIm5KwqQpBC6ZEMXrZRui11w8zgfTWp8cdO9B8OaPsbA8bTHO2P+HNo1VlUTGMVBwPhydu6poeXiag==", + "dev": true, + "license": "MIT" + }, "node_modules/stop-iteration-iterator": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/stop-iteration-iterator/-/stop-iteration-iterator-1.1.0.tgz", @@ -7608,15 +8115,32 @@ "url": "https://opencollective.com/webpack" } }, + "node_modules/tinybench": { + "version": "2.9.0", + "resolved": "https://registry.npmjs.org/tinybench/-/tinybench-2.9.0.tgz", + "integrity": "sha512-0+DUvqWMValLmha6lr4kD8iAMK1HzV0/aKnCtWb9v9641TnP/MFb7Pc2bxoxQjTXAErryXVgUOfv2YqNllqGeg==", + "dev": true, + "license": "MIT" + }, + "node_modules/tinyexec": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/tinyexec/-/tinyexec-1.3.1.tgz", + "integrity": "sha512-GCvB3aoys96IuDFBMcTB46JOR6mdMtAToqwiW8JlWhsoh1mhHi/xn9ss/Dg7N555GiJyEt2qzoG/NHCwM6h1EA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + } + }, "node_modules/tinyglobby": { - "version": "0.2.15", - "resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.15.tgz", - "integrity": "sha512-j2Zq4NyQYG5XMST4cbs02Ak8iJUdxRM0XI5QyxXuZOzKOINmWurp3smXu3y5wDcJrptwpSjgXHzIQxR0omXljQ==", + "version": "0.2.17", + "resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.17.tgz", + "integrity": "sha512-wXR/dYpcqKmfWpEdZjiKJOwCNFndD0DMnrW/cYjVGttEkBfVgcLFHoNrlj47mjOVic9yyNu65alsgF4NQyTa2g==", "dev": true, "license": "MIT", "dependencies": { "fdir": "^6.5.0", - "picomatch": "^4.0.3" + "picomatch": "^4.0.4" }, "engines": { "node": ">=12.0.0" @@ -7656,6 +8180,16 @@ "url": "https://github.com/sponsors/jonschlinkert" } }, + "node_modules/tinyrainbow": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/tinyrainbow/-/tinyrainbow-3.2.0.tgz", + "integrity": "sha512-LgO3D9yZJjApUiuUfl9iFAwrtaX4+lok3wJIqttGoKCHlWUqHqbQpnxCf82L8FjgKsh4iGo78hqJwgL8F6To2A==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=14.0.0" + } + }, "node_modules/to-regex-range": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", @@ -8469,6 +9003,987 @@ "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0" } }, + "node_modules/vitest": { + "version": "4.1.12", + "resolved": "https://registry.npmjs.org/vitest/-/vitest-4.1.12.tgz", + "integrity": "sha512-5eWdz2yb3ajxWF3C8C4TjkXl7FGm3n2E/VlazALrQHzK7nYMSGFnCZto0bbPNl77AwkOZVLk0YnBAejUu0NiWA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vitest/expect": "4.1.12", + "@vitest/mocker": "4.1.12", + "@vitest/pretty-format": "4.1.12", + "@vitest/runner": "4.1.12", + "@vitest/snapshot": "4.1.12", + "@vitest/spy": "4.1.12", + "@vitest/utils": "4.1.12", + "es-module-lexer": "^2.0.0", + "expect-type": "^1.3.0", + "magic-string": "^0.30.21", + "obug": "^2.1.1", + "pathe": "^2.0.3", + "picomatch": "^4.0.3", + "std-env": "^4.0.0-rc.1", + "tinybench": "^2.9.0", + "tinyexec": "^1.0.2", + "tinyglobby": "^0.2.15", + "tinyrainbow": "^3.1.0", + "vite": "^6.0.0 || ^7.0.0 || ^8.0.0", + "why-is-node-running": "^2.3.0" + }, + "bin": { + "vitest": "vitest.mjs" + }, + "engines": { + "node": "^20.0.0 || ^22.0.0 || >=24.0.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + }, + "peerDependencies": { + "@edge-runtime/vm": "*", + "@opentelemetry/api": "^1.9.0", + "@types/node": "^20.0.0 || ^22.0.0 || >=24.0.0", + "@vitest/browser-playwright": "4.1.12", + "@vitest/browser-preview": "4.1.12", + "@vitest/browser-webdriverio": "^4.1.11", + "@vitest/coverage-istanbul": "4.1.12", + "@vitest/coverage-v8": "4.1.12", + "@vitest/ui": "4.1.12", + "happy-dom": "*", + "jsdom": "*", + "vite": "^6.0.0 || ^7.0.0 || ^8.0.0" + }, + "peerDependenciesMeta": { + "@edge-runtime/vm": { + "optional": true + }, + "@opentelemetry/api": { + "optional": true + }, + "@types/node": { + "optional": true + }, + "@vitest/browser-playwright": { + "optional": true + }, + "@vitest/browser-preview": { + "optional": true + }, + "@vitest/browser-webdriverio": { + "optional": true + }, + "@vitest/coverage-istanbul": { + "optional": true + }, + "@vitest/coverage-v8": { + "optional": true + }, + "@vitest/ui": { + "optional": true + }, + "happy-dom": { + "optional": true + }, + "jsdom": { + "optional": true + }, + "vite": { + "optional": false + } + } + }, + "node_modules/vitest/node_modules/@esbuild/aix-ppc64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.28.2.tgz", + "integrity": "sha512-XExcO+dvLKvVtNTibSTBej1NCAbaGhWn9Ww1ZPx80qsahhPFe/8jgWP0IchNe0F3HwkU7n8ejhH8bjonqht8mQ==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "aix" + ], + "peer": true, + "engines": { + "node": ">=18" + } + }, + "node_modules/vitest/node_modules/@esbuild/android-arm": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.28.2.tgz", + "integrity": "sha512-kXXoiPVVGQcnIYGOeaovwOURpniDBpSq4A03qkQ+BMQqtGG6HYap3xne9C1O1yo4TR3qxlCX5IqqmX6fFo2Lqg==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "peer": true, + "engines": { + "node": ">=18" + } + }, + "node_modules/vitest/node_modules/@esbuild/android-arm64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.28.2.tgz", + "integrity": "sha512-5YfKeeI8qWfBZIX+u2xZC3Zlb3Os/gLS2sbEKM+I4ZOcsWmHS2WLysCcQZDAFRslDUU5Oiq44gf6PYN1vGwG5A==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "peer": true, + "engines": { + "node": ">=18" + } + }, + "node_modules/vitest/node_modules/@esbuild/android-x64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.28.2.tgz", + "integrity": "sha512-O387ite7SzUyCcy3JQX4P4bLtEA7bLLkx+esve5JHnyYfNTxcVpXZo9jhdB0lTKN44gztELTdU7nS8Nr16Fs1Q==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "peer": true, + "engines": { + "node": ">=18" + } + }, + "node_modules/vitest/node_modules/@esbuild/darwin-arm64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.28.2.tgz", + "integrity": "sha512-n4KqkOQrraxHJcgjM1RvwbigfQKIKJVpM7xp+KsxiyUSrRdIXnt73VhrPAx0fV44hgfmIVKjxMN9J1t5jySVkw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "peer": true, + "engines": { + "node": ">=18" + } + }, + "node_modules/vitest/node_modules/@esbuild/darwin-x64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.28.2.tgz", + "integrity": "sha512-uq6suIWYP37qzGddBKPw5QEQPi6HiLGsO7UmkpfyaYNQ3D+rN6w6WfwH+nuqcGXWvawGwxOEroO4YGnFh95azw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "peer": true, + "engines": { + "node": ">=18" + } + }, + "node_modules/vitest/node_modules/@esbuild/freebsd-arm64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.28.2.tgz", + "integrity": "sha512-n+I0BTSRIoy+d6RPKnEVwql5UwBJolytvY4mAOIEJorKlqgPII8ix6slVVrfZ5Tnj7glIZvloylbB/EJPMWEXw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "peer": true, + "engines": { + "node": ">=18" + } + }, + "node_modules/vitest/node_modules/@esbuild/freebsd-x64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.28.2.tgz", + "integrity": "sha512-78XJTJkvPs0kz2w61301PJjXl4g7q3JqiYMZ/M/yVI73EHBrCRTgkhu9oqG7vPqq+a/yadEW8aD+agKlk5xrmg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "peer": true, + "engines": { + "node": ">=18" + } + }, + "node_modules/vitest/node_modules/@esbuild/linux-arm": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.28.2.tgz", + "integrity": "sha512-XlDnu2q5yoqems+xay6wSAcg9DDD7K9RLKZEBOMZm3ckNpJBvOX20tSfby8KfrrhINDyv9V2YVZKY/SpoGJI8w==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "peer": true, + "engines": { + "node": ">=18" + } + }, + "node_modules/vitest/node_modules/@esbuild/linux-arm64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.28.2.tgz", + "integrity": "sha512-pW4AC0P3it8c7do9MVM4p51FzHzdM/TZrerurgRcHJ2WTa1VQ1CIq18xncfpBJw4ojkiZZrKW2yIBWBP92j6Ug==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "peer": true, + "engines": { + "node": ">=18" + } + }, + "node_modules/vitest/node_modules/@esbuild/linux-ia32": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.28.2.tgz", + "integrity": "sha512-CYbnj78HsIeA+DhgUKgFCfvNsTHFhMMrinUrMZpDXJXKN8T3XViTZ/+wtHeVxEWY8ewSzTFN+nRmSwO2tZaLUQ==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "peer": true, + "engines": { + "node": ">=18" + } + }, + "node_modules/vitest/node_modules/@esbuild/linux-loong64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.28.2.tgz", + "integrity": "sha512-buwkd8nsph4R+ajRvw0qM5Hja/TXQow3ptzWO2EbG/cqcIkHloRrdlBtQlshyYGTNFvfkfJ5tpPLVkY4DtsPfQ==", + "cpu": [ + "loong64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "peer": true, + "engines": { + "node": ">=18" + } + }, + "node_modules/vitest/node_modules/@esbuild/linux-mips64el": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.28.2.tgz", + "integrity": "sha512-ZVykbDyk7519VwiNb9Lcj9m8XM6v5V9uKPvrEMkkEedVewf+0itkhahp4HDpgERXhwLRpWFypsGbG/J8s0QjJA==", + "cpu": [ + "mips64el" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "peer": true, + "engines": { + "node": ">=18" + } + }, + "node_modules/vitest/node_modules/@esbuild/linux-ppc64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.28.2.tgz", + "integrity": "sha512-CAXl+Dtd9UUuJd8pKKdwh6MLm3MUMiqMPmhZ3tTSXPqfyQ3vDl6R5hZdZ/kYojK4ofXtdfSv1tFq8XzWx3heNQ==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "peer": true, + "engines": { + "node": ">=18" + } + }, + "node_modules/vitest/node_modules/@esbuild/linux-riscv64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.28.2.tgz", + "integrity": "sha512-GeXCej4IQtU1B+QlDV8W/RRvbzI3O/Stss+/bCXv4lZls5WGRtu2a+3JkA3i4qIUlMXpcHebWpF8AkJhATowuA==", + "cpu": [ + "riscv64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "peer": true, + "engines": { + "node": ">=18" + } + }, + "node_modules/vitest/node_modules/@esbuild/linux-s390x": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.28.2.tgz", + "integrity": "sha512-3H1weTYZPxt/WOhByszQZybS9w5lKzUn1FDMsgEChbHWQwHYQQRfBxgCcZvPhjHfKyJjIievvMmEUawJrdY9Dg==", + "cpu": [ + "s390x" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "peer": true, + "engines": { + "node": ">=18" + } + }, + "node_modules/vitest/node_modules/@esbuild/linux-x64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.28.2.tgz", + "integrity": "sha512-4xTZr1FUmSoQW4XIWmit3tzQrUTZM+N3P0XV8xROKYF50XfI7xeO90+1bZvNwxIufQ9hDQVRJH5YhgPVF8A/HQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "peer": true, + "engines": { + "node": ">=18" + } + }, + "node_modules/vitest/node_modules/@esbuild/netbsd-arm64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.28.2.tgz", + "integrity": "sha512-sSATRjPeDBg3pdgHoQfoYBob11Kk1FGa9lui5RIHZCoCkJa9QKlvl3/vKz2usCmYYjs7ymJR/2Nnsqe+Hjt5nw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "peer": true, + "engines": { + "node": ">=18" + } + }, + "node_modules/vitest/node_modules/@esbuild/netbsd-x64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.28.2.tgz", + "integrity": "sha512-lqnzCV+mM0gIADaKihiCg6ifgfU2L3h5E33rNQBN1Y4MaVGnzryzmvvf7UHxprpQdE8hpqLolJ9Rl+SkIRDpyw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "peer": true, + "engines": { + "node": ">=18" + } + }, + "node_modules/vitest/node_modules/@esbuild/openbsd-arm64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.28.2.tgz", + "integrity": "sha512-AL2qJILH7lNjrDmCQDvdxMfAUIv8KMNZOvrwAQ8i8//ntL9FflhOyMJ8OZSMBb8/AWXe3/5v5S20y3zCoZWKoQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "peer": true, + "engines": { + "node": ">=18" + } + }, + "node_modules/vitest/node_modules/@esbuild/openbsd-x64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.28.2.tgz", + "integrity": "sha512-QtiuPytchRyC4rwUKhexJdQKvDuZ6hWloi3igqPQNUJCS1/v9EiO3UTOXR6A3FoMo4fnAKbWJdqaIwhOzh8qEw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "peer": true, + "engines": { + "node": ">=18" + } + }, + "node_modules/vitest/node_modules/@esbuild/openharmony-arm64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/openharmony-arm64/-/openharmony-arm64-0.28.2.tgz", + "integrity": "sha512-WkhYDmpTjLvGlScA1rwjRUmhl4k8oXR3cIbtqWmELgU/dFeHHlEllxDvdWcNJV9rbzCexB5vz8gtNewWLgCT7Q==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openharmony" + ], + "peer": true, + "engines": { + "node": ">=18" + } + }, + "node_modules/vitest/node_modules/@esbuild/sunos-x64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.28.2.tgz", + "integrity": "sha512-GPMSkTOtMnv2U2F8gxe4Io6qmVs+YKyp832Etqqxr0hFngmXQ3rzwytelm3GIn7T4VviRUlf3sOgBOiTdvaf7g==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "sunos" + ], + "peer": true, + "engines": { + "node": ">=18" + } + }, + "node_modules/vitest/node_modules/@esbuild/win32-arm64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.28.2.tgz", + "integrity": "sha512-PIhhEkE9uPBleRBrQEJpUn7MBnibZzbGzYWPmY3x+YoVg/95zbjB4CxPPOQ8l5tYYM4mMaCthF8/1DIfBQQyWQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "peer": true, + "engines": { + "node": ">=18" + } + }, + "node_modules/vitest/node_modules/@esbuild/win32-ia32": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.28.2.tgz", + "integrity": "sha512-YmJbfTlvU7Sdn9BB+4PRES4oB6pxgS37MAONj+hBr/cpXS1aBPKXxNnDbu+QCWPj0o9dgyxeq79g6c5P8KeuYA==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "peer": true, + "engines": { + "node": ">=18" + } + }, + "node_modules/vitest/node_modules/@esbuild/win32-x64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.28.2.tgz", + "integrity": "sha512-5ebpxr3nWMzrL/rnUI755Jkuee0bHL/Gq0WTF9lvcpv73wAp5eu8MfBUgWK9bhWvZjj7yX8etf/8tI8Ney695g==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "peer": true, + "engines": { + "node": ">=18" + } + }, + "node_modules/vitest/node_modules/@vitest/mocker": { + "version": "4.1.12", + "resolved": "https://registry.npmjs.org/@vitest/mocker/-/mocker-4.1.12.tgz", + "integrity": "sha512-fKShNpKZzupWZuY0z7egydvL0sqW4INEZBEExMBMAa6izlENEVHwoXgdaTCaBZ5fwlr4xf2o1wXC83n9RpO+NA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vitest/spy": "4.1.12", + "estree-walker": "^3.0.3", + "magic-string": "^0.30.21" + }, + "funding": { + "url": "https://opencollective.com/vitest" + }, + "peerDependencies": { + "msw": "^2.4.9", + "vite": "^6.0.0 || ^7.0.0 || ^8.0.0" + }, + "peerDependenciesMeta": { + "msw": { + "optional": true + }, + "vite": { + "optional": true + } + } + }, + "node_modules/vitest/node_modules/esbuild": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.28.2.tgz", + "integrity": "sha512-HKVLS8dvII+xoKW9kmqxbRKrnWEXfJJr/FZhhJmiqIB0e053QNYFqOBouTMO/k5sID4MvCiUCvv8b9M4h32wIA==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "peer": true, + "bin": { + "esbuild": "bin/esbuild" + }, + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "@esbuild/aix-ppc64": "0.28.2", + "@esbuild/android-arm": "0.28.2", + "@esbuild/android-arm64": "0.28.2", + "@esbuild/android-x64": "0.28.2", + "@esbuild/darwin-arm64": "0.28.2", + "@esbuild/darwin-x64": "0.28.2", + "@esbuild/freebsd-arm64": "0.28.2", + "@esbuild/freebsd-x64": "0.28.2", + "@esbuild/linux-arm": "0.28.2", + "@esbuild/linux-arm64": "0.28.2", + "@esbuild/linux-ia32": "0.28.2", + "@esbuild/linux-loong64": "0.28.2", + "@esbuild/linux-mips64el": "0.28.2", + "@esbuild/linux-ppc64": "0.28.2", + "@esbuild/linux-riscv64": "0.28.2", + "@esbuild/linux-s390x": "0.28.2", + "@esbuild/linux-x64": "0.28.2", + "@esbuild/netbsd-arm64": "0.28.2", + "@esbuild/netbsd-x64": "0.28.2", + "@esbuild/openbsd-arm64": "0.28.2", + "@esbuild/openbsd-x64": "0.28.2", + "@esbuild/openharmony-arm64": "0.28.2", + "@esbuild/sunos-x64": "0.28.2", + "@esbuild/win32-arm64": "0.28.2", + "@esbuild/win32-ia32": "0.28.2", + "@esbuild/win32-x64": "0.28.2" + } + }, + "node_modules/vitest/node_modules/lightningcss": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss/-/lightningcss-1.33.0.tgz", + "integrity": "sha512-WkUDrojuJs0xkgGf2udWxa3yGBRxPtxUkB79i6aCZLRgc7PM8fZe9TosfPDcvEpQZbuFASnHYmRLBLUbmLOIIA==", + "dev": true, + "license": "MPL-2.0", + "dependencies": { + "detect-libc": "^2.0.3" + }, + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + }, + "optionalDependencies": { + "lightningcss-android-arm64": "1.33.0", + "lightningcss-darwin-arm64": "1.33.0", + "lightningcss-darwin-x64": "1.33.0", + "lightningcss-freebsd-x64": "1.33.0", + "lightningcss-linux-arm-gnueabihf": "1.33.0", + "lightningcss-linux-arm64-gnu": "1.33.0", + "lightningcss-linux-arm64-musl": "1.33.0", + "lightningcss-linux-x64-gnu": "1.33.0", + "lightningcss-linux-x64-musl": "1.33.0", + "lightningcss-win32-arm64-msvc": "1.33.0", + "lightningcss-win32-x64-msvc": "1.33.0" + } + }, + "node_modules/vitest/node_modules/lightningcss-android-arm64": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-android-arm64/-/lightningcss-android-arm64-1.33.0.tgz", + "integrity": "sha512-gEpRTalKdosp4Bb8qWtc2iOgE5SeIHlpS1up9bFq2wAyYhl1UdTObYiHe98zEM9SQvSoqQZ1IQD0JNpg3Ml5pg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/vitest/node_modules/lightningcss-darwin-arm64": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-darwin-arm64/-/lightningcss-darwin-arm64-1.33.0.tgz", + "integrity": "sha512-Sciaz8eenNTKn9b3t7+xr0ipTp9YxKQY4npwQ3mrRuL0BAVHBLyZxofhaKBAVtzmtRZ/zTyo0/to4B1uWG/Djg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/vitest/node_modules/lightningcss-darwin-x64": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-darwin-x64/-/lightningcss-darwin-x64-1.33.0.tgz", + "integrity": "sha512-Z5UPAxzrjlWNNyGy6i65cJzzvgJ5D3T6wMvs+gWpY9d7qRhANrxqAp6LhxIgZhWEw18RfJTGcRxjuLIBr+m8XQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/vitest/node_modules/lightningcss-freebsd-x64": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-freebsd-x64/-/lightningcss-freebsd-x64-1.33.0.tgz", + "integrity": "sha512-QQM/Ti/hQajJwCY+RiWuCZ9sdtI/XQk7nDK5vC8kkdwixezOlDgvDx7+RT+QjK6FcFT4MpsuoBnHIo/O3StRRg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/vitest/node_modules/lightningcss-linux-arm-gnueabihf": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-arm-gnueabihf/-/lightningcss-linux-arm-gnueabihf-1.33.0.tgz", + "integrity": "sha512-N7FVBe6iS24MlM6R/4RBTxGhQheZGs7tiQ9U32UtF75NzP5Q7xWPRqLBCKxlRQRk3rY1jCIPLzx7WzOhuUIRLQ==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/vitest/node_modules/lightningcss-linux-arm64-gnu": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-arm64-gnu/-/lightningcss-linux-arm64-gnu-1.33.0.tgz", + "integrity": "sha512-j2v/itmy4HlNxlc6voKXYgBqNi0Ng2LShg4z7GufpEgs05P+2suBVyi9I6YHq5uoVFx9ETin3eCEhLVyXGQnKg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/vitest/node_modules/lightningcss-linux-arm64-musl": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-arm64-musl/-/lightningcss-linux-arm64-musl-1.33.0.tgz", + "integrity": "sha512-yiO5ROMuYQgXbC60yjZU5CYSFZGKXL0HFATXt9mHJn1+zW55oCtMI9NfcVhYLMFDL7gV7oBPon/EmMMGg2OvtQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/vitest/node_modules/lightningcss-linux-x64-gnu": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-x64-gnu/-/lightningcss-linux-x64-gnu-1.33.0.tgz", + "integrity": "sha512-ar+Ju7LmcN0Jo4FpL4hpFybwNG9/3A/Br5KW2n2jyODg3MEZXaDYADdemoNS+BDNfMgKvylJLj4S5tyRActuAg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/vitest/node_modules/lightningcss-linux-x64-musl": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-x64-musl/-/lightningcss-linux-x64-musl-1.33.0.tgz", + "integrity": "sha512-RYiYbkokw0trfKqqzfF55lginwEPrD3OJDfTuJzFs1MK6iFnDenaz1fqLLtX4ITG3OktJQXOeTaw1awrBAlZPw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/vitest/node_modules/lightningcss-win32-arm64-msvc": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-win32-arm64-msvc/-/lightningcss-win32-arm64-msvc-1.33.0.tgz", + "integrity": "sha512-1K+MPfLSFVpphzpdbfkhlWk6wBrTObBzS2T6db10PNOZgR9GoVsAWzwNyuhUYYbTp23j+4RrncfujZ4uAzXvwA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/vitest/node_modules/lightningcss-win32-x64-msvc": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-win32-x64-msvc/-/lightningcss-win32-x64-msvc-1.33.0.tgz", + "integrity": "sha512-OlEICDx/Xl0FqSp4bry8zFnCvGpig3Gl4gCquvYwHuqJKEC1+n9NgDniFvqHGmMv1ZkqDJrDqKKSykTDX+ehuA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/vitest/node_modules/picomatch": { + "version": "4.0.7", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.7.tgz", + "integrity": "sha512-qcJu88Q2IWqJsDD529JKMdwGm/dvInW4HvQnRwiH9JtihJvzGOscDtHE3x1pBKeUOTysQ8kVmLnJ2kJu7yhcGA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, + "node_modules/vitest/node_modules/vite": { + "version": "8.3.4", + "resolved": "https://registry.npmjs.org/vite/-/vite-8.3.4.tgz", + "integrity": "sha512-IftLE8phJhdNRIGNEV4JCCvfNScoZQVfcXaN8TQropWGJtOHcu+iAB9pHcuGvmEb/kddw0LBe/jS8ztdC6xdiQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "lightningcss": "^1.33.0", + "picomatch": "^4.0.7", + "postcss": "^8.5.29", + "rolldown": "~1.2.12", + "tinyglobby": "^0.2.17" + }, + "bin": { + "vite": "bin/vite.js" + }, + "engines": { + "node": "^20.19.0 || >=22.12.0" + }, + "funding": { + "url": "https://github.com/vitejs/vite?sponsor=1" + }, + "optionalDependencies": { + "fsevents": "~2.3.3" + }, + "peerDependencies": { + "@types/node": "^20.19.0 || >=22.12.0", + "@vitejs/devtools": "^0.7.1", + "esbuild": "^0.27.0 || ^0.28.0", + "jiti": ">=1.21.0", + "less": "^4.0.0", + "sass": "^1.70.0", + "sass-embedded": "^1.70.0", + "stylus": ">=0.54.8", + "sugarss": "^5.0.0", + "terser": "^5.16.0", + "tsx": "^4.8.1", + "yaml": "^2.4.2" + }, + "peerDependenciesMeta": { + "@types/node": { + "optional": true + }, + "@vitejs/devtools": { + "optional": true + }, + "esbuild": { + "optional": true + }, + "jiti": { + "optional": true + }, + "less": { + "optional": true + }, + "sass": { + "optional": true + }, + "sass-embedded": { + "optional": true + }, + "stylus": { + "optional": true + }, + "sugarss": { + "optional": true + }, + "terser": { + "optional": true + }, + "tsx": { + "optional": true + }, + "yaml": { + "optional": true + } + } + }, "node_modules/void-elements": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/void-elements/-/void-elements-3.1.0.tgz", @@ -8583,6 +10098,23 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/why-is-node-running": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/why-is-node-running/-/why-is-node-running-2.3.0.tgz", + "integrity": "sha512-hUrmaWBdVDcxvYqnyh09zunKzROWjbZTiNy8dBEjkS7ehEDQibXJ7XvlmtbwuTclUiIyN+CyXQD4Vmko8fNm8w==", + "dev": true, + "license": "MIT", + "dependencies": { + "siginfo": "^2.0.0", + "stackback": "0.0.2" + }, + "bin": { + "why-is-node-running": "cli.js" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/word-wrap": { "version": "1.2.5", "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.5.tgz", diff --git a/web/package.json b/web/package.json index 1c87792..261006b 100644 --- a/web/package.json +++ b/web/package.json @@ -6,7 +6,8 @@ "dev": "next dev", "build": "next build", "start": "next start", - "lint": "eslint" + "lint": "eslint", + "test": "vitest run" }, "dependencies": { "@logto/next": "^4.2.9", @@ -34,6 +35,7 @@ "eslint": "^9", "eslint-config-next": "16.2.2", "tailwindcss": "^4", - "typescript": "^5" + "typescript": "^5", + "vitest": "^4.1.12" } } diff --git a/web/src/app/api/sync/route.ts b/web/src/app/api/sync/route.ts index 56541cd..cb14996 100644 --- a/web/src/app/api/sync/route.ts +++ b/web/src/app/api/sync/route.ts @@ -5,6 +5,15 @@ import { eq, and, gte, isNull } from 'drizzle-orm'; import { requireAuth, parseBody } from '@/lib/api'; import { rateLimit } from '@/lib/rateLimit'; import { syncPushSchema, type SyncOperation } from '@/lib/validators'; +import { + listCreateData, + listUpdateData, + taskCreateData, + taskUpdateData, + tagCreateData, + tagUpdateData, + taskTagData, +} from '@/lib/syncData'; // Idempotency key store (TTL 24h) const idempotencyStore = new Map(); @@ -191,27 +200,28 @@ export async function POST(request: Request) { } async function processOperation(op: SyncOperation, userId: string) { - const { entityType, entityId, action, data } = op; + const { entityType, entityId, action } = op; + const data = op.data ?? {}; const now = new Date(); switch (entityType) { case 'list': { if (action === 'create') { - const d = (data as Record) || {}; - const incomingIsInbox = d.isInbox as boolean | undefined; + const d = listCreateData.parse(data); + await assertIdNotTaken(slLists, entityId, userId); const listValues = { id: entityId, userId, - name: d.name as string || 'Untitled', - color: d.color as string | undefined, - icon: d.icon as string | undefined, - position: d.position as number | undefined, - isInbox: incomingIsInbox, + name: d.name || 'Untitled', + color: d.color, + icon: d.icon, + position: d.position, + isInbox: d.isInbox, }; // If the incoming list is an inbox, check for an existing inbox and merge - if (incomingIsInbox) { + if (d.isInbox) { await db.transaction(async (tx) => { const [existingInbox] = await tx .select() @@ -235,9 +245,10 @@ async function processOperation(op: SyncOperation, userId: string) { await db.insert(slLists).values(listValues).onConflictDoNothing(); } } else if (action === 'update') { + const d = listUpdateData.parse(data); await verifyOwnership(slLists, entityId, userId); await db.update(slLists) - .set({ ...(data as Record), updatedAt: now }) + .set({ ...d, updatedAt: now }) .where(and(eq(slLists.id, entityId), eq(slLists.userId, userId))); } else if (action === 'delete') { await verifyOwnership(slLists, entityId, userId); @@ -249,32 +260,30 @@ async function processOperation(op: SyncOperation, userId: string) { } case 'task': { if (action === 'create') { - const d = (data as Record) || {}; + const d = taskCreateData.parse(data); + await verifyOwnership(slLists, d.listId, userId); + // Not verifyOwnership: initialMerge pushes all tasks in one batch, a + // subtask may arrive before its parent (parent_id has no FK). + if (d.parentId) await assertIdNotTaken(slTasks, d.parentId, userId); await db.insert(slTasks).values({ id: entityId, userId, - title: d.title as string || 'Untitled', - listId: d.listId as string, - notes: d.notes as string | undefined, - priority: d.priority as number | undefined, - dueDate: d.dueDate ? new Date(d.dueDate as string) : undefined, - parentId: d.parentId as string | undefined, - recurrence: d.recurrence as string | undefined, - position: d.position as number | undefined, + title: d.title || 'Untitled', + listId: d.listId, + notes: d.notes, + priority: d.priority, + dueDate: d.dueDate, + parentId: d.parentId, + recurrence: d.recurrence, + position: d.position, }).onConflictDoNothing(); } else if (action === 'update') { + const d = taskUpdateData.parse(data); await verifyOwnership(slTasks, entityId, userId); - const raw = { ...(data as Record), updatedAt: now } as Record; - // Remove id from payload to avoid overwriting primary key - delete raw.id; - if (raw.dueDate !== undefined) { - raw.dueDate = raw.dueDate ? new Date(raw.dueDate as string) : null; - } - if (raw.completedAt !== undefined) { - raw.completedAt = raw.completedAt ? new Date(raw.completedAt as string) : null; - } + if (d.listId) await verifyOwnership(slLists, d.listId, userId); + if (d.parentId) await assertIdNotTaken(slTasks, d.parentId, userId); await db.update(slTasks) - .set(raw) + .set({ ...d, updatedAt: now }) .where(and(eq(slTasks.id, entityId), eq(slTasks.userId, userId))); } else if (action === 'delete') { await verifyOwnership(slTasks, entityId, userId); @@ -286,17 +295,20 @@ async function processOperation(op: SyncOperation, userId: string) { } case 'tag': { if (action === 'create') { - const d = (data as Record) || {}; + const d = tagCreateData.parse(data); await db.insert(slTags).values({ id: entityId, userId, - name: d.name as string || 'Untitled', - color: d.color as string | undefined, + name: d.name || 'Untitled', + color: d.color, }).onConflictDoNothing(); } else if (action === 'update') { + const d = tagUpdateData.parse(data); await verifyTagOwnership(entityId, userId); + // Tags have no updatedAt: skip when nothing is left to write + if (d.name === undefined && d.color === undefined) break; await db.update(slTags) - .set(data as Record) + .set(d) .where(and(eq(slTags.id, entityId), eq(slTags.userId, userId))); } else if (action === 'delete') { await verifyTagOwnership(entityId, userId); @@ -308,8 +320,9 @@ async function processOperation(op: SyncOperation, userId: string) { } case 'taskTag': { // entityId is used as taskId, tagId comes from data - const d = (data as Record) || {}; - const tagId = d.tagId as string; + const { tagId } = taskTagData.parse(data); + await verifyOwnership(slTasks, entityId, userId); + await verifyTagOwnership(tagId, userId); if (action === 'create') { await db.insert(slTaskTags) .values({ taskId: entityId, tagId }) @@ -339,3 +352,15 @@ async function verifyTagOwnership(entityId: string, userId: string) { .where(and(eq(slTags.id, entityId), eq(slTags.userId, userId))); if (!row) throw new Error('Tag not found or access denied'); } + +// Refuse an id that already exists under another account. Unlike +// verifyOwnership, a missing row passes: the id may be created later in the +// same batch (a subtask pushed before its parent), or by this very insert. +// eslint-disable-next-line @typescript-eslint/no-explicit-any +async function assertIdNotTaken(table: any, id: string, userId: string) { + const [row] = await db + .select({ userId: table.userId }) + .from(table) + .where(eq(table.id, id)); + if (row && row.userId !== userId) throw new Error('Entity not found or access denied'); +} diff --git a/web/src/lib/syncData.test.ts b/web/src/lib/syncData.test.ts new file mode 100644 index 0000000..3d54154 --- /dev/null +++ b/web/src/lib/syncData.test.ts @@ -0,0 +1,188 @@ +import { describe, it, expect } from 'vitest'; +import { + listCreateData, + listUpdateData, + taskCreateData, + taskUpdateData, + tagCreateData, + tagUpdateData, + taskTagData, +} from './syncData'; + +const ID = '3f1c2b7a-9d4e-4c1a-8b2f-5e6d7c8b9a01'; +const LIST_ID = '7a8b9c0d-1e2f-4a3b-8c4d-5e6f7a8b9c0d'; +const PARENT_ID = 'b1c2d3e4-f5a6-4b7c-8d9e-0f1a2b3c4d5e'; +const TAG_ID = 'c2d3e4f5-a6b7-4c8d-9e0f-1a2b3c4d5e6f'; +const DATE = '2026-10-19T12:00:00.000Z'; + +// Keys a client must never be able to write through `data`. +const FORBIDDEN = { + id: '00000000-0000-4000-8000-000000000000', + userId: 'someone-else', + deletedAt: DATE, + createdAt: DATE, + updatedAt: DATE, +}; + +function expectNoForbiddenKeys(parsed: object) { + for (const key of Object.keys(FORBIDDEN)) { + expect(parsed).not.toHaveProperty(key); + } +} + +// Payloads below are copied from what the mobile app sends today: +// src/db/repository/{lists,tasks,tags}.ts and src/services/syncClient.ts (initialMerge). +// JSON.parse(JSON.stringify(...)) drops undefined values like the real push does. +const wire = (v: T): T => JSON.parse(JSON.stringify(v)); + +describe('list data', () => { + it('accepts the createList payload with null color and icon', () => { + const d = listCreateData.parse(wire({ + id: LIST_ID, name: 'Courses', color: null, icon: null, position: 3, isInbox: false, + })); + expect(d).toEqual({ name: 'Courses', color: null, icon: null, position: 3, isInbox: false }); + }); + + it('accepts the initialMerge inbox payload', () => { + const d = listCreateData.parse(wire({ + name: 'Inbox', color: '#4A90A4', icon: 'inbox', position: 0, isInbox: true, + })); + expect(d.isInbox).toBe(true); + expect(d.name).toBe('Inbox'); + }); + + it('accepts the updateList payload and drops id', () => { + const d = listUpdateData.parse(wire({ id: LIST_ID, name: 'Maison', color: '#C17767', icon: null })); + expect(d).toEqual({ name: 'Maison', color: '#C17767', icon: null }); + }); + + it('strips forbidden keys and isInbox on update', () => { + const d = listUpdateData.parse({ ...FORBIDDEN, name: 'x', isInbox: true }); + expectNoForbiddenKeys(d); + expect(d).not.toHaveProperty('isInbox'); + }); + + it('strips forbidden keys on create', () => { + expectNoForbiddenKeys(listCreateData.parse({ ...FORBIDDEN, name: 'x' })); + }); + + it('truncates a long name instead of rejecting it', () => { + expect(listUpdateData.parse({ name: 'a'.repeat(201) }).name).toHaveLength(200); + }); + + it('turns a null name into undefined (NOT NULL column left untouched)', () => { + expect(listUpdateData.parse({ name: null }).name).toBeUndefined(); + }); + + it('accepts an empty data object', () => { + expect(listCreateData.parse({})).toEqual({}); + }); + + it('rejects a wrong type', () => { + expect(() => listUpdateData.parse({ position: '3' })).toThrow(); + expect(() => listCreateData.parse({ isInbox: 'yes' })).toThrow(); + }); +}); + +describe('task data', () => { + it('accepts the createTask payload with nulls', () => { + const d = taskCreateData.parse(wire({ + id: ID, title: 'Lait', notes: null, completed: false, completedAt: null, priority: 0, + dueDate: null, listId: LIST_ID, parentId: null, recurrence: null, + })); + expect(d).toEqual({ + title: 'Lait', notes: null, priority: 0, dueDate: null, listId: LIST_ID, + parentId: null, recurrence: null, + }); + }); + + it('accepts the initialMerge task payload (undefined fields dropped on the wire)', () => { + const d = taskCreateData.parse(wire({ + title: 'Sous-tâche', notes: 'n', completed: true, priority: 2, + dueDate: DATE, listId: LIST_ID, parentId: PARENT_ID, position: 4, recurrence: 'weekly', + })); + expect(d).toEqual({ + title: 'Sous-tâche', notes: 'n', priority: 2, dueDate: new Date(DATE), + listId: LIST_ID, parentId: PARENT_ID, position: 4, recurrence: 'weekly', + }); + }); + + it('accepts the updateTask payload', () => { + const d = taskUpdateData.parse(wire({ + id: ID, title: 'Lait', notes: 'bio', completed: true, completedAt: DATE, priority: 3, + dueDate: DATE, listId: LIST_ID, parentId: null, recurrence: null, + })); + expect(d).toEqual({ + title: 'Lait', notes: 'bio', completed: true, completedAt: new Date(DATE), priority: 3, + dueDate: new Date(DATE), listId: LIST_ID, parentId: null, recurrence: null, + }); + }); + + it('accepts the local inbox id as a reference', () => { + const d = taskCreateData.parse({ listId: '00000000-0000-0000-0000-000000000001' }); + expect(d.listId).toBe('00000000-0000-0000-0000-000000000001'); + }); + + it('strips forbidden keys', () => { + expectNoForbiddenKeys(taskUpdateData.parse({ ...FORBIDDEN, title: 'x' })); + expectNoForbiddenKeys(taskCreateData.parse({ ...FORBIDDEN, listId: LIST_ID })); + }); + + it('keeps 10000-char notes and truncates beyond', () => { + expect(taskUpdateData.parse({ notes: 'n'.repeat(10000) }).notes).toHaveLength(10000); + expect(taskUpdateData.parse({ notes: 'n'.repeat(10001) }).notes).toHaveLength(10000); + }); + + it('truncates a long title', () => { + expect(taskCreateData.parse({ listId: LIST_ID, title: 't'.repeat(501) }).title).toHaveLength(500); + }); + + it('turns a null listId into undefined on update', () => { + expect(taskUpdateData.parse({ listId: null }).listId).toBeUndefined(); + }); + + it('requires listId on create', () => { + expect(() => taskCreateData.parse({ title: 'x' })).toThrow(); + expect(() => taskCreateData.parse({ title: 'x', listId: null })).toThrow(); + }); + + it('rejects invalid dates and wrong types', () => { + expect(() => taskUpdateData.parse({ dueDate: 'tomorrow' })).toThrow(); + expect(() => taskUpdateData.parse({ dueDate: 1760875200000 })).toThrow(); + expect(() => taskUpdateData.parse({ completedAt: '2026-10-19T12:00:00+02:00' })).toThrow(); + expect(() => taskUpdateData.parse({ parentId: 'not-a-uuid' })).toThrow(); + expect(() => taskUpdateData.parse({ priority: 1.5 })).toThrow(); + expect(() => taskUpdateData.parse({ completed: 'true' })).toThrow(); + }); +}); + +describe('tag data', () => { + it('accepts the createTag / updateTag payload and drops id', () => { + const payload = wire({ id: TAG_ID, name: 'urgent', color: '#E57373' }); + expect(tagCreateData.parse(payload)).toEqual({ name: 'urgent', color: '#E57373' }); + expect(tagUpdateData.parse(payload)).toEqual({ name: 'urgent', color: '#E57373' }); + }); + + it('strips forbidden keys', () => { + expectNoForbiddenKeys(tagUpdateData.parse({ ...FORBIDDEN, name: 'x' })); + }); + + it('turns a null color into undefined (NOT NULL column)', () => { + expect(tagUpdateData.parse({ color: null }).color).toBeUndefined(); + }); + + it('truncates a long name', () => { + expect(tagCreateData.parse({ name: 'a'.repeat(101) }).name).toHaveLength(100); + }); +}); + +describe('taskTag data', () => { + it('accepts the setTagsForTask payload', () => { + expect(taskTagData.parse({ tagId: TAG_ID })).toEqual({ tagId: TAG_ID }); + }); + + it('strips forbidden keys and requires tagId', () => { + expectNoForbiddenKeys(taskTagData.parse({ ...FORBIDDEN, tagId: TAG_ID })); + expect(() => taskTagData.parse({})).toThrow(); + }); +}); diff --git a/web/src/lib/syncData.ts b/web/src/lib/syncData.ts new file mode 100644 index 0000000..e1e8907 --- /dev/null +++ b/web/src/lib/syncData.ts @@ -0,0 +1,76 @@ +import { z } from 'zod'; + +// Schemas for the `data` field of a sync operation (POST /api/sync). +// +// Each schema lists the columns a client may write for one entity and action. +// Objects are NOT strict: unknown keys (userId, id, deletedAt, createdAt...) +// are stripped instead of rejected. The mobile app marks its whole outbox as +// synced once the push returns 200, so a rejected operation is lost silently; +// stripping keeps older app versions working while never writing those keys. +// +// Strings are truncated rather than rejected for the same reason. Limits +// follow the mobile app (notes go up to 10000 there, unlike the REST schema). + +const text = (max: number) => z.string().transform((s) => s.slice(0, max)); + +// NOT NULL column: null means "leave untouched" (or DB default on insert). +const notNull = (schema: T) => + schema.nullish().transform((v) => v ?? undefined); + +// Nullable column: null clears it, undefined leaves it untouched. +const nullable = (schema: T) => schema.nullable().optional(); + +const isoDate = z.iso.datetime().transform((s) => new Date(s)); + +// Format check only; ownership is verified against the database by the route. +// z.guid() rather than z.uuid(): the latter rejects non-RFC ids. +const ref = z.guid(); + +export const listCreateData = z.object({ + name: notNull(text(200)), + color: nullable(text(20)), + icon: nullable(text(50)), + position: notNull(z.number().int()), + isInbox: notNull(z.boolean()), +}); + +export const listUpdateData = z.object({ + name: notNull(text(200)), + color: nullable(text(20)), + icon: nullable(text(50)), + position: notNull(z.number().int()), +}); + +const taskFields = { + title: notNull(text(500)), + notes: nullable(text(10000)), + priority: notNull(z.number().int()), + dueDate: nullable(isoDate), + parentId: nullable(ref), + recurrence: nullable(text(100)), + position: notNull(z.number().int()), +}; + +// completed / completedAt are sent by the app on create but not stored (#142, out of scope). +export const taskCreateData = z.object({ + ...taskFields, + listId: ref, +}); + +export const taskUpdateData = z.object({ + ...taskFields, + listId: notNull(ref), + completed: notNull(z.boolean()), + completedAt: nullable(isoDate), +}); + +export const tagCreateData = z.object({ + name: notNull(text(100)), + color: notNull(text(20)), +}); + +export const tagUpdateData = tagCreateData; + +export const taskTagData = z.object({ + tagId: ref, +}); -- 2.52.0 From fdd4c95f7eb6e0be8a421164f5c752291a285b01 Mon Sep 17 00:00:00 2001 From: le king fu Date: Tue, 20 Oct 2026 21:14:21 -0400 Subject: [PATCH 2/4] test(sync): cover account isolation of POST /api/sync on the real route The ownership checks added for #142 were only proven by benches kept out of the repo: removing one left `npm test` green. route.test.ts runs the real POST handler against PGlite (in-memory Postgres, migrations 0000-0002 applied) with two accounts: an initialMerge batch, userId and other forbidden keys in data, task-tag links, task listId/parentId, and list creation with an id held by another account. Each of the 11 route guards, when removed, turns 1 to 4 tests red; 12 of 14 fail on master's route. PGlite is installed under the npm alias `electric-sql-pglite`. Under its real name it satisfies drizzle-orm's optional peer, npm then counts it in the production tree and `npm ci --omit=dev` would ship 35 MB in the image. vitest.config.mts maps the real name to the alias and inlines drizzle-orm so its pglite driver picks it up. Refs #142 Co-Authored-By: Claude Opus 5.5 --- REVIEW.md | 2 +- web/package-lock.json | 9 ++ web/package.json | 1 + web/src/app/api/sync/route.test.ts | 198 +++++++++++++++++++++++++++++ web/vitest.config.mts | 19 +++ 5 files changed, 228 insertions(+), 1 deletion(-) create mode 100644 web/src/app/api/sync/route.test.ts create mode 100644 web/vitest.config.mts diff --git a/REVIEW.md b/REVIEW.md index 183d7ac..578dad8 100644 --- a/REVIEW.md +++ b/REVIEW.md @@ -166,7 +166,7 @@ Companion web, depuis `web/` : ```bash npm ci -npm test # vitest : schémas de données de sync (web/src/lib/syncData.test.ts) +npm test # vitest : schémas de sync (syncData.test.ts) et isolation des comptes sur la vraie route, PGlite en mémoire (api/sync/route.test.ts) npx tsc --noEmit npm run lint npm run build diff --git a/web/package-lock.json b/web/package-lock.json index afa7702..658ceed 100644 --- a/web/package-lock.json +++ b/web/package-lock.json @@ -30,6 +30,7 @@ "@types/react-dom": "^19", "@types/ws": "^8.18.1", "drizzle-kit": "^0.31.10", + "electric-sql-pglite": "npm:@electric-sql/pglite@^0.5.10", "eslint": "^9", "eslint-config-next": "16.2.2", "tailwindcss": "^4", @@ -4421,6 +4422,14 @@ "node": ">= 0.4" } }, + "node_modules/electric-sql-pglite": { + "name": "@electric-sql/pglite", + "version": "0.5.10", + "resolved": "https://registry.npmjs.org/@electric-sql/pglite/-/pglite-0.5.10.tgz", + "integrity": "sha512-tXc/25U3ulOkiRQuTFdwIv+JhBqtMdAF7Gvo6CfZZWtSB4+hgC4Wr2vwK5ngvvN5PJfAAEGIsfyCVy1JhCOBYw==", + "dev": true, + "license": "Apache-2.0" + }, "node_modules/electron-to-chromium": { "version": "1.5.331", "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.331.tgz", diff --git a/web/package.json b/web/package.json index 261006b..1fb952e 100644 --- a/web/package.json +++ b/web/package.json @@ -32,6 +32,7 @@ "@types/react-dom": "^19", "@types/ws": "^8.18.1", "drizzle-kit": "^0.31.10", + "electric-sql-pglite": "npm:@electric-sql/pglite@^0.5.10", "eslint": "^9", "eslint-config-next": "16.2.2", "tailwindcss": "^4", diff --git a/web/src/app/api/sync/route.test.ts b/web/src/app/api/sync/route.test.ts new file mode 100644 index 0000000..7878d36 --- /dev/null +++ b/web/src/app/api/sync/route.test.ts @@ -0,0 +1,198 @@ +import fs from 'node:fs'; +import path from 'node:path'; +import { randomUUID as u } from 'node:crypto'; +import { describe, it, expect, beforeAll, vi } from 'vitest'; +import type { PGlite } from 'electric-sql-pglite'; + +// Account-isolation tests for POST /api/sync (#142): the real route handler +// runs against an in-memory Postgres (PGlite) with the companion migrations, +// and two accounts. Auth and rate limiting are stubbed; they are not under test. + +const h = await vi.hoisted(async () => { + const { PGlite } = await import('electric-sql-pglite'); + return { pg: new PGlite() as PGlite, userId: '' }; +}); + +vi.mock('@/db/client', async () => { + const { drizzle } = await import('drizzle-orm/pglite'); + const schema = await import('@/db/schema'); + return { db: drizzle(h.pg, { schema }) }; +}); + +vi.mock('@/lib/api', () => ({ + requireAuth: async () => ({ userId: h.userId }), + parseBody: async (request: Request, parse: (d: unknown) => T) => { + try { + return { data: parse(await request.json()) }; + } catch (e) { + return { error: new Response(String(e), { status: 400 }) }; + } + }, +})); + +vi.mock('@/lib/rateLimit', () => ({ rateLimit: () => null })); + +const { POST } = await import('./route'); + +type Op = [entityType: string, action: string, entityId: string, data?: Record]; + +async function push(userId: string, ops: Op[]): Promise { + h.userId = userId; + const operations = ops.map(([entityType, action, entityId, data]) => ({ + idempotencyKey: u(), entityType, action, entityId, ...(data ? { data } : {}), + })); + const res = await POST(new Request('http://localhost/api/sync', { + method: 'POST', + body: JSON.stringify({ operations }), + })); + expect(res.status).toBe(200); + const body = await res.json() as { results: { status: string }[] }; + return body.results.map((r) => r.status); +} + +async function row>(sql: string, params: unknown[]): Promise { + return (await h.pg.query(sql, params)).rows[0]; +} + +const D = '2026-10-19T12:00:00.000Z'; +const A = { inbox: u(), list: u(), task: u(), tag: u() }; +const B = { inbox: u(), list: u(), task: u(), tag: u(), sub: u(), parent: u() }; + +beforeAll(async () => { + const dir = path.join(__dirname, '../../../db/migrations'); + for (const f of fs.readdirSync(dir).filter((f) => f.endsWith('.sql')).sort()) { + for (const stmt of fs.readFileSync(path.join(dir, f), 'utf8').split('--> statement-breakpoint')) { + if (stmt.trim()) await h.pg.exec(stmt); + } + } + + // Payload shapes copied from src/db/repository/* and initialMerge (src/services/syncClient.ts) + expect(await push('userA', [ + ['list', 'create', A.inbox, { name: 'Inbox', color: '#4A90A4', icon: 'inbox', position: 0, isInbox: true }], + ['list', 'create', A.list, { id: A.list, name: 'A list', color: null, icon: null, position: 1, isInbox: false }], + ['task', 'create', A.task, { id: A.task, title: 'A task', notes: null, completed: false, completedAt: null, priority: 0, dueDate: null, listId: A.list, parentId: null, recurrence: null }], + ['tag', 'create', A.tag, { id: A.tag, name: 'a-tag', color: '#E57373' }], + ['taskTag', 'create', A.task, { tagId: A.tag }], + ])).toEqual(Array(5).fill('applied')); +}); + +describe('POST /api/sync: payloads the app sends today', () => { + it('applies an initialMerge batch (nulls, 10000-char notes, subtask before its parent)', async () => { + const results = await push('userB', [ + ['list', 'create', B.inbox, { name: 'Inbox', color: null, icon: null, position: 0, isInbox: true }], + ['list', 'create', B.list, { id: B.list, name: 'B list', color: null, icon: null, position: 1, isInbox: false }], + ['list', 'update', B.list, { id: B.list, name: 'B list 2', color: '#C17767', icon: null }], + ['task', 'create', B.task, { id: B.task, title: 'B task', notes: null, completed: false, completedAt: null, priority: 1, dueDate: D, listId: B.inbox, parentId: null, recurrence: null }], + ['task', 'create', B.sub, { title: 'B sub', completed: false, priority: 0, listId: B.list, parentId: B.parent, position: 0 }], + ['task', 'create', B.parent, { title: 'B parent', completed: false, priority: 0, listId: B.list, position: 1 }], + ['task', 'update', B.task, { id: B.task, title: 'B task', notes: 'n'.repeat(10000), completed: true, completedAt: D, priority: 3, dueDate: null, listId: B.inbox, parentId: null, recurrence: 'weekly' }], + ['tag', 'create', B.tag, { id: B.tag, name: 'b-tag', color: '#8BA889' }], + ['tag', 'update', B.tag, { id: B.tag, name: 'b-tag-2', color: '#7B68EE' }], + ['taskTag', 'create', B.task, { tagId: B.tag }], + ]); + expect(results).toEqual(Array(10).fill('applied')); + expect(await row('select length(notes) n, completed from sl_tasks where id=$1', [B.task])) + .toEqual({ n: 10000, completed: true }); + expect(await row('select parent_id from sl_tasks where id=$1', [B.sub])).toEqual({ parent_id: B.parent }); + }); +}); + +describe('POST /api/sync: mass assignment', () => { + it('does not move a list to another account through data.userId', async () => { + expect(await push('userB', [['list', 'update', B.list, { userId: 'userA', name: 'moved?' }]])).toEqual(['applied']); + expect(await row('select user_id, name from sl_lists where id=$1', [B.list])) + .toEqual({ user_id: 'userB', name: 'moved?' }); + }); + + it('ignores userId, id, createdAt, deletedAt and isInbox on list, task and tag updates', async () => { + const evil = { userId: 'userA', id: u(), createdAt: '2000-01-01T00:00:00.000Z', deletedAt: D, isInbox: true }; + expect(await push('userB', [ + ['list', 'update', B.list, { ...evil, name: 'renamed' }], + ['task', 'update', B.task, { ...evil, title: 'renamed' }], + ['tag', 'update', B.tag, { ...evil, name: 'renamed' }], + ])).toEqual(['applied', 'applied', 'applied']); + for (const [table, id] of [['sl_lists', B.list], ['sl_tasks', B.task], ['sl_tags', B.tag]]) { + const r = await row<{ user_id: string; deleted_at: Date | null; created_at: Date }>( + `select user_id, deleted_at, created_at from ${table} where id=$1`, [id]); + expect(r?.user_id).toBe('userB'); + expect(r?.deleted_at).toBeNull(); + expect(r?.created_at.getFullYear()).toBeGreaterThan(2000); + } + expect(await row('select is_inbox from sl_lists where id=$1', [B.list])).toEqual({ is_inbox: false }); + }); + + it('applies a tag update carrying only forbidden keys without writing anything', async () => { + expect(await push('userB', [['tag', 'update', B.tag, { userId: 'userA' }]])).toEqual(['applied']); + expect(await row('select user_id, name from sl_tags where id=$1', [B.tag])).toEqual({ user_id: 'userB', name: 'renamed' }); + }); +}); + +describe('POST /api/sync: task-tag links', () => { + it('refuses a link to another account\'s task', async () => { + expect(await push('userB', [['taskTag', 'create', A.task, { tagId: B.tag }]])).toEqual(['skipped']); + expect(await row('select count(*)::int c from sl_task_tags where task_id=$1 and tag_id=$2', [A.task, B.tag])).toEqual({ c: 0 }); + }); + + it('refuses a link to another account\'s tag', async () => { + expect(await push('userB', [['taskTag', 'create', B.task, { tagId: A.tag }]])).toEqual(['skipped']); + expect(await row('select count(*)::int c from sl_task_tags where task_id=$1 and tag_id=$2', [B.task, A.tag])).toEqual({ c: 0 }); + }); + + it('refuses to delete another account\'s link', async () => { + expect(await push('userB', [['taskTag', 'delete', A.task, { tagId: A.tag }]])).toEqual(['skipped']); + expect(await row('select count(*)::int c from sl_task_tags where task_id=$1 and tag_id=$2', [A.task, A.tag])).toEqual({ c: 1 }); + }); +}); + +describe('POST /api/sync: task references', () => { + it('refuses a task created in another account\'s list', async () => { + const id = u(); + expect(await push('userB', [['task', 'create', id, { title: 'x', listId: A.list }]])).toEqual(['skipped']); + expect(await row('select count(*)::int c from sl_tasks where id=$1', [id])).toEqual({ c: 0 }); + }); + + it('refuses a task created under another account\'s task', async () => { + const id = u(); + expect(await push('userB', [['task', 'create', id, { title: 'x', listId: B.list, parentId: A.task }]])).toEqual(['skipped']); + expect(await row('select count(*)::int c from sl_tasks where id=$1', [id])).toEqual({ c: 0 }); + }); + + it('refuses moving a task into another account\'s list or under its task', async () => { + expect(await push('userB', [ + ['task', 'update', B.task, { listId: A.list }], + ['task', 'update', B.task, { parentId: A.task }], + ])).toEqual(['skipped', 'skipped']); + expect(await row('select list_id, parent_id from sl_tasks where id=$1', [B.task])) + .toEqual({ list_id: B.inbox, parent_id: null }); + }); + + it('still lets the owner move a task between its own lists', async () => { + expect(await push('userB', [['task', 'update', B.sub, { listId: B.inbox }]])).toEqual(['applied']); + expect(await row('select list_id from sl_tasks where id=$1', [B.sub])).toEqual({ list_id: B.inbox }); + }); +}); + +describe('POST /api/sync: list creation with an id taken by another account', () => { + it('refuses an inbox create before moving tasks or archiving the caller\'s inbox', async () => { + expect(await push('userB', [['list', 'create', A.list, { name: 'hijack', isInbox: true }]])).toEqual(['skipped']); + expect(await row('select deleted_at from sl_lists where id=$1', [B.inbox])).toEqual({ deleted_at: null }); + expect(await row('select list_id from sl_tasks where id=$1', [B.task])).toEqual({ list_id: B.inbox }); + expect(await row('select user_id, name from sl_lists where id=$1', [A.list])).toEqual({ user_id: 'userA', name: 'A list' }); + }); + + it('refuses a regular list create', async () => { + expect(await push('userB', [['list', 'create', A.inbox, { name: 'hijack' }]])).toEqual(['skipped']); + expect(await row('select user_id, name from sl_lists where id=$1', [A.inbox])).toEqual({ user_id: 'userA', name: 'Inbox' }); + }); +}); + +describe('POST /api/sync: owner deletes', () => { + it('applies deletes of the caller\'s own rows and links', async () => { + expect(await push('userB', [ + ['taskTag', 'delete', B.task, { tagId: B.tag }], + ['task', 'delete', B.sub, { id: B.sub }], + ['tag', 'delete', B.tag, { id: B.tag }], + ])).toEqual(['applied', 'applied', 'applied']); + expect(await row('select count(*)::int c from sl_task_tags where task_id=$1', [B.task])).toEqual({ c: 0 }); + }); +}); diff --git a/web/vitest.config.mts b/web/vitest.config.mts new file mode 100644 index 0000000..30a25e0 --- /dev/null +++ b/web/vitest.config.mts @@ -0,0 +1,19 @@ +import { fileURLToPath } from 'node:url'; +import { defineConfig } from 'vitest/config'; + +export default defineConfig({ + resolve: { + alias: [ + // Mirrors the `@/*` path of tsconfig.json so tests can import route handlers. + { find: /^@\//, replacement: fileURLToPath(new URL('./src/', import.meta.url)) }, + // PGlite is installed under an npm alias (devDependency `electric-sql-pglite`): + // under its real name it would satisfy drizzle-orm's optional peer and land + // in the production image (`npm ci --omit=dev`), 35 MB for a test database. + { find: /^@electric-sql\/pglite$/, replacement: 'electric-sql-pglite' }, + ], + }, + test: { + // drizzle-orm/pglite imports `@electric-sql/pglite`: inline it so the alias applies. + server: { deps: { inline: ['drizzle-orm'] } }, + }, +}); -- 2.52.0 From e8abcfc21798c3ba51e5e83ce2c8c8fc4389d24f Mon Sep 17 00:00:00 2001 From: le king fu Date: Wed, 21 Oct 2026 19:36:35 -0400 Subject: [PATCH 3/4] fix(sync): require an existing parent and order each pushed batch Decision from Max (2026-10-21, /pr-brief of PR #144): a subtask whose parent does not exist on the server is refused, instead of accepted when no other account holds the id. initialMerge pushes every local task in one batch, in SQLite order, so a subtask could come before its parent. orderSyncOperations moves a subtask create right after the create of its parent when both are in the batch (nested subtasks and cycles handled); every other operation keeps its relative order. A parent sent in a later batch is not found and the subtask is skipped, which Max accepted. Refs #142 Co-Authored-By: Claude Opus 5.5 --- REVIEW.md | 2 +- web/src/app/api/sync/route.test.ts | 11 +++++++ web/src/app/api/sync/route.ts | 14 ++++---- web/src/lib/syncData.test.ts | 46 ++++++++++++++++++++++++++ web/src/lib/syncData.ts | 52 ++++++++++++++++++++++++++++++ 5 files changed, 117 insertions(+), 8 deletions(-) diff --git a/REVIEW.md b/REVIEW.md index 578dad8..05dcc3e 100644 --- a/REVIEW.md +++ b/REVIEW.md @@ -91,7 +91,7 @@ Chaque règle cite sa source. Elles valent quel que soit le niveau : une PR norm - Toute lecture et toute écriture filtrent sur `userId = auth.userId` ; une mise à jour ou une suppression vérifie d'abord la propriété (`verifyOwnership`). Une jointure (étiquettes d'une tâche) vérifie la propriété des deux côtés. — `web/src/app/api/sync/route.ts`, `web/src/app/api/tasks/[id]/route.ts` - Le corps est validé par un schéma zod `.strict()`. Exception : `data` d'une opération de sync passe par un schéma par entité et par action (`web/src/lib/syncData.ts`), sans `.strict()` : les clés hors liste sont retirées, pas rejetées, parce que l'app marque son outbox comme synchronisée dès que le push répond 200 et qu'une opération `skipped` serait perdue. Ces schémas ne nomment jamais `id`, `userId`, `createdAt`, `updatedAt` ni `deletedAt`, et `processOperation` n'écrit que leur sortie. Une colonne ajoutée côté app l'est aussi dans le schéma, sinon elle est ignorée en silence. — `web/src/lib/syncData.ts`, `web/src/app/api/sync/route.ts`, #142 -- Une référence reçue du client (`listId`, `parentId`, `tagId`, l'id d'une liste créée) est vérifiée contre le compte de l'appelant avant l'écriture. `parentId` et l'id d'une création refusent seulement un id pris par un autre compte, sans exiger que la ligne existe : `initialMerge` pousse tout en un lot, une sous-tâche peut arriver avant son parent. — `web/src/app/api/sync/route.ts`, #142 +- Une référence reçue du client (`listId`, `parentId`, `tagId`, l'id d'une liste créée) est vérifiée contre le compte de l'appelant avant l'écriture. `listId` et `parentId` doivent exister et appartenir à l'appelant (décision de Max du 2026-10-21, `/pr-brief` de la PR #144) : `initialMerge` pousse tout en un lot, donc le serveur range chaque lot pour qu'un parent créé dans le même lot passe avant ses sous-tâches (`orderSyncOperations`). L'id d'une liste créée refuse seulement un id pris par un autre compte. — `web/src/app/api/sync/route.ts`, `web/src/lib/syncData.ts`, #142 - Limites de débit par utilisateur et par catégorie (`sync`, `create`, `read`, `ws-ticket`) ; une route ajoutée en prend une. Le store est en mémoire : il repart à zéro à chaque redémarrage. — `web/src/lib/rateLimit.ts` - WebSocket : ticket à usage unique de 30 s, origines autorisées listées, revalidation toutes les 15 min ; aucun paramètre de requête de `/ws` n'est journalisé. — `web/src/lib/ws.ts`, `web/src/app/api/ws-ticket/route.ts`, `web/server.ts` - Une route de diagnostic (`/api/debug`) ne renvoie que les données de la session qui l'appelle, jamais de secret ni de valeur de cookie. — `web/src/app/api/debug/route.ts` diff --git a/web/src/app/api/sync/route.test.ts b/web/src/app/api/sync/route.test.ts index 7878d36..b9d24de 100644 --- a/web/src/app/api/sync/route.test.ts +++ b/web/src/app/api/sync/route.test.ts @@ -157,6 +157,17 @@ describe('POST /api/sync: task references', () => { expect(await row('select count(*)::int c from sl_tasks where id=$1', [id])).toEqual({ c: 0 }); }); + it('refuses a subtask whose parent does not exist', async () => { + const id = u(); + expect(await push('userB', [['task', 'create', id, { title: 'orphan', listId: B.list, parentId: u() }]])).toEqual(['skipped']); + expect(await row('select count(*)::int c from sl_tasks where id=$1', [id])).toEqual({ c: 0 }); + }); + + it('refuses moving a task under a parent that does not exist', async () => { + expect(await push('userB', [['task', 'update', B.task, { parentId: u() }]])).toEqual(['skipped']); + expect(await row('select parent_id from sl_tasks where id=$1', [B.task])).toEqual({ parent_id: null }); + }); + it('refuses moving a task into another account\'s list or under its task', async () => { expect(await push('userB', [ ['task', 'update', B.task, { listId: A.list }], diff --git a/web/src/app/api/sync/route.ts b/web/src/app/api/sync/route.ts index cb14996..69062f5 100644 --- a/web/src/app/api/sync/route.ts +++ b/web/src/app/api/sync/route.ts @@ -6,6 +6,7 @@ import { requireAuth, parseBody } from '@/lib/api'; import { rateLimit } from '@/lib/rateLimit'; import { syncPushSchema, type SyncOperation } from '@/lib/validators'; import { + orderSyncOperations, listCreateData, listUpdateData, taskCreateData, @@ -170,7 +171,7 @@ export async function POST(request: Request) { const results: { idempotencyKey: string; status: 'applied' | 'skipped'; error?: string }[] = []; - for (const op of body.data.operations) { + for (const op of orderSyncOperations(body.data.operations)) { const storeKey = `${auth.userId}:${op.idempotencyKey}`; // Check idempotency @@ -262,9 +263,9 @@ async function processOperation(op: SyncOperation, userId: string) { if (action === 'create') { const d = taskCreateData.parse(data); await verifyOwnership(slLists, d.listId, userId); - // Not verifyOwnership: initialMerge pushes all tasks in one batch, a - // subtask may arrive before its parent (parent_id has no FK). - if (d.parentId) await assertIdNotTaken(slTasks, d.parentId, userId); + // The parent must already exist: POST orders each batch so that a + // parent created in the same batch comes first (orderSyncOperations). + if (d.parentId) await verifyOwnership(slTasks, d.parentId, userId); await db.insert(slTasks).values({ id: entityId, userId, @@ -281,7 +282,7 @@ async function processOperation(op: SyncOperation, userId: string) { const d = taskUpdateData.parse(data); await verifyOwnership(slTasks, entityId, userId); if (d.listId) await verifyOwnership(slLists, d.listId, userId); - if (d.parentId) await assertIdNotTaken(slTasks, d.parentId, userId); + if (d.parentId) await verifyOwnership(slTasks, d.parentId, userId); await db.update(slTasks) .set({ ...d, updatedAt: now }) .where(and(eq(slTasks.id, entityId), eq(slTasks.userId, userId))); @@ -354,8 +355,7 @@ async function verifyTagOwnership(entityId: string, userId: string) { } // Refuse an id that already exists under another account. Unlike -// verifyOwnership, a missing row passes: the id may be created later in the -// same batch (a subtask pushed before its parent), or by this very insert. +// verifyOwnership, a missing row passes: the insert that follows creates it. // eslint-disable-next-line @typescript-eslint/no-explicit-any async function assertIdNotTaken(table: any, id: string, userId: string) { const [row] = await db diff --git a/web/src/lib/syncData.test.ts b/web/src/lib/syncData.test.ts index 3d54154..a23f0c1 100644 --- a/web/src/lib/syncData.test.ts +++ b/web/src/lib/syncData.test.ts @@ -7,6 +7,7 @@ import { tagCreateData, tagUpdateData, taskTagData, + orderSyncOperations, } from './syncData'; const ID = '3f1c2b7a-9d4e-4c1a-8b2f-5e6d7c8b9a01'; @@ -186,3 +187,48 @@ describe('taskTag data', () => { expect(() => taskTagData.parse({})).toThrow(); }); }); + +describe('orderSyncOperations', () => { + const op = (entityType: string, action: string, entityId: string, data?: Record) => + ({ entityType, action, entityId, data }); + const ids = (ops: { entityId: string; action: string }[]) => ops.map((o) => `${o.action}:${o.entityId}`); + + it('moves a subtask create right after the create of its parent', () => { + const ops = [ + op('list', 'create', 'L'), + op('task', 'create', 'sub', { parentId: 'P' }), + op('task', 'create', 'other'), + op('task', 'create', 'P'), + op('taskTag', 'create', 'sub', { tagId: 'T' }), + ]; + expect(ids(orderSyncOperations(ops))).toEqual(['create:L', 'create:other', 'create:P', 'create:sub', 'create:sub']); + }); + + it('handles nested subtasks in reverse order', () => { + const ops = [ + op('task', 'create', 'c', { parentId: 'b' }), + op('task', 'create', 'b', { parentId: 'a' }), + op('task', 'create', 'a'), + ]; + expect(ids(orderSyncOperations(ops))).toEqual(['create:a', 'create:b', 'create:c']); + }); + + it('keeps the order when the parent is not created in the batch, or already came first', () => { + const ops = [ + op('task', 'create', 'P'), + op('task', 'create', 'sub', { parentId: 'P' }), + op('task', 'create', 'orphan', { parentId: 'elsewhere' }), + op('task', 'update', 'x', { parentId: 'P' }), + ]; + expect(orderSyncOperations(ops)).toEqual(ops); + }); + + it('keeps every operation of a parent cycle', () => { + const ops = [ + op('task', 'create', 'a', { parentId: 'b' }), + op('task', 'create', 'b', { parentId: 'a' }), + op('tag', 'create', 't'), + ]; + expect(ids(orderSyncOperations(ops)).sort()).toEqual(['create:a', 'create:b', 'create:t']); + }); +}); diff --git a/web/src/lib/syncData.ts b/web/src/lib/syncData.ts index e1e8907..045d990 100644 --- a/web/src/lib/syncData.ts +++ b/web/src/lib/syncData.ts @@ -74,3 +74,55 @@ export const tagUpdateData = tagCreateData; export const taskTagData = z.object({ tagId: ref, }); + +type OrderableOp = { + entityType: string; + action: string; + entityId: string; + data?: Record; +}; + +/** + * Order a pushed batch so that a subtask create comes right after the create + * of its parent when both are in the batch. initialMerge sends every local + * task in one go, in SQLite order, and the route requires an existing parent + * owned by the caller (#142). Other operations keep their relative order. + * A subtask whose parent is not created in the batch keeps its place. + */ +export function orderSyncOperations(ops: T[]): T[] { + const parentOf = (op: T): string | undefined => + op.entityType === 'task' && op.action === 'create' && typeof op.data?.parentId === 'string' + ? op.data.parentId + : undefined; + + const createdTasks = new Set( + ops.filter((op) => op.entityType === 'task' && op.action === 'create').map((op) => op.entityId), + ); + const done = new Set(); + const waiting = new Map(); + const ordered: T[] = []; + + const emit = (op: T) => { + ordered.push(op); + if (op.entityType !== 'task' || op.action !== 'create') return; + done.add(op.entityId); + const children = waiting.get(op.entityId) ?? []; + waiting.delete(op.entityId); + children.forEach(emit); + }; + + for (const op of ops) { + const parent = parentOf(op); + if (parent && parent !== op.entityId && createdTasks.has(parent) && !done.has(parent)) { + waiting.set(parent, [...(waiting.get(parent) ?? []), op]); + } else { + emit(op); + } + } + // Cycles (a task listed as the parent of its own parent): keep them, in order. + const emitted = new Set(ordered); + for (const op of ops) { + if (!emitted.has(op)) ordered.push(op); + } + return ordered; +} -- 2.52.0 From c923485fd730eb4b69c1317a30adb7cf58d6fff0 Mon Sep 17 00:00:00 2001 From: le king fu Date: Wed, 21 Oct 2026 19:47:17 -0400 Subject: [PATCH 4/4] revert: drop the strict parent check and batch ordering (e8abcfc) Decision from Max (2026-10-21, after review comment 26317): forget the parent existence check altogether. The review found that orderSyncOperations was quadratic and synchronous, so one authenticated request of a few MB could freeze the companion for every account, and that the strict check on updates would silently refuse every edit of a subtask already stored without its parent. The tree is back to fdd4c95 (approved in comment 26259): a parentId held by another account is still refused (assertIdNotTaken), a missing parent is accepted as before. This reverts commit e8abcfc21798c3ba51e5e83ce2c8c8fc4389d24f. Refs #142 Co-Authored-By: Claude Opus 5.5 --- REVIEW.md | 2 +- web/src/app/api/sync/route.test.ts | 11 ------- web/src/app/api/sync/route.ts | 14 ++++---- web/src/lib/syncData.test.ts | 46 -------------------------- web/src/lib/syncData.ts | 52 ------------------------------ 5 files changed, 8 insertions(+), 117 deletions(-) diff --git a/REVIEW.md b/REVIEW.md index 05dcc3e..578dad8 100644 --- a/REVIEW.md +++ b/REVIEW.md @@ -91,7 +91,7 @@ Chaque règle cite sa source. Elles valent quel que soit le niveau : une PR norm - Toute lecture et toute écriture filtrent sur `userId = auth.userId` ; une mise à jour ou une suppression vérifie d'abord la propriété (`verifyOwnership`). Une jointure (étiquettes d'une tâche) vérifie la propriété des deux côtés. — `web/src/app/api/sync/route.ts`, `web/src/app/api/tasks/[id]/route.ts` - Le corps est validé par un schéma zod `.strict()`. Exception : `data` d'une opération de sync passe par un schéma par entité et par action (`web/src/lib/syncData.ts`), sans `.strict()` : les clés hors liste sont retirées, pas rejetées, parce que l'app marque son outbox comme synchronisée dès que le push répond 200 et qu'une opération `skipped` serait perdue. Ces schémas ne nomment jamais `id`, `userId`, `createdAt`, `updatedAt` ni `deletedAt`, et `processOperation` n'écrit que leur sortie. Une colonne ajoutée côté app l'est aussi dans le schéma, sinon elle est ignorée en silence. — `web/src/lib/syncData.ts`, `web/src/app/api/sync/route.ts`, #142 -- Une référence reçue du client (`listId`, `parentId`, `tagId`, l'id d'une liste créée) est vérifiée contre le compte de l'appelant avant l'écriture. `listId` et `parentId` doivent exister et appartenir à l'appelant (décision de Max du 2026-10-21, `/pr-brief` de la PR #144) : `initialMerge` pousse tout en un lot, donc le serveur range chaque lot pour qu'un parent créé dans le même lot passe avant ses sous-tâches (`orderSyncOperations`). L'id d'une liste créée refuse seulement un id pris par un autre compte. — `web/src/app/api/sync/route.ts`, `web/src/lib/syncData.ts`, #142 +- Une référence reçue du client (`listId`, `parentId`, `tagId`, l'id d'une liste créée) est vérifiée contre le compte de l'appelant avant l'écriture. `parentId` et l'id d'une création refusent seulement un id pris par un autre compte, sans exiger que la ligne existe : `initialMerge` pousse tout en un lot, une sous-tâche peut arriver avant son parent. — `web/src/app/api/sync/route.ts`, #142 - Limites de débit par utilisateur et par catégorie (`sync`, `create`, `read`, `ws-ticket`) ; une route ajoutée en prend une. Le store est en mémoire : il repart à zéro à chaque redémarrage. — `web/src/lib/rateLimit.ts` - WebSocket : ticket à usage unique de 30 s, origines autorisées listées, revalidation toutes les 15 min ; aucun paramètre de requête de `/ws` n'est journalisé. — `web/src/lib/ws.ts`, `web/src/app/api/ws-ticket/route.ts`, `web/server.ts` - Une route de diagnostic (`/api/debug`) ne renvoie que les données de la session qui l'appelle, jamais de secret ni de valeur de cookie. — `web/src/app/api/debug/route.ts` diff --git a/web/src/app/api/sync/route.test.ts b/web/src/app/api/sync/route.test.ts index b9d24de..7878d36 100644 --- a/web/src/app/api/sync/route.test.ts +++ b/web/src/app/api/sync/route.test.ts @@ -157,17 +157,6 @@ describe('POST /api/sync: task references', () => { expect(await row('select count(*)::int c from sl_tasks where id=$1', [id])).toEqual({ c: 0 }); }); - it('refuses a subtask whose parent does not exist', async () => { - const id = u(); - expect(await push('userB', [['task', 'create', id, { title: 'orphan', listId: B.list, parentId: u() }]])).toEqual(['skipped']); - expect(await row('select count(*)::int c from sl_tasks where id=$1', [id])).toEqual({ c: 0 }); - }); - - it('refuses moving a task under a parent that does not exist', async () => { - expect(await push('userB', [['task', 'update', B.task, { parentId: u() }]])).toEqual(['skipped']); - expect(await row('select parent_id from sl_tasks where id=$1', [B.task])).toEqual({ parent_id: null }); - }); - it('refuses moving a task into another account\'s list or under its task', async () => { expect(await push('userB', [ ['task', 'update', B.task, { listId: A.list }], diff --git a/web/src/app/api/sync/route.ts b/web/src/app/api/sync/route.ts index 69062f5..cb14996 100644 --- a/web/src/app/api/sync/route.ts +++ b/web/src/app/api/sync/route.ts @@ -6,7 +6,6 @@ import { requireAuth, parseBody } from '@/lib/api'; import { rateLimit } from '@/lib/rateLimit'; import { syncPushSchema, type SyncOperation } from '@/lib/validators'; import { - orderSyncOperations, listCreateData, listUpdateData, taskCreateData, @@ -171,7 +170,7 @@ export async function POST(request: Request) { const results: { idempotencyKey: string; status: 'applied' | 'skipped'; error?: string }[] = []; - for (const op of orderSyncOperations(body.data.operations)) { + for (const op of body.data.operations) { const storeKey = `${auth.userId}:${op.idempotencyKey}`; // Check idempotency @@ -263,9 +262,9 @@ async function processOperation(op: SyncOperation, userId: string) { if (action === 'create') { const d = taskCreateData.parse(data); await verifyOwnership(slLists, d.listId, userId); - // The parent must already exist: POST orders each batch so that a - // parent created in the same batch comes first (orderSyncOperations). - if (d.parentId) await verifyOwnership(slTasks, d.parentId, userId); + // Not verifyOwnership: initialMerge pushes all tasks in one batch, a + // subtask may arrive before its parent (parent_id has no FK). + if (d.parentId) await assertIdNotTaken(slTasks, d.parentId, userId); await db.insert(slTasks).values({ id: entityId, userId, @@ -282,7 +281,7 @@ async function processOperation(op: SyncOperation, userId: string) { const d = taskUpdateData.parse(data); await verifyOwnership(slTasks, entityId, userId); if (d.listId) await verifyOwnership(slLists, d.listId, userId); - if (d.parentId) await verifyOwnership(slTasks, d.parentId, userId); + if (d.parentId) await assertIdNotTaken(slTasks, d.parentId, userId); await db.update(slTasks) .set({ ...d, updatedAt: now }) .where(and(eq(slTasks.id, entityId), eq(slTasks.userId, userId))); @@ -355,7 +354,8 @@ async function verifyTagOwnership(entityId: string, userId: string) { } // Refuse an id that already exists under another account. Unlike -// verifyOwnership, a missing row passes: the insert that follows creates it. +// verifyOwnership, a missing row passes: the id may be created later in the +// same batch (a subtask pushed before its parent), or by this very insert. // eslint-disable-next-line @typescript-eslint/no-explicit-any async function assertIdNotTaken(table: any, id: string, userId: string) { const [row] = await db diff --git a/web/src/lib/syncData.test.ts b/web/src/lib/syncData.test.ts index a23f0c1..3d54154 100644 --- a/web/src/lib/syncData.test.ts +++ b/web/src/lib/syncData.test.ts @@ -7,7 +7,6 @@ import { tagCreateData, tagUpdateData, taskTagData, - orderSyncOperations, } from './syncData'; const ID = '3f1c2b7a-9d4e-4c1a-8b2f-5e6d7c8b9a01'; @@ -187,48 +186,3 @@ describe('taskTag data', () => { expect(() => taskTagData.parse({})).toThrow(); }); }); - -describe('orderSyncOperations', () => { - const op = (entityType: string, action: string, entityId: string, data?: Record) => - ({ entityType, action, entityId, data }); - const ids = (ops: { entityId: string; action: string }[]) => ops.map((o) => `${o.action}:${o.entityId}`); - - it('moves a subtask create right after the create of its parent', () => { - const ops = [ - op('list', 'create', 'L'), - op('task', 'create', 'sub', { parentId: 'P' }), - op('task', 'create', 'other'), - op('task', 'create', 'P'), - op('taskTag', 'create', 'sub', { tagId: 'T' }), - ]; - expect(ids(orderSyncOperations(ops))).toEqual(['create:L', 'create:other', 'create:P', 'create:sub', 'create:sub']); - }); - - it('handles nested subtasks in reverse order', () => { - const ops = [ - op('task', 'create', 'c', { parentId: 'b' }), - op('task', 'create', 'b', { parentId: 'a' }), - op('task', 'create', 'a'), - ]; - expect(ids(orderSyncOperations(ops))).toEqual(['create:a', 'create:b', 'create:c']); - }); - - it('keeps the order when the parent is not created in the batch, or already came first', () => { - const ops = [ - op('task', 'create', 'P'), - op('task', 'create', 'sub', { parentId: 'P' }), - op('task', 'create', 'orphan', { parentId: 'elsewhere' }), - op('task', 'update', 'x', { parentId: 'P' }), - ]; - expect(orderSyncOperations(ops)).toEqual(ops); - }); - - it('keeps every operation of a parent cycle', () => { - const ops = [ - op('task', 'create', 'a', { parentId: 'b' }), - op('task', 'create', 'b', { parentId: 'a' }), - op('tag', 'create', 't'), - ]; - expect(ids(orderSyncOperations(ops)).sort()).toEqual(['create:a', 'create:b', 'create:t']); - }); -}); diff --git a/web/src/lib/syncData.ts b/web/src/lib/syncData.ts index 045d990..e1e8907 100644 --- a/web/src/lib/syncData.ts +++ b/web/src/lib/syncData.ts @@ -74,55 +74,3 @@ export const tagUpdateData = tagCreateData; export const taskTagData = z.object({ tagId: ref, }); - -type OrderableOp = { - entityType: string; - action: string; - entityId: string; - data?: Record; -}; - -/** - * Order a pushed batch so that a subtask create comes right after the create - * of its parent when both are in the batch. initialMerge sends every local - * task in one go, in SQLite order, and the route requires an existing parent - * owned by the caller (#142). Other operations keep their relative order. - * A subtask whose parent is not created in the batch keeps its place. - */ -export function orderSyncOperations(ops: T[]): T[] { - const parentOf = (op: T): string | undefined => - op.entityType === 'task' && op.action === 'create' && typeof op.data?.parentId === 'string' - ? op.data.parentId - : undefined; - - const createdTasks = new Set( - ops.filter((op) => op.entityType === 'task' && op.action === 'create').map((op) => op.entityId), - ); - const done = new Set(); - const waiting = new Map(); - const ordered: T[] = []; - - const emit = (op: T) => { - ordered.push(op); - if (op.entityType !== 'task' || op.action !== 'create') return; - done.add(op.entityId); - const children = waiting.get(op.entityId) ?? []; - waiting.delete(op.entityId); - children.forEach(emit); - }; - - for (const op of ops) { - const parent = parentOf(op); - if (parent && parent !== op.entityId && createdTasks.has(parent) && !done.has(parent)) { - waiting.set(parent, [...(waiting.get(parent) ?? []), op]); - } else { - emit(op); - } - } - // Cycles (a task listed as the parent of its own parent): keep them, in order. - const emitted = new Set(ordered); - for (const op of ops) { - if (!emitted.has(op)) ordered.push(op); - } - return ordered; -} -- 2.52.0