@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.
Files changed (56) hide show
  1. package/README.md +11 -4
  2. package/dist/{chunk-IKOEYZVT.js → chunk-2LZBZXBF.js} +9 -3
  3. package/dist/chunk-2LZBZXBF.js.map +1 -0
  4. package/dist/{chunk-LBSBZO7O.cjs → chunk-4B4AY44F.cjs} +33 -7
  5. package/dist/chunk-4B4AY44F.cjs.map +1 -0
  6. package/dist/{chunk-2SJPZP2D.js → chunk-AHXPQQKO.js} +30 -4
  7. package/dist/chunk-AHXPQQKO.js.map +1 -0
  8. package/dist/{chunk-SC7TFGTO.js → chunk-BCGR27G2.js} +130 -14
  9. package/dist/chunk-BCGR27G2.js.map +1 -0
  10. package/dist/{chunk-FRJK7OCQ.js → chunk-MFZEIH5Z.js} +7 -4
  11. package/dist/chunk-MFZEIH5Z.js.map +1 -0
  12. package/dist/{chunk-CSTC3ADG.cjs → chunk-OLSMH4RY.cjs} +9 -3
  13. package/dist/chunk-OLSMH4RY.cjs.map +1 -0
  14. package/dist/{chunk-GCLUMVPA.cjs → chunk-VQ2CD5MG.cjs} +138 -22
  15. package/dist/chunk-VQ2CD5MG.cjs.map +1 -0
  16. package/dist/{chunk-HRKELGGH.cjs → chunk-XI3VP5DN.cjs} +7 -4
  17. package/dist/chunk-XI3VP5DN.cjs.map +1 -0
  18. package/dist/client.cjs +94 -44
  19. package/dist/client.cjs.map +1 -1
  20. package/dist/client.d.cts +8 -4
  21. package/dist/client.d.ts +8 -4
  22. package/dist/client.js +58 -8
  23. package/dist/client.js.map +1 -1
  24. package/dist/control.cjs +14 -4
  25. package/dist/control.cjs.map +1 -1
  26. package/dist/control.d.cts +49 -7
  27. package/dist/control.d.ts +49 -7
  28. package/dist/control.js +15 -5
  29. package/dist/index.cjs +2 -2
  30. package/dist/index.d.cts +15 -4
  31. package/dist/index.d.ts +15 -4
  32. package/dist/index.js +1 -1
  33. package/dist/ingest.cjs +2 -2
  34. package/dist/ingest.d.cts +9 -7
  35. package/dist/ingest.d.ts +9 -7
  36. package/dist/ingest.js +1 -1
  37. package/dist/query.cjs +29 -3
  38. package/dist/query.cjs.map +1 -1
  39. package/dist/query.d.cts +317 -21
  40. package/dist/query.d.ts +317 -21
  41. package/dist/query.js +30 -4
  42. package/dist/report.cjs +85 -0
  43. package/dist/report.cjs.map +1 -0
  44. package/dist/report.d.cts +167 -0
  45. package/dist/report.d.ts +167 -0
  46. package/dist/report.js +85 -0
  47. package/dist/report.js.map +1 -0
  48. package/package.json +7 -2
  49. package/dist/chunk-2SJPZP2D.js.map +0 -1
  50. package/dist/chunk-CSTC3ADG.cjs.map +0 -1
  51. package/dist/chunk-FRJK7OCQ.js.map +0 -1
  52. package/dist/chunk-GCLUMVPA.cjs.map +0 -1
  53. package/dist/chunk-HRKELGGH.cjs.map +0 -1
  54. package/dist/chunk-IKOEYZVT.js.map +0 -1
  55. package/dist/chunk-LBSBZO7O.cjs.map +0 -1
  56. package/dist/chunk-SC7TFGTO.js.map +0 -1
@@ -4,9 +4,10 @@ var RESERVED_EVENT_NAMES = ["session_start", "session_end", "screen_view"];
4
4
  var MAX_TRACK_PAYLOAD_BYTES = 512e3;
5
5
  var zClientEventMetadata = {
6
6
  /**
7
- * Client-generated UUID. This is the idempotency key: it becomes the
8
- * `RawEvent` primary key, scoped to the project. Re-sending the same
9
- * eventId is always safe and always reported as a duplicate.
7
+ * Client-generated UUID. This is the project-scoped idempotency key stored as
8
+ * `RawEvent.clientEventId`; the server uses a separate globally unique raw
9
+ * event id internally. Re-sending the same eventId to the same project is
10
+ * always safe and always reported as a duplicate.
10
11
  */
11
12
  eventId: z.uuid(),
12
13
  /** Event time, epoch milliseconds. */
@@ -113,6 +114,8 @@ var INGEST_ERROR_CODES = [
113
114
  "rate_limited",
114
115
  /** 429 — the organization's monthly event quota is exhausted. `Retry-After` set (capped at 1h). Alert: a human must raise the limit. */
115
116
  "quota_exceeded",
117
+ /** 410 — the project is being deleted. Permanent; stop sending. */
118
+ "project_purging",
116
119
  /** 500 — unexpected server failure. Back off and retry. */
117
120
  "internal_error"
118
121
  ];
@@ -148,4 +151,4 @@ export {
148
151
  zIngestErrorCode,
149
152
  zIngestError
150
153
  };
151
- //# sourceMappingURL=chunk-FRJK7OCQ.js.map
154
+ //# sourceMappingURL=chunk-MFZEIH5Z.js.map
@@ -0,0 +1 @@
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 project-scoped idempotency key stored as\n * `RawEvent.clientEventId`; the server uses a separate globally unique raw\n * event id internally. Re-sending the same eventId to the same project is\n * always safe and always reported as a duplicate.\n */\n eventId: z.uuid(),\n /** Event time, epoch milliseconds. */\n timestamp: z.number().int().nonnegative(),\n};\n\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 /** 410 — the project is being deleted. Permanent; stop sending. */\n \"project_purging\",\n /** 500 — unexpected server failure. Back off and retry. */\n \"internal_error\",\n] as const;\nexport const zIngestErrorCode = z.enum(INGEST_ERROR_CODES);\nexport type IngestErrorCode = z.infer<typeof zIngestErrorCode>;\n\nexport const zIngestError = z.object({\n status: z.number().int(),\n code: zIngestErrorCode,\n error: z.string(),\n message: z.string().optional(),\n /** zod issues, when `code === \"validation_failed\"`. */\n errors: z.unknown().optional(),\n requestId: z.string().optional(),\n});\nexport type I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AA,EACN,OAAO,EAAE,OAAO;AAAA,EAChB,SAAS,EAAE,OAAO,EAAE,SAAS;AAAA;AAAA,EAE7B,QAAQ,EAAE,QAAQ,EAAE,SAAS;AAAA,EAC7B,WAAW,EAAE,OAAO,EAAE,SAAS;AACjC,CAAC;","names":[]}
@@ -1,13 +1,19 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); var _class;// src/index.ts
2
2
  var _zod = require('zod');
