@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,97 @@
|
|
|
1
|
+
import type { ProviderRef } from "./common.js";
|
|
2
|
+
export type BillingSubscriptionStatus = "incomplete" | "incomplete_expired" | "trialing" | "active" | "past_due" | "canceled" | "unpaid" | "paused" | "expired";
|
|
3
|
+
export declare const SUBSCRIPTION_STATUS: {
|
|
4
|
+
readonly ACTIVE: "active";
|
|
5
|
+
readonly TRIALING: "trialing";
|
|
6
|
+
readonly CANCELED: "canceled";
|
|
7
|
+
readonly INCOMPLETE: "incomplete";
|
|
8
|
+
readonly PAST_DUE: "past_due";
|
|
9
|
+
readonly INCOMPLETE_EXPIRED: "incomplete_expired";
|
|
10
|
+
readonly UNPAID: "unpaid";
|
|
11
|
+
readonly PAUSED: "paused";
|
|
12
|
+
readonly EXPIRED: "expired";
|
|
13
|
+
};
|
|
14
|
+
export interface BillingSubscriptionInfo {
|
|
15
|
+
providerSubscriptionId: string;
|
|
16
|
+
status?: BillingSubscriptionStatus | null;
|
|
17
|
+
cancelAtPeriodEnd?: boolean | null;
|
|
18
|
+
periodStart?: string | null;
|
|
19
|
+
periodEnd?: string | null;
|
|
20
|
+
trialEnd?: string | null;
|
|
21
|
+
cancelAt?: string | null;
|
|
22
|
+
endedAt?: string | null;
|
|
23
|
+
refs?: ProviderRef | null;
|
|
24
|
+
interval?: string | null;
|
|
25
|
+
intervalCount?: number | null;
|
|
26
|
+
}
|
|
27
|
+
export interface BillingSubscriptionState {
|
|
28
|
+
subscriptionId?: string | null;
|
|
29
|
+
userId: string;
|
|
30
|
+
provider: string;
|
|
31
|
+
providerSubscriptionId: string;
|
|
32
|
+
providerCustomerId?: string | null;
|
|
33
|
+
offerId?: string | null;
|
|
34
|
+
offerKey?: string | null;
|
|
35
|
+
planId?: string | null;
|
|
36
|
+
plan?: string | null;
|
|
37
|
+
status?: BillingSubscriptionStatus;
|
|
38
|
+
currentPeriodStart?: string | null;
|
|
39
|
+
currentPeriodEnd?: string | null;
|
|
40
|
+
trialEnd?: string | null;
|
|
41
|
+
cancelAt?: string | null;
|
|
42
|
+
endedAt?: string | null;
|
|
43
|
+
graceEndsAt?: string | null;
|
|
44
|
+
graceExpiredAt?: string | null;
|
|
45
|
+
providerUpdatedAt?: string | null;
|
|
46
|
+
cancelAtPeriodEnd?: boolean;
|
|
47
|
+
interval?: string | null;
|
|
48
|
+
intervalCount?: number | null;
|
|
49
|
+
metadata?: Record<string, unknown> | null;
|
|
50
|
+
}
|
|
51
|
+
export type BillingSubscriptionChangeState = "awaiting_payment" | "scheduled" | "applied" | "failed" | "canceled";
|
|
52
|
+
export interface BillingSubscriptionOfferContext {
|
|
53
|
+
offerId: string;
|
|
54
|
+
offerKey: string;
|
|
55
|
+
planId?: string | null;
|
|
56
|
+
plan?: string | null;
|
|
57
|
+
interval?: string | null;
|
|
58
|
+
intervalCount?: number | null;
|
|
59
|
+
}
|
|
60
|
+
export interface BillingSubscriptionChange {
|
|
61
|
+
id: string;
|
|
62
|
+
subscriptionId: string;
|
|
63
|
+
fromOfferId: string;
|
|
64
|
+
toOfferId: string;
|
|
65
|
+
fromOffer: BillingSubscriptionOfferContext;
|
|
66
|
+
toOffer: BillingSubscriptionOfferContext;
|
|
67
|
+
effectiveAt: string | null;
|
|
68
|
+
effective: "immediate" | "renewal";
|
|
69
|
+
state: BillingSubscriptionChangeState;
|
|
70
|
+
prorationBehavior: "provider_default" | "invoice_immediately" | "none";
|
|
71
|
+
idempotencyKey: string;
|
|
72
|
+
providerOperationId?: string | null;
|
|
73
|
+
errorMessage?: string | null;
|
|
74
|
+
}
|
|
75
|
+
export interface BillingSubscriptionChangeInput {
|
|
76
|
+
provider: string;
|
|
77
|
+
providerSubscriptionId: string;
|
|
78
|
+
toOfferId: string;
|
|
79
|
+
effectiveAt: string;
|
|
80
|
+
effective: "immediate" | "renewal";
|
|
81
|
+
idempotencyKey: string;
|
|
82
|
+
prorationBehavior?: "provider_default" | "invoice_immediately" | "none";
|
|
83
|
+
}
|
|
84
|
+
export type CheckoutIntentStatus = "open" | "completed" | "failed" | "expired";
|
|
85
|
+
export interface CheckoutIntent {
|
|
86
|
+
id: string;
|
|
87
|
+
subjectId: string;
|
|
88
|
+
provider: string;
|
|
89
|
+
checkoutKind: "subscription" | "credit_topup";
|
|
90
|
+
productKey: string;
|
|
91
|
+
requestDigest: string;
|
|
92
|
+
status: CheckoutIntentStatus;
|
|
93
|
+
providerSessionId?: string | null;
|
|
94
|
+
checkoutUrl?: string | null;
|
|
95
|
+
expiresAt: string;
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=subscriptions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscriptions.d.ts","sourceRoot":"","sources":["../../../src/billing/types/subscriptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,MAAM,MAAM,yBAAyB,GACjC,YAAY,GACZ,oBAAoB,GACpB,UAAU,GACV,QAAQ,GACR,UAAU,GACV,UAAU,GACV,QAAQ,GACR,QAAQ,GACR,SAAS,CAAC;AAEd,eAAO,MAAM,mBAAmB;;;;;;;;;;CAU8B,CAAC;AAE/D,MAAM,WAAW,uBAAuB;IACtC,sBAAsB,EAAE,MAAM,CAAC;IAC/B,MAAM,CAAC,EAAE,yBAAyB,GAAG,IAAI,CAAC;IAC1C,iBAAiB,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IACnC,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC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,MAAM,GAAG,WAAW,GAAG,QAAQ,GAAG,SAAS,CAAC;AAE/E,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,cAAc,GAAG,cAAc,CAAC;IAC9C,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,oBAAoB,CAAC;IAC7B,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,SAAS,EAAE,MAAM,CAAC;CACnB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const SUBSCRIPTION_STATUS = {
|
|
2
|
+
ACTIVE: "active",
|
|
3
|
+
TRIALING: "trialing",
|
|
4
|
+
CANCELED: "canceled",
|
|
5
|
+
INCOMPLETE: "incomplete",
|
|
6
|
+
PAST_DUE: "past_due",
|
|
7
|
+
INCOMPLETE_EXPIRED: "incomplete_expired",
|
|
8
|
+
UNPAID: "unpaid",
|
|
9
|
+
PAUSED: "paused",
|
|
10
|
+
EXPIRED: "expired",
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=subscriptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscriptions.js","sourceRoot":"","sources":["../../../src/billing/types/subscriptions.ts"],"names":[],"mappings":"AAaA,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,MAAM,EAAE,QAAQ;IAChB,QAAQ,EAAE,UAAU;IACpB,QAAQ,EAAE,UAAU;IACpB,UAAU,EAAE,YAAY;IACxB,QAAQ,EAAE,UAAU;IACpB,kBAAkB,EAAE,oBAAoB;IACxC,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,SAAS;CAC0C,CAAC","sourcesContent":["import type { ProviderRef } from \"./common.js\";\n\nexport type BillingSubscriptionStatus =\n | \"incomplete\"\n | \"incomplete_expired\"\n | \"trialing\"\n | \"active\"\n | \"past_due\"\n | \"canceled\"\n | \"unpaid\"\n | \"paused\"\n | \"expired\";\n\nexport const SUBSCRIPTION_STATUS = {\n ACTIVE: \"active\",\n TRIALING: \"trialing\",\n CANCELED: \"canceled\",\n INCOMPLETE: \"incomplete\",\n PAST_DUE: \"past_due\",\n INCOMPLETE_EXPIRED: \"incomplete_expired\",\n UNPAID: \"unpaid\",\n PAUSED: \"paused\",\n EXPIRED: \"expired\",\n} as const satisfies Record<string, BillingSubscriptionStatus>;\n\nexport interface BillingSubscriptionInfo {\n providerSubscriptionId: string;\n status?: BillingSubscriptionStatus | null;\n cancelAtPeriodEnd?: boolean | null;\n periodStart?: string | null;\n periodEnd?: string | null;\n trialEnd?: string | null;\n cancelAt?: string | null;\n endedAt?: string | null;\n refs?: ProviderRef | null;\n interval?: string | null;\n intervalCount?: number | null;\n}\n\nexport interface BillingSubscriptionState {\n subscriptionId?: string | null;\n userId: string;\n provider: string;\n providerSubscriptionId: string;\n providerCustomerId?: string | null;\n offerId?: string | null;\n offerKey?: string | null;\n planId?: string | null;\n plan?: string | null;\n status?: BillingSubscriptionStatus;\n currentPeriodStart?: string | null;\n currentPeriodEnd?: string | null;\n trialEnd?: string | null;\n cancelAt?: string | null;\n endedAt?: string | null;\n graceEndsAt?: string | null;\n graceExpiredAt?: string | null;\n providerUpdatedAt?: string | null;\n cancelAtPeriodEnd?: boolean;\n interval?: string | null;\n intervalCount?: number | null;\n metadata?: Record<string, unknown> | null;\n}\n\nexport type BillingSubscriptionChangeState =\n \"awaiting_payment\" | \"scheduled\" | \"applied\" | \"failed\" | \"canceled\";\n\nexport interface BillingSubscriptionOfferContext {\n offerId: string;\n offerKey: string;\n planId?: string | null;\n plan?: string | null;\n interval?: string | null;\n intervalCount?: number | null;\n}\n\nexport interface BillingSubscriptionChange {\n id: string;\n subscriptionId: string;\n fromOfferId: string;\n toOfferId: string;\n fromOffer: BillingSubscriptionOfferContext;\n toOffer: BillingSubscriptionOfferContext;\n effectiveAt: string | null;\n effective: \"immediate\" | \"renewal\";\n state: BillingSubscriptionChangeState;\n prorationBehavior: \"provider_default\" | \"invoice_immediately\" | \"none\";\n idempotencyKey: string;\n providerOperationId?: string | null;\n errorMessage?: string | null;\n}\n\nexport interface BillingSubscriptionChangeInput {\n provider: string;\n providerSubscriptionId: string;\n toOfferId: string;\n effectiveAt: string;\n effective: \"immediate\" | \"renewal\";\n idempotencyKey: string;\n prorationBehavior?: \"provider_default\" | \"invoice_immediately\" | \"none\";\n}\n\nexport type CheckoutIntentStatus = \"open\" | \"completed\" | \"failed\" | \"expired\";\n\nexport interface CheckoutIntent {\n id: string;\n subjectId: string;\n provider: string;\n checkoutKind: \"subscription\" | \"credit_topup\";\n productKey: string;\n requestDigest: string;\n status: CheckoutIntentStatus;\n providerSessionId?: string | null;\n checkoutUrl?: string | null;\n expiresAt: string;\n}\n"]}
|
package/dist/breakdown.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import Decimal from "decimal.js";
|
|
|
3
3
|
* Granular credit cost report for a usage event.
|
|
4
4
|
*
|
|
5
5
|
* All money fields are `Decimal` (never binary `number`) and are quantized to
|
|
6
|
-
*
|
|
6
|
+
* 6dp ROUND_HALF_UP. `total` is the single source of truth: it is recomputed
|
|
7
7
|
* from the components (clamped at 0) and quantized — there is NO implicit
|
|
8
8
|
* integer truncation of the total (that was the revenue-leak bug).
|
|
9
9
|
*/
|
|
@@ -13,6 +13,7 @@ export interface CostBreakdown {
|
|
|
13
13
|
searchCredits: Decimal;
|
|
14
14
|
cacheSavings: Decimal;
|
|
15
15
|
fixedCredits: Decimal;
|
|
16
|
+
operationCredits: Decimal;
|
|
16
17
|
total: Decimal;
|
|
17
18
|
breakdown: Record<string, unknown>;
|
|
18
19
|
}
|
|
@@ -22,6 +23,7 @@ export declare function makeCostBreakdown(partial?: {
|
|
|
22
23
|
searchCredits?: Decimal;
|
|
23
24
|
cacheSavings?: Decimal;
|
|
24
25
|
fixedCredits?: Decimal;
|
|
26
|
+
operationCredits?: Decimal;
|
|
25
27
|
breakdown?: Record<string, unknown>;
|
|
26
28
|
}): CostBreakdown;
|
|
27
29
|
//# sourceMappingURL=breakdown.d.ts.map
|
package/dist/breakdown.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"breakdown.d.ts","sourceRoot":"","sources":["../src/breakdown.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,YAAY,CAAC;AAGjC;;;;;;;GAOG;AACH,MAAM,WAAW,aAAa;IAC5B,YAAY,EAAE,OAAO,CAAC;IACtB,WAAW,EAAE,OAAO,CAAC;IACrB,aAAa,EAAE,OAAO,CAAC;IACvB,YAAY,EAAE,OAAO,CAAC;IACtB,YAAY,EAAE,OAAO,CAAC;IACtB,KAAK,EAAE,OAAO,CAAC;IACf,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,wBAAgB,iBAAiB,CAAC,OAAO,CAAC,EAAE;IAC1C,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACrC,GAAG,aAAa,
|
|
1
|
+
{"version":3,"file":"breakdown.d.ts","sourceRoot":"","sources":["../src/breakdown.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,YAAY,CAAC;AAGjC;;;;;;;GAOG;AACH,MAAM,WAAW,aAAa;IAC5B,YAAY,EAAE,OAAO,CAAC;IACtB,WAAW,EAAE,OAAO,CAAC;IACrB,aAAa,EAAE,OAAO,CAAC;IACvB,YAAY,EAAE,OAAO,CAAC;IACtB,YAAY,EAAE,OAAO,CAAC;IACtB,gBAAgB,EAAE,OAAO,CAAC;IAC1B,KAAK,EAAE,OAAO,CAAC;IACf,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,wBAAgB,iBAAiB,CAAC,OAAO,CAAC,EAAE;IAC1C,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACrC,GAAG,aAAa,CA4BhB"}
|
package/dist/breakdown.js
CHANGED
|
@@ -6,12 +6,14 @@ export function makeCostBreakdown(partial) {
|
|
|
6
6
|
const searchCredits = quantizeMoney(partial?.searchCredits ?? new Decimal(0));
|
|
7
7
|
const cacheSavings = quantizeMoney(partial?.cacheSavings ?? new Decimal(0));
|
|
8
8
|
const fixedCredits = quantizeMoney(partial?.fixedCredits ?? new Decimal(0));
|
|
9
|
+
const operationCredits = quantizeMoney(partial?.operationCredits ?? new Decimal(0));
|
|
9
10
|
// Single source of truth for the total: sum of components, clamped at 0,
|
|
10
|
-
// quantized to
|
|
11
|
+
// quantized to 6dp HALF_UP.
|
|
11
12
|
const rawTotal = modelCredits
|
|
12
13
|
.plus(toolCredits)
|
|
13
14
|
.plus(searchCredits)
|
|
14
15
|
.plus(fixedCredits)
|
|
16
|
+
.plus(operationCredits)
|
|
15
17
|
.plus(cacheSavings);
|
|
16
18
|
const total = quantizeMoney(Decimal.max(new Decimal(0), rawTotal));
|
|
17
19
|
return {
|
|
@@ -20,6 +22,7 @@ export function makeCostBreakdown(partial) {
|
|
|
20
22
|
searchCredits,
|
|
21
23
|
cacheSavings,
|
|
22
24
|
fixedCredits,
|
|
25
|
+
operationCredits,
|
|
23
26
|
total,
|
|
24
27
|
breakdown: partial?.breakdown ?? {},
|
|
25
28
|
};
|
package/dist/breakdown.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"breakdown.js","sourceRoot":"","sources":["../src/breakdown.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"breakdown.js","sourceRoot":"","sources":["../src/breakdown.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAqB1C,MAAM,UAAU,iBAAiB,CAAC,OAQjC;IACC,MAAM,YAAY,GAAG,aAAa,CAAC,OAAO,EAAE,YAAY,IAAI,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5E,MAAM,WAAW,GAAG,aAAa,CAAC,OAAO,EAAE,WAAW,IAAI,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1E,MAAM,aAAa,GAAG,aAAa,CAAC,OAAO,EAAE,aAAa,IAAI,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9E,MAAM,YAAY,GAAG,aAAa,CAAC,OAAO,EAAE,YAAY,IAAI,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5E,MAAM,YAAY,GAAG,aAAa,CAAC,OAAO,EAAE,YAAY,IAAI,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5E,MAAM,gBAAgB,GAAG,aAAa,CAAC,OAAO,EAAE,gBAAgB,IAAI,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IAEpF,yEAAyE;IACzE,4BAA4B;IAC5B,MAAM,QAAQ,GAAG,YAAY;SAC1B,IAAI,CAAC,WAAW,CAAC;SACjB,IAAI,CAAC,aAAa,CAAC;SACnB,IAAI,CAAC,YAAY,CAAC;SAClB,IAAI,CAAC,gBAAgB,CAAC;SACtB,IAAI,CAAC,YAAY,CAAC,CAAC;IACtB,MAAM,KAAK,GAAG,aAAa,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC;IAEnE,OAAO;QACL,YAAY;QACZ,WAAW;QACX,aAAa;QACb,YAAY;QACZ,YAAY;QACZ,gBAAgB;QAChB,KAAK;QACL,SAAS,EAAE,OAAO,EAAE,SAAS,IAAI,EAAE;KACpC,CAAC;AACJ,CAAC","sourcesContent":["import Decimal from \"decimal.js\";\nimport { quantizeMoney } from \"./expr.js\";\n\n/**\n * Granular credit cost report for a usage event.\n *\n * All money fields are `Decimal` (never binary `number`) and are quantized to\n * 6dp ROUND_HALF_UP. `total` is the single source of truth: it is recomputed\n * from the components (clamped at 0) and quantized — there is NO implicit\n * integer truncation of the total (that was the revenue-leak bug).\n */\nexport interface CostBreakdown {\n modelCredits: Decimal;\n toolCredits: Decimal;\n searchCredits: Decimal;\n cacheSavings: Decimal;\n fixedCredits: Decimal;\n operationCredits: Decimal;\n total: Decimal;\n breakdown: Record<string, unknown>;\n}\n\nexport function makeCostBreakdown(partial?: {\n modelCredits?: Decimal;\n toolCredits?: Decimal;\n searchCredits?: Decimal;\n cacheSavings?: Decimal;\n fixedCredits?: Decimal;\n operationCredits?: Decimal;\n breakdown?: Record<string, unknown>;\n}): CostBreakdown {\n const modelCredits = quantizeMoney(partial?.modelCredits ?? new Decimal(0));\n const toolCredits = quantizeMoney(partial?.toolCredits ?? new Decimal(0));\n const searchCredits = quantizeMoney(partial?.searchCredits ?? new Decimal(0));\n const cacheSavings = quantizeMoney(partial?.cacheSavings ?? new Decimal(0));\n const fixedCredits = quantizeMoney(partial?.fixedCredits ?? new Decimal(0));\n const operationCredits = quantizeMoney(partial?.operationCredits ?? new Decimal(0));\n\n // Single source of truth for the total: sum of components, clamped at 0,\n // quantized to 6dp HALF_UP.\n const rawTotal = modelCredits\n .plus(toolCredits)\n .plus(searchCredits)\n .plus(fixedCredits)\n .plus(operationCredits)\n .plus(cacheSavings);\n const total = quantizeMoney(Decimal.max(new Decimal(0), rawTotal));\n\n return {\n modelCredits,\n toolCredits,\n searchCredits,\n cacheSavings,\n fixedCredits,\n operationCredits,\n total,\n breakdown: partial?.breakdown ?? {},\n };\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Browser-safe bursar exports.
|
|
2
|
+
*
|
|
3
|
+
* This entrypoint intentionally contains no database stores or Node-only
|
|
4
|
+
* dependencies, so it can be imported by Client Components.
|
|
5
|
+
*/
|
|
6
|
+
export { AUTO_RECHARGE_STATES } from "./billing/types/index.js";
|
|
7
|
+
export type { BillingAutoRechargeStatus } from "./billing/types/index.js";
|
|
8
|
+
//# sourceMappingURL=browser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,YAAY,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC"}
|
package/dist/browser.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Browser-safe bursar exports.
|
|
2
|
+
*
|
|
3
|
+
* This entrypoint intentionally contains no database stores or Node-only
|
|
4
|
+
* dependencies, so it can be imported by Client Components.
|
|
5
|
+
*/
|
|
6
|
+
export { AUTO_RECHARGE_STATES } from "./billing/types/index.js";
|
|
7
|
+
//# sourceMappingURL=browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.js","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC","sourcesContent":["/** Browser-safe bursar exports.\n *\n * This entrypoint intentionally contains no database stores or Node-only\n * dependencies, so it can be imported by Client Components.\n */\nexport { AUTO_RECHARGE_STATES } from \"./billing/types/index.js\";\nexport type { BillingAutoRechargeStatus } from \"./billing/types/index.js\";\n"]}
|
package/dist/bursar.d.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { type BillingServiceOptions } from "./billing/billing-service.js";
|
|
2
|
+
import type { BillingStore } from "./billing/billing-store.js";
|
|
3
|
+
import { CreditsService as CreditsServiceImpl, type CreditsServiceOptions } from "./credits/service.js";
|
|
4
|
+
import type { CreditStore } from "./credits/store.js";
|
|
5
|
+
import type { CreditEventEmitter } from "./credits/events.js";
|
|
6
|
+
import type { BillingEvent, BillingEventResult } from "./billing/types/index.js";
|
|
7
|
+
import type { BillingCapability as BillingService, BillingEventSink } from "./billing/contracts.js";
|
|
8
|
+
import { CommerceService as CommerceServiceImpl } from "./commerce/service.js";
|
|
9
|
+
import type { CommerceOptions } from "./commerce/types.js";
|
|
10
|
+
import type { CatalogRollout, ParsedBursarConfig } from "./config/types.js";
|
|
11
|
+
import { type PublicCatalog } from "./catalog.js";
|
|
12
|
+
import type { CreditMetadata, GrantProgramAwardResult } from "./credits/types/index.js";
|
|
13
|
+
export type { BillingCapability as BillingService, BillingEventSink } from "./billing/contracts.js";
|
|
14
|
+
export type { CommerceOptions } from "./commerce/types.js";
|
|
15
|
+
/** Public credit capability. The implementation remains package-private. */
|
|
16
|
+
export type CreditsService = Pick<CreditsServiceImpl, keyof CreditsServiceImpl>;
|
|
17
|
+
/** Options for constructing the single application-facing Bursar service. */
|
|
18
|
+
export interface BursarOptions {
|
|
19
|
+
creditStore: CreditStore;
|
|
20
|
+
billingStore?: BillingStore | null;
|
|
21
|
+
credits?: CreditsService | null;
|
|
22
|
+
creditsOptions?: CreditsServiceOptions | null;
|
|
23
|
+
billingOptions?: BillingServiceOptions | null;
|
|
24
|
+
commerceOptions?: CommerceOptions | null;
|
|
25
|
+
emitter?: CreditEventEmitter | null;
|
|
26
|
+
}
|
|
27
|
+
/** Catalog operations. Configuration writes live here, never in BillingService. */
|
|
28
|
+
export declare class CatalogService {
|
|
29
|
+
private readonly credits;
|
|
30
|
+
constructor(credits: CreditsService);
|
|
31
|
+
get active(): Promise<import("./index.js").BursarConfigResult | null>;
|
|
32
|
+
getConfig(): Promise<ParsedBursarConfig>;
|
|
33
|
+
publicView(): Promise<PublicCatalog>;
|
|
34
|
+
publishDraft(config: Record<string, unknown>, label?: string | null): Promise<string>;
|
|
35
|
+
activate(version: number, rollout?: CatalogRollout | Record<string, unknown> | null): Promise<string>;
|
|
36
|
+
publishAndActivate(config: Record<string, unknown>, label?: string | null, rollout?: CatalogRollout | Record<string, unknown> | null): Promise<void>;
|
|
37
|
+
/** Pin or unpin one current assignment from automatic catalog rollout. */
|
|
38
|
+
setRevisionPin(userId: string, pinned: boolean): Promise<boolean>;
|
|
39
|
+
/** Apply one bounded batch of renewal-effective plan changes. */
|
|
40
|
+
applyDueChanges(limit?: number): Promise<number>;
|
|
41
|
+
}
|
|
42
|
+
export interface AccountCreatedInput {
|
|
43
|
+
accountId: string;
|
|
44
|
+
eventKey: string;
|
|
45
|
+
region?: string | null;
|
|
46
|
+
metadata?: CreditMetadata | null;
|
|
47
|
+
}
|
|
48
|
+
export interface AccountCreatedResult {
|
|
49
|
+
accountId: string;
|
|
50
|
+
planKey: string;
|
|
51
|
+
planAssigned: boolean;
|
|
52
|
+
grants: GrantProgramAwardResult[];
|
|
53
|
+
}
|
|
54
|
+
/** Generic financial lifecycle operations for SaaS accounts. */
|
|
55
|
+
export declare class AccountService {
|
|
56
|
+
private readonly credits;
|
|
57
|
+
private readonly catalog;
|
|
58
|
+
constructor(credits: CreditsService, catalog: CatalogService);
|
|
59
|
+
onAccountCreated(input: AccountCreatedInput): Promise<AccountCreatedResult>;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The application-facing Bursar boundary.
|
|
63
|
+
*
|
|
64
|
+
* Credit and billing services are deliberately created together so consumers
|
|
65
|
+
* cannot accidentally construct unrelated services for the same account
|
|
66
|
+
* lifecycle. Provider and application integrations use this facade rather
|
|
67
|
+
* than constructing lifecycle services independently.
|
|
68
|
+
*/
|
|
69
|
+
export declare class Bursar implements BillingEventSink {
|
|
70
|
+
readonly credits: CreditsService;
|
|
71
|
+
readonly billing: BillingService | null;
|
|
72
|
+
readonly commerce: CommerceServiceImpl | null;
|
|
73
|
+
readonly catalog: CatalogService;
|
|
74
|
+
readonly accounts: AccountService;
|
|
75
|
+
constructor(options: BursarOptions);
|
|
76
|
+
/** Load the active catalog into the pricing engine. */
|
|
77
|
+
loadCatalog(): Promise<void>;
|
|
78
|
+
/**
|
|
79
|
+
* Ingest a normalized provider event through the facade-owned billing
|
|
80
|
+
* lifecycle. Providers must not depend on BillingService directly.
|
|
81
|
+
*/
|
|
82
|
+
ingestBillingEvent(event: BillingEvent): Promise<BillingEventResult>;
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=bursar.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bursar.d.ts","sourceRoot":"","sources":["../src/bursar.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,qBAAqB,EAC3B,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EACL,cAAc,IAAI,kBAAkB,EACpC,KAAK,qBAAqB,EAC3B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AACjF,OAAO,KAAK,EAAE,iBAAiB,IAAI,cAAc,EAAE,gBAAgB,EAAE,MAAM,wBAAw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BAAa,MAAO,YAAW,gBAAgB;IAC7C,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC;IACjC,QAAQ,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI,CAAC;IACxC,QAAQ,CAAC,QAAQ,EAAE,mBAAmB,GAAG,IAAI,CAAC;IAC9C,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC;IACjC,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;gBAEtB,OAAO,EAAE,aAAa;IA6BlC,uDAAuD;IACjD,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAIlC;;;OAGG;IACG,kBAAkB,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,kBAAkB,CAAC;CAK3E"}
|
package/dist/bursar.js
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { BillingService as BillingEventService, } from "./billing/billing-service.js";
|
|
2
|
+
import { CreditsService as CreditsServiceImpl, } from "./credits/service.js";
|
|
3
|
+
import { CommerceService as CommerceServiceImpl } from "./commerce/service.js";
|
|
4
|
+
import { CommerceNotConfiguredError } from "./commerce/errors.js";
|
|
5
|
+
import { loadConfigFromDict } from "./config.js";
|
|
6
|
+
import { ConfigError, PricingNotLoadedError } from "./errors.js";
|
|
7
|
+
import { projectPublicCatalog } from "./catalog.js";
|
|
8
|
+
import { retryBursarOperation } from "./retry.js";
|
|
9
|
+
/** Catalog operations. Configuration writes live here, never in BillingService. */
|
|
10
|
+
export class CatalogService {
|
|
11
|
+
credits;
|
|
12
|
+
constructor(credits) {
|
|
13
|
+
this.credits = credits;
|
|
14
|
+
}
|
|
15
|
+
get active() {
|
|
16
|
+
return this.credits.getActivePricing();
|
|
17
|
+
}
|
|
18
|
+
async getConfig() {
|
|
19
|
+
const active = await this.active;
|
|
20
|
+
if (!active)
|
|
21
|
+
throw new PricingNotLoadedError("No active Bursar catalog is available");
|
|
22
|
+
return loadConfigFromDict(active.config);
|
|
23
|
+
}
|
|
24
|
+
async publicView() {
|
|
25
|
+
return projectPublicCatalog(await this.getConfig());
|
|
26
|
+
}
|
|
27
|
+
publishDraft(config, label) {
|
|
28
|
+
return this.credits.publishPricingDraft(config, label);
|
|
29
|
+
}
|
|
30
|
+
activate(version, rollout) {
|
|
31
|
+
return this.credits.activatePricing(version, rollout);
|
|
32
|
+
}
|
|
33
|
+
publishAndActivate(config, label, rollout) {
|
|
34
|
+
return this.credits.publishPricing(config, label, rollout);
|
|
35
|
+
}
|
|
36
|
+
/** Pin or unpin one current assignment from automatic catalog rollout. */
|
|
37
|
+
setRevisionPin(userId, pinned) {
|
|
38
|
+
return this.credits.setPlanRevisionPin(userId, pinned);
|
|
39
|
+
}
|
|
40
|
+
/** Apply one bounded batch of renewal-effective plan changes. */
|
|
41
|
+
applyDueChanges(limit = 100) {
|
|
42
|
+
return this.credits.applyDuePlanChanges(limit);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/** Generic financial lifecycle operations for SaaS accounts. */
|
|
46
|
+
export class AccountService {
|
|
47
|
+
credits;
|
|
48
|
+
catalog;
|
|
49
|
+
constructor(credits, catalog) {
|
|
50
|
+
this.credits = credits;
|
|
51
|
+
this.catalog = catalog;
|
|
52
|
+
}
|
|
53
|
+
async onAccountCreated(input) {
|
|
54
|
+
if (!input.eventKey.trim())
|
|
55
|
+
throw new ConfigError("eventKey must not be empty");
|
|
56
|
+
const config = await retryBursarOperation(() => this.catalog.getConfig());
|
|
57
|
+
const fallback = Object.entries(config.plans).sort(([aKey, a], [bKey, b]) => a.rank - b.rank || aKey.localeCompare(bKey))[0]?.[0];
|
|
58
|
+
const planKey = config.catalog.defaultPlan ?? fallback;
|
|
59
|
+
if (!planKey)
|
|
60
|
+
throw new ConfigError("The active catalog has no default account plan");
|
|
61
|
+
const current = await retryBursarOperation(() => this.credits.getUserPlan(input.accountId));
|
|
62
|
+
const planAssigned = current.planKey == null;
|
|
63
|
+
if (planAssigned) {
|
|
64
|
+
await retryBursarOperation(() => this.credits.setUserPlan(input.accountId, planKey));
|
|
65
|
+
}
|
|
66
|
+
const grants = [];
|
|
67
|
+
for (const [programKey, program] of Object.entries(config.credits.grantPrograms).sort(([a], [b]) => a.localeCompare(b))) {
|
|
68
|
+
if (program.trigger !== "account_created")
|
|
69
|
+
continue;
|
|
70
|
+
grants.push(...(await retryBursarOperation(() => this.credits.executeGrantProgram({
|
|
71
|
+
trigger: "account_created",
|
|
72
|
+
programKey,
|
|
73
|
+
subjectId: input.accountId,
|
|
74
|
+
eventKey: input.eventKey,
|
|
75
|
+
region: input.region,
|
|
76
|
+
metadata: input.metadata,
|
|
77
|
+
}))));
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
accountId: input.accountId,
|
|
81
|
+
planKey: current.planKey ?? planKey,
|
|
82
|
+
planAssigned,
|
|
83
|
+
grants,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* The application-facing Bursar boundary.
|
|
89
|
+
*
|
|
90
|
+
* Credit and billing services are deliberately created together so consumers
|
|
91
|
+
* cannot accidentally construct unrelated services for the same account
|
|
92
|
+
* lifecycle. Provider and application integrations use this facade rather
|
|
93
|
+
* than constructing lifecycle services independently.
|
|
94
|
+
*/
|
|
95
|
+
export class Bursar {
|
|
96
|
+
credits;
|
|
97
|
+
billing;
|
|
98
|
+
commerce;
|
|
99
|
+
catalog;
|
|
100
|
+
accounts;
|
|
101
|
+
constructor(options) {
|
|
102
|
+
this.credits =
|
|
103
|
+
options.credits ??
|
|
104
|
+
new CreditsServiceImpl(options.creditStore, undefined, options.emitter ?? undefined, options.creditsOptions ?? undefined);
|
|
105
|
+
this.catalog = new CatalogService(this.credits);
|
|
106
|
+
this.accounts = new AccountService(this.credits, this.catalog);
|
|
107
|
+
this.billing = options.billingStore
|
|
108
|
+
? new BillingEventService(options.billingStore, {
|
|
109
|
+
...(options.billingOptions ?? {}),
|
|
110
|
+
provisioning: this.credits,
|
|
111
|
+
})
|
|
112
|
+
: null;
|
|
113
|
+
this.commerce =
|
|
114
|
+
this.billing && options.commerceOptions
|
|
115
|
+
? new CommerceServiceImpl(this.billing, this.credits, this, options.commerceOptions)
|
|
116
|
+
: null;
|
|
117
|
+
if (this.commerce) {
|
|
118
|
+
this.credits.addPostDeductionHook(async ({ userId }) => {
|
|
119
|
+
await this.commerce.autoRecharge.processIfNeeded({ accountId: userId });
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/** Load the active catalog into the pricing engine. */
|
|
124
|
+
async loadCatalog() {
|
|
125
|
+
await this.credits.loadPricingFromStore();
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Ingest a normalized provider event through the facade-owned billing
|
|
129
|
+
* lifecycle. Providers must not depend on BillingService directly.
|
|
130
|
+
*/
|
|
131
|
+
async ingestBillingEvent(event) {
|
|
132
|
+
if (!this.billing)
|
|
133
|
+
throw new CommerceNotConfiguredError("Bursar billing capability is not configured");
|
|
134
|
+
return this.billing.ingestBillingEvent(event);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=bursar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bursar.js","sourceRoot":"","sources":["../src/bursar.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,IAAI,mBAAmB,GAEtC,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EACL,cAAc,IAAI,kBAAkB,GAErC,MAAM,sBAAsB,CAAC;AAK9B,OAAO,EAAE,eAAe,IAAI,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC/E,OAAO,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAElE,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEjD,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,oBAAoB,EAAsB,MAAM,cAAc,CAAC;AAExE,OAAO,EAAE,oBAA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AAC,KAAK,CAAC,CAAC;IAChD,CAAC;CACF","sourcesContent":["import {\n BillingService as BillingEventService,\n type BillingServiceOptions,\n} from \"./billing/billing-service.js\";\nimport type { BillingStore } from \"./billing/billing-store.js\";\nimport {\n CreditsService as CreditsServiceImpl,\n type CreditsServiceOptions,\n} from \"./credits/service.js\";\nimport type { CreditStore } from \"./credits/store.js\";\nimport type { CreditEventEmitter } from \"./credits/events.js\";\nimport type { BillingEvent, BillingEventResult } from \"./billing/types/index.js\";\nimport type { BillingCapability as BillingService, BillingEventSink } from \"./billing/contracts.js\";\nimport { CommerceService as CommerceServiceImpl } from \"./commerce/service.js\";\nimport { CommerceNotConfiguredError } from \"./commerce/errors.js\";\nimport type { CommerceOptions } from \"./commerce/types.js\";\nimport { loadConfigFromDict } from \"./config.js\";\nimport type { CatalogRollout, ParsedBursarConfig } from \"./config/types.js\";\nimport { ConfigError, PricingNotLoadedError } from \"./errors.js\";\nimport { projectPublicCatalog, type PublicCatalog } from \"./catalog.js\";\nimport type { CreditMetadata, GrantProgramAwardResult } from \"./credits/types/index.js\";\nimport { retryBursarOperation } from \"./retry.js\";\nexport type { BillingCapability as BillingService, BillingEventSink } from \"./billing/contracts.js\";\nexport type { CommerceOptions } from \"./commerce/types.js\";\n\n/** Public credit capability. The implementation remains package-private. */\nexport type CreditsService = Pick<CreditsServiceImpl, keyof CreditsServiceImpl>;\n\n/** Options for constructing the single application-facing Bursar service. */\nexport interface BursarOptions {\n creditStore: CreditStore;\n billingStore?: BillingStore | null;\n credits?: CreditsService | null;\n creditsOptions?: CreditsServiceOptions | null;\n billingOptions?: BillingServiceOptions | null;\n commerceOptions?: CommerceOptions | null;\n emitter?: CreditEventEmitter | null;\n}\n\n/** Catalog operations. Configuration writes live here, never in BillingService. */\nexport class CatalogService {\n constructor(private readonly credits: CreditsService) {}\n\n get active() {\n return this.credits.getActivePricing();\n }\n\n async getConfig(): Promise<ParsedBursarConfig> {\n const active = await this.active;\n if (!active) throw new PricingNotLoadedError(\"No active Bursar catalog is available\");\n return loadConfigFromDict(active.config);\n }\n\n async publicView(): Promise<PublicCatalog> {\n return projectPublicCatalog(await this.getConfig());\n }\n\n publishDraft(config: Record<string, unknown>, label?: string | null): Promise<string> {\n return this.credits.publishPricingDraft(config, label);\n }\n\n activate(\n version: number,\n rollout?: CatalogRollout | Record<string, unknown> | null,\n ): Promise<string> {\n return this.credits.activatePricing(version, rollout);\n }\n\n publishAndActivate(\n config: Record<string, unknown>,\n label?: string | null,\n rollout?: CatalogRollout | Record<string, unknown> | null,\n ): Promise<void> {\n return this.credits.publishPricing(config, label, rollout);\n }\n\n /** Pin or unpin one current assignment from automatic catalog rollout. */\n setRevisionPin(userId: string, pinned: boolean): Promise<boolean> {\n return this.credits.setPlanRevisionPin(userId, pinned);\n }\n\n /** Apply one bounded batch of renewal-effective plan changes. */\n applyDueChanges(limit = 100): Promise<number> {\n return this.credits.applyDuePlanChanges(limit);\n }\n}\n\nexport interface AccountCreatedInput {\n accountId: string;\n eventKey: string;\n region?: string | null;\n metadata?: CreditMetadata | null;\n}\n\nexport interface AccountCreatedResult {\n accountId: string;\n planKey: string;\n planAssigned: boolean;\n grants: GrantProgramAwardResult[];\n}\n\n/** Generic financial lifecycle operations for SaaS accounts. */\nexport class AccountService {\n constructor(\n private readonly credits: CreditsService,\n private readonly catalog: CatalogService,\n ) {}\n\n async onAccountCreated(input: AccountCreatedInput): Promise<AccountCreatedResult> {\n if (!input.eventKey.trim()) throw new ConfigError(\"eventKey must not be empty\");\n const config = await retryBursarOperation(() => this.catalog.getConfig());\n const fallback = Object.entries(config.plans).sort(\n ([aKey, a], [bKey, b]) => a.rank - b.rank || aKey.localeCompare(bKey),\n )[0]?.[0];\n const planKey = config.catalog.defaultPlan ?? fallback;\n if (!planKey) throw new ConfigError(\"The active catalog has no default account plan\");\n\n const current = await retryBursarOperation(() => this.credits.getUserPlan(input.accountId));\n const planAssigned = current.planKey == null;\n if (planAssigned) {\n await retryBursarOperation(() => this.credits.setUserPlan(input.accountId, planKey));\n }\n\n const grants: GrantProgramAwardResult[] = [];\n for (const [programKey, program] of Object.entries(config.credits.grantPrograms).sort(\n ([a], [b]) => a.localeCompare(b),\n )) {\n if (program.trigger !== \"account_created\") continue;\n grants.push(\n ...(await retryBursarOperation(() =>\n this.credits.executeGrantProgram({\n trigger: \"account_created\",\n programKey,\n subjectId: input.accountId,\n eventKey: input.eventKey,\n region: input.region,\n metadata: input.metadata,\n }),\n )),\n );\n }\n return {\n accountId: input.accountId,\n planKey: current.planKey ?? planKey,\n planAssigned,\n grants,\n };\n }\n}\n\n/**\n * The application-facing Bursar boundary.\n *\n * Credit and billing services are deliberately created together so consumers\n * cannot accidentally construct unrelated services for the same account\n * lifecycle. Provider and application integrations use this facade rather\n * than constructing lifecycle services independently.\n */\nexport class Bursar implements BillingEventSink {\n readonly credits: CreditsService;\n readonly billing: BillingService | null;\n readonly commerce: CommerceServiceImpl | null;\n readonly catalog: CatalogService;\n readonly accounts: AccountService;\n\n constructor(options: BursarOptions) {\n this.credits =\n options.credits ??\n new CreditsServiceImpl(\n options.creditStore,\n undefined,\n options.emitter ?? undefined,\n options.creditsOptions ?? undefined,\n );\n this.catalog = new CatalogService(this.credits);\n this.accounts = new AccountService(this.credits, this.catalog);\n\n this.billing = options.billingStore\n ? new BillingEventService(options.billingStore, {\n ...(options.billingOptions ?? {}),\n provisioning: this.credits,\n })\n : null;\n this.commerce =\n this.billing && options.commerceOptions\n ? new CommerceServiceImpl(this.billing, this.credits, this, options.commerceOptions)\n : null;\n if (this.commerce) {\n this.credits.addPostDeductionHook(async ({ userId }) => {\n await this.commerce!.autoRecharge.processIfNeeded({ accountId: userId });\n });\n }\n }\n\n /** Load the active catalog into the pricing engine. */\n async loadCatalog(): Promise<void> {\n await this.credits.loadPricingFromStore();\n }\n\n /**\n * Ingest a normalized provider event through the facade-owned billing\n * lifecycle. Providers must not depend on BillingService directly.\n */\n async ingestBillingEvent(event: BillingEvent): Promise<BillingEventResult> {\n if (!this.billing)\n throw new CommerceNotConfiguredError(\"Bursar billing capability is not configured\");\n return this.billing.ingestBillingEvent(event);\n }\n}\n"]}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { CommerceOffer, FeatureValue, ParsedBursarConfig, Window } from "./config/types.js";
|
|
2
|
+
export interface PublicCatalogWindow {
|
|
3
|
+
type: Window["type"];
|
|
4
|
+
unit: string;
|
|
5
|
+
count: number;
|
|
6
|
+
timezone?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface PublicCatalogOffer {
|
|
9
|
+
key: string;
|
|
10
|
+
type: CommerceOffer["type"];
|
|
11
|
+
displayName: string;
|
|
12
|
+
description?: string;
|
|
13
|
+
sortOrder: number;
|
|
14
|
+
price: {
|
|
15
|
+
amountMinor: number;
|
|
16
|
+
currency: string;
|
|
17
|
+
taxBehavior: "inclusive" | "exclusive" | "unspecified";
|
|
18
|
+
};
|
|
19
|
+
billingInterval?: {
|
|
20
|
+
unit: string;
|
|
21
|
+
count: number;
|
|
22
|
+
};
|
|
23
|
+
creditsPerUnit?: string;
|
|
24
|
+
quantity?: {
|
|
25
|
+
minimum: number;
|
|
26
|
+
maximum: number;
|
|
27
|
+
default: number;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export interface PublicCatalogPlan {
|
|
31
|
+
key: string;
|
|
32
|
+
displayName: string;
|
|
33
|
+
description?: string;
|
|
34
|
+
rank: number;
|
|
35
|
+
features: Record<string, FeatureValue>;
|
|
36
|
+
allowance?: {
|
|
37
|
+
amount: string;
|
|
38
|
+
priority: number | null;
|
|
39
|
+
window: PublicCatalogWindow;
|
|
40
|
+
};
|
|
41
|
+
quotas: Record<string, {
|
|
42
|
+
operation: string;
|
|
43
|
+
measure: string;
|
|
44
|
+
limit: string;
|
|
45
|
+
window: PublicCatalogWindow;
|
|
46
|
+
enforcement: "block" | "allow";
|
|
47
|
+
}>;
|
|
48
|
+
offers: PublicCatalogOffer[];
|
|
49
|
+
}
|
|
50
|
+
export interface PublicCatalog {
|
|
51
|
+
version: 1;
|
|
52
|
+
defaultPlan: string | null;
|
|
53
|
+
creditDisplay: {
|
|
54
|
+
currency: string;
|
|
55
|
+
unitsPerMajor: string;
|
|
56
|
+
} | null;
|
|
57
|
+
plans: PublicCatalogPlan[];
|
|
58
|
+
topups: PublicCatalogOffer[];
|
|
59
|
+
}
|
|
60
|
+
/** Produce a provider-secret-free, JSON-safe catalog for product surfaces. */
|
|
61
|
+
export declare function projectPublicCatalog(config: ParsedBursarConfig): PublicCatalog;
|
|
62
|
+
//# sourceMappingURL=catalog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../src/catalog.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEjG,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,kBAAkB;IACjC,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE;QACL,WAAW,EAAE,MAAM,CAAC;QACpB,QAAQ,EAAE,MAAM,CAAC;QACjB,WAAW,EAAE,WAAW,GAAG,WAAW,GAAG,aAAa,CAAC;KACxD,CAAC;IACF,eAAe,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAClD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,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window.type,
|
|
5
|
+
unit: window.unit,
|
|
6
|
+
count: window.count,
|
|
7
|
+
timezone: window.timezone,
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
if (window.type === "plan_assignment") {
|
|
11
|
+
return {
|
|
12
|
+
type: window.type,
|
|
13
|
+
unit: window.interval.unit,
|
|
14
|
+
count: window.interval.count,
|
|
15
|
+
timezone: window.timezone,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
type: window.type,
|
|
20
|
+
unit: window.duration.unit,
|
|
21
|
+
count: window.duration.count,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function publicOffer(key, offer) {
|
|
25
|
+
return {
|
|
26
|
+
key,
|
|
27
|
+
type: offer.type,
|
|
28
|
+
displayName: offer.displayName,
|
|
29
|
+
...(offer.description ? { description: offer.description } : {}),
|
|
30
|
+
sortOrder: offer.sortOrder,
|
|
31
|
+
price: { ...offer.price },
|
|
32
|
+
...(offer.type === "subscription"
|
|
33
|
+
? {
|
|
34
|
+
billingInterval: {
|
|
35
|
+
unit: offer.billingInterval.unit,
|
|
36
|
+
count: offer.billingInterval.count,
|
|
37
|
+
},
|
|
38
|
+
}
|
|
39
|
+
: {
|
|
40
|
+
creditsPerUnit: offer.creditsPerUnit.toString(),
|
|
41
|
+
quantity: { ...offer.quantity },
|
|
42
|
+
}),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/** Produce a provider-secret-free, JSON-safe catalog for product surfaces. */
|
|
46
|
+
export function projectPublicCatalog(config) {
|
|
47
|
+
const offers = Object.entries(config.commerce.offers);
|
|
48
|
+
const plans = Object.entries(config.plans)
|
|
49
|
+
.map(([key, plan]) => ({
|
|
50
|
+
key,
|
|
51
|
+
displayName: plan.displayName,
|
|
52
|
+
...(plan.description ? { description: plan.description } : {}),
|
|
53
|
+
rank: plan.rank,
|
|
54
|
+
features: { ...plan.features },
|
|
55
|
+
...(plan.creditAllowance
|
|
56
|
+
? {
|
|
57
|
+
allowance: {
|
|
58
|
+
amount: plan.creditAllowance.amount.toString(),
|
|
59
|
+
priority: plan.creditAllowance.priority ?? null,
|
|
60
|
+
window: publicWindow(plan.creditAllowance.window),
|
|
61
|
+
},
|
|
62
|
+
}
|
|
63
|
+
: {}),
|
|
64
|
+
quotas: Object.fromEntries(Object.entries(plan.quotas).map(([quotaKey, quota]) => [
|
|
65
|
+
quotaKey,
|
|
66
|
+
{
|
|
67
|
+
operation: quota.operation,
|
|
68
|
+
measure: quota.measure,
|
|
69
|
+
limit: quota.limit.toString(),
|
|
70
|
+
window: publicWindow(quota.window),
|
|
71
|
+
enforcement: quota.enforcement,
|
|
72
|
+
},
|
|
73
|
+
])),
|
|
74
|
+
offers: offers
|
|
75
|
+
.filter((entry) => entry[1].type === "subscription" && entry[1].plan === key)
|
|
76
|
+
.map(([offerKey, offer]) => publicOffer(offerKey, offer))
|
|
77
|
+
.sort((a, b) => a.sortOrder - b.sortOrder || a.key.localeCompare(b.key)),
|
|
78
|
+
}))
|
|
79
|
+
.sort((a, b) => a.rank - b.rank || a.key.localeCompare(b.key));
|
|
80
|
+
return {
|
|
81
|
+
version: 1,
|
|
82
|
+
defaultPlan: config.catalog.defaultPlan ?? plans[0]?.key ?? null,
|
|
83
|
+
creditDisplay: config.credits.display
|
|
84
|
+
? {
|
|
85
|
+
currency: config.credits.display.currency,
|
|
86
|
+
unitsPerMajor: config.credits.display.unitsPerMajor.toString(),
|
|
87
|
+
}
|
|
88
|
+
: null,
|
|
89
|
+
plans,
|
|
90
|
+
topups: offers
|
|
91
|
+
.filter((entry) => entry[1].type === "topup")
|
|
92
|
+
.map(([key, offer]) => publicOffer(key, offer))
|
|
93
|
+
.sort((a, b) => a.sortOrder - b.sortOrder || a.key.localeCompare(b.key)),
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=catalog.js.map
|