@reopt-ai/data-contract 0.2.0 → 0.5.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/README.md +11 -4
- package/dist/{chunk-IKOEYZVT.js → chunk-2LZBZXBF.js} +9 -3
- package/dist/chunk-2LZBZXBF.js.map +1 -0
- package/dist/{chunk-LBSBZO7O.cjs → chunk-4B4AY44F.cjs} +33 -7
- package/dist/chunk-4B4AY44F.cjs.map +1 -0
- package/dist/{chunk-2SJPZP2D.js → chunk-AHXPQQKO.js} +30 -4
- package/dist/chunk-AHXPQQKO.js.map +1 -0
- package/dist/{chunk-SC7TFGTO.js → chunk-BCGR27G2.js} +130 -14
- package/dist/chunk-BCGR27G2.js.map +1 -0
- package/dist/{chunk-FRJK7OCQ.js → chunk-MFZEIH5Z.js} +7 -4
- package/dist/chunk-MFZEIH5Z.js.map +1 -0
- package/dist/{chunk-CSTC3ADG.cjs → chunk-OLSMH4RY.cjs} +9 -3
- package/dist/chunk-OLSMH4RY.cjs.map +1 -0
- package/dist/{chunk-GCLUMVPA.cjs → chunk-VQ2CD5MG.cjs} +138 -22
- package/dist/chunk-VQ2CD5MG.cjs.map +1 -0
- package/dist/{chunk-HRKELGGH.cjs → chunk-XI3VP5DN.cjs} +7 -4
- package/dist/chunk-XI3VP5DN.cjs.map +1 -0
- package/dist/client.cjs +94 -44
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +8 -4
- package/dist/client.d.ts +8 -4
- package/dist/client.js +58 -8
- package/dist/client.js.map +1 -1
- package/dist/control.cjs +14 -4
- package/dist/control.cjs.map +1 -1
- package/dist/control.d.cts +49 -7
- package/dist/control.d.ts +49 -7
- package/dist/control.js +15 -5
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +15 -4
- package/dist/index.d.ts +15 -4
- package/dist/index.js +1 -1
- package/dist/ingest.cjs +2 -2
- package/dist/ingest.d.cts +9 -7
- package/dist/ingest.d.ts +9 -7
- package/dist/ingest.js +1 -1
- package/dist/query.cjs +29 -3
- package/dist/query.cjs.map +1 -1
- package/dist/query.d.cts +317 -21
- package/dist/query.d.ts +317 -21
- package/dist/query.js +30 -4
- package/dist/report.cjs +85 -0
- package/dist/report.cjs.map +1 -0
- package/dist/report.d.cts +167 -0
- package/dist/report.d.ts +167 -0
- package/dist/report.js +85 -0
- package/dist/report.js.map +1 -0
- package/package.json +7 -2
- package/dist/chunk-2SJPZP2D.js.map +0 -1
- package/dist/chunk-CSTC3ADG.cjs.map +0 -1
- package/dist/chunk-FRJK7OCQ.js.map +0 -1
- package/dist/chunk-GCLUMVPA.cjs.map +0 -1
- package/dist/chunk-HRKELGGH.cjs.map +0 -1
- package/dist/chunk-IKOEYZVT.js.map +0 -1
- package/dist/chunk-LBSBZO7O.cjs.map +0 -1
- package/dist/chunk-SC7TFGTO.js.map +0 -1
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
declare const REPORT_SPEC_VERSION: 1;
|
|
4
|
+
declare const zReportRange: z.ZodString;
|
|
5
|
+
declare const zReportInterval: z.ZodEnum<{
|
|
6
|
+
month: "month";
|
|
7
|
+
day: "day";
|
|
8
|
+
hour: "hour";
|
|
9
|
+
week: "week";
|
|
10
|
+
minute: "minute";
|
|
11
|
+
}>;
|
|
12
|
+
declare const zLegacyChartType: z.ZodEnum<{
|
|
13
|
+
linear: "linear";
|
|
14
|
+
bar: "bar";
|
|
15
|
+
pie: "pie";
|
|
16
|
+
metric: "metric";
|
|
17
|
+
area: "area";
|
|
18
|
+
gauge: "gauge";
|
|
19
|
+
scatter: "scatter";
|
|
20
|
+
table: "table";
|
|
21
|
+
sparkline: "sparkline";
|
|
22
|
+
}>;
|
|
23
|
+
declare const zTimeseriesReportSpec: z.ZodObject<{
|
|
24
|
+
kind: z.ZodLiteral<"timeseries">;
|
|
25
|
+
chartType: z.ZodEnum<{
|
|
26
|
+
linear: "linear";
|
|
27
|
+
bar: "bar";
|
|
28
|
+
pie: "pie";
|
|
29
|
+
metric: "metric";
|
|
30
|
+
area: "area";
|
|
31
|
+
gauge: "gauge";
|
|
32
|
+
scatter: "scatter";
|
|
33
|
+
table: "table";
|
|
34
|
+
sparkline: "sparkline";
|
|
35
|
+
}>;
|
|
36
|
+
interval: z.ZodEnum<{
|
|
37
|
+
month: "month";
|
|
38
|
+
day: "day";
|
|
39
|
+
hour: "hour";
|
|
40
|
+
week: "week";
|
|
41
|
+
minute: "minute";
|
|
42
|
+
}>;
|
|
43
|
+
events: z.ZodArray<z.ZodObject<{
|
|
44
|
+
name: z.ZodString;
|
|
45
|
+
}, z.core.$strip>>;
|
|
46
|
+
breakdowns: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
47
|
+
comparePrevious: z.ZodDefault<z.ZodBoolean>;
|
|
48
|
+
version: z.ZodLiteral<1>;
|
|
49
|
+
range: z.ZodDefault<z.ZodString>;
|
|
50
|
+
segmentId: z.ZodOptional<z.ZodString>;
|
|
51
|
+
}, z.core.$strip>;
|
|
52
|
+
declare const zFunnelReportSpec: z.ZodObject<{
|
|
53
|
+
kind: z.ZodLiteral<"funnel">;
|
|
54
|
+
steps: z.ZodArray<z.ZodString>;
|
|
55
|
+
windowSeconds: z.ZodDefault<z.ZodNumber>;
|
|
56
|
+
version: z.ZodLiteral<1>;
|
|
57
|
+
range: z.ZodDefault<z.ZodString>;
|
|
58
|
+
segmentId: z.ZodOptional<z.ZodString>;
|
|
59
|
+
}, z.core.$strip>;
|
|
60
|
+
declare const zRetentionReportSpec: z.ZodObject<{
|
|
61
|
+
kind: z.ZodLiteral<"retention">;
|
|
62
|
+
interval: z.ZodDefault<z.ZodEnum<{
|
|
63
|
+
month: "month";
|
|
64
|
+
day: "day";
|
|
65
|
+
week: "week";
|
|
66
|
+
}>>;
|
|
67
|
+
periods: z.ZodDefault<z.ZodNumber>;
|
|
68
|
+
startEvent: z.ZodOptional<z.ZodString>;
|
|
69
|
+
returnEvent: z.ZodOptional<z.ZodString>;
|
|
70
|
+
retentionType: z.ZodDefault<z.ZodEnum<{
|
|
71
|
+
bounded: "bounded";
|
|
72
|
+
unbounded: "unbounded";
|
|
73
|
+
}>>;
|
|
74
|
+
cohortMode: z.ZodDefault<z.ZodEnum<{
|
|
75
|
+
"first-ever": "first-ever";
|
|
76
|
+
"first-in-window": "first-in-window";
|
|
77
|
+
}>>;
|
|
78
|
+
version: z.ZodLiteral<1>;
|
|
79
|
+
range: z.ZodDefault<z.ZodString>;
|
|
80
|
+
segmentId: z.ZodOptional<z.ZodString>;
|
|
81
|
+
}, z.core.$strip>;
|
|
82
|
+
declare const zPathReportSpec: z.ZodObject<{
|
|
83
|
+
kind: z.ZodLiteral<"path">;
|
|
84
|
+
limit: z.ZodDefault<z.ZodNumber>;
|
|
85
|
+
startPage: z.ZodOptional<z.ZodString>;
|
|
86
|
+
endPage: z.ZodOptional<z.ZodString>;
|
|
87
|
+
version: z.ZodLiteral<1>;
|
|
88
|
+
range: z.ZodDefault<z.ZodString>;
|
|
89
|
+
segmentId: z.ZodOptional<z.ZodString>;
|
|
90
|
+
}, z.core.$strip>;
|
|
91
|
+
declare const zReportSpec: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
92
|
+
kind: z.ZodLiteral<"timeseries">;
|
|
93
|
+
chartType: z.ZodEnum<{
|
|
94
|
+
linear: "linear";
|
|
95
|
+
bar: "bar";
|
|
96
|
+
pie: "pie";
|
|
97
|
+
metric: "metric";
|
|
98
|
+
area: "area";
|
|
99
|
+
gauge: "gauge";
|
|
100
|
+
scatter: "scatter";
|
|
101
|
+
table: "table";
|
|
102
|
+
sparkline: "sparkline";
|
|
103
|
+
}>;
|
|
104
|
+
interval: z.ZodEnum<{
|
|
105
|
+
month: "month";
|
|
106
|
+
day: "day";
|
|
107
|
+
hour: "hour";
|
|
108
|
+
week: "week";
|
|
109
|
+
minute: "minute";
|
|
110
|
+
}>;
|
|
111
|
+
events: z.ZodArray<z.ZodObject<{
|
|
112
|
+
name: z.ZodString;
|
|
113
|
+
}, z.core.$strip>>;
|
|
114
|
+
breakdowns: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
115
|
+
comparePrevious: z.ZodDefault<z.ZodBoolean>;
|
|
116
|
+
version: z.ZodLiteral<1>;
|
|
117
|
+
range: z.ZodDefault<z.ZodString>;
|
|
118
|
+
segmentId: z.ZodOptional<z.ZodString>;
|
|
119
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
120
|
+
kind: z.ZodLiteral<"funnel">;
|
|
121
|
+
steps: z.ZodArray<z.ZodString>;
|
|
122
|
+
windowSeconds: z.ZodDefault<z.ZodNumber>;
|
|
123
|
+
version: z.ZodLiteral<1>;
|
|
124
|
+
range: z.ZodDefault<z.ZodString>;
|
|
125
|
+
segmentId: z.ZodOptional<z.ZodString>;
|
|
126
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
127
|
+
kind: z.ZodLiteral<"retention">;
|
|
128
|
+
interval: z.ZodDefault<z.ZodEnum<{
|
|
129
|
+
month: "month";
|
|
130
|
+
day: "day";
|
|
131
|
+
week: "week";
|
|
132
|
+
}>>;
|
|
133
|
+
periods: z.ZodDefault<z.ZodNumber>;
|
|
134
|
+
startEvent: z.ZodOptional<z.ZodString>;
|
|
135
|
+
returnEvent: z.ZodOptional<z.ZodString>;
|
|
136
|
+
retentionType: z.ZodDefault<z.ZodEnum<{
|
|
137
|
+
bounded: "bounded";
|
|
138
|
+
unbounded: "unbounded";
|
|
139
|
+
}>>;
|
|
140
|
+
cohortMode: z.ZodDefault<z.ZodEnum<{
|
|
141
|
+
"first-ever": "first-ever";
|
|
142
|
+
"first-in-window": "first-in-window";
|
|
143
|
+
}>>;
|
|
144
|
+
version: z.ZodLiteral<1>;
|
|
145
|
+
range: z.ZodDefault<z.ZodString>;
|
|
146
|
+
segmentId: z.ZodOptional<z.ZodString>;
|
|
147
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
148
|
+
kind: z.ZodLiteral<"path">;
|
|
149
|
+
limit: z.ZodDefault<z.ZodNumber>;
|
|
150
|
+
startPage: z.ZodOptional<z.ZodString>;
|
|
151
|
+
endPage: z.ZodOptional<z.ZodString>;
|
|
152
|
+
version: z.ZodLiteral<1>;
|
|
153
|
+
range: z.ZodDefault<z.ZodString>;
|
|
154
|
+
segmentId: z.ZodOptional<z.ZodString>;
|
|
155
|
+
}, z.core.$strip>], "kind">;
|
|
156
|
+
type ReportSpec = z.infer<typeof zReportSpec>;
|
|
157
|
+
type TimeseriesReportSpec = z.infer<typeof zTimeseriesReportSpec>;
|
|
158
|
+
/** Convert a pre-ReportSpec row into the canonical v1 representation. */
|
|
159
|
+
declare function legacyReportToSpec(input: {
|
|
160
|
+
chartType: z.infer<typeof zLegacyChartType>;
|
|
161
|
+
interval: z.infer<typeof zReportInterval>;
|
|
162
|
+
range: string;
|
|
163
|
+
events: unknown;
|
|
164
|
+
breakdowns: unknown;
|
|
165
|
+
}): TimeseriesReportSpec;
|
|
166
|
+
|
|
167
|
+
export { REPORT_SPEC_VERSION, type ReportSpec, type TimeseriesReportSpec, legacyReportToSpec, zFunnelReportSpec, zLegacyChartType, zPathReportSpec, zReportInterval, zReportRange, zReportSpec, zRetentionReportSpec, zTimeseriesReportSpec };
|
package/dist/report.d.ts
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
declare const REPORT_SPEC_VERSION: 1;
|
|
4
|
+
declare const zReportRange: z.ZodString;
|
|
5
|
+
declare const zReportInterval: z.ZodEnum<{
|
|
6
|
+
month: "month";
|
|
7
|
+
day: "day";
|
|
8
|
+
hour: "hour";
|
|
9
|
+
week: "week";
|
|
10
|
+
minute: "minute";
|
|
11
|
+
}>;
|
|
12
|
+
declare const zLegacyChartType: z.ZodEnum<{
|
|
13
|
+
linear: "linear";
|
|
14
|
+
bar: "bar";
|
|
15
|
+
pie: "pie";
|
|
16
|
+
metric: "metric";
|
|
17
|
+
area: "area";
|
|
18
|
+
gauge: "gauge";
|
|
19
|
+
scatter: "scatter";
|
|
20
|
+
table: "table";
|
|
21
|
+
sparkline: "sparkline";
|
|
22
|
+
}>;
|
|
23
|
+
declare const zTimeseriesReportSpec: z.ZodObject<{
|
|
24
|
+
kind: z.ZodLiteral<"timeseries">;
|
|
25
|
+
chartType: z.ZodEnum<{
|
|
26
|
+
linear: "linear";
|
|
27
|
+
bar: "bar";
|
|
28
|
+
pie: "pie";
|
|
29
|
+
metric: "metric";
|
|
30
|
+
area: "area";
|
|
31
|
+
gauge: "gauge";
|
|
32
|
+
scatter: "scatter";
|
|
33
|
+
table: "table";
|
|
34
|
+
sparkline: "sparkline";
|
|
35
|
+
}>;
|
|
36
|
+
interval: z.ZodEnum<{
|
|
37
|
+
month: "month";
|
|
38
|
+
day: "day";
|
|
39
|
+
hour: "hour";
|
|
40
|
+
week: "week";
|
|
41
|
+
minute: "minute";
|
|
42
|
+
}>;
|
|
43
|
+
events: z.ZodArray<z.ZodObject<{
|
|
44
|
+
name: z.ZodString;
|
|
45
|
+
}, z.core.$strip>>;
|
|
46
|
+
breakdowns: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
47
|
+
comparePrevious: z.ZodDefault<z.ZodBoolean>;
|
|
48
|
+
version: z.ZodLiteral<1>;
|
|
49
|
+
range: z.ZodDefault<z.ZodString>;
|
|
50
|
+
segmentId: z.ZodOptional<z.ZodString>;
|
|
51
|
+
}, z.core.$strip>;
|
|
52
|
+
declare const zFunnelReportSpec: z.ZodObject<{
|
|
53
|
+
kind: z.ZodLiteral<"funnel">;
|
|
54
|
+
steps: z.ZodArray<z.ZodString>;
|
|
55
|
+
windowSeconds: z.ZodDefault<z.ZodNumber>;
|
|
56
|
+
version: z.ZodLiteral<1>;
|
|
57
|
+
range: z.ZodDefault<z.ZodString>;
|
|
58
|
+
segmentId: z.ZodOptional<z.ZodString>;
|
|
59
|
+
}, z.core.$strip>;
|
|
60
|
+
declare const zRetentionReportSpec: z.ZodObject<{
|
|
61
|
+
kind: z.ZodLiteral<"retention">;
|
|
62
|
+
interval: z.ZodDefault<z.ZodEnum<{
|
|
63
|
+
month: "month";
|
|
64
|
+
day: "day";
|
|
65
|
+
week: "week";
|
|
66
|
+
}>>;
|
|
67
|
+
periods: z.ZodDefault<z.ZodNumber>;
|
|
68
|
+
startEvent: z.ZodOptional<z.ZodString>;
|
|
69
|
+
returnEvent: z.ZodOptional<z.ZodString>;
|
|
70
|
+
retentionType: z.ZodDefault<z.ZodEnum<{
|
|
71
|
+
bounded: "bounded";
|
|
72
|
+
unbounded: "unbounded";
|
|
73
|
+
}>>;
|
|
74
|
+
cohortMode: z.ZodDefault<z.ZodEnum<{
|
|
75
|
+
"first-ever": "first-ever";
|
|
76
|
+
"first-in-window": "first-in-window";
|
|
77
|
+
}>>;
|
|
78
|
+
version: z.ZodLiteral<1>;
|
|
79
|
+
range: z.ZodDefault<z.ZodString>;
|
|
80
|
+
segmentId: z.ZodOptional<z.ZodString>;
|
|
81
|
+
}, z.core.$strip>;
|
|
82
|
+
declare const zPathReportSpec: z.ZodObject<{
|
|
83
|
+
kind: z.ZodLiteral<"path">;
|
|
84
|
+
limit: z.ZodDefault<z.ZodNumber>;
|
|
85
|
+
startPage: z.ZodOptional<z.ZodString>;
|
|
86
|
+
endPage: z.ZodOptional<z.ZodString>;
|
|
87
|
+
version: z.ZodLiteral<1>;
|
|
88
|
+
range: z.ZodDefault<z.ZodString>;
|
|
89
|
+
segmentId: z.ZodOptional<z.ZodString>;
|
|
90
|
+
}, z.core.$strip>;
|
|
91
|
+
declare const zReportSpec: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
92
|
+
kind: z.ZodLiteral<"timeseries">;
|
|
93
|
+
chartType: z.ZodEnum<{
|
|
94
|
+
linear: "linear";
|
|
95
|
+
bar: "bar";
|
|
96
|
+
pie: "pie";
|
|
97
|
+
metric: "metric";
|
|
98
|
+
area: "area";
|
|
99
|
+
gauge: "gauge";
|
|
100
|
+
scatter: "scatter";
|
|
101
|
+
table: "table";
|
|
102
|
+
sparkline: "sparkline";
|
|
103
|
+
}>;
|
|
104
|
+
interval: z.ZodEnum<{
|
|
105
|
+
month: "month";
|
|
106
|
+
day: "day";
|
|
107
|
+
hour: "hour";
|
|
108
|
+
week: "week";
|
|
109
|
+
minute: "minute";
|
|
110
|
+
}>;
|
|
111
|
+
events: z.ZodArray<z.ZodObject<{
|
|
112
|
+
name: z.ZodString;
|
|
113
|
+
}, z.core.$strip>>;
|
|
114
|
+
breakdowns: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
115
|
+
comparePrevious: z.ZodDefault<z.ZodBoolean>;
|
|
116
|
+
version: z.ZodLiteral<1>;
|
|
117
|
+
range: z.ZodDefault<z.ZodString>;
|
|
118
|
+
segmentId: z.ZodOptional<z.ZodString>;
|
|
119
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
120
|
+
kind: z.ZodLiteral<"funnel">;
|
|
121
|
+
steps: z.ZodArray<z.ZodString>;
|
|
122
|
+
windowSeconds: z.ZodDefault<z.ZodNumber>;
|
|
123
|
+
version: z.ZodLiteral<1>;
|
|
124
|
+
range: z.ZodDefault<z.ZodString>;
|
|
125
|
+
segmentId: z.ZodOptional<z.ZodString>;
|
|
126
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
127
|
+
kind: z.ZodLiteral<"retention">;
|
|
128
|
+
interval: z.ZodDefault<z.ZodEnum<{
|
|
129
|
+
month: "month";
|
|
130
|
+
day: "day";
|
|
131
|
+
week: "week";
|
|
132
|
+
}>>;
|
|
133
|
+
periods: z.ZodDefault<z.ZodNumber>;
|
|
134
|
+
startEvent: z.ZodOptional<z.ZodString>;
|
|
135
|
+
returnEvent: z.ZodOptional<z.ZodString>;
|
|
136
|
+
retentionType: z.ZodDefault<z.ZodEnum<{
|
|
137
|
+
bounded: "bounded";
|
|
138
|
+
unbounded: "unbounded";
|
|
139
|
+
}>>;
|
|
140
|
+
cohortMode: z.ZodDefault<z.ZodEnum<{
|
|
141
|
+
"first-ever": "first-ever";
|
|
142
|
+
"first-in-window": "first-in-window";
|
|
143
|
+
}>>;
|
|
144
|
+
version: z.ZodLiteral<1>;
|
|
145
|
+
range: z.ZodDefault<z.ZodString>;
|
|
146
|
+
segmentId: z.ZodOptional<z.ZodString>;
|
|
147
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
148
|
+
kind: z.ZodLiteral<"path">;
|
|
149
|
+
limit: z.ZodDefault<z.ZodNumber>;
|
|
150
|
+
startPage: z.ZodOptional<z.ZodString>;
|
|
151
|
+
endPage: z.ZodOptional<z.ZodString>;
|
|
152
|
+
version: z.ZodLiteral<1>;
|
|
153
|
+
range: z.ZodDefault<z.ZodString>;
|
|
154
|
+
segmentId: z.ZodOptional<z.ZodString>;
|
|
155
|
+
}, z.core.$strip>], "kind">;
|
|
156
|
+
type ReportSpec = z.infer<typeof zReportSpec>;
|
|
157
|
+
type TimeseriesReportSpec = z.infer<typeof zTimeseriesReportSpec>;
|
|
158
|
+
/** Convert a pre-ReportSpec row into the canonical v1 representation. */
|
|
159
|
+
declare function legacyReportToSpec(input: {
|
|
160
|
+
chartType: z.infer<typeof zLegacyChartType>;
|
|
161
|
+
interval: z.infer<typeof zReportInterval>;
|
|
162
|
+
range: string;
|
|
163
|
+
events: unknown;
|
|
164
|
+
breakdowns: unknown;
|
|
165
|
+
}): TimeseriesReportSpec;
|
|
166
|
+
|
|
167
|
+
export { REPORT_SPEC_VERSION, type ReportSpec, type TimeseriesReportSpec, legacyReportToSpec, zFunnelReportSpec, zLegacyChartType, zPathReportSpec, zReportInterval, zReportRange, zReportSpec, zRetentionReportSpec, zTimeseriesReportSpec };
|
package/dist/report.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// src/report.ts
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
var REPORT_SPEC_VERSION = 1;
|
|
4
|
+
var zReportRange = z.string().regex(/^\d+[dhm]$/, "expected a relative range such as 7d or 24h");
|
|
5
|
+
var zReportInterval = z.enum(["minute", "hour", "day", "week", "month"]);
|
|
6
|
+
var zLegacyChartType = z.enum([
|
|
7
|
+
"linear",
|
|
8
|
+
"bar",
|
|
9
|
+
"pie",
|
|
10
|
+
"metric",
|
|
11
|
+
"area",
|
|
12
|
+
"gauge",
|
|
13
|
+
"scatter",
|
|
14
|
+
"table",
|
|
15
|
+
"sparkline"
|
|
16
|
+
]);
|
|
17
|
+
var zCommon = {
|
|
18
|
+
version: z.literal(REPORT_SPEC_VERSION),
|
|
19
|
+
range: zReportRange.default("30d"),
|
|
20
|
+
segmentId: z.string().min(1).optional()
|
|
21
|
+
};
|
|
22
|
+
var zTimeseriesReportSpec = z.object({
|
|
23
|
+
...zCommon,
|
|
24
|
+
kind: z.literal("timeseries"),
|
|
25
|
+
chartType: zLegacyChartType,
|
|
26
|
+
interval: zReportInterval,
|
|
27
|
+
events: z.array(z.object({ name: z.string().min(1).max(200) })).min(1).max(20),
|
|
28
|
+
breakdowns: z.array(z.string().min(1).max(200)).max(5).default([]),
|
|
29
|
+
comparePrevious: z.boolean().default(false)
|
|
30
|
+
});
|
|
31
|
+
var zFunnelReportSpec = z.object({
|
|
32
|
+
...zCommon,
|
|
33
|
+
kind: z.literal("funnel"),
|
|
34
|
+
steps: z.array(z.string().min(1).max(200)).min(2).max(10),
|
|
35
|
+
windowSeconds: z.number().int().min(60).max(2592e3).default(86400)
|
|
36
|
+
});
|
|
37
|
+
var zRetentionReportSpec = z.object({
|
|
38
|
+
...zCommon,
|
|
39
|
+
kind: z.literal("retention"),
|
|
40
|
+
interval: z.enum(["day", "week", "month"]).default("day"),
|
|
41
|
+
periods: z.number().int().min(1).max(30).default(7),
|
|
42
|
+
startEvent: z.string().min(1).max(200).optional(),
|
|
43
|
+
returnEvent: z.string().min(1).max(200).optional(),
|
|
44
|
+
retentionType: z.enum(["bounded", "unbounded"]).default("bounded"),
|
|
45
|
+
cohortMode: z.enum(["first-ever", "first-in-window"]).default("first-ever")
|
|
46
|
+
});
|
|
47
|
+
var zPathReportSpec = z.object({
|
|
48
|
+
...zCommon,
|
|
49
|
+
kind: z.literal("path"),
|
|
50
|
+
limit: z.number().int().min(1).max(100).default(30),
|
|
51
|
+
startPage: z.string().max(2e3).optional(),
|
|
52
|
+
endPage: z.string().max(2e3).optional()
|
|
53
|
+
});
|
|
54
|
+
var zReportSpec = z.discriminatedUnion("kind", [
|
|
55
|
+
zTimeseriesReportSpec,
|
|
56
|
+
zFunnelReportSpec,
|
|
57
|
+
zRetentionReportSpec,
|
|
58
|
+
zPathReportSpec
|
|
59
|
+
]);
|
|
60
|
+
function legacyReportToSpec(input) {
|
|
61
|
+
const events = z.array(z.object({ name: z.string().min(1).max(200) })).safeParse(input.events);
|
|
62
|
+
const breakdowns = z.array(z.string().min(1).max(200)).safeParse(input.breakdowns);
|
|
63
|
+
return zTimeseriesReportSpec.parse({
|
|
64
|
+
version: REPORT_SPEC_VERSION,
|
|
65
|
+
kind: "timeseries",
|
|
66
|
+
chartType: input.chartType,
|
|
67
|
+
interval: input.interval,
|
|
68
|
+
range: input.range,
|
|
69
|
+
events: events.success && events.data.length > 0 ? events.data : [{ name: "$pageview" }],
|
|
70
|
+
breakdowns: breakdowns.success ? breakdowns.data : []
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
export {
|
|
74
|
+
REPORT_SPEC_VERSION,
|
|
75
|
+
legacyReportToSpec,
|
|
76
|
+
zFunnelReportSpec,
|
|
77
|
+
zLegacyChartType,
|
|
78
|
+
zPathReportSpec,
|
|
79
|
+
zReportInterval,
|
|
80
|
+
zReportRange,
|
|
81
|
+
zReportSpec,
|
|
82
|
+
zRetentionReportSpec,
|
|
83
|
+
zTimeseriesReportSpec
|
|
84
|
+
};
|
|
85
|
+
//# sourceMappingURL=report.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/report.ts"],"sourcesContent":["import { z } from \"zod\";\n\nexport const REPORT_SPEC_VERSION = 1 as const;\n\nexport const zReportRange = z.string().regex(/^\\d+[dhm]$/, \"expected a relative range such as 7d or 24h\");\nexport const zReportInterval = z.enum([\"minute\", \"hour\", \"day\", \"week\", \"month\"]);\nexport const zLegacyChartType = z.enum([\n \"linear\",\n \"bar\",\n \"pie\",\n \"metric\",\n \"area\",\n \"gauge\",\n \"scatter\",\n \"table\",\n \"sparkline\",\n]);\n\nconst zCommon = {\n version: z.literal(REPORT_SPEC_VERSION),\n range: zReportRange.default(\"30d\"),\n segmentId: z.string().min(1).optional(),\n};\n\nexport const zTimeseriesReportSpec = z.object({\n ...zCommon,\n kind: z.literal(\"timeseries\"),\n chartType: zLegacyChartType,\n interval: zReportInterval,\n events: z\n .array(z.object({ name: z.string().min(1).max(200) }))\n .min(1)\n .max(20),\n breakdowns: z.array(z.string().min(1).max(200)).max(5).default([]),\n comparePrevious: z.boolean().default(false),\n});\n\nexport const zFunnelReportSpec = z.object({\n ...zCommon,\n kind: z.literal(\"funnel\"),\n steps: z.array(z.string().min(1).max(200)).min(2).max(10),\n windowSeconds: z.number().int().min(60).max(2_592_000).default(86_400),\n});\n\nexport const zRetentionReportSpec = z.object({\n ...zCommon,\n kind: z.literal(\"retention\"),\n interval: z.enum([\"day\", \"week\", \"month\"]).default(\"day\"),\n periods: z.number().int().min(1).max(30).default(7),\n startEvent: z.string().min(1).max(200).optional(),\n returnEvent: z.string().min(1).max(200).optional(),\n retentionType: z.enum([\"bounded\", \"unbounded\"]).default(\"bounded\"),\n cohortMode: z.enum([\"first-ever\", \"first-in-window\"]).default(\"first-ever\"),\n});\n\nexport const zPathReportSpec = z.object({\n ...zCommon,\n kind: z.literal(\"path\"),\n limit: z.number().int().min(1).max(100).default(30),\n startPage: z.string().max(2_000).optional(),\n endPage: z.string().max(2_000).optional(),\n});\n\nexport const zReportSpec = z.discriminatedUnion(\"kind\", [\n zTimeseriesReportSpec,\n zFunnelReportSpec,\n zRetentionReportSpec,\n zPathReportSpec,\n]);\n\nexport type ReportSpec = z.infer<typeof zReportSpec>;\nexport type TimeseriesReportSpec = z.infer<typeof zTimeseriesReportSpec>;\n\n/** Convert a pre-ReportSpec row into the canonical v1 representation. */\nexport function legacyReportToSpec(input: {\n chartType: z.infer<typeof zLegacyChartType>;\n interval: z.infer<typeof zReportInterval>;\n range: string;\n events: unknown;\n breakdowns: unknown;\n}): TimeseriesReportSpec {\n const events = z.array(z.object({ name: z.string().min(1).max(200) })).safeParse(input.events);\n const breakdowns = z.array(z.string().min(1).max(200)).safeParse(input.breakdowns);\n return zTimeseriesReportSpec.parse({\n version: REPORT_SPEC_VERSION,\n kind: \"timeseries\",\n chartType: input.chartType,\n interval: input.interval,\n range: input.range,\n events: events.success && events.data.length > 0 ? events.data : [{ name: \"$pageview\" }],\n breakdowns: breakdowns.success ? breakdowns.data : [],\n });\n}\n"],"mappings":";AAAA,SAAS,SAAS;AAEX,IAAM,sBAAsB;AAE5B,IAAM,eAAe,EAAE,OAAO,EAAE,MAAM,cAAc,6CAA6C;AACjG,IAAM,kBAAkB,EAAE,KAAK,CAAC,UAAU,QAAQ,OAAO,QAAQ,OAAO,CAAC;AACzE,IAAM,mBAAmB,EAAE,KAAK;AAAA,EACrC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAED,IAAM,UAAU;AAAA,EACd,SAAS,EAAE,QAAQ,mBAAmB;AAAA,EACtC,OAAO,aAAa,QAAQ,KAAK;AAAA,EACjC,WAAW,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,SAAS;AACxC;AAEO,IAAM,wBAAwB,EAAE,OAAO;AAAA,EAC5C,GAAG;AAAA,EACH,MAAM,EAAE,QAAQ,YAAY;AAAA,EAC5B,WAAW;AAAA,EACX,UAAU;AAAA,EACV,QAAQ,EACL,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC,EACpD,IAAI,CAAC,EACL,IAAI,E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AE,IAAI,CAAC,EAAE,IAAI,GAAG,EAAE,QAAQ,EAAE;AAAA,EAClD,WAAW,EAAE,OAAO,EAAE,IAAI,GAAK,EAAE,SAAS;AAAA,EAC1C,SAAS,EAAE,OAAO,EAAE,IAAI,GAAK,EAAE,SAAS;AAC1C,CAAC;AAEM,IAAM,cAAc,EAAE,mBAAmB,QAAQ;AAAA,EACtD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAMM,SAAS,mBAAmB,OAMV;AACvB,QAAM,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC,EAAE,UAAU,MAAM,MAAM;AAC7F,QAAM,aAAa,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,IAAI,GAAG,CAAC,EAAE,UAAU,MAAM,UAAU;AACjF,SAAO,sBAAsB,MAAM;AAAA,IACjC,SAAS;AAAA,IACT,MAAM;AAAA,IACN,WAAW,MAAM;AAAA,IACjB,UAAU,MAAM;AAAA,IAChB,OAAO,MAAM;AAAA,IACb,QAAQ,OAAO,WAAW,OAAO,KAAK,SAAS,IAAI,OAAO,OAAO,CAAC,EAAE,MAAM,YAAY,CAAC;AAAA,IACvF,YAAY,WAAW,UAAU,WAAW,OAAO,CAAC;AAAA,EACtD,CAAC;AACH;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reopt-ai/data-contract",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.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": {
|
|
@@ -39,6 +39,11 @@
|
|
|
39
39
|
"types": "./dist/client.d.ts",
|
|
40
40
|
"import": "./dist/client.js",
|
|
41
41
|
"require": "./dist/client.cjs"
|
|
42
|
+
},
|
|
43
|
+
"./report": {
|
|
44
|
+
"types": "./dist/report.d.ts",
|
|
45
|
+
"import": "./dist/report.js",
|
|
46
|
+
"require": "./dist/report.cjs"
|
|
42
47
|
}
|
|
43
48
|
},
|
|
44
49
|
"main": "./dist/index.cjs",
|
|
@@ -62,6 +67,6 @@
|
|
|
62
67
|
"check-types": "tsc --noEmit",
|
|
63
68
|
"dev": "tsup --watch",
|
|
64
69
|
"lint": "oxlint .",
|
|
65
|
-
"test": "
|
|
70
|
+
"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__/package-identity.test.ts"
|
|
66
71
|
}
|
|
67
72
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/control.ts"],"sourcesContent":["/**\n * `POST /api/v1/organizations` · `/api/v1/projects` and friends — the\n * provisioning contract.\n *\n * A project-scoped client credential cannot authenticate the creation of the\n * project it is scoped to, and an organization key cannot authenticate the\n * creation of its own organization. So provisioning runs on two credentials\n * above the client one: a platform key that creates organizations and writes\n * quotas, and an organization key that creates and deletes projects inside one\n * organization.\n *\n * Quota writes sit with the platform key on purpose. Organization keys are held\n * one-per-workspace by the caller and so have a wide exposure surface; a leaked\n * one that could raise its own limits would turn a credential leak into an\n * unbounded bill.\n */\nimport { z } from \"zod\";\nimport { zInstant } from \"./index.js\";\nimport { zTimezone } from \"./query.js\";\n\nexport const PLATFORM_KEY_HEADER = \"reopt-platform-key\";\nexport const ORG_KEY_HEADER = \"reopt-org-key\";\n\n/**\n * The caller's own id for the thing being provisioned.\n *\n * Preferred over an `Idempotency-Key` header because this domain has a real\n * natural key — the caller already has a stable id for the workspace or brand —\n * and a header would make the caller store a second one just to retry safely.\n */\nexport const zExternalId = z.string().min(1).max(191);\n\n// ─── Organizations ──────────────────────────────────────────────────────────\n\nexport const zCreateOrganizationInput = z.object({\n externalId: zExternalId,\n name: z.string().min(1).max(200),\n slug: z\n .string()\n .min(1)\n .max(100)\n .regex(/^[a-z0-9-]+$/, \"lowercase letters, digits and hyphens only\")\n .optional(),\n monthlyEventQuota: z.number().int().nonnegative().optional(),\n monthlyCreditQuota: z.number().int().nonnegative().optional(),\n});\nexport type CreateOrganizationInput = z.input<typeof zCreateOrganizationInput>;\n\nexport const zOrganization = z.object({\n id: z.string(),\n externalId: zExternalId,\n name: z.string(),\n slug: z.string(),\n monthlyEventQuota: z.number().int(),\n monthlyCreditQuota: z.number().int(),\n});\n\nexport const zCreateOrganizationResponse = z.object({\n /** `false` when this externalId already had an organization. */\n created: z.boolean(),\n organization: zOrganization,\n /**\n * Plaintext, returned here and nowhere else.\n *\n * Absent when `created` is `false`: re-issuing on every retry would let a\n * retry quietly multiply live credentials. A caller that lost the key rotates\n * instead — see `POST /api/v1/organizations/{id}/keys`.\n */\n orgKey: z.string().optional(),\n});\nexport type CreateOrganizationResponse = z.infer<typeof zCreateOrganizationResponse>;\n\nexport const zRotateOrganizationKeyResponse = z.object({\n organizationId: z.string(),\n keyPrefix: z.string(),\n /** Plaintext, returned once. Every previously issued key is revoked immediately. */\n orgKey: z.string(),\n});\nexport type RotateOrganizationKeyResponse = z.infer<typeof zRotateOrganizationKeyResponse>;\n\nexport const zUpdateOrganizationQuotaInput = z\n .object({\n monthlyEventQuota: z.number().int().nonnegative().optional(),\n monthlyCreditQuota: z.number().int().nonnegative().optional(),\n })\n .refine((value) => value.monthlyEventQuota !== undefined || value.monthlyCreditQuota !== undefined, {\n message: \"at least one quota must be given\",\n });\nexport type UpdateOrganizationQuotaInput = z.input<typeof zUpdateOrganizationQuotaInput>;\n\nexport const zUpdateOrganizationQuotaResponse = z.object({ organization: zOrganization });\nexport type UpdateOrganizationQuotaResponse = z.infer<typeof zUpdateOrganizationQuotaResponse>;\n\n// ─── Projects ───────────────────────────────────────────────────────────────\n\nexport const zCreateProjectInput = z.object({\n externalId: zExternalId,\n name: z.string().min(1).max(200),\n domain: z.string().max(253).optional(),\n /** Becomes the project's default for every query that omits one. */\n timezone: zTimezone.optional(),\n retentionDays: z.number().int().min(1).max(3650).optional(),\n});\nexport type CreateProjectInput = z.input<typeof zCreateProjectInput>;\n\nexport const zProject = z.object({\n id: z.string(),\n externalId: zExternalId,\n organizationId: z.string(),\n name: z.string(),\n /** The applied value — `\"UTC\"` when none was given. */\n timezone: z.string(),\n retentionDays: z.number().int().nullable(),\n});\n\nexport const zCreateProjectResponse = z.object({\n created: z.boolean(),\n project: zProject,\n /**\n * Two credentials, not one. A key embedded in a browser bundle must not also\n * be able to read the project's analytics, so the browser write key and the\n * server secret are separate rows with different reach.\n */\n clients: z.object({\n browser: z.object({\n id: z.string(),\n /** Public by design, and recoverable — it ships in page source anyway. */\n writeKey: z.string(),\n scopes: z.array(z.string()),\n }),\n server: z.object({\n id: z.string(),\n /** Plaintext, returned once. Absent when `created` is `false`. */\n clientSecret: z.string().optional(),\n scopes: z.array(z.string()),\n }),\n }),\n});\nexport type CreateProjectResponse = z.infer<typeof zCreateProjectResponse>;\n\nexport const zRotateClientSecretResponse = z.object({\n projectId: z.string(),\n clientId: z.string(),\n /** Plaintext, returned once. The previous secret stops working immediately. */\n clientSecret: z.string(),\n});\nexport type RotateClientSecretResponse = z.infer<typeof zRotateClientSecretResponse>;\n\nexport const zDeleteProjectInput = z.object({\n /**\n * A field in the body rather than `?purge=true`. This deletes the project's\n * Postgres rows and every analytics row behind it, with no undo — and a query\n * parameter is far too easy to fire from shell history or a mis-copied URL.\n */\n purge: z.literal(true),\n /** Checked against the project on record; a mismatch is refused. */\n externalId: zExternalId,\n});\nexport type DeleteProjectInput = z.input<typeof zDeleteProjectInput>;\n\nexport const zDeleteProjectResponse = z.object({\n projectId: z.string(),\n /** Idempotent, but it still says which of the two happened. */\n purge: z.enum([\"queued\", \"already-absent\"]),\n /** When the purge was marked. Absent for `already-absent`. */\n purgingAt: zInstant.optional(),\n});\nexport type DeleteProjectResponse = z.infer<typeof zDeleteProjectResponse>;\n\n// ─── Errors ─────────────────────────────────────────────────────────────────\n\nexport const CONTROL_ERROR_CODES = [\n /** 401 — missing or invalid platform key / organization key. */\n \"unauthorized\",\n /** 403 — the organization key belongs to a different organization. */\n \"organization_scope_mismatch\",\n /**\n * 409 — this externalId exists with a materially different configuration.\n * Only fields whose change alters results are compared (see the docs); a\n * renamed brand is not a conflict.\n */\n \"external_id_conflict\",\n /** 409 — the externalId in a delete body does not match the project's. */\n \"project_external_id_mismatch\",\n /** 404 — no such organization or project, on an endpoint that is not idempotent. */\n \"not_found\",\n /** 400 — input failed the schema. */\n \"validation_failed\",\n /** 429 — per-credential rate limit. */\n \"rate_limited\",\n /** 500 — unexpected server failure. */\n \"internal_error\",\n] as const;\nexport const zControlErrorCode = z.enum(CONTROL_ERROR_CODES);\nexport type ControlErrorCode = z.infer<typeof zControlErrorCode>;\n\nexport const zControlError = z.object({\n status: z.number().int(),\n code: zControlErrorCode,\n error: z.string(),\n message: z.string().optional(),\n errors: z.unknown().optional(),\n requestId: z.string().optional(),\n});\nexport type ControlError = z.infer<typeof zControlError>;\n\n/** Paths, so the client and the route handlers cannot drift apart. */\nexport const CONTROL_API_PATHS = {\n organizations: \"/api/v1/organizations\",\n organization: (id: string) => `/api/v1/organizations/${encodeURIComponent(id)}`,\n organizationKeys: (id: string) => `/api/v1/organizations/${encodeURIComponent(id)}/keys`,\n projects: \"/api/v1/projects\",\n project: (id: string) => `/api/v1/projects/${encodeURIComponent(id)}`,\n clientRotate: (projectId: string, clientId: string) =>\n `/api/v1/projects/${encodeURIComponent(projectId)}/clients/${encodeURIComponent(clientId)}/rotate`,\n} as const;\n"],"mappings":";;;;;;;;AAgBA,SAAS,SAAS;AAIX,IAAM,sBAAsB;AAC5B,IAAM,iBAAiB;AASvB,IAAM,cAAc,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,IAAI,GAAG;AAI7C,IAAM,2BAA2B,EAAE,OAAO;AAAA,EAC/C,YAAY;AAAA,EACZ,MAAM,EAAE,OAAO,EAA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AAO,EAAA,CAAG,KAAA,EAAuC;AAC/C,IAAA,OACE,MAAA,WAAiB,cAAA,GAChB,OAAO,MAAA,IAAU,SAAA,GAAY,MAAA,IAAU,KAAA,GAAS,KAAA,CAAuC,eAAA,IAAmB,IAAA;AAAA,EAE/G;AACF,UAAA;AD1DA;AACA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,2aAAC","file":"/Users/eric/reopt-ai/reopt-data/packages/data-contract/dist/chunk-CSTC3ADG.cjs","sourcesContent":[null,"/**\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 *\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\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 */\nexport const CONTRACT_VERSION = \"0.2.0\";\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\n/**\n * A UTC calendar date. Windows are inclusive on both ends and are widened\n * server-side to `startDate T00:00:00Z` .. `endDate T23:59:59Z`.\n */\nexport const zDate = z.string().regex(/^\\d{4}-\\d{2}-\\d{2}$/, \"expected YYYY-MM-DD (UTC)\");\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 * 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"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/ingest.ts"],"sourcesContent":["/**\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\";\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/** 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 idempotency key: it becomes the\n * `RawEvent` primary key, scoped to the project. Re-sending the same\n * eventId is 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\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/** 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});\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});\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 /** 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"],"mappings":";AAWA,SAAS,SAAS;AAGX,IAAM,uBAAuB,CAAC,iBAAiB,eAAe,aAAa;AAG3E,IAAM,0BAA0B;AAEvC,IAAM,uBAAuB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAM3B,SAAS,EAAE,KAAK;AAAA;AAAA,EAEhB,WAAW,EAAE,OAAO,EAAE,IAAI,EAAE,YAAY;AAC1C;AAEO,IAAM,gBAAgB,EAC1B,OAAO;AAAA,EACN,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,IAAI,GAAG;AAAA,EAC/B,YAAY,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,QAAQ,CAAC,EAAE,SAAS;AAAA,EACvD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AA,CAAS,CAAA;AAAA,EAC7B,SAAA,EAAW,MAAA,CAAE,MAAA,CAAO,CAAA,CAAE,QAAA,CAAS;AACjC,CAAC,CAAA;AAIM,IAAM,gBAAA,EAAkB;AAAA,EAC7B,gBAAA,EAAkB,iCAAA;AAAA,EAClB,MAAA,EAAQ,sBAAA;AAAA,EACR,SAAA,EAAW;AACb,CAAA;AD3FA;AACA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,+gCAAC","file":"/Users/eric/reopt-ai/reopt-data/packages/data-contract/dist/chunk-GCLUMVPA.cjs","sourcesContent":[null,"/**\n * `POST /api/v1/query/*` — the read contract.\n *\n * Server credentials, project-scoped: the authenticated client's projectId must\n * equal the `projectId` in the body, or the request is refused. Reads are POSTs\n * because the inputs nest (funnel steps, channel filters) and would not survive\n * a query string; consumers cache on their own side, so HTTP cache semantics\n * buy nothing here.\n *\n * Response shapes mirror the existing dashboard computations exactly — this\n * plane re-exposes them, it does not add new math.\n */\nimport { z } from \"zod\";\nimport { zDate, zInstant } from \"./index.js\";\n\nexport { zDate, zInstant };\n\n/** Bucket width for a time series. */\nexport const zGranularity = z.enum([\"hour\", \"day\", \"week\", \"month\"]);\nexport type Granularity = z.infer<typeof zGranularity>;\n\n/**\n * IANA time zone name, e.g. `Asia/Seoul`. Decides two things at once: where a\n * calendar day starts, and therefore which bucket an event falls in.\n *\n * A Korean brand reading \"23 Aug: 120 visits\" means 23 Aug in Seoul. Computed\n * in UTC, that headline silently covers 23 Aug 09:00 through 24 Aug 09:00 —\n * wrong by nine hours in a way nothing on the page reveals.\n *\n * Validated against the runtime's own zone database rather than a regex, so an\n * unknown name fails here with a clear message instead of deep inside a query.\n */\nexport const zTimezone = z.string().min(1).max(64).refine(isValidTimeZone, { message: \"unknown IANA time zone\" });\n\nexport function isValidTimeZone(value: string): boolean {\n try {\n new Intl.DateTimeFormat(\"en-US\", { timeZone: value });\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Acquisition-channel filter. Every field is a set — an event matches when its\n * value is in the set; omitted fields do not constrain. Mirrors the dashboard's\n * `channelFilterSchema` field-for-field.\n */\nexport const zChannelFilter = z\n .object({\n referrerTypes: z.array(z.string()).optional(),\n channelTypes: z.array(z.string()).optional(),\n utmSources: z.array(z.string()).optional(),\n utmMediums: z.array(z.string()).optional(),\n utmCampaigns: z.array(z.string()).optional(),\n })\n .optional();\nexport type ChannelFilter = z.infer<typeof zChannelFilter>;\n\n// ─── Envelope ───────────────────────────────────────────────────────────────\n\n/**\n * Staleness is reported as two independent numbers, never as one sum, because\n * the two have different remedies: a stale cache resolves itself at the next\n * TTL, while ingest lag means the read model is genuinely behind and the right\n * response is an \"aggregating\" badge, not a refresh.\n */\nexport const zQueryMeta = z.object({\n projectId: z.string(),\n /** When the underlying computation actually ran. On a cache hit, when the cached value was computed. */\n computedAt: zInstant,\n /** Age of the returned computation, in seconds. `0` on a cache miss. */\n cacheAgeSeconds: z.number().int().nonnegative(),\n /**\n * How far behind materialization was when the computation ran, in seconds:\n * the age of the oldest raw event not yet materialized, or `0` when nothing\n * is pending.\n *\n * Deliberately not `now - max(events.created_at)` — that conflates \"the\n * pipeline is behind\" with \"this project is quiet\", and grows without bound\n * on an idle project.\n */\n ingestLagSeconds: z.number().int().nonnegative(),\n cached: z.boolean(),\n /**\n * The time zone actually used to place bucket and window boundaries — the\n * resolved value, not the requested one. Read it rather than assuming the\n * request was honoured: when no zone is given anywhere it is `\"UTC\"`, and\n * that is exactly the case a consumer needs to notice.\n */\n timezone: z.string(),\n requestId: z.string(),\n});\nexport type QueryMeta = z.infer<typeof zQueryMeta>;\n\n/** Every query response is `{ data, meta }`. */\nexport function zQueryEnvelope<T extends z.ZodTypeAny>(data: T) {\n return z.object({ data, meta: zQueryMeta });\n}\n\n// ─── events.timeseries ──────────────────────────────────────────────────────\n\n/**\n * v1 breaks down by `properties` JSON keys only. Built-in columns\n * (country / os / browser / utm_*) have a totals breakdown in the backend but\n * no *time series* variant, and this plane does not add new computations.\n */\nexport const zTimeseriesBreakdown = z.object({\n kind: z.literal(\"property\"),\n key: z.string().min(1).max(200),\n topN: z.number().int().min(1).max(10).default(5),\n});\nexport type TimeseriesBreakdown = z.infer<typeof zTimeseriesBreakdown>;\n\nexport const zEventsTimeseriesInput = z.object({\n projectId: z.string().min(1),\n startDate: zDate,\n endDate: zDate,\n granularity: zGranularity.default(\"day\"),\n /** Omit to count every event in the window. */\n eventName: z.string().min(1).max(200).optional(),\n breakdown: zTimeseriesBreakdown.optional(),\n /**\n * Cannot be combined with `breakdown` — the backend's breakdown time series\n * takes no segment. Sending both is refused with `unsupported_combination`\n * rather than silently ignoring one of them.\n */\n segmentId: z.string().min(1).optional(),\n /** Omit to fall back to the project's configured zone, then to UTC. */\n timezone: zTimezone.optional(),\n});\nexport type EventsTimeseriesInput = z.input<typeof zEventsTimeseriesInput>;\n\nexport const zTimeseriesPoint = z.object({\n /** Bucket start, formatted by the analytics backend for the requested granularity. */\n date: z.string(),\n count: z.number().int().nonnegative(),\n});\nexport type TimeseriesPoint = z.infer<typeof zTimeseriesPoint>;\n\nexport const zEventsTimeseriesData = z.object({\n granularity: zGranularity,\n /** Zone the buckets were cut in. Mirrors `meta.timezone`. */\n timezone: z.string(),\n /** Total per bucket. Always present, with or without a breakdown. */\n series: z.array(zTimeseriesPoint),\n /** Present only when `breakdown` was requested: the top-N values, each with its own series. */\n breakdown: z\n .array(\n z.object({\n value: z.string(),\n points: z.array(zTimeseriesPoint),\n })\n )\n .optional(),\n});\nexport type EventsTimeseriesData = z.infer<typeof zEventsTimeseriesData>;\n\nexport const zEventsTimeseriesResponse = zQueryEnvelope(zEventsTimeseriesData);\nexport type EventsTimeseriesResponse = z.infer<typeof zEventsTimeseriesResponse>;\n\n// ─── funnel ─────────────────────────────────────────────────────────────────\n\nexport const zFunnelInput = z.object({\n projectId: z.string().min(1),\n /** Ordered event names. A user counts at step k if they reached at least step k. */\n steps: z.array(z.string().min(1).max(200)).min(2).max(10),\n startDate: zDate,\n endDate: zDate,\n /** Max seconds between the first and last step for a conversion to count. Default 24h. */\n windowSeconds: z.number().int().min(60).max(2_592_000).default(86_400),\n segmentId: z.string().min(1).optional(),\n channelFilter: zChannelFilter,\n /**\n * Decides where `startDate` / `endDate` fall. A funnel has no buckets, so\n * this only moves the window — but a nine-hour window shift changes who is\n * in the funnel.\n */\n timezone: zTimezone.optional(),\n});\nexport type FunnelInput = z.input<typeof zFunnelInput>;\n\nexport const zFunnelStep = z.object({\n step: z.number().int().min(1),\n name: z.string(),\n users: z.number().int().nonnegative(),\n /** Percent of the previous step that reached this one. `100` for step 1. */\n conversionRate: z.number(),\n /** Percent of the previous step that did not. `0` for step 1. */\n dropoffRate: z.number(),\n dropoffUsers: z.number().int().nonnegative(),\n});\n\nexport const zFunnelData = z.object({\n steps: z.array(zFunnelStep),\n totalUsers: z.number().int().nonnegative(),\n /** Percent of step-1 users that reached the last step. */\n overallConversionRate: z.number(),\n});\nexport type FunnelData = z.infer<typeof zFunnelData>;\n\nexport const zFunnelResponse = zQueryEnvelope(zFunnelData);\nexport type FunnelResponse = z.infer<typeof zFunnelResponse>;\n\n// ─── retention ──────────────────────────────────────────────────────────────\n\nexport const zRetentionInterval = z.enum([\"day\", \"week\", \"month\"]);\n\nexport const zRetentionInput = z.object({\n projectId: z.string().min(1),\n startDate: zDate,\n endDate: zDate,\n interval: zRetentionInterval.default(\"day\"),\n periods: z.number().int().min(1).max(30).default(7),\n startEvent: z.string().min(1).max(200).optional(),\n returnEvent: z.string().min(1).max(200).optional(),\n /** `bounded`: returned in exactly period N. `unbounded`: returned in period N or later. */\n retentionType: z.enum([\"bounded\", \"unbounded\"]).default(\"bounded\"),\n /**\n * `first-ever` (default): the cohort is everyone whose true first activity\n * landed in the window, read from the first-seen aggregate. `startEvent`,\n * `segmentId` and `channelFilter` then constrain only the *returning* side.\n * `first-in-window`: the cohort is selected by scanning events in the window\n * with all filters applied. Slower, but filters apply to cohort selection.\n */\n cohortMode: z.enum([\"first-ever\", \"first-in-window\"]).default(\"first-ever\"),\n segmentId: z.string().min(1).optional(),\n channelFilter: zChannelFilter,\n /**\n * Decides where a cohort day starts, and so which period a return falls in.\n *\n * Honoured under both cohort modes. Note that a non-UTC zone makes\n * `first-ever` read raw events instead of its daily rollup — the rollup is\n * cut on UTC days and cannot be re-cut after the fact — so expect a slower\n * query in exchange for cohorts that match the reader's calendar.\n */\n timezone: zTimezone.optional(),\n});\nexport type RetentionInput = z.input<typeof zRetentionInput>;\n\nexport const zRetentionCell = z.object({\n /** `0` is the cohort's own period. */\n period: z.number().int().nonnegative(),\n users: z.number().int().nonnegative(),\n /** Percent of `cohortSize`. */\n rate: z.number(),\n});\n\nexport const zRetentionData = z.object({\n matrix: z.array(\n z.object({\n cohortDate: z.string(),\n cohortSize: z.number().int().nonnegative(),\n /** Length is `periods + 1`, index-aligned to `period`. */\n retention: z.array(zRetentionCell),\n })\n ),\n /** Unweighted mean rate per period across cohorts. */\n averageRetention: z.array(z.object({ period: z.number().int().nonnegative(), rate: z.number() })),\n interval: zRetentionInterval,\n periods: z.number().int(),\n retentionType: z.enum([\"bounded\", \"unbounded\"]),\n /** Zone the cohort days were cut in. Mirrors `meta.timezone`. */\n timezone: z.string(),\n});\nexport type RetentionData = z.infer<typeof zRetentionData>;\n\nexport const zRetentionResponse = zQueryEnvelope(zRetentionData);\nexport type RetentionResponse = z.infer<typeof zRetentionResponse>;\n\n// ─── Errors ─────────────────────────────────────────────────────────────────\n\nexport const QUERY_ERROR_CODES = [\n /** 401 — unknown or mismatched credentials. */\n \"unauthorized\",\n /** 403 — the credential's project is not the project asked about. */\n \"project_scope_mismatch\",\n /** 403 — the credential lacks the `query` scope. Provision a query-scoped client. */\n \"query_scope_missing\",\n /** 400 — input failed the schema. `errors` carries the zod issues. */\n \"validation_failed\",\n /** 400 — inputs are individually valid but cannot be served together (e.g. breakdown + segmentId). */\n \"unsupported_combination\",\n /** 429 — per-credential query rate limit. `Retry-After` set. */\n \"rate_limited\",\n /** 504 — the analytics backend exceeded its statement timeout. Narrow the window. */\n \"query_timeout\",\n /** 500 — unexpected server failure. */\n \"internal_error\",\n] as const;\nexport const zQueryErrorCode = z.enum(QUERY_ERROR_CODES);\nexport type QueryErrorCode = z.infer<typeof zQueryErrorCode>;\n\nexport const zQueryError = z.object({\n status: z.number().int(),\n code: zQueryErrorCode,\n error: z.string(),\n message: z.string().optional(),\n errors: z.unknown().optional(),\n requestId: z.string().optional(),\n});\nexport type QueryError = z.infer<typeof zQueryError>;\n\n/** Paths, so the client and the route handlers cannot drift apart. */\nexport const QUERY_API_PATHS = {\n eventsTimeseries: \"/api/v1/query/events/timeseries\",\n funnel: \"/api/v1/query/funnel\",\n retention: \"/api/v1/query/retention\",\n} as const;\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/eric/reopt-ai/reopt-data/packages/data-contract/dist/chunk-HRKELGGH.cjs","../src/ingest.ts"],"names":[],"mappings":"AAAA;ACWA,0BAAkB;AAGX,IAAM,qBAAA,EAAuB,CAAC,eAAA,EAAiB,aAAA,EAAe,aAAa,CAAA;AAG3E,IAAM,wBAAA,EAA0B,KAAA;AAEvC,IAAM,qBAAA,EAAuB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAM3B,OAAA,EAAS,MAAA,CAAE,IAAA,CAAK,CAAA;AAAA;AAAA,EAEhB,SAAA,EAAW,MAAA,CAAE,MAAA,CAAO,CAAA,CAAE,GAAA,CAAI,CAAA,CAAE,WAAA,CAAY;AAC1C,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,CA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AEA,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;ADtF6F;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-HRKELGGH.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\";\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/** 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 idempotency key: it becomes the\n * `RawEvent` primary key, scoped to the project. Re-sending the same\n * eventId is 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\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/** 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});\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});\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 /** 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"]}
|
|
@@ -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 *\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\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 */\nexport const CONTRACT_VERSION = \"0.2.0\";\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\n/**\n * A UTC calendar date. Windows are inclusive on both ends and are widened\n * server-side to `startDate T00:00:00Z` .. `endDate T23:59:59Z`.\n */\nexport const zDate = z.string().regex(/^\\d{4}-\\d{2}-\\d{2}$/, \"expected YYYY-MM-DD (UTC)\");\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 * 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":";AAcA,SAAS,SAAS;AAOX,IAAM,mBAAmB;AAGzB,IAAM,0BAA0B;AAGhC,IAAM,mBAAmB;AACzB,IAAM,uBAAuB;AAC7B,IAAM,mBAAmB;AACzB,IAAM,mBAAmB;AACzB,IAAM,oBAAoB;AAM1B,IAAM,QAAQ,EAAE,OAAO,EAAE,MAAM,uBAAuB,2BAA2B;AAGjF,IAAM,WAAW,EAAE,OAAO,EAAE,IAAI,EAAE;AAgBlC,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":[]}
|