@zonastery/bursar 1.0.1 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (366) hide show
  1. package/README.md +86 -3
  2. package/dist/billing/auto-recharge-port.d.ts +3 -3
  3. package/dist/billing/auto-recharge-port.d.ts.map +1 -1
  4. package/dist/billing/auto-recharge-port.js.map +1 -1
  5. package/dist/billing/auto-recharge-service.d.ts +5 -4
  6. package/dist/billing/auto-recharge-service.d.ts.map +1 -1
  7. package/dist/billing/auto-recharge-service.js +64 -34
  8. package/dist/billing/auto-recharge-service.js.map +1 -1
  9. package/dist/billing/billing-service.d.ts +5 -5
  10. package/dist/billing/billing-service.d.ts.map +1 -1
  11. package/dist/billing/billing-service.js +2 -2
  12. package/dist/billing/billing-service.js.map +1 -1
  13. package/dist/billing/billing-store.d.ts +8 -7
  14. package/dist/billing/billing-store.d.ts.map +1 -1
  15. package/dist/billing/billing-store.js.map +1 -1
  16. package/dist/billing/contracts.d.ts +31 -31
  17. package/dist/billing/contracts.d.ts.map +1 -1
  18. package/dist/billing/contracts.js.map +1 -1
  19. package/dist/billing/event-handlers.d.ts.map +1 -1
  20. package/dist/billing/event-handlers.js +31 -9
  21. package/dist/billing/event-handlers.js.map +1 -1
  22. package/dist/billing/event-processor.d.ts.map +1 -1
  23. package/dist/billing/event-processor.js +2 -1
  24. package/dist/billing/event-processor.js.map +1 -1
  25. package/dist/billing/financial-event-handlers.d.ts.map +1 -1
  26. package/dist/billing/financial-event-handlers.js +69 -72
  27. package/dist/billing/financial-event-handlers.js.map +1 -1
  28. package/dist/billing/index.d.ts +1 -1
  29. package/dist/billing/index.d.ts.map +1 -1
  30. package/dist/billing/index.js.map +1 -1
  31. package/dist/billing/management.d.ts +5 -5
  32. package/dist/billing/management.d.ts.map +1 -1
  33. package/dist/billing/management.js +2 -2
  34. package/dist/billing/management.js.map +1 -1
  35. package/dist/billing/postgres/repositories/auto-recharge.d.ts +3 -3
  36. package/dist/billing/postgres/repositories/auto-recharge.d.ts.map +1 -1
  37. package/dist/billing/postgres/repositories/auto-recharge.js +202 -59
  38. package/dist/billing/postgres/repositories/auto-recharge.js.map +1 -1
  39. package/dist/billing/postgres/repositories/customer.d.ts.map +1 -1
  40. package/dist/billing/postgres/repositories/customer.js +19 -11
  41. package/dist/billing/postgres/repositories/customer.js.map +1 -1
  42. package/dist/billing/postgres/repositories/dispute.d.ts.map +1 -1
  43. package/dist/billing/postgres/repositories/dispute.js +3 -1
  44. package/dist/billing/postgres/repositories/dispute.js.map +1 -1
  45. package/dist/billing/postgres/repositories/event.d.ts +12 -5
  46. package/dist/billing/postgres/repositories/event.d.ts.map +1 -1
  47. package/dist/billing/postgres/repositories/event.js +18 -15
  48. package/dist/billing/postgres/repositories/event.js.map +1 -1
  49. package/dist/billing/postgres/repositories/invoice.d.ts +3 -3
  50. package/dist/billing/postgres/repositories/invoice.d.ts.map +1 -1
  51. package/dist/billing/postgres/repositories/invoice.js +53 -11
  52. package/dist/billing/postgres/repositories/invoice.js.map +1 -1
  53. package/dist/billing/postgres/repositories/offer.d.ts +20 -17
  54. package/dist/billing/postgres/repositories/offer.d.ts.map +1 -1
  55. package/dist/billing/postgres/repositories/offer.js +123 -57
  56. package/dist/billing/postgres/repositories/offer.js.map +1 -1
  57. package/dist/billing/postgres/repositories/payment.d.ts +23 -20
  58. package/dist/billing/postgres/repositories/payment.d.ts.map +1 -1
  59. package/dist/billing/postgres/repositories/payment.js +43 -37
  60. package/dist/billing/postgres/repositories/payment.js.map +1 -1
  61. package/dist/billing/postgres/repositories/preferences.d.ts +3 -9
  62. package/dist/billing/postgres/repositories/preferences.d.ts.map +1 -1
  63. package/dist/billing/postgres/repositories/preferences.js +45 -7
  64. package/dist/billing/postgres/repositories/preferences.js.map +1 -1
  65. package/dist/billing/postgres/repositories/refund.d.ts +1 -1
  66. package/dist/billing/postgres/repositories/refund.d.ts.map +1 -1
  67. package/dist/billing/postgres/repositories/refund.js +13 -9
  68. package/dist/billing/postgres/repositories/refund.js.map +1 -1
  69. package/dist/billing/postgres/repositories/subscription-change.d.ts +15 -0
  70. package/dist/billing/postgres/repositories/subscription-change.d.ts.map +1 -0
  71. package/dist/billing/postgres/repositories/subscription-change.js +234 -0
  72. package/dist/billing/postgres/repositories/subscription-change.js.map +1 -0
  73. package/dist/billing/postgres/repositories/subscription.d.ts +38 -17
  74. package/dist/billing/postgres/repositories/subscription.d.ts.map +1 -1
  75. package/dist/billing/postgres/repositories/subscription.js +199 -91
  76. package/dist/billing/postgres/repositories/subscription.js.map +1 -1
  77. package/dist/billing/postgres/repositories/topup.d.ts +13 -15
  78. package/dist/billing/postgres/repositories/topup.d.ts.map +1 -1
  79. package/dist/billing/postgres/repositories/topup.js +65 -34
  80. package/dist/billing/postgres/repositories/topup.js.map +1 -1
  81. package/dist/billing/postgres/store.d.ts +18 -11
  82. package/dist/billing/postgres/store.d.ts.map +1 -1
  83. package/dist/billing/postgres/store.js +260 -238
  84. package/dist/billing/postgres/store.js.map +1 -1
  85. package/dist/billing/service-types.d.ts +6 -5
  86. package/dist/billing/service-types.d.ts.map +1 -1
  87. package/dist/billing/service-types.js.map +1 -1
  88. package/dist/billing/types/auto-recharge.d.ts +6 -4
  89. package/dist/billing/types/auto-recharge.d.ts.map +1 -1
  90. package/dist/billing/types/auto-recharge.js.map +1 -1
  91. package/dist/billing/types/catalog.d.ts +18 -35
  92. package/dist/billing/types/catalog.d.ts.map +1 -1
  93. package/dist/billing/types/catalog.js.map +1 -1
  94. package/dist/billing/types/common.d.ts +0 -1
  95. package/dist/billing/types/common.d.ts.map +1 -1
  96. package/dist/billing/types/common.js.map +1 -1
  97. package/dist/billing/types/documents.d.ts +38 -12
  98. package/dist/billing/types/documents.d.ts.map +1 -1
  99. package/dist/billing/types/documents.js.map +1 -1
  100. package/dist/billing/types/events.d.ts +2 -0
  101. package/dist/billing/types/events.d.ts.map +1 -1
  102. package/dist/billing/types/events.js +238 -0
  103. package/dist/billing/types/events.js.map +1 -1
  104. package/dist/billing/types/subscriptions.d.ts +8 -8
  105. package/dist/billing/types/subscriptions.d.ts.map +1 -1
  106. package/dist/billing/types/subscriptions.js.map +1 -1
  107. package/dist/bursar.d.ts +27 -9
  108. package/dist/bursar.d.ts.map +1 -1
  109. package/dist/bursar.js +48 -20
  110. package/dist/bursar.js.map +1 -1
  111. package/dist/catalog.d.ts +1 -1
  112. package/dist/catalog.d.ts.map +1 -1
  113. package/dist/catalog.js +1 -1
  114. package/dist/catalog.js.map +1 -1
  115. package/dist/commerce/errors.d.ts +1 -10
  116. package/dist/commerce/errors.d.ts.map +1 -1
  117. package/dist/commerce/errors.js +1 -16
  118. package/dist/commerce/errors.js.map +1 -1
  119. package/dist/commerce/index.d.ts +1 -0
  120. package/dist/commerce/index.d.ts.map +1 -1
  121. package/dist/commerce/index.js.map +1 -1
  122. package/dist/commerce/provider-registry.d.ts.map +1 -1
  123. package/dist/commerce/provider-registry.js +27 -2
  124. package/dist/commerce/provider-registry.js.map +1 -1
  125. package/dist/commerce/service.d.ts +15 -7
  126. package/dist/commerce/service.d.ts.map +1 -1
  127. package/dist/commerce/service.js +85 -67
  128. package/dist/commerce/service.js.map +1 -1
  129. package/dist/commerce/types.d.ts +27 -15
  130. package/dist/commerce/types.d.ts.map +1 -1
  131. package/dist/commerce/types.js.map +1 -1
  132. package/dist/config/parse-plans.d.ts.map +1 -1
  133. package/dist/config/parse-plans.js +16 -15
  134. package/dist/config/parse-plans.js.map +1 -1
  135. package/dist/config/parse-pricing.d.ts.map +1 -1
  136. package/dist/config/parse-pricing.js +16 -5
  137. package/dist/config/parse-pricing.js.map +1 -1
  138. package/dist/config/types.d.ts +2 -2
  139. package/dist/config/types.d.ts.map +1 -1
  140. package/dist/config/types.js.map +1 -1
  141. package/dist/credits/{pricing-runtime.d.ts → catalog-runtime.d.ts} +8 -8
  142. package/dist/credits/catalog-runtime.d.ts.map +1 -0
  143. package/dist/credits/{pricing-runtime.js → catalog-runtime.js} +58 -38
  144. package/dist/credits/catalog-runtime.js.map +1 -0
  145. package/dist/credits/events.d.ts +4 -4
  146. package/dist/credits/events.d.ts.map +1 -1
  147. package/dist/credits/events.js +1 -1
  148. package/dist/credits/events.js.map +1 -1
  149. package/dist/credits/lease-workflow.d.ts +14 -14
  150. package/dist/credits/lease-workflow.d.ts.map +1 -1
  151. package/dist/credits/lease-workflow.js +18 -17
  152. package/dist/credits/lease-workflow.js.map +1 -1
  153. package/dist/credits/low-balance-monitor.d.ts +2 -2
  154. package/dist/credits/low-balance-monitor.d.ts.map +1 -1
  155. package/dist/credits/low-balance-monitor.js.map +1 -1
  156. package/dist/credits/postgres/repositories/analytics.d.ts +34 -34
  157. package/dist/credits/postgres/repositories/analytics.d.ts.map +1 -1
  158. package/dist/credits/postgres/repositories/analytics.js +52 -52
  159. package/dist/credits/postgres/repositories/analytics.js.map +1 -1
  160. package/dist/credits/postgres/repositories/balance.d.ts +28 -30
  161. package/dist/credits/postgres/repositories/balance.d.ts.map +1 -1
  162. package/dist/credits/postgres/repositories/balance.js +100 -59
  163. package/dist/credits/postgres/repositories/balance.js.map +1 -1
  164. package/dist/credits/postgres/repositories/bucket.d.ts +14 -8
  165. package/dist/credits/postgres/repositories/bucket.d.ts.map +1 -1
  166. package/dist/credits/postgres/repositories/bucket.js +22 -21
  167. package/dist/credits/postgres/repositories/bucket.js.map +1 -1
  168. package/dist/credits/postgres/repositories/catalog.d.ts +31 -0
  169. package/dist/credits/postgres/repositories/catalog.d.ts.map +1 -0
  170. package/dist/credits/postgres/repositories/catalog.js +90 -0
  171. package/dist/credits/postgres/repositories/catalog.js.map +1 -0
  172. package/dist/credits/postgres/repositories/deduction.d.ts +28 -26
  173. package/dist/credits/postgres/repositories/deduction.d.ts.map +1 -1
  174. package/dist/credits/postgres/repositories/deduction.js +153 -68
  175. package/dist/credits/postgres/repositories/deduction.js.map +1 -1
  176. package/dist/credits/postgres/repositories/lease.d.ts +21 -18
  177. package/dist/credits/postgres/repositories/lease.d.ts.map +1 -1
  178. package/dist/credits/postgres/repositories/lease.js +157 -65
  179. package/dist/credits/postgres/repositories/lease.js.map +1 -1
  180. package/dist/credits/postgres/repositories/plan.d.ts +90 -43
  181. package/dist/credits/postgres/repositories/plan.d.ts.map +1 -1
  182. package/dist/credits/postgres/repositories/plan.js +126 -108
  183. package/dist/credits/postgres/repositories/plan.js.map +1 -1
  184. package/dist/credits/postgres/repositories/team.d.ts +36 -27
  185. package/dist/credits/postgres/repositories/team.d.ts.map +1 -1
  186. package/dist/credits/postgres/repositories/team.js +96 -52
  187. package/dist/credits/postgres/repositories/team.js.map +1 -1
  188. package/dist/credits/postgres/store.d.ts +23 -18
  189. package/dist/credits/postgres/store.d.ts.map +1 -1
  190. package/dist/credits/postgres/store.js +282 -265
  191. package/dist/credits/postgres/store.js.map +1 -1
  192. package/dist/credits/postgres/value-mappers.d.ts +7 -9
  193. package/dist/credits/postgres/value-mappers.d.ts.map +1 -1
  194. package/dist/credits/postgres/value-mappers.js +36 -61
  195. package/dist/credits/postgres/value-mappers.js.map +1 -1
  196. package/dist/credits/queries.d.ts +5 -5
  197. package/dist/credits/queries.d.ts.map +1 -1
  198. package/dist/credits/queries.js +4 -4
  199. package/dist/credits/queries.js.map +1 -1
  200. package/dist/credits/service-types.d.ts +42 -7
  201. package/dist/credits/service-types.d.ts.map +1 -1
  202. package/dist/credits/service-types.js.map +1 -1
  203. package/dist/credits/service.d.ts +42 -62
  204. package/dist/credits/service.d.ts.map +1 -1
  205. package/dist/credits/service.js +140 -121
  206. package/dist/credits/service.js.map +1 -1
  207. package/dist/credits/store.d.ts +20 -22
  208. package/dist/credits/store.d.ts.map +1 -1
  209. package/dist/credits/store.js +5 -5
  210. package/dist/credits/store.js.map +1 -1
  211. package/dist/credits/types/account.d.ts +49 -11
  212. package/dist/credits/types/account.d.ts.map +1 -1
  213. package/dist/credits/types/account.js.map +1 -1
  214. package/dist/credits/types/admission.d.ts +17 -6
  215. package/dist/credits/types/admission.d.ts.map +1 -1
  216. package/dist/credits/types/admission.js.map +1 -1
  217. package/dist/credits/types/analytics.d.ts +2 -2
  218. package/dist/credits/types/analytics.d.ts.map +1 -1
  219. package/dist/credits/types/analytics.js.map +1 -1
  220. package/dist/credits/types/catalog.d.ts +20 -15
  221. package/dist/credits/types/catalog.d.ts.map +1 -1
  222. package/dist/credits/types/catalog.js.map +1 -1
  223. package/dist/credits/types/grants.d.ts +22 -8
  224. package/dist/credits/types/grants.d.ts.map +1 -1
  225. package/dist/credits/types/grants.js.map +1 -1
  226. package/dist/credits/types/ledger.d.ts +12 -3
  227. package/dist/credits/types/ledger.d.ts.map +1 -1
  228. package/dist/credits/types/ledger.js.map +1 -1
  229. package/dist/credits/types/teams.d.ts +18 -6
  230. package/dist/credits/types/teams.d.ts.map +1 -1
  231. package/dist/credits/types/teams.js.map +1 -1
  232. package/dist/engine.d.ts.map +1 -1
  233. package/dist/engine.js +24 -10
  234. package/dist/engine.js.map +1 -1
  235. package/dist/errors.d.ts +52 -4
  236. package/dist/errors.d.ts.map +1 -1
  237. package/dist/errors.js +76 -4
  238. package/dist/errors.js.map +1 -1
  239. package/dist/expr/ast.d.ts.map +1 -1
  240. package/dist/expr/ast.js.map +1 -1
  241. package/dist/expr/evaluator.d.ts.map +1 -1
  242. package/dist/expr/evaluator.js +29 -17
  243. package/dist/expr/evaluator.js.map +1 -1
  244. package/dist/expr/parser.d.ts.map +1 -1
  245. package/dist/expr/parser.js +11 -4
  246. package/dist/expr/parser.js.map +1 -1
  247. package/dist/expr/tokenizer.d.ts.map +1 -1
  248. package/dist/expr/tokenizer.js +17 -13
  249. package/dist/expr/tokenizer.js.map +1 -1
  250. package/dist/expr.d.ts +2 -2
  251. package/dist/expr.d.ts.map +1 -1
  252. package/dist/expr.js +5 -7
  253. package/dist/expr.js.map +1 -1
  254. package/dist/generated/pricing-config.schema.json +5 -12
  255. package/dist/generated/pricing-config.types.d.ts +3 -3
  256. package/dist/generated/pricing-config.types.d.ts.map +1 -1
  257. package/dist/generated/pricing-config.types.js.map +1 -1
  258. package/dist/index.d.ts +6 -4
  259. package/dist/index.d.ts.map +1 -1
  260. package/dist/index.js +1 -1
  261. package/dist/index.js.map +1 -1
  262. package/dist/integrations/better-auth.d.ts +23 -0
  263. package/dist/integrations/better-auth.d.ts.map +1 -0
  264. package/dist/integrations/better-auth.js +54 -0
  265. package/dist/integrations/better-auth.js.map +1 -0
  266. package/dist/{load-pricing-file.d.ts → load-config-file.d.ts} +4 -4
  267. package/dist/load-config-file.d.ts.map +1 -0
  268. package/dist/{load-pricing-file.js → load-config-file.js} +15 -10
  269. package/dist/load-config-file.js.map +1 -0
  270. package/dist/node.d.ts +3 -3
  271. package/dist/node.d.ts.map +1 -1
  272. package/dist/node.js +2 -2
  273. package/dist/node.js.map +1 -1
  274. package/dist/providers/_shared.d.ts +5 -0
  275. package/dist/providers/_shared.d.ts.map +1 -1
  276. package/dist/providers/_shared.js +36 -0
  277. package/dist/providers/_shared.js.map +1 -1
  278. package/dist/providers/dodo/better-auth.d.ts +29 -0
  279. package/dist/providers/dodo/better-auth.d.ts.map +1 -0
  280. package/dist/providers/dodo/better-auth.js +23 -0
  281. package/dist/providers/dodo/better-auth.js.map +1 -0
  282. package/dist/providers/dodo/client-contract.d.ts +32 -70
  283. package/dist/providers/dodo/client-contract.d.ts.map +1 -1
  284. package/dist/providers/dodo/client-contract.js.map +1 -1
  285. package/dist/providers/dodo/event-mapper.d.ts +3 -1
  286. package/dist/providers/dodo/event-mapper.d.ts.map +1 -1
  287. package/dist/providers/dodo/event-mapper.js +219 -148
  288. package/dist/providers/dodo/event-mapper.js.map +1 -1
  289. package/dist/providers/dodo/index.d.ts +5 -2
  290. package/dist/providers/dodo/index.d.ts.map +1 -1
  291. package/dist/providers/dodo/index.js +2 -1
  292. package/dist/providers/dodo/index.js.map +1 -1
  293. package/dist/providers/dodo/nextjs.d.ts +16 -0
  294. package/dist/providers/dodo/nextjs.d.ts.map +1 -0
  295. package/dist/providers/dodo/nextjs.js +16 -0
  296. package/dist/providers/dodo/nextjs.js.map +1 -0
  297. package/dist/providers/dodo/provider.d.ts +30 -11
  298. package/dist/providers/dodo/provider.d.ts.map +1 -1
  299. package/dist/providers/dodo/provider.js +192 -122
  300. package/dist/providers/dodo/provider.js.map +1 -1
  301. package/dist/providers/dodo/react-native.d.ts +56 -0
  302. package/dist/providers/dodo/react-native.d.ts.map +1 -0
  303. package/dist/providers/dodo/react-native.js +57 -0
  304. package/dist/providers/dodo/react-native.js.map +1 -0
  305. package/dist/providers/dodo/webhook-bridge.d.ts +17 -0
  306. package/dist/providers/dodo/webhook-bridge.d.ts.map +1 -0
  307. package/dist/providers/dodo/webhook-bridge.js +21 -0
  308. package/dist/providers/dodo/webhook-bridge.js.map +1 -0
  309. package/dist/providers/index.d.ts +1 -1
  310. package/dist/providers/index.d.ts.map +1 -1
  311. package/dist/providers/index.js.map +1 -1
  312. package/dist/providers/mock/index.d.ts +1 -0
  313. package/dist/providers/mock/index.d.ts.map +1 -1
  314. package/dist/providers/mock/index.js.map +1 -1
  315. package/dist/providers/mock/provider.d.ts +8 -8
  316. package/dist/providers/mock/provider.d.ts.map +1 -1
  317. package/dist/providers/mock/provider.js +26 -19
  318. package/dist/providers/mock/provider.js.map +1 -1
  319. package/dist/providers/stripe/event-mapper.d.ts.map +1 -1
  320. package/dist/providers/stripe/event-mapper.js +214 -173
  321. package/dist/providers/stripe/event-mapper.js.map +1 -1
  322. package/dist/providers/stripe/index.d.ts +1 -0
  323. package/dist/providers/stripe/index.d.ts.map +1 -1
  324. package/dist/providers/stripe/index.js.map +1 -1
  325. package/dist/providers/stripe/provider.d.ts +13 -11
  326. package/dist/providers/stripe/provider.d.ts.map +1 -1
  327. package/dist/providers/stripe/provider.js +287 -107
  328. package/dist/providers/stripe/provider.js.map +1 -1
  329. package/dist/providers/types.d.ts +1 -2
  330. package/dist/providers/types.d.ts.map +1 -1
  331. package/dist/providers/types.js.map +1 -1
  332. package/dist/shared/postgres-client.d.ts +5 -0
  333. package/dist/shared/postgres-client.d.ts.map +1 -1
  334. package/dist/shared/postgres-client.js +23 -7
  335. package/dist/shared/postgres-client.js.map +1 -1
  336. package/dist/shared/postgres-validation.d.ts +15 -3
  337. package/dist/shared/postgres-validation.d.ts.map +1 -1
  338. package/dist/shared/postgres-validation.js +58 -14
  339. package/dist/shared/postgres-validation.js.map +1 -1
  340. package/dist/storage/adapters/clickhouse.d.ts.map +1 -1
  341. package/dist/storage/adapters/clickhouse.js +2 -5
  342. package/dist/storage/adapters/clickhouse.js.map +1 -1
  343. package/dist/storage/adapters/s3.d.ts +0 -6
  344. package/dist/storage/adapters/s3.d.ts.map +1 -1
  345. package/dist/storage/adapters/s3.js +0 -2
  346. package/dist/storage/adapters/s3.js.map +1 -1
  347. package/dist/storage/ports.d.ts +0 -1
  348. package/dist/storage/ports.d.ts.map +1 -1
  349. package/dist/storage/ports.js.map +1 -1
  350. package/dist/storage/postgres-repository.d.ts +1 -1
  351. package/dist/storage/postgres-repository.d.ts.map +1 -1
  352. package/dist/storage/postgres-repository.js +2 -2
  353. package/dist/storage/postgres-repository.js.map +1 -1
  354. package/dist/storage/runtime.d.ts +24 -6
  355. package/dist/storage/runtime.d.ts.map +1 -1
  356. package/dist/storage/runtime.js +87 -30
  357. package/dist/storage/runtime.js.map +1 -1
  358. package/package.json +56 -7
  359. package/dist/credits/postgres/repositories/pricing.d.ts +0 -28
  360. package/dist/credits/postgres/repositories/pricing.d.ts.map +0 -1
  361. package/dist/credits/postgres/repositories/pricing.js +0 -76
  362. package/dist/credits/postgres/repositories/pricing.js.map +0 -1
  363. package/dist/credits/pricing-runtime.d.ts.map +0 -1
  364. package/dist/credits/pricing-runtime.js.map +0 -1
  365. package/dist/load-pricing-file.d.ts.map +0 -1
  366. package/dist/load-pricing-file.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"pricing.js","sourceRoot":"","sources":["../../../../src/credits/postgres/repositories/pricing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC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"zod\";\nimport type { CallProc } from \"../../../shared/postgres-types.js\";\nimport { pgBoolean, safeParse } from \"../../../shared/postgres-validation.js\";\n\nconst ActivePricingRowSchema = z\n .object({\n id: z.string().optional(),\n config: z.record(z.string(), z.unknown()).optional(),\n source_document: z.record(z.string(), z.unknown()).optional(),\n version: z.coerce.number().optional(),\n revision_no: z.coerce.number().optional(),\n label: z.string().nullable().optional(),\n active: pgBoolean.nullable().optional(),\n status: z.string().nullable().optional(),\n created_at: z.union([z.string(), z.date().transform((v) => v.toISOString())]).optional(),\n })\n .passthrough();\nexport type ActivePricingRow = z.infer<typeof ActivePricingRowSchema>;\nexport type PricingHistoryRow = ActivePricingRow;\n\nexport class PricingRepository {\n constructor(private readonly callproc: CallProc) {}\n\n private parseRevision(row: Record<string, unknown>, context: string): ActivePricingRow {\n return safeParse(\n ActivePricingRowSchema,\n {\n ...row,\n config: row.source_document,\n version: row.revision_no,\n active: row.status === \"active\",\n },\n context,\n );\n }\n\n async getActivePricing(): Promise<ActivePricingRow | null> {\n const rows = await this.callproc(\"active_catalog_revision\", []);\n if (!rows?.length) return null;\n const row = rows[0] as Record<string, unknown>;\n return this.parseRevision(row, \"PricingRepository.getActivePricing\");\n }\n\n async setActivePricing(\n config: string,\n label: string | null,\n rollout: Record<string, unknown>,\n ): Promise<ActivePricingRow> {\n return this.publishPricing(config, label, true, rollout);\n }\n\n async publishPricing(\n config: string,\n label: string | null,\n activate = false,\n rollout: Record<string, unknown> = { plans: {} },\n ): Promise<ActivePricingRow> {\n const published = (\n await this.callproc(\"publish_and_activate_catalog\", [\n 1,\n JSON.parse(config),\n label,\n activate,\n rollout,\n ])\n )[0] as Record<string, unknown> | undefined;\n if (published?.revision_no == null) {\n return safeParse(ActivePricingRowSchema, {}, \"PricingRepository.publishPricing\");\n }\n const revision = await this.getBursarConfig(Number(published.revision_no));\n return (\n revision ??\n safeParse(\n ActivePricingRowSchema,\n {\n id: published.revision_id,\n version: published.revision_no,\n status: published.status,\n active: published.status === \"active\",\n },\n \"PricingRepository.publishPricing\",\n )\n );\n }\n\n async getPricingHistory(): Promise<PricingHistoryRow[]> {\n const rows = await this.callproc(\"list_catalog_revisions\", [500]);\n return (rows ?? []).map((row) =>\n this.parseRevision(row as Record<string, unknown>, \"PricingRepository.getPricingHistory\"),\n );\n }\n\n async getBursarConfig(version: number): Promise<ActivePricingRow | null> {\n const rows = await this.callproc(\"catalog_revision_by_number\", [version]);\n if (!rows?.length) return null;\n return this.parseRevision(\n rows[0] as Record<string, unknown>,\n \"PricingRepository.getBursarConfig\",\n );\n }\n\n async activatePricing(\n version: number,\n rollout: Record<string, unknown>,\n ): Promise<ActivePricingRow> {\n const rows = await this.callproc(\"activate_catalog_revision\", [version, rollout]);\n if (!rows?.length) throw new Error(`Catalog revision ${version} was not found`);\n return this.parseRevision(\n rows[0] as Record<string, unknown>,\n \"PricingRepository.activatePricing\",\n );\n }\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"pricing-runtime.d.ts","sourceRoot":"","sources":["../../src/credits/pricing-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,YAAY,CAAC;AAEjC,OAAO,EAA6B,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAGlD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE1D,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,OAAO,CAE1D;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,eAAe,GAAG,KAAK,IAAI,OAAO,GAAG,MAAM,CAE1E;AAED,4EAA4E;AAC5E,qBAAa,cAAc;IAMvB,OAAO,CAAC,QAAQ,CAAC,KAAK;IAEtB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port { canonicalBursarConfigDict, type CatalogRollout } from \"../config.js\";\nimport type { PricingEngine } from \"../engine.js\";\nimport { PricingEngine as PricingEngineClass } from \"../engine.js\";\nimport { LeaseNotFoundError, PricingNotLoadedError } from \"../errors.js\";\nimport type { NormalizedLogger } from \"../shared/logger.js\";\nimport type { CreditStore } from \"./store.js\";\nimport type { MetricsOrAmount } from \"./service-types.js\";\n\nexport function toDecimal(value: Decimal | number): Decimal {\n return value instanceof Decimal ? value : new Decimal(value);\n}\n\nexport function isAmount(value: MetricsOrAmount): value is Decimal | number {\n return value instanceof Decimal || typeof value === \"number\";\n}\n\n/** Owns pricing publication, cache refresh, and catalog-version pinning. */\nexport class PricingRuntime {\n private engine: PricingEngine | null;\n private readonly cache: LRUCache<string, PricingEngine>;\n private readonly versionEngines = new Map<number, PricingEngine>();\n\n constructor(\n private readonly store: CreditStore,\n engine: PricingEngine | null,\n private readonly logger: NormalizedLogger,\n private readonly ttl: number,\n ) {\n this.engine = engine;\n this.cache = new LRUCache<string, PricingEngine>({\n max: 1,\n ttl,\n allowStale: true,\n fetchMethod: async () => {\n await this.loadFromStore();\n return this.engine!;\n },\n });\n if (engine) this.cache.set(\"pricing\", engine);\n }\n\n get currentEngine(): PricingEngine | null {\n return this.engine;\n }\n\n async publishFromDict(data: Record<string, unknown>): Promise<void> {\n const canonical = canonicalBursarConfigDict(data);\n this.setEngine(PricingEngineClass.fromDict(canonical));\n await this.store.setActivePricing(canonical);\n }\n\n async loadFromStore(): Promise<void> {\n this.logger.info(\"[CreditsService] loading pricing from store\");\n const active = await this.store.getActivePricing();\n if (!active) {\n this.logger.warn(\"[CreditsService] no active pricing config in store\");\n throw new PricingNotLoadedError(\"no active pricing config in store\");\n }\n this.setEngine(PricingEngineClass.fromDict(active.config as Record<string, unknown>));\n }\n\n async refreshIfStale(): Promise<void> {\n if (this.ttl === 0) return;\n await this.cache.fetch(\"pricing\");\n }\n\n invalidate(): void {\n this.cache.delete(\"pricing\");\n }\n\n async publish(\n config: Record<string, unknown>,\n label?: string | null,\n rollout?: CatalogRollout | Record<string, unknown> | null,\n ): Promise<void> {\n this.logger.info(\"[CreditsService] publishPricing\", { label });\n const canonical = canonicalBursarConfigDict(config);\n this.setEngine(PricingEngineClass.fromDict(canonical));\n await this.store.setActivePricing(canonical, label, rollout);\n }\n\n async publishDraft(config: Record<string, unknown>, label?: string | null): Promise<string> {\n return this.store.publishPricing(canonicalBursarConfigDict(config), label);\n }\n\n async activate(\n version: number,\n rollout?: CatalogRollout | Record<string, unknown> | null,\n ): Promise<string> {\n const id = await this.store.activatePricing(version, rollout);\n await this.loadFromStore();\n return id;\n }\n\n async costOf(\n metricsOrAmount: MetricsOrAmount,\n userId?: string | null,\n leaseId?: string | null,\n ): Promise<{ amount: Decimal; model: string | null }> {\n if (isAmount(metricsOrAmount)) {\n return { amount: toDecimal(metricsOrAmount), model: null };\n }\n let engine: PricingEngine;\n let rateCard: string | undefined;\n if (leaseId != null) {\n if (userId == null) throw new TypeError(\"userId is required when pricing a lease\");\n const context = await this.store.getLeasePricingContext(userId, leaseId);\n if (!context) throw new LeaseNotFoundError(`Lease not found. User=${userId}`);\n engine = await this.engineForCatalogVersion(context.catalogVersion);\n rateCard = context.rateCard ?? engine.getRateCardForPlan(context.planKey);\n } else {\n engine = await this.engineForUser(userId ?? null);\n const plan = userId == null ? null : await this.store.getUserPlan(userId);\n rateCard = plan?.rateCard ?? undefined;\n }\n const breakdown = engine.calculate(metricsOrAmount, {\n rateCard,\n });\n return {\n amount: breakdown.total,\n model:\n typeof metricsOrAmount.dimensions?.model === \"string\"\n ? metricsOrAmount.dimensions.model\n : null,\n };\n }\n\n private setEngine(engine: PricingEngine): void {\n this.engine = engine;\n this.versionEngines.clear();\n this.cache.set(\"pricing\", engine);\n }\n\n async engineForUser(userId: string | null): Promise<PricingEngine> {\n if (userId == null) return this.requireEngine();\n\n const plan = await this.store.getUserPlan(userId);\n const catalogVersion = plan.catalogVersion ?? null;\n if (catalogVersion == null) {\n await this.refreshIfStale();\n return this.requireEngine();\n }\n\n return this.engineForCatalogVersion(catalogVersion);\n }\n\n private async engineForCatalogVersion(catalogVersion: number): Promise<PricingEngine> {\n const cached = this.versionEngines.get(catalogVersion);\n if (cached) return cached;\n\n const config = await this.store.getBursarConfig(catalogVersion);\n if (!config?.config) {\n throw new PricingNotLoadedError(\n `no pricing config for pinned catalog version ${catalogVersion}`,\n );\n }\n\n const engine = PricingEngineClass.fromDict(config.config as Record<string, unknown>);\n this.versionEngines.set(catalogVersion, engine);\n return engine;\n }\n\n private requireEngine(): PricingEngine {\n if (!this.engine) {\n throw new PricingNotLoadedError(\n \"pricing not loaded: call loadPricingFromStore or publishPricing first\",\n );\n }\n return this.engine;\n }\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"load-pricing-file.d.ts","sourceRoot":"","sources":["../src/load-pricing-file.ts"],"names":[],"mappings":"AAkEA;;;;;;;;;GASG;AACH,wBAAsB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CA+BxF"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"load-pricing-file.js","sourceRoot":"","sources":["../src/load-pricing-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAOvD;;;;;GAKG;AACH,SAAS,YAAY,CAAC,GAAY;IAChC,MAAM,SAAS,GAAG,GAAuD,CAAC;IAC1E,IAAI,OAAO,SAAS,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;QACzC,OAAO,SAAuB,CAAC;IACjC,CAAC;IACD,IAAI,SAAS,CAAC,OAAO,IAAI,OAAO,SAAS,CAAC,OAAO,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;QACtE,OAAO,SAAS,CAAC,OAAqB,CAAC;IACzC,CAAC;IAC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C;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 { 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_pricing_file`, `__main__.py:162-198`).\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(`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(`Pricing config is empty: ${filepath}`);\n }\n if (typeof data !== \"object\" || Array.isArray(data)) {\n throw new ConfigError(\n `Pricing config must be a JSON/YAML object, got ${typeof data}: ${filepath}`,\n );\n }\n if (Object.keys(data).length === 0) {\n throw new ConfigError(`Pricing config is empty: ${filepath}`);\n }\n return data as Record<string, unknown>;\n}\n\n/**\n * Read a JSON or YAML pricing 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 (contract §4 / L4).\n */\nexport async function loadPricingFile(filepath: string): Promise<Record<string, unknown>> {\n if (filepath.endsWith(\".yaml\") || filepath.endsWith(\".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"]}