@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
@@ -0,0 +1,464 @@
1
+ import { access, createFilesField, createTextField } from "@cosmicdrift/kumiko-framework/engine";
2
+ import { DELIVERY_LOG_SCREEN_ID } from "../delivery/index.js";
3
+ import { REPORT_ACCESS } from "./handlers/access.js";
4
+ import { CONTACT_ADMIN_KINDS, CONTACT_DELIVERY_STATUS, CONTACT_FEATURE, CONTACT_MAX_FILES, CONTACT_ORIGIN, CONTACT_REPLY_CHANNELS, CONTACT_STATUS, CONTACT_UPLOAD_FIELD, ContactConfigKeys, ContactHandlers, ContactQueries, } from "./web/constants.js";
5
+ const MAX_FILE_SIZE = "10MB";
6
+ const REQUEST_FIELD = `${CONTACT_FEATURE}:entity:contact-request:field`;
7
+ const DELIVERY_FIELD = `${CONTACT_FEATURE}:entity:contact-delivery:field`;
8
+ const TELEGRAM_BOT_TOKEN_SECRET = "channel-telegram:secret:bot-token";
9
+ export const REPORT_FIELD_LABEL = `${CONTACT_FEATURE}:report.field`;
10
+ export const REPLY_FIELD_LABEL = `${CONTACT_FEATURE}:reply.field`;
11
+ function attachmentsField() {
12
+ return createFilesField({
13
+ personal: false,
14
+ reason: "is_business_data",
15
+ maxCount: CONTACT_MAX_FILES,
16
+ maxSize: MAX_FILE_SIZE,
17
+ display: "dropzone",
18
+ });
19
+ }
20
+ // The files the form uploads stay pending under this screen's QN until the handler takes them
21
+ // over (copyPendingFileRefsToTenant).
22
+ function createReportScreen(opts, settings) {
23
+ const withPhone = settings.phone !== "off";
24
+ return {
25
+ id: "report",
26
+ type: "actionForm",
27
+ dormant: true,
28
+ handler: ContactHandlers.report,
29
+ summary: {
30
+ title: `${CONTACT_FEATURE}:report.hint`,
31
+ subtitle: `${CONTACT_FEATURE}:report.summary`,
32
+ },
33
+ fields: {
34
+ kind: { type: "select", options: CONTACT_ADMIN_KINDS, required: true, display: "radio" },
35
+ ...(withPhone && {
36
+ phone: { type: "text", format: "phone", required: settings.phone === "required" },
37
+ }),
38
+ subject: { type: "text", required: true },
39
+ message: { type: "longText", required: true },
40
+ [CONTACT_UPLOAD_FIELD]: attachmentsField(),
41
+ },
42
+ layout: {
43
+ sections: [
44
+ {
45
+ title: `${CONTACT_FEATURE}:report.section`,
46
+ description: `${CONTACT_FEATURE}:report.section.description`,
47
+ fields: [
48
+ "kind",
49
+ ...(withPhone ? ["phone"] : []),
50
+ { field: "subject", span: 2 },
51
+ "message",
52
+ CONTACT_UPLOAD_FIELD,
53
+ ],
54
+ },
55
+ ],
56
+ },
57
+ fieldLabels: {
58
+ kind: `${REPORT_FIELD_LABEL}.kind`,
59
+ phone: `${REPORT_FIELD_LABEL}.phone`,
60
+ subject: `${REPORT_FIELD_LABEL}.subject`,
61
+ message: `${REPORT_FIELD_LABEL}.message`,
62
+ [CONTACT_UPLOAD_FIELD]: `${REPORT_FIELD_LABEL}.files`,
63
+ },
64
+ submitLabel: `${CONTACT_FEATURE}:report.submit`,
65
+ ...(opts.reportCancelTarget !== undefined && { cancelTarget: opts.reportCancelTarget }),
66
+ successMessage: `${CONTACT_FEATURE}:report.success`,
67
+ access: REPORT_ACCESS,
68
+ };
69
+ }
70
+ // The two reply screens differ only in the summary text: the screen QN is also the entityType the
71
+ // pending uploads hang under, so reply.write picks the variant by the reporter's reply channels.
72
+ function createReplyScreen(id, summarySubtitle) {
73
+ return {
74
+ id,
75
+ type: "actionForm",
76
+ dormant: true,
77
+ handler: ContactHandlers.reply,
78
+ summary: { title: `${CONTACT_FEATURE}:reply.title`, subtitle: summarySubtitle },
79
+ fields: {
80
+ requestId: { type: "text", required: true },
81
+ message: { type: "longText", required: true },
82
+ [CONTACT_UPLOAD_FIELD]: attachmentsField(),
83
+ markDone: { type: "boolean" },
84
+ name: { type: "text" },
85
+ email: { type: "text" },
86
+ replyTo: { type: "text" },
87
+ },
88
+ layout: {
89
+ sections: [
90
+ {
91
+ title: `${CONTACT_FEATURE}:reply.section`,
92
+ description: `${CONTACT_FEATURE}:reply.section.description`,
93
+ fields: [
94
+ { field: "requestId", visible: false },
95
+ { field: "name", visible: false },
96
+ { field: "email", visible: false },
97
+ { field: "replyTo", visible: false },
98
+ "message",
99
+ CONTACT_UPLOAD_FIELD,
100
+ "markDone",
101
+ ],
102
+ },
103
+ ],
104
+ },
105
+ fieldLabels: {
106
+ message: `${REPLY_FIELD_LABEL}.message`,
107
+ [CONTACT_UPLOAD_FIELD]: `${REPLY_FIELD_LABEL}.files`,
108
+ markDone: `${REPLY_FIELD_LABEL}.mark-done`,
109
+ },
110
+ submitLabel: `${CONTACT_FEATURE}:reply.submit`,
111
+ access: { roles: access.systemAdmin },
112
+ };
113
+ }
114
+ const requestListScreen = {
115
+ id: "request-list",
116
+ type: "entityList",
117
+ entity: "contact-request",
118
+ dormant: true,
119
+ allowCreate: false,
120
+ searchable: true,
121
+ columns: [
122
+ { field: "submittedAt", display: "datetime" },
123
+ "kind",
124
+ { field: "name", label: `${CONTACT_FEATURE}:list.from` },
125
+ { field: "reporterTenantName", label: `${REQUEST_FIELD}:reporterTenantName` },
126
+ { field: "subject", hideOnNarrow: true },
127
+ {
128
+ field: "source",
129
+ hideOnNarrow: true,
130
+ renderer: { format: "enumOption", keyPrefix: `${REQUEST_FIELD}:source:option:` },
131
+ },
132
+ { field: "fileCount", label: `${REQUEST_FIELD}:fileCount`, hideOnNarrow: true },
133
+ "status",
134
+ ],
135
+ facets: {
136
+ status: {
137
+ display: "chips",
138
+ showCounts: true,
139
+ extraOptions: [
140
+ { id: "all", label: `${CONTACT_FEATURE}:filter.all`, values: [], position: "start" },
141
+ ],
142
+ },
143
+ kind: { display: "select" },
144
+ source: { display: "select" },
145
+ },
146
+ defaultFilters: { status: [CONTACT_STATUS.Open] },
147
+ defaultSort: { field: "submittedAt", dir: "desc" },
148
+ rowActions: [
149
+ {
150
+ kind: "navigate",
151
+ id: "open",
152
+ label: `${CONTACT_FEATURE}:action.open`,
153
+ screen: "request-detail",
154
+ entityId: "id",
155
+ rowClick: true,
156
+ },
157
+ {
158
+ kind: "writeHandler",
159
+ id: "mark-done",
160
+ label: `${CONTACT_FEATURE}:action.mark-done`,
161
+ handler: ContactHandlers.markDone,
162
+ payload: { pick: ["id"] },
163
+ visible: { field: "status", ne: CONTACT_STATUS.Done },
164
+ },
165
+ ],
166
+ bulkActions: [{ id: "mark-done", rowAction: "mark-done" }],
167
+ access: { roles: access.systemAdmin },
168
+ };
169
+ const deliveryStatusTones = {
170
+ [CONTACT_DELIVERY_STATUS.Pending]: "warn",
171
+ [CONTACT_DELIVERY_STATUS.Delivered]: "ok",
172
+ [CONTACT_DELIVERY_STATUS.Failed]: "bad",
173
+ [CONTACT_DELIVERY_STATUS.Skipped]: "neutral",
174
+ [CONTACT_DELIVERY_STATUS.Read]: "accent",
175
+ };
176
+ function detailLinkTarget(link, defaultScreen) {
177
+ if (link === false)
178
+ return undefined;
179
+ return link ?? defaultScreen;
180
+ }
181
+ function createRequestDetailScreen(opts, settings) {
182
+ const userScreen = detailLinkTarget(opts.detailLinks?.user, "user-edit");
183
+ const tenantScreen = detailLinkTarget(opts.detailLinks?.tenant, "tenant-edit");
184
+ return {
185
+ id: "request-detail",
186
+ type: "projectionDetail",
187
+ dormant: true,
188
+ query: ContactQueries.requestDetail,
189
+ listScreenId: "request-list",
190
+ header: {
191
+ title: "subject",
192
+ subtitle: [
193
+ {
194
+ field: "kind",
195
+ format: { format: "enumOption", keyPrefix: `${REQUEST_FIELD}:kind:option:` },
196
+ },
197
+ {
198
+ field: "name",
199
+ ...(userScreen !== undefined && {
200
+ navigate: { screen: userScreen, entityId: "reporterUserId" },
201
+ }),
202
+ },
203
+ {
204
+ field: "reporterTenantName",
205
+ ...(tenantScreen !== undefined && {
206
+ navigate: { screen: tenantScreen, entityId: "reporterTenantId" },
207
+ }),
208
+ },
209
+ {
210
+ field: "submittedAt",
211
+ format: { format: "timestamp", dateStyle: "medium", timeStyle: "short" },
212
+ },
213
+ ],
214
+ status: "status",
215
+ statusFormat: { format: "enumOption", keyPrefix: `${REQUEST_FIELD}:status:option:` },
216
+ statusTones: {
217
+ [CONTACT_STATUS.Open]: "warn",
218
+ [CONTACT_STATUS.Answered]: "accent",
219
+ [CONTACT_STATUS.Done]: "ok",
220
+ },
221
+ },
222
+ actions: [
223
+ {
224
+ kind: "writeHandler",
225
+ id: "mark-done",
226
+ label: `${CONTACT_FEATURE}:action.mark-done`,
227
+ handler: ContactHandlers.markDone,
228
+ icon: "check-circle",
229
+ style: "secondary",
230
+ payload: { pick: ["id"] },
231
+ visible: { field: "status", ne: CONTACT_STATUS.Done },
232
+ },
233
+ {
234
+ kind: "drawer",
235
+ id: "reply",
236
+ icon: "mail",
237
+ style: "primary",
238
+ label: `${CONTACT_FEATURE}:action.reply`,
239
+ screen: "reply",
240
+ params: { map: { requestId: "id", name: "name", email: "email", replyTo: "replyTo" } },
241
+ title: "screen:reply.title",
242
+ visible: { field: "replyChannels", eq: CONTACT_REPLY_CHANNELS.EmailAndInApp },
243
+ },
244
+ {
245
+ kind: "drawer",
246
+ id: "reply-mail",
247
+ icon: "mail",
248
+ style: "primary",
249
+ label: `${CONTACT_FEATURE}:action.reply`,
250
+ screen: "reply-mail",
251
+ params: { map: { requestId: "id", name: "name", email: "email", replyTo: "replyTo" } },
252
+ title: "screen:reply-mail.title",
253
+ visible: { field: "replyChannels", eq: CONTACT_REPLY_CHANNELS.Email },
254
+ },
255
+ ],
256
+ primaryAction: "reply",
257
+ inlineActions: ["mark-done"],
258
+ fieldLabels: {
259
+ message: `${REQUEST_FIELD}:message`,
260
+ fileIds: `${CONTACT_FEATURE}:detail.attachments`,
261
+ name: `${REQUEST_FIELD}:name`,
262
+ email: `${REQUEST_FIELD}:email`,
263
+ phone: `${REQUEST_FIELD}:phone`,
264
+ reporterTenantPlan: `${REQUEST_FIELD}:reporterTenantPlan`,
265
+ origin: `${REQUEST_FIELD}:origin`,
266
+ page: `${REQUEST_FIELD}:page`,
267
+ versionLabel: `${REQUEST_FIELD}:versionLabel`,
268
+ browser: `${REQUEST_FIELD}:browser`,
269
+ },
270
+ layout: {
271
+ sections: [
272
+ { title: `${CONTACT_FEATURE}:detail.section.message`, fields: ["message"] },
273
+ {
274
+ kind: "relatedList",
275
+ readOnly: true,
276
+ title: `${CONTACT_FEATURE}:detail.section.replies`,
277
+ query: ContactQueries.replies,
278
+ columns: [
279
+ {
280
+ field: "sentAt",
281
+ renderer: { format: "timestamp", dateStyle: "medium", timeStyle: "short" },
282
+ label: `${CONTACT_FEATURE}:entity:contact-reply:field:sentAt`,
283
+ },
284
+ {
285
+ field: "authorName",
286
+ label: `${CONTACT_FEATURE}:entity:contact-reply:field:authorName`,
287
+ },
288
+ { field: "message", label: `${CONTACT_FEATURE}:entity:contact-reply:field:message` },
289
+ ],
290
+ },
291
+ {
292
+ title: `${CONTACT_FEATURE}:detail.section.files`,
293
+ fields: [
294
+ {
295
+ field: CONTACT_UPLOAD_FIELD,
296
+ renderer: { format: "file" },
297
+ visible: { field: "fileCount", ne: 0 },
298
+ },
299
+ ],
300
+ },
301
+ {
302
+ title: `${CONTACT_FEATURE}:detail.section.sender`,
303
+ fields: [
304
+ "name",
305
+ { field: "email", format: "email" },
306
+ ...(settings.phone !== "off"
307
+ ? [
308
+ {
309
+ field: "phone",
310
+ format: "phone",
311
+ visible: { field: "phone", notIn: [null, ""] },
312
+ },
313
+ ]
314
+ : []),
315
+ "reporterTenantPlan",
316
+ ],
317
+ },
318
+ {
319
+ title: `${CONTACT_FEATURE}:detail.section.origin`,
320
+ fields: [
321
+ {
322
+ field: "origin",
323
+ renderer: { format: "enumOption", keyPrefix: `${REQUEST_FIELD}:origin:option:` },
324
+ },
325
+ { field: "page", visible: { field: "origin", eq: CONTACT_ORIGIN.Website } },
326
+ "versionLabel",
327
+ "browser",
328
+ ],
329
+ },
330
+ {
331
+ kind: "relatedList",
332
+ readOnly: true,
333
+ title: `${CONTACT_FEATURE}:detail.section.delivery`,
334
+ query: ContactQueries.requestDelivery,
335
+ toolbarActions: [
336
+ {
337
+ kind: "navigate",
338
+ id: "delivery-log",
339
+ label: `${CONTACT_FEATURE}:detail.delivery-log`,
340
+ screen: DELIVERY_LOG_SCREEN_ID,
341
+ },
342
+ ],
343
+ columns: [
344
+ {
345
+ field: "channel",
346
+ label: `${DELIVERY_FIELD}:channel`,
347
+ renderer: { format: "enumOption", keyPrefix: `${DELIVERY_FIELD}:channel:option:` },
348
+ },
349
+ { field: "recipient", label: `${DELIVERY_FIELD}:recipient` },
350
+ {
351
+ field: "at",
352
+ renderer: { format: "timestamp", dateStyle: "medium", timeStyle: "short" },
353
+ label: `${DELIVERY_FIELD}:at`,
354
+ },
355
+ {
356
+ field: "status",
357
+ label: `${DELIVERY_FIELD}:status`,
358
+ renderer: {
359
+ format: "enumOption",
360
+ keyPrefix: `${DELIVERY_FIELD}:status:option:`,
361
+ tones: deliveryStatusTones,
362
+ },
363
+ },
364
+ ],
365
+ },
366
+ {
367
+ kind: "extension",
368
+ title: `${CONTACT_FEATURE}:detail.section.notes`,
369
+ component: { react: { __component: "NotesSection" } },
370
+ entityName: "contact-request",
371
+ },
372
+ ],
373
+ },
374
+ access: { roles: access.systemAdmin },
375
+ };
376
+ }
377
+ function createForwardingScreen(telegram) {
378
+ return {
379
+ id: "forwarding",
380
+ type: "configEdit",
381
+ dormant: true,
382
+ scope: "system",
383
+ configKeys: {
384
+ replyTo: ContactConfigKeys.replyTo,
385
+ ...(telegram && { telegramChat: ContactConfigKeys.telegramChat }),
386
+ },
387
+ ...(telegram && { secretKeys: { botToken: TELEGRAM_BOT_TOKEN_SECRET } }),
388
+ fields: {
389
+ replyTo: createTextField({
390
+ format: "email",
391
+ maxLength: 254,
392
+ personal: false,
393
+ reason: "is_business_data",
394
+ }),
395
+ ...(telegram && {
396
+ telegramChat: createTextField({
397
+ maxLength: 64,
398
+ personal: false,
399
+ reason: "is_business_data",
400
+ }),
401
+ botToken: createTextField({
402
+ writeOnly: true,
403
+ maxLength: 200,
404
+ personal: false,
405
+ reason: "is_business_data",
406
+ }),
407
+ }),
408
+ },
409
+ layout: {
410
+ variant: "settings-list",
411
+ sections: [
412
+ {
413
+ title: `${CONTACT_FEATURE}:forwarding.email`,
414
+ description: `${CONTACT_FEATURE}:forwarding.email.description`,
415
+ fields: ["replyTo"],
416
+ },
417
+ ...(telegram
418
+ ? [
419
+ {
420
+ title: `${CONTACT_FEATURE}:forwarding.telegram`,
421
+ description: `${CONTACT_FEATURE}:forwarding.telegram.description`,
422
+ fields: ["telegramChat", "botToken"],
423
+ },
424
+ ]
425
+ : []),
426
+ ],
427
+ },
428
+ fieldLabels: {
429
+ replyTo: `${CONTACT_FEATURE}:config.reply-to.label`,
430
+ telegramChat: `${CONTACT_FEATURE}:config.telegram-chat.label`,
431
+ botToken: `${CONTACT_FEATURE}:config.bot-token.label`,
432
+ },
433
+ fieldDescriptions: {
434
+ replyTo: `${CONTACT_FEATURE}:config.reply-to.description`,
435
+ telegramChat: `${CONTACT_FEATURE}:config.telegram-chat.description`,
436
+ botToken: `${CONTACT_FEATURE}:config.bot-token.description`,
437
+ },
438
+ submitLabel: `${CONTACT_FEATURE}:forwarding.submit`,
439
+ ...(telegram && {
440
+ actions: [
441
+ {
442
+ id: "send-test",
443
+ handler: ContactHandlers.sendTest,
444
+ label: `${CONTACT_FEATURE}:config.send-test.label`,
445
+ description: `${CONTACT_FEATURE}:config.send-test.description`,
446
+ buttonLabel: `${CONTACT_FEATURE}:config.send-test.button`,
447
+ afterField: "botToken",
448
+ successMessage: `${CONTACT_FEATURE}:config.send-test.success`,
449
+ },
450
+ ],
451
+ }),
452
+ access: { roles: access.systemAdmin },
453
+ };
454
+ }
455
+ export function createContactScreens(opts, settings) {
456
+ return [
457
+ createReportScreen(opts, settings),
458
+ requestListScreen,
459
+ createRequestDetailScreen(opts, settings),
460
+ createReplyScreen("reply", `${CONTACT_FEATURE}:reply.summary.in-app`),
461
+ createReplyScreen("reply-mail", `${CONTACT_FEATURE}:reply.summary.mail`),
462
+ createForwardingScreen(opts.telegram === true),
463
+ ];
464
+ }
@@ -0,0 +1 @@
1
+ export declare function deriveSubjectFromMessage(message: string): string;
@@ -0,0 +1,13 @@
1
+ import { CONTACT_SUBJECT_MAX_CHARS } from "./web/constants.js";
2
+ // The website form has no subject field; the first non-empty line of the message stands in for it.
3
+ export function deriveSubjectFromMessage(message) {
4
+ const firstLine = message.split(/[\r\n]/).find((line) => line.trim() !== "") ?? "";
5
+ const trimmed = firstLine.trim();
6
+ const chars = [...trimmed];
7
+ if (chars.length <= CONTACT_SUBJECT_MAX_CHARS)
8
+ return trimmed;
9
+ return `${chars
10
+ .slice(0, CONTACT_SUBJECT_MAX_CHARS - 1)
11
+ .join("")
12
+ .trimEnd()}…`;
13
+ }
@@ -0,0 +1 @@
1
+ export declare function summarizeUserAgent(userAgent: string | undefined, locale: string): string | null;
@@ -0,0 +1,35 @@
1
+ // Order matters: Edge and Opera also say "Chrome", Chrome also says "Safari".
2
+ const BROWSER_PATTERNS = [
3
+ ["Edge", /\bEdg(?:e|A|iOS)?\/(\d+)/],
4
+ ["Opera", /\b(?:OPR|Opera)\/(\d+)/],
5
+ ["Firefox", /\b(?:Firefox|FxiOS)\/(\d+)/],
6
+ ["Chrome", /\b(?:Chrome|CriOS)\/(\d+)/],
7
+ ["Safari", /\bVersion\/(\d+)[\s\S]*\bSafari\//],
8
+ ];
9
+ // iOS and Android UAs also contain "Mac OS X" / "Linux", so they are tested first.
10
+ const OS_PATTERNS = [
11
+ ["iOS", /\b(?:iPhone|iPad|iPod)\b/],
12
+ ["Android", /\bAndroid\b/],
13
+ ["Windows", /\bWindows\b/],
14
+ ["macOS", /\bMac OS X\b|\bMacintosh\b/],
15
+ ["Linux", /\b(?:Linux|X11)\b/],
16
+ ];
17
+ const CONNECTOR_BY_LANGUAGE = { de: "auf", en: "on" };
18
+ function languageOf(locale) {
19
+ return locale.split("-")[0]?.toLowerCase() ?? "en";
20
+ }
21
+ // Null when the UA names no known browser; the browser column is a hint for operators, not an identity.
22
+ export function summarizeUserAgent(userAgent, locale) {
23
+ if (userAgent === undefined)
24
+ return null;
25
+ const browser = BROWSER_PATTERNS.map(([name, pattern]) => {
26
+ const version = pattern.exec(userAgent)?.[1];
27
+ return version === undefined ? undefined : `${name} ${version}`;
28
+ }).find((summary) => summary !== undefined);
29
+ if (browser === undefined)
30
+ return null;
31
+ const os = OS_PATTERNS.find(([, pattern]) => pattern.test(userAgent))?.[0];
32
+ if (os === undefined)
33
+ return browser;
34
+ return `${browser} ${CONNECTOR_BY_LANGUAGE[languageOf(locale)] ?? "on"} ${os}`;
35
+ }
@@ -0,0 +1,3 @@
1
+ import type { UserDataDeleteHook, UserDataExportHook } from "@cosmicdrift/kumiko-framework/engine";
2
+ export declare const contactExportHook: UserDataExportHook;
3
+ export declare const contactDeleteHook: UserDataDeleteHook;
@@ -0,0 +1,129 @@
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 { SYSTEM_TENANT_ID } from "@cosmicdrift/kumiko-framework/engine";
5
+ import { InternalError } from "@cosmicdrift/kumiko-framework/errors";
6
+ import { fileRefEntity, fileRefsTable } from "@cosmicdrift/kumiko-framework/files";
7
+ import { collectErasureFailure, decryptStoredPii, throwIfErasureFailed } from "../shared/index.js";
8
+ import { userTable } from "../user/index.js";
9
+ import { normalizeEmail, platformActor, replyExecutor, requestExecutor } from "./lib.js";
10
+ import { CONTACT_REPLY_ENTITY, CONTACT_REQUEST_ENTITY, CONTACT_UPLOAD_FIELD, } from "./web/constants.js";
11
+ const PII_DECRYPT_REASON = "contact:user-data";
12
+ const ERASE_REASON = "contact:user-data-forget";
13
+ const LOOKUP_LIMIT = 200;
14
+ // Anonymous requests are matched by email, so the user must have proven they own it: otherwise
15
+ // registering with someone else's address would expose or erase that person's requests.
16
+ async function resolveVerifiedUserEmail(ctx) {
17
+ const row = await ctx.db.fetchOne(userTable, {
18
+ id: ctx.userId,
19
+ });
20
+ if (row?.emailVerified !== true)
21
+ return null;
22
+ if (ctx.userEmailBeforeDelete)
23
+ return normalizeEmail(ctx.userEmailBeforeDelete);
24
+ return normalizeEmail(await decryptStoredPii(row.email, "email", PII_DECRYPT_REASON));
25
+ }
26
+ async function findRequests(ctx) {
27
+ const byUser = await requestExecutor.list({ filter: { field: "reporterUserId", op: "eq", value: ctx.userId }, limit: LOOKUP_LIMIT }, platformActor(), ctx.db);
28
+ const email = await resolveVerifiedUserEmail(ctx);
29
+ const byEmail = email
30
+ ? await requestExecutor.list({ filter: { field: "email", op: "eq", value: email }, limit: LOOKUP_LIMIT }, platformActor(), ctx.db)
31
+ : { rows: [] };
32
+ const unique = new Map(byUser.rows.map((row) => [row.id, row]));
33
+ for (const row of byEmail.rows)
34
+ unique.set(row.id, row);
35
+ return [...unique.values()];
36
+ }
37
+ const fileRefExecutor = createEventStoreExecutor(fileRefsTable, fileRefEntity, {
38
+ entityName: "fileRef",
39
+ });
40
+ // Attachments are copied into the system tenant and bound to the request or reply row.
41
+ async function findAttachments(ctx, entity, id) {
42
+ return ctx.db.selectMany(fileRefsTable, {
43
+ tenantId: SYSTEM_TENANT_ID,
44
+ entityType: entity,
45
+ entityId: id,
46
+ fieldName: CONTACT_UPLOAD_FIELD,
47
+ });
48
+ }
49
+ // Bytes first, then the fileRef row: a crash in between leaves a row whose delete converges on the
50
+ // next run, never bytes without a row. A failing byte delete aborts, like the generic fileRef hook.
51
+ async function purgeAttachments(ctx, entity, id) {
52
+ const attachments = await findAttachments(ctx, entity, id);
53
+ // skip: a row without attachments has no bytes to erase and needs no storage provider
54
+ if (attachments.length === 0)
55
+ return;
56
+ const provider = await ctx.buildStorageProvider?.(SYSTEM_TENANT_ID);
57
+ if (!provider) {
58
+ throw new InternalError({
59
+ message: `[contact:user-data] no file storage resolvable, attachments of ${entity} ${id} cannot be erased`,
60
+ });
61
+ }
62
+ for (const attachment of attachments) {
63
+ const failed = await deleteStoredFileAndDerivatives(attachment.storageKey, provider, "contact:user-data");
64
+ if (failed.length > 0) {
65
+ throw new InternalError({
66
+ message: `[contact:user-data] ${failed.length} attachment byte delete(s) failed for ${entity} ${id}`,
67
+ });
68
+ }
69
+ }
70
+ const failures = [];
71
+ for (const attachment of attachments) {
72
+ collectErasureFailure(await fileRefExecutor.forget({ id: attachment.id }, platformActor(), ctx.db), "fileRef", attachment.id, failures);
73
+ }
74
+ throwIfErasureFailed(failures);
75
+ }
76
+ async function findReplies(ctx, requestId) {
77
+ const found = await replyExecutor.list({ filter: { field: "requestId", op: "eq", value: requestId }, limit: LOOKUP_LIMIT }, platformActor(), ctx.db);
78
+ return found.rows;
79
+ }
80
+ export const contactExportHook = async (ctx) => {
81
+ const requests = await findRequests(ctx);
82
+ if (requests.length === 0)
83
+ return null;
84
+ const rows = [];
85
+ for (const request of requests) {
86
+ const replies = await findReplies(ctx, request.id);
87
+ rows.push({
88
+ kind: request.kind,
89
+ status: request.status,
90
+ source: request.source,
91
+ subject: request.subject,
92
+ message: request.message,
93
+ name: request.name,
94
+ email: request.email,
95
+ phone: request.phone,
96
+ page: request.page,
97
+ submittedAt: String(request.submittedAt),
98
+ attachments: (await findAttachments(ctx, CONTACT_REQUEST_ENTITY, request.id)).map((file) => file.fileName),
99
+ replies: replies.map((reply) => ({
100
+ message: reply.message,
101
+ authorName: reply.authorName,
102
+ sentAt: String(reply.sentAt),
103
+ })),
104
+ });
105
+ }
106
+ return { entity: CONTACT_REQUEST_ENTITY, rows };
107
+ };
108
+ // Requests and replies carry no statutory retention duty, so both strategies erase: rows are
109
+ // purged through the executor (replays on rebuild) and the record subject keys are shredded so
110
+ // the event log's ciphertext becomes unreadable. Replies go with their request.
111
+ export const contactDeleteHook = async (ctx) => {
112
+ const kms = configuredPiiSubjectKms();
113
+ const failures = [];
114
+ const erase = async (entity, id, forgotten) => {
115
+ collectErasureFailure(forgotten, entity, id, failures);
116
+ if (forgotten.isSuccess && kms) {
117
+ await kms.eraseKey({ kind: "record", entity, id }, { requestId: ERASE_REASON, userId: ctx.userId, eraseReason: ERASE_REASON });
118
+ }
119
+ };
120
+ for (const request of await findRequests(ctx)) {
121
+ for (const reply of await findReplies(ctx, request.id)) {
122
+ await purgeAttachments(ctx, CONTACT_REPLY_ENTITY, reply.id);
123
+ await erase(CONTACT_REPLY_ENTITY, reply.id, await replyExecutor.forget({ id: reply.id }, platformActor(), ctx.db));
124
+ }
125
+ await purgeAttachments(ctx, CONTACT_REQUEST_ENTITY, request.id);
126
+ await erase(CONTACT_REQUEST_ENTITY, request.id, await requestExecutor.forget({ id: request.id }, platformActor(), ctx.db));
127
+ }
128
+ throwIfErasureFailed(failures);
129
+ };