@zonastery/bursar 1.0.0 → 2.0.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/README.md +189 -62
- package/dist/billing/auto-recharge-port.d.ts +3 -3
- package/dist/billing/auto-recharge-port.d.ts.map +1 -1
- package/dist/billing/auto-recharge-port.js.map +1 -1
- package/dist/billing/auto-recharge-service.d.ts +5 -4
- package/dist/billing/auto-recharge-service.d.ts.map +1 -1
- package/dist/billing/auto-recharge-service.js +64 -34
- package/dist/billing/auto-recharge-service.js.map +1 -1
- package/dist/billing/billing-service.d.ts +5 -5
- package/dist/billing/billing-service.d.ts.map +1 -1
- package/dist/billing/billing-service.js +2 -2
- package/dist/billing/billing-service.js.map +1 -1
- package/dist/billing/billing-store.d.ts +10 -9
- package/dist/billing/billing-store.d.ts.map +1 -1
- package/dist/billing/billing-store.js.map +1 -1
- package/dist/billing/contracts.d.ts +31 -31
- package/dist/billing/contracts.d.ts.map +1 -1
- package/dist/billing/contracts.js.map +1 -1
- package/dist/billing/event-handlers.d.ts.map +1 -1
- package/dist/billing/event-handlers.js +49 -10
- package/dist/billing/event-handlers.js.map +1 -1
- package/dist/billing/event-processor.d.ts +1 -0
- package/dist/billing/event-processor.d.ts.map +1 -1
- package/dist/billing/event-processor.js +37 -10
- package/dist/billing/event-processor.js.map +1 -1
- package/dist/billing/financial-event-handlers.d.ts.map +1 -1
- package/dist/billing/financial-event-handlers.js +69 -72
- package/dist/billing/financial-event-handlers.js.map +1 -1
- package/dist/billing/index.d.ts +2 -1
- package/dist/billing/index.d.ts.map +1 -1
- package/dist/billing/index.js.map +1 -1
- package/dist/billing/management.d.ts +5 -5
- package/dist/billing/management.d.ts.map +1 -1
- package/dist/billing/management.js +2 -2
- package/dist/billing/management.js.map +1 -1
- package/dist/billing/policy-window.js.map +1 -1
- package/dist/billing/postgres/repositories/auto-recharge.d.ts +3 -3
- package/dist/billing/postgres/repositories/auto-recharge.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/auto-recharge.js +205 -60
- package/dist/billing/postgres/repositories/auto-recharge.js.map +1 -1
- package/dist/billing/postgres/repositories/customer.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/customer.js +19 -11
- package/dist/billing/postgres/repositories/customer.js.map +1 -1
- package/dist/billing/postgres/repositories/dispute.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/dispute.js +3 -1
- package/dist/billing/postgres/repositories/dispute.js.map +1 -1
- package/dist/billing/postgres/repositories/event.d.ts +14 -7
- package/dist/billing/postgres/repositories/event.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/event.js +21 -20
- package/dist/billing/postgres/repositories/event.js.map +1 -1
- package/dist/billing/postgres/repositories/invoice.d.ts +3 -3
- package/dist/billing/postgres/repositories/invoice.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/invoice.js +53 -11
- package/dist/billing/postgres/repositories/invoice.js.map +1 -1
- package/dist/billing/postgres/repositories/offer.d.ts +20 -17
- package/dist/billing/postgres/repositories/offer.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/offer.js +123 -57
- package/dist/billing/postgres/repositories/offer.js.map +1 -1
- package/dist/billing/postgres/repositories/payment.d.ts +23 -20
- package/dist/billing/postgres/repositories/payment.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/payment.js +43 -37
- package/dist/billing/postgres/repositories/payment.js.map +1 -1
- package/dist/billing/postgres/repositories/preferences.d.ts +3 -9
- package/dist/billing/postgres/repositories/preferences.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/preferences.js +45 -7
- package/dist/billing/postgres/repositories/preferences.js.map +1 -1
- package/dist/billing/postgres/repositories/refund.d.ts +1 -1
- package/dist/billing/postgres/repositories/refund.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/refund.js +13 -9
- package/dist/billing/postgres/repositories/refund.js.map +1 -1
- package/dist/billing/postgres/repositories/subscription-change.d.ts +15 -0
- package/dist/billing/postgres/repositories/subscription-change.d.ts.map +1 -0
- package/dist/billing/postgres/repositories/subscription-change.js +234 -0
- package/dist/billing/postgres/repositories/subscription-change.js.map +1 -0
- package/dist/billing/postgres/repositories/subscription.d.ts +38 -17
- package/dist/billing/postgres/repositories/subscription.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/subscription.js +199 -91
- package/dist/billing/postgres/repositories/subscription.js.map +1 -1
- package/dist/billing/postgres/repositories/topup.d.ts +13 -15
- package/dist/billing/postgres/repositories/topup.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/topup.js +65 -34
- package/dist/billing/postgres/repositories/topup.js.map +1 -1
- package/dist/billing/postgres/store.d.ts +23 -14
- package/dist/billing/postgres/store.d.ts.map +1 -1
- package/dist/billing/postgres/store.js +265 -228
- package/dist/billing/postgres/store.js.map +1 -1
- package/dist/billing/service-types.d.ts +6 -5
- package/dist/billing/service-types.d.ts.map +1 -1
- package/dist/billing/service-types.js.map +1 -1
- package/dist/billing/types/auto-recharge.d.ts +6 -4
- package/dist/billing/types/auto-recharge.d.ts.map +1 -1
- package/dist/billing/types/auto-recharge.js.map +1 -1
- package/dist/billing/types/catalog.d.ts +18 -35
- package/dist/billing/types/catalog.d.ts.map +1 -1
- package/dist/billing/types/catalog.js.map +1 -1
- package/dist/billing/types/common.d.ts +0 -1
- package/dist/billing/types/common.d.ts.map +1 -1
- package/dist/billing/types/common.js.map +1 -1
- package/dist/billing/types/documents.d.ts +38 -12
- package/dist/billing/types/documents.d.ts.map +1 -1
- package/dist/billing/types/documents.js.map +1 -1
- package/dist/billing/types/events.d.ts +2 -0
- package/dist/billing/types/events.d.ts.map +1 -1
- package/dist/billing/types/events.js +238 -0
- package/dist/billing/types/events.js.map +1 -1
- package/dist/billing/types/index.js.map +1 -1
- package/dist/billing/types/preferences.js.map +1 -1
- package/dist/billing/types/subscriptions.d.ts +8 -8
- package/dist/billing/types/subscriptions.d.ts.map +1 -1
- package/dist/billing/types/subscriptions.js.map +1 -1
- package/dist/breakdown.js.map +1 -1
- package/dist/browser.js.map +1 -1
- package/dist/bursar.d.ts +33 -11
- package/dist/bursar.d.ts.map +1 -1
- package/dist/bursar.js +58 -22
- package/dist/bursar.js.map +1 -1
- package/dist/catalog.d.ts +1 -0
- package/dist/catalog.d.ts.map +1 -1
- package/dist/catalog.js +1 -0
- package/dist/catalog.js.map +1 -1
- package/dist/commerce/errors.d.ts +4 -14
- package/dist/commerce/errors.d.ts.map +1 -1
- package/dist/commerce/errors.js +4 -21
- package/dist/commerce/errors.js.map +1 -1
- package/dist/commerce/index.d.ts +1 -0
- package/dist/commerce/index.d.ts.map +1 -1
- package/dist/commerce/index.js.map +1 -1
- package/dist/commerce/plan-change.js.map +1 -1
- package/dist/commerce/provider-registry.d.ts.map +1 -1
- package/dist/commerce/provider-registry.js +27 -2
- package/dist/commerce/provider-registry.js.map +1 -1
- package/dist/commerce/service.d.ts +15 -7
- package/dist/commerce/service.d.ts.map +1 -1
- package/dist/commerce/service.js +130 -77
- package/dist/commerce/service.js.map +1 -1
- package/dist/commerce/types.d.ts +33 -13
- package/dist/commerce/types.d.ts.map +1 -1
- package/dist/commerce/types.js.map +1 -1
- package/dist/config/parse-access.js.map +1 -1
- package/dist/config/parse-commerce.js.map +1 -1
- package/dist/config/parse-credits.js.map +1 -1
- package/dist/config/parse-plans.d.ts.map +1 -1
- package/dist/config/parse-plans.js +30 -13
- package/dist/config/parse-plans.js.map +1 -1
- package/dist/config/parse-pricing.d.ts.map +1 -1
- package/dist/config/parse-pricing.js +16 -5
- package/dist/config/parse-pricing.js.map +1 -1
- package/dist/config/parse-utils.js.map +1 -1
- package/dist/config/types.d.ts +14 -1
- package/dist/config/types.d.ts.map +1 -1
- package/dist/config/types.js.map +1 -1
- package/dist/config.d.ts +7 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +64 -1
- package/dist/config.js.map +1 -1
- package/dist/credits/{pricing-runtime.d.ts → catalog-runtime.d.ts} +9 -8
- package/dist/credits/catalog-runtime.d.ts.map +1 -0
- package/dist/credits/{pricing-runtime.js → catalog-runtime.js} +58 -38
- package/dist/credits/catalog-runtime.js.map +1 -0
- package/dist/credits/events.d.ts +4 -4
- package/dist/credits/events.d.ts.map +1 -1
- package/dist/credits/events.js +1 -1
- package/dist/credits/events.js.map +1 -1
- package/dist/credits/lease-workflow.d.ts +14 -14
- package/dist/credits/lease-workflow.d.ts.map +1 -1
- package/dist/credits/lease-workflow.js +18 -17
- package/dist/credits/lease-workflow.js.map +1 -1
- package/dist/credits/low-balance-monitor.d.ts +2 -2
- package/dist/credits/low-balance-monitor.d.ts.map +1 -1
- package/dist/credits/low-balance-monitor.js.map +1 -1
- package/dist/credits/postgres/repositories/analytics.d.ts +39 -35
- package/dist/credits/postgres/repositories/analytics.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/analytics.js +55 -53
- package/dist/credits/postgres/repositories/analytics.js.map +1 -1
- package/dist/credits/postgres/repositories/balance.d.ts +28 -30
- package/dist/credits/postgres/repositories/balance.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/balance.js +100 -59
- package/dist/credits/postgres/repositories/balance.js.map +1 -1
- package/dist/credits/postgres/repositories/bucket.d.ts +14 -8
- package/dist/credits/postgres/repositories/bucket.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/bucket.js +22 -21
- package/dist/credits/postgres/repositories/bucket.js.map +1 -1
- package/dist/credits/postgres/repositories/catalog.d.ts +31 -0
- package/dist/credits/postgres/repositories/catalog.d.ts.map +1 -0
- package/dist/credits/postgres/repositories/catalog.js +90 -0
- package/dist/credits/postgres/repositories/catalog.js.map +1 -0
- package/dist/credits/postgres/repositories/deduction.d.ts +32 -21
- package/dist/credits/postgres/repositories/deduction.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/deduction.js +171 -62
- package/dist/credits/postgres/repositories/deduction.js.map +1 -1
- package/dist/credits/postgres/repositories/lease.d.ts +21 -18
- package/dist/credits/postgres/repositories/lease.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/lease.js +157 -65
- package/dist/credits/postgres/repositories/lease.js.map +1 -1
- package/dist/credits/postgres/repositories/plan.d.ts +94 -42
- package/dist/credits/postgres/repositories/plan.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/plan.js +134 -104
- package/dist/credits/postgres/repositories/plan.js.map +1 -1
- package/dist/credits/postgres/repositories/team.d.ts +36 -27
- package/dist/credits/postgres/repositories/team.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/team.js +96 -52
- package/dist/credits/postgres/repositories/team.js.map +1 -1
- package/dist/credits/postgres/store.d.ts +31 -21
- package/dist/credits/postgres/store.d.ts.map +1 -1
- package/dist/credits/postgres/store.js +325 -235
- package/dist/credits/postgres/store.js.map +1 -1
- package/dist/credits/postgres/value-mappers.d.ts +7 -9
- package/dist/credits/postgres/value-mappers.d.ts.map +1 -1
- package/dist/credits/postgres/value-mappers.js +42 -63
- package/dist/credits/postgres/value-mappers.js.map +1 -1
- package/dist/credits/queries.d.ts +5 -5
- package/dist/credits/queries.d.ts.map +1 -1
- package/dist/credits/queries.js +4 -4
- package/dist/credits/queries.js.map +1 -1
- package/dist/credits/service-errors.js.map +1 -1
- package/dist/credits/service-types.d.ts +42 -7
- package/dist/credits/service-types.d.ts.map +1 -1
- package/dist/credits/service-types.js.map +1 -1
- package/dist/credits/service.d.ts +51 -58
- package/dist/credits/service.d.ts.map +1 -1
- package/dist/credits/service.js +178 -113
- package/dist/credits/service.js.map +1 -1
- package/dist/credits/store.d.ts +25 -22
- package/dist/credits/store.d.ts.map +1 -1
- package/dist/credits/store.js +9 -5
- package/dist/credits/store.js.map +1 -1
- package/dist/credits/types/account.d.ts +50 -12
- package/dist/credits/types/account.d.ts.map +1 -1
- package/dist/credits/types/account.js.map +1 -1
- package/dist/credits/types/admission.d.ts +17 -6
- package/dist/credits/types/admission.d.ts.map +1 -1
- package/dist/credits/types/admission.js.map +1 -1
- package/dist/credits/types/analytics.d.ts +2 -2
- package/dist/credits/types/analytics.d.ts.map +1 -1
- package/dist/credits/types/analytics.js.map +1 -1
- package/dist/credits/types/catalog.d.ts +21 -14
- package/dist/credits/types/catalog.d.ts.map +1 -1
- package/dist/credits/types/catalog.js.map +1 -1
- package/dist/credits/types/grants.d.ts +22 -8
- package/dist/credits/types/grants.d.ts.map +1 -1
- package/dist/credits/types/grants.js.map +1 -1
- package/dist/credits/types/index.js.map +1 -1
- package/dist/credits/types/ledger.d.ts +19 -0
- package/dist/credits/types/ledger.d.ts.map +1 -1
- package/dist/credits/types/ledger.js.map +1 -1
- package/dist/credits/types/quotas.js.map +1 -1
- package/dist/credits/types/teams.d.ts +18 -6
- package/dist/credits/types/teams.d.ts.map +1 -1
- package/dist/credits/types/teams.js.map +1 -1
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +24 -10
- package/dist/engine.js.map +1 -1
- package/dist/errors.d.ts +105 -8
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +137 -9
- package/dist/errors.js.map +1 -1
- package/dist/expr/ast.d.ts.map +1 -1
- package/dist/expr/ast.js.map +1 -1
- package/dist/expr/evaluator.d.ts.map +1 -1
- package/dist/expr/evaluator.js +29 -17
- package/dist/expr/evaluator.js.map +1 -1
- package/dist/expr/language.js.map +1 -1
- package/dist/expr/parser.d.ts.map +1 -1
- package/dist/expr/parser.js +11 -4
- package/dist/expr/parser.js.map +1 -1
- package/dist/expr/tokenizer.d.ts.map +1 -1
- package/dist/expr/tokenizer.js +17 -13
- package/dist/expr/tokenizer.js.map +1 -1
- package/dist/expr.d.ts +2 -2
- package/dist/expr.d.ts.map +1 -1
- package/dist/expr.js +7 -9
- package/dist/expr.js.map +1 -1
- package/dist/generated/pricing-config.schema.json +30 -9
- package/dist/generated/pricing-config.types.d.ts +14 -3
- package/dist/generated/pricing-config.types.d.ts.map +1 -1
- package/dist/generated/pricing-config.types.js.map +1 -1
- package/dist/index.d.ts +11 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/integrations/better-auth.d.ts +23 -0
- package/dist/integrations/better-auth.d.ts.map +1 -0
- package/dist/integrations/better-auth.js +54 -0
- package/dist/integrations/better-auth.js.map +1 -0
- package/dist/{load-pricing-file.d.ts → load-config-file.d.ts} +4 -4
- package/dist/load-config-file.d.ts.map +1 -0
- package/dist/{load-pricing-file.js → load-config-file.js} +23 -14
- package/dist/load-config-file.js.map +1 -0
- package/dist/metrics.js.map +1 -1
- package/dist/node.d.ts +3 -3
- package/dist/node.d.ts.map +1 -1
- package/dist/node.js +2 -2
- package/dist/node.js.map +1 -1
- package/dist/providers/_shared.d.ts +5 -0
- package/dist/providers/_shared.d.ts.map +1 -1
- package/dist/providers/_shared.js +77 -14
- package/dist/providers/_shared.js.map +1 -1
- package/dist/providers/dodo/better-auth.d.ts +29 -0
- package/dist/providers/dodo/better-auth.d.ts.map +1 -0
- package/dist/providers/dodo/better-auth.js +23 -0
- package/dist/providers/dodo/better-auth.js.map +1 -0
- package/dist/providers/dodo/client-contract.d.ts +32 -70
- package/dist/providers/dodo/client-contract.d.ts.map +1 -1
- package/dist/providers/dodo/client-contract.js.map +1 -1
- package/dist/providers/dodo/event-mapper.d.ts +3 -1
- package/dist/providers/dodo/event-mapper.d.ts.map +1 -1
- package/dist/providers/dodo/event-mapper.js +219 -148
- package/dist/providers/dodo/event-mapper.js.map +1 -1
- package/dist/providers/dodo/index.d.ts +5 -2
- package/dist/providers/dodo/index.d.ts.map +1 -1
- package/dist/providers/dodo/index.js +2 -1
- package/dist/providers/dodo/index.js.map +1 -1
- package/dist/providers/dodo/nextjs.d.ts +16 -0
- package/dist/providers/dodo/nextjs.d.ts.map +1 -0
- package/dist/providers/dodo/nextjs.js +16 -0
- package/dist/providers/dodo/nextjs.js.map +1 -0
- package/dist/providers/dodo/provider.d.ts +30 -11
- package/dist/providers/dodo/provider.d.ts.map +1 -1
- package/dist/providers/dodo/provider.js +192 -122
- package/dist/providers/dodo/provider.js.map +1 -1
- package/dist/providers/dodo/react-native.d.ts +56 -0
- package/dist/providers/dodo/react-native.d.ts.map +1 -0
- package/dist/providers/dodo/react-native.js +57 -0
- package/dist/providers/dodo/react-native.js.map +1 -0
- package/dist/providers/dodo/webhook-bridge.d.ts +17 -0
- package/dist/providers/dodo/webhook-bridge.d.ts.map +1 -0
- package/dist/providers/dodo/webhook-bridge.js +21 -0
- package/dist/providers/dodo/webhook-bridge.js.map +1 -0
- package/dist/providers/index.d.ts +1 -1
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/mock/index.d.ts +1 -0
- package/dist/providers/mock/index.d.ts.map +1 -1
- package/dist/providers/mock/index.js.map +1 -1
- package/dist/providers/mock/provider.d.ts +8 -8
- package/dist/providers/mock/provider.d.ts.map +1 -1
- package/dist/providers/mock/provider.js +26 -19
- package/dist/providers/mock/provider.js.map +1 -1
- package/dist/providers/stripe/event-mapper.d.ts.map +1 -1
- package/dist/providers/stripe/event-mapper.js +214 -173
- package/dist/providers/stripe/event-mapper.js.map +1 -1
- package/dist/providers/stripe/index.d.ts +1 -0
- package/dist/providers/stripe/index.d.ts.map +1 -1
- package/dist/providers/stripe/index.js.map +1 -1
- package/dist/providers/stripe/provider.d.ts +13 -11
- package/dist/providers/stripe/provider.d.ts.map +1 -1
- package/dist/providers/stripe/provider.js +287 -107
- package/dist/providers/stripe/provider.js.map +1 -1
- package/dist/providers/types.d.ts +1 -2
- package/dist/providers/types.d.ts.map +1 -1
- package/dist/providers/types.js.map +1 -1
- package/dist/retry.d.ts +26 -4
- package/dist/retry.d.ts.map +1 -1
- package/dist/retry.js +65 -23
- package/dist/retry.js.map +1 -1
- package/dist/shared/diagnostics.d.ts +7 -0
- package/dist/shared/diagnostics.d.ts.map +1 -0
- package/dist/shared/diagnostics.js +18 -0
- package/dist/shared/diagnostics.js.map +1 -0
- package/dist/shared/logger.js.map +1 -1
- package/dist/shared/postgres-client.d.ts +43 -5
- package/dist/shared/postgres-client.d.ts.map +1 -1
- package/dist/shared/postgres-client.js +282 -30
- package/dist/shared/postgres-client.js.map +1 -1
- package/dist/shared/postgres-errors.d.ts +11 -0
- package/dist/shared/postgres-errors.d.ts.map +1 -0
- package/dist/shared/postgres-errors.js +105 -0
- package/dist/shared/postgres-errors.js.map +1 -0
- package/dist/shared/postgres-types.js.map +1 -1
- package/dist/shared/postgres-validation.d.ts +15 -3
- package/dist/shared/postgres-validation.d.ts.map +1 -1
- package/dist/shared/postgres-validation.js +58 -14
- package/dist/shared/postgres-validation.js.map +1 -1
- package/dist/storage/adapters/clickhouse.d.ts.map +1 -1
- package/dist/storage/adapters/clickhouse.js +18 -3
- package/dist/storage/adapters/clickhouse.js.map +1 -1
- package/dist/storage/adapters/s3.d.ts +0 -6
- package/dist/storage/adapters/s3.d.ts.map +1 -1
- package/dist/storage/adapters/s3.js +0 -2
- package/dist/storage/adapters/s3.js.map +1 -1
- package/dist/storage/outbox-worker.d.ts +2 -1
- package/dist/storage/outbox-worker.d.ts.map +1 -1
- package/dist/storage/outbox-worker.js +17 -3
- package/dist/storage/outbox-worker.js.map +1 -1
- package/dist/storage/ports.d.ts +1 -1
- package/dist/storage/ports.d.ts.map +1 -1
- package/dist/storage/ports.js.map +1 -1
- package/dist/storage/postgres-repository.d.ts +1 -1
- package/dist/storage/postgres-repository.d.ts.map +1 -1
- package/dist/storage/postgres-repository.js +13 -3
- package/dist/storage/postgres-repository.js.map +1 -1
- package/dist/storage/runtime.d.ts +35 -7
- package/dist/storage/runtime.d.ts.map +1 -1
- package/dist/storage/runtime.js +166 -53
- package/dist/storage/runtime.js.map +1 -1
- package/package.json +62 -7
- package/dist/credits/postgres/repositories/pricing.d.ts +0 -28
- package/dist/credits/postgres/repositories/pricing.d.ts.map +0 -1
- package/dist/credits/postgres/repositories/pricing.js +0 -70
- package/dist/credits/postgres/repositories/pricing.js.map +0 -1
- package/dist/credits/pricing-runtime.d.ts.map +0 -1
- package/dist/credits/pricing-runtime.js.map +0 -1
- package/dist/load-pricing-file.d.ts.map +0 -1
- package/dist/load-pricing-file.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refund.js","sourceRoot":"","sources":["../../../../src/billing/postgres/repositories/refund.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"refund.js","sourceRoot":"","sources":["../../../../src/billing/postgres/repositories/refund.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EACL,iBAAiB,EACjB,YAAY,EACZ,kBAAkB,EAClB,SAAS,GACV,MAAM,wCAAwC,CAAC;AAEhD,MAAM,OAAO,uBAAuB;IACd;IAApB,YAAoB,KAAc;QAAd,UAAK,GAAL,KAAK,CAAS;IAAG,CAAC;IAEtC,KAAK,CAAC,MAAM,CACV,QAAgB,EAChB,gBAAwB,EACxB,iBAAyB,EACzB,MAAc,EACd,WAAmB,EACnB,QAAgB,EAChB,MAAqB,EACrB,QAAuB,EACvB,MAAc,EACd,iBAAyB;QAEzB,IAAI,CAAC,iBAAiB;YAAE,MAAM,IAAI,SAAS,CAAC,mCAAmC,CAAC,CAAC;QACjF,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,KAAK,CAC/B,8DAA8D,EAC9D,CAAC,QAAQ,EAAE,iBAAiB,CAAC,CAC9B,CAAC;QACF,MAAM,OAAO,GAAG,iBAAiB,CAAC,QAAQ,EAAE,wCAAwC,CAAC,CAAC;QACtF,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;YACrB,MAAM,IAAI,UAAU,CAAC,0BAA0B,EAAE;gBAC/C,SAAS,EAAE,IAAI;gBACf,OAAO,EAAE,EAAE,QAAQ,EAAE,iBAAiB,EAAE;aACzC,CAAC,CAAC;QACL,CAAC;QACD,MAAM,SAAS,GAAG,SAAS,CACzB,YAAY,EACZ,OAAO,CAAC,EAAE,EACV,2CAA2C,CAC5C,CAAC;QACF,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,KAAK,CAC3B;;eAES,EACT;YACE,SAAS;YACT,gBAAgB;YAChB,WAAW;YACX,MAAM;YACN,MAAM;YACN,iBAAiB;YACjB,MAAM;YACN,QAAQ;YACR,QAAQ,IAAI,IAAI;SACjB,CACF,CAAC;QACF,OAAO,kBAAkB,CAAC,IAAI,EAAE,IAAI,EAAE,YAAY,EAAE,gCAAgC,CAAC,CAAC;IACxF,CAAC;CACF","sourcesContent":["import { StoreError } from \"../../../errors.js\";\nimport type { QueryFn } from \"../../../shared/postgres-types.js\";\nimport {\n optionalRecordRow,\n postgresUuid,\n requireResultField,\n safeParse,\n} from \"../../../shared/postgres-validation.js\";\n\nexport class BillingRefundRepository {\n constructor(private query: QueryFn) {}\n\n async upsert(\n provider: string,\n providerRefundId: string,\n providerPaymentId: string,\n userId: string,\n amountMinor: number,\n currency: string,\n reason: string | null,\n metadata: string | null,\n status: string,\n providerUpdatedAt: string,\n ): Promise<string> {\n if (!providerPaymentId) throw new TypeError(\"refund requires providerPaymentId\");\n const payments = await this.query(\n \"SELECT * FROM bursar.get_billing_payment_by_provider($1, $2)\",\n [provider, providerPaymentId],\n );\n const payment = optionalRecordRow(payments, \"BillingRefundRepository.upsert.payment\");\n if (payment === null) {\n throw new StoreError(\"refund payment not found\", {\n retryable: true,\n details: { provider, providerPaymentId },\n });\n }\n const paymentId = safeParse(\n postgresUuid,\n payment.id,\n \"BillingRefundRepository.upsert.payment.id\",\n );\n const rows = await this.query(\n `SELECT bursar.upsert_billing_refund(\n $1::uuid, $2, $3, $4, $5, $6, $7::uuid, $8::char(3), $9::jsonb\n ) AS id`,\n [\n paymentId,\n providerRefundId,\n amountMinor,\n status,\n reason,\n providerUpdatedAt,\n userId,\n currency,\n metadata ?? \"{}\",\n ],\n );\n return requireResultField(rows, \"id\", postgresUuid, \"BillingRefundRepository.upsert\");\n }\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { BillingSubscriptionChangeUpdate } from "../../contracts.js";
|
|
2
|
+
import type { BillingSubscriptionChange, BillingSubscriptionChangeInput } from "../../types/index.js";
|
|
3
|
+
import type { QueryFn } from "../../../shared/postgres-types.js";
|
|
4
|
+
/** Persistence boundary for durable subscription offer transitions. */
|
|
5
|
+
export declare class BillingSubscriptionChangeRepository {
|
|
6
|
+
private readonly query;
|
|
7
|
+
constructor(query: QueryFn);
|
|
8
|
+
create(subscriptionId: string, input: BillingSubscriptionChangeInput): Promise<BillingSubscriptionChange>;
|
|
9
|
+
getById(id: string): Promise<BillingSubscriptionChange | null>;
|
|
10
|
+
getOpen(provider: string, providerSubscriptionId: string): Promise<BillingSubscriptionChange | null>;
|
|
11
|
+
update(id: string, update: BillingSubscriptionChangeUpdate): Promise<void>;
|
|
12
|
+
private parseOptional;
|
|
13
|
+
private getOfferContexts;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=subscription-change.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscription-change.d.ts","sourceRoot":"","sources":["../../../../src/billing/postgres/repositories/subscription-change.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,KAAK,EACV,yBAAyB,EACzB,8BAA8B,EAE/B,MAAM,sBAAsB,CAAC;AAG9B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AA2HjE,uEAAuE;AACvE,qBAAa,mCAAmC;IAClC,OAAO,CAAC,QAAQ,CAAC,KAAK;gBAAL,KAAK,EAAE,OAAO;IAErC,MAAM,CACV,cAAc,EAAE,MAAM,EACtB,KAAK,EAAE,8BAA8B,GACpC,OAAO,CAAC,yBAAyB,CAAC;IAuC/B,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,yBAAyB,GAAG,IAAI,CAAC;IAQ9D,OAAO,CACX,QAAQ,EAAE,MAAM,EAChB,sBAAsB,EAAE,MAAM,GAC7B,OAAO,CAAC,yBAAyB,GAAG,IAAI,CAAC;IAQtC,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,+BAA+B,GAAG,OAAO,CAAC,IAAI,CAAC;YAoBlE,aAAa;YAyBb,gBAAgB;CAmD/B"}
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { StoreError } from "../../../errors.js";
|
|
3
|
+
import { optionalBoundedDiagnosticMessage } from "../../../shared/diagnostics.js";
|
|
4
|
+
import { optionalRecordRow, pgBoolean, postgresUuid, requireRecordRow, requireResultField, safeParse, } from "../../../shared/postgres-validation.js";
|
|
5
|
+
const timestamp = z
|
|
6
|
+
.union([
|
|
7
|
+
z.string().datetime({ offset: true }),
|
|
8
|
+
z.date().refine((value) => !Number.isNaN(value.getTime())),
|
|
9
|
+
])
|
|
10
|
+
.transform((value) => (value instanceof Date ? value.toISOString() : value));
|
|
11
|
+
const positiveBigint = z
|
|
12
|
+
.union([z.string().regex(/^[1-9]\d*$/), z.number().int().positive().safe()])
|
|
13
|
+
.transform(String);
|
|
14
|
+
const changeState = z.enum(["awaiting_payment", "scheduled", "applied", "failed", "canceled"]);
|
|
15
|
+
const effectiveBehavior = z.enum(["immediate", "renewal"]);
|
|
16
|
+
const prorationBehavior = z.enum(["provider_default", "invoice_immediately", "none"]);
|
|
17
|
+
const OpenChangeResultSchema = z
|
|
18
|
+
.object({
|
|
19
|
+
change_id: positiveBigint.nullable(),
|
|
20
|
+
state: changeState.nullable(),
|
|
21
|
+
error_code: z
|
|
22
|
+
.enum([
|
|
23
|
+
"invalid_request",
|
|
24
|
+
"missing_subscription",
|
|
25
|
+
"invalid_target_offer",
|
|
26
|
+
"idempotency_conflict",
|
|
27
|
+
"open_change_exists",
|
|
28
|
+
])
|
|
29
|
+
.nullable(),
|
|
30
|
+
})
|
|
31
|
+
.strict()
|
|
32
|
+
.superRefine((row, ctx) => {
|
|
33
|
+
const succeeded = row.error_code === null;
|
|
34
|
+
if (succeeded !== (row.change_id !== null && row.state !== null)) {
|
|
35
|
+
ctx.addIssue({
|
|
36
|
+
code: z.ZodIssueCode.custom,
|
|
37
|
+
message: "subscription-change result has inconsistent success fields",
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
const ChangeRowSchema = z
|
|
42
|
+
.object({
|
|
43
|
+
id: positiveBigint,
|
|
44
|
+
subscription_id: postgresUuid,
|
|
45
|
+
from_offer_id: postgresUuid,
|
|
46
|
+
from_catalog_revision_id: postgresUuid,
|
|
47
|
+
to_offer_id: postgresUuid,
|
|
48
|
+
to_catalog_revision_id: postgresUuid,
|
|
49
|
+
effective_at: timestamp.nullable(),
|
|
50
|
+
effective_behavior: effectiveBehavior,
|
|
51
|
+
state: changeState,
|
|
52
|
+
proration_behavior: prorationBehavior,
|
|
53
|
+
idempotency_key: z.string().min(1),
|
|
54
|
+
provider_operation_id: z.string().min(1).nullable(),
|
|
55
|
+
error_message: z.string().min(1).max(8192).nullable(),
|
|
56
|
+
})
|
|
57
|
+
.strict();
|
|
58
|
+
const OfferContextRowSchema = z
|
|
59
|
+
.object({
|
|
60
|
+
side: z.enum(["from", "to"]),
|
|
61
|
+
offer_id: postgresUuid,
|
|
62
|
+
offer_key: z.string().min(1),
|
|
63
|
+
plan_id: postgresUuid,
|
|
64
|
+
plan_key: z.string().min(1),
|
|
65
|
+
billing_unit: z.enum(["day", "week", "month", "year"]),
|
|
66
|
+
billing_count: z.number().int().positive(),
|
|
67
|
+
})
|
|
68
|
+
.strict();
|
|
69
|
+
function projectChange(row) {
|
|
70
|
+
return {
|
|
71
|
+
id: row.id,
|
|
72
|
+
subscription_id: row.subscription_id,
|
|
73
|
+
from_offer_id: row.from_offer_id,
|
|
74
|
+
from_catalog_revision_id: row.from_catalog_revision_id,
|
|
75
|
+
to_offer_id: row.to_offer_id,
|
|
76
|
+
to_catalog_revision_id: row.to_catalog_revision_id,
|
|
77
|
+
effective_at: row.effective_at,
|
|
78
|
+
effective_behavior: row.effective_behavior,
|
|
79
|
+
state: row.state,
|
|
80
|
+
proration_behavior: row.proration_behavior,
|
|
81
|
+
idempotency_key: row.idempotency_key,
|
|
82
|
+
provider_operation_id: row.provider_operation_id,
|
|
83
|
+
error_message: row.error_message,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
function projectContext(row) {
|
|
87
|
+
return {
|
|
88
|
+
side: row.side,
|
|
89
|
+
offer_id: row.offer_id,
|
|
90
|
+
offer_key: row.offer_key,
|
|
91
|
+
plan_id: row.plan_id,
|
|
92
|
+
plan_key: row.plan_key,
|
|
93
|
+
billing_unit: row.billing_unit,
|
|
94
|
+
billing_count: row.billing_count,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function publicContext(row) {
|
|
98
|
+
return {
|
|
99
|
+
offerId: row.offer_id,
|
|
100
|
+
offerKey: row.offer_key,
|
|
101
|
+
planId: row.plan_id,
|
|
102
|
+
plan: row.plan_key,
|
|
103
|
+
interval: row.billing_unit,
|
|
104
|
+
intervalCount: row.billing_count,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/** Persistence boundary for durable subscription offer transitions. */
|
|
108
|
+
export class BillingSubscriptionChangeRepository {
|
|
109
|
+
query;
|
|
110
|
+
constructor(query) {
|
|
111
|
+
this.query = query;
|
|
112
|
+
}
|
|
113
|
+
async create(subscriptionId, input) {
|
|
114
|
+
const rows = await this.query(`SELECT * FROM bursar.open_subscription_change(
|
|
115
|
+
$1::uuid, $2::uuid, $3::timestamptz, $4, $5, $6
|
|
116
|
+
)`, [
|
|
117
|
+
subscriptionId,
|
|
118
|
+
input.toOfferId,
|
|
119
|
+
input.effectiveAt,
|
|
120
|
+
input.effective,
|
|
121
|
+
input.idempotencyKey,
|
|
122
|
+
input.prorationBehavior ?? "provider_default",
|
|
123
|
+
]);
|
|
124
|
+
const raw = requireRecordRow(rows, "BillingSubscriptionChangeRepository.create");
|
|
125
|
+
const result = safeParse(OpenChangeResultSchema, { change_id: raw.change_id, state: raw.state, error_code: raw.error_code }, "BillingSubscriptionChangeRepository.create", { indeterminate: true });
|
|
126
|
+
if (result.error_code !== null) {
|
|
127
|
+
throw new StoreError(`subscription change rejected: ${result.error_code}`, {
|
|
128
|
+
details: { errorCode: result.error_code },
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
if (result.change_id === null) {
|
|
132
|
+
throw new StoreError("subscription change returned no identifier", { indeterminate: true });
|
|
133
|
+
}
|
|
134
|
+
const change = await this.getById(result.change_id);
|
|
135
|
+
if (change === null) {
|
|
136
|
+
throw new StoreError("subscription change could not be read after creation", {
|
|
137
|
+
indeterminate: true,
|
|
138
|
+
details: { subscriptionChangeId: result.change_id },
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
return change;
|
|
142
|
+
}
|
|
143
|
+
async getById(id) {
|
|
144
|
+
const rows = await this.query("SELECT * FROM bursar.get_billing_subscription_change($1::bigint)", [id]);
|
|
145
|
+
return this.parseOptional(rows, "BillingSubscriptionChangeRepository.getById");
|
|
146
|
+
}
|
|
147
|
+
async getOpen(provider, providerSubscriptionId) {
|
|
148
|
+
const rows = await this.query("SELECT * FROM bursar.get_open_billing_subscription_change($1, $2)", [provider, providerSubscriptionId]);
|
|
149
|
+
return this.parseOptional(rows, "BillingSubscriptionChangeRepository.getOpen");
|
|
150
|
+
}
|
|
151
|
+
async update(id, update) {
|
|
152
|
+
if (update.state === undefined)
|
|
153
|
+
return;
|
|
154
|
+
const rows = await this.query("SELECT bursar.advance_subscription_change($1::bigint, $2, $3, $4) AS advanced", [
|
|
155
|
+
id,
|
|
156
|
+
update.state,
|
|
157
|
+
update.providerOperationId ?? null,
|
|
158
|
+
optionalBoundedDiagnosticMessage(update.errorMessage),
|
|
159
|
+
]);
|
|
160
|
+
if (!requireResultField(rows, "advanced", pgBoolean, "BillingSubscriptionChangeRepository.update")) {
|
|
161
|
+
throw new StoreError(`subscription change transition rejected: ${id}`, {
|
|
162
|
+
details: { subscriptionChangeId: id },
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
async parseOptional(rows, context) {
|
|
167
|
+
const raw = optionalRecordRow(rows, context);
|
|
168
|
+
if (raw === null)
|
|
169
|
+
return null;
|
|
170
|
+
const row = safeParse(ChangeRowSchema, projectChange(raw), context);
|
|
171
|
+
const contexts = await this.getOfferContexts(row, context);
|
|
172
|
+
return {
|
|
173
|
+
id: row.id,
|
|
174
|
+
subscriptionId: row.subscription_id,
|
|
175
|
+
fromOfferId: row.from_offer_id,
|
|
176
|
+
toOfferId: row.to_offer_id,
|
|
177
|
+
fromOffer: publicContext(contexts.from),
|
|
178
|
+
toOffer: publicContext(contexts.to),
|
|
179
|
+
effectiveAt: row.effective_at,
|
|
180
|
+
effective: row.effective_behavior,
|
|
181
|
+
state: row.state,
|
|
182
|
+
prorationBehavior: row.proration_behavior,
|
|
183
|
+
idempotencyKey: row.idempotency_key,
|
|
184
|
+
providerOperationId: row.provider_operation_id,
|
|
185
|
+
errorMessage: row.error_message,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
async getOfferContexts(row, context) {
|
|
189
|
+
const rows = await this.query(`SELECT requested.side, requested.offer_id, offer_context.*
|
|
190
|
+
FROM (
|
|
191
|
+
VALUES
|
|
192
|
+
('from', $1::uuid, $2::uuid),
|
|
193
|
+
('to', $3::uuid, $4::uuid)
|
|
194
|
+
) AS requested(side, offer_id, catalog_revision_id)
|
|
195
|
+
CROSS JOIN LATERAL bursar.get_catalog_offer_context(
|
|
196
|
+
requested.offer_id,
|
|
197
|
+
requested.catalog_revision_id
|
|
198
|
+
) AS offer_context`, [
|
|
199
|
+
row.from_offer_id,
|
|
200
|
+
row.from_catalog_revision_id,
|
|
201
|
+
row.to_offer_id,
|
|
202
|
+
row.to_catalog_revision_id,
|
|
203
|
+
]);
|
|
204
|
+
if (rows.length !== 2) {
|
|
205
|
+
throw new StoreError(`${context}: expected both subscription-change offer contexts`, {
|
|
206
|
+
details: { subscriptionChangeId: row.id, rowCount: rows.length },
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
const parsed = rows.map((candidate, index) => {
|
|
210
|
+
if (typeof candidate !== "object" || candidate === null || Array.isArray(candidate)) {
|
|
211
|
+
throw new StoreError(`${context}: malformed subscription-change offer context`, {
|
|
212
|
+
details: { subscriptionChangeId: row.id, index },
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
const record = candidate;
|
|
216
|
+
return safeParse(OfferContextRowSchema, projectContext(record), `${context}.context`);
|
|
217
|
+
});
|
|
218
|
+
const bySide = new Map(parsed.map((candidate) => [candidate.side, candidate]));
|
|
219
|
+
const from = bySide.get("from");
|
|
220
|
+
const to = bySide.get("to");
|
|
221
|
+
if (bySide.size !== 2 || from === undefined || to === undefined) {
|
|
222
|
+
throw new StoreError(`${context}: duplicate or missing subscription-change offer context`, {
|
|
223
|
+
details: { subscriptionChangeId: row.id },
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
if (from.offer_id !== row.from_offer_id || to.offer_id !== row.to_offer_id) {
|
|
227
|
+
throw new StoreError(`${context}: subscription-change offer context does not match`, {
|
|
228
|
+
details: { subscriptionChangeId: row.id },
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
return { from, to };
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
//# sourceMappingURL=subscription-change.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscription-change.js","sourceRoot":"","sources":["../../../../src/billing/postgres/repositories/subscription-change.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAOxB,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,gCAAgC,EAAE,MAAM,gCAAgC,CAAC;AAElF,OAAO,EACL,iBAAiB,EACjB,SAAS,EACT,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,EAClB,SAAS,GACV,MAAM,wCAAwC,CAAC;AAEhD,MAAM,SAAS,GAAG,CAAC;KAChB,KAAK,CAAC;IACL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I,CAAC,CAAC;QAC5B,IAAI,MAAM,CAAC,IAAI,KAAK,CAAC,IAAI,IAAI,KAAK,SAAS,IAAI,EAAE,KAAK,SAAS,EAAE,CAAC;YAChE,MAAM,IAAI,UAAU,CAAC,GAAG,OAAO,0DAA0D,EAAE;gBACzF,OAAO,EAAE,EAAE,oBAAoB,EAAE,GAAG,CAAC,EAAE,EAAE;aAC1C,CAAC,CAAC;QACL,CAAC;QACD,IAAI,IAAI,CAAC,QAAQ,KAAK,GAAG,CAAC,aAAa,IAAI,EAAE,CAAC,QAAQ,KAAK,GAAG,CAAC,WAAW,EAAE,CAAC;YAC3E,MAAM,IAAI,UAAU,CAAC,GAAG,OAAO,oDAAoD,EAAE;gBACnF,OAAO,EAAE,EAAE,oBAAoB,EAAE,GAAG,CAAC,EAAE,EAAE;aAC1C,CAAC,CAAC;QACL,CAAC;QACD,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;IACtB,CAAC;CACF","sourcesContent":["import { z } from \"zod\";\nimport type { BillingSubscriptionChangeUpdate } from \"../../contracts.js\";\nimport type {\n BillingSubscriptionChange,\n BillingSubscriptionChangeInput,\n BillingSubscriptionOfferContext,\n} from \"../../types/index.js\";\nimport { StoreError } from \"../../../errors.js\";\nimport { optionalBoundedDiagnosticMessage } from \"../../../shared/diagnostics.js\";\nimport type { QueryFn } from \"../../../shared/postgres-types.js\";\nimport {\n optionalRecordRow,\n pgBoolean,\n postgresUuid,\n requireRecordRow,\n requireResultField,\n safeParse,\n} from \"../../../shared/postgres-validation.js\";\n\nconst timestamp = z\n .union([\n z.string().datetime({ offset: true }),\n z.date().refine((value) => !Number.isNaN(value.getTime())),\n ])\n .transform((value) => (value instanceof Date ? value.toISOString() : value));\nconst positiveBigint = z\n .union([z.string().regex(/^[1-9]\\d*$/), z.number().int().positive().safe()])\n .transform(String);\nconst changeState = z.enum([\"awaiting_payment\", \"scheduled\", \"applied\", \"failed\", \"canceled\"]);\nconst effectiveBehavior = z.enum([\"immediate\", \"renewal\"]);\nconst prorationBehavior = z.enum([\"provider_default\", \"invoice_immediately\", \"none\"]);\n\nconst OpenChangeResultSchema = z\n .object({\n change_id: positiveBigint.nullable(),\n state: changeState.nullable(),\n error_code: z\n .enum([\n \"invalid_request\",\n \"missing_subscription\",\n \"invalid_target_offer\",\n \"idempotency_conflict\",\n \"open_change_exists\",\n ])\n .nullable(),\n })\n .strict()\n .superRefine((row, ctx) => {\n const succeeded = row.error_code === null;\n if (succeeded !== (row.change_id !== null && row.state !== null)) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: \"subscription-change result has inconsistent success fields\",\n });\n }\n });\n\nconst ChangeRowSchema = z\n .object({\n id: positiveBigint,\n subscription_id: postgresUuid,\n from_offer_id: postgresUuid,\n from_catalog_revision_id: postgresUuid,\n to_offer_id: postgresUuid,\n to_catalog_revision_id: postgresUuid,\n effective_at: timestamp.nullable(),\n effective_behavior: effectiveBehavior,\n state: changeState,\n proration_behavior: prorationBehavior,\n idempotency_key: z.string().min(1),\n provider_operation_id: z.string().min(1).nullable(),\n error_message: z.string().min(1).max(8192).nullable(),\n })\n .strict();\n\ntype ChangeRow = z.infer<typeof ChangeRowSchema>;\n\nconst OfferContextRowSchema = z\n .object({\n side: z.enum([\"from\", \"to\"]),\n offer_id: postgresUuid,\n offer_key: z.string().min(1),\n plan_id: postgresUuid,\n plan_key: z.string().min(1),\n billing_unit: z.enum([\"day\", \"week\", \"month\", \"year\"]),\n billing_count: z.number().int().positive(),\n })\n .strict();\n\ntype OfferContextRow = z.infer<typeof OfferContextRowSchema>;\n\nfunction projectChange(row: Record<string, unknown>): Record<string, unknown> {\n return {\n id: row.id,\n subscription_id: row.subscription_id,\n from_offer_id: row.from_offer_id,\n from_catalog_revision_id: row.from_catalog_revision_id,\n to_offer_id: row.to_offer_id,\n to_catalog_revision_id: row.to_catalog_revision_id,\n effective_at: row.effective_at,\n effective_behavior: row.effective_behavior,\n state: row.state,\n proration_behavior: row.proration_behavior,\n idempotency_key: row.idempotency_key,\n provider_operation_id: row.provider_operation_id,\n error_message: row.error_message,\n };\n}\n\nfunction projectContext(row: Record<string, unknown>): Record<string, unknown> {\n return {\n side: row.side,\n offer_id: row.offer_id,\n offer_key: row.offer_key,\n plan_id: row.plan_id,\n plan_key: row.plan_key,\n billing_unit: row.billing_unit,\n billing_count: row.billing_count,\n };\n}\n\nfunction publicContext(row: OfferContextRow): BillingSubscriptionOfferContext {\n return {\n offerId: row.offer_id,\n offerKey: row.offer_key,\n planId: row.plan_id,\n plan: row.plan_key,\n interval: row.billing_unit,\n intervalCount: row.billing_count,\n };\n}\n\n/** Persistence boundary for durable subscription offer transitions. */\nexport class BillingSubscriptionChangeRepository {\n constructor(private readonly query: QueryFn) {}\n\n async create(\n subscriptionId: string,\n input: BillingSubscriptionChangeInput,\n ): Promise<BillingSubscriptionChange> {\n const rows = await this.query(\n `SELECT * FROM bursar.open_subscription_change(\n $1::uuid, $2::uuid, $3::timestamptz, $4, $5, $6\n )`,\n [\n subscriptionId,\n input.toOfferId,\n input.effectiveAt,\n input.effective,\n input.idempotencyKey,\n input.prorationBehavior ?? \"provider_default\",\n ],\n );\n const raw = requireRecordRow(rows, \"BillingSubscriptionChangeRepository.create\");\n const result = safeParse(\n OpenChangeResultSchema,\n { change_id: raw.change_id, state: raw.state, error_code: raw.error_code },\n \"BillingSubscriptionChangeRepository.create\",\n { indeterminate: true },\n );\n if (result.error_code !== null) {\n throw new StoreError(`subscription change rejected: ${result.error_code}`, {\n details: { errorCode: result.error_code },\n });\n }\n if (result.change_id === null) {\n throw new StoreError(\"subscription change returned no identifier\", { indeterminate: true });\n }\n const change = await this.getById(result.change_id);\n if (change === null) {\n throw new StoreError(\"subscription change could not be read after creation\", {\n indeterminate: true,\n details: { subscriptionChangeId: result.change_id },\n });\n }\n return change;\n }\n\n async getById(id: string): Promise<BillingSubscriptionChange | null> {\n const rows = await this.query(\n \"SELECT * FROM bursar.get_billing_subscription_change($1::bigint)\",\n [id],\n );\n return this.parseOptional(rows, \"BillingSubscriptionChangeRepository.getById\");\n }\n\n async getOpen(\n provider: string,\n providerSubscriptionId: string,\n ): Promise<BillingSubscriptionChange | null> {\n const rows = await this.query(\n \"SELECT * FROM bursar.get_open_billing_subscription_change($1, $2)\",\n [provider, providerSubscriptionId],\n );\n return this.parseOptional(rows, \"BillingSubscriptionChangeRepository.getOpen\");\n }\n\n async update(id: string, update: BillingSubscriptionChangeUpdate): Promise<void> {\n if (update.state === undefined) return;\n const rows = await this.query(\n \"SELECT bursar.advance_subscription_change($1::bigint, $2, $3, $4) AS advanced\",\n [\n id,\n update.state,\n update.providerOperationId ?? null,\n optionalBoundedDiagnosticMessage(update.errorMessage),\n ],\n );\n if (\n !requireResultField(rows, \"advanced\", pgBoolean, \"BillingSubscriptionChangeRepository.update\")\n ) {\n throw new StoreError(`subscription change transition rejected: ${id}`, {\n details: { subscriptionChangeId: id },\n });\n }\n }\n\n private async parseOptional(\n rows: readonly unknown[],\n context: string,\n ): Promise<BillingSubscriptionChange | null> {\n const raw = optionalRecordRow(rows, context);\n if (raw === null) return null;\n const row = safeParse(ChangeRowSchema, projectChange(raw), context);\n const contexts = await this.getOfferContexts(row, context);\n return {\n id: row.id,\n subscriptionId: row.subscription_id,\n fromOfferId: row.from_offer_id,\n toOfferId: row.to_offer_id,\n fromOffer: publicContext(contexts.from),\n toOffer: publicContext(contexts.to),\n effectiveAt: row.effective_at,\n effective: row.effective_behavior,\n state: row.state,\n prorationBehavior: row.proration_behavior,\n idempotencyKey: row.idempotency_key,\n providerOperationId: row.provider_operation_id,\n errorMessage: row.error_message,\n };\n }\n\n private async getOfferContexts(\n row: ChangeRow,\n context: string,\n ): Promise<{ from: OfferContextRow; to: OfferContextRow }> {\n const rows = await this.query(\n `SELECT requested.side, requested.offer_id, offer_context.*\n FROM (\n VALUES\n ('from', $1::uuid, $2::uuid),\n ('to', $3::uuid, $4::uuid)\n ) AS requested(side, offer_id, catalog_revision_id)\n CROSS JOIN LATERAL bursar.get_catalog_offer_context(\n requested.offer_id,\n requested.catalog_revision_id\n ) AS offer_context`,\n [\n row.from_offer_id,\n row.from_catalog_revision_id,\n row.to_offer_id,\n row.to_catalog_revision_id,\n ],\n );\n if (rows.length !== 2) {\n throw new StoreError(`${context}: expected both subscription-change offer contexts`, {\n details: { subscriptionChangeId: row.id, rowCount: rows.length },\n });\n }\n const parsed = rows.map((candidate, index) => {\n if (typeof candidate !== \"object\" || candidate === null || Array.isArray(candidate)) {\n throw new StoreError(`${context}: malformed subscription-change offer context`, {\n details: { subscriptionChangeId: row.id, index },\n });\n }\n const record = candidate as Record<string, unknown>;\n return safeParse(OfferContextRowSchema, projectContext(record), `${context}.context`);\n });\n const bySide = new Map(parsed.map((candidate) => [candidate.side, candidate]));\n const from = bySide.get(\"from\");\n const to = bySide.get(\"to\");\n if (bySide.size !== 2 || from === undefined || to === undefined) {\n throw new StoreError(`${context}: duplicate or missing subscription-change offer context`, {\n details: { subscriptionChangeId: row.id },\n });\n }\n if (from.offer_id !== row.from_offer_id || to.offer_id !== row.to_offer_id) {\n throw new StoreError(`${context}: subscription-change offer context does not match`, {\n details: { subscriptionChangeId: row.id },\n });\n }\n return { from, to };\n }\n}\n"]}
|
|
@@ -1,29 +1,50 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import type { BillingSubscriptionState } from "../../types/subscriptions.js";
|
|
2
3
|
import type { QueryFn } from "../../../shared/postgres-types.js";
|
|
3
4
|
declare const SubscriptionRowSchema: z.ZodObject<{
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
id: z.ZodString;
|
|
6
|
+
user_id: z.ZodString;
|
|
6
7
|
provider: z.ZodString;
|
|
7
8
|
provider_subscription_id: z.ZodString;
|
|
8
|
-
provider_customer_id: z.
|
|
9
|
-
offer_id: z.
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
9
|
+
provider_customer_id: z.ZodNullable<z.ZodString>;
|
|
10
|
+
offer_id: z.ZodString;
|
|
11
|
+
offer_key: z.ZodString;
|
|
12
|
+
plan_id: z.ZodString;
|
|
13
|
+
plan: z.ZodString;
|
|
14
|
+
status: z.ZodEnum<{
|
|
15
|
+
canceled: "canceled";
|
|
16
|
+
incomplete: "incomplete";
|
|
17
|
+
incomplete_expired: "incomplete_expired";
|
|
18
|
+
trialing: "trialing";
|
|
19
|
+
active: "active";
|
|
20
|
+
past_due: "past_due";
|
|
21
|
+
unpaid: "unpaid";
|
|
22
|
+
paused: "paused";
|
|
23
|
+
expired: "expired";
|
|
24
|
+
}>;
|
|
25
|
+
current_period_start: z.ZodNullable<z.ZodPipe<z.ZodUnion<readonly [z.ZodDate, z.ZodString]>, z.ZodTransform<string, string | Date>>>;
|
|
26
|
+
current_period_end: z.ZodNullable<z.ZodPipe<z.ZodUnion<readonly [z.ZodDate, z.ZodString]>, z.ZodTransform<string, string | Date>>>;
|
|
27
|
+
trial_end: z.ZodNullable<z.ZodPipe<z.ZodUnion<readonly [z.ZodDate, z.ZodString]>, z.ZodTransform<string, string | Date>>>;
|
|
28
|
+
cancel_at: z.ZodNullable<z.ZodPipe<z.ZodUnion<readonly [z.ZodDate, z.ZodString]>, z.ZodTransform<string, string | Date>>>;
|
|
29
|
+
ended_at: z.ZodNullable<z.ZodPipe<z.ZodUnion<readonly [z.ZodDate, z.ZodString]>, z.ZodTransform<string, string | Date>>>;
|
|
30
|
+
grace_ends_at: z.ZodNullable<z.ZodPipe<z.ZodUnion<readonly [z.ZodDate, z.ZodString]>, z.ZodTransform<string, string | Date>>>;
|
|
31
|
+
grace_expired_at: z.ZodNullable<z.ZodPipe<z.ZodUnion<readonly [z.ZodDate, z.ZodString]>, z.ZodTransform<string, string | Date>>>;
|
|
32
|
+
provider_updated_at: z.ZodPipe<z.ZodUnion<readonly [z.ZodDate, z.ZodString]>, z.ZodTransform<string, string | Date>>;
|
|
33
|
+
cancel_at_period_end: z.ZodBoolean;
|
|
34
|
+
interval: z.ZodEnum<{
|
|
35
|
+
day: "day";
|
|
36
|
+
week: "week";
|
|
37
|
+
month: "month";
|
|
38
|
+
year: "year";
|
|
39
|
+
}>;
|
|
40
|
+
interval_count: z.ZodNumber;
|
|
41
|
+
metadata: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
42
|
+
}, z.core.$strict>;
|
|
22
43
|
export type SubscriptionRow = z.infer<typeof SubscriptionRowSchema>;
|
|
23
44
|
export declare class BillingSubscriptionRepository {
|
|
24
45
|
private query;
|
|
25
46
|
constructor(query: QueryFn);
|
|
26
|
-
upsert(state:
|
|
47
|
+
upsert(state: BillingSubscriptionState): Promise<void>;
|
|
27
48
|
private map;
|
|
28
49
|
private withOfferContext;
|
|
29
50
|
get(provider: string, providerSubscriptionId: string): Promise<SubscriptionRow | null>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscription.d.ts","sourceRoot":"","sources":["../../../../src/billing/postgres/repositories/subscription.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"subscription.d.ts","sourceRoot":"","sources":["../../../../src/billing/postgres/repositories/subscription.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAC7E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAiEjE,QAAA,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAyBhB,CAAC;AAEZ,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAmCpE,qBAAa,6B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