doccupine 0.0.126 → 0.0.128

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.
Files changed (107) hide show
  1. package/dist/index.js +1 -3
  2. package/dist/templates/app/api/rag/route.d.ts +1 -1
  3. package/dist/templates/app/api/rag/route.js +1 -1
  4. package/dist/templates/components/PostHogProviderLazy.d.ts +1 -1
  5. package/dist/templates/components/PostHogProviderLazy.js +21 -1
  6. package/dist/templates/mdx/accordion.mdx.d.ts +1 -1
  7. package/dist/templates/mdx/accordion.mdx.js +0 -1
  8. package/dist/templates/mdx/ai-assistant.mdx.d.ts +1 -1
  9. package/dist/templates/mdx/ai-assistant.mdx.js +0 -1
  10. package/dist/templates/mdx/analytics.mdx.d.ts +1 -1
  11. package/dist/templates/mdx/analytics.mdx.js +23 -6
  12. package/dist/templates/mdx/authentication.mdx.d.ts +1 -1
  13. package/dist/templates/mdx/authentication.mdx.js +0 -1
  14. package/dist/templates/mdx/buttons.mdx.d.ts +1 -1
  15. package/dist/templates/mdx/buttons.mdx.js +0 -1
  16. package/dist/templates/mdx/callouts.mdx.d.ts +1 -1
  17. package/dist/templates/mdx/callouts.mdx.js +0 -1
  18. package/dist/templates/mdx/cards.mdx.d.ts +1 -1
  19. package/dist/templates/mdx/cards.mdx.js +0 -1
  20. package/dist/templates/mdx/code.mdx.d.ts +1 -1
  21. package/dist/templates/mdx/code.mdx.js +0 -1
  22. package/dist/templates/mdx/color-swatches.mdx.d.ts +1 -1
  23. package/dist/templates/mdx/color-swatches.mdx.js +0 -1
  24. package/dist/templates/mdx/columns.mdx.d.ts +1 -1
  25. package/dist/templates/mdx/columns.mdx.js +0 -1
  26. package/dist/templates/mdx/commands.mdx.d.ts +1 -1
  27. package/dist/templates/mdx/commands.mdx.js +0 -1
  28. package/dist/templates/mdx/components.mdx.d.ts +1 -1
  29. package/dist/templates/mdx/components.mdx.js +0 -1
  30. package/dist/templates/mdx/deployment-and-hosting.mdx.d.ts +1 -1
  31. package/dist/templates/mdx/deployment-and-hosting.mdx.js +0 -1
  32. package/dist/templates/mdx/fields.mdx.d.ts +1 -1
  33. package/dist/templates/mdx/fields.mdx.js +0 -1
  34. package/dist/templates/mdx/fonts.mdx.d.ts +1 -1
  35. package/dist/templates/mdx/fonts.mdx.js +0 -1
  36. package/dist/templates/mdx/footer-links.mdx.d.ts +1 -1
  37. package/dist/templates/mdx/footer-links.mdx.js +0 -1
  38. package/dist/templates/mdx/globals.mdx.d.ts +1 -1
  39. package/dist/templates/mdx/globals.mdx.js +0 -1
  40. package/dist/templates/mdx/headers-and-text.mdx.d.ts +1 -1
  41. package/dist/templates/mdx/headers-and-text.mdx.js +0 -1
  42. package/dist/templates/mdx/icons.mdx.d.ts +1 -1
  43. package/dist/templates/mdx/icons.mdx.js +0 -1
  44. package/dist/templates/mdx/image-and-embeds.mdx.d.ts +1 -1
  45. package/dist/templates/mdx/image-and-embeds.mdx.js +0 -1
  46. package/dist/templates/mdx/index.mdx.d.ts +1 -1
  47. package/dist/templates/mdx/index.mdx.js +0 -1
  48. package/dist/templates/mdx/lists-and-tables.mdx.d.ts +1 -1
  49. package/dist/templates/mdx/lists-and-tables.mdx.js +0 -1
  50. package/dist/templates/mdx/media-and-assets.mdx.d.ts +1 -1
  51. package/dist/templates/mdx/media-and-assets.mdx.js +0 -1
  52. package/dist/templates/mdx/mermaid.mdx.d.ts +1 -1
  53. package/dist/templates/mdx/mermaid.mdx.js +0 -1
  54. package/dist/templates/mdx/model-context-protocol.mdx.d.ts +1 -1
  55. package/dist/templates/mdx/model-context-protocol.mdx.js +0 -1
  56. package/dist/templates/mdx/navigation.mdx.d.ts +1 -1
  57. package/dist/templates/mdx/navigation.mdx.js +0 -1
  58. package/dist/templates/mdx/platform/ai-assistant.mdx.d.ts +1 -1
  59. package/dist/templates/mdx/platform/ai-assistant.mdx.js +0 -1
  60. package/dist/templates/mdx/platform/analytics.mdx.d.ts +1 -1
  61. package/dist/templates/mdx/platform/analytics.mdx.js +1 -2
  62. package/dist/templates/mdx/platform/billing.mdx.d.ts +1 -1
  63. package/dist/templates/mdx/platform/billing.mdx.js +0 -1
  64. package/dist/templates/mdx/platform/build-and-deploy.mdx.d.ts +1 -1
  65. package/dist/templates/mdx/platform/build-and-deploy.mdx.js +0 -1
  66. package/dist/templates/mdx/platform/creating-a-project.mdx.d.ts +1 -1
  67. package/dist/templates/mdx/platform/creating-a-project.mdx.js +0 -1
  68. package/dist/templates/mdx/platform/custom-domains.mdx.d.ts +1 -1
  69. package/dist/templates/mdx/platform/custom-domains.mdx.js +0 -1
  70. package/dist/templates/mdx/platform/external-links.mdx.d.ts +1 -1
  71. package/dist/templates/mdx/platform/external-links.mdx.js +0 -1
  72. package/dist/templates/mdx/platform/file-editor.mdx.d.ts +1 -1
  73. package/dist/templates/mdx/platform/file-editor.mdx.js +41 -2
  74. package/dist/templates/mdx/platform/fonts-settings.mdx.d.ts +1 -1
  75. package/dist/templates/mdx/platform/fonts-settings.mdx.js +0 -1
  76. package/dist/templates/mdx/platform/index.mdx.d.ts +1 -1
  77. package/dist/templates/mdx/platform/index.mdx.js +0 -1
  78. package/dist/templates/mdx/platform/mcp.mdx.d.ts +1 -1
  79. package/dist/templates/mdx/platform/mcp.mdx.js +0 -1
  80. package/dist/templates/mdx/platform/navigation-settings.mdx.d.ts +1 -1
  81. package/dist/templates/mdx/platform/navigation-settings.mdx.js +0 -1
  82. package/dist/templates/mdx/platform/project-settings.mdx.d.ts +1 -1
  83. package/dist/templates/mdx/platform/project-settings.mdx.js +0 -1
  84. package/dist/templates/mdx/platform/publishing.mdx.d.ts +1 -1
  85. package/dist/templates/mdx/platform/publishing.mdx.js +0 -1
  86. package/dist/templates/mdx/platform/site-settings.mdx.d.ts +1 -1
  87. package/dist/templates/mdx/platform/site-settings.mdx.js +0 -1
  88. package/dist/templates/mdx/platform/team-members.mdx.d.ts +1 -1
  89. package/dist/templates/mdx/platform/team-members.mdx.js +0 -1
  90. package/dist/templates/mdx/platform/theme-settings.mdx.d.ts +1 -1
  91. package/dist/templates/mdx/platform/theme-settings.mdx.js +0 -1
  92. package/dist/templates/mdx/sections.mdx.d.ts +1 -1
  93. package/dist/templates/mdx/sections.mdx.js +0 -1
  94. package/dist/templates/mdx/steps.mdx.d.ts +1 -1
  95. package/dist/templates/mdx/steps.mdx.js +0 -1
  96. package/dist/templates/mdx/tabs.mdx.d.ts +1 -1
  97. package/dist/templates/mdx/tabs.mdx.js +0 -1
  98. package/dist/templates/mdx/theme.mdx.d.ts +1 -1
  99. package/dist/templates/mdx/theme.mdx.js +0 -1
  100. package/dist/templates/mdx/update.mdx.d.ts +1 -1
  101. package/dist/templates/mdx/update.mdx.js +0 -1
  102. package/dist/templates/mdx/what-is-doccupine.mdx.d.ts +1 -1
  103. package/dist/templates/mdx/what-is-doccupine.mdx.js +1 -2
  104. package/dist/templates/next.config.js +5 -4
  105. package/dist/templates/package.js +6 -7
  106. package/dist/templates/proxy.js +118 -25
  107. package/package.json +1 -1
