@zonastery/bursar 0.0.2 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +118 -333
- package/dist/billing/auto-recharge-port.d.ts +27 -0
- package/dist/billing/auto-recharge-port.d.ts.map +1 -0
- package/dist/billing/auto-recharge-port.js +2 -0
- package/dist/billing/auto-recharge-port.js.map +1 -0
- package/dist/billing/auto-recharge-service.d.ts +43 -0
- package/dist/billing/auto-recharge-service.d.ts.map +1 -0
- package/dist/billing/auto-recharge-service.js +218 -0
- package/dist/billing/auto-recharge-service.js.map +1 -0
- package/dist/billing/billing-service.d.ts +71 -0
- package/dist/billing/billing-service.d.ts.map +1 -0
- package/dist/billing/billing-service.js +172 -0
- package/dist/billing/billing-service.js.map +1 -0
- package/dist/billing/billing-store.d.ts +45 -13
- package/dist/billing/billing-store.d.ts.map +1 -1
- package/dist/billing/billing-store.js.map +1 -1
- package/dist/billing/contracts.d.ts +149 -0
- package/dist/billing/contracts.d.ts.map +1 -0
- package/dist/billing/contracts.js +2 -0
- package/dist/billing/contracts.js.map +1 -0
- package/dist/billing/event-handlers.d.ts +57 -0
- package/dist/billing/event-handlers.d.ts.map +1 -0
- package/dist/billing/event-handlers.js +684 -0
- package/dist/billing/event-handlers.js.map +1 -0
- package/dist/billing/event-processor.d.ts +20 -0
- package/dist/billing/event-processor.d.ts.map +1 -0
- package/dist/billing/event-processor.js +131 -0
- package/dist/billing/event-processor.js.map +1 -0
- package/dist/billing/financial-event-handlers.d.ts +26 -0
- package/dist/billing/financial-event-handlers.d.ts.map +1 -0
- package/dist/billing/financial-event-handlers.js +241 -0
- package/dist/billing/financial-event-handlers.js.map +1 -0
- package/dist/billing/index.d.ts +9 -5
- package/dist/billing/index.d.ts.map +1 -1
- package/dist/billing/index.js +4 -4
- package/dist/billing/index.js.map +1 -1
- package/dist/billing/management.d.ts +59 -0
- package/dist/billing/management.d.ts.map +1 -0
- package/dist/billing/management.js +113 -0
- package/dist/billing/management.js.map +1 -0
- package/dist/billing/policy-window.d.ts +24 -0
- package/dist/billing/policy-window.d.ts.map +1 -0
- package/dist/billing/policy-window.js +88 -0
- package/dist/billing/policy-window.js.map +1 -0
- package/dist/billing/postgres/repositories/auto-recharge.d.ts +32 -0
- package/dist/billing/postgres/repositories/auto-recharge.d.ts.map +1 -0
- package/dist/billing/postgres/repositories/auto-recharge.js +180 -0
- package/dist/billing/postgres/repositories/auto-recharge.js.map +1 -0
- package/dist/billing/postgres/repositories/customer.d.ts +12 -0
- package/dist/billing/postgres/repositories/customer.d.ts.map +1 -0
- package/dist/billing/postgres/repositories/customer.js +33 -0
- package/dist/billing/postgres/repositories/customer.js.map +1 -0
- package/dist/billing/postgres/repositories/dispute.d.ts +7 -0
- package/dist/billing/postgres/repositories/dispute.d.ts.map +1 -0
- package/dist/billing/postgres/repositories/dispute.js +18 -0
- package/dist/billing/postgres/repositories/dispute.js.map +1 -0
- package/dist/billing/postgres/repositories/event.d.ts +21 -0
- package/dist/billing/postgres/repositories/event.d.ts.map +1 -0
- package/dist/billing/postgres/repositories/event.js +45 -0
- package/dist/billing/postgres/repositories/event.js.map +1 -0
- package/dist/billing/postgres/repositories/invoice.d.ts +9 -0
- package/dist/billing/postgres/repositories/invoice.d.ts.map +1 -0
- package/dist/billing/postgres/repositories/invoice.js +36 -0
- package/dist/billing/postgres/repositories/invoice.js.map +1 -0
- package/dist/billing/postgres/repositories/offer.d.ts +26 -0
- package/dist/billing/postgres/repositories/offer.d.ts.map +1 -0
- package/dist/billing/postgres/repositories/offer.js +73 -0
- package/dist/billing/postgres/repositories/offer.js.map +1 -0
- package/dist/billing/postgres/repositories/payment.d.ts +32 -0
- package/dist/billing/postgres/repositories/payment.d.ts.map +1 -0
- package/dist/billing/postgres/repositories/payment.js +78 -0
- package/dist/billing/postgres/repositories/payment.js.map +1 -0
- package/dist/billing/postgres/repositories/preferences.d.ts +15 -0
- package/dist/billing/postgres/repositories/preferences.d.ts.map +1 -0
- package/dist/billing/postgres/repositories/preferences.js +23 -0
- package/dist/billing/postgres/repositories/preferences.js.map +1 -0
- package/dist/billing/postgres/repositories/refund.d.ts +7 -0
- package/dist/billing/postgres/repositories/refund.d.ts.map +1 -0
- package/dist/billing/postgres/repositories/refund.js +32 -0
- package/dist/billing/postgres/repositories/refund.js.map +1 -0
- package/dist/billing/postgres/repositories/subscription.d.ts +46 -0
- package/dist/billing/postgres/repositories/subscription.d.ts.map +1 -0
- package/dist/billing/postgres/repositories/subscription.js +187 -0
- package/dist/billing/postgres/repositories/subscription.js.map +1 -0
- package/dist/billing/postgres/repositories/topup.d.ts +27 -0
- package/dist/billing/postgres/repositories/topup.d.ts.map +1 -0
- package/dist/billing/postgres/repositories/topup.js +51 -0
- package/dist/billing/postgres/repositories/topup.js.map +1 -0
- package/dist/billing/postgres/store.d.ts +89 -0
- package/dist/billing/postgres/store.d.ts.map +1 -0
- package/dist/billing/postgres/store.js +542 -0
- package/dist/billing/postgres/store.js.map +1 -0
- package/dist/billing/service-types.d.ts +37 -0
- package/dist/billing/service-types.d.ts.map +1 -0
- package/dist/billing/service-types.js +2 -0
- package/dist/billing/service-types.js.map +1 -0
- package/dist/billing/types/auto-recharge.d.ts +56 -0
- package/dist/billing/types/auto-recharge.d.ts.map +1 -0
- package/dist/billing/types/auto-recharge.js +2 -0
- package/dist/billing/types/auto-recharge.js.map +1 -0
- package/dist/billing/types/catalog.d.ts +47 -0
- package/dist/billing/types/catalog.d.ts.map +1 -0
- package/dist/billing/types/catalog.js +2 -0
- package/dist/billing/types/catalog.js.map +1 -0
- package/dist/billing/types/common.d.ts +16 -0
- package/dist/billing/types/common.d.ts.map +1 -0
- package/dist/billing/types/common.js +2 -0
- package/dist/billing/types/common.js.map +1 -0
- package/dist/billing/types/documents.d.ts +39 -0
- package/dist/billing/types/documents.d.ts.map +1 -0
- package/dist/billing/types/documents.js +2 -0
- package/dist/billing/types/documents.js.map +1 -0
- package/dist/billing/types/events.d.ts +75 -0
- package/dist/billing/types/events.d.ts.map +1 -0
- package/dist/billing/types/events.js +38 -0
- package/dist/billing/types/events.js.map +1 -0
- package/dist/billing/types/index.d.ts +8 -0
- package/dist/billing/types/index.d.ts.map +1 -0
- package/dist/billing/types/index.js +8 -0
- package/dist/billing/types/index.js.map +1 -0
- package/dist/billing/types/preferences.d.ts +13 -0
- package/dist/billing/types/preferences.d.ts.map +1 -0
- package/dist/billing/types/preferences.js +2 -0
- package/dist/billing/types/preferences.js.map +1 -0
- package/dist/billing/types/subscriptions.d.ts +97 -0
- package/dist/billing/types/subscriptions.d.ts.map +1 -0
- package/dist/billing/types/subscriptions.js +12 -0
- package/dist/billing/types/subscriptions.js.map +1 -0
- package/dist/breakdown.d.ts +3 -1
- package/dist/breakdown.d.ts.map +1 -1
- package/dist/breakdown.js +4 -1
- package/dist/breakdown.js.map +1 -1
- package/dist/browser.d.ts +8 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +7 -0
- package/dist/browser.js.map +1 -0
- package/dist/bursar.d.ts +84 -0
- package/dist/bursar.d.ts.map +1 -0
- package/dist/bursar.js +137 -0
- package/dist/bursar.js.map +1 -0
- package/dist/catalog.d.ts +62 -0
- package/dist/catalog.d.ts.map +1 -0
- package/dist/catalog.js +96 -0
- package/dist/catalog.js.map +1 -0
- package/dist/commerce/errors.d.ts +68 -0
- package/dist/commerce/errors.d.ts.map +1 -0
- package/dist/commerce/errors.js +105 -0
- package/dist/commerce/errors.js.map +1 -0
- package/dist/commerce/index.d.ts +6 -0
- package/dist/commerce/index.d.ts.map +1 -0
- package/dist/commerce/index.js +6 -0
- package/dist/commerce/index.js.map +1 -0
- package/dist/commerce/plan-change.d.ts +10 -0
- package/dist/commerce/plan-change.d.ts.map +1 -0
- package/dist/commerce/plan-change.js +42 -0
- package/dist/commerce/plan-change.js.map +1 -0
- package/dist/commerce/provider-registry.d.ts +18 -0
- package/dist/commerce/provider-registry.d.ts.map +1 -0
- package/dist/commerce/provider-registry.js +70 -0
- package/dist/commerce/provider-registry.js.map +1 -0
- package/dist/commerce/service.d.ts +73 -0
- package/dist/commerce/service.d.ts.map +1 -0
- package/dist/commerce/service.js +1016 -0
- package/dist/commerce/service.js.map +1 -0
- package/dist/commerce/types.d.ts +225 -0
- package/dist/commerce/types.d.ts.map +1 -0
- package/dist/commerce/types.js.map +1 -0
- package/dist/config/parse-access.d.ts +6 -0
- package/dist/config/parse-access.d.ts.map +1 -0
- package/dist/config/parse-access.js +72 -0
- package/dist/config/parse-access.js.map +1 -0
- package/dist/config/parse-commerce.d.ts +3 -0
- package/dist/config/parse-commerce.d.ts.map +1 -0
- package/dist/config/parse-commerce.js +236 -0
- package/dist/config/parse-commerce.js.map +1 -0
- package/dist/config/parse-credits.d.ts +3 -0
- package/dist/config/parse-credits.d.ts.map +1 -0
- package/dist/config/parse-credits.js +99 -0
- package/dist/config/parse-credits.js.map +1 -0
- package/dist/config/parse-plans.d.ts +5 -0
- package/dist/config/parse-plans.d.ts.map +1 -0
- package/dist/config/parse-plans.js +142 -0
- package/dist/config/parse-plans.js.map +1 -0
- package/dist/config/parse-pricing.d.ts +4 -0
- package/dist/config/parse-pricing.d.ts.map +1 -0
- package/dist/config/parse-pricing.js +252 -0
- package/dist/config/parse-pricing.js.map +1 -0
- package/dist/config/parse-utils.d.ts +18 -0
- package/dist/config/parse-utils.d.ts.map +1 -0
- package/dist/config/parse-utils.js +118 -0
- package/dist/config/parse-utils.js.map +1 -0
- package/dist/config/types.d.ts +340 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/config/types.js +2 -0
- package/dist/config/types.js.map +1 -0
- package/dist/config.d.ts +12 -23
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +141 -377
- package/dist/config.js.map +1 -1
- package/dist/{stores → credits}/events.d.ts +6 -6
- package/dist/credits/events.d.ts.map +1 -0
- package/dist/{stores → credits}/events.js +5 -5
- package/dist/credits/events.js.map +1 -0
- package/dist/credits/lease-workflow.d.ts +90 -0
- package/dist/credits/lease-workflow.d.ts.map +1 -0
- package/dist/credits/lease-workflow.js +378 -0
- package/dist/credits/lease-workflow.js.map +1 -0
- package/dist/credits/low-balance-monitor.d.ts +26 -0
- package/dist/credits/low-balance-monitor.d.ts.map +1 -0
- package/dist/credits/low-balance-monitor.js +110 -0
- package/dist/credits/low-balance-monitor.js.map +1 -0
- package/dist/credits/postgres/repositories/analytics.d.ts +81 -0
- package/dist/credits/postgres/repositories/analytics.d.ts.map +1 -0
- package/dist/credits/postgres/repositories/analytics.js +153 -0
- package/dist/credits/postgres/repositories/analytics.js.map +1 -0
- package/dist/credits/postgres/repositories/balance.d.ts +66 -0
- package/dist/credits/postgres/repositories/balance.d.ts.map +1 -0
- package/dist/credits/postgres/repositories/balance.js +139 -0
- package/dist/credits/postgres/repositories/balance.js.map +1 -0
- package/dist/credits/postgres/repositories/bucket.d.ts +25 -0
- package/dist/credits/postgres/repositories/bucket.d.ts.map +1 -0
- package/dist/credits/postgres/repositories/bucket.js +52 -0
- package/dist/credits/postgres/repositories/bucket.js.map +1 -0
- package/dist/credits/postgres/repositories/deduction.d.ts +64 -0
- package/dist/credits/postgres/repositories/deduction.d.ts.map +1 -0
- package/dist/credits/postgres/repositories/deduction.js +154 -0
- package/dist/credits/postgres/repositories/deduction.js.map +1 -0
- package/dist/credits/postgres/repositories/lease.d.ts +69 -0
- package/dist/credits/postgres/repositories/lease.d.ts.map +1 -0
- package/dist/credits/postgres/repositories/lease.js +148 -0
- package/dist/credits/postgres/repositories/lease.js.map +1 -0
- package/dist/credits/postgres/repositories/plan.d.ts +110 -0
- package/dist/credits/postgres/repositories/plan.d.ts.map +1 -0
- package/dist/credits/postgres/repositories/plan.js +194 -0
- package/dist/credits/postgres/repositories/plan.js.map +1 -0
- package/dist/credits/postgres/repositories/pricing.d.ts +28 -0
- package/dist/credits/postgres/repositories/pricing.d.ts.map +1 -0
- package/dist/credits/postgres/repositories/pricing.js +76 -0
- package/dist/credits/postgres/repositories/pricing.js.map +1 -0
- package/dist/credits/postgres/repositories/team.d.ts +63 -0
- package/dist/credits/postgres/repositories/team.d.ts.map +1 -0
- package/dist/credits/postgres/repositories/team.js +120 -0
- package/dist/credits/postgres/repositories/team.js.map +1 -0
- package/dist/credits/postgres/store.d.ts +89 -0
- package/dist/credits/postgres/store.d.ts.map +1 -0
- package/dist/credits/postgres/store.js +838 -0
- package/dist/credits/postgres/store.js.map +1 -0
- package/dist/credits/postgres/value-mappers.d.ts +17 -0
- package/dist/credits/postgres/value-mappers.d.ts.map +1 -0
- package/dist/credits/postgres/value-mappers.js +102 -0
- package/dist/credits/postgres/value-mappers.js.map +1 -0
- package/dist/credits/pricing-runtime.d.ts +35 -0
- package/dist/credits/pricing-runtime.d.ts.map +1 -0
- package/dist/credits/pricing-runtime.js +141 -0
- package/dist/credits/pricing-runtime.js.map +1 -0
- package/dist/credits/queries.d.ts +33 -0
- package/dist/credits/queries.d.ts.map +1 -0
- package/dist/credits/queries.js +71 -0
- package/dist/credits/queries.js.map +1 -0
- package/dist/credits/service-errors.d.ts +4 -0
- package/dist/credits/service-errors.d.ts.map +1 -0
- package/dist/credits/service-errors.js +57 -0
- package/dist/credits/service-errors.js.map +1 -0
- package/dist/credits/service-types.d.ts +122 -0
- package/dist/credits/service-types.d.ts.map +1 -0
- package/dist/credits/service-types.js +2 -0
- package/dist/credits/service-types.js.map +1 -0
- package/dist/credits/service.d.ts +220 -0
- package/dist/credits/service.d.ts.map +1 -0
- package/dist/credits/service.js +640 -0
- package/dist/credits/service.js.map +1 -0
- package/dist/credits/store.d.ts +172 -0
- package/dist/credits/store.d.ts.map +1 -0
- package/dist/{stores/credit-store.js → credits/store.js} +27 -43
- package/dist/credits/store.js.map +1 -0
- package/dist/credits/types/account.d.ts +82 -0
- package/dist/credits/types/account.d.ts.map +1 -0
- package/dist/credits/types/account.js +2 -0
- package/dist/credits/types/account.js.map +1 -0
- package/dist/credits/types/admission.d.ts +39 -0
- package/dist/credits/types/admission.d.ts.map +1 -0
- package/dist/credits/types/admission.js +2 -0
- package/dist/credits/types/admission.js.map +1 -0
- package/dist/credits/types/analytics.d.ts +52 -0
- package/dist/credits/types/analytics.d.ts.map +1 -0
- package/dist/credits/types/analytics.js +2 -0
- package/dist/credits/types/analytics.js.map +1 -0
- package/dist/credits/types/catalog.d.ts +71 -0
- package/dist/credits/types/catalog.d.ts.map +1 -0
- package/dist/credits/types/catalog.js +2 -0
- package/dist/credits/types/catalog.js.map +1 -0
- package/dist/credits/types/grants.d.ts +24 -0
- package/dist/credits/types/grants.d.ts.map +1 -0
- package/dist/credits/types/grants.js +2 -0
- package/dist/credits/types/grants.js.map +1 -0
- package/dist/credits/types/index.d.ts +9 -0
- package/dist/credits/types/index.d.ts.map +1 -0
- package/dist/credits/types/index.js +2 -0
- package/dist/credits/types/index.js.map +1 -0
- package/dist/credits/types/ledger.d.ts +87 -0
- package/dist/credits/types/ledger.d.ts.map +1 -0
- package/dist/credits/types/ledger.js +2 -0
- package/dist/credits/types/ledger.js.map +1 -0
- package/dist/credits/types/quotas.d.ts +40 -0
- package/dist/credits/types/quotas.d.ts.map +1 -0
- package/dist/credits/types/quotas.js +2 -0
- package/dist/credits/types/quotas.js.map +1 -0
- package/dist/credits/types/teams.d.ts +44 -0
- package/dist/credits/types/teams.d.ts.map +1 -0
- package/dist/credits/types/teams.js +2 -0
- package/dist/credits/types/teams.js.map +1 -0
- package/dist/engine.d.ts +18 -39
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +169 -145
- package/dist/engine.js.map +1 -1
- package/dist/errors.d.ts +133 -25
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +173 -24
- package/dist/errors.js.map +1 -1
- package/dist/expr/ast.d.ts +46 -0
- package/dist/expr/ast.d.ts.map +1 -0
- package/dist/expr/ast.js +18 -0
- package/dist/expr/ast.js.map +1 -0
- package/dist/expr/evaluator.d.ts +4 -0
- package/dist/expr/evaluator.d.ts.map +1 -0
- package/dist/expr/evaluator.js +144 -0
- package/dist/expr/evaluator.js.map +1 -0
- package/dist/expr/language.d.ts +5 -0
- package/dist/expr/language.d.ts.map +1 -0
- package/dist/expr/language.js +73 -0
- package/dist/expr/language.js.map +1 -0
- package/dist/expr/parser.d.ts +24 -0
- package/dist/expr/parser.d.ts.map +1 -0
- package/dist/expr/parser.js +175 -0
- package/dist/expr/parser.js.map +1 -0
- package/dist/expr/tokenizer.d.ts +7 -0
- package/dist/expr/tokenizer.d.ts.map +1 -0
- package/dist/expr/tokenizer.js +85 -0
- package/dist/expr/tokenizer.js.map +1 -0
- package/dist/expr.d.ts +7 -58
- package/dist/expr.d.ts.map +1 -1
- package/dist/expr.js +41 -640
- package/dist/expr.js.map +1 -1
- package/dist/generated/pricing-config.schema.json +2792 -0
- package/dist/generated/pricing-config.types.d.ts +685 -0
- package/dist/generated/pricing-config.types.d.ts.map +1 -0
- package/dist/generated/pricing-config.types.js +8 -0
- package/dist/generated/pricing-config.types.js.map +1 -0
- package/dist/index.d.ts +23 -17
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -10
- package/dist/index.js.map +1 -1
- package/dist/load-pricing-file.d.ts.map +1 -1
- package/dist/load-pricing-file.js +8 -4
- package/dist/load-pricing-file.js.map +1 -1
- package/dist/metrics.d.ts +6 -16
- package/dist/metrics.d.ts.map +1 -1
- package/dist/metrics.js.map +1 -1
- package/dist/node.d.ts +9 -2
- package/dist/node.d.ts.map +1 -1
- package/dist/node.js +6 -2
- package/dist/node.js.map +1 -1
- package/dist/providers/_shared.d.ts +9 -0
- package/dist/providers/_shared.d.ts.map +1 -0
- package/dist/providers/_shared.js +52 -0
- package/dist/providers/_shared.js.map +1 -0
- package/dist/providers/dodo/client-contract.d.ts +106 -0
- package/dist/providers/dodo/client-contract.d.ts.map +1 -0
- package/dist/providers/dodo/client-contract.js +2 -0
- package/dist/providers/dodo/client-contract.js.map +1 -0
- package/dist/providers/dodo/event-mapper.d.ts +5 -3
- package/dist/providers/dodo/event-mapper.d.ts.map +1 -1
- package/dist/providers/dodo/event-mapper.js +213 -38
- package/dist/providers/dodo/event-mapper.js.map +1 -1
- package/dist/providers/dodo/index.d.ts +1 -0
- package/dist/providers/dodo/index.d.ts.map +1 -1
- package/dist/providers/dodo/index.js.map +1 -1
- package/dist/providers/dodo/provider.d.ts +24 -14
- package/dist/providers/dodo/provider.d.ts.map +1 -1
- package/dist/providers/dodo/provider.js +249 -31
- package/dist/providers/dodo/provider.js.map +1 -1
- package/dist/providers/index.d.ts +3 -1
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js +1 -0
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/mock/index.js.map +1 -1
- package/dist/providers/mock/provider.d.ts +14 -10
- package/dist/providers/mock/provider.d.ts.map +1 -1
- package/dist/providers/mock/provider.js +78 -10
- package/dist/providers/mock/provider.js.map +1 -1
- package/dist/providers/stripe/event-mapper.d.ts +3 -3
- package/dist/providers/stripe/event-mapper.d.ts.map +1 -1
- package/dist/providers/stripe/event-mapper.js +139 -30
- package/dist/providers/stripe/event-mapper.js.map +1 -1
- package/dist/providers/stripe/index.js.map +1 -1
- package/dist/providers/stripe/provider.d.ts +21 -12
- package/dist/providers/stripe/provider.d.ts.map +1 -1
- package/dist/providers/stripe/provider.js +175 -17
- package/dist/providers/stripe/provider.js.map +1 -1
- package/dist/providers/types.d.ts +128 -32
- package/dist/providers/types.d.ts.map +1 -1
- package/dist/providers/types.js +17 -1
- package/dist/providers/types.js.map +1 -1
- package/dist/retry.d.ts +35 -0
- package/dist/retry.d.ts.map +1 -0
- package/dist/retry.js +70 -0
- package/dist/retry.js.map +1 -0
- package/dist/shared/diagnostics.d.ts +7 -0
- package/dist/shared/diagnostics.d.ts.map +1 -0
- package/dist/shared/diagnostics.js +18 -0
- package/dist/shared/diagnostics.js.map +1 -0
- package/dist/shared/logger.d.ts +10 -0
- package/dist/shared/logger.d.ts.map +1 -0
- package/dist/shared/logger.js +15 -0
- package/dist/shared/logger.js.map +1 -0
- package/dist/shared/postgres-client.d.ts +84 -0
- package/dist/shared/postgres-client.d.ts.map +1 -0
- package/dist/shared/postgres-client.js +337 -0
- package/dist/shared/postgres-client.js.map +1 -0
- package/dist/shared/postgres-errors.d.ts +11 -0
- package/dist/shared/postgres-errors.d.ts.map +1 -0
- package/dist/shared/postgres-errors.js +105 -0
- package/dist/shared/postgres-errors.js.map +1 -0
- package/dist/shared/postgres-types.d.ts +7 -0
- package/dist/shared/postgres-types.d.ts.map +1 -0
- package/dist/shared/postgres-types.js +2 -0
- package/dist/shared/postgres-types.js.map +1 -0
- package/dist/shared/postgres-validation.d.ts +8 -0
- package/dist/shared/postgres-validation.d.ts.map +1 -0
- package/dist/shared/postgres-validation.js +40 -0
- package/dist/shared/postgres-validation.js.map +1 -0
- package/dist/storage/adapters/clickhouse.d.ts +61 -0
- package/dist/storage/adapters/clickhouse.d.ts.map +1 -0
- package/dist/storage/adapters/clickhouse.js +347 -0
- package/dist/storage/adapters/clickhouse.js.map +1 -0
- package/dist/storage/adapters/s3.d.ts +35 -0
- package/dist/storage/adapters/s3.d.ts.map +1 -0
- package/dist/storage/adapters/s3.js +100 -0
- package/dist/storage/adapters/s3.js.map +1 -0
- package/dist/storage/outbox-worker.d.ts +41 -0
- package/dist/storage/outbox-worker.d.ts.map +1 -0
- package/dist/storage/outbox-worker.js +146 -0
- package/dist/storage/outbox-worker.js.map +1 -0
- package/dist/storage/ports.d.ts +78 -0
- package/dist/storage/ports.d.ts.map +1 -0
- package/dist/storage/ports.js +2 -0
- package/dist/storage/ports.js.map +1 -0
- package/dist/storage/postgres-repository.d.ts +14 -0
- package/dist/storage/postgres-repository.d.ts.map +1 -0
- package/dist/storage/postgres-repository.js +140 -0
- package/dist/storage/postgres-repository.js.map +1 -0
- package/dist/storage/runtime.d.ts +77 -0
- package/dist/storage/runtime.d.ts.map +1 -0
- package/dist/storage/runtime.js +369 -0
- package/dist/storage/runtime.js.map +1 -0
- package/package.json +43 -21
- package/dist/allowance.d.ts +0 -48
- package/dist/allowance.d.ts.map +0 -1
- package/dist/allowance.js +0 -140
- package/dist/allowance.js.map +0 -1
- package/dist/billing/billing-manager.d.ts +0 -66
- package/dist/billing/billing-manager.d.ts.map +0 -1
- package/dist/billing/billing-manager.js +0 -560
- package/dist/billing/billing-manager.js.map +0 -1
- package/dist/billing/billing-types.d.ts +0 -203
- package/dist/billing/billing-types.d.ts.map +0 -1
- package/dist/billing/billing-types.js +0 -6
- package/dist/billing/billing-types.js.map +0 -1
- package/dist/billing/memory-billing-store.d.ts +0 -37
- package/dist/billing/memory-billing-store.d.ts.map +0 -1
- package/dist/billing/memory-billing-store.js +0 -197
- package/dist/billing/memory-billing-store.js.map +0 -1
- package/dist/billing/postgres-billing-store.d.ts +0 -35
- package/dist/billing/postgres-billing-store.d.ts.map +0 -1
- package/dist/billing/postgres-billing-store.js +0 -274
- package/dist/billing/postgres-billing-store.js.map +0 -1
- package/dist/billing/supabase-billing-store.d.ts +0 -29
- package/dist/billing/supabase-billing-store.d.ts.map +0 -1
- package/dist/billing/supabase-billing-store.js +0 -250
- package/dist/billing/supabase-billing-store.js.map +0 -1
- package/dist/manager.d.ts +0 -444
- package/dist/manager.d.ts.map +0 -1
- package/dist/manager.js +0 -1153
- package/dist/manager.js.map +0 -1
- package/dist/stores/credit-store.d.ts +0 -198
- package/dist/stores/credit-store.d.ts.map +0 -1
- package/dist/stores/credit-store.js.map +0 -1
- package/dist/stores/events.d.ts.map +0 -1
- package/dist/stores/events.js.map +0 -1
- package/dist/stores/memory-store.d.ts +0 -187
- package/dist/stores/memory-store.d.ts.map +0 -1
- package/dist/stores/memory-store.js +0 -1890
- package/dist/stores/memory-store.js.map +0 -1
- package/dist/stores/postgres-store.d.ts +0 -100
- package/dist/stores/postgres-store.d.ts.map +0 -1
- package/dist/stores/postgres-store.js +0 -891
- package/dist/stores/postgres-store.js.map +0 -1
- package/dist/stores/supabase-store.d.ts +0 -87
- package/dist/stores/supabase-store.d.ts.map +0 -1
- package/dist/stores/supabase-store.js +0 -948
- package/dist/stores/supabase-store.js.map +0 -1
- package/dist/types.d.ts +0 -463
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
- /package/dist/{types.js → commerce/types.js} +0 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { optionalBoundedDiagnosticMessage } from "../../../shared/diagnostics.js";
|
|
2
|
+
function iso(value) {
|
|
3
|
+
return new Date(String(value)).toISOString();
|
|
4
|
+
}
|
|
5
|
+
function profileFromRow(row) {
|
|
6
|
+
return {
|
|
7
|
+
userId: String(row.subject_id),
|
|
8
|
+
enabled: Boolean(row.enabled),
|
|
9
|
+
armed: Boolean(row.armed),
|
|
10
|
+
state: String(row.state),
|
|
11
|
+
provider: row.provider == null ? null : String(row.provider),
|
|
12
|
+
topupId: row.topup_id == null ? null : String(row.topup_id),
|
|
13
|
+
quantity: Number(row.quantity),
|
|
14
|
+
threshold: Number(row.threshold),
|
|
15
|
+
maxChargesPerWindow: row.max_charges_per_window == null ? null : Number(row.max_charges_per_window),
|
|
16
|
+
windowUnit: String(row.window_unit),
|
|
17
|
+
windowCount: Number(row.window_count),
|
|
18
|
+
windowAnchor: String(row.window_anchor),
|
|
19
|
+
windowTimezone: String(row.window_timezone),
|
|
20
|
+
updatedAt: row.updated_at == null ? null : iso(row.updated_at),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function attemptFromRow(row) {
|
|
24
|
+
return {
|
|
25
|
+
id: String(row.id),
|
|
26
|
+
userId: String(row.subject_id),
|
|
27
|
+
provider: String(row.provider),
|
|
28
|
+
idempotencyKey: String(row.idempotency_key),
|
|
29
|
+
providerAttemptId: row.provider_attempt_id == null ? null : String(row.provider_attempt_id),
|
|
30
|
+
topupId: String(row.topup_id),
|
|
31
|
+
quantity: Number(row.quantity),
|
|
32
|
+
state: String(row.state),
|
|
33
|
+
windowStart: iso(row.window_start),
|
|
34
|
+
windowEnd: iso(row.window_end),
|
|
35
|
+
quotedAmountMinor: row.quoted_amount_minor == null ? null : Number(row.quoted_amount_minor),
|
|
36
|
+
currency: row.currency == null ? null : String(row.currency),
|
|
37
|
+
failureCode: row.failure_code == null ? null : String(row.failure_code),
|
|
38
|
+
failureMessage: row.failure_message == null ? null : String(row.failure_message),
|
|
39
|
+
metadata: row.metadata != null && typeof row.metadata === "object" && !Array.isArray(row.metadata)
|
|
40
|
+
? row.metadata
|
|
41
|
+
: {},
|
|
42
|
+
createdAt: iso(row.created_at),
|
|
43
|
+
updatedAt: iso(row.updated_at),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export class BillingAutoRechargeRepository {
|
|
47
|
+
query;
|
|
48
|
+
constructor(query) {
|
|
49
|
+
this.query = query;
|
|
50
|
+
}
|
|
51
|
+
async getProfile(userId) {
|
|
52
|
+
const rows = await this.query("SELECT * FROM bursar.get_auto_recharge_profile($1::uuid)", [
|
|
53
|
+
userId,
|
|
54
|
+
]);
|
|
55
|
+
const row = rows[0];
|
|
56
|
+
return row?.subject_id == null ? null : profileFromRow(row);
|
|
57
|
+
}
|
|
58
|
+
async upsertProfile(profile, options = {}) {
|
|
59
|
+
const rows = await this.query(`SELECT bursar.upsert_auto_recharge_profile(
|
|
60
|
+
$1::uuid, $2, $3, $4::uuid, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14
|
|
61
|
+
) AS updated`, [
|
|
62
|
+
profile.userId,
|
|
63
|
+
profile.enabled,
|
|
64
|
+
profile.provider,
|
|
65
|
+
profile.topupId,
|
|
66
|
+
profile.quantity,
|
|
67
|
+
profile.threshold,
|
|
68
|
+
profile.maxChargesPerWindow,
|
|
69
|
+
profile.windowUnit,
|
|
70
|
+
profile.windowCount,
|
|
71
|
+
profile.windowAnchor,
|
|
72
|
+
profile.windowTimezone,
|
|
73
|
+
profile.armed,
|
|
74
|
+
profile.state,
|
|
75
|
+
options.resetCooldown ?? false,
|
|
76
|
+
]);
|
|
77
|
+
if (!rows[0]?.updated) {
|
|
78
|
+
throw new Error(`auto-recharge profile update rejected: ${profile.userId}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
async claimAttempt(input) {
|
|
82
|
+
const rows = await this.query("SELECT * FROM bursar.claim_auto_recharge_attempt($1::uuid, $2)", [input.userId, input.idempotencyKey]);
|
|
83
|
+
const row = rows[0];
|
|
84
|
+
return row?.id == null ? null : attemptFromRow(row);
|
|
85
|
+
}
|
|
86
|
+
async advanceAttempt(input) {
|
|
87
|
+
const failureMessage = optionalBoundedDiagnosticMessage(input.failureMessage);
|
|
88
|
+
const currentRows = await this.query("SELECT * FROM bursar.get_auto_recharge_attempt($1::uuid)", [input.id]);
|
|
89
|
+
const current = String(currentRows[0]?.state ?? "");
|
|
90
|
+
const paths = {
|
|
91
|
+
claimed: {
|
|
92
|
+
submitted: ["submitted"],
|
|
93
|
+
processing: ["submitted", "processing"],
|
|
94
|
+
succeeded: ["submitted", "processing", "succeeded"],
|
|
95
|
+
failed: ["submitted", "processing", "failed"],
|
|
96
|
+
unknown: ["submitted", "processing", "unknown"],
|
|
97
|
+
action_required: ["submitted", "action_required"],
|
|
98
|
+
},
|
|
99
|
+
submitted: {
|
|
100
|
+
submitted: [],
|
|
101
|
+
processing: ["processing"],
|
|
102
|
+
succeeded: ["processing", "succeeded"],
|
|
103
|
+
failed: ["processing", "failed"],
|
|
104
|
+
unknown: ["processing", "unknown"],
|
|
105
|
+
action_required: ["action_required"],
|
|
106
|
+
},
|
|
107
|
+
processing: {
|
|
108
|
+
processing: [],
|
|
109
|
+
succeeded: ["succeeded"],
|
|
110
|
+
failed: ["failed"],
|
|
111
|
+
unknown: ["unknown"],
|
|
112
|
+
action_required: ["action_required"],
|
|
113
|
+
},
|
|
114
|
+
unknown: {
|
|
115
|
+
unknown: [],
|
|
116
|
+
processing: ["processing"],
|
|
117
|
+
succeeded: ["succeeded"],
|
|
118
|
+
failed: ["failed"],
|
|
119
|
+
action_required: ["action_required"],
|
|
120
|
+
},
|
|
121
|
+
action_required: {
|
|
122
|
+
action_required: [],
|
|
123
|
+
processing: ["processing"],
|
|
124
|
+
succeeded: ["succeeded"],
|
|
125
|
+
failed: ["failed"],
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
const path = paths[current]?.[input.state];
|
|
129
|
+
if (!path) {
|
|
130
|
+
throw new Error(`auto-recharge attempt transition rejected: ${input.id}`);
|
|
131
|
+
}
|
|
132
|
+
for (const state of path) {
|
|
133
|
+
const rows = await this.query(`SELECT bursar.advance_auto_recharge_attempt(
|
|
134
|
+
$1::uuid,
|
|
135
|
+
$2::bursar.recharge_attempt_status,
|
|
136
|
+
$3,
|
|
137
|
+
$4,
|
|
138
|
+
$5,
|
|
139
|
+
$6::jsonb
|
|
140
|
+
) AS advanced`, [
|
|
141
|
+
input.id,
|
|
142
|
+
state,
|
|
143
|
+
input.providerAttemptId ?? null,
|
|
144
|
+
input.failureCode ?? null,
|
|
145
|
+
failureMessage,
|
|
146
|
+
JSON.stringify(input.metadata ?? {}),
|
|
147
|
+
]);
|
|
148
|
+
if (!rows[0]?.advanced) {
|
|
149
|
+
throw new Error(`auto-recharge attempt transition rejected: ${input.id}`);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
async updateAttempt(input) {
|
|
154
|
+
return this.advanceAttempt(input);
|
|
155
|
+
}
|
|
156
|
+
async updateAttemptByProviderPayment(input) {
|
|
157
|
+
const rows = await this.query(`SELECT * FROM bursar.get_auto_recharge_attempt_by_provider($1, $2)`, [input.provider, input.providerPaymentId]);
|
|
158
|
+
for (const row of rows) {
|
|
159
|
+
if (row.id == null) {
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
await this.advanceAttempt({
|
|
163
|
+
id: String(row.id),
|
|
164
|
+
state: input.state,
|
|
165
|
+
providerAttemptId: input.providerPaymentId,
|
|
166
|
+
failureCode: input.failureCode,
|
|
167
|
+
failureMessage: input.failureMessage,
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
async countAttempts(userId, since) {
|
|
172
|
+
const sinceDate = since instanceof Date ? since : new Date(since);
|
|
173
|
+
if (Number.isNaN(sinceDate.getTime())) {
|
|
174
|
+
throw new TypeError("auto-recharge attempt boundary must be a valid instant");
|
|
175
|
+
}
|
|
176
|
+
const rows = await this.query(`SELECT bursar.count_auto_recharge_attempts($1::uuid, $2::timestamptz) AS count`, [userId, sinceDate.toISOString()]);
|
|
177
|
+
return Number(rows[0]?.count ?? 0);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
//# sourceMappingURL=auto-recharge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auto-recharge.js","sourceRoot":"","sources":["../../../../src/billing/postgres/repositories/auto-recharge.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gCAAgC,EAAE,MAAM,gCAAgC,CAAC;AAElF,SAAS,GAAG,CAAC,KAAc;IACzB,OAAO,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;AAC/C,CAAC;AAED,SAAS,cAAc,CAAC,GAA4B;IAClD,OAAO;QACL,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC;QAC9B,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC;QAC7B,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC;QACzB,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC,KAAK,CAAwC;QAC/D,QAAQ,EAAE,GAAG,CAAC,QAAQ,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;QAC5D,OAAO,EAAE,GAAG,CAAC,QAAQ,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;QAC3D,QAAQ,EAAE,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;QAC9B,SAAS,EAAE,MAAM,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CAAC;YACD,MAAM,IAAI,CAAC,cAAc,CAAC;gBACxB,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;gBAClB,KAAK,EAAE,KAAK,CAAC,KAAK;gBAClB,iBAAiB,EAAE,KAAK,CAAC,iBAAiB;gBAC1C,WAAW,EAAE,KAAK,CAAC,WAAW;gBAC9B,cAAc,EAAE,KAAK,CAAC,cAAc;aACrC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,MAAc,EAAE,KAAoB;QACtD,MAAM,SAAS,GAAG,KAAK,YAAY,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC;QAClE,IAAI,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC;YACtC,MAAM,IAAI,SAAS,CAAC,wDAAwD,CAAC,CAAC;QAChF,CAAC;QACD,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,KAAK,CAC3B,gFAAgF,EAChF,CAAC,MAAM,EAAE,SAAS,CAAC,WAAW,EAAE,CAAC,CAClC,CAAC;QACF,OAAO,MAAM,CAAE,IAAI,CAAC,CAAC,CAAyC,EAAE,KAAK,IAAI,CAAC,CAAC,CAAC;IAC9E,CAAC;CACF","sourcesContent":["import type { QueryFn } from \"../../../shared/postgres-types.js\";\nimport type { BillingAutoRechargeAttempt, BillingAutoRechargeProfile } from \"../../types/index.js\";\nimport { optionalBoundedDiagnosticMessage } from \"../../../shared/diagnostics.js\";\n\nfunction iso(value: unknown): string {\n return new Date(String(value)).toISOString();\n}\n\nfunction profileFromRow(row: Record<string, unknown>): BillingAutoRechargeProfile {\n return {\n userId: String(row.subject_id),\n enabled: Boolean(row.enabled),\n armed: Boolean(row.armed),\n state: String(row.state) as BillingAutoRechargeProfile[\"state\"],\n provider: row.provider == null ? null : String(row.provider),\n topupId: row.topup_id == null ? null : String(row.topup_id),\n quantity: Number(row.quantity),\n threshold: Number(row.threshold),\n maxChargesPerWindow:\n row.max_charges_per_window == null ? null : Number(row.max_charges_per_window),\n windowUnit: String(row.window_unit) as BillingAutoRechargeProfile[\"windowUnit\"],\n windowCount: Number(row.window_count),\n windowAnchor: String(row.window_anchor) as BillingAutoRechargeProfile[\"windowAnchor\"],\n windowTimezone: String(row.window_timezone),\n updatedAt: row.updated_at == null ? null : iso(row.updated_at),\n };\n}\n\nfunction attemptFromRow(row: Record<string, unknown>): BillingAutoRechargeAttempt {\n return {\n id: String(row.id),\n userId: String(row.subject_id),\n provider: String(row.provider),\n idempotencyKey: String(row.idempotency_key),\n providerAttemptId: row.provider_attempt_id == null ? null : String(row.provider_attempt_id),\n topupId: String(row.topup_id),\n quantity: Number(row.quantity),\n state: String(row.state) as BillingAutoRechargeAttempt[\"state\"],\n windowStart: iso(row.window_start),\n windowEnd: iso(row.window_end),\n quotedAmountMinor: row.quoted_amount_minor == null ? null : Number(row.quoted_amount_minor),\n currency: row.currency == null ? null : String(row.currency),\n failureCode: row.failure_code == null ? null : String(row.failure_code),\n failureMessage: row.failure_message == null ? null : String(row.failure_message),\n metadata:\n row.metadata != null && typeof row.metadata === \"object\" && !Array.isArray(row.metadata)\n ? (row.metadata as Record<string, unknown>)\n : {},\n createdAt: iso(row.created_at),\n updatedAt: iso(row.updated_at),\n };\n}\n\nexport class BillingAutoRechargeRepository {\n constructor(private readonly query: QueryFn) {}\n\n async getProfile(userId: string): Promise<BillingAutoRechargeProfile | null> {\n const rows = await this.query(\"SELECT * FROM bursar.get_auto_recharge_profile($1::uuid)\", [\n userId,\n ]);\n const row = rows[0] as Record<string, unknown> | undefined;\n return row?.subject_id == null ? null : profileFromRow(row);\n }\n\n async upsertProfile(\n profile: BillingAutoRechargeProfile,\n options: { resetCooldown?: boolean } = {},\n ): Promise<void> {\n const rows = await this.query(\n `SELECT bursar.upsert_auto_recharge_profile(\n $1::uuid, $2, $3, $4::uuid, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14\n ) AS updated`,\n [\n profile.userId,\n profile.enabled,\n profile.provider,\n profile.topupId,\n profile.quantity,\n profile.threshold,\n profile.maxChargesPerWindow,\n profile.windowUnit,\n profile.windowCount,\n profile.windowAnchor,\n profile.windowTimezone,\n profile.armed,\n profile.state,\n options.resetCooldown ?? false,\n ],\n );\n if (!(rows[0] as Record<string, unknown> | undefined)?.updated) {\n throw new Error(`auto-recharge profile update rejected: ${profile.userId}`);\n }\n }\n\n async claimAttempt(input: {\n userId: string;\n idempotencyKey: string;\n }): Promise<BillingAutoRechargeAttempt | null> {\n const rows = await this.query(\n \"SELECT * FROM bursar.claim_auto_recharge_attempt($1::uuid, $2)\",\n [input.userId, input.idempotencyKey],\n );\n const row = rows[0] as Record<string, unknown> | undefined;\n return row?.id == null ? null : attemptFromRow(row);\n }\n\n private async advanceAttempt(input: {\n id: string;\n state: string;\n providerAttemptId?: string | null;\n failureCode?: string | null;\n failureMessage?: string | null;\n metadata?: Record<string, unknown>;\n }): Promise<void> {\n const failureMessage = optionalBoundedDiagnosticMessage(input.failureMessage);\n const currentRows = await this.query(\n \"SELECT * FROM bursar.get_auto_recharge_attempt($1::uuid)\",\n [input.id],\n );\n const current = String((currentRows[0] as Record<string, unknown> | undefined)?.state ?? \"\");\n const paths: Record<string, Record<string, string[]>> = {\n claimed: {\n submitted: [\"submitted\"],\n processing: [\"submitted\", \"processing\"],\n succeeded: [\"submitted\", \"processing\", \"succeeded\"],\n failed: [\"submitted\", \"processing\", \"failed\"],\n unknown: [\"submitted\", \"processing\", \"unknown\"],\n action_required: [\"submitted\", \"action_required\"],\n },\n submitted: {\n submitted: [],\n processing: [\"processing\"],\n succeeded: [\"processing\", \"succeeded\"],\n failed: [\"processing\", \"failed\"],\n unknown: [\"processing\", \"unknown\"],\n action_required: [\"action_required\"],\n },\n processing: {\n processing: [],\n succeeded: [\"succeeded\"],\n failed: [\"failed\"],\n unknown: [\"unknown\"],\n action_required: [\"action_required\"],\n },\n unknown: {\n unknown: [],\n processing: [\"processing\"],\n succeeded: [\"succeeded\"],\n failed: [\"failed\"],\n action_required: [\"action_required\"],\n },\n action_required: {\n action_required: [],\n processing: [\"processing\"],\n succeeded: [\"succeeded\"],\n failed: [\"failed\"],\n },\n };\n const path = paths[current]?.[input.state];\n if (!path) {\n throw new Error(`auto-recharge attempt transition rejected: ${input.id}`);\n }\n for (const state of path) {\n const rows = await this.query(\n `SELECT bursar.advance_auto_recharge_attempt(\n $1::uuid,\n $2::bursar.recharge_attempt_status,\n $3,\n $4,\n $5,\n $6::jsonb\n ) AS advanced`,\n [\n input.id,\n state,\n input.providerAttemptId ?? null,\n input.failureCode ?? null,\n failureMessage,\n JSON.stringify(input.metadata ?? {}),\n ],\n );\n if (!(rows[0] as Record<string, unknown> | undefined)?.advanced) {\n throw new Error(`auto-recharge attempt transition rejected: ${input.id}`);\n }\n }\n }\n\n async updateAttempt(input: {\n id: string;\n state: string;\n providerAttemptId?: string | null;\n failureCode?: string | null;\n failureMessage?: string | null;\n metadata?: Record<string, unknown>;\n }): Promise<void> {\n return this.advanceAttempt(input);\n }\n\n async updateAttemptByProviderPayment(input: {\n provider: string;\n providerPaymentId: string;\n state: string;\n failureCode?: string | null;\n failureMessage?: string | null;\n }): Promise<void> {\n const rows = await this.query(\n `SELECT * FROM bursar.get_auto_recharge_attempt_by_provider($1, $2)`,\n [input.provider, input.providerPaymentId],\n );\n for (const row of rows as Array<Record<string, unknown>>) {\n if (row.id == null) {\n continue;\n }\n await this.advanceAttempt({\n id: String(row.id),\n state: input.state,\n providerAttemptId: input.providerPaymentId,\n failureCode: input.failureCode,\n failureMessage: input.failureMessage,\n });\n }\n }\n\n async countAttempts(userId: string, since: string | Date): Promise<number> {\n const sinceDate = since instanceof Date ? since : new Date(since);\n if (Number.isNaN(sinceDate.getTime())) {\n throw new TypeError(\"auto-recharge attempt boundary must be a valid instant\");\n }\n const rows = await this.query(\n `SELECT bursar.count_auto_recharge_attempts($1::uuid, $2::timestamptz) AS count`,\n [userId, sinceDate.toISOString()],\n );\n return Number((rows[0] as Record<string, unknown> | undefined)?.count ?? 0);\n }\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { QueryFn } from "../../../shared/postgres-types.js";
|
|
2
|
+
export declare class BillingCustomerRepository {
|
|
3
|
+
private query;
|
|
4
|
+
constructor(query: QueryFn);
|
|
5
|
+
upsert(provider: string, providerCustomerId: string, userId: string, email: string | null): Promise<void>;
|
|
6
|
+
get(provider: string, providerCustomerId: string): Promise<string | null>;
|
|
7
|
+
getByUserId(userId: string, provider?: string | null): Promise<{
|
|
8
|
+
provider: string;
|
|
9
|
+
providerCustomerId: string;
|
|
10
|
+
} | null>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=customer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"customer.d.ts","sourceRoot":"","sources":["../../../../src/billing/postgres/repositories/customer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAEjE,qBAAa,yBAAyB;IACxB,OAAO,CAAC,KAAK;gBAAL,KAAK,EAAE,OAAO;IAE5B,MAAM,CACV,QAAQ,EAAE,MAAM,EAChB,kBAAkB,EAAE,MAAM,EAC1B,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,GAAG,IAAI,GACnB,OAAO,CAAC,IAAI,CAAC;IASV,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IASzE,WAAW,CACf,MAAM,EAAE,MAAM,EACd,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,GACvB,OAAO,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,kBAAkB,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;CASpE"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export class BillingCustomerRepository {
|
|
2
|
+
query;
|
|
3
|
+
constructor(query) {
|
|
4
|
+
this.query = query;
|
|
5
|
+
}
|
|
6
|
+
async upsert(provider, providerCustomerId, userId, email) {
|
|
7
|
+
await this.query("SELECT bursar.upsert_billing_customer($1::uuid, $2, $3, $4)", [
|
|
8
|
+
userId,
|
|
9
|
+
provider,
|
|
10
|
+
providerCustomerId,
|
|
11
|
+
email,
|
|
12
|
+
]);
|
|
13
|
+
}
|
|
14
|
+
async get(provider, providerCustomerId) {
|
|
15
|
+
const rows = await this.query("SELECT * FROM bursar.get_billing_customer_by_provider($1, $2)", [
|
|
16
|
+
provider,
|
|
17
|
+
providerCustomerId,
|
|
18
|
+
]);
|
|
19
|
+
const row = rows[0];
|
|
20
|
+
return row?.subject_id == null ? null : String(row.subject_id);
|
|
21
|
+
}
|
|
22
|
+
async getByUserId(userId, provider) {
|
|
23
|
+
const rows = await this.query("SELECT * FROM bursar.get_billing_customer($1::uuid, $2)", [
|
|
24
|
+
userId,
|
|
25
|
+
provider ?? null,
|
|
26
|
+
]);
|
|
27
|
+
const row = rows[0];
|
|
28
|
+
if (!row)
|
|
29
|
+
return null;
|
|
30
|
+
return { provider: String(row.provider), providerCustomerId: String(row.provider_customer_id) };
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=customer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"customer.js","sourceRoot":"","sources":["../../../../src/billing/postgres/repositories/customer.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,yBAAyB;IAChB;IAApB,YAAoB,KAAc;QAAd,UAAK,GAAL,KAAK,CAAS;IAAG,CAAC;IAEtC,KAAK,CAAC,MAAM,CACV,QAAgB,EAChB,kBAA0B,EAC1B,MAAc,EACd,KAAoB;QAEpB,MAAM,IAAI,CAAC,KAAK,CAAC,6DAA6D,EAAE;YAC9E,MAAM;YACN,QAAQ;YACR,kBAAkB;YAClB,KAAK;SACN,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,QAAgB,EAAE,kBAA0B;QACpD,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,+DAA+D,EAAE;YAC7F,QAAQ;YACR,kBAAkB;SACnB,CAAC,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAwC,CAAC;QAC3D,OAAO,GAAG,EAAE,UAAU,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IACjE,CAAC;IAED,KAAK,CAAC,WAAW,CACf,MAAc,EACd,QAAwB;QAExB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,yDAAyD,EAAE;YACvF,MAAM;YACN,QAAQ,IAAI,IAAI;SACjB,CAAC,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAwC,CAAC;QAC3D,IAAI,CAAC,GAAG;YAAE,OAAO,IAAI,CAAC;QACtB,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,kBAAkB,EAAE,MAAM,CAAC,GAAG,CAAC,oBAAoB,CAAC,EAAE,CAAC;IAClG,CAAC;CACF","sourcesContent":["import type { QueryFn } from \"../../../shared/postgres-types.js\";\n\nexport class BillingCustomerRepository {\n constructor(private query: QueryFn) {}\n\n async upsert(\n provider: string,\n providerCustomerId: string,\n userId: string,\n email: string | null,\n ): Promise<void> {\n await this.query(\"SELECT bursar.upsert_billing_customer($1::uuid, $2, $3, $4)\", [\n userId,\n provider,\n providerCustomerId,\n email,\n ]);\n }\n\n async get(provider: string, providerCustomerId: string): Promise<string | null> {\n const rows = await this.query(\"SELECT * FROM bursar.get_billing_customer_by_provider($1, $2)\", [\n provider,\n providerCustomerId,\n ]);\n const row = rows[0] as Record<string, unknown> | undefined;\n return row?.subject_id == null ? null : String(row.subject_id);\n }\n\n async getByUserId(\n userId: string,\n provider?: string | null,\n ): Promise<{ provider: string; providerCustomerId: string } | null> {\n const rows = await this.query(\"SELECT * FROM bursar.get_billing_customer($1::uuid, $2)\", [\n userId,\n provider ?? null,\n ]);\n const row = rows[0] as Record<string, unknown> | undefined;\n if (!row) return null;\n return { provider: String(row.provider), providerCustomerId: String(row.provider_customer_id) };\n }\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { QueryFn } from "../../../shared/postgres-types.js";
|
|
2
|
+
export declare class BillingDisputeRepository {
|
|
3
|
+
private query;
|
|
4
|
+
constructor(query: QueryFn);
|
|
5
|
+
upsert(provider: string, providerDisputeId: string, paymentId: string, status: string, reason: string | null, metadata: Record<string, unknown>, providerUpdatedAt: string): Promise<void>;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=dispute.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dispute.d.ts","sourceRoot":"","sources":["../../../../src/billing/postgres/repositories/dispute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAEjE,qBAAa,wBAAwB;IACvB,OAAO,CAAC,KAAK;gBAAL,KAAK,EAAE,OAAO;IAE5B,MAAM,CACV,QAAQ,EAAE,MAAM,EAChB,iBAAiB,EAAE,MAAM,EACzB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,GAAG,IAAI,EACrB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,iBAAiB,EAAE,MAAM,GACxB,OAAO,CAAC,IAAI,CAAC;CAcjB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export class BillingDisputeRepository {
|
|
2
|
+
query;
|
|
3
|
+
constructor(query) {
|
|
4
|
+
this.query = query;
|
|
5
|
+
}
|
|
6
|
+
async upsert(provider, providerDisputeId, paymentId, status, reason, metadata, providerUpdatedAt) {
|
|
7
|
+
await this.query(`SELECT bursar.upsert_billing_dispute($1, $2, $3::uuid, $4, $5, $6::jsonb, $7)`, [
|
|
8
|
+
provider,
|
|
9
|
+
providerDisputeId,
|
|
10
|
+
paymentId,
|
|
11
|
+
status,
|
|
12
|
+
reason,
|
|
13
|
+
JSON.stringify(metadata),
|
|
14
|
+
providerUpdatedAt,
|
|
15
|
+
]);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=dispute.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dispute.js","sourceRoot":"","sources":["../../../../src/billing/postgres/repositories/dispute.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,wBAAwB;IACf;IAApB,YAAoB,KAAc;QAAd,UAAK,GAAL,KAAK,CAAS;IAAG,CAAC;IAEtC,KAAK,CAAC,MAAM,CACV,QAAgB,EAChB,iBAAyB,EACzB,SAAiB,EACjB,MAAc,EACd,MAAqB,EACrB,QAAiC,EACjC,iBAAyB;QAEzB,MAAM,IAAI,CAAC,KAAK,CACd,+EAA+E,EAC/E;YACE,QAAQ;YACR,iBAAiB;YACjB,SAAS;YACT,MAAM;YACN,MAAM;YACN,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC;YACxB,iBAAiB;SAClB,CACF,CAAC;IACJ,CAAC;CACF","sourcesContent":["import type { QueryFn } from \"../../../shared/postgres-types.js\";\n\nexport class BillingDisputeRepository {\n constructor(private query: QueryFn) {}\n\n async upsert(\n provider: string,\n providerDisputeId: string,\n paymentId: string,\n status: string,\n reason: string | null,\n metadata: Record<string, unknown>,\n providerUpdatedAt: string,\n ): Promise<void> {\n await this.query(\n `SELECT bursar.upsert_billing_dispute($1, $2, $3::uuid, $4, $5, $6::jsonb, $7)`,\n [\n provider,\n providerDisputeId,\n paymentId,\n status,\n reason,\n JSON.stringify(metadata),\n providerUpdatedAt,\n ],\n );\n }\n}\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { QueryFn } from "../../../shared/postgres-types.js";
|
|
3
|
+
declare const BillingEventRowSchema: z.ZodObject<{
|
|
4
|
+
status: z.ZodOptional<z.ZodString>;
|
|
5
|
+
event_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
6
|
+
claim_token: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
7
|
+
}, z.core.$loose>;
|
|
8
|
+
export type BillingEventRow = z.infer<typeof BillingEventRowSchema>;
|
|
9
|
+
/** Repository for billing event lifecycle operations. */
|
|
10
|
+
export declare class BillingEventRepository {
|
|
11
|
+
private query;
|
|
12
|
+
constructor(query: QueryFn);
|
|
13
|
+
/** Claim a billing event for processing (idempotent claim). */
|
|
14
|
+
claim(provider: string, eventId: string, eventType: string, metadata: string): Promise<BillingEventRow | null>;
|
|
15
|
+
/** Mark a billing event as completed. */
|
|
16
|
+
complete(provider: string, eventId: string, claimToken: string): Promise<boolean>;
|
|
17
|
+
/** Mark a billing event as failed. */
|
|
18
|
+
fail(provider: string, eventId: string, claimToken: string, error?: string): Promise<boolean>;
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=event.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../../../../src/billing/postgres/repositories/event.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAGjE,QAAA,MAAM,qBAAqB;;;;iBAMX,CAAC;AAEjB,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAQpE,yDAAyD;AACzD,qBAAa,sBAAsB;IACrB,OAAO,CAAC,KAAK;gBAAL,KAAK,EAAE,OAAO;IAElC,+DAA+D;IACzD,KAAK,CACT,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;IAiBlC,yCAAyC;IACnC,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAQvF,sCAAsC;IAChC,IAAI,CACR,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,OAAO,CAAC;CAOpB"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { pgBoolean, safeParse } from "../../../shared/postgres-validation.js";
|
|
3
|
+
const BillingEventRowSchema = z
|
|
4
|
+
.object({
|
|
5
|
+
status: z.string().optional(),
|
|
6
|
+
event_id: z.string().uuid().nullable().optional(),
|
|
7
|
+
claim_token: z.string().uuid().nullable().optional(),
|
|
8
|
+
})
|
|
9
|
+
.passthrough();
|
|
10
|
+
function booleanResult(rows, key) {
|
|
11
|
+
const row = rows[0];
|
|
12
|
+
const parsed = pgBoolean.safeParse(row?.[key]);
|
|
13
|
+
return parsed.success && parsed.data;
|
|
14
|
+
}
|
|
15
|
+
/** Repository for billing event lifecycle operations. */
|
|
16
|
+
export class BillingEventRepository {
|
|
17
|
+
query;
|
|
18
|
+
constructor(query) {
|
|
19
|
+
this.query = query;
|
|
20
|
+
}
|
|
21
|
+
/** Claim a billing event for processing (idempotent claim). */
|
|
22
|
+
async claim(provider, eventId, eventType, metadata) {
|
|
23
|
+
const rows = await this.query("SELECT * FROM bursar.claim_billing_event($1, $2, $3, $4)", [
|
|
24
|
+
provider,
|
|
25
|
+
eventId,
|
|
26
|
+
eventType,
|
|
27
|
+
metadata,
|
|
28
|
+
]);
|
|
29
|
+
const row = rows[0];
|
|
30
|
+
return row
|
|
31
|
+
? safeParse(BillingEventRowSchema, { ...row, status: row.result, event_id: row.event_id }, "BillingEventRepository.claim")
|
|
32
|
+
: null;
|
|
33
|
+
}
|
|
34
|
+
/** Mark a billing event as completed. */
|
|
35
|
+
async complete(provider, eventId, claimToken) {
|
|
36
|
+
const rows = await this.query("SELECT bursar.complete_billing_event($1, $2, $3::uuid) AS completed", [provider, eventId, claimToken]);
|
|
37
|
+
return booleanResult(rows, "completed");
|
|
38
|
+
}
|
|
39
|
+
/** Mark a billing event as failed. */
|
|
40
|
+
async fail(provider, eventId, claimToken, error) {
|
|
41
|
+
const rows = await this.query("SELECT bursar.fail_billing_event($1, $2, $3::uuid, $4) AS failed", [provider, eventId, claimToken, error ?? null]);
|
|
42
|
+
return booleanResult(rows, "failed");
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=event.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event.js","sourceRoot":"","sources":["../../../../src/billing/postgres/repositories/event.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,wCAAwC,CAAC;AAE9E,MAAM,qBAAqB,GAAG,CAAC;KAC5B,MAAM,CAAC;IACN,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC7B,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE;IACjD,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE;CACrD,CAAC;KACD,WAAW,EAAE,CAAC;AAIjB,SAAS,aAAa,CAAC,IAAe,EAAE,GAAW;IACjD,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAwC,CAAC;IAC3D,MAAM,M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I,IAAI,CAAC,CAC/C,CAAC;QACF,OAAO,aAAa,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IACvC,CAAC;CACF","sourcesContent":["import { z } from \"zod\";\nimport type { QueryFn } from \"../../../shared/postgres-types.js\";\nimport { pgBoolean, safeParse } from \"../../../shared/postgres-validation.js\";\n\nconst BillingEventRowSchema = z\n .object({\n status: z.string().optional(),\n event_id: z.string().uuid().nullable().optional(),\n claim_token: z.string().uuid().nullable().optional(),\n })\n .passthrough();\n\nexport type BillingEventRow = z.infer<typeof BillingEventRowSchema>;\n\nfunction booleanResult(rows: unknown[], key: string): boolean {\n const row = rows[0] as Record<string, unknown> | undefined;\n const parsed = pgBoolean.safeParse(row?.[key]);\n return parsed.success && parsed.data;\n}\n\n/** Repository for billing event lifecycle operations. */\nexport class BillingEventRepository {\n constructor(private query: QueryFn) {}\n\n /** Claim a billing event for processing (idempotent claim). */\n async claim(\n provider: string,\n eventId: string,\n eventType: string,\n metadata: string,\n ): Promise<BillingEventRow | null> {\n const rows = await this.query(\"SELECT * FROM bursar.claim_billing_event($1, $2, $3, $4)\", [\n provider,\n eventId,\n eventType,\n metadata,\n ]);\n const row = rows[0] as Record<string, unknown> | undefined;\n return row\n ? safeParse(\n BillingEventRowSchema,\n { ...row, status: row.result, event_id: row.event_id },\n \"BillingEventRepository.claim\",\n )\n : null;\n }\n\n /** Mark a billing event as completed. */\n async complete(provider: string, eventId: string, claimToken: string): Promise<boolean> {\n const rows = await this.query(\n \"SELECT bursar.complete_billing_event($1, $2, $3::uuid) AS completed\",\n [provider, eventId, claimToken],\n );\n return booleanResult(rows, \"completed\");\n }\n\n /** Mark a billing event as failed. */\n async fail(\n provider: string,\n eventId: string,\n claimToken: string,\n error?: string,\n ): Promise<boolean> {\n const rows = await this.query(\n \"SELECT bursar.fail_billing_event($1, $2, $3::uuid, $4) AS failed\",\n [provider, eventId, claimToken, error ?? null],\n );\n return booleanResult(rows, \"failed\");\n }\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { QueryFn } from "../../../shared/postgres-types.js";
|
|
2
|
+
import type { BillingInvoiceInfo } from "../../types/index.js";
|
|
3
|
+
export declare class BillingInvoiceRepository {
|
|
4
|
+
private query;
|
|
5
|
+
constructor(query: QueryFn);
|
|
6
|
+
listForUser(userId: string): Promise<BillingInvoiceInfo[]>;
|
|
7
|
+
upsert(subjectId: string, provider: string, providerInvoiceId: string, subscriptionId: string | null, status: string | null, amountPaidMinor: number | null, amountDueMinor: number | null, currency: string, periodStart: string | null, periodEnd: string | null, metadata: Record<string, unknown>, providerUpdatedAt: string): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=invoice.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invoice.d.ts","sourceRoot":"","sources":["../../../../src/billing/postgres/repositories/invoice.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AACjE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE/D,qBAAa,wBAAwB;IACvB,OAAO,CAAC,KAAK;gBAAL,KAAK,EAAE,OAAO;IAE5B,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC;IAc1D,MAAM,CACV,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,iBAAiB,EAAE,MAAM,EACzB,cAAc,EAAE,MAAM,GAAG,IAAI,EAC7B,MAAM,EAAE,MAAM,GAAG,IAAI,EACrB,eAAe,EAAE,MAAM,GAAG,IAAI,EAC9B,cAAc,EAAE,MAAM,GAAG,IAAI,EAC7B,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,GAAG,IAAI,EAC1B,SAAS,EAAE,MAAM,GAAG,IAAI,EACxB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,iBAAiB,EAAE,MAAM,GACxB,OAAO,CAAC,IAAI,CAAC;CAmBjB"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export class BillingInvoiceRepository {
|
|
2
|
+
query;
|
|
3
|
+
constructor(query) {
|
|
4
|
+
this.query = query;
|
|
5
|
+
}
|
|
6
|
+
async listForUser(userId) {
|
|
7
|
+
const rows = await this.query(`SELECT * FROM bursar.list_billing_invoices($1::uuid)`, [userId]);
|
|
8
|
+
return rows.map((row) => ({
|
|
9
|
+
provider: String(row.provider),
|
|
10
|
+
providerInvoiceId: String(row.provider_invoice_id),
|
|
11
|
+
status: row.status == null ? null : String(row.status),
|
|
12
|
+
amountPaidMinor: row.amount_paid_minor == null ? null : Number(row.amount_paid_minor),
|
|
13
|
+
amountDueMinor: row.amount_due_minor == null ? null : Number(row.amount_due_minor),
|
|
14
|
+
currency: row.currency == null ? null : String(row.currency),
|
|
15
|
+
periodStart: row.period_start == null ? null : String(row.period_start),
|
|
16
|
+
periodEnd: row.period_end == null ? null : String(row.period_end),
|
|
17
|
+
}));
|
|
18
|
+
}
|
|
19
|
+
async upsert(subjectId, provider, providerInvoiceId, subscriptionId, status, amountPaidMinor, amountDueMinor, currency, periodStart, periodEnd, metadata, providerUpdatedAt) {
|
|
20
|
+
await this.query(`SELECT bursar.upsert_billing_invoice($1::uuid, $2, $3, $4::uuid, $5, $6, $7, $8, $9, $10, $11::jsonb, $12)`, [
|
|
21
|
+
subjectId,
|
|
22
|
+
provider,
|
|
23
|
+
providerInvoiceId,
|
|
24
|
+
subscriptionId,
|
|
25
|
+
status,
|
|
26
|
+
amountDueMinor,
|
|
27
|
+
amountPaidMinor,
|
|
28
|
+
currency,
|
|
29
|
+
periodStart,
|
|
30
|
+
periodEnd,
|
|
31
|
+
JSON.stringify(metadata),
|
|
32
|
+
providerUpdatedAt,
|
|
33
|
+
]);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=invoice.js.map
|
|
@@ -0,0 +1 @@
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,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC;SAClE,CAAC,CAAC,CAAC;IACN,CAAC;IAED,KAAK,CAAC,MAAM,CACV,SAAiB,EACjB,QAAgB,EAChB,iBAAyB,EACzB,cAA6B,EAC7B,MAAqB,EACrB,eAA8B,EAC9B,cAA6B,EAC7B,QAAgB,EAChB,WAA0B,EAC1B,SAAwB,EACxB,QAAiC,EACjC,iBAAyB;QAEzB,MAAM,IAAI,CAAC,KAAK,CACd,4GAA4G,EAC5G;YACE,SAAS;YACT,QAAQ;YACR,iBAAiB;YACjB,cAAc;YACd,MAAM;YACN,cAAc;YACd,eAAe;YACf,QAAQ;YACR,WAAW;YACX,SAAS;YACT,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC;YACxB,iBAAiB;SAClB,CACF,CAAC;IACJ,CAAC;CACF","sourcesContent":["import type { QueryFn } from \"../../../shared/postgres-types.js\";\nimport type { BillingInvoiceInfo } from \"../../types/index.js\";\n\nexport class BillingInvoiceRepository {\n constructor(private query: QueryFn) {}\n\n async listForUser(userId: string): Promise<BillingInvoiceInfo[]> {\n const rows = await this.query(`SELECT * FROM bursar.list_billing_invoices($1::uuid)`, [userId]);\n return (rows as Array<Record<string, unknown>>).map((row) => ({\n provider: String(row.provider),\n providerInvoiceId: String(row.provider_invoice_id),\n status: row.status == null ? null : String(row.status),\n amountPaidMinor: row.amount_paid_minor == null ? null : Number(row.amount_paid_minor),\n amountDueMinor: row.amount_due_minor == null ? null : Number(row.amount_due_minor),\n currency: row.currency == null ? null : String(row.currency),\n periodStart: row.period_start == null ? null : String(row.period_start),\n periodEnd: row.period_end == null ? null : String(row.period_end),\n }));\n }\n\n async upsert(\n subjectId: string,\n provider: string,\n providerInvoiceId: string,\n subscriptionId: string | null,\n status: string | null,\n amountPaidMinor: number | null,\n amountDueMinor: number | null,\n currency: string,\n periodStart: string | null,\n periodEnd: string | null,\n metadata: Record<string, unknown>,\n providerUpdatedAt: string,\n ): Promise<void> {\n await this.query(\n `SELECT bursar.upsert_billing_invoice($1::uuid, $2, $3, $4::uuid, $5, $6, $7, $8, $9, $10, $11::jsonb, $12)`,\n [\n subjectId,\n provider,\n providerInvoiceId,\n subscriptionId,\n status,\n amountDueMinor,\n amountPaidMinor,\n currency,\n periodStart,\n periodEnd,\n JSON.stringify(metadata),\n providerUpdatedAt,\n ],\n );\n }\n}\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { QueryFn } from "../../../shared/postgres-types.js";
|
|
3
|
+
declare const BillingOfferRowSchema: z.ZodObject<{
|
|
4
|
+
id: z.ZodOptional<z.ZodString>;
|
|
5
|
+
plan_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
6
|
+
offer_key: z.ZodOptional<z.ZodString>;
|
|
7
|
+
plan: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
8
|
+
interval: z.ZodOptional<z.ZodString>;
|
|
9
|
+
interval_count: z.ZodOptional<z.ZodNumber>;
|
|
10
|
+
grant_mode: z.ZodOptional<z.ZodString>;
|
|
11
|
+
grant_credits: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>;
|
|
12
|
+
grant_bucket: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
13
|
+
grant_replace_prior: z.ZodOptional<z.ZodNullable<z.ZodPipe<z.ZodUnion<readonly [z.ZodBoolean, z.ZodString, z.ZodNumber]>, z.ZodTransform<boolean, string | number | boolean>>>>;
|
|
14
|
+
}, z.core.$loose>;
|
|
15
|
+
export type BillingOfferRow = z.infer<typeof BillingOfferRowSchema>;
|
|
16
|
+
/** Repository for billing offer resolution. */
|
|
17
|
+
export declare class BillingOfferRepository {
|
|
18
|
+
private query;
|
|
19
|
+
constructor(query: QueryFn);
|
|
20
|
+
/** Resolve a billing offer by price ID and product ID. */
|
|
21
|
+
resolveByPrice(provider: string, priceId: string | null, productId: string | null): Promise<BillingOfferRow | null>;
|
|
22
|
+
/** Resolve a billing offer by provider lookup key. */
|
|
23
|
+
resolveByLookup(provider: string, lookupKey: string): Promise<BillingOfferRow | null>;
|
|
24
|
+
}
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=offer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"offer.d.ts","sourceRoot":"","sources":["../../../../src/billing/postgres/repositories/offer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAGjE,QAAA,MAAM,qBAAqB;;;;;;;;;;;iBAgBX,CAAC;AAEjB,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAEpE,+CAA+C;AAC/C,qBAAa,sBAAsB;IACrB,OAAO,CAAC,KAAK;gBAAL,KAAK,EAAE,OAAO;IAElC,0DAA0D;IACpD,cAAc,CAClB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,GAAG,IAAI,EACtB,SAAS,EAAE,MAAM,GAAG,IAAI,GACvB,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;IA+BlC,sDAAsD;IAChD,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;CA4B5F"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { pgBoolean, unwrapJsonb, safeParse } from "../../../shared/postgres-validation.js";
|
|
3
|
+
const BillingOfferRowSchema = z
|
|
4
|
+
.object({
|
|
5
|
+
id: z.string().optional(),
|
|
6
|
+
plan_id: z.string().nullable().optional(),
|
|
7
|
+
offer_key: z.string().optional(),
|
|
8
|
+
plan: z.string().nullable().optional(),
|
|
9
|
+
interval: z.string().optional(),
|
|
10
|
+
interval_count: z.number().optional(),
|
|
11
|
+
grant_mode: z.string().optional(),
|
|
12
|
+
grant_credits: z
|
|
13
|
+
.union([z.string(), z.number()])
|
|
14
|
+
.nullable()
|
|
15
|
+
.optional(),
|
|
16
|
+
grant_bucket: z.string().nullable().optional(),
|
|
17
|
+
grant_replace_prior: pgBoolean.nullable().optional(),
|
|
18
|
+
})
|
|
19
|
+
.passthrough();
|
|
20
|
+
/** Repository for billing offer resolution. */
|
|
21
|
+
export class BillingOfferRepository {
|
|
22
|
+
query;
|
|
23
|
+
constructor(query) {
|
|
24
|
+
this.query = query;
|
|
25
|
+
}
|
|
26
|
+
/** Resolve a billing offer by price ID and product ID. */
|
|
27
|
+
async resolveByPrice(provider, priceId, productId) {
|
|
28
|
+
const rows = await this.query("SELECT * FROM bursar.resolve_catalog_offer($1, $2, $3)", [
|
|
29
|
+
provider,
|
|
30
|
+
priceId != null ? "price_id" : "product_id",
|
|
31
|
+
priceId ?? productId,
|
|
32
|
+
]);
|
|
33
|
+
const data = unwrapJsonb(rows);
|
|
34
|
+
const planRows = (await this.query("SELECT * FROM bursar.resolve_catalog_plan($1, $2, $3)", [
|
|
35
|
+
provider,
|
|
36
|
+
priceId != null ? "price_id" : "product_id",
|
|
37
|
+
priceId ?? productId,
|
|
38
|
+
]));
|
|
39
|
+
return data && data.offer_key != null
|
|
40
|
+
? safeParse(BillingOfferRowSchema, {
|
|
41
|
+
...data,
|
|
42
|
+
plan_id: planRows[0]?.id,
|
|
43
|
+
plan: data.plan_key,
|
|
44
|
+
interval: data.billing_unit,
|
|
45
|
+
interval_count: data.billing_count,
|
|
46
|
+
grant_mode: data.cycle_grant_amount == null ? undefined : "cycle_grant",
|
|
47
|
+
grant_credits: data.cycle_grant_amount,
|
|
48
|
+
grant_bucket: data.cycle_grant_bucket_key,
|
|
49
|
+
grant_replace_prior: data.cycle_grant_renewal === "replace_previous",
|
|
50
|
+
}, "BillingOfferRepository.resolveByPrice")
|
|
51
|
+
: null;
|
|
52
|
+
}
|
|
53
|
+
/** Resolve a billing offer by provider lookup key. */
|
|
54
|
+
async resolveByLookup(provider, lookupKey) {
|
|
55
|
+
const rows = await this.query("SELECT * FROM bursar.resolve_catalog_offer($1, 'external_id', $2)", [provider, lookupKey]);
|
|
56
|
+
const data = unwrapJsonb(rows);
|
|
57
|
+
const planRows = (await this.query("SELECT * FROM bursar.resolve_catalog_plan($1, 'external_id', $2)", [provider, lookupKey]));
|
|
58
|
+
return data && data.offer_key != null
|
|
59
|
+
? safeParse(BillingOfferRowSchema, {
|
|
60
|
+
...data,
|
|
61
|
+
plan_id: planRows[0]?.id,
|
|
62
|
+
plan: data.plan_key,
|
|
63
|
+
interval: data.billing_unit,
|
|
64
|
+
interval_count: data.billing_count,
|
|
65
|
+
grant_mode: data.cycle_grant_amount == null ? undefined : "cycle_grant",
|
|
66
|
+
grant_credits: data.cycle_grant_amount,
|
|
67
|
+
grant_bucket: data.cycle_grant_bucket_key,
|
|
68
|
+
grant_replace_prior: data.cycle_grant_renewal === "replace_previous",
|
|
69
|
+
}, "BillingOfferRepository.resolveByLookup")
|
|
70
|
+
: null;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=offer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"offer.js","sourceRoot":"","sources":["../../../../src/billing/postgres/repositories/offer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,wCAAwC,CAAC;AAE3F,MAAM,qBAAqB,GAAG,CAAC;KAC5B,MAAM,CAAC;IACN,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACzB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE;IACzC,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,Q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AAc,EAAE,IAAI,CAAC,aAAa;gBAClC,UAAU,EAAE,IAAI,CAAC,kBAAkB,IAAI,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,aAAa;gBACvE,aAAa,EAAE,IAAI,CAAC,kBAAkB;gBACtC,YAAY,EAAE,IAAI,CAAC,sBAAsB;gBACzC,mBAAmB,EAAE,IAAI,CAAC,mBAAmB,KAAK,kBAAkB;aACrE,EACD,wCAAwC,CACzC;YACH,CAAC,CAAC,IAAI,CAAC;IACX,CAAC;CACF","sourcesContent":["import { z } from \"zod\";\nimport type { QueryFn } from \"../../../shared/postgres-types.js\";\nimport { pgBoolean, unwrapJsonb, safeParse } from \"../../../shared/postgres-validation.js\";\n\nconst BillingOfferRowSchema = z\n .object({\n id: z.string().optional(),\n plan_id: z.string().nullable().optional(),\n offer_key: z.string().optional(),\n plan: z.string().nullable().optional(),\n interval: z.string().optional(),\n interval_count: z.number().optional(),\n grant_mode: z.string().optional(),\n grant_credits: z\n .union([z.string(), z.number()] as const)\n .nullable()\n .optional(),\n grant_bucket: z.string().nullable().optional(),\n grant_replace_prior: pgBoolean.nullable().optional(),\n })\n .passthrough();\n\nexport type BillingOfferRow = z.infer<typeof BillingOfferRowSchema>;\n\n/** Repository for billing offer resolution. */\nexport class BillingOfferRepository {\n constructor(private query: QueryFn) {}\n\n /** Resolve a billing offer by price ID and product ID. */\n async resolveByPrice(\n provider: string,\n priceId: string | null,\n productId: string | null,\n ): Promise<BillingOfferRow | null> {\n const rows = await this.query(\"SELECT * FROM bursar.resolve_catalog_offer($1, $2, $3)\", [\n provider,\n priceId != null ? \"price_id\" : \"product_id\",\n priceId ?? productId,\n ]);\n const data = unwrapJsonb(rows);\n const planRows = (await this.query(\"SELECT * FROM bursar.resolve_catalog_plan($1, $2, $3)\", [\n provider,\n priceId != null ? \"price_id\" : \"product_id\",\n priceId ?? productId,\n ])) as Array<Record<string, unknown>>;\n return data && data.offer_key != null\n ? safeParse(\n BillingOfferRowSchema,\n {\n ...data,\n plan_id: planRows[0]?.id,\n plan: data.plan_key,\n interval: data.billing_unit,\n interval_count: data.billing_count,\n grant_mode: data.cycle_grant_amount == null ? undefined : \"cycle_grant\",\n grant_credits: data.cycle_grant_amount,\n grant_bucket: data.cycle_grant_bucket_key,\n grant_replace_prior: data.cycle_grant_renewal === \"replace_previous\",\n },\n \"BillingOfferRepository.resolveByPrice\",\n )\n : null;\n }\n\n /** Resolve a billing offer by provider lookup key. */\n async resolveByLookup(provider: string, lookupKey: string): Promise<BillingOfferRow | null> {\n const rows = await this.query(\n \"SELECT * FROM bursar.resolve_catalog_offer($1, 'external_id', $2)\",\n [provider, lookupKey],\n );\n const data = unwrapJsonb(rows);\n const planRows = (await this.query(\n \"SELECT * FROM bursar.resolve_catalog_plan($1, 'external_id', $2)\",\n [provider, lookupKey],\n )) as Array<Record<string, unknown>>;\n return data && data.offer_key != null\n ? safeParse(\n BillingOfferRowSchema,\n {\n ...data,\n plan_id: planRows[0]?.id,\n plan: data.plan_key,\n interval: data.billing_unit,\n interval_count: data.billing_count,\n grant_mode: data.cycle_grant_amount == null ? undefined : \"cycle_grant\",\n grant_credits: data.cycle_grant_amount,\n grant_bucket: data.cycle_grant_bucket_key,\n grant_replace_prior: data.cycle_grant_renewal === \"replace_previous\",\n },\n \"BillingOfferRepository.resolveByLookup\",\n )\n : null;\n }\n}\n"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { QueryFn } from "../../../shared/postgres-types.js";
|
|
3
|
+
declare const BillingPaymentRowSchema: z.ZodObject<{
|
|
4
|
+
provider: z.ZodOptional<z.ZodString>;
|
|
5
|
+
provider_payment_id: z.ZodOptional<z.ZodString>;
|
|
6
|
+
subject_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
7
|
+
user_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
8
|
+
amount_minor: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
9
|
+
tax_minor: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>;
|
|
10
|
+
currency: z.ZodOptional<z.ZodString>;
|
|
11
|
+
purpose: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
12
|
+
status: z.ZodOptional<z.ZodString>;
|
|
13
|
+
provider_updated_at: z.ZodOptional<z.ZodUnknown>;
|
|
14
|
+
metadata: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
15
|
+
}, z.core.$loose>;
|
|
16
|
+
declare const ForRefundRowSchema: z.ZodObject<{
|
|
17
|
+
credits_per_unit: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>;
|
|
18
|
+
credits_per_major_unit: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>;
|
|
19
|
+
tier: z.ZodOptional<z.ZodString>;
|
|
20
|
+
deposit_to: z.ZodOptional<z.ZodString>;
|
|
21
|
+
}, z.core.$loose>;
|
|
22
|
+
export type BillingPaymentRow = z.infer<typeof BillingPaymentRowSchema>;
|
|
23
|
+
export type ForRefundRow = z.infer<typeof ForRefundRowSchema>;
|
|
24
|
+
export declare class BillingPaymentRepository {
|
|
25
|
+
private query;
|
|
26
|
+
constructor(query: QueryFn);
|
|
27
|
+
upsert(provider: string, providerPaymentId: string, providerInvoiceId: string | null, userId: string | null, amountMinor: number, taxMinor: number | null, currency: string, purpose: string | null, metadata: string | null, status: string, providerUpdatedAt: string): Promise<string>;
|
|
28
|
+
getForRefund(provider: string, providerPaymentId: string): Promise<ForRefundRow | null>;
|
|
29
|
+
getDirect(provider: string, providerPaymentId: string): Promise<BillingPaymentRow | null>;
|
|
30
|
+
}
|
|
31
|
+
export {};
|
|
32
|
+
//# sourceMappingURL=payment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payment.d.ts","sourceRoot":"","sources":["../../../../src/billing/postgres/repositories/payment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAGjE,QAAA,MAAM,uBAAuB;;;;;;;;;;;;iBAcb,CAAC;AACjB,QAAA,MAAM,kBAAkB;;;;;iBAOR,CAAC;AACjB,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AACxE,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAE9D,qBAAa,wBAAwB;IACvB,OAAO,CAAC,KAAK;gBAAL,KAAK,EAAE,OAAO;IAC5B,MAAM,CACV,QAAQ,EAAE,MAAM,EAChB,iBAAiB,EAAE,MAAM,EACzB,iBAAiB,EAAE,MAAM,GAAG,IAAI,EAChC,MAAM,EAAE,MAAM,GAAG,IAAI,EACrB,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,GAAG,IAAI,EACvB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,GAAG,IAAI,EACtB,QAAQ,EAAE,MAAM,GAAG,IAAI,EACvB,MAAM,EAAE,MAAM,EACd,iBAAiB,EAAE,MAAM,GACxB,OAAO,CAAC,MAAM,CAAC;IA2BZ,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAUvF,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC;CAUhG"}
|