@zonastery/bursar 2.0.1 → 2.0.3

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.
Files changed (285) hide show
  1. package/README.md +22 -14
  2. package/dist/billing/auto-recharge-service.d.ts +1 -1
  3. package/dist/billing/auto-recharge-service.d.ts.map +1 -1
  4. package/dist/billing/auto-recharge-service.js +9 -6
  5. package/dist/billing/auto-recharge-service.js.map +1 -1
  6. package/dist/billing/billing-store.d.ts +4 -1
  7. package/dist/billing/billing-store.d.ts.map +1 -1
  8. package/dist/billing/billing-store.js +2 -0
  9. package/dist/billing/billing-store.js.map +1 -1
  10. package/dist/billing/contracts.d.ts +2 -1
  11. package/dist/billing/contracts.d.ts.map +1 -1
  12. package/dist/billing/contracts.js.map +1 -1
  13. package/dist/billing/event-handlers.d.ts +2 -3
  14. package/dist/billing/event-handlers.d.ts.map +1 -1
  15. package/dist/billing/event-handlers.js +38 -49
  16. package/dist/billing/event-handlers.js.map +1 -1
  17. package/dist/billing/event-processor.d.ts.map +1 -1
  18. package/dist/billing/event-processor.js +22 -10
  19. package/dist/billing/event-processor.js.map +1 -1
  20. package/dist/billing/financial-event-handlers.d.ts +2 -2
  21. package/dist/billing/financial-event-handlers.d.ts.map +1 -1
  22. package/dist/billing/financial-event-handlers.js +7 -7
  23. package/dist/billing/financial-event-handlers.js.map +1 -1
  24. package/dist/billing/postgres/repositories/auto-recharge.js +1 -1
  25. package/dist/billing/postgres/repositories/auto-recharge.js.map +1 -1
  26. package/dist/billing/postgres/repositories/event.d.ts.map +1 -1
  27. package/dist/billing/postgres/repositories/event.js +33 -1
  28. package/dist/billing/postgres/repositories/event.js.map +1 -1
  29. package/dist/billing/postgres/repositories/offer.d.ts +1 -1
  30. package/dist/billing/postgres/repositories/offer.d.ts.map +1 -1
  31. package/dist/billing/postgres/repositories/offer.js +1 -1
  32. package/dist/billing/postgres/repositories/offer.js.map +1 -1
  33. package/dist/billing/postgres/repositories/topup.d.ts +1 -1
  34. package/dist/billing/postgres/repositories/topup.d.ts.map +1 -1
  35. package/dist/billing/postgres/repositories/topup.js +1 -1
  36. package/dist/billing/postgres/repositories/topup.js.map +1 -1
  37. package/dist/billing/postgres/store.d.ts +6 -2
  38. package/dist/billing/postgres/store.d.ts.map +1 -1
  39. package/dist/billing/postgres/store.js +21 -6
  40. package/dist/billing/postgres/store.js.map +1 -1
  41. package/dist/billing/service-types.d.ts +2 -15
  42. package/dist/billing/service-types.d.ts.map +1 -1
  43. package/dist/billing/service-types.js.map +1 -1
  44. package/dist/billing/types/auto-recharge.d.ts +1 -1
  45. package/dist/billing/types/auto-recharge.d.ts.map +1 -1
  46. package/dist/billing/types/auto-recharge.js.map +1 -1
  47. package/dist/billing/types/catalog.d.ts +1 -1
  48. package/dist/billing/types/catalog.d.ts.map +1 -1
  49. package/dist/billing/types/catalog.js.map +1 -1
  50. package/dist/billing/types/documents.d.ts +1 -1
  51. package/dist/billing/types/documents.d.ts.map +1 -1
  52. package/dist/billing/types/documents.js.map +1 -1
  53. package/dist/billing/types/events.d.ts +11 -2
  54. package/dist/billing/types/events.d.ts.map +1 -1
  55. package/dist/billing/types/events.js +2 -2
  56. package/dist/billing/types/events.js.map +1 -1
  57. package/dist/billing/types/subscriptions.d.ts.map +1 -1
  58. package/dist/billing/types/subscriptions.js.map +1 -1
  59. package/dist/breakdown.d.ts +1 -1
  60. package/dist/breakdown.d.ts.map +1 -1
  61. package/dist/breakdown.js +1 -1
  62. package/dist/breakdown.js.map +1 -1
  63. package/dist/bursar.d.ts +21 -11
  64. package/dist/bursar.d.ts.map +1 -1
  65. package/dist/bursar.js +40 -4
  66. package/dist/bursar.js.map +1 -1
  67. package/dist/catalog.d.ts.map +1 -1
  68. package/dist/catalog.js +1 -1
  69. package/dist/catalog.js.map +1 -1
  70. package/dist/commerce/index.d.ts +0 -1
  71. package/dist/commerce/index.d.ts.map +1 -1
  72. package/dist/commerce/index.js +0 -1
  73. package/dist/commerce/index.js.map +1 -1
  74. package/dist/commerce/service.d.ts.map +1 -1
  75. package/dist/commerce/service.js +154 -106
  76. package/dist/commerce/service.js.map +1 -1
  77. package/dist/commerce/types.d.ts +9 -5
  78. package/dist/commerce/types.d.ts.map +1 -1
  79. package/dist/commerce/types.js.map +1 -1
  80. package/dist/config/parse-credits.d.ts.map +1 -1
  81. package/dist/config/parse-credits.js +0 -6
  82. package/dist/config/parse-credits.js.map +1 -1
  83. package/dist/config/parse-utils.d.ts +1 -1
  84. package/dist/config/parse-utils.d.ts.map +1 -1
  85. package/dist/config/parse-utils.js +1 -1
  86. package/dist/config/parse-utils.js.map +1 -1
  87. package/dist/config/types.d.ts +1 -6
  88. package/dist/config/types.d.ts.map +1 -1
  89. package/dist/config/types.js.map +1 -1
  90. package/dist/config.d.ts.map +1 -1
  91. package/dist/config.js +8 -1
  92. package/dist/config.js.map +1 -1
  93. package/dist/credits/amount.d.ts +8 -0
  94. package/dist/credits/amount.d.ts.map +1 -0
  95. package/dist/credits/amount.js +32 -0
  96. package/dist/credits/amount.js.map +1 -0
  97. package/dist/credits/catalog-runtime.d.ts +5 -7
  98. package/dist/credits/catalog-runtime.d.ts.map +1 -1
  99. package/dist/credits/catalog-runtime.js +4 -13
  100. package/dist/credits/catalog-runtime.js.map +1 -1
  101. package/dist/credits/lease-workflow.d.ts +2 -2
  102. package/dist/credits/lease-workflow.d.ts.map +1 -1
  103. package/dist/credits/lease-workflow.js +24 -21
  104. package/dist/credits/lease-workflow.js.map +1 -1
  105. package/dist/credits/low-balance-monitor.d.ts +1 -1
  106. package/dist/credits/low-balance-monitor.d.ts.map +1 -1
  107. package/dist/credits/low-balance-monitor.js +3 -4
  108. package/dist/credits/low-balance-monitor.js.map +1 -1
  109. package/dist/credits/postgres/repositories/balance.d.ts.map +1 -1
  110. package/dist/credits/postgres/repositories/balance.js +1 -1
  111. package/dist/credits/postgres/repositories/balance.js.map +1 -1
  112. package/dist/credits/postgres/repositories/bucket.js +1 -1
  113. package/dist/credits/postgres/repositories/bucket.js.map +1 -1
  114. package/dist/credits/postgres/repositories/lease.d.ts.map +1 -1
  115. package/dist/credits/postgres/repositories/lease.js +4 -2
  116. package/dist/credits/postgres/repositories/lease.js.map +1 -1
  117. package/dist/credits/postgres/repositories/team.d.ts +2 -1
  118. package/dist/credits/postgres/repositories/team.d.ts.map +1 -1
  119. package/dist/credits/postgres/repositories/team.js +19 -5
  120. package/dist/credits/postgres/repositories/team.js.map +1 -1
  121. package/dist/credits/postgres/store.d.ts +18 -14
  122. package/dist/credits/postgres/store.d.ts.map +1 -1
  123. package/dist/credits/postgres/store.js +30 -18
  124. package/dist/credits/postgres/store.js.map +1 -1
  125. package/dist/credits/postgres/value-mappers.d.ts +1 -1
  126. package/dist/credits/postgres/value-mappers.d.ts.map +1 -1
  127. package/dist/credits/postgres/value-mappers.js +1 -1
  128. package/dist/credits/postgres/value-mappers.js.map +1 -1
  129. package/dist/credits/service-errors.d.ts +1 -1
  130. package/dist/credits/service-errors.d.ts.map +1 -1
  131. package/dist/credits/service-errors.js +1 -1
  132. package/dist/credits/service-errors.js.map +1 -1
  133. package/dist/credits/service-types.d.ts +21 -16
  134. package/dist/credits/service-types.d.ts.map +1 -1
  135. package/dist/credits/service-types.js.map +1 -1
  136. package/dist/credits/service.d.ts +21 -17
  137. package/dist/credits/service.d.ts.map +1 -1
  138. package/dist/credits/service.js +81 -38
  139. package/dist/credits/service.js.map +1 -1
  140. package/dist/credits/store.d.ts +26 -23
  141. package/dist/credits/store.d.ts.map +1 -1
  142. package/dist/credits/store.js +4 -2
  143. package/dist/credits/store.js.map +1 -1
  144. package/dist/credits/types/account.d.ts +1 -1
  145. package/dist/credits/types/account.d.ts.map +1 -1
  146. package/dist/credits/types/account.js.map +1 -1
  147. package/dist/credits/types/grants.d.ts.map +1 -1
  148. package/dist/credits/types/grants.js.map +1 -1
  149. package/dist/credits/types/teams.d.ts +1 -0
  150. package/dist/credits/types/teams.d.ts.map +1 -1
  151. package/dist/credits/types/teams.js.map +1 -1
  152. package/dist/engine.js +1 -1
  153. package/dist/engine.js.map +1 -1
  154. package/dist/errors.d.ts +4 -0
  155. package/dist/errors.d.ts.map +1 -1
  156. package/dist/errors.js +34 -0
  157. package/dist/errors.js.map +1 -1
  158. package/dist/expr/ast.d.ts.map +1 -1
  159. package/dist/expr/ast.js.map +1 -1
  160. package/dist/expr/evaluator.d.ts +1 -1
  161. package/dist/expr/evaluator.d.ts.map +1 -1
  162. package/dist/expr/evaluator.js +1 -1
  163. package/dist/expr/evaluator.js.map +1 -1
  164. package/dist/expr/parser.d.ts +1 -0
  165. package/dist/expr/parser.d.ts.map +1 -1
  166. package/dist/expr/parser.js +15 -3
  167. package/dist/expr/parser.js.map +1 -1
  168. package/dist/expr.d.ts +1 -1
  169. package/dist/expr.d.ts.map +1 -1
  170. package/dist/expr.js +1 -1
  171. package/dist/expr.js.map +1 -1
  172. package/dist/generated/pricing-config.schema.json +31 -29
  173. package/dist/generated/pricing-config.types.d.ts +6 -18
  174. package/dist/generated/pricing-config.types.d.ts.map +1 -1
  175. package/dist/generated/pricing-config.types.js.map +1 -1
  176. package/dist/index.d.ts +7 -3
  177. package/dist/index.d.ts.map +1 -1
  178. package/dist/index.js +2 -0
  179. package/dist/index.js.map +1 -1
  180. package/dist/load-config-file.d.ts +2 -3
  181. package/dist/load-config-file.d.ts.map +1 -1
  182. package/dist/load-config-file.js +14 -29
  183. package/dist/load-config-file.js.map +1 -1
  184. package/dist/metrics.d.ts +1 -1
  185. package/dist/metrics.d.ts.map +1 -1
  186. package/dist/metrics.js.map +1 -1
  187. package/dist/node.d.ts +6 -3
  188. package/dist/node.d.ts.map +1 -1
  189. package/dist/node.js +1 -0
  190. package/dist/node.js.map +1 -1
  191. package/dist/providers/_shared.d.ts +3 -3
  192. package/dist/providers/_shared.d.ts.map +1 -1
  193. package/dist/providers/_shared.js +11 -6
  194. package/dist/providers/_shared.js.map +1 -1
  195. package/dist/providers/dodo/client-contract.d.ts +8 -13
  196. package/dist/providers/dodo/client-contract.d.ts.map +1 -1
  197. package/dist/providers/dodo/client-contract.js.map +1 -1
  198. package/dist/providers/dodo/event-mapper.d.ts +1 -1
  199. package/dist/providers/dodo/event-mapper.d.ts.map +1 -1
  200. package/dist/providers/dodo/event-mapper.js +23 -15
  201. package/dist/providers/dodo/event-mapper.js.map +1 -1
  202. package/dist/providers/dodo/provider.d.ts +4 -6
  203. package/dist/providers/dodo/provider.d.ts.map +1 -1
  204. package/dist/providers/dodo/provider.js +44 -82
  205. package/dist/providers/dodo/provider.js.map +1 -1
  206. package/dist/providers/dodo/webhook-bridge.d.ts +1 -2
  207. package/dist/providers/dodo/webhook-bridge.d.ts.map +1 -1
  208. package/dist/providers/dodo/webhook-bridge.js +0 -1
  209. package/dist/providers/dodo/webhook-bridge.js.map +1 -1
  210. package/dist/providers/environment.d.ts +6 -0
  211. package/dist/providers/environment.d.ts.map +1 -0
  212. package/dist/providers/environment.js +10 -0
  213. package/dist/providers/environment.js.map +1 -0
  214. package/dist/providers/index.d.ts +3 -7
  215. package/dist/providers/index.d.ts.map +1 -1
  216. package/dist/providers/index.js +1 -5
  217. package/dist/providers/index.js.map +1 -1
  218. package/dist/providers/mock/provider.d.ts +6 -8
  219. package/dist/providers/mock/provider.d.ts.map +1 -1
  220. package/dist/providers/mock/provider.js +18 -50
  221. package/dist/providers/mock/provider.js.map +1 -1
  222. package/dist/providers/stripe/event-mapper.d.ts.map +1 -1
  223. package/dist/providers/stripe/event-mapper.js +82 -14
  224. package/dist/providers/stripe/event-mapper.js.map +1 -1
  225. package/dist/providers/stripe/provider.d.ts +3 -3
  226. package/dist/providers/stripe/provider.d.ts.map +1 -1
  227. package/dist/providers/stripe/provider.js +37 -24
  228. package/dist/providers/stripe/provider.js.map +1 -1
  229. package/dist/providers/types.d.ts +9 -20
  230. package/dist/providers/types.d.ts.map +1 -1
  231. package/dist/providers/types.js.map +1 -1
  232. package/dist/shared/diagnostics.d.ts +8 -0
  233. package/dist/shared/diagnostics.d.ts.map +1 -1
  234. package/dist/shared/diagnostics.js +49 -0
  235. package/dist/shared/diagnostics.js.map +1 -1
  236. package/dist/shared/idempotency.d.ts +9 -0
  237. package/dist/shared/idempotency.d.ts.map +1 -0
  238. package/dist/shared/idempotency.js +34 -0
  239. package/dist/shared/idempotency.js.map +1 -0
  240. package/dist/shared/postgres-client.d.ts +7 -0
  241. package/dist/shared/postgres-client.d.ts.map +1 -1
  242. package/dist/shared/postgres-client.js +21 -4
  243. package/dist/shared/postgres-client.js.map +1 -1
  244. package/dist/shared/postgres-errors.d.ts.map +1 -1
  245. package/dist/shared/postgres-errors.js.map +1 -1
  246. package/dist/storage/adapters/clickhouse.d.ts +9 -2
  247. package/dist/storage/adapters/clickhouse.d.ts.map +1 -1
  248. package/dist/storage/adapters/clickhouse.js +142 -36
  249. package/dist/storage/adapters/clickhouse.js.map +1 -1
  250. package/dist/storage/adapters/s3.d.ts +44 -6
  251. package/dist/storage/adapters/s3.d.ts.map +1 -1
  252. package/dist/storage/adapters/s3.js +59 -21
  253. package/dist/storage/adapters/s3.js.map +1 -1
  254. package/dist/storage/diagnostics.d.ts +105 -0
  255. package/dist/storage/diagnostics.d.ts.map +1 -0
  256. package/dist/storage/diagnostics.js +227 -0
  257. package/dist/storage/diagnostics.js.map +1 -0
  258. package/dist/storage/maintenance.d.ts +88 -0
  259. package/dist/storage/maintenance.d.ts.map +1 -0
  260. package/dist/storage/maintenance.js +266 -0
  261. package/dist/storage/maintenance.js.map +1 -0
  262. package/dist/storage/outbox-worker.d.ts +20 -0
  263. package/dist/storage/outbox-worker.d.ts.map +1 -1
  264. package/dist/storage/outbox-worker.js +172 -42
  265. package/dist/storage/outbox-worker.js.map +1 -1
  266. package/dist/storage/ports.d.ts +43 -1
  267. package/dist/storage/ports.d.ts.map +1 -1
  268. package/dist/storage/ports.js.map +1 -1
  269. package/dist/storage/postgres-repository.d.ts +7 -2
  270. package/dist/storage/postgres-repository.d.ts.map +1 -1
  271. package/dist/storage/postgres-repository.js +155 -54
  272. package/dist/storage/postgres-repository.js.map +1 -1
  273. package/dist/storage/runtime.d.ts +30 -9
  274. package/dist/storage/runtime.d.ts.map +1 -1
  275. package/dist/storage/runtime.js +268 -37
  276. package/dist/storage/runtime.js.map +1 -1
  277. package/dist/telemetry/index.d.ts +37 -0
  278. package/dist/telemetry/index.d.ts.map +1 -0
  279. package/dist/telemetry/index.js +115 -0
  280. package/dist/telemetry/index.js.map +1 -0
  281. package/dist/telemetry/opentelemetry.d.ts +25 -0
  282. package/dist/telemetry/opentelemetry.d.ts.map +1 -0
  283. package/dist/telemetry/opentelemetry.js +74 -0
  284. package/dist/telemetry/opentelemetry.js.map +1 -0
  285. package/package.json +62 -36
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAiBnD,OAAO,EACL,yBAAyB,EACzB,2BAA2B,EAC3B,kBAAkB,EAClB,kBAAkB,EAClB,sBAAsB,GACvB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAOpD,OAAO,EACL,yBAAyB,EACzB,8BAA8B,EAC9B,YAAY,EACZ,WAAW,EACX,4BAA4B,EAC5B,2BAA2B,EAC3B,eAAe,EACf,qBAAqB,EACrB,WAAW,EACX,WAAW,EACX,eAAe,EACf,uBAAuB,EACvB,WAAW,EACX,wBAAwB,EACxB,iBAAiB,EACjB,kBAAkB,EAClB,wBAAwB,EACxB,0BAA0B,EAC1B,mCAAmC,EACnC,qBAAqB,EACrB,qBAAqB,EACrB,WAAW,EACX,kBAAkB,EAClB,UAAU,EACV,gBAAgB,EAChB,iBAAiB,EACjB,qBAAqB,EACrB,qBAAqB,EACrB,wBAAwB,EACxB,aAAa,EACb,sBAAsB,GACvB,MAAM,aAAa,CAAC;AAQrB,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAElD,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAEnE,0EAA0E;AAC1E,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAUrE,cAAc,qBAAqB,CAAC;AA8FpC,SAAS;AACT,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAM5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEzD,UAAU;AACV,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC","sourcesContent":["export { PricingEngine } from \"./engine.js\";\nexport type { CostBreakdown } from \"./breakdown.js\";\nexport { makeCostBreakdown } from \"./breakdown.js\";\nexport type { UsageMetrics } from \"./metrics.js\";\nexport type {\n BursarConfigData,\n CatalogRollout,\n ParsedBursarConfig,\n PricingConfig,\n CreditsConfig,\n PlanDefinition,\n PlanEvolution,\n PlanRollout,\n PlanRolloutStrategy,\n CommerceConfig,\n Window,\n Charge,\n FeatureDefinition,\n} from \"./config.js\";\nexport {\n canonicalBursarConfigDict,\n canonicalCatalogRolloutDict,\n loadCatalogRollout,\n loadConfigFromDict,\n validateCatalogRollout,\n} from \"./config.js\";\nexport { projectPublicCatalog } from \"./catalog.js\";\nexport type {\n PublicCatalog,\n PublicCatalogOffer,\n PublicCatalogPlan,\n PublicCatalogWindow,\n} from \"./catalog.js\";\nexport {\n AutoRechargeDisabledError,\n AutoRechargeNotConfiguredError,\n BillingError,\n BursarError,\n CapabilityNotConfiguredError,\n CapabilityNotSupportedError,\n CapReachedError,\n ConcurrencyLimitError,\n CreditError,\n ConfigError,\n ExpressionError,\n FeatureNotEntitledError,\n ImportError,\n InsufficientCreditsError,\n LeaseExpiredError,\n LeaseNotFoundError,\n OperationNotAllowedError,\n PaymentMethodRequiredError,\n ProviderCapabilityNotSupportedError,\n ProviderResponseError,\n CatalogNotLoadedError,\n RefundError,\n QuotaExceededError,\n StoreError,\n StoreClosedError,\n StoreTimeoutError,\n StoreUnavailableError,\n bursarErrorHttpStatus,\n bursarErrorPublicMessage,\n isBursarError,\n isRetryableBursarError,\n} from \"./errors.js\";\nexport type {\n BursarErrorCategory,\n BursarErrorDetails,\n BursarErrorOptions,\n SerializedBursarError,\n StoreErrorOptions,\n} from \"./errors.js\";\nexport { retryBursarOperation } from \"./retry.js\";\nexport type { BursarRetryOptions } from \"./retry.js\";\nexport { validateExpression, evaluateExpression } from \"./expr.js\";\n\n// Application facade. Credit/billing orchestration is internal to Bursar.\nexport { AccountService, Bursar, CatalogService } from \"./bursar.js\";\nexport type {\n AccountCreatedInput,\n AccountCreatedResult,\n BursarOptions,\n BillingCapability,\n BillingEventSink,\n CommerceOptions,\n CreditsService,\n} from \"./bursar.js\";\nexport * from \"./commerce/index.js\";\n\n// Types\nexport type {\n AddCreditsResult,\n AddTeamMemberResult,\n AggregateStats,\n AllowanceResult,\n AvailableResult,\n BalanceResult,\n BillingMode,\n CatalogRevisionSummary,\n CatalogRevision,\n BucketBalance,\n BucketBalancesResult,\n BucketDefinition,\n CanAffordResult,\n CheckFeatureResult,\n CreateTeamResult,\n CreditMetadata,\n DailySpendRow,\n DeductionResult,\n DeductionFailure,\n DeductionSuccess,\n DeductWithAllowanceOptions,\n ExecuteGrantProgramRequest,\n GetUserPlanResult,\n GrantProgramAwardResult,\n GrantProgramTrigger,\n LeaseResult,\n LeaseFailure,\n LeaseSuccess,\n LeasePricingContext,\n ListQuotaEventsOptions,\n PlanAllowancePolicy,\n PlanAdmissionPolicy,\n PlanCreditPolicy,\n PlanMigrationBatchResult,\n PlanMigrationStartResult,\n QuotaEvent,\n QuotaState,\n RefundResult,\n RefundFailure,\n RefundSuccess,\n RevokeCreditsResult,\n ReleaseResult,\n SetUserPlanResult,\n SpendByModelRow,\n SpendByUserRow,\n ListLedgerEntriesOptions,\n ListUsageChargesOptions,\n ListUsageEntriesOptions,\n LedgerCursor,\n LedgerPage,\n LedgerEntry,\n UsageCharge,\n UsageChargeCursor,\n UsageChargePage,\n UsageRecordResult,\n UsageRecordFailure,\n UsageRecordSuccess,\n SweepResult,\n Team,\n TeamBalanceResult,\n TeamDeductionResult,\n TeamDeductionFailure,\n TeamDeductionSuccess,\n TeamMember,\n TopUserRow,\n UsageAnalyticsStore,\n} from \"./credits/types/index.js\";\n\n// Store options\nexport type { CreateLeaseOptions, SettleLeaseOptions } from \"./credits/store.js\";\nexport type {\n AddCreditsOptions,\n BeginBilledOperationOptions,\n CanAffordOptions,\n CreditsServiceOptions,\n DeductCreditsOptions,\n DeductFlatJobOptions,\n DeductOptions,\n DeductTeamOptions,\n GrantSubscriptionCycleOptions,\n LowBalanceConfig,\n MetricsOrAmount,\n PostDeductionContext,\n RecordUsageOptions,\n RefundCreditsOptions,\n ReserveOptions,\n RunBilledOptions,\n SettleOptions,\n} from \"./credits/service-types.js\";\n\n// Stores\nexport { CreditStore } from \"./credits/store.js\";\nexport { PostgresStore } from \"./credits/postgres/store.js\";\nexport type { PostgresStoreOptions } from \"./credits/postgres/store.js\";\nexport type { PostgresConnectionOptions } from \"./shared/postgres-client.js\";\n\n// Events\nexport type { CreditEvent, CreditEventType } from \"./credits/events.js\";\nexport { CreditEventEmitter } from \"./credits/events.js\";\n\n// Billing\nexport { BillingStore, PostgresBillingStore } from \"./billing/index.js\";\nexport { AUTO_RECHARGE_STATES, BillingEventType } from \"./billing/index.js\";\nexport type { BillingServiceOptions } from \"./billing/billing-service.js\";\n\nexport type {\n BillingAutoRechargeAttempt,\n BillingAutoRechargeAttemptState,\n BillingAutoRechargeProfile,\n BillingAutoRechargeStatus,\n BillingProvisioningPort,\n BillingCreditPostingResult,\n BillingCustomerInfo,\n BillingCustomerRecord,\n BillingDisputeInfo,\n BillingEvent,\n BillingEventClaim,\n BillingEventHandler,\n BillingEventResult,\n BillingInvoiceInfo,\n BillingInvoiceRecord,\n BillingOfferInterval,\n BillingPaymentInfo,\n BillingPaymentRecord,\n BillingPreferences,\n PostgresBillingStoreOptions,\n BillingRefundInfo,\n BillingSubscriptionInfo,\n BillingSubscriptionChange,\n BillingSubscriptionChangeInput,\n BillingSubscriptionOfferContext,\n BillingSubscriptionChangeState,\n BillingSubscriptionState,\n BillingSubscriptionStatus,\n EntitlementMode,\n ProviderRef,\n SubscriptionGrant,\n} from \"./billing/index.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAiBnD,OAAO,EACL,yBAAyB,EACzB,2BAA2B,EAC3B,kBAAkB,EAClB,kBAAkB,EAClB,sBAAsB,GACvB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAOpD,OAAO,EACL,yBAAyB,EACzB,8BAA8B,EAC9B,YAAY,EACZ,WAAW,EACX,4BAA4B,EAC5B,2BAA2B,EAC3B,eAAe,EACf,qBAAqB,EACrB,WAAW,EACX,WAAW,EACX,eAAe,EACf,uBAAuB,EACvB,WAAW,EACX,wBAAwB,EACxB,iBAAiB,EACjB,kBAAkB,EAClB,wBAAwB,EACxB,0BAA0B,EAC1B,mCAAmC,EACnC,qBAAqB,EACrB,qBAAqB,EACrB,WAAW,EACX,kBAAkB,EAClB,UAAU,EACV,gBAAgB,EAChB,iBAAiB,EACjB,qBAAqB,EACrB,qBAAqB,EACrB,wBAAwB,EACxB,aAAa,EACb,sBAAsB,GACvB,MAAM,aAAa,CAAC;AAQrB,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAElD,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AACnE,OAAO,EACL,4BAA4B,EAC5B,8BAA8B,EAC9B,oBAAoB,EACpB,mBAAmB,EACnB,yBAAyB,EACzB,2BAA2B,EAC3B,yBAAyB,EACzB,wBAAwB,EACxB,4BAA4B,GAC7B,MAAM,sBAAsB,CAAC;AAO9B,0EAA0E;AAC1E,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAYrE,cAAc,qBAAqB,CAAC;AA+FpC,SAAS;AACT,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAG5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAKnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEzD,UAAU;AACV,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC","sourcesContent":["export { PricingEngine } from \"./engine.js\";\nexport type { CostBreakdown } from \"./breakdown.js\";\nexport { makeCostBreakdown } from \"./breakdown.js\";\nexport type { UsageMetrics } from \"./metrics.js\";\nexport type {\n BursarConfigData,\n CatalogRollout,\n ParsedBursarConfig,\n PricingConfig,\n CreditsConfig,\n PlanDefinition,\n PlanEvolution,\n PlanRollout,\n PlanRolloutStrategy,\n CommerceConfig,\n Window,\n Charge,\n FeatureDefinition,\n} from \"./config.js\";\nexport {\n canonicalBursarConfigDict,\n canonicalCatalogRolloutDict,\n loadCatalogRollout,\n loadConfigFromDict,\n validateCatalogRollout,\n} from \"./config.js\";\nexport { projectPublicCatalog } from \"./catalog.js\";\nexport type {\n PublicCatalog,\n PublicCatalogOffer,\n PublicCatalogPlan,\n PublicCatalogWindow,\n} from \"./catalog.js\";\nexport {\n AutoRechargeDisabledError,\n AutoRechargeNotConfiguredError,\n BillingError,\n BursarError,\n CapabilityNotConfiguredError,\n CapabilityNotSupportedError,\n CapReachedError,\n ConcurrencyLimitError,\n CreditError,\n ConfigError,\n ExpressionError,\n FeatureNotEntitledError,\n ImportError,\n InsufficientCreditsError,\n LeaseExpiredError,\n LeaseNotFoundError,\n OperationNotAllowedError,\n PaymentMethodRequiredError,\n ProviderCapabilityNotSupportedError,\n ProviderResponseError,\n CatalogNotLoadedError,\n RefundError,\n QuotaExceededError,\n StoreError,\n StoreClosedError,\n StoreTimeoutError,\n StoreUnavailableError,\n bursarErrorHttpStatus,\n bursarErrorPublicMessage,\n isBursarError,\n isRetryableBursarError,\n} from \"./errors.js\";\nexport type {\n BursarErrorCategory,\n BursarErrorDetails,\n BursarErrorOptions,\n SerializedBursarError,\n StoreErrorOptions,\n} from \"./errors.js\";\nexport { retryBursarOperation } from \"./retry.js\";\nexport type { BursarRetryOptions } from \"./retry.js\";\nexport { validateExpression, evaluateExpression } from \"./expr.js\";\nexport {\n BURSAR_INSTRUMENTATION_SCOPE,\n BURSAR_INSTRUMENTATION_VERSION,\n NOOP_INSTRUMENTATION,\n NoopInstrumentation,\n getDefaultInstrumentation,\n sanitizeTelemetryAttributes,\n setDefaultInstrumentation,\n telemetryErrorAttributes,\n telemetryOperationAttributes,\n} from \"./telemetry/index.js\";\nexport type {\n Instrumentation,\n TelemetryAttributes,\n TelemetryAttributeValue,\n} from \"./telemetry/index.js\";\n\n// Application facade. Credit/billing orchestration is internal to Bursar.\nexport { AccountService, Bursar, CatalogService } from \"./bursar.js\";\nexport type {\n AccountCreatedInput,\n AccountCreatedResult,\n BillingBursarOptions,\n BursarOptions,\n BillingCapability,\n BillingEventSink,\n CommerceOptions,\n CreditsService,\n CreditsOnlyBursarOptions,\n} from \"./bursar.js\";\nexport * from \"./commerce/index.js\";\n\n// Types\nexport type {\n AddCreditsResult,\n AddTeamMemberResult,\n AggregateStats,\n AllowanceResult,\n AvailableResult,\n BalanceResult,\n BillingMode,\n CatalogRevisionSummary,\n CatalogRevision,\n BucketBalance,\n BucketBalancesResult,\n BucketDefinition,\n CanAffordResult,\n CheckFeatureResult,\n CreateTeamResult,\n CreditMetadata,\n DailySpendRow,\n DeductionResult,\n DeductionFailure,\n DeductionSuccess,\n DeductWithAllowanceOptions,\n ExecuteGrantProgramRequest,\n GetUserPlanResult,\n GrantProgramAwardResult,\n GrantProgramTrigger,\n LeaseResult,\n LeaseFailure,\n LeaseSuccess,\n LeasePricingContext,\n ListQuotaEventsOptions,\n PlanAllowancePolicy,\n PlanAdmissionPolicy,\n PlanCreditPolicy,\n PlanMigrationBatchResult,\n PlanMigrationStartResult,\n QuotaEvent,\n QuotaState,\n RefundResult,\n RefundFailure,\n RefundSuccess,\n RevokeCreditsResult,\n ReleaseResult,\n SetUserPlanResult,\n SpendByModelRow,\n SpendByUserRow,\n ListLedgerEntriesOptions,\n ListUsageChargesOptions,\n ListUsageEntriesOptions,\n LedgerCursor,\n LedgerPage,\n LedgerEntry,\n UsageCharge,\n UsageChargeCursor,\n UsageChargePage,\n UsageRecordResult,\n UsageRecordFailure,\n UsageRecordSuccess,\n SweepResult,\n Team,\n TeamBalanceResult,\n TeamDeductionResult,\n TeamDeductionFailure,\n TeamDeductionSuccess,\n TeamMember,\n TopUserRow,\n UsageAnalyticsStore,\n} from \"./credits/types/index.js\";\n\n// Store options\nexport type { CreateLeaseOptions, CreateTeamOptions, SettleLeaseOptions } from \"./credits/store.js\";\nexport type {\n AddCreditsOptions,\n BeginBilledOperationOptions,\n CanAffordOptions,\n CreditsServiceOptions,\n DeductCreditsOptions,\n DeductFlatJobOptions,\n DeductOptions,\n DeductTeamOptions,\n ExactAmount,\n GrantSubscriptionCycleOptions,\n LowBalanceConfig,\n MetricsOrAmount,\n PostDeductionContext,\n RecordUsageOptions,\n RefundCreditsOptions,\n ReserveOptions,\n RunBilledOptions,\n SettleOptions,\n} from \"./credits/service-types.js\";\n\n// Stores\nexport { CreditStore } from \"./credits/store.js\";\nexport { PostgresStore } from \"./credits/postgres/store.js\";\nexport type { PostgresStoreOptions } from \"./credits/postgres/store.js\";\nexport type { PostgresConnectionOptions } from \"./shared/postgres-client.js\";\nexport { PROVIDER_ENVIRONMENTS } from \"./providers/environment.js\";\nexport type { ProviderEnvironment } from \"./providers/environment.js\";\n\n// Events\nexport type { CreditEvent, CreditEventType } from \"./credits/events.js\";\nexport { CreditEventEmitter } from \"./credits/events.js\";\n\n// Billing\nexport { BillingStore, PostgresBillingStore } from \"./billing/index.js\";\nexport { AUTO_RECHARGE_STATES, BillingEventType } from \"./billing/index.js\";\nexport type { BillingServiceOptions } from \"./billing/billing-service.js\";\n\nexport type {\n BillingAutoRechargeAttempt,\n BillingAutoRechargeAttemptState,\n BillingAutoRechargeProfile,\n BillingAutoRechargeStatus,\n BillingProvisioningPort,\n BillingCreditPostingResult,\n BillingCustomerInfo,\n BillingCustomerRecord,\n BillingDisputeInfo,\n BillingEvent,\n BillingEventClaim,\n BillingEventHandler,\n BillingEventResult,\n BillingInvoiceInfo,\n BillingInvoiceRecord,\n BillingOfferInterval,\n BillingPaymentInfo,\n BillingPaymentRecord,\n BillingPreferences,\n PostgresBillingStoreOptions,\n BillingRefundInfo,\n BillingSubscriptionInfo,\n BillingSubscriptionChange,\n BillingSubscriptionChangeInput,\n BillingSubscriptionOfferContext,\n BillingSubscriptionChangeState,\n BillingSubscriptionState,\n BillingSubscriptionStatus,\n EntitlementMode,\n ProviderRef,\n SubscriptionGrant,\n} from \"./billing/index.js\";\n"]}
@@ -4,9 +4,8 @@
4
4
  * Returns the raw parsed dict (suitable for ``loadConfigFromDict`` or
5
5
  * ``PricingEngine.fromDict``).
