@zonastery/bursar 0.0.2 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +118 -333
- package/dist/billing/auto-recharge-port.d.ts +27 -0
- package/dist/billing/auto-recharge-port.d.ts.map +1 -0
- package/dist/billing/auto-recharge-port.js +2 -0
- package/dist/billing/auto-recharge-port.js.map +1 -0
- package/dist/billing/auto-recharge-service.d.ts +43 -0
- package/dist/billing/auto-recharge-service.d.ts.map +1 -0
- package/dist/billing/auto-recharge-service.js +218 -0
- package/dist/billing/auto-recharge-service.js.map +1 -0
- package/dist/billing/billing-service.d.ts +71 -0
- package/dist/billing/billing-service.d.ts.map +1 -0
- package/dist/billing/billing-service.js +172 -0
- package/dist/billing/billing-service.js.map +1 -0
- package/dist/billing/billing-store.d.ts +45 -13
- package/dist/billing/billing-store.d.ts.map +1 -1
- package/dist/billing/billing-store.js.map +1 -1
- package/dist/billing/contracts.d.ts +149 -0
- package/dist/billing/contracts.d.ts.map +1 -0
- package/dist/billing/contracts.js +2 -0
- package/dist/billing/contracts.js.map +1 -0
- package/dist/billing/event-handlers.d.ts +57 -0
- package/dist/billing/event-handlers.d.ts.map +1 -0
- package/dist/billing/event-handlers.js +684 -0
- package/dist/billing/event-handlers.js.map +1 -0
- package/dist/billing/event-processor.d.ts +20 -0
- package/dist/billing/event-processor.d.ts.map +1 -0
- package/dist/billing/event-processor.js +131 -0
- package/dist/billing/event-processor.js.map +1 -0
- package/dist/billing/financial-event-handlers.d.ts +26 -0
- package/dist/billing/financial-event-handlers.d.ts.map +1 -0
- package/dist/billing/financial-event-handlers.js +241 -0
- package/dist/billing/financial-event-handlers.js.map +1 -0
- package/dist/billing/index.d.ts +9 -5
- package/dist/billing/index.d.ts.map +1 -1
- package/dist/billing/index.js +4 -4
- package/dist/billing/index.js.map +1 -1
- package/dist/billing/management.d.ts +59 -0
- package/dist/billing/management.d.ts.map +1 -0
- package/dist/billing/management.js +113 -0
- package/dist/billing/management.js.map +1 -0
- package/dist/billing/policy-window.d.ts +24 -0
- package/dist/billing/policy-window.d.ts.map +1 -0
- package/dist/billing/policy-window.js +88 -0
- package/dist/billing/policy-window.js.map +1 -0
- package/dist/billing/postgres/repositories/auto-recharge.d.ts +32 -0
- package/dist/billing/postgres/repositories/auto-recharge.d.ts.map +1 -0
- package/dist/billing/postgres/repositories/auto-recharge.js +180 -0
- package/dist/billing/postgres/repositories/auto-recharge.js.map +1 -0
- package/dist/billing/postgres/repositories/customer.d.ts +12 -0
- package/dist/billing/postgres/repositories/customer.d.ts.map +1 -0
- package/dist/billing/postgres/repositories/customer.js +33 -0
- package/dist/billing/postgres/repositories/customer.js.map +1 -0
- package/dist/billing/postgres/repositories/dispute.d.ts +7 -0
- package/dist/billing/postgres/repositories/dispute.d.ts.map +1 -0
- package/dist/billing/postgres/repositories/dispute.js +18 -0
- package/dist/billing/postgres/repositories/dispute.js.map +1 -0
- package/dist/billing/postgres/repositories/event.d.ts +21 -0
- package/dist/billing/postgres/repositories/event.d.ts.map +1 -0
- package/dist/billing/postgres/repositories/event.js +45 -0
- package/dist/billing/postgres/repositories/event.js.map +1 -0
- package/dist/billing/postgres/repositories/invoice.d.ts +9 -0
- package/dist/billing/postgres/repositories/invoice.d.ts.map +1 -0
- package/dist/billing/postgres/repositories/invoice.js +36 -0
- package/dist/billing/postgres/repositories/invoice.js.map +1 -0
- package/dist/billing/postgres/repositories/offer.d.ts +26 -0
- package/dist/billing/postgres/repositories/offer.d.ts.map +1 -0
- package/dist/billing/postgres/repositories/offer.js +73 -0
- package/dist/billing/postgres/repositories/offer.js.map +1 -0
- package/dist/billing/postgres/repositories/payment.d.ts +32 -0
- package/dist/billing/postgres/repositories/payment.d.ts.map +1 -0
- package/dist/billing/postgres/repositories/payment.js +78 -0
- package/dist/billing/postgres/repositories/payment.js.map +1 -0
- package/dist/billing/postgres/repositories/preferences.d.ts +15 -0
- package/dist/billing/postgres/repositories/preferences.d.ts.map +1 -0
- package/dist/billing/postgres/repositories/preferences.js +23 -0
- package/dist/billing/postgres/repositories/preferences.js.map +1 -0
- package/dist/billing/postgres/repositories/refund.d.ts +7 -0
- package/dist/billing/postgres/repositories/refund.d.ts.map +1 -0
- package/dist/billing/postgres/repositories/refund.js +32 -0
- package/dist/billing/postgres/repositories/refund.js.map +1 -0
- package/dist/billing/postgres/repositories/subscription.d.ts +46 -0
- package/dist/billing/postgres/repositories/subscription.d.ts.map +1 -0
- package/dist/billing/postgres/repositories/subscription.js +187 -0
- package/dist/billing/postgres/repositories/subscription.js.map +1 -0
- package/dist/billing/postgres/repositories/topup.d.ts +27 -0
- package/dist/billing/postgres/repositories/topup.d.ts.map +1 -0
- package/dist/billing/postgres/repositories/topup.js +51 -0
- package/dist/billing/postgres/repositories/topup.js.map +1 -0
- package/dist/billing/postgres/store.d.ts +89 -0
- package/dist/billing/postgres/store.d.ts.map +1 -0
- package/dist/billing/postgres/store.js +542 -0
- package/dist/billing/postgres/store.js.map +1 -0
- package/dist/billing/service-types.d.ts +37 -0
- package/dist/billing/service-types.d.ts.map +1 -0
- package/dist/billing/service-types.js +2 -0
- package/dist/billing/service-types.js.map +1 -0
- package/dist/billing/types/auto-recharge.d.ts +56 -0
- package/dist/billing/types/auto-recharge.d.ts.map +1 -0
- package/dist/billing/types/auto-recharge.js +2 -0
- package/dist/billing/types/auto-recharge.js.map +1 -0
- package/dist/billing/types/catalog.d.ts +47 -0
- package/dist/billing/types/catalog.d.ts.map +1 -0
- package/dist/billing/types/catalog.js +2 -0
- package/dist/billing/types/catalog.js.map +1 -0
- package/dist/billing/types/common.d.ts +16 -0
- package/dist/billing/types/common.d.ts.map +1 -0
- package/dist/billing/types/common.js +2 -0
- package/dist/billing/types/common.js.map +1 -0
- package/dist/billing/types/documents.d.ts +39 -0
- package/dist/billing/types/documents.d.ts.map +1 -0
- package/dist/billing/types/documents.js +2 -0
- package/dist/billing/types/documents.js.map +1 -0
- package/dist/billing/types/events.d.ts +75 -0
- package/dist/billing/types/events.d.ts.map +1 -0
- package/dist/billing/types/events.js +38 -0
- package/dist/billing/types/events.js.map +1 -0
- package/dist/billing/types/index.d.ts +8 -0
- package/dist/billing/types/index.d.ts.map +1 -0
- package/dist/billing/types/index.js +8 -0
- package/dist/billing/types/index.js.map +1 -0
- package/dist/billing/types/preferences.d.ts +13 -0
- package/dist/billing/types/preferences.d.ts.map +1 -0
- package/dist/billing/types/preferences.js +2 -0
- package/dist/billing/types/preferences.js.map +1 -0
- package/dist/billing/types/subscriptions.d.ts +97 -0
- package/dist/billing/types/subscriptions.d.ts.map +1 -0
- package/dist/billing/types/subscriptions.js +12 -0
- package/dist/billing/types/subscriptions.js.map +1 -0
- package/dist/breakdown.d.ts +3 -1
- package/dist/breakdown.d.ts.map +1 -1
- package/dist/breakdown.js +4 -1
- package/dist/breakdown.js.map +1 -1
- package/dist/browser.d.ts +8 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +7 -0
- package/dist/browser.js.map +1 -0
- package/dist/bursar.d.ts +84 -0
- package/dist/bursar.d.ts.map +1 -0
- package/dist/bursar.js +137 -0
- package/dist/bursar.js.map +1 -0
- package/dist/catalog.d.ts +62 -0
- package/dist/catalog.d.ts.map +1 -0
- package/dist/catalog.js +96 -0
- package/dist/catalog.js.map +1 -0
- package/dist/commerce/errors.d.ts +68 -0
- package/dist/commerce/errors.d.ts.map +1 -0
- package/dist/commerce/errors.js +105 -0
- package/dist/commerce/errors.js.map +1 -0
- package/dist/commerce/index.d.ts +6 -0
- package/dist/commerce/index.d.ts.map +1 -0
- package/dist/commerce/index.js +6 -0
- package/dist/commerce/index.js.map +1 -0
- package/dist/commerce/plan-change.d.ts +10 -0
- package/dist/commerce/plan-change.d.ts.map +1 -0
- package/dist/commerce/plan-change.js +42 -0
- package/dist/commerce/plan-change.js.map +1 -0
- package/dist/commerce/provider-registry.d.ts +18 -0
- package/dist/commerce/provider-registry.d.ts.map +1 -0
- package/dist/commerce/provider-registry.js +70 -0
- package/dist/commerce/provider-registry.js.map +1 -0
- package/dist/commerce/service.d.ts +73 -0
- package/dist/commerce/service.d.ts.map +1 -0
- package/dist/commerce/service.js +1016 -0
- package/dist/commerce/service.js.map +1 -0
- package/dist/commerce/types.d.ts +225 -0
- package/dist/commerce/types.d.ts.map +1 -0
- package/dist/commerce/types.js.map +1 -0
- package/dist/config/parse-access.d.ts +6 -0
- package/dist/config/parse-access.d.ts.map +1 -0
- package/dist/config/parse-access.js +72 -0
- package/dist/config/parse-access.js.map +1 -0
- package/dist/config/parse-commerce.d.ts +3 -0
- package/dist/config/parse-commerce.d.ts.map +1 -0
- package/dist/config/parse-commerce.js +236 -0
- package/dist/config/parse-commerce.js.map +1 -0
- package/dist/config/parse-credits.d.ts +3 -0
- package/dist/config/parse-credits.d.ts.map +1 -0
- package/dist/config/parse-credits.js +99 -0
- package/dist/config/parse-credits.js.map +1 -0
- package/dist/config/parse-plans.d.ts +5 -0
- package/dist/config/parse-plans.d.ts.map +1 -0
- package/dist/config/parse-plans.js +142 -0
- package/dist/config/parse-plans.js.map +1 -0
- package/dist/config/parse-pricing.d.ts +4 -0
- package/dist/config/parse-pricing.d.ts.map +1 -0
- package/dist/config/parse-pricing.js +252 -0
- package/dist/config/parse-pricing.js.map +1 -0
- package/dist/config/parse-utils.d.ts +18 -0
- package/dist/config/parse-utils.d.ts.map +1 -0
- package/dist/config/parse-utils.js +118 -0
- package/dist/config/parse-utils.js.map +1 -0
- package/dist/config/types.d.ts +340 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/config/types.js +2 -0
- package/dist/config/types.js.map +1 -0
- package/dist/config.d.ts +12 -23
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +141 -377
- package/dist/config.js.map +1 -1
- package/dist/{stores → credits}/events.d.ts +6 -6
- package/dist/credits/events.d.ts.map +1 -0
- package/dist/{stores → credits}/events.js +5 -5
- package/dist/credits/events.js.map +1 -0
- package/dist/credits/lease-workflow.d.ts +90 -0
- package/dist/credits/lease-workflow.d.ts.map +1 -0
- package/dist/credits/lease-workflow.js +378 -0
- package/dist/credits/lease-workflow.js.map +1 -0
- package/dist/credits/low-balance-monitor.d.ts +26 -0
- package/dist/credits/low-balance-monitor.d.ts.map +1 -0
- package/dist/credits/low-balance-monitor.js +110 -0
- package/dist/credits/low-balance-monitor.js.map +1 -0
- package/dist/credits/postgres/repositories/analytics.d.ts +81 -0
- package/dist/credits/postgres/repositories/analytics.d.ts.map +1 -0
- package/dist/credits/postgres/repositories/analytics.js +153 -0
- package/dist/credits/postgres/repositories/analytics.js.map +1 -0
- package/dist/credits/postgres/repositories/balance.d.ts +66 -0
- package/dist/credits/postgres/repositories/balance.d.ts.map +1 -0
- package/dist/credits/postgres/repositories/balance.js +139 -0
- package/dist/credits/postgres/repositories/balance.js.map +1 -0
- package/dist/credits/postgres/repositories/bucket.d.ts +25 -0
- package/dist/credits/postgres/repositories/bucket.d.ts.map +1 -0
- package/dist/credits/postgres/repositories/bucket.js +52 -0
- package/dist/credits/postgres/repositories/bucket.js.map +1 -0
- package/dist/credits/postgres/repositories/deduction.d.ts +64 -0
- package/dist/credits/postgres/repositories/deduction.d.ts.map +1 -0
- package/dist/credits/postgres/repositories/deduction.js +154 -0
- package/dist/credits/postgres/repositories/deduction.js.map +1 -0
- package/dist/credits/postgres/repositories/lease.d.ts +69 -0
- package/dist/credits/postgres/repositories/lease.d.ts.map +1 -0
- package/dist/credits/postgres/repositories/lease.js +148 -0
- package/dist/credits/postgres/repositories/lease.js.map +1 -0
- package/dist/credits/postgres/repositories/plan.d.ts +110 -0
- package/dist/credits/postgres/repositories/plan.d.ts.map +1 -0
- package/dist/credits/postgres/repositories/plan.js +194 -0
- package/dist/credits/postgres/repositories/plan.js.map +1 -0
- package/dist/credits/postgres/repositories/pricing.d.ts +28 -0
- package/dist/credits/postgres/repositories/pricing.d.ts.map +1 -0
- package/dist/credits/postgres/repositories/pricing.js +76 -0
- package/dist/credits/postgres/repositories/pricing.js.map +1 -0
- package/dist/credits/postgres/repositories/team.d.ts +63 -0
- package/dist/credits/postgres/repositories/team.d.ts.map +1 -0
- package/dist/credits/postgres/repositories/team.js +120 -0
- package/dist/credits/postgres/repositories/team.js.map +1 -0
- package/dist/credits/postgres/store.d.ts +89 -0
- package/dist/credits/postgres/store.d.ts.map +1 -0
- package/dist/credits/postgres/store.js +838 -0
- package/dist/credits/postgres/store.js.map +1 -0
- package/dist/credits/postgres/value-mappers.d.ts +17 -0
- package/dist/credits/postgres/value-mappers.d.ts.map +1 -0
- package/dist/credits/postgres/value-mappers.js +102 -0
- package/dist/credits/postgres/value-mappers.js.map +1 -0
- package/dist/credits/pricing-runtime.d.ts +35 -0
- package/dist/credits/pricing-runtime.d.ts.map +1 -0
- package/dist/credits/pricing-runtime.js +141 -0
- package/dist/credits/pricing-runtime.js.map +1 -0
- package/dist/credits/queries.d.ts +33 -0
- package/dist/credits/queries.d.ts.map +1 -0
- package/dist/credits/queries.js +71 -0
- package/dist/credits/queries.js.map +1 -0
- package/dist/credits/service-errors.d.ts +4 -0
- package/dist/credits/service-errors.d.ts.map +1 -0
- package/dist/credits/service-errors.js +57 -0
- package/dist/credits/service-errors.js.map +1 -0
- package/dist/credits/service-types.d.ts +122 -0
- package/dist/credits/service-types.d.ts.map +1 -0
- package/dist/credits/service-types.js +2 -0
- package/dist/credits/service-types.js.map +1 -0
- package/dist/credits/service.d.ts +220 -0
- package/dist/credits/service.d.ts.map +1 -0
- package/dist/credits/service.js +640 -0
- package/dist/credits/service.js.map +1 -0
- package/dist/credits/store.d.ts +172 -0
- package/dist/credits/store.d.ts.map +1 -0
- package/dist/{stores/credit-store.js → credits/store.js} +27 -43
- package/dist/credits/store.js.map +1 -0
- package/dist/credits/types/account.d.ts +82 -0
- package/dist/credits/types/account.d.ts.map +1 -0
- package/dist/credits/types/account.js +2 -0
- package/dist/credits/types/account.js.map +1 -0
- package/dist/credits/types/admission.d.ts +39 -0
- package/dist/credits/types/admission.d.ts.map +1 -0
- package/dist/credits/types/admission.js +2 -0
- package/dist/credits/types/admission.js.map +1 -0
- package/dist/credits/types/analytics.d.ts +52 -0
- package/dist/credits/types/analytics.d.ts.map +1 -0
- package/dist/credits/types/analytics.js +2 -0
- package/dist/credits/types/analytics.js.map +1 -0
- package/dist/credits/types/catalog.d.ts +71 -0
- package/dist/credits/types/catalog.d.ts.map +1 -0
- package/dist/credits/types/catalog.js +2 -0
- package/dist/credits/types/catalog.js.map +1 -0
- package/dist/credits/types/grants.d.ts +24 -0
- package/dist/credits/types/grants.d.ts.map +1 -0
- package/dist/credits/types/grants.js +2 -0
- package/dist/credits/types/grants.js.map +1 -0
- package/dist/credits/types/index.d.ts +9 -0
- package/dist/credits/types/index.d.ts.map +1 -0
- package/dist/credits/types/index.js +2 -0
- package/dist/credits/types/index.js.map +1 -0
- package/dist/credits/types/ledger.d.ts +87 -0
- package/dist/credits/types/ledger.d.ts.map +1 -0
- package/dist/credits/types/ledger.js +2 -0
- package/dist/credits/types/ledger.js.map +1 -0
- package/dist/credits/types/quotas.d.ts +40 -0
- package/dist/credits/types/quotas.d.ts.map +1 -0
- package/dist/credits/types/quotas.js +2 -0
- package/dist/credits/types/quotas.js.map +1 -0
- package/dist/credits/types/teams.d.ts +44 -0
- package/dist/credits/types/teams.d.ts.map +1 -0
- package/dist/credits/types/teams.js +2 -0
- package/dist/credits/types/teams.js.map +1 -0
- package/dist/engine.d.ts +18 -39
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +169 -145
- package/dist/engine.js.map +1 -1
- package/dist/errors.d.ts +133 -25
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +173 -24
- package/dist/errors.js.map +1 -1
- package/dist/expr/ast.d.ts +46 -0
- package/dist/expr/ast.d.ts.map +1 -0
- package/dist/expr/ast.js +18 -0
- package/dist/expr/ast.js.map +1 -0
- package/dist/expr/evaluator.d.ts +4 -0
- package/dist/expr/evaluator.d.ts.map +1 -0
- package/dist/expr/evaluator.js +144 -0
- package/dist/expr/evaluator.js.map +1 -0
- package/dist/expr/language.d.ts +5 -0
- package/dist/expr/language.d.ts.map +1 -0
- package/dist/expr/language.js +73 -0
- package/dist/expr/language.js.map +1 -0
- package/dist/expr/parser.d.ts +24 -0
- package/dist/expr/parser.d.ts.map +1 -0
- package/dist/expr/parser.js +175 -0
- package/dist/expr/parser.js.map +1 -0
- package/dist/expr/tokenizer.d.ts +7 -0
- package/dist/expr/tokenizer.d.ts.map +1 -0
- package/dist/expr/tokenizer.js +85 -0
- package/dist/expr/tokenizer.js.map +1 -0
- package/dist/expr.d.ts +7 -58
- package/dist/expr.d.ts.map +1 -1
- package/dist/expr.js +41 -640
- package/dist/expr.js.map +1 -1
- package/dist/generated/pricing-config.schema.json +2792 -0
- package/dist/generated/pricing-config.types.d.ts +685 -0
- package/dist/generated/pricing-config.types.d.ts.map +1 -0
- package/dist/generated/pricing-config.types.js +8 -0
- package/dist/generated/pricing-config.types.js.map +1 -0
- package/dist/index.d.ts +23 -17
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -10
- package/dist/index.js.map +1 -1
- package/dist/load-pricing-file.d.ts.map +1 -1
- package/dist/load-pricing-file.js +8 -4
- package/dist/load-pricing-file.js.map +1 -1
- package/dist/metrics.d.ts +6 -16
- package/dist/metrics.d.ts.map +1 -1
- package/dist/metrics.js.map +1 -1
- package/dist/node.d.ts +9 -2
- package/dist/node.d.ts.map +1 -1
- package/dist/node.js +6 -2
- package/dist/node.js.map +1 -1
- package/dist/providers/_shared.d.ts +9 -0
- package/dist/providers/_shared.d.ts.map +1 -0
- package/dist/providers/_shared.js +52 -0
- package/dist/providers/_shared.js.map +1 -0
- package/dist/providers/dodo/client-contract.d.ts +106 -0
- package/dist/providers/dodo/client-contract.d.ts.map +1 -0
- package/dist/providers/dodo/client-contract.js +2 -0
- package/dist/providers/dodo/client-contract.js.map +1 -0
- package/dist/providers/dodo/event-mapper.d.ts +5 -3
- package/dist/providers/dodo/event-mapper.d.ts.map +1 -1
- package/dist/providers/dodo/event-mapper.js +213 -38
- package/dist/providers/dodo/event-mapper.js.map +1 -1
- package/dist/providers/dodo/index.d.ts +1 -0
- package/dist/providers/dodo/index.d.ts.map +1 -1
- package/dist/providers/dodo/index.js.map +1 -1
- package/dist/providers/dodo/provider.d.ts +24 -14
- package/dist/providers/dodo/provider.d.ts.map +1 -1
- package/dist/providers/dodo/provider.js +249 -31
- package/dist/providers/dodo/provider.js.map +1 -1
- package/dist/providers/index.d.ts +3 -1
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js +1 -0
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/mock/index.js.map +1 -1
- package/dist/providers/mock/provider.d.ts +14 -10
- package/dist/providers/mock/provider.d.ts.map +1 -1
- package/dist/providers/mock/provider.js +78 -10
- package/dist/providers/mock/provider.js.map +1 -1
- package/dist/providers/stripe/event-mapper.d.ts +3 -3
- package/dist/providers/stripe/event-mapper.d.ts.map +1 -1
- package/dist/providers/stripe/event-mapper.js +139 -30
- package/dist/providers/stripe/event-mapper.js.map +1 -1
- package/dist/providers/stripe/index.js.map +1 -1
- package/dist/providers/stripe/provider.d.ts +21 -12
- package/dist/providers/stripe/provider.d.ts.map +1 -1
- package/dist/providers/stripe/provider.js +175 -17
- package/dist/providers/stripe/provider.js.map +1 -1
- package/dist/providers/types.d.ts +128 -32
- package/dist/providers/types.d.ts.map +1 -1
- package/dist/providers/types.js +17 -1
- package/dist/providers/types.js.map +1 -1
- package/dist/retry.d.ts +35 -0
- package/dist/retry.d.ts.map +1 -0
- package/dist/retry.js +70 -0
- package/dist/retry.js.map +1 -0
- package/dist/shared/diagnostics.d.ts +7 -0
- package/dist/shared/diagnostics.d.ts.map +1 -0
- package/dist/shared/diagnostics.js +18 -0
- package/dist/shared/diagnostics.js.map +1 -0
- package/dist/shared/logger.d.ts +10 -0
- package/dist/shared/logger.d.ts.map +1 -0
- package/dist/shared/logger.js +15 -0
- package/dist/shared/logger.js.map +1 -0
- package/dist/shared/postgres-client.d.ts +84 -0
- package/dist/shared/postgres-client.d.ts.map +1 -0
- package/dist/shared/postgres-client.js +337 -0
- package/dist/shared/postgres-client.js.map +1 -0
- package/dist/shared/postgres-errors.d.ts +11 -0
- package/dist/shared/postgres-errors.d.ts.map +1 -0
- package/dist/shared/postgres-errors.js +105 -0
- package/dist/shared/postgres-errors.js.map +1 -0
- package/dist/shared/postgres-types.d.ts +7 -0
- package/dist/shared/postgres-types.d.ts.map +1 -0
- package/dist/shared/postgres-types.js +2 -0
- package/dist/shared/postgres-types.js.map +1 -0
- package/dist/shared/postgres-validation.d.ts +8 -0
- package/dist/shared/postgres-validation.d.ts.map +1 -0
- package/dist/shared/postgres-validation.js +40 -0
- package/dist/shared/postgres-validation.js.map +1 -0
- package/dist/storage/adapters/clickhouse.d.ts +61 -0
- package/dist/storage/adapters/clickhouse.d.ts.map +1 -0
- package/dist/storage/adapters/clickhouse.js +347 -0
- package/dist/storage/adapters/clickhouse.js.map +1 -0
- package/dist/storage/adapters/s3.d.ts +35 -0
- package/dist/storage/adapters/s3.d.ts.map +1 -0
- package/dist/storage/adapters/s3.js +100 -0
- package/dist/storage/adapters/s3.js.map +1 -0
- package/dist/storage/outbox-worker.d.ts +41 -0
- package/dist/storage/outbox-worker.d.ts.map +1 -0
- package/dist/storage/outbox-worker.js +146 -0
- package/dist/storage/outbox-worker.js.map +1 -0
- package/dist/storage/ports.d.ts +78 -0
- package/dist/storage/ports.d.ts.map +1 -0
- package/dist/storage/ports.js +2 -0
- package/dist/storage/ports.js.map +1 -0
- package/dist/storage/postgres-repository.d.ts +14 -0
- package/dist/storage/postgres-repository.d.ts.map +1 -0
- package/dist/storage/postgres-repository.js +140 -0
- package/dist/storage/postgres-repository.js.map +1 -0
- package/dist/storage/runtime.d.ts +77 -0
- package/dist/storage/runtime.d.ts.map +1 -0
- package/dist/storage/runtime.js +369 -0
- package/dist/storage/runtime.js.map +1 -0
- package/package.json +43 -21
- package/dist/allowance.d.ts +0 -48
- package/dist/allowance.d.ts.map +0 -1
- package/dist/allowance.js +0 -140
- package/dist/allowance.js.map +0 -1
- package/dist/billing/billing-manager.d.ts +0 -66
- package/dist/billing/billing-manager.d.ts.map +0 -1
- package/dist/billing/billing-manager.js +0 -560
- package/dist/billing/billing-manager.js.map +0 -1
- package/dist/billing/billing-types.d.ts +0 -203
- package/dist/billing/billing-types.d.ts.map +0 -1
- package/dist/billing/billing-types.js +0 -6
- package/dist/billing/billing-types.js.map +0 -1
- package/dist/billing/memory-billing-store.d.ts +0 -37
- package/dist/billing/memory-billing-store.d.ts.map +0 -1
- package/dist/billing/memory-billing-store.js +0 -197
- package/dist/billing/memory-billing-store.js.map +0 -1
- package/dist/billing/postgres-billing-store.d.ts +0 -35
- package/dist/billing/postgres-billing-store.d.ts.map +0 -1
- package/dist/billing/postgres-billing-store.js +0 -274
- package/dist/billing/postgres-billing-store.js.map +0 -1
- package/dist/billing/supabase-billing-store.d.ts +0 -29
- package/dist/billing/supabase-billing-store.d.ts.map +0 -1
- package/dist/billing/supabase-billing-store.js +0 -250
- package/dist/billing/supabase-billing-store.js.map +0 -1
- package/dist/manager.d.ts +0 -444
- package/dist/manager.d.ts.map +0 -1
- package/dist/manager.js +0 -1153
- package/dist/manager.js.map +0 -1
- package/dist/stores/credit-store.d.ts +0 -198
- package/dist/stores/credit-store.d.ts.map +0 -1
- package/dist/stores/credit-store.js.map +0 -1
- package/dist/stores/events.d.ts.map +0 -1
- package/dist/stores/events.js.map +0 -1
- package/dist/stores/memory-store.d.ts +0 -187
- package/dist/stores/memory-store.d.ts.map +0 -1
- package/dist/stores/memory-store.js +0 -1890
- package/dist/stores/memory-store.js.map +0 -1
- package/dist/stores/postgres-store.d.ts +0 -100
- package/dist/stores/postgres-store.d.ts.map +0 -1
- package/dist/stores/postgres-store.js +0 -891
- package/dist/stores/postgres-store.js.map +0 -1
- package/dist/stores/supabase-store.d.ts +0 -87
- package/dist/stores/supabase-store.d.ts.map +0 -1
- package/dist/stores/supabase-store.js +0 -948
- package/dist/stores/supabase-store.js.map +0 -1
- package/dist/types.d.ts +0 -463
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
- /package/dist/{types.js → commerce/types.js} +0 -0
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { validateExpression } from "../expr.js";
|
|
2
|
+
import { asBoolean, asDecimal, asObject, asString, identifier, semanticError, validateIdentifiers, } from "./parse-utils.js";
|
|
3
|
+
function parseMatcherScalar(value, definition, path) {
|
|
4
|
+
if (definition.type === "boolean") {
|
|
5
|
+
if (typeof value !== "boolean")
|
|
6
|
+
semanticError(`${path} matcher values must be booleans`);
|
|
7
|
+
return value;
|
|
8
|
+
}
|
|
9
|
+
if (definition.type === "number") {
|
|
10
|
+
if (typeof value !== "number" && typeof value !== "string") {
|
|
11
|
+
semanticError(`${path} matcher values must be decimal strings or numbers`);
|
|
12
|
+
}
|
|
13
|
+
return asDecimal(value);
|
|
14
|
+
}
|
|
15
|
+
if (typeof value !== "string")
|
|
16
|
+
semanticError(`${path} matcher values must be strings`);
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
function parseMatcher(value, definition, path) {
|
|
20
|
+
const raw = asObject(value);
|
|
21
|
+
switch (raw.op) {
|
|
22
|
+
case "in":
|
|
23
|
+
case "not_in":
|
|
24
|
+
return {
|
|
25
|
+
op: raw.op,
|
|
26
|
+
values: raw.values.map((item) => parseMatcherScalar(item, definition, path)),
|
|
27
|
+
};
|
|
28
|
+
case "prefix":
|
|
29
|
+
if (definition.type !== "string") {
|
|
30
|
+
semanticError(`${path} prefix matcher requires a string dimension`);
|
|
31
|
+
}
|
|
32
|
+
return { op: "prefix", value: asString(raw.value) };
|
|
33
|
+
case "range": {
|
|
34
|
+
if (definition.type !== "number") {
|
|
35
|
+
semanticError(`${path} range matcher requires a number dimension`);
|
|
36
|
+
}
|
|
37
|
+
const parsed = {
|
|
38
|
+
op: "range",
|
|
39
|
+
...(raw.gt == null ? {} : { gt: asDecimal(raw.gt) }),
|
|
40
|
+
...(raw.gte == null ? {} : { gte: asDecimal(raw.gte) }),
|
|
41
|
+
...(raw.lt == null ? {} : { lt: asDecimal(raw.lt) }),
|
|
42
|
+
...(raw.lte == null ? {} : { lte: asDecimal(raw.lte) }),
|
|
43
|
+
};
|
|
44
|
+
if (parsed.gt == null && parsed.gte == null && parsed.lt == null && parsed.lte == null) {
|
|
45
|
+
semanticError(`${path} range matcher requires at least one bound`);
|
|
46
|
+
}
|
|
47
|
+
if (parsed.gt != null && parsed.gte != null) {
|
|
48
|
+
semanticError(`${path} range matcher cannot combine gt and gte`);
|
|
49
|
+
}
|
|
50
|
+
if (parsed.lt != null && parsed.lte != null) {
|
|
51
|
+
semanticError(`${path} range matcher cannot combine lt and lte`);
|
|
52
|
+
}
|
|
53
|
+
const lower = parsed.gt ?? parsed.gte;
|
|
54
|
+
const upper = parsed.lt ?? parsed.lte;
|
|
55
|
+
if (lower != null && upper != null && lower.gte(upper)) {
|
|
56
|
+
semanticError(`${path} range matcher lower bound must be less than upper bound`);
|
|
57
|
+
}
|
|
58
|
+
return parsed;
|
|
59
|
+
}
|
|
60
|
+
default:
|
|
61
|
+
return { op: "eq", value: parseMatcherScalar(raw.value, definition, path) };
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function parseTiers(value) {
|
|
65
|
+
const tiers = value.map((item) => {
|
|
66
|
+
const tier = asObject(item);
|
|
67
|
+
return {
|
|
68
|
+
...(tier.up_to == null ? {} : { upTo: asDecimal(tier.up_to) }),
|
|
69
|
+
rate: asDecimal(tier.rate),
|
|
70
|
+
};
|
|
71
|
+
});
|
|
72
|
+
if (tiers.at(-1)?.upTo != null || tiers.slice(0, -1).some((tier) => tier.upTo == null)) {
|
|
73
|
+
semanticError("graduated and volume tiers must end with exactly one open-ended tier");
|
|
74
|
+
}
|
|
75
|
+
const finite = tiers.flatMap((tier) => (tier.upTo == null ? [] : [tier.upTo]));
|
|
76
|
+
if (finite.some((bound, index) => index > 0 && bound.lte(finite[index - 1]))) {
|
|
77
|
+
semanticError("graduated and volume tier bounds must be strictly increasing");
|
|
78
|
+
}
|
|
79
|
+
return tiers;
|
|
80
|
+
}
|
|
81
|
+
function parseCharge(value) {
|
|
82
|
+
const raw = asObject(value);
|
|
83
|
+
switch (raw.type) {
|
|
84
|
+
case "flat":
|
|
85
|
+
return { type: "flat", amount: asDecimal(raw.amount) };
|
|
86
|
+
case "per_unit":
|
|
87
|
+
return {
|
|
88
|
+
type: "per_unit",
|
|
89
|
+
measure: asString(raw.measure),
|
|
90
|
+
rate: asDecimal(raw.rate),
|
|
91
|
+
unitSize: asDecimal(raw.unit_size ?? 1),
|
|
92
|
+
};
|
|
93
|
+
case "package":
|
|
94
|
+
return {
|
|
95
|
+
type: "package",
|
|
96
|
+
measure: asString(raw.measure),
|
|
97
|
+
units: asDecimal(raw.units),
|
|
98
|
+
amount: asDecimal(raw.amount),
|
|
99
|
+
rounding: (raw.rounding ?? "ceil"),
|
|
100
|
+
};
|
|
101
|
+
case "graduated":
|
|
102
|
+
case "volume":
|
|
103
|
+
return {
|
|
104
|
+
type: raw.type,
|
|
105
|
+
measure: asString(raw.measure),
|
|
106
|
+
tiers: parseTiers(raw.tiers),
|
|
107
|
+
};
|
|
108
|
+
case "expression":
|
|
109
|
+
return { type: "expression", formula: asString(raw.formula) };
|
|
110
|
+
case "sum":
|
|
111
|
+
return { type: "sum", components: raw.components.map(parseCharge) };
|
|
112
|
+
default:
|
|
113
|
+
return semanticError(`unsupported charge type '${asString(raw.type)}'`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
function chargeMeasures(value) {
|
|
117
|
+
if ("measure" in value)
|
|
118
|
+
return new Set([value.measure]);
|
|
119
|
+
if (value.type === "sum") {
|
|
120
|
+
return new Set(value.components.flatMap((component) => [...chargeMeasures(component)]));
|
|
121
|
+
}
|
|
122
|
+
return new Set();
|
|
123
|
+
}
|
|
124
|
+
function expressionCharges(value) {
|
|
125
|
+
if (value.type === "expression")
|
|
126
|
+
return [value];
|
|
127
|
+
if (value.type === "sum")
|
|
128
|
+
return value.components.flatMap(expressionCharges);
|
|
129
|
+
return [];
|
|
130
|
+
}
|
|
131
|
+
function validateCharge(parsed, definition, operationKey) {
|
|
132
|
+
const unknownMeasures = [...chargeMeasures(parsed)].filter((name) => !definition.measures[name]);
|
|
133
|
+
if (unknownMeasures.length) {
|
|
134
|
+
semanticError(`pricing for operation '${operationKey}' references undeclared measures ${unknownMeasures.join(", ")}`);
|
|
135
|
+
}
|
|
136
|
+
for (const expression of expressionCharges(parsed)) {
|
|
137
|
+
validateExpression(expression.formula, new Set(Object.keys(definition.measures)));
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
function validateRateCardInheritance(rateCards) {
|
|
141
|
+
const visiting = new Set();
|
|
142
|
+
const visited = new Set();
|
|
143
|
+
const visit = (key) => {
|
|
144
|
+
if (visiting.has(key))
|
|
145
|
+
semanticError(`pricing rate-card inheritance cycle includes '${key}'`);
|
|
146
|
+
if (visited.has(key))
|
|
147
|
+
return;
|
|
148
|
+
const card = rateCards[key];
|
|
149
|
+
if (!card)
|
|
150
|
+
semanticError(`unknown rate card '${key}'`);
|
|
151
|
+
visiting.add(key);
|
|
152
|
+
if (card.extends)
|
|
153
|
+
visit(card.extends);
|
|
154
|
+
visiting.delete(key);
|
|
155
|
+
visited.add(key);
|
|
156
|
+
};
|
|
157
|
+
Object.keys(rateCards).forEach(visit);
|
|
158
|
+
}
|
|
159
|
+
export function parsePricing(value) {
|
|
160
|
+
const raw = asObject(value);
|
|
161
|
+
const operationsRaw = asObject(raw.operations);
|
|
162
|
+
const cardsRaw = asObject(raw.rate_cards);
|
|
163
|
+
validateIdentifiers(operationsRaw, "pricing.operations");
|
|
164
|
+
validateIdentifiers(cardsRaw, "pricing.rate_cards");
|
|
165
|
+
if (Object.keys(operationsRaw).length === 0) {
|
|
166
|
+
semanticError("pricing.operations must not be empty");
|
|
167
|
+
}
|
|
168
|
+
if (Object.keys(cardsRaw).length === 0) {
|
|
169
|
+
semanticError("pricing.rate_cards must not be empty");
|
|
170
|
+
}
|
|
171
|
+
const operations = {};
|
|
172
|
+
for (const [operationKey, input] of Object.entries(operationsRaw)) {
|
|
173
|
+
const operation = asObject(input);
|
|
174
|
+
const measuresRaw = asObject(operation.measures);
|
|
175
|
+
const dimensionsRaw = asObject(operation.dimensions ?? {});
|
|
176
|
+
validateIdentifiers(measuresRaw, `pricing.operations.${operationKey}.measures`);
|
|
177
|
+
validateIdentifiers(dimensionsRaw, `pricing.operations.${operationKey}.dimensions`);
|
|
178
|
+
if (Object.keys(measuresRaw).length === 0) {
|
|
179
|
+
semanticError(`pricing.operations.${operationKey}.measures must not be empty`);
|
|
180
|
+
}
|
|
181
|
+
const overlap = Object.keys(measuresRaw).filter((key) => Object.prototype.hasOwnProperty.call(dimensionsRaw, key));
|
|
182
|
+
if (overlap.length) {
|
|
183
|
+
semanticError(`operation '${operationKey}' reuses names as measures and dimensions`);
|
|
184
|
+
}
|
|
185
|
+
operations[operationKey] = {
|
|
186
|
+
measures: Object.fromEntries(Object.entries(measuresRaw).map(([key, definition]) => [
|
|
187
|
+
key,
|
|
188
|
+
{ unit: identifier(asString(asObject(definition).unit), `${operationKey}.${key}.unit`) },
|
|
189
|
+
])),
|
|
190
|
+
dimensions: Object.fromEntries(Object.entries(dimensionsRaw).map(([key, definition]) => {
|
|
191
|
+
const item = asObject(definition);
|
|
192
|
+
return [
|
|
193
|
+
key,
|
|
194
|
+
{
|
|
195
|
+
type: item.type,
|
|
196
|
+
required: asBoolean(item.required ?? true),
|
|
197
|
+
},
|
|
198
|
+
];
|
|
199
|
+
})),
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
const rateCards = {};
|
|
203
|
+
for (const [cardKey, input] of Object.entries(cardsRaw)) {
|
|
204
|
+
const rawCard = asObject(input);
|
|
205
|
+
const operationPricesRaw = asObject(rawCard.operations ?? {});
|
|
206
|
+
const operationPrices = {};
|
|
207
|
+
for (const [operationKey, operationInput] of Object.entries(operationPricesRaw)) {
|
|
208
|
+
const definition = operations[operationKey];
|
|
209
|
+
if (!definition) {
|
|
210
|
+
semanticError(`rate card '${cardKey}' references unknown operation '${operationKey}'`);
|
|
211
|
+
}
|
|
212
|
+
const operationPriceRaw = asObject(operationInput);
|
|
213
|
+
const rules = (operationPriceRaw.rules ?? []).map((ruleInput, index) => {
|
|
214
|
+
const ruleRaw = asObject(ruleInput);
|
|
215
|
+
const whenRaw = asObject(ruleRaw.when);
|
|
216
|
+
const unknownDimensions = Object.keys(whenRaw).filter((name) => !definition.dimensions[name]);
|
|
217
|
+
if (unknownDimensions.length) {
|
|
218
|
+
semanticError(`pricing.rate_cards.${cardKey}.operations.${operationKey}.rules[${index}] matches undeclared dimensions ${unknownDimensions.join(", ")}`);
|
|
219
|
+
}
|
|
220
|
+
const parsedCharge = parseCharge(ruleRaw.charge);
|
|
221
|
+
validateCharge(parsedCharge, definition, operationKey);
|
|
222
|
+
return {
|
|
223
|
+
when: Object.fromEntries(Object.entries(whenRaw).map(([key, item]) => [
|
|
224
|
+
key,
|
|
225
|
+
parseMatcher(item, definition.dimensions[key], `pricing.rate_cards.${cardKey}.operations.${operationKey}.rules[${index}].when.${key}`),
|
|
226
|
+
])),
|
|
227
|
+
charge: parsedCharge,
|
|
228
|
+
};
|
|
229
|
+
});
|
|
230
|
+
const unmatchedRaw = asObject(operationPriceRaw.unmatched);
|
|
231
|
+
const unmatched = unmatchedRaw.action === "charge"
|
|
232
|
+
? { action: "charge", charge: parseCharge(unmatchedRaw.charge) }
|
|
233
|
+
: { action: "reject" };
|
|
234
|
+
if (unmatched.action === "charge") {
|
|
235
|
+
validateCharge(unmatched.charge, definition, operationKey);
|
|
236
|
+
}
|
|
237
|
+
operationPrices[operationKey] = { rules, unmatched };
|
|
238
|
+
}
|
|
239
|
+
rateCards[cardKey] = {
|
|
240
|
+
...(rawCard.extends == null ? {} : { extends: asString(rawCard.extends) }),
|
|
241
|
+
operations: operationPrices,
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
validateRateCardInheritance(rateCards);
|
|
245
|
+
return { operations, rateCards };
|
|
246
|
+
}
|
|
247
|
+
export function resolvesOperation(pricing, cardKey, operation) {
|
|
248
|
+
const card = pricing.rateCards[cardKey];
|
|
249
|
+
return (Object.prototype.hasOwnProperty.call(card.operations, operation) ||
|
|
250
|
+
(card.extends != null && resolvesOperation(pricing, card.extends, operation)));
|
|
251
|
+
}
|
|
252
|
+
//# sourceMappingURL=parse-pricing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-pricing.js","sourceRoot":"","sources":["../../src/config/parse-pricing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EACL,SAAS,EACT,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,aAAa,EACb,mBAAmB,GACpB,MAAM,kBAAkB,CAAC;AAa1B,SAAS,kBAAkB,CACzB,KAAc,EACd,UAA+B,EAC/B,IAAY;IAEZ,IAAI,UAAU,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAClC,IAAI,OAAO,KAAK,KAAK,SAAS;YAAE,aAAa,CAAC,GAAG,IAAI,kCAAkC,CAAC,CAAC;QACzF,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,UAAU,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QACjC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC3D,aAAa,CAAC,GAAG,IAAI,oDAAoD,CAAC,CAAC;QAC7E,CAAC;QACD,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC;IAC1B,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,aAAa,CAAC,GAAG,IAAI,iCAAiC,CAAC,CAAC;IACvF,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,YAAY,CACnB,KAAc,EACd,UAA+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AC,OAAO,EAAE,SAAS,CAAC,CAAC,CAC9E,CAAC;AACJ,CAAC","sourcesContent":["import { validateExpression } from \"../expr.js\";\nimport {\n asBoolean,\n asDecimal,\n asObject,\n asString,\n identifier,\n semanticError,\n validateIdentifiers,\n} from \"./parse-utils.js\";\nimport type {\n Charge,\n DimensionDefinition,\n DimensionMatcher,\n GraduatedTier,\n MatcherScalar,\n OperationDefinition,\n OperationPricing,\n PricingConfig,\n RateCard,\n} from \"./types.js\";\n\nfunction parseMatcherScalar(\n value: unknown,\n definition: DimensionDefinition,\n path: string,\n): MatcherScalar {\n if (definition.type === \"boolean\") {\n if (typeof value !== \"boolean\") semanticError(`${path} matcher values must be booleans`);\n return value;\n }\n if (definition.type === \"number\") {\n if (typeof value !== \"number\" && typeof value !== \"string\") {\n semanticError(`${path} matcher values must be decimal strings or numbers`);\n }\n return asDecimal(value);\n }\n if (typeof value !== \"string\") semanticError(`${path} matcher values must be strings`);\n return value;\n}\n\nfunction parseMatcher(\n value: unknown,\n definition: DimensionDefinition,\n path: string,\n): DimensionMatcher {\n const raw = asObject(value);\n switch (raw.op) {\n case \"in\":\n case \"not_in\":\n return {\n op: raw.op,\n values: (raw.values as unknown[]).map((item) => parseMatcherScalar(item, definition, path)),\n };\n case \"prefix\":\n if (definition.type !== \"string\") {\n semanticError(`${path} prefix matcher requires a string dimension`);\n }\n return { op: \"prefix\", value: asString(raw.value) };\n case \"range\": {\n if (definition.type !== \"number\") {\n semanticError(`${path} range matcher requires a number dimension`);\n }\n const parsed = {\n op: \"range\",\n ...(raw.gt == null ? {} : { gt: asDecimal(raw.gt) }),\n ...(raw.gte == null ? {} : { gte: asDecimal(raw.gte) }),\n ...(raw.lt == null ? {} : { lt: asDecimal(raw.lt) }),\n ...(raw.lte == null ? {} : { lte: asDecimal(raw.lte) }),\n } as const;\n if (parsed.gt == null && parsed.gte == null && parsed.lt == null && parsed.lte == null) {\n semanticError(`${path} range matcher requires at least one bound`);\n }\n if (parsed.gt != null && parsed.gte != null) {\n semanticError(`${path} range matcher cannot combine gt and gte`);\n }\n if (parsed.lt != null && parsed.lte != null) {\n semanticError(`${path} range matcher cannot combine lt and lte`);\n }\n const lower = parsed.gt ?? parsed.gte;\n const upper = parsed.lt ?? parsed.lte;\n if (lower != null && upper != null && lower.gte(upper)) {\n semanticError(`${path} range matcher lower bound must be less than upper bound`);\n }\n return parsed;\n }\n default:\n return { op: \"eq\", value: parseMatcherScalar(raw.value, definition, path) };\n }\n}\n\nfunction parseTiers(value: unknown): GraduatedTier[] {\n const tiers = (value as unknown[]).map((item) => {\n const tier = asObject(item);\n return {\n ...(tier.up_to == null ? {} : { upTo: asDecimal(tier.up_to) }),\n rate: asDecimal(tier.rate),\n };\n });\n if (tiers.at(-1)?.upTo != null || tiers.slice(0, -1).some((tier) => tier.upTo == null)) {\n semanticError(\"graduated and volume tiers must end with exactly one open-ended tier\");\n }\n const finite = tiers.flatMap((tier) => (tier.upTo == null ? [] : [tier.upTo]));\n if (finite.some((bound, index) => index > 0 && bound.lte(finite[index - 1]))) {\n semanticError(\"graduated and volume tier bounds must be strictly increasing\");\n }\n return tiers;\n}\n\nfunction parseCharge(value: unknown): Charge {\n const raw = asObject(value);\n switch (raw.type) {\n case \"flat\":\n return { type: \"flat\", amount: asDecimal(raw.amount) };\n case \"per_unit\":\n return {\n type: \"per_unit\",\n measure: asString(raw.measure),\n rate: asDecimal(raw.rate),\n unitSize: asDecimal(raw.unit_size ?? 1),\n };\n case \"package\":\n return {\n type: \"package\",\n measure: asString(raw.measure),\n units: asDecimal(raw.units),\n amount: asDecimal(raw.amount),\n rounding: (raw.rounding ?? \"ceil\") as \"ceil\" | \"floor\" | \"nearest\",\n };\n case \"graduated\":\n case \"volume\":\n return {\n type: raw.type,\n measure: asString(raw.measure),\n tiers: parseTiers(raw.tiers),\n };\n case \"expression\":\n return { type: \"expression\", formula: asString(raw.formula) };\n case \"sum\":\n return { type: \"sum\", components: (raw.components as unknown[]).map(parseCharge) };\n default:\n return semanticError(`unsupported charge type '${asString(raw.type)}'`);\n }\n}\n\nfunction chargeMeasures(value: Charge): Set<string> {\n if (\"measure\" in value) return new Set([value.measure]);\n if (value.type === \"sum\") {\n return new Set(value.components.flatMap((component) => [...chargeMeasures(component)]));\n }\n return new Set();\n}\n\nfunction expressionCharges(value: Charge): Extract<Charge, { type: \"expression\" }>[] {\n if (value.type === \"expression\") return [value];\n if (value.type === \"sum\") return value.components.flatMap(expressionCharges);\n return [];\n}\n\nfunction validateCharge(\n parsed: Charge,\n definition: OperationDefinition,\n operationKey: string,\n): void {\n const unknownMeasures = [...chargeMeasures(parsed)].filter((name) => !definition.measures[name]);\n if (unknownMeasures.length) {\n semanticError(\n `pricing for operation '${operationKey}' references undeclared measures ${unknownMeasures.join(\", \")}`,\n );\n }\n for (const expression of expressionCharges(parsed)) {\n validateExpression(expression.formula, new Set(Object.keys(definition.measures)));\n }\n}\n\nfunction validateRateCardInheritance(rateCards: Record<string, RateCard>): void {\n const visiting = new Set<string>();\n const visited = new Set<string>();\n const visit = (key: string): void => {\n if (visiting.has(key)) semanticError(`pricing rate-card inheritance cycle includes '${key}'`);\n if (visited.has(key)) return;\n const card = rateCards[key];\n if (!card) semanticError(`unknown rate card '${key}'`);\n visiting.add(key);\n if (card.extends) visit(card.extends);\n visiting.delete(key);\n visited.add(key);\n };\n Object.keys(rateCards).forEach(visit);\n}\n\nexport function parsePricing(value: unknown): PricingConfig {\n const raw = asObject(value);\n const operationsRaw = asObject(raw.operations);\n const cardsRaw = asObject(raw.rate_cards);\n validateIdentifiers(operationsRaw, \"pricing.operations\");\n validateIdentifiers(cardsRaw, \"pricing.rate_cards\");\n if (Object.keys(operationsRaw).length === 0) {\n semanticError(\"pricing.operations must not be empty\");\n }\n if (Object.keys(cardsRaw).length === 0) {\n semanticError(\"pricing.rate_cards must not be empty\");\n }\n\n const operations: Record<string, OperationDefinition> = {};\n for (const [operationKey, input] of Object.entries(operationsRaw)) {\n const operation = asObject(input);\n const measuresRaw = asObject(operation.measures);\n const dimensionsRaw = asObject(operation.dimensions ?? {});\n validateIdentifiers(measuresRaw, `pricing.operations.${operationKey}.measures`);\n validateIdentifiers(dimensionsRaw, `pricing.operations.${operationKey}.dimensions`);\n if (Object.keys(measuresRaw).length === 0) {\n semanticError(`pricing.operations.${operationKey}.measures must not be empty`);\n }\n const overlap = Object.keys(measuresRaw).filter((key) =>\n Object.prototype.hasOwnProperty.call(dimensionsRaw, key),\n );\n if (overlap.length) {\n semanticError(`operation '${operationKey}' reuses names as measures and dimensions`);\n }\n operations[operationKey] = {\n measures: Object.fromEntries(\n Object.entries(measuresRaw).map(([key, definition]) => [\n key,\n { unit: identifier(asString(asObject(definition).unit), `${operationKey}.${key}.unit`) },\n ]),\n ),\n dimensions: Object.fromEntries(\n Object.entries(dimensionsRaw).map(([key, definition]) => {\n const item = asObject(definition);\n return [\n key,\n {\n type: item.type as DimensionDefinition[\"type\"],\n required: asBoolean(item.required ?? true),\n },\n ];\n }),\n ),\n };\n }\n\n const rateCards: Record<string, RateCard> = {};\n for (const [cardKey, input] of Object.entries(cardsRaw)) {\n const rawCard = asObject(input);\n const operationPricesRaw = asObject(rawCard.operations ?? {});\n const operationPrices: Record<string, OperationPricing> = {};\n for (const [operationKey, operationInput] of Object.entries(operationPricesRaw)) {\n const definition = operations[operationKey];\n if (!definition) {\n semanticError(`rate card '${cardKey}' references unknown operation '${operationKey}'`);\n }\n const operationPriceRaw = asObject(operationInput);\n const rules = ((operationPriceRaw.rules ?? []) as unknown[]).map((ruleInput, index) => {\n const ruleRaw = asObject(ruleInput);\n const whenRaw = asObject(ruleRaw.when);\n const unknownDimensions = Object.keys(whenRaw).filter(\n (name) => !definition.dimensions[name],\n );\n if (unknownDimensions.length) {\n semanticError(\n `pricing.rate_cards.${cardKey}.operations.${operationKey}.rules[${index}] matches undeclared dimensions ${unknownDimensions.join(\", \")}`,\n );\n }\n const parsedCharge = parseCharge(ruleRaw.charge);\n validateCharge(parsedCharge, definition, operationKey);\n return {\n when: Object.fromEntries(\n Object.entries(whenRaw).map(([key, item]) => [\n key,\n parseMatcher(\n item,\n definition.dimensions[key],\n `pricing.rate_cards.${cardKey}.operations.${operationKey}.rules[${index}].when.${key}`,\n ),\n ]),\n ),\n charge: parsedCharge,\n };\n });\n const unmatchedRaw = asObject(operationPriceRaw.unmatched);\n const unmatched =\n unmatchedRaw.action === \"charge\"\n ? ({ action: \"charge\", charge: parseCharge(unmatchedRaw.charge) } as const)\n : ({ action: \"reject\" } as const);\n if (unmatched.action === \"charge\") {\n validateCharge(unmatched.charge, definition, operationKey);\n }\n operationPrices[operationKey] = { rules, unmatched };\n }\n rateCards[cardKey] = {\n ...(rawCard.extends == null ? {} : { extends: asString(rawCard.extends) }),\n operations: operationPrices,\n };\n }\n\n validateRateCardInheritance(rateCards);\n return { operations, rateCards };\n}\n\nexport function resolvesOperation(\n pricing: PricingConfig,\n cardKey: string,\n operation: string,\n): boolean {\n const card = pricing.rateCards[cardKey];\n return (\n Object.prototype.hasOwnProperty.call(card.operations, operation) ||\n (card.extends != null && resolvesOperation(pricing, card.extends, operation))\n );\n}\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import Decimal from "decimal.js";
|
|
2
|
+
import type { Availability, BillingInterval, Duration, ExpiryPolicy, Window } from "./types.js";
|
|
3
|
+
export type JsonObject = Record<string, unknown>;
|
|
4
|
+
export declare function asObject(value: unknown): JsonObject;
|
|
5
|
+
export declare function semanticError(message: string): never;
|
|
6
|
+
export declare function identifier(value: string, path: string): string;
|
|
7
|
+
export declare function validateIdentifiers(value: JsonObject, path: string): void;
|
|
8
|
+
export declare function validateRegions(values: string[], path: string): void;
|
|
9
|
+
export declare function asDecimal(value: unknown): Decimal;
|
|
10
|
+
export declare function asInteger(value: unknown): number;
|
|
11
|
+
export declare function asString(value: unknown): string;
|
|
12
|
+
export declare function asBoolean(value: unknown): boolean;
|
|
13
|
+
export declare function parseDuration(value: unknown): Duration;
|
|
14
|
+
export declare function parseBillingInterval(value: unknown): BillingInterval;
|
|
15
|
+
export declare function parseWindow(value: unknown, path: string): Window;
|
|
16
|
+
export declare function parseAvailability(value: unknown): Availability;
|
|
17
|
+
export declare function parseExpiry(value: unknown, path: string): ExpiryPolicy;
|
|
18
|
+
//# sourceMappingURL=parse-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-utils.d.ts","sourceRoot":"","sources":["../../src/config/parse-utils.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,YAAY,CAAC;AAGjC,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAKhG,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEjD,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,CAEnD;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,CAEpD;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAG9D;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAEzE;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAOpE;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAEjD;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAEhD;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAE/C;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAEjD;AAYD,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,QAAQ,CAGtD;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,CAMpE;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAkBhE;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,YAAY,CAc9D;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,YAAY,CAqBtE"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import Decimal from "decimal.js";
|
|
2
|
+
import { ConfigError } from "../errors.js";
|
|
3
|
+
const IDENTIFIER = /^[a-z][a-z0-9_]*$/;
|
|
4
|
+
const REGION = /^[A-Z]{2}(?:-[A-Z0-9]{1,3})?$/;
|
|
5
|
+
export function asObject(value) {
|
|
6
|
+
return value;
|
|
7
|
+
}
|
|
8
|
+
export function semanticError(message) {
|
|
9
|
+
throw new ConfigError(message);
|
|
10
|
+
}
|
|
11
|
+
export function identifier(value, path) {
|
|
12
|
+
if (!IDENTIFIER.test(value))
|
|
13
|
+
semanticError(`${path} must be a non-empty snake_case identifier`);
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
export function validateIdentifiers(value, path) {
|
|
17
|
+
for (const key of Object.keys(value))
|
|
18
|
+
identifier(key, `${path}.${key}`);
|
|
19
|
+
}
|
|
20
|
+
export function validateRegions(values, path) {
|
|
21
|
+
if (new Set(values).size !== values.length) {
|
|
22
|
+
semanticError(`${path} must not contain duplicates`);
|
|
23
|
+
}
|
|
24
|
+
if (values.some((value) => !REGION.test(value))) {
|
|
25
|
+
semanticError(`${path} must contain uppercase ISO-style region codes`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export function asDecimal(value) {
|
|
29
|
+
return new Decimal(value);
|
|
30
|
+
}
|
|
31
|
+
export function asInteger(value) {
|
|
32
|
+
return Number(value);
|
|
33
|
+
}
|
|
34
|
+
export function asString(value) {
|
|
35
|
+
return String(value);
|
|
36
|
+
}
|
|
37
|
+
export function asBoolean(value) {
|
|
38
|
+
return Boolean(value);
|
|
39
|
+
}
|
|
40
|
+
function asTimezone(value, path) {
|
|
41
|
+
const candidate = asString(value);
|
|
42
|
+
try {
|
|
43
|
+
new Intl.DateTimeFormat("en-US", { timeZone: candidate }).format();
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
semanticError(`${path} must be a valid IANA timezone`);
|
|
47
|
+
}
|
|
48
|
+
return candidate;
|
|
49
|
+
}
|
|
50
|
+
export function parseDuration(value) {
|
|
51
|
+
const raw = asObject(value);
|
|
52
|
+
return { unit: raw.unit, count: asInteger(raw.count) };
|
|
53
|
+
}
|
|
54
|
+
export function parseBillingInterval(value) {
|
|
55
|
+
const raw = asObject(value);
|
|
56
|
+
return {
|
|
57
|
+
unit: raw.unit,
|
|
58
|
+
count: asInteger(raw.count ?? 1),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
export function parseWindow(value, path) {
|
|
62
|
+
const raw = asObject(value);
|
|
63
|
+
if (raw.type === "rolling") {
|
|
64
|
+
return { type: "rolling", duration: parseDuration(raw.duration) };
|
|
65
|
+
}
|
|
66
|
+
if (raw.type === "plan_assignment") {
|
|
67
|
+
return {
|
|
68
|
+
type: "plan_assignment",
|
|
69
|
+
interval: parseBillingInterval(raw.interval),
|
|
70
|
+
timezone: asTimezone(raw.timezone ?? "UTC", `${path}.timezone`),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
type: "calendar",
|
|
75
|
+
unit: raw.unit,
|
|
76
|
+
count: asInteger(raw.count ?? 1),
|
|
77
|
+
timezone: asTimezone(raw.timezone ?? "UTC", `${path}.timezone`),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
export function parseAvailability(value) {
|
|
81
|
+
const raw = asObject(value);
|
|
82
|
+
const startsAt = raw.starts_at == null ? undefined : asString(raw.starts_at);
|
|
83
|
+
const endsAt = raw.ends_at == null ? undefined : asString(raw.ends_at);
|
|
84
|
+
const regions = (raw.regions ?? []);
|
|
85
|
+
validateRegions(regions, "availability.regions");
|
|
86
|
+
if (startsAt != null && endsAt != null && Date.parse(endsAt) <= Date.parse(startsAt)) {
|
|
87
|
+
semanticError("availability.ends_at must be later than starts_at");
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
...(startsAt == null ? {} : { startsAt }),
|
|
91
|
+
...(endsAt == null ? {} : { endsAt }),
|
|
92
|
+
regions,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
export function parseExpiry(value, path) {
|
|
96
|
+
const raw = asObject(value);
|
|
97
|
+
switch (raw.type) {
|
|
98
|
+
case "after_grant":
|
|
99
|
+
return {
|
|
100
|
+
type: "after_grant",
|
|
101
|
+
interval: parseBillingInterval(raw.interval),
|
|
102
|
+
timezone: asTimezone(raw.timezone ?? "UTC", `${path}.timezone`),
|
|
103
|
+
};
|
|
104
|
+
case "end_of_window": {
|
|
105
|
+
const parsed = parseWindow(raw.window, `${path}.window`);
|
|
106
|
+
if (parsed.type === "rolling")
|
|
107
|
+
semanticError(`${path} cannot use a rolling window`);
|
|
108
|
+
return { type: "end_of_window", window: parsed };
|
|
109
|
+
}
|
|
110
|
+
case "fixed_at":
|
|
111
|
+
return { type: "fixed_at", at: asString(raw.at) };
|
|
112
|
+
case "subscription_end":
|
|
113
|
+
return { type: "subscription_end" };
|
|
114
|
+
default:
|
|
115
|
+
return { type: "never" };
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=parse-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-utils.js","sourceRoot":"","sources":["../../src/config/parse-utils.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,YAAY,CAAC;AAEjC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAG3C,MAAM,UAAU,GAAG,mBAAmB,CAAC;AACvC,MA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Interval, Duration, ExpiryPolicy, Window } from \"./types.js\";\n\nconst IDENTIFIER = /^[a-z][a-z0-9_]*$/;\nconst REGION = /^[A-Z]{2}(?:-[A-Z0-9]{1,3})?$/;\n\nexport type JsonObject = Record<string, unknown>;\n\nexport function asObject(value: unknown): JsonObject {\n return value as JsonObject;\n}\n\nexport function semanticError(message: string): never {\n throw new ConfigError(message);\n}\n\nexport function identifier(value: string, path: string): string {\n if (!IDENTIFIER.test(value)) semanticError(`${path} must be a non-empty snake_case identifier`);\n return value;\n}\n\nexport function validateIdentifiers(value: JsonObject, path: string): void {\n for (const key of Object.keys(value)) identifier(key, `${path}.${key}`);\n}\n\nexport function validateRegions(values: string[], path: string): void {\n if (new Set(values).size !== values.length) {\n semanticError(`${path} must not contain duplicates`);\n }\n if (values.some((value) => !REGION.test(value))) {\n semanticError(`${path} must contain uppercase ISO-style region codes`);\n }\n}\n\nexport function asDecimal(value: unknown): Decimal {\n return new Decimal(value as Decimal.Value);\n}\n\nexport function asInteger(value: unknown): number {\n return Number(value);\n}\n\nexport function asString(value: unknown): string {\n return String(value);\n}\n\nexport function asBoolean(value: unknown): boolean {\n return Boolean(value);\n}\n\nfunction asTimezone(value: unknown, path: string): string {\n const candidate = asString(value);\n try {\n new Intl.DateTimeFormat(\"en-US\", { timeZone: candidate }).format();\n } catch {\n semanticError(`${path} must be a valid IANA timezone`);\n }\n return candidate;\n}\n\nexport function parseDuration(value: unknown): Duration {\n const raw = asObject(value);\n return { unit: raw.unit as Duration[\"unit\"], count: asInteger(raw.count) };\n}\n\nexport function parseBillingInterval(value: unknown): BillingInterval {\n const raw = asObject(value);\n return {\n unit: raw.unit as BillingInterval[\"unit\"],\n count: asInteger(raw.count ?? 1),\n };\n}\n\nexport function parseWindow(value: unknown, path: string): Window {\n const raw = asObject(value);\n if (raw.type === \"rolling\") {\n return { type: \"rolling\", duration: parseDuration(raw.duration) };\n }\n if (raw.type === \"plan_assignment\") {\n return {\n type: \"plan_assignment\",\n interval: parseBillingInterval(raw.interval),\n timezone: asTimezone(raw.timezone ?? \"UTC\", `${path}.timezone`),\n };\n }\n return {\n type: \"calendar\",\n unit: raw.unit as Extract<Window, { type: \"calendar\" }>[\"unit\"],\n count: asInteger(raw.count ?? 1),\n timezone: asTimezone(raw.timezone ?? \"UTC\", `${path}.timezone`),\n };\n}\n\nexport function parseAvailability(value: unknown): Availability {\n const raw = asObject(value);\n const startsAt = raw.starts_at == null ? undefined : asString(raw.starts_at);\n const endsAt = raw.ends_at == null ? undefined : asString(raw.ends_at);\n const regions = (raw.regions ?? []) as string[];\n validateRegions(regions, \"availability.regions\");\n if (startsAt != null && endsAt != null && Date.parse(endsAt) <= Date.parse(startsAt)) {\n semanticError(\"availability.ends_at must be later than starts_at\");\n }\n return {\n ...(startsAt == null ? {} : { startsAt }),\n ...(endsAt == null ? {} : { endsAt }),\n regions,\n };\n}\n\nexport function parseExpiry(value: unknown, path: string): ExpiryPolicy {\n const raw = asObject(value);\n switch (raw.type) {\n case \"after_grant\":\n return {\n type: \"after_grant\",\n interval: parseBillingInterval(raw.interval),\n timezone: asTimezone(raw.timezone ?? \"UTC\", `${path}.timezone`),\n };\n case \"end_of_window\": {\n const parsed = parseWindow(raw.window, `${path}.window`);\n if (parsed.type === \"rolling\") semanticError(`${path} cannot use a rolling window`);\n return { type: \"end_of_window\", window: parsed };\n }\n case \"fixed_at\":\n return { type: \"fixed_at\", at: asString(raw.at) };\n case \"subscription_end\":\n return { type: \"subscription_end\" };\n default:\n return { type: \"never\" };\n }\n}\n"]}
|