@cosmicdrift/kumiko-samples 0.413.1 → 0.415.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 +16 -1
- package/packages/bundled-features/src/admin-shell/changes.json +6 -0
- package/packages/bundled-features/src/admin-shell/feature.ts +8 -7
- package/packages/bundled-features/src/agent-tools/agent-doc-lint.ts +5 -1
- package/packages/bundled-features/src/agent-tools/agent-manifest.ts +36 -27
- package/packages/bundled-features/src/agent-tools/api-docs/collect-events.ts +8 -1
- package/packages/bundled-features/src/agent-tools/api-docs/collect.ts +3 -2
- package/packages/bundled-features/src/agent-tools/api-docs/generate.ts +6 -0
- package/packages/bundled-features/src/agent-tools/api-docs/index.ts +1 -0
- package/packages/bundled-features/src/agent-tools/api-docs/problems.ts +38 -1
- package/packages/bundled-features/src/agent-tools/api-docs/render-openapi.ts +1 -0
- package/packages/bundled-features/src/agent-tools/api-docs/resolve-config.ts +17 -0
- package/packages/bundled-features/src/agent-tools/api-docs/scope-slug-collisions.ts +17 -0
- package/packages/bundled-features/src/agent-tools/api-docs/translation-gaps.ts +42 -0
- package/packages/bundled-features/src/agent-tools/api-docs/webhook-example-problems.ts +30 -0
- package/packages/bundled-features/src/agent-tools/changes.json +12 -0
- package/packages/bundled-features/src/agent-tools/index.ts +1 -0
- package/packages/bundled-features/src/agent-tools/labels.ts +19 -6
- package/packages/bundled-features/src/agent-tools/tool-catalog.ts +18 -7
- package/packages/bundled-features/src/agent-tools/tool-dispatch.ts +14 -1
- package/packages/bundled-features/src/agent-tools/types.ts +4 -0
- package/packages/bundled-features/src/audit/event-classification.ts +6 -0
- package/packages/bundled-features/src/audit/web/i18n.ts +1 -0
- package/packages/bundled-features/src/auth-email-password/changes.json +18 -0
- package/packages/bundled-features/src/auth-email-password/errors.ts +0 -13
- package/packages/bundled-features/src/auth-email-password/handlers/invite-signup-complete.write.ts +147 -121
- package/packages/bundled-features/src/auth-email-password/handlers/login-options.query.ts +1 -1
- package/packages/bundled-features/src/auth-email-password/handlers/request-account-unlock.write.ts +1 -1
- package/packages/bundled-features/src/auth-email-password/handlers/request-email-verification.write.ts +0 -1
- package/packages/bundled-features/src/auth-email-password/handlers/request-password-reset.write.ts +0 -1
- package/packages/bundled-features/src/auth-email-password/handlers/self-registration-status.query.ts +1 -1
- package/packages/bundled-features/src/auth-email-password/reset-token.ts +0 -2
- package/packages/bundled-features/src/auth-email-password/seeding.ts +39 -7
- package/packages/bundled-features/src/auth-email-password/signup-token-store.ts +2 -3
- package/packages/bundled-features/src/auth-email-password/unlock-token.ts +0 -2
- package/packages/bundled-features/src/auth-email-password/verification-token.ts +0 -2
- package/packages/bundled-features/src/auth-email-password/web/auth-form-primitives.tsx +2 -2
- package/packages/bundled-features/src/auth-email-password/web/auth-gate.tsx +2 -2
- package/packages/bundled-features/src/auth-email-password/web/auth-redirect.ts +5 -0
- package/packages/bundled-features/src/auth-email-password/web/forgot-password-screen.tsx +1 -6
- package/packages/bundled-features/src/auth-email-password/web/invite-accept-screen.tsx +1 -1
- package/packages/bundled-features/src/auth-email-password/web/return-path.ts +2 -1
- package/packages/bundled-features/src/auth-email-password/web/session.tsx +12 -13
- package/packages/bundled-features/src/auth-email-password/web/signup-screen.tsx +1 -6
- package/packages/bundled-features/src/auth-email-password/web/static-account.ts +6 -1
- package/packages/bundled-features/src/auth-email-password/web/tenant-switcher.tsx +1 -1
- package/packages/bundled-features/src/auth-email-password/web/token-confirm-screen.tsx +4 -5
- package/packages/bundled-features/src/auth-email-password/web/user-menu.tsx +1 -1
- package/packages/bundled-features/src/auth-mfa/changes.json +6 -0
- package/packages/bundled-features/src/auth-mfa/web/mfa-code-or-recovery-field.tsx +17 -1
- package/packages/bundled-features/src/auth-mfa/web/mfa-disable-dialog.tsx +1 -1
- package/packages/bundled-features/src/auth-mfa/web/mfa-regenerate-recovery-dialog.tsx +1 -1
- package/packages/bundled-features/src/auth-mfa/web/mfa-setup-preauth-screen.tsx +1 -1
- package/packages/bundled-features/src/auth-mfa/web/mfa-verify-screen.tsx +16 -47
- package/packages/bundled-features/src/auth-mfa-user-data/index.ts +5 -6
- package/packages/bundled-features/src/billing-foundation/aggregate-id.ts +0 -4
- package/packages/bundled-features/src/billing-foundation/changes.json +61 -0
- package/packages/bundled-features/src/billing-foundation/checkout-core.ts +19 -1
- package/packages/bundled-features/src/billing-foundation/checkout-ledger.ts +67 -0
- package/packages/bundled-features/src/billing-foundation/consumer-protection/consent-gate.ts +2 -1
- package/packages/bundled-features/src/billing-foundation/consumer-protection/consent-text.ts +49 -2
- package/packages/bundled-features/src/billing-foundation/consumer-protection/termination-open-cancels.ts +5 -0
- package/packages/bundled-features/src/billing-foundation/consumer-protection/termination-provider-timeout.ts +23 -0
- package/packages/bundled-features/src/billing-foundation/consumer-protection/termination-record.ts +12 -7
- package/packages/bundled-features/src/billing-foundation/consumer-protection/termination-revoke.ts +1 -1
- package/packages/bundled-features/src/billing-foundation/events.ts +51 -10
- package/packages/bundled-features/src/billing-foundation/feature.ts +15 -1
- package/packages/bundled-features/src/billing-foundation/handlers/billing-plans.query.ts +47 -14
- package/packages/bundled-features/src/billing-foundation/handlers/create-checkout-session.write.ts +9 -1
- package/packages/bundled-features/src/billing-foundation/handlers/process-event.write.ts +183 -17
- package/packages/bundled-features/src/billing-foundation/handlers/process-payment-event.write.ts +35 -10
- package/packages/bundled-features/src/billing-foundation/handlers/record-checkout-opened.write.ts +25 -0
- package/packages/bundled-features/src/billing-foundation/handlers/start-plan-checkout.write.ts +9 -1
- package/packages/bundled-features/src/billing-foundation/handlers/switch-plan.write.ts +16 -4
- package/packages/bundled-features/src/billing-foundation/i18n.ts +3 -0
- package/packages/bundled-features/src/billing-foundation/pending-plan-switch.ts +80 -0
- package/packages/bundled-features/src/billing-foundation/scrub-raw-payload-headers.ts +50 -0
- package/packages/bundled-features/src/billing-foundation/types.ts +47 -30
- package/packages/bundled-features/src/billing-foundation/validate-options.ts +18 -0
- package/packages/bundled-features/src/billing-foundation/web/billing-plans-panel.tsx +10 -5
- package/packages/bundled-features/src/billing-foundation/web/cancel-contract-dialog.tsx +1 -1
- package/packages/bundled-features/src/billing-foundation/web/checkout-consent-dialog.tsx +1 -1
- package/packages/bundled-features/src/billing-foundation/web/constants.ts +5 -2
- package/packages/bundled-features/src/billing-foundation/web/plan-switch-confirm-dialog.tsx +1 -1
- package/packages/bundled-features/src/billing-foundation/webhook-handler.ts +65 -17
- package/packages/bundled-features/src/cap-counter/aggregate-id.ts +0 -2
- package/packages/bundled-features/src/cap-counter/changes.json +6 -0
- package/packages/bundled-features/src/cap-counter/stock-cap-guard.ts +19 -4
- package/packages/bundled-features/src/cap-overview/changes.json +6 -0
- package/packages/bundled-features/src/cap-overview/handlers/tenant-caps-list.query.ts +22 -6
- package/packages/bundled-features/src/cap-overview/i18n.ts +1 -0
- package/packages/bundled-features/src/cap-overview/index.ts +1 -0
- package/packages/bundled-features/src/cap-overview/types.ts +11 -1
- package/packages/bundled-features/src/cap-overview/web/cap-cards-panel.tsx +6 -2
- package/packages/bundled-features/src/cap-overview/web/cap-usage-bar.tsx +10 -1
- package/packages/bundled-features/src/cap-overview/web/usage-math.ts +5 -0
- package/packages/bundled-features/src/channel-in-app/changes.json +6 -0
- package/packages/bundled-features/src/channel-in-app/handlers/read-state-by-keys.query.ts +2 -2
- package/packages/bundled-features/src/channel-whatsapp/aggregate-id.ts +29 -0
- package/packages/bundled-features/src/channel-whatsapp/changes.json +32 -0
- package/packages/bundled-features/src/channel-whatsapp/constants.ts +46 -0
- package/packages/bundled-features/src/channel-whatsapp/events.ts +94 -0
- package/packages/bundled-features/src/channel-whatsapp/feature.ts +72 -0
- package/packages/bundled-features/src/channel-whatsapp/graph-client.ts +398 -0
- package/packages/bundled-features/src/channel-whatsapp/in-memory-meta.ts +300 -0
- package/packages/bundled-features/src/channel-whatsapp/inbound-handlers.ts +210 -0
- package/packages/bundled-features/src/channel-whatsapp/index.ts +66 -0
- package/packages/bundled-features/src/channel-whatsapp/meta-signature.ts +26 -0
- package/packages/bundled-features/src/channel-whatsapp/options.ts +149 -0
- package/packages/bundled-features/src/channel-whatsapp/pii.ts +109 -0
- package/packages/bundled-features/src/channel-whatsapp/webhook-normalize.ts +247 -0
- package/packages/bundled-features/src/channel-whatsapp/webhook-routes.ts +185 -0
- package/packages/bundled-features/src/compliance-profiles/changes.json +5 -0
- package/packages/bundled-features/src/compliance-profiles/handlers/set-profile.write.ts +2 -0
- package/packages/bundled-features/src/compliance-profiles/handlers/sub-processors.query.ts +1 -1
- package/packages/bundled-features/src/config/changes.json +12 -0
- package/packages/bundled-features/src/config/handlers/set.write.ts +7 -0
- package/packages/bundled-features/src/config/handlers/values.query.ts +8 -1
- package/packages/bundled-features/src/config/index.ts +1 -0
- package/packages/bundled-features/src/config/read-redaction.ts +6 -3
- package/packages/bundled-features/src/config/table.ts +1 -0
- package/packages/bundled-features/src/config/write-helpers.ts +3 -2
- package/packages/bundled-features/src/crypto-shredding/changes.json +18 -0
- package/packages/bundled-features/src/crypto-shredding/constants.ts +2 -0
- package/packages/bundled-features/src/crypto-shredding/handlers/forget-subject.write.ts +38 -18
- package/packages/bundled-features/src/crypto-shredding/index.ts +4 -0
- package/packages/bundled-features/src/crypto-shredding/subject-forget-after-delete-hook.ts +49 -0
- package/packages/bundled-features/src/custom-fields/aggregate-id.ts +0 -1
- package/packages/bundled-features/src/custom-fields/entity.ts +1 -0
- package/packages/bundled-features/src/custom-fields/wire-for-entity.ts +0 -1
- package/packages/bundled-features/src/data-retention/changes.json +12 -0
- package/packages/bundled-features/src/data-retention/erase-notes-of-deleted-row.ts +23 -0
- package/packages/bundled-features/src/data-retention/feature.ts +2 -5
- package/packages/bundled-features/src/data-retention/run-retention-cleanup.ts +38 -18
- package/packages/bundled-features/src/data-retention/tenant-destruction-hold.ts +9 -0
- package/packages/bundled-features/src/delivery/attempt-log-factory.ts +11 -0
- package/packages/bundled-features/src/delivery/attempt-log.ts +3 -3
- package/packages/bundled-features/src/delivery/changes.json +12 -0
- package/packages/bundled-features/src/delivery/channel-context.ts +6 -3
- package/packages/bundled-features/src/delivery/db/queries/preferences.ts +0 -1
- package/packages/bundled-features/src/delivery/delivery-service.ts +3 -0
- package/packages/bundled-features/src/delivery/feature.ts +4 -13
- package/packages/bundled-features/src/delivery/handlers/opted-in-user-ids.query.ts +54 -0
- package/packages/bundled-features/src/delivery/handlers/preferences.query.ts +2 -20
- package/packages/bundled-features/src/delivery/handlers/resubscribe-user.write.ts +2 -25
- package/packages/bundled-features/src/delivery/handlers/unsubscribe-page-chrome.query.ts +2 -0
- package/packages/bundled-features/src/delivery/handlers/unsubscribe-user.write.ts +2 -27
- package/packages/bundled-features/src/delivery/index.ts +3 -1
- package/packages/bundled-features/src/delivery/options.ts +11 -0
- package/packages/bundled-features/src/delivery/preference-rows.ts +33 -0
- package/packages/bundled-features/src/delivery/set-preference-enabled.ts +40 -0
- package/packages/bundled-features/src/delivery/testing.ts +3 -1
- package/packages/bundled-features/src/delivery/types.ts +1 -0
- package/packages/bundled-features/src/delivery/unsubscribe-page.ts +7 -1
- package/packages/bundled-features/src/delivery/upsert-preference.ts +0 -1
- package/packages/bundled-features/src/delivery/web/public-names.ts +1 -0
- package/packages/bundled-features/src/derivatives-sharp/render.ts +9 -9
- package/packages/bundled-features/src/document-ingest-foundation/aggregate-id.ts +0 -1
- package/packages/bundled-features/src/document-ingest-foundation/append-missing-extract-event.ts +37 -25
- package/packages/bundled-features/src/document-ingest-foundation/changes.json +6 -0
- package/packages/bundled-features/src/document-ingest-foundation/feature.ts +1 -0
- package/packages/bundled-features/src/document-ingest-foundation/report-ingest-progress.ts +34 -14
- package/packages/bundled-features/src/documents/aggregate-id.ts +0 -2
- package/packages/bundled-features/src/documents/changes.json +24 -0
- package/packages/bundled-features/src/documents/constants.ts +10 -2
- package/packages/bundled-features/src/documents/ensure-link.ts +3 -4
- package/packages/bundled-features/src/documents/feature.ts +33 -6
- package/packages/bundled-features/src/documents/handlers/import.write.ts +2 -2
- package/packages/bundled-features/src/documents/queries/expiry-overview.query.ts +2 -1
- package/packages/bundled-features/src/documents/queries/for-record.query.ts +3 -4
- package/packages/bundled-features/src/documents/queries/list-page.ts +11 -3
- package/packages/bundled-features/src/documents/queries/overview.query.ts +2 -2
- package/packages/bundled-features/src/documents/screens.ts +8 -3
- package/packages/bundled-features/src/documents/tab.ts +1 -1
- package/packages/bundled-features/src/feature-toggles/toggle-sync-signal.ts +6 -3
- package/packages/bundled-features/src/file-derivatives/handlers/public-variant-by-file-ref.query.ts +1 -1
- package/packages/bundled-features/src/file-derivatives/handlers/public-variant.query.ts +1 -1
- package/packages/bundled-features/src/file-foundation/probe.ts +9 -3
- package/packages/bundled-features/src/file-foundation/read-file-ref-content.ts +24 -11
- package/packages/bundled-features/src/file-provider-inmemory/feature.ts +1 -1
- package/packages/bundled-features/src/file-provider-s3/changes.json +14 -0
- package/packages/bundled-features/src/file-provider-s3/env-feature.ts +1 -1
- package/packages/bundled-features/src/file-provider-s3/env-named-feature.ts +1 -1
- package/packages/bundled-features/src/file-provider-s3/env-schema.ts +24 -7
- package/packages/bundled-features/src/file-provider-s3/feature.ts +1 -1
- package/packages/bundled-features/src/file-provider-s3/index.ts +7 -1
- package/packages/bundled-features/src/file-provider-s3/lib/env-helper.ts +21 -13
- package/packages/bundled-features/src/file-provider-s3/lib/s3-provider.ts +8 -1
- package/packages/bundled-features/src/files/changes.json +7 -0
- package/packages/bundled-features/src/folders/aggregate-id.ts +0 -1
- package/packages/bundled-features/src/folders/web/folder-manager.tsx +6 -6
- package/packages/bundled-features/src/folders-user-data/index.ts +12 -14
- package/packages/bundled-features/src/form-draft/feature.ts +1 -0
- package/packages/bundled-features/src/helpdesk/changes.json +56 -0
- package/packages/bundled-features/src/helpdesk/entity.ts +4 -1
- package/packages/bundled-features/src/helpdesk/feature.ts +42 -0
- package/packages/bundled-features/src/helpdesk/handlers/access.ts +0 -10
- package/packages/bundled-features/src/helpdesk/handlers/attempts.ts +7 -14
- package/packages/bundled-features/src/helpdesk/handlers/challenge.query.ts +1 -2
- package/packages/bundled-features/src/helpdesk/handlers/reply.write.ts +5 -12
- package/packages/bundled-features/src/helpdesk/handlers/report.write.ts +4 -10
- package/packages/bundled-features/src/helpdesk/handlers/submit.write.ts +5 -12
- package/packages/bundled-features/src/helpdesk/index.ts +1 -0
- package/packages/bundled-features/src/helpdesk/legacy-contact-config.ts +61 -0
- package/packages/bundled-features/src/helpdesk/legacy-contact-erasure.ts +45 -0
- package/packages/bundled-features/src/helpdesk/legacy-contact-retention.ts +65 -0
- package/packages/bundled-features/src/helpdesk/legacy-contact-streams.ts +187 -0
- package/packages/bundled-features/src/helpdesk/legacy-contact-user-data.ts +84 -0
- package/packages/bundled-features/src/helpdesk/lib.ts +55 -37
- package/packages/bundled-features/src/helpdesk/user-data-hooks.ts +89 -48
- package/packages/bundled-features/src/helpdesk/web/constants.ts +0 -1
- package/packages/bundled-features/src/inbound-mail-foundation/account-health.ts +1 -1
- package/packages/bundled-features/src/inbound-mail-foundation/account-poll.ts +9 -2
- package/packages/bundled-features/src/inbound-mail-foundation/aggregate-id.ts +0 -2
- package/packages/bundled-features/src/inbound-mail-foundation/changes.json +54 -0
- package/packages/bundled-features/src/inbound-mail-foundation/constants.ts +6 -0
- package/packages/bundled-features/src/inbound-mail-foundation/content-refetch.ts +23 -2
- package/packages/bundled-features/src/inbound-mail-foundation/entities.ts +73 -15
- package/packages/bundled-features/src/inbound-mail-foundation/events.ts +24 -16
- package/packages/bundled-features/src/inbound-mail-foundation/feature.ts +3 -1
- package/packages/bundled-features/src/inbound-mail-foundation/handlers/account-address.ts +16 -2
- package/packages/bundled-features/src/inbound-mail-foundation/handlers/attach-message-content.write.ts +10 -3
- package/packages/bundled-features/src/inbound-mail-foundation/handlers/connect-account.write.ts +23 -9
- package/packages/bundled-features/src/inbound-mail-foundation/handlers/forget-message.write.ts +79 -0
- package/packages/bundled-features/src/inbound-mail-foundation/handlers/ingest-message-schema.ts +18 -5
- package/packages/bundled-features/src/inbound-mail-foundation/i18n.ts +3 -0
- package/packages/bundled-features/src/inbound-mail-foundation/index.ts +1 -0
- package/packages/bundled-features/src/inbound-mail-foundation/normalize-inbound-message.ts +22 -8
- package/packages/bundled-features/src/inbound-mail-foundation/oauth-access-token.ts +1 -1
- package/packages/bundled-features/src/inbound-mail-foundation/outbound-mail.ts +2 -0
- package/packages/bundled-features/src/inbound-mail-foundation/personal-address.ts +20 -0
- package/packages/bundled-features/src/inbound-mail-foundation/purge-messages.ts +54 -0
- package/packages/bundled-features/src/inbound-mail-foundation/quarantine.ts +15 -5
- package/packages/bundled-features/src/inbound-mail-foundation/retention-job.ts +1 -5
- package/packages/bundled-features/src/inbound-mail-foundation/retention-sweep.ts +21 -34
- package/packages/bundled-features/src/inbound-mail-foundation/sanitize-inbound-html.ts +2 -5
- package/packages/bundled-features/src/inbound-mail-foundation/send-from-account.ts +9 -1
- package/packages/bundled-features/src/inbound-mail-foundation/supervisor-ingest.ts +7 -1
- package/packages/bundled-features/src/inbound-mail-foundation/sync-account-now.ts +1 -1
- package/packages/bundled-features/src/inbound-mail-foundation/tenant-destroy-hook.ts +14 -17
- package/packages/bundled-features/src/inbound-mail-foundation/watch-supervisor.ts +1 -1
- package/packages/bundled-features/src/inbound-provider-imap/byte-budget.ts +80 -0
- package/packages/bundled-features/src/inbound-provider-imap/changes.json +13 -0
- package/packages/bundled-features/src/inbound-provider-imap/connect-mailbox.ts +8 -4
- package/packages/bundled-features/src/inbound-provider-imap/connect-my-mailbox.ts +23 -6
- package/packages/bundled-features/src/inbound-provider-imap/connect-target-rate-limit.ts +46 -0
- package/packages/bundled-features/src/inbound-provider-imap/download-batch.ts +47 -10
- package/packages/bundled-features/src/inbound-provider-imap/feature.ts +7 -4
- package/packages/bundled-features/src/inbound-provider-imap/fetch-content.ts +43 -29
- package/packages/bundled-features/src/inbound-provider-imap/i18n.ts +2 -2
- package/packages/bundled-features/src/inbound-provider-imap/parse-message.ts +14 -0
- package/packages/bundled-features/src/inbound-provider-imap/reconnect-mailbox.ts +5 -4
- package/packages/bundled-features/src/inbound-provider-imap/send-mail.ts +39 -7
- package/packages/bundled-features/src/inbound-provider-imap/smtp-client.ts +19 -4
- package/packages/bundled-features/src/inbound-provider-imap/watch-mailbox.ts +8 -23
- package/packages/bundled-features/src/inbound-provider-inmemory/feature.ts +1 -1
- package/packages/bundled-features/src/jobs/events.ts +10 -0
- package/packages/bundled-features/src/jobs/feature.ts +2 -0
- package/packages/bundled-features/src/jobs/handlers/consumer.write.ts +41 -16
- package/packages/bundled-features/src/jobs/web/constants.ts +4 -0
- package/packages/bundled-features/src/mail-foundation/changes.json +6 -0
- package/packages/bundled-features/src/mail-transport-inmemory/feature.ts +1 -1
- package/packages/bundled-features/src/mail-transport-smtp/feature.ts +3 -2
- package/packages/bundled-features/src/managed-pages/changes.json +12 -0
- package/packages/bundled-features/src/managed-pages/handlers/branding.query.ts +1 -1
- package/packages/bundled-features/src/managed-pages/handlers/by-slug.query.ts +1 -1
- package/packages/bundled-features/src/managed-pages/handlers/by-tenant-published.query.ts +1 -1
- package/packages/bundled-features/src/managed-pages/render-page-body.ts +18 -10
- package/packages/bundled-features/src/managed-pages/screens/page-screens.ts +18 -38
- package/packages/bundled-features/src/managed-pages/table.ts +1 -0
- package/packages/bundled-features/src/managed-pages/web/client-plugin.tsx +8 -6
- package/packages/bundled-features/src/managed-pages/web/constants.ts +8 -1
- package/packages/bundled-features/src/managed-pages/web/i18n.ts +11 -3
- package/packages/bundled-features/src/managed-pages/web/markdown-to-document.ts +1 -1
- package/packages/bundled-features/src/managed-pages/web/page-edit-draft.ts +108 -0
- package/packages/bundled-features/src/managed-pages/web/page-edit-screen.tsx +204 -0
- package/packages/bundled-features/src/managed-pages/web/page-settings-rail.tsx +117 -0
- package/packages/bundled-features/src/notes-history-user-data/index.ts +8 -14
- package/packages/bundled-features/src/personal-access-tokens/boot-rules.ts +5 -0
- package/packages/bundled-features/src/personal-access-tokens/handlers/create.write.ts +0 -1
- package/packages/bundled-features/src/personal-access-tokens/scope-events-check.ts +31 -5
- package/packages/bundled-features/src/presence/changes.json +6 -0
- package/packages/bundled-features/src/presence/handlers/list.query.ts +28 -11
- package/packages/bundled-features/src/presence/room.ts +21 -7
- package/packages/bundled-features/src/presence/store.ts +79 -21
- package/packages/bundled-features/src/readiness/changes.json +25 -0
- package/packages/bundled-features/src/readiness/handlers/latest-summary.query.ts +11 -6
- package/packages/bundled-features/src/readiness/handlers/run-probes.write.ts +35 -5
- package/packages/bundled-features/src/readiness/handlers/run-tone.ts +3 -2
- package/packages/bundled-features/src/readiness/handlers/status.query.ts +15 -1
- package/packages/bundled-features/src/readiness/probe-context.ts +11 -10
- package/packages/bundled-features/src/readiness/screens.ts +4 -4
- package/packages/bundled-features/src/readiness/visible-results.ts +5 -3
- package/packages/bundled-features/src/renderer-foundation/api.ts +6 -13
- package/packages/bundled-features/src/renderer-foundation/types.ts +2 -2
- package/packages/bundled-features/src/secrets/changes.json +7 -0
- package/packages/bundled-features/src/secrets/db/queries/read.ts +18 -4
- package/packages/bundled-features/src/secrets/handlers/list.query.ts +8 -2
- package/packages/bundled-features/src/secrets/secret-scope.ts +2 -3
- package/packages/bundled-features/src/secrets/secrets-context.ts +6 -4
- package/packages/bundled-features/src/secrets/write-gate.ts +4 -2
- package/packages/bundled-features/src/seo/handlers/seo-config.query.ts +1 -1
- package/packages/bundled-features/src/shared/acknowledged-system-db.ts +20 -0
- package/packages/bundled-features/src/shared/assert-billing-live.ts +9 -2
- package/packages/bundled-features/src/shared/changes.json +12 -0
- package/packages/bundled-features/src/shared/hmac-signature.ts +4 -2
- package/packages/bundled-features/src/shared/index.ts +7 -1
- package/packages/bundled-features/src/shared/normalize-email.ts +3 -0
- package/packages/bundled-features/src/shared/parent-visibility.ts +25 -1
- package/packages/bundled-features/src/shared/password-hashing.ts +0 -1
- package/packages/bundled-features/src/shared/price-env-shape.ts +1 -4
- package/packages/bundled-features/src/shared/register-user-data-hooks.ts +29 -0
- package/packages/bundled-features/src/shared/require-bootstrap-extension.ts +26 -0
- package/packages/bundled-features/src/shared/send-best-effort.ts +29 -0
- package/packages/bundled-features/src/shared/stream-tenant-backfill.ts +22 -1
- package/packages/bundled-features/src/shared/stream-tenant-derived-state.ts +31 -1
- package/packages/bundled-features/src/step-dispatcher/changes.json +18 -0
- package/packages/bundled-features/src/step-dispatcher/constants.ts +13 -0
- package/packages/bundled-features/src/step-dispatcher/deliver-dispatch-request.ts +50 -2
- package/packages/bundled-features/src/step-dispatcher/feature.ts +42 -1
- package/packages/bundled-features/src/step-dispatcher/mail-runner.ts +0 -1
- package/packages/bundled-features/src/step-dispatcher/sweep-abandoned.ts +61 -0
- package/packages/bundled-features/src/subscription-mollie/changes.json +7 -0
- package/packages/bundled-features/src/subscription-mollie/plugin-methods.ts +5 -3
- package/packages/bundled-features/src/subscription-mollie/verify-webhook.ts +5 -5
- package/packages/bundled-features/src/subscription-paddle/backfill-checkout-ledger.ts +161 -0
- package/packages/bundled-features/src/subscription-paddle/changes.json +19 -0
- package/packages/bundled-features/src/subscription-paddle/checkout-config.query.ts +1 -1
- package/packages/bundled-features/src/subscription-paddle/checkout-methods.ts +2 -8
- package/packages/bundled-features/src/subscription-paddle/constants.ts +1 -2
- package/packages/bundled-features/src/subscription-paddle/feature.ts +26 -24
- package/packages/bundled-features/src/subscription-paddle/ledger-backfill-marker.ts +70 -0
- package/packages/bundled-features/src/subscription-paddle/plan-switch-methods.ts +2 -8
- package/packages/bundled-features/src/subscription-paddle/redeliver-legacy-checkout.ts +57 -0
- package/packages/bundled-features/src/subscription-paddle/runtime.ts +13 -24
- package/packages/bundled-features/src/subscription-paddle/subscription-state.ts +1 -0
- package/packages/bundled-features/src/subscription-paddle/webhook-events.ts +68 -21
- package/packages/bundled-features/src/subscription-stripe/changes.json +13 -0
- package/packages/bundled-features/src/subscription-stripe/feature.ts +5 -0
- package/packages/bundled-features/src/subscription-stripe/plugin-methods.ts +6 -6
- package/packages/bundled-features/src/subscription-stripe/runtime.ts +8 -7
- package/packages/bundled-features/src/subscription-stripe/verify-webhook.ts +38 -6
- package/packages/bundled-features/src/tags/aggregate-id.ts +0 -1
- package/packages/bundled-features/src/tags/web/tag-chip.tsx +4 -5
- package/packages/bundled-features/src/tags/web/tag-manager.tsx +2 -1
- package/packages/bundled-features/src/template-resolver/api.ts +6 -13
- package/packages/bundled-features/src/template-resolver/changes.json +48 -0
- package/packages/bundled-features/src/template-resolver/document-sanitizer.ts +25 -0
- package/packages/bundled-features/src/template-resolver/feature.ts +2 -0
- package/packages/bundled-features/src/template-resolver/handlers/body-preview.query.ts +41 -0
- package/packages/bundled-features/src/template-resolver/handlers/by-slug.query.ts +1 -1
- package/packages/bundled-features/src/template-resolver/handlers/by-tenant.query.ts +1 -1
- package/packages/bundled-features/src/template-resolver/handlers/collection-shared.ts +5 -11
- package/packages/bundled-features/src/template-resolver/handlers/overview.query.ts +3 -2
- package/packages/bundled-features/src/template-resolver/handlers/send-test.write.ts +37 -8
- package/packages/bundled-features/src/template-resolver/linked-resources.ts +2 -5
- package/packages/bundled-features/src/template-resolver/seeding.ts +107 -0
- package/packages/bundled-features/src/template-resolver/table.ts +1 -0
- package/packages/bundled-features/src/template-resolver/template-draft.ts +2 -1
- package/packages/bundled-features/src/template-resolver/template-preview.ts +14 -3
- package/packages/bundled-features/src/template-resolver/testing.ts +0 -2
- package/packages/bundled-features/src/template-resolver/web/client-plugin.tsx +3 -0
- package/packages/bundled-features/src/template-resolver/web/collection-entry-create-form.tsx +33 -33
- package/packages/bundled-features/src/template-resolver/web/constants.ts +7 -0
- package/packages/bundled-features/src/template-resolver/web/content-tree-provider.ts +0 -1
- package/packages/bundled-features/src/template-resolver/web/content-workbench.tsx +142 -0
- package/packages/bundled-features/src/template-resolver/web/document-insert-model.ts +3 -8
- package/packages/bundled-features/src/template-resolver/web/document-link-policy.ts +58 -0
- package/packages/bundled-features/src/template-resolver/web/document-schema.ts +11 -57
- package/packages/bundled-features/src/template-resolver/web/document-tiptap-bubble.tsx +2 -4
- package/packages/bundled-features/src/template-resolver/web/document-tiptap-context.ts +4 -5
- package/packages/bundled-features/src/template-resolver/web/document-tiptap-editor.tsx +2 -2
- package/packages/bundled-features/src/template-resolver/web/document-tiptap-helpers.ts +6 -3
- package/packages/bundled-features/src/template-resolver/web/document-tiptap-toolbar-groups.tsx +2 -3
- package/packages/bundled-features/src/template-resolver/web/editor-handle.ts +1 -0
- package/packages/bundled-features/src/template-resolver/web/fill-document-variables.ts +24 -0
- package/packages/bundled-features/src/template-resolver/web/i18n.ts +14 -0
- package/packages/bundled-features/src/template-resolver/web/index.ts +3 -0
- package/packages/bundled-features/src/template-resolver/web/preview-targets.ts +25 -0
- package/packages/bundled-features/src/template-resolver/web/qualified-names.ts +1 -0
- package/packages/bundled-features/src/template-resolver/web/snippet-preview-renderer.tsx +24 -0
- package/packages/bundled-features/src/template-resolver/web/string-values.ts +7 -0
- package/packages/bundled-features/src/template-resolver/web/text-block-editor.tsx +38 -50
- package/packages/bundled-features/src/template-resolver/web/use-collection-entry-create.ts +7 -0
- package/packages/bundled-features/src/template-resolver/web/use-content-write.ts +1 -3
- package/packages/bundled-features/src/template-resolver/web/use-document-tiptap-model.ts +1 -2
- package/packages/bundled-features/src/template-resolver/web/use-text-block-editor.ts +28 -7
- package/packages/bundled-features/src/template-resolver/web/web-preview-renderer.tsx +132 -0
- package/packages/bundled-features/src/template-resolver-user-data/index.ts +11 -10
- package/packages/bundled-features/src/tenant/changes.json +6 -0
- package/packages/bundled-features/src/tenant/handlers/create.write.ts +7 -8
- package/packages/bundled-features/src/tenant/handlers/list.query.ts +7 -9
- package/packages/bundled-features/src/tenant/handlers/member-directory.query.ts +10 -4
- package/packages/bundled-features/src/tenant/handlers/toggle-enabled.write.ts +1 -1
- package/packages/bundled-features/src/tenant/invited-membership.ts +10 -1
- package/packages/bundled-features/src/tenant/seeding.ts +4 -2
- package/packages/bundled-features/src/tenant/stream-tenant-backfill.ts +5 -1
- package/packages/bundled-features/src/tenant/testing.ts +1 -1
- package/packages/bundled-features/src/tenant-inactivity/changes.json +6 -0
- package/packages/bundled-features/src/tenant-inactivity/check-inactive-tenants.ts +36 -17
- package/packages/bundled-features/src/tenant-inactivity/constants.ts +1 -2
- package/packages/bundled-features/src/tenant-inactivity/handlers/keep-account.write.ts +7 -2
- package/packages/bundled-features/src/tenant-inactivity/state-store.ts +22 -2
- package/packages/bundled-features/src/tenant-lifecycle/changes.json +24 -0
- package/packages/bundled-features/src/tenant-lifecycle/constants.ts +4 -0
- package/packages/bundled-features/src/tenant-lifecycle/feature.ts +1 -0
- package/packages/bundled-features/src/tenant-lifecycle/run-tenant-destroy.ts +43 -6
- package/packages/bundled-features/src/tenant-lifecycle/stages.ts +15 -2
- package/packages/bundled-features/src/tier-engine/aggregate-id.ts +0 -1
- package/packages/bundled-features/src/tier-engine/changes.json +6 -0
- package/packages/bundled-features/src/tier-engine/feature.ts +8 -2
- package/packages/bundled-features/src/user/changes.json +6 -0
- package/packages/bundled-features/src/user/db/queries/stream-tenant-backfill.ts +2 -1
- package/packages/bundled-features/src/user/handlers/me.query.ts +3 -1
- package/packages/bundled-features/src/user/index.ts +1 -0
- package/packages/bundled-features/src/user/resolve-verified-user-email.ts +17 -0
- package/packages/bundled-features/src/user-data-rights/db/queries/export-jobs.ts +0 -1
- package/packages/bundled-features/src/user-data-rights/feature.ts +1 -0
- package/packages/bundled-features/src/user-data-rights/handlers/confirm-deletion-by-token.write.ts +1 -1
- package/packages/bundled-features/src/user-data-rights/handlers/download-by-token.query.ts +1 -1
- package/packages/bundled-features/src/user-data-rights/handlers/request-deletion-by-email.write.ts +1 -1
- package/packages/bundled-features/src/user-data-rights/run-export-jobs.ts +0 -2
- package/packages/bundled-features/src/user-data-rights/run-forget-cleanup.ts +3 -3
- package/packages/bundled-features/src/user-data-rights/schema/download-attempt.ts +3 -2
- package/packages/bundled-features/src/user-data-rights/web/confirm-deletion-screen.tsx +1 -1
- package/packages/bundled-features/src/user-data-rights/web/privacy-center-screen.tsx +1 -1
- package/packages/bundled-features/src/user-data-rights/web/request-deletion-screen.tsx +1 -1
- package/packages/bundled-features/src/user-data-rights-defaults/hooks/api-token.userdata-hook.ts +5 -5
- package/packages/bundled-features/src/user-data-rights-defaults/hooks/hard-delete-own-rows-hook.ts +17 -0
- package/packages/bundled-features/src/user-data-rights-defaults/hooks/in-app-message.userdata-hook.ts +5 -5
- package/packages/bundled-features/src/user-data-rights-defaults/hooks/job-run.userdata-hook.ts +2 -1
- package/packages/bundled-features/src/user-data-rights-defaults/hooks/user-session.userdata-hook.ts +5 -5
- package/packages/bundled-features/src/user-profile/handlers/change-email.write.ts +0 -1
- package/packages/bundled-features/src/waitlist/changes.json +6 -0
- package/packages/bundled-features/src/waitlist/handlers/reject.write.ts +1 -1
- package/packages/bundled-features/src/waitlist/handlers/submit.write.ts +5 -29
- package/packages/bundled-features/src/waitlist/import.ts +2 -1
- package/packages/bundled-features/src/waitlist/lib.ts +2 -11
- package/packages/bundled-features/src/waitlist/link-on-signup.ts +2 -2
- package/packages/bundled-features/src/waitlist/user-data-hooks.ts +6 -19
- package/packages/bundled-features/src/workflow-runner/aggregate-id.ts +0 -1
- package/packages/bundled-features/src/workflow-runner/changes.json +6 -0
- package/packages/bundled-features/src/workflow-runner/event-trigger.ts +6 -2
- package/packages/bundled-features/src/workflow-runner/feature.ts +1 -5
- package/packages/bundled-features/src/workflow-runner/handlers/resume-run.write.ts +7 -4
- package/packages/bundled-features/src/workflow-runner/runner.ts +2 -0
- package/samples/apps/admin-console/src/app/shell.tsx +1 -0
- package/samples/apps/showcase/src/features/demos/web/pages/dialog.tsx +0 -1
- package/samples/apps/showcase/src/features/demos/web/pages/layout.tsx +1 -1
- package/samples/apps/showcase/src/features/demos/web/pages/sidebar-panel.tsx +0 -1
- package/samples/apps/styleguide/src/features/gallery/web/Gallery.tsx +1 -4
- package/samples/apps/ui-walkthrough/src/features/subscription-plans/feature.ts +6 -2
- package/samples/apps/use-all-bundled/e2e-billing-gallery/gallery-features.ts +12 -14
- package/samples/apps/use-all-bundled/feature-manifest.json +60 -29
- package/samples/apps/use-all-bundled/playwright.billing-docs.config.ts +1 -1
- package/samples/apps/use-all-bundled/playwright.config.ts +1 -0
- package/samples/apps/use-all-bundled/src/app/seed.ts +1 -1
- package/samples/apps/use-all-bundled/src/run-config.ts +2 -1
- package/samples/recipes/auth-mfa/src/web/confirmation-code-step.tsx +32 -10
- package/samples/recipes/chat-channels/README.md +2 -0
- package/samples/recipes/crypto-shredding-hr/README.md +11 -0
- package/samples/recipes/crypto-shredding-hr/src/feature.ts +27 -0
- package/samples/recipes/currencies-global/src/entities/currency.ts +1 -0
- package/samples/recipes/managed-pages/README.md +5 -1
- package/samples/recipes/managed-pages/package.json +3 -2
- package/samples/recipes/managed-pages/src/web/branded-preview.tsx +21 -0
- package/samples/recipes/managed-pages/tsconfig.json +8 -0
- package/samples/recipes/pwa-shell/README.md +52 -0
- package/samples/recipes/pwa-shell/bin/server.ts +12 -0
- package/samples/recipes/pwa-shell/package.json +13 -0
- package/samples/recipes/pwa-shell/src/app.ts +34 -0
- package/samples/recipes/rate-limiting/README.md +3 -3
- package/samples/recipes/record-detail-layout/README.md +33 -0
- package/samples/recipes/record-detail-layout/src/feature.ts +556 -44
- package/samples/recipes/record-detail-layout/src/order-board.ts +529 -0
- package/packages/bundled-features/src/managed-pages/web/page-body-section.tsx +0 -72
- package/packages/bundled-features/src/subscription-paddle/tenant-binding.ts +0 -34
- package/packages/bundled-features/src/template-resolver/web/content-field.tsx +0 -61
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import {
|
|
2
|
+
collectPiiEncryptedFields,
|
|
3
|
+
configuredPiiSubjectKms,
|
|
4
|
+
decryptPiiFieldValues,
|
|
5
|
+
isPiiCiphertext,
|
|
6
|
+
PII_ERASED_SENTINEL,
|
|
7
|
+
} from "@cosmicdrift/kumiko-framework/crypto";
|
|
8
|
+
import type { TenantDb } from "@cosmicdrift/kumiko-framework/db";
|
|
9
|
+
import { SYSTEM_TENANT_ID } from "@cosmicdrift/kumiko-framework/engine";
|
|
10
|
+
import {
|
|
11
|
+
archiveStream,
|
|
12
|
+
isStreamArchived,
|
|
13
|
+
streamAllEventsByType,
|
|
14
|
+
} from "@cosmicdrift/kumiko-framework/event-store";
|
|
15
|
+
import {
|
|
16
|
+
systemTenantReadRunner,
|
|
17
|
+
systemTenantWriteRunner,
|
|
18
|
+
} from "@cosmicdrift/kumiko-framework/internal/row-level-security";
|
|
19
|
+
import { helpdeskReplyEntity, helpdeskRequestEntity } from "./entity.ts";
|
|
20
|
+
|
|
21
|
+
// Data stored before the contact -> helpdesk rename stays under the old aggregate names. The old
|
|
22
|
+
// read tables are dropped in the apps, so the streams are folded straight from the event log.
|
|
23
|
+
export const LEGACY_CONTACT_REQUEST_ENTITY = "contact-request";
|
|
24
|
+
export const LEGACY_CONTACT_REPLY_ENTITY = "contact-reply";
|
|
25
|
+
|
|
26
|
+
const PII_DECRYPT_REASON = "helpdesk:legacy-contact-streams";
|
|
27
|
+
const ARCHIVED_BY = "helpdesk:legacy-contact";
|
|
28
|
+
const ARCHIVE_WRITE_REASON =
|
|
29
|
+
"archives the legacy contact streams of an erased subject in the system tenant";
|
|
30
|
+
export const LEGACY_ARCHIVE_REASON = "legacy contact data erased";
|
|
31
|
+
|
|
32
|
+
export type LegacyAggregate = {
|
|
33
|
+
readonly id: string;
|
|
34
|
+
// Plaintext after decryption; a field whose subject key is shredded holds PII_ERASED_SENTINEL.
|
|
35
|
+
readonly fields: Readonly<Record<string, unknown>>;
|
|
36
|
+
// True when a personal field could not be read, so the content is gone for good.
|
|
37
|
+
readonly erased: boolean;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const PII_FIELDS_BY_TYPE: Readonly<Record<string, readonly string[]>> = {
|
|
41
|
+
[LEGACY_CONTACT_REQUEST_ENTITY]: collectPiiEncryptedFields(helpdeskRequestEntity),
|
|
42
|
+
[LEGACY_CONTACT_REPLY_ENTITY]: collectPiiEncryptedFields(helpdeskReplyEntity),
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
46
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async function readableFields(
|
|
50
|
+
aggregateType: string,
|
|
51
|
+
fields: Record<string, unknown>,
|
|
52
|
+
onlyFields?: readonly string[],
|
|
53
|
+
): Promise<LegacyAggregate["fields"]> {
|
|
54
|
+
const piiFields = PII_FIELDS_BY_TYPE[aggregateType] ?? [];
|
|
55
|
+
const kms = configuredPiiSubjectKms();
|
|
56
|
+
if (kms === undefined) return fields;
|
|
57
|
+
return decryptPiiFieldValues(
|
|
58
|
+
fields,
|
|
59
|
+
onlyFields ? piiFields.filter((name) => onlyFields.includes(name)) : piiFields,
|
|
60
|
+
kms,
|
|
61
|
+
{ requestId: PII_DECRYPT_REASON },
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function hasUnreadablePersonalField(aggregateType: string, fields: LegacyAggregate["fields"]) {
|
|
66
|
+
return (PII_FIELDS_BY_TYPE[aggregateType] ?? []).some((name) => {
|
|
67
|
+
const value = fields[name];
|
|
68
|
+
return value === PII_ERASED_SENTINEL || isPiiCiphertext(value);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
type RawFields = Record<string, unknown>;
|
|
73
|
+
|
|
74
|
+
// Folds created and updated events per aggregate; a deleted or forgotten stream is gone for good.
|
|
75
|
+
async function foldLegacyStreams(
|
|
76
|
+
runner: ReturnType<typeof systemTenantReadRunner>,
|
|
77
|
+
aggregateType: string,
|
|
78
|
+
): Promise<Map<string, RawFields>> {
|
|
79
|
+
const folded = new Map<string, RawFields>();
|
|
80
|
+
const gone = new Set<string>();
|
|
81
|
+
for await (const event of streamAllEventsByType(runner, aggregateType)) {
|
|
82
|
+
const id = event.aggregateId;
|
|
83
|
+
if (gone.has(id)) continue;
|
|
84
|
+
switch (event.type) {
|
|
85
|
+
case `${aggregateType}.created`:
|
|
86
|
+
folded.set(id, { ...event.payload });
|
|
87
|
+
break;
|
|
88
|
+
case `${aggregateType}.updated`: {
|
|
89
|
+
const current = folded.get(id);
|
|
90
|
+
const changes = event.payload["changes"];
|
|
91
|
+
if (current && isRecord(changes)) Object.assign(current, changes);
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
case `${aggregateType}.deleted`:
|
|
95
|
+
case `${aggregateType}.forgotten`:
|
|
96
|
+
folded.delete(id);
|
|
97
|
+
gone.add(id);
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return folded;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export type LegacyReadOptions = {
|
|
105
|
+
// Retention compares plaintext timestamps only, so it skips the KMS round trips.
|
|
106
|
+
readonly decrypt?: boolean;
|
|
107
|
+
// Narrows by plaintext fields before any archive lookup or decryption.
|
|
108
|
+
readonly isCandidate?: (raw: Readonly<Record<string, unknown>>) => boolean;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
// Archived streams are skipped, so an erased aggregate is never read again. The archive lookup
|
|
112
|
+
// is per aggregate (the framework has no bulk query for it), after the candidate filter.
|
|
113
|
+
export async function readLegacyAggregates(
|
|
114
|
+
db: TenantDb,
|
|
115
|
+
aggregateType: string,
|
|
116
|
+
options: LegacyReadOptions = {},
|
|
117
|
+
): Promise<readonly LegacyAggregate[]> {
|
|
118
|
+
const runner = systemTenantReadRunner(db);
|
|
119
|
+
const aggregates: LegacyAggregate[] = [];
|
|
120
|
+
for (const [id, raw] of await foldLegacyStreams(runner, aggregateType)) {
|
|
121
|
+
if (options.isCandidate && !options.isCandidate(raw)) continue;
|
|
122
|
+
if (await isStreamArchived(runner, SYSTEM_TENANT_ID, id)) continue;
|
|
123
|
+
if (options.decrypt === false) {
|
|
124
|
+
aggregates.push({ id, fields: raw, erased: false });
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
const fields = await readableFields(aggregateType, raw);
|
|
128
|
+
aggregates.push({ id, fields, erased: hasUnreadablePersonalField(aggregateType, fields) });
|
|
129
|
+
}
|
|
130
|
+
return aggregates;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// A signed-in request carries the plaintext user id; an anonymous one is matched by the email,
|
|
134
|
+
// which is the only field decrypted for the rest. Only the matches are fully decrypted.
|
|
135
|
+
export async function findLegacyRequestsOfSubject(
|
|
136
|
+
db: TenantDb,
|
|
137
|
+
subject: { readonly userId: string; readonly email: string | undefined },
|
|
138
|
+
): Promise<readonly LegacyAggregate[]> {
|
|
139
|
+
const runner = systemTenantReadRunner(db);
|
|
140
|
+
const matches: LegacyAggregate[] = [];
|
|
141
|
+
for (const [id, raw] of await foldLegacyStreams(runner, LEGACY_CONTACT_REQUEST_ENTITY)) {
|
|
142
|
+
if (await isStreamArchived(runner, SYSTEM_TENANT_ID, id)) continue;
|
|
143
|
+
if (!(await isSubjectRequest(raw, subject))) continue;
|
|
144
|
+
const fields = await readableFields(LEGACY_CONTACT_REQUEST_ENTITY, raw);
|
|
145
|
+
matches.push({
|
|
146
|
+
id,
|
|
147
|
+
fields,
|
|
148
|
+
erased: hasUnreadablePersonalField(LEGACY_CONTACT_REQUEST_ENTITY, fields),
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
return matches;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
async function isSubjectRequest(
|
|
155
|
+
raw: RawFields,
|
|
156
|
+
subject: { readonly userId: string; readonly email: string | undefined },
|
|
157
|
+
): Promise<boolean> {
|
|
158
|
+
if (raw["reporterUserId"] === subject.userId) return true;
|
|
159
|
+
if (subject.email === undefined) return false;
|
|
160
|
+
// Only anonymous requests can match by email; another signed-in reporter needs no decryption.
|
|
161
|
+
if (typeof raw["reporterUserId"] === "string" && raw["reporterUserId"] !== "") return false;
|
|
162
|
+
const { email } = await readableFields(LEGACY_CONTACT_REQUEST_ENTITY, { email: raw["email"] }, [
|
|
163
|
+
"email",
|
|
164
|
+
]);
|
|
165
|
+
return typeof email === "string" && email.toLowerCase() === subject.email;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export async function archiveLegacyStream(
|
|
169
|
+
db: TenantDb,
|
|
170
|
+
aggregateType: string,
|
|
171
|
+
aggregateId: string,
|
|
172
|
+
): Promise<void> {
|
|
173
|
+
await archiveStream(systemTenantWriteRunner(db, ARCHIVE_WRITE_REASON), {
|
|
174
|
+
tenantId: SYSTEM_TENANT_ID,
|
|
175
|
+
aggregateId,
|
|
176
|
+
aggregateType,
|
|
177
|
+
archivedBy: ARCHIVED_BY,
|
|
178
|
+
reason: LEGACY_ARCHIVE_REASON,
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export function repliesOf(
|
|
183
|
+
replies: readonly LegacyAggregate[],
|
|
184
|
+
requestId: string,
|
|
185
|
+
): readonly LegacyAggregate[] {
|
|
186
|
+
return replies.filter((reply) => reply.fields["requestId"] === requestId);
|
|
187
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
UserDataDeleteHook,
|
|
3
|
+
UserDataExportHook,
|
|
4
|
+
UserDataHookCtx,
|
|
5
|
+
} from "@cosmicdrift/kumiko-framework/engine";
|
|
6
|
+
import { resolveVerifiedUserEmail } from "../user/index.ts";
|
|
7
|
+
import { eraseLegacyRequest } from "./legacy-contact-erasure.ts";
|
|
8
|
+
import {
|
|
9
|
+
findLegacyRequestsOfSubject,
|
|
10
|
+
LEGACY_CONTACT_REPLY_ENTITY,
|
|
11
|
+
LEGACY_CONTACT_REQUEST_ENTITY,
|
|
12
|
+
type LegacyAggregate,
|
|
13
|
+
readLegacyAggregates,
|
|
14
|
+
repliesOf,
|
|
15
|
+
} from "./legacy-contact-streams.ts";
|
|
16
|
+
import { findAttachments, purgeAttachments } from "./user-data-hooks.ts";
|
|
17
|
+
|
|
18
|
+
export { LEGACY_CONTACT_REPLY_ENTITY, LEGACY_CONTACT_REQUEST_ENTITY };
|
|
19
|
+
|
|
20
|
+
const PII_DECRYPT_REASON = "helpdesk:legacy-contact-user-data";
|
|
21
|
+
|
|
22
|
+
async function findLegacyRequests(ctx: UserDataHookCtx): Promise<readonly LegacyAggregate[]> {
|
|
23
|
+
const email = (await resolveVerifiedUserEmail(ctx, PII_DECRYPT_REASON))?.toLowerCase();
|
|
24
|
+
return findLegacyRequestsOfSubject(ctx.db, { userId: ctx.userId, email });
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Replies are linked by the plaintext request id, so only those of the matched requests are read.
|
|
28
|
+
function repliesOfRequests(ctx: UserDataHookCtx, requests: readonly LegacyAggregate[]) {
|
|
29
|
+
const requestIds = new Set(requests.map((request) => request.id));
|
|
30
|
+
return readLegacyAggregates(ctx.db, LEGACY_CONTACT_REPLY_ENTITY, {
|
|
31
|
+
isCandidate: (raw) => typeof raw["requestId"] === "string" && requestIds.has(raw["requestId"]),
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const legacyContactExportHook: UserDataExportHook = async (ctx) => {
|
|
36
|
+
const requests = (await findLegacyRequests(ctx)).filter((request) => !request.erased);
|
|
37
|
+
if (requests.length === 0) return null;
|
|
38
|
+
const replies = await repliesOfRequests(ctx, requests);
|
|
39
|
+
const rows = [];
|
|
40
|
+
for (const request of requests) {
|
|
41
|
+
const { fields } = request;
|
|
42
|
+
rows.push({
|
|
43
|
+
kind: fields["kind"],
|
|
44
|
+
status: fields["status"],
|
|
45
|
+
source: fields["source"],
|
|
46
|
+
subject: fields["subject"],
|
|
47
|
+
message: fields["message"],
|
|
48
|
+
name: fields["name"],
|
|
49
|
+
email: fields["email"],
|
|
50
|
+
phone: fields["phone"],
|
|
51
|
+
page: fields["page"],
|
|
52
|
+
submittedAt: String(fields["submittedAt"]),
|
|
53
|
+
attachments: (await findAttachments(ctx, LEGACY_CONTACT_REQUEST_ENTITY, request.id)).map(
|
|
54
|
+
(file) => file.fileName,
|
|
55
|
+
),
|
|
56
|
+
replies: repliesOf(replies, request.id)
|
|
57
|
+
.filter((reply) => !reply.erased)
|
|
58
|
+
.map((reply) => ({
|
|
59
|
+
message: reply.fields["message"],
|
|
60
|
+
authorName: reply.fields["authorName"],
|
|
61
|
+
sentAt: String(reply.fields["sentAt"]),
|
|
62
|
+
})),
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
return { entity: LEGACY_CONTACT_REQUEST_ENTITY, rows };
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export const legacyContactDeleteHook: UserDataDeleteHook = async (ctx) => {
|
|
69
|
+
const requests = await findLegacyRequests(ctx);
|
|
70
|
+
// skip: user has no pre-rename contact data to erase
|
|
71
|
+
if (requests.length === 0) return;
|
|
72
|
+
const replies = await repliesOfRequests(ctx, requests);
|
|
73
|
+
for (const request of requests) {
|
|
74
|
+
await eraseLegacyRequest(
|
|
75
|
+
{
|
|
76
|
+
db: ctx.db,
|
|
77
|
+
erasedBy: ctx.userId,
|
|
78
|
+
purgeAttachments: (entity, id) => purgeAttachments(ctx, entity, id),
|
|
79
|
+
},
|
|
80
|
+
request,
|
|
81
|
+
repliesOf(replies, request.id),
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ROLES } from "@cosmicdrift/kumiko-framework/auth";
|
|
1
2
|
import {
|
|
2
3
|
createEventStoreExecutor,
|
|
3
4
|
fetchOne,
|
|
@@ -12,9 +13,13 @@ import {
|
|
|
12
13
|
type SessionUser,
|
|
13
14
|
SYSTEM_TENANT_ID,
|
|
14
15
|
} from "@cosmicdrift/kumiko-framework/engine";
|
|
15
|
-
import { InternalError } from "@cosmicdrift/kumiko-framework/errors";
|
|
16
16
|
import { propertyOf } from "@cosmicdrift/kumiko-types/type-guards";
|
|
17
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
acknowledgedSystemDb,
|
|
19
|
+
decryptStoredPii,
|
|
20
|
+
runBestEffort as runSharedBestEffort,
|
|
21
|
+
sendBestEffort as sendSharedBestEffort,
|
|
22
|
+
} from "../shared/index.ts";
|
|
18
23
|
import { tenantTable } from "../tenant/index.ts";
|
|
19
24
|
import { TierEngineQueries } from "../tier-engine/index.ts";
|
|
20
25
|
import { USER_STATUS, userTable } from "../user/index.ts";
|
|
@@ -29,6 +34,7 @@ import {
|
|
|
29
34
|
HELPDESK_REPLY_ENTITY,
|
|
30
35
|
HELPDESK_REQUEST_ENTITY,
|
|
31
36
|
HelpdeskErrors,
|
|
37
|
+
HelpdeskHandlers,
|
|
32
38
|
type HelpdeskPhoneMode,
|
|
33
39
|
type HelpdeskReplyChannels,
|
|
34
40
|
} from "./web/constants.ts";
|
|
@@ -38,7 +44,6 @@ export const TELEGRAM_FEATURE = "channel-telegram";
|
|
|
38
44
|
|
|
39
45
|
export const HELPDESK_CROSS_TENANT_REASON = "helpdesk is platform-wide (systemScope)";
|
|
40
46
|
|
|
41
|
-
export const SYSTEM_ADMIN_ROLE = "SystemAdmin";
|
|
42
47
|
const PII_DECRYPT_REASON = "helpdesk:user-lookup";
|
|
43
48
|
|
|
44
49
|
export const adminAccess = { roles: access.systemAdmin } as const;
|
|
@@ -56,33 +61,37 @@ export const replyExecutor = createEventStoreExecutor(helpdeskReplyTable, helpde
|
|
|
56
61
|
entityName: HELPDESK_REPLY_ENTITY,
|
|
57
62
|
});
|
|
58
63
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
);
|
|
72
|
-
return found.rows;
|
|
64
|
+
// Equals the executor's MAX_LIST_LIMIT, so every page is filled until the last one.
|
|
65
|
+
const LIST_PAGE_SIZE = 200;
|
|
66
|
+
|
|
67
|
+
export async function listAllPages<Row>(
|
|
68
|
+
fetchPage: (page: { limit: number; offset: number }) => Promise<{ rows: readonly Row[] }>,
|
|
69
|
+
): Promise<Row[]> {
|
|
70
|
+
const all: Row[] = [];
|
|
71
|
+
for (;;) {
|
|
72
|
+
const { rows } = await fetchPage({ limit: LIST_PAGE_SIZE, offset: all.length });
|
|
73
|
+
all.push(...rows);
|
|
74
|
+
if (rows.length < LIST_PAGE_SIZE) return all;
|
|
75
|
+
}
|
|
73
76
|
}
|
|
74
77
|
|
|
75
|
-
export function
|
|
76
|
-
return
|
|
78
|
+
export function listRepliesOf(db: TenantDb, requestId: string) {
|
|
79
|
+
return listAllPages((page) =>
|
|
80
|
+
replyExecutor.list(
|
|
81
|
+
{
|
|
82
|
+
filter: { field: "requestId", op: "eq", value: requestId },
|
|
83
|
+
sort: "sentAt",
|
|
84
|
+
sortDirection: "asc",
|
|
85
|
+
...page,
|
|
86
|
+
},
|
|
87
|
+
platformActor(),
|
|
88
|
+
db,
|
|
89
|
+
),
|
|
90
|
+
);
|
|
77
91
|
}
|
|
78
92
|
|
|
79
93
|
export function helpdeskDb(ctx: Pick<AppContext, "systemDb">): TenantDb {
|
|
80
|
-
|
|
81
|
-
throw new InternalError({
|
|
82
|
-
message: "helpdesk requires ctx.systemDb — is r.systemScope() set on the feature?",
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
return ctx.systemDb.acknowledgeCrossTenant(HELPDESK_CROSS_TENANT_REASON);
|
|
94
|
+
return acknowledgedSystemDb(ctx, "helpdesk", HELPDESK_CROSS_TENANT_REASON);
|
|
86
95
|
}
|
|
87
96
|
|
|
88
97
|
// Requests and replies are systemStream rows, so every write targets the system tenant's stream.
|
|
@@ -94,7 +103,7 @@ export async function listSystemAdminIds(db: TenantDb): Promise<readonly string[
|
|
|
94
103
|
const rows = await selectMany<{ readonly id: string }>(
|
|
95
104
|
db,
|
|
96
105
|
userTable,
|
|
97
|
-
{ isDeleted: false, status: USER_STATUS.Active, roles:
|
|
106
|
+
{ isDeleted: false, status: USER_STATUS.Active, roles: ROLES.SystemAdmin },
|
|
98
107
|
{ fields: ["id"], orderBy: { col: "id" } },
|
|
99
108
|
);
|
|
100
109
|
return rows.map((r) => r.id);
|
|
@@ -117,16 +126,25 @@ export async function sendBestEffort(
|
|
|
117
126
|
label: string,
|
|
118
127
|
send: (notify: NonNullable<HandlerContext["notify"]>) => Promise<unknown>,
|
|
119
128
|
): Promise<void> {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
129
|
+
return sendSharedBestEffort(ctx, `[helpdesk] ${label} failed`, send);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export async function runBestEffort(
|
|
133
|
+
ctx: Pick<HandlerContext, "obs">,
|
|
134
|
+
label: string,
|
|
135
|
+
run: () => Promise<unknown>,
|
|
136
|
+
): Promise<void> {
|
|
137
|
+
return runSharedBestEffort(ctx, `[helpdesk] ${label} failed`, run);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export async function forwardHelpdeskRequest(
|
|
141
|
+
ctx: Pick<HandlerContext, "dispatch">,
|
|
142
|
+
requestId: string,
|
|
143
|
+
): Promise<void> {
|
|
144
|
+
const forwarded = await ctx.dispatch.writeAs(platformActor(), HelpdeskHandlers.forwardRequest, {
|
|
145
|
+
requestId,
|
|
146
|
+
});
|
|
147
|
+
if (!forwarded.isSuccess) throw new Error(forwarded.error.message);
|
|
130
148
|
}
|
|
131
149
|
|
|
132
150
|
export async function pickReplyChannels(
|
|
@@ -165,7 +183,7 @@ export async function loadTenantPlan(
|
|
|
165
183
|
if (ctx.registry.getQueryHandler(TierEngineQueries.getTenantTier) === undefined) return null;
|
|
166
184
|
try {
|
|
167
185
|
const assignment = await ctx.dispatch.queryAs(
|
|
168
|
-
createSystemUser(SYSTEM_TENANT_ID, [
|
|
186
|
+
createSystemUser(SYSTEM_TENANT_ID, [ROLES.SystemAdmin]),
|
|
169
187
|
TierEngineQueries.getTenantTier,
|
|
170
188
|
{ tenantId },
|
|
171
189
|
);
|
|
@@ -9,9 +9,14 @@ import type {
|
|
|
9
9
|
import { SYSTEM_TENANT_ID } from "@cosmicdrift/kumiko-framework/engine";
|
|
10
10
|
import { InternalError } from "@cosmicdrift/kumiko-framework/errors";
|
|
11
11
|
import { fileRefEntity, fileRefsTable } from "@cosmicdrift/kumiko-framework/files";
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
import {
|
|
13
|
+
systemTenantReadDb,
|
|
14
|
+
systemTenantWriteRunner,
|
|
15
|
+
} from "@cosmicdrift/kumiko-framework/internal/row-level-security";
|
|
16
|
+
import { eraseNoteBodiesReachingSubject } from "../notes-history-user-data/index.ts";
|
|
17
|
+
import { collectErasureFailure, throwIfErasureFailed } from "../shared/index.ts";
|
|
18
|
+
import { resolveVerifiedUserEmail } from "../user/index.ts";
|
|
19
|
+
import { listAllPages, platformActor, replyExecutor, requestExecutor } from "./lib.ts";
|
|
15
20
|
import {
|
|
16
21
|
HELPDESK_REPLY_ENTITY,
|
|
17
22
|
HELPDESK_REQUEST_ENTITY,
|
|
@@ -20,35 +25,29 @@ import {
|
|
|
20
25
|
|
|
21
26
|
const PII_DECRYPT_REASON = "helpdesk:user-data";
|
|
22
27
|
const ERASE_REASON = "helpdesk:user-data-forget";
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
// Anonymous requests are matched by email, so the user must have proven they own it: otherwise
|
|
26
|
-
// registering with someone else's address would expose or erase that person's requests.
|
|
27
|
-
async function resolveVerifiedUserEmail(ctx: UserDataHookCtx): Promise<string | null> {
|
|
28
|
-
const row = await ctx.db.fetchOne<{ email: string; emailVerified: boolean }>(userTable, {
|
|
29
|
-
id: ctx.userId,
|
|
30
|
-
});
|
|
31
|
-
if (row?.emailVerified !== true) return null;
|
|
32
|
-
if (ctx.userEmailBeforeDelete) return normalizeEmail(ctx.userEmailBeforeDelete);
|
|
33
|
-
return normalizeEmail(await decryptStoredPii(row.email, "email", PII_DECRYPT_REASON));
|
|
34
|
-
}
|
|
28
|
+
const NOTE_ERASE_WRITE_REASON =
|
|
29
|
+
"erases the note bodies SystemAdmins wrote in the system tenant on a request of an erased subject";
|
|
35
30
|
|
|
36
31
|
async function findRequests(ctx: UserDataHookCtx) {
|
|
37
|
-
const byUser = await
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
32
|
+
const byUser = await listAllPages((page) =>
|
|
33
|
+
requestExecutor.list(
|
|
34
|
+
{ filter: { field: "reporterUserId", op: "eq", value: ctx.userId }, ...page },
|
|
35
|
+
platformActor(),
|
|
36
|
+
ctx.db,
|
|
37
|
+
),
|
|
41
38
|
);
|
|
42
|
-
const email = await resolveVerifiedUserEmail(ctx);
|
|
39
|
+
const email = await resolveVerifiedUserEmail(ctx, PII_DECRYPT_REASON);
|
|
43
40
|
const byEmail = email
|
|
44
|
-
? await
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
41
|
+
? await listAllPages((page) =>
|
|
42
|
+
requestExecutor.list(
|
|
43
|
+
{ filter: { field: "email", op: "eq", value: email }, ...page },
|
|
44
|
+
platformActor(),
|
|
45
|
+
ctx.db,
|
|
46
|
+
),
|
|
48
47
|
)
|
|
49
|
-
:
|
|
50
|
-
const unique = new Map(byUser.
|
|
51
|
-
for (const row of byEmail
|
|
48
|
+
: [];
|
|
49
|
+
const unique = new Map(byUser.map((row) => [row.id, row]));
|
|
50
|
+
for (const row of byEmail) unique.set(row.id, row);
|
|
52
51
|
return [...unique.values()];
|
|
53
52
|
}
|
|
54
53
|
|
|
@@ -56,9 +55,18 @@ const fileRefExecutor = createEventStoreExecutor(fileRefsTable, fileRefEntity, {
|
|
|
56
55
|
entityName: "fileRef",
|
|
57
56
|
});
|
|
58
57
|
|
|
59
|
-
// Attachments are copied into the system tenant and bound to the request or reply row
|
|
60
|
-
|
|
61
|
-
|
|
58
|
+
// Attachments are copied into the system tenant and bound to the request or reply row; a tenant
|
|
59
|
+
// session cannot read those file_refs, so the lookup uses the system-tenant read handle.
|
|
60
|
+
export async function findAttachments(
|
|
61
|
+
ctx: Pick<UserDataHookCtx, "db">,
|
|
62
|
+
entity: string,
|
|
63
|
+
id: string,
|
|
64
|
+
) {
|
|
65
|
+
return systemTenantReadDb(ctx.db).selectMany<{
|
|
66
|
+
id: string;
|
|
67
|
+
storageKey: string;
|
|
68
|
+
fileName: string;
|
|
69
|
+
}>(fileRefsTable, {
|
|
62
70
|
tenantId: SYSTEM_TENANT_ID,
|
|
63
71
|
entityType: entity,
|
|
64
72
|
entityId: id,
|
|
@@ -66,24 +74,23 @@ async function findAttachments(ctx: UserDataHookCtx, entity: string, id: string)
|
|
|
66
74
|
});
|
|
67
75
|
}
|
|
68
76
|
|
|
77
|
+
export type AttachmentByteDeleter = (storageKey: string) => Promise<readonly string[]>;
|
|
78
|
+
|
|
69
79
|
// Bytes first, then the fileRef row: a crash in between leaves a row whose delete converges on the
|
|
70
80
|
// next run, never bytes without a row. A failing byte delete aborts, like the generic fileRef hook.
|
|
71
|
-
|
|
81
|
+
// The deleter is resolved lazily, so a row without attachments needs no storage provider.
|
|
82
|
+
export async function purgeAttachmentsWith(
|
|
83
|
+
ctx: Pick<UserDataHookCtx, "db">,
|
|
84
|
+
entity: string,
|
|
85
|
+
id: string,
|
|
86
|
+
resolveByteDeleter: () => Promise<AttachmentByteDeleter>,
|
|
87
|
+
): Promise<void> {
|
|
72
88
|
const attachments = await findAttachments(ctx, entity, id);
|
|
73
89
|
// skip: a row without attachments has no bytes to erase and needs no storage provider
|
|
74
90
|
if (attachments.length === 0) return;
|
|
75
|
-
const
|
|
76
|
-
if (!provider) {
|
|
77
|
-
throw new InternalError({
|
|
78
|
-
message: `[helpdesk:user-data] no file storage resolvable, attachments of ${entity} ${id} cannot be erased`,
|
|
79
|
-
});
|
|
80
|
-
}
|
|
91
|
+
const deleteBytes = await resolveByteDeleter();
|
|
81
92
|
for (const attachment of attachments) {
|
|
82
|
-
const failed = await
|
|
83
|
-
attachment.storageKey,
|
|
84
|
-
provider,
|
|
85
|
-
"helpdesk:user-data",
|
|
86
|
-
);
|
|
93
|
+
const failed = await deleteBytes(attachment.storageKey);
|
|
87
94
|
if (failed.length > 0) {
|
|
88
95
|
throw new InternalError({
|
|
89
96
|
message: `[helpdesk:user-data] ${failed.length} attachment byte delete(s) failed for ${entity} ${id}`,
|
|
@@ -102,13 +109,46 @@ async function purgeAttachments(ctx: UserDataHookCtx, entity: string, id: string
|
|
|
102
109
|
throwIfErasureFailed(failures);
|
|
103
110
|
}
|
|
104
111
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
112
|
+
export function purgeAttachments(ctx: UserDataHookCtx, entity: string, id: string): Promise<void> {
|
|
113
|
+
return purgeAttachmentsWith(ctx, entity, id, async () => {
|
|
114
|
+
const provider = await ctx.buildStorageProvider?.(SYSTEM_TENANT_ID);
|
|
115
|
+
if (!provider) {
|
|
116
|
+
throw new InternalError({
|
|
117
|
+
message: `[helpdesk:user-data] no file storage resolvable, attachments of ${entity} ${id} cannot be erased`,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
return (storageKey) =>
|
|
121
|
+
deleteStoredFileAndDerivatives(storageKey, provider, "helpdesk:user-data");
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Note bodies hang on the request as host. Notes written by SystemAdmins live in the system tenant,
|
|
126
|
+
// which a tenant-scoped hook db cannot see, so both handles are swept.
|
|
127
|
+
export async function eraseNotesOnRequest(
|
|
128
|
+
ctx: Pick<UserDataHookCtx, "db">,
|
|
129
|
+
entity: string,
|
|
130
|
+
id: string,
|
|
131
|
+
erasedBy: string,
|
|
132
|
+
): Promise<void> {
|
|
133
|
+
for (const db of [ctx.db, systemTenantWriteRunner(ctx.db, NOTE_ERASE_WRITE_REASON)]) {
|
|
134
|
+
await eraseNoteBodiesReachingSubject({
|
|
135
|
+
db,
|
|
136
|
+
subject: { kind: "record", entity, id },
|
|
137
|
+
erasedBy,
|
|
138
|
+
requestId: ERASE_REASON,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// guard:dup-ok executor and foreign-key field differ; a generic executor abstraction would obscure row types.
|
|
144
|
+
function findReplies(ctx: UserDataHookCtx, requestId: string) {
|
|
145
|
+
return listAllPages((page) =>
|
|
146
|
+
replyExecutor.list(
|
|
147
|
+
{ filter: { field: "requestId", op: "eq", value: requestId }, ...page },
|
|
148
|
+
platformActor(),
|
|
149
|
+
ctx.db,
|
|
150
|
+
),
|
|
110
151
|
);
|
|
111
|
-
return found.rows;
|
|
112
152
|
}
|
|
113
153
|
|
|
114
154
|
export const helpdeskExportHook: UserDataExportHook = async (ctx) => {
|
|
@@ -169,6 +209,7 @@ export const helpdeskDeleteHook: UserDataDeleteHook = async (ctx) => {
|
|
|
169
209
|
await replyExecutor.forget({ id: reply.id }, platformActor(), ctx.db),
|
|
170
210
|
);
|
|
171
211
|
}
|
|
212
|
+
await eraseNotesOnRequest(ctx, HELPDESK_REQUEST_ENTITY, request.id, ctx.userId);
|
|
172
213
|
await purgeAttachments(ctx, HELPDESK_REQUEST_ENTITY, request.id);
|
|
173
214
|
await erase(
|
|
174
215
|
HELPDESK_REQUEST_ENTITY,
|
|
@@ -112,7 +112,6 @@ export const HelpdeskErrors = {
|
|
|
112
112
|
phoneNotAllowed: "helpdesk_phone_not_allowed",
|
|
113
113
|
phoneRequired: "helpdesk_phone_required",
|
|
114
114
|
reporterEmailMissing: "helpdesk_reporter_email_missing",
|
|
115
|
-
attachmentNotFound: "helpdesk_attachment_not_found",
|
|
116
115
|
} as const;
|
|
117
116
|
|
|
118
117
|
export const HELPDESK_NOTIFICATION_TYPES = {
|
|
@@ -86,7 +86,7 @@ export function createAccountHealth(deps: {
|
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
async function lastErrorWithoutOutage(account: AccountHealthRef) {
|
|
89
|
-
if (await hasOpenQuarantine(deps.db, account.id)) {
|
|
89
|
+
if (await hasOpenQuarantine(deps.db, { tenantId: account.tenantId, accountId: account.id })) {
|
|
90
90
|
return InboundMailLastErrors.messageQuarantined;
|
|
91
91
|
}
|
|
92
92
|
if (storageUnavailable.has(account.id)) return InboundMailLastErrors.fileStorageUnavailable;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { DbConnection } from "@cosmicdrift/kumiko-framework/db";
|
|
2
2
|
import { selectMany } from "@cosmicdrift/kumiko-framework/db";
|
|
3
3
|
import type { AccountHealth, PollFailureKind } from "./account-health.ts";
|
|
4
|
-
import { refetchSnippetOnlyMessages } from "./content-refetch.ts";
|
|
4
|
+
import { refetchSnippetOnlyMessages, type ScanResumePoints } from "./content-refetch.ts";
|
|
5
5
|
import { describeError } from "./describe-error.ts";
|
|
6
6
|
import { seenMessageTable } from "./entities.ts";
|
|
7
7
|
import {
|
|
@@ -63,6 +63,8 @@ export function createAccountPoller(deps: AccountPollerDeps): {
|
|
|
63
63
|
log,
|
|
64
64
|
} = deps;
|
|
65
65
|
|
|
66
|
+
const scanResumePoint: ScanResumePoints = new Map();
|
|
67
|
+
|
|
66
68
|
function unknownMessageIdsFilterFor(account: MailAccountRecord) {
|
|
67
69
|
return async (providerMessageIds: readonly string[]): Promise<ReadonlySet<string>> => {
|
|
68
70
|
if (providerMessageIds.length === 0) return new Set();
|
|
@@ -84,7 +86,11 @@ export function createAccountPoller(deps: AccountPollerDeps): {
|
|
|
84
86
|
for (const row of seen) seenIds.add(row.providerMessageId);
|
|
85
87
|
}
|
|
86
88
|
// A quarantined message counts as seen: re-fetching it would only fail the same way again.
|
|
87
|
-
for (const id of await quarantinedMessageIds(
|
|
89
|
+
for (const id of await quarantinedMessageIds(
|
|
90
|
+
systemDb,
|
|
91
|
+
{ tenantId: account.tenantId, accountId: account.id },
|
|
92
|
+
providerMessageIds,
|
|
93
|
+
)) {
|
|
88
94
|
seenIds.add(id);
|
|
89
95
|
}
|
|
90
96
|
return new Set(providerMessageIds.filter((id) => !seenIds.has(id)));
|
|
@@ -107,6 +113,7 @@ export function createAccountPoller(deps: AccountPollerDeps): {
|
|
|
107
113
|
const accessToken = await resolveAccessToken(account, plugin);
|
|
108
114
|
await refetchSnippetOnlyMessages({
|
|
109
115
|
db: systemDb,
|
|
116
|
+
scanResumePoint,
|
|
110
117
|
dispatchWrite: deps.dispatchWrite,
|
|
111
118
|
providerCtx,
|
|
112
119
|
account,
|