@nextlytics/core 0.1.0-canary-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.
Files changed (93) hide show
  1. package/dist/anonymous-user.cjs +118 -0
  2. package/dist/anonymous-user.d.mts +22 -0
  3. package/dist/anonymous-user.d.ts +22 -0
  4. package/dist/anonymous-user.js +94 -0
  5. package/dist/backends/clickhouse.cjs +110 -0
  6. package/dist/backends/clickhouse.d.mts +58 -0
  7. package/dist/backends/clickhouse.d.ts +58 -0
  8. package/dist/backends/clickhouse.js +92 -0
  9. package/dist/backends/ga.cjs +207 -0
  10. package/dist/backends/ga.d.mts +21 -0
  11. package/dist/backends/ga.d.ts +21 -0
  12. package/dist/backends/ga.js +183 -0
  13. package/dist/backends/gtm.cjs +155 -0
  14. package/dist/backends/gtm.d.mts +11 -0
  15. package/dist/backends/gtm.d.ts +11 -0
  16. package/dist/backends/gtm.js +131 -0
  17. package/dist/backends/lib/db.cjs +150 -0
  18. package/dist/backends/lib/db.d.mts +121 -0
  19. package/dist/backends/lib/db.d.ts +121 -0
  20. package/dist/backends/lib/db.js +119 -0
  21. package/dist/backends/logging.cjs +45 -0
  22. package/dist/backends/logging.d.mts +7 -0
  23. package/dist/backends/logging.d.ts +7 -0
  24. package/dist/backends/logging.js +21 -0
  25. package/dist/backends/neon.cjs +84 -0
  26. package/dist/backends/neon.d.mts +11 -0
  27. package/dist/backends/neon.d.ts +11 -0
  28. package/dist/backends/neon.js +66 -0
  29. package/dist/backends/postgrest.cjs +98 -0
  30. package/dist/backends/postgrest.d.mts +46 -0
  31. package/dist/backends/postgrest.d.ts +46 -0
  32. package/dist/backends/postgrest.js +73 -0
  33. package/dist/backends/posthog.cjs +120 -0
  34. package/dist/backends/posthog.d.mts +13 -0
  35. package/dist/backends/posthog.d.ts +13 -0
  36. package/dist/backends/posthog.js +96 -0
  37. package/dist/backends/segment.cjs +112 -0
  38. package/dist/backends/segment.d.mts +43 -0
  39. package/dist/backends/segment.d.ts +43 -0
  40. package/dist/backends/segment.js +88 -0
  41. package/dist/client.cjs +171 -0
  42. package/dist/client.d.mts +29 -0
  43. package/dist/client.d.ts +29 -0
  44. package/dist/client.js +146 -0
  45. package/dist/config-helpers.cjs +71 -0
  46. package/dist/config-helpers.d.mts +16 -0
  47. package/dist/config-helpers.d.ts +16 -0
  48. package/dist/config-helpers.js +45 -0
  49. package/dist/handlers.cjs +123 -0
  50. package/dist/handlers.d.mts +9 -0
  51. package/dist/handlers.d.ts +9 -0
  52. package/dist/handlers.js +99 -0
  53. package/dist/headers.cjs +41 -0
  54. package/dist/headers.d.mts +3 -0
  55. package/dist/headers.d.ts +3 -0
  56. package/dist/headers.js +17 -0
  57. package/dist/index.cjs +41 -0
  58. package/dist/index.d.mts +9 -0
  59. package/dist/index.d.ts +9 -0
  60. package/dist/index.js +12 -0
  61. package/dist/middleware.cjs +204 -0
  62. package/dist/middleware.d.mts +10 -0
  63. package/dist/middleware.d.ts +10 -0
  64. package/dist/middleware.js +183 -0
  65. package/dist/pages-router.cjs +45 -0
  66. package/dist/pages-router.d.mts +45 -0
  67. package/dist/pages-router.d.ts +45 -0
  68. package/dist/pages-router.js +21 -0
  69. package/dist/plugins/vercel-geo.cjs +60 -0
  70. package/dist/plugins/vercel-geo.d.mts +25 -0
  71. package/dist/plugins/vercel-geo.d.ts +25 -0
  72. package/dist/plugins/vercel-geo.js +36 -0
  73. package/dist/server-component-context.cjs +95 -0
  74. package/dist/server-component-context.d.mts +30 -0
  75. package/dist/server-component-context.d.ts +30 -0
  76. package/dist/server-component-context.js +69 -0
  77. package/dist/server.cjs +236 -0
  78. package/dist/server.d.mts +13 -0
  79. package/dist/server.d.ts +13 -0
  80. package/dist/server.js +213 -0
  81. package/dist/template.cjs +108 -0
  82. package/dist/template.d.mts +27 -0
  83. package/dist/template.d.ts +27 -0
  84. package/dist/template.js +83 -0
  85. package/dist/types.cjs +16 -0
  86. package/dist/types.d.mts +216 -0
  87. package/dist/types.d.ts +216 -0
  88. package/dist/types.js +0 -0
  89. package/dist/uitils.cjs +94 -0
  90. package/dist/uitils.d.mts +22 -0
  91. package/dist/uitils.d.ts +22 -0
  92. package/dist/uitils.js +68 -0
  93. package/package.json +162 -0
