@nextlytics/core 0.2.0 → 0.2.1-canary.57
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/anonymous-user.js +26 -2
- package/dist/backends/clickhouse.js +32 -14
- package/dist/backends/ga.js +26 -2
- package/dist/backends/gtm.js +26 -2
- package/dist/backends/lib/db.js +33 -2
- package/dist/backends/logging.js +26 -2
- package/dist/backends/neon.js +41 -20
- package/dist/backends/postgrest.js +33 -8
- package/dist/backends/posthog.js +26 -2
- package/dist/backends/segment.js +26 -2
- package/dist/client.js +41 -16
- package/dist/config-helpers.js +28 -2
- package/dist/handlers.js +35 -11
- package/dist/headers.js +26 -2
- package/dist/index.js +35 -6
- package/dist/middleware.js +47 -26
- package/dist/pages-router.js +28 -4
- package/dist/plugins/vercel-geo.js +26 -2
- package/dist/server-component-context.js +29 -3
- package/dist/server.js +60 -35
- package/dist/template.js +27 -2
- package/dist/types.js +16 -0
- package/dist/uitils.js +30 -4
- package/package.json +28 -101
- package/dist/anonymous-user.cjs +0 -118
- package/dist/anonymous-user.d.mts +0 -22
- package/dist/backends/clickhouse.cjs +0 -110
- package/dist/backends/clickhouse.d.mts +0 -58
- package/dist/backends/ga.cjs +0 -207
- package/dist/backends/ga.d.mts +0 -21
- package/dist/backends/gtm.cjs +0 -155
- package/dist/backends/gtm.d.mts +0 -11
- package/dist/backends/lib/db.cjs +0 -150
- package/dist/backends/lib/db.d.mts +0 -121
- package/dist/backends/logging.cjs +0 -45
- package/dist/backends/logging.d.mts +0 -7
- package/dist/backends/neon.cjs +0 -84
- package/dist/backends/neon.d.mts +0 -11
- package/dist/backends/postgrest.cjs +0 -98
- package/dist/backends/postgrest.d.mts +0 -46
- package/dist/backends/posthog.cjs +0 -120
- package/dist/backends/posthog.d.mts +0 -13
- package/dist/backends/segment.cjs +0 -112
- package/dist/backends/segment.d.mts +0 -43
- package/dist/client.cjs +0 -171
- package/dist/client.d.mts +0 -29
- package/dist/config-helpers.cjs +0 -71
- package/dist/config-helpers.d.mts +0 -16
- package/dist/handlers.cjs +0 -123
- package/dist/handlers.d.mts +0 -9
- package/dist/headers.cjs +0 -41
- package/dist/headers.d.mts +0 -3
- package/dist/index.cjs +0 -41
- package/dist/index.d.mts +0 -9
- package/dist/middleware.cjs +0 -204
- package/dist/middleware.d.mts +0 -10
- package/dist/pages-router.cjs +0 -45
- package/dist/pages-router.d.mts +0 -45
- package/dist/plugins/vercel-geo.cjs +0 -60
- package/dist/plugins/vercel-geo.d.mts +0 -25
- package/dist/server-component-context.cjs +0 -95
- package/dist/server-component-context.d.mts +0 -30
- package/dist/server.cjs +0 -236
- package/dist/server.d.mts +0 -13
- package/dist/template.cjs +0 -108
- package/dist/template.d.mts +0 -27
- package/dist/types.cjs +0 -16
- package/dist/types.d.mts +0 -216
- package/dist/uitils.cjs +0 -94
- package/dist/uitils.d.mts +0 -22
package/dist/client.cjs
DELETED
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
"use client";
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
-
var client_exports = {};
|
|
21
|
-
__export(client_exports, {
|
|
22
|
-
NextlyticsClient: () => NextlyticsClient,
|
|
23
|
-
useNextlytics: () => useNextlytics
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(client_exports);
|
|
26
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
27
|
-
var import_react = require("react");
|
|
28
|
-
var import_server_component_context = require("./server-component-context");
|
|
29
|
-
var import_template = require("./template");
|
|
30
|
-
const templateFunctions = {
|
|
31
|
-
q: (v) => JSON.stringify(v ?? null),
|
|
32
|
-
json: (v) => JSON.stringify(v ?? null)
|
|
33
|
-
};
|
|
34
|
-
const compiledCache = {};
|
|
35
|
-
const NextlyticsContext = (0, import_react.createContext)(null);
|
|
36
|
-
function createClientContext() {
|
|
37
|
-
const isBrowser = typeof window !== "undefined";
|
|
38
|
-
return {
|
|
39
|
-
collectedAt: /* @__PURE__ */ new Date(),
|
|
40
|
-
referer: isBrowser ? document.referrer || void 0 : void 0,
|
|
41
|
-
path: isBrowser ? window.location.pathname : void 0,
|
|
42
|
-
screen: {
|
|
43
|
-
width: isBrowser ? window.screen.width : void 0,
|
|
44
|
-
height: isBrowser ? window.screen.height : void 0,
|
|
45
|
-
innerWidth: isBrowser ? window.innerWidth : void 0,
|
|
46
|
-
innerHeight: isBrowser ? window.innerHeight : void 0,
|
|
47
|
-
density: isBrowser ? window.devicePixelRatio : void 0
|
|
48
|
-
},
|
|
49
|
-
userAgent: isBrowser ? navigator.userAgent : void 0,
|
|
50
|
-
locale: isBrowser ? navigator.language : void 0
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
function getCompiledTemplate(templateId, itemIndex, item) {
|
|
54
|
-
const cacheKey = `${templateId}:${itemIndex}`;
|
|
55
|
-
if (!compiledCache[cacheKey]) {
|
|
56
|
-
compiledCache[cacheKey] = {
|
|
57
|
-
src: item.src ? (0, import_template.compile)(item.src) : void 0,
|
|
58
|
-
body: item.body ? (0, import_template.compile)(item.body) : void 0
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
return compiledCache[cacheKey];
|
|
62
|
-
}
|
|
63
|
-
function executeTemplatedScripts(scripts, templates) {
|
|
64
|
-
if (!scripts || typeof window === "undefined") return;
|
|
65
|
-
for (const script of scripts) {
|
|
66
|
-
if (script.type !== "script-template") {
|
|
67
|
-
console.warn(`[Nextlytics] unsupported script type ${script.type} `);
|
|
68
|
-
continue;
|
|
69
|
-
}
|
|
70
|
-
const template = templates[script.templateId];
|
|
71
|
-
if (!template) {
|
|
72
|
-
console.warn(`[Nextlytics] Missing template: ${script.templateId}`);
|
|
73
|
-
continue;
|
|
74
|
-
}
|
|
75
|
-
const params = script.params;
|
|
76
|
-
for (let i = 0; i < template.items.length; i++) {
|
|
77
|
-
const item = template.items[i];
|
|
78
|
-
const compiled = getCompiledTemplate(script.templateId, i, item);
|
|
79
|
-
const src = compiled.src ? (0, import_template.apply)(compiled.src, params, templateFunctions) : void 0;
|
|
80
|
-
if (item.singleton && src && document.querySelector(`script[src="${src}"]`)) {
|
|
81
|
-
continue;
|
|
82
|
-
}
|
|
83
|
-
const el = document.createElement("script");
|
|
84
|
-
if (src) {
|
|
85
|
-
el.src = src;
|
|
86
|
-
}
|
|
87
|
-
if (compiled.body) {
|
|
88
|
-
el.textContent = (0, import_template.apply)(compiled.body, params, templateFunctions);
|
|
89
|
-
}
|
|
90
|
-
if (item.async) {
|
|
91
|
-
el.async = true;
|
|
92
|
-
}
|
|
93
|
-
document.head.appendChild(el);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
async function sendEvent(requestId, type, payload) {
|
|
98
|
-
try {
|
|
99
|
-
const response = await fetch("/api/event", {
|
|
100
|
-
method: "POST",
|
|
101
|
-
headers: {
|
|
102
|
-
"Content-Type": "application/json",
|
|
103
|
-
[import_server_component_context.headers.pageRenderId]: requestId
|
|
104
|
-
},
|
|
105
|
-
body: JSON.stringify({ type, payload })
|
|
106
|
-
});
|
|
107
|
-
if (response.status === 404) {
|
|
108
|
-
console.error(
|
|
109
|
-
"[Nextlytics] In order for NextlyticsClient to work, you must mount nextlyticsRouteHandler to /api/event"
|
|
110
|
-
);
|
|
111
|
-
return { ok: false };
|
|
112
|
-
}
|
|
113
|
-
const data = await response.json().catch(() => ({ ok: response.ok }));
|
|
114
|
-
return { ok: data.ok ?? response.ok, scripts: data.scripts };
|
|
115
|
-
} catch (error) {
|
|
116
|
-
console.error("[Nextlytics] Failed to send event:", error);
|
|
117
|
-
return { ok: false };
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
const initializedRequestIds = /* @__PURE__ */ new Set();
|
|
121
|
-
function NextlyticsClient(props) {
|
|
122
|
-
const requestId = props.ctx?.requestId ?? props.requestId ?? "";
|
|
123
|
-
const scripts = props.ctx?.scripts ?? props.scripts;
|
|
124
|
-
const templates = props.ctx?.templates ?? props.templates ?? {};
|
|
125
|
-
(0, import_react.useEffect)(() => {
|
|
126
|
-
if (initializedRequestIds.has(requestId)) return;
|
|
127
|
-
initializedRequestIds.add(requestId);
|
|
128
|
-
if (scripts && Object.keys(templates).length > 0) {
|
|
129
|
-
executeTemplatedScripts(scripts, templates);
|
|
130
|
-
}
|
|
131
|
-
const clientContext = createClientContext();
|
|
132
|
-
sendEvent(requestId, "client-init", clientContext).then(
|
|
133
|
-
({ scripts: responseScripts }) => {
|
|
134
|
-
if (responseScripts) {
|
|
135
|
-
executeTemplatedScripts(responseScripts, templates);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
);
|
|
139
|
-
}, [requestId, scripts, templates]);
|
|
140
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(NextlyticsContext.Provider, { value: { requestId, templates }, children: props.children });
|
|
141
|
-
}
|
|
142
|
-
function useNextlytics() {
|
|
143
|
-
const context = (0, import_react.useContext)(NextlyticsContext);
|
|
144
|
-
if (!context) {
|
|
145
|
-
throw new Error(
|
|
146
|
-
"[Nextlytics] useNextlytics() must be used within a component wrapped by <NextlyticsServer>. Add <NextlyticsServer> at the top of your layout.tsx file."
|
|
147
|
-
);
|
|
148
|
-
}
|
|
149
|
-
const { requestId, templates } = context;
|
|
150
|
-
const send = (0, import_react.useCallback)(
|
|
151
|
-
async (eventName, opts) => {
|
|
152
|
-
const result = await sendEvent(requestId, "client-event", {
|
|
153
|
-
name: eventName,
|
|
154
|
-
props: opts?.props,
|
|
155
|
-
collectedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
156
|
-
clientContext: createClientContext()
|
|
157
|
-
});
|
|
158
|
-
if (result.scripts) {
|
|
159
|
-
executeTemplatedScripts(result.scripts, templates);
|
|
160
|
-
}
|
|
161
|
-
return { ok: result.ok };
|
|
162
|
-
},
|
|
163
|
-
[requestId, templates]
|
|
164
|
-
);
|
|
165
|
-
return { sendEvent: send };
|
|
166
|
-
}
|
|
167
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
168
|
-
0 && (module.exports = {
|
|
169
|
-
NextlyticsClient,
|
|
170
|
-
useNextlytics
|
|
171
|
-
});
|
package/dist/client.d.mts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { ReactNode } from 'react';
|
|
3
|
-
import { TemplatizedScriptInsertion, JavascriptTemplate } from './types.mjs';
|
|
4
|
-
import 'next/dist/server/web/spec-extension/cookies';
|
|
5
|
-
import 'next/server';
|
|
6
|
-
|
|
7
|
-
/** Context object for Pages Router integration */
|
|
8
|
-
type NextlyticsContext = {
|
|
9
|
-
requestId: string;
|
|
10
|
-
scripts?: TemplatizedScriptInsertion<unknown>[];
|
|
11
|
-
templates?: Record<string, JavascriptTemplate>;
|
|
12
|
-
};
|
|
13
|
-
declare function NextlyticsClient(props: {
|
|
14
|
-
ctx?: NextlyticsContext;
|
|
15
|
-
requestId?: string;
|
|
16
|
-
scripts?: TemplatizedScriptInsertion<unknown>[];
|
|
17
|
-
templates?: Record<string, JavascriptTemplate>;
|
|
18
|
-
children?: ReactNode;
|
|
19
|
-
}): react_jsx_runtime.JSX.Element;
|
|
20
|
-
type NextlyticsClientApi = {
|
|
21
|
-
sendEvent: (eventName: string, opts?: {
|
|
22
|
-
props?: Record<string, unknown>;
|
|
23
|
-
}) => Promise<{
|
|
24
|
-
ok: boolean;
|
|
25
|
-
}>;
|
|
26
|
-
};
|
|
27
|
-
declare function useNextlytics(): NextlyticsClientApi;
|
|
28
|
-
|
|
29
|
-
export { NextlyticsClient, type NextlyticsClientApi, type NextlyticsContext, useNextlytics };
|
package/dist/config-helpers.cjs
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
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 config_helpers_exports = {};
|
|
20
|
-
__export(config_helpers_exports, {
|
|
21
|
-
logConfigWarnings: () => logConfigWarnings,
|
|
22
|
-
validateConfig: () => validateConfig,
|
|
23
|
-
withDefaults: () => withDefaults
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(config_helpers_exports);
|
|
26
|
-
function withDefaults(config) {
|
|
27
|
-
return {
|
|
28
|
-
...config,
|
|
29
|
-
pageViewMode: config.pageViewMode ?? "server",
|
|
30
|
-
excludeApiCalls: config.excludeApiCalls ?? false,
|
|
31
|
-
eventEndpoint: config.eventEndpoint ?? "/api/event",
|
|
32
|
-
isApiPath: config.isApiPath ?? (() => false),
|
|
33
|
-
backends: config.backends ?? [],
|
|
34
|
-
anonymousUsers: {
|
|
35
|
-
gdprMode: config.anonymousUsers?.gdprMode ?? true,
|
|
36
|
-
useCookies: config.anonymousUsers?.useCookies ?? false,
|
|
37
|
-
dailySalt: config.anonymousUsers?.dailySalt ?? true,
|
|
38
|
-
cookieName: config.anonymousUsers?.cookieName ?? "__nextlytics_anon",
|
|
39
|
-
cookieMaxAge: config.anonymousUsers?.cookieMaxAge ?? 60 * 60 * 24 * 365 * 2
|
|
40
|
-
// 2 years
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
function validateConfig(config) {
|
|
45
|
-
const warnings = [];
|
|
46
|
-
if (config.pageViewMode === "client-init" && config.backends?.length) {
|
|
47
|
-
const staticBackends = config.backends.filter((b) => typeof b !== "function");
|
|
48
|
-
const backendsWithoutUpdates = staticBackends.filter((b) => !b.supportsUpdates);
|
|
49
|
-
if (backendsWithoutUpdates.length > 0) {
|
|
50
|
-
const backendNames = backendsWithoutUpdates.map((b) => `"${b.name}"`).join(", ");
|
|
51
|
-
warnings.push(
|
|
52
|
-
`[Nextlytics] pageViewMode="client-init" requires backends that support updates. These don't: ${backendNames}`
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return {
|
|
57
|
-
valid: warnings.length === 0,
|
|
58
|
-
warnings
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
function logConfigWarnings(result) {
|
|
62
|
-
for (const warning of result.warnings) {
|
|
63
|
-
console.warn(warning);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
67
|
-
0 && (module.exports = {
|
|
68
|
-
logConfigWarnings,
|
|
69
|
-
validateConfig,
|
|
70
|
-
withDefaults
|
|
71
|
-
});
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { NextlyticsConfig } from './types.mjs';
|
|
2
|
-
import 'next/dist/server/web/spec-extension/cookies';
|
|
3
|
-
import 'next/server';
|
|
4
|
-
|
|
5
|
-
type NextlyticsConfigWithDefaults = Required<Pick<NextlyticsConfig, "pageViewMode" | "excludeApiCalls" | "eventEndpoint" | "isApiPath" | "backends">> & NextlyticsConfig & {
|
|
6
|
-
anonymousUsers: Required<NonNullable<NextlyticsConfig["anonymousUsers"]>>;
|
|
7
|
-
};
|
|
8
|
-
declare function withDefaults(config: NextlyticsConfig): NextlyticsConfigWithDefaults;
|
|
9
|
-
interface ConfigValidationResult {
|
|
10
|
-
valid: boolean;
|
|
11
|
-
warnings: string[];
|
|
12
|
-
}
|
|
13
|
-
declare function validateConfig(config: NextlyticsConfig): ConfigValidationResult;
|
|
14
|
-
declare function logConfigWarnings(result: ConfigValidationResult): void;
|
|
15
|
-
|
|
16
|
-
export { type ConfigValidationResult, type NextlyticsConfigWithDefaults, logConfigWarnings, validateConfig, withDefaults };
|
package/dist/handlers.cjs
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
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 handlers_exports = {};
|
|
20
|
-
__export(handlers_exports, {
|
|
21
|
-
createHandlers: () => createHandlers
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(handlers_exports);
|
|
24
|
-
var import_server_component_context = require("./server-component-context");
|
|
25
|
-
var import_uitils = require("./uitils");
|
|
26
|
-
var import_anonymous_user = require("./anonymous-user");
|
|
27
|
-
function createRequestContext(request) {
|
|
28
|
-
return {
|
|
29
|
-
headers: request.headers,
|
|
30
|
-
cookies: request.cookies
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
async function getUserContext(config, ctx) {
|
|
34
|
-
if (!config.callbacks.getUser) return void 0;
|
|
35
|
-
return await config.callbacks.getUser(ctx) || void 0;
|
|
36
|
-
}
|
|
37
|
-
function createHandlers(config, dispatchEvent, updateEvent) {
|
|
38
|
-
return {
|
|
39
|
-
GET: async () => {
|
|
40
|
-
return Response.json({ status: "ok" });
|
|
41
|
-
},
|
|
42
|
-
POST: async (req) => {
|
|
43
|
-
const pageRenderId = req.headers.get(import_server_component_context.headers.pageRenderId);
|
|
44
|
-
if (!pageRenderId) {
|
|
45
|
-
return Response.json({ error: "Missing page render ID" }, { status: 400 });
|
|
46
|
-
}
|
|
47
|
-
let body;
|
|
48
|
-
try {
|
|
49
|
-
body = await req.json();
|
|
50
|
-
} catch {
|
|
51
|
-
return Response.json({ error: "Invalid JSON" }, { status: 400 });
|
|
52
|
-
}
|
|
53
|
-
const { type, payload } = body;
|
|
54
|
-
const ctx = createRequestContext(req);
|
|
55
|
-
if (type === "client-init") {
|
|
56
|
-
const clientContext = payload;
|
|
57
|
-
const serverContext = (0, import_uitils.createServerContext)(req);
|
|
58
|
-
if (clientContext?.path) {
|
|
59
|
-
serverContext.path = clientContext.path;
|
|
60
|
-
}
|
|
61
|
-
const userContext = await getUserContext(config, ctx);
|
|
62
|
-
const { anonId: anonymousUserId } = await (0, import_anonymous_user.resolveAnonymousUser)({
|
|
63
|
-
ctx,
|
|
64
|
-
serverContext,
|
|
65
|
-
config
|
|
66
|
-
});
|
|
67
|
-
if (config.pageViewMode === "client-init") {
|
|
68
|
-
const event = {
|
|
69
|
-
eventId: pageRenderId,
|
|
70
|
-
type: "pageView",
|
|
71
|
-
collectedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
72
|
-
anonymousUserId,
|
|
73
|
-
serverContext,
|
|
74
|
-
clientContext,
|
|
75
|
-
userContext,
|
|
76
|
-
properties: {}
|
|
77
|
-
};
|
|
78
|
-
const { clientActions, completion } = dispatchEvent(event, ctx);
|
|
79
|
-
const actions = await clientActions;
|
|
80
|
-
completion.catch((err) => console.warn("[Nextlytics] Dispatch completion error:", err));
|
|
81
|
-
const scripts = actions.items.filter((i) => i.type === "script-template");
|
|
82
|
-
return Response.json({ ok: true, scripts: scripts.length > 0 ? scripts : void 0 });
|
|
83
|
-
} else {
|
|
84
|
-
await updateEvent(pageRenderId, { clientContext, userContext, anonymousUserId }, ctx);
|
|
85
|
-
return Response.json({ ok: true });
|
|
86
|
-
}
|
|
87
|
-
} else if (type === "client-event") {
|
|
88
|
-
const clientContext = payload.clientContext || void 0;
|
|
89
|
-
const serverContext = (0, import_uitils.createServerContext)(req);
|
|
90
|
-
if (clientContext?.path) {
|
|
91
|
-
serverContext.path = clientContext.path;
|
|
92
|
-
}
|
|
93
|
-
const userContext = await getUserContext(config, ctx);
|
|
94
|
-
const { anonId: anonymousUserId } = await (0, import_anonymous_user.resolveAnonymousUser)({
|
|
95
|
-
ctx,
|
|
96
|
-
serverContext,
|
|
97
|
-
config
|
|
98
|
-
});
|
|
99
|
-
const event = {
|
|
100
|
-
eventId: (0, import_uitils.generateId)(),
|
|
101
|
-
parentEventId: pageRenderId,
|
|
102
|
-
type: payload.name || type,
|
|
103
|
-
collectedAt: payload.collectedAt || (/* @__PURE__ */ new Date()).toISOString(),
|
|
104
|
-
anonymousUserId,
|
|
105
|
-
serverContext,
|
|
106
|
-
clientContext,
|
|
107
|
-
userContext,
|
|
108
|
-
properties: payload.props || {}
|
|
109
|
-
};
|
|
110
|
-
const { clientActions, completion } = dispatchEvent(event, ctx);
|
|
111
|
-
const actions = await clientActions;
|
|
112
|
-
completion.catch((err) => console.warn("[Nextlytics] Dispatch completion error:", err));
|
|
113
|
-
const scripts = actions.items.filter((i) => i.type === "script-template");
|
|
114
|
-
return Response.json({ ok: true, scripts: scripts.length > 0 ? scripts : void 0 });
|
|
115
|
-
}
|
|
116
|
-
return Response.json({ ok: true });
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
121
|
-
0 && (module.exports = {
|
|
122
|
-
createHandlers
|
|
123
|
-
});
|
package/dist/handlers.d.mts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { NextRequest } from 'next/server';
|
|
2
|
-
import { NextlyticsEvent, RequestContext, DispatchResult } from './types.mjs';
|
|
3
|
-
import { NextlyticsConfigWithDefaults } from './config-helpers.mjs';
|
|
4
|
-
import 'next/dist/server/web/spec-extension/cookies';
|
|
5
|
-
|
|
6
|
-
type AppRouteHandlers = Record<"GET" | "POST", (req: NextRequest) => Promise<Response>>;
|
|
7
|
-
declare function createHandlers(config: NextlyticsConfigWithDefaults, dispatchEvent: (event: NextlyticsEvent, ctx: RequestContext) => DispatchResult, updateEvent: (eventId: string, patch: Partial<NextlyticsEvent>, ctx: RequestContext) => Promise<void>): AppRouteHandlers;
|
|
8
|
-
|
|
9
|
-
export { createHandlers };
|
package/dist/headers.cjs
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
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 headers_exports = {};
|
|
20
|
-
__export(headers_exports, {
|
|
21
|
-
removeSensitiveHeaders: () => removeSensitiveHeaders
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(headers_exports);
|
|
24
|
-
const SENSITIVE_HEADERS = /* @__PURE__ */ new Set(["cookie", "set-cookie", "authorization", "proxy-authorization"]);
|
|
25
|
-
const SENSITIVE_PATTERNS = /auth|token|key|secret|password|credential|session/i;
|
|
26
|
-
function removeSensitiveHeaders(requestHeaders) {
|
|
27
|
-
const result = {};
|
|
28
|
-
for (const [key, value] of Object.entries(requestHeaders)) {
|
|
29
|
-
const lowerKey = key.toLowerCase();
|
|
30
|
-
if (SENSITIVE_HEADERS.has(lowerKey) || SENSITIVE_PATTERNS.test(lowerKey)) {
|
|
31
|
-
result[key] = `[redacted, len ${value.length}]`;
|
|
32
|
-
} else {
|
|
33
|
-
result[key] = value;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return result;
|
|
37
|
-
}
|
|
38
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
39
|
-
0 && (module.exports = {
|
|
40
|
-
removeSensitiveHeaders
|
|
41
|
-
});
|
package/dist/headers.d.mts
DELETED
package/dist/index.cjs
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
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 index_exports = {};
|
|
20
|
-
__export(index_exports, {
|
|
21
|
-
Nextlytics: () => import_server.Nextlytics,
|
|
22
|
-
NextlyticsClient: () => import_client.NextlyticsClient,
|
|
23
|
-
NextlyticsServer: () => import_server.NextlyticsServer,
|
|
24
|
-
getNextlyticsProps: () => import_pages_router.getNextlyticsProps,
|
|
25
|
-
loggingBackend: () => import_logging.loggingBackend,
|
|
26
|
-
useNextlytics: () => import_client.useNextlytics
|
|
27
|
-
});
|
|
28
|
-
module.exports = __toCommonJS(index_exports);
|
|
29
|
-
var import_server = require("./server");
|
|
30
|
-
var import_client = require("./client");
|
|
31
|
-
var import_pages_router = require("./pages-router");
|
|
32
|
-
var import_logging = require("./backends/logging");
|
|
33
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
34
|
-
0 && (module.exports = {
|
|
35
|
-
Nextlytics,
|
|
36
|
-
NextlyticsClient,
|
|
37
|
-
NextlyticsServer,
|
|
38
|
-
getNextlyticsProps,
|
|
39
|
-
loggingBackend,
|
|
40
|
-
useNextlytics
|
|
41
|
-
});
|
package/dist/index.d.mts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export { Nextlytics, NextlyticsServer } from './server.mjs';
|
|
2
|
-
export { NextlyticsClient, NextlyticsContext, useNextlytics } from './client.mjs';
|
|
3
|
-
export { getNextlyticsProps } from './pages-router.mjs';
|
|
4
|
-
export { loggingBackend } from './backends/logging.mjs';
|
|
5
|
-
export { AnonymousUserResult, ClientContext, NextlyticsBackend, NextlyticsBackendFactory, NextlyticsConfig, NextlyticsEvent, NextlyticsPlugin, NextlyticsPluginFactory, NextlyticsResult, NextlyticsServerSide, RequestContext, ServerEventContext, UserContext } from './types.mjs';
|
|
6
|
-
import 'react/jsx-runtime';
|
|
7
|
-
import 'react';
|
|
8
|
-
import 'next/dist/server/web/spec-extension/cookies';
|
|
9
|
-
import 'next/server';
|