@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
@@ -24,6 +24,7 @@ import {
24
24
  DeliveryQueries,
25
25
  } from "./constants.ts";
26
26
  import { deliveryAttemptAddressErasedSchema, deliveryAttemptSchema } from "./events.ts";
27
+ import { attemptsByKeysQuery } from "./handlers/attempts-by-keys.query.ts";
27
28
  import { logQuery } from "./handlers/log.query.ts";
28
29
  import { preferencesQuery } from "./handlers/preferences.query.ts";
29
30
  import { resubscribeAddressWrite } from "./handlers/resubscribe-address.write.ts";
@@ -153,6 +154,7 @@ export function createDeliveryFeature(options?: DeliveryFeatureOptions): Feature
153
154
  error: p.error,
154
155
  priority: p.priority,
155
156
  confirmed: p.confirmed ?? null,
157
+ idempotencyKey: p.idempotencyKey ?? null,
156
158
  },
157
159
  {
158
160
  status: p.status,
@@ -216,7 +218,6 @@ export function createDeliveryFeature(options?: DeliveryFeatureOptions): Feature
216
218
  },
217
219
  });
218
220
  }
219
-
220
221
  const handlers = {
221
222
  setPreference: r.writeHandler(setPreferenceWrite),
222
223
  unsubscribeAddress: r.writeHandler(unsubscribeAddressWrite),
@@ -224,10 +225,10 @@ export function createDeliveryFeature(options?: DeliveryFeatureOptions): Feature
224
225
  resubscribeAddress: r.writeHandler(resubscribeAddressWrite),
225
226
  resubscribeUser: r.writeHandler(resubscribeUserWrite),
226
227
  };
227
-
228
228
  const queries = {
229
229
  log: r.queryHandler({ ...logQuery, access: { roles: resolvedAccess } }),
230
230
  preferences: r.queryHandler(preferencesQuery),
231
+ attemptsByKeys: r.queryHandler(attemptsByKeysQuery),
231
232
  unsubscribePageChrome: r.queryHandler(unsubscribePageChromeQuery),
232
233
  };
233
234
 
@@ -0,0 +1,55 @@
1
+ import { selectMany } from "@cosmicdrift/kumiko-framework/db";
2
+ import { access, defineQueryHandler } from "@cosmicdrift/kumiko-framework/engine";
3
+ import { InternalError } from "@cosmicdrift/kumiko-framework/errors";
4
+ import type { Temporal } from "@cosmicdrift/kumiko-types/temporal";
5
+ import * as z from "zod";
6
+ import { deliveryAttemptsTable } from "../tables.ts";
7
+ import { toClientError } from "./log.query.ts";
8
+
9
+ const MAX_KEYS = 50;
10
+
11
+ export const attemptsByKeysQuery = defineQueryHandler({
12
+ name: "attempts-by-keys",
13
+ schema: z.object({ keys: z.array(z.string().min(1).max(256)).min(1).max(MAX_KEYS) }).strict(),
14
+ access: { roles: access.systemAdmin },
15
+ description:
16
+ "Returns the delivery attempts (channel, status, error code, time, recipient id, never an address) recorded for notify() calls made with one of the given idempotency keys, across all tenants; use it to show whether a notification a feature sent under a known key arrived.",
17
+ handler: async (query, ctx) => {
18
+ if (!ctx.systemDb) {
19
+ throw new InternalError({ message: "attempts-by-keys requires ctx.systemDb" });
20
+ }
21
+ const db = ctx.systemDb.acknowledgeCrossTenant(
22
+ "SystemAdmin reads delivery attempts of a notification across tenants",
23
+ );
24
+ const rows = await selectMany<{
25
+ id: string;
26
+ idempotencyKey: string | null;
27
+ notificationType: string;
28
+ channel: string;
29
+ recipientId: string | null;
30
+ status: string;
31
+ error: string | null;
32
+ createdAt: Temporal.Instant;
33
+ }>(
34
+ db,
35
+ deliveryAttemptsTable,
36
+ { idempotencyKey: { in: query.payload.keys } },
37
+ { orderBy: [{ col: "createdAt", direction: "asc" }] },
38
+ );
39
+ return {
40
+ rows: rows
41
+ // "*" rows only record that a duplicate key was skipped.
42
+ .filter((row) => row.channel !== "*")
43
+ .map((row) => ({
44
+ id: row.id,
45
+ key: row.idempotencyKey,
46
+ notificationType: row.notificationType,
47
+ channel: row.channel,
48
+ recipientId: row.recipientId,
49
+ status: row.status,
50
+ error: toClientError(row.error),
51
+ createdAt: row.createdAt,
52
+ })),
53
+ };
54
+ },
55
+ });
@@ -39,7 +39,7 @@ type DeliveryLogRow = {
39
39
  createdAt: Temporal.Instant;
40
40
  };
