@cosmicdrift/kumiko-bundled-features 0.406.0 → 0.409.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 (333) 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/web/auth-client.d.ts +8 -32
  11. package/dist/auth-email-password/web/auth-client.js +18 -52
  12. package/dist/auth-email-password/web/auth-redirect.js +2 -2
  13. package/dist/auth-email-password/web/confirm-account-unlock-screen.d.ts +2 -2
  14. package/dist/auth-email-password/web/confirm-account-unlock-screen.js +14 -35
  15. package/dist/auth-email-password/web/index.d.ts +1 -0
  16. package/dist/auth-email-password/web/index.js +1 -0
  17. package/dist/auth-email-password/web/read-path-param.d.ts +1 -0
  18. package/dist/auth-email-password/web/read-path-param.js +4 -0
  19. package/dist/auth-email-password/web/return-path.js +2 -2
  20. package/dist/auth-email-password/web/token-confirm-screen.d.ts +20 -0
  21. package/dist/auth-email-password/web/token-confirm-screen.js +38 -0
  22. package/dist/auth-email-password/web/verify-email-screen.d.ts +2 -2
  23. package/dist/auth-email-password/web/verify-email-screen.js +14 -37
  24. package/dist/auth-foundation/boot-checks.js +24 -12
  25. package/dist/auth-foundation/boot-rules.d.ts +27 -0
  26. package/dist/auth-foundation/boot-rules.js +27 -0
  27. package/dist/auth-mfa/errors.d.ts +1 -1
  28. package/dist/auth-mfa/errors.js +11 -24
  29. package/dist/auth-mfa/feature-exports.js +6 -45
  30. package/dist/auth-mfa/feature.js +7 -18
  31. package/dist/auth-mfa/web/mfa-client.js +11 -25
  32. package/dist/billing-foundation/consumer-protection/termination-notify.js +1 -0
  33. package/dist/billing-foundation/web/plan-price.js +7 -8
  34. package/dist/cap-counter/stock-cap-guard.js +1 -0
  35. package/dist/channel-in-app/constants.d.ts +1 -0
  36. package/dist/channel-in-app/feature.js +2 -0
  37. package/dist/channel-in-app/handlers/read-state-by-keys.query.d.ts +9 -0
  38. package/dist/channel-in-app/handlers/read-state-by-keys.query.js +21 -0
  39. package/dist/channel-in-app/in-app-channel.js +1 -0
  40. package/dist/channel-in-app/tables.js +5 -1
  41. package/dist/contact/challenge.d.ts +14 -0
  42. package/dist/contact/challenge.js +30 -0
  43. package/dist/contact/client/contact-client-source.d.ts +1 -0
  44. package/dist/contact/client/contact-client-source.js +203 -0
  45. package/dist/contact/entity.d.ts +777 -0
  46. package/dist/contact/entity.js +145 -0
  47. package/dist/contact/feature.d.ts +3 -0
  48. package/dist/contact/feature.js +130 -0
  49. package/dist/contact/handlers/access.d.ts +7 -0
  50. package/dist/contact/handlers/access.js +9 -0
  51. package/dist/contact/handlers/attempts.d.ts +14 -0
  52. package/dist/contact/handlers/attempts.js +54 -0
  53. package/dist/contact/handlers/challenge.query.d.ts +9 -0
  54. package/dist/contact/handlers/challenge.query.js +35 -0
  55. package/dist/contact/handlers/forward-request.write.d.ts +9 -0
  56. package/dist/contact/handlers/forward-request.write.js +61 -0
  57. package/dist/contact/handlers/mark-done.write.d.ts +7 -0
  58. package/dist/contact/handlers/mark-done.write.js +30 -0
  59. package/dist/contact/handlers/notify-reporter-in-app.write.d.ts +10 -0
  60. package/dist/contact/handlers/notify-reporter-in-app.write.js +36 -0
  61. package/dist/contact/handlers/open-count.d.ts +2 -0
  62. package/dist/contact/handlers/open-count.js +11 -0
  63. package/dist/contact/handlers/open-count.query.d.ts +3 -0
  64. package/dist/contact/handlers/open-count.query.js +13 -0
  65. package/dist/contact/handlers/replies.query.d.ts +11 -0
  66. package/dist/contact/handlers/replies.query.js +28 -0
  67. package/dist/contact/handlers/reply.write.d.ts +12 -0
  68. package/dist/contact/handlers/reply.write.js +118 -0
  69. package/dist/contact/handlers/report.write.d.ts +16 -0
  70. package/dist/contact/handlers/report.write.js +90 -0
  71. package/dist/contact/handlers/request-delivery.query.d.ts +16 -0
  72. package/dist/contact/handlers/request-delivery.query.js +85 -0
  73. package/dist/contact/handlers/request-detail.query.d.ts +41 -0
  74. package/dist/contact/handlers/request-detail.query.js +32 -0
  75. package/dist/contact/handlers/request-list.query.d.ts +2 -0
  76. package/dist/contact/handlers/request-list.query.js +9 -0
  77. package/dist/contact/handlers/send-reply-mail.write.d.ts +8 -0
  78. package/dist/contact/handlers/send-reply-mail.write.js +82 -0
  79. package/dist/contact/handlers/send-test.write.d.ts +5 -0
  80. package/dist/contact/handlers/send-test.write.js +36 -0
  81. package/dist/contact/handlers/submit.write.d.ts +20 -0
  82. package/dist/contact/handlers/submit.write.js +137 -0
  83. package/dist/contact/handlers/take-over-uploads.d.ts +9 -0
  84. package/dist/contact/handlers/take-over-uploads.js +33 -0
  85. package/dist/contact/i18n.d.ts +6 -0
  86. package/dist/contact/i18n.js +186 -0
  87. package/dist/contact/index.d.ts +5 -0
  88. package/dist/contact/index.js +4 -0
  89. package/dist/contact/lib.d.ts +101 -0
  90. package/dist/contact/lib.js +109 -0
  91. package/dist/contact/mail.d.ts +91 -0
  92. package/dist/contact/mail.js +279 -0
  93. package/dist/contact/options.d.ts +51 -0
  94. package/dist/contact/options.js +32 -0
  95. package/dist/contact/panels.d.ts +2 -0
  96. package/dist/contact/panels.js +21 -0
  97. package/dist/contact/payloads.d.ts +56 -0
  98. package/dist/contact/payloads.js +82 -0
  99. package/dist/contact/pow.d.ts +6 -0
  100. package/dist/contact/pow.js +19 -0
  101. package/dist/contact/screens.d.ts +5 -0
  102. package/dist/contact/screens.js +464 -0
  103. package/dist/contact/subject.d.ts +1 -0
  104. package/dist/contact/subject.js +13 -0
  105. package/dist/contact/user-agent.d.ts +1 -0
  106. package/dist/contact/user-agent.js +35 -0
  107. package/dist/contact/user-data-hooks.d.ts +3 -0
  108. package/dist/contact/user-data-hooks.js +129 -0
  109. package/dist/contact/web/constants.d.ts +127 -0
  110. package/dist/contact/web/constants.js +126 -0
  111. package/dist/contact/web/index.d.ts +1 -0
  112. package/dist/contact/web/index.js +1 -0
  113. package/dist/crypto-shredding/handlers/forget-subject.write.js +5 -13
  114. package/dist/data-retention/feature.js +16 -2
  115. package/dist/data-retention/index.d.ts +1 -0
  116. package/dist/data-retention/index.js +1 -0
  117. package/dist/data-retention/run-retention-cleanup.d.ts +14 -2
  118. package/dist/data-retention/run-retention-cleanup.js +102 -36
  119. package/dist/data-retention/tenant-destruction-hold.d.ts +23 -0
  120. package/dist/data-retention/tenant-destruction-hold.js +132 -0
  121. package/dist/delivery/address-opt-out.js +1 -0
  122. package/dist/delivery/channel-context.d.ts +1 -1
  123. package/dist/delivery/channel-context.js +2 -1
  124. package/dist/delivery/delivery-service.js +18 -8
  125. package/dist/delivery/events.d.ts +1 -0
  126. package/dist/delivery/events.js +2 -0
  127. package/dist/delivery/feature.js +3 -0
  128. package/dist/delivery/handlers/attempts-by-keys.query.d.ts +15 -0
  129. package/dist/delivery/handlers/attempts-by-keys.query.js +35 -0
  130. package/dist/delivery/handlers/log.query.d.ts +1 -0
  131. package/dist/delivery/handlers/log.query.js +1 -1
  132. package/dist/delivery/jobs.js +5 -2
  133. package/dist/delivery/tables.js +12 -2
  134. package/dist/delivery/types.d.ts +2 -0
  135. package/dist/delivery/unsubscribe-page.js +2 -0
  136. package/dist/delivery/web/delivery-channel-cell.js +1 -1
  137. package/dist/delivery/web/delivery-error-cell.js +1 -1
  138. package/dist/delivery/web/delivery-status-cell.js +1 -1
  139. package/dist/delivery/web/delivery-time-cell.js +3 -2
  140. package/dist/delivery/web/delivery-type-cell.js +1 -1
  141. package/dist/delivery/web/public-names.d.ts +1 -0
  142. package/dist/delivery/web/public-names.js +1 -0
  143. package/dist/document-ingest-foundation/boot-checks.js +19 -11
  144. package/dist/document-ingest-foundation/boot-rules.d.ts +17 -0
  145. package/dist/document-ingest-foundation/boot-rules.js +17 -0
  146. package/dist/document-ingest-foundation/events.d.ts +8 -0
  147. package/dist/document-ingest-foundation/events.js +12 -0
  148. package/dist/document-ingest-foundation/feature.js +30 -2
  149. package/dist/document-ingest-foundation/index.d.ts +3 -1
  150. package/dist/document-ingest-foundation/index.js +3 -1
  151. package/dist/document-ingest-foundation/report-ingest-progress.d.ts +14 -0
  152. package/dist/document-ingest-foundation/report-ingest-progress.js +20 -0
  153. package/dist/document-ingest-foundation/tables.d.ts +3 -0
  154. package/dist/document-ingest-foundation/tables.js +26 -0
  155. package/dist/files-tenant-data/hooks.js +4 -1
  156. package/dist/folders/web/folder-manager.js +3 -10
  157. package/dist/folders/web/folder-section.js +1 -1
  158. package/dist/form-draft-user-data/index.js +4 -1
  159. package/dist/inbound-mail-foundation/entities.d.ts +3 -0
  160. package/dist/inbound-mail-foundation/entities.js +2 -0
  161. package/dist/inbound-mail-foundation/events.d.ts +2 -0
  162. package/dist/inbound-mail-foundation/events.js +2 -0
  163. package/dist/inbound-mail-foundation/feature.js +6 -6
  164. package/dist/inbound-mail-foundation/handlers/attach-message-content.write.js +3 -1
  165. package/dist/inbound-mail-foundation/handlers/ingest-message.write.js +5 -0
  166. package/dist/inbound-mail-foundation/handlers/list-messages.query.js +4 -2
  167. package/dist/inbound-mail-foundation/handlers/message-content.d.ts +1 -0
  168. package/dist/inbound-mail-foundation/handlers/message-content.js +8 -0
  169. package/dist/inbound-mail-foundation/handlers/message-content.query.d.ts +2 -0
  170. package/dist/inbound-mail-foundation/handlers/message-content.query.js +1 -0
  171. package/dist/inbound-mail-foundation/projection.d.ts +3 -0
  172. package/dist/inbound-mail-foundation/projection.js +2 -0
  173. package/dist/inbound-mail-foundation/sanitize-inbound-html.d.ts +2 -0
  174. package/dist/inbound-mail-foundation/sanitize-inbound-html.js +135 -0
  175. package/dist/inbound-mail-foundation/types.js +1 -0
  176. package/dist/jobs/job-run-logger.js +16 -20
  177. package/dist/ledger/handlers/reports.query.js +25 -27
  178. package/dist/ledger/recurring.js +1 -0
  179. package/dist/notes-history/web/notes-section.js +3 -2
  180. package/dist/personal-access-tokens/feature.js +5 -18
  181. package/dist/personal-access-tokens/handlers/create.write.js +2 -5
  182. package/dist/secrets/handlers/delete.write.d.ts +4 -0
  183. package/dist/secrets/handlers/delete.write.js +9 -4
  184. package/dist/secrets/handlers/list.query.d.ts +6 -1
  185. package/dist/secrets/handlers/list.query.js +7 -3
  186. package/dist/secrets/handlers/set.write.d.ts +4 -0
  187. package/dist/secrets/handlers/set.write.js +10 -4
  188. package/dist/secrets/secret-scope.d.ts +17 -0
  189. package/dist/secrets/secret-scope.js +18 -0
  190. package/dist/sessions/feature.d.ts +3 -0
  191. package/dist/sessions/feature.js +13 -19
  192. package/dist/sessions/handlers/last-activity-probe.query.d.ts +7 -0
  193. package/dist/sessions/handlers/last-activity-probe.query.js +40 -0
  194. package/dist/sessions/handlers/last-activity-probe.route.d.ts +2 -0
  195. package/dist/sessions/handlers/last-activity-probe.route.js +30 -0
  196. package/dist/sessions/screens.js +1 -0
  197. package/dist/sessions/session-callbacks.d.ts +2 -0
  198. package/dist/sessions/session-callbacks.js +9 -7
  199. package/dist/sessions/web/i18n.js +4 -1
  200. package/dist/shared/assert-billing-live.d.ts +2 -0
  201. package/dist/shared/assert-billing-live.js +7 -0
  202. package/dist/shared/collect-extension-options.d.ts +1 -0
  203. package/dist/shared/collect-extension-options.js +8 -0
  204. package/dist/shared/index.d.ts +7 -1
  205. package/dist/shared/index.js +7 -1
  206. package/dist/shared/late-bound-slot.d.ts +5 -0
  207. package/dist/shared/late-bound-slot.js +13 -0
  208. package/dist/shared/mail-locale-templates.d.ts +1 -0
  209. package/dist/shared/mail-locale-templates.js +1 -1
  210. package/dist/shared/price-env-shape.d.ts +11 -0
  211. package/dist/shared/price-env-shape.js +15 -0
  212. package/dist/shared/purge-row-file-refs.d.ts +1 -0
  213. package/dist/shared/purge-row-file-refs.js +1 -1
  214. package/dist/shared/read-feature-export-fn.d.ts +2 -0
  215. package/dist/shared/read-feature-export-fn.js +11 -0
  216. package/dist/shared/signup-handover.js +3 -5
  217. package/dist/shared/tenant-destruction-hold.d.ts +23 -0
  218. package/dist/shared/tenant-destruction-hold.js +15 -0
  219. package/dist/shared/unprocessable.d.ts +4 -0
  220. package/dist/shared/unprocessable.js +4 -0
  221. package/dist/shared/web/index.d.ts +3 -0
  222. package/dist/shared/web/index.js +3 -0
  223. package/dist/subscription-paddle/feature.d.ts +1 -5
  224. package/dist/subscription-paddle/feature.js +7 -9
  225. package/dist/subscription-paddle/runtime.js +3 -7
  226. package/dist/subscription-stripe/feature.d.ts +1 -5
  227. package/dist/subscription-stripe/feature.js +7 -9
  228. package/dist/subscription-stripe/runtime.js +3 -7
  229. package/dist/tags/entity.js +1 -0
  230. package/dist/tags/web/tag-chip.d.ts +7 -0
  231. package/dist/tags/web/tag-chip.js +4 -0
  232. package/dist/tags/web/tag-filter.js +2 -5
  233. package/dist/tags/web/tag-manager.js +1 -1
  234. package/dist/tags/web/tag-section.js +3 -6
  235. package/dist/tags/web/tags-cell.js +2 -5
  236. package/dist/template-resolver/compile-document-body.js +12 -17
  237. package/dist/template-resolver/handlers/by-tenant.query.js +3 -1
  238. package/dist/template-resolver/handlers/discard-draft.write.js +1 -0
  239. package/dist/template-resolver/handlers/overview.query.js +3 -1
  240. package/dist/template-resolver/handlers/send-test.write.js +2 -4
  241. package/dist/template-resolver/handlers/toggle-status.write.js +3 -0
  242. package/dist/template-resolver/linked-resources.js +6 -5
  243. package/dist/template-resolver/store-template-resource.js +5 -10
  244. package/dist/template-resolver/web/document-images.js +6 -6
  245. package/dist/template-resolver/web/document-insert-fields.js +22 -4
  246. package/dist/template-resolver/web/document-schema.js +11 -12
  247. package/dist/template-resolver/web/tiptap-attribute-parse-rule.d.ts +15 -0
  248. package/dist/template-resolver/web/tiptap-attribute-parse-rule.js +11 -0
  249. package/dist/tenant/i18n.js +3 -0
  250. package/dist/tenant/schema/tenant.d.ts +9 -7
  251. package/dist/tenant/schema/tenant.js +1 -0
  252. package/dist/tenant/web/member-roles-cell.js +1 -1
  253. package/dist/tenant/web/member-status-cell.js +1 -1
  254. package/dist/tenant-inactivity/check-inactive-tenants.d.ts +3 -0
  255. package/dist/tenant-inactivity/check-inactive-tenants.js +184 -0
  256. package/dist/tenant-inactivity/constants.d.ts +10 -0
  257. package/dist/tenant-inactivity/constants.js +10 -0
  258. package/dist/tenant-inactivity/email-templates.d.ts +3 -0
  259. package/dist/tenant-inactivity/email-templates.js +16 -0
  260. package/dist/tenant-inactivity/feature.d.ts +8 -0
  261. package/dist/tenant-inactivity/feature.js +45 -0
  262. package/dist/tenant-inactivity/handlers/inactivity-state.query.d.ts +11 -0
  263. package/dist/tenant-inactivity/handlers/inactivity-state.query.js +45 -0
  264. package/dist/tenant-inactivity/handlers/keep-account.write.d.ts +8 -0
  265. package/dist/tenant-inactivity/handlers/keep-account.write.js +48 -0
  266. package/dist/tenant-inactivity/inactivity-plan.d.ts +51 -0
  267. package/dist/tenant-inactivity/inactivity-plan.js +113 -0
  268. package/dist/tenant-inactivity/index.d.ts +5 -0
  269. package/dist/tenant-inactivity/index.js +3 -0
  270. package/dist/tenant-inactivity/keep-token.d.ts +16 -0
  271. package/dist/tenant-inactivity/keep-token.js +24 -0
  272. package/dist/tenant-inactivity/mail-notifications.d.ts +4 -0
  273. package/dist/tenant-inactivity/mail-notifications.js +42 -0
  274. package/dist/tenant-inactivity/options.d.ts +27 -0
  275. package/dist/tenant-inactivity/options.js +5 -0
  276. package/dist/tenant-inactivity/remote-activity.d.ts +15 -0
  277. package/dist/tenant-inactivity/remote-activity.js +24 -0
  278. package/dist/tenant-inactivity/state-store.d.ts +10 -0
  279. package/dist/tenant-inactivity/state-store.js +50 -0
  280. package/dist/tenant-inactivity/state-table.d.ts +109 -0
  281. package/dist/tenant-inactivity/state-table.js +38 -0
  282. package/dist/tenant-lifecycle/boot-checks.js +8 -3
  283. package/dist/tenant-lifecycle/boot-rules.d.ts +12 -0
  284. package/dist/tenant-lifecycle/boot-rules.js +12 -0
  285. package/dist/tenant-lifecycle/feature.js +17 -2
  286. package/dist/tenant-lifecycle/handlers/request-destruction.write.js +11 -67
  287. package/dist/tenant-lifecycle/index.d.ts +1 -0
  288. package/dist/tenant-lifecycle/index.js +1 -0
  289. package/dist/tenant-lifecycle/request-tenant-destruction.d.ts +20 -0
  290. package/dist/tenant-lifecycle/request-tenant-destruction.js +66 -0
  291. package/dist/tenant-lifecycle/retention-config-destroy-hooks.d.ts +5 -0
  292. package/dist/tenant-lifecycle/retention-config-destroy-hooks.js +29 -0
  293. package/dist/tenant-lifecycle/run-tenant-destroy.d.ts +3 -0
  294. package/dist/tenant-lifecycle/run-tenant-destroy.js +43 -5
  295. package/dist/tenant-lifecycle/stages.d.ts +2 -0
  296. package/dist/tenant-lifecycle/stages.js +23 -2
  297. package/dist/tenant-lifecycle/testing.js +1 -1
  298. package/dist/tier-engine/caps-for-tier-from-map.d.ts +5 -0
  299. package/dist/tier-engine/caps-for-tier-from-map.js +12 -0
  300. package/dist/tier-engine/compose-app.d.ts +0 -22
  301. package/dist/tier-engine/compose-app.js +9 -16
  302. package/dist/tier-engine/index.d.ts +1 -0
  303. package/dist/tier-engine/index.js +1 -0
  304. package/dist/user/handlers/detail.query.d.ts +1 -1
  305. package/dist/user-data-rights/feature.js +2 -0
  306. package/dist/user-data-rights/run-forget-cleanup.js +2 -0
  307. package/dist/user-data-rights/web/privacy-center-screen.js +1 -1
  308. package/dist/user-data-rights/zip-path.js +1 -0
  309. package/dist/user-data-rights-defaults/hooks/config-value.userdata-hook.d.ts +1 -1
  310. package/dist/user-data-rights-defaults/hooks/config-value.userdata-hook.js +7 -20
  311. package/dist/user-data-rights-defaults/hooks/delivery-attempt.userdata-hook.js +3 -1
  312. package/dist/user-data-rights-defaults/hooks/forget-own-rows-delete-hook.d.ts +10 -0
  313. package/dist/user-data-rights-defaults/hooks/forget-own-rows-delete-hook.js +26 -0
  314. package/dist/user-data-rights-defaults/hooks/notification-preference.userdata-hook.d.ts +1 -1
  315. package/dist/user-data-rights-defaults/hooks/notification-preference.userdata-hook.js +7 -20
  316. package/dist/user-profile/handlers/change-email.write.js +2 -4
  317. package/dist/user-profile/web/profile-screen.js +2 -3
  318. package/kumiko-es-tables.json +12 -0
  319. package/package.json +46 -12
  320. package/src/admin-shell/changes.json +6 -0
  321. package/src/agent-tools/changes.json +6 -0
  322. package/src/channel-in-app/changes.json +7 -0
  323. package/src/contact/changes.json +27 -0
  324. package/src/data-retention/changes.json +6 -0
  325. package/src/delivery/changes.json +7 -0
  326. package/src/document-ingest-foundation/changes.json +6 -0
  327. package/src/files-tenant-data/changes.json +6 -0
  328. package/src/inbound-mail-foundation/changes.json +13 -0
  329. package/src/secrets/changes.json +6 -0
  330. package/src/sessions/changes.json +6 -0
  331. package/src/tenant-inactivity/changes.json +8 -0
  332. package/src/tenant-lifecycle/changes.json +18 -0
  333. package/src/tier-engine/changes.json +6 -0
