{"_id":"@adwait12345/telemetry-astro","_rev":"5-e919bea2e942374cab964c92ada41caa","name":"@adwait12345/telemetry-astro","dist-tags":{"latest":"0.1.4"},"versions":{"0.1.0":{"name":"@adwait12345/telemetry-astro","version":"0.1.0","_id":"@adwait12345/telemetry-astro@0.1.0","maintainers":[{"name":"adwait12345","email":"advtbokde@gmail.com"}],"dist":{"shasum":"d5d2af67574e85dc2e97460148841494650dc8d8","tarball":"https://registry.npmjs.org/@adwait12345/telemetry-astro/-/telemetry-astro-0.1.0.tgz","fileCount":5,"integrity":"sha512-F4H9+P64euKGTF0lVPcb+eqXeE9/4mTtZdLXos/oxwG10Vs4Zrk1J3Cf9VRU1Ml/KgPqiyXfOC25XGgPahPXVQ==","signatures":[{"sig":"MEUCIQCeynDzi3t0CUMe2+DhvhpeHwR63WJrADZ4ju8bVeD3igIgVGv/Ez3gINsEGlLHkK/Gl8zjCEOWvHsguS9/I7AlOis=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":7819},"main":"./dist/index.js","_from":"file:adwait12345-telemetry-astro-0.1.0.tgz","types":"./dist/index.d.ts","module":"./dist/index.mjs","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.js"}},"scripts":{"dev":"tsup src/index.ts --format esm,cjs --dts --watch","build":"tsup src/index.ts --format esm,cjs --dts --clean","clean":"rm -rf dist","typecheck":"tsc --noEmit"},"_npmUser":{"name":"adwait12345","email":"advtbokde@gmail.com"},"_resolved":"/private/var/folders/n5/qzpv7qs52kz9rd1ks63nybvc0000gn/T/d85c8a0bdfc24ec3db905544c6f7e3d2/adwait12345-telemetry-astro-0.1.0.tgz","_integrity":"sha512-F4H9+P64euKGTF0lVPcb+eqXeE9/4mTtZdLXos/oxwG10Vs4Zrk1J3Cf9VRU1Ml/KgPqiyXfOC25XGgPahPXVQ==","_npmVersion":"10.9.3","description":"Astro middleware for Telemetry SDK — bot detection and server-side tracking","directories":{},"_nodeVersion":"22.18.0","dependencies":{"@adwait12345/telemetry-core":">=0.1.0"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.0.0","astro":"^4.0.0","typescript":"^5.4.0"},"peerDependencies":{"astro":">=3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/telemetry-astro_0.1.0_1772823329008_0.4139684483595103","host":"s3://npm-registry-packages-npm-production"}},"0.1.1":{"name":"@adwait12345/telemetry-astro","version":"0.1.1","_id":"@adwait12345/telemetry-astro@0.1.1","maintainers":[{"name":"adwait12345","email":"advtbokde@gmail.com"}],"dist":{"shasum":"9e5bdb1d091d677828fcf64a23f9d789d2e0c0a1","tarball":"https://registry.npmjs.org/@adwait12345/telemetry-astro/-/telemetry-astro-0.1.1.tgz","fileCount":5,"integrity":"sha512-EBiJzpsPX1WF5JiJ8clLWrUrq8OzBRpjnStYLiPcmYruhxZzwmG0jgH51divUqBFXFu5FMUqKmQxTr/+CuY87Q==","signatures":[{"sig":"MEUCIQD2pNtpPnn74z6Cfq9k1kKLHCTERo/X3iDt+pzt6u1xCQIgLTzHnWWg2ST8wvKUPjTEh1HqhWNSy+FcPNjznQdhqgs=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":8743},"main":"./dist/index.js","_from":"file:adwait12345-telemetry-astro-0.1.1.tgz","types":"./dist/index.d.ts","module":"./dist/index.mjs","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.js"}},"scripts":{"dev":"tsup src/index.ts --format esm,cjs --dts --watch","build":"tsup src/index.ts --format esm,cjs --dts --clean","clean":"rm -rf dist","typecheck":"tsc --noEmit"},"_npmUser":{"name":"adwait12345","email":"advtbokde@gmail.com"},"_resolved":"/private/var/folders/n5/qzpv7qs52kz9rd1ks63nybvc0000gn/T/a32e3fa0e28ba3ce1e172069e0a129f7/adwait12345-telemetry-astro-0.1.1.tgz","_integrity":"sha512-EBiJzpsPX1WF5JiJ8clLWrUrq8OzBRpjnStYLiPcmYruhxZzwmG0jgH51divUqBFXFu5FMUqKmQxTr/+CuY87Q==","_npmVersion":"10.9.3","description":"Astro middleware for Telemetry SDK — bot detection and server-side tracking","directories":{},"_nodeVersion":"22.18.0","dependencies":{"@adwait12345/telemetry-core":">=0.1.0"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.0.0","astro":"^4.0.0","typescript":"^5.4.0"},"peerDependencies":{"astro":">=3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/telemetry-astro_0.1.1_1772824307825_0.33318309285990244","host":"s3://npm-registry-packages-npm-production"}},"0.1.2":{"name":"@adwait12345/telemetry-astro","version":"0.1.2","_id":"@adwait12345/telemetry-astro@0.1.2","maintainers":[{"name":"adwait12345","email":"advtbokde@gmail.com"}],"dist":{"shasum":"a9f87e6efe13192c6ccd6abdae722083ad4c7e75","tarball":"https://registry.npmjs.org/@adwait12345/telemetry-astro/-/telemetry-astro-0.1.2.tgz","fileCount":6,"integrity":"sha512-Q3akxa51YSYqZkIYEV/N5M3NH23uhMzlQV2sby2AwvocVUV7EortB4Kt3SAv8eKmL3Hdsi7hacCaQdagukpl+A==","signatures":[{"sig":"MEUCIE+ct0GiMXAsorjSyQn7g8KlMN9OybuiOKGvfeANuMBnAiEA2gFRimjo5ZxuHwSuUlzTBZGMDoxwimAMT7zpuQH1t+o=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":14846},"main":"./dist/index.js","_from":"file:adwait12345-telemetry-astro-0.1.2.tgz","types":"./dist/index.d.ts","module":"./dist/index.mjs","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.js"}},"scripts":{"dev":"tsup src/index.ts --format esm,cjs --dts --watch","build":"tsup src/index.ts --format esm,cjs --dts --clean","clean":"rm -rf dist","typecheck":"tsc --noEmit"},"_npmUser":{"name":"adwait12345","email":"advtbokde@gmail.com"},"_resolved":"/private/var/folders/n5/qzpv7qs52kz9rd1ks63nybvc0000gn/T/ed65f894a7cd7a80a3ad62285c9de56f/adwait12345-telemetry-astro-0.1.2.tgz","_integrity":"sha512-Q3akxa51YSYqZkIYEV/N5M3NH23uhMzlQV2sby2AwvocVUV7EortB4Kt3SAv8eKmL3Hdsi7hacCaQdagukpl+A==","_npmVersion":"10.9.3","description":"Astro middleware for Telemetry SDK — bot detection and server-side tracking","directories":{},"_nodeVersion":"22.18.0","dependencies":{"@adwait12345/telemetry-core":">=0.1.0"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.0.0","astro":"^4.0.0","typescript":"^5.4.0"},"peerDependencies":{"astro":">=3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/telemetry-astro_0.1.2_1772827806647_0.9674609590737862","host":"s3://npm-registry-packages-npm-production"}},"0.1.3":{"name":"@adwait12345/telemetry-astro","version":"0.1.3","_id":"@adwait12345/telemetry-astro@0.1.3","maintainers":[{"name":"adwait12345","email":"advtbokde@gmail.com"}],"dist":{"shasum":"ebaf1c20b814159708f396c9a94c319b9b3fd78f","tarball":"https://registry.npmjs.org/@adwait12345/telemetry-astro/-/telemetry-astro-0.1.3.tgz","fileCount":6,"integrity":"sha512-Bd2VfwYssOuP8DYATZsYtbkgcMVn8X/XLvvMCQ8ucOt7AcaxQK921SEqM+TTzxUkUYK6cD/nJpjpAAWftvZktg==","signatures":[{"sig":"MEUCIQCpkubFG8YNdIeS1S/QOqQQi54ogFKISe9jx1z1jrr9tgIgV2ubnCpXyRmOwn6JyxBNkriHAA72BQ2eDnvLTDGpmkc=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":15158},"main":"./dist/index.js","types":"./dist/index.d.ts","module":"./dist/index.mjs","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.js"}},"gitHead":"602eb8a9300311669ba6cd7653dbc4ff3aa662fe","scripts":{"dev":"tsup src/index.ts --format esm,cjs --dts --watch","build":"tsup src/index.ts --format esm,cjs --dts --clean","clean":"rm -rf dist","typecheck":"tsc --noEmit"},"_npmUser":{"name":"adwait12345","email":"advtbokde@gmail.com"},"_npmVersion":"10.9.3","description":"Astro middleware for Telemetry SDK — bot detection and server-side tracking","directories":{},"_nodeVersion":"22.18.0","dependencies":{"@adwait12345/telemetry-core":">=0.1.0"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.0.0","astro":"^4.0.0","typescript":"^5.4.0"},"peerDependencies":{"astro":">=3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/telemetry-astro_0.1.3_1772885599954_0.6383478313802275","host":"s3://npm-registry-packages-npm-production"}},"0.1.4":{"name":"@adwait12345/telemetry-astro","version":"0.1.4","description":"Astro middleware for Telemetry SDK — bot detection and server-side tracking","main":"./dist/index.js","module":"./dist/index.mjs","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.js"}},"scripts":{"build":"tsup src/index.ts --format esm,cjs --dts --clean","dev":"tsup src/index.ts --format esm,cjs --dts --watch","typecheck":"tsc --noEmit","clean":"rm -rf dist"},"dependencies":{"@adwait12345/telemetry-core":"^0.1.5"},"devDependencies":{"astro":"^4.0.0","tsup":"^8.0.0","typescript":"^5.4.0"},"peerDependencies":{"astro":">=3.0.0"},"_id":"@adwait12345/telemetry-astro@0.1.4","gitHead":"602eb8a9300311669ba6cd7653dbc4ff3aa662fe","_nodeVersion":"22.18.0","_npmVersion":"10.9.3","dist":{"integrity":"sha512-KOkZ9/zZU8gdPOFgghsR7zVTbADBKXiWj+w8IQP14oTUF7w7hG/KVwUIqL4iLdgG+A1e0J0o78zNAQTrgdKjmw==","shasum":"167d296de33bbfe8918b4219480c34277fcbd60b","tarball":"https://registry.npmjs.org/@adwait12345/telemetry-astro/-/telemetry-astro-0.1.4.tgz","fileCount":6,"unpackedSize":15085,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIHRVVQBjeuDPPgo9+nZEzcZbrbeybMjrL2KwDlZjmIQ9AiBQxyiYZqagxal0lmCrNZB8KMeWcRZc4arXO9D2OE4xow=="}]},"_npmUser":{"name":"adwait12345","email":"advtbokde@gmail.com"},"directories":{},"maintainers":[{"name":"adwait12345","email":"advtbokde@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/telemetry-astro_0.1.4_1773139588909_0.8002352598184648"},"_hasShrinkwrap":false}},"time":{"created":"2026-03-06T18:55:28.955Z","modified":"2026-03-10T10:46:29.217Z","0.1.0":"2026-03-06T18:55:29.164Z","0.1.1":"2026-03-06T19:11:47.975Z","0.1.2":"2026-03-06T20:10:06.813Z","0.1.3":"2026-03-07T12:13:20.108Z","0.1.4":"2026-03-10T10:46:29.086Z"},"description":"Astro middleware for Telemetry SDK — bot detection and server-side tracking","maintainers":[{"name":"adwait12345","email":"advtbokde@gmail.com"}],"readme":"# `@adwait12345/telemetry-astro`\n\nAstro middleware adapter for the Telemetry SDK. Detects bots and crawlers on every server-side request and sends tracking payloads to the Telemetry API — without affecting response time.\n\n---\n\n## Requirements\n\n- Astro **3.0.0 or later**\n- Astro must be running in **SSR mode** (`output: \"server\"` or `output: \"hybrid\"`)  \n  ⚠️ Static (`output: \"static\"`) pages do not have access to request headers — the middleware will not run\n- Node.js **18+** (uses native `fetch`)\n- A Telemetry account with a **Project ID** and **Server Secret**\n\n---\n\n## Installation\n\n```bash\nnpm install @adwait12345/telemetry-astro @adwait12345/telemetry-core\n# or\npnpm add @adwait12345/telemetry-astro @adwait12345/telemetry-core\n```\n\n---\n\n## Setup\n\n### 1. Enable SSR in `astro.config.mjs`\n\n```javascript\n// astro.config.mjs\nimport { defineConfig } from \"astro/config\";\nimport node from \"@astrojs/node\";\n\nexport default defineConfig({\n  output: \"server\", // or \"hybrid\" — required for middleware to receive real headers\n  adapter: node({ mode: \"standalone\" }),\n});\n```\n\n> **Note:** If you use `output: \"hybrid\"`, pages default to static. Add `export const prerender = false;` to any page you want the middleware to run on, or set `prerender = false` globally.\n\n### 2. Create `src/middleware.ts`\n\n```typescript\n// src/middleware.ts\nimport { telemetryMiddleware } from \"@adwait12345/telemetry-astro\";\n\nexport const onRequest = telemetryMiddleware({\n  projectId: import.meta.env.TELEMETRY_PROJECT_ID,\n  apiUrl: import.meta.env.TELEMETRY_API_URL,\n  serverSecret: import.meta.env.TELEMETRY_SERVER_SECRET,\n  debug: false,\n});\n```\n\n### 3. Add environment variables\n\n```bash\n# .env\nTELEMETRY_PROJECT_ID=your-project-id\nTELEMETRY_API_URL=https://telemetry-uqd3.onrender.com\nTELEMETRY_SERVER_SECRET=sk_...\n```\n\n---\n\n## How it works\n\n1. `onRequest` is called by Astro on every incoming request before the page renders\n2. Requests with an **empty user-agent** are skipped immediately — these are Astro internal server requests (SSR pre-renders, HMR, etc.) and are not real traffic\n3. The request is normalized (UA, IP, headers) and passed to `detectBot()`\n4. If a bot is detected (or `trackAll: true`), a payload is sent to the Telemetry API\n5. On **Vercel / Cloudflare edge runtimes**, `waitUntil` is used so the send happens after the response — zero latency impact\n6. On other runtimes, the send is `await`ed before `next()` is called\n7. `next()` is always called — the middleware never blocks or modifies the response\n\n---\n\n## Configuration options\n\n| Option | Type | Default | Description |\n|--------|------|---------|-------------|\n| `projectId` | `string` | **required** | Your Telemetry project ID |\n| `serverSecret` | `string` | **required** | Your server secret key for API auth |\n| `apiUrl` | `string` | hosted service | Override the API endpoint |\n| `trackAll` | `boolean` | `false` | Track all requests, not just bots |\n| `trackSearchBots` | `boolean` | `true` | Include Googlebot, Bingbot etc. |\n| `ignorePaths` | `(string \\| RegExp)[]` | — | Paths to skip entirely |\n| `customBots` | `Array<{name, pattern, category?}>` | — | Add custom bot definitions |\n| `debug` | `boolean` | `false` | Log detection results to the console |\n| `authorizationHeader` | `string` | — | Fully custom `Authorization` header value |\n| `headers` | `Record<string, string>` | — | Extra headers on every telemetry request |\n\n---\n\n## Examples\n\n### Skip specific paths\n\n```typescript\nexport const onRequest = telemetryMiddleware({\n  projectId: \"...\",\n  serverSecret: \"sk_...\",\n  ignorePaths: [\"/health\", /^\\/api\\//],\n});\n```\n\n### Track all visitors (not just bots)\n\n```typescript\nexport const onRequest = telemetryMiddleware({\n  projectId: \"...\",\n  serverSecret: \"sk_...\",\n  trackAll: true,\n});\n```\n\n### Composing with other Astro middleware\n\n```typescript\n// src/middleware.ts\nimport { sequence } from \"astro:middleware\";\nimport { telemetryMiddleware } from \"@adwait12345/telemetry-astro\";\n\nconst telemetry = telemetryMiddleware({\n  projectId: \"...\",\n  serverSecret: \"sk_...\",\n});\n\nasync function authMiddleware(context, next) {\n  // your auth logic\n  return next();\n}\n\nexport const onRequest = sequence(telemetry, authMiddleware);\n```\n\n### Debug mode — see what's being detected\n\n```typescript\nexport const onRequest = telemetryMiddleware({\n  projectId: \"...\",\n  serverSecret: \"sk_...\",\n  debug: true,\n});\n```\n\nWith `debug: true`, you'll see a line like this in your server console for every request:\n\n```\n[Telemetry Astro] / — UA: \"Mozilla/5.0 ...\" | isBot: false | botName: — | category: — | confidence: low\n[Telemetry Astro] /about — UA: \"Mozilla/5.0 (compatible; Googlebot...\" | isBot: true | botName: Googlebot | category: search | confidence: certain\n[Telemetry Astro] Skipping request with no user-agent: /_image\n```\n\n---\n\n## What gets tracked\n\n| Field | Description |\n|-------|-------------|\n| `projectId` | Your project ID |\n| `path` | Request path |\n| `method` | HTTP method |\n| `userAgent` | Full user-agent string |\n| `ip` | Client IP (from `x-forwarded-for` or `x-real-ip`) |\n| `isBot` | `true` / `false` |\n| `botName` | Named bot e.g. `\"GPTBot\"`, or `null` |\n| `botCategory` | e.g. `\"ai-crawler\"`, `\"search\"`, `\"scraper\"` |\n| `confidence` | `\"certain\"` / `\"high\"` / `\"medium\"` / `\"low\"` |\n| `detectionMethod` | `\"ua-match\"` / `\"header-anomaly\"` / `\"automation-header\"` / etc. |\n| `referrer` | Referrer header |\n| `timestamp` | ISO 8601 UTC |\n\n---\n\n## Troubleshooting\n\n**Middleware not running / headers not available**  \nMake sure `output` is set to `\"server\"` or `\"hybrid\"` in `astro.config.mjs`. Static pages do not have access to request headers.\n\n**Getting false positives for internal requests**  \nThe middleware skips requests with no `user-agent` automatically. If you see internal requests being tracked, enable `debug: true` to see what user-agent they're sending and add them to `ignorePaths`.\n\n**500 errors from the API**  \nCheck that `serverSecret` is set correctly. The API requires `Authorization: Bearer sk_...` on all server-side tracking requests.\n","readmeFilename":"README.md"}