@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 +1 @@
1
- {"version":3,"file":"deduction.d.ts","sourceRoot":"","sources":["../../../../src/credits/postgres/repositories/deduction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAA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KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,kDAAkD;AAClD,qBAAa,mBAAmB;IAClB,OAAO,CAAC,QAAQ;gBAAR,QAAQ,EAAE,QAAQ;IAEtC,mGAAmG;IAC7F,mBAAmB,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;IA8CtE,0EAA0E;IACpE,WAAW,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,cAAc,CAAC;IA8BhE,0CAA0C;IACpC,aAAa,CACjB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,GAAG,IAAI,EACrB,cAAc,EAAE,MAAM,EACtB,MAAM,EAAE,MAAM,GAAG,IAAI,EACrB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,SAAS,CAAC;IA2BrB,0CAA0C;IACpC,wBAAwB,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;CAkBtF"}
@@ -1,70 +1,147 @@
1
1
  import { z } from "zod";
2
- import { pgBoolean, safeParse } from "../../../shared/postgres-validation.js";
2
+ import { optionalRecordRow, postgresUuid, requireRow, safeParse, } from "../../../shared/postgres-validation.js";
3
+ const decimal = z.union([z.string().min(1), z.number().finite()]);
3
4
  export const DeductionRowSchema = z
4
5
  .object({
5
- entry_id: z.string().nullable().optional(),
6
- amount: z
7
- .union([z.string(), z.number()])
8
- .nullable()
9
- .optional(),
10
- balance_after: z
11
- .union([z.string(), z.number()])
12
- .nullable()
13
- .optional(),
14
- allowance_consumed: z
15
- .union([z.string(), z.number()])
16
- .nullable()
17
- .optional(),
18
- idempotent: pgBoolean.nullable().optional(),
19
- bucket_breakdown: z
20
- .record(z.string(), z.union([z.string(), z.number()]))
21
- .nullable()
22
- .optional(),
23
- error: z.string().nullable().optional(),
24
- user_id: z.string().optional(),
6
+ charge_id: postgresUuid.nullable(),
7
+ entry_id: postgresUuid.nullable(),
8
+ amount: decimal,
9
+ balance_after: decimal.nullable(),
10
+ allowance_consumed: decimal,
11
+ idempotent: z.boolean(),
12
+ bucket_breakdown: z.record(z.string().min(1), decimal).nullable(),
13
+ error: z.string().min(1).nullable(),
14
+ user_id: postgresUuid,
25
15
  })
26
- .passthrough();
16
+ .strict()
17
+ .superRefine((row, context) => {
18
+ if (row.error === null && (row.charge_id === null || row.balance_after === null)) {
19
+ context.addIssue({
20
+ code: "custom",
21
+ message: "successful usage charges require a receipt and committed balance",
22
+ });
23
+ }
24
+ if (row.error !== null &&
25
+ (row.charge_id !== null ||
26
+ row.entry_id !== null ||
27
+ row.balance_after !== null ||
28
+ row.idempotent)) {
29
+ context.addIssue({
30
+ code: "custom",
31
+ message: "failed usage charges cannot expose committed fields",
32
+ });
33
+ }
34
+ });
35
+ const ChargeRpcRowSchema = z
36
+ .object({
37
+ charge_id: postgresUuid.nullable(),
38
+ ledger_entry_id: postgresUuid.nullable(),
39
+ charged: decimal,
40
+ allowance_covered: decimal,
41
+ replayed: z.boolean(),
42
+ error_code: z.string().min(1).nullable(),
43
+ })
44
+ .strict()
45
+ .superRefine((row, context) => {
46
+ if (row.error_code === null && row.charge_id === null) {
47
+ context.addIssue({ code: "custom", message: "successful usage charges require a receipt" });
48
+ }
49
+ if (row.error_code !== null &&
50
+ (row.charge_id !== null || row.ledger_entry_id !== null || row.replayed)) {
51
+ context.addIssue({
52
+ code: "custom",
53
+ message: "failed usage charges cannot expose committed fields",
54
+ });
55
+ }
56
+ });
27
57
  const RefundRowSchema = z
28
58
  .object({
29
- refund_entry_id: z.string().optional(),
30
- user_id: z.string().optional(),
31
- amount: z
32
- .union([z.string(), z.number()])
33
- .nullable()
34
- .optional(),
35
- new_balance: z
36
- .union([z.string(), z.number()])
37
- .nullable()
38
- .optional(),
39
- bucket_breakdown: z
40
- .record(z.string(), z.union([z.string(), z.number()]))
41
- .nullable()
42
- .optional(),
43
- error: z.string().nullable().optional(),
59
+ refund_entry_id: postgresUuid.nullable(),
60
+ user_id: postgresUuid.nullable(),
61
+ amount: decimal.nullable(),
62
+ new_balance: decimal.nullable(),
63
+ bucket_breakdown: z.record(z.string().min(1), decimal).nullable(),
64
+ error: z.string().min(1).nullable(),
65
+ })
66
+ .strict()
67
+ .superRefine((row, context) => {
68
+ if (row.error === null &&
69
+ (row.refund_entry_id === null ||
70
+ row.user_id === null ||
71
+ row.amount === null ||
72
+ row.new_balance === null)) {
73
+ context.addIssue({
74
+ code: "custom",
75
+ message: "successful refunds require identity and balance fields",
76
+ });
77
+ }
78
+ if (row.error !== null && (row.refund_entry_id !== null || row.bucket_breakdown !== null)) {
79
+ context.addIssue({
80
+ code: "custom",
81
+ message: "failed refunds cannot expose committed fields",
82
+ });
83
+ }
84
+ });
85
+ const RefundRpcRowSchema = z
86
+ .object({
87
+ entry_id: postgresUuid.nullable(),
88
+ subject_id: postgresUuid.nullable(),
89
+ amount: decimal.nullable(),
90
+ balance_after: decimal.nullable(),
91
+ replayed: z.boolean(),
92
+ error_code: z.string().min(1).nullable(),
44
93
  })
45
- .passthrough();
94
+ .strict();
46
95
  const RevokeRowSchema = z
47
96
  .object({
48
- user_id: z.string().optional(),
49
- amount: z
50
- .union([z.string(), z.number()])
51
- .nullable()
52
- .optional(),
53
- new_balance: z
54
- .union([z.string(), z.number()])
55
- .nullable()
56
- .optional(),
57
- bucket: z.string().nullable().optional(),
97
+ user_id: postgresUuid,
98
+ entry_type: z.string().min(1),
99
+ revoked: decimal,
100
+ balance_after: decimal.nullable(),
101
+ error_code: z.string().min(1).nullable(),
58
102
  })
59
- .passthrough();
103
+ .strict()
104
+ .superRefine((row, context) => {
105
+ if (row.error_code === null && row.balance_after === null) {
106
+ context.addIssue({
107
+ code: "custom",
108
+ message: "successful revocations require a committed balance",
109
+ });
110
+ }
111
+ });
60
112
  const UsageRecordRowSchema = z
61
113
  .object({
62
- charge_id: z.string().nullable().optional(),
63
- requested: z.union([z.string(), z.number()]).nullable().optional(),
64
- replayed: pgBoolean.nullable().optional(),
65
- error_code: z.string().nullable().optional(),
114
+ charge_id: postgresUuid.nullable(),
115
+ requested: decimal,
116
+ replayed: z.boolean(),
117
+ error_code: z.string().min(1).nullable(),
118
+ })
119
+ .strict()
120
+ .superRefine((row, context) => {
121
+ if (row.error_code === null && row.charge_id === null) {
122
+ context.addIssue({
123
+ code: "custom",
124
+ message: "successful usage records require a charge receipt",
125
+ });
126
+ }
127
+ if (row.error_code !== null && (row.charge_id !== null || row.replayed)) {
128
+ context.addIssue({
129
+ code: "custom",
130
+ message: "failed usage records cannot expose committed fields",
131
+ });
132
+ }
133
+ });
134
+ const UsageRecordRpcRowSchema = z
135
+ .object({
136
+ charge_id: postgresUuid.nullable(),
137
+ requested: decimal,
138
+ ledger_entry_id: postgresUuid.nullable(),
139
+ charged: decimal,
140
+ allowance_covered: decimal,
141
+ replayed: z.boolean(),
142
+ error_code: z.string().min(1).nullable(),
66
143
  })
67
- .passthrough();
144
+ .strict();
68
145
  /** Repository for credit deduction operations. */
69
146
  export class DeductionRepository {
70
147
  callproc;
@@ -85,22 +162,22 @@ export class DeductionRepository {
85
162
  params.measures,
86
163
  params.dimensions,
87
164
  ]);
88
- const row = (rows?.[0] ?? {});
165
+ const row = safeParse(ChargeRpcRowSchema, requireRow(rows, "DeductionRepository.deductWithAllowance"), "DeductionRepository.deductWithAllowance");
89
166
  const details = row.error_code != null
90
- ? undefined
91
- : (await this.callproc("get_credit_operation_details", [
167
+ ? null
168
+ : optionalRecordRow(await this.callproc("get_credit_operation_details", [
92
169
  params.userId,
93
170
  row.ledger_entry_id ?? null,
94
171
  params.idempotencyKey,
95
- ]))[0];
172
+ ]), "DeductionRepository.deductWithAllowance.details");
96
173
  return safeParse(DeductionRowSchema, {
97
- ...row,
174
+ charge_id: row.charge_id,
98
175
  user_id: params.userId,
99
176
  entry_id: row.ledger_entry_id,
100
177
  amount: row.charged,
101
178
  allowance_consumed: row.allowance_covered,
102
- balance_after: details?.balance_after ?? row.balance_after,
103
- bucket_breakdown: details?.bucket_breakdown ?? row.bucket_breakdown,
179
+ balance_after: row.error_code === null ? details?.balance_after : null,
180
+ bucket_breakdown: row.error_code === null ? details?.bucket_breakdown : null,
104
181
  idempotent: row.replayed,
105
182
  error: row.error_code,
106
183
  }, "DeductionRepository.deductWithAllowance");
@@ -119,7 +196,13 @@ export class DeductionRepository {
119
196
  params.measures,
120
197
  params.dimensions,
121
198
  ]);
