@cosmicdrift/kumiko-samples 0.405.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 (242) hide show
  1. package/package.json +1 -1
  2. package/packages/bundled-features/package.json +26 -4
  3. package/packages/bundled-features/src/account-security/feature.ts +9 -1
  4. package/packages/bundled-features/src/admin-shell/changes.json +6 -0
  5. package/packages/bundled-features/src/admin-shell/feature.ts +4 -1
  6. package/packages/bundled-features/src/agent-tools/agent-manifest.ts +1 -0
  7. package/packages/bundled-features/src/agent-tools/changes.json +6 -0
  8. package/packages/bundled-features/src/agent-tools/tool-catalog.ts +1 -0
  9. package/packages/bundled-features/src/agent-tools/types.ts +4 -0
  10. package/packages/bundled-features/src/audit/event-classification.ts +1 -0
  11. package/packages/bundled-features/src/auth-email-password/bootstrap.ts +1 -0
  12. package/packages/bundled-features/src/auth-email-password/errors.ts +18 -66
  13. package/packages/bundled-features/src/auth-email-password/web/auth-client.ts +30 -64
  14. package/packages/bundled-features/src/auth-email-password/web/auth-redirect.ts +2 -2
  15. package/packages/bundled-features/src/auth-email-password/web/confirm-account-unlock-screen.tsx +20 -66
  16. package/packages/bundled-features/src/auth-email-password/web/index.ts +1 -0
  17. package/packages/bundled-features/src/auth-email-password/web/read-path-param.ts +8 -0
  18. package/packages/bundled-features/src/auth-email-password/web/return-path.ts +3 -2
  19. package/packages/bundled-features/src/auth-email-password/web/token-confirm-screen.tsx +97 -0
  20. package/packages/bundled-features/src/auth-email-password/web/verify-email-screen.tsx +20 -68
  21. package/packages/bundled-features/src/auth-foundation/boot-checks.ts +22 -15
  22. package/packages/bundled-features/src/auth-foundation/boot-rules.ts +33 -0
  23. package/packages/bundled-features/src/auth-mfa/errors.ts +12 -42
  24. package/packages/bundled-features/src/auth-mfa/feature-exports.ts +6 -45
  25. package/packages/bundled-features/src/auth-mfa/feature.ts +8 -19
  26. package/packages/bundled-features/src/auth-mfa/web/mfa-client.ts +19 -33
  27. package/packages/bundled-features/src/billing-foundation/consumer-protection/termination-notify.ts +1 -0
  28. package/packages/bundled-features/src/billing-foundation/web/plan-price.ts +20 -7
  29. package/packages/bundled-features/src/cap-counter/stock-cap-guard.ts +1 -0
  30. package/packages/bundled-features/src/channel-in-app/changes.json +7 -0
  31. package/packages/bundled-features/src/channel-in-app/feature.ts +2 -0
  32. package/packages/bundled-features/src/channel-in-app/handlers/read-state-by-keys.query.ts +35 -0
  33. package/packages/bundled-features/src/channel-in-app/in-app-channel.ts +1 -0
  34. package/packages/bundled-features/src/channel-in-app/tables.ts +5 -1
  35. package/packages/bundled-features/src/contact/challenge.ts +41 -0
  36. package/packages/bundled-features/src/contact/changes.json +27 -0
  37. package/packages/bundled-features/src/contact/client/contact-client-source.ts +203 -0
  38. package/packages/bundled-features/src/contact/entity.ts +168 -0
  39. package/packages/bundled-features/src/contact/feature.ts +171 -0
  40. package/packages/bundled-features/src/contact/handlers/access.ts +17 -0
  41. package/packages/bundled-features/src/contact/handlers/attempts.ts +76 -0
  42. package/packages/bundled-features/src/contact/handlers/challenge.query.ts +44 -0
  43. package/packages/bundled-features/src/contact/handlers/forward-request.write.ts +98 -0
  44. package/packages/bundled-features/src/contact/handlers/mark-done.write.ts +40 -0
  45. package/packages/bundled-features/src/contact/handlers/notify-reporter-in-app.write.ts +48 -0
  46. package/packages/bundled-features/src/contact/handlers/open-count.query.ts +15 -0
  47. package/packages/bundled-features/src/contact/handlers/open-count.ts +17 -0
  48. package/packages/bundled-features/src/contact/handlers/replies.query.ts +29 -0
  49. package/packages/bundled-features/src/contact/handlers/reply.write.ts +197 -0
  50. package/packages/bundled-features/src/contact/handlers/report.write.ts +126 -0
  51. package/packages/bundled-features/src/contact/handlers/request-delivery.query.ts +143 -0
  52. package/packages/bundled-features/src/contact/handlers/request-detail.query.ts +50 -0
  53. package/packages/bundled-features/src/contact/handlers/request-list.query.ts +14 -0
  54. package/packages/bundled-features/src/contact/handlers/send-reply-mail.write.ts +124 -0
  55. package/packages/bundled-features/src/contact/handlers/send-test.write.ts +45 -0
  56. package/packages/bundled-features/src/contact/handlers/submit.write.ts +194 -0
  57. package/packages/bundled-features/src/contact/handlers/take-over-uploads.ts +47 -0
  58. package/packages/bundled-features/src/contact/i18n.ts +189 -0
  59. package/packages/bundled-features/src/contact/index.ts +29 -0
  60. package/packages/bundled-features/src/contact/lib.ts +176 -0
  61. package/packages/bundled-features/src/contact/mail.ts +401 -0
  62. package/packages/bundled-features/src/contact/options.ts +95 -0
  63. package/packages/bundled-features/src/contact/panels.ts +28 -0
  64. package/packages/bundled-features/src/contact/payloads.ts +106 -0
  65. package/packages/bundled-features/src/contact/pow.ts +22 -0
  66. package/packages/bundled-features/src/contact/screens.ts +506 -0
  67. package/packages/bundled-features/src/contact/subject.ts +13 -0
  68. package/packages/bundled-features/src/contact/user-agent.ts +39 -0
  69. package/packages/bundled-features/src/contact/user-data-hooks.ts +180 -0
  70. package/packages/bundled-features/src/contact/web/constants.ts +160 -0
  71. package/packages/bundled-features/src/contact/web/index.ts +29 -0
  72. package/packages/bundled-features/src/crypto-shredding/handlers/forget-subject.write.ts +5 -16
  73. package/packages/bundled-features/src/data-retention/changes.json +6 -0
  74. package/packages/bundled-features/src/data-retention/feature.ts +16 -2
  75. package/packages/bundled-features/src/data-retention/index.ts +5 -0
  76. package/packages/bundled-features/src/data-retention/run-retention-cleanup.ts +138 -41
  77. package/packages/bundled-features/src/data-retention/tenant-destruction-hold.ts +196 -0
  78. package/packages/bundled-features/src/delivery/address-opt-out.ts +1 -0
  79. package/packages/bundled-features/src/delivery/changes.json +7 -0
  80. package/packages/bundled-features/src/delivery/channel-context.ts +2 -0
  81. package/packages/bundled-features/src/delivery/delivery-service.ts +29 -5
  82. package/packages/bundled-features/src/delivery/events.ts +2 -0
  83. package/packages/bundled-features/src/delivery/feature.ts +3 -2
  84. package/packages/bundled-features/src/delivery/handlers/attempts-by-keys.query.ts +55 -0
  85. package/packages/bundled-features/src/delivery/handlers/log.query.ts +1 -1
  86. package/packages/bundled-features/src/delivery/jobs.ts +5 -0
  87. package/packages/bundled-features/src/delivery/tables.ts +13 -2
  88. package/packages/bundled-features/src/delivery/types.ts +3 -0
  89. package/packages/bundled-features/src/delivery/unsubscribe-page.ts +2 -0
  90. package/packages/bundled-features/src/delivery/web/delivery-channel-cell.tsx +1 -1
  91. package/packages/bundled-features/src/delivery/web/delivery-error-cell.tsx +1 -1
  92. package/packages/bundled-features/src/delivery/web/delivery-status-cell.tsx +1 -1
  93. package/packages/bundled-features/src/delivery/web/delivery-time-cell.tsx +3 -2
  94. package/packages/bundled-features/src/delivery/web/delivery-type-cell.tsx +1 -1
  95. package/packages/bundled-features/src/delivery/web/public-names.ts +1 -0
  96. package/packages/bundled-features/src/document-ingest-foundation/boot-checks.ts +14 -9
  97. package/packages/bundled-features/src/document-ingest-foundation/boot-rules.ts +22 -0
  98. package/packages/bundled-features/src/document-ingest-foundation/changes.json +6 -0
  99. package/packages/bundled-features/src/document-ingest-foundation/events.ts +17 -0
  100. package/packages/bundled-features/src/document-ingest-foundation/feature.ts +39 -1
  101. package/packages/bundled-features/src/document-ingest-foundation/index.ts +10 -0
  102. package/packages/bundled-features/src/document-ingest-foundation/report-ingest-progress.ts +43 -0
  103. package/packages/bundled-features/src/document-ingest-foundation/tables.ts +43 -0
  104. package/packages/bundled-features/src/files-tenant-data/changes.json +6 -0
  105. package/packages/bundled-features/src/files-tenant-data/hooks.ts +4 -1
  106. package/packages/bundled-features/src/folders/web/folder-manager.tsx +8 -9
  107. package/packages/bundled-features/src/folders/web/folder-section.tsx +1 -1
  108. package/packages/bundled-features/src/form-draft-user-data/index.ts +2 -0
  109. package/packages/bundled-features/src/inbound-mail-foundation/changes.json +13 -0
  110. package/packages/bundled-features/src/inbound-mail-foundation/entities.ts +2 -0
  111. package/packages/bundled-features/src/inbound-mail-foundation/events.ts +2 -0
  112. package/packages/bundled-features/src/inbound-mail-foundation/feature.ts +6 -6
  113. package/packages/bundled-features/src/inbound-mail-foundation/handlers/attach-message-content.write.ts +7 -0
  114. package/packages/bundled-features/src/inbound-mail-foundation/handlers/ingest-message.write.ts +6 -0
  115. package/packages/bundled-features/src/inbound-mail-foundation/handlers/list-messages.query.ts +6 -2
  116. package/packages/bundled-features/src/inbound-mail-foundation/handlers/message-content.query.ts +3 -0
  117. package/packages/bundled-features/src/inbound-mail-foundation/handlers/message-content.ts +19 -0
  118. package/packages/bundled-features/src/inbound-mail-foundation/projection.ts +2 -0
  119. package/packages/bundled-features/src/inbound-mail-foundation/sanitize-inbound-html.ts +150 -0
  120. package/packages/bundled-features/src/inbound-mail-foundation/types.ts +1 -0
  121. package/packages/bundled-features/src/jobs/job-run-logger.ts +24 -25
  122. package/packages/bundled-features/src/ledger/handlers/reports.query.ts +46 -31
  123. package/packages/bundled-features/src/ledger/recurring.ts +1 -0
  124. package/packages/bundled-features/src/notes-history/web/notes-section.tsx +3 -1
  125. package/packages/bundled-features/src/personal-access-tokens/feature.ts +9 -17
  126. package/packages/bundled-features/src/personal-access-tokens/handlers/create.write.ts +2 -7
  127. package/packages/bundled-features/src/secrets/changes.json +6 -0
  128. package/packages/bundled-features/src/secrets/handlers/delete.write.ts +8 -4
  129. package/packages/bundled-features/src/secrets/handlers/list.query.ts +6 -3
  130. package/packages/bundled-features/src/secrets/handlers/set.write.ts +9 -4
  131. package/packages/bundled-features/src/secrets/secret-scope.ts +33 -0
  132. package/packages/bundled-features/src/sessions/changes.json +6 -0
  133. package/packages/bundled-features/src/sessions/feature.ts +21 -18
  134. package/packages/bundled-features/src/sessions/handlers/last-activity-probe.query.ts +53 -0
  135. package/packages/bundled-features/src/sessions/handlers/last-activity-probe.route.ts +39 -0
  136. package/packages/bundled-features/src/sessions/screens.ts +1 -0
  137. package/packages/bundled-features/src/sessions/session-callbacks.ts +13 -12
  138. package/packages/bundled-features/src/sessions/web/i18n.ts +4 -1
  139. package/packages/bundled-features/src/shared/assert-billing-live.ts +14 -0
  140. package/packages/bundled-features/src/shared/collect-extension-options.ts +12 -0
  141. package/packages/bundled-features/src/shared/index.ts +16 -0
  142. package/packages/bundled-features/src/shared/late-bound-slot.ts +19 -0
  143. package/packages/bundled-features/src/shared/mail-locale-templates.ts +7 -1
  144. package/packages/bundled-features/src/shared/price-env-shape.ts +44 -0
  145. package/packages/bundled-features/src/shared/purge-row-file-refs.ts +1 -1
  146. package/packages/bundled-features/src/shared/read-feature-export-fn.ts +16 -0
  147. package/packages/bundled-features/src/shared/signup-handover.ts +3 -4
  148. package/packages/bundled-features/src/shared/tenant-destruction-hold.ts +49 -0
  149. package/packages/bundled-features/src/shared/unprocessable.ts +19 -0
  150. package/packages/bundled-features/src/shared/web/index.ts +3 -0
  151. package/packages/bundled-features/src/subscription-paddle/feature.ts +7 -15
  152. package/packages/bundled-features/src/subscription-paddle/runtime.ts +4 -7
  153. package/packages/bundled-features/src/subscription-stripe/feature.ts +7 -15
  154. package/packages/bundled-features/src/subscription-stripe/runtime.ts +4 -7
  155. package/packages/bundled-features/src/tags/entity.ts +1 -0
  156. package/packages/bundled-features/src/tags/web/tag-chip.tsx +14 -0
  157. package/packages/bundled-features/src/tags/web/tag-filter.tsx +4 -5
  158. package/packages/bundled-features/src/tags/web/tag-manager.tsx +1 -1
  159. package/packages/bundled-features/src/tags/web/tag-section.tsx +3 -6
  160. package/packages/bundled-features/src/tags/web/tags-cell.tsx +4 -5
  161. package/packages/bundled-features/src/template-resolver/compile-document-body.ts +27 -15
  162. package/packages/bundled-features/src/template-resolver/handlers/by-tenant.query.ts +11 -8
  163. package/packages/bundled-features/src/template-resolver/handlers/discard-draft.write.ts +1 -0
  164. package/packages/bundled-features/src/template-resolver/handlers/overview.query.ts +1 -0
  165. package/packages/bundled-features/src/template-resolver/handlers/send-test.write.ts +5 -5
  166. package/packages/bundled-features/src/template-resolver/handlers/toggle-status.write.ts +3 -0
  167. package/packages/bundled-features/src/template-resolver/linked-resources.ts +11 -6
  168. package/packages/bundled-features/src/template-resolver/store-template-resource.ts +15 -12
  169. package/packages/bundled-features/src/template-resolver/web/document-images.ts +6 -6
  170. package/packages/bundled-features/src/template-resolver/web/document-insert-fields.tsx +41 -36
  171. package/packages/bundled-features/src/template-resolver/web/document-schema.ts +11 -12
  172. package/packages/bundled-features/src/template-resolver/web/tiptap-attribute-parse-rule.ts +19 -0
  173. package/packages/bundled-features/src/tenant/i18n.ts +3 -0
  174. package/packages/bundled-features/src/tenant/schema/tenant.ts +1 -0
  175. package/packages/bundled-features/src/tenant/web/member-roles-cell.tsx +1 -1
  176. package/packages/bundled-features/src/tenant/web/member-status-cell.tsx +1 -1
  177. package/packages/bundled-features/src/tenant-inactivity/changes.json +8 -0
  178. package/packages/bundled-features/src/tenant-inactivity/check-inactive-tenants.ts +260 -0
  179. package/packages/bundled-features/src/tenant-inactivity/constants.ts +12 -0
  180. package/packages/bundled-features/src/tenant-inactivity/email-templates.ts +24 -0
  181. package/packages/bundled-features/src/tenant-inactivity/feature.ts +66 -0
  182. package/packages/bundled-features/src/tenant-inactivity/handlers/inactivity-state.query.ts +49 -0
  183. package/packages/bundled-features/src/tenant-inactivity/handlers/keep-account.write.ts +56 -0
  184. package/packages/bundled-features/src/tenant-inactivity/inactivity-plan.ts +187 -0
  185. package/packages/bundled-features/src/tenant-inactivity/index.ts +5 -0
  186. package/packages/bundled-features/src/tenant-inactivity/keep-token.ts +44 -0
  187. package/packages/bundled-features/src/tenant-inactivity/mail-notifications.ts +62 -0
  188. package/packages/bundled-features/src/tenant-inactivity/options.ts +38 -0
  189. package/packages/bundled-features/src/tenant-inactivity/remote-activity.ts +32 -0
  190. package/packages/bundled-features/src/tenant-inactivity/state-store.ts +71 -0
  191. package/packages/bundled-features/src/tenant-inactivity/state-table.ts +50 -0
  192. package/packages/bundled-features/src/tenant-lifecycle/boot-checks.ts +8 -6
  193. package/packages/bundled-features/src/tenant-lifecycle/boot-rules.ts +16 -0
  194. package/packages/bundled-features/src/tenant-lifecycle/changes.json +30 -0
  195. package/packages/bundled-features/src/tenant-lifecycle/constants.ts +6 -0
  196. package/packages/bundled-features/src/tenant-lifecycle/events.ts +2 -0
  197. package/packages/bundled-features/src/tenant-lifecycle/feature.ts +25 -2
  198. package/packages/bundled-features/src/tenant-lifecycle/handlers/request-destruction.write.ts +12 -87
  199. package/packages/bundled-features/src/tenant-lifecycle/index.ts +6 -0
  200. package/packages/bundled-features/src/tenant-lifecycle/request-tenant-destruction.ts +108 -0
  201. package/packages/bundled-features/src/tenant-lifecycle/retention-config-destroy-hooks.ts +62 -0
  202. package/packages/bundled-features/src/tenant-lifecycle/run-tenant-destroy.ts +131 -11
  203. package/packages/bundled-features/src/tenant-lifecycle/stages.ts +39 -4
  204. package/packages/bundled-features/src/tenant-lifecycle/testing.ts +1 -1
  205. package/packages/bundled-features/src/tier-engine/caps-for-tier-from-map.ts +16 -0
  206. package/packages/bundled-features/src/tier-engine/changes.json +6 -0
  207. package/packages/bundled-features/src/tier-engine/compose-app.ts +21 -20
  208. package/packages/bundled-features/src/tier-engine/index.ts +1 -0
  209. package/packages/bundled-features/src/user-data-rights/feature.ts +2 -0
  210. package/packages/bundled-features/src/user-data-rights/run-forget-cleanup.ts +2 -0
  211. package/packages/bundled-features/src/user-data-rights/web/privacy-center-screen.tsx +1 -1
  212. package/packages/bundled-features/src/user-data-rights/zip-path.ts +1 -0
  213. package/packages/bundled-features/src/user-data-rights-defaults/hooks/config-value.userdata-hook.ts +8 -27
  214. package/packages/bundled-features/src/user-data-rights-defaults/hooks/delivery-attempt.userdata-hook.ts +11 -8
  215. package/packages/bundled-features/src/user-data-rights-defaults/hooks/forget-own-rows-delete-hook.ts +42 -0
  216. package/packages/bundled-features/src/user-data-rights-defaults/hooks/notification-preference.userdata-hook.ts +8 -27
  217. package/packages/bundled-features/src/user-profile/handlers/change-email.write.ts +2 -6
  218. package/packages/bundled-features/src/user-profile/web/profile-screen.tsx +2 -3
  219. package/samples/apps/styleguide/src/features/widgets/i18n.ts +6 -0
  220. package/samples/apps/styleguide/src/features/widgets/web/InboxReaderExamples.tsx +158 -0
  221. package/samples/apps/styleguide/src/features/widgets/web/Widgets.tsx +2 -0
  222. package/samples/apps/styleguide/src/features/widgets/web/sample-pdf.ts +28 -0
  223. package/samples/apps/use-all-bundled/feature-manifest.json +134 -2
  224. package/samples/apps/use-all-bundled/kumiko/migrations/0063_contact.rebuild.json +4 -0
  225. package/samples/apps/use-all-bundled/package.json +1 -0
  226. package/samples/apps/use-all-bundled/playwright.config.ts +2 -0
  227. package/samples/apps/use-all-bundled/src/app/client.tsx +3 -0
  228. package/samples/apps/use-all-bundled/src/app/screens-feature.ts +46 -2
  229. package/samples/apps/use-all-bundled/src/run-config.ts +38 -4
  230. package/samples/recipes/contact/README.md +46 -0
  231. package/samples/recipes/contact/package.json +12 -0
  232. package/samples/recipes/contact/src/feature.ts +27 -0
  233. package/samples/recipes/delivery-notifications/src/feature.ts +3 -0
  234. package/samples/recipes/lane-routing/README.md +1 -0
  235. package/samples/recipes/lane-routing/src/feature.ts +8 -0
  236. package/samples/recipes/record-detail-layout/src/feature.ts +9 -1
  237. package/samples/recipes/search/README.md +2 -0
  238. package/samples/recipes/search/src/feature.ts +27 -2
  239. package/samples/recipes/secrets-demo/README.md +1 -0
  240. package/samples/recipes/secrets-demo/src/feature.ts +56 -0
  241. package/samples/recipes/tenant-inactivity/README.md +21 -0
  242. package/samples/recipes/tenant-inactivity/package.json +12 -0
