@punchline-analytics/next 0.4.0 → 0.4.1

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/dist/index.d.ts CHANGED
@@ -40,6 +40,7 @@ interface EdgeEvent {
40
40
  mcp?: {
41
41
  calls: McpCall[];
42
42
  };
43
+ mcpSession?: string;
43
44
  visitorId?: string;
44
45
  consent?: true;
45
46
  ip: string;
package/dist/index.js CHANGED
@@ -519,9 +519,11 @@ Share link to this page: ${link}
519
519
  const headers = new Headers(md.headers);
520
520
  headers.set("cache-control", "private, no-store");
521
521
  headers.delete("content-length");
522
- const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(token));
523
- const tokenHash = Array.from(new Uint8Array(digest), (b) => b.toString(16).padStart(2, "0")).join("");
524
- return { response: new Response(body, { status: md.status, headers }), tokenHash };
522
+ return { response: new Response(body, { status: md.status, headers }), tokenHash: await sha256Hex(token) };
523
+ }
524
+ async function sha256Hex(text) {
525
+ const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(text));
526
+ return Array.from(new Uint8Array(digest), (b) => b.toString(16).padStart(2, "0")).join("");
525
527
  }
526
528
  function randomBase62(n) {
527
529
  const ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
@@ -603,10 +605,12 @@ function createTracker(options) {
603
605
  const config = resolveDsn();
604
606
  if (config && isMcpRequest(request, options.mcpPaths)) {
605
607
  const event2 = buildEvent(request, config.siteId, options.readFacts(request), Date.now());
608
+ const sessionId = request.headers.get("mcp-session-id")?.trim();
606
609
  const sent2 = readMcpCalls(request).then(async (calls) => {
607
610
  if (!calls) return;
608
611
  const r = response ? await response.catch(() => null) : null;
609
- await send(config, { ...event2, mcp: { calls }, ...r ? { status: r.status } : {} });
612
+ const mcpSession = sessionId && sessionId.length <= 256 ? await sha256Hex(sessionId) : void 0;
613
+ await send(config, { ...event2, mcp: { calls }, ...mcpSession ? { mcpSession } : {}, ...r ? { status: r.status } : {} });
610
614
  });
611
615
  waitUntil(sent2.catch(onError));
612
616
  return { overheadMs: performance.now() - start };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@punchline-analytics/next",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "See which visitors are AI agents: Next.js middleware/proxy for Punchline Analytics. Forwards a minimal, privacy-reduced event per page request.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -30,7 +30,7 @@
30
30
  "devDependencies": {
31
31
  "@punchline/privacy": "0.0.0",
32
32
  "@punchline/schema": "0.0.0",
33
- "next": "16.4.1",
33
+ "next": "16.4.6",
34
34
  "tsup": "8.5.1",
35
35
  "typescript": "5.9.3",
36
36
  "@punchline/edge": "0.0.0"