3
- var CONTRACT_VERSION = "0.2.0";
3
+ var CONTRACT_VERSION = "0.5.0";
4
4
  var CONTRACT_VERSION_HEADER = "x-reopt-contract-version";
5
5
  var CLIENT_ID_HEADER = "reopt-client-id";
6
6
  var CLIENT_SECRET_HEADER = "reopt-client-secret";
7
7
  var WRITE_KEY_HEADER = "reopt-write-key";
8
8
  var DEVICE_ID_HEADER = "reopt-device-id";
9
9
  var REQUEST_ID_HEADER = "x-request-id";
10
- var zDate = _zod.z.string().regex(/^\d{4}-\d{2}-\d{2}$/, "expected YYYY-MM-DD (UTC)");
10
+ var zDate = _zod.z.string().regex(/^\d{4}-\d{2}-\d{2}$/, "expected YYYY-MM-DD").refine(isRealCalendarDate, "date does not exist");
11
+ function isRealCalendarDate(value) {
12
+ if (!/^\d{4}-\d{2}-\d{2}$/.test(value)) return false;
13
+ const [year, month, day] = value.split("-").map(Number);
14
+ const instant = new Date(Date.UTC(year, month - 1, day));
15
+ return instant.getUTCFullYear() === year && instant.getUTCMonth() === month - 1 && instant.getUTCDate() === day;
16
+ }
11
17
  var zInstant = _zod.z.string().min(20);
