@cosmicdrift/kumiko-bundled-features 0.406.0 → 0.410.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (353) hide show
  1. package/dist/account-security/feature.js +9 -1
  2. package/dist/admin-shell/feature.d.ts +3 -0
  3. package/dist/admin-shell/feature.js +1 -1
  4. package/dist/agent-tools/agent-manifest.js +1 -0
  5. package/dist/agent-tools/tool-catalog.js +1 -0
  6. package/dist/agent-tools/types.d.ts +4 -1
  7. package/dist/audit/event-classification.js +1 -0
  8. package/dist/auth-email-password/bootstrap.js +1 -0
  9. package/dist/auth-email-password/errors.js +16 -41
  10. package/dist/auth-email-password/handlers/login-options.query.js +1 -1
  11. package/dist/auth-email-password/handlers/self-registration-status.query.js +1 -1
  12. package/dist/auth-email-password/web/auth-client.d.ts +8 -32
  13. package/dist/auth-email-password/web/auth-client.js +18 -52
  14. package/dist/auth-email-password/web/auth-redirect.js +2 -2
  15. package/dist/auth-email-password/web/confirm-account-unlock-screen.d.ts +2 -2
  16. package/dist/auth-email-password/web/confirm-account-unlock-screen.js +14 -35
  17. package/dist/auth-email-password/web/index.d.ts +1 -0
  18. package/dist/auth-email-password/web/index.js +1 -0
  19. package/dist/auth-email-password/web/read-path-param.d.ts +1 -0
  20. package/dist/auth-email-password/web/read-path-param.js +4 -0
  21. package/dist/auth-email-password/web/return-path.js +2 -2
  22. package/dist/auth-email-password/web/token-confirm-screen.d.ts +20 -0
  23. package/dist/auth-email-password/web/token-confirm-screen.js +38 -0
  24. package/dist/auth-email-password/web/verify-email-screen.d.ts +2 -2
  25. package/dist/auth-email-password/web/verify-email-screen.js +14 -37
  26. package/dist/auth-foundation/boot-checks.js +24 -12
  27. package/dist/auth-foundation/boot-rules.d.ts +27 -0
  28. package/dist/auth-foundation/boot-rules.js +27 -0
  29. package/dist/auth-mfa/errors.d.ts +1 -1
  30. package/dist/auth-mfa/errors.js +11 -24
  31. package/dist/auth-mfa/feature-exports.js +6 -45
  32. package/dist/auth-mfa/feature.js +7 -18
  33. package/dist/auth-mfa/web/mfa-client.js +11 -25
  34. package/dist/billing-foundation/consumer-protection/termination-notify.js +1 -0
  35. package/dist/billing-foundation/web/plan-price.js +7 -8
  36. package/dist/cap-counter/stock-cap-guard.js +1 -0
  37. package/dist/channel-in-app/constants.d.ts +1 -0
  38. package/dist/channel-in-app/feature.js +2 -0
  39. package/dist/channel-in-app/handlers/read-state-by-keys.query.d.ts +9 -0
  40. package/dist/channel-in-app/handlers/read-state-by-keys.query.js +21 -0
  41. package/dist/channel-in-app/in-app-channel.js +1 -0
  42. package/dist/channel-in-app/tables.js +5 -1
  43. package/dist/compliance-profiles/handlers/sub-processors.query.js +4 -1
  44. package/dist/contact/challenge.d.ts +14 -0
  45. package/dist/contact/challenge.js +30 -0
  46. package/dist/contact/client/contact-client-source.d.ts +1 -0
  47. package/dist/contact/client/contact-client-source.js +203 -0
  48. package/dist/contact/client/contact-website-client.d.ts +26 -0
  49. package/dist/contact/client/contact-website-client.js +1 -0
  50. package/dist/contact/client/index.d.ts +2 -0
  51. package/dist/contact/client/index.js +1 -0
  52. package/dist/contact/entity.d.ts +777 -0
  53. package/dist/contact/entity.js +145 -0
  54. package/dist/contact/feature.d.ts +3 -0
  55. package/dist/contact/feature.js +134 -0
  56. package/dist/contact/handlers/access.d.ts +7 -0
  57. package/dist/contact/handlers/access.js +9 -0
  58. package/dist/contact/handlers/attempts.d.ts +14 -0
  59. package/dist/contact/handlers/attempts.js +54 -0
  60. package/dist/contact/handlers/challenge.query.d.ts +9 -0
  61. package/dist/contact/handlers/challenge.query.js +35 -0
  62. package/dist/contact/handlers/forward-request.write.d.ts +9 -0
  63. package/dist/contact/handlers/forward-request.write.js +61 -0
  64. package/dist/contact/handlers/mark-done.write.d.ts +7 -0
  65. package/dist/contact/handlers/mark-done.write.js +30 -0
  66. package/dist/contact/handlers/notify-reporter-in-app.write.d.ts +10 -0
  67. package/dist/contact/handlers/notify-reporter-in-app.write.js +36 -0
  68. package/dist/contact/handlers/open-count.d.ts +2 -0
  69. package/dist/contact/handlers/open-count.js +11 -0
  70. package/dist/contact/handlers/open-count.query.d.ts +3 -0
  71. package/dist/contact/handlers/open-count.query.js +13 -0
  72. package/dist/contact/handlers/replies.query.d.ts +11 -0
  73. package/dist/contact/handlers/replies.query.js +28 -0
  74. package/dist/contact/handlers/reply.write.d.ts +12 -0
  75. package/dist/contact/handlers/reply.write.js +118 -0
  76. package/dist/contact/handlers/report.write.d.ts +16 -0
  77. package/dist/contact/handlers/report.write.js +90 -0
  78. package/dist/contact/handlers/request-delivery.query.d.ts +16 -0
  79. package/dist/contact/handlers/request-delivery.query.js +85 -0
  80. package/dist/contact/handlers/request-detail.query.d.ts +41 -0
  81. package/dist/contact/handlers/request-detail.query.js +32 -0
  82. package/dist/contact/handlers/request-list.query.d.ts +2 -0
  83. package/dist/contact/handlers/request-list.query.js +9 -0
  84. package/dist/contact/handlers/send-reply-mail.write.d.ts +8 -0
  85. package/dist/contact/handlers/send-reply-mail.write.js +82 -0
  86. package/dist/contact/handlers/send-test.write.d.ts +5 -0
  87. package/dist/contact/handlers/send-test.write.js +36 -0
  88. package/dist/contact/handlers/submit.write.d.ts +20 -0
  89. package/dist/contact/handlers/submit.write.js +137 -0
  90. package/dist/contact/handlers/take-over-uploads.d.ts +9 -0
  91. package/dist/contact/handlers/take-over-uploads.js +33 -0
  92. package/dist/contact/i18n.d.ts +6 -0
  93. package/dist/contact/i18n.js +189 -0
  94. package/dist/contact/index.d.ts +5 -0
  95. package/dist/contact/index.js +4 -0
  96. package/dist/contact/lib.d.ts +101 -0
  97. package/dist/contact/lib.js +109 -0
  98. package/dist/contact/mail.d.ts +91 -0
  99. package/dist/contact/mail.js +279 -0
  100. package/dist/contact/options.d.ts +51 -0
  101. package/dist/contact/options.js +32 -0
  102. package/dist/contact/panels.d.ts +2 -0
  103. package/dist/contact/panels.js +21 -0
  104. package/dist/contact/payloads.d.ts +56 -0
  105. package/dist/contact/payloads.js +82 -0
  106. package/dist/contact/pow.d.ts +6 -0
  107. package/dist/contact/pow.js +19 -0
  108. package/dist/contact/screens.d.ts +5 -0
  109. package/dist/contact/screens.js +465 -0
  110. package/dist/contact/subject.d.ts +1 -0
  111. package/dist/contact/subject.js +13 -0
  112. package/dist/contact/user-agent.d.ts +1 -0
  113. package/dist/contact/user-agent.js +35 -0
  114. package/dist/contact/user-data-hooks.d.ts +3 -0
  115. package/dist/contact/user-data-hooks.js +129 -0
  116. package/dist/contact/web/constants.d.ts +127 -0
  117. package/dist/contact/web/constants.js +126 -0
  118. package/dist/contact/web/index.d.ts +1 -0
  119. package/dist/contact/web/index.js +1 -0
  120. package/dist/crypto-shredding/handlers/forget-subject.write.js +5 -13
  121. package/dist/data-retention/feature.js +16 -2
  122. package/dist/data-retention/index.d.ts +1 -0
  123. package/dist/data-retention/index.js +1 -0
  124. package/dist/data-retention/run-retention-cleanup.d.ts +14 -2
  125. package/dist/data-retention/run-retention-cleanup.js +102 -36
  126. package/dist/data-retention/tenant-destruction-hold.d.ts +23 -0
  127. package/dist/data-retention/tenant-destruction-hold.js +132 -0
  128. package/dist/delivery/address-opt-out.js +1 -0
  129. package/dist/delivery/channel-context.d.ts +1 -1
  130. package/dist/delivery/channel-context.js +2 -1
  131. package/dist/delivery/delivery-service.js +18 -8
  132. package/dist/delivery/events.d.ts +1 -0
  133. package/dist/delivery/events.js +2 -0
  134. package/dist/delivery/feature.js +3 -0
  135. package/dist/delivery/handlers/attempts-by-keys.query.d.ts +15 -0
  136. package/dist/delivery/handlers/attempts-by-keys.query.js +35 -0
  137. package/dist/delivery/handlers/log.query.d.ts +1 -0
  138. package/dist/delivery/handlers/log.query.js +1 -1
  139. package/dist/delivery/jobs.js +5 -2
  140. package/dist/delivery/tables.js +12 -2
  141. package/dist/delivery/types.d.ts +2 -0
  142. package/dist/delivery/unsubscribe-page.js +2 -0
  143. package/dist/delivery/web/delivery-channel-cell.js +1 -1
  144. package/dist/delivery/web/delivery-error-cell.js +1 -1
  145. package/dist/delivery/web/delivery-status-cell.js +1 -1
  146. package/dist/delivery/web/delivery-time-cell.js +3 -2
  147. package/dist/delivery/web/delivery-type-cell.js +1 -1
  148. package/dist/delivery/web/public-names.d.ts +1 -0
  149. package/dist/delivery/web/public-names.js +1 -0
  150. package/dist/document-ingest-foundation/boot-checks.js +19 -11
  151. package/dist/document-ingest-foundation/boot-rules.d.ts +17 -0
  152. package/dist/document-ingest-foundation/boot-rules.js +17 -0
  153. package/dist/document-ingest-foundation/events.d.ts +8 -0
  154. package/dist/document-ingest-foundation/events.js +12 -0
  155. package/dist/document-ingest-foundation/feature.js +30 -2
  156. package/dist/document-ingest-foundation/index.d.ts +3 -1
  157. package/dist/document-ingest-foundation/index.js +3 -1
  158. package/dist/document-ingest-foundation/report-ingest-progress.d.ts +14 -0
  159. package/dist/document-ingest-foundation/report-ingest-progress.js +20 -0
  160. package/dist/document-ingest-foundation/tables.d.ts +3 -0
  161. package/dist/document-ingest-foundation/tables.js +26 -0
  162. package/dist/file-derivatives/handlers/public-variant-by-file-ref.query.js +1 -1
  163. package/dist/file-derivatives/handlers/public-variant.query.js +1 -1
  164. package/dist/files-tenant-data/hooks.js +4 -1
  165. package/dist/folders/web/folder-manager.js +3 -10
  166. package/dist/folders/web/folder-section.js +1 -1
  167. package/dist/form-draft-user-data/index.js +4 -1
  168. package/dist/inbound-mail-foundation/entities.d.ts +3 -0
  169. package/dist/inbound-mail-foundation/entities.js +2 -0
  170. package/dist/inbound-mail-foundation/events.d.ts +2 -0
  171. package/dist/inbound-mail-foundation/events.js +2 -0
  172. package/dist/inbound-mail-foundation/feature.js +6 -6
  173. package/dist/inbound-mail-foundation/handlers/attach-message-content.write.js +3 -1
  174. package/dist/inbound-mail-foundation/handlers/ingest-message.write.js +5 -0
  175. package/dist/inbound-mail-foundation/handlers/list-messages.query.js +4 -2
  176. package/dist/inbound-mail-foundation/handlers/message-content.d.ts +1 -0
  177. package/dist/inbound-mail-foundation/handlers/message-content.js +8 -0
  178. package/dist/inbound-mail-foundation/handlers/message-content.query.d.ts +2 -0
  179. package/dist/inbound-mail-foundation/handlers/message-content.query.js +1 -0
  180. package/dist/inbound-mail-foundation/projection.d.ts +3 -0
  181. package/dist/inbound-mail-foundation/projection.js +2 -0
  182. package/dist/inbound-mail-foundation/sanitize-inbound-html.d.ts +2 -0
  183. package/dist/inbound-mail-foundation/sanitize-inbound-html.js +135 -0
  184. package/dist/inbound-mail-foundation/types.js +1 -0
  185. package/dist/jobs/job-run-logger.js +16 -20
  186. package/dist/ledger/handlers/reports.query.js +25 -27
  187. package/dist/ledger/recurring.js +1 -0
  188. package/dist/managed-pages/handlers/branding.query.js +1 -1
  189. package/dist/managed-pages/handlers/by-slug.query.js +1 -1
  190. package/dist/managed-pages/handlers/by-tenant-published.query.js +1 -1
  191. package/dist/notes-history/web/notes-section.js +3 -2
  192. package/dist/personal-access-tokens/feature.js +5 -18
  193. package/dist/personal-access-tokens/handlers/create.write.js +2 -5
  194. package/dist/secrets/handlers/delete.write.d.ts +4 -0
  195. package/dist/secrets/handlers/delete.write.js +9 -4
  196. package/dist/secrets/handlers/list.query.d.ts +6 -1
  197. package/dist/secrets/handlers/list.query.js +7 -3
  198. package/dist/secrets/handlers/set.write.d.ts +4 -0
  199. package/dist/secrets/handlers/set.write.js +10 -4
  200. package/dist/secrets/secret-scope.d.ts +17 -0
  201. package/dist/secrets/secret-scope.js +18 -0
  202. package/dist/seo/handlers/seo-config.query.js +1 -1
  203. package/dist/sessions/feature.d.ts +3 -0
  204. package/dist/sessions/feature.js +13 -19
  205. package/dist/sessions/handlers/last-activity-probe.query.d.ts +7 -0
  206. package/dist/sessions/handlers/last-activity-probe.query.js +40 -0
  207. package/dist/sessions/handlers/last-activity-probe.route.d.ts +2 -0
  208. package/dist/sessions/handlers/last-activity-probe.route.js +30 -0
  209. package/dist/sessions/screens.js +1 -0
  210. package/dist/sessions/session-callbacks.d.ts +2 -0
  211. package/dist/sessions/session-callbacks.js +9 -7
  212. package/dist/sessions/web/i18n.js +4 -1
  213. package/dist/shared/assert-billing-live.d.ts +2 -0
  214. package/dist/shared/assert-billing-live.js +7 -0
  215. package/dist/shared/collect-extension-options.d.ts +1 -0
  216. package/dist/shared/collect-extension-options.js +8 -0
  217. package/dist/shared/index.d.ts +7 -1
  218. package/dist/shared/index.js +7 -1
  219. package/dist/shared/late-bound-slot.d.ts +5 -0
  220. package/dist/shared/late-bound-slot.js +13 -0
  221. package/dist/shared/mail-locale-templates.d.ts +1 -0
  222. package/dist/shared/mail-locale-templates.js +1 -1
  223. package/dist/shared/price-env-shape.d.ts +11 -0
  224. package/dist/shared/price-env-shape.js +15 -0
  225. package/dist/shared/purge-row-file-refs.d.ts +1 -0
  226. package/dist/shared/purge-row-file-refs.js +1 -1
  227. package/dist/shared/read-feature-export-fn.d.ts +2 -0
  228. package/dist/shared/read-feature-export-fn.js +11 -0
  229. package/dist/shared/signup-handover.js +3 -5
  230. package/dist/shared/tenant-destruction-hold.d.ts +23 -0
  231. package/dist/shared/tenant-destruction-hold.js +15 -0
  232. package/dist/shared/unprocessable.d.ts +4 -0
  233. package/dist/shared/unprocessable.js +4 -0
  234. package/dist/shared/web/index.d.ts +3 -0
  235. package/dist/shared/web/index.js +3 -0
  236. package/dist/subscription-paddle/checkout-config.query.js +1 -1
  237. package/dist/subscription-paddle/feature.d.ts +1 -5
  238. package/dist/subscription-paddle/feature.js +7 -9
  239. package/dist/subscription-paddle/runtime.js +3 -7
  240. package/dist/subscription-stripe/feature.d.ts +1 -5
  241. package/dist/subscription-stripe/feature.js +7 -9
  242. package/dist/subscription-stripe/runtime.js +3 -7
  243. package/dist/tags/entity.js +1 -0
  244. package/dist/tags/web/tag-chip.d.ts +7 -0
  245. package/dist/tags/web/tag-chip.js +4 -0
  246. package/dist/tags/web/tag-filter.js +2 -5
  247. package/dist/tags/web/tag-manager.js +1 -1
  248. package/dist/tags/web/tag-section.js +3 -6
  249. package/dist/tags/web/tags-cell.js +2 -5
  250. package/dist/template-resolver/compile-document-body.js +12 -17
  251. package/dist/template-resolver/handlers/by-slug.query.js +1 -1
  252. package/dist/template-resolver/handlers/by-tenant.query.js +4 -2
  253. package/dist/template-resolver/handlers/discard-draft.write.js +1 -0
  254. package/dist/template-resolver/handlers/overview.query.js +3 -1
  255. package/dist/template-resolver/handlers/send-test.write.js +2 -4
  256. package/dist/template-resolver/handlers/toggle-status.write.js +3 -0
  257. package/dist/template-resolver/linked-resources.js +6 -5
  258. package/dist/template-resolver/store-template-resource.js +5 -10
  259. package/dist/template-resolver/web/document-images.js +6 -6
  260. package/dist/template-resolver/web/document-insert-fields.js +22 -4
  261. package/dist/template-resolver/web/document-schema.js +11 -12
  262. package/dist/template-resolver/web/tiptap-attribute-parse-rule.d.ts +15 -0
  263. package/dist/template-resolver/web/tiptap-attribute-parse-rule.js +11 -0
  264. package/dist/tenant/i18n.js +3 -0
  265. package/dist/tenant/schema/tenant.d.ts +9 -7
  266. package/dist/tenant/schema/tenant.js +1 -0
  267. package/dist/tenant/web/member-roles-cell.js +1 -1
  268. package/dist/tenant/web/member-status-cell.js +1 -1
  269. package/dist/tenant-inactivity/check-inactive-tenants.d.ts +3 -0
  270. package/dist/tenant-inactivity/check-inactive-tenants.js +184 -0
  271. package/dist/tenant-inactivity/constants.d.ts +10 -0
  272. package/dist/tenant-inactivity/constants.js +10 -0
  273. package/dist/tenant-inactivity/email-templates.d.ts +3 -0
  274. package/dist/tenant-inactivity/email-templates.js +16 -0
  275. package/dist/tenant-inactivity/feature.d.ts +8 -0
  276. package/dist/tenant-inactivity/feature.js +45 -0
  277. package/dist/tenant-inactivity/handlers/inactivity-state.query.d.ts +11 -0
  278. package/dist/tenant-inactivity/handlers/inactivity-state.query.js +45 -0
  279. package/dist/tenant-inactivity/handlers/keep-account.write.d.ts +8 -0
  280. package/dist/tenant-inactivity/handlers/keep-account.write.js +51 -0
  281. package/dist/tenant-inactivity/inactivity-plan.d.ts +51 -0
  282. package/dist/tenant-inactivity/inactivity-plan.js +113 -0
  283. package/dist/tenant-inactivity/index.d.ts +5 -0
  284. package/dist/tenant-inactivity/index.js +3 -0
  285. package/dist/tenant-inactivity/keep-token.d.ts +16 -0
  286. package/dist/tenant-inactivity/keep-token.js +24 -0
  287. package/dist/tenant-inactivity/mail-notifications.d.ts +4 -0
  288. package/dist/tenant-inactivity/mail-notifications.js +42 -0
  289. package/dist/tenant-inactivity/options.d.ts +27 -0
  290. package/dist/tenant-inactivity/options.js +5 -0
  291. package/dist/tenant-inactivity/remote-activity.d.ts +15 -0
  292. package/dist/tenant-inactivity/remote-activity.js +24 -0
  293. package/dist/tenant-inactivity/state-store.d.ts +10 -0
  294. package/dist/tenant-inactivity/state-store.js +50 -0
  295. package/dist/tenant-inactivity/state-table.d.ts +109 -0
  296. package/dist/tenant-inactivity/state-table.js +38 -0
  297. package/dist/tenant-lifecycle/boot-checks.js +8 -3
  298. package/dist/tenant-lifecycle/boot-rules.d.ts +12 -0
  299. package/dist/tenant-lifecycle/boot-rules.js +12 -0
  300. package/dist/tenant-lifecycle/feature.js +17 -2
  301. package/dist/tenant-lifecycle/handlers/request-destruction.write.js +11 -67
  302. package/dist/tenant-lifecycle/index.d.ts +1 -0
  303. package/dist/tenant-lifecycle/index.js +1 -0
  304. package/dist/tenant-lifecycle/request-tenant-destruction.d.ts +20 -0
  305. package/dist/tenant-lifecycle/request-tenant-destruction.js +66 -0
  306. package/dist/tenant-lifecycle/retention-config-destroy-hooks.d.ts +5 -0
  307. package/dist/tenant-lifecycle/retention-config-destroy-hooks.js +29 -0
  308. package/dist/tenant-lifecycle/run-tenant-destroy.d.ts +3 -0
  309. package/dist/tenant-lifecycle/run-tenant-destroy.js +43 -5
  310. package/dist/tenant-lifecycle/stages.d.ts +2 -0
  311. package/dist/tenant-lifecycle/stages.js +23 -2
  312. package/dist/tenant-lifecycle/testing.js +1 -1
  313. package/dist/tier-engine/caps-for-tier-from-map.d.ts +5 -0
  314. package/dist/tier-engine/caps-for-tier-from-map.js +12 -0
  315. package/dist/tier-engine/compose-app.d.ts +0 -22
  316. package/dist/tier-engine/compose-app.js +9 -16
  317. package/dist/tier-engine/index.d.ts +1 -0
  318. package/dist/tier-engine/index.js +1 -0
  319. package/dist/user/handlers/detail.query.d.ts +1 -1
  320. package/dist/user-data-rights/feature.js +2 -0
  321. package/dist/user-data-rights/handlers/confirm-deletion-by-token.write.js +4 -1
  322. package/dist/user-data-rights/handlers/download-by-token.query.js +1 -0
  323. package/dist/user-data-rights/handlers/request-deletion-by-email.write.js +4 -1
  324. package/dist/user-data-rights/run-forget-cleanup.js +2 -0
  325. package/dist/user-data-rights/web/privacy-center-screen.js +1 -1
  326. package/dist/user-data-rights/zip-path.js +1 -0
  327. package/dist/user-data-rights-defaults/hooks/config-value.userdata-hook.d.ts +1 -1
  328. package/dist/user-data-rights-defaults/hooks/config-value.userdata-hook.js +7 -20
  329. package/dist/user-data-rights-defaults/hooks/delivery-attempt.userdata-hook.js +3 -1
  330. package/dist/user-data-rights-defaults/hooks/forget-own-rows-delete-hook.d.ts +10 -0
  331. package/dist/user-data-rights-defaults/hooks/forget-own-rows-delete-hook.js +26 -0
  332. package/dist/user-data-rights-defaults/hooks/notification-preference.userdata-hook.d.ts +1 -1
  333. package/dist/user-data-rights-defaults/hooks/notification-preference.userdata-hook.js +7 -20
  334. package/dist/user-profile/handlers/change-email.write.js +2 -4
  335. package/dist/user-profile/web/profile-screen.js +2 -3
  336. package/dist/waitlist/handlers/submit.write.js +1 -2
  337. package/kumiko-es-tables.json +12 -0
  338. package/package.json +54 -12
  339. package/src/admin-shell/changes.json +6 -0
  340. package/src/agent-tools/changes.json +6 -0
  341. package/src/channel-in-app/changes.json +7 -0
  342. package/src/contact/changes.json +33 -0
  343. package/src/data-retention/changes.json +6 -0
  344. package/src/delivery/changes.json +7 -0
  345. package/src/document-ingest-foundation/changes.json +6 -0
  346. package/src/files-tenant-data/changes.json +6 -0
  347. package/src/inbound-mail-foundation/changes.json +13 -0
  348. package/src/secrets/changes.json +6 -0
  349. package/src/sessions/changes.json +6 -0
  350. package/src/tenant-inactivity/changes.json +8 -0
  351. package/src/tenant-lifecycle/changes.json +18 -0
  352. package/src/tier-engine/changes.json +6 -0
  353. package/src/waitlist/changes.json +6 -0