122
- return safeParse(UsageRecordRowSchema, rows?.[0] ?? {}, "DeductionRepository.recordUsage");
199
+ const row = safeParse(UsageRecordRpcRowSchema, requireRow(rows, "DeductionRepository.recordUsage"), "DeductionRepository.recordUsage");
200
+ return safeParse(UsageRecordRowSchema, {
201
+ charge_id: row.charge_id,
202
+ requested: row.requested,
203
+ replayed: row.replayed,
204
+ error_code: row.error_code,
205
+ }, "DeductionRepository.recordUsage");
123
206
  }
124
207
  /** Refund a previous credit deduction. */
125
208
  async refundCredits(entryId, amount, idempotencyKey, reason, metadata) {
@@ -130,24 +213,26 @@ export class DeductionRepository {
130
213
  reason,
131
214
  metadata,
132
215
  ]);
133
- const row = (rows?.[0] ?? {});
216
+ const row = safeParse(RefundRpcRowSchema, requireRow(rows, "DeductionRepository.refundCredits"), "DeductionRepository.refundCredits");
134
217
  return safeParse(RefundRowSchema, {
135
- ...row,
136
218
  refund_entry_id: row.entry_id,
137
219
  user_id: row.subject_id,
220
+ amount: row.amount,
138
221
  new_balance: row.balance_after,
222
+ bucket_breakdown: null,
139
223
  error: row.error_code,
140
224
  }, "DeductionRepository.refundCredits");
