@zonastery/bursar 0.0.2 → 1.0.1
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 +118 -333
- package/dist/billing/auto-recharge-port.d.ts +27 -0
- package/dist/billing/auto-recharge-port.d.ts.map +1 -0
- package/dist/billing/auto-recharge-port.js +2 -0
- package/dist/billing/auto-recharge-port.js.map +1 -0
- package/dist/billing/auto-recharge-service.d.ts +43 -0
- package/dist/billing/auto-recharge-service.d.ts.map +1 -0
- package/dist/billing/auto-recharge-service.js +218 -0
- package/dist/billing/auto-recharge-service.js.map +1 -0
- package/dist/billing/billing-service.d.ts +71 -0
- package/dist/billing/billing-service.d.ts.map +1 -0
- package/dist/billing/billing-service.js +172 -0
- package/dist/billing/billing-service.js.map +1 -0
- package/dist/billing/billing-store.d.ts +45 -13
- 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 +149 -0
- package/dist/billing/contracts.d.ts.map +1 -0
- package/dist/billing/contracts.js +2 -0
- package/dist/billing/contracts.js.map +1 -0
- package/dist/billing/event-handlers.d.ts +57 -0
- package/dist/billing/event-handlers.d.ts.map +1 -0
- package/dist/billing/event-handlers.js +684 -0
- package/dist/billing/event-handlers.js.map +1 -0
- package/dist/billing/event-processor.d.ts +20 -0
- package/dist/billing/event-processor.d.ts.map +1 -0
- package/dist/billing/event-processor.js +131 -0
- package/dist/billing/event-processor.js.map +1 -0
- package/dist/billing/financial-event-handlers.d.ts +26 -0
- package/dist/billing/financial-event-handlers.d.ts.map +1 -0
- package/dist/billing/financial-event-handlers.js +241 -0
- package/dist/billing/financial-event-handlers.js.map +1 -0
- package/dist/billing/index.d.ts +9 -5
- package/dist/billing/index.d.ts.map +1 -1
- package/dist/billing/index.js +4 -4
- package/dist/billing/index.js.map +1 -1
- package/dist/billing/management.d.ts +59 -0
- package/dist/billing/management.d.ts.map +1 -0
- package/dist/billing/management.js +113 -0
- package/dist/billing/management.js.map +1 -0
- package/dist/billing/policy-window.d.ts +24 -0
- package/dist/billing/policy-window.d.ts.map +1 -0
- package/dist/billing/policy-window.js +88 -0
- package/dist/billing/policy-window.js.map +1 -0
- package/dist/billing/postgres/repositories/auto-recharge.d.ts +32 -0
- package/dist/billing/postgres/repositories/auto-recharge.d.ts.map +1 -0
- package/dist/billing/postgres/repositories/auto-recharge.js +180 -0
- package/dist/billing/postgres/repositories/auto-recharge.js.map +1 -0
- package/dist/billing/postgres/repositories/customer.d.ts +12 -0
- package/dist/billing/postgres/repositories/customer.d.ts.map +1 -0
- package/dist/billing/postgres/repositories/customer.js +33 -0
- package/dist/billing/postgres/repositories/customer.js.map +1 -0
- package/dist/billing/postgres/repositories/dispute.d.ts +7 -0
- package/dist/billing/postgres/repositories/dispute.d.ts.map +1 -0
- package/dist/billing/postgres/repositories/dispute.js +18 -0
- package/dist/billing/postgres/repositories/dispute.js.map +1 -0
- package/dist/billing/postgres/repositories/event.d.ts +21 -0
- package/dist/billing/postgres/repositories/event.d.ts.map +1 -0
- package/dist/billing/postgres/repositories/event.js +45 -0
- package/dist/billing/postgres/repositories/event.js.map +1 -0
- package/dist/billing/postgres/repositories/invoice.d.ts +9 -0
- package/dist/billing/postgres/repositories/invoice.d.ts.map +1 -0
- package/dist/billing/postgres/repositories/invoice.js +36 -0
- package/dist/billing/postgres/repositories/invoice.js.map +1 -0
- package/dist/billing/postgres/repositories/offer.d.ts +26 -0
- package/dist/billing/postgres/repositories/offer.d.ts.map +1 -0
- package/dist/billing/postgres/repositories/offer.js +73 -0
- package/dist/billing/postgres/repositories/offer.js.map +1 -0
- package/dist/billing/postgres/repositories/payment.d.ts +32 -0
- package/dist/billing/postgres/repositories/payment.d.ts.map +1 -0
- package/dist/billing/postgres/repositories/payment.js +78 -0
- package/dist/billing/postgres/repositories/payment.js.map +1 -0
- package/dist/billing/postgres/repositories/preferences.d.ts +15 -0
- package/dist/billing/postgres/repositories/preferences.d.ts.map +1 -0
- package/dist/billing/postgres/repositories/preferences.js +23 -0
- package/dist/billing/postgres/repositories/preferences.js.map +1 -0
- package/dist/billing/postgres/repositories/refund.d.ts +7 -0
- package/dist/billing/postgres/repositories/refund.d.ts.map +1 -0
- package/dist/billing/postgres/repositories/refund.js +32 -0
- package/dist/billing/postgres/repositories/refund.js.map +1 -0
- package/dist/billing/postgres/repositories/subscription.d.ts +46 -0
- package/dist/billing/postgres/repositories/subscription.d.ts.map +1 -0
- package/dist/billing/postgres/repositories/subscription.js +187 -0
- package/dist/billing/postgres/repositories/subscription.js.map +1 -0
- package/dist/billing/postgres/repositories/topup.d.ts +27 -0
- package/dist/billing/postgres/repositories/topup.d.ts.map +1 -0
- package/dist/billing/postgres/repositories/topup.js +51 -0
- package/dist/billing/postgres/repositories/topup.js.map +1 -0
- package/dist/billing/postgres/store.d.ts +89 -0
- package/dist/billing/postgres/store.d.ts.map +1 -0
- package/dist/billing/postgres/store.js +542 -0
- package/dist/billing/postgres/store.js.map +1 -0
- package/dist/billing/service-types.d.ts +37 -0
- package/dist/billing/service-types.d.ts.map +1 -0
- package/dist/billing/service-types.js +2 -0
- package/dist/billing/service-types.js.map +1 -0
- package/dist/billing/types/auto-recharge.d.ts +56 -0
- package/dist/billing/types/auto-recharge.d.ts.map +1 -0
- package/dist/billing/types/auto-recharge.js +2 -0
- package/dist/billing/types/auto-recharge.js.map +1 -0
- package/dist/billing/types/catalog.d.ts +47 -0
- package/dist/billing/types/catalog.d.ts.map +1 -0
- package/dist/billing/types/catalog.js +2 -0
- package/dist/billing/types/catalog.js.map +1 -0
- package/dist/billing/types/common.d.ts +16 -0
- package/dist/billing/types/common.d.ts.map +1 -0
- package/dist/billing/types/common.js +2 -0
- package/dist/billing/types/common.js.map +1 -0
- package/dist/billing/types/documents.d.ts +39 -0
- package/dist/billing/types/documents.d.ts.map +1 -0
- package/dist/billing/types/documents.js +2 -0
- package/dist/billing/types/documents.js.map +1 -0
- package/dist/billing/types/events.d.ts +75 -0
- package/dist/billing/types/events.d.ts.map +1 -0
- package/dist/billing/types/events.js +38 -0
- package/dist/billing/types/events.js.map +1 -0
- package/dist/billing/types/index.d.ts +8 -0
- package/dist/billing/types/index.d.ts.map +1 -0
- package/dist/billing/types/index.js +8 -0
- package/dist/billing/types/index.js.map +1 -0
- package/dist/billing/types/preferences.d.ts +13 -0
- package/dist/billing/types/preferences.d.ts.map +1 -0
- package/dist/billing/types/preferences.js +2 -0
- package/dist/billing/types/preferences.js.map +1 -0
- package/dist/billing/types/subscriptions.d.ts +97 -0
- package/dist/billing/types/subscriptions.d.ts.map +1 -0
- package/dist/billing/types/subscriptions.js +12 -0
- package/dist/billing/types/subscriptions.js.map +1 -0
- package/dist/breakdown.d.ts +3 -1
- package/dist/breakdown.d.ts.map +1 -1
- package/dist/breakdown.js +4 -1
- package/dist/breakdown.js.map +1 -1
- package/dist/browser.d.ts +8 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +7 -0
- package/dist/browser.js.map +1 -0
- package/dist/bursar.d.ts +84 -0
- package/dist/bursar.d.ts.map +1 -0
- package/dist/bursar.js +137 -0
- package/dist/bursar.js.map +1 -0
- package/dist/catalog.d.ts +62 -0
- package/dist/catalog.d.ts.map +1 -0
- package/dist/catalog.js +96 -0
- package/dist/catalog.js.map +1 -0
- package/dist/commerce/errors.d.ts +68 -0
- package/dist/commerce/errors.d.ts.map +1 -0
- package/dist/commerce/errors.js +105 -0
- package/dist/commerce/errors.js.map +1 -0
- package/dist/commerce/index.d.ts +6 -0
- package/dist/commerce/index.d.ts.map +1 -0
- package/dist/commerce/index.js +6 -0
- package/dist/commerce/index.js.map +1 -0
- package/dist/commerce/plan-change.d.ts +10 -0
- package/dist/commerce/plan-change.d.ts.map +1 -0
- package/dist/commerce/plan-change.js +42 -0
- package/dist/commerce/plan-change.js.map +1 -0
- package/dist/commerce/provider-registry.d.ts +18 -0
- package/dist/commerce/provider-registry.d.ts.map +1 -0
- package/dist/commerce/provider-registry.js +70 -0
- package/dist/commerce/provider-registry.js.map +1 -0
- package/dist/commerce/service.d.ts +73 -0
- package/dist/commerce/service.d.ts.map +1 -0
- package/dist/commerce/service.js +1016 -0
- package/dist/commerce/service.js.map +1 -0
- package/dist/commerce/types.d.ts +225 -0
- package/dist/commerce/types.d.ts.map +1 -0
- package/dist/commerce/types.js.map +1 -0
- package/dist/config/parse-access.d.ts +6 -0
- package/dist/config/parse-access.d.ts.map +1 -0
- package/dist/config/parse-access.js +72 -0
- package/dist/config/parse-access.js.map +1 -0
- package/dist/config/parse-commerce.d.ts +3 -0
- package/dist/config/parse-commerce.d.ts.map +1 -0
- package/dist/config/parse-commerce.js +236 -0
- package/dist/config/parse-commerce.js.map +1 -0
- package/dist/config/parse-credits.d.ts +3 -0
- package/dist/config/parse-credits.d.ts.map +1 -0
- package/dist/config/parse-credits.js +99 -0
- package/dist/config/parse-credits.js.map +1 -0
- package/dist/config/parse-plans.d.ts +5 -0
- package/dist/config/parse-plans.d.ts.map +1 -0
- package/dist/config/parse-plans.js +142 -0
- package/dist/config/parse-plans.js.map +1 -0
- package/dist/config/parse-pricing.d.ts +4 -0
- package/dist/config/parse-pricing.d.ts.map +1 -0
- package/dist/config/parse-pricing.js +252 -0
- package/dist/config/parse-pricing.js.map +1 -0
- package/dist/config/parse-utils.d.ts +18 -0
- package/dist/config/parse-utils.d.ts.map +1 -0
- package/dist/config/parse-utils.js +118 -0
- package/dist/config/parse-utils.js.map +1 -0
- package/dist/config/types.d.ts +340 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/config/types.js +2 -0
- package/dist/config/types.js.map +1 -0
- package/dist/config.d.ts +12 -23
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +141 -377
- package/dist/config.js.map +1 -1
- package/dist/{stores → credits}/events.d.ts +6 -6
- package/dist/credits/events.d.ts.map +1 -0
- package/dist/{stores → credits}/events.js +5 -5
- package/dist/credits/events.js.map +1 -0
- package/dist/credits/lease-workflow.d.ts +90 -0
- package/dist/credits/lease-workflow.d.ts.map +1 -0
- package/dist/credits/lease-workflow.js +378 -0
- package/dist/credits/lease-workflow.js.map +1 -0
- package/dist/credits/low-balance-monitor.d.ts +26 -0
- package/dist/credits/low-balance-monitor.d.ts.map +1 -0
- package/dist/credits/low-balance-monitor.js +110 -0
- package/dist/credits/low-balance-monitor.js.map +1 -0
- package/dist/credits/postgres/repositories/analytics.d.ts +81 -0
- package/dist/credits/postgres/repositories/analytics.d.ts.map +1 -0
- package/dist/credits/postgres/repositories/analytics.js +153 -0
- package/dist/credits/postgres/repositories/analytics.js.map +1 -0
- package/dist/credits/postgres/repositories/balance.d.ts +66 -0
- package/dist/credits/postgres/repositories/balance.d.ts.map +1 -0
- package/dist/credits/postgres/repositories/balance.js +139 -0
- package/dist/credits/postgres/repositories/balance.js.map +1 -0
- package/dist/credits/postgres/repositories/bucket.d.ts +25 -0
- package/dist/credits/postgres/repositories/bucket.d.ts.map +1 -0
- package/dist/credits/postgres/repositories/bucket.js +52 -0
- package/dist/credits/postgres/repositories/bucket.js.map +1 -0
- package/dist/credits/postgres/repositories/deduction.d.ts +64 -0
- package/dist/credits/postgres/repositories/deduction.d.ts.map +1 -0
- package/dist/credits/postgres/repositories/deduction.js +154 -0
- package/dist/credits/postgres/repositories/deduction.js.map +1 -0
- package/dist/credits/postgres/repositories/lease.d.ts +69 -0
- package/dist/credits/postgres/repositories/lease.d.ts.map +1 -0
- package/dist/credits/postgres/repositories/lease.js +148 -0
- package/dist/credits/postgres/repositories/lease.js.map +1 -0
- package/dist/credits/postgres/repositories/plan.d.ts +110 -0
- package/dist/credits/postgres/repositories/plan.d.ts.map +1 -0
- package/dist/credits/postgres/repositories/plan.js +194 -0
- package/dist/credits/postgres/repositories/plan.js.map +1 -0
- package/dist/credits/postgres/repositories/pricing.d.ts +28 -0
- package/dist/credits/postgres/repositories/pricing.d.ts.map +1 -0
- package/dist/credits/postgres/repositories/pricing.js +76 -0
- package/dist/credits/postgres/repositories/pricing.js.map +1 -0
- package/dist/credits/postgres/repositories/team.d.ts +63 -0
- package/dist/credits/postgres/repositories/team.d.ts.map +1 -0
- package/dist/credits/postgres/repositories/team.js +120 -0
- package/dist/credits/postgres/repositories/team.js.map +1 -0
- package/dist/credits/postgres/store.d.ts +89 -0
- package/dist/credits/postgres/store.d.ts.map +1 -0
- package/dist/credits/postgres/store.js +838 -0
- package/dist/credits/postgres/store.js.map +1 -0
- package/dist/credits/postgres/value-mappers.d.ts +17 -0
- package/dist/credits/postgres/value-mappers.d.ts.map +1 -0
- package/dist/credits/postgres/value-mappers.js +102 -0
- package/dist/credits/postgres/value-mappers.js.map +1 -0
- package/dist/credits/pricing-runtime.d.ts +35 -0
- package/dist/credits/pricing-runtime.d.ts.map +1 -0
- package/dist/credits/pricing-runtime.js +141 -0
- package/dist/credits/pricing-runtime.js.map +1 -0
- package/dist/credits/queries.d.ts +33 -0
- package/dist/credits/queries.d.ts.map +1 -0
- package/dist/credits/queries.js +71 -0
- package/dist/credits/queries.js.map +1 -0
- package/dist/credits/service-errors.d.ts +4 -0
- package/dist/credits/service-errors.d.ts.map +1 -0
- package/dist/credits/service-errors.js +57 -0
- package/dist/credits/service-errors.js.map +1 -0
- package/dist/credits/service-types.d.ts +122 -0
- package/dist/credits/service-types.d.ts.map +1 -0
- package/dist/credits/service-types.js +2 -0
- package/dist/credits/service-types.js.map +1 -0
- package/dist/credits/service.d.ts +220 -0
- package/dist/credits/service.d.ts.map +1 -0
- package/dist/credits/service.js +640 -0
- package/dist/credits/service.js.map +1 -0
- package/dist/credits/store.d.ts +172 -0
- package/dist/credits/store.d.ts.map +1 -0
- package/dist/{stores/credit-store.js → credits/store.js} +27 -43
- package/dist/credits/store.js.map +1 -0
- package/dist/credits/types/account.d.ts +82 -0
- package/dist/credits/types/account.d.ts.map +1 -0
- package/dist/credits/types/account.js +2 -0
- package/dist/credits/types/account.js.map +1 -0
- package/dist/credits/types/admission.d.ts +39 -0
- package/dist/credits/types/admission.d.ts.map +1 -0
- package/dist/credits/types/admission.js +2 -0
- package/dist/credits/types/admission.js.map +1 -0
- package/dist/credits/types/analytics.d.ts +52 -0
- package/dist/credits/types/analytics.d.ts.map +1 -0
- package/dist/credits/types/analytics.js +2 -0
- package/dist/credits/types/analytics.js.map +1 -0
- package/dist/credits/types/catalog.d.ts +71 -0
- package/dist/credits/types/catalog.d.ts.map +1 -0
- package/dist/credits/types/catalog.js +2 -0
- package/dist/credits/types/catalog.js.map +1 -0
- package/dist/credits/types/grants.d.ts +24 -0
- package/dist/credits/types/grants.d.ts.map +1 -0
- package/dist/credits/types/grants.js +2 -0
- package/dist/credits/types/grants.js.map +1 -0
- package/dist/credits/types/index.d.ts +9 -0
- package/dist/credits/types/index.d.ts.map +1 -0
- package/dist/credits/types/index.js +2 -0
- package/dist/credits/types/index.js.map +1 -0
- package/dist/credits/types/ledger.d.ts +87 -0
- package/dist/credits/types/ledger.d.ts.map +1 -0
- package/dist/credits/types/ledger.js +2 -0
- package/dist/credits/types/ledger.js.map +1 -0
- package/dist/credits/types/quotas.d.ts +40 -0
- package/dist/credits/types/quotas.d.ts.map +1 -0
- package/dist/credits/types/quotas.js +2 -0
- package/dist/credits/types/quotas.js.map +1 -0
- package/dist/credits/types/teams.d.ts +44 -0
- package/dist/credits/types/teams.d.ts.map +1 -0
- package/dist/credits/types/teams.js +2 -0
- package/dist/credits/types/teams.js.map +1 -0
- package/dist/engine.d.ts +18 -39
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +169 -145
- package/dist/engine.js.map +1 -1
- package/dist/errors.d.ts +133 -25
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +173 -24
- package/dist/errors.js.map +1 -1
- package/dist/expr/ast.d.ts +46 -0
- package/dist/expr/ast.d.ts.map +1 -0
- package/dist/expr/ast.js +18 -0
- package/dist/expr/ast.js.map +1 -0
- package/dist/expr/evaluator.d.ts +4 -0
- package/dist/expr/evaluator.d.ts.map +1 -0
- package/dist/expr/evaluator.js +144 -0
- package/dist/expr/evaluator.js.map +1 -0
- package/dist/expr/language.d.ts +5 -0
- package/dist/expr/language.d.ts.map +1 -0
- package/dist/expr/language.js +73 -0
- package/dist/expr/language.js.map +1 -0
- package/dist/expr/parser.d.ts +24 -0
- package/dist/expr/parser.d.ts.map +1 -0
- package/dist/expr/parser.js +175 -0
- package/dist/expr/parser.js.map +1 -0
- package/dist/expr/tokenizer.d.ts +7 -0
- package/dist/expr/tokenizer.d.ts.map +1 -0
- package/dist/expr/tokenizer.js +85 -0
- package/dist/expr/tokenizer.js.map +1 -0
- package/dist/expr.d.ts +7 -58
- package/dist/expr.d.ts.map +1 -1
- package/dist/expr.js +41 -640
- package/dist/expr.js.map +1 -1
- package/dist/generated/pricing-config.schema.json +2792 -0
- package/dist/generated/pricing-config.types.d.ts +685 -0
- package/dist/generated/pricing-config.types.d.ts.map +1 -0
- package/dist/generated/pricing-config.types.js +8 -0
- package/dist/generated/pricing-config.types.js.map +1 -0
- package/dist/index.d.ts +23 -17
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -10
- package/dist/index.js.map +1 -1
- package/dist/load-pricing-file.d.ts.map +1 -1
- package/dist/load-pricing-file.js +8 -4
- package/dist/load-pricing-file.js.map +1 -1
- package/dist/metrics.d.ts +6 -16
- package/dist/metrics.d.ts.map +1 -1
- package/dist/metrics.js.map +1 -1
- package/dist/node.d.ts +9 -2
- package/dist/node.d.ts.map +1 -1
- package/dist/node.js +6 -2
- package/dist/node.js.map +1 -1
- package/dist/providers/_shared.d.ts +9 -0
- package/dist/providers/_shared.d.ts.map +1 -0
- package/dist/providers/_shared.js +52 -0
- package/dist/providers/_shared.js.map +1 -0
- package/dist/providers/dodo/client-contract.d.ts +106 -0
- package/dist/providers/dodo/client-contract.d.ts.map +1 -0
- package/dist/providers/dodo/client-contract.js +2 -0
- package/dist/providers/dodo/client-contract.js.map +1 -0
- package/dist/providers/dodo/event-mapper.d.ts +5 -3
- package/dist/providers/dodo/event-mapper.d.ts.map +1 -1
- package/dist/providers/dodo/event-mapper.js +213 -38
- package/dist/providers/dodo/event-mapper.js.map +1 -1
- package/dist/providers/dodo/index.d.ts +1 -0
- package/dist/providers/dodo/index.d.ts.map +1 -1
- package/dist/providers/dodo/index.js.map +1 -1
- package/dist/providers/dodo/provider.d.ts +24 -14
- package/dist/providers/dodo/provider.d.ts.map +1 -1
- package/dist/providers/dodo/provider.js +249 -31
- package/dist/providers/dodo/provider.js.map +1 -1
- package/dist/providers/index.d.ts +3 -1
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js +1 -0
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/mock/index.js.map +1 -1
- package/dist/providers/mock/provider.d.ts +14 -10
- package/dist/providers/mock/provider.d.ts.map +1 -1
- package/dist/providers/mock/provider.js +78 -10
- package/dist/providers/mock/provider.js.map +1 -1
- package/dist/providers/stripe/event-mapper.d.ts +3 -3
- package/dist/providers/stripe/event-mapper.d.ts.map +1 -1
- package/dist/providers/stripe/event-mapper.js +139 -30
- package/dist/providers/stripe/event-mapper.js.map +1 -1
- package/dist/providers/stripe/index.js.map +1 -1
- package/dist/providers/stripe/provider.d.ts +21 -12
- package/dist/providers/stripe/provider.d.ts.map +1 -1
- package/dist/providers/stripe/provider.js +175 -17
- package/dist/providers/stripe/provider.js.map +1 -1
- package/dist/providers/types.d.ts +128 -32
- package/dist/providers/types.d.ts.map +1 -1
- package/dist/providers/types.js +17 -1
- package/dist/providers/types.js.map +1 -1
- package/dist/retry.d.ts +35 -0
- package/dist/retry.d.ts.map +1 -0
- package/dist/retry.js +70 -0
- package/dist/retry.js.map +1 -0
- 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.d.ts +10 -0
- package/dist/shared/logger.d.ts.map +1 -0
- package/dist/shared/logger.js +15 -0
- package/dist/shared/logger.js.map +1 -0
- package/dist/shared/postgres-client.d.ts +84 -0
- package/dist/shared/postgres-client.d.ts.map +1 -0
- package/dist/shared/postgres-client.js +337 -0
- package/dist/shared/postgres-client.js.map +1 -0
- 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.d.ts +7 -0
- package/dist/shared/postgres-types.d.ts.map +1 -0
- package/dist/shared/postgres-types.js +2 -0
- package/dist/shared/postgres-types.js.map +1 -0
- package/dist/shared/postgres-validation.d.ts +8 -0
- package/dist/shared/postgres-validation.d.ts.map +1 -0
- package/dist/shared/postgres-validation.js +40 -0
- package/dist/shared/postgres-validation.js.map +1 -0
- package/dist/storage/adapters/clickhouse.d.ts +61 -0
- package/dist/storage/adapters/clickhouse.d.ts.map +1 -0
- package/dist/storage/adapters/clickhouse.js +347 -0
- package/dist/storage/adapters/clickhouse.js.map +1 -0
- package/dist/storage/adapters/s3.d.ts +35 -0
- package/dist/storage/adapters/s3.d.ts.map +1 -0
- package/dist/storage/adapters/s3.js +100 -0
- package/dist/storage/adapters/s3.js.map +1 -0
- package/dist/storage/outbox-worker.d.ts +41 -0
- package/dist/storage/outbox-worker.d.ts.map +1 -0
- package/dist/storage/outbox-worker.js +146 -0
- package/dist/storage/outbox-worker.js.map +1 -0
- package/dist/storage/ports.d.ts +78 -0
- package/dist/storage/ports.d.ts.map +1 -0
- package/dist/storage/ports.js +2 -0
- package/dist/storage/ports.js.map +1 -0
- package/dist/storage/postgres-repository.d.ts +14 -0
- package/dist/storage/postgres-repository.d.ts.map +1 -0
- package/dist/storage/postgres-repository.js +140 -0
- package/dist/storage/postgres-repository.js.map +1 -0
- package/dist/storage/runtime.d.ts +77 -0
- package/dist/storage/runtime.d.ts.map +1 -0
- package/dist/storage/runtime.js +369 -0
- package/dist/storage/runtime.js.map +1 -0
- package/package.json +43 -21
- package/dist/allowance.d.ts +0 -48
- package/dist/allowance.d.ts.map +0 -1
- package/dist/allowance.js +0 -140
- package/dist/allowance.js.map +0 -1
- package/dist/billing/billing-manager.d.ts +0 -66
- package/dist/billing/billing-manager.d.ts.map +0 -1
- package/dist/billing/billing-manager.js +0 -560
- package/dist/billing/billing-manager.js.map +0 -1
- package/dist/billing/billing-types.d.ts +0 -203
- package/dist/billing/billing-types.d.ts.map +0 -1
- package/dist/billing/billing-types.js +0 -6
- package/dist/billing/billing-types.js.map +0 -1
- package/dist/billing/memory-billing-store.d.ts +0 -37
- package/dist/billing/memory-billing-store.d.ts.map +0 -1
- package/dist/billing/memory-billing-store.js +0 -197
- package/dist/billing/memory-billing-store.js.map +0 -1
- package/dist/billing/postgres-billing-store.d.ts +0 -35
- package/dist/billing/postgres-billing-store.d.ts.map +0 -1
- package/dist/billing/postgres-billing-store.js +0 -274
- package/dist/billing/postgres-billing-store.js.map +0 -1
- package/dist/billing/supabase-billing-store.d.ts +0 -29
- package/dist/billing/supabase-billing-store.d.ts.map +0 -1
- package/dist/billing/supabase-billing-store.js +0 -250
- package/dist/billing/supabase-billing-store.js.map +0 -1
- package/dist/manager.d.ts +0 -444
- package/dist/manager.d.ts.map +0 -1
- package/dist/manager.js +0 -1153
- package/dist/manager.js.map +0 -1
- package/dist/stores/credit-store.d.ts +0 -198
- package/dist/stores/credit-store.d.ts.map +0 -1
- package/dist/stores/credit-store.js.map +0 -1
- package/dist/stores/events.d.ts.map +0 -1
- package/dist/stores/events.js.map +0 -1
- package/dist/stores/memory-store.d.ts +0 -187
- package/dist/stores/memory-store.d.ts.map +0 -1
- package/dist/stores/memory-store.js +0 -1890
- package/dist/stores/memory-store.js.map +0 -1
- package/dist/stores/postgres-store.d.ts +0 -100
- package/dist/stores/postgres-store.d.ts.map +0 -1
- package/dist/stores/postgres-store.js +0 -891
- package/dist/stores/postgres-store.js.map +0 -1
- package/dist/stores/supabase-store.d.ts +0 -87
- package/dist/stores/supabase-store.d.ts.map +0 -1
- package/dist/stores/supabase-store.js +0 -948
- package/dist/stores/supabase-store.js.map +0 -1
- package/dist/types.d.ts +0 -463
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
- /package/dist/{types.js → commerce/types.js} +0 -0
|
@@ -0,0 +1,684 @@
|
|
|
1
|
+
import { LRUCache } from "lru-cache";
|
|
2
|
+
import { normalizeLogger } from "../shared/logger.js";
|
|
3
|
+
import { BillingEventType } from "./types/index.js";
|
|
4
|
+
import { BillingFinancialEventHandlers } from "./financial-event-handlers.js";
|
|
5
|
+
export class BillingEventHandlers {
|
|
6
|
+
store;
|
|
7
|
+
provisioning;
|
|
8
|
+
resolveUser;
|
|
9
|
+
autoSelectEntitlementSource;
|
|
10
|
+
pastDueGracePeriodMs;
|
|
11
|
+
terminalPlanKey;
|
|
12
|
+
logger;
|
|
13
|
+
offerCache;
|
|
14
|
+
financial;
|
|
15
|
+
handlerMap;
|
|
16
|
+
get hasProvisioning() {
|
|
17
|
+
return this.provisioning !== null;
|
|
18
|
+
}
|
|
19
|
+
constructor(store, options) {
|
|
20
|
+
this.store = store;
|
|
21
|
+
this.provisioning = options?.provisioning ?? null;
|
|
22
|
+
this.resolveUser = options?.resolveUser ?? null;
|
|
23
|
+
this.autoSelectEntitlementSource = options?.autoSelectEntitlementSource ?? true;
|
|
24
|
+
this.pastDueGracePeriodMs = options?.pastDueGracePeriodMs ?? 7 * 24 * 60 * 60 * 1000;
|
|
25
|
+
if (!Number.isFinite(this.pastDueGracePeriodMs) || this.pastDueGracePeriodMs < 0) {
|
|
26
|
+
throw new RangeError("pastDueGracePeriodMs must be a finite non-negative number");
|
|
27
|
+
}
|
|
28
|
+
this.terminalPlanKey = options?.terminalPlanKey ?? null;
|
|
29
|
+
this.logger = normalizeLogger(options?.logger);
|
|
30
|
+
this.offerCache = new LRUCache({
|
|
31
|
+
max: 100,
|
|
32
|
+
ttl: 60_000,
|
|
33
|
+
allowStale: false,
|
|
34
|
+
fetchMethod: async (_, __, { context }) => {
|
|
35
|
+
const offer = await this.store.resolveBillingOffer(context.provider, context.productId, context.priceId);
|
|
36
|
+
return { offer };
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
this.financial = new BillingFinancialEventHandlers(store, this.logger, this.pastDueGracePeriodMs, (event) => this.resolveUserId(event), (event) => this.handleSubscriptionRenewed(event), (event, status) => this.updateCheckoutIntentFromEvent(event, status), (event) => this.getExistingSubscription(event), (event, userId, existing, overrides) => this.buildSubscriptionState(event, userId, existing, overrides));
|
|
40
|
+
this.handlerMap = {
|
|
41
|
+
[BillingEventType.CUSTOMER_CREATED]: this.handleCustomerCreated.bind(this),
|
|
42
|
+
[BillingEventType.CUSTOMER_UPDATED]: this.handleCustomerCreated.bind(this),
|
|
43
|
+
[BillingEventType.CUSTOMER_DELETED]: this.handleCustomerDeleted.bind(this),
|
|
44
|
+
[BillingEventType.CHECKOUT_COMPLETED]: this.handleCheckoutCompleted.bind(this),
|
|
45
|
+
[BillingEventType.SUBSCRIPTION_CREATED]: this.handleSubscriptionCreated.bind(this),
|
|
46
|
+
[BillingEventType.SUBSCRIPTION_UPDATED]: this.handleSubscriptionUpdated.bind(this),
|
|
47
|
+
[BillingEventType.SUBSCRIPTION_ACTIVATED]: this.handleSubscriptionActivated.bind(this),
|
|
48
|
+
[BillingEventType.SUBSCRIPTION_RENEWED]: this.handleSubscriptionRenewed.bind(this),
|
|
49
|
+
[BillingEventType.SUBSCRIPTION_PLAN_CHANGED]: this.handleSubscriptionPlanChanged.bind(this),
|
|
50
|
+
[BillingEventType.SUBSCRIPTION_CANCELLATION_SCHEDULED]: this.handleCancellationScheduled.bind(this),
|
|
51
|
+
[BillingEventType.SUBSCRIPTION_CANCELLATION_UNSCHEDULED]: this.handleCancellationUnscheduled.bind(this),
|
|
52
|
+
[BillingEventType.SUBSCRIPTION_CANCELED]: this.handleSubscriptionCanceled.bind(this),
|
|
53
|
+
[BillingEventType.SUBSCRIPTION_EXPIRED]: this.handleSubscriptionExpired.bind(this),
|
|
54
|
+
[BillingEventType.SUBSCRIPTION_PAUSED]: this.handleSubscriptionPaused.bind(this),
|
|
55
|
+
[BillingEventType.SUBSCRIPTION_RESUMED]: this.handleSubscriptionResumed.bind(this),
|
|
56
|
+
[BillingEventType.SUBSCRIPTION_TRIAL_WILL_END]: this.handleTrialWillEnd.bind(this),
|
|
57
|
+
[BillingEventType.INVOICE_PAID]: this.financial.handleInvoicePaid.bind(this.financial),
|
|
58
|
+
[BillingEventType.PAYMENT_SUCCEEDED]: this.financial.handlePaymentSucceeded.bind(this.financial),
|
|
59
|
+
[BillingEventType.PAYMENT_FAILED]: this.financial.handlePaymentFailed.bind(this.financial),
|
|
60
|
+
[BillingEventType.REFUND_CREATED]: this.financial.handleRefundCreated.bind(this.financial),
|
|
61
|
+
[BillingEventType.REFUND_UPDATED]: this.financial.handleRefundCreated.bind(this.financial),
|
|
62
|
+
[BillingEventType.REFUND_FAILED]: this.financial.handleRefundCreated.bind(this.financial),
|
|
63
|
+
[BillingEventType.DISPUTE_CREATED]: this.financial.handleDisputeCreated.bind(this.financial),
|
|
64
|
+
[BillingEventType.DISPUTE_CLOSED]: this.financial.handleDisputeClosed.bind(this.financial),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
getHandler(eventType) {
|
|
68
|
+
return this.handlerMap[eventType];
|
|
69
|
+
}
|
|
70
|
+
invalidateOfferCache() {
|
|
71
|
+
this.offerCache.clear();
|
|
72
|
+
}
|
|
73
|
+
async updateCheckoutIntentFromEvent(event, status) {
|
|
74
|
+
const intentId = event.metadata?.checkout_intent_id;
|
|
75
|
+
if (typeof intentId !== "string" || !intentId)
|
|
76
|
+
return;
|
|
77
|
+
await this.store.updateCheckoutIntent(intentId, { status });
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Resolve userId from the event, mutating event.userId so that
|
|
81
|
+
* routeEvent's blanket fireEventCallback can read it. Each ingestBillingEvent
|
|
82
|
+
* call creates a fresh event object, so mutation is safe.
|
|
83
|
+
*/
|
|
84
|
+
async resolveUserId(event) {
|
|
85
|
+
if (event.userId)
|
|
86
|
+
return event.userId;
|
|
87
|
+
if (event.customer?.providerCustomerId) {
|
|
88
|
+
const uid = await this.store.getBillingCustomer(event.provider, event.customer.providerCustomerId);
|
|
89
|
+
if (uid) {
|
|
90
|
+
event.userId = uid;
|
|
91
|
+
return uid;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (this.resolveUser && event.customer?.providerCustomerId) {
|
|
95
|
+
const uid = this.resolveUser(event.provider, event.customer.providerCustomerId, event.customer.email ?? null);
|
|
96
|
+
if (uid) {
|
|
97
|
+
event.userId = uid;
|
|
98
|
+
return uid;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (event.subscription?.providerSubscriptionId) {
|
|
102
|
+
const existing = await this.store.getBillingSubscription(event.provider, event.subscription.providerSubscriptionId);
|
|
103
|
+
if (existing?.userId) {
|
|
104
|
+
event.userId = existing.userId;
|
|
105
|
+
return existing.userId;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const providerPaymentId = event.payment?.providerPaymentId ??
|
|
109
|
+
event.refund?.providerPaymentId ??
|
|
110
|
+
event.dispute?.providerPaymentId ??
|
|
111
|
+
null;
|
|
112
|
+
if (providerPaymentId) {
|
|
113
|
+
const payment = await this.store.getBillingPayment(event.provider, providerPaymentId);
|
|
114
|
+
if (typeof payment?.userId === "string") {
|
|
115
|
+
event.userId = payment.userId;
|
|
116
|
+
return payment.userId;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
async resolveBillingOfferCached(provider, productId, priceId) {
|
|
122
|
+
const cacheKey = `${provider}:${productId ?? ""}:${priceId ?? ""}`;
|
|
123
|
+
const result = await this.offerCache.fetch(cacheKey, {
|
|
124
|
+
context: { provider, productId, priceId },
|
|
125
|
+
});
|
|
126
|
+
return result?.offer ?? null;
|
|
127
|
+
}
|
|
128
|
+
async handleCustomerCreated(event) {
|
|
129
|
+
this.logger.info("[BillingService] handleCustomerCreated", {
|
|
130
|
+
provider: event.provider,
|
|
131
|
+
customerId: event.customer?.providerCustomerId,
|
|
132
|
+
});
|
|
133
|
+
if (event.customer?.providerCustomerId) {
|
|
134
|
+
const uid = await this.resolveUserId(event);
|
|
135
|
+
if (uid) {
|
|
136
|
+
await this.store.upsertBillingCustomer(event.provider, event.customer.providerCustomerId, uid, event.customer.email ?? null);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return { handled: true, action: "customer_created" };
|
|
140
|
+
}
|
|
141
|
+
async handleCustomerDeleted(event) {
|
|
142
|
+
this.logger.info("[BillingService] handleCustomerDeleted", {
|
|
143
|
+
provider: event.provider,
|
|
144
|
+
customerId: event.customer?.providerCustomerId,
|
|
145
|
+
});
|
|
146
|
+
if (event.customer?.providerCustomerId) {
|
|
147
|
+
const uid = await this.resolveUserId(event);
|
|
148
|
+
if (uid && this.provisioning) {
|
|
149
|
+
await this.revokeSubscription(uid);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return { handled: true, action: "customer_deleted" };
|
|
153
|
+
}
|
|
154
|
+
async handleCheckoutCompleted(event) {
|
|
155
|
+
this.logger.info("[BillingService] handleCheckoutCompleted", {
|
|
156
|
+
provider: event.provider,
|
|
157
|
+
eventId: event.eventId,
|
|
158
|
+
hasUserId: Boolean(event.userId),
|
|
159
|
+
});
|
|
160
|
+
if (event.customer?.providerCustomerId) {
|
|
161
|
+
const uid = await this.resolveUserId(event);
|
|
162
|
+
if (uid) {
|
|
163
|
+
await this.store.upsertBillingCustomer(event.provider, event.customer.providerCustomerId, uid, event.customer.email ?? null);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (event.subscription?.providerSubscriptionId) {
|
|
167
|
+
return this.handleSubscriptionCreated(event);
|
|
168
|
+
}
|
|
169
|
+
await this.updateCheckoutIntentFromEvent(event, "completed");
|
|
170
|
+
return { handled: true, action: "checkout_completed" };
|
|
171
|
+
}
|
|
172
|
+
async getExistingSubscription(event) {
|
|
173
|
+
if (!event.subscription?.providerSubscriptionId)
|
|
174
|
+
return null;
|
|
175
|
+
return this.store.getBillingSubscription(event.provider, event.subscription.providerSubscriptionId);
|
|
176
|
+
}
|
|
177
|
+
buildSubscriptionState(event, userId, existing, overrides) {
|
|
178
|
+
if (!event.subscription) {
|
|
179
|
+
throw new Error("no_subscription_data");
|
|
180
|
+
}
|
|
181
|
+
const sub = event.subscription;
|
|
182
|
+
const status = overrides?.status ?? sub.status ?? existing?.status ?? "incomplete";
|
|
183
|
+
return {
|
|
184
|
+
userId,
|
|
185
|
+
provider: event.provider,
|
|
186
|
+
providerSubscriptionId: sub.providerSubscriptionId,
|
|
187
|
+
providerCustomerId: event.customer?.providerCustomerId ?? existing?.providerCustomerId ?? null,
|
|
188
|
+
offerId: overrides?.offerId ?? existing?.offerId ?? null,
|
|
189
|
+
offerKey: overrides?.offerKey ?? existing?.offerKey ?? null,
|
|
190
|
+
plan: overrides?.plan ?? existing?.plan ?? null,
|
|
191
|
+
status,
|
|
192
|
+
currentPeriodStart: sub.periodStart ?? existing?.currentPeriodStart ?? null,
|
|
193
|
+
currentPeriodEnd: sub.periodEnd ?? existing?.currentPeriodEnd ?? null,
|
|
194
|
+
trialEnd: sub.trialEnd ?? existing?.trialEnd ?? null,
|
|
195
|
+
cancelAt: sub.cancelAt ?? existing?.cancelAt ?? null,
|
|
196
|
+
endedAt: sub.endedAt ?? existing?.endedAt ?? null,
|
|
197
|
+
graceEndsAt: status === "past_due" ? (overrides?.graceEndsAt ?? existing?.graceEndsAt ?? null) : null,
|
|
198
|
+
graceExpiredAt: status === "past_due"
|
|
199
|
+
? (overrides?.graceExpiredAt ?? existing?.graceExpiredAt ?? null)
|
|
200
|
+
: null,
|
|
201
|
+
providerUpdatedAt: event.occurredAt,
|
|
202
|
+
cancelAtPeriodEnd: overrides?.cancelAtPeriodEnd ??
|
|
203
|
+
sub.cancelAtPeriodEnd ??
|
|
204
|
+
existing?.cancelAtPeriodEnd ??
|
|
205
|
+
false,
|
|
206
|
+
interval: overrides?.interval ??
|
|
207
|
+
sub.interval ??
|
|
208
|
+
event.metadata?.billing_interval ??
|
|
209
|
+
existing?.interval ??
|
|
210
|
+
null,
|
|
211
|
+
intervalCount: overrides?.intervalCount ?? sub.intervalCount ?? existing?.intervalCount ?? null,
|
|
212
|
+
metadata: overrides?.metadata ??
|
|
213
|
+
(event.metadata || existing?.metadata
|
|
214
|
+
? { ...(existing?.metadata ?? {}), ...(event.metadata ?? {}) }
|
|
215
|
+
: null),
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
async resolveOfferAndKeys(event) {
|
|
219
|
+
const refs = event.subscription?.refs;
|
|
220
|
+
if (!refs)
|
|
221
|
+
return { offer: null, offerId: null, offerKey: null, plan: null };
|
|
222
|
+
// Tier 1: Resolve by price/product ID
|
|
223
|
+
const offer = await this.resolveBillingOfferCached(event.provider, refs.productId ?? null, refs.priceId ?? null);
|
|
224
|
+
if (offer) {
|
|
225
|
+
return {
|
|
226
|
+
offer,
|
|
227
|
+
offerId: offer.offerId,
|
|
228
|
+
offerKey: offer?.offerKey ?? null,
|
|
229
|
+
plan: offer?.plan ?? null,
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
// Tier 2: Resolve by lookup_key
|
|
233
|
+
if (refs.lookupKey) {
|
|
234
|
+
const lookupOffer = await this.store.resolveBillingOfferByLookup(event.provider, refs.lookupKey);
|
|
235
|
+
if (lookupOffer) {
|
|
236
|
+
return {
|
|
237
|
+
offer: lookupOffer,
|
|
238
|
+
offerId: lookupOffer.offerId,
|
|
239
|
+
offerKey: lookupOffer?.offerKey ?? null,
|
|
240
|
+
plan: lookupOffer?.plan ?? null,
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
this.logger.error(`[BillingService] resolveOfferAndKeys: no offer found for ${event.provider}/${refs.lookupKey}`);
|
|
244
|
+
}
|
|
245
|
+
return { offer: null, offerId: null, offerKey: null, plan: null };
|
|
246
|
+
}
|
|
247
|
+
async handleSubscriptionCreated(event) {
|
|
248
|
+
const uid = await this.resolveUserId(event);
|
|
249
|
+
this.logger.info("[BillingService] handleSubscriptionCreated", {
|
|
250
|
+
eventId: event.eventId,
|
|
251
|
+
provider: event.provider,
|
|
252
|
+
hasUserId: Boolean(uid),
|
|
253
|
+
});
|
|
254
|
+
if (!uid)
|
|
255
|
+
return { handled: false, error: "user_not_found" };
|
|
256
|
+
if (event.customer?.providerCustomerId) {
|
|
257
|
+
await this.store.upsertBillingCustomer(event.provider, event.customer.providerCustomerId, uid, event.customer.email ?? null);
|
|
258
|
+
}
|
|
259
|
+
if (!event.subscription?.providerSubscriptionId)
|
|
260
|
+
return { handled: false, error: "no_subscription_data" };
|
|
261
|
+
const subscriptionId = event.subscription.providerSubscriptionId;
|
|
262
|
+
const existing = await this.getExistingSubscription(event);
|
|
263
|
+
const blockingStatuses = new Set(["active", "trialing", "past_due", "incomplete"]);
|
|
264
|
+
const existingForProvider = (await this.store.getUserSubscriptions(uid)).find((candidate) => candidate.provider === event.provider &&
|
|
265
|
+
candidate.providerSubscriptionId !== subscriptionId &&
|
|
266
|
+
blockingStatuses.has(candidate.status ?? ""));
|
|
267
|
+
if (existingForProvider) {
|
|
268
|
+
await this.store.recordSubscriptionConflict({
|
|
269
|
+
userId: uid,
|
|
270
|
+
provider: event.provider,
|
|
271
|
+
duplicateSubscriptionId: subscriptionId,
|
|
272
|
+
existingSubscriptionId: existingForProvider.providerSubscriptionId,
|
|
273
|
+
eventId: event.eventId,
|
|
274
|
+
metadata: event.metadata ?? {},
|
|
275
|
+
});
|
|
276
|
+
return { handled: false, error: "subscription_conflict" };
|
|
277
|
+
}
|
|
278
|
+
const { offer, offerId, offerKey, plan } = await this.resolveOfferAndKeys(event);
|
|
279
|
+
this.logger.debug("[BillingService] resolveOfferAndKeys", {
|
|
280
|
+
offerKey,
|
|
281
|
+
plan,
|
|
282
|
+
eventId: event.eventId,
|
|
283
|
+
});
|
|
284
|
+
const subscriptionState = this.buildSubscriptionState(event, uid, existing, {
|
|
285
|
+
status: event.subscription.status ?? "incomplete",
|
|
286
|
+
cancelAtPeriodEnd: event.subscription.cancelAtPeriodEnd ?? false,
|
|
287
|
+
offerKey: offerKey ?? existing?.offerKey ?? null,
|
|
288
|
+
offerId: offerId ?? existing?.offerId ?? null,
|
|
289
|
+
plan: plan ?? existing?.plan ?? null,
|
|
290
|
+
interval: offer?.interval,
|
|
291
|
+
intervalCount: offer?.intervalCount,
|
|
292
|
+
});
|
|
293
|
+
try {
|
|
294
|
+
this.logger.debug("[BillingService] upserting subscription", {
|
|
295
|
+
plan: subscriptionState.plan,
|
|
296
|
+
eventId: event.eventId,
|
|
297
|
+
});
|
|
298
|
+
await this.store.upsertBillingSubscription(subscriptionState);
|
|
299
|
+
}
|
|
300
|
+
catch (error) {
|
|
301
|
+
// The partial unique index is the final arbiter under concurrent
|
|
302
|
+
// webhooks. Convert its race loser into the same manual-review path as
|
|
303
|
+
// the preflight check instead of retrying a permanently invalid event.
|
|
304
|
+
const code = error.code;
|
|
305
|
+
if (code !== "23505")
|
|
306
|
+
throw error;
|
|
307
|
+
const concurrent = (await this.store.getUserSubscriptions(uid)).find((candidate) => candidate.provider === event.provider &&
|
|
308
|
+
candidate.providerSubscriptionId !== subscriptionId &&
|
|
309
|
+
blockingStatuses.has(candidate.status ?? ""));
|
|
310
|
+
if (!concurrent)
|
|
311
|
+
throw error;
|
|
312
|
+
await this.store.recordSubscriptionConflict({
|
|
313
|
+
userId: uid,
|
|
314
|
+
provider: event.provider,
|
|
315
|
+
duplicateSubscriptionId: subscriptionId,
|
|
316
|
+
existingSubscriptionId: concurrent.providerSubscriptionId,
|
|
317
|
+
eventId: event.eventId,
|
|
318
|
+
metadata: event.metadata ?? {},
|
|
319
|
+
});
|
|
320
|
+
return { handled: false, error: "subscription_conflict" };
|
|
321
|
+
}
|
|
322
|
+
if (this.provisioning &&
|
|
323
|
+
event.subscription.status &&
|
|
324
|
+
["active", "trialing"].includes(event.subscription.status)) {
|
|
325
|
+
await this.provisionSubscription(uid, offer, event);
|
|
326
|
+
}
|
|
327
|
+
if (["active", "trialing"].includes(event.subscription.status ?? "")) {
|
|
328
|
+
await this.updateCheckoutIntentFromEvent(event, "completed");
|
|
329
|
+
}
|
|
330
|
+
return { handled: true, action: "subscription_created" };
|
|
331
|
+
}
|
|
332
|
+
async handleSubscriptionUpdated(event) {
|
|
333
|
+
this.logger.info("[BillingService] handleSubscriptionUpdated", {
|
|
334
|
+
provider: event.provider,
|
|
335
|
+
eventId: event.eventId,
|
|
336
|
+
subId: event.subscription?.providerSubscriptionId,
|
|
337
|
+
});
|
|
338
|
+
const uid = await this.resolveUserId(event);
|
|
339
|
+
if (!uid)
|
|
340
|
+
return { handled: false, error: "user_not_found" };
|
|
341
|
+
if (!event.subscription?.providerSubscriptionId)
|
|
342
|
+
return { handled: false, error: "no_subscription_data" };
|
|
343
|
+
const existing = await this.getExistingSubscription(event);
|
|
344
|
+
const { offer, offerId, offerKey, plan } = await this.resolveOfferAndKeys(event);
|
|
345
|
+
await this.store.upsertBillingSubscription(this.buildSubscriptionState(event, uid, existing, {
|
|
346
|
+
status: event.subscription.status ?? existing?.status ?? "incomplete",
|
|
347
|
+
cancelAtPeriodEnd: event.subscription.cancelAtPeriodEnd ?? existing?.cancelAtPeriodEnd ?? false,
|
|
348
|
+
offerKey: offerKey ?? existing?.offerKey ?? null,
|
|
349
|
+
offerId: offerId ?? existing?.offerId ?? null,
|
|
350
|
+
plan: plan ?? existing?.plan ?? null,
|
|
351
|
+
interval: offer?.interval,
|
|
352
|
+
intervalCount: offer?.intervalCount,
|
|
353
|
+
}));
|
|
354
|
+
if (this.provisioning) {
|
|
355
|
+
await this.reEvaluateAccess(uid, event);
|
|
356
|
+
}
|
|
357
|
+
return { handled: true, action: "subscription_updated" };
|
|
358
|
+
}
|
|
359
|
+
async handleSubscriptionActivated(event) {
|
|
360
|
+
this.logger.info("[BillingService] handleSubscriptionActivated", {
|
|
361
|
+
provider: event.provider,
|
|
362
|
+
eventId: event.eventId,
|
|
363
|
+
});
|
|
364
|
+
const uid = await this.resolveUserId(event);
|
|
365
|
+
if (!uid)
|
|
366
|
+
return { handled: false, error: "user_not_found" };
|
|
367
|
+
if (!event.subscription?.providerSubscriptionId)
|
|
368
|
+
return { handled: false, error: "no_subscription_data" };
|
|
369
|
+
const existing = await this.getExistingSubscription(event);
|
|
370
|
+
const { offer, offerId, offerKey, plan } = await this.resolveOfferAndKeys(event);
|
|
371
|
+
await this.store.upsertBillingSubscription(this.buildSubscriptionState(event, uid, existing, {
|
|
372
|
+
status: "active",
|
|
373
|
+
offerKey: offerKey ?? existing?.offerKey ?? null,
|
|
374
|
+
offerId: offerId ?? existing?.offerId ?? null,
|
|
375
|
+
plan: plan ?? existing?.plan ?? null,
|
|
376
|
+
interval: offer?.interval,
|
|
377
|
+
intervalCount: offer?.intervalCount,
|
|
378
|
+
}));
|
|
379
|
+
if (this.provisioning) {
|
|
380
|
+
await this.provisionSubscription(uid, offer, event);
|
|
381
|
+
}
|
|
382
|
+
return { handled: true, action: "subscription_activated" };
|
|
383
|
+
}
|
|
384
|
+
async handleSubscriptionRenewed(event) {
|
|
385
|
+
const uid = await this.resolveUserId(event);
|
|
386
|
+
if (!uid)
|
|
387
|
+
return { handled: false, error: "user_not_found" };
|
|
388
|
+
if (!event.subscription?.providerSubscriptionId)
|
|
389
|
+
return { handled: false, error: "no_subscription_data" };
|
|
390
|
+
const existing = await this.getExistingSubscription(event);
|
|
391
|
+
const { offer, offerId, offerKey, plan } = await this.resolveOfferAndKeys(event);
|
|
392
|
+
const resolvedPlanKey = plan ?? existing?.plan ?? null;
|
|
393
|
+
await this.store.upsertBillingSubscription(this.buildSubscriptionState(event, uid, existing, {
|
|
394
|
+
status: "active",
|
|
395
|
+
offerKey: offerKey ?? existing?.offerKey ?? null,
|
|
396
|
+
offerId: offerId ?? existing?.offerId ?? null,
|
|
397
|
+
plan: resolvedPlanKey,
|
|
398
|
+
interval: offer?.interval,
|
|
399
|
+
intervalCount: offer?.intervalCount,
|
|
400
|
+
}));
|
|
401
|
+
if (this.provisioning && resolvedPlanKey) {
|
|
402
|
+
await this.provisionSubscription(uid, offer, event);
|
|
403
|
+
}
|
|
404
|
+
await this.grantSubscriptionCycle(event, offer);
|
|
405
|
+
return { handled: true, action: "subscription_renewed" };
|
|
406
|
+
}
|
|
407
|
+
async handleSubscriptionPlanChanged(event) {
|
|
408
|
+
const uid = await this.resolveUserId(event);
|
|
409
|
+
if (!uid)
|
|
410
|
+
return { handled: false, error: "user_not_found" };
|
|
411
|
+
if (!event.subscription?.providerSubscriptionId)
|
|
412
|
+
return { handled: false, error: "no_subscription_data" };
|
|
413
|
+
const existing = await this.getExistingSubscription(event);
|
|
414
|
+
const { offer, offerId, offerKey, plan } = await this.resolveOfferAndKeys(event);
|
|
415
|
+
const pending = await this.store.getOpenBillingSubscriptionChange(event.provider, event.subscription.providerSubscriptionId);
|
|
416
|
+
if (pending) {
|
|
417
|
+
await this.store.updateBillingSubscriptionChange(pending.id, {
|
|
418
|
+
state: "applied",
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
await this.store.upsertBillingSubscription(this.buildSubscriptionState(event, uid, existing, {
|
|
422
|
+
status: event.subscription.status ?? "active",
|
|
423
|
+
offerKey: offerKey ?? existing?.offerKey ?? null,
|
|
424
|
+
offerId: offerId ?? existing?.offerId ?? null,
|
|
425
|
+
plan: plan ?? existing?.plan ?? null,
|
|
426
|
+
interval: offer?.interval,
|
|
427
|
+
intervalCount: offer?.intervalCount,
|
|
428
|
+
metadata: {
|
|
429
|
+
...(existing?.metadata ?? {}),
|
|
430
|
+
...(event.metadata ?? {}),
|
|
431
|
+
pendingPlanChange: null,
|
|
432
|
+
},
|
|
433
|
+
}));
|
|
434
|
+
if (this.provisioning && (plan ?? existing?.plan)) {
|
|
435
|
+
// 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);
|
|
437
|
+
}
|
|
438
|
+
return { handled: true, action: "subscription_plan_changed" };
|
|
439
|
+
}
|
|
440
|
+
async handleCancellationScheduled(event) {
|
|
441
|
+
const uid = await this.resolveUserId(event);
|
|
442
|
+
if (!uid)
|
|
443
|
+
return { handled: false, error: "user_not_found" };
|
|
444
|
+
if (!event.subscription?.providerSubscriptionId)
|
|
445
|
+
return { handled: false, error: "no_subscription_data" };
|
|
446
|
+
const existing = await this.getExistingSubscription(event);
|
|
447
|
+
await this.store.upsertBillingSubscription(this.buildSubscriptionState(event, uid, existing, {
|
|
448
|
+
status: existing?.status ?? event.subscription.status ?? "active",
|
|
449
|
+
cancelAtPeriodEnd: true,
|
|
450
|
+
}));
|
|
451
|
+
return { handled: true, action: "cancellation_scheduled" };
|
|
452
|
+
}
|
|
453
|
+
async handleCancellationUnscheduled(event) {
|
|
454
|
+
const uid = await this.resolveUserId(event);
|
|
455
|
+
if (!uid)
|
|
456
|
+
return { handled: false, error: "user_not_found" };
|
|
457
|
+
if (!event.subscription?.providerSubscriptionId)
|
|
458
|
+
return { handled: false, error: "no_subscription_data" };
|
|
459
|
+
const existing = await this.getExistingSubscription(event);
|
|
460
|
+
await this.store.upsertBillingSubscription(this.buildSubscriptionState(event, uid, existing, {
|
|
461
|
+
status: existing?.status ?? event.subscription.status ?? "active",
|
|
462
|
+
cancelAtPeriodEnd: false,
|
|
463
|
+
}));
|
|
464
|
+
return { handled: true, action: "cancellation_unscheduled" };
|
|
465
|
+
}
|
|
466
|
+
async handleSubscriptionCanceled(event) {
|
|
467
|
+
this.logger.info("[BillingService] handleSubscriptionCanceled", {
|
|
468
|
+
provider: event.provider,
|
|
469
|
+
eventId: event.eventId,
|
|
470
|
+
});
|
|
471
|
+
const uid = await this.resolveUserId(event);
|
|
472
|
+
if (!uid)
|
|
473
|
+
return { handled: false, error: "user_not_found" };
|
|
474
|
+
if (!event.subscription?.providerSubscriptionId)
|
|
475
|
+
return { handled: false, error: "no_subscription_data" };
|
|
476
|
+
const existing = await this.getExistingSubscription(event);
|
|
477
|
+
const resolved = existing ? null : await this.resolveOfferAndKeys(event);
|
|
478
|
+
if (!existing && !resolved?.offerId) {
|
|
479
|
+
throw new Error(`cannot persist cancellation for unknown subscription ${event.provider}/${event.subscription.providerSubscriptionId}: offer could not be resolved`);
|
|
480
|
+
}
|
|
481
|
+
await this.store.upsertBillingSubscription(this.buildSubscriptionState(event, uid, existing, {
|
|
482
|
+
status: "canceled",
|
|
483
|
+
cancelAtPeriodEnd: event.subscription.cancelAtPeriodEnd ?? true,
|
|
484
|
+
offerKey: resolved?.offerKey ?? existing?.offerKey ?? null,
|
|
485
|
+
offerId: resolved?.offerId ?? existing?.offerId ?? null,
|
|
486
|
+
plan: resolved?.plan ?? existing?.plan ?? null,
|
|
487
|
+
interval: resolved?.offer?.interval,
|
|
488
|
+
intervalCount: resolved?.offer?.intervalCount,
|
|
489
|
+
}));
|
|
490
|
+
if (this.provisioning) {
|
|
491
|
+
await this.revokeIfCurrentSubscription(uid, event.subscription.providerSubscriptionId);
|
|
492
|
+
}
|
|
493
|
+
return { handled: true, action: "subscription_canceled" };
|
|
494
|
+
}
|
|
495
|
+
async handleSubscriptionExpired(event) {
|
|
496
|
+
const uid = await this.resolveUserId(event);
|
|
497
|
+
if (!uid)
|
|
498
|
+
return { handled: false, error: "user_not_found" };
|
|
499
|
+
if (!event.subscription?.providerSubscriptionId)
|
|
500
|
+
return { handled: false, error: "no_subscription_data" };
|
|
501
|
+
const existing = await this.getExistingSubscription(event);
|
|
502
|
+
await this.store.upsertBillingSubscription(this.buildSubscriptionState(event, uid, existing, {
|
|
503
|
+
status: "expired",
|
|
504
|
+
cancelAtPeriodEnd: event.subscription.cancelAtPeriodEnd ?? true,
|
|
505
|
+
}));
|
|
506
|
+
if (this.provisioning) {
|
|
507
|
+
await this.revokeIfCurrentSubscription(uid, event.subscription.providerSubscriptionId);
|
|
508
|
+
}
|
|
509
|
+
return { handled: true, action: "subscription_expired" };
|
|
510
|
+
}
|
|
511
|
+
async handleSubscriptionPaused(event) {
|
|
512
|
+
const uid = await this.resolveUserId(event);
|
|
513
|
+
if (!uid)
|
|
514
|
+
return { handled: false, error: "user_not_found" };
|
|
515
|
+
if (!event.subscription?.providerSubscriptionId)
|
|
516
|
+
return { handled: false, error: "no_subscription_data" };
|
|
517
|
+
const existing = await this.getExistingSubscription(event);
|
|
518
|
+
await this.store.upsertBillingSubscription(this.buildSubscriptionState(event, uid, existing, {
|
|
519
|
+
status: "paused",
|
|
520
|
+
cancelAtPeriodEnd: existing?.cancelAtPeriodEnd ?? false,
|
|
521
|
+
}));
|
|
522
|
+
if (this.provisioning) {
|
|
523
|
+
await this.revokeIfCurrentSubscription(uid, event.subscription.providerSubscriptionId);
|
|
524
|
+
}
|
|
525
|
+
return { handled: true, action: "subscription_paused" };
|
|
526
|
+
}
|
|
527
|
+
async handleSubscriptionResumed(event) {
|
|
528
|
+
const uid = await this.resolveUserId(event);
|
|
529
|
+
if (!uid)
|
|
530
|
+
return { handled: false, error: "user_not_found" };
|
|
531
|
+
if (!event.subscription?.providerSubscriptionId)
|
|
532
|
+
return { handled: false, error: "no_subscription_data" };
|
|
533
|
+
const existing = await this.getExistingSubscription(event);
|
|
534
|
+
const { offer, offerKey, plan } = await this.resolveOfferAndKeys(event);
|
|
535
|
+
await this.store.upsertBillingSubscription(this.buildSubscriptionState(event, uid, existing, {
|
|
536
|
+
status: "active",
|
|
537
|
+
cancelAtPeriodEnd: false,
|
|
538
|
+
offerKey: offerKey ?? existing?.offerKey ?? null,
|
|
539
|
+
plan: plan ?? existing?.plan ?? null,
|
|
540
|
+
}));
|
|
541
|
+
if (this.provisioning) {
|
|
542
|
+
await this.provisionSubscription(uid, offer, event);
|
|
543
|
+
}
|
|
544
|
+
return { handled: true, action: "subscription_resumed" };
|
|
545
|
+
}
|
|
546
|
+
async handleTrialWillEnd(event) {
|
|
547
|
+
// Resolve userId so routeEvent's blanket fireEventCallback has a useful value.
|
|
548
|
+
await this.resolveUserId(event);
|
|
549
|
+
return { handled: true, action: "trial_will_end_notified" };
|
|
550
|
+
}
|
|
551
|
+
async provisionSubscription(uid, offer, event, planKeyOverride, preserveAllowanceAnchor = false) {
|
|
552
|
+
if (!this.provisioning) {
|
|
553
|
+
this.logger.debug(`[BillingService] provisionSubscription: no provisioning capability for user ${uid}`);
|
|
554
|
+
return;
|
|
555
|
+
}
|
|
556
|
+
const plan = planKeyOverride ?? offer?.plan;
|
|
557
|
+
if (!plan) {
|
|
558
|
+
this.logger.debug("[BillingService] provisionSubscription skipped (no plan)", { uid });
|
|
559
|
+
return;
|
|
560
|
+
}
|
|
561
|
+
this.logger.debug("[BillingService] provisionSubscription setting plan", { uid, plan });
|
|
562
|
+
let periodStart;
|
|
563
|
+
if (preserveAllowanceAnchor) {
|
|
564
|
+
const existingAnchor = this.provisioning.getUserPlan
|
|
565
|
+
? (await this.provisioning.getUserPlan(uid))?.planAssignedAt
|
|
566
|
+
: undefined;
|
|
567
|
+
if (existingAnchor) {
|
|
568
|
+
const anchor = new Date(existingAnchor);
|
|
569
|
+
// A provider's subscription period start may actually be its next
|
|
570
|
+
// renewal date. Never let a future anchor hide an already-active
|
|
571
|
+
// entitlement after a plan change.
|
|
572
|
+
if (!Number.isNaN(anchor.getTime()) && anchor.getTime() <= Date.now()) {
|
|
573
|
+
periodStart = anchor;
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
else {
|
|
578
|
+
periodStart = event.subscription?.periodStart;
|
|
579
|
+
}
|
|
580
|
+
const planAssignedAt = periodStart
|
|
581
|
+
? (() => {
|
|
582
|
+
const d = new Date(periodStart);
|
|
583
|
+
return Number.isNaN(d.getTime()) ? undefined : d;
|
|
584
|
+
})()
|
|
585
|
+
: preserveAllowanceAnchor
|
|
586
|
+
? new Date()
|
|
587
|
+
: undefined;
|
|
588
|
+
await this.provisioning.setUserPlan(uid, plan, planAssignedAt);
|
|
589
|
+
if (this.autoSelectEntitlementSource && event.provider) {
|
|
590
|
+
const selected = await this.store.selectSubscriptionEntitlementSource(uid, event.provider, event.subscription?.providerSubscriptionId);
|
|
591
|
+
if (selected) {
|
|
592
|
+
this.logger.debug(`[BillingService] selected ${event.provider} subscription as entitlement source for user ${uid}`);
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
async grantSubscriptionCycle(event, offer) {
|
|
597
|
+
const credits = offer?.grant?.mode === "cycle_grant" ? offer.grant.credits : null;
|
|
598
|
+
if (!credits || credits <= 0 || !event.billingEventId || !event.subscription)
|
|
599
|
+
return;
|
|
600
|
+
const subscription = await this.store.getBillingSubscription(event.provider, event.subscription.providerSubscriptionId);
|
|
601
|
+
if (!subscription?.subscriptionId) {
|
|
602
|
+
throw new Error("subscription cycle grant requires a persisted subscription");
|
|
603
|
+
}
|
|
604
|
+
const payment = event.payment?.providerPaymentId != null
|
|
605
|
+
? await this.store.getBillingPayment(event.provider, event.payment.providerPaymentId)
|
|
606
|
+
: null;
|
|
607
|
+
const grantId = await this.store.createBillingCreditGrant({
|
|
608
|
+
paymentId: payment?.id == null ? null : String(payment.id),
|
|
609
|
+
subscriptionId: subscription.subscriptionId,
|
|
610
|
+
configuredCredits: credits,
|
|
611
|
+
quantity: 1,
|
|
612
|
+
billingEventId: event.billingEventId,
|
|
613
|
+
});
|
|
614
|
+
await this.store.grantBillingCredit(grantId, `billing:${event.eventId}:subscription-cycle`);
|
|
615
|
+
}
|
|
616
|
+
async revokeSubscription(uid) {
|
|
617
|
+
if (!this.provisioning)
|
|
618
|
+
return;
|
|
619
|
+
if (this.terminalPlanKey) {
|
|
620
|
+
await this.provisioning.setUserPlan(uid, this.terminalPlanKey);
|
|
621
|
+
return;
|
|
622
|
+
}
|
|
623
|
+
await this.provisioning.unsetUserPlan(uid);
|
|
624
|
+
}
|
|
625
|
+
/**
|
|
626
|
+
* Do not revoke access because a stale subscription record ended while a
|
|
627
|
+
* newer subscription for the same user is still active.
|
|
628
|
+
*/
|
|
629
|
+
async revokeIfCurrentSubscription(uid, subscriptionId) {
|
|
630
|
+
const current = await this.store.getUserSubscription(uid, ["active", "trialing", "past_due"]);
|
|
631
|
+
if (!current || current.providerSubscriptionId === subscriptionId) {
|
|
632
|
+
await this.revokeSubscription(uid);
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
async reEvaluateAccess(uid, event) {
|
|
636
|
+
if (!this.provisioning || !event.subscription)
|
|
637
|
+
return;
|
|
638
|
+
const status = event.subscription.status;
|
|
639
|
+
// Provider retries (Stripe past_due, Dodo on_hold mapped to past_due)
|
|
640
|
+
// are a grace period. Keep the last paid entitlements until the provider
|
|
641
|
+
// reaches a terminal state instead of revoking access on the first miss.
|
|
642
|
+
if (status && ["active", "trialing"].includes(status)) {
|
|
643
|
+
const offer = await this.resolveOfferFromEvent(event);
|
|
644
|
+
if (offer) {
|
|
645
|
+
await this.provisionSubscription(uid, offer, event);
|
|
646
|
+
}
|
|
647
|
+
else {
|
|
648
|
+
const existing = await this.store.getBillingSubscription(event.provider, event.subscription.providerSubscriptionId);
|
|
649
|
+
if (existing?.plan) {
|
|
650
|
+
await this.provisionSubscription(uid, null, event, existing.plan);
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
else if (status === "past_due") {
|
|
655
|
+
const existing = await this.store.getBillingSubscription(event.provider, event.subscription.providerSubscriptionId);
|
|
656
|
+
const graceHasExpired = Boolean(existing?.graceExpiredAt) ||
|
|
657
|
+
(Boolean(existing?.graceEndsAt) &&
|
|
658
|
+
new Date(existing.graceEndsAt).getTime() <= Date.now());
|
|
659
|
+
if (graceHasExpired) {
|
|
660
|
+
await this.revokeIfCurrentSubscription(uid, event.subscription.providerSubscriptionId);
|
|
661
|
+
}
|
|
662
|
+
else {
|
|
663
|
+
const offer = await this.resolveOfferFromEvent(event);
|
|
664
|
+
if (offer) {
|
|
665
|
+
await this.provisionSubscription(uid, offer, event);
|
|
666
|
+
}
|
|
667
|
+
else if (existing?.plan) {
|
|
668
|
+
await this.provisionSubscription(uid, null, event, existing.plan);
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
else if (status &&
|
|
673
|
+
["canceled", "expired", "unpaid", "paused", "incomplete_expired"].includes(status)) {
|
|
674
|
+
await this.revokeIfCurrentSubscription(uid, event.subscription.providerSubscriptionId);
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
async resolveOfferFromEvent(event) {
|
|
678
|
+
const refs = event.subscription?.refs;
|
|
679
|
+
if (!refs)
|
|
680
|
+
return null;
|
|
681
|
+
return this.resolveBillingOfferCached(event.provider, refs.productId ?? null, refs.priceId ?? null);
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
//# sourceMappingURL=event-handlers.js.map
|