@jini-ai/core 0.7.2 → 0.7.3-next.2

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 (343) hide show
  1. package/README.md +40 -12
  2. package/dist/admin-runtime/admin-api-error.d.ts +68 -0
  3. package/dist/admin-runtime/admin-api-error.js +72 -0
  4. package/dist/admin-runtime/admin-config-error.d.ts +8 -0
  5. package/dist/admin-runtime/admin-config-error.js +11 -0
  6. package/dist/admin-runtime/controller-store.d.ts +20 -0
  7. package/dist/admin-runtime/controller-store.js +32 -0
  8. package/dist/admin-runtime/index.d.ts +13 -0
  9. package/dist/admin-runtime/index.js +12 -0
  10. package/dist/admin-runtime/panel-access.d.ts +88 -0
  11. package/dist/admin-runtime/panel-access.js +76 -0
  12. package/dist/admin-runtime/query-suffix.d.ts +5 -0
  13. package/dist/admin-runtime/query-suffix.js +5 -0
  14. package/dist/agent-handles/element-handles.d.ts +134 -0
  15. package/dist/agent-handles/element-handles.js +45 -0
  16. package/dist/agent-handles/field-descriptor.d.ts +28 -0
  17. package/dist/agent-handles/field-descriptor.js +3 -0
  18. package/dist/agent-handles/handle.d.ts +109 -0
  19. package/dist/agent-handles/handle.js +109 -0
  20. package/dist/agent-handles/index.d.ts +9 -0
  21. package/dist/agent-handles/index.js +6 -0
  22. package/dist/agent-handles/list-handles.d.ts +46 -0
  23. package/dist/agent-handles/list-handles.js +67 -0
  24. package/dist/agent-handles/secret-attrs.d.ts +14 -0
  25. package/dist/agent-handles/secret-attrs.js +13 -0
  26. package/dist/approval-batch-chain.d.ts +45 -0
  27. package/dist/approval-batch-chain.js +75 -0
  28. package/dist/approval.d.ts +33 -14
  29. package/dist/approval.js +57 -43
  30. package/dist/batch-tool-inputs.js +24 -20
  31. package/dist/contracts/admin-module.d.ts +166 -0
  32. package/dist/contracts/admin-module.js +14 -0
  33. package/dist/contracts/agents/definition.d.ts +459 -0
  34. package/dist/contracts/agents/definition.js +2 -0
  35. package/dist/contracts/agents/index.d.ts +7 -0
  36. package/dist/contracts/agents/index.js +2 -0
  37. package/dist/contracts/agents/launch.d.ts +64 -0
  38. package/dist/contracts/agents/launch.js +2 -0
  39. package/dist/contracts/agents/model-catalog.d.ts +213 -0
  40. package/dist/contracts/agents/model-catalog.js +4 -0
  41. package/dist/contracts/agents/native-tool-policy.d.ts +42 -0
  42. package/dist/contracts/agents/native-tool-policy.js +2 -0
  43. package/dist/contracts/ai-trace/capture.d.ts +17 -0
  44. package/dist/contracts/ai-trace/capture.js +43 -0
  45. package/dist/contracts/ai-trace/classify.d.ts +12 -0
  46. package/dist/contracts/ai-trace/classify.js +16 -0
  47. package/dist/contracts/ai-trace/index.d.ts +13 -0
  48. package/dist/contracts/ai-trace/index.js +6 -0
  49. package/dist/contracts/ai-trace/recorder.d.ts +64 -0
  50. package/dist/contracts/ai-trace/recorder.js +283 -0
  51. package/dist/contracts/ai-trace/sinks.d.ts +51 -0
  52. package/dist/contracts/ai-trace/sinks.js +153 -0
  53. package/dist/contracts/ai-trace/types.d.ts +123 -0
  54. package/dist/contracts/ai-trace/types.js +17 -0
  55. package/dist/contracts/ai-trace/usage.d.ts +16 -0
  56. package/dist/contracts/ai-trace/usage.js +45 -0
  57. package/dist/contracts/blob.d.ts +31 -0
  58. package/dist/contracts/blob.js +10 -0
  59. package/dist/contracts/capabilities.d.ts +95 -0
  60. package/dist/contracts/capabilities.js +111 -0
  61. package/dist/contracts/charts.d.ts +75 -0
  62. package/dist/contracts/charts.js +4 -0
  63. package/dist/contracts/env.d.ts +96 -0
  64. package/dist/contracts/env.js +6 -0
  65. package/dist/contracts/events/change-set.d.ts +106 -0
  66. package/dist/contracts/events/change-set.js +2 -0
  67. package/dist/contracts/events/command.d.ts +118 -0
  68. package/dist/contracts/events/command.js +2 -0
  69. package/dist/contracts/events/ports.d.ts +172 -0
  70. package/dist/contracts/events/ports.js +2 -0
  71. package/dist/contracts/events.d.ts +5 -0
  72. package/dist/contracts/events.js +2 -0
  73. package/dist/contracts/forms.d.ts +110 -0
  74. package/dist/contracts/forms.js +4 -0
  75. package/dist/contracts/hosted-mcp/config.d.ts +19 -0
  76. package/dist/contracts/hosted-mcp/record.d.ts +61 -4
  77. package/dist/contracts/mail/email-sender.d.ts +118 -0
  78. package/dist/contracts/mail/email-sender.js +20 -0
  79. package/dist/contracts/mail/smtp-payload.d.ts +32 -0
  80. package/dist/contracts/mail/smtp-payload.js +2 -0
  81. package/dist/contracts/mail.d.ts +2 -0
  82. package/dist/contracts/mail.js +1 -1
  83. package/dist/contracts/observability.d.ts +235 -0
  84. package/dist/contracts/observability.js +28 -0
  85. package/dist/contracts/plugin-sdk.d.ts +186 -0
  86. package/dist/contracts/plugin-sdk.js +39 -0
  87. package/dist/contracts/runtime/command.d.ts +41 -0
  88. package/dist/contracts/runtime/command.js +60 -0
  89. package/dist/contracts/runtime/environment.d.ts +18 -0
  90. package/dist/contracts/runtime/environment.js +26 -0
  91. package/dist/contracts/runtime/file-lock.d.ts +94 -0
  92. package/dist/contracts/runtime/file-lock.js +25 -0
  93. package/dist/contracts/runtime/fs.d.ts +33 -0
  94. package/dist/contracts/runtime/fs.js +2 -0
  95. package/dist/contracts/runtime/http.d.ts +89 -0
  96. package/dist/contracts/runtime/http.js +2 -0
  97. package/dist/contracts/runtime/platform.d.ts +3 -0
  98. package/dist/contracts/runtime/platform.js +2 -0
  99. package/dist/contracts/runtime/process.d.ts +40 -0
  100. package/dist/contracts/runtime/process.js +31 -0
  101. package/dist/contracts/runtime/reader.d.ts +11 -0
  102. package/dist/contracts/runtime/reader.js +2 -0
  103. package/dist/contracts/runtime/terminal.d.ts +99 -0
  104. package/dist/contracts/runtime/terminal.js +2 -0
  105. package/dist/contracts/runtime/testing.d.ts +84 -0
  106. package/dist/contracts/runtime/testing.js +116 -0
  107. package/dist/contracts/runtime.d.ts +10 -0
  108. package/dist/contracts/runtime.js +10 -0
  109. package/dist/contracts/server/api-error.d.ts +43 -0
  110. package/dist/contracts/server/api-error.js +49 -0
  111. package/dist/contracts/server/auth.d.ts +20 -0
  112. package/dist/contracts/server/auth.js +21 -0
  113. package/dist/contracts/server/conformance.d.ts +25 -0
  114. package/dist/contracts/server/conformance.js +50 -0
  115. package/dist/contracts/server/json-route.d.ts +176 -0
  116. package/dist/contracts/server/json-route.js +155 -0
  117. package/dist/contracts/server/middleware.d.ts +35 -0
  118. package/dist/contracts/server/middleware.js +56 -0
  119. package/dist/contracts/server/origin.d.ts +44 -0
  120. package/dist/contracts/server/origin.js +32 -0
  121. package/dist/contracts/server/query.d.ts +16 -0
  122. package/dist/contracts/server/query.js +69 -0
  123. package/dist/contracts/server/rate-limit.d.ts +20 -0
  124. package/dist/contracts/server/rate-limit.js +8 -0
  125. package/dist/contracts/server/request-body.d.ts +26 -0
  126. package/dist/contracts/server/request-body.js +82 -0
  127. package/dist/contracts/server/result.d.ts +17 -0
  128. package/dist/contracts/server/result.js +5 -0
  129. package/dist/contracts/server/route-table.d.ts +54 -0
  130. package/dist/contracts/server/route-table.js +119 -0
  131. package/dist/contracts/server/same-origin-write.d.ts +18 -0
  132. package/dist/contracts/server/same-origin-write.js +31 -0
  133. package/dist/contracts/server/security-headers.d.ts +30 -0
  134. package/dist/contracts/server/security-headers.js +35 -0
  135. package/dist/contracts/server/sse.d.ts +82 -0
  136. package/dist/contracts/server/sse.js +103 -0
  137. package/dist/contracts/server/testing.d.ts +59 -0
  138. package/dist/contracts/server/testing.js +68 -0
  139. package/dist/contracts/server/verified-origin/configured-origin.d.ts +37 -0
  140. package/dist/contracts/server/verified-origin/configured-origin.js +103 -0
  141. package/dist/contracts/server/verified-origin/index.d.ts +7 -0
  142. package/dist/contracts/server/verified-origin/index.js +6 -0
  143. package/dist/contracts/server/verified-origin/loopback-host.d.ts +9 -0
  144. package/dist/contracts/server/verified-origin/loopback-host.js +17 -0
  145. package/dist/contracts/server/verified-origin/origin.d.ts +64 -0
  146. package/dist/contracts/server/verified-origin/origin.js +162 -0
  147. package/dist/contracts/server/verified-origin/ports.d.ts +38 -0
  148. package/dist/contracts/server/verified-origin/ports.js +2 -0
  149. package/dist/contracts/server/verified-origin/repo.memory.d.ts +32 -0
  150. package/dist/contracts/server/verified-origin/repo.memory.js +34 -0
  151. package/dist/contracts/server/verified-origin/site-path.d.ts +113 -0
  152. package/dist/contracts/server/verified-origin/site-path.js +188 -0
  153. package/dist/contracts/server/verified-origin/types.d.ts +33 -0
  154. package/dist/contracts/server/verified-origin/types.js +30 -0
  155. package/dist/contracts/server.d.ts +46 -2
  156. package/dist/contracts/server.js +17 -3
  157. package/dist/contracts/storage/kernel.d.ts +86 -0
  158. package/dist/contracts/storage/kernel.js +38 -0
  159. package/dist/contracts/storage/migration.d.ts +32 -0
  160. package/dist/contracts/storage/migration.js +2 -0
  161. package/dist/contracts/storage/rows.d.ts +33 -0
  162. package/dist/contracts/storage/rows.js +42 -0
  163. package/dist/contracts/storage/sqlite.d.ts +113 -0
  164. package/dist/contracts/storage/sqlite.js +8 -0
  165. package/dist/contracts/storage/values.d.ts +25 -0
  166. package/dist/contracts/storage/values.js +25 -0
  167. package/dist/contracts/storage.d.ts +8 -0
  168. package/dist/contracts/storage.js +6 -0
  169. package/dist/contracts/vault/invariants.d.ts +26 -0
  170. package/dist/contracts/vault/invariants.js +49 -0
  171. package/dist/contracts/vault.d.ts +1 -0
  172. package/dist/contracts/vault.js +1 -1
  173. package/dist/env/coercers.d.ts +21 -0
  174. package/dist/env/coercers.js +68 -0
  175. package/dist/env/describe-env-for-diagnostics.d.ts +16 -0
  176. package/dist/env/describe-env-for-diagnostics.js +23 -0
  177. package/dist/env/format-env-issue.d.ts +13 -0
  178. package/dist/env/format-env-issue.js +22 -0
  179. package/dist/env/parse-env.d.ts +24 -0
  180. package/dist/env/parse-env.js +102 -0
  181. package/dist/env/value-echo.d.ts +17 -0
  182. package/dist/env/value-echo.js +42 -0
  183. package/dist/errors/approved-cause.d.ts +36 -0
  184. package/dist/errors/approved-cause.js +17 -0
  185. package/dist/errors/bindings.d.ts +61 -0
  186. package/dist/errors/bindings.js +57 -0
  187. package/dist/errors/catalog.d.ts +84 -0
  188. package/dist/errors/catalog.js +151 -0
  189. package/dist/errors/disclosure.d.ts +48 -0
  190. package/dist/errors/disclosure.js +27 -0
  191. package/dist/errors/error-id.d.ts +26 -0
  192. package/dist/errors/error-id.js +23 -0
  193. package/dist/errors/idioms.d.ts +73 -0
  194. package/dist/errors/idioms.js +85 -0
  195. package/dist/errors/incident-text.d.ts +16 -0
  196. package/dist/errors/incident-text.js +77 -0
  197. package/dist/errors/reporter.d.ts +94 -0
  198. package/dist/errors/reporter.js +152 -0
  199. package/dist/errors/sentences.d.ts +68 -0
  200. package/dist/errors/sentences.js +93 -0
  201. package/dist/errors/testing.d.ts +50 -0
  202. package/dist/errors/testing.js +44 -0
  203. package/dist/fetch/cache.d.ts +12 -5
  204. package/dist/fetch/cache.js +46 -47
  205. package/dist/fetch/index.d.ts +1 -1
  206. package/dist/fetch/loader-read.d.ts +6 -2
  207. package/dist/fetch/loader-read.js +4 -4
  208. package/dist/format-error-for-log.d.ts +15 -0
  209. package/dist/format-error-for-log.js +55 -0
  210. package/dist/gated-mutations/gateway.d.ts +2 -0
  211. package/dist/gated-mutations/gateway.js +4 -1
  212. package/dist/host-read-vocabulary.d.ts +47 -0
  213. package/dist/host-read-vocabulary.js +44 -0
  214. package/dist/index.d.ts +5 -1
  215. package/dist/index.js +4 -0
  216. package/dist/list-page.d.ts +93 -0
  217. package/dist/list-page.js +154 -0
  218. package/dist/model-facing-tool-errors.d.ts +67 -5
  219. package/dist/model-facing-tool-errors.js +155 -19
  220. package/dist/net/endpoint-policy.d.ts +39 -0
  221. package/dist/net/endpoint-policy.js +218 -0
  222. package/dist/net/fetch-timeouts.d.ts +38 -0
  223. package/dist/net/fetch-timeouts.js +31 -0
  224. package/dist/net/index.d.ts +4 -0
  225. package/dist/net/index.js +4 -0
  226. package/dist/net/loopback.d.ts +13 -0
  227. package/dist/net/loopback.js +39 -0
  228. package/dist/optimistic-concurrency.d.ts +183 -0
  229. package/dist/optimistic-concurrency.js +222 -0
  230. package/dist/primitives/errors.d.ts +9 -0
  231. package/dist/primitives/errors.js +12 -0
  232. package/dist/primitives/ids.d.ts +0 -2
  233. package/dist/primitives/ids.js +1 -4
  234. package/dist/primitives/index.d.ts +3 -0
  235. package/dist/primitives/index.js +2 -0
  236. package/dist/primitives/logger.d.ts +36 -1
  237. package/dist/primitives/logger.js +125 -9
  238. package/dist/primitives/node-shape.d.ts +24 -0
  239. package/dist/primitives/node-shape.js +21 -0
  240. package/dist/primitives/time.d.ts +9 -2
  241. package/dist/primitives/time.js +4 -3
  242. package/dist/provider-registry.js +26 -20
  243. package/dist/records.d.ts +40 -7
  244. package/dist/records.js +37 -3
  245. package/dist/redact.d.ts +1 -84
  246. package/dist/redact.js +2 -826
  247. package/dist/redaction-collectors.d.ts +7 -0
  248. package/dist/redaction-collectors.js +152 -0
  249. package/dist/redaction-exact-secrets.d.ts +14 -0
  250. package/dist/redaction-exact-secrets.js +115 -0
  251. package/dist/redaction-labels.d.ts +14 -0
  252. package/dist/redaction-labels.js +156 -0
  253. package/dist/redaction-patterns.d.ts +54 -0
  254. package/dist/redaction-patterns.js +178 -0
  255. package/dist/redaction-spans.d.ts +31 -0
  256. package/dist/redaction-spans.js +83 -0
  257. package/dist/registration-kit.d.ts +1 -1
  258. package/dist/revision-conflict-error.d.ts +18 -0
  259. package/dist/revision-conflict-error.js +20 -0
  260. package/dist/secret-shapes.d.ts +50 -0
  261. package/dist/secret-shapes.js +105 -0
  262. package/dist/settings/agent-tools.js +22 -8
  263. package/dist/settings/agent-value-write-tools.d.ts +4 -1
  264. package/dist/settings/agent-value-write-tools.js +7 -6
  265. package/dist/settings/agent-writable-preferences.d.ts +3 -1
  266. package/dist/settings/agent-writable-preferences.js +1 -1
  267. package/dist/settings/agent-write-denylist.d.ts +7 -4
  268. package/dist/settings/agent-write-denylist.js +1 -1
  269. package/dist/settings/{express/cms-adapter.d.ts → cms-adapter.d.ts} +3 -2
  270. package/dist/settings/{express/cms-adapter.js → cms-adapter.js} +21 -11
  271. package/dist/settings/definitions-dispatch.js +3 -1
  272. package/dist/settings/ensure-definitions.js +3 -1
  273. package/dist/settings/errors.d.ts +1 -13
  274. package/dist/settings/errors.js +2 -15
  275. package/dist/settings/index.d.ts +11 -2
  276. package/dist/settings/index.js +10 -2
  277. package/dist/settings/purge-service.js +63 -86
  278. package/dist/settings/{express/contracts.d.ts → route-policy.d.ts} +53 -47
  279. package/dist/settings/{express/shared.js → route-policy.js} +1 -16
  280. package/dist/settings/settings.d.ts +19 -11
  281. package/dist/settings/settings.js +9 -11
  282. package/dist/settings/tool-registrations.d.ts +3 -3
  283. package/dist/settings/tool-registrations.js +130 -125
  284. package/dist/settings/types.d.ts +1 -1
  285. package/dist/settings/write-definition-rename.d.ts +37 -0
  286. package/dist/settings/write-definition-rename.js +119 -0
  287. package/dist/settings/write-definition-retype.d.ts +61 -0
  288. package/dist/settings/write-definition-retype.js +109 -0
  289. package/dist/settings/write-definition-status.d.ts +81 -0
  290. package/dist/settings/write-definition-status.js +121 -0
  291. package/dist/settings/write-reset.d.ts +34 -0
  292. package/dist/settings/write-reset.js +73 -0
  293. package/dist/settings/write-service.d.ts +16 -287
  294. package/dist/settings/write-service.js +49 -681
  295. package/dist/settings/write-value-revisions.d.ts +68 -0
  296. package/dist/settings/write-value-revisions.js +124 -0
  297. package/dist/settings/write-values.d.ts +96 -0
  298. package/dist/settings/write-values.js +83 -0
  299. package/dist/surface-exchanges.d.ts +2 -2
  300. package/dist/text/dictionary-translator.d.ts +19 -0
  301. package/dist/text/dictionary-translator.js +14 -0
  302. package/dist/text/format-byte-size.d.ts +25 -0
  303. package/dist/text/format-byte-size.js +25 -0
  304. package/dist/text/format-timestamp.d.ts +22 -0
  305. package/dist/text/format-timestamp.js +57 -0
  306. package/dist/text/index.d.ts +12 -0
  307. package/dist/text/index.js +9 -0
  308. package/dist/text/is-abort-error.d.ts +5 -0
  309. package/dist/text/is-abort-error.js +5 -0
  310. package/dist/text/mime.d.ts +5 -0
  311. package/dist/text/mime.js +21 -0
  312. package/dist/text/redact-urls.d.ts +7 -0
  313. package/dist/text/redact-urls.js +5 -0
  314. package/dist/text/resolve-active-tab-id.d.ts +13 -0
  315. package/dist/text/resolve-active-tab-id.js +15 -0
  316. package/dist/text/sanitize-untrusted-text.d.ts +1 -1
  317. package/dist/text/sanitize-untrusted-text.js +2 -1
  318. package/dist/text/tagged-text-suppression.d.ts +103 -0
  319. package/dist/text/tagged-text-suppression.js +143 -0
  320. package/dist/text/template-i18n.d.ts +37 -0
  321. package/dist/text/template-i18n.js +48 -0
  322. package/dist/tool-call-text.d.ts +59 -0
  323. package/dist/tool-call-text.js +62 -0
  324. package/dist/tool-input-envelope.js +8 -4
  325. package/dist/tool-input-normalization.js +8 -1
  326. package/dist/tool-input-repairs.d.ts +58 -0
  327. package/dist/tool-input-repairs.js +154 -0
  328. package/dist/tool-tokens.js +1 -1
  329. package/dist/user-facing-error.d.ts +1 -1
  330. package/dist/user-facing-error.js +3 -1
  331. package/package.json +235 -14
  332. package/plugin-directory.d.ts +2 -2
  333. package/plugin-directory.js +16 -10
  334. package/dist/settings/express/contracts.js +0 -2
  335. package/dist/settings/express/http-request.d.ts +0 -33
  336. package/dist/settings/express/http-request.js +0 -50
  337. package/dist/settings/express/http.d.ts +0 -10
  338. package/dist/settings/express/http.js +0 -196
  339. package/dist/settings/express/index.d.ts +0 -5
  340. package/dist/settings/express/index.js +0 -4
  341. package/dist/settings/express/shared.d.ts +0 -68
  342. package/dist/settings/express/stream.d.ts +0 -24
  343. package/dist/settings/express/stream.js +0 -171
