@vertesia/common 1.5.0-dev.20260725.083715Z → 1.5.0-dev.20260804.124748Z

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 (521) hide show
  1. package/lib/access-control-values.d.ts +98 -0
  2. package/lib/access-control-values.d.ts.map +1 -0
  3. package/lib/access-control-values.js +101 -0
  4. package/lib/access-control-values.js.map +1 -0
  5. package/lib/access-control.d.ts +22 -119
  6. package/lib/access-control.d.ts.map +1 -1
  7. package/lib/access-control.js +6 -78
  8. package/lib/access-control.js.map +1 -1
  9. package/lib/account-values.d.ts +53 -0
  10. package/lib/account-values.d.ts.map +1 -0
  11. package/lib/account-values.js +91 -0
  12. package/lib/account-values.js.map +1 -0
  13. package/lib/analytics.d.ts +12 -38
  14. package/lib/analytics.d.ts.map +1 -1
  15. package/lib/api-schemas/access-control.d.ts +215 -0
  16. package/lib/api-schemas/access-control.d.ts.map +1 -0
  17. package/lib/api-schemas/access-control.js +165 -0
  18. package/lib/api-schemas/access-control.js.map +1 -0
  19. package/lib/api-schemas/account.d.ts +101 -0
  20. package/lib/api-schemas/account.d.ts.map +1 -0
  21. package/lib/api-schemas/account.js +136 -0
  22. package/lib/api-schemas/account.js.map +1 -0
  23. package/lib/api-schemas/adapter.d.ts +80 -0
  24. package/lib/api-schemas/adapter.d.ts.map +1 -0
  25. package/lib/api-schemas/adapter.js +726 -0
  26. package/lib/api-schemas/adapter.js.map +1 -0
  27. package/lib/api-schemas/agent-runs.d.ts +3781 -0
  28. package/lib/api-schemas/agent-runs.d.ts.map +1 -0
  29. package/lib/api-schemas/agent-runs.js +991 -0
  30. package/lib/api-schemas/agent-runs.js.map +1 -0
  31. package/lib/api-schemas/analytics.d.ts +86 -0
  32. package/lib/api-schemas/analytics.d.ts.map +1 -0
  33. package/lib/api-schemas/analytics.js +58 -0
  34. package/lib/api-schemas/analytics.js.map +1 -0
  35. package/lib/api-schemas/apikey.d.ts +231 -0
  36. package/lib/api-schemas/apikey.d.ts.map +1 -0
  37. package/lib/api-schemas/apikey.js +172 -0
  38. package/lib/api-schemas/apikey.js.map +1 -0
  39. package/lib/api-schemas/app-lifecycle.d.ts +1114 -0
  40. package/lib/api-schemas/app-lifecycle.d.ts.map +1 -0
  41. package/lib/api-schemas/app-lifecycle.js +750 -0
  42. package/lib/api-schemas/app-lifecycle.js.map +1 -0
  43. package/lib/api-schemas/app-runtime.d.ts +9056 -0
  44. package/lib/api-schemas/app-runtime.d.ts.map +1 -0
  45. package/lib/api-schemas/app-runtime.js +782 -0
  46. package/lib/api-schemas/app-runtime.js.map +1 -0
  47. package/lib/api-schemas/apps.d.ts +247 -0
  48. package/lib/api-schemas/apps.d.ts.map +1 -0
  49. package/lib/api-schemas/apps.js +366 -0
  50. package/lib/api-schemas/apps.js.map +1 -0
  51. package/lib/api-schemas/audit-trail.d.ts +465 -0
  52. package/lib/api-schemas/audit-trail.d.ts.map +1 -0
  53. package/lib/api-schemas/audit-trail.js +218 -0
  54. package/lib/api-schemas/audit-trail.js.map +1 -0
  55. package/lib/api-schemas/bulk-operation.d.ts +104 -0
  56. package/lib/api-schemas/bulk-operation.d.ts.map +1 -0
  57. package/lib/api-schemas/bulk-operation.js +66 -0
  58. package/lib/api-schemas/bulk-operation.js.map +1 -0
  59. package/lib/api-schemas/commands.d.ts +50 -0
  60. package/lib/api-schemas/commands.d.ts.map +1 -0
  61. package/lib/api-schemas/commands.js +58 -0
  62. package/lib/api-schemas/commands.js.map +1 -0
  63. package/lib/api-schemas/content.d.ts +3561 -0
  64. package/lib/api-schemas/content.d.ts.map +1 -0
  65. package/lib/api-schemas/content.js +842 -0
  66. package/lib/api-schemas/content.js.map +1 -0
  67. package/lib/api-schemas/cost-analytics.d.ts +300 -0
  68. package/lib/api-schemas/cost-analytics.d.ts.map +1 -0
  69. package/lib/api-schemas/cost-analytics.js +218 -0
  70. package/lib/api-schemas/cost-analytics.js.map +1 -0
  71. package/lib/api-schemas/dashboard.d.ts +408 -0
  72. package/lib/api-schemas/dashboard.d.ts.map +1 -0
  73. package/lib/api-schemas/dashboard.js +311 -0
  74. package/lib/api-schemas/dashboard.js.map +1 -0
  75. package/lib/api-schemas/data-store.d.ts +1650 -0
  76. package/lib/api-schemas/data-store.d.ts.map +1 -0
  77. package/lib/api-schemas/data-store.js +504 -0
  78. package/lib/api-schemas/data-store.js.map +1 -0
  79. package/lib/api-schemas/document-processing.d.ts +1501 -0
  80. package/lib/api-schemas/document-processing.d.ts.map +1 -0
  81. package/lib/api-schemas/document-processing.js +312 -0
  82. package/lib/api-schemas/document-processing.js.map +1 -0
  83. package/lib/api-schemas/embeddings.d.ts +184 -0
  84. package/lib/api-schemas/embeddings.d.ts.map +1 -0
  85. package/lib/api-schemas/embeddings.js +102 -0
  86. package/lib/api-schemas/embeddings.js.map +1 -0
  87. package/lib/api-schemas/environment.d.ts +412 -0
  88. package/lib/api-schemas/environment.d.ts.map +1 -0
  89. package/lib/api-schemas/environment.js +170 -0
  90. package/lib/api-schemas/environment.js.map +1 -0
  91. package/lib/api-schemas/events.d.ts +4880 -0
  92. package/lib/api-schemas/events.d.ts.map +1 -0
  93. package/lib/api-schemas/events.js +832 -0
  94. package/lib/api-schemas/events.js.map +1 -0
  95. package/lib/api-schemas/files.d.ts +107 -0
  96. package/lib/api-schemas/files.d.ts.map +1 -0
  97. package/lib/api-schemas/files.js +137 -0
  98. package/lib/api-schemas/files.js.map +1 -0
  99. package/lib/api-schemas/group.d.ts +122 -0
  100. package/lib/api-schemas/group.d.ts.map +1 -0
  101. package/lib/api-schemas/group.js +142 -0
  102. package/lib/api-schemas/group.js.map +1 -0
  103. package/lib/api-schemas/index.d.ts +36 -0
  104. package/lib/api-schemas/index.d.ts.map +1 -0
  105. package/lib/api-schemas/index.js +36 -0
  106. package/lib/api-schemas/index.js.map +1 -0
  107. package/lib/api-schemas/indexing.d.ts +144 -0
  108. package/lib/api-schemas/indexing.d.ts.map +1 -0
  109. package/lib/api-schemas/indexing.js +217 -0
  110. package/lib/api-schemas/indexing.js.map +1 -0
  111. package/lib/api-schemas/integrations.d.ts +269 -0
  112. package/lib/api-schemas/integrations.d.ts.map +1 -0
  113. package/lib/api-schemas/integrations.js +335 -0
  114. package/lib/api-schemas/integrations.js.map +1 -0
  115. package/lib/api-schemas/interaction.d.ts +22454 -0
  116. package/lib/api-schemas/interaction.d.ts.map +1 -0
  117. package/lib/api-schemas/interaction.js +2065 -0
  118. package/lib/api-schemas/interaction.js.map +1 -0
  119. package/lib/api-schemas/invites.d.ts +162 -0
  120. package/lib/api-schemas/invites.d.ts.map +1 -0
  121. package/lib/api-schemas/invites.js +106 -0
  122. package/lib/api-schemas/invites.js.map +1 -0
  123. package/lib/api-schemas/oauth-server.d.ts +415 -0
  124. package/lib/api-schemas/oauth-server.d.ts.map +1 -0
  125. package/lib/api-schemas/oauth-server.js +193 -0
  126. package/lib/api-schemas/oauth-server.js.map +1 -0
  127. package/lib/api-schemas/oauth.d.ts +150 -0
  128. package/lib/api-schemas/oauth.d.ts.map +1 -0
  129. package/lib/api-schemas/oauth.js +148 -0
  130. package/lib/api-schemas/oauth.js.map +1 -0
  131. package/lib/api-schemas/parameters.d.ts +64 -0
  132. package/lib/api-schemas/parameters.d.ts.map +1 -0
  133. package/lib/api-schemas/parameters.js +246 -0
  134. package/lib/api-schemas/parameters.js.map +1 -0
  135. package/lib/api-schemas/process.d.ts +499 -0
  136. package/lib/api-schemas/process.d.ts.map +1 -0
  137. package/lib/api-schemas/process.js +817 -0
  138. package/lib/api-schemas/process.js.map +1 -0
  139. package/lib/api-schemas/project-configuration.d.ts +4900 -0
  140. package/lib/api-schemas/project-configuration.d.ts.map +1 -0
  141. package/lib/api-schemas/project-configuration.js +425 -0
  142. package/lib/api-schemas/project-configuration.js.map +1 -0
  143. package/lib/api-schemas/project.d.ts +7247 -0
  144. package/lib/api-schemas/project.d.ts.map +1 -0
  145. package/lib/api-schemas/project.js +185 -0
  146. package/lib/api-schemas/project.js.map +1 -0
  147. package/lib/api-schemas/prompt.d.ts +70 -0
  148. package/lib/api-schemas/prompt.d.ts.map +1 -0
  149. package/lib/api-schemas/prompt.js +77 -0
  150. package/lib/api-schemas/prompt.js.map +1 -0
  151. package/lib/api-schemas/quota.d.ts +90 -0
  152. package/lib/api-schemas/quota.d.ts.map +1 -0
  153. package/lib/api-schemas/quota.js +95 -0
  154. package/lib/api-schemas/quota.js.map +1 -0
  155. package/lib/api-schemas/registry.d.ts +97458 -0
  156. package/lib/api-schemas/registry.d.ts.map +1 -0
  157. package/lib/api-schemas/registry.js +2586 -0
  158. package/lib/api-schemas/registry.js.map +1 -0
  159. package/lib/api-schemas/schema-primitives.d.ts +5 -0
  160. package/lib/api-schemas/schema-primitives.d.ts.map +1 -0
  161. package/lib/api-schemas/schema-primitives.js +11 -0
  162. package/lib/api-schemas/schema-primitives.js.map +1 -0
  163. package/lib/api-schemas/secrets.d.ts +497 -0
  164. package/lib/api-schemas/secrets.d.ts.map +1 -0
  165. package/lib/api-schemas/secrets.js +298 -0
  166. package/lib/api-schemas/secrets.js.map +1 -0
  167. package/lib/api-schemas/store.d.ts +22140 -0
  168. package/lib/api-schemas/store.d.ts.map +1 -0
  169. package/lib/api-schemas/store.js +557 -0
  170. package/lib/api-schemas/store.js.map +1 -0
  171. package/lib/api-schemas/sts.d.ts +156 -0
  172. package/lib/api-schemas/sts.d.ts.map +1 -0
  173. package/lib/api-schemas/sts.js +96 -0
  174. package/lib/api-schemas/sts.js.map +1 -0
  175. package/lib/api-schemas/task.d.ts +215 -0
  176. package/lib/api-schemas/task.d.ts.map +1 -0
  177. package/lib/api-schemas/task.js +95 -0
  178. package/lib/api-schemas/task.js.map +1 -0
  179. package/lib/api-schemas/tools.d.ts +111 -0
  180. package/lib/api-schemas/tools.d.ts.map +1 -0
  181. package/lib/api-schemas/tools.js +122 -0
  182. package/lib/api-schemas/tools.js.map +1 -0
  183. package/lib/api-schemas/user.d.ts +208 -0
  184. package/lib/api-schemas/user.d.ts.map +1 -0
  185. package/lib/api-schemas/user.js +180 -0
  186. package/lib/api-schemas/user.js.map +1 -0
  187. package/lib/api-schemas/view-execution.d.ts +3163 -0
  188. package/lib/api-schemas/view-execution.d.ts.map +1 -0
  189. package/lib/api-schemas/view-execution.js +172 -0
  190. package/lib/api-schemas/view-execution.js.map +1 -0
  191. package/lib/api-schemas/views.d.ts +5990 -0
  192. package/lib/api-schemas/views.d.ts.map +1 -0
  193. package/lib/api-schemas/views.js +396 -0
  194. package/lib/api-schemas/views.js.map +1 -0
  195. package/lib/api-schemas/workflow-runs.d.ts +2209 -0
  196. package/lib/api-schemas/workflow-runs.d.ts.map +1 -0
  197. package/lib/api-schemas/workflow-runs.js +589 -0
  198. package/lib/api-schemas/workflow-runs.js.map +1 -0
  199. package/lib/apikey-values.d.ts +10 -0
  200. package/lib/apikey-values.d.ts.map +1 -0
  201. package/lib/apikey-values.js +11 -0
  202. package/lib/apikey-values.js.map +1 -0
  203. package/lib/apikey.d.ts +37 -36
  204. package/lib/apikey.d.ts.map +1 -1
  205. package/lib/apikey.js +5 -4
  206. package/lib/apikey.js.map +1 -1
  207. package/lib/apps.d.ts +107 -1151
  208. package/lib/apps.d.ts.map +1 -1
  209. package/lib/apps.js.map +1 -1
  210. package/lib/ask-user.d.ts +8 -1
  211. package/lib/ask-user.d.ts.map +1 -1
  212. package/lib/audit-trail.d.ts +17 -128
  213. package/lib/audit-trail.d.ts.map +1 -1
  214. package/lib/audit-trail.js.map +1 -1
  215. package/lib/browser-credentials.d.ts +11 -106
  216. package/lib/browser-credentials.d.ts.map +1 -1
  217. package/lib/common.d.ts +59 -81
  218. package/lib/common.d.ts.map +1 -1
  219. package/lib/cost-analytics.d.ts +14 -167
  220. package/lib/cost-analytics.d.ts.map +1 -1
  221. package/lib/cost-analytics.js.map +1 -1
  222. package/lib/data-platform.d.ts +122 -786
  223. package/lib/data-platform.d.ts.map +1 -1
  224. package/lib/data-platform.js +41 -61
  225. package/lib/data-platform.js.map +1 -1
  226. package/lib/email.d.ts +5 -17
  227. package/lib/email.d.ts.map +1 -1
  228. package/lib/email.js +0 -3
  229. package/lib/email.js.map +1 -1
  230. package/lib/embeddings.d.ts +14 -56
  231. package/lib/embeddings.d.ts.map +1 -1
  232. package/lib/environment.d.ts +19 -115
  233. package/lib/environment.d.ts.map +1 -1
  234. package/lib/environment.js +3 -0
  235. package/lib/environment.js.map +1 -1
  236. package/lib/facets.d.ts +4 -7
  237. package/lib/facets.d.ts.map +1 -1
  238. package/lib/group.d.ts +33 -39
  239. package/lib/group.d.ts.map +1 -1
  240. package/lib/group.js +0 -1
  241. package/lib/group.js.map +1 -1
  242. package/lib/index.d.ts +7 -0
  243. package/lib/index.d.ts.map +1 -1
  244. package/lib/index.js.map +1 -1
  245. package/lib/integrations.d.ts +20 -108
  246. package/lib/integrations.d.ts.map +1 -1
  247. package/lib/integrations.js.map +1 -1
  248. package/lib/interaction-values.d.ts +11 -0
  249. package/lib/interaction-values.d.ts.map +1 -0
  250. package/lib/interaction-values.js +24 -0
  251. package/lib/interaction-values.js.map +1 -0
  252. package/lib/interaction.d.ts +88 -778
  253. package/lib/interaction.d.ts.map +1 -1
  254. package/lib/interaction.js +8 -12
  255. package/lib/interaction.js.map +1 -1
  256. package/lib/meters.d.ts +11 -7
  257. package/lib/meters.d.ts.map +1 -1
  258. package/lib/meters.js.map +1 -1
  259. package/lib/oauth-server.d.ts +33 -119
  260. package/lib/oauth-server.d.ts.map +1 -1
  261. package/lib/oauth.d.ts +14 -96
  262. package/lib/oauth.d.ts.map +1 -1
  263. package/lib/oauth.js +0 -4
  264. package/lib/oauth.js.map +1 -1
  265. package/lib/payload.d.ts +15 -38
  266. package/lib/payload.d.ts.map +1 -1
  267. package/lib/platform-event.d.ts +49 -462
  268. package/lib/platform-event.d.ts.map +1 -1
  269. package/lib/platform-event.js.map +1 -1
  270. package/lib/principal-context.d.ts +10 -15
  271. package/lib/principal-context.d.ts.map +1 -1
  272. package/lib/project-values.d.ts +24 -0
  273. package/lib/project-values.d.ts.map +1 -0
  274. package/lib/project-values.js +42 -0
  275. package/lib/project-values.js.map +1 -0
  276. package/lib/project.d.ts +55 -503
  277. package/lib/project.d.ts.map +1 -1
  278. package/lib/project.js +6 -76
  279. package/lib/project.js.map +1 -1
  280. package/lib/prompt.d.ts +20 -51
  281. package/lib/prompt.d.ts.map +1 -1
  282. package/lib/prompt.js.map +1 -1
  283. package/lib/query.d.ts +27 -88
  284. package/lib/query.d.ts.map +1 -1
  285. package/lib/rate-limiter.d.ts +19 -70
  286. package/lib/rate-limiter.d.ts.map +1 -1
  287. package/lib/rate-limiter.js +0 -3
  288. package/lib/rate-limiter.js.map +1 -1
  289. package/lib/refs.d.ts +3 -11
  290. package/lib/refs.d.ts.map +1 -1
  291. package/lib/refs.js.map +1 -1
  292. package/lib/roles/types.d.ts +14 -20
  293. package/lib/roles/types.d.ts.map +1 -1
  294. package/lib/roles/types.js +5 -9
  295. package/lib/roles/types.js.map +1 -1
  296. package/lib/runs.d.ts +6 -25
  297. package/lib/runs.d.ts.map +1 -1
  298. package/lib/secrets.d.ts +20 -105
  299. package/lib/secrets.d.ts.map +1 -1
  300. package/lib/store/agent-approval.d.ts +5 -14
  301. package/lib/store/agent-approval.d.ts.map +1 -1
  302. package/lib/store/agent-approval.js.map +1 -1
  303. package/lib/store/agent-run.d.ts +57 -358
  304. package/lib/store/agent-run.d.ts.map +1 -1
  305. package/lib/store/collections.d.ts +11 -63
  306. package/lib/store/collections.d.ts.map +1 -1
  307. package/lib/store/collections.js.map +1 -1
  308. package/lib/store/conversation-state.d.ts +61 -61
  309. package/lib/store/conversation-state.d.ts.map +1 -1
  310. package/lib/store/conversation-state.js +2 -0
  311. package/lib/store/conversation-state.js.map +1 -1
  312. package/lib/store/doc-analyzer.d.ts +9 -32
  313. package/lib/store/doc-analyzer.d.ts.map +1 -1
  314. package/lib/store/dsl-workflow.d.ts +37 -151
  315. package/lib/store/dsl-workflow.d.ts.map +1 -1
  316. package/lib/store/dsl-workflow.js.map +1 -1
  317. package/lib/store/editing-policy-schema.generated.d.ts +3 -0
  318. package/lib/store/editing-policy-schema.generated.d.ts.map +1 -0
  319. package/lib/store/editing-policy-schema.generated.js +28 -0
  320. package/lib/store/editing-policy-schema.generated.js.map +1 -0
  321. package/lib/store/grounded-extraction.d.ts +7 -104
  322. package/lib/store/grounded-extraction.d.ts.map +1 -1
  323. package/lib/store/grounded-extraction.js.map +1 -1
  324. package/lib/store/index.d.ts +2 -0
  325. package/lib/store/index.d.ts.map +1 -1
  326. package/lib/store/index.js +3 -0
  327. package/lib/store/index.js.map +1 -1
  328. package/lib/store/intake-policy-schema.generated.d.ts +3 -0
  329. package/lib/store/intake-policy-schema.generated.d.ts.map +1 -0
  330. package/lib/store/intake-policy-schema.generated.js +1425 -0
  331. package/lib/store/intake-policy-schema.generated.js.map +1 -0
  332. package/lib/store/process-schema.d.ts +80 -0
  333. package/lib/store/process-schema.d.ts.map +1 -1
  334. package/lib/store/process-schema.js +79 -0
  335. package/lib/store/process-schema.js.map +1 -1
  336. package/lib/store/process-validation.d.ts.map +1 -1
  337. package/lib/store/process-validation.js +70 -2
  338. package/lib/store/process-validation.js.map +1 -1
  339. package/lib/store/process.d.ts +36 -125
  340. package/lib/store/process.d.ts.map +1 -1
  341. package/lib/store/process.js.map +1 -1
  342. package/lib/store/rendering.d.ts +9 -64
  343. package/lib/store/rendering.d.ts.map +1 -1
  344. package/lib/store/rendering.js.map +1 -1
  345. package/lib/store/store.d.ts +98 -700
  346. package/lib/store/store.d.ts.map +1 -1
  347. package/lib/store/store.js +4 -456
  348. package/lib/store/store.js.map +1 -1
  349. package/lib/store/task.d.ts +15 -59
  350. package/lib/store/task.d.ts.map +1 -1
  351. package/lib/store/task.js +0 -3
  352. package/lib/store/task.js.map +1 -1
  353. package/lib/store/workflow.d.ts +54 -518
  354. package/lib/store/workflow.d.ts.map +1 -1
  355. package/lib/store/workflow.js +23 -11
  356. package/lib/store/workflow.js.map +1 -1
  357. package/lib/sts-token-types.d.ts +12 -66
  358. package/lib/sts-token-types.d.ts.map +1 -1
  359. package/lib/sts-token-types.js.map +1 -1
  360. package/lib/tools.d.ts +8 -100
  361. package/lib/tools.d.ts.map +1 -1
  362. package/lib/transient-tokens-values.d.ts +11 -0
  363. package/lib/transient-tokens-values.d.ts.map +1 -0
  364. package/lib/transient-tokens-values.js +12 -0
  365. package/lib/transient-tokens-values.js.map +1 -0
  366. package/lib/transient-tokens.d.ts +15 -13
  367. package/lib/transient-tokens.d.ts.map +1 -1
  368. package/lib/transient-tokens.js +5 -5
  369. package/lib/transient-tokens.js.map +1 -1
  370. package/lib/user.d.ts +54 -155
  371. package/lib/user.d.ts.map +1 -1
  372. package/lib/user.js +1 -78
  373. package/lib/user.js.map +1 -1
  374. package/lib/versions.d.ts +24 -1
  375. package/lib/versions.d.ts.map +1 -1
  376. package/lib/versions.js +23 -0
  377. package/lib/versions.js.map +1 -1
  378. package/lib/vertesia-common.js +6 -2
  379. package/lib/vertesia-common.js.map +1 -1
  380. package/lib/views-schema.d.ts +4 -4
  381. package/lib/views.d.ts +56 -312
  382. package/lib/views.d.ts.map +1 -1
  383. package/lib/views.js.map +1 -1
  384. package/package.json +13 -4
  385. package/src/access-control-values.ts +113 -0
  386. package/src/access-control.ts +33 -138
  387. package/src/account-values.ts +95 -0
  388. package/src/analytics.ts +18 -42
  389. package/src/api-schemas/access-control.contract.test.ts +209 -0
  390. package/src/api-schemas/access-control.ts +208 -0
  391. package/src/api-schemas/account.contract.test.ts +318 -0
  392. package/src/api-schemas/account.ts +150 -0
  393. package/src/api-schemas/adapter-edge-cases.test.ts +480 -0
  394. package/src/api-schemas/adapter.ts +778 -0
  395. package/src/api-schemas/agent-runs.ts +1081 -0
  396. package/src/api-schemas/analytics.ts +65 -0
  397. package/src/api-schemas/apikey.contract.test.ts +270 -0
  398. package/src/api-schemas/apikey.ts +199 -0
  399. package/src/api-schemas/app-lifecycle.ts +841 -0
  400. package/src/api-schemas/app-runtime.ts +919 -0
  401. package/src/api-schemas/apps.ts +415 -0
  402. package/src/api-schemas/audit-trail.ts +243 -0
  403. package/src/api-schemas/bulk-operation.contract.test.ts +39 -0
  404. package/src/api-schemas/bulk-operation.ts +75 -0
  405. package/src/api-schemas/bundle-isolation.test.ts +80 -0
  406. package/src/api-schemas/commands.contract.test.ts +51 -0
  407. package/src/api-schemas/commands.ts +62 -0
  408. package/src/api-schemas/content.ts +939 -0
  409. package/src/api-schemas/cost-analytics.contract.test.ts +64 -0
  410. package/src/api-schemas/cost-analytics.ts +235 -0
  411. package/src/api-schemas/dashboard.contract.test.ts +127 -0
  412. package/src/api-schemas/dashboard.ts +351 -0
  413. package/src/api-schemas/data-store.contract.test.ts +91 -0
  414. package/src/api-schemas/data-store.ts +571 -0
  415. package/src/api-schemas/document-processing.contract.test.ts +76 -0
  416. package/src/api-schemas/document-processing.ts +344 -0
  417. package/src/api-schemas/embeddings.ts +113 -0
  418. package/src/api-schemas/environment.contract.test.ts +184 -0
  419. package/src/api-schemas/environment.ts +190 -0
  420. package/src/api-schemas/events.ts +921 -0
  421. package/src/api-schemas/files.ts +159 -0
  422. package/src/api-schemas/group.contract.test.ts +205 -0
  423. package/src/api-schemas/group.ts +155 -0
  424. package/src/api-schemas/index.ts +35 -0
  425. package/src/api-schemas/indexing.contract.test.ts +83 -0
  426. package/src/api-schemas/indexing.ts +234 -0
  427. package/src/api-schemas/integrations.ts +369 -0
  428. package/src/api-schemas/interaction.ts +2357 -0
  429. package/src/api-schemas/invites.contract.test.ts +268 -0
  430. package/src/api-schemas/invites.ts +127 -0
  431. package/src/api-schemas/llumiverse.contract.test.ts +108 -0
  432. package/src/api-schemas/oauth-server.ts +219 -0
  433. package/src/api-schemas/oauth.contract.test.ts +118 -0
  434. package/src/api-schemas/oauth.ts +166 -0
  435. package/src/api-schemas/parameters.test.ts +402 -0
  436. package/src/api-schemas/parameters.ts +310 -0
  437. package/src/api-schemas/process.ts +929 -0
  438. package/src/api-schemas/project-configuration.ts +478 -0
  439. package/src/api-schemas/project.contract.test.ts +365 -0
  440. package/src/api-schemas/project.ts +214 -0
  441. package/src/api-schemas/prompt.ts +88 -0
  442. package/src/api-schemas/pruning-limits.test.ts +189 -0
  443. package/src/api-schemas/quota.contract.test.ts +147 -0
  444. package/src/api-schemas/quota.ts +122 -0
  445. package/src/api-schemas/registry-groups.test.ts +91 -0
  446. package/src/api-schemas/registry.ts +3487 -0
  447. package/src/api-schemas/response-pruning.test.ts +260 -0
  448. package/src/api-schemas/schema-primitives.ts +12 -0
  449. package/src/api-schemas/secrets.ts +332 -0
  450. package/src/api-schemas/store.contract.test.ts +450 -0
  451. package/src/api-schemas/store.ts +604 -0
  452. package/src/api-schemas/sts.contract.test.ts +80 -0
  453. package/src/api-schemas/sts.ts +110 -0
  454. package/src/api-schemas/task.ts +104 -0
  455. package/src/api-schemas/tools.ts +140 -0
  456. package/src/api-schemas/user.contract.test.ts +191 -0
  457. package/src/api-schemas/user.ts +204 -0
  458. package/src/api-schemas/view-execution.ts +200 -0
  459. package/src/api-schemas/views.ts +437 -0
  460. package/src/api-schemas/workflow-runs.ts +653 -0
  461. package/src/apikey-values.ts +10 -0
  462. package/src/apikey.ts +49 -40
  463. package/src/apps.ts +234 -1213
  464. package/src/ask-user.ts +9 -1
  465. package/src/audit-trail.ts +45 -137
  466. package/src/browser-credentials.ts +21 -106
  467. package/src/common.ts +67 -78
  468. package/src/cost-analytics.ts +37 -176
  469. package/src/data-platform.ts +205 -776
  470. package/src/email.ts +5 -17
  471. package/src/embeddings.ts +22 -60
  472. package/src/environment.ts +52 -126
  473. package/src/facets.ts +4 -7
  474. package/src/group.ts +38 -42
  475. package/src/index.ts +11 -0
  476. package/src/integrations.ts +39 -129
  477. package/src/interaction-values.ts +23 -0
  478. package/src/interaction.ts +162 -902
  479. package/src/meters.ts +11 -7
  480. package/src/oauth-server.ts +58 -127
  481. package/src/oauth.ts +24 -108
  482. package/src/payload.ts +25 -40
  483. package/src/platform-event.ts +98 -484
  484. package/src/principal-context.ts +11 -15
  485. package/src/project-values.ts +41 -0
  486. package/src/project.ts +116 -588
  487. package/src/prompt.ts +34 -61
  488. package/src/query.ts +34 -93
  489. package/src/rate-limiter.ts +27 -75
  490. package/src/refs.ts +4 -11
  491. package/src/roles/types.ts +20 -20
  492. package/src/runs.ts +11 -24
  493. package/src/secrets.ts +38 -117
  494. package/src/store/agent-approval.ts +9 -14
  495. package/src/store/agent-run.ts +93 -450
  496. package/src/store/collections.ts +21 -63
  497. package/src/store/content-type-editing.test.ts +1 -1
  498. package/src/store/conversation-state.ts +75 -64
  499. package/src/store/doc-analyzer.ts +17 -33
  500. package/src/store/dsl-workflow.ts +62 -158
  501. package/src/store/editing-policy-schema.generated.ts +30 -0
  502. package/src/store/grounded-extraction.ts +13 -104
  503. package/src/store/index.ts +3 -0
  504. package/src/store/intake-policy-schema.generated.ts +1442 -0
  505. package/src/store/process-schema.test.ts +43 -0
  506. package/src/store/process-schema.ts +79 -0
  507. package/src/store/process-validation.test.ts +141 -0
  508. package/src/store/process-validation.ts +82 -2
  509. package/src/store/process.ts +70 -146
  510. package/src/store/rendering.ts +15 -64
  511. package/src/store/store.ts +197 -1204
  512. package/src/store/task.ts +25 -59
  513. package/src/store/workflow.ts +97 -557
  514. package/src/sts-token-types.ts +24 -75
  515. package/src/tools.ts +18 -97
  516. package/src/transient-tokens-values.ts +11 -0
  517. package/src/transient-tokens.ts +16 -13
  518. package/src/user.ts +74 -214
  519. package/src/versions.ts +24 -0
  520. package/src/views-schema.test.ts +9 -1
  521. package/src/views.ts +106 -329
