@zonastery/bursar 2.0.6 → 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 +33 -4
- package/dist/billing/auto-recharge-port.d.ts +11 -0
- 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.map +1 -1
- package/dist/billing/auto-recharge-service.js +53 -26
- package/dist/billing/auto-recharge-service.js.map +1 -1
- package/dist/billing/billing-service.d.ts +38 -3
- package/dist/billing/billing-service.d.ts.map +1 -1
- package/dist/billing/billing-service.js +51 -7
- package/dist/billing/billing-service.js.map +1 -1
- package/dist/billing/billing-store.d.ts +34 -9
- 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 +35 -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 -2
- package/dist/billing/event-handlers.d.ts.map +1 -1
- package/dist/billing/event-handlers.js +69 -29
- package/dist/billing/event-handlers.js.map +1 -1
- package/dist/billing/event-processor.d.ts +2 -2
- package/dist/billing/event-processor.d.ts.map +1 -1
- package/dist/billing/event-processor.js +82 -19
- 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 +168 -44
- 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 +16 -3
- package/dist/billing/management.d.ts.map +1 -1
- package/dist/billing/management.js +11 -2
- package/dist/billing/management.js.map +1 -1
- package/dist/billing/postgres/repositories/auto-recharge.d.ts +13 -1
- package/dist/billing/postgres/repositories/auto-recharge.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/auto-recharge.js +71 -12
- 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 +5 -1
- package/dist/billing/postgres/repositories/offer.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/offer.js +7 -10
- 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 -16
- 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 +25 -4
- package/dist/billing/postgres/repositories/subscription-change.js.map +1 -1
- package/dist/billing/postgres/repositories/subscription.d.ts +3 -2
- package/dist/billing/postgres/repositories/subscription.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/subscription.js +44 -48
- 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 +27 -10
- package/dist/billing/postgres/repositories/topup.js.map +1 -1
- package/dist/billing/postgres/store.d.ts +46 -34
- package/dist/billing/postgres/store.d.ts.map +1 -1
- package/dist/billing/postgres/store.js +152 -126
- package/dist/billing/postgres/store.js.map +1 -1
- package/dist/billing/service-types.d.ts +0 -1
- package/dist/billing/service-types.d.ts.map +1 -1
- package/dist/billing/service-types.js.map +1 -1
- package/dist/billing/types/auto-recharge.d.ts +2 -0
- 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 -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 +12 -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 +13 -21
- package/dist/bursar.d.ts.map +1 -1
- package/dist/bursar.js +44 -50
- package/dist/bursar.js.map +1 -1
- package/dist/catalog.d.ts +21 -2
- package/dist/catalog.d.ts.map +1 -1
- package/dist/catalog.js +27 -4
- package/dist/catalog.js.map +1 -1
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +147 -0
- package/dist/cli.js.map +1 -0
- package/dist/commerce/plan-change.d.ts +3 -3
- package/dist/commerce/plan-change.d.ts.map +1 -1
- package/dist/commerce/plan-change.js +14 -7
- package/dist/commerce/plan-change.js.map +1 -1
- package/dist/commerce/provider-registry.d.ts.map +1 -1
- package/dist/commerce/provider-registry.js +8 -2
- package/dist/commerce/provider-registry.js.map +1 -1
- package/dist/commerce/service.d.ts +2 -0
- package/dist/commerce/service.d.ts.map +1 -1
- package/dist/commerce/service.js +330 -76
- package/dist/commerce/service.js.map +1 -1
- package/dist/commerce/types.d.ts +12 -3
- package/dist/commerce/types.d.ts.map +1 -1
- package/dist/commerce/types.js.map +1 -1
- package/dist/config/availability.d.ts +4 -0
- package/dist/config/availability.d.ts.map +1 -0
- package/dist/config/availability.js +10 -0
- package/dist/config/availability.js.map +1 -0
- package/dist/config/normalize.d.ts +7 -0
- package/dist/config/normalize.d.ts.map +1 -0
- package/dist/config/normalize.js +119 -0
- package/dist/config/normalize.js.map +1 -0
- 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 +5 -1
- package/dist/config/parse-commerce.d.ts.map +1 -1
- package/dist/config/parse-commerce.js +79 -22
- 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 +10 -7
- 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 +31 -15
- 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 +42 -27
- package/dist/config/parse-pricing.js.map +1 -1
- package/dist/config/parse-utils.d.ts +4 -0
- package/dist/config/parse-utils.d.ts.map +1 -1
- package/dist/config/parse-utils.js +26 -1
- package/dist/config/parse-utils.js.map +1 -1
- package/dist/config/types.d.ts +8 -4
- package/dist/config/types.d.ts.map +1 -1
- package/dist/config/types.js.map +1 -1
- package/dist/config.d.ts +5 -4
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +118 -70
- 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 +77 -21
- 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 +6 -1
- package/dist/credits/postgres/repositories/plan.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/plan.js +13 -3
- 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 +30 -20
- package/dist/credits/postgres/store.d.ts.map +1 -1
- package/dist/credits/postgres/store.js +335 -251
- 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 +12 -9
- package/dist/credits/service.d.ts.map +1 -1
- package/dist/credits/service.js +161 -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/catalog.d.ts +1 -0
- 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 +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 +4 -1
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +59 -36
- 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 +272 -228
- package/dist/generated/pricing-config.types.d.ts +128 -79
- 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 +8 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/load-config-file.d.ts +5 -1
- package/dist/load-config-file.d.ts.map +1 -1
- package/dist/load-config-file.js +56 -17
- 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 +2 -2
- package/dist/node.d.ts.map +1 -1
- package/dist/node.js +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 +124 -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 +46 -7
- 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 +51 -24
- 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 +118 -34
- package/dist/providers/stripe/provider.js.map +1 -1
- package/dist/providers/types.d.ts +16 -2
- 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 +5 -0
- package/dist/shared/postgres-client.d.ts.map +1 -1
- package/dist/shared/postgres-client.js +72 -11
- package/dist/shared/postgres-client.js.map +1 -1
- package/dist/shared/postgres-errors.d.ts.map +1 -1
- package/dist/shared/postgres-errors.js +6 -0
- package/dist/shared/postgres-errors.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 +5 -0
- package/dist/shared/timestamp.d.ts.map +1 -0
- package/dist/shared/timestamp.js +21 -0
- package/dist/shared/timestamp.js.map +1 -0
- package/dist/starter.yaml +17 -0
- 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 +42 -37
- 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 +8 -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 +34 -12
- package/dist/storage/postgres-repository.js.map +1 -1
- package/dist/storage/raw-json.d.ts +10 -0
- package/dist/storage/raw-json.d.ts.map +1 -0
- package/dist/storage/raw-json.js +19 -0
- package/dist/storage/raw-json.js.map +1 -0
- package/dist/storage/runtime.d.ts +15 -10
- package/dist/storage/runtime.d.ts.map +1 -1
- package/dist/storage/runtime.js +97 -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 +78 -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
|
@@ -6,11 +6,11 @@ import type { CreditsServiceOptions } from "../credits/service.js";
|
|
|
6
6
|
import type { CreditEventEmitter } from "../credits/events.js";
|
|
7
7
|
import type { CommerceOptions } from "../commerce/types.js";
|
|
8
8
|
import { type ProviderEnvironment } from "../providers/environment.js";
|
|
9
|
-
import type { UsageAnalyticsStore } from "../credits/types/index.js";
|
|
9
|
+
import type { UsageAnalyticsStore, UsageChargeStore } from "../credits/types/index.js";
|
|
10
10
|
import { type PostgresConnectionOptions, type PostgresPool } from "../shared/postgres-client.js";
|
|
11
11
|
import { type ClickHouseUsageStoreOptions } from "./adapters/clickhouse.js";
|
|
12
12
|
import { type S3BillingArchiveOptions } from "./adapters/s3.js";
|
|
13
|
-
import { type BursarRuntimeDiagnostics, type BursarRuntimeState
|
|
13
|
+
import { type BursarRuntimeDiagnostics, type BursarRuntimeState } from "./diagnostics.js";
|
|
14
14
|
import { BursarMaintenance, BursarOperatorMaintenance } from "./maintenance.js";
|
|
15
15
|
import { OutboxWorker, type OutboxRunResult, type OutboxWorkerOptions } from "./outbox-worker.js";
|
|
16
16
|
import type { BillingPayloadArchive, OutboxRecoveryStore, UsageEventSink } from "./ports.js";
|
|
@@ -24,8 +24,8 @@ export interface BursarRuntimeBursarOptions {
|
|
|
24
24
|
export interface BursarRuntimeOptions {
|
|
25
25
|
/** Tenant-scoped caller with SET-only membership in bursar_client. */
|
|
26
26
|
postgres: string | PostgresPool;
|
|
27
|
-
/**
|
|
28
|
-
operatorPostgres
|
|
27
|
+
/** Operator caller; required for local outbox delivery, recovery, maintenance and slug verification. */
|
|
28
|
+
operatorPostgres?: string | PostgresPool;
|
|
29
29
|
/** Explicit financial namespace shared by persistence and provider factories. */
|
|
30
30
|
providerEnvironment: ProviderEnvironment;
|
|
31
31
|
/** Applied to SDK-owned pools and per-transaction statement deadlines. */
|
|
@@ -37,7 +37,7 @@ export interface BursarRuntimeOptions {
|
|
|
37
37
|
*/
|
|
38
38
|
tenantSlug?: string;
|
|
39
39
|
s3?: BillingPayloadArchive | S3BillingArchiveOptions;
|
|
40
|
-
clickhouse?: (UsageEventSink & UsageAnalyticsStore) | ClickHouseUsageStoreOptions;
|
|
40
|
+
clickhouse?: (UsageEventSink & UsageAnalyticsStore & UsageChargeStore) | ClickHouseUsageStoreOptions;
|
|
41
41
|
/**
|
|
42
42
|
* Background delivery configuration. Set false only when another process
|
|
43
43
|
* consumes Bursar's outbox.
|
|
@@ -71,17 +71,15 @@ export interface BursarRuntimeHealth {
|
|
|
71
71
|
* Node composition root for Bursar's stores and optional data infrastructure.
|
|
72
72
|
*
|
|
73
73
|
* Without S3 or ClickHouse it constructs the same PostgreSQL-only Bursar and
|
|
74
|
-
* no outbox polling loop.
|
|
74
|
+
* no outbox polling loop. When configured, operator work uses a distinct pool.
|
|
75
75
|
*/
|
|
76
76
|
export declare class BursarRuntime {
|
|
77
77
|
readonly bursar: Bursar;
|
|
78
78
|
readonly creditStore: PostgresStore;
|
|
79
79
|
readonly billingStore: PostgresBillingStore;
|
|
80
80
|
readonly maintenance: BursarMaintenance;
|
|
81
|
-
readonly operatorMaintenance: BursarOperatorMaintenance;
|
|
82
81
|
readonly worker: OutboxWorker | null;
|
|
83
|
-
readonly
|
|
84
|
-
readonly clickhouse: (UsageEventSink & UsageAnalyticsStore) | null;
|
|
82
|
+
readonly clickhouse: RuntimeClickhouseHistoryStore | null;
|
|
85
83
|
readonly s3: BillingPayloadArchive | null;
|
|
86
84
|
private readonly pool;
|
|
87
85
|
private readonly operatorPool;
|
|
@@ -89,6 +87,8 @@ export declare class BursarRuntime {
|
|
|
89
87
|
private readonly ownsOperatorPool;
|
|
90
88
|
private readonly postgres;
|
|
91
89
|
private readonly query;
|
|
90
|
+
private readonly operatorMaintenanceValue;
|
|
91
|
+
private readonly outboxRecoveryValue;
|
|
92
92
|
private readonly tenantId;
|
|
93
93
|
private readonly tenantSlug;
|
|
94
94
|
private readonly diagnosticsTracker;
|
|
@@ -101,10 +101,12 @@ export declare class BursarRuntime {
|
|
|
101
101
|
/** Construct a runtime while keeping pool ownership inside the SDK. */
|
|
102
102
|
static create(options: BursarRuntimeOptions): Promise<BursarRuntime>;
|
|
103
103
|
private constructor();
|
|
104
|
+
get operatorMaintenance(): BursarOperatorMaintenance;
|
|
105
|
+
get outboxRecovery(): OutboxRecoveryStore;
|
|
104
106
|
start(options?: BursarRuntimeStartOptions): Promise<void>;
|
|
105
107
|
private startRuntime;
|
|
106
108
|
state(): BursarRuntimeState;
|
|
107
|
-
checkDependencies(
|
|
109
|
+
checkDependencies(): Promise<BursarRuntimeDiagnostics>;
|
|
108
110
|
health(): BursarRuntimeHealth;
|
|
109
111
|
flush(): Promise<OutboxRunResult>;
|
|
110
112
|
close(): Promise<void>;
|
|
@@ -113,4 +115,7 @@ export declare class BursarRuntime {
|
|
|
113
115
|
private verifyTenantIdentity;
|
|
114
116
|
}
|
|
115
117
|
export declare function createBursarRuntime(options: BursarRuntimeOptions): Promise<BursarRuntime>;
|
|
118
|
+
type RuntimeClickhouseStore = UsageEventSink & UsageAnalyticsStore;
|
|
119
|
+
type RuntimeClickhouseHistoryStore = RuntimeClickhouseStore & UsageChargeStore;
|
|
120
|
+
export {};
|
|
116
121
|
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/storage/runtime.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/storage/runtime.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,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C,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,aAAa,CAAC,CA6DzE;IAED,OAAO,eAiLN;IAED,IAAI,mBAAmB,IAAI,yBAAyB,CAInD;IAED,IAAI,cAAc,IAAI,mBAAmB,CAIxC;IAED,KAAK,CAAC,OAAO,GAAE,yBAA8B,GAAG,OAAO,CAAC,IAAI,CAAC,CAY5D;YAEa,YAAY;IA4B1B,KAAK,IAAI,kBAAkB,CAM1B;IAED,iBAAiB,IAAI,OAAO,CAAC,wBAAwB,CAAC,CAMrD;IAED,MAAM,IAAI,mBAAmB,CAW5B;IAEK,KAAK,IAAI,OAAO,CAAC,eAAe,CAAC,CAItC;IAED,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAKrB;YAEa,YAAY;IAkD1B,OAAO,CAAC,cAAc;YAmER,oBAAoB;CAenC;AAED,wBAAsB,mBAAmB,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,aAAa,CAAC,CAE/F;AAgCD,KAAK,sBAAsB,GAAG,cAAc,GAAG,mBAAmB,CAAC;AACnE,KAAK,6BAA6B,GAAG,sBAAsB,GAAG,gBAAgB,CAAC"}
|
package/dist/storage/runtime.js
CHANGED
|
@@ -71,16 +71,14 @@ class UsageWriteBatcher {
|
|
|
71
71
|
* Node composition root for Bursar's stores and optional data infrastructure.
|
|
72
72
|
*
|
|
73
73
|
* Without S3 or ClickHouse it constructs the same PostgreSQL-only Bursar and
|
|
74
|
-
* no outbox polling loop.
|
|
74
|
+
* no outbox polling loop. When configured, operator work uses a distinct pool.
|
|
75
75
|
*/
|
|
76
76
|
export class BursarRuntime {
|
|
77
77
|
bursar;
|
|
78
78
|
creditStore;
|
|
79
79
|
billingStore;
|
|
80
80
|
maintenance;
|
|
81
|
-
operatorMaintenance;
|
|
82
81
|
worker;
|
|
83
|
-
outboxRecovery;
|
|
84
82
|
clickhouse;
|
|
85
83
|
s3;
|
|
86
84
|
pool;
|
|
@@ -89,6 +87,8 @@ export class BursarRuntime {
|
|
|
89
87
|
ownsOperatorPool;
|
|
90
88
|
postgres;
|
|
91
89
|
query;
|
|
90
|
+
operatorMaintenanceValue;
|
|
91
|
+
outboxRecoveryValue;
|
|
92
92
|
tenantId;
|
|
93
93
|
tenantSlug;
|
|
94
94
|
diagnosticsTracker;
|
|
@@ -100,11 +100,18 @@ export class BursarRuntime {
|
|
|
100
100
|
closed = false;
|
|
101
101
|
/** Construct a runtime while keeping pool ownership inside the SDK. */
|
|
102
102
|
static async create(options) {
|
|
103
|
-
if (options.operatorPostgres ===
|
|
104
|
-
throw new TypeError("operatorPostgres
|
|
105
|
-
|
|
103
|
+
if (options.operatorPostgres === null)
|
|
104
|
+
throw new TypeError("operatorPostgres must not be null");
|
|
105
|
+
if (options.operatorPostgres === undefined && options.tenantSlug !== undefined)
|
|
106
|
+
throw new TypeError("operatorPostgres is required to verify tenantSlug");
|
|
107
|
+
if (options.operatorPostgres === undefined &&
|
|
108
|
+
(options.clickhouse || options.s3) &&
|
|
109
|
+
options.outbox !== false)
|
|
110
|
+
throw new TypeError("operatorPostgres is required for local outbox delivery; set outbox to false for external delivery");
|
|
106
111
|
const postgresConnection = connectionStringValue(options.postgres);
|
|
107
|
-
const operatorPostgresConnection =
|
|
112
|
+
const operatorPostgresConnection = options.operatorPostgres === undefined
|
|
113
|
+
? null
|
|
114
|
+
: connectionStringValue(options.operatorPostgres);
|
|
108
115
|
const ownsPool = postgresConnection !== null;
|
|
109
116
|
const ownsOperatorPool = operatorPostgresConnection !== null;
|
|
110
117
|
if (postgresConnection !== null && !postgresConnection.trim()) {
|
|
@@ -113,7 +120,7 @@ export class BursarRuntime {
|
|
|
113
120
|
if (operatorPostgresConnection !== null && !operatorPostgresConnection.trim()) {
|
|
114
121
|
throw new TypeError("operatorPostgres connection string must not be empty");
|
|
115
122
|
}
|
|
116
|
-
if (options.postgres === options.operatorPostgres) {
|
|
123
|
+
if (options.operatorPostgres !== undefined && options.postgres === options.operatorPostgres) {
|
|
117
124
|
throw new TypeError("postgres and operatorPostgres must use distinct connections");
|
|
118
125
|
}
|
|
119
126
|
let pg;
|
|
@@ -133,13 +140,15 @@ export class BursarRuntime {
|
|
|
133
140
|
if ((ownsPool || ownsOperatorPool) && pg === undefined) {
|
|
134
141
|
throw new BursarImportError("pg is required for the Bursar runtime: npm install pg");
|
|
135
142
|
}
|
|
136
|
-
pool =
|
|
137
|
-
? createOwnedPool(pg,
|
|
138
|
-
:
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
+
pool = isPostgresConnectionString(options.postgres)
|
|
144
|
+
? createOwnedPool(pg, options.postgres, options.postgresOptions)
|
|
145
|
+
: options.postgres;
|
|
146
|
+
if (options.operatorPostgres !== undefined) {
|
|
147
|
+
operatorPool = isPostgresConnectionString(options.operatorPostgres)
|
|
148
|
+
? createOwnedPool(pg, options.operatorPostgres, options.postgresOptions)
|
|
149
|
+
: options.operatorPostgres;
|
|
150
|
+
}
|
|
151
|
+
return new BursarRuntime(pool, ownsPool, operatorPool ?? null, ownsOperatorPool, options);
|
|
143
152
|
}
|
|
144
153
|
catch (error) {
|
|
145
154
|
await Promise.allSettled([
|
|
@@ -184,11 +193,15 @@ export class BursarRuntime {
|
|
|
184
193
|
normalizeTenantId(options.clickhouse.tenantId) !== this.tenantId) {
|
|
185
194
|
throw new TypeError("ClickHouse tenantId must match runtime tenantId");
|
|
186
195
|
}
|
|
187
|
-
|
|
196
|
+
const clickhouse = options.clickhouse
|
|
188
197
|
? "writeUsage" in options.clickhouse
|
|
189
198
|
? options.clickhouse
|
|
190
199
|
: new ClickHouseUsageStore({ ...options.clickhouse, tenantId: this.tenantId })
|
|
191
200
|
: null;
|
|
201
|
+
if (clickhouse && !supportsUsageHistory(clickhouse)) {
|
|
202
|
+
throw new TypeError("ClickHouse usage store must support listUsageCharges");
|
|
203
|
+
}
|
|
204
|
+
this.clickhouse = clickhouse;
|
|
192
205
|
this.usageBatcher = this.clickhouse ? new UsageWriteBatcher(this.clickhouse) : null;
|
|
193
206
|
this.s3 = options.s3
|
|
194
207
|
? "archive" in options.s3
|
|
@@ -196,16 +209,16 @@ export class BursarRuntime {
|
|
|
196
209
|
: new S3BillingArchive(options.s3)
|
|
197
210
|
: null;
|
|
198
211
|
this.creditStore = new PostgresStore({
|
|
212
|
+
...options.postgresOptions,
|
|
199
213
|
postgres: pool,
|
|
200
214
|
tenantId: this.tenantId,
|
|
201
|
-
...(options.postgresOptions ?? {}),
|
|
202
215
|
providerEnvironment: this.providerEnvironment,
|
|
203
216
|
usageBackend: this.clickhouse ? "clickhouse" : "postgres",
|
|
204
217
|
});
|
|
205
218
|
this.billingStore = new PostgresBillingStore({
|
|
219
|
+
...options.postgresOptions,
|
|
206
220
|
postgres: pool,
|
|
207
221
|
tenantId: this.tenantId,
|
|
208
|
-
...(options.postgresOptions ?? {}),
|
|
209
222
|
providerEnvironment: this.providerEnvironment,
|
|
210
223
|
billingPayloadBackend: this.s3 ? "s3" : "postgres",
|
|
211
224
|
});
|
|
@@ -216,6 +229,21 @@ export class BursarRuntime {
|
|
|
216
229
|
providerEnvironment: this.providerEnvironment,
|
|
217
230
|
}
|
|
218
231
|
: undefined;
|
|
232
|
+
const usage = this.clickhouse;
|
|
233
|
+
const guardedAnalytics = usage
|
|
234
|
+
? {
|
|
235
|
+
spendByUser: (start, end) => this.creditStore.withUsageBackend("clickhouse", () => usage.spendByUser(start, end)),
|
|
236
|
+
spendByModel: (start, end) => this.creditStore.withUsageBackend("clickhouse", () => usage.spendByModel(start, end)),
|
|
237
|
+
topUsers: (limit, start, end) => this.creditStore.withUsageBackend("clickhouse", () => usage.topUsers(limit, start, end)),
|
|
238
|
+
dailySpend: (start, end) => this.creditStore.withUsageBackend("clickhouse", () => usage.dailySpend(start, end)),
|
|
239
|
+
aggregateStats: (start, end) => this.creditStore.withUsageBackend("clickhouse", () => usage.aggregateStats(start, end)),
|
|
240
|
+
}
|
|
241
|
+
: undefined;
|
|
242
|
+
const guardedHistory = usage
|
|
243
|
+
? {
|
|
244
|
+
listUsageCharges: (userId, options) => this.creditStore.withUsageBackend("clickhouse", () => usage.listUsageCharges(userId, options)),
|
|
245
|
+
}
|
|
246
|
+
: undefined;
|
|
219
247
|
this.bursar = new Bursar({
|
|
220
248
|
...bursarOptions,
|
|
221
249
|
commerceOptions,
|
|
@@ -223,19 +251,21 @@ export class BursarRuntime {
|
|
|
223
251
|
billingStore: this.billingStore,
|
|
224
252
|
creditsOptions: {
|
|
225
253
|
...(bursarOptions.creditsOptions ?? {}),
|
|
226
|
-
analytics:
|
|
227
|
-
usageStore:
|
|
254
|
+
analytics: guardedAnalytics,
|
|
255
|
+
usageStore: guardedHistory,
|
|
228
256
|
},
|
|
229
257
|
});
|
|
230
|
-
this.postgres =
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
258
|
+
this.postgres =
|
|
259
|
+
operatorPool &&
|
|
260
|
+
new PostgresClient(operatorPool, {
|
|
261
|
+
...(options.postgresOptions ?? {}),
|
|
262
|
+
tenantId: this.tenantId,
|
|
263
|
+
providerEnvironment: this.providerEnvironment,
|
|
264
|
+
accessRole: "bursar_operator",
|
|
265
|
+
usageBackend: this.clickhouse ? "clickhouse" : "postgres",
|
|
266
|
+
billingPayloadBackend: this.s3 ? "s3" : "postgres",
|
|
267
|
+
});
|
|
268
|
+
this.query = this.postgres?.query ?? null;
|
|
239
269
|
this.maintenance = new BursarMaintenance({
|
|
240
270
|
expireLeases: (limit) => this.creditStore.expireLeases(limit),
|
|
241
271
|
expireCredits: async (limit) => (await this.creditStore.sweepExpiredCredits(false, undefined, limit)).expiredCount,
|
|
@@ -248,10 +278,10 @@ export class BursarRuntime {
|
|
|
248
278
|
? undefined
|
|
249
279
|
: "billing is not configured",
|
|
250
280
|
});
|
|
251
|
-
this.
|
|
252
|
-
const repository = new PostgresStorageRepository(this.query, this.tenantId);
|
|
253
|
-
this.
|
|
254
|
-
const handlers = this.createHandlers(repository);
|
|
281
|
+
this.operatorMaintenanceValue = this.query ? new BursarOperatorMaintenance(this.query) : null;
|
|
282
|
+
const repository = this.query ? new PostgresStorageRepository(this.query, this.tenantId) : null;
|
|
283
|
+
this.outboxRecoveryValue = repository;
|
|
284
|
+
const handlers = repository ? this.createHandlers(repository) : [];
|
|
255
285
|
const configuredOutboxOptions = options.outbox === false || options.outbox === undefined ? {} : options.outbox;
|
|
256
286
|
const originalOnError = configuredOutboxOptions.onError;
|
|
257
287
|
let diagnosticsTracker = null;
|
|
@@ -263,27 +293,30 @@ export class BursarRuntime {
|
|
|
263
293
|
},
|
|
264
294
|
};
|
|
265
295
|
this.worker =
|
|
266
|
-
handlers.length > 0 && options.outbox !== false
|
|
296
|
+
repository && handlers.length > 0 && options.outbox !== false
|
|
267
297
|
? new OutboxWorker(repository, handlers, workerOptions)
|
|
268
298
|
: null;
|
|
269
299
|
this.diagnosticsTracker = new RuntimeDiagnosticsTracker({
|
|
270
|
-
checkPostgres:
|
|
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
|
-
},
|
|
300
|
+
checkPostgres: () => this.creditStore.checkReachability(),
|
|
279
301
|
getCatalogRevision: async () => {
|
|
280
302
|
const revision = await this.bursar.catalog.getActive();
|
|
281
303
|
return revision ? { id: revision.id, version: revision.version } : null;
|
|
282
304
|
},
|
|
283
|
-
getOutboxStatus: outboxStatusProvider(repository),
|
|
305
|
+
getOutboxStatus: repository ? outboxStatusProvider(repository) : undefined,
|
|
306
|
+
outboxUnavailableReason: repository ? undefined : "operatorPostgres is not configured",
|
|
284
307
|
}, this.worker !== null);
|
|
285
308
|
diagnosticsTracker = this.diagnosticsTracker;
|
|
286
309
|
}
|
|
310
|
+
get operatorMaintenance() {
|
|
311
|
+
if (!this.operatorMaintenanceValue)
|
|
312
|
+
throw new ConfigError("operatorPostgres is required for operator maintenance");
|
|
313
|
+
return this.operatorMaintenanceValue;
|
|
314
|
+
}
|
|
315
|
+
get outboxRecovery() {
|
|
316
|
+
if (!this.outboxRecoveryValue)
|
|
317
|
+
throw new ConfigError("operatorPostgres is required for outbox recovery");
|
|
318
|
+
return this.outboxRecoveryValue;
|
|
319
|
+
}
|
|
287
320
|
start(options = {}) {
|
|
288
321
|
if (this.closed) {
|
|
289
322
|
return Promise.reject(new StoreClosedError("BursarRuntime has been closed"));
|
|
@@ -302,6 +335,7 @@ export class BursarRuntime {
|
|
|
302
335
|
const startOptions = runtimeStartOptionsSchema.parse(options);
|
|
303
336
|
if (this.tenantSlug)
|
|
304
337
|
await this.verifyTenantIdentity();
|
|
338
|
+
await this.creditStore.withUsageBackend(this.clickhouse ? "clickhouse" : "postgres", async () => { });
|
|
305
339
|
if (startOptions.loadCatalog) {
|
|
306
340
|
const shouldRetry = startOptions.shouldRetry ??
|
|
307
341
|
((cause) => cause instanceof CatalogNotLoadedError || isRetryableBursarError(cause));
|
|
@@ -328,12 +362,12 @@ export class BursarRuntime {
|
|
|
328
362
|
catalogLoaded: this.bursar.catalog.isLoaded,
|
|
329
363
|
});
|
|
330
364
|
}
|
|
331
|
-
checkDependencies(
|
|
365
|
+
checkDependencies() {
|
|
332
366
|
return this.diagnosticsTracker.checkDependencies({
|
|
333
367
|
started: this.started,
|
|
334
368
|
closed: this.closed,
|
|
335
369
|
catalogLoaded: this.bursar.catalog.isLoaded,
|
|
336
|
-
}
|
|
370
|
+
});
|
|
337
371
|
}
|
|
338
372
|
health() {
|
|
339
373
|
const state = this.state();
|
|
@@ -386,7 +420,7 @@ export class BursarRuntime {
|
|
|
386
420
|
Promise.resolve().then(() => this.s3?.close?.()),
|
|
387
421
|
Promise.resolve().then(() => this.creditStore.close()),
|
|
388
422
|
Promise.resolve().then(() => this.billingStore.close()),
|
|
389
|
-
Promise.resolve().then(() => this.postgres
|
|
423
|
+
Promise.resolve().then(() => this.postgres?.close()),
|
|
390
424
|
]);
|
|
391
425
|
for (const result of resources) {
|
|
392
426
|
if (result.status === "rejected")
|
|
@@ -402,7 +436,7 @@ export class BursarRuntime {
|
|
|
402
436
|
}
|
|
403
437
|
if (this.ownsOperatorPool) {
|
|
404
438
|
try {
|
|
405
|
-
await this.operatorPool
|
|
439
|
+
await this.operatorPool?.end();
|
|
406
440
|
}
|
|
407
441
|
catch (error) {
|
|
408
442
|
failures.push(error);
|
|
@@ -423,7 +457,7 @@ export class BursarRuntime {
|
|
|
423
457
|
if (outboxEvent.payloadVersion !== 1) {
|
|
424
458
|
throw new Error(`Unsupported usage outbox payload version ${outboxEvent.payloadVersion}`);
|
|
425
459
|
}
|
|
426
|
-
let usage = usageExportFromOutbox(outboxEvent.payload);
|
|
460
|
+
let usage = usageExportFromOutbox(outboxEvent.payload, outboxEvent.rawUsage);
|
|
427
461
|
usage ??= await repository.getUsageCharge(outboxEvent.aggregateId);
|
|
428
462
|
if (!usage) {
|
|
429
463
|
throw new Error(`Usage charge ${outboxEvent.aggregateId} is unavailable for export`);
|
|
@@ -451,7 +485,7 @@ export class BursarRuntime {
|
|
|
451
485
|
if (stored?.objectKey)
|
|
452
486
|
return;
|
|
453
487
|
const event = outboxEvent.topic === "billing.webhook_received"
|
|
454
|
-
? billingExportFromOutbox(outboxEvent.payload)
|
|
488
|
+
? billingExportFromOutbox(outboxEvent.payload, outboxEvent.rawEnvelope)
|
|
455
489
|
: stored;
|
|
456
490
|
if (!event) {
|
|
457
491
|
throw new Error(`Billing event ${outboxEvent.aggregateId} is unavailable for archive`);
|
|
@@ -477,6 +511,8 @@ export class BursarRuntime {
|
|
|
477
511
|
async verifyTenantIdentity() {
|
|
478
512
|
if (!this.tenantSlug)
|
|
479
513
|
return;
|
|
514
|
+
if (!this.query)
|
|
515
|
+
throw new ConfigError("operatorPostgres is required to verify tenantSlug");
|
|
480
516
|
const rows = await this.query("SELECT bursar.resolve_active_tenant_for_trigger($1)::text AS tenant_id", [this.tenantSlug]);
|
|
481
517
|
const resolved = rows[0];
|
|
482
518
|
const tenantId = z.string().safeParse(resolved?.tenant_id);
|
|
@@ -489,7 +525,7 @@ export async function createBursarRuntime(options) {
|
|
|
489
525
|
return BursarRuntime.create(options);
|
|
490
526
|
}
|
|
491
527
|
function outboxStatusProvider(repository) {
|
|
492
|
-
return async (
|
|
528
|
+
return async () => repository.stats();
|
|
493
529
|
}
|
|
494
530
|
function isPostgresConnectionString(value) {
|
|
495
531
|
return z.string().safeParse(value).success;
|
|
@@ -498,13 +534,6 @@ function connectionStringValue(value) {
|
|
|
498
534
|
const parsed = z.string().safeParse(value);
|
|
499
535
|
return parsed.success ? parsed.data : null;
|
|
500
536
|
}
|
|
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
537
|
function createOwnedPool(pg, connectionString, options) {
|
|
509
538
|
if (pg === undefined) {
|
|
510
539
|
throw new BursarImportError("pg is required for the Bursar runtime: npm install pg");
|
|
@@ -513,12 +542,6 @@ function createOwnedPool(pg, connectionString, options) {
|
|
|
513
542
|
// and the node-postgres Pool is created from the validated connection options above.
|
|
514
543
|
return new pg.Pool(postgresPoolConfig(connectionString, options));
|
|
515
544
|
}
|
|
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
545
|
function supportsUsageHistory(value) {
|
|
523
546
|
return z.object({ listUsageCharges: z.function() }).safeParse(value).success;
|
|
524
547
|
}
|
|
@@ -582,12 +605,12 @@ const billingOutboxPayloadSchema = z
|
|
|
582
605
|
archived_at: z.string().nullable().optional(),
|
|
583
606
|
})
|
|
584
607
|
.passthrough();
|
|
585
|
-
function usageExportFromOutbox(payload) {
|
|
608
|
+
function usageExportFromOutbox(payload, rawUsage) {
|
|
586
609
|
const parsed = usageOutboxPayloadSchema.safeParse(payload);
|
|
587
610
|
if (!parsed.success)
|
|
588
611
|
return null;
|
|
589
612
|
const value = parsed.data;
|
|
590
|
-
|
|
613
|
+
const usage = {
|
|
591
614
|
tenantId: value.tenant_id,
|
|
592
615
|
chargeId: value.charge_id,
|
|
593
616
|
accountId: value.account_id,
|
|
@@ -615,13 +638,16 @@ function usageExportFromOutbox(payload) {
|
|
|
615
638
|
eventAt: value.event_at,
|
|
616
639
|
createdAt: value.created_at,
|
|
617
640
|
};
|
|
641
|
+
if (rawUsage)
|
|
642
|
+
usage.rawJson = rawUsage;
|
|
643
|
+
return usage;
|
|
618
644
|
}
|
|
619
|
-
function billingExportFromOutbox(payload) {
|
|
645
|
+
function billingExportFromOutbox(payload, rawEnvelope) {
|
|
620
646
|
const parsed = billingOutboxPayloadSchema.safeParse(payload);
|
|
621
647
|
if (!parsed.success)
|
|
622
648
|
return null;
|
|
623
649
|
const value = parsed.data;
|
|
624
|
-
|
|
650
|
+
const result = {
|
|
625
651
|
tenantId: value.tenant_id,
|
|
626
652
|
eventId: value.event_id,
|
|
627
653
|
provider: value.provider,
|
|
@@ -636,5 +662,8 @@ function billingExportFromOutbox(payload) {
|
|
|
636
662
|
objectVersion: value.object_version ?? null,
|
|
637
663
|
archivedAt: value.archived_at ?? null,
|
|
638
664
|
};
|
|
665
|
+
if (rawEnvelope !== undefined)
|
|
666
|
+
result.rawEnvelope = rawEnvelope;
|
|
667
|
+
return result;
|
|
639
668
|
}
|
|
640
669
|
//# sourceMappingURL=runtime.js.map
|