@@ -1,4 +1,4 @@
1
- export declare const TENANT_LIFECYCLE_STATUSES: readonly ["active", "destroyRequested", "destroying", "destroyFailed", "destroyed"];
1
+ export declare const TENANT_LIFECYCLE_STATUSES: readonly ["active", "destroyRequested", "destroying", "destroyHeld", "destroyFailed", "destroyed"];
2
2
  export type TenantLifecycleStatus = (typeof TENANT_LIFECYCLE_STATUSES)[number];
3
3
  export declare const tenantEntity: import("@cosmicdrift/kumiko-types/fields").EntityDefinition<{
4
4
  readonly key: import("@cosmicdrift/kumiko-types/fields").EntityTextFieldDef & {
@@ -24,18 +24,19 @@ export declare const tenantEntity: import("@cosmicdrift/kumiko-types/fields").En
24
24
  readonly status: {
25
25
  readonly type: "select";
26
26
  readonly description?: string;
27
- readonly options: readonly ["active", "destroyRequested", "destroying", "destroyFailed", "destroyed"];
27
+ readonly options: readonly ["active", "destroyRequested", "destroying", "destroyHeld", "destroyFailed", "destroyed"];
28
28
  readonly required?: boolean;
29
29
  readonly sortable?: boolean;
30
30
  readonly sortNulls?: import("@cosmicdrift/kumiko-types/fields").SortNulls;
31
31
  readonly filterable?: boolean;
32
32
  readonly sensitive?: boolean;
33
- readonly default?: "active" | "destroyFailed" | "destroyRequested" | "destroyed" | "destroying" | undefined;
33
+ readonly default?: "active" | "destroyFailed" | "destroyHeld" | "destroyRequested" | "destroyed" | "destroying" | undefined;
34
34
  readonly access?: import("@cosmicdrift/kumiko-types/fields").FieldAccess;
35
35
  readonly display?: "radio" | "dropdown";
36
36
  readonly optionTones?: {
37
37
  readonly active?: "accent" | "bad" | "critical" | "neutral" | "ok" | "warn" | undefined;
38
38
  readonly destroyFailed?: "accent" | "bad" | "critical" | "neutral" | "ok" | "warn" | undefined;
39
+ readonly destroyHeld?: "accent" | "bad" | "critical" | "neutral" | "ok" | "warn" | undefined;
39
40
  readonly destroyRequested?: "accent" | "bad" | "critical" | "neutral" | "ok" | "warn" | undefined;
40
41
  readonly destroyed?: "accent" | "bad" | "critical" | "neutral" | "ok" | "warn" | undefined;
41
42
  readonly destroying?: "accent" | "bad" | "critical" | "neutral" | "ok" | "warn" | undefined;
@@ -43,7 +44,7 @@ export declare const tenantEntity: import("@cosmicdrift/kumiko-types/fields").En
43
44
  readonly optionsQuery?: string;
44
45
  readonly optionsQueryPayload?: import("@cosmicdrift/kumiko-types/fields").OptionsQueryPayload;
45
46
  readonly optionsAvailabilityQuery?: string;
46
- readonly conditionalOptions?: readonly import("@cosmicdrift/kumiko-types/fields").SelectConditionalOptions<"active" | "destroyFailed" | "destroyRequested" | "destroyed" | "destroying">[] | undefined;
47
+ readonly conditionalOptions?: readonly import("@cosmicdrift/kumiko-types/fields").SelectConditionalOptions<"active" | "destroyFailed" | "destroyHeld" | "destroyRequested" | "destroyed" | "destroying">[] | undefined;
47
48
  } & import("@cosmicdrift/kumiko-types/fields").ResolvedPiiFlags & import("@cosmicdrift/kumiko-types/fields").FieldStateConditions & {
48
49
  required: true;
49
50
  };
@@ -139,18 +140,19 @@ export declare const tenantTable: import("@cosmicdrift/kumiko-framework/db").Ent
139
140
  readonly status: {
140
141
  readonly type: "select";
141
142
  readonly description?: string;
142
- readonly options: readonly ["active", "destroyRequested", "destroying", "destroyFailed", "destroyed"];
143
+ readonly options: readonly ["active", "destroyRequested", "destroying", "destroyHeld", "destroyFailed", "destroyed"];
143
144
  readonly required?: boolean;
144
145
  readonly sortable?: boolean;
145
146
  readonly sortNulls?: import("@cosmicdrift/kumiko-types/fields").SortNulls;
146
147
  readonly filterable?: boolean;
147
148
  readonly sensitive?: boolean;
148
- readonly default?: "active" | "destroyFailed" | "destroyRequested" | "destroyed" | "destroying" | undefined;
149
+ readonly default?: "active" | "destroyFailed" | "destroyHeld" | "destroyRequested" | "destroyed" | "destroying" | undefined;
149
150
  readonly access?: import("@cosmicdrift/kumiko-types/fields").FieldAccess;
150
151
  readonly display?: "radio" | "dropdown";
151
152
  readonly optionTones?: {
152
153
  readonly active?: "accent" | "bad" | "critical" | "neutral" | "ok" | "warn" | undefined;
153
154
  readonly destroyFailed?: "accent" | "bad" | "critical" | "neutral" | "ok" | "warn" | undefined;
155
+ readonly destroyHeld?: "accent" | "bad" | "critical" | "neutral" | "ok" | "warn" | undefined;
154
156
  readonly destroyRequested?: "accent" | "bad" | "critical" | "neutral" | "ok" | "warn" | undefined;
155
157
  readonly destroyed?: "accent" | "bad" | "critical" | "neutral" | "ok" | "warn" | undefined;
156
158
  readonly destroying?: "accent" | "bad" | "critical" | "neutral" | "ok" | "warn" | undefined;
@@ -158,7 +160,7 @@ export declare const tenantTable: import("@cosmicdrift/kumiko-framework/db").Ent
158
160
  readonly optionsQuery?: string;
159
161
  readonly optionsQueryPayload?: import("@cosmicdrift/kumiko-types/fields").OptionsQueryPayload;
160
162
  readonly optionsAvailabilityQuery?: string;
161
- readonly conditionalOptions?: readonly import("@cosmicdrift/kumiko-types/fields").SelectConditionalOptions<"active" | "destroyFailed" | "destroyRequested" | "destroyed" | "destroying">[] | undefined;
163
+ readonly conditionalOptions?: readonly import("@cosmicdrift/kumiko-types/fields").SelectConditionalOptions<"active" | "destroyFailed" | "destroyHeld" | "destroyRequested" | "destroyed" | "destroying">[] | undefined;
162
164
  } & import("@cosmicdrift/kumiko-types/fields").ResolvedPiiFlags & import("@cosmicdrift/kumiko-types/fields").FieldStateConditions & {
163
165
  required: true;
164
166
  };
@@ -4,6 +4,7 @@ export const TENANT_LIFECYCLE_STATUSES = [
4
4
  "active",
5
5
  "destroyRequested",
6
6
  "destroying",
7
+ "destroyHeld",
7
8
  "destroyFailed",
8
9
  "destroyed",
9
10
  ];
@@ -2,7 +2,7 @@
2
2
  // `readonly string[]` on TeamRow (see team-list.query.ts), and DataTable has
3
3
  // no default array-to-cell formatting, so this joins it into one string.
4
4
  import { useTranslation } from "@cosmicdrift/kumiko-renderer";
5
- import { translateOrRaw } from "../../shared/web/translate-or-raw.js";
5
+ import { translateOrRaw } from "../../shared/web/index.js";
6
6
  export function MemberRolesCell({ row }) {
7
7
  const t = useTranslation();
8
8
  const roles = row["roles"];
@@ -5,7 +5,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
5
5
  // projectionList renderer — only this one cell stays TSX.
6
6
  import { useTranslation } from "@cosmicdrift/kumiko-renderer";
7
7
  import { StatusBadge } from "@cosmicdrift/kumiko-renderer/web";
8
- import { translateOrRaw } from "../../shared/web/translate-or-raw.js";
8
+ import { translateOrRaw } from "../../shared/web/index.js";
9
9
  const STATUS_TONE = {
10
10
  active: "ok",
11
11
  pending: "muted",
@@ -0,0 +1,3 @@
1
+ import type { JobContext } from "@cosmicdrift/kumiko-framework/engine";
2
+ import { type TenantInactivityOptions } from "./options.ts";
3
+ export declare function checkTenantInactivity(ctx: JobContext, options: TenantInactivityOptions): Promise<void>;
@@ -0,0 +1,184 @@
1
+ import { fetchOne } from "@cosmicdrift/kumiko-framework/db";
2
+ import { hasMailTranslations, mailT } from "@cosmicdrift/kumiko-framework/i18n";
3
+ import { parseRoles } from "@cosmicdrift/kumiko-framework/utils";
4
+ import { Temporal } from "@cosmicdrift/kumiko-types/temporal";
5
+ import { decryptTenantNames, tenantMembershipsTable, tenantTable, } from "../tenant/index.js";
6
+ import { requestTenantDestruction } from "../tenant-lifecycle/index.js";
7
+ import { userTable } from "../user/index.js";
8
+ import { TENANT_OWNER_ROLE } from "./constants.js";
9
+ import { formatInactivityMailDate } from "./email-templates.js";
10
+ import { activityBase, decideInactivityAction, foldActivity, resetWarnings, } from "./inactivity-plan.js";
11
+ import { signKeepAccountToken } from "./keep-token.js";
12
+ import { InactivityWarningNotificationType, inactivityMailTemplateLocale, } from "./mail-notifications.js";
13
+ import { resolveInactivityRule } from "./options.js";
14
+ import { loadInactivityState, loadNewestSessionActivity, saveInactivityState, } from "./state-store.js";
15
+ // Links outlive the deadline a little so a late click still counts as a reaction.
16
+ const KEEP_LINK_GRACE_MINUTES = 14 * 24 * 60;
17
+ const MS_PER_MINUTE = 60_000;
18
+ function emptyState(now) {
19
+ return {
20
+ cycleId: crypto.randomUUID(),
21
+ firstSeenAt: now,
22
+ lastActivityAt: null,
23
+ lastExemptAt: null,
24
+ lastWarnedAt: null,
25
+ postponedDueAt: null,
26
+ warningsSent: 0,
27
+ };
28
+ }
29
+ function startNewCycle(state) {
30
+ return { ...resetWarnings(state), cycleId: crypto.randomUUID() };
31
+ }
32
+ function latestOf(instants) {
33
+ let latest = null;
34
+ for (const instant of instants) {
35
+ if (instant !== null && (latest === null || Temporal.Instant.compare(instant, latest) > 0)) {
36
+ latest = instant;
37
+ }
38
+ }
39
+ return latest;
40
+ }
41
+ async function newestExternalActivity(options, tenantId, now) {
42
+ const found = await Promise.all((options.activitySources ?? []).map((source) => source({ tenantId, now })));
43
+ return latestOf(found);
44
+ }
45
+ function isNewerThanBase(activity, state) {
46
+ return activity !== null && Temporal.Instant.compare(activity, activityBase(state)) > 0;
47
+ }
48
+ async function loadOwners(ctx) {
49
+ const memberships = await ctx.db.selectMany(tenantMembershipsTable, {});
50
+ const owners = [];
51
+ for (const membership of memberships) {
52
+ if (!parseRoles(membership.roles).includes(TENANT_OWNER_ROLE))
53
+ continue;
54
+ const user = await ctx.db
55
+ .global(userTable)
56
+ .fetchOne({ id: membership.userId });
57
+ owners.push({ userId: membership.userId, locale: user?.locale ?? null });
58
+ }
59
+ return owners;
60
+ }
61
+ function mailLocaleFor(userLocale) {
62
+ const root = userLocale?.toLowerCase().split("-")[0];
63
+ const preferred = root !== undefined && hasMailTranslations(root) ? root : "en";
64
+ return inactivityMailTemplateLocale(InactivityWarningNotificationType, preferred);
65
+ }
66
+ async function readTenantName(ctx, tenantId) {
67
+ const row = await fetchOne(ctx.db.unsafeRaw(), tenantTable, {
68
+ id: tenantId,
69
+ });
70
+ const [named] = await decryptTenantNames(row ? [row] : [], tenantId);
71
+ return typeof named?.name === "string" ? named.name : tenantId;
72
+ }
73
+ function keepLinkFor(args) {
74
+ const { options, tenantId, state, deadline, now } = args;
75
+ if (options.keepAccountTokenSecret === undefined)
76
+ return options.keepAccountUrl;
77
+ const untilDeadline = Math.ceil((deadline.epochMilliseconds - now.epochMilliseconds) / MS_PER_MINUTE);
78
+ const token = signKeepAccountToken({
79
+ tenantId,
80
+ cycleId: state.cycleId,
81
+ ttlMinutes: Math.max(0, untilDeadline) + KEEP_LINK_GRACE_MINUTES,
82
+ secret: options.keepAccountTokenSecret,
83
+ now,
84
+ });
85
+ return `${options.keepAccountUrl}#token=${token}`;
86
+ }
87
+ // True when at least one owner got the mail. A failed delivery must not count as a sent warning,
88
+ // or the deletion request would follow without the owner ever having been told.
89
+ async function sendWarningMails(args) {
90
+ const { ctx, options, tenantId, deadline } = args;
91
+ if (!ctx.notify)
92
+ throw new Error("tenant-inactivity: ctx.notify missing, mount delivery");
93
+ const tenantName = await readTenantName(ctx, tenantId);
94
+ const keepUrl = keepLinkFor(args);
95
+ let delivered = false;
96
+ for (const owner of await loadOwners(ctx)) {
97
+ const locale = mailLocaleFor(owner.locale);
98
+ // immediate: the keep-account token must not land in a delivery job payload.
99
+ const result = await ctx.notify(InactivityWarningNotificationType, {
100
+ to: owner.userId,
101
+ locale,
102
+ immediate: true,
103
+ data: {
104
+ app: options.appName ?? mailT(locale, "gdpr.mail.appNameDefault"),
105
+ tenant: tenantName,
106
+ when: formatInactivityMailDate(deadline),
107
+ keepUrl,
108
+ },
109
+ });
110
+ if (result.deliveries.some((delivery) => delivery.status !== "failed"))
111
+ delivered = true;
112
+ }
113
+ return delivered;
114
+ }
115
+ async function evaluate(ctx, options, tenantId, rule, stored, now) {
116
+ const initial = stored ?? emptyState(now);
117
+ const folded = foldActivity(initial, await loadNewestSessionActivity(ctx.db));
118
+ const merged = { ...initial, ...folded.state };
119
+ const state = folded.newCycle ? startNewCycle(merged) : merged;
120
+ const decision = decideInactivityAction(state, rule, now);
121
+ if (decision.kind === "none")
122
+ return state;
123
+ // Steps with consequences ask other apps first: activity there counts too.
124
+ const external = await newestExternalActivity(options, tenantId, now);
125
+ if (isNewerThanBase(external, state)) {
126
+ return startNewCycle({ ...state, lastActivityAt: external });
127
+ }
128
+ if (decision.kind === "warn") {
129
+ const delivered = await sendWarningMails({
130
+ ctx,
131
+ options,
132
+ tenantId,
133
+ state,
134
+ deadline: decision.deadline,
135
+ now,
136
+ });
137
+ if (!delivered)
138
+ return state;
139
+ return {
140
+ ...state,
141
+ warningsSent: decision.warningsSentAfter,
142
+ lastWarnedAt: now,
143
+ postponedDueAt: decision.postponedDueAt ?? state.postponedDueAt,
144
+ };
145
+ }
146
+ if (!ctx.registry)
147
+ throw new Error("tenant-inactivity: ctx.registry required");
148
+ const result = await requestTenantDestruction({
149
+ tenantId,
150
+ actor: ctx.systemUser,
151
+ now,
152
+ db: ctx.db,
153
+ runner: ctx.db.unsafeRaw(),
154
+ registry: ctx.registry,
155
+ revokeSessions: true,
156
+ });
157
+ if (!result.isSuccess) {
158
+ throw new Error(`tenant-inactivity: destruction request for ${tenantId} failed`);
159
+ }
160
+ // If the owner cancels the request, a fresh cycle starts instead of an instant second request.
161
+ return startNewCycle({ ...state, lastActivityAt: now });
162
+ }
163
+ export async function checkTenantInactivity(ctx, options) {
164
+ const tenantId = ctx.systemUser.tenantId ?? ctx._tenantId;
165
+ // skip: a job without a tenant scope has nothing to evaluate
166
+ if (tenantId === undefined)
167
+ return;
168
+ const now = ctx.tz.now();
169
+ const tenant = await fetchOne(ctx.db.unsafeRaw(), tenantTable, { id: tenantId });
170
+ // skip: only active tenants are evaluated; others are already in a lifecycle step
171
+ if (tenant?.status !== "active")
172
+ return;
173
+ const rule = await resolveInactivityRule(options, ctx.db);
174
+ const stored = await loadInactivityState(ctx.db);
175
+ if (rule === null) {
176
+ const state = stored ?? emptyState(now);
177
+ // A tier change back to a rule starts its period at the last exempt run.
178
+ const exempt = state.warningsSent > 0 ? startNewCycle(state) : state;
179
+ await saveInactivityState(ctx.db, stored, { ...exempt, lastExemptAt: now });
180
+ }
181
+ else {
182
+ await saveInactivityState(ctx.db, stored, await evaluate(ctx, options, tenantId, rule, stored, now));
183
+ }
184
+ }
@@ -0,0 +1,10 @@
1
+ export declare const TENANT_INACTIVITY_FEATURE = "tenant-inactivity";
2
+ export declare const TENANT_INACTIVITY_STATE_ENTITY = "tenant-inactivity-state";
3
+ export declare const TENANT_OWNER_ROLE = "TenantOwner";
4
+ export declare const TenantInactivityJobs: {
5
+ readonly check: "tenant-inactivity:job:check-inactive-tenants";
6
+ };
7
+ export declare const TenantInactivityHandlers: {
8
+ readonly keepAccount: "tenant-inactivity:write:keep-account";
9
+ readonly state: "tenant-inactivity:query:state";
10
+ };
@@ -0,0 +1,10 @@
1
+ export const TENANT_INACTIVITY_FEATURE = "tenant-inactivity";
2
+ export const TENANT_INACTIVITY_STATE_ENTITY = "tenant-inactivity-state";
3
+ export const TENANT_OWNER_ROLE = "TenantOwner";
4
+ export const TenantInactivityJobs = {
5
+ check: `${TENANT_INACTIVITY_FEATURE}:job:check-inactive-tenants`,
6
+ };
7
+ export const TenantInactivityHandlers = {
8
+ keepAccount: `${TENANT_INACTIVITY_FEATURE}:write:keep-account`,
9
+ state: `${TENANT_INACTIVITY_FEATURE}:query:state`,
10
+ };
@@ -0,0 +1,3 @@
1
+ import type { Temporal } from "@cosmicdrift/kumiko-types/temporal";
2
+ export declare const INACTIVITY_MAIL_EN: Readonly<Record<string, string>>;
3
+ export declare function formatInactivityMailDate(instant: Temporal.Instant): string;
@@ -0,0 +1,16 @@
1
+ // English defaults of the inactivity warning mail; other languages register through
2
+ // @cosmicdrift/kumiko-locale-* (same pattern as the GDPR mails).
3
+ import { registerMailTranslations } from "@cosmicdrift/kumiko-framework/i18n";
4
+ export const INACTIVITY_MAIL_EN = {
5
+ "inactivity.mail.warning.subject": "{app}: Deletion request for your account {account} on {when}",
6
+ "inactivity.mail.warning.intro": "nobody has signed in to your {app} account {account} for a long time. If that does not change, we will request deletion of the account and all its data on {when}.",
7
+ "inactivity.mail.warning.keep": "To keep the account, sign in or click the button. The period then starts over.",
8
+ "inactivity.mail.warning.button": "Keep account",
9
+ "inactivity.mail.warning.after": "Even after the deletion request you can cancel it in the account settings until the waiting period ends.",
10
+ };
11
+ registerMailTranslations("en", INACTIVITY_MAIL_EN);
12
+ export function formatInactivityMailDate(instant) {
13
+ const zoned = instant.toZonedDateTimeISO("UTC");
14
+ const pad = (value) => String(value).padStart(2, "0");
15
+ return `${zoned.year}-${pad(zoned.month)}-${pad(zoned.day)}`;
16
+ }
@@ -0,0 +1,8 @@
1
+ import { type FeatureDefinition } from "@cosmicdrift/kumiko-framework/engine";
2
+ import type { TenantInactivityOptions } from "./options.ts";
3
+ /**
4
+ * Opt-in by mounting. Free accounts without activity get warning mails, then a normal deletion
5
+ * request through tenant-lifecycle; paid tiers are exempt. The option value carries functions
6
+ * (rules per tier, activity sources), so the feature is never deduplicated by options.
7
+ */
8
+ export declare function createTenantInactivityFeature<TTier extends string = string>(options: TenantInactivityOptions<TTier>): FeatureDefinition;
@@ -0,0 +1,45 @@
1
+ import { deleteMany, deriveEntityTableMeta } from "@cosmicdrift/kumiko-framework/db";
2
+ import { defineFeature, EXT_TENANT_DATA, } from "@cosmicdrift/kumiko-framework/engine";
3
+ import { checkTenantInactivity } from "./check-inactive-tenants.js";
4
+ import { TENANT_INACTIVITY_FEATURE, TENANT_INACTIVITY_STATE_ENTITY } from "./constants.js";
5
+ import { createInactivityStateQuery } from "./handlers/inactivity-state.query.js";
6
+ import { createKeepAccountHandler } from "./handlers/keep-account.write.js";
7
+ import { registerInactivityMails } from "./mail-notifications.js";
8
+ import { tenantInactivityStateEntity, tenantInactivityStateTable } from "./state-table.js";
9
+ const CHECK_JOB_ESCAPE_HATCH_REASON = "reads the tenant's lifecycle status on the system tenant and files the deletion request through the shared tenant-lifecycle core, which writes the tenant row and its event stream with a raw runner";
10
+ const tenantInactivityStateDestroyHook = async (ctx) => {
11
+ await deleteMany(ctx.db, tenantInactivityStateTable, { tenantId: ctx.tenantId });
12
+ };
13
+ /**
14
+ * Opt-in by mounting. Free accounts without activity get warning mails, then a normal deletion
15
+ * request through tenant-lifecycle; paid tiers are exempt. The option value carries functions
16
+ * (rules per tier, activity sources), so the feature is never deduplicated by options.
17
+ */
18
+ export function createTenantInactivityFeature(options) {
19
+ return defineFeature(TENANT_INACTIVITY_FEATURE, (r) => {
20
+ r.describe("Deletes abandoned free accounts: warns the tenant owners before the deadline, then files the regular tenant-lifecycle deletion request. Activity or the keep-account link restarts the period; tiers without a rule are exempt.");
21
+ r.uiHints({
22
+ displayLabel: "Tenant Inactivity · Deletion",
23
+ category: "compliance",
24
+ recommended: false,
25
+ });
26
+ r.requires({ features: ["sessions", "tenant", "tenant-lifecycle", "delivery"] });
27
+ r.storeTable(deriveEntityTableMeta(TENANT_INACTIVITY_STATE_ENTITY, tenantInactivityStateEntity, {
28
+ source: "unmanaged",
29
+ }), { reason: "read_side.tenant_inactivity_state_direct_write" });
30
+ r.useExtension(EXT_TENANT_DATA, TENANT_INACTIVITY_STATE_ENTITY, {
31
+ destroy: tenantInactivityStateDestroyHook,
32
+ });
33
+ registerInactivityMails(r);
34
+ r.job({
35
+ name: "check-inactive-tenants",
36
+ trigger: { maintenance: true, wakesSleepingApp: false },
37
+ perTenant: true,
38
+ concurrency: "skip",
39
+ escapeHatch: { grants: ["unsafeRaw"], reason: CHECK_JOB_ESCAPE_HATCH_REASON },
40
+ handler: async (_payload, ctx) => checkTenantInactivity(ctx, options),
41
+ });
42
+ r.writeHandler(createKeepAccountHandler(options));
43
+ r.queryHandler(createInactivityStateQuery(options));
44
+ });
45
+ }
@@ -0,0 +1,11 @@
1
+ import * as z from "zod";
2
+ import { type TenantInactivityOptions } from "../options.ts";
3
+ export declare function createInactivityStateQuery<TTier extends string>(options: TenantInactivityOptions<TTier>): import("@cosmicdrift/kumiko-types/define-handler").QueryHandlerDefinition<"state", z.ZodObject<{
4
+ tenantIdOverride: z.ZodOptional<z.ZodString>;
5
+ }, z.core.$strip>, {
6
+ exempt: boolean;
7
+ lastActivityAt: string | null;
8
+ warningsSent: number;
9
+ nextStep: import("../inactivity-plan.ts").InactivityStep | null;
10
+ nextStepAt: string | null;
11
+ }, import("@cosmicdrift/kumiko-types/event-type-map").KumikoEventTypeMap>;
@@ -0,0 +1,45 @@
1
+ import { createTenantDb } from "@cosmicdrift/kumiko-framework/db";
2
+ import { defineQueryHandler, parseTenantId } from "@cosmicdrift/kumiko-framework/engine";
3
+ import { AccessDeniedError, UnprocessableError } from "@cosmicdrift/kumiko-framework/errors";
4
+ import * as z from "zod";
5
+ import { describeOutlook, foldActivity } from "../inactivity-plan.js";
6
+ import { resolveInactivityRule } from "../options.js";
7
+ import { loadInactivityState, loadNewestSessionActivity } from "../state-store.js";
8
+ const STATE_QUERY_ESCAPE_HATCH_REASON = "a SystemAdmin reads the inactivity state of any tenant through a database handle pinned to that tenant";
9
+ // Folds the sessions' newest activity in like the daily job does, so a login shows up before
10
+ // the next job run.
11
+ export function createInactivityStateQuery(options) {
12
+ return defineQueryHandler({
13
+ name: "state",
14
+ schema: z.object({ tenantIdOverride: z.string().min(1).max(36).optional() }),
15
+ access: { roles: ["TenantOwner", "TenantAdmin", "SystemAdmin"] },
16
+ escapeHatch: { grants: ["unsafeRaw"], reason: STATE_QUERY_ESCAPE_HATCH_REASON },
17
+ description: "Returns whether the tenant is exempt from inactivity deletion, its last activity, the warnings already sent and the next step with its date; owners and admins see their own tenant, a SystemAdmin any tenant.",
18
+ handler: async (query, ctx) => {
19
+ const requested = query.payload.tenantIdOverride;
20
+ const isOtherTenant = requested !== undefined && requested !== query.user.tenantId;
21
+ let db = ctx.db;
22
+ if (isOtherTenant) {
23
+ if (!query.user.roles.includes("SystemAdmin"))
24
+ throw new AccessDeniedError();
25
+ const tenantId = parseTenantId(requested);
26
+ if (tenantId === null)
27
+ throw new UnprocessableError("invalid_tenant_id");
28
+ db = createTenantDb({ db: ctx.db.unsafeRaw(), tenantId });
29
+ }
30
+ const rule = await resolveInactivityRule(options, db);
31
+ const stored = await loadInactivityState(db);
32
+ const folded = stored
33
+ ? foldActivity(stored, await loadNewestSessionActivity(db)).state
34
+ : null;
35
+ const outlook = describeOutlook(folded, rule);
36
+ return {
37
+ exempt: outlook.exempt,
38
+ lastActivityAt: outlook.lastActivityAt?.toString() ?? null,
39
+ warningsSent: outlook.warningsSent,
40
+ nextStep: outlook.nextStep,
41
+ nextStepAt: outlook.nextStepAt?.toString() ?? null,
42
+ };
43
+ },
44
+ });
45
+ }
@@ -0,0 +1,8 @@
1
+ import * as z from "zod";
2
+ export declare function createKeepAccountHandler(opts: {
3
+ readonly keepAccountTokenSecret?: string;
4
+ }): import("@cosmicdrift/kumiko-types/define-handler").WriteHandlerDefinition<"keep-account", z.ZodObject<{
5
+ token: z.ZodString;
6
+ }, z.core.$strip>, {
7
+ kept: boolean;
8
+ }, import("@cosmicdrift/kumiko-types/event-type-map").KumikoEventTypeMap, undefined, undefined>;
@@ -0,0 +1,48 @@
1
+ import { fetchOne, updateMany } from "@cosmicdrift/kumiko-framework/db";
2
+ import { defineWriteHandler } from "@cosmicdrift/kumiko-framework/engine";
3
+ import { UnprocessableError, writeFailure } from "@cosmicdrift/kumiko-framework/errors";
4
+ import * as z from "zod";
5
+ import { redeemKeepAccountToken } from "../keep-token.js";
6
+ import { tenantInactivityStateTable } from "../state-table.js";
7
+ const KEEP_ACCOUNT_ESCAPE_HATCH_REASON = "the anonymous link holder has no tenant scope; the tenant comes from the signed token and every statement filters by that tenantId";
8
+ export function createKeepAccountHandler(opts) {
9
+ return defineWriteHandler({
10
+ name: "keep-account",
11
+ schema: z.object({ token: z.string().min(1) }),
12
+ access: { roles: ["anonymous", "Member", "User", "TenantAdmin", "TenantOwner", "SystemAdmin"] },
13
+ escapeHatch: { grants: ["unsafeRaw"], reason: KEEP_ACCOUNT_ESCAPE_HATCH_REASON },
14
+ agent: { expose: false },
15
+ rateLimit: { per: "ip+handler", limit: 10, windowSeconds: 60 },
16
+ description: "Redeems the keep-account link from an inactivity warning mail: counts as activity, resets the warning cycle and invalidates every earlier link.",
17
+ handler: async (event, ctx) => {
18
+ const runner = ctx.db.unsafeRaw();
19
+ const now = ctx.tz.now();
20
+ const redeemed = await redeemKeepAccountToken({
21
+ token: event.payload.token,
22
+ secret: opts.keepAccountTokenSecret,
23
+ now,
24
+ // The tenant id comes from the not-yet-verified token; a malformed value must end in the
25
+ // generic 422, so the lookup error is swallowed by the grant's anchor-lookup guard.
26
+ loadCycleId: async (tenantId) => {
27
+ const row = await fetchOne(runner, tenantInactivityStateTable, {
28
+ tenantId,
29
+ });
30
+ return row?.cycleId ?? null;
31
+ },
32
+ commitKeep: async (tenantId, cycleId) => {
33
+ const updated = await updateMany(runner, tenantInactivityStateTable, {
34
+ lastActivityAt: now,
35
+ warningsSent: 0,
36
+ lastWarnedAt: null,
37
+ postponedDueAt: null,
38
+ cycleId: crypto.randomUUID(),
39
+ }, { tenantId, cycleId });
40
+ return updated.length === 1;
41
+ },
42
+ });
43
+ if (!redeemed.ok)
44
+ return writeFailure(new UnprocessableError("invalid_or_expired_token"));
45
+ return { isSuccess: true, data: { kept: true } };
46
+ },
47
+ });
48
+ }
@@ -0,0 +1,51 @@
1
+ import { type DurationSpec, type RetentionSpec } from "@cosmicdrift/kumiko-framework/compliance";
2
+ import { Temporal } from "@cosmicdrift/kumiko-types/temporal";
3
+ type Instant = Temporal.Instant;
4
+ export type InactivityRule = {
5
+ readonly after: RetentionSpec;
6
+ readonly warnings: readonly DurationSpec[];
7
+ };
8
+ export type InactivityState = {
9
+ readonly firstSeenAt: Instant;
10
+ readonly lastActivityAt: Instant | null;
11
+ readonly lastExemptAt: Instant | null;
12
+ readonly warningsSent: number;
13
+ readonly lastWarnedAt: Instant | null;
14
+ readonly postponedDueAt: Instant | null;
15
+ };
16
+ export type InactivityStep = "warning" | "destructionRequest";
17
+ export type InactivityPlan = {
18
+ readonly step: InactivityStep;
19
+ readonly at: Instant;
20
+ };
21
+ export type InactivityDecision = {
22
+ readonly kind: "none";
23
+ } | {
24
+ readonly kind: "warn";
25
+ readonly warningsSentAfter: number;
26
+ readonly deadline: Instant;
27
+ readonly postponedDueAt: Instant | null;
28
+ } | {
29
+ readonly kind: "destroy";
30
+ };
31
+ export declare function addRetentionSpec(from: Instant, spec: RetentionSpec): Instant;
32
+ export declare function sortedWarnings(rule: InactivityRule): readonly DurationSpec[];
33
+ export declare function activityBase(state: InactivityState): Instant;
34
+ export declare function isNewCycle(state: InactivityState): boolean;
35
+ export declare function resetWarnings(state: InactivityState): InactivityState;
36
+ export declare function dueAt(state: InactivityState, rule: InactivityRule): Instant;
37
+ export declare function planNextStep(state: InactivityState, rule: InactivityRule): InactivityPlan;
38
+ export declare function decideInactivityAction(state: InactivityState, rule: InactivityRule, now: Instant): InactivityDecision;
39
+ export declare function foldActivity(state: InactivityState, newest: Instant | null): {
40
+ readonly state: InactivityState;
41
+ readonly newCycle: boolean;
42
+ };
43
+ export type InactivityOutlook = {
44
+ readonly exempt: boolean;
45
+ readonly lastActivityAt: Instant | null;
46
+ readonly warningsSent: number;
47
+ readonly nextStep: InactivityStep | null;
48
+ readonly nextStepAt: Instant | null;
49
+ };
50
+ export declare function describeOutlook(state: InactivityState | null, rule: InactivityRule | null): InactivityOutlook;
51
+ export {};