@zonastery/bursar 2.1.1 → 2.2.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 +20 -3
- package/dist/billing/auto-recharge-service.d.ts.map +1 -1
- package/dist/billing/auto-recharge-service.js +6 -4
- package/dist/billing/auto-recharge-service.js.map +1 -1
- package/dist/billing/billing-service.d.ts +19 -3
- package/dist/billing/billing-service.d.ts.map +1 -1
- package/dist/billing/billing-service.js +34 -5
- package/dist/billing/billing-service.js.map +1 -1
- package/dist/billing/billing-store.d.ts +12 -6
- package/dist/billing/billing-store.d.ts.map +1 -1
- package/dist/billing/billing-store.js +2 -0
- package/dist/billing/billing-store.js.map +1 -1
- package/dist/billing/contracts.d.ts +20 -3
- package/dist/billing/contracts.d.ts.map +1 -1
- package/dist/billing/contracts.js.map +1 -1
- package/dist/billing/event-handlers.d.ts +1 -0
- package/dist/billing/event-handlers.d.ts.map +1 -1
- package/dist/billing/event-handlers.js +40 -13
- package/dist/billing/event-handlers.js.map +1 -1
- package/dist/billing/event-processor.d.ts +2 -1
- package/dist/billing/event-processor.d.ts.map +1 -1
- package/dist/billing/event-processor.js +82 -16
- package/dist/billing/event-processor.js.map +1 -1
- package/dist/billing/financial-event-handlers.d.ts +2 -0
- package/dist/billing/financial-event-handlers.d.ts.map +1 -1
- package/dist/billing/financial-event-handlers.js +160 -48
- package/dist/billing/financial-event-handlers.js.map +1 -1
- package/dist/billing/index.d.ts +1 -1
- package/dist/billing/index.d.ts.map +1 -1
- package/dist/billing/index.js.map +1 -1
- package/dist/billing/management.d.ts +6 -3
- package/dist/billing/management.d.ts.map +1 -1
- package/dist/billing/management.js +5 -2
- package/dist/billing/management.js.map +1 -1
- package/dist/billing/postgres/repositories/auto-recharge.d.ts +3 -1
- package/dist/billing/postgres/repositories/auto-recharge.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/auto-recharge.js +23 -7
- package/dist/billing/postgres/repositories/auto-recharge.js.map +1 -1
- package/dist/billing/postgres/repositories/invoice.d.ts +3 -2
- package/dist/billing/postgres/repositories/invoice.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/invoice.js +33 -3
- package/dist/billing/postgres/repositories/invoice.js.map +1 -1
- package/dist/billing/postgres/repositories/offer.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/offer.js +2 -1
- package/dist/billing/postgres/repositories/offer.js.map +1 -1
- package/dist/billing/postgres/repositories/payment.d.ts +6 -1
- package/dist/billing/postgres/repositories/payment.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/payment.js +25 -17
- package/dist/billing/postgres/repositories/payment.js.map +1 -1
- package/dist/billing/postgres/repositories/subscription-change.d.ts +1 -0
- package/dist/billing/postgres/repositories/subscription-change.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/subscription-change.js +24 -4
- package/dist/billing/postgres/repositories/subscription-change.js.map +1 -1
- package/dist/billing/postgres/repositories/subscription.d.ts +1 -0
- package/dist/billing/postgres/repositories/subscription.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/subscription.js +40 -43
- package/dist/billing/postgres/repositories/subscription.js.map +1 -1
- package/dist/billing/postgres/repositories/topup.d.ts +6 -1
- package/dist/billing/postgres/repositories/topup.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/topup.js +9 -5
- package/dist/billing/postgres/repositories/topup.js.map +1 -1
- package/dist/billing/postgres/store.d.ts +24 -31
- package/dist/billing/postgres/store.d.ts.map +1 -1
- package/dist/billing/postgres/store.js +110 -113
- package/dist/billing/postgres/store.js.map +1 -1
- package/dist/billing/types/catalog.d.ts +1 -0
- package/dist/billing/types/catalog.d.ts.map +1 -1
- package/dist/billing/types/catalog.js.map +1 -1
- package/dist/billing/types/documents.d.ts +15 -1
- package/dist/billing/types/documents.d.ts.map +1 -1
- package/dist/billing/types/documents.js.map +1 -1
- package/dist/billing/types/events.d.ts +2 -0
- package/dist/billing/types/events.d.ts.map +1 -1
- package/dist/billing/types/events.js +15 -0
- package/dist/billing/types/events.js.map +1 -1
- package/dist/billing/types/subscriptions.d.ts +10 -0
- package/dist/billing/types/subscriptions.d.ts.map +1 -1
- package/dist/billing/types/subscriptions.js.map +1 -1
- package/dist/breakdown.d.ts +2 -24
- package/dist/breakdown.d.ts.map +1 -1
- package/dist/breakdown.js +1 -29
- package/dist/breakdown.js.map +1 -1
- package/dist/bursar.d.ts +5 -17
- package/dist/bursar.d.ts.map +1 -1
- package/dist/bursar.js +26 -44
- package/dist/bursar.js.map +1 -1
- package/dist/cli.js +0 -6
- package/dist/cli.js.map +1 -1
- package/dist/commerce/service.d.ts +1 -0
- package/dist/commerce/service.d.ts.map +1 -1
- package/dist/commerce/service.js +162 -38
- package/dist/commerce/service.js.map +1 -1
- package/dist/commerce/types.d.ts +2 -0
- package/dist/commerce/types.d.ts.map +1 -1
- package/dist/commerce/types.js.map +1 -1
- package/dist/config/normalize.d.ts +3 -1
- package/dist/config/normalize.d.ts.map +1 -1
- package/dist/config/normalize.js +12 -5
- package/dist/config/normalize.js.map +1 -1
- package/dist/config/parse-access.d.ts.map +1 -1
- package/dist/config/parse-access.js +4 -1
- package/dist/config/parse-access.js.map +1 -1
- package/dist/config/parse-commerce.d.ts.map +1 -1
- package/dist/config/parse-commerce.js +32 -17
- package/dist/config/parse-commerce.js.map +1 -1
- package/dist/config/parse-credits.d.ts.map +1 -1
- package/dist/config/parse-credits.js +5 -5
- package/dist/config/parse-credits.js.map +1 -1
- package/dist/config/parse-plans.d.ts.map +1 -1
- package/dist/config/parse-plans.js +13 -9
- package/dist/config/parse-plans.js.map +1 -1
- package/dist/config/parse-pricing.d.ts.map +1 -1
- package/dist/config/parse-pricing.js +7 -5
- package/dist/config/parse-pricing.js.map +1 -1
- package/dist/config/parse-utils.d.ts +2 -0
- package/dist/config/parse-utils.d.ts.map +1 -1
- package/dist/config/parse-utils.js +11 -1
- package/dist/config/parse-utils.js.map +1 -1
- package/dist/config.d.ts +2 -2
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +94 -86
- package/dist/config.js.map +1 -1
- package/dist/credits/amount.d.ts.map +1 -1
- package/dist/credits/amount.js +5 -4
- package/dist/credits/amount.js.map +1 -1
- package/dist/credits/catalog-runtime.d.ts +15 -2
- package/dist/credits/catalog-runtime.d.ts.map +1 -1
- package/dist/credits/catalog-runtime.js +74 -18
- package/dist/credits/catalog-runtime.js.map +1 -1
- package/dist/credits/lease-workflow.d.ts +3 -1
- package/dist/credits/lease-workflow.d.ts.map +1 -1
- package/dist/credits/lease-workflow.js +47 -38
- package/dist/credits/lease-workflow.js.map +1 -1
- package/dist/credits/low-balance-monitor.d.ts +2 -7
- package/dist/credits/low-balance-monitor.d.ts.map +1 -1
- package/dist/credits/low-balance-monitor.js +6 -57
- package/dist/credits/low-balance-monitor.js.map +1 -1
- package/dist/credits/postgres/repositories/analytics.d.ts +3 -3
- package/dist/credits/postgres/repositories/analytics.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/analytics.js +25 -7
- package/dist/credits/postgres/repositories/analytics.js.map +1 -1
- package/dist/credits/postgres/repositories/balance.d.ts +28 -0
- package/dist/credits/postgres/repositories/balance.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/balance.js +33 -14
- package/dist/credits/postgres/repositories/balance.js.map +1 -1
- package/dist/credits/postgres/repositories/bucket.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/bucket.js +2 -2
- package/dist/credits/postgres/repositories/bucket.js.map +1 -1
- package/dist/credits/postgres/repositories/catalog.d.ts +2 -2
- package/dist/credits/postgres/repositories/catalog.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/catalog.js +2 -12
- package/dist/credits/postgres/repositories/catalog.js.map +1 -1
- package/dist/credits/postgres/repositories/deduction.d.ts +2 -0
- package/dist/credits/postgres/repositories/deduction.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/deduction.js +9 -2
- package/dist/credits/postgres/repositories/deduction.js.map +1 -1
- package/dist/credits/postgres/repositories/lease.d.ts +3 -0
- package/dist/credits/postgres/repositories/lease.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/lease.js +46 -12
- package/dist/credits/postgres/repositories/lease.js.map +1 -1
- package/dist/credits/postgres/repositories/plan.d.ts +1 -1
- package/dist/credits/postgres/repositories/plan.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/plan.js +4 -1
- package/dist/credits/postgres/repositories/plan.js.map +1 -1
- package/dist/credits/postgres/repositories/team.d.ts +1 -1
- package/dist/credits/postgres/repositories/team.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/team.js +9 -5
- package/dist/credits/postgres/repositories/team.js.map +1 -1
- package/dist/credits/postgres/store.d.ts +29 -20
- package/dist/credits/postgres/store.d.ts.map +1 -1
- package/dist/credits/postgres/store.js +329 -250
- package/dist/credits/postgres/store.js.map +1 -1
- package/dist/credits/postgres/value-mappers.d.ts.map +1 -1
- package/dist/credits/postgres/value-mappers.js +4 -4
- package/dist/credits/postgres/value-mappers.js.map +1 -1
- package/dist/credits/rated-wire.d.ts +7 -0
- package/dist/credits/rated-wire.d.ts.map +1 -0
- package/dist/credits/rated-wire.js +70 -0
- package/dist/credits/rated-wire.js.map +1 -0
- package/dist/credits/service-errors.d.ts.map +1 -1
- package/dist/credits/service-errors.js +8 -1
- package/dist/credits/service-errors.js.map +1 -1
- package/dist/credits/service-types.d.ts +5 -7
- package/dist/credits/service-types.d.ts.map +1 -1
- package/dist/credits/service-types.js.map +1 -1
- package/dist/credits/service.d.ts +11 -9
- package/dist/credits/service.d.ts.map +1 -1
- package/dist/credits/service.js +156 -138
- package/dist/credits/service.js.map +1 -1
- package/dist/credits/store.d.ts +11 -3
- package/dist/credits/store.d.ts.map +1 -1
- package/dist/credits/store.js +9 -0
- package/dist/credits/store.js.map +1 -1
- package/dist/credits/types/account.d.ts +9 -1
- package/dist/credits/types/account.d.ts.map +1 -1
- package/dist/credits/types/account.js.map +1 -1
- package/dist/credits/types/admission.d.ts +1 -0
- package/dist/credits/types/admission.d.ts.map +1 -1
- package/dist/credits/types/admission.js.map +1 -1
- package/dist/credits/types/grants.d.ts +12 -0
- package/dist/credits/types/grants.d.ts.map +1 -1
- package/dist/credits/types/grants.js.map +1 -1
- package/dist/credits/types/ledger.d.ts +13 -0
- package/dist/credits/types/ledger.d.ts.map +1 -1
- package/dist/credits/types/ledger.js.map +1 -1
- package/dist/credits/types/quotas.d.ts +2 -1
- package/dist/credits/types/quotas.d.ts.map +1 -1
- package/dist/credits/types/quotas.js.map +1 -1
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +51 -34
- package/dist/engine.js.map +1 -1
- package/dist/errors.d.ts +12 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +13 -0
- package/dist/errors.js.map +1 -1
- package/dist/expr/evaluator.d.ts.map +1 -1
- package/dist/expr/evaluator.js +29 -9
- package/dist/expr/evaluator.js.map +1 -1
- package/dist/expr/language.js +1 -1
- package/dist/expr/language.js.map +1 -1
- package/dist/expr.d.ts.map +1 -1
- package/dist/expr.js +5 -6
- package/dist/expr.js.map +1 -1
- package/dist/generated/pricing-config.schema.json +102 -202
- package/dist/generated/pricing-config.types.d.ts +7 -1
- package/dist/generated/pricing-config.types.d.ts.map +1 -1
- package/dist/generated/pricing-config.types.js.map +1 -1
- package/dist/index.d.ts +6 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/load-config-file.d.ts.map +1 -1
- package/dist/load-config-file.js +38 -12
- package/dist/load-config-file.js.map +1 -1
- package/dist/metrics.d.ts +1 -1
- package/dist/metrics.d.ts.map +1 -1
- package/dist/metrics.js.map +1 -1
- package/dist/node.d.ts +1 -1
- package/dist/node.d.ts.map +1 -1
- package/dist/node.js.map +1 -1
- package/dist/pricing-decimal.d.ts +7 -0
- package/dist/pricing-decimal.d.ts.map +1 -0
- package/dist/pricing-decimal.js +43 -0
- package/dist/pricing-decimal.js.map +1 -0
- package/dist/providers/dodo/better-auth-core.d.ts +1 -1
- package/dist/providers/dodo/better-auth-core.d.ts.map +1 -1
- package/dist/providers/dodo/better-auth-core.js +2 -2
- package/dist/providers/dodo/better-auth-core.js.map +1 -1
- package/dist/providers/dodo/better-auth.d.ts.map +1 -1
- package/dist/providers/dodo/better-auth.js +16 -2
- package/dist/providers/dodo/better-auth.js.map +1 -1
- package/dist/providers/dodo/event-mapper.d.ts +1 -1
- package/dist/providers/dodo/event-mapper.d.ts.map +1 -1
- package/dist/providers/dodo/event-mapper.js +120 -18
- package/dist/providers/dodo/event-mapper.js.map +1 -1
- package/dist/providers/dodo/nextjs-core.d.ts +1 -1
- package/dist/providers/dodo/nextjs-core.d.ts.map +1 -1
- package/dist/providers/dodo/nextjs-core.js +2 -2
- package/dist/providers/dodo/nextjs-core.js.map +1 -1
- package/dist/providers/dodo/nextjs.d.ts.map +1 -1
- package/dist/providers/dodo/nextjs.js +16 -6
- package/dist/providers/dodo/nextjs.js.map +1 -1
- package/dist/providers/dodo/provider.d.ts +5 -2
- package/dist/providers/dodo/provider.d.ts.map +1 -1
- package/dist/providers/dodo/provider.js +33 -6
- package/dist/providers/dodo/provider.js.map +1 -1
- package/dist/providers/dodo/verified-payment-payload.d.ts +6 -0
- package/dist/providers/dodo/verified-payment-payload.d.ts.map +1 -0
- package/dist/providers/dodo/verified-payment-payload.js +42 -0
- package/dist/providers/dodo/verified-payment-payload.js.map +1 -0
- package/dist/providers/index.d.ts +1 -1
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/mock/provider.d.ts +4 -1
- package/dist/providers/mock/provider.d.ts.map +1 -1
- package/dist/providers/mock/provider.js +3 -1
- package/dist/providers/mock/provider.js.map +1 -1
- package/dist/providers/stripe/event-mapper.d.ts.map +1 -1
- package/dist/providers/stripe/event-mapper.js +48 -20
- package/dist/providers/stripe/event-mapper.js.map +1 -1
- package/dist/providers/stripe/provider.d.ts +4 -1
- package/dist/providers/stripe/provider.d.ts.map +1 -1
- package/dist/providers/stripe/provider.js +64 -23
- package/dist/providers/stripe/provider.js.map +1 -1
- package/dist/providers/types.d.ts +11 -1
- package/dist/providers/types.d.ts.map +1 -1
- package/dist/providers/types.js +9 -0
- package/dist/providers/types.js.map +1 -1
- package/dist/shared/postgres-client.d.ts +3 -0
- package/dist/shared/postgres-client.d.ts.map +1 -1
- package/dist/shared/postgres-client.js +61 -49
- package/dist/shared/postgres-client.js.map +1 -1
- package/dist/shared/provider-rejection.d.ts +3 -0
- package/dist/shared/provider-rejection.d.ts.map +1 -0
- package/dist/shared/provider-rejection.js +17 -0
- package/dist/shared/provider-rejection.js.map +1 -0
- package/dist/shared/timestamp.d.ts +2 -0
- package/dist/shared/timestamp.d.ts.map +1 -1
- package/dist/shared/timestamp.js +7 -0
- package/dist/shared/timestamp.js.map +1 -1
- package/dist/storage/adapters/clickhouse.d.ts +1 -1
- package/dist/storage/adapters/clickhouse.d.ts.map +1 -1
- package/dist/storage/adapters/clickhouse.js +18 -17
- package/dist/storage/adapters/clickhouse.js.map +1 -1
- package/dist/storage/adapters/s3.d.ts +5 -0
- package/dist/storage/adapters/s3.d.ts.map +1 -1
- package/dist/storage/adapters/s3.js +46 -14
- package/dist/storage/adapters/s3.js.map +1 -1
- package/dist/storage/diagnostics.d.ts +3 -7
- package/dist/storage/diagnostics.d.ts.map +1 -1
- package/dist/storage/diagnostics.js +6 -15
- package/dist/storage/diagnostics.js.map +1 -1
- package/dist/storage/outbox-worker.d.ts.map +1 -1
- package/dist/storage/outbox-worker.js +4 -3
- package/dist/storage/outbox-worker.js.map +1 -1
- package/dist/storage/ports.d.ts +3 -0
- package/dist/storage/ports.d.ts.map +1 -1
- package/dist/storage/ports.js.map +1 -1
- package/dist/storage/postgres-repository.d.ts +1 -3
- package/dist/storage/postgres-repository.d.ts.map +1 -1
- package/dist/storage/postgres-repository.js +10 -4
- package/dist/storage/postgres-repository.js.map +1 -1
- package/dist/storage/runtime.d.ts +15 -10
- package/dist/storage/runtime.d.ts.map +1 -1
- package/dist/storage/runtime.js +74 -68
- package/dist/storage/runtime.js.map +1 -1
- package/dist/telemetry/index.d.ts +1 -1
- package/dist/telemetry/index.js +1 -1
- package/dist/telemetry/index.js.map +1 -1
- package/package.json +73 -71
- package/dist/credits/queries.d.ts +0 -33
- package/dist/credits/queries.d.ts.map +0 -1
- package/dist/credits/queries.js +0 -71
- package/dist/credits/queries.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service-errors.js","sourceRoot":"","sources":["../../src/credits/service-errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,OAAO,EACL,qBAAqB,EACrB,WAAW,EACX,uBAAuB,EACvB,wBAAwB,EACxB,iBAAiB,EACjB,kBAAkB,EAClB,wBAAwB,EACxB,kBAAkB,EAClB,UAAU,
|
|
1
|
+
{"version":3,"file":"service-errors.js","sourceRoot":"","sources":["../../src/credits/service-errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,OAAO,EACL,qBAAqB,EACrB,WAAW,EACX,uBAAuB,EACvB,wBAAwB,EACxB,wBAAwB,EACxB,iBAAiB,EACjB,kBAAkB,EAClB,wBAAwB,EACxB,kBAAkB,EAClB,UAAU,EACV,eAAe,GAChB,MAAM,cAAc,CAAC;AAEtB,MAAM,UAAU,eAAe,CAAC,KAAa,EAAE,MAAc,EAAE,MAAe;IAC5E,QAAQ,KAAK,EAAE,CAAC;QACd,KAAK,sBAAsB;YACzB,MAAM,IAAI,wBAAwB,CAChC,wDAAwD,MAAM,EAAE,CACjE,CAAC;QACJ,KAAK,wBAAwB;YAC3B,MAAM,IAAI,qBAAqB,CAAC,mCAAmC,MAAM,EAAE,CAAC,CAAC;QAC/E,KAAK,gBAAgB;YACnB,MAAM,IAAI,kBAAkB,CAAC,8BAA8B,MAAM,EAAE,CAAC,CAAC;QACvE,KAAK,sBAAsB;YACzB,MAAM,IAAI,uBAAuB,CAAC,8BAA8B,M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kBAAkB,CAAC,8BAA8B,MAAM,EAAE,CAAC,CAAC;QACvE,KAAK,sBAAsB;YACzB,MAAM,IAAI,uBAAuB,CAAC,8BAA8B,MAAM,EAAE,CAAC,CAAC;QAC5E,KAAK,uBAAuB;YAC1B,MAAM,IAAI,wBAAwB,CAAC,kCAAkC,MAAM,EAAE,CAAC,CAAC;QACjF,KAAK,uBAAuB,CAAC;QAC7B,KAAK,sBAAsB;YACzB,MAAM,IAAI,wBAAwB,CAAC,8BAA8B,MAAM,eAAe,IAAI,EAAE,CAAC,CAAC;QAChG,KAAK,iBAAiB;YACpB,MAAM,IAAI,WAAW,CAAC,kCAAkC,MAAM,EAAE,CAAC,CAAC;QACpE,KAAK,uBAAuB,CAAC;QAC7B,KAAK,iBAAiB;YACpB,MAAM,IAAI,WAAW,CAAC,mCAAmC,MAAM,KAAK,KAAK,EAAE,CAAC,CAAC;QAC/E,KAAK,gBAAgB,CAAC;QACtB,KAAK,iBAAiB;YACpB,MAAM,IAAI,UAAU,CAAC,6BAA6B,IAAI,EAAE,CAAC,CAAC;QAC5D;YACE,MAAM,IAAI,UAAU,CAAC,4BAA4B,KAAK,UAAU,MAAM,eAAe,IAAI,EAAE,CAAC,CAAC;IACjG,CAAC;AACH,CAAC","sourcesContent":["import { Decimal } from \"decimal.js\";\n\nimport {\n ConcurrencyLimitError,\n ConfigError,\n FeatureNotEntitledError,\n IdempotencyConflictError,\n InsufficientCreditsError,\n LeaseExpiredError,\n LeaseNotFoundError,\n OperationNotAllowedError,\n QuotaExceededError,\n StoreError,\n StaleQuoteError,\n} from \"../errors.js\";\n\nexport function raiseLeaseError(error: string, userId: string, amount: Decimal): never {\n switch (error) {\n case \"idempotency_conflict\":\n throw new IdempotencyConflictError(\n `Idempotency key conflicts with a prior request. user=${userId}`,\n );\n case \"max_concurrent_reached\":\n throw new ConcurrencyLimitError(`Concurrency limit reached. user=${userId}`);\n case \"quota_exceeded\":\n throw new QuotaExceededError(`Usage quota exceeded. user=${userId}`);\n case \"feature_not_entitled\":\n throw new FeatureNotEntitledError(`Feature not entitled. user=${userId}`);\n case \"operation_not_allowed\":\n throw new OperationNotAllowedError(`Operation is not allowed. user=${userId}`);\n case \"insufficient_headroom\":\n case \"insufficient_credits\":\n throw new InsufficientCreditsError(\n `Insufficient credits. user=${userId}, requested=${amount}`,\n );\n case \"expired_lease\":\n throw new LeaseExpiredError(`Lease expired. user=${userId}`);\n case \"missing_lease\":\n throw new LeaseNotFoundError(`Lease not found. user=${userId}`);\n case \"released_lease\":\n case \"settled_lease\":\n case \"settling_lease\":\n throw new LeaseNotFoundError(`Lease is already finalized. user=${userId}`);\n case \"policy_mismatch\":\n throw new ConfigError(`Invalid operation policy. user=${userId}`);\n case \"missing_quota_measure\":\n case \"invalid_measure\":\n throw new ConfigError(`Invalid quota measures for user ${userId}: ${error}`);\n case \"invalid_request\":\n throw new RangeError(`Invalid amount: ${amount}`);\n default:\n throw new StoreError(`Lease operation failed: ${error}. user=${userId}`);\n }\n}\n\nexport function raiseDeductError(error: string, userId: string, cost: Decimal): never {\n switch (error) {\n case \"idempotency_conflict\":\n throw new IdempotencyConflictError(\n `Idempotency key conflicts with a prior request. user=${userId}`,\n );\n case \"stale_quote\":\n throw new StaleQuoteError(`Pricing changed; retry the deduction. user=${userId}`);\n case \"quota_exceeded\":\n throw new QuotaExceededError(`Usage quota exceeded. user=${userId}`);\n case \"feature_not_entitled\":\n throw new FeatureNotEntitledError(`Feature not entitled. user=${userId}`);\n case \"operation_not_allowed\":\n throw new OperationNotAllowedError(`Operation is not allowed. user=${userId}`);\n case \"insufficient_headroom\":\n case \"insufficient_credits\":\n throw new InsufficientCreditsError(`Insufficient credits. user=${userId}, requested=${cost}`);\n case \"policy_mismatch\":\n throw new ConfigError(`Invalid operation policy. user=${userId}`);\n case \"missing_quota_measure\":\n case \"invalid_measure\":\n throw new ConfigError(`Invalid quota measures for user ${userId}: ${error}`);\n case \"invalid_amount\":\n case \"invalid_request\":\n throw new RangeError(`Invalid deduction amount: ${cost}`);\n default:\n throw new StoreError(`Credit deduction failed: ${error}. user=${userId}, requested=${cost}`);\n }\n}\n"]}
|
|
@@ -16,11 +16,6 @@ export interface PostDeductionContext {
|
|
|
16
16
|
export interface LowBalanceConfig {
|
|
17
17
|
thresholds?: ExactAmount[] | null;
|
|
18
18
|
onTrigger?: ((event: CreditEvent) => void | Promise<void>) | null;
|
|
19
|
-
/**
|
|
20
|
-
* Maximum number of subjects whose breached-threshold state is retained in
|
|
21
|
-
* memory. Defaults to 100,000.
|
|
22
|
-
*/
|
|
23
|
-
maxTrackedUsers?: number;
|
|
24
19
|
}
|
|
25
20
|
export interface CreditsServiceOptions {
|
|
26
21
|
logger?: Logger | null;
|
|
@@ -121,13 +116,16 @@ export interface CanAffordOptions {
|
|
|
121
116
|
export interface GrantSubscriptionCycleOptions {
|
|
122
117
|
bucket?: string;
|
|
123
118
|
expiresAt?: Date;
|
|
124
|
-
ttlDays?: number;
|
|
125
|
-
planKey?: string;
|
|
126
119
|
idempotencyKey: string;
|
|
127
120
|
metadata?: CreditMetadata | null;
|
|
128
121
|
}
|
|
129
122
|
export interface RunBilledOptions<T> {
|
|
130
123
|
estimate: MetricsOrAmount;
|
|
124
|
+
/**
|
|
125
|
+
* Performs the billable work. A repeated invocation of runBilled can call
|
|
126
|
+
* this again even with the same operationKey; make external effects
|
|
127
|
+
* idempotent separately.
|
|
128
|
+
*/
|
|
131
129
|
doWork: () => Promise<{
|
|
132
130
|
result: T;
|
|
133
131
|
actual: MetricsOrAmount;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service-types.d.ts","sourceRoot":"","sources":["../../src/credits/service-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,EA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AE,MAAM,GAAG,IAAI,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,QAAQ,CAAC,EAAE,cAAc,GAAG,IAAI,CAAC;IACjC,gFAAgF;IAChF,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,WAAW,2BAA2B;IAC1C,QAAQ,EAAE,eAAe,CAAC;IAC1B,4DAA4D;IAC5D,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;IACjC,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,QAAQ,CAAC,EAAE,cAAc,GAAG,IAAI,CAAC;CAClC;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,MAAM,CAAC,MAAM,EAAE,eAAe,EAAE,QAAQ,CAAC,EAAE,cAAc,GAAG,IAAI,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IAC5F,KAAK,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1C,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service-types.js","sourceRoot":"","sources":["../../src/credits/service-types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Decimal } from \"decimal.js\";\n\nimport type { UsageMetrics } from \"../metrics.js\";\nimport type { Logger } from \"../shared/logger.js\";\nimport type { Instrumentation } from \"../telemetry/index.js\";\nimport type { CreditEvent } from \"./events.js\";\nimport type {\n BillingMode,\n CreditMetadata,\n DeductionResult,\n DeductionSuccess,\n UsageAnalyticsStore,\n UsageChargeStore,\n} from \"./types/index.js\";\n\nexport type PolicyPreset = \"strict_prepaid\" | \"overdraft\";\n/** Exact decimal credit input. Native numbers are intentionally excluded. */\nexport type ExactAmount = Decimal | string;\nexport type MetricsOrAmount = UsageMetrics | ExactAmount;\n\nexport interface PostDeductionContext {\n userId: string;\n source: \"deduct\" | \"settle\" | \"raw\";\n deduction: DeductionSuccess;\n}\n\nexport interface LowBalanceConfig {\n thresholds?: ExactAmount[] | null;\n onTrigger?: ((event: CreditEvent) => void | Promise<void>) | null;\n
|
|
1
|
+
{"version":3,"file":"service-types.js","sourceRoot":"","sources":["../../src/credits/service-types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Decimal } from \"decimal.js\";\n\nimport type { UsageMetrics } from \"../metrics.js\";\nimport type { Logger } from \"../shared/logger.js\";\nimport type { Instrumentation } from \"../telemetry/index.js\";\nimport type { CreditEvent } from \"./events.js\";\nimport type {\n BillingMode,\n CreditMetadata,\n DeductionResult,\n DeductionSuccess,\n UsageAnalyticsStore,\n UsageChargeStore,\n} from \"./types/index.js\";\n\nexport type PolicyPreset = \"strict_prepaid\" | \"overdraft\";\n/** Exact decimal credit input. Native numbers are intentionally excluded. */\nexport type ExactAmount = Decimal | string;\nexport type MetricsOrAmount = UsageMetrics | ExactAmount;\n\nexport interface PostDeductionContext {\n userId: string;\n source: \"deduct\" | \"settle\" | \"raw\";\n deduction: DeductionSuccess;\n}\n\nexport interface LowBalanceConfig {\n thresholds?: ExactAmount[] | null;\n onTrigger?: ((event: CreditEvent) => void | Promise<void>) | null;\n}\n\nexport interface CreditsServiceOptions {\n logger?: Logger | null;\n /** Explicit telemetry implementation; falls back to Bursar's no-op registry. */\n instrumentation?: Instrumentation | null;\n /**\n * Optional read-only analytics backend. Defaults to the credit store, which\n * keeps PostgreSQL as the zero-infrastructure behavior.\n */\n analytics?: UsageAnalyticsStore | null;\n /** Optional usage-history backend. Defaults to the credit store. */\n usageStore?: UsageChargeStore | null;\n /** Fallback credit policy for subjects without a plan assignment. */\n policy?: PolicyPreset;\n /** Planless-subject floor used with the `overdraft` fallback. */\n overdraftFloor?: ExactAmount | null;\n /** Planless-subject admission limit fallback. */\n maxConcurrent?: number | null;\n /**\n * Edge-triggered low-balance thresholds and optional non-blocking handler.\n * Defaults to zero when omitted.\n */\n lowBalance?: LowBalanceConfig | null;\n /** Default lease TTL in seconds. Defaults to 600. */\n defaultTtlSeconds?: number;\n /** Sweep a subject's expired credits before balance-sensitive operations. */\n lazyExpiry?: boolean;\n /**\n * Catalog cache TTL in milliseconds. A value of 0 disables automatic\n * reloads. Concurrent reloads are deduplicated. Defaults to 300,000.\n */\n catalogCacheTtlMs?: number;\n /**\n * Awaited after a committed, non-replayed deduction. Hook failures are\n * isolated from the committed credit charge.\n */\n postDeduction?: ((context: PostDeductionContext) => void | Promise<void>) | null;\n}\n\nexport interface AddCreditsOptions {\n type?: string;\n metadata?: CreditMetadata | null;\n expiresAt?: Date | null;\n /** Target credit bucket; omitted resolves to the catalog's default bucket. */\n bucket?: string | null;\n /** Stable replay key for the ledger mutation. */\n idempotencyKey: string;\n}\n\nexport interface DeductCreditsOptions {\n entryType?: string;\n bucket?: string | null;\n metadata?: CreditMetadata | null;\n /** Stable replay key for the ledger mutation. */\n idempotencyKey: string;\n}\n\nexport interface DeductOptions {\n idempotencyKey: string;\n metadata?: CreditMetadata | null;\n /** Entitlement feature required for this operation. */\n feature?: string | null;\n}\n\nexport type DeductFlatJobOptions = DeductOptions;\n\nexport interface RecordUsageOptions {\n idempotencyKey: string;\n metadata?: CreditMetadata | null;\n}\n\nexport interface RefundCreditsOptions {\n amount?: ExactAmount;\n reason?: string;\n metadata?: CreditMetadata | null;\n idempotencyKey: string;\n}\n\nexport interface DeductTeamOptions {\n idempotencyKey: string;\n metadata?: CreditMetadata | null;\n}\n\nexport interface ReserveOptions {\n /** Caller-stable replay-safe acquisition key. */\n idempotencyKey: string;\n operationType?: string;\n billingMode?: BillingMode | null;\n ttl?: number | null;\n metadata?: CreditMetadata | null;\n feature?: string | null;\n /** Model tag used when reserving a raw amount instead of usage metrics. */\n model?: string | null;\n}\n\nexport interface SettleOptions {\n idempotencyKey?: string;\n metadata?: CreditMetadata | null;\n /** Entitlement key supplied at reserve time. */\n feature?: string | null;\n}\n\nexport interface CanAffordOptions {\n feature?: string | null;\n billingMode?: BillingMode | null;\n operationType?: string;\n}\n\nexport interface GrantSubscriptionCycleOptions {\n bucket?: string;\n expiresAt?: Date;\n idempotencyKey: string;\n metadata?: CreditMetadata | null;\n}\n\nexport interface RunBilledOptions<T> {\n estimate: MetricsOrAmount;\n /**\n * Performs the billable work. A repeated invocation of runBilled can call\n * this again even with the same operationKey; make external effects\n * idempotent separately.\n */\n doWork: () => Promise<{ result: T; actual: MetricsOrAmount }>;\n operationType?: string;\n billingMode?: BillingMode | null;\n /** Stable key for the complete reserve/work/settle operation. */\n operationKey: string;\n ttl?: number | null;\n feature?: string | null;\n metadata?: CreditMetadata | null;\n /** Settlement attempts for SDK-classified transient failures. Defaults to 3. */\n settlementAttempts?: number;\n}\n\nexport interface BeginBilledOperationOptions {\n estimate: MetricsOrAmount;\n /** Stable key for the complete reserve/settle operation. */\n operationKey: string;\n operationType?: string;\n billingMode?: BillingMode | null;\n ttl?: number | null;\n feature?: string | null;\n metadata?: CreditMetadata | null;\n}\n\nexport interface BilledOperation {\n readonly leaseId: string;\n readonly operationKey: string;\n settle(actual: MetricsOrAmount, metadata?: CreditMetadata | null): Promise<DeductionResult>;\n renew(ttl?: number | null): Promise<void>;\n release(): Promise<void>;\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { PricingEngine } from "../engine.js";
|
|
2
2
|
import type { BursarConfigData, CatalogRollout } from "../config.js";
|
|
3
|
-
import type { AddCreditsResult, AggregateStats, AllowanceResult, AvailableResult, BalanceResult, CatalogRevision, BucketBalancesResult, CanAffordResult, CheckFeatureResult, DailySpendRow, DeductionResult, ExecuteGrantProgramRequest, GetUserPlanResult, GrantProgramAwardResult, LedgerEntry, LedgerPage, LeaseSuccess, ListLedgerEntriesOptions, ListQuotaEventsOptions, ListUsageChargesOptions, ListUsageEntriesOptions, PlanMigrationBatchResult, PlanMigrationStartResult, QuotaEvent, QuotaState, RefundSuccess, RevokeCreditsResult, ReleaseResult, SetUserPlanResult, UnsetUserPlanResult, SpendByModelRow, SpendByUserRow, SweepResult, TeamDeductionResult, TopUserRow, UsageChargePage, UsageRecordResult } from "./types/index.js";
|
|
3
|
+
import type { AddCreditsResult, AggregateStats, AllowanceResult, AvailableResult, BalanceResult, CatalogRevision, BucketBalancesResult, CanAffordResult, CheckFeatureResult, DailySpendRow, DeductionResult, ExecuteGrantProgramRequest, GetUserPlanResult, GrantProgramAwardResult, LedgerEntry, LedgerPage, LeaseSuccess, ListLedgerEntriesOptions, ListQuotaEventsOptions, ListUsageChargesOptions, ListUsageEntriesOptions, PlanMigrationBatchResult, PlanMigrationStartResult, QuotaEvent, QuotaState, RefundSuccess, RevokeCreditsResult, ReleaseResult, SetUserPlanResult, UnsetUserPlanResult, SpendByModelRow, SpendByUserRow, SweepResult, TeamDeductionResult, TopUserRow, UsageChargePage, UsageRecordResult, OperationReceipt } from "./types/index.js";
|
|
4
4
|
import type { CreditStore } from "./store.js";
|
|
5
5
|
import type { CreditEventEmitter } from "./events.js";
|
|
6
6
|
import type { UsageMetrics } from "../metrics.js";
|
|
@@ -20,9 +20,12 @@ export type { AddCreditsOptions, BeginBilledOperationOptions, BilledOperation, C
|
|
|
20
20
|
* low_balance).
|
|
21
21
|
*/
|
|
22
22
|
export declare class CreditsService {
|
|
23
|
+
/** Look up a durable charge or lease after an ambiguous outcome. */
|
|
24
|
+
getOperationReceipt(userId: string, key: string, kind: "charge" | "lease"): Promise<OperationReceipt | null>;
|
|
23
25
|
private readonly store;
|
|
24
26
|
get providerEnvironment(): "live" | "sandbox" | "test" | undefined;
|
|
25
|
-
private readonly
|
|
27
|
+
private readonly analytics;
|
|
28
|
+
private readonly usageStore;
|
|
26
29
|
private readonly catalogRuntime;
|
|
27
30
|
private readonly leases;
|
|
28
31
|
private emitter;
|
|
@@ -127,17 +130,15 @@ export declare class CreditsService {
|
|
|
127
130
|
* payment-provider webhook handler (Stripe, etc. — bursar stays
|
|
128
131
|
* provider-agnostic) to call even on webhook redelivery.
|
|
129
132
|
*
|
|
130
|
-
* 1.
|
|
131
|
-
*
|
|
132
|
-
* 2. When ``ttlDays`` is given, ``expiresAt = now + ttlDays`` days.
|
|
133
|
-
* 3. The new cycle is granted via a direct ``store.addCredits`` call
|
|
133
|
+
* 1. Supply a stable absolute ``expiresAt`` across retries, if the grant expires.
|
|
134
|
+
* 2. The new cycle is granted via a direct ``store.addCredits`` call
|
|
134
135
|
* (bypassing {@link addCredits} so only ``credits.cycle_renewed`` fires,
|
|
135
136
|
* not a duplicate ``credits.added``), threading ``idempotencyKey`` so a
|
|
136
137
|
* redelivered webhook replays the prior grant instead of double-crediting.
|
|
137
|
-
*
|
|
138
|
+
* 3. Existing bucket credits are never removed here. Subscription renewal
|
|
138
139
|
* policies that replace prior lots run atomically through BillingService.
|
|
139
|
-
*
|
|
140
|
-
*
|
|
140
|
+
* 4. Emits ``credits.cycle_renewed`` and returns the grant result. Plan
|
|
141
|
+
* assignment is a separate operation managed by the caller.
|
|
141
142
|
*/
|
|
142
143
|
grantSubscriptionCycle(userId: string, amount: ExactAmount, options: GrantSubscriptionCycleOptions): Promise<AddCreditsResult>;
|
|
143
144
|
private grantSubscriptionCycleUninstrumented;
|
|
@@ -173,6 +174,7 @@ export declare class CreditsService {
|
|
|
173
174
|
* affecting the account balance, such as externally billed usage.
|
|
174
175
|
*/
|
|
175
176
|
recordUsage(userId: string, metrics: UsageMetrics, options: RecordUsageOptions): Promise<UsageRecordResult>;
|
|
177
|
+
private recordUsageOnce;
|
|
176
178
|
/**
|
|
177
179
|
* Refund a previous credit deduction.
|
|
178
180
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../src/credits/service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../src/credits/service.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACrE,OAAO,KAAK,EACV,gBAAgB,EAChB,cAAc,EACd,eAAe,EACf,eAAe,EACf,aAAa,EACb,eAAe,EACf,oBAAoB,EACpB,eAAe,EACf,kBAAkB,EAElB,aAAa,EACb,eAAe,EAEf,0BAA0B,EAC1B,iBAAiB,EACjB,uBAAuB,EACvB,WAAW,EACX,UAAU,EACV,YAAY,EACZ,wBAAwB,EACxB,sBAAsB,EACtB,uBAAuB,EACvB,uBAAuB,EACvB,wBAAwB,EACxB,wBAAwB,EACxB,UAAU,EACV,UAAU,EACV,aAAa,EACb,mBAAmB,EACnB,aAAa,EACb,iBAAiB,EACjB,mBAAmB,EACnB,eAAe,EACf,cAAc,EACd,WAAW,EACX,mBAAmB,EACnB,UAAU,EACV,eAAe,EAGf,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,KAAK,EAAE,kBAAkB,EAAmB,MAAM,aAAa,CAAC;AACvE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAUlD,OAAO,KAAK,EACV,iBAAiB,EACjB,2BAA2B,EAC3B,eAAe,EACf,gBAAgB,EAChB,qBAAqB,EACrB,oBAAoB,EACpB,oBAAoB,EACpB,aAAa,EACb,iBAAiB,EACjB,WAAW,EACX,6BAA6B,EAC7B,eAAe,EAEf,oBAAoB,EACpB,kBAAkB,EAClB,oBAAoB,EACpB,cAAc,EACd,gBAAgB,EAChB,aAAa,EACd,MAAM,oBAAoB,CAAC;AAE5B,YAAY,EACV,iBAAi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