@koryla/node 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +4 -2
- package/dist/index.js +5 -3
- package/package.json +7 -7
package/dist/index.cjs
CHANGED
|
@@ -66,14 +66,16 @@ async function trackConversion(req, options) {
|
|
|
66
66
|
);
|
|
67
67
|
const sessionId = cookies["ky_sid"];
|
|
68
68
|
if (!sessionId) return;
|
|
69
|
+
const distinctId = (0, import_core.posthogDistinctId)(cookies);
|
|
70
|
+
const host = (0, import_core.hostFromUrl)(`http://${req.headers["x-forwarded-host"] ?? req.headers["host"] ?? ""}`);
|
|
69
71
|
for (const [key, value] of Object.entries(cookies)) {
|
|
70
72
|
if (!key.startsWith("ky_") || key === "ky_sid") continue;
|
|
71
73
|
const experimentId = key.slice(3);
|
|
72
74
|
try {
|
|
73
75
|
await fetch(`${options.apiUrl}/api/worker/event`, {
|
|
74
76
|
method: "POST",
|
|
75
|
-
headers: { "Content-Type": "application/json", Authorization: `Bearer ${options.apiKey}
|
|
76
|
-
body: JSON.stringify({ experiment_id: experimentId, variant_id: value, session_id: sessionId, event_type: "conversion" })
|
|
77
|
+
headers: { "Content-Type": "application/json", Authorization: `Bearer ${options.apiKey}`, ...(0, import_core.hostHeader)(host) },
|
|
78
|
+
body: JSON.stringify({ experiment_id: experimentId, variant_id: value, session_id: sessionId, event_type: "conversion", distinct_id: distinctId })
|
|
77
79
|
});
|
|
78
80
|
} catch {
|
|
79
81
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import { createSplitEngine } from "@koryla/core";
|
|
2
|
+
import { createSplitEngine, hostFromUrl, hostHeader, posthogDistinctId } from "@koryla/core";
|
|
3
3
|
var engine = null;
|
|
4
4
|
function korylaMiddleware(options) {
|
|
5
5
|
return async function middleware(req, res, next) {
|
|
@@ -41,14 +41,16 @@ async function trackConversion(req, options) {
|
|
|
41
41
|
);
|
|
42
42
|
const sessionId = cookies["ky_sid"];
|
|
43
43
|
if (!sessionId) return;
|
|
44
|
+
const distinctId = posthogDistinctId(cookies);
|
|
45
|
+
const host = hostFromUrl(`http://${req.headers["x-forwarded-host"] ?? req.headers["host"] ?? ""}`);
|
|
44
46
|
for (const [key, value] of Object.entries(cookies)) {
|
|
45
47
|
if (!key.startsWith("ky_") || key === "ky_sid") continue;
|
|
46
48
|
const experimentId = key.slice(3);
|
|
47
49
|
try {
|
|
48
50
|
await fetch(`${options.apiUrl}/api/worker/event`, {
|
|
49
51
|
method: "POST",
|
|
50
|
-
headers: { "Content-Type": "application/json", Authorization: `Bearer ${options.apiKey}
|
|
51
|
-
body: JSON.stringify({ experiment_id: experimentId, variant_id: value, session_id: sessionId, event_type: "conversion" })
|
|
52
|
+
headers: { "Content-Type": "application/json", Authorization: `Bearer ${options.apiKey}`, ...hostHeader(host) },
|
|
53
|
+
body: JSON.stringify({ experiment_id: experimentId, variant_id: value, session_id: sessionId, event_type: "conversion", distinct_id: distinctId })
|
|
52
54
|
});
|
|
53
55
|
} catch {
|
|
54
56
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koryla/node",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -18,15 +18,15 @@
|
|
|
18
18
|
"publishConfig": {
|
|
19
19
|
"access": "public"
|
|
20
20
|
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsup src/index.ts --format esm,cjs --dts --clean",
|
|
23
|
+
"dev": "tsup src/index.ts --format esm,cjs --dts --watch"
|
|
24
|
+
},
|
|
21
25
|
"dependencies": {
|
|
22
|
-
"@koryla/core": "^0.2.
|
|
26
|
+
"@koryla/core": "^0.2.7"
|
|
23
27
|
},
|
|
24
28
|
"devDependencies": {
|
|
25
29
|
"tsup": "^8.0.0",
|
|
26
30
|
"typescript": "^5"
|
|
27
|
-
},
|
|
28
|
-
"scripts": {
|
|
29
|
-
"build": "tsup src/index.ts --format esm,cjs --dts --clean",
|
|
30
|
-
"dev": "tsup src/index.ts --format esm,cjs --dts --watch"
|
|
31
31
|
}
|
|
32
|
-
}
|
|
32
|
+
}
|