@@ -1,50 +0,0 @@
1
- import { respondToSettingsError } from "./shared.js";
2
- /**
3
- * @file Request-level steps of the settings HTTP registrar (`http.ts`): the
4
- * authentication gate, the failure envelope and value-write body parsing.
5
- * Pure or response-only; no service, authorization or storage effects.
6
- */
7
- export const SETTING_SCOPES = ["global", "workspace", "user"];
8
- export function unauthenticated(res) {
9
- res.status(401).json({ error: "unauthenticated", code: "UNAUTHENTICATED" });
10
- }
11
- /** Readiness/principal failures preserve the authentication boundary's existing 401 envelope, so both collapse to null. */
12
- export async function resolvePrincipal(required, context) {
13
- try {
14
- await required.ready;
15
- return await required.principalResolver(context);
16
- }
17
- catch {
18
- return null;
19
- }
20
- }
21
- /** Map a handler failure to its envelope, or end a response whose headers have already been sent. */
22
- export function failRequest(required, optional) {
23
- const { response, error, mappings } = required;
24
- if (!response.headersSent) {
25
- respondToSettingsError({ response, error, mappings });
26
- return;
27
- }
28
- // Reporting cannot prevent ending a response whose headers have already been sent.
29
- try {
30
- optional.onError?.({ operation: "settings-request", error });
31
- }
32
- catch { /* Host diagnostics are best-effort. */ }
33
- finally {
34
- response.end();
35
- }
36
- }
37
- export const VALUE_MUTATION_REQUIRED = {
38
- set: "namespace, key, scope (global|workspace|user), and valueJson are required",
39
- clear: "namespace, key, and scope (global|workspace|user) are required",
40
- };
41
- /** The fields a value write needs, or null when one is missing or the scope is unknown. Pure, O(1). */
42
- export function readValueMutation(body, operation) {
43
- const namespace = String(body.namespace ?? "");
44
- const key = String(body.key ?? "");
45
- const scope = body.scope;
46
- const hasValue = operation === "clear" || "valueJson" in body;
47
- const complete = namespace && key && SETTING_SCOPES.includes(scope) && hasValue;
48
- return complete ? { namespace, key, scope } : null;
49
- }
50
- //# sourceMappingURL=http-request.js.map
@@ -1,10 +0,0 @@
1
- import type { SettingsHttpRequired, SettingsHttpOptions } from "./contracts.js";
2
- /** Mount all eight endpoints. The returned disposer closes active feeds and cancels their schedules.
3
- * Injected policy and services preserve the settings HTTP response envelopes.
4
- * O(1) mounting; read/mutation work is delegated. Feed resources are bounded per connection.
5
- * @example registerSettingsRoutes({ app, workspaceId, ready, service, changeFeed, principalResolver, authorize, scheduler, routes, permissions });
6
- */
7
- export declare function registerSettingsRoutes(required: SettingsHttpRequired, optional?: SettingsHttpOptions): {
8
- dispose(): void;
9
- };
10
- //# sourceMappingURL=http.d.ts.map
@@ -1,196 +0,0 @@
1
- import { AliasDepthExceededError, DefinitionInvalidError, DefinitionNotFoundError, DefinitionTombstonedError, ForbiddenError, PrincipalNotFoundError, RenameRetypeConflictError, ScopeNotAllowedError, SecretNotSupportedError, ValueValidationFailedError, } from "../index.js";
2
- import { resolveTargetWorkspaceId, resolveUserLayerReadTarget, settingsWritePermission } from "./shared.js";
3
- import { openSettingsChangeStream } from "./stream.js";
4
- import { failRequest, readValueMutation, resolvePrincipal, SETTING_SCOPES, unauthenticated, VALUE_MUTATION_REQUIRED } from "./http-request.js";
5
- const VALUE_ERRORS = [
6
- { matches: (e) => e instanceof PrincipalNotFoundError, status: 404, code: "PRINCIPAL_NOT_FOUND" },
7
- { matches: (e) => e instanceof DefinitionNotFoundError, status: 404, code: "DEFINITION_NOT_FOUND" },
8
- { matches: (e) => e instanceof DefinitionTombstonedError, status: 409, code: "DEFINITION_TOMBSTONED" },
9
- { matches: (e) => e instanceof ScopeNotAllowedError, status: 400, code: "SCOPE_NOT_ALLOWED" },
10
- { matches: (e) => e instanceof ValueValidationFailedError, status: 400, code: "VALUE_VALIDATION_FAILED" },
11
- { matches: (e) => e instanceof ForbiddenError, status: 403, code: "FORBIDDEN" },
12
- ];
13
- const DEFINITION_ERRORS = [
14
- { matches: (e) => e instanceof SecretNotSupportedError, status: 400, code: "SECRET_NOT_SUPPORTED" },
15
- { matches: (e) => e instanceof DefinitionInvalidError, status: 400, code: "DEFINITION_INVALID" },
16
- { matches: (e) => e instanceof RenameRetypeConflictError, status: 409, code: "RENAME_RETYPE_CONFLICT" },
17
- { matches: (e) => e instanceof AliasDepthExceededError, status: 409, code: "ALIAS_DEPTH_EXCEEDED" },
18
- { matches: (e) => e instanceof DefinitionTombstonedError, status: 409, code: "DEFINITION_TOMBSTONED" },
19
- { matches: (e) => e instanceof ForbiddenError, status: 403, code: "FORBIDDEN" },
20
- ];
21
- const RESET_ERRORS = VALUE_ERRORS.filter((m) => m.code === "FORBIDDEN");
22
- function validation(res, error) {
23
- res.status(400).json({ error, code: "VALIDATION_ERROR" });
24
- }
25
- function denied(res, principalId, permission, reason) {
26
- res.status(403).json({ error: `principal '${principalId}' is not authorized for '${permission}' (${reason})`,
27
- code: "FORBIDDEN", details: { permission, reason } });
28
- }
29
- function bodyOf(req) {
30
- return req.body && typeof req.body === "object" && !Array.isArray(req.body) ? req.body : {};
31
- }
32
- /** Mount all eight endpoints. The returned disposer closes active feeds and cancels their schedules.
33
- * Injected policy and services preserve the settings HTTP response envelopes.
34
- * O(1) mounting; read/mutation work is delegated. Feed resources are bounded per connection.
35
- * @example registerSettingsRoutes({ app, workspaceId, ready, service, changeFeed, principalResolver, authorize, scheduler, routes, permissions });
36
- */
37
- export function registerSettingsRoutes(required, optional = {}) {
38
- const { app, workspaceId, service, routes, permissions } = required;
39
- const streams = new Set();
40
- let disposed = false;
41
- const wrap = (handler, mappings = []) => async (req, res) => {
42
- if (disposed) {
43
- res.status(503).json({ error: "settings routes are disposed", code: "UNAVAILABLE" });
44
- return;
45
- }
46
- if (String(req.params[routes.workspaceParam] ?? "") !== workspaceId) {
47
- res.status(404).json({ error: "workspace was not found" });
48
- return;
49
- }
50
- const principal = await resolvePrincipal(required, { request: req, response: res });
51
- if (!principal) {
52
- unauthenticated(res);
53
- return;
54
- }
55
- try {
56
- await handler(req, res, principal.id);
57
- }
58
- catch (error) {
59
- failRequest({ response: res, error, mappings }, optional);
60
- }
61
- };
62
- const check = async (res, principalId, permission, entityType) => {
63
- const result = await required.authorize({ principalId, permission, workspaceId, entityType });
64
- if (!result.allowed)
65
- denied(res, principalId, permission, result.reason);
66
- return result.allowed;
67
- };
68
- const readTarget = async (res, principalId, requestedPrincipalId) => {
69
- const result = await resolveUserLayerReadTarget({ deps: { workspaceId, authorize: required.authorize, permission: permissions.readOtherUser },
70
- input: { callerPrincipalId: principalId, requestedPrincipalId } });
71
- if (!result.allowed)
72
- res.status(403).json({
73
- error: `principal '${principalId}' is not authorized to read another principal's user-layer value (${result.reason})`,
74
- code: "FORBIDDEN", details: { permission: permissions.readOtherUser, reason: result.reason },
75
- });
76
- return result;
77
- };
78
- app.get(routes.definitions, wrap(async (_req, res, principalId) => {
79
- if (!await check(res, principalId, permissions.readDefinitions, "setting-definition"))
80
- return;
81
- const definitions = await service.listDefinitions({ workspaceId });
82
- const data = definitions.map(({ namespace, key, ownerKind, scopes, status, version }) => ({ namespace, key, ownerKind, scopes, status, version }))
83
- .sort((a, b) => a.namespace.localeCompare(b.namespace) || a.key.localeCompare(b.key));
84
- res.json({ data });
85
- }));
86
- app.get(routes.effective, wrap(async (req, res, principalId) => {
87
- if (!await check(res, principalId, permissions.read, "setting-value"))
88
- return;
89
- const namespace = String(req.query.namespace ?? "");
90
- if (!namespace) {
91
- validation(res, "'namespace' query param is required");
92
- return;
93
- }
94
- const target = await readTarget(res, principalId, req.query.principalId ? String(req.query.principalId) : principalId);
95
- if (!target.allowed)
96
- return;
97
- res.json({ data: await service.effective({ namespace, workspaceId, principalId: target.principalId }) });
98
- }));
99
- app.get(routes.raw, wrap(async (req, res, principalId) => {
100
- if (!await check(res, principalId, permissions.readRaw, "setting-value"))
101
- return;
102
- const namespace = String(req.query.namespace ?? "");
103
- const key = String(req.query.key ?? "");
104
- if (!namespace || !key) {
105
- validation(res, "'namespace' and 'key' query params are required");
106
- return;
107
- }
108
- const target = await readTarget(res, principalId, req.query.principalId ? String(req.query.principalId) : undefined);
109
- if (!target.allowed)
110
- return;
111
- const result = await service.raw({ namespace, key, workspaceId, principalId: target.principalId });
112
- if (!result) {
113
- res.status(404).json({ error: `definition '${namespace}.${key}' was not found`, code: "DEFINITION_NOT_FOUND" });
114
- return;
115
- }
116
- res.json(result);
117
- }));
118
- app.post(routes.definitions, wrap(async (req, res, principalId) => {
119
- if (!await check(res, principalId, permissions.manageDefinitions, "setting-definition"))
120
- return;
121
- const items = bodyOf(req).definitions;
122
- if (!Array.isArray(items)) {
123
- validation(res, "'definitions' must be an array");
124
- return;
125
- }
126
- const result = await service.definitions({ items, callerPrincipalId: principalId, authWorkspaceId: workspaceId });
127
- if ("unknownOp" in result) {
128
- validation(res, `unknown op '${result.unknownOp}'`);
129
- return;
130
- }
131
- res.json(result);
132
- }, DEFINITION_ERRORS));
133
- const mutate = (operation) => async (req, res, callerPrincipalId) => {
134
- const body = bodyOf(req);
135
- const fields = readValueMutation(body, operation);
136
- if (!fields) {
137
- validation(res, VALUE_MUTATION_REQUIRED[operation]);
138
- return;
139
- }
140
- const { namespace, key, scope } = fields;
141
- const target = resolveTargetWorkspaceId({ workspaceId, input: { bodyWorkspaceId: body.workspaceId, scope } });
142
- if (!target.ok) {
143
- validation(res, target.error);
144
- return;
145
- }
146
- const principalId = body.principalId ? String(body.principalId) : undefined;
147
- const permission = settingsWritePermission({ permissions, scope, callerPrincipalId, targetPrincipalId: principalId });
148
- if (!await check(res, callerPrincipalId, permission, "setting-value"))
149
- return;
150
- const input = { namespace, key, scope, workspaceId: target.workspaceId, principalId, callerPrincipalId, authWorkspaceId: workspaceId };
151
- const result = operation === "set" ? await service.set({ ...input, value: body.valueJson }) : await service.clear(input);
152
- res.json({ key: `${namespace}.${key}`, scope, value: "value" in result ? result.value : null, revisionSeq: result.revisionSeq });
153
- };
154
- app.put(routes.value, wrap(mutate("set"), VALUE_ERRORS));
155
- app.delete(routes.value, wrap(mutate("clear"), VALUE_ERRORS.filter((m) => m.code !== "VALUE_VALIDATION_FAILED")));
156
- app.post(routes.reset, wrap(async (req, res, callerPrincipalId) => {
157
- const body = bodyOf(req);
158
- const namespace = String(body.namespace ?? "");
159
- const scope = body.scope;
160
- if (!namespace || !SETTING_SCOPES.includes(scope)) {
161
- validation(res, "namespace and scope (global|workspace|user) are required");
162
- return;
163
- }
164
- const target = resolveTargetWorkspaceId({ workspaceId, input: { bodyWorkspaceId: body.workspaceId, scope } });
165
- if (!target.ok) {
166
- validation(res, target.error);
167
- return;
168
- }
169
- if (!await check(res, callerPrincipalId, permissions.reset[scope], "setting-namespace"))
170
- return;
171
- const result = await service.reset({ namespace, scope, workspaceId: target.workspaceId, callerPrincipalId, authWorkspaceId: workspaceId });
172
- res.json({ namespace, ...result });
173
- }, RESET_ERRORS));
174
- app.get(routes.events, wrap(async (req, res, principalId) => {
175
- if (!await check(res, principalId, permissions.read, "setting-value"))
176
- return;
177
- const close = await openSettingsChangeStream({ request: req, response: res, workspaceId, principalId,
178
- changeFeed: required.changeFeed, authorize: required.authorize, permission: permissions.read, scheduler: required.scheduler,
179
- onClose: ({ close }) => { streams.delete(close); }, isDisposed: () => disposed }, optional);
180
- if (disposed) {
181
- close();
182
- return;
183
- }
184
- if (!res.destroyed && !res.writableEnded)
185
- streams.add(close);
186
- }));
187
- return {
188
- dispose: () => {
189
- disposed = true;
190
- for (const close of streams)
191
- close();
192
- streams.clear();
193
- },
194
- };
195
- }
196
- //# sourceMappingURL=http.js.map
@@ -1,5 +0,0 @@
1
- export type { Authorize, PrincipalResolver, Scheduler, SettingsPermissions, SettingsRoutes, SettingsService, SettingsChangeFeed, SettingsHttpRequired, SettingsHttpOptions, EffectiveSettingRow, RawSetting, DefinitionResult, } from "./contracts.js";
2
- export { resolveTargetWorkspaceId, resolveUserLayerReadTarget, respondToSettingsError, settingsWritePermission, type TargetWorkspaceResolution, type UserLayerReadTarget, type SettingsErrorMapping, } from "./shared.js";
3
- export { createCmsSettingsService, createCmsSettingsChangeFeed } from "./cms-adapter.js";
4
- export { registerSettingsRoutes } from "./http.js";
5
- //# sourceMappingURL=index.d.ts.map
@@ -1,4 +0,0 @@
1
- export { resolveTargetWorkspaceId, resolveUserLayerReadTarget, respondToSettingsError, settingsWritePermission, } from "./shared.js";
2
- export { createCmsSettingsService, createCmsSettingsChangeFeed } from "./cms-adapter.js";
3
- export { registerSettingsRoutes } from "./http.js";
4
- //# sourceMappingURL=index.js.map
@@ -1,68 +0,0 @@
1
- import type { Response } from "express";
2
- import type { SettingScope } from "../index.js";
3
- import type { Authorize, SettingsPermissions } from "./contracts.js";
4
- export type TargetWorkspaceResolution = {
5
- ok: true;
6
- workspaceId: string | undefined;
7
- } | {
8
- ok: false;
9
- error: string;
10
- };
11
- /** Pin writes to the authorized workspace, rejecting a conflicting body target.
12
- * Global scope has no target workspace. Pure; O(1) time/space for string ids.
13
- * @example resolveTargetWorkspaceId({ workspaceId, input: { scope: "workspace", bodyWorkspaceId } });
14
- */
15
- export declare function resolveTargetWorkspaceId(required: {
16
- workspaceId: string;
17
- input: {
18
- bodyWorkspaceId: unknown;
19
- scope: SettingScope;
20
- };
21
- }): TargetWorkspaceResolution;
22
- export type UserLayerReadTarget = {
23
- allowed: true;
24
- principalId: string | undefined;
25
- } | {
26
- allowed: false;
27
- reason: string;
28
- };
29
- /** Require the injected cross-principal grant only when a read targets another user.
30
- * Returns the denial reason without reading values; one authorization effect at most.
31
- * @complexity O(1) excluding the authorizer.
32
- * @example resolveUserLayerReadTarget({ deps: { workspaceId, authorize, permission }, input });
33
- */
34
- export declare function resolveUserLayerReadTarget(required: {
35
- deps: {
36
- workspaceId: string;
37
- authorize: Authorize;
38
- permission: string;
39
- };
40
- input: {
41
- requestedPrincipalId: string | undefined;
42
- callerPrincipalId: string;
43
- };
44
- }): Promise<UserLayerReadTarget>;
45
- export interface SettingsErrorMapping {
46
- readonly matches: (error: unknown) => boolean;
47
- readonly status: number;
48
- readonly code: string;
49
- }
50
- /** Write the first matching status/code, or a fixed 500 that does not disclose unknown errors.
51
- * @complexity O(mapping count) time, O(1) space; response write effect.
52
- * @example respondToSettingsError({ response, error, mappings });
53
- */
54
- export declare function respondToSettingsError(required: {
55
- response: Pick<Response, "status" | "json">;
56
- error: unknown;
57
- mappings: readonly SettingsErrorMapping[];
58
- }): void;
59
- /** Select caller policy for the CMS scope and self/other-user split; pure, O(1).
60
- * @example settingsWritePermission({ permissions, scope: "user", callerPrincipalId, targetPrincipalId });
61
- */
62
- export declare function settingsWritePermission(required: {
63
- permissions: SettingsPermissions;
64
- scope: SettingScope;
65
- callerPrincipalId: string;
66
- targetPrincipalId: string | undefined;
67
- }): string;
68
- //# sourceMappingURL=shared.d.ts.map
@@ -1,24 +0,0 @@
1
- import type { Request, Response } from "express";
2
- import type { Authorize, SettingsChangeFeed, SettingsHttpOptions, Scheduler } from "./contracts.js";
3
- interface StreamRequired {
4
- request: Request;
5
- response: Response;
6
- workspaceId: string;
7
- principalId: string;
8
- changeFeed: SettingsChangeFeed;
9
- authorize: Authorize;
10
- permission: string;
11
- scheduler: Scheduler;
12
- onClose: (required: {
13
- close: () => void;
14
- }) => void;
15
- isDisposed: () => boolean;
16
- }
17
- /** Starts after HTTP authorization. All scheduling and storage are injected.
18
- * Poll with bounded pages, tenant-scoped ids and retryable reads; close cancels all schedules.
19
- * O(page size) per tick and O(1) connection state; repository effects live behind the feed port.
20
- * Invalid scheduler intervals/page sizes throw RangeError before opening; initial read errors propagate.
21
- */
22
- export declare function openSettingsChangeStream(required: StreamRequired, optional?: SettingsHttpOptions): Promise<() => void>;
23
- export {};
24
- //# sourceMappingURL=stream.d.ts.map
@@ -1,171 +0,0 @@
1
- import { inspect } from 'node:util';
2
- import { redactSecrets } from '../../redact.js';
3
- /** Starts after HTTP authorization. All scheduling and storage are injected.
4
- * Poll with bounded pages, tenant-scoped ids and retryable reads; close cancels all schedules.
5
- * O(page size) per tick and O(1) connection state; repository effects live behind the feed port.
6
- * Invalid scheduler intervals/page sizes throw RangeError before opening; initial read errors propagate.
7
- */
8
- export async function openSettingsChangeStream(required, optional = {}) {
9
- const { request, response, workspaceId, principalId, changeFeed, scheduler } = required;
10
- const { pageSize, pollIntervalMs, keepaliveIntervalMs, reauthorizeIntervalMs } = readStreamTimings(optional);
11
- let closed = false;
12
- let ticking = false;
13
- let checkingAuthorization = false;
14
- const cancellations = [];
15
- const reportError = createErrorReporter(optional);
16
- const recover = (operation, effect) => {
17
- try {
18
- effect();
19
- }
20
- catch (error) {
21
- reportError(operation, error);
22
- }
23
- };
24
- const release = () => {
25
- // Every resource gets its own recovery boundary so one failing cancellation cannot leak others.
26
- for (const cancel of cancellations.splice(0))
27
- recover("cancel", cancel);
28
- recover("request-listener", () => { request.off("close", close); });
29
- recover("response-listener", () => { response.off("close", close); });
30
- };
31
- const close = () => {
32
- if (closed)
33
- return;
34
- closed = true;
35
- release();
36
- recover("close", () => { required.onClose({ close }); });
37
- if (!response.writableEnded && !response.destroyed)
38
- recover("end", () => { response.end(); });
39
- };
40
- request.on("close", close);
41
- response.on("close", close);
42
- try {
43
- const head = await changeFeed.head({});
44
- const gone = () => closed || required.isDisposed() || response.destroyed || response.writableEnded;
45
- if (gone()) {
46
- close();
47
- return close;
48
- }
49
- let cursor = resumeCursor({ lastEventId: request.headers["last-event-id"], head });
50
- let lastEmittedId = cursor;
51
- const viewer = { workspaceId, principalId };
52
- response.writeHead(200, sseHeaders({ httpVersionMajor: request.httpVersionMajor }));
53
- const tick = async () => {
54
- if (closed || ticking)
55
- return;
56
- ticking = true;
57
- try {
58
- // Snapshot head before the page: concurrent writes must never be skipped.
59
- const ledgerHead = await changeFeed.head({});
60
- if (closed)
61
- return;
62
- const batch = await changeFeed.collect({ sinceSeq: cursor, limit: pageSize, viewer });
63
- if (closed)
64
- return;
65
- const examined = batch.examinedCount < pageSize ? ledgerHead : batch.cursor;
66
- cursor = Math.max(cursor, examined, batch.cursor);
67
- if (!batch.namespaces.length)
68
- return;
69
- // The internal global head is never disclosed as an event id.
70
- lastEmittedId = Math.max(lastEmittedId, batch.cursor);
71
- response.write(`id: ${lastEmittedId}\nevent: settings-changed\ndata: ${JSON.stringify({ namespaces: batch.namespaces })}\n\n`);
72
- }
73
- catch (error) {
74
- if (!closed)
75
- reportError("poll", error);
76
- }
77
- finally {
78
- ticking = false;
79
- }
80
- };
81
- const reauthorize = async () => {
82
- if (closed || checkingAuthorization)
83
- return;
84
- checkingAuthorization = true;
85
- try {
86
- const result = await required.authorize({ principalId, workspaceId, permission: required.permission, entityType: "setting-value" });
87
- if (!closed && !result.allowed)
88
- close();
89
- }
90
- catch (error) {
91
- if (!closed)
92
- reportError("re-authorization", error);
93
- }
94
- finally {
95
- checkingAuthorization = false;
96
- }
97
- };
98
- const schedule = (intervalMs, callback) => {
99
- const cancel = scheduler.every({ intervalMs, callback });
100
- if (closed)
101
- recover("cancel", cancel);
102
- else
103
- cancellations.push(cancel);
104
- };
105
- schedule(pollIntervalMs, () => { void tick(); });
106
- schedule(keepaliveIntervalMs, () => {
107
- if (closed)
108
- return;
109
- try {
110
- response.write(": keepalive\n\n");
111
- }
112
- catch (error) {
113
- reportError("keepalive", error);
114
- close();
115
- }
116
- });
117
- schedule(reauthorizeIntervalMs, () => { void reauthorize(); });
118
- if (!closed)
119
- response.write(": connected\n\n");
120
- return close;
121
- }
122
- catch (error) {
123
- // Cancel schedules even when opening a feed fails. Let the HTTP wrapper map the error.
124
- if (response.headersSent)
125
- close();
126
- else {
127
- closed = true;
128
- release();
129
- }
130
- throw error;
131
- }
132
- }
133
- /** Fill the documented defaults, then refuse any non-positive page size or interval before an effect. Pure. */
134
- function readStreamTimings(optional) {
135
- const timings = {
136
- pageSize: optional.revisionPageSize ?? 200,
137
- pollIntervalMs: optional.pollIntervalMs ?? 1_000,
138
- keepaliveIntervalMs: optional.keepaliveIntervalMs ?? 25_000,
139
- reauthorizeIntervalMs: optional.reauthorizeIntervalMs ?? 30_000,
140
- };
141
- const intervals = [timings.pollIntervalMs, timings.keepaliveIntervalMs, timings.reauthorizeIntervalMs];
142
- if (!Number.isSafeInteger(timings.pageSize) || timings.pageSize <= 0 || intervals.some((n) => !Number.isFinite(n) || n <= 0)) {
143
- throw new RangeError("settings feed page size and intervals must be positive");
144
- }
145
- return timings;
146
- }
147
- function createErrorReporter(optional) {
148
- return (operation, error) => {
149
- // Reporting is best-effort: a host hook must never turn recovery into an unhandled rejection.
150
- try {
151
- if (optional.onError)
152
- optional.onError({ operation, error });
153
- else
154
- console.error(`[settings] change feed ${operation} failed`, redactSecrets({ input: inspect(error) }, { redactPii: false }));
155
- }
156
- catch { /* Diagnostic failures cannot interrupt stream cleanup or retries. */ }
157
- };
158
- }
159
- /** A client's Last-Event-ID resumes at or before the ledger head; a missing or unusable id starts at head. Pure. */
160
- function resumeCursor(required) {
161
- const resumeFrom = Number(required.lastEventId);
162
- return Number.isFinite(resumeFrom) && resumeFrom >= 0 ? Math.min(resumeFrom, required.head) : required.head;
163
- }
164
- /** HTTP/2 forbids the Connection header; HTTP/1 needs it to keep the stream open. Pure. */
165
- function sseHeaders(required) {
166
- return {
167
- "Content-Type": "text/event-stream", "Cache-Control": "no-cache, no-transform",
168
- ...(required.httpVersionMajor < 2 ? { Connection: "keep-alive" } : {}), "X-Accel-Buffering": "no",
169
- };
170
- }
171
- //# sourceMappingURL=stream.js.map