141
225
  }
142
226
  /** Revoke credits by transaction type. */
143
227
  async revokeCreditsByEntryType(userId, entryType) {
144
228
  const rows = await this.callproc("revoke_subject_credits_by_operation", [userId, entryType]);
145
- const row = (rows?.[0] ?? {});
229
+ const row = requireRow(rows, "DeductionRepository.revokeCreditsByEntryType");
146
230
  return safeParse(RevokeRowSchema, {
147
231
  user_id: userId,
148
- amount: row.revoked,
149
- new_balance: row.balance_after,
150
- bucket: null,
232
+ entry_type: entryType,
233
+ revoked: row.revoked,
234
+ balance_after: row.balance_after,
235
+ error_code: row.error_code,
151
236
  }, "DeductionRepository.revokeCreditsByEntryType");
152
237
  }
153
238
  }
@@ -1 +1 @@
1
- {"version":3,"file":"deduction.js","sourceRoot":"","sources":["../../../../src/credits/postgres/repositories/deduction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,wCAAwC,CAAC;AAE9E,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC;KAChC,MAAM,CAAC;IACN,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE;IAC1C,MAAM,EAAE,CAAC;SACN,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAU,CAAC;SACxC,QAAQ,EAAE;SACV,QAAQ,EAAE;IACb,aAAa,EAAE,CAAC;SACb,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAU,CAAC;SACxC,QAAQ,EAAE;SACV,QAAQ,EAAE;IACb,kBAAkB,EAAE,CAAC;SAClB,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAU,CAAC;SACxC,QAAQ,EAAE;SACV,QAAQ,EAAE;IACb,UAAU,EAAE,SAAS,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE;IAC3C,gBAAgB,EAAE,CAAC;SAChB,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EA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Proc } from \"../../../shared/postgres-types.js\";\nimport { pgBoolean, safeParse } from \"../../../shared/postgres-validation.js\";\n\nexport const DeductionRowSchema = z\n .object({\n entry_id: z.string().nullable().optional(),\n amount: z\n .union([z.string(), z.number()] as const)\n .nullable()\n .optional(),\n balance_after: z\n .union([z.string(), z.number()] as const)\n .nullable()\n .optional(),\n allowance_consumed: z\n .union([z.string(), z.number()] as const)\n .nullable()\n .optional(),\n idempotent: pgBoolean.nullable().optional(),\n bucket_breakdown: z\n .record(z.string(), z.union([z.string(), z.number()] as const))\n .nullable()\n .optional(),\n error: z.string().nullable().optional(),\n user_id: z.string().optional(),\n })\n .passthrough();\n\nconst RefundRowSchema = z\n .object({\n refund_entry_id: z.string().optional(),\n user_id: z.string().optional(),\n amount: z\n .union([z.string(), z.number()] as const)\n .nullable()\n .optional(),\n new_balance: z\n .union([z.string(), z.number()] as const)\n .nullable()\n .optional(),\n bucket_breakdown: z\n .record(z.string(), z.union([z.string(), z.number()] as const))\n .nullable()\n .optional(),\n error: z.string().nullable().optional(),\n })\n .passthrough();\n\nconst RevokeRowSchema = z\n .object({\n user_id: z.string().optional(),\n amount: z\n .union([z.string(), z.number()] as const)\n .nullable()\n .optional(),\n new_balance: z\n .union([z.string(), z.number()] as const)\n .nullable()\n .optional(),\n bucket: z.string().nullable().optional(),\n })\n .passthrough();\n\nexport type DeductionRow = z.infer<typeof DeductionRowSchema>;\nexport type RefundRow = z.infer<typeof RefundRowSchema>;\nexport type RevokeRow = z.infer<typeof RevokeRowSchema>;\n\nconst UsageRecordRowSchema = z\n .object({\n charge_id: z.string().nullable().optional(),\n requested: z.union([z.string(), z.number()]).nullable().optional(),\n replayed: pgBoolean.nullable().optional(),\n error_code: z.string().nullable().optional(),\n })\n .passthrough();\n\nexport type UsageRecordRow = z.infer<typeof UsageRecordRowSchema>;\n\n/** Typed input for the plan-aware operation charge RPC. */\nexport interface DeductParams {\n userId: string;\n operation: string;\n amount: string;\n idempotencyKey: string;\n feature: string | null;\n model: string | null;\n region: string | null;\n measures: string;\n dimensions: string;\n metadata: string;\n}\n\n/** Repository for credit deduction operations. */\nexport class DeductionRepository {\n constructor(private callproc: CallProc) {}\n\n /** Atomically deduct credits with allowance, entitlement, quota, and credit-policy enforcement. */\n async deductWithAllowance(params: DeductParams): Promise<DeductionRow> {\n const rows = await this.callproc(\"charge_usage_for_operation\", [\n params.userId,\n params.operation,\n params.amount,\n params.idempotencyKey,\n params.feature,\n params.model,\n params.region,\n params.metadata,\n params.measures,\n params.dimensions,\n ]);\n const row = (rows?.[0] ?? {}) as Record<string, unknown>;\n const details =\n row.error_code != null\n ? undefined\n : ((\n await this.callproc(\"get_credit_operation_details\", [\n params.userId,\n row.ledger_entry_id ?? null,\n params.idempotencyKey,\n ])\n )[0] as Record<string, unknown> | undefined);\n return safeParse(\n DeductionRowSchema,\n {\n ...row,\n user_id: params.userId,\n entry_id: row.ledger_entry_id,\n amount: row.charged,\n allowance_consumed: row.allowance_covered,\n balance_after: details?.balance_after ?? row.balance_after,\n bucket_breakdown: details?.bucket_breakdown ?? row.bucket_breakdown,\n idempotent: row.replayed,\n error: row.error_code,\n },\n \"DeductionRepository.deductWithAllowance\",\n );\n }\n\n /** Append a priced usage event without creating another balance debit. */\n async recordUsage(params: DeductParams): Promise<UsageRecordRow> {\n const rows = await this.callproc(\"record_usage\", [\n params.userId,\n params.operation,\n params.amount,\n params.idempotencyKey,\n params.feature,\n params.model,\n params.region,\n params.metadata,\n params.measures,\n params.dimensions,\n ]);\n return safeParse(UsageRecordRowSchema, rows?.[0] ?? {}, \"DeductionRepository.recordUsage\");\n }\n\n /** Refund a previous credit deduction. */\n async refundCredits(\n entryId: string,\n amount: string | null,\n idempotencyKey: string,\n reason: string | null,\n metadata: string,\n ): Promise<RefundRow> {\n const rows = await this.callproc(\"refund_credit_by_entry\", [\n entryId,\n amount,\n idempotencyKey,\n reason,\n metadata,\n ]);\n const row = (rows?.[0] ?? {}) as Record<string, unknown>;\n return safeParse(\n RefundRowSchema,\n {\n ...row,\n refund_entry_id: row.entry_id,\n user_id: row.subject_id,\n new_balance: row.balance_after,\n error: row.error_code,\n },\n \"DeductionRepository.refundCredits\",\n );\n }\n\n /** Revoke credits by transaction type. */\n async revokeCreditsByEntryType(userId: string, entryType: string): Promise<RevokeRow> {\n const rows = await this.callproc(\"revoke_subject_credits_by_operation\", [userId, entryType]);\n const row = (rows?.[0] ?? {}) as Record<string, unknown>;\n return safeParse(\n RevokeRowSchema,\n {\n user_id: userId,\n amount: row.revoked,\n new_balance: row.balance_after,\n bucket: null,\n },\n \"DeductionRepository.revokeCreditsByEntryType\",\n );\n }\n}\n"]}
1
+ {"version":3,"file":"deduction.js","sourceRoot":"","sources":["../../../../src/credits/postgres/repositories/deduction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EACL,iBAAiB,EACjB,YAAY,EACZ,UAAU,EACV,SAAS,GACV,MAAM,wCAAwC,CAAC;AAEhD,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,CAAU,CAAC,CAAC;AAE3E,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC;KAChC,MAAM,CAAC;IACN,SAAS,EAAE,YAAY,CAAC,QAAQ,EAAE;IAClC,QAAQ,EAAE,YAAY,CAAC,QAAQ,EAAE;IACjC,MAAM,EAAE,OAAO;IACf,aAAa,EAAE,OAAO,CAAC,QAAQ,EAAE;IACjC,kBAAkB,EAAE,OAAO;IAC3B,UAAU,EAAE,CAAC,CAAC,OAAO,EAAE;IACvB,gBAAgB,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,QAAQ,EAAE;IACjE,KAAK,EAAE,CA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AAM,GAAG,GAAG,SAAS,CACnB,kBAAkB,EAClB,UAAU,CAAC,IAAI,EAAE,mCAAmC,CAAC,EACrD,mCAAmC,CACpC,CAAC;QACF,OAAO,SAAS,CACd,eAAe,EACf;YACE,eAAe,EAAE,GAAG,CAAC,QAAQ;YAC7B,OAAO,EAAE,GAAG,CAAC,UAAU;YACvB,MAAM,EAAE,GAAG,CAAC,MAAM;YAClB,WAAW,EAAE,GAAG,CAAC,aAAa;YAC9B,gBAAgB,EAAE,IAAI;YACtB,KAAK,EAAE,GAAG,CAAC,UAAU;SACtB,EACD,mCAAmC,CACpC,CAAC;IACJ,CAAC;IAED,0CAA0C;IAC1C,KAAK,CAAC,wBAAwB,CAAC,MAAc,EAAE,SAAiB;QAC9D,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,qCAAqC,EAAE,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;QAC7F,MAAM,GAAG,GAAG,UAAU,CAAC,IAAI,EAAE,8CAA8C,CAG1E,CAAC;QACF,OAAO,SAAS,CACd,eAAe,EACf;YACE,OAAO,EAAE,MAAM;YACf,UAAU,EAAE,SAAS;YACrB,OAAO,EAAE,GAAG,CAAC,OAAO;YACpB,aAAa,EAAE,GAAG,CAAC,aAAa;YAChC,UAAU,EAAE,GAAG,CAAC,UAAU;SAC3B,EACD,8CAA8C,CAC/C,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { z } from \"zod\";\nimport type { CallProc } from \"../../../shared/postgres-types.js\";\nimport {\n optionalRecordRow,\n postgresUuid,\n requireRow,\n safeParse,\n} from \"../../../shared/postgres-validation.js\";\n\nconst decimal = z.union([z.string().min(1), z.number().finite()] as const);\n\nexport const DeductionRowSchema = z\n .object({\n charge_id: postgresUuid.nullable(),\n entry_id: postgresUuid.nullable(),\n amount: decimal,\n balance_after: decimal.nullable(),\n allowance_consumed: decimal,\n idempotent: z.boolean(),\n bucket_breakdown: z.record(z.string().min(1), decimal).nullable(),\n error: z.string().min(1).nullable(),\n user_id: postgresUuid,\n })\n .strict()\n .superRefine((row, context) => {\n if (row.error === null && (row.charge_id === null || row.balance_after === null)) {\n context.addIssue({\n code: \"custom\",\n message: \"successful usage charges require a receipt and committed balance\",\n });\n }\n if (\n row.error !== null &&\n (row.charge_id !== null ||\n row.entry_id !== null ||\n row.balance_after !== null ||\n row.idempotent)\n ) {\n context.addIssue({\n code: \"custom\",\n message: \"failed usage charges cannot expose committed fields\",\n });\n }\n });\n\nconst ChargeRpcRowSchema = z\n .object({\n charge_id: postgresUuid.nullable(),\n ledger_entry_id: postgresUuid.nullable(),\n charged: decimal,\n allowance_covered: decimal,\n replayed: z.boolean(),\n error_code: z.string().min(1).nullable(),\n })\n .strict()\n .superRefine((row, context) => {\n if (row.error_code === null && row.charge_id === null) {\n context.addIssue({ code: \"custom\", message: \"successful usage charges require a receipt\" });\n }\n if (\n row.error_code !== null &&\n (row.charge_id !== null || row.ledger_entry_id !== null || row.replayed)\n ) {\n context.addIssue({\n code: \"custom\",\n message: \"failed usage charges cannot expose committed fields\",\n });\n }\n });\n\nconst RefundRowSchema = z\n .object({\n refund_entry_id: postgresUuid.nullable(),\n user_id: postgresUuid.nullable(),\n amount: decimal.nullable(),\n new_balance: decimal.nullable(),\n bucket_breakdown: z.record(z.string().min(1), decimal).nullable(),\n error: z.string().min(1).nullable(),\n })\n .strict()\n .superRefine((row, context) => {\n if (\n row.error === null &&\n (row.refund_entry_id === null ||\n row.user_id === null ||\n row.amount === null ||\n row.new_balance === null)\n ) {\n context.addIssue({\n code: \"custom\",\n message: \"successful refunds require identity and balance fields\",\n });\n }\n if (row.error !== null && (row.refund_entry_id !== null || row.bucket_breakdown !== null)) {\n context.addIssue({\n code: \"custom\",\n message: \"failed refunds cannot expose committed fields\",\n });\n }\n });\n\nconst RefundRpcRowSchema = z\n .object({\n entry_id: postgresUuid.nullable(),\n subject_id: postgresUuid.nullable(),\n amount: decimal.nullable(),\n balance_after: decimal.nullable(),\n replayed: z.boolean(),\n error_code: z.string().min(1).nullable(),\n })\n .strict();\n\nconst RevokeRowSchema = z\n .object({\n user_id: postgresUuid,\n entry_type: z.string().min(1),\n revoked: decimal,\n balance_after: decimal.nullable(),\n error_code: z.string().min(1).nullable(),\n })\n .strict()\n .superRefine((row, context) => {\n if (row.error_code === null && row.balance_after === null) {\n context.addIssue({\n code: \"custom\",\n message: \"successful revocations require a committed balance\",\n });\n }\n });\n\nexport type DeductionRow = z.infer<typeof DeductionRowSchema>;\nexport type RefundRow = z.infer<typeof RefundRowSchema>;\nexport type RevokeRow = z.infer<typeof RevokeRowSchema>;\n\nconst UsageRecordRowSchema = z\n .object({\n charge_id: postgresUuid.nullable(),\n requested: decimal,\n replayed: z.boolean(),\n error_code: z.string().min(1).nullable(),\n })\n .strict()\n .superRefine((row, context) => {\n if (row.error_code === null && row.charge_id === null) {\n context.addIssue({\n code: \"custom\",\n message: \"successful usage records require a charge receipt\",\n });\n }\n if (row.error_code !== null && (row.charge_id !== null || row.replayed)) {\n context.addIssue({\n code: \"custom\",\n message: \"failed usage records cannot expose committed fields\",\n });\n }\n });\n\nconst UsageRecordRpcRowSchema = z\n .object({\n charge_id: postgresUuid.nullable(),\n requested: decimal,\n ledger_entry_id: postgresUuid.nullable(),\n charged: decimal,\n allowance_covered: decimal,\n replayed: z.boolean(),\n error_code: z.string().min(1).nullable(),\n })\n .strict();\n\nexport type UsageRecordRow = z.infer<typeof UsageRecordRowSchema>;\n\n/** Typed input for the plan-aware operation charge RPC. */\nexport interface DeductParams {\n userId: string;\n operation: string;\n amount: string;\n idempotencyKey: string;\n feature: string | null;\n model: string | null;\n region: string | null;\n measures: string;\n dimensions: string;\n metadata: string;\n}\n\n/** Repository for credit deduction operations. */\nexport class DeductionRepository {\n constructor(private callproc: CallProc) {}\n\n /** Atomically deduct credits with allowance, entitlement, quota, and credit-policy enforcement. */\n async deductWithAllowance(params: DeductParams): Promise<DeductionRow> {\n const rows = await this.callproc(\"charge_usage_for_operation\", [\n params.userId,\n params.operation,\n params.amount,\n params.idempotencyKey,\n params.feature,\n params.model,\n params.region,\n params.metadata,\n params.measures,\n params.dimensions,\n ]);\n const row = safeParse(\n ChargeRpcRowSchema,\n requireRow(rows, \"DeductionRepository.deductWithAllowance\"),\n \"DeductionRepository.deductWithAllowance\",\n );\n const details =\n row.error_code != null\n ? null\n : optionalRecordRow(\n await this.callproc(\"get_credit_operation_details\", [\n params.userId,\n row.ledger_entry_id ?? null,\n params.idempotencyKey,\n ]),\n \"DeductionRepository.deductWithAllowance.details\",\n );\n return safeParse(\n DeductionRowSchema,\n {\n charge_id: row.charge_id,\n user_id: params.userId,\n entry_id: row.ledger_entry_id,\n amount: row.charged,\n allowance_consumed: row.allowance_covered,\n balance_after: row.error_code === null ? details?.balance_after : null,\n bucket_breakdown: row.error_code === null ? details?.bucket_breakdown : null,\n idempotent: row.replayed,\n error: row.error_code,\n },\n \"DeductionRepository.deductWithAllowance\",\n );\n }\n\n /** Append a priced usage event without creating another balance debit. */\n async recordUsage(params: DeductParams): Promise<UsageRecordRow> {\n const rows = await this.callproc(\"record_usage\", [\n params.userId,\n params.operation,\n params.amount,\n params.idempotencyKey,\n params.feature,\n params.model,\n params.region,\n params.metadata,\n params.measures,\n params.dimensions,\n ]);\n const row = safeParse(\n UsageRecordRpcRowSchema,\n requireRow(rows, \"DeductionRepository.recordUsage\"),\n \"DeductionRepository.recordUsage\",\n );\n return safeParse(\n UsageRecordRowSchema,\n {\n charge_id: row.charge_id,\n requested: row.requested,\n replayed: row.replayed,\n error_code: row.error_code,\n },\n \"DeductionRepository.recordUsage\",\n );\n }\n\n /** Refund a previous credit deduction. */\n async refundCredits(\n entryId: string,\n amount: string | null,\n idempotencyKey: string,\n reason: string | null,\n metadata: string,\n ): Promise<RefundRow> {\n const rows = await this.callproc(\"refund_credit_by_entry\", [\n entryId,\n amount,\n idempotencyKey,\n reason,\n metadata,\n ]);\n const row = safeParse(\n RefundRpcRowSchema,\n requireRow(rows, \"DeductionRepository.refundCredits\"),\n \"DeductionRepository.refundCredits\",\n );\n return safeParse(\n RefundRowSchema,\n {\n refund_entry_id: row.entry_id,\n user_id: row.subject_id,\n amount: row.amount,\n new_balance: row.balance_after,\n bucket_breakdown: null,\n error: row.error_code,\n },\n \"DeductionRepository.refundCredits\",\n );\n }\n\n /** Revoke credits by transaction type. */\n async revokeCreditsByEntryType(userId: string, entryType: string): Promise<RevokeRow> {\n const rows = await this.callproc(\"revoke_subject_credits_by_operation\", [userId, entryType]);\n const row = requireRow(rows, \"DeductionRepository.revokeCreditsByEntryType\") as Record<\n string,\n unknown\n >;\n return safeParse(\n RevokeRowSchema,\n {\n user_id: userId,\n entry_type: entryType,\n revoked: row.revoked,\n balance_after: row.balance_after,\n error_code: row.error_code,\n },\n \"DeductionRepository.revokeCreditsByEntryType\",\n );\n }\n}\n"]}
@@ -2,26 +2,29 @@ import { z } from "zod";
2
2
  import type { CallProc } from "../../../shared/postgres-types.js";