@@ -0,0 +1,216 @@
1
+ import { RequestCookies } from 'next/dist/server/web/spec-extension/cookies';
2
+ import { NextRequest, NextMiddleware } from 'next/server';
3
+
4
+ /** Server-side request context collected in middleware */
5
+ interface ServerEventContext {
6
+ /** When the event was collected on server */
7
+ collectedAt: Date;
8
+ /** Request host (e.g. "example.com") */
9
+ host: string;
10
+ /** HTTP method (GET, POST, etc.) */
11
+ method: string;
12
+ /** URL pathname (e.g. "/products/123") */
13
+ path: string;
14
+ /** Query parameters as key -> values[] */
15
+ search: Record<string, string[]>;
16
+ /** Client IP from x-forwarded-for or direct connection */
17
+ ip: string;
18
+ /** Request headers (sensitive ones removed) */
19
+ requestHeaders: Record<string, string>;
20
+ /** Response headers */
21
+ responseHeaders: Record<string, string>;
22
+ }
23
+ /** Client-side context collected in browser */
24
+ interface ClientContext {
25
+ /** When the event was collected on client */
26
+ collectedAt: Date;
27
+ /** document.referrer */
28
+ referer?: string;
29
+ /** window.location.pathname - may differ from server path in SPAs */
30
+ path?: string;
31
+ /** Screen and viewport dimensions */
32
+ screen: {
33
+ /** screen.width */
34
+ width?: number;
35
+ /** screen.height */
36
+ height?: number;
37
+ /** window.innerWidth (viewport) */
38
+ innerWidth?: number;
39
+ /** window.innerHeight (viewport) */
40
+ innerHeight?: number;
41
+ /** window.devicePixelRatio */
42
+ density?: number;
43
+ };
44
+ /** navigator.userAgent */
45
+ userAgent?: string;
46
+ /** navigator.language */
47
+ locale?: string;
48
+ }
49
+ /** Identified user context */
50
+ interface UserContext {
51
+ /** Unique user identifier */
52
+ userId: string;
53
+ /** User traits for identification */
54
+ traits: {
55
+ email?: string;
56
+ name?: string;
57
+ phone?: string;
58
+ } & Record<string, unknown>;
59
+ }
60
+ /** Analytics event sent to backends */
61
+ interface NextlyticsEvent {
62
+ /** ISO timestamp when event was collected */
63
+ collectedAt: string;
64
+ /** Unique event ID */
65
+ eventId: string;
66
+ /** Parent event ID (e.g. pageView for client events) */
67
+ parentEventId?: string;
68
+ /** Event type (e.g. "pageView", "apiCall", custom events) */
69
+ type: "pageView" | "apiCall" | string;
70
+ /** Anonymous user identifier (GDPR-compliant hash or cookie-based) */
71
+ anonymousUserId?: string;
72
+ /** Server-side request context */
73
+ serverContext: ServerEventContext;
74
+ /** Identified user context */
75
+ userContext?: UserContext;
76
+ /** Client-side browser context */
77
+ clientContext?: ClientContext;
78
+ /** Custom event properties */
79
+ properties: Record<string, unknown>;
80
+ }
81
+
82
+ type AnonymousUserResult = {
83
+ /** Anonymous user identifier */
84
+ anonId: string;
85
+ };
86
+ /** Headers and cookies context for backend/plugin factories. Uses Pick for compatibility with both
87
+ * middleware (RequestCookies) and server components (ReadonlyRequestCookies) */
88
+ type RequestContext = {
89
+ headers: Headers;
90
+ cookies: Pick<RequestCookies, "get" | "getAll" | "has">;
91
+ };
92
+ type NextlyticsPlugin = {
93
+ /**
94
+ * Called right after event is created but before it's sent to backends.
95
+ * Plugin can mutate the event to add/modify properties.
96
+ * @param event - The event to process (can be mutated)
97
+ */
98
+ onDispatch(event: NextlyticsEvent): Promise<void>;
99
+ };
100
+ /** Factory to create plugin per-request (for request-scoped plugins) */
101
+ type NextlyticsPluginFactory = (ctx: RequestContext) => NextlyticsPlugin;
102
+ type NextlyticsConfig = {
103
+ /** Enable debug logging (shows backend stats for each event) */
104
+ debug?: boolean;
105
+ anonymousUsers?: {
106
+ /** Store anonymous ID in cookies */
107
+ useCookies?: boolean;
108
+ /** Use hash-based IDs for GDPR compliance (default: true) */
109
+ gdprMode?: boolean;
110
+ /** Rotate hash salt daily for shorter-lived IDs (default: true) */
111
+ dailySalt?: boolean;
112
+ /** Cookie name when useCookies=true (default: "__nextlytics_anon") */
113
+ cookieName?: string;
114
+ /** Cookie max age in seconds (default: 2 years) */
115
+ cookieMaxAge?: number;
116
+ };
117
+ /**
118
+ * When to record pageView:
119
+ * - "server": in middleware (default, more reliable)
120
+ * - "client-init": when JS loads (has client context) - NOT SUPPORTED CURRENTLU
121
+ */
122
+ pageViewMode?: "server" | "client-init";
123
+ /** Skip tracking for API routes */
124
+ excludeApiCalls?: boolean;
125
+ /** Skip tracking for specific paths */
126
+ excludePaths?: (path: string) => boolean;
127
+ /** Determine if path is API route. Default: () => false */
128
+ isApiPath?: (path: string) => boolean;
129
+ /** Endpoint for client events. Default: "/api/event" */
130
+ eventEndpoint?: string;
131
+ callbacks: {
132
+ /** Resolve authenticated user from request context */
133
+ getUser?: (ctx: RequestContext) => Promise<UserContext | undefined>;
134
+ /** Override anonymous user ID generation */
135
+ getAnonymousUserId?: (opts: {
136
+ ctx: RequestContext;
137
+ originalAnonymousUserId?: string;
138
+ }) => Promise<AnonymousUserResult>;
139
+ };
140
+ /** Analytics backends to send events to */
141
+ backends?: (NextlyticsBackend | NextlyticsBackendFactory)[];
142
+ plugins?: (NextlyticsPlugin | NextlyticsPluginFactory)[];
143
+ };
144
+ type ClientAction = {
145
+ items: ClientActionItem[];
146
+ };
147
+ type ClientActionItem = TemplatizedScriptInsertion<unknown>;
148
+ /**
149
+ * Inserts scripts to a page as
150
+ * `<script scr={src}></script>` or <script>{body}</script>
151
+ */
152
+ type TemplatizedScriptInsertion<T> = {
153
+ type: "script-template";
154
+ params: T;
155
+ templateId: string;
156
+ };
157
+ /** Result of dispatching an event (two-phase) */
158
+ type DispatchResult = {
159
+ /** Resolves quickly with actions from backends with returnsClientActions=true */
160
+ clientActions: Promise<ClientAction>;
161
+ /** Resolves when ALL backends complete processing */
162
+ completion: Promise<void>;
163
+ };
164
+ type JavascriptTemplate = {
165
+ items: ScriptElement[];
166
+ };
167
+ type ScriptElement = {
168
+ async?: string;
169
+ body?: string;
170
+ src?: string;
171
+ /** If true, skip insertion if script with same src already exists */
172
+ singleton?: boolean;
173
+ };
174
+ /** Backend that receives analytics events */
175
+ type NextlyticsBackend = {
176
+ /** Backend name for logging */
177
+ name: string;
178
+ /** Whether backend supports updating existing events */
179
+ supportsUpdates?: boolean;
180
+ /**
181
+ * If onEvent can return client actions
182
+ */
183
+ returnsClientActions?: boolean;
184
+ getClientSideTemplates?: () => Record<string, JavascriptTemplate>;
185
+ /** Handle new event */
186
+ onEvent(event: NextlyticsEvent): Promise<void | ClientAction>;
187
+ /** Update existing event (e.g. add client context to server pageView) */
188
+ updateEvent(eventId: string, patch: Partial<NextlyticsEvent>): Promise<void> | void;
189
+ };
190
+ /** Factory to create backend per-request (for request-scoped backends) */
191
+ type NextlyticsBackendFactory = (ctx: RequestContext) => NextlyticsBackend;
192
+ /** Server-side analytics API */
193
+ type NextlyticsServerSide = {
194
+ /** Send custom event from server component/action */
195
+ sendEvent: (eventName: string, opts?: {
196
+ props?: Record<string, unknown>;
197
+ }) => Promise<{
198
+ ok: boolean;
199
+ }>;
200
+ };
201
+ type AppRouteHandlers = Record<"GET" | "POST", (req: NextRequest) => Promise<Response>>;
202
+ /** Return value from Nextlytics() */
203
+ type NextlyticsResult = {
204
+ /** Route handlers for /api/event */
205
+ handlers: AppRouteHandlers;
206
+ /** Get server-side analytics API */
207
+ analytics: () => Promise<NextlyticsServerSide>;
208
+ /** Middleware to intercept requests */
209
+ middleware: NextMiddleware;
210
+ /** Manually dispatch event (returns two-phase result) */
211
+ dispatchEvent: (event: NextlyticsEvent) => Promise<DispatchResult>;
212
+ /** Manually update existing event */
213
+ updateEvent: (eventId: string, patch: Partial<NextlyticsEvent>) => Promise<void>;
214
+ };
215
+
216
+ export type { AnonymousUserResult, ClientAction, ClientActionItem, ClientContext, DispatchResult, JavascriptTemplate, NextlyticsBackend, NextlyticsBackendFactory, NextlyticsConfig, NextlyticsEvent, NextlyticsPlugin, NextlyticsPluginFactory, NextlyticsResult, NextlyticsServerSide, RequestContext, ScriptElement, ServerEventContext, TemplatizedScriptInsertion, UserContext };
package/dist/types.js ADDED
File without changes
@@ -0,0 +1,94 @@
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
+ var uitils_exports = {};
20
+ __export(uitils_exports, {
21
+ createServerContext: () => createServerContext,
22
+ generateId: () => generateId,
23
+ getRequestInfo: () => getRequestInfo
24
+ });
25
+ module.exports = __toCommonJS(uitils_exports);
26
+ var import_headers = require("./headers");
27
+ const BASE62_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
28
+ function generateId() {
29
+ const length = 16;
30
+ const bytes = new Uint8Array(length * 2);
31
+ crypto.getRandomValues(bytes);
32
+ let result = "";
33
+ for (let i = 0; i < length; i++) {
34
+ const idx = (bytes[i * 2] * 256 + bytes[i * 2 + 1]) % 62;
35
+ result += BASE62_CHARS[idx];
36
+ }
37
+ return result;
38
+ }
39
+ function getRequestInfo(request) {
40
+ const headers = request.headers;
41
+ const pathname = request.nextUrl.pathname;
42
+ const isNextjsInternal = pathname.startsWith("/_next");
43
+ const isStaticFile = /\.(ico|png|jpg|jpeg|gif|svg|webp|css|js|woff2?|ttf|eot|map)$/i.test(
44
+ pathname
45
+ );
46
+ const hasStandardPrefetchHeader = headers.get("next-router-prefetch") === "1" || headers.get("purpose") === "prefetch" || headers.get("sec-purpose") === "prefetch";
47
+ const nextUrl = headers.get("next-url");
48
+ const isRscPrefetch = nextUrl !== null && nextUrl !== pathname;
49
+ const isPrefetch = hasStandardPrefetchHeader || isRscPrefetch;
50
+ const isRsc = !!(nextUrl || headers.get("rsc"));
51
+ const secFetchDest = headers.get("sec-fetch-dest");
52
+ const secFetchMode = headers.get("sec-fetch-mode");
53
+ const accept = headers.get("accept") || "";
54
+ const isDocumentRequest = secFetchDest === "document" || secFetchMode === "navigate";
55
+ const acceptsHtml = accept.includes("text/html");
56
+ const isPageNavigation = isRsc || isDocumentRequest || acceptsHtml;
57
+ return {
58
+ isPrefetch,
59
+ isRsc,
60
+ isPageNavigation,
61
+ isStaticFile,
62
+ isNextjsInternal
63
+ };
64
+ }
65
+ function createServerContext(request) {
66
+ const rawHeaders = {};
67
+ request.headers.forEach((value, key) => {
68
+ rawHeaders[key] = value;
69
+ });
70
+ const requestHeaders = (0, import_headers.removeSensitiveHeaders)(rawHeaders);
71
+ const searchParams = {};
72
+ request.nextUrl.searchParams.forEach((value, key) => {
73
+ if (!searchParams[key]) {
74
+ searchParams[key] = [];
75
+ }
76
+ searchParams[key].push(value);
77
+ });
78
+ return {
79
+ collectedAt: /* @__PURE__ */ new Date(),
80
+ host: request.headers.get("host") || "",
81
+ method: request.method,
82
+ path: request.nextUrl.pathname,
83
+ search: searchParams,
84
+ ip: request.headers.get("x-forwarded-for")?.split(",")[0]?.trim() || "",
85
+ requestHeaders,
86
+ responseHeaders: {}
87
+ };
88
+ }
89
+ // Annotate the CommonJS export names for ESM import in node:
90
+ 0 && (module.exports = {
91
+ createServerContext,
92
+ generateId,
93
+ getRequestInfo
94
+ });
@@ -0,0 +1,22 @@
1
+ import { NextRequest } from 'next/server';
2
+ import { ServerEventContext } from './types.mjs';
3
+ import 'next/dist/server/web/spec-extension/cookies';
4
+
5
+ /** Generate a random base62 ID (16 chars = 62^16 ≈ 4.7 × 10^28 combinations) */
6
+ declare function generateId(): string;
7
+ type RequestInfo = {
8
+ /** True if this is a prefetch request (browser or Next.js router prefetch) */
9
+ isPrefetch: boolean;
10
+ /** True if this is an RSC (React Server Components) navigation */
11
+ isRsc: boolean;
12
+ /** True if this is a standard document or RSC navigation */
13
+ isPageNavigation: boolean;
14
+ /** True if this is a static file (ico, png, css, js, etc.) */
15
+ isStaticFile: boolean;
16
+ /** True if this is a Next.js internal path (/_next/*) */
17
+ isNextjsInternal: boolean;
18
+ };
19
+ declare function getRequestInfo(request: NextRequest): RequestInfo;
20
+ declare function createServerContext(request: NextRequest): ServerEventContext;
21
+
22
+ export { type RequestInfo, createServerContext, generateId, getRequestInfo };
@@ -0,0 +1,22 @@
1
+ import { NextRequest } from 'next/server';
2
+ import { ServerEventContext } from './types.js';
3
+ import 'next/dist/server/web/spec-extension/cookies';
4
+
5
+ /** Generate a random base62 ID (16 chars = 62^16 ≈ 4.7 × 10^28 combinations) */
6
+ declare function generateId(): string;
7
+ type RequestInfo = {
8
+ /** True if this is a prefetch request (browser or Next.js router prefetch) */
9
+ isPrefetch: boolean;
10
+ /** True if this is an RSC (React Server Components) navigation */
11
+ isRsc: boolean;
12
+ /** True if this is a standard document or RSC navigation */
13
+ isPageNavigation: boolean;
14
+ /** True if this is a static file (ico, png, css, js, etc.) */
15
+ isStaticFile: boolean;
16
+ /** True if this is a Next.js internal path (/_next/*) */
17
+ isNextjsInternal: boolean;
18
+ };
19
+ declare function getRequestInfo(request: NextRequest): RequestInfo;
20
+ declare function createServerContext(request: NextRequest): ServerEventContext;
21
+
22
+ export { type RequestInfo, createServerContext, generateId, getRequestInfo };
package/dist/uitils.js ADDED
@@ -0,0 +1,68 @@
1
+ import { removeSensitiveHeaders } from "./headers";
2
+ const BASE62_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
3
+ function generateId() {
4
+ const length = 16;
5
+ const bytes = new Uint8Array(length * 2);
6
+ crypto.getRandomValues(bytes);
7
+ let result = "";
8
+ for (let i = 0; i < length; i++) {
9
+ const idx = (bytes[i * 2] * 256 + bytes[i * 2 + 1]) % 62;
10
+ result += BASE62_CHARS[idx];
11
+ }
12
+ return result;
13
+ }
14
+ function getRequestInfo(request) {
15
+ const headers = request.headers;
16
+ const pathname = request.nextUrl.pathname;
17
+ const isNextjsInternal = pathname.startsWith("/_next");
18
+ const isStaticFile = /\.(ico|png|jpg|jpeg|gif|svg|webp|css|js|woff2?|ttf|eot|map)$/i.test(
19
+ pathname
20
+ );
21
+ const hasStandardPrefetchHeader = headers.get("next-router-prefetch") === "1" || headers.get("purpose") === "prefetch" || headers.get("sec-purpose") === "prefetch";
22
+ const nextUrl = headers.get("next-url");
23
+ const isRscPrefetch = nextUrl !== null && nextUrl !== pathname;
24
+ const isPrefetch = hasStandardPrefetchHeader || isRscPrefetch;
25
+ const isRsc = !!(nextUrl || headers.get("rsc"));
26
+ const secFetchDest = headers.get("sec-fetch-dest");
27
+ const secFetchMode = headers.get("sec-fetch-mode");
28
+ const accept = headers.get("accept") || "";
29
+ const isDocumentRequest = secFetchDest === "document" || secFetchMode === "navigate";
30
+ const acceptsHtml = accept.includes("text/html");
31
+ const isPageNavigation = isRsc || isDocumentRequest || acceptsHtml;
32
+ return {
33
+ isPrefetch,
34
+ isRsc,
35
+ isPageNavigation,
36
+ isStaticFile,
37
+ isNextjsInternal
38
+ };
39
+ }
40
+ function createServerContext(request) {
41
+ const rawHeaders = {};
42
+ request.headers.forEach((value, key) => {
43
+ rawHeaders[key] = value;
44
+ });
45
+ const requestHeaders = removeSensitiveHeaders(rawHeaders);
46
+ const searchParams = {};
47
+ request.nextUrl.searchParams.forEach((value, key) => {
48
+ if (!searchParams[key]) {
49
+ searchParams[key] = [];
50
+ }
51
+ searchParams[key].push(value);
52
+ });
53
+ return {
54
+ collectedAt: /* @__PURE__ */ new Date(),
55
+ host: request.headers.get("host") || "",
56
+ method: request.method,
57
+ path: request.nextUrl.pathname,
58
+ search: searchParams,
59
+ ip: request.headers.get("x-forwarded-for")?.split(",")[0]?.trim() || "",
60
+ requestHeaders,
61
+ responseHeaders: {}
62
+ };
63
+ }
64
+ export {
65
+ createServerContext,
66
+ generateId,
67
+ getRequestInfo
68
+ };
package/package.json ADDED
@@ -0,0 +1,162 @@
1
+ {
2
+ "name": "@nextlytics/core",
3
+ "version": "0.1.0-canary-1",
4
+ "description": "Analytics library for Next.js",
5
+ "license": "MIT",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "require": {
16
+ "types": "./dist/index.d.ts",
17
+ "default": "./dist/index.cjs"
18
+ }
19
+ },
20
+ "./client": {
21
+ "import": {
22
+ "types": "./dist/client.d.ts",
23
+ "default": "./dist/client.js"
24
+ },
25
+ "require": {
26
+ "types": "./dist/client.d.ts",
27
+ "default": "./dist/client.cjs"
28
+ }
29
+ },
30
+ "./server": {
31
+ "import": {
32
+ "types": "./dist/server.d.ts",
33
+ "default": "./dist/server.js"
34
+ },
35
+ "require": {
36
+ "types": "./dist/server.d.ts",
37
+ "default": "./dist/server.cjs"
38
+ }
39
+ },
40
+ "./backends/logging": {
41
+ "import": {
42
+ "types": "./dist/backends/logging.d.ts",
43
+ "default": "./dist/backends/logging.js"
44
+ },
45
+ "require": {
46
+ "types": "./dist/backends/logging.d.ts",
47
+ "default": "./dist/backends/logging.cjs"
48
+ }
49
+ },
50
+ "./backends/posthog": {
51
+ "import": {
52
+ "types": "./dist/backends/posthog.d.ts",
53
+ "default": "./dist/backends/posthog.js"
54
+ },
55
+ "require": {
56
+ "types": "./dist/backends/posthog.d.ts",
57
+ "default": "./dist/backends/posthog.cjs"
58
+ }
59
+ },
60
+ "./backends/neon": {
61
+ "import": {
62
+ "types": "./dist/backends/neon.d.ts",
63
+ "default": "./dist/backends/neon.js"
64
+ },
65
+ "require": {
66
+ "types": "./dist/backends/neon.d.ts",
67
+ "default": "./dist/backends/neon.cjs"
68
+ }
69
+ },
70
+ "./backends/postgrest": {
71
+ "import": {
72
+ "types": "./dist/backends/postgrest.d.ts",
73
+ "default": "./dist/backends/postgrest.js"
74
+ },
75
+ "require": {
76
+ "types": "./dist/backends/postgrest.d.ts",
77
+ "default": "./dist/backends/postgrest.cjs"
78
+ }
79
+ },
80
+ "./backends/segment": {
81
+ "import": {
82
+ "types": "./dist/backends/segment.d.ts",
83
+ "default": "./dist/backends/segment.js"
84
+ },
85
+ "require": {
86
+ "types": "./dist/backends/segment.d.ts",
87
+ "default": "./dist/backends/segment.cjs"
88
+ }
89
+ },
90
+ "./backends/clickhouse": {
91
+ "import": {
92
+ "types": "./dist/backends/clickhouse.d.ts",
93
+ "default": "./dist/backends/clickhouse.js"
94
+ },
95
+ "require": {
96
+ "types": "./dist/backends/clickhouse.d.ts",
97
+ "default": "./dist/backends/clickhouse.cjs"
98
+ }
99
+ },
100
+ "./backends/gtm": {
101
+ "import": {
102
+ "types": "./dist/backends/gtm.d.ts",
103
+ "default": "./dist/backends/gtm.js"
104
+ },
105
+ "require": {
106
+ "types": "./dist/backends/gtm.d.ts",
107
+ "default": "./dist/backends/gtm.cjs"
108
+ }
109
+ },
110
+ "./backends/ga": {
111
+ "import": {
112
+ "types": "./dist/backends/ga.d.ts",
113
+ "default": "./dist/backends/ga.js"
114
+ },
115
+ "require": {
116
+ "types": "./dist/backends/ga.d.ts",
117
+ "default": "./dist/backends/ga.cjs"
118
+ }
119
+ },
120
+ "./plugins/vercel-geo": {
121
+ "import": {
122
+ "types": "./dist/plugins/vercel-geo.d.ts",
123
+ "default": "./dist/plugins/vercel-geo.js"
124
+ },
125
+ "require": {
126
+ "types": "./dist/plugins/vercel-geo.d.ts",
127
+ "default": "./dist/plugins/vercel-geo.cjs"
128
+ }
129
+ }
130
+ },
131
+ "files": [
132
+ "dist"
133
+ ],
134
+ "scripts": {
135
+ "typecheck": "bun tsc --noEmit",
136
+ "build": "rm -rf dist && tsup && find dist -name '*.d.cts' -delete",
137
+ "lint": "bun eslint src",
138
+ "test": "vitest run",
139
+ "test:watch": "vitest",
140
+ "prepublishOnly": "bun run build",
141
+ "pub": "npm publish --access public"
142
+ },
143
+ "peerDependencies": {
144
+ "next": ">=15.0.0",
145
+ "@neondatabase/serverless": ">=0.10.0"
146
+ },
147
+ "peerDependenciesMeta": {
148
+ "@neondatabase/serverless": {
149
+ "optional": true
150
+ }
151
+ },
152
+ "devDependencies": {
153
+ "@neondatabase/serverless": "^0.10.0",
154
+ "@types/react": "^19.0.0",
155
+ "eslint": "^9.0.0",
156
+ "next": "^15.0.0",
157
+ "tsup": "^8.5.1",
158
+ "typescript": "^5.0.0",
159
+ "typescript-eslint": "^8.0.0",
160
+ "vitest": "^4.0.18"
161
+ }
162
+ }