Skip to content

🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.

Enhance domain normalization and tracking validation (#376)

Bill Yang6f67f5e0f8a1
diff --git a/client/src/app/[site]/components/shared/Filters/const.tsx b/client/src/app/[site]/components/shared/Filters/const.tsx
index 376125019..7d9b89634 100644
--- a/client/src/app/[site]/components/shared/Filters/const.tsx
+++ b/client/src/app/[site]/components/shared/Filters/const.tsx
@@ -17,6 +17,7 @@ import {
Puzzle,
Radio,
Search,
+ Server,
TabletSmartphone,
Tag,
Target,
@@ -44,6 +45,11 @@ export const FilterOptions: {
value: "querystring",
icon: <Search className="h-4 w-4" />,
},
+ {
+ label: "Hostname",
+ value: "hostname",
+ icon: <Server className="h-4 w-4" />,
+ },
{
label: "Event Name",
value: "event_name",
diff --git a/client/src/app/[site]/main/components/sections/Pages.tsx b/client/src/app/[site]/main/components/sections/Pages.tsx
index bcb5e6ed5..0c17b9744 100644
--- a/client/src/app/[site]/main/components/sections/Pages.tsx
+++ b/client/src/app/[site]/main/components/sections/Pages.tsx
@@ -15,7 +15,7 @@ import { Card, CardContent } from "../../../../../components/ui/card";
import { truncateString } from "../../../../../lib/utils";
import { StandardSection } from "../../../components/shared/StandardSection/StandardSection";
-type Tab = "pages" | "page_title" | "entry_pages" | "exit_pages";
+type Tab = "pages" | "page_title" | "entry_pages" | "exit_pages" | "hostname";
const MAX_LABEL_LENGTH = 70;
@@ -41,6 +41,7 @@ export function Pages() {
<TabsTrigger value="page_title">Page Titles</TabsTrigger>
<TabsTrigger value="entry_pages">Entry Pages</TabsTrigger>
<TabsTrigger value="exit_pages">Exit Pages</TabsTrigger>
+ <TabsTrigger value="hostname">Hostnames</TabsTrigger>
</TabsList>
<Button size="smIcon" onClick={() => setExpanded(!expanded)}>
<Expand className="w-4 h-4" />
@@ -106,6 +107,17 @@ export function Pages() {
close={close}
/>
</TabsContent>
+ <TabsContent value="hostname">
+ <StandardSection
+ filterParameter="hostname"
+ title="Hostnames"
+ getValue={(e) => e.value}
+ getKey={(e) => e.value}
+ getLabel={(e) => e.value}
+ expanded={expanded}
+ close={close}
+ />
+ </TabsContent>
</Tabs>
</CardContent>
</Card>
diff --git a/client/src/app/layout.tsx b/client/src/app/layout.tsx
index e3b16e8f4..a3a79118c 100644
--- a/client/src/app/layout.tsx
+++ b/client/src/app/layout.tsx
@@ -41,11 +41,18 @@ export default function RootLayout({
</body>
</TooltipProvider>
{globalThis?.location?.hostname === "app.rybbit.io" && (
- <Script
- src="https://demo.rybbit.io/api/script.js"
- data-site-id="22"
- strategy="afterInteractive"
- />
+ <>
+ {/* <Script
+ src="https://demo.rybbit.io/api/script.js"
+ data-site-id="22"
+ strategy="afterInteractive"
+ /> */}
+ <Script
+ src="https://demo.rybbit.io/api/script.js"
+ data-site-id="21"
+ strategy="afterInteractive"
+ />
+ </>
)}
</html>
);
diff --git a/client/src/lib/store.ts b/client/src/lib/store.ts
index 9c6848651..b5e10fcab 100644
--- a/client/src/lib/store.ts
+++ b/client/src/lib/store.ts
@@ -32,6 +32,7 @@ export type FilterParameter =
| "city"
| "device_type"
| "referrer"
+ | "hostname"
| "pathname"
| "page_title"
| "querystring"
@@ -50,6 +51,7 @@ export type FilterParameter =
| "operating_system_version";
export const SESSION_PAGE_FILTERS: FilterParameter[] = [
+ "hostname",
"browser",
"operating_system",
"language",
@@ -76,7 +78,7 @@ export const EVENT_FILTERS: FilterParameter[] = [
// "country",
// "device_type",
// "referrer",
-
+ "hostname",
"browser",
"operating_system",
"language",
@@ -101,6 +103,7 @@ export const EVENT_FILTERS: FilterParameter[] = [
];
export const GOALS_PAGE_FILTERS: FilterParameter[] = [
+ "hostname",
"browser",
"operating_system",
"language",
@@ -116,6 +119,7 @@ export const GOALS_PAGE_FILTERS: FilterParameter[] = [
];
export const USER_PAGE_FILTERS: FilterParameter[] = [
+ "hostname",
"browser",
"operating_system",
"language",
diff --git a/memory-bank/progress.md b/memory-bank/progress.md
index 3da9c7b54..04294e20e 100644
--- a/memory-bank/progress.md
+++ b/memory-bank/progress.md
@@ -53,3 +53,27 @@ This file tracks the project's progress using a task list format.
- Removed duplicate sequential queries that were previously executed separately
- Now runs admin check, member check, sites query, owner query, and org info query all concurrently
- Maximum performance optimization achieved - reduced from 5 sequential to 1 concurrent operation
+
+2025-06-06 21:28:35 - Enhanced normalizeOrigin function to remove all subdomain prefixes
+
+- Modified normalizeOrigin function in server/src/utils.ts to handle all subdomains, not just "www"
+- Added support for IP addresses and localhost (returned as-is)
+- Implemented logic for multi-level TLDs (e.g., .co.uk, .com.au)
+- Function now extracts the root domain from any subdomain structure
+- Examples: api.example.com → example.com, subdomain.site.co.uk → site.co.uk
+
+2025-06-06 21:29:55 - Updated domain normalization in trackEvent.ts validateOrigin function
+
+- Imported normalizeOrigin function from utils.ts into trackEvent.ts
+- Replaced manual www. prefix removal with enhanced normalizeOrigin function
+- Now uses consistent subdomain removal logic across both origin and site domain validation
+- Ensures proper domain matching for sites with subdomains in tracking validation
+
+2025-06-06 21:33:45 - Improved normalizeOrigin function with Public Suffix List and better input handling
+
+- Added psl (Public Suffix List) dependency for reliable multi-level TLD detection
+- Removed unnecessary URL parsing when input is already a hostname
+- Function now accepts both URLs and hostnames as input
+- Uses PSL to accurately determine registrable domains (handles all TLDs correctly)
+- Added robust fallback logic for edge cases
+- Eliminates hardcoded TLD list that was incomplete and unreliable
diff --git a/server/README.md b/server/README.md
new file mode 100644
index 000000000..8d6ecdcd0
--- /dev/null
+++ b/server/README.md
@@ -0,0 +1,80 @@
+# Analytics Backend
+
+Self-hosted analytics backend using ClickHouse.
+
+## Development
+
+### Prerequisites
+
+- Node.js (v22.1.0 or higher)
+- npm
+
+### Installation
+
+```bash
+npm install
+```
+
+### Running the Application
+
+```bash
+# Development mode
+npm run dev
+
+# Production build
+npm run build
+npm start
+```
+
+### Testing
+
+```bash
+# Run tests once
+npm run test:run
+
+# Run tests in watch mode
+npm run test:watch
+
+# Run tests with coverage
+npm run test
+```
+
+### Database Operations
+
+```bash
+# Generate migrations
+npm run db:generate
+
+# Run migrations
+npm run db:migrate
+
+# Push schema changes
+npm run db:push
+
+# Pull schema from database
+npm run db:pull
+
+# Drop database
+npm run db:drop
+
+# Check migrations
+npm run db:check
+```
+
+## Testing
+
+The project uses [Vitest](https://vitest.dev/) for testing. Test files should be placed alongside source files with the `.test.ts` extension.
+
+### Current Test Coverage
+
+- `normalizeOrigin` function: Comprehensive tests covering subdomain removal, multi-level TLD handling, URL parsing, edge cases, and error handling.
+
+### Running Specific Tests
+
+```bash
+# Run a specific test file
+npx vitest src/utils.test.ts
+
+# Run tests matching a pattern
+npx vitest --grep "normalizeOrigin"
+```
diff --git a/server/package-lock.json b/server/package-lock.json
index 3a432f9b0..ef0dddf5a 100644
--- a/server/package-lock.json
+++ b/server/package-lock.json
@@ -25,6 +25,7 @@
"node-cron": "4.0.6",
"pg": "8.16.0",
"postgres": "3.4.5",
+ "psl": "^1.15.0",
"resend": "^4.5.1",
"sqlstring": "2.3.3",
"stripe": "18.1.0",
@@ -36,12 +37,14 @@
"@types/luxon": "3.6.2",
"@types/node": "20.14.8",
"@types/pg": "8.15.1",
+ "@types/psl": "^1.1.3",
"@types/sqlstring": "2.3.2",
"drizzle-kit": "0.31.1",
"terser": "^5.40.0",
"ts-node-dev": "2.0.0",
"tsx": "4.19.4",
- "typescript": "5.8.3"
+ "typescript": "5.8.3",
+ "vitest": "^3.2.2"
}
},
"node_modules/@better-auth/stripe": {
@@ -1390,6 +1393,266 @@
"react-dom": "^18.0 || ^19.0 || ^19.0.0-rc"
}
},
+ "node_modules/@rollup/rollup-android-arm-eabi": {
+ "version": "4.42.0",
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.42.0.tgz",
+ "integrity": "sha512-gldmAyS9hpj+H6LpRNlcjQWbuKUtb94lodB9uCz71Jm+7BxK1VIOo7y62tZZwxhA7j1ylv/yQz080L5WkS+LoQ==",
+ "cpu": [
+ "arm"
+ ],
+ "dev": true,
+ "optional": true,
+ "os": [
+ "android"
+ ]
+ },
+ "node_modules/@rollup/rollup-android-arm64": {
+ "version": "4.42.0",
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.42.0.tgz",
+ "integrity": "sha512-bpRipfTgmGFdCZDFLRvIkSNO1/3RGS74aWkJJTFJBH7h3MRV4UijkaEUeOMbi9wxtxYmtAbVcnMtHTPBhLEkaw==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "optional": true,
+ "os": [
+ "android"
+ ]
+ },
+ "node_modules/@rollup/rollup-darwin-arm64": {
+ "version": "4.42.0",
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.42.0.tgz",
+ "integrity": "sha512-JxHtA081izPBVCHLKnl6GEA0w3920mlJPLh89NojpU2GsBSB6ypu4erFg/Wx1qbpUbepn0jY4dVWMGZM8gplgA==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "optional": true,
+ "os": [
+ "darwin"
+ ]
+ },
+ "node_modules/@rollup/rollup-darwin-x64": {
+ "version": "4.42.0",
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.42.0.tgz",
+ "integrity": "sha512-rv5UZaWVIJTDMyQ3dCEK+m0SAn6G7H3PRc2AZmExvbDvtaDc+qXkei0knQWcI3+c9tEs7iL/4I4pTQoPbNL2SA==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "optional": true,
+ "os": [
+ "darwin"
+ ]
+ },
+ "node_modules/@rollup/rollup-freebsd-arm64": {
+ "version": "4.42.0",
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-arm64/-/rollup-freebsd-arm64-4.42.0.tgz",
+ "integrity": "sha512-fJcN4uSGPWdpVmvLuMtALUFwCHgb2XiQjuECkHT3lWLZhSQ3MBQ9pq+WoWeJq2PrNxr9rPM1Qx+IjyGj8/c6zQ==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "optional": true,
+ "os": [
+ "freebsd"
+ ]
+ },
+ "node_modules/@rollup/rollup-freebsd-x64": {
+ "version": "4.42.0",
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-x64/-/rollup-freebsd-x64-4.42.0.tgz",
+ "integrity": "sha512-CziHfyzpp8hJpCVE/ZdTizw58gr+m7Y2Xq5VOuCSrZR++th2xWAz4Nqk52MoIIrV3JHtVBhbBsJcAxs6NammOQ==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "optional": true,
+ "os": [
+ "freebsd"
+ ]
+ },
+ "node_modules/@rollup/rollup-linux-arm-gnueabihf": {
+ "version": "4.42.0",
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.42.0.tgz",
+ "integrity": "sha512-UsQD5fyLWm2Fe5CDM7VPYAo+UC7+2Px4Y+N3AcPh/LdZu23YcuGPegQly++XEVaC8XUTFVPscl5y5Cl1twEI4A==",
+ "cpu": [
+ "arm"
+ ],
+ "dev": true,
+ "optional": true,
+ "os": [
+ "linux"
+ ]
+ },
+ "node_modules/@rollup/rollup-linux-arm-musleabihf": {
+ "version": "4.42.0",
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-musleabihf/-/rollup-linux-arm-musleabihf-4.42.0.tgz",
+ "integrity": "sha512-/i8NIrlgc/+4n1lnoWl1zgH7Uo0XK5xK3EDqVTf38KvyYgCU/Rm04+o1VvvzJZnVS5/cWSd07owkzcVasgfIkQ==",
+ "cpu": [
+ "arm"
+ ],
+ "dev": true,
+ "optional": true,
+ "os": [
+ "linux"
+ ]
+ },
+ "node_modules/@rollup/rollup-linux-arm64-gnu": {
+ "version": "4.42.0",
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.42.0.tgz",
+ "integrity": "sha512-eoujJFOvoIBjZEi9hJnXAbWg+Vo1Ov8n/0IKZZcPZ7JhBzxh2A+2NFyeMZIRkY9iwBvSjloKgcvnjTbGKHE44Q==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "optional": true,
+ "os": [
+ "linux"
+ ]
+ },
+ "node_modules/@rollup/rollup-linux-arm64-musl": {
+ "version": "4.42.0",
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.42.0.tgz",
+ "integrity": "sha512-/3NrcOWFSR7RQUQIuZQChLND36aTU9IYE4j+TB40VU78S+RA0IiqHR30oSh6P1S9f9/wVOenHQnacs/Byb824g==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "optional": true,
+ "os": [
+ "linux"
+ ]
+ },
+ "node_modules/@rollup/rollup-linux-loongarch64-gnu": {
+ "version": "4.42.0",
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-loongarch64-gnu/-/rollup-linux-loongarch64-gnu-4.42.0.tgz",
+ "integrity": "sha512-O8AplvIeavK5ABmZlKBq9/STdZlnQo7Sle0LLhVA7QT+CiGpNVe197/t8Aph9bhJqbDVGCHpY2i7QyfEDDStDg==",
+ "cpu": [
+ "loong64"
+ ],
+ "dev": true,
+ "optional": true,
+ "os": [
+ "linux"
+ ]
+ },
+ "node_modules/@rollup/rollup-linux-powerpc64le-gnu": {
+ "version": "4.42.0",
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-powerpc64le-gnu/-/rollup-linux-powerpc64le-gnu-4.42.0.tgz",
+ "integrity": "sha512-6Qb66tbKVN7VyQrekhEzbHRxXXFFD8QKiFAwX5v9Xt6FiJ3BnCVBuyBxa2fkFGqxOCSGGYNejxd8ht+q5SnmtA==",
+ "cpu": [
+ "ppc64"
+ ],
+ "dev": true,
+ "optional": true,
+ "os": [
+ "linux"
+ ]
+ },
+ "node_modules/@rollup/rollup-linux-riscv64-gnu": {
+ "version": "4.42.0",
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.42.0.tgz",
+ "integrity": "sha512-KQETDSEBamQFvg/d8jajtRwLNBlGc3aKpaGiP/LvEbnmVUKlFta1vqJqTrvPtsYsfbE/DLg5CC9zyXRX3fnBiA==",
+ "cpu": [
+ "riscv64"
+ ],
+ "dev": true,
+ "optional": true,
+ "os": [
+ "linux"
+ ]
+ },
+ "node_modules/@rollup/rollup-linux-riscv64-musl": {
+ "version": "4.42.0",
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-musl/-/rollup-linux-riscv64-musl-4.42.0.tgz",
+ "integrity": "sha512-qMvnyjcU37sCo/tuC+JqeDKSuukGAd+pVlRl/oyDbkvPJ3awk6G6ua7tyum02O3lI+fio+eM5wsVd66X0jQtxw==",
+ "cpu": [
+ "riscv64"
+ ],
+ "dev": true,
+ "optional": true,
+ "os": [
+ "linux"
+ ]
+ },
+ "node_modules/@rollup/rollup-linux-s390x-gnu": {
+ "version": "4.42.0",
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-s390x-gnu/-/rollup-linux-s390x-gnu-4.42.0.tgz",
+ "integrity": "sha512-I2Y1ZUgTgU2RLddUHXTIgyrdOwljjkmcZ/VilvaEumtS3Fkuhbw4p4hgHc39Ypwvo2o7sBFNl2MquNvGCa55Iw==",
+ "cpu": [
+ "s390x"
+ ],
+ "dev": true,
+ "optional": true,
+ "os": [
+ "linux"
+ ]
+ },
+ "node_modules/@rollup/rollup-linux-x64-gnu": {
+ "version": "4.42.0",
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.42.0.tgz",
+ "integrity": "sha512-Gfm6cV6mj3hCUY8TqWa63DB8Mx3NADoFwiJrMpoZ1uESbK8FQV3LXkhfry+8bOniq9pqY1OdsjFWNsSbfjPugw==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "optional": true,
+ "os": [
+ "linux"
+ ]
+ },
+ "node_modules/@rollup/rollup-linux-x64-musl": {
+ "version": "4.42.0",
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.42.0.tgz",
+ "integrity": "sha512-g86PF8YZ9GRqkdi0VoGlcDUb4rYtQKyTD1IVtxxN4Hpe7YqLBShA7oHMKU6oKTCi3uxwW4VkIGnOaH/El8de3w==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "optional": true,
+ "os": [
+ "linux"
+ ]
+ },
+ "node_modules/@rollup/rollup-win32-arm64-msvc": {
+ "version": "4.42.0",
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.42.0.tgz",
+ "integrity": "sha512-+axkdyDGSp6hjyzQ5m1pgcvQScfHnMCcsXkx8pTgy/6qBmWVhtRVlgxjWwDp67wEXXUr0x+vD6tp5W4x6V7u1A==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "optional": true,
+ "os": [
+ "win32"
+ ]
+ },
+ "node_modules/@rollup/rollup-win32-ia32-msvc": {
+ "version": "4.42.0",
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.42.0.tgz",
+ "integrity": "sha512-F+5J9pelstXKwRSDq92J0TEBXn2nfUrQGg+HK1+Tk7VOL09e0gBqUHugZv7SW4MGrYj41oNCUe3IKCDGVlis2g==",
+ "cpu": [
+ "ia32"
+ ],
+ "dev": true,
+ "optional": true,
+ "os": [
+ "win32"
+ ]
+ },
+ "node_modules/@rollup/rollup-win32-x64-msvc": {
+ "version": "4.42.0",
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.42.0.tgz",
+ "integrity": "sha512-LpHiJRwkaVz/LqjHjK8LCi8osq7elmpwujwbXKNW88bM8eeGxavJIKKjkjpMHAh/2xfnrt1ZSnhTv41WYUHYmA==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "optional": true,
+ "os": [
+ "win32"
+ ]
+ },
"node_modules/@selderee/plugin-htmlparser2": {
"version": "0.11.0",
"resolved": "https://registry.npmjs.org/@selderee/plugin-htmlparser2/-/plugin-htmlparser2-0.11.0.tgz",
@@ -1454,6 +1717,27 @@
"dev": true,
"license": "MIT"
},
+ "node_modules/@types/chai": {
+ "version": "5.2.2",
+ "resolved": "https://registry.npmjs.org/@types/chai/-/chai-5.2.2.tgz",
+ "integrity": "sha512-8kB30R7Hwqf40JPiKhVzodJs2Qc1ZJ5zuT3uzw5Hq/dhNCl3G3l83jfpdI1e20BP348+fV7VIL/+FxaXkqBmWg==",
+ "dev": true,
+ "dependencies": {
+ "@types/deep-eql": "*"
+ }
+ },
+ "node_modules/@types/deep-eql": {
+ "version": "4.0.2",
+ "resolved": "https://registry.npmjs.org/@types/deep-eql/-/deep-eql-4.0.2.tgz",
+ "integrity": "sha512-c9h9dVVMigMPc4bwTvC5dxqtqJZwQPePsWjPlpSOnojbor6pGqdk541lfA7AqFQr5pB1BRdq0juY9db81BwyFw==",
+ "dev": true
+ },
+ "node_modules/@types/estree": {
+ "version": "1.0.8",
+ "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.8.tgz",
+ "integrity": "sha512-dWHzHa2WqEXI/O1E9OjrocMTKJl2mSrEolh1Iomrv6U+JuNwaHXsXx9bLu5gG7BUWFIN0skIQJQ/L1rIex4X6w==",
+ "dev": true
+ },
"node_modules/@types/luxon": {
"version": "3.6.2",
"resolved": "https://registry.npmjs.org/@types/luxon/-/luxon-3.6.2.tgz",
@@ -1492,6 +1776,12 @@
"pg-types": "^4.0.1"
}
},
+ "node_modules/@types/psl": {
+ "version": "1.1.3",
+ "resolved": "https://registry.npmjs.org/@types/psl/-/psl-1.1.3.tgz",
+ "integrity": "sha512-Iu174JHfLd7i/XkXY6VDrqSlPvTDQOtQI7wNAXKKOAADJ9TduRLkNdMgjGiMxSttUIZnomv81JAbAbC0DhggxA==",
+ "dev": true
+ },
"node_modules/@types/sqlstring": {
"version": "2.3.2",
"resolved": "https://registry.npmjs.org/@types/sqlstring/-/sqlstring-2.3.2.tgz",
@@ -1513,6 +1803,113 @@
"dev": true,
"license": "MIT"
},
+ "node_modules/@vitest/expect": {
+ "version": "3.2.2",
+ "resolved": "https://registry.npmjs.org/@vitest/expect/-/expect-3.2.2.tgz",
+ "integrity": "sha512-ipHw0z669vEMjzz3xQE8nJX1s0rQIb7oEl4jjl35qWTwm/KIHERIg/p/zORrjAaZKXfsv7IybcNGHwhOOAPMwQ==",
+ "dev": true,
+ "dependencies": {
+ "@types/chai": "^5.2.2",
+ "@vitest/spy": "3.2.2",
+ "@vitest/utils": "3.2.2",
+ "chai": "^5.2.0",
+ "tinyrainbow": "^2.0.0"
+ },
+ "funding": {
+ "url": "https://opencollective.com/vitest"
+ }
+ },
+ "node_modules/@vitest/mocker": {
+ "version": "3.2.2",
+ "resolved": "https://registry.npmjs.org/@vitest/mocker/-/mocker-3.2.2.tgz",
+ "integrity": "sha512-jKojcaRyIYpDEf+s7/dD3LJt53c0dPfp5zCPXz9H/kcGrSlovU/t1yEaNzM9oFME3dcd4ULwRI/x0Po1Zf+LTw==",
+ "dev": true,
+ "dependencies": {
+ "@vitest/spy": "3.2.2",
+ "estree-walker": "^3.0.3",
+ "magic-string": "^0.30.17"
+ },
+ "funding": {
+ "url": "https://opencollective.com/vitest"
+ },
+ "peerDependencies": {
+ "msw": "^2.4.9",
+ "vite": "^5.0.0 || ^6.0.0 || ^7.0.0-0"
+ },
+ "peerDependenciesMeta": {
+ "msw": {
+ "optional": true
+ },
+ "vite": {
+ "optional": true
+ }
+ }
+ },
+ "node_modules/@vitest/pretty-format": {
+ "version": "3.2.2",
+ "resolved": "https://registry.npmjs.org/@vitest/pretty-format/-/pretty-format-3.2.2.tgz",
+ "integrity": "sha512-FY4o4U1UDhO9KMd2Wee5vumwcaHw7Vg4V7yR4Oq6uK34nhEJOmdRYrk3ClburPRUA09lXD/oXWZ8y/Sdma0aUQ==",
+ "dev": true,
+ "dependencies": {
+ "tinyrainbow": "^2.0.0"
+ },
+ "funding": {
+ "url": "https://opencollective.com/vitest"
+ }
+ },
+ "node_modules/@vitest/runner": {
+ "version": "3.2.2",
+ "resolved": "https://registry.npmjs.org/@vitest/runner/-/runner-3.2.2.tgz",
+ "integrity": "sha512-GYcHcaS3ejGRZYed2GAkvsjBeXIEerDKdX3orQrBJqLRiea4NSS9qvn9Nxmuy1IwIB+EjFOaxXnX79l8HFaBwg==",
+ "dev": true,
+ "dependencies": {
+ "@vitest/utils": "3.2.2",
+ "pathe": "^2.0.3"
+ },
+ "funding": {
+ "url": "https://opencollective.com/vitest"
+ }
+ },
+ "node_modules/@vitest/snapshot": {
+ "version": "3.2.2",
+ "resolved": "https://registry.npmjs.org/@vitest/snapshot/-/snapshot-3.2.2.tgz",
+ "integrity": "sha512-aMEI2XFlR1aNECbBs5C5IZopfi5Lb8QJZGGpzS8ZUHML5La5wCbrbhLOVSME68qwpT05ROEEOAZPRXFpxZV2wA==",
+ "dev": true,
+ "dependencies": {
+ "@vitest/pretty-format": "3.2.2",
+ "magic-string": "^0.30.17",
+ "pathe": "^2.0.3"
+ },
+ "funding": {
+ "url": "https://opencollective.com/vitest"
+ }
+ },
+ "node_modules/@vitest/spy": {
+ "version": "3.2.2",
+ "resolved": "https://registry.npmjs.org/@vitest/spy/-/spy-3.2.2.tgz",
+ "integrity": "sha512-6Utxlx3o7pcTxvp0u8kUiXtRFScMrUg28KjB3R2hon7w4YqOFAEA9QwzPVVS1QNL3smo4xRNOpNZClRVfpMcYg==",
+ "dev": true,
+ "dependencies": {
+ "tinyspy": "^4.0.3"
+ },
+ "funding": {
+ "url": "https://opencollective.com/vitest"
+ }
+ },
+ "node_modules/@vitest/utils": {
+ "version": "3.2.2",
+ "resolved": "https://registry.npmjs.org/@vitest/utils/-/utils-3.2.2.tgz",
+ "integrity": "sha512-qJYMllrWpF/OYfWHP32T31QCaLa3BAzT/n/8mNGhPdVcjY+JYazQFO1nsJvXU12Kp1xMpNY4AGuljPTNjQve6A==",
+ "dev": true,
+ "dependencies": {
+ "@vitest/pretty-format": "3.2.2",
+ "loupe": "^3.1.3",
+ "tinyrainbow": "^2.0.0"
+ },
+ "funding": {
+ "url": "https://opencollective.com/vitest"
+ }
+ },
"node_modules/abstract-logging": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/abstract-logging/-/abstract-logging-2.0.1.tgz",
@@ -1637,6 +2034,15 @@
"node": ">=12.0.0"
}
},
+ "node_modules/assertion-error": {
+ "version": "2.0.1",
+ "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-2.0.1.tgz",
+ "integrity": "sha512-Izi8RQcffqCeNVgFigKli1ssklIbpHnCYc6AknXGYoB6grJqyeby7jv12JUQgmTAnIDnbck1uxksT4dzN3PWBA==",
+ "dev": true,
+ "engines": {
+ "node": ">=12"
+ }
+ },
"node_modules/asynckit": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
@@ -1740,6 +2146,15 @@
"dev": true,
"license": "MIT"
},
+ "node_modules/cac": {
+ "version": "6.7.14",
+ "resolved": "https://registry.npmjs.org/cac/-/cac-6.7.14.tgz",
+ "integrity": "sha512-b6Ilus+c3RrdDk+JhLKUAQfzzgLEPy6wcXqS7f/xe1EETvsDP6GORG7SFuOs6cID5YkqchW/LXZbX5bc8j7ZcQ==",
+ "dev": true,
+ "engines": {
+ "node": ">=8"
+ }
+ },
"node_modules/call-bind-apply-helpers": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz",
@@ -1769,6 +2184,31 @@
"url": "https://github.com/sponsors/ljharb"
}
},
+ "node_modules/chai": {
+ "version": "5.2.0",
+ "resolved": "https://registry.npmjs.org/chai/-/chai-5.2.0.tgz",
+ "integrity": "sha512-mCuXncKXk5iCLhfhwTc0izo0gtEmpz5CtG2y8GiOINBlMVS6v8TMRc5TaLWKS6692m9+dVVfzgeVxR5UxWHTYw==",
+ "dev": true,
+ "dependencies": {
+ "assertion-error": "^2.0.1",
+ "check-error": "^2.1.1",
+ "deep-eql": "^5.0.1",
+ "loupe": "^3.1.0",
+ "pathval": "^2.0.0"
+ },
+ "engines": {
+ "node": ">=12"
+ }
+ },
+ "node_modules/check-error": {
+ "version": "2.1.1",
+ "resolved": "https://registry.npmjs.org/check-error/-/check-error-2.1.1.tgz",
+ "integrity": "sha512-OAlb+T7V4Op9OwdkjmguYRqncdlx5JiofwOAUkmTF+jNdHwzTaTs4sRAGpzLF3oOz5xAyDGrPgeIDFQmDOTiJw==",
+ "dev": true,
+ "engines": {
+ "node": ">= 16"
+ }
+ },
"node_modules/chokidar": {
"version": "3.6.0",
"resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.6.0.tgz",
@@ -1921,6 +2361,15 @@
}
}
},
+ "node_modules/deep-eql": {
+ "version": "5.0.2",
+ "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-5.0.2.tgz",
+ "integrity": "sha512-h5k/5U50IJJFpzfL6nO9jaaumfjO/f2NjK/oYB2Djzm4p9L+3T9qWpZqZ2hAbLPuuYq9wrU08WQyBTL5GbPk5Q==",
+ "dev": true,
+ "engines": {
+ "node": ">=6"
+ }
+ },
"node_modules/deepmerge": {
"version": "4.3.1",
"resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-4.3.1.tgz",
@@ -2266,6 +2715,12 @@
"node": ">= 0.4"
}
},
+ "node_modules/es-module-lexer": {
+ "version": "1.7.0",
+ "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-1.7.0.tgz",
+ "integrity": "sha512-jEQoCwk8hyb2AZziIOLhDqpm5+2ww5uIE6lkO/6jcOCusfk6LhMHpXXfBLXTZ7Ydyt0j4VoUQv6uGNYbdW+kBA==",
+ "dev": true
+ },
"node_modules/es-object-atoms": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz",
@@ -2353,6 +2808,24 @@
"integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==",
"license": "MIT"
},
+ "node_modules/estree-walker": {
+ "version": "3.0.3",
+ "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-3.0.3.tgz",
+ "integrity": "sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==",
+ "dev": true,
+ "dependencies": {
+ "@types/estree": "^1.0.0"
+ }
+ },
+ "node_modules/expect-type": {
+ "version": "1.2.1",
+ "resolved": "https://registry.npmjs.org/expect-type/-/expect-type-1.2.1.tgz",
+ "integrity": "sha512-/kP8CAwxzLVEeFrMm4kMmy4CCDlpipyA7MYLVrdJIkV0fYF0UaigQHRsxHiuY/GEea+bh4KSv3TIlgr+2UL6bw==",
+ "dev": true,
+ "engines": {
+ "node": ">=12.0.0"
+ }
+ },
"node_modules/fast-copy": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/fast-copy/-/fast-copy-3.0.2.tgz",
@@ -3024,6 +3497,12 @@
],
"license": "MIT"
},
+ "node_modules/loupe": {
+ "version": "3.1.3",
+ "resolved": "https://registry.npmjs.org/loupe/-/loupe-3.1.3.tgz",
+ "integrity": "sha512-kkIp7XSkP78ZxJEsSxW3712C6teJVoeHHwgo9zJ380de7IYyJ2ISlxojcH2pC5OFLewESmnRi/+XCDIEEVyoug==",
+ "dev": true
+ },
"node_modules/lru-cache": {
"version": "11.1.0",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-11.1.0.tgz",
@@ -3042,6 +3521,15 @@
"node": ">=12"
}
},
+ "node_modules/magic-string": {
+ "version": "0.30.17",
+ "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.17.tgz",
+ "integrity": "sha512-sNPKHvyjVf7gyjwS4xGTaW/mCnF8wnjtifKBEhxfZ7E/S8tQ0rssrwGNn6q8JH/ohItJfSQp9mBtQYuTlH5QnA==",
+ "dev": true,
+ "dependencies": {
+ "@jridgewell/sourcemap-codec": "^1.5.0"
+ }
+ },
"node_modules/make-error": {
"version": "1.3.6",
"resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz",
@@ -3168,6 +3656,24 @@
"dev": true,
"license": "MIT"
},
+ "node_modules/nanoid": {
+ "version": "3.3.11",
+ "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.11.tgz",
+ "integrity": "sha512-N8SpfPUnUp1bK+PMYW8qSWdl9U+wwNWI4QKxOYDy9JAro3WMX7p2OeVRF9v+347pnakNevPmiHhNmZ2HbFA76w==",
+ "dev": true,
+ "funding": [
+ {
+ "type": "github",
+ "url": "https://github.com/sponsors/ai"
+ }
+ ],
+ "bin": {
+ "nanoid": "bin/nanoid.cjs"
+ },
+ "engines": {
+ "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1"
+ }
+ },
"node_modules/nanostores": {
"version": "0.11.4",
"resolved": "https://registry.npmjs.org/nanostores/-/nanostores-0.11.4.tgz",
@@ -3329,6 +3835,21 @@
"url": "https://github.com/sponsors/isaacs"
}
},
+ "node_modules/pathe": {
+ "version": "2.0.3",
+ "resolved": "https://registry.npmjs.org/pathe/-/pathe-2.0.3.tgz",
+ "integrity": "sha512-WUjGcAqP1gQacoQe+OBJsFA7Ld4DyXuUIjZ5cc75cLHvJ7dtNsTugphxIADwspS+AraAUePCKrSVtPLFj/F88w==",
+ "dev": true
+ },
+ "node_modules/pathval": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/pathval/-/pathval-2.0.0.tgz",
+ "integrity": "sha512-vE7JKRyES09KiunauX7nd2Q9/L7lhok4smP9RZTDeD4MVs72Dp2qNFVz39Nz5a0FVEW0BJR6C0DYrq6unoziZA==",
+ "dev": true,
+ "engines": {
+ "node": ">= 14.16"
+ }
+ },
"node_modules/peberminta": {
"version": "0.9.0",
"resolved": "https://registry.npmjs.org/peberminta/-/peberminta-0.9.0.tgz",
@@ -3494,6 +4015,12 @@
"split2": "^4.1.0"
}
},
+ "node_modules/picocolors": {
+ "version": "1.1.1",
+ "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz",
+ "integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==",
+ "dev": true
+ },
"node_modules/picomatch": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz",
@@ -3590,6 +4117,34 @@
],
"license": "MIT"
},
+ "node_modules/postcss": {
+ "version": "8.5.4",
+ "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.4.tgz",
+ "integrity": "sha512-QSa9EBe+uwlGTFmHsPKokv3B/oEMQZxfqW0QqNCyhpa6mB1afzulwn8hihglqAb2pOw+BJgNlmXQ8la2VeHB7w==",
+ "dev": true,
+ "funding": [
+ {
+ "type": "opencollective",
+ "url": "https://opencollective.com/postcss/"
+ },
+ {
+ "type": "tidelift",
+ "url": "https://tidelift.com/funding/github/npm/postcss"
+ },
+ {
+ "type": "github",
+ "url": "https://github.com/sponsors/ai"
+ }
+ ],
+ "dependencies": {
+ "nanoid": "^3.3.11",
+ "picocolors": "^1.1.1",
+ "source-map-js": "^1.2.1"
+ },
+ "engines": {
+ "node": "^10 || ^12 || >=14"
+ }
+ },
"node_modules/postgres": {
"version": "3.4.5",
"resolved": "https://registry.npmjs.org/postgres/-/postgres-3.4.5.tgz",
@@ -3683,6 +4238,17 @@
],
"license": "MIT"
},
+ "node_modules/psl": {
+ "version": "1.15.0",
+ "resolved": "https://registry.npmjs.org/psl/-/psl-1.15.0.tgz",
+ "integrity": "sha512-JZd3gMVBAVQkSs6HdNZo9Sdo0LNcQeMNP3CozBJb3JYC/QUYZTnKxP+f8oWRX4rHP5EurWxqAHTSwUCjlNKa1w==",
+ "dependencies": {
+ "punycode": "^2.3.1"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/lupomontero"
+ }
+ },
"node_modules/pump": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/pump/-/pump-3.0.2.tgz",
@@ -3693,6 +4259,14 @@
"once": "^1.3.1"
}
},
+ "node_modules/punycode": {
+ "version": "2.3.1",
+ "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz",
+ "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==",
+ "engines": {
+ "node": ">=6"
+ }
+ },
"node_modules/pvtsutils": {
"version": "1.3.6",
"resolved": "https://registry.npmjs.org/pvtsutils/-/pvtsutils-1.3.6.tgz",
@@ -3924,6 +4498,51 @@
"node": "*"
}
},
+ "node_modules/rollup": {
+ "version": "4.42.0",
+ "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.42.0.tgz",
+ "integrity": "sha512-LW+Vse3BJPyGJGAJt1j8pWDKPd73QM8cRXYK1IxOBgL2AGLu7Xd2YOW0M2sLUBCkF5MshXXtMApyEAEzMVMsnw==",
+ "dev": true,
+ "dependencies": {
+ "@types/estree": "1.0.7"
+ },
+ "bin": {
+ "rollup": "dist/bin/rollup"
+ },
+ "engines": {
+ "node": ">=18.0.0",
+ "npm": ">=8.0.0"
+ },
+ "optionalDependencies": {
+ "@rollup/rollup-android-arm-eabi": "4.42.0",
+ "@rollup/rollup-android-arm64": "4.42.0",
+ "@rollup/rollup-darwin-arm64": "4.42.0",
+ "@rollup/rollup-darwin-x64": "4.42.0",
+ "@rollup/rollup-freebsd-arm64": "4.42.0",
+ "@rollup/rollup-freebsd-x64": "4.42.0",
+ "@rollup/rollup-linux-arm-gnueabihf": "4.42.0",
+ "@rollup/rollup-linux-arm-musleabihf": "4.42.0",
+ "@rollup/rollup-linux-arm64-gnu": "4.42.0",
+ "@rollup/rollup-linux-arm64-musl": "4.42.0",
+ "@rollup/rollup-linux-loongarch64-gnu": "4.42.0",
+ "@rollup/rollup-linux-powerpc64le-gnu": "4.42.0",
+ "@rollup/rollup-linux-riscv64-gnu": "4.42.0",
+ "@rollup/rollup-linux-riscv64-musl": "4.42.0",
+ "@rollup/rollup-linux-s390x-gnu": "4.42.0",
+ "@rollup/rollup-linux-x64-gnu": "4.42.0",
+ "@rollup/rollup-linux-x64-musl": "4.42.0",
+ "@rollup/rollup-win32-arm64-msvc": "4.42.0",
+ "@rollup/rollup-win32-ia32-msvc": "4.42.0",
+ "@rollup/rollup-win32-x64-msvc": "4.42.0",
+ "fsevents": "~2.3.2"
+ }
+ },
+ "node_modules/rollup/node_modules/@types/estree": {
+ "version": "1.0.7",
+ "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.7.tgz",
+ "integrity": "sha512-w28IoSUCJpidD/TGviZwwMJckNESJZXFu7NBZ5YJ4mEUnNraUn9Pm8HSZm/jDF1pDWYKspWE7oVphigUPRakIQ==",
+ "dev": true
+ },
"node_modules/rou3": {
"version": "0.5.1",
"resolved": "https://registry.npmjs.org/rou3/-/rou3-0.5.1.tgz",
@@ -4128,6 +4747,12 @@
"url": "https://github.com/sponsors/ljharb"
}
},
+ "node_modules/siginfo": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/siginfo/-/siginfo-2.0.0.tgz",
+ "integrity": "sha512-ybx0WO1/8bSBLEWXZvEd7gMW3Sn3JFlW3TvX1nREbDLRNQNaeNN8WK0meBwPdAaOI7TtRRRJn/Es1zhrrCHu7g==",
+ "dev": true
+ },
"node_modules/signal-exit": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.1.0.tgz",
@@ -4159,6 +4784,15 @@
"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",
+ "integrity": "sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==",
+ "dev": true,
+ "engines": {
+ "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",
@@ -4188,6 +4822,12 @@
"node": ">= 0.6"
}
},
+ "node_modules/stackback": {
+ "version": "0.0.2",
+ "resolved": "https://registry.npmjs.org/stackback/-/stackback-0.0.2.tgz",
+ "integrity": "sha512-1XMJE5fQo1jGH6Y/7ebnwPOBEkIEnT4QF32d5R1+VXdXveM0IBMJt8zfaxX1P3QhVwrYe+576+jkANtSS2mBbw==",
+ "dev": true
+ },
"node_modules/statuses": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz",
@@ -4197,6 +4837,12 @@
"node": ">= 0.8"
}
},
+ "node_modules/std-env": {
+ "version": "3.9.0",
+ "resolved": "https://registry.npmjs.org/std-env/-/std-env-3.9.0.tgz",
+ "integrity": "sha512-UGvjygr6F6tpH7o2qyqR6QYpwraIjKSdtzyBdyytFOHmPZY917kwdwLG0RbOjWOnKmnm3PeHjaoLLMie7kPLQw==",
+ "dev": true
+ },
"node_modules/string-width": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-5.1.2.tgz",
@@ -4385,6 +5031,87 @@
"node": ">=12"
}
},
+ "node_modules/tinybench": {
+ "version": "2.9.0",
+ "resolved": "https://registry.npmjs.org/tinybench/-/tinybench-2.9.0.tgz",
+ "integrity": "sha512-0+DUvqWMValLmha6lr4kD8iAMK1HzV0/aKnCtWb9v9641TnP/MFb7Pc2bxoxQjTXAErryXVgUOfv2YqNllqGeg==",
+ "dev": true
+ },
+ "node_modules/tinyexec": {
+ "version": "0.3.2",
+ "resolved": "https://registry.npmjs.org/tinyexec/-/tinyexec-0.3.2.tgz",
+ "integrity": "sha512-KQQR9yN7R5+OSwaK0XQoj22pwHoTlgYqmUscPYoknOoWCWfj/5/ABTMRi69FrKU5ffPVh5QcFikpWJI/P1ocHA==",
+ "dev": true
+ },
+ "node_modules/tinyglobby": {
+ "version": "0.2.14",
+ "resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.14.tgz",
+ "integrity": "sha512-tX5e7OM1HnYr2+a2C/4V0htOcSQcoSTH9KgJnVvNm5zm/cyEWKJ7j7YutsH9CxMdtOkkLFy2AHrMci9IM8IPZQ==",
+ "dev": true,
+ "dependencies": {
+ "fdir": "^6.4.4",
+ "picomatch": "^4.0.2"
+ },
+ "engines": {
+ "node": ">=12.0.0"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/SuperchupuDev"
+ }
+ },
+ "node_modules/tinyglobby/node_modules/fdir": {
+ "version": "6.4.5",
+ "resolved": "https://registry.npmjs.org/fdir/-/fdir-6.4.5.tgz",
+ "integrity": "sha512-4BG7puHpVsIYxZUbiUE3RqGloLaSSwzYie5jvasC4LWuBWzZawynvYouhjbQKw2JuIGYdm0DzIxl8iVidKlUEw==",
+ "dev": true,
+ "peerDependencies": {
+ "picomatch": "^3 || ^4"
+ },
+ "peerDependenciesMeta": {
+ "picomatch": {
+ "optional": true
+ }
+ }
+ },
+ "node_modules/tinyglobby/node_modules/picomatch": {
+ "version": "4.0.2",
+ "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.2.tgz",
+ "integrity": "sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==",
+ "dev": true,
+ "engines": {
+ "node": ">=12"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/jonschlinkert"
+ }
+ },
+ "node_modules/tinypool": {
+ "version": "1.1.0",
+ "resolved": "https://registry.npmjs.org/tinypool/-/tinypool-1.1.0.tgz",
+ "integrity": "sha512-7CotroY9a8DKsKprEy/a14aCCm8jYVmR7aFy4fpkZM8sdpNJbKkixuNjgM50yCmip2ezc8z4N7k3oe2+rfRJCQ==",
+ "dev": true,
+ "engines": {
+ "node": "^18.0.0 || >=20.0.0"
+ }
+ },
+ "node_modules/tinyrainbow": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/tinyrainbow/-/tinyrainbow-2.0.0.tgz",
+ "integrity": "sha512-op4nsTR47R6p0vMUUoYl/a+ljLFVtlfaXkLQmqfLR1qHma1h/ysYk4hEXZ880bf2CYgTskvTa/e196Vd5dDQXw==",
+ "dev": true,
+ "engines": {
+ "node": ">=14.0.0"
+ }
+ },
+ "node_modules/tinyspy": {
+ "version": "4.0.3",
+ "resolved": "https://registry.npmjs.org/tinyspy/-/tinyspy-4.0.3.tgz",
+ "integrity": "sha512-t2T/WLB2WRgZ9EpE4jgPJ9w+i66UZfDc8wHh0xrwiRNN+UwH98GIJkTeZqX9rg0i0ptwzqW+uYeIF0T4F8LR7A==",
+ "dev": true,
+ "engines": {
+ "node": ">=14.0.0"
+ }
+ },
"node_modules/to-regex-range": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz",
@@ -4654,6 +5381,212 @@
"dev": true,
"license": "MIT"
},
+ "node_modules/vite": {
+ "version": "6.3.5",
+ "resolved": "https://registry.npmjs.org/vite/-/vite-6.3.5.tgz",
+ "integrity": "sha512-cZn6NDFE7wdTpINgs++ZJ4N49W2vRp8LCKrn3Ob1kYNtOo21vfDoaV5GzBfLU4MovSAB8uNRm4jgzVQZ+mBzPQ==",
+ "dev": true,
+ "dependencies": {
+ "esbuild": "^0.25.0",
+ "fdir": "^6.4.4",
+ "picomatch": "^4.0.2",
+ "postcss": "^8.5.3",
+ "rollup": "^4.34.9",
+ "tinyglobby": "^0.2.13"
+ },
+ "bin": {
+ "vite": "bin/vite.js"
+ },
+ "engines": {
+ "node": "^18.0.0 || ^20.0.0 || >=22.0.0"
+ },
+ "funding": {
+ "url": "https://github.com/vitejs/vite?sponsor=1"
+ },
+ "optionalDependencies": {
+ "fsevents": "~2.3.3"
+ },
+ "peerDependencies": {
+ "@types/node": "^18.0.0 || ^20.0.0 || >=22.0.0",
+ "jiti": ">=1.21.0",
+ "less": "*",
+ "lightningcss": "^1.21.0",
+ "sass": "*",
+ "sass-embedded": "*",
+ "stylus": "*",
+ "sugarss": "*",
+ "terser": "^5.16.0",
+ "tsx": "^4.8.1",
+ "yaml": "^2.4.2"
+ },
+ "peerDependenciesMeta": {
+ "@types/node": {
+ "optional": true
+ },
+ "jiti": {
+ "optional": true
+ },
+ "less": {
+ "optional": true
+ },
+ "lightningcss": {
+ "optional": true
+ },
+ "sass": {
+ "optional": true
+ },
+ "sass-embedded": {
+ "optional": true
+ },
+ "stylus": {
+ "optional": true
+ },
+ "sugarss": {
+ "optional": true
+ },
+ "terser": {
+ "optional": true
+ },
+ "tsx": {
+ "optional": true
+ },
+ "yaml": {
+ "optional": true
+ }
+ }
+ },
+ "node_modules/vite-node": {
+ "version": "3.2.2",
+ "resolved": "https://registry.npmjs.org/vite-node/-/vite-node-3.2.2.tgz",
+ "integrity": "sha512-Xj/jovjZvDXOq2FgLXu8NsY4uHUMWtzVmMC2LkCu9HWdr9Qu1Is5sanX3Z4jOFKdohfaWDnEJWp9pRP0vVpAcA==",
+ "dev": true,
+ "dependencies": {
+ "cac": "^6.7.14",
+ "debug": "^4.4.1",
+ "es-module-lexer": "^1.7.0",
+ "pathe": "^2.0.3",
+ "vite": "^5.0.0 || ^6.0.0 || ^7.0.0-0"
+ },
+ "bin": {
+ "vite-node": "vite-node.mjs"
+ },
+ "engines": {
+ "node": "^18.0.0 || ^20.0.0 || >=22.0.0"
+ },
+ "funding": {
+ "url": "https://opencollective.com/vitest"
+ }
+ },
+ "node_modules/vite/node_modules/fdir": {
+ "version": "6.4.5",
+ "resolved": "https://registry.npmjs.org/fdir/-/fdir-6.4.5.tgz",
+ "integrity": "sha512-4BG7puHpVsIYxZUbiUE3RqGloLaSSwzYie5jvasC4LWuBWzZawynvYouhjbQKw2JuIGYdm0DzIxl8iVidKlUEw==",
+ "dev": true,
+ "peerDependencies": {
+ "picomatch": "^3 || ^4"
+ },
+ "peerDependenciesMeta": {
+ "picomatch": {
+ "optional": true
+ }
+ }
+ },
+ "node_modules/vite/node_modules/picomatch": {
+ "version": "4.0.2",
+ "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.2.tgz",
+ "integrity": "sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==",
+ "dev": true,
+ "engines": {
+ "node": ">=12"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/jonschlinkert"
+ }
+ },
+ "node_modules/vitest": {
+ "version": "3.2.2",
+ "resolved": "https://registry.npmjs.org/vitest/-/vitest-3.2.2.tgz",
+ "integrity": "sha512-fyNn/Rp016Bt5qvY0OQvIUCwW2vnaEBLxP42PmKbNIoasSYjML+8xyeADOPvBe+Xfl/ubIw4og7Lt9jflRsCNw==",
+ "dev": true,
+ "dependencies": {
+ "@types/chai": "^5.2.2",
+ "@vitest/expect": "3.2.2",
+ "@vitest/mocker": "3.2.2",
+ "@vitest/pretty-format": "^3.2.2",
+ "@vitest/runner": "3.2.2",
+ "@vitest/snapshot": "3.2.2",
+ "@vitest/spy": "3.2.2",
+ "@vitest/utils": "3.2.2",
+ "chai": "^5.2.0",
+ "debug": "^4.4.1",
+ "expect-type": "^1.2.1",
+ "magic-string": "^0.30.17",
+ "pathe": "^2.0.3",
+ "picomatch": "^4.0.2",
+ "std-env": "^3.9.0",
+ "tinybench": "^2.9.0",
+ "tinyexec": "^0.3.2",
+ "tinyglobby": "^0.2.14",
+ "tinypool": "^1.1.0",
+ "tinyrainbow": "^2.0.0",
+ "vite": "^5.0.0 || ^6.0.0 || ^7.0.0-0",
+ "vite-node": "3.2.2",
+ "why-is-node-running": "^2.3.0"
+ },
+ "bin": {
+ "vitest": "vitest.mjs"
+ },
+ "engines": {
+ "node": "^18.0.0 || ^20.0.0 || >=22.0.0"
+ },
+ "funding": {
+ "url": "https://opencollective.com/vitest"
+ },
+ "peerDependencies": {
+ "@edge-runtime/vm": "*",
+ "@types/debug": "^4.1.12",
+ "@types/node": "^18.0.0 || ^20.0.0 || >=22.0.0",
+ "@vitest/browser": "3.2.2",
+ "@vitest/ui": "3.2.2",
+ "happy-dom": "*",
+ "jsdom": "*"
+ },
+ "peerDependenciesMeta": {
+ "@edge-runtime/vm": {
+ "optional": true
+ },
+ "@types/debug": {
+ "optional": true
+ },
+ "@types/node": {
+ "optional": true
+ },
+ "@vitest/browser": {
+ "optional": true
+ },
+ "@vitest/ui": {
+ "optional": true
+ },
+ "happy-dom": {
+ "optional": true
+ },
+ "jsdom": {
+ "optional": true
+ }
+ }
+ },
+ "node_modules/vitest/node_modules/picomatch": {
+ "version": "4.0.2",
+ "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.2.tgz",
+ "integrity": "sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==",
+ "dev": true,
+ "engines": {
+ "node": ">=12"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/jonschlinkert"
+ }
+ },
"node_modules/webidl-conversions": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
@@ -4685,6 +5618,22 @@
"node": ">= 8"
}
},
+ "node_modules/why-is-node-running": {
+ "version": "2.3.0",
+ "resolved": "https://registry.npmjs.org/why-is-node-running/-/why-is-node-running-2.3.0.tgz",
+ "integrity": "sha512-hUrmaWBdVDcxvYqnyh09zunKzROWjbZTiNy8dBEjkS7ehEDQibXJ7XvlmtbwuTclUiIyN+CyXQD4Vmko8fNm8w==",
+ "dev": true,
+ "dependencies": {
+ "siginfo": "^2.0.0",
+ "stackback": "0.0.2"
+ },
+ "bin": {
+ "why-is-node-running": "cli.js"
+ },
+ "engines": {
+ "node": ">=8"
+ }
+ },
"node_modules/wrap-ansi": {
"version": "8.1.0",
"resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-8.1.0.tgz",
diff --git a/server/package.json b/server/package.json
index 64cb25210..66e7a0db5 100644
--- a/server/package.json
+++ b/server/package.json
@@ -9,6 +9,9 @@
"dev": "tsc && node dist/index.js",
"build": "tsc && npm run pack-script",
"start": "node dist/index.js",
+ "test": "vitest",
+ "test:run": "vitest run",
+ "test:watch": "vitest --watch",
"db:generate": "drizzle-kit generate --config=drizzle.config.ts",
"db:migrate": "drizzle-kit migrate --config=drizzle.config.ts",
"db:push": "drizzle-kit push --config=drizzle.config.ts",
@@ -34,6 +37,7 @@
"node-cron": "4.0.6",
"pg": "8.16.0",
"postgres": "3.4.5",
+ "psl": "^1.15.0",
"resend": "^4.5.1",
"sqlstring": "2.3.3",
"stripe": "18.1.0",
@@ -45,11 +49,13 @@
"@types/luxon": "3.6.2",
"@types/node": "20.14.8",
"@types/pg": "8.15.1",
+ "@types/psl": "^1.1.3",
"@types/sqlstring": "2.3.2",
"drizzle-kit": "0.31.1",
"terser": "^5.40.0",
"ts-node-dev": "2.0.0",
"tsx": "4.19.4",
- "typescript": "5.8.3"
+ "typescript": "5.8.3",
+ "vitest": "^3.2.2"
}
}
diff --git a/server/src/api/analytics/query-validation.ts b/server/src/api/analytics/query-validation.ts
index ed6c97aeb..c70c06909 100644
--- a/server/src/api/analytics/query-validation.ts
+++ b/server/src/api/analytics/query-validation.ts
@@ -184,6 +184,7 @@ export const filterParamSchema = z.enum([
"city",
"device_type",
"referrer",
+ "hostname",
"pathname",
"page_title",
"querystring",
diff --git a/server/src/api/analytics/types.ts b/server/src/api/analytics/types.ts
index 6f4e545d7..b480557bd 100644
--- a/server/src/api/analytics/types.ts
+++ b/server/src/api/analytics/types.ts
@@ -9,6 +9,7 @@ export type FilterParameter =
| "city"
| "device_type"
| "referrer"
+ | "hostname"
| "pathname"
| "page_title"
| "querystring"
diff --git a/server/src/tracker/trackEvent.ts b/server/src/tracker/trackEvent.ts
index 5fd108a66..685d2a77b 100644
--- a/server/src/tracker/trackEvent.ts
+++ b/server/src/tracker/trackEvent.ts
@@ -11,7 +11,7 @@ import {
import { db } from "../db/postgres/postgres.js";
import { activeSessions } from "../db/postgres/schema.js";
import { eq } from "drizzle-orm";
-import { getDeviceType } from "../utils.js";
+import { getDeviceType, normalizeOrigin } from "../utils.js";
import { pageviewQueue } from "./pageviewQueue.js";
import { siteConfig } from "../lib/siteConfig.js";
import { DISABLE_ORIGIN_CHECK } from "./const.js";
@@ -205,9 +205,9 @@ async function validateOrigin(siteId: string, requestOrigin?: string) {
// Parse the origin into URL components
const originUrl = new URL(requestOrigin);
- // Normalize domains by removing 'www.' prefix if present
- const normalizedOriginHost = originUrl.hostname.replace(/^www\./, "");
- const normalizedSiteDomain = siteDomain.replace(/^www\./, "");
+ // Normalize domains by removing all subdomain prefixes
+ const normalizedOriginHost = normalizeOrigin(requestOrigin);
+ const normalizedSiteDomain = normalizeOrigin(`https://${siteDomain}`);
// Check if the normalized domains match
if (normalizedOriginHost !== normalizedSiteDomain) {
diff --git a/server/src/utils.test.ts b/server/src/utils.test.ts
new file mode 100644
index 000000000..7111ff9cf
--- /dev/null
+++ b/server/src/utils.test.ts
@@ -0,0 +1,223 @@
+import { describe, it, expect } from "vitest";
+import { normalizeOrigin } from "./utils.js";
+
+describe("normalizeOrigin", () => {
+ describe("Basic subdomain removal", () => {
+ it("should remove www subdomain", () => {
+ expect(normalizeOrigin("www.example.com")).toBe("example.com");
+ expect(normalizeOrigin("https://www.example.com")).toBe("example.com");
+ });
+
+ it("should remove single-level subdomains", () => {
+ expect(normalizeOrigin("api.example.com")).toBe("example.com");
+ expect(normalizeOrigin("blog.example.com")).toBe("example.com");
+ expect(normalizeOrigin("cdn.example.com")).toBe("example.com");
+ expect(normalizeOrigin("https://api.example.com")).toBe("example.com");
+ });
+
+ it("should remove multi-level subdomains", () => {
+ expect(normalizeOrigin("api.v1.example.com")).toBe("example.com");
+ expect(normalizeOrigin("www.blog.example.com")).toBe("example.com");
+ expect(normalizeOrigin("https://api.v2.staging.example.com")).toBe(
+ "example.com"
+ );
+ });
+ });
+
+ describe("Multi-level TLD handling", () => {
+ it("should handle .co.uk domains correctly", () => {
+ expect(normalizeOrigin("www.example.co.uk")).toBe("example.co.uk");
+ expect(normalizeOrigin("api.example.co.uk")).toBe("example.co.uk");
+ expect(normalizeOrigin("https://subdomain.example.co.uk")).toBe(
+ "example.co.uk"
+ );
+ });
+
+ it("should handle .com.au domains correctly", () => {
+ expect(normalizeOrigin("www.example.com.au")).toBe("example.com.au");
+ expect(normalizeOrigin("blog.example.com.au")).toBe("example.com.au");
+ });
+
+ it("should handle .org.uk domains correctly", () => {
+ expect(normalizeOrigin("www.charity.org.uk")).toBe("charity.org.uk");
+ expect(normalizeOrigin("subdomain.charity.org.uk")).toBe(
+ "charity.org.uk"
+ );
+ });
+
+ it("should handle .gov.uk domains correctly", () => {
+ expect(normalizeOrigin("www.agency.gov.uk")).toBe("agency.gov.uk");
+ expect(normalizeOrigin("portal.agency.gov.uk")).toBe("agency.gov.uk");
+ });
+
+ it("should handle .edu.au domains correctly", () => {
+ expect(normalizeOrigin("www.university.edu.au")).toBe(
+ "university.edu.au"
+ );
+ expect(normalizeOrigin("library.university.edu.au")).toBe(
+ "university.edu.au"
+ );
+ });
+ });
+
+ describe("URL vs hostname input handling", () => {
+ it("should handle full URLs with protocols", () => {
+ expect(normalizeOrigin("https://www.example.com")).toBe("example.com");
+ expect(normalizeOrigin("http://api.example.com")).toBe("example.com");
+ expect(normalizeOrigin("https://subdomain.example.co.uk")).toBe(
+ "example.co.uk"
+ );
+ });
+
+ it("should handle URLs with paths", () => {
+ expect(normalizeOrigin("https://www.example.com/path/to/page")).toBe(
+ "example.com"
+ );
+ expect(normalizeOrigin("https://api.example.com/v1/users")).toBe(
+ "example.com"
+ );
+ });
+
+ it("should handle URLs with query parameters", () => {
+ expect(normalizeOrigin("https://www.example.com?param=value")).toBe(
+ "example.com"
+ );
+ expect(normalizeOrigin("https://api.example.com/search?q=test")).toBe(
+ "example.com"
+ );
+ });
+
+ it("should handle URLs with fragments", () => {
+ expect(normalizeOrigin("https://www.example.com#section")).toBe(
+ "example.com"
+ );
+ expect(normalizeOrigin("https://blog.example.com/post#comments")).toBe(
+ "example.com"
+ );
+ });
+
+ it("should handle URLs with ports", () => {
+ expect(normalizeOrigin("https://www.example.com:8080")).toBe(
+ "example.com"
+ );
+ expect(normalizeOrigin("http://api.example.com:3000")).toBe(
+ "example.com"
+ );
+ });
+
+ it("should handle plain hostnames without protocol", () => {
+ expect(normalizeOrigin("www.example.com")).toBe("example.com");
+ expect(normalizeOrigin("api.example.com")).toBe("example.com");
+ expect(normalizeOrigin("subdomain.example.co.uk")).toBe("example.co.uk");
+ });
+ });
+
+ describe("Edge cases", () => {
+ it("should handle localhost", () => {
+ expect(normalizeOrigin("localhost")).toBe("localhost");
+ expect(normalizeOrigin("http://localhost")).toBe("localhost");
+ expect(normalizeOrigin("https://localhost:3000")).toBe("localhost");
+ });
+
+ it("should handle IP addresses", () => {
+ expect(normalizeOrigin("192.168.1.1")).toBe("192.168.1.1");
+ expect(normalizeOrigin("http://192.168.1.1")).toBe("192.168.1.1");
+ expect(normalizeOrigin("https://10.0.0.1:8080")).toBe("10.0.0.1");
+ });
+
+ it("should handle domains that are already root domains", () => {
+ expect(normalizeOrigin("example.com")).toBe("example.com");
+ expect(normalizeOrigin("https://example.com")).toBe("example.com");
+ expect(normalizeOrigin("example.co.uk")).toBe("example.co.uk");
+ });
+
+ it("should handle single-word domains", () => {
+ expect(normalizeOrigin("localhost")).toBe("localhost");
+ expect(normalizeOrigin("intranet")).toBe("intranet");
+ });
+
+ it("should handle domains with hyphens", () => {
+ expect(normalizeOrigin("www.my-site.com")).toBe("my-site.com");
+ expect(normalizeOrigin("api.my-awesome-site.co.uk")).toBe(
+ "my-awesome-site.co.uk"
+ );
+ });
+
+ it("should handle domains with numbers", () => {
+ expect(normalizeOrigin("www.site123.com")).toBe("site123.com");
+ expect(normalizeOrigin("api.123site.com")).toBe("123site.com");
+ });
+ });
+
+ describe("Error handling", () => {
+ it("should handle empty strings", () => {
+ expect(normalizeOrigin("")).toBe("");
+ });
+
+ it("should handle invalid URLs gracefully", () => {
+ // These should not throw errors and should return reasonable results
+ expect(normalizeOrigin("not-a-valid-url")).toBe("not-a-valid-url");
+ expect(normalizeOrigin("://invalid")).toBe("://invalid");
+ });
+
+ it("should handle URLs with invalid characters", () => {
+ // PSL should handle these gracefully
+ expect(normalizeOrigin("www.example_.com")).toBe("example_.com");
+ });
+ });
+
+ describe("Real-world examples", () => {
+ it("should handle common website patterns", () => {
+ // E-commerce sites
+ expect(normalizeOrigin("shop.example.com")).toBe("example.com");
+ expect(normalizeOrigin("store.example.com")).toBe("example.com");
+
+ // API endpoints
+ expect(normalizeOrigin("api.v1.example.com")).toBe("example.com");
+ expect(normalizeOrigin("rest.api.example.com")).toBe("example.com");
+
+ // CDN patterns
+ expect(normalizeOrigin("cdn.assets.example.com")).toBe("example.com");
+ expect(normalizeOrigin("static.example.com")).toBe("example.com");
+
+ // Regional subdomains
+ expect(normalizeOrigin("us.example.com")).toBe("example.com");
+ expect(normalizeOrigin("eu.example.com")).toBe("example.com");
+ });
+
+ it("should handle staging and development environments", () => {
+ expect(normalizeOrigin("staging.example.com")).toBe("example.com");
+ expect(normalizeOrigin("dev.example.com")).toBe("example.com");
+ expect(normalizeOrigin("test.api.example.com")).toBe("example.com");
+ });
+
+ it("should handle international domains", () => {
+ expect(normalizeOrigin("www.example.de")).toBe("example.de");
+ expect(normalizeOrigin("api.example.fr")).toBe("example.fr");
+ expect(normalizeOrigin("subdomain.example.jp")).toBe("example.jp");
+ });
+ });
+
+ describe("Performance considerations", () => {
+ it("should handle multiple calls efficiently", () => {
+ // Test that the function can handle multiple calls without issues
+ const domains = [
+ "www.example.com",
+ "api.example.com",
+ "blog.example.co.uk",
+ "cdn.assets.example.org",
+ "https://shop.example.net",
+ ];
+
+ const results = domains.map((domain) => normalizeOrigin(domain));
+
+ expect(results).toEqual([
+ "example.com",
+ "example.com",
+ "example.co.uk",
+ "example.org",
+ "example.net",
+ ]);
+ });
+ });
+});
diff --git a/server/src/utils.ts b/server/src/utils.ts
index 7999df1be..082b08a87 100644
--- a/server/src/utils.ts
+++ b/server/src/utils.ts
@@ -1,4 +1,5 @@
import { siteConfig } from "./lib/siteConfig.js";
+import * as psl from "psl";
export function getDeviceType(
screenWidth: number,
@@ -75,12 +76,55 @@ export const extractSiteId = (path: string) => {
return null;
};
-// Normalizes a URL origin by removing the "www." prefix.
-export const normalizeOrigin = (url: string) => {
+// Normalizes a domain/hostname by removing all subdomain prefixes.
+// Accepts either a full URL or just a hostname.
+export const normalizeOrigin = (input: string): string => {
try {
- const hostname = new URL(url).hostname;
- return hostname.replace(/^www\./, "").toLowerCase();
+ let hostname: string;
+
+ // If input looks like a URL, extract hostname; otherwise treat as hostname
+ if (input.includes("://")) {
+ hostname = new URL(input).hostname;
+ } else {
+ hostname = input;
+ }
+
+ hostname = hostname.toLowerCase();
+
+ // Handle IP addresses and localhost - return as-is
+ if (hostname === "localhost" || /^\d+\.\d+\.\d+\.\d+$/.test(hostname)) {
+ return hostname;
+ }
+
+ // Use Public Suffix List to get the registrable domain
+ const parsed = psl.parse(hostname);
+
+ // If parsing failed or no domain found, fall back to simple logic
+ if (parsed.error || !parsed.domain) {
+ const parts = hostname.split(".");
+ if (parts.length < 2) {
+ return hostname;
+ }
+ // Default fallback: take last 2 parts
+ return parts.slice(-2).join(".");
+ }
+
+ // Return the registrable domain (domain + public suffix)
+ return parsed.domain;
} catch {
- return url;
+ // Fallback for any errors: try simple domain extraction
+ try {
+ let hostname = input.includes("://") ? new URL(input).hostname : input;
+ hostname = hostname.toLowerCase();
+
+ if (hostname === "localhost" || /^\d+\.\d+\.\d+\.\d+$/.test(hostname)) {
+ return hostname;
+ }
+
+ const parts = hostname.split(".");
+ return parts.length >= 2 ? parts.slice(-2).join(".") : hostname;
+ } catch {
+ return input;
+ }
}
};
diff --git a/server/vitest.config.ts b/server/vitest.config.ts
new file mode 100644
index 000000000..c7eb54768
--- /dev/null
+++ b/server/vitest.config.ts
@@ -0,0 +1,15 @@
+import { defineConfig } from "vitest/config";
+
+export default defineConfig({
+ test: {
+ environment: "node",
+ globals: true,
+ include: ["src/**/*.test.ts"],
+ exclude: ["node_modules", "dist"],
+ },
+ resolve: {
+ alias: {
+ "@": "./src",
+ },
+ },
+});