@cosmicdrift/kumiko-bundled-features 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 (337) hide show
  1. package/dist/account-security/feature.js +9 -1
  2. package/dist/admin-shell/feature.d.ts +3 -0
  3. package/dist/admin-shell/feature.js +1 -1
  4. package/dist/agent-tools/agent-manifest.js +1 -0
  5. package/dist/agent-tools/tool-catalog.js +1 -0
  6. package/dist/agent-tools/types.d.ts +4 -1
  7. package/dist/audit/event-classification.js +1 -0
  8. package/dist/auth-email-password/bootstrap.js +1 -0
  9. package/dist/auth-email-password/errors.js +16 -41
  10. package/dist/auth-email-password/web/auth-client.d.ts +8 -32
  11. package/dist/auth-email-password/web/auth-client.js +18 -52
  12. package/dist/auth-email-password/web/auth-redirect.js +2 -2
  13. package/dist/auth-email-password/web/confirm-account-unlock-screen.d.ts +2 -2
  14. package/dist/auth-email-password/web/confirm-account-unlock-screen.js +14 -35
  15. package/dist/auth-email-password/web/index.d.ts +1 -0
  16. package/dist/auth-email-password/web/index.js +1 -0
  17. package/dist/auth-email-password/web/read-path-param.d.ts +1 -0
  18. package/dist/auth-email-password/web/read-path-param.js +4 -0
  19. package/dist/auth-email-password/web/return-path.js +2 -2
  20. package/dist/auth-email-password/web/token-confirm-screen.d.ts +20 -0
  21. package/dist/auth-email-password/web/token-confirm-screen.js +38 -0
  22. package/dist/auth-email-password/web/verify-email-screen.d.ts +2 -2
  23. package/dist/auth-email-password/web/verify-email-screen.js +14 -37
  24. package/dist/auth-foundation/boot-checks.js +24 -12
  25. package/dist/auth-foundation/boot-rules.d.ts +27 -0
  26. package/dist/auth-foundation/boot-rules.js +27 -0
  27. package/dist/auth-mfa/errors.d.ts +1 -1
  28. package/dist/auth-mfa/errors.js +11 -24
  29. package/dist/auth-mfa/feature-exports.js +6 -45
  30. package/dist/auth-mfa/feature.js +7 -18
  31. package/dist/auth-mfa/web/mfa-client.js +11 -25
  32. package/dist/billing-foundation/consumer-protection/termination-notify.js +1 -0
  33. package/dist/billing-foundation/web/plan-price.js +7 -8
  34. package/dist/cap-counter/stock-cap-guard.js +1 -0
  35. package/dist/channel-in-app/constants.d.ts +1 -0
  36. package/dist/channel-in-app/feature.js +2 -0
  37. package/dist/channel-in-app/handlers/read-state-by-keys.query.d.ts +9 -0
  38. package/dist/channel-in-app/handlers/read-state-by-keys.query.js +21 -0
  39. package/dist/channel-in-app/in-app-channel.js +1 -0
  40. package/dist/channel-in-app/tables.js +5 -1
  41. package/dist/contact/challenge.d.ts +14 -0
  42. package/dist/contact/challenge.js +30 -0
  43. package/dist/contact/client/contact-client-source.d.ts +1 -0
  44. package/dist/contact/client/contact-client-source.js +203 -0
  45. package/dist/contact/entity.d.ts +777 -0
  46. package/dist/contact/entity.js +145 -0
  47. package/dist/contact/feature.d.ts +3 -0
  48. package/dist/contact/feature.js +130 -0
  49. package/dist/contact/handlers/access.d.ts +7 -0
  50. package/dist/contact/handlers/access.js +9 -0
  51. package/dist/contact/handlers/attempts.d.ts +14 -0
  52. package/dist/contact/handlers/attempts.js +54 -0
  53. package/dist/contact/handlers/challenge.query.d.ts +9 -0
  54. package/dist/contact/handlers/challenge.query.js +35 -0
  55. package/dist/contact/handlers/forward-request.write.d.ts +9 -0
  56. package/dist/contact/handlers/forward-request.write.js +61 -0
  57. package/dist/contact/handlers/mark-done.write.d.ts +7 -0
  58. package/dist/contact/handlers/mark-done.write.js +30 -0
  59. package/dist/contact/handlers/notify-reporter-in-app.write.d.ts +10 -0
  60. package/dist/contact/handlers/notify-reporter-in-app.write.js +36 -0
  61. package/dist/contact/handlers/open-count.d.ts +2 -0
  62. package/dist/contact/handlers/open-count.js +11 -0
  63. package/dist/contact/handlers/open-count.query.d.ts +3 -0
  64. package/dist/contact/handlers/open-count.query.js +13 -0
  65. package/dist/contact/handlers/replies.query.d.ts +11 -0
  66. package/dist/contact/handlers/replies.query.js +28 -0
  67. package/dist/contact/handlers/reply.write.d.ts +12 -0
  68. package/dist/contact/handlers/reply.write.js +118 -0
  69. package/dist/contact/handlers/report.write.d.ts +16 -0
  70. package/dist/contact/handlers/report.write.js +90 -0
  71. package/dist/contact/handlers/request-delivery.query.d.ts +16 -0
  72. package/dist/contact/handlers/request-delivery.query.js +85 -0
  73. package/dist/contact/handlers/request-detail.query.d.ts +41 -0
  74. package/dist/contact/handlers/request-detail.query.js +32 -0
  75. package/dist/contact/handlers/request-list.query.d.ts +2 -0
  76. package/dist/contact/handlers/request-list.query.js +9 -0
  77. package/dist/contact/handlers/send-reply-mail.write.d.ts +8 -0
  78. package/dist/contact/handlers/send-reply-mail.write.js +82 -0
  79. package/dist/contact/handlers/send-test.write.d.ts +5 -0
  80. package/dist/contact/handlers/send-test.write.js +36 -0
  81. package/dist/contact/handlers/submit.write.d.ts +20 -0
  82. package/dist/contact/handlers/submit.write.js +137 -0
  83. package/dist/contact/handlers/take-over-uploads.d.ts +9 -0
  84. package/dist/contact/handlers/take-over-uploads.js +33 -0
  85. package/dist/contact/i18n.d.ts +6 -0
  86. package/dist/contact/i18n.js +186 -0
  87. package/dist/contact/index.d.ts +5 -0
  88. package/dist/contact/index.js +4 -0
  89. package/dist/contact/lib.d.ts +101 -0
  90. package/dist/contact/lib.js +109 -0
  91. package/dist/contact/mail.d.ts +91 -0
  92. package/dist/contact/mail.js +279 -0
  93. package/dist/contact/options.d.ts +51 -0
  94. package/dist/contact/options.js +32 -0
  95. package/dist/contact/panels.d.ts +2 -0
  96. package/dist/contact/panels.js +21 -0
  97. package/dist/contact/payloads.d.ts +56 -0
  98. package/dist/contact/payloads.js +82 -0
  99. package/dist/contact/pow.d.ts +6 -0
  100. package/dist/contact/pow.js +19 -0
  101. package/dist/contact/screens.d.ts +5 -0
  102. package/dist/contact/screens.js +464 -0
  103. package/dist/contact/subject.d.ts +1 -0
  104. package/dist/contact/subject.js +13 -0
  105. package/dist/contact/user-agent.d.ts +1 -0
  106. package/dist/contact/user-agent.js +35 -0
  107. package/dist/contact/user-data-hooks.d.ts +3 -0
  108. package/dist/contact/user-data-hooks.js +129 -0
  109. package/dist/contact/web/constants.d.ts +127 -0
  110. package/dist/contact/web/constants.js +126 -0
  111. package/dist/contact/web/index.d.ts +1 -0
  112. package/dist/contact/web/index.js +1 -0
  113. package/dist/crypto-shredding/handlers/forget-subject.write.js +5 -13
  114. package/dist/data-retention/feature.js +16 -2
  115. package/dist/data-retention/index.d.ts +1 -0
  116. package/dist/data-retention/index.js +1 -0
  117. package/dist/data-retention/run-retention-cleanup.d.ts +14 -2
  118. package/dist/data-retention/run-retention-cleanup.js +102 -36
  119. package/dist/data-retention/tenant-destruction-hold.d.ts +23 -0
  120. package/dist/data-retention/tenant-destruction-hold.js +132 -0
  121. package/dist/delivery/address-opt-out.js +1 -0
  122. package/dist/delivery/channel-context.d.ts +1 -1
  123. package/dist/delivery/channel-context.js +2 -1
  124. package/dist/delivery/delivery-service.js +18 -8
  125. package/dist/delivery/events.d.ts +1 -0
  126. package/dist/delivery/events.js +2 -0
  127. package/dist/delivery/feature.js +3 -0
  128. package/dist/delivery/handlers/attempts-by-keys.query.d.ts +15 -0
  129. package/dist/delivery/handlers/attempts-by-keys.query.js +35 -0
  130. package/dist/delivery/handlers/log.query.d.ts +1 -0
  131. package/dist/delivery/handlers/log.query.js +1 -1
  132. package/dist/delivery/jobs.js +5 -2
  133. package/dist/delivery/tables.js +12 -2
  134. package/dist/delivery/types.d.ts +2 -0
  135. package/dist/delivery/unsubscribe-page.js +2 -0
  136. package/dist/delivery/web/delivery-channel-cell.js +1 -1
  137. package/dist/delivery/web/delivery-error-cell.js +1 -1
  138. package/dist/delivery/web/delivery-status-cell.js +1 -1
  139. package/dist/delivery/web/delivery-time-cell.js +3 -2
  140. package/dist/delivery/web/delivery-type-cell.js +1 -1
  141. package/dist/delivery/web/public-names.d.ts +1 -0
  142. package/dist/delivery/web/public-names.js +1 -0
  143. package/dist/document-ingest-foundation/boot-checks.js +19 -11
  144. package/dist/document-ingest-foundation/boot-rules.d.ts +17 -0
  145. package/dist/document-ingest-foundation/boot-rules.js +17 -0
  146. package/dist/document-ingest-foundation/events.d.ts +8 -0
  147. package/dist/document-ingest-foundation/events.js +12 -0
  148. package/dist/document-ingest-foundation/feature.js +30 -2
  149. package/dist/document-ingest-foundation/index.d.ts +3 -1
  150. package/dist/document-ingest-foundation/index.js +3 -1
  151. package/dist/document-ingest-foundation/report-ingest-progress.d.ts +14 -0
  152. package/dist/document-ingest-foundation/report-ingest-progress.js +20 -0
  153. package/dist/document-ingest-foundation/tables.d.ts +3 -0
  154. package/dist/document-ingest-foundation/tables.js +26 -0
  155. package/dist/files-tenant-data/hooks.js +4 -1
  156. package/dist/folders/web/folder-manager.js +3 -10
  157. package/dist/folders/web/folder-section.js +1 -1
  158. package/dist/form-draft-user-data/index.js +4 -1
  159. package/dist/inbound-mail-foundation/entities.d.ts +3 -0
  160. package/dist/inbound-mail-foundation/entities.js +2 -0
  161. package/dist/inbound-mail-foundation/events.d.ts +2 -0
  162. package/dist/inbound-mail-foundation/events.js +2 -0
  163. package/dist/inbound-mail-foundation/feature.js +6 -6
  164. package/dist/inbound-mail-foundation/handlers/attach-message-content.write.js +3 -1
  165. package/dist/inbound-mail-foundation/handlers/ingest-message.write.js +5 -0
  166. package/dist/inbound-mail-foundation/handlers/list-messages.query.js +4 -2
  167. package/dist/inbound-mail-foundation/handlers/message-content.d.ts +1 -0
  168. package/dist/inbound-mail-foundation/handlers/message-content.js +8 -0
  169. package/dist/inbound-mail-foundation/handlers/message-content.query.d.ts +2 -0
  170. package/dist/inbound-mail-foundation/handlers/message-content.query.js +1 -0
  171. package/dist/inbound-mail-foundation/projection.d.ts +3 -0
  172. package/dist/inbound-mail-foundation/projection.js +2 -0
  173. package/dist/inbound-mail-foundation/sanitize-inbound-html.d.ts +2 -0
  174. package/dist/inbound-mail-foundation/sanitize-inbound-html.js +135 -0
  175. package/dist/inbound-mail-foundation/types.js +1 -0
  176. package/dist/jobs/job-run-logger.js +16 -20
  177. package/dist/ledger/handlers/reports.query.js +25 -27
  178. package/dist/ledger/recurring.js +1 -0
  179. package/dist/notes-history/web/notes-section.js +3 -2
  180. package/dist/personal-access-tokens/feature.js +5 -18
  181. package/dist/personal-access-tokens/handlers/create.write.js +2 -5
  182. package/dist/secrets/handlers/delete.write.d.ts +4 -0
  183. package/dist/secrets/handlers/delete.write.js +9 -4
  184. package/dist/secrets/handlers/list.query.d.ts +6 -1
  185. package/dist/secrets/handlers/list.query.js +7 -3
  186. package/dist/secrets/handlers/set.write.d.ts +4 -0
  187. package/dist/secrets/handlers/set.write.js +10 -4
  188. package/dist/secrets/secret-scope.d.ts +17 -0
  189. package/dist/secrets/secret-scope.js +18 -0
  190. package/dist/sessions/feature.d.ts +3 -0
  191. package/dist/sessions/feature.js +13 -19
  192. package/dist/sessions/handlers/last-activity-probe.query.d.ts +7 -0
  193. package/dist/sessions/handlers/last-activity-probe.query.js +40 -0
  194. package/dist/sessions/handlers/last-activity-probe.route.d.ts +2 -0
  195. package/dist/sessions/handlers/last-activity-probe.route.js +30 -0
  196. package/dist/sessions/screens.js +1 -0
  197. package/dist/sessions/session-callbacks.d.ts +2 -0
  198. package/dist/sessions/session-callbacks.js +9 -7
  199. package/dist/sessions/web/i18n.js +4 -1
  200. package/dist/shared/assert-billing-live.d.ts +2 -0
  201. package/dist/shared/assert-billing-live.js +7 -0
  202. package/dist/shared/collect-extension-options.d.ts +1 -0
  203. package/dist/shared/collect-extension-options.js +8 -0
  204. package/dist/shared/index.d.ts +7 -1
  205. package/dist/shared/index.js +7 -1
  206. package/dist/shared/late-bound-slot.d.ts +5 -0
  207. package/dist/shared/late-bound-slot.js +13 -0
  208. package/dist/shared/mail-locale-templates.d.ts +1 -0
  209. package/dist/shared/mail-locale-templates.js +1 -1
  210. package/dist/shared/price-env-shape.d.ts +11 -0
  211. package/dist/shared/price-env-shape.js +15 -0
  212. package/dist/shared/purge-row-file-refs.d.ts +1 -0
  213. package/dist/shared/purge-row-file-refs.js +1 -1
  214. package/dist/shared/read-feature-export-fn.d.ts +2 -0
  215. package/dist/shared/read-feature-export-fn.js +11 -0
  216. package/dist/shared/signup-handover.js +3 -5
  217. package/dist/shared/tenant-destruction-hold.d.ts +23 -0
  218. package/dist/shared/tenant-destruction-hold.js +15 -0
  219. package/dist/shared/unprocessable.d.ts +4 -0
  220. package/dist/shared/unprocessable.js +4 -0
  221. package/dist/shared/web/index.d.ts +3 -0
  222. package/dist/shared/web/index.js +3 -0
  223. package/dist/subscription-paddle/feature.d.ts +1 -5
  224. package/dist/subscription-paddle/feature.js +7 -9
  225. package/dist/subscription-paddle/runtime.js +3 -7
  226. package/dist/subscription-stripe/feature.d.ts +1 -5
  227. package/dist/subscription-stripe/feature.js +7 -9
  228. package/dist/subscription-stripe/runtime.js +3 -7
  229. package/dist/tags/entity.js +1 -0
  230. package/dist/tags/web/tag-chip.d.ts +7 -0
  231. package/dist/tags/web/tag-chip.js +4 -0
  232. package/dist/tags/web/tag-filter.js +2 -5
  233. package/dist/tags/web/tag-manager.js +1 -1
  234. package/dist/tags/web/tag-section.js +3 -6
  235. package/dist/tags/web/tags-cell.js +2 -5
  236. package/dist/template-resolver/compile-document-body.js +12 -17
  237. package/dist/template-resolver/handlers/by-tenant.query.js +3 -1
  238. package/dist/template-resolver/handlers/discard-draft.write.js +1 -0
  239. package/dist/template-resolver/handlers/overview.query.js +3 -1
  240. package/dist/template-resolver/handlers/send-test.write.js +2 -4
  241. package/dist/template-resolver/handlers/toggle-status.write.js +3 -0
  242. package/dist/template-resolver/linked-resources.js +6 -5
  243. package/dist/template-resolver/store-template-resource.js +5 -10
  244. package/dist/template-resolver/web/document-images.js +6 -6
  245. package/dist/template-resolver/web/document-insert-fields.js +22 -4
  246. package/dist/template-resolver/web/document-schema.js +11 -12
  247. package/dist/template-resolver/web/tiptap-attribute-parse-rule.d.ts +15 -0
  248. package/dist/template-resolver/web/tiptap-attribute-parse-rule.js +11 -0
  249. package/dist/tenant/i18n.js +3 -0
  250. package/dist/tenant/schema/tenant.d.ts +9 -7
  251. package/dist/tenant/schema/tenant.js +1 -0
  252. package/dist/tenant/web/member-roles-cell.js +1 -1
  253. package/dist/tenant/web/member-status-cell.js +1 -1
  254. package/dist/tenant-inactivity/check-inactive-tenants.d.ts +3 -0
  255. package/dist/tenant-inactivity/check-inactive-tenants.js +184 -0
  256. package/dist/tenant-inactivity/constants.d.ts +10 -0
  257. package/dist/tenant-inactivity/constants.js +10 -0
  258. package/dist/tenant-inactivity/email-templates.d.ts +3 -0
  259. package/dist/tenant-inactivity/email-templates.js +16 -0
  260. package/dist/tenant-inactivity/feature.d.ts +8 -0
  261. package/dist/tenant-inactivity/feature.js +45 -0
  262. package/dist/tenant-inactivity/handlers/inactivity-state.query.d.ts +11 -0
  263. package/dist/tenant-inactivity/handlers/inactivity-state.query.js +45 -0
  264. package/dist/tenant-inactivity/handlers/keep-account.write.d.ts +8 -0
  265. package/dist/tenant-inactivity/handlers/keep-account.write.js +48 -0
  266. package/dist/tenant-inactivity/inactivity-plan.d.ts +51 -0
  267. package/dist/tenant-inactivity/inactivity-plan.js +113 -0
  268. package/dist/tenant-inactivity/index.d.ts +5 -0
  269. package/dist/tenant-inactivity/index.js +3 -0
  270. package/dist/tenant-inactivity/keep-token.d.ts +16 -0
  271. package/dist/tenant-inactivity/keep-token.js +24 -0
  272. package/dist/tenant-inactivity/mail-notifications.d.ts +4 -0
  273. package/dist/tenant-inactivity/mail-notifications.js +42 -0
  274. package/dist/tenant-inactivity/options.d.ts +27 -0
  275. package/dist/tenant-inactivity/options.js +5 -0
  276. package/dist/tenant-inactivity/remote-activity.d.ts +15 -0
  277. package/dist/tenant-inactivity/remote-activity.js +24 -0
  278. package/dist/tenant-inactivity/state-store.d.ts +10 -0
  279. package/dist/tenant-inactivity/state-store.js +50 -0
  280. package/dist/tenant-inactivity/state-table.d.ts +109 -0
  281. package/dist/tenant-inactivity/state-table.js +38 -0
  282. package/dist/tenant-lifecycle/boot-checks.js +8 -3
  283. package/dist/tenant-lifecycle/boot-rules.d.ts +12 -0
  284. package/dist/tenant-lifecycle/boot-rules.js +12 -0
  285. package/dist/tenant-lifecycle/constants.d.ts +1 -0
  286. package/dist/tenant-lifecycle/constants.js +5 -0
  287. package/dist/tenant-lifecycle/events.d.ts +2 -0
  288. package/dist/tenant-lifecycle/events.js +2 -0
  289. package/dist/tenant-lifecycle/feature.js +18 -3
  290. package/dist/tenant-lifecycle/handlers/request-destruction.write.js +11 -67
  291. package/dist/tenant-lifecycle/index.d.ts +2 -1
  292. package/dist/tenant-lifecycle/index.js +2 -1
  293. package/dist/tenant-lifecycle/request-tenant-destruction.d.ts +20 -0
  294. package/dist/tenant-lifecycle/request-tenant-destruction.js +66 -0
  295. package/dist/tenant-lifecycle/retention-config-destroy-hooks.d.ts +5 -0
  296. package/dist/tenant-lifecycle/retention-config-destroy-hooks.js +29 -0
  297. package/dist/tenant-lifecycle/run-tenant-destroy.d.ts +5 -0
  298. package/dist/tenant-lifecycle/run-tenant-destroy.js +85 -12
  299. package/dist/tenant-lifecycle/stages.d.ts +3 -0
  300. package/dist/tenant-lifecycle/stages.js +27 -3
  301. package/dist/tenant-lifecycle/testing.js +1 -1
  302. package/dist/tier-engine/caps-for-tier-from-map.d.ts +5 -0
  303. package/dist/tier-engine/caps-for-tier-from-map.js +12 -0
  304. package/dist/tier-engine/compose-app.d.ts +0 -22
  305. package/dist/tier-engine/compose-app.js +9 -16
  306. package/dist/tier-engine/index.d.ts +1 -0
  307. package/dist/tier-engine/index.js +1 -0
  308. package/dist/user/handlers/detail.query.d.ts +1 -1
  309. package/dist/user-data-rights/feature.js +2 -0
  310. package/dist/user-data-rights/run-forget-cleanup.js +2 -0
  311. package/dist/user-data-rights/web/privacy-center-screen.js +1 -1
  312. package/dist/user-data-rights/zip-path.js +1 -0
  313. package/dist/user-data-rights-defaults/hooks/config-value.userdata-hook.d.ts +1 -1
  314. package/dist/user-data-rights-defaults/hooks/config-value.userdata-hook.js +7 -20
  315. package/dist/user-data-rights-defaults/hooks/delivery-attempt.userdata-hook.js +3 -1
  316. package/dist/user-data-rights-defaults/hooks/forget-own-rows-delete-hook.d.ts +10 -0
  317. package/dist/user-data-rights-defaults/hooks/forget-own-rows-delete-hook.js +26 -0
  318. package/dist/user-data-rights-defaults/hooks/notification-preference.userdata-hook.d.ts +1 -1
  319. package/dist/user-data-rights-defaults/hooks/notification-preference.userdata-hook.js +7 -20
  320. package/dist/user-profile/handlers/change-email.write.js +2 -4
  321. package/dist/user-profile/web/profile-screen.js +2 -3
  322. package/kumiko-es-tables.json +12 -0
  323. package/package.json +46 -12
  324. package/src/admin-shell/changes.json +6 -0
  325. package/src/agent-tools/changes.json +6 -0
  326. package/src/channel-in-app/changes.json +7 -0
  327. package/src/contact/changes.json +27 -0
  328. package/src/data-retention/changes.json +6 -0
  329. package/src/delivery/changes.json +7 -0
  330. package/src/document-ingest-foundation/changes.json +6 -0
  331. package/src/files-tenant-data/changes.json +6 -0
  332. package/src/inbound-mail-foundation/changes.json +13 -0
  333. package/src/secrets/changes.json +6 -0
  334. package/src/sessions/changes.json +6 -0
  335. package/src/tenant-inactivity/changes.json +8 -0
  336. package/src/tenant-lifecycle/changes.json +30 -0
  337. package/src/tier-engine/changes.json +6 -0