@@ -17,23 +17,22 @@ export const packageJsonTemplate = JSON.stringify({
17
17
  "@langchain/openai": "^1.5.5",
18
18
  "@mdx-js/react": "^3.1.1",
19
19
  "@modelcontextprotocol/sdk": "^1.29.0",
20
- "@posthog/react": "^1.10.3",
21
20
  "beautiful-mermaid": "^1.1.3",
22
21
  "cherry-styled-components": "^0.2.11",
23
22
  langchain: "^1.5.3",
24
- "lucide-react": "^1.24.0",
23
+ "lucide-react": "^1.25.0",
25
24
  minisearch: "^7.2.0",
26
25
  next: "16.2.10",
27
26
  "next-mdx-remote": "^6.0.0",
28
- "posthog-js": "^1.403.0",
29
- "posthog-node": "^5.45.1",
27
+ "posthog-js": "^1.404.1",
28
+ "posthog-node": "^5.45.2",
30
29
  react: "19.2.7",
31
30
  "react-dom": "19.2.7",
32
31
  "rehype-highlight": "^7.0.2",
33
32
  "rehype-parse": "^9.0.1",
34
33
  "rehype-stringify": "^10.0.1",
35
34
  "remark-gfm": "^4.0.1",
36
- "styled-components": "^6.4.3",
35
+ "styled-components": "^6.4.4",
37
36
  unified: "^11.0.5",
38
37
  zod: "^4.4.3",
39
38
  },
@@ -43,8 +42,8 @@ export const packageJsonTemplate = JSON.stringify({
43
42
  "@types/node": "^26",
44
43
  "@types/react": "^19",
45
44
  "@types/react-dom": "^19",
46
- "@typescript-eslint/eslint-plugin": "^8.64.0",
47
- "@typescript-eslint/parser": "^8.64.0",
45
+ "@typescript-eslint/eslint-plugin": "^8.65.0",
46
+ "@typescript-eslint/parser": "^8.65.0",
48
47
  "@typescript/native-preview": "^7.0.0-dev.20260707.2",
49
48
  eslint: "^10",
50
49
  "eslint-plugin-import": "^2.32.0",
@@ -8,36 +8,96 @@ export const proxyTemplate = (analyticsConfig = null) => {
8
8
  ? `
9
9
  const SKIP_PAGEVIEW_PATTERN = /^\\/(api|ingest|_next)\\//;
10
10
 
11
- function captureServerPageview(req: NextRequest, event: NextFetchEvent) {
12
- const pathname = req.nextUrl.pathname;
13
-
14
- if (SKIP_PAGEVIEW_PATTERN.test(pathname)) return;
15
-
16
- const isPrefetch =
17
- req.headers.get("next-router-prefetch") === "1" ||
18
- req.headers.get("purpose") === "prefetch";
19
- if (isPrefetch) return;
11
+ /**
12
+ * First-party anonymous id.
13
+ *
14
+ * posthog-js keeps its own id in \`ph_<key>_posthog\`, but an ad blocker stops
15
+ * that script from ever running, so a blocked reader never gets one. Without an
16
+ * id of our own we minted a fresh UUID per request, which made every single
17
+ * pageview a brand-new "person" and badly inflated unique-visitor counts. This
18
+ * cookie is what makes one anonymous reader one person across requests.
19
+ *
20
+ * It is first-party and httpOnly: only the edge reads it, and it never leaves
21
+ * your domain except as a PostHog distinct_id.
22
+ */
23
+ const ANON_ID_COOKIE = "dcp_anon_id";
24
+
25
+ const ANON_ID_MAX_AGE = 60 * 60 * 24 * 365;
26
+
27
+ interface TrackingIdentity {
28
+ distinctId: string;
29
+ /** Set only when the id was just minted and still needs writing to a cookie. */
30
+ anonIdToPersist?: string;
31
+ sessionId?: string;
32
+ deviceId?: string;
33
+ }
20
34
 
21
- const posthog = getPostHogServerClient();
22
- if (!posthog) return;
35
+ /**
36
+ * Resolves who this pageview belongs to: whatever posthog-js already
37
+ * established for this browser, else our own anonymous cookie, else a fresh id
38
+ * that the caller persists.
39
+ */
40
+ function resolveTrackingIdentity(req: NextRequest): TrackingIdentity {
41
+ let distinctId: string | undefined;
42
+ let sessionId: string | undefined;
43
+ let deviceId: string | undefined;
23
44
 
24
45
  const phCookie = req.cookies.get(
25
46
  "ph_${analyticsConfig.posthog.key}_posthog",
26
47
  )?.value;
27
- let distinctId: string | undefined;
28
48
  if (phCookie) {
29
49
  try {
30
- distinctId = JSON.parse(phCookie).distinct_id;
50
+ const parsed = JSON.parse(phCookie);
51
+ if (typeof parsed.distinct_id === "string") distinctId = parsed.distinct_id;
52
+ // \`$sesid\` is [lastActivityTs, sessionId, sessionStartTs]. Forwarding it
53
+ // keeps server events inside the client's session instead of floating free.
54
+ if (Array.isArray(parsed.$sesid) && typeof parsed.$sesid[1] === "string") {
55
+ sessionId = parsed.$sesid[1];
56
+ }
57
+ if (typeof parsed.$device_id === "string") deviceId = parsed.$device_id;
31
58
  } catch {
32
59
  // ignore malformed cookie
33
60
  }
34
61
  }
35
- if (!distinctId) {
36
- distinctId = crypto.randomUUID();
37
- }
62
+
63
+ if (distinctId) return { distinctId, sessionId, deviceId };
64
+
65
+ const anonId = req.cookies.get(ANON_ID_COOKIE)?.value;
66
+ if (anonId) return { distinctId: anonId, sessionId, deviceId };
67
+
68
+ const minted = crypto.randomUUID();
69
+ return { distinctId: minted, anonIdToPersist: minted, sessionId, deviceId };
70
+ }
71
+
72
+ /**
73
+ * Server captures document loads; the client tracker captures soft navigations.
74
+ * Splitting by navigation type is what stops the two from both counting the
75
+ * same view — previously every page load produced two \`$pageview\` events.
76
+ */
77
+ function captureServerPageview(
78
+ req: NextRequest,
79
+ event: NextFetchEvent,
80
+ ): TrackingIdentity | null {
81
+ const pathname = req.nextUrl.pathname;
82
+
83
+ if (SKIP_PAGEVIEW_PATTERN.test(pathname)) return null;
84
+
85
+ const isPrefetch =
86
+ req.headers.get("next-router-prefetch") === "1" ||
87
+ req.headers.get("purpose") === "prefetch";
88
+ if (isPrefetch) return null;
89
+
90
+ // A soft navigation fetches an RSC payload rather than a document, and
91
+ // carries this header. The client tracker owns those.
92
+ if (req.headers.get("RSC")) return null;
93
+
94
+ const posthog = getPostHogServerClient();
95
+ if (!posthog) return null;
96
+
97
+ const identity = resolveTrackingIdentity(req);
38
98
 
39
99
  posthog.capture({
40
- distinctId,
100
+ distinctId: identity.distinctId,
41
101
  event: "$pageview",
42
102
  properties: {
43
103
  $current_url: req.url,
@@ -45,16 +105,46 @@ function captureServerPageview(req: NextRequest, event: NextFetchEvent) {
45
105
  $host: req.headers.get("host") ?? undefined,
46
106
  $referrer: req.headers.get("referer") ?? undefined,
47
107
  $user_agent: req.headers.get("user-agent") ?? undefined,
108
+ $session_id: identity.sessionId,
109
+ $device_id: identity.deviceId,
48
110
  _server_side: true,
49
111
  },
50
112
  });
51
113
  event.waitUntil(posthog.flush());
114
+
115
+ return identity;
52
116
  }
53
117
  `
54
118
  : "";
55
- const posthogCall = hasPostHog
56
- ? ` captureServerPageview(req, event);\n`
57
- : "";
119
+ // Applied at every exit so the anonymous id is persisted whichever branch the
120
+ // request takes (gate rewrite, redirect, or the normal response). Without it
121
+ // a reader stuck behind the password gate would keep minting new ids.
122
+ const applyTrackingFn = hasPostHog
123
+ ? `
124
+ function applyTracking(
125
+ res: NextResponse,
126
+ tracking: TrackingIdentity | null,
127
+ ): NextResponse {
128
+ if (tracking?.anonIdToPersist) {
129
+ res.cookies.set(ANON_ID_COOKIE, tracking.anonIdToPersist, {
130
+ path: "/",
131
+ maxAge: ANON_ID_MAX_AGE,
132
+ sameSite: "lax",
133
+ httpOnly: true,
134
+ secure: process.env.NODE_ENV === "production",
135
+ });
136
+ }
137
+ return res;
138
+ }
139
+ `
140
+ : `
141
+ function applyTracking(res: NextResponse, _tracking: null): NextResponse {
142
+ return res;
143
+ }
144
+ `;
145
+ const trackingInit = hasPostHog
146
+ ? ` const tracking = captureServerPageview(req, event);\n`
147
+ : ` const tracking = null;\n`;
58
148
  const fnSignature = hasPostHog
59
149
  ? `export async function proxy(req: NextRequest, event: NextFetchEvent)`
60
150
  : `export async function proxy(req: NextRequest)`;
@@ -73,9 +163,9 @@ function captureServerPageview(req: NextRequest, event: NextFetchEvent) {
73
163
  const matcher = `["/:path*"]`;
74
164
  return `import { NextResponse } from "next/server";
75
165
  import type { NextRequest${eventImport} } from "next/server";
76
- ${gateImport}${posthogImport}${posthogPageviewFn}
166
+ ${gateImport}${posthogImport}${posthogPageviewFn}${applyTrackingFn}
77
167
  ${fnSignature} {
78
- ${posthogCall} const pathname = req.nextUrl.pathname;
168
+ ${trackingInit} const pathname = req.nextUrl.pathname;
79
169
  const sitePassword = process.env.SITE_PASSWORD;
80
170
 
81
171
  // API key auth for /api/mcp when DOCS_API_KEY is configured
@@ -119,12 +209,15 @@ ${posthogCall} const pathname = req.nextUrl.pathname;
119
209
  if (!unlocked && !pathname.startsWith("/api") && pathname !== "/gate") {
120
210
  const res = NextResponse.rewrite(new URL("/gate", req.url));
121
211
  res.headers.set("X-Robots-Tag", "noindex, nofollow");
122
- return res;
212
+ return applyTracking(res, tracking);
123
213
  }
124
214
 
125
215
  // Unlocked visitors never need the gate screen.
126
216
  if (unlocked && pathname === "/gate") {
127
- return NextResponse.redirect(new URL("/", req.url));
217
+ return applyTracking(
218
+ NextResponse.redirect(new URL("/", req.url)),
219
+ tracking,
220
+ );
128
221
  }
129
222
  }
130
223
 
@@ -136,7 +229,7 @@ ${posthogCall} const pathname = req.nextUrl.pathname;
136
229
  res.headers.set("X-Robots-Tag", "noindex, nofollow");
137
230
  }
138
231
 
139
- return res;
232
+ return applyTracking(res, tracking);
140
233
  }
141
234
 
142
235
  export const config = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "doccupine",
3
- "version": "0.0.126",
3
+ "version": "0.0.128",
4
4
  "description": "Free and open-source documentation platform. Write MDX, get a production-ready site with AI chat, built-in components, and an MCP server - in one command.",
5
5
  "main": "dist/index.js",
6
6
  "bin": {