@@ -0,0 +1,65 @@
1
+ import { z } from 'zod';
2
+
3
+ /**
4
+ * The run-analytics query and its result rows.
5
+ *
6
+ * `POST /environments/:envId/analytics` and `POST /analytics` take the same body, so the components
7
+ * are shared rather than duplicated per resource.
8
+ */
9
+
10
+ export const TimeResolutionSchema = z
11
+ .enum(['minute', 'hour', 'day', 'week', 'month', 'year'])
12
+ .meta({ id: 'TimeResolution' });
13
+
14
+ export const RunAnalyticsGroupBySchema = z
15
+ .enum(['interaction', 'modelId', 'project', 'status', 'tags', 'environment'])
16
+ .meta({ id: 'RunAnalyticsGroupBy' });
17
+
18
+ export const AnalyticsAxisSchema = z
19
+ .strictObject({
20
+ environment: z.string().optional(),
21
+ project: z.string().optional(),
22
+ interactions: z.array(z.string()).optional(),
23
+ models: z.array(z.string()).optional(),
24
+ status: z.array(z.string()).optional(),
25
+ tags: z.array(z.string()).optional(),
26
+ selectedOnly: z.boolean().optional(),
27
+ })
28
+ .meta({ id: 'AnalyticsAxis' });
29
+
30
+ export const RunAnalyticsQuerySchema = z
31
+ .strictObject({
32
+ filterBy: AnalyticsAxisSchema.meta({ description: 'filters to apply to the query' }),
33
+ groupBy: RunAnalyticsGroupBySchema.meta({ description: 'The field to group by' }).optional(),
34
+ from: z.number().meta({ description: 'The start date of the query in EPOCH format' }).optional(),
35
+ to: z.number().meta({ description: 'The end date of the query in EPOCH format' }).optional(),
36
+ resolution: TimeResolutionSchema.meta({
37
+ description: 'The time resolution unit of the analytics query',
38
+ }).optional(),
39
+ resolutionStep: z
40
+ .number()
41
+ .meta({
42
+ description:
43
+ "The step size for the resolution (e.g., 4 with resolution='hour' means 4-hour " +
44
+ 'intervals). Defaults to 1.',
45
+ })
46
+ .optional(),
47
+ virtual: z.boolean().meta({ description: 'The field to sort by' }).optional(),
48
+ })
49
+ .meta({ id: 'RunAnalyticsQuery' });
50
+
51
+ export const RunAnalyticsResultSchema = z
52
+ .strictObject({
53
+ date: z.string(),
54
+ timestamp: z.string(),
55
+ group: z.string(),
56
+ count: z.number(),
57
+ execution_time: z.strictObject({
58
+ avg: z.number(),
59
+ min: z.number(),
60
+ max: z.number(),
61
+ }),
62
+ })
63
+ .meta({ id: 'RunAnalyticsResult' });
64
+
65
+ export const RunAnalyticsResultArraySchema = z.array(RunAnalyticsResultSchema).meta({ id: 'RunAnalyticsResultArray' });
@@ -0,0 +1,270 @@
1
+ import { Ajv2020 } from 'ajv/dist/2020.js';
2
+ import { describe, expect, it } from 'vitest';
3
+ import {
4
+ type ApiKey,
5
+ type ApiKeyArray,
6
+ type ApiKeyReadResponse,
7
+ ApiKeyTypes,
8
+ type ApiKeyWithValue,
9
+ type CreateApiKeyPayload,
10
+ type UpdateApiKeyPayload,
11
+ } from '../apikey.js';
12
+ import { type ProjectRef, SystemRoles } from '../project.js';
13
+ import type { JsonObject } from './adapter.js';
14
+ import type { ProjectRefArrayFromSchema } from './apikey.js';
15
+ import { ApiSchemaComponents, apiComponentRef, validateApiRequest, validateApiResponse } from './registry.js';
16
+
17
+ /** Exact type identity — `extends` in both directions is too weak (any/unknown slip through). */
18
+ type Equals<A, B> = (<T>() => T extends A ? 1 : 2) extends <T>() => T extends B ? 1 : 2 ? true : false;
19
+ function assertType<T extends true>(_ok: T): void {}
20
+
21
+ function compile(name: string) {
22
+ const ajv = new Ajv2020({ strictSchema: false, allErrors: true });
23
+ ajv.addSchema({ $id: 'vertesia://openapi', components: { schemas: ApiSchemaComponents } });
24
+ return ajv.compile({ $ref: `vertesia://openapi${apiComponentRef(name as never)}` });
25
+ }
26
+
27
+ const VALID_PROJECT_REF = {
28
+ id: '69d4762f24d3048c99149d0b',
29
+ name: 'Research',
30
+ account: '68b1779130afe5403a1589ba',
31
+ };
32
+
33
+ const VALID_KEY = {
34
+ id: '68b1779130afe5403a1589bc',
35
+ name: 'CI',
36
+ type: ApiKeyTypes.secret,
37
+ role: SystemRoles.developer,
38
+ account: '68b1779130afe5403a1589ba',
39
+ project: VALID_PROJECT_REF,
40
+ enabled: true,
41
+ created_by: 'ada@acme.test',
42
+ updated_by: 'ada@acme.test',
43
+ created_at: '2026-01-01T00:00:00.000Z',
44
+ updated_at: '2026-01-02T00:00:00.000Z',
45
+ };
46
+
47
+ describe('gate 1 — the schema is the single source of truth for the public API key types', () => {
48
+ it('publishes the exact schema-derived type, not a hand-written twin', () => {
49
+ assertType<Equals<ApiKeyArray, ApiKey[]>>(true);
50
+ assertType<Equals<ProjectRefArrayFromSchema, ProjectRef[]>>(true);
51
+ expect(true).toBe(true);
52
+ });
53
+
54
+ it('types the timestamps as strings, which is what the document always published', () => {
55
+ // The hand-written `ApiKey` said `Date` for all three. JSON has no date type and the
56
+ // component has always declared `format: date-time`, so the old declaration described the
57
+ // Mongoose document, not the response — the same correction `User` and `UserGroup` needed.
58
+ assertType<Equals<ApiKey['created_at'], string>>(true);
59
+ assertType<Equals<ApiKey['updated_at'], string>>(true);
60
+ assertType<Equals<ApiKey['expires_at'], string | undefined>>(true);
61
+ expect(true).toBe(true);
62
+ });
63
+
64
+ it('keeps the secret off the base type and derives the two shapes that carry it', () => {
65
+ // `value` is absent from `ApiKey` entirely, so a handler cannot leak a secret by returning
66
+ // the wrong shape — it has to name a component that declares one.
67
+ assertType<Equals<Extract<keyof ApiKey, 'value'>, never>>(true);
68
+ // Creation always returns the secret; the single-key read returns it only when asked for it
69
+ // AND permitted, which is why the two cannot share a component.
70
+ assertType<Equals<ApiKeyWithValue['value'], string>>(true);
71
+ assertType<Equals<ApiKeyReadResponse['value'], string | undefined>>(true);
72
+ // Everything else is inherited rather than restated.
73
+ assertType<Equals<ApiKeyWithValue['project'], ApiKey['project']>>(true);
74
+ assertType<Equals<ApiKeyReadResponse['role'], ApiKey['role']>>(true);
75
+ expect(true).toBe(true);
76
+ });
77
+
78
+ it('gives create and update the different payloads the two operations actually have', () => {
79
+ // Both pick from `ApiKeySchema`, so a field's type and documentation keep one home; what
80
+ // differs is requiredness and which fields are writable at all — the only two things a write
81
+ // payload legitimately changes about a field it shares.
82
+ // Compared against `ApiKey`, not against the enums directly: the claim is that the payloads
83
+ // are PICKED from the key, so the identity that matters is with the field they came from.
84
+ assertType<Equals<CreateApiKeyPayload['name'], ApiKey['name']>>(true);
85
+ assertType<Equals<CreateApiKeyPayload['role'], ApiKey['role']>>(true);
86
+ assertType<Equals<CreateApiKeyPayload['type'], ApiKey['type'] | undefined>>(true);
87
+ assertType<Equals<CreateApiKeyPayload['expires_at'], ApiKey['expires_at']>>(true);
88
+ assertType<Equals<UpdateApiKeyPayload['name'], ApiKey['name'] | undefined>>(true);
89
+ assertType<Equals<UpdateApiKeyPayload['role'], ApiKey['role'] | undefined>>(true);
90
+ assertType<Equals<UpdateApiKeyPayload['enabled'], ApiKey['enabled'] | undefined>>(true);
91
+ // `name` and `role` are required on create and optional on update — the only difference a
92
+ // write payload legitimately introduces.
93
+ assertType<Equals<CreateApiKeyPayload['name'], string>>(true);
94
+ assertType<Equals<UpdateApiKeyPayload['name'], string | undefined>>(true);
95
+
96
+ // What the picks leave out is the whitelist, and it is now an explicit list rather than a
97
+ // consequence of `Partial<ApiKey>`: the server-owned fields are unreachable from either.
98
+ assertType<Equals<Extract<keyof CreateApiKeyPayload, 'id' | 'account' | 'maskedValue'>, never>>(true);
99
+ assertType<Equals<Extract<keyof CreateApiKeyPayload, 'created_at' | 'enabled' | 'project'>, never>>(true);
100
+ // `type` and `expires_at` are immutable after creation, so update cannot name them.
101
+ assertType<Equals<Extract<keyof UpdateApiKeyPayload, 'type' | 'expires_at'>, never>>(true);
102
+ expect(true).toBe(true);
103
+ });
104
+ });
105
+
106
+ describe('gate 2 — the published components match the closure the types come from', () => {
107
+ it('publishes the single-member key type as a const, not a one-member enum', () => {
108
+ // Both validate identically; only one is byte-identical to what the TypeScript scanner
109
+ // emitted, and slots that have not converted still derive this component — the generator
110
+ // fails the build if the two definitions disagree.
111
+ expect(ApiSchemaComponents.ApiKeyTypes).toEqual({ type: 'string', const: 'sk' });
112
+ });
113
+
114
+ it('keeps ProjectRef and SystemRoles as shared components rather than inlining them', () => {
115
+ const props = ApiSchemaComponents.ApiKey.properties as Record<string, JsonObject>;
116
+ expect(props.project).toEqual({ $ref: '#/components/schemas/ProjectRef' });
117
+ expect(props.role).toEqual({ $ref: '#/components/schemas/SystemRoles' });
118
+ expect(props.type).toEqual({ $ref: '#/components/schemas/ApiKeyTypes' });
119
+ expect(ApiSchemaComponents.SystemRoles.enum).toContain('content_superadmin');
120
+ });
121
+
122
+ it('tightens the API key timestamps to date-time, unlike the ACE ones', () => {
123
+ // Safe here in a way it was not for an access control entry: every one of these is written
124
+ // by the server. `expires_at` too — it is computed from a TTL, never copied out of a payload.
125
+ const props = ApiSchemaComponents.ApiKey.properties as Record<string, JsonObject>;
126
+ expect(props.created_at).toEqual({ type: 'string', format: 'date-time' });
127
+ expect(props.updated_at).toEqual({ type: 'string', format: 'date-time' });
128
+ expect(props.expires_at).toEqual({ type: 'string', format: 'date-time' });
129
+ });
130
+
131
+ it('does not declare value on the base component', () => {
132
+ expect(Object.keys(ApiSchemaComponents.ApiKey.properties as JsonObject)).not.toContain('value');
133
+ expect(ApiSchemaComponents.ApiKey.additionalProperties).toBe(false);
134
+ expect((ApiSchemaComponents.ApiKeyWithValue.required as string[]) ?? []).toContain('value');
135
+ expect((ApiSchemaComponents.ApiKeyReadResponse.required as string[]) ?? []).not.toContain('value');
136
+ });
137
+
138
+ it('publishes ProjectRef closed, with the documentation the list endpoints rely on', () => {
139
+ const props = ApiSchemaComponents.ProjectRef.properties as Record<string, JsonObject>;
140
+ expect(ApiSchemaComponents.ProjectRef.additionalProperties).toBe(false);
141
+ expect(props.restricted.description).toContain('org admin or owner');
142
+ expect(ApiSchemaComponents.ProjectRef.required).toEqual(['id', 'name', 'account']);
143
+ });
144
+ });
145
+
146
+ describe('gate 3 — AJV validates the same canonical objects that are published', () => {
147
+ it('accepts a minimal key and rejects a missing required field', () => {
148
+ const validate = compile('ApiKey');
149
+ expect(validate(VALID_KEY)).toBe(true);
150
+ const { project: _dropped, ...incomplete } = VALID_KEY;
151
+ expect(validate(incomplete)).toBe(false);
152
+ });
153
+
154
+ it('rejects a base key response that carries a secret', () => {
155
+ // The point of splitting the components: a handler that returns the wrong one is caught at
156
+ // the boundary rather than shipping the secret.
157
+ expect(compile('ApiKey')({ ...VALID_KEY, value: 'sk-live-abcdef' })).toBe(false);
158
+ expect(compile('ApiKeyWithValue')({ ...VALID_KEY, value: 'sk-live-abcdef' })).toBe(true);
159
+ expect(compile('ApiKeyReadResponse')({ ...VALID_KEY, value: 'sk-live-abcdef' })).toBe(true);
160
+ expect(compile('ApiKeyReadResponse')(VALID_KEY)).toBe(true);
161
+ // ...and one that omits it where it is promised.
162
+ expect(compile('ApiKeyWithValue')(VALID_KEY)).toBe(false);
163
+ });
164
+
165
+ it('rejects a Date where the contract declares a date-time string', () => {
166
+ // What `jsonDoc()` produced before `toApiKeyResponse` existed: `toJSON()` leaves `Date`
167
+ // objects in place, and only `JSON.stringify` converts them — after the enforcer has run.
168
+ // A `Date` fails on `type: string` alone, so this holds with or without format assertion.
169
+ expect(compile('ApiKey')({ ...VALID_KEY, created_at: new Date('2026-01-01T00:00:00.000Z') })).toBe(false);
170
+ });
171
+
172
+ it('enforces the date-time format through the registry validator, which is what registers formats', () => {
173
+ // The local `compile()` above deliberately does NOT add ajv-formats — it exists to check the
174
+ // published SHAPE. `format` is only asserted by the production validator, so a malformed
175
+ // timestamp has to be checked there or the assertion would pass vacuously.
176
+ expect(validateApiResponse('ApiKey', { ...VALID_KEY, created_at: 'last tuesday' }).valid).toBe(false);
177
+ expect(validateApiResponse('ApiKey', VALID_KEY).valid).toBe(true);
178
+ });
179
+
180
+ it('rejects the internal fields a serialized document would have leaked', () => {
181
+ const validate = compile('ApiKey');
182
+ expect(validate({ ...VALID_KEY, _id: 'deadbeef' })).toBe(false);
183
+ expect(validate({ ...VALID_KEY, hashed_value: 'deadbeef' })).toBe(false);
184
+ });
185
+
186
+ it('constrains the key type and the role to their catalogs', () => {
187
+ const validate = compile('ApiKey');
188
+ expect(validate({ ...VALID_KEY, type: 'pk' })).toBe(false);
189
+ expect(validate({ ...VALID_KEY, role: 'superuser' })).toBe(false);
190
+ expect(validate({ ...VALID_KEY, role: SystemRoles.content_superadmin })).toBe(true);
191
+ });
192
+
193
+ it('requires name and role on a create, which the handler needed and the payload never said', () => {
194
+ const validate = compile('CreateApiKeyPayload');
195
+ expect(validate({ name: 'CI', role: SystemRoles.reader })).toBe(true);
196
+ expect(validate({ name: 'CI', role: SystemRoles.reader, type: 'sk', expires_at: '2030-01-01T00:00:00Z' })).toBe(
197
+ true,
198
+ );
199
+ // `role` is `required: true` on the Mongoose schema: this used to be accepted here and fail
200
+ // inside `ApiKeyModel.create`, which the endpoint reported as a 500.
201
+ expect(validate({ name: 'CI' })).toBe(false);
202
+ // `name` is required by the published `ApiKey` component, so a key created without one could
203
+ // not produce a conforming response.
204
+ expect(validate({ role: SystemRoles.reader })).toBe(false);
205
+ expect(validate({})).toBe(false);
206
+ // Server-owned fields are no longer declared, so sending one is now an error rather than
207
+ // silently ignored.
208
+ expect(validate({ name: 'CI', role: SystemRoles.reader, id: 'x' })).toBe(false);
209
+ expect(validate({ name: 'CI', role: SystemRoles.reader, enabled: true })).toBe(false);
210
+ expect(validate({ name: 'CI', role: SystemRoles.reader, project: VALID_PROJECT_REF })).toBe(false);
211
+ });
212
+
213
+ it('accepts a partial update and rejects the fields creation owns', () => {
214
+ const validate = compile('UpdateApiKeyPayload');
215
+ expect(validate({})).toBe(true);
216
+ expect(validate({ enabled: false })).toBe(true);
217
+ expect(validate({ name: 'CI', role: SystemRoles.reader, enabled: true })).toBe(true);
218
+ expect(validate({ role: 'superuser' })).toBe(false);
219
+ // Immutable after creation.
220
+ expect(validate({ type: 'sk' })).toBe(false);
221
+ expect(validate({ expires_at: '2030-01-01T00:00:00Z' })).toBe(false);
222
+ expect(validate({ rogue_field: 1 })).toBe(false);
223
+ });
224
+
225
+ it('validates the two query components the scanner expands into parameters', () => {
226
+ expect(compile('ApiKeyListQuery')({ level: 'project' })).toBe(true);
227
+ expect(compile('ApiKeyListQuery')({})).toBe(true);
228
+ expect(compile('ApiKeyListQuery')({ level: 'organization' })).toBe(false);
229
+ expect(compile('ApiKeyReadQuery')({ withValue: true })).toBe(true);
230
+ expect(compile('ApiKeyReadQuery')({ withValue: 'yes' })).toBe(false);
231
+ });
232
+ });
233
+
234
+ describe('gate 4 — runtime enforcement uses the published components', () => {
235
+ it('checks every member of a listing against the same key component', () => {
236
+ expect(validateApiResponse('ApiKeyArray', [VALID_KEY, VALID_KEY]).valid).toBe(true);
237
+ expect(validateApiResponse('ApiKeyArray', []).valid).toBe(true);
238
+ // One key in the listing still carrying its secret is exactly what the fail-closed boundary
239
+ // in `toApiKeyResponse` exists to make impossible.
240
+ expect(validateApiResponse('ApiKeyArray', [VALID_KEY, { ...VALID_KEY, value: 'sk-leak' }]).valid).toBe(false);
241
+ });
242
+
243
+ it('rejects an undeclared payload field without removing it', () => {
244
+ const payload: Record<string, unknown> = { name: 'CI', role: SystemRoles.reader, rogue_field: 42 };
245
+ const result = validateApiRequest('CreateApiKeyPayload', payload);
246
+ expect(result.valid).toBe(false);
247
+ expect(payload.rogue_field).toBe(42);
248
+ });
249
+
250
+ it('hands back the component type on the valid branch', () => {
251
+ const result = validateApiResponse('ApiKey', VALID_KEY);
252
+ expect(result.valid).toBe(true);
253
+ if (result.valid) {
254
+ assertType<Equals<typeof result.data, ApiKey>>(true);
255
+ }
256
+ });
257
+
258
+ it('checks the shared project listing against the ref component', () => {
259
+ expect(validateApiResponse('ProjectRefArray', [VALID_PROJECT_REF]).valid).toBe(true);
260
+ expect(validateApiResponse('ProjectRefArray', [{ ...VALID_PROJECT_REF, restricted: true }]).valid).toBe(true);
261
+ expect(validateApiResponse('ProjectRefArray', [{ id: 'p1', name: 'Research' }]).valid).toBe(false);
262
+ });
263
+
264
+ it('checks the two single-field responses the key endpoints publish', () => {
265
+ expect(validateApiResponse('AuthTokenResponse', { token: 'ey...' }).valid).toBe(true);
266
+ expect(validateApiResponse('AuthTokenResponse', { token: 'ey...', refresh: 'x' }).valid).toBe(false);
267
+ expect(validateApiResponse('DeleteOperationResult', { acknowledged: true, deletedCount: 1 }).valid).toBe(true);
268
+ expect(validateApiResponse('DeleteOperationResult', { acknowledged: true }).valid).toBe(false);
269
+ });
270
+ });
@@ -0,0 +1,199 @@
1
+ import { z } from 'zod';
2
+ // From the values modules, never from `../apikey.js` / `../project.js`: both derive their public
3
+ // types from the schemas below, so importing them here would invert the dependency.
4
+ import { ApiKeyTypes } from '../apikey-values.js';
5
+ import { SystemRoles } from '../project-values.js';
6
+ import { ProjectSchema } from './project.js';
7
+
8
+ /**
9
+ * Runtime API schemas for API key endpoints and their compact project reference.
10
+ */
11
+
12
+ export const ApiKeyListQuerySchema = z
13
+ .object({
14
+ /** Restricts the listing to keys scoped at the account or the project level. */
15
+ level: z.enum(['account', 'project']).optional(),
16
+ })
17
+ .meta({ id: 'ApiKeyListQuery' });
18
+
19
+ export const ApiKeyReadQuerySchema = z
20
+ .object({
21
+ withValue: z.boolean().optional(),
22
+ })
23
+ .meta({ id: 'ApiKeyReadQuery' });
24
+
25
+ /**
26
+ * `z.literal` rather than `z.enum`, because the enum has exactly one member and the document
27
+ * publishes it as `const: 'sk'`. A one-member `enum: ['sk']` would validate identically but change
28
+ * the generated contract.
29
+ */
30
+ export const ApiKeyTypesSchema = z.literal(ApiKeyTypes.secret).meta({ id: 'ApiKeyTypes' });
31
+
32
+ export const SystemRolesSchema = z.enum(SystemRoles).meta({ id: 'SystemRoles' });
33
+
34
+ /**
35
+ * The compact project shape embedded in other resources' responses.
36
+ *
37
+ * Kept as a documented bridge because its recursive consumers require the named public interface;
38
+ * `apikey.contract.test.ts` asserts exact parity with the project projection.
39
+ */
40
+ export const ProjectRefSchema = ProjectSchema.pick({ id: true, name: true, account: true })
41
+ .extend({
42
+ restricted: z
43
+ .boolean()
44
+ .optional()
45
+ .meta({
46
+ description:
47
+ 'Only set when fetching the list of projects visible to an user which is an org admin or owner. ' +
48
+ 'If present and true, it means that the project is not accessible to the user.(even if it visible ' +
49
+ 'in listing) If not present or false then the project is accessible to the user.',
50
+ }),
51
+ })
52
+ .meta({ id: 'ProjectRef' });
53
+
54
+ export const ProjectRefArraySchema = z.array(ProjectRefSchema).meta({ id: 'ProjectRefArray' });
55
+
56
+ /**
57
+ * The API key as it crosses the wire.
58
+ *
59
+ * `created_at`, `updated_at` and `expires_at` are `z.string()` while the public TypeScript type said
60
+ * `Date`. The document has always published `format: date-time`, and JSON has no date type, so the
61
+ * old declaration described the Mongoose document rather than the response — the same correction
62
+ * `UserGroup` needed.
63
+ *
64
+ * Enforcing that format on read is safe here in a way it was not for an ACE, but not for the reason
65
+ * an earlier draft of this comment gave: `expires_at` DOES originate in the caller's create payload.
66
+ * What makes it safe is that it is a `Date` on the Mongoose schema, so a value Mongoose cannot cast
67
+ * is rejected at write time and everything stored is a real date — and the response mapper renders
68
+ * it with `toISOString()` rather than echoing what the caller sent. The ACE's `expires_at` is a
69
+ * plain string all the way down, which is why tightening it there would have turned stored data into
70
+ * a 500 on read.
71
+ *
72
+ * `value` is deliberately absent. A key's secret is published only by the two components that
73
+ * declare it — {@link ApiKeyWithValueSchema} on creation and {@link ApiKeyReadResponseSchema} on an
74
+ * explicit `?withValue=true` read — so a handler cannot leak it by returning the wrong shape.
75
+ */
76
+ export const ApiKeySchema = z
77
+ .object({
78
+ id: z.string(),
79
+ name: z.string(),
80
+ type: ApiKeyTypesSchema,
81
+ role: SystemRolesSchema,
82
+ maskedValue: z.string().optional(),
83
+ can_retrieve_value: z.boolean().optional(),
84
+ account: z.string(),
85
+ project: ProjectRefSchema,
86
+ enabled: z.boolean(),
87
+ created_by: z.string(),
88
+ updated_by: z.string(),
89
+ created_at: z.string().meta({ format: 'date-time' }),
90
+ updated_at: z.string().meta({ format: 'date-time' }),
91
+ expires_at: z.string().meta({ format: 'date-time' }).optional(),
92
+ properties: z
93
+ .record(z.string(), z.unknown())
94
+ .meta({
95
+ description:
96
+ 'Custom properties for dynamic permission matching (PrincipalSet / $principal. conditions)',
97
+ })
98
+ .optional(),
99
+ clearance: z
100
+ .number()
101
+ .meta({ description: 'BLP clearance level — the maximum document sensitivity the key can access' })
102
+ .optional(),
103
+ compartments: z
104
+ .array(z.string())
105
+ .meta({ description: 'Compartments the key belongs to — restricts access to matching documents' })
106
+ .optional(),
107
+ })
108
+ .meta({ id: 'ApiKey' });
109
+
110
+ export const ApiKeyArraySchema = z.array(ApiKeySchema).meta({ id: 'ApiKeyArray' });
111
+
112
+ /** The creation response: the only time the secret is returned unconditionally. */
113
+ export const ApiKeyWithValueSchema = ApiKeySchema.extend({
114
+ value: z.string(),
115
+ }).meta({ id: 'ApiKeyWithValue' });
116
+
117
+ /**
118
+ * The single-key read. `value` is present only when the caller asked for it AND holds
119
+ * `api_key:secret_read`, so it is optional here where creation makes it required — which is exactly
120
+ * why the two cannot share one component.
121
+ */
122
+ export const ApiKeyReadResponseSchema = ApiKeySchema.extend({
123
+ value: z.string().optional(),
124
+ }).meta({ id: 'ApiKeyReadResponse' });
125
+
126
+ /**
127
+ * What `POST /apikeys` accepts.
128
+ *
129
+ * Create and update used to share one `CreateOrUpdateApiKeyPayload extends Partial<ApiKey>`, and
130
+ * translating that literally as `ApiKeySchema.partial()` reproduced a payload that could not
131
+ * describe either operation truthfully:
132
+ *
133
+ * - `role` is `required: true` on the Mongoose schema, so a create that omitted it reached
134
+ * `ApiKeyModel.create` with `role: undefined` and failed validation inside the handler. Requiring
135
+ * it here turns a 500 into the 400 it always was.
136
+ * - `name` is required by the published `ApiKey` component, so a key created without one could not
137
+ * produce a conforming response.
138
+ * - It declared every server-owned field — `id`, `account`, `maskedValue`, `can_retrieve_value`,
139
+ * the timestamps — all of which the handler has always ignored.
140
+ *
141
+ * `.pick()` rather than a fresh object, so the seven fields keep one declaration; `.partial()` on the
142
+ * two the server defaults (`type` falls back to `sk`, `expires_at` means "never"). Requiredness is
143
+ * the only thing a write payload legitimately changes about a field it shares.
144
+ */
145
+ export const CreateApiKeyPayloadSchema = ApiKeySchema.pick({
146
+ name: true,
147
+ role: true,
148
+ type: true,
149
+ expires_at: true,
150
+ properties: true,
151
+ clearance: true,
152
+ compartments: true,
153
+ })
154
+ .partial({ type: true, expires_at: true })
155
+ .meta({ id: 'CreateApiKeyPayload' });
156
+
157
+ /**
158
+ * What `PUT /apikeys/:keyId` accepts: the six fields the handler applies, each optional.
159
+ *
160
+ * Narrower than the create payload in both directions — `type` and `expires_at` are immutable after
161
+ * creation, `enabled` is only settable here — which is precisely why one shared component could not
162
+ * be right for both. The handler now applies only the properties actually present; it used to assign
163
+ * `payload.name`, `payload.role` and `payload.enabled` unconditionally, so omitting `role` in a
164
+ * partial update unset a required path and made `save()` throw.
165
+ */
166
+ export const UpdateApiKeyPayloadSchema = ApiKeySchema.pick({
167
+ name: true,
168
+ role: true,
169
+ enabled: true,
170
+ properties: true,
171
+ clearance: true,
172
+ compartments: true,
173
+ })
174
+ .partial()
175
+ .meta({ id: 'UpdateApiKeyPayload' });
176
+
177
+ export const AuthTokenResponseSchema = z.object({ token: z.string() }).meta({ id: 'AuthTokenResponse' });
178
+
179
+ /**
180
+ * The raw Mongo delete acknowledgement, published as-is — `deletedCount` is `number` rather than
181
+ * `integer` because that is the public contract.
182
+ */
183
+ export const DeleteOperationResultSchema = z
184
+ .object({
185
+ acknowledged: z.boolean(),
186
+ deletedCount: z.number(),
187
+ })
188
+ .meta({ id: 'DeleteOperationResult' });
189
+
190
+ export type ApiKeyListQueryFromSchema = z.infer<typeof ApiKeyListQuerySchema>;
191
+ export type ApiKeyReadQueryFromSchema = z.infer<typeof ApiKeyReadQuerySchema>;
192
+ export type ProjectRefArrayFromSchema = z.infer<typeof ProjectRefArraySchema>;
193
+ export type ApiKeyFromSchema = z.infer<typeof ApiKeySchema>;
194
+ export type ApiKeyArrayFromSchema = z.infer<typeof ApiKeyArraySchema>;
195
+ export type ApiKeyWithValueFromSchema = z.infer<typeof ApiKeyWithValueSchema>;
196
+ export type ApiKeyReadResponseFromSchema = z.infer<typeof ApiKeyReadResponseSchema>;
197
+ export type CreateApiKeyPayloadFromSchema = z.infer<typeof CreateApiKeyPayloadSchema>;
198
+ export type UpdateApiKeyPayloadFromSchema = z.infer<typeof UpdateApiKeyPayloadSchema>;
199
+ export type AuthTokenResponseFromSchema = z.infer<typeof AuthTokenResponseSchema>;