From 9aba692b91f48e3a92c73c4af7d844c21ca13b34 Mon Sep 17 00:00:00 2001 From: Carlos Lopez Date: Tue, 18 Aug 2026 21:09:00 +0200 Subject: [PATCH 1/4] apikeys working --- src/lib/database/schemas.ts | 1 + .../auth/application/apikeys.service.ts | 88 ++++++- .../auth/application/profile.service.ts | 48 +--- src/modules/auth/domain/entities.ts | 2 + src/modules/auth/index.ts | 6 +- .../repositories/apikey.repository.ts | 85 ++++++- src/routes/profile/+page.server.ts | 46 +++- src/routes/profile/+page.svelte | 234 +++++++++++++++--- 8 files changed, 428 insertions(+), 82 deletions(-) diff --git a/src/lib/database/schemas.ts b/src/lib/database/schemas.ts index 8a2ba5f7..697122b2 100644 --- a/src/lib/database/schemas.ts +++ b/src/lib/database/schemas.ts @@ -29,6 +29,7 @@ export const ApiKeyEntity = entity('api_keys', { name: text().notNull(), keyPrefix: text().notNull(), keyHash: text().notNull(), + expiresAt: timestamp(), lastUsedAt: timestamp(), revokedAt: timestamp(), createdAt: timestamp().notNull().$defaultFn(() => new Date().toISOString()), diff --git a/src/modules/auth/application/apikeys.service.ts b/src/modules/auth/application/apikeys.service.ts index 75910007..2d9f6b8b 100644 --- a/src/modules/auth/application/apikeys.service.ts +++ b/src/modules/auth/application/apikeys.service.ts @@ -1,10 +1,94 @@ -import type { AuthUserRepository } from '../domain/repositories'; +import crypto from 'crypto'; +import type { ApiKeyView } from '../domain/entities'; +import { ApiKeyRepository } from '../infrastructure/repositories/apikey.repository'; + +function hashApiKey(token: string): string { + return crypto.createHash('sha256').update(token).digest('hex'); +} export class ApiKeysService { constructor( - private readonly userRepository: AuthUserRepository, + private readonly apiKeyRepository: ApiKeyRepository, ) {} + async listActiveApiKeys(userId: string): Promise { + return this.apiKeyRepository.listByUser(userId); + } + + async createApiKey(userId: string, name: string, expiresAt: string | null): Promise<{ token: string; key: ApiKeyView }> { + const token = `gvs_${crypto.randomBytes(24).toString('hex')}`; + const id = crypto.randomUUID(); + const keyPrefix = token.slice(0, 6); + + await this.apiKeyRepository.create({ + id, + userId, + name, + keyPrefix, + keyHash: hashApiKey(token), + expiresAt, + }); + + return { + token, + key: { + id, + name, + keyPrefix, + expiresAt, + lastUsedAt: null, + createdAt: new Date().toISOString(), + }, + }; + } + + async revokeApiKey(userId: string, keyId: string): Promise { + const existing = await this.apiKeyRepository.findById(userId, keyId); + + if (!existing) { + throw new Error('API key not found'); + } + + if (existing.revokedAt) { + throw new Error('API key is already revoked'); + } + + await this.apiKeyRepository.revoke(userId, keyId); + } + + async regenerateApiKey(userId: string, keyId: string): Promise<{ token: string; key: ApiKeyView }> { + const existing = await this.apiKeyRepository.findById(userId, keyId); + + if (!existing) { + throw new Error('API key not found'); + } + + if (existing.revokedAt) { + throw new Error('API key is revoked'); + } + + const token = `gvs_${crypto.randomBytes(24).toString('hex')}`; + const keyPrefix = token.slice(0, 6); + + await this.apiKeyRepository.updateKeyMaterial(userId, keyId, { + keyPrefix, + keyHash: hashApiKey(token), + expiresAt: existing.expiresAt, + }); + + return { + token, + key: { + id: keyId, + name: existing.name, + keyPrefix, + expiresAt: existing.expiresAt, + lastUsedAt: null, + createdAt: new Date().toISOString(), + }, + }; + } + } \ No newline at end of file diff --git a/src/modules/auth/application/profile.service.ts b/src/modules/auth/application/profile.service.ts index dcadf999..9f11f74b 100644 --- a/src/modules/auth/application/profile.service.ts +++ b/src/modules/auth/application/profile.service.ts @@ -1,16 +1,13 @@ -import crypto from 'crypto'; -import type { ApiKeyView, AuthenticatedUser } from '../domain/entities'; +import type { ApiKeyView } from '../domain/entities'; import { UserRepository } from '../infrastructure/repositories/user.repository'; import { PasswordService } from './password.service'; - -function hashApiKey(token: string): string { - return crypto.createHash('sha256').update(token).digest('hex'); -} +import { ApiKeysService } from './apikeys.service'; export class ProfileService { constructor( private readonly userRepository: UserRepository, private readonly passwordService: PasswordService, + private readonly apiKeysService: ApiKeysService, ) {} async getAuthenticatedUserProfile(userId: string): Promise { @@ -41,41 +38,18 @@ export class ProfileService { } async listActiveApiKeys(userId: string): Promise { - const keys = await this.userRepository.listActiveApiKeys(userId); - return keys.map((key) => ({ - id: key.id, - name: key.name, - keyPrefix: key.keyPrefix, - lastUsedAt: key.lastUsedAt, - createdAt: key.createdAt, - })); + return this.apiKeysService.listActiveApiKeys(userId); } - async createApiKey(userId: string, name: string): Promise<{ token: string; key: ApiKeyView }> { - const token = `gvs_${crypto.randomBytes(24).toString('hex')}`; - const id = crypto.randomUUID(); - - await this.userRepository.createApiKey({ - id, - userId, - name, - keyPrefix: token.slice(0, 10), - keyHash: hashApiKey(token), - }); - - return { - token, - key: { - id, - name, - keyPrefix: token.slice(0, 10), - lastUsedAt: null, - createdAt: new Date().toISOString(), - }, - }; + async createApiKey(userId: string, name: string, expiresAt: string | null): Promise<{ token: string; key: ApiKeyView }> { + return this.apiKeysService.createApiKey(userId, name, expiresAt); } async revokeApiKey(userId: string, keyId: string): Promise { - await this.userRepository.revokeApiKey(userId, keyId); + await this.apiKeysService.revokeApiKey(userId, keyId); + } + + async regenerateApiKey(userId: string, keyId: string): Promise<{ token: string; key: ApiKeyView }> { + return this.apiKeysService.regenerateApiKey(userId, keyId); } } diff --git a/src/modules/auth/domain/entities.ts b/src/modules/auth/domain/entities.ts index e8340679..a897dd4d 100644 --- a/src/modules/auth/domain/entities.ts +++ b/src/modules/auth/domain/entities.ts @@ -52,6 +52,8 @@ export type ApiKeyView = { id: string; name: string; keyPrefix: string; + expiresAt: string | null; lastUsedAt: string | null; + revokedAt: string | null; createdAt: string; }; diff --git a/src/modules/auth/index.ts b/src/modules/auth/index.ts index 6749653f..ad05eec8 100644 --- a/src/modules/auth/index.ts +++ b/src/modules/auth/index.ts @@ -1,21 +1,25 @@ import { canAccessAdminArea, isAdmin } from './domain/rbac'; import { AuthService } from './application/auth.service'; +import { ApiKeysService } from './application/apikeys.service'; import { PasswordService } from './application/password.service'; import { ProfileService } from './application/profile.service'; import { SessionService } from './application/session.service'; import { UserService } from './application/user.service'; import { UserRepository } from './infrastructure/repositories/user.repository'; import { RoleRepository } from './infrastructure/repositories/role.repository'; +import { ApiKeyRepository } from './infrastructure/repositories/apikey.repository'; const userRepository = new UserRepository(); const roleRepository = new RoleRepository(); +const apiKeyRepository = new ApiKeyRepository(); export const passwordService = new PasswordService(); const sessionService = new SessionService(passwordService); +export const apiKeysService = new ApiKeysService(apiKeyRepository); export const authService = new AuthService(userRepository, passwordService, sessionService); export const userService = new UserService(userRepository, roleRepository, passwordService); -export const profileService = new ProfileService(userRepository, passwordService); +export const profileService = new ProfileService(userRepository, passwordService, apiKeysService); export { canAccessAdminArea, isAdmin }; diff --git a/src/modules/auth/infrastructure/repositories/apikey.repository.ts b/src/modules/auth/infrastructure/repositories/apikey.repository.ts index 23e331b3..c4d10c90 100644 --- a/src/modules/auth/infrastructure/repositories/apikey.repository.ts +++ b/src/modules/auth/infrastructure/repositories/apikey.repository.ts @@ -1,6 +1,89 @@ import { Repository } from './repository'; +import { ApiKeyEntity } from '$lib/database/schemas'; +import type { ApiKeyView } from '../../domain/entities'; + +type ApiKeyRow = { + id: string; + userId: string; + name: string; + keyPrefix: string; + keyHash: string; + expiresAt: string | null; + lastUsedAt: string | null; + revokedAt: string | null; + createdAt: string; +}; export class ApiKeyRepository extends Repository { - + async listByUser(userId: string): Promise { + const result = await this.db.select().from(ApiKeyEntity).where({ userId }).orderBy('createdAt', 'desc'); + + return (result.rows as ApiKeyRow[]).map((row) => this.toJSON(row)); + } + + async findById(userId: string, keyId: string): Promise { + const result = await this.db.select().from(ApiKeyEntity).where({ id: keyId, userId }).limit(1); + const row = result.rows[0] as ApiKeyRow | undefined; + + if (!row) { + return null; + } + + return this.toJSON(row); + } + + async create(input: { + id: string; + userId: string; + name: string; + keyPrefix: string; + keyHash: string; + expiresAt: string | null; + }): Promise { + await this.db.insert(ApiKeyEntity).values({ + id: input.id, + userId: input.userId, + name: input.name, + keyPrefix: input.keyPrefix, + keyHash: input.keyHash, + expiresAt: input.expiresAt, + lastUsedAt: null, + revokedAt: null, + createdAt: new Date().toISOString(), + }); + } + + async revoke(userId: string, keyId: string): Promise { + await this.db.update(ApiKeyEntity).set({ revokedAt: new Date().toISOString() }).where({ id: keyId, userId }); + } + + async updateKeyMaterial(userId: string, keyId: string, input: { + keyPrefix: string; + keyHash: string; + expiresAt: string | null; + }): Promise { + await this.db + .update(ApiKeyEntity) + .set({ + keyPrefix: input.keyPrefix, + keyHash: input.keyHash, + expiresAt: input.expiresAt, + revokedAt: null, + lastUsedAt: null, + }) + .where({ id: keyId, userId }); + } + + override protected toJSON(row: ApiKeyRow): ApiKeyView { + return { + id: row.id, + name: row.name, + keyPrefix: row.keyPrefix.slice(0, 6), + expiresAt: row.expiresAt, + lastUsedAt: row.lastUsedAt, + revokedAt: row.revokedAt, + createdAt: row.createdAt, + }; + } } \ No newline at end of file diff --git a/src/routes/profile/+page.server.ts b/src/routes/profile/+page.server.ts index 9432e765..799839c4 100644 --- a/src/routes/profile/+page.server.ts +++ b/src/routes/profile/+page.server.ts @@ -2,6 +2,21 @@ import { fail, redirect } from '@sveltejs/kit'; import { profileService } from '../../modules/auth'; import { storageBackendService } from '../../modules/config'; +function expiresAtFromDays(expiresInDays: string | null): string | null { + if (!expiresInDays) { + return null; + } + + const days = Number(expiresInDays); + if (!Number.isFinite(days) || days <= 0) { + return null; + } + + const date = new Date(); + date.setDate(date.getDate() + days); + return date.toISOString(); +} + export async function load({ locals, cookies }) { if (!locals.user) { throw redirect(302, '/login'); @@ -18,8 +33,7 @@ export async function load({ locals, cookies }) { const activeBackend = backends.find((backend) => backend.id === activeBackendId) || null; const gcpConnected = activeBackend?.provider === 'gcs'; - // const apiKeys = await profileService.listActiveApiKeys(user.id); - const apiKeys = [] + const apiKeys = await profileService.listActiveApiKeys(user.id); return { user: { @@ -29,13 +43,7 @@ export async function load({ locals, cookies }) { role: user.role, }, gcpConnected, - apiKeys: apiKeys.map((key) => ({ - id: key.id, - name: key.name, - keyPrefix: key.keyPrefix, - lastUsedAt: key.lastUsedAt, - createdAt: key.createdAt, - })), + apiKeys, }; } @@ -83,16 +91,34 @@ export const actions = { const formData = await request.formData(); const name = String(formData.get('name') || '').trim(); + const expiresInDays = String(formData.get('expiresInDays') || '').trim(); if (!name) { return fail(400, { section: 'apiKeys', message: 'Key name is required.' }); } - const { token } = await profileService.createApiKey(locals.user.id, name); + const expiresAt = expiresAtFromDays(expiresInDays || null); + + const { token } = await profileService.createApiKey(locals.user.id, name, expiresAt); return { section: 'apiKeys', message: 'API key created.', createdKey: token }; }, + regenerateApiKey: async ({ request, locals }) => { + if (!locals.user) throw redirect(302, '/login'); + + const formData = await request.formData(); + const keyId = String(formData.get('keyId') || ''); + + if (!keyId) { + return fail(400, { section: 'apiKeys', message: 'Key id is required.' }); + } + + const { token } = await profileService.regenerateApiKey(locals.user.id, keyId); + + return { section: 'apiKeys', message: 'API key regenerated.', createdKey: token }; + }, + revokeApiKey: async ({ request, locals }) => { if (!locals.user) throw redirect(302, '/login'); diff --git a/src/routes/profile/+page.svelte b/src/routes/profile/+page.svelte index 83582f46..80ebec3c 100644 --- a/src/routes/profile/+page.svelte +++ b/src/routes/profile/+page.svelte @@ -1,14 +1,73 @@ @@ -17,7 +76,7 @@
-
+

Account

Profile

@@ -161,27 +220,40 @@

-
- - -
+
{#if form?.createdKey}
-

Copy this token now. It will not be shown again.

- {form.createdKey} +
+
+

Copy this token now. It will not be shown again.

+ {form.createdKey} +
+ + +
{/if} @@ -196,23 +268,123 @@

{key.name}

- Prefix: {key.keyPrefix} · Created {key.createdAt} + Prefix: {key.keyPrefix} · Created {key.createdAt} · Expires {formatDateTime(key.expiresAt)} +

+

+ Status: {getKeyState(key)} + {#if key.revokedAt} + · Revoked {formatDateTime(key.revokedAt)} + {/if}

-
- - -
+
+ {#if !key.revokedAt} +
+ + +
+ +
+ + +
+ {:else} +
+ Actions unavailable for revoked keys. +
+ {/if} +
{/each} {/if} - \ No newline at end of file + + +{#if createApiKeyModalOpen} + +
+ +
+{/if} \ No newline at end of file From 4cba80c7be0d562b71bfdd3278c2d20b9a037ad7 Mon Sep 17 00:00:00 2001 From: Carlos Lopez Date: Tue, 18 Aug 2026 21:14:26 +0200 Subject: [PATCH 2/4] apikeys + unit tests --- bun.lock | 142 +++++++++++++++++ package.json | 6 +- .../auth/application/apikeys.service.test.ts | 150 ++++++++++++++++++ .../auth/application/profile.service.test.ts | 129 +++++++++++++++ .../auth/application/profile.service.ts | 21 +-- src/modules/auth/index.ts | 2 +- src/routes/profile/+page.server.ts | 10 +- vitest.config.ts | 9 ++ 8 files changed, 442 insertions(+), 27 deletions(-) create mode 100644 src/modules/auth/application/apikeys.service.test.ts create mode 100644 src/modules/auth/application/profile.service.test.ts create mode 100644 vitest.config.ts diff --git a/bun.lock b/bun.lock index 79502600..48793425 100644 --- a/bun.lock +++ b/bun.lock @@ -21,6 +21,7 @@ "@types/node": "^22.10.1", "@typescript-eslint/eslint-plugin": "^8.17.0", "@typescript-eslint/parser": "^8.17.0", + "@vitest/coverage-v8": "^4.1.11", "autoprefixer": "^10.5.3", "eslint": "^9.14.0", "eslint-config-prettier": "^9.0.0", @@ -36,6 +37,7 @@ "tailwindcss": "^4.3.2", "typescript": "^5.6.3", "vite": "^5.4.10", + "vitest": "^4.1.11", }, }, }, @@ -80,6 +82,16 @@ "@aws/lambda-invoke-store": ["@aws/lambda-invoke-store@0.3.0", "", {}, "sha512-sl4Bm6yiMNYrZKkqqDFWN0UfnWhlS8ivKxrYl+6t0gCLrqr8y3B2IqZZbFRkfaVVp7C/baApyh71P+LeE1A2sQ=="], + "@babel/helper-string-parser": ["@babel/helper-string-parser@7.29.7", "", {}, "sha512-Pb5ijPrZ89GDH8223L4UP8i6QApWxs04RbPQJTeWDV0/keR2E36MeKnyr6LYmUUvqRRI+Iv87SuF1W6ErINzYw=="], + + "@babel/helper-validator-identifier": ["@babel/helper-validator-identifier@7.29.7", "", {}, "sha512-qehxGkRj55h/ff8EMaJ+cYhyaKlHIxqYDn682wQD7RNp9UujOQsHog2uS0r2vzr4pW+sXf90NeeayjcNaX3fFg=="], + + "@babel/parser": ["@babel/parser@7.29.8", "", { "dependencies": { "@babel/types": "^7.29.8" }, "bin": "./bin/babel-parser.js" }, "sha512-E8lTAYNB1KW+FH+VGJuZM1ioAx2E6oVlvQFRrf5P8ZZmsiJXYAD9vTFV7yyEURNzgh1dFqMZuO6tUwcARbqFCA=="], + + "@babel/types": ["@babel/types@7.29.8", "", { "dependencies": { "@babel/helper-string-parser": "^7.29.7", "@babel/helper-validator-identifier": "^7.29.7" } }, "sha512-Vj1jF3cPfxg7OAfoI7QnVKLoILlm2JF9pnVHrX8qx7AHMiYWT+NDAA7jChlNgRS4WTLc/fD1lXLmPixluj+3Gg=="], + + "@bcoe/v8-coverage": ["@bcoe/v8-coverage@1.0.2", "", {}, "sha512-6zABk/ECA/QYSCQ1NGiVwwbQerUCZ+TQbp64Q3AgmfNvurHH0j8TtXa1qbShXA6qqkpAj4V5W8pP6mLe1mcMqA=="], + "@esbuild/aix-ppc64": ["@esbuild/aix-ppc64@0.21.5", "", { "os": "aix", "cpu": "ppc64" }, "sha512-1SDgH6ZSPTlggy1yI6+Dbkiz8xzpHJEVAlF/AM1tHPLsf5STom9rwtjE4hKAF20FfXXNTFqEYXyJNWh1GiZedQ=="], "@esbuild/android-arm": ["@esbuild/android-arm@0.21.5", "", { "os": "android", "cpu": "arm" }, "sha512-vCPvzSjpPHEi1siZdlvAlsPxXl7WbOVUBBAowWug4rJHb68Ox8KualB+1ocNvT5fjv6wpkX6o/iEpbDrf68zcg=="], @@ -176,8 +188,40 @@ "@nodable/entities": ["@nodable/entities@2.2.0", "", {}, "sha512-9uGyhaQavEUMC8AIddIjau4NsnsXhou+j5sBAGojCM1oxmQpVKTWR/9JxABD6UAv12vpIms55fPZKFQEhG6uBg=="], + "@oxc-project/types": ["@oxc-project/types@0.144.0", "", {}, "sha512-nuhZIOLuI6TFQ32I/WnUx+SCPY7SdSKwgnFHydAuoS1+Z4BRcaP+RRJmGzl9lw+0OFF7UmaESf7KQRXaNLHypg=="], + "@polka/url": ["@polka/url@1.0.0-next.29", "", {}, "sha512-wwQAWhWSuHaag8c4q/KN/vCoeOJYshAIvMQwD4GpSb3OiZklFfvAgmj0VCBBImRpuF/aFgIRzllXlVX93Jevww=="], + "@rolldown/binding-android-arm64": ["@rolldown/binding-android-arm64@1.2.4", "", { "os": "android", "cpu": "arm64" }, "sha512-jHC2cnyKz5xU2fhECtFl8OZ83cYNt13GZQD+0uMJ/X3o+ijmd56okHhTUwxVSHPx1IRVIJEZ1/1pPzeLCU6XKA=="], + + "@rolldown/binding-darwin-arm64": ["@rolldown/binding-darwin-arm64@1.2.4", "", { "os": "darwin", "cpu": "arm64" }, "sha512-Dc5mPD8F5F/FS8i01syd7FTF6yB2fVthH/TRkjwJkzUK6EpoxHtqvZQP5Zwq80/5z19TWYHIg1KOHboCgVx/aQ=="], + + "@rolldown/binding-darwin-x64": ["@rolldown/binding-darwin-x64@1.2.4", "", { "os": "darwin", "cpu": "x64" }, "sha512-fpDm4oBo6SqLvWUYCmFhdde3U9KH2fRNNMeAnAPAIwxRL345xutL0EtEUcuoxsoazdJGv/MuDBQHlCDrtbvqOg=="], + + "@rolldown/binding-freebsd-x64": ["@rolldown/binding-freebsd-x64@1.2.4", "", { "os": "freebsd", "cpu": "x64" }, "sha512-rSJoreDE/HoIzoaib6MTp5jQtCTdMHKIvItAKT/ImS6Y6Ww76oUaeMyp4Vc/fAgd/ehji068IxetHXAnqUwN9A=="], + + "@rolldown/binding-linux-arm-gnueabihf": ["@rolldown/binding-linux-arm-gnueabihf@1.2.4", "", { "os": "linux", "cpu": "arm" }, "sha512-/jm8OGHgn7oGaJu3i/qZI9spUGcJ+y/lk43ttQ/iO1tOd9NissG6o97bighBCiL+BKRngmcDuR6ikfwYdJmVuQ=="], + + "@rolldown/binding-linux-arm64-gnu": ["@rolldown/binding-linux-arm64-gnu@1.2.4", "", { "os": "linux", "cpu": "arm64" }, "sha512-tIP06BeD9EqvECBrPZ+sqdPlYrT+aYaAiu1wYziVx5elRK/ftm33JxVDy2bXGbr6J0CrtirCkR87/X5a2euEng=="], + + "@rolldown/binding-linux-arm64-musl": ["@rolldown/binding-linux-arm64-musl@1.2.4", "", { "os": "linux", "cpu": "arm64" }, "sha512-Ql1Q0EQqVThvn9VAVlwNzsUvbSFtCMGjLpRRi4pk5i7NZZ4n5ISiLMjHYtus4VQ2PvkSw24zyaCVsiS+sXPj1w=="], + + "@rolldown/binding-linux-ppc64-gnu": ["@rolldown/binding-linux-ppc64-gnu@1.2.4", "", { "os": "linux", "cpu": "ppc64" }, "sha512-GjbjXD4XXfN19D0LZNbmiCBUoDiRACsYHr0yaIbbn8aFsXjHZifcYqu/W5Er5X2X990WjHXFrxarn5chzItorQ=="], + + "@rolldown/binding-linux-s390x-gnu": ["@rolldown/binding-linux-s390x-gnu@1.2.4", "", { "os": "linux", "cpu": "s390x" }, "sha512-p5WR0NOwaRmJ/B1b6IjEFLLivwEsf3PrdBIhRbhTCQisbo2SvHHpG4ELB/+FgQNnB88LTOF86upmJmbvZdQ2lw=="], + + "@rolldown/binding-linux-x64-gnu": ["@rolldown/binding-linux-x64-gnu@1.2.4", "", { "os": "linux", "cpu": "x64" }, "sha512-4/GyVjmhR+Tc6HLJvwc1sOhPqAZtySiSMesOZyX6JQ5XBxoTDEMKQzvo07NIK6nTon/SivlZqvhzvuVBNQhObQ=="], + + "@rolldown/binding-linux-x64-musl": ["@rolldown/binding-linux-x64-musl@1.2.4", "", { "os": "linux", "cpu": "x64" }, "sha512-l9eeLsCNvPpmSXUej0etw/J1eqV0Jj1D5G/xG6YTijmE6dkv6E2QezgWbTfQk63v952DPqrjOCoiqxq7Bw0YUQ=="], + + "@rolldown/binding-openharmony-arm64": ["@rolldown/binding-openharmony-arm64@1.2.4", "", { "os": "none", "cpu": "arm64" }, "sha512-e0F355MSTMm3+UOqtV3L24gFUp2N5m1f8L/7d56deik6va+AXdrt9F8LbzGpeWGWRbZEDq4m8NVnJDeBtf9DZg=="], + + "@rolldown/binding-win32-arm64-msvc": ["@rolldown/binding-win32-arm64-msvc@1.2.4", "", { "os": "win32", "cpu": "arm64" }, "sha512-AWLi0uBRYh6QlE7OKhiz+phZC0qwtij2QZmhmOdsLdFn64m7oMpooE9ICE3lhm9xMb4SpDo2WbHcxX1iFLFtqw=="], + + "@rolldown/binding-win32-x64-msvc": ["@rolldown/binding-win32-x64-msvc@1.2.4", "", { "os": "win32", "cpu": "x64" }, "sha512-UwSDJOg3dqCAejWdxclJjCsh3Qq4vLYMDxmyHqo1btz3stK2VqgwNd3mm5tuIwzSlGIQ/1H9Hr+Zn09mrezNqQ=="], + + "@rolldown/pluginutils": ["@rolldown/pluginutils@1.0.1", "", {}, "sha512-2j9bGt5Jh8hj+vPtgzPtl72j0yRxHAyumoo6TNfAjsLB04UtpSvPbPcDcBMxz7n+9CYB0c1GxQFxYRg2jimqGw=="], + "@rollup/rollup-android-arm-eabi": ["@rollup/rollup-android-arm-eabi@4.62.2", "", { "os": "android", "cpu": "arm" }, "sha512-6o7ZLZK+BeenkZCFNDXqpbjw9bD6nuWonvS/lwQJp7NoVVxm6p3qE7qQ5jGuBjiFsgvqjD8mZAU5oWxTmbOeOg=="], "@rollup/rollup-android-arm64": ["@rollup/rollup-android-arm64@4.62.2", "", { "os": "android", "cpu": "arm64" }, "sha512-BaH7BllCACHoH1LguOU56UItGfUWjujlO65kS9LAodViaN4bwIKd7oeW/ZHJ/4ljr/7MIiENnNy3HJ0zXv8Zkw=="], @@ -290,8 +334,12 @@ "@types/caseless": ["@types/caseless@0.12.5", "", {}, "sha512-hWtVTC2q7hc7xZ/RLbxapMvDMgUnDvKvMOpKal4DrMyfGBUfB1oKaZlIRr6mJL+If3bAP6sV/QneGzF6tJjZDg=="], + "@types/chai": ["@types/chai@5.2.3", "", { "dependencies": { "@types/deep-eql": "*", "assertion-error": "^2.0.1" } }, "sha512-Mw558oeA9fFbv65/y4mHtXDs9bPnFMZAL/jxdPFUpOHHIXX91mcgEHbS5Lahr+pwZFR8A7GQleRWeI6cGFC2UA=="], + "@types/cookie": ["@types/cookie@0.6.0", "", {}, "sha512-4Kh9a6B2bQciAhf7FSuMRRkUWecJgJu9nPnx3yzpsfXX/c50REIqpHY4C82bXP90qrLtXtkDxTZosYO3UpOwlA=="], + "@types/deep-eql": ["@types/deep-eql@4.0.2", "", {}, "sha512-c9h9dVVMigMPc4bwTvC5dxqtqJZwQPePsWjPlpSOnojbor6pGqdk541lfA7AqFQr5pB1BRdq0juY9db81BwyFw=="], + "@types/estree": ["@types/estree@1.0.9", "", {}, "sha512-GhdPgy1el4/ImP05X05Uw4cw2/M93BCUmnEvWZNStlCzEKME4Fkk+YpoA5OiHNQmoS7Cafb8Xa3Pya8m1Qrzeg=="], "@types/json-schema": ["@types/json-schema@7.0.15", "", {}, "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA=="], @@ -322,6 +370,22 @@ "@typescript-eslint/visitor-keys": ["@typescript-eslint/visitor-keys@8.64.0", "", { "dependencies": { "@typescript-eslint/types": "8.64.0", "eslint-visitor-keys": "^5.0.0" } }, "sha512-mrtuL8Nsn6gi2H4mo5KMTp823M+3Q19Ew/i+Zlikq20tIMm99C3Ez0dCmkWWnxut20esQvTg8aUSEhMcAOXhEw=="], + "@vitest/coverage-v8": ["@vitest/coverage-v8@4.1.11", "", { "dependencies": { "@bcoe/v8-coverage": "^1.0.2", "@vitest/utils": "4.1.11", "ast-v8-to-istanbul": "^1.0.0", "istanbul-lib-coverage": "^3.2.2", "istanbul-lib-report": "^3.0.1", "istanbul-reports": "^3.2.0", "magicast": "^0.5.2", "obug": "^2.1.1", "std-env": "^4.0.0-rc.1", "tinyrainbow": "^3.1.0" }, "peerDependencies": { "@vitest/browser": "4.1.11", "vitest": "4.1.11" }, "optionalPeers": ["@vitest/browser"] }, "sha512-8MVGEFnJIcdGjcbfKmeq8z0pZHH0JlVtoVZH9Q/qwUp6wyFnEJUBMrw9DCaj+ra3vShGmhavjalMIhPNxZAUcw=="], + + "@vitest/expect": ["@vitest/expect@4.1.11", "", { "dependencies": { "@standard-schema/spec": "^1.1.0", "@types/chai": "^5.2.2", "@vitest/spy": "4.1.11", "@vitest/utils": "4.1.11", "chai": "^6.2.2", "tinyrainbow": "^3.1.0" } }, "sha512-VX2x5vNJXET47KAFzwERI+KRMtTTCSWTfSMKsW7JsUsXV4psq++e3DvZpuTDOpHcxytiDs6p2nhVb2tVDiiUYw=="], + + "@vitest/mocker": ["@vitest/mocker@4.1.11", "", { "dependencies": { "@vitest/spy": "4.1.11", "estree-walker": "^3.0.3", "magic-string": "^0.30.21" }, "peerDependencies": { "msw": "^2.4.9", "vite": "^6.0.0 || ^7.0.0 || ^8.0.0" }, "optionalPeers": ["msw", "vite"] }, "sha512-2XJVD55d1o5AZous5CCGKS74g/riOj9odEt2bQpCVZeblHyHdnMeFl4jl0XjU21stf4mbjUkew2eXQZt65g5CQ=="], + + "@vitest/pretty-format": ["@vitest/pretty-format@4.1.11", "", { "dependencies": { "tinyrainbow": "^3.1.0" } }, "sha512-yiZzPbGTS9Sr/JpFl8zHrcIkAofNbFV6k21vIgQN/cY/oxZeXhJv5sc/MBJ5jFKWmWs+oJHw0UXLZjmf931+Vw=="], + + "@vitest/runner": ["@vitest/runner@4.1.11", "", { "dependencies": { "@vitest/utils": "4.1.11", "pathe": "^2.0.3" } }, "sha512-LztvUgdwMNJMIkj3hQnnxiC2Xy1zNxq928W/xhjCLaNCzqTZOudjwbQf6v9IntZGPw132i2Lq2rgTRZHD3JHNw=="], + + "@vitest/snapshot": ["@vitest/snapshot@4.1.11", "", { "dependencies": { "@vitest/pretty-format": "4.1.11", "@vitest/utils": "4.1.11", "magic-string": "^0.30.21", "pathe": "^2.0.3" } }, "sha512-pN7ikn1ON7h8ee4gIAp4AzyK+zBtJPzVbqOgu5LCEh4VaJVbPQcgYQYJIMGQPXVeJJq1fnfazis7a5pFNPahog=="], + + "@vitest/spy": ["@vitest/spy@4.1.11", "", {}, "sha512-apNa/prQy2qCeywhnixOHPRCgGNhvg7T4Dapfl1GahLp/R+uhBm5cPyFoNVyqsNd2h1nJxL6BqqdIjiABL60YA=="], + + "@vitest/utils": ["@vitest/utils@4.1.11", "", { "dependencies": { "@vitest/pretty-format": "4.1.11", "convert-source-map": "^2.0.0", "tinyrainbow": "^3.1.0" } }, "sha512-zTCVGpyFsGWBhllOyKlTw/vnr6D9qxsfSDyfbyZmTyjHw5N/VuvzHpHoQjm2ZJzn4RJgx5w4r7V0er69CmLgPQ=="], + "abort-controller": ["abort-controller@3.0.0", "", { "dependencies": { "event-target-shim": "^5.0.0" } }, "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg=="], "acorn": ["acorn@8.17.0", "", { "bin": { "acorn": "bin/acorn" } }, "sha512-xRQbDb9BnwDafYNn6Vwl839DYVjqXYb1XVGtWAZ1kcDc6iwAL4hg3B1dZlRiuENFeO2H53gFG3in621AdERVAg=="], @@ -342,6 +406,10 @@ "arrify": ["arrify@2.0.1", "", {}, "sha512-3duEwti880xqi4eAMN8AyR4a0ByT90zoYdLlevfrvU43vb0YZwZVfxOgxWrLXXXpyugL0hNZc9G6BiB5B3nUug=="], + "assertion-error": ["assertion-error@2.0.1", "", {}, "sha512-Izi8RQcffqCeNVgFigKli1ssklIbpHnCYc6AknXGYoB6grJqyeby7jv12JUQgmTAnIDnbck1uxksT4dzN3PWBA=="], + + "ast-v8-to-istanbul": ["ast-v8-to-istanbul@1.0.5", "", { "dependencies": { "@jridgewell/trace-mapping": "^0.3.31", "estree-walker": "^3.0.3", "js-tokens": "^10.0.0" } }, "sha512-UPAgKJFSEGMWSDr3LX4tqnAb4f7KGT8O40Tyx8wbYmmZ/yn58lNCm8h3svs3eXgiGd5AXxz8NDOvXWvicq+rJA=="], + "async-retry": ["async-retry@1.3.3", "", { "dependencies": { "retry": "0.13.1" } }, "sha512-wfr/jstw9xNi/0teMHrRW7dsz3Lt5ARhYNZ2ewpadnhaIp5mbALhOAP+EAdsC7t4Z6wqsDVv9+W6gm1Dk9mEyw=="], "asynckit": ["asynckit@0.4.0", "", {}, "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="], @@ -380,6 +448,8 @@ "caniuse-lite": ["caniuse-lite@1.0.30001806", "", {}, "sha512-72Cuvd95zbSYPKq6Fhg8eDJRlzgWDf7/mtoZv6Qe/DYNCEBdNxoA3+rZAU2ZhGCpZlns3EssFavaZomckT5Uuw=="], + "chai": ["chai@6.2.2", "", {}, "sha512-NUPRluOfOiTKBKvWPtSD4PhFvWCqOi0BGStNWs57X9js7XGTprSmFoz5F0tWhR4WPjNeR9jXqdC7/UpSJTnlRg=="], + "chalk": ["chalk@4.1.2", "", { "dependencies": { "ansi-styles": "^4.1.0", "supports-color": "^7.1.0" } }, "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA=="], "chokidar": ["chokidar@4.0.3", "", { "dependencies": { "readdirp": "^4.0.1" } }, "sha512-Qgzu8kfBvo+cA4962jnP1KkS6Dop5NS6g7R5LFYJr4b8Ub94PPQXUksCw9PvXoeXPRRddRNC5C1JQUR2SMGtnA=="], @@ -396,6 +466,8 @@ "concat-map": ["concat-map@0.0.1", "", {}, "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg=="], + "convert-source-map": ["convert-source-map@2.0.0", "", {}, "sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg=="], + "cookie": ["cookie@0.6.0", "", {}, "sha512-U71cyTamuh1CRNCfpGY6to28lxvNwPG4Guz/EVjgf3Jmzv0vlDp1atT9eS5dDjMYHucpHbWns6Lwf3BKz6svdw=="], "cross-spawn": ["cross-spawn@7.0.6", "", { "dependencies": { "path-key": "^3.1.0", "shebang-command": "^2.0.0", "which": "^2.0.1" } }, "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA=="], @@ -436,6 +508,8 @@ "es-errors": ["es-errors@1.3.0", "", {}, "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw=="], + "es-module-lexer": ["es-module-lexer@2.3.2", "", {}, "sha512-poHGpORABojJJucnV9KbOavETW8lBVnphkW77ER5/BQ5Fz7oXSoCNek7IH3vR5nRjdsEz926ibFYX8KtLQmdyw=="], + "es-object-atoms": ["es-object-atoms@1.1.2", "", { "dependencies": { "es-errors": "^1.3.0" } }, "sha512-HWcBoN6NileqtSydK2FqHbS/LoDd2pqrnQHLyJzBj4kOp/ky2MWMN694xOfkK8/SnUsW2DH7EfyVlydKCsm1Zw=="], "es-set-tostringtag": ["es-set-tostringtag@2.1.0", "", { "dependencies": { "es-errors": "^1.3.0", "get-intrinsic": "^1.2.6", "has-tostringtag": "^1.0.2", "hasown": "^2.0.2" } }, "sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA=="], @@ -476,6 +550,8 @@ "expand-template": ["expand-template@2.0.3", "", {}, "sha512-XYfuKMvj4O35f/pOXLObndIRvyQ+/+6AhODh+OKWj9S9498pHHn/IMszH+gt0fBCRWMNfk1ZSp5x3AifmnI2vg=="], + "expect-type": ["expect-type@1.4.0", "", {}, "sha512-KfYbmpRm0VbLjEvVa9yGwCi9GI34xvi7A/HXYWQO65CSD2u3MczUJSuwXKFIxlGsgBQizV9q5J9NHj4VG0n+pA=="], + "extend": ["extend@3.0.2", "", {}, "sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g=="], "fast-deep-equal": ["fast-deep-equal@3.1.3", "", {}, "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q=="], @@ -544,6 +620,8 @@ "html-entities": ["html-entities@2.6.0", "", {}, "sha512-kig+rMn/QOVRvr7c86gQ8lWXq+Hkv6CbAH1hLu+RG338StTpE8Z0b44SDVaqVu7HGKf27frdmUYEs9hTUX/cLQ=="], + "html-escaper": ["html-escaper@2.0.2", "", {}, "sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg=="], + "http-proxy-agent": ["http-proxy-agent@5.0.0", "", { "dependencies": { "@tootallnate/once": "2", "agent-base": "6", "debug": "4" } }, "sha512-n2hY8YdoRE1i7r6M0w9DIw5GgZN0G25P8zLCRQ8rjXtTU3vsNFBI/vWK/UIeE6g5MUUz6avwAPXmL6Fy9D/90w=="], "https-proxy-agent": ["https-proxy-agent@7.0.6", "", { "dependencies": { "agent-base": "^7.1.2", "debug": "4" } }, "sha512-vK9P5/iUfdl95AI+JVyUuIcVtd4ofvtrOr3HNtM2yxC9bnMbEdp3x01OhQNnjb8IJYi38VlTE3mBXwcfvywuSw=="], @@ -576,8 +654,16 @@ "isexe": ["isexe@2.0.0", "", {}, "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw=="], + "istanbul-lib-coverage": ["istanbul-lib-coverage@3.2.2", "", {}, "sha512-O8dpsF+r0WV/8MNRKfnmrtCWhuKjxrq2w+jpzBL5UZKTi2LeVWnWOmWRxFlesJONmc+wLAGvKQZEOanko0LFTg=="], + + "istanbul-lib-report": ["istanbul-lib-report@3.0.1", "", { "dependencies": { "istanbul-lib-coverage": "^3.0.0", "make-dir": "^4.0.0", "supports-color": "^7.1.0" } }, "sha512-GCfE1mtsHGOELCU8e/Z7YWzpmybrx/+dSTfLrvY8qRmaY6zXTKWn6WQIjaAFw069icm6GVMNkgu0NzI4iPZUNw=="], + + "istanbul-reports": ["istanbul-reports@3.2.0", "", { "dependencies": { "html-escaper": "^2.0.0", "istanbul-lib-report": "^3.0.0" } }, "sha512-HGYWWS/ehqTV3xN10i23tkPkpH46MLCIMFNCaaKNavAXTF1RkqxawEPtnjnGZ6XKSInBKkiOA5BKS+aZiY3AvA=="], + "jiti": ["jiti@2.7.0", "", { "bin": { "jiti": "lib/jiti-cli.mjs" } }, "sha512-AC/7JofJvZGrrneWNaEnJeOLUx+JlGt7tNa0wZiRPT4MY1wmfKjt2+6O2p2uz2+skll8OZZmJMNqeke7kKbNgQ=="], + "js-tokens": ["js-tokens@10.0.0", "", {}, "sha512-lM/UBzQmfJRo9ABXbPWemivdCW8V2G8FHaHdypQaIy523snUjog0W71ayWXTjiR+ixeMyVHN2XcpnTd/liPg/Q=="], + "js-yaml": ["js-yaml@4.3.0", "", { "dependencies": { "argparse": "^2.0.1" }, "bin": { "js-yaml": "bin/js-yaml.js" } }, "sha512-1td788aAnnZ5qs7V2QIRl1owjtYpbKt749Y3xauqQgwIIGF/xXWz1wMTEBx5O3LK3lXLVuqXPdPxj2BoFHaW9Q=="], "json-bigint": ["json-bigint@1.0.0", "", { "dependencies": { "bignumber.js": "^9.0.0" } }, "sha512-SiPv/8VpZuWbvLSMtTDU8hEfrZWg/mH/nV/b4o0CYbSxu1UIQPLdwKOCIyLQX+VIPO5vrLX3i8qtqFyhdPSUSQ=="], @@ -636,6 +722,10 @@ "magic-string": ["magic-string@0.30.21", "", { "dependencies": { "@jridgewell/sourcemap-codec": "^1.5.5" } }, "sha512-vd2F4YUyEXKGcLHoq+TEyCjxueSeHnFxyyjNp80yg0XV4vUhnDer/lvvlqM/arB5bXQN5K2/3oinyCRyx8T2CQ=="], + "magicast": ["magicast@0.5.4", "", { "dependencies": { "@babel/parser": "^7.29.7", "@babel/types": "^7.29.7", "source-map-js": "^1.2.1" } }, "sha512-llBEhWm1SacoRwgHUoQJYtwp4PBLF4faQi5TCpIGyGs9n4y5+juI0tDgyKIfpqxckRHaHzouUEph3THklWh03w=="], + + "make-dir": ["make-dir@4.0.0", "", { "dependencies": { "semver": "^7.5.3" } }, "sha512-hXdUTZYIVOt1Ex//jAQi+wTZZpUpwBj/0QsOzqegb3rGMMeJiSEu5xLHnYfBrRV4RH2+OCSOO95Is/7x1WJ4bw=="], + "math-intrinsics": ["math-intrinsics@1.1.0", "", {}, "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g=="], "mdn-data": ["mdn-data@2.0.30", "", {}, "sha512-GaqWWShW4kv/G9IEucWScBx9G1/vsFZZJUO+tD26M8J8z3Kw5RDQjaoZe03YAClgeS/SWPOcb4nkFBTEi5DUEA=="], @@ -672,6 +762,8 @@ "node-releases": ["node-releases@2.0.51", "", {}, "sha512-wRNIrw4DmVLKQlbgOMdkMx27Wrpzes2hh5Jtbi2bjPd+4wJstWIqP5A+lscnqbm0xxmT5Bpg8Lec5ItEBwx6BQ=="], + "obug": ["obug@2.1.4", "", {}, "sha512-4a+OsYv9UktOJKE+l1A4OufDgdRF9PifWj+tJnHURo/P+WOxpG4GzUFL9qCalmWauao6ogiG+QvnCovwPoyAWA=="], + "once": ["once@1.4.0", "", { "dependencies": { "wrappy": "1" } }, "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w=="], "optionator": ["optionator@0.9.4", "", { "dependencies": { "deep-is": "^0.1.3", "fast-levenshtein": "^2.0.6", "levn": "^0.4.1", "prelude-ls": "^1.2.1", "type-check": "^0.4.0", "word-wrap": "^1.2.5" } }, "sha512-6IpQ7mKUxRcZNLIObR0hz7lxsapSSIYNZJwXPGeF0mTVqGKFIXj1DQcMoT22S3ROcLyY/rz0PWaWZ9ayWmad9g=="], @@ -688,6 +780,8 @@ "path-key": ["path-key@3.1.1", "", {}, "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q=="], + "pathe": ["pathe@2.0.3", "", {}, "sha512-WUjGcAqP1gQacoQe+OBJsFA7Ld4DyXuUIjZ5cc75cLHvJ7dtNsTugphxIADwspS+AraAUePCKrSVtPLFj/F88w=="], + "periscopic": ["periscopic@3.1.0", "", { "dependencies": { "@types/estree": "^1.0.0", "estree-walker": "^3.0.0", "is-reference": "^3.0.0" } }, "sha512-vKiQ8RRtkl9P+r/+oefh25C3fhybptkHKCZSPlcXiJux2tJF55GnEj3BVn4A5gKfq9NWWXXrxkHBwVPUfH0opw=="], "picocolors": ["picocolors@1.1.1", "", {}, "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA=="], @@ -730,6 +824,8 @@ "retry-request": ["retry-request@7.0.2", "", { "dependencies": { "@types/request": "^2.48.8", "extend": "^3.0.2", "teeny-request": "^9.0.0" } }, "sha512-dUOvLMJ0/JJYEn8NrpOaGNE7X3vpI5XlZS/u0ANjqtcZVKnIxP7IgCFwrKTxENw29emmwug53awKtaMm4i9g5w=="], + "rolldown": ["rolldown@1.2.4", "", { "dependencies": { "@oxc-project/types": "=0.144.0", "@rolldown/pluginutils": "^1.0.0" }, "optionalDependencies": { "@rolldown/binding-android-arm64": "1.2.4", "@rolldown/binding-darwin-arm64": "1.2.4", "@rolldown/binding-darwin-x64": "1.2.4", "@rolldown/binding-freebsd-x64": "1.2.4", "@rolldown/binding-linux-arm-gnueabihf": "1.2.4", "@rolldown/binding-linux-arm64-gnu": "1.2.4", "@rolldown/binding-linux-arm64-musl": "1.2.4", "@rolldown/binding-linux-ppc64-gnu": "1.2.4", "@rolldown/binding-linux-s390x-gnu": "1.2.4", "@rolldown/binding-linux-x64-gnu": "1.2.4", "@rolldown/binding-linux-x64-musl": "1.2.4", "@rolldown/binding-openharmony-arm64": "1.2.4", "@rolldown/binding-win32-arm64-msvc": "1.2.4", "@rolldown/binding-win32-x64-msvc": "1.2.4" }, "bin": { "rolldown": "./bin/cli.mjs" } }, "sha512-rSr7irW0K7QRWzjdJXqZowkcRdDtjRduh43rBltnVKd0VFq839l1lJoDvGJb6gl7+4rTTCrPWu+YfujUL8Ug7w=="], + "rollup": ["rollup@4.62.2", "", { "dependencies": { "@types/estree": "1.0.9" }, "optionalDependencies": { "@rollup/rollup-android-arm-eabi": "4.62.2", "@rollup/rollup-android-arm64": "4.62.2", "@rollup/rollup-darwin-arm64": "4.62.2", "@rollup/rollup-darwin-x64": "4.62.2", "@rollup/rollup-freebsd-arm64": "4.62.2", "@rollup/rollup-freebsd-x64": "4.62.2", "@rollup/rollup-linux-arm-gnueabihf": "4.62.2", "@rollup/rollup-linux-arm-musleabihf": "4.62.2", "@rollup/rollup-linux-arm64-gnu": "4.62.2", "@rollup/rollup-linux-arm64-musl": "4.62.2", "@rollup/rollup-linux-loong64-gnu": "4.62.2", "@rollup/rollup-linux-loong64-musl": "4.62.2", "@rollup/rollup-linux-ppc64-gnu": "4.62.2", "@rollup/rollup-linux-ppc64-musl": "4.62.2", "@rollup/rollup-linux-riscv64-gnu": "4.62.2", "@rollup/rollup-linux-riscv64-musl": "4.62.2", "@rollup/rollup-linux-s390x-gnu": "4.62.2", "@rollup/rollup-linux-x64-gnu": "4.62.2", "@rollup/rollup-linux-x64-musl": "4.62.2", "@rollup/rollup-openbsd-x64": "4.62.2", "@rollup/rollup-openharmony-arm64": "4.62.2", "@rollup/rollup-win32-arm64-msvc": "4.62.2", "@rollup/rollup-win32-ia32-msvc": "4.62.2", "@rollup/rollup-win32-x64-gnu": "4.62.2", "@rollup/rollup-win32-x64-msvc": "4.62.2", "fsevents": "~2.3.2" }, "bin": { "rollup": "dist/bin/rollup" } }, "sha512-RFnrW4lhXA3s3eqHDZvN654g8OTjzRfqpIRJYczCGB6HzphckVAi/Qh4tbPUbRuDi7s1Llv8g/NspLkttY3gTA=="], "sade": ["sade@1.8.1", "", { "dependencies": { "mri": "^1.1.0" } }, "sha512-xal3CZX1Xlo/k4ApwCFrHVACi9fBqJ7V+mwhBsuf/1IOKbBy098Fex+Wa/5QMubw09pSZ/u8EY8PWgevJsXp1A=="], @@ -744,6 +840,8 @@ "shebang-regex": ["shebang-regex@3.0.0", "", {}, "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A=="], + "siginfo": ["siginfo@2.0.0", "", {}, "sha512-ybx0WO1/8bSBLEWXZvEd7gMW3Sn3JFlW3TvX1nREbDLRNQNaeNN8WK0meBwPdAaOI7TtRRRJn/Es1zhrrCHu7g=="], + "simple-concat": ["simple-concat@1.0.1", "", {}, "sha512-cSFtAPtRhljv69IK0hTVZQ+OfE9nePi/rtJmw5UjHeVyVroEqJXP1sFztKUy1qU+xvz3u/sfYJLa947b7nAN2Q=="], "simple-get": ["simple-get@4.0.1", "", { "dependencies": { "decompress-response": "^6.0.0", "once": "^1.3.1", "simple-concat": "^1.0.0" } }, "sha512-brv7p5WgH0jmQJr1ZDDfKDOSeWWg+OVypG99A/5vYGPqJ6pxiaHLy8nxtFjBA7oMa01ebA9gfh1uMCFqOuXxvA=="], @@ -752,6 +850,10 @@ "source-map-js": ["source-map-js@1.2.1", "", {}, "sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA=="], + "stackback": ["stackback@0.0.2", "", {}, "sha512-1XMJE5fQo1jGH6Y/7ebnwPOBEkIEnT4QF32d5R1+VXdXveM0IBMJt8zfaxX1P3QhVwrYe+576+jkANtSS2mBbw=="], + + "std-env": ["std-env@4.2.0", "", {}, "sha512-oCUKSupKTHX53EyjDtuZQ64pjLJ6yYCtpmEw0goYxtjG9KpbRe8KAsl2tBUGU9DyMcJ0RwJ8GqJAFzMXcXW1Rw=="], + "stream-events": ["stream-events@1.0.5", "", { "dependencies": { "stubs": "^3.0.0" } }, "sha512-E1GUzBSgvct8Jsb3v2X15pjzN1tYebtbLaMg+eBOUOAxgbLoSbT2NS91ckc5lJD1KfLjId+jXJRgo0qnV5Nerg=="], "stream-shift": ["stream-shift@1.0.3", "", {}, "sha512-76ORR0DO1o1hlKwTbi/DM3EXWGf3ZJYO8cXX5RJwnul2DEg2oyoZyjLNoQM8WsvZiFKCRfC1O0J7iCvie3RZmQ=="], @@ -784,8 +886,14 @@ "teeny-request": ["teeny-request@9.0.0", "", { "dependencies": { "http-proxy-agent": "^5.0.0", "https-proxy-agent": "^5.0.0", "node-fetch": "^2.6.9", "stream-events": "^1.0.5", "uuid": "^9.0.0" } }, "sha512-resvxdc6Mgb7YEThw6G6bExlXKkv6+YbuzGg9xuXxSgxJF7Ozs+o8Y9+2R3sArdWdW8nOokoQb1yrpFB0pQK2g=="], + "tinybench": ["tinybench@2.9.0", "", {}, "sha512-0+DUvqWMValLmha6lr4kD8iAMK1HzV0/aKnCtWb9v9641TnP/MFb7Pc2bxoxQjTXAErryXVgUOfv2YqNllqGeg=="], + + "tinyexec": ["tinyexec@1.3.0", "", {}, "sha512-QKAl9m8gWWGHV8jZcPeym6j+XULi6tOf1mT83WYJ4Lk2ytW/uwAWkrP0uFsdoYMdueVJ0qs26wZ+23xeB4ibNQ=="], + "tinyglobby": ["tinyglobby@0.2.17", "", { "dependencies": { "fdir": "^6.5.0", "picomatch": "^4.0.4" } }, "sha512-wXR/dYpcqKmfWpEdZjiKJOwCNFndD0DMnrW/cYjVGttEkBfVgcLFHoNrlj47mjOVic9yyNu65alsgF4NQyTa2g=="], + "tinyrainbow": ["tinyrainbow@3.1.1", "", {}, "sha512-yau8yJdTt989Mm0Bd/236QnzEiPf2xLLTqUZRUJOo/3CB078LSwzei343DgtJVmfJKJE3TMINY1u42SQsP6mXw=="], + "totalist": ["totalist@3.0.1", "", {}, "sha512-sf4i37nQ2LBx4m3wB74y+ubopq6W/dIzXg0FDGjsYnZHVa1Da8FH853wlL2gtUhg+xJXjfk3kUZS3BRoQeoQBQ=="], "tr46": ["tr46@0.0.3", "", {}, "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw=="], @@ -814,12 +922,16 @@ "vitefu": ["vitefu@0.2.5", "", { "peerDependencies": { "vite": "^3.0.0 || ^4.0.0 || ^5.0.0" }, "optionalPeers": ["vite"] }, "sha512-SgHtMLoqaeeGnd2evZ849ZbACbnwQCIwRH57t18FxcXoZop0uQu0uzlIhJBlF/eWVzuce0sHeqPcDo+evVcg8Q=="], + "vitest": ["vitest@4.1.11", "", { "dependencies": { "@vitest/expect": "4.1.11", "@vitest/mocker": "4.1.11", "@vitest/pretty-format": "4.1.11", "@vitest/runner": "4.1.11", "@vitest/snapshot": "4.1.11", "@vitest/spy": "4.1.11", "@vitest/utils": "4.1.11", "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" }, "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.11", "@vitest/browser-preview": "4.1.11", "@vitest/browser-webdriverio": "4.1.11", "@vitest/coverage-istanbul": "4.1.11", "@vitest/coverage-v8": "4.1.11", "@vitest/ui": "4.1.11", "happy-dom": "*", "jsdom": "*" }, "optionalPeers": ["@edge-runtime/vm", "@opentelemetry/api", "@types/node", "@vitest/browser-playwright", "@vitest/browser-preview", "@vitest/browser-webdriverio", "@vitest/coverage-istanbul", "@vitest/coverage-v8", "@vitest/ui", "happy-dom", "jsdom"], "bin": { "vitest": "./vitest.mjs" } }, "sha512-fhACrNXUidIbGSBr5FlbuBkO7VWC1ZyLl0DO4CU2DrQoAPxX84Ysxs+HeGQpii5lZWV1Q4gBZTTu49mF+A6Edw=="], + "webidl-conversions": ["webidl-conversions@3.0.1", "", {}, "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ=="], "whatwg-url": ["whatwg-url@5.0.0", "", { "dependencies": { "tr46": "~0.0.3", "webidl-conversions": "^3.0.0" } }, "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw=="], "which": ["which@2.0.2", "", { "dependencies": { "isexe": "^2.0.0" }, "bin": { "node-which": "./bin/node-which" } }, "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA=="], + "why-is-node-running": ["why-is-node-running@2.3.0", "", { "dependencies": { "siginfo": "^2.0.0", "stackback": "0.0.2" }, "bin": { "why-is-node-running": "cli.js" } }, "sha512-hUrmaWBdVDcxvYqnyh09zunKzROWjbZTiNy8dBEjkS7ehEDQibXJ7XvlmtbwuTclUiIyN+CyXQD4Vmko8fNm8w=="], + "word-wrap": ["word-wrap@1.2.5", "", {}, "sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA=="], "wrappy": ["wrappy@1.0.2", "", {}, "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ=="], @@ -868,6 +980,8 @@ "teeny-request/https-proxy-agent": ["https-proxy-agent@5.0.1", "", { "dependencies": { "agent-base": "6", "debug": "4" } }, "sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA=="], + "vitest/vite": ["vite@8.2.1", "", { "dependencies": { "lightningcss": "^1.33.0", "picomatch": "^4.0.5", "postcss": "^8.5.25", "rolldown": "~1.2.1", "tinyglobby": "^0.2.17" }, "optionalDependencies": { "fsevents": "~2.3.3" }, "peerDependencies": { "@types/node": "^20.19.0 || >=22.12.0", "@vitejs/devtools": "^0.4.0", "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" }, "optionalPeers": ["@types/node", "@vitejs/devtools", "esbuild", "jiti", "less", "sass", "sass-embedded", "stylus", "sugarss", "terser", "tsx", "yaml"], "bin": { "vite": "bin/vite.js" } }, "sha512-EU/eS7BH3XROHh2YnBefjM6DBKA6ZeMZEYQbj7NLWg5wHYlhB8B/Mayd5XsgWq+NFYccDOTemRpdETWR6Ka/lw=="], + "@typescript-eslint/typescript-estree/minimatch/brace-expansion": ["brace-expansion@5.0.7", "", { "dependencies": { "balanced-match": "^4.0.2" } }, "sha512-7oFy703dxfY3/NLxC1fh2SUCQ0H9rmAY+5EpDVfXjUTTs+HEwR2nYaqLv+GWcTsumwxPfiz6CzCNkwXwBUwqCA=="], "eslint-plugin-svelte/svelte-eslint-parser/eslint-scope": ["eslint-scope@7.2.2", "", { "dependencies": { "esrecurse": "^4.3.0", "estraverse": "^5.2.0" } }, "sha512-dOt21O7lTMhDM+X9mB4GX+DZrZtCUJPL/wlcTqxyrx5IvO0IYtILdtrQGQp+8n5S0gwSVmOf9NQrjMOgfQZlIg=="], @@ -878,6 +992,34 @@ "teeny-request/https-proxy-agent/agent-base": ["agent-base@6.0.2", "", { "dependencies": { "debug": "4" } }, "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ=="], + "vitest/vite/lightningcss": ["lightningcss@1.33.0", "", { "dependencies": { "detect-libc": "^2.0.3" }, "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" } }, "sha512-WkUDrojuJs0xkgGf2udWxa3yGBRxPtxUkB79i6aCZLRgc7PM8fZe9TosfPDcvEpQZbuFASnHYmRLBLUbmLOIIA=="], + + "vitest/vite/postcss": ["postcss@8.5.26", "", { "dependencies": { "nanoid": "^3.3.17", "picocolors": "^1.1.1", "source-map-js": "^1.2.1" } }, "sha512-u82N74LFzG8ca+dD8puPnplTXoGH4fTPpVGuIbt36G3qvNlkvfD0lEAZSxaly3KX8TS/L1A1gsCEmvKmBcVbkQ=="], + "@typescript-eslint/typescript-estree/minimatch/brace-expansion/balanced-match": ["balanced-match@4.0.4", "", {}, "sha512-BLrgEcRTwX2o6gGxGOCNyMvGSp35YofuYzw9h1IMTRmKqttAZZVU67bdb9Pr2vUHA8+j3i2tJfjO6C6+4myGTA=="], + + "vitest/vite/lightningcss/lightningcss-android-arm64": ["lightningcss-android-arm64@1.33.0", "", { "os": "android", "cpu": "arm64" }, "sha512-gEpRTalKdosp4Bb8qWtc2iOgE5SeIHlpS1up9bFq2wAyYhl1UdTObYiHe98zEM9SQvSoqQZ1IQD0JNpg3Ml5pg=="], + + "vitest/vite/lightningcss/lightningcss-darwin-arm64": ["lightningcss-darwin-arm64@1.33.0", "", { "os": "darwin", "cpu": "arm64" }, "sha512-Sciaz8eenNTKn9b3t7+xr0ipTp9YxKQY4npwQ3mrRuL0BAVHBLyZxofhaKBAVtzmtRZ/zTyo0/to4B1uWG/Djg=="], + + "vitest/vite/lightningcss/lightningcss-darwin-x64": ["lightningcss-darwin-x64@1.33.0", "", { "os": "darwin", "cpu": "x64" }, "sha512-Z5UPAxzrjlWNNyGy6i65cJzzvgJ5D3T6wMvs+gWpY9d7qRhANrxqAp6LhxIgZhWEw18RfJTGcRxjuLIBr+m8XQ=="], + + "vitest/vite/lightningcss/lightningcss-freebsd-x64": ["lightningcss-freebsd-x64@1.33.0", "", { "os": "freebsd", "cpu": "x64" }, "sha512-QQM/Ti/hQajJwCY+RiWuCZ9sdtI/XQk7nDK5vC8kkdwixezOlDgvDx7+RT+QjK6FcFT4MpsuoBnHIo/O3StRRg=="], + + "vitest/vite/lightningcss/lightningcss-linux-arm-gnueabihf": ["lightningcss-linux-arm-gnueabihf@1.33.0", "", { "os": "linux", "cpu": "arm" }, "sha512-N7FVBe6iS24MlM6R/4RBTxGhQheZGs7tiQ9U32UtF75NzP5Q7xWPRqLBCKxlRQRk3rY1jCIPLzx7WzOhuUIRLQ=="], + + "vitest/vite/lightningcss/lightningcss-linux-arm64-gnu": ["lightningcss-linux-arm64-gnu@1.33.0", "", { "os": "linux", "cpu": "arm64" }, "sha512-j2v/itmy4HlNxlc6voKXYgBqNi0Ng2LShg4z7GufpEgs05P+2suBVyi9I6YHq5uoVFx9ETin3eCEhLVyXGQnKg=="], + + "vitest/vite/lightningcss/lightningcss-linux-arm64-musl": ["lightningcss-linux-arm64-musl@1.33.0", "", { "os": "linux", "cpu": "arm64" }, "sha512-yiO5ROMuYQgXbC60yjZU5CYSFZGKXL0HFATXt9mHJn1+zW55oCtMI9NfcVhYLMFDL7gV7oBPon/EmMMGg2OvtQ=="], + + "vitest/vite/lightningcss/lightningcss-linux-x64-gnu": ["lightningcss-linux-x64-gnu@1.33.0", "", { "os": "linux", "cpu": "x64" }, "sha512-ar+Ju7LmcN0Jo4FpL4hpFybwNG9/3A/Br5KW2n2jyODg3MEZXaDYADdemoNS+BDNfMgKvylJLj4S5tyRActuAg=="], + + "vitest/vite/lightningcss/lightningcss-linux-x64-musl": ["lightningcss-linux-x64-musl@1.33.0", "", { "os": "linux", "cpu": "x64" }, "sha512-RYiYbkokw0trfKqqzfF55lginwEPrD3OJDfTuJzFs1MK6iFnDenaz1fqLLtX4ITG3OktJQXOeTaw1awrBAlZPw=="], + + "vitest/vite/lightningcss/lightningcss-win32-arm64-msvc": ["lightningcss-win32-arm64-msvc@1.33.0", "", { "os": "win32", "cpu": "arm64" }, "sha512-1K+MPfLSFVpphzpdbfkhlWk6wBrTObBzS2T6db10PNOZgR9GoVsAWzwNyuhUYYbTp23j+4RrncfujZ4uAzXvwA=="], + + "vitest/vite/lightningcss/lightningcss-win32-x64-msvc": ["lightningcss-win32-x64-msvc@1.33.0", "", { "os": "win32", "cpu": "x64" }, "sha512-OlEICDx/Xl0FqSp4bry8zFnCvGpig3Gl4gCquvYwHuqJKEC1+n9NgDniFvqHGmMv1ZkqDJrDqKKSykTDX+ehuA=="], + + "vitest/vite/postcss/nanoid": ["nanoid@3.3.18", "", { "bin": { "nanoid": "bin/nanoid.cjs" } }, "sha512-DTg4MJbGMWkfi6VZFdNt2/caMbQy4Ou+Op/hJQvGEWcnVfoA1QA+xzRKAzw9jD6+GVOOeYr/mIcuDSdug6F6+w=="], } } diff --git a/package.json b/package.json index 1b161049..9c89225f 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,8 @@ "preview": "vite preview", "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json", "lint": "eslint . --ext .js,.ts,.svelte", + "test": "vitest run", + "test:watch": "vitest", "format": "prettier --write .", "format:check": "prettier --check .", "prepare": "husky" @@ -23,6 +25,7 @@ "@types/node": "^22.10.1", "@typescript-eslint/eslint-plugin": "^8.17.0", "@typescript-eslint/parser": "^8.17.0", + "@vitest/coverage-v8": "^4.1.11", "autoprefixer": "^10.5.3", "eslint": "^9.14.0", "eslint-config-prettier": "^9.0.0", @@ -37,7 +40,8 @@ "svelte-eslint-parser": "^0.25.0", "tailwindcss": "^4.3.2", "typescript": "^5.6.3", - "vite": "^5.4.10" + "vite": "^5.4.10", + "vitest": "^4.1.11" }, "dependencies": { "@aws-sdk/client-s3": "^3.500.0", diff --git a/src/modules/auth/application/apikeys.service.test.ts b/src/modules/auth/application/apikeys.service.test.ts new file mode 100644 index 00000000..a7f037df --- /dev/null +++ b/src/modules/auth/application/apikeys.service.test.ts @@ -0,0 +1,150 @@ +import crypto from 'crypto'; +import { beforeEach, describe, expect, it, vi } from 'vitest'; +import { ApiKeysService } from './apikeys.service'; +import type { ApiKeyView } from '../domain/entities'; +import type { ApiKeyRepository } from '../infrastructure/repositories/apikey.repository'; + +function createRepositoryMock() { + return { + listByUser: vi.fn(), + create: vi.fn(), + findById: vi.fn(), + revoke: vi.fn(), + updateKeyMaterial: vi.fn(), + } as unknown as ApiKeyRepository; +} + +describe('ApiKeysService', () => { + const randomBytesSpy = vi.spyOn(crypto, 'randomBytes'); + const randomUuidSpy = vi.spyOn(crypto, 'randomUUID'); + + beforeEach(() => { + vi.clearAllMocks(); + randomBytesSpy.mockReturnValue(Buffer.alloc(24, 0x12)); + randomUuidSpy.mockReturnValue('11111111-1111-4111-8111-111111111111'); + }); + + it('lists keys through the repository', async () => { + const repository = createRepositoryMock(); + const keys: ApiKeyView[] = [ + { + id: 'key-1', + name: 'Deploy', + keyPrefix: 'gvs_12', + expiresAt: null, + lastUsedAt: null, + revokedAt: null, + createdAt: '2026-08-18T00:00:00.000Z', + }, + ]; + + repository.listByUser.mockResolvedValue(keys); + + const service = new ApiKeysService(repository); + + await expect(service.listActiveApiKeys('user-1')).resolves.toEqual(keys); + expect(repository.listByUser).toHaveBeenCalledWith('user-1'); + }); + + it('creates a key with a capped prefix and hashed token', async () => { + const repository = createRepositoryMock(); + const service = new ApiKeysService(repository); + + const result = await service.createApiKey('user-1', 'Deploy', '2026-12-31T00:00:00.000Z'); + + expect(result.token).toBe('gvs_121212121212121212121212121212121212121212121212'); + expect(result.key).toMatchObject({ + id: '11111111-1111-4111-8111-111111111111', + name: 'Deploy', + keyPrefix: 'gvs_12', + expiresAt: '2026-12-31T00:00:00.000Z', + lastUsedAt: null, + }); + + expect(repository.create).toHaveBeenCalledWith({ + id: '11111111-1111-4111-8111-111111111111', + userId: 'user-1', + name: 'Deploy', + keyPrefix: 'gvs_12', + keyHash: expect.any(String), + expiresAt: '2026-12-31T00:00:00.000Z', + }); + }); + + it('revokes an active key and rejects already revoked keys', async () => { + const repository = createRepositoryMock(); + repository.findById + .mockResolvedValueOnce({ + id: 'key-1', + name: 'Deploy', + keyPrefix: 'gvs_12', + expiresAt: null, + lastUsedAt: null, + revokedAt: null, + createdAt: '2026-08-18T00:00:00.000Z', + }) + .mockResolvedValueOnce({ + id: 'key-1', + name: 'Deploy', + keyPrefix: 'gvs_12', + expiresAt: null, + lastUsedAt: null, + revokedAt: '2026-08-18T00:10:00.000Z', + createdAt: '2026-08-18T00:00:00.000Z', + }); + + const service = new ApiKeysService(repository); + + await service.revokeApiKey('user-1', 'key-1'); + await expect(service.revokeApiKey('user-1', 'key-1')).rejects.toThrow('API key is already revoked'); + expect(repository.revoke).toHaveBeenCalledTimes(1); + }); + + it('regenerates the same record instead of creating a new one', async () => { + const repository = createRepositoryMock(); + repository.findById.mockResolvedValue({ + id: 'key-1', + name: 'Deploy', + keyPrefix: 'gvs_old', + expiresAt: '2026-12-31T00:00:00.000Z', + lastUsedAt: null, + revokedAt: null, + createdAt: '2026-08-18T00:00:00.000Z', + }); + + const service = new ApiKeysService(repository); + const result = await service.regenerateApiKey('user-1', 'key-1'); + + expect(repository.updateKeyMaterial).toHaveBeenCalledWith('user-1', 'key-1', { + keyPrefix: 'gvs_12', + keyHash: expect.any(String), + expiresAt: '2026-12-31T00:00:00.000Z', + }); + expect(repository.create).not.toHaveBeenCalled(); + expect(result.key).toMatchObject({ + id: 'key-1', + name: 'Deploy', + keyPrefix: 'gvs_12', + expiresAt: '2026-12-31T00:00:00.000Z', + lastUsedAt: null, + }); + }); + + it('does not regenerate revoked keys', async () => { + const repository = createRepositoryMock(); + repository.findById.mockResolvedValue({ + id: 'key-1', + name: 'Deploy', + keyPrefix: 'gvs_old', + expiresAt: null, + lastUsedAt: null, + revokedAt: '2026-08-18T00:10:00.000Z', + createdAt: '2026-08-18T00:00:00.000Z', + }); + + const service = new ApiKeysService(repository); + + await expect(service.regenerateApiKey('user-1', 'key-1')).rejects.toThrow('API key is revoked'); + expect(repository.updateKeyMaterial).not.toHaveBeenCalled(); + }); +}); \ No newline at end of file diff --git a/src/modules/auth/application/profile.service.test.ts b/src/modules/auth/application/profile.service.test.ts new file mode 100644 index 00000000..f044c102 --- /dev/null +++ b/src/modules/auth/application/profile.service.test.ts @@ -0,0 +1,129 @@ +import { beforeEach, describe, expect, it, vi } from 'vitest'; +import { ProfileService } from './profile.service'; +import type { PasswordService } from './password.service'; +import type { UserRepository } from '../infrastructure/repositories/user.repository'; + +function createUserRepositoryMock() { + return { + findById: vi.fn(), + findByUsername: vi.fn(), + listUsers: vi.fn(), + createUser: vi.fn(), + updateEmail: vi.fn(), + updatePassword: vi.fn(), + updateRole: vi.fn(), + deleteById: vi.fn(), + countAdmins: vi.fn(), + listActiveApiKeys: vi.fn(), + createApiKey: vi.fn(), + revokeApiKey: vi.fn(), + } as unknown as UserRepository; +} + +function createPasswordServiceMock() { + return { + ensureEncryptionKey: vi.fn(), + hashPassword: vi.fn(), + verifyPassword: vi.fn(), + } as unknown as PasswordService; +} + +describe('ProfileService', () => { + beforeEach(() => { + vi.clearAllMocks(); + }); + + it('returns the authenticated user profile as JSON', async () => { + const userRepository = createUserRepositoryMock(); + const passwordService = createPasswordServiceMock(); + const service = new ProfileService(userRepository, passwordService); + + const user = { + toJson: vi.fn().mockReturnValue({ + id: 'user-1', + username: 'alice', + email: 'alice@example.com', + role: { id: 'role-1', name: 'Developer' }, + createdAt: '2026-08-18T00:00:00.000Z', + }), + }; + + userRepository.findById.mockResolvedValue(user); + + await expect(service.getAuthenticatedUserProfile('user-1')).resolves.toEqual({ + id: 'user-1', + username: 'alice', + email: 'alice@example.com', + role: { id: 'role-1', name: 'Developer' }, + createdAt: '2026-08-18T00:00:00.000Z', + }); + + expect(userRepository.findById).toHaveBeenCalledWith('user-1'); + expect(user.toJson).toHaveBeenCalledTimes(1); + }); + + it('returns null when the user profile does not exist', async () => { + const userRepository = createUserRepositoryMock(); + const passwordService = createPasswordServiceMock(); + const service = new ProfileService(userRepository, passwordService); + + userRepository.findById.mockResolvedValue(null); + + await expect(service.getAuthenticatedUserProfile('missing-user')).resolves.toBeNull(); + expect(userRepository.findById).toHaveBeenCalledWith('missing-user'); + }); + + it('updates the email address', async () => { + const userRepository = createUserRepositoryMock(); + const passwordService = createPasswordServiceMock(); + const service = new ProfileService(userRepository, passwordService); + + await service.updateEmail('user-1', 'new@example.com'); + + expect(userRepository.updateEmail).toHaveBeenCalledWith('user-1', 'new@example.com'); + }); + + it('changes the password when the current password is valid', async () => { + const userRepository = createUserRepositoryMock(); + const passwordService = createPasswordServiceMock(); + const service = new ProfileService(userRepository, passwordService); + + userRepository.findById.mockResolvedValue({ + password: 'hashed-current', + }); + passwordService.verifyPassword.mockReturnValue(true); + passwordService.hashPassword.mockReturnValue('hashed-new'); + + await expect(service.changePassword('user-1', 'current-pass', 'new-pass')).resolves.toBe(true); + expect(passwordService.verifyPassword).toHaveBeenCalledWith('current-pass', 'hashed-current'); + expect(passwordService.hashPassword).toHaveBeenCalledWith('new-pass'); + expect(userRepository.updatePassword).toHaveBeenCalledWith('user-1', 'hashed-new'); + }); + + it('returns false when the current password is invalid', async () => { + const userRepository = createUserRepositoryMock(); + const passwordService = createPasswordServiceMock(); + const service = new ProfileService(userRepository, passwordService); + + userRepository.findById.mockResolvedValue({ + password: 'hashed-current', + }); + passwordService.verifyPassword.mockReturnValue(false); + + await expect(service.changePassword('user-1', 'wrong-pass', 'new-pass')).resolves.toBe(false); + expect(userRepository.updatePassword).not.toHaveBeenCalled(); + expect(passwordService.hashPassword).not.toHaveBeenCalled(); + }); + + it('returns false when the user does not exist', async () => { + const userRepository = createUserRepositoryMock(); + const passwordService = createPasswordServiceMock(); + const service = new ProfileService(userRepository, passwordService); + + userRepository.findById.mockResolvedValue(null); + + await expect(service.changePassword('missing-user', 'current-pass', 'new-pass')).resolves.toBe(false); + expect(passwordService.verifyPassword).not.toHaveBeenCalled(); + expect(userRepository.updatePassword).not.toHaveBeenCalled(); + }); +}); \ No newline at end of file diff --git a/src/modules/auth/application/profile.service.ts b/src/modules/auth/application/profile.service.ts index 9f11f74b..9922b503 100644 --- a/src/modules/auth/application/profile.service.ts +++ b/src/modules/auth/application/profile.service.ts @@ -1,13 +1,10 @@ -import type { ApiKeyView } from '../domain/entities'; import { UserRepository } from '../infrastructure/repositories/user.repository'; import { PasswordService } from './password.service'; -import { ApiKeysService } from './apikeys.service'; export class ProfileService { constructor( private readonly userRepository: UserRepository, private readonly passwordService: PasswordService, - private readonly apiKeysService: ApiKeysService, ) {} async getAuthenticatedUserProfile(userId: string): Promise { @@ -29,27 +26,11 @@ export class ProfileService { return false; } - if (!this.passwordService.verifyPassword(currentPassword, user.passwordHash)) { + if (!this.passwordService.verifyPassword(currentPassword, user.password)) { return false; } await this.userRepository.updatePassword(userId, this.passwordService.hashPassword(newPassword)); return true; } - - async listActiveApiKeys(userId: string): Promise { - return this.apiKeysService.listActiveApiKeys(userId); - } - - async createApiKey(userId: string, name: string, expiresAt: string | null): Promise<{ token: string; key: ApiKeyView }> { - return this.apiKeysService.createApiKey(userId, name, expiresAt); - } - - async revokeApiKey(userId: string, keyId: string): Promise { - await this.apiKeysService.revokeApiKey(userId, keyId); - } - - async regenerateApiKey(userId: string, keyId: string): Promise<{ token: string; key: ApiKeyView }> { - return this.apiKeysService.regenerateApiKey(userId, keyId); - } } diff --git a/src/modules/auth/index.ts b/src/modules/auth/index.ts index ad05eec8..4b799159 100644 --- a/src/modules/auth/index.ts +++ b/src/modules/auth/index.ts @@ -19,7 +19,7 @@ export const apiKeysService = new ApiKeysService(apiKeyRepository); export const authService = new AuthService(userRepository, passwordService, sessionService); export const userService = new UserService(userRepository, roleRepository, passwordService); -export const profileService = new ProfileService(userRepository, passwordService, apiKeysService); +export const profileService = new ProfileService(userRepository, passwordService); export { canAccessAdminArea, isAdmin }; diff --git a/src/routes/profile/+page.server.ts b/src/routes/profile/+page.server.ts index 799839c4..d26db62a 100644 --- a/src/routes/profile/+page.server.ts +++ b/src/routes/profile/+page.server.ts @@ -1,5 +1,5 @@ import { fail, redirect } from '@sveltejs/kit'; -import { profileService } from '../../modules/auth'; +import { apiKeysService, profileService } from '../../modules/auth'; import { storageBackendService } from '../../modules/config'; function expiresAtFromDays(expiresInDays: string | null): string | null { @@ -33,7 +33,7 @@ export async function load({ locals, cookies }) { const activeBackend = backends.find((backend) => backend.id === activeBackendId) || null; const gcpConnected = activeBackend?.provider === 'gcs'; - const apiKeys = await profileService.listActiveApiKeys(user.id); + const apiKeys = await apiKeysService.listActiveApiKeys(user.id); return { user: { @@ -99,7 +99,7 @@ export const actions = { const expiresAt = expiresAtFromDays(expiresInDays || null); - const { token } = await profileService.createApiKey(locals.user.id, name, expiresAt); + const { token } = await apiKeysService.createApiKey(locals.user.id, name, expiresAt); return { section: 'apiKeys', message: 'API key created.', createdKey: token }; }, @@ -114,7 +114,7 @@ export const actions = { return fail(400, { section: 'apiKeys', message: 'Key id is required.' }); } - const { token } = await profileService.regenerateApiKey(locals.user.id, keyId); + const { token } = await apiKeysService.regenerateApiKey(locals.user.id, keyId); return { section: 'apiKeys', message: 'API key regenerated.', createdKey: token }; }, @@ -125,7 +125,7 @@ export const actions = { const formData = await request.formData(); const keyId = String(formData.get('keyId') || ''); - await profileService.revokeApiKey(locals.user.id, keyId); + await apiKeysService.revokeApiKey(locals.user.id, keyId); return { section: 'apiKeys', message: 'API key revoked.' }; }, diff --git a/vitest.config.ts b/vitest.config.ts new file mode 100644 index 00000000..30c7f9d3 --- /dev/null +++ b/vitest.config.ts @@ -0,0 +1,9 @@ +import { defineConfig } from 'vitest/config'; + +export default defineConfig({ + test: { + environment: 'node', + include: ['src/**/*.test.ts', 'src/**/*.spec.ts'], + globals: true, + }, +}); \ No newline at end of file From f227100c230d2e6ab6b8ba2f4dab30c6c1694566 Mon Sep 17 00:00:00 2001 From: Carlos Lopez Date: Tue, 18 Aug 2026 21:15:40 +0200 Subject: [PATCH 3/4] github workflow tests --- .github/workflows/ci.yml | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 74a6c536..e7f9d266 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,15 +1,12 @@ name: CI on: - push: - branches: - - develop pull_request: branches: - - develop + - main jobs: - quality: + lint: runs-on: ubuntu-latest steps: @@ -27,8 +24,20 @@ jobs: - name: Run lint run: bun run lint - - name: Run type check - run: bun run check + unit-tests: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup Bun + uses: oven-sh/setup-bun@v2 + with: + bun-version: latest + + - name: Install dependencies + run: bun install - - name: Run formatting check - run: bun run format:check + - name: Run unit tests + run: bun test From 25500be387fa864dfc9b8d608e5edd385322034e Mon Sep 17 00:00:00 2001 From: Carlos Lopez Date: Tue, 18 Aug 2026 21:32:35 +0200 Subject: [PATCH 4/4] validation apikey --- .../auth/application/apikeys.service.test.ts | 82 +++++++++++++------ .../auth/application/apikeys.service.ts | 11 +++ .../repositories/apikey.repository.ts | 15 ++++ 3 files changed, 83 insertions(+), 25 deletions(-) diff --git a/src/modules/auth/application/apikeys.service.test.ts b/src/modules/auth/application/apikeys.service.test.ts index a7f037df..1ddb7a97 100644 --- a/src/modules/auth/application/apikeys.service.test.ts +++ b/src/modules/auth/application/apikeys.service.test.ts @@ -1,27 +1,21 @@ -import crypto from 'crypto'; import { beforeEach, describe, expect, it, vi } from 'vitest'; import { ApiKeysService } from './apikeys.service'; import type { ApiKeyView } from '../domain/entities'; -import type { ApiKeyRepository } from '../infrastructure/repositories/apikey.repository'; -function createRepositoryMock() { +function createRepositoryMock(): any { return { listByUser: vi.fn(), + findValidByHash: vi.fn(), create: vi.fn(), findById: vi.fn(), revoke: vi.fn(), updateKeyMaterial: vi.fn(), - } as unknown as ApiKeyRepository; + }; } describe('ApiKeysService', () => { - const randomBytesSpy = vi.spyOn(crypto, 'randomBytes'); - const randomUuidSpy = vi.spyOn(crypto, 'randomUUID'); - beforeEach(() => { vi.clearAllMocks(); - randomBytesSpy.mockReturnValue(Buffer.alloc(24, 0x12)); - randomUuidSpy.mockReturnValue('11111111-1111-4111-8111-111111111111'); }); it('lists keys through the repository', async () => { @@ -38,7 +32,7 @@ describe('ApiKeysService', () => { }, ]; - repository.listByUser.mockResolvedValue(keys); + repository.listByUser.mockImplementation(async () => keys); const service = new ApiKeysService(repository); @@ -46,26 +40,63 @@ describe('ApiKeysService', () => { expect(repository.listByUser).toHaveBeenCalledWith('user-1'); }); + it('validates an active api key token', async () => { + const repository = createRepositoryMock(); + repository.findValidByHash.mockImplementation(async () => ({ + id: 'key-1', + name: 'Deploy', + keyPrefix: 'gvs_12', + expiresAt: null, + lastUsedAt: null, + revokedAt: null, + createdAt: '2026-08-18T00:00:00.000Z', + })); + + const service = new ApiKeysService(repository); + + await expect(service.validateApiKey('gvs_121212')).resolves.toBe(true); + expect(repository.findValidByHash).toHaveBeenCalledWith(expect.any(String)); + }); + + it('rejects empty api key tokens', async () => { + const repository = createRepositoryMock(); + const service = new ApiKeysService(repository); + + await expect(service.validateApiKey(' ')).resolves.toBe(false); + expect(repository.findValidByHash).not.toHaveBeenCalled(); + }); + + it('returns false when the token does not map to an active key', async () => { + const repository = createRepositoryMock(); + repository.findValidByHash.mockImplementation(async () => null); + + const service = new ApiKeysService(repository); + + await expect(service.validateApiKey('gvs_missing')).resolves.toBe(false); + expect(repository.findValidByHash).toHaveBeenCalledWith(expect.any(String)); + }); + it('creates a key with a capped prefix and hashed token', async () => { const repository = createRepositoryMock(); const service = new ApiKeysService(repository); const result = await service.createApiKey('user-1', 'Deploy', '2026-12-31T00:00:00.000Z'); - expect(result.token).toBe('gvs_121212121212121212121212121212121212121212121212'); + expect(result.token.startsWith('gvs_')).toBe(true); expect(result.key).toMatchObject({ - id: '11111111-1111-4111-8111-111111111111', + id: expect.any(String), name: 'Deploy', - keyPrefix: 'gvs_12', + keyPrefix: result.token.slice(0, 6), expiresAt: '2026-12-31T00:00:00.000Z', lastUsedAt: null, + revokedAt: null, }); expect(repository.create).toHaveBeenCalledWith({ - id: '11111111-1111-4111-8111-111111111111', + id: expect.any(String), userId: 'user-1', name: 'Deploy', - keyPrefix: 'gvs_12', + keyPrefix: result.token.slice(0, 6), keyHash: expect.any(String), expiresAt: '2026-12-31T00:00:00.000Z', }); @@ -74,7 +105,7 @@ describe('ApiKeysService', () => { it('revokes an active key and rejects already revoked keys', async () => { const repository = createRepositoryMock(); repository.findById - .mockResolvedValueOnce({ + .mockImplementationOnce(async () => ({ id: 'key-1', name: 'Deploy', keyPrefix: 'gvs_12', @@ -82,8 +113,8 @@ describe('ApiKeysService', () => { lastUsedAt: null, revokedAt: null, createdAt: '2026-08-18T00:00:00.000Z', - }) - .mockResolvedValueOnce({ + })) + .mockImplementationOnce(async () => ({ id: 'key-1', name: 'Deploy', keyPrefix: 'gvs_12', @@ -91,7 +122,7 @@ describe('ApiKeysService', () => { lastUsedAt: null, revokedAt: '2026-08-18T00:10:00.000Z', createdAt: '2026-08-18T00:00:00.000Z', - }); + })); const service = new ApiKeysService(repository); @@ -102,7 +133,7 @@ describe('ApiKeysService', () => { it('regenerates the same record instead of creating a new one', async () => { const repository = createRepositoryMock(); - repository.findById.mockResolvedValue({ + repository.findById.mockImplementation(async () => ({ id: 'key-1', name: 'Deploy', keyPrefix: 'gvs_old', @@ -110,13 +141,13 @@ describe('ApiKeysService', () => { lastUsedAt: null, revokedAt: null, createdAt: '2026-08-18T00:00:00.000Z', - }); + })); const service = new ApiKeysService(repository); const result = await service.regenerateApiKey('user-1', 'key-1'); expect(repository.updateKeyMaterial).toHaveBeenCalledWith('user-1', 'key-1', { - keyPrefix: 'gvs_12', + keyPrefix: result.token.slice(0, 6), keyHash: expect.any(String), expiresAt: '2026-12-31T00:00:00.000Z', }); @@ -124,15 +155,16 @@ describe('ApiKeysService', () => { expect(result.key).toMatchObject({ id: 'key-1', name: 'Deploy', - keyPrefix: 'gvs_12', + keyPrefix: result.token.slice(0, 6), expiresAt: '2026-12-31T00:00:00.000Z', lastUsedAt: null, + revokedAt: null, }); }); it('does not regenerate revoked keys', async () => { const repository = createRepositoryMock(); - repository.findById.mockResolvedValue({ + repository.findById.mockImplementation(async () => ({ id: 'key-1', name: 'Deploy', keyPrefix: 'gvs_old', @@ -140,7 +172,7 @@ describe('ApiKeysService', () => { lastUsedAt: null, revokedAt: '2026-08-18T00:10:00.000Z', createdAt: '2026-08-18T00:00:00.000Z', - }); + })); const service = new ApiKeysService(repository); diff --git a/src/modules/auth/application/apikeys.service.ts b/src/modules/auth/application/apikeys.service.ts index 2d9f6b8b..dd990ca3 100644 --- a/src/modules/auth/application/apikeys.service.ts +++ b/src/modules/auth/application/apikeys.service.ts @@ -17,6 +17,15 @@ export class ApiKeysService { return this.apiKeyRepository.listByUser(userId); } + async validateApiKey(token: string): Promise { + if (!token.trim()) { + return false; + } + + const key = await this.apiKeyRepository.findValidByHash(hashApiKey(token)); + return key !== null; + } + async createApiKey(userId: string, name: string, expiresAt: string | null): Promise<{ token: string; key: ApiKeyView }> { const token = `gvs_${crypto.randomBytes(24).toString('hex')}`; const id = crypto.randomUUID(); @@ -39,6 +48,7 @@ export class ApiKeysService { keyPrefix, expiresAt, lastUsedAt: null, + revokedAt: null, createdAt: new Date().toISOString(), }, }; @@ -86,6 +96,7 @@ export class ApiKeysService { keyPrefix, expiresAt: existing.expiresAt, lastUsedAt: null, + revokedAt: null, createdAt: new Date().toISOString(), }, }; diff --git a/src/modules/auth/infrastructure/repositories/apikey.repository.ts b/src/modules/auth/infrastructure/repositories/apikey.repository.ts index c4d10c90..160a575b 100644 --- a/src/modules/auth/infrastructure/repositories/apikey.repository.ts +++ b/src/modules/auth/infrastructure/repositories/apikey.repository.ts @@ -33,6 +33,21 @@ export class ApiKeyRepository extends Repository { return this.toJSON(row); } + async findValidByHash(keyHash: string): Promise { + const result = await this.db.select().from(ApiKeyEntity).where({ keyHash }).limit(1); + const row = result.rows[0] as ApiKeyRow | undefined; + + if (!row || row.revokedAt) { + return null; + } + + if (row.expiresAt && row.expiresAt <= new Date().toISOString()) { + return null; + } + + return this.toJSON(row); + } + async create(input: { id: string; userId: string;