12
18
  var DataApiError = (_class = class _DataApiError extends Error {
13
19
  /**
@@ -58,4 +64,4 @@ var DataApiError = (_class = class _DataApiError extends Error {
58
64
 
59
65
 
60
66
  exports.CONTRACT_VERSION = CONTRACT_VERSION; exports.CONTRACT_VERSION_HEADER = CONTRACT_VERSION_HEADER; exports.CLIENT_ID_HEADER = CLIENT_ID_HEADER; exports.CLIENT_SECRET_HEADER = CLIENT_SECRET_HEADER; exports.WRITE_KEY_HEADER = WRITE_KEY_HEADER; exports.DEVICE_ID_HEADER = DEVICE_ID_HEADER; exports.REQUEST_ID_HEADER = REQUEST_ID_HEADER; exports.zDate = zDate; exports.zInstant = zInstant; exports.DataApiError = DataApiError;
61
- //# sourceMappingURL=chunk-CSTC3ADG.cjs.map
67
+ //# sourceMappingURL=chunk-OLSMH4RY.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/eric/reopt-ai/reopt-data/packages/data-contract/dist/chunk-OLSMH4RY.cjs","../src/index.ts"],"names":[],"mappings":"AAAA;ACcA,0BAAkB;AAOX,IAAM,iBAAA,EAAmB,OAAA;AAGzB,IAAM,wBAAA,EAA0B,0BAAA;AAGhC,IAAM,iBAAA,EAAmB,iBAAA;AACzB,IAAM,qBAAA,EAAuB,qBAAA;AAC7B,IAAM,iBAAA,EAAmB,iBAAA;AACzB,IAAM,iBAAA,EAAmB,iBAAA;AACzB,IAAM,kBAAA,EAAoB,cAAA;AAM1B,IAAM,MAAA,EAAQ,MAAA,CAClB,MAAA,CAAO,CAAA,CACP,KAAA,CAAM,qBAAA,EAAuB,qBAAqB,CAAA,CAClD,MAAA,CAAO,kBAAA,EAAoB,qBAAqB,CAAA;AAEnD,SAAS,kBAAA,CAAmB,KAAA,EAAwB;AAClD,EAAA,GAAA,CAAI,CAAC,qBAAA,CAAsB,IAAA,CAAK,KAAK,CAAA,EAAG,OAAO,KAAA;AAC/C,EAAA,MAAM,CAAC,IAAA,EAAM,KAAA,EAAO,GAAG,EAAA,EAAI,KAAA,CAAM,KAAA,CAAM,GAAG,CAAA,CAAE,GAAA,CAAI,MAAM,CAAA;AACtD,EAAA,MAAM,QAAA,EAAU,IAAI,IAAA,CAAK,IAAA,CAAK,GAAA,CAAI,IAAA,EAAO,MAAA,EAAS,CAAA,EAAG,GAAI,CAAC,CAAA;AAC1D,EAAA,OAAO,OAAA,CAAQ,cAAA,CAAe,EAAA,IAAM,KAAA,GAAQ,OAAA,CAAQ,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t-ai/reopt-data/packages/data-contract/dist/chunk-OLSMH4RY.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.5.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 real calendar date. The query's resolved IANA zone decides which instants\n * its inclusive day covers.\n */\nexport const zDate = z\n .string()\n .regex(/^\\d{4}-\\d{2}-\\d{2}$/, \"expected YYYY-MM-DD\")\n .refine(isRealCalendarDate, \"date does not exist\");\n\nfunction isRealCalendarDate(value: string): boolean {\n if (!/^\\d{4}-\\d{2}-\\d{2}$/.test(value)) return false;\n const [year, month, day] = value.split(\"-\").map(Number);\n const instant = new Date(Date.UTC(year!, month! - 1, day!));\n return instant.getUTCFullYear() === year && instant.getUTCMonth() === month! - 1 && instant.getUTCDate() === day;\n}\n\n/** ISO-8601 instant, as produced by `Date#toISOString()`. */\nexport const zInstant = z.string().min(20);\n\n/**\n * Client credentials. The same pair authenticates both planes; what a given\n * client may reach is decided server-side by `Client.scopes`\n * (`\"ingest\"` / `\"query\"` / `\"provision\"`).\n */\nexport interface ClientCredentials {\n clientId: string;\n clientSecret: string;\n}\n\n/**\n * Credentials are optional on the client itself because the provisioning\n * surface does not use them — it authenticates per call with a platform or\n * organization key. A caller that only provisions should not have to invent an\n * empty client id to satisfy a constructor.\n *\n * Reaching ingest or query without them fails with `credentials_missing`\n * rather than sending an unauthenticated request and reporting the 401 as a\n * server problem.\n */\nexport type OptionalClientCredentials = Partial<ClientCredentials>;\n\n/**\n * Every non-2xx response from either plane, plus the two failures the client\n * itself raises (`contract_mismatch`, `network_error`).\n */\nexport class DataApiError extends Error {\n /**\n * Brand for {@link DataApiError.is}. A bundler that inlines this module into\n * more than one entry point produces two distinct classes, and `instanceof`\n * silently stops matching — the brand survives that, and realm boundaries.\n */\n readonly isDataApiError = true as const;\n\n readonly status: number;\n readonly code: string;\n readonly requestId?: string;\n /** Parsed from `Retry-After`, in milliseconds. Only set on 429. */\n readonly retryAfterMs?: number;\n /** zod issues for `validation_failed`, or the raw body when unparseable. */\n readonly details?: unknown;\n\n constructor(init: {\n message: string;\n status: number;\n code: string;\n requestId?: string;\n retryAfterMs?: number;\n details?: unknown;\n }) {\n super(init.message);\n this.name = \"DataApiError\";\n this.status = init.status;\n this.code = init.code;\n this.requestId = init.requestId;\n this.retryAfterMs = init.retryAfterMs;\n this.details = init.details;\n }\n\n /** 429 and 5xx are worth retrying; 4xx are the caller's fault and are not. */\n get retryable(): boolean {\n return this.status === 429 || this.status >= 500;\n }\n\n /**\n * Prefer this over `instanceof` in a `catch`. It holds even when the class\n * has been duplicated — across CJS entry points, across bundler chunks, or\n * across realms — where `instanceof` quietly returns false.\n */\n static is(value: unknown): value is DataApiError {\n return (\n value instanceof DataApiError ||\n (typeof value === \"object\" && value !== null && (value as { isDataApiError?: unknown }).isDataApiError === true)\n );\n }\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
3
 
4
- var _chunkCSTC3ADGcjs = require('./chunk-CSTC3ADG.cjs');
4
+ var _chunkOLSMH4RYcjs = require('./chunk-OLSMH4RY.cjs');
5
5
 
6
6
  // src/query.ts
7
7
  var _zod = require('zod');
@@ -22,22 +22,31 @@ var zChannelFilter = _zod.z.object({
22
22
  utmMediums: _zod.z.array(_zod.z.string()).optional(),
23
23
  utmCampaigns: _zod.z.array(_zod.z.string()).optional()
24
24
  }).optional();
25
+ var zQuerySource = _zod.z.enum(["rollup", "raw", "mixed"]);
25
26
  var zQueryMeta = _zod.z.object({
26
27
  projectId: _zod.z.string(),
27
28
  /** When the underlying computation actually ran. On a cache hit, when the cached value was computed. */
28
- computedAt: _chunkCSTC3ADGcjs.zInstant,
29
+ computedAt: _chunkOLSMH4RYcjs.zInstant,
29
30
  /** Age of the returned computation, in seconds. `0` on a cache miss. */
30
31
  cacheAgeSeconds: _zod.z.number().int().nonnegative(),
31
32
  /**
32
- * How far behind materialization was when the computation ran, in seconds:
33
- * the age of the oldest raw event not yet materialized, or `0` when nothing
34
- * is pending.
33
+ * How far behind live materialization was when the computation ran, in
34
+ * seconds. `0` means no live event is pending; `null` means measurement
35
+ * failed and must never be interpreted as fresh.
35
36
  *
36
37
  * Deliberately not `now - max(events.created_at)` — that conflates "the
37
38
  * pipeline is behind" with "this project is quiet", and grows without bound
38
39
  * on an idle project.
39
40
  */
40
- ingestLagSeconds: _zod.z.number().int().nonnegative(),
41
+ ingestLagSeconds: _zod.z.number().int().nonnegative().nullable(),
42
+ /** Whether the freshness measurement itself succeeded. */
43
+ ingestLagStatus: _zod.z.enum(["known", "unknown"]),
44
+ /**
45
+ * Pending events older than the live replay window. Kept separate so an old
46
+ * permanently failing event neither pegs live lag nor disappears behind 0.
47
+ * `null` means the measurement failed.
48
+ */
49
+ ingestDeadLetterCount: _zod.z.number().int().nonnegative().nullable(),
41
50
  cached: _zod.z.boolean(),
42
51
  /**
43
52
  * The time zone actually used to place bucket and window boundaries — the
@@ -46,6 +55,14 @@ var zQueryMeta = _zod.z.object({
46
55
  * that is exactly the case a consumer needs to notice.
47
56
  */
48
57
  timezone: _zod.z.string(),
58
+ /**
59
+ * Where the numbers came from. `rollup`: pre-aggregated hourly tables;
60
+ * `raw`: a scan of the event/session tables; `mixed`: finished hours from
61
+ * the rollup, the hour still in progress from raw. Diagnostic — the values
62
+ * agree either way — but a consumer that expected `rollup` and sees `raw`
63
+ * has asked for a combination the rollups cannot serve.
64
+ */
65
+ source: zQuerySource,
49
66
  requestId: _zod.z.string()
50
67
  });
51
68
  function zQueryEnvelope(data) {
@@ -54,15 +71,22 @@ function zQueryEnvelope(data) {
54
71
  var zTimeseriesBreakdown = _zod.z.object({
55
72
  kind: _zod.z.literal("property"),
56
73
  key: _zod.z.string().min(1).max(200),
57
- topN: _zod.z.number().int().min(1).max(10).default(5)
74
+ topN: _zod.z.number().int().min(1).max(100).default(5)
75
+ });
76
+ var zEventPropertyFilter = _zod.z.object({
77
+ key: _zod.z.string().min(1).max(200),
78
+ operator: _zod.z.literal("eq").default("eq"),
79
+ value: _zod.z.string().min(1).max(500)
58
80
  });
59
81
  var zEventsTimeseriesInput = _zod.z.object({
60
82
  projectId: _zod.z.string().min(1),
61
- startDate: _chunkCSTC3ADGcjs.zDate,
62
- endDate: _chunkCSTC3ADGcjs.zDate,
83
+ startDate: _chunkOLSMH4RYcjs.zDate,
84
+ endDate: _chunkOLSMH4RYcjs.zDate,
63
85
  granularity: zGranularity.default("day"),
64
86
  /** Omit to count every event in the window. */
65
87
  eventName: _zod.z.string().min(1).max(200).optional(),
88
+ /** Exact matches against top-level `properties` keys. Every item must match. */
89
+ propertyFilters: _zod.z.array(zEventPropertyFilter).max(10).optional(),
66
90
  breakdown: zTimeseriesBreakdown.optional(),
67
91
  /**
68
92
  * Cannot be combined with `breakdown` — the backend's breakdown time series
@@ -71,11 +95,19 @@ var zEventsTimeseriesInput = _zod.z.object({
71
95
  */
72
96
  segmentId: _zod.z.string().min(1).optional(),
73
97
  /** Omit to fall back to the project's configured zone, then to UTC. */
74
- timezone: zTimezone.optional()
98
+ timezone: zTimezone.optional(),
99
+ /**
100
+ * Events whose catalogue status is `internal` (operational probes) are
101
+ * left out by default. A probe that needs to find its own event sets this.
102
+ */
103
+ includeInternal: _zod.z.boolean().default(false)
104
+ }).refine((input) => input.startDate <= input.endDate, {
105
+ message: "endDate must be on or after startDate",
106
+ path: ["endDate"]
75
107
  });
108
+ var zBucketStart = _zod.z.string().regex(/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/, "expected 'YYYY-MM-DD HH:MM:SS'");
76
109
  var zTimeseriesPoint = _zod.z.object({
77
- /** Bucket start, formatted by the analytics backend for the requested granularity. */
78
- date: _zod.z.string(),
110
+ date: zBucketStart,
79
111
  count: _zod.z.number().int().nonnegative()
80
112
  });
81
113
  var zEventsTimeseriesData = _zod.z.object({
@@ -97,8 +129,8 @@ var zFunnelInput = _zod.z.object({
97
129
  projectId: _zod.z.string().min(1),
98
130
  /** Ordered event names. A user counts at step k if they reached at least step k. */
99
131
  steps: _zod.z.array(_zod.z.string().min(1).max(200)).min(2).max(10),
100
- startDate: _chunkCSTC3ADGcjs.zDate,
101
- endDate: _chunkCSTC3ADGcjs.zDate,
132
+ startDate: _chunkOLSMH4RYcjs.zDate,
133
+ endDate: _chunkOLSMH4RYcjs.zDate,
102
134
  /** Max seconds between the first and last step for a conversion to count. Default 24h. */
103
135
  windowSeconds: _zod.z.number().int().min(60).max(2592e3).default(86400),
104
136
  segmentId: _zod.z.string().min(1).optional(),
@@ -108,7 +140,12 @@ var zFunnelInput = _zod.z.object({
108
140
  * this only moves the window — but a nine-hour window shift changes who is
109
141
  * in the funnel.
110
142
  */
111
- timezone: zTimezone.optional()
143
+ timezone: zTimezone.optional(),
144
+ /** Accepted for symmetry with events.timeseries; funnel steps are named explicitly, so nothing is filtered. */
145
+ includeInternal: _zod.z.boolean().default(false)
146
+ }).refine((input) => input.startDate <= input.endDate, {
147
+ message: "endDate must be on or after startDate",
148
+ path: ["endDate"]
112
149
  });
113
150
  var zFunnelStep = _zod.z.object({
114
151
  step: _zod.z.number().int().min(1),
@@ -130,8 +167,8 @@ var zFunnelResponse = zQueryEnvelope(zFunnelData);
130
167
  var zRetentionInterval = _zod.z.enum(["day", "week", "month"]);
131
168
  var zRetentionInput = _zod.z.object({
132
169
  projectId: _zod.z.string().min(1),
133
- startDate: _chunkCSTC3ADGcjs.zDate,
134
- endDate: _chunkCSTC3ADGcjs.zDate,
170
+ startDate: _chunkOLSMH4RYcjs.zDate,
171
+ endDate: _chunkOLSMH4RYcjs.zDate,
135
172
  interval: zRetentionInterval.default("day"),
136
173
  periods: _zod.z.number().int().min(1).max(30).default(7),
137
174
  startEvent: _zod.z.string().min(1).max(200).optional(),
@@ -156,7 +193,12 @@ var zRetentionInput = _zod.z.object({
156
193
  * cut on UTC days and cannot be re-cut after the fact — so expect a slower
157
194
  * query in exchange for cohorts that match the reader's calendar.
158
195
  */
159
- timezone: zTimezone.optional()
196
+ timezone: zTimezone.optional(),
197
+ /** Accepted for symmetry with events.timeseries; retention reads named or all-event activity and does not yet apply the internal filter. */
198
+ includeInternal: _zod.z.boolean().default(false)
199
+ }).refine((input) => input.startDate <= input.endDate, {
200
+ message: "endDate must be on or after startDate",
201
+ path: ["endDate"]
160
202
  });
161
203
  var zRetentionCell = _zod.z.object({
162
204
  /** `0` is the cohort's own period. */
@@ -168,7 +210,8 @@ var zRetentionCell = _zod.z.object({
168
210
  var zRetentionData = _zod.z.object({
169
211
  matrix: _zod.z.array(
170
212
  _zod.z.object({
171
- cohortDate: _zod.z.string(),
213
+ /** Cohort bucket start, same shape and zone as {@link zBucketStart}. */
214
+ cohortDate: zBucketStart,
172
215
  cohortSize: _zod.z.number().int().nonnegative(),
173
216
  /** Length is `periods + 1`, index-aligned to `period`. */
174
217
  retention: _zod.z.array(zRetentionCell)
@@ -183,6 +226,62 @@ var zRetentionData = _zod.z.object({
183
226
  timezone: _zod.z.string()
184
227
  });
185
228
  var zRetentionResponse = zQueryEnvelope(zRetentionData);
229
+ var zTrafficOverviewInput = _zod.z.object({
230
+ projectId: _zod.z.string().min(1),
231
+ startDate: _chunkOLSMH4RYcjs.zDate,
232
+ endDate: _chunkOLSMH4RYcjs.zDate,
233
+ granularity: zGranularity.default("day"),
234
+ timezone: zTimezone.optional()
235
+ }).refine((input) => input.startDate <= input.endDate, {
236
+ message: "endDate must be on or after startDate",
237
+ path: ["endDate"]
238
+ });
239
+ var zTrafficTotals = _zod.z.object({
240
+ sessions: _zod.z.number().int().nonnegative(),
241
+ pageviews: _zod.z.number().int().nonnegative(),
242
+ newVisitors: _zod.z.number().int().nonnegative(),
243
+ returningVisitors: _zod.z.number().int().nonnegative(),
244
+ /** Percent of sessions that bounced, two decimals. */
245
+ bounceRate: _zod.z.number()
246
+ });
247
+ var zTrafficSeriesPoint = zTrafficTotals.extend({ date: zBucketStart });
248
+ var zTrafficOverviewData = _zod.z.object({
249
+ granularity: zGranularity,
250
+ timezone: _zod.z.string(),
251
+ totals: zTrafficTotals,
252
+ series: _zod.z.array(zTrafficSeriesPoint)
253
+ });
254
+ var zTrafficOverviewResponse = zQueryEnvelope(zTrafficOverviewData);
255
+ var zTrafficDimension = _zod.z.enum(["channel", "referrer", "utm"]);
256
+ var zTrafficSourcesInput = _zod.z.object({
257
+ projectId: _zod.z.string().min(1),
258
+ startDate: _chunkOLSMH4RYcjs.zDate,
259
+ endDate: _chunkOLSMH4RYcjs.zDate,
260
+ /** `channel`: channel_type · `referrer`: referrer name+type · `utm`: source/medium/campaign. */
261
+ dimension: zTrafficDimension,
262
+ limit: _zod.z.number().int().min(1).max(100).default(10),
263
+ timezone: zTimezone.optional()
264
+ }).refine((input) => input.startDate <= input.endDate, {
265
+ message: "endDate must be on or after startDate",
266
+ path: ["endDate"]
267
+ });
268
+ var zTrafficSourceRow = zTrafficTotals.extend({
269
+ /** Display key for the row: the channel, the referrer name, or `source / medium / campaign`. */
270
+ key: _zod.z.string(),
271
+ channelType: _zod.z.string().optional(),
272
+ referrerName: _zod.z.string().optional(),
273
+ referrerType: _zod.z.string().optional(),
274
+ utmSource: _zod.z.string().optional(),
275
+ utmMedium: _zod.z.string().optional(),
276
+ utmCampaign: _zod.z.string().optional()
277
+ });
278
+ var zTrafficSourcesData = _zod.z.object({
279
+ dimension: zTrafficDimension,
280
+ timezone: _zod.z.string(),
281
+ /** Ordered by sessions, descending. */
282
+ rows: _zod.z.array(zTrafficSourceRow)
283
+ });
284
+ var zTrafficSourcesResponse = zQueryEnvelope(zTrafficSourcesData);
186
285
  var QUERY_ERROR_CODES = [
187
286
  /** 401 — unknown or mismatched credentials. */
188
287
  "unauthorized",
@@ -194,6 +293,8 @@ var QUERY_ERROR_CODES = [
194
293
  "validation_failed",
195
294
  /** 400 — inputs are individually valid but cannot be served together (e.g. breakdown + segmentId). */
196
295
  "unsupported_combination",
296
+ /** 410 — the project is being deleted. Permanent; stop asking. */
297
+ "project_purging",
197
298
  /** 429 — per-credential query rate limit. `Retry-After` set. */
198
299
  "rate_limited",
199
300
  /** 504 — the analytics backend exceeded its statement timeout. Narrow the window. */
@@ -213,7 +314,9 @@ var zQueryError = _zod.z.object({
213
314
  var QUERY_API_PATHS = {
214
315
  eventsTimeseries: "/api/v1/query/events/timeseries",
215
316
  funnel: "/api/v1/query/funnel",
216
- retention: "/api/v1/query/retention"
317
+ retention: "/api/v1/query/retention",
318
+ trafficOverview: "/api/v1/query/traffic/overview",
319
+ trafficSources: "/api/v1/query/traffic/sources"
217
320
  };
218
321
 
219
322
 
@@ -241,5 +344,18 @@ var QUERY_API_PATHS = {
241
344
 
242
345
 
243
346
 
244
- exports.zGranularity = zGranularity; exports.zTimezone = zTimezone; exports.isValidTimeZone = isValidTimeZone; exports.zChannelFilter = zChannelFilter; exports.zQueryMeta = zQueryMeta; exports.zQueryEnvelope = zQueryEnvelope; exports.zTimeseriesBreakdown = zTimeseriesBreakdown; exports.zEventsTimeseriesInput = zEventsTimeseriesInput; exports.zTimeseriesPoint = zTimeseriesPoint; exports.zEventsTimeseriesData = zEventsTimeseriesData; exports.zEventsTimeseriesResponse = zEventsTimeseriesResponse; exports.zFunnelInput = zFunnelInput; exports.zFunnelStep = zFunnelStep; exports.zFunnelData = zFunnelData; exports.zFunnelResponse = zFunnelResponse; exports.zRetentionInterval = zRetentionInterval; exports.zRetentionInput = zRetentionInput; exports.zRetentionCell = zRetentionCell; exports.zRetentionData = zRetentionData; exports.zRetentionResponse = zRetentionResponse; exports.QUERY_ERROR_CODES = QUERY_ERROR_CODES; exports.zQueryErrorCode = zQueryErrorCode; exports.zQueryError = zQueryError; exports.QUERY_API_PATHS = QUERY_API_PATHS;
245
- //# sourceMappingURL=chunk-GCLUMVPA.cjs.map
347
+
348
+
349
+
350
+
351
+
352
+
353
+
354
+
355
+
356
+
357
+
358
+
359
+
360
+ exports.zGranularity = zGranularity; exports.zTimezone = zTimezone; exports.isValidTimeZone = isValidTimeZone; exports.zChannelFilter = zChannelFilter; exports.zQuerySource = zQuerySource; exports.zQueryMeta = zQueryMeta; exports.zQueryEnvelope = zQueryEnvelope; exports.zTimeseriesBreakdown = zTimeseriesBreakdown; exports.zEventPropertyFilter = zEventPropertyFilter; exports.zEventsTimeseriesInput = zEventsTimeseriesInput; exports.zBucketStart = zBucketStart; exports.zTimeseriesPoint = zTimeseriesPoint; exports.zEventsTimeseriesData = zEventsTimeseriesData; exports.zEventsTimeseriesResponse = zEventsTimeseriesResponse; exports.zFunnelInput = zFunnelInput; exports.zFunnelStep = zFunnelStep; exports.zFunnelData = zFunnelData; exports.zFunnelResponse = zFunnelResponse; exports.zRetentionInterval = zRetentionInterval; exports.zRetentionInput = zRetentionInput; exports.zRetentionCell = zRetentionCell; exports.zRetentionData = zRetentionData; exports.zRetentionResponse = zRetentionResponse; exports.zTrafficOverviewInput = zTrafficOverviewInput; exports.zTrafficTotals = zTrafficTotals; exports.zTrafficSeriesPoint = zTrafficSeriesPoint; exports.zTrafficOverviewData = zTrafficOverviewData; exports.zTrafficOverviewResponse = zTrafficOverviewResponse; exports.zTrafficDimension = zTrafficDimension; exports.zTrafficSourcesInput = zTrafficSourcesInput; exports.zTrafficSourceRow = zTrafficSourceRow; exports.zTrafficSourcesData = zTrafficSourcesData; exports.zTrafficSourcesResponse = zTrafficSourcesResponse; exports.QUERY_ERROR_CODES = QUERY_ERROR_CODES; exports.zQueryErrorCode = zQueryErrorCode; exports.zQueryError = zQueryError; exports.QUERY_API_PATHS = QUERY_API_PATHS;
361
+ //# sourceMappingURL=chunk-VQ2CD5MG.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/eric/reopt-ai/reopt-data/packages/data-contract/dist/chunk-VQ2CD5MG.cjs","../src/query.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACF,wDAA6B;AAC7B;AACA;ACOA,0BAAkB;AAMX,IAAM,aAAA,EAAe,MAAA,CAAE,IAAA,CAAK,CAAC,MAAA,EAAQ,KAAA,EAAO,MAAA,EAAQ,OAAO,CAAC,CAAA;AAc5D,IAAM,UAAA,EAAY,MAAA,CAAE,MAAA,CAAO,CAAA,CAAE,GAAA,CAAI,CAAC,CAAA,CAAE,GAAA,CAAI,EAAE,CAAA,CAAE,MAAA,CAAO,eAAA,EAAiB,EAAE,OAAA,EAAS,yBAAyB,CAAC,CAAA;AAEzG,SAAS,eAAA,CAAgB,KAAA,EAAwB;AACtD,EAAA,IAAI;AACF,IAAA,IAAI,IAAA,CAAK,cAAA,CAAe,OAAA,EAAS,EAAE,QAAA,EAAU,MAAM,CAAC,CAAA;AACpD,IAAA,OAAO,IAAA;AAAA,EACT,EAAA,UAAQ;AACN,IAAA,OAAO,KAAA;AAAA,EACT;AACF;AAOO,IAAM,eAAA,EAAiB,MAAA,CAC3B,MAAA,CAAO;AAAA,EACN,aAAA,EAAe,MAAA,CAAE,KAAA,CAAM,MAAA,CA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Content":[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 zQuerySource = z.enum([\"rollup\", \"raw\", \"mixed\"]);\nexport type QuerySource = z.infer<typeof zQuerySource>;\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 live materialization was when the computation ran, in\n * seconds. `0` means no live event is pending; `null` means measurement\n * failed and must never be interpreted as fresh.\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().nullable(),\n /** Whether the freshness measurement itself succeeded. */\n ingestLagStatus: z.enum([\"known\", \"unknown\"]),\n /**\n * Pending events older than the live replay window. Kept separate so an old\n * permanently failing event neither pegs live lag nor disappears behind 0.\n * `null` means the measurement failed.\n */\n ingestDeadLetterCount: z.number().int().nonnegative().nullable(),\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 /**\n * Where the numbers came from. `rollup`: pre-aggregated hourly tables;\n * `raw`: a scan of the event/session tables; `mixed`: finished hours from\n * the rollup, the hour still in progress from raw. Diagnostic — the values\n * agree either way — but a consumer that expected `rollup` and sees `raw`\n * has asked for a combination the rollups cannot serve.\n */\n source: zQuerySource,\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(100).default(5),\n});\nexport type TimeseriesBreakdown = z.infer<typeof zTimeseriesBreakdown>;\n\n/** Exact-match filter for a top-level event `properties` key. Multiple filters are ANDed. */\nexport const zEventPropertyFilter = z.object({\n key: z.string().min(1).max(200),\n operator: z.literal(\"eq\").default(\"eq\"),\n value: z.string().min(1).max(500),\n});\nexport type EventPropertyFilter = z.infer<typeof zEventPropertyFilter>;\n\nexport const zEventsTimeseriesInput = z\n .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 /** Exact matches against top-level `properties` keys. Every item must match. */\n propertyFilters: z.array(zEventPropertyFilter).max(10).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 /**\n * Events whose catalogue status is `internal` (operational probes) are\n * left out by default. A probe that needs to find its own event sets this.\n */\n includeInternal: z.boolean().default(false),\n })\n .refine((input) => input.startDate <= input.endDate, {\n message: \"endDate must be on or after startDate\",\n path: [\"endDate\"],\n });\nexport type EventsTimeseriesInput = z.input<typeof zEventsTimeseriesInput>;\n\n/**\n * Bucket start as wall-clock time in `meta.timezone`, `YYYY-MM-DD HH:MM:SS`.\n *\n * Pinned rather than left to the backend, because a consumer keys its chart on\n * this string: an unspecified format is one where two backends, or two\n * granularities, can quietly disagree and produce two different keys for the\n * same bucket.\n *\n * It is wall time, not an instant — for `Asia/Seoul` a day bucket reads\n * `2026-08-24 00:00:00`, which is `2026-08-23T15:00:00Z`. Day, week and month\n * buckets always carry `00:00:00`, so slicing the first ten characters is a\n * safe way to get a date key.\n */\nexport const zBucketStart = z.string().regex(/^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}$/, \"expected 'YYYY-MM-DD HH:MM:SS'\");\n\nexport const zTimeseriesPoint = z.object({\n date: zBucketStart,\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\n .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 /** Accepted for symmetry with events.timeseries; funnel steps are named explicitly, so nothing is filtered. */\n includeInternal: z.boolean().default(false),\n })\n .refine((input) => input.startDate <= input.endDate, {\n message: \"endDate must be on or after startDate\",\n path: [\"endDate\"],\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\n .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 /** Accepted for symmetry with events.timeseries; retention reads named or all-event activity and does not yet apply the internal filter. */\n includeInternal: z.boolean().default(false),\n })\n .refine((input) => input.startDate <= input.endDate, {\n message: \"endDate must be on or after startDate\",\n path: [\"endDate\"],\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 /** Cohort bucket start, same shape and zone as {@link zBucketStart}. */\n cohortDate: zBucketStart,\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// ─── traffic ────────────────────────────────────────────────────────────────\n\n/**\n * Session-level traffic for a brand site, served from the hourly rollups.\n * `newVisitors` counts sessions whose device was first seen inside them;\n * `returningVisitors` is the rest. Both are session counts, not people —\n * \"visitor\" is the vocabulary the dashboards already use.\n */\nexport const zTrafficOverviewInput = z\n .object({\n projectId: z.string().min(1),\n startDate: zDate,\n endDate: zDate,\n granularity: zGranularity.default(\"day\"),\n timezone: zTimezone.optional(),\n })\n .refine((input) => input.startDate <= input.endDate, {\n message: \"endDate must be on or after startDate\",\n path: [\"endDate\"],\n });\nexport type TrafficOverviewInput = z.input<typeof zTrafficOverviewInput>;\n\nexport const zTrafficTotals = z.object({\n sessions: z.number().int().nonnegative(),\n pageviews: z.number().int().nonnegative(),\n newVisitors: z.number().int().nonnegative(),\n returningVisitors: z.number().int().nonnegative(),\n /** Percent of sessions that bounced, two decimals. */\n bounceRate: z.number(),\n});\nexport type TrafficTotals = z.infer<typeof zTrafficTotals>;\n\nexport const zTrafficSeriesPoint = zTrafficTotals.extend({ date: zBucketStart });\n\nexport const zTrafficOverviewData = z.object({\n granularity: zGranularity,\n timezone: z.string(),\n totals: zTrafficTotals,\n series: z.array(zTrafficSeriesPoint),\n});\nexport type TrafficOverviewData = z.infer<typeof zTrafficOverviewData>;\nexport const zTrafficOverviewResponse = zQueryEnvelope(zTrafficOverviewData);\nexport type TrafficOverviewResponse = z.infer<typeof zTrafficOverviewResponse>;\n\nexport const zTrafficDimension = z.enum([\"channel\", \"referrer\", \"utm\"]);\nexport type TrafficDimension = z.infer<typeof zTrafficDimension>;\n\nexport const zTrafficSourcesInput = z\n .object({\n projectId: z.string().min(1),\n startDate: zDate,\n endDate: zDate,\n /** `channel`: channel_type · `referrer`: referrer name+type · `utm`: source/medium/campaign. */\n dimension: zTrafficDimension,\n limit: z.number().int().min(1).max(100).default(10),\n timezone: zTimezone.optional(),\n })\n .refine((input) => input.startDate <= input.endDate, {\n message: \"endDate must be on or after startDate\",\n path: [\"endDate\"],\n });\nexport type TrafficSourcesInput = z.input<typeof zTrafficSourcesInput>;\n\nexport const zTrafficSourceRow = zTrafficTotals.extend({\n /** Display key for the row: the channel, the referrer name, or `source / medium / campaign`. */\n key: z.string(),\n channelType: z.string().optional(),\n referrerName: z.string().optional(),\n referrerType: z.string().optional(),\n utmSource: z.string().optional(),\n utmMedium: z.string().optional(),\n utmCampaign: z.string().optional(),\n});\nexport type TrafficSourceRow = z.infer<typeof zTrafficSourceRow>;\n\nexport const zTrafficSourcesData = z.object({\n dimension: zTrafficDimension,\n timezone: z.string(),\n /** Ordered by sessions, descending. */\n rows: z.array(zTrafficSourceRow),\n});\nexport type TrafficSourcesData = z.infer<typeof zTrafficSourcesData>;\nexport const zTrafficSourcesResponse = zQueryEnvelope(zTrafficSourcesData);\nexport type TrafficSourcesResponse = z.infer<typeof zTrafficSourcesResponse>;\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 /** 410 — the project is being deleted. Permanent; stop asking. */\n \"project_purging\",\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 trafficOverview: \"/api/v1/query/traffic/overview\",\n trafficSources: \"/api/v1/query/traffic/sources\",\n} as const;\n"]}
@@ -4,9 +4,10 @@ var RESERVED_EVENT_NAMES = ["session_start", "session_end", "screen_view"];
4
4
  var MAX_TRACK_PAYLOAD_BYTES = 512e3;
5
5
  var zClientEventMetadata = {
6
6
  /**
7
- * Client-generated UUID. This is the idempotency key: it becomes the
8
- * `RawEvent` primary key, scoped to the project. Re-sending the same
9
- * eventId is always safe and always reported as a duplicate.
7
+ * Client-generated UUID. This is the project-scoped idempotency key stored as
8
+ * `RawEvent.clientEventId`; the server uses a separate globally unique raw
9
+ * event id internally. Re-sending the same eventId to the same project is
10
+ * always safe and always reported as a duplicate.
10
11
  */
11
12
  eventId: _zod.z.uuid(),
12
13
  /** Event time, epoch milliseconds. */
@@ -113,6 +114,8 @@ var INGEST_ERROR_CODES = [
113
114
  "rate_limited",
114
115
  /** 429 — the organization's monthly event quota is exhausted. `Retry-After` set (capped at 1h). Alert: a human must raise the limit. */
115
116
  "quota_exceeded",
117
+ /** 410 — the project is being deleted. Permanent; stop sending. */
118
+ "project_purging",
116
119
  /** 500 — unexpected server failure. Back off and retry. */
117
120
  "internal_error"
118
121
  ];
@@ -148,4 +151,4 @@ var zIngestError = _zod.z.object({
148
151
 
149
152
 
150
153
  exports.RESERVED_EVENT_NAMES = RESERVED_EVENT_NAMES; exports.MAX_TRACK_PAYLOAD_BYTES = MAX_TRACK_PAYLOAD_BYTES; exports.zTrackPayload = zTrackPayload; exports.zIdentifyPayload = zIdentifyPayload; exports.zIncrementPayload = zIncrementPayload; exports.zDecrementPayload = zDecrementPayload; exports.zTrackHandlerPayload = zTrackHandlerPayload; exports.INGEST_MODES = INGEST_MODES; exports.zIngestMode = zIngestMode; exports.INGEST_REJECTION_REASONS = INGEST_REJECTION_REASONS; exports.zIngestRejectionReason = zIngestRejectionReason; exports.zIngestRejection = zIngestRejection; exports.zIngestOkResponse = zIngestOkResponse; exports.zIngestAcceptedResponse = zIngestAcceptedResponse; exports.zIngestResponse = zIngestResponse; exports.reconcileIngestResponse = reconcileIngestResponse; exports.INGEST_ERROR_CODES = INGEST_ERROR_CODES; exports.zIngestErrorCode = zIngestErrorCode; exports.zIngestError = zIngestError;
151
- //# sourceMappingURL=chunk-HRKELGGH.cjs.map
154
+ //# sourceMapping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AA;AACD,EAAA;AACJ,EAAA;AACA,EAAA;AACoB,EAAA;AACxD;AAEyC;AACW,EAAA;AAChB,EAAA;AACG,EAAA;AACvC;AAEyC;AACW,EAAA;AAChB,EAAA;AACG,EAAA;AACvC;AAEgE;AACuB,EAAA;AACM,EAAA;AACpB,EAAA;AACA,EAAA;AACzE;AAqB+C;AACF;AAUN;AAAA;AAEtC,EAAA;AAAA;AAEA,EAAA;AAAA;AAEA,EAAA;AACF;AACqE;AAG5B;AAAA;AAErB,EAAA;AAAA;AAEkB,EAAA;AAC5B,EAAA;AACqB,EAAA;AAC9B;AAGoB;AAAA;AAEoB,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAME,EAAA;AAAA;AAEP,EAAA;AACpC;AAG0C;AAClB,EAAA;AACF,EAAA;AACd,EAAA;AACH,EAAA;AACe,EAAA;AACnB;AAQ+C;AAClB,EAAA;AACR,EAAA;AACd,EAAA;AACH,EAAA;AAC8B,EAAA;AACY,EAAA;AAC9C;AAEiF;AAcY;AACd,EAAA;AAChF;AAQkC;AAAA;AAEhC,EAAA;AAAA;AAEA,EAAA;AAAA;AAEA,EAAA;AAAA;AAEA,EAAA;AAAA;AAEA,EAAA;AAAA;AAEA,EAAA;AAAA;AAEA,EAAA;AAAA;AAEA,EAAA;AAAA;AAEA,EAAA;AAAA;AAEA,EAAA;AAAA;AAEA,EAAA;AACF;AACyD;AAGpB;AACZ,EAAA;AACjB,EAAA;AACU,EAAA;AACa,EAAA;AAAA;AAEA,EAAA;AACE,EAAA;AAChC;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-XI3VP5DN.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 project-scoped idempotency key stored as\n * `RawEvent.clientEventId`; the server uses a separate globally unique raw\n * event id internally. Re-sending the same eventId to the same project is\n * always safe and always reported as a duplicate.\n */\n eventId: z.uuid(),\n /** Event time, epoch milliseconds. */\n timestamp: z.number().int().nonnegative(),\n};\n\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 /** 410 — the project is being deleted. Permanent; stop sending. */\n \"project_purging\",\n /** 500 — unexpected server failure. Back off and retry. */\n \"internal_error\",\n] as const;\nexport const zIngestErrorCode = z.enum(INGEST_ERROR_CODES);\nexport type IngestErrorCode = z.infer<typeof zIngestErrorCode>;\n\nexport const zIngestError = z.object({\n status: z.number().int(),\n code: zIngestErrorCode,\n error: z.string(),\n message: z.string().optional(),\n /** zod issues, when `code === \"validation_failed\"`. */\n errors: z.unknown().optional(),\n requestId: z.string().optional(),\n});\nexport type IngestError = z.infer<typeof zIngestError>;\n"]}