6
6
  *
7
- * For YAML files the optional peer dep ``js-yaml`` is loaded on demand. If it
8
- * is not installed, an {@link ImportError} is thrown so callers get a clear,
9
- * typed message.
7
+ * JSON syntax is validated by the platform parser and mapping keys are also
8
+ * checked by js-yaml so duplicate config fields cannot silently overwrite.
10
9
  */
11
10
  export declare function loadConfigFile(filepath: string): Promise<Record<string, unknown>>;
12
11
  //# sourceMappingURL=load-config-file.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"load-config-file.d.ts","sourceRoot":"","sources":["../src/load-config-file.ts"],"names":[],"mappings":"AAmEA;;;;;;;;;GASG;AACH,wBAAsB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAsCvF"}
1
+ {"version":3,"file":"load-config-file.d.ts","sourceRoot":"","sources":["../src/load-config-file.ts"],"names":[],"mappings":"AAwDA;;;;;;;;GAQG;AACH,wBAAsB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CA+BvF"}
@@ -1,21 +1,15 @@
1
1
  import { readFileSync, statSync } from "fs";
2
2
  import { extname } from "path";
3
- import { ConfigError, ImportError } from "./errors.js";
4
- /**
5
- * Narrow an unknown dynamic-import result to the `js-yaml` shape we use.
6
- *
7
- * The result of `import()` is treated as `unknown` and validated (L12): the
8
- * module may expose `load` directly or under a CJS-interop `default` export.
9
- */
10
- function asYamlModule(mod) {
11
- const candidate = mod;
12
- if (typeof candidate.load === "function") {
13
- return candidate;
14
- }
15
- if (candidate.default && typeof candidate.default.load === "function") {
16
- return candidate.default;
17
- }
18
- throw new ImportError("js-yaml is installed but does not export a `load` function");
3
+ import { load as parseYaml } from "js-yaml";
4
+ import { ConfigError } from "./errors.js";
5
+ function parseJsonWithUniqueKeys(content) {
6
+ const parsed = JSON.parse(content);
7
+ // JSON is a strict subset of YAML. js-yaml retains source-level mapping
8
+ // keys and rejects duplicates, including nested and escape-equivalent keys;
9
+ // native JSON.parse above remains the authority for strict JSON syntax and
10
+ // for the returned JavaScript value.
11
+ parseYaml(content, { json: false });
12
+ return parsed;
19
13
  }
20
14
  /**
21
15
  * Read a file's contents, converting missing-file/directory/permission
@@ -64,9 +58,8 @@ function assertNonEmptyObject(data, filepath) {
64
58
  * Returns the raw parsed dict (suitable for ``loadConfigFromDict`` or
65
59
  * ``PricingEngine.fromDict``).
66
60
  *
67
- * For YAML files the optional peer dep ``js-yaml`` is loaded on demand. If it
68
- * is not installed, an {@link ImportError} is thrown so callers get a clear,
69
- * typed message.
61
+ * JSON syntax is validated by the platform parser and mapping keys are also
62
+ * checked by js-yaml so duplicate config fields cannot silently overwrite.
70
63
  */
71
64
  export async function loadConfigFile(filepath) {
72
65
  const extension = extname(filepath).toLowerCase();
@@ -74,18 +67,10 @@ export async function loadConfigFile(filepath) {
74
67
  throw new ConfigError(`Unsupported config file format: ${extension || "<none>"}. Expected .json, .yaml, or .yml`);
75
68
  }
76
69
  if (extension === ".yaml" || extension === ".yml") {
77
- let mod;
78
- try {
79
- mod = await import("js-yaml");
80
- }
81
- catch (cause) {
82
- throw new ImportError("js-yaml required for YAML files: npm install js-yaml", { cause });
83
- }
84
- const yaml = asYamlModule(mod);
85
70
  const content = readFileClean(filepath);
86
71
  let parsed;
87
72
  try {
88
- parsed = yaml.load(content);
73
+ parsed = parseYaml(content, { json: false });
89
74
  }
90
75
  catch (cause) {
91
76
  throw new ConfigError(`Invalid YAML in ${filepath}: ${cause.message}`, [], {
@@ -97,7 +82,7 @@ export async function loadConfigFile(filepath) {
97
82
  const content = readFileClean(filepath);
98
83
  let parsed;
99
84
  try {
100
- parsed = JSON.parse(content);
85
+ parsed = parseJsonWithUniqueKeys(content);
101
86
  }
102
87
  catch (cause) {
103
88
  throw new ConfigError(`Invalid JSON in ${filepath}: ${cause.message}`, [], {
@@ -1 +1 @@
1
- {"version":3,"file":"load-config-file.js","sourceRoot":"","sources":["../src/load-config-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAE,WAAW,EAAE,W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,EAAE,CAAC;YACf,MAAM,IAAI,WAAW,CAAC,sDAAsD,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QAC3F,CAAC;QACD,MAAM,IAAI,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;QAC/B,MAAM,OAAO,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC;QACxC,IAAI,MAAe,CAAC;QACpB,IAAI,CAAC;YACH,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC9B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,WAAW,CAAC,mBAAmB,QAAQ,KAAM,KAAe,CAAC,OAAO,EAAE,EAAE,EAAE,EAAE;gBACpF,KAAK;aACN,CAAC,CAAC;QACL,CAAC;QACD,OAAO,oBAAoB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAChD,CAAC;IAED,MAAM,OAAO,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC;IACxC,IAAI,MAAe,CAAC;IACpB,IAAI,CAAC;QACH,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC/B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,WAAW,CAAC,mBAAmB,QAAQ,KAAM,KAAe,CAAC,OAAO,EAAE,EAAE,EAAE,EAAE;YACpF,KAAK;SACN,CAAC,CAAC;IACL,CAAC;IACD,OAAO,oBAAoB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AAChD,CAAC","sourcesContent":["import { readFileSync, statSync } from \"fs\";\nimport { extname } from \"path\";\nimport { ConfigError, ImportError } from \"./errors.js\";\n\n/** Minimal shape of the `js-yaml` module we rely on (loaded on demand). */\ninterface YamlModule {\n load(content: string): unknown;\n}\n\n/**\n * Narrow an unknown dynamic-import result to the `js-yaml` shape we use.\n *\n * The result of `import()` is treated as `unknown` and validated (L12): the\n * module may expose `load` directly or under a CJS-interop `default` export.\n */\nfunction asYamlModule(mod: unknown): YamlModule {\n const candidate = mod as { load?: unknown; default?: { load?: unknown } };\n if (typeof candidate.load === \"function\") {\n return candidate as YamlModule;\n }\n if (candidate.default && typeof candidate.default.load === \"function\") {\n return candidate.default as YamlModule;\n }\n throw new ImportError(\"js-yaml is installed but does not export a `load` function\");\n}\n\n/**\n * Read a file's contents, converting missing-file/directory/permission\n * failures into a clean {@link ConfigError} instead of a raw Node `fs` error\n * (mirrors the Python CLI's `_load_config_file`).\n */\nfunction readFileClean(filepath: string): string {\n let stat: ReturnType<typeof statSync> | undefined;\n try {\n stat = statSync(filepath);\n } catch (cause) {\n const code = (cause as NodeJS.ErrnoException).code;\n if (code === \"ENOENT\") throw new ConfigError(`Config file not found: ${filepath}`);\n if (code === \"EACCES\") throw new ConfigError(`Permission denied: ${filepath}`);\n throw new ConfigError(`Could not read ${filepath}: ${(cause as Error).message}`, [], { cause });\n }\n if (stat.isDirectory()) {\n throw new ConfigError(`Not a file (is a directory): ${filepath}`);\n }\n try {\n return readFileSync(filepath, \"utf-8\");\n } catch (cause) {\n throw new ConfigError(`Could not read ${filepath}: ${(cause as Error).message}`, [], { cause });\n }\n}\n\n/** Guard against an empty file or a non-object parse result (e.g. an empty YAML document). */\nfunction assertNonEmptyObject(data: unknown, filepath: string): Record<string, unknown> {\n if (data == null) {\n throw new ConfigError(`Bursar config is empty: ${filepath}`);\n }\n if (typeof data !== \"object\" || Array.isArray(data)) {\n throw new ConfigError(\n `Bursar config must be a JSON/YAML object, got ${typeof data}: ${filepath}`,\n );\n }\n if (Object.keys(data).length === 0) {\n throw new ConfigError(`Bursar config is empty: ${filepath}`);\n }\n return data as Record<string, unknown>;\n}\n\n/**\n * Read a JSON or YAML Bursar config file from disk.\n *\n * Returns the raw parsed dict (suitable for ``loadConfigFromDict`` or\n * ``PricingEngine.fromDict``).\n *\n * For YAML files the optional peer dep ``js-yaml`` is loaded on demand. If it\n * is not installed, an {@link ImportError} is thrown so callers get a clear,\n * typed message.\n */\nexport async function loadConfigFile(filepath: string): Promise<Record<string, unknown>> {\n const extension = extname(filepath).toLowerCase();\n if (!new Set([\".json\", \".yaml\", \".yml\"]).has(extension)) {\n throw new ConfigError(\n `Unsupported config file format: ${extension || \"<none>\"}. Expected .json, .yaml, or .yml`,\n );\n }\n\n if (extension === \".yaml\" || extension === \".yml\") {\n let mod: unknown;\n try {\n mod = await import(\"js-yaml\");\n } catch (cause) {\n throw new ImportError(\"js-yaml required for YAML files: npm install js-yaml\", { cause });\n }\n const yaml = asYamlModule(mod);\n const content = readFileClean(filepath);\n let parsed: unknown;\n try {\n parsed = yaml.load(content);\n } catch (cause) {\n throw new ConfigError(`Invalid YAML in ${filepath}: ${(cause as Error).message}`, [], {\n cause,\n });\n }\n return assertNonEmptyObject(parsed, filepath);\n }\n\n const content = readFileClean(filepath);\n let parsed: unknown;\n try {\n parsed = JSON.parse(content);\n } catch (cause) {\n throw new ConfigError(`Invalid JSON in ${filepath}: ${(cause as Error).message}`, [], {\n cause,\n });\n }\n return assertNonEmptyObject(parsed, filepath);\n}\n"]}
1
+ {"version":3,"file":"load-config-file.js","sourceRoot":"","sources":["../src/load-config-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAE,IAAI,IAAI,SAAS,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,SAAS,uBAAuB,CAAC,OAAe;IAC9C,MAAM,MAAM,GAAY,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC5C,wEAAwE;IACxE,4EAA4E;IAC5E,2EAA2E;IAC3E,qCAAqC;IACrC,SAAS,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IACpC,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;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AC,OAAO,CAAC,CAAC;IAC5C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,WAAW,CAAC,mBAAmB,QAAQ,KAAM,KAAe,CAAC,OAAO,EAAE,EAAE,EAAE,EAAE;YACpF,KAAK;SACN,CAAC,CAAC;IACL,CAAC;IACD,OAAO,oBAAoB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AAChD,CAAC","sourcesContent":["import { readFileSync, statSync } from \"fs\";\nimport { extname } from \"path\";\nimport { load as parseYaml } from \"js-yaml\";\nimport { ConfigError } from \"./errors.js\";\n\nfunction parseJsonWithUniqueKeys(content: string): unknown {\n const parsed: unknown = JSON.parse(content);\n // JSON is a strict subset of YAML. js-yaml retains source-level mapping\n // keys and rejects duplicates, including nested and escape-equivalent keys;\n // native JSON.parse above remains the authority for strict JSON syntax and\n // for the returned JavaScript value.\n parseYaml(content, { json: false });\n return parsed;\n}\n\n/**\n * Read a file's contents, converting missing-file/directory/permission\n * failures into a clean {@link ConfigError} instead of a raw Node `fs` error\n * (mirrors the Python CLI's `_load_config_file`).\n */\nfunction readFileClean(filepath: string): string {\n let stat: ReturnType<typeof statSync> | undefined;\n try {\n stat = statSync(filepath);\n } catch (cause) {\n const code = (cause as NodeJS.ErrnoException).code;\n if (code === \"ENOENT\") throw new ConfigError(`Config file not found: ${filepath}`);\n if (code === \"EACCES\") throw new ConfigError(`Permission denied: ${filepath}`);\n throw new ConfigError(`Could not read ${filepath}: ${(cause as Error).message}`, [], { cause });\n }\n if (stat.isDirectory()) {\n throw new ConfigError(`Not a file (is a directory): ${filepath}`);\n }\n try {\n return readFileSync(filepath, \"utf-8\");\n } catch (cause) {\n throw new ConfigError(`Could not read ${filepath}: ${(cause as Error).message}`, [], { cause });\n }\n}\n\n/** Guard against an empty file or a non-object parse result (e.g. an empty YAML document). */\nfunction assertNonEmptyObject(data: unknown, filepath: string): Record<string, unknown> {\n if (data == null) {\n throw new ConfigError(`Bursar config is empty: ${filepath}`);\n }\n if (typeof data !== \"object\" || Array.isArray(data)) {\n throw new ConfigError(\n `Bursar config must be a JSON/YAML object, got ${typeof data}: ${filepath}`,\n );\n }\n if (Object.keys(data).length === 0) {\n throw new ConfigError(`Bursar config is empty: ${filepath}`);\n }\n return data as Record<string, unknown>;\n}\n\n/**\n * Read a JSON or YAML Bursar config file from disk.\n *\n * Returns the raw parsed dict (suitable for ``loadConfigFromDict`` or\n * ``PricingEngine.fromDict``).\n *\n * JSON syntax is validated by the platform parser and mapping keys are also\n * checked by js-yaml so duplicate config fields cannot silently overwrite.\n */\nexport async function loadConfigFile(filepath: string): Promise<Record<string, unknown>> {\n const extension = extname(filepath).toLowerCase();\n if (!new Set([\".json\", \".yaml\", \".yml\"]).has(extension)) {\n throw new ConfigError(\n `Unsupported config file format: ${extension || \"<none>\"}. Expected .json, .yaml, or .yml`,\n );\n }\n\n if (extension === \".yaml\" || extension === \".yml\") {\n const content = readFileClean(filepath);\n let parsed: unknown;\n try {\n parsed = parseYaml(content, { json: false });\n } catch (cause) {\n throw new ConfigError(`Invalid YAML in ${filepath}: ${(cause as Error).message}`, [], {\n cause,\n });\n }\n return assertNonEmptyObject(parsed, filepath);\n }\n\n const content = readFileClean(filepath);\n let parsed: unknown;\n try {\n parsed = parseJsonWithUniqueKeys(content);\n } catch (cause) {\n throw new ConfigError(`Invalid JSON in ${filepath}: ${(cause as Error).message}`, [], {\n cause,\n });\n }\n return assertNonEmptyObject(parsed, filepath);\n}\n"]}
package/dist/metrics.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type Decimal from "decimal.js";
1
+ import type { Decimal } from "decimal.js";
2
2
  /** One provider-neutral billable operation. */
3
3
  export interface UsageMetrics {
4
4
  operation: string;
@@ -1 +1 @@
1
- {"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../src/metrics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,YAAY,CAAC;AAEtC,+CAA+C;AAC/C,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC;IAC3C,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;IACvE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC"}
1
+ {"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../src/metrics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C,+CAA+C;AAC/C,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC;IAC3C,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;IACvE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC"}
@@ -1 +1 @@
1
- {"version":3,"file":"metrics.js","sourceRoot":"","sources":["../src/metrics.ts"],"names":[],"mappings":"","sourcesContent":["import type Decimal from \"decimal.js\";\n\n/** One provider-neutral billable operation. */\nexport interface UsageMetrics {\n operation: string;\n measures?: Record<string, number | string>;\n dimensions?: Record<string, string | number | boolean | Decimal.Value>;\n metadata?: Record<string, unknown>;\n}\n"]}
1
+ {"version":3,"file":"metrics.js","sourceRoot":"","sources":["../src/metrics.ts"],"names":[],"mappings":"","sourcesContent":["import type { Decimal } from \"decimal.js\";\n\n/** One provider-neutral billable operation. */\nexport interface UsageMetrics {\n operation: string;\n measures?: Record<string, number | string>;\n dimensions?: Record<string, string | number | boolean | Decimal.Value>;\n metadata?: Record<string, unknown>;\n}\n"]}
package/dist/node.d.ts CHANGED
@@ -12,11 +12,14 @@
12
12
  export { loadConfigFile } from "./load-config-file.js";
13
13
  export { BursarRuntime, createBursarRuntime } from "./storage/runtime.js";
14
14
  export type { BursarRuntimeBursarOptions, BursarRuntimeHealth, BursarRuntimeOptions, BursarRuntimeStartOptions, } from "./storage/runtime.js";
15
+ export type { BursarRuntimeDiagnostics, BursarRuntimeState, CatalogDependencyCheck, CheckDependenciesOptions, DependencyCheck, DependencyStatus, OutboxDependencyCheck, OutboxStatusSnapshot, WorkerErrorSnapshot, WorkerLifecycle, WorkerRunSnapshot, WorkerState, } from "./storage/diagnostics.js";
16
+ export { BursarMaintenance, BursarOperatorMaintenance } from "./storage/maintenance.js";
17
+ export type { MaintenanceRunOptions, MaintenanceRunResult, MaintenanceRunStatus, MaintenanceOperations, MaintenanceTaskResult, MaintenanceTaskStatus, OperatorMaintenanceRunOptions, PartitionMaintenanceResult, StorageMaintenanceCounts, StorageMaintenanceResult, StorageMaintenanceStatus, StoragePartition, } from "./storage/maintenance.js";
15
18
  export { OutboxWorker } from "./storage/outbox-worker.js";
16
- export type { OutboxRunResult, OutboxWorkerOptions } from "./storage/outbox-worker.js";
19
+ export type { OutboxClaimLossPhase, OutboxEventOutcome, OutboxEventOutcomeStatus, OutboxRunResult, OutboxWorkerOptions, } from "./storage/outbox-worker.js";
17
20
  export { ClickHouseUsageStore } from "./storage/adapters/clickhouse.js";
18
21
  export type { ClickHouseClient, ClickHouseQueryResult, ClickHouseUsageStoreOptions, } from "./storage/adapters/clickhouse.js";
19
22
  export { S3BillingArchive } from "./storage/adapters/s3.js";
20
- export type { S3BillingArchiveOptions, S3Credentials } from "./storage/adapters/s3.js";
21
- export type { BillingEventPayloadExport, BillingPayloadArchive, BillingPayloadArchiveResult, OutboxEvent, OutboxHandler, OutboxStore, UsageChargeExport, UsageEventSink, } from "./storage/ports.js";
23
+ export type { S3ArchiveClient, S3ArchiveClientFactory, S3BillingArchiveOptions, S3Credentials, S3PutObjectOptions, } from "./storage/adapters/s3.js";
24
+ export type { BillingEventPayloadExport, BillingPayloadArchive, BillingPayloadArchiveResult, OutboxClaimRenewalStore, OutboxDeadLetter, OutboxDeadLetterCursor, OutboxDeadLetterListOptions, OutboxDeadLetterPage, OutboxEvent, OutboxHandler, OutboxRecoveryStore, OutboxStats, OutboxStore, UsageChargeExport, UsageEventSink, } from "./storage/ports.js";
22
25
  //# sourceMappingURL=node.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAIvD,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC1E,YAAY,EACV,0BAA0B,EAC1B,mBAAmB,EACnB,oBAAoB,EACpB,yBAAyB,GAC1B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,YAAY,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACvF,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AACxE,YAAY,EACV,gBAAgB,EAChB,qBAAqB,EACrB,2BAA2B,GAC5B,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,YAAY,EAAE,uBAAuB,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACvF,YAAY,EACV,yBAAyB,EACzB,qBAAqB,EACrB,2BAA2B,EAC3B,WAAW,EACX,aAAa,EACb,WAAW,EACX,iBAAiB,EACjB,cAAc,GACf,MAAM,oBAAoB,CAAC"}
1
+ {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,cAAc,E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2B,EAC3B,oBAAoB,EACpB,WAAW,EACX,aAAa,EACb,mBAAmB,EACnB,WAAW,EACX,WAAW,EACX,iBAAiB,EACjB,cAAc,GACf,MAAM,oBAAoB,CAAC"}
package/dist/node.js CHANGED
@@ -13,6 +13,7 @@ export { loadConfigFile } from "./load-config-file.js";
13
13
  // Optional high-volume storage infrastructure. These adapters are Node-only;
14
14
  // the main package remains the PostgreSQL-first application API.
15
15
  export { BursarRuntime, createBursarRuntime } from "./storage/runtime.js";
16
+ export { BursarMaintenance, BursarOperatorMaintenance } from "./storage/maintenance.js";
16
17
  export { OutboxWorker } from "./storage/outbox-worker.js";
17
18
  export { ClickHouseUsageStore } from "./storage/adapters/clickhouse.js";
18
19
  export { S3BillingArchive } from "./storage/adapters/s3.js";
package/dist/node.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"node.js","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,6EAA6E;AAC7E,iEAAiE;AACjE,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAO1E,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAMxE,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC","sourcesContent":["/**\n * Node.js-only bursar exports.\n *\n * These modules depend on Node built-ins (`crypto`, `fs`) and are not\n * compatible with Edge Runtime environments. Import them from the\n * ``@zonastery/bursar/node`` subpath when you need Node-specific behaviour:\n *\n * ```ts\n * import { loadConfigFile } from \"@zonastery/bursar/node\";\n * ```\n */\n\nexport { loadConfigFile } from \"./load-config-file.js\";\n\n// Optional high-volume storage infrastructure. These adapters are Node-only;\n// the main package remains the PostgreSQL-first application API.\nexport { BursarRuntime, createBursarRuntime } from \"./storage/runtime.js\";\nexport type {\n BursarRuntimeBursarOptions,\n BursarRuntimeHealth,\n BursarRuntimeOptions,\n BursarRuntimeStartOptions,\n} from \"./storage/runtime.js\";\nexport { OutboxWorker } from \"./storage/outbox-worker.js\";\nexport type { OutboxRunResult, OutboxWorkerOptions } from \"./storage/outbox-worker.js\";\nexport { ClickHouseUsageStore } from \"./storage/adapters/clickhouse.js\";\nexport type {\n ClickHouseClient,\n ClickHouseQueryResult,\n ClickHouseUsageStoreOptions,\n} from \"./storage/adapters/clickhouse.js\";\nexport { S3BillingArchive } from \"./storage/adapters/s3.js\";\nexport type { S3BillingArchiveOptions, S3Credentials } from \"./storage/adapters/s3.js\";\nexport type {\n BillingEventPayloadExport,\n BillingPayloadArchive,\n BillingPayloadArchiveResult,\n OutboxEvent,\n OutboxHandler,\n OutboxStore,\n UsageChargeExport,\n UsageEventSink,\n} from \"./storage/ports.js\";\n"]}
1
+ {"version":3,"file":"node.js","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,6EAA6E;AAC7E,iEAAiE;AACjE,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAqB1E,OAAO,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AAexF,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAQ1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAMxE,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC","sourcesContent":["/**\n * Node.js-only bursar exports.\n *\n * These modules depend on Node built-ins (`crypto`, `fs`) and are not\n * compatible with Edge Runtime environments. Import them from the\n * ``@zonastery/bursar/node`` subpath when you need Node-specific behaviour:\n *\n * ```ts\n * import { loadConfigFile } from \"@zonastery/bursar/node\";\n * ```\n */\n\nexport { loadConfigFile } from \"./load-config-file.js\";\n\n// Optional high-volume storage infrastructure. These adapters are Node-only;\n// the main package remains the PostgreSQL-first application API.\nexport { BursarRuntime, createBursarRuntime } from \"./storage/runtime.js\";\nexport type {\n BursarRuntimeBursarOptions,\n BursarRuntimeHealth,\n BursarRuntimeOptions,\n BursarRuntimeStartOptions,\n} from \"./storage/runtime.js\";\nexport type {\n BursarRuntimeDiagnostics,\n BursarRuntimeState,\n CatalogDependencyCheck,\n CheckDependenciesOptions,\n DependencyCheck,\n DependencyStatus,\n OutboxDependencyCheck,\n OutboxStatusSnapshot,\n WorkerErrorSnapshot,\n WorkerLifecycle,\n WorkerRunSnapshot,\n WorkerState,\n} from \"./storage/diagnostics.js\";\nexport { BursarMaintenance, BursarOperatorMaintenance } from \"./storage/maintenance.js\";\nexport type {\n MaintenanceRunOptions,\n MaintenanceRunResult,\n MaintenanceRunStatus,\n MaintenanceOperations,\n MaintenanceTaskResult,\n MaintenanceTaskStatus,\n OperatorMaintenanceRunOptions,\n PartitionMaintenanceResult,\n StorageMaintenanceCounts,\n StorageMaintenanceResult,\n StorageMaintenanceStatus,\n StoragePartition,\n} from \"./storage/maintenance.js\";\nexport { OutboxWorker } from \"./storage/outbox-worker.js\";\nexport type {\n OutboxClaimLossPhase,\n OutboxEventOutcome,\n OutboxEventOutcomeStatus,\n OutboxRunResult,\n OutboxWorkerOptions,\n} from \"./storage/outbox-worker.js\";\nexport { ClickHouseUsageStore } from \"./storage/adapters/clickhouse.js\";\nexport type {\n ClickHouseClient,\n ClickHouseQueryResult,\n ClickHouseUsageStoreOptions,\n} from \"./storage/adapters/clickhouse.js\";\nexport { S3BillingArchive } from \"./storage/adapters/s3.js\";\nexport type {\n S3ArchiveClient,\n S3ArchiveClientFactory,\n S3BillingArchiveOptions,\n S3Credentials,\n S3PutObjectOptions,\n} from \"./storage/adapters/s3.js\";\nexport type {\n BillingEventPayloadExport,\n BillingPayloadArchive,\n BillingPayloadArchiveResult,\n OutboxClaimRenewalStore,\n OutboxDeadLetter,\n OutboxDeadLetterCursor,\n OutboxDeadLetterListOptions,\n OutboxDeadLetterPage,\n OutboxEvent,\n OutboxHandler,\n OutboxRecoveryStore,\n OutboxStats,\n OutboxStore,\n UsageChargeExport,\n UsageEventSink,\n} from \"./storage/ports.js\";\n"]}
@@ -6,9 +6,9 @@ export declare function optionalProviderBoolean(value: unknown, field: string):
6
6
  export declare function requireMinorUnits(value: unknown, field: string, positive?: boolean): number;
7
7
  export declare function requireCurrency(value: unknown, field: string): string;
8
8
  /**
9
- * Wrapper around the facade event sink that throws on unhandled results (except
10
- * "unhandled_event_type" which is a permanent no-op). Ensures the provider
11
- * receives a retryable signal when the event could not be processed.
9
+ * Wrapper around the facade event sink that throws on retryable or unexpected
10
+ * failures. Permanent claim outcomes are returned so the provider can
11
+ * acknowledge them without scheduling another delivery.
12
12
  */
13
13
  export declare function callBillingEventSink(sink: BillingEventSink, event: BillingEvent): Promise<BillingEventResult>;
14
14
  //# sourceMappingURL=_shared.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"_shared.d.ts","sourceRoot":"","sources":["../../src/providers/_shared.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAC5E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAOrD,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAK3E;AAED,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAGxF;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAM1F;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,UAAQ,GAAG,MAAM,CAazF;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAKrE;AAED;;;;GAIG;AACH,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,gBAAgB,EACtB,KAAK,EAAE,YAAY,GAClB,OAAO,CAAC,kBAAkB,CAAC,CA4C7B"}
1
+ {"version":3,"file":"_shared.d.ts","sourceRoot":"","sources":["../../src/providers/_shared.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAC5E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAerD,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAK3E;AAED,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAGxF;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAM1F;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,UAAQ,GAAG,MAAM,CAazF;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAKrE;AAED;;;;GAIG;AACH,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,gBAAgB,EACtB,KAAK,EAAE,YAAY,GAClB,OAAO,CAAC,kBAAkB,CAAC,CAwC7B"}
@@ -3,6 +3,13 @@ import { BursarError, StoreUnavailableError } from "../errors.js";
3
3
  class BillingClaimBusyError extends Error {
4
4
  name = "BillingClaimBusyError";
5
5
  }
6
+ const ACKNOWLEDGED_BILLING_EVENT_ERRORS = new Set([
7
+ "unhandled_event_type",
8
+ "account_not_found",
9
+ "invalid_request",
10
+ "idempotency_conflict",
11
+ "max_retries_exceeded",
12
+ ]);
6
13
  export function requireProviderString(value, field) {
7
14
  if (typeof value !== "string" || value.trim().length === 0) {
8
15
  throw new TypeError(`${field} must be a non-empty string`);
@@ -40,9 +47,9 @@ export function requireCurrency(value, field) {
40
47
  return value.toUpperCase();
41
48
  }
42
49
  /**
43
- * Wrapper around the facade event sink that throws on unhandled results (except
44
- * "unhandled_event_type" which is a permanent no-op). Ensures the provider
45
- * receives a retryable signal when the event could not be processed.
50
+ * Wrapper around the facade event sink that throws on retryable or unexpected
51
+ * failures. Permanent claim outcomes are returned so the provider can
52
+ * acknowledge them without scheduling another delivery.
46
53
  */
47
54
  export async function callBillingEventSink(sink, event) {
48
55
  let result;
@@ -76,9 +83,7 @@ export async function callBillingEventSink(sink, event) {
76
83
  details: { reason: result.error },
77
84
  });
78
85
  }
79
- if (!result.handled &&
80
- result.error !== "unhandled_event_type" &&
81
- result.error !== "user_not_found") {
86
+ if (!result.handled && !ACKNOWLEDGED_BILLING_EVENT_ERRORS.has(result.error ?? "")) {
82
87
  throw new BursarError("Bursar failed to ingest the billing event", {
83
88
  details: { reason: result.error ?? "unknown" },
84
89
  });
@@ -1 +1 @@
1
- {"version":3,"file":"_shared.js","sourceRoot":"","sources":["../../src/providers/_shared.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,SAAS,CAAC;AAI7B,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAElE,MAAM,qBAAsB,SAAQ,KAAK;IACrB,IAAI,GAAG,uBAAuB,CAAC;CAClD;AAED,MAAM,UAAU,qBAAqB,CAAC,KAAc,EAAE,KAAa;IACjE,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC3D,MAAM,IAAI,SAAS,CAAC,GAAG,KAAK,6BAA6B,CAAC,CAAC;IAC7D,CAAC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AAC,KAAK,EAAE;SAClC,CAAC,CAAC;IACL,CAAC;IACD,IACE,CAAC,MAAM,CAAC,OAAO;QACf,MAAM,CAAC,KAAK,KAAK,sBAAsB;QACvC,MAAM,CAAC,KAAK,KAAK,gBAAgB,EACjC,CAAC;QACD,MAAM,IAAI,WAAW,CAAC,2CAA2C,EAAE;YACjE,OAAO,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,IAAI,SAAS,EAAE;SAC/C,CAAC,CAAC;IACL,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import pRetry from \"p-retry\";\n\nimport type { BillingEvent, BillingEventResult } from \"../billing/index.js\";\nimport type { BillingEventSink } from \"../bursar.js\";\nimport { BursarError, StoreUnavailableError } from \"../errors.js\";\n\nclass BillingClaimBusyError extends Error {\n override readonly name = \"BillingClaimBusyError\";\n}\n\nexport function requireProviderString(value: unknown, field: string): string {\n if (typeof value !== \"string\" || value.trim().length === 0) {\n throw new TypeError(`${field} must be a non-empty string`);\n }\n return value.trim();\n}\n\nexport function optionalProviderString(value: unknown, field: string): string | undefined {\n if (value === null || value === undefined) return undefined;\n return requireProviderString(value, field);\n}\n\nexport function optionalProviderBoolean(value: unknown, field: string): boolean | undefined {\n if (value === null || value === undefined) return undefined;\n if (typeof value !== \"boolean\") {\n throw new TypeError(`${field} must be a boolean`);\n }\n return value;\n}\n\nexport function requireMinorUnits(value: unknown, field: string, positive = false): number {\n const amount =\n typeof value === \"number\"\n ? value\n : typeof value === \"string\" && /^\\d+$/.test(value)\n ? Number(value)\n : Number.NaN;\n if (!Number.isSafeInteger(amount) || amount < (positive ? 1 : 0)) {\n throw new TypeError(\n `${field} must be a ${positive ? \"positive\" : \"non-negative\"} safe integer`,\n );\n }\n return amount;\n}\n\nexport function requireCurrency(value: unknown, field: string): string {\n if (typeof value !== \"string\" || !/^[A-Za-z]{3}$/.test(value)) {\n throw new TypeError(`${field} must be a three-letter currency code`);\n }\n return value.toUpperCase();\n}\n\n/**\n * Wrapper around the facade event sink that throws on unhandled results (except\n * \"unhandled_event_type\" which is a permanent no-op). Ensures the provider\n * receives a retryable signal when the event could not be processed.\n */\nexport async function callBillingEventSink(\n sink: BillingEventSink,\n event: BillingEvent,\n): Promise<BillingEventResult> {\n let result: BillingEventResult;\n try {\n result = await pRetry(\n async () => {\n const attempted = await sink.ingestBillingEvent(event);\n if (attempted.error === \"claim_busy\") throw new BillingClaimBusyError();\n return attempted;\n },\n {\n retries: 6,\n minTimeout: 25,\n maxTimeout: 800,\n factor: 2,\n randomize: true,\n maxRetryTime: 5_000,\n shouldRetry: ({ error }) => error instanceof BillingClaimBusyError,\n },\n );\n } catch (cause) {\n if (cause instanceof BillingClaimBusyError) {\n throw new StoreUnavailableError(\"Billing event claim remained busy\", {\n cause,\n details: { reason: \"claim_busy\" },\n });\n }\n throw cause;\n }\n\n if (result.error === \"claim_failed_retry\") {\n throw new StoreUnavailableError(\"Billing event claim could not be acquired\", {\n details: { reason: result.error },\n });\n }\n if (\n !result.handled &&\n result.error !== \"unhandled_event_type\" &&\n result.error !== \"user_not_found\"\n ) {\n throw new BursarError(\"Bursar failed to ingest the billing event\", {\n details: { reason: result.error ?? \"unknown\" },\n });\n }\n return result;\n}\n"]}
1
+ {"version":3,"file":"_shared.js","sourceRoot":"","sources":["../../src/providers/_shared.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,SAAS,CAAC;AAI7B,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAElE,MAAM,qBAAsB,SAAQ,KAAK;IACrB,IAAI,GAAG,uBAAuB,CAAC;CAClD;AAED,MAAM,iCAAiC,GAAG,IAAI,GAAG,CAAC;IAChD,sBAAsB;IACtB,mBAAmB;IACnB,iBAAiB;IACjB,sBAAsB;IACtB,sBAAsB;CACvB,CAAC,CAAC;AAEH,MAAM,UAAU,qBAAqB,CAAC,KAAc,EAAE,KAAa;IACjE,IAAI,OAAO,KAAK,KAAK,QAA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ED,IAAI,MAAM,CAAC,KAAK,KAAK,oBAAoB,EAAE,CAAC;QAC1C,MAAM,IAAI,qBAAqB,CAAC,2CAA2C,EAAE;YAC3E,OAAO,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,EAAE;SAClC,CAAC,CAAC;IACL,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,CAAC,iCAAiC,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC,EAAE,CAAC;QAClF,MAAM,IAAI,WAAW,CAAC,2CAA2C,EAAE;YACjE,OAAO,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,IAAI,SAAS,EAAE;SAC/C,CAAC,CAAC;IACL,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import pRetry from \"p-retry\";\n\nimport type { BillingEvent, BillingEventResult } from \"../billing/index.js\";\nimport type { BillingEventSink } from \"../bursar.js\";\nimport { BursarError, StoreUnavailableError } from \"../errors.js\";\n\nclass BillingClaimBusyError extends Error {\n override readonly name = \"BillingClaimBusyError\";\n}\n\nconst ACKNOWLEDGED_BILLING_EVENT_ERRORS = new Set([\n \"unhandled_event_type\",\n \"account_not_found\",\n \"invalid_request\",\n \"idempotency_conflict\",\n \"max_retries_exceeded\",\n]);\n\nexport function requireProviderString(value: unknown, field: string): string {\n if (typeof value !== \"string\" || value.trim().length === 0) {\n throw new TypeError(`${field} must be a non-empty string`);\n }\n return value.trim();\n}\n\nexport function optionalProviderString(value: unknown, field: string): string | undefined {\n if (value === null || value === undefined) return undefined;\n return requireProviderString(value, field);\n}\n\nexport function optionalProviderBoolean(value: unknown, field: string): boolean | undefined {\n if (value === null || value === undefined) return undefined;\n if (typeof value !== \"boolean\") {\n throw new TypeError(`${field} must be a boolean`);\n }\n return value;\n}\n\nexport function requireMinorUnits(value: unknown, field: string, positive = false): number {\n const amount =\n typeof value === \"number\"\n ? value\n : typeof value === \"string\" && /^\\d+$/.test(value)\n ? Number(value)\n : Number.NaN;\n if (!Number.isSafeInteger(amount) || amount < (positive ? 1 : 0)) {\n throw new TypeError(\n `${field} must be a ${positive ? \"positive\" : \"non-negative\"} safe integer`,\n );\n }\n return amount;\n}\n\nexport function requireCurrency(value: unknown, field: string): string {\n if (typeof value !== \"string\" || !/^[A-Za-z]{3}$/.test(value)) {\n throw new TypeError(`${field} must be a three-letter currency code`);\n }\n return value.toUpperCase();\n}\n\n/**\n * Wrapper around the facade event sink that throws on retryable or unexpected\n * failures. Permanent claim outcomes are returned so the provider can\n * acknowledge them without scheduling another delivery.\n */\nexport async function callBillingEventSink(\n sink: BillingEventSink,\n event: BillingEvent,\n): Promise<BillingEventResult> {\n let result: BillingEventResult;\n try {\n result = await pRetry(\n async () => {\n const attempted = await sink.ingestBillingEvent(event);\n if (attempted.error === \"claim_busy\") throw new BillingClaimBusyError();\n return attempted;\n },\n {\n retries: 6,\n minTimeout: 25,\n maxTimeout: 800,\n factor: 2,\n randomize: true,\n maxRetryTime: 5_000,\n shouldRetry: ({ error }) => error instanceof BillingClaimBusyError,\n },\n );\n } catch (cause) {\n if (cause instanceof BillingClaimBusyError) {\n throw new StoreUnavailableError(\"Billing event claim remained busy\", {\n cause,\n details: { reason: \"claim_busy\" },\n });\n }\n throw cause;\n }\n\n if (result.error === \"claim_failed_retry\") {\n throw new StoreUnavailableError(\"Billing event claim could not be acquired\", {\n details: { reason: result.error },\n });\n }\n if (!result.handled && !ACKNOWLEDGED_BILLING_EVENT_ERRORS.has(result.error ?? \"\")) {\n throw new BursarError(\"Bursar failed to ingest the billing event\", {\n details: { reason: result.error ?? \"unknown\" },\n });\n }\n return result;\n}\n"]}
@@ -10,9 +10,11 @@ type DodoCheckoutSessionStatus = Awaited<ReturnType<DodoPayments["checkoutSessio
10
10
  type DodoCheckoutPreview = Awaited<ReturnType<DodoPayments["checkoutSessions"]["preview"]>>;
11
11
  type DodoPayment = Awaited<ReturnType<DodoPayments["payments"]["retrieve"]>>;
12
12
  type DodoPlanChangePreview = Awaited<ReturnType<DodoPayments["subscriptions"]["previewChangePlan"]>>;
13
+ type DodoPaymentMethodUpdate = Awaited<ReturnType<DodoPayments["subscriptions"]["updatePaymentMethod"]>>;
13
14
  type DodoCustomer = Awaited<ReturnType<DodoPayments["customers"]["create"]>>;
14
15
  type DodoCustomerPortalSession = Awaited<ReturnType<DodoPayments["customers"]["customerPortal"]["create"]>>;
15
16
  type DodoPaymentMethods = Awaited<ReturnType<DodoPayments["customers"]["retrievePaymentMethods"]>>;
17
+ type DodoMutationRequestOptions = Pick<NonNullable<Parameters<DodoPayments["checkoutSessions"]["create"]>[1]>, "headers">;
16
18
  type DodoSdkWebhookPayload = ReturnType<DodoPayments["webhooks"]["unwrap"]>;
17
19
  /**
18
20
  * Payload returned by an official Dodo adapter after signature verification.
@@ -35,14 +37,12 @@ export interface DodoClient {
35
37
  }): DodoWebhookPayload;
36
38
  };
37
39
  checkoutSessions: {
38
- create(body: Parameters<DodoPayments["checkoutSessions"]["create"]>[0], options?: {
39
- idempotencyKey?: string;
40
- }): Promise<DodoCheckoutSession>;
40
+ create(body: Parameters<DodoPayments["checkoutSessions"]["create"]>[0], options?: DodoMutationRequestOptions): Promise<DodoCheckoutSession>;
41
41
  preview(body: Parameters<DodoPayments["checkoutSessions"]["preview"]>[0]): Promise<DodoCheckoutPreview>;
42
42
  retrieve(sessionId: Parameters<DodoPayments["checkoutSessions"]["retrieve"]>[0]): Promise<DodoCheckoutSessionStatus>;
43
43
  };
44
44
  customers: {
45
- create(body: Parameters<DodoPayments["customers"]["create"]>[0]): Promise<DodoCustomer>;
45
+ create(body: Parameters<DodoPayments["customers"]["create"]>[0], options?: DodoMutationRequestOptions): Promise<DodoCustomer>;
46
46
  customerPortal: {
47
47
  create(customerId: Parameters<DodoPayments["customers"]["customerPortal"]["create"]>[0], body: Parameters<DodoPayments["customers"]["customerPortal"]["create"]>[1]): Promise<DodoCustomerPortalSession>;
48
48
  };
@@ -52,16 +52,11 @@ export interface DodoClient {
52
52
  retrieve(paymentId: Parameters<DodoPayments["payments"]["retrieve"]>[0]): Promise<DodoPayment>;
53
53
  };
54
54
  subscriptions: {
55
- cancelChangePlan(subscriptionId: Parameters<DodoPayments["subscriptions"]["cancelChangePlan"]>[0], options?: {
56
- idempotencyKey?: string;
57
- }): Promise<unknown>;
58
- changePlan(subscriptionId: Parameters<DodoPayments["subscriptions"]["changePlan"]>[0], body: Parameters<DodoPayments["subscriptions"]["changePlan"]>[1], options?: {
59
- idempotencyKey?: string;
60
- }): Promise<unknown>;
55
+ cancelChangePlan(subscriptionId: Parameters<DodoPayments["subscriptions"]["cancelChangePlan"]>[0], options?: DodoMutationRequestOptions): Promise<unknown>;
56
+ changePlan(subscriptionId: Parameters<DodoPayments["subscriptions"]["changePlan"]>[0], body: Parameters<DodoPayments["subscriptions"]["changePlan"]>[1], options?: DodoMutationRequestOptions): Promise<unknown>;
61
57
  previewChangePlan(subscriptionId: Parameters<DodoPayments["subscriptions"]["previewChangePlan"]>[0], body: Parameters<DodoPayments["subscriptions"]["previewChangePlan"]>[1]): Promise<DodoPlanChangePreview>;
62
- update(subscriptionId: Parameters<DodoPayments["subscriptions"]["update"]>[0], body: Parameters<DodoPayments["subscriptions"]["update"]>[1], options?: {
63
- idempotencyKey?: string;
64
- }): Promise<unknown>;
58
+ update(subscriptionId: Parameters<DodoPayments["subscriptions"]["update"]>[0], body: Parameters<DodoPayments["subscriptions"]["update"]>[1], options?: DodoMutationRequestOptions): Promise<unknown>;
59
+ updatePaymentMethod(subscriptionId: Parameters<DodoPayments["subscriptions"]["updatePaymentMethod"]>[0], body: Parameters<DodoPayments["subscriptions"]["updatePaymentMethod"]>[1]): Promise<DodoPaymentMethodUpdate>;
65
60
  };
66
61
  }
67
62
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"client-contract.d.ts","sourceRoot":"","sources":["../../../src/providers/dodo/client-contract.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,YAAY,MAAM,cAAc,CAAC;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esContent":["import type DodoPayments from \"dodopayments\";\n\n/**\n * The public Dodo SDK surface used by Bursar.\n *\n * This structural boundary prevents compatible Dodo SDK installations from\n * becoming nominally incompatible through private class and APIPromise fields.\n */\ntype DodoCheckoutSession = Awaited<ReturnType<DodoPayments[\"checkoutSessions\"][\"create\"]>>;\ntype DodoCheckoutSessionStatus = Awaited<ReturnType<DodoPayments[\"checkoutSessions\"][\"retrieve\"]>>;\ntype DodoCheckoutPreview = Awaited<ReturnType<DodoPayments[\"checkoutSessions\"][\"preview\"]>>;\ntype DodoPayment = Awaited<ReturnType<DodoPayments[\"payments\"][\"retrieve\"]>>;\ntype DodoPlanChangePreview = Awaited<\n ReturnType<DodoPayments[\"subscriptions\"][\"previewChangePlan\"]>\n>;\ntype DodoCustomer = Awaited<ReturnType<DodoPayments[\"customers\"][\"create\"]>>;\ntype DodoCustomerPortalSession = Awaited<\n ReturnType<DodoPayments[\"customers\"][\"customerPortal\"][\"create\"]>\n>;\ntype DodoPaymentMethods = Awaited<ReturnType<DodoPayments[\"customers\"][\"retrievePaymentMethods\"]>>;\n\ntype DodoSdkWebhookPayload = ReturnType<DodoPayments[\"webhooks\"][\"unwrap\"]>;\n\n/**\n * Payload returned by an official Dodo adapter after signature verification.\n *\n * Dodo's core, Next.js, and Better Auth packages expose equivalent webhook\n * envelopes but can carry incompatible nested SDK types. Keep the envelope\n * SDK-derived and treat only the resource payload as untrusted input; Bursar's\n * mapper validates every field it consumes.\n */\nexport type DodoWebhookPayload = Partial<\n Omit<DodoSdkWebhookPayload, \"data\" | \"timestamp\" | \"type\">\n> & {\n data: unknown;\n timestamp: string | Date;\n type: string;\n};\n\nexport interface DodoClient {\n webhooks: {\n unwrap(\n body: string,\n options: { headers: Record<string, string>; key?: string },\n ): DodoWebhookPayload;\n };\n checkoutSessions: {\n create(\n body: Parameters<DodoPayments[\"checkoutSessions\"][\"create\"]>[0],\n options?: { idempotencyKey?: string },\n ): Promise<DodoCheckoutSession>;\n preview(\n body: Parameters<DodoPayments[\"checkoutSessions\"][\"preview\"]>[0],\n ): Promise<DodoCheckoutPreview>;\n retrieve(\n sessionId: Parameters<DodoPayments[\"checkoutSessions\"][\"retrieve\"]>[0],\n ): Promise<DodoCheckoutSessionStatus>;\n };\n customers: {\n create(body: Parameters<DodoPayments[\"customers\"][\"create\"]>[0]): Promise<DodoCustomer>;\n customerPortal: {\n create(\n customerId: Parameters<DodoPayments[\"customers\"][\"customerPortal\"][\"create\"]>[0],\n body: Parameters<DodoPayments[\"customers\"][\"customerPortal\"][\"create\"]>[1],\n ): Promise<DodoCustomerPortalSession>;\n };\n retrievePaymentMethods(\n customerId: Parameters<DodoPayments[\"customers\"][\"retrievePaymentMethods\"]>[0],\n ): Promise<DodoPaymentMethods>;\n };\n payments: {\n retrieve(paymentId: Parameters<DodoPayments[\"payments\"][\"retrieve\"]>[0]): Promise<DodoPayment>;\n };\n subscriptions: {\n cancelChangePlan(\n subscriptionId: Parameters<DodoPayments[\"subscriptions\"][\"cancelChangePlan\"]>[0],\n options?: { idempotencyKey?: string },\n ): Promise<unknown>;\n changePlan(\n subscriptionId: Parameters<DodoPayments[\"subscriptions\"][\"changePlan\"]>[0],\n body: Parameters<DodoPayments[\"subscriptions\"][\"changePlan\"]>[1],\n options?: { idempotencyKey?: string },\n ): Promise<unknown>;\n previewChangePlan(\n subscriptionId: Parameters<DodoPayments[\"subscriptions\"][\"previewChangePlan\"]>[0],\n body: Parameters<DodoPayments[\"subscriptions\"][\"previewChangePlan\"]>[1],\n ): Promise<DodoPlanChangePreview>;\n update(\n subscriptionId: Parameters<DodoPayments[\"subscriptions\"][\"update\"]>[0],\n body: Parameters<DodoPayments[\"subscriptions\"][\"update\"]>[1],\n options?: { idempotencyKey?: string },\n ): Promise<unknown>;\n };\n}\n"]}
1
+ {"version":3,"file":"client-contract.js","sourceRoot":"","sources":["../../../src/providers/dodo/client-contract.ts"],"names":[],"mappings":"","sourcesContent":["import type DodoPayments from \"dodopayments\";\n\n/**\n * The public Dodo SDK surface used by Bursar.\n *\n * This structural boundary prevents compatible Dodo SDK installations from\n * becoming nominally incompatible through private class and APIPromise fields.\n */\ntype DodoCheckoutSession = Awaited<ReturnType<DodoPayments[\"checkoutSessions\"][\"create\"]>>;\ntype DodoCheckoutSessionStatus = Awaited<ReturnType<DodoPayments[\"checkoutSessions\"][\"retrieve\"]>>;\ntype DodoCheckoutPreview = Awaited<ReturnType<DodoPayments[\"checkoutSessions\"][\"preview\"]>>;\ntype DodoPayment = Awaited<ReturnType<DodoPayments[\"payments\"][\"retrieve\"]>>;\ntype DodoPlanChangePreview = Awaited<\n ReturnType<DodoPayments[\"subscriptions\"][\"previewChangePlan\"]>\n>;\ntype DodoPaymentMethodUpdate = Awaited<\n ReturnType<DodoPayments[\"subscriptions\"][\"updatePaymentMethod\"]>\n>;\ntype DodoCustomer = Awaited<ReturnType<DodoPayments[\"customers\"][\"create\"]>>;\ntype DodoCustomerPortalSession = Awaited<\n ReturnType<DodoPayments[\"customers\"][\"customerPortal\"][\"create\"]>\n>;\ntype DodoPaymentMethods = Awaited<ReturnType<DodoPayments[\"customers\"][\"retrievePaymentMethods\"]>>;\ntype DodoMutationRequestOptions = Pick<\n NonNullable<Parameters<DodoPayments[\"checkoutSessions\"][\"create\"]>[1]>,\n \"headers\"\n>;\n\ntype DodoSdkWebhookPayload = ReturnType<DodoPayments[\"webhooks\"][\"unwrap\"]>;\n\n/**\n * Payload returned by an official Dodo adapter after signature verification.\n *\n * Dodo's core, Next.js, and Better Auth packages expose equivalent webhook\n * envelopes but can carry incompatible nested SDK types. Keep the envelope\n * SDK-derived and treat only the resource payload as untrusted input; Bursar's\n * mapper validates every field it consumes.\n */\nexport type DodoWebhookPayload = Partial<\n Omit<DodoSdkWebhookPayload, \"data\" | \"timestamp\" | \"type\">\n> & {\n data: unknown;\n timestamp: string | Date;\n type: string;\n};\n\nexport interface DodoClient {\n webhooks: {\n unwrap(\n body: string,\n options: { headers: Record<string, string>; key?: string },\n ): DodoWebhookPayload;\n };\n checkoutSessions: {\n create(\n body: Parameters<DodoPayments[\"checkoutSessions\"][\"create\"]>[0],\n options?: DodoMutationRequestOptions,\n ): Promise<DodoCheckoutSession>;\n preview(\n body: Parameters<DodoPayments[\"checkoutSessions\"][\"preview\"]>[0],\n ): Promise<DodoCheckoutPreview>;\n retrieve(\n sessionId: Parameters<DodoPayments[\"checkoutSessions\"][\"retrieve\"]>[0],\n ): Promise<DodoCheckoutSessionStatus>;\n };\n customers: {\n create(\n body: Parameters<DodoPayments[\"customers\"][\"create\"]>[0],\n options?: DodoMutationRequestOptions,\n ): Promise<DodoCustomer>;\n customerPortal: {\n create(\n customerId: Parameters<DodoPayments[\"customers\"][\"customerPortal\"][\"create\"]>[0],\n body: Parameters<DodoPayments[\"customers\"][\"customerPortal\"][\"create\"]>[1],\n ): Promise<DodoCustomerPortalSession>;\n };\n retrievePaymentMethods(\n customerId: Parameters<DodoPayments[\"customers\"][\"retrievePaymentMethods\"]>[0],\n ): Promise<DodoPaymentMethods>;\n };\n payments: {\n retrieve(paymentId: Parameters<DodoPayments[\"payments\"][\"retrieve\"]>[0]): Promise<DodoPayment>;\n };\n subscriptions: {\n cancelChangePlan(\n subscriptionId: Parameters<DodoPayments[\"subscriptions\"][\"cancelChangePlan\"]>[0],\n options?: DodoMutationRequestOptions,\n ): Promise<unknown>;\n changePlan(\n subscriptionId: Parameters<DodoPayments[\"subscriptions\"][\"changePlan\"]>[0],\n body: Parameters<DodoPayments[\"subscriptions\"][\"changePlan\"]>[1],\n options?: DodoMutationRequestOptions,\n ): Promise<unknown>;\n previewChangePlan(\n subscriptionId: Parameters<DodoPayments[\"subscriptions\"][\"previewChangePlan\"]>[0],\n body: Parameters<DodoPayments[\"subscriptions\"][\"previewChangePlan\"]>[1],\n ): Promise<DodoPlanChangePreview>;\n update(\n subscriptionId: Parameters<DodoPayments[\"subscriptions\"][\"update\"]>[0],\n body: Parameters<DodoPayments[\"subscriptions\"][\"update\"]>[1],\n options?: DodoMutationRequestOptions,\n ): Promise<unknown>;\n updatePaymentMethod(\n subscriptionId: Parameters<DodoPayments[\"subscriptions\"][\"updatePaymentMethod\"]>[0],\n body: Parameters<DodoPayments[\"subscriptions\"][\"updatePaymentMethod\"]>[1],\n ): Promise<DodoPaymentMethodUpdate>;\n };\n}\n"]}
@@ -4,5 +4,5 @@ import { type ProviderLogger } from "../types.js";
4
4
  /** Dodo sometimes sends dates in JS toString() format (e.g. "Sat Jul 18 2026 05:15:24 GMT+0000..."). Normalize to ISO 8601. */
5
5
  export declare function normalizeDate(raw: unknown): string | null;
6
6
  export declare function dodoBillingEventId(payload: DodoWebhookPayload): string;
7
- export declare function handleDodoBillingEvent(payload: DodoWebhookPayload, userId: string | null, metadata: Record<string, string>, sink: BillingEventSink, logger?: ProviderLogger | null): Promise<void>;
7
+ export declare function handleDodoBillingEvent(payload: DodoWebhookPayload, accountId: string | null, metadata: Record<string, string>, sink: BillingEventSink, logger?: ProviderLogger | null): Promise<void>;
8
8
  //# sourceMappingURL=event-mapper.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"event-mapper.d.ts","sourceRoot":"","sources":["../../../src/providers/dodo/event-mapper.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAMxD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,KAAK,cAAc,EAA2B,MAAM,aAAa,CAAC;AA6D3E,+HAA+H;AAC/H,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAWzD;AAgBD,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,kBAAkB,GAAG,MAAM,CAgBtE;AAyGD,wBAAsB,sBAAsB,CAC1C,OAAO,EAAE,kBAAkB,EAC3B,MAAM,EAAE,MAAM,GAAG,IAAI,EACrB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAChC,IAAI,EAAE,gBAAgB,EACtB,MAAM,CAAC,EAAE,cAAc,GAAG,IAAI,GAC7B,OAAO,CAAC,IAAI,CAAC,CAgRf"}
1
+ {"version":3,"file":"event-mapper.d.ts","sourceRoot":"","sources":["../../../src/providers/dodo/event-mapper.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAMxD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,KAAK,cAAc,EAA2B,MAAM,aAAa,CAAC;AA8D3E,+HAA+H;AAC/H,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAWzD;AAgBD,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,kBAAkB,GAAG,MAAM,CAgBtE;AAyGD,wBAAsB,sBAAsB,CAC1C,OAAO,EAAE,kBAAkB,EAC3B,SAAS,EAAE,MAAM,GAAG,IAAI,EACxB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAChC,IAAI,EAAE,gBAAgB,EACtB,MAAM,CAAC,EAAE,cAAc,GAAG,IAAI,GAC7B,OAAO,CAAC,IAAI,CAAC,CAwRf"}
@@ -14,6 +14,7 @@ const DODO_SUBSCRIPTION_STATUS = {
14
14
  pending: "incomplete",
15
15
  trialing: "trialing",
16
16
  active: "active",
17
+ paused: "paused",
17
18
  on_hold: "past_due",
18
19
  cancelled: "canceled",
19
20
  failed: "past_due",
@@ -169,7 +170,7 @@ function subscriptionStatus(value, logger) {
169
170
  logger.warn("Unsupported Dodo subscription status", { status: raw });
170
171
  return status ?? null;
171
172
  }
172
- export async function handleDodoBillingEvent(payload, userId, metadata, sink, logger) {
173
+ export async function handleDodoBillingEvent(payload, accountId, metadata, sink, logger) {
173
174
  const log = normalizeProviderLogger(logger);
174
175
  const data = objectValue(payload.data);
175
176
  if (!data)
@@ -181,24 +182,20 @@ export async function handleDodoBillingEvent(payload, userId, metadata, sink, lo
181
182
  provider: "dodo",
182
183
  eventId: dodoBillingEventId(payload),
183
184
  occurredAt: requireDate(payload.timestamp, "Dodo webhook timestamp"),
184
- ...(userId ? { userId } : {}),
185
+ ...(accountId ? { accountId } : {}),
185
186
  ...(customerInfo.providerCustomerId ? { customer: customerInfo } : {}),
186
187
  ...(Object.keys(metadata).length ? { metadata } : {}),
187
188
  };
188
189
  }
189
190
  switch (type) {
190
191
  case "subscription.active": {
191
- if (!userId) {
192
- log.error("Dodo subscription event: no userId", { event: type });
193
- return;
194
- }
195
192
  const subId = subscriptionId(data);
196
193
  const refs = subscriptionRefs(data, metadata);
197
194
  log.debug("Dodo subscription.active mapped", {
198
195
  subscriptionId: subId,
199
196
  productId: productId(data),
200
197
  planSlug: metadata.plan_slug,
201
- hasUserId: Boolean(userId),
198
+ hasAccountId: Boolean(accountId),
202
199
  refs,
203
200
  });
204
201
  await callBillingEventSink(sink, {
@@ -217,10 +214,6 @@ export async function handleDodoBillingEvent(payload, userId, metadata, sink, lo
217
214
  return;
218
215
  }
219
216
  case "subscription.renewed": {
220
- if (!userId) {
221
- log.error("Dodo subscription event: no userId", { event: type });
222
- return;
223
- }
224
217
  const subId = subscriptionId(data);
225
218
  await callBillingEventSink(sink, {
226
219
  ...baseEvent(),
@@ -291,6 +284,20 @@ export async function handleDodoBillingEvent(payload, userId, metadata, sink, lo
291
284
  });
292
285
  return;
293
286
  }
287
+ case "subscription.paused": {
288
+ const subId = subscriptionId(data);
289
+ await callBillingEventSink(sink, {
290
+ ...baseEvent(),
291
+ eventType: "subscription.paused",
292
+ subscription: {
293
+ providerSubscriptionId: subId,
294
+ status: "paused",
295
+ ...subscriptionFields(data, metadata),
296
+ refs: subscriptionRefs(data, metadata),
297
+ },
298
+ });
299
+ return;
300
+ }
294
301
  case "subscription.updated": {
295
302
  const subId = subscriptionId(data);
296
303
  const periodEnd = optionalDate(data.next_billing_date, "Dodo subscription.next_billing_date");
@@ -337,7 +344,7 @@ export async function handleDodoBillingEvent(payload, userId, metadata, sink, lo
337
344
  await callBillingEventSink(sink, {
338
345
  ...baseEvent(),
339
346
  eventType: "payment.succeeded",
340
- ...(userId ? { userId } : {}),
347
+ ...(accountId ? { accountId } : {}),
341
348
  ...(subscriptionId
342
349
  ? {
343
350
  subscription: {
@@ -354,14 +361,15 @@ export async function handleDodoBillingEvent(payload, userId, metadata, sink, lo
354
361
  });
355
362
  return;
356
363
  }
357
- case "payment.failed": {
364
+ case "payment.failed":
365
+ case "payment.cancelled": {
358
366
  const subId = optionalProviderString(data.subscription_id, "Dodo payment.subscription_id");
359
367
  const paymentId = requireProviderString(data.payment_id, "Dodo payment.payment_id");
360
368
  const providerProductId = productId(data);
361
369
  await callBillingEventSink(sink, {
362
370
  ...baseEvent(),
363
371
  eventType: "payment.failed",
364
- ...(userId ? { userId } : {}),
372
+ ...(accountId ? { accountId } : {}),
365
373
  subscription: subId ? { providerSubscriptionId: subId } : undefined,
366
374
  payment: {
367
375
  providerPaymentId: paymentId,
@@ -369,7 +377,7 @@ export async function handleDodoBillingEvent(payload, userId, metadata, sink, lo
369
377
  taxMinor: requireMinorUnits(data.tax ?? 0, "Dodo payment.tax"),
370
378
  currency: requireCurrency(data.currency, "Dodo payment.currency"),
371
379
  purpose: subId ? "subscription" : "credit_topup",
372
- status: "failed",
380
+ status: type === "payment.cancelled" ? "canceled" : "failed",
373
381
  refs: providerProductId ? { productId: providerProductId } : undefined,
374
382
  },
375
383
  });