@cosmicdrift/kumiko-samples 0.406.0 → 0.410.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 (257) hide show
  1. package/package.json +1 -1
  2. package/packages/bundled-features/package.json +31 -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/handlers/login-options.query.ts +1 -1
  14. package/packages/bundled-features/src/auth-email-password/handlers/self-registration-status.query.ts +1 -1
  15. package/packages/bundled-features/src/auth-email-password/web/auth-client.ts +30 -64
  16. package/packages/bundled-features/src/auth-email-password/web/auth-redirect.ts +2 -2
  17. package/packages/bundled-features/src/auth-email-password/web/confirm-account-unlock-screen.tsx +20 -66
  18. package/packages/bundled-features/src/auth-email-password/web/index.ts +1 -0
  19. package/packages/bundled-features/src/auth-email-password/web/read-path-param.ts +8 -0
  20. package/packages/bundled-features/src/auth-email-password/web/return-path.ts +3 -2
  21. package/packages/bundled-features/src/auth-email-password/web/token-confirm-screen.tsx +97 -0
  22. package/packages/bundled-features/src/auth-email-password/web/verify-email-screen.tsx +20 -68
  23. package/packages/bundled-features/src/auth-foundation/boot-checks.ts +22 -15
  24. package/packages/bundled-features/src/auth-foundation/boot-rules.ts +33 -0
  25. package/packages/bundled-features/src/auth-mfa/errors.ts +12 -42
  26. package/packages/bundled-features/src/auth-mfa/feature-exports.ts +6 -45
  27. package/packages/bundled-features/src/auth-mfa/feature.ts +8 -19
  28. package/packages/bundled-features/src/auth-mfa/web/mfa-client.ts +19 -33
  29. package/packages/bundled-features/src/billing-foundation/consumer-protection/termination-notify.ts +1 -0
  30. package/packages/bundled-features/src/billing-foundation/web/plan-price.ts +20 -7
  31. package/packages/bundled-features/src/cap-counter/stock-cap-guard.ts +1 -0
  32. package/packages/bundled-features/src/channel-in-app/changes.json +7 -0
  33. package/packages/bundled-features/src/channel-in-app/feature.ts +2 -0
  34. package/packages/bundled-features/src/channel-in-app/handlers/read-state-by-keys.query.ts +35 -0
  35. package/packages/bundled-features/src/channel-in-app/in-app-channel.ts +1 -0
  36. package/packages/bundled-features/src/channel-in-app/tables.ts +5 -1
  37. package/packages/bundled-features/src/compliance-profiles/handlers/sub-processors.query.ts +4 -1
  38. package/packages/bundled-features/src/contact/challenge.ts +41 -0
  39. package/packages/bundled-features/src/contact/changes.json +33 -0
  40. package/packages/bundled-features/src/contact/client/contact-client-source.ts +203 -0
  41. package/packages/bundled-features/src/contact/client/contact-website-client.ts +29 -0
  42. package/packages/bundled-features/src/contact/client/index.ts +9 -0
  43. package/packages/bundled-features/src/contact/entity.ts +168 -0
  44. package/packages/bundled-features/src/contact/feature.ts +174 -0
  45. package/packages/bundled-features/src/contact/handlers/access.ts +17 -0
  46. package/packages/bundled-features/src/contact/handlers/attempts.ts +76 -0
  47. package/packages/bundled-features/src/contact/handlers/challenge.query.ts +44 -0
  48. package/packages/bundled-features/src/contact/handlers/forward-request.write.ts +98 -0
  49. package/packages/bundled-features/src/contact/handlers/mark-done.write.ts +40 -0
  50. package/packages/bundled-features/src/contact/handlers/notify-reporter-in-app.write.ts +48 -0
  51. package/packages/bundled-features/src/contact/handlers/open-count.query.ts +15 -0
  52. package/packages/bundled-features/src/contact/handlers/open-count.ts +17 -0
  53. package/packages/bundled-features/src/contact/handlers/replies.query.ts +29 -0
  54. package/packages/bundled-features/src/contact/handlers/reply.write.ts +197 -0
  55. package/packages/bundled-features/src/contact/handlers/report.write.ts +126 -0
  56. package/packages/bundled-features/src/contact/handlers/request-delivery.query.ts +143 -0
  57. package/packages/bundled-features/src/contact/handlers/request-detail.query.ts +50 -0
  58. package/packages/bundled-features/src/contact/handlers/request-list.query.ts +14 -0
  59. package/packages/bundled-features/src/contact/handlers/send-reply-mail.write.ts +124 -0
  60. package/packages/bundled-features/src/contact/handlers/send-test.write.ts +45 -0
  61. package/packages/bundled-features/src/contact/handlers/submit.write.ts +194 -0
  62. package/packages/bundled-features/src/contact/handlers/take-over-uploads.ts +47 -0
  63. package/packages/bundled-features/src/contact/i18n.ts +192 -0
  64. package/packages/bundled-features/src/contact/index.ts +29 -0
  65. package/packages/bundled-features/src/contact/lib.ts +176 -0
  66. package/packages/bundled-features/src/contact/mail.ts +401 -0
  67. package/packages/bundled-features/src/contact/options.ts +95 -0
  68. package/packages/bundled-features/src/contact/panels.ts +28 -0
  69. package/packages/bundled-features/src/contact/payloads.ts +106 -0
  70. package/packages/bundled-features/src/contact/pow.ts +22 -0
  71. package/packages/bundled-features/src/contact/screens.ts +507 -0
  72. package/packages/bundled-features/src/contact/subject.ts +13 -0
  73. package/packages/bundled-features/src/contact/user-agent.ts +39 -0
  74. package/packages/bundled-features/src/contact/user-data-hooks.ts +180 -0
  75. package/packages/bundled-features/src/contact/web/constants.ts +160 -0
  76. package/packages/bundled-features/src/contact/web/index.ts +29 -0
  77. package/packages/bundled-features/src/crypto-shredding/handlers/forget-subject.write.ts +5 -16
  78. package/packages/bundled-features/src/data-retention/changes.json +6 -0
  79. package/packages/bundled-features/src/data-retention/feature.ts +16 -2
  80. package/packages/bundled-features/src/data-retention/index.ts +5 -0
  81. package/packages/bundled-features/src/data-retention/run-retention-cleanup.ts +138 -41
  82. package/packages/bundled-features/src/data-retention/tenant-destruction-hold.ts +196 -0
  83. package/packages/bundled-features/src/delivery/address-opt-out.ts +1 -0
  84. package/packages/bundled-features/src/delivery/changes.json +7 -0
  85. package/packages/bundled-features/src/delivery/channel-context.ts +2 -0
  86. package/packages/bundled-features/src/delivery/delivery-service.ts +29 -5
  87. package/packages/bundled-features/src/delivery/events.ts +2 -0
  88. package/packages/bundled-features/src/delivery/feature.ts +3 -2
  89. package/packages/bundled-features/src/delivery/handlers/attempts-by-keys.query.ts +55 -0
  90. package/packages/bundled-features/src/delivery/handlers/log.query.ts +1 -1
  91. package/packages/bundled-features/src/delivery/jobs.ts +5 -0
  92. package/packages/bundled-features/src/delivery/tables.ts +13 -2
  93. package/packages/bundled-features/src/delivery/types.ts +3 -0
  94. package/packages/bundled-features/src/delivery/unsubscribe-page.ts +2 -0
  95. package/packages/bundled-features/src/delivery/web/delivery-channel-cell.tsx +1 -1
  96. package/packages/bundled-features/src/delivery/web/delivery-error-cell.tsx +1 -1
  97. package/packages/bundled-features/src/delivery/web/delivery-status-cell.tsx +1 -1
  98. package/packages/bundled-features/src/delivery/web/delivery-time-cell.tsx +3 -2
  99. package/packages/bundled-features/src/delivery/web/delivery-type-cell.tsx +1 -1
  100. package/packages/bundled-features/src/delivery/web/public-names.ts +1 -0
  101. package/packages/bundled-features/src/document-ingest-foundation/boot-checks.ts +14 -9
  102. package/packages/bundled-features/src/document-ingest-foundation/boot-rules.ts +22 -0
  103. package/packages/bundled-features/src/document-ingest-foundation/changes.json +6 -0
  104. package/packages/bundled-features/src/document-ingest-foundation/events.ts +17 -0
  105. package/packages/bundled-features/src/document-ingest-foundation/feature.ts +39 -1
  106. package/packages/bundled-features/src/document-ingest-foundation/index.ts +10 -0
  107. package/packages/bundled-features/src/document-ingest-foundation/report-ingest-progress.ts +43 -0
  108. package/packages/bundled-features/src/document-ingest-foundation/tables.ts +43 -0
  109. package/packages/bundled-features/src/file-derivatives/handlers/public-variant-by-file-ref.query.ts +1 -1
  110. package/packages/bundled-features/src/file-derivatives/handlers/public-variant.query.ts +1 -1
  111. package/packages/bundled-features/src/files-tenant-data/changes.json +6 -0
  112. package/packages/bundled-features/src/files-tenant-data/hooks.ts +4 -1
  113. package/packages/bundled-features/src/folders/web/folder-manager.tsx +8 -9
  114. package/packages/bundled-features/src/folders/web/folder-section.tsx +1 -1
  115. package/packages/bundled-features/src/form-draft-user-data/index.ts +2 -0
  116. package/packages/bundled-features/src/inbound-mail-foundation/changes.json +13 -0
  117. package/packages/bundled-features/src/inbound-mail-foundation/entities.ts +2 -0
  118. package/packages/bundled-features/src/inbound-mail-foundation/events.ts +2 -0
  119. package/packages/bundled-features/src/inbound-mail-foundation/feature.ts +6 -6
  120. package/packages/bundled-features/src/inbound-mail-foundation/handlers/attach-message-content.write.ts +7 -0
  121. package/packages/bundled-features/src/inbound-mail-foundation/handlers/ingest-message.write.ts +6 -0
  122. package/packages/bundled-features/src/inbound-mail-foundation/handlers/list-messages.query.ts +6 -2
  123. package/packages/bundled-features/src/inbound-mail-foundation/handlers/message-content.query.ts +3 -0
  124. package/packages/bundled-features/src/inbound-mail-foundation/handlers/message-content.ts +19 -0
  125. package/packages/bundled-features/src/inbound-mail-foundation/projection.ts +2 -0
  126. package/packages/bundled-features/src/inbound-mail-foundation/sanitize-inbound-html.ts +150 -0
  127. package/packages/bundled-features/src/inbound-mail-foundation/types.ts +1 -0
  128. package/packages/bundled-features/src/jobs/job-run-logger.ts +24 -25
  129. package/packages/bundled-features/src/ledger/handlers/reports.query.ts +46 -31
  130. package/packages/bundled-features/src/ledger/recurring.ts +1 -0
  131. package/packages/bundled-features/src/managed-pages/handlers/branding.query.ts +1 -1
  132. package/packages/bundled-features/src/managed-pages/handlers/by-slug.query.ts +1 -1
  133. package/packages/bundled-features/src/managed-pages/handlers/by-tenant-published.query.ts +1 -1
  134. package/packages/bundled-features/src/notes-history/web/notes-section.tsx +3 -1
  135. package/packages/bundled-features/src/personal-access-tokens/feature.ts +9 -17
  136. package/packages/bundled-features/src/personal-access-tokens/handlers/create.write.ts +2 -7
  137. package/packages/bundled-features/src/secrets/changes.json +6 -0
  138. package/packages/bundled-features/src/secrets/handlers/delete.write.ts +8 -4
  139. package/packages/bundled-features/src/secrets/handlers/list.query.ts +6 -3
  140. package/packages/bundled-features/src/secrets/handlers/set.write.ts +9 -4
  141. package/packages/bundled-features/src/secrets/secret-scope.ts +33 -0
  142. package/packages/bundled-features/src/seo/handlers/seo-config.query.ts +1 -1
  143. package/packages/bundled-features/src/sessions/changes.json +6 -0
  144. package/packages/bundled-features/src/sessions/feature.ts +21 -18
  145. package/packages/bundled-features/src/sessions/handlers/last-activity-probe.query.ts +53 -0
  146. package/packages/bundled-features/src/sessions/handlers/last-activity-probe.route.ts +39 -0
  147. package/packages/bundled-features/src/sessions/screens.ts +1 -0
  148. package/packages/bundled-features/src/sessions/session-callbacks.ts +13 -12
  149. package/packages/bundled-features/src/sessions/web/i18n.ts +4 -1
  150. package/packages/bundled-features/src/shared/assert-billing-live.ts +14 -0
  151. package/packages/bundled-features/src/shared/collect-extension-options.ts +12 -0
  152. package/packages/bundled-features/src/shared/index.ts +16 -0
  153. package/packages/bundled-features/src/shared/late-bound-slot.ts +19 -0
  154. package/packages/bundled-features/src/shared/mail-locale-templates.ts +7 -1
  155. package/packages/bundled-features/src/shared/price-env-shape.ts +44 -0
  156. package/packages/bundled-features/src/shared/purge-row-file-refs.ts +1 -1
  157. package/packages/bundled-features/src/shared/read-feature-export-fn.ts +16 -0
  158. package/packages/bundled-features/src/shared/signup-handover.ts +3 -4
  159. package/packages/bundled-features/src/shared/tenant-destruction-hold.ts +49 -0
  160. package/packages/bundled-features/src/shared/unprocessable.ts +19 -0
  161. package/packages/bundled-features/src/shared/web/index.ts +3 -0
  162. package/packages/bundled-features/src/subscription-paddle/checkout-config.query.ts +1 -1
  163. package/packages/bundled-features/src/subscription-paddle/feature.ts +7 -15
  164. package/packages/bundled-features/src/subscription-paddle/runtime.ts +4 -7
  165. package/packages/bundled-features/src/subscription-stripe/feature.ts +7 -15
  166. package/packages/bundled-features/src/subscription-stripe/runtime.ts +4 -7
  167. package/packages/bundled-features/src/tags/entity.ts +1 -0
  168. package/packages/bundled-features/src/tags/web/tag-chip.tsx +14 -0
  169. package/packages/bundled-features/src/tags/web/tag-filter.tsx +4 -5
  170. package/packages/bundled-features/src/tags/web/tag-manager.tsx +1 -1
  171. package/packages/bundled-features/src/tags/web/tag-section.tsx +3 -6
  172. package/packages/bundled-features/src/tags/web/tags-cell.tsx +4 -5
  173. package/packages/bundled-features/src/template-resolver/compile-document-body.ts +27 -15
  174. package/packages/bundled-features/src/template-resolver/handlers/by-slug.query.ts +1 -1
  175. package/packages/bundled-features/src/template-resolver/handlers/by-tenant.query.ts +12 -9
  176. package/packages/bundled-features/src/template-resolver/handlers/discard-draft.write.ts +1 -0
  177. package/packages/bundled-features/src/template-resolver/handlers/overview.query.ts +1 -0
  178. package/packages/bundled-features/src/template-resolver/handlers/send-test.write.ts +5 -5
  179. package/packages/bundled-features/src/template-resolver/handlers/toggle-status.write.ts +3 -0
  180. package/packages/bundled-features/src/template-resolver/linked-resources.ts +11 -6
  181. package/packages/bundled-features/src/template-resolver/store-template-resource.ts +15 -12
  182. package/packages/bundled-features/src/template-resolver/web/document-images.ts +6 -6
  183. package/packages/bundled-features/src/template-resolver/web/document-insert-fields.tsx +41 -36
  184. package/packages/bundled-features/src/template-resolver/web/document-schema.ts +11 -12
  185. package/packages/bundled-features/src/template-resolver/web/tiptap-attribute-parse-rule.ts +19 -0
  186. package/packages/bundled-features/src/tenant/i18n.ts +3 -0
  187. package/packages/bundled-features/src/tenant/schema/tenant.ts +1 -0
  188. package/packages/bundled-features/src/tenant/web/member-roles-cell.tsx +1 -1
  189. package/packages/bundled-features/src/tenant/web/member-status-cell.tsx +1 -1
  190. package/packages/bundled-features/src/tenant-inactivity/changes.json +8 -0
  191. package/packages/bundled-features/src/tenant-inactivity/check-inactive-tenants.ts +260 -0
  192. package/packages/bundled-features/src/tenant-inactivity/constants.ts +12 -0
  193. package/packages/bundled-features/src/tenant-inactivity/email-templates.ts +24 -0
  194. package/packages/bundled-features/src/tenant-inactivity/feature.ts +66 -0
  195. package/packages/bundled-features/src/tenant-inactivity/handlers/inactivity-state.query.ts +49 -0
  196. package/packages/bundled-features/src/tenant-inactivity/handlers/keep-account.write.ts +59 -0
  197. package/packages/bundled-features/src/tenant-inactivity/inactivity-plan.ts +187 -0
  198. package/packages/bundled-features/src/tenant-inactivity/index.ts +5 -0
  199. package/packages/bundled-features/src/tenant-inactivity/keep-token.ts +44 -0
  200. package/packages/bundled-features/src/tenant-inactivity/mail-notifications.ts +62 -0
  201. package/packages/bundled-features/src/tenant-inactivity/options.ts +38 -0
  202. package/packages/bundled-features/src/tenant-inactivity/remote-activity.ts +32 -0
  203. package/packages/bundled-features/src/tenant-inactivity/state-store.ts +71 -0
  204. package/packages/bundled-features/src/tenant-inactivity/state-table.ts +50 -0
  205. package/packages/bundled-features/src/tenant-lifecycle/boot-checks.ts +8 -6
  206. package/packages/bundled-features/src/tenant-lifecycle/boot-rules.ts +16 -0
  207. package/packages/bundled-features/src/tenant-lifecycle/changes.json +18 -0
  208. package/packages/bundled-features/src/tenant-lifecycle/feature.ts +24 -1
  209. package/packages/bundled-features/src/tenant-lifecycle/handlers/request-destruction.write.ts +12 -87
  210. package/packages/bundled-features/src/tenant-lifecycle/index.ts +4 -0
  211. package/packages/bundled-features/src/tenant-lifecycle/request-tenant-destruction.ts +108 -0
  212. package/packages/bundled-features/src/tenant-lifecycle/retention-config-destroy-hooks.ts +62 -0
  213. package/packages/bundled-features/src/tenant-lifecycle/run-tenant-destroy.ts +58 -5
  214. package/packages/bundled-features/src/tenant-lifecycle/stages.ts +31 -2
  215. package/packages/bundled-features/src/tenant-lifecycle/testing.ts +1 -1
  216. package/packages/bundled-features/src/tier-engine/caps-for-tier-from-map.ts +16 -0
  217. package/packages/bundled-features/src/tier-engine/changes.json +6 -0
  218. package/packages/bundled-features/src/tier-engine/compose-app.ts +21 -20
  219. package/packages/bundled-features/src/tier-engine/index.ts +1 -0
  220. package/packages/bundled-features/src/user-data-rights/feature.ts +2 -0
  221. package/packages/bundled-features/src/user-data-rights/handlers/confirm-deletion-by-token.write.ts +4 -1
  222. package/packages/bundled-features/src/user-data-rights/handlers/download-by-token.query.ts +1 -0
  223. package/packages/bundled-features/src/user-data-rights/handlers/request-deletion-by-email.write.ts +4 -1
  224. package/packages/bundled-features/src/user-data-rights/run-forget-cleanup.ts +2 -0
  225. package/packages/bundled-features/src/user-data-rights/web/privacy-center-screen.tsx +1 -1
  226. package/packages/bundled-features/src/user-data-rights/zip-path.ts +1 -0
  227. package/packages/bundled-features/src/user-data-rights-defaults/hooks/config-value.userdata-hook.ts +8 -27
  228. package/packages/bundled-features/src/user-data-rights-defaults/hooks/delivery-attempt.userdata-hook.ts +11 -8
  229. package/packages/bundled-features/src/user-data-rights-defaults/hooks/forget-own-rows-delete-hook.ts +42 -0
  230. package/packages/bundled-features/src/user-data-rights-defaults/hooks/notification-preference.userdata-hook.ts +8 -27
  231. package/packages/bundled-features/src/user-profile/handlers/change-email.write.ts +2 -6
  232. package/packages/bundled-features/src/user-profile/web/profile-screen.tsx +2 -3
  233. package/packages/bundled-features/src/waitlist/changes.json +6 -0
  234. package/packages/bundled-features/src/waitlist/handlers/submit.write.ts +1 -2
  235. package/samples/apps/styleguide/src/features/widgets/i18n.ts +6 -0
  236. package/samples/apps/styleguide/src/features/widgets/web/InboxReaderExamples.tsx +158 -0
  237. package/samples/apps/styleguide/src/features/widgets/web/Widgets.tsx +2 -0
  238. package/samples/apps/styleguide/src/features/widgets/web/sample-pdf.ts +28 -0
  239. package/samples/apps/use-all-bundled/feature-manifest.json +113 -2
  240. package/samples/apps/use-all-bundled/kumiko/migrations/0063_contact.rebuild.json +4 -0
  241. package/samples/apps/use-all-bundled/package.json +1 -0
  242. package/samples/apps/use-all-bundled/src/app/client.tsx +3 -0
  243. package/samples/apps/use-all-bundled/src/app/screens-feature.ts +46 -2
  244. package/samples/apps/use-all-bundled/src/run-config.ts +23 -1
  245. package/samples/recipes/anonymous-access/README.md +2 -0
  246. package/samples/recipes/anonymous-access/src/feature.ts +7 -1
  247. package/samples/recipes/contact/README.md +52 -0
  248. package/samples/recipes/contact/package.json +12 -0
  249. package/samples/recipes/contact/src/feature.ts +27 -0
  250. package/samples/recipes/delivery-notifications/src/feature.ts +3 -0
  251. package/samples/recipes/record-detail-layout/src/feature.ts +9 -1
  252. package/samples/recipes/search/README.md +2 -0
  253. package/samples/recipes/search/src/feature.ts +27 -2
  254. package/samples/recipes/secrets-demo/README.md +1 -0
  255. package/samples/recipes/secrets-demo/src/feature.ts +56 -0
  256. package/samples/recipes/tenant-inactivity/README.md +21 -0
  257. package/samples/recipes/tenant-inactivity/package.json +12 -0
