@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
@@ -0,0 +1,180 @@
1
+ import { configuredPiiSubjectKms } from "@cosmicdrift/kumiko-framework/crypto";
2
+ import { createEventStoreExecutor } from "@cosmicdrift/kumiko-framework/db";
3
+ import { deleteStoredFileAndDerivatives } from "@cosmicdrift/kumiko-framework/derivatives";
4
+ import type {
5
+ UserDataDeleteHook,
6
+ UserDataExportHook,
7
+ UserDataHookCtx,
8
+ } from "@cosmicdrift/kumiko-framework/engine";
9
+ import { SYSTEM_TENANT_ID } from "@cosmicdrift/kumiko-framework/engine";
10
+ import { InternalError } from "@cosmicdrift/kumiko-framework/errors";
11
+ import { fileRefEntity, fileRefsTable } from "@cosmicdrift/kumiko-framework/files";
12
+ import { collectErasureFailure, decryptStoredPii, throwIfErasureFailed } from "../shared/index.ts";
13
+ import { userTable } from "../user/index.ts";
14
+ import { normalizeEmail, platformActor, replyExecutor, requestExecutor } from "./lib.ts";
15
+ import {
16
+ CONTACT_REPLY_ENTITY,
17
+ CONTACT_REQUEST_ENTITY,
18
+ CONTACT_UPLOAD_FIELD,
19
+ } from "./web/constants.ts";
20
+
21
+ const PII_DECRYPT_REASON = "contact:user-data";
22
+ const ERASE_REASON = "contact:user-data-forget";
23
+ const LOOKUP_LIMIT = 200;
24
+
25
+ // Anonymous requests are matched by email, so the user must have proven they own it: otherwise
26
+ // registering with someone else's address would expose or erase that person's requests.
27
+ async function resolveVerifiedUserEmail(ctx: UserDataHookCtx): Promise<string | null> {
28
+ const row = await ctx.db.fetchOne<{ email: string; emailVerified: boolean }>(userTable, {
29
+ id: ctx.userId,
30
+ });
31
+ if (row?.emailVerified !== true) return null;
32
+ if (ctx.userEmailBeforeDelete) return normalizeEmail(ctx.userEmailBeforeDelete);
33
+ return normalizeEmail(await decryptStoredPii(row.email, "email", PII_DECRYPT_REASON));
34
+ }
35
+
36
+ async function findRequests(ctx: UserDataHookCtx) {
37
+ const byUser = await requestExecutor.list(
38
+ { filter: { field: "reporterUserId", op: "eq", value: ctx.userId }, limit: LOOKUP_LIMIT },
39
+ platformActor(),
40
+ ctx.db,
41
+ );
42
+ const email = await resolveVerifiedUserEmail(ctx);
43
+ const byEmail = email
44
+ ? await requestExecutor.list(
45
+ { filter: { field: "email", op: "eq", value: email }, limit: LOOKUP_LIMIT },
46
+ platformActor(),
47
+ ctx.db,
48
+ )
49
+ : { rows: [] };
50
+ const unique = new Map(byUser.rows.map((row) => [row.id, row]));
51
+ for (const row of byEmail.rows) unique.set(row.id, row);
52
+ return [...unique.values()];
53
+ }
54
+
55
+ const fileRefExecutor = createEventStoreExecutor(fileRefsTable, fileRefEntity, {
56
+ entityName: "fileRef",
57
+ });
58
+
59
+ // Attachments are copied into the system tenant and bound to the request or reply row.
60
+ async function findAttachments(ctx: UserDataHookCtx, entity: string, id: string) {
61
+ return ctx.db.selectMany<{ id: string; storageKey: string; fileName: string }>(fileRefsTable, {
62
+ tenantId: SYSTEM_TENANT_ID,
63
+ entityType: entity,
64
+ entityId: id,
65
+ fieldName: CONTACT_UPLOAD_FIELD,
66
+ });
67
+ }
68
+
69
+ // Bytes first, then the fileRef row: a crash in between leaves a row whose delete converges on the
70
+ // next run, never bytes without a row. A failing byte delete aborts, like the generic fileRef hook.
71
+ async function purgeAttachments(ctx: UserDataHookCtx, entity: string, id: string): Promise<void> {
72
+ const attachments = await findAttachments(ctx, entity, id);
73
+ // skip: a row without attachments has no bytes to erase and needs no storage provider
74
+ if (attachments.length === 0) return;
75
+ const provider = await ctx.buildStorageProvider?.(SYSTEM_TENANT_ID);
76
+ if (!provider) {
77
+ throw new InternalError({
78
+ message: `[contact:user-data] no file storage resolvable, attachments of ${entity} ${id} cannot be erased`,
79
+ });
80
+ }
81
+ for (const attachment of attachments) {
82
+ const failed = await deleteStoredFileAndDerivatives(
83
+ attachment.storageKey,
84
+ provider,
85
+ "contact:user-data",
86
+ );
87
+ if (failed.length > 0) {
88
+ throw new InternalError({
89
+ message: `[contact:user-data] ${failed.length} attachment byte delete(s) failed for ${entity} ${id}`,
90
+ });
91
+ }
92
+ }
93
+ const failures: string[] = [];
94
+ for (const attachment of attachments) {
95
+ collectErasureFailure(
96
+ await fileRefExecutor.forget({ id: attachment.id }, platformActor(), ctx.db),
97
+ "fileRef",
98
+ attachment.id,
99
+ failures,
100
+ );
101
+ }
102
+ throwIfErasureFailed(failures);
103
+ }
104
+
105
+ async function findReplies(ctx: UserDataHookCtx, requestId: string) {
106
+ const found = await replyExecutor.list(
107
+ { filter: { field: "requestId", op: "eq", value: requestId }, limit: LOOKUP_LIMIT },
108
+ platformActor(),
109
+ ctx.db,
110
+ );
111
+ return found.rows;
112
+ }
113
+
114
+ export const contactExportHook: UserDataExportHook = async (ctx) => {
115
+ const requests = await findRequests(ctx);
116
+ if (requests.length === 0) return null;
117
+ const rows = [];
118
+ for (const request of requests) {
119
+ const replies = await findReplies(ctx, request.id);
120
+ rows.push({
121
+ kind: request.kind,
122
+ status: request.status,
123
+ source: request.source,
124
+ subject: request.subject,
125
+ message: request.message,
126
+ name: request.name,
127
+ email: request.email,
128
+ phone: request.phone,
129
+ page: request.page,
130
+ submittedAt: String(request.submittedAt),
131
+ attachments: (await findAttachments(ctx, CONTACT_REQUEST_ENTITY, request.id)).map(
132
+ (file) => file.fileName,
133
+ ),
134
+ replies: replies.map((reply) => ({
135
+ message: reply.message,
136
+ authorName: reply.authorName,
137
+ sentAt: String(reply.sentAt),
138
+ })),
139
+ });
140
+ }
141
+ return { entity: CONTACT_REQUEST_ENTITY, rows };
142
+ };
143
+
144
+ // Requests and replies carry no statutory retention duty, so both strategies erase: rows are
145
+ // purged through the executor (replays on rebuild) and the record subject keys are shredded so
146
+ // the event log's ciphertext becomes unreadable. Replies go with their request.
147
+ export const contactDeleteHook: UserDataDeleteHook = async (ctx) => {
148
+ const kms = configuredPiiSubjectKms();
149
+ const failures: string[] = [];
150
+ const erase = async (
151
+ entity: string,
152
+ id: string,
153
+ forgotten: Parameters<typeof collectErasureFailure>[0],
154
+ ) => {
155
+ collectErasureFailure(forgotten, entity, id, failures);
156
+ if (forgotten.isSuccess && kms) {
157
+ await kms.eraseKey(
158
+ { kind: "record", entity, id },
159
+ { requestId: ERASE_REASON, userId: ctx.userId, eraseReason: ERASE_REASON },
160
+ );
161
+ }
162
+ };
163
+ for (const request of await findRequests(ctx)) {
164
+ for (const reply of await findReplies(ctx, request.id)) {
165
+ await purgeAttachments(ctx, CONTACT_REPLY_ENTITY, reply.id);
166
+ await erase(
167
+ CONTACT_REPLY_ENTITY,
168
+ reply.id,
169
+ await replyExecutor.forget({ id: reply.id }, platformActor(), ctx.db),
170
+ );
171
+ }
172
+ await purgeAttachments(ctx, CONTACT_REQUEST_ENTITY, request.id);
173
+ await erase(
174
+ CONTACT_REQUEST_ENTITY,
175
+ request.id,
176
+ await requestExecutor.forget({ id: request.id }, platformActor(), ctx.db),
177
+ );
178
+ }
179
+ throwIfErasureFailed(failures);
180
+ };
@@ -0,0 +1,160 @@
1
+ // Pure string constants, safe for browser code (see waitlist/web/constants.ts).
2
+ export const CONTACT_FEATURE = "contact" as const;
3
+
4
+ export const CONTACT_KIND = {
5
+ Question: "question",
6
+ Contact: "contact",
7
+ Bug: "bug",
8
+ Wish: "wish",
9
+ } as const;
10
+ export type ContactKind = (typeof CONTACT_KIND)[keyof typeof CONTACT_KIND];
11
+
12
+ export const CONTACT_WEBSITE_KINDS = [
13
+ CONTACT_KIND.Question,
14
+ CONTACT_KIND.Contact,
15
+ CONTACT_KIND.Bug,
16
+ ] as const;
17
+ export const CONTACT_ADMIN_KINDS = [
18
+ CONTACT_KIND.Question,
19
+ CONTACT_KIND.Bug,
20
+ CONTACT_KIND.Wish,
21
+ ] as const;
22
+
23
+ export const CONTACT_STATUS = {
24
+ Open: "open",
25
+ Answered: "answered",
26
+ Done: "done",
27
+ } as const;
28
+ export type ContactStatus = (typeof CONTACT_STATUS)[keyof typeof CONTACT_STATUS];
29
+
30
+ export const CONTACT_SOURCE = {
31
+ Website: "website",
32
+ Admin: "admin",
33
+ } as const;
34
+ export type ContactSource = (typeof CONTACT_SOURCE)[keyof typeof CONTACT_SOURCE];
35
+
36
+ export const CONTACT_REPLY_CHANNELS = {
37
+ Email: "email",
38
+ EmailAndInApp: "email+inApp",
39
+ } as const;
40
+ export type ContactReplyChannels =
41
+ (typeof CONTACT_REPLY_CHANNELS)[keyof typeof CONTACT_REPLY_CHANNELS];
42
+
43
+ export const CONTACT_ORIGIN = {
44
+ Website: "website",
45
+ AdminReport: "admin-report",
46
+ } as const;
47
+ export type ContactOrigin = (typeof CONTACT_ORIGIN)[keyof typeof CONTACT_ORIGIN];
48
+
49
+ export const CONTACT_DELIVERY_CHANNEL = {
50
+ Email: "email",
51
+ Telegram: "telegram",
52
+ ReplyEmail: "reply-email",
53
+ ReplyInApp: "reply-in-app",
54
+ } as const;
55
+ export type ContactDeliveryChannel =
56
+ (typeof CONTACT_DELIVERY_CHANNEL)[keyof typeof CONTACT_DELIVERY_CHANNEL];
57
+
58
+ export const CONTACT_DELIVERY_STATUS = {
59
+ Pending: "pending",
60
+ Delivered: "delivered",
61
+ Failed: "failed",
62
+ Skipped: "skipped",
63
+ Read: "read",
64
+ } as const;
65
+ export type ContactDeliveryStatus =
66
+ (typeof CONTACT_DELIVERY_STATUS)[keyof typeof CONTACT_DELIVERY_STATUS];
67
+
68
+ export type ContactPhoneMode = "off" | "optional" | "required";
69
+
70
+ export const ContactHandlers = {
71
+ submit: "contact:write:submit",
72
+ report: "contact:write:report",
73
+ reply: "contact:write:reply",
74
+ markDone: "contact:write:mark-done",
75
+ sendTest: "contact:write:send-test",
76
+ forwardRequest: "contact:write:forward-request",
77
+ sendReplyMail: "contact:write:send-reply-mail",
78
+ notifyReporterInApp: "contact:write:notify-reporter-in-app",
79
+ } as const;
80
+
81
+ export const ContactQueries = {
82
+ challenge: "contact:query:challenge",
83
+ openCount: "contact:query:open-count",
84
+ requestDetail: "contact:query:request-detail",
85
+ replies: "contact:query:replies",
86
+ requestDelivery: "contact:query:request-delivery",
87
+ // Entity-convention list QN: entityList screens resolve their query by this shape.
88
+ requestList: "contact:query:contact-request:list",
89
+ } as const;
90
+
91
+ export const ContactScreens = {
92
+ requestList: "contact:screen:request-list",
93
+ requestDetail: "contact:screen:request-detail",
94
+ report: "contact:screen:report",
95
+ reply: "contact:screen:reply",
96
+ replyMail: "contact:screen:reply-mail",
97
+ forwarding: "contact:screen:forwarding",
98
+ } as const;
99
+
100
+ // Files field of both upload forms (report, reply); the uploads are pending under the screen QN.
101
+ export const CONTACT_UPLOAD_FIELD = "fileIds" as const;
102
+
103
+ export const ContactConfigKeys = {
104
+ replyTo: "contact:config:reply-to",
105
+ telegramChat: "contact:config:telegram-chat",
106
+ } as const;
107
+
108
+ export const ContactErrors = {
109
+ telegramChatMissing: "telegram_chat_missing",
110
+ telegramTestFailed: "telegram_test_failed",
111
+ notFound: "contact_request_not_found",
112
+ phoneNotAllowed: "contact_phone_not_allowed",
113
+ phoneRequired: "contact_phone_required",
114
+ reporterEmailMissing: "contact_reporter_email_missing",
115
+ attachmentNotFound: "contact_attachment_not_found",
116
+ } as const;
117
+
118
+ export const CONTACT_NOTIFICATION_TYPES = {
119
+ newRequest: "contact:notify:new-request",
120
+ confirmation: "contact:notify:confirmation",
121
+ acknowledgement: "contact:notify:acknowledgement",
122
+ reply: "contact:notify:reply",
123
+ replyInApp: "contact:notify:reply-in-app",
124
+ test: "contact:notify:test",
125
+ } as const;
126
+
127
+ export const CONTACT_CLIENT_PATH = "/contact/client.js" as const;
128
+
129
+ export const CONTACT_FIELD_LIMITS = {
130
+ name: 120,
131
+ email: 254,
132
+ phone: 40,
133
+ subject: 200,
134
+ message: 5000,
135
+ locale: 35,
136
+ honeypot: 500,
137
+ page: 300,
138
+ challenge: 64,
139
+ nonce: 32,
140
+ } as const;
141
+
142
+ export const CONTACT_MAX_FILES = 5;
143
+
144
+ export const CONTACT_SUBJECT_MAX_CHARS = 80;
145
+
146
+ export const CONTACT_POW_BITS = { min: 8, max: 26, default: 19 } as const;
147
+ export const CONTACT_DEFAULT_MIN_SUBMIT_SECONDS = 3;
148
+ export const CONTACT_DEFAULT_CHALLENGE_TTL_MINUTES = 30;
149
+ export const CONTACT_CHALLENGE_REDIS_PREFIX = "contact:challenge:" as const;
150
+
151
+ export const CONTACT_REQUEST_ENTITY = "contact-request" as const;
152
+ export const CONTACT_REPLY_ENTITY = "contact-reply" as const;
153
+
154
+ export const contactIdempotencyKeys = {
155
+ admins: (requestId: string) => `contact:request:${requestId}:admins`,
156
+ telegram: (requestId: string) => `contact:request:${requestId}:telegram`,
157
+ confirmation: (requestId: string) => `contact:request:${requestId}:confirmation`,
158
+ reply: (replyId: string) => `contact:reply:${replyId}`,
159
+ replyInApp: (replyId: string) => `contact:reply:${replyId}:in-app`,
160
+ } as const;
@@ -0,0 +1,29 @@
1
+ export {
2
+ CONTACT_ADMIN_KINDS,
3
+ CONTACT_CLIENT_PATH,
4
+ CONTACT_DELIVERY_CHANNEL,
5
+ CONTACT_DELIVERY_STATUS,
6
+ CONTACT_FEATURE,
7
+ CONTACT_FIELD_LIMITS,
8
+ CONTACT_KIND,
9
+ CONTACT_NOTIFICATION_TYPES,
10
+ CONTACT_ORIGIN,
11
+ CONTACT_REPLY_CHANNELS,
12
+ CONTACT_SOURCE,
13
+ CONTACT_STATUS,
14
+ CONTACT_SUBJECT_MAX_CHARS,
15
+ CONTACT_WEBSITE_KINDS,
16
+ ContactConfigKeys,
17
+ type ContactDeliveryChannel,
18
+ type ContactDeliveryStatus,
19
+ ContactErrors,
20
+ ContactHandlers,
21
+ type ContactKind,
22
+ type ContactOrigin,
23
+ type ContactPhoneMode,
24
+ ContactQueries,
25
+ type ContactReplyChannels,
26
+ ContactScreens,
27
+ type ContactSource,
28
+ type ContactStatus,
29
+ } from "./constants.ts";
@@ -24,8 +24,8 @@ import {
24
24
  } from "@cosmicdrift/kumiko-framework/db";
