@reopt-ai/data-contract 0.6.3 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/dist/client.cjs +228 -321
  2. package/dist/client.cjs.map +1 -1
  3. package/dist/client.d.cts +57 -71
  4. package/dist/client.d.cts.map +1 -0
  5. package/dist/client.d.ts +57 -71
  6. package/dist/client.d.ts.map +1 -0
  7. package/dist/client.js +228 -322
  8. package/dist/client.js.map +1 -1
  9. package/dist/control.cjs +158 -54
  10. package/dist/control.cjs.map +1 -1
  11. package/dist/control.d.cts +121 -137
  12. package/dist/control.d.cts.map +1 -0
  13. package/dist/control.d.ts +121 -137
  14. package/dist/control.d.ts.map +1 -0
  15. package/dist/control.js +134 -54
  16. package/dist/control.js.map +1 -1
  17. package/dist/events-BUIeU60t.d.cts +142 -0
  18. package/dist/events-BUIeU60t.d.cts.map +1 -0
  19. package/dist/events-BUIeU60t.d.ts +142 -0
  20. package/dist/events-BUIeU60t.d.ts.map +1 -0
  21. package/dist/events.cjs +110 -15
  22. package/dist/events.cjs.map +1 -1
  23. package/dist/events.d.cts +2 -59
  24. package/dist/events.d.ts +2 -59
  25. package/dist/events.js +101 -15
  26. package/dist/events.js.map +1 -1
  27. package/dist/identity.cjs +150 -55
  28. package/dist/identity.cjs.map +1 -1
  29. package/dist/identity.d.cts +21 -20
  30. package/dist/identity.d.cts.map +1 -0
  31. package/dist/identity.d.ts +21 -20
  32. package/dist/identity.d.ts.map +1 -0
  33. package/dist/identity.js +126 -56
  34. package/dist/identity.js.map +1 -1
  35. package/dist/index.cjs +46 -25
  36. package/dist/index.cjs.map +1 -1
  37. package/dist/index.d.cts +37 -54
  38. package/dist/index.d.cts.map +1 -0
  39. package/dist/index.d.ts +37 -54
  40. package/dist/index.d.ts.map +1 -0
  41. package/dist/index.js +36 -25
  42. package/dist/index.js.map +1 -1
  43. package/dist/ingest.cjs +152 -57
  44. package/dist/ingest.cjs.map +1 -1
  45. package/dist/ingest.d.cts +182 -193
  46. package/dist/ingest.d.cts.map +1 -0
  47. package/dist/ingest.d.ts +182 -193
  48. package/dist/ingest.d.ts.map +1 -0
  49. package/dist/ingest.js +126 -57
  50. package/dist/ingest.js.map +1 -1
  51. package/dist/query.cjs +284 -84
  52. package/dist/query.cjs.map +1 -1
  53. package/dist/query.d.cts +456 -469
  54. package/dist/query.d.cts.map +1 -0
  55. package/dist/query.d.ts +456 -469
  56. package/dist/query.d.ts.map +1 -0
  57. package/dist/query.js +245 -84
  58. package/dist/query.js.map +1 -1
  59. package/dist/report.cjs +104 -74
  60. package/dist/report.cjs.map +1 -1
  61. package/dist/report.d.cts +182 -136
  62. package/dist/report.d.cts.map +1 -0
  63. package/dist/report.d.ts +182 -136
  64. package/dist/report.d.ts.map +1 -0
  65. package/dist/report.js +93 -74
  66. package/dist/report.js.map +1 -1
  67. package/dist/version-B_0qb1_K.cjs +53 -0
  68. package/dist/version-B_0qb1_K.cjs.map +1 -0
  69. package/dist/version-C09Cyf4R.js +12 -0
  70. package/dist/version-C09Cyf4R.js.map +1 -0
  71. package/dist/{version-DJ2Grb_N.d.ts → version-CGujUGWd.d.cts} +5 -3
  72. package/dist/version-CGujUGWd.d.cts.map +1 -0
  73. package/dist/{version-DJ2Grb_N.d.cts → version-CGujUGWd.d.ts} +5 -3
  74. package/dist/version-CGujUGWd.d.ts.map +1 -0
  75. package/package.json +69 -28
  76. package/dist/chunk-3EEANNYN.cjs +0 -62
  77. package/dist/chunk-3EEANNYN.cjs.map +0 -1
  78. package/dist/chunk-7W33YGRO.js +0 -160
  79. package/dist/chunk-7W33YGRO.js.map +0 -1
  80. package/dist/chunk-F2RNXJGO.cjs +0 -19
  81. package/dist/chunk-F2RNXJGO.cjs.map +0 -1
  82. package/dist/chunk-FP2X3PRK.js +0 -62
  83. package/dist/chunk-FP2X3PRK.js.map +0 -1
  84. package/dist/chunk-JCEWUSUM.js +0 -53
  85. package/dist/chunk-JCEWUSUM.js.map +0 -1
  86. package/dist/chunk-L3JPDRVG.cjs +0 -160
  87. package/dist/chunk-L3JPDRVG.cjs.map +0 -1
  88. package/dist/chunk-L4KBQAOO.js +0 -204
  89. package/dist/chunk-L4KBQAOO.js.map +0 -1
  90. package/dist/chunk-NJ4JKNBX.js +0 -361
  91. package/dist/chunk-NJ4JKNBX.js.map +0 -1
  92. package/dist/chunk-ORNTN6AK.cjs +0 -53
  93. package/dist/chunk-ORNTN6AK.cjs.map +0 -1
  94. package/dist/chunk-PSUINLW7.js +0 -19
  95. package/dist/chunk-PSUINLW7.js.map +0 -1
  96. package/dist/chunk-RU26QFM2.js +0 -179
  97. package/dist/chunk-RU26QFM2.js.map +0 -1
  98. package/dist/chunk-XDH5QQYF.cjs +0 -361
  99. package/dist/chunk-XDH5QQYF.cjs.map +0 -1
  100. package/dist/chunk-YCTGHWTP.cjs +0 -204
  101. package/dist/chunk-YCTGHWTP.cjs.map +0 -1
  102. package/dist/chunk-ZI6A3WQP.cjs +0 -179
  103. package/dist/chunk-ZI6A3WQP.cjs.map +0 -1
