2027-track 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -29,6 +29,50 @@ Or wrap existing middleware:
29
29
  export default withAIAnalytics(yourMiddleware);
30
30
  ```
31
31
 
32
+ ## Vercel (any framework)
33
+
34
+ Works with Remix, SvelteKit, Astro, Nuxt, or any Vercel deployment:
35
+
36
+ ```ts
37
+ // middleware.ts
38
+ import { withAIAnalytics } from "2027-track/vercel";
39
+
40
+ export default withAIAnalytics();
41
+
42
+ export const config = {
43
+ matcher: "/((?!_next|api|favicon.ico|assets|.*\\..*).*)",
44
+ };
45
+ ```
46
+
47
+ Or wrap existing middleware:
48
+
49
+ ```ts
50
+ export default withAIAnalytics(yourMiddleware);
51
+ ```
52
+
53
+ Or use `trackVisit` directly:
54
+
55
+ ```ts
56
+ import { trackVisit } from "2027-track";
57
+
58
+ export const config = {
59
+ matcher: "/((?!_next|api|favicon.ico|assets|.*\\..*).*)",
60
+ };
61
+
62
+ export default function middleware(request: Request, context: { waitUntil: (promise: Promise<unknown>) => void }) {
63
+ const url = new URL(request.url);
64
+ context.waitUntil(
65
+ trackVisit({
66
+ host: url.hostname,
67
+ path: url.pathname,
68
+ userAgent: request.headers.get("user-agent") || "",
69
+ accept: request.headers.get("accept") || "",
70
+ country: request.headers.get("x-vercel-ip-country") || undefined,
71
+ }).catch(() => {})
72
+ );
73
+ }
74
+ ```
75
+
32
76
  ## Generic Usage
33
77
 
34
78
  ```ts
@@ -0,0 +1,8 @@
1
+ export { trackVisit } from './index.mjs';
2
+
3
+ interface VercelContext {
4
+ waitUntil: (promise: Promise<unknown>) => void;
5
+ }
6
+ declare function withAIAnalytics(middleware?: (request: Request, context: VercelContext) => Response | undefined | Promise<Response | undefined>): (request: Request, context: VercelContext) => Promise<Response | undefined>;
7
+
8
+ export { withAIAnalytics };
@@ -0,0 +1,8 @@
1
+ export { trackVisit } from './index.js';
2
+
3
+ interface VercelContext {
4
+ waitUntil: (promise: Promise<unknown>) => void;
5
+ }
6
+ declare function withAIAnalytics(middleware?: (request: Request, context: VercelContext) => Response | undefined | Promise<Response | undefined>): (request: Request, context: VercelContext) => Promise<Response | undefined>;
7
+
8
+ export { withAIAnalytics };
package/dist/vercel.js ADDED
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/vercel.ts
21
+ var vercel_exports = {};
22
+ __export(vercel_exports, {
23
+ trackVisit: () => trackVisit,
24
+ withAIAnalytics: () => withAIAnalytics
25
+ });
26
+ module.exports = __toCommonJS(vercel_exports);
27
+
28
+ // src/index.ts
29
+ var DEFAULT_ENDPOINT = "https://ai-docs-analytics-api.theisease.workers.dev/track";
30
+ var TIMEOUT_MS = 2500;
31
+ function getEndpoint() {
32
+ const env = typeof process !== "undefined" ? process.env.AI_ANALYTICS_ENDPOINT : void 0;
33
+ if (env === "") return null;
34
+ return env || DEFAULT_ENDPOINT;
35
+ }
36
+ function isPageView(accept) {
37
+ const a = accept.toLowerCase();
38
+ return a.includes("text/html") || a.includes("text/markdown");
39
+ }
40
+ async function trackVisit(options) {
41
+ const endpoint = getEndpoint();
42
+ if (!endpoint) {
43
+ return { ok: true, skipped: "disabled" };
44
+ }
45
+ if (!isPageView(options.accept)) {
46
+ return { ok: true, skipped: "not-page-view" };
47
+ }
48
+ const controller = new AbortController();
49
+ const timeoutId = setTimeout(() => controller.abort(), TIMEOUT_MS);
50
+ try {
51
+ const response = await fetch(endpoint, {
52
+ method: "POST",
53
+ headers: { "Content-Type": "application/json" },
54
+ body: JSON.stringify({
55
+ host: options.host,
56
+ path: options.path,
57
+ user_agent: options.userAgent,
58
+ accept: options.accept,
59
+ country: options.country || "unknown"
60
+ }),
61
+ signal: controller.signal
62
+ });
63
+ clearTimeout(timeoutId);
64
+ return await response.json();
65
+ } catch (e) {
66
+ clearTimeout(timeoutId);
67
+ return { ok: false, error: e instanceof Error ? e.message : "unknown error" };
68
+ }
69
+ }
70
+
71
+ // src/vercel.ts
72
+ function withAIAnalytics(middleware) {
73
+ return async (request, context) => {
74
+ const response = middleware ? await middleware(request, context) : void 0;
75
+ const url = new URL(request.url);
76
+ context.waitUntil(
77
+ trackVisit({
78
+ host: url.hostname,
79
+ path: url.pathname,
80
+ userAgent: request.headers.get("user-agent") || "",
81
+ accept: request.headers.get("accept") || "",
82
+ country: request.headers.get("x-vercel-ip-country") || void 0
83
+ }).catch(() => {
84
+ })
85
+ );
86
+ return response;
87
+ };
88
+ }
89
+ // Annotate the CommonJS export names for ESM import in node:
90
+ 0 && (module.exports = {
91
+ trackVisit,
92
+ withAIAnalytics
93
+ });
@@ -0,0 +1,26 @@
1
+ import {
2
+ trackVisit
3
+ } from "./chunk-2UMSOEKA.mjs";
4
+
5
+ // src/vercel.ts
6
+ function withAIAnalytics(middleware) {
7
+ return async (request, context) => {
8
+ const response = middleware ? await middleware(request, context) : void 0;
9
+ const url = new URL(request.url);
10
+ context.waitUntil(
11
+ trackVisit({
12
+ host: url.hostname,
13
+ path: url.pathname,
14
+ userAgent: request.headers.get("user-agent") || "",
15
+ accept: request.headers.get("accept") || "",
16
+ country: request.headers.get("x-vercel-ip-country") || void 0
17
+ }).catch(() => {
18
+ })
19
+ );
20
+ return response;
21
+ };
22
+ }
23
+ export {
24
+ trackVisit,
25
+ withAIAnalytics
26
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "2027-track",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Track AI coding agents visiting your documentation",
5
5
  "repository": {
6
6
  "type": "git",
@@ -20,14 +20,19 @@
20
20
  "types": "./dist/next.d.ts",
21
21
  "import": "./dist/next.mjs",
22
22
  "require": "./dist/next.js"
23
+ },
24
+ "./vercel": {
25
+ "types": "./dist/vercel.d.ts",
26
+ "import": "./dist/vercel.mjs",
27
+ "require": "./dist/vercel.js"
23
28
  }
24
29
  },
25
30
  "files": [
26
31
  "dist"
27
32
  ],
28
33
  "scripts": {
29
- "build": "tsup src/index.ts src/next.ts --format cjs,esm --dts",
30
- "dev": "tsup src/index.ts src/next.ts --format cjs,esm --dts --watch"
34
+ "build": "tsup src/index.ts src/next.ts src/vercel.ts --format cjs,esm --dts",
35
+ "dev": "tsup src/index.ts src/next.ts src/vercel.ts --format cjs,esm --dts --watch"
31
36
  },
32
37
  "keywords": [
33
38
  "ai",