@zonastery/bursar 0.0.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +85 -344
- 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 +59 -0
- package/dist/billing/billing-store.d.ts.map +1 -0
- package/dist/billing/billing-store.js +9 -0
- package/dist/billing/billing-store.js.map +1 -0
- 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 +667 -0
- package/dist/billing/event-handlers.js.map +1 -0
- package/dist/billing/event-processor.d.ts +19 -0
- package/dist/billing/event-processor.d.ts.map +1 -0
- package/dist/billing/event-processor.js +105 -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 +10 -0
- package/dist/billing/index.d.ts.map +1 -0
- package/dist/billing/index.js +6 -0
- package/dist/billing/index.js.map +1 -0
- 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 +178 -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 +47 -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 +87 -0
- package/dist/billing/postgres/store.d.ts.map +1 -0
- package/dist/billing/postgres/store.js +527 -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 +80 -0
- package/dist/bursar.d.ts.map +1 -0
- package/dist/bursar.js +129 -0
- package/dist/bursar.js.map +1 -0
- package/dist/catalog.d.ts +61 -0
- package/dist/catalog.d.ts.map +1 -0
- package/dist/catalog.js +95 -0
- package/dist/catalog.js.map +1 -0
- package/dist/commerce/errors.d.ts +69 -0
- package/dist/commerce/errors.d.ts.map +1 -0
- package/dist/commerce/errors.js +107 -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 +981 -0
- package/dist/commerce/service.js.map +1 -0
- package/dist/commerce/types.d.ts +217 -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 +126 -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 +327 -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 +6 -22
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +82 -263
- 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 +77 -0
- package/dist/credits/postgres/repositories/analytics.d.ts.map +1 -0
- package/dist/credits/postgres/repositories/analytics.js +151 -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 +55 -0
- package/dist/credits/postgres/repositories/deduction.d.ts.map +1 -0
- package/dist/credits/postgres/repositories/deduction.js +130 -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 +105 -0
- package/dist/credits/postgres/repositories/plan.d.ts.map +1 -0
- package/dist/credits/postgres/repositories/plan.js +182 -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 +70 -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 +84 -0
- package/dist/credits/postgres/store.d.ts.map +1 -0
- package/dist/credits/postgres/store.js +765 -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 +98 -0
- package/dist/credits/postgres/value-mappers.js.map +1 -0
- package/dist/credits/pricing-runtime.d.ts +34 -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 +207 -0
- package/dist/credits/service.d.ts.map +1 -0
- package/dist/credits/service.js +594 -0
- package/dist/credits/service.js.map +1 -0
- package/dist/{stores/credit-store.d.ts → credits/store.d.ts} +67 -71
- package/dist/credits/store.d.ts.map +1 -0
- package/dist/{stores/credit-store.js → credits/store.js} +30 -6
- 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 +69 -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 +77 -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 +84 -25
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +117 -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 +2764 -0
- package/dist/generated/pricing-config.types.d.ts +674 -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 +21 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -9
- package/dist/index.js.map +1 -1
- package/dist/load-pricing-file.d.ts.map +1 -1
- package/dist/load-pricing-file.js +61 -6
- 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/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 +25 -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 +6 -0
- package/dist/providers/dodo/event-mapper.d.ts.map +1 -0
- package/dist/providers/dodo/event-mapper.js +344 -0
- package/dist/providers/dodo/event-mapper.js.map +1 -0
- package/dist/providers/dodo/index.d.ts +4 -0
- package/dist/providers/dodo/index.d.ts.map +1 -0
- package/dist/providers/dodo/index.js +3 -0
- package/dist/providers/dodo/index.js.map +1 -0
- package/dist/providers/dodo/provider.d.ts +53 -0
- package/dist/providers/dodo/provider.d.ts.map +1 -0
- package/dist/providers/dodo/provider.js +353 -0
- package/dist/providers/dodo/provider.js.map +1 -0
- package/dist/providers/index.d.ts +9 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +7 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/mock/index.d.ts +2 -0
- package/dist/providers/mock/index.d.ts.map +1 -0
- package/dist/providers/mock/index.js +2 -0
- package/dist/providers/mock/index.js.map +1 -0
- package/dist/providers/mock/provider.d.ts +41 -0
- package/dist/providers/mock/provider.d.ts.map +1 -0
- package/dist/providers/mock/provider.js +124 -0
- package/dist/providers/mock/provider.js.map +1 -0
- package/dist/providers/stripe/event-mapper.d.ts +7 -0
- package/dist/providers/stripe/event-mapper.d.ts.map +1 -0
- package/dist/providers/stripe/event-mapper.js +342 -0
- package/dist/providers/stripe/event-mapper.js.map +1 -0
- package/dist/providers/stripe/index.d.ts +3 -0
- package/dist/providers/stripe/index.d.ts.map +1 -0
- package/dist/providers/stripe/index.js +3 -0
- package/dist/providers/stripe/index.js.map +1 -0
- package/dist/providers/stripe/provider.d.ts +48 -0
- package/dist/providers/stripe/provider.d.ts.map +1 -0
- package/dist/providers/stripe/provider.js +289 -0
- package/dist/providers/stripe/provider.js.map +1 -0
- package/dist/providers/types.d.ts +175 -0
- package/dist/providers/types.d.ts.map +1 -0
- package/dist/providers/types.js +18 -0
- package/dist/providers/types.js.map +1 -0
- package/dist/retry.d.ts +13 -0
- package/dist/retry.d.ts.map +1 -0
- package/dist/retry.js +28 -0
- package/dist/retry.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 +51 -0
- package/dist/shared/postgres-client.d.ts.map +1 -0
- package/dist/shared/postgres-client.js +101 -0
- package/dist/shared/postgres-client.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 +329 -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 +40 -0
- package/dist/storage/outbox-worker.d.ts.map +1 -0
- package/dist/storage/outbox-worker.js +132 -0
- package/dist/storage/outbox-worker.js.map +1 -0
- package/dist/storage/ports.d.ts +77 -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 +130 -0
- package/dist/storage/postgres-repository.js.map +1 -0
- package/dist/storage/runtime.d.ts +67 -0
- package/dist/storage/runtime.d.ts.map +1 -0
- package/dist/storage/runtime.js +313 -0
- package/dist/storage/runtime.js.map +1 -0
- package/package.json +70 -12
- 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/manager.d.ts +0 -421
- package/dist/manager.d.ts.map +0 -1
- package/dist/manager.js +0 -1112
- package/dist/manager.js.map +0 -1
- 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 -178
- package/dist/stores/memory-store.d.ts.map +0 -1
- package/dist/stores/memory-store.js +0 -1833
- package/dist/stores/memory-store.js.map +0 -1
- package/dist/stores/postgres-store.d.ts +0 -95
- package/dist/stores/postgres-store.d.ts.map +0 -1
- package/dist/stores/postgres-store.js +0 -872
- package/dist/stores/postgres-store.js.map +0 -1
- package/dist/stores/supabase-store.d.ts +0 -76
- package/dist/stores/supabase-store.d.ts.map +0 -1
- package/dist/stores/supabase-store.js +0 -865
- package/dist/stores/supabase-store.js.map +0 -1
- package/dist/types.d.ts +0 -462
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
- /package/dist/{types.js → commerce/types.js} +0 -0
package/dist/config.js
CHANGED
|
@@ -1,278 +1,97 @@
|
|
|
1
|
+
import Ajv2020, {} from "ajv/dist/2020.js";
|
|
2
|
+
import addFormats from "ajv-formats";
|
|
1
3
|
import Decimal from "decimal.js";
|
|
4
|
+
import schema from "./generated/pricing-config.schema.json" with { type: "json" };
|
|
2
5
|
import { ConfigError } from "./errors.js";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
* exactly. Expressions may only reference these names (or allowed functions).
|
|
22
|
-
* Passed into `validateExpression` so typos like `inputtokens` fail at
|
|
23
|
-
* config-load, not at first runtime use (M5).
|
|
24
|
-
*/
|
|
25
|
-
export const KNOWN_VARIABLES = new Set([
|
|
26
|
-
"input_tokens",
|
|
27
|
-
"output_tokens",
|
|
28
|
-
"cache_read_tokens",
|
|
29
|
-
"cache_write_tokens",
|
|
30
|
-
"tool_calls",
|
|
31
|
-
"search_queries",
|
|
32
|
-
"search_results",
|
|
33
|
-
"web_search_calls",
|
|
34
|
-
"code_exec_calls",
|
|
35
|
-
]);
|
|
36
|
-
/** Variable set for validating `tools` expressions: base set + `this_tool_calls` (WS2). */
|
|
37
|
-
const TOOLS_VARIABLES = new Set([...KNOWN_VARIABLES, "this_tool_calls"]);
|
|
38
|
-
function validateExpressions(raw) {
|
|
39
|
-
for (const [key, expr] of Object.entries(raw.models)) {
|
|
40
|
-
try {
|
|
41
|
-
validateExpression(expr, KNOWN_VARIABLES);
|
|
42
|
-
}
|
|
43
|
-
catch (e) {
|
|
44
|
-
throw new ConfigError(`invalid expression in models.${key}: ${e.message}`);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
for (const [key, expr] of Object.entries(raw.tools)) {
|
|
48
|
-
try {
|
|
49
|
-
validateExpression(expr, TOOLS_VARIABLES);
|
|
50
|
-
}
|
|
51
|
-
catch (e) {
|
|
52
|
-
throw new ConfigError(`invalid expression in tools.${key}: ${e.message}`);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
if (raw.search) {
|
|
56
|
-
try {
|
|
57
|
-
validateExpression(raw.search, KNOWN_VARIABLES);
|
|
58
|
-
}
|
|
59
|
-
catch (e) {
|
|
60
|
-
throw new ConfigError(`invalid expression in search: ${e.message}`);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
if (raw.cache) {
|
|
64
|
-
try {
|
|
65
|
-
validateExpression(raw.cache, KNOWN_VARIABLES);
|
|
66
|
-
}
|
|
67
|
-
catch (e) {
|
|
68
|
-
throw new ConfigError(`invalid expression in cache: ${e.message}`);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* H6 fix: normalise snake_case keys to camelCase before consumption.
|
|
74
|
-
*
|
|
75
|
-
* The documented config format is snake_case (min_balance, free_allowance,
|
|
76
|
-
* rate_overrides, billing_mode, overdraft_floor). JS previously only read
|
|
77
|
-
* camelCase, silently dropping these fields and falling back to defaults.
|
|
78
|
-
*/
|
|
79
|
-
function normaliseKeys(data) {
|
|
80
|
-
const keyMap = {
|
|
81
|
-
min_balance: "minBalance",
|
|
82
|
-
free_allowance: "freeAllowance",
|
|
83
|
-
rate_overrides: "rateOverrides",
|
|
84
|
-
billing_mode: "billingMode",
|
|
85
|
-
overdraft_floor: "overdraftFloor",
|
|
86
|
-
default_billing_mode: "defaultBillingMode",
|
|
87
|
-
per_operation: "perOperation",
|
|
88
|
-
max_concurrent: "maxConcurrent",
|
|
89
|
-
signup_bonus: "signupBonus",
|
|
90
|
-
allowance_period: "allowancePeriod",
|
|
91
|
-
default_ttl_days: "defaultTtlDays",
|
|
92
|
-
allow_overdraft: "allowOverdraft",
|
|
93
|
-
is_default: "isDefault",
|
|
94
|
-
feature_limits: "featureLimits",
|
|
95
|
-
max_calls: "maxCalls",
|
|
96
|
-
};
|
|
97
|
-
const out = {};
|
|
98
|
-
for (const [k, v] of Object.entries(data)) {
|
|
99
|
-
const mapped = keyMap[k] ?? k;
|
|
100
|
-
out[mapped] = v;
|
|
101
|
-
}
|
|
102
|
-
return out;
|
|
6
|
+
import { parseAdmission, parseEntitlements } from "./config/parse-access.js";
|
|
7
|
+
import { parseCommerce } from "./config/parse-commerce.js";
|
|
8
|
+
import { parseCredits } from "./config/parse-credits.js";
|
|
9
|
+
import { parsePlans } from "./config/parse-plans.js";
|
|
10
|
+
import { parsePricing } from "./config/parse-pricing.js";
|
|
11
|
+
import { asObject, semanticError } from "./config/parse-utils.js";
|
|
12
|
+
const ajv = new Ajv2020({
|
|
13
|
+
allErrors: true,
|
|
14
|
+
strict: false,
|
|
15
|
+
});
|
|
16
|
+
addFormats(ajv, { mode: "full" });
|
|
17
|
+
const validateStructure = ajv.compile(schema);
|
|
18
|
+
function formatAjvErrors(errors) {
|
|
19
|
+
if (!errors?.length)
|
|
20
|
+
return "configuration does not match the Bursar schema";
|
|
21
|
+
return errors
|
|
22
|
+
.map((error) => `${error.instancePath || "$"} ${error.message ?? error.keyword}`)
|
|
23
|
+
.join("; ");
|
|
103
24
|
}
|
|
104
|
-
/** Recursively normalise a plan definition object. */
|
|
105
|
-
function normalisePlan(p) {
|
|
106
|
-
return normaliseKeys(p);
|
|
107
|
-
}
|
|
108
|
-
/** Recursively normalise a tier definition object (credit tiers). */
|
|
109
|
-
function normaliseTier(t) {
|
|
110
|
-
return normaliseKeys(t);
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Normalise + validate a plan's `featureLimits` map (per-feature
|
|
114
|
-
* invocation-count limits, mirrors `per_operation`/`OperationPolicy`
|
|
115
|
-
* handling). Each entry's own keys are snake/camel-normalised (`max_calls`
|
|
116
|
-
* -> `maxCalls`) since, unlike top-level plan fields, these nested objects
|
|
117
|
-
* are not otherwise touched by `normaliseKeys`.
|
|
118
|
-
*/
|
|
119
|
-
function normaliseFeatureLimits(planKey, raw) {
|
|
120
|
-
const out = {};
|
|
121
|
-
for (const [featureKey, rawLimit] of Object.entries(raw)) {
|
|
122
|
-
const limit = normaliseKeys((rawLimit ?? {}));
|
|
123
|
-
const maxCalls = Number(limit.maxCalls ?? 0);
|
|
124
|
-
const period = limit.period ?? "monthly";
|
|
125
|
-
const action = limit.action ?? "deny";
|
|
126
|
-
if (!Number.isFinite(maxCalls) || maxCalls < 0) {
|
|
127
|
-
throw new ConfigError(`invalid featureLimits in plans.${planKey}.${featureKey}: maxCalls must be >= 0, got ${String(limit.maxCalls)}`);
|
|
128
|
-
}
|
|
129
|
-
if (!FEATURE_LIMIT_PERIODS.has(period)) {
|
|
130
|
-
throw new ConfigError(`invalid featureLimits in plans.${planKey}.${featureKey}: unknown period '${period}' ` +
|
|
131
|
-
`(expected one of ${[...FEATURE_LIMIT_PERIODS].sort().join(", ")})`);
|
|
132
|
-
}
|
|
133
|
-
if (!FEATURE_LIMIT_ACTIONS.has(action)) {
|
|
134
|
-
throw new ConfigError(`invalid featureLimits in plans.${planKey}.${featureKey}: unknown action '${action}' ` +
|
|
135
|
-
`(expected one of ${[...FEATURE_LIMIT_ACTIONS].sort().join(", ")})`);
|
|
136
|
-
}
|
|
137
|
-
out[featureKey] = {
|
|
138
|
-
maxCalls,
|
|
139
|
-
period: period,
|
|
140
|
-
action: action,
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
return out;
|
|
144
|
-
}
|
|
145
|
-
/** Load and validate a pricing config from a raw dictionary. */
|
|
146
25
|
export function loadConfigFromDict(data) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
if (d.models == null)
|
|
150
|
-
throw new ConfigError("missing required section: models");
|
|
151
|
-
if (typeof d.models !== "object" || Object.keys(d.models).length === 0) {
|
|
152
|
-
throw new ConfigError("models must be a non-empty dict");
|
|
26
|
+
if (!validateStructure(data)) {
|
|
27
|
+
throw new ConfigError(formatAjvErrors(validateStructure.errors), validateStructure.errors ?? []);
|
|
153
28
|
}
|
|
154
|
-
|
|
155
|
-
const
|
|
156
|
-
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
for (const [modelKey, expr] of Object.entries(overrides)) {
|
|
165
|
-
try {
|
|
166
|
-
validateExpression(expr, KNOWN_VARIABLES);
|
|
167
|
-
}
|
|
168
|
-
catch (e) {
|
|
169
|
-
throw new ConfigError(`invalid expression in plans.${planKey}.rateOverrides.${modelKey}: ${e.message}`);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
// WS9b: allowancePeriod must be one of the three valid strings if present.
|
|
174
|
-
if (plan.allowancePeriod != null && !ALLOWANCE_PERIODS.has(plan.allowancePeriod)) {
|
|
175
|
-
throw new ConfigError(`invalid allowancePeriod in plans.${planKey}: ${String(plan.allowancePeriod)} ` +
|
|
176
|
-
`(expected one of ${[...ALLOWANCE_PERIODS].sort().join(", ")})`);
|
|
29
|
+
const raw = data;
|
|
30
|
+
const pricing = raw.pricing == null ? undefined : parsePricing(raw.pricing);
|
|
31
|
+
const credits = parseCredits(raw.credits);
|
|
32
|
+
const entitlements = parseEntitlements(raw.entitlements);
|
|
33
|
+
const admission = parseAdmission(raw.admission);
|
|
34
|
+
if (pricing != null) {
|
|
35
|
+
for (const [policyKey, policy] of Object.entries(admission.policies)) {
|
|
36
|
+
const unknown = Object.keys(policy.operations).filter((operation) => !pricing.operations[operation]);
|
|
37
|
+
if (unknown.length) {
|
|
38
|
+
semanticError(`admission policy '${policyKey}' references unknown operations ${unknown.join(", ")}`);
|
|
177
39
|
}
|
|
178
|
-
// Per-feature invocation-count limits: normalise nested keys + validate.
|
|
179
|
-
if (plan.featureLimits != null) {
|
|
180
|
-
if (typeof plan.featureLimits !== "object" || Array.isArray(plan.featureLimits)) {
|
|
181
|
-
throw new ConfigError(`plans.${planKey}.featureLimits must be a dict`);
|
|
182
|
-
}
|
|
183
|
-
plan.featureLimits = normaliseFeatureLimits(planKey, plan.featureLimits);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
const planNames = Object.values(plans).map((p) => p.name);
|
|
187
|
-
if (new Set(planNames).size !== planNames.length) {
|
|
188
|
-
throw new ConfigError("duplicate plan names in pricing config");
|
|
189
40
|
}
|
|
190
41
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
throw new ConfigError("tiers must not be an empty object; omit the `tiers` key entirely for no tiers");
|
|
42
|
+
const commerce = parseCommerce(raw.commerce, credits);
|
|
43
|
+
const subscriptionPlans = new Set(Object.values(commerce.offers)
|
|
44
|
+
.filter((offer) => offer.type === "subscription")
|
|
45
|
+
.map((offer) => offer.plan));
|
|
46
|
+
const plans = parsePlans(raw.plans, pricing, credits, entitlements, admission, subscriptionPlans);
|
|
47
|
+
for (const [offerKey, offer] of Object.entries(commerce.offers)) {
|
|
48
|
+
if (offer.type === "subscription" && !plans[offer.plan]) {
|
|
49
|
+
semanticError(`commerce.offers.${offerKey}.plan references unknown plan '${offer.plan}'`);
|
|
200
50
|
}
|
|
201
51
|
}
|
|
202
|
-
const
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
if (tiers) {
|
|
207
|
-
let overdraftCount = 0;
|
|
208
|
-
let defaultCount = 0;
|
|
209
|
-
for (const [tierKey, t] of Object.entries(tiers)) {
|
|
210
|
-
if (t.allowOverdraft === true)
|
|
211
|
-
overdraftCount++;
|
|
212
|
-
if (t.isDefault === true)
|
|
213
|
-
defaultCount++;
|
|
214
|
-
if (t.defaultTtlDays != null && t.defaultTtlDays <= 0) {
|
|
215
|
-
throw new ConfigError(`tiers.${tierKey}.defaultTtlDays must be > 0, got ${String(t.defaultTtlDays)}`);
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
if (overdraftCount > 1) {
|
|
219
|
-
throw new ConfigError("at most one tier may set allowOverdraft: true");
|
|
220
|
-
}
|
|
221
|
-
if (defaultCount > 1) {
|
|
222
|
-
throw new ConfigError("at most one tier may set isDefault: true");
|
|
52
|
+
for (const [programKey, program] of Object.entries(credits.grantPrograms)) {
|
|
53
|
+
const unknown = program.eligibility.plans.filter((plan) => !plans[plan]);
|
|
54
|
+
if (unknown.length) {
|
|
55
|
+
semanticError(`grant program '${programKey}' references unknown plans ${unknown.join(", ")}`);
|
|
223
56
|
}
|
|
224
57
|
}
|
|
225
|
-
const
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
cache: d.cache ?? null,
|
|
230
|
-
minBalance: d.minBalance ?? 0,
|
|
231
|
-
signupBonus: d.signupBonus,
|
|
232
|
-
fixed: d.fixed ?? {},
|
|
233
|
-
};
|
|
234
|
-
if (config.minBalance < 0)
|
|
235
|
-
throw new ConfigError("min_balance must be >= 0");
|
|
236
|
-
// WS3: fixed job costs may be fractional (Decimal-compatible) — only non-negative
|
|
237
|
-
// is enforced. Was: Number.isInteger check (contradicted docs).
|
|
238
|
-
for (const [job, cost] of Object.entries(config.fixed)) {
|
|
239
|
-
if (cost < 0) {
|
|
240
|
-
throw new ConfigError(`fixed.${job} must be non-negative, got ${cost}`);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
if (plans) {
|
|
244
|
-
const planDefs = {};
|
|
245
|
-
for (const [key, p] of Object.entries(plans)) {
|
|
246
|
-
planDefs[key] = {
|
|
247
|
-
id: p.id ?? key,
|
|
248
|
-
name: p.name,
|
|
249
|
-
freeAllowance: new Decimal(p.freeAllowance ?? 0),
|
|
250
|
-
rateOverrides: p.rateOverrides ?? null,
|
|
251
|
-
features: p.features ?? null,
|
|
252
|
-
featureLimits: p.featureLimits ?? null,
|
|
253
|
-
defaultBillingMode: (p.defaultBillingMode ?? p.billingMode) ?? "strict",
|
|
254
|
-
overdraftFloor: p.overdraftFloor != null ? new Decimal(p.overdraftFloor) : null,
|
|
255
|
-
maxConcurrent: p.maxConcurrent ?? null,
|
|
256
|
-
allowancePeriod: (p.allowancePeriod ?? "calendar_month"),
|
|
257
|
-
};
|
|
258
|
-
}
|
|
259
|
-
config.plans = planDefs;
|
|
260
|
-
}
|
|
261
|
-
if (tiers) {
|
|
262
|
-
const tierDefs = {};
|
|
263
|
-
for (const [key, t] of Object.entries(tiers)) {
|
|
264
|
-
tierDefs[key] = {
|
|
265
|
-
name: t.name ?? key,
|
|
266
|
-
priority: Number(t.priority ?? 0),
|
|
267
|
-
expires: Boolean(t.expires ?? false),
|
|
268
|
-
defaultTtlDays: t.defaultTtlDays != null ? Number(t.defaultTtlDays) : null,
|
|
269
|
-
allowOverdraft: Boolean(t.allowOverdraft ?? false),
|
|
270
|
-
isDefault: Boolean(t.isDefault ?? false),
|
|
271
|
-
};
|
|
272
|
-
}
|
|
273
|
-
config.tiers = tierDefs;
|
|
58
|
+
const catalogRaw = asObject(raw.catalog ?? {});
|
|
59
|
+
const defaultPlan = catalogRaw.default_plan == null ? undefined : String(catalogRaw.default_plan);
|
|
60
|
+
if (defaultPlan != null && !plans[defaultPlan]) {
|
|
61
|
+
semanticError(`catalog.default_plan references unknown plan '${defaultPlan}'`);
|
|
274
62
|
}
|
|
275
|
-
|
|
276
|
-
|
|
63
|
+
return {
|
|
64
|
+
version: 1,
|
|
65
|
+
catalog: {
|
|
66
|
+
...(defaultPlan == null ? {} : { defaultPlan }),
|
|
67
|
+
},
|
|
68
|
+
...(pricing == null ? {} : { pricing }),
|
|
69
|
+
credits,
|
|
70
|
+
entitlements,
|
|
71
|
+
admission,
|
|
72
|
+
plans,
|
|
73
|
+
commerce,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function toSnakeCase(value) {
|
|
77
|
+
if (value instanceof Decimal)
|
|
78
|
+
return value.toFixed(6);
|
|
79
|
+
if (Array.isArray(value))
|
|
80
|
+
return value.map(toSnakeCase);
|
|
81
|
+
if (typeof value !== "object" || value === null)
|
|
82
|
+
return value;
|
|
83
|
+
return Object.fromEntries(Object.entries(value)
|
|
84
|
+
.filter(([, child]) => child !== undefined)
|
|
85
|
+
.map(([key, child]) => [
|
|
86
|
+
key.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`),
|
|
87
|
+
toSnakeCase(child),
|
|
88
|
+
]));
|
|
89
|
+
}
|
|
90
|
+
export function canonicalBursarConfigDict(data) {
|
|
91
|
+
return toSnakeCase(loadConfigFromDict(data));
|
|
92
|
+
}
|
|
93
|
+
/** Serialize an already parsed configuration without re-validating camelCase fields as raw input. */
|
|
94
|
+
export function canonicalParsedBursarConfigDict(data) {
|
|
95
|
+
return toSnakeCase(data);
|
|
277
96
|
}
|
|
278
97
|
//# sourceMappingURL=config.js.map
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,EAAE,EAAoB,MAAM,kBAAkB,CAAC;AAC7D,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,OAAO,MAAM,YAAY,CAAC;AAEjC,OAAO,MAAM,MAAM,wCAAwC,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAClF,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAmB,MAAM,yBAAyB,CAAC;AAKnF,MAAM,GAAG,GAAG,IAAI,OAAO,CAAC;IACtB,SAAS,EAAE,IAAI;IACf,MAAM,EAAE,KAAK;CACd,CAAC,CAAC;AACH,UAAU,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;AAClC,MAAM,iBAAiB,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;AAE9C,SAAS,eAAe,CAAC,MAAwC;IAC/D,IAAI,CAAC,MAAM,EAAE,MAAM;QAAE,OAAO,gDAAgD,CAAC;IAC7E,OAAO,MAAM;SACV,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,GAAG,KAAK,CAAC,YAAY,IAAI,GAAG,IAAI,KAAK,CAAC,OAAO,IAAI,KAAK,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AE,EAAE,CAAC,IAAI,MAAM,CAAC,WAAW,EAAE,EAAE,CAAC;QAC7D,WAAW,CAAC,KAAK,CAAC;KACnB,CAAC,CACL,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,yBAAyB,CACvC,IAAgD;IAEhD,OAAO,WAAW,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAA+C,CAAC;AAC7F,CAAC;AAED,qGAAqG;AACrG,MAAM,UAAU,+BAA+B,CAC7C,IAAwB;IAExB,OAAO,WAAW,CAAC,IAAI,CAA+C,CAAC;AACzE,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Typed event emitter for credit lifecycle events.
|
|
3
3
|
*
|
|
4
|
-
* Events are emitted by ``
|
|
5
|
-
* The emitter is optional — inject into ``
|
|
4
|
+
* Events are emitted by ``CreditsService`` after each store operation.
|
|
5
|
+
* The emitter is optional — inject into ``CreditsService`` constructor,
|
|
6
6
|
* no-op if omitted.
|
|
7
7
|
*
|
|
8
8
|
* @example
|
|
@@ -11,19 +11,19 @@
|
|
|
11
11
|
* emitter.on("credits.deducted", (event) => {
|
|
12
12
|
* console.log(`Deducted ${event.data?.amount} from ${event.userId}`);
|
|
13
13
|
* });
|
|
14
|
-
* const manager = new
|
|
14
|
+
* const manager = new CreditsService(store, engine, emitter);
|
|
15
15
|
* ```
|
|
16
16
|
*/
|
|
17
17
|
/**
|
|
18
18
|
* All credit lifecycle event types.
|
|
19
19
|
*
|
|
20
20
|
* Success events (``credits.deducted``/``credits.refunded``/…) are emitted by
|
|
21
|
-
* ``
|
|
21
|
+
* ``CreditsService`` only after the underlying store operation committed without
|
|
22
22
|
* an ``error`` (contract §6). Failure events (``credits.deduct_failed`` /
|
|
23
23
|
* ``credits.refund_failed``) carry the store's business-error code in
|
|
24
24
|
* ``data.error`` for observability/fraud monitoring.
|
|
25
25
|
*/
|
|
26
|
-
export type CreditEventType = "credits.deducted" | "credits.deduct_failed" | "credits.added" | "credits.refunded" | "credits.refund_failed" | "credits.expired" | "credits.
|
|
26
|
+
export type CreditEventType = "credits.deducted" | "credits.deduct_failed" | "credits.added" | "credits.refunded" | "credits.refund_failed" | "credits.expired" | "credits.low_balance" | "credits.plan_changed" | "credits.reserved" | "credits.reservation_released" | "credits.lease_expired" | "credits.overdraft" | "credits.cycle_renewed" | "credits.quota_blocked" | "credits.quota_threshold";
|
|
27
27
|
/**
|
|
28
28
|
* A typed credit lifecycle event.
|
|
29
29
|
*
|
|
@@ -37,7 +37,7 @@ export interface CreditEvent {
|
|
|
37
37
|
userId: string;
|
|
38
38
|
data?: Record<string, unknown>;
|
|
39
39
|
}
|
|
40
|
-
type EventHandler = (event: CreditEvent) => void
|
|
40
|
+
type EventHandler = (event: CreditEvent) => void | PromiseLike<void>;
|
|
41
41
|
/** Typed pub/sub event emitter for credit events. */
|
|
42
42
|
export declare class CreditEventEmitter {
|
|
43
43
|
private listeners;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/credits/events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH;;;;;;;;GAQG;AACH,MAAM,MAAM,eAAe,GACvB,kBAAkB,GAClB,uBAAuB,GACvB,eAAe,GACf,kBAAkB,GAClB,uBAAuB,GACvB,iBAAiB,GACjB,qBAAqB,GACrB,sBAAsB,GACtB,kBAAkB,GAClB,8BAA8B,GAC9B,uBAAuB,GACvB,mBAAmB,GACnB,uBAAuB,GACvB,uBAAuB,GACvB,yBAAyB,CAAC;AAE9B;;;;;;GAMG;AACH,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,eAAe,CAAC;IACtB,SAAS,EAAE,IAAI,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC;AAED,KAAK,YAAY,GAAG,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;AAErE,qDAAqD;AACrD,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,SAAS,CAAiD;IAElE,oDAAoD;IACpD,EAAE,CAAC,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI;IAOtD,8CAA8C;IAC9C,GAAG,CAAC,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI;IAIvD;;;;;;;OAOG;IACH,IAAI,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI;IAmB9B,+CAA+C;IAC/C,SAAS,CAAC,IAAI,EAAE,eAAe,GAAG,IAAI;IAItC,yCAAyC;IACzC,QAAQ,IAAI,IAAI;CAGjB"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Typed event emitter for credit lifecycle events.
|
|
3
3
|
*
|
|
4
|
-
* Events are emitted by ``
|
|
5
|
-
* The emitter is optional — inject into ``
|
|
4
|
+
* Events are emitted by ``CreditsService`` after each store operation.
|
|
5
|
+
* The emitter is optional — inject into ``CreditsService`` constructor,
|
|
6
6
|
* no-op if omitted.
|
|
7
7
|
*
|
|
8
8
|
* @example
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* emitter.on("credits.deducted", (event) => {
|
|
12
12
|
* console.log(`Deducted ${event.data?.amount} from ${event.userId}`);
|
|
13
13
|
* });
|
|
14
|
-
* const manager = new
|
|
14
|
+
* const manager = new CreditsService(store, engine, emitter);
|
|
15
15
|
* ```
|
|
16
16
|
*/
|
|
17
17
|
/** Typed pub/sub event emitter for credit events. */
|
|
@@ -45,8 +45,8 @@ export class CreditEventEmitter {
|
|
|
45
45
|
try {
|
|
46
46
|
const out = handler(event);
|
|
47
47
|
// Swallow rejections from async handlers so they never become unhandled.
|
|
48
|
-
if (out
|
|
49
|
-
out.catch((err) => {
|
|
48
|
+
if (out != null && typeof out.then === "function") {
|
|
49
|
+
void Promise.resolve(out).catch((err) => {
|
|
50
50
|
console.error(`[CreditEventEmitter] async handler error for event ${event.type}:`, err);
|
|
51
51
|
});
|
|
52
52
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/credits/events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AA4CH,qDAAqD;AACrD,MAAM,OAAO,kBAAkB;IACrB,SAAS,GAAG,IAAI,GAAG,EAAsC,CAAC;IAElE,oDAAoD;IACpD,EAAE,CAAC,IAAqB,EAAE,OAAqB;QAC7C,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YAC9B,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;QACtC,CAAC;QACD,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAE,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACzC,CAAC;IAED,8CAA8C;IAC9C,GAAG,CAAC,IAAqB,EAAE,OAAqB;QAC9C,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IAC5C,CAAC;IAED;;;;;;;OAOG;IACH,IAAI,CAAC,KAAkB;QACrB,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAChD,IAAI,CAAC,QAAQ;YAAE,OAAO;QACtB,4EAA4E;QAC5E,KAAK,MAAM,OAAO,IAAI,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC;YACpC,IAAI,CAAC;gBACH,MAAM,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;gBAC3B,yEAAyE;gBACzE,IAAI,GAAG,IAAI,IAAI,IAAI,OAAO,GAAG,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;oBAClD,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,GAAY,EAAE,EAAE;wBAC/C,OAAO,CAAC,KAAK,CAAC,sDAAsD,KAAK,CAAC,IAAI,GAAG,EAAE,GAAG,CAAC,CAAC;oBAC1F,CAAC,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,OAAO,CAAC,KAAK,CAAC,gDAAgD,KAAK,CAAC,IAAI,GAAG,EAAE,GAAG,CAAC,CAAC;YACpF,CAAC;QACH,CAAC;IACH,CAAC;IAED,+CAA+C;IAC/C,SAAS,CAAC,IAAqB;QAC7B,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;IAED,yCAAyC;IACzC,QAAQ;QACN,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;IACzB,CAAC;CACF"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import Decimal from "decimal.js";
|
|
2
|
+
import type { NormalizedLogger } from "../shared/logger.js";
|
|
3
|
+
import type { CreditEventType } from "./events.js";
|
|
4
|
+
import { LowBalanceMonitor } from "./low-balance-monitor.js";
|
|
5
|
+
import { PricingRuntime } from "./pricing-runtime.js";
|
|
6
|
+
import type { CanAffordOptions, BeginBilledOperationOptions, BilledOperation, MetricsOrAmount, PolicyPreset, ReserveOptions, RunBilledOptions, SettleOptions } from "./service-types.js";
|
|
7
|
+
import type { CreditStore } from "./store.js";
|
|
8
|
+
import type { AllowanceResult, BucketBalancesResult, CanAffordResult, DeductionResult, LeaseResult, ReleaseResult } from "./types/index.js";
|
|
9
|
+
export declare class CreditLeaseWorkflow {
|
|
10
|
+
private readonly store;
|
|
11
|
+
private readonly pricing;
|
|
12
|
+
private readonly logger;
|
|
13
|
+
private readonly balanceMonitor;
|
|
14
|
+
private readonly policy;
|
|
15
|
+
private readonly overdraftFloor;
|
|
16
|
+
private readonly defaultMaxConcurrent;
|
|
17
|
+
private readonly defaultTtl;
|
|
18
|
+
private readonly emit;
|
|
19
|
+
private readonly emitQuotaEvents;
|
|
20
|
+
private readonly maybeLazyExpire;
|
|
21
|
+
private readonly afterDeduction;
|
|
22
|
+
constructor(store: CreditStore, pricing: PricingRuntime, logger: NormalizedLogger, balanceMonitor: LowBalanceMonitor, policy: PolicyPreset, overdraftFloor: Decimal | null, defaultMaxConcurrent: number | null, defaultTtl: number, emit: (type: CreditEventType, userId: string, data?: Record<string, unknown>) => void, emitQuotaEvents: (userId: string, idempotencyKey: string) => Promise<void>, maybeLazyExpire: (userId: string) => Promise<void>, afterDeduction: (userId: string, result: DeductionResult) => Promise<void>);
|
|
23
|
+
private expectedAdmissionPolicy;
|
|
24
|
+
/**
|
|
25
|
+
* Compute the credit cost and model from metrics, or pass a raw amount through.
|
|
26
|
+
*
|
|
27
|
+
* For {@link UsageMetrics} the cost is ``engine.calculate(...).total`` (exact
|
|
28
|
+
* `Decimal`, no truncation); a raw amount is used as-is with no model.
|
|
29
|
+
*/
|
|
30
|
+
private costOf;
|
|
31
|
+
/**
|
|
32
|
+
* Atomically acquire a lease — the only admission control (D4).
|
|
33
|
+
*
|
|
34
|
+
* Prices the estimate and delegates entitlement, quota, allowance, credit
|
|
35
|
+
* policy, and concurrency enforcement to the database in one atomic call.
|
|
36
|
+
*/
|
|
37
|
+
reserve(userId: string, metricsOrAmount: MetricsOrAmount, options?: ReserveOptions): Promise<LeaseResult>;
|
|
38
|
+
/**
|
|
39
|
+
* Charge the ACTUAL cost against a lease and finalize it (D5).
|
|
40
|
+
*
|
|
41
|
+
* De-clamped: bills the full actual cost even if it exceeds the lease hold
|
|
42
|
+
* (overdraft). Emits ``credits.deducted``, then low-balance and overdraft
|
|
43
|
+
* signals as applicable.
|
|
44
|
+
*/
|
|
45
|
+
settle(userId: string, leaseId: string, metricsOrAmount: MetricsOrAmount, options?: SettleOptions): Promise<DeductionResult>;
|
|
46
|
+
/** Release a lease without charging (work failed/aborted) — idempotent (H1). */
|
|
47
|
+
release(userId: string, leaseId: string): Promise<ReleaseResult>;
|
|
48
|
+
/** Extend an active lease's expiry without changing its captured policy. */
|
|
49
|
+
renew(userId: string, leaseId: string, ttl?: number | null): Promise<LeaseResult>;
|
|
50
|
+
/**
|
|
51
|
+
* Advisory affordability check — UI only, non-locking, may be stale (D4/H3).
|
|
52
|
+
*
|
|
53
|
+
* Never use this as an admission gate; only ``reserve`` is authoritative.
|
|
54
|
+
*/
|
|
55
|
+
canAfford(userId: string, metricsOrAmount: MetricsOrAmount, options?: CanAffordOptions): Promise<CanAffordResult>;
|
|
56
|
+
/** Get a user's per-bucket credit balances (credit buckets). Thin pass-through, no event emission. */
|
|
57
|
+
getBucketBalances(userId: string): Promise<BucketBalancesResult>;
|
|
58
|
+
/**
|
|
59
|
+
* Get remaining free allowance for the current billing period.
|
|
60
|
+
*
|
|
61
|
+
* Convenience wrapper that routes through the manager so callers never need
|
|
62
|
+
* to reach past it into the raw store. Returns a zero-allowance result for
|
|
63
|
+
* planless users (no exception).
|
|
64
|
+
*
|
|
65
|
+
* Window calculation is database-owned and supports the full normalized
|
|
66
|
+
* policy tuple, including timezone and arbitrary interval counts.
|
|
67
|
+
*/
|
|
68
|
+
checkAllowance(userId: string): Promise<AllowanceResult>;
|
|
69
|
+
/**
|
|
70
|
+
* One-call shortcut wiring reserve → doWork → settle (interface plan §4).
|
|
71
|
+
*
|
|
72
|
+
* ``doWork`` runs the operation and returns ``{ result, actual }`` where
|
|
73
|
+
* ``actual`` is the real usage metrics (or amount) to settle. On any exception
|
|
74
|
+
* from ``doWork`` the lease is released and the error re-raised. For long jobs
|
|
75
|
+
* ``doWork`` may call the configured lease TTL. A crash between reserve and settle is
|
|
76
|
+
* covered by the lease TTL (and the store's reaper).
|
|
77
|
+
*/
|
|
78
|
+
runBilled<T>(userId: string, options: RunBilledOptions<T>): Promise<{
|
|
79
|
+
result: T;
|
|
80
|
+
deduction: DeductionResult;
|
|
81
|
+
}>;
|
|
82
|
+
/**
|
|
83
|
+
* Begin a replay-safe billable operation that can span framework callbacks.
|
|
84
|
+
*
|
|
85
|
+
* The operation key is namespaced into distinct reserve and settle keys, so
|
|
86
|
+
* replaying the whole lifecycle cannot acquire a second hold.
|
|
87
|
+
*/
|
|
88
|
+
beginBilledOperation(userId: string, options: BeginBilledOperationOptions): Promise<BilledOperation>;
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=lease-workflow.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lease-workflow.d.ts","sourceRoot":"","sources":["../../src/credits/lease-workflow.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,YAAY,CAAC;AAIjC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAY,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEhE,OAAO,KAAK,EACV,gBAAgB,EAChB,2BAA2B,EAC3B,eAAe,EACf,eAAe,EACf,YAAY,EACZ,cAAc,EACd,gBAAgB,EAChB,aAAa,EACd,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,KAAK,EACV,eAAe,EAEf,oBAAoB,EACpB,eAAe,EAEf,eAAe,EACf,WAAW,EACX,aAAa,EACd,MAAM,kBAAkB,CAAC;AAE1B,qBAAa,mBAAmB;IAE5B,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,cAAc;IAC/B,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,cAAc;IAC/B,OAAO,CAAC,QAAQ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