@@ -1,4 +1,5 @@
1
1
  import {
2
+ bootRuleError,
2
3
  EXT_EXTERNAL_RESOURCE,
3
4
  EXT_INFRA_RESOURCE,
4
5
  EXT_SEARCH_ADAPTER,
@@ -11,6 +12,7 @@ import {
11
12
  } from "@cosmicdrift/kumiko-framework/engine";
12
13
  import { createFallbackLogger } from "@cosmicdrift/kumiko-framework/logging";
13
14
  import { entitiesOf } from "../shared/index.ts";
15
+ import { TENANT_LIFECYCLE_BOOT_RULES } from "./boot-rules.ts";
14
16
 
15
17
  const log = createFallbackLogger("kumiko:boot");
16
18
 
@@ -46,9 +48,9 @@ export function validateTenantDataHookCoverage(features: readonly FeatureDefinit
46
48
  .filter(([, field]) => hasTenantOwned(field))
47
49
  .map(([name]) => name);
48
50
  if (tenantSubjectFields.length === 0) continue;
49
- throw new Error(
50
- `[kumiko:boot] Entity "${entityName}" (feature "${feature.name}") has tenant-subject fields (${tenantSubjectFields.join(", ")}) but no feature registers an EXT_TENANT_DATA destroy hook for it — tenant destroy never erases this data. Register r.useExtension(EXT_TENANT_DATA, "${entityName}", { destroy }) or a documented no-op if crypto-shredding covers it.`,
51
- );
51
+ throw bootRuleError(TENANT_LIFECYCLE_BOOT_RULES.tenantSubjectWithoutDestroyHook, {
52
+ message: `[kumiko:boot] Entity "${entityName}" (feature "${feature.name}") has tenant-subject fields (${tenantSubjectFields.join(", ")}) but no feature registers an EXT_TENANT_DATA destroy hook for it — tenant destroy never erases this data. Register r.useExtension(EXT_TENANT_DATA, "${entityName}", { destroy }) or a documented no-op if crypto-shredding covers it.`,
53
+ });
52
54
  }
53
55
  }
