@zonastery/bursar 1.0.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +189 -62
- package/dist/billing/auto-recharge-port.d.ts +3 -3
- package/dist/billing/auto-recharge-port.d.ts.map +1 -1
- package/dist/billing/auto-recharge-port.js.map +1 -1
- package/dist/billing/auto-recharge-service.d.ts +5 -4
- package/dist/billing/auto-recharge-service.d.ts.map +1 -1
- package/dist/billing/auto-recharge-service.js +64 -34
- package/dist/billing/auto-recharge-service.js.map +1 -1
- package/dist/billing/billing-service.d.ts +5 -5
- package/dist/billing/billing-service.d.ts.map +1 -1
- package/dist/billing/billing-service.js +2 -2
- package/dist/billing/billing-service.js.map +1 -1
- package/dist/billing/billing-store.d.ts +10 -9
- package/dist/billing/billing-store.d.ts.map +1 -1
- package/dist/billing/billing-store.js.map +1 -1
- package/dist/billing/contracts.d.ts +31 -31
- package/dist/billing/contracts.d.ts.map +1 -1
- package/dist/billing/contracts.js.map +1 -1
- package/dist/billing/event-handlers.d.ts.map +1 -1
- package/dist/billing/event-handlers.js +49 -10
- package/dist/billing/event-handlers.js.map +1 -1
- package/dist/billing/event-processor.d.ts +1 -0
- package/dist/billing/event-processor.d.ts.map +1 -1
- package/dist/billing/event-processor.js +37 -10
- package/dist/billing/event-processor.js.map +1 -1
- package/dist/billing/financial-event-handlers.d.ts.map +1 -1
- package/dist/billing/financial-event-handlers.js +69 -72
- package/dist/billing/financial-event-handlers.js.map +1 -1
- package/dist/billing/index.d.ts +2 -1
- package/dist/billing/index.d.ts.map +1 -1
- package/dist/billing/index.js.map +1 -1
- package/dist/billing/management.d.ts +5 -5
- package/dist/billing/management.d.ts.map +1 -1
- package/dist/billing/management.js +2 -2
- package/dist/billing/management.js.map +1 -1
- package/dist/billing/policy-window.js.map +1 -1
- package/dist/billing/postgres/repositories/auto-recharge.d.ts +3 -3
- package/dist/billing/postgres/repositories/auto-recharge.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/auto-recharge.js +205 -60
- package/dist/billing/postgres/repositories/auto-recharge.js.map +1 -1
- package/dist/billing/postgres/repositories/customer.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/customer.js +19 -11
- package/dist/billing/postgres/repositories/customer.js.map +1 -1
- package/dist/billing/postgres/repositories/dispute.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/dispute.js +3 -1
- package/dist/billing/postgres/repositories/dispute.js.map +1 -1
- package/dist/billing/postgres/repositories/event.d.ts +14 -7
- package/dist/billing/postgres/repositories/event.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/event.js +21 -20
- package/dist/billing/postgres/repositories/event.js.map +1 -1
- package/dist/billing/postgres/repositories/invoice.d.ts +3 -3
- package/dist/billing/postgres/repositories/invoice.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/invoice.js +53 -11
- package/dist/billing/postgres/repositories/invoice.js.map +1 -1
- package/dist/billing/postgres/repositories/offer.d.ts +20 -17
- package/dist/billing/postgres/repositories/offer.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/offer.js +123 -57
- package/dist/billing/postgres/repositories/offer.js.map +1 -1
- package/dist/billing/postgres/repositories/payment.d.ts +23 -20
- package/dist/billing/postgres/repositories/payment.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/payment.js +43 -37
- package/dist/billing/postgres/repositories/payment.js.map +1 -1
- package/dist/billing/postgres/repositories/preferences.d.ts +3 -9
- package/dist/billing/postgres/repositories/preferences.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/preferences.js +45 -7
- package/dist/billing/postgres/repositories/preferences.js.map +1 -1
- package/dist/billing/postgres/repositories/refund.d.ts +1 -1
- package/dist/billing/postgres/repositories/refund.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/refund.js +13 -9
- package/dist/billing/postgres/repositories/refund.js.map +1 -1
- package/dist/billing/postgres/repositories/subscription-change.d.ts +15 -0
- package/dist/billing/postgres/repositories/subscription-change.d.ts.map +1 -0
- package/dist/billing/postgres/repositories/subscription-change.js +234 -0
- package/dist/billing/postgres/repositories/subscription-change.js.map +1 -0
- package/dist/billing/postgres/repositories/subscription.d.ts +38 -17
- package/dist/billing/postgres/repositories/subscription.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/subscription.js +199 -91
- package/dist/billing/postgres/repositories/subscription.js.map +1 -1
- package/dist/billing/postgres/repositories/topup.d.ts +13 -15
- package/dist/billing/postgres/repositories/topup.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/topup.js +65 -34
- package/dist/billing/postgres/repositories/topup.js.map +1 -1
- package/dist/billing/postgres/store.d.ts +23 -14
- package/dist/billing/postgres/store.d.ts.map +1 -1
- package/dist/billing/postgres/store.js +265 -228
- package/dist/billing/postgres/store.js.map +1 -1
- package/dist/billing/service-types.d.ts +6 -5
- package/dist/billing/service-types.d.ts.map +1 -1
- package/dist/billing/service-types.js.map +1 -1
- package/dist/billing/types/auto-recharge.d.ts +6 -4
- package/dist/billing/types/auto-recharge.d.ts.map +1 -1
- package/dist/billing/types/auto-recharge.js.map +1 -1
- package/dist/billing/types/catalog.d.ts +18 -35
- package/dist/billing/types/catalog.d.ts.map +1 -1
- package/dist/billing/types/catalog.js.map +1 -1
- package/dist/billing/types/common.d.ts +0 -1
- package/dist/billing/types/common.d.ts.map +1 -1
- package/dist/billing/types/common.js.map +1 -1
- package/dist/billing/types/documents.d.ts +38 -12
- package/dist/billing/types/documents.d.ts.map +1 -1
- package/dist/billing/types/documents.js.map +1 -1
- package/dist/billing/types/events.d.ts +2 -0
- package/dist/billing/types/events.d.ts.map +1 -1
- package/dist/billing/types/events.js +238 -0
- package/dist/billing/types/events.js.map +1 -1
- package/dist/billing/types/index.js.map +1 -1
- package/dist/billing/types/preferences.js.map +1 -1
- package/dist/billing/types/subscriptions.d.ts +8 -8
- package/dist/billing/types/subscriptions.d.ts.map +1 -1
- package/dist/billing/types/subscriptions.js.map +1 -1
- package/dist/breakdown.js.map +1 -1
- package/dist/browser.js.map +1 -1
- package/dist/bursar.d.ts +33 -11
- package/dist/bursar.d.ts.map +1 -1
- package/dist/bursar.js +58 -22
- package/dist/bursar.js.map +1 -1
- package/dist/catalog.d.ts +1 -0
- package/dist/catalog.d.ts.map +1 -1
- package/dist/catalog.js +1 -0
- package/dist/catalog.js.map +1 -1
- package/dist/commerce/errors.d.ts +4 -14
- package/dist/commerce/errors.d.ts.map +1 -1
- package/dist/commerce/errors.js +4 -21
- package/dist/commerce/errors.js.map +1 -1
- package/dist/commerce/index.d.ts +1 -0
- package/dist/commerce/index.d.ts.map +1 -1
- package/dist/commerce/index.js.map +1 -1
- package/dist/commerce/plan-change.js.map +1 -1
- package/dist/commerce/provider-registry.d.ts.map +1 -1
- package/dist/commerce/provider-registry.js +27 -2
- package/dist/commerce/provider-registry.js.map +1 -1
- package/dist/commerce/service.d.ts +15 -7
- package/dist/commerce/service.d.ts.map +1 -1
- package/dist/commerce/service.js +130 -77
- package/dist/commerce/service.js.map +1 -1
- package/dist/commerce/types.d.ts +33 -13
- package/dist/commerce/types.d.ts.map +1 -1
- package/dist/commerce/types.js.map +1 -1
- package/dist/config/parse-access.js.map +1 -1
- package/dist/config/parse-commerce.js.map +1 -1
- package/dist/config/parse-credits.js.map +1 -1
- package/dist/config/parse-plans.d.ts.map +1 -1
- package/dist/config/parse-plans.js +30 -13
- package/dist/config/parse-plans.js.map +1 -1
- package/dist/config/parse-pricing.d.ts.map +1 -1
- package/dist/config/parse-pricing.js +16 -5
- package/dist/config/parse-pricing.js.map +1 -1
- package/dist/config/parse-utils.js.map +1 -1
- package/dist/config/types.d.ts +14 -1
- package/dist/config/types.d.ts.map +1 -1
- package/dist/config/types.js.map +1 -1
- package/dist/config.d.ts +7 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +64 -1
- package/dist/config.js.map +1 -1
- package/dist/credits/{pricing-runtime.d.ts → catalog-runtime.d.ts} +9 -8
- package/dist/credits/catalog-runtime.d.ts.map +1 -0
- package/dist/credits/{pricing-runtime.js → catalog-runtime.js} +58 -38
- package/dist/credits/catalog-runtime.js.map +1 -0
- package/dist/credits/events.d.ts +4 -4
- package/dist/credits/events.d.ts.map +1 -1
- package/dist/credits/events.js +1 -1
- package/dist/credits/events.js.map +1 -1
- package/dist/credits/lease-workflow.d.ts +14 -14
- package/dist/credits/lease-workflow.d.ts.map +1 -1
- package/dist/credits/lease-workflow.js +18 -17
- package/dist/credits/lease-workflow.js.map +1 -1
- package/dist/credits/low-balance-monitor.d.ts +2 -2
- package/dist/credits/low-balance-monitor.d.ts.map +1 -1
- package/dist/credits/low-balance-monitor.js.map +1 -1
- package/dist/credits/postgres/repositories/analytics.d.ts +39 -35
- package/dist/credits/postgres/repositories/analytics.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/analytics.js +55 -53
- package/dist/credits/postgres/repositories/analytics.js.map +1 -1
- package/dist/credits/postgres/repositories/balance.d.ts +28 -30
- package/dist/credits/postgres/repositories/balance.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/balance.js +100 -59
- package/dist/credits/postgres/repositories/balance.js.map +1 -1
- package/dist/credits/postgres/repositories/bucket.d.ts +14 -8
- package/dist/credits/postgres/repositories/bucket.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/bucket.js +22 -21
- package/dist/credits/postgres/repositories/bucket.js.map +1 -1
- package/dist/credits/postgres/repositories/catalog.d.ts +31 -0
- package/dist/credits/postgres/repositories/catalog.d.ts.map +1 -0
- package/dist/credits/postgres/repositories/catalog.js +90 -0
- package/dist/credits/postgres/repositories/catalog.js.map +1 -0
- package/dist/credits/postgres/repositories/deduction.d.ts +32 -21
- package/dist/credits/postgres/repositories/deduction.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/deduction.js +171 -62
- package/dist/credits/postgres/repositories/deduction.js.map +1 -1
- package/dist/credits/postgres/repositories/lease.d.ts +21 -18
- package/dist/credits/postgres/repositories/lease.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/lease.js +157 -65
- package/dist/credits/postgres/repositories/lease.js.map +1 -1
- package/dist/credits/postgres/repositories/plan.d.ts +94 -42
- package/dist/credits/postgres/repositories/plan.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/plan.js +134 -104
- package/dist/credits/postgres/repositories/plan.js.map +1 -1
- package/dist/credits/postgres/repositories/team.d.ts +36 -27
- package/dist/credits/postgres/repositories/team.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/team.js +96 -52
- package/dist/credits/postgres/repositories/team.js.map +1 -1
- package/dist/credits/postgres/store.d.ts +31 -21
- package/dist/credits/postgres/store.d.ts.map +1 -1
- package/dist/credits/postgres/store.js +325 -235
- package/dist/credits/postgres/store.js.map +1 -1
- package/dist/credits/postgres/value-mappers.d.ts +7 -9
- package/dist/credits/postgres/value-mappers.d.ts.map +1 -1
- package/dist/credits/postgres/value-mappers.js +42 -63
- package/dist/credits/postgres/value-mappers.js.map +1 -1
- package/dist/credits/queries.d.ts +5 -5
- package/dist/credits/queries.d.ts.map +1 -1
- package/dist/credits/queries.js +4 -4
- package/dist/credits/queries.js.map +1 -1
- package/dist/credits/service-errors.js.map +1 -1
- package/dist/credits/service-types.d.ts +42 -7
- package/dist/credits/service-types.d.ts.map +1 -1
- package/dist/credits/service-types.js.map +1 -1
- package/dist/credits/service.d.ts +51 -58
- package/dist/credits/service.d.ts.map +1 -1
- package/dist/credits/service.js +178 -113
- package/dist/credits/service.js.map +1 -1
- package/dist/credits/store.d.ts +25 -22
- package/dist/credits/store.d.ts.map +1 -1
- package/dist/credits/store.js +9 -5
- package/dist/credits/store.js.map +1 -1
- package/dist/credits/types/account.d.ts +50 -12
- package/dist/credits/types/account.d.ts.map +1 -1
- package/dist/credits/types/account.js.map +1 -1
- package/dist/credits/types/admission.d.ts +17 -6
- package/dist/credits/types/admission.d.ts.map +1 -1
- package/dist/credits/types/admission.js.map +1 -1
- package/dist/credits/types/analytics.d.ts +2 -2
- package/dist/credits/types/analytics.d.ts.map +1 -1
- package/dist/credits/types/analytics.js.map +1 -1
- package/dist/credits/types/catalog.d.ts +21 -14
- package/dist/credits/types/catalog.d.ts.map +1 -1
- package/dist/credits/types/catalog.js.map +1 -1
- package/dist/credits/types/grants.d.ts +22 -8
- package/dist/credits/types/grants.d.ts.map +1 -1
- package/dist/credits/types/grants.js.map +1 -1
- package/dist/credits/types/index.js.map +1 -1
- package/dist/credits/types/ledger.d.ts +19 -0
- package/dist/credits/types/ledger.d.ts.map +1 -1
- package/dist/credits/types/ledger.js.map +1 -1
- package/dist/credits/types/quotas.js.map +1 -1
- package/dist/credits/types/teams.d.ts +18 -6
- package/dist/credits/types/teams.d.ts.map +1 -1
- package/dist/credits/types/teams.js.map +1 -1
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +24 -10
- package/dist/engine.js.map +1 -1
- package/dist/errors.d.ts +105 -8
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +137 -9
- package/dist/errors.js.map +1 -1
- package/dist/expr/ast.d.ts.map +1 -1
- package/dist/expr/ast.js.map +1 -1
- package/dist/expr/evaluator.d.ts.map +1 -1
- package/dist/expr/evaluator.js +29 -17
- package/dist/expr/evaluator.js.map +1 -1
- package/dist/expr/language.js.map +1 -1
- package/dist/expr/parser.d.ts.map +1 -1
- package/dist/expr/parser.js +11 -4
- package/dist/expr/parser.js.map +1 -1
- package/dist/expr/tokenizer.d.ts.map +1 -1
- package/dist/expr/tokenizer.js +17 -13
- package/dist/expr/tokenizer.js.map +1 -1
- package/dist/expr.d.ts +2 -2
- package/dist/expr.d.ts.map +1 -1
- package/dist/expr.js +7 -9
- package/dist/expr.js.map +1 -1
- package/dist/generated/pricing-config.schema.json +30 -9
- package/dist/generated/pricing-config.types.d.ts +14 -3
- package/dist/generated/pricing-config.types.d.ts.map +1 -1
- package/dist/generated/pricing-config.types.js.map +1 -1
- package/dist/index.d.ts +11 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/integrations/better-auth.d.ts +23 -0
- package/dist/integrations/better-auth.d.ts.map +1 -0
- package/dist/integrations/better-auth.js +54 -0
- package/dist/integrations/better-auth.js.map +1 -0
- package/dist/{load-pricing-file.d.ts → load-config-file.d.ts} +4 -4
- package/dist/load-config-file.d.ts.map +1 -0
- package/dist/{load-pricing-file.js → load-config-file.js} +23 -14
- package/dist/load-config-file.js.map +1 -0
- package/dist/metrics.js.map +1 -1
- package/dist/node.d.ts +3 -3
- package/dist/node.d.ts.map +1 -1
- package/dist/node.js +2 -2
- package/dist/node.js.map +1 -1
- package/dist/providers/_shared.d.ts +5 -0
- package/dist/providers/_shared.d.ts.map +1 -1
- package/dist/providers/_shared.js +77 -14
- package/dist/providers/_shared.js.map +1 -1
- package/dist/providers/dodo/better-auth.d.ts +29 -0
- package/dist/providers/dodo/better-auth.d.ts.map +1 -0
- package/dist/providers/dodo/better-auth.js +23 -0
- package/dist/providers/dodo/better-auth.js.map +1 -0
- package/dist/providers/dodo/client-contract.d.ts +32 -70
- package/dist/providers/dodo/client-contract.d.ts.map +1 -1
- package/dist/providers/dodo/client-contract.js.map +1 -1
- package/dist/providers/dodo/event-mapper.d.ts +3 -1
- package/dist/providers/dodo/event-mapper.d.ts.map +1 -1
- package/dist/providers/dodo/event-mapper.js +219 -148
- package/dist/providers/dodo/event-mapper.js.map +1 -1
- package/dist/providers/dodo/index.d.ts +5 -2
- package/dist/providers/dodo/index.d.ts.map +1 -1
- package/dist/providers/dodo/index.js +2 -1
- package/dist/providers/dodo/index.js.map +1 -1
- package/dist/providers/dodo/nextjs.d.ts +16 -0
- package/dist/providers/dodo/nextjs.d.ts.map +1 -0
- package/dist/providers/dodo/nextjs.js +16 -0
- package/dist/providers/dodo/nextjs.js.map +1 -0
- package/dist/providers/dodo/provider.d.ts +30 -11
- package/dist/providers/dodo/provider.d.ts.map +1 -1
- package/dist/providers/dodo/provider.js +192 -122
- package/dist/providers/dodo/provider.js.map +1 -1
- package/dist/providers/dodo/react-native.d.ts +56 -0
- package/dist/providers/dodo/react-native.d.ts.map +1 -0
- package/dist/providers/dodo/react-native.js +57 -0
- package/dist/providers/dodo/react-native.js.map +1 -0
- package/dist/providers/dodo/webhook-bridge.d.ts +17 -0
- package/dist/providers/dodo/webhook-bridge.d.ts.map +1 -0
- package/dist/providers/dodo/webhook-bridge.js +21 -0
- package/dist/providers/dodo/webhook-bridge.js.map +1 -0
- package/dist/providers/index.d.ts +1 -1
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/mock/index.d.ts +1 -0
- package/dist/providers/mock/index.d.ts.map +1 -1
- package/dist/providers/mock/index.js.map +1 -1
- package/dist/providers/mock/provider.d.ts +8 -8
- package/dist/providers/mock/provider.d.ts.map +1 -1
- package/dist/providers/mock/provider.js +26 -19
- package/dist/providers/mock/provider.js.map +1 -1
- package/dist/providers/stripe/event-mapper.d.ts.map +1 -1
- package/dist/providers/stripe/event-mapper.js +214 -173
- package/dist/providers/stripe/event-mapper.js.map +1 -1
- package/dist/providers/stripe/index.d.ts +1 -0
- package/dist/providers/stripe/index.d.ts.map +1 -1
- package/dist/providers/stripe/index.js.map +1 -1
- package/dist/providers/stripe/provider.d.ts +13 -11
- package/dist/providers/stripe/provider.d.ts.map +1 -1
- package/dist/providers/stripe/provider.js +287 -107
- package/dist/providers/stripe/provider.js.map +1 -1
- package/dist/providers/types.d.ts +1 -2
- package/dist/providers/types.d.ts.map +1 -1
- package/dist/providers/types.js.map +1 -1
- package/dist/retry.d.ts +26 -4
- package/dist/retry.d.ts.map +1 -1
- package/dist/retry.js +65 -23
- package/dist/retry.js.map +1 -1
- package/dist/shared/diagnostics.d.ts +7 -0
- package/dist/shared/diagnostics.d.ts.map +1 -0
- package/dist/shared/diagnostics.js +18 -0
- package/dist/shared/diagnostics.js.map +1 -0
- package/dist/shared/logger.js.map +1 -1
- package/dist/shared/postgres-client.d.ts +43 -5
- package/dist/shared/postgres-client.d.ts.map +1 -1
- package/dist/shared/postgres-client.js +282 -30
- package/dist/shared/postgres-client.js.map +1 -1
- package/dist/shared/postgres-errors.d.ts +11 -0
- package/dist/shared/postgres-errors.d.ts.map +1 -0
- package/dist/shared/postgres-errors.js +105 -0
- package/dist/shared/postgres-errors.js.map +1 -0
- package/dist/shared/postgres-types.js.map +1 -1
- package/dist/shared/postgres-validation.d.ts +15 -3
- package/dist/shared/postgres-validation.d.ts.map +1 -1
- package/dist/shared/postgres-validation.js +58 -14
- package/dist/shared/postgres-validation.js.map +1 -1
- package/dist/storage/adapters/clickhouse.d.ts.map +1 -1
- package/dist/storage/adapters/clickhouse.js +18 -3
- package/dist/storage/adapters/clickhouse.js.map +1 -1
- package/dist/storage/adapters/s3.d.ts +0 -6
- package/dist/storage/adapters/s3.d.ts.map +1 -1
- package/dist/storage/adapters/s3.js +0 -2
- package/dist/storage/adapters/s3.js.map +1 -1
- package/dist/storage/outbox-worker.d.ts +2 -1
- package/dist/storage/outbox-worker.d.ts.map +1 -1
- package/dist/storage/outbox-worker.js +17 -3
- package/dist/storage/outbox-worker.js.map +1 -1
- package/dist/storage/ports.d.ts +1 -1
- package/dist/storage/ports.d.ts.map +1 -1
- package/dist/storage/ports.js.map +1 -1
- package/dist/storage/postgres-repository.d.ts +1 -1
- package/dist/storage/postgres-repository.d.ts.map +1 -1
- package/dist/storage/postgres-repository.js +13 -3
- package/dist/storage/postgres-repository.js.map +1 -1
- package/dist/storage/runtime.d.ts +35 -7
- package/dist/storage/runtime.d.ts.map +1 -1
- package/dist/storage/runtime.js +166 -53
- package/dist/storage/runtime.js.map +1 -1
- package/package.json +62 -7
- package/dist/credits/postgres/repositories/pricing.d.ts +0 -28
- package/dist/credits/postgres/repositories/pricing.d.ts.map +0 -1
- package/dist/credits/postgres/repositories/pricing.js +0 -70
- package/dist/credits/postgres/repositories/pricing.js.map +0 -1
- package/dist/credits/pricing-runtime.d.ts.map +0 -1
- package/dist/credits/pricing-runtime.js.map +0 -1
- package/dist/load-pricing-file.d.ts.map +0 -1
- package/dist/load-pricing-file.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"financial-event-handlers.js","sourceRoot":"","sources":["../../src/billing/financial-event-handlers.ts"],"names":[],"mappings":"AAgBA,MAAM,OAAO,6BAA6B;IAErB;IACA;IACA;IACA;IACA;IAGA;IAIA;IAGA;IAfnB,YACmB,KAAmB,EACnB,MAAwB,EACxB,oBAA4B,EAC5B,aAA8D,EAC9D,yBAEe,EACf,6BAGC,EACD,uBAE4B,EAC5B,sBAKY;QAnBZ,UAAK,GAAL,KAAK,CAAc;QACnB,WAAM,GAAN,MAAM,CAAkB;QACxB,yBAAoB,GAApB,oBAAoB,CAAQ;QAC5B,kBAAa,GAAb,aAAa,CAAiD;QAC9D,8BAAyB,GAAzB,yBAAyB,CAEV;QACf,kCAA6B,GAA7B,6BAA6B,CAG5B;QACD,4BAAuB,GAAvB,uBAAuB,CAEK;QAC5B,2BAAsB,GAAtB,sBAAsB,CAKV;IAC5B,CAAC;IAEJ,KAAK,CAAC,iBAAiB,CAAC,KAAmB;QACzC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,oCAAoC,EAAE;YACrD,QAAQ,EAAE,KAAK,CAAC,QAAQ;YACxB,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,SAAS,EAAE,KAAK,CAAC,OAAO,EAAE,iBAAiB;SAC5C,CAAC,CAAC;QACH,MAAM,aAAa,GAAG,KAAK,CAAC,YAAY;YACtC,CAAC,CAAC,MAAM,IAAI,CAAC,yBAAyB,CAAC,KAAK,CAAC;YAC7C,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,cAAc,EAAE,CAAC;QAC9C,IAAI,CAAC,aAAa,CAAC,OAAO;YAAE,OAAO,aAAa,CAAC;QACjD,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;YAClB,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;YAC5C,IAAI,GAAG,EAAE,CAAC;gBACR,MA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,OAAO,CAAC,iBAAiB;gBAClD,iBAAiB,EAAE,KAAK,CAAC,OAAO,CAAC,iBAAiB;gBAClD,MAAM,EAAE,GAAG;gBACX,MAAM,EAAE,gBAAgB;gBACxB,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,MAAM;gBAC5B,QAAQ,EAAE,KAAK,CAAC,QAAQ;gBACxB,iBAAiB,EAAE,KAAK,CAAC,UAAU;aACpC,CAAC,CAAC;QACL,CAAC;QACD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,kBAAkB,EAAE,CAAC;IACvD,CAAC;IAED,KAAK,CAAC,mBAAmB,CAAC,KAAmB;QAC3C,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QAC5C,IAAI,GAAG,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;YACzB,MAAM,IAAI,CAAC,KAAK,CAAC,oBAAoB,CAAC;gBACpC,QAAQ,EAAE,KAAK,CAAC,QAAQ;gBACxB,iBAAiB,EAAE,KAAK,CAAC,OAAO,CAAC,iBAAiB;gBAClD,iBAAiB,EAAE,KAAK,CAAC,OAAO,CAAC,iBAAiB;gBAClD,MAAM,EAAE,GAAG;gBACX,MAAM,EAAE,QAAQ;gBAChB,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,MAAM;gBAC5B,QAAQ,EAAE,KAAK,CAAC,QAAQ;gBACxB,iBAAiB,EAAE,KAAK,CAAC,UAAU;aACpC,CAAC,CAAC;QACL,CAAC;QACD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,gBAAgB,EAAE,CAAC;IACrD,CAAC;CACF"}
|
|
1
|
+
{"version":3,"file":"financial-event-handlers.js","sourceRoot":"","sources":["../../src/billing/financial-event-handlers.ts"],"names":[],"mappings":"AAgBA,MAAM,OAAO,6BAA6B;IAErB;IACA;IACA;IACA;IACA;IAGA;IAIA;IAGA;IAfnB,YACmB,KAAmB,EACnB,MAAw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ACpC,CAAC,CAAC;QACH,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,kBAAkB,EAAE,CAAC;IACvD,CAAC;IAED,KAAK,CAAC,mBAAmB,CAAC,KAAmB;QAC3C,IAAI,CAAC,KAAK,CAAC,OAAO;YAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,iBAAiB,EAAE,CAAC;QACxE,MAAM,IAAI,CAAC,KAAK,CAAC,oBAAoB,CAAC;YACpC,QAAQ,EAAE,KAAK,CAAC,QAAQ;YACxB,iBAAiB,EAAE,KAAK,CAAC,OAAO,CAAC,iBAAiB;YAClD,iBAAiB,EAAE,KAAK,CAAC,OAAO,CAAC,iBAAiB;YAClD,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,MAAM;YAC5B,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,MAAM;YAC5B,QAAQ,EAAE,KAAK,CAAC,QAAQ;YACxB,iBAAiB,EAAE,KAAK,CAAC,UAAU;SACpC,CAAC,CAAC;QACH,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,gBAAgB,EAAE,CAAC;IACrD,CAAC;CACF","sourcesContent":["import type { NormalizedLogger } from \"../shared/logger.js\";\nimport type { BillingStore } from \"./billing-store.js\";\nimport type {\n BillingEvent,\n BillingEventResult,\n BillingSubscriptionState,\n BillingSubscriptionStatus,\n BillingTopupResult,\n} from \"./types/index.js\";\n\nexport interface FinancialSubscriptionOverrides {\n status?: BillingSubscriptionStatus | null;\n graceEndsAt?: string | null;\n graceExpiredAt?: string | null;\n}\n\nexport class BillingFinancialEventHandlers {\n constructor(\n private readonly store: BillingStore,\n private readonly logger: NormalizedLogger,\n private readonly pastDueGracePeriodMs: number,\n private readonly resolveUserId: (event: BillingEvent) => Promise<string | null>,\n private readonly handleSubscriptionRenewed: (\n event: BillingEvent,\n ) => Promise<BillingEventResult>,\n private readonly updateCheckoutIntentFromEvent: (\n event: BillingEvent,\n status: \"completed\" | \"failed\" | \"expired\",\n ) => Promise<void>,\n private readonly getExistingSubscription: (\n event: BillingEvent,\n ) => Promise<BillingSubscriptionState | null>,\n private readonly buildSubscriptionState: (\n event: BillingEvent,\n userId: string,\n existing: BillingSubscriptionState | null,\n overrides?: FinancialSubscriptionOverrides,\n ) => BillingSubscriptionState,\n ) {}\n\n async handleInvoicePaid(event: BillingEvent): Promise<BillingEventResult> {\n this.logger.info(\"[BillingService] handleInvoicePaid\", {\n provider: event.provider,\n eventId: event.eventId,\n invoiceId: event.invoice?.providerInvoiceId,\n });\n if (!event.invoice) return { handled: false, error: \"no_invoice_data\" };\n const renewalResult = event.subscription\n ? await this.handleSubscriptionRenewed(event)\n : { handled: true, action: \"invoice_paid\" };\n if (!renewalResult.handled) return renewalResult;\n const uid = await this.resolveUserId(event);\n if (uid) {\n await this.store.upsertBillingInvoice({\n provider: event.provider,\n providerInvoiceId: event.invoice.providerInvoiceId,\n providerSubscriptionId: event.subscription?.providerSubscriptionId,\n userId: uid,\n status: event.invoice.status,\n amountPaidMinor: event.invoice.amountPaidMinor,\n amountDueMinor: event.invoice.amountDueMinor,\n currency: event.invoice.currency,\n periodStart: event.invoice.periodStart,\n periodEnd: event.invoice.periodEnd,\n metadata: event.metadata,\n providerUpdatedAt: event.occurredAt,\n });\n }\n return renewalResult;\n }\n\n async handlePaymentSucceeded(event: BillingEvent): Promise<BillingEventResult> {\n this.logger.info(\"[BillingService] handlePaymentSucceeded\", {\n provider: event.provider,\n eventId: event.eventId,\n amountMinor: event.payment?.amountMinor,\n });\n if (!event.payment) return { handled: false, error: \"no_payment_data\" };\n\n const uid = await this.resolveUserId(event);\n const refs = event.payment.refs;\n let topupConfig: BillingTopupResult | null = null;\n if (refs) {\n topupConfig = await this.store.resolveCreditTopup(\n event.provider,\n refs.productId ?? null,\n refs.priceId ?? null,\n );\n }\n\n let paymentId: string | null = null;\n if (uid) {\n const paymentMetadata: Record<string, unknown> | null =\n topupConfig && event.payment.purpose === \"credit_topup\"\n ? { credits_per_unit: topupConfig.creditsPerUnit.toString() }\n : null;\n paymentId = await this.store.upsertBillingPayment({\n provider: event.provider,\n providerPaymentId: event.payment.providerPaymentId,\n userId: uid,\n amountMinor: event.payment.amountMinor,\n taxMinor: event.payment.taxMinor,\n currency: event.payment.currency,\n purpose: event.payment.purpose,\n status: event.payment.status,\n providerUpdatedAt: event.occurredAt,\n metadata: paymentMetadata,\n });\n\n // Dodo represents subscription receipts as payment.succeeded events,\n // while Stripe emits invoice.paid. Materialize the Dodo payment as a\n // paid invoice so invoice history is provider-agnostic.\n if (event.payment.purpose === \"subscription\" && event.subscription) {\n const renewalResult = await this.handleSubscriptionRenewed(event);\n if (!renewalResult.handled) return renewalResult;\n await this.store.upsertBillingInvoice({\n provider: event.provider,\n providerInvoiceId: event.payment.providerPaymentId,\n providerSubscriptionId: event.subscription.providerSubscriptionId,\n userId: uid,\n status: \"paid\",\n amountPaidMinor: event.payment.amountMinor,\n amountDueMinor: event.payment.amountMinor,\n currency: event.payment.currency,\n periodStart: event.subscription.periodStart,\n periodEnd: event.subscription.periodEnd,\n metadata: event.metadata,\n providerUpdatedAt: event.occurredAt,\n });\n }\n }\n\n if (topupConfig && event.payment.purpose === \"credit_topup\" && uid) {\n if (\n event.payment.amountMinor < topupConfig.minAmountMinor ||\n event.payment.amountMinor > topupConfig.maxAmountMinor\n ) {\n this.logger.warn(\n `[BillingService] topup amount ${event.payment.amountMinor} exceeds cap ${topupConfig.maxAmountMinor} for topup key ${topupConfig.topupKey} (user ${uid})`,\n );\n return { handled: true, action: \"payment_succeeded_out_of_bounds\" };\n }\n const credits = await this.store.computeTopupCredits(event.payment.amountMinor, topupConfig);\n const quantity =\n topupConfig.amountMinor <= 0 ? 0 : event.payment.amountMinor / topupConfig.amountMinor;\n if (\n credits.gt(0) &&\n paymentId &&\n Number.isSafeInteger(quantity) &&\n topupConfig.creditsPerUnit.gt(0)\n ) {\n const grantId = await this.store.createBillingCreditGrant({\n paymentId,\n topupId: topupConfig.topupId,\n configuredCredits: topupConfig.creditsPerUnit,\n quantity,\n });\n await this.store.grantBillingCredit(grantId, `billing:${event.eventId}:topup`);\n }\n await this.store.updateAutoRechargeAttemptByProviderPayment({\n provider: event.provider,\n providerPaymentId: event.payment.providerPaymentId,\n state: \"succeeded\",\n });\n }\n\n await this.updateCheckoutIntentFromEvent(event, \"completed\");\n\n return { handled: true, action: \"payment_succeeded\" };\n }\n\n async handlePaymentFailed(event: BillingEvent): Promise<BillingEventResult> {\n this.logger.info(\"[BillingService] handlePaymentFailed\", {\n provider: event.provider,\n eventId: event.eventId,\n });\n if (!event.payment) return { handled: false, error: \"no_payment_data\" };\n const uid = await this.resolveUserId(event);\n if (uid) {\n await this.store.upsertBillingPayment({\n provider: event.provider,\n providerPaymentId: event.payment.providerPaymentId,\n userId: uid,\n amountMinor: event.payment.amountMinor,\n taxMinor: event.payment.taxMinor,\n currency: event.payment.currency,\n purpose: event.payment.purpose,\n status: event.payment.status,\n providerUpdatedAt: event.occurredAt,\n });\n }\n if (uid && event.subscription) {\n const existing = await this.getExistingSubscription(event);\n const occurredAt = new Date(event.occurredAt);\n if (Number.isNaN(occurredAt.getTime())) {\n throw new TypeError(\"billing event occurredAt must be a valid instant\");\n }\n const pastDue = this.buildSubscriptionState(event, uid, existing, {\n status: \"past_due\",\n graceEndsAt: new Date(occurredAt.getTime() + this.pastDueGracePeriodMs).toISOString(),\n graceExpiredAt: null,\n });\n await this.store.upsertBillingSubscription(pastDue);\n }\n await this.store.updateAutoRechargeAttemptByProviderPayment({\n provider: event.provider,\n providerPaymentId: event.payment.providerPaymentId,\n state: \"failed\",\n failureCode: \"provider_payment_failed\",\n });\n await this.updateCheckoutIntentFromEvent(event, \"failed\");\n return { handled: true, action: \"payment_failed_recorded\" };\n }\n\n async handleRefundCreated(event: BillingEvent): Promise<BillingEventResult> {\n if (!event.refund) return { handled: false, error: \"no_refund_data\" };\n const uid = await this.resolveUserId(event);\n if (uid) {\n const refundId = await this.store.upsertBillingRefund({\n provider: event.provider,\n providerRefundId: event.refund.providerRefundId,\n providerPaymentId: event.refund.providerPaymentId,\n userId: uid,\n amountMinor: event.refund.amountMinor,\n currency: event.refund.currency,\n reason: event.refund.reason,\n status: event.refund.status,\n providerUpdatedAt: event.occurredAt,\n metadata: event.metadata,\n });\n if (event.refund.status === \"succeeded\") {\n const payment = await this.store.getBillingPayment(\n event.provider,\n event.refund.providerPaymentId,\n );\n\n if (payment?.purpose === \"credit_topup\" && payment.id) {\n const grantId = await this.store.getBillingCreditGrantByPayment(String(payment.id));\n if (grantId) {\n const result = await this.store.postBillingRefund(\n refundId,\n grantId,\n event.refund.amountMinor,\n `billing:${event.eventId}:refund`,\n );\n if (!result.errorCode) return { handled: true, action: \"refund_clawback\" };\n }\n }\n }\n }\n return { handled: true, action: \"refund_recorded\" };\n }\n\n async handleDisputeCreated(event: BillingEvent): Promise<BillingEventResult> {\n if (!event.dispute) return { handled: false, error: \"no_dispute_data\" };\n await this.store.upsertBillingDispute({\n provider: event.provider,\n providerDisputeId: event.dispute.providerDisputeId,\n providerPaymentId: event.dispute.providerPaymentId,\n status: event.dispute.status,\n reason: event.dispute.reason,\n metadata: event.metadata,\n providerUpdatedAt: event.occurredAt,\n });\n return { handled: true, action: \"dispute_recorded\" };\n }\n\n async handleDisputeClosed(event: BillingEvent): Promise<BillingEventResult> {\n if (!event.dispute) return { handled: false, error: \"no_dispute_data\" };\n await this.store.upsertBillingDispute({\n provider: event.provider,\n providerDisputeId: event.dispute.providerDisputeId,\n providerPaymentId: event.dispute.providerPaymentId,\n status: event.dispute.status,\n reason: event.dispute.reason,\n metadata: event.metadata,\n providerUpdatedAt: event.occurredAt,\n });\n return { handled: true, action: \"dispute_closed\" };\n }\n}\n"]}
|
package/dist/billing/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
export { BillingStore } from "./billing-store.js";
|
|
2
2
|
export { PostgresBillingStore } from "./postgres/store.js";
|
|
3
|
+
export type { PostgresBillingStoreOptions } from "./postgres/store.js";
|
|
3
4
|
export { BillingService } from "./billing-service.js";
|
|
4
5
|
export type { BillingServiceOptions, BillingProvisioningPort } from "./billing-service.js";
|
|
5
6
|
export type { AutoRechargeAttemptClaim, AutoRechargeAttemptUpdate, AutoRechargeProviderPaymentUpdate, BillingCreditGrantCreate, BillingDisputeUpsert, BillingEventSink, BillingInvoiceUpsert, BillingPaymentUpsert, BillingRefundUpsert, BillingSubscriptionChangeUpdate, BillingSubscriptionConflictCreate, CheckoutIntentCreate, CheckoutIntentUpdate, } from "./contracts.js";
|
|
6
7
|
export { AUTO_RECHARGE_STATES, BillingEventType } from "./types/index.js";
|
|
7
8
|
export { AutoRechargeService } from "./auto-recharge-service.js";
|
|
8
9
|
export type { AutoRechargeOutcome, AutoRechargeProcessResult } from "./auto-recharge-service.js";
|
|
9
|
-
export type { BillingAutoRechargeAttempt, BillingAutoRechargeProfile, BillingAutoRechargeStatus,
|
|
10
|
+
export type { BillingAutoRechargeAttempt, BillingAutoRechargeAttemptState, BillingAutoRechargeProfile, BillingAutoRechargeStatus, BillingCreditPostingResult, BillingCustomerInfo, BillingCustomerRecord, BillingDisputeInfo, BillingEvent, BillingEventClaim, BillingEventHandler, BillingEventResult, BillingInvoiceInfo, BillingInvoiceRecord, BillingOfferInterval, BillingPaymentInfo, BillingPaymentRecord, BillingPreferences, BillingRefundInfo, BillingSubscriptionInfo, BillingSubscriptionChange, BillingSubscriptionChangeInput, BillingSubscriptionOfferContext, BillingSubscriptionChangeState, BillingSubscriptionState, BillingSubscriptionStatus, CheckoutIntent, CheckoutIntentStatus, EntitlementMode, ProviderRef, SubscriptionGrant, } from "./types/index.js";
|
|
10
11
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/billing/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAA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AE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,YAAY,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AAEjG,YAAY,EACV,0BAA0B,EAC1B,+BAA+B,EAC/B,0BAA0B,EAC1B,yBAAyB,EACzB,0BAA0B,EAC1B,mBAAmB,EACnB,qBAAqB,EACrB,kBAAkB,EAClB,YAAY,EACZ,iBAAiB,EACjB,mBAAmB,EACnB,kBAAkB,EAClB,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,EAClB,oBAAoB,EACpB,kBAAkB,EAClB,iBAAiB,EACjB,uBAAuB,EACvB,yBAAyB,EACzB,8BAA8B,EAC9B,+BAA+B,EAC/B,8BAA8B,EAC9B,wBAAwB,EACxB,yBAAyB,EACzB,cAAc,EACd,oBAAoB,EACpB,eAAe,EACf,WAAW,EACX,iBAAiB,GAClB,MAAM,kBAAkB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/billing/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/billing/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAE3D,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAkBtD,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC","sourcesContent":["export { BillingStore } from \"./billing-store.js\";\nexport { PostgresBillingStore } from \"./postgres/store.js\";\nexport type { PostgresBillingStoreOptions } from \"./postgres/store.js\";\nexport { BillingService } from \"./billing-service.js\";\nexport type { BillingServiceOptions, BillingProvisioningPort } from \"./billing-service.js\";\nexport type {\n AutoRechargeAttemptClaim,\n AutoRechargeAttemptUpdate,\n AutoRechargeProviderPaymentUpdate,\n BillingCreditGrantCreate,\n BillingDisputeUpsert,\n BillingEventSink,\n BillingInvoiceUpsert,\n BillingPaymentUpsert,\n BillingRefundUpsert,\n BillingSubscriptionChangeUpdate,\n BillingSubscriptionConflictCreate,\n CheckoutIntentCreate,\n CheckoutIntentUpdate,\n} from \"./contracts.js\";\n\nexport { AUTO_RECHARGE_STATES, BillingEventType } from \"./types/index.js\";\nexport { AutoRechargeService } from \"./auto-recharge-service.js\";\nexport type { AutoRechargeOutcome, AutoRechargeProcessResult } from \"./auto-recharge-service.js\";\n\nexport type {\n BillingAutoRechargeAttempt,\n BillingAutoRechargeAttemptState,\n BillingAutoRechargeProfile,\n BillingAutoRechargeStatus,\n BillingCreditPostingResult,\n BillingCustomerInfo,\n BillingCustomerRecord,\n BillingDisputeInfo,\n BillingEvent,\n BillingEventClaim,\n BillingEventHandler,\n BillingEventResult,\n BillingInvoiceInfo,\n BillingInvoiceRecord,\n BillingOfferInterval,\n BillingPaymentInfo,\n BillingPaymentRecord,\n BillingPreferences,\n BillingRefundInfo,\n BillingSubscriptionInfo,\n BillingSubscriptionChange,\n BillingSubscriptionChangeInput,\n BillingSubscriptionOfferContext,\n BillingSubscriptionChangeState,\n BillingSubscriptionState,\n BillingSubscriptionStatus,\n CheckoutIntent,\n CheckoutIntentStatus,\n EntitlementMode,\n ProviderRef,\n SubscriptionGrant,\n} from \"./types/index.js\";\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { BillingStore } from "./billing-store.js";
|
|
2
|
-
import type { BillingAutoRechargeAttempt, BillingAutoRechargeProfile, BillingCustomerRecord, BillingOfferResult, BillingPreferences, BillingSubscriptionChange, BillingSubscriptionChangeInput, BillingSubscriptionState, BillingTopupResult, CheckoutIntent } from "./types/index.js";
|
|
2
|
+
import type { BillingAutoRechargeAttempt, BillingAutoRechargeAttemptState, BillingAutoRechargeProfile, BillingCustomerRecord, BillingOfferResult, BillingPreferences, BillingSubscriptionChange, BillingSubscriptionChangeInput, BillingSubscriptionState, BillingTopupResult, CheckoutIntent } from "./types/index.js";
|
|
3
3
|
/**
|
|
4
4
|
* Public billing reads and commands that delegate directly to BillingStore.
|
|
5
5
|
*
|
|
@@ -14,7 +14,7 @@ export declare class BillingManagement {
|
|
|
14
14
|
getCheckoutIntent(id: string, subjectId: string): Promise<CheckoutIntent | null>;
|
|
15
15
|
getActiveSubscription(userId: string): Promise<BillingSubscriptionState | null>;
|
|
16
16
|
getUserPreferences(userId: string): Promise<BillingPreferences | null>;
|
|
17
|
-
listBillingInvoices(userId: string): Promise<import("./contracts.js").
|
|
17
|
+
listBillingInvoices(userId: string): Promise<import("./contracts.js").BillingInvoiceRecord[]>;
|
|
18
18
|
upsertBillingSubscription(state: BillingSubscriptionState): Promise<void>;
|
|
19
19
|
createBillingSubscriptionChange(input: BillingSubscriptionChangeInput): Promise<BillingSubscriptionChange>;
|
|
20
20
|
getOpenBillingSubscriptionChange(provider: string, providerSubscriptionId: string): Promise<BillingSubscriptionChange | null>;
|
|
@@ -22,7 +22,7 @@ export declare class BillingManagement {
|
|
|
22
22
|
recordSubscriptionConflict(input: Parameters<BillingStore["recordSubscriptionConflict"]>[0]): Promise<void>;
|
|
23
23
|
updateUserPreferences(preferences: BillingPreferences): Promise<void>;
|
|
24
24
|
getAutoRechargeProfile(userId: string): Promise<BillingAutoRechargeProfile | null>;
|
|
25
|
-
|
|
25
|
+
getActiveCatalogDocument(): Promise<Record<string, unknown> | null>;
|
|
26
26
|
listCancellableProviderSubscriptionIds(userId: string): Promise<string[]>;
|
|
27
27
|
listCancellableSubscriptions(userId: string): Promise<BillingSubscriptionState[]>;
|
|
28
28
|
pseudonymizeFinancialSubject(userId: string): Promise<void>;
|
|
@@ -35,7 +35,7 @@ export declare class BillingManagement {
|
|
|
35
35
|
}): Promise<BillingAutoRechargeAttempt | null>;
|
|
36
36
|
updateAutoRechargeAttempt(input: {
|
|
37
37
|
id: string;
|
|
38
|
-
state:
|
|
38
|
+
state: BillingAutoRechargeAttemptState;
|
|
39
39
|
providerAttemptId?: string | null;
|
|
40
40
|
failureCode?: string | null;
|
|
41
41
|
failureMessage?: string | null;
|
|
@@ -44,7 +44,7 @@ export declare class BillingManagement {
|
|
|
44
44
|
updateAutoRechargeAttemptByProviderPayment(input: {
|
|
45
45
|
provider: string;
|
|
46
46
|
providerPaymentId: string;
|
|
47
|
-
state:
|
|
47
|
+
state: BillingAutoRechargeAttemptState;
|
|
48
48
|
failureCode?: string | null;
|
|
49
49
|
failureMessage?: string | null;
|
|
50
50
|
}): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"management.d.ts","sourceRoot":"","sources":["../../src/billing/management.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EACV,0BAA0B,EAC1B,0BAA0B,EAC1B,qBAAqB,EACrB,kBAAkB,EAClB,kBAAkB,EAClB,yBAAyB,EACzB,8BAA8B,EAC9B,wBAAwB,EAExB,kBAAkB,EAClB,cAAc,EACf,MAAM,kBAAkB,CAAC;AAG1B;;;;;GAKG;AACH,qBAAa,iBAAiB;IAChB,OAAO,CAAC,QAAQ,CAAC,KAAK;gBAAL,KAAK,EAAE,YAAY;IAE1C,yBAAyB,CAAC,KAAK,EAAE,UAAU,CAAC,YAAY,CAAC,2BAA2B,CAAC,CAAC,CAAC,CAAC,CAAC;IAIzF,oBAAoB,CACxB,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,UAAU,CAAC,YAAY,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC,CAAC,GA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
52
52
|
async getAutoRechargeProfile(userId) {
|
|
53
53
|
return this.store.getAutoRechargeProfile(userId);
|
|
54
54
|
}
|
|
55
|
-
async
|
|
56
|
-
return this.store.
|
|
55
|
+
async getActiveCatalogDocument() {
|
|
56
|
+
return this.store.getActiveCatalogDocument();
|
|
57
57
|
}
|
|
58
58
|
async listCancellableProviderSubscriptionIds(userId) {
|
|
59
59
|
const subscriptions = await this.listCancellableSubscriptions(userId);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"management.js","sourceRoot":"","sources":["../../src/billing/management.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAEvD;;;;;GAKG;AACH,MAAM,OAAO,iBAAiB;IACC;IAA7B,YAA6B,KAAmB;QAAnB,UAAK,GAAL,KAAK,CAAc;IAAG,CAAC;IAEpD,KAAK,CAAC,yBAAyB,CAAC,KAA+D;QAC7F,OAAO,IAAI,CAAC,KAAK,CAAC,yBAAyB,CAAC,KAAK,CAAC,CAAC;IACrD,CAAC;IAED,KAAK,CAAC,oBAAoB,CACxB,EAAU,EACV,MAA2D;QAE3D,MAAM,IAAI,CAAC,KAAK,CAAC,oBAAoB,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;IACpD,CAAC;IAED,KAAK,CAAC,iBAAiB,CAAC,EAAU,EAAE,SAAiB;QACnD,OAAO,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC,EAAE,EAAE,SAAS,CAAC,CAAC;IACrD,CAAC;IAED,KAAK,CAAC,qBAAqB,CAAC,MAAc;QACxC,OAAO,IAAI,CAAC,KAAK,CAAC,mBAAmB,CAAC,MAAM,EAAE;YAC5C,mBAAmB,CAAC,MAAM;YAC1B,mBAAmB,CAAC,QAAQ;SAC7B,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,kBAAkB,CAAC,MAAc;QACrC,OAAO,IAAI,CAAC,KAAK,CAAC,qBAAqB,CAAC,MAAM,CAAC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,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IACjE,CAAC;IAED,KAAK,CAAC,YAAY,CAChB,QAAgB,EAChB,SAAyB,EACzB,OAAuB;QAEvB,OAAO,IAAI,CAAC,KAAK,CAAC,mBAAmB,CAAC,QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;IACtE,CAAC;IAED,KAAK,CAAC,oBAAoB,CACxB,QAAgB,EAChB,SAAiB;QAEjB,OAAO,IAAI,CAAC,KAAK,CAAC,2BAA2B,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;IACrE,CAAC;IAED,KAAK,CAAC,YAAY,CAChB,QAAgB,EAChB,SAAyB,EACzB,OAAuB;QAEvB,OAAO,IAAI,CAAC,KAAK,CAAC,kBAAkB,CAAC,QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;IACrE,CAAC;IAED,KAAK,CAAC,oBAAoB,CACxB,QAAgB,EAChB,SAAiB;QAEjB,OAAO,IAAI,CAAC,KAAK,CAAC,0BAA0B,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;IACpE,CAAC;IAED,KAAK,CAAC,cAAc,CAClB,QAAgB,EAChB,kBAA0B,EAC1B,MAAc,EACd,KAAqB;QAErB,MAAM,IAAI,CAAC,KAAK,CAAC,qBAAqB,CAAC,QAAQ,EAAE,kBAAkB,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IACtF,CAAC;CACF","sourcesContent":["import type { BillingStore } from \"./billing-store.js\";\nimport type {\n BillingAutoRechargeAttempt,\n BillingAutoRechargeAttemptState,\n BillingAutoRechargeProfile,\n BillingCustomerRecord,\n BillingOfferResult,\n BillingPreferences,\n BillingSubscriptionChange,\n BillingSubscriptionChangeInput,\n BillingSubscriptionState,\n BillingSubscriptionStatus,\n BillingTopupResult,\n CheckoutIntent,\n} from \"./types/index.js\";\nimport { SUBSCRIPTION_STATUS } from \"./types/index.js\";\n\n/**\n * Public billing reads and commands that delegate directly to BillingStore.\n *\n * Webhook lifecycle orchestration lives in BillingService; this class keeps\n * the stable facade surface separate from that state machine.\n */\nexport class BillingManagement {\n constructor(private readonly store: BillingStore) {}\n\n async createOrGetCheckoutIntent(input: Parameters<BillingStore[\"createOrGetCheckoutIntent\"]>[0]) {\n return this.store.createOrGetCheckoutIntent(input);\n }\n\n async updateCheckoutIntent(\n id: string,\n update: Parameters<BillingStore[\"updateCheckoutIntent\"]>[1],\n ): Promise<void> {\n await this.store.updateCheckoutIntent(id, update);\n }\n\n async getCheckoutIntent(id: string, subjectId: string): Promise<CheckoutIntent | null> {\n return this.store.getCheckoutIntent(id, subjectId);\n }\n\n async getActiveSubscription(userId: string): Promise<BillingSubscriptionState | null> {\n return this.store.getUserSubscription(userId, [\n SUBSCRIPTION_STATUS.ACTIVE,\n SUBSCRIPTION_STATUS.TRIALING,\n ]);\n }\n\n async getUserPreferences(userId: string): Promise<BillingPreferences | null> {\n return this.store.getBillingPreferences(userId);\n }\n\n async listBillingInvoices(userId: string) {\n return this.store.listBillingInvoices(userId);\n }\n\n async upsertBillingSubscription(state: BillingSubscriptionState): Promise<void> {\n await this.store.upsertBillingSubscription(state);\n }\n\n async createBillingSubscriptionChange(\n input: BillingSubscriptionChangeInput,\n ): Promise<BillingSubscriptionChange> {\n return this.store.createBillingSubscriptionChange(input);\n }\n\n async getOpenBillingSubscriptionChange(\n provider: string,\n providerSubscriptionId: string,\n ): Promise<BillingSubscriptionChange | null> {\n return this.store.getOpenBillingSubscriptionChange(provider, providerSubscriptionId);\n }\n\n async updateBillingSubscriptionChange(\n id: string,\n update: Parameters<BillingStore[\"updateBillingSubscriptionChange\"]>[1],\n ): Promise<void> {\n await this.store.updateBillingSubscriptionChange(id, update);\n }\n\n async recordSubscriptionConflict(\n input: Parameters<BillingStore[\"recordSubscriptionConflict\"]>[0],\n ): Promise<void> {\n await this.store.recordSubscriptionConflict(input);\n }\n\n async updateUserPreferences(preferences: BillingPreferences): Promise<void> {\n await this.store.upsertBillingPreferences(preferences);\n }\n\n async getAutoRechargeProfile(userId: string): Promise<BillingAutoRechargeProfile | null> {\n return this.store.getAutoRechargeProfile(userId);\n }\n\n async getActiveCatalogDocument(): Promise<Record<string, unknown> | null> {\n return this.store.getActiveCatalogDocument();\n }\n\n async listCancellableProviderSubscriptionIds(userId: string): Promise<string[]> {\n const subscriptions = await this.listCancellableSubscriptions(userId);\n return subscriptions.map((subscription) => subscription.providerSubscriptionId);\n }\n\n async listCancellableSubscriptions(userId: string): Promise<BillingSubscriptionState[]> {\n const cancellableStatuses = new Set<BillingSubscriptionStatus>([\n SUBSCRIPTION_STATUS.ACTIVE,\n SUBSCRIPTION_STATUS.TRIALING,\n SUBSCRIPTION_STATUS.PAST_DUE,\n SUBSCRIPTION_STATUS.INCOMPLETE,\n SUBSCRIPTION_STATUS.UNPAID,\n SUBSCRIPTION_STATUS.PAUSED,\n ]);\n const subscriptions = await this.store.getUserSubscriptions(userId);\n return subscriptions.filter(\n (subscription) =>\n subscription.status != null &&\n cancellableStatuses.has(subscription.status) &&\n Boolean(subscription.providerSubscriptionId),\n );\n }\n\n async pseudonymizeFinancialSubject(userId: string): Promise<void> {\n await this.store.pseudonymizeFinancialSubject(userId);\n }\n\n async upsertAutoRechargeProfile(\n profile: BillingAutoRechargeProfile,\n options?: { resetCooldown?: boolean },\n ): Promise<void> {\n return this.store.upsertAutoRechargeProfile(profile, options);\n }\n\n async claimAutoRechargeAttempt(input: {\n userId: string;\n idempotencyKey: string;\n }): Promise<BillingAutoRechargeAttempt | null> {\n return this.store.claimAutoRechargeAttempt(input);\n }\n\n async updateAutoRechargeAttempt(input: {\n id: string;\n state: BillingAutoRechargeAttemptState;\n providerAttemptId?: string | null;\n failureCode?: string | null;\n failureMessage?: string | null;\n metadata?: Record<string, unknown>;\n }): Promise<void> {\n return this.store.updateAutoRechargeAttempt(input);\n }\n\n async updateAutoRechargeAttemptByProviderPayment(input: {\n provider: string;\n providerPaymentId: string;\n state: BillingAutoRechargeAttemptState;\n failureCode?: string | null;\n failureMessage?: string | null;\n }): Promise<void> {\n return this.store.updateAutoRechargeAttemptByProviderPayment(input);\n }\n\n async countAutoRechargeAttempts(userId: string, since: string | Date): Promise<number> {\n return this.store.countAutoRechargeAttempts(userId, since);\n }\n\n async getCustomerByUserId(\n userId: string,\n provider?: string | null,\n ): Promise<BillingCustomerRecord | null> {\n return this.store.getBillingCustomerByUserId(userId, provider);\n }\n\n async resolveOffer(\n provider: string,\n productId?: string | null,\n priceId?: string | null,\n ): Promise<BillingOfferResult | null> {\n return this.store.resolveBillingOffer(provider, productId, priceId);\n }\n\n async resolveOfferByLookup(\n provider: string,\n lookupKey: string,\n ): Promise<BillingOfferResult | null> {\n return this.store.resolveBillingOfferByLookup(provider, lookupKey);\n }\n\n async resolveTopup(\n provider: string,\n productId?: string | null,\n priceId?: string | null,\n ): Promise<BillingTopupResult | null> {\n return this.store.resolveCreditTopup(provider, productId, priceId);\n }\n\n async resolveTopupByLookup(\n provider: string,\n lookupKey: string,\n ): Promise<BillingTopupResult | null> {\n return this.store.resolveCreditTopupByLookup(provider, lookupKey);\n }\n\n async upsertCustomer(\n provider: string,\n providerCustomerId: string,\n userId: string,\n email?: string | null,\n ): Promise<void> {\n await this.store.upsertBillingCustomer(provider, providerCustomerId, userId, email);\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"policy-window.js","sourceRoot":"","sources":["../../src/billing/policy-window.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAIjD,MAAM,oBAAoB,GAAG,UAAU,CAAC;AACxC,MAAM,eAAe,GAAG,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;AAC9D,MAAM,WAAW,GAAG,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;AAc1D,SAAS,YAAY,CACnB,GAA2B,EAC3B,IAA0E,EAC1E,KAAa;IAEb,QAAQ,IAAI,EAAE,CA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AQ,CAAC,KAAK;YAC5B,MAAM,EAAE,SAAS;YACjB,QAAQ;YACR,KAAK,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC,QAAQ,EAAE;YACnC,GAAG,EAAE,GAAG,CAAC,SAAS,EAAE,CAAC,QAAQ,EAAE;YAC/B,YAAY,EACV,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC,iBAAiB,GAAG,KAAK,CAAC,SAAS,EAAE,CAAC,iBAAiB,CAAC;gBACzE,oBAAoB;SACvB,CAAC;IACJ,CAAC;IAED,MAAM,QAAQ,GAAG,GAAG,CAAC,kBAAkB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IACzD,MAAM,KAAK,GAAG,aAAa,CAAC,QAAQ,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;IACjE,MAAM,GAAG,GAAG,WAAW,CAAC,KAAK,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;IAC1D,OAAO;QACL,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,MAAM,EAAE,UAAU;QAClB,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,KAAK,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC,QAAQ,EAAE;QACnC,GAAG,EAAE,GAAG,CAAC,SAAS,EAAE,CAAC,QAAQ,EAAE;QAC/B,YAAY,EACV,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC,iBAAiB,GAAG,KAAK,CAAC,SAAS,EAAE,CAAC,iBAAiB,CAAC;YACzE,oBAAoB;KACvB,CAAC;AACJ,CAAC","sourcesContent":["import { Temporal } from \"@js-temporal/polyfill\";\n\nimport type { Window } from \"../config.js\";\n\nconst MILLISECONDS_PER_DAY = 86_400_000;\nconst CALENDAR_ANCHOR = Temporal.PlainDate.from(\"2000-01-01\");\nconst WEEK_ANCHOR = Temporal.PlainDate.from(\"2000-01-03\");\n\ntype AutoRechargeWindow = Extract<Window, { type: \"calendar\" | \"rolling\" }>;\n\nexport interface ResolvedPolicyWindow {\n unit: \"second\" | \"minute\" | \"hour\" | \"day\" | \"week\" | \"month\" | \"year\";\n count: number;\n anchor: \"calendar\" | \"rolling\";\n timezone: string;\n start: string;\n end: string;\n durationDays: number;\n}\n\nfunction rollingStart(\n end: Temporal.ZonedDateTime,\n unit: Extract<AutoRechargeWindow, { type: \"rolling\" }>[\"duration\"][\"unit\"],\n count: number,\n): Temporal.ZonedDateTime {\n switch (unit) {\n case \"second\":\n return end.subtract({ seconds: count });\n case \"minute\":\n return end.subtract({ minutes: count });\n case \"hour\":\n return end.subtract({ hours: count });\n case \"day\":\n return end.subtract({ days: count });\n case \"week\":\n return end.subtract({ weeks: count });\n default:\n throw new Error(\"auto_recharge_window_unit_not_supported\");\n }\n}\n\nfunction calendarStart(\n now: Temporal.ZonedDateTime,\n unit: Extract<AutoRechargeWindow, { type: \"calendar\" }>[\"unit\"],\n count: number,\n): Temporal.ZonedDateTime {\n if (unit === \"day\" || unit === \"week\") {\n const anchor = unit === \"week\" ? WEEK_ANCHOR : CALENDAR_ANCHOR;\n const stepDays = count * (unit === \"week\" ? 7 : 1);\n const elapsedDays = anchor.until(now.toPlainDate(), { largestUnit: \"day\" }).days;\n const startDate = anchor.add({\n days: Math.floor(elapsedDays / stepDays) * stepDays,\n });\n return startDate.toZonedDateTime(now.timeZoneId);\n }\n\n const stepMonths = count * (unit === \"year\" ? 12 : 1);\n const currentMonth = now.year * 12 + now.month - 1;\n const anchorMonth = 2000 * 12;\n const startMonth =\n anchorMonth + Math.floor((currentMonth - anchorMonth) / stepMonths) * stepMonths;\n const year = Math.floor(startMonth / 12);\n const month = startMonth - year * 12 + 1;\n return Temporal.PlainDate.from({ year, month, day: 1 }).toZonedDateTime(now.timeZoneId);\n}\n\nfunction calendarEnd(\n start: Temporal.ZonedDateTime,\n unit: Extract<AutoRechargeWindow, { type: \"calendar\" }>[\"unit\"],\n count: number,\n): Temporal.ZonedDateTime {\n switch (unit) {\n case \"day\":\n return start.add({ days: count });\n case \"week\":\n return start.add({ weeks: count });\n case \"month\":\n return start.add({ months: count });\n case \"year\":\n return start.add({ years: count });\n }\n}\n\n/**\n * Resolves the reporting boundary that corresponds to PostgreSQL's\n * `bursar.policy_period_window`.\n *\n * SQL remains authoritative for claiming an auto-recharge attempt. This\n * calculation is used only to report the current window and query its count.\n */\nexport function resolveAutoRechargeWindow(\n window: AutoRechargeWindow,\n now: Temporal.Instant = Temporal.Now.instant(),\n): ResolvedPolicyWindow {\n if (window.type === \"rolling\") {\n const timezone = \"UTC\";\n const end = now.toZonedDateTimeISO(timezone);\n const start = rollingStart(end, window.duration.unit, window.duration.count);\n return {\n unit: window.duration.unit,\n count: window.duration.count,\n anchor: \"rolling\",\n timezone,\n start: start.toInstant().toString(),\n end: end.toInstant().toString(),\n durationDays:\n (end.toInstant().epochMilliseconds - start.toInstant().epochMilliseconds) /\n MILLISECONDS_PER_DAY,\n };\n }\n\n const zonedNow = now.toZonedDateTimeISO(window.timezone);\n const start = calendarStart(zonedNow, window.unit, window.count);\n const end = calendarEnd(start, window.unit, window.count);\n return {\n unit: window.unit,\n count: window.count,\n anchor: \"calendar\",\n timezone: window.timezone,\n start: start.toInstant().toString(),\n end: end.toInstant().toString(),\n durationDays:\n (end.toInstant().epochMilliseconds - start.toInstant().epochMilliseconds) /\n MILLISECONDS_PER_DAY,\n };\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { QueryFn } from "../../../shared/postgres-types.js";
|
|
2
|
-
import type { BillingAutoRechargeAttempt, BillingAutoRechargeProfile } from "../../types/index.js";
|
|
2
|
+
import type { BillingAutoRechargeAttempt, BillingAutoRechargeAttemptState, BillingAutoRechargeProfile } from "../../types/index.js";
|
|
3
3
|
export declare class BillingAutoRechargeRepository {
|
|
4
4
|
private readonly query;
|
|
5
5
|
constructor(query: QueryFn);
|
|
@@ -14,7 +14,7 @@ export declare class BillingAutoRechargeRepository {
|
|
|
14
14
|
private advanceAttempt;
|
|
15
15
|
updateAttempt(input: {
|
|
16
16
|
id: string;
|
|
17
|
-
state:
|
|
17
|
+
state: BillingAutoRechargeAttemptState;
|
|
18
18
|
providerAttemptId?: string | null;
|
|
19
19
|
failureCode?: string | null;
|
|
20
20
|
failureMessage?: string | null;
|
|
@@ -23,7 +23,7 @@ export declare class BillingAutoRechargeRepository {
|
|
|
23
23
|
updateAttemptByProviderPayment(input: {
|
|
24
24
|
provider: string;
|
|
25
25
|
providerPaymentId: string;
|
|
26
|
-
state:
|
|
26
|
+
state: BillingAutoRechargeAttemptState;
|
|
27
27
|
failureCode?: string | null;
|
|
28
28
|
failureMessage?: string | null;
|
|
29
29
|
}): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auto-recharge.d.ts","sourceRoot":"","sources":["../../../../src/billing/postgres/repositories/auto-recharge.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"auto-recharge.d.ts","sourceRoot":"","sources":["../../../../src/billing/postgres/repositories/auto-recharge.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AACjE,OAAO,KAAK,EACV,0BAA0B,EAC1B,+BAA+B,EAC/B,0BAA0B,EAC3B,MAAM,sBAAsB,CAAC;AAoM9B,qBAAa,6BAA6B;IAC5B,OAAO,CAAC,QAAQ,CAAC,KAAK;gBAAL,KAAK,EAAE,OAAO;IAErC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,0BAA0B,GAAG,IAAI,CAAC;IAQtE,aAAa,CACjB,OAAO,EAAE,0BAA0B,EACnC,OAAO,GAAE;QAAE,aAAa,CAAC,EAAE,OAAO,CAAA;KAAO,GACxC,OAAO,CAAC,IAAI,CAAC;IA6BV,YAAY,CAAC,KAAK,EAAE;QACxB,MAAM,EAAE,MAAM,CAAC;QACf,cAAc,EAAE,MAAM,CAAC;KACxB,GAAG,OAAO,CAAC,0BAA0B,GAAG,IAAI,CAAC;YAShC,cAAc;IA8GtB,aAAa,CAAC,KAAK,EAAE;QACzB,EAAE,EAAE,MAAM,CAAC;QACX,KAAK,EAAE,+BAA+B,CAAC;QACvC,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QAClC,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QAC5B,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QAC/B,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACpC,GAAG,OAAO,CAAC,IAAI,CAAC;IAIX,8BAA8B,CAAC,KAAK,EAAE;QAC1C,QAAQ,EAAE,MAAM,CAAC;QACjB,iBAAiB,EAAE,MAAM,CAAC;QAC1B,KAAK,EAAE,+BAA+B,CAAC;QACvC,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QAC5B,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;KAChC,GAAG,OAAO,CAAC,IAAI,CAAC;IAoBX,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC;CAmB3E"}
|
|
@@ -1,45 +1,177 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import Decimal from "decimal.js";
|
|
3
|
+
import { StoreError } from "../../../errors.js";
|
|
4
|
+
import { optionalBoundedDiagnosticMessage } from "../../../shared/diagnostics.js";
|
|
5
|
+
import { optionalRecordRow, pgBoolean, postgresUuid, requireResultField, safeParse, } from "../../../shared/postgres-validation.js";
|
|
6
|
+
const safeNonnegativeInteger = z
|
|
7
|
+
.union([z.number(), z.string().regex(/^\d+$/)])
|
|
8
|
+
.transform(Number)
|
|
9
|
+
.pipe(z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER));
|
|
10
|
+
const positiveInteger = safeNonnegativeInteger.pipe(z.number().positive());
|
|
11
|
+
const timestamp = z
|
|
12
|
+
.union([
|
|
13
|
+
z.date().refine((value) => !Number.isNaN(value.getTime())),
|
|
14
|
+
z.string().datetime({ offset: true }),
|
|
15
|
+
])
|
|
16
|
+
.transform((value) => (value instanceof Date ? value : new Date(value)).toISOString());
|
|
17
|
+
const decimal = z
|
|
18
|
+
.union([z.instanceof(Decimal), z.string().min(1), z.number().finite()])
|
|
19
|
+
.transform((value) => new Decimal(value))
|
|
20
|
+
.refine((value) => value.isFinite() && !value.isNegative(), "expected a non-negative decimal");
|
|
21
|
+
const ProfileRowSchema = z
|
|
22
|
+
.object({
|
|
23
|
+
subject_id: postgresUuid,
|
|
24
|
+
enabled: pgBoolean,
|
|
25
|
+
armed: pgBoolean,
|
|
26
|
+
state: z.enum(["disabled", "active", "paused"]),
|
|
27
|
+
provider: z.string().min(1).nullable(),
|
|
28
|
+
topup_id: postgresUuid.nullable(),
|
|
29
|
+
quantity: positiveInteger,
|
|
30
|
+
threshold: decimal,
|
|
31
|
+
max_charges_per_window: positiveInteger.nullable(),
|
|
32
|
+
window_unit: z.enum(["second", "minute", "hour", "day", "week", "month", "year"]),
|
|
33
|
+
window_count: positiveInteger,
|
|
34
|
+
window_anchor: z.enum(["calendar", "rolling"]),
|
|
35
|
+
window_timezone: z.string().min(1),
|
|
36
|
+
updated_at: timestamp,
|
|
37
|
+
})
|
|
38
|
+
.strict()
|
|
39
|
+
.superRefine((row, ctx) => {
|
|
40
|
+
if (row.enabled !== (row.state !== "disabled")) {
|
|
41
|
+
ctx.addIssue({ code: z.ZodIssueCode.custom, message: "enabled and state are inconsistent" });
|
|
42
|
+
}
|
|
43
|
+
if (row.enabled && (row.provider === null || row.topup_id === null)) {
|
|
44
|
+
ctx.addIssue({
|
|
45
|
+
code: z.ZodIssueCode.custom,
|
|
46
|
+
message: "enabled profile requires provider and topup_id",
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
const AttemptStateSchema = z.enum([
|
|
51
|
+
"claimed",
|
|
52
|
+
"submitted",
|
|
53
|
+
"processing",
|
|
54
|
+
"unknown",
|
|
55
|
+
"succeeded",
|
|
56
|
+
"failed",
|
|
57
|
+
"action_required",
|
|
58
|
+
]);
|
|
59
|
+
const AttemptRowSchema = z
|
|
60
|
+
.object({
|
|
61
|
+
id: postgresUuid,
|
|
62
|
+
subject_id: postgresUuid,
|
|
63
|
+
provider: z.string().min(1),
|
|
64
|
+
idempotency_key: z.string().min(1),
|
|
65
|
+
provider_attempt_id: z.string().min(1).nullable(),
|
|
66
|
+
topup_id: postgresUuid,
|
|
67
|
+
quantity: positiveInteger,
|
|
68
|
+
state: AttemptStateSchema,
|
|
69
|
+
window_start: timestamp,
|
|
70
|
+
window_end: timestamp,
|
|
71
|
+
quoted_amount_minor: safeNonnegativeInteger.nullable(),
|
|
72
|
+
currency: z
|
|
73
|
+
.string()
|
|
74
|
+
.regex(/^[A-Z]{3}$/)
|
|
75
|
+
.nullable(),
|
|
76
|
+
failure_code: z.string().min(1).nullable(),
|
|
77
|
+
failure_message: z.string().min(1).nullable(),
|
|
78
|
+
metadata: z.record(z.string(), z.unknown()),
|
|
79
|
+
created_at: timestamp,
|
|
80
|
+
updated_at: timestamp,
|
|
81
|
+
})
|
|
82
|
+
.strict()
|
|
83
|
+
.superRefine((row, ctx) => {
|
|
84
|
+
if (new Date(row.window_end).getTime() <= new Date(row.window_start).getTime()) {
|
|
85
|
+
ctx.addIssue({
|
|
86
|
+
code: z.ZodIssueCode.custom,
|
|
87
|
+
message: "window_end must be later than window_start",
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
if ((row.quoted_amount_minor === null) !== (row.currency === null)) {
|
|
91
|
+
ctx.addIssue({
|
|
92
|
+
code: z.ZodIssueCode.custom,
|
|
93
|
+
message: "quoted_amount_minor and currency must be present together",
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
function projectProfile(row) {
|
|
98
|
+
return {
|
|
99
|
+
subject_id: row.subject_id,
|
|
100
|
+
enabled: row.enabled,
|
|
101
|
+
armed: row.armed,
|
|
102
|
+
state: row.state,
|
|
103
|
+
provider: row.provider,
|
|
104
|
+
topup_id: row.topup_id,
|
|
105
|
+
quantity: row.quantity,
|
|
106
|
+
threshold: row.threshold,
|
|
107
|
+
max_charges_per_window: row.max_charges_per_window,
|
|
108
|
+
window_unit: row.window_unit,
|
|
109
|
+
window_count: row.window_count,
|
|
110
|
+
window_anchor: row.window_anchor,
|
|
111
|
+
window_timezone: row.window_timezone,
|
|
112
|
+
updated_at: row.updated_at,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
function projectAttempt(row) {
|
|
116
|
+
return {
|
|
117
|
+
id: row.id,
|
|
118
|
+
subject_id: row.subject_id,
|
|
119
|
+
provider: row.provider,
|
|
120
|
+
idempotency_key: row.idempotency_key,
|
|
121
|
+
provider_attempt_id: row.provider_attempt_id,
|
|
122
|
+
topup_id: row.topup_id,
|
|
123
|
+
quantity: row.quantity,
|
|
124
|
+
state: row.state,
|
|
125
|
+
window_start: row.window_start,
|
|
126
|
+
window_end: row.window_end,
|
|
127
|
+
quoted_amount_minor: row.quoted_amount_minor,
|
|
128
|
+
currency: row.currency,
|
|
129
|
+
failure_code: row.failure_code,
|
|
130
|
+
failure_message: row.failure_message,
|
|
131
|
+
metadata: row.metadata,
|
|
132
|
+
created_at: row.created_at,
|
|
133
|
+
updated_at: row.updated_at,
|
|
134
|
+
};
|
|
3
135
|
}
|
|
4
136
|
function profileFromRow(row) {
|
|
137
|
+
const parsed = safeParse(ProfileRowSchema, projectProfile(row), "BillingAutoRechargeRepository.profile");
|
|
5
138
|
return {
|
|
6
|
-
userId:
|
|
7
|
-
enabled:
|
|
8
|
-
armed:
|
|
9
|
-
state:
|
|
10
|
-
provider:
|
|
11
|
-
topupId:
|
|
12
|
-
quantity:
|
|
13
|
-
threshold:
|
|
14
|
-
maxChargesPerWindow:
|
|
15
|
-
windowUnit:
|
|
16
|
-
windowCount:
|
|
17
|
-
windowAnchor:
|
|
18
|
-
windowTimezone:
|
|
19
|
-
updatedAt:
|
|
139
|
+
userId: parsed.subject_id,
|
|
140
|
+
enabled: parsed.enabled,
|
|
141
|
+
armed: parsed.armed,
|
|
142
|
+
state: parsed.state,
|
|
143
|
+
provider: parsed.provider,
|
|
144
|
+
topupId: parsed.topup_id,
|
|
145
|
+
quantity: parsed.quantity,
|
|
146
|
+
threshold: parsed.threshold,
|
|
147
|
+
maxChargesPerWindow: parsed.max_charges_per_window,
|
|
148
|
+
windowUnit: parsed.window_unit,
|
|
149
|
+
windowCount: parsed.window_count,
|
|
150
|
+
windowAnchor: parsed.window_anchor,
|
|
151
|
+
windowTimezone: parsed.window_timezone,
|
|
152
|
+
updatedAt: parsed.updated_at,
|
|
20
153
|
};
|
|
21
154
|
}
|
|
22
155
|
function attemptFromRow(row) {
|
|
156
|
+
const parsed = safeParse(AttemptRowSchema, projectAttempt(row), "BillingAutoRechargeRepository.attempt");
|
|
23
157
|
return {
|
|
24
|
-
id:
|
|
25
|
-
userId:
|
|
26
|
-
provider:
|
|
27
|
-
idempotencyKey:
|
|
28
|
-
providerAttemptId:
|
|
29
|
-
topupId:
|
|
30
|
-
quantity:
|
|
31
|
-
state:
|
|
32
|
-
windowStart:
|
|
33
|
-
windowEnd:
|
|
34
|
-
quotedAmountMinor:
|
|
35
|
-
currency:
|
|
36
|
-
failureCode:
|
|
37
|
-
failureMessage:
|
|
38
|
-
metadata:
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
createdAt: iso(row.created_at),
|
|
42
|
-
updatedAt: iso(row.updated_at),
|
|
158
|
+
id: parsed.id,
|
|
159
|
+
userId: parsed.subject_id,
|
|
160
|
+
provider: parsed.provider,
|
|
161
|
+
idempotencyKey: parsed.idempotency_key,
|
|
162
|
+
providerAttemptId: parsed.provider_attempt_id,
|
|
163
|
+
topupId: parsed.topup_id,
|
|
164
|
+
quantity: parsed.quantity,
|
|
165
|
+
state: parsed.state,
|
|
166
|
+
windowStart: parsed.window_start,
|
|
167
|
+
windowEnd: parsed.window_end,
|
|
168
|
+
quotedAmountMinor: parsed.quoted_amount_minor,
|
|
169
|
+
currency: parsed.currency,
|
|
170
|
+
failureCode: parsed.failure_code,
|
|
171
|
+
failureMessage: parsed.failure_message,
|
|
172
|
+
metadata: parsed.metadata,
|
|
173
|
+
createdAt: parsed.created_at,
|
|
174
|
+
updatedAt: parsed.updated_at,
|
|
43
175
|
};
|
|
44
176
|
}
|
|
45
177
|
export class BillingAutoRechargeRepository {
|
|
@@ -51,8 +183,8 @@ export class BillingAutoRechargeRepository {
|
|
|
51
183
|
const rows = await this.query("SELECT * FROM bursar.get_auto_recharge_profile($1::uuid)", [
|
|
52
184
|
userId,
|
|
53
185
|
]);
|
|
54
|
-
const row = rows
|
|
55
|
-
return row
|
|
186
|
+
const row = optionalRecordRow(rows, "BillingAutoRechargeRepository.getProfile");
|
|
187
|
+
return row === null ? null : profileFromRow(row);
|
|
56
188
|
}
|
|
57
189
|
async upsertProfile(profile, options = {}) {
|
|
58
190
|
const rows = await this.query(`SELECT bursar.upsert_auto_recharge_profile(
|
|
@@ -63,7 +195,7 @@ export class BillingAutoRechargeRepository {
|
|
|
63
195
|
profile.provider,
|
|
64
196
|
profile.topupId,
|
|
65
197
|
profile.quantity,
|
|
66
|
-
profile.threshold,
|
|
198
|
+
profile.threshold.toString(),
|
|
67
199
|
profile.maxChargesPerWindow,
|
|
68
200
|
profile.windowUnit,
|
|
69
201
|
profile.windowCount,
|
|
@@ -73,18 +205,25 @@ export class BillingAutoRechargeRepository {
|
|
|
73
205
|
profile.state,
|
|
74
206
|
options.resetCooldown ?? false,
|
|
75
207
|
]);
|
|
76
|
-
if (!rows
|
|
77
|
-
throw new
|
|
208
|
+
if (!requireResultField(rows, "updated", pgBoolean, "BillingAutoRechargeRepository.upsertProfile")) {
|
|
209
|
+
throw new StoreError(`auto-recharge profile update rejected: ${profile.userId}`);
|
|
78
210
|
}
|
|
79
211
|
}
|
|
80
212
|
async claimAttempt(input) {
|
|
81
213
|
const rows = await this.query("SELECT * FROM bursar.claim_auto_recharge_attempt($1::uuid, $2)", [input.userId, input.idempotencyKey]);
|
|
82
|
-
const row = rows
|
|
83
|
-
return row
|
|
214
|
+
const row = optionalRecordRow(rows, "BillingAutoRechargeRepository.claimAttempt");
|
|
215
|
+
return row === null ? null : attemptFromRow(row);
|
|
84
216
|
}
|
|
85
217
|
async advanceAttempt(input) {
|
|
218
|
+
const failureMessage = optionalBoundedDiagnosticMessage(input.failureMessage);
|
|
86
219
|
const currentRows = await this.query("SELECT * FROM bursar.get_auto_recharge_attempt($1::uuid)", [input.id]);
|
|
87
|
-
const
|
|
220
|
+
const currentRow = optionalRecordRow(currentRows, "BillingAutoRechargeRepository.advanceAttempt.current");
|
|
221
|
+
if (currentRow === null) {
|
|
222
|
+
throw new StoreError(`auto-recharge attempt not found: ${input.id}`, {
|
|
223
|
+
details: { attemptId: input.id },
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
const current = safeParse(AttemptStateSchema, currentRow.state, "BillingAutoRechargeRepository.advanceAttempt.current.state");
|
|
88
227
|
const paths = {
|
|
89
228
|
claimed: {
|
|
90
229
|
submitted: ["submitted"],
|
|
@@ -125,7 +264,9 @@ export class BillingAutoRechargeRepository {
|
|
|
125
264
|
};
|
|
126
265
|
const path = paths[current]?.[input.state];
|
|
127
266
|
if (!path) {
|
|
128
|
-
throw new
|
|
267
|
+
throw new StoreError(`auto-recharge attempt transition rejected: ${input.id}`, {
|
|
268
|
+
details: { attemptId: input.id, currentState: current, requestedState: input.state },
|
|
269
|
+
});
|
|
129
270
|
}
|
|
130
271
|
for (const state of path) {
|
|
131
272
|
const rows = await this.query(`SELECT bursar.advance_auto_recharge_attempt(
|
|
@@ -140,11 +281,13 @@ export class BillingAutoRechargeRepository {
|
|
|
140
281
|
state,
|
|
141
282
|
input.providerAttemptId ?? null,
|
|
142
283
|
input.failureCode ?? null,
|
|
143
|
-
|
|
284
|
+
failureMessage,
|
|
144
285
|
JSON.stringify(input.metadata ?? {}),
|
|
145
286
|
]);
|
|
146
|
-
if (!rows
|
|
147
|
-
throw new
|
|
287
|
+
if (!requireResultField(rows, "advanced", pgBoolean, "BillingAutoRechargeRepository.advanceAttempt")) {
|
|
288
|
+
throw new StoreError(`auto-recharge attempt transition rejected: ${input.id}`, {
|
|
289
|
+
details: { attemptId: input.id, requestedState: state },
|
|
290
|
+
});
|
|
148
291
|
}
|
|
149
292
|
}
|
|
150
293
|
}
|
|
@@ -153,18 +296,17 @@ export class BillingAutoRechargeRepository {
|
|
|
153
296
|
}
|
|
154
297
|
async updateAttemptByProviderPayment(input) {
|
|
155
298
|
const rows = await this.query(`SELECT * FROM bursar.get_auto_recharge_attempt_by_provider($1, $2)`, [input.provider, input.providerPaymentId]);
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
}
|
|
299
|
+
const row = optionalRecordRow(rows, "BillingAutoRechargeRepository.updateAttemptByProviderPayment");
|
|
300
|
+
if (row === null)
|
|
301
|
+
return;
|
|
302
|
+
const attempt = attemptFromRow(row);
|
|
303
|
+
await this.advanceAttempt({
|
|
304
|
+
id: attempt.id,
|
|
305
|
+
state: input.state,
|
|
306
|
+
providerAttemptId: input.providerPaymentId,
|
|
307
|
+
failureCode: input.failureCode,
|
|
308
|
+
failureMessage: input.failureMessage,
|
|
309
|
+
});
|
|
168
310
|
}
|
|
169
311
|
async countAttempts(userId, since) {
|
|
170
312
|
const sinceDate = since instanceof Date ? since : new Date(since);
|
|
@@ -172,7 +314,10 @@ export class BillingAutoRechargeRepository {
|
|
|
172
314
|
throw new TypeError("auto-recharge attempt boundary must be a valid instant");
|
|
173
315
|
}
|
|
174
316
|
const rows = await this.query(`SELECT bursar.count_auto_recharge_attempts($1::uuid, $2::timestamptz) AS count`, [userId, sinceDate.toISOString()]);
|
|
175
|
-
return
|
|
317
|
+
return requireResultField(rows, "count", z
|
|
318
|
+
.union([z.number(), z.string().regex(/^\d+$/)])
|
|
319
|
+
.transform(Number)
|
|
320
|
+
.pipe(z.number().int().nonnegative().safe()), "BillingAutoRechargeRepository.countAttempts");
|
|
176
321
|
}
|
|
177
322
|
}
|
|
178
323
|
//# sourceMappingURL=auto-recharge.js.map
|