41
41
 
42
- function toClientError(stored: string | null): DeliveryErrorCode | null {
42
+ export function toClientError(stored: string | null): DeliveryErrorCode | null {
43
43
  if (stored === null) return null;
44
44
  return isDeliveryErrorCode(stored) ? stored : "channel_error";
45
45
  }
@@ -55,6 +55,8 @@ const renderJobBaseSchema = z.object({
55
55
  priority: z.enum(["critical", "normal", "low"]),
56
56
  message: channelMessageSchema,
57
57
  idempotencyKey: z.string().optional(),
58
+ // The notify() key as given, for the channel context; idempotencyKey above is only the release key.
59
+ notifyIdempotencyKey: z.string().optional(),
58
60
  });
59
61
 
60
62
  const renderJobPayloadSchema = renderJobBaseSchema.and(recipientAddressFieldSchema);
@@ -258,6 +260,7 @@ async function renderStep(p: RenderJobPayload, ctx: JobContext): Promise<void> {
258
260
  ctx.services.secrets,
259
261
  ctx.config,
260
262
  (fileTenantId) => fileContextForTenant(ctx, ctx.systemUser.tenantId, fileTenantId),
263
+ p.notifyIdempotencyKey,
261
264
  );
262
265
 
263
266
  let rendered: RenderedMessage;
@@ -284,6 +287,7 @@ async function renderStep(p: RenderJobPayload, ctx: JobContext): Promise<void> {
284
287
  // Deliver via the channel using the rendered payload (if any). On failure:
285
288
  // record the terminal failed event and rethrow so BullMQ retries the send with
286
289
  // the same already-rendered HTML — no re-render needed.
290
+ // guard:dup-ok one job entry point per step; payload schema and step differ from deliveryRenderJob
287
291
  export const deliverySendJob: JobHandlerFn = async (payload, ctx) => {
288
292
  const p = sendJobPayloadSchema.parse(payload);
289
293
  return releasingKeyOnTerminalFailure(ctx, p, () => sendStep(p, ctx));
@@ -301,6 +305,7 @@ async function sendStep(p: z.infer<typeof sendJobPayloadSchema>, ctx: JobContext
301
305
  ctx.services.secrets,
302
306
  ctx.config,
303
307
  (fileTenantId) => fileContextForTenant(ctx, ctx.systemUser.tenantId, fileTenantId),
308
+ p.notifyIdempotencyKey,
304
309
  );
305
310
 
306
311
  try {
@@ -30,6 +30,8 @@ import {
30
30
  // its event stream 1:1 — same convention as jobRunsTable + tenantSecretsTable.
31
31
  // Event replays stay idempotent (primary-key conflict instead of duplicate rows).
32
32
  const DELIVERY_ATTEMPTS_TENANT_CREATED_INDEX = "store_delivery_attempts_tenant_id_created_at_idx";
33
+ const DELIVERY_ATTEMPTS_TENANT_IDEMPOTENCY_INDEX =
34
+ "store_delivery_attempts_tenant_id_idempotency_key_idx";
33
35
 
34
36
  export const deliveryAttemptsTable = pgTable(
35
37
  "store_delivery_attempts",
@@ -49,8 +51,13 @@ export const deliveryAttemptsTable = pgTable(
49
51
  // notify() priority from the event payload.
50
52
  priority: text("priority").notNull().default("normal").$type<"critical" | "normal" | "low">(),
51
53
  createdAt: instant("created_at").default(sql`now()`).notNull(),
54
+ // Null for attempts of notify() calls without an idempotencyKey and for rows that predate the column.
55
+ idempotencyKey: text("idempotency_key"),
52
56
  },
53
- (t) => [index(DELIVERY_ATTEMPTS_TENANT_CREATED_INDEX).on(t.tenantId, t.createdAt)],
57
+ (t) => [
58
+ index(DELIVERY_ATTEMPTS_TENANT_CREATED_INDEX).on(t.tenantId, t.createdAt),
59
+ index(DELIVERY_ATTEMPTS_TENANT_IDEMPOTENCY_INDEX).on(t.tenantId, t.idempotencyKey),
60
+ ],
54
61
  );
55
62
 
56
63
  // **Unmanaged table** — deliberately has no createEntity because:
@@ -64,7 +71,10 @@ export const deliveryAttemptsTable = pgTable(
64
71
  // from this metadata.
65
72
  export const deliveryAttemptsTableMeta: EntityTableMeta = defineUnmanagedTable({
66
73
  tableName: "store_delivery_attempts",
67
- indexes: [{ name: DELIVERY_ATTEMPTS_TENANT_CREATED_INDEX, columns: ["tenant_id", "created_at"] }],
74
+ indexes: [
75
+ { name: DELIVERY_ATTEMPTS_TENANT_CREATED_INDEX, columns: ["tenant_id", "created_at"] },
76
+ { name: DELIVERY_ATTEMPTS_TENANT_IDEMPOTENCY_INDEX, columns: ["tenant_id", "idempotency_key"] },
77
+ ],
68
78
  columns: [
69
79
  { name: "id", pgType: "uuid", notNull: true, primaryKey: true },
70
80
  { name: "tenant_id", pgType: "uuid", notNull: true },
@@ -77,6 +87,7 @@ export const deliveryAttemptsTableMeta: EntityTableMeta = defineUnmanagedTable({
77
87
  { name: "confirmed", pgType: "boolean", notNull: false },
78
88
  { name: "priority", pgType: "text", notNull: true, defaultSql: "'normal'" },
79
89
  { name: "created_at", pgType: "timestamptz", notNull: true, defaultSql: "now()" },
90
+ { name: "idempotency_key", pgType: "text", notNull: false },
80
91
  ],
81
92
  });
82
93
 
@@ -43,6 +43,8 @@ export type ChannelContext = {
43
43
  // The tenant's own config accessor, built server-side for this tenantId. Absent when the
44
44
  // delivery service has no tenantConfigFor and the job context carries no config.
45
45
  readonly config?: ConfigAccessor | undefined;
46
+ // The notify() idempotencyKey of the call, so a channel can store it next to what it sends.
47
+ readonly idempotencyKey?: string | undefined;
46
48
  // Renders a stored mail template, the tenant's own or the system fallback.
47
49
  readonly renderMail?: (payload: MailPayload) => Promise<RenderedMail>;
48
50
  // Reads the bytes behind an attachment ref at send time. Absent when no file storage is wired.
@@ -121,6 +123,7 @@ export type DeliveryLogEntry = {
121
123
  readonly error: DeliveryErrorCode | null;
122
124
  readonly priority: NotifyPriority;
123
125
  readonly confirmed?: false;
126
+ readonly idempotencyKey?: string;
124
127
  };
125
128
 
126
129
  // --- Delivery Service ---
@@ -61,6 +61,7 @@ function linkHtml(link: MailChromeLink): string {
61
61
 
62
62
  // The style block is static apart from the validated hex accent and the markup carries
63
63
  // no style attributes, so the CSP admits exactly this block by its hash.
64
+ // guard:dup-ok one template-literal stylesheet; only the shape matches unrelated string builders
64
65
  function pageStyle(accent: string): string {
65
66
  return `@font-face{font-family:"IBM Plex Sans";font-style:normal;font-weight:400;font-display:swap;src:url("${FONT_URL_PREFIX}400.woff2") format("woff2")}
66
67
  @font-face{font-family:"IBM Plex Sans";font-style:normal;font-weight:600;font-display:swap;src:url("${FONT_URL_PREFIX}600.woff2") format("woff2")}
@@ -125,6 +126,7 @@ function footerHtml(chrome: MailChrome): string {
125
126
  return linesHtml === "" ? "" : `<footer class="footer">${linesHtml}</footer>`;
126
127
  }
127
128
 
129
+ // guard:dup-ok one escaped template-literal form; only the shape matches other HTML snippets
128
130
  function tokenForm(action: string, token: string, label: string, variant: string): string {
129
131
  return `<form method="post" action="${escapeHtmlAttr(action)}">
130
132
  <input type="hidden" name="token" value="${escapeHtmlAttr(token)}">
@@ -3,7 +3,7 @@
3
3
 
4
4
  import { type ColumnRendererProps, useTranslation } from "@cosmicdrift/kumiko-renderer";
5
5
  import type { ReactNode } from "react";
6
- import { translateOrRaw } from "../../shared/web/translate-or-raw.ts";
6
+ import { translateOrRaw } from "../../shared/web/index.ts";
7
7
 
8
8
  export function DeliveryChannelCell({ row }: ColumnRendererProps): ReactNode {
9
9
  const t = useTranslation();
@@ -4,7 +4,7 @@
4
4
  import { type ColumnRendererProps, useTranslation } from "@cosmicdrift/kumiko-renderer";
5
5
  import { HTTP_ERROR_CODE_PATTERN } from "@cosmicdrift/kumiko-types/handlers";
6
6
  import type { ReactNode } from "react";
7
- import { translateOrRaw } from "../../shared/web/translate-or-raw.ts";
7
+ import { translateOrRaw } from "../../shared/web/index.ts";
8
8
 
9
9
  export function DeliveryErrorCell({ row }: ColumnRendererProps): ReactNode {
10
10
  const t = useTranslation();
@@ -6,7 +6,7 @@
6
6
  import { type ColumnRendererProps, useTranslation } from "@cosmicdrift/kumiko-renderer";
7
7
  import { StatusBadge, type StatusTone } from "@cosmicdrift/kumiko-renderer/web";
8
8
  import type { ReactNode } from "react";
9
- import { translateOrRaw } from "../../shared/web/translate-or-raw.ts";
9
+ import { translateOrRaw } from "../../shared/web/index.ts";
10
10
  import { DeliveryStatus } from "./public-names.ts";
11
11
 
12
12
  const STATUS_TONE: Readonly<Record<string, StatusTone>> = {
@@ -1,7 +1,8 @@
1
- import { type ColumnRendererProps, formatWhen } from "@cosmicdrift/kumiko-renderer";
1
+ import { type ColumnRendererProps, formatWhen, useLocale } from "@cosmicdrift/kumiko-renderer";
2
2
  import type { ReactNode } from "react";
3
3
 
4
4
  export function DeliveryTimeCell({ row }: ColumnRendererProps): ReactNode {
5
+ const locale = useLocale().locale();
5
6
  const createdAt = row["createdAt"];
6
- return typeof createdAt === "string" ? formatWhen(createdAt) : "";
7
+ return typeof createdAt === "string" ? formatWhen(createdAt, locale) : "";
7
8
  }
@@ -5,7 +5,7 @@
5
5
 
6
6
  import { type ColumnRendererProps, useTranslation } from "@cosmicdrift/kumiko-renderer";
7
7
  import type { ReactNode } from "react";
8
- import { translateOrRaw } from "../../shared/web/translate-or-raw.ts";
8
+ import { translateOrRaw } from "../../shared/web/index.ts";
9
9
 
10
10
  const NOTIFICATION_QN_PATTERN = /^([^:]+):notify:(.+)$/;
11
11
 
@@ -24,6 +24,7 @@ export const DELIVERY_RESUBSCRIBE_PATH = "/api/delivery/resubscribe" as const;
24
24
  export const DeliveryQueries = {
25
25
  log: "delivery:query:log",
26
26
  preferences: "delivery:query:preferences",
27
+ attemptsByKeys: "delivery:query:attempts-by-keys",
27
28
  unsubscribePageChrome: "delivery:query:unsubscribe-page-chrome",
28
29
  } as const;
29
30
 
@@ -3,6 +3,8 @@
3
3
  // to it — otherwise requested ingests for that provider never get picked up.
4
4
 
5
5
  import type { FeatureDefinition, JobDefinition } from "@cosmicdrift/kumiko-framework/engine";
6
+ import { bootRuleError } from "@cosmicdrift/kumiko-framework/engine";
7
+ import { DOCUMENT_INGEST_BOOT_RULES } from "./boot-rules.ts";
6
8
  import { DOCUMENT_INGEST_REQUESTED_EVENT_QN } from "./events.ts";
7
9
  import { resolveDocumentIngestProviders } from "./providers.ts";
8
10
 
@@ -28,20 +30,22 @@ export function validateDocumentIngestProviderWiring(features: readonly FeatureD
28
30
  const provider = providerFilterOf(jobDef.trigger);
29
31
  if (provider === undefined) continue;
30
32
  if (provider === "") {
31
- throw new Error(
32
- `[kumiko:boot] Job "${jobDef.name}" (feature "${feature.name}") triggers on ` +
33
+ throw bootRuleError(DOCUMENT_INGEST_BOOT_RULES.jobWithoutProviderFilter, {
34
+ message:
35
+ `[kumiko:boot] Job "${jobDef.name}" (feature "${feature.name}") triggers on ` +
33
36
  `document-ingest-foundation's documentIngest.requested without a provider filter — every job on ` +
34
37
  `this event must route through documentIngestProviderTrigger("<name>"), or it fires for every ` +
35
38
  `provider's uploads. Use: trigger: documentIngestProviderTrigger("<name>").`,
36
- );
39
+ });
37
40
  }
38
41
  if (!registeredProviderNames.has(provider)) {
39
- throw new Error(
40
- `[kumiko:boot] Job "${jobDef.name}" (feature "${feature.name}") filters documentIngest.requested to ` +
42
+ throw bootRuleError(DOCUMENT_INGEST_BOOT_RULES.jobUnknownProvider, {
43
+ message:
44
+ `[kumiko:boot] Job "${jobDef.name}" (feature "${feature.name}") filters documentIngest.requested to ` +
41
45
  `provider "${provider}", but no feature registers that provider via ` +
42
46
  `r.useExtension(EXT_DOCUMENT_INGEST_PROVIDER, "${provider}", ...). Known: ` +
43
47
  `${[...registeredProviderNames].join(", ") || "<none>"}.`,
44
- );
48
+ });
45
49
  }
46
50
  wiredProviderNames.add(provider);
47
51
  }
@@ -49,10 +53,11 @@ export function validateDocumentIngestProviderWiring(features: readonly FeatureD
49
53
 
50
54
  for (const name of registeredProviderNames) {
51
55
  if (wiredProviderNames.has(name)) continue;
52
- throw new Error(
53
- `[kumiko:boot] Provider "${name}" is registered via EXT_DOCUMENT_INGEST_PROVIDER but no job triggers on ` +
56
+ throw bootRuleError(DOCUMENT_INGEST_BOOT_RULES.providerWithoutJob, {
57
+ message:
58
+ `[kumiko:boot] Provider "${name}" is registered via EXT_DOCUMENT_INGEST_PROVIDER but no job triggers on ` +
54
59
  `documentIngestProviderTrigger("${name}") — files matching its mimeTypes would be requested for ingest ` +
55
60
  `and never processed. Add an r.job with that trigger, or unmount the provider.`,
56
- );
61
+ });
57
62
  }
58
63
  }
@@ -0,0 +1,22 @@
1
+ import type { BootRuleTable } from "@cosmicdrift/kumiko-framework/engine";
2
+
3
+ export const DOCUMENT_INGEST_BOOT_RULES = {
4
+ jobWithoutProviderFilter: {
5
+ id: "document-ingest-foundation/job-without-provider-filter",
6
+ summary:
7
+ "A job triggered by documentIngest.requested filters to one provider, so it does not fire for every provider's uploads.",
8
+ fix: 'Use trigger: documentIngestProviderTrigger("<name>").',
9
+ },
10
+ jobUnknownProvider: {
11
+ id: "document-ingest-foundation/job-unknown-provider",
12
+ summary:
13
+ "A documentIngest.requested job filters to a provider that some feature registers via EXT_DOCUMENT_INGEST_PROVIDER.",
14
+ fix: 'Register the provider via r.useExtension(EXT_DOCUMENT_INGEST_PROVIDER, "<name>", ...) or fix the provider name.',
15
+ },
16
+ providerWithoutJob: {
17
+ id: "document-ingest-foundation/provider-without-job",
18
+ summary:
19
+ "A registered document-ingest provider has a job triggered by documentIngestProviderTrigger, otherwise requested files are never processed.",
20
+ fix: "Add an r.job with that trigger, or unmount the provider.",
21
+ },
22
+ } as const satisfies BootRuleTable;
@@ -1,4 +1,10 @@
1
1
  [
2
+ {
3
+ "version": "0.409.0",
4
+ "type": "improvement",
5
+ "title": "Ingest progress per file via reportIngestProgress",
6
+ "detail": "reportIngestProgress(deps, { fileRefId, pagesDone, pagesTotal }) appends a documentIngest.progress event to the file's ingest stream and runs the ingest-progress projection, which keeps one row per file in store_document_ingest_progress (documentIngestProgressTable, read by tenantId and fileRefId). The payload is validated by documentIngestProgressPayloadSchema (pagesTotal at least 1, pagesDone not above pagesTotal). Provider jobs still trigger only on documentIngest.requested. Apps need a migration for the new table."
7
+ },
2
8
  {
3
9
  "version": "0.389.0",
4
10
  "type": "improvement",
@@ -48,6 +48,23 @@ export const documentIngestSkippedPayloadSchema = z.object({
48
48
  });
49
49
  export type DocumentIngestSkippedPayload = z.infer<typeof documentIngestSkippedPayloadSchema>;
50
50
 
51
+ export const DOCUMENT_INGEST_PROGRESS_EVENT_SHORT = "documentIngest.progress" as const;
52
+
53
+ export const DOCUMENT_INGEST_PROGRESS_EVENT_QN =
54
+ "document-ingest-foundation:event:document-ingest-progress" as const;
55
+
56
+ export const documentIngestProgressPayloadSchema = z
57
+ .object({
58
+ fileRefId: z.string().min(1),
59
+ pagesDone: z.number().int().min(0),
60
+ pagesTotal: z.number().int().min(1),
61
+ })
62
+ .refine((p) => p.pagesDone <= p.pagesTotal, {
63
+ message: "pagesDone must not exceed pagesTotal",
64
+ path: ["pagesDone"],
65
+ });
66
+ export type DocumentIngestProgressPayload = z.infer<typeof documentIngestProgressPayloadSchema>;
67
+
51
68
  // Terminal events of a document-extract stream. The QNs belong to the provider that registers
52
69
  // them; the foundation only owns the shared payload shape.
53
70
  export const documentExtractReadyPayloadSchema = z.object({
@@ -4,7 +4,7 @@
4
4
  // hardcoded mime allowlist or size cap — providers register via
5
5
  // EXT_DOCUMENT_INGEST_PROVIDER (see providers.ts).
6
6
 
7
- import { applyEntityEvent, entityEventName } from "@cosmicdrift/kumiko-framework/db";
7
+ import { applyEntityEvent, entityEventName, upsertByPk } from "@cosmicdrift/kumiko-framework/db";
8
8
  import {
9
9
  access,
10
10
  createTenantConfig,
@@ -20,10 +20,13 @@ import { documentExtractEntity, documentExtractsTable } from "./entity.ts";
20
20
  import {
21
21
  DOCUMENT_EXTRACT_AGGREGATE_TYPE,
22
22
  DOCUMENT_INGEST_AGGREGATE_TYPE,
23
+ DOCUMENT_INGEST_PROGRESS_EVENT_QN,
24
+ DOCUMENT_INGEST_PROGRESS_EVENT_SHORT,
23
25
  DOCUMENT_INGEST_REQUESTED_EVENT_QN,
24
26
  DOCUMENT_INGEST_REQUESTED_EVENT_SHORT,
25
27
  DOCUMENT_INGEST_SKIPPED_EVENT_QN,
26
28
  DOCUMENT_INGEST_SKIPPED_EVENT_SHORT,
29
+ documentIngestProgressPayloadSchema,
27
30
  documentIngestRequestedPayloadSchema,
28
31
  documentIngestSkippedPayloadSchema,
29
32
  } from "./events.ts";
@@ -37,6 +40,7 @@ import {
37
40
  resolveDocumentIngestProviders,
38
41
  UNCLAIMED_PROVIDER_SENTINEL,
39
42
  } from "./providers.ts";
43
+ import { documentIngestProgressTable, documentIngestProgressTableMeta } from "./tables.ts";
40
44
  import { documentExtractTenantDestroyHook } from "./tenant-destroy-hook.ts";
41
45
 
42
46
  const FEATURE_NAME = "document-ingest-foundation";
@@ -206,6 +210,40 @@ export function createDocumentIngestFoundationFeature() {
206
210
  piiFields: "none",
207
211
  });
208
212
 
213
+ r.defineEvent(DOCUMENT_INGEST_PROGRESS_EVENT_SHORT, documentIngestProgressPayloadSchema, {
214
+ piiFields: "none",
215
+ });
216
+
217
+ r.storeTable(documentIngestProgressTableMeta, {
218
+ reason: "read_side.document_ingest_progress",
219
+ });
220
+ r.projection({
221
+ name: "ingest-progress",
222
+ source: DOCUMENT_INGEST_AGGREGATE_TYPE,
223
+ table: documentIngestProgressTable,
224
+ apply: {
225
+ [DOCUMENT_INGEST_PROGRESS_EVENT_QN]: async (event, tx) => {
226
+ const progress = documentIngestProgressPayloadSchema.parse(event.payload);
227
+ await upsertByPk(
228
+ tx,
229
+ documentIngestProgressTable,
230
+ {
231
+ id: event.aggregateId,
232
+ tenantId: event.tenantId,
233
+ fileRefId: progress.fileRefId,
234
+ pagesDone: progress.pagesDone,
235
+ pagesTotal: progress.pagesTotal,
236
+ },
237
+ {
238
+ pagesDone: progress.pagesDone,
239
+ pagesTotal: progress.pagesTotal,
240
+ updatedAt: event.createdAt,
241
+ },
242
+ );
243
+ },
244
+ },
245
+ });
246
+
209
247
  r.multiStreamProjection({
210
248
  name: "request-ingest",
211
249
  apply: {
@@ -17,16 +17,20 @@ export {
17
17
  export {
18
18
  DOCUMENT_EXTRACT_AGGREGATE_TYPE,
19
19
  DOCUMENT_INGEST_AGGREGATE_TYPE,
20
+ DOCUMENT_INGEST_PROGRESS_EVENT_QN,
21
+ DOCUMENT_INGEST_PROGRESS_EVENT_SHORT,
20
22
  DOCUMENT_INGEST_REQUESTED_EVENT_QN,
21
23
  DOCUMENT_INGEST_REQUESTED_EVENT_SHORT,
22
24
  DOCUMENT_INGEST_SKIPPED_EVENT_QN,
23
25
  DOCUMENT_INGEST_SKIPPED_EVENT_SHORT,
24
26
  type DocumentExtractFailedPayload,
25
27
  type DocumentExtractReadyPayload,
28
+ type DocumentIngestProgressPayload,
26
29
  type DocumentIngestRequestedPayload,
27
30
  type DocumentIngestSkippedPayload,
28
31
  documentExtractFailedPayloadSchema,
29
32
  documentExtractReadyPayloadSchema,
33
+ documentIngestProgressPayloadSchema,
30
34
  documentIngestRequestedPayloadSchema,
31
35
  documentIngestSkippedPayloadSchema,
32
36
  } from "./events.ts";
@@ -41,6 +45,12 @@ export {
41
45
  type ResolvedDocumentIngestProvider,
42
46
  resolveDocumentIngestProviders,
43
47
  } from "./providers.ts";
48
+ export {
49
+ type ReportIngestProgressDeps,
50
+ type ReportIngestProgressInput,
51
+ reportIngestProgress,
52
+ } from "./report-ingest-progress.ts";
53
+ export { documentIngestProgressTable } from "./tables.ts";
44
54
  export {
45
55
  type DocumentExtractWriteResult,
46
56
  writeDocumentExtractForLiveFileRef,
@@ -0,0 +1,43 @@
1
+ import type { DbConnection } from "@cosmicdrift/kumiko-framework/db";
2
+ import type { Registry } from "@cosmicdrift/kumiko-framework/engine";
3
+ import { append, getStreamVersion } from "@cosmicdrift/kumiko-framework/event-store";
4
+ import { runProjectionsForEvent } from "@cosmicdrift/kumiko-framework/pipeline";
5
+ import { documentIngestAggregateId } from "./aggregate-id.ts";
6
+ import {
7
+ DOCUMENT_INGEST_AGGREGATE_TYPE,
8
+ DOCUMENT_INGEST_PROGRESS_EVENT_QN,
9
+ documentIngestProgressPayloadSchema,
10
+ } from "./events.ts";
11
+
12
+ export type ReportIngestProgressDeps = {
13
+ readonly db: DbConnection;
14
+ readonly registry: Registry;
15
+ readonly tenantId: string;
16
+ readonly actorId: string;
17
+ };
18
+
19
+ export type ReportIngestProgressInput = {
20
+ readonly fileRefId: string;
21
+ readonly pagesDone: number;
22
+ readonly pagesTotal: number;
23
+ };
24
+
25
+ // Low-level append() does not fire projections, so they run explicitly in the same call.
26
+ export async function reportIngestProgress(
27
+ deps: ReportIngestProgressDeps,
28
+ input: ReportIngestProgressInput,
29
+ ): Promise<void> {
30
+ const payload = documentIngestProgressPayloadSchema.parse(input);
31
+ const aggregateId = documentIngestAggregateId(deps.tenantId, payload.fileRefId);
32
+ const expectedVersion = await getStreamVersion(deps.db, aggregateId, deps.tenantId);
33
+ const stored = await append(deps.db, {
34
+ aggregateId,
35
+ aggregateType: DOCUMENT_INGEST_AGGREGATE_TYPE,
36
+ tenantId: deps.tenantId,
37
+ expectedVersion,
38
+ type: DOCUMENT_INGEST_PROGRESS_EVENT_QN,
39
+ payload,
40
+ metadata: { userId: deps.actorId },
41
+ });
42
+ await runProjectionsForEvent(stored, deps.registry, deps.db);
43
+ }
@@ -0,0 +1,43 @@
1
+ import {
2
+ defineUnmanagedTable,
3
+ type EntityTableMeta,
4
+ index,
5
+ instant,
6
+ integer,
7
+ table as pgTable,
8
+ sql,
9
+ text,
10
+ uuid,
11
+ } from "@cosmicdrift/kumiko-framework/db";
12
+
13
+ const INGEST_PROGRESS_FILE_REF_INDEX = "store_document_ingest_progress_tenant_id_file_ref_id_idx";
14
+
15
+ // One row per ingest stream (PK = documentIngestAggregateId), upserted by the
16
+ // "ingest-progress" projection on every documentIngest.progress event.
17
+ export const documentIngestProgressTable = pgTable(
18
+ "store_document_ingest_progress",
19
+ {
20
+ id: uuid("id").primaryKey(),
21
+ tenantId: uuid("tenant_id").notNull(),
22
+ fileRefId: text("file_ref_id").notNull(),
23
+ pagesDone: integer("pages_done").notNull(),
24
+ pagesTotal: integer("pages_total").notNull(),
25
+ updatedAt: instant("updated_at").default(sql`now()`).notNull(),
26
+ },
27
+ (t) => [index(INGEST_PROGRESS_FILE_REF_INDEX).on(t.tenantId, t.fileRefId)],
28
+ );
29
+
30
+ // Unmanaged: the id is the event-stream aggregate id and replays are idempotent via the PK upsert,
31
+ // so the managed base columns (version, audit columns) have no use here.
32
+ export const documentIngestProgressTableMeta: EntityTableMeta = defineUnmanagedTable({
33
+ tableName: "store_document_ingest_progress",
34
+ indexes: [{ name: INGEST_PROGRESS_FILE_REF_INDEX, columns: ["tenant_id", "file_ref_id"] }],
35
+ columns: [
36
+ { name: "id", pgType: "uuid", notNull: true, primaryKey: true },
37
+ { name: "tenant_id", pgType: "uuid", notNull: true },
38
+ { name: "file_ref_id", pgType: "text", notNull: true },
39
+ { name: "pages_done", pgType: "integer", notNull: true },
40
+ { name: "pages_total", pgType: "integer", notNull: true },
41
+ { name: "updated_at", pgType: "timestamptz", notNull: true, defaultSql: "now()" },
42
+ ],
43
+ });
@@ -31,7 +31,7 @@ export const PUBLIC_VARIANT_BY_FILE_REF_QN = "file-derivatives:query:public-vari
31
31
  export const publicVariantByFileRefQuery = defineQueryHandler({
32
32
  name: "public-variant-by-file-ref",
33
33
  schema: publicVariantPayloadSchema,
34
- access: { roles: ["anonymous", "User", "TenantAdmin", "SystemAdmin"] },
34
+ access: { roles: ["anonymous", "User", "TenantAdmin", "SystemAdmin"], anySignedIn: true },
35
35
  agent: { expose: false },
36
36
  rateLimit: { per: "ip", limit: 60, windowSeconds: 60 },
37
37
  escapeHatch: {
@@ -93,7 +93,7 @@ export const publicVariantPayloadSchema = z.object({
93
93
  export const publicVariantQuery = defineQueryHandler({
94
94
  name: "public-variant",
95
95
  schema: publicVariantPayloadSchema,
96
- access: { roles: ["anonymous", "User", "TenantAdmin", "SystemAdmin"] },
96
+ access: { roles: ["anonymous", "User", "TenantAdmin", "SystemAdmin"], anySignedIn: true },
97
97
  agent: { expose: false },
98
98
  // ponytail: "ip" is the ONLY throttle on an anonymous, internet-facing
99
99
  // render/storage-cost route — its accuracy depends on the server's
@@ -1,4 +1,10 @@
1
1
  [
2
+ {
3
+ "version": "0.407.0",
4
+ "type": "improvement",
5
+ "title": "Tenant destruction keeps files of held rows",
6
+ "detail": "The fileRef destroy hook skips the fileRefs listed in heldFileRefIds, and the files prefix sweep keeps their bytes. Without a configured file provider, the retention cleanup still removes the held fileRef rows after keepFor and logs that no bytes could be deleted, so the tenant does not stay in destroyHeld forever."
7
+ },
2
8
  {
3
9
  "version": "0.364.0",
4
10
  "type": "fix",
@@ -100,7 +100,10 @@ export const fileRefTenantDestroyHook: TenantDataDestroyHook = async (ctx) => {
100
100
  nextBatch: () =>
101
101
  ctx.db.selectMany<{ id: string; storageKey: string }>(
102
102
  fileRefsTable,
103
- { tenantId: ctx.tenantId },
103
+ {
104
+ tenantId: ctx.tenantId,
105
+ id: { notIn: [...(ctx.heldFileRefIds ?? [])] },
106
+ },
104
107
  { limit: DESTROY_CHUNK_SIZE },
105
108
  ),
106
109
  migrateRow: async (row) => {