@reopt-ai/data-contract 0.6.3 → 0.7.0
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/client.cjs +228 -321
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +57 -71
- package/dist/client.d.cts.map +1 -0
- package/dist/client.d.ts +57 -71
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +228 -322
- package/dist/client.js.map +1 -1
- package/dist/control.cjs +158 -54
- package/dist/control.cjs.map +1 -1
- package/dist/control.d.cts +121 -137
- package/dist/control.d.cts.map +1 -0
- package/dist/control.d.ts +121 -137
- package/dist/control.d.ts.map +1 -0
- package/dist/control.js +134 -54
- package/dist/control.js.map +1 -1
- package/dist/events-BUIeU60t.d.cts +142 -0
- package/dist/events-BUIeU60t.d.cts.map +1 -0
- package/dist/events-BUIeU60t.d.ts +142 -0
- package/dist/events-BUIeU60t.d.ts.map +1 -0
- package/dist/events.cjs +110 -15
- package/dist/events.cjs.map +1 -1
- package/dist/events.d.cts +2 -59
- package/dist/events.d.ts +2 -59
- package/dist/events.js +101 -15
- package/dist/events.js.map +1 -1
- package/dist/identity.cjs +150 -55
- package/dist/identity.cjs.map +1 -1
- package/dist/identity.d.cts +21 -20
- package/dist/identity.d.cts.map +1 -0
- package/dist/identity.d.ts +21 -20
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +126 -56
- package/dist/identity.js.map +1 -1
- package/dist/index.cjs +46 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +37 -54
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +37 -54
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +36 -25
- package/dist/index.js.map +1 -1
- package/dist/ingest.cjs +152 -57
- package/dist/ingest.cjs.map +1 -1
- package/dist/ingest.d.cts +182 -193
- package/dist/ingest.d.cts.map +1 -0
- package/dist/ingest.d.ts +182 -193
- package/dist/ingest.d.ts.map +1 -0
- package/dist/ingest.js +126 -57
- package/dist/ingest.js.map +1 -1
- package/dist/query.cjs +284 -84
- package/dist/query.cjs.map +1 -1
- package/dist/query.d.cts +456 -469
- package/dist/query.d.cts.map +1 -0
- package/dist/query.d.ts +456 -469
- package/dist/query.d.ts.map +1 -0
- package/dist/query.js +245 -84
- package/dist/query.js.map +1 -1
- package/dist/report.cjs +104 -74
- package/dist/report.cjs.map +1 -1
- package/dist/report.d.cts +182 -136
- package/dist/report.d.cts.map +1 -0
- package/dist/report.d.ts +182 -136
- package/dist/report.d.ts.map +1 -0
- package/dist/report.js +93 -74
- package/dist/report.js.map +1 -1
- package/dist/version-B_0qb1_K.cjs +53 -0
- package/dist/version-B_0qb1_K.cjs.map +1 -0
- package/dist/version-C09Cyf4R.js +12 -0
- package/dist/version-C09Cyf4R.js.map +1 -0
- package/dist/{version-DJ2Grb_N.d.ts → version-CGujUGWd.d.cts} +5 -3
- package/dist/version-CGujUGWd.d.cts.map +1 -0
- package/dist/{version-DJ2Grb_N.d.cts → version-CGujUGWd.d.ts} +5 -3
- package/dist/version-CGujUGWd.d.ts.map +1 -0
- package/package.json +69 -28
- package/dist/chunk-3EEANNYN.cjs +0 -62
- package/dist/chunk-3EEANNYN.cjs.map +0 -1
- package/dist/chunk-7W33YGRO.js +0 -160
- package/dist/chunk-7W33YGRO.js.map +0 -1
- package/dist/chunk-F2RNXJGO.cjs +0 -19
- package/dist/chunk-F2RNXJGO.cjs.map +0 -1
- package/dist/chunk-FP2X3PRK.js +0 -62
- package/dist/chunk-FP2X3PRK.js.map +0 -1
- package/dist/chunk-JCEWUSUM.js +0 -53
- package/dist/chunk-JCEWUSUM.js.map +0 -1
- package/dist/chunk-L3JPDRVG.cjs +0 -160
- package/dist/chunk-L3JPDRVG.cjs.map +0 -1
- package/dist/chunk-L4KBQAOO.js +0 -204
- package/dist/chunk-L4KBQAOO.js.map +0 -1
- package/dist/chunk-NJ4JKNBX.js +0 -361
- package/dist/chunk-NJ4JKNBX.js.map +0 -1
- package/dist/chunk-ORNTN6AK.cjs +0 -53
- package/dist/chunk-ORNTN6AK.cjs.map +0 -1
- package/dist/chunk-PSUINLW7.js +0 -19
- package/dist/chunk-PSUINLW7.js.map +0 -1
- package/dist/chunk-RU26QFM2.js +0 -179
- package/dist/chunk-RU26QFM2.js.map +0 -1
- package/dist/chunk-XDH5QQYF.cjs +0 -361
- package/dist/chunk-XDH5QQYF.cjs.map +0 -1
- package/dist/chunk-YCTGHWTP.cjs +0 -204
- package/dist/chunk-YCTGHWTP.cjs.map +0 -1
- package/dist/chunk-ZI6A3WQP.cjs +0 -179
- package/dist/chunk-ZI6A3WQP.cjs.map +0 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//#region src/version.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* Wire version and header names — the part of the contract every party
|
|
3
4
|
* needs and none of them should pay zod for. Both `.` and `./identity`
|
|
@@ -13,7 +14,7 @@
|
|
|
13
14
|
* every publish is a wire bump: consumers that check for exact equality —
|
|
14
15
|
* every SDK — must upgrade in lockstep with the server.
|
|
15
16
|
*/
|
|
16
|
-
declare const CONTRACT_VERSION = "0.
|
|
17
|
+
declare const CONTRACT_VERSION = "0.7.0";
|
|
17
18
|
/** Response header carrying the server's contract version. */
|
|
18
19
|
declare const CONTRACT_VERSION_HEADER = "x-reopt-contract-version";
|
|
19
20
|
/** Request header names shared by the ingest and query planes. */
|
|
@@ -22,5 +23,6 @@ declare const CLIENT_SECRET_HEADER = "reopt-client-secret";
|
|
|
22
23
|
declare const WRITE_KEY_HEADER = "reopt-write-key";
|
|
23
24
|
declare const DEVICE_ID_HEADER = "reopt-device-id";
|
|
24
25
|
declare const REQUEST_ID_HEADER = "x-request-id";
|
|
25
|
-
|
|
26
|
-
export {
|
|
26
|
+
//#endregion
|
|
27
|
+
export { DEVICE_ID_HEADER as a, CONTRACT_VERSION_HEADER as i, CLIENT_SECRET_HEADER as n, REQUEST_ID_HEADER as o, CONTRACT_VERSION as r, WRITE_KEY_HEADER as s, CLIENT_ID_HEADER as t };
|
|
28
|
+
//# sourceMappingURL=version-CGujUGWd.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version-CGujUGWd.d.cts","names":[],"sources":["../src/version.ts"],"mappings":";;;;;;;;;;;;;;;;cAgBa;;cAGA;;cAGA;cACA;cACA;cACA;cACA"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//#region src/version.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* Wire version and header names — the part of the contract every party
|
|
3
4
|
* needs and none of them should pay zod for. Both `.` and `./identity`
|
|
@@ -13,7 +14,7 @@
|
|
|
13
14
|
* every publish is a wire bump: consumers that check for exact equality —
|
|
14
15
|
* every SDK — must upgrade in lockstep with the server.
|
|
15
16
|
*/
|
|
16
|
-
declare const CONTRACT_VERSION = "0.
|
|
17
|
+
declare const CONTRACT_VERSION = "0.7.0";
|
|
17
18
|
/** Response header carrying the server's contract version. */
|
|
18
19
|
declare const CONTRACT_VERSION_HEADER = "x-reopt-contract-version";
|
|
19
20
|
/** Request header names shared by the ingest and query planes. */
|
|
@@ -22,5 +23,6 @@ declare const CLIENT_SECRET_HEADER = "reopt-client-secret";
|
|
|
22
23
|
declare const WRITE_KEY_HEADER = "reopt-write-key";
|
|
23
24
|
declare const DEVICE_ID_HEADER = "reopt-device-id";
|
|
24
25
|
declare const REQUEST_ID_HEADER = "x-request-id";
|
|
25
|
-
|
|
26
|
-
export {
|
|
26
|
+
//#endregion
|
|
27
|
+
export { DEVICE_ID_HEADER as a, CONTRACT_VERSION_HEADER as i, CLIENT_SECRET_HEADER as n, REQUEST_ID_HEADER as o, CONTRACT_VERSION as r, WRITE_KEY_HEADER as s, CLIENT_ID_HEADER as t };
|
|
28
|
+
//# sourceMappingURL=version-CGujUGWd.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version-CGujUGWd.d.ts","names":[],"sources":["../src/version.ts"],"mappings":";;;;;;;;;;;;;;;;cAgBa;;cAGA;;cAGA;cACA;cACA;cACA;cACA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reopt-ai/data-contract",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Wire contract (zod schemas + typed client) for the reopt-data ingest and query APIs",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -17,44 +17,84 @@
|
|
|
17
17
|
},
|
|
18
18
|
"exports": {
|
|
19
19
|
".": {
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
"import": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"default": "./dist/index.js"
|
|
23
|
+
},
|
|
24
|
+
"require": {
|
|
25
|
+
"types": "./dist/index.d.cts",
|
|
26
|
+
"default": "./dist/index.cjs"
|
|
27
|
+
}
|
|
23
28
|
},
|
|
24
29
|
"./ingest": {
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
30
|
+
"import": {
|
|
31
|
+
"types": "./dist/ingest.d.ts",
|
|
32
|
+
"default": "./dist/ingest.js"
|
|
33
|
+
},
|
|
34
|
+
"require": {
|
|
35
|
+
"types": "./dist/ingest.d.cts",
|
|
36
|
+
"default": "./dist/ingest.cjs"
|
|
37
|
+
}
|
|
28
38
|
},
|
|
29
39
|
"./query": {
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
|
|
40
|
+
"import": {
|
|
41
|
+
"types": "./dist/query.d.ts",
|
|
42
|
+
"default": "./dist/query.js"
|
|
43
|
+
},
|
|
44
|
+
"require": {
|
|
45
|
+
"types": "./dist/query.d.cts",
|
|
46
|
+
"default": "./dist/query.cjs"
|
|
47
|
+
}
|
|
33
48
|
},
|
|
34
49
|
"./control": {
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
|
|
50
|
+
"import": {
|
|
51
|
+
"types": "./dist/control.d.ts",
|
|
52
|
+
"default": "./dist/control.js"
|
|
53
|
+
},
|
|
54
|
+
"require": {
|
|
55
|
+
"types": "./dist/control.d.cts",
|
|
56
|
+
"default": "./dist/control.cjs"
|
|
57
|
+
}
|
|
38
58
|
},
|
|
39
59
|
"./client": {
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
-
|
|
60
|
+
"import": {
|
|
61
|
+
"types": "./dist/client.d.ts",
|
|
62
|
+
"default": "./dist/client.js"
|
|
63
|
+
},
|
|
64
|
+
"require": {
|
|
65
|
+
"types": "./dist/client.d.cts",
|
|
66
|
+
"default": "./dist/client.cjs"
|
|
67
|
+
}
|
|
43
68
|
},
|
|
44
69
|
"./report": {
|
|
45
|
-
"
|
|
46
|
-
|
|
47
|
-
|
|
70
|
+
"import": {
|
|
71
|
+
"types": "./dist/report.d.ts",
|
|
72
|
+
"default": "./dist/report.js"
|
|
73
|
+
},
|
|
74
|
+
"require": {
|
|
75
|
+
"types": "./dist/report.d.cts",
|
|
76
|
+
"default": "./dist/report.cjs"
|
|
77
|
+
}
|
|
48
78
|
},
|
|
49
79
|
"./identity": {
|
|
50
|
-
"
|
|
51
|
-
|
|
52
|
-
|
|
80
|
+
"import": {
|
|
81
|
+
"types": "./dist/identity.d.ts",
|
|
82
|
+
"default": "./dist/identity.js"
|
|
83
|
+
},
|
|
84
|
+
"require": {
|
|
85
|
+
"types": "./dist/identity.d.cts",
|
|
86
|
+
"default": "./dist/identity.cjs"
|
|
87
|
+
}
|
|
53
88
|
},
|
|
54
89
|
"./events": {
|
|
55
|
-
"
|
|
56
|
-
|
|
57
|
-
|
|
90
|
+
"import": {
|
|
91
|
+
"types": "./dist/events.d.ts",
|
|
92
|
+
"default": "./dist/events.js"
|
|
93
|
+
},
|
|
94
|
+
"require": {
|
|
95
|
+
"types": "./dist/events.d.cts",
|
|
96
|
+
"default": "./dist/events.cjs"
|
|
97
|
+
}
|
|
58
98
|
}
|
|
59
99
|
},
|
|
60
100
|
"main": "./dist/index.cjs",
|
|
@@ -68,15 +108,16 @@
|
|
|
68
108
|
},
|
|
69
109
|
"devDependencies": {
|
|
70
110
|
"@types/node": "^22.20.1",
|
|
71
|
-
"
|
|
111
|
+
"tsdown": "^0.22.14",
|
|
72
112
|
"tsx": "^4.23.12",
|
|
73
113
|
"typescript": "^5.9.3",
|
|
74
114
|
"@repo/typescript-config": "0.0.0"
|
|
75
115
|
},
|
|
76
116
|
"scripts": {
|
|
77
|
-
"build": "
|
|
117
|
+
"build": "tsdown",
|
|
118
|
+
"check:package": "node ../../scripts/check-package-contract.mjs",
|
|
78
119
|
"check-types": "tsc --noEmit",
|
|
79
|
-
"dev": "
|
|
120
|
+
"dev": "tsdown --watch",
|
|
80
121
|
"lint": "oxlint .",
|
|
81
122
|
"test": "tsx --test src/__tests__/ingest.test.ts src/__tests__/query.test.ts src/__tests__/control.test.ts src/__tests__/client.test.ts src/__tests__/report.test.ts src/__tests__/identity.test.ts src/__tests__/package-identity.test.ts"
|
|
82
123
|
}
|
package/dist/chunk-3EEANNYN.cjs
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/events.ts
|
|
2
|
-
var RESERVED_EVENT_NAMES = ["session_start", "session_end", "screen_view"];
|
|
3
|
-
var AUTO_EVENT_NAMES = {
|
|
4
|
-
pageview: "$pageview",
|
|
5
|
-
screenView: "$screen_view",
|
|
6
|
-
pageleave: "$pageleave",
|
|
7
|
-
webVitals: "$web_vitals",
|
|
8
|
-
exception: "$exception"
|
|
9
|
-
};
|
|
10
|
-
var AUTO_EVENT_PROPERTIES = {
|
|
11
|
-
[AUTO_EVENT_NAMES.pageview]: [
|
|
12
|
-
"path",
|
|
13
|
-
"origin",
|
|
14
|
-
"title",
|
|
15
|
-
"referrer",
|
|
16
|
-
"search",
|
|
17
|
-
"utm_source",
|
|
18
|
-
"utm_medium",
|
|
19
|
-
"utm_campaign",
|
|
20
|
-
"utm_term",
|
|
21
|
-
"utm_content"
|
|
22
|
-
],
|
|
23
|
-
[AUTO_EVENT_NAMES.screenView]: ["screen_name"],
|
|
24
|
-
[AUTO_EVENT_NAMES.pageleave]: ["path", "origin", "duration", "scroll_depth", "scroll_depth_bucket"],
|
|
25
|
-
[AUTO_EVENT_NAMES.webVitals]: ["metric_name", "metric_id", "value", "delta", "rating", "navigation_type", "path"],
|
|
26
|
-
// `$`-prefixed on purpose: these are reserved, SDK-owned keys with fixed
|
|
27
|
-
// semantics, distinguished from a host's own snake_case vocabulary the
|
|
28
|
-
// same way the event names are. Not a typo — do not strip the prefix.
|
|
29
|
-
[AUTO_EVENT_NAMES.exception]: [
|
|
30
|
-
"$exception_type",
|
|
31
|
-
"$exception_message",
|
|
32
|
-
"$exception_stack",
|
|
33
|
-
"$exception_source",
|
|
34
|
-
"$exception_handled",
|
|
35
|
-
"path"
|
|
36
|
-
]
|
|
37
|
-
};
|
|
38
|
-
var AUTO_EVENT_ROLLUP_KEYS = {
|
|
39
|
-
[AUTO_EVENT_NAMES.pageview]: ["path", "origin", "referrer", "utm_source", "utm_medium", "utm_campaign"],
|
|
40
|
-
[AUTO_EVENT_NAMES.screenView]: ["screen_name"],
|
|
41
|
-
[AUTO_EVENT_NAMES.pageleave]: ["path", "origin", "scroll_depth_bucket"],
|
|
42
|
-
[AUTO_EVENT_NAMES.webVitals]: ["metric_name", "rating", "navigation_type", "path"],
|
|
43
|
-
[AUTO_EVENT_NAMES.exception]: ["$exception_type", "$exception_source", "$exception_handled", "path"]
|
|
44
|
-
};
|
|
45
|
-
var SCROLL_DEPTH_BUCKETS = [25, 50, 75, 100];
|
|
46
|
-
function scrollDepthBucket(depth) {
|
|
47
|
-
let reached = "0";
|
|
48
|
-
for (const threshold of SCROLL_DEPTH_BUCKETS) {
|
|
49
|
-
if (depth >= threshold) reached = `${threshold}`;
|
|
50
|
-
}
|
|
51
|
-
return reached;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
exports.RESERVED_EVENT_NAMES = RESERVED_EVENT_NAMES; exports.AUTO_EVENT_NAMES = AUTO_EVENT_NAMES; exports.AUTO_EVENT_PROPERTIES = AUTO_EVENT_PROPERTIES; exports.AUTO_EVENT_ROLLUP_KEYS = AUTO_EVENT_ROLLUP_KEYS; exports.SCROLL_DEPTH_BUCKETS = SCROLL_DEPTH_BUCKETS; exports.scrollDepthBucket = scrollDepthBucket;
|
|
62
|
-
//# sourceMappingURL=chunk-3EEANNYN.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/eric/reopt-ai/reopt-data/packages/data-contract/dist/chunk-3EEANNYN.cjs","../src/events.ts"],"names":[],"mappings":"AAAA;ACOO,IAAM,qBAAA,EAAuB,CAAC,eAAA,EAAiB,aAAA,EAAe,aAAa,CAAA;AAQ3E,IAAM,iBAAA,EAAmB;AAAA,EAC9B,QAAA,EAAU,WAAA;AAAA,EACV,UAAA,EAAY,cAAA;AAAA,EACZ,SAAA,EAAW,YAAA;AAAA,EACX,SAAA,EAAW,aAAA;AAAA,EACX,SAAA,EAAW;AACb,CAAA;AASO,IAAM,sBAAA,EAAwB;AAAA,EACnC,CAAC,gBAAA,CAAiB,QAAQ,CAAA,EAAG;AAAA,IAC3B,MAAA;AAAA,IACA,QAAA;AAAA,IACA,OAAA;AAAA,IACA,UAAA;AAAA,IACA,QAAA;AAAA,IACA,YAAA;AAAA,IACA,YAAA;AAAA,IACA,cAAA;AAAA,IACA,UAAA;AAAA,IACA;AAAA,EACF,CAAA;AAAA,EACA,CAAC,gBAAA,CAAiB,UAAU,CAAA,EAAG,CAAC,aAAa,CAAA;AAAA,EAC7C,CAAC,gBAAA,CAAiB,SAAS,CAAA,EAAG,CAAC,MAAA,EAAQ,QAAA,EAAU,UAAA,EAAY,cAAA,EAAgB,qBAAqB,CAAA;AAAA,EAClG,CAAC,gBAAA,CAAiB,SAA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ai/reopt-data/packages/data-contract/dist/chunk-3EEANNYN.cjs","sourcesContent":[null,"/**\n * `@reopt-ai/data-contract/events` — event names and property keys, with no\n * zod. Browser SDKs import this so their production bundles stay free of\n * schema code; `./ingest` re-exports everything here.\n */\n\n/** Event names the pipeline reserves for its own session bookkeeping. */\nexport const RESERVED_EVENT_NAMES = [\"session_start\", \"session_end\", \"screen_view\"] as const;\n\n/**\n * Events the SDKs emit on their own. One declaration, so a consumer that\n * registers them in its event catalogue (to make them roll up) cannot drift\n * from what the SDK actually sends — a drifted name silently falls back to\n * raw queries, which is slower but not visibly wrong.\n */\nexport const AUTO_EVENT_NAMES = {\n pageview: \"$pageview\",\n screenView: \"$screen_view\",\n pageleave: \"$pageleave\",\n webVitals: \"$web_vitals\",\n exception: \"$exception\",\n} as const;\nexport type AutoEventName = (typeof AUTO_EVENT_NAMES)[keyof typeof AUTO_EVENT_NAMES];\n\n/**\n * Property keys each automatic event carries. Consumers derive their\n * breakdown / rollup property lists from here rather than retyping them.\n * `path`, `origin`, `referrer` and `utm_*` are the keys the ingest pipeline\n * reads into session and event columns.\n */\nexport const AUTO_EVENT_PROPERTIES = {\n [AUTO_EVENT_NAMES.pageview]: [\n \"path\",\n \"origin\",\n \"title\",\n \"referrer\",\n \"search\",\n \"utm_source\",\n \"utm_medium\",\n \"utm_campaign\",\n \"utm_term\",\n \"utm_content\",\n ],\n [AUTO_EVENT_NAMES.screenView]: [\"screen_name\"],\n [AUTO_EVENT_NAMES.pageleave]: [\"path\", \"origin\", \"duration\", \"scroll_depth\", \"scroll_depth_bucket\"],\n [AUTO_EVENT_NAMES.webVitals]: [\"metric_name\", \"metric_id\", \"value\", \"delta\", \"rating\", \"navigation_type\", \"path\"],\n // `$`-prefixed on purpose: these are reserved, SDK-owned keys with fixed\n // semantics, distinguished from a host's own snake_case vocabulary the\n // same way the event names are. Not a typo — do not strip the prefix.\n [AUTO_EVENT_NAMES.exception]: [\n \"$exception_type\",\n \"$exception_message\",\n \"$exception_stack\",\n \"$exception_source\",\n \"$exception_handled\",\n \"path\",\n ],\n} as const satisfies Record<AutoEventName, readonly string[]>;\n\n/**\n * The subset of {@link AUTO_EVENT_PROPERTIES} that is a sensible rollup\n * dimension: low cardinality, categorical. Per-measurement ids and\n * continuous values (`metric_id`, `value`, `delta`, `duration`,\n * `scroll_depth`) are deliberately absent — as dimensions they would make\n * the rollup larger than the raw table it summarises. Derive\n * `rollupProperties` from here, not from the full property list.\n */\nexport const AUTO_EVENT_ROLLUP_KEYS = {\n [AUTO_EVENT_NAMES.pageview]: [\"path\", \"origin\", \"referrer\", \"utm_source\", \"utm_medium\", \"utm_campaign\"],\n [AUTO_EVENT_NAMES.screenView]: [\"screen_name\"],\n [AUTO_EVENT_NAMES.pageleave]: [\"path\", \"origin\", \"scroll_depth_bucket\"],\n [AUTO_EVENT_NAMES.webVitals]: [\"metric_name\", \"rating\", \"navigation_type\", \"path\"],\n [AUTO_EVENT_NAMES.exception]: [\"$exception_type\", \"$exception_source\", \"$exception_handled\", \"path\"],\n} as const satisfies Record<AutoEventName, readonly string[]>;\n\n/**\n * `$pageleave.scroll_depth` is the exact 0–100 percentage; `scroll_depth_bucket`\n * is the deepest of these thresholds reached, as a string — the value to\n * break down by. `\"0\"` means the visitor never reached the first threshold.\n */\nexport const SCROLL_DEPTH_BUCKETS = [25, 50, 75, 100] as const;\nexport type ScrollDepthBucket = \"0\" | `${(typeof SCROLL_DEPTH_BUCKETS)[number]}`;\n\nexport function scrollDepthBucket(depth: number): ScrollDepthBucket {\n let reached: ScrollDepthBucket = \"0\";\n for (const threshold of SCROLL_DEPTH_BUCKETS) {\n if (depth >= threshold) reached = `${threshold}`;\n }\n return reached;\n}\n"]}
|
package/dist/chunk-7W33YGRO.js
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DEVICE_ID_HEADER
|
|
3
|
-
} from "./chunk-PSUINLW7.js";
|
|
4
|
-
|
|
5
|
-
// src/identity.ts
|
|
6
|
-
var SESSION_ID_HEADER = "reopt-session-id";
|
|
7
|
-
var IDENTITY_REQUEST_HEADERS = [DEVICE_ID_HEADER, SESSION_ID_HEADER];
|
|
8
|
-
var COOKIE_MAX_AGE_SECONDS = 400 * 24 * 60 * 60;
|
|
9
|
-
var OPT_OUT_CONSENT_CATEGORY = "analytics";
|
|
10
|
-
var COOKIE_PREFIX = "reopt_";
|
|
11
|
-
function cookieSafe(writeKey) {
|
|
12
|
-
if (!writeKey) {
|
|
13
|
-
throw new Error("[reopt] writeKey is required to derive cookie names");
|
|
14
|
-
}
|
|
15
|
-
return writeKey.replace(/[^A-Za-z0-9_-]/g, "_");
|
|
16
|
-
}
|
|
17
|
-
function deviceCookieName(writeKey) {
|
|
18
|
-
return `${COOKIE_PREFIX}${cookieSafe(writeKey)}_device`;
|
|
19
|
-
}
|
|
20
|
-
function consentCookieName(writeKey) {
|
|
21
|
-
return `${COOKIE_PREFIX}${cookieSafe(writeKey)}_consent`;
|
|
22
|
-
}
|
|
23
|
-
var IDENTITY_ID_PATTERN = /^[A-Za-z0-9._~-]{1,200}$/;
|
|
24
|
-
function isValidIdentityId(value) {
|
|
25
|
-
return typeof value === "string" && IDENTITY_ID_PATTERN.test(value);
|
|
26
|
-
}
|
|
27
|
-
function decode(raw) {
|
|
28
|
-
let text = raw;
|
|
29
|
-
for (let round = 0; round < 3 && /%[0-9A-Fa-f]{2}/.test(text); round++) {
|
|
30
|
-
try {
|
|
31
|
-
const next = decodeURIComponent(text);
|
|
32
|
-
if (next === text) break;
|
|
33
|
-
text = next;
|
|
34
|
-
} catch {
|
|
35
|
-
break;
|
|
36
|
-
}
|
|
37
|
-
if (text.startsWith("{")) break;
|
|
38
|
-
}
|
|
39
|
-
return text;
|
|
40
|
-
}
|
|
41
|
-
function parseDeviceCookie(raw) {
|
|
42
|
-
if (!raw) return null;
|
|
43
|
-
const text = decode(raw.trim());
|
|
44
|
-
if (!text) return null;
|
|
45
|
-
if (!text.startsWith("{")) {
|
|
46
|
-
return isValidIdentityId(text) ? { deviceId: text } : null;
|
|
47
|
-
}
|
|
48
|
-
let parsed;
|
|
49
|
-
try {
|
|
50
|
-
parsed = JSON.parse(text);
|
|
51
|
-
} catch {
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
if (typeof parsed !== "object" || parsed === null) return null;
|
|
55
|
-
const candidate = parsed;
|
|
56
|
-
if (!isValidIdentityId(candidate.deviceId)) return null;
|
|
57
|
-
const state = { deviceId: candidate.deviceId };
|
|
58
|
-
if (isValidIdentityId(candidate.sessionId)) state.sessionId = candidate.sessionId;
|
|
59
|
-
if (isValidIdentityId(candidate.profileId)) state.profileId = candidate.profileId;
|
|
60
|
-
return state;
|
|
61
|
-
}
|
|
62
|
-
function serializeDeviceCookie(state) {
|
|
63
|
-
if (!isValidIdentityId(state.deviceId)) {
|
|
64
|
-
throw new Error("[reopt] deviceId must be a non-empty string without control characters");
|
|
65
|
-
}
|
|
66
|
-
const envelope = { deviceId: state.deviceId };
|
|
67
|
-
if (isValidIdentityId(state.sessionId)) envelope.sessionId = state.sessionId;
|
|
68
|
-
if (isValidIdentityId(state.profileId)) envelope.profileId = state.profileId;
|
|
69
|
-
return encodeURIComponent(JSON.stringify(envelope));
|
|
70
|
-
}
|
|
71
|
-
function parseConsentCookie(raw) {
|
|
72
|
-
if (!raw) return null;
|
|
73
|
-
const text = decode(raw.trim());
|
|
74
|
-
if (!text.startsWith("{")) return null;
|
|
75
|
-
let parsed;
|
|
76
|
-
try {
|
|
77
|
-
parsed = JSON.parse(text);
|
|
78
|
-
} catch {
|
|
79
|
-
return null;
|
|
80
|
-
}
|
|
81
|
-
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) return null;
|
|
82
|
-
const state = {};
|
|
83
|
-
for (const [category, decision] of Object.entries(parsed)) {
|
|
84
|
-
if (typeof decision === "boolean" && isValidIdentityId(category)) {
|
|
85
|
-
state[category] = decision;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return state;
|
|
89
|
-
}
|
|
90
|
-
function serializeConsentCookie(state) {
|
|
91
|
-
const clean = {};
|
|
92
|
-
for (const [category, decision] of Object.entries(state)) {
|
|
93
|
-
if (typeof decision === "boolean" && isValidIdentityId(category)) {
|
|
94
|
-
clean[category] = decision;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return encodeURIComponent(JSON.stringify(clean));
|
|
98
|
-
}
|
|
99
|
-
function isOptedOut(consent) {
|
|
100
|
-
return consent?.[OPT_OUT_CONSENT_CATEGORY] === false;
|
|
101
|
-
}
|
|
102
|
-
var SESSION_HEADER_SEPARATOR = ".";
|
|
103
|
-
function formatSessionHeader(credential) {
|
|
104
|
-
return `${credential.id}${SESSION_HEADER_SEPARATOR}${credential.token}`;
|
|
105
|
-
}
|
|
106
|
-
function parseSessionHeader(value) {
|
|
107
|
-
if (!value) return null;
|
|
108
|
-
const at = value.lastIndexOf(SESSION_HEADER_SEPARATOR);
|
|
109
|
-
if (at <= 0 || at === value.length - 1) return null;
|
|
110
|
-
const id = value.slice(0, at);
|
|
111
|
-
const token = value.slice(at + 1);
|
|
112
|
-
return isValidIdentityId(id) && /^[A-Za-z0-9_-]{43}$/.test(token) ? { id, token } : null;
|
|
113
|
-
}
|
|
114
|
-
var encoder = new TextEncoder();
|
|
115
|
-
function base64url(bytes) {
|
|
116
|
-
let binary = "";
|
|
117
|
-
for (const byte of new Uint8Array(bytes)) binary += String.fromCharCode(byte);
|
|
118
|
-
const b64 = typeof btoa === "function" ? btoa(binary) : Buffer.from(binary, "binary").toString("base64");
|
|
119
|
-
return b64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
120
|
-
}
|
|
121
|
-
async function hmacKey(secret) {
|
|
122
|
-
return crypto.subtle.importKey("raw", encoder.encode(secret), { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
|
|
123
|
-
}
|
|
124
|
-
async function signSessionToken(secret, sessionId) {
|
|
125
|
-
if (!secret) throw new Error("[reopt] a session signing secret is required");
|
|
126
|
-
const signature = await crypto.subtle.sign("HMAC", await hmacKey(secret), encoder.encode(sessionId));
|
|
127
|
-
return base64url(signature);
|
|
128
|
-
}
|
|
129
|
-
async function verifySessionToken(secret, credential) {
|
|
130
|
-
if (!secret || !credential) return false;
|
|
131
|
-
const expected = await signSessionToken(secret, credential.id);
|
|
132
|
-
if (expected.length !== credential.token.length) return false;
|
|
133
|
-
let diff = 0;
|
|
134
|
-
for (let index = 0; index < expected.length; index++) {
|
|
135
|
-
diff |= expected.charCodeAt(index) ^ credential.token.charCodeAt(index);
|
|
136
|
-
}
|
|
137
|
-
return diff === 0;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
export {
|
|
141
|
-
SESSION_ID_HEADER,
|
|
142
|
-
IDENTITY_REQUEST_HEADERS,
|
|
143
|
-
COOKIE_MAX_AGE_SECONDS,
|
|
144
|
-
OPT_OUT_CONSENT_CATEGORY,
|
|
145
|
-
deviceCookieName,
|
|
146
|
-
consentCookieName,
|
|
147
|
-
IDENTITY_ID_PATTERN,
|
|
148
|
-
isValidIdentityId,
|
|
149
|
-
parseDeviceCookie,
|
|
150
|
-
serializeDeviceCookie,
|
|
151
|
-
parseConsentCookie,
|
|
152
|
-
serializeConsentCookie,
|
|
153
|
-
isOptedOut,
|
|
154
|
-
SESSION_HEADER_SEPARATOR,
|
|
155
|
-
formatSessionHeader,
|
|
156
|
-
parseSessionHeader,
|
|
157
|
-
signSessionToken,
|
|
158
|
-
verifySessionToken
|
|
159
|
-
};
|
|
160
|
-
//# sourceMappingURL=chunk-7W33YGRO.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/identity.ts"],"sourcesContent":["/**\n * `@reopt-ai/data-contract/identity` — the names and encodings that carry a\n * visitor's identity between the browser SDK, the server SDK, the Next.js\n * proxy and the ingest pipeline.\n *\n * Every one of those parties reads or writes the same cookies and headers.\n * None of them depends on another (ingest does not import the SDKs), so this\n * module is the only place a name may be spelled out. A party that hardcodes\n * `reopt_<key>_device` instead of calling `deviceCookieName()` fails silently:\n * the browser sets one cookie, the server looks for another, and every\n * visitor is counted as new. `packages/db/src/__tests__/redis-namespace.test.ts`\n * guards Redis key prefixes for exactly the same reason.\n *\n * Nothing here touches `document`, `fetch` or Node built-ins — it runs in\n * browsers, edge runtimes and Node alike.\n */\nimport { DEVICE_ID_HEADER } from \"./version.js\";\n\nexport {\n CLIENT_ID_HEADER,\n CLIENT_SECRET_HEADER,\n CONTRACT_VERSION,\n CONTRACT_VERSION_HEADER,\n DEVICE_ID_HEADER,\n REQUEST_ID_HEADER,\n WRITE_KEY_HEADER,\n} from \"./version.js\";\n\n/**\n * Request header carrying the browser's current session id. The browser SDK\n * adds it to same-origin requests so a server-side `track()` can land in the\n * session the user is actually in; the server SDK forwards it to ingest.\n *\n * Ingest treats it as a *hint*, never as authority — a browser can put any\n * value here.\n */\nexport const SESSION_ID_HEADER = \"reopt-session-id\";\n\n/** Every request header the identity protocol may carry, for CORS allow-lists. */\nexport const IDENTITY_REQUEST_HEADERS = [DEVICE_ID_HEADER, SESSION_ID_HEADER] as const;\n\n/**\n * 400 days — the longest lifetime Chrome will honour. Anything longer is\n * silently clamped to this, so asking for more only hides the real expiry.\n */\nexport const COOKIE_MAX_AGE_SECONDS = 400 * 24 * 60 * 60;\n\n/** Consent category whose refusal means \"send nothing at all\". */\nexport const OPT_OUT_CONSENT_CATEGORY = \"analytics\";\n\nconst COOKIE_PREFIX = \"reopt_\";\n\n/**\n * Cookie names may not contain separators (`=`, `;`, `,`, whitespace) or\n * control characters. A write key is opaque to us, so anything outside the\n * safe set is folded to `_` — deterministically, so both ends agree.\n */\nfunction cookieSafe(writeKey: string): string {\n if (!writeKey) {\n throw new Error(\"[reopt] writeKey is required to derive cookie names\");\n }\n return writeKey.replace(/[^A-Za-z0-9_-]/g, \"_\");\n}\n\n/**\n * `reopt_<writeKey>_device` — device id plus session/profile hints.\n *\n * The write key is **sanitized**: any character outside `[A-Za-z0-9_-]`\n * becomes `_` (see `cookieSafe`), so do not derive prefix/suffix pieces by\n * probing this with a marker character — the marker is folded too. Always\n * call this with the real write key and compare whole names.\n */\nexport function deviceCookieName(writeKey: string): string {\n return `${COOKIE_PREFIX}${cookieSafe(writeKey)}_device`;\n}\n\n/** `reopt_<writeKey>_consent` — per-category consent decisions. Same sanitizing as `deviceCookieName`. */\nexport function consentCookieName(writeKey: string): string {\n return `${COOKIE_PREFIX}${cookieSafe(writeKey)}_consent`;\n}\n\n/** Everything the device cookie may carry. Only `deviceId` is required. */\nexport interface DeviceCookieState {\n deviceId: string;\n /** Current session, if the browser has one. */\n sessionId?: string | undefined;\n /** Last identified profile. A hint for the server SDK, never trusted by ingest. */\n profileId?: string | undefined;\n}\n\n/** Per-category consent. `false` withdraws, `true` grants, absent = undecided. */\nexport type ConsentCookieState = Record<string, boolean>;\n\n/**\n * What the server hands the browser SDK so the first render already agrees\n * with the server about who the visitor is. Plain JSON — it crosses the\n * RSC → client component boundary as a prop.\n */\nexport interface ReoptBootstrap {\n /** From the device cookie (seeded by the proxy on first visit). */\n deviceId: string;\n /** Session hint, or `null` when the browser has not started one. */\n sessionId: string | null;\n /** Result of the server's `getProfileId` resolver, or `null`. */\n profileId: string | null;\n consent: ConsentCookieState;\n /** Server clock at render time, so a skewed device clock can be corrected. */\n serverTimeMs: number;\n}\n\n/**\n * Ids are opaque, but a cookie is attacker-controlled input (a sibling\n * subdomain can set one). The value ends up in an HTTP header, and\n * `Headers.set` throws on anything outside ISO-8859-1 — so a single odd\n * cookie would break every `fetch` the tracing patch touches. Only the URL\n * \"unreserved\" set is accepted; every id this SDK mints is a UUID.\n */\nexport const IDENTITY_ID_PATTERN = /^[A-Za-z0-9._~-]{1,200}$/;\n\nexport function isValidIdentityId(value: unknown): value is string {\n return typeof value === \"string\" && IDENTITY_ID_PATTERN.test(value);\n}\n\n/**\n * Decodes the envelope. Tolerates one extra layer (`%257B…`) — a cookie\n * setter that encodes an already-encoded value is a mistake we have shipped\n * once, and a visitor's identity should survive it rather than be reminted.\n */\nfunction decode(raw: string): string {\n let text = raw;\n for (let round = 0; round < 3 && /%[0-9A-Fa-f]{2}/.test(text); round++) {\n try {\n const next = decodeURIComponent(text);\n if (next === text) break;\n text = next;\n } catch {\n break;\n }\n if (text.startsWith(\"{\")) break;\n }\n return text;\n}\n\n/**\n * Reads a device cookie value. Accepts the JSON envelope written by\n * `serializeDeviceCookie` and, for cookies seeded before the envelope existed,\n * a bare device id. Returns `null` for anything else — a malformed cookie is\n * treated as absent, never as an error, so a corrupted value cannot take the\n * page down.\n */\nexport function parseDeviceCookie(raw: string | null | undefined): DeviceCookieState | null {\n if (!raw) return null;\n const text = decode(raw.trim());\n if (!text) return null;\n\n if (!text.startsWith(\"{\")) {\n return isValidIdentityId(text) ? { deviceId: text } : null;\n }\n\n let parsed: unknown;\n try {\n parsed = JSON.parse(text);\n } catch {\n return null;\n }\n if (typeof parsed !== \"object\" || parsed === null) return null;\n\n const candidate = parsed as Record<string, unknown>;\n if (!isValidIdentityId(candidate.deviceId)) return null;\n\n const state: DeviceCookieState = { deviceId: candidate.deviceId };\n if (isValidIdentityId(candidate.sessionId)) state.sessionId = candidate.sessionId;\n if (isValidIdentityId(candidate.profileId)) state.profileId = candidate.profileId;\n return state;\n}\n\n/**\n * Cookie values may not contain `;`, `,` or whitespace, and JSON contains\n * quotes and commas. The envelope is therefore URI-encoded; `parseDeviceCookie`\n * reverses it. Optional fields are omitted rather than written as `null` so\n * the cookie stays as small as the state it carries.\n */\nexport function serializeDeviceCookie(state: DeviceCookieState): string {\n if (!isValidIdentityId(state.deviceId)) {\n throw new Error(\"[reopt] deviceId must be a non-empty string without control characters\");\n }\n const envelope: DeviceCookieState = { deviceId: state.deviceId };\n if (isValidIdentityId(state.sessionId)) envelope.sessionId = state.sessionId;\n if (isValidIdentityId(state.profileId)) envelope.profileId = state.profileId;\n return encodeURIComponent(JSON.stringify(envelope));\n}\n\n/**\n * Reads a consent cookie. Only boolean entries survive; anything else in the\n * object is dropped rather than failing the whole cookie, because one odd key\n * must not erase a user's recorded opt-out.\n */\nexport function parseConsentCookie(raw: string | null | undefined): ConsentCookieState | null {\n if (!raw) return null;\n const text = decode(raw.trim());\n if (!text.startsWith(\"{\")) return null;\n\n let parsed: unknown;\n try {\n parsed = JSON.parse(text);\n } catch {\n return null;\n }\n if (typeof parsed !== \"object\" || parsed === null || Array.isArray(parsed)) return null;\n\n const state: ConsentCookieState = {};\n for (const [category, decision] of Object.entries(parsed as Record<string, unknown>)) {\n if (typeof decision === \"boolean\" && isValidIdentityId(category)) {\n state[category] = decision;\n }\n }\n return state;\n}\n\nexport function serializeConsentCookie(state: ConsentCookieState): string {\n const clean: ConsentCookieState = {};\n for (const [category, decision] of Object.entries(state)) {\n if (typeof decision === \"boolean\" && isValidIdentityId(category)) {\n clean[category] = decision;\n }\n }\n return encodeURIComponent(JSON.stringify(clean));\n}\n\n/**\n * \"Opted out\" means the visitor refused the `analytics` category. An absent\n * cookie or an undecided category is *not* an opt-out — it is the default\n * state of every first visit, and treating it as refusal would make consent\n * banners mandatory for every integration.\n */\nexport function isOptedOut(consent: ConsentCookieState | null | undefined): boolean {\n return consent?.[OPT_OUT_CONSENT_CATEGORY] === false;\n}\n\n// ─── Session tokens ───────────────────────────────────────────────────────────\n\n/**\n * Sessions are assigned by ingest, not by the browser. To let a later request\n * — from the same browser, or from a server acting for it — join that session\n * with authority, ingest hands the browser its session id together with an\n * HMAC over it, and the browser sends both back as `reopt-session-id`. An\n * unsigned or wrongly signed value is a hint at most: ingest falls back to\n * deciding the session from the device, exactly as if the header were absent.\n *\n * The token is `base64url(HMAC-SHA256(secret, sessionId))`. The secret is\n * per project and never leaves the server. WebCrypto only, so this runs in\n * browsers, edge runtimes and Node alike.\n */\nexport const SESSION_HEADER_SEPARATOR = \".\";\n\nexport interface SessionCredential {\n id: string;\n token: string;\n}\n\n/** `<id>.<token>` — what travels in `reopt-session-id`. */\nexport function formatSessionHeader(credential: SessionCredential): string {\n return `${credential.id}${SESSION_HEADER_SEPARATOR}${credential.token}`;\n}\n\n/** Splits a `reopt-session-id` value. `null` unless both parts are well-formed. */\nexport function parseSessionHeader(value: string | null | undefined): SessionCredential | null {\n if (!value) return null;\n const at = value.lastIndexOf(SESSION_HEADER_SEPARATOR);\n if (at <= 0 || at === value.length - 1) return null;\n const id = value.slice(0, at);\n const token = value.slice(at + 1);\n return isValidIdentityId(id) && /^[A-Za-z0-9_-]{43}$/.test(token) ? { id, token } : null;\n}\n\nconst encoder = new TextEncoder();\n\nfunction base64url(bytes: ArrayBuffer): string {\n let binary = \"\";\n for (const byte of new Uint8Array(bytes)) binary += String.fromCharCode(byte);\n const b64 = typeof btoa === \"function\" ? btoa(binary) : Buffer.from(binary, \"binary\").toString(\"base64\");\n return b64.replace(/\\+/g, \"-\").replace(/\\//g, \"_\").replace(/=+$/, \"\");\n}\n\nasync function hmacKey(secret: string): Promise<CryptoKey> {\n return crypto.subtle.importKey(\"raw\", encoder.encode(secret), { name: \"HMAC\", hash: \"SHA-256\" }, false, [\"sign\"]);\n}\n\n/** Issues the token for `sessionId`. Server-side only — needs the project secret. */\nexport async function signSessionToken(secret: string, sessionId: string): Promise<string> {\n if (!secret) throw new Error(\"[reopt] a session signing secret is required\");\n const signature = await crypto.subtle.sign(\"HMAC\", await hmacKey(secret), encoder.encode(sessionId));\n return base64url(signature);\n}\n\n/**\n * Constant-time check of a presented token. Recomputes and compares the\n * digests byte by byte rather than using `subtle.verify` with a decoded\n * token, so a malformed token can never throw its way past the check.\n */\nexport async function verifySessionToken(secret: string, credential: SessionCredential): Promise<boolean> {\n if (!secret || !credential) return false;\n const expected = await signSessionToken(secret, credential.id);\n if (expected.length !== credential.token.length) return false;\n let diff = 0;\n for (let index = 0; index < expected.length; index++) {\n diff |= expected.charCodeAt(index) ^ credential.token.charCodeAt(index);\n }\n return diff === 0;\n}\n"],"mappings":";;;;;AAoCO,IAAM,oBAAoB;AAG1B,IAAM,2BAA2B,CAAC,kBAAkB,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AAM,GAAG,QAAQ,OAAO,SAAS,CAAC;AACnG,SAAO,UAAU,SAAS;AAC5B;AAOA,eAAsB,mBAAmB,QAAgB,YAAiD;AACxG,MAAI,CAAC,UAAU,CAAC,WAAY,QAAO;AACnC,QAAM,WAAW,MAAM,iBAAiB,QAAQ,WAAW,EAAE;AAC7D,MAAI,SAAS,WAAW,WAAW,MAAM,OAAQ,QAAO;AACxD,MAAI,OAAO;AACX,WAAS,QAAQ,GAAG,QAAQ,SAAS,QAAQ,SAAS;AACpD,YAAQ,SAAS,WAAW,KAAK,IAAI,WAAW,MAAM,WAAW,KAAK;AAAA,EACxE;AACA,SAAO,SAAS;AAClB;","names":[]}
|
package/dist/chunk-F2RNXJGO.cjs
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/version.ts
|
|
2
|
-
var CONTRACT_VERSION = "0.6.3";
|
|
3
|
-
var CONTRACT_VERSION_HEADER = "x-reopt-contract-version";
|
|
4
|
-
var CLIENT_ID_HEADER = "reopt-client-id";
|
|
5
|
-
var CLIENT_SECRET_HEADER = "reopt-client-secret";
|
|
6
|
-
var WRITE_KEY_HEADER = "reopt-write-key";
|
|
7
|
-
var DEVICE_ID_HEADER = "reopt-device-id";
|
|
8
|
-
var REQUEST_ID_HEADER = "x-request-id";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
exports.CONTRACT_VERSION = CONTRACT_VERSION; exports.CONTRACT_VERSION_HEADER = CONTRACT_VERSION_HEADER; exports.CLIENT_ID_HEADER = CLIENT_ID_HEADER; exports.CLIENT_SECRET_HEADER = CLIENT_SECRET_HEADER; exports.WRITE_KEY_HEADER = WRITE_KEY_HEADER; exports.DEVICE_ID_HEADER = DEVICE_ID_HEADER; exports.REQUEST_ID_HEADER = REQUEST_ID_HEADER;
|
|
19
|
-
//# sourceMappingURL=chunk-F2RNXJGO.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/eric/reopt-ai/reopt-data/packages/data-contract/dist/chunk-F2RNXJGO.cjs","../src/version.ts"],"names":[],"mappings":"AAAA;ACgBO,IAAM,iBAAA,EAAmB,OAAA;AAGzB,IAAM,wBAAA,EAA0B,0BAAA;AAGhC,IAAM,iBAAA,EAAmB,iBAAA;AACzB,IAAM,qBAAA,EAAuB,qBAAA;AAC7B,IAAM,iBAAA,EAAmB,iBAAA;AACzB,IAAM,iBAAA,EAAmB,iBAAA;AACzB,IAAM,kBAAA,EAAoB,cAAA;ADlBjC;AACA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACF,kVAAC","file":"/Users/eric/reopt-ai/reopt-data/packages/data-contract/dist/chunk-F2RNXJGO.cjs","sourcesContent":[null,"/**\n * Wire version and header names — the part of the contract every party\n * needs and none of them should pay zod for. Both `.` and `./identity`\n * re-export these; browser bundles import them through `./identity` so the\n * schema modules stay out of the client graph.\n */\n\n/**\n * Contract version. Bumped on any breaking change to a schema in this package.\n * The server echoes the version it was built against in `x-reopt-contract-version`;\n * `createDataClient` surfaces a mismatch rather than guessing.\n *\n * Must equal the package version (`package-identity.test.ts` enforces it), so\n * every publish is a wire bump: consumers that check for exact equality —\n * every SDK — must upgrade in lockstep with the server.\n */\nexport const CONTRACT_VERSION = \"0.6.3\";\n\n/** Response header carrying the server's contract version. */\nexport const CONTRACT_VERSION_HEADER = \"x-reopt-contract-version\";\n\n/** Request header names shared by the ingest and query planes. */\nexport const CLIENT_ID_HEADER = \"reopt-client-id\";\nexport const CLIENT_SECRET_HEADER = \"reopt-client-secret\";\nexport const WRITE_KEY_HEADER = \"reopt-write-key\";\nexport const DEVICE_ID_HEADER = \"reopt-device-id\";\nexport const REQUEST_ID_HEADER = \"x-request-id\";\n"]}
|
package/dist/chunk-FP2X3PRK.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
// src/events.ts
|
|
2
|
-
var RESERVED_EVENT_NAMES = ["session_start", "session_end", "screen_view"];
|
|
3
|
-
var AUTO_EVENT_NAMES = {
|
|
4
|
-
pageview: "$pageview",
|
|
5
|
-
screenView: "$screen_view",
|
|
6
|
-
pageleave: "$pageleave",
|
|
7
|
-
webVitals: "$web_vitals",
|
|
8
|
-
exception: "$exception"
|
|
9
|
-
};
|
|
10
|
-
var AUTO_EVENT_PROPERTIES = {
|
|
11
|
-
[AUTO_EVENT_NAMES.pageview]: [
|
|
12
|
-
"path",
|
|
13
|
-
"origin",
|
|
14
|
-
"title",
|
|
15
|
-
"referrer",
|
|
16
|
-
"search",
|
|
17
|
-
"utm_source",
|
|
18
|
-
"utm_medium",
|
|
19
|
-
"utm_campaign",
|
|
20
|
-
"utm_term",
|
|
21
|
-
"utm_content"
|
|
22
|
-
],
|
|
23
|
-
[AUTO_EVENT_NAMES.screenView]: ["screen_name"],
|
|
24
|
-
[AUTO_EVENT_NAMES.pageleave]: ["path", "origin", "duration", "scroll_depth", "scroll_depth_bucket"],
|
|
25
|
-
[AUTO_EVENT_NAMES.webVitals]: ["metric_name", "metric_id", "value", "delta", "rating", "navigation_type", "path"],
|
|
26
|
-
// `$`-prefixed on purpose: these are reserved, SDK-owned keys with fixed
|
|
27
|
-
// semantics, distinguished from a host's own snake_case vocabulary the
|
|
28
|
-
// same way the event names are. Not a typo — do not strip the prefix.
|
|
29
|
-
[AUTO_EVENT_NAMES.exception]: [
|
|
30
|
-
"$exception_type",
|
|
31
|
-
"$exception_message",
|
|
32
|
-
"$exception_stack",
|
|
33
|
-
"$exception_source",
|
|
34
|
-
"$exception_handled",
|
|
35
|
-
"path"
|
|
36
|
-
]
|
|
37
|
-
};
|
|
38
|
-
var AUTO_EVENT_ROLLUP_KEYS = {
|
|
39
|
-
[AUTO_EVENT_NAMES.pageview]: ["path", "origin", "referrer", "utm_source", "utm_medium", "utm_campaign"],
|
|
40
|
-
[AUTO_EVENT_NAMES.screenView]: ["screen_name"],
|
|
41
|
-
[AUTO_EVENT_NAMES.pageleave]: ["path", "origin", "scroll_depth_bucket"],
|
|
42
|
-
[AUTO_EVENT_NAMES.webVitals]: ["metric_name", "rating", "navigation_type", "path"],
|
|
43
|
-
[AUTO_EVENT_NAMES.exception]: ["$exception_type", "$exception_source", "$exception_handled", "path"]
|
|
44
|
-
};
|
|
45
|
-
var SCROLL_DEPTH_BUCKETS = [25, 50, 75, 100];
|
|
46
|
-
function scrollDepthBucket(depth) {
|
|
47
|
-
let reached = "0";
|
|
48
|
-
for (const threshold of SCROLL_DEPTH_BUCKETS) {
|
|
49
|
-
if (depth >= threshold) reached = `${threshold}`;
|
|
50
|
-
}
|
|
51
|
-
return reached;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export {
|
|
55
|
-
RESERVED_EVENT_NAMES,
|
|
56
|
-
AUTO_EVENT_NAMES,
|
|
57
|
-
AUTO_EVENT_PROPERTIES,
|
|
58
|
-
AUTO_EVENT_ROLLUP_KEYS,
|
|
59
|
-
SCROLL_DEPTH_BUCKETS,
|
|
60
|
-
scrollDepthBucket
|
|
61
|
-
};
|
|
62
|
-
//# sourceMappingURL=chunk-FP2X3PRK.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/events.ts"],"sourcesContent":["/**\n * `@reopt-ai/data-contract/events` — event names and property keys, with no\n * zod. Browser SDKs import this so their production bundles stay free of\n * schema code; `./ingest` re-exports everything here.\n */\n\n/** Event names the pipeline reserves for its own session bookkeeping. */\nexport const RESERVED_EVENT_NAMES = [\"session_start\", \"session_end\", \"screen_view\"] as const;\n\n/**\n * Events the SDKs emit on their own. One declaration, so a consumer that\n * registers them in its event catalogue (to make them roll up) cannot drift\n * from what the SDK actually sends — a drifted name silently falls back to\n * raw queries, which is slower but not visibly wrong.\n */\nexport const AUTO_EVENT_NAMES = {\n pageview: \"$pageview\",\n screenView: \"$screen_view\",\n pageleave: \"$pageleave\",\n webVitals: \"$web_vitals\",\n exception: \"$exception\",\n} as const;\nexport type AutoEventName = (typeof AUTO_EVENT_NAMES)[keyof typeof AUTO_EVENT_NAMES];\n\n/**\n * Property keys each automatic event carries. Consumers derive their\n * breakdown / rollup property lists from here rather than retyping them.\n * `path`, `origin`, `referrer` and `utm_*` are the keys the ingest pipeline\n * reads into session and event columns.\n */\nexport const AUTO_EVENT_PROPERTIES = {\n [AUTO_EVENT_NAMES.pageview]: [\n \"path\",\n \"origin\",\n \"title\",\n \"referrer\",\n \"search\",\n \"utm_source\",\n \"utm_medium\",\n \"utm_campaign\",\n \"utm_term\",\n \"utm_content\",\n ],\n [AUTO_EVENT_NAMES.screenView]: [\"screen_name\"],\n [AUTO_EVENT_NAMES.pageleave]: [\"path\", \"origin\", \"duration\", \"scroll_depth\", \"scroll_depth_bucket\"],\n [AUTO_EVENT_NAMES.webVitals]: [\"metric_name\", \"metric_id\", \"value\", \"delta\", \"rating\", \"navigation_type\", \"path\"],\n // `$`-prefixed on purpose: these are reserved, SDK-owned keys with fixed\n // semantics, distinguished from a host's own snake_case vocabulary the\n // same way the event names are. Not a typo — do not strip the prefix.\n [AUTO_EVENT_NAMES.exception]: [\n \"$exception_type\",\n \"$exception_message\",\n \"$exception_stack\",\n \"$exception_source\",\n \"$exception_handled\",\n \"path\",\n ],\n} as const satisfies Record<AutoEventName, readonly string[]>;\n\n/**\n * The subset of {@link AUTO_EVENT_PROPERTIES} that is a sensible rollup\n * dimension: low cardinality, categorical. Per-measurement ids and\n * continuous values (`metric_id`, `value`, `delta`, `duration`,\n * `scroll_depth`) are deliberately absent — as dimensions they would make\n * the rollup larger than the raw table it summarises. Derive\n * `rollupProperties` from here, not from the full property list.\n */\nexport const AUTO_EVENT_ROLLUP_KEYS = {\n [AUTO_EVENT_NAMES.pageview]: [\"path\", \"origin\", \"referrer\", \"utm_source\", \"utm_medium\", \"utm_campaign\"],\n [AUTO_EVENT_NAMES.screenView]: [\"screen_name\"],\n [AUTO_EVENT_NAMES.pageleave]: [\"path\", \"origin\", \"scroll_depth_bucket\"],\n [AUTO_EVENT_NAMES.webVitals]: [\"metric_name\", \"rating\", \"navigation_type\", \"path\"],\n [AUTO_EVENT_NAMES.exception]: [\"$exception_type\", \"$exception_source\", \"$exception_handled\", \"path\"],\n} as const satisfies Record<AutoEventName, readonly string[]>;\n\n/**\n * `$pageleave.scroll_depth` is the exact 0–100 percentage; `scroll_depth_bucket`\n * is the deepest of these thresholds reached, as a string — the value to\n * break down by. `\"0\"` means the visitor never reached the first threshold.\n */\nexport const SCROLL_DEPTH_BUCKETS = [25, 50, 75, 100] as const;\nexport type ScrollDepthBucket = \"0\" | `${(typeof SCROLL_DEPTH_BUCKETS)[number]}`;\n\nexport function scrollDepthBucket(depth: number): ScrollDepthBucket {\n let reached: ScrollDepthBucket = \"0\";\n for (const threshold of SCROLL_DEPTH_BUCKETS) {\n if (depth >= threshold) reached = `${threshold}`;\n }\n return reached;\n}\n"],"mappings":";AAOO,IAAM,uBAAuB,CAAC,iBAAiB,eAAe,aAAa;AAQ3E,IAAM,mBAAmB;AAAA,EAC9B,UAAU;AAAA,EACV,YAAY;AAAA,EACZ,WAAW;AAAA,EACX,WAAW;AAAA,EACX,WAAW;AACb;AASO,IAAM,wBAAwB;AAAA,EACnC,CAAC,iBAAiB,QAAQ,GAAG;AAAA,IAC3B;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EACA,CAAC,iBAAiB,UAAU,GAAG,CAAC,aAAa;AAAA,EAC7C,CAAC,iBAAiB,SAAS,GAAG,CAAC,QAAQ,UAAU,YAAY,gBAAgB,qBAAqB;AAAA,EAClG,CAAC,iBAAiB,SAAS,GAAG,CAAC,eAAe,aAAa,SAAS,SAAS,UAAU,mBAAmB,MAAM;AAAA;AAAA;AAAA;AAAA,EAIhH,CAAC,iBAAiB,SAAS,GAAG;AAAA,IAC5B;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAUO,IAAM,yBAAyB;AAAA,EACpC,CAAC,iBAAiB,QAAQ,GAAG,CAAC,QAAQ,UAAU,YAAY,cAAc,cAAc,cAAc;AAAA,EACtG,CAAC,iBAAiB,UAAU,GAAG,CAAC,aAAa;AAAA,EAC7C,CAAC,iBAAiB,SAAS,GAAG,CAAC,QAAQ,UAAU,qBAAqB;AAAA,EACtE,CAAC,iBAAiB,SAAS,GAAG,CAAC,eAAe,UAAU,mBAAmB,MAAM;AAAA,EACjF,CAAC,iBAAiB,SAAS,GAAG,CAAC,mBAAmB,qBAAqB,sBAAsB,MAAM;AACrG;AAOO,IAAM,uBAAuB,CAAC,IAAI,IAAI,IAAI,GAAG;AAG7C,SAAS,kBAAkB,OAAkC;AAClE,MAAI,UAA6B;AACjC,aAAW,aAAa,sBAAsB;AAC5C,QAAI,SAAS,UAAW,WAAU,GAAG,SAAS;AAAA,EAChD;AACA,SAAO;AACT;","names":[]}
|
package/dist/chunk-JCEWUSUM.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
// src/index.ts
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
var zDate = z.string().regex(/^\d{4}-\d{2}-\d{2}$/, "expected YYYY-MM-DD").refine(isRealCalendarDate, "date does not exist");
|
|
4
|
-
function isRealCalendarDate(value) {
|
|
5
|
-
if (!/^\d{4}-\d{2}-\d{2}$/.test(value)) return false;
|
|
6
|
-
const [year, month, day] = value.split("-").map(Number);
|
|
7
|
-
const instant = new Date(Date.UTC(year, month - 1, day));
|
|
8
|
-
return instant.getUTCFullYear() === year && instant.getUTCMonth() === month - 1 && instant.getUTCDate() === day;
|
|
9
|
-
}
|
|
10
|
-
var zInstant = z.string().min(20);
|
|
11
|
-
var DataApiError = class _DataApiError extends Error {
|
|
12
|
-
/**
|
|
13
|
-
* Brand for {@link DataApiError.is}. A bundler that inlines this module into
|
|
14
|
-
* more than one entry point produces two distinct classes, and `instanceof`
|
|
15
|
-
* silently stops matching — the brand survives that, and realm boundaries.
|
|
16
|
-
*/
|
|
17
|
-
isDataApiError = true;
|
|
18
|
-
status;
|
|
19
|
-
code;
|
|
20
|
-
requestId;
|
|
21
|
-
/** Parsed from `Retry-After`, in milliseconds. Only set on 429. */
|
|
22
|
-
retryAfterMs;
|
|
23
|
-
/** zod issues for `validation_failed`, or the raw body when unparseable. */
|
|
24
|
-
details;
|
|
25
|
-
constructor(init) {
|
|
26
|
-
super(init.message);
|
|
27
|
-
this.name = "DataApiError";
|
|
28
|
-
this.status = init.status;
|
|
29
|
-
this.code = init.code;
|
|
30
|
-
this.requestId = init.requestId;
|
|
31
|
-
this.retryAfterMs = init.retryAfterMs;
|
|
32
|
-
this.details = init.details;
|
|
33
|
-
}
|
|
34
|
-
/** 429 and 5xx are worth retrying; 4xx are the caller's fault and are not. */
|
|
35
|
-
get retryable() {
|
|
36
|
-
return this.status === 429 || this.status >= 500;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Prefer this over `instanceof` in a `catch`. It holds even when the class
|
|
40
|
-
* has been duplicated — across CJS entry points, across bundler chunks, or
|
|
41
|
-
* across realms — where `instanceof` quietly returns false.
|
|
42
|
-
*/
|
|
43
|
-
static is(value) {
|
|
44
|
-
return value instanceof _DataApiError || typeof value === "object" && value !== null && value.isDataApiError === true;
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export {
|
|
49
|
-
zDate,
|
|
50
|
-
zInstant,
|
|
51
|
-
DataApiError
|
|
52
|
-
};
|
|
53
|
-
//# sourceMappingURL=chunk-JCEWUSUM.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * `@reopt-ai/data-contract` — the wire contract between reopt-data and its\n * server-credential consumers (RFC-0023).\n *\n * Subpaths:\n * `@reopt-ai/data-contract` this module — version, shared primitives, errors\n * `@reopt-ai/data-contract/ingest` POST /api/track request + response schemas\n * `@reopt-ai/data-contract/query` POST /api/v1/query/* request + response schemas\n * `@reopt-ai/data-contract/control` provisioning request + response schemas\n * `@reopt-ai/data-contract/client` createDataClient() — typed fetch over all\n * `@reopt-ai/data-contract/events` event names + property keys (no zod)\n * `@reopt-ai/data-contract/identity` cookie/header names and encodings shared by\n * the SDKs, the Next.js proxy and ingest\n *\n * Only `/client` touches `fetch`; everything else is pure zod. The single\n * runtime dependency is zod, deliberately — consumers bundle this.\n */\nimport { z } from \"zod\";\n\nexport {\n CONTRACT_VERSION,\n CONTRACT_VERSION_HEADER,\n CLIENT_ID_HEADER,\n CLIENT_SECRET_HEADER,\n WRITE_KEY_HEADER,\n DEVICE_ID_HEADER,\n REQUEST_ID_HEADER,\n} from \"./version.js\";\n\n/**\n * A real calendar date. The query's resolved IANA zone decides which instants\n * its inclusive day covers.\n */\nexport const zDate = z\n .string()\n .regex(/^\\d{4}-\\d{2}-\\d{2}$/, \"expected YYYY-MM-DD\")\n .refine(isRealCalendarDate, \"date does not exist\");\n\nfunction isRealCalendarDate(value: string): boolean {\n if (!/^\\d{4}-\\d{2}-\\d{2}$/.test(value)) return false;\n const [year, month, day] = value.split(\"-\").map(Number);\n const instant = new Date(Date.UTC(year!, month! - 1, day!));\n return instant.getUTCFullYear() === year && instant.getUTCMonth() === month! - 1 && instant.getUTCDate() === day;\n}\n\n/** ISO-8601 instant, as produced by `Date#toISOString()`. */\nexport const zInstant = z.string().min(20);\n\n/**\n * Client credentials. The same pair authenticates both planes; what a given\n * client may reach is decided server-side by `Client.scopes`\n * (`\"ingest\"` / `\"query\"` / `\"provision\"`).\n */\nexport interface ClientCredentials {\n clientId: string;\n clientSecret: string;\n}\n\n/**\n * Credentials are optional on the client itself because the provisioning\n * surface does not use them — it authenticates per call with a platform or\n * organization key. A caller that only provisions should not have to invent an\n * empty client id to satisfy a constructor.\n *\n * Reaching ingest or query without them fails with `credentials_missing`\n * rather than sending an unauthenticated request and reporting the 401 as a\n * server problem.\n */\nexport type OptionalClientCredentials = Partial<ClientCredentials>;\n\n/**\n * Every non-2xx response from either plane, plus the two failures the client\n * itself raises (`contract_mismatch`, `network_error`).\n */\nexport class DataApiError extends Error {\n /**\n * Brand for {@link DataApiError.is}. A bundler that inlines this module into\n * more than one entry point produces two distinct classes, and `instanceof`\n * silently stops matching — the brand survives that, and realm boundaries.\n */\n readonly isDataApiError = true as const;\n\n readonly status: number;\n readonly code: string;\n readonly requestId?: string | undefined;\n /** Parsed from `Retry-After`, in milliseconds. Only set on 429. */\n readonly retryAfterMs?: number | undefined;\n /** zod issues for `validation_failed`, or the raw body when unparseable. */\n readonly details?: unknown | undefined;\n\n constructor(init: {\n message: string;\n status: number;\n code: string;\n requestId?: string | undefined;\n retryAfterMs?: number | undefined;\n details?: unknown | undefined;\n }) {\n super(init.message);\n this.name = \"DataApiError\";\n this.status = init.status;\n this.code = init.code;\n this.requestId = init.requestId;\n this.retryAfterMs = init.retryAfterMs;\n this.details = init.details;\n }\n\n /** 429 and 5xx are worth retrying; 4xx are the caller's fault and are not. */\n get retryable(): boolean {\n return this.status === 429 || this.status >= 500;\n }\n\n /**\n * Prefer this over `instanceof` in a `catch`. It holds even when the class\n * has been duplicated — across CJS entry points, across bundler chunks, or\n * across realms — where `instanceof` quietly returns false.\n */\n static is(value: unknown): value is DataApiError {\n return (\n value instanceof DataApiError ||\n (typeof value === \"object\" && value !== null && (value as { isDataApiError?: unknown }).isDataApiError === true)\n );\n }\n}\n"],"mappings":";AAiBA,SAAS,SAAS;AAgBX,IAAM,QAAQ,EAClB,OAAO,EACP,MAAM,uBAAuB,qBAAqB,EAClD,OAAO,oBAAoB,qBAAqB;AAEnD,SAAS,mBAAmB,OAAwB;AAClD,MAAI,CAAC,sBAAsB,KAAK,KAAK,EAAG,QAAO;AAC/C,QAAM,CAAC,MAAM,OAAO,GAAG,IAAI,MAAM,MAAM,GAAG,EAAE,IAAI,MAAM;AACtD,QAAM,UAAU,IAAI,KAAK,KAAK,IAAI,MAAO,QAAS,GAAG,GAAI,CAAC;AAC1D,SAAO,QAAQ,eAAe,MAAM,QAAQ,QAAQ,YAAY,MAAM,QAAS,KAAK,QAAQ,WAAW,MAAM;AAC/G;AAGO,IAAM,WAAW,EAAE,OAAO,EAAE,IAAI,EAAE;AA4BlC,IAAM,eAAN,MAAM,sBAAqB,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAM7B,iBAAiB;AAAA,EAEjB;AAAA,EACA;AAAA,EACA;AAAA;AAAA,EAEA;AAAA;AAAA,EAEA;AAAA,EAET,YAAY,MAOT;AACD,UAAM,KAAK,OAAO;AAClB,SAAK,OAAO;AACZ,SAAK,SAAS,KAAK;AACnB,SAAK,OAAO,KAAK;AACjB,SAAK,YAAY,KAAK;AACtB,SAAK,eAAe,KAAK;AACzB,SAAK,UAAU,KAAK;AAAA,EACtB;AAAA;AAAA,EAGA,IAAI,YAAqB;AACvB,WAAO,KAAK,WAAW,OAAO,KAAK,UAAU;AAAA,EAC/C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,OAAO,GAAG,OAAuC;AAC/C,WACE,iBAAiB,iBAChB,OAAO,UAAU,YAAY,UAAU,QAAS,MAAuC,mBAAmB;AAAA,EAE/G;AACF;","names":[]}
|