@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
package/dist/commerce/service.js
CHANGED
|
@@ -3,7 +3,7 @@ import Decimal from "decimal.js";
|
|
|
3
3
|
import { loadConfigFromDict } from "../config.js";
|
|
4
4
|
import { ConfigError } from "../errors.js";
|
|
5
5
|
import { normalizeLogger } from "../shared/logger.js";
|
|
6
|
-
import { ActiveSubscriptionError, CheckoutCompletedError, CheckoutConflictError, CommerceResourceNotFoundError, CoreBillingDataUnavailableError, InvalidOfferQuantityError,
|
|
6
|
+
import { ActiveSubscriptionError, CheckoutCompletedError, CheckoutConflictError, CommerceResourceNotFoundError, CoreBillingDataUnavailableError, InvalidOfferQuantityError, ProviderCapabilityNotSupportedError, QuoteChangedError, UnknownOfferError, } from "./errors.js";
|
|
7
7
|
import { CommerceProviderRegistry } from "./provider-registry.js";
|
|
8
8
|
import { classifySubscriptionChange } from "./plan-change.js";
|
|
9
9
|
const DEFAULT_CHECKOUT_INTENT_TTL_MS = 24 * 60 * 60 * 1_000;
|
|
@@ -14,6 +14,40 @@ const DEFAULT_PREFERENCES = {
|
|
|
14
14
|
usageAlerts: true,
|
|
15
15
|
invoiceReminders: false,
|
|
16
16
|
};
|
|
17
|
+
function requireNonEmptyText(value, field) {
|
|
18
|
+
if (typeof value !== "string" || !value.trim()) {
|
|
19
|
+
throw new TypeError(`${field} must be a non-empty string`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function requireOptionalNonEmptyText(value, field) {
|
|
23
|
+
if (value !== null && value !== undefined)
|
|
24
|
+
requireNonEmptyText(value, field);
|
|
25
|
+
}
|
|
26
|
+
function assertCreateCheckoutInput(input) {
|
|
27
|
+
requireNonEmptyText(input.subjectId, "subjectId");
|
|
28
|
+
requireNonEmptyText(input.offerKey, "offerKey");
|
|
29
|
+
requireNonEmptyText(input.returnUrl, "returnUrl");
|
|
30
|
+
requireNonEmptyText(input.cancelUrl, "cancelUrl");
|
|
31
|
+
requireNonEmptyText(input.operationKey, "operationKey");
|
|
32
|
+
requireOptionalNonEmptyText(input.accountId, "accountId");
|
|
33
|
+
requireOptionalNonEmptyText(input.email, "email");
|
|
34
|
+
requireOptionalNonEmptyText(input.provider, "provider");
|
|
35
|
+
if (input.type !== undefined && input.type !== "subscription" && input.type !== "credit_pack") {
|
|
36
|
+
throw new TypeError("type must be 'subscription' or 'credit_pack'");
|
|
37
|
+
}
|
|
38
|
+
if (input.metadata !== undefined) {
|
|
39
|
+
if (typeof input.metadata !== "object" ||
|
|
40
|
+
input.metadata === null ||
|
|
41
|
+
Array.isArray(input.metadata)) {
|
|
42
|
+
throw new TypeError("metadata must be an object of string values");
|
|
43
|
+
}
|
|
44
|
+
for (const [key, value] of Object.entries(input.metadata)) {
|
|
45
|
+
if (!key.trim() || typeof value !== "string") {
|
|
46
|
+
throw new TypeError("metadata must contain non-empty keys and string values");
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
17
51
|
const TERMINAL_CHECKOUT_STATUSES = new Set(["failed", "cancelled", "requires_payment_method"]);
|
|
18
52
|
const CURRENT_SUBSCRIPTION_STATUSES = new Set(["active", "trialing", "past_due", "incomplete"]);
|
|
19
53
|
const BLOCKING_SUBSCRIPTION_STATUSES = new Set(["active", "trialing", "past_due", "incomplete"]);
|
|
@@ -70,8 +104,10 @@ function providerPlanChangeParams(policy) {
|
|
|
70
104
|
}
|
|
71
105
|
class CommerceAutoRechargeService {
|
|
72
106
|
commerce;
|
|
73
|
-
|
|
107
|
+
providerByName;
|
|
108
|
+
constructor(commerce, providerByName) {
|
|
74
109
|
this.commerce = commerce;
|
|
110
|
+
this.providerByName = providerByName;
|
|
75
111
|
}
|
|
76
112
|
async getStatus(input) {
|
|
77
113
|
const provider = await this.commerce.providerForAccount(input.accountId);
|
|
@@ -85,20 +121,12 @@ class CommerceAutoRechargeService {
|
|
|
85
121
|
this.commerce.providerForAccount(input.accountId),
|
|
86
122
|
this.commerce.credits.getBalance(input.accountId),
|
|
87
123
|
]);
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
catch (error) {
|
|
97
|
-
if (error instanceof Error && error.message.includes("payment_method")) {
|
|
98
|
-
throw new MissingPaymentMethodError();
|
|
99
|
-
}
|
|
100
|
-
throw error;
|
|
101
|
-
}
|
|
124
|
+
return this.commerce.billing.autoRecharge.enable({
|
|
125
|
+
userId: input.accountId,
|
|
126
|
+
provider,
|
|
127
|
+
balance: balance.balance,
|
|
128
|
+
returnUrl: input.returnUrl,
|
|
129
|
+
});
|
|
102
130
|
}
|
|
103
131
|
async disable(input) {
|
|
104
132
|
await this.commerce.billing.autoRecharge.disable(input.accountId);
|
|
@@ -108,24 +136,16 @@ class CommerceAutoRechargeService {
|
|
|
108
136
|
this.commerce.providerForAccount(input.accountId),
|
|
109
137
|
this.commerce.credits.getBalance(input.accountId),
|
|
110
138
|
]);
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
catch (error) {
|
|
124
|
-
if (error instanceof Error && error.message.includes("payment_method")) {
|
|
125
|
-
throw new MissingPaymentMethodError();
|
|
126
|
-
}
|
|
127
|
-
throw error;
|
|
128
|
-
}
|
|
139
|
+
await this.commerce.billing.autoRecharge.retry({
|
|
140
|
+
userId: input.accountId,
|
|
141
|
+
provider,
|
|
142
|
+
balance: balance.balance,
|
|
143
|
+
returnUrl: input.returnUrl,
|
|
144
|
+
});
|
|
145
|
+
return this.commerce.billing.autoRecharge.getStatus({
|
|
146
|
+
userId: input.accountId,
|
|
147
|
+
provider,
|
|
148
|
+
});
|
|
129
149
|
}
|
|
130
150
|
async processIfNeeded(input) {
|
|
131
151
|
const profile = await this.commerce.billing.getAutoRechargeProfile(input.accountId);
|
|
@@ -134,14 +154,14 @@ class CommerceAutoRechargeService {
|
|
|
134
154
|
}
|
|
135
155
|
const [provider, balance] = await Promise.all([
|
|
136
156
|
profile.provider
|
|
137
|
-
? this.
|
|
157
|
+
? this.providerByName(profile.provider)
|
|
138
158
|
: this.commerce.providerForAccount(input.accountId),
|
|
139
159
|
this.commerce.credits.getBalance(input.accountId),
|
|
140
160
|
]);
|
|
141
161
|
return this.commerce.billing.autoRecharge.processIfNeeded({
|
|
142
162
|
userId: input.accountId,
|
|
143
163
|
provider,
|
|
144
|
-
balance:
|
|
164
|
+
balance: balance.balance,
|
|
145
165
|
returnUrl: input.returnUrl,
|
|
146
166
|
});
|
|
147
167
|
}
|
|
@@ -158,10 +178,15 @@ export class CommerceService {
|
|
|
158
178
|
this.billing = billing;
|
|
159
179
|
this.credits = credits;
|
|
160
180
|
this.options = options;
|
|
181
|
+
if (options.checkoutIntentTtlMs !== undefined &&
|
|
182
|
+
(!Number.isSafeInteger(options.checkoutIntentTtlMs) || options.checkoutIntentTtlMs <= 0)) {
|
|
183
|
+
throw new TypeError("checkoutIntentTtlMs must be a positive safe integer");
|
|
184
|
+
}
|
|
161
185
|
this.logger = normalizeLogger(options.logger);
|
|
162
186
|
const identityResolver = options.identityResolver
|
|
163
187
|
? async (input) => {
|
|
164
188
|
const accountId = await options.identityResolver(input);
|
|
189
|
+
requireOptionalNonEmptyText(accountId, "identity resolver accountId");
|
|
165
190
|
if (accountId && input.customerId) {
|
|
166
191
|
await this.billing.upsertCustomer(input.provider, input.customerId, accountId, input.email);
|
|
167
192
|
}
|
|
@@ -173,17 +198,13 @@ export class CommerceService {
|
|
|
173
198
|
eventSink,
|
|
174
199
|
identityResolver,
|
|
175
200
|
});
|
|
176
|
-
this.autoRecharge = new CommerceAutoRechargeService(this);
|
|
177
|
-
}
|
|
178
|
-
/** Exposed for application composition and compatibility, not provider selection policy. */
|
|
179
|
-
getProvider(providerName) {
|
|
180
|
-
return this.providers.get(providerName);
|
|
201
|
+
this.autoRecharge = new CommerceAutoRechargeService(this, (name) => this.providers.get(name));
|
|
181
202
|
}
|
|
182
203
|
clearProviderCache() {
|
|
183
204
|
this.providers.clear();
|
|
184
205
|
}
|
|
185
206
|
async activeConfig() {
|
|
186
|
-
const raw = await this.billing.
|
|
207
|
+
const raw = await this.billing.getActiveCatalogDocument();
|
|
187
208
|
if (!raw) {
|
|
188
209
|
throw new CoreBillingDataUnavailableError("The active commerce catalog is unavailable");
|
|
189
210
|
}
|
|
@@ -235,6 +256,7 @@ export class CommerceService {
|
|
|
235
256
|
});
|
|
236
257
|
}
|
|
237
258
|
async createCheckout(input) {
|
|
259
|
+
assertCreateCheckoutInput(input);
|
|
238
260
|
const resolved = await this.resolveOffer(input);
|
|
239
261
|
const quantity = this.quantity(resolved.offer, input.quantity);
|
|
240
262
|
const accountState = input.accountId
|
|
@@ -491,7 +513,8 @@ export class CommerceService {
|
|
|
491
513
|
const status = subscription?.status ?? null;
|
|
492
514
|
const isCurrent = status != null && CURRENT_SUBSCRIPTION_STATUSES.has(status);
|
|
493
515
|
const isEntitled = entitlement.planKey != null;
|
|
494
|
-
|
|
516
|
+
const planKey = entitlement.planKey ?? (isCurrent ? (subscription?.plan ?? null) : null);
|
|
517
|
+
if (planKey && !config.plans[planKey]) {
|
|
495
518
|
throw new CoreBillingDataUnavailableError("The account plan is not present in the catalog");
|
|
496
519
|
}
|
|
497
520
|
const inGrace = status === "past_due" &&
|
|
@@ -499,7 +522,7 @@ export class CommerceService {
|
|
|
499
522
|
Date.parse(subscription.graceEndsAt) > Date.now();
|
|
500
523
|
return {
|
|
501
524
|
accountId,
|
|
502
|
-
planKey
|
|
525
|
+
planKey,
|
|
503
526
|
status,
|
|
504
527
|
lifecycleState: status ?? "none",
|
|
505
528
|
accessState: isEntitled ? (inGrace ? "grace" : "entitled") : status ? "blocked" : "none",
|
|
@@ -632,13 +655,7 @@ export class CommerceService {
|
|
|
632
655
|
}
|
|
633
656
|
const existing = await this.billing.getOpenBillingSubscriptionChange(context.subscription.provider, context.subscription.providerSubscriptionId);
|
|
634
657
|
if (existing?.state === "scheduled" && existing.effective === "renewal") {
|
|
635
|
-
|
|
636
|
-
throw new ProviderCapabilityNotSupportedError(context.provider.provider, "cancelScheduledPlanChange");
|
|
637
|
-
}
|
|
638
|
-
await context.provider.cancelScheduledPlanChange(context.subscription.providerSubscriptionId, existing.providerOperationId, `${input.operationKey}:replace`);
|
|
639
|
-
await this.billing.updateBillingSubscriptionChange(existing.id, {
|
|
640
|
-
state: "canceled",
|
|
641
|
-
});
|
|
658
|
+
throw new CheckoutConflictError("Cancel the existing plan change before choosing another plan");
|
|
642
659
|
}
|
|
643
660
|
else if (existing) {
|
|
644
661
|
throw new CheckoutConflictError("A plan change is already awaiting payment");
|
|
@@ -661,12 +678,17 @@ export class CommerceService {
|
|
|
661
678
|
idempotencyKey: input.operationKey,
|
|
662
679
|
prorationBehavior: context.policy.proration === "none" ? "none" : "invoice_immediately",
|
|
663
680
|
});
|
|
681
|
+
let cancellationWasReactivated = false;
|
|
664
682
|
try {
|
|
665
683
|
if (context.subscription.cancelAtPeriodEnd) {
|
|
666
684
|
if (!context.provider.reactivateSubscription) {
|
|
667
685
|
throw new ProviderCapabilityNotSupportedError(context.provider.provider, "reactivateSubscription");
|
|
668
686
|
}
|
|
687
|
+
if (!context.provider.cancelSubscription) {
|
|
688
|
+
throw new ProviderCapabilityNotSupportedError(context.provider.provider, "cancelSubscription");
|
|
689
|
+
}
|
|
669
690
|
await context.provider.reactivateSubscription(context.subscription.providerSubscriptionId, `${input.operationKey}:keep`);
|
|
691
|
+
cancellationWasReactivated = true;
|
|
670
692
|
}
|
|
671
693
|
const result = await context.provider.changePlan({
|
|
672
694
|
providerSubscriptionId: context.subscription.providerSubscriptionId,
|
|
@@ -685,11 +707,20 @@ export class CommerceService {
|
|
|
685
707
|
});
|
|
686
708
|
}
|
|
687
709
|
catch (error) {
|
|
710
|
+
let failure = error;
|
|
711
|
+
if (cancellationWasReactivated) {
|
|
712
|
+
try {
|
|
713
|
+
await context.provider.cancelSubscription(context.subscription.providerSubscriptionId, `${input.operationKey}:restore-cancellation`);
|
|
714
|
+
}
|
|
715
|
+
catch (compensationError) {
|
|
716
|
+
failure = new AggregateError([error, compensationError], "Plan change failed and the original subscription cancellation could not be restored");
|
|
717
|
+
}
|
|
718
|
+
}
|
|
688
719
|
await this.billing.updateBillingSubscriptionChange(change.id, {
|
|
689
720
|
state: "failed",
|
|
690
|
-
errorMessage:
|
|
721
|
+
errorMessage: failure instanceof Error ? failure.message : String(failure),
|
|
691
722
|
});
|
|
692
|
-
throw
|
|
723
|
+
throw failure;
|
|
693
724
|
}
|
|
694
725
|
return {
|
|
695
726
|
success: true,
|
|
@@ -820,7 +851,7 @@ export class CommerceService {
|
|
|
820
851
|
const subscriptionSummary = this.accountSubscriptionSummary(accountId, core.subscription, core.entitlement, core.config, pendingChange);
|
|
821
852
|
const [transactionsResult, usageResult, invoicesResult] = await Promise.allSettled([
|
|
822
853
|
this.credits.listLedgerEntries(accountId, { limit: 50 }),
|
|
823
|
-
this.credits.listUsageCharges(accountId, { limit: 100 }),
|
|
854
|
+
this.credits.listUsageCharges(accountId, { limit: 100, includeRecordOnly: false }),
|
|
824
855
|
this.billing.listBillingInvoices(accountId),
|
|
825
856
|
]);
|
|
826
857
|
const transactions = transactionsResult.status === "fulfilled"
|
|
@@ -830,22 +861,19 @@ export class CommerceService {
|
|
|
830
861
|
const invoices = invoicesResult.status === "fulfilled" ? invoicesResult.value : [];
|
|
831
862
|
const documents = [
|
|
832
863
|
...invoices.flatMap((invoice) => {
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
},
|
|
847
|
-
]
|
|
848
|
-
: [];
|
|
864
|
+
return [
|
|
865
|
+
{
|
|
866
|
+
kind: "provider_invoice",
|
|
867
|
+
provider: invoice.provider,
|
|
868
|
+
providerDocumentId: invoice.providerInvoiceId,
|
|
869
|
+
status: invoice.status,
|
|
870
|
+
amountPaidMinor: invoice.amountPaidMinor,
|
|
871
|
+
amountDueMinor: invoice.amountDueMinor,
|
|
872
|
+
currency: invoice.currency,
|
|
873
|
+
periodStart: invoice.periodStart,
|
|
874
|
+
periodEnd: invoice.periodEnd,
|
|
875
|
+
},
|
|
876
|
+
];
|
|
849
877
|
}),
|
|
850
878
|
...transactions.flatMap((entry) => {
|
|
851
879
|
const document = this.ledgerDocument(entry);
|
|
@@ -892,22 +920,47 @@ export class CommerceService {
|
|
|
892
920
|
const floor = core.entitlement.creditPolicy?.type === "credit_line"
|
|
893
921
|
? (core.entitlement.creditPolicy.creditLimit ?? new Decimal(0)).negated()
|
|
894
922
|
: new Decimal(0);
|
|
923
|
+
const allowanceRemaining = core.allowance?.allowanceRemaining ?? new Decimal(0);
|
|
924
|
+
const spendOrder = [
|
|
925
|
+
...(core.entitlement.allowance
|
|
926
|
+
? [
|
|
927
|
+
{
|
|
928
|
+
type: "allowance",
|
|
929
|
+
key: "allowance",
|
|
930
|
+
label: "Plan allowance",
|
|
931
|
+
priority: core.entitlement.allowance.priority,
|
|
932
|
+
},
|
|
933
|
+
]
|
|
934
|
+
: []),
|
|
935
|
+
...core.bucketBalances.buckets.map((bucket) => ({
|
|
936
|
+
type: "bucket",
|
|
937
|
+
key: bucket.bucketKey,
|
|
938
|
+
label: bucket.label,
|
|
939
|
+
priority: bucket.priority,
|
|
940
|
+
})),
|
|
941
|
+
].sort((left, right) => {
|
|
942
|
+
const priority = left.priority - right.priority;
|
|
943
|
+
if (priority !== 0)
|
|
944
|
+
return priority;
|
|
945
|
+
if (left.type !== right.type)
|
|
946
|
+
return left.type === "allowance" ? -1 : 1;
|
|
947
|
+
return left.key.localeCompare(right.key);
|
|
948
|
+
});
|
|
895
949
|
return {
|
|
896
950
|
accountId,
|
|
897
951
|
credits: {
|
|
898
952
|
ledgerBalance: core.balance.balance,
|
|
899
|
-
effectiveSpendableBalance: core.available.available
|
|
900
|
-
.plus(core.allowance.allowanceRemaining)
|
|
901
|
-
.minus(floor),
|
|
953
|
+
effectiveSpendableBalance: core.available.available.plus(allowanceRemaining).minus(floor),
|
|
902
954
|
lifetimePurchases: core.balance.lifetimePurchased,
|
|
903
955
|
allowance: {
|
|
904
|
-
remaining:
|
|
956
|
+
remaining: allowanceRemaining,
|
|
905
957
|
limit: core.entitlement.allowance?.amount ?? null,
|
|
906
|
-
periodStart: core.allowance
|
|
907
|
-
periodEnd: core.allowance
|
|
958
|
+
periodStart: core.allowance?.periodStart ?? null,
|
|
959
|
+
periodEnd: core.allowance?.periodEnd ?? null,
|
|
908
960
|
},
|
|
909
961
|
buckets: core.bucketBalances.buckets,
|
|
910
962
|
bucketsByKey: Object.fromEntries(core.bucketBalances.buckets.map((bucket) => [bucket.bucketKey, bucket.balance])),
|
|
963
|
+
spendOrder,
|
|
911
964
|
display: core.config.credits.display ?? null,
|
|
912
965
|
},
|
|
913
966
|
entitlement: core.entitlement,
|
|
@@ -936,7 +989,7 @@ export class CommerceService {
|
|
|
936
989
|
let providerDocumentId;
|
|
937
990
|
if (input.document.kind === "provider_invoice") {
|
|
938
991
|
const document = input.document;
|
|
939
|
-
const owned = (await this.billing.listBillingInvoices(input.accountId)).find((invoice) =>
|
|
992
|
+
const owned = (await this.billing.listBillingInvoices(input.accountId)).find((invoice) => invoice.provider === document.provider &&
|
|
940
993
|
invoice.providerInvoiceId === document.providerDocumentId);
|
|
941
994
|
if (!owned)
|
|
942
995
|
throw new CommerceResourceNotFoundError("Invoice not found");
|