@reopt-ai/data-contract 0.6.2 → 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 +124 -140
- package/dist/control.d.cts.map +1 -0
- package/dist/control.d.ts +124 -140
- 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 +185 -196
- package/dist/ingest.d.cts.map +1 -0
- package/dist/ingest.d.ts +185 -196
- 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 +458 -471
- package/dist/query.d.cts.map +1 -0
- package/dist/query.d.ts +458 -471
- 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-BANKB6Og.d.ts → version-CGujUGWd.d.cts} +5 -3
- package/dist/version-CGujUGWd.d.cts.map +1 -0
- package/dist/{version-BANKB6Og.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-33BCA2LH.js +0 -53
- package/dist/chunk-33BCA2LH.js.map +0 -1
- package/dist/chunk-3EEANNYN.cjs +0 -62
- package/dist/chunk-3EEANNYN.cjs.map +0 -1
- package/dist/chunk-AOS53KAV.cjs +0 -19
- package/dist/chunk-AOS53KAV.cjs.map +0 -1
- package/dist/chunk-BA52YA7N.cjs +0 -179
- package/dist/chunk-BA52YA7N.cjs.map +0 -1
- package/dist/chunk-DUJSYMYY.js +0 -179
- package/dist/chunk-DUJSYMYY.js.map +0 -1
- package/dist/chunk-FMOKJTQD.js +0 -160
- package/dist/chunk-FMOKJTQD.js.map +0 -1
- package/dist/chunk-FP2X3PRK.js +0 -62
- package/dist/chunk-FP2X3PRK.js.map +0 -1
- package/dist/chunk-FQSCQSMP.cjs +0 -160
- package/dist/chunk-FQSCQSMP.cjs.map +0 -1
- package/dist/chunk-FUGY5ANJ.cjs +0 -361
- package/dist/chunk-FUGY5ANJ.cjs.map +0 -1
- package/dist/chunk-IY4MXH35.js +0 -204
- package/dist/chunk-IY4MXH35.js.map +0 -1
- package/dist/chunk-L3WJGIKD.js +0 -361
- package/dist/chunk-L3WJGIKD.js.map +0 -1
- package/dist/chunk-LA5F5KR6.cjs +0 -204
- package/dist/chunk-LA5F5KR6.cjs.map +0 -1
- package/dist/chunk-YSAEOYPD.cjs +0 -53
- package/dist/chunk-YSAEOYPD.cjs.map +0 -1
- package/dist/chunk-ZCKVMUIQ.js +0 -19
- package/dist/chunk-ZCKVMUIQ.js.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-33BCA2LH.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-33BCA2LH.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;\n /** Parsed from `Retry-After`, in milliseconds. Only set on 429. */\n readonly retryAfterMs?: number;\n /** zod issues for `validation_failed`, or the raw body when unparseable. */\n readonly details?: unknown;\n\n constructor(init: {\n message: string;\n status: number;\n code: string;\n requestId?: string;\n retryAfterMs?: number;\n details?: unknown;\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":[]}
|
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,SAAS,CAAA,EAAG,CAAC,aAAA,EAAe,WAAA,EAAa,OAAA,EAAS,OAAA,EAAS,QAAA,EAAU,iBAAA,EAAmB,MAAM,CAAA;AAAA;AAAA;AAAA;AAAA,EAIhH,CAAC,gBAAA,CAAiB,SAAS,CAAA,EAAG;AAAA,IAC5B,iBAAA;AAAA,IACA,oBAAA;AAAA,IACA,kBAAA;AAAA,IACA,mBAAA;AAAA,IACA,oBAAA;AAAA,IACA;AAAA,EACF;AACF,CAAA;AAUO,IAAM,uBAAA,EAAyB;AAAA,EACpC,CAAC,gBAAA,CAAiB,QAAQ,CAAA,EAAG,CAAC,MAAA,EAAQ,QAAA,EAAU,UAAA,EAAY,YAAA,EAAc,YAAA,EAAc,cAAc,CAAA;AAAA,EACtG,CAAC,gBAAA,CAAiB,UAAU,CAAA,EAAG,CAAC,aAAa,CAAA;AAAA,EAC7C,CAAC,gBAAA,CAAiB,SAAS,CAAA,EAAG,CAAC,MAAA,EAAQ,QAAA,EAAU,qBAAqB,CAAA;AAAA,EACtE,CAAC,gBAAA,CAAiB,SAAS,CAAA,EAAG,CAAC,aAAA,EAAe,QAAA,EAAU,iBAAA,EAAmB,MAAM,CAAA;AAAA,EACjF,CAAC,gBAAA,CAAiB,SAAS,CAAA,EAAG,CAAC,iBAAA,EAAmB,mBAAA,EAAqB,oBAAA,EAAsB,MAAM;AACrG,CAAA;AAOO,IAAM,qBAAA,EAAuB,CAAC,EAAA,EAAI,EAAA,EAAI,EAAA,EAAI,GAAG,CAAA;AAG7C,SAAS,iBAAA,CAAkB,KAAA,EAAkC;AAClE,EAAA,IAAI,QAAA,EAA6B,GAAA;AACjC,EAAA,IAAA,CAAA,MAAW,UAAA,GAAa,oBAAA,EAAsB;AAC5C,IAAA,GAAA,CAAI,MAAA,GAAS,SAAA,EAAW,QAAA,EAAU,CAAA,EAAA;AACpC,EAAA;AACO,EAAA;AACT;ADrCuC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/Users/eric/reopt-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-AOS53KAV.cjs
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/version.ts
|
|
2
|
-
var CONTRACT_VERSION = "0.6.2";
|
|
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-AOS53KAV.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/eric/reopt-ai/reopt-data/packages/data-contract/dist/chunk-AOS53KAV.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-AOS53KAV.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.2\";\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-BA52YA7N.cjs
DELETED
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
-
|
|
3
|
-
var _chunkFQSCQSMPcjs = require('./chunk-FQSCQSMP.cjs');
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var _chunk3EEANNYNcjs = require('./chunk-3EEANNYN.cjs');
|
|
7
|
-
|
|
8
|
-
// src/ingest.ts
|
|
9
|
-
var _zod = require('zod');
|
|
10
|
-
var MAX_TRACK_PAYLOAD_BYTES = 512e3;
|
|
11
|
-
var zClientEventMetadata = {
|
|
12
|
-
/**
|
|
13
|
-
* Client-generated UUID. This is the project-scoped idempotency key stored as
|
|
14
|
-
* `RawEvent.clientEventId`; the server uses a separate globally unique raw
|
|
15
|
-
* event id internally. Re-sending the same eventId to the same project is
|
|
16
|
-
* always safe and always reported as a duplicate.
|
|
17
|
-
*/
|
|
18
|
-
eventId: _zod.z.uuid(),
|
|
19
|
-
/** Event time, epoch milliseconds. */
|
|
20
|
-
timestamp: _zod.z.number().int().nonnegative(),
|
|
21
|
-
/**
|
|
22
|
-
* The browser device this event belongs to, for events a server records
|
|
23
|
-
* on a visitor's behalf (a form submission, an order). Lets one server
|
|
24
|
-
* batch carry events from many visitors — a forwarder cannot split its
|
|
25
|
-
* batches per device without breaking its failure model and its
|
|
26
|
-
* `accepted + duplicates + rejected === sent` invariant.
|
|
27
|
-
*
|
|
28
|
-
* Honoured in `server` mode only, where it takes precedence over the
|
|
29
|
-
* `reopt-device-id` request header. Ignored in `browser` mode: there the
|
|
30
|
-
* header is authoritative and a body field would be trivially forged.
|
|
31
|
-
* Same character set as every identity id.
|
|
32
|
-
*/
|
|
33
|
-
deviceId: _zod.z.string().regex(_chunkFQSCQSMPcjs.IDENTITY_ID_PATTERN, "expected an identity id").optional()
|
|
34
|
-
};
|
|
35
|
-
var zTrackPayload = _zod.z.object({
|
|
36
|
-
name: _zod.z.string().min(1).max(200),
|
|
37
|
-
properties: _zod.z.record(_zod.z.string(), _zod.z.unknown()).optional(),
|
|
38
|
-
profileId: _zod.z.string().max(500).or(_zod.z.number()).optional()
|
|
39
|
-
}).refine((data) => !_chunk3EEANNYNcjs.RESERVED_EVENT_NAMES.includes(data.name), {
|
|
40
|
-
message: `Event name cannot be one of the reserved names: ${_chunk3EEANNYNcjs.RESERVED_EVENT_NAMES.join(", ")}`,
|
|
41
|
-
path: ["name"]
|
|
42
|
-
});
|
|
43
|
-
var zIdentifyPayload = _zod.z.object({
|
|
44
|
-
profileId: _zod.z.string().min(1).max(500).or(_zod.z.number()),
|
|
45
|
-
firstName: _zod.z.string().max(200).optional(),
|
|
46
|
-
lastName: _zod.z.string().max(200).optional(),
|
|
47
|
-
email: _zod.z.email().max(320).optional(),
|
|
48
|
-
avatar: _zod.z.url().max(2e3).optional(),
|
|
49
|
-
properties: _zod.z.record(_zod.z.string(), _zod.z.unknown()).optional()
|
|
50
|
-
});
|
|
51
|
-
var zIncrementPayload = _zod.z.object({
|
|
52
|
-
profileId: _zod.z.string().min(1).max(500).or(_zod.z.number()),
|
|
53
|
-
property: _zod.z.string().min(1).max(200),
|
|
54
|
-
value: _zod.z.number().positive().optional()
|
|
55
|
-
});
|
|
56
|
-
var zDecrementPayload = _zod.z.object({
|
|
57
|
-
profileId: _zod.z.string().min(1).max(500).or(_zod.z.number()),
|
|
58
|
-
property: _zod.z.string().min(1).max(200),
|
|
59
|
-
value: _zod.z.number().positive().optional()
|
|
60
|
-
});
|
|
61
|
-
var zTrackHandlerPayload = _zod.z.discriminatedUnion("type", [
|
|
62
|
-
_zod.z.object({ type: _zod.z.literal("track"), payload: zTrackPayload, ...zClientEventMetadata }),
|
|
63
|
-
_zod.z.object({ type: _zod.z.literal("identify"), payload: zIdentifyPayload, ...zClientEventMetadata }),
|
|
64
|
-
_zod.z.object({ type: _zod.z.literal("increment"), payload: zIncrementPayload, ...zClientEventMetadata }),
|
|
65
|
-
_zod.z.object({ type: _zod.z.literal("decrement"), payload: zDecrementPayload, ...zClientEventMetadata })
|
|
66
|
-
]);
|
|
67
|
-
var INGEST_MODES = ["browser", "server"];
|
|
68
|
-
var zIngestMode = _zod.z.enum(INGEST_MODES);
|
|
69
|
-
var INGEST_REJECTION_REASONS = [
|
|
70
|
-
/** Failed the zod schema (bad eventId, missing name, wrong types…). */
|
|
71
|
-
"validation_failed",
|
|
72
|
-
/** Used one of RESERVED_EVENT_NAMES. */
|
|
73
|
-
"reserved_name",
|
|
74
|
-
/** Another row earlier in the same batch already claimed this eventId. */
|
|
75
|
-
"duplicate_in_batch"
|
|
76
|
-
];
|
|
77
|
-
var zIngestRejectionReason = _zod.z.enum(INGEST_REJECTION_REASONS);
|
|
78
|
-
var zIngestRejection = _zod.z.object({
|
|
79
|
-
/** May be absent or malformed on `validation_failed` — hence `string`, not `uuid`. */
|
|
80
|
-
eventId: _zod.z.string(),
|
|
81
|
-
/** Position in the submitted batch. The only reliable identifier when eventId itself is bad. */
|
|
82
|
-
index: _zod.z.number().int().nonnegative(),
|
|
83
|
-
reason: zIngestRejectionReason,
|
|
84
|
-
message: _zod.z.string().optional()
|
|
85
|
-
});
|
|
86
|
-
var ingestCounts = {
|
|
87
|
-
/** Raw events newly persisted by this request. */
|
|
88
|
-
accepted: _zod.z.number().int().nonnegative(),
|
|
89
|
-
/**
|
|
90
|
-
* Events the server already had. In `server` mode this is exactly the
|
|
91
|
-
* eventId-idempotency count; in `browser` mode it also includes the
|
|
92
|
-
* 5-second click dedup.
|
|
93
|
-
*/
|
|
94
|
-
duplicates: _zod.z.number().int().nonnegative(),
|
|
95
|
-
/** Always `[]` in `browser` mode, where a bad row fails the whole batch. */
|
|
96
|
-
rejected: _zod.z.array(zIngestRejection)
|
|
97
|
-
};
|
|
98
|
-
var zSessionCredential = _zod.z.object({
|
|
99
|
-
id: _zod.z.string().regex(_chunkFQSCQSMPcjs.IDENTITY_ID_PATTERN),
|
|
100
|
-
token: _zod.z.string().regex(/^[A-Za-z0-9_-]{43}$/)
|
|
101
|
-
});
|
|
102
|
-
var zIngestOkResponse = _zod.z.object({
|
|
103
|
-
status: _zod.z.literal("ok"),
|
|
104
|
-
requestId: _zod.z.string(),
|
|
105
|
-
mode: zIngestMode,
|
|
106
|
-
...ingestCounts,
|
|
107
|
-
queued: _zod.z.boolean(),
|
|
108
|
-
session: zSessionCredential.optional()
|
|
109
|
-
});
|
|
110
|
-
var zIngestAcceptedResponse = _zod.z.object({
|
|
111
|
-
status: _zod.z.literal("accepted"),
|
|
112
|
-
requestId: _zod.z.string(),
|
|
113
|
-
mode: zIngestMode,
|
|
114
|
-
...ingestCounts,
|
|
115
|
-
backgroundQueued: _zod.z.literal(false),
|
|
116
|
-
replay: _zod.z.literal("unmaterialized-raw-events"),
|
|
117
|
-
session: zSessionCredential.optional()
|
|
118
|
-
});
|
|
119
|
-
var zIngestResponse = _zod.z.discriminatedUnion("status", [zIngestOkResponse, zIngestAcceptedResponse]);
|
|
120
|
-
function reconcileIngestResponse(response, sentCount) {
|
|
121
|
-
return response.accepted + response.duplicates + response.rejected.length === sentCount;
|
|
122
|
-
}
|
|
123
|
-
var INGEST_ERROR_CODES = [
|
|
124
|
-
/** 401 — unknown or mismatched credentials. Stop and alert; do not retry. */
|
|
125
|
-
"unauthorized",
|
|
126
|
-
/** 400 — body was not valid JSON. */
|
|
127
|
-
"invalid_json",
|
|
128
|
-
/** 400 — request exceeded MAX_TRACK_PAYLOAD_BYTES. Split the batch. */
|
|
129
|
-
"payload_too_large",
|
|
130
|
-
/** 400 — zero events submitted. */
|
|
131
|
-
"empty_batch",
|
|
132
|
-
/** 400 — batch contained a `type: "alias"` event, which is not supported. */
|
|
133
|
-
"alias_unsupported",
|
|
134
|
-
/** 400 — the project has no organization; it cannot be billed or quota-checked. */
|
|
135
|
-
"project_without_organization",
|
|
136
|
-
/** 400 — `browser` mode only: a row failed validation. `server` mode reports these in `rejected[]`. */
|
|
137
|
-
"validation_failed",
|
|
138
|
-
/** 429 — per-project request rate limit. `Retry-After` set. Pause this tick, keep the cursor. */
|
|
139
|
-
"rate_limited",
|
|
140
|
-
/** 429 — the organization's monthly event quota is exhausted. `Retry-After` set (capped at 1h). Alert: a human must raise the limit. */
|
|
141
|
-
"quota_exceeded",
|
|
142
|
-
/** 410 — the project is being deleted. Permanent; stop sending. */
|
|
143
|
-
"project_purging",
|
|
144
|
-
/** 500 — unexpected server failure. Back off and retry. */
|
|
145
|
-
"internal_error"
|
|
146
|
-
];
|
|
147
|
-
var zIngestErrorCode = _zod.z.enum(INGEST_ERROR_CODES);
|
|
148
|
-
var zIngestError = _zod.z.object({
|
|
149
|
-
status: _zod.z.number().int(),
|
|
150
|
-
code: zIngestErrorCode,
|
|
151
|
-
error: _zod.z.string(),
|
|
152
|
-
message: _zod.z.string().optional(),
|
|
153
|
-
/** zod issues, when `code === "validation_failed"`. */
|
|
154
|
-
errors: _zod.z.unknown().optional(),
|
|
155
|
-
requestId: _zod.z.string().optional()
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
exports.MAX_TRACK_PAYLOAD_BYTES = MAX_TRACK_PAYLOAD_BYTES; exports.zTrackPayload = zTrackPayload; exports.zIdentifyPayload = zIdentifyPayload; exports.zIncrementPayload = zIncrementPayload; exports.zDecrementPayload = zDecrementPayload; exports.zTrackHandlerPayload = zTrackHandlerPayload; exports.INGEST_MODES = INGEST_MODES; exports.zIngestMode = zIngestMode; exports.INGEST_REJECTION_REASONS = INGEST_REJECTION_REASONS; exports.zIngestRejectionReason = zIngestRejectionReason; exports.zIngestRejection = zIngestRejection; exports.zSessionCredential = zSessionCredential; exports.zIngestOkResponse = zIngestOkResponse; exports.zIngestAcceptedResponse = zIngestAcceptedResponse; exports.zIngestResponse = zIngestResponse; exports.reconcileIngestResponse = reconcileIngestResponse; exports.INGEST_ERROR_CODES = INGEST_ERROR_CODES; exports.zIngestErrorCode = zIngestErrorCode; exports.zIngestError = zIngestError;
|
|
179
|
-
//# sourceMappingURL=chunk-BA52YA7N.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/eric/reopt-ai/reopt-data/packages/data-contract/dist/chunk-BA52YA7N.cjs","../src/ingest.ts"],"names":[],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACA;ACIA,0BAAkB;AAgBX,IAAM,wBAAA,EAA0B,KAAA;AAEvC,IAAM,qBAAA,EAAuB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAO3B,OAAA,EAAS,MAAA,CAAE,IAAA,CAAK,CAAA;AAAA;AAAA,EAEhB,SAAA,EAAW,MAAA,CAAE,MAAA,CAAO,CAAA,CAAE,GAAA,CAAI,CAAA,CAAE,WAAA,CAAY,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaxC,QAAA,EAAU,MAAA,CAAE,MAAA,CAAO,CAAA,CAAE,KAAA,CAAM,qCAAA,EAAqB,yBAAyB,CAAA,CAAE,QAAA,CAAS;AACtF,CAAA;AAEO,IAAM,cAAA,EAAgB,MAAA,CAC1B,MAAA,CAAO;AAAA,EACN,IAAA,EAAM,MAAA,CAAE,MAAA,CAAO,CAAA,CAAE,GAAA,CAAI,CAAC,CAAA,CAAE,GAAA,CAAI,GAAG,CAAA;AAAA,EAC/B,UAAA,EAAY,MAAA,CAAE,MAAA,CAAO,MAAA,CAAE,MAAA,CAAO,CAAA,EAAG,MAAA,CAAE,OAAA,CAAQ,CAAC,CAAA,CAAE,QAAA,CAAS,CAAA;AAAA,EACvD,SAAA,EAAW,MAAA,CAAE,MAAA,CAAO,CAAA,CAAE,GAAA,CAAI,GAAG,CAAA,CAAE,EAAA,CAAG,MAAA,CAAE,MAAA,CAAO,CAAC,CAAA,CAAE,QAAA,CAAS;AACzD,CAAC,CAAA,CACA,MAAA,CAAO,CAAC,IAAA,EAAA,GAAS,CAAC,sCAAA,CAAqB,QAAA,CAAS,IAAA,CAAK,IAAa,CAAA,EAAG;AAAA,EACpE,OAAA,EAAS,CAAA,gDAAA,EAAmD,sCAAA,CAAqB,IAAA,CAAK,IAAI,CAAC,CAAA,CAAA;AAC9E,EAAA;AACd;AAEsC;AACY,EAAA;AACX,EAAA;AACD,EAAA;AACJ,EAAA;AACA,EAAA;AACoB,EAAA;AACxD;AAEyC;AACW,EAAA;AAChB,EAAA;AACG,EAAA;AACvC;AAEyC;AACW,EAAA;AAChB,EAAA;AACG,EAAA;AACvC;AAEgE;AACuB,EAAA;AACM,EAAA;AACpB,EAAA;AACA,EAAA;AACzE;AAqB+C;AACF;AAUN;AAAA;AAEtC,EAAA;AAAA;AAEA,EAAA;AAAA;AAEA,EAAA;AACF;AACqE;AAG5B;AAAA;AAErB,EAAA;AAAA;AAEkB,EAAA;AAC5B,EAAA;AACqB,EAAA;AAC9B;AAGoB;AAAA;AAEoB,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAME,EAAA;AAAA;AAEP,EAAA;AACpC;AAQ2C;AACD,EAAA;AACK,EAAA;AAC9C;AAIyC;AAClB,EAAA;AACF,EAAA;AACd,EAAA;AACH,EAAA;AACe,EAAA;AACmB,EAAA;AACtC;AAQ+C;AAClB,EAAA;AACR,EAAA;AACd,EAAA;AACH,EAAA;AAC8B,EAAA;AACY,EAAA;AACR,EAAA;AACtC;AAEiF;AAcY;AACd,EAAA;AAChF;AAQkC;AAAA;AAEhC,EAAA;AAAA;AAEA,EAAA;AAAA;AAEA,EAAA;AAAA;AAEA,EAAA;AAAA;AAEA,EAAA;AAAA;AAEA,EAAA;AAAA;AAEA,EAAA;AAAA;AAEA,EAAA;AAAA;AAEA,EAAA;AAAA;AAEA,EAAA;AAAA;AAEA,EAAA;AACF;AACyD;AAGpB;AACZ,EAAA;AACjB,EAAA;AACU,EAAA;AACa,EAAA;AAAA;AAEA,EAAA;AACE,EAAA;AAChC;ADlG6F;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/Users/eric/reopt-ai/reopt-data/packages/data-contract/dist/chunk-BA52YA7N.cjs","sourcesContent":[null,"/**\n * `POST /api/track` — the ingest contract.\n *\n * The request shape is shared by both credential modes. The *response* shape\n * is where server-ingest differs: it reports per-event rejections instead of\n * failing a whole batch, because a forwarder that stalls on one malformed row\n * stops forwarding forever.\n *\n * Absorbed from the former internal `@reopt/ingest-contract`; that package is\n * now a deprecated re-export of this module.\n */\nimport { z } from \"zod\";\nimport { IDENTITY_ID_PATTERN } from \"./identity.js\";\n\nexport {\n AUTO_EVENT_NAMES,\n AUTO_EVENT_PROPERTIES,\n AUTO_EVENT_ROLLUP_KEYS,\n RESERVED_EVENT_NAMES,\n SCROLL_DEPTH_BUCKETS,\n scrollDepthBucket,\n type AutoEventName,\n type ScrollDepthBucket,\n} from \"./events.js\";\nimport { RESERVED_EVENT_NAMES } from \"./events.js\";\n\n/** Hard cap enforced by the route before the body is even parsed. */\nexport const MAX_TRACK_PAYLOAD_BYTES = 512_000;\n\nconst zClientEventMetadata = {\n /**\n * Client-generated UUID. This is the project-scoped idempotency key stored as\n * `RawEvent.clientEventId`; the server uses a separate globally unique raw\n * event id internally. Re-sending the same eventId to the same project is\n * always safe and always reported as a duplicate.\n */\n eventId: z.uuid(),\n /** Event time, epoch milliseconds. */\n timestamp: z.number().int().nonnegative(),\n /**\n * The browser device this event belongs to, for events a server records\n * on a visitor's behalf (a form submission, an order). Lets one server\n * batch carry events from many visitors — a forwarder cannot split its\n * batches per device without breaking its failure model and its\n * `accepted + duplicates + rejected === sent` invariant.\n *\n * Honoured in `server` mode only, where it takes precedence over the\n * `reopt-device-id` request header. Ignored in `browser` mode: there the\n * header is authoritative and a body field would be trivially forged.\n * Same character set as every identity id.\n */\n deviceId: z.string().regex(IDENTITY_ID_PATTERN, \"expected an identity id\").optional(),\n};\n\nexport const zTrackPayload = z\n .object({\n name: z.string().min(1).max(200),\n properties: z.record(z.string(), z.unknown()).optional(),\n profileId: z.string().max(500).or(z.number()).optional(),\n })\n .refine((data) => !RESERVED_EVENT_NAMES.includes(data.name as never), {\n message: `Event name cannot be one of the reserved names: ${RESERVED_EVENT_NAMES.join(\", \")}`,\n path: [\"name\"],\n });\n\nexport const zIdentifyPayload = z.object({\n profileId: z.string().min(1).max(500).or(z.number()),\n firstName: z.string().max(200).optional(),\n lastName: z.string().max(200).optional(),\n email: z.email().max(320).optional(),\n avatar: z.url().max(2000).optional(),\n properties: z.record(z.string(), z.unknown()).optional(),\n});\n\nexport const zIncrementPayload = z.object({\n profileId: z.string().min(1).max(500).or(z.number()),\n property: z.string().min(1).max(200),\n value: z.number().positive().optional(),\n});\n\nexport const zDecrementPayload = z.object({\n profileId: z.string().min(1).max(500).or(z.number()),\n property: z.string().min(1).max(200),\n value: z.number().positive().optional(),\n});\n\nexport const zTrackHandlerPayload = z.discriminatedUnion(\"type\", [\n z.object({ type: z.literal(\"track\"), payload: zTrackPayload, ...zClientEventMetadata }),\n z.object({ type: z.literal(\"identify\"), payload: zIdentifyPayload, ...zClientEventMetadata }),\n z.object({ type: z.literal(\"increment\"), payload: zIncrementPayload, ...zClientEventMetadata }),\n z.object({ type: z.literal(\"decrement\"), payload: zDecrementPayload, ...zClientEventMetadata }),\n]);\n\nexport type ITrackPayload = z.infer<typeof zTrackPayload>;\nexport type IIdentifyPayload = z.infer<typeof zIdentifyPayload>;\nexport type IIncrementPayload = z.infer<typeof zIncrementPayload>;\nexport type IDecrementPayload = z.infer<typeof zDecrementPayload>;\nexport type ITrackHandlerPayload = z.infer<typeof zTrackHandlerPayload>;\n\n// ─── Ingest mode ────────────────────────────────────────────────────────────\n\n/**\n * Decided by the credential presented, never by a header the caller sets:\n * `reopt-write-key` alone → `browser`, `reopt-client-id` + `reopt-client-secret`\n * → `server`. A separate mode header could disagree with the credential; this\n * cannot.\n *\n * `browser` keeps the 5-second click dedup and device-scoped sessions.\n * `server` drops both and relies solely on `eventId` idempotency — a server\n * batch legitimately contains the same event name many times within one second,\n * and its \"device\" is a process, not a person.\n */\nexport const INGEST_MODES = [\"browser\", \"server\"] as const;\nexport const zIngestMode = z.enum(INGEST_MODES);\nexport type IngestMode = z.infer<typeof zIngestMode>;\n\n// ─── Response ───────────────────────────────────────────────────────────────\n\n/**\n * Why a single event in a batch was dropped. These are permanent: re-sending\n * the same row produces the same rejection, so a forwarder should count it as\n * skipped and advance its cursor rather than retry.\n */\nexport const INGEST_REJECTION_REASONS = [\n /** Failed the zod schema (bad eventId, missing name, wrong types…). */\n \"validation_failed\",\n /** Used one of RESERVED_EVENT_NAMES. */\n \"reserved_name\",\n /** Another row earlier in the same batch already claimed this eventId. */\n \"duplicate_in_batch\",\n] as const;\nexport const zIngestRejectionReason = z.enum(INGEST_REJECTION_REASONS);\nexport type IngestRejectionReason = z.infer<typeof zIngestRejectionReason>;\n\nexport const zIngestRejection = z.object({\n /** May be absent or malformed on `validation_failed` — hence `string`, not `uuid`. */\n eventId: z.string(),\n /** Position in the submitted batch. The only reliable identifier when eventId itself is bad. */\n index: z.number().int().nonnegative(),\n reason: zIngestRejectionReason,\n message: z.string().optional(),\n});\nexport type IngestRejection = z.infer<typeof zIngestRejection>;\n\nconst ingestCounts = {\n /** Raw events newly persisted by this request. */\n accepted: z.number().int().nonnegative(),\n /**\n * Events the server already had. In `server` mode this is exactly the\n * eventId-idempotency count; in `browser` mode it also includes the\n * 5-second click dedup.\n */\n duplicates: z.number().int().nonnegative(),\n /** Always `[]` in `browser` mode, where a bad row fails the whole batch. */\n rejected: z.array(zIngestRejection),\n};\n\n/**\n * The session ingest filed this batch under, with the token that lets the\n * browser (or a server acting for it) join the same session later with\n * authority — see `signSessionToken` in `./identity`. Browser mode only;\n * absent when the batch carried no sessionable event.\n */\nexport const zSessionCredential = z.object({\n id: z.string().regex(IDENTITY_ID_PATTERN),\n token: z.string().regex(/^[A-Za-z0-9_-]{43}$/),\n});\nexport type SessionCredential = z.infer<typeof zSessionCredential>;\n\n/** 200 — accepted and handed to the materialize queue. */\nexport const zIngestOkResponse = z.object({\n status: z.literal(\"ok\"),\n requestId: z.string(),\n mode: zIngestMode,\n ...ingestCounts,\n queued: z.boolean(),\n session: zSessionCredential.optional(),\n});\n\n/**\n * 202 — raw events landed, but enqueueing the materialize task failed. No data\n * is lost: the `replay-unmaterialized` cron picks these up. A forwarder should\n * treat this as success and advance its cursor. Carries the same counts as 200\n * so the reconciliation below works here too.\n */\nexport const zIngestAcceptedResponse = z.object({\n status: z.literal(\"accepted\"),\n requestId: z.string(),\n mode: zIngestMode,\n ...ingestCounts,\n backgroundQueued: z.literal(false),\n replay: z.literal(\"unmaterialized-raw-events\"),\n session: zSessionCredential.optional(),\n});\n\nexport const zIngestResponse = z.discriminatedUnion(\"status\", [zIngestOkResponse, zIngestAcceptedResponse]);\n\nexport type IngestOkResponse = z.infer<typeof zIngestOkResponse>;\nexport type IngestAcceptedResponse = z.infer<typeof zIngestAcceptedResponse>;\nexport type IngestResponse = z.infer<typeof zIngestResponse>;\n\n/**\n * The reconciliation a forwarder runs on every 2xx:\n *\n * accepted + duplicates + rejected.length === events sent\n *\n * A mismatch means the server silently dropped something, which is exactly the\n * failure mode this contract exists to make impossible to miss.\n */\nexport function reconcileIngestResponse(response: IngestResponse, sentCount: number): boolean {\n return response.accepted + response.duplicates + response.rejected.length === sentCount;\n}\n\n// ─── Errors ─────────────────────────────────────────────────────────────────\n\n/**\n * Stable machine-readable codes. Branch on these, never on `error`/`message`,\n * which are prose and may be reworded.\n */\nexport const INGEST_ERROR_CODES = [\n /** 401 — unknown or mismatched credentials. Stop and alert; do not retry. */\n \"unauthorized\",\n /** 400 — body was not valid JSON. */\n \"invalid_json\",\n /** 400 — request exceeded MAX_TRACK_PAYLOAD_BYTES. Split the batch. */\n \"payload_too_large\",\n /** 400 — zero events submitted. */\n \"empty_batch\",\n /** 400 — batch contained a `type: \"alias\"` event, which is not supported. */\n \"alias_unsupported\",\n /** 400 — the project has no organization; it cannot be billed or quota-checked. */\n \"project_without_organization\",\n /** 400 — `browser` mode only: a row failed validation. `server` mode reports these in `rejected[]`. */\n \"validation_failed\",\n /** 429 — per-project request rate limit. `Retry-After` set. Pause this tick, keep the cursor. */\n \"rate_limited\",\n /** 429 — the organization's monthly event quota is exhausted. `Retry-After` set (capped at 1h). Alert: a human must raise the limit. */\n \"quota_exceeded\",\n /** 410 — the project is being deleted. Permanent; stop sending. */\n \"project_purging\",\n /** 500 — unexpected server failure. Back off and retry. */\n \"internal_error\",\n] as const;\nexport const zIngestErrorCode = z.enum(INGEST_ERROR_CODES);\nexport type IngestErrorCode = z.infer<typeof zIngestErrorCode>;\n\nexport const zIngestError = z.object({\n status: z.number().int(),\n code: zIngestErrorCode,\n error: z.string(),\n message: z.string().optional(),\n /** zod issues, when `code === \"validation_failed\"`. */\n errors: z.unknown().optional(),\n requestId: z.string().optional(),\n});\nexport type IngestError = z.infer<typeof zIngestError>;\n"]}
|