@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,17 @@
1
+ import type { TenantDb } from "@cosmicdrift/kumiko-framework/db";
2
+ import { platformActor, requestExecutor } from "../lib.ts";
3
+ import { CONTACT_STATUS } from "../web/constants.ts";
4
+
5
+ // Open means no answer yet; an answered request counts as handled even before it is marked done.
6
+ export async function countOpenRequests(db: TenantDb): Promise<number> {
7
+ const found = await requestExecutor.list(
8
+ {
9
+ filter: { field: "status", op: "eq", value: CONTACT_STATUS.Open },
10
+ limit: 1,
11
+ totalCount: true,
12
+ },
13
+ platformActor(),
14
+ db,
15
+ );
16
+ return found.total ?? 0;
17
+ }
@@ -0,0 +1,29 @@
1
+ import { defineQueryHandler } from "@cosmicdrift/kumiko-framework/engine";
2
+ import { NotFoundError } from "@cosmicdrift/kumiko-framework/errors";
3
+ import { adminAccess, contactDb, listRepliesOf, platformActor, requestExecutor } from "../lib.ts";
4
+ import { ContactIdSchema } from "../payloads.ts";
5
+ import { CONTACT_REQUEST_ENTITY } from "../web/constants.ts";
6
+
7
+ export const repliesQuery = defineQueryHandler({
8
+ name: "replies",
9
+ schema: ContactIdSchema,
10
+ access: adminAccess,
11
+ description:
12
+ "Returns the answers SystemAdmins sent to one contact request (id, sent time, author name, message), oldest first, as flat rows for a related list; the request itself is not part of it.",
13
+ handler: async (event, ctx) => {
14
+ const db = contactDb(ctx);
15
+ const { id } = event.payload;
16
+ const request = await requestExecutor.detail({ id }, platformActor(), db);
17
+ if (!request) throw new NotFoundError(CONTACT_REQUEST_ENTITY, id);
18
+ const replies = await listRepliesOf(db, id);
19
+ return {
20
+ rows: replies.map((reply) => ({
21
+ id: reply.id,
22
+ sentAt: reply.sentAt.toString(),
23
+ authorName: reply.authorName,
24
+ message: reply.message,
25
+ })),
26
+ nextCursor: null,
27
+ };
28
+ },
29
+ });
@@ -0,0 +1,197 @@
1
+ import {
2
+ createSystemUser,
3
+ defineWriteHandler,
4
+ type HandlerContext,
5
+ } from "@cosmicdrift/kumiko-framework/engine";
6
+ import {
7
+ NotFoundError,
8
+ UnprocessableError,
9
+ writeFailure,
10
+ } from "@cosmicdrift/kumiko-framework/errors";
11
+ import { generateId } from "@cosmicdrift/kumiko-framework/utils";
12
+ import { parseTenantId } from "@cosmicdrift/kumiko-types/identifiers";
13
+ import {
14
+ adminAccess,
15
+ contactDb,
16
+ loadUserLabel,
17
+ pickReplyChannels,
18
+ platformActor,
19
+ replyExecutor,
20
+ requestExecutor,
21
+ sendBestEffort,
22
+ } from "../lib.ts";
23
+ import { ContactReplySchema } from "../payloads.ts";
24
+ import {
25
+ CONTACT_REPLY_CHANNELS,
26
+ CONTACT_REPLY_ENTITY,
27
+ CONTACT_REQUEST_ENTITY,
28
+ CONTACT_STATUS,
29
+ ContactErrors,
30
+ ContactHandlers,
31
+ type ContactReplyChannels,
32
+ ContactScreens,
33
+ } from "../web/constants.ts";
34
+ import { takeOverUploads } from "./take-over-uploads.ts";
35
+
36
+ export type ContactReplyData = {
37
+ readonly kind: "replied";
38
+ readonly id: string;
39
+ readonly status: typeof CONTACT_STATUS.Answered | typeof CONTACT_STATUS.Done;
40
+ };
41
+
42
+ type InAppNoteArgs = {
43
+ readonly replyId: string;
44
+ readonly request: {
45
+ readonly id: string;
46
+ readonly reporterUserId?: string | null | undefined;
47
+ readonly reporterTenantId?: string | null | undefined;
48
+ readonly locale?: string | null | undefined;
49
+ };
50
+ readonly authorName: string;
51
+ };
52
+
53
+ async function noteReporterInApp(ctx: HandlerContext, args: InAppNoteArgs): Promise<void> {
54
+ const { request } = args;
55
+ const tenantId = parseTenantId(request.reporterTenantId);
56
+ // skip: the in-app note needs a signed-in reporter whose tenant id is still valid
57
+ if (!request.reporterUserId || tenantId === null) return;
58
+ await sendBestEffort(ctx, "reply in-app note", async () => {
59
+ const noted = await ctx.dispatch.writeAs(
60
+ createSystemUser(tenantId),
61
+ ContactHandlers.notifyReporterInApp,
62
+ {
63
+ replyId: args.replyId,
64
+ requestId: request.id,
65
+ userId: request.reporterUserId,
66
+ authorName: args.authorName,
67
+ locale: request.locale ?? undefined,
68
+ },
69
+ );
70
+ if (!noted.isSuccess) throw new Error(noted.error.message);
71
+ });
72
+ }
73
+
74
+ type PersistReplyArgs = {
75
+ readonly replyId: string;
76
+ readonly request: {
77
+ readonly id: string;
78
+ readonly version: number;
79
+ readonly replyCount?: number | null | undefined;
80
+ readonly reporterUserId?: string | null | undefined;
81
+ };
82
+ readonly message: string;
83
+ readonly authorUserId: string;
84
+ readonly authorName: string;
85
+ readonly fileIds: readonly string[];
86
+ readonly channels: ContactReplyChannels;
87
+ readonly status: ContactReplyData["status"];
88
+ };
89
+
90
+ // Returns the failing write result, or null when reply and request update both succeeded.
91
+ async function persistReply(
92
+ ctx: HandlerContext,
93
+ db: ReturnType<typeof contactDb>,
94
+ args: PersistReplyArgs,
95
+ ) {
96
+ const { request } = args;
97
+ const sentAt = ctx.tz.now();
98
+ const createdReply = await replyExecutor.create(
99
+ {
100
+ id: args.replyId,
101
+ requestId: request.id,
102
+ ...(request.reporterUserId && { reporterUserId: request.reporterUserId }),
103
+ message: args.message,
104
+ authorUserId: args.authorUserId,
105
+ authorName: args.authorName,
106
+ ...(args.fileIds.length > 0 && { fileIds: args.fileIds }),
107
+ channels: args.channels,
108
+ sentAt,
109
+ },
110
+ platformActor(),
111
+ db,
112
+ );
113
+ if (!createdReply.isSuccess) return createdReply;
114
+ const updated = await requestExecutor.update(
115
+ {
116
+ id: request.id,
117
+ version: request.version,
118
+ changes: {
119
+ status: args.status,
120
+ answeredAt: sentAt,
121
+ ...(args.status === CONTACT_STATUS.Done && { closedAt: sentAt }),
122
+ replyCount: (request.replyCount ?? 0) + 1,
123
+ },
124
+ },
125
+ platformActor(),
126
+ db,
127
+ );
128
+ return updated.isSuccess ? null : updated;
129
+ }
130
+
131
+ // The drawer variant the admin used is chosen by the reply channels, and pending uploads hang under that screen.
132
+ function replyScreenFor(channels: ContactReplyChannels): string {
133
+ return channels === CONTACT_REPLY_CHANNELS.EmailAndInApp
134
+ ? ContactScreens.reply
135
+ : ContactScreens.replyMail;
136
+ }
137
+
138
+ export function createReplyHandler() {
139
+ return defineWriteHandler<"reply", typeof ContactReplySchema, ContactReplyData>({
140
+ name: "reply",
141
+ schema: ContactReplySchema,
142
+ access: adminAccess,
143
+ description:
144
+ "A SystemAdmin answers a contact request: stores the reply (uploaded files are taken over into the system tenant), mails it to the reporter (Reply-To set, optional attachments, quoting the original request) and, for a signed-in reporter, adds an in-app note in the reporter's tenant. Marks the request answered, or done when markDone is set.",
145
+ // The reply mail leaves the platform and cannot be recalled; reporter text may carry prompt injection.
146
+ agent: { expose: false },
147
+ handler: async (event, ctx) => {
148
+ const { requestId, message, markDone } = event.payload;
149
+ const db = contactDb(ctx);
150
+ const request = await requestExecutor.detail({ id: requestId }, platformActor(), db);
151
+ if (!request) return writeFailure(new NotFoundError(CONTACT_REQUEST_ENTITY, requestId));
152
+
153
+ const replyId = generateId();
154
+ const reporterUserId = request.reporterUserId ?? undefined;
155
+ const channels = await pickReplyChannels(ctx, reporterUserId);
156
+ const uploaded = await takeOverUploads(ctx, {
157
+ user: event.user,
158
+ screen: replyScreenFor(channels),
159
+ entityType: CONTACT_REPLY_ENTITY,
160
+ entityId: replyId,
161
+ fileIds: event.payload.fileIds ?? [],
162
+ });
163
+ if (!uploaded.isSuccess) {
164
+ return writeFailure(new UnprocessableError(ContactErrors.attachmentNotFound));
165
+ }
166
+ const fileIds = uploaded.data;
167
+ const author = await loadUserLabel(db, event.user.id);
168
+ const authorName = author?.name ?? event.user.id;
169
+
170
+ const status = markDone ? CONTACT_STATUS.Done : CONTACT_STATUS.Answered;
171
+ const failed = await persistReply(ctx, db, {
172
+ replyId,
173
+ request,
174
+ message,
175
+ authorUserId: event.user.id,
176
+ authorName,
177
+ fileIds,
178
+ channels,
179
+ status,
180
+ });
181
+ if (failed !== null) return failed;
182
+
183
+ await sendBestEffort(ctx, "reply mail", async () => {
184
+ const sent = await ctx.dispatch.writeAs(platformActor(), ContactHandlers.sendReplyMail, {
185
+ replyId,
186
+ });
187
+ if (!sent.isSuccess) throw new Error(sent.error.message);
188
+ });
189
+
190
+ if (channels === CONTACT_REPLY_CHANNELS.EmailAndInApp) {
191
+ await noteReporterInApp(ctx, { replyId, request, authorName });
192
+ }
193
+
194
+ return { isSuccess: true, data: { kind: "replied", id: replyId, status } };
195
+ },
196
+ });
197
+ }
@@ -0,0 +1,126 @@
1
+ import { requestContext } from "@cosmicdrift/kumiko-framework/api";
2
+ import { defineWriteHandler } from "@cosmicdrift/kumiko-framework/engine";
3
+ import { UnprocessableError, writeFailure } from "@cosmicdrift/kumiko-framework/errors";
4
+ import { generateId } from "@cosmicdrift/kumiko-framework/utils";
5
+ import {
6
+ contactDb,
7
+ loadTenantName,
8
+ loadTenantPlan,
9
+ loadUserLabel,
10
+ normalizeEmail,
11
+ phoneProblem,
12
+ platformActor,
13
+ requestExecutor,
14
+ sendBestEffort,
15
+ } from "../lib.ts";
16
+ import { contactConfirmationVariables, resolveContactMailLocale } from "../mail.ts";
17
+ import { type ContactOptions, type ContactSettings, REPORT_RATE_LIMIT } from "../options.ts";
18
+ import { ContactReportSchema } from "../payloads.ts";
19
+ import { summarizeUserAgent } from "../user-agent.ts";
20
+ import {
21
+ CONTACT_NOTIFICATION_TYPES,
22
+ CONTACT_REQUEST_ENTITY,
23
+ CONTACT_SOURCE,
24
+ CONTACT_STATUS,
25
+ CONTACT_UPLOAD_FIELD,
26
+ ContactErrors,
27
+ ContactHandlers,
28
+ ContactScreens,
29
+ contactIdempotencyKeys,
30
+ } from "../web/constants.ts";
31
+ import { REPORT_ACCESS } from "./access.ts";
32
+ import { takeOverUploads } from "./take-over-uploads.ts";
33
+
34
+ export type ContactReportData = { readonly kind: "reported"; readonly id: string };
35
+
36
+ export function createReportHandler(opts: ContactOptions, settings: ContactSettings) {
37
+ return defineWriteHandler<"report", typeof ContactReportSchema, ContactReportData>({
38
+ name: "report",
39
+ schema: ContactReportSchema,
40
+ access: REPORT_ACCESS,
41
+ rateLimit: REPORT_RATE_LIMIT,
42
+ agent: { expose: false },
43
+ description:
44
+ "A signed-in user reports a problem, asks a question or voices a wish to the platform operators; name, email and tenant come from the session, never from the payload. Forwards the request to the SystemAdmins and mails the reporter a copy.",
45
+ handler: async (event, ctx) => {
46
+ const payload = event.payload;
47
+ const phoneIssue = phoneProblem(settings.phone, payload.phone);
48
+ if (phoneIssue !== null) return writeFailure(new UnprocessableError(phoneIssue));
49
+
50
+ const db = contactDb(ctx);
51
+ const reporter = await loadUserLabel(db, event.user.id);
52
+ if (!reporter?.email) {
53
+ return writeFailure(new UnprocessableError(ContactErrors.reporterEmailMissing));
54
+ }
55
+ const tenantName = await loadTenantName(db, event.user.tenantId);
56
+ const email = normalizeEmail(reporter.email);
57
+ const browser = summarizeUserAgent(requestContext.get()?.userAgent, ctx.locale);
58
+
59
+ const tenantPlan = await loadTenantPlan(ctx, event.user.tenantId);
60
+
61
+ const requestId = generateId();
62
+ const uploaded = await takeOverUploads(ctx, {
63
+ user: event.user,
64
+ screen: ContactScreens.report,
65
+ entityType: CONTACT_REQUEST_ENTITY,
66
+ entityId: requestId,
67
+ fileIds: payload.fileIds ?? [],
68
+ });
69
+ if (!uploaded.isSuccess) return uploaded;
70
+ const fileIds = uploaded.data;
71
+ const created = await requestExecutor.create(
72
+ {
73
+ id: requestId,
74
+ kind: payload.kind,
75
+ status: CONTACT_STATUS.Open,
76
+ source: CONTACT_SOURCE.Admin,
77
+ subject: payload.subject,
78
+ message: payload.message,
79
+ name: reporter.name,
80
+ email,
81
+ locale: ctx.locale,
82
+ reporterUserId: event.user.id,
83
+ reporterTenantId: event.user.tenantId,
84
+ ...(tenantName !== null && { reporterTenantName: tenantName }),
85
+ ...(tenantPlan !== null && { reporterTenantPlan: tenantPlan }),
86
+ ...(payload.phone !== undefined && payload.phone !== "" && { phone: payload.phone }),
87
+ ...(opts.appVersion !== undefined && { appVersion: opts.appVersion }),
88
+ ...(browser !== null && { browser }),
89
+ submittedAt: ctx.tz.now(),
90
+ ...(fileIds.length > 0 && { [CONTACT_UPLOAD_FIELD]: fileIds }),
91
+ fileCount: fileIds.length,
92
+ replyCount: 0,
93
+ },
94
+ platformActor(),
95
+ db,
96
+ );
97
+ if (!created.isSuccess) return created;
98
+
99
+ await sendBestEffort(ctx, "forward request", async () => {
100
+ const forwarded = await ctx.dispatch.writeAs(
101
+ platformActor(),
102
+ ContactHandlers.forwardRequest,
103
+ { requestId },
104
+ );
105
+ if (!forwarded.isSuccess) throw new Error(forwarded.error.message);
106
+ });
107
+
108
+ await sendBestEffort(ctx, "confirmation mail", (notify) =>
109
+ notify(CONTACT_NOTIFICATION_TYPES.confirmation, {
110
+ route: { email },
111
+ recipientId: requestId,
112
+ data: contactConfirmationVariables({
113
+ appName: opts.appName,
114
+ message: payload.message,
115
+ locale: ctx.locale,
116
+ }),
117
+ idempotencyKey: contactIdempotencyKeys.confirmation(requestId),
118
+ priority: "normal",
119
+ locale: resolveContactMailLocale(ctx.locale),
120
+ }),
121
+ );
122
+
123
+ return { isSuccess: true, data: { kind: "reported", id: requestId } };
124
+ },
125
+ });
126
+ }
@@ -0,0 +1,143 @@
1
+ import type { TenantDb } from "@cosmicdrift/kumiko-framework/db";
2
+ import { defineQueryHandler } from "@cosmicdrift/kumiko-framework/engine";
3
+ import { NotFoundError } from "@cosmicdrift/kumiko-framework/errors";
4
+ import { parseTenantId } from "@cosmicdrift/kumiko-types/identifiers";
5
+ import type { Temporal } from "@cosmicdrift/kumiko-types/temporal";
6
+ import {
7
+ adminAccess,
8
+ contactDb,
9
+ listRepliesOf,
10
+ loadUserLabel,
11
+ platformActor,
12
+ requestExecutor,
13
+ } from "../lib.ts";
14
+ import type { ContactOptions } from "../options.ts";
15
+ import { ContactIdSchema } from "../payloads.ts";
16
+ import {
17
+ CONTACT_DELIVERY_CHANNEL,
18
+ CONTACT_DELIVERY_STATUS,
19
+ CONTACT_REQUEST_ENTITY,
20
+ ContactConfigKeys,
21
+ type ContactDeliveryChannel,
22
+ type ContactDeliveryStatus,
23
+ contactIdempotencyKeys,
24
+ } from "../web/constants.ts";
25
+ import { type ContactAttempt, loadAttemptsByKey, loadReadAtByKey } from "./attempts.ts";
26
+
27
+ type DeliveryRow = {
28
+ readonly id: string;
29
+ readonly channel: ContactDeliveryChannel;
30
+ readonly recipient: string;
31
+ readonly at: string;
32
+ readonly status: ContactDeliveryStatus;
33
+ };
34
+
35
+ function displayStatus(attemptStatus: string): ContactDeliveryStatus {
36
+ switch (attemptStatus) {
37
+ case "sent":
38
+ return CONTACT_DELIVERY_STATUS.Delivered;
39
+ case "failed":
40
+ return CONTACT_DELIVERY_STATUS.Failed;
41
+ case "skipped":
42
+ return CONTACT_DELIVERY_STATUS.Skipped;
43
+ default:
44
+ return CONTACT_DELIVERY_STATUS.Pending;
45
+ }
46
+ }
47
+
48
+ function attemptsOf(attempts: readonly ContactAttempt[], key: string): readonly ContactAttempt[] {
49
+ return attempts.filter((attempt) => attempt.key === key);
50
+ }
51
+
52
+ function rowOf(
53
+ attempt: ContactAttempt,
54
+ channel: ContactDeliveryChannel,
55
+ recipient: string,
56
+ readAt: Temporal.Instant | null | undefined,
57
+ ): DeliveryRow {
58
+ const read = readAt !== undefined && readAt !== null;
59
+ return {
60
+ id: `${attempt.key}:${attempt.channel}:${attempt.recipientId ?? ""}`,
61
+ channel,
62
+ recipient,
63
+ at: (read ? readAt : attempt.createdAt).toString(),
64
+ status: read ? CONTACT_DELIVERY_STATUS.Read : displayStatus(attempt.status),
65
+ };
66
+ }
67
+
68
+ async function adminRows(
69
+ db: TenantDb,
70
+ attempts: readonly ContactAttempt[],
71
+ requestId: string,
72
+ ): Promise<readonly DeliveryRow[]> {
73
+ const rows: DeliveryRow[] = [];
74
+ for (const attempt of attemptsOf(attempts, contactIdempotencyKeys.admins(requestId))) {
75
+ const admin = attempt.recipientId ? await loadUserLabel(db, attempt.recipientId) : null;
76
+ rows.push(
77
+ rowOf(attempt, CONTACT_DELIVERY_CHANNEL.Email, `${admin?.name ?? "?"} (SystemAdmin)`, null),
78
+ );
79
+ }
80
+ return rows;
81
+ }
82
+
83
+ export function createRequestDeliveryQuery(opts: ContactOptions) {
84
+ return defineQueryHandler({
85
+ name: "request-delivery",
86
+ schema: ContactIdSchema,
87
+ access: adminAccess,
88
+ description:
89
+ "Returns where one contact request went and how: the admin mails, the Telegram message and each answer as mail and in-app note, each with channel, recipient, time and delivery status (an in-app note shows as read with the time it was opened), as flat rows for a related list.",
90
+ handler: async (event, ctx) => {
91
+ const db = contactDb(ctx);
92
+ const { id } = event.payload;
93
+ const request = await requestExecutor.detail({ id }, platformActor(), db);
94
+ if (!request) throw new NotFoundError(CONTACT_REQUEST_ENTITY, id);
95
+ const replies = await listRepliesOf(db, id);
96
+ const replyInAppKeys = replies.map((reply) => contactIdempotencyKeys.replyInApp(reply.id));
97
+ const attempts = await loadAttemptsByKey(ctx, event.user, [
98
+ contactIdempotencyKeys.admins(id),
99
+ contactIdempotencyKeys.telegram(id),
100
+ ...replies.map((reply) => contactIdempotencyKeys.reply(reply.id)),
101
+ ...replyInAppKeys,
102
+ ]);
103
+ const reporterTenantId = parseTenantId(request.reporterTenantId);
104
+ const readAtByKey =
105
+ reporterTenantId === null
106
+ ? new Map<string, Temporal.Instant | null>()
107
+ : await loadReadAtByKey(ctx, reporterTenantId, replyInAppKeys);
108
+
109
+ const rows: DeliveryRow[] = [...(await adminRows(db, attempts, id))];
110
+ if (opts.telegram) {
111
+ const chat = await ctx.config?.(ContactConfigKeys.telegramChat);
112
+ for (const attempt of attemptsOf(attempts, contactIdempotencyKeys.telegram(id))) {
113
+ rows.push(
114
+ rowOf(
115
+ attempt,
116
+ CONTACT_DELIVERY_CHANNEL.Telegram,
117
+ typeof chat === "string" ? chat : "",
118
+ null,
119
+ ),
120
+ );
121
+ }
122
+ }
123
+ for (const reply of replies) {
124
+ const mailKey = contactIdempotencyKeys.reply(reply.id);
125
+ for (const attempt of attemptsOf(attempts, mailKey)) {
126
+ rows.push(rowOf(attempt, CONTACT_DELIVERY_CHANNEL.ReplyEmail, request.name, null));
127
+ }
128
+ const inAppKey = contactIdempotencyKeys.replyInApp(reply.id);
129
+ for (const attempt of attemptsOf(attempts, inAppKey)) {
130
+ rows.push(
131
+ rowOf(
132
+ attempt,
133
+ CONTACT_DELIVERY_CHANNEL.ReplyInApp,
134
+ request.name,
135
+ readAtByKey.get(inAppKey),
136
+ ),
137
+ );
138
+ }
139
+ }
140
+ return { rows, nextCursor: null };
141
+ },
142
+ });
143
+ }
@@ -0,0 +1,50 @@
1
+ import { defineQueryHandler } from "@cosmicdrift/kumiko-framework/engine";
2
+ import { NotFoundError } from "@cosmicdrift/kumiko-framework/errors";
3
+ import {
4
+ adminAccess,
5
+ contactDb,
6
+ loadUserLabel,
7
+ pickReplyChannels,
8
+ platformActor,
9
+ requestExecutor,
10
+ } from "../lib.ts";
11
+ import type { ContactOptions } from "../options.ts";
12
+ import { ContactIdSchema } from "../payloads.ts";
13
+ import {
14
+ CONTACT_ORIGIN,
15
+ CONTACT_REQUEST_ENTITY,
16
+ CONTACT_SOURCE,
17
+ ContactConfigKeys,
18
+ } from "../web/constants.ts";
19
+
20
+ export function createRequestDetailQuery(opts: ContactOptions) {
21
+ return defineQueryHandler({
22
+ name: "request-detail",
23
+ schema: ContactIdSchema,
24
+ access: adminAccess,
25
+ description:
26
+ "Returns one contact request with its origin fields plus what the detail screen shows around it: the Reply-To address a reply goes out with (the caller's own email while none is configured), the channels a reply reaches the reporter on, the app version label and whether the request came from the website or the admin.",
27
+ handler: async (event, ctx) => {
28
+ const db = contactDb(ctx);
29
+ const request = await requestExecutor.detail({ id: event.payload.id }, platformActor(), db);
30
+ if (!request) throw new NotFoundError(CONTACT_REQUEST_ENTITY, event.payload.id);
31
+
32
+ const configuredReplyTo = await ctx.config?.(ContactConfigKeys.replyTo);
33
+ const replyTo =
34
+ typeof configuredReplyTo === "string" && configuredReplyTo !== ""
35
+ ? configuredReplyTo
36
+ : ((await loadUserLabel(db, event.user.id))?.email ?? null);
37
+
38
+ return {
39
+ ...request,
40
+ replyTo,
41
+ replyChannels: await pickReplyChannels(ctx, request.reporterUserId),
42
+ versionLabel: opts.appVersion !== undefined ? `${opts.appName} ${opts.appVersion}` : null,
43
+ origin:
44
+ request.source === CONTACT_SOURCE.Admin
45
+ ? CONTACT_ORIGIN.AdminReport
46
+ : CONTACT_ORIGIN.Website,
47
+ };
48
+ },
49
+ });
50
+ }
@@ -0,0 +1,14 @@
1
+ import {
2
+ defineEntityListHandler,
3
+ type EntityDefinition,
4
+ } from "@cosmicdrift/kumiko-framework/engine";
5
+ import { adminAccess } from "../lib.ts";
6
+ import { CONTACT_REQUEST_ENTITY } from "../web/constants.ts";
7
+
8
+ export function createRequestListQuery(requestEntity: EntityDefinition) {
9
+ return defineEntityListHandler(CONTACT_REQUEST_ENTITY, requestEntity, {
10
+ access: adminAccess,
11
+ description:
12
+ "Lists contact requests for the SystemAdmin inbox: searchable, filterable by status, kind and source, newest first; the open named filter backs the dashboard tile.",
13
+ });
14
+ }