@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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/credits/types/index.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { Decimal } from "decimal.js";
|
|
2
|
+
/** One immutable monetary entry on a canonical credit account. */
|
|
3
|
+
export interface LedgerEntry {
|
|
4
|
+
entryId: string;
|
|
5
|
+
accountId: string;
|
|
6
|
+
actorUserId: string | null;
|
|
7
|
+
amount: Decimal;
|
|
8
|
+
entryType: string;
|
|
9
|
+
operation: string;
|
|
10
|
+
referenceEntryId: string | null;
|
|
11
|
+
idempotencyKey: string | null;
|
|
12
|
+
metadata: Record<string, unknown> | null;
|
|
13
|
+
createdAt: string;
|
|
14
|
+
}
|
|
15
|
+
/** Stable position in an account ledger. */
|
|
16
|
+
export interface LedgerCursor {
|
|
17
|
+
createdAt: string;
|
|
18
|
+
entryId: string;
|
|
19
|
+
}
|
|
20
|
+
/** Cursor-only options for listing account ledger entries. */
|
|
21
|
+
export interface ListLedgerEntriesOptions {
|
|
22
|
+
entryTypes?: string[];
|
|
23
|
+
fromDate?: Date;
|
|
24
|
+
toDate?: Date;
|
|
25
|
+
limit?: number;
|
|
26
|
+
cursor?: LedgerCursor | null;
|
|
27
|
+
}
|
|
28
|
+
/** One stable cursor page. */
|
|
29
|
+
export interface LedgerPage {
|
|
30
|
+
items: LedgerEntry[];
|
|
31
|
+
nextCursor: LedgerCursor | null;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* A metered usage charge from the usage charge journal.
|
|
35
|
+
*
|
|
36
|
+
* Usage charges are deliberately separate from ledger entries: included
|
|
37
|
+
* allowance consumption does not create a monetary ledger debit, but it is
|
|
38
|
+
* still a billable usage event that belongs in the usage history.
|
|
39
|
+
*/
|
|
40
|
+
export interface UsageCharge {
|
|
41
|
+
usageId: string;
|
|
42
|
+
accountId: string;
|
|
43
|
+
operation: string;
|
|
44
|
+
requested: Decimal;
|
|
45
|
+
charged: Decimal;
|
|
46
|
+
allowanceRequested: Decimal;
|
|
47
|
+
allowanceCovered: Decimal;
|
|
48
|
+
feature: string | null;
|
|
49
|
+
model: string | null;
|
|
50
|
+
region: string | null;
|
|
51
|
+
eventAt: string;
|
|
52
|
+
idempotencyKey: string;
|
|
53
|
+
metadata: Record<string, unknown> | null;
|
|
54
|
+
createdAt: string;
|
|
55
|
+
}
|
|
56
|
+
export interface UsageChargeCursor {
|
|
57
|
+
eventAt: string;
|
|
58
|
+
usageId: string;
|
|
59
|
+
}
|
|
60
|
+
export interface ListUsageChargesOptions {
|
|
61
|
+
fromDate?: Date;
|
|
62
|
+
toDate?: Date;
|
|
63
|
+
limit?: number;
|
|
64
|
+
cursor?: UsageChargeCursor | null;
|
|
65
|
+
}
|
|
66
|
+
export interface UsageChargePage {
|
|
67
|
+
items: UsageCharge[];
|
|
68
|
+
nextCursor: UsageChargeCursor | null;
|
|
69
|
+
}
|
|
70
|
+
/** Cursor-only options for the usage-only ledger view. */
|
|
71
|
+
export interface ListUsageEntriesOptions {
|
|
72
|
+
fromDate?: Date;
|
|
73
|
+
toDate?: Date;
|
|
74
|
+
limit?: number;
|
|
75
|
+
cursor?: LedgerCursor | null;
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=ledger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ledger.d.ts","sourceRoot":"","sources":["../../../src/credits/types/ledger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAI1C,kEAAkE;AAClE,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,MAAM,EAAE,OAAO,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACzC,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,4CAA4C;AAC5C,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,8DAA8D;AAC9D,MAAM,WAAW,wBAAwB;IACvC,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,QAAQ,CAAC,EAAE,IAAI,CAAC;IAChB,MAAM,CAAC,EAAE,IAAI,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,YAAY,GAAG,IAAI,CAAC;CAC9B;AAED,8BAA8B;AAC9B,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,WAAW,EAAE,CAAC;IACrB,UAAU,EAAE,YAAY,GAAG,IAAI,CAAC;CACjC;AAED;;;;;;GAMG;AACH,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,kBAAkB,EAAE,OAAO,CAAC;IAC5B,gBAAgB,EAAE,OAAO,CAAC;IAC1B,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACzC,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,EAAE,IAAI,CAAC;IAChB,MAAM,CAAC,EAAE,IAAI,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,iBAAiB,GAAG,IAAI,CAAC;CACnC;AAED,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,WAAW,EAAE,CAAC;IACrB,UAAU,EAAE,iBAAiB,GAAG,IAAI,CAAC;CACtC;AAED,0DAA0D;AAC1D,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,EAAE,IAAI,CAAC;IAChB,MAAM,CAAC,EAAE,IAAI,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,YAAY,GAAG,IAAI,CAAC;CAC9B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ledger.js","sourceRoot":"","sources":["../../../src/credits/types/ledger.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Decimal } from "decimal.js";
|
|
2
|
+
export interface CheckFeatureResult {
|
|
3
|
+
userId: string;
|
|
4
|
+
feature: string;
|
|
5
|
+
value: unknown;
|
|
6
|
+
hasFeature: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface QuotaState {
|
|
9
|
+
userId: string;
|
|
10
|
+
quotaKey: string;
|
|
11
|
+
operation: string;
|
|
12
|
+
measure: string;
|
|
13
|
+
limit: Decimal;
|
|
14
|
+
consumed: Decimal;
|
|
15
|
+
reserved: Decimal;
|
|
16
|
+
remaining: Decimal;
|
|
17
|
+
overage: Decimal;
|
|
18
|
+
enforcement: "block" | "allow";
|
|
19
|
+
windowStart: string;
|
|
20
|
+
windowEnd: string;
|
|
21
|
+
emitAtPercent: number[];
|
|
22
|
+
}
|
|
23
|
+
export interface QuotaEvent {
|
|
24
|
+
eventId: string;
|
|
25
|
+
quotaKey: string;
|
|
26
|
+
operation: string;
|
|
27
|
+
measure: string;
|
|
28
|
+
eventType: "threshold" | "blocked";
|
|
29
|
+
thresholdPercent: number | null;
|
|
30
|
+
idempotencyKey: string;
|
|
31
|
+
usageChargeId: string | null;
|
|
32
|
+
createdAt: string;
|
|
33
|
+
}
|
|
34
|
+
export interface ListQuotaEventsOptions {
|
|
35
|
+
after?: Date | null;
|
|
36
|
+
afterId?: string | null;
|
|
37
|
+
limit?: number;
|
|
38
|
+
idempotencyKey?: string | null;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=quotas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quotas.d.ts","sourceRoot":"","sources":["../../../src/credits/types/quotas.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,OAAO,CAAC;IACf,UAAU,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,OAAO,CAAC;IACf,QAAQ,EAAE,OAAO,CAAC;IAClB,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,OAAO,GAAG,OAAO,CAAC;IAC/B,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,EAAE,CAAC;CACzB;AAED,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,WAAW,GAAG,SAAS,CAAC;IACnC,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,sBAAsB;IACrC,KAAK,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quotas.js","sourceRoot":"","sources":["../../../src/credits/types/quotas.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { Decimal } from "decimal.js";
|
|
2
|
+
/** A team with a shared credit balance pool. */
|
|
3
|
+
export interface Team {
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
balance: Decimal;
|
|
7
|
+
memberCount: number;
|
|
8
|
+
createdAt: string;
|
|
9
|
+
}
|
|
10
|
+
/** A member of a team, with optional spend cap. */
|
|
11
|
+
export interface TeamMember {
|
|
12
|
+
userId: string;
|
|
13
|
+
role: string;
|
|
14
|
+
spendCap?: Decimal | null;
|
|
15
|
+
totalSpent: Decimal;
|
|
16
|
+
}
|
|
17
|
+
/** Result of fetching team balance. */
|
|
18
|
+
export interface TeamBalanceResult {
|
|
19
|
+
teamId: string;
|
|
20
|
+
name: string;
|
|
21
|
+
balance: Decimal;
|
|
22
|
+
memberCount: number;
|
|
23
|
+
}
|
|
24
|
+
/** Result of creating a team. */
|
|
25
|
+
export interface CreateTeamResult {
|
|
26
|
+
teamId: string;
|
|
27
|
+
name: string;
|
|
28
|
+
}
|
|
29
|
+
/** Result of adding a team member. */
|
|
30
|
+
export interface AddTeamMemberResult {
|
|
31
|
+
teamId: string;
|
|
32
|
+
userId: string;
|
|
33
|
+
role: string;
|
|
34
|
+
}
|
|
35
|
+
/** Result of deducting credits from a team pool. */
|
|
36
|
+
export interface TeamDeductionResult {
|
|
37
|
+
entryId: string;
|
|
38
|
+
teamId: string;
|
|
39
|
+
userId: string;
|
|
40
|
+
amount: Decimal;
|
|
41
|
+
teamBalanceAfter: Decimal;
|
|
42
|
+
error?: string | null;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=teams.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"teams.d.ts","sourceRoot":"","sources":["../../../src/credits/types/teams.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAG1C,gDAAgD;AAChD,MAAM,WAAW,IAAI;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,mDAAmD;AACnD,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAC1B,UAAU,EAAE,OAAO,CAAC;CACrB;AAED,uCAAuC;AACvC,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,iCAAiC;AACjC,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd;AAED,sCAAsC;AACtC,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd;AAED,oDAAoD;AACpD,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,OAAO,CAAC;IAChB,gBAAgB,EAAE,OAAO,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"teams.js","sourceRoot":"","sources":["../../../src/credits/types/teams.ts"],"names":[],"mappings":""}
|
package/dist/engine.d.ts
CHANGED
|
@@ -1,44 +1,23 @@
|
|
|
1
|
-
import Decimal from "decimal.js";
|
|
2
|
-
import type { PricingConfig } from "./config.js";
|
|
3
1
|
import type { CostBreakdown } from "./breakdown.js";
|
|
2
|
+
import { type BursarConfigData, type ParsedBursarConfig } from "./config.js";
|
|
4
3
|
import type { UsageMetrics } from "./metrics.js";
|
|
5
|
-
import type { PricingConfigData } from "./types.js";
|
|
6
|
-
/**
|
|
7
|
-
* Credit calculation engine.
|
|
8
|
-
*
|
|
9
|
-
* Evaluates pricing expressions against usage metrics to produce cost
|
|
10
|
-
* breakdowns. All money values are exact `Decimal`s — never binary `number`.
|
|
11
|
-
*/
|
|
12
4
|
export declare class PricingEngine {
|
|
13
|
-
private config;
|
|
14
|
-
constructor(config:
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
calculateBatch(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
resolveModel(modelVersion: string): string | null;
|
|
31
|
-
/**
|
|
32
|
-
* Get the fixed credit cost for a named batch job, as a `Decimal`.
|
|
33
|
-
* Returns `null` for an unknown job (L3 parity with Python). The amount is
|
|
34
|
-
* NOT truncated to an integer.
|
|
35
|
-
*/
|
|
36
|
-
getFixedCost(jobName: string): Decimal | null;
|
|
37
|
-
private buildVariables;
|
|
38
|
-
private calcModel;
|
|
39
|
-
private calcTools;
|
|
40
|
-
private calcSearch;
|
|
41
|
-
private calcCache;
|
|
42
|
-
private calcFixed;
|
|
5
|
+
private readonly config;
|
|
6
|
+
constructor(config: ParsedBursarConfig);
|
|
7
|
+
static fromDict(data: BursarConfigData | Record<string, unknown>): PricingEngine;
|
|
8
|
+
get pricingSchema(): Record<string, unknown>;
|
|
9
|
+
calculate(metrics: UsageMetrics, options?: {
|
|
10
|
+
rateCard?: string;
|
|
11
|
+
} | Record<string, string> | null): CostBreakdown;
|
|
12
|
+
calculateBatch(metrics: UsageMetrics[], options?: {
|
|
13
|
+
rateCard?: string;
|
|
14
|
+
}): CostBreakdown[];
|
|
15
|
+
getRateCardForPlan(planId: string | null | undefined): string | undefined;
|
|
16
|
+
private resolveRateCard;
|
|
17
|
+
private operationPricing;
|
|
18
|
+
private matches;
|
|
19
|
+
private matchesOne;
|
|
20
|
+
private scalarEquals;
|
|
21
|
+
private evaluateCharge;
|
|
43
22
|
}
|
|
44
23
|
//# sourceMappingURL=engine.d.ts.map
|
package/dist/engine.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAIL,KAAK,gBAAgB,EAGrB,KAAK,kBAAkB,EAExB,MAAM,aAAa,CAAC;AAGrB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAMjD,qBAAa,aAAa;IACZ,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,kBAAkB;IAEvD,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,aAAa;IAIhF,IAAI,aAAa,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAE3C;IAED,SAAS,CACP,OAAO,EAAE,YAAY,EACrB,OAAO,GAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAS,GAClE,aAAa;IAiFhB,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,OAAO,GAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAO,GAAG,aAAa,EAAE;IAI7F,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS;IAKzE,OAAO,CAAC,eAAe;IAWvB,OAAO,CAAC,gBAAgB;IAQxB,OAAO,CAAC,OAAO;IAMf,OAAO,CAAC,UAAU;IAiBlB,OAAO,CAAC,YAAY;IAWpB,OAAO,CAAC,cAAc;CA4CvB"}
|
package/dist/engine.js
CHANGED
|
@@ -1,172 +1,196 @@
|
|
|
1
1
|
import Decimal from "decimal.js";
|
|
2
|
-
import { evaluateExpression } from "./expr.js";
|
|
3
|
-
import { loadConfigFromDict } from "./config.js";
|
|
4
2
|
import { makeCostBreakdown } from "./breakdown.js";
|
|
3
|
+
import { canonicalParsedBursarConfigDict, loadConfigFromDict, } from "./config.js";
|
|
5
4
|
import { ConfigError } from "./errors.js";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
*
|
|
9
|
-
* Evaluates pricing expressions against usage metrics to produce cost
|
|
10
|
-
* breakdowns. All money values are exact `Decimal`s — never binary `number`.
|
|
11
|
-
*/
|
|
5
|
+
import { evaluateExpression } from "./expr.js";
|
|
6
|
+
const quantize = (value) => value.toDecimalPlaces(6, Decimal.ROUND_HALF_UP);
|
|
12
7
|
export class PricingEngine {
|
|
13
8
|
config;
|
|
14
9
|
constructor(config) {
|
|
15
10
|
this.config = config;
|
|
16
11
|
}
|
|
17
|
-
/** Load engine from a config dictionary. */
|
|
18
12
|
static fromDict(data) {
|
|
19
13
|
return new PricingEngine(loadConfigFromDict(data));
|
|
20
14
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
15
|
+
get pricingSchema() {
|
|
16
|
+
return canonicalParsedBursarConfigDict(this.config);
|
|
17
|
+
}
|
|
18
|
+
calculate(metrics, options = {}) {
|
|
19
|
+
const pricing = this.config.pricing;
|
|
20
|
+
if (!pricing)
|
|
21
|
+
throw new ConfigError("usage pricing not configured");
|
|
22
|
+
const operation = pricing.operations[metrics.operation];
|
|
23
|
+
if (!operation)
|
|
24
|
+
throw new ConfigError(`unknown usage operation '${metrics.operation}'`);
|
|
25
|
+
const measuresInput = metrics.measures ?? {};
|
|
26
|
+
const dimensionsInput = metrics.dimensions ?? {};
|
|
27
|
+
const unknownMeasures = Object.keys(measuresInput).filter((key) => !operation.measures[key]);
|
|
28
|
+
const unknownDimensions = Object.keys(dimensionsInput).filter((key) => !operation.dimensions[key]);
|
|
29
|
+
if (unknownMeasures.length)
|
|
30
|
+
throw new ConfigError(`operation '${metrics.operation}' received undeclared measures ${unknownMeasures.join(", ")}`);
|
|
31
|
+
if (unknownDimensions.length)
|
|
32
|
+
throw new ConfigError(`operation '${metrics.operation}' received undeclared dimensions ${unknownDimensions.join(", ")}`);
|
|
33
|
+
const dimensions = {};
|
|
34
|
+
for (const [name, definition] of Object.entries(operation.dimensions)) {
|
|
35
|
+
const input = dimensionsInput[name];
|
|
36
|
+
if (input == null) {
|
|
37
|
+
if (definition.required)
|
|
38
|
+
throw new ConfigError(`operation '${metrics.operation}' requires dimension '${name}'`);
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (definition.type === "string") {
|
|
42
|
+
if (typeof input !== "string")
|
|
43
|
+
throw new ConfigError(`dimension '${name}' must be string`);
|
|
44
|
+
dimensions[name] = input;
|
|
45
|
+
}
|
|
46
|
+
else if (definition.type === "boolean") {
|
|
47
|
+
if (typeof input !== "boolean")
|
|
48
|
+
throw new ConfigError(`dimension '${name}' must be boolean`);
|
|
49
|
+
dimensions[name] = input;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
const numeric = new Decimal(input);
|
|
53
|
+
if (!numeric.isFinite())
|
|
54
|
+
throw new ConfigError(`dimension '${name}' must be finite`);
|
|
55
|
+
dimensions[name] = numeric;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const measures = {};
|
|
59
|
+
for (const name of Object.keys(operation.measures)) {
|
|
60
|
+
const value = new Decimal(measuresInput[name] ?? 0);
|
|
61
|
+
if (!value.isFinite() || value.isNegative())
|
|
62
|
+
throw new ConfigError(`usage measure '${name}' must be finite and non-negative`);
|
|
63
|
+
measures[name] = value;
|
|
64
|
+
}
|
|
65
|
+
const requestedRateCard = options != null && "rateCard" in options ? options.rateCard : undefined;
|
|
66
|
+
const cardKey = this.resolveRateCard(requestedRateCard);
|
|
67
|
+
const operationPrice = this.operationPricing(cardKey, metrics.operation);
|
|
68
|
+
const matched = operationPrice.rules.find((rule) => this.matches(rule, dimensions));
|
|
69
|
+
const selected = matched?.charge ??
|
|
70
|
+
(operationPrice.unmatched.action === "charge" ? operationPrice.unmatched.charge : undefined);
|
|
71
|
+
if (!selected)
|
|
72
|
+
throw new ConfigError(`no price rule matched operation '${metrics.operation}' in rate card '${cardKey}'`);
|
|
73
|
+
const value = this.evaluateCharge(selected, measures);
|
|
74
|
+
if (!value.isFinite() || value.isNegative())
|
|
75
|
+
throw new ConfigError(`price charge for '${metrics.operation}' produced a negative or non-finite credit cost`);
|
|
76
|
+
const total = quantize(value);
|
|
31
77
|
return makeCostBreakdown({
|
|
32
|
-
|
|
33
|
-
toolCredits,
|
|
34
|
-
searchCredits,
|
|
35
|
-
cacheSavings,
|
|
36
|
-
fixedCredits,
|
|
78
|
+
operationCredits: total,
|
|
37
79
|
breakdown: {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
80
|
+
operation: metrics.operation,
|
|
81
|
+
rateCard: cardKey,
|
|
82
|
+
chargeType: selected.type,
|
|
83
|
+
measures: Object.fromEntries(Object.entries(measures).map(([key, amount]) => [key, amount.toString()])),
|
|
84
|
+
dimensions: dimensionsInput,
|
|
42
85
|
},
|
|
43
86
|
});
|
|
44
87
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return metricsList.map((m) => this.calculate(m));
|
|
48
|
-
}
|
|
49
|
-
/** Return the pricing config as a typed model. */
|
|
50
|
-
pricingSchema() {
|
|
51
|
-
return {
|
|
52
|
-
models: { ...this.config.models },
|
|
53
|
-
tools: Object.keys(this.config.tools).length > 0 ? { ...this.config.tools } : null,
|
|
54
|
-
search: this.config.search ?? null,
|
|
55
|
-
cache: this.config.cache ?? null,
|
|
56
|
-
fixed: Object.keys(this.config.fixed).length > 0 ? { ...this.config.fixed } : null,
|
|
57
|
-
minBalance: this.config.minBalance,
|
|
58
|
-
plans: this.config.plans ? { ...this.config.plans } : null,
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
/** Minimum balance users must keep. */
|
|
62
|
-
get minBalance() {
|
|
63
|
-
return this.config.minBalance;
|
|
88
|
+
calculateBatch(metrics, options = {}) {
|
|
89
|
+
return metrics.map((item) => this.calculate(item, options));
|
|
64
90
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
/** Check if a model name exists in the pricing config. */
|
|
70
|
-
hasModel(modelName) {
|
|
71
|
-
return Object.prototype.hasOwnProperty.call(this.config.models, modelName);
|
|
72
|
-
}
|
|
73
|
-
/** Resolve a model version string to a pricing config key. */
|
|
74
|
-
resolveModel(modelVersion) {
|
|
75
|
-
if (Object.prototype.hasOwnProperty.call(this.config.models, modelVersion))
|
|
76
|
-
return modelVersion;
|
|
77
|
-
for (const key of Object.keys(this.config.models)) {
|
|
78
|
-
if (key !== "_default" && modelVersion.startsWith(key))
|
|
79
|
-
return key;
|
|
80
|
-
}
|
|
81
|
-
if (Object.prototype.hasOwnProperty.call(this.config.models, "_default"))
|
|
82
|
-
return "_default";
|
|
83
|
-
return null;
|
|
91
|
+
getRateCardForPlan(planId) {
|
|
92
|
+
if (!planId)
|
|
93
|
+
return undefined;
|
|
94
|
+
return this.config.plans[planId]?.rateCard;
|
|
84
95
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
if (Object.prototype.hasOwnProperty.call(this.config.fixed, jobName)) {
|
|
92
|
-
return this.config.fixed[jobName];
|
|
96
|
+
resolveRateCard(requested) {
|
|
97
|
+
const cards = this.config.pricing.rateCards;
|
|
98
|
+
if (requested) {
|
|
99
|
+
if (!cards[requested])
|
|
100
|
+
throw new ConfigError(`unknown rate card '${requested}'`);
|
|
101
|
+
return requested;
|
|
93
102
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
if (
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
if (
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
103
|
+
const keys = Object.keys(cards);
|
|
104
|
+
if (keys.length === 1)
|
|
105
|
+
return keys[0];
|
|
106
|
+
throw new ConfigError("rateCard is required when more than one rate card is configured");
|
|
107
|
+
}
|
|
108
|
+
operationPricing(cardKey, operation) {
|
|
109
|
+
const card = this.config.pricing.rateCards[cardKey];
|
|
110
|
+
if (card.operations[operation])
|
|
111
|
+
return card.operations[operation];
|
|
112
|
+
if (!card.extends)
|
|
113
|
+
throw new ConfigError(`rate card '${cardKey}' has no price for operation '${operation}'`);
|
|
114
|
+
return this.operationPricing(card.extends, operation);
|
|
115
|
+
}
|
|
116
|
+
matches(rule, dimensions) {
|
|
117
|
+
return Object.entries(rule.when).every(([name, matcher]) => this.matchesOne(matcher, dimensions[name]));
|
|
118
|
+
}
|
|
119
|
+
matchesOne(matcher, value) {
|
|
120
|
+
if (value == null)
|
|
121
|
+
return false;
|
|
122
|
+
if (matcher.op === "eq")
|
|
123
|
+
return this.scalarEquals(value, matcher.value);
|
|
124
|
+
if (matcher.op === "in")
|
|
125
|
+
return matcher.values.some((candidate) => this.scalarEquals(value, candidate));
|
|
126
|
+
if (matcher.op === "not_in")
|
|
127
|
+
return !matcher.values.some((candidate) => this.scalarEquals(value, candidate));
|
|
128
|
+
if (matcher.op === "prefix")
|
|
129
|
+
return typeof value === "string" && value.startsWith(matcher.value);
|
|
130
|
+
if (matcher.op !== "range" || !(value instanceof Decimal))
|
|
131
|
+
return false;
|
|
132
|
+
if (matcher.gt && !value.gt(matcher.gt))
|
|
133
|
+
return false;
|
|
134
|
+
if (matcher.gte && !value.gte(matcher.gte))
|
|
135
|
+
return false;
|
|
136
|
+
if (matcher.lt && !value.lt(matcher.lt))
|
|
137
|
+
return false;
|
|
138
|
+
if (matcher.lte && !value.lte(matcher.lte))
|
|
139
|
+
return false;
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
scalarEquals(left, right) {
|
|
143
|
+
if (left instanceof Decimal || right instanceof Decimal) {
|
|
144
|
+
try {
|
|
145
|
+
return new Decimal(left).eq(new Decimal(right));
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
return false;
|
|
139
149
|
}
|
|
140
150
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
if (
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
151
|
+
return left === right;
|
|
152
|
+
}
|
|
153
|
+
evaluateCharge(charge, measures) {
|
|
154
|
+
if (charge.type === "flat")
|
|
155
|
+
return charge.amount;
|
|
156
|
+
if (charge.type === "per_unit")
|
|
157
|
+
return measures[charge.measure].div(charge.unitSize).mul(charge.rate);
|
|
158
|
+
if (charge.type === "package") {
|
|
159
|
+
const packages = measures[charge.measure].div(charge.units);
|
|
160
|
+
const rounded = charge.rounding === "ceil"
|
|
161
|
+
? packages.ceil()
|
|
162
|
+
: charge.rounding === "floor"
|
|
163
|
+
? packages.floor()
|
|
164
|
+
: packages.toDecimalPlaces(0, Decimal.ROUND_HALF_UP);
|
|
165
|
+
return rounded.mul(charge.amount);
|
|
155
166
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
167
|
+
if (charge.type === "graduated") {
|
|
168
|
+
let remaining = measures[charge.measure];
|
|
169
|
+
let previous = new Decimal(0);
|
|
170
|
+
let total = new Decimal(0);
|
|
171
|
+
for (const tier of charge.tiers) {
|
|
172
|
+
const units = tier.upTo == null ? remaining : Decimal.min(remaining, tier.upTo.sub(previous));
|
|
173
|
+
if (units.isPositive()) {
|
|
174
|
+
total = total.add(units.mul(tier.rate));
|
|
175
|
+
remaining = remaining.sub(units);
|
|
176
|
+
}
|
|
177
|
+
if (!remaining.isPositive())
|
|
178
|
+
break;
|
|
179
|
+
if (tier.upTo != null)
|
|
180
|
+
previous = tier.upTo;
|
|
181
|
+
}
|
|
182
|
+
return total;
|
|
161
183
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
Object.prototype.hasOwnProperty.call(this.config.fixed, metrics.fixedJob)) {
|
|
167
|
-
return this.config.fixed[metrics.fixedJob];
|
|
184
|
+
if (charge.type === "volume") {
|
|
185
|
+
const value = measures[charge.measure];
|
|
186
|
+
const tier = charge.tiers.find((candidate) => candidate.upTo == null || value.lte(candidate.upTo));
|
|
187
|
+
return value.mul((tier ?? charge.tiers.at(-1)).rate);
|
|
168
188
|
}
|
|
169
|
-
|
|
189
|
+
if (charge.type === "expression")
|
|
190
|
+
return evaluateExpression(charge.formula, measures);
|
|
191
|
+
if (charge.type === "sum")
|
|
192
|
+
return Decimal.sum(...charge.components.map((component) => this.evaluateCharge(component, measures)));
|
|
193
|
+
throw new ConfigError(`unsupported charge type '${String(charge.type)}'`);
|
|
170
194
|
}
|
|
171
195
|
}
|
|
172
196
|
//# sourceMappingURL=engine.js.map
|