25
25
  import {
26
26
  defineWriteHandler,
27
- type EntityDefinition,
28
27
  type FeatureDefinition,
28
+ findEntity,
29
29
  type HandlerContext,
30
30
  parseTenantId,
31
31
  type SessionUser,
@@ -111,19 +111,6 @@ function subjectAggregateId(raw: SubjectIdInput): string {
111
111
  }
112
112
  }
113
113
 
114
- // The record subject names its own entity — resolve it against the registry
115
- // instead of trusting the payload straight into resolveTableName/SQL.
116
- function findRegisteredEntity(
117
- features: ReadonlyMap<string, FeatureDefinition>,
118
- entityName: string,
119
- ): EntityDefinition | undefined {
120
- for (const feature of features.values()) {
121
- const entity = feature.entities?.[entityName];
122
- if (entity) return entity;
123
- }
124
- return undefined;
125
- }
126
-
127
114
  // Tenant-scope guard: DataProtectionOfficer is a tenant-scoped role,
128
115
  // but the handler otherwise erases ANY subject cross-tenant on a raw
129
116
  // (un-scoped) client — a Tenant-A DPO who learns a Tenant-B subject id
@@ -148,7 +135,9 @@ async function resolveTenantScopeDenial(
148
135
  // Same fail-open rule as the user branch below — without the tenant
149
136
  // feature there is no tenant concept to enforce.
150
137
  if (!features.has("tenant")) return undefined;
151
- const entity = findRegisteredEntity(features, raw.entity);
138
+ // The record subject names its own entity — resolve it against the registry
139
+ // instead of trusting the payload straight into resolveTableName/SQL.
140
+ const entity = findEntity(features, raw.entity);
152
141
  const rowInTenant =
153
142
  entity !== undefined &&
154
143
  (await recordRowExistsInTenant(db, features, raw.entity, raw.id, user.tenantId));
@@ -202,7 +191,7 @@ async function resolveRetentionDenial(
202
191
  writeFailure(
203
192
  new AccessDeniedError({ details: { reason: TARGET_RECORD_RETENTION_BLOCK_DELETE } }),
204
193
  );
205
- const entity = findRegisteredEntity(features, raw.entity);
194
+ const entity = findEntity(features, raw.entity);
206
195
  if (entity?.retention?.strategy === "blockDelete") return deny();
207
196
  if (!features.has("data-retention")) return undefined;
208
197
 
@@ -1,4 +1,10 @@
1
1
  [
2
+ {
3
+ "version": "0.407.0",
4
+ "type": "fix",
5
+ "title": "Anonymize no longer emits one event per run for encrypted fields",
6
+ "detail": "The retention cleanup compared the encrypted ciphertext with the anonymized value and treated every row with encrypted fields as still needing anonymization, so each run appended another anonymize event. The check now looks at the decrypted value, so already anonymized rows are left alone."
7
+ },
2
8
  {
3
9
  "version": "0.372.0",
4
10
  "type": "improvement",
@@ -1,4 +1,5 @@
1
1
  import { defineFeature, type FeatureDefinition } from "@cosmicdrift/kumiko-framework/engine";
2
+ import { findTenantDestructionHoldProvider } from "../shared/index.ts";
2
3
  import { policyForQuery } from "./handlers/policy-for.query.ts";
3
4
  import { resolveTenantRetentionPreset } from "./resolve-tenant-preset.ts";
4
5
  import { runRetentionCleanup } from "./run-retention-cleanup.ts";
@@ -87,7 +88,6 @@ export function createDataRetentionFeature(): FeatureDefinition {
87
88
  // skip: cron fired without a perTenant fan-out tenant — nothing scoped
88
89
  return;
89
90
  }
90
- const T = (await import("@cosmicdrift/kumiko-framework/time")).getTemporal();
91
91
  const cleanupDb =
92
92
  ctx.db.unsafeRaw() as import("@cosmicdrift/kumiko-framework/db").DbConnection; // @cast-boundary db-operator — jobs never run inside a DbTx
93
93
  const tenantPreset = await resolveTenantRetentionPreset({
@@ -95,14 +95,28 @@ export function createDataRetentionFeature(): FeatureDefinition {
95
95
  registry: ctx.registry,
96
96
  tenantId,
97
97
  });
98
+ const now = ctx.tz.now();
99
+ const destructionHold = findTenantDestructionHoldProvider(ctx.registry);
100
+ const parked = destructionHold
101
+ ? await destructionHold.isParked({ db: cleanupDb, tenantId })
102
+ : false;
98
103
  const result = await runRetentionCleanup({
99
104
  db: cleanupDb,
100
105
  registry: ctx.registry,
101
106
  tenantId,
102
107
  preloadedTenantPreset: tenantPreset,
103
- now: T.Now.instant(),
108
+ now,
109
+ purgeExpiredBlockDelete: parked,
104
110
  files: ctx.services.files,
105
111
  });
112
+ if (destructionHold && parked) {
113
+ await destructionHold.releaseIfFree({
114
+ db: cleanupDb,
115
+ registry: ctx.registry,
116
+ tenantId,
117
+ now,
118
+ });
119
+ }
106
120
  if (result.skipped.length > 0) {
107
121
  // biome-ignore lint/suspicious/noConsole: operator-visibility for skipped entities
108
122
  console.warn(
@@ -25,3 +25,8 @@ export {
25
25
  type RunRetentionCleanupResult,
26
26
  runRetentionCleanup,
27
27
  } from "./run-retention-cleanup.ts";
28
+ export {
29
+ type DestructionHold,
30
+ holdBlockDeleteRowsForDestruction,
31
+ tenantHasBlockDeleteRows,
32
+ } from "./tenant-destruction-hold.ts";