@zonastery/bursar 0.0.2 → 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 +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 +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 +8 -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 +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 -23
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +86 -385
- 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/credits/store.d.ts +167 -0
- package/dist/credits/store.d.ts.map +1 -0
- package/dist/{stores/credit-store.js → credits/store.js} +23 -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 +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 -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.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 +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/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/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 +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 +36 -20
- 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
package/dist/config.js
CHANGED
|
@@ -1,396 +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
|
-
/** Known top-level config keys, checked after snake→camel normalisation. */
|
|
37
|
-
const TOP_LEVEL_KEYS = new Set([
|
|
38
|
-
"version",
|
|
39
|
-
"models",
|
|
40
|
-
"tools",
|
|
41
|
-
"search",
|
|
42
|
-
"cache",
|
|
43
|
-
"minBalance",
|
|
44
|
-
"signupBonus",
|
|
45
|
-
"fixed",
|
|
46
|
-
"plans",
|
|
47
|
-
"tiers",
|
|
48
|
-
]);
|
|
49
|
-
/** Known plan-definition keys (`billingMode` is the short-form alias for `defaultBillingMode`). */
|
|
50
|
-
const PLAN_KEYS = new Set([
|
|
51
|
-
"id",
|
|
52
|
-
"name",
|
|
53
|
-
"freeAllowance",
|
|
54
|
-
"rateOverrides",
|
|
55
|
-
"features",
|
|
56
|
-
"featureLimits",
|
|
57
|
-
"defaultBillingMode",
|
|
58
|
-
"billingMode",
|
|
59
|
-
"perOperation",
|
|
60
|
-
"maxConcurrent",
|
|
61
|
-
"overdraftFloor",
|
|
62
|
-
"allowancePeriod",
|
|
63
|
-
]);
|
|
64
|
-
/** Known `FeatureLimit` keys. */
|
|
65
|
-
const FEATURE_LIMIT_KEYS = new Set(["maxCalls", "period", "action"]);
|
|
66
|
-
/** Known `OperationPolicy` keys (entries of a plan's `perOperation` map). */
|
|
67
|
-
const OPERATION_POLICY_KEYS = new Set([
|
|
68
|
-
"billingMode",
|
|
69
|
-
"maxConcurrent",
|
|
70
|
-
"overdraftFloor",
|
|
71
|
-
]);
|
|
72
|
-
/** Known tier-definition keys. */
|
|
73
|
-
const TIER_KEYS = new Set([
|
|
74
|
-
"name",
|
|
75
|
-
"priority",
|
|
76
|
-
"expires",
|
|
77
|
-
"defaultTtlDays",
|
|
78
|
-
"allowOverdraft",
|
|
79
|
-
"isDefault",
|
|
80
|
-
]);
|
|
81
|
-
/** Reject any key not in `known` — catches typos (`min_balnce`) that would otherwise silently fall back to a default. */
|
|
82
|
-
function assertKnownKeys(obj, known, context) {
|
|
83
|
-
for (const key of Object.keys(obj)) {
|
|
84
|
-
if (!known.has(key)) {
|
|
85
|
-
throw new ConfigError(`unknown config key in ${context}: ${key}`);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
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("; ");
|
|
88
24
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
catch (e) {
|
|
105
|
-
throw new ConfigError(`invalid expression in tools.${key}: ${e.message}`);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
if (raw.search) {
|
|
109
|
-
try {
|
|
110
|
-
validateExpression(raw.search, KNOWN_VARIABLES);
|
|
111
|
-
}
|
|
112
|
-
catch (e) {
|
|
113
|
-
throw new ConfigError(`invalid expression in search: ${e.message}`);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
if (raw.cache) {
|
|
117
|
-
try {
|
|
118
|
-
validateExpression(raw.cache, KNOWN_VARIABLES);
|
|
119
|
-
}
|
|
120
|
-
catch (e) {
|
|
121
|
-
throw new ConfigError(`invalid expression in cache: ${e.message}`);
|
|
25
|
+
export function loadConfigFromDict(data) {
|
|
26
|
+
if (!validateStructure(data)) {
|
|
27
|
+
throw new ConfigError(formatAjvErrors(validateStructure.errors), validateStructure.errors ?? []);
|
|
28
|
+
}
|
|
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(", ")}`);
|
|
39
|
+
}
|
|
122
40
|
}
|
|
123
41
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
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}'`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
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(", ")}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
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}'`);
|
|
62
|
+
}
|
|
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,
|
|
149
74
|
};
|
|
150
|
-
const out = {};
|
|
151
|
-
for (const [k, v] of Object.entries(data)) {
|
|
152
|
-
const mapped = keyMap[k] ?? k;
|
|
153
|
-
out[mapped] = v;
|
|
154
|
-
}
|
|
155
|
-
return out;
|
|
156
75
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
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
|
+
]));
|
|
160
89
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
return normaliseKeys(t);
|
|
90
|
+
export function canonicalBursarConfigDict(data) {
|
|
91
|
+
return toSnakeCase(loadConfigFromDict(data));
|
|
164
92
|
}
|
|
165
|
-
/**
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
* handling). Each entry's own keys are snake/camel-normalised (`max_calls`
|
|
169
|
-
* -> `maxCalls`) since, unlike top-level plan fields, these nested objects
|
|
170
|
-
* are not otherwise touched by `normaliseKeys`.
|
|
171
|
-
*/
|
|
172
|
-
function normaliseFeatureLimits(planKey, raw) {
|
|
173
|
-
const out = {};
|
|
174
|
-
for (const [featureKey, rawLimit] of Object.entries(raw)) {
|
|
175
|
-
const limit = normaliseKeys((rawLimit ?? {}));
|
|
176
|
-
assertKnownKeys(limit, FEATURE_LIMIT_KEYS, `plans.${planKey}.featureLimits.${featureKey}`);
|
|
177
|
-
const maxCalls = Number(limit.maxCalls ?? 0);
|
|
178
|
-
const period = limit.period ?? "monthly";
|
|
179
|
-
const action = limit.action ?? "deny";
|
|
180
|
-
if (!Number.isFinite(maxCalls) || maxCalls < 0) {
|
|
181
|
-
throw new ConfigError(`invalid featureLimits in plans.${planKey}.${featureKey}: maxCalls must be >= 0, got ${String(limit.maxCalls)}`);
|
|
182
|
-
}
|
|
183
|
-
if (!FEATURE_LIMIT_PERIODS.has(period)) {
|
|
184
|
-
throw new ConfigError(`invalid featureLimits in plans.${planKey}.${featureKey}: unknown period '${period}' ` +
|
|
185
|
-
`(expected one of ${[...FEATURE_LIMIT_PERIODS].sort().join(", ")})`);
|
|
186
|
-
}
|
|
187
|
-
if (!FEATURE_LIMIT_ACTIONS.has(action)) {
|
|
188
|
-
throw new ConfigError(`invalid featureLimits in plans.${planKey}.${featureKey}: unknown action '${action}' ` +
|
|
189
|
-
`(expected one of ${[...FEATURE_LIMIT_ACTIONS].sort().join(", ")})`);
|
|
190
|
-
}
|
|
191
|
-
out[featureKey] = {
|
|
192
|
-
maxCalls,
|
|
193
|
-
period: period,
|
|
194
|
-
action: action,
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
return out;
|
|
198
|
-
}
|
|
199
|
-
/**
|
|
200
|
-
* Normalise + validate a plan's `perOperation` map (per-operation
|
|
201
|
-
* financial-safety policy overrides, mirrors Python's `OperationPolicy`).
|
|
202
|
-
* Each entry's own keys are snake/camel-normalised since, unlike top-level
|
|
203
|
-
* plan fields, these nested objects are not otherwise touched by
|
|
204
|
-
* `normaliseKeys`.
|
|
205
|
-
*/
|
|
206
|
-
function normalisePerOperation(planKey, raw) {
|
|
207
|
-
const out = {};
|
|
208
|
-
for (const [opType, rawPolicy] of Object.entries(raw)) {
|
|
209
|
-
const policy = normaliseKeys((rawPolicy ?? {}));
|
|
210
|
-
assertKnownKeys(policy, OPERATION_POLICY_KEYS, `plans.${planKey}.perOperation.${opType}`);
|
|
211
|
-
const billingMode = policy.billingMode ?? "strict";
|
|
212
|
-
if (billingMode !== "strict" && billingMode !== "overdraft") {
|
|
213
|
-
throw new ConfigError(`invalid billingMode in plans.${planKey}.perOperation.${opType}: '${billingMode}' ` +
|
|
214
|
-
`(expected 'strict' or 'overdraft')`);
|
|
215
|
-
}
|
|
216
|
-
out[opType] = {
|
|
217
|
-
billingMode: billingMode,
|
|
218
|
-
maxConcurrent: policy.maxConcurrent ?? null,
|
|
219
|
-
overdraftFloor: policy.overdraftFloor != null ? new Decimal(policy.overdraftFloor) : null,
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
return out;
|
|
223
|
-
}
|
|
224
|
-
/** Load and validate a pricing config from a raw dictionary. */
|
|
225
|
-
export function loadConfigFromDict(data) {
|
|
226
|
-
// H6: normalise top-level keys from snake_case to camelCase first.
|
|
227
|
-
const d = normaliseKeys(data);
|
|
228
|
-
assertKnownKeys(d, TOP_LEVEL_KEYS, "config");
|
|
229
|
-
// Only `1` is a valid version (mirrors Python's `Literal[1]`); JS previously
|
|
230
|
-
// never inspected this field at all.
|
|
231
|
-
if (d.version !== undefined && d.version !== 1) {
|
|
232
|
-
throw new ConfigError(`version must be 1, got ${JSON.stringify(d.version)}`);
|
|
233
|
-
}
|
|
234
|
-
if (d.models == null)
|
|
235
|
-
throw new ConfigError("missing required section: models");
|
|
236
|
-
if (typeof d.models !== "object" || Object.keys(d.models).length === 0) {
|
|
237
|
-
throw new ConfigError("models must be a non-empty dict");
|
|
238
|
-
}
|
|
239
|
-
// Validate plan rate overrides and duplicate names
|
|
240
|
-
const rawPlans = d.plans;
|
|
241
|
-
// Normalise each plan's keys too (free_allowance etc.)
|
|
242
|
-
const plans = rawPlans
|
|
243
|
-
? Object.fromEntries(Object.entries(rawPlans).map(([k, v]) => [k, normalisePlan(v)]))
|
|
244
|
-
: undefined;
|
|
245
|
-
if (plans) {
|
|
246
|
-
for (const [planKey, plan] of Object.entries(plans)) {
|
|
247
|
-
assertKnownKeys(plan, PLAN_KEYS, `plans.${planKey}`);
|
|
248
|
-
// A plan definition must carry a `name` (mirrors Python's `config.py:62`);
|
|
249
|
-
// JS previously left this unchecked and silently produced `undefined`.
|
|
250
|
-
if (plan.name == null) {
|
|
251
|
-
throw new ConfigError(`plan definition is missing required 'name' field: plans.${planKey}`);
|
|
252
|
-
}
|
|
253
|
-
const overrides = plan.rateOverrides;
|
|
254
|
-
if (overrides) {
|
|
255
|
-
for (const [modelKey, expr] of Object.entries(overrides)) {
|
|
256
|
-
try {
|
|
257
|
-
validateExpression(expr, KNOWN_VARIABLES);
|
|
258
|
-
}
|
|
259
|
-
catch (e) {
|
|
260
|
-
throw new ConfigError(`invalid expression in plans.${planKey}.rateOverrides.${modelKey}: ${e.message}`);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
// WS9b: allowancePeriod must be one of the three valid strings if present.
|
|
265
|
-
if (plan.allowancePeriod != null && !ALLOWANCE_PERIODS.has(plan.allowancePeriod)) {
|
|
266
|
-
throw new ConfigError(`invalid allowancePeriod in plans.${planKey}: ${String(plan.allowancePeriod)} ` +
|
|
267
|
-
`(expected one of ${[...ALLOWANCE_PERIODS].sort().join(", ")})`);
|
|
268
|
-
}
|
|
269
|
-
// Per-feature invocation-count limits: normalise nested keys + validate.
|
|
270
|
-
if (plan.featureLimits != null) {
|
|
271
|
-
if (typeof plan.featureLimits !== "object" || Array.isArray(plan.featureLimits)) {
|
|
272
|
-
throw new ConfigError(`plans.${planKey}.featureLimits must be a dict`);
|
|
273
|
-
}
|
|
274
|
-
plan.featureLimits = normaliseFeatureLimits(planKey, plan.featureLimits);
|
|
275
|
-
}
|
|
276
|
-
// Per-operation financial-safety policy overrides: validate shape here;
|
|
277
|
-
// normalised into `OperationPolicy` objects when `planDefs` is built below.
|
|
278
|
-
if (plan.perOperation != null) {
|
|
279
|
-
if (typeof plan.perOperation !== "object" || Array.isArray(plan.perOperation)) {
|
|
280
|
-
throw new ConfigError(`plans.${planKey}.perOperation must be a dict`);
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
const planNames = Object.values(plans).map((p) => p.name);
|
|
285
|
-
if (new Set(planNames).size !== planNames.length) {
|
|
286
|
-
throw new ConfigError("duplicate plan names in pricing config");
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
// Credit tiers (sibling to `plans`): validate + normalise. An explicit empty
|
|
290
|
-
// `tiers: {}` is a config error (ambiguous intent — omit the key entirely
|
|
291
|
-
// for "no tiers"), mirroring the Python `config.py` validator exactly.
|
|
292
|
-
if (d.tiers !== undefined && d.tiers !== null) {
|
|
293
|
-
if (typeof d.tiers !== "object" || Array.isArray(d.tiers)) {
|
|
294
|
-
throw new ConfigError("tiers must be a dict of tier definitions");
|
|
295
|
-
}
|
|
296
|
-
if (Object.keys(d.tiers).length === 0) {
|
|
297
|
-
throw new ConfigError("tiers must not be an empty object; omit the `tiers` key entirely for no tiers");
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
const rawTiers = d.tiers;
|
|
301
|
-
const tiers = rawTiers
|
|
302
|
-
? Object.fromEntries(Object.entries(rawTiers).map(([k, v]) => [k, normaliseTier(v)]))
|
|
303
|
-
: undefined;
|
|
304
|
-
if (tiers) {
|
|
305
|
-
let overdraftCount = 0;
|
|
306
|
-
let defaultCount = 0;
|
|
307
|
-
for (const [tierKey, t] of Object.entries(tiers)) {
|
|
308
|
-
assertKnownKeys(t, TIER_KEYS, `tiers.${tierKey}`);
|
|
309
|
-
if (t.allowOverdraft === true)
|
|
310
|
-
overdraftCount++;
|
|
311
|
-
if (t.isDefault === true)
|
|
312
|
-
defaultCount++;
|
|
313
|
-
if (t.defaultTtlDays != null && t.defaultTtlDays <= 0) {
|
|
314
|
-
throw new ConfigError(`tiers.${tierKey}.defaultTtlDays must be > 0, got ${String(t.defaultTtlDays)}`);
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
if (overdraftCount > 1) {
|
|
318
|
-
throw new ConfigError("at most one tier may set allowOverdraft: true");
|
|
319
|
-
}
|
|
320
|
-
if (defaultCount > 1) {
|
|
321
|
-
throw new ConfigError("at most one tier may set isDefault: true");
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
const config = {
|
|
325
|
-
models: d.models,
|
|
326
|
-
// Only default `tools` when the key is entirely absent (mirrors Python's
|
|
327
|
-
// pydantic `default_factory`); a user-supplied `tools` map — even one
|
|
328
|
-
// without `_default` — is used as-is. `PricingEngine.calcTools` already
|
|
329
|
-
// falls back to `"tool_calls * 0"` at evaluation time when `_default` is
|
|
330
|
-
// missing, so behavior is unaffected either way.
|
|
331
|
-
tools: d.tools ?? { _default: "tool_calls * 0" },
|
|
332
|
-
search: d.search ?? null,
|
|
333
|
-
cache: d.cache ?? null,
|
|
334
|
-
// Money fields: Decimal, never a binary `number` (contract §1).
|
|
335
|
-
minBalance: new Decimal(d.minBalance ?? 0),
|
|
336
|
-
signupBonus: d.signupBonus,
|
|
337
|
-
fixed: Object.fromEntries(Object.entries(d.fixed ?? {}).map(([job, cost]) => [job, new Decimal(cost)])),
|
|
338
|
-
};
|
|
339
|
-
if (config.minBalance.isNegative())
|
|
340
|
-
throw new ConfigError("min_balance must be >= 0");
|
|
341
|
-
if (config.signupBonus != null && config.signupBonus < 0) {
|
|
342
|
-
throw new ConfigError(`signup_bonus must be >= 0, got ${config.signupBonus}`);
|
|
343
|
-
}
|
|
344
|
-
// WS3: fixed job costs may be fractional (Decimal-compatible) — only non-negative
|
|
345
|
-
// is enforced. Was: Number.isInteger check (contradicted docs).
|
|
346
|
-
for (const [job, cost] of Object.entries(config.fixed)) {
|
|
347
|
-
if (cost.isNegative()) {
|
|
348
|
-
throw new ConfigError(`fixed.${job} must be non-negative, got ${cost.toString()}`);
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
if (plans) {
|
|
352
|
-
const planDefs = {};
|
|
353
|
-
for (const [key, p] of Object.entries(plans)) {
|
|
354
|
-
const freeAllowance = new Decimal(p.freeAllowance ?? 0);
|
|
355
|
-
if (freeAllowance.isNegative()) {
|
|
356
|
-
throw new ConfigError(`plans.${key}.freeAllowance must be >= 0, got ${freeAllowance.toString()}`);
|
|
357
|
-
}
|
|
358
|
-
planDefs[key] = {
|
|
359
|
-
id: p.id ?? key,
|
|
360
|
-
name: p.name,
|
|
361
|
-
freeAllowance,
|
|
362
|
-
rateOverrides: p.rateOverrides ?? null,
|
|
363
|
-
features: p.features ?? null,
|
|
364
|
-
featureLimits: p.featureLimits ?? null,
|
|
365
|
-
defaultBillingMode: (p.defaultBillingMode ?? p.billingMode) ?? "strict",
|
|
366
|
-
overdraftFloor: p.overdraftFloor != null ? new Decimal(p.overdraftFloor) : null,
|
|
367
|
-
maxConcurrent: p.maxConcurrent ?? null,
|
|
368
|
-
allowancePeriod: (p.allowancePeriod ?? "calendar_month"),
|
|
369
|
-
// Was silently dropped: `PlanDefinition.perOperation` was declared in
|
|
370
|
-
// types.ts but never populated here, so per-operation billing policy
|
|
371
|
-
// from config was ignored by the JS SDK.
|
|
372
|
-
perOperation: p.perOperation != null
|
|
373
|
-
? normalisePerOperation(key, p.perOperation)
|
|
374
|
-
: undefined,
|
|
375
|
-
};
|
|
376
|
-
}
|
|
377
|
-
config.plans = planDefs;
|
|
378
|
-
}
|
|
379
|
-
if (tiers) {
|
|
380
|
-
const tierDefs = {};
|
|
381
|
-
for (const [key, t] of Object.entries(tiers)) {
|
|
382
|
-
tierDefs[key] = {
|
|
383
|
-
name: t.name ?? key,
|
|
384
|
-
priority: Number(t.priority ?? 0),
|
|
385
|
-
expires: Boolean(t.expires ?? false),
|
|
386
|
-
defaultTtlDays: t.defaultTtlDays != null ? Number(t.defaultTtlDays) : null,
|
|
387
|
-
allowOverdraft: Boolean(t.allowOverdraft ?? false),
|
|
388
|
-
isDefault: Boolean(t.isDefault ?? false),
|
|
389
|
-
};
|
|
390
|
-
}
|
|
391
|
-
config.tiers = tierDefs;
|
|
392
|
-
}
|
|
393
|
-
validateExpressions(config);
|
|
394
|
-
return config;
|
|
93
|
+
/** Serialize an already parsed configuration without re-validating camelCase fields as raw input. */
|
|
94
|
+
export function canonicalParsedBursarConfigDict(data) {
|
|
95
|
+
return toSnakeCase(data);
|
|
395
96
|
}
|
|
396
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,YAAY,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAI/C,6CAA6C;AAC7C,MAAM,iBAAiB,GAAwB,IAAI,GAAG,CAAC;IACrD,gBAAgB;IAChB,aAAa;IACb,aAAa;CACd,CAAC,CAAC;AAEH,uFAAuF;AACvF,MAAM,qBAAqB,GAAwB,IAAI,GAAG,CAAC;IACzD,OAAO;IACP,QAAQ;IACR,SAAS;IACT,QAAQ;CACT,CAAC,CAAC;AAEH,sEAAsE;AACtE,MAAM,qBAAqB,GAAwB,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;AAEvF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAAwB,IAAI,GAAG,CAAC;IAC1D,cAAc;IACd,eAAe;IACf,mBAAmB;IACnB,oBAAoB;IACpB,YAAY;IACZ,gBAAgB;IAChB,gBAAgB;IAChB,kBAAkB;IAClB,iBAAiB;CAClB,CAAC,CAAC;AAgBH,4EAA4E;AAC5E,MAAM,cAAc,GAAwB,IAAI,GAAG,CAAC;IAClD,SAAS;IACT,QAAQ;IACR,OAAO;IACP,QAAQ;IACR,OAAO;IACP,YAAY;IACZ,aAAa;IACb,OAAO;IACP,OAAO;IAC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,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,KAAmB,CAAC;SAChC,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,KAAK,SAAS,CAAC;SAC1C,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC;QACrB,GAAG,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,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;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