@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 +1 -0
- package/dist/index.js +8 -4
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
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
|
-
|
|
523
|
-
|
|
524
|
-
|
|
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
|
-
|
|
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.
|
|
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.
|
|
33
|
+
"next": "16.4.6",
|
|
34
34
|
"tsup": "8.5.1",
|
|
35
35
|
"typescript": "5.9.3",
|
|
36
36
|
"@punchline/edge": "0.0.0"
|