@@ -1,204 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
-
3
- var _chunkXDH5QQYFcjs = require('./chunk-XDH5QQYF.cjs');
4
-
5
-
6
- var _chunkORNTN6AKcjs = require('./chunk-ORNTN6AK.cjs');
7
-
8
- // src/control.ts
9
- var _zod = require('zod');
10
- var PLATFORM_KEY_HEADER = "reopt-platform-key";
11
- var ORG_KEY_HEADER = "reopt-org-key";
12
- var zExternalId = _zod.z.string().min(1).max(191);
13
- var zCreateOrganizationInput = _zod.z.object({
14
- externalId: zExternalId,
15
- name: _zod.z.string().min(1).max(200),
16
- slug: _zod.z.string().min(1).max(100).regex(/^[a-z0-9-]+$/, "lowercase letters, digits and hyphens only").optional(),
17
- monthlyEventQuota: _zod.z.number().int().nonnegative().optional(),
18
- monthlyCreditQuota: _zod.z.number().int().nonnegative().optional()
19
- });
20
- var zOrganization = _zod.z.object({
21
- id: _zod.z.string(),
22
- externalId: zExternalId,
23
- name: _zod.z.string(),
24
- slug: _zod.z.string(),
25
- monthlyEventQuota: _zod.z.number().int(),
26
- monthlyCreditQuota: _zod.z.number().int()
27
- });
28
- var zCreateOrganizationResponse = _zod.z.object({
29
- /** `false` when this externalId already had an organization. */
30
- created: _zod.z.boolean(),
31
- organization: zOrganization,
32
- /**
33
- * Plaintext, returned here and nowhere else.
34
- *
35
- * Absent when `created` is `false`: re-issuing on every retry would let a
36
- * retry quietly multiply live credentials. A caller that lost the key rotates
37
- * instead — see `POST /api/v1/organizations/{id}/keys`.
38
- */
39
- orgKey: _zod.z.string().optional()
40
- });
41
- var zRotateOrganizationKeyResponse = _zod.z.object({
42
- organizationId: _zod.z.string(),
43
- keyPrefix: _zod.z.string(),
44
- /** Plaintext, returned once. Every previously issued key is revoked immediately. */
45
- orgKey: _zod.z.string()
46
- });
47
- var zUpdateOrganizationQuotaInput = _zod.z.object({
48
- monthlyEventQuota: _zod.z.number().int().nonnegative().optional(),
49
- monthlyCreditQuota: _zod.z.number().int().nonnegative().optional()
50
- }).refine((value) => value.monthlyEventQuota !== void 0 || value.monthlyCreditQuota !== void 0, {
51
- message: "at least one quota must be given"
52
- });
53
- var zUpdateOrganizationQuotaResponse = _zod.z.object({ organization: zOrganization });
54
- var zCreateProjectInput = _zod.z.object({
55
- externalId: zExternalId,
56
- name: _zod.z.string().min(1).max(200),
57
- domain: _zod.z.string().max(253).optional(),
58
- /** Becomes the project's default for every query that omits one. */
59
- timezone: _chunkXDH5QQYFcjs.zTimezone.optional(),
60
- retentionDays: _zod.z.number().int().min(1).max(3650).optional()
61
- });
62
- var zProject = _zod.z.object({
63
- id: _zod.z.string(),
64
- externalId: zExternalId,
65
- organizationId: _zod.z.string(),
66
- name: _zod.z.string(),
67
- /** The applied value — `"UTC"` when none was given. */
68
- timezone: _zod.z.string(),
69
- retentionDays: _zod.z.number().int().nullable()
70
- });
71
- var zCreateProjectResponse = _zod.z.object({
72
- created: _zod.z.boolean(),
73
- project: zProject,
74
- /**
75
- * Two credentials, not one. A key embedded in a browser bundle must not also
76
- * be able to read the project's analytics, so the browser write key and the
77
- * server secret are separate rows with different reach.
78
- */
79
- clients: _zod.z.object({
80
- browser: _zod.z.object({
81
- id: _zod.z.string(),
82
- /** Public by design, and recoverable — it ships in page source anyway. */
83
- writeKey: _zod.z.string(),
84
- scopes: _zod.z.array(_zod.z.string())
85
- }),
86
- server: _zod.z.object({
87
- id: _zod.z.string(),
88
- /** Plaintext, returned once. Absent when `created` is `false`. */
89
- clientSecret: _zod.z.string().optional(),
90
- scopes: _zod.z.array(_zod.z.string())
91
- })
92
- })
93
- });
94
- var zRotateClientSecretResponse = _zod.z.object({
95
- projectId: _zod.z.string(),
96
- clientId: _zod.z.string(),
97
- /** Plaintext, returned once. The previous secret stops working immediately. */
98
- clientSecret: _zod.z.string()
99
- });
100
- var zDeleteProjectInput = _zod.z.object({
101
- /**
102
- * A field in the body rather than `?purge=true`. This deletes the project's
103
- * Postgres rows and every analytics row behind it, with no undo — and a query
104
- * parameter is far too easy to fire from shell history or a mis-copied URL.
105
- */
106
- purge: _zod.z.literal(true),
107
- /** Checked against the project on record; a mismatch is refused. */
108
- externalId: zExternalId
109
- });
110
- var zDeleteProjectResponse = _zod.z.object({
111
- projectId: _zod.z.string(),
112
- /** Idempotent, but it still says which of the two happened. */
113
- purge: _zod.z.enum(["queued", "already-absent"]),
114
- /** When the purge was marked. Absent for `already-absent`. */
115
- purgingAt: _chunkORNTN6AKcjs.zInstant.optional()
116
- });
117
- var EVENT_META_STATUSES = ["active", "deprecated", "archived", "internal"];
118
- var zEventMetaStatus = _zod.z.enum(EVENT_META_STATUSES);
119
- var zEventName = _zod.z.string().min(1).max(200);
120
- var zUpsertEventMetaInput = _zod.z.object({
121
- conversion: _zod.z.boolean().optional(),
122
- /** `internal` events are left out of every metric unless a query opts in. */
123
- status: zEventMetaStatus.optional(),
124
- /** Property keys the hourly rollups break this event down by. */
125
- rollupProperties: _zod.z.array(_zod.z.string().min(1).max(200)).max(20).optional()
126
- }).strict();
127
- var zEventMetaResponse = _zod.z.object({
128
- projectId: _zod.z.string(),
129
- name: _zod.z.string(),
130
- conversion: _zod.z.boolean(),
131
- status: zEventMetaStatus,
132
- rollupProperties: _zod.z.array(_zod.z.string()),
133
- /** Fields this call actually changed; empty on a repeat. */
134
- changed: _zod.z.array(_zod.z.string()),
135
- updatedAt: _chunkORNTN6AKcjs.zInstant
136
- });
137
- var CONTROL_ERROR_CODES = [
138
- /** 401 — missing or invalid platform key / organization key. */
139
- "unauthorized",
140
- /** 403 — the organization key belongs to a different organization. */
141
- "organization_scope_mismatch",
142
- /**
143
- * 409 — this externalId exists with a materially different configuration.
144
- * Only fields whose change alters results are compared (see the docs); a
145
- * renamed brand is not a conflict.
146
- */
147
- "external_id_conflict",
148
- /** 409 — the externalId in a delete body does not match the project's. */
149
- "project_external_id_mismatch",
150
- /** 404 — no such organization or project, on an endpoint that is not idempotent. */
151
- "not_found",
152
- /** 400 — input failed the schema. */
153
- "validation_failed",
154
- /** 429 — per-credential rate limit. */
155
- "rate_limited",
156
- /** 500 — unexpected server failure. */
157
- "internal_error"
158
- ];
159
- var zControlErrorCode = _zod.z.enum(CONTROL_ERROR_CODES);
160
- var zControlError = _zod.z.object({
161
- status: _zod.z.number().int(),
162
- code: zControlErrorCode,
163
- error: _zod.z.string(),
164
- message: _zod.z.string().optional(),
165
- errors: _zod.z.unknown().optional(),
166
- requestId: _zod.z.string().optional()
167
- });
168
- var CONTROL_API_PATHS = {
169
- organizations: "/api/v1/organizations",
170
- organization: (id) => `/api/v1/organizations/${encodeURIComponent(id)}`,
171
- organizationKeys: (id) => `/api/v1/organizations/${encodeURIComponent(id)}/keys`,
172
- projects: "/api/v1/projects",
173
- project: (id) => `/api/v1/projects/${encodeURIComponent(id)}`,
174
- clientRotate: (projectId, clientId) => `/api/v1/projects/${encodeURIComponent(projectId)}/clients/${encodeURIComponent(clientId)}/rotate`,
175
- projectEvent: (projectId, name) => `/api/v1/projects/${encodeURIComponent(projectId)}/events/${encodeURIComponent(name)}`
176
- };
177
-
178
-
179
-
180
-
181
-
182
-
183
-
184
-
185
-
186
-
187
-
188
-
189
-
190
-
191
-
192
-
193
-
194
-
195
-
196
-
197
-
198
-
199
-
200
-
201
-
202
-
203
- exports.PLATFORM_KEY_HEADER = PLATFORM_KEY_HEADER; exports.ORG_KEY_HEADER = ORG_KEY_HEADER; exports.zExternalId = zExternalId; exports.zCreateOrganizationInput = zCreateOrganizationInput; exports.zOrganization = zOrganization; exports.zCreateOrganizationResponse = zCreateOrganizationResponse; exports.zRotateOrganizationKeyResponse = zRotateOrganizationKeyResponse; exports.zUpdateOrganizationQuotaInput = zUpdateOrganizationQuotaInput; exports.zUpdateOrganizationQuotaResponse = zUpdateOrganizationQuotaResponse; exports.zCreateProjectInput = zCreateProjectInput; exports.zProject = zProject; exports.zCreateProjectResponse = zCreateProjectResponse; exports.zRotateClientSecretResponse = zRotateClientSecretResponse; exports.zDeleteProjectInput = zDeleteProjectInput; exports.zDeleteProjectResponse = zDeleteProjectResponse; exports.EVENT_META_STATUSES = EVENT_META_STATUSES; exports.zEventMetaStatus = zEventMetaStatus; exports.zEventName = zEventName; exports.zUpsertEventMetaInput = zUpsertEventMetaInput; exports.zEventMetaResponse = zEventMetaResponse; exports.CONTROL_ERROR_CODES = CONTROL_ERROR_CODES; exports.zControlErrorCode = zControlErrorCode; exports.zControlError = zControlError; exports.CONTROL_API_PATHS = CONTROL_API_PATHS;
204
- //# sourceMappingURL=chunk-YCTGHWTP.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["/Users/eric/reopt-ai/reopt-data/packages/data-contract/dist/chunk-YCTGHWTP.cjs","../src/control.ts"],"names":[],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACA;ACSA,0BAAkB;AAIX,IAAM,oBAAA,EAAsB,oBAAA;AAC5B,IAAM,eAAA,EAAiB,eA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kBAAA,EAAoB,MAAA,CAAE,IAAA,CAAK,mBAAmB,CAAA;AAGpD,IAAM,cAAA,EAAgB,MAAA,CAAE,MAAA,CAAO;AAAA,EACpC,MAAA,EAAQ,MAAA,CAAE,MAAA,CAAO,CAAA,CAAE,GAAA,CAAI,CAAA;AAAA,EACvB,IAAA,EAAM,iBAAA;AAAA,EACN,KAAA,EAAO,MAAA,CAAE,MAAA,CAAO,CAAA;AAAA,EAChB,OAAA,EAAS,MAAA,CAAE,MAAA,CAAO,CAAA,CAAE,QAAA,CAAS,CAAA;AAAA,EAC7B,MAAA,EAAQ,MAAA,CAAE,OAAA,CAAQ,CAAA,CAAE,QAAA,CAAS,CAAA;AAAA,EAC7B,SAAA,EAAW,MAAA,CAAE,MAAA,CAAO,CAAA,CAAE,QAAA,CAAS;AACjC,CAAC,CAAA;AAIM,IAAM,kBAAA,EAAoB;AAAA,EAC/B,aAAA,EAAe,uBAAA;AAAA,EACf,YAAA,EAAc,CAAC,EAAA,EAAA,GAAe,CAAA,sBAAA,EAAyB,kBAAA,CAAmB,EAAE,CAAC,CAAA,CAAA;AACC,EAAA;AACpE,EAAA;AACyD,EAAA;AAE7C,EAAA;AAEA,EAAA;AACxB;AD9EwE;AACA;AACA;AACA;AACA;AACA;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-YCTGHWTP.cjs","sourcesContent":[null,"/**\n * `POST /api/v1/organizations` · `/api/v1/projects` and friends — the\n * provisioning contract.\n *\n * A project-scoped client credential cannot authenticate the creation of the\n * project it is scoped to, and an organization key cannot authenticate the\n * creation of its own organization. So provisioning runs on two credentials\n * above the client one: a platform key that creates organizations and writes\n * quotas, and an organization key that creates and deletes projects inside one\n * organization.\n *\n * Quota writes sit with the platform key on purpose. Organization keys are held\n * one-per-workspace by the caller and so have a wide exposure surface; a leaked\n * one that could raise its own limits would turn a credential leak into an\n * unbounded bill.\n */\nimport { z } from \"zod\";\nimport { zInstant } from \"./index.js\";\nimport { zTimezone } from \"./query.js\";\n\nexport const PLATFORM_KEY_HEADER = \"reopt-platform-key\";\nexport const ORG_KEY_HEADER = \"reopt-org-key\";\n\n/**\n * The caller's own id for the thing being provisioned.\n *\n * Preferred over an `Idempotency-Key` header because this domain has a real\n * natural key — the caller already has a stable id for the workspace or brand —\n * and a header would make the caller store a second one just to retry safely.\n */\nexport const zExternalId = z.string().min(1).max(191);\n\n// ─── Organizations ──────────────────────────────────────────────────────────\n\nexport const zCreateOrganizationInput = z.object({\n externalId: zExternalId,\n name: z.string().min(1).max(200),\n slug: z\n .string()\n .min(1)\n .max(100)\n .regex(/^[a-z0-9-]+$/, \"lowercase letters, digits and hyphens only\")\n .optional(),\n monthlyEventQuota: z.number().int().nonnegative().optional(),\n monthlyCreditQuota: z.number().int().nonnegative().optional(),\n});\nexport type CreateOrganizationInput = z.input<typeof zCreateOrganizationInput>;\n\nexport const zOrganization = z.object({\n id: z.string(),\n externalId: zExternalId,\n name: z.string(),\n slug: z.string(),\n monthlyEventQuota: z.number().int(),\n monthlyCreditQuota: z.number().int(),\n});\n\nexport const zCreateOrganizationResponse = z.object({\n /** `false` when this externalId already had an organization. */\n created: z.boolean(),\n organization: zOrganization,\n /**\n * Plaintext, returned here and nowhere else.\n *\n * Absent when `created` is `false`: re-issuing on every retry would let a\n * retry quietly multiply live credentials. A caller that lost the key rotates\n * instead — see `POST /api/v1/organizations/{id}/keys`.\n */\n orgKey: z.string().optional(),\n});\nexport type CreateOrganizationResponse = z.infer<typeof zCreateOrganizationResponse>;\n\nexport const zRotateOrganizationKeyResponse = z.object({\n organizationId: z.string(),\n keyPrefix: z.string(),\n /** Plaintext, returned once. Every previously issued key is revoked immediately. */\n orgKey: z.string(),\n});\nexport type RotateOrganizationKeyResponse = z.infer<typeof zRotateOrganizationKeyResponse>;\n\nexport const zUpdateOrganizationQuotaInput = z\n .object({\n monthlyEventQuota: z.number().int().nonnegative().optional(),\n monthlyCreditQuota: z.number().int().nonnegative().optional(),\n })\n .refine((value) => value.monthlyEventQuota !== undefined || value.monthlyCreditQuota !== undefined, {\n message: \"at least one quota must be given\",\n });\nexport type UpdateOrganizationQuotaInput = z.input<typeof zUpdateOrganizationQuotaInput>;\n\nexport const zUpdateOrganizationQuotaResponse = z.object({ organization: zOrganization });\nexport type UpdateOrganizationQuotaResponse = z.infer<typeof zUpdateOrganizationQuotaResponse>;\n\n// ─── Projects ───────────────────────────────────────────────────────────────\n\nexport const zCreateProjectInput = z.object({\n externalId: zExternalId,\n name: z.string().min(1).max(200),\n domain: z.string().max(253).optional(),\n /** Becomes the project's default for every query that omits one. */\n timezone: zTimezone.optional(),\n retentionDays: z.number().int().min(1).max(3650).optional(),\n});\nexport type CreateProjectInput = z.input<typeof zCreateProjectInput>;\n\nexport const zProject = z.object({\n id: z.string(),\n externalId: zExternalId,\n organizationId: z.string(),\n name: z.string(),\n /** The applied value — `\"UTC\"` when none was given. */\n timezone: z.string(),\n retentionDays: z.number().int().nullable(),\n});\n\nexport const zCreateProjectResponse = z.object({\n created: z.boolean(),\n project: zProject,\n /**\n * Two credentials, not one. A key embedded in a browser bundle must not also\n * be able to read the project's analytics, so the browser write key and the\n * server secret are separate rows with different reach.\n */\n clients: z.object({\n browser: z.object({\n id: z.string(),\n /** Public by design, and recoverable — it ships in page source anyway. */\n writeKey: z.string(),\n scopes: z.array(z.string()),\n }),\n server: z.object({\n id: z.string(),\n /** Plaintext, returned once. Absent when `created` is `false`. */\n clientSecret: z.string().optional(),\n scopes: z.array(z.string()),\n }),\n }),\n});\nexport type CreateProjectResponse = z.infer<typeof zCreateProjectResponse>;\n\nexport const zRotateClientSecretResponse = z.object({\n projectId: z.string(),\n clientId: z.string(),\n /** Plaintext, returned once. The previous secret stops working immediately. */\n clientSecret: z.string(),\n});\nexport type RotateClientSecretResponse = z.infer<typeof zRotateClientSecretResponse>;\n\nexport const zDeleteProjectInput = z.object({\n /**\n * A field in the body rather than `?purge=true`. This deletes the project's\n * Postgres rows and every analytics row behind it, with no undo — and a query\n * parameter is far too easy to fire from shell history or a mis-copied URL.\n */\n purge: z.literal(true),\n /** Checked against the project on record; a mismatch is refused. */\n externalId: zExternalId,\n});\nexport type DeleteProjectInput = z.input<typeof zDeleteProjectInput>;\n\nexport const zDeleteProjectResponse = z.object({\n projectId: z.string(),\n /** Idempotent, but it still says which of the two happened. */\n purge: z.enum([\"queued\", \"already-absent\"]),\n /** When the purge was marked. Absent for `already-absent`. */\n purgingAt: zInstant.optional(),\n});\nexport type DeleteProjectResponse = z.infer<typeof zDeleteProjectResponse>;\n\n// ─── Errors ─────────────────────────────────────────────────────────────────\n\n// ─── Event metadata ─────────────────────────────────────────────────────────\n\n/**\n * `PUT /api/v1/projects/{projectId}/events/{name}` — catalogue settings for\n * one event name. Provisioning calls it to mark `form.submitted` a conversion\n * and an operational probe `internal`; the call is idempotent so a retried\n * provisioning run is harmless.\n */\nexport const EVENT_META_STATUSES = [\"active\", \"deprecated\", \"archived\", \"internal\"] as const;\nexport const zEventMetaStatus = z.enum(EVENT_META_STATUSES);\nexport type EventMetaStatus = z.infer<typeof zEventMetaStatus>;\n\nexport const zEventName = z.string().min(1).max(200);\n\nexport const zUpsertEventMetaInput = z\n .object({\n conversion: z.boolean().optional(),\n /** `internal` events are left out of every metric unless a query opts in. */\n status: zEventMetaStatus.optional(),\n /** Property keys the hourly rollups break this event down by. */\n rollupProperties: z.array(z.string().min(1).max(200)).max(20).optional(),\n })\n .strict();\nexport type UpsertEventMetaInput = z.infer<typeof zUpsertEventMetaInput>;\n\nexport const zEventMetaResponse = z.object({\n projectId: z.string(),\n name: z.string(),\n conversion: z.boolean(),\n status: zEventMetaStatus,\n rollupProperties: z.array(z.string()),\n /** Fields this call actually changed; empty on a repeat. */\n changed: z.array(z.string()),\n updatedAt: zInstant,\n});\nexport type EventMetaResponse = z.infer<typeof zEventMetaResponse>;\n\nexport const CONTROL_ERROR_CODES = [\n /** 401 — missing or invalid platform key / organization key. */\n \"unauthorized\",\n /** 403 — the organization key belongs to a different organization. */\n \"organization_scope_mismatch\",\n /**\n * 409 — this externalId exists with a materially different configuration.\n * Only fields whose change alters results are compared (see the docs); a\n * renamed brand is not a conflict.\n */\n \"external_id_conflict\",\n /** 409 — the externalId in a delete body does not match the project's. */\n \"project_external_id_mismatch\",\n /** 404 — no such organization or project, on an endpoint that is not idempotent. */\n \"not_found\",\n /** 400 — input failed the schema. */\n \"validation_failed\",\n /** 429 — per-credential rate limit. */\n \"rate_limited\",\n /** 500 — unexpected server failure. */\n \"internal_error\",\n] as const;\nexport const zControlErrorCode = z.enum(CONTROL_ERROR_CODES);\nexport type ControlErrorCode = z.infer<typeof zControlErrorCode>;\n\nexport const zControlError = z.object({\n status: z.number().int(),\n code: zControlErrorCode,\n error: z.string(),\n message: z.string().optional(),\n errors: z.unknown().optional(),\n requestId: z.string().optional(),\n});\nexport type ControlError = z.infer<typeof zControlError>;\n\n/** Paths, so the client and the route handlers cannot drift apart. */\nexport const CONTROL_API_PATHS = {\n organizations: \"/api/v1/organizations\",\n organization: (id: string) => `/api/v1/organizations/${encodeURIComponent(id)}`,\n organizationKeys: (id: string) => `/api/v1/organizations/${encodeURIComponent(id)}/keys`,\n projects: \"/api/v1/projects\",\n project: (id: string) => `/api/v1/projects/${encodeURIComponent(id)}`,\n clientRotate: (projectId: string, clientId: string) =>\n `/api/v1/projects/${encodeURIComponent(projectId)}/clients/${encodeURIComponent(clientId)}/rotate`,\n projectEvent: (projectId: string, name: string) =>\n `/api/v1/projects/${encodeURIComponent(projectId)}/events/${encodeURIComponent(name)}`,\n} as const;\n"]}
@@ -1,179 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
-
3
- var _chunkL3JPDRVGcjs = require('./chunk-L3JPDRVG.cjs');
4
-
5
-
6
- var _chunk3EEANNYNcjs = require('./chunk-3EEANNYN.cjs');
7
-
8
- // src/ingest.ts
9
- var _zod = require('zod');
10
- var MAX_TRACK_PAYLOAD_BYTES = 512e3;
11
- var zClientEventMetadata = {
12
- /**
13
- * Client-generated UUID. This is the project-scoped idempotency key stored as
14
- * `RawEvent.clientEventId`; the server uses a separate globally unique raw
15
- * event id internally. Re-sending the same eventId to the same project is
16
- * always safe and always reported as a duplicate.
17
- */
18
- eventId: _zod.z.uuid(),
19
- /** Event time, epoch milliseconds. */
20
- timestamp: _zod.z.number().int().nonnegative(),
21
- /**
22
- * The browser device this event belongs to, for events a server records
23
- * on a visitor's behalf (a form submission, an order). Lets one server
24
- * batch carry events from many visitors — a forwarder cannot split its
25
- * batches per device without breaking its failure model and its
26
- * `accepted + duplicates + rejected === sent` invariant.
27
- *
28
- * Honoured in `server` mode only, where it takes precedence over the
29
- * `reopt-device-id` request header. Ignored in `browser` mode: there the
30
- * header is authoritative and a body field would be trivially forged.
31
- * Same character set as every identity id.
32
- */
33
- deviceId: _zod.z.string().regex(_chunkL3JPDRVGcjs.IDENTITY_ID_PATTERN, "expected an identity id").optional()
34
- };
35
- var zTrackPayload = _zod.z.object({
36
- name: _zod.z.string().min(1).max(200),
37
- properties: _zod.z.record(_zod.z.string(), _zod.z.unknown()).optional(),
38
- profileId: _zod.z.string().max(500).or(_zod.z.number()).optional()
39
- }).refine((data) => !_chunk3EEANNYNcjs.RESERVED_EVENT_NAMES.includes(data.name), {
40
- message: `Event name cannot be one of the reserved names: ${_chunk3EEANNYNcjs.RESERVED_EVENT_NAMES.join(", ")}`,
41
- path: ["name"]
42
- });
43
- var zIdentifyPayload = _zod.z.object({
44
- profileId: _zod.z.string().min(1).max(500).or(_zod.z.number()),
45
- firstName: _zod.z.string().max(200).optional(),
46
- lastName: _zod.z.string().max(200).optional(),
47
- email: _zod.z.email().max(320).optional(),
48
- avatar: _zod.z.url().max(2e3).optional(),
49
- properties: _zod.z.record(_zod.z.string(), _zod.z.unknown()).optional()
50
- });
51
- var zIncrementPayload = _zod.z.object({
52
- profileId: _zod.z.string().min(1).max(500).or(_zod.z.number()),
53
- property: _zod.z.string().min(1).max(200),
54
- value: _zod.z.number().positive().optional()
55
- });
56
- var zDecrementPayload = _zod.z.object({
57
- profileId: _zod.z.string().min(1).max(500).or(_zod.z.number()),
58
- property: _zod.z.string().min(1).max(200),
59
- value: _zod.z.number().positive().optional()
60
- });
61
- var zTrackHandlerPayload = _zod.z.discriminatedUnion("type", [
62
- _zod.z.object({ type: _zod.z.literal("track"), payload: zTrackPayload, ...zClientEventMetadata }),
63
- _zod.z.object({ type: _zod.z.literal("identify"), payload: zIdentifyPayload, ...zClientEventMetadata }),
64
- _zod.z.object({ type: _zod.z.literal("increment"), payload: zIncrementPayload, ...zClientEventMetadata }),
65
- _zod.z.object({ type: _zod.z.literal("decrement"), payload: zDecrementPayload, ...zClientEventMetadata })
66
- ]);
67
- var INGEST_MODES = ["browser", "server"];
68
- var zIngestMode = _zod.z.enum(INGEST_MODES);
69
- var INGEST_REJECTION_REASONS = [
70
- /** Failed the zod schema (bad eventId, missing name, wrong types…). */
71
- "validation_failed",
72
- /** Used one of RESERVED_EVENT_NAMES. */
73
- "reserved_name",
74
- /** Another row earlier in the same batch already claimed this eventId. */
75
- "duplicate_in_batch"
76
- ];
77
- var zIngestRejectionReason = _zod.z.enum(INGEST_REJECTION_REASONS);
78
- var zIngestRejection = _zod.z.object({
79
- /** May be absent or malformed on `validation_failed` — hence `string`, not `uuid`. */
80
- eventId: _zod.z.string(),
81
- /** Position in the submitted batch. The only reliable identifier when eventId itself is bad. */
82
- index: _zod.z.number().int().nonnegative(),
83
- reason: zIngestRejectionReason,
84
- message: _zod.z.string().optional()
85
- });
86
- var ingestCounts = {
87
- /** Raw events newly persisted by this request. */
88
- accepted: _zod.z.number().int().nonnegative(),
89
- /**
90
- * Events the server already had. In `server` mode this is exactly the
91
- * eventId-idempotency count; in `browser` mode it also includes the
92
- * 5-second click dedup.
93
- */
94
- duplicates: _zod.z.number().int().nonnegative(),
95
- /** Always `[]` in `browser` mode, where a bad row fails the whole batch. */
96
- rejected: _zod.z.array(zIngestRejection)
97
- };
98
- var zSessionCredential = _zod.z.object({
99
- id: _zod.z.string().regex(_chunkL3JPDRVGcjs.IDENTITY_ID_PATTERN),
100
- token: _zod.z.string().regex(/^[A-Za-z0-9_-]{43}$/)
101
- });
102
- var zIngestOkResponse = _zod.z.object({
103
- status: _zod.z.literal("ok"),
104
- requestId: _zod.z.string(),
105
- mode: zIngestMode,
106
- ...ingestCounts,
107
- queued: _zod.z.boolean(),
108
- session: zSessionCredential.optional()
109
- });
110
- var zIngestAcceptedResponse = _zod.z.object({
111
- status: _zod.z.literal("accepted"),
112
- requestId: _zod.z.string(),
113
- mode: zIngestMode,
114
- ...ingestCounts,
115
- backgroundQueued: _zod.z.literal(false),
116
- replay: _zod.z.literal("unmaterialized-raw-events"),
117
- session: zSessionCredential.optional()
118
- });
119
- var zIngestResponse = _zod.z.discriminatedUnion("status", [zIngestOkResponse, zIngestAcceptedResponse]);
120
- function reconcileIngestResponse(response, sentCount) {
121
- return response.accepted + response.duplicates + response.rejected.length === sentCount;
122
- }
123
- var INGEST_ERROR_CODES = [
124
- /** 401 — unknown or mismatched credentials. Stop and alert; do not retry. */
125
- "unauthorized",
126
- /** 400 — body was not valid JSON. */
127
- "invalid_json",
128
- /** 400 — request exceeded MAX_TRACK_PAYLOAD_BYTES. Split the batch. */
129
- "payload_too_large",
130
- /** 400 — zero events submitted. */
131
- "empty_batch",
132
- /** 400 — batch contained a `type: "alias"` event, which is not supported. */
133
- "alias_unsupported",
134
- /** 400 — the project has no organization; it cannot be billed or quota-checked. */
135
- "project_without_organization",
136
- /** 400 — `browser` mode only: a row failed validation. `server` mode reports these in `rejected[]`. */
137
- "validation_failed",
138
- /** 429 — per-project request rate limit. `Retry-After` set. Pause this tick, keep the cursor. */
139
- "rate_limited",
140
- /** 429 — the organization's monthly event quota is exhausted. `Retry-After` set (capped at 1h). Alert: a human must raise the limit. */
141
- "quota_exceeded",
142
- /** 410 — the project is being deleted. Permanent; stop sending. */
143
- "project_purging",
144
- /** 500 — unexpected server failure. Back off and retry. */
145
- "internal_error"
146
- ];
147
- var zIngestErrorCode = _zod.z.enum(INGEST_ERROR_CODES);
148
- var zIngestError = _zod.z.object({
149
- status: _zod.z.number().int(),
150
- code: zIngestErrorCode,
151
- error: _zod.z.string(),
152
- message: _zod.z.string().optional(),
153
- /** zod issues, when `code === "validation_failed"`. */
154
- errors: _zod.z.unknown().optional(),
155
- requestId: _zod.z.string().optional()
156
- });
157
-
158
-
159
-
160
-
161
-
162
-
163
-
164
-
165
-
166
-
167
-
168
-
169
-
170
-
171
-
172
-
173
-
174
-
175
-
176
-
177
-
178
- exports.MAX_TRACK_PAYLOAD_BYTES = MAX_TRACK_PAYLOAD_BYTES; exports.zTrackPayload = zTrackPayload; exports.zIdentifyPayload = zIdentifyPayload; exports.zIncrementPayload = zIncrementPayload; exports.zDecrementPayload = zDecrementPayload; exports.zTrackHandlerPayload = zTrackHandlerPayload; exports.INGEST_MODES = INGEST_MODES; exports.zIngestMode = zIngestMode; exports.INGEST_REJECTION_REASONS = INGEST_REJECTION_REASONS; exports.zIngestRejectionReason = zIngestRejectionReason; exports.zIngestRejection = zIngestRejection; exports.zSessionCredential = zSessionCredential; exports.zIngestOkResponse = zIngestOkResponse; exports.zIngestAcceptedResponse = zIngestAcceptedResponse; exports.zIngestResponse = zIngestResponse; exports.reconcileIngestResponse = reconcileIngestResponse; exports.INGEST_ERROR_CODES = INGEST_ERROR_CODES; exports.zIngestErrorCode = zIngestErrorCode; exports.zIngestError = zIngestError;
179
- //# sourceMappingURL=chunk-ZI6A3WQP.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["/Users/eric/reopt-ai/reopt-data/packages/data-contract/dist/chunk-ZI6A3WQP.cjs","../src/ingest.ts"],"names":[],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACA;ACIA,0BAAkB;AAgBX,IAAM,wBA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AAEyC;AACW,EAAA;AAChB,EAAA;AACG,EAAA;AACvC;AAEyC;AACW,EAAA;AAChB,EAAA;AACG,EAAA;AACvC;AAEgE;AACuB,EAAA;AACM,EAAA;AACpB,EAAA;AACA,EAAA;AACzE;AAqB+C;AACF;AAUN;AAAA;AAEtC,EAAA;AAAA;AAEA,EAAA;AAAA;AAEA,EAAA;AACF;AACqE;AAG5B;AAAA;AAErB,EAAA;AAAA;AAEkB,EAAA;AAC5B,EAAA;AACqB,EAAA;AAC9B;AAGoB;AAAA;AAEoB,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAME,EAAA;AAAA;AAEP,EAAA;AACpC;AAQ2C;AACD,EAAA;AACK,EAAA;AAC9C;AAIyC;AAClB,EAAA;AACF,EAAA;AACd,EAAA;AACH,EAAA;AACe,EAAA;AACmB,EAAA;AACtC;AAQ+C;AAClB,EAAA;AACR,EAAA;AACd,EAAA;AACH,EAAA;AAC8B,EAAA;AACY,EAAA;AACR,EAAA;AACtC;AAEiF;AAcY;AACd,EAAA;AAChF;AAQkC;AAAA;AAEhC,EAAA;AAAA;AAEA,EAAA;AAAA;AAEA,EAAA;AAAA;AAEA,EAAA;AAAA;AAEA,EAAA;AAAA;AAEA,EAAA;AAAA;AAEA,EAAA;AAAA;AAEA,EAAA;AAAA;AAEA,EAAA;AAAA;AAEA,EAAA;AAAA;AAEA,EAAA;AACF;AACyD;AAGpB;AACZ,EAAA;AACjB,EAAA;AACU,EAAA;AACa,EAAA;AAAA;AAEA,EAAA;AACE,EAAA;AAChC;ADlG6F;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/Users/eric/reopt-ai/reopt-data/packages/data-contract/dist/chunk-ZI6A3WQP.cjs","sourcesContent":[null,"/**\n * `POST /api/track` — the ingest contract.\n *\n * The request shape is shared by both credential modes. The *response* shape\n * is where server-ingest differs: it reports per-event rejections instead of\n * failing a whole batch, because a forwarder that stalls on one malformed row\n * stops forwarding forever.\n *\n * Absorbed from the former internal `@reopt/ingest-contract`; that package is\n * now a deprecated re-export of this module.\n */\nimport { z } from \"zod\";\nimport { IDENTITY_ID_PATTERN } from \"./identity.js\";\n\nexport {\n AUTO_EVENT_NAMES,\n AUTO_EVENT_PROPERTIES,\n AUTO_EVENT_ROLLUP_KEYS,\n RESERVED_EVENT_NAMES,\n SCROLL_DEPTH_BUCKETS,\n scrollDepthBucket,\n type AutoEventName,\n type ScrollDepthBucket,\n} from \"./events.js\";\nimport { RESERVED_EVENT_NAMES } from \"./events.js\";\n\n/** Hard cap enforced by the route before the body is even parsed. */\nexport const MAX_TRACK_PAYLOAD_BYTES = 512_000;\n\nconst zClientEventMetadata = {\n /**\n * Client-generated UUID. This is the project-scoped idempotency key stored as\n * `RawEvent.clientEventId`; the server uses a separate globally unique raw\n * event id internally. Re-sending the same eventId to the same project is\n * always safe and always reported as a duplicate.\n */\n eventId: z.uuid(),\n /** Event time, epoch milliseconds. */\n timestamp: z.number().int().nonnegative(),\n /**\n * The browser device this event belongs to, for events a server records\n * on a visitor's behalf (a form submission, an order). Lets one server\n * batch carry events from many visitors — a forwarder cannot split its\n * batches per device without breaking its failure model and its\n * `accepted + duplicates + rejected === sent` invariant.\n *\n * Honoured in `server` mode only, where it takes precedence over the\n * `reopt-device-id` request header. Ignored in `browser` mode: there the\n * header is authoritative and a body field would be trivially forged.\n * Same character set as every identity id.\n */\n deviceId: z.string().regex(IDENTITY_ID_PATTERN, \"expected an identity id\").optional(),\n};\n\nexport const zTrackPayload = z\n .object({\n name: z.string().min(1).max(200),\n properties: z.record(z.string(), z.unknown()).optional(),\n profileId: z.string().max(500).or(z.number()).optional(),\n })\n .refine((data) => !RESERVED_EVENT_NAMES.includes(data.name as never), {\n message: `Event name cannot be one of the reserved names: ${RESERVED_EVENT_NAMES.join(\", \")}`,\n path: [\"name\"],\n });\n\nexport const zIdentifyPayload = z.object({\n profileId: z.string().min(1).max(500).or(z.number()),\n firstName: z.string().max(200).optional(),\n lastName: z.string().max(200).optional(),\n email: z.email().max(320).optional(),\n avatar: z.url().max(2000).optional(),\n properties: z.record(z.string(), z.unknown()).optional(),\n});\n\nexport const zIncrementPayload = z.object({\n profileId: z.string().min(1).max(500).or(z.number()),\n property: z.string().min(1).max(200),\n value: z.number().positive().optional(),\n});\n\nexport const zDecrementPayload = z.object({\n profileId: z.string().min(1).max(500).or(z.number()),\n property: z.string().min(1).max(200),\n value: z.number().positive().optional(),\n});\n\nexport const zTrackHandlerPayload = z.discriminatedUnion(\"type\", [\n z.object({ type: z.literal(\"track\"), payload: zTrackPayload, ...zClientEventMetadata }),\n z.object({ type: z.literal(\"identify\"), payload: zIdentifyPayload, ...zClientEventMetadata }),\n z.object({ type: z.literal(\"increment\"), payload: zIncrementPayload, ...zClientEventMetadata }),\n z.object({ type: z.literal(\"decrement\"), payload: zDecrementPayload, ...zClientEventMetadata }),\n]);\n\nexport type ITrackPayload = z.infer<typeof zTrackPayload>;\nexport type IIdentifyPayload = z.infer<typeof zIdentifyPayload>;\nexport type IIncrementPayload = z.infer<typeof zIncrementPayload>;\nexport type IDecrementPayload = z.infer<typeof zDecrementPayload>;\nexport type ITrackHandlerPayload = z.infer<typeof zTrackHandlerPayload>;\n\n// ─── Ingest mode ────────────────────────────────────────────────────────────\n\n/**\n * Decided by the credential presented, never by a header the caller sets:\n * `reopt-write-key` alone → `browser`, `reopt-client-id` + `reopt-client-secret`\n * → `server`. A separate mode header could disagree with the credential; this\n * cannot.\n *\n * `browser` keeps the 5-second click dedup and device-scoped sessions.\n * `server` drops both and relies solely on `eventId` idempotency — a server\n * batch legitimately contains the same event name many times within one second,\n * and its \"device\" is a process, not a person.\n */\nexport const INGEST_MODES = [\"browser\", \"server\"] as const;\nexport const zIngestMode = z.enum(INGEST_MODES);\nexport type IngestMode = z.infer<typeof zIngestMode>;\n\n// ─── Response ───────────────────────────────────────────────────────────────\n\n/**\n * Why a single event in a batch was dropped. These are permanent: re-sending\n * the same row produces the same rejection, so a forwarder should count it as\n * skipped and advance its cursor rather than retry.\n */\nexport const INGEST_REJECTION_REASONS = [\n /** Failed the zod schema (bad eventId, missing name, wrong types…). */\n \"validation_failed\",\n /** Used one of RESERVED_EVENT_NAMES. */\n \"reserved_name\",\n /** Another row earlier in the same batch already claimed this eventId. */\n \"duplicate_in_batch\",\n] as const;\nexport const zIngestRejectionReason = z.enum(INGEST_REJECTION_REASONS);\nexport type IngestRejectionReason = z.infer<typeof zIngestRejectionReason>;\n\nexport const zIngestRejection = z.object({\n /** May be absent or malformed on `validation_failed` — hence `string`, not `uuid`. */\n eventId: z.string(),\n /** Position in the submitted batch. The only reliable identifier when eventId itself is bad. */\n index: z.number().int().nonnegative(),\n reason: zIngestRejectionReason,\n message: z.string().optional(),\n});\nexport type IngestRejection = z.infer<typeof zIngestRejection>;\n\nconst ingestCounts = {\n /** Raw events newly persisted by this request. */\n accepted: z.number().int().nonnegative(),\n /**\n * Events the server already had. In `server` mode this is exactly the\n * eventId-idempotency count; in `browser` mode it also includes the\n * 5-second click dedup.\n */\n duplicates: z.number().int().nonnegative(),\n /** Always `[]` in `browser` mode, where a bad row fails the whole batch. */\n rejected: z.array(zIngestRejection),\n};\n\n/**\n * The session ingest filed this batch under, with the token that lets the\n * browser (or a server acting for it) join the same session later with\n * authority — see `signSessionToken` in `./identity`. Browser mode only;\n * absent when the batch carried no sessionable event.\n */\nexport const zSessionCredential = z.object({\n id: z.string().regex(IDENTITY_ID_PATTERN),\n token: z.string().regex(/^[A-Za-z0-9_-]{43}$/),\n});\nexport type SessionCredential = z.infer<typeof zSessionCredential>;\n\n/** 200 — accepted and handed to the materialize queue. */\nexport const zIngestOkResponse = z.object({\n status: z.literal(\"ok\"),\n requestId: z.string(),\n mode: zIngestMode,\n ...ingestCounts,\n queued: z.boolean(),\n session: zSessionCredential.optional(),\n});\n\n/**\n * 202 — raw events landed, but enqueueing the materialize task failed. No data\n * is lost: the `replay-unmaterialized` cron picks these up. A forwarder should\n * treat this as success and advance its cursor. Carries the same counts as 200\n * so the reconciliation below works here too.\n */\nexport const zIngestAcceptedResponse = z.object({\n status: z.literal(\"accepted\"),\n requestId: z.string(),\n mode: zIngestMode,\n ...ingestCounts,\n backgroundQueued: z.literal(false),\n replay: z.literal(\"unmaterialized-raw-events\"),\n session: zSessionCredential.optional(),\n});\n\nexport const zIngestResponse = z.discriminatedUnion(\"status\", [zIngestOkResponse, zIngestAcceptedResponse]);\n\nexport type IngestOkResponse = z.infer<typeof zIngestOkResponse>;\nexport type IngestAcceptedResponse = z.infer<typeof zIngestAcceptedResponse>;\nexport type IngestResponse = z.infer<typeof zIngestResponse>;\n\n/**\n * The reconciliation a forwarder runs on every 2xx:\n *\n * accepted + duplicates + rejected.length === events sent\n *\n * A mismatch means the server silently dropped something, which is exactly the\n * failure mode this contract exists to make impossible to miss.\n */\nexport function reconcileIngestResponse(response: IngestResponse, sentCount: number): boolean {\n return response.accepted + response.duplicates + response.rejected.length === sentCount;\n}\n\n// ─── Errors ─────────────────────────────────────────────────────────────────\n\n/**\n * Stable machine-readable codes. Branch on these, never on `error`/`message`,\n * which are prose and may be reworded.\n */\nexport const INGEST_ERROR_CODES = [\n /** 401 — unknown or mismatched credentials. Stop and alert; do not retry. */\n \"unauthorized\",\n /** 400 — body was not valid JSON. */\n \"invalid_json\",\n /** 400 — request exceeded MAX_TRACK_PAYLOAD_BYTES. Split the batch. */\n \"payload_too_large\",\n /** 400 — zero events submitted. */\n \"empty_batch\",\n /** 400 — batch contained a `type: \"alias\"` event, which is not supported. */\n \"alias_unsupported\",\n /** 400 — the project has no organization; it cannot be billed or quota-checked. */\n \"project_without_organization\",\n /** 400 — `browser` mode only: a row failed validation. `server` mode reports these in `rejected[]`. */\n \"validation_failed\",\n /** 429 — per-project request rate limit. `Retry-After` set. Pause this tick, keep the cursor. */\n \"rate_limited\",\n /** 429 — the organization's monthly event quota is exhausted. `Retry-After` set (capped at 1h). Alert: a human must raise the limit. */\n \"quota_exceeded\",\n /** 410 — the project is being deleted. Permanent; stop sending. */\n \"project_purging\",\n /** 500 — unexpected server failure. Back off and retry. */\n \"internal_error\",\n] as const;\nexport const zIngestErrorCode = z.enum(INGEST_ERROR_CODES);\nexport type IngestErrorCode = z.infer<typeof zIngestErrorCode>;\n\nexport const zIngestError = z.object({\n status: z.number().int(),\n code: zIngestErrorCode,\n error: z.string(),\n message: z.string().optional(),\n /** zod issues, when `code === \"validation_failed\"`. */\n errors: z.unknown().optional(),\n requestId: z.string().optional(),\n});\nexport type IngestError = z.infer<typeof zIngestError>;\n"]}