@cosmicdrift/kumiko-bundled-features 0.406.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/dist/account-security/feature.js +9 -1
- package/dist/admin-shell/feature.d.ts +3 -0
- package/dist/admin-shell/feature.js +1 -1
- package/dist/agent-tools/agent-manifest.js +1 -0
- package/dist/agent-tools/tool-catalog.js +1 -0
- package/dist/agent-tools/types.d.ts +4 -1
- package/dist/audit/event-classification.js +1 -0
- package/dist/auth-email-password/bootstrap.js +1 -0
- package/dist/auth-email-password/errors.js +16 -41
- package/dist/auth-email-password/web/auth-client.d.ts +8 -32
- package/dist/auth-email-password/web/auth-client.js +18 -52
- package/dist/auth-email-password/web/auth-redirect.js +2 -2
- package/dist/auth-email-password/web/confirm-account-unlock-screen.d.ts +2 -2
- package/dist/auth-email-password/web/confirm-account-unlock-screen.js +14 -35
- package/dist/auth-email-password/web/index.d.ts +1 -0
- package/dist/auth-email-password/web/index.js +1 -0
- package/dist/auth-email-password/web/read-path-param.d.ts +1 -0
- package/dist/auth-email-password/web/read-path-param.js +4 -0
- package/dist/auth-email-password/web/return-path.js +2 -2
- package/dist/auth-email-password/web/token-confirm-screen.d.ts +20 -0
- package/dist/auth-email-password/web/token-confirm-screen.js +38 -0
- package/dist/auth-email-password/web/verify-email-screen.d.ts +2 -2
- package/dist/auth-email-password/web/verify-email-screen.js +14 -37
- package/dist/auth-foundation/boot-checks.js +24 -12
- package/dist/auth-foundation/boot-rules.d.ts +27 -0
- package/dist/auth-foundation/boot-rules.js +27 -0
- package/dist/auth-mfa/errors.d.ts +1 -1
- package/dist/auth-mfa/errors.js +11 -24
- package/dist/auth-mfa/feature-exports.js +6 -45
- package/dist/auth-mfa/feature.js +7 -18
- package/dist/auth-mfa/web/mfa-client.js +11 -25
- package/dist/billing-foundation/consumer-protection/termination-notify.js +1 -0
- package/dist/billing-foundation/web/plan-price.js +7 -8
- package/dist/cap-counter/stock-cap-guard.js +1 -0
- package/dist/channel-in-app/constants.d.ts +1 -0
- package/dist/channel-in-app/feature.js +2 -0
- package/dist/channel-in-app/handlers/read-state-by-keys.query.d.ts +9 -0
- package/dist/channel-in-app/handlers/read-state-by-keys.query.js +21 -0
- package/dist/channel-in-app/in-app-channel.js +1 -0
- package/dist/channel-in-app/tables.js +5 -1
- package/dist/contact/challenge.d.ts +14 -0
- package/dist/contact/challenge.js +30 -0
- package/dist/contact/client/contact-client-source.d.ts +1 -0
- package/dist/contact/client/contact-client-source.js +203 -0
- package/dist/contact/entity.d.ts +777 -0
- package/dist/contact/entity.js +145 -0
- package/dist/contact/feature.d.ts +3 -0
- package/dist/contact/feature.js +130 -0
- package/dist/contact/handlers/access.d.ts +7 -0
- package/dist/contact/handlers/access.js +9 -0
- package/dist/contact/handlers/attempts.d.ts +14 -0
- package/dist/contact/handlers/attempts.js +54 -0
- package/dist/contact/handlers/challenge.query.d.ts +9 -0
- package/dist/contact/handlers/challenge.query.js +35 -0
- package/dist/contact/handlers/forward-request.write.d.ts +9 -0
- package/dist/contact/handlers/forward-request.write.js +61 -0
- package/dist/contact/handlers/mark-done.write.d.ts +7 -0
- package/dist/contact/handlers/mark-done.write.js +30 -0
- package/dist/contact/handlers/notify-reporter-in-app.write.d.ts +10 -0
- package/dist/contact/handlers/notify-reporter-in-app.write.js +36 -0
- package/dist/contact/handlers/open-count.d.ts +2 -0
- package/dist/contact/handlers/open-count.js +11 -0
- package/dist/contact/handlers/open-count.query.d.ts +3 -0
- package/dist/contact/handlers/open-count.query.js +13 -0
- package/dist/contact/handlers/replies.query.d.ts +11 -0
- package/dist/contact/handlers/replies.query.js +28 -0
- package/dist/contact/handlers/reply.write.d.ts +12 -0
- package/dist/contact/handlers/reply.write.js +118 -0
- package/dist/contact/handlers/report.write.d.ts +16 -0
- package/dist/contact/handlers/report.write.js +90 -0
- package/dist/contact/handlers/request-delivery.query.d.ts +16 -0
- package/dist/contact/handlers/request-delivery.query.js +85 -0
- package/dist/contact/handlers/request-detail.query.d.ts +41 -0
- package/dist/contact/handlers/request-detail.query.js +32 -0
- package/dist/contact/handlers/request-list.query.d.ts +2 -0
- package/dist/contact/handlers/request-list.query.js +9 -0
- package/dist/contact/handlers/send-reply-mail.write.d.ts +8 -0
- package/dist/contact/handlers/send-reply-mail.write.js +82 -0
- package/dist/contact/handlers/send-test.write.d.ts +5 -0
- package/dist/contact/handlers/send-test.write.js +36 -0
- package/dist/contact/handlers/submit.write.d.ts +20 -0
- package/dist/contact/handlers/submit.write.js +137 -0
- package/dist/contact/handlers/take-over-uploads.d.ts +9 -0
- package/dist/contact/handlers/take-over-uploads.js +33 -0
- package/dist/contact/i18n.d.ts +6 -0
- package/dist/contact/i18n.js +186 -0
- package/dist/contact/index.d.ts +5 -0
- package/dist/contact/index.js +4 -0
- package/dist/contact/lib.d.ts +101 -0
- package/dist/contact/lib.js +109 -0
- package/dist/contact/mail.d.ts +91 -0
- package/dist/contact/mail.js +279 -0
- package/dist/contact/options.d.ts +51 -0
- package/dist/contact/options.js +32 -0
- package/dist/contact/panels.d.ts +2 -0
- package/dist/contact/panels.js +21 -0
- package/dist/contact/payloads.d.ts +56 -0
- package/dist/contact/payloads.js +82 -0
- package/dist/contact/pow.d.ts +6 -0
- package/dist/contact/pow.js +19 -0
- package/dist/contact/screens.d.ts +5 -0
- package/dist/contact/screens.js +464 -0
- package/dist/contact/subject.d.ts +1 -0
- package/dist/contact/subject.js +13 -0
- package/dist/contact/user-agent.d.ts +1 -0
- package/dist/contact/user-agent.js +35 -0
- package/dist/contact/user-data-hooks.d.ts +3 -0
- package/dist/contact/user-data-hooks.js +129 -0
- package/dist/contact/web/constants.d.ts +127 -0
- package/dist/contact/web/constants.js +126 -0
- package/dist/contact/web/index.d.ts +1 -0
- package/dist/contact/web/index.js +1 -0
- package/dist/crypto-shredding/handlers/forget-subject.write.js +5 -13
- package/dist/data-retention/feature.js +16 -2
- package/dist/data-retention/index.d.ts +1 -0
- package/dist/data-retention/index.js +1 -0
- package/dist/data-retention/run-retention-cleanup.d.ts +14 -2
- package/dist/data-retention/run-retention-cleanup.js +102 -36
- package/dist/data-retention/tenant-destruction-hold.d.ts +23 -0
- package/dist/data-retention/tenant-destruction-hold.js +132 -0
- package/dist/delivery/address-opt-out.js +1 -0
- package/dist/delivery/channel-context.d.ts +1 -1
- package/dist/delivery/channel-context.js +2 -1
- package/dist/delivery/delivery-service.js +18 -8
- package/dist/delivery/events.d.ts +1 -0
- package/dist/delivery/events.js +2 -0
- package/dist/delivery/feature.js +3 -0
- package/dist/delivery/handlers/attempts-by-keys.query.d.ts +15 -0
- package/dist/delivery/handlers/attempts-by-keys.query.js +35 -0
- package/dist/delivery/handlers/log.query.d.ts +1 -0
- package/dist/delivery/handlers/log.query.js +1 -1
- package/dist/delivery/jobs.js +5 -2
- package/dist/delivery/tables.js +12 -2
- package/dist/delivery/types.d.ts +2 -0
- package/dist/delivery/unsubscribe-page.js +2 -0
- package/dist/delivery/web/delivery-channel-cell.js +1 -1
- package/dist/delivery/web/delivery-error-cell.js +1 -1
- package/dist/delivery/web/delivery-status-cell.js +1 -1
- package/dist/delivery/web/delivery-time-cell.js +3 -2
- package/dist/delivery/web/delivery-type-cell.js +1 -1
- package/dist/delivery/web/public-names.d.ts +1 -0
- package/dist/delivery/web/public-names.js +1 -0
- package/dist/document-ingest-foundation/boot-checks.js +19 -11
- package/dist/document-ingest-foundation/boot-rules.d.ts +17 -0
- package/dist/document-ingest-foundation/boot-rules.js +17 -0
- package/dist/document-ingest-foundation/events.d.ts +8 -0
- package/dist/document-ingest-foundation/events.js +12 -0
- package/dist/document-ingest-foundation/feature.js +30 -2
- package/dist/document-ingest-foundation/index.d.ts +3 -1
- package/dist/document-ingest-foundation/index.js +3 -1
- package/dist/document-ingest-foundation/report-ingest-progress.d.ts +14 -0
- package/dist/document-ingest-foundation/report-ingest-progress.js +20 -0
- package/dist/document-ingest-foundation/tables.d.ts +3 -0
- package/dist/document-ingest-foundation/tables.js +26 -0
- package/dist/files-tenant-data/hooks.js +4 -1
- package/dist/folders/web/folder-manager.js +3 -10
- package/dist/folders/web/folder-section.js +1 -1
- package/dist/form-draft-user-data/index.js +4 -1
- package/dist/inbound-mail-foundation/entities.d.ts +3 -0
- package/dist/inbound-mail-foundation/entities.js +2 -0
- package/dist/inbound-mail-foundation/events.d.ts +2 -0
- package/dist/inbound-mail-foundation/events.js +2 -0
- package/dist/inbound-mail-foundation/feature.js +6 -6
- package/dist/inbound-mail-foundation/handlers/attach-message-content.write.js +3 -1
- package/dist/inbound-mail-foundation/handlers/ingest-message.write.js +5 -0
- package/dist/inbound-mail-foundation/handlers/list-messages.query.js +4 -2
- package/dist/inbound-mail-foundation/handlers/message-content.d.ts +1 -0
- package/dist/inbound-mail-foundation/handlers/message-content.js +8 -0
- package/dist/inbound-mail-foundation/handlers/message-content.query.d.ts +2 -0
- package/dist/inbound-mail-foundation/handlers/message-content.query.js +1 -0
- package/dist/inbound-mail-foundation/projection.d.ts +3 -0
- package/dist/inbound-mail-foundation/projection.js +2 -0
- package/dist/inbound-mail-foundation/sanitize-inbound-html.d.ts +2 -0
- package/dist/inbound-mail-foundation/sanitize-inbound-html.js +135 -0
- package/dist/inbound-mail-foundation/types.js +1 -0
- package/dist/jobs/job-run-logger.js +16 -20
- package/dist/ledger/handlers/reports.query.js +25 -27
- package/dist/ledger/recurring.js +1 -0
- package/dist/notes-history/web/notes-section.js +3 -2
- package/dist/personal-access-tokens/feature.js +5 -18
- package/dist/personal-access-tokens/handlers/create.write.js +2 -5
- package/dist/secrets/handlers/delete.write.d.ts +4 -0
- package/dist/secrets/handlers/delete.write.js +9 -4
- package/dist/secrets/handlers/list.query.d.ts +6 -1
- package/dist/secrets/handlers/list.query.js +7 -3
- package/dist/secrets/handlers/set.write.d.ts +4 -0
- package/dist/secrets/handlers/set.write.js +10 -4
- package/dist/secrets/secret-scope.d.ts +17 -0
- package/dist/secrets/secret-scope.js +18 -0
- package/dist/sessions/feature.d.ts +3 -0
- package/dist/sessions/feature.js +13 -19
- package/dist/sessions/handlers/last-activity-probe.query.d.ts +7 -0
- package/dist/sessions/handlers/last-activity-probe.query.js +40 -0
- package/dist/sessions/handlers/last-activity-probe.route.d.ts +2 -0
- package/dist/sessions/handlers/last-activity-probe.route.js +30 -0
- package/dist/sessions/screens.js +1 -0
- package/dist/sessions/session-callbacks.d.ts +2 -0
- package/dist/sessions/session-callbacks.js +9 -7
- package/dist/sessions/web/i18n.js +4 -1
- package/dist/shared/assert-billing-live.d.ts +2 -0
- package/dist/shared/assert-billing-live.js +7 -0
- package/dist/shared/collect-extension-options.d.ts +1 -0
- package/dist/shared/collect-extension-options.js +8 -0
- package/dist/shared/index.d.ts +7 -1
- package/dist/shared/index.js +7 -1
- package/dist/shared/late-bound-slot.d.ts +5 -0
- package/dist/shared/late-bound-slot.js +13 -0
- package/dist/shared/mail-locale-templates.d.ts +1 -0
- package/dist/shared/mail-locale-templates.js +1 -1
- package/dist/shared/price-env-shape.d.ts +11 -0
- package/dist/shared/price-env-shape.js +15 -0
- package/dist/shared/purge-row-file-refs.d.ts +1 -0
- package/dist/shared/purge-row-file-refs.js +1 -1
- package/dist/shared/read-feature-export-fn.d.ts +2 -0
- package/dist/shared/read-feature-export-fn.js +11 -0
- package/dist/shared/signup-handover.js +3 -5
- package/dist/shared/tenant-destruction-hold.d.ts +23 -0
- package/dist/shared/tenant-destruction-hold.js +15 -0
- package/dist/shared/unprocessable.d.ts +4 -0
- package/dist/shared/unprocessable.js +4 -0
- package/dist/shared/web/index.d.ts +3 -0
- package/dist/shared/web/index.js +3 -0
- package/dist/subscription-paddle/feature.d.ts +1 -5
- package/dist/subscription-paddle/feature.js +7 -9
- package/dist/subscription-paddle/runtime.js +3 -7
- package/dist/subscription-stripe/feature.d.ts +1 -5
- package/dist/subscription-stripe/feature.js +7 -9
- package/dist/subscription-stripe/runtime.js +3 -7
- package/dist/tags/entity.js +1 -0
- package/dist/tags/web/tag-chip.d.ts +7 -0
- package/dist/tags/web/tag-chip.js +4 -0
- package/dist/tags/web/tag-filter.js +2 -5
- package/dist/tags/web/tag-manager.js +1 -1
- package/dist/tags/web/tag-section.js +3 -6
- package/dist/tags/web/tags-cell.js +2 -5
- package/dist/template-resolver/compile-document-body.js +12 -17
- package/dist/template-resolver/handlers/by-tenant.query.js +3 -1
- package/dist/template-resolver/handlers/discard-draft.write.js +1 -0
- package/dist/template-resolver/handlers/overview.query.js +3 -1
- package/dist/template-resolver/handlers/send-test.write.js +2 -4
- package/dist/template-resolver/handlers/toggle-status.write.js +3 -0
- package/dist/template-resolver/linked-resources.js +6 -5
- package/dist/template-resolver/store-template-resource.js +5 -10
- package/dist/template-resolver/web/document-images.js +6 -6
- package/dist/template-resolver/web/document-insert-fields.js +22 -4
- package/dist/template-resolver/web/document-schema.js +11 -12
- package/dist/template-resolver/web/tiptap-attribute-parse-rule.d.ts +15 -0
- package/dist/template-resolver/web/tiptap-attribute-parse-rule.js +11 -0
- package/dist/tenant/i18n.js +3 -0
- package/dist/tenant/schema/tenant.d.ts +9 -7
- package/dist/tenant/schema/tenant.js +1 -0
- package/dist/tenant/web/member-roles-cell.js +1 -1
- package/dist/tenant/web/member-status-cell.js +1 -1
- package/dist/tenant-inactivity/check-inactive-tenants.d.ts +3 -0
- package/dist/tenant-inactivity/check-inactive-tenants.js +184 -0
- package/dist/tenant-inactivity/constants.d.ts +10 -0
- package/dist/tenant-inactivity/constants.js +10 -0
- package/dist/tenant-inactivity/email-templates.d.ts +3 -0
- package/dist/tenant-inactivity/email-templates.js +16 -0
- package/dist/tenant-inactivity/feature.d.ts +8 -0
- package/dist/tenant-inactivity/feature.js +45 -0
- package/dist/tenant-inactivity/handlers/inactivity-state.query.d.ts +11 -0
- package/dist/tenant-inactivity/handlers/inactivity-state.query.js +45 -0
- package/dist/tenant-inactivity/handlers/keep-account.write.d.ts +8 -0
- package/dist/tenant-inactivity/handlers/keep-account.write.js +48 -0
- package/dist/tenant-inactivity/inactivity-plan.d.ts +51 -0
- package/dist/tenant-inactivity/inactivity-plan.js +113 -0
- package/dist/tenant-inactivity/index.d.ts +5 -0
- package/dist/tenant-inactivity/index.js +3 -0
- package/dist/tenant-inactivity/keep-token.d.ts +16 -0
- package/dist/tenant-inactivity/keep-token.js +24 -0
- package/dist/tenant-inactivity/mail-notifications.d.ts +4 -0
- package/dist/tenant-inactivity/mail-notifications.js +42 -0
- package/dist/tenant-inactivity/options.d.ts +27 -0
- package/dist/tenant-inactivity/options.js +5 -0
- package/dist/tenant-inactivity/remote-activity.d.ts +15 -0
- package/dist/tenant-inactivity/remote-activity.js +24 -0
- package/dist/tenant-inactivity/state-store.d.ts +10 -0
- package/dist/tenant-inactivity/state-store.js +50 -0
- package/dist/tenant-inactivity/state-table.d.ts +109 -0
- package/dist/tenant-inactivity/state-table.js +38 -0
- package/dist/tenant-lifecycle/boot-checks.js +8 -3
- package/dist/tenant-lifecycle/boot-rules.d.ts +12 -0
- package/dist/tenant-lifecycle/boot-rules.js +12 -0
- package/dist/tenant-lifecycle/feature.js +17 -2
- package/dist/tenant-lifecycle/handlers/request-destruction.write.js +11 -67
- package/dist/tenant-lifecycle/index.d.ts +1 -0
- package/dist/tenant-lifecycle/index.js +1 -0
- package/dist/tenant-lifecycle/request-tenant-destruction.d.ts +20 -0
- package/dist/tenant-lifecycle/request-tenant-destruction.js +66 -0
- package/dist/tenant-lifecycle/retention-config-destroy-hooks.d.ts +5 -0
- package/dist/tenant-lifecycle/retention-config-destroy-hooks.js +29 -0
- package/dist/tenant-lifecycle/run-tenant-destroy.d.ts +3 -0
- package/dist/tenant-lifecycle/run-tenant-destroy.js +43 -5
- package/dist/tenant-lifecycle/stages.d.ts +2 -0
- package/dist/tenant-lifecycle/stages.js +23 -2
- package/dist/tenant-lifecycle/testing.js +1 -1
- package/dist/tier-engine/caps-for-tier-from-map.d.ts +5 -0
- package/dist/tier-engine/caps-for-tier-from-map.js +12 -0
- package/dist/tier-engine/compose-app.d.ts +0 -22
- package/dist/tier-engine/compose-app.js +9 -16
- package/dist/tier-engine/index.d.ts +1 -0
- package/dist/tier-engine/index.js +1 -0
- package/dist/user/handlers/detail.query.d.ts +1 -1
- package/dist/user-data-rights/feature.js +2 -0
- package/dist/user-data-rights/run-forget-cleanup.js +2 -0
- package/dist/user-data-rights/web/privacy-center-screen.js +1 -1
- package/dist/user-data-rights/zip-path.js +1 -0
- package/dist/user-data-rights-defaults/hooks/config-value.userdata-hook.d.ts +1 -1
- package/dist/user-data-rights-defaults/hooks/config-value.userdata-hook.js +7 -20
- package/dist/user-data-rights-defaults/hooks/delivery-attempt.userdata-hook.js +3 -1
- package/dist/user-data-rights-defaults/hooks/forget-own-rows-delete-hook.d.ts +10 -0
- package/dist/user-data-rights-defaults/hooks/forget-own-rows-delete-hook.js +26 -0
- package/dist/user-data-rights-defaults/hooks/notification-preference.userdata-hook.d.ts +1 -1
- package/dist/user-data-rights-defaults/hooks/notification-preference.userdata-hook.js +7 -20
- package/dist/user-profile/handlers/change-email.write.js +2 -4
- package/dist/user-profile/web/profile-screen.js +2 -3
- package/kumiko-es-tables.json +12 -0
- package/package.json +46 -12
- package/src/admin-shell/changes.json +6 -0
- package/src/agent-tools/changes.json +6 -0
- package/src/channel-in-app/changes.json +7 -0
- package/src/contact/changes.json +27 -0
- package/src/data-retention/changes.json +6 -0
- package/src/delivery/changes.json +7 -0
- package/src/document-ingest-foundation/changes.json +6 -0
- package/src/files-tenant-data/changes.json +6 -0
- package/src/inbound-mail-foundation/changes.json +13 -0
- package/src/secrets/changes.json +6 -0
- package/src/sessions/changes.json +6 -0
- package/src/tenant-inactivity/changes.json +8 -0
- package/src/tenant-lifecycle/changes.json +18 -0
- package/src/tier-engine/changes.json +6 -0
|
@@ -0,0 +1,135 @@
|
|
|
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
|
+
import sanitizeHtml from "sanitize-html";
|
|
4
|
+
// Counted in UTF-8 bytes, not characters: the ciphertext grows with the bytes, and a CJK or emoji
|
|
5
|
+
// mail of 500,000 characters would encrypt past the event's bodyHtml maximum.
|
|
6
|
+
export const BODY_HTML_MAX_BYTES = 500_000;
|
|
7
|
+
const ALLOWED_TAGS = [
|
|
8
|
+
"p",
|
|
9
|
+
"br",
|
|
10
|
+
"div",
|
|
11
|
+
"span",
|
|
12
|
+
"a",
|
|
13
|
+
"b",
|
|
14
|
+
"strong",
|
|
15
|
+
"i",
|
|
16
|
+
"em",
|
|
17
|
+
"u",
|
|
18
|
+
"s",
|
|
19
|
+
"sub",
|
|
20
|
+
"sup",
|
|
21
|
+
"blockquote",
|
|
22
|
+
"pre",
|
|
23
|
+
"code",
|
|
24
|
+
"ul",
|
|
25
|
+
"ol",
|
|
26
|
+
"li",
|
|
27
|
+
"h1",
|
|
28
|
+
"h2",
|
|
29
|
+
"h3",
|
|
30
|
+
"h4",
|
|
31
|
+
"h5",
|
|
32
|
+
"h6",
|
|
33
|
+
"table",
|
|
34
|
+
"thead",
|
|
35
|
+
"tbody",
|
|
36
|
+
"tfoot",
|
|
37
|
+
"tr",
|
|
38
|
+
"td",
|
|
39
|
+
"th",
|
|
40
|
+
"img",
|
|
41
|
+
"hr",
|
|
42
|
+
"font",
|
|
43
|
+
"center",
|
|
44
|
+
];
|
|
45
|
+
const ALLOWED_ATTRIBUTES = {
|
|
46
|
+
a: ["href", "title", "target", "rel"],
|
|
47
|
+
img: ["src", "alt", "width", "height"],
|
|
48
|
+
td: ["colspan", "rowspan", "align", "valign", "width"],
|
|
49
|
+
th: ["colspan", "rowspan", "align", "valign", "width"],
|
|
50
|
+
table: ["width", "cellpadding", "cellspacing", "border", "align"],
|
|
51
|
+
font: ["color", "size"],
|
|
52
|
+
div: ["class", "id"],
|
|
53
|
+
blockquote: ["class", "type"],
|
|
54
|
+
"*": ["style", "dir", "align"],
|
|
55
|
+
};
|
|
56
|
+
// Exactly the markers the reader's quote folding looks for (Gmail, Apple Mail, Thunderbird, Yahoo, Outlook).
|
|
57
|
+
const QUOTE_CLASS_NAMES = ["gmail_quote", "moz-cite-prefix", "yahoo_quoted"];
|
|
58
|
+
const QUOTE_ELEMENT_IDS = new Set(["divRplyFwdMsg", "appendonsend"]);
|
|
59
|
+
// A style value may carry a remote load (url(), @import) or legacy script (expression()).
|
|
60
|
+
const SAFE_STYLE_VALUE = /^(?!.*(?:url\s*\(|expression|@import|javascript:)).*$/i;
|
|
61
|
+
const STYLE_PROPERTIES = [
|
|
62
|
+
"color",
|
|
63
|
+
"background-color",
|
|
64
|
+
"font-weight",
|
|
65
|
+
"font-style",
|
|
66
|
+
"font-size",
|
|
67
|
+
"font-family",
|
|
68
|
+
"text-decoration",
|
|
69
|
+
"text-align",
|
|
70
|
+
"line-height",
|
|
71
|
+
"width",
|
|
72
|
+
"max-width",
|
|
73
|
+
"vertical-align",
|
|
74
|
+
...["padding", "margin", "border"].flatMap((base) => [
|
|
75
|
+
base,
|
|
76
|
+
`${base}-top`,
|
|
77
|
+
`${base}-right`,
|
|
78
|
+
`${base}-bottom`,
|
|
79
|
+
`${base}-left`,
|
|
80
|
+
]),
|
|
81
|
+
];
|
|
82
|
+
const ALLOWED_STYLES = Object.fromEntries(STYLE_PROPERTIES.map((property) => [property, [SAFE_STYLE_VALUE]]));
|
|
83
|
+
// Relative, protocol-relative and backslash URLs would resolve against the app origin in the srcdoc frame
|
|
84
|
+
// and send a cookie-carrying same-origin request, so only absolute targets are kept.
|
|
85
|
+
const ABSOLUTE_IMAGE_SRC = /^https?:\/\//i;
|
|
86
|
+
const ABSOLUTE_LINK_HREF = /^(?:https?:\/\/|mailto:|tel:)/i;
|
|
87
|
+
function withoutAttributeUnless(attribs, name, allowed) {
|
|
88
|
+
const value = attribs[name];
|
|
89
|
+
if (value === undefined || allowed.test(value.trim()))
|
|
90
|
+
return attribs;
|
|
91
|
+
const { [name]: _dropped, ...rest } = attribs;
|
|
92
|
+
return rest;
|
|
93
|
+
}
|
|
94
|
+
function withoutIdUnlessQuoteMarker(attribs) {
|
|
95
|
+
const id = attribs["id"];
|
|
96
|
+
if (id === undefined || QUOTE_ELEMENT_IDS.has(id.trim()))
|
|
97
|
+
return attribs;
|
|
98
|
+
const { id: _dropped, ...rest } = attribs;
|
|
99
|
+
return rest;
|
|
100
|
+
}
|
|
101
|
+
export function sanitizeInboundHtml(html) {
|
|
102
|
+
const clean = sanitizeHtml(html, {
|
|
103
|
+
allowedTags: ALLOWED_TAGS,
|
|
104
|
+
allowedAttributes: ALLOWED_ATTRIBUTES,
|
|
105
|
+
allowedStyles: { "*": ALLOWED_STYLES },
|
|
106
|
+
allowedClasses: { div: QUOTE_CLASS_NAMES, blockquote: QUOTE_CLASS_NAMES },
|
|
107
|
+
allowedSchemes: ["http", "https", "mailto", "tel"],
|
|
108
|
+
allowedSchemesByTag: { img: ["http", "https"] },
|
|
109
|
+
allowProtocolRelative: false,
|
|
110
|
+
transformTags: {
|
|
111
|
+
div: (tagName, attribs) => ({ tagName, attribs: withoutIdUnlessQuoteMarker(attribs) }),
|
|
112
|
+
blockquote: (tagName, attribs) => ({
|
|
113
|
+
tagName,
|
|
114
|
+
attribs: withoutAttributeUnless(attribs, "type", /^cite$/),
|
|
115
|
+
}),
|
|
116
|
+
a: (tagName, attribs) => ({
|
|
117
|
+
tagName,
|
|
118
|
+
attribs: {
|
|
119
|
+
...withoutAttributeUnless(attribs, "href", ABSOLUTE_LINK_HREF),
|
|
120
|
+
target: "_blank",
|
|
121
|
+
rel: "noopener noreferrer",
|
|
122
|
+
},
|
|
123
|
+
}),
|
|
124
|
+
img: (tagName, attribs) => ({
|
|
125
|
+
tagName,
|
|
126
|
+
attribs: withoutAttributeUnless(attribs, "src", ABSOLUTE_IMAGE_SRC),
|
|
127
|
+
}),
|
|
128
|
+
},
|
|
129
|
+
// An image whose src was stripped (cid:, data:, other scheme) is only a broken placeholder.
|
|
130
|
+
exclusiveFilter: (frame) => frame.tag === "img" && frame.attribs["src"] === undefined,
|
|
131
|
+
}).trim();
|
|
132
|
+
return clean.length === 0 || Buffer.byteLength(clean, "utf8") > BODY_HTML_MAX_BYTES
|
|
133
|
+
? null
|
|
134
|
+
: clean;
|
|
135
|
+
}
|
|
@@ -13,6 +13,7 @@ import { INBOUND_MAIL_PROVIDER_EXTENSION } from "./constants.js";
|
|
|
13
13
|
// `options` in the extension usage is an engine payload (unknown), so
|
|
14
14
|
// validate its structure instead of casting blindly (patterned after
|
|
15
15
|
// isMailTransportPlugin).
|
|
16
|
+
// guard:dup-ok type guard over this plugin's own two members; only the guard shape is shared
|
|
16
17
|
export function isInboundMailProviderPlugin(o) {
|
|
17
18
|
return (typeof o === "object" &&
|
|
18
19
|
o !== null &&
|
|
@@ -268,43 +268,39 @@ async function dropTenantRunQueued(db, jobName, bullJobId, meta) {
|
|
|
268
268
|
}));
|
|
269
269
|
}
|
|
270
270
|
const log = createFallbackLogger("job-run-logger");
|
|
271
|
-
|
|
272
|
-
// fail the enqueue, skip the run-row write or turn a completed run into a
|
|
273
|
-
// BullMQ retry. A row-level-security rejection is logged louder (a missing or wrong tenant scope), never rethrown.
|
|
274
|
-
export async function isolateTenantRunWrite(write, jobName, bullJobId) {
|
|
271
|
+
async function isolateTenantWrite(write, jobName, bullJobId, messages) {
|
|
275
272
|
try {
|
|
276
273
|
await write();
|
|
277
274
|
}
|
|
278
275
|
catch (e) {
|
|
279
276
|
if (isRowLevelSecurityViolation(e)) {
|
|
280
|
-
log.error(
|
|
277
|
+
log.error(messages.rejected, { jobName, bullJobId });
|
|
281
278
|
return;
|
|
282
279
|
}
|
|
283
|
-
log.error(
|
|
280
|
+
log.error(messages.failed, {
|
|
284
281
|
jobName,
|
|
285
282
|
bullJobId,
|
|
286
283
|
error: e instanceof Error ? e.message : String(e),
|
|
287
284
|
});
|
|
288
285
|
}
|
|
289
286
|
}
|
|
287
|
+
// The tenant run state is an optional side write: a throw here must not
|
|
288
|
+
// fail the enqueue, skip the run-row write or turn a completed run into a
|
|
289
|
+
// BullMQ retry. A row-level-security rejection is logged louder (a missing or wrong tenant scope), never rethrown.
|
|
290
|
+
export async function isolateTenantRunWrite(write, jobName, bullJobId) {
|
|
291
|
+
await isolateTenantWrite(write, jobName, bullJobId, {
|
|
292
|
+
rejected: "tenant job run state write rejected by row level security: missing or wrong tenant scope",
|
|
293
|
+
failed: "tenant job run state write failed",
|
|
294
|
+
});
|
|
295
|
+
}
|
|
290
296
|
// The tenant failure record is an optional side write: a throw here must not
|
|
291
297
|
// skip the run-row update or turn a completed run into a BullMQ retry. A row-level-security rejection is
|
|
292
298
|
// logged louder (a missing or wrong tenant scope), never rethrown.
|
|
293
299
|
async function isolateTenantFailureWrite(write, jobName, bullJobId) {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
if (isRowLevelSecurityViolation(e)) {
|
|
299
|
-
log.error("tenant job failure record write rejected by row level security: missing or wrong tenant scope", { jobName, bullJobId });
|
|
300
|
-
return;
|
|
301
|
-
}
|
|
302
|
-
log.error("tenant job failure record write failed", {
|
|
303
|
-
jobName,
|
|
304
|
-
bullJobId,
|
|
305
|
-
error: e instanceof Error ? e.message : String(e),
|
|
306
|
-
});
|
|
307
|
-
}
|
|
300
|
+
await isolateTenantWrite(write, jobName, bullJobId, {
|
|
301
|
+
rejected: "tenant job failure record write rejected by row level security: missing or wrong tenant scope",
|
|
302
|
+
failed: "tenant job failure record write failed",
|
|
303
|
+
});
|
|
308
304
|
}
|
|
309
305
|
export function createJobRunLogger(opts) {
|
|
310
306
|
const { db } = opts;
|
|
@@ -13,45 +13,43 @@ async function loadBooks(ctx) {
|
|
|
13
13
|
const txRows = await ctx.db.selectMany(transactionTable, { tenantId: ctx.user.tenantId });
|
|
14
14
|
return { accounts: toAccounts(accountRows), entries: toEntries(txRows) };
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
export function createBalancesReportHandler(access = DEFAULT_LEDGER_ACCESS) {
|
|
16
|
+
function createPeriodReportHandler(report, access) {
|
|
18
17
|
return {
|
|
19
|
-
name:
|
|
18
|
+
name: report.name,
|
|
20
19
|
schema: periodSchema,
|
|
21
20
|
access,
|
|
22
|
-
description:
|
|
21
|
+
description: report.description,
|
|
23
22
|
handler: async (query, ctx) => {
|
|
24
23
|
const period = periodSchema.parse(query);
|
|
25
24
|
const { accounts, entries } = await loadBooks(ctx);
|
|
26
|
-
return
|
|
25
|
+
return report.compute(accounts, entries, period);
|
|
27
26
|
},
|
|
28
27
|
};
|
|
29
28
|
}
|
|
29
|
+
const BALANCES_REPORT = {
|
|
30
|
+
name: "report:balances",
|
|
31
|
+
description: "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.",
|
|
32
|
+
compute: accountBalances,
|
|
33
|
+
};
|
|
34
|
+
const INCOME_STATEMENT_REPORT = {
|
|
35
|
+
name: "report:income-statement",
|
|
36
|
+
description: "Returns income minus expense over an optional from/to period; use it for a profit-and-loss statement.",
|
|
37
|
+
compute: incomeStatement,
|
|
38
|
+
};
|
|
39
|
+
const BALANCE_SHEET_REPORT = {
|
|
40
|
+
name: "report:balance-sheet",
|
|
41
|
+
description: "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.",
|
|
42
|
+
compute: balanceSheet,
|
|
43
|
+
};
|
|
44
|
+
// Per-account balances (natural sign) + the trial balance (Σ raw = 0 invariant).
|
|
45
|
+
export function createBalancesReportHandler(access = DEFAULT_LEDGER_ACCESS) {
|
|
46
|
+
return createPeriodReportHandler(BALANCES_REPORT, access);
|
|
47
|
+
}
|
|
30
48
|
// GuV — income − expense over the period.
|
|
31
49
|
export function createIncomeStatementHandler(access = DEFAULT_LEDGER_ACCESS) {
|
|
32
|
-
return
|
|
33
|
-
name: "report:income-statement",
|
|
34
|
-
schema: periodSchema,
|
|
35
|
-
access,
|
|
36
|
-
description: "Returns income minus expense over an optional from/to period; use it for a profit-and-loss statement.",
|
|
37
|
-
handler: async (query, ctx) => {
|
|
38
|
-
const period = periodSchema.parse(query);
|
|
39
|
-
const { accounts, entries } = await loadBooks(ctx);
|
|
40
|
-
return incomeStatement(accounts, entries, period);
|
|
41
|
-
},
|
|
42
|
-
};
|
|
50
|
+
return createPeriodReportHandler(INCOME_STATEMENT_REPORT, access);
|
|
43
51
|
}
|
|
44
52
|
// Bilanz as of `to` — current result folded into equity so it balances.
|
|
45
53
|
export function createBalanceSheetHandler(access = DEFAULT_LEDGER_ACCESS) {
|
|
46
|
-
return
|
|
47
|
-
name: "report:balance-sheet",
|
|
48
|
-
schema: periodSchema,
|
|
49
|
-
access,
|
|
50
|
-
description: "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.",
|
|
51
|
-
handler: async (query, ctx) => {
|
|
52
|
-
const period = periodSchema.parse(query);
|
|
53
|
-
const { accounts, entries } = await loadBooks(ctx);
|
|
54
|
-
return balanceSheet(accounts, entries, period);
|
|
55
|
-
},
|
|
56
|
-
};
|
|
54
|
+
return createPeriodReportHandler(BALANCE_SHEET_REPORT, access);
|
|
57
55
|
}
|
package/dist/ledger/recurring.js
CHANGED
|
@@ -35,6 +35,7 @@ function monthIndex(ym) {
|
|
|
35
35
|
const [y, m] = ym.split("-");
|
|
36
36
|
return Number(y) * 12 + (Number(m) - 1);
|
|
37
37
|
}
|
|
38
|
+
// guard:dup-ok ledger month key YYYY-MM; look-alike month-index helpers return other formats
|
|
38
39
|
function indexToMonth(index) {
|
|
39
40
|
const year = Math.floor(index / 12);
|
|
40
41
|
const month = (index % 12) + 1;
|
|
@@ -10,7 +10,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
10
10
|
// - extension: a screen-schema section with
|
|
11
11
|
// component: { react: { __component: NOTES_SECTION_EXTENSION_NAME } }
|
|
12
12
|
// (RenderEdit passes { entityName, entityId }).
|
|
13
|
-
import { formatWhen, useDispatcher, usePrimitives, useQuery, useTranslation, } from "@cosmicdrift/kumiko-renderer";
|
|
13
|
+
import { formatWhen, useDispatcher, useLocale, usePrimitives, useQuery, useTranslation, } from "@cosmicdrift/kumiko-renderer";
|
|
14
14
|
import { useState } from "react";
|
|
15
15
|
import { NotesHistoryHandlers, NotesHistoryQueries } from "./constants.js";
|
|
16
16
|
// Matches @cosmicdrift/kumiko-framework/crypto PII_ERASED_SENTINEL — cannot
|
|
@@ -22,6 +22,7 @@ function displayAuthorName(authorName, unknownLabel) {
|
|
|
22
22
|
export function NotesSection({ entityName, entityId, }) {
|
|
23
23
|
const { Banner, Button, Grid, Heading, Text, Input } = usePrimitives();
|
|
24
24
|
const t = useTranslation();
|
|
25
|
+
const locale = useLocale().locale();
|
|
25
26
|
const dispatcher = useDispatcher();
|
|
26
27
|
const enabled = entityId !== null;
|
|
27
28
|
const notes = useQuery(NotesHistoryQueries.noteList, {
|
|
@@ -85,6 +86,6 @@ export function NotesSection({ entityName, entityId, }) {
|
|
|
85
86
|
addNote();
|
|
86
87
|
} }), _jsxs("div", { className: "flex items-center justify-between gap-2", children: [_jsx(Text, { variant: "small", children: t("notesHistory.section.shortcutHint") }), _jsx(Button, { variant: "primary", disabled: busy || draft.trim() === "", onClick: () => addNote(), testId: "notes-section-add", children: busy ? t("notesHistory.section.working") : t("notesHistory.section.add") })] }), errorKey !== null && (_jsx(Banner, { variant: "error", testId: "notes-section-action-error", children: _jsx(Text, { children: t(errorKey) }) }))] }), _jsxs("div", { className: "flex flex-col gap-3", "data-testid": "notes-section-history", children: [_jsx(Heading, { variant: "section", children: t("notesHistory.section.historyTitle") }), rows.length === 0 ? (_jsx(Text, { variant: "small", children: t("notesHistory.section.empty") })) : (_jsx("div", { className: "flex flex-col divide-y", children: rows.map((n) => (_jsxs("div", { "data-testid": `notes-section-row-${n.id}`, className: "flex flex-col gap-1 py-3 first:pt-0 last:pb-0", children: [_jsx(Text, { testId: `notes-section-body-${n.id}`, children: n.body }), _jsx(Text, { variant: "small", testId: `notes-section-meta-${n.id}`, children: t("notesHistory.section.meta", {
|
|
87
88
|
author: displayAuthorName(n.authorName, t("notesHistory.section.authorUnknown")),
|
|
88
|
-
date: formatWhen(n.insertedAt),
|
|
89
|
+
date: formatWhen(n.insertedAt, locale),
|
|
89
90
|
}) })] }, n.id))) }))] })] }));
|
|
90
91
|
}
|
|
@@ -2,6 +2,7 @@ import { EXT_TOKEN_VERIFIER, } from "@cosmicdrift/kumiko-bundled-features/auth-f
|
|
|
2
2
|
import { PAT_TOKEN_PREFIX } from "@cosmicdrift/kumiko-framework/api";
|
|
3
3
|
import { deriveEntityTableMeta } from "@cosmicdrift/kumiko-framework/db";
|
|
4
4
|
import { defineFeature, } from "@cosmicdrift/kumiko-framework/engine";
|
|
5
|
+
import { createLateBoundSlot, readFeatureExportFn } from "../shared/index.js";
|
|
5
6
|
import { availabilityQuery } from "./handlers/availability.query.js";
|
|
6
7
|
import { buildAvailableScopesQuery } from "./handlers/available-scopes.query.js";
|
|
7
8
|
import { createPatCreateHandler } from "./handlers/create.write.js";
|
|
@@ -23,15 +24,7 @@ const PAT_REVOKE_TRIGGERING_FIELDS = ["passwordHash"];
|
|
|
23
24
|
// exports — run{Prod,Dev}App call this once a concrete db is available,
|
|
24
25
|
// mirrors sessions' own bindAutoRevokeFromFeature/bindAutoRevokeOnPasswordChange.
|
|
25
26
|
export function bindPatAutoRevokeOnPasswordChangeFromFeature(feature) {
|
|
26
|
-
|
|
27
|
-
if (exports && typeof exports === "object" && "bindAutoRevokeOnPasswordChange" in exports) {
|
|
28
|
-
const { bindAutoRevokeOnPasswordChange } = exports;
|
|
29
|
-
if (typeof bindAutoRevokeOnPasswordChange === "function") {
|
|
30
|
-
// @cast-boundary feature-exports — feature.exports is untyped by design
|
|
31
|
-
return bindAutoRevokeOnPasswordChange;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return undefined;
|
|
27
|
+
return readFeatureExportFn(feature, "bindAutoRevokeOnPasswordChange");
|
|
35
28
|
}
|
|
36
29
|
// Personal Access Tokens — long-lived, revocable bearer credentials for the
|
|
37
30
|
// HTTP API. Like `sessions`, the hot-path resolver is NOT a handler: it runs on
|
|
@@ -85,12 +78,12 @@ export function createPersonalAccessTokensFeature(options) {
|
|
|
85
78
|
// run{Prod,Dev}App has a real db handle.
|
|
86
79
|
// Explicit option wins; the runtime binding is replaceable so a second boot of the same
|
|
87
80
|
// feature instance binds its own database.
|
|
88
|
-
|
|
81
|
+
const autoRevokeSlot = createLateBoundSlot();
|
|
89
82
|
r.hook({
|
|
90
83
|
type: "postSave",
|
|
91
84
|
target: { allOf: "user" },
|
|
92
85
|
handler: async (result) => {
|
|
93
|
-
const autoRevokeOnPasswordChange = options.autoRevokeOnPasswordChange ??
|
|
86
|
+
const autoRevokeOnPasswordChange = options.autoRevokeOnPasswordChange ?? autoRevokeSlot.current();
|
|
94
87
|
// skip: nothing bound — same late-bind pattern as sessions/feature.ts
|
|
95
88
|
if (!autoRevokeOnPasswordChange)
|
|
96
89
|
return;
|
|
@@ -104,13 +97,7 @@ export function createPersonalAccessTokensFeature(options) {
|
|
|
104
97
|
await autoRevokeOnPasswordChange(String(result.id));
|
|
105
98
|
},
|
|
106
99
|
});
|
|
107
|
-
const bindAutoRevokeOnPasswordChange =
|
|
108
|
-
boundAutoRevoke = revoker;
|
|
109
|
-
return () => {
|
|
110
|
-
if (boundAutoRevoke === revoker)
|
|
111
|
-
boundAutoRevoke = undefined;
|
|
112
|
-
};
|
|
113
|
-
};
|
|
100
|
+
const bindAutoRevokeOnPasswordChange = autoRevokeSlot.bind;
|
|
114
101
|
const handlers = {
|
|
115
102
|
create: r.writeHandler(createPatCreateHandler({ mfaVerifier: options.mfaVerifier })),
|
|
116
103
|
revoke: r.writeHandler(revokePatWrite),
|
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
import { insertOne } from "@cosmicdrift/kumiko-framework/db";
|
|
2
2
|
import { createSystemUser, defineWriteHandler, } from "@cosmicdrift/kumiko-framework/engine";
|
|
3
|
-
import { UnprocessableError, writeFailure } from "@cosmicdrift/kumiko-framework/errors";
|
|
4
3
|
import { generateId } from "@cosmicdrift/kumiko-framework/utils";
|
|
5
4
|
import { Temporal } from "@cosmicdrift/kumiko-types/temporal";
|
|
6
5
|
import * as z from "zod";
|
|
7
|
-
import { encryptForDirectWrite, verifyPassword } from "../../shared/index.js";
|
|
6
|
+
import { encryptForDirectWrite, unprocessable, verifyPassword } from "../../shared/index.js";
|
|
8
7
|
import { UserQueries } from "../../user/index.js";
|
|
9
8
|
import { mintPatToken } from "../hash.js";
|
|
10
9
|
import { apiTokenEntity, apiTokenTable } from "../schema/api-token.js";
|
|
11
10
|
import { API_TOKEN_ENTITY_NAME, PAT_DEFAULT_EXPIRES_IN_DAYS, PatErrors } from "../web/constants.js";
|
|
12
11
|
// @wrapper-known error-helper
|
|
13
12
|
function reauthFailed() {
|
|
14
|
-
return
|
|
15
|
-
i18nKey: "errors.reauthRequired",
|
|
16
|
-
}));
|
|
13
|
+
return unprocessable(PatErrors.reauthRequired, "errors.reauthRequired");
|
|
17
14
|
}
|
|
18
15
|
// Mint a PAT for the calling user in their active tenant. The plaintext token
|
|
19
16
|
// is returned ONCE (data.token) and never again — only the hash is stored.
|
|
@@ -2,6 +2,10 @@ import { type AccessRule } from "@cosmicdrift/kumiko-framework/engine";
|
|
|
2
2
|
import * as z from "zod";
|
|
3
3
|
export declare function createDeleteHandler(access?: AccessRule): import("@cosmicdrift/kumiko-types/define-handler").WriteHandlerDefinition<"delete", z.ZodObject<{
|
|
4
4
|
key: z.ZodString;
|
|
5
|
+
scope: z.ZodOptional<z.ZodEnum<{
|
|
6
|
+
system: "system";
|
|
7
|
+
tenant: "tenant";
|
|
8
|
+
}>>;
|
|
5
9
|
}, z.core.$strip>, {
|
|
6
10
|
key: string;
|
|
7
11
|
}, import("@cosmicdrift/kumiko-types/event-type-map").KumikoEventTypeMap, undefined, undefined>;
|
|
@@ -1,33 +1,38 @@
|
|
|
1
1
|
import { defineWriteHandler } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
-
import { failNotFound } from "@cosmicdrift/kumiko-framework/errors";
|
|
2
|
+
import { failNotFound, writeFailure } from "@cosmicdrift/kumiko-framework/errors";
|
|
3
3
|
import * as z from "zod";
|
|
4
4
|
import { announceSecretChange } from "../announce-secret-change.js";
|
|
5
5
|
import { JOIN_REQUEST_TRANSACTION_REASON, requireSecretsContext } from "../feature.js";
|
|
6
|
+
import { resolveSecretTarget, secretScopeSchema } from "../secret-scope.js";
|
|
6
7
|
import { DEFAULT_SECRETS_ACCESS, SecretsHandlers } from "../web/constants.js";
|
|
7
8
|
import { checkSecretKeyWrite } from "../write-gate.js";
|
|
8
9
|
export function createDeleteHandler(access = DEFAULT_SECRETS_ACCESS) {
|
|
9
10
|
return defineWriteHandler({
|
|
10
11
|
name: "delete",
|
|
11
|
-
description: "Permanently removes the stored secret under the given key for the caller's tenant, breaking every feature that depends on that credential.",
|
|
12
|
+
description: "Permanently removes the stored secret under the given key for the caller's tenant (or, with scope system and the SystemAdmin role, the platform-wide one), breaking every feature that depends on that credential.",
|
|
12
13
|
agent: { risk: "high" },
|
|
13
14
|
schema: z.object({
|
|
14
15
|
key: z.string().min(1).max(100),
|
|
16
|
+
scope: secretScopeSchema,
|
|
15
17
|
}),
|
|
16
18
|
access,
|
|
17
19
|
escapeHatch: { grants: ["unsafeRaw"], reason: JOIN_REQUEST_TRANSACTION_REASON },
|
|
18
20
|
handler: async (event, ctx) => {
|
|
19
21
|
const secrets = requireSecretsContext({ secrets: ctx.services.secrets, user: ctx.user }, SecretsHandlers.delete).withRunner(ctx.db.unsafeRaw());
|
|
22
|
+
const target = resolveSecretTarget(event.user, event.payload.scope);
|
|
23
|
+
if (!target.ok)
|
|
24
|
+
return writeFailure(target.error);
|
|
20
25
|
const gate = checkSecretKeyWrite(ctx.registry, event.user.roles, event.payload.key, {
|
|
21
26
|
allowUndeclared: true,
|
|
22
27
|
});
|
|
23
28
|
if (!gate.ok)
|
|
24
29
|
return gate.failure;
|
|
25
|
-
const removed = await secrets.delete(
|
|
30
|
+
const removed = await secrets.delete(target.tenantId, event.payload.key, {
|
|
26
31
|
deletedBy: event.user.id,
|
|
27
32
|
});
|
|
28
33
|
if (!removed)
|
|
29
34
|
return failNotFound("tenant-secret", event.payload.key);
|
|
30
|
-
announceSecretChange(ctx,
|
|
35
|
+
announceSecretChange(ctx, target.tenantId, event.payload.key);
|
|
31
36
|
return { isSuccess: true, data: { key: event.payload.key } };
|
|
32
37
|
},
|
|
33
38
|
});
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { type AccessRule } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
2
|
import * as z from "zod";
|
|
3
|
-
export declare function createListHandler(access?: AccessRule): import("@cosmicdrift/kumiko-types/define-handler").QueryHandlerDefinition<"list", z.ZodObject<{
|
|
3
|
+
export declare function createListHandler(access?: AccessRule): import("@cosmicdrift/kumiko-types/define-handler").QueryHandlerDefinition<"list", z.ZodObject<{
|
|
4
|
+
scope: z.ZodOptional<z.ZodEnum<{
|
|
5
|
+
system: "system";
|
|
6
|
+
tenant: "tenant";
|
|
7
|
+
}>>;
|
|
8
|
+
}, z.core.$strip>, {
|
|
4
9
|
key: string;
|
|
5
10
|
redactedPreview: string | null;
|
|
6
11
|
hint: string | null;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { defineQueryHandler } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
2
|
import * as z from "zod";
|
|
3
|
+
import { resolveSecretTarget, secretScopeSchema } from "../secret-scope.js";
|
|
3
4
|
import { tenantSecretsTable } from "../table.js";
|
|
4
5
|
import { DEFAULT_SECRETS_ACCESS } from "../web/constants.js";
|
|
5
6
|
// Lists all secrets for the current tenant. Returns redactedPreview, never
|
|
@@ -8,11 +9,14 @@ import { DEFAULT_SECRETS_ACCESS } from "../web/constants.js";
|
|
|
8
9
|
export function createListHandler(access = DEFAULT_SECRETS_ACCESS) {
|
|
9
10
|
return defineQueryHandler({
|
|
10
11
|
name: "list",
|
|
11
|
-
description: "Lists the secrets stored for the caller's tenant by key with a redacted preview, hint, key version and rotation date — never the plaintext; use it to check which credentials are set.",
|
|
12
|
-
schema: z.object({}),
|
|
12
|
+
description: "Lists the secrets stored for the caller's tenant (or, with scope system and the SystemAdmin role, the platform-wide ones) by key with a redacted preview, hint, key version and rotation date — never the plaintext; use it to check which credentials are set.",
|
|
13
|
+
schema: z.object({ scope: secretScopeSchema }),
|
|
13
14
|
access,
|
|
14
15
|
handler: async (event, ctx) => {
|
|
15
|
-
const
|
|
16
|
+
const target = resolveSecretTarget(event.user, event.payload.scope);
|
|
17
|
+
if (!target.ok)
|
|
18
|
+
throw target.error;
|
|
19
|
+
const rows = await ctx.db.selectMany(tenantSecretsTable, { tenantId: target.tenantId }, {
|
|
16
20
|
orderBy: { col: "key", direction: "asc" },
|
|
17
21
|
});
|
|
18
22
|
return rows.map((r) => ({
|
|
@@ -5,6 +5,10 @@ export declare function createSetHandler(access?: AccessRule): import("@cosmicdr
|
|
|
5
5
|
value: z.ZodString;
|
|
6
6
|
redactedPreview: z.ZodOptional<z.ZodString>;
|
|
7
7
|
hint: z.ZodOptional<z.ZodString>;
|
|
8
|
+
scope: z.ZodOptional<z.ZodEnum<{
|
|
9
|
+
system: "system";
|
|
10
|
+
tenant: "tenant";
|
|
11
|
+
}>>;
|
|
8
12
|
}, z.core.$strip>, {
|
|
9
13
|
key: string;
|
|
10
14
|
redactedPreview: string;
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { defineWriteHandler } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
+
import { writeFailure } from "@cosmicdrift/kumiko-framework/errors";
|
|
2
3
|
import * as z from "zod";
|
|
3
4
|
import { announceSecretChange } from "../announce-secret-change.js";
|
|
4
5
|
import { JOIN_REQUEST_TRANSACTION_REASON, requireSecretsContext } from "../feature.js";
|
|
6
|
+
import { resolveSecretTarget, secretScopeSchema } from "../secret-scope.js";
|
|
5
7
|
import { DEFAULT_SECRETS_ACCESS, SecretsHandlers } from "../web/constants.js";
|
|
6
8
|
import { checkSecretKeyWrite, checkSecretValue } from "../write-gate.js";
|
|
7
9
|
export function createSetHandler(access = DEFAULT_SECRETS_ACCESS) {
|
|
8
10
|
return defineWriteHandler({
|
|
9
11
|
name: "set",
|
|
10
|
-
description: "Stores or replaces one encrypted secret for the caller's tenant under the given key, together with a redacted preview and optional hint; use it to enter or rotate a credential.",
|
|
12
|
+
description: "Stores or replaces one encrypted secret for the caller's tenant (or, with scope system and the SystemAdmin role, the platform-wide one) under the given key, together with a redacted preview and optional hint; use it to enter or rotate a credential.",
|
|
11
13
|
// `value` is the plaintext credential: as a tool call it would travel to
|
|
12
14
|
// the model provider before it is ever encrypted at rest.
|
|
13
15
|
agent: { expose: false },
|
|
@@ -19,12 +21,16 @@ export function createSetHandler(access = DEFAULT_SECRETS_ACCESS) {
|
|
|
19
21
|
// handler derives a generic one (first-3-chars + bullets).
|
|
20
22
|
redactedPreview: z.string().max(50).optional(),
|
|
21
23
|
hint: z.string().max(200).optional(),
|
|
24
|
+
scope: secretScopeSchema,
|
|
22
25
|
}),
|
|
23
26
|
access,
|
|
24
27
|
escapeHatch: { grants: ["unsafeRaw"], reason: JOIN_REQUEST_TRANSACTION_REASON },
|
|
25
28
|
handler: async (event, ctx) => {
|
|
26
29
|
const secrets = requireSecretsContext({ secrets: ctx.services.secrets, user: ctx.user }, SecretsHandlers.set).withRunner(ctx.db.unsafeRaw());
|
|
27
|
-
const { key, value, redactedPreview, hint } = event.payload;
|
|
30
|
+
const { key, value, redactedPreview, hint, scope } = event.payload;
|
|
31
|
+
const target = resolveSecretTarget(event.user, scope);
|
|
32
|
+
if (!target.ok)
|
|
33
|
+
return writeFailure(target.error);
|
|
28
34
|
// Preview-priority: explicit payload param > feature-declared redact
|
|
29
35
|
// (via r.secret()) > generic default. A feature that declared a
|
|
30
36
|
// domain-aware redact (Stripe keys: "sk_test...2345") wins over the
|
|
@@ -39,12 +45,12 @@ export function createSetHandler(access = DEFAULT_SECRETS_ACCESS) {
|
|
|
39
45
|
const redactFn = redactedPreview
|
|
40
46
|
? () => redactedPreview
|
|
41
47
|
: (featureRedact ?? defaultRedact);
|
|
42
|
-
await secrets.set(
|
|
48
|
+
await secrets.set(target.tenantId, key, value, {
|
|
43
49
|
redact: redactFn,
|
|
44
50
|
...(hint ? { hint } : {}),
|
|
45
51
|
updatedBy: event.user.id,
|
|
46
52
|
});
|
|
47
|
-
announceSecretChange(ctx,
|
|
53
|
+
announceSecretChange(ctx, target.tenantId, key);
|
|
48
54
|
return {
|
|
49
55
|
isSuccess: true,
|
|
50
56
|
data: { key, redactedPreview: redactedPreview ?? redactFn(value) },
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type SessionUser, type TenantId } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
+
import { AccessDeniedError } from "@cosmicdrift/kumiko-framework/errors";
|
|
3
|
+
import * as z from "zod";
|
|
4
|
+
export declare const SYSTEM_ADMIN_ROLE = "SystemAdmin";
|
|
5
|
+
export declare const secretScopeSchema: z.ZodOptional<z.ZodEnum<{
|
|
6
|
+
system: "system";
|
|
7
|
+
tenant: "tenant";
|
|
8
|
+
}>>;
|
|
9
|
+
export type SecretScope = z.infer<typeof secretScopeSchema>;
|
|
10
|
+
export type SecretTarget = {
|
|
11
|
+
readonly ok: true;
|
|
12
|
+
readonly tenantId: TenantId;
|
|
13
|
+
} | {
|
|
14
|
+
readonly ok: false;
|
|
15
|
+
readonly error: AccessDeniedError;
|
|
16
|
+
};
|
|
17
|
+
export declare function resolveSecretTarget(user: Pick<SessionUser, "tenantId" | "roles">, scope: SecretScope): SecretTarget;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SYSTEM_TENANT_ID, } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
+
import { AccessDeniedError } from "@cosmicdrift/kumiko-framework/errors";
|
|
3
|
+
import * as z from "zod";
|
|
4
|
+
export const SYSTEM_ADMIN_ROLE = "SystemAdmin";
|
|
5
|
+
// "system" targets the platform-wide secrets under SYSTEM_TENANT_ID (settings a SystemAdmin
|
|
6
|
+
// edits for the whole app). The target is never taken from the payload, only chosen here.
|
|
7
|
+
export const secretScopeSchema = z.enum(["tenant", "system"]).optional();
|
|
8
|
+
export function resolveSecretTarget(user, scope) {
|
|
9
|
+
if (scope !== "system")
|
|
10
|
+
return { ok: true, tenantId: user.tenantId };
|
|
11
|
+
if (!user.roles.includes(SYSTEM_ADMIN_ROLE)) {
|
|
12
|
+
return {
|
|
13
|
+
ok: false,
|
|
14
|
+
error: new AccessDeniedError({ message: "system-scope secrets need the SystemAdmin role" }),
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
return { ok: true, tenantId: SYSTEM_TENANT_ID };
|
|
18
|
+
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { type FeatureDefinition } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
+
import type { Clock } from "@cosmicdrift/kumiko-types/tz-context";
|
|
2
3
|
import { type SessionAllOthersRevoker, type SessionMassRevoker } from "./session-callbacks.ts";
|
|
3
4
|
export type SessionsFeatureOptions = {
|
|
4
5
|
readonly autoRevokeOnPasswordChange?: SessionMassRevoker;
|
|
5
6
|
readonly expiresInMs?: number;
|
|
6
7
|
readonly adminAccess?: "admin" | "systemAdmin";
|
|
8
|
+
readonly clock?: Clock;
|
|
9
|
+
readonly lastActivityProbeSecret?: string;
|
|
7
10
|
};
|
|
8
11
|
export type BindAutoRevokeOnPasswordChange = (revoker: SessionMassRevoker) => () => void;
|
|
9
12
|
export type BindRevokeAllOtherSessions = (revoker: SessionAllOthersRevoker) => () => void;
|