@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/anonymous-user.js
CHANGED
|
@@ -1,3 +1,26 @@
|
|
|
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 anonymous_user_exports = {};
|
|
20
|
+
__export(anonymous_user_exports, {
|
|
21
|
+
resolveAnonymousUser: () => resolveAnonymousUser
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(anonymous_user_exports);
|
|
1
24
|
const BASE62_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
2
25
|
const ANON_ID_LENGTH = 10;
|
|
3
26
|
const DEFAULTS = {
|
|
@@ -89,6 +112,7 @@ async function resolveAnonymousUser(params) {
|
|
|
89
112
|
}
|
|
90
113
|
return { anonId };
|
|
91
114
|
}
|
|
92
|
-
export
|
|
115
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
116
|
+
0 && (module.exports = {
|
|
93
117
|
resolveAnonymousUser
|
|
94
|
-
};
|
|
118
|
+
});
|
|
@@ -1,10 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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 clickhouse_exports = {};
|
|
20
|
+
__export(clickhouse_exports, {
|
|
21
|
+
clickhouseBackend: () => clickhouseBackend
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(clickhouse_exports);
|
|
24
|
+
var import_db = require("./lib/db");
|
|
8
25
|
function clickhouseBackend(config) {
|
|
9
26
|
const baseUrl = config.url.replace(/\/$/, "");
|
|
10
27
|
const database = config.database ?? "default";
|
|
@@ -16,7 +33,7 @@ function clickhouseBackend(config) {
|
|
|
16
33
|
function printCreateTableStatement() {
|
|
17
34
|
console.error(`[Nextlytics ClickHouse] Table "${database}.${table}" does not exist. Run:
|
|
18
35
|
`);
|
|
19
|
-
console.error(generateChCreateTableSQL(database, table));
|
|
36
|
+
console.error((0, import_db.generateChCreateTableSQL)(database, table));
|
|
20
37
|
}
|
|
21
38
|
async function query(sql) {
|
|
22
39
|
const params = new URLSearchParams({
|
|
@@ -54,7 +71,7 @@ function clickhouseBackend(config) {
|
|
|
54
71
|
});
|
|
55
72
|
if (!res.ok) {
|
|
56
73
|
const text = await res.text();
|
|
57
|
-
if (isChTableNotFoundError(text)) {
|
|
74
|
+
if ((0, import_db.isChTableNotFoundError)(text)) {
|
|
58
75
|
printCreateTableStatement();
|
|
59
76
|
}
|
|
60
77
|
throw new Error(`ClickHouse error ${res.status}: ${text}`);
|
|
@@ -64,18 +81,18 @@ function clickhouseBackend(config) {
|
|
|
64
81
|
name: "clickhouse",
|
|
65
82
|
supportsUpdates: acceptUpdates,
|
|
66
83
|
async onEvent(event) {
|
|
67
|
-
const row = eventToJsonRow(event);
|
|
84
|
+
const row = (0, import_db.eventToJsonRow)(event);
|
|
68
85
|
await insert(row);
|
|
69
86
|
},
|
|
70
87
|
async updateEvent(eventId, patch) {
|
|
71
88
|
if (!acceptUpdates || !patch.clientContext) return;
|
|
72
|
-
const cols = tableColumns.map((c) => c.name).join(", ");
|
|
89
|
+
const cols = import_db.tableColumns.map((c) => c.name).join(", ");
|
|
73
90
|
const rows = await query(
|
|
74
91
|
`SELECT ${cols} FROM ${table} WHERE event_id = '${eventId}' AND timestamp > now() - INTERVAL ${updateLookbackMinutes} MINUTE FORMAT JSONEachRow`
|
|
75
92
|
);
|
|
76
93
|
if (rows.length === 0) return;
|
|
77
94
|
const existing = rows[0];
|
|
78
|
-
const clientCtx = extractClientContext(patch.clientContext);
|
|
95
|
+
const clientCtx = (0, import_db.extractClientContext)(patch.clientContext);
|
|
79
96
|
const updated = {
|
|
80
97
|
...existing,
|
|
81
98
|
referer: clientCtx.referer ?? existing.referer,
|
|
@@ -87,6 +104,7 @@ function clickhouseBackend(config) {
|
|
|
87
104
|
}
|
|
88
105
|
};
|
|
89
106
|
}
|
|
90
|
-
export
|
|
107
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
108
|
+
0 && (module.exports = {
|
|
91
109
|
clickhouseBackend
|
|
92
|
-
};
|
|
110
|
+
});
|
package/dist/backends/ga.js
CHANGED
|
@@ -1,3 +1,26 @@
|
|
|
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 ga_exports = {};
|
|
20
|
+
__export(ga_exports, {
|
|
21
|
+
googleAnalyticsBackend: () => googleAnalyticsBackend
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(ga_exports);
|
|
1
24
|
const GA_TEMPLATE_ID = "ga-gtag";
|
|
2
25
|
function parseGaCookie(cookieValue) {
|
|
3
26
|
const match = cookieValue.match(/^GA\d+\.\d+\.(.+)$/);
|
|
@@ -178,6 +201,7 @@ function googleAnalyticsBackend(opts) {
|
|
|
178
201
|
};
|
|
179
202
|
};
|
|
180
203
|
}
|
|
181
|
-
export
|
|
204
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
205
|
+
0 && (module.exports = {
|
|
182
206
|
googleAnalyticsBackend
|
|
183
|
-
};
|
|
207
|
+
});
|
package/dist/backends/gtm.js
CHANGED
|
@@ -1,3 +1,26 @@
|
|
|
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 gtm_exports = {};
|
|
20
|
+
__export(gtm_exports, {
|
|
21
|
+
googleTagManagerBackend: () => googleTagManagerBackend
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(gtm_exports);
|
|
1
24
|
const GTM_INIT_TEMPLATE_ID = "gtm-init";
|
|
2
25
|
const GTM_PAGEVIEW_TEMPLATE_ID = "gtm-pageview";
|
|
3
26
|
const GTM_EVENT_TEMPLATE_ID = "gtm-event";
|
|
@@ -126,6 +149,7 @@ function googleTagManagerBackend(opts) {
|
|
|
126
149
|
}
|
|
127
150
|
};
|
|
128
151
|
}
|
|
129
|
-
export
|
|
152
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
153
|
+
0 && (module.exports = {
|
|
130
154
|
googleTagManagerBackend
|
|
131
|
-
};
|
|
155
|
+
});
|
package/dist/backends/lib/db.js
CHANGED
|
@@ -1,3 +1,33 @@
|
|
|
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 db_exports = {};
|
|
20
|
+
__export(db_exports, {
|
|
21
|
+
eventToJsonRow: () => eventToJsonRow,
|
|
22
|
+
eventToRow: () => eventToRow,
|
|
23
|
+
extractClientContext: () => extractClientContext,
|
|
24
|
+
generateChCreateTableSQL: () => generateChCreateTableSQL,
|
|
25
|
+
generatePgCreateTableSQL: () => generatePgCreateTableSQL,
|
|
26
|
+
isChTableNotFoundError: () => isChTableNotFoundError,
|
|
27
|
+
isPgTableNotFoundError: () => isPgTableNotFoundError,
|
|
28
|
+
tableColumns: () => tableColumns
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(db_exports);
|
|
1
31
|
const tableColumns = [
|
|
2
32
|
{ name: "event_id", pgType: "TEXT PRIMARY KEY", chType: "String" },
|
|
3
33
|
{ name: "parent_event_id", pgType: "TEXT", chType: "Nullable(String)" },
|
|
@@ -107,7 +137,8 @@ ${alters}`;
|
|
|
107
137
|
function isChTableNotFoundError(text) {
|
|
108
138
|
return text.includes("UNKNOWN_TABLE") || text.includes("doesn't exist");
|
|
109
139
|
}
|
|
110
|
-
export
|
|
140
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
141
|
+
0 && (module.exports = {
|
|
111
142
|
eventToJsonRow,
|
|
112
143
|
eventToRow,
|
|
113
144
|
extractClientContext,
|
|
@@ -116,4 +147,4 @@ export {
|
|
|
116
147
|
isChTableNotFoundError,
|
|
117
148
|
isPgTableNotFoundError,
|
|
118
149
|
tableColumns
|
|
119
|
-
};
|
|
150
|
+
});
|
package/dist/backends/logging.js
CHANGED
|
@@ -1,3 +1,26 @@
|
|
|
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 logging_exports = {};
|
|
20
|
+
__export(logging_exports, {
|
|
21
|
+
loggingBackend: () => loggingBackend
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(logging_exports);
|
|
1
24
|
function loggingBackend() {
|
|
2
25
|
return {
|
|
3
26
|
name: "logging",
|
|
@@ -16,6 +39,7 @@ function loggingBackend() {
|
|
|
16
39
|
}
|
|
17
40
|
};
|
|
18
41
|
}
|
|
19
|
-
export
|
|
42
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
43
|
+
0 && (module.exports = {
|
|
20
44
|
loggingBackend
|
|
21
|
-
};
|
|
45
|
+
});
|
package/dist/backends/neon.js
CHANGED
|
@@ -1,32 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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 neon_exports = {};
|
|
20
|
+
__export(neon_exports, {
|
|
21
|
+
neonBackend: () => neonBackend
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(neon_exports);
|
|
24
|
+
var import_serverless = require("@neondatabase/serverless");
|
|
25
|
+
var import_db = require("./lib/db");
|
|
9
26
|
function neonBackend(config) {
|
|
10
|
-
const sql = neon(config.databaseUrl);
|
|
27
|
+
const sql = (0, import_serverless.neon)(config.databaseUrl);
|
|
11
28
|
const table = config.tableName ?? "analytics";
|
|
12
29
|
function printCreateTableStatement() {
|
|
13
30
|
console.error(`[Nextlytics Neon] Table "${table}" does not exist. Run this SQL:
|
|
14
31
|
`);
|
|
15
|
-
console.error(generatePgCreateTableSQL(table));
|
|
32
|
+
console.error((0, import_db.generatePgCreateTableSQL)(table));
|
|
16
33
|
}
|
|
17
34
|
return {
|
|
18
35
|
name: "neon",
|
|
19
36
|
supportsUpdates: true,
|
|
20
37
|
async onEvent(event) {
|
|
21
|
-
const values = eventToRow(event);
|
|
22
|
-
const cols = tableColumns.map((c) => c.name).join(", ");
|
|
23
|
-
const placeholders = tableColumns.map((_, i) => `$${i + 1}`).join(", ");
|
|
38
|
+
const values = (0, import_db.eventToRow)(event);
|
|
39
|
+
const cols = import_db.tableColumns.map((c) => c.name).join(", ");
|
|
40
|
+
const placeholders = import_db.tableColumns.map((_, i) => `$${i + 1}`).join(", ");
|
|
24
41
|
try {
|
|
25
|
-
await sql(`INSERT INTO ${table} (${cols}) VALUES (${placeholders})`, [
|
|
26
|
-
...tableColumns.map((c) => values[c.name])
|
|
42
|
+
await sql.query(`INSERT INTO ${table} (${cols}) VALUES (${placeholders})`, [
|
|
43
|
+
...import_db.tableColumns.map((c) => values[c.name])
|
|
27
44
|
]);
|
|
28
45
|
} catch (err) {
|
|
29
|
-
if (isPgTableNotFoundError(err)) {
|
|
46
|
+
if ((0, import_db.isPgTableNotFoundError)(err)) {
|
|
30
47
|
printCreateTableStatement();
|
|
31
48
|
}
|
|
32
49
|
throw err;
|
|
@@ -37,7 +54,7 @@ function neonBackend(config) {
|
|
|
37
54
|
const params = [];
|
|
38
55
|
let paramIndex = 1;
|
|
39
56
|
if (patch.clientContext) {
|
|
40
|
-
const clientCtx = extractClientContext(patch.clientContext);
|
|
57
|
+
const clientCtx = (0, import_db.extractClientContext)(patch.clientContext);
|
|
41
58
|
const columns = {
|
|
42
59
|
referer: clientCtx.referer,
|
|
43
60
|
user_agent: clientCtx.user_agent,
|
|
@@ -56,11 +73,15 @@ function neonBackend(config) {
|
|
|
56
73
|
}
|
|
57
74
|
if (sets.length > 0) {
|
|
58
75
|
params.push(eventId);
|
|
59
|
-
await sql
|
|
76
|
+
await sql.query(
|
|
77
|
+
`UPDATE ${table} SET ${sets.join(", ")} WHERE event_id = $${paramIndex}`,
|
|
78
|
+
params
|
|
79
|
+
);
|
|
60
80
|
}
|
|
61
81
|
}
|
|
62
82
|
};
|
|
63
83
|
}
|
|
64
|
-
export
|
|
84
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
85
|
+
0 && (module.exports = {
|
|
65
86
|
neonBackend
|
|
66
|
-
};
|
|
87
|
+
});
|
|
@@ -1,5 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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 postgrest_exports = {};
|
|
20
|
+
__export(postgrest_exports, {
|
|
21
|
+
generatePgCreateTableSQL: () => import_db2.generatePgCreateTableSQL,
|
|
22
|
+
postgrestBackend: () => postgrestBackend
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(postgrest_exports);
|
|
25
|
+
var import_db = require("./lib/db");
|
|
26
|
+
var import_db2 = require("./lib/db");
|
|
3
27
|
function postgrestBackend(config) {
|
|
4
28
|
const table = config.tableName ?? "analytics";
|
|
5
29
|
const baseUrl = config.url.replace(/\/$/, "");
|
|
@@ -17,7 +41,7 @@ function postgrestBackend(config) {
|
|
|
17
41
|
function printCreateTableStatement() {
|
|
18
42
|
console.error(`[Nextlytics PostgREST] Table "${table}" does not exist. Run this SQL:
|
|
19
43
|
`);
|
|
20
|
-
console.error(generatePgCreateTableSQL(table));
|
|
44
|
+
console.error((0, import_db.generatePgCreateTableSQL)(table));
|
|
21
45
|
}
|
|
22
46
|
async function handleResponse(res) {
|
|
23
47
|
if (!res.ok) {
|
|
@@ -32,7 +56,7 @@ function postgrestBackend(config) {
|
|
|
32
56
|
name: "postgrest",
|
|
33
57
|
supportsUpdates: true,
|
|
34
58
|
async onEvent(event) {
|
|
35
|
-
const row = eventToJsonRow(event);
|
|
59
|
+
const row = (0, import_db.eventToJsonRow)(event);
|
|
36
60
|
const res = await fetch(`${baseUrl}/${table}`, {
|
|
37
61
|
method: "POST",
|
|
38
62
|
headers: headers(),
|
|
@@ -43,7 +67,7 @@ function postgrestBackend(config) {
|
|
|
43
67
|
async updateEvent(eventId, patch) {
|
|
44
68
|
const updates = {};
|
|
45
69
|
if (patch.clientContext) {
|
|
46
|
-
const clientCtx = extractClientContext(patch.clientContext);
|
|
70
|
+
const clientCtx = (0, import_db.extractClientContext)(patch.clientContext);
|
|
47
71
|
if (clientCtx.referer !== void 0) updates.referer = clientCtx.referer;
|
|
48
72
|
if (clientCtx.user_agent !== void 0) updates.user_agent = clientCtx.user_agent;
|
|
49
73
|
if (clientCtx.locale !== void 0) updates.locale = clientCtx.locale;
|
|
@@ -67,7 +91,8 @@ function postgrestBackend(config) {
|
|
|
67
91
|
}
|
|
68
92
|
};
|
|
69
93
|
}
|
|
70
|
-
export
|
|
71
|
-
|
|
94
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
95
|
+
0 && (module.exports = {
|
|
96
|
+
generatePgCreateTableSQL,
|
|
72
97
|
postgrestBackend
|
|
73
|
-
};
|
|
98
|
+
});
|
package/dist/backends/posthog.js
CHANGED
|
@@ -1,3 +1,26 @@
|
|
|
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 posthog_exports = {};
|
|
20
|
+
__export(posthog_exports, {
|
|
21
|
+
posthogBackend: () => posthogBackend
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(posthog_exports);
|
|
1
24
|
function posthogBackend(opts) {
|
|
2
25
|
const host = (opts.host ?? "https://app.posthog.com").replace(/\/$/, "");
|
|
3
26
|
const apiKey = opts.apiKey;
|
|
@@ -91,6 +114,7 @@ function posthogBackend(opts) {
|
|
|
91
114
|
}
|
|
92
115
|
};
|
|
93
116
|
}
|
|
94
|
-
export
|
|
117
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
118
|
+
0 && (module.exports = {
|
|
95
119
|
posthogBackend
|
|
96
|
-
};
|
|
120
|
+
});
|
package/dist/backends/segment.js
CHANGED
|
@@ -1,3 +1,26 @@
|
|
|
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 segment_exports = {};
|
|
20
|
+
__export(segment_exports, {
|
|
21
|
+
segmentBackend: () => segmentBackend
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(segment_exports);
|
|
1
24
|
function segmentBackend(config) {
|
|
2
25
|
const host = (config.host ?? "https://api.segment.io").replace(/\/$/, "");
|
|
3
26
|
const authHeader = "Basic " + btoa(config.writeKey + ":");
|
|
@@ -83,6 +106,7 @@ function segmentBackend(config) {
|
|
|
83
106
|
}
|
|
84
107
|
};
|
|
85
108
|
}
|
|
86
|
-
export
|
|
109
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
110
|
+
0 && (module.exports = {
|
|
87
111
|
segmentBackend
|
|
88
|
-
};
|
|
112
|
+
});
|
package/dist/client.js
CHANGED
|
@@ -1,14 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
"use client";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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");
|
|
6
30
|
const templateFunctions = {
|
|
7
31
|
q: (v) => JSON.stringify(v ?? null),
|
|
8
32
|
json: (v) => JSON.stringify(v ?? null)
|
|
9
33
|
};
|
|
10
34
|
const compiledCache = {};
|
|
11
|
-
const NextlyticsContext = createContext(null);
|
|
35
|
+
const NextlyticsContext = (0, import_react.createContext)(null);
|
|
12
36
|
function createClientContext() {
|
|
13
37
|
const isBrowser = typeof window !== "undefined";
|
|
14
38
|
return {
|
|
@@ -30,8 +54,8 @@ function getCompiledTemplate(templateId, itemIndex, item) {
|
|
|
30
54
|
const cacheKey = `${templateId}:${itemIndex}`;
|
|
31
55
|
if (!compiledCache[cacheKey]) {
|
|
32
56
|
compiledCache[cacheKey] = {
|
|
33
|
-
src: item.src ? compile(item.src) : void 0,
|
|
34
|
-
body: item.body ? compile(item.body) : void 0
|
|
57
|
+
src: item.src ? (0, import_template.compile)(item.src) : void 0,
|
|
58
|
+
body: item.body ? (0, import_template.compile)(item.body) : void 0
|
|
35
59
|
};
|
|
36
60
|
}
|
|
37
61
|
return compiledCache[cacheKey];
|
|
@@ -52,7 +76,7 @@ function executeTemplatedScripts(scripts, templates) {
|
|
|
52
76
|
for (let i = 0; i < template.items.length; i++) {
|
|
53
77
|
const item = template.items[i];
|
|
54
78
|
const compiled = getCompiledTemplate(script.templateId, i, item);
|
|
55
|
-
const src = compiled.src ? apply(compiled.src, params, templateFunctions) : void 0;
|
|
79
|
+
const src = compiled.src ? (0, import_template.apply)(compiled.src, params, templateFunctions) : void 0;
|
|
56
80
|
if (item.singleton && src && document.querySelector(`script[src="${src}"]`)) {
|
|
57
81
|
continue;
|
|
58
82
|
}
|
|
@@ -61,7 +85,7 @@ function executeTemplatedScripts(scripts, templates) {
|
|
|
61
85
|
el.src = src;
|
|
62
86
|
}
|
|
63
87
|
if (compiled.body) {
|
|
64
|
-
el.textContent = apply(compiled.body, params, templateFunctions);
|
|
88
|
+
el.textContent = (0, import_template.apply)(compiled.body, params, templateFunctions);
|
|
65
89
|
}
|
|
66
90
|
if (item.async) {
|
|
67
91
|
el.async = true;
|
|
@@ -76,7 +100,7 @@ async function sendEvent(requestId, type, payload) {
|
|
|
76
100
|
method: "POST",
|
|
77
101
|
headers: {
|
|
78
102
|
"Content-Type": "application/json",
|
|
79
|
-
[headers.pageRenderId]: requestId
|
|
103
|
+
[import_server_component_context.headers.pageRenderId]: requestId
|
|
80
104
|
},
|
|
81
105
|
body: JSON.stringify({ type, payload })
|
|
82
106
|
});
|
|
@@ -98,7 +122,7 @@ function NextlyticsClient(props) {
|
|
|
98
122
|
const requestId = props.ctx?.requestId ?? props.requestId ?? "";
|
|
99
123
|
const scripts = props.ctx?.scripts ?? props.scripts;
|
|
100
124
|
const templates = props.ctx?.templates ?? props.templates ?? {};
|
|
101
|
-
useEffect(() => {
|
|
125
|
+
(0, import_react.useEffect)(() => {
|
|
102
126
|
if (initializedRequestIds.has(requestId)) return;
|
|
103
127
|
initializedRequestIds.add(requestId);
|
|
104
128
|
if (scripts && Object.keys(templates).length > 0) {
|
|
@@ -113,17 +137,17 @@ function NextlyticsClient(props) {
|
|
|
113
137
|
}
|
|
114
138
|
);
|
|
115
139
|
}, [requestId, scripts, templates]);
|
|
116
|
-
return /* @__PURE__ */ jsx(NextlyticsContext.Provider, { value: { requestId, templates }, children: props.children });
|
|
140
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(NextlyticsContext.Provider, { value: { requestId, templates }, children: props.children });
|
|
117
141
|
}
|
|
118
142
|
function useNextlytics() {
|
|
119
|
-
const context = useContext(NextlyticsContext);
|
|
143
|
+
const context = (0, import_react.useContext)(NextlyticsContext);
|
|
120
144
|
if (!context) {
|
|
121
145
|
throw new Error(
|
|
122
146
|
"[Nextlytics] useNextlytics() must be used within a component wrapped by <NextlyticsServer>. Add <NextlyticsServer> at the top of your layout.tsx file."
|
|
123
147
|
);
|
|
124
148
|
}
|
|
125
149
|
const { requestId, templates } = context;
|
|
126
|
-
const send = useCallback(
|
|
150
|
+
const send = (0, import_react.useCallback)(
|
|
127
151
|
async (eventName, opts) => {
|
|
128
152
|
const result = await sendEvent(requestId, "client-event", {
|
|
129
153
|
name: eventName,
|
|
@@ -140,7 +164,8 @@ function useNextlytics() {
|
|
|
140
164
|
);
|
|
141
165
|
return { sendEvent: send };
|
|
142
166
|
}
|
|
143
|
-
export
|
|
167
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
168
|
+
0 && (module.exports = {
|
|
144
169
|
NextlyticsClient,
|
|
145
170
|
useNextlytics
|
|
146
|
-
};
|
|
171
|
+
});
|