@zonastery/bursar 1.0.1 → 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 +86 -3
- 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 +8 -7
- 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 +31 -9
- package/dist/billing/event-handlers.js.map +1 -1
- package/dist/billing/event-processor.d.ts.map +1 -1
- package/dist/billing/event-processor.js +2 -1
- 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 +1 -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/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 +202 -59
- 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 +12 -5
- package/dist/billing/postgres/repositories/event.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/event.js +18 -15
- 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 +18 -11
- package/dist/billing/postgres/store.d.ts.map +1 -1
- package/dist/billing/postgres/store.js +260 -238
- 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/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/bursar.d.ts +27 -9
- package/dist/bursar.d.ts.map +1 -1
- package/dist/bursar.js +48 -20
- package/dist/bursar.js.map +1 -1
- package/dist/catalog.d.ts +1 -1
- package/dist/catalog.d.ts.map +1 -1
- package/dist/catalog.js +1 -1
- package/dist/catalog.js.map +1 -1
- package/dist/commerce/errors.d.ts +1 -10
- package/dist/commerce/errors.d.ts.map +1 -1
- package/dist/commerce/errors.js +1 -16
- 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/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 +85 -67
- package/dist/commerce/service.js.map +1 -1
- package/dist/commerce/types.d.ts +27 -15
- package/dist/commerce/types.d.ts.map +1 -1
- package/dist/commerce/types.js.map +1 -1
- package/dist/config/parse-plans.d.ts.map +1 -1
- package/dist/config/parse-plans.js +16 -15
- 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/types.d.ts +2 -2
- package/dist/config/types.d.ts.map +1 -1
- package/dist/config/types.js.map +1 -1
- package/dist/credits/{pricing-runtime.d.ts → catalog-runtime.d.ts} +8 -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 +34 -34
- package/dist/credits/postgres/repositories/analytics.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/analytics.js +52 -52
- 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 +28 -26
- package/dist/credits/postgres/repositories/deduction.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/deduction.js +153 -68
- 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 +90 -43
- package/dist/credits/postgres/repositories/plan.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/plan.js +126 -108
- 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 +23 -18
- package/dist/credits/postgres/store.d.ts.map +1 -1
- package/dist/credits/postgres/store.js +282 -265
- 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 +36 -61
- 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-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 +42 -62
- package/dist/credits/service.d.ts.map +1 -1
- package/dist/credits/service.js +140 -121
- package/dist/credits/service.js.map +1 -1
- package/dist/credits/store.d.ts +20 -22
- package/dist/credits/store.d.ts.map +1 -1
- package/dist/credits/store.js +5 -5
- package/dist/credits/store.js.map +1 -1
- package/dist/credits/types/account.d.ts +49 -11
- 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 +20 -15
- 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/ledger.d.ts +12 -3
- package/dist/credits/types/ledger.d.ts.map +1 -1
- package/dist/credits/types/ledger.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 +52 -4
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +76 -4
- 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/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 +5 -7
- package/dist/expr.js.map +1 -1
- package/dist/generated/pricing-config.schema.json +5 -12
- package/dist/generated/pricing-config.types.d.ts +3 -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 +6 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- 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} +15 -10
- package/dist/load-config-file.js.map +1 -0
- 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 +36 -0
- 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/shared/postgres-client.d.ts +5 -0
- package/dist/shared/postgres-client.d.ts.map +1 -1
- package/dist/shared/postgres-client.js +23 -7
- package/dist/shared/postgres-client.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 +2 -5
- 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/ports.d.ts +0 -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 +2 -2
- package/dist/storage/postgres-repository.js.map +1 -1
- package/dist/storage/runtime.d.ts +24 -6
- package/dist/storage/runtime.d.ts.map +1 -1
- package/dist/storage/runtime.js +87 -30
- package/dist/storage/runtime.js.map +1 -1
- package/package.json +56 -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 -76
- 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":"store.js","sourceRoot":"","sources":["../../../src/billing/postgres/store.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAgBnD,OAAO,EACL,cAAc,GAGf,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,gCAAgC,EAAE,MAAM,6BAA6B,CAAC;AAC/E,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AACvE,OAAO,EAAE,6BAA6B,EAAE,MAAM,gCAAgC,CAAC;AAC/E,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AACrE,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AACrE,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AACrE,OAAO,EAAE,4BAA4B,EAAE,MAAM,+BAA+B,CAAC;AAC7E,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAEhF,SAAS,KAAK,CAAC,KAAc;IAC3B,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAC;IACxB,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE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,CAAC;CACF","sourcesContent":["import type {\n BillingAutoRechargeAttempt,\n BillingAutoRechargeProfile,\n BillingCustomerRecord,\n BillingEventClaim,\n BillingOfferResult,\n BillingPreferences,\n BillingSubscriptionChange,\n BillingSubscriptionChangeInput,\n BillingSubscriptionOfferContext,\n BillingSubscriptionState,\n BillingSubscriptionStatus,\n CheckoutIntent,\n BillingTopupResult,\n} from \"../types/index.js\";\nimport { BillingStore } from \"../billing-store.js\";\nimport type {\n AutoRechargeAttemptClaim,\n AutoRechargeAttemptUpdate,\n AutoRechargeProviderPaymentUpdate,\n BillingCreditGrantCreate,\n BillingDisputeUpsert,\n BillingInvoiceUpsert,\n BillingPaymentUpsert,\n BillingRefundUpsert,\n BillingSubscriptionChangeUpdate,\n BillingSubscriptionConflictCreate,\n CheckoutIntentCreate,\n CheckoutIntentUpdate,\n} from \"../contracts.js\";\nimport type { QueryFn } from \"../../shared/postgres-types.js\";\nimport {\n PostgresClient,\n type PostgresConnectionOptions,\n type PostgresPool,\n} from \"../../shared/postgres-client.js\";\nimport { StoreClosedError } from \"../../errors.js\";\nimport { optionalBoundedDiagnosticMessage } from \"../../shared/diagnostics.js\";\nimport { BillingOfferRepository } from \"./repositories/offer.js\";\nimport { BillingTopupRepository } from \"./repositories/topup.js\";\nimport { BillingCustomerRepository } from \"./repositories/customer.js\";\nimport { BillingSubscriptionRepository } from \"./repositories/subscription.js\";\nimport { BillingEventRepository } from \"./repositories/event.js\";\nimport { BillingPaymentRepository } from \"./repositories/payment.js\";\nimport { BillingRefundRepository } from \"./repositories/refund.js\";\nimport { BillingInvoiceRepository } from \"./repositories/invoice.js\";\nimport { BillingDisputeRepository } from \"./repositories/dispute.js\";\nimport { BillingPreferencesRepository } from \"./repositories/preferences.js\";\nimport { BillingAutoRechargeRepository } from \"./repositories/auto-recharge.js\";\n\nfunction toIso(value: unknown): string | null {\n if (!value) return null;\n if (typeof value === \"string\") return value;\n if (value instanceof Date) return value.toISOString();\n if (typeof (value as Record<string, unknown>)[\"toISOString\"] === \"function\") {\n return (value as Date).toISOString();\n }\n return String(value);\n}\n\nexport interface PostgresBillingStoreOptions extends PostgresConnectionOptions {\n billingPayloadBackend?: \"postgres\" | \"s3\";\n}\n\nexport class PostgresBillingStore extends BillingStore {\n private readonly postgres: PostgresClient;\n\n private _offer: BillingOfferRepository | null = null;\n private _topup: BillingTopupRepository | null = null;\n private _customer: BillingCustomerRepository | null = null;\n private _subscription: BillingSubscriptionRepository | null = null;\n private _event: BillingEventRepository | null = null;\n private _payment: BillingPaymentRepository | null = null;\n private _refund: BillingRefundRepository | null = null;\n private _invoice: BillingInvoiceRepository | null = null;\n private _dispute: BillingDisputeRepository | null = null;\n private _preferences: BillingPreferencesRepository | null = null;\n private _autoRecharge: BillingAutoRechargeRepository | null = null;\n constructor(\n poolOrUrl: PostgresPool | string,\n tenantId: string,\n storageOptions?: PostgresBillingStoreOptions,\n ) {\n super();\n this.postgres = new PostgresClient(poolOrUrl, {\n tenantId,\n billingPayloadBackend: storageOptions?.billingPayloadBackend,\n connectionTimeoutMs: storageOptions?.connectionTimeoutMs,\n statementTimeoutMs: storageOptions?.statementTimeoutMs,\n idleTransactionTimeoutMs: storageOptions?.idleTransactionTimeoutMs,\n idleTimeoutMs: storageOptions?.idleTimeoutMs,\n maxConnections: storageOptions?.maxConnections,\n applicationName: storageOptions?.applicationName,\n onPoolError: storageOptions?.onPoolError,\n closedError: () => new StoreClosedError(\"Billing store has been closed\"),\n });\n }\n\n async close(): Promise<void> {\n await this.postgres.close();\n }\n\n private get queryFn(): QueryFn {\n return this.postgres.query;\n }\n\n private get billingOffer(): BillingOfferRepository {\n if (!this._offer) this._offer = new BillingOfferRepository(this.queryFn);\n return this._offer;\n }\n\n private get billingTopup(): BillingTopupRepository {\n if (!this._topup) this._topup = new BillingTopupRepository(this.queryFn);\n return this._topup;\n }\n\n private get billingCustomer(): BillingCustomerRepository {\n if (!this._customer) this._customer = new BillingCustomerRepository(this.queryFn);\n return this._customer;\n }\n\n private get billingSubscription(): BillingSubscriptionRepository {\n if (!this._subscription) this._subscription = new BillingSubscriptionRepository(this.queryFn);\n return this._subscription;\n }\n\n private get billingEvent(): BillingEventRepository {\n if (!this._event) this._event = new BillingEventRepository(this.queryFn);\n return this._event;\n }\n\n private get billingPayment(): BillingPaymentRepository {\n if (!this._payment) this._payment = new BillingPaymentRepository(this.queryFn);\n return this._payment;\n }\n\n private get billingRefund(): BillingRefundRepository {\n if (!this._refund) this._refund = new BillingRefundRepository(this.queryFn);\n return this._refund;\n }\n\n private get billingInvoice(): BillingInvoiceRepository {\n if (!this._invoice) this._invoice = new BillingInvoiceRepository(this.queryFn);\n return this._invoice;\n }\n\n private get billingDispute(): BillingDisputeRepository {\n if (!this._dispute) this._dispute = new BillingDisputeRepository(this.queryFn);\n return this._dispute;\n }\n\n private get billingPreferences(): BillingPreferencesRepository {\n if (!this._preferences) this._preferences = new BillingPreferencesRepository(this.queryFn);\n return this._preferences;\n }\n\n private get billingAutoRecharge(): BillingAutoRechargeRepository {\n if (!this._autoRecharge) this._autoRecharge = new BillingAutoRechargeRepository(this.queryFn);\n return this._autoRecharge;\n }\n\n async createOrGetCheckoutIntent(input: CheckoutIntentCreate): Promise<CheckoutIntent> {\n if (!/^[0-9a-fA-F]{64}$/.test(input.requestDigest)) {\n throw new Error(\"requestDigest must be a 32-byte hex string\");\n }\n const rows = await this.queryFn(\n `SELECT bursar.create_checkout_intent($1::uuid, $2, $3, $4, decode($5, 'hex'), $6::timestamptz) AS id`,\n [\n input.subjectId,\n input.provider,\n input.checkoutKind,\n input.productKey,\n input.requestDigest,\n input.expiresAt,\n ],\n );\n const id = (rows[0] as Record<string, unknown> | undefined)?.id;\n if (!id) throw new Error(\"checkout intent creation returned no ID\");\n const intent = await this.getCheckoutIntent(String(id), input.subjectId);\n if (!intent) throw new Error(\"checkout intent creation returned no row\");\n return intent;\n }\n\n async updateCheckoutIntent(id: string, update: CheckoutIntentUpdate): Promise<void> {\n const rows = await this.queryFn(\n `SELECT bursar.advance_checkout_intent($1::uuid, $2, $3, $4) AS advanced`,\n [id, update.status ?? null, update.providerSessionId ?? null, update.checkoutUrl ?? null],\n );\n if (!(rows[0] as Record<string, unknown> | undefined)?.advanced) {\n throw new Error(`checkout intent transition rejected: ${id}`);\n }\n }\n\n async getCheckoutIntent(id: string, subjectId: string): Promise<CheckoutIntent | null> {\n const rows = await this.queryFn(\n `SELECT * FROM bursar.get_checkout_intent($1::uuid, $2::uuid)`,\n [id, subjectId],\n );\n const row = rows[0] as Record<string, unknown> | undefined;\n return row?.id == null ? null : this.rowToCheckoutIntent(row);\n }\n\n private rowToCheckoutIntent(row: Record<string, unknown>): CheckoutIntent {\n return {\n id: String(row.id),\n subjectId: String(row.subject_id),\n provider: String(row.provider),\n checkoutKind: row.checkout_kind as CheckoutIntent[\"checkoutKind\"],\n productKey: String(row.product_key),\n requestDigest: Buffer.from(row.request_digest as Uint8Array).toString(\"hex\"),\n status: row.status as CheckoutIntent[\"status\"],\n providerSessionId: row.provider_session_id == null ? null : String(row.provider_session_id),\n checkoutUrl: row.checkout_url == null ? null : String(row.checkout_url),\n expiresAt: toIso(row.expires_at) ?? new Date(0).toISOString(),\n };\n }\n\n private rowToOffer(row: Record<string, unknown> | null): BillingOfferResult | null {\n if (!row?.offer_key || !row.id) return null;\n return {\n offerId: String(row.id),\n offerKey: String(row.offer_key),\n planId: row.plan_id == null ? null : String(row.plan_id),\n plan: row.plan == null ? null : String(row.plan),\n interval: row.interval == null ? \"month\" : String(row.interval),\n intervalCount: Number(row.interval_count ?? 1),\n grant: {\n mode: row.grant_mode == null ? undefined : String(row.grant_mode),\n credits: row.grant_credits == null ? null : Number(row.grant_credits),\n bucket: row.grant_bucket == null ? undefined : String(row.grant_bucket),\n replacePrior: row.grant_replace_prior === true,\n },\n };\n }\n\n async resolveBillingOffer(\n provider: string,\n productId?: string | null,\n priceId?: string | null,\n ): Promise<BillingOfferResult | null> {\n const r = await this.billingOffer.resolveByPrice(provider, priceId ?? null, productId ?? null);\n return this.rowToOffer(r as Record<string, unknown>);\n }\n\n async resolveBillingOfferByLookup(\n provider: string,\n lookupKey: string,\n ): Promise<BillingOfferResult | null> {\n const r = await this.billingOffer.resolveByLookup(provider, lookupKey);\n return this.rowToOffer(r as Record<string, unknown>);\n }\n\n async claimBillingEvent(\n provider: string,\n eventId: string,\n eventType: string,\n envelope?: Record<string, unknown>,\n ): Promise<BillingEventClaim> {\n const result = await this.billingEvent.claim(\n provider,\n eventId,\n eventType,\n JSON.stringify(envelope ?? { eventType }),\n );\n if (!result) return { status: \"retry\" as const };\n const r = result as Record<string, unknown>;\n const s = r.status as string;\n if (s === \"claimed\" && typeof r.claim_token === \"string\" && typeof r.event_id === \"string\") {\n return {\n status: \"claimed\" as const,\n claimToken: r.claim_token,\n billingEventId: r.event_id,\n };\n }\n if (s === \"duplicate\") return { status: \"duplicate\" as const };\n if (s === \"busy\") return { status: \"busy\" as const };\n return { status: \"retry\" as const };\n }\n\n async completeBillingEvent(\n provider: string,\n eventId: string,\n claimToken: string,\n ): Promise<boolean> {\n return this.billingEvent.complete(provider, eventId, claimToken);\n }\n\n async failBillingEvent(\n provider: string,\n eventId: string,\n claimToken: string,\n error?: string,\n ): Promise<boolean> {\n return this.billingEvent.fail(\n provider,\n eventId,\n claimToken,\n optionalBoundedDiagnosticMessage(error) ?? undefined,\n );\n }\n\n async upsertBillingCustomer(\n provider: string,\n providerCustomerId: string,\n userId: string,\n email?: string | null,\n ): Promise<void> {\n await this.billingCustomer.upsert(provider, providerCustomerId, userId, email ?? null);\n }\n\n async upsertBillingSubscription(state: BillingSubscriptionState): Promise<void> {\n await this.billingSubscription.upsert(state as unknown as Record<string, unknown>);\n }\n\n async getBillingCustomer(provider: string, providerCustomerId: string): Promise<string | null> {\n return this.billingCustomer.get(provider, providerCustomerId);\n }\n\n async getBillingSubscription(\n provider: string,\n providerSubscriptionId: string,\n ): Promise<BillingSubscriptionState | null> {\n const r = await this.billingSubscription.get(provider, providerSubscriptionId);\n if (!r) return null;\n return this.rowToSubscriptionState(r);\n }\n\n async createBillingSubscriptionChange(\n input: BillingSubscriptionChangeInput,\n ): Promise<BillingSubscriptionChange> {\n const subscription = await this.billingSubscription.get(\n input.provider,\n input.providerSubscriptionId,\n );\n if (!subscription?.id) throw new Error(\"subscription change requires a persisted subscription\");\n const rows = await this.queryFn(\n `SELECT * FROM bursar.open_subscription_change(\n $1::uuid, $2::uuid, $3::timestamptz, $4, $5, $6\n )`,\n [\n subscription.id,\n input.toOfferId,\n input.effectiveAt,\n input.effective,\n input.idempotencyKey,\n input.prorationBehavior ?? \"provider_default\",\n ],\n );\n const result = (rows[0] as Record<string, unknown> | undefined) ?? {};\n if (result.error_code) throw new Error(`subscription change: ${String(result.error_code)}`);\n const changeRows = await this.queryFn(\n `SELECT * FROM bursar.get_billing_subscription_change($1::bigint)`,\n [result.change_id],\n );\n if ((changeRows[0] as Record<string, unknown> | undefined)?.id == null) {\n throw new Error(\"subscription change creation returned no row\");\n }\n return this.rowToSubscriptionChange(changeRows[0] as Record<string, unknown>);\n }\n\n async getOpenBillingSubscriptionChange(\n provider: string,\n providerSubscriptionId: string,\n ): Promise<BillingSubscriptionChange | null> {\n const rows = await this.queryFn(\n `SELECT * FROM bursar.get_open_billing_subscription_change($1, $2)`,\n [provider, providerSubscriptionId],\n );\n const row = rows[0] as Record<string, unknown> | undefined;\n return row?.id == null ? null : this.rowToSubscriptionChange(row);\n }\n\n async listExpiredGraceSubscriptions(\n now: string,\n limit = 100,\n ): Promise<BillingSubscriptionState[]> {\n const rows = await this.billingSubscription.listExpiredGraceSubscriptions(now, limit);\n return rows.map((row) => this.rowToSubscriptionState(row));\n }\n\n async markSubscriptionGraceExpired(\n subscriptionId: string,\n expectedGraceEndsAt: string,\n expiredAt = new Date().toISOString(),\n ): Promise<boolean> {\n return this.billingSubscription.markGraceExpired(\n subscriptionId,\n expectedGraceEndsAt,\n expiredAt,\n );\n }\n\n async updateBillingSubscriptionChange(\n id: string,\n update: BillingSubscriptionChangeUpdate,\n ): Promise<void> {\n if (!update.state) return;\n const rows = await this.queryFn(\n `SELECT bursar.advance_subscription_change($1::bigint, $2, $3, $4) AS advanced`,\n [\n id,\n update.state,\n update.providerOperationId ?? null,\n optionalBoundedDiagnosticMessage(update.errorMessage),\n ],\n );\n if (!(rows[0] as Record<string, unknown> | undefined)?.advanced) {\n throw new Error(`subscription change transition rejected: ${id}`);\n }\n }\n\n async getUserSubscription(\n userId: string,\n statuses?: string[],\n ): Promise<BillingSubscriptionState | null> {\n const r = await this.billingSubscription.getUserSubscription(userId, statuses);\n if (!r) return null;\n return this.rowToSubscriptionState(r);\n }\n\n async getUserSubscriptions(userId: string): Promise<BillingSubscriptionState[]> {\n const rows = await this.billingSubscription.getUserSubscriptions(userId);\n return rows.map((r) => this.rowToSubscriptionState(r));\n }\n\n async recordSubscriptionConflict(input: BillingSubscriptionConflictCreate): Promise<void> {\n await this.billingSubscription.recordConflict(input);\n }\n\n async selectSubscriptionEntitlementSource(\n userId: string,\n provider: string,\n providerSubscriptionId?: string | null,\n ): Promise<boolean> {\n return this.billingSubscription.selectEntitlementSource(\n userId,\n provider,\n providerSubscriptionId,\n );\n }\n\n private rowToTopup(r: Record<string, unknown>): BillingTopupResult | null {\n if (!r?.topup_key || !r.id) return null;\n return {\n topupId: String(r.id),\n topupKey: r.topup_key as string,\n creditsPerUnit: Number(r.credits_per_unit ?? r.credits_per_major_unit ?? 1000),\n depositTo: (r.bucket_key as string | undefined) || \"purchased\",\n amountMinor: r.amount_minor == null ? undefined : Number(r.amount_minor),\n currency: r.currency == null ? undefined : String(r.currency),\n minQuantity: r.min_quantity == null ? undefined : Number(r.min_quantity),\n maxQuantity: r.max_quantity == null ? undefined : Number(r.max_quantity),\n defaultQuantity: r.default_quantity == null ? undefined : Number(r.default_quantity),\n minAmountMinor:\n r.amount_minor == null ? undefined : Number(r.amount_minor) * Number(r.min_quantity ?? 1),\n maxAmountMinor:\n r.amount_minor == null ? undefined : Number(r.amount_minor) * Number(r.max_quantity ?? 1),\n };\n }\n\n async resolveCreditTopup(\n provider: string,\n productId?: string | null,\n priceId?: string | null,\n ): Promise<BillingTopupResult | null> {\n const r = await this.billingTopup.resolveByPrice(provider, priceId ?? null, productId ?? null);\n return this.rowToTopup(r as Record<string, unknown>);\n }\n\n async resolveCreditTopupByLookup(\n provider: string,\n lookupKey: string,\n ): Promise<BillingTopupResult | null> {\n const r = await this.billingTopup.resolveByLookup(provider, lookupKey);\n return this.rowToTopup(r as Record<string, unknown>);\n }\n\n async computeTopupCredits(amountMinor: number, topupConfig: BillingTopupResult): Promise<number> {\n const unitAmount = topupConfig.amountMinor;\n const creditsPer = topupConfig.creditsPerUnit ?? 0;\n if (!unitAmount || amountMinor % unitAmount !== 0) return 0;\n const quantity = amountMinor / unitAmount;\n if (quantity < (topupConfig.minQuantity ?? 1) || quantity > (topupConfig.maxQuantity ?? 1)) {\n return 0;\n }\n return quantity * creditsPer;\n }\n\n async upsertBillingPayment(options: BillingPaymentUpsert): Promise<string> {\n return this.billingPayment.upsert(\n options.provider,\n options.providerPaymentId,\n options.providerInvoiceId ?? null,\n options.userId ?? null,\n options.amountMinor ?? 0,\n options.taxMinor ?? null,\n options.currency ?? \"USD\",\n options.purpose ?? null,\n options.metadata ? JSON.stringify(options.metadata) : null,\n options.status ?? \"succeeded\",\n options.providerUpdatedAt ?? new Date().toISOString(),\n );\n }\n\n async createBillingCreditGrant(input: BillingCreditGrantCreate): Promise<string> {\n const rows = await this.queryFn(\n \"SELECT bursar.create_billing_credit_grant($1::uuid, $2::uuid, $3::uuid, $4, $5, $6::uuid) AS id\",\n [\n input.paymentId ?? null,\n input.subscriptionId ?? null,\n input.topupId ?? null,\n input.configuredCredits,\n input.quantity ?? 1,\n input.billingEventId ?? null,\n ],\n );\n const id = (rows[0] as Record<string, unknown> | undefined)?.id;\n if (!id) throw new Error(\"billing credit grant creation returned no ID\");\n return String(id);\n }\n\n async grantBillingCredit(\n grantId: string,\n idempotencyKey: string,\n ): Promise<Record<string, unknown>> {\n const rows = await this.queryFn(\"SELECT * FROM bursar.grant_billing_credit($1::uuid, $2)\", [\n grantId,\n idempotencyKey,\n ]);\n return (rows[0] as Record<string, unknown> | undefined) ?? {};\n }\n\n async getBillingCreditGrantByPayment(paymentId: string): Promise<string | null> {\n const rows = await this.queryFn(\n `SELECT * FROM bursar.get_billing_credit_grant_by_payment($1::uuid)`,\n [paymentId],\n );\n const id = (rows[0] as Record<string, unknown> | undefined)?.id;\n return id ? String(id) : null;\n }\n\n async postBillingRefund(\n refundId: string,\n grantId: string,\n amountMinor: number,\n idempotencyKey: string,\n ): Promise<Record<string, unknown>> {\n const rows = await this.queryFn(\n \"SELECT * FROM bursar.post_billing_refund($1::uuid, $2::uuid, $3, $4)\",\n [refundId, grantId, amountMinor, idempotencyKey],\n );\n return (rows[0] as Record<string, unknown> | undefined) ?? {};\n }\n\n async upsertBillingRefund(options: BillingRefundUpsert): Promise<string> {\n return this.billingRefund.upsert(\n options.provider,\n options.providerRefundId,\n options.providerPaymentId ?? null,\n options.userId ?? null,\n options.amountMinor ?? 0,\n options.currency ?? \"USD\",\n options.reason ?? null,\n options.metadata ? JSON.stringify(options.metadata) : null,\n options.status ?? \"pending\",\n options.providerUpdatedAt ?? new Date().toISOString(),\n );\n }\n\n async upsertBillingInvoice(options: BillingInvoiceUpsert): Promise<void> {\n const subscription = options.providerSubscriptionId\n ? await this.billingSubscription.get(options.provider, options.providerSubscriptionId)\n : null;\n const subjectId =\n options.userId ?? (subscription?.subject_id ? String(subscription.subject_id) : null);\n if (!subjectId) throw new Error(\"invoice subject is required\");\n await this.billingInvoice.upsert(\n subjectId,\n options.provider,\n options.providerInvoiceId,\n subscription?.id ? String(subscription.id) : null,\n options.status ?? null,\n options.amountDueMinor ?? null,\n options.amountPaidMinor ?? null,\n options.currency ?? \"USD\",\n options.periodStart ?? null,\n options.periodEnd ?? null,\n options.metadata ?? {},\n options.providerUpdatedAt ?? new Date().toISOString(),\n );\n }\n\n async listBillingInvoices(userId: string) {\n return this.billingInvoice.listForUser(userId);\n }\n\n async upsertBillingDispute(options: BillingDisputeUpsert): Promise<void> {\n const payment = options.providerPaymentId\n ? await this.billingPayment.getForRefund(options.provider, options.providerPaymentId)\n : null;\n if (!payment?.id) throw new Error(\"dispute payment is required\");\n await this.billingDispute.upsert(\n options.provider,\n options.providerDisputeId,\n String(payment.id),\n options.status ?? \"needs_response\",\n options.reason ?? null,\n options.metadata ?? {},\n options.providerUpdatedAt ?? new Date().toISOString(),\n );\n }\n\n async getBillingPayment(\n provider: string,\n providerPaymentId: string,\n ): Promise<Record<string, unknown> | null> {\n const result = await this.billingPayment.getForRefund(provider, providerPaymentId);\n if (!result) return null;\n const row = result as Record<string, unknown>;\n return {\n id: row.id,\n provider: row.provider,\n providerPaymentId: row.provider_payment_id,\n providerInvoiceId: row.provider_invoice_id,\n userId: row.subject_id,\n amountMinor: row.amount_minor == null ? null : Number(row.amount_minor),\n taxMinor: row.tax_minor == null ? null : Number(row.tax_minor),\n currency: row.currency,\n purpose: row.purpose,\n status: row.status,\n providerUpdatedAt: toIso(row.provider_updated_at),\n metadata: row.metadata,\n };\n }\n\n private rowToSubscriptionState(r: Record<string, unknown>): BillingSubscriptionState {\n return {\n subscriptionId: r.id ? String(r.id) : null,\n userId: String(r.user_id),\n provider: String(r.provider),\n providerSubscriptionId: String(r.provider_subscription_id),\n providerCustomerId: r.provider_customer_id ? String(r.provider_customer_id) : null,\n offerId: r.offer_id ? String(r.offer_id) : null,\n offerKey: r.offer_key ? String(r.offer_key) : null,\n plan: r.plan ? String(r.plan) : null,\n status: (r.status ? String(r.status) : \"incomplete\") as BillingSubscriptionStatus,\n currentPeriodStart: toIso(r.current_period_start),\n currentPeriodEnd: toIso(r.current_period_end),\n trialEnd: toIso(r.trial_end),\n cancelAt: toIso(r.cancel_at),\n endedAt: toIso(r.ended_at),\n graceEndsAt: toIso(r.grace_ends_at),\n graceExpiredAt: toIso(r.grace_expired_at),\n providerUpdatedAt: toIso(r.provider_updated_at),\n cancelAtPeriodEnd: Boolean(r.cancel_at_period_end),\n interval: r.interval ? String(r.interval) : null,\n intervalCount: r.interval_count ? Number(r.interval_count) : null,\n metadata:\n r.metadata && typeof r.metadata === \"object\"\n ? (r.metadata as Record<string, unknown>)\n : null,\n };\n }\n\n private async getSubscriptionOfferContexts(r: Record<string, unknown>): Promise<{\n fromOffer: BillingSubscriptionOfferContext;\n toOffer: BillingSubscriptionOfferContext;\n }> {\n const rows = await this.queryFn(\n `SELECT requested.side, requested.offer_id, context.*\n FROM (\n VALUES\n ('from', $1::uuid, $2::uuid),\n ('to', $3::uuid, $4::uuid)\n ) AS requested(side, offer_id, catalog_revision_id)\n CROSS JOIN LATERAL bursar.get_catalog_offer_context(\n requested.offer_id,\n requested.catalog_revision_id\n ) AS context`,\n [r.from_offer_id, r.from_catalog_revision_id, r.to_offer_id, r.to_catalog_revision_id],\n );\n const bySide = new Map(\n rows.map((row) => {\n const context = row as Record<string, unknown>;\n return [String(context.side), context] as const;\n }),\n );\n const mapContext = (side: \"from\" | \"to\"): BillingSubscriptionOfferContext => {\n const context = bySide.get(side);\n if (context?.offer_key == null) {\n throw new Error(`subscription change ${side}-offer context not found`);\n }\n return {\n offerId: String(context.offer_id),\n offerKey: String(context.offer_key),\n planId: context.plan_id ? String(context.plan_id) : null,\n plan: context.plan_key ? String(context.plan_key) : null,\n interval: context.billing_unit ? String(context.billing_unit) : null,\n intervalCount: context.billing_count == null ? null : Number(context.billing_count),\n };\n };\n return { fromOffer: mapContext(\"from\"), toOffer: mapContext(\"to\") };\n }\n\n private async rowToSubscriptionChange(\n r: Record<string, unknown>,\n ): Promise<BillingSubscriptionChange> {\n const { fromOffer, toOffer } = await this.getSubscriptionOfferContexts(r);\n return {\n id: String(r.id),\n subscriptionId: String(r.subscription_id),\n fromOfferId: String(r.from_offer_id),\n toOfferId: String(r.to_offer_id),\n fromOffer,\n toOffer,\n effectiveAt: toIso(r.effective_at),\n effective: String(r.effective_behavior) as BillingSubscriptionChange[\"effective\"],\n state: String(r.state) as BillingSubscriptionChange[\"state\"],\n prorationBehavior: String(\n r.proration_behavior,\n ) as BillingSubscriptionChange[\"prorationBehavior\"],\n idempotencyKey: String(r.idempotency_key),\n providerOperationId: r.provider_operation_id ? String(r.provider_operation_id) : null,\n errorMessage: r.error_message ? String(r.error_message) : null,\n };\n }\n\n async getActiveBursarConfig(): Promise<Record<string, unknown> | null> {\n const rows = await this.queryFn(\"SELECT * FROM bursar.active_catalog_revision()\", []);\n if (!rows || rows.length === 0) return null;\n return (\n ((rows[0] as Record<string, unknown>)?.source_document as Record<string, unknown> | null) ??\n null\n );\n }\n\n async pseudonymizeFinancialSubject(userId: string): Promise<boolean> {\n const rows = await this.queryFn(\n `SELECT bursar.pseudonymize_financial_subject($1::uuid) AS pseudonymized`,\n [userId],\n );\n return (rows[0] as Record<string, unknown> | undefined)?.pseudonymized === true;\n }\n\n async getBillingPreferences(userId: string): Promise<BillingPreferences | null> {\n const row = await this.billingPreferences.get(userId);\n if (!row || row.subject_id == null) return null;\n return {\n userId: String(row.subject_id),\n autoRecharge: Boolean(row.auto_recharge),\n overageProtection: Boolean(row.overage_protection),\n emailNotifications: Boolean(row.email_notifications),\n usageAlerts: Boolean(row.usage_alerts),\n invoiceReminders: Boolean(row.invoice_reminders),\n };\n }\n\n async upsertBillingPreferences(prefs: BillingPreferences): Promise<void> {\n await this.billingPreferences.upsert({\n userId: prefs.userId,\n autoRecharge: prefs.autoRecharge,\n overageProtection: prefs.overageProtection,\n emailNotifications: prefs.emailNotifications,\n usageAlerts: prefs.usageAlerts,\n invoiceReminders: prefs.invoiceReminders,\n });\n }\n\n async getAutoRechargeProfile(userId: string): Promise<BillingAutoRechargeProfile | null> {\n return this.billingAutoRecharge.getProfile(userId);\n }\n\n async upsertAutoRechargeProfile(\n profile: BillingAutoRechargeProfile,\n options?: { resetCooldown?: boolean },\n ): Promise<void> {\n return this.billingAutoRecharge.upsertProfile(profile, options);\n }\n\n async claimAutoRechargeAttempt(\n input: AutoRechargeAttemptClaim,\n ): Promise<BillingAutoRechargeAttempt | null> {\n return this.billingAutoRecharge.claimAttempt(input);\n }\n\n async updateAutoRechargeAttempt(input: AutoRechargeAttemptUpdate): Promise<void> {\n return this.billingAutoRecharge.updateAttempt(input);\n }\n\n async updateAutoRechargeAttemptByProviderPayment(\n input: AutoRechargeProviderPaymentUpdate,\n ): Promise<void> {\n return this.billingAutoRecharge.updateAttemptByProviderPayment(input);\n }\n\n async countAutoRechargeAttempts(userId: string, since: string | Date): Promise<number> {\n return this.billingAutoRecharge.countAttempts(userId, since);\n }\n\n async getBillingCustomerByUserId(\n userId: string,\n provider?: string | null,\n ): Promise<BillingCustomerRecord | null> {\n const result = await this.billingCustomer.getByUserId(userId, provider ?? null);\n if (!result) return null;\n return {\n provider: result.provider,\n providerCustomerId: result.providerCustomerId,\n };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../../src/billing/postgres/store.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAgBxB,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAgBnD,OAAO,EACL,cAAc,GAIf,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAAE,gCAAgC,EAAE,MAAM,6BAA6B,CAAC;AAC/E,OAAO,EACL,iBAAiB,EACjB,SAAS,EACT,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,EAClB,SAAS,GACV,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,sBAAsB,EAAwB,MAAM,yBAAyB,CAAC;AACvF,OAAO,EAAE,sBAAsB,EAAwB,MAAM,yBAAyB,CAAC;AACvF,OAAO,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AACvE,OAA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/B,OAAO,IAAI,CAAC,mBAAmB,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IACtD,CAAC;IAED,KAAK,CAAC,yBAAyB,CAAC,KAAgC;QAC9D,OAAO,IAAI,CAAC,mBAAmB,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IACvD,CAAC;IAED,KAAK,CAAC,0CAA0C,CAC9C,KAAwC;QAExC,OAAO,IAAI,CAAC,mBAAmB,CAAC,8BAA8B,CAAC,KAAK,CAAC,CAAC;IACxE,CAAC;IAED,KAAK,CAAC,yBAAyB,CAAC,MAAc,EAAE,KAAoB;QAClE,OAAO,IAAI,CAAC,mBAAmB,CAAC,aAAa,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAC/D,CAAC;IAED,KAAK,CAAC,0BAA0B,CAC9B,MAAc,EACd,QAAwB;QAExB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,WAAW,CAAC,MAAM,EAAE,QAAQ,IAAI,IAAI,CAAC,CAAC;QAChF,IAAI,CAAC,MAAM;YAAE,OAAO,IAAI,CAAC;QACzB,OAAO;YACL,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,kBAAkB,EAAE,MAAM,CAAC,kBAAkB;SAC9C,CAAC;IACJ,CAAC;CACF","sourcesContent":["import Decimal from \"decimal.js\";\nimport { z } from \"zod\";\nimport type {\n BillingAutoRechargeAttempt,\n BillingAutoRechargeProfile,\n BillingCreditPostingResult,\n BillingCustomerRecord,\n BillingEventClaim,\n BillingOfferResult,\n BillingPaymentRecord,\n BillingPreferences,\n BillingSubscriptionChange,\n BillingSubscriptionChangeInput,\n BillingSubscriptionState,\n CheckoutIntent,\n BillingTopupResult,\n} from \"../types/index.js\";\nimport { BillingStore } from \"../billing-store.js\";\nimport type {\n AutoRechargeAttemptClaim,\n AutoRechargeAttemptUpdate,\n AutoRechargeProviderPaymentUpdate,\n BillingCreditGrantCreate,\n BillingDisputeUpsert,\n BillingInvoiceUpsert,\n BillingPaymentUpsert,\n BillingRefundUpsert,\n BillingSubscriptionChangeUpdate,\n BillingSubscriptionConflictCreate,\n CheckoutIntentCreate,\n CheckoutIntentUpdate,\n} from \"../contracts.js\";\nimport type { QueryFn } from \"../../shared/postgres-types.js\";\nimport {\n PostgresClient,\n type PostgresConnectionOptions,\n type PostgresPool,\n type PostgresPoolConstructor,\n} from \"../../shared/postgres-client.js\";\nimport { StoreClosedError, StoreError } from \"../../errors.js\";\nimport { optionalBoundedDiagnosticMessage } from \"../../shared/diagnostics.js\";\nimport {\n optionalRecordRow,\n pgBoolean,\n postgresUuid,\n requireRecordRow,\n requireResultField,\n safeParse,\n} from \"../../shared/postgres-validation.js\";\nimport { BillingOfferRepository, type BillingOfferRow } from \"./repositories/offer.js\";\nimport { BillingTopupRepository, type BillingTopupRow } from \"./repositories/topup.js\";\nimport { BillingCustomerRepository } from \"./repositories/customer.js\";\nimport {\n BillingSubscriptionRepository,\n type SubscriptionRow,\n} from \"./repositories/subscription.js\";\nimport { BillingEventRepository } from \"./repositories/event.js\";\nimport { BillingPaymentRepository } from \"./repositories/payment.js\";\nimport { BillingRefundRepository } from \"./repositories/refund.js\";\nimport { BillingInvoiceRepository } from \"./repositories/invoice.js\";\nimport { BillingDisputeRepository } from \"./repositories/dispute.js\";\nimport { BillingPreferencesRepository } from \"./repositories/preferences.js\";\nimport { BillingAutoRechargeRepository } from \"./repositories/auto-recharge.js\";\nimport { BillingSubscriptionChangeRepository } from \"./repositories/subscription-change.js\";\n\nconst PgSafeMinorUnitsSchema = z\n .union([z.string().regex(/^\\d+$/), z.number().int().nonnegative().safe()])\n .transform(Number)\n .refine(Number.isSafeInteger, \"minor-unit amount exceeds JavaScript's safe integer range\");\n\nconst BillingCreditPostingRowSchema = z\n .object({\n ledger_entry_id: postgresUuid.nullable(),\n balance_after: z\n .union([z.string(), z.number(), z.instanceof(Decimal)])\n .nullable()\n .transform((value) => (value === null ? null : new Decimal(value))),\n replayed: pgBoolean,\n error_code: z.string().min(1).nullable(),\n })\n .strict()\n .superRefine((row, ctx) => {\n if (row.error_code === null && (row.ledger_entry_id === null || row.balance_after === null)) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: \"successful posting requires ledger_entry_id and balance_after\",\n });\n }\n });\n\nconst CheckoutIntentRowSchema = z\n .object({\n id: postgresUuid,\n subject_id: postgresUuid,\n provider: z.string().min(1),\n checkout_kind: z.enum([\"subscription\", \"credit_topup\"]),\n product_key: z.string().min(1),\n request_digest: z.instanceof(Uint8Array).refine((value) => value.byteLength === 32),\n status: z.enum([\"open\", \"completed\", \"failed\", \"expired\"]),\n provider_session_id: z.string().min(1).nullable(),\n checkout_url: z.string().min(1).nullable(),\n expires_at: z.union([z.string().datetime({ offset: true }), z.date()]),\n })\n .strict();\n\nfunction billingCreditPostingResult(\n rows: readonly unknown[] | null | undefined,\n context: string,\n): BillingCreditPostingResult {\n const raw = requireRecordRow(rows, context);\n const row = safeParse(\n BillingCreditPostingRowSchema,\n {\n ledger_entry_id: raw.ledger_entry_id,\n balance_after: raw.balance_after,\n replayed: raw.replayed,\n error_code: raw.error_code,\n },\n context,\n { indeterminate: true },\n );\n return {\n ledgerEntryId: row.ledger_entry_id,\n balanceAfter: row.balance_after,\n replayed: row.replayed,\n errorCode: row.error_code,\n };\n}\n\nexport interface PostgresBillingStoreOptions extends PostgresConnectionOptions {\n /** PostgreSQL connection string or an application-owned pool. */\n postgres: PostgresPool | string;\n /** Tenant UUID bound to every store transaction. */\n tenantId: string;\n /** Injectable `pg.Pool` constructor for custom runtimes and tests. */\n poolConstructor?: PostgresPoolConstructor;\n billingPayloadBackend?: \"postgres\" | \"s3\";\n}\n\nexport class PostgresBillingStore extends BillingStore {\n private readonly postgres: PostgresClient;\n\n private _offer: BillingOfferRepository | null = null;\n private _topup: BillingTopupRepository | null = null;\n private _customer: BillingCustomerRepository | null = null;\n private _subscription: BillingSubscriptionRepository | null = null;\n private _event: BillingEventRepository | null = null;\n private _payment: BillingPaymentRepository | null = null;\n private _refund: BillingRefundRepository | null = null;\n private _invoice: BillingInvoiceRepository | null = null;\n private _dispute: BillingDisputeRepository | null = null;\n private _preferences: BillingPreferencesRepository | null = null;\n private _autoRecharge: BillingAutoRechargeRepository | null = null;\n private _subscriptionChange: BillingSubscriptionChangeRepository | null = null;\n constructor(options: PostgresBillingStoreOptions) {\n super();\n if (typeof options !== \"object\" || options === null) {\n throw new TypeError(\"PostgresBillingStore options are required\");\n }\n if (typeof options.postgres !== \"string\" && options.poolConstructor !== undefined) {\n throw new TypeError(\"poolConstructor cannot be used with an existing PostgreSQL pool\");\n }\n this.postgres = new PostgresClient(options.postgres, {\n tenantId: options.tenantId,\n poolConstructor: options.poolConstructor,\n billingPayloadBackend: options.billingPayloadBackend,\n connectionTimeoutMs: options.connectionTimeoutMs,\n statementTimeoutMs: options.statementTimeoutMs,\n idleTransactionTimeoutMs: options.idleTransactionTimeoutMs,\n idleTimeoutMs: options.idleTimeoutMs,\n maxConnections: options.maxConnections,\n applicationName: options.applicationName,\n onPoolError: options.onPoolError,\n closedError: () => new StoreClosedError(\"Billing store has been closed\"),\n });\n }\n\n async close(): Promise<void> {\n await this.postgres.close();\n }\n\n private get queryFn(): QueryFn {\n return this.postgres.query;\n }\n\n private get billingOffer(): BillingOfferRepository {\n if (!this._offer) this._offer = new BillingOfferRepository(this.queryFn);\n return this._offer;\n }\n\n private get billingTopup(): BillingTopupRepository {\n if (!this._topup) this._topup = new BillingTopupRepository(this.queryFn);\n return this._topup;\n }\n\n private get billingCustomer(): BillingCustomerRepository {\n if (!this._customer) this._customer = new BillingCustomerRepository(this.queryFn);\n return this._customer;\n }\n\n private get billingSubscription(): BillingSubscriptionRepository {\n if (!this._subscription) this._subscription = new BillingSubscriptionRepository(this.queryFn);\n return this._subscription;\n }\n\n private get billingEvent(): BillingEventRepository {\n if (!this._event) this._event = new BillingEventRepository(this.queryFn);\n return this._event;\n }\n\n private get billingPayment(): BillingPaymentRepository {\n if (!this._payment) this._payment = new BillingPaymentRepository(this.queryFn);\n return this._payment;\n }\n\n private get billingRefund(): BillingRefundRepository {\n if (!this._refund) this._refund = new BillingRefundRepository(this.queryFn);\n return this._refund;\n }\n\n private get billingInvoice(): BillingInvoiceRepository {\n if (!this._invoice) this._invoice = new BillingInvoiceRepository(this.queryFn);\n return this._invoice;\n }\n\n private get billingDispute(): BillingDisputeRepository {\n if (!this._dispute) this._dispute = new BillingDisputeRepository(this.queryFn);\n return this._dispute;\n }\n\n private get billingPreferences(): BillingPreferencesRepository {\n if (!this._preferences) this._preferences = new BillingPreferencesRepository(this.queryFn);\n return this._preferences;\n }\n\n private get billingAutoRecharge(): BillingAutoRechargeRepository {\n if (!this._autoRecharge) this._autoRecharge = new BillingAutoRechargeRepository(this.queryFn);\n return this._autoRecharge;\n }\n\n private get billingSubscriptionChange(): BillingSubscriptionChangeRepository {\n if (!this._subscriptionChange) {\n this._subscriptionChange = new BillingSubscriptionChangeRepository(this.queryFn);\n }\n return this._subscriptionChange;\n }\n\n async createOrGetCheckoutIntent(input: CheckoutIntentCreate): Promise<CheckoutIntent> {\n if (!/^[0-9a-fA-F]{64}$/.test(input.requestDigest)) {\n throw new TypeError(\"requestDigest must be a 32-byte hex string\");\n }\n const rows = await this.queryFn(\n `SELECT bursar.create_checkout_intent($1::uuid, $2, $3, $4, decode($5, 'hex'), $6::timestamptz) AS id`,\n [\n input.subjectId,\n input.provider,\n input.checkoutKind,\n input.productKey,\n input.requestDigest,\n input.expiresAt,\n ],\n );\n const id = requireResultField(\n rows,\n \"id\",\n postgresUuid,\n \"PostgresBillingStore.createOrGetCheckoutIntent\",\n );\n const intent = await this.getCheckoutIntent(id, input.subjectId);\n if (!intent) {\n throw new StoreError(\"checkout intent could not be read after creation\", {\n indeterminate: true,\n details: { checkoutIntentId: id },\n });\n }\n return intent;\n }\n\n async updateCheckoutIntent(id: string, update: CheckoutIntentUpdate): Promise<void> {\n const rows = await this.queryFn(\n `SELECT bursar.advance_checkout_intent($1::uuid, $2, $3, $4) AS advanced`,\n [id, update.status ?? null, update.providerSessionId ?? null, update.checkoutUrl ?? null],\n );\n if (\n !requireResultField(rows, \"advanced\", pgBoolean, \"PostgresBillingStore.updateCheckoutIntent\")\n ) {\n throw new StoreError(`checkout intent transition rejected: ${id}`, {\n details: { checkoutIntentId: id },\n });\n }\n }\n\n async getCheckoutIntent(id: string, subjectId: string): Promise<CheckoutIntent | null> {\n const rows = await this.queryFn(\n `SELECT * FROM bursar.get_checkout_intent($1::uuid, $2::uuid)`,\n [id, subjectId],\n );\n if (rows.length === 0) return null;\n if (rows.length !== 1) {\n throw new StoreError(\"getCheckoutIntent: expected at most one row\", {\n details: { rowCount: rows.length, checkoutIntentId: id },\n });\n }\n const row = rows[0] as Record<string, unknown>;\n return this.rowToCheckoutIntent(\n safeParse(\n CheckoutIntentRowSchema,\n {\n id: row.id,\n subject_id: row.subject_id,\n provider: row.provider,\n checkout_kind: row.checkout_kind,\n product_key: row.product_key,\n request_digest: row.request_digest,\n status: row.status,\n provider_session_id: row.provider_session_id,\n checkout_url: row.checkout_url,\n expires_at: row.expires_at,\n },\n \"PostgresBillingStore.getCheckoutIntent\",\n ),\n );\n }\n\n private rowToCheckoutIntent(row: z.infer<typeof CheckoutIntentRowSchema>): CheckoutIntent {\n return {\n id: row.id,\n subjectId: row.subject_id,\n provider: row.provider,\n checkoutKind: row.checkout_kind,\n productKey: row.product_key,\n requestDigest: Buffer.from(row.request_digest).toString(\"hex\"),\n status: row.status,\n providerSessionId: row.provider_session_id,\n checkoutUrl: row.checkout_url,\n expiresAt: row.expires_at instanceof Date ? row.expires_at.toISOString() : row.expires_at,\n };\n }\n\n private rowToOffer(row: BillingOfferRow | null): BillingOfferResult | null {\n if (!row) return null;\n return {\n offerId: row.id,\n offerKey: row.offerKey,\n planId: row.planId,\n plan: row.plan,\n interval: row.interval,\n intervalCount: row.intervalCount,\n grant:\n row.grantCredits === null\n ? null\n : {\n mode: \"cycle_grant\",\n credits: row.grantCredits,\n bucket: row.grantBucket,\n replacePrior: row.grantReplacePrior,\n },\n };\n }\n\n async resolveBillingOffer(\n provider: string,\n productId?: string | null,\n priceId?: string | null,\n ): Promise<BillingOfferResult | null> {\n const r = await this.billingOffer.resolveByPrice(provider, priceId ?? null, productId ?? null);\n return this.rowToOffer(r);\n }\n\n async resolveBillingOfferByLookup(\n provider: string,\n lookupKey: string,\n ): Promise<BillingOfferResult | null> {\n const r = await this.billingOffer.resolveByLookup(provider, lookupKey);\n return this.rowToOffer(r);\n }\n\n async claimBillingEvent(\n provider: string,\n eventId: string,\n eventType: string,\n envelope?: Record<string, unknown>,\n ): Promise<BillingEventClaim> {\n const result = await this.billingEvent.claim(\n provider,\n eventId,\n eventType,\n JSON.stringify(envelope ?? { eventType }),\n );\n if (result.status === \"claimed\") {\n if (result.claim_token === null || result.event_id === null) {\n throw new StoreError(\"Billing event claim returned no claim identifiers\", {\n details: { provider, eventId },\n });\n }\n return {\n status: \"claimed\" as const,\n claimToken: result.claim_token,\n billingEventId: result.event_id,\n };\n }\n if (result.status === \"duplicate\") return { status: \"duplicate\" as const };\n if (result.status === \"busy\") return { status: \"busy\" as const };\n if (\n result.status === \"invalid_request\" ||\n result.status === \"idempotency_conflict\" ||\n result.status === \"max_retries_exceeded\"\n ) {\n return { status: \"retry\" as const };\n }\n throw new StoreError(\"Billing event claim returned an unsupported status\", {\n details: { provider, eventId, status: result.status },\n });\n }\n\n async completeBillingEvent(\n provider: string,\n eventId: string,\n claimToken: string,\n ): Promise<boolean> {\n return this.billingEvent.complete(provider, eventId, claimToken);\n }\n\n async failBillingEvent(\n provider: string,\n eventId: string,\n claimToken: string,\n error?: string,\n ): Promise<boolean> {\n return this.billingEvent.fail(\n provider,\n eventId,\n claimToken,\n optionalBoundedDiagnosticMessage(error) ?? undefined,\n );\n }\n\n async upsertBillingCustomer(\n provider: string,\n providerCustomerId: string,\n userId: string,\n email?: string | null,\n ): Promise<void> {\n await this.billingCustomer.upsert(provider, providerCustomerId, userId, email ?? null);\n }\n\n async upsertBillingSubscription(state: BillingSubscriptionState): Promise<void> {\n await this.billingSubscription.upsert(state);\n }\n\n async getBillingCustomer(provider: string, providerCustomerId: string): Promise<string | null> {\n return this.billingCustomer.get(provider, providerCustomerId);\n }\n\n async getBillingSubscription(\n provider: string,\n providerSubscriptionId: string,\n ): Promise<BillingSubscriptionState | null> {\n const r = await this.billingSubscription.get(provider, providerSubscriptionId);\n if (!r) return null;\n return this.rowToSubscriptionState(r);\n }\n\n async createBillingSubscriptionChange(\n input: BillingSubscriptionChangeInput,\n ): Promise<BillingSubscriptionChange> {\n const subscription = await this.billingSubscription.get(\n input.provider,\n input.providerSubscriptionId,\n );\n if (!subscription?.id) {\n throw new StoreError(\"subscription change requires a persisted subscription\", {\n retryable: true,\n details: {\n provider: input.provider,\n providerSubscriptionId: input.providerSubscriptionId,\n },\n });\n }\n return this.billingSubscriptionChange.create(subscription.id, input);\n }\n\n async getOpenBillingSubscriptionChange(\n provider: string,\n providerSubscriptionId: string,\n ): Promise<BillingSubscriptionChange | null> {\n return this.billingSubscriptionChange.getOpen(provider, providerSubscriptionId);\n }\n\n async listExpiredGraceSubscriptions(\n now: string,\n limit = 100,\n ): Promise<BillingSubscriptionState[]> {\n const rows = await this.billingSubscription.listExpiredGraceSubscriptions(now, limit);\n return rows.map((row) => this.rowToSubscriptionState(row));\n }\n\n async markSubscriptionGraceExpired(\n subscriptionId: string,\n expectedGraceEndsAt: string,\n expiredAt = new Date().toISOString(),\n ): Promise<boolean> {\n return this.billingSubscription.markGraceExpired(\n subscriptionId,\n expectedGraceEndsAt,\n expiredAt,\n );\n }\n\n async updateBillingSubscriptionChange(\n id: string,\n update: BillingSubscriptionChangeUpdate,\n ): Promise<void> {\n await this.billingSubscriptionChange.update(id, update);\n }\n\n async getUserSubscription(\n userId: string,\n statuses?: string[],\n ): Promise<BillingSubscriptionState | null> {\n const r = await this.billingSubscription.getUserSubscription(userId, statuses);\n if (!r) return null;\n return this.rowToSubscriptionState(r);\n }\n\n async getUserSubscriptions(userId: string): Promise<BillingSubscriptionState[]> {\n const rows = await this.billingSubscription.getUserSubscriptions(userId);\n return rows.map((r) => this.rowToSubscriptionState(r));\n }\n\n async recordSubscriptionConflict(input: BillingSubscriptionConflictCreate): Promise<void> {\n await this.billingSubscription.recordConflict(input);\n }\n\n async selectSubscriptionEntitlementSource(\n userId: string,\n provider: string,\n providerSubscriptionId?: string | null,\n ): Promise<boolean> {\n return this.billingSubscription.selectEntitlementSource(\n userId,\n provider,\n providerSubscriptionId,\n );\n }\n\n private rowToTopup(r: BillingTopupRow | null): BillingTopupResult | null {\n if (!r) return null;\n const minAmountMinor = safeParse(\n PgSafeMinorUnitsSchema,\n r.amount_minor * r.min_quantity,\n \"PostgresBillingStore.rowToTopup.minAmountMinor\",\n );\n const maxAmountMinor = safeParse(\n PgSafeMinorUnitsSchema,\n r.amount_minor * r.max_quantity,\n \"PostgresBillingStore.rowToTopup.maxAmountMinor\",\n );\n return {\n topupId: r.id,\n topupKey: r.topup_key,\n creditsPerUnit: r.credits_per_unit,\n depositTo: r.bucket_key,\n amountMinor: r.amount_minor,\n currency: r.currency,\n minQuantity: r.min_quantity,\n maxQuantity: r.max_quantity,\n defaultQuantity: r.default_quantity,\n minAmountMinor,\n maxAmountMinor,\n };\n }\n\n async resolveCreditTopup(\n provider: string,\n productId?: string | null,\n priceId?: string | null,\n ): Promise<BillingTopupResult | null> {\n const r = await this.billingTopup.resolveByPrice(provider, priceId ?? null, productId ?? null);\n return this.rowToTopup(r);\n }\n\n async resolveCreditTopupByLookup(\n provider: string,\n lookupKey: string,\n ): Promise<BillingTopupResult | null> {\n const r = await this.billingTopup.resolveByLookup(provider, lookupKey);\n return this.rowToTopup(r);\n }\n\n async computeTopupCredits(\n amountMinor: number,\n topupConfig: BillingTopupResult,\n ): Promise<Decimal> {\n if (!Number.isSafeInteger(amountMinor) || amountMinor < 0) {\n throw new TypeError(\"amountMinor must be a non-negative safe integer\");\n }\n const unitAmount = topupConfig.amountMinor;\n if (unitAmount <= 0 || amountMinor % unitAmount !== 0) return new Decimal(0);\n const quantity = amountMinor / unitAmount;\n if (quantity < topupConfig.minQuantity || quantity > topupConfig.maxQuantity) {\n return new Decimal(0);\n }\n return topupConfig.creditsPerUnit.mul(quantity);\n }\n\n async upsertBillingPayment(options: BillingPaymentUpsert): Promise<string> {\n return this.billingPayment.upsert(\n options.provider,\n options.providerPaymentId,\n options.providerInvoiceId ?? null,\n options.userId,\n options.amountMinor,\n options.taxMinor,\n options.currency,\n options.purpose,\n options.metadata ? JSON.stringify(options.metadata) : null,\n options.status,\n options.providerUpdatedAt,\n );\n }\n\n async createBillingCreditGrant(input: BillingCreditGrantCreate): Promise<string> {\n const rows = await this.queryFn(\n \"SELECT bursar.create_billing_credit_grant($1::uuid, $2::uuid, $3::uuid, $4, $5, $6::uuid) AS id\",\n [\n input.paymentId ?? null,\n input.subscriptionId ?? null,\n input.topupId ?? null,\n input.configuredCredits.toString(),\n input.quantity,\n input.billingEventId ?? null,\n ],\n );\n return requireResultField(\n rows,\n \"id\",\n postgresUuid,\n \"PostgresBillingStore.createBillingCreditGrant\",\n );\n }\n\n async grantBillingCredit(\n grantId: string,\n idempotencyKey: string,\n ): Promise<BillingCreditPostingResult> {\n const rows = await this.queryFn(\"SELECT * FROM bursar.grant_billing_credit($1::uuid, $2)\", [\n grantId,\n idempotencyKey,\n ]);\n return billingCreditPostingResult(rows, \"PostgresBillingStore.grantBillingCredit\");\n }\n\n async getBillingCreditGrantByPayment(paymentId: string): Promise<string | null> {\n const rows = await this.queryFn(\n `SELECT * FROM bursar.get_billing_credit_grant_by_payment($1::uuid)`,\n [paymentId],\n );\n const row = optionalRecordRow(rows, \"PostgresBillingStore.getBillingCreditGrantByPayment\");\n return row === null\n ? null\n : safeParse(postgresUuid, row.id, \"PostgresBillingStore.getBillingCreditGrantByPayment.id\");\n }\n\n async postBillingRefund(\n refundId: string,\n grantId: string,\n amountMinor: number,\n idempotencyKey: string,\n ): Promise<BillingCreditPostingResult> {\n const rows = await this.queryFn(\n \"SELECT * FROM bursar.post_billing_refund($1::uuid, $2::uuid, $3, $4)\",\n [refundId, grantId, amountMinor, idempotencyKey],\n );\n return billingCreditPostingResult(rows, \"PostgresBillingStore.postBillingRefund\");\n }\n\n async upsertBillingRefund(options: BillingRefundUpsert): Promise<string> {\n return this.billingRefund.upsert(\n options.provider,\n options.providerRefundId,\n options.providerPaymentId,\n options.userId,\n options.amountMinor,\n options.currency,\n options.reason ?? null,\n options.metadata ? JSON.stringify(options.metadata) : null,\n options.status,\n options.providerUpdatedAt,\n );\n }\n\n async upsertBillingInvoice(options: BillingInvoiceUpsert): Promise<void> {\n const subscription = options.providerSubscriptionId\n ? await this.billingSubscription.get(options.provider, options.providerSubscriptionId)\n : null;\n if (options.providerSubscriptionId && !subscription) {\n throw new StoreError(\"invoice subscription is not available\", {\n retryable: true,\n details: {\n provider: options.provider,\n providerInvoiceId: options.providerInvoiceId,\n providerSubscriptionId: options.providerSubscriptionId ?? null,\n },\n });\n }\n await this.billingInvoice.upsert(\n options.userId,\n options.provider,\n options.providerInvoiceId,\n subscription?.id ? String(subscription.id) : null,\n options.status,\n options.amountDueMinor,\n options.amountPaidMinor,\n options.currency,\n options.periodStart ?? null,\n options.periodEnd ?? null,\n options.metadata ?? {},\n options.providerUpdatedAt,\n );\n }\n\n async listBillingInvoices(userId: string) {\n return this.billingInvoice.listForUser(userId);\n }\n\n async upsertBillingDispute(options: BillingDisputeUpsert): Promise<void> {\n const payment = await this.billingPayment.getForRefund(\n options.provider,\n options.providerPaymentId,\n );\n if (!payment?.id) {\n throw new StoreError(\"dispute payment is required\", {\n retryable: true,\n details: {\n provider: options.provider,\n providerDisputeId: options.providerDisputeId,\n providerPaymentId: options.providerPaymentId ?? null,\n },\n });\n }\n await this.billingDispute.upsert(\n options.provider,\n options.providerDisputeId,\n String(payment.id),\n options.status,\n options.reason ?? null,\n options.metadata ?? {},\n options.providerUpdatedAt,\n );\n }\n\n async getBillingPayment(\n provider: string,\n providerPaymentId: string,\n ): Promise<BillingPaymentRecord | null> {\n const row = await this.billingPayment.getForRefund(provider, providerPaymentId);\n if (!row) return null;\n return {\n id: row.id,\n provider: row.provider,\n providerPaymentId: row.provider_payment_id,\n providerInvoiceId: row.provider_invoice_id,\n userId: row.subject_id,\n amountMinor: safeParse(\n PgSafeMinorUnitsSchema,\n row.amount_minor,\n \"PostgresBillingStore.getBillingPayment.amountMinor\",\n ),\n taxMinor: safeParse(\n PgSafeMinorUnitsSchema,\n row.tax_minor,\n \"PostgresBillingStore.getBillingPayment.taxMinor\",\n ),\n currency: row.currency,\n purpose: row.purpose,\n status: row.status,\n providerUpdatedAt:\n row.provider_updated_at instanceof Date\n ? row.provider_updated_at.toISOString()\n : row.provider_updated_at,\n metadata: row.metadata,\n };\n }\n\n private rowToSubscriptionState(r: SubscriptionRow): BillingSubscriptionState {\n return {\n subscriptionId: r.id,\n userId: r.user_id,\n provider: r.provider,\n providerSubscriptionId: r.provider_subscription_id,\n providerCustomerId: r.provider_customer_id,\n offerId: r.offer_id,\n offerKey: r.offer_key,\n planId: r.plan_id,\n plan: r.plan,\n status: r.status,\n currentPeriodStart: r.current_period_start,\n currentPeriodEnd: r.current_period_end,\n trialEnd: r.trial_end,\n cancelAt: r.cancel_at,\n endedAt: r.ended_at,\n graceEndsAt: r.grace_ends_at,\n graceExpiredAt: r.grace_expired_at,\n providerUpdatedAt: r.provider_updated_at,\n cancelAtPeriodEnd: r.cancel_at_period_end,\n interval: r.interval,\n intervalCount: r.interval_count,\n metadata: r.metadata,\n };\n }\n\n async getActiveCatalogDocument(): Promise<Record<string, unknown> | null> {\n const rows = await this.queryFn(\"SELECT * FROM bursar.active_catalog_revision()\", []);\n if (rows.length === 0) return null;\n if (rows.length !== 1 || typeof rows[0] !== \"object\" || rows[0] === null) {\n throw new StoreError(\"active catalog revision returned a malformed row\", {\n details: { rowCount: rows.length },\n });\n }\n return safeParse(\n z.record(z.string(), z.unknown()),\n (rows[0] as Record<string, unknown>).source_document,\n \"PostgresBillingStore.getActiveCatalogDocument\",\n );\n }\n\n async pseudonymizeFinancialSubject(userId: string): Promise<boolean> {\n const rows = await this.queryFn(\n `SELECT bursar.pseudonymize_financial_subject($1::uuid) AS pseudonymized`,\n [userId],\n );\n return requireResultField(\n rows,\n \"pseudonymized\",\n pgBoolean,\n \"PostgresBillingStore.pseudonymizeFinancialSubject\",\n );\n }\n\n async getBillingPreferences(userId: string): Promise<BillingPreferences | null> {\n return this.billingPreferences.get(userId);\n }\n\n async upsertBillingPreferences(prefs: BillingPreferences): Promise<void> {\n await this.billingPreferences.upsert(prefs);\n }\n\n async getAutoRechargeProfile(userId: string): Promise<BillingAutoRechargeProfile | null> {\n return this.billingAutoRecharge.getProfile(userId);\n }\n\n async upsertAutoRechargeProfile(\n profile: BillingAutoRechargeProfile,\n options?: { resetCooldown?: boolean },\n ): Promise<void> {\n return this.billingAutoRecharge.upsertProfile(profile, options);\n }\n\n async claimAutoRechargeAttempt(\n input: AutoRechargeAttemptClaim,\n ): Promise<BillingAutoRechargeAttempt | null> {\n return this.billingAutoRecharge.claimAttempt(input);\n }\n\n async updateAutoRechargeAttempt(input: AutoRechargeAttemptUpdate): Promise<void> {\n return this.billingAutoRecharge.updateAttempt(input);\n }\n\n async updateAutoRechargeAttemptByProviderPayment(\n input: AutoRechargeProviderPaymentUpdate,\n ): Promise<void> {\n return this.billingAutoRecharge.updateAttemptByProviderPayment(input);\n }\n\n async countAutoRechargeAttempts(userId: string, since: string | Date): Promise<number> {\n return this.billingAutoRecharge.countAttempts(userId, since);\n }\n\n async getBillingCustomerByUserId(\n userId: string,\n provider?: string | null,\n ): Promise<BillingCustomerRecord | null> {\n const result = await this.billingCustomer.getByUserId(userId, provider ?? null);\n if (!result) return null;\n return {\n provider: result.provider,\n providerCustomerId: result.providerCustomerId,\n };\n }\n}\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type Decimal from "decimal.js";
|
|
2
2
|
import type { Logger } from "../shared/logger.js";
|
|
3
|
+
import type { AddCreditsResult, RevokeCreditsResult, SetUserPlanResult, UnsetUserPlanResult } from "../credits/types/index.js";
|
|
3
4
|
import type { BillingEventHandler, BillingEventType } from "./types/index.js";
|
|
4
5
|
export type ResolveUser = (provider: string, providerCustomerId: string | null, email: string | null) => string | null;
|
|
5
6
|
export interface BillingServiceOptions {
|
|
@@ -21,17 +22,17 @@ export interface BillingProvisioningPort {
|
|
|
21
22
|
getUserPlan?(userId: string): Promise<{
|
|
22
23
|
planAssignedAt?: Date | string | null;
|
|
23
24
|
} | null>;
|
|
24
|
-
setUserPlan(userId: string, planKey: string, planAssignedAt?: Date | null): Promise<
|
|
25
|
-
unsetUserPlan(userId: string): Promise<
|
|
25
|
+
setUserPlan(userId: string, planKey: string, planAssignedAt?: Date | null): Promise<SetUserPlanResult>;
|
|
26
|
+
unsetUserPlan(userId: string): Promise<UnsetUserPlanResult>;
|
|
26
27
|
addCredits(userId: string, amount: Decimal | number, options?: {
|
|
27
28
|
type?: string;
|
|
28
29
|
bucket?: string | null;
|
|
29
30
|
idempotencyKey?: string | null;
|
|
30
|
-
}): Promise<
|
|
31
|
+
}): Promise<AddCreditsResult>;
|
|
31
32
|
deductCredits(userId: string, amount: Decimal | number, options?: {
|
|
32
33
|
entryType?: string;
|
|
33
34
|
bucket?: string | null;
|
|
34
|
-
}): Promise<
|
|
35
|
-
revokeCreditsByEntryType(userId: string, entryType: string): Promise<
|
|
35
|
+
}): Promise<AddCreditsResult>;
|
|
36
|
+
revokeCreditsByEntryType(userId: string, entryType: string): Promise<RevokeCreditsResult>;
|
|
36
37
|
}
|
|
37
38
|
//# sourceMappingURL=service-types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service-types.d.ts","sourceRoot":"","sources":["../../src/billing/service-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,YAAY,CAAC;AAEtC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAA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gB,CAAC,CAAC;IAC7B,aAAa,CACX,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,OAAO,GAAG,MAAM,EACxB,OAAO,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,GACvD,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAC7B,wBAAwB,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;CAC3F"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service-types.js","sourceRoot":"","sources":["../../src/billing/service-types.ts"],"names":[],"mappings":"","sourcesContent":["import type Decimal from \"decimal.js\";\n\nimport type { Logger } from \"../shared/logger.js\";\nimport type { BillingEventHandler, BillingEventType } from \"./types/index.js\";\n\nexport type ResolveUser = (\n provider: string,\n providerCustomerId: string | null,\n email: string | null,\n) => string | null;\n\nexport interface BillingServiceOptions {\n provisioning?: BillingProvisioningPort | null;\n resolveUser?: ResolveUser | null;\n eventHandlers?: Partial<Record<BillingEventType, BillingEventHandler>>;\n autoSelectEntitlementSource?: boolean;\n /** Access grace after a failed subscription payment. Defaults to seven days. */\n pastDueGracePeriodMs?: number;\n /** Plan assigned when a paid subscription reaches terminal state. */\n terminalPlanKey?: string | null;\n logger?: Logger | null;\n}\n\n/**\n * The narrow credit capability billing may request during subscription\n * provisioning. Billing does not depend on the full credit service.\n */\nexport interface BillingProvisioningPort {\n getUserPlan?(userId: string): Promise<{ planAssignedAt?: Date | string | null } | null>;\n setUserPlan(userId: string
|
|
1
|
+
{"version":3,"file":"service-types.js","sourceRoot":"","sources":["../../src/billing/service-types.ts"],"names":[],"mappings":"","sourcesContent":["import type Decimal from \"decimal.js\";\n\nimport type { Logger } from \"../shared/logger.js\";\nimport type {\n AddCreditsResult,\n RevokeCreditsResult,\n SetUserPlanResult,\n UnsetUserPlanResult,\n} from \"../credits/types/index.js\";\nimport type { BillingEventHandler, BillingEventType } from \"./types/index.js\";\n\nexport type ResolveUser = (\n provider: string,\n providerCustomerId: string | null,\n email: string | null,\n) => string | null;\n\nexport interface BillingServiceOptions {\n provisioning?: BillingProvisioningPort | null;\n resolveUser?: ResolveUser | null;\n eventHandlers?: Partial<Record<BillingEventType, BillingEventHandler>>;\n autoSelectEntitlementSource?: boolean;\n /** Access grace after a failed subscription payment. Defaults to seven days. */\n pastDueGracePeriodMs?: number;\n /** Plan assigned when a paid subscription reaches terminal state. */\n terminalPlanKey?: string | null;\n logger?: Logger | null;\n}\n\n/**\n * The narrow credit capability billing may request during subscription\n * provisioning. Billing does not depend on the full credit service.\n */\nexport interface BillingProvisioningPort {\n getUserPlan?(userId: string): Promise<{ planAssignedAt?: Date | string | null } | null>;\n setUserPlan(\n userId: string,\n planKey: string,\n planAssignedAt?: Date | null,\n ): Promise<SetUserPlanResult>;\n unsetUserPlan(userId: string): Promise<UnsetUserPlanResult>;\n addCredits(\n userId: string,\n amount: Decimal | number,\n options?: {\n type?: string;\n bucket?: string | null;\n idempotencyKey?: string | null;\n },\n ): Promise<AddCreditsResult>;\n deductCredits(\n userId: string,\n amount: Decimal | number,\n options?: { entryType?: string; bucket?: string | null },\n ): Promise<AddCreditsResult>;\n revokeCreditsByEntryType(userId: string, entryType: string): Promise<RevokeCreditsResult>;\n}\n"]}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import type Decimal from "decimal.js";
|
|
1
2
|
export declare const AUTO_RECHARGE_STATES: readonly ["disabled", "active", "paused"];
|
|
2
3
|
export type BillingAutoRechargeState = (typeof AUTO_RECHARGE_STATES)[number];
|
|
4
|
+
export type BillingAutoRechargeAttemptState = "claimed" | "submitted" | "processing" | "unknown" | "succeeded" | "failed" | "action_required";
|
|
3
5
|
export interface BillingAutoRechargeProfile {
|
|
4
6
|
userId: string;
|
|
5
7
|
enabled: boolean;
|
|
@@ -8,11 +10,11 @@ export interface BillingAutoRechargeProfile {
|
|
|
8
10
|
provider: string | null;
|
|
9
11
|
topupId: string | null;
|
|
10
12
|
quantity: number;
|
|
11
|
-
threshold:
|
|
13
|
+
threshold: Decimal;
|
|
12
14
|
maxChargesPerWindow: number | null;
|
|
13
15
|
windowUnit: "second" | "minute" | "hour" | "day" | "week" | "month" | "year";
|
|
14
16
|
windowCount: number;
|
|
15
|
-
windowAnchor: "calendar" | "
|
|
17
|
+
windowAnchor: "calendar" | "rolling";
|
|
16
18
|
windowTimezone: string;
|
|
17
19
|
updatedAt?: string | null;
|
|
18
20
|
}
|
|
@@ -24,7 +26,7 @@ export interface BillingAutoRechargeAttempt {
|
|
|
24
26
|
providerAttemptId: string | null;
|
|
25
27
|
topupId: string;
|
|
26
28
|
quantity: number;
|
|
27
|
-
state:
|
|
29
|
+
state: BillingAutoRechargeAttemptState;
|
|
28
30
|
windowStart: string;
|
|
29
31
|
windowEnd: string;
|
|
30
32
|
quotedAmountMinor: number | null;
|
|
@@ -38,7 +40,7 @@ export interface BillingAutoRechargeAttempt {
|
|
|
38
40
|
export interface BillingAutoRechargeStatus {
|
|
39
41
|
enabled: boolean;
|
|
40
42
|
state: BillingAutoRechargeState;
|
|
41
|
-
thresholdCredits:
|
|
43
|
+
thresholdCredits: Decimal;
|
|
42
44
|
topupKey: string;
|
|
43
45
|
quantity: number;
|
|
44
46
|
maxRecharges: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auto-recharge.d.ts","sourceRoot":"","sources":["../../../src/billing/types/auto-recharge.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,2CAA4C,CAAC;AAC9E,MAAM,MAAM,wBAAwB,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE7E,MAAM,WAAW,0BAA0B;IACzC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,wBAAwB,CAAC;IAChC,KAAK,CAAC,EAAE,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Root":"","sources":["../../../src/billing/types/auto-recharge.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"auto-recharge.js","sourceRoot":"","sources":["../../../src/billing/types/auto-recharge.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,UAAU,EAAE,QAAQ,EAAE,QAAQ,CAAU,CAAC","sourcesContent":["import type Decimal from \"decimal.js\";\n\nexport const AUTO_RECHARGE_STATES = [\"disabled\", \"active\", \"paused\"] as const;\nexport type BillingAutoRechargeState = (typeof AUTO_RECHARGE_STATES)[number];\n\nexport type BillingAutoRechargeAttemptState =\n | \"claimed\"\n | \"submitted\"\n | \"processing\"\n | \"unknown\"\n | \"succeeded\"\n | \"failed\"\n | \"action_required\";\n\nexport interface BillingAutoRechargeProfile {\n userId: string;\n enabled: boolean;\n state: BillingAutoRechargeState;\n armed?: boolean;\n provider: string | null;\n topupId: string | null;\n quantity: number;\n threshold: Decimal;\n maxChargesPerWindow: number | null;\n windowUnit: \"second\" | \"minute\" | \"hour\" | \"day\" | \"week\" | \"month\" | \"year\";\n windowCount: number;\n windowAnchor: \"calendar\" | \"rolling\";\n windowTimezone: string;\n updatedAt?: string | null;\n}\n\nexport interface BillingAutoRechargeAttempt {\n id: string;\n userId: string;\n provider: string;\n idempotencyKey: string;\n providerAttemptId: string | null;\n topupId: string;\n quantity: number;\n state: BillingAutoRechargeAttemptState;\n windowStart: string;\n windowEnd: string;\n quotedAmountMinor: number | null;\n currency: string | null;\n failureCode: string | null;\n failureMessage: string | null;\n metadata: Record<string, unknown>;\n createdAt: string;\n updatedAt: string;\n}\n\nexport interface BillingAutoRechargeStatus {\n enabled: boolean;\n state: BillingAutoRechargeState;\n thresholdCredits: Decimal;\n topupKey: string;\n quantity: number;\n maxRecharges: number;\n windowStart: string;\n windowEnd: string;\n rechargesInWindow: number;\n paymentMethodId: string | null;\n paymentMethodLast4: string | null;\n paymentMethodBrand: string | null;\n suspendedReason: string | null;\n pendingAttemptId: string | null;\n quoteAmountMinor: number | null;\n quoteCurrency: string | null;\n}\n"]}
|
|
@@ -1,47 +1,30 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type Decimal from "decimal.js";
|
|
2
2
|
export interface BillingGrantResult {
|
|
3
|
-
mode
|
|
4
|
-
credits
|
|
5
|
-
bucket
|
|
6
|
-
replacePrior
|
|
3
|
+
mode: "cycle_grant";
|
|
4
|
+
credits: Decimal;
|
|
5
|
+
bucket: string;
|
|
6
|
+
replacePrior: boolean;
|
|
7
7
|
}
|
|
8
8
|
export interface BillingOfferResult {
|
|
9
9
|
offerId: string;
|
|
10
10
|
offerKey: string;
|
|
11
|
-
planId
|
|
12
|
-
plan
|
|
13
|
-
interval
|
|
14
|
-
intervalCount
|
|
15
|
-
grant
|
|
11
|
+
planId: string;
|
|
12
|
+
plan: string;
|
|
13
|
+
interval: "day" | "week" | "month" | "year";
|
|
14
|
+
intervalCount: number;
|
|
15
|
+
grant: BillingGrantResult | null;
|
|
16
16
|
}
|
|
17
17
|
export interface BillingTopupResult {
|
|
18
18
|
topupId: string;
|
|
19
19
|
topupKey: string;
|
|
20
|
-
creditsPerUnit
|
|
21
|
-
depositTo?: string;
|
|
22
|
-
amountMinor?: number;
|
|
23
|
-
currency?: string;
|
|
24
|
-
minQuantity?: number;
|
|
25
|
-
maxQuantity?: number;
|
|
26
|
-
defaultQuantity?: number;
|
|
27
|
-
minAmountMinor?: number;
|
|
28
|
-
maxAmountMinor?: number;
|
|
29
|
-
}
|
|
30
|
-
export interface BillingOffer {
|
|
31
|
-
plan: string;
|
|
32
|
-
interval?: BillingOfferInterval;
|
|
33
|
-
intervalCount?: number;
|
|
34
|
-
grant?: SubscriptionGrant;
|
|
35
|
-
providers?: Record<string, ProviderRef>;
|
|
36
|
-
validFrom?: string | null;
|
|
37
|
-
validTo?: string | null;
|
|
38
|
-
}
|
|
39
|
-
export interface BillingCreditTopup {
|
|
20
|
+
creditsPerUnit: Decimal;
|
|
40
21
|
depositTo: string;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
22
|
+
amountMinor: number;
|
|
23
|
+
currency: string;
|
|
24
|
+
minQuantity: number;
|
|
25
|
+
maxQuantity: number;
|
|
26
|
+
defaultQuantity: number;
|
|
27
|
+
minAmountMinor: number;
|
|
28
|
+
maxAmountMinor: number;
|
|
46
29
|
}
|
|
47
30
|
//# sourceMappingURL=catalog.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../../../src/billing/types/catalog.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../../../src/billing/types/catalog.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,YAAY,CAAC;AAEtC,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,aAAa,CAAC;IACpB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;IAC5C,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,kBAAkB,GAAG,IAAI,CAAC;CAClC;AAED,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,OAAO,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;CACxB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"catalog.js","sourceRoot":"","sources":["../../../src/billing/types/catalog.ts"],"names":[],"mappings":"","sourcesContent":["import type
|
|
1
|
+
{"version":3,"file":"catalog.js","sourceRoot":"","sources":["../../../src/billing/types/catalog.ts"],"names":[],"mappings":"","sourcesContent":["import type Decimal from \"decimal.js\";\n\nexport interface BillingGrantResult {\n mode: \"cycle_grant\";\n credits: Decimal;\n bucket: string;\n replacePrior: boolean;\n}\n\nexport interface BillingOfferResult {\n offerId: string;\n offerKey: string;\n planId: string;\n plan: string;\n interval: \"day\" | \"week\" | \"month\" | \"year\";\n intervalCount: number;\n grant: BillingGrantResult | null;\n}\n\nexport interface BillingTopupResult {\n topupId: string;\n topupKey: string;\n creditsPerUnit: Decimal;\n depositTo: string;\n amountMinor: number;\n currency: string;\n minQuantity: number;\n maxQuantity: number;\n defaultQuantity: number;\n minAmountMinor: number;\n maxAmountMinor: number;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/billing/types/common.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/billing/types/common.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,oBAAoB,GAAG,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;AAErE,MAAM,MAAM,eAAe,GAAG,WAAW,GAAG,aAAa,CAAC;AAE1D,MAAM,WAAW,WAAW;IAC1B,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,CAAC,EAAE,eAAe,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/billing/types/common.ts"],"names":[],"mappings":"","sourcesContent":["export type
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/billing/types/common.ts"],"names":[],"mappings":"","sourcesContent":["export type BillingOfferInterval = \"day\" | \"week\" | \"month\" | \"year\";\n\nexport type EntitlementMode = \"allowance\" | \"cycle_grant\";\n\nexport interface ProviderRef {\n productId?: string | null;\n priceId?: string | null;\n variantId?: string | null;\n lookupKey?: string | null;\n}\n\nexport interface SubscriptionGrant {\n mode?: EntitlementMode;\n credits?: number | null;\n bucket?: string | null;\n replacePrior?: boolean;\n}\n"]}
|
|
@@ -1,39 +1,65 @@
|
|
|
1
|
+
import type Decimal from "decimal.js";
|
|
1
2
|
import type { ProviderRef } from "./common.js";
|
|
2
3
|
export interface BillingCustomerInfo {
|
|
3
4
|
providerCustomerId?: string | null;
|
|
4
5
|
email?: string | null;
|
|
5
6
|
}
|
|
6
7
|
export interface BillingInvoiceInfo {
|
|
7
|
-
provider?: string;
|
|
8
8
|
providerInvoiceId: string;
|
|
9
|
-
status
|
|
10
|
-
amountPaidMinor
|
|
11
|
-
amountDueMinor
|
|
12
|
-
currency
|
|
9
|
+
status: "draft" | "open" | "paid" | "void" | "uncollectible";
|
|
10
|
+
amountPaidMinor: number;
|
|
11
|
+
amountDueMinor: number;
|
|
12
|
+
currency: string;
|
|
13
13
|
periodStart?: string | null;
|
|
14
14
|
periodEnd?: string | null;
|
|
15
15
|
}
|
|
16
|
+
/** Persisted invoice document returned from account-level billing queries. */
|
|
17
|
+
export interface BillingInvoiceRecord extends BillingInvoiceInfo {
|
|
18
|
+
provider: string;
|
|
19
|
+
}
|
|
16
20
|
export interface BillingPaymentInfo {
|
|
17
21
|
providerPaymentId: string;
|
|
18
22
|
amountMinor: number;
|
|
19
|
-
taxMinor
|
|
23
|
+
taxMinor: number;
|
|
20
24
|
currency: string;
|
|
21
25
|
refs?: ProviderRef | null;
|
|
22
|
-
purpose: "subscription" | "credit_topup"
|
|
23
|
-
status
|
|
26
|
+
purpose: "subscription" | "credit_topup";
|
|
27
|
+
status: "pending" | "succeeded" | "failed" | "canceled";
|
|
28
|
+
}
|
|
29
|
+
/** Persisted payment state used by billing lifecycle handlers. */
|
|
30
|
+
export interface BillingPaymentRecord {
|
|
31
|
+
id: string;
|
|
32
|
+
provider: string;
|
|
33
|
+
providerPaymentId: string;
|
|
34
|
+
providerInvoiceId: string | null;
|
|
35
|
+
userId: string;
|
|
36
|
+
amountMinor: number;
|
|
37
|
+
taxMinor: number;
|
|
38
|
+
currency: string;
|
|
39
|
+
purpose: "subscription" | "credit_topup";
|
|
40
|
+
status: "pending" | "succeeded" | "failed" | "canceled";
|
|
41
|
+
providerUpdatedAt: string;
|
|
42
|
+
metadata: Record<string, unknown>;
|
|
43
|
+
}
|
|
44
|
+
/** Result of posting a billing grant or refund to the credit ledger. */
|
|
45
|
+
export interface BillingCreditPostingResult {
|
|
46
|
+
ledgerEntryId: string | null;
|
|
47
|
+
balanceAfter: Decimal | null;
|
|
48
|
+
replayed: boolean;
|
|
49
|
+
errorCode: string | null;
|
|
24
50
|
}
|
|
25
51
|
export interface BillingRefundInfo {
|
|
26
52
|
providerRefundId: string;
|
|
27
|
-
providerPaymentId
|
|
53
|
+
providerPaymentId: string;
|
|
28
54
|
amountMinor: number;
|
|
29
55
|
currency: string;
|
|
30
56
|
reason?: string | null;
|
|
31
|
-
status
|
|
57
|
+
status: "pending" | "succeeded" | "failed" | "canceled";
|
|
32
58
|
}
|
|
33
59
|
export interface BillingDisputeInfo {
|
|
34
60
|
providerDisputeId: string;
|
|
35
|
-
providerPaymentId
|
|
36
|
-
status
|
|
61
|
+
providerPaymentId: string;
|
|
62
|
+
status: "needs_response" | "under_review" | "won" | "lost" | "closed";
|
|
37
63
|
reason?: string | null;
|
|
38
64
|
}
|
|
39
65
|
//# sourceMappingURL=documents.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"documents.d.ts","sourceRoot":"","sources":["../../../src/billing/types/documents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,MAAM,WAAW,mBAAmB;IAClC,kBAAkB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB;AAED,MAAM,WAAW,kBAAkB;IACjC,
|
|
1
|
+
{"version":3,"file":"documents.d.ts","sourceRoot":"","sources":["../../../src/billing/types/documents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,YAAY,CAAC;AACtC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,MAAM,WAAW,mBAAmB;IAClC,kBAAkB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB;AAED,MAAM,WAAW,kBAAkB;IACjC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,eAAe,CAAC;IAC7D,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B;AAED,8E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AAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,MAAM,EAAE,SAAS,GAAG,WAAW,GAAG,QAAQ,GAAG,UAAU,CAAC;CACzD;AAED,MAAM,WAAW,kBAAkB;IACjC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,MAAM,EAAE,gBAAgB,GAAG,cAAc,GAAG,KAAK,GAAG,MAAM,GAAG,QAAQ,CAAC;IACtE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"documents.js","sourceRoot":"","sources":["../../../src/billing/types/documents.ts"],"names":[],"mappings":"","sourcesContent":["import type { ProviderRef } from \"./common.js\";\n\nexport interface BillingCustomerInfo {\n providerCustomerId?: string | null;\n email?: string | null;\n}\n\nexport interface BillingInvoiceInfo {\n
|
|
1
|
+
{"version":3,"file":"documents.js","sourceRoot":"","sources":["../../../src/billing/types/documents.ts"],"names":[],"mappings":"","sourcesContent":["import type Decimal from \"decimal.js\";\nimport type { ProviderRef } from \"./common.js\";\n\nexport interface BillingCustomerInfo {\n providerCustomerId?: string | null;\n email?: string | null;\n}\n\nexport interface BillingInvoiceInfo {\n providerInvoiceId: string;\n status: \"draft\" | \"open\" | \"paid\" | \"void\" | \"uncollectible\";\n amountPaidMinor: number;\n amountDueMinor: number;\n currency: string;\n periodStart?: string | null;\n periodEnd?: string | null;\n}\n\n/** Persisted invoice document returned from account-level billing queries. */\nexport interface BillingInvoiceRecord extends BillingInvoiceInfo {\n provider: string;\n}\n\nexport interface BillingPaymentInfo {\n providerPaymentId: string;\n amountMinor: number;\n taxMinor: number;\n currency: string;\n refs?: ProviderRef | null;\n purpose: \"subscription\" | \"credit_topup\";\n status: \"pending\" | \"succeeded\" | \"failed\" | \"canceled\";\n}\n\n/** Persisted payment state used by billing lifecycle handlers. */\nexport interface BillingPaymentRecord {\n id: string;\n provider: string;\n providerPaymentId: string;\n providerInvoiceId: string | null;\n userId: string;\n amountMinor: number;\n taxMinor: number;\n currency: string;\n purpose: \"subscription\" | \"credit_topup\";\n status: \"pending\" | \"succeeded\" | \"failed\" | \"canceled\";\n providerUpdatedAt: string;\n metadata: Record<string, unknown>;\n}\n\n/** Result of posting a billing grant or refund to the credit ledger. */\nexport interface BillingCreditPostingResult {\n ledgerEntryId: string | null;\n balanceAfter: Decimal | null;\n replayed: boolean;\n errorCode: string | null;\n}\n\nexport interface BillingRefundInfo {\n providerRefundId: string;\n providerPaymentId: string;\n amountMinor: number;\n currency: string;\n reason?: string | null;\n status: \"pending\" | \"succeeded\" | \"failed\" | \"canceled\";\n}\n\nexport interface BillingDisputeInfo {\n providerDisputeId: string;\n providerPaymentId: string;\n status: \"needs_response\" | \"under_review\" | \"won\" | \"lost\" | \"closed\";\n reason?: string | null;\n}\n"]}
|
|
@@ -54,6 +54,8 @@ export interface BillingEvent {
|
|
|
54
54
|
raw?: unknown;
|
|
55
55
|
billingEventId?: string;
|
|
56
56
|
}
|
|
57
|
+
/** Validate an event at the public ingestion boundary before claiming it. */
|
|
58
|
+
export declare function assertBillingEvent(value: unknown): asserts value is BillingEvent;
|
|
57
59
|
export type BillingEventHandler = (event: BillingEvent, userId: string) => Promise<void>;
|
|
58
60
|
export interface BillingEventResult {
|
|
59
61
|
handled: boolean;
|