From 10003580a145b5698e598cbe42d2144bac3f8cff Mon Sep 17 00:00:00 2001 From: Luca Knobel Date: Sun, 16 Aug 2026 15:58:53 +0000 Subject: [PATCH 1/8] refactor: simplify rate limiting logic and improve test coverage --- src/services/rateLimitService.ts | 210 +++++++++++--------------- tests/rateLimitService.test.ts | 249 +++++++++++-------------------- 2 files changed, 173 insertions(+), 286 deletions(-) diff --git a/src/services/rateLimitService.ts b/src/services/rateLimitService.ts index 649fb46..8cee4ef 100644 --- a/src/services/rateLimitService.ts +++ b/src/services/rateLimitService.ts @@ -1,147 +1,109 @@ -import { db } from "../db/index.js"; -import { rateLimits } from "../db/schema.js"; -import { eq } from "drizzle-orm"; - export interface RateLimitResult { - allowed: boolean; - currentCount: number; - maxLimit: number; - resetDate: string; + allowed: boolean; + currentCount: number; + maxLimit: number; + resetDate: string; } export interface RateLimitService { - checkLimit(date: string): Promise; - incrementCount(date: string): Promise; - getSwissDate(): string; + checkLimit(date: string): Promise; + incrementCount(date: string): Promise; + getSwissDate(): string; } +const productionCounts = new Map(); + /** * Rate Limiting Service * Handles contact form submission limits per day */ export class ContactRateLimitService implements RateLimitService { - private readonly maxDailyEmails = 10; - - /** - * Get current date in Swiss timezone (YYYY-MM-DD) - */ - getSwissDate(): string { - return new Date().toLocaleDateString('de-CH', { - year: 'numeric', - month: '2-digit', - day: '2-digit', - timeZone: 'Europe/Zurich' - }).split('.').reverse().join('-'); - } - - /** - * Check if rate limit is exceeded for given date - */ - async checkLimit(date: string): Promise { - try { - const currentRecord = db.select({ count: rateLimits.count }) - .from(rateLimits) - .where(eq(rateLimits.date, date)) - .get(); - - const currentCount = currentRecord?.count ?? 0; - const allowed = currentCount < this.maxDailyEmails; - - return { - allowed, - currentCount, - maxLimit: this.maxDailyEmails, - resetDate: date, - }; - } catch (error) { - console.error("Rate limit check failed:", error); - // Fail open - allow request if DB is unavailable - return { - allowed: true, - currentCount: 0, - maxLimit: this.maxDailyEmails, - resetDate: date, - }; - } - } - - /** - * Increment rate limit counter for successful email - */ - async incrementCount(date: string): Promise { - try { - // Check if record exists - const existingRecord = db.select() - .from(rateLimits) - .where(eq(rateLimits.date, date)) - .get(); - - if (existingRecord) { - // Update existing record - db.update(rateLimits) - .set({ count: existingRecord.count + 1 }) - .where(eq(rateLimits.date, date)) - .run(); - } else { - // Insert new record - db.insert(rateLimits) - .values({ date, count: 1 }) - .run(); - } - - console.log(`Rate limit counter updated for ${date}`); - } catch (error) { - console.error("Failed to update rate limit counter:", error); - // Don't throw - email was already sent successfully - } - } + private readonly maxDailyEmails = 10; + + /** + * Get current date in Swiss timezone (YYYY-MM-DD) + */ + getSwissDate(): string { + return new Date() + .toLocaleDateString("de-CH", { + year: "numeric", + month: "2-digit", + day: "2-digit", + timeZone: "Europe/Zurich", + }) + .split(".") + .reverse() + .join("-"); + } + + /** + * Check if rate limit is exceeded for given date + */ + async checkLimit(date: string): Promise { + const currentCount = productionCounts.get(date) ?? 0; + + return { + allowed: currentCount < this.maxDailyEmails, + currentCount, + maxLimit: this.maxDailyEmails, + resetDate: date, + }; + } + + /** + * Increment rate limit counter for successful email + */ + async incrementCount(date: string): Promise { + const currentCount = productionCounts.get(date) ?? 0; + productionCounts.set(date, currentCount + 1); + } } /** * Mock service for testing */ export class MockRateLimitService implements RateLimitService { - private counts = new Map(); - private readonly maxDailyEmails = 10; - - getSwissDate(): string { - return "2025-10-11"; // Fixed date for testing - } - - async checkLimit(date: string): Promise { - const currentCount = this.counts.get(date) ?? 0; - const allowed = currentCount < this.maxDailyEmails; - - return { - allowed, - currentCount, - maxLimit: this.maxDailyEmails, - resetDate: date, - }; - } - - async incrementCount(date: string): Promise { - const current = this.counts.get(date) ?? 0; - this.counts.set(date, current + 1); - } - - // Test helpers - reset(): void { - this.counts.clear(); - } - - setCount(date: string, count: number): void { - this.counts.set(date, count); - } + private counts = new Map(); + private readonly maxDailyEmails = 10; + + getSwissDate(): string { + return "2025-10-11"; // Fixed date for testing + } + + async checkLimit(date: string): Promise { + const currentCount = this.counts.get(date) ?? 0; + const allowed = currentCount < this.maxDailyEmails; + + return { + allowed, + currentCount, + maxLimit: this.maxDailyEmails, + resetDate: date, + }; + } + + async incrementCount(date: string): Promise { + const current = this.counts.get(date) ?? 0; + this.counts.set(date, current + 1); + } + + // Test helpers + reset(): void { + this.counts.clear(); + } + + setCount(date: string, count: number): void { + this.counts.set(date, count); + } } // Factory function export const getRateLimitService = (): RateLimitService => { - const isDevelopment = process.env.NODE_ENV !== "production"; + const isDevelopment = process.env.NODE_ENV !== "production"; - if (isDevelopment) { - return new MockRateLimitService(); - } + if (isDevelopment) { + return new MockRateLimitService(); + } - return new ContactRateLimitService(); -}; \ No newline at end of file + return new ContactRateLimitService(); +}; diff --git a/tests/rateLimitService.test.ts b/tests/rateLimitService.test.ts index 529782d..4a5d752 100644 --- a/tests/rateLimitService.test.ts +++ b/tests/rateLimitService.test.ts @@ -1,170 +1,95 @@ -import { describe, it, expect, beforeEach, vi } from 'vitest'; -import { ContactRateLimitService } from '../src/services/rateLimitService.js'; - -// Mock the database -vi.mock('../src/db/index.js', () => ({ - db: { - select: vi.fn(), - insert: vi.fn(), - update: vi.fn(), - } -})); - -describe('ContactRateLimitService', () => { - let service: ContactRateLimitService; - let mockDb: any; - - beforeEach(async () => { - vi.clearAllMocks(); - const dbModule = await import('../src/db/index.js'); - mockDb = dbModule.db; - service = new ContactRateLimitService(); +import { describe, it, expect, beforeEach } from "vitest"; +import { ContactRateLimitService } from "../src/services/rateLimitService.js"; + +describe("ContactRateLimitService", () => { + let service: ContactRateLimitService; + + beforeEach(() => { + service = new ContactRateLimitService(); + }); + + describe("getSwissDate", () => { + it("should return date in YYYY-MM-DD format", () => { + const date = service.getSwissDate(); + expect(date).toMatch(/^\d{4}-\d{2}-\d{2}$/); }); - describe('getSwissDate', () => { - it('should return date in YYYY-MM-DD format', () => { - const date = service.getSwissDate(); - expect(date).toMatch(/^\d{4}-\d{2}-\d{2}$/); - }); - - it('should return consistent date for same day', () => { - const date1 = service.getSwissDate(); - const date2 = service.getSwissDate(); - expect(date1).toBe(date2); - }); + it("should return consistent date for same day", () => { + const date1 = service.getSwissDate(); + const date2 = service.getSwissDate(); + expect(date1).toBe(date2); }); + }); + + describe("checkLimit", () => { + it("should allow requests when under limit", async () => { + const date = "2025-10-11-under"; + await service.incrementCount(date); + await service.incrementCount(date); + await service.incrementCount(date); + await service.incrementCount(date); + await service.incrementCount(date); + + const result = await service.checkLimit(date); + + expect(result.allowed).toBe(true); + expect(result.currentCount).toBe(5); + expect(result.maxLimit).toBe(10); + }); + + it("should deny requests when at limit", async () => { + const date = "2025-10-11-at"; + for (let count = 0; count < 10; count++) { + await service.incrementCount(date); + } + + const result = await service.checkLimit(date); - describe('checkLimit', () => { - it('should allow requests when under limit', async () => { - mockDb.select.mockReturnValue({ - from: vi.fn().mockReturnValue({ - where: vi.fn().mockReturnValue({ - get: vi.fn().mockReturnValue({ count: 5 }) - }) - }) - }); - - const result = await service.checkLimit('2025-10-11'); - - expect(result.allowed).toBe(true); - expect(result.currentCount).toBe(5); - expect(result.maxLimit).toBe(10); - }); - - it('should deny requests when at limit', async () => { - mockDb.select.mockReturnValue({ - from: vi.fn().mockReturnValue({ - where: vi.fn().mockReturnValue({ - get: vi.fn().mockReturnValue({ count: 10 }) - }) - }) - }); - - const result = await service.checkLimit('2025-10-11'); - - expect(result.allowed).toBe(false); - expect(result.currentCount).toBe(10); - }); - - it('should deny requests when over limit', async () => { - mockDb.select.mockReturnValue({ - from: vi.fn().mockReturnValue({ - where: vi.fn().mockReturnValue({ - get: vi.fn().mockReturnValue({ count: 15 }) - }) - }) - }); - - const result = await service.checkLimit('2025-10-11'); - - expect(result.allowed).toBe(false); - expect(result.currentCount).toBe(15); - }); - - it('should allow when no record exists', async () => { - mockDb.select.mockReturnValue({ - from: vi.fn().mockReturnValue({ - where: vi.fn().mockReturnValue({ - get: vi.fn().mockReturnValue(undefined) - }) - }) - }); - - const result = await service.checkLimit('2025-10-11'); - - expect(result.allowed).toBe(true); - expect(result.currentCount).toBe(0); - }); - - it('should fail open on DB error', async () => { - mockDb.select.mockReturnValue({ - from: vi.fn().mockReturnValue({ - where: vi.fn().mockReturnValue({ - get: vi.fn(() => { throw new Error('DB error'); }) - }) - }) - }); - - const result = await service.checkLimit('2025-10-11'); - - expect(result.allowed).toBe(true); - expect(result.currentCount).toBe(0); - }); + expect(result.allowed).toBe(false); + expect(result.currentCount).toBe(10); }); - describe('incrementCount', () => { - it('should insert new record when none exists', async () => { - mockDb.select.mockReturnValue({ - from: vi.fn().mockReturnValue({ - where: vi.fn().mockReturnValue({ - get: vi.fn().mockReturnValue(undefined) - }) - }) - }); - - mockDb.insert.mockReturnValue({ - values: vi.fn().mockReturnValue({ - run: vi.fn() - }) - }); - - await service.incrementCount('2025-10-11'); - - expect(mockDb.insert).toHaveBeenCalled(); - }); - - it('should update existing record', async () => { - mockDb.select.mockReturnValue({ - from: vi.fn().mockReturnValue({ - where: vi.fn().mockReturnValue({ - get: vi.fn().mockReturnValue({ date: '2025-10-11', count: 5 }) - }) - }) - }); - - mockDb.update.mockReturnValue({ - set: vi.fn().mockReturnValue({ - where: vi.fn().mockReturnValue({ - run: vi.fn() - }) - }) - }); - - await service.incrementCount('2025-10-11'); - - expect(mockDb.update).toHaveBeenCalled(); - }); - - it('should not throw on DB error', async () => { - mockDb.select.mockReturnValue({ - from: vi.fn().mockReturnValue({ - where: vi.fn().mockReturnValue({ - get: vi.fn(() => { throw new Error('DB error'); }) - }) - }) - }); - - await expect(service.incrementCount('2025-10-11')).resolves.not.toThrow(); - }); + it("should deny requests when over limit", async () => { + const date = "2025-10-11-over"; + for (let count = 0; count < 15; count++) { + await service.incrementCount(date); + } + + const result = await service.checkLimit(date); + + expect(result.allowed).toBe(false); + expect(result.currentCount).toBe(15); + }); + + it("should allow when no record exists", async () => { + const result = await service.checkLimit("2025-10-11-empty"); + + expect(result.allowed).toBe(true); + expect(result.currentCount).toBe(0); + }); + + it("should share state across service instances", async () => { + const secondService = new ContactRateLimitService(); + const date = "2025-10-11-shared"; + + await service.incrementCount(date); + + const result = await secondService.checkLimit(date); + + expect(result.currentCount).toBe(1); + }); + }); + + describe("incrementCount", () => { + it("should increment the in-memory counter", async () => { + const date = "2025-10-11-increment"; + + await service.incrementCount(date); + await service.incrementCount(date); + + const result = await service.checkLimit(date); + + expect(result.currentCount).toBe(2); }); + }); }); From 9f43732dc2e63dde608cbde8fbd70e8172b1ad5f Mon Sep 17 00:00:00 2001 From: Luca Knobel Date: Sun, 16 Aug 2026 16:00:48 +0000 Subject: [PATCH 2/8] test: enhance rate limit tests for edge cases and reset functionality --- tests/rateLimitService.test.ts | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/rateLimitService.test.ts b/tests/rateLimitService.test.ts index 4a5d752..7e36a64 100644 --- a/tests/rateLimitService.test.ts +++ b/tests/rateLimitService.test.ts @@ -49,6 +49,22 @@ describe("ContactRateLimitService", () => { expect(result.currentCount).toBe(10); }); + it("should allow the tenth email and block the eleventh", async () => { + const date = "2025-10-11-tenth"; + for (let count = 0; count < 9; count++) { + await service.incrementCount(date); + } + + const tenthEmail = await service.checkLimit(date); + await service.incrementCount(date); + const eleventhEmail = await service.checkLimit(date); + + expect(tenthEmail.allowed).toBe(true); + expect(tenthEmail.currentCount).toBe(9); + expect(eleventhEmail.allowed).toBe(false); + expect(eleventhEmail.currentCount).toBe(10); + }); + it("should deny requests when over limit", async () => { const date = "2025-10-11-over"; for (let count = 0; count < 15; count++) { @@ -78,6 +94,21 @@ describe("ContactRateLimitService", () => { expect(result.currentCount).toBe(1); }); + + it("should reset the counter for a new Swiss calendar day", async () => { + const firstDate = "2025-10-11-reset"; + const secondDate = "2025-10-12-reset"; + + for (let count = 0; count < 10; count++) { + await service.incrementCount(firstDate); + } + + const result = await service.checkLimit(secondDate); + + expect(result.allowed).toBe(true); + expect(result.currentCount).toBe(0); + expect(result.resetDate).toBe(secondDate); + }); }); describe("incrementCount", () => { From f4478f27dc052873cab92dee0360b2fd051d9919 Mon Sep 17 00:00:00 2001 From: Luca Knobel Date: Sun, 16 Aug 2026 16:03:47 +0000 Subject: [PATCH 3/8] refactor: remove rate limiting database schema and related migrations --- src/db/index.ts | 12 ---- .../migrations/0000_nosy_moira_mactaggert.sql | 7 --- src/db/migrations/meta/0000_snapshot.json | 58 ------------------- src/db/migrations/meta/_journal.json | 13 ----- src/db/schema.ts | 13 ----- 5 files changed, 103 deletions(-) delete mode 100644 src/db/index.ts delete mode 100644 src/db/migrations/0000_nosy_moira_mactaggert.sql delete mode 100644 src/db/migrations/meta/0000_snapshot.json delete mode 100644 src/db/migrations/meta/_journal.json delete mode 100644 src/db/schema.ts diff --git a/src/db/index.ts b/src/db/index.ts deleted file mode 100644 index 42229ac..0000000 --- a/src/db/index.ts +++ /dev/null @@ -1,12 +0,0 @@ -import Database from "better-sqlite3"; -import { drizzle } from "drizzle-orm/better-sqlite3"; -import * as schema from "./schema.js"; - -// Create or connect to SQLite database using environment variable -const sqlite = new Database(process.env.DATABASE_URL!); - -// Enable WAL mode for better performance -sqlite.pragma("journal_mode = WAL"); - -// Initialize Drizzle ORM with schema -export const db = drizzle(sqlite, { schema }); \ No newline at end of file diff --git a/src/db/migrations/0000_nosy_moira_mactaggert.sql b/src/db/migrations/0000_nosy_moira_mactaggert.sql deleted file mode 100644 index 16a771e..0000000 --- a/src/db/migrations/0000_nosy_moira_mactaggert.sql +++ /dev/null @@ -1,7 +0,0 @@ -CREATE TABLE `rate_limits` ( - `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, - `date` text NOT NULL, - `count` integer DEFAULT 0 NOT NULL -); ---> statement-breakpoint -CREATE UNIQUE INDEX `rate_limits_date_unique` ON `rate_limits` (`date`); \ No newline at end of file diff --git a/src/db/migrations/meta/0000_snapshot.json b/src/db/migrations/meta/0000_snapshot.json deleted file mode 100644 index 5a7fb55..0000000 --- a/src/db/migrations/meta/0000_snapshot.json +++ /dev/null @@ -1,58 +0,0 @@ -{ - "version": "6", - "dialect": "sqlite", - "id": "ca5424ab-a700-4527-adc7-9d7473652de4", - "prevId": "00000000-0000-0000-0000-000000000000", - "tables": { - "rate_limits": { - "name": "rate_limits", - "columns": { - "id": { - "name": "id", - "type": "integer", - "primaryKey": true, - "notNull": true, - "autoincrement": true - }, - "date": { - "name": "date", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "count": { - "name": "count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - } - }, - "indexes": { - "rate_limits_date_unique": { - "name": "rate_limits_date_unique", - "columns": [ - "date" - ], - "isUnique": true - } - }, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - } - }, - "views": {}, - "enums": {}, - "_meta": { - "schemas": {}, - "tables": {}, - "columns": {} - }, - "internal": { - "indexes": {} - } -} \ No newline at end of file diff --git a/src/db/migrations/meta/_journal.json b/src/db/migrations/meta/_journal.json deleted file mode 100644 index eaf4e5b..0000000 --- a/src/db/migrations/meta/_journal.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "version": "7", - "dialect": "sqlite", - "entries": [ - { - "idx": 0, - "version": "6", - "when": 1760257207718, - "tag": "0000_nosy_moira_mactaggert", - "breakpoints": true - } - ] -} \ No newline at end of file diff --git a/src/db/schema.ts b/src/db/schema.ts deleted file mode 100644 index 37e36ac..0000000 --- a/src/db/schema.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { sqliteTable as table } from "drizzle-orm/sqlite-core"; -import * as t from "drizzle-orm/sqlite-core"; - -/* Rate limiting table to track contact form submissions per day */ -export const rateLimits = table("rate_limits", { - id: t.int().primaryKey({ autoIncrement: true }), - date: t.text().notNull().unique(), /* YYYY-MM-D */ - count: t.int().notNull().default(0), /* Submissions */ -}); - -export type RateLimit = typeof rateLimits.$inferSelect; -export type InsertRateLimit = typeof rateLimits.$inferInsert; - From 214b55e9bb4b8e8c15d88e0dcac73ec169fb08d8 Mon Sep 17 00:00:00 2001 From: Luca Knobel Date: Sun, 16 Aug 2026 16:05:49 +0000 Subject: [PATCH 4/8] refactor: remove mock rate limiting service and related logic --- src/services/rateLimitService.ts | 44 -------------------------------- 1 file changed, 44 deletions(-) diff --git a/src/services/rateLimitService.ts b/src/services/rateLimitService.ts index 8cee4ef..5fc9b40 100644 --- a/src/services/rateLimitService.ts +++ b/src/services/rateLimitService.ts @@ -59,51 +59,7 @@ export class ContactRateLimitService implements RateLimitService { } } -/** - * Mock service for testing - */ -export class MockRateLimitService implements RateLimitService { - private counts = new Map(); - private readonly maxDailyEmails = 10; - - getSwissDate(): string { - return "2025-10-11"; // Fixed date for testing - } - - async checkLimit(date: string): Promise { - const currentCount = this.counts.get(date) ?? 0; - const allowed = currentCount < this.maxDailyEmails; - - return { - allowed, - currentCount, - maxLimit: this.maxDailyEmails, - resetDate: date, - }; - } - - async incrementCount(date: string): Promise { - const current = this.counts.get(date) ?? 0; - this.counts.set(date, current + 1); - } - - // Test helpers - reset(): void { - this.counts.clear(); - } - - setCount(date: string, count: number): void { - this.counts.set(date, count); - } -} - // Factory function export const getRateLimitService = (): RateLimitService => { - const isDevelopment = process.env.NODE_ENV !== "production"; - - if (isDevelopment) { - return new MockRateLimitService(); - } - return new ContactRateLimitService(); }; From 72d5597f330d4b9e180640201f76c8b40fc2fa96 Mon Sep 17 00:00:00 2001 From: Luca Knobel Date: Sun, 16 Aug 2026 16:09:00 +0000 Subject: [PATCH 5/8] refactor: remove now unused database-related scripts and dependencies from package.json --- package-lock.json | 1131 ++------------------------------------------- package.json | 7 - 2 files changed, 44 insertions(+), 1094 deletions(-) diff --git a/package-lock.json b/package-lock.json index a8ee589..9134183 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,16 +17,12 @@ "@iconify/vue": "^5.0.0", "astro": "^5.15.3", "astro-icon": "^1.1.5", - "better-sqlite3": "^12.4.1", - "drizzle-orm": "^0.44.6", "nodemailer": "^7.0.9", "typescript": "^5.9.3", "vue": "^3.5.22" }, "devDependencies": { - "@types/better-sqlite3": "^7.6.13", "@types/nodemailer": "^7.0.2", - "drizzle-kit": "^0.31.5", "vitest": "^3.2.4" } }, @@ -1389,13 +1385,6 @@ "node": ">=18" } }, - "node_modules/@drizzle-team/brocli": { - "version": "0.10.2", - "resolved": "https://registry.npmjs.org/@drizzle-team/brocli/-/brocli-0.10.2.tgz", - "integrity": "sha512-z33Il7l5dKjUgGULTqBsQBQwckHh5AbIuxhdsIxDDiZAzBOrZO6q9ogcWC65kU382AfynTfgNumVcNIjuIua6w==", - "dev": true, - "license": "Apache-2.0" - }, "node_modules/@emmetio/abbreviation": { "version": "2.3.3", "resolved": "https://registry.npmjs.org/@emmetio/abbreviation/-/abbreviation-2.3.3.tgz", @@ -1460,442 +1449,6 @@ "tslib": "^2.4.0" } }, - "node_modules/@esbuild-kit/core-utils": { - "version": "3.3.2", - "resolved": "https://registry.npmjs.org/@esbuild-kit/core-utils/-/core-utils-3.3.2.tgz", - "integrity": "sha512-sPRAnw9CdSsRmEtnsl2WXWdyquogVpB3yZ3dgwJfe8zrOzTsV7cJvmwrKVa+0ma5BoiGJ+BoqkMvawbayKUsqQ==", - "deprecated": "Merged into tsx: https://tsx.is", - "dev": true, - "license": "MIT", - "dependencies": { - "esbuild": "~0.18.20", - "source-map-support": "^0.5.21" - } - }, - "node_modules/@esbuild-kit/core-utils/node_modules/@esbuild/android-arm": { - "version": "0.18.20", - "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.18.20.tgz", - "integrity": "sha512-fyi7TDI/ijKKNZTUJAQqiG5T7YjJXgnzkURqmGj13C6dCqckZBLdl4h7bkhHt/t0WP+zO9/zwroDvANaOqO5Sw==", - "cpu": [ - "arm" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "android" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild-kit/core-utils/node_modules/@esbuild/android-arm64": { - "version": "0.18.20", - "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.18.20.tgz", - "integrity": "sha512-Nz4rJcchGDtENV0eMKUNa6L12zz2zBDXuhj/Vjh18zGqB44Bi7MBMSXjgunJgjRhCmKOjnPuZp4Mb6OKqtMHLQ==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "android" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild-kit/core-utils/node_modules/@esbuild/android-x64": { - "version": "0.18.20", - "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.18.20.tgz", - "integrity": "sha512-8GDdlePJA8D6zlZYJV/jnrRAi6rOiNaCC/JclcXpB+KIuvfBN4owLtgzY2bsxnx666XjJx2kDPUmnTtR8qKQUg==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "android" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild-kit/core-utils/node_modules/@esbuild/darwin-arm64": { - "version": "0.18.20", - "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.18.20.tgz", - "integrity": "sha512-bxRHW5kHU38zS2lPTPOyuyTm+S+eobPUnTNkdJEfAddYgEcll4xkT8DB9d2008DtTbl7uJag2HuE5NZAZgnNEA==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild-kit/core-utils/node_modules/@esbuild/darwin-x64": { - "version": "0.18.20", - "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.18.20.tgz", - "integrity": "sha512-pc5gxlMDxzm513qPGbCbDukOdsGtKhfxD1zJKXjCCcU7ju50O7MeAZ8c4krSJcOIJGFR+qx21yMMVYwiQvyTyQ==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild-kit/core-utils/node_modules/@esbuild/freebsd-arm64": { - "version": "0.18.20", - "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.18.20.tgz", - "integrity": "sha512-yqDQHy4QHevpMAaxhhIwYPMv1NECwOvIpGCZkECn8w2WFHXjEwrBn3CeNIYsibZ/iZEUemj++M26W3cNR5h+Tw==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "freebsd" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild-kit/core-utils/node_modules/@esbuild/freebsd-x64": { - "version": "0.18.20", - "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.18.20.tgz", - "integrity": "sha512-tgWRPPuQsd3RmBZwarGVHZQvtzfEBOreNuxEMKFcd5DaDn2PbBxfwLcj4+aenoh7ctXcbXmOQIn8HI6mCSw5MQ==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "freebsd" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild-kit/core-utils/node_modules/@esbuild/linux-arm": { - "version": "0.18.20", - "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.18.20.tgz", - "integrity": "sha512-/5bHkMWnq1EgKr1V+Ybz3s1hWXok7mDFUMQ4cG10AfW3wL02PSZi5kFpYKrptDsgb2WAJIvRcDm+qIvXf/apvg==", - "cpu": [ - "arm" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild-kit/core-utils/node_modules/@esbuild/linux-arm64": { - "version": "0.18.20", - "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.18.20.tgz", - "integrity": "sha512-2YbscF+UL7SQAVIpnWvYwM+3LskyDmPhe31pE7/aoTMFKKzIc9lLbyGUpmmb8a8AixOL61sQ/mFh3jEjHYFvdA==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild-kit/core-utils/node_modules/@esbuild/linux-ia32": { - "version": "0.18.20", - "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.18.20.tgz", - "integrity": "sha512-P4etWwq6IsReT0E1KHU40bOnzMHoH73aXp96Fs8TIT6z9Hu8G6+0SHSw9i2isWrD2nbx2qo5yUqACgdfVGx7TA==", - "cpu": [ - "ia32" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild-kit/core-utils/node_modules/@esbuild/linux-loong64": { - "version": "0.18.20", - "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.18.20.tgz", - "integrity": "sha512-nXW8nqBTrOpDLPgPY9uV+/1DjxoQ7DoB2N8eocyq8I9XuqJ7BiAMDMf9n1xZM9TgW0J8zrquIb/A7s3BJv7rjg==", - "cpu": [ - "loong64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild-kit/core-utils/node_modules/@esbuild/linux-mips64el": { - "version": "0.18.20", - "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.18.20.tgz", - "integrity": "sha512-d5NeaXZcHp8PzYy5VnXV3VSd2D328Zb+9dEq5HE6bw6+N86JVPExrA6O68OPwobntbNJ0pzCpUFZTo3w0GyetQ==", - "cpu": [ - "mips64el" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild-kit/core-utils/node_modules/@esbuild/linux-ppc64": { - "version": "0.18.20", - "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.18.20.tgz", - "integrity": "sha512-WHPyeScRNcmANnLQkq6AfyXRFr5D6N2sKgkFo2FqguP44Nw2eyDlbTdZwd9GYk98DZG9QItIiTlFLHJHjxP3FA==", - "cpu": [ - "ppc64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild-kit/core-utils/node_modules/@esbuild/linux-riscv64": { - "version": "0.18.20", - "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.18.20.tgz", - "integrity": "sha512-WSxo6h5ecI5XH34KC7w5veNnKkju3zBRLEQNY7mv5mtBmrP/MjNBCAlsM2u5hDBlS3NGcTQpoBvRzqBcRtpq1A==", - "cpu": [ - "riscv64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild-kit/core-utils/node_modules/@esbuild/linux-s390x": { - "version": "0.18.20", - "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.18.20.tgz", - "integrity": "sha512-+8231GMs3mAEth6Ja1iK0a1sQ3ohfcpzpRLH8uuc5/KVDFneH6jtAJLFGafpzpMRO6DzJ6AvXKze9LfFMrIHVQ==", - "cpu": [ - "s390x" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild-kit/core-utils/node_modules/@esbuild/linux-x64": { - "version": "0.18.20", - "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.18.20.tgz", - "integrity": "sha512-UYqiqemphJcNsFEskc73jQ7B9jgwjWrSayxawS6UVFZGWrAAtkzjxSqnoclCXxWtfwLdzU+vTpcNYhpn43uP1w==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild-kit/core-utils/node_modules/@esbuild/netbsd-x64": { - "version": "0.18.20", - "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.18.20.tgz", - "integrity": "sha512-iO1c++VP6xUBUmltHZoMtCUdPlnPGdBom6IrO4gyKPFFVBKioIImVooR5I83nTew5UOYrk3gIJhbZh8X44y06A==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "netbsd" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild-kit/core-utils/node_modules/@esbuild/openbsd-x64": { - "version": "0.18.20", - "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.18.20.tgz", - "integrity": "sha512-e5e4YSsuQfX4cxcygw/UCPIEP6wbIL+se3sxPdCiMbFLBWu0eiZOJ7WoD+ptCLrmjZBK1Wk7I6D/I3NglUGOxg==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "openbsd" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild-kit/core-utils/node_modules/@esbuild/sunos-x64": { - "version": "0.18.20", - "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.18.20.tgz", - "integrity": "sha512-kDbFRFp0YpTQVVrqUd5FTYmWo45zGaXe0X8E1G/LKFC0v8x0vWrhOWSLITcCn63lmZIxfOMXtCfti/RxN/0wnQ==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "sunos" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild-kit/core-utils/node_modules/@esbuild/win32-arm64": { - "version": "0.18.20", - "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.18.20.tgz", - "integrity": "sha512-ddYFR6ItYgoaq4v4JmQQaAI5s7npztfV4Ag6NrhiaW0RrnOXqBkgwZLofVTlq1daVTQNhtI5oieTvkRPfZrePg==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild-kit/core-utils/node_modules/@esbuild/win32-ia32": { - "version": "0.18.20", - "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.18.20.tgz", - "integrity": "sha512-Wv7QBi3ID/rROT08SABTS7eV4hX26sVduqDOTe1MvGMjNd3EjOz4b7zeexIR62GTIEKrfJXKL9LFxTYgkyeu7g==", - "cpu": [ - "ia32" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild-kit/core-utils/node_modules/@esbuild/win32-x64": { - "version": "0.18.20", - "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.18.20.tgz", - "integrity": "sha512-kTdfRcSiDfQca/y9QIkng02avJ+NCaQvrMejlsB3RRv5sE9rRoeBPISaZpKxHELzRxZyLvNts1P27W3wV+8geQ==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild-kit/core-utils/node_modules/esbuild": { - "version": "0.18.20", - "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.18.20.tgz", - "integrity": "sha512-ceqxoedUrcayh7Y7ZX6NdbbDzGROiyVBgC4PriJThBKSVPWnnFHZAkfI1lJT8QFkOwH4qOS2SJkS4wvpGl8BpA==", - "dev": true, - "hasInstallScript": true, - "license": "MIT", - "bin": { - "esbuild": "bin/esbuild" - }, - "engines": { - "node": ">=12" - }, - "optionalDependencies": { - "@esbuild/android-arm": "0.18.20", - "@esbuild/android-arm64": "0.18.20", - "@esbuild/android-x64": "0.18.20", - "@esbuild/darwin-arm64": "0.18.20", - "@esbuild/darwin-x64": "0.18.20", - "@esbuild/freebsd-arm64": "0.18.20", - "@esbuild/freebsd-x64": "0.18.20", - "@esbuild/linux-arm": "0.18.20", - "@esbuild/linux-arm64": "0.18.20", - "@esbuild/linux-ia32": "0.18.20", - "@esbuild/linux-loong64": "0.18.20", - "@esbuild/linux-mips64el": "0.18.20", - "@esbuild/linux-ppc64": "0.18.20", - "@esbuild/linux-riscv64": "0.18.20", - "@esbuild/linux-s390x": "0.18.20", - "@esbuild/linux-x64": "0.18.20", - "@esbuild/netbsd-x64": "0.18.20", - "@esbuild/openbsd-x64": "0.18.20", - "@esbuild/sunos-x64": "0.18.20", - "@esbuild/win32-arm64": "0.18.20", - "@esbuild/win32-ia32": "0.18.20", - "@esbuild/win32-x64": "0.18.20" - } - }, - "node_modules/@esbuild-kit/esm-loader": { - "version": "2.6.5", - "resolved": "https://registry.npmjs.org/@esbuild-kit/esm-loader/-/esm-loader-2.6.5.tgz", - "integrity": "sha512-FxEMIkJKnodyA1OaCUoEvbYRkoZlLZ4d/eXFu9Fh8CbBBgP5EmZxrfTRyN0qpXZ4vOvqnE5YdRdcrmUUXuU+dA==", - "deprecated": "Merged into tsx: https://tsx.is", - "dev": true, - "license": "MIT", - "dependencies": { - "@esbuild-kit/core-utils": "^3.3.2", - "get-tsconfig": "^4.7.0" - } - }, "node_modules/@esbuild/aix-ppc64": { "version": "0.25.11", "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.25.11.tgz", @@ -3983,16 +3536,6 @@ "node": ">=10.13.0" } }, - "node_modules/@types/better-sqlite3": { - "version": "7.6.13", - "resolved": "https://registry.npmjs.org/@types/better-sqlite3/-/better-sqlite3-7.6.13.tgz", - "integrity": "sha512-NMv9ASNARoKksWtsq/SHakpYAYnhBrQgGD8zkLYk/jaK8jUGn08CfEdTRgYhMypUQAfzSP8W6gNLe0q19/t4VA==", - "devOptional": true, - "license": "MIT", - "dependencies": { - "@types/node": "*" - } - }, "node_modules/@types/chai": { "version": "5.2.3", "resolved": "https://registry.npmjs.org/@types/chai/-/chai-5.2.3.tgz", @@ -4946,29 +4489,6 @@ "baseline-browser-mapping": "dist/cli.js" } }, - "node_modules/better-sqlite3": { - "version": "12.4.1", - "resolved": "https://registry.npmjs.org/better-sqlite3/-/better-sqlite3-12.4.1.tgz", - "integrity": "sha512-3yVdyZhklTiNrtg+4WqHpJpFDd+WHTg2oM7UcR80GqL05AOV0xEJzc6qNvFYoEtE+hRp1n9MpN6/+4yhlGkDXQ==", - "hasInstallScript": true, - "license": "MIT", - "dependencies": { - "bindings": "^1.5.0", - "prebuild-install": "^7.1.1" - }, - "engines": { - "node": "20.x || 22.x || 23.x || 24.x" - } - }, - "node_modules/bindings": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz", - "integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==", - "license": "MIT", - "dependencies": { - "file-uri-to-path": "1.0.0" - } - }, "node_modules/birpc": { "version": "2.6.1", "resolved": "https://registry.npmjs.org/birpc/-/birpc-2.6.1.tgz", @@ -4978,17 +4498,6 @@ "url": "https://github.com/sponsors/antfu" } }, - "node_modules/bl": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/bl/-/bl-4.1.0.tgz", - "integrity": "sha512-1W07cM9gS6DcLperZfFSj+bWLtaPGSOHWhPiGzXmvVJbRLdG82sH/Kn8EtW1VqWVA54AKf2h5k5BbnIbwF3h6w==", - "license": "MIT", - "dependencies": { - "buffer": "^5.5.0", - "inherits": "^2.0.4", - "readable-stream": "^3.4.0" - } - }, "node_modules/boolbase": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/boolbase/-/boolbase-1.0.0.tgz", @@ -5078,30 +4587,6 @@ "node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7" } }, - "node_modules/buffer": { - "version": "5.7.1", - "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz", - "integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ], - "license": "MIT", - "dependencies": { - "base64-js": "^1.3.1", - "ieee754": "^1.1.13" - } - }, "node_modules/buffer-crc32": { "version": "0.2.13", "resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.13.tgz", @@ -5111,13 +4596,6 @@ "node": "*" } }, - "node_modules/buffer-from": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", - "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==", - "dev": true, - "license": "MIT" - }, "node_modules/bundle-name": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/bundle-name/-/bundle-name-4.1.0.tgz", @@ -5707,21 +5185,6 @@ "url": "https://github.com/sponsors/wooorm" } }, - "node_modules/decompress-response": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-6.0.0.tgz", - "integrity": "sha512-aW35yZM6Bb/4oJlZncMH2LCoZtJXTRxES17vE3hoRiowU2kWHaJKFkSBDnDR+cm9J+9QhXmREyIfv0pji9ejCQ==", - "license": "MIT", - "dependencies": { - "mimic-response": "^3.1.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/deep-eql": { "version": "5.0.2", "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-5.0.2.tgz", @@ -5732,15 +5195,6 @@ "node": ">=6" } }, - "node_modules/deep-extend": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz", - "integrity": "sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==", - "license": "MIT", - "engines": { - "node": ">=4.0.0" - } - }, "node_modules/default-browser": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/default-browser/-/default-browser-5.2.1.tgz", @@ -5825,6 +5279,7 @@ "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.1.2.tgz", "integrity": "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==", "license": "Apache-2.0", + "optional": true, "engines": { "node": ">=8" } @@ -5890,191 +5345,50 @@ "domelementtype": "^2.3.0", "domhandler": "^5.0.2", "entities": "^4.2.0" - }, - "funding": { - "url": "https://github.com/cheeriojs/dom-serializer?sponsor=1" - } - }, - "node_modules/domelementtype": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-2.3.0.tgz", - "integrity": "sha512-OLETBj6w0OsagBwdXnPdN0cnMfF9opN69co+7ZrbfPGrdpPVNBUj02spi6B1N7wChLQiPn4CSH/zJvXw56gmHw==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/fb55" - } - ], - "license": "BSD-2-Clause" - }, - "node_modules/domhandler": { - "version": "5.0.3", - "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-5.0.3.tgz", - "integrity": "sha512-cgwlv/1iFQiFnU96XXgROh8xTeetsnJiDsTc7TYCLFd9+/WNkIqPTxiM/8pSd8VIrhXGTf1Ny1q1hquVqDJB5w==", - "license": "BSD-2-Clause", - "dependencies": { - "domelementtype": "^2.3.0" - }, - "engines": { - "node": ">= 4" - }, - "funding": { - "url": "https://github.com/fb55/domhandler?sponsor=1" - } - }, - "node_modules/domutils": { - "version": "3.2.2", - "resolved": "https://registry.npmjs.org/domutils/-/domutils-3.2.2.tgz", - "integrity": "sha512-6kZKyUajlDuqlHKVX1w7gyslj9MPIXzIFiz/rGu35uC1wMi+kMhQwGhl4lt9unC9Vb9INnY9Z3/ZA3+FhASLaw==", - "license": "BSD-2-Clause", - "dependencies": { - "dom-serializer": "^2.0.0", - "domelementtype": "^2.3.0", - "domhandler": "^5.0.3" - }, - "funding": { - "url": "https://github.com/fb55/domutils?sponsor=1" - } - }, - "node_modules/drizzle-kit": { - "version": "0.31.6", - "resolved": "https://registry.npmjs.org/drizzle-kit/-/drizzle-kit-0.31.6.tgz", - "integrity": "sha512-/B4e/4pwnx25QwD5xXgdpo1S+077a2VZdosXbItE/oNmUgQwZydGDz9qJYmnQl/b+5IX0rLfwRhrPnroGtrg8Q==", - "dev": true, - "license": "MIT", - "dependencies": { - "@drizzle-team/brocli": "^0.10.2", - "@esbuild-kit/esm-loader": "^2.5.5", - "esbuild": "^0.25.4", - "esbuild-register": "^3.5.0" - }, - "bin": { - "drizzle-kit": "bin.cjs" - } - }, - "node_modules/drizzle-orm": { - "version": "0.44.7", - "resolved": "https://registry.npmjs.org/drizzle-orm/-/drizzle-orm-0.44.7.tgz", - "integrity": "sha512-quIpnYznjU9lHshEOAYLoZ9s3jweleHlZIAWR/jX9gAWNg/JhQ1wj0KGRf7/Zm+obRrYd9GjPVJg790QY9N5AQ==", - "license": "Apache-2.0", - "peerDependencies": { - "@aws-sdk/client-rds-data": ">=3", - "@cloudflare/workers-types": ">=4", - "@electric-sql/pglite": ">=0.2.0", - "@libsql/client": ">=0.10.0", - "@libsql/client-wasm": ">=0.10.0", - "@neondatabase/serverless": ">=0.10.0", - "@op-engineering/op-sqlite": ">=2", - "@opentelemetry/api": "^1.4.1", - "@planetscale/database": ">=1.13", - "@prisma/client": "*", - "@tidbcloud/serverless": "*", - "@types/better-sqlite3": "*", - "@types/pg": "*", - "@types/sql.js": "*", - "@upstash/redis": ">=1.34.7", - "@vercel/postgres": ">=0.8.0", - "@xata.io/client": "*", - "better-sqlite3": ">=7", - "bun-types": "*", - "expo-sqlite": ">=14.0.0", - "gel": ">=2", - "knex": "*", - "kysely": "*", - "mysql2": ">=2", - "pg": ">=8", - "postgres": ">=3", - "sql.js": ">=1", - "sqlite3": ">=5" - }, - "peerDependenciesMeta": { - "@aws-sdk/client-rds-data": { - "optional": true - }, - "@cloudflare/workers-types": { - "optional": true - }, - "@electric-sql/pglite": { - "optional": true - }, - "@libsql/client": { - "optional": true - }, - "@libsql/client-wasm": { - "optional": true - }, - "@neondatabase/serverless": { - "optional": true - }, - "@op-engineering/op-sqlite": { - "optional": true - }, - "@opentelemetry/api": { - "optional": true - }, - "@planetscale/database": { - "optional": true - }, - "@prisma/client": { - "optional": true - }, - "@tidbcloud/serverless": { - "optional": true - }, - "@types/better-sqlite3": { - "optional": true - }, - "@types/pg": { - "optional": true - }, - "@types/sql.js": { - "optional": true - }, - "@upstash/redis": { - "optional": true - }, - "@vercel/postgres": { - "optional": true - }, - "@xata.io/client": { - "optional": true - }, - "better-sqlite3": { - "optional": true - }, - "bun-types": { - "optional": true - }, - "expo-sqlite": { - "optional": true - }, - "gel": { - "optional": true - }, - "knex": { - "optional": true - }, - "kysely": { - "optional": true - }, - "mysql2": { - "optional": true - }, - "pg": { - "optional": true - }, - "postgres": { - "optional": true - }, - "prisma": { - "optional": true - }, - "sql.js": { - "optional": true - }, - "sqlite3": { - "optional": true + }, + "funding": { + "url": "https://github.com/cheeriojs/dom-serializer?sponsor=1" + } + }, + "node_modules/domelementtype": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-2.3.0.tgz", + "integrity": "sha512-OLETBj6w0OsagBwdXnPdN0cnMfF9opN69co+7ZrbfPGrdpPVNBUj02spi6B1N7wChLQiPn4CSH/zJvXw56gmHw==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fb55" } + ], + "license": "BSD-2-Clause" + }, + "node_modules/domhandler": { + "version": "5.0.3", + "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-5.0.3.tgz", + "integrity": "sha512-cgwlv/1iFQiFnU96XXgROh8xTeetsnJiDsTc7TYCLFd9+/WNkIqPTxiM/8pSd8VIrhXGTf1Ny1q1hquVqDJB5w==", + "license": "BSD-2-Clause", + "dependencies": { + "domelementtype": "^2.3.0" + }, + "engines": { + "node": ">= 4" + }, + "funding": { + "url": "https://github.com/fb55/domhandler?sponsor=1" + } + }, + "node_modules/domutils": { + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/domutils/-/domutils-3.2.2.tgz", + "integrity": "sha512-6kZKyUajlDuqlHKVX1w7gyslj9MPIXzIFiz/rGu35uC1wMi+kMhQwGhl4lt9unC9Vb9INnY9Z3/ZA3+FhASLaw==", + "license": "BSD-2-Clause", + "dependencies": { + "dom-serializer": "^2.0.0", + "domelementtype": "^2.3.0", + "domhandler": "^5.0.3" + }, + "funding": { + "url": "https://github.com/fb55/domutils?sponsor=1" } }, "node_modules/dset": { @@ -6278,19 +5592,6 @@ "@esbuild/win32-x64": "0.25.11" } }, - "node_modules/esbuild-register": { - "version": "3.6.0", - "resolved": "https://registry.npmjs.org/esbuild-register/-/esbuild-register-3.6.0.tgz", - "integrity": "sha512-H2/S7Pm8a9CL1uhp9OvjwrBh5Pvx0H8qVOxNu8Wed9Y7qv56MPtq+GGM8RJpq6glYJn9Wspr8uw7l55uyinNeg==", - "dev": true, - "license": "MIT", - "dependencies": { - "debug": "^4.3.4" - }, - "peerDependencies": { - "esbuild": ">=0.12 <1" - } - }, "node_modules/escalade": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.2.0.tgz", @@ -6381,15 +5682,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/expand-template": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/expand-template/-/expand-template-2.0.3.tgz", - "integrity": "sha512-XYfuKMvj4O35f/pOXLObndIRvyQ+/+6AhODh+OKWj9S9498pHHn/IMszH+gt0fBCRWMNfk1ZSp5x3AifmnI2vg==", - "license": "(MIT OR WTFPL)", - "engines": { - "node": ">=6" - } - }, "node_modules/expect-type": { "version": "1.2.2", "resolved": "https://registry.npmjs.org/expect-type/-/expect-type-1.2.2.tgz", @@ -6539,12 +5831,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/file-uri-to-path": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", - "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==", - "license": "MIT" - }, "node_modules/fill-range": { "version": "7.1.1", "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", @@ -6638,12 +5924,6 @@ "node": ">= 0.8" } }, - "node_modules/fs-constants": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz", - "integrity": "sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==", - "license": "MIT" - }, "node_modules/fs-extra": { "version": "11.3.2", "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.3.2.tgz", @@ -6793,25 +6073,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/get-tsconfig": { - "version": "4.13.0", - "resolved": "https://registry.npmjs.org/get-tsconfig/-/get-tsconfig-4.13.0.tgz", - "integrity": "sha512-1VKTZJCwBrvbd+Wn3AOgQP/2Av+TfTCOlE4AcRJE72W1ksZXbAx8PPBR9RzgTeSPzlPMHrbANMH3LbltH73wxQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "resolve-pkg-maps": "^1.0.0" - }, - "funding": { - "url": "https://github.com/privatenumber/get-tsconfig?sponsor=1" - } - }, - "node_modules/github-from-package": { - "version": "0.0.0", - "resolved": "https://registry.npmjs.org/github-from-package/-/github-from-package-0.0.0.tgz", - "integrity": "sha512-SyHy3T1v2NUXn29OsWdxmK6RwHD+vkj3v8en8AOBZ1wBQ/hCAQ5bAQTD02kW4W9tUp/3Qh6J8r9EvntiyCmOOw==", - "license": "MIT" - }, "node_modules/github-slugger": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/github-slugger/-/github-slugger-2.0.0.tgz", @@ -7196,26 +6457,6 @@ "node": ">=0.10.0" } }, - "node_modules/ieee754": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", - "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ], - "license": "BSD-3-Clause" - }, "node_modules/import-meta-resolve": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/import-meta-resolve/-/import-meta-resolve-4.2.0.tgz", @@ -7232,12 +6473,6 @@ "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", "license": "ISC" }, - "node_modules/ini": { - "version": "1.3.8", - "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.8.tgz", - "integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==", - "license": "ISC" - }, "node_modules/iron-webcrypto": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/iron-webcrypto/-/iron-webcrypto-1.2.1.tgz", @@ -8405,27 +7640,6 @@ "node": ">= 0.6" } }, - "node_modules/mimic-response": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-3.1.0.tgz", - "integrity": "sha512-z0yWI+4FDrrweS8Zmt4Ej5HdJmky15+L2e6Wgn3+iK5fWzb6T3fhNFq2+MeTRb064c6Wr4N/wv0DzQTjNzHNGQ==", - "license": "MIT", - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/minimist": { - "version": "1.2.8", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", - "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", - "license": "MIT", - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/minipass": { "version": "4.2.8", "resolved": "https://registry.npmjs.org/minipass/-/minipass-4.2.8.tgz", @@ -8484,12 +7698,6 @@ "node": ">=10" } }, - "node_modules/mkdirp-classic": { - "version": "0.5.3", - "resolved": "https://registry.npmjs.org/mkdirp-classic/-/mkdirp-classic-0.5.3.tgz", - "integrity": "sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A==", - "license": "MIT" - }, "node_modules/mlly": { "version": "1.8.0", "resolved": "https://registry.npmjs.org/mlly/-/mlly-1.8.0.tgz", @@ -8547,12 +7755,6 @@ "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" } }, - "node_modules/napi-build-utils": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/napi-build-utils/-/napi-build-utils-2.0.0.tgz", - "integrity": "sha512-GEbrYkbfF7MoNaoh2iGG84Mnf/WZfB0GdGEsM8wz7Expx/LlWf5U8t9nvJKXSp3qr5IsEbK04cBGhol/KwOsWA==", - "license": "MIT" - }, "node_modules/neotraverse": { "version": "0.6.18", "resolved": "https://registry.npmjs.org/neotraverse/-/neotraverse-0.6.18.tgz", @@ -8575,30 +7777,6 @@ "url": "https://opencollective.com/unified" } }, - "node_modules/node-abi": { - "version": "3.78.0", - "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.78.0.tgz", - "integrity": "sha512-E2wEyrgX/CqvicaQYU3Ze1PFGjc4QYPGsjUrlYkqAE0WjHEZwgOsGMPMzkMse4LjJbDmaEuDX3CM036j5K2DSQ==", - "license": "MIT", - "dependencies": { - "semver": "^7.3.5" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/node-abi/node_modules/semver": { - "version": "7.7.3", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.3.tgz", - "integrity": "sha512-SdsKMrI9TdgjdweUSR9MweHA4EJ8YxHn8DFaDisvhVlUOe4BF1tLD7GAj0lIqWVl+dPb/rExr0Btby5loQm20Q==", - "license": "ISC", - "bin": { - "semver": "bin/semver.js" - }, - "engines": { - "node": ">=10" - } - }, "node_modules/node-fetch-native": { "version": "1.6.7", "resolved": "https://registry.npmjs.org/node-fetch-native/-/node-fetch-native-1.6.7.tgz", @@ -8988,32 +8166,6 @@ "node": "^10 || ^12 || >=14" } }, - "node_modules/prebuild-install": { - "version": "7.1.3", - "resolved": "https://registry.npmjs.org/prebuild-install/-/prebuild-install-7.1.3.tgz", - "integrity": "sha512-8Mf2cbV7x1cXPUILADGI3wuhfqWvtiLA1iclTDbFRZkgRQS0NqsPZphna9V+HyTEadheuPmjaJMsbzKQFOzLug==", - "license": "MIT", - "dependencies": { - "detect-libc": "^2.0.0", - "expand-template": "^2.0.3", - "github-from-package": "0.0.0", - "minimist": "^1.2.3", - "mkdirp-classic": "^0.5.3", - "napi-build-utils": "^2.0.0", - "node-abi": "^3.3.0", - "pump": "^3.0.0", - "rc": "^1.2.7", - "simple-get": "^4.0.0", - "tar-fs": "^2.0.0", - "tunnel-agent": "^0.6.0" - }, - "bin": { - "prebuild-install": "bin.js" - }, - "engines": { - "node": ">=10" - } - }, "node_modules/pretty-ms": { "version": "9.3.0", "resolved": "https://registry.npmjs.org/pretty-ms/-/pretty-ms-9.3.0.tgz", @@ -9137,35 +8289,6 @@ "node": ">= 0.6" } }, - "node_modules/rc": { - "version": "1.2.8", - "resolved": "https://registry.npmjs.org/rc/-/rc-1.2.8.tgz", - "integrity": "sha512-y3bGgqKj3QBdxLbLkomlohkvsA8gdAiUQlSBJnBhfn+BPxg4bc62d8TcBW15wavDfgexCgccckhcZvywyQYPOw==", - "license": "(BSD-2-Clause OR MIT OR Apache-2.0)", - "dependencies": { - "deep-extend": "^0.6.0", - "ini": "~1.3.0", - "minimist": "^1.2.0", - "strip-json-comments": "~2.0.1" - }, - "bin": { - "rc": "cli.js" - } - }, - "node_modules/readable-stream": { - "version": "3.6.2", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", - "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", - "license": "MIT", - "dependencies": { - "inherits": "^2.0.3", - "string_decoder": "^1.1.1", - "util-deprecate": "^1.0.1" - }, - "engines": { - "node": ">= 6" - } - }, "node_modules/readdirp": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-4.1.2.tgz", @@ -9369,16 +8492,6 @@ "node": ">=0.10.0" } }, - "node_modules/resolve-pkg-maps": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/resolve-pkg-maps/-/resolve-pkg-maps-1.0.0.tgz", - "integrity": "sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==", - "dev": true, - "license": "MIT", - "funding": { - "url": "https://github.com/privatenumber/resolve-pkg-maps?sponsor=1" - } - }, "node_modules/restructure": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/restructure/-/restructure-3.0.2.tgz", @@ -9538,26 +8651,6 @@ "queue-microtask": "^1.2.2" } }, - "node_modules/safe-buffer": { - "version": "5.2.1", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", - "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ], - "license": "MIT" - }, "node_modules/safer-buffer": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", @@ -9740,51 +8833,6 @@ "url": "https://github.com/sponsors/isaacs" } }, - "node_modules/simple-concat": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/simple-concat/-/simple-concat-1.0.1.tgz", - "integrity": "sha512-cSFtAPtRhljv69IK0hTVZQ+OfE9nePi/rtJmw5UjHeVyVroEqJXP1sFztKUy1qU+xvz3u/sfYJLa947b7nAN2Q==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ], - "license": "MIT" - }, - "node_modules/simple-get": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/simple-get/-/simple-get-4.0.1.tgz", - "integrity": "sha512-brv7p5WgH0jmQJr1ZDDfKDOSeWWg+OVypG99A/5vYGPqJ6pxiaHLy8nxtFjBA7oMa01ebA9gfh1uMCFqOuXxvA==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ], - "license": "MIT", - "dependencies": { - "decompress-response": "^6.0.0", - "once": "^1.3.1", - "simple-concat": "^1.0.0" - } - }, "node_modules/sirv": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/sirv/-/sirv-3.0.2.tgz", @@ -9817,16 +8865,6 @@ "url": "https://github.com/sponsors/cyyynthia" } }, - "node_modules/source-map": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", - "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", - "dev": true, - "license": "BSD-3-Clause", - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/source-map-js": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.1.tgz", @@ -9836,17 +8874,6 @@ "node": ">=0.10.0" } }, - "node_modules/source-map-support": { - "version": "0.5.21", - "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.21.tgz", - "integrity": "sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==", - "dev": true, - "license": "MIT", - "dependencies": { - "buffer-from": "^1.0.0", - "source-map": "^0.6.0" - } - }, "node_modules/space-separated-tokens": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/space-separated-tokens/-/space-separated-tokens-2.0.2.tgz", @@ -9889,15 +8916,6 @@ "dev": true, "license": "MIT" }, - "node_modules/string_decoder": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", - "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", - "license": "MIT", - "dependencies": { - "safe-buffer": "~5.2.0" - } - }, "node_modules/string-width": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/string-width/-/string-width-7.2.0.tgz", @@ -9956,15 +8974,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/strip-json-comments": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", - "integrity": "sha512-4gB8na07fecVVkOI6Rs4e7T6NOTki5EmL7TUduTs6bu3EdnSycntVJ4re8kgZA+wx9IueI2Y11bfbgwtzuE0KQ==", - "license": "MIT", - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/strip-literal": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/strip-literal/-/strip-literal-3.1.0.tgz", @@ -10052,40 +9061,6 @@ "node": ">=10" } }, - "node_modules/tar-fs": { - "version": "2.1.4", - "resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-2.1.4.tgz", - "integrity": "sha512-mDAjwmZdh7LTT6pNleZ05Yt65HC3E+NiQzl672vQG38jIrehtJk/J3mNwIg+vShQPcLF/LV7CMnDW6vjj6sfYQ==", - "license": "MIT", - "dependencies": { - "chownr": "^1.1.1", - "mkdirp-classic": "^0.5.2", - "pump": "^3.0.0", - "tar-stream": "^2.1.4" - } - }, - "node_modules/tar-fs/node_modules/chownr": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/chownr/-/chownr-1.1.4.tgz", - "integrity": "sha512-jJ0bqzaylmJtVnNgzTeSOs8DPavpbYgEr/b0YL8/2GO3xJEhInFmhKMUnEJQjZumK7KXGFhUy89PrsJWlakBVg==", - "license": "ISC" - }, - "node_modules/tar-stream": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-2.2.0.tgz", - "integrity": "sha512-ujeqbceABgwMZxEJnk2HDY2DlnUZ+9oEcb1KzTVfYHio0UE6dG71n60d8D2I4qNvleWrrXpmjpt7vZeF1LnMZQ==", - "license": "MIT", - "dependencies": { - "bl": "^4.0.3", - "end-of-stream": "^1.4.1", - "fs-constants": "^1.0.0", - "inherits": "^2.0.3", - "readable-stream": "^3.1.1" - }, - "engines": { - "node": ">=6" - } - }, "node_modules/tar/node_modules/minipass": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/minipass/-/minipass-5.0.0.tgz", @@ -10242,18 +9217,6 @@ "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==", "license": "0BSD" }, - "node_modules/tunnel-agent": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", - "integrity": "sha512-McnNiV1l8RYeY8tBgEpuodCC1mLUdbSN+CYBL7kJsJNInOP8UjDDEwdk6Mw60vdLLrr5NHKZhMAOSrR2NZuQ+w==", - "license": "Apache-2.0", - "dependencies": { - "safe-buffer": "^5.0.1" - }, - "engines": { - "node": "*" - } - }, "node_modules/type-fest": { "version": "4.41.0", "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-4.41.0.tgz", @@ -10684,12 +9647,6 @@ "browserslist": ">= 4.21.0" } }, - "node_modules/util-deprecate": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", - "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==", - "license": "MIT" - }, "node_modules/vfile": { "version": "6.0.3", "resolved": "https://registry.npmjs.org/vfile/-/vfile-6.0.3.tgz", diff --git a/package.json b/package.json index 0cb0124..b16dcab 100644 --- a/package.json +++ b/package.json @@ -12,9 +12,6 @@ "test": "vitest", "test:run": "vitest run", "test:watch": "vitest --watch", - "db:generate": "drizzle-kit generate", - "db:migrate": "drizzle-kit migrate", - "db:studio": "drizzle-kit studio", "typecheck": "astro check", "lint": "echo 'Add ESLint/Prettier here'" }, @@ -27,16 +24,12 @@ "@iconify/vue": "^5.0.0", "astro": "^5.15.3", "astro-icon": "^1.1.5", - "better-sqlite3": "^12.4.1", - "drizzle-orm": "^0.44.6", "nodemailer": "^7.0.9", "typescript": "^5.9.3", "vue": "^3.5.22" }, "devDependencies": { - "@types/better-sqlite3": "^7.6.13", "@types/nodemailer": "^7.0.2", - "drizzle-kit": "^0.31.5", "vitest": "^3.2.4" } } From 78243c9e22615cd41306b2a0c04853b0743db860 Mon Sep 17 00:00:00 2001 From: Luca Knobel Date: Sun, 16 Aug 2026 16:13:04 +0000 Subject: [PATCH 6/8] refactor: remove unused DATABASE_URL and SQLite data directory creation from Dockerfile --- Dockerfile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2ab9606..98a14fa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -35,11 +35,7 @@ FROM base AS runtime ENV NODE_ENV=production \ HOST=0.0.0.0 \ - PORT=4321 \ - DATABASE_URL=/app/data/portfolio.db - -# Create the SQLite data directory and grant ownership to the non-root user. -RUN mkdir -p /app/data && chown node:node /app/data + PORT=4321 # Copy only the dependencies and build artifacts required at runtime. COPY --from=production-dependencies --chown=node:node /app/node_modules ./node_modules @@ -50,5 +46,9 @@ USER node EXPOSE 4321 +# Verify that the Astro server is responding inside the container. +HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \ + CMD node -e "fetch('http://127.0.0.1:4321/').then(r => { if (!r.ok) process.exit(1) }).catch(() => process.exit(1))" + # Start the Astro standalone Node.js server. CMD ["node", "./dist/server/entry.mjs"] \ No newline at end of file From bbcb38b9799c8811ee2194e121926ec150a3525a Mon Sep 17 00:00:00 2001 From: Luca Knobel Date: Sun, 16 Aug 2026 16:15:37 +0000 Subject: [PATCH 7/8] refactor: clean up rate limiting configuration and related files --- .gitignore | 5 ----- drizzle.config.ts | 15 --------------- src/components/ContactForm.astro | 1 - 3 files changed, 21 deletions(-) delete mode 100644 drizzle.config.ts diff --git a/.gitignore b/.gitignore index 17b1a5d..86c5f1b 100644 --- a/.gitignore +++ b/.gitignore @@ -24,11 +24,6 @@ data/ *.db-wal *.db-journal -# keep database schema and migrations -!src/db/schema.ts -!src/db/index.ts -!drizzle.config.ts -!src/db/migrations/ # macOS-specific files .DS_Store diff --git a/drizzle.config.ts b/drizzle.config.ts deleted file mode 100644 index 2dae665..0000000 --- a/drizzle.config.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { defineConfig } from "drizzle-kit"; - -export default defineConfig({ - out: "./src/db/migrations", - dialect: "sqlite", - schema: "./src/db/schema.ts", - dbCredentials: { - url: "./data/portfolio.db" - }, - verbose: true, - strict: true, -}); - - - diff --git a/src/components/ContactForm.astro b/src/components/ContactForm.astro index eca8539..fc996c1 100644 --- a/src/components/ContactForm.astro +++ b/src/components/ContactForm.astro @@ -20,7 +20,6 @@ try { rateLimitReached = !rateLimit.allowed; } catch (error) { console.error("Failed to check rate limit on page load:", error); - // If DB fails, allow form to be shown rateLimitReached = false; } From f2858f9d5ca679adf781d90516a1b0c20f815b23 Mon Sep 17 00:00:00 2001 From: Luca Knobel Date: Sun, 16 Aug 2026 16:33:55 +0000 Subject: [PATCH 8/8] refactor: enhance rate limiting logic and implement email slot reservations --- src/actions/sendMail.ts | 161 ++++++++++++++++--------------- src/components/ContactForm.astro | 12 +-- src/services/rateLimitService.ts | 106 ++++++++++++++++---- tests/rateLimitService.test.ts | 159 +++++++++++++----------------- tests/sendMail.test.ts | 102 ++++++++++++++++++++ 5 files changed, 341 insertions(+), 199 deletions(-) create mode 100644 tests/sendMail.test.ts diff --git a/src/actions/sendMail.ts b/src/actions/sendMail.ts index a622ef8..632917c 100644 --- a/src/actions/sendMail.ts +++ b/src/actions/sendMail.ts @@ -2,96 +2,103 @@ import { defineAction, ActionError } from "astro:actions"; import { z } from "astro:schema"; import { getEmailService } from "../services/emailService.js"; import { getRateLimitService } from "../services/rateLimitService.js"; +import type { + RateLimitReservation, + RateLimitService, +} from "../services/rateLimitService.js"; import type { EmailData } from "../utils/email.js"; -// Define the success result type +/** Result returned after a contact email has been sent successfully. */ type SendMailResult = { - success: true; + success: true; }; +/** Validates contact data, reserves a slot, and sends the contact email. */ export const sendMail = defineAction({ - accept: "form", - input: z.object({ - firstName: z.string().min(2).max(50).trim(), - lastName: z.string().min(2).max(60).trim(), - email: z.string().email().max(254).toLowerCase(), - subject: z.string().min(1).max(100).trim(), - message: z.string().min(1).max(3000).trim(), - privacy: z.coerce.boolean().refine(val => val === true), - company: z.string().max(100).trim().optional(), - phone: z.string().max(20).trim().optional(), - website: z.union([z.string(), z.null(), z.undefined()]) - .transform(v => (v ?? "").trim()) - .refine(v => v === "") /* Honeypot */ - }), - - handler: async (input): Promise => { - try { - const rateLimitService = getRateLimitService(); - const emailService = getEmailService(); - - // Get today's date in Swiss timezone - const today = rateLimitService.getSwissDate(); - - // 1. Check rate limit BEFORE sending email - const rateLimit = await rateLimitService.checkLimit(today); - - if (!rateLimit.allowed) { - throw new ActionError({ - code: "TOO_MANY_REQUESTS", - message: "Daily email limit reached. Please try again tomorrow." - }); - } + accept: "form", + input: z.object({ + firstName: z.string().min(2).max(50).trim(), + lastName: z.string().min(2).max(60).trim(), + email: z.string().email().max(254).toLowerCase(), + subject: z.string().min(1).max(100).trim(), + message: z.string().min(1).max(3000).trim(), + privacy: z.coerce.boolean().refine((val) => val === true), + company: z.string().max(100).trim().optional(), + phone: z.string().max(20).trim().optional(), + website: z + .union([z.string(), z.null(), z.undefined()]) + .transform((v) => (v ?? "").trim()) + .refine((v) => v === "") /* Honeypot */, + }), - // 2. Send email - const emailData: EmailData = { - firstName: input.firstName, - lastName: input.lastName, - email: input.email, - subject: input.subject, - message: input.message, - ...(input.company && { company: input.company }), - ...(input.phone && { phone: input.phone }), - }; + handler: async (input): Promise => { + let reservation: RateLimitReservation | null = null; + let rateLimitService: RateLimitService | null = null; - const result = await emailService.sendEmail(emailData); + try { + rateLimitService = getRateLimitService(); + const emailService = getEmailService(); - if (!result.success) { - console.error("Email sending failed:", result.error); - throw new ActionError({ - code: "BAD_REQUEST", - message: "Email service unavailable. Please try again later." - }); - } + // Reserve a slot before crossing the asynchronous email boundary. + reservation = rateLimitService.tryAcquire(); - console.log("Contact form processed successfully", { - messageId: result.messageId, - timestamp: new Date().toISOString(), - }); + if (reservation === null) { + throw new ActionError({ + code: "TOO_MANY_REQUESTS", + message: "Daily email limit reached. Please try again tomorrow.", + }); + } - // 3. Increment rate limit counter after successful email - await rateLimitService.incrementCount(today); + // Keep the reservation when the email succeeds; release it in catch on failure. + const emailData: EmailData = { + firstName: input.firstName, + lastName: input.lastName, + email: input.email, + subject: input.subject, + message: input.message, + ...(input.company && { company: input.company }), + ...(input.phone && { phone: input.phone }), + }; - return { - success: true, - } as const; + const result = await emailService.sendEmail(emailData); - } catch (error) { - console.error("Unexpected error during email sending:", { - error: error instanceof Error ? error.message : "Unknown error", - timestamp: new Date().toISOString(), - }); + if (!result.success) { + console.error("Email sending failed:", result.error); + throw new ActionError({ + code: "BAD_REQUEST", + message: "Email service unavailable. Please try again later.", + }); + } - /* Re-throw ActionErrors as-is */ - if (error instanceof ActionError) { - throw error; - } + console.log("Contact form processed successfully", { + messageId: result.messageId, + timestamp: new Date().toISOString(), + }); - /* Convert unexpected errors to ActionError */ - throw new ActionError({ - code: "INTERNAL_SERVER_ERROR", - message: "An unexpected error occurred. Please try again later." - }); - } + return { + success: true, + } as const; + } catch (error) { + console.error("Unexpected error during email sending:", { + error: error instanceof Error ? error.message : "Unknown error", + timestamp: new Date().toISOString(), + }); + + if (reservation !== null) { + rateLimitService?.release(reservation); + reservation = null; + } + + /* Re-throw ActionErrors as-is */ + if (error instanceof ActionError) { + throw error; + } + + /* Convert unexpected errors to ActionError */ + throw new ActionError({ + code: "INTERNAL_SERVER_ERROR", + message: "An unexpected error occurred. Please try again later.", + }); } -}); \ No newline at end of file + }, +}); diff --git a/src/components/ContactForm.astro b/src/components/ContactForm.astro index fc996c1..3669277 100644 --- a/src/components/ContactForm.astro +++ b/src/components/ContactForm.astro @@ -12,16 +12,8 @@ export interface ContactFormProps { const { lang, t } = Astro.props as ContactFormProps; const rateLimitService = getRateLimitService(); -const today = rateLimitService.getSwissDate(); -let rateLimitReached = false; - -try { - const rateLimit = await rateLimitService.checkLimit(today); - rateLimitReached = !rateLimit.allowed; -} catch (error) { - console.error("Failed to check rate limit on page load:", error); - rateLimitReached = false; -} +const rateLimit = rateLimitService.getStatus(); +const rateLimitReached = !rateLimit.allowed; const result = Astro.getActionResult(actions.sendMail); diff --git a/src/services/rateLimitService.ts b/src/services/rateLimitService.ts index 5fc9b40..624b38c 100644 --- a/src/services/rateLimitService.ts +++ b/src/services/rateLimitService.ts @@ -1,3 +1,4 @@ +/** Result of a read-only daily rate-limit status check. */ export interface RateLimitResult { allowed: boolean; currentCount: number; @@ -5,26 +6,45 @@ export interface RateLimitResult { resetDate: string; } +/** Token representing one reserved email slot. */ +export interface RateLimitReservation { + readonly date: string; +} + +/** Public operations exposed by the in-memory rate-limit service. */ export interface RateLimitService { - checkLimit(date: string): Promise; - incrementCount(date: string): Promise; + tryAcquire(): RateLimitReservation | null; + release(reservation: RateLimitReservation): void; + getStatus(): RateLimitResult; getSwissDate(): string; } -const productionCounts = new Map(); +interface RateLimitState { + date: string | null; + count: number; +} + +const productionState: RateLimitState = { + date: null, + count: 0, +}; + +const activeReservations = new WeakSet(); /** - * Rate Limiting Service - * Handles contact form submission limits per day + * Provides a process-wide limit of ten successfully sent emails per Swiss + * calendar day using synchronous in-memory reservations. */ export class ContactRateLimitService implements RateLimitService { private readonly maxDailyEmails = 10; + constructor(private readonly now: () => Date = () => new Date()) {} + /** - * Get current date in Swiss timezone (YYYY-MM-DD) + * Returns the current date in the Europe/Zurich timezone as YYYY-MM-DD. */ getSwissDate(): string { - return new Date() + return this.now() .toLocaleDateString("de-CH", { year: "numeric", month: "2-digit", @@ -36,30 +56,74 @@ export class ContactRateLimitService implements RateLimitService { .join("-"); } + private resetForCurrentDay(): string { + const date = this.getSwissDate(); + + if (productionState.date !== date) { + productionState.date = date; + productionState.count = 0; + } + + return date; + } + /** - * Check if rate limit is exceeded for given date + * Atomically reserves one daily email slot, or returns null at the limit. */ - async checkLimit(date: string): Promise { - const currentCount = productionCounts.get(date) ?? 0; + tryAcquire(): RateLimitReservation | null { + const date = this.resetForCurrentDay(); - return { - allowed: currentCount < this.maxDailyEmails, - currentCount, - maxLimit: this.maxDailyEmails, - resetDate: date, - }; + if (productionState.count >= this.maxDailyEmails) { + return null; + } + + productionState.count += 1; + const reservation = { date }; + activeReservations.add(reservation); + return reservation; + } + + /** + * Releases a previously acquired reservation on the same calendar day. + */ + release(reservation: RateLimitReservation): void { + if (!activeReservations.has(reservation)) { + return; + } + + activeReservations.delete(reservation); + this.resetForCurrentDay(); + + if ( + reservation.date === productionState.date && + productionState.count > 0 + ) { + productionState.count -= 1; + } } /** - * Increment rate limit counter for successful email + * Reads the current limit status without reserving a slot. */ - async incrementCount(date: string): Promise { - const currentCount = productionCounts.get(date) ?? 0; - productionCounts.set(date, currentCount + 1); + getStatus(): RateLimitResult { + const date = this.resetForCurrentDay(); + + return { + allowed: productionState.count < this.maxDailyEmails, + currentCount: productionState.count, + maxLimit: this.maxDailyEmails, + resetDate: date, + }; } } -// Factory function +/** Resets shared rate-limit state for isolated tests. */ +export const resetRateLimitStateForTests = (): void => { + productionState.date = null; + productionState.count = 0; +}; + +/** Creates a rate-limit service backed by shared process-level state. */ export const getRateLimitService = (): RateLimitService => { return new ContactRateLimitService(); }; diff --git a/tests/rateLimitService.test.ts b/tests/rateLimitService.test.ts index 7e36a64..1a6fdf1 100644 --- a/tests/rateLimitService.test.ts +++ b/tests/rateLimitService.test.ts @@ -1,126 +1,103 @@ import { describe, it, expect, beforeEach } from "vitest"; -import { ContactRateLimitService } from "../src/services/rateLimitService.js"; +import { + ContactRateLimitService, + resetRateLimitStateForTests, +} from "../src/services/rateLimitService.js"; describe("ContactRateLimitService", () => { let service: ContactRateLimitService; + let currentTime: Date; beforeEach(() => { - service = new ContactRateLimitService(); + resetRateLimitStateForTests(); + currentTime = new Date("2025-10-11T12:00:00+02:00"); + service = new ContactRateLimitService(() => currentTime); }); - describe("getSwissDate", () => { - it("should return date in YYYY-MM-DD format", () => { - const date = service.getSwissDate(); - expect(date).toMatch(/^\d{4}-\d{2}-\d{2}$/); - }); - - it("should return consistent date for same day", () => { - const date1 = service.getSwissDate(); - const date2 = service.getSwissDate(); - expect(date1).toBe(date2); + it("reports that a fresh limiter allows sending", () => { + expect(service.getStatus()).toMatchObject({ + allowed: true, + currentCount: 0, + maxLimit: 10, }); }); - describe("checkLimit", () => { - it("should allow requests when under limit", async () => { - const date = "2025-10-11-under"; - await service.incrementCount(date); - await service.incrementCount(date); - await service.incrementCount(date); - await service.incrementCount(date); - await service.incrementCount(date); - - const result = await service.checkLimit(date); - - expect(result.allowed).toBe(true); - expect(result.currentCount).toBe(5); - expect(result.maxLimit).toBe(10); - }); - - it("should deny requests when at limit", async () => { - const date = "2025-10-11-at"; - for (let count = 0; count < 10; count++) { - await service.incrementCount(date); - } + it("allows the first ten acquisitions and rejects the eleventh", () => { + const reservations = Array.from({ length: 10 }, () => service.tryAcquire()); - const result = await service.checkLimit(date); + expect(reservations.every(Boolean)).toBe(true); + expect(service.tryAcquire()).toBeNull(); + expect(service.getStatus().currentCount).toBe(10); + }); - expect(result.allowed).toBe(false); - expect(result.currentCount).toBe(10); - }); + it("allows exactly one of two competing acquisitions for the final slot", () => { + for (let count = 0; count < 9; count += 1) { + expect(service.tryAcquire()).not.toBeNull(); + } - it("should allow the tenth email and block the eleventh", async () => { - const date = "2025-10-11-tenth"; - for (let count = 0; count < 9; count++) { - await service.incrementCount(date); - } + const first = service.tryAcquire(); + const second = service.tryAcquire(); - const tenthEmail = await service.checkLimit(date); - await service.incrementCount(date); - const eleventhEmail = await service.checkLimit(date); + expect([first, second].filter(Boolean)).toHaveLength(1); + expect(service.getStatus().currentCount).toBe(10); + }); - expect(tenthEmail.allowed).toBe(true); - expect(tenthEmail.currentCount).toBe(9); - expect(eleventhEmail.allowed).toBe(false); - expect(eleventhEmail.currentCount).toBe(10); - }); + it("does not consume a slot when reading status", () => { + expect(service.getStatus().currentCount).toBe(0); + expect(service.getStatus().currentCount).toBe(0); + expect(service.tryAcquire()).not.toBeNull(); + expect(service.getStatus().currentCount).toBe(1); + }); - it("should deny requests when over limit", async () => { - const date = "2025-10-11-over"; - for (let count = 0; count < 15; count++) { - await service.incrementCount(date); - } + it("makes a released reservation available again", () => { + const reservation = service.tryAcquire(); - const result = await service.checkLimit(date); + expect(reservation).not.toBeNull(); + service.release(reservation!); - expect(result.allowed).toBe(false); - expect(result.currentCount).toBe(15); - }); + expect(service.getStatus().currentCount).toBe(0); + expect(service.tryAcquire()).not.toBeNull(); + }); - it("should allow when no record exists", async () => { - const result = await service.checkLimit("2025-10-11-empty"); + it("does not make the counter negative when releasing repeatedly", () => { + const reservation = service.tryAcquire(); - expect(result.allowed).toBe(true); - expect(result.currentCount).toBe(0); - }); + service.release(reservation!); + service.release(reservation!); + service.release({ date: service.getSwissDate() }); - it("should share state across service instances", async () => { - const secondService = new ContactRateLimitService(); - const date = "2025-10-11-shared"; + expect(service.getStatus().currentCount).toBe(0); + }); - await service.incrementCount(date); + it("resets the effective counter on a new Swiss calendar day", () => { + for (let count = 0; count < 10; count += 1) { + expect(service.tryAcquire()).not.toBeNull(); + } - const result = await secondService.checkLimit(date); + currentTime = new Date("2025-10-12T00:00:00+02:00"); - expect(result.currentCount).toBe(1); + expect(service.getStatus()).toMatchObject({ + allowed: true, + currentCount: 0, + resetDate: "2025-10-12", }); + }); - it("should reset the counter for a new Swiss calendar day", async () => { - const firstDate = "2025-10-11-reset"; - const secondDate = "2025-10-12-reset"; - - for (let count = 0; count < 10; count++) { - await service.incrementCount(firstDate); - } + it("does not release an old-day reservation into the new day", () => { + const reservation = service.tryAcquire(); + currentTime = new Date("2025-10-12T00:00:00+02:00"); - const result = await service.checkLimit(secondDate); + expect(service.getStatus().currentCount).toBe(0); + service.release(reservation!); - expect(result.allowed).toBe(true); - expect(result.currentCount).toBe(0); - expect(result.resetDate).toBe(secondDate); - }); + expect(service.getStatus().currentCount).toBe(0); }); - describe("incrementCount", () => { - it("should increment the in-memory counter", async () => { - const date = "2025-10-11-increment"; + it("shares the counter across service instances", () => { + const secondService = new ContactRateLimitService(() => currentTime); - await service.incrementCount(date); - await service.incrementCount(date); + expect(service.tryAcquire()).not.toBeNull(); - const result = await service.checkLimit(date); - - expect(result.currentCount).toBe(2); - }); + expect(secondService.getStatus().currentCount).toBe(1); }); }); diff --git a/tests/sendMail.test.ts b/tests/sendMail.test.ts new file mode 100644 index 0000000..6d7bbdf --- /dev/null +++ b/tests/sendMail.test.ts @@ -0,0 +1,102 @@ +import { describe, it, expect, beforeEach, vi } from "vitest"; + +vi.mock("astro:actions", () => { + class ActionError extends Error { + code: string; + + constructor({ code, message }: { code: string; message?: string }) { + super(message); + this.code = code; + } + } + + return { + ActionError, + defineAction: ({ handler }: { handler: (input: unknown) => unknown }) => { + const action = async (input: unknown) => handler(input); + action.orThrow = action; + return action; + }, + }; +}); + +vi.mock("astro:schema", async () => ({ + z: (await import("zod")).z, +})); + +import { getEmailService } from "../src/services/emailService.js"; +import { + getRateLimitService, + resetRateLimitStateForTests, +} from "../src/services/rateLimitService.js"; +import { sendMail } from "../src/actions/sendMail.js"; + +vi.mock("../src/services/emailService.js", () => ({ + getEmailService: vi.fn(), +})); + +const validInput = () => ({ + firstName: "Max", + lastName: "Mustermann", + email: "max@example.com", + subject: "Test", + message: "Hello", + privacy: true, + website: "", +}); + +describe("sendMail rate-limit reservations", () => { + beforeEach(() => { + resetRateLimitStateForTests(); + vi.clearAllMocks(); + }); + + it("keeps exactly one slot after a successful email", async () => { + vi.mocked(getEmailService).mockReturnValue({ + sendEmail: vi + .fn() + .mockResolvedValue({ success: true, messageId: "test" }), + validateConfig: vi.fn(), + }); + + await sendMail.orThrow(validInput() as unknown as FormData); + + expect(getRateLimitService().getStatus().currentCount).toBe(1); + }); + + it("releases the slot after a failed email", async () => { + vi.mocked(getEmailService).mockReturnValue({ + sendEmail: vi + .fn() + .mockResolvedValue({ success: false, error: "SMTP failed" }), + validateConfig: vi.fn(), + }); + + await expect( + sendMail.orThrow(validInput() as unknown as FormData), + ).rejects.toBeDefined(); + + expect(getRateLimitService().getStatus().currentCount).toBe(0); + }); + + it("preserves TOO_MANY_REQUESTS when all slots are reserved", async () => { + const rateLimitService = getRateLimitService(); + for (let count = 0; count < 10; count += 1) { + expect(rateLimitService.tryAcquire()).not.toBeNull(); + } + + const sendEmail = vi.fn(); + vi.mocked(getEmailService).mockReturnValue({ + sendEmail, + validateConfig: vi.fn(), + }); + + await expect( + sendMail.orThrow(validInput() as unknown as FormData), + ).rejects.toMatchObject({ + code: "TOO_MANY_REQUESTS", + }); + + expect(sendEmail).not.toHaveBeenCalled(); + }); +});