@zonastery/bursar 2.0.2 → 2.0.4
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 +1 -0
- package/dist/billing/auto-recharge-port.d.ts +3 -2
- package/dist/billing/auto-recharge-port.d.ts.map +1 -1
- package/dist/billing/auto-recharge-port.js.map +1 -1
- package/dist/billing/auto-recharge-service.d.ts +1 -1
- package/dist/billing/auto-recharge-service.d.ts.map +1 -1
- package/dist/billing/auto-recharge-service.js +5 -4
- package/dist/billing/auto-recharge-service.js.map +1 -1
- package/dist/billing/billing-service.d.ts +3 -2
- package/dist/billing/billing-service.d.ts.map +1 -1
- package/dist/billing/billing-service.js +2 -10
- package/dist/billing/billing-service.js.map +1 -1
- package/dist/billing/billing-store.d.ts +7 -7
- 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 +10 -8
- package/dist/billing/contracts.d.ts.map +1 -1
- package/dist/billing/contracts.js.map +1 -1
- package/dist/billing/event-handlers.d.ts +5 -9
- package/dist/billing/event-handlers.d.ts.map +1 -1
- package/dist/billing/event-handlers.js +191 -285
- package/dist/billing/event-handlers.js.map +1 -1
- package/dist/billing/event-processor.d.ts +1 -1
- package/dist/billing/event-processor.d.ts.map +1 -1
- package/dist/billing/event-processor.js +42 -21
- package/dist/billing/event-processor.js.map +1 -1
- package/dist/billing/financial-event-handlers.d.ts +3 -9
- package/dist/billing/financial-event-handlers.d.ts.map +1 -1
- package/dist/billing/financial-event-handlers.js +10 -12
- 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 +3 -2
- package/dist/billing/management.d.ts.map +1 -1
- package/dist/billing/management.js.map +1 -1
- package/dist/billing/postgres/repositories/auto-recharge.d.ts +2 -1
- package/dist/billing/postgres/repositories/auto-recharge.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/auto-recharge.js +59 -41
- package/dist/billing/postgres/repositories/auto-recharge.js.map +1 -1
- package/dist/billing/postgres/repositories/dispute.d.ts +2 -1
- package/dist/billing/postgres/repositories/dispute.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/dispute.js.map +1 -1
- package/dist/billing/postgres/repositories/event.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/event.js +33 -1
- package/dist/billing/postgres/repositories/event.js.map +1 -1
- package/dist/billing/postgres/repositories/invoice.d.ts +2 -1
- package/dist/billing/postgres/repositories/invoice.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/invoice.js +8 -12
- package/dist/billing/postgres/repositories/invoice.js.map +1 -1
- package/dist/billing/postgres/repositories/offer.d.ts +1 -1
- package/dist/billing/postgres/repositories/offer.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/offer.js +6 -1
- package/dist/billing/postgres/repositories/offer.js.map +1 -1
- package/dist/billing/postgres/repositories/payment.d.ts +1 -1
- package/dist/billing/postgres/repositories/payment.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/payment.js +1 -1
- package/dist/billing/postgres/repositories/payment.js.map +1 -1
- package/dist/billing/postgres/repositories/subscription-change.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/subscription-change.js +1 -9
- package/dist/billing/postgres/repositories/subscription-change.js.map +1 -1
- package/dist/billing/postgres/repositories/subscription.d.ts +6 -6
- package/dist/billing/postgres/repositories/subscription.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/subscription.js +29 -30
- package/dist/billing/postgres/repositories/subscription.js.map +1 -1
- package/dist/billing/postgres/repositories/topup.d.ts +1 -1
- package/dist/billing/postgres/repositories/topup.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/topup.js +1 -1
- package/dist/billing/postgres/repositories/topup.js.map +1 -1
- package/dist/billing/postgres/store.d.ts +7 -6
- package/dist/billing/postgres/store.d.ts.map +1 -1
- package/dist/billing/postgres/store.js +31 -19
- package/dist/billing/postgres/store.js.map +1 -1
- package/dist/billing/types/auto-recharge.d.ts +3 -2
- package/dist/billing/types/auto-recharge.d.ts.map +1 -1
- package/dist/billing/types/auto-recharge.js.map +1 -1
- package/dist/billing/types/catalog.d.ts +1 -1
- 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 +3 -2
- 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 +11 -2
- package/dist/billing/types/events.d.ts.map +1 -1
- package/dist/billing/types/events.js +73 -39
- package/dist/billing/types/events.js.map +1 -1
- package/dist/billing/types/subscriptions.d.ts +4 -1
- package/dist/billing/types/subscriptions.d.ts.map +1 -1
- package/dist/billing/types/subscriptions.js.map +1 -1
- package/dist/breakdown.d.ts +4 -3
- package/dist/breakdown.d.ts.map +1 -1
- package/dist/breakdown.js +1 -1
- package/dist/breakdown.js.map +1 -1
- package/dist/bursar.d.ts.map +1 -1
- package/dist/bursar.js +4 -3
- package/dist/bursar.js.map +1 -1
- package/dist/catalog.d.ts.map +1 -1
- package/dist/catalog.js +45 -42
- package/dist/catalog.js.map +1 -1
- package/dist/commerce/provider-registry.d.ts.map +1 -1
- package/dist/commerce/provider-registry.js +11 -6
- package/dist/commerce/provider-registry.js.map +1 -1
- package/dist/commerce/service.d.ts.map +1 -1
- package/dist/commerce/service.js +70 -68
- package/dist/commerce/service.js.map +1 -1
- package/dist/commerce/types.d.ts +1 -1
- package/dist/commerce/types.d.ts.map +1 -1
- package/dist/commerce/types.js.map +1 -1
- package/dist/config/parse-access.d.ts +5 -2
- package/dist/config/parse-access.d.ts.map +1 -1
- package/dist/config/parse-access.js +60 -41
- package/dist/config/parse-access.js.map +1 -1
- package/dist/config/parse-commerce.d.ts +2 -1
- package/dist/config/parse-commerce.d.ts.map +1 -1
- package/dist/config/parse-commerce.js +49 -29
- package/dist/config/parse-commerce.js.map +1 -1
- package/dist/config/parse-credits.d.ts +2 -1
- package/dist/config/parse-credits.d.ts.map +1 -1
- package/dist/config/parse-credits.js +39 -23
- package/dist/config/parse-credits.js.map +1 -1
- package/dist/config/parse-plans.d.ts +7 -2
- package/dist/config/parse-plans.d.ts.map +1 -1
- package/dist/config/parse-plans.js +49 -22
- package/dist/config/parse-plans.js.map +1 -1
- package/dist/config/parse-pricing.d.ts +2 -1
- package/dist/config/parse-pricing.d.ts.map +1 -1
- package/dist/config/parse-pricing.js +41 -31
- package/dist/config/parse-pricing.js.map +1 -1
- package/dist/config/parse-utils.d.ts +16 -12
- package/dist/config/parse-utils.d.ts.map +1 -1
- package/dist/config/parse-utils.js +91 -28
- package/dist/config/parse-utils.js.map +1 -1
- package/dist/config/types.d.ts +1 -1
- package/dist/config/types.d.ts.map +1 -1
- package/dist/config/types.js.map +1 -1
- package/dist/config.d.ts +6 -5
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +66 -36
- package/dist/config.js.map +1 -1
- package/dist/credits/amount.d.ts +2 -2
- package/dist/credits/amount.d.ts.map +1 -1
- package/dist/credits/amount.js +6 -5
- package/dist/credits/amount.js.map +1 -1
- package/dist/credits/catalog-runtime.d.ts +1 -1
- package/dist/credits/catalog-runtime.d.ts.map +1 -1
- package/dist/credits/catalog-runtime.js +3 -4
- package/dist/credits/catalog-runtime.js.map +1 -1
- package/dist/credits/events.d.ts +12 -1
- package/dist/credits/events.d.ts.map +1 -1
- package/dist/credits/events.js +35 -21
- package/dist/credits/events.js.map +1 -1
- package/dist/credits/lease-workflow.d.ts +3 -2
- package/dist/credits/lease-workflow.d.ts.map +1 -1
- package/dist/credits/lease-workflow.js +4 -3
- package/dist/credits/lease-workflow.js.map +1 -1
- package/dist/credits/low-balance-monitor.d.ts +3 -2
- package/dist/credits/low-balance-monitor.d.ts.map +1 -1
- package/dist/credits/low-balance-monitor.js +1 -1
- package/dist/credits/low-balance-monitor.js.map +1 -1
- package/dist/credits/postgres/repositories/analytics.d.ts +2 -2
- package/dist/credits/postgres/repositories/analytics.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/analytics.js +14 -6
- package/dist/credits/postgres/repositories/analytics.js.map +1 -1
- package/dist/credits/postgres/repositories/balance.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/balance.js +7 -7
- package/dist/credits/postgres/repositories/balance.js.map +1 -1
- package/dist/credits/postgres/repositories/bucket.js +1 -1
- package/dist/credits/postgres/repositories/bucket.js.map +1 -1
- package/dist/credits/postgres/repositories/catalog.d.ts +4 -3
- package/dist/credits/postgres/repositories/catalog.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/catalog.js +4 -3
- package/dist/credits/postgres/repositories/catalog.js.map +1 -1
- package/dist/credits/postgres/repositories/deduction.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/deduction.js +2 -2
- package/dist/credits/postgres/repositories/deduction.js.map +1 -1
- package/dist/credits/postgres/repositories/lease.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/lease.js +4 -2
- 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/team.d.ts +2 -1
- package/dist/credits/postgres/repositories/team.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/team.js +19 -5
- package/dist/credits/postgres/repositories/team.js.map +1 -1
- package/dist/credits/postgres/store.d.ts +6 -5
- package/dist/credits/postgres/store.d.ts.map +1 -1
- package/dist/credits/postgres/store.js +23 -13
- package/dist/credits/postgres/store.js.map +1 -1
- package/dist/credits/postgres/value-mappers.d.ts +5 -4
- package/dist/credits/postgres/value-mappers.d.ts.map +1 -1
- package/dist/credits/postgres/value-mappers.js +11 -12
- package/dist/credits/postgres/value-mappers.js.map +1 -1
- package/dist/credits/service-errors.d.ts +1 -1
- package/dist/credits/service-errors.d.ts.map +1 -1
- package/dist/credits/service-errors.js +1 -1
- package/dist/credits/service-errors.js.map +1 -1
- package/dist/credits/service-types.d.ts +4 -1
- 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 +5 -0
- package/dist/credits/service.d.ts.map +1 -1
- package/dist/credits/service.js +30 -10
- package/dist/credits/service.js.map +1 -1
- package/dist/credits/store.d.ts +15 -5
- package/dist/credits/store.d.ts.map +1 -1
- package/dist/credits/store.js +1 -1
- package/dist/credits/store.js.map +1 -1
- package/dist/credits/types/account.d.ts +5 -4
- package/dist/credits/types/account.d.ts.map +1 -1
- package/dist/credits/types/account.js.map +1 -1
- package/dist/credits/types/catalog.d.ts +2 -1
- package/dist/credits/types/catalog.d.ts.map +1 -1
- package/dist/credits/types/catalog.js.map +1 -1
- 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 +3 -2
- package/dist/credits/types/ledger.d.ts.map +1 -1
- package/dist/credits/types/ledger.js.map +1 -1
- package/dist/credits/types/teams.d.ts +1 -0
- package/dist/credits/types/teams.d.ts.map +1 -1
- package/dist/credits/types/teams.js.map +1 -1
- package/dist/engine.d.ts +2 -2
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +40 -11
- package/dist/engine.js.map +1 -1
- package/dist/errors.d.ts +10 -3
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +50 -9
- package/dist/errors.js.map +1 -1
- package/dist/expr/ast.d.ts.map +1 -1
- package/dist/expr/ast.js.map +1 -1
- package/dist/expr/evaluator.d.ts +1 -1
- package/dist/expr/evaluator.d.ts.map +1 -1
- package/dist/expr/evaluator.js +1 -1
- package/dist/expr/evaluator.js.map +1 -1
- package/dist/expr/parser.d.ts.map +1 -1
- package/dist/expr/parser.js.map +1 -1
- package/dist/expr/tokenizer.d.ts.map +1 -1
- package/dist/expr/tokenizer.js +34 -12
- package/dist/expr/tokenizer.js.map +1 -1
- package/dist/expr.d.ts +1 -1
- package/dist/expr.d.ts.map +1 -1
- package/dist/expr.js +13 -7
- package/dist/expr.js.map +1 -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 +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/integrations/better-auth.d.ts +4 -1
- package/dist/integrations/better-auth.d.ts.map +1 -1
- package/dist/integrations/better-auth.js +7 -4
- package/dist/integrations/better-auth.js.map +1 -1
- package/dist/load-config-file.d.ts +2 -1
- package/dist/load-config-file.d.ts.map +1 -1
- package/dist/load-config-file.js +19 -13
- package/dist/load-config-file.js.map +1 -1
- package/dist/metrics.d.ts +3 -2
- package/dist/metrics.d.ts.map +1 -1
- package/dist/metrics.js.map +1 -1
- package/dist/node.d.ts +6 -3
- package/dist/node.d.ts.map +1 -1
- package/dist/node.js +1 -0
- package/dist/node.js.map +1 -1
- package/dist/providers/_shared.d.ts +11 -8
- package/dist/providers/_shared.d.ts.map +1 -1
- package/dist/providers/_shared.js +26 -17
- package/dist/providers/_shared.js.map +1 -1
- package/dist/providers/dodo/better-auth-core.d.ts +32 -0
- package/dist/providers/dodo/better-auth-core.d.ts.map +1 -0
- package/dist/providers/dodo/better-auth-core.js +14 -0
- package/dist/providers/dodo/better-auth-core.js.map +1 -0
- package/dist/providers/dodo/better-auth.d.ts +5 -7
- package/dist/providers/dodo/better-auth.d.ts.map +1 -1
- package/dist/providers/dodo/better-auth.js +16 -13
- package/dist/providers/dodo/better-auth.js.map +1 -1
- package/dist/providers/dodo/client-contract.d.ts +16 -22
- package/dist/providers/dodo/client-contract.d.ts.map +1 -1
- package/dist/providers/dodo/client-contract.js.map +1 -1
- package/dist/providers/dodo/event-mapper.d.ts +7 -4
- package/dist/providers/dodo/event-mapper.d.ts.map +1 -1
- package/dist/providers/dodo/event-mapper.js +130 -106
- package/dist/providers/dodo/event-mapper.js.map +1 -1
- package/dist/providers/dodo/nextjs-core.d.ts +22 -0
- package/dist/providers/dodo/nextjs-core.d.ts.map +1 -0
- package/dist/providers/dodo/nextjs-core.js +14 -0
- package/dist/providers/dodo/nextjs-core.js.map +1 -0
- package/dist/providers/dodo/nextjs.d.ts +5 -7
- package/dist/providers/dodo/nextjs.d.ts.map +1 -1
- package/dist/providers/dodo/nextjs.js +11 -10
- package/dist/providers/dodo/nextjs.js.map +1 -1
- package/dist/providers/dodo/provider.d.ts +3 -3
- package/dist/providers/dodo/provider.d.ts.map +1 -1
- package/dist/providers/dodo/provider.js +76 -58
- package/dist/providers/dodo/provider.js.map +1 -1
- package/dist/providers/dodo/react-native-core.d.ts +56 -0
- package/dist/providers/dodo/react-native-core.d.ts.map +1 -0
- package/dist/providers/dodo/react-native-core.js +56 -0
- package/dist/providers/dodo/react-native-core.js.map +1 -0
- package/dist/providers/dodo/react-native.d.ts +6 -50
- package/dist/providers/dodo/react-native.d.ts.map +1 -1
- package/dist/providers/dodo/react-native.js +5 -49
- package/dist/providers/dodo/react-native.js.map +1 -1
- package/dist/providers/dodo/webhook-bridge.d.ts +4 -2
- package/dist/providers/dodo/webhook-bridge.d.ts.map +1 -1
- package/dist/providers/dodo/webhook-bridge.js.map +1 -1
- package/dist/providers/environment.d.ts +1 -1
- package/dist/providers/environment.d.ts.map +1 -1
- package/dist/providers/environment.js +4 -2
- package/dist/providers/environment.js.map +1 -1
- package/dist/providers/mock/provider.d.ts.map +1 -1
- package/dist/providers/mock/provider.js +5 -10
- 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 +104 -12
- package/dist/providers/stripe/event-mapper.js.map +1 -1
- package/dist/providers/stripe/provider.d.ts.map +1 -1
- package/dist/providers/stripe/provider.js +100 -60
- package/dist/providers/stripe/provider.js.map +1 -1
- package/dist/providers/types.d.ts +0 -1
- package/dist/providers/types.d.ts.map +1 -1
- package/dist/providers/types.js.map +1 -1
- package/dist/retry.d.ts.map +1 -1
- package/dist/retry.js +16 -9
- package/dist/retry.js.map +1 -1
- package/dist/shared/diagnostics.d.ts +10 -2
- package/dist/shared/diagnostics.d.ts.map +1 -1
- package/dist/shared/diagnostics.js +65 -6
- package/dist/shared/diagnostics.js.map +1 -1
- package/dist/shared/idempotency.d.ts +4 -3
- package/dist/shared/idempotency.d.ts.map +1 -1
- package/dist/shared/idempotency.js +21 -10
- package/dist/shared/idempotency.js.map +1 -1
- package/dist/shared/json.d.ts +28 -0
- package/dist/shared/json.d.ts.map +1 -0
- package/dist/shared/json.js +41 -0
- package/dist/shared/json.js.map +1 -0
- package/dist/shared/logger.d.ts +10 -4
- package/dist/shared/logger.d.ts.map +1 -1
- package/dist/shared/logger.js.map +1 -1
- package/dist/shared/postgres-client.d.ts +10 -5
- package/dist/shared/postgres-client.d.ts.map +1 -1
- package/dist/shared/postgres-client.js +80 -45
- package/dist/shared/postgres-client.js.map +1 -1
- package/dist/shared/postgres-errors.d.ts +1 -1
- package/dist/shared/postgres-errors.d.ts.map +1 -1
- package/dist/shared/postgres-errors.js +32 -31
- package/dist/shared/postgres-errors.js.map +1 -1
- package/dist/shared/postgres-types.d.ts +3 -2
- package/dist/shared/postgres-types.d.ts.map +1 -1
- package/dist/shared/postgres-types.js.map +1 -1
- package/dist/shared/postgres-validation.d.ts +7 -6
- package/dist/shared/postgres-validation.d.ts.map +1 -1
- package/dist/shared/postgres-validation.js +17 -10
- package/dist/shared/postgres-validation.js.map +1 -1
- package/dist/storage/adapters/clickhouse.d.ts +20 -6
- package/dist/storage/adapters/clickhouse.d.ts.map +1 -1
- package/dist/storage/adapters/clickhouse.js +150 -42
- package/dist/storage/adapters/clickhouse.js.map +1 -1
- package/dist/storage/adapters/s3.d.ts +67 -6
- package/dist/storage/adapters/s3.d.ts.map +1 -1
- package/dist/storage/adapters/s3.js +79 -26
- package/dist/storage/adapters/s3.js.map +1 -1
- package/dist/storage/diagnostics.d.ts +105 -0
- package/dist/storage/diagnostics.d.ts.map +1 -0
- package/dist/storage/diagnostics.js +228 -0
- package/dist/storage/diagnostics.js.map +1 -0
- package/dist/storage/maintenance.d.ts +88 -0
- package/dist/storage/maintenance.d.ts.map +1 -0
- package/dist/storage/maintenance.js +272 -0
- package/dist/storage/maintenance.js.map +1 -0
- package/dist/storage/outbox-worker.d.ts +21 -1
- package/dist/storage/outbox-worker.d.ts.map +1 -1
- package/dist/storage/outbox-worker.js +157 -28
- package/dist/storage/outbox-worker.js.map +1 -1
- package/dist/storage/ports.d.ts +52 -7
- package/dist/storage/ports.d.ts.map +1 -1
- package/dist/storage/ports.js.map +1 -1
- package/dist/storage/postgres-repository.d.ts +9 -2
- package/dist/storage/postgres-repository.d.ts.map +1 -1
- package/dist/storage/postgres-repository.js +97 -11
- package/dist/storage/postgres-repository.js.map +1 -1
- package/dist/storage/runtime.d.ts +20 -3
- package/dist/storage/runtime.d.ts.map +1 -1
- package/dist/storage/runtime.js +326 -156
- package/dist/storage/runtime.js.map +1 -1
- package/dist/telemetry/index.d.ts +41 -0
- package/dist/telemetry/index.d.ts.map +1 -0
- package/dist/telemetry/index.js +118 -0
- package/dist/telemetry/index.js.map +1 -0
- package/dist/telemetry/opentelemetry.d.ts +25 -0
- package/dist/telemetry/opentelemetry.d.ts.map +1 -0
- package/dist/telemetry/opentelemetry.js +74 -0
- package/dist/telemetry/opentelemetry.js.map +1 -0
- package/package.json +24 -14
package/dist/storage/runtime.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Bursar } from "../bursar.js";
|
|
2
1
|
import { z } from "zod";
|
|
2
|
+
import { Bursar } from "../bursar.js";
|
|
3
3
|
import { ConfigError, ImportError as BursarImportError, isRetryableBursarError, CatalogNotLoadedError, StoreClosedError, } from "../errors.js";
|
|
4
4
|
import { retryBursarOperation } from "../retry.js";
|
|
5
5
|
import { PostgresBillingStore } from "../billing/postgres/store.js";
|
|
@@ -8,43 +8,91 @@ import { normalizeProviderEnvironment, } from "../providers/environment.js";
|
|
|
8
8
|
import { normalizeTenantId, PostgresClient, postgresPoolConfig, } from "../shared/postgres-client.js";
|
|
9
9
|
import { ClickHouseUsageStore } from "./adapters/clickhouse.js";
|
|
10
10
|
import { S3BillingArchive } from "./adapters/s3.js";
|
|
11
|
+
import { RuntimeDiagnosticsTracker, } from "./diagnostics.js";
|
|
12
|
+
import { BursarMaintenance, BursarOperatorMaintenance } from "./maintenance.js";
|
|
11
13
|
import { OutboxWorker } from "./outbox-worker.js";
|
|
12
14
|
import { PostgresStorageRepository } from "./postgres-repository.js";
|
|
15
|
+
const abortSignalSchema = z.custom((value) => z
|
|
16
|
+
.object({
|
|
17
|
+
aborted: z.boolean(),
|
|
18
|
+
addEventListener: z.function(),
|
|
19
|
+
removeEventListener: z.function(),
|
|
20
|
+
throwIfAborted: z.function(),
|
|
21
|
+
})
|
|
22
|
+
.safeParse(value).success, "signal must be an AbortSignal");
|
|
23
|
+
const shouldRetrySchema = z.custom((value) => z.function().safeParse(value).success, "shouldRetry must be a function");
|
|
13
24
|
const runtimeStartOptionsSchema = z
|
|
14
25
|
.object({
|
|
15
26
|
loadCatalog: z.boolean().default(true),
|
|
16
27
|
maxAttempts: z.number().finite().int().min(1).max(Number.MAX_SAFE_INTEGER).default(1),
|
|
17
28
|
retryDelayMs: z.number().finite().min(0).max(5_000).default(250),
|
|
18
|
-
shouldRetry:
|
|
19
|
-
.custom((value) => typeof value === "function", "shouldRetry must be a function")
|
|
20
|
-
.optional(),
|
|
29
|
+
shouldRetry: shouldRetrySchema.optional(),
|
|
21
30
|
maxElapsedMs: z.number().finite().min(0).max(2_147_483_647).optional(),
|
|
22
|
-
signal:
|
|
23
|
-
.custom((value) => typeof value === "object" &&
|
|
24
|
-
value !== null &&
|
|
25
|
-
typeof value.throwIfAborted === "function", "signal must be an AbortSignal")
|
|
26
|
-
.optional(),
|
|
31
|
+
signal: abortSignalSchema.optional(),
|
|
27
32
|
})
|
|
28
33
|
.strict();
|
|
34
|
+
/** Coalesce concurrently dispatched usage events into one optional sink write. */
|
|
35
|
+
class UsageWriteBatcher {
|
|
36
|
+
sink;
|
|
37
|
+
pending = [];
|
|
38
|
+
scheduled = false;
|
|
39
|
+
constructor(sink) {
|
|
40
|
+
this.sink = sink;
|
|
41
|
+
}
|
|
42
|
+
write(event, outboxEventId) {
|
|
43
|
+
if (!this.sink.writeUsageBatch)
|
|
44
|
+
return this.sink.writeUsage(event, outboxEventId);
|
|
45
|
+
return new Promise((resolve, reject) => {
|
|
46
|
+
this.pending.push({ event, outboxEventId, resolve, reject });
|
|
47
|
+
if (this.scheduled)
|
|
48
|
+
return;
|
|
49
|
+
this.scheduled = true;
|
|
50
|
+
queueMicrotask(() => {
|
|
51
|
+
void this.flush();
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
async flush() {
|
|
56
|
+
const pending = this.pending.splice(0);
|
|
57
|
+
this.scheduled = false;
|
|
58
|
+
try {
|
|
59
|
+
await this.sink.writeUsageBatch(pending.map(({ event, outboxEventId }) => [event, outboxEventId]));
|
|
60
|
+
for (const write of pending)
|
|
61
|
+
write.resolve();
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
const failure = error instanceof Error ? error : new Error("Usage batch write failed", { cause: error });
|
|
65
|
+
for (const write of pending)
|
|
66
|
+
write.reject(failure);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
29
70
|
/**
|
|
30
71
|
* Node composition root for Bursar's stores and optional data infrastructure.
|
|
31
72
|
*
|
|
32
73
|
* Without S3 or ClickHouse it constructs the same PostgreSQL-only Bursar and
|
|
33
|
-
* no outbox polling loop.
|
|
74
|
+
* no outbox polling loop. Tenant and operator work always use distinct pools.
|
|
34
75
|
*/
|
|
35
76
|
export class BursarRuntime {
|
|
36
77
|
bursar;
|
|
37
78
|
creditStore;
|
|
38
79
|
billingStore;
|
|
80
|
+
maintenance;
|
|
81
|
+
operatorMaintenance;
|
|
39
82
|
worker;
|
|
83
|
+
outboxRecovery;
|
|
40
84
|
clickhouse;
|
|
41
85
|
s3;
|
|
42
86
|
pool;
|
|
87
|
+
operatorPool;
|
|
43
88
|
ownsPool;
|
|
89
|
+
ownsOperatorPool;
|
|
44
90
|
postgres;
|
|
45
91
|
query;
|
|
46
92
|
tenantId;
|
|
47
93
|
tenantSlug;
|
|
94
|
+
diagnosticsTracker;
|
|
95
|
+
usageBatcher;
|
|
48
96
|
providerEnvironment;
|
|
49
97
|
startPromise = null;
|
|
50
98
|
closePromise = null;
|
|
@@ -52,38 +100,60 @@ export class BursarRuntime {
|
|
|
52
100
|
closed = false;
|
|
53
101
|
/** Construct a runtime while keeping pool ownership inside the SDK. */
|
|
54
102
|
static async create(options) {
|
|
55
|
-
if (
|
|
56
|
-
|
|
103
|
+
if (options.operatorPostgres === undefined || options.operatorPostgres === null) {
|
|
104
|
+
throw new TypeError("operatorPostgres is required");
|
|
57
105
|
}
|
|
58
|
-
|
|
106
|
+
const postgresConnection = connectionStringValue(options.postgres);
|
|
107
|
+
const operatorPostgresConnection = connectionStringValue(options.operatorPostgres);
|
|
108
|
+
const ownsPool = postgresConnection !== null;
|
|
109
|
+
const ownsOperatorPool = operatorPostgresConnection !== null;
|
|
110
|
+
if (postgresConnection !== null && !postgresConnection.trim()) {
|
|
59
111
|
throw new TypeError("postgres connection string must not be empty");
|
|
60
112
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
pg = await import("pg");
|
|
64
|
-
}
|
|
65
|
-
catch (cause) {
|
|
66
|
-
throw new BursarImportError("pg is required for the Bursar runtime: npm install pg", {
|
|
67
|
-
cause,
|
|
68
|
-
});
|
|
113
|
+
if (operatorPostgresConnection !== null && !operatorPostgresConnection.trim()) {
|
|
114
|
+
throw new TypeError("operatorPostgres connection string must not be empty");
|
|
69
115
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return new BursarRuntime(pool, true, options);
|
|
116
|
+
if (options.postgres === options.operatorPostgres) {
|
|
117
|
+
throw new TypeError("postgres and operatorPostgres must use distinct connections");
|
|
73
118
|
}
|
|
74
|
-
|
|
119
|
+
let pg;
|
|
120
|
+
if (ownsPool || ownsOperatorPool) {
|
|
75
121
|
try {
|
|
76
|
-
await
|
|
122
|
+
pg = await import("pg");
|
|
77
123
|
}
|
|
78
|
-
catch {
|
|
79
|
-
|
|
124
|
+
catch (cause) {
|
|
125
|
+
throw new BursarImportError("pg is required for the Bursar runtime: npm install pg", {
|
|
126
|
+
cause,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
let pool;
|
|
131
|
+
let operatorPool;
|
|
132
|
+
try {
|
|
133
|
+
if ((ownsPool || ownsOperatorPool) && pg === undefined) {
|
|
134
|
+
throw new BursarImportError("pg is required for the Bursar runtime: npm install pg");
|
|
80
135
|
}
|
|
136
|
+
pool = ownsPool
|
|
137
|
+
? createOwnedPool(pg, postgresConnection ?? requiredConnectionString(options.postgres), options.postgresOptions)
|
|
138
|
+
: providedPool(options.postgres);
|
|
139
|
+
operatorPool = ownsOperatorPool
|
|
140
|
+
? createOwnedPool(pg, operatorPostgresConnection ?? requiredConnectionString(options.operatorPostgres), options.postgresOptions)
|
|
141
|
+
: providedPool(options.operatorPostgres);
|
|
142
|
+
return new BursarRuntime(pool, ownsPool, operatorPool, ownsOperatorPool, options);
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
await Promise.allSettled([
|
|
146
|
+
...(ownsPool && pool ? [pool.end()] : []),
|
|
147
|
+
...(ownsOperatorPool && operatorPool ? [operatorPool.end()] : []),
|
|
148
|
+
]);
|
|
81
149
|
throw error;
|
|
82
150
|
}
|
|
83
151
|
}
|
|
84
|
-
constructor(pool, ownsPool, options) {
|
|
152
|
+
constructor(pool, ownsPool, operatorPool, ownsOperatorPool, options) {
|
|
85
153
|
this.pool = pool;
|
|
154
|
+
this.operatorPool = operatorPool;
|
|
86
155
|
this.ownsPool = ownsPool;
|
|
156
|
+
this.ownsOperatorPool = ownsOperatorPool;
|
|
87
157
|
this.tenantId = normalizeTenantId(options.tenantId);
|
|
88
158
|
this.providerEnvironment = normalizeProviderEnvironment(options.providerEnvironment);
|
|
89
159
|
this.tenantSlug =
|
|
@@ -119,6 +189,7 @@ export class BursarRuntime {
|
|
|
119
189
|
? options.clickhouse
|
|
120
190
|
: new ClickHouseUsageStore({ ...options.clickhouse, tenantId: this.tenantId })
|
|
121
191
|
: null;
|
|
192
|
+
this.usageBatcher = this.clickhouse ? new UsageWriteBatcher(this.clickhouse) : null;
|
|
122
193
|
this.s3 = options.s3
|
|
123
194
|
? "archive" in options.s3
|
|
124
195
|
? options.s3
|
|
@@ -153,12 +224,10 @@ export class BursarRuntime {
|
|
|
153
224
|
creditsOptions: {
|
|
154
225
|
...(bursarOptions.creditsOptions ?? {}),
|
|
155
226
|
analytics: this.clickhouse ?? undefined,
|
|
156
|
-
usageStore: this.clickhouse &&
|
|
157
|
-
? this.clickhouse
|
|
158
|
-
: undefined,
|
|
227
|
+
usageStore: this.clickhouse && supportsUsageHistory(this.clickhouse) ? this.clickhouse : undefined,
|
|
159
228
|
},
|
|
160
229
|
});
|
|
161
|
-
this.postgres = new PostgresClient(
|
|
230
|
+
this.postgres = new PostgresClient(operatorPool, {
|
|
162
231
|
...(options.postgresOptions ?? {}),
|
|
163
232
|
tenantId: this.tenantId,
|
|
164
233
|
providerEnvironment: this.providerEnvironment,
|
|
@@ -167,12 +236,53 @@ export class BursarRuntime {
|
|
|
167
236
|
billingPayloadBackend: this.s3 ? "s3" : "postgres",
|
|
168
237
|
});
|
|
169
238
|
this.query = this.postgres.query;
|
|
239
|
+
this.maintenance = new BursarMaintenance({
|
|
240
|
+
expireLeases: (limit) => this.creditStore.expireLeases(limit),
|
|
241
|
+
expireCredits: async (limit) => (await this.creditStore.sweepExpiredCredits(false, undefined, limit)).expiredCount,
|
|
242
|
+
applyDuePlanChanges: (limit) => this.creditStore.applyDuePlanChanges(limit),
|
|
243
|
+
expirePastDueGracePeriods: this.bursar.billing
|
|
244
|
+
? (now) => this.bursar.billing.expirePastDueGracePeriods(now)
|
|
245
|
+
: undefined,
|
|
246
|
+
pastDueGracePeriodLimit: 100,
|
|
247
|
+
pastDueGracePeriodsUnavailableReason: this.bursar.billing
|
|
248
|
+
? undefined
|
|
249
|
+
: "billing is not configured",
|
|
250
|
+
});
|
|
251
|
+
this.operatorMaintenance = new BursarOperatorMaintenance(this.query);
|
|
170
252
|
const repository = new PostgresStorageRepository(this.query, this.tenantId);
|
|
253
|
+
this.outboxRecovery = repository;
|
|
171
254
|
const handlers = this.createHandlers(repository);
|
|
255
|
+
const configuredOutboxOptions = options.outbox === false || options.outbox === undefined ? {} : options.outbox;
|
|
256
|
+
const originalOnError = configuredOutboxOptions.onError;
|
|
257
|
+
let diagnosticsTracker = null;
|
|
258
|
+
const workerOptions = {
|
|
259
|
+
...configuredOutboxOptions,
|
|
260
|
+
onError: async (error) => {
|
|
261
|
+
diagnosticsTracker?.recordWorkerError(error);
|
|
262
|
+
await originalOnError?.(error);
|
|
263
|
+
},
|
|
264
|
+
};
|
|
172
265
|
this.worker =
|
|
173
266
|
handlers.length > 0 && options.outbox !== false
|
|
174
|
-
? new OutboxWorker(repository, handlers,
|
|
267
|
+
? new OutboxWorker(repository, handlers, workerOptions)
|
|
175
268
|
: null;
|
|
269
|
+
this.diagnosticsTracker = new RuntimeDiagnosticsTracker({
|
|
270
|
+
checkPostgres: async () => {
|
|
271
|
+
const rows = await this.query("SELECT 1 AS bursar_reachable");
|
|
272
|
+
const row = rows[0];
|
|
273
|
+
if (!row ||
|
|
274
|
+
!z.number().int().safeParse(row.bursar_reachable).success ||
|
|
275
|
+
row.bursar_reachable !== 1) {
|
|
276
|
+
throw new Error("PostgreSQL reachability check returned an invalid result");
|
|
277
|
+
}
|
|
278
|
+
},
|
|
279
|
+
getCatalogRevision: async () => {
|
|
280
|
+
const revision = await this.bursar.catalog.getActive();
|
|
281
|
+
return revision ? { id: revision.id, version: revision.version } : null;
|
|
282
|
+
},
|
|
283
|
+
getOutboxStatus: outboxStatusProvider(repository),
|
|
284
|
+
}, this.worker !== null);
|
|
285
|
+
diagnosticsTracker = this.diagnosticsTracker;
|
|
176
286
|
}
|
|
177
287
|
start(options = {}) {
|
|
178
288
|
if (this.closed) {
|
|
@@ -194,7 +304,7 @@ export class BursarRuntime {
|
|
|
194
304
|
await this.verifyTenantIdentity();
|
|
195
305
|
if (startOptions.loadCatalog) {
|
|
196
306
|
const shouldRetry = startOptions.shouldRetry ??
|
|
197
|
-
((
|
|
307
|
+
((cause) => cause instanceof CatalogNotLoadedError || isRetryableBursarError(cause));
|
|
198
308
|
await retryBursarOperation(() => this.bursar.loadCatalog(), {
|
|
199
309
|
maxAttempts: startOptions.maxAttempts,
|
|
200
310
|
baseDelayMs: startOptions.retryDelayMs,
|
|
@@ -205,22 +315,44 @@ export class BursarRuntime {
|
|
|
205
315
|
});
|
|
206
316
|
}
|
|
207
317
|
await this.clickhouse?.initialize?.();
|
|
318
|
+
await this.clickhouse?.checkSchemaCompatibility?.();
|
|
208
319
|
await this.worker?.start();
|
|
320
|
+
if (this.worker)
|
|
321
|
+
this.diagnosticsTracker.markWorkerStarted();
|
|
209
322
|
this.started = true;
|
|
210
323
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
324
|
+
state() {
|
|
325
|
+
return this.diagnosticsTracker.state({
|
|
326
|
+
started: this.started,
|
|
327
|
+
closed: this.closed,
|
|
328
|
+
catalogLoaded: this.bursar.catalog.isLoaded,
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
checkDependencies(options = {}) {
|
|
332
|
+
return this.diagnosticsTracker.checkDependencies({
|
|
215
333
|
started: this.started,
|
|
216
334
|
closed: this.closed,
|
|
217
|
-
catalogLoaded,
|
|
335
|
+
catalogLoaded: this.bursar.catalog.isLoaded,
|
|
336
|
+
}, options);
|
|
337
|
+
}
|
|
338
|
+
health() {
|
|
339
|
+
const state = this.state();
|
|
340
|
+
return {
|
|
341
|
+
ready: state.ready,
|
|
342
|
+
financialReady: state.financialReady,
|
|
343
|
+
projectionReady: state.projectionReady,
|
|
344
|
+
degraded: state.degraded,
|
|
345
|
+
started: state.started,
|
|
346
|
+
closed: state.closed,
|
|
347
|
+
catalogLoaded: state.catalogLoaded,
|
|
218
348
|
};
|
|
219
349
|
}
|
|
220
350
|
async flush() {
|
|
221
351
|
if (this.closed)
|
|
222
352
|
throw new StoreClosedError("BursarRuntime has been closed");
|
|
223
|
-
|
|
353
|
+
if (!this.worker)
|
|
354
|
+
return { claimed: 0, delivered: 0, failed: 0, claimLost: 0 };
|
|
355
|
+
return this.diagnosticsTracker.observeManualRun(() => this.worker.runOnce());
|
|
224
356
|
}
|
|
225
357
|
close() {
|
|
226
358
|
if (this.closePromise)
|
|
@@ -246,6 +378,10 @@ export class BursarRuntime {
|
|
|
246
378
|
catch (error) {
|
|
247
379
|
failures.push(error);
|
|
248
380
|
}
|
|
381
|
+
finally {
|
|
382
|
+
if (this.worker)
|
|
383
|
+
this.diagnosticsTracker.markWorkerStopped();
|
|
384
|
+
}
|
|
249
385
|
const resources = await Promise.allSettled([
|
|
250
386
|
Promise.resolve().then(() => this.s3?.close?.()),
|
|
251
387
|
Promise.resolve().then(() => this.creditStore.close()),
|
|
@@ -264,6 +400,14 @@ export class BursarRuntime {
|
|
|
264
400
|
failures.push(error);
|
|
265
401
|
}
|
|
266
402
|
}
|
|
403
|
+
if (this.ownsOperatorPool) {
|
|
404
|
+
try {
|
|
405
|
+
await this.operatorPool.end();
|
|
406
|
+
}
|
|
407
|
+
catch (error) {
|
|
408
|
+
failures.push(error);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
267
411
|
if (failures.length === 1)
|
|
268
412
|
throw failures[0];
|
|
269
413
|
if (failures.length > 1) {
|
|
@@ -290,7 +434,9 @@ export class BursarRuntime {
|
|
|
290
434
|
if (usage.chargeId !== outboxEvent.aggregateId) {
|
|
291
435
|
throw new Error("Usage export charge does not match its outbox event");
|
|
292
436
|
}
|
|
293
|
-
|
|
437
|
+
if (!this.usageBatcher)
|
|
438
|
+
throw new Error("ClickHouse usage sink is not configured");
|
|
439
|
+
await this.usageBatcher.write(usage, outboxEvent.eventId);
|
|
294
440
|
},
|
|
295
441
|
});
|
|
296
442
|
}
|
|
@@ -333,10 +479,8 @@ export class BursarRuntime {
|
|
|
333
479
|
return;
|
|
334
480
|
const rows = await this.query("SELECT bursar.resolve_active_tenant_for_trigger($1)::text AS tenant_id", [this.tenantSlug]);
|
|
335
481
|
const resolved = rows[0];
|
|
336
|
-
const tenantId = resolved
|
|
337
|
-
|
|
338
|
-
: undefined;
|
|
339
|
-
if (tenantId !== this.tenantId) {
|
|
482
|
+
const tenantId = z.string().safeParse(resolved?.tenant_id);
|
|
483
|
+
if (!tenantId.success || tenantId.data !== this.tenantId) {
|
|
340
484
|
throw new ConfigError(`Bursar tenant slug '${this.tenantSlug}' resolves to a different tenant ID`);
|
|
341
485
|
}
|
|
342
486
|
}
|
|
@@ -344,127 +488,153 @@ export class BursarRuntime {
|
|
|
344
488
|
export async function createBursarRuntime(options) {
|
|
345
489
|
return BursarRuntime.create(options);
|
|
346
490
|
}
|
|
491
|
+
function outboxStatusProvider(repository) {
|
|
492
|
+
return async (limit) => repository.stats({ limit });
|
|
493
|
+
}
|
|
494
|
+
function isPostgresConnectionString(value) {
|
|
495
|
+
return z.string().safeParse(value).success;
|
|
496
|
+
}
|
|
497
|
+
function connectionStringValue(value) {
|
|
498
|
+
const parsed = z.string().safeParse(value);
|
|
499
|
+
return parsed.success ? parsed.data : null;
|
|
500
|
+
}
|
|
501
|
+
function requiredConnectionString(value) {
|
|
502
|
+
const parsed = z.string().min(1).safeParse(value);
|
|
503
|
+
if (!parsed.success) {
|
|
504
|
+
throw new TypeError("an owned PostgreSQL pool requires a connection string");
|
|
505
|
+
}
|
|
506
|
+
return parsed.data;
|
|
507
|
+
}
|
|
508
|
+
function createOwnedPool(pg, connectionString, options) {
|
|
509
|
+
if (pg === undefined) {
|
|
510
|
+
throw new BursarImportError("pg is required for the Bursar runtime: npm install pg");
|
|
511
|
+
}
|
|
512
|
+
// SAFETY: the runtime's PostgresPool contract is the subset used by Bursar,
|
|
513
|
+
// and the node-postgres Pool is created from the validated connection options above.
|
|
514
|
+
return new pg.Pool(postgresPoolConfig(connectionString, options));
|
|
515
|
+
}
|
|
516
|
+
function providedPool(value) {
|
|
517
|
+
if (isPostgresConnectionString(value)) {
|
|
518
|
+
throw new TypeError("a connection string cannot be used as an external PostgreSQL pool");
|
|
519
|
+
}
|
|
520
|
+
return value;
|
|
521
|
+
}
|
|
522
|
+
function supportsUsageHistory(value) {
|
|
523
|
+
return z.object({ listUsageCharges: z.function() }).safeParse(value).success;
|
|
524
|
+
}
|
|
347
525
|
function normalizeTenantSlug(value) {
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
const normalized = value.trim().toLowerCase();
|
|
351
|
-
if (normalized.length < 1 ||
|
|
352
|
-
normalized.length > 100 ||
|
|
353
|
-
!/^[a-z0-9]+(?:[a-z0-9-]*[a-z0-9])?$/.test(normalized)) {
|
|
526
|
+
const trimmed = z.string().trim().min(1).max(100).safeParse(value);
|
|
527
|
+
if (!trimmed.success)
|
|
354
528
|
throw new TypeError("tenantSlug must be a valid Bursar tenant slug");
|
|
355
|
-
|
|
356
|
-
|
|
529
|
+
const normalized = z
|
|
530
|
+
.string()
|
|
531
|
+
.regex(/^[a-z0-9]+(?:[a-z0-9-]*[a-z0-9])?$/u)
|
|
532
|
+
.safeParse(trimmed.data.toLowerCase());
|
|
533
|
+
if (!normalized.success)
|
|
534
|
+
throw new TypeError("tenantSlug must be a valid Bursar tenant slug");
|
|
535
|
+
return normalized.data;
|
|
357
536
|
}
|
|
537
|
+
const outboxJsonObjectSchema = z.record(z.string(), z.json());
|
|
538
|
+
const usageOutboxPayloadSchema = z
|
|
539
|
+
.object({
|
|
540
|
+
tenant_id: z.string().min(1),
|
|
541
|
+
charge_id: z.string().min(1),
|
|
542
|
+
account_id: z.string().min(1),
|
|
543
|
+
subject_id: z.string().min(1),
|
|
544
|
+
operation: z.string().min(1),
|
|
545
|
+
feature: z.string().nullable().optional(),
|
|
546
|
+
model: z.string().nullable().optional(),
|
|
547
|
+
region: z.string().nullable().optional(),
|
|
548
|
+
measures: outboxJsonObjectSchema,
|
|
549
|
+
dimensions: outboxJsonObjectSchema,
|
|
550
|
+
metadata: outboxJsonObjectSchema,
|
|
551
|
+
requested: z.string().min(1),
|
|
552
|
+
charged: z.string().min(1),
|
|
553
|
+
allowance_requested: z.string().min(1),
|
|
554
|
+
allowance_covered: z.string().min(1),
|
|
555
|
+
billing_disposition: z.enum(["billable", "record_only"]).optional(),
|
|
556
|
+
catalog_revision_id: z.string().nullable().optional(),
|
|
557
|
+
plan_id: z.string().nullable().optional(),
|
|
558
|
+
rate_card_key: z.string().nullable().optional(),
|
|
559
|
+
pricing_snapshot: outboxJsonObjectSchema,
|
|
560
|
+
ledger_entry_id: z.string().nullable().optional(),
|
|
561
|
+
correction_of_charge_id: z.string().nullable().optional(),
|
|
562
|
+
idempotency_key: z.string().min(1),
|
|
563
|
+
request_digest: z.string().min(1),
|
|
564
|
+
event_at: z.string().min(1),
|
|
565
|
+
created_at: z.string().min(1),
|
|
566
|
+
})
|
|
567
|
+
.passthrough();
|
|
568
|
+
const billingOutboxPayloadSchema = z
|
|
569
|
+
.object({
|
|
570
|
+
tenant_id: z.string().min(1),
|
|
571
|
+
event_id: z.string().min(1),
|
|
572
|
+
provider: z.string().min(1),
|
|
573
|
+
provider_environment: z.string().min(1),
|
|
574
|
+
provider_event_id: z.string().min(1),
|
|
575
|
+
event_type: z.string().min(1),
|
|
576
|
+
status: z.string().min(1),
|
|
577
|
+
received_at: z.string().min(1),
|
|
578
|
+
completed_at: z.string().nullable().optional(),
|
|
579
|
+
envelope: outboxJsonObjectSchema,
|
|
580
|
+
object_key: z.string().nullable().optional(),
|
|
581
|
+
object_version: z.string().nullable().optional(),
|
|
582
|
+
archived_at: z.string().nullable().optional(),
|
|
583
|
+
})
|
|
584
|
+
.passthrough();
|
|
358
585
|
function usageExportFromOutbox(payload) {
|
|
359
|
-
const
|
|
360
|
-
|
|
361
|
-
"charge_id",
|
|
362
|
-
"account_id",
|
|
363
|
-
"subject_id",
|
|
364
|
-
"operation",
|
|
365
|
-
"requested",
|
|
366
|
-
"charged",
|
|
367
|
-
"allowance_requested",
|
|
368
|
-
"allowance_covered",
|
|
369
|
-
"idempotency_key",
|
|
370
|
-
"request_digest",
|
|
371
|
-
"event_at",
|
|
372
|
-
"created_at",
|
|
373
|
-
];
|
|
374
|
-
if (requiredStrings.some((key) => !isNonEmptyString(payload[key])))
|
|
375
|
-
return null;
|
|
376
|
-
if (!isJsonObject(payload.measures) ||
|
|
377
|
-
!isJsonObject(payload.dimensions) ||
|
|
378
|
-
!isJsonObject(payload.metadata) ||
|
|
379
|
-
!isJsonObject(payload.pricing_snapshot)) {
|
|
586
|
+
const parsed = usageOutboxPayloadSchema.safeParse(payload);
|
|
587
|
+
if (!parsed.success)
|
|
380
588
|
return null;
|
|
381
|
-
|
|
382
|
-
const optionalStrings = [
|
|
383
|
-
"feature",
|
|
384
|
-
"model",
|
|
385
|
-
"region",
|
|
386
|
-
"catalog_revision_id",
|
|
387
|
-
"plan_id",
|
|
388
|
-
"rate_card_key",
|
|
389
|
-
"ledger_entry_id",
|
|
390
|
-
"correction_of_charge_id",
|
|
391
|
-
];
|
|
392
|
-
if (optionalStrings.some((key) => !isOptionalString(payload[key])))
|
|
393
|
-
return null;
|
|
394
|
-
if (payload.billing_disposition !== undefined &&
|
|
395
|
-
payload.billing_disposition !== "billable" &&
|
|
396
|
-
payload.billing_disposition !== "record_only") {
|
|
397
|
-
return null;
|
|
398
|
-
}
|
|
589
|
+
const value = parsed.data;
|
|
399
590
|
return {
|
|
400
|
-
tenantId:
|
|
401
|
-
chargeId:
|
|
402
|
-
accountId:
|
|
403
|
-
subjectId:
|
|
404
|
-
operation:
|
|
405
|
-
feature:
|
|
406
|
-
model:
|
|
407
|
-
region:
|
|
408
|
-
measures:
|
|
409
|
-
dimensions:
|
|
410
|
-
metadata:
|
|
411
|
-
requested:
|
|
412
|
-
charged:
|
|
413
|
-
allowanceRequested:
|
|
414
|
-
allowanceCovered:
|
|
415
|
-
billingDisposition:
|
|
416
|
-
catalogRevisionId:
|
|
417
|
-
planId:
|
|
418
|
-
rateCardKey:
|
|
419
|
-
pricingSnapshot:
|
|
420
|
-
ledgerEntryId:
|
|
421
|
-
correctionOfChargeId:
|
|
422
|
-
idempotencyKey:
|
|
423
|
-
requestDigest:
|
|
424
|
-
eventAt:
|
|
425
|
-
createdAt:
|
|
591
|
+
tenantId: value.tenant_id,
|
|
592
|
+
chargeId: value.charge_id,
|
|
593
|
+
accountId: value.account_id,
|
|
594
|
+
subjectId: value.subject_id,
|
|
595
|
+
operation: value.operation,
|
|
596
|
+
feature: value.feature ?? null,
|
|
597
|
+
model: value.model ?? null,
|
|
598
|
+
region: value.region ?? null,
|
|
599
|
+
measures: value.measures,
|
|
600
|
+
dimensions: value.dimensions,
|
|
601
|
+
metadata: value.metadata,
|
|
602
|
+
requested: value.requested,
|
|
603
|
+
charged: value.charged,
|
|
604
|
+
allowanceRequested: value.allowance_requested,
|
|
605
|
+
allowanceCovered: value.allowance_covered,
|
|
606
|
+
billingDisposition: value.billing_disposition ?? "billable",
|
|
607
|
+
catalogRevisionId: value.catalog_revision_id ?? null,
|
|
608
|
+
planId: value.plan_id ?? null,
|
|
609
|
+
rateCardKey: value.rate_card_key ?? null,
|
|
610
|
+
pricingSnapshot: value.pricing_snapshot,
|
|
611
|
+
ledgerEntryId: value.ledger_entry_id ?? null,
|
|
612
|
+
correctionOfChargeId: value.correction_of_charge_id ?? null,
|
|
613
|
+
idempotencyKey: value.idempotency_key,
|
|
614
|
+
requestDigest: value.request_digest,
|
|
615
|
+
eventAt: value.event_at,
|
|
616
|
+
createdAt: value.created_at,
|
|
426
617
|
};
|
|
427
618
|
}
|
|
428
619
|
function billingExportFromOutbox(payload) {
|
|
429
|
-
const
|
|
430
|
-
|
|
431
|
-
"event_id",
|
|
432
|
-
"provider",
|
|
433
|
-
"provider_environment",
|
|
434
|
-
"provider_event_id",
|
|
435
|
-
"event_type",
|
|
436
|
-
"status",
|
|
437
|
-
"received_at",
|
|
438
|
-
];
|
|
439
|
-
if (requiredStrings.some((key) => !isNonEmptyString(payload[key])))
|
|
440
|
-
return null;
|
|
441
|
-
if (!isJsonObject(payload.envelope))
|
|
442
|
-
return null;
|
|
443
|
-
if (!isOptionalString(payload.completed_at))
|
|
620
|
+
const parsed = billingOutboxPayloadSchema.safeParse(payload);
|
|
621
|
+
if (!parsed.success)
|
|
444
622
|
return null;
|
|
623
|
+
const value = parsed.data;
|
|
445
624
|
return {
|
|
446
|
-
tenantId:
|
|
447
|
-
eventId:
|
|
448
|
-
provider:
|
|
449
|
-
providerEnvironment:
|
|
450
|
-
providerEventId:
|
|
451
|
-
eventType:
|
|
452
|
-
status:
|
|
453
|
-
receivedAt:
|
|
454
|
-
completedAt:
|
|
455
|
-
envelope:
|
|
456
|
-
objectKey:
|
|
457
|
-
objectVersion:
|
|
458
|
-
archivedAt:
|
|
625
|
+
tenantId: value.tenant_id,
|
|
626
|
+
eventId: value.event_id,
|
|
627
|
+
provider: value.provider,
|
|
628
|
+
providerEnvironment: value.provider_environment,
|
|
629
|
+
providerEventId: value.provider_event_id,
|
|
630
|
+
eventType: value.event_type,
|
|
631
|
+
status: value.status,
|
|
632
|
+
receivedAt: value.received_at,
|
|
633
|
+
completedAt: value.completed_at ?? null,
|
|
634
|
+
envelope: value.envelope,
|
|
635
|
+
objectKey: value.object_key ?? null,
|
|
636
|
+
objectVersion: value.object_version ?? null,
|
|
637
|
+
archivedAt: value.archived_at ?? null,
|
|
459
638
|
};
|
|
460
639
|
}
|
|
461
|
-
function isNonEmptyString(value) {
|
|
462
|
-
return typeof value === "string" && value.length > 0;
|
|
463
|
-
}
|
|
464
|
-
function isOptionalString(value) {
|
|
465
|
-
return value === null || value === undefined || typeof value === "string";
|
|
466
|
-
}
|
|
467
|
-
function isJsonObject(value) {
|
|
468
|
-
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
469
|
-
}
|
|
470
640
|
//# sourceMappingURL=runtime.js.map
|