@@ -0,0 +1,135 @@
1
+ // Allowlist sanitizer for the HTML part of an inbound mail. The result is stored in the event and
2
+ // shown by the reader inside a script-free sandboxed iframe; this is the first of the two layers.
3
+ import sanitizeHtml from "sanitize-html";
4
+ // Counted in UTF-8 bytes, not characters: the ciphertext grows with the bytes, and a CJK or emoji
5
+ // mail of 500,000 characters would encrypt past the event's bodyHtml maximum.
6
+ export const BODY_HTML_MAX_BYTES = 500_000;
7
+ const ALLOWED_TAGS = [
8
+ "p",
9
+ "br",
10
+ "div",
11
+ "span",
12
+ "a",
13
+ "b",
14
+ "strong",
15
+ "i",
16
+ "em",
17
+ "u",
18
+ "s",
19
+ "sub",
20
+ "sup",
21
+ "blockquote",
22
+ "pre",
23
+ "code",
24
+ "ul",
25
+ "ol",
26
+ "li",
27
+ "h1",
28
+ "h2",
29
+ "h3",
30
+ "h4",
31
+ "h5",
32
+ "h6",
33
+ "table",
34
+ "thead",
35
+ "tbody",
36
+ "tfoot",
37
+ "tr",
38
+ "td",
39
+ "th",
40
+ "img",
41
+ "hr",
42
+ "font",
43
+ "center",
44
+ ];
45
+ const ALLOWED_ATTRIBUTES = {
46
+ a: ["href", "title", "target", "rel"],
47
+ img: ["src", "alt", "width", "height"],
48
+ td: ["colspan", "rowspan", "align", "valign", "width"],
49
+ th: ["colspan", "rowspan", "align", "valign", "width"],
50
+ table: ["width", "cellpadding", "cellspacing", "border", "align"],
51
+ font: ["color", "size"],
52
+ div: ["class", "id"],
53
+ blockquote: ["class", "type"],
54
+ "*": ["style", "dir", "align"],
55
+ };
56
+ // Exactly the markers the reader's quote folding looks for (Gmail, Apple Mail, Thunderbird, Yahoo, Outlook).
57
+ const QUOTE_CLASS_NAMES = ["gmail_quote", "moz-cite-prefix", "yahoo_quoted"];
58
+ const QUOTE_ELEMENT_IDS = new Set(["divRplyFwdMsg", "appendonsend"]);
59
+ // A style value may carry a remote load (url(), @import) or legacy script (expression()).
60
+ const SAFE_STYLE_VALUE = /^(?!.*(?:url\s*\(|expression|@import|javascript:)).*$/i;
61
+ const STYLE_PROPERTIES = [
62
+ "color",
63
+ "background-color",
64
+ "font-weight",
65
+ "font-style",
66
+ "font-size",
67
+ "font-family",
68
+ "text-decoration",
69
+ "text-align",
70
+ "line-height",
71
+ "width",
72
+ "max-width",
73
+ "vertical-align",
74
+ ...["padding", "margin", "border"].flatMap((base) => [
75
+ base,
76
+ `${base}-top`,
77
+ `${base}-right`,
78
+ `${base}-bottom`,
79
+ `${base}-left`,
80
+ ]),
81
+ ];
82
+ const ALLOWED_STYLES = Object.fromEntries(STYLE_PROPERTIES.map((property) => [property, [SAFE_STYLE_VALUE]]));
83
+ // Relative, protocol-relative and backslash URLs would resolve against the app origin in the srcdoc frame
84
+ // and send a cookie-carrying same-origin request, so only absolute targets are kept.
85
+ const ABSOLUTE_IMAGE_SRC = /^https?:\/\//i;
86
+ const ABSOLUTE_LINK_HREF = /^(?:https?:\/\/|mailto:|tel:)/i;
87
+ function withoutAttributeUnless(attribs, name, allowed) {
88
+ const value = attribs[name];
89
+ if (value === undefined || allowed.test(value.trim()))
90
+ return attribs;
91
+ const { [name]: _dropped, ...rest } = attribs;
92
+ return rest;
93
+ }
94
+ function withoutIdUnlessQuoteMarker(attribs) {
95
+ const id = attribs["id"];
96
+ if (id === undefined || QUOTE_ELEMENT_IDS.has(id.trim()))
97
+ return attribs;
98
+ const { id: _dropped, ...rest } = attribs;
99
+ return rest;
100
+ }
101
+ export function sanitizeInboundHtml(html) {
102
+ const clean = sanitizeHtml(html, {
103
+ allowedTags: ALLOWED_TAGS,
104
+ allowedAttributes: ALLOWED_ATTRIBUTES,
105
+ allowedStyles: { "*": ALLOWED_STYLES },
106
+ allowedClasses: { div: QUOTE_CLASS_NAMES, blockquote: QUOTE_CLASS_NAMES },
107
+ allowedSchemes: ["http", "https", "mailto", "tel"],
108
+ allowedSchemesByTag: { img: ["http", "https"] },
109
+ allowProtocolRelative: false,
110
+ transformTags: {
111
+ div: (tagName, attribs) => ({ tagName, attribs: withoutIdUnlessQuoteMarker(attribs) }),
112
+ blockquote: (tagName, attribs) => ({
113
+ tagName,
114
+ attribs: withoutAttributeUnless(attribs, "type", /^cite$/),
115
+ }),
116
+ a: (tagName, attribs) => ({
117
+ tagName,
118
+ attribs: {
119
+ ...withoutAttributeUnless(attribs, "href", ABSOLUTE_LINK_HREF),
120
+ target: "_blank",
121
+ rel: "noopener noreferrer",
122
+ },
123
+ }),
124
+ img: (tagName, attribs) => ({
125
+ tagName,
126
+ attribs: withoutAttributeUnless(attribs, "src", ABSOLUTE_IMAGE_SRC),
127
+ }),
128
+ },
129
+ // An image whose src was stripped (cid:, data:, other scheme) is only a broken placeholder.
130
+ exclusiveFilter: (frame) => frame.tag === "img" && frame.attribs["src"] === undefined,
131
+ }).trim();
132
+ return clean.length === 0 || Buffer.byteLength(clean, "utf8") > BODY_HTML_MAX_BYTES
133
+ ? null
134
+ : clean;
135
+ }
@@ -13,6 +13,7 @@ import { INBOUND_MAIL_PROVIDER_EXTENSION } from "./constants.js";
13
13
  // `options` in the extension usage is an engine payload (unknown), so
14
14
  // validate its structure instead of casting blindly (patterned after
15
15
  // isMailTransportPlugin).
16
+ // guard:dup-ok type guard over this plugin's own two members; only the guard shape is shared
16
17
  export function isInboundMailProviderPlugin(o) {
17
18
  return (typeof o === "object" &&
18
19
  o !== null &&
@@ -268,43 +268,39 @@ async function dropTenantRunQueued(db, jobName, bullJobId, meta) {
268
268
  }));
269
269
  }