54
56
  }
@@ -74,9 +76,9 @@ export function validateTenantDestroyHookShapes(features: readonly FeatureDefini
74
76
  : isTenantResourceExtensionHooks(usage.options);
75
77
  if (isValid) continue;
76
78
  const requiredFn = isTenantData ? "destroy" : "destroyTenant";
77
- throw new Error(
78
- `[kumiko:boot] ${usage.extensionName} registration for "${usage.entityName}" (feature "${feature.name}") has no ${requiredFn} function — tenant destroy would fail at this stage.`,
79
- );
79
+ throw bootRuleError(TENANT_LIFECYCLE_BOOT_RULES.destroyFunctionMissing, {
80
+ message: `[kumiko:boot] ${usage.extensionName} registration for "${usage.entityName}" (feature "${feature.name}") has no ${requiredFn} function — tenant destroy would fail at this stage.`,
81
+ });
80
82
  }
81
83
  }
82
84
  }
@@ -0,0 +1,16 @@
1
+ import type { BootRuleTable } from "@cosmicdrift/kumiko-framework/engine";
2
+
3
+ export const TENANT_LIFECYCLE_BOOT_RULES = {
4
+ tenantSubjectWithoutDestroyHook: {
5
+ id: "tenant-lifecycle/tenant-subject-without-destroy-hook",
6
+ summary:
7
+ "An entity with tenant-subject fields has an EXT_TENANT_DATA destroy hook, so tenant destroy erases its data.",
8
+ fix: 'Register r.useExtension(EXT_TENANT_DATA, "<entity>", { destroy }) or a documented no-op if crypto-shredding covers it.',
9
+ },
10
+ destroyFunctionMissing: {
11
+ id: "tenant-lifecycle/destroy-function-missing",
12
+ summary:
13
+ "A tenant data or tenant resource extension registration provides its destroy function, otherwise tenant destroy fails at that stage.",
14
+ fix: "Provide destroy (EXT_TENANT_DATA) or destroyTenant (tenant resource extensions) in the registration options.",
15
+ },
16
+ } as const satisfies BootRuleTable;
@@ -1,4 +1,34 @@
1
1
  [
2
+ {
3
+ "version": "0.408.0",
4
+ "type": "improvement",
5
+ "title": "Shared lookup for single-provider extension points",
6
+ "detail": "findSignupHandoverProvider and findTenantDestructionHoldProvider now go through one internal helper that returns the first registered usage whose options match the provider shape. Usages with other options are still skipped, and the result is undefined when none matches."
7
+ },
8
+ {
9
+ "version": "0.407.0",
10
+ "type": "improvement",
11
+ "title": "Tenants with blockDelete rows park in destroyHeld",
12
+ "detail": "When a destroying tenant owns rows of an entity with strategy blockDelete (entity default, preset, profile or per-tenant override), the destruction pauses before the tenant row in the new tenant status destroyHeld instead of deleting those rows. The sweep ignores destroyHeld tenants and hasTenantDestructionWork does not count them. The daily data-retention cleanup hard-deletes the held rows once their keepFor has passed, including their files, and then moves the tenant back to destroying in the same run. Code that switches exhaustively over the tenant status must handle destroyHeld; it is a transient state between destroying and destroyed and never the final one. The tenant's compliance profile and retention overrides are erased in the tenant-row phase through EXT_TENANT_DATA hooks, so they survive while the tenant is held."
13
+ },
14
+ {
15
+ "version": "0.407.0",
16
+ "type": "improvement",
17
+ "title": "requestTenantDestruction extracted",
18
+ "detail": "The core of the request-destruction handler is exported as requestTenantDestruction({ tenantId, actor, now, db, runner, registry, revokeSessions }) so other features, such as tenant-inactivity, file the same deletion request. The handler behavior is unchanged."
19
+ },
20
+ {
21
+ "version": "0.406.0",
22
+ "type": "improvement",
23
+ "title": "Destroy stages can wait on external operations",
24
+ "detail": "A tick in which a hook reports pending is recorded as a progressed event with pending true and does not count as a failed attempt. The wait is bounded: once 60 minutes (DESTRUCTION_STAGE_MAX_PENDING_MS) have passed since the attempt's stage-started event, a pending tick fails the attempt with \"still pending\", and the stage is abandoned after its usual maxAttempts, so a stage waits at most maxAttempts x 60 minutes. Ticks without progress and without pending still count as failed attempts. stage-started events now carry startedAt from the sweep clock."
25
+ },
26
+ {
27
+ "version": "0.406.0",
28
+ "type": "improvement",
29
+ "title": "Destruction sweep no longer wakes a sleeping app",
30
+ "detail": "The run-tenant-destruction cron declares wakesSleepingApp false, so its per-minute schedule does not keep a sleeping shared app awake. A due destruction runs on the next wake, for example the daily maintenance window. Its scheduler id changes to scheduler-nowake-tenant-lifecycle-job-run-tenant-destruction; the old scheduler is removed on the first start."
31
+ },
2
32
  {
3
33
  "version": "0.405.0",
4
34
  "type": "improvement",
@@ -67,3 +67,9 @@ export const DESTRUCTION_STAGE_TICK_BUDGET_MS = 30_000;
67
67
  // without a guaranteed first batch processes nothing, and a no-progress stage
68
68
  // counts as a failed attempt, which would abandon the pipeline under load.
69
69
  export const DESTRUCTION_STAGE_MIN_SLICE_MS = 2_000;
70
+
71
+ // How long one stage attempt may report pending (a hook waiting on an external
72
+ // operation) after its stage-started event before the wait counts as a failed attempt.
73
+ // Sized for a queued app teardown (pod drain up to 330 s, database drop up to 180 s,
74
+ // two teardowns in parallel) with headroom for several apps per tenant.
75
+ export const DESTRUCTION_STAGE_MAX_PENDING_MS = 60 * 60_000;
@@ -16,6 +16,7 @@ export const tenantDestructionStartedSchema = z.object({
16
16
  export const tenantDestructionStageStartedSchema = z.object({
17
17
  stage: z.string().min(1),
18
18
  attempts: z.number().int().positive(),
19
+ startedAt: z.string().datetime().optional(),
19
20
  });
20
21
 
21
22
  export const tenantDestructionStageSucceededSchema = z.object({
@@ -27,6 +28,7 @@ export const tenantDestructionStageProgressedSchema = z.object({
27
28
  stage: z.string().min(1),
28
29
  attempts: z.number().int().positive(),
29
30
  processed: z.number().int().nonnegative(),
31
+ pending: z.boolean().optional(),
30
32
  });
31
33
 
32
34
  export const tenantDestructionStageFailedSchema = z.object({
@@ -9,6 +9,7 @@ import {
9
9
  type FeatureDefinition,
10
10
  type TenantLifecycleStatusPlugin,
11
11
  } from "@cosmicdrift/kumiko-framework/engine";
12
+ import { EXT_TENANT_DESTRUCTION_HOLD } from "../shared/index.ts";
12
13
  import {
13
14
  validateTenantDataHookCoverage,
14
15
  validateTenantDestroyHookShapes,
@@ -40,10 +41,17 @@ import {
40
41
  } from "./events.ts";
41
42
  import { cancelDestructionWrite } from "./handlers/cancel-destruction.write.ts";
42
43
  import { requestDestructionWrite } from "./handlers/request-destruction.write.ts";
44
+ import {
45
+ COMPLIANCE_PROFILE_ENTITY_NAME,
46
+ complianceProfileTenantDestroyHook,
47
+ RETENTION_OVERRIDE_ENTITY_NAME,
48
+ retentionOverrideTenantDestroyHook,
49
+ } from "./retention-config-destroy-hooks.ts";
43
50
  import {
44
51
  hasTenantDestructionWork,
45
52
  resolveTenantLifecycleGate,
46
53
  runTenantDestructionSweep,
54
+ tenantDestructionHoldProvider,
47
55
  } from "./run-tenant-destroy.ts";
48
56
 
49
57
  const tenantLifecycleStatusPlugin: TenantLifecycleStatusPlugin = {
@@ -64,7 +72,7 @@ export function createTenantLifecycleFeature(): FeatureDefinition {
64
72
  recommended: false,
65
73
  });
66
74
  r.requires({ features: ["tenant", "compliance-profiles"] });
67
- r.optionalRequires("sessions");
75
+ r.optionalRequires("sessions", "data-retention");
68
76
  r.usesApi("compliance.forTenant");
69
77
 
70
78
  r.extendsRegistrar(EXT_TENANT_DATA, {});
@@ -73,6 +81,21 @@ export function createTenantLifecycleFeature(): FeatureDefinition {
73
81
  r.extendsRegistrar(EXT_STORAGE_PROVIDER, {});
74
82
  r.extendsRegistrar(EXT_INFRA_RESOURCE, {});
75
83
 
84
+ // Self-extension: data-retention hands a parked tenant back through this, see shared/tenant-destruction-hold.ts.
85
+ r.extendsRegistrar(EXT_TENANT_DESTRUCTION_HOLD, {});
86
+ r.useExtension(EXT_TENANT_DESTRUCTION_HOLD, "tenant-lifecycle", tenantDestructionHoldProvider);
87
+
88
+ // Registered here because the hosts of these entities cannot require tenant-lifecycle (cycle,
89
+ // resp. standalone use); the override hook no-ops without data-retention.
90
+ r.useExtension(EXT_TENANT_DATA, COMPLIANCE_PROFILE_ENTITY_NAME, {
91
+ destroy: complianceProfileTenantDestroyHook,
92
+ phase: "tenant-row",
93
+ });
94
+ r.useExtension(EXT_TENANT_DATA, RETENTION_OVERRIDE_ENTITY_NAME, {
95
+ destroy: retentionOverrideTenantDestroyHook,
96
+ phase: "tenant-row",
97
+ });
98
+
76
99
  // Self-extension, same pattern as `user`/EXT_PRINCIPAL_STATUS — declares
77
100
  // AND fulfils tenantLifecycleStatus so teardown state is visible with no per-app wiring.
78
101
  r.extendsRegistrar(EXT_TENANT_LIFECYCLE_STATUS, {});
@@ -133,7 +156,7 @@ export function createTenantLifecycleFeature(): FeatureDefinition {
133
156
  const RUN_TENANT_DESTRUCTION_REASON = "sweeps tenant destruction across every tenant";
134
157
  r.job({
135
158
  name: "run-tenant-destruction",
136
- trigger: { cron: "0 * * * * *" },
159
+ trigger: { cron: "0 * * * * *", wakesSleepingApp: false },
137
160
  concurrency: "skip",
138
161
  escapeHatch: { reason: RUN_TENANT_DESTRUCTION_REASON },
139
162
  handler: async (_payload, ctx) => {
@@ -1,22 +1,6 @@
1
- import { addDurationSpec } from "@cosmicdrift/kumiko-framework/compliance";
2
- import { createEventStoreExecutor, fetchOne } from "@cosmicdrift/kumiko-framework/db";
3
- import { defineWriteHandler, SYSTEM_TENANT_ID } from "@cosmicdrift/kumiko-framework/engine";
4
- import { UnprocessableError, writeFailure } from "@cosmicdrift/kumiko-framework/errors";
5
- import { appendDomainEventCore } from "@cosmicdrift/kumiko-framework/pipeline";
6
- import { getTemporal } from "@cosmicdrift/kumiko-framework/time";
1
+ import { defineWriteHandler } from "@cosmicdrift/kumiko-framework/engine";
7
2
  import * as z from "zod";
8
- import { resolveProfileForTenant } from "../../compliance-profiles/index.ts";
9
- import { type TenantLifecycleStatus, tenantEntity, tenantTable } from "../../tenant/index.ts";
10
- import { DESTRUCTION_REQUESTED_EVENT_QN, TENANT_LIFECYCLE_FEATURE } from "../constants.ts";
11
- import { revokeTenantSessions } from "../lib/revoke-tenant-sessions.ts";
12
- import { invalidateTenantLifecycleGate } from "../lifecycle-gate.ts";
13
-
14
- const crud = createEventStoreExecutor(tenantTable, tenantEntity, { entityName: "tenant" });
15
-
16
- type TenantLifecycleRow = {
17
- status: TenantLifecycleStatus;
18
- gracePeriodEnd: Temporal.Instant | null;
19
- };
3
+ import { requestTenantDestruction } from "../request-tenant-destruction.ts";
20
4
 
21
5
  const REQUEST_DESTRUCTION_TENANT_ROW_REASON =
22
6
  "reads the caller's tenant row (a global row on the system tenant), its compliance profile, appends to the tenant stream on the system tenant and revokes its sessions via DbRunner helpers";
@@ -32,73 +16,14 @@ export const requestDestructionWrite = defineWriteHandler({
32
16
  grants: ["unsafeRaw"],
33
17
  reason: REQUEST_DESTRUCTION_TENANT_ROW_REASON,
34
18
  },
35
- handler: async (event, ctx) => {
36
- const tenantId = event.user.tenantId;
37
- const runner = ctx.db.unsafeRaw();
38
- const row = await fetchOne<TenantLifecycleRow>(runner, tenantTable, { id: tenantId });
39
- if (!row) {
40
- return writeFailure(new UnprocessableError("tenant_not_found", { details: { tenantId } }));
41
- }
42
- if (row.status !== "active") {
43
- return writeFailure(
44
- new UnprocessableError("tenant_not_active", {
45
- details: { status: row.status },
46
- }),
47
- );
48
- }
49
-
50
- const { profile } = await resolveProfileForTenant({ db: runner, tenantId });
51
- const T = getTemporal();
52
- const gracePeriodEnd = addDurationSpec(T.Now.instant(), profile.tenantDestroyGracePeriod);
53
-
54
- const update = await crud.update(
55
- {
56
- id: tenantId,
57
- changes: {
58
- status: "destroyRequested",
59
- destroyRequestedAt: T.Now.instant(),
60
- destroyRequestedBy: event.user.id,
61
- gracePeriodEnd,
62
- },
63
- },
64
- event.user,
65
- ctx.db,
66
- { skipOptimisticLock: true },
67
- );
68
- if (!update.isSuccess) return update;
69
- invalidateTenantLifecycleGate(tenantId);
70
-
71
- await appendDomainEventCore(
72
- {
73
- registry: ctx.registry,
74
- db: runner,
75
- tenantId: SYSTEM_TENANT_ID,
76
- userId: String(event.user.id),
77
- callSiteLabel: "tenant-lifecycle request-destruction",
78
- callerFeature: TENANT_LIFECYCLE_FEATURE,
79
- },
80
- {
81
- aggregateId: tenantId,
82
- aggregateType: "tenant",
83
- type: DESTRUCTION_REQUESTED_EVENT_QN,
84
- payload: {
85
- requestedBy: event.user.id,
86
- gracePeriodEnd: gracePeriodEnd.toString(),
87
- },
88
- },
89
- );
90
-
91
- if (await ctx.hasFeature("sessions")) {
92
- await revokeTenantSessions(runner, tenantId);
93
- }
94
-
95
- return {
96
- isSuccess: true as const,
97
- data: {
98
- tenantId,
99
- status: "destroyRequested" as const,
100
- gracePeriodEnd: gracePeriodEnd.toString(),
101
- },
102
- };
103
- },
19
+ handler: async (event, ctx) =>
20
+ requestTenantDestruction({
21
+ tenantId: event.user.tenantId,
22
+ actor: event.user,
23
+ now: ctx.tz.now(),
24
+ db: ctx.db,
25
+ runner: ctx.db.unsafeRaw(),
26
+ registry: ctx.registry,
27
+ revokeSessions: await ctx.hasFeature("sessions"),
28
+ }),
104
29
  });
@@ -4,9 +4,15 @@ export {
4
4
  TENANT_DESTROY_ARCHIVED_BY,
5
5
  } from "./archive-and-delete-tenant-rows.ts";
6
6
  export {
7
+ TENANT_DESTRUCTION_STAGE_FAILED_EVENT_QN,
8
+ TENANT_DESTRUCTION_STAGE_PROGRESSED_EVENT_QN,
7
9
  TENANT_DESTRUCTION_STAGES,
8
10
  TENANT_LIFECYCLE_FEATURE,
9
11
  TenantLifecycleHandlers,
10
12
  } from "./constants.ts";
11
13
  export { createTenantLifecycleFeature } from "./feature.ts";
14
+ export {
15
+ type RequestTenantDestructionArgs,
16
+ requestTenantDestruction,
17
+ } from "./request-tenant-destruction.ts";
12
18
  export { resolveTenantLifecycleGate } from "./run-tenant-destroy.ts";
@@ -0,0 +1,108 @@
1
+ import { addDurationSpec } from "@cosmicdrift/kumiko-framework/compliance";
2
+ import {
3
+ createEventStoreExecutor,
4
+ type DbRunner,
5
+ fetchOne,
6
+ type TenantDb,
7
+ } from "@cosmicdrift/kumiko-framework/db";
8
+ import {
9
+ type Registry,
10
+ type SessionUser,
11
+ SYSTEM_TENANT_ID,
12
+ type TenantId,
13
+ } from "@cosmicdrift/kumiko-framework/engine";
14
+ import { UnprocessableError, writeFailure } from "@cosmicdrift/kumiko-framework/errors";
15
+ import { appendDomainEventCore } from "@cosmicdrift/kumiko-framework/pipeline";
16
+ import type { Temporal } from "@cosmicdrift/kumiko-types/temporal";
17
+ import { resolveProfileForTenant } from "../compliance-profiles/index.ts";
18
+ import { type TenantLifecycleStatus, tenantEntity, tenantTable } from "../tenant/index.ts";
19
+ import { DESTRUCTION_REQUESTED_EVENT_QN, TENANT_LIFECYCLE_FEATURE } from "./constants.ts";
20
+ import { revokeTenantSessions } from "./lib/revoke-tenant-sessions.ts";
21
+ import { invalidateTenantLifecycleGate } from "./lifecycle-gate.ts";
22
+
23
+ const crud = createEventStoreExecutor(tenantTable, tenantEntity, { entityName: "tenant" });
24
+
25
+ type TenantLifecycleRow = {
26
+ status: TenantLifecycleStatus;
27
+ gracePeriodEnd: Temporal.Instant | null;
28
+ };
29
+
30
+ export type RequestTenantDestructionArgs = {
31
+ readonly tenantId: TenantId;
32
+ readonly actor: SessionUser;
33
+ readonly now: Temporal.Instant;
34
+ readonly db: TenantDb;
35
+ readonly runner: DbRunner;
36
+ readonly registry: Registry;
37
+ readonly revokeSessions: boolean;
38
+ };
39
+
40
+ // Shared by the owner-facing request-destruction handler and by system callers such as
41
+ // tenant-inactivity, so both start the same compliance-profile grace period.
42
+ export async function requestTenantDestruction(args: RequestTenantDestructionArgs) {
43
+ const { tenantId, actor, now, db, runner, registry } = args;
44
+ const row = await fetchOne<TenantLifecycleRow>(runner, tenantTable, { id: tenantId });
45
+ if (!row) {
46
+ return writeFailure(new UnprocessableError("tenant_not_found", { details: { tenantId } }));
47
+ }
48
+ if (row.status !== "active") {
49
+ return writeFailure(
50
+ new UnprocessableError("tenant_not_active", {
51
+ details: { status: row.status },
52
+ }),
53
+ );
54
+ }
55
+
56
+ const { profile } = await resolveProfileForTenant({ db: runner, tenantId });
57
+ const gracePeriodEnd = addDurationSpec(now, profile.tenantDestroyGracePeriod);
58
+
59
+ const update = await crud.update(
60
+ {
61
+ id: tenantId,
62
+ changes: {
63
+ status: "destroyRequested",
64
+ destroyRequestedAt: now,
65
+ destroyRequestedBy: actor.id,
66
+ gracePeriodEnd,
67
+ },
68
+ },
69
+ actor,
70
+ db,
71
+ { skipOptimisticLock: true },
72
+ );
73
+ if (!update.isSuccess) return update;
74
+ invalidateTenantLifecycleGate(tenantId);
75
+
76
+ await appendDomainEventCore(
77
+ {
78
+ registry,
79
+ db: runner,
80
+ tenantId: SYSTEM_TENANT_ID,
81
+ userId: String(actor.id),
82
+ callSiteLabel: "tenant-lifecycle request-destruction",
83
+ callerFeature: TENANT_LIFECYCLE_FEATURE,
84
+ },
85
+ {
86
+ aggregateId: tenantId,
87
+ aggregateType: "tenant",
88
+ type: DESTRUCTION_REQUESTED_EVENT_QN,
89
+ payload: {
90
+ requestedBy: actor.id,
91
+ gracePeriodEnd: gracePeriodEnd.toString(),
92
+ },
93
+ },
94
+ );
95
+
96
+ if (args.revokeSessions) {
97
+ await revokeTenantSessions(runner, tenantId);
98
+ }
99
+
100
+ return {
101
+ isSuccess: true as const,
102
+ data: {
103
+ tenantId,
104
+ status: "destroyRequested" as const,
105
+ gracePeriodEnd: gracePeriodEnd.toString(),
106
+ },
107
+ };
108
+ }
@@ -0,0 +1,62 @@
1
+ // The tenant's retention configuration (compliance profile, retention overrides) decides which
2
+ // entities are blockDelete-held. It is erased in the "tenant-row" phase, after the hold check, because
3
+ // deleting it earlier would change the hold predicate while the tenant still waits on held rows.
4
+
5
+ import { createEventStoreExecutor } from "@cosmicdrift/kumiko-framework/db";
6
+ import {
7
+ createSystemUser,
8
+ type EntityDefinition,
9
+ type TenantDataHookCtx,
10
+ } from "@cosmicdrift/kumiko-framework/engine";
11
+ import {
12
+ tenantComplianceProfileEntity,
13
+ tenantComplianceProfileTable,
14
+ } from "../compliance-profiles/index.ts";
15
+ import {
16
+ tenantRetentionOverrideEntity,
17
+ tenantRetentionOverrideTable,
18
+ } from "../data-retention/index.ts";
19
+
20
+ export const COMPLIANCE_PROFILE_ENTITY_NAME = "tenant-compliance-profile";
21
+ export const RETENTION_OVERRIDE_ENTITY_NAME = "tenant-retention-override";
22
+
23
+ type ExecutorTable = Parameters<typeof createEventStoreExecutor>[0];
24
+
25
+ async function forgetAllTenantRows(
26
+ ctx: TenantDataHookCtx,
27
+ table: ExecutorTable,
28
+ entity: EntityDefinition,
29
+ entityName: string,
30
+ ): Promise<void> {
31
+ const executor = createEventStoreExecutor(table, entity, { entityName });
32
+ const user = createSystemUser(ctx.tenantId);
33
+ const rows = await ctx.db.selectMany<{ id: string }>(table, { tenantId: ctx.tenantId });
34
+ for (const row of rows) {
35
+ const forgotten = await executor.forget({ id: row.id }, user, ctx.db);
36
+ if (!forgotten.isSuccess) {
37
+ throw new Error(
38
+ `tenant-lifecycle: failed to forget ${entityName} ${row.id} for tenant ${ctx.tenantId}: ${forgotten.error.message}`,
39
+ );
40
+ }
41
+ }
42
+ }
43
+
44
+ export async function complianceProfileTenantDestroyHook(ctx: TenantDataHookCtx): Promise<void> {
45
+ await forgetAllTenantRows(
46
+ ctx,
47
+ tenantComplianceProfileTable,
48
+ tenantComplianceProfileEntity,
49
+ COMPLIANCE_PROFILE_ENTITY_NAME,
50
+ );
51
+ }
52
+
53
+ export async function retentionOverrideTenantDestroyHook(ctx: TenantDataHookCtx): Promise<void> {
54
+ // skip: data-retention is optional, without it the override table does not exist
55
+ if (!ctx.registry.getEntity(RETENTION_OVERRIDE_ENTITY_NAME)) return;
56
+ await forgetAllTenantRows(
57
+ ctx,
58
+ tenantRetentionOverrideTable,
59
+ tenantRetentionOverrideEntity,
60
+ RETENTION_OVERRIDE_ENTITY_NAME,
61
+ );
62
+ }