@@ -0,0 +1,106 @@
1
+ import { canonicalizeLocaleTag, isValidLocaleTag } from "@cosmicdrift/kumiko-framework/i18n";
2
+ import * as z from "zod";
3
+ import {
4
+ CONTACT_ADMIN_KINDS,
5
+ CONTACT_FIELD_LIMITS,
6
+ CONTACT_MAX_FILES,
7
+ CONTACT_WEBSITE_KINDS,
8
+ } from "./web/constants.ts";
9
+
10
+ // Submitted text lands in mail subjects; CR/LF there would allow header injection.
11
+ const NO_CONTROL_CHARS = /^\P{Cc}*$/u;
12
+ const NO_CONTROL_CHARS_EXCEPT_WHITESPACE = /^(?:[^\p{Cc}]|[\n\r\t])*$/u;
13
+ const noControlChars = (value: string) => NO_CONTROL_CHARS.test(value);
14
+ const CONTROL_CHARS_MESSAGE = "control characters not allowed";
15
+
16
+ const singleLine = (max: number) =>
17
+ z.string().trim().min(1).max(max).refine(noControlChars, CONTROL_CHARS_MESSAGE);
18
+
19
+ const multiLine = (max: number) =>
20
+ z
21
+ .string()
22
+ .trim()
23
+ .min(1)
24
+ .max(max)
25
+ .refine((value) => NO_CONTROL_CHARS_EXCEPT_WHITESPACE.test(value), CONTROL_CHARS_MESSAGE);
26
+
27
+ // An empty phone field of a form counts as absent.
28
+ const phone = z
29
+ .string()
30
+ .trim()
31
+ .max(CONTACT_FIELD_LIMITS.phone)
32
+ .refine(noControlChars, CONTROL_CHARS_MESSAGE)
33
+ .optional();
34
+
35
+ const pagePath = z
36
+ .string()
37
+ .trim()
38
+ .max(CONTACT_FIELD_LIMITS.page)
39
+ .refine(noControlChars, CONTROL_CHARS_MESSAGE)
40
+ // Query strings and fragments carry tokens and ids (reset links, session hints) that must not
41
+ // end up in an inbox that is kept for a year.
42
+ .transform((value) => value.split(/[?#]/, 1)[0] ?? "")
43
+ .optional();
44
+
45
+ const locale = z
46
+ .string()
47
+ .max(CONTACT_FIELD_LIMITS.locale)
48
+ .refine(isValidLocaleTag, "invalid locale tag")
49
+ .transform(canonicalizeLocaleTag);
50
+
51
+ export const ContactSubmitSchema = z
52
+ .object({
53
+ kind: z.enum(CONTACT_WEBSITE_KINDS),
54
+ name: singleLine(CONTACT_FIELD_LIMITS.name),
55
+ email: z.email().max(CONTACT_FIELD_LIMITS.email),
56
+ phone,
57
+ message: multiLine(CONTACT_FIELD_LIMITS.message),
58
+ locale,
59
+ // Honeypot: bots fill it, humans leave it empty.
60
+ website: z.string().max(CONTACT_FIELD_LIMITS.honeypot).optional(),
61
+ challenge: z.string().max(CONTACT_FIELD_LIMITS.challenge),
62
+ nonce: z.string().max(CONTACT_FIELD_LIMITS.nonce),
63
+ page: pagePath,
64
+ })
65
+ .strict();
66
+ export type ContactSubmitInput = z.infer<typeof ContactSubmitSchema>;
67
+
68
+ export const ContactReportSchema = z
69
+ .object({
70
+ kind: z.enum(CONTACT_ADMIN_KINDS),
71
+ subject: singleLine(CONTACT_FIELD_LIMITS.subject),
72
+ message: multiLine(CONTACT_FIELD_LIMITS.message),
73
+ phone,
74
+ fileIds: z.array(z.uuid()).max(CONTACT_MAX_FILES).optional(),
75
+ })
76
+ .strict();
77
+ export type ContactReportInput = z.infer<typeof ContactReportSchema>;
78
+
79
+ export const ContactIdSchema = z.object({ id: z.uuid() }).strict();
80
+
81
+ export const ContactReplySchema = z
82
+ .object({
83
+ requestId: z.uuid(),
84
+ message: multiLine(CONTACT_FIELD_LIMITS.message),
85
+ fileIds: z.array(z.uuid()).max(CONTACT_MAX_FILES).optional(),
86
+ markDone: z.boolean().default(false),
87
+ })
88
+ .strict();
89
+
90
+ export const ContactMarkDoneSchema = ContactIdSchema;
91
+
92
+ export const ContactForwardRequestSchema = z.object({ requestId: z.uuid() }).strict();
93
+
94
+ export const ContactSendReplyMailSchema = z.object({ replyId: z.uuid() }).strict();
95
+
96
+ export const ContactNotifyReporterInAppSchema = z
97
+ .object({
98
+ replyId: z.uuid(),
99
+ requestId: z.uuid(),
100
+ userId: z.uuid(),
101
+ authorName: z.string().max(CONTACT_FIELD_LIMITS.name),
102
+ locale: z.string().max(CONTACT_FIELD_LIMITS.locale).optional(),
103
+ })
104
+ .strict();
105
+
106
+ export const ContactEmptySchema = z.object({}).strict();
@@ -0,0 +1,22 @@
1
+ import { createHash } from "node:crypto";
2
+
3
+ export function hasLeadingZeroBits(hash: Uint8Array, bits: number): boolean {
4
+ const fullBytes = Math.floor(bits / 8);
5
+ for (let index = 0; index < fullBytes; index++) {
6
+ if (hash[index] !== 0) return false;
7
+ }
8
+ const remainingBits = bits % 8;
9
+ if (remainingBits === 0) return true;
10
+ const next = hash[fullBytes];
11
+ if (next === undefined) return false;
12
+ return next >> (8 - remainingBits) === 0;
13
+ }
14
+
15
+ export function verifyProofOfWork(args: {
16
+ readonly challenge: string;
17
+ readonly nonce: string;
18
+ readonly bits: number;
19
+ }): boolean {
20
+ const hash = createHash("sha256").update(`${args.challenge}:${args.nonce}`).digest();
21
+ return hasLeadingZeroBits(hash, args.bits);
22
+ }
@@ -0,0 +1,507 @@
1
+ import { access, createFilesField, createTextField } from "@cosmicdrift/kumiko-framework/engine";
2
+ import type {
3
+ ActionFormScreenDefinition,
4
+ ConfigEditScreenDefinition,
5
+ EntityListScreenDefinition,
6
+ ProjectionDetailScreenDefinition,
7
+ ScreenDefinition,
8
+ } from "@cosmicdrift/kumiko-framework/ui-types";
9
+ import { DELIVERY_LOG_SCREEN_ID } from "../delivery/index.ts";
10
+ import { REPORT_ACCESS } from "./handlers/access.ts";
11
+ import type { ContactOptions, ContactSettings } from "./options.ts";
12
+ import {
13
+ CONTACT_ADMIN_KINDS,
14
+ CONTACT_DELIVERY_STATUS,
15
+ CONTACT_FEATURE,
16
+ CONTACT_MAX_FILES,
17
+ CONTACT_ORIGIN,
18
+ CONTACT_REPLY_CHANNELS,
19
+ CONTACT_STATUS,
20
+ CONTACT_UPLOAD_FIELD,
21
+ ContactConfigKeys,
22
+ ContactHandlers,
23
+ ContactQueries,
24
+ } from "./web/constants.ts";
25
+
26
+ const MAX_FILE_SIZE = "10MB";
27
+ const REQUEST_FIELD = `${CONTACT_FEATURE}:entity:contact-request:field`;
28
+ const DELIVERY_FIELD = `${CONTACT_FEATURE}:entity:contact-delivery:field`;
29
+ const TELEGRAM_BOT_TOKEN_SECRET = "channel-telegram:secret:bot-token";
30
+
31
+ export const REPORT_FIELD_LABEL = `${CONTACT_FEATURE}:report.field`;
32
+ export const REPLY_FIELD_LABEL = `${CONTACT_FEATURE}:reply.field`;
33
+
34
+ function attachmentsField() {
35
+ return createFilesField({
36
+ personal: false,
37
+ reason: "is_business_data",
38
+ maxCount: CONTACT_MAX_FILES,
39
+ maxSize: MAX_FILE_SIZE,
40
+ display: "dropzone",
41
+ });
42
+ }
43
+
44
+ // The files the form uploads stay pending under this screen's QN until the handler takes them
45
+ // over (copyPendingFileRefsToTenant).
46
+ function createReportScreen(
47
+ opts: ContactOptions,
48
+ settings: ContactSettings,
49
+ ): ActionFormScreenDefinition {
50
+ const withPhone = settings.phone !== "off";
51
+ return {
52
+ id: "report",
53
+ type: "actionForm",
54
+ dormant: true,
55
+ handler: ContactHandlers.report,
56
+ summary: {
57
+ title: `${CONTACT_FEATURE}:report.hint`,
58
+ subtitle: `${CONTACT_FEATURE}:report.summary`,
59
+ params: { appName: opts.appName },
60
+ },
61
+ fields: {
62
+ kind: { type: "select", options: CONTACT_ADMIN_KINDS, required: true, display: "radio" },
63
+ ...(withPhone && {
64
+ phone: { type: "text", format: "phone", required: settings.phone === "required" },
65
+ }),
66
+ subject: { type: "text", required: true },
67
+ message: { type: "longText", required: true },
68
+ [CONTACT_UPLOAD_FIELD]: attachmentsField(),
69
+ },
70
+ layout: {
71
+ sections: [
72
+ {
73
+ title: `${CONTACT_FEATURE}:report.section`,
74
+ description: `${CONTACT_FEATURE}:report.section.description`,
75
+ fields: [
76
+ "kind",
77
+ ...(withPhone ? ["phone"] : []),
78
+ { field: "subject", span: 2 },
79
+ "message",
80
+ CONTACT_UPLOAD_FIELD,
81
+ ],
82
+ },
83
+ ],
84
+ },
85
+ fieldLabels: {
86
+ kind: `${REPORT_FIELD_LABEL}.kind`,
87
+ phone: `${REPORT_FIELD_LABEL}.phone`,
88
+ subject: `${REPORT_FIELD_LABEL}.subject`,
89
+ message: `${REPORT_FIELD_LABEL}.message`,
90
+ [CONTACT_UPLOAD_FIELD]: `${REPORT_FIELD_LABEL}.files`,
91
+ },
92
+ submitLabel: `${CONTACT_FEATURE}:report.submit`,
93
+ ...(opts.reportCancelTarget !== undefined && { cancelTarget: opts.reportCancelTarget }),
94
+ successMessage: `${CONTACT_FEATURE}:report.success`,
95
+ access: REPORT_ACCESS,
96
+ };
97
+ }
98
+
99
+ // The two reply screens differ only in the summary text: the screen QN is also the entityType the
100
+ // pending uploads hang under, so reply.write picks the variant by the reporter's reply channels.
101
+ function createReplyScreen(id: string, summarySubtitle: string): ActionFormScreenDefinition {
102
+ return {
103
+ id,
104
+ type: "actionForm",
105
+ dormant: true,
106
+ handler: ContactHandlers.reply,
107
+ summary: { title: `${CONTACT_FEATURE}:reply.title`, subtitle: summarySubtitle },
108
+ fields: {
109
+ requestId: { type: "text", required: true },
110
+ message: { type: "longText", required: true },
111
+ [CONTACT_UPLOAD_FIELD]: attachmentsField(),
112
+ markDone: { type: "boolean" },
113
+ name: { type: "text" },
114
+ email: { type: "text" },
115
+ replyTo: { type: "text" },
116
+ },
117
+ layout: {
118
+ sections: [
119
+ {
120
+ title: `${CONTACT_FEATURE}:reply.section`,
121
+ description: `${CONTACT_FEATURE}:reply.section.description`,
122
+ fields: [
123
+ { field: "requestId", visible: false },
124
+ { field: "name", visible: false },
125
+ { field: "email", visible: false },
126
+ { field: "replyTo", visible: false },
127
+ "message",
128
+ CONTACT_UPLOAD_FIELD,
129
+ "markDone",
130
+ ],
131
+ },
132
+ ],
133
+ },
134
+ fieldLabels: {
135
+ message: `${REPLY_FIELD_LABEL}.message`,
136
+ [CONTACT_UPLOAD_FIELD]: `${REPLY_FIELD_LABEL}.files`,
137
+ markDone: `${REPLY_FIELD_LABEL}.mark-done`,
138
+ },
139
+ submitLabel: `${CONTACT_FEATURE}:reply.submit`,
140
+ access: { roles: access.systemAdmin },
141
+ };
142
+ }
143
+
144
+ const requestListScreen: EntityListScreenDefinition = {
145
+ id: "request-list",
146
+ type: "entityList",
147
+ entity: "contact-request",
148
+ dormant: true,
149
+ allowCreate: false,
150
+ searchable: true,
151
+ columns: [
152
+ { field: "submittedAt", display: "datetime" },
153
+ "kind",
154
+ { field: "name", label: `${CONTACT_FEATURE}:list.from` },
155
+ { field: "reporterTenantName", label: `${REQUEST_FIELD}:reporterTenantName` },
156
+ { field: "subject", hideOnNarrow: true },
157
+ {
158
+ field: "source",
159
+ hideOnNarrow: true,
160
+ renderer: { format: "enumOption", keyPrefix: `${REQUEST_FIELD}:source:option:` },
161
+ },
162
+ { field: "fileCount", label: `${REQUEST_FIELD}:fileCount`, hideOnNarrow: true },
163
+ "status",
164
+ ],
165
+ facets: {
166
+ status: {
167
+ display: "chips",
168
+ showCounts: true,
169
+ extraOptions: [
170
+ { id: "all", label: `${CONTACT_FEATURE}:filter.all`, values: [], position: "start" },
171
+ ],
172
+ },
173
+ kind: { display: "select" },
174
+ source: { display: "select" },
175
+ },
176
+ defaultFilters: { status: [CONTACT_STATUS.Open] },
177
+ defaultSort: { field: "submittedAt", dir: "desc" },
178
+ rowActions: [
179
+ {
180
+ kind: "navigate",
181
+ id: "open",
182
+ label: `${CONTACT_FEATURE}:action.open`,
183
+ screen: "request-detail",
184
+ entityId: "id",
185
+ rowClick: true,
186
+ },
187
+ {
188
+ kind: "writeHandler",
189
+ id: "mark-done",
190
+ label: `${CONTACT_FEATURE}:action.mark-done`,
191
+ handler: ContactHandlers.markDone,
192
+ payload: { pick: ["id"] },
193
+ visible: { field: "status", ne: CONTACT_STATUS.Done },
194
+ },
195
+ ],
196
+ bulkActions: [{ id: "mark-done", rowAction: "mark-done" }],
197
+ access: { roles: access.systemAdmin },
198
+ };
199
+
200
+ const deliveryStatusTones = {
201
+ [CONTACT_DELIVERY_STATUS.Pending]: "warn",
202
+ [CONTACT_DELIVERY_STATUS.Delivered]: "ok",
203
+ [CONTACT_DELIVERY_STATUS.Failed]: "bad",
204
+ [CONTACT_DELIVERY_STATUS.Skipped]: "neutral",
205
+ [CONTACT_DELIVERY_STATUS.Read]: "accent",
206
+ } as const;
207
+
208
+ function detailLinkTarget(
209
+ link: string | false | undefined,
210
+ defaultScreen: string,
211
+ ): string | undefined {
212
+ if (link === false) return undefined;
213
+ return link ?? defaultScreen;
214
+ }
215
+
216
+ function createRequestDetailScreen(
217
+ opts: ContactOptions,
218
+ settings: ContactSettings,
219
+ ): ProjectionDetailScreenDefinition {
220
+ const userScreen = detailLinkTarget(opts.detailLinks?.user, "user-edit");
221
+ const tenantScreen = detailLinkTarget(opts.detailLinks?.tenant, "tenant-edit");
222
+ return {
223
+ id: "request-detail",
224
+ type: "projectionDetail",
225
+ dormant: true,
226
+ query: ContactQueries.requestDetail,
227
+ listScreenId: "request-list",
228
+ header: {
229
+ title: "subject",
230
+ subtitle: [
231
+ {
232
+ field: "kind",
233
+ format: { format: "enumOption", keyPrefix: `${REQUEST_FIELD}:kind:option:` },
234
+ },
235
+ {
236
+ field: "name",
237
+ ...(userScreen !== undefined && {
238
+ navigate: { screen: userScreen, entityId: "reporterUserId" },
239
+ }),
240
+ },
241
+ {
242
+ field: "reporterTenantName",
243
+ ...(tenantScreen !== undefined && {
244
+ navigate: { screen: tenantScreen, entityId: "reporterTenantId" },
245
+ }),
246
+ },
247
+ {
248
+ field: "submittedAt",
249
+ format: { format: "timestamp", dateStyle: "medium", timeStyle: "short" },
250
+ },
251
+ ],
252
+ status: "status",
253
+ statusFormat: { format: "enumOption", keyPrefix: `${REQUEST_FIELD}:status:option:` },
254
+ statusTones: {
255
+ [CONTACT_STATUS.Open]: "warn",
256
+ [CONTACT_STATUS.Answered]: "accent",
257
+ [CONTACT_STATUS.Done]: "ok",
258
+ },
259
+ },
260
+ actions: [
261
+ {
262
+ kind: "writeHandler",
263
+ id: "mark-done",
264
+ label: `${CONTACT_FEATURE}:action.mark-done`,
265
+ handler: ContactHandlers.markDone,
266
+ icon: "check-circle",
267
+ style: "secondary",
268
+ payload: { pick: ["id"] },
269
+ visible: { field: "status", ne: CONTACT_STATUS.Done },
270
+ },
271
+ {
272
+ kind: "drawer",
273
+ id: "reply",
274
+ icon: "mail",
275
+ style: "primary",
276
+ label: `${CONTACT_FEATURE}:action.reply`,
277
+ screen: "reply",
278
+ params: { map: { requestId: "id", name: "name", email: "email", replyTo: "replyTo" } },
279
+ title: "screen:reply.title",
280
+ visible: { field: "replyChannels", eq: CONTACT_REPLY_CHANNELS.EmailAndInApp },
281
+ },
282
+ {
283
+ kind: "drawer",
284
+ id: "reply-mail",
285
+ icon: "mail",
286
+ style: "primary",
287
+ label: `${CONTACT_FEATURE}:action.reply`,
288
+ screen: "reply-mail",
289
+ params: { map: { requestId: "id", name: "name", email: "email", replyTo: "replyTo" } },
290
+ title: "screen:reply-mail.title",
291
+ visible: { field: "replyChannels", eq: CONTACT_REPLY_CHANNELS.Email },
292
+ },
293
+ ],
294
+ primaryAction: "reply",
295
+ inlineActions: ["mark-done"],
296
+ fieldLabels: {
297
+ message: `${REQUEST_FIELD}:message`,
298
+ fileIds: `${CONTACT_FEATURE}:detail.attachments`,
299
+ name: `${REQUEST_FIELD}:name`,
300
+ email: `${REQUEST_FIELD}:email`,
301
+ phone: `${REQUEST_FIELD}:phone`,
302
+ reporterTenantPlan: `${REQUEST_FIELD}:reporterTenantPlan`,
303
+ origin: `${REQUEST_FIELD}:origin`,
304
+ page: `${REQUEST_FIELD}:page`,
305
+ versionLabel: `${REQUEST_FIELD}:versionLabel`,
306
+ browser: `${REQUEST_FIELD}:browser`,
307
+ },
308
+ layout: {
309
+ sections: [
310
+ { title: `${CONTACT_FEATURE}:detail.section.message`, fields: ["message"] },
311
+ {
312
+ kind: "relatedList",
313
+ readOnly: true,
314
+ title: `${CONTACT_FEATURE}:detail.section.replies`,
315
+ query: ContactQueries.replies,
316
+ columns: [
317
+ {
318
+ field: "sentAt",
319
+ renderer: { format: "timestamp", dateStyle: "medium", timeStyle: "short" },
320
+ label: `${CONTACT_FEATURE}:entity:contact-reply:field:sentAt`,
321
+ },
322
+ {
323
+ field: "authorName",
324
+ label: `${CONTACT_FEATURE}:entity:contact-reply:field:authorName`,
325
+ },
326
+ { field: "message", label: `${CONTACT_FEATURE}:entity:contact-reply:field:message` },
327
+ ],
328
+ },
329
+ {
330
+ title: `${CONTACT_FEATURE}:detail.section.files`,
331
+ fields: [
332
+ {
333
+ field: CONTACT_UPLOAD_FIELD,
334
+ renderer: { format: "file" },
335
+ visible: { field: "fileCount", ne: 0 },
336
+ },
337
+ ],
338
+ },
339
+ {
340
+ title: `${CONTACT_FEATURE}:detail.section.sender`,
341
+ fields: [
342
+ "name",
343
+ { field: "email", format: "email" },
344
+ ...(settings.phone !== "off"
345
+ ? [
346
+ {
347
+ field: "phone",
348
+ format: "phone" as const,
349
+ visible: { field: "phone", notIn: [null, ""] },
350
+ },
351
+ ]
352
+ : []),
353
+ "reporterTenantPlan",
354
+ ],
355
+ },
356
+ {
357
+ title: `${CONTACT_FEATURE}:detail.section.origin`,
358
+ fields: [
359
+ {
360
+ field: "origin",
361
+ renderer: { format: "enumOption", keyPrefix: `${REQUEST_FIELD}:origin:option:` },
362
+ },
363
+ { field: "page", visible: { field: "origin", eq: CONTACT_ORIGIN.Website } },
364
+ "versionLabel",
365
+ "browser",
366
+ ],
367
+ },
368
+ {
369
+ kind: "relatedList",
370
+ readOnly: true,
371
+ title: `${CONTACT_FEATURE}:detail.section.delivery`,
372
+ query: ContactQueries.requestDelivery,
373
+ toolbarActions: [
374
+ {
375
+ kind: "navigate",
376
+ id: "delivery-log",
377
+ label: `${CONTACT_FEATURE}:detail.delivery-log`,
378
+ screen: DELIVERY_LOG_SCREEN_ID,
379
+ },
380
+ ],
381
+ columns: [
382
+ {
383
+ field: "channel",
384
+ label: `${DELIVERY_FIELD}:channel`,
385
+ renderer: { format: "enumOption", keyPrefix: `${DELIVERY_FIELD}:channel:option:` },
386
+ },
387
+ { field: "recipient", label: `${DELIVERY_FIELD}:recipient` },
388
+ {
389
+ field: "at",
390
+ renderer: { format: "timestamp", dateStyle: "medium", timeStyle: "short" },
391
+ label: `${DELIVERY_FIELD}:at`,
392
+ },
393
+ {
394
+ field: "status",
395
+ label: `${DELIVERY_FIELD}:status`,
396
+ renderer: {
397
+ format: "enumOption",
398
+ keyPrefix: `${DELIVERY_FIELD}:status:option:`,
399
+ tones: deliveryStatusTones,
400
+ },
401
+ },
402
+ ],
403
+ },
404
+ {
405
+ kind: "extension",
406
+ title: `${CONTACT_FEATURE}:detail.section.notes`,
407
+ component: { react: { __component: "NotesSection" } },
408
+ entityName: "contact-request",
409
+ },
410
+ ],
411
+ },
412
+ access: { roles: access.systemAdmin },
413
+ };
414
+ }
415
+
416
+ function createForwardingScreen(telegram: boolean): ConfigEditScreenDefinition {
417
+ return {
418
+ id: "forwarding",
419
+ type: "configEdit",
420
+ dormant: true,
421
+ scope: "system",
422
+ configKeys: {
423
+ replyTo: ContactConfigKeys.replyTo,
424
+ ...(telegram && { telegramChat: ContactConfigKeys.telegramChat }),
425
+ },
426
+ ...(telegram && { secretKeys: { botToken: TELEGRAM_BOT_TOKEN_SECRET } }),
427
+ fields: {
428
+ replyTo: createTextField({
429
+ format: "email",
430
+ maxLength: 254,
431
+ personal: false,
432
+ reason: "is_business_data",
433
+ }),
434
+ ...(telegram && {
435
+ telegramChat: createTextField({
436
+ maxLength: 64,
437
+ personal: false,
438
+ reason: "is_business_data",
439
+ }),
440
+ botToken: createTextField({
441
+ writeOnly: true,
442
+ maxLength: 200,
443
+ personal: false,
444
+ reason: "is_business_data",
445
+ }),
446
+ }),
447
+ },
448
+ layout: {
449
+ variant: "settings-list",
450
+ sections: [
451
+ {
452
+ title: `${CONTACT_FEATURE}:forwarding.email`,
453
+ description: `${CONTACT_FEATURE}:forwarding.email.description`,
454
+ fields: ["replyTo"],
455
+ },
456
+ ...(telegram
457
+ ? [
458
+ {
459
+ title: `${CONTACT_FEATURE}:forwarding.telegram`,
460
+ description: `${CONTACT_FEATURE}:forwarding.telegram.description`,
461
+ fields: ["telegramChat", "botToken"],
462
+ },
463
+ ]
464
+ : []),
465
+ ],
466
+ },
467
+ fieldLabels: {
468
+ replyTo: `${CONTACT_FEATURE}:config.reply-to.label`,
469
+ telegramChat: `${CONTACT_FEATURE}:config.telegram-chat.label`,
470
+ botToken: `${CONTACT_FEATURE}:config.bot-token.label`,
471
+ },
472
+ fieldDescriptions: {
473
+ replyTo: `${CONTACT_FEATURE}:config.reply-to.description`,
474
+ telegramChat: `${CONTACT_FEATURE}:config.telegram-chat.description`,
475
+ botToken: `${CONTACT_FEATURE}:config.bot-token.description`,
476
+ },
477
+ submitLabel: `${CONTACT_FEATURE}:forwarding.submit`,
478
+ ...(telegram && {
479
+ actions: [
480
+ {
481
+ id: "send-test",
482
+ handler: ContactHandlers.sendTest,
483
+ label: `${CONTACT_FEATURE}:config.send-test.label`,
484
+ description: `${CONTACT_FEATURE}:config.send-test.description`,
485
+ buttonLabel: `${CONTACT_FEATURE}:config.send-test.button`,
486
+ afterField: "botToken",
487
+ successMessage: `${CONTACT_FEATURE}:config.send-test.success`,
488
+ },
489
+ ],
490
+ }),
491
+ access: { roles: access.systemAdmin },
492
+ };
493
+ }
494
+
495
+ export function createContactScreens(
496
+ opts: ContactOptions,
497
+ settings: ContactSettings,
498
+ ): readonly ScreenDefinition[] {
499
+ return [
500
+ createReportScreen(opts, settings),
501
+ requestListScreen,
502
+ createRequestDetailScreen(opts, settings),
503
+ createReplyScreen("reply", `${CONTACT_FEATURE}:reply.summary.in-app`),
504
+ createReplyScreen("reply-mail", `${CONTACT_FEATURE}:reply.summary.mail`),
505
+ createForwardingScreen(opts.telegram === true),
506
+ ];
507
+ }
@@ -0,0 +1,13 @@
1
+ import { CONTACT_SUBJECT_MAX_CHARS } from "./web/constants.ts";
2
+
3
+ // The website form has no subject field; the first non-empty line of the message stands in for it.
4
+ export function deriveSubjectFromMessage(message: string): string {
5
+ const firstLine = message.split(/[\r\n]/).find((line) => line.trim() !== "") ?? "";
6
+ const trimmed = firstLine.trim();
7
+ const chars = [...trimmed];
8
+ if (chars.length <= CONTACT_SUBJECT_MAX_CHARS) return trimmed;
9
+ return `${chars
10
+ .slice(0, CONTACT_SUBJECT_MAX_CHARS - 1)
11
+ .join("")
12
+ .trimEnd()}…`;
13
+ }
@@ -0,0 +1,39 @@
1
+ type BrowserName = "Edge" | "Opera" | "Firefox" | "Chrome" | "Safari";
2
+ type OsName = "Windows" | "macOS" | "iOS" | "Android" | "Linux";
3
+
4
+ // Order matters: Edge and Opera also say "Chrome", Chrome also says "Safari".
5
+ const BROWSER_PATTERNS: readonly (readonly [BrowserName, RegExp])[] = [
6
+ ["Edge", /\bEdg(?:e|A|iOS)?\/(\d+)/],
7
+ ["Opera", /\b(?:OPR|Opera)\/(\d+)/],
8
+ ["Firefox", /\b(?:Firefox|FxiOS)\/(\d+)/],
9
+ ["Chrome", /\b(?:Chrome|CriOS)\/(\d+)/],
10
+ ["Safari", /\bVersion\/(\d+)[\s\S]*\bSafari\//],
11
+ ];
12
+
13
+ // iOS and Android UAs also contain "Mac OS X" / "Linux", so they are tested first.
14
+ const OS_PATTERNS: readonly (readonly [OsName, RegExp])[] = [
15
+ ["iOS", /\b(?:iPhone|iPad|iPod)\b/],
16
+ ["Android", /\bAndroid\b/],
17
+ ["Windows", /\bWindows\b/],
18
+ ["macOS", /\bMac OS X\b|\bMacintosh\b/],
19
+ ["Linux", /\b(?:Linux|X11)\b/],
20
+ ];
21
+
22
+ const CONNECTOR_BY_LANGUAGE: Readonly<Record<string, string>> = { de: "auf", en: "on" };
23
+
24
+ function languageOf(locale: string): string {
25
+ return locale.split("-")[0]?.toLowerCase() ?? "en";
26
+ }
27
+
28
+ // Null when the UA names no known browser; the browser column is a hint for operators, not an identity.
29
+ export function summarizeUserAgent(userAgent: string | undefined, locale: string): string | null {
30
+ if (userAgent === undefined) return null;
31
+ const browser = BROWSER_PATTERNS.map(([name, pattern]) => {
32
+ const version = pattern.exec(userAgent)?.[1];
33
+ return version === undefined ? undefined : `${name} ${version}`;
34
+ }).find((summary) => summary !== undefined);
35
+ if (browser === undefined) return null;
36
+ const os = OS_PATTERNS.find(([, pattern]) => pattern.test(userAgent))?.[0];
37
+ if (os === undefined) return browser;
38
+ return `${browser} ${CONNECTOR_BY_LANGUAGE[languageOf(locale)] ?? "on"} ${os}`;
39
+ }