3
3
  import type { DeductionRow } from "./deduction.js";
4
4
  declare const LeaseRowSchema: z.ZodObject<{
5
- lease_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
6
- user_id: z.ZodOptional<z.ZodString>;
7
- amount: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>;
8
- available: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>;
9
- reserved: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>;
10
- billing_mode: z.ZodOptional<z.ZodString>;
11
- minimum_balance: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>;
12
- expires_at: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodPipe<z.ZodDate, z.ZodTransform<string, Date>>]>>;
13
- error: z.ZodOptional<z.ZodNullable<z.ZodString>>;
14
- }, z.core.$loose>;
5
+ lease_id: z.ZodNullable<z.ZodString>;
6
+ user_id: z.ZodString;
7
+ amount: z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
8
+ minimum_balance: z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
9
+ expires_at: z.ZodNullable<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodDate]>, z.ZodTransform<string, string | Date>>>;
10
+ error: z.ZodNullable<z.ZodString>;
11
+ }, z.core.$strict>;
15
12
  declare const ReleaseRowSchema: z.ZodObject<{
16
- released: z.ZodOptional<z.ZodNullable<z.ZodPipe<z.ZodUnion<readonly [z.ZodBoolean, z.ZodString, z.ZodNumber]>, z.ZodTransform<boolean, string | number | boolean>>>>;
17
- reason: z.ZodOptional<z.ZodNullable<z.ZodString>>;
18
- }, z.core.$loose>;
13
+ released: z.ZodBoolean;
14
+ reason: z.ZodNullable<z.ZodUnion<[z.ZodEnum<{
15
+ active: "active";
16
+ expired: "expired";
17
+ settling: "settling";
18
+ settled: "settled";
19
+ released: "released";
20
+ }>, z.ZodLiteral<"missing_lease">]>>;
21
+ }, z.core.$strict>;
19
22
  declare const LeasePricingContextRowSchema: z.ZodObject<{
20
- catalog_revision_no: z.ZodCoercedNumber<unknown>;
21
- plan_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
22
- plan_key: z.ZodOptional<z.ZodNullable<z.ZodString>>;
23
- rate_card: z.ZodOptional<z.ZodNullable<z.ZodString>>;
24
- }, z.core.$loose>;
23
+ catalog_revision_no: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>, z.ZodTransform<number, string | number>>;
24
+ plan_id: z.ZodNullable<z.ZodString>;
25
+ plan_key: z.ZodNullable<z.ZodString>;
26
+ rate_card: z.ZodNullable<z.ZodString>;
27
+ }, z.core.$strict>;
25
28
  export type LeaseRow = z.infer<typeof LeaseRowSchema>;
26
29
  export type ReleaseRow = z.infer<typeof ReleaseRowSchema>;
27
30
  export type LeasePricingContextRow = z.infer<typeof LeasePricingContextRowSchema>;
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