270
270
  const log = createFallbackLogger("job-run-logger");
271
- // The tenant run state is an optional side write: a throw here must not
272
- // fail the enqueue, skip the run-row write or turn a completed run into a
273
- // BullMQ retry. A row-level-security rejection is logged louder (a missing or wrong tenant scope), never rethrown.
274
- export async function isolateTenantRunWrite(write, jobName, bullJobId) {
271
+ async function isolateTenantWrite(write, jobName, bullJobId, messages) {
275
272
  try {
276
273
  await write();
277
274
  }
278
275
  catch (e) {
279
276
  if (isRowLevelSecurityViolation(e)) {
280
- log.error("tenant job run state write rejected by row level security: missing or wrong tenant scope", { jobName, bullJobId });
277
+ log.error(messages.rejected, { jobName, bullJobId });
281
278
  return;
282
279
  }
283
- log.error("tenant job run state write failed", {
280
+ log.error(messages.failed, {
284
281
  jobName,
285
282
  bullJobId,
286
283
  error: e instanceof Error ? e.message : String(e),
287
284
  });
288
285
  }
289
286
  }
287
+ // The tenant run state is an optional side write: a throw here must not
288
+ // fail the enqueue, skip the run-row write or turn a completed run into a
289
+ // BullMQ retry. A row-level-security rejection is logged louder (a missing or wrong tenant scope), never rethrown.
290
+ export async function isolateTenantRunWrite(write, jobName, bullJobId) {
291
+ await isolateTenantWrite(write, jobName, bullJobId, {
292
+ rejected: "tenant job run state write rejected by row level security: missing or wrong tenant scope",
293
+ failed: "tenant job run state write failed",
294
+ });
295
+ }
290
296
  // The tenant failure record is an optional side write: a throw here must not
291
297
  // skip the run-row update or turn a completed run into a BullMQ retry. A row-level-security rejection is
292
298
  // logged louder (a missing or wrong tenant scope), never rethrown.
293
299
  async function isolateTenantFailureWrite(write, jobName, bullJobId) {
294
- try {
295
- await write();
296
- }
297
- catch (e) {
298
- if (isRowLevelSecurityViolation(e)) {
299
- log.error("tenant job failure record write rejected by row level security: missing or wrong tenant scope", { jobName, bullJobId });
300
- return;
301
- }
302
- log.error("tenant job failure record write failed", {
303
- jobName,
304
- bullJobId,
305
- error: e instanceof Error ? e.message : String(e),
306
- });
307
- }
300
+ await isolateTenantWrite(write, jobName, bullJobId, {
301
+ rejected: "tenant job failure record write rejected by row level security: missing or wrong tenant scope",
302
+ failed: "tenant job failure record write failed",
303
+ });
308
304
  }
309
305
  export function createJobRunLogger(opts) {
310
306
  const { db } = opts;
@@ -13,45 +13,43 @@ async function loadBooks(ctx) {
13
13
  const txRows = await ctx.db.selectMany(transactionTable, { tenantId: ctx.user.tenantId });
14
14
  return { accounts: toAccounts(accountRows), entries: toEntries(txRows) };
15
15
  }
16
- // Per-account balances (natural sign) + the trial balance (Σ raw = 0 invariant).
17
- export function createBalancesReportHandler(access = DEFAULT_LEDGER_ACCESS) {
16
+ function createPeriodReportHandler(report, access) {
18
17
  return {
19
- name: "report:balances",
18
+ name: report.name,
20
19
  schema: periodSchema,
21
20
  access,
22
- description: "Returns the per-account balance in its natural sign plus the trial balance over an optional from/to period; use it for a trial balance or to read one account's standing.",
21
+ description: report.description,
23
22
  handler: async (query, ctx) => {
24
23
  const period = periodSchema.parse(query);
25
24
  const { accounts, entries } = await loadBooks(ctx);
26
- return accountBalances(accounts, entries, period);
25
+ return report.compute(accounts, entries, period);
27
26
  },
28
27
  };
29
28
  }
29
+ const BALANCES_REPORT = {
30
+ name: "report:balances",
31
+ description: "Returns the per-account balance in its natural sign plus the trial balance over an optional from/to period; use it for a trial balance or to read one account's standing.",
32
+ compute: accountBalances,
33
+ };
34
+ const INCOME_STATEMENT_REPORT = {
35
+ name: "report:income-statement",
36
+ description: "Returns income minus expense over an optional from/to period; use it for a profit-and-loss statement.",
37
+ compute: incomeStatement,
38
+ };
39
+ const BALANCE_SHEET_REPORT = {
40
+ name: "report:balance-sheet",
41
+ description: "Returns assets, liabilities and equity as of the optional `to` date with the period result folded into equity so the sheet balances; use it for a balance sheet at a point in time.",
42
+ compute: balanceSheet,
43
+ };
44
+ // Per-account balances (natural sign) + the trial balance (Σ raw = 0 invariant).
45
+ export function createBalancesReportHandler(access = DEFAULT_LEDGER_ACCESS) {
46
+ return createPeriodReportHandler(BALANCES_REPORT, access);
47
+ }
30
48
  // GuV — income − expense over the period.
31
49
  export function createIncomeStatementHandler(access = DEFAULT_LEDGER_ACCESS) {
32
- return {
33
- name: "report:income-statement",
34
- schema: periodSchema,
35
- access,
36
- description: "Returns income minus expense over an optional from/to period; use it for a profit-and-loss statement.",
37
- handler: async (query, ctx) => {
38
- const period = periodSchema.parse(query);
39
- const { accounts, entries } = await loadBooks(ctx);
40
- return incomeStatement(accounts, entries, period);
41
- },
42
- };
50
+ return createPeriodReportHandler(INCOME_STATEMENT_REPORT, access);
43
51
  }
44
52
  // Bilanz as of `to` — current result folded into equity so it balances.
45
53
  export function createBalanceSheetHandler(access = DEFAULT_LEDGER_ACCESS) {
46
- return {
47
- name: "report:balance-sheet",
48
- schema: periodSchema,
49
- access,
50
- description: "Returns assets, liabilities and equity as of the optional `to` date with the period result folded into equity so the sheet balances; use it for a balance sheet at a point in time.",
51
- handler: async (query, ctx) => {
52
- const period = periodSchema.parse(query);
53
- const { accounts, entries } = await loadBooks(ctx);
54
- return balanceSheet(accounts, entries, period);
55
- },
56
- };
54
+ return createPeriodReportHandler(BALANCE_SHEET_REPORT, access);
57
55
  }
@@ -35,6 +35,7 @@ function monthIndex(ym) {
35
35
  const [y, m] = ym.split("-");
36
36
  return Number(y) * 12 + (Number(m) - 1);
37
37
  }
38
+ // guard:dup-ok ledger month key YYYY-MM; look-alike month-index helpers return other formats
38
39
  function indexToMonth(index) {
39
40
  const year = Math.floor(index / 12);
40
41
  const month = (index % 12) + 1;
@@ -17,7 +17,7 @@ export function createBrandingQuery(opts) {
17
17
  return defineQueryHandler({
18
18
  name: "branding",
19
19
  schema: z.object({}),
20
- access: { roles: ["anonymous", "User", "TenantAdmin", "SystemAdmin"] },
20
+ access: { roles: ["anonymous", "User", "TenantAdmin", "SystemAdmin"], anySignedIn: true },
21
21
  rateLimit: { per: "ip+handler", limit: 60, windowSeconds: 60 },
22
22
  description: "Reads the tenant's public branding values for the rendered page shell, adding the raw custom CSS only when the app opted in and the per-tenant CSS toggle is on; anonymous callers may read it because it dresses public pages.",
23
23
  handler: async (_query, ctx) => {
@@ -14,7 +14,7 @@ export const bySlugQuery = defineQueryHandler({
14
14
  slug: z.string().min(1).max(64),
15
15
  lang: z.string().min(2).max(8),
16
16
  }),
17
- access: { roles: ["anonymous", "User", "TenantAdmin", "SystemAdmin"] },
17
+ access: { roles: ["anonymous", "User", "TenantAdmin", "SystemAdmin"], anySignedIn: true },
18
18
  rateLimit: { per: "ip+handler", limit: 60, windowSeconds: 60 },
19
19
  description: "Reads the body and metadata of one published managed page of the caller's tenant by slug and language, returning null for drafts and bodyless pages; use it to render a public page, not to load one for editing.",
20
20
  handler: async (query, ctx) => {
@@ -9,7 +9,7 @@ export const byTenantPublishedQuery = defineQueryHandler({
9
9
  * logic in by-slug.query. */
10
10
  tenantIdOverride: z.string().min(1).optional(),
11
11
  }),
12
- access: { roles: ["anonymous", "User", "TenantAdmin", "SystemAdmin"] },
12
+ access: { roles: ["anonymous", "User", "TenantAdmin", "SystemAdmin"], anySignedIn: true },
13
13
  rateLimit: { per: "ip+handler", limit: 60, windowSeconds: 60 },
14
14
  description: "Lists every published page of a tenant with slug, language, title and last-change time but no body; use it to enumerate the public pages for sitemap.xml or llms.txt, rather than by-slug which fetches one page's content.",
15
15
  handler: async (query, ctx) => {
@@ -10,7 +10,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
10
10
  // - extension: a screen-schema section with
11
11
  // component: { react: { __component: NOTES_SECTION_EXTENSION_NAME } }
12
12
  // (RenderEdit passes { entityName, entityId }).
13
- import { formatWhen, useDispatcher, usePrimitives, useQuery, useTranslation, } from "@cosmicdrift/kumiko-renderer";
13
+ import { formatWhen, useDispatcher, useLocale, usePrimitives, useQuery, useTranslation, } from "@cosmicdrift/kumiko-renderer";
14
14
  import { useState } from "react";
15
15
  import { NotesHistoryHandlers, NotesHistoryQueries } from "./constants.js";
16
16
  // Matches @cosmicdrift/kumiko-framework/crypto PII_ERASED_SENTINEL — cannot
@@ -22,6 +22,7 @@ function displayAuthorName(authorName, unknownLabel) {
22
22
  export function NotesSection({ entityName, entityId, }) {
23
23
  const { Banner, Button, Grid, Heading, Text, Input } = usePrimitives();
24
24
  const t = useTranslation();
25
+ const locale = useLocale().locale();
25
26
  const dispatcher = useDispatcher();
26
27
  const enabled = entityId !== null;
27
28
  const notes = useQuery(NotesHistoryQueries.noteList, {
@@ -85,6 +86,6 @@ export function NotesSection({ entityName, entityId, }) {
85
86
  addNote();
86
87
  } }), _jsxs("div", { className: "flex items-center justify-between gap-2", children: [_jsx(Text, { variant: "small", children: t("notesHistory.section.shortcutHint") }), _jsx(Button, { variant: "primary", disabled: busy || draft.trim() === "", onClick: () => addNote(), testId: "notes-section-add", children: busy ? t("notesHistory.section.working") : t("notesHistory.section.add") })] }), errorKey !== null && (_jsx(Banner, { variant: "error", testId: "notes-section-action-error", children: _jsx(Text, { children: t(errorKey) }) }))] }), _jsxs("div", { className: "flex flex-col gap-3", "data-testid": "notes-section-history", children: [_jsx(Heading, { variant: "section", children: t("notesHistory.section.historyTitle") }), rows.length === 0 ? (_jsx(Text, { variant: "small", children: t("notesHistory.section.empty") })) : (_jsx("div", { className: "flex flex-col divide-y", children: rows.map((n) => (_jsxs("div", { "data-testid": `notes-section-row-${n.id}`, className: "flex flex-col gap-1 py-3 first:pt-0 last:pb-0", children: [_jsx(Text, { testId: `notes-section-body-${n.id}`, children: n.body }), _jsx(Text, { variant: "small", testId: `notes-section-meta-${n.id}`, children: t("notesHistory.section.meta", {
87
88
  author: displayAuthorName(n.authorName, t("notesHistory.section.authorUnknown")),
88
- date: formatWhen(n.insertedAt),
89
+ date: formatWhen(n.insertedAt, locale),
89
90
  }) })] }, n.id))) }))] })] }));
90
91
  }
@@ -2,6 +2,7 @@ import { EXT_TOKEN_VERIFIER, } from "@cosmicdrift/kumiko-bundled-features/auth-f
2
2
  import { PAT_TOKEN_PREFIX } from "@cosmicdrift/kumiko-framework/api";
3
3
  import { deriveEntityTableMeta } from "@cosmicdrift/kumiko-framework/db";
4
4
  import { defineFeature, } from "@cosmicdrift/kumiko-framework/engine";
5
+ import { createLateBoundSlot, readFeatureExportFn } from "../shared/index.js";
5
6
  import { availabilityQuery } from "./handlers/availability.query.js";
6
7
  import { buildAvailableScopesQuery } from "./handlers/available-scopes.query.js";
7
8
  import { createPatCreateHandler } from "./handlers/create.write.js";
@@ -23,15 +24,7 @@ const PAT_REVOKE_TRIGGERING_FIELDS = ["passwordHash"];
23
24
  // exports — run{Prod,Dev}App call this once a concrete db is available,
24
25
  // mirrors sessions' own bindAutoRevokeFromFeature/bindAutoRevokeOnPasswordChange.
25
26
  export function bindPatAutoRevokeOnPasswordChangeFromFeature(feature) {
26
- const exports = feature.exports;
27
- if (exports && typeof exports === "object" && "bindAutoRevokeOnPasswordChange" in exports) {
28
- const { bindAutoRevokeOnPasswordChange } = exports;
29
- if (typeof bindAutoRevokeOnPasswordChange === "function") {
30
- // @cast-boundary feature-exports — feature.exports is untyped by design
31
- return bindAutoRevokeOnPasswordChange;
32
- }
33
- }
34
- return undefined;
27
+ return readFeatureExportFn(feature, "bindAutoRevokeOnPasswordChange");
35
28
  }
36
29
  // Personal Access Tokens — long-lived, revocable bearer credentials for the
37
30
  // HTTP API. Like `sessions`, the hot-path resolver is NOT a handler: it runs on
@@ -85,12 +78,12 @@ export function createPersonalAccessTokensFeature(options) {
85
78
  // run{Prod,Dev}App has a real db handle.
86
79
  // Explicit option wins; the runtime binding is replaceable so a second boot of the same
87
80
  // feature instance binds its own database.
88
- let boundAutoRevoke;
81
+ const autoRevokeSlot = createLateBoundSlot();
89
82
  r.hook({
90
83
  type: "postSave",
91
84
  target: { allOf: "user" },
92
85
  handler: async (result) => {
93
- const autoRevokeOnPasswordChange = options.autoRevokeOnPasswordChange ?? boundAutoRevoke;
86
+ const autoRevokeOnPasswordChange = options.autoRevokeOnPasswordChange ?? autoRevokeSlot.current();
94
87
  // skip: nothing bound — same late-bind pattern as sessions/feature.ts
95
88
  if (!autoRevokeOnPasswordChange)
96
89
  return;
@@ -104,13 +97,7 @@ export function createPersonalAccessTokensFeature(options) {
104
97
  await autoRevokeOnPasswordChange(String(result.id));
105
98
  },
106
99
  });
107
- const bindAutoRevokeOnPasswordChange = (revoker) => {
108
- boundAutoRevoke = revoker;
109
- return () => {
110
- if (boundAutoRevoke === revoker)
111
- boundAutoRevoke = undefined;
112
- };
113
- };
100
+ const bindAutoRevokeOnPasswordChange = autoRevokeSlot.bind;
114
101
  const handlers = {
115
102
  create: r.writeHandler(createPatCreateHandler({ mfaVerifier: options.mfaVerifier })),
116
103
  revoke: r.writeHandler(revokePatWrite),
@@ -1,19 +1,16 @@
1
1
  import { insertOne } from "@cosmicdrift/kumiko-framework/db";
2
2
  import { createSystemUser, defineWriteHandler, } from "@cosmicdrift/kumiko-framework/engine";
3
- import { UnprocessableError, writeFailure } from "@cosmicdrift/kumiko-framework/errors";
4
3
  import { generateId } from "@cosmicdrift/kumiko-framework/utils";
5
4
  import { Temporal } from "@cosmicdrift/kumiko-types/temporal";
6
5
  import * as z from "zod";
7
- import { encryptForDirectWrite, verifyPassword } from "../../shared/index.js";
6
+ import { encryptForDirectWrite, unprocessable, verifyPassword } from "../../shared/index.js";
8
7
  import { UserQueries } from "../../user/index.js";
9
8
  import { mintPatToken } from "../hash.js";
10
9
  import { apiTokenEntity, apiTokenTable } from "../schema/api-token.js";
11
10
  import { API_TOKEN_ENTITY_NAME, PAT_DEFAULT_EXPIRES_IN_DAYS, PatErrors } from "../web/constants.js";
12
11
  // @wrapper-known error-helper
13
12
  function reauthFailed() {
14
- return writeFailure(new UnprocessableError(PatErrors.reauthRequired, {
15
- i18nKey: "errors.reauthRequired",
16
- }));
13
+ return unprocessable(PatErrors.reauthRequired, "errors.reauthRequired");
17
14
  }
18
15
  // Mint a PAT for the calling user in their active tenant. The plaintext token
19
16
  // is returned ONCE (data.token) and never again — only the hash is stored.
@@ -2,6 +2,10 @@ import { type AccessRule } from "@cosmicdrift/kumiko-framework/engine";
2
2
  import * as z from "zod";
3
3
  export declare function createDeleteHandler(access?: AccessRule): import("@cosmicdrift/kumiko-types/define-handler").WriteHandlerDefinition<"delete", z.ZodObject<{
4
4
  key: z.ZodString;
5
+ scope: z.ZodOptional<z.ZodEnum<{
6
+ system: "system";
7
+ tenant: "tenant";
8
+ }>>;
5
9
  }, z.core.$strip>, {
6
10
  key: string;
7
11
  }, import("@cosmicdrift/kumiko-types/event-type-map").KumikoEventTypeMap, undefined, undefined>;
@@ -1,33 +1,38 @@
1
1
  import { defineWriteHandler } from "@cosmicdrift/kumiko-framework/engine";
2
- import { failNotFound } from "@cosmicdrift/kumiko-framework/errors";
2
+ import { failNotFound, writeFailure } from "@cosmicdrift/kumiko-framework/errors";
3
3
  import * as z from "zod";
4
4
  import { announceSecretChange } from "../announce-secret-change.js";
5
5
  import { JOIN_REQUEST_TRANSACTION_REASON, requireSecretsContext } from "../feature.js";
6
+ import { resolveSecretTarget, secretScopeSchema } from "../secret-scope.js";
6
7
  import { DEFAULT_SECRETS_ACCESS, SecretsHandlers } from "../web/constants.js";
7
8
  import { checkSecretKeyWrite } from "../write-gate.js";
8
9
  export function createDeleteHandler(access = DEFAULT_SECRETS_ACCESS) {
9
10
  return defineWriteHandler({
10
11
  name: "delete",
11
- description: "Permanently removes the stored secret under the given key for the caller's tenant, breaking every feature that depends on that credential.",
12
+ description: "Permanently removes the stored secret under the given key for the caller's tenant (or, with scope system and the SystemAdmin role, the platform-wide one), breaking every feature that depends on that credential.",
12
13
  agent: { risk: "high" },
13
14
  schema: z.object({
14
15
  key: z.string().min(1).max(100),
16
+ scope: secretScopeSchema,
15
17
  }),
16
18
  access,
17
19
  escapeHatch: { grants: ["unsafeRaw"], reason: JOIN_REQUEST_TRANSACTION_REASON },
18
20
  handler: async (event, ctx) => {
19
21
  const secrets = requireSecretsContext({ secrets: ctx.services.secrets, user: ctx.user }, SecretsHandlers.delete).withRunner(ctx.db.unsafeRaw());
22
+ const target = resolveSecretTarget(event.user, event.payload.scope);
23
+ if (!target.ok)
24
+ return writeFailure(target.error);
20
25
  const gate = checkSecretKeyWrite(ctx.registry, event.user.roles, event.payload.key, {
21
26
  allowUndeclared: true,
22
27
  });
23
28
  if (!gate.ok)
24
29
  return gate.failure;
25
- const removed = await secrets.delete(event.user.tenantId, event.payload.key, {
30
+ const removed = await secrets.delete(target.tenantId, event.payload.key, {
26
31
  deletedBy: event.user.id,
27
32
  });
28
33
  if (!removed)
29
34
  return failNotFound("tenant-secret", event.payload.key);
30
- announceSecretChange(ctx, event.user.tenantId, event.payload.key);
35
+ announceSecretChange(ctx, target.tenantId, event.payload.key);
31
36
  return { isSuccess: true, data: { key: event.payload.key } };
32
37
  },
33
38
  });
@@ -1,6 +1,11 @@
1
1
  import { type AccessRule } from "@cosmicdrift/kumiko-framework/engine";
2
2
  import * as z from "zod";
3
- export declare function createListHandler(access?: AccessRule): import("@cosmicdrift/kumiko-types/define-handler").QueryHandlerDefinition<"list", z.ZodObject<{}, z.core.$strip>, {
3
+ export declare function createListHandler(access?: AccessRule): import("@cosmicdrift/kumiko-types/define-handler").QueryHandlerDefinition<"list", z.ZodObject<{
4
+ scope: z.ZodOptional<z.ZodEnum<{
5
+ system: "system";
6
+ tenant: "tenant";
7
+ }>>;
8
+ }, z.core.$strip>, {
4
9
  key: string;
5
10
  redactedPreview: string | null;
6
11
  hint: string | null;
@@ -1,5 +1,6 @@
1
1
  import { defineQueryHandler } from "@cosmicdrift/kumiko-framework/engine";
2
2
  import * as z from "zod";
3
+ import { resolveSecretTarget, secretScopeSchema } from "../secret-scope.js";
3
4
  import { tenantSecretsTable } from "../table.js";
4
5
  import { DEFAULT_SECRETS_ACCESS } from "../web/constants.js";
5
6
  // Lists all secrets for the current tenant. Returns redactedPreview, never
@@ -8,11 +9,14 @@ import { DEFAULT_SECRETS_ACCESS } from "../web/constants.js";
8
9
  export function createListHandler(access = DEFAULT_SECRETS_ACCESS) {
9
10
  return defineQueryHandler({
10
11
  name: "list",
11
- description: "Lists the secrets stored for the caller's tenant by key with a redacted preview, hint, key version and rotation date — never the plaintext; use it to check which credentials are set.",
12
- schema: z.object({}),
12
+ description: "Lists the secrets stored for the caller's tenant (or, with scope system and the SystemAdmin role, the platform-wide ones) by key with a redacted preview, hint, key version and rotation date — never the plaintext; use it to check which credentials are set.",
13
+ schema: z.object({ scope: secretScopeSchema }),
13
14
  access,
14
15
  handler: async (event, ctx) => {
15
- const rows = await ctx.db.selectMany(tenantSecretsTable, { tenantId: event.user.tenantId }, {
16
+ const target = resolveSecretTarget(event.user, event.payload.scope);
17
+ if (!target.ok)
18
+ throw target.error;
19
+ const rows = await ctx.db.selectMany(tenantSecretsTable, { tenantId: target.tenantId }, {
16
20
  orderBy: { col: "key", direction: "asc" },
17
21
  });
18
22
  return rows.map((r) => ({
@@ -5,6 +5,10 @@ export declare function createSetHandler(access?: AccessRule): import("@cosmicdr
5
5
  value: z.ZodString;
6
6
  redactedPreview: z.ZodOptional<z.ZodString>;
7
7
  hint: z.ZodOptional<z.ZodString>;
8
+ scope: z.ZodOptional<z.ZodEnum<{
9
+ system: "system";
10
+ tenant: "tenant";
11
+ }>>;
8
12
  }, z.core.$strip>, {
9
13
  key: string;
10
14
  redactedPreview: string;
@@ -1,13 +1,15 @@
1
1
  import { defineWriteHandler } from "@cosmicdrift/kumiko-framework/engine";
2
+ import { writeFailure } from "@cosmicdrift/kumiko-framework/errors";
2
3
  import * as z from "zod";
3
4
  import { announceSecretChange } from "../announce-secret-change.js";
4
5
  import { JOIN_REQUEST_TRANSACTION_REASON, requireSecretsContext } from "../feature.js";
6
+ import { resolveSecretTarget, secretScopeSchema } from "../secret-scope.js";
5
7
  import { DEFAULT_SECRETS_ACCESS, SecretsHandlers } from "../web/constants.js";
6
8
  import { checkSecretKeyWrite, checkSecretValue } from "../write-gate.js";
7
9
  export function createSetHandler(access = DEFAULT_SECRETS_ACCESS) {
8
10
  return defineWriteHandler({
9
11
  name: "set",
10
- description: "Stores or replaces one encrypted secret for the caller's tenant under the given key, together with a redacted preview and optional hint; use it to enter or rotate a credential.",
12
+ description: "Stores or replaces one encrypted secret for the caller's tenant (or, with scope system and the SystemAdmin role, the platform-wide one) under the given key, together with a redacted preview and optional hint; use it to enter or rotate a credential.",
11
13
  // `value` is the plaintext credential: as a tool call it would travel to
12
14
  // the model provider before it is ever encrypted at rest.
13
15
  agent: { expose: false },
@@ -19,12 +21,16 @@ export function createSetHandler(access = DEFAULT_SECRETS_ACCESS) {
19
21
  // handler derives a generic one (first-3-chars + bullets).
20
22
  redactedPreview: z.string().max(50).optional(),
21
23
  hint: z.string().max(200).optional(),
24
+ scope: secretScopeSchema,
22
25
  }),
23
26
  access,
24
27
  escapeHatch: { grants: ["unsafeRaw"], reason: JOIN_REQUEST_TRANSACTION_REASON },
25
28
  handler: async (event, ctx) => {
26
29
  const secrets = requireSecretsContext({ secrets: ctx.services.secrets, user: ctx.user }, SecretsHandlers.set).withRunner(ctx.db.unsafeRaw());
27
- const { key, value, redactedPreview, hint } = event.payload;
30
+ const { key, value, redactedPreview, hint, scope } = event.payload;
31
+ const target = resolveSecretTarget(event.user, scope);
32
+ if (!target.ok)
33
+ return writeFailure(target.error);
28
34
  // Preview-priority: explicit payload param > feature-declared redact
29
35
  // (via r.secret()) > generic default. A feature that declared a
30
36
  // domain-aware redact (Stripe keys: "sk_test...2345") wins over the
@@ -39,12 +45,12 @@ export function createSetHandler(access = DEFAULT_SECRETS_ACCESS) {
39
45
  const redactFn = redactedPreview
40
46
  ? () => redactedPreview
41
47
  : (featureRedact ?? defaultRedact);
42
- await secrets.set(event.user.tenantId, key, value, {
48
+ await secrets.set(target.tenantId, key, value, {
43
49
  redact: redactFn,
44
50
  ...(hint ? { hint } : {}),
45
51
  updatedBy: event.user.id,
46
52
  });
47
- announceSecretChange(ctx, event.user.tenantId, key);
53
+ announceSecretChange(ctx, target.tenantId, key);
48
54
  return {
49
55
  isSuccess: true,
50
56
  data: { key, redactedPreview: redactedPreview ?? redactFn(value) },
@@ -0,0 +1,17 @@
1
+ import { type SessionUser, type TenantId } from "@cosmicdrift/kumiko-framework/engine";
2
+ import { AccessDeniedError } from "@cosmicdrift/kumiko-framework/errors";
3
+ import * as z from "zod";
4
+ export declare const SYSTEM_ADMIN_ROLE = "SystemAdmin";
5
+ export declare const secretScopeSchema: z.ZodOptional<z.ZodEnum<{
6
+ system: "system";
7
+ tenant: "tenant";
8
+ }>>;
9
+ export type SecretScope = z.infer<typeof secretScopeSchema>;
10
+ export type SecretTarget = {
11
+ readonly ok: true;
12
+ readonly tenantId: TenantId;
13
+ } | {
14
+ readonly ok: false;
15
+ readonly error: AccessDeniedError;
16
+ };
17
+ export declare function resolveSecretTarget(user: Pick<SessionUser, "tenantId" | "roles">, scope: SecretScope): SecretTarget;
@@ -0,0 +1,18 @@
1
+ import { SYSTEM_TENANT_ID, } from "@cosmicdrift/kumiko-framework/engine";
2
+ import { AccessDeniedError } from "@cosmicdrift/kumiko-framework/errors";
3
+ import * as z from "zod";
4
+ export const SYSTEM_ADMIN_ROLE = "SystemAdmin";
5
+ // "system" targets the platform-wide secrets under SYSTEM_TENANT_ID (settings a SystemAdmin
6
+ // edits for the whole app). The target is never taken from the payload, only chosen here.
7
+ export const secretScopeSchema = z.enum(["tenant", "system"]).optional();
8
+ export function resolveSecretTarget(user, scope) {
9
+ if (scope !== "system")
10
+ return { ok: true, tenantId: user.tenantId };
11
+ if (!user.roles.includes(SYSTEM_ADMIN_ROLE)) {
12
+ return {
13
+ ok: false,
14
+ error: new AccessDeniedError({ message: "system-scope secrets need the SystemAdmin role" }),
15
+ };
16
+ }
17
+ return { ok: true, tenantId: SYSTEM_TENANT_ID };
18
+ }
@@ -16,7 +16,7 @@ import { SEO_CONFIG_QN } from "../constants.js";
16
16
  export const seoConfigQuery = defineQueryHandler({
17
17
  name: "config",
18
18
  schema: z.object({}),
19
- access: { roles: ["anonymous", "User", "TenantAdmin", "SystemAdmin"] },
19
+ access: { roles: ["anonymous", "User", "TenantAdmin", "SystemAdmin"], anySignedIn: true },
20
20
  rateLimit: { per: "ip+handler", limit: 60, windowSeconds: 60 },
21
21
  description: "Reads the tenant's SEO metadata settings — organization name and logo URL, Twitter site handle, LLMs summary and default OG image — as plain strings; use it to inspect what the sitemap, llms.txt and page meta tags will publish.",
22
22
  handler: async (_query, ctx) => {
@@ -1,9 +1,12 @@
1
1
  import { type FeatureDefinition } from "@cosmicdrift/kumiko-framework/engine";
2
+ import type { Clock } from "@cosmicdrift/kumiko-types/tz-context";
2
3
  import { type SessionAllOthersRevoker, type SessionMassRevoker } from "./session-callbacks.ts";
3
4
  export type SessionsFeatureOptions = {
4
5
  readonly autoRevokeOnPasswordChange?: SessionMassRevoker;
5
6
  readonly expiresInMs?: number;
6
7
  readonly adminAccess?: "admin" | "systemAdmin";
8
+ readonly clock?: Clock;
9
+ readonly lastActivityProbeSecret?: string;
7
10
  };
8
11
  export type BindAutoRevokeOnPasswordChange = (revoker: SessionMassRevoker) => () => void;
9
12
  export type BindRevokeAllOtherSessions = (revoker: SessionAllOthersRevoker) => () => void;