@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,5 +1,5 @@
|
|
|
1
1
|
import type { BillingStore } from "./billing-store.js";
|
|
2
|
-
import type { BillingAutoRechargeAttempt, BillingAutoRechargeProfile, BillingCustomerRecord, BillingEvent, BillingEventResult, BillingOfferResult, BillingPreferences, BillingSubscriptionChange, BillingSubscriptionChangeInput, BillingSubscriptionState, BillingTopupResult, CheckoutIntent } from "./types/index.js";
|
|
2
|
+
import type { BillingAutoRechargeAttempt, BillingAutoRechargeAttemptState, BillingAutoRechargeProfile, BillingCustomerRecord, BillingEvent, BillingEventResult, BillingOfferResult, BillingPreferences, BillingSubscriptionChange, BillingSubscriptionChangeInput, BillingSubscriptionState, BillingTopupResult, CheckoutIntent } from "./types/index.js";
|
|
3
3
|
import { AutoRechargeService } from "./auto-recharge-service.js";
|
|
4
4
|
import type { BillingServiceOptions } from "./service-types.js";
|
|
5
5
|
export type { BillingProvisioningPort, BillingServiceOptions } from "./service-types.js";
|
|
@@ -19,7 +19,7 @@ export declare class BillingService {
|
|
|
19
19
|
getCheckoutIntent(id: string, subjectId: string): Promise<CheckoutIntent | null>;
|
|
20
20
|
getActiveSubscription(userId: string): Promise<BillingSubscriptionState | null>;
|
|
21
21
|
getUserPreferences(userId: string): Promise<BillingPreferences | null>;
|
|
22
|
-
listBillingInvoices(userId: string): Promise<import("./contracts.js").
|
|
22
|
+
listBillingInvoices(userId: string): Promise<import("./contracts.js").BillingInvoiceRecord[]>;
|
|
23
23
|
upsertBillingSubscription(state: BillingSubscriptionState): Promise<void>;
|
|
24
24
|
createBillingSubscriptionChange(input: BillingSubscriptionChangeInput): Promise<BillingSubscriptionChange>;
|
|
25
25
|
getOpenBillingSubscriptionChange(provider: string, providerSubscriptionId: string): Promise<BillingSubscriptionChange | null>;
|
|
@@ -27,7 +27,7 @@ export declare class BillingService {
|
|
|
27
27
|
recordSubscriptionConflict(input: Parameters<BillingStore["recordSubscriptionConflict"]>[0]): Promise<void>;
|
|
28
28
|
updateUserPreferences(preferences: BillingPreferences): Promise<void>;
|
|
29
29
|
getAutoRechargeProfile(userId: string): Promise<BillingAutoRechargeProfile | null>;
|
|
30
|
-
|
|
30
|
+
getActiveCatalogDocument(): Promise<Record<string, unknown> | null>;
|
|
31
31
|
listCancellableProviderSubscriptionIds(userId: string): Promise<string[]>;
|
|
32
32
|
listCancellableSubscriptions(userId: string): Promise<BillingSubscriptionState[]>;
|
|
33
33
|
pseudonymizeFinancialSubject(userId: string): Promise<void>;
|
|
@@ -40,7 +40,7 @@ export declare class BillingService {
|
|
|
40
40
|
}): Promise<BillingAutoRechargeAttempt | null>;
|
|
41
41
|
updateAutoRechargeAttempt(input: {
|
|
42
42
|
id: string;
|
|
43
|
-
state:
|
|
43
|
+
state: BillingAutoRechargeAttemptState;
|
|
44
44
|
providerAttemptId?: string | null;
|
|
45
45
|
failureCode?: string | null;
|
|
46
46
|
failureMessage?: string | null;
|
|
@@ -49,7 +49,7 @@ export declare class BillingService {
|
|
|
49
49
|
updateAutoRechargeAttemptByProviderPayment(input: {
|
|
50
50
|
provider: string;
|
|
51
51
|
providerPaymentId: string;
|
|
52
|
-
state:
|
|
52
|
+
state: BillingAutoRechargeAttemptState;
|
|
53
53
|
failureCode?: string | null;
|
|
54
54
|
failureMessage?: string | null;
|
|
55
55
|
}): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"billing-service.d.ts","sourceRoot":"","sources":["../../src/billing/billing-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EACV,0BAA0B,EAC1B,0BAA0B,EAC1B,qBAAqB,EACrB,YAAY,EACZ,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,yBAAyB,EACzB,8BAA8B,EAC9B,wBAAwB,EACxB,kBAAkB,EAClB,cAAc,EACf,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAGjE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wB,GAAG,IAAI,CAAC;IAUjF,yBAAyB,CAAC,GAAG,OAAa,GAAG,OAAO,CAAC,MAAM,CAAC;YAmCpD,mBAAmB;IA4BjC,mDAAmD;IACnD,oBAAoB,IAAI,IAAI;IAItB,kBAAkB,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,kBAAkB,CAAC;CAG3E"}
|
|
@@ -59,8 +59,8 @@ export class BillingService {
|
|
|
59
59
|
async getAutoRechargeProfile(userId) {
|
|
60
60
|
return this.management.getAutoRechargeProfile(userId);
|
|
61
61
|
}
|
|
62
|
-
async
|
|
63
|
-
return this.management.
|
|
62
|
+
async getActiveCatalogDocument() {
|
|
63
|
+
return this.management.getActiveCatalogDocument();
|
|
64
64
|
}
|
|
65
65
|
async listCancellableProviderSubscriptionIds(userId) {
|
|
66
66
|
return this.management.listCancellableProviderSubscriptionIds(userId);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"billing-service.js","sourceRoot":"","sources":["../../src/billing/billing-service.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAIpD;;;GAGG;AACH,MAAM,OAAO,cAAc;IAChB,YAAY,CAAsB;IAC1B,KAAK,CAAe;IACpB,UAAU,CAAoB;IAC9B,MAAM,CAAwB;IAE/C,IAAI,eAAe;QACjB,OAAO,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC;IACrC,CAAC;IAED,YAAY,KAAmB,EAAE,OAA+B;QAC9D,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,UAAU,GAAG,IAAI,iBAAiB,CAAC,KAAK,CAAC,CAAC;QAC/C,IAAI,CAAC,MAAM,GAAG,IAA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AAG,YAAY,EAAE,cAAc,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC;IAChF,CAAC;IAED,mDAAmD;IACnD,oBAAoB;QAClB,IAAI,CAAC,MAAM,CAAC,oBAAoB,EAAE,CAAC;IACrC,CAAC;IAED,KAAK,CAAC,kBAAkB,CAAC,KAAmB;QAC1C,OAAO,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;IAC/C,CAAC;CACF","sourcesContent":["import type { BillingStore } from \"./billing-store.js\";\nimport type {\n BillingAutoRechargeAttempt,\n BillingAutoRechargeAttemptState,\n BillingAutoRechargeProfile,\n BillingCustomerRecord,\n BillingEvent,\n BillingEventResult,\n BillingOfferResult,\n BillingPreferences,\n BillingSubscriptionChange,\n BillingSubscriptionChangeInput,\n BillingSubscriptionState,\n BillingTopupResult,\n CheckoutIntent,\n} from \"./types/index.js\";\nimport { SUBSCRIPTION_STATUS } from \"./types/index.js\";\nimport { AutoRechargeService } from \"./auto-recharge-service.js\";\nimport { BillingEventProcessor } from \"./event-processor.js\";\nimport { BillingManagement } from \"./management.js\";\nimport type { BillingServiceOptions } from \"./service-types.js\";\nexport type { BillingProvisioningPort, BillingServiceOptions } from \"./service-types.js\";\n\n/**\n * Provider-agnostic billing lifecycle state machine.\n * Mirrors the Python billing service implementation.\n */\nexport class BillingService {\n readonly autoRecharge: AutoRechargeService;\n private readonly store: BillingStore;\n private readonly management: BillingManagement;\n private readonly events: BillingEventProcessor;\n\n get hasProvisioning(): boolean {\n return this.events.hasProvisioning;\n }\n\n constructor(store: BillingStore, options?: BillingServiceOptions) {\n this.store = store;\n this.management = new BillingManagement(store);\n this.events = new BillingEventProcessor(store, options);\n this.autoRecharge = new AutoRechargeService(this);\n }\n\n async createOrGetCheckoutIntent(\n input: Parameters<BillingStore[\"createOrGetCheckoutIntent\"]>[0],\n ): Promise<CheckoutIntent> {\n return this.management.createOrGetCheckoutIntent(input);\n }\n\n async updateCheckoutIntent(\n id: string,\n update: Parameters<BillingStore[\"updateCheckoutIntent\"]>[1],\n ): Promise<void> {\n await this.management.updateCheckoutIntent(id, update);\n }\n\n async getCheckoutIntent(id: string, subjectId: string): Promise<CheckoutIntent | null> {\n return this.management.getCheckoutIntent(id, subjectId);\n }\n\n async getActiveSubscription(userId: string): Promise<BillingSubscriptionState | null> {\n return this.management.getActiveSubscription(userId);\n }\n\n async getUserPreferences(userId: string): Promise<BillingPreferences | null> {\n return this.management.getUserPreferences(userId);\n }\n\n async listBillingInvoices(userId: string) {\n return this.management.listBillingInvoices(userId);\n }\n\n async upsertBillingSubscription(state: BillingSubscriptionState): Promise<void> {\n await this.management.upsertBillingSubscription(state);\n }\n\n async createBillingSubscriptionChange(\n input: BillingSubscriptionChangeInput,\n ): Promise<BillingSubscriptionChange> {\n return this.management.createBillingSubscriptionChange(input);\n }\n\n async getOpenBillingSubscriptionChange(\n provider: string,\n providerSubscriptionId: string,\n ): Promise<BillingSubscriptionChange | null> {\n return this.management.getOpenBillingSubscriptionChange(provider, providerSubscriptionId);\n }\n\n async updateBillingSubscriptionChange(\n id: string,\n update: Parameters<BillingStore[\"updateBillingSubscriptionChange\"]>[1],\n ): Promise<void> {\n await this.management.updateBillingSubscriptionChange(id, update);\n }\n\n async recordSubscriptionConflict(\n input: Parameters<BillingStore[\"recordSubscriptionConflict\"]>[0],\n ): Promise<void> {\n await this.management.recordSubscriptionConflict(input);\n }\n\n async updateUserPreferences(preferences: BillingPreferences): Promise<void> {\n await this.management.updateUserPreferences(preferences);\n }\n\n async getAutoRechargeProfile(userId: string): Promise<BillingAutoRechargeProfile | null> {\n return this.management.getAutoRechargeProfile(userId);\n }\n\n async getActiveCatalogDocument(): Promise<Record<string, unknown> | null> {\n return this.management.getActiveCatalogDocument();\n }\n\n async listCancellableProviderSubscriptionIds(userId: string): Promise<string[]> {\n return this.management.listCancellableProviderSubscriptionIds(userId);\n }\n\n async listCancellableSubscriptions(userId: string): Promise<BillingSubscriptionState[]> {\n return this.management.listCancellableSubscriptions(userId);\n }\n\n async pseudonymizeFinancialSubject(userId: string): Promise<void> {\n await this.management.pseudonymizeFinancialSubject(userId);\n }\n\n async upsertAutoRechargeProfile(\n profile: BillingAutoRechargeProfile,\n options?: { resetCooldown?: boolean },\n ): Promise<void> {\n await this.management.upsertAutoRechargeProfile(profile, options);\n }\n\n async claimAutoRechargeAttempt(input: {\n userId: string;\n idempotencyKey: string;\n }): Promise<BillingAutoRechargeAttempt | null> {\n return this.management.claimAutoRechargeAttempt(input);\n }\n\n async updateAutoRechargeAttempt(input: {\n id: string;\n state: BillingAutoRechargeAttemptState;\n providerAttemptId?: string | null;\n failureCode?: string | null;\n failureMessage?: string | null;\n metadata?: Record<string, unknown>;\n }): Promise<void> {\n await this.management.updateAutoRechargeAttempt(input);\n }\n\n async updateAutoRechargeAttemptByProviderPayment(input: {\n provider: string;\n providerPaymentId: string;\n state: BillingAutoRechargeAttemptState;\n failureCode?: string | null;\n failureMessage?: string | null;\n }): Promise<void> {\n await this.management.updateAutoRechargeAttemptByProviderPayment(input);\n }\n\n async countAutoRechargeAttempts(userId: string, since: string | Date): Promise<number> {\n return this.management.countAutoRechargeAttempts(userId, since);\n }\n\n async getCustomerByUserId(\n userId: string,\n provider?: string | null,\n ): Promise<BillingCustomerRecord | null> {\n return this.management.getCustomerByUserId(userId, provider);\n }\n\n async resolveOffer(\n provider: string,\n productId?: string | null,\n priceId?: string | null,\n ): Promise<BillingOfferResult | null> {\n return this.management.resolveOffer(provider, productId, priceId);\n }\n\n async resolveOfferByLookup(\n provider: string,\n lookupKey: string,\n ): Promise<BillingOfferResult | null> {\n return this.management.resolveOfferByLookup(provider, lookupKey);\n }\n\n async resolveTopup(\n provider: string,\n productId?: string | null,\n priceId?: string | null,\n ): Promise<BillingTopupResult | null> {\n return this.management.resolveTopup(provider, productId, priceId);\n }\n\n async resolveTopupByLookup(\n provider: string,\n lookupKey: string,\n ): Promise<BillingTopupResult | null> {\n return this.management.resolveTopupByLookup(provider, lookupKey);\n }\n\n async upsertCustomer(\n provider: string,\n providerCustomerId: string,\n userId: string,\n email?: string | null,\n ): Promise<void> {\n await this.management.upsertCustomer(provider, providerCustomerId, userId, email);\n }\n\n async getUserSubscription(userId: string): Promise<BillingSubscriptionState | null> {\n const subscription = await this.store.getUserSubscription(userId, [\n SUBSCRIPTION_STATUS.ACTIVE,\n SUBSCRIPTION_STATUS.TRIALING,\n SUBSCRIPTION_STATUS.CANCELED,\n SUBSCRIPTION_STATUS.PAST_DUE,\n SUBSCRIPTION_STATUS.INCOMPLETE,\n // EXPIRED excluded — expired subscriptions are not \"current\" for billing purposes.\n ]);\n return this.expireGraceIfNeeded(subscription);\n }\n\n async getBlockingSubscription(userId: string): Promise<BillingSubscriptionState | null> {\n const subscription = await this.store.getUserSubscription(userId, [\n SUBSCRIPTION_STATUS.ACTIVE,\n SUBSCRIPTION_STATUS.TRIALING,\n SUBSCRIPTION_STATUS.PAST_DUE,\n SUBSCRIPTION_STATUS.INCOMPLETE,\n ]);\n return this.expireGraceIfNeeded(subscription);\n }\n\n async expirePastDueGracePeriods(now = new Date()): Promise<number> {\n if (!this.events.hasProvisioning) return 0;\n const asOf = now.toISOString();\n const candidates = await this.store.listExpiredGraceSubscriptions(asOf);\n let expiredCount = 0;\n for (const candidate of candidates) {\n if (!candidate.subscriptionId || !candidate.graceEndsAt) continue;\n const current = await this.store.getBillingSubscription(\n candidate.provider,\n candidate.providerSubscriptionId,\n );\n if (\n current?.status !== \"past_due\" ||\n current.graceEndsAt !== candidate.graceEndsAt ||\n current.graceExpiredAt\n ) {\n continue;\n }\n await this.events.revokeIfCurrentSubscription(\n candidate.userId,\n candidate.providerSubscriptionId,\n );\n if (\n await this.store.markSubscriptionGraceExpired(\n candidate.subscriptionId,\n candidate.graceEndsAt,\n asOf,\n )\n ) {\n expiredCount += 1;\n }\n }\n return expiredCount;\n }\n\n private async expireGraceIfNeeded(\n subscription: BillingSubscriptionState | null,\n ): Promise<BillingSubscriptionState | null> {\n if (\n !subscription ||\n !this.events.hasProvisioning ||\n subscription.status !== \"past_due\" ||\n subscription.graceExpiredAt ||\n !subscription.graceEndsAt ||\n new Date(subscription.graceEndsAt).getTime() > Date.now() ||\n !subscription.subscriptionId\n ) {\n return subscription;\n }\n\n await this.events.revokeIfCurrentSubscription(\n subscription.userId,\n subscription.providerSubscriptionId,\n );\n const expiredAt = new Date().toISOString();\n const marked = await this.store.markSubscriptionGraceExpired(\n subscription.subscriptionId,\n subscription.graceEndsAt,\n expiredAt,\n );\n return marked ? { ...subscription, graceExpiredAt: expiredAt } : subscription;\n }\n\n /** Invalidate cached provider offer resolution. */\n invalidateOfferCache(): void {\n this.events.invalidateOfferCache();\n }\n\n async ingestBillingEvent(event: BillingEvent): Promise<BillingEventResult> {\n return this.events.ingestBillingEvent(event);\n }\n}\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { BillingAutoRechargeAttempt, BillingAutoRechargeProfile, BillingCustomerRecord, BillingEventClaim, BillingOfferResult, BillingPreferences, BillingSubscriptionChange, BillingSubscriptionChangeInput, BillingSubscriptionState, CheckoutIntent, BillingTopupResult,
|
|
1
|
+
import type { BillingAutoRechargeAttempt, BillingAutoRechargeProfile, BillingCustomerRecord, BillingCreditPostingResult, BillingEventClaim, BillingOfferResult, BillingPaymentRecord, BillingPreferences, BillingSubscriptionChange, BillingSubscriptionChangeInput, BillingSubscriptionState, CheckoutIntent, BillingTopupResult, BillingInvoiceRecord } from "./types/index.js";
|
|
2
2
|
import type { AutoRechargeAttemptClaim, AutoRechargeAttemptUpdate, AutoRechargeProviderPaymentUpdate, BillingCreditGrantCreate, BillingDisputeUpsert, BillingInvoiceUpsert, BillingPaymentUpsert, BillingRefundUpsert, BillingSubscriptionChangeUpdate, BillingSubscriptionConflictCreate, CheckoutIntentCreate, CheckoutIntentUpdate } from "./contracts.js";
|
|
3
|
+
import type Decimal from "decimal.js";
|
|
3
4
|
/**
|
|
4
5
|
* Abstract billing store — provider-agnostic persistence layer for
|
|
5
6
|
* subscription lifecycle state.
|
|
@@ -12,8 +13,8 @@ export declare abstract class BillingStore {
|
|
|
12
13
|
abstract getCheckoutIntent(id: string, subjectId: string): Promise<CheckoutIntent | null>;
|
|
13
14
|
abstract resolveBillingOffer(provider: string, productId?: string | null, priceId?: string | null): Promise<BillingOfferResult | null>;
|
|
14
15
|
abstract claimBillingEvent(provider: string, eventId: string, eventType: string, envelope?: Record<string, unknown>): Promise<BillingEventClaim>;
|
|
15
|
-
abstract completeBillingEvent(provider: string, eventId: string, claimToken: string): Promise<
|
|
16
|
-
abstract failBillingEvent(provider: string, eventId: string, claimToken: string, error?: string): Promise<
|
|
16
|
+
abstract completeBillingEvent(provider: string, eventId: string, claimToken: string): Promise<boolean>;
|
|
17
|
+
abstract failBillingEvent(provider: string, eventId: string, claimToken: string, error?: string): Promise<boolean>;
|
|
17
18
|
abstract upsertBillingCustomer(provider: string, providerCustomerId: string, userId: string, email?: string | null): Promise<void>;
|
|
18
19
|
abstract upsertBillingSubscription(state: BillingSubscriptionState): Promise<void>;
|
|
19
20
|
abstract getBillingCustomer(provider: string, providerCustomerId: string): Promise<string | null>;
|
|
@@ -27,18 +28,18 @@ export declare abstract class BillingStore {
|
|
|
27
28
|
abstract resolveCreditTopup(provider: string, productId?: string | null, priceId?: string | null): Promise<BillingTopupResult | null>;
|
|
28
29
|
abstract resolveCreditTopupByLookup(provider: string, lookupKey: string): Promise<BillingTopupResult | null>;
|
|
29
30
|
abstract resolveBillingOfferByLookup(provider: string, lookupKey: string): Promise<BillingOfferResult | null>;
|
|
30
|
-
abstract computeTopupCredits(amountMinor: number, topupConfig: BillingTopupResult): Promise<
|
|
31
|
+
abstract computeTopupCredits(amountMinor: number, topupConfig: BillingTopupResult): Promise<Decimal>;
|
|
31
32
|
abstract upsertBillingPayment(options: BillingPaymentUpsert): Promise<string>;
|
|
32
33
|
abstract createBillingCreditGrant(input: BillingCreditGrantCreate): Promise<string>;
|
|
33
|
-
abstract grantBillingCredit(grantId: string, idempotencyKey: string): Promise<
|
|
34
|
+
abstract grantBillingCredit(grantId: string, idempotencyKey: string): Promise<BillingCreditPostingResult>;
|
|
34
35
|
abstract getBillingCreditGrantByPayment(paymentId: string): Promise<string | null>;
|
|
35
|
-
abstract postBillingRefund(refundId: string, grantId: string, amountMinor: number, idempotencyKey: string): Promise<
|
|
36
|
-
abstract listBillingInvoices(userId: string): Promise<
|
|
36
|
+
abstract postBillingRefund(refundId: string, grantId: string, amountMinor: number, idempotencyKey: string): Promise<BillingCreditPostingResult>;
|
|
37
|
+
abstract listBillingInvoices(userId: string): Promise<BillingInvoiceRecord[]>;
|
|
37
38
|
abstract upsertBillingRefund(options: BillingRefundUpsert): Promise<string>;
|
|
38
39
|
abstract upsertBillingInvoice(options: BillingInvoiceUpsert): Promise<void>;
|
|
39
40
|
abstract upsertBillingDispute(options: BillingDisputeUpsert): Promise<void>;
|
|
40
|
-
abstract getBillingPayment(provider: string, providerPaymentId: string): Promise<
|
|
41
|
-
abstract
|
|
41
|
+
abstract getBillingPayment(provider: string, providerPaymentId: string): Promise<BillingPaymentRecord | null>;
|
|
42
|
+
abstract getActiveCatalogDocument(): Promise<Record<string, unknown> | null>;
|
|
42
43
|
abstract pseudonymizeFinancialSubject(userId: string): Promise<boolean>;
|
|
43
44
|
abstract getUserSubscriptions(userId: string): Promise<BillingSubscriptionState[]>;
|
|
44
45
|
abstract recordSubscriptionConflict(input: BillingSubscriptionConflictCreate): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"billing-store.d.ts","sourceRoot":"","sources":["../../src/billing/billing-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,0BAA0B,EAC1B,0BAA0B,EAC1B,qBAAqB,EACrB,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,yBAAyB,EACzB,8BAA8B,EAC9B,wBAAwB,EACxB,cAAc,EACd,kBAAkB,EAClB,
|
|
1
|
+
{"version":3,"file":"billing-store.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AAG,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;IAElF,QAAQ,CAAC,wBAAwB,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAC3E,QAAQ,CAAC,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,0BAA0B,GAAG,IAAI,CAAC;IAC3F,QAAQ,CAAC,yBAAyB,CAChC,OAAO,EAAE,0BAA0B,EACnC,OAAO,CAAC,EAAE;QAAE,aAAa,CAAC,EAAE,OAAO,CAAA;KAAE,GACpC,OAAO,CAAC,IAAI,CAAC;IAChB,QAAQ,CAAC,wBAAwB,CAC/B,KAAK,EAAE,wBAAwB,GAC9B,OAAO,CAAC,0BAA0B,GAAG,IAAI,CAAC;IAC7C,QAAQ,CAAC,yBAAyB,CAAC,KAAK,EAAE,yBAAyB,GAAG,OAAO,CAAC,IAAI,CAAC;IACnF,QAAQ,CAAC,0CAA0C,CACjD,KAAK,EAAE,iCAAiC,GACvC,OAAO,CAAC,IAAI,CAAC;IAChB,QAAQ,CAAC,yBAAyB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC;IAEzF,QAAQ,CAAC,0BAA0B,CACjC,MAAM,EAAE,MAAM,EACd,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,GACvB,OAAO,CAAC,qBAAqB,GAAG,IAAI,CAAC;CACzC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"billing-store.js","sourceRoot":"","sources":["../../src/billing/billing-store.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"billing-store.js","sourceRoot":"","sources":["../../src/billing/billing-store.ts"],"names":[],"mappings":"AAgCA;;;;;GAKG;AACH,MAAM,OAAgB,YAAY;CAkKjC","sourcesContent":["import type {\n BillingAutoRechargeAttempt,\n BillingAutoRechargeProfile,\n BillingCustomerRecord,\n BillingCreditPostingResult,\n BillingEventClaim,\n BillingOfferResult,\n BillingPaymentRecord,\n BillingPreferences,\n BillingSubscriptionChange,\n BillingSubscriptionChangeInput,\n BillingSubscriptionState,\n CheckoutIntent,\n BillingTopupResult,\n BillingInvoiceRecord,\n} from \"./types/index.js\";\nimport type {\n AutoRechargeAttemptClaim,\n AutoRechargeAttemptUpdate,\n AutoRechargeProviderPaymentUpdate,\n BillingCreditGrantCreate,\n BillingDisputeUpsert,\n BillingInvoiceUpsert,\n BillingPaymentUpsert,\n BillingRefundUpsert,\n BillingSubscriptionChangeUpdate,\n BillingSubscriptionConflictCreate,\n CheckoutIntentCreate,\n CheckoutIntentUpdate,\n} from \"./contracts.js\";\nimport type Decimal from \"decimal.js\";\n\n/**\n * Abstract billing store — provider-agnostic persistence layer for\n * subscription lifecycle state.\n *\n * Mirrors Python bursar/billing/store.py.\n */\nexport abstract class BillingStore {\n abstract createOrGetCheckoutIntent(input: CheckoutIntentCreate): Promise<CheckoutIntent>;\n\n abstract updateCheckoutIntent(id: string, update: CheckoutIntentUpdate): Promise<void>;\n\n abstract getCheckoutIntent(id: string, subjectId: string): Promise<CheckoutIntent | null>;\n\n abstract resolveBillingOffer(\n provider: string,\n productId?: string | null,\n priceId?: string | null,\n ): Promise<BillingOfferResult | null>;\n\n abstract claimBillingEvent(\n provider: string,\n eventId: string,\n eventType: string,\n envelope?: Record<string, unknown>,\n ): Promise<BillingEventClaim>;\n\n abstract completeBillingEvent(\n provider: string,\n eventId: string,\n claimToken: string,\n ): Promise<boolean>;\n\n abstract failBillingEvent(\n provider: string,\n eventId: string,\n claimToken: string,\n error?: string,\n ): Promise<boolean>;\n\n abstract upsertBillingCustomer(\n provider: string,\n providerCustomerId: string,\n userId: string,\n email?: string | null,\n ): Promise<void>;\n\n abstract upsertBillingSubscription(state: BillingSubscriptionState): Promise<void>;\n\n abstract getBillingCustomer(provider: string, providerCustomerId: string): Promise<string | null>;\n\n abstract getBillingSubscription(\n provider: string,\n providerSubscriptionId: string,\n ): Promise<BillingSubscriptionState | null>;\n\n abstract createBillingSubscriptionChange(\n input: BillingSubscriptionChangeInput,\n ): Promise<BillingSubscriptionChange>;\n\n abstract getOpenBillingSubscriptionChange(\n provider: string,\n providerSubscriptionId: string,\n ): Promise<BillingSubscriptionChange | null>;\n\n abstract listExpiredGraceSubscriptions(\n now: string,\n limit?: number,\n ): Promise<BillingSubscriptionState[]>;\n\n abstract markSubscriptionGraceExpired(\n subscriptionId: string,\n expectedGraceEndsAt: string,\n expiredAt?: string,\n ): Promise<boolean>;\n\n abstract updateBillingSubscriptionChange(\n id: string,\n update: BillingSubscriptionChangeUpdate,\n ): Promise<void>;\n\n abstract getUserSubscription(\n userId: string,\n statuses?: string[],\n ): Promise<BillingSubscriptionState | null>;\n\n abstract resolveCreditTopup(\n provider: string,\n productId?: string | null,\n priceId?: string | null,\n ): Promise<BillingTopupResult | null>;\n abstract resolveCreditTopupByLookup(\n provider: string,\n lookupKey: string,\n ): Promise<BillingTopupResult | null>;\n\n abstract resolveBillingOfferByLookup(\n provider: string,\n lookupKey: string,\n ): Promise<BillingOfferResult | null>;\n\n abstract computeTopupCredits(\n amountMinor: number,\n topupConfig: BillingTopupResult,\n ): Promise<Decimal>;\n\n abstract upsertBillingPayment(options: BillingPaymentUpsert): Promise<string>;\n abstract createBillingCreditGrant(input: BillingCreditGrantCreate): Promise<string>;\n abstract grantBillingCredit(\n grantId: string,\n idempotencyKey: string,\n ): Promise<BillingCreditPostingResult>;\n abstract getBillingCreditGrantByPayment(paymentId: string): Promise<string | null>;\n abstract postBillingRefund(\n refundId: string,\n grantId: string,\n amountMinor: number,\n idempotencyKey: string,\n ): Promise<BillingCreditPostingResult>;\n\n abstract listBillingInvoices(userId: string): Promise<BillingInvoiceRecord[]>;\n\n abstract upsertBillingRefund(options: BillingRefundUpsert): Promise<string>;\n\n abstract upsertBillingInvoice(options: BillingInvoiceUpsert): Promise<void>;\n\n abstract upsertBillingDispute(options: BillingDisputeUpsert): Promise<void>;\n\n abstract getBillingPayment(\n provider: string,\n providerPaymentId: string,\n ): Promise<BillingPaymentRecord | null>;\n\n abstract getActiveCatalogDocument(): Promise<Record<string, unknown> | null>;\n\n abstract pseudonymizeFinancialSubject(userId: string): Promise<boolean>;\n\n abstract getUserSubscriptions(userId: string): Promise<BillingSubscriptionState[]>;\n\n abstract recordSubscriptionConflict(input: BillingSubscriptionConflictCreate): Promise<void>;\n\n /** Select a current provider subscription as the subject's entitlement source. */\n abstract selectSubscriptionEntitlementSource(\n userId: string,\n provider: string,\n providerSubscriptionId?: string | null,\n ): Promise<boolean>;\n\n abstract getBillingPreferences(userId: string): Promise<BillingPreferences | null>;\n\n abstract upsertBillingPreferences(prefs: BillingPreferences): Promise<void>;\n abstract getAutoRechargeProfile(userId: string): Promise<BillingAutoRechargeProfile | null>;\n abstract upsertAutoRechargeProfile(\n profile: BillingAutoRechargeProfile,\n options?: { resetCooldown?: boolean },\n ): Promise<void>;\n abstract claimAutoRechargeAttempt(\n input: AutoRechargeAttemptClaim,\n ): Promise<BillingAutoRechargeAttempt | null>;\n abstract updateAutoRechargeAttempt(input: AutoRechargeAttemptUpdate): Promise<void>;\n abstract updateAutoRechargeAttemptByProviderPayment(\n input: AutoRechargeProviderPaymentUpdate,\n ): Promise<void>;\n abstract countAutoRechargeAttempts(userId: string, since: string | Date): Promise<number>;\n\n abstract getBillingCustomerByUserId(\n userId: string,\n provider?: string | null,\n ): Promise<BillingCustomerRecord | null>;\n}\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AutoRechargeService } from "./auto-recharge-service.js";
|
|
2
|
-
import type
|
|
2
|
+
import type Decimal from "decimal.js";
|
|
3
|
+
import type { BillingAutoRechargeAttempt, BillingAutoRechargeAttemptState, BillingAutoRechargeProfile, BillingCustomerRecord, BillingDisputeInfo, BillingEvent, BillingEventResult, BillingInvoiceInfo, BillingInvoiceRecord, BillingOfferResult, BillingPaymentInfo, BillingPreferences, BillingRefundInfo, BillingSubscriptionChange, BillingSubscriptionChangeInput, BillingSubscriptionState, BillingTopupResult, CheckoutIntent } from "./types/index.js";
|
|
3
4
|
export interface CheckoutIntentCreate {
|
|
4
5
|
subjectId: string;
|
|
5
6
|
provider: string;
|
|
@@ -30,58 +31,57 @@ export interface BillingPaymentUpsert {
|
|
|
30
31
|
provider: string;
|
|
31
32
|
providerPaymentId: string;
|
|
32
33
|
providerInvoiceId?: string | null;
|
|
33
|
-
userId
|
|
34
|
-
amountMinor
|
|
35
|
-
taxMinor
|
|
36
|
-
currency
|
|
37
|
-
purpose
|
|
38
|
-
status
|
|
39
|
-
providerUpdatedAt
|
|
34
|
+
userId: string;
|
|
35
|
+
amountMinor: number;
|
|
36
|
+
taxMinor: number;
|
|
37
|
+
currency: string;
|
|
38
|
+
purpose: "subscription" | "credit_topup";
|
|
39
|
+
status: "pending" | "succeeded" | "failed" | "canceled";
|
|
40
|
+
providerUpdatedAt: string;
|
|
40
41
|
metadata?: Record<string, unknown> | null;
|
|
41
42
|
}
|
|
42
43
|
export interface BillingCreditGrantCreate {
|
|
43
44
|
paymentId?: string | null;
|
|
44
45
|
subscriptionId?: string | null;
|
|
45
46
|
topupId?: string | null;
|
|
46
|
-
configuredCredits:
|
|
47
|
-
quantity
|
|
47
|
+
configuredCredits: Decimal;
|
|
48
|
+
quantity: number;
|
|
48
49
|
billingEventId?: string | null;
|
|
49
50
|
}
|
|
50
51
|
export interface BillingRefundUpsert {
|
|
51
52
|
provider: string;
|
|
52
53
|
providerRefundId: string;
|
|
53
|
-
providerPaymentId
|
|
54
|
-
userId
|
|
55
|
-
amountMinor
|
|
56
|
-
currency
|
|
54
|
+
providerPaymentId: string;
|
|
55
|
+
userId: string;
|
|
56
|
+
amountMinor: number;
|
|
57
|
+
currency: string;
|
|
57
58
|
reason?: string | null;
|
|
58
|
-
status
|
|
59
|
-
providerUpdatedAt
|
|
59
|
+
status: "pending" | "succeeded" | "failed" | "canceled";
|
|
60
|
+
providerUpdatedAt: string;
|
|
60
61
|
metadata?: Record<string, unknown> | null;
|
|
61
62
|
}
|
|
62
63
|
export interface BillingInvoiceUpsert {
|
|
63
64
|
provider: string;
|
|
64
65
|
providerInvoiceId: string;
|
|
65
66
|
providerSubscriptionId?: string | null;
|
|
66
|
-
userId
|
|
67
|
-
status
|
|
68
|
-
amountPaidMinor
|
|
69
|
-
amountDueMinor
|
|
70
|
-
currency
|
|
67
|
+
userId: string;
|
|
68
|
+
status: "draft" | "open" | "paid" | "void" | "uncollectible";
|
|
69
|
+
amountPaidMinor: number;
|
|
70
|
+
amountDueMinor: number;
|
|
71
|
+
currency: string;
|
|
71
72
|
periodStart?: string | null;
|
|
72
73
|
periodEnd?: string | null;
|
|
73
74
|
metadata?: Record<string, unknown> | null;
|
|
74
|
-
providerUpdatedAt
|
|
75
|
+
providerUpdatedAt: string;
|
|
75
76
|
}
|
|
76
77
|
export interface BillingDisputeUpsert {
|
|
77
78
|
provider: string;
|
|
78
79
|
providerDisputeId: string;
|
|
79
|
-
providerPaymentId
|
|
80
|
-
|
|
81
|
-
status?: string;
|
|
80
|
+
providerPaymentId: string;
|
|
81
|
+
status: "needs_response" | "under_review" | "won" | "lost" | "closed";
|
|
82
82
|
reason?: string | null;
|
|
83
83
|
metadata?: Record<string, unknown> | null;
|
|
84
|
-
providerUpdatedAt
|
|
84
|
+
providerUpdatedAt: string;
|
|
85
85
|
}
|
|
86
86
|
export interface AutoRechargeAttemptClaim {
|
|
87
87
|
userId: string;
|
|
@@ -89,7 +89,7 @@ export interface AutoRechargeAttemptClaim {
|
|
|
89
89
|
}
|
|
90
90
|
export interface AutoRechargeAttemptUpdate {
|
|
91
91
|
id: string;
|
|
92
|
-
state:
|
|
92
|
+
state: BillingAutoRechargeAttemptState;
|
|
93
93
|
providerAttemptId?: string | null;
|
|
94
94
|
failureCode?: string | null;
|
|
95
95
|
failureMessage?: string | null;
|
|
@@ -98,7 +98,7 @@ export interface AutoRechargeAttemptUpdate {
|
|
|
98
98
|
export interface AutoRechargeProviderPaymentUpdate {
|
|
99
99
|
provider: string;
|
|
100
100
|
providerPaymentId: string;
|
|
101
|
-
state:
|
|
101
|
+
state: BillingAutoRechargeAttemptState;
|
|
102
102
|
failureCode?: string | null;
|
|
103
103
|
failureMessage?: string | null;
|
|
104
104
|
}
|
|
@@ -117,10 +117,10 @@ export interface BillingCapability extends BillingEventSink {
|
|
|
117
117
|
getActiveSubscription(userId: string): Promise<BillingSubscriptionState | null>;
|
|
118
118
|
getBlockingSubscription(userId: string): Promise<BillingSubscriptionState | null>;
|
|
119
119
|
getUserPreferences(userId: string): Promise<BillingPreferences | null>;
|
|
120
|
-
|
|
120
|
+
getActiveCatalogDocument(): Promise<Record<string, unknown> | null>;
|
|
121
121
|
listCancellableProviderSubscriptionIds(userId: string): Promise<string[]>;
|
|
122
122
|
listCancellableSubscriptions(userId: string): Promise<BillingSubscriptionState[]>;
|
|
123
|
-
listBillingInvoices(userId: string): Promise<
|
|
123
|
+
listBillingInvoices(userId: string): Promise<BillingInvoiceRecord[]>;
|
|
124
124
|
createBillingSubscriptionChange(input: BillingSubscriptionChangeInput): Promise<BillingSubscriptionChange>;
|
|
125
125
|
getOpenBillingSubscriptionChange(provider: string, providerSubscriptionId: string): Promise<BillingSubscriptionChange | null>;
|
|
126
126
|
updateBillingSubscriptionChange(id: string, update: BillingSubscriptionChangeUpdate): Promise<void>;
|
|
@@ -145,5 +145,5 @@ export interface BillingCapability extends BillingEventSink {
|
|
|
145
145
|
upsertCustomer(provider: string, providerCustomerId: string, userId: string, email?: string | null): Promise<void>;
|
|
146
146
|
pseudonymizeFinancialSubject(userId: string): Promise<void>;
|
|
147
147
|
}
|
|
148
|
-
export type { BillingDisputeInfo, BillingInvoiceInfo, BillingPaymentInfo, BillingRefundInfo };
|
|
148
|
+
export type { BillingDisputeInfo, BillingInvoiceInfo, BillingInvoiceRecord, BillingPaymentInfo, BillingRefundInfo, };
|
|
149
149
|
//# sourceMappingURL=contracts.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
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AAY,CACV,QAAQ,EAAE,MAAM,EAChB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,EACzB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,GACtB,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC,CAAC;IACtC,oBAAoB,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC,CAAC;IAC9F,cAAc,CACZ,QAAQ,EAAE,MAAM,EAChB,kBAAkB,EAAE,MAAM,EAC1B,MAAM,EAAE,MAAM,EACd,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,GACpB,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,4BAA4B,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7D;AAID,YAAY,EACV,kBAAkB,EAClB,kBAAkB,EAClB,oBAAoB,EACpB,kBAAkB,EAClB,iBAAiB,GAClB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contracts.js","sourceRoot":"","sources":["../../src/billing/contracts.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"contracts.js","sourceRoot":"","sources":["../../src/billing/contracts.ts"],"names":[],"mappings":"","sourcesContent":["import type { AutoRechargeService } from \"./auto-recharge-service.js\";\nimport type Decimal from \"decimal.js\";\nimport type {\n BillingAutoRechargeAttempt,\n BillingAutoRechargeAttemptState,\n BillingAutoRechargeProfile,\n BillingCustomerRecord,\n BillingDisputeInfo,\n BillingEvent,\n BillingEventResult,\n BillingInvoiceInfo,\n BillingInvoiceRecord,\n BillingOfferResult,\n BillingPaymentInfo,\n BillingPreferences,\n BillingRefundInfo,\n BillingSubscriptionChange,\n BillingSubscriptionChangeInput,\n BillingSubscriptionState,\n BillingTopupResult,\n CheckoutIntent,\n} from \"./types/index.js\";\n\nexport interface CheckoutIntentCreate {\n subjectId: string;\n provider: string;\n checkoutKind: \"subscription\" | \"credit_topup\";\n productKey: string;\n requestDigest: string;\n expiresAt: string;\n}\n\nexport interface CheckoutIntentUpdate {\n status?: \"open\" | \"completed\" | \"failed\" | \"expired\";\n providerSessionId?: string | null;\n checkoutUrl?: string | null;\n}\n\nexport interface BillingSubscriptionChangeUpdate {\n state?: BillingSubscriptionChange[\"state\"];\n providerOperationId?: string | null;\n errorMessage?: string | null;\n}\n\nexport interface BillingSubscriptionConflictCreate {\n userId?: string | null;\n provider: string;\n duplicateSubscriptionId: string;\n existingSubscriptionId?: string | null;\n eventId?: string | null;\n metadata?: Record<string, unknown>;\n}\n\nexport interface BillingPaymentUpsert {\n provider: string;\n providerPaymentId: string;\n providerInvoiceId?: string | null;\n userId: string;\n amountMinor: number;\n taxMinor: number;\n currency: string;\n purpose: \"subscription\" | \"credit_topup\";\n status: \"pending\" | \"succeeded\" | \"failed\" | \"canceled\";\n providerUpdatedAt: string;\n metadata?: Record<string, unknown> | null;\n}\n\nexport interface BillingCreditGrantCreate {\n paymentId?: string | null;\n subscriptionId?: string | null;\n topupId?: string | null;\n configuredCredits: Decimal;\n quantity: number;\n billingEventId?: string | null;\n}\n\nexport interface BillingRefundUpsert {\n provider: string;\n providerRefundId: string;\n providerPaymentId: string;\n userId: string;\n amountMinor: number;\n currency: string;\n reason?: string | null;\n status: \"pending\" | \"succeeded\" | \"failed\" | \"canceled\";\n providerUpdatedAt: string;\n metadata?: Record<string, unknown> | null;\n}\n\nexport interface BillingInvoiceUpsert {\n provider: string;\n providerInvoiceId: string;\n providerSubscriptionId?: string | null;\n userId: string;\n status: \"draft\" | \"open\" | \"paid\" | \"void\" | \"uncollectible\";\n amountPaidMinor: number;\n amountDueMinor: number;\n currency: string;\n periodStart?: string | null;\n periodEnd?: string | null;\n metadata?: Record<string, unknown> | null;\n providerUpdatedAt: string;\n}\n\nexport interface BillingDisputeUpsert {\n provider: string;\n providerDisputeId: string;\n providerPaymentId: string;\n status: \"needs_response\" | \"under_review\" | \"won\" | \"lost\" | \"closed\";\n reason?: string | null;\n metadata?: Record<string, unknown> | null;\n providerUpdatedAt: string;\n}\n\nexport interface AutoRechargeAttemptClaim {\n userId: string;\n idempotencyKey: string;\n}\n\nexport interface AutoRechargeAttemptUpdate {\n id: string;\n state: BillingAutoRechargeAttemptState;\n providerAttemptId?: string | null;\n failureCode?: string | null;\n failureMessage?: string | null;\n metadata?: Record<string, unknown>;\n}\n\nexport interface AutoRechargeProviderPaymentUpdate {\n provider: string;\n providerPaymentId: string;\n state: BillingAutoRechargeAttemptState;\n failureCode?: string | null;\n failureMessage?: string | null;\n}\n\n/** Boundary used by payment providers to submit normalized lifecycle events. */\nexport interface BillingEventSink {\n ingestBillingEvent(event: BillingEvent): Promise<BillingEventResult>;\n}\n\n/** Application-facing billing capability exposed by Bursar. */\nexport interface BillingCapability extends BillingEventSink {\n readonly autoRecharge: AutoRechargeService;\n readonly hasProvisioning: boolean;\n createOrGetCheckoutIntent(input: CheckoutIntentCreate): Promise<CheckoutIntent>;\n updateCheckoutIntent(id: string, update: CheckoutIntentUpdate): Promise<void>;\n getCheckoutIntent(id: string, subjectId: string): Promise<CheckoutIntent | null>;\n getUserSubscription(userId: string): Promise<BillingSubscriptionState | null>;\n getActiveSubscription(userId: string): Promise<BillingSubscriptionState | null>;\n getBlockingSubscription(userId: string): Promise<BillingSubscriptionState | null>;\n getUserPreferences(userId: string): Promise<BillingPreferences | null>;\n getActiveCatalogDocument(): Promise<Record<string, unknown> | null>;\n listCancellableProviderSubscriptionIds(userId: string): Promise<string[]>;\n listCancellableSubscriptions(userId: string): Promise<BillingSubscriptionState[]>;\n listBillingInvoices(userId: string): Promise<BillingInvoiceRecord[]>;\n createBillingSubscriptionChange(\n input: BillingSubscriptionChangeInput,\n ): Promise<BillingSubscriptionChange>;\n getOpenBillingSubscriptionChange(\n provider: string,\n providerSubscriptionId: string,\n ): Promise<BillingSubscriptionChange | null>;\n updateBillingSubscriptionChange(\n id: string,\n update: BillingSubscriptionChangeUpdate,\n ): Promise<void>;\n recordSubscriptionConflict(input: BillingSubscriptionConflictCreate): Promise<void>;\n upsertBillingSubscription(state: BillingSubscriptionState): Promise<void>;\n updateUserPreferences(preferences: BillingPreferences): Promise<void>;\n getAutoRechargeProfile(userId: string): Promise<BillingAutoRechargeProfile | null>;\n upsertAutoRechargeProfile(\n profile: BillingAutoRechargeProfile,\n options?: { resetCooldown?: boolean },\n ): Promise<void>;\n claimAutoRechargeAttempt(\n input: AutoRechargeAttemptClaim,\n ): Promise<BillingAutoRechargeAttempt | null>;\n updateAutoRechargeAttempt(input: AutoRechargeAttemptUpdate): Promise<void>;\n updateAutoRechargeAttemptByProviderPayment(\n input: AutoRechargeProviderPaymentUpdate,\n ): Promise<void>;\n countAutoRechargeAttempts(userId: string, since: string | Date): Promise<number>;\n expirePastDueGracePeriods(now?: Date): Promise<number>;\n invalidateOfferCache(): void;\n getCustomerByUserId(\n userId: string,\n provider?: string | null,\n ): Promise<BillingCustomerRecord | null>;\n resolveOffer(\n provider: string,\n productId?: string | null,\n priceId?: string | null,\n ): Promise<BillingOfferResult | null>;\n resolveOfferByLookup(provider: string, lookupKey: string): Promise<BillingOfferResult | null>;\n resolveTopup(\n provider: string,\n productId?: string | null,\n priceId?: string | null,\n ): Promise<BillingTopupResult | null>;\n resolveTopupByLookup(provider: string, lookupKey: string): Promise<BillingTopupResult | null>;\n upsertCustomer(\n provider: string,\n providerCustomerId: string,\n userId: string,\n email?: string | null,\n ): Promise<void>;\n pseudonymizeFinancialSubject(userId: string): Promise<void>;\n}\n\n// Keep document-record types reachable from the contract module for store\n// implementers without forcing them to import the broad billing type barrel.\nexport type {\n BillingDisputeInfo,\n BillingInvoiceInfo,\n BillingInvoiceRecord,\n BillingPaymentInfo,\n BillingRefundInfo,\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-handlers.d.ts","sourceRoot":"","sources":["../../src/billing/event-handlers.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE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KAAK,EAAE,YAAY,EACnB,MAAM,EAAE,WAAW,GAAG,QAAQ,GAAG,SAAS,GACzC,OAAO,CAAC,IAAI,CAAC;IAMhB;;;;OAIG;YACW,aAAa;YAgDb,yBAAyB;YAYzB,qBAAqB;YAmBrB,qBAAqB;YAcrB,uBAAuB;YAwBvB,uBAAuB;IAUrC,OAAO,CAAC,sBAAsB;YAiEhB,mBAAmB;YA+CnB,yBAAyB;YA+FzB,yBAAyB;YA8BzB,2BAA2B;YA2B3B,yBAAyB;YAyBzB,6BAA6B;YAoD7B,2BAA2B;YAe3B,6BAA6B;YAe7B,0BAA0B;YAwC1B,yBAAyB;YAkBzB,wBAAwB;YAkBxB,yBAAyB;YAqBzB,kBAAkB;YAMlB,qBAAqB;YAgErB,sBAAsB;YAkCtB,kBAAkB;IAShC;;;OAGG;IACG,2BAA2B,CAAC,GAAG,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;YAOvE,gBAAgB;YA8ChB,qBAAqB;CASpC"}
|
|
@@ -2,6 +2,7 @@ import { LRUCache } from "lru-cache";
|
|
|
2
2
|
import { normalizeLogger } from "../shared/logger.js";
|
|
3
3
|
import { BillingEventType } from "./types/index.js";
|
|
4
4
|
import { BillingFinancialEventHandlers } from "./financial-event-handlers.js";
|
|
5
|
+
import { StoreError } from "../errors.js";
|
|
5
6
|
export class BillingEventHandlers {
|
|
6
7
|
store;
|
|
7
8
|
provisioning;
|
|
@@ -176,7 +177,7 @@ export class BillingEventHandlers {
|
|
|
176
177
|
}
|
|
177
178
|
buildSubscriptionState(event, userId, existing, overrides) {
|
|
178
179
|
if (!event.subscription) {
|
|
179
|
-
throw new
|
|
180
|
+
throw new TypeError("billing subscription event requires subscription data");
|
|
180
181
|
}
|
|
181
182
|
const sub = event.subscription;
|
|
182
183
|
const status = overrides?.status ?? sub.status ?? existing?.status ?? "incomplete";
|
|
@@ -412,6 +413,13 @@ export class BillingEventHandlers {
|
|
|
412
413
|
return { handled: false, error: "no_subscription_data" };
|
|
413
414
|
const existing = await this.getExistingSubscription(event);
|
|
414
415
|
const { offer, offerId, offerKey, plan } = await this.resolveOfferAndKeys(event);
|
|
416
|
+
// Capture the current allowance anchor before advancing the durable
|
|
417
|
+
// change. The Postgres transition updates the assignment atomically, so
|
|
418
|
+
// reading it afterwards would return the new assignment's timestamp and
|
|
419
|
+
// silently reset the learner's current allowance window.
|
|
420
|
+
const preservedAllowanceAnchor = this.provisioning?.getUserPlan
|
|
421
|
+
? ((await this.provisioning.getUserPlan(uid))?.planAssignedAt ?? null)
|
|
422
|
+
: undefined;
|
|
415
423
|
const pending = await this.store.getOpenBillingSubscriptionChange(event.provider, event.subscription.providerSubscriptionId);
|
|
416
424
|
if (pending) {
|
|
417
425
|
await this.store.updateBillingSubscriptionChange(pending.id, {
|
|
@@ -433,7 +441,7 @@ export class BillingEventHandlers {
|
|
|
433
441
|
}));
|
|
434
442
|
if (this.provisioning && (plan ?? existing?.plan)) {
|
|
435
443
|
// Plan-change: prefer new plan over existing (renewal at L422 correctly keeps existing).
|
|
436
|
-
await this.provisionSubscription(uid, offer, event, plan ?? existing?.plan ?? undefined, true);
|
|
444
|
+
await this.provisionSubscription(uid, offer, event, plan ?? existing?.plan ?? undefined, true, preservedAllowanceAnchor);
|
|
437
445
|
}
|
|
438
446
|
return { handled: true, action: "subscription_plan_changed" };
|
|
439
447
|
}
|
|
@@ -476,7 +484,13 @@ export class BillingEventHandlers {
|
|
|
476
484
|
const existing = await this.getExistingSubscription(event);
|
|
477
485
|
const resolved = existing ? null : await this.resolveOfferAndKeys(event);
|
|
478
486
|
if (!existing && !resolved?.offerId) {
|
|
479
|
-
throw new
|
|
487
|
+
throw new StoreError(`cannot persist cancellation for unknown subscription ${event.provider}/${event.subscription.providerSubscriptionId}: offer could not be resolved`, {
|
|
488
|
+
retryable: true,
|
|
489
|
+
details: {
|
|
490
|
+
provider: event.provider,
|
|
491
|
+
providerSubscriptionId: event.subscription.providerSubscriptionId,
|
|
492
|
+
},
|
|
493
|
+
});
|
|
480
494
|
}
|
|
481
495
|
await this.store.upsertBillingSubscription(this.buildSubscriptionState(event, uid, existing, {
|
|
482
496
|
status: "canceled",
|
|
@@ -548,7 +562,7 @@ export class BillingEventHandlers {
|
|
|
548
562
|
await this.resolveUserId(event);
|
|
549
563
|
return { handled: true, action: "trial_will_end_notified" };
|
|
550
564
|
}
|
|
551
|
-
async provisionSubscription(uid, offer, event, planKeyOverride, preserveAllowanceAnchor = false) {
|
|
565
|
+
async provisionSubscription(uid, offer, event, planKeyOverride, preserveAllowanceAnchor = false, preservedAllowanceAnchor) {
|
|
552
566
|
if (!this.provisioning) {
|
|
553
567
|
this.logger.debug(`[BillingService] provisionSubscription: no provisioning capability for user ${uid}`);
|
|
554
568
|
return;
|
|
@@ -559,15 +573,34 @@ export class BillingEventHandlers {
|
|
|
559
573
|
return;
|
|
560
574
|
}
|
|
561
575
|
this.logger.debug("[BillingService] provisionSubscription setting plan", { uid, plan });
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
576
|
+
let periodStart;
|
|
577
|
+
if (preserveAllowanceAnchor) {
|
|
578
|
+
const existingAnchor = preservedAllowanceAnchor !== undefined
|
|
579
|
+
? preservedAllowanceAnchor
|
|
580
|
+
: this.provisioning.getUserPlan
|
|
581
|
+
? (await this.provisioning.getUserPlan(uid))?.planAssignedAt
|
|
582
|
+
: undefined;
|
|
583
|
+
if (existingAnchor) {
|
|
584
|
+
const anchor = new Date(existingAnchor);
|
|
585
|
+
// A provider's subscription period start may actually be its next
|
|
586
|
+
// renewal date. Never let a future anchor hide an already-active
|
|
587
|
+
// entitlement after a plan change.
|
|
588
|
+
if (!Number.isNaN(anchor.getTime()) && anchor.getTime() <= Date.now()) {
|
|
589
|
+
periodStart = anchor;
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
else {
|
|
594
|
+
periodStart = event.subscription?.periodStart;
|
|
595
|
+
}
|
|
565
596
|
const planAssignedAt = periodStart
|
|
566
597
|
? (() => {
|
|
567
598
|
const d = new Date(periodStart);
|
|
568
599
|
return Number.isNaN(d.getTime()) ? undefined : d;
|
|
569
600
|
})()
|
|
570
|
-
:
|
|
601
|
+
: preserveAllowanceAnchor
|
|
602
|
+
? new Date()
|
|
603
|
+
: undefined;
|
|
571
604
|
await this.provisioning.setUserPlan(uid, plan, planAssignedAt);
|
|
572
605
|
if (this.autoSelectEntitlementSource && event.provider) {
|
|
573
606
|
const selected = await this.store.selectSubscriptionEntitlementSource(uid, event.provider, event.subscription?.providerSubscriptionId);
|
|
@@ -578,11 +611,17 @@ export class BillingEventHandlers {
|
|
|
578
611
|
}
|
|
579
612
|
async grantSubscriptionCycle(event, offer) {
|
|
580
613
|
const credits = offer?.grant?.mode === "cycle_grant" ? offer.grant.credits : null;
|
|
581
|
-
if (!credits || credits
|
|
614
|
+
if (!credits || credits.lte(0) || !event.billingEventId || !event.subscription)
|
|
582
615
|
return;
|
|
583
616
|
const subscription = await this.store.getBillingSubscription(event.provider, event.subscription.providerSubscriptionId);
|
|
584
617
|
if (!subscription?.subscriptionId) {
|
|
585
|
-
throw new
|
|
618
|
+
throw new StoreError("subscription cycle grant requires a persisted subscription", {
|
|
619
|
+
indeterminate: true,
|
|
620
|
+
details: {
|
|
621
|
+
provider: event.provider,
|
|
622
|
+
providerSubscriptionId: event.subscription.providerSubscriptionId,
|
|
623
|
+
},
|
|
624
|
+
});
|
|
586
625
|
}
|
|
587
626
|
const payment = event.payment?.providerPaymentId != null
|
|
588
627
|
? await this.store.getBillingPayment(event.provider, event.payment.providerPaymentId)
|