@@ -0,0 +1,137 @@
1
+ import { requestContext } from "@cosmicdrift/kumiko-framework/api";
2
+ import { defineWriteHandler, } from "@cosmicdrift/kumiko-framework/engine";
3
+ import { InternalError, isKumikoError, UnprocessableError, writeFailure, } from "@cosmicdrift/kumiko-framework/errors";
4
+ import { normalizePayloadBucketValue } from "@cosmicdrift/kumiko-framework/pipeline";
5
+ import { generateId } from "@cosmicdrift/kumiko-framework/utils";
6
+ import { consumeChallenge } from "../challenge.js";
7
+ import { contactDb, normalizeEmail, phoneProblem, platformActor, requestExecutor, sendBestEffort, } from "../lib.js";
8
+ import { contactAcknowledgementVariables, resolveContactMailLocale } from "../mail.js";
9
+ import { DEFAULT_SUBMIT_EMAIL_RATE_LIMITS, DEFAULT_SUBMIT_RATE_LIMIT, } from "../options.js";
10
+ import { ContactSubmitSchema } from "../payloads.js";
11
+ import { verifyProofOfWork } from "../pow.js";
12
+ import { deriveSubjectFromMessage } from "../subject.js";
13
+ import { summarizeUserAgent } from "../user-agent.js";
14
+ import { CONTACT_NOTIFICATION_TYPES, CONTACT_SOURCE, CONTACT_STATUS, ContactHandlers, contactIdempotencyKeys, } from "../web/constants.js";
15
+ import { SUBMIT_ROLES } from "./access.js";
16
+ // Identical body for stored and silently dropped submits, so a bot learns nothing from it.
17
+ const SUBMITTED = {
18
+ isSuccess: true,
19
+ data: { kind: "submitted" },
20
+ };
21
+ // An explicitly bound `undefined` is an error for the postgres driver; a missing key is not.
22
+ function presentOptionalFields(payload) {
23
+ return {
24
+ ...(payload.phone !== undefined && payload.phone !== "" && { phone: payload.phone }),
25
+ ...(payload.page !== undefined && payload.page !== "" && { page: payload.page }),
26
+ };
27
+ }
28
+ async function findDropReason(payload, ctx, settings) {
29
+ if (payload.website !== undefined && payload.website.trim() !== "")
30
+ return "honeypot";
31
+ const redis = ctx.services.redis;
32
+ if (!redis) {
33
+ throw new InternalError({
34
+ message: "contact:submit requires ctx.services.redis for the challenge store",
35
+ });
36
+ }
37
+ const issued = await consumeChallenge(redis, payload.challenge);
38
+ if (!issued)
39
+ return "challenge";
40
+ if (ctx.tz.now().epochMilliseconds - issued.issuedAtMs < settings.minSubmitMs)
41
+ return "too_fast";
42
+ if (!verifyProofOfWork({ challenge: payload.challenge, nonce: payload.nonce, bits: issued.bits })) {
43
+ return "proof_of_work";
44
+ }
45
+ return null;
46
+ }
47
+ // Counted here instead of as a payload bucket in front of the handler: a bot that posts a victim's
48
+ // address without solving the challenge would otherwise exhaust that address's quota and lock the
49
+ // real owner out. Only submits that passed the spam checks count. An empty list disables the limit.
50
+ async function enforceEmailLimits(ctx, payload, limits) {
51
+ if (limits.length === 0)
52
+ return null;
53
+ const { rateLimit } = ctx.services;
54
+ if (!rateLimit || !ctx.rateLimitDigest) {
55
+ throw new InternalError({
56
+ message: "contact:submit declares an email rate limit but no rate limiter or digest is wired",
57
+ });
58
+ }
59
+ const requests = limits.map(({ per, limit, windowSeconds, cost, normalize }) => ({
60
+ bucket: `contact-submit:${per.payloadField}:${ctx.rateLimitDigest?.(normalizePayloadBucketValue(payload.email, normalize))}`,
61
+ config: { limit, windowSeconds, ...(cost !== undefined && { cost }) },
62
+ }));
63
+ try {
64
+ await rateLimit.enforceAll(requests);
65
+ }
66
+ catch (error) {
67
+ if (isKumikoError(error))
68
+ return writeFailure(error);
69
+ throw error;
70
+ }
71
+ return null;
72
+ }
73
+ export function createSubmitHandler(opts, settings) {
74
+ const emailRateLimits = opts.emailRateLimits ?? DEFAULT_SUBMIT_EMAIL_RATE_LIMITS;
75
+ return defineWriteHandler({
76
+ name: "submit",
77
+ schema: ContactSubmitSchema,
78
+ access: { roles: SUBMIT_ROLES, personalData: "public-intake" },
79
+ rateLimit: opts.rateLimit ?? DEFAULT_SUBMIT_RATE_LIMIT,
80
+ agent: { expose: false },
81
+ description: "Public contact form: stores a question, contact request or problem report from a website visitor after a single-use proof-of-work challenge, forwards it to the SystemAdmins (mail, optional Telegram) and mails the sender a copy. Spam (honeypot, unknown or reused challenge, too fast, wrong proof of work) gets the same success body but nothing is stored or sent.",
82
+ handler: async (event, ctx) => {
83
+ const payload = event.payload;
84
+ const dropReason = await findDropReason(payload, ctx, settings);
85
+ if (dropReason !== null) {
86
+ ctx.obs.log?.info("[contact:submit] dropped", { reason: dropReason });
87
+ return SUBMITTED;
88
+ }
89
+ // Before the email limit, so a mistyped phone number does not use up the sender's quota.
90
+ const phoneIssue = phoneProblem(settings.phone, payload.phone);
91
+ if (phoneIssue !== null)
92
+ return writeFailure(new UnprocessableError(phoneIssue));
93
+ const limited = await enforceEmailLimits(ctx, payload, emailRateLimits);
94
+ if (limited !== null)
95
+ return limited;
96
+ const email = normalizeEmail(payload.email);
97
+ const browser = summarizeUserAgent(requestContext.get()?.userAgent, payload.locale);
98
+ const requestId = generateId();
99
+ const created = await requestExecutor.create({
100
+ id: requestId,
101
+ kind: payload.kind,
102
+ status: CONTACT_STATUS.Open,
103
+ source: CONTACT_SOURCE.Website,
104
+ subject: deriveSubjectFromMessage(payload.message),
105
+ message: payload.message,
106
+ name: payload.name,
107
+ email,
108
+ locale: payload.locale,
109
+ ...presentOptionalFields(payload),
110
+ ...(opts.appVersion !== undefined && { appVersion: opts.appVersion }),
111
+ ...(browser !== null && { browser }),
112
+ submittedAt: ctx.tz.now(),
113
+ fileCount: 0,
114
+ replyCount: 0,
115
+ }, platformActor(), contactDb(ctx));
116
+ if (!created.isSuccess)
117
+ return created;
118
+ await sendBestEffort(ctx, "forward request", async () => {
119
+ const forwarded = await ctx.dispatch.writeAs(platformActor(), ContactHandlers.forwardRequest, { requestId });
120
+ if (!forwarded.isSuccess)
121
+ throw new Error(forwarded.error.message);
122
+ });
123
+ await sendBestEffort(ctx, "confirmation mail", (notify) => notify(CONTACT_NOTIFICATION_TYPES.acknowledgement, {
124
+ route: { email },
125
+ recipientId: requestId,
126
+ data: contactAcknowledgementVariables({
127
+ appName: opts.appName,
128
+ locale: payload.locale,
129
+ }),
130
+ idempotencyKey: contactIdempotencyKeys.confirmation(requestId),
131
+ priority: "normal",
132
+ locale: resolveContactMailLocale(payload.locale),
133
+ }));
134
+ return SUBMITTED;
135
+ },
136
+ });
137
+ }
@@ -0,0 +1,9 @@
1
+ import { type HandlerContext, type SessionUser } from "@cosmicdrift/kumiko-framework/engine";
2
+ import type { WriteResult } from "@cosmicdrift/kumiko-types/handlers";
3
+ export declare function takeOverUploads(ctx: HandlerContext, args: {
4
+ readonly user: SessionUser;
5
+ readonly screen: string;
6
+ readonly entityType: string;
7
+ readonly entityId: string;
8
+ readonly fileIds: readonly string[];
9
+ }): Promise<WriteResult<readonly string[]>>;
@@ -0,0 +1,33 @@
1
+ import { SYSTEM_TENANT_ID, } from "@cosmicdrift/kumiko-framework/engine";
2
+ import { copyPendingFileRefsToTenant } from "@cosmicdrift/kumiko-framework/files";
3
+ import { fileContextForTenant } from "../../file-foundation/index.js";
4
+ import { contactDb, platformActor } from "../lib.js";
5
+ import { CONTACT_UPLOAD_FIELD } from "../web/constants.js";
6
+ // The form uploads into the submitter's tenant; the request or reply lives in the system tenant.
7
+ export async function takeOverUploads(ctx, args) {
8
+ if (args.fileIds.length === 0)
9
+ return { isSuccess: true, data: [] };
10
+ const db = contactDb(ctx);
11
+ const submitterTenantId = args.user.tenantId;
12
+ return copyPendingFileRefsToTenant({
13
+ source: {
14
+ db,
15
+ user: args.user,
16
+ files: fileContextForTenant(ctx, submitterTenantId, submitterTenantId),
17
+ entityType: args.screen,
18
+ fieldName: CONTACT_UPLOAD_FIELD,
19
+ },
20
+ target: {
21
+ db,
22
+ user: platformActor(),
23
+ registry: ctx.registry,
24
+ files: fileContextForTenant(ctx, submitterTenantId, SYSTEM_TENANT_ID),
25
+ attachTo: {
26
+ entityType: args.entityType,
27
+ fieldName: CONTACT_UPLOAD_FIELD,
28
+ entityId: args.entityId,
29
+ },
30
+ },
31
+ fileIds: args.fileIds,
32
+ });
33
+ }
@@ -0,0 +1,6 @@
1
+ type LocalizedString = {
2
+ readonly en: string;
3
+ readonly de: string;
4
+ };
5
+ export declare function createContactI18n(): Readonly<Record<string, LocalizedString>>;
6
+ export {};
@@ -0,0 +1,186 @@
1
+ const DELIVERY_FIELD = "contact:entity:contact-delivery:field";
2
+ const REQUEST_FIELD = "contact:entity:contact-request:field";
3
+ const REPLY_ENTITY_FIELD = "contact:entity:contact-reply:field";
4
+ // Option labels of an actionForm select resolve against the renderer's pseudo-entity, not a real one.
5
+ const FORM_FIELD = "contact:entity:__action-form__:field";
6
+ export function createContactI18n() {
7
+ return {
8
+ "contact:feature.label": { en: "Contact", de: "Kontakt" },
9
+ "contact:notify.new-request.label": { en: "New contact request", de: "Neue Meldung" },
10
+ "contact:notify.confirmation.label": {
11
+ en: "Contact confirmation",
12
+ de: "Bestätigung der Meldung",
13
+ },
14
+ "contact:notify.acknowledgement.label": {
15
+ en: "Contact acknowledgement",
16
+ de: "Eingangsbestätigung der Meldung",
17
+ },
18
+ "contact:notify.reply.label": {
19
+ en: "Reply to a contact request",
20
+ de: "Antwort auf eine Meldung",
21
+ },
22
+ "contact:notify.reply-in-app.label": {
23
+ en: "Reply note in the app",
24
+ de: "Hinweis auf eine Antwort in der App",
25
+ },
26
+ "contact:notify.test.label": { en: "Contact test message", de: "Testnachricht Kontakt" },
27
+ "contact:report.submit": { en: "Send report", de: "Meldung senden" },
28
+ "contact:reply.submit": { en: "Send reply", de: "Antwort senden" },
29
+ "contact:overview.open": { en: "Open requests", de: "Offene Meldungen" },
30
+ "contact:filter.open": { en: "Open", de: "Offen" },
31
+ "contact:config.reply-to.label": { en: "Reply-To address", de: "Antwortadresse" },
32
+ "contact:config.telegram-chat.label": { en: "Chat id or @channel", de: "Chat-ID oder @Kanal" },
33
+ "contact:entity:contact-request:field:kind": { en: "Kind", de: "Art" },
34
+ "contact:entity:contact-request:field:status": { en: "Status", de: "Status" },
35
+ "contact:entity:contact-request:field:source": { en: "Source", de: "Quelle" },
36
+ "contact:entity:contact-request:field:subject": { en: "Subject", de: "Betreff" },
37
+ "contact:entity:contact-request:field:message": { en: "Message", de: "Nachricht" },
38
+ "contact:entity:contact-request:field:name": { en: "Name", de: "Name" },
39
+ "contact:entity:contact-request:field:email": { en: "Email", de: "E-Mail" },
40
+ "contact:entity:contact-request:field:phone": { en: "Phone", de: "Telefon" },
41
+ "contact:entity:contact-request:field:submittedAt": { en: "Received", de: "Eingang" },
42
+ "contact:entity:contact-request:field:answeredAt": { en: "Answered", de: "Beantwortet" },
43
+ "contact:entity:contact-request:field:closedAt": { en: "Closed", de: "Abgeschlossen" },
44
+ "contact:entity:contact-request:field:replyCount": { en: "Replies", de: "Antworten" },
45
+ "contact:report.hint": { en: "Goes straight to our team", de: "Geht direkt an unser Team" },
46
+ "contact:config.send-test.description": {
47
+ en: "Now sends a test message to the chat.",
48
+ de: "Schickt jetzt eine Testnachricht an den Chat.",
49
+ },
50
+ "screen:report.title": { en: "Report a problem", de: "Problem melden" },
51
+ "screen:request-list.title": { en: "Requests", de: "Meldungen" },
52
+ "screen:request-detail.title": { en: "Request", de: "Meldung" },
53
+ "screen:reply.title": { en: "Reply", de: "Antworten" },
54
+ "screen:reply-mail.title": { en: "Reply", de: "Antworten" },
55
+ "screen:forwarding.title": { en: "Forwarding of requests", de: "Weiterleitung von Meldungen" },
56
+ "contact:report.summary": {
57
+ en: "The answer comes by email to your account address, usually the same working day.",
58
+ de: "Die Antwort kommt per Mail an die Adresse deines Kontos, meist am selben Werktag.",
59
+ },
60
+ "contact:report.section": { en: "Your report", de: "Deine Meldung" },
61
+ "contact:report.section.description": {
62
+ en: "We attach account, tenant, app version and browser automatically.",
63
+ de: "Konto, Mandant, App-Version und Browser hängen wir automatisch an.",
64
+ },
65
+ "contact:report.success": {
66
+ en: "Thanks, your report has arrived. The answer comes by email.",
67
+ de: "Danke, deine Meldung ist angekommen. Die Antwort kommt per Mail.",
68
+ },
69
+ "contact:report.field.kind": { en: "Kind", de: "Art" },
70
+ "contact:report.field.phone": { en: "Phone", de: "Telefon" },
71
+ "contact:report.field.subject": { en: "Subject", de: "Betreff" },
72
+ "contact:report.field.message": { en: "What happened?", de: "Was ist passiert?" },
73
+ "contact:report.field.files": { en: "Files", de: "Dateien" },
74
+ [`${FORM_FIELD}:name`]: { en: "Reporter", de: "Absender" },
75
+ [`${FORM_FIELD}:email`]: { en: "Email", de: "E-Mail" },
76
+ [`${FORM_FIELD}:replyTo`]: { en: "Replies go to", de: "Rückantworten an" },
77
+ [`${FORM_FIELD}:requestId`]: { en: "Request", de: "Meldung" },
78
+ [`${FORM_FIELD}:kind:option:question`]: { en: "Question", de: "Frage" },
79
+ [`${FORM_FIELD}:kind:option:bug`]: { en: "Bug", de: "Fehler" },
80
+ [`${FORM_FIELD}:kind:option:wish`]: { en: "Wish", de: "Wunsch" },
81
+ "contact:reply.title": { en: "To {name}", de: "An {name}" },
82
+ "contact:reply.summary.in-app": {
83
+ en: "By email to {email} and in the app. Replies go to {replyTo}.",
84
+ de: "Per E-Mail an {email} und in der App. Rückantworten gehen an {replyTo}.",
85
+ },
86
+ "contact:reply.summary.mail": {
87
+ en: "By email to {email}. Replies go to {replyTo}.",
88
+ de: "Per E-Mail an {email}. Rückantworten gehen an {replyTo}.",
89
+ },
90
+ "contact:reply.section": { en: "Reply", de: "Antwort" },
91
+ "contact:reply.section.description": {
92
+ en: "The request is quoted below in the mail.",
93
+ de: "Die Meldung wird unten in der Mail zitiert.",
94
+ },
95
+ "contact:reply.field.message": { en: "Message", de: "Nachricht" },
96
+ "contact:reply.field.files": { en: "Files", de: "Dateien" },
97
+ "contact:reply.field.mark-done": {
98
+ en: "Mark the request as done afterwards",
99
+ de: "Meldung danach als erledigt markieren",
100
+ },
101
+ "contact:filter.all": { en: "All", de: "Alle" },
102
+ "contact:list.from": { en: "From", de: "Von" },
103
+ "contact:action.open": { en: "Open", de: "Öffnen" },
104
+ "contact:action.mark-done": { en: "Mark as done", de: "Als erledigt markieren" },
105
+ "contact:action.reply": { en: "Reply", de: "Antworten" },
106
+ "contact:detail.attachments": { en: "Attachments", de: "Anhänge" },
107
+ "contact:detail.section.message": { en: "Request", de: "Anliegen" },
108
+ "contact:detail.section.replies": { en: "Replies", de: "Antworten" },
109
+ "contact:detail.section.files": { en: "Files", de: "Dateien" },
110
+ "contact:detail.section.sender": { en: "Sender", de: "Absender" },
111
+ "contact:detail.section.origin": { en: "Origin", de: "Herkunft" },
112
+ "contact:detail.section.delivery": { en: "Delivery", de: "Zustellung" },
113
+ "contact:detail.delivery-log": { en: "Delivery log", de: "Zustellprotokoll" },
114
+ "contact:detail.section.notes": { en: "Notes", de: "Notizen" },
115
+ [`${REQUEST_FIELD}:reporterTenantName`]: { en: "Tenant", de: "Mandant" },
116
+ [`${REQUEST_FIELD}:reporterTenantPlan`]: { en: "Tenant plan", de: "Plan des Mandanten" },
117
+ [`${REQUEST_FIELD}:fileCount`]: { en: "Files", de: "Dateien" },
118
+ [`${REQUEST_FIELD}:origin`]: { en: "Source", de: "Quelle" },
119
+ [`${REQUEST_FIELD}:page`]: { en: "Page", de: "Seite" },
120
+ [`${REQUEST_FIELD}:versionLabel`]: { en: "Version", de: "Version" },
121
+ [`${REQUEST_FIELD}:browser`]: { en: "Browser", de: "Browser" },
122
+ [`${REQUEST_FIELD}:kind:option:question`]: { en: "Question", de: "Frage" },
123
+ [`${REQUEST_FIELD}:kind:option:contact`]: { en: "Contact", de: "Kontakt" },
124
+ [`${REQUEST_FIELD}:kind:option:bug`]: { en: "Bug", de: "Fehler" },
125
+ [`${REQUEST_FIELD}:kind:option:wish`]: { en: "Wish", de: "Wunsch" },
126
+ [`${REQUEST_FIELD}:source:option:website`]: { en: "Website", de: "Website" },
127
+ [`${REQUEST_FIELD}:source:option:admin`]: { en: "Admin", de: "Admin" },
128
+ [`${REQUEST_FIELD}:status:option:open`]: { en: "Open", de: "Offen" },
129
+ [`${REQUEST_FIELD}:status:option:answered`]: { en: "Answered", de: "Beantwortet" },
130
+ [`${REQUEST_FIELD}:status:option:done`]: { en: "Done", de: "Erledigt" },
131
+ [`${REPLY_ENTITY_FIELD}:sentAt`]: { en: "Sent", de: "Gesendet" },
132
+ [`${REPLY_ENTITY_FIELD}:authorName`]: { en: "From", de: "Von" },
133
+ [`${REPLY_ENTITY_FIELD}:message`]: { en: "Message", de: "Nachricht" },
134
+ "contact:forwarding.email": { en: "Email", de: "E-Mail" },
135
+ "contact:forwarding.email.description": {
136
+ en: "Every new request goes by email to all SystemAdmins of this app. Turning it off per person goes through delivery; there is no screen for that yet.",
137
+ de: "Jede neue Meldung geht per Mail an alle SystemAdmins dieser App. Abschalten pro Person geht über die Zustellung, eine Maske dafür gibt es noch nicht.",
138
+ },
139
+ "contact:forwarding.telegram": { en: "Telegram", de: "Telegram" },
140
+ "contact:forwarding.telegram.description": {
141
+ en: "Optional. Requests also go as a message to a Telegram chat or channel.",
142
+ de: "Optional. Meldungen gehen zusätzlich als Nachricht in einen Telegram-Chat oder Kanal.",
143
+ },
144
+ "contact:forwarding.submit": { en: "Save", de: "Speichern" },
145
+ "contact:config.reply-to.description": {
146
+ en: "Used as Reply-To in every answer. Empty means the address of the SystemAdmin who replies.",
147
+ de: "Steht als Reply-To in jeder Antwort. Leer heißt: Adresse des SystemAdmins, der antwortet.",
148
+ },
149
+ "contact:config.telegram-chat.description": {
150
+ en: "Leave empty to not use Telegram.",
151
+ de: "Leer lassen, um Telegram nicht zu nutzen.",
152
+ },
153
+ "contact:config.bot-token.label": { en: "Bot token", de: "Bot-Token" },
154
+ "contact:config.bot-token.description": {
155
+ en: "From @BotFather. Stored encrypted and never shown again.",
156
+ de: "Von @BotFather. Wird verschlüsselt gespeichert und nie wieder angezeigt.",
157
+ },
158
+ "contact:config.send-test.label": { en: "Test message", de: "Testnachricht" },
159
+ "contact:config.send-test.button": { en: "Send test message", de: "Testnachricht senden" },
160
+ "contact:config.send-test.success": { en: "Test message sent.", de: "Testnachricht gesendet." },
161
+ [`${REQUEST_FIELD}:origin:option:website`]: { en: "Website", de: "Website" },
162
+ [`${REQUEST_FIELD}:origin:option:admin-report`]: {
163
+ en: "Admin, report a problem",
164
+ de: "Admin, Problem melden",
165
+ },
166
+ [`${DELIVERY_FIELD}:channel`]: { en: "Channel", de: "Kanal" },
167
+ [`${DELIVERY_FIELD}:recipient`]: { en: "Recipient", de: "Empfänger" },
168
+ [`${DELIVERY_FIELD}:at`]: { en: "Time", de: "Zeit" },
169
+ [`${DELIVERY_FIELD}:status`]: { en: "Status", de: "Status" },
170
+ [`${DELIVERY_FIELD}:channel:option:email`]: { en: "Email", de: "E-Mail" },
171
+ [`${DELIVERY_FIELD}:channel:option:telegram`]: { en: "Telegram", de: "Telegram" },
172
+ [`${DELIVERY_FIELD}:channel:option:reply-email`]: {
173
+ en: "Reply, email",
174
+ de: "Antwort, E-Mail",
175
+ },
176
+ [`${DELIVERY_FIELD}:channel:option:reply-in-app`]: {
177
+ en: "Reply, in the app",
178
+ de: "Antwort, in der App",
179
+ },
180
+ [`${DELIVERY_FIELD}:status:option:pending`]: { en: "Pending", de: "Ausstehend" },
181
+ [`${DELIVERY_FIELD}:status:option:delivered`]: { en: "Delivered", de: "Zugestellt" },
182
+ [`${DELIVERY_FIELD}:status:option:failed`]: { en: "Failed", de: "Fehlgeschlagen" },
183
+ [`${DELIVERY_FIELD}:status:option:skipped`]: { en: "Skipped", de: "Übersprungen" },
184
+ [`${DELIVERY_FIELD}:status:option:read`]: { en: "Read", de: "Gelesen" },
185
+ };
186
+ }
@@ -0,0 +1,5 @@
1
+ export { contactReplyEntity, contactReplyTable, contactRequestEntity, contactRequestTable, } from "./entity.ts";
2
+ export { createContactFeature } from "./feature.ts";
3
+ export type { ContactOptions } from "./options.ts";
4
+ export { contactOpenRequestsPanels } from "./panels.ts";
5
+ export { CONTACT_ADMIN_KINDS, CONTACT_CLIENT_PATH, CONTACT_DELIVERY_CHANNEL, CONTACT_DELIVERY_STATUS, CONTACT_FEATURE, CONTACT_FIELD_LIMITS, CONTACT_KIND, CONTACT_NOTIFICATION_TYPES, CONTACT_ORIGIN, CONTACT_REPLY_CHANNELS, CONTACT_SOURCE, CONTACT_STATUS, CONTACT_WEBSITE_KINDS, ContactConfigKeys, ContactErrors, ContactHandlers, ContactQueries, ContactScreens, } from "./web/constants.ts";
@@ -0,0 +1,4 @@
1
+ export { contactReplyEntity, contactReplyTable, contactRequestEntity, contactRequestTable, } from "./entity.js";
2
+ export { createContactFeature } from "./feature.js";
3
+ export { contactOpenRequestsPanels } from "./panels.js";
4
+ export { CONTACT_ADMIN_KINDS, CONTACT_CLIENT_PATH, CONTACT_DELIVERY_CHANNEL, CONTACT_DELIVERY_STATUS, CONTACT_FEATURE, CONTACT_FIELD_LIMITS, CONTACT_KIND, CONTACT_NOTIFICATION_TYPES, CONTACT_ORIGIN, CONTACT_REPLY_CHANNELS, CONTACT_SOURCE, CONTACT_STATUS, CONTACT_WEBSITE_KINDS, ContactConfigKeys, ContactErrors, ContactHandlers, ContactQueries, ContactScreens, } from "./web/constants.js";
@@ -0,0 +1,101 @@
1
+ import { type TenantDb } from "@cosmicdrift/kumiko-framework/db";
2
+ import { type AppContext, type HandlerContext, type SessionUser } from "@cosmicdrift/kumiko-framework/engine";
3
+ import { ContactErrors, type ContactPhoneMode, type ContactReplyChannels } from "./web/constants.ts";
4
+ export declare const IN_APP_FEATURE = "channel-in-app";
5
+ export declare const TELEGRAM_FEATURE = "channel-telegram";
6
+ export declare const CONTACT_CROSS_TENANT_REASON = "contact is platform-wide (systemScope)";
7
+ export declare const SYSTEM_ADMIN_ROLE = "SystemAdmin";
8
+ export declare const adminAccess: {
9
+ readonly roles: readonly string[];
10
+ };
11
+ export declare const internalAccess: {
12
+ readonly roles: readonly string[];
13
+ };
14
+ export declare const requestExecutor: import("@cosmicdrift/kumiko-types/event-store-executor-types").EventStoreExecutor<{
15
+ readonly id: string;
16
+ readonly tenantId: string;
17
+ readonly version: number;
18
+ readonly insertedAt: Temporal.Instant;
19
+ readonly modifiedAt: Temporal.Instant | null;
20
+ readonly insertedById: string | null;
21
+ readonly modifiedById: string | null;
22
+ readonly isDeleted?: boolean | undefined;
23
+ readonly deletedAt?: Temporal.Instant | null | undefined;
24
+ readonly deletedById?: string | null | undefined;
25
+ readonly answeredAt: Temporal.Instant | null;
26
+ readonly appVersion: string | null;
27
+ readonly browser: string | null;
28
+ readonly closedAt: Temporal.Instant | null;
29
+ readonly email: string;
30
+ readonly fileCount: number | null;
31
+ readonly fileIds: readonly string[];
32
+ readonly kind: string;
33
+ readonly locale: string | null;
34
+ readonly message: string;
35
+ readonly name: string;
36
+ readonly page: string | null;
37
+ readonly phone: string | null;
38
+ readonly replyCount: number | null;
39
+ readonly reporterTenantId: string | null;
40
+ readonly reporterTenantName: string | null;
41
+ readonly reporterTenantPlan: string | null;
42
+ readonly reporterUserId: string | null;
43
+ readonly source: string;
44
+ readonly status: string;
45
+ readonly subject: string;
46
+ readonly submittedAt: Temporal.Instant;
47
+ }>;
48
+ export declare const replyExecutor: import("@cosmicdrift/kumiko-types/event-store-executor-types").EventStoreExecutor<{
49
+ readonly id: string;
50
+ readonly tenantId: string;
51
+ readonly version: number;
52
+ readonly insertedAt: Temporal.Instant;
53
+ readonly modifiedAt: Temporal.Instant | null;
54
+ readonly insertedById: string | null;
55
+ readonly modifiedById: string | null;
56
+ readonly isDeleted?: boolean | undefined;
57
+ readonly deletedAt?: Temporal.Instant | null | undefined;
58
+ readonly deletedById?: string | null | undefined;
59
+ readonly authorName: string;
60
+ readonly authorUserId: string;
61
+ readonly channels: string;
62
+ readonly fileIds: readonly string[];
63
+ readonly message: string;
64
+ readonly reporterUserId: string | null;
65
+ readonly requestId: string;
66
+ readonly sentAt: Temporal.Instant;
67
+ }>;
68
+ export declare function listRepliesOf(db: TenantDb, requestId: string): Promise<{
69
+ readonly id: string;
70
+ readonly tenantId: string;
71
+ readonly version: number;
72
+ readonly insertedAt: Temporal.Instant;
73
+ readonly modifiedAt: Temporal.Instant | null;
74
+ readonly insertedById: string | null;
75
+ readonly modifiedById: string | null;
76
+ readonly isDeleted?: boolean | undefined;
77
+ readonly deletedAt?: Temporal.Instant | null | undefined;
78
+ readonly deletedById?: string | null | undefined;
79
+ readonly authorName: string;
80
+ readonly authorUserId: string;
81
+ readonly channels: string;
82
+ readonly fileIds: readonly string[];
83
+ readonly message: string;
84
+ readonly reporterUserId: string | null;
85
+ readonly requestId: string;
86
+ readonly sentAt: Temporal.Instant;
87
+ }[]>;
88
+ export declare function normalizeEmail(email: string): string;
89
+ export declare function contactDb(ctx: Pick<AppContext, "systemDb">): TenantDb;
90
+ export declare function platformActor(): SessionUser;
91
+ export declare function listSystemAdminIds(db: TenantDb): Promise<readonly string[]>;
92
+ export type UserLabel = {
93
+ readonly name: string;
94
+ readonly email: string | null;
95
+ };
96
+ export declare function loadUserLabel(db: TenantDb, userId: string): Promise<UserLabel | null>;
97
+ export declare function sendBestEffort(ctx: Pick<HandlerContext, "notify" | "obs">, label: string, send: (notify: NonNullable<HandlerContext["notify"]>) => Promise<unknown>): Promise<void>;
98
+ export declare function pickReplyChannels(ctx: Pick<HandlerContext, "hasFeature">, reporterUserId: string | null | undefined): Promise<ContactReplyChannels>;
99
+ export declare function phoneProblem(mode: ContactPhoneMode, phone: string | undefined): (typeof ContactErrors)[keyof typeof ContactErrors] | null;
100
+ export declare function loadTenantName(db: TenantDb, tenantId: string): Promise<string | null>;
101
+ export declare function loadTenantPlan(ctx: Pick<HandlerContext, "dispatch" | "registry" | "obs">, tenantId: string): Promise<string | null>;
@@ -0,0 +1,109 @@
1
+ import { createEventStoreExecutor, fetchOne, selectMany, } from "@cosmicdrift/kumiko-framework/db";
2
+ import { access, createSystemUser, SYSTEM_TENANT_ID, } from "@cosmicdrift/kumiko-framework/engine";
3
+ import { InternalError } from "@cosmicdrift/kumiko-framework/errors";
4
+ import { propertyOf } from "@cosmicdrift/kumiko-types/type-guards";
5
+ import { decryptStoredPii } from "../shared/index.js";
6
+ import { tenantTable } from "../tenant/index.js";
7
+ import { TierEngineQueries } from "../tier-engine/index.js";
8
+ import { USER_STATUS, userTable } from "../user/index.js";
9
+ import { contactReplyEntity, contactReplyTable, contactRequestEntity, contactRequestTable, } from "./entity.js";
10
+ import { CONTACT_REPLY_CHANNELS, CONTACT_REPLY_ENTITY, CONTACT_REQUEST_ENTITY, ContactErrors, } from "./web/constants.js";
11
+ export const IN_APP_FEATURE = "channel-in-app";
12
+ export const TELEGRAM_FEATURE = "channel-telegram";
13
+ export const CONTACT_CROSS_TENANT_REASON = "contact is platform-wide (systemScope)";
14
+ export const SYSTEM_ADMIN_ROLE = "SystemAdmin";
15
+ const PII_DECRYPT_REASON = "contact:user-lookup";
16
+ export const adminAccess = { roles: access.systemAdmin };
17
+ export const internalAccess = { roles: access.system };
18
+ export const requestExecutor = createEventStoreExecutor(contactRequestTable, contactRequestEntity, {
19
+ entityName: CONTACT_REQUEST_ENTITY,
20
+ });
21
+ export const replyExecutor = createEventStoreExecutor(contactReplyTable, contactReplyEntity, {
22
+ entityName: CONTACT_REPLY_ENTITY,
23
+ });
24
+ const MAX_REPLIES_PER_REQUEST = 200;
25
+ export async function listRepliesOf(db, requestId) {
26
+ const found = await replyExecutor.list({
27
+ filter: { field: "requestId", op: "eq", value: requestId },
28
+ sort: "sentAt",
29
+ sortDirection: "asc",
30
+ limit: MAX_REPLIES_PER_REQUEST,
31
+ }, platformActor(), db);
32
+ return found.rows;
33
+ }
34
+ export function normalizeEmail(email) {
35
+ return email.toLowerCase();
36
+ }
37
+ export function contactDb(ctx) {
38
+ if (!ctx.systemDb) {
39
+ throw new InternalError({
40
+ message: "contact requires ctx.systemDb — is r.systemScope() set on the feature?",
41
+ });
42
+ }
43
+ return ctx.systemDb.acknowledgeCrossTenant(CONTACT_CROSS_TENANT_REASON);
44
+ }
45
+ // Requests and replies are systemStream rows, so every write targets the system tenant's stream.
46
+ export function platformActor() {
47
+ return createSystemUser(SYSTEM_TENANT_ID);
48
+ }
49
+ export async function listSystemAdminIds(db) {
50
+ const rows = await selectMany(db, userTable, { isDeleted: false, status: USER_STATUS.Active, roles: SYSTEM_ADMIN_ROLE }, { fields: ["id"], orderBy: { col: "id" } });
51
+ return rows.map((r) => r.id);
52
+ }
53
+ export async function loadUserLabel(db, userId) {
54
+ const row = await fetchOne(db, userTable, { id: userId, isDeleted: false });
55
+ if (!row)
56
+ return null;
57
+ const email = await decryptStoredPii(row.email, "email", PII_DECRYPT_REASON);
58
+ const name = await decryptStoredPii(row.displayName, "displayName", PII_DECRYPT_REASON);
59
+ return { name, email };
60
+ }
61
+ export async function sendBestEffort(ctx, label, send) {
62
+ try {
63
+ if (!ctx.notify) {
64
+ throw new InternalError({ message: "ctx.notify unavailable — mount the delivery feature" });
65
+ }
66
+ await send(ctx.notify);
67
+ }
68
+ catch (err) {
69
+ ctx.obs.log?.warn(`[contact] ${label} failed`, {
70
+ error: err instanceof Error ? err.message : String(err),
71
+ });
72
+ }
73
+ }
74
+ export async function pickReplyChannels(ctx, reporterUserId) {
75
+ const hasInApp = reporterUserId && (await ctx.hasFeature(IN_APP_FEATURE));
76
+ return hasInApp ? CONTACT_REPLY_CHANNELS.EmailAndInApp : CONTACT_REPLY_CHANNELS.Email;
77
+ }
78
+ export function phoneProblem(mode, phone) {
79
+ const present = phone !== undefined && phone !== "";
80
+ if (mode === "off")
81
+ return present ? ContactErrors.phoneNotAllowed : null;
82
+ if (mode === "required")
83
+ return present ? null : ContactErrors.phoneRequired;
84
+ return null;
85
+ }
86
+ export async function loadTenantName(db, tenantId) {
87
+ const row = await fetchOne(db, tenantTable, { id: tenantId });
88
+ return row ? decryptStoredPii(row.name, "name", PII_DECRYPT_REASON) : null;
89
+ }
90
+ // The tier engine only knows tier ids, so the operators' label is the id with a capital.
91
+ function planDisplayName(tier) {
92
+ return tier.charAt(0).toUpperCase() + tier.slice(1);
93
+ }
94
+ // The plan is context for the operators, so a missing tier-engine or a failed lookup leaves it empty.
95
+ export async function loadTenantPlan(ctx, tenantId) {
96
+ if (ctx.registry.getQueryHandler(TierEngineQueries.getTenantTier) === undefined)
97
+ return null;
98
+ try {
99
+ const assignment = await ctx.dispatch.queryAs(createSystemUser(SYSTEM_TENANT_ID, [SYSTEM_ADMIN_ROLE]), TierEngineQueries.getTenantTier, { tenantId });
100
+ const tier = propertyOf(assignment, "tier");
101
+ return typeof tier === "string" && tier !== "" ? planDisplayName(tier) : null;
102
+ }
103
+ catch (err) {
104
+ ctx.obs.log?.warn("[contact] tenant plan lookup failed", {
105
+ error: err instanceof Error ? err.message : String(err),
106
+ });
107
+ return null;
108
+ }
109
+ }