@cosmicdrift/kumiko-bundled-features 0.387.0 → 0.389.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/agent-tools/index.d.ts +1 -1
- package/dist/agent-tools/index.js +1 -1
- package/dist/agent-tools/tool-dispatch.d.ts +12 -7
- package/dist/agent-tools/tool-dispatch.js +42 -31
- package/dist/audit/feature.js +1 -0
- package/dist/audit/handlers/audit-events.js +1 -1
- package/dist/auth-email-password/handlers/request-account-unlock.write.d.ts +1 -0
- package/dist/auth-email-password/handlers/request-account-unlock.write.js +1 -0
- package/dist/auth-email-password/handlers/request-email-verification.write.d.ts +1 -0
- package/dist/auth-email-password/handlers/request-email-verification.write.js +1 -0
- package/dist/auth-email-password/handlers/request-password-reset.write.d.ts +1 -0
- package/dist/auth-email-password/handlers/request-password-reset.write.js +1 -0
- package/dist/auth-email-password/handlers/signup-request.write.d.ts +1 -0
- package/dist/auth-email-password/handlers/signup-request.write.js +4 -0
- package/dist/auth-email-password/handlers/token-request-handler.d.ts +2 -0
- package/dist/auth-email-password/handlers/token-request-handler.js +5 -0
- package/dist/auth-email-password/magic-link-mail.d.ts +2 -0
- package/dist/auth-email-password/magic-link-mail.js +7 -3
- package/dist/auth-email-password/signup-activation.d.ts +1 -0
- package/dist/auth-email-password/signup-activation.js +1 -0
- package/dist/auth-email-password/web/auth-client.d.ts +2 -2
- package/dist/auth-email-password/web/auth-client.js +8 -4
- package/dist/auth-email-password/web/auth-redirect.d.ts +5 -1
- package/dist/auth-email-password/web/auth-redirect.js +20 -25
- package/dist/auth-email-password/web/default-auth-pages-gate.js +6 -3
- package/dist/auth-email-password/web/forgot-password-screen.d.ts +4 -1
- package/dist/auth-email-password/web/forgot-password-screen.js +7 -2
- 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/login-screen.js +11 -6
- package/dist/auth-email-password/web/reset-password-screen.js +7 -1
- package/dist/auth-email-password/web/return-path.d.ts +4 -0
- package/dist/auth-email-password/web/return-path.js +34 -0
- package/dist/auth-email-password/web/session.js +6 -1
- package/dist/auth-email-password/web/signup-complete-screen.js +11 -3
- package/dist/auth-email-password/web/signup-screen.d.ts +4 -1
- package/dist/auth-email-password/web/signup-screen.js +8 -3
- package/dist/auth-mfa/config.d.ts +1 -1
- package/dist/auth-mfa/config.js +3 -7
- package/dist/auth-mfa/feature-exports.d.ts +2 -2
- package/dist/auth-mfa/feature.js +8 -0
- package/dist/auth-mfa/mfa-status-checker.js +5 -3
- package/dist/auth-mfa/web/i18n.js +5 -1
- package/dist/auth-mfa/web/mfa-code-or-recovery-field.d.ts +11 -0
- package/dist/auth-mfa/web/mfa-code-or-recovery-field.js +12 -0
- package/dist/auth-mfa/web/mfa-disable-dialog.js +14 -3
- package/dist/auth-mfa/web/mfa-regenerate-recovery-dialog.js +14 -3
- package/dist/auth-mfa/web/mfa-setup-preauth-screen.js +10 -5
- package/dist/auth-mfa/web/mfa-verify-screen.js +26 -5
- package/dist/billing-foundation/checkout-core.d.ts +9 -14
- package/dist/billing-foundation/checkout-core.js +24 -39
- package/dist/billing-foundation/consumer-protection/confirmation-mail.js +8 -2
- package/dist/billing-foundation/consumer-protection/consent-gate.d.ts +1 -0
- package/dist/billing-foundation/consumer-protection/consent-gate.js +1 -0
- package/dist/billing-foundation/consumer-protection/issue-confirmation.js +9 -3
- package/dist/billing-foundation/consumer-protection/mail-notifications.js +3 -1
- package/dist/billing-foundation/consumer-protection/termination-receipt-limit.d.ts +4 -2
- package/dist/billing-foundation/consumer-protection/termination-receipt-limit.js +6 -5
- package/dist/billing-foundation/consumer-protection/termination-record.d.ts +5 -1
- package/dist/billing-foundation/consumer-protection/termination-record.js +27 -17
- package/dist/billing-foundation/consumer-protection/termination-request.js +12 -7
- package/dist/billing-foundation/consumer-protection/termination-revoke.js +12 -7
- package/dist/billing-foundation/consumer-protection/termination-texts.d.ts +1 -1
- package/dist/billing-foundation/consumer-protection/termination-texts.js +3 -0
- package/dist/billing-foundation/consumer-protection/withdrawal-period.d.ts +5 -2
- package/dist/billing-foundation/consumer-protection/withdrawal-period.js +8 -9
- package/dist/billing-foundation/events.d.ts +1 -0
- package/dist/billing-foundation/events.js +1 -0
- package/dist/billing-foundation/feature.js +3 -1
- package/dist/billing-foundation/handlers/billing-plans.query.js +35 -5
- package/dist/billing-foundation/handlers/create-checkout-session.write.js +1 -0
- package/dist/billing-foundation/handlers/plan-switch-preview.query.d.ts +13 -0
- package/dist/billing-foundation/handlers/plan-switch-preview.query.js +48 -0
- package/dist/billing-foundation/handlers/process-event.write.d.ts +6 -0
- package/dist/billing-foundation/handlers/process-event.write.js +8 -2
- package/dist/billing-foundation/handlers/start-plan-checkout.write.js +32 -5
- package/dist/billing-foundation/handlers/switch-plan.write.d.ts +2 -2
- package/dist/billing-foundation/handlers/switch-plan.write.js +56 -64
- package/dist/billing-foundation/handlers/sync-subscription.write.js +12 -1
- package/dist/billing-foundation/i18n.js +22 -0
- package/dist/billing-foundation/index.d.ts +1 -1
- package/dist/billing-foundation/plan-catalog.d.ts +21 -5
- package/dist/billing-foundation/plan-catalog.js +25 -16
- package/dist/billing-foundation/plan-switch.d.ts +12 -0
- package/dist/billing-foundation/plan-switch.js +60 -0
- package/dist/billing-foundation/types.d.ts +57 -1
- package/dist/billing-foundation/types.js +9 -0
- package/dist/billing-foundation/validate-options.js +17 -0
- package/dist/billing-foundation/web/billing-plans-panel.js +78 -32
- package/dist/billing-foundation/web/checkout-consent-dialog.d.ts +17 -3
- package/dist/billing-foundation/web/checkout-consent-dialog.js +14 -10
- package/dist/billing-foundation/web/constants.d.ts +4 -0
- package/dist/billing-foundation/web/constants.js +4 -0
- package/dist/billing-foundation/web/plan-price.d.ts +15 -0
- package/dist/billing-foundation/web/plan-price.js +32 -0
- package/dist/billing-foundation/web/plan-switch-confirm-dialog.d.ts +15 -0
- package/dist/billing-foundation/web/plan-switch-confirm-dialog.js +66 -0
- package/dist/cap-counter/cap-reservation.js +20 -7
- package/dist/cap-counter/enforce-cap.js +2 -1
- package/dist/cap-counter/feature.js +1 -0
- package/dist/cap-counter/stock-cap-guard.js +7 -1
- package/dist/cap-overview/feature.js +1 -0
- package/dist/channel-email/feature.js +1 -1
- package/dist/config/handlers/cascade.query.d.ts +5 -0
- package/dist/config/handlers/cascade.query.js +4 -3
- package/dist/config/handlers/set.write.js +12 -2
- package/dist/config/handlers/values.query.d.ts +5 -0
- package/dist/config/handlers/values.query.js +4 -3
- package/dist/config/write-helpers.d.ts +1 -0
- package/dist/config/write-helpers.js +18 -9
- package/dist/crypto-shredding/handlers/forget-subject.write.js +14 -11
- package/dist/custom-fields/lib/parse-serialized-field.js +1 -1
- package/dist/delivery/channel-context.js +6 -3
- package/dist/delivery/db/queries/preferences.js +2 -2
- package/dist/delivery/delivery-service.js +22 -7
- package/dist/delivery/feature.js +1 -0
- package/dist/delivery/handlers/preferences.query.d.ts +1 -1
- package/dist/delivery/handlers/preferences.query.js +20 -1
- package/dist/delivery/handlers/unsubscribe-page-chrome.query.js +1 -1
- package/dist/delivery/index.d.ts +1 -0
- package/dist/delivery/index.js +1 -0
- package/dist/delivery/system-channel-context.d.ts +15 -0
- package/dist/delivery/system-channel-context.js +5 -0
- package/dist/delivery/unsubscribe-link.d.ts +3 -1
- package/dist/delivery/unsubscribe-page-strings.d.ts +1 -0
- package/dist/delivery/unsubscribe-page-strings.js +1 -0
- package/dist/delivery/unsubscribe-page.d.ts +2 -0
- package/dist/delivery/unsubscribe-page.js +5 -0
- package/dist/delivery/unsubscribe.js +25 -7
- package/dist/document-ingest-foundation/append-missing-extract-event.d.ts +21 -0
- package/dist/document-ingest-foundation/append-missing-extract-event.js +42 -0
- package/dist/document-ingest-foundation/events.d.ts +11 -0
- package/dist/document-ingest-foundation/events.js +11 -0
- package/dist/document-ingest-foundation/index.d.ts +2 -1
- package/dist/document-ingest-foundation/index.js +2 -1
- package/dist/feature-toggles/feature.js +1 -0
- package/dist/file-foundation/index.d.ts +1 -1
- package/dist/file-foundation/index.js +1 -1
- package/dist/file-foundation/read-file-ref-content.d.ts +3 -0
- package/dist/file-foundation/read-file-ref-content.js +6 -1
- package/dist/file-provider-s3/env-named-feature.d.ts +0 -2
- package/dist/form-draft/db/queries/cleanup.js +2 -2
- package/dist/form-draft/decrypt-draft.js +5 -1
- package/dist/host-routing/dispatch.js +11 -20
- package/dist/host-routing/validate-options.js +3 -0
- package/dist/inbound-mail-foundation/feature.js +1 -0
- package/dist/inbound-mail-foundation/handlers/update-account.write.d.ts +2 -2
- package/dist/inbound-mail-foundation/handlers/update-account.write.js +12 -4
- package/dist/inbound-mail-foundation/i18n.js +0 -1
- package/dist/inbound-mail-foundation/screens.js +0 -3
- package/dist/inbound-mail-foundation/types.d.ts +4 -3
- package/dist/inbound-mail-foundation/watch-supervisor.js +28 -11
- package/dist/jobs/feature.d.ts +1 -0
- package/dist/jobs/feature.js +9 -4
- package/dist/jobs/handlers/tenant-failures.query.d.ts +1 -1
- package/dist/jobs/handlers/tenant-failures.query.js +45 -41
- package/dist/jobs/handlers/tenant-runs.query.d.ts +1 -1
- package/dist/jobs/handlers/tenant-runs.query.js +54 -50
- package/dist/jobs/job-run-logger.js +5 -4
- package/dist/ledger/web/index.js +1 -1
- package/dist/legal-pages/seed.d.ts +3 -1
- package/dist/legal-pages/seed.js +2 -2
- package/dist/mail-foundation/feature.d.ts +3 -3
- package/dist/mail-foundation/feature.js +3 -0
- package/dist/mail-transport-smtp/config-keys.js +1 -1
- package/dist/mail-transport-smtp/feature.js +6 -5
- package/dist/managed-pages/constants.d.ts +1 -0
- package/dist/managed-pages/constants.js +1 -0
- package/dist/managed-pages/feature.js +3 -1
- package/dist/managed-pages/index.d.ts +1 -0
- package/dist/managed-pages/index.js +1 -0
- package/dist/notes-history/handlers/add-note.write.js +1 -1
- package/dist/personal-access-tokens/feature.d.ts +1 -1
- package/dist/personal-access-tokens/feature.js +5 -0
- package/dist/renderer-pdf/render-table-pdf.d.ts +1 -1
- package/dist/renderer-pdf/render-table-pdf.js +22 -10
- package/dist/secrets/write-gate.js +8 -2
- package/dist/sessions/feature.d.ts +2 -2
- package/dist/sessions/feature.js +5 -0
- package/dist/sessions/index.d.ts +1 -1
- package/dist/sessions/index.js +1 -1
- package/dist/sessions/session-callbacks.d.ts +0 -2
- package/dist/sessions/session-callbacks.js +1 -3
- package/dist/shared/decrypt-stored-pii.d.ts +1 -0
- package/dist/shared/decrypt-stored-pii.js +6 -1
- package/dist/shared/index.d.ts +1 -1
- package/dist/shared/index.js +1 -1
- package/dist/shared/mail-template-body.d.ts +6 -2
- package/dist/shared/mail-template-body.js +7 -4
- package/dist/shared/purge-files-reaching-subject.d.ts +1 -0
- package/dist/shared/purge-files-reaching-subject.js +19 -2
- package/dist/shared/run-in-sub-transaction.js +5 -5
- package/dist/step-dispatcher/deliver-dispatch-request.js +16 -3
- package/dist/step-dispatcher/feature.js +1 -0
- package/dist/step-dispatcher/mail-runner.d.ts +1 -0
- package/dist/subscription-dodo/client.d.ts +17 -0
- package/dist/subscription-dodo/client.js +31 -0
- package/dist/subscription-dodo/constants.d.ts +12 -0
- package/dist/subscription-dodo/constants.js +19 -0
- package/dist/subscription-dodo/feature.d.ts +37 -0
- package/dist/subscription-dodo/feature.js +144 -0
- package/dist/subscription-dodo/index.d.ts +2 -0
- package/dist/subscription-dodo/index.js +4 -0
- package/dist/subscription-dodo/plugin-methods.d.ts +23 -0
- package/dist/subscription-dodo/plugin-methods.js +260 -0
- package/dist/subscription-dodo/runtime.d.ts +27 -0
- package/dist/subscription-dodo/runtime.js +89 -0
- package/dist/subscription-dodo/verify-webhook.d.ts +37 -0
- package/dist/subscription-dodo/verify-webhook.js +189 -0
- package/dist/subscription-stripe/feature.js +1 -0
- package/dist/subscription-stripe/runtime.js +7 -6
- package/dist/tags/feature.js +1 -0
- package/dist/template-resolver/api.d.ts +3 -2
- package/dist/template-resolver/api.js +24 -2
- package/dist/template-resolver/compile-document-body.js +1 -0
- package/dist/template-resolver/document-ops.d.ts +5 -0
- package/dist/template-resolver/document-ops.js +18 -2
- package/dist/template-resolver/feature.js +4 -4
- package/dist/template-resolver/handlers/bundle-import.js +3 -3
- package/dist/template-resolver/handlers/copy-locale.write.d.ts +5 -1
- package/dist/template-resolver/handlers/copy-locale.write.js +22 -7
- package/dist/template-resolver/handlers/diff-to-system.query.js +3 -2
- package/dist/template-resolver/handlers/document-base.js +3 -2
- package/dist/template-resolver/handlers/find-by-id.query.js +3 -2
- package/dist/template-resolver/handlers/layout-source.query.d.ts +4 -0
- package/dist/template-resolver/handlers/layout-source.query.js +26 -6
- package/dist/template-resolver/handlers/list.query.js +5 -6
- package/dist/template-resolver/handlers/overview.query.d.ts +3 -0
- package/dist/template-resolver/handlers/overview.query.js +21 -10
- package/dist/template-resolver/handlers/patch-draft.write.js +1 -1
- package/dist/template-resolver/handlers/send-test-status.query.d.ts +2 -1
- package/dist/template-resolver/handlers/send-test-status.query.js +18 -15
- package/dist/template-resolver/handlers/tenant-override-counts.query.js +1 -3
- package/dist/template-resolver/handlers/tenant-override-selection.d.ts +2 -1
- package/dist/template-resolver/handlers/tenant-overrides.query.js +28 -5
- package/dist/template-resolver/handlers/usage.query.d.ts +2 -1
- package/dist/template-resolver/handlers/usage.query.js +26 -16
- package/dist/template-resolver/handlers/validate.query.js +7 -2
- package/dist/template-resolver/seeding.d.ts +1 -0
- package/dist/template-resolver/seeding.js +31 -12
- package/dist/template-resolver/store-template-resource.d.ts +1 -0
- package/dist/template-resolver/store-template-resource.js +65 -10
- package/dist/template-resolver/template-delivery-policy.d.ts +0 -5
- package/dist/template-resolver/template-delivery-policy.js +0 -6
- package/dist/template-resolver/template-meta.js +7 -4
- package/dist/template-resolver/template-preview.js +4 -3
- package/dist/template-resolver/web/constants.d.ts +2 -2
- package/dist/template-resolver/web/constants.js +3 -3
- package/dist/template-resolver/web/i18n.js +3 -0
- package/dist/template-resolver/web/index.d.ts +1 -0
- package/dist/template-resolver/web/index.js +1 -0
- package/dist/template-resolver/web/mail-layout-constants.d.ts +5 -0
- package/dist/template-resolver/web/mail-layout-constants.js +7 -0
- package/dist/template-resolver/web/qualified-names.d.ts +1 -0
- package/dist/template-resolver/web/qualified-names.js +1 -0
- package/dist/tenant/feature.js +1 -0
- package/dist/tenant/handlers/member-directory.query.d.ts +1 -0
- package/dist/tenant/handlers/member-directory.query.js +10 -3
- package/dist/tenant/handlers/team-list.query.js +3 -3
- package/dist/tenant/handlers/tenant-directory.query.d.ts +1 -0
- package/dist/tenant/handlers/tenant-directory.query.js +8 -4
- package/dist/tenant-lifecycle/constants.d.ts +1 -0
- package/dist/tenant-lifecycle/constants.js +4 -0
- package/dist/tenant-lifecycle/run-tenant-destroy.js +2 -2
- package/dist/tenant-lifecycle/stages.js +22 -1
- package/dist/tier-engine/handlers/set-tenant-tier.write.d.ts +2 -3
- package/dist/tier-engine/handlers/set-tenant-tier.write.js +4 -1
- package/dist/tier-engine/web/constants.js +2 -2
- package/dist/user/feature.js +1 -0
- package/dist/user-data-rights/feature.js +1 -0
- package/dist/user-data-rights/index.d.ts +1 -1
- package/dist/user-data-rights/index.js +1 -1
- package/dist/user-data-rights/run-export-jobs.js +3 -4
- package/dist/user-data-rights/run-forget-cleanup.js +2 -1
- package/dist/user-data-rights/web/constants.d.ts +6 -0
- package/dist/user-data-rights/web/constants.js +6 -0
- package/dist/user-data-rights/web/index.d.ts +1 -0
- package/dist/user-data-rights/web/index.js +1 -0
- package/dist/waitlist/feature.js +1 -0
- package/dist/waitlist/handlers/export-purge.write.js +2 -1
- package/dist/waitlist/handlers/submit.write.js +14 -10
- package/dist/waitlist/import.d.ts +3 -1
- package/dist/waitlist/import.js +26 -2
- package/dist/waitlist/legacy-migrate.js +18 -7
- package/dist/waitlist/link-on-signup.js +18 -6
- package/dist/waitlist/options.d.ts +5 -1
- package/dist/workflow-runner/handlers/resume-run.write.js +1 -1
- package/package.json +19 -9
- package/src/agent-tools/changes.json +12 -0
- package/src/audit/changes.json +12 -0
- package/src/auth-email-password/changes.json +12 -0
- package/src/auth-mfa/changes.json +12 -0
- package/src/billing-foundation/changes.json +55 -0
- package/src/cap-counter/changes.json +30 -0
- package/src/channel-email/changes.json +6 -0
- package/src/config/changes.json +18 -0
- package/src/crypto-shredding/changes.json +18 -0
- package/src/delivery/changes.json +42 -0
- package/src/document-ingest-foundation/changes.json +6 -0
- package/src/form-draft/changes.json +6 -0
- package/src/host-routing/changes.json +12 -0
- package/src/inbound-mail-foundation/changes.json +18 -0
- package/src/jobs/changes.json +13 -0
- package/src/mail-foundation/changes.json +6 -0
- package/src/mail-transport-smtp/changes.json +6 -0
- package/src/managed-pages/changes.json +6 -0
- package/src/renderer-pdf/changes.json +6 -0
- package/src/secrets/changes.json +6 -0
- package/src/sessions/changes.json +7 -0
- package/src/step-dispatcher/changes.json +12 -0
- package/src/subscription-dodo/changes.json +14 -0
- package/src/subscription-stripe/changes.json +12 -0
- package/src/template-resolver/changes.json +84 -0
- package/src/tenant/changes.json +6 -0
- package/src/tenant-lifecycle/changes.json +12 -0
- package/src/tier-engine/changes.json +6 -0
- package/src/user-data-rights/changes.json +12 -0
- package/src/waitlist/changes.json +36 -0
- package/dist/billing-foundation/consumer-protection/stored-user-email.d.ts +0 -1
- package/dist/billing-foundation/consumer-protection/stored-user-email.js +0 -8
package/dist/sessions/index.d.ts
CHANGED
|
@@ -3,6 +3,6 @@ export type { BindAutoRevokeOnPasswordChange, SessionsFeatureOptions } from "./f
|
|
|
3
3
|
export { bindAutoRevokeFromFeature, createSessionsFeature } from "./feature.ts";
|
|
4
4
|
export { userSessionEntity, userSessionTable } from "./schema/user-session.ts";
|
|
5
5
|
export type { SessionCallbacks, SessionCallbacksOptions, SessionMassRevoker, } from "./session-callbacks.ts";
|
|
6
|
-
export { createSessionCallbacks
|
|
6
|
+
export { createSessionCallbacks } from "./session-callbacks.ts";
|
|
7
7
|
export type { SessionRevokedPayload } from "./session-revoked-event.ts";
|
|
8
8
|
export { SESSION_REVOKED_AGGREGATE_TYPE, SESSION_REVOKED_EVENT_QN, SESSION_REVOKED_EVENT_SHORT, sessionRevokedSchema, } from "./session-revoked-event.ts";
|
package/dist/sessions/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { DEFAULT_SESSION_CACHE_TTL_MS, DEFAULT_SESSION_EXPIRY_MS, SESSION_MINE_SCREEN_ID, SESSIONS_FEATURE, SessionErrors, SessionHandlers, SessionQueries, } from "./constants.js";
|
|
2
2
|
export { bindAutoRevokeFromFeature, createSessionsFeature } from "./feature.js";
|
|
3
3
|
export { userSessionEntity, userSessionTable } from "./schema/user-session.js";
|
|
4
|
-
export { createSessionCallbacks
|
|
4
|
+
export { createSessionCallbacks } from "./session-callbacks.js";
|
|
5
5
|
export { SESSION_REVOKED_AGGREGATE_TYPE, SESSION_REVOKED_EVENT_QN, SESSION_REVOKED_EVENT_SHORT, sessionRevokedSchema, } from "./session-revoked-event.js";
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import type { SessionChecker, SessionCreator, SessionMassRevoker, SessionRevoker } from "@cosmicdrift/kumiko-framework/api";
|
|
2
2
|
export type { SessionMassRevoker } from "@cosmicdrift/kumiko-framework/api";
|
|
3
3
|
import type { DbConnection } from "@cosmicdrift/kumiko-framework/db";
|
|
4
|
-
import { isPrincipalBlocked } from "../user/index.ts";
|
|
5
|
-
export { isPrincipalBlocked };
|
|
6
4
|
export type SessionAllOthersRevoker = (userId: string, currentSid: string | undefined) => Promise<number>;
|
|
7
5
|
export type SessionCallbacksOptions = {
|
|
8
6
|
readonly db: DbConnection;
|
|
@@ -5,12 +5,10 @@ import { generateId, parseRoles } from "@cosmicdrift/kumiko-framework/utils";
|
|
|
5
5
|
import { Temporal } from "@cosmicdrift/kumiko-types/temporal";
|
|
6
6
|
import { encryptForDirectWrite } from "../shared/index.js";
|
|
7
7
|
import { tenantMembershipsTable } from "../tenant/index.js";
|
|
8
|
-
import {
|
|
8
|
+
import { isPrincipalRowBlocked, userTable } from "../user/index.js";
|
|
9
9
|
import { DEFAULT_SESSION_EXPIRY_MS, LAST_SEEN_REFRESH_MS, USER_SESSION_ENTITY_NAME, } from "./constants.js";
|
|
10
10
|
import { userSessionEntity, userSessionTable } from "./schema/user-session.js";
|
|
11
11
|
import { SESSION_REVOKED_AGGREGATE_TYPE, SESSION_REVOKED_EVENT_QN, sessionRevokedSchema, } from "./session-revoked-event.js";
|
|
12
|
-
// Re-exported so existing `../sessions` importers keep working unchanged.
|
|
13
|
-
export { isPrincipalBlocked };
|
|
14
12
|
function settleLookup(lookup) {
|
|
15
13
|
return lookup.then((value) => ({ ok: true, value }), () => ({ ok: false }));
|
|
16
14
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { requestContext } from "@cosmicdrift/kumiko-framework/api";
|
|
2
|
-
import { configuredPiiSubjectKms, decryptPiiFieldValues, } from "@cosmicdrift/kumiko-framework/crypto";
|
|
2
|
+
import { configuredPiiSubjectKms, decryptPiiFieldValues, PII_ERASED_SENTINEL, } from "@cosmicdrift/kumiko-framework/crypto";
|
|
3
3
|
// Raw reads (fetchOne/selectMany) return the stored column value — with an
|
|
4
4
|
// active KMS that is ciphertext (self-describing: it names its own subject,
|
|
5
5
|
// so no entity/field context is needed for key selection). `field` must
|
|
@@ -17,3 +17,8 @@ export async function decryptStoredPii(value, field, fallbackRequestId) {
|
|
|
17
17
|
const decrypted = out[field];
|
|
18
18
|
return typeof decrypted === "string" ? decrypted : value;
|
|
19
19
|
}
|
|
20
|
+
// Null for an erased subject: the sentinel must never be mailed or shown as an address.
|
|
21
|
+
export async function decryptStoredUserEmail(stored, fallbackRequestId) {
|
|
22
|
+
const email = await decryptStoredPii(stored, "email", fallbackRequestId);
|
|
23
|
+
return email === PII_ERASED_SENTINEL ? null : email;
|
|
24
|
+
}
|
package/dist/shared/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { assertNoWhereRuleInOwnershipWrite } from "./assert-no-where-rule-in-own
|
|
|
3
3
|
export { attachmentFileNameSchema, sanitizePdfAttachmentFileName, } from "./attachment-file-name.ts";
|
|
4
4
|
export { type ChunkedMigrationOptions, type ChunkedMigrationResult, type ChunkedMigrationStopReason, type MigrationRowOutcome, runChunkedMigration, } from "./chunked-entity-migration.ts";
|
|
5
5
|
export { classifyStoredEnvelope, type StoredEnvelopeClassification, } from "./classify-stored-envelope.ts";
|
|
6
|
-
export { decryptStoredPii } from "./decrypt-stored-pii.ts";
|
|
6
|
+
export { decryptStoredPii, decryptStoredUserEmail } from "./decrypt-stored-pii.ts";
|
|
7
7
|
export { encryptForDirectWrite } from "./encrypt-for-direct-write.ts";
|
|
8
8
|
export { entitiesOf } from "./entities-of.ts";
|
|
9
9
|
export { isWithinGracePeriod } from "./grace-period.ts";
|
package/dist/shared/index.js
CHANGED
|
@@ -3,7 +3,7 @@ export { assertNoWhereRuleInOwnershipWrite } from "./assert-no-where-rule-in-own
|
|
|
3
3
|
export { attachmentFileNameSchema, sanitizePdfAttachmentFileName, } from "./attachment-file-name.js";
|
|
4
4
|
export { runChunkedMigration, } from "./chunked-entity-migration.js";
|
|
5
5
|
export { classifyStoredEnvelope, } from "./classify-stored-envelope.js";
|
|
6
|
-
export { decryptStoredPii } from "./decrypt-stored-pii.js";
|
|
6
|
+
export { decryptStoredPii, decryptStoredUserEmail } from "./decrypt-stored-pii.js";
|
|
7
7
|
export { encryptForDirectWrite } from "./encrypt-for-direct-write.js";
|
|
8
8
|
export { entitiesOf } from "./entities-of.js";
|
|
9
9
|
export { isWithinGracePeriod } from "./grace-period.js";
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
export declare function mailTextWithSlotsHtml(text: string): string;
|
|
2
|
-
|
|
2
|
+
type MailParagraphOptions = {
|
|
3
|
+
readonly showIf?: string;
|
|
4
|
+
};
|
|
5
|
+
export declare function mailParagraph(text: string, options?: MailParagraphOptions): string;
|
|
3
6
|
export declare function mailHeading(text: string): string;
|
|
4
7
|
export declare function mailButton(label: string, linkVariable: string): string;
|
|
5
|
-
export declare function mailParagraphWithLink(text: string, linkLabel: string, linkVariable: string): string;
|
|
8
|
+
export declare function mailParagraphWithLink(text: string, linkLabel: string, linkVariable: string, options?: MailParagraphOptions): string;
|
|
6
9
|
export declare function mailRepeatedRows(listName: string, field: string): string;
|
|
7
10
|
export declare function mailSubject(text: string): string;
|
|
11
|
+
export {};
|
|
@@ -5,8 +5,11 @@ const SLOT_PATTERN = /\{([A-Za-z_][A-Za-z0-9_]*)\}/g;
|
|
|
5
5
|
export function mailTextWithSlotsHtml(text) {
|
|
6
6
|
return escapeHtml(text).replace(SLOT_PATTERN, (_, name) => `<span data-variable="${escapeHtmlAttr(name)}"></span>`);
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
return `<p
|
|
8
|
+
function paragraphOpenTag(options) {
|
|
9
|
+
return options?.showIf === undefined ? "<p>" : `<p data-if="${escapeHtmlAttr(options.showIf)}">`;
|
|
10
|
+
}
|
|
11
|
+
export function mailParagraph(text, options) {
|
|
12
|
+
return `${paragraphOpenTag(options)}${mailTextWithSlotsHtml(text)}</p>`;
|
|
10
13
|
}
|
|
11
14
|
export function mailHeading(text) {
|
|
12
15
|
return `<h2>${mailTextWithSlotsHtml(text)}</h2>`;
|
|
@@ -14,8 +17,8 @@ export function mailHeading(text) {
|
|
|
14
17
|
export function mailButton(label, linkVariable) {
|
|
15
18
|
return `<p><a data-button href="{{${escapeHtmlAttr(linkVariable)}}}">${escapeHtml(label)}</a></p>`;
|
|
16
19
|
}
|
|
17
|
-
export function mailParagraphWithLink(text, linkLabel, linkVariable) {
|
|
18
|
-
return
|
|
20
|
+
export function mailParagraphWithLink(text, linkLabel, linkVariable, options) {
|
|
21
|
+
return `${paragraphOpenTag(options)}${mailTextWithSlotsHtml(text)} <a href="{{${escapeHtmlAttr(linkVariable)}}}">${escapeHtml(linkLabel)}</a></p>`;
|
|
19
22
|
}
|
|
20
23
|
// One table row per list entry; the cell shows the entry's `field`.
|
|
21
24
|
export function mailRepeatedRows(listName, field) {
|
|
@@ -7,6 +7,7 @@ export declare class FileSweepError extends Error {
|
|
|
7
7
|
readonly entityName: string;
|
|
8
8
|
constructor(code: Exclude<FileRefPurgeOutcome, "purged">, entityName: string);
|
|
9
9
|
}
|
|
10
|
+
export declare const PURGE_CANDIDATE_PAGE_SIZE = 200;
|
|
10
11
|
export type DeleteFileBytes = (storageKey: string) => Promise<readonly string[]>;
|
|
11
12
|
export type MissingStoragePolicy = {
|
|
12
13
|
readonly mode: "fail";
|
|
@@ -70,6 +70,24 @@ function fieldsResolvingToSubject(fileEntity, row, rowTenantId, subjectKey) {
|
|
|
70
70
|
}
|
|
71
71
|
});
|
|
72
72
|
}
|
|
73
|
+
// A user owning many records must not load them all at once; the id cursor keeps each page
|
|
74
|
+
// bounded while rows purged in place stay out of the way.
|
|
75
|
+
export const PURGE_CANDIDATE_PAGE_SIZE = 200;
|
|
76
|
+
async function* candidateRowsPaged(db, table, where) {
|
|
77
|
+
let cursor;
|
|
78
|
+
for (;;) {
|
|
79
|
+
const pageWhere = cursor === undefined ? where : { ...where, id: { gt: cursor } };
|
|
80
|
+
const page = await selectMany(db, table, pageWhere, {
|
|
81
|
+
orderBy: { col: "id", direction: "asc" },
|
|
82
|
+
limit: PURGE_CANDIDATE_PAGE_SIZE,
|
|
83
|
+
});
|
|
84
|
+
yield* page;
|
|
85
|
+
// skip: a short page is the last one
|
|
86
|
+
if (page.length < PURGE_CANDIDATE_PAGE_SIZE)
|
|
87
|
+
return;
|
|
88
|
+
cursor = page[page.length - 1]?.["id"];
|
|
89
|
+
}
|
|
90
|
+
}
|
|
73
91
|
const fileRefExecutor = createEventStoreExecutor(fileRefsTable, fileRefEntity, {
|
|
74
92
|
entityName: "fileRef",
|
|
75
93
|
});
|
|
@@ -99,8 +117,7 @@ export async function purgeFilesReachingSubject(args) {
|
|
|
99
117
|
for (const fileEntity of fileEntities) {
|
|
100
118
|
const seenRowIds = new Set();
|
|
101
119
|
for (const where of candidateWheres(subject, recordTenantId, fileEntity)) {
|
|
102
|
-
const
|
|
103
|
-
for (const row of rows) {
|
|
120
|
+
for await (const row of candidateRowsPaged(db, fileEntity.table, where)) {
|
|
104
121
|
const rowId = String(row["id"]);
|
|
105
122
|
const tenantId = parseTenantId(row["tenantId"]);
|
|
106
123
|
// skip: a row without a tenant cannot own tenant-scoped file refs
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// Per-unit sub-transaction (one user, one purged row), nesting-aware across both db shapes:
|
|
2
|
-
// - top-level connection (
|
|
3
|
-
// -
|
|
2
|
+
// - top-level connection (Bun.SQL pool) → `.begin` (BEGIN)
|
|
3
|
+
// - TransactionSQL (inside the dispatcher's outer tx, where every
|
|
4
4
|
// writeHandler already runs) → `.savepoint` (SAVEPOINT)
|
|
5
|
-
// A
|
|
6
|
-
// threw
|
|
5
|
+
// A transaction handle cannot begin another transaction, so the previous unconditional `.begin`
|
|
6
|
+
// threw on every user when invoked through the dispatcher
|
|
7
7
|
// (the cron path) → zero deletions in production, while direct-connection tests
|
|
8
8
|
// stayed green. Selecting the available method makes the sub-tx work in both
|
|
9
9
|
// contexts; on throw the savepoint rolls back just this user (others survive).
|
|
@@ -13,7 +13,7 @@ export async function runInSubTransaction(db, fn) {
|
|
|
13
13
|
// without asRawClient (a test-only escape hatch).
|
|
14
14
|
const runner = db;
|
|
15
15
|
// savepoint-first: empirically (Bun 1.3.14, not re-checked on 1.4.0) the
|
|
16
|
-
// surfaces are NOT mutually exclusive — a
|
|
16
|
+
// surfaces are NOT mutually exclusive — a TransactionSQL exposes begin AND
|
|
17
17
|
// savepoint, only the top-level connection has begin alone. begin-first
|
|
18
18
|
// picked the nested BEGIN inside a tx (the incident class above);
|
|
19
19
|
// savepoint-first hits the savepoint there and falls back to begin top-level.
|
|
@@ -31,9 +31,16 @@ export async function eraseDispatchKey(aggregateId) {
|
|
|
31
31
|
eraseReason: "step-dispatch-outcome-recorded",
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
|
-
|
|
34
|
+
const SMTP_PERMANENT_REJECTION_MIN = 500;
|
|
35
|
+
const SMTP_PERMANENT_REJECTION_MAX = 599;
|
|
36
|
+
// Without an SMTP code the adapter gave nothing to classify, so the failure counts as transient.
|
|
35
37
|
function mailResultAsDelivery(result) {
|
|
36
|
-
|
|
38
|
+
if (result.ok)
|
|
39
|
+
return result;
|
|
40
|
+
const isPermanent = result.smtpCode !== undefined &&
|
|
41
|
+
result.smtpCode >= SMTP_PERMANENT_REJECTION_MIN &&
|
|
42
|
+
result.smtpCode <= SMTP_PERMANENT_REJECTION_MAX;
|
|
43
|
+
return { ok: false, error: result.error, retryable: !isPermanent };
|
|
37
44
|
}
|
|
38
45
|
// Outcome events are plaintext and generic; the request payload's per-dispatch
|
|
39
46
|
// key is erased right after, so the PII dies with the dispatch instead of
|
|
@@ -137,7 +144,13 @@ async function sendDispatch(dispatchSpec, target) {
|
|
|
137
144
|
aggregateId: target.aggregateId,
|
|
138
145
|
errorName: err instanceof Error ? err.name : "unknown",
|
|
139
146
|
});
|
|
140
|
-
|
|
147
|
+
// A mail adapter has no idempotency key: a throw after the provider accepted the message
|
|
148
|
+
// would send it again, so only the webhook (which carries one) is retried.
|
|
149
|
+
return {
|
|
150
|
+
ok: false,
|
|
151
|
+
error: DISPATCH_THREW_ERROR,
|
|
152
|
+
retryable: dispatchSpec.stepKind === "webhook.send",
|
|
153
|
+
};
|
|
141
154
|
}
|
|
142
155
|
}
|
|
143
156
|
async function abortOnFinalAttempt(err, ctx, recorder, aggregateId, requestedPayload) {
|
|
@@ -42,6 +42,7 @@ export function createStepDispatcherFeature() {
|
|
|
42
42
|
retries: DELIVER_RETRIES,
|
|
43
43
|
backoff: "exponential",
|
|
44
44
|
maxPerTenant: { limit: DELIVER_MAX_PER_TENANT, onLimit: "defer" },
|
|
45
|
+
schema: deliverJobPayloadSchema,
|
|
45
46
|
escapeHatch: { reason: DELIVER_ESCAPE_HATCH_REASON },
|
|
46
47
|
}, async (payload, ctx) => {
|
|
47
48
|
const { aggregateId } = deliverJobPayloadSchema.parse(payload);
|
|
@@ -12,6 +12,7 @@ export type MailDispatchResult = {
|
|
|
12
12
|
} | {
|
|
13
13
|
readonly ok: false;
|
|
14
14
|
readonly error: string;
|
|
15
|
+
readonly smtpCode?: number;
|
|
15
16
|
};
|
|
16
17
|
export declare function setMailRunner(fn: (spec: MailSpec) => Promise<MailDispatchResult>): void;
|
|
17
18
|
export declare function performMailDispatch(spec: MailSpec): Promise<MailDispatchResult>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type DodoSend = (url: string, init?: RequestInit) => Promise<Response>;
|
|
2
|
+
export type DodoRequest = {
|
|
3
|
+
readonly method: "GET" | "POST" | "PATCH";
|
|
4
|
+
/** Path segments interpolated into it must already be encodeURIComponent'ed. */
|
|
5
|
+
readonly path: string;
|
|
6
|
+
readonly query?: Readonly<Record<string, string>>;
|
|
7
|
+
readonly body?: unknown;
|
|
8
|
+
};
|
|
9
|
+
export type DodoTarget = {
|
|
10
|
+
readonly baseUrl: string;
|
|
11
|
+
readonly apiKey: string;
|
|
12
|
+
};
|
|
13
|
+
export declare class DodoHttpError extends Error {
|
|
14
|
+
readonly status: number;
|
|
15
|
+
constructor(request: DodoRequest, status: number);
|
|
16
|
+
}
|
|
17
|
+
export declare function createDodoHttp(send: DodoSend): (target: DodoTarget, request: DodoRequest) => Promise<unknown>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Thin JSON-over-fetch client for the Dodo Payments REST API. All traffic goes
|
|
2
|
+
// through the injected `send`, which defaults to the SSRF-safe egress in
|
|
3
|
+
// feature.ts and is replaced by a mock in tests.
|
|
4
|
+
import { parseJsonOrThrow } from "@cosmicdrift/kumiko-framework/utils";
|
|
5
|
+
// Never carries the response body or the key: both can hold customer data or secrets.
|
|
6
|
+
export class DodoHttpError extends Error {
|
|
7
|
+
status;
|
|
8
|
+
constructor(request, status) {
|
|
9
|
+
super(`subscription-dodo: ${request.method} ${request.path} failed with status ${status}`);
|
|
10
|
+
this.name = "DodoHttpError";
|
|
11
|
+
this.status = status;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export function createDodoHttp(send) {
|
|
15
|
+
return async (target, request) => {
|
|
16
|
+
const query = request.query ? `?${new URLSearchParams(request.query).toString()}` : "";
|
|
17
|
+
const response = await send(`${target.baseUrl}${request.path}${query}`, {
|
|
18
|
+
method: request.method,
|
|
19
|
+
headers: {
|
|
20
|
+
Authorization: `Bearer ${target.apiKey}`,
|
|
21
|
+
Accept: "application/json",
|
|
22
|
+
...(request.body !== undefined && { "Content-Type": "application/json" }),
|
|
23
|
+
},
|
|
24
|
+
...(request.body !== undefined && { body: JSON.stringify(request.body) }),
|
|
25
|
+
});
|
|
26
|
+
if (!response.ok)
|
|
27
|
+
throw new DodoHttpError(request, response.status);
|
|
28
|
+
const text = await response.text();
|
|
29
|
+
return text.length === 0 ? null : parseJsonOrThrow(text, "subscription-dodo response");
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const SUBSCRIPTION_DODO_FEATURE: "subscription-dodo";
|
|
2
|
+
export declare const DODO_PROVIDER_NAME: "dodo";
|
|
3
|
+
export declare const DODO_API_KEY_CONFIG: "api-key";
|
|
4
|
+
export declare const DODO_WEBHOOK_SECRET_CONFIG: "webhook-secret";
|
|
5
|
+
export declare const DODO_BILLING_LIVE_CONFIG: "billingLive";
|
|
6
|
+
export declare const DODO_ENVIRONMENT_CONFIG: "environment";
|
|
7
|
+
export declare const DodoEnvironments: {
|
|
8
|
+
readonly test: "test";
|
|
9
|
+
readonly live: "live";
|
|
10
|
+
};
|
|
11
|
+
export type DodoEnvironment = (typeof DodoEnvironments)[keyof typeof DodoEnvironments];
|
|
12
|
+
export declare const DODO_BASE_URLS: Readonly<Record<DodoEnvironment, string>>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export const SUBSCRIPTION_DODO_FEATURE = "subscription-dodo";
|
|
2
|
+
// Must match the path segment in the webhook URL `/api/subscription/webhook/dodo`.
|
|
3
|
+
export const DODO_PROVIDER_NAME = "dodo";
|
|
4
|
+
// Config-key short-names, qualified to `subscription-dodo:config:<name>` at
|
|
5
|
+
// registry-build. api-key + webhook-secret are backing:"secrets".
|
|
6
|
+
export const DODO_API_KEY_CONFIG = "api-key";
|
|
7
|
+
export const DODO_WEBHOOK_SECRET_CONFIG = "webhook-secret";
|
|
8
|
+
export const DODO_BILLING_LIVE_CONFIG = "billingLive";
|
|
9
|
+
export const DODO_ENVIRONMENT_CONFIG = "environment";
|
|
10
|
+
// Separate from billingLive on purpose: staging runs Dodo's test API with
|
|
11
|
+
// billingLive on, production flips both.
|
|
12
|
+
export const DodoEnvironments = {
|
|
13
|
+
test: "test",
|
|
14
|
+
live: "live",
|
|
15
|
+
};
|
|
16
|
+
export const DODO_BASE_URLS = {
|
|
17
|
+
test: "https://test.dodopayments.com",
|
|
18
|
+
live: "https://live.dodopayments.com",
|
|
19
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type FeatureDefinition } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
+
import { type FeatureWithEnvSchema } from "@cosmicdrift/kumiko-framework/env";
|
|
3
|
+
import * as z from "zod";
|
|
4
|
+
import type { DodoSend } from "./client.ts";
|
|
5
|
+
/** Bridge contract: both fields are optional fallbacks for the secrets store. */
|
|
6
|
+
export declare const subscriptionDodoEnvSchema: z.ZodObject<{
|
|
7
|
+
DODO_PAYMENTS_API_KEY: z.ZodOptional<z.ZodString>;
|
|
8
|
+
DODO_PAYMENTS_WEBHOOK_KEY: z.ZodOptional<z.ZodString>;
|
|
9
|
+
}, z.core.$strip>;
|
|
10
|
+
type DodoProductEnvShape<TPrice extends string> = {
|
|
11
|
+
[Key in `DODO_PRODUCT_${TPrice}`]: z.ZodOptional<z.ZodString>;
|
|
12
|
+
};
|
|
13
|
+
/** Dodo env block plus one `DODO_PRODUCT_<NAME>` slot per plan product the app
|
|
14
|
+
* maps to a tier, e.g. `dodoEnvSchema({ prices: ["PRO", "TEAM"] })`.
|
|
15
|
+
* Shares its bridge fields with `subscriptionDodoEnvSchema`, so spreading
|
|
16
|
+
* it into `composeEnvSchema({ extend })` next to the mounted feature is no
|
|
17
|
+
* key clash. */
|
|
18
|
+
export declare function dodoEnvSchema<const TPrice extends string>(options: {
|
|
19
|
+
readonly prices: readonly TPrice[];
|
|
20
|
+
}): z.ZodObject<{
|
|
21
|
+
DODO_PAYMENTS_API_KEY: z.ZodOptional<z.ZodString>;
|
|
22
|
+
DODO_PAYMENTS_WEBHOOK_KEY: z.ZodOptional<z.ZodString>;
|
|
23
|
+
} & DodoProductEnvShape<TPrice> extends infer T ? { -readonly [P in keyof T]: T[P]; } : never, z.core.$strip>;
|
|
24
|
+
export type SubscriptionDodoOptions = {
|
|
25
|
+
/** Bridge-fallback API key; the `api-key` config key wins when set. */
|
|
26
|
+
readonly apiKey?: string;
|
|
27
|
+
/** Bridge-fallback webhook secret; the `webhook-secret` config key wins when set. */
|
|
28
|
+
readonly webhookSecret?: string;
|
|
29
|
+
/** Dodo product id → app tier name. Products absent here drop the event. */
|
|
30
|
+
readonly priceToTier?: Readonly<Record<string, string>>;
|
|
31
|
+
/** Product ids a mode:"payment" checkout may target; empty = one-off checkouts closed. */
|
|
32
|
+
readonly oneOffPriceIds?: readonly string[];
|
|
33
|
+
/** HTTP transport; defaults to the SSRF-safe external egress. Test seam. */
|
|
34
|
+
readonly send?: DodoSend;
|
|
35
|
+
};
|
|
36
|
+
export declare function createSubscriptionDodoFeature(options?: SubscriptionDodoOptions): FeatureWithEnvSchema<FeatureDefinition, typeof subscriptionDodoEnvSchema.shape>;
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// kumiko-feature-version: 1
|
|
2
|
+
//
|
|
3
|
+
// subscription-dodo — Dodo Payments (merchant of record) plugin for the
|
|
4
|
+
// billing-foundation plugin API. Credentials, the billing-live master switch and
|
|
5
|
+
// the API environment (test | live) are config keys resolved at call time, like
|
|
6
|
+
// subscription-stripe. `apiKey` / `webhookSecret` options are env→secrets bridge
|
|
7
|
+
// fallbacks.
|
|
8
|
+
import { access, createSystemConfig, defineFeature, } from "@cosmicdrift/kumiko-framework/engine";
|
|
9
|
+
import { featureWithEnvSchema } from "@cosmicdrift/kumiko-framework/env";
|
|
10
|
+
import { egress } from "@cosmicdrift/kumiko-framework/http";
|
|
11
|
+
import * as z from "zod";
|
|
12
|
+
import { DODO_API_KEY_CONFIG, DODO_BILLING_LIVE_CONFIG, DODO_ENVIRONMENT_CONFIG, DODO_PROVIDER_NAME, DODO_WEBHOOK_SECRET_CONFIG, DodoEnvironments, SUBSCRIPTION_DODO_FEATURE, } from "./constants.js";
|
|
13
|
+
import { createDodoApplyPlanSwitch, createDodoCancelSubscription, createDodoCheckoutSession, createDodoPortalSession, createDodoPreviewPlanSwitch, createDodoPriceCache, createDodoResumeSubscription, createDodoRetrievePrices, createDodoRetrieveSubscription, } from "./plugin-methods.js";
|
|
14
|
+
import { createDodoRuntimes } from "./runtime.js";
|
|
15
|
+
import { verifyAndParseDodoWebhook } from "./verify-webhook.js";
|
|
16
|
+
/** Bridge contract: both fields are optional fallbacks for the secrets store. */
|
|
17
|
+
export const subscriptionDodoEnvSchema = z.object({
|
|
18
|
+
DODO_PAYMENTS_API_KEY: z
|
|
19
|
+
.string()
|
|
20
|
+
.min(1)
|
|
21
|
+
.describe("Dodo Payments API key. Bridge-fallback — prefer the secret.")
|
|
22
|
+
.meta({ kumiko: { pulumi: { secret: true } } })
|
|
23
|
+
.optional(),
|
|
24
|
+
DODO_PAYMENTS_WEBHOOK_KEY: z
|
|
25
|
+
.string()
|
|
26
|
+
.min(1)
|
|
27
|
+
.describe("Dodo Payments webhook signing key (`whsec_...`). Bridge-fallback — prefer the secret.")
|
|
28
|
+
.meta({ kumiko: { pulumi: { secret: true } } })
|
|
29
|
+
.optional(),
|
|
30
|
+
});
|
|
31
|
+
/** Dodo env block plus one `DODO_PRODUCT_<NAME>` slot per plan product the app
|
|
32
|
+
* maps to a tier, e.g. `dodoEnvSchema({ prices: ["PRO", "TEAM"] })`.
|
|
33
|
+
* Shares its bridge fields with `subscriptionDodoEnvSchema`, so spreading
|
|
34
|
+
* it into `composeEnvSchema({ extend })` next to the mounted feature is no
|
|
35
|
+
* key clash. */
|
|
36
|
+
export function dodoEnvSchema(options) {
|
|
37
|
+
const productShape = Object.fromEntries(options.prices.map((price) => [
|
|
38
|
+
`DODO_PRODUCT_${price}`,
|
|
39
|
+
z
|
|
40
|
+
.string()
|
|
41
|
+
.regex(/^pdt_/, `DODO_PRODUCT_${price} must start with 'pdt_'`)
|
|
42
|
+
.optional()
|
|
43
|
+
.describe(`Dodo Payments product id (\`pdt_...\`) of the ${price} plan.`),
|
|
44
|
+
]));
|
|
45
|
+
return z.object({ ...subscriptionDodoEnvSchema.shape, ...productShape });
|
|
46
|
+
}
|
|
47
|
+
// Validated once at feature-build time so a typo fails app startup instead of
|
|
48
|
+
// silently widening or narrowing the one-off allowlist at request time.
|
|
49
|
+
function validateOneOffPriceIds(priceIds) {
|
|
50
|
+
const seen = new Set();
|
|
51
|
+
for (const priceId of priceIds) {
|
|
52
|
+
if (priceId.length === 0) {
|
|
53
|
+
throw new Error("subscription-dodo: oneOffPriceIds must not contain an empty string");
|
|
54
|
+
}
|
|
55
|
+
if (seen.has(priceId)) {
|
|
56
|
+
throw new Error(`subscription-dodo: duplicate oneOffPriceIds entry "${priceId}"`);
|
|
57
|
+
}
|
|
58
|
+
seen.add(priceId);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
export function createSubscriptionDodoFeature(options = {}) {
|
|
62
|
+
validateOneOffPriceIds(options.oneOffPriceIds ?? []);
|
|
63
|
+
const feature = defineFeature(SUBSCRIPTION_DODO_FEATURE, (r) => {
|
|
64
|
+
r.describe('Dodo Payments provider plugin for `billing-foundation`. Dodo acts as merchant of record: it sells to the customer and issues invoice and VAT, so the consumer-protection texts for this provider come from `consumerProtection.providerTexts`. Reads its API key and webhook secret from system config keys with `backing:"secrets"` (envelope-encrypted in the secrets store under the system tenant), plus a `billingLive` master switch and an `environment` key (test | live). `environment` is its own key because Dodo serves test and live mode from different API hosts and a live key must never hit the test host or the other way round; `billingLive` only decides whether checkouts are offered at all. All four are runtime config, so keys rotate and prod goes live without a redeploy, and the `mask` on each derives the sysadmin settings screen and nav. Mount via `createSubscriptionDodoFeature({ priceToTier })`; the optional `apiKey`/`webhookSecret` options are env to secrets bridge fallbacks (`DODO_PAYMENTS_API_KEY`, `DODO_PAYMENTS_WEBHOOK_KEY`). The plugin always mounts; `createCheckoutSession` throws `feature_disabled` unless `billingLive` is true. Webhooks arrive at `/api/subscription/webhook/dodo` and are verified per the Standard Webhooks spec (HMAC-SHA256 over id, timestamp and the raw body, 5 minute tolerance); events for products outside `priceToTier` or without tenant metadata are dropped. Implements hosted checkout, customer portal, cancel and resume, `retrievePrices` (10-minute TTL cache), `retrieveSubscription` for the sync job, and an in-app plan switch: `previewPlanSwitch` shows the proration before the customer confirms, `applyPlanSwitch` changes the plan without a hosted page and waits for the `plan_changed` webhook to move the tier. A plan switch in Dodo requires all plan products to belong to one Product Collection.');
|
|
65
|
+
r.uiHints({
|
|
66
|
+
displayLabel: "Billing · Dodo Payments",
|
|
67
|
+
category: "billing",
|
|
68
|
+
recommended: false,
|
|
69
|
+
});
|
|
70
|
+
r.requires({ features: ["billing-foundation"] });
|
|
71
|
+
r.requires({ features: ["config"] });
|
|
72
|
+
r.requires({ features: ["secrets"] });
|
|
73
|
+
r.envSchema(subscriptionDodoEnvSchema);
|
|
74
|
+
const configKeys = r.config({
|
|
75
|
+
keys: {
|
|
76
|
+
[DODO_API_KEY_CONFIG]: createSystemConfig("text", {
|
|
77
|
+
backing: "secrets",
|
|
78
|
+
write: access.systemAdmin,
|
|
79
|
+
read: access.admin,
|
|
80
|
+
mask: { title: "subscription-dodo.api-key", icon: "key", order: 1 },
|
|
81
|
+
}),
|
|
82
|
+
[DODO_WEBHOOK_SECRET_CONFIG]: createSystemConfig("text", {
|
|
83
|
+
backing: "secrets",
|
|
84
|
+
write: access.systemAdmin,
|
|
85
|
+
read: access.admin,
|
|
86
|
+
mask: { title: "subscription-dodo.webhook-secret", icon: "shield", order: 2 },
|
|
87
|
+
}),
|
|
88
|
+
[DODO_ENVIRONMENT_CONFIG]: createSystemConfig("select", {
|
|
89
|
+
default: DodoEnvironments.test,
|
|
90
|
+
options: [DodoEnvironments.test, DodoEnvironments.live],
|
|
91
|
+
write: access.systemAdmin,
|
|
92
|
+
read: access.admin,
|
|
93
|
+
mask: { title: "subscription-dodo.environment", icon: "server", order: 3 },
|
|
94
|
+
}),
|
|
95
|
+
[DODO_BILLING_LIVE_CONFIG]: createSystemConfig("boolean", {
|
|
96
|
+
default: false,
|
|
97
|
+
write: access.privileged,
|
|
98
|
+
read: access.admin,
|
|
99
|
+
mask: { title: "subscription-dodo.billing-live", icon: "rocket", order: 4 },
|
|
100
|
+
}),
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
r.translations({
|
|
104
|
+
keys: {
|
|
105
|
+
"subscription-dodo.api-key": { en: "Dodo Payments API key" },
|
|
106
|
+
"subscription-dodo.webhook-secret": { en: "Dodo Payments webhook secret" },
|
|
107
|
+
"subscription-dodo.environment": { en: "Dodo Payments environment" },
|
|
108
|
+
"subscription-dodo.billing-live": { en: "Live billing" },
|
|
109
|
+
"subscription-dodo.settings": { en: "Dodo Payments" },
|
|
110
|
+
"screen:subscription-dodo-system.title": { en: "Dodo Payments" },
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
const priceToTier = options.priceToTier ?? {};
|
|
114
|
+
const runtimes = createDodoRuntimes({
|
|
115
|
+
apiKeyHandle: configKeys[DODO_API_KEY_CONFIG],
|
|
116
|
+
webhookSecretHandle: configKeys[DODO_WEBHOOK_SECRET_CONFIG],
|
|
117
|
+
billingLiveHandle: configKeys[DODO_BILLING_LIVE_CONFIG],
|
|
118
|
+
environmentHandle: configKeys[DODO_ENVIRONMENT_CONFIG],
|
|
119
|
+
send: options.send ?? egress({ kind: "external" }),
|
|
120
|
+
fallback: {
|
|
121
|
+
...(options.apiKey !== undefined && { apiKey: options.apiKey }),
|
|
122
|
+
...(options.webhookSecret !== undefined && { webhookSecret: options.webhookSecret }),
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
const plugin = {
|
|
126
|
+
displayName: "Dodo Payments",
|
|
127
|
+
verifyAndParseWebhook: verifyAndParseDodoWebhook(runtimes.webhook, { priceToTier }),
|
|
128
|
+
createCheckoutSession: createDodoCheckoutSession(runtimes.ctx),
|
|
129
|
+
createPortalSession: createDodoPortalSession(runtimes.ctx),
|
|
130
|
+
cancelSubscription: createDodoCancelSubscription(runtimes.ctx),
|
|
131
|
+
resumeSubscription: createDodoResumeSubscription(runtimes.ctx),
|
|
132
|
+
priceToTier,
|
|
133
|
+
oneOffPriceIds: options.oneOffPriceIds ?? [],
|
|
134
|
+
isBillingEnabled: runtimes.ctx.isBillingEnabled,
|
|
135
|
+
retrievePrices: createDodoRetrievePrices(runtimes.ctx, createDodoPriceCache()),
|
|
136
|
+
retrieveSubscription: createDodoRetrieveSubscription(runtimes.ctx, { priceToTier }),
|
|
137
|
+
previewPlanSwitch: createDodoPreviewPlanSwitch(runtimes.ctx),
|
|
138
|
+
applyPlanSwitch: createDodoApplyPlanSwitch(runtimes.ctx),
|
|
139
|
+
};
|
|
140
|
+
r.useExtension("subscriptionProvider", DODO_PROVIDER_NAME, plugin);
|
|
141
|
+
return { configKeys };
|
|
142
|
+
});
|
|
143
|
+
return featureWithEnvSchema(feature, subscriptionDodoEnvSchema);
|
|
144
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
// Public API of the subscription-dodo bundled feature. The webhook verifier,
|
|
2
|
+
// client and plugin methods are internal to feature.ts.
|
|
3
|
+
export { DODO_BASE_URLS, DODO_PROVIDER_NAME, DodoEnvironments, SUBSCRIPTION_DODO_FEATURE, } from "./constants.js";
|
|
4
|
+
export { createSubscriptionDodoFeature, dodoEnvSchema, subscriptionDodoEnvSchema, } from "./feature.js";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type ProviderPrice, type SubscriptionProviderPlugin } from "@cosmicdrift/kumiko-bundled-features/billing-foundation";
|
|
2
|
+
import type { DodoCtxRuntime } from "./runtime.ts";
|
|
3
|
+
type PluginMethod<TName extends keyof SubscriptionProviderPlugin> = NonNullable<SubscriptionProviderPlugin[TName]>;
|
|
4
|
+
export declare function createDodoCheckoutSession(runtime: DodoCtxRuntime): PluginMethod<"createCheckoutSession">;
|
|
5
|
+
export declare function createDodoPortalSession(runtime: DodoCtxRuntime): PluginMethod<"createPortalSession">;
|
|
6
|
+
export declare function createDodoCancelSubscription(runtime: DodoCtxRuntime): PluginMethod<"cancelSubscription">;
|
|
7
|
+
export declare function createDodoResumeSubscription(runtime: DodoCtxRuntime): PluginMethod<"resumeSubscription">;
|
|
8
|
+
export type DodoPriceCache = {
|
|
9
|
+
readonly get: (priceId: string) => ProviderPrice | null | undefined;
|
|
10
|
+
readonly set: (priceId: string, price: ProviderPrice | null) => void;
|
|
11
|
+
};
|
|
12
|
+
export type DodoPriceCacheOptions = {
|
|
13
|
+
readonly ttlMs?: number;
|
|
14
|
+
readonly now?: () => number;
|
|
15
|
+
};
|
|
16
|
+
export declare function createDodoPriceCache({ ttlMs, now, }?: DodoPriceCacheOptions): DodoPriceCache;
|
|
17
|
+
export declare function createDodoRetrievePrices(runtime: DodoCtxRuntime, cache: DodoPriceCache): PluginMethod<"retrievePrices">;
|
|
18
|
+
export declare function createDodoPreviewPlanSwitch(runtime: DodoCtxRuntime): PluginMethod<"previewPlanSwitch">;
|
|
19
|
+
export declare function createDodoApplyPlanSwitch(runtime: DodoCtxRuntime): PluginMethod<"applyPlanSwitch">;
|
|
20
|
+
export declare function createDodoRetrieveSubscription(runtime: DodoCtxRuntime, options: {
|
|
21
|
+
readonly priceToTier: Readonly<Record<string, string>>;
|
|
22
|
+
}): PluginMethod<"retrieveSubscription">;
|
|
23
|
+
export {};
|