@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
@@ -5,18 +5,31 @@ type Recurrence = {
5
5
  readonly intervalCount: number | null;
6
6
  };
7
7
 
8
- export function intervalKey(price: Recurrence | null): string | undefined {
8
+ function recurrenceKey(
9
+ price: Recurrence | null,
10
+ everyPrefix: string,
11
+ singlePrefix: string,
12
+ ): string | undefined {
9
13
  if (price === null || price.interval === null) return undefined;
10
14
  return price.intervalCount !== null && price.intervalCount > 1
11
- ? `billing-foundation.plans.everyInterval.${price.interval}`
12
- : `billing-foundation.plans.perInterval.${price.interval}`;
15
+ ? `${everyPrefix}.${price.interval}`
16
+ : `${singlePrefix}.${price.interval}`;
17
+ }
18
+
19
+ export function intervalKey(price: Recurrence | null): string | undefined {
20
+ return recurrenceKey(
21
+ price,
22
+ "billing-foundation.plans.everyInterval",
23
+ "billing-foundation.plans.perInterval",
24
+ );
13
25
  }
14
26
 
15
27
  export function renewalKey(price: Recurrence | null): string | undefined {
16
- if (price === null || price.interval === null) return undefined;
17
- return price.intervalCount !== null && price.intervalCount > 1
18
- ? `billing-foundation.consent.renewsEvery.${price.interval}`
19
- : `billing-foundation.consent.renews.${price.interval}`;
28
+ return recurrenceKey(
29
+ price,
30
+ "billing-foundation.consent.renewsEvery",
31
+ "billing-foundation.consent.renews",
32
+ );
20
33
  }
21
34
 
22
35
  type PlanPrice = NonNullable<BillingPlanView["price"]>;
@@ -42,6 +42,7 @@ export type StockCapSpec<TCaps> = {
42
42
 
43
43
  // Lock on the counted set, not on `code`: two handlers capping the same rows under
44
44
  // different codes must still serialize against each other.
45
+ // guard:dup-ok lock key of one counted set; only the sorted-entries shape matches other key builders
45
46
  function countedSetKey(spec: Pick<StockCapSpec<unknown>, "table" | "where">): string {
46
47
  const where = Object.entries(spec.where ?? {}).sort(([a], [b]) => a.localeCompare(b));
47
48
  return `${spec.table.tableName}:${JSON.stringify(where)}`;
@@ -1,4 +1,11 @@
1
1
  [
2
+ {
3
+ "version": "0.409.0",
4
+ "type": "improvement",
5
+ "title": "In-app read state by idempotency key",
6
+ "detail": "Channels receive the notify `idempotencyKey` as `ChannelContext.idempotencyKey`. The in-app channel stores it in the new nullable column `in_app_messages.idempotency_key` (indexed) and the SystemAdmin query `channel-in-app:query:readStateByKeys` (`{ keys }`, 1 to 50) returns `{ key, readAt }` rows without any content, tenant-scoped. Queued delivery jobs carry the key as `notifyIdempotencyKey` in their payload.",
7
+ "migration": "Run `kumiko schema generate`: it adds the `idempotency_key` column and its index to `in_app_messages`. Notes sent before the migration have no key."
8
+ },
2
9
  {
3
10
  "version": "0.399.0",
4
11
  "type": "improvement",
@@ -3,6 +3,7 @@ import { defineFeature, type FeatureDefinition } from "@cosmicdrift/kumiko-frame
3
3
  import { inboxQuery } from "./handlers/inbox.query.ts";
4
4
  import { markAllReadWrite } from "./handlers/mark-all-read.write.ts";
5
5
  import { markReadWrite } from "./handlers/mark-read.write.ts";
6
+ import { readStateByKeysQuery } from "./handlers/read-state-by-keys.query.ts";
6
7
  import { unreadCountQuery } from "./handlers/unread-count.query.ts";
7
8
  import { inAppChannel } from "./in-app-channel.ts";
8
9
  import { inAppMessagesTableMeta } from "./tables.ts";
@@ -39,6 +40,7 @@ export function createChannelInAppFeature(): FeatureDefinition {
39
40
  const queries = {
40
41
  inbox: r.queryHandler(inboxQuery),
41
42
  unreadCount: r.queryHandler(unreadCountQuery),
43
+ readStateByKeys: r.queryHandler(readStateByKeysQuery),
42
44
  };
43
45
 
44
46
  return { handlers, queries };
@@ -0,0 +1,35 @@
1
+ import { selectMany } from "@cosmicdrift/kumiko-framework/db";
2
+ import { access, defineQueryHandler } from "@cosmicdrift/kumiko-framework/engine";
3
+ import type { Temporal } from "@cosmicdrift/kumiko-types/temporal";
4
+ import * as z from "zod";
5
+ import { inAppMessagesTable } from "../tables.ts";
6
+
7
+ const MAX_KEYS = 50;
8
+
9
+ type MessageRow = {
10
+ readonly idempotencyKey: string | null;
11
+ readonly readAt: Temporal.Instant | null;
12
+ };
13
+
14
+ export const readStateByKeysQuery = defineQueryHandler({
15
+ name: "readStateByKeys",
16
+ schema: z.object({ keys: z.array(z.string().min(1).max(256)).min(1).max(MAX_KEYS) }).strict(),
17
+ access: { roles: access.systemAdmin },
18
+ description:
19
+ "Returns when the in-app message sent under each given notify() idempotency key was read (null while unread), within the caller's tenant and without any message content; a SystemAdmin queries the recipient's tenant by acting as a system user of it. Use it to show whether a recipient has seen a notification a feature sent under a known key.",
20
+ handler: async (query, ctx) => {
21
+ const rows = await selectMany<MessageRow>(
22
+ ctx.db,
23
+ inAppMessagesTable,
24
+ { idempotencyKey: { in: query.payload.keys } },
25
+ { orderBy: [{ col: "createdAt", direction: "asc" }] },
26
+ );
27
+ const states = new Map<string, Temporal.Instant | null>();
28
+ for (const row of rows) {
29
+ if (row.idempotencyKey !== null && !states.has(row.idempotencyKey)) {
30
+ states.set(row.idempotencyKey, row.readAt);
31
+ }
32
+ }
33
+ return { rows: [...states].map(([key, readAt]) => ({ key, readAt })) };
34
+ },
35
+ });
@@ -33,6 +33,7 @@ export const inAppChannel: DeliveryChannel = {
33
33
  title: message.title,
34
34
  body: message.body ?? null,
35
35
  data: storedData,
36
+ idempotencyKey: ctx.idempotencyKey ?? null,
36
37
  });
37
38
 
38
39
  if (ctx.sseBroker) {
@@ -23,10 +23,14 @@ export const inAppMessagesTable = pgTable(
23
23
  data: text("data"), // JSON string for action, screen, etc.
24
24
  isRead: boolean("is_read").default(false).notNull(),
25
25
  readAt: instant("read_at"),
26
+ idempotencyKey: text("idempotency_key"),
26
27
  createdAt: instant("created_at").default(sql`now()`).notNull(),
27
28
  },
28
29
  // Every inbox, unread-count, mark-all-read and userData export/delete read filters by tenant + user.
29
- (t) => [index("in_app_messages_tenant_user_created_idx").on(t.tenantId, t.userId, t.createdAt)],
30
+ (t) => [
31
+ index("in_app_messages_tenant_user_created_idx").on(t.tenantId, t.userId, t.createdAt),
32
+ index("in_app_messages_idempotency_key_idx").on(t.idempotencyKey),
33
+ ],
30
34
  );
31
35
 
32
36
  // Derived from inAppMessagesTable (table() attaches the meta as a Symbol) so
@@ -0,0 +1,41 @@
1
+ import { randomBytes } from "node:crypto";
2
+ import type { Redis } from "ioredis";
3
+ import * as z from "zod";
4
+ import { CONTACT_CHALLENGE_REDIS_PREFIX } from "./web/constants.ts";
5
+
6
+ const CHALLENGE_BYTES = 16;
7
+
8
+ const StoredChallengeSchema = z.object({
9
+ issuedAtMs: z.number().int().nonnegative(),
10
+ bits: z.number().int().positive(),
11
+ });
12
+ export type StoredChallenge = z.infer<typeof StoredChallengeSchema>;
13
+
14
+ const challengeKey = (challenge: string) => `${CONTACT_CHALLENGE_REDIS_PREFIX}${challenge}`;
15
+
16
+ export async function issueChallenge(
17
+ redis: Redis,
18
+ args: { readonly bits: number; readonly ttlSeconds: number; readonly nowMs: number },
19
+ ): Promise<string> {
20
+ const challenge = randomBytes(CHALLENGE_BYTES).toString("base64url");
21
+ const stored: StoredChallenge = { issuedAtMs: args.nowMs, bits: args.bits };
22
+ await redis.set(challengeKey(challenge), JSON.stringify(stored), "EX", args.ttlSeconds);
23
+ return challenge;
24
+ }
25
+
26
+ // GETDEL makes the challenge single-use even when the submit is rejected afterwards.
27
+ export async function consumeChallenge(
28
+ redis: Redis,
29
+ challenge: string,
30
+ ): Promise<StoredChallenge | null> {
31
+ const raw = await redis.getdel(challengeKey(challenge));
32
+ if (raw === null) return null;
33
+ let json: unknown;
34
+ try {
35
+ json = JSON.parse(raw);
36
+ } catch {
37
+ return null;
38
+ }
39
+ const parsed = StoredChallengeSchema.safeParse(json);
40
+ return parsed.success ? parsed.data : null;
41
+ }
@@ -0,0 +1,27 @@
1
+ [
2
+ {
3
+ "version": "0.409.0",
4
+ "type": "improvement",
5
+ "title": "New bundled feature contact: public contact form with spam protection, admin replies and Telegram forwarding",
6
+ "detail": "`createContactFeature({ appName, telegram? })` adds a public contact form backend: the anonymous `contact:write:submit` stores a question, contact request or problem report (honeypot, single-use proof-of-work challenge from `contact:query:challenge`, minimum submit time, per-IP and per-email rate limits; spam gets the same 200 body and nothing is stored), notifies every SystemAdmin by mail and, with option `telegram: true` (default off), in a Telegram chat (adds `channel-telegram` to `requires`, the `telegramChat` config key and `contact:write:send-test`). The notification carries no personal data on any channel: only the kind, the app name and a link into the inbox, never name, address, phone, subject or message, because mail and Telegram cannot be shredded. A website sender gets a fixed acknowledgement that repeats nothing they typed (the form is no mail relay); a signed-in admin report gets a copy. The per-email limit counts only submits that passed the spam checks, `contact:write:report` is limited to 10 per hour and user, and the stored `page` loses its query string and fragment. Phone is off by default (`fields.phone`). Logged-in users file reports with `contact:write:report`; SystemAdmins answer with `contact:write:reply` (mail with Reply-To, optional in-app notice for logged-in reporters), mark requests done, and read `contact:query:request-detail`, `contact:query:replies` and `contact:query:request-delivery` (one row per channel with recipient, time and status email|telegram|reply-email|reply-in-app: pending|delivered|failed|skipped|read). Open means no answer yet: only status `open` counts. The browser client is served at `GET /contact/client.js` (`window.KumikoContact`). Requests are crypto-shredding-ready PII with EXT_USER_DATA export and erasure and a 365 day retention. The feature requires `config`, `delivery`, `user-data-rights` and `files` (a file provider must be mounted).",
7
+ "migration": "Run `kumiko schema generate`: it adds the `contact-request` and `contact-reply` tables. Apps mounting contact also need the delivery and channel-in-app migrations (`idempotency_key` columns) and a mounted file provider."
8
+ },
9
+ {
10
+ "version": "0.409.0",
11
+ "type": "improvement",
12
+ "title": "contact option reportCancelTarget",
13
+ "detail": "`createContactFeature({ reportCancelTarget })` sets the screen the Cancel button of the report form navigates to; without it the form shows no Cancel button."
14
+ },
15
+ {
16
+ "version": "0.409.0",
17
+ "type": "improvement",
18
+ "title": "contact option detailLinks; every signed-in user may report a problem",
19
+ "detail": "`createContactFeature({ detailLinks: { user, tenant } })` sets the screens the sender and tenant links in the request detail header open (short id or `<feature>:screen:<id>`); defaults stay `user-edit` and `tenant-edit`, `false` removes a link. `contact:write:report` and the report screen are now open to every signed-in user (`openToAll`), not only TenantAdmin and Member. The detail layout drops the phone row while `fields.phone` is off and hides it for an empty value, and the contact feature now requires `notes-history` (the detail notes section needs it)."
20
+ },
21
+ {
22
+ "version": "0.409.0",
23
+ "type": "fix",
24
+ "title": "The contact website client sends without credentials",
25
+ "detail": "`GET /contact/client.js` now sends the challenge and submit requests with `credentials: \"omit\"`, so a visitor who is signed in on the same domain with any role (including app roles) still submits as an anonymous caller instead of getting 403. Name and email come from the form, never from the session."
26
+ }
27
+ ]
@@ -0,0 +1,203 @@
1
+ // The browser client ships as a string so it survives the tsc-only dist build, which copies no
2
+ // loose .js assets. Keep it free of backslashes, backticks and template placeholders.
3
+ export const CONTACT_CLIENT_SOURCE = `(function () {
4
+ "use strict";
5
+
6
+ var QUERY_PATH = "/api/query";
7
+ var WRITE_PATH = "/api/write";
8
+ var CHALLENGE_QUERY = "contact:query:challenge";
9
+ var SUBMIT_WRITE = "contact:write:submit";
10
+ var CSRF_COOKIE_NAME = "kumiko_csrf";
11
+ var CSRF_HEADER_NAME = "X-CSRF-Token";
12
+ var LOCALE_HEADER_NAME = "X-Locale";
13
+ var SLICE_MS = 12;
14
+
15
+ var K = new Uint32Array([
16
+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
17
+ 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
18
+ 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
19
+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
20
+ 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
21
+ 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
22
+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
23
+ 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
24
+ ]);
25
+ var H0 = [0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19];
26
+
27
+ var block = new Uint8Array(64);
28
+ var words = new Uint32Array(64);
29
+ var digest = new Uint32Array(8);
30
+
31
+ function rotr(x, n) {
32
+ return (x >>> n) | (x << (32 - n));
33
+ }
34
+
35
+ // One 64-byte block only: challenge, colon and decimal nonce stay far below 56 bytes.
36
+ function sha256Block() {
37
+ var i;
38
+ for (i = 0; i < 16; i++) {
39
+ words[i] = (block[i * 4] << 24) | (block[i * 4 + 1] << 16) | (block[i * 4 + 2] << 8) | block[i * 4 + 3];
40
+ }
41
+ for (i = 16; i < 64; i++) {
42
+ var w15 = words[i - 15];
43
+ var w2 = words[i - 2];
44
+ var s0 = rotr(w15, 7) ^ rotr(w15, 18) ^ (w15 >>> 3);
45
+ var s1 = rotr(w2, 17) ^ rotr(w2, 19) ^ (w2 >>> 10);
46
+ words[i] = (words[i - 16] + s0 + words[i - 7] + s1) | 0;
47
+ }
48
+ var a = H0[0], b = H0[1], c = H0[2], d = H0[3], e = H0[4], f = H0[5], g = H0[6], h = H0[7];
49
+ for (i = 0; i < 64; i++) {
50
+ var t1 = (h + (rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25)) + ((e & f) ^ (~e & g)) + K[i] + words[i]) | 0;
51
+ var t2 = ((rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22)) + ((a & b) ^ (a & c) ^ (b & c))) | 0;
52
+ h = g; g = f; f = e; e = (d + t1) | 0; d = c; c = b; b = a; a = (t1 + t2) | 0;
53
+ }
54
+ digest[0] = (H0[0] + a) | 0; digest[1] = (H0[1] + b) | 0; digest[2] = (H0[2] + c) | 0; digest[3] = (H0[3] + d) | 0;
55
+ digest[4] = (H0[4] + e) | 0; digest[5] = (H0[5] + f) | 0; digest[6] = (H0[6] + g) | 0; digest[7] = (H0[7] + h) | 0;
56
+ }
57
+
58
+ function hasLeadingZeroBits(bits) {
59
+ var i = 0;
60
+ var remaining = bits;
61
+ while (remaining >= 32) {
62
+ if (digest[i] !== 0) return false;
63
+ i++;
64
+ remaining -= 32;
65
+ }
66
+ if (remaining === 0) return true;
67
+ return (digest[i] >>> (32 - remaining)) === 0;
68
+ }
69
+
70
+ function solveProofOfWork(challenge, bits) {
71
+ return new Promise(function (resolve, reject) {
72
+ var prefix = challenge + ":";
73
+ if (prefix.length > 40) {
74
+ reject(new Error("challenge too long"));
75
+ return;
76
+ }
77
+ var i;
78
+ block.fill(0);
79
+ for (i = 0; i < prefix.length; i++) block[i] = prefix.charCodeAt(i);
80
+ var counter = 0;
81
+
82
+ function step() {
83
+ var deadline = Date.now() + SLICE_MS;
84
+ do {
85
+ var nonce = String(counter);
86
+ var length = prefix.length + nonce.length;
87
+ for (i = 0; i < nonce.length; i++) block[prefix.length + i] = nonce.charCodeAt(i);
88
+ block[length] = 0x80;
89
+ var bitLength = length * 8;
90
+ block[62] = (bitLength >>> 8) & 0xff;
91
+ block[63] = bitLength & 0xff;
92
+ sha256Block();
93
+ if (hasLeadingZeroBits(bits)) {
94
+ resolve(nonce);
95
+ return;
96
+ }
97
+ counter++;
98
+ } while (counter % 256 !== 0 || Date.now() < deadline);
99
+ setTimeout(step, 0);
100
+ }
101
+ step();
102
+ });
103
+ }
104
+
105
+ function readCsrfToken() {
106
+ var parts = document.cookie.split(";");
107
+ for (var i = 0; i < parts.length; i++) {
108
+ var part = parts[i].trim();
109
+ var separator = part.indexOf("=");
110
+ if (separator > 0 && part.slice(0, separator) === CSRF_COOKIE_NAME) {
111
+ return decodeURIComponent(part.slice(separator + 1));
112
+ }
113
+ }
114
+ return undefined;
115
+ }
116
+
117
+ function pageLocale() {
118
+ var language = (document.documentElement.lang || "").toLowerCase().split("-")[0];
119
+ return language === "de" ? "de-DE" : "en-US";
120
+ }
121
+
122
+ function postJson(path, body) {
123
+ var headers = { "Content-Type": "application/json" };
124
+ headers[LOCALE_HEADER_NAME] = pageLocale();
125
+ var csrf = readCsrfToken();
126
+ if (csrf !== undefined) headers[CSRF_HEADER_NAME] = csrf;
127
+ return fetch(path, {
128
+ method: "POST",
129
+ credentials: "omit",
130
+ headers: headers,
131
+ body: JSON.stringify(body)
132
+ }).then(function (response) {
133
+ return response.json().then(
134
+ function (json) { return { status: response.status, response: response, body: json }; },
135
+ function () { return { status: response.status, response: response, body: undefined }; }
136
+ );
137
+ });
138
+ }
139
+
140
+ function retryAfterOf(result) {
141
+ var header = result.response.headers.get("Retry-After");
142
+ if (header !== null && /^[0-9]+$/.test(header)) return Number(header);
143
+ var error = result.body && result.body.error;
144
+ var seconds = error && error.details && error.details.retryAfterSeconds;
145
+ return typeof seconds === "number" ? seconds : undefined;
146
+ }
147
+
148
+ var pending = null;
149
+
150
+ function startChallenge() {
151
+ return postJson(QUERY_PATH, { type: CHALLENGE_QUERY, payload: {} }).then(function (result) {
152
+ var data = result.body && result.body.data;
153
+ if (result.status !== 200 || !data || typeof data.challenge !== "string") {
154
+ throw new Error("challenge failed");
155
+ }
156
+ var solved = solveProofOfWork(data.challenge, data.bits);
157
+ solved.catch(function () {});
158
+ return { challenge: data.challenge, solved: solved, options: { phone: data.phone, kinds: data.kinds } };
159
+ });
160
+ }
161
+
162
+ function ensureChallenge() {
163
+ if (pending === null) {
164
+ pending = startChallenge();
165
+ pending.catch(function () { pending = null; });
166
+ }
167
+ return pending;
168
+ }
169
+
170
+ function load() {
171
+ return ensureChallenge().then(function (state) { return state.options; });
172
+ }
173
+
174
+ function submit(fields) {
175
+ return ensureChallenge().then(function (state) {
176
+ pending = null;
177
+ return state.solved.then(function (nonce) {
178
+ var payload = {};
179
+ for (var key in fields) {
180
+ if (Object.prototype.hasOwnProperty.call(fields, key)) payload[key] = fields[key];
181
+ }
182
+ payload.challenge = state.challenge;
183
+ payload.nonce = nonce;
184
+ if (payload.locale === undefined) payload.locale = document.documentElement.lang || "en";
185
+ return postJson(WRITE_PATH, { type: SUBMIT_WRITE, payload: payload });
186
+ });
187
+ }).then(function (result) {
188
+ if (result.status === 429) {
189
+ var retryAfterSeconds = retryAfterOf(result);
190
+ return retryAfterSeconds === undefined
191
+ ? { kind: "rate-limited" }
192
+ : { kind: "rate-limited", retryAfterSeconds: retryAfterSeconds };
193
+ }
194
+ if (result.status === 200 && result.body && result.body.isSuccess === true) return { kind: "sent" };
195
+ return { kind: "failed" };
196
+ }, function () {
197
+ return { kind: "failed" };
198
+ });
199
+ }
200
+
201
+ window.KumikoContact = { load: load, submit: submit };
202
+ })();
203
+ `;
@@ -0,0 +1,168 @@
1
+ import { buildEntityTable } from "@cosmicdrift/kumiko-framework/db";
2
+ import {
3
+ createEntity,
4
+ createFilesField,
5
+ createLongTextField,
6
+ createNumberField,
7
+ createSelectField,
8
+ createTextField,
9
+ createTimestampField,
10
+ } from "@cosmicdrift/kumiko-framework/engine";
11
+ import type { PersonalSubject } from "@cosmicdrift/kumiko-types/fields";
12
+ import { DEFAULT_RETENTION_KEEP_FOR } from "./options.ts";
13
+ import {
14
+ CONTACT_KIND,
15
+ CONTACT_MAX_FILES,
16
+ CONTACT_REPLY_CHANNELS,
17
+ CONTACT_SOURCE,
18
+ CONTACT_STATUS,
19
+ } from "./web/constants.ts";
20
+
21
+ const KIND_OPTIONS = [
22
+ CONTACT_KIND.Question,
23
+ CONTACT_KIND.Contact,
24
+ CONTACT_KIND.Bug,
25
+ CONTACT_KIND.Wish,
26
+ ] as const;
27
+ const STATUS_OPTIONS = [CONTACT_STATUS.Open, CONTACT_STATUS.Answered, CONTACT_STATUS.Done] as const;
28
+ const SOURCE_OPTIONS = [CONTACT_SOURCE.Website, CONTACT_SOURCE.Admin] as const;
29
+ const REPLY_CHANNEL_OPTIONS = [
30
+ CONTACT_REPLY_CHANNELS.Email,
31
+ CONTACT_REPLY_CHANNELS.EmailAndInApp,
32
+ ] as const;
33
+
34
+ // A signed-in reporter is the data subject; an anonymous reporter has no user id, so the row
35
+ // itself is the crypto-shredding subject.
36
+ const REPORTER_SUBJECT: PersonalSubject = { of: "reporterUserId", whenAbsent: "self" };
37
+
38
+ const MAX_FILE_SIZE = "10MB";
39
+
40
+ export function createContactRequestEntity(retentionKeepFor: string = DEFAULT_RETENTION_KEEP_FOR) {
41
+ return createEntity({
42
+ table: "read_contact_requests",
43
+ description:
44
+ "A message from a website visitor or a signed-in user to the platform operators (question, contact request, bug report or wish), tracked through open, answered and done as SystemAdmins process it; name, email, phone, subject and message are the reporter's personal data.",
45
+ systemStream: true,
46
+ tenancy: "global",
47
+ retention: { keepFor: retentionKeepFor, strategy: "hardDelete", reference: "submittedAt" },
48
+ fields: {
49
+ kind: createSelectField({
50
+ options: KIND_OPTIONS,
51
+ required: true,
52
+ filterable: true,
53
+ sortable: true,
54
+ optionTones: {
55
+ [CONTACT_KIND.Bug]: "bad",
56
+ [CONTACT_KIND.Question]: "accent",
57
+ [CONTACT_KIND.Contact]: "accent",
58
+ [CONTACT_KIND.Wish]: "neutral",
59
+ },
60
+ }),
61
+ status: createSelectField({
62
+ options: STATUS_OPTIONS,
63
+ required: true,
64
+ default: CONTACT_STATUS.Open,
65
+ filterable: true,
66
+ sortable: true,
67
+ optionTones: {
68
+ [CONTACT_STATUS.Open]: "warn",
69
+ [CONTACT_STATUS.Answered]: "accent",
70
+ [CONTACT_STATUS.Done]: "ok",
71
+ },
72
+ }),
73
+ source: createSelectField({
74
+ options: SOURCE_OPTIONS,
75
+ required: true,
76
+ filterable: true,
77
+ }),
78
+ subject: createTextField({
79
+ required: true,
80
+ personal: REPORTER_SUBJECT,
81
+ find: "none",
82
+ searchable: true,
83
+ }),
84
+ message: createLongTextField({ required: true, personal: REPORTER_SUBJECT, find: "none" }),
85
+ name: createTextField({
86
+ required: true,
87
+ personal: REPORTER_SUBJECT,
88
+ find: "fuzzy",
89
+ searchable: true,
90
+ }),
91
+ email: createTextField({
92
+ required: true,
93
+ personal: REPORTER_SUBJECT,
94
+ find: "fuzzy",
95
+ searchable: true,
96
+ }),
97
+ phone: createTextField({ personal: REPORTER_SUBJECT, find: "none" }),
98
+ reporterUserId: createTextField({ personal: false, reason: "pseudonymous_fk" }),
99
+ // Not named tenantId: that is the framework's physical tenant column.
100
+ reporterTenantId: createTextField({ personal: false, reason: "is_tenant_reference" }),
101
+ reporterTenantName: createTextField({ personal: false, reason: "is_business_data" }),
102
+ reporterTenantPlan: createTextField({ personal: false, reason: "is_business_data" }),
103
+ page: createTextField({ personal: false, reason: "is_page_path" }),
104
+ appVersion: createTextField({ personal: false, reason: "is_app_build_version" }),
105
+ browser: createTextField({ personal: false, reason: "is_browser_summary" }),
106
+ locale: createTextField({ personal: false, reason: "is_ui_language_preference" }),
107
+ fileIds: createFilesField({
108
+ maxCount: CONTACT_MAX_FILES,
109
+ maxSize: MAX_FILE_SIZE,
110
+ personal: REPORTER_SUBJECT,
111
+ }),
112
+ fileCount: createNumberField({ default: 0 }),
113
+ submittedAt: createTimestampField({
114
+ personal: false,
115
+ sortable: true,
116
+ required: true,
117
+ reason: "is_submission_timestamp",
118
+ }),
119
+ answeredAt: createTimestampField(),
120
+ closedAt: createTimestampField(),
121
+ replyCount: createNumberField({ default: 0 }),
122
+ },
123
+ });
124
+ }
125
+
126
+ export function createContactReplyEntity(retentionKeepFor: string = DEFAULT_RETENTION_KEEP_FOR) {
127
+ return createEntity({
128
+ table: "read_contact_replies",
129
+ description:
130
+ "A SystemAdmin's answer to a contact request, with the channels it went out on; the message is the reporter's personal data because it quotes and addresses them.",
131
+ systemStream: true,
132
+ tenancy: "global",
133
+ retention: { keepFor: retentionKeepFor, strategy: "hardDelete", reference: "sentAt" },
134
+ fields: {
135
+ requestId: createTextField({
136
+ required: true,
137
+ personal: false,
138
+ reason: "technical_reference",
139
+ }),
140
+ reporterUserId: createTextField({ personal: false, reason: "pseudonymous_fk" }),
141
+ message: createLongTextField({ required: true, personal: REPORTER_SUBJECT, find: "none" }),
142
+ authorUserId: createTextField({
143
+ required: true,
144
+ personal: false,
145
+ reason: "is_admin_audit_id",
146
+ }),
147
+ authorName: createTextField({ required: true, personal: false, reason: "is_admin_label" }),
148
+ fileIds: createFilesField({
149
+ maxCount: CONTACT_MAX_FILES,
150
+ maxSize: MAX_FILE_SIZE,
151
+ personal: false,
152
+ reason: "is_business_data",
153
+ }),
154
+ channels: createSelectField({ options: REPLY_CHANNEL_OPTIONS, required: true }),
155
+ sentAt: createTimestampField({
156
+ personal: false,
157
+ sortable: true,
158
+ required: true,
159
+ reason: "is_submission_timestamp",
160
+ }),
161
+ },
162
+ });
163
+ }
164
+
165
+ export const contactRequestEntity = createContactRequestEntity();
166
+ export const contactReplyEntity = createContactReplyEntity();
167
+ export const contactRequestTable = buildEntityTable("contact-request", contactRequestEntity);
168
+ export const contactReplyTable = buildEntityTable("contact-reply", contactReplyEntity);