@cosmicdrift/kumiko-samples 0.405.0 → 0.409.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/packages/bundled-features/package.json +26 -4
- package/packages/bundled-features/src/account-security/feature.ts +9 -1
- package/packages/bundled-features/src/admin-shell/changes.json +6 -0
- package/packages/bundled-features/src/admin-shell/feature.ts +4 -1
- package/packages/bundled-features/src/agent-tools/agent-manifest.ts +1 -0
- package/packages/bundled-features/src/agent-tools/changes.json +6 -0
- package/packages/bundled-features/src/agent-tools/tool-catalog.ts +1 -0
- package/packages/bundled-features/src/agent-tools/types.ts +4 -0
- package/packages/bundled-features/src/audit/event-classification.ts +1 -0
- package/packages/bundled-features/src/auth-email-password/bootstrap.ts +1 -0
- package/packages/bundled-features/src/auth-email-password/errors.ts +18 -66
- package/packages/bundled-features/src/auth-email-password/web/auth-client.ts +30 -64
- package/packages/bundled-features/src/auth-email-password/web/auth-redirect.ts +2 -2
- package/packages/bundled-features/src/auth-email-password/web/confirm-account-unlock-screen.tsx +20 -66
- package/packages/bundled-features/src/auth-email-password/web/index.ts +1 -0
- package/packages/bundled-features/src/auth-email-password/web/read-path-param.ts +8 -0
- package/packages/bundled-features/src/auth-email-password/web/return-path.ts +3 -2
- package/packages/bundled-features/src/auth-email-password/web/token-confirm-screen.tsx +97 -0
- package/packages/bundled-features/src/auth-email-password/web/verify-email-screen.tsx +20 -68
- package/packages/bundled-features/src/auth-foundation/boot-checks.ts +22 -15
- package/packages/bundled-features/src/auth-foundation/boot-rules.ts +33 -0
- package/packages/bundled-features/src/auth-mfa/errors.ts +12 -42
- package/packages/bundled-features/src/auth-mfa/feature-exports.ts +6 -45
- package/packages/bundled-features/src/auth-mfa/feature.ts +8 -19
- package/packages/bundled-features/src/auth-mfa/web/mfa-client.ts +19 -33
- package/packages/bundled-features/src/billing-foundation/consumer-protection/termination-notify.ts +1 -0
- package/packages/bundled-features/src/billing-foundation/web/plan-price.ts +20 -7
- package/packages/bundled-features/src/cap-counter/stock-cap-guard.ts +1 -0
- package/packages/bundled-features/src/channel-in-app/changes.json +7 -0
- package/packages/bundled-features/src/channel-in-app/feature.ts +2 -0
- package/packages/bundled-features/src/channel-in-app/handlers/read-state-by-keys.query.ts +35 -0
- package/packages/bundled-features/src/channel-in-app/in-app-channel.ts +1 -0
- package/packages/bundled-features/src/channel-in-app/tables.ts +5 -1
- package/packages/bundled-features/src/contact/challenge.ts +41 -0
- package/packages/bundled-features/src/contact/changes.json +27 -0
- package/packages/bundled-features/src/contact/client/contact-client-source.ts +203 -0
- package/packages/bundled-features/src/contact/entity.ts +168 -0
- package/packages/bundled-features/src/contact/feature.ts +171 -0
- package/packages/bundled-features/src/contact/handlers/access.ts +17 -0
- package/packages/bundled-features/src/contact/handlers/attempts.ts +76 -0
- package/packages/bundled-features/src/contact/handlers/challenge.query.ts +44 -0
- package/packages/bundled-features/src/contact/handlers/forward-request.write.ts +98 -0
- package/packages/bundled-features/src/contact/handlers/mark-done.write.ts +40 -0
- package/packages/bundled-features/src/contact/handlers/notify-reporter-in-app.write.ts +48 -0
- package/packages/bundled-features/src/contact/handlers/open-count.query.ts +15 -0
- package/packages/bundled-features/src/contact/handlers/open-count.ts +17 -0
- package/packages/bundled-features/src/contact/handlers/replies.query.ts +29 -0
- package/packages/bundled-features/src/contact/handlers/reply.write.ts +197 -0
- package/packages/bundled-features/src/contact/handlers/report.write.ts +126 -0
- package/packages/bundled-features/src/contact/handlers/request-delivery.query.ts +143 -0
- package/packages/bundled-features/src/contact/handlers/request-detail.query.ts +50 -0
- package/packages/bundled-features/src/contact/handlers/request-list.query.ts +14 -0
- package/packages/bundled-features/src/contact/handlers/send-reply-mail.write.ts +124 -0
- package/packages/bundled-features/src/contact/handlers/send-test.write.ts +45 -0
- package/packages/bundled-features/src/contact/handlers/submit.write.ts +194 -0
- package/packages/bundled-features/src/contact/handlers/take-over-uploads.ts +47 -0
- package/packages/bundled-features/src/contact/i18n.ts +189 -0
- package/packages/bundled-features/src/contact/index.ts +29 -0
- package/packages/bundled-features/src/contact/lib.ts +176 -0
- package/packages/bundled-features/src/contact/mail.ts +401 -0
- package/packages/bundled-features/src/contact/options.ts +95 -0
- package/packages/bundled-features/src/contact/panels.ts +28 -0
- package/packages/bundled-features/src/contact/payloads.ts +106 -0
- package/packages/bundled-features/src/contact/pow.ts +22 -0
- package/packages/bundled-features/src/contact/screens.ts +506 -0
- package/packages/bundled-features/src/contact/subject.ts +13 -0
- package/packages/bundled-features/src/contact/user-agent.ts +39 -0
- package/packages/bundled-features/src/contact/user-data-hooks.ts +180 -0
- package/packages/bundled-features/src/contact/web/constants.ts +160 -0
- package/packages/bundled-features/src/contact/web/index.ts +29 -0
- package/packages/bundled-features/src/crypto-shredding/handlers/forget-subject.write.ts +5 -16
- package/packages/bundled-features/src/data-retention/changes.json +6 -0
- package/packages/bundled-features/src/data-retention/feature.ts +16 -2
- package/packages/bundled-features/src/data-retention/index.ts +5 -0
- package/packages/bundled-features/src/data-retention/run-retention-cleanup.ts +138 -41
- package/packages/bundled-features/src/data-retention/tenant-destruction-hold.ts +196 -0
- package/packages/bundled-features/src/delivery/address-opt-out.ts +1 -0
- package/packages/bundled-features/src/delivery/changes.json +7 -0
- package/packages/bundled-features/src/delivery/channel-context.ts +2 -0
- package/packages/bundled-features/src/delivery/delivery-service.ts +29 -5
- package/packages/bundled-features/src/delivery/events.ts +2 -0
- package/packages/bundled-features/src/delivery/feature.ts +3 -2
- package/packages/bundled-features/src/delivery/handlers/attempts-by-keys.query.ts +55 -0
- package/packages/bundled-features/src/delivery/handlers/log.query.ts +1 -1
- package/packages/bundled-features/src/delivery/jobs.ts +5 -0
- package/packages/bundled-features/src/delivery/tables.ts +13 -2
- package/packages/bundled-features/src/delivery/types.ts +3 -0
- package/packages/bundled-features/src/delivery/unsubscribe-page.ts +2 -0
- package/packages/bundled-features/src/delivery/web/delivery-channel-cell.tsx +1 -1
- package/packages/bundled-features/src/delivery/web/delivery-error-cell.tsx +1 -1
- package/packages/bundled-features/src/delivery/web/delivery-status-cell.tsx +1 -1
- package/packages/bundled-features/src/delivery/web/delivery-time-cell.tsx +3 -2
- package/packages/bundled-features/src/delivery/web/delivery-type-cell.tsx +1 -1
- package/packages/bundled-features/src/delivery/web/public-names.ts +1 -0
- package/packages/bundled-features/src/document-ingest-foundation/boot-checks.ts +14 -9
- package/packages/bundled-features/src/document-ingest-foundation/boot-rules.ts +22 -0
- package/packages/bundled-features/src/document-ingest-foundation/changes.json +6 -0
- package/packages/bundled-features/src/document-ingest-foundation/events.ts +17 -0
- package/packages/bundled-features/src/document-ingest-foundation/feature.ts +39 -1
- package/packages/bundled-features/src/document-ingest-foundation/index.ts +10 -0
- package/packages/bundled-features/src/document-ingest-foundation/report-ingest-progress.ts +43 -0
- package/packages/bundled-features/src/document-ingest-foundation/tables.ts +43 -0
- package/packages/bundled-features/src/files-tenant-data/changes.json +6 -0
- package/packages/bundled-features/src/files-tenant-data/hooks.ts +4 -1
- package/packages/bundled-features/src/folders/web/folder-manager.tsx +8 -9
- package/packages/bundled-features/src/folders/web/folder-section.tsx +1 -1
- package/packages/bundled-features/src/form-draft-user-data/index.ts +2 -0
- package/packages/bundled-features/src/inbound-mail-foundation/changes.json +13 -0
- package/packages/bundled-features/src/inbound-mail-foundation/entities.ts +2 -0
- package/packages/bundled-features/src/inbound-mail-foundation/events.ts +2 -0
- package/packages/bundled-features/src/inbound-mail-foundation/feature.ts +6 -6
- package/packages/bundled-features/src/inbound-mail-foundation/handlers/attach-message-content.write.ts +7 -0
- package/packages/bundled-features/src/inbound-mail-foundation/handlers/ingest-message.write.ts +6 -0
- package/packages/bundled-features/src/inbound-mail-foundation/handlers/list-messages.query.ts +6 -2
- package/packages/bundled-features/src/inbound-mail-foundation/handlers/message-content.query.ts +3 -0
- package/packages/bundled-features/src/inbound-mail-foundation/handlers/message-content.ts +19 -0
- package/packages/bundled-features/src/inbound-mail-foundation/projection.ts +2 -0
- package/packages/bundled-features/src/inbound-mail-foundation/sanitize-inbound-html.ts +150 -0
- package/packages/bundled-features/src/inbound-mail-foundation/types.ts +1 -0
- package/packages/bundled-features/src/jobs/job-run-logger.ts +24 -25
- package/packages/bundled-features/src/ledger/handlers/reports.query.ts +46 -31
- package/packages/bundled-features/src/ledger/recurring.ts +1 -0
- package/packages/bundled-features/src/notes-history/web/notes-section.tsx +3 -1
- package/packages/bundled-features/src/personal-access-tokens/feature.ts +9 -17
- package/packages/bundled-features/src/personal-access-tokens/handlers/create.write.ts +2 -7
- package/packages/bundled-features/src/secrets/changes.json +6 -0
- package/packages/bundled-features/src/secrets/handlers/delete.write.ts +8 -4
- package/packages/bundled-features/src/secrets/handlers/list.query.ts +6 -3
- package/packages/bundled-features/src/secrets/handlers/set.write.ts +9 -4
- package/packages/bundled-features/src/secrets/secret-scope.ts +33 -0
- package/packages/bundled-features/src/sessions/changes.json +6 -0
- package/packages/bundled-features/src/sessions/feature.ts +21 -18
- package/packages/bundled-features/src/sessions/handlers/last-activity-probe.query.ts +53 -0
- package/packages/bundled-features/src/sessions/handlers/last-activity-probe.route.ts +39 -0
- package/packages/bundled-features/src/sessions/screens.ts +1 -0
- package/packages/bundled-features/src/sessions/session-callbacks.ts +13 -12
- package/packages/bundled-features/src/sessions/web/i18n.ts +4 -1
- package/packages/bundled-features/src/shared/assert-billing-live.ts +14 -0
- package/packages/bundled-features/src/shared/collect-extension-options.ts +12 -0
- package/packages/bundled-features/src/shared/index.ts +16 -0
- package/packages/bundled-features/src/shared/late-bound-slot.ts +19 -0
- package/packages/bundled-features/src/shared/mail-locale-templates.ts +7 -1
- package/packages/bundled-features/src/shared/price-env-shape.ts +44 -0
- package/packages/bundled-features/src/shared/purge-row-file-refs.ts +1 -1
- package/packages/bundled-features/src/shared/read-feature-export-fn.ts +16 -0
- package/packages/bundled-features/src/shared/signup-handover.ts +3 -4
- package/packages/bundled-features/src/shared/tenant-destruction-hold.ts +49 -0
- package/packages/bundled-features/src/shared/unprocessable.ts +19 -0
- package/packages/bundled-features/src/shared/web/index.ts +3 -0
- package/packages/bundled-features/src/subscription-paddle/feature.ts +7 -15
- package/packages/bundled-features/src/subscription-paddle/runtime.ts +4 -7
- package/packages/bundled-features/src/subscription-stripe/feature.ts +7 -15
- package/packages/bundled-features/src/subscription-stripe/runtime.ts +4 -7
- package/packages/bundled-features/src/tags/entity.ts +1 -0
- package/packages/bundled-features/src/tags/web/tag-chip.tsx +14 -0
- package/packages/bundled-features/src/tags/web/tag-filter.tsx +4 -5
- package/packages/bundled-features/src/tags/web/tag-manager.tsx +1 -1
- package/packages/bundled-features/src/tags/web/tag-section.tsx +3 -6
- package/packages/bundled-features/src/tags/web/tags-cell.tsx +4 -5
- package/packages/bundled-features/src/template-resolver/compile-document-body.ts +27 -15
- package/packages/bundled-features/src/template-resolver/handlers/by-tenant.query.ts +11 -8
- package/packages/bundled-features/src/template-resolver/handlers/discard-draft.write.ts +1 -0
- package/packages/bundled-features/src/template-resolver/handlers/overview.query.ts +1 -0
- package/packages/bundled-features/src/template-resolver/handlers/send-test.write.ts +5 -5
- package/packages/bundled-features/src/template-resolver/handlers/toggle-status.write.ts +3 -0
- package/packages/bundled-features/src/template-resolver/linked-resources.ts +11 -6
- package/packages/bundled-features/src/template-resolver/store-template-resource.ts +15 -12
- package/packages/bundled-features/src/template-resolver/web/document-images.ts +6 -6
- package/packages/bundled-features/src/template-resolver/web/document-insert-fields.tsx +41 -36
- package/packages/bundled-features/src/template-resolver/web/document-schema.ts +11 -12
- package/packages/bundled-features/src/template-resolver/web/tiptap-attribute-parse-rule.ts +19 -0
- package/packages/bundled-features/src/tenant/i18n.ts +3 -0
- package/packages/bundled-features/src/tenant/schema/tenant.ts +1 -0
- package/packages/bundled-features/src/tenant/web/member-roles-cell.tsx +1 -1
- package/packages/bundled-features/src/tenant/web/member-status-cell.tsx +1 -1
- package/packages/bundled-features/src/tenant-inactivity/changes.json +8 -0
- package/packages/bundled-features/src/tenant-inactivity/check-inactive-tenants.ts +260 -0
- package/packages/bundled-features/src/tenant-inactivity/constants.ts +12 -0
- package/packages/bundled-features/src/tenant-inactivity/email-templates.ts +24 -0
- package/packages/bundled-features/src/tenant-inactivity/feature.ts +66 -0
- package/packages/bundled-features/src/tenant-inactivity/handlers/inactivity-state.query.ts +49 -0
- package/packages/bundled-features/src/tenant-inactivity/handlers/keep-account.write.ts +56 -0
- package/packages/bundled-features/src/tenant-inactivity/inactivity-plan.ts +187 -0
- package/packages/bundled-features/src/tenant-inactivity/index.ts +5 -0
- package/packages/bundled-features/src/tenant-inactivity/keep-token.ts +44 -0
- package/packages/bundled-features/src/tenant-inactivity/mail-notifications.ts +62 -0
- package/packages/bundled-features/src/tenant-inactivity/options.ts +38 -0
- package/packages/bundled-features/src/tenant-inactivity/remote-activity.ts +32 -0
- package/packages/bundled-features/src/tenant-inactivity/state-store.ts +71 -0
- package/packages/bundled-features/src/tenant-inactivity/state-table.ts +50 -0
- package/packages/bundled-features/src/tenant-lifecycle/boot-checks.ts +8 -6
- package/packages/bundled-features/src/tenant-lifecycle/boot-rules.ts +16 -0
- package/packages/bundled-features/src/tenant-lifecycle/changes.json +30 -0
- package/packages/bundled-features/src/tenant-lifecycle/constants.ts +6 -0
- package/packages/bundled-features/src/tenant-lifecycle/events.ts +2 -0
- package/packages/bundled-features/src/tenant-lifecycle/feature.ts +25 -2
- package/packages/bundled-features/src/tenant-lifecycle/handlers/request-destruction.write.ts +12 -87
- package/packages/bundled-features/src/tenant-lifecycle/index.ts +6 -0
- package/packages/bundled-features/src/tenant-lifecycle/request-tenant-destruction.ts +108 -0
- package/packages/bundled-features/src/tenant-lifecycle/retention-config-destroy-hooks.ts +62 -0
- package/packages/bundled-features/src/tenant-lifecycle/run-tenant-destroy.ts +131 -11
- package/packages/bundled-features/src/tenant-lifecycle/stages.ts +39 -4
- package/packages/bundled-features/src/tenant-lifecycle/testing.ts +1 -1
- package/packages/bundled-features/src/tier-engine/caps-for-tier-from-map.ts +16 -0
- package/packages/bundled-features/src/tier-engine/changes.json +6 -0
- package/packages/bundled-features/src/tier-engine/compose-app.ts +21 -20
- package/packages/bundled-features/src/tier-engine/index.ts +1 -0
- package/packages/bundled-features/src/user-data-rights/feature.ts +2 -0
- package/packages/bundled-features/src/user-data-rights/run-forget-cleanup.ts +2 -0
- package/packages/bundled-features/src/user-data-rights/web/privacy-center-screen.tsx +1 -1
- package/packages/bundled-features/src/user-data-rights/zip-path.ts +1 -0
- package/packages/bundled-features/src/user-data-rights-defaults/hooks/config-value.userdata-hook.ts +8 -27
- package/packages/bundled-features/src/user-data-rights-defaults/hooks/delivery-attempt.userdata-hook.ts +11 -8
- package/packages/bundled-features/src/user-data-rights-defaults/hooks/forget-own-rows-delete-hook.ts +42 -0
- package/packages/bundled-features/src/user-data-rights-defaults/hooks/notification-preference.userdata-hook.ts +8 -27
- package/packages/bundled-features/src/user-profile/handlers/change-email.write.ts +2 -6
- package/packages/bundled-features/src/user-profile/web/profile-screen.tsx +2 -3
- package/samples/apps/styleguide/src/features/widgets/i18n.ts +6 -0
- package/samples/apps/styleguide/src/features/widgets/web/InboxReaderExamples.tsx +158 -0
- package/samples/apps/styleguide/src/features/widgets/web/Widgets.tsx +2 -0
- package/samples/apps/styleguide/src/features/widgets/web/sample-pdf.ts +28 -0
- package/samples/apps/use-all-bundled/feature-manifest.json +134 -2
- package/samples/apps/use-all-bundled/kumiko/migrations/0063_contact.rebuild.json +4 -0
- package/samples/apps/use-all-bundled/package.json +1 -0
- package/samples/apps/use-all-bundled/playwright.config.ts +2 -0
- package/samples/apps/use-all-bundled/src/app/client.tsx +3 -0
- package/samples/apps/use-all-bundled/src/app/screens-feature.ts +46 -2
- package/samples/apps/use-all-bundled/src/run-config.ts +38 -4
- package/samples/recipes/contact/README.md +46 -0
- package/samples/recipes/contact/package.json +12 -0
- package/samples/recipes/contact/src/feature.ts +27 -0
- package/samples/recipes/delivery-notifications/src/feature.ts +3 -0
- package/samples/recipes/lane-routing/README.md +1 -0
- package/samples/recipes/lane-routing/src/feature.ts +8 -0
- package/samples/recipes/record-detail-layout/src/feature.ts +9 -1
- package/samples/recipes/search/README.md +2 -0
- package/samples/recipes/search/src/feature.ts +27 -2
- package/samples/recipes/secrets-demo/README.md +1 -0
- package/samples/recipes/secrets-demo/src/feature.ts +56 -0
- package/samples/recipes/tenant-inactivity/README.md +21 -0
- package/samples/recipes/tenant-inactivity/package.json +12 -0
|
@@ -8,9 +8,11 @@
|
|
|
8
8
|
import { defineFeature, EXT_USER_DATA } from "@cosmicdrift/kumiko-framework/engine";
|
|
9
9
|
import { formDraftDeleteHook, formDraftExportHook } from "./hooks.ts";
|
|
10
10
|
|
|
11
|
+
// guard:dup-ok feature tooling and guards find features by a literal defineFeature call per feature
|
|
11
12
|
export function createFormDraftUserDataFeature() {
|
|
12
13
|
return defineFeature(
|
|
13
14
|
"form-draft-user-data",
|
|
15
|
+
// guard:dup-ok feature tooling and guards find features by a literal defineFeature call per feature
|
|
14
16
|
(r) => {
|
|
15
17
|
r.describe(
|
|
16
18
|
"GDPR (Art. 20 export / Art. 17 erasure) coverage for the `form-draft` feature's `form-draft` entity. Mounts the EXT_USER_DATA export hook so a user's saved drafts are included in the user-data export bundle, and a delete hook that physically removes the user's own draft rows on forget. Kept separate from `form-draft` so form-draft consumers without the user-data-rights pipeline don't pull a hard dependency — requires `user-data-rights`, optionalRequires `form-draft`.",
|
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"version": "0.409.0",
|
|
4
|
+
"type": "fix",
|
|
5
|
+
"title": "Inbound HTML sanitizer keeps quote markers so the reader can fold quoted text",
|
|
6
|
+
"detail": "The sanitizer stripped class and type attributes, so the reader never found the quote of Gmail, Apple Mail, Thunderbird, Yahoo or Outlook mails. It now keeps blockquote type=\"cite\", the classes gmail_quote, moz-cite-prefix and yahoo_quoted on div and blockquote, and the ids appendonsend and divRplyFwdMsg on div; every other class, id and type is still removed. The reader's HTML quote detection also folds moz-cite-prefix and yahoo_quoted."
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
"version": "0.409.0",
|
|
10
|
+
"type": "improvement",
|
|
11
|
+
"title": "Sanitized HTML body on inbound messages (message.bodyHtml, event version 4)",
|
|
12
|
+
"detail": "ingest-message and attach-message-content run the HTML part of a mail through sanitizeInboundHtml (sanitize-html allowlist for tags, attributes, schemes and style properties; no scripts, forms, on* attributes, cid: or data: images; img src only absolute http(s), a href only absolute http(s), mailto or tel, so nothing resolves against the app origin; links open in a new tab with rel=\"noopener noreferrer\"; empty or over 500,000 bytes of UTF-8 becomes null instead of a cut-off body). Only the sanitized result reaches the event and the projection, PII-encrypted for the tenant like bodyText; the unsanitized original stays in file storage. inbound-message-received and inbound-message-content-fetched are version 4 with bodyHtml (older events upcast to null), the entity message has the new field bodyHtml, and message:content returns bodyHtml (string or null); the message list leaves bodyHtml out like bodyText.",
|
|
13
|
+
"migration": "Run `kumiko-schema generate <name>` in each app that mounts inbound-mail-foundation to get the migration for the new column read_inbound_messages.body_html. Existing messages keep bodyHtml null and show their plain text; nothing else to do."
|
|
14
|
+
},
|
|
2
15
|
{
|
|
3
16
|
"version": "0.402.0",
|
|
4
17
|
"type": "breaking",
|
|
@@ -120,6 +120,8 @@ export const inboundMessageEntity = createEntity({
|
|
|
120
120
|
// Null on rows from before the column; list-messages never selects it.
|
|
121
121
|
bodyText: createLongTextField({ maxLength: 200_000, personal: "tenant", find: "none" }),
|
|
122
122
|
bodyTextTruncated: createBooleanField(),
|
|
123
|
+
// Sanitized HTML of the mail (sanitizeInboundHtml), null when the mail has none or it was too large.
|
|
124
|
+
bodyHtml: createLongTextField({ maxLength: 500_000, personal: "tenant", find: "none" }),
|
|
123
125
|
// Bound to the message (entityType = the aggregate type), so the file guard answers with the
|
|
124
126
|
// mail's visibility. The fileRefs are bound at ingest, the projection copies the ids.
|
|
125
127
|
attachmentFileIds: createFilesField({ personal: false, reason: "technical_reference" }),
|
|
@@ -118,6 +118,8 @@ export const skippedAttachmentSchema = z.object({
|
|
|
118
118
|
const inboundMessageContentShape = {
|
|
119
119
|
bodyText: z.string().max(200_000),
|
|
120
120
|
bodyTextTruncated: z.boolean(),
|
|
121
|
+
/** Sanitized HTML body, PII ciphertext (500_000 characters become roughly 1.2 MB). Null: none or too large. */
|
|
122
|
+
bodyHtml: z.string().max(1_500_000).nullable(),
|
|
121
123
|
/** file-foundation FileRef ids (plaintext uuids). Attachments outlive the mail: apps turn them
|
|
122
124
|
* into documents, so the retention sweep never deletes them. */
|
|
123
125
|
attachmentFileIds: z.array(z.uuid()).max(50),
|
|
@@ -14,8 +14,7 @@
|
|
|
14
14
|
// ingest-message (programmatic, SystemAdmin), account:list +
|
|
15
15
|
// message:list (PII-decrypted; personal mail only for its owner).
|
|
16
16
|
//
|
|
17
|
-
// **Not here:** business semantics (intent, ticket, assignment, read/completed) belong to the
|
|
18
|
-
// app consumer, for example an event job on inbound-message-received with its own projection.
|
|
17
|
+
// **Not here:** business semantics (intent, ticket, assignment, read/completed) belong to the app consumer (e.g. an event job on inbound-message-received).
|
|
19
18
|
//
|
|
20
19
|
// **PII/GDPR:** address/from/to/cc/subject/snippet are `personal: "tenant"`, encrypted BEFORE every
|
|
21
20
|
// event append (the only write path), so event log AND projections carry ciphertext; tenant-destroy
|
|
@@ -142,11 +141,10 @@ export function createInboundMailFoundationFeature(options: InboundMailRoleOptio
|
|
|
142
141
|
version: 2,
|
|
143
142
|
migrations: mailAccountMigrations,
|
|
144
143
|
});
|
|
145
|
-
// v1 mails carry the snippet only
|
|
146
|
-
// refetch find them. v3 adds the reason a message has no content.
|
|
144
|
+
// v1 mails carry the snippet only (contentState "snippet" lets the refetch find them); v3 adds the unavailable reason, v4 the sanitized HTML body.
|
|
147
145
|
r.defineEvent(INBOUND_MESSAGE_RECEIVED_EVENT_SHORT, inboundMessageEventPayloadSchema, {
|
|
148
146
|
piiFields: "none",
|
|
149
|
-
version:
|
|
147
|
+
version: 4,
|
|
150
148
|
migrations: [
|
|
151
149
|
{
|
|
152
150
|
fromVersion: 1,
|
|
@@ -167,6 +165,7 @@ export function createInboundMailFoundationFeature(options: InboundMailRoleOptio
|
|
|
167
165
|
toVersion: 3,
|
|
168
166
|
transform: { default: { contentUnavailableReason: null } },
|
|
169
167
|
},
|
|
168
|
+
{ fromVersion: 3, toVersion: 4, transform: { default: { bodyHtml: null } } },
|
|
170
169
|
],
|
|
171
170
|
});
|
|
172
171
|
r.defineEvent(
|
|
@@ -174,7 +173,7 @@ export function createInboundMailFoundationFeature(options: InboundMailRoleOptio
|
|
|
174
173
|
inboundMessageContentFetchedEventPayloadSchema,
|
|
175
174
|
{
|
|
176
175
|
piiFields: "none",
|
|
177
|
-
version:
|
|
176
|
+
version: 4,
|
|
178
177
|
migrations: [
|
|
179
178
|
{
|
|
180
179
|
fromVersion: 1,
|
|
@@ -186,6 +185,7 @@ export function createInboundMailFoundationFeature(options: InboundMailRoleOptio
|
|
|
186
185
|
toVersion: 3,
|
|
187
186
|
transform: { default: { accountId: null, ownerUserId: null } },
|
|
188
187
|
},
|
|
188
|
+
{ fromVersion: 3, toVersion: 4, transform: { default: { bodyHtml: null } } },
|
|
189
189
|
],
|
|
190
190
|
},
|
|
191
191
|
);
|
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
type InboundMessageContentFetchedEventPayload,
|
|
21
21
|
} from "../events.ts";
|
|
22
22
|
import { inboundMessagesProjectionTable } from "../projection.ts";
|
|
23
|
+
import { sanitizeInboundHtml } from "../sanitize-inbound-html.ts";
|
|
23
24
|
import {
|
|
24
25
|
finalizePreparedContent,
|
|
25
26
|
type PreparedInboundContent,
|
|
@@ -27,6 +28,7 @@ import {
|
|
|
27
28
|
} from "./ingest-message-prepare.ts";
|
|
28
29
|
import {
|
|
29
30
|
contentStateOf,
|
|
31
|
+
encryptMessageBodyHtml,
|
|
30
32
|
encryptMessageBodyText,
|
|
31
33
|
inboundContentPayloadShape,
|
|
32
34
|
MESSAGE_LOCK_NAMESPACE,
|
|
@@ -104,6 +106,11 @@ async function contentEventPayloadOf(
|
|
|
104
106
|
bodyRef: content?.bodyRef ?? "",
|
|
105
107
|
bodyText: await encryptMessageBodyText(tenantId, messageAggId, fetched ? payload.bodyText : ""),
|
|
106
108
|
bodyTextTruncated: fetched && payload.bodyTextTruncated,
|
|
109
|
+
bodyHtml: await encryptMessageBodyHtml(
|
|
110
|
+
tenantId,
|
|
111
|
+
messageAggId,
|
|
112
|
+
fetched && payload.bodyHtml !== undefined ? sanitizeInboundHtml(payload.bodyHtml) : null,
|
|
113
|
+
),
|
|
107
114
|
attachmentFileIds: content?.attachmentFileIds ?? [],
|
|
108
115
|
skippedAttachments: content?.skippedAttachments ?? [],
|
|
109
116
|
contentState: content
|
package/packages/bundled-features/src/inbound-mail-foundation/handlers/ingest-message.write.ts
CHANGED
|
@@ -38,6 +38,7 @@ import {
|
|
|
38
38
|
type InboundMessageEventHeaders,
|
|
39
39
|
type InboundMessageEventPayload,
|
|
40
40
|
} from "../events.ts";
|
|
41
|
+
import { sanitizeInboundHtml } from "../sanitize-inbound-html.ts";
|
|
41
42
|
import {
|
|
42
43
|
finalizePreparedContent,
|
|
43
44
|
type PreparedIngest,
|
|
@@ -145,9 +146,13 @@ export const ingestMessageHandler = defineWriteHandler({
|
|
|
145
146
|
payload.contentUnavailableReason ??
|
|
146
147
|
(content.contentStorage === "unavailable" ? ("no_file_storage" as const) : null);
|
|
147
148
|
const piiKms = configuredPiiSubjectKms();
|
|
149
|
+
// Only the sanitized HTML reaches the event; the unsanitized original stays in the file store.
|
|
150
|
+
const sanitizedHtml =
|
|
151
|
+
payload.bodyHtml === undefined ? null : sanitizeInboundHtml(payload.bodyHtml);
|
|
148
152
|
const messagePlainPii = {
|
|
149
153
|
tenantId,
|
|
150
154
|
bodyText: payload.bodyText,
|
|
155
|
+
bodyHtml: sanitizedHtml,
|
|
151
156
|
from: payload.from,
|
|
152
157
|
to: JSON.stringify(payload.to),
|
|
153
158
|
cc: JSON.stringify(payload.cc),
|
|
@@ -185,6 +190,7 @@ export const ingestMessageHandler = defineWriteHandler({
|
|
|
185
190
|
senderAuthentication: payload.senderAuthentication ?? null,
|
|
186
191
|
bodyText: encryptedMessageFields.bodyText,
|
|
187
192
|
bodyTextTruncated: payload.bodyTextTruncated,
|
|
193
|
+
bodyHtml: encryptedMessageFields.bodyHtml,
|
|
188
194
|
attachmentFileIds: content.attachmentFileIds,
|
|
189
195
|
skippedAttachments: content.skippedAttachments,
|
|
190
196
|
contentState:
|
package/packages/bundled-features/src/inbound-mail-foundation/handlers/list-messages.query.ts
CHANGED
|
@@ -19,7 +19,9 @@ import type { InboundMailRoles } from "../mail-roles.ts";
|
|
|
19
19
|
import { inboundMessagesProjectionTable } from "../projection.ts";
|
|
20
20
|
import { isVisibleToCaller } from "./scope-visibility.ts";
|
|
21
21
|
|
|
22
|
-
// The full text
|
|
22
|
+
// The full text and HTML are delivered only by message:content; selecting them here would decrypt
|
|
23
|
+
// every body of the list, the HTML at up to its event cap per row.
|
|
24
|
+
const LIST_EXCLUDED_BODY_FIELDS: ReadonlySet<string> = new Set(["bodyText", "bodyHtml"]);
|
|
23
25
|
const LIST_MESSAGE_COLUMNS = [
|
|
24
26
|
"id",
|
|
25
27
|
"tenantId",
|
|
@@ -28,7 +30,9 @@ const LIST_MESSAGE_COLUMNS = [
|
|
|
28
30
|
"modifiedAt",
|
|
29
31
|
"insertedById",
|
|
30
32
|
"modifiedById",
|
|
31
|
-
...Object.keys(inboundMessageEntity.fields).filter(
|
|
33
|
+
...Object.keys(inboundMessageEntity.fields).filter(
|
|
34
|
+
(name) => !LIST_EXCLUDED_BODY_FIELDS.has(name),
|
|
35
|
+
),
|
|
32
36
|
];
|
|
33
37
|
|
|
34
38
|
const listMessagesSchema = z
|
package/packages/bundled-features/src/inbound-mail-foundation/handlers/message-content.query.ts
CHANGED
|
@@ -26,6 +26,8 @@ export type InboundMessageContent = {
|
|
|
26
26
|
readonly messageId: string;
|
|
27
27
|
readonly bodyText: string;
|
|
28
28
|
readonly bodyTextTruncated: boolean;
|
|
29
|
+
/** Sanitized HTML, null when the mail has none; readers show bodyText then. */
|
|
30
|
+
readonly bodyHtml: string | null;
|
|
29
31
|
readonly bodyRef: string;
|
|
30
32
|
readonly attachmentFileIds: readonly string[];
|
|
31
33
|
readonly skippedAttachments: readonly SkippedInboundAttachment[];
|
|
@@ -67,6 +69,7 @@ export async function loadInboundMessageContent(
|
|
|
67
69
|
messageId,
|
|
68
70
|
bodyText: typeof bodyText === "string" ? bodyText : "",
|
|
69
71
|
bodyTextTruncated: row["bodyTextTruncated"] === true,
|
|
72
|
+
bodyHtml: typeof readable["bodyHtml"] === "string" ? readable["bodyHtml"] : null,
|
|
70
73
|
bodyRef: typeof row["bodyRef"] === "string" ? row["bodyRef"] : "",
|
|
71
74
|
attachmentFileIds: fileIdsSchema.parse(row["attachmentFileIds"] ?? []),
|
|
72
75
|
skippedAttachments: parseJsonColumn(row["skippedAttachments"], skippedListSchema, []),
|
|
@@ -219,6 +219,25 @@ export async function encryptMessageBodyText(
|
|
|
219
219
|
return encrypted.bodyText;
|
|
220
220
|
}
|
|
221
221
|
|
|
222
|
+
// Same, for the sanitized HTML body (null stays null: nothing to encrypt).
|
|
223
|
+
export async function encryptMessageBodyHtml(
|
|
224
|
+
tenantId: string,
|
|
225
|
+
messageAggId: string,
|
|
226
|
+
bodyHtml: string | null,
|
|
227
|
+
): Promise<string | null> {
|
|
228
|
+
const piiKms = configuredPiiSubjectKms();
|
|
229
|
+
if (!piiKms || bodyHtml === null) return bodyHtml;
|
|
230
|
+
const encrypted = await encryptPiiFieldValues(
|
|
231
|
+
{ tenantId, bodyHtml },
|
|
232
|
+
inboundMessageEntity,
|
|
233
|
+
INBOUND_MESSAGE_PII_FIELDS,
|
|
234
|
+
piiKms,
|
|
235
|
+
{ requestId: `inbound-mail-foundation:message-content:${messageAggId}`, tenantId },
|
|
236
|
+
{ tenantId, entityName: INBOUND_MESSAGE_AGGREGATE_TYPE },
|
|
237
|
+
);
|
|
238
|
+
return encrypted.bodyHtml;
|
|
239
|
+
}
|
|
240
|
+
|
|
222
241
|
export function contentStateOf(args: {
|
|
223
242
|
readonly bodyText: string;
|
|
224
243
|
readonly hasOriginal: boolean;
|
|
@@ -130,6 +130,7 @@ export const applyInboundMessageReceived = defineApply<InboundMessageEventPayloa
|
|
|
130
130
|
scope: p.scope,
|
|
131
131
|
bodyText: p.bodyText,
|
|
132
132
|
bodyTextTruncated: p.bodyTextTruncated,
|
|
133
|
+
bodyHtml: p.bodyHtml,
|
|
133
134
|
attachmentFileIds: p.attachmentFileIds,
|
|
134
135
|
skippedAttachments: JSON.stringify(p.skippedAttachments),
|
|
135
136
|
senderAuthentication: JSON.stringify(p.senderAuthentication),
|
|
@@ -150,6 +151,7 @@ export const applyInboundMessageContentFetched =
|
|
|
150
151
|
bodyRef: p.bodyRef,
|
|
151
152
|
bodyText: p.bodyText,
|
|
152
153
|
bodyTextTruncated: p.bodyTextTruncated,
|
|
154
|
+
bodyHtml: p.bodyHtml,
|
|
153
155
|
attachmentFileIds: p.attachmentFileIds,
|
|
154
156
|
skippedAttachments: JSON.stringify(p.skippedAttachments),
|
|
155
157
|
contentState: p.contentState,
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
// Allowlist sanitizer for the HTML part of an inbound mail. The result is stored in the event and
|
|
2
|
+
// shown by the reader inside a script-free sandboxed iframe; this is the first of the two layers.
|
|
3
|
+
|
|
4
|
+
import sanitizeHtml from "sanitize-html";
|
|
5
|
+
|
|
6
|
+
// Counted in UTF-8 bytes, not characters: the ciphertext grows with the bytes, and a CJK or emoji
|
|
7
|
+
// mail of 500,000 characters would encrypt past the event's bodyHtml maximum.
|
|
8
|
+
export const BODY_HTML_MAX_BYTES = 500_000;
|
|
9
|
+
|
|
10
|
+
const ALLOWED_TAGS = [
|
|
11
|
+
"p",
|
|
12
|
+
"br",
|
|
13
|
+
"div",
|
|
14
|
+
"span",
|
|
15
|
+
"a",
|
|
16
|
+
"b",
|
|
17
|
+
"strong",
|
|
18
|
+
"i",
|
|
19
|
+
"em",
|
|
20
|
+
"u",
|
|
21
|
+
"s",
|
|
22
|
+
"sub",
|
|
23
|
+
"sup",
|
|
24
|
+
"blockquote",
|
|
25
|
+
"pre",
|
|
26
|
+
"code",
|
|
27
|
+
"ul",
|
|
28
|
+
"ol",
|
|
29
|
+
"li",
|
|
30
|
+
"h1",
|
|
31
|
+
"h2",
|
|
32
|
+
"h3",
|
|
33
|
+
"h4",
|
|
34
|
+
"h5",
|
|
35
|
+
"h6",
|
|
36
|
+
"table",
|
|
37
|
+
"thead",
|
|
38
|
+
"tbody",
|
|
39
|
+
"tfoot",
|
|
40
|
+
"tr",
|
|
41
|
+
"td",
|
|
42
|
+
"th",
|
|
43
|
+
"img",
|
|
44
|
+
"hr",
|
|
45
|
+
"font",
|
|
46
|
+
"center",
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
const ALLOWED_ATTRIBUTES: Record<string, string[]> = {
|
|
50
|
+
a: ["href", "title", "target", "rel"],
|
|
51
|
+
img: ["src", "alt", "width", "height"],
|
|
52
|
+
td: ["colspan", "rowspan", "align", "valign", "width"],
|
|
53
|
+
th: ["colspan", "rowspan", "align", "valign", "width"],
|
|
54
|
+
table: ["width", "cellpadding", "cellspacing", "border", "align"],
|
|
55
|
+
font: ["color", "size"],
|
|
56
|
+
div: ["class", "id"],
|
|
57
|
+
blockquote: ["class", "type"],
|
|
58
|
+
"*": ["style", "dir", "align"],
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
// Exactly the markers the reader's quote folding looks for (Gmail, Apple Mail, Thunderbird, Yahoo, Outlook).
|
|
62
|
+
const QUOTE_CLASS_NAMES = ["gmail_quote", "moz-cite-prefix", "yahoo_quoted"];
|
|
63
|
+
const QUOTE_ELEMENT_IDS = new Set(["divRplyFwdMsg", "appendonsend"]);
|
|
64
|
+
|
|
65
|
+
// A style value may carry a remote load (url(), @import) or legacy script (expression()).
|
|
66
|
+
const SAFE_STYLE_VALUE = /^(?!.*(?:url\s*\(|expression|@import|javascript:)).*$/i;
|
|
67
|
+
const STYLE_PROPERTIES = [
|
|
68
|
+
"color",
|
|
69
|
+
"background-color",
|
|
70
|
+
"font-weight",
|
|
71
|
+
"font-style",
|
|
72
|
+
"font-size",
|
|
73
|
+
"font-family",
|
|
74
|
+
"text-decoration",
|
|
75
|
+
"text-align",
|
|
76
|
+
"line-height",
|
|
77
|
+
"width",
|
|
78
|
+
"max-width",
|
|
79
|
+
"vertical-align",
|
|
80
|
+
...["padding", "margin", "border"].flatMap((base) => [
|
|
81
|
+
base,
|
|
82
|
+
`${base}-top`,
|
|
83
|
+
`${base}-right`,
|
|
84
|
+
`${base}-bottom`,
|
|
85
|
+
`${base}-left`,
|
|
86
|
+
]),
|
|
87
|
+
];
|
|
88
|
+
|
|
89
|
+
const ALLOWED_STYLES: Record<string, RegExp[]> = Object.fromEntries(
|
|
90
|
+
STYLE_PROPERTIES.map((property) => [property, [SAFE_STYLE_VALUE]]),
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
// Relative, protocol-relative and backslash URLs would resolve against the app origin in the srcdoc frame
|
|
94
|
+
// and send a cookie-carrying same-origin request, so only absolute targets are kept.
|
|
95
|
+
const ABSOLUTE_IMAGE_SRC = /^https?:\/\//i;
|
|
96
|
+
const ABSOLUTE_LINK_HREF = /^(?:https?:\/\/|mailto:|tel:)/i;
|
|
97
|
+
|
|
98
|
+
function withoutAttributeUnless(
|
|
99
|
+
attribs: Record<string, string>,
|
|
100
|
+
name: string,
|
|
101
|
+
allowed: RegExp,
|
|
102
|
+
): Record<string, string> {
|
|
103
|
+
const value = attribs[name];
|
|
104
|
+
if (value === undefined || allowed.test(value.trim())) return attribs;
|
|
105
|
+
const { [name]: _dropped, ...rest } = attribs;
|
|
106
|
+
return rest;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function withoutIdUnlessQuoteMarker(attribs: Record<string, string>): Record<string, string> {
|
|
110
|
+
const id = attribs["id"];
|
|
111
|
+
if (id === undefined || QUOTE_ELEMENT_IDS.has(id.trim())) return attribs;
|
|
112
|
+
const { id: _dropped, ...rest } = attribs;
|
|
113
|
+
return rest;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export function sanitizeInboundHtml(html: string): string | null {
|
|
117
|
+
const clean = sanitizeHtml(html, {
|
|
118
|
+
allowedTags: ALLOWED_TAGS,
|
|
119
|
+
allowedAttributes: ALLOWED_ATTRIBUTES,
|
|
120
|
+
allowedStyles: { "*": ALLOWED_STYLES },
|
|
121
|
+
allowedClasses: { div: QUOTE_CLASS_NAMES, blockquote: QUOTE_CLASS_NAMES },
|
|
122
|
+
allowedSchemes: ["http", "https", "mailto", "tel"],
|
|
123
|
+
allowedSchemesByTag: { img: ["http", "https"] },
|
|
124
|
+
allowProtocolRelative: false,
|
|
125
|
+
transformTags: {
|
|
126
|
+
div: (tagName, attribs) => ({ tagName, attribs: withoutIdUnlessQuoteMarker(attribs) }),
|
|
127
|
+
blockquote: (tagName, attribs) => ({
|
|
128
|
+
tagName,
|
|
129
|
+
attribs: withoutAttributeUnless(attribs, "type", /^cite$/),
|
|
130
|
+
}),
|
|
131
|
+
a: (tagName, attribs) => ({
|
|
132
|
+
tagName,
|
|
133
|
+
attribs: {
|
|
134
|
+
...withoutAttributeUnless(attribs, "href", ABSOLUTE_LINK_HREF),
|
|
135
|
+
target: "_blank",
|
|
136
|
+
rel: "noopener noreferrer",
|
|
137
|
+
},
|
|
138
|
+
}),
|
|
139
|
+
img: (tagName, attribs) => ({
|
|
140
|
+
tagName,
|
|
141
|
+
attribs: withoutAttributeUnless(attribs, "src", ABSOLUTE_IMAGE_SRC),
|
|
142
|
+
}),
|
|
143
|
+
},
|
|
144
|
+
// An image whose src was stripped (cid:, data:, other scheme) is only a broken placeholder.
|
|
145
|
+
exclusiveFilter: (frame) => frame.tag === "img" && frame.attribs["src"] === undefined,
|
|
146
|
+
}).trim();
|
|
147
|
+
return clean.length === 0 || Buffer.byteLength(clean, "utf8") > BODY_HTML_MAX_BYTES
|
|
148
|
+
? null
|
|
149
|
+
: clean;
|
|
150
|
+
}
|
|
@@ -246,6 +246,7 @@ export type InboundMailProviderPlugin = {
|
|
|
246
246
|
// `options` in the extension usage is an engine payload (unknown), so
|
|
247
247
|
// validate its structure instead of casting blindly (patterned after
|
|
248
248
|
// isMailTransportPlugin).
|
|
249
|
+
// guard:dup-ok type guard over this plugin's own two members; only the guard shape is shared
|
|
249
250
|
export function isInboundMailProviderPlugin(o: unknown): o is InboundMailProviderPlugin {
|
|
250
251
|
return (
|
|
251
252
|
typeof o === "object" &&
|
|
@@ -455,25 +455,20 @@ async function dropTenantRunQueued(
|
|
|
455
455
|
|
|
456
456
|
const log = createFallbackLogger("job-run-logger");
|
|
457
457
|
|
|
458
|
-
|
|
459
|
-
// fail the enqueue, skip the run-row write or turn a completed run into a
|
|
460
|
-
// BullMQ retry. A row-level-security rejection is logged louder (a missing or wrong tenant scope), never rethrown.
|
|
461
|
-
export async function isolateTenantRunWrite(
|
|
458
|
+
async function isolateTenantWrite(
|
|
462
459
|
write: () => Promise<void>,
|
|
463
460
|
jobName: string,
|
|
464
461
|
bullJobId: string,
|
|
462
|
+
messages: { readonly rejected: string; readonly failed: string },
|
|
465
463
|
): Promise<void> {
|
|
466
464
|
try {
|
|
467
465
|
await write();
|
|
468
466
|
} catch (e) {
|
|
469
467
|
if (isRowLevelSecurityViolation(e)) {
|
|
470
|
-
log.error(
|
|
471
|
-
"tenant job run state write rejected by row level security: missing or wrong tenant scope",
|
|
472
|
-
{ jobName, bullJobId },
|
|
473
|
-
);
|
|
468
|
+
log.error(messages.rejected, { jobName, bullJobId });
|
|
474
469
|
return;
|
|
475
470
|
}
|
|
476
|
-
log.error(
|
|
471
|
+
log.error(messages.failed, {
|
|
477
472
|
jobName,
|
|
478
473
|
bullJobId,
|
|
479
474
|
error: e instanceof Error ? e.message : String(e),
|
|
@@ -481,6 +476,21 @@ export async function isolateTenantRunWrite(
|
|
|
481
476
|
}
|
|
482
477
|
}
|
|
483
478
|
|
|
479
|
+
// The tenant run state is an optional side write: a throw here must not
|
|
480
|
+
// fail the enqueue, skip the run-row write or turn a completed run into a
|
|
481
|
+
// BullMQ retry. A row-level-security rejection is logged louder (a missing or wrong tenant scope), never rethrown.
|
|
482
|
+
export async function isolateTenantRunWrite(
|
|
483
|
+
write: () => Promise<void>,
|
|
484
|
+
jobName: string,
|
|
485
|
+
bullJobId: string,
|
|
486
|
+
): Promise<void> {
|
|
487
|
+
await isolateTenantWrite(write, jobName, bullJobId, {
|
|
488
|
+
rejected:
|
|
489
|
+
"tenant job run state write rejected by row level security: missing or wrong tenant scope",
|
|
490
|
+
failed: "tenant job run state write failed",
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
|
|
484
494
|
// The tenant failure record is an optional side write: a throw here must not
|
|
485
495
|
// skip the run-row update or turn a completed run into a BullMQ retry. A row-level-security rejection is
|
|
486
496
|
// logged louder (a missing or wrong tenant scope), never rethrown.
|
|
@@ -489,22 +499,11 @@ async function isolateTenantFailureWrite(
|
|
|
489
499
|
jobName: string,
|
|
490
500
|
bullJobId: string,
|
|
491
501
|
): Promise<void> {
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
"tenant job failure record write rejected by row level security: missing or wrong tenant scope",
|
|
498
|
-
{ jobName, bullJobId },
|
|
499
|
-
);
|
|
500
|
-
return;
|
|
501
|
-
}
|
|
502
|
-
log.error("tenant job failure record write failed", {
|
|
503
|
-
jobName,
|
|
504
|
-
bullJobId,
|
|
505
|
-
error: e instanceof Error ? e.message : String(e),
|
|
506
|
-
});
|
|
507
|
-
}
|
|
502
|
+
await isolateTenantWrite(write, jobName, bullJobId, {
|
|
503
|
+
rejected:
|
|
504
|
+
"tenant job failure record write rejected by row level security: missing or wrong tenant scope",
|
|
505
|
+
failed: "tenant job failure record write failed",
|
|
506
|
+
});
|
|
508
507
|
}
|
|
509
508
|
|
|
510
509
|
export function createJobRunLogger(opts: JobRunLoggerOptions): JobRunLoggerCallbacks {
|
|
@@ -29,56 +29,71 @@ async function loadBooks(
|
|
|
29
29
|
return { accounts: toAccounts(accountRows), entries: toEntries(txRows) };
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
type ReportPeriod = z.infer<typeof periodSchema>;
|
|
33
|
+
|
|
34
|
+
function createPeriodReportHandler(
|
|
35
|
+
report: {
|
|
36
|
+
readonly name: string;
|
|
37
|
+
readonly description: string;
|
|
38
|
+
readonly compute: (
|
|
39
|
+
accounts: LedgerAccount[],
|
|
40
|
+
entries: LedgerEntry[],
|
|
41
|
+
period: ReportPeriod,
|
|
42
|
+
) => unknown;
|
|
43
|
+
},
|
|
44
|
+
access: AccessRule,
|
|
35
45
|
): QueryHandlerDef {
|
|
36
46
|
return {
|
|
37
|
-
name:
|
|
47
|
+
name: report.name,
|
|
38
48
|
schema: periodSchema,
|
|
39
49
|
access,
|
|
40
|
-
description:
|
|
41
|
-
"Returns the per-account balance in its natural sign plus the trial balance over an optional from/to period; use it for a trial balance or to read one account's standing.",
|
|
50
|
+
description: report.description,
|
|
42
51
|
handler: async (query, ctx) => {
|
|
43
52
|
const period = periodSchema.parse(query);
|
|
44
53
|
const { accounts, entries } = await loadBooks(ctx);
|
|
45
|
-
return
|
|
54
|
+
return report.compute(accounts, entries, period);
|
|
46
55
|
},
|
|
47
56
|
};
|
|
48
57
|
}
|
|
49
58
|
|
|
59
|
+
const BALANCES_REPORT = {
|
|
60
|
+
name: "report:balances",
|
|
61
|
+
description:
|
|
62
|
+
"Returns the per-account balance in its natural sign plus the trial balance over an optional from/to period; use it for a trial balance or to read one account's standing.",
|
|
63
|
+
compute: accountBalances,
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const INCOME_STATEMENT_REPORT = {
|
|
67
|
+
name: "report:income-statement",
|
|
68
|
+
description:
|
|
69
|
+
"Returns income minus expense over an optional from/to period; use it for a profit-and-loss statement.",
|
|
70
|
+
compute: incomeStatement,
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const BALANCE_SHEET_REPORT = {
|
|
74
|
+
name: "report:balance-sheet",
|
|
75
|
+
description:
|
|
76
|
+
"Returns assets, liabilities and equity as of the optional `to` date with the period result folded into equity so the sheet balances; use it for a balance sheet at a point in time.",
|
|
77
|
+
compute: balanceSheet,
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
// Per-account balances (natural sign) + the trial balance (Σ raw = 0 invariant).
|
|
81
|
+
export function createBalancesReportHandler(
|
|
82
|
+
access: AccessRule = DEFAULT_LEDGER_ACCESS,
|
|
83
|
+
): QueryHandlerDef {
|
|
84
|
+
return createPeriodReportHandler(BALANCES_REPORT, access);
|
|
85
|
+
}
|
|
86
|
+
|
|
50
87
|
// GuV — income − expense over the period.
|
|
51
88
|
export function createIncomeStatementHandler(
|
|
52
89
|
access: AccessRule = DEFAULT_LEDGER_ACCESS,
|
|
53
90
|
): QueryHandlerDef {
|
|
54
|
-
return
|
|
55
|
-
name: "report:income-statement",
|
|
56
|
-
schema: periodSchema,
|
|
57
|
-
access,
|
|
58
|
-
description:
|
|
59
|
-
"Returns income minus expense over an optional from/to period; use it for a profit-and-loss statement.",
|
|
60
|
-
handler: async (query, ctx) => {
|
|
61
|
-
const period = periodSchema.parse(query);
|
|
62
|
-
const { accounts, entries } = await loadBooks(ctx);
|
|
63
|
-
return incomeStatement(accounts, entries, period);
|
|
64
|
-
},
|
|
65
|
-
};
|
|
91
|
+
return createPeriodReportHandler(INCOME_STATEMENT_REPORT, access);
|
|
66
92
|
}
|
|
67
93
|
|
|
68
94
|
// Bilanz as of `to` — current result folded into equity so it balances.
|
|
69
95
|
export function createBalanceSheetHandler(
|
|
70
96
|
access: AccessRule = DEFAULT_LEDGER_ACCESS,
|
|
71
97
|
): QueryHandlerDef {
|
|
72
|
-
return
|
|
73
|
-
name: "report:balance-sheet",
|
|
74
|
-
schema: periodSchema,
|
|
75
|
-
access,
|
|
76
|
-
description:
|
|
77
|
-
"Returns assets, liabilities and equity as of the optional `to` date with the period result folded into equity so the sheet balances; use it for a balance sheet at a point in time.",
|
|
78
|
-
handler: async (query, ctx) => {
|
|
79
|
-
const period = periodSchema.parse(query);
|
|
80
|
-
const { accounts, entries } = await loadBooks(ctx);
|
|
81
|
-
return balanceSheet(accounts, entries, period);
|
|
82
|
-
},
|
|
83
|
-
};
|
|
98
|
+
return createPeriodReportHandler(BALANCE_SHEET_REPORT, access);
|
|
84
99
|
}
|
|
@@ -79,6 +79,7 @@ function monthIndex(ym: string): number {
|
|
|
79
79
|
return Number(y) * 12 + (Number(m) - 1);
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
+
// guard:dup-ok ledger month key YYYY-MM; look-alike month-index helpers return other formats
|
|
82
83
|
function indexToMonth(index: number): string {
|
|
83
84
|
const year = Math.floor(index / 12);
|
|
84
85
|
const month = (index % 12) + 1;
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
import {
|
|
14
14
|
formatWhen,
|
|
15
15
|
useDispatcher,
|
|
16
|
+
useLocale,
|
|
16
17
|
usePrimitives,
|
|
17
18
|
useQuery,
|
|
18
19
|
useTranslation,
|
|
@@ -49,6 +50,7 @@ export function NotesSection({
|
|
|
49
50
|
}): ReactNode {
|
|
50
51
|
const { Banner, Button, Grid, Heading, Text, Input } = usePrimitives();
|
|
51
52
|
const t = useTranslation();
|
|
53
|
+
const locale = useLocale().locale();
|
|
52
54
|
const dispatcher = useDispatcher();
|
|
53
55
|
const enabled = entityId !== null;
|
|
54
56
|
const notes = useQuery<NoteListResponse>(
|
|
@@ -176,7 +178,7 @@ export function NotesSection({
|
|
|
176
178
|
n.authorName,
|
|
177
179
|
t("notesHistory.section.authorUnknown"),
|
|
178
180
|
),
|
|
179
|
-
date: formatWhen(n.insertedAt),
|
|
181
|
+
date: formatWhen(n.insertedAt, locale),
|
|
180
182
|
})}
|
|
181
183
|
</Text>
|
|
182
184
|
</div>
|