@vllnt/convex-analytics 0.1.0 → 0.1.1-canary.46dc78e
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 +75 -33
- package/dist/component/crons.js +1 -1
- package/dist/component/crons.js.map +1 -1
- package/dist/component/http.d.ts +5 -0
- package/dist/component/http.d.ts.map +1 -1
- package/dist/component/http.js +76 -21
- package/dist/component/http.js.map +1 -1
- package/dist/component/internal_mutations.js +3 -3
- package/dist/component/internal_mutations.js.map +1 -1
- package/dist/component/mutations.d.ts.map +1 -1
- package/dist/component/mutations.js +27 -5
- package/dist/component/mutations.js.map +1 -1
- package/dist/component/queries.d.ts.map +1 -1
- package/dist/component/queries.js +40 -42
- package/dist/component/queries.js.map +1 -1
- package/dist/component/schema.d.ts +1 -0
- package/dist/component/schema.js +2 -1
- package/dist/component/schema.js.map +1 -1
- package/dist/component/validators.d.ts +27 -0
- package/dist/component/validators.d.ts.map +1 -1
- package/dist/component/validators.js +54 -1
- package/dist/component/validators.js.map +1 -1
- package/dist/test.d.ts +1 -0
- package/package.json +20 -24
- package/src/component/crons.ts +1 -1
- package/src/component/http.ts +78 -21
- package/src/component/internal_mutations.ts +4 -4
- package/src/component/mutations.ts +36 -6
- package/src/component/queries.ts +55 -47
- package/src/component/schema.ts +2 -1
- package/src/component/validators.ts +80 -1
package/README.md
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<!-- Badges -->
|
|
2
|
+
|
|
2
3
|
[](https://www.convex.dev/components)
|
|
3
4
|
[](https://www.npmjs.com/package/@vllnt/convex-analytics)
|
|
4
5
|
[](https://github.com/vllnt/convex-analytics/actions/workflows/ci.yml)
|
|
@@ -7,7 +8,7 @@
|
|
|
7
8
|
# @vllnt/convex-analytics
|
|
8
9
|
|
|
9
10
|
A generic, configurable, embedded analytics component for Convex — any event,
|
|
10
|
-
any dimension, any domain — with rollup-on-write
|
|
11
|
+
any dimension, any domain — with rollup-on-write for reactive aggregate reads.
|
|
11
12
|
|
|
12
13
|
```ts
|
|
13
14
|
import { AnalyticsClient } from "@vllnt/convex-analytics";
|
|
@@ -17,7 +18,10 @@ const analytics = new AnalyticsClient(components.analytics, {
|
|
|
17
18
|
dimensions: ["plan", "country"], // prop keys to roll up on
|
|
18
19
|
});
|
|
19
20
|
|
|
20
|
-
await analytics.track(ctx, "signup", {
|
|
21
|
+
await analytics.track(ctx, "signup", {
|
|
22
|
+
subjectRef: userId,
|
|
23
|
+
props: { plan: "pro", country: "FR" },
|
|
24
|
+
});
|
|
21
25
|
const byPlan = await analytics.top(ctx, "signup", "plan"); // [{ value: "pro", count: 1 }]
|
|
22
26
|
```
|
|
23
27
|
|
|
@@ -25,9 +29,9 @@ const byPlan = await analytics.top(ctx, "signup", "plan"); // [{ value: "pro", c
|
|
|
25
29
|
|
|
26
30
|
- **Generic events** — free-string event name, opaque `subjectRef` / `sessionRef`, host-typed `props`.
|
|
27
31
|
- **Host-declared dimensions** — you pass the prop keys to roll up on; nothing is hardcoded.
|
|
28
|
-
- **Rollup-on-write** — counts are incremented as events land
|
|
32
|
+
- **Rollup-on-write** — counts are incremented as events land. Unfiltered lifetime `metric` reads a fixed-shard counter; ranged/filtered metrics, breakdowns, and time series scan matching rollup rows, not constant-time results.
|
|
29
33
|
- **Rich verb set** — `metric`, `top`, `timeseries`, `uniques`, `funnel`, `retention`, `distribution`, plus paginated raw `list`.
|
|
30
|
-
- **Configurable** — `scope`, `dimensions`, `granularities`, `retentionDays`, `sampleRate
|
|
34
|
+
- **Configurable** — `scope`, `dimensions`, `granularities`, `retentionDays`, `sampleRate`; sensible defaults, zero config required.
|
|
31
35
|
- **Per-session rate limiting + dedupe + sampling** built into `track`.
|
|
32
36
|
- **Opt-in web preset** — `@vllnt/convex-analytics/web` adds web dimensions + UA/geo helpers when you want them.
|
|
33
37
|
- **Optional React hooks** — `@vllnt/convex-analytics/react` for reactive aggregate reads.
|
|
@@ -48,6 +52,9 @@ fields. See [docs/web-preset.md](docs/web-preset.md).
|
|
|
48
52
|
npm install @vllnt/convex-analytics
|
|
49
53
|
```
|
|
50
54
|
|
|
55
|
+
Requires `convex@^1.45.0` as a peer dependency; React is optional. The command installs
|
|
56
|
+
the latest stable release; `@canary` follows `main`.
|
|
57
|
+
|
|
51
58
|
## Usage
|
|
52
59
|
|
|
53
60
|
```ts
|
|
@@ -72,7 +79,10 @@ const analytics = new AnalyticsClient<MyProps>(components.analytics, {
|
|
|
72
79
|
granularities: ["day"],
|
|
73
80
|
});
|
|
74
81
|
|
|
75
|
-
await analytics.track(ctx, "signup", {
|
|
82
|
+
await analytics.track(ctx, "signup", {
|
|
83
|
+
subjectRef: userId,
|
|
84
|
+
props: { plan: "pro" },
|
|
85
|
+
});
|
|
76
86
|
const total = await analytics.metric(ctx, "signup");
|
|
77
87
|
```
|
|
78
88
|
|
|
@@ -80,42 +90,70 @@ const total = await analytics.metric(ctx, "signup");
|
|
|
80
90
|
|
|
81
91
|
Passed to the `AnalyticsClient` constructor. All optional — the defaults work with zero config.
|
|
82
92
|
|
|
83
|
-
| Option
|
|
84
|
-
|
|
85
|
-
| `scope`
|
|
86
|
-
| `dimensions`
|
|
87
|
-
| `granularities` | `("minute" \| "hour" \| "day")[]` | `["day"]`
|
|
88
|
-
| `retentionDays` | `number`
|
|
89
|
-
| `sampleRate`
|
|
90
|
-
| `sessionIdleMs` | `number`
|
|
91
|
-
| `propsValidator` | Convex validator | typed scalar record | Optional host validator narrowing `props` at the boundary. |
|
|
93
|
+
| Option | Type | Default | Purpose |
|
|
94
|
+
| --------------- | --------------------------------- | ----------- | ----------------------------------------------------------------------------------- |
|
|
95
|
+
| `scope` | `string` | `"default"` | Multi-tenant partition; isolates one tenant's data. |
|
|
96
|
+
| `dimensions` | `string[]` | `[]` | Prop keys to roll up on (drives rollup-on-write). Empty = count by event name only. |
|
|
97
|
+
| `granularities` | `("minute" \| "hour" \| "day")[]` | `["day"]` | Rollup bucket sizes (`minute` for short live windows). |
|
|
98
|
+
| `retentionDays` | `number` | `90` | Raw-event TTL in days (rollups are kept forever). Applied via `configure`. |
|
|
99
|
+
| `sampleRate` | `number` | `1` | Fraction `0..1` of events to keep at ingest. |
|
|
100
|
+
| `sessionIdleMs` | `number` | `1800000` | Idle timeout before a session is closed. Applied via `configure`. |
|
|
92
101
|
|
|
93
102
|
`scope`, `dimensions`, `granularities`, and `sampleRate` apply per call from the client.
|
|
94
103
|
`retentionDays`, `sampleRate`, and `sessionIdleMs` are persisted for the prune/close-sessions
|
|
95
104
|
crons by calling `analytics.configure(ctx, { ... })` once.
|
|
105
|
+
`TProps` is compile-time typing only; validate untrusted props in host wrappers. There is no
|
|
106
|
+
`propsValidator` constructor option.
|
|
107
|
+
|
|
108
|
+
When `sessionRef` is supplied, ingest uses a token bucket per `(scope, sessionRef)`:
|
|
109
|
+
100 events/minute refill, capacity 10. These limits are currently fixed, not client config.
|
|
110
|
+
Exhaustion and sampling both return `"dropped"`; without `sessionRef`, this limiter is skipped.
|
|
96
111
|
|
|
97
112
|
## API
|
|
98
113
|
|
|
99
|
-
| Verb
|
|
100
|
-
|
|
101
|
-
| `track(ctx, name, opts)`
|
|
102
|
-
| `metric(ctx, name, opts)`
|
|
103
|
-
| `top(ctx, name, dimension, opts)`
|
|
104
|
-
| `timeseries(ctx, name, opts)`
|
|
105
|
-
| `uniques(ctx, opts)`
|
|
106
|
-
| `funnel(ctx, steps, opts)`
|
|
107
|
-
| `retention(ctx, opts)`
|
|
108
|
-
| `distribution(ctx, name, measure, opts)` | query
|
|
109
|
-
| `list(ctx, name, paginationOpts, opts)`
|
|
110
|
-
| `configure(ctx, opts)`
|
|
111
|
-
|
|
112
|
-
|
|
114
|
+
| Verb | Kind | Purpose |
|
|
115
|
+
| ---------------------------------------- | -------- | -------------------------------------------------------------------------------------------------------- |
|
|
116
|
+
| `track(ctx, name, opts)` | mutation | Ingest an event; rollup-on-write + raw event + counter. Returns `"tracked" \| "dropped" \| "duplicate"`. |
|
|
117
|
+
| `metric(ctx, name, opts)` | query | Total count over a range, optionally filtered by a dimension value. |
|
|
118
|
+
| `top(ctx, name, dimension, opts)` | query | Top values of a dimension (breakdown). |
|
|
119
|
+
| `timeseries(ctx, name, opts)` | query | Bucketed counts over a range. |
|
|
120
|
+
| `uniques(ctx, opts)` | query | DAU / WAU / MAU from subjects. |
|
|
121
|
+
| `funnel(ctx, steps, opts)` | query | Ordered step conversion, keyed by `subjectRef`. |
|
|
122
|
+
| `retention(ctx, opts)` | query | Cohort return rates by first-seen period. |
|
|
123
|
+
| `distribution(ctx, name, measure, opts)` | query | Histogram of a numeric measure over declared buckets + overflow (with `count` / `sum`). |
|
|
124
|
+
| `list(ctx, name, paginationOpts, opts)` | query | Paginated raw events, newest first. |
|
|
125
|
+
| `configure(ctx, opts)` | mutation | Persist cron-relevant config (retention / sampling / idle). |
|
|
126
|
+
|
|
127
|
+
`timeseries` and `uniques` require `range` and `granularity`; `funnel` requires `range`;
|
|
128
|
+
`retention` requires `cohortRange` and `periods`; `distribution` requires `buckets`.
|
|
129
|
+
`list` requires pagination options. See [docs/client-sdk.md](docs/client-sdk.md) for exact types.
|
|
130
|
+
|
|
131
|
+
### Optional REST access
|
|
132
|
+
|
|
133
|
+
Expose the routes by mounting with `app.use(analytics, { httpPrefix: "/analytics" })`.
|
|
134
|
+
Then configure keys from a trusted host mutation (not a public unauthenticated endpoint):
|
|
135
|
+
|
|
136
|
+
```ts
|
|
137
|
+
await ctx.runMutation(components.analytics.mutations.configSet, {
|
|
138
|
+
scope: "default",
|
|
139
|
+
key: "apiKeys",
|
|
140
|
+
value: JSON.stringify([apiKey]), // host-provided secret; never ship it to the browser
|
|
141
|
+
});
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
curl -H "x-api-key: $ANALYTICS_API_KEY" \
|
|
146
|
+
"https://your-deployment.convex.site/analytics/metric?name=signup"
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
There is no client `configSet` method. Keys are stored per scope; missing/unconfigured/invalid
|
|
150
|
+
keys return HTTP 401. See [docs/api-reference.md](docs/api-reference.md).
|
|
113
151
|
|
|
114
152
|
## What it serves
|
|
115
153
|
|
|
116
154
|
The Convex-native, authoritative in-app aggregate layer — predefined-dimension rollups served
|
|
117
|
-
**reactively**
|
|
118
|
-
Declare the dimensions
|
|
155
|
+
**reactively** from pre-aggregated rows. It complements a product-analytics warehouse; it doesn't replace one.
|
|
156
|
+
Declare the dimensions you'll query; read cost still grows with matching buckets and values; ad-hoc or
|
|
119
157
|
retroactive questions over **non-declared** dimensions, or beyond the raw-event retention window,
|
|
120
158
|
are an export concern. `metric` / `top` / `timeseries` read pre-aggregated rollups (kept forever);
|
|
121
159
|
`funnel` / `retention` / `distribution` read raw events in range (index-backed, bounded, TTL-pruned).
|
|
@@ -126,7 +164,9 @@ are an export concern. `metric` / `top` / `timeseries` read pre-aggregated rollu
|
|
|
126
164
|
import { AnalyticsClient } from "@vllnt/convex-analytics";
|
|
127
165
|
import { webDimensions, trackPageview } from "@vllnt/convex-analytics/web";
|
|
128
166
|
|
|
129
|
-
const analytics = new AnalyticsClient(components.analytics, {
|
|
167
|
+
const analytics = new AnalyticsClient(components.analytics, {
|
|
168
|
+
dimensions: webDimensions,
|
|
169
|
+
});
|
|
130
170
|
|
|
131
171
|
await trackPageview(analytics, ctx, {
|
|
132
172
|
path: "/pricing",
|
|
@@ -150,13 +190,15 @@ const byPlan = useTop(api.analytics.top, { name: "signup", dimension: "plan" });
|
|
|
150
190
|
```
|
|
151
191
|
|
|
152
192
|
Thin reactive wrappers over the host's re-exported query refs (`metric`, `top`, `timeseries`,
|
|
153
|
-
`uniques`). `react`
|
|
193
|
+
`uniques`). `react` is an optional peer dep; backend-only consumers pull no React.
|
|
154
194
|
|
|
155
195
|
## Security
|
|
156
196
|
|
|
157
197
|
- Auth-agnostic mount — the host gates access and passes opaque `subjectRef` / `sessionRef` in.
|
|
158
198
|
- Tables are sandboxed; the host reaches them only through the exported functions.
|
|
159
199
|
- REST endpoints require an `x-api-key` header, compared timing-safe.
|
|
200
|
+
- Invalid input (empty strings, `NaN` / infinite timestamps, non-scalar props) is rejected with a typed `ConvexError`; see [docs/api-reference.md](docs/api-reference.md#input-errors).
|
|
201
|
+
- The component never logs event data. Props and refs are stored as given, so keep personal data out of them (the web preset stores `path`, `referrer`, and geo as received).
|
|
160
202
|
|
|
161
203
|
See [docs/architecture.md](docs/architecture.md).
|
|
162
204
|
|
|
@@ -179,7 +221,7 @@ analyticsTest.register(t);
|
|
|
179
221
|
[Schema](docs/schema.md) · [Client SDK](docs/client-sdk.md) · [REST API](docs/api-reference.md) ·
|
|
180
222
|
[Web Preset](docs/web-preset.md) · [Multi-Product](docs/multi-product.md) ·
|
|
181
223
|
[Architecture](docs/architecture.md). For AI agents:
|
|
182
|
-
[`llms.txt`](llms.txt)
|
|
224
|
+
[`llms.txt`](llms.txt), the maintained documentation index.
|
|
183
225
|
|
|
184
226
|
## Contributing
|
|
185
227
|
|
package/dist/component/crons.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { cronJobs } from "convex/server";
|
|
2
|
-
import { internal } from "./_generated/api";
|
|
2
|
+
import { internal } from "./_generated/api.js";
|
|
3
3
|
const crons = cronJobs();
|
|
4
4
|
crons.interval("analytics:close-sessions", { minutes: 30 }, internal.internal_mutations.closeSessions, {});
|
|
5
5
|
crons.interval("analytics:prune-events", { hours: 24 }, internal.internal_mutations.prune, {});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crons.js","sourceRoot":"","sources":["../../src/component/crons.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"crons.js","sourceRoot":"","sources":["../../src/component/crons.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAE/C,MAAM,KAAK,GAAG,QAAQ,EAAE,CAAC;AAEzB,KAAK,CAAC,QAAQ,CACZ,0BAA0B,EAC1B,EAAE,OAAO,EAAE,EAAE,EAAE,EACf,QAAQ,CAAC,kBAAkB,CAAC,aAAa,EACzC,EAAE,CACH,CAAC;AACF,KAAK,CAAC,QAAQ,CACZ,wBAAwB,EACxB,EAAE,KAAK,EAAE,EAAE,EAAE,EACb,QAAQ,CAAC,kBAAkB,CAAC,KAAK,EACjC,EAAE,CACH,CAAC;AAEF,eAAe,KAAK,CAAC"}
|
package/dist/component/http.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Run a handler body and turn a typed input error from the component (a `ConvexError`
|
|
3
|
+
* with `{ code, message }`) into `400 { error, code }`. Anything else still fails the action.
|
|
4
|
+
*/
|
|
5
|
+
export declare function withInputErrors(run: () => Promise<Response>): Promise<Response>;
|
|
1
6
|
export declare const trackEndpoint: import("convex/server").PublicHttpAction;
|
|
2
7
|
export declare const metricEndpoint: import("convex/server").PublicHttpAction;
|
|
3
8
|
export declare const topEndpoint: import("convex/server").PublicHttpAction;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/component/http.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/component/http.ts"],"names":[],"mappings":"AAkBA;;;GAGG;AACH,wBAAsB,eAAe,CAAC,GAAG,EAAE,MAAM,OAAO,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAUrF;AAsFD,eAAO,MAAM,aAAa,0CA0CxB,CAAC;AAEH,eAAO,MAAM,cAAc,0CAmBzB,CAAC;AAEH,eAAO,MAAM,WAAW,0CAoBtB,CAAC;AAEH,eAAO,MAAM,kBAAkB,0CAqB7B,CAAC;AAEH,eAAO,MAAM,eAAe,0CAkB1B,CAAC;AAEH;;;;GAIG;AACH,QAAA,MAAM,IAAI,oCAAe,CAAC;eAOX,IAAI"}
|
package/dist/component/http.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { httpRouter } from "convex/server";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { ConvexError } from "convex/values";
|
|
3
|
+
import { httpAction } from "./_generated/server.js";
|
|
4
|
+
import { assertProps } from "./validators.js";
|
|
5
|
+
import { api } from "./_generated/api.js";
|
|
4
6
|
function json(data, status = 200) {
|
|
5
7
|
return new Response(JSON.stringify(data), {
|
|
6
8
|
status,
|
|
@@ -10,6 +12,26 @@ function json(data, status = 200) {
|
|
|
10
12
|
function error(message, status = 400) {
|
|
11
13
|
return json({ error: message }, status);
|
|
12
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Run a handler body and turn a typed input error from the component (a `ConvexError`
|
|
17
|
+
* with `{ code, message }`) into `400 { error, code }`. Anything else still fails the action.
|
|
18
|
+
*/
|
|
19
|
+
export async function withInputErrors(run) {
|
|
20
|
+
try {
|
|
21
|
+
return await run();
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
const data = e instanceof ConvexError ? e.data : undefined;
|
|
25
|
+
if (typeof data === "object" && data !== null && "code" in data && "message" in data) {
|
|
26
|
+
return json({ error: String(data.message), code: String(data.code) }, 400);
|
|
27
|
+
}
|
|
28
|
+
throw e;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/** An `httpAction` whose typed input errors are returned as 400 responses. */
|
|
32
|
+
function handle(fn) {
|
|
33
|
+
return httpAction((ctx, request) => withInputErrors(() => fn(ctx, request)));
|
|
34
|
+
}
|
|
13
35
|
function timingSafeEqual(a, b) {
|
|
14
36
|
if (a.length !== b.length)
|
|
15
37
|
return false;
|
|
@@ -22,6 +44,16 @@ function timingSafeEqual(a, b) {
|
|
|
22
44
|
function scopeOf(value) {
|
|
23
45
|
return typeof value === "string" && value.length > 0 ? value : "default";
|
|
24
46
|
}
|
|
47
|
+
/** The stored `apiKeys` value as a string array, or `null` when it is not one. */
|
|
48
|
+
function parseApiKeys(raw) {
|
|
49
|
+
try {
|
|
50
|
+
const keys = JSON.parse(raw);
|
|
51
|
+
return Array.isArray(keys) && keys.every((k) => typeof k === "string") ? keys : null;
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
25
57
|
/**
|
|
26
58
|
* Gate a request by API key. Keys are a JSON string array stored at config
|
|
27
59
|
* `(scope, "apiKeys")`. Returns an error Response on failure, else null.
|
|
@@ -36,7 +68,9 @@ async function requireApiKey(ctx, request, scope) {
|
|
|
36
68
|
});
|
|
37
69
|
if (!config)
|
|
38
70
|
return error("API keys not configured", 401);
|
|
39
|
-
const keys =
|
|
71
|
+
const keys = parseApiKeys(config);
|
|
72
|
+
if (keys === null)
|
|
73
|
+
return error("API keys misconfigured", 500);
|
|
40
74
|
const matched = keys.some((stored) => timingSafeEqual(stored, key));
|
|
41
75
|
if (!matched)
|
|
42
76
|
return error("Invalid API key", 401);
|
|
@@ -48,20 +82,31 @@ function parseJsonSafe(request) {
|
|
|
48
82
|
function getParams(request) {
|
|
49
83
|
return new URL(request.url).searchParams;
|
|
50
84
|
}
|
|
85
|
+
/** A numeric query param; blank or malformed values become NaN so the component rejects them. */
|
|
86
|
+
function numberParam(params, name) {
|
|
87
|
+
const raw = params.get(name);
|
|
88
|
+
if (raw === null)
|
|
89
|
+
return undefined;
|
|
90
|
+
return raw.trim() === "" ? NaN : Number(raw);
|
|
91
|
+
}
|
|
51
92
|
function range(params) {
|
|
52
|
-
const from = params
|
|
53
|
-
const to = params
|
|
54
|
-
if (from ===
|
|
93
|
+
const from = numberParam(params, "from");
|
|
94
|
+
const to = numberParam(params, "to");
|
|
95
|
+
if (from === undefined && to === undefined)
|
|
55
96
|
return undefined;
|
|
56
|
-
return {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
97
|
+
return { from, to };
|
|
98
|
+
}
|
|
99
|
+
const GRANULARITIES = ["minute", "hour", "day"];
|
|
100
|
+
function isStringArray(value) {
|
|
101
|
+
return Array.isArray(value) && value.every((item) => typeof item === "string");
|
|
60
102
|
}
|
|
61
|
-
export const trackEndpoint =
|
|
103
|
+
export const trackEndpoint = handle(async (ctx, request) => {
|
|
62
104
|
const parsed = await parseJsonSafe(request);
|
|
63
105
|
if (!parsed.ok)
|
|
64
106
|
return error("Invalid JSON body");
|
|
107
|
+
if (typeof parsed.data !== "object" || parsed.data === null || Array.isArray(parsed.data)) {
|
|
108
|
+
return error("Body must be a JSON object");
|
|
109
|
+
}
|
|
65
110
|
const body = parsed.data;
|
|
66
111
|
const scope = scopeOf(body["scope"]);
|
|
67
112
|
const authError = await requireApiKey(ctx, request, scope);
|
|
@@ -70,24 +115,34 @@ export const trackEndpoint = httpAction(async (ctx, request) => {
|
|
|
70
115
|
if (typeof body["name"] !== "string" || body["name"].length === 0) {
|
|
71
116
|
return error("name is required");
|
|
72
117
|
}
|
|
73
|
-
if (!
|
|
118
|
+
if (!isStringArray(body["dimensions"])) {
|
|
74
119
|
return error("dimensions (string[]) is required");
|
|
75
120
|
}
|
|
121
|
+
const props = body["props"] ?? undefined;
|
|
122
|
+
if (props !== undefined && (typeof props !== "object" || Array.isArray(props))) {
|
|
123
|
+
return error("props must be a flat object of scalar values");
|
|
124
|
+
}
|
|
125
|
+
if (props !== undefined)
|
|
126
|
+
assertProps(props);
|
|
127
|
+
const granularities = body["granularities"] ?? ["day"];
|
|
128
|
+
if (!isStringArray(granularities) || !granularities.every((g) => GRANULARITIES.includes(g))) {
|
|
129
|
+
return error("granularities must be an array of minute, hour, or day");
|
|
130
|
+
}
|
|
76
131
|
const result = await ctx.runMutation(api.mutations.track, {
|
|
77
132
|
scope,
|
|
78
133
|
name: body["name"],
|
|
79
134
|
subjectRef: typeof body["subjectRef"] === "string" ? body["subjectRef"] : undefined,
|
|
80
135
|
sessionRef: typeof body["sessionRef"] === "string" ? body["sessionRef"] : undefined,
|
|
81
|
-
props
|
|
136
|
+
props,
|
|
82
137
|
ts: typeof body["ts"] === "number" ? body["ts"] : undefined,
|
|
83
138
|
dedupeKey: typeof body["dedupeKey"] === "string" ? body["dedupeKey"] : undefined,
|
|
84
139
|
dimensions: body["dimensions"],
|
|
85
|
-
granularities
|
|
140
|
+
granularities,
|
|
86
141
|
sampleRate: typeof body["sampleRate"] === "number" ? body["sampleRate"] : undefined,
|
|
87
142
|
});
|
|
88
143
|
return json({ result }, 201);
|
|
89
144
|
});
|
|
90
|
-
export const metricEndpoint =
|
|
145
|
+
export const metricEndpoint = handle(async (ctx, request) => {
|
|
91
146
|
const params = getParams(request);
|
|
92
147
|
const scope = scopeOf(params.get("scope"));
|
|
93
148
|
const authError = await requireApiKey(ctx, request, scope);
|
|
@@ -106,7 +161,7 @@ export const metricEndpoint = httpAction(async (ctx, request) => {
|
|
|
106
161
|
});
|
|
107
162
|
return json({ name, count });
|
|
108
163
|
});
|
|
109
|
-
export const topEndpoint =
|
|
164
|
+
export const topEndpoint = handle(async (ctx, request) => {
|
|
110
165
|
const params = getParams(request);
|
|
111
166
|
const scope = scopeOf(params.get("scope"));
|
|
112
167
|
const authError = await requireApiKey(ctx, request, scope);
|
|
@@ -123,11 +178,11 @@ export const topEndpoint = httpAction(async (ctx, request) => {
|
|
|
123
178
|
name,
|
|
124
179
|
dimension,
|
|
125
180
|
range: range(params),
|
|
126
|
-
limit: params
|
|
181
|
+
limit: numberParam(params, "limit"),
|
|
127
182
|
});
|
|
128
183
|
return json(result);
|
|
129
184
|
});
|
|
130
|
-
export const timeseriesEndpoint =
|
|
185
|
+
export const timeseriesEndpoint = handle(async (ctx, request) => {
|
|
131
186
|
const params = getParams(request);
|
|
132
187
|
const scope = scopeOf(params.get("scope"));
|
|
133
188
|
const authError = await requireApiKey(ctx, request, scope);
|
|
@@ -137,7 +192,7 @@ export const timeseriesEndpoint = httpAction(async (ctx, request) => {
|
|
|
137
192
|
if (!name)
|
|
138
193
|
return error("name parameter required");
|
|
139
194
|
const granularity = params.get("granularity") ?? "day";
|
|
140
|
-
if (granularity
|
|
195
|
+
if (!GRANULARITIES.includes(granularity)) {
|
|
141
196
|
return error("granularity must be minute, hour, or day");
|
|
142
197
|
}
|
|
143
198
|
const result = await ctx.runQuery(api.queries.timeseries, {
|
|
@@ -148,14 +203,14 @@ export const timeseriesEndpoint = httpAction(async (ctx, request) => {
|
|
|
148
203
|
});
|
|
149
204
|
return json(result);
|
|
150
205
|
});
|
|
151
|
-
export const uniquesEndpoint =
|
|
206
|
+
export const uniquesEndpoint = handle(async (ctx, request) => {
|
|
152
207
|
const params = getParams(request);
|
|
153
208
|
const scope = scopeOf(params.get("scope"));
|
|
154
209
|
const authError = await requireApiKey(ctx, request, scope);
|
|
155
210
|
if (authError)
|
|
156
211
|
return authError;
|
|
157
212
|
const granularity = params.get("granularity") ?? "day";
|
|
158
|
-
if (granularity
|
|
213
|
+
if (!GRANULARITIES.includes(granularity)) {
|
|
159
214
|
return error("granularity must be minute, hour, or day");
|
|
160
215
|
}
|
|
161
216
|
const result = await ctx.runQuery(api.queries.uniques, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/component/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/component/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAC;A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AE,OAAO,EAAE,kBAAkB,EAAE,CAAC,CAAC;AAChF,IAAI,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,CAAC,CAAC;AAE1E,eAAe,IAAI,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { internal } from "./_generated/api";
|
|
2
|
-
import { internalMutation } from "./_generated/server";
|
|
1
|
+
import { internal } from "./_generated/api.js";
|
|
2
|
+
import { internalMutation } from "./_generated/server.js";
|
|
3
3
|
import { v } from "convex/values";
|
|
4
4
|
import { granularitiesValidator } from "./validators.js";
|
|
5
5
|
import { bucketStart, valKey } from "../shared.js";
|
|
@@ -132,7 +132,7 @@ export const backfill = internalMutation({
|
|
|
132
132
|
const bucket = bucketStart(e.ts, gran);
|
|
133
133
|
bump(gran, bucket, TOTAL, TOTAL);
|
|
134
134
|
for (const dim of args.dimensions) {
|
|
135
|
-
if (
|
|
135
|
+
if (Object.hasOwn(e.props, dim)) {
|
|
136
136
|
bump(gran, bucket, dim, valKey(e.props[dim]));
|
|
137
137
|
}
|
|
138
138
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal_mutations.js","sourceRoot":"","sources":["../../src/component/internal_mutations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"internal_mutations.js","sourceRoot":"","sources":["../../src/component/internal_mutations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE1D,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAClC,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAGnD,MAAM,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AM,EAAE,CAAC,CAAC,MAAM;gBAChB,GAAG,EAAE,CAAC,CAAC,GAAG;gBACV,GAAG,EAAE,CAAC,CAAC,GAAG;gBACV,KAAK;aACN,CAAC,CAAC;QACL,CAAC,CAAC,CACH,CAAC;QAEF,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;IACtD,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mutations.d.ts","sourceRoot":"","sources":["../../src/component/mutations.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mutations.d.ts","sourceRoot":"","sources":["../../src/component/mutations.ts"],"names":[],"mappings":"AAkFA,eAAO,MAAM,KAAK;;;;;;;;;;;gDAwJhB,CAAC;AAoBH,eAAO,MAAM,SAAS;;;;iBAUpB,CAAC;AAEH,eAAO,MAAM,SAAS;;;;;iBAmCpB,CAAC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { mutation } from "./_generated/server";
|
|
2
|
-
import { components } from "./_generated/api";
|
|
1
|
+
import { mutation } from "./_generated/server.js";
|
|
2
|
+
import { components } from "./_generated/api.js";
|
|
3
3
|
import { v } from "convex/values";
|
|
4
4
|
import { DirectAggregate } from "@convex-dev/aggregate";
|
|
5
5
|
import { ShardedCounter } from "@convex-dev/sharded-counter";
|
|
6
6
|
import { RateLimiter, MINUTE } from "@convex-dev/rate-limiter";
|
|
7
|
-
import { propsValidator, granularitiesValidator } from "./validators.js";
|
|
7
|
+
import { propsValidator, granularitiesValidator, assertProps, assertFiniteTs, assertNonEmpty, assertSampleRate, invalidInput, } from "./validators.js";
|
|
8
8
|
import { bucketStart, tupleKey, valKey } from "../shared.js";
|
|
9
9
|
const aggregate = new DirectAggregate(components.aggregate);
|
|
10
10
|
const counter = new ShardedCounter(components.shardedCounter, {
|
|
@@ -70,10 +70,20 @@ export const track = mutation({
|
|
|
70
70
|
},
|
|
71
71
|
returns: v.union(v.literal("tracked"), v.literal("dropped"), v.literal("duplicate")),
|
|
72
72
|
handler: async (ctx, args) => {
|
|
73
|
+
assertNonEmpty("scope", args.scope);
|
|
74
|
+
assertNonEmpty("name", args.name);
|
|
75
|
+
assertNonEmpty("subjectRef", args.subjectRef);
|
|
76
|
+
assertNonEmpty("sessionRef", args.sessionRef);
|
|
77
|
+
assertNonEmpty("dedupeKey", args.dedupeKey);
|
|
78
|
+
for (const dim of args.dimensions)
|
|
79
|
+
assertNonEmpty("dimensions[]", dim);
|
|
80
|
+
assertFiniteTs("ts", args.ts);
|
|
81
|
+
assertSampleRate(args.sampleRate);
|
|
82
|
+
const props = args.props ?? {};
|
|
83
|
+
assertProps(props);
|
|
73
84
|
const now = Date.now();
|
|
74
85
|
const scope = args.scope;
|
|
75
86
|
const ts = args.ts ?? now;
|
|
76
|
-
const props = args.props ?? {};
|
|
77
87
|
const grans = args.granularities.length > 0 ? args.granularities : ["day"];
|
|
78
88
|
if (args.sessionRef !== undefined) {
|
|
79
89
|
const rl = await rateLimiter.limit(ctx, "trackEvent", {
|
|
@@ -161,7 +171,7 @@ export const track = mutation({
|
|
|
161
171
|
const bucket = bucketStart(ts, granularity);
|
|
162
172
|
await bumpRollup(ctx, scope, args.name, granularity, bucket, TOTAL, TOTAL);
|
|
163
173
|
for (const dim of args.dimensions) {
|
|
164
|
-
if (dim
|
|
174
|
+
if (Object.hasOwn(props, dim)) {
|
|
165
175
|
await bumpRollup(ctx, scope, args.name, granularity, bucket, dim, valKey(props[dim]));
|
|
166
176
|
}
|
|
167
177
|
}
|
|
@@ -192,6 +202,8 @@ export const configSet = mutation({
|
|
|
192
202
|
args: { scope: v.string(), key: v.string(), value: v.string() },
|
|
193
203
|
returns: v.null(),
|
|
194
204
|
handler: async (ctx, args) => {
|
|
205
|
+
assertNonEmpty("scope", args.scope);
|
|
206
|
+
assertNonEmpty("key", args.key);
|
|
195
207
|
await ensureScope(ctx, args.scope);
|
|
196
208
|
await upsertConfig(ctx, args.scope, args.key, args.value);
|
|
197
209
|
return null;
|
|
@@ -206,6 +218,16 @@ export const configure = mutation({
|
|
|
206
218
|
},
|
|
207
219
|
returns: v.null(),
|
|
208
220
|
handler: async (ctx, args) => {
|
|
221
|
+
assertNonEmpty("scope", args.scope);
|
|
222
|
+
assertSampleRate(args.sampleRate);
|
|
223
|
+
for (const [field, value] of [
|
|
224
|
+
["retentionDays", args.retentionDays],
|
|
225
|
+
["sessionIdleMs", args.sessionIdleMs],
|
|
226
|
+
]) {
|
|
227
|
+
if (value !== undefined && !(Number.isFinite(value) && value > 0)) {
|
|
228
|
+
throw invalidInput("INVALID_CONFIG", `${field} must be a positive finite number`);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
209
231
|
await ensureScope(ctx, args.scope);
|
|
210
232
|
const entries = [];
|
|
211
233
|
if (args.retentionDays !== undefined) {
|