@zonastery/bursar 2.0.3 → 2.0.5

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 (376) hide show
  1. package/README.md +1 -1
  2. package/dist/billing/auto-recharge-port.d.ts +3 -2
  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.map +1 -1
  6. package/dist/billing/auto-recharge-service.js +3 -3
  7. package/dist/billing/auto-recharge-service.js.map +1 -1
  8. package/dist/billing/billing-service.d.ts +3 -2
  9. package/dist/billing/billing-service.d.ts.map +1 -1
  10. package/dist/billing/billing-service.js +2 -10
  11. package/dist/billing/billing-service.js.map +1 -1
  12. package/dist/billing/billing-store.d.ts +6 -6
  13. package/dist/billing/billing-store.d.ts.map +1 -1
  14. package/dist/billing/billing-store.js.map +1 -1
  15. package/dist/billing/contracts.d.ts +8 -7
  16. package/dist/billing/contracts.d.ts.map +1 -1
  17. package/dist/billing/contracts.js.map +1 -1
  18. package/dist/billing/event-handlers.d.ts +5 -9
  19. package/dist/billing/event-handlers.d.ts.map +1 -1
  20. package/dist/billing/event-handlers.js +191 -285
  21. package/dist/billing/event-handlers.js.map +1 -1
  22. package/dist/billing/event-processor.d.ts +1 -1
  23. package/dist/billing/event-processor.d.ts.map +1 -1
  24. package/dist/billing/event-processor.js +32 -23
  25. package/dist/billing/event-processor.js.map +1 -1
  26. package/dist/billing/financial-event-handlers.d.ts +3 -9
  27. package/dist/billing/financial-event-handlers.d.ts.map +1 -1
  28. package/dist/billing/financial-event-handlers.js +10 -12
  29. package/dist/billing/financial-event-handlers.js.map +1 -1
  30. package/dist/billing/index.d.ts +1 -1
  31. package/dist/billing/index.d.ts.map +1 -1
  32. package/dist/billing/index.js.map +1 -1
  33. package/dist/billing/management.d.ts +3 -2
  34. package/dist/billing/management.d.ts.map +1 -1
  35. package/dist/billing/management.js.map +1 -1
  36. package/dist/billing/policy-window.js.map +1 -1
  37. package/dist/billing/postgres/repositories/auto-recharge.d.ts +2 -1
  38. package/dist/billing/postgres/repositories/auto-recharge.d.ts.map +1 -1
  39. package/dist/billing/postgres/repositories/auto-recharge.js +58 -40
  40. package/dist/billing/postgres/repositories/auto-recharge.js.map +1 -1
  41. package/dist/billing/postgres/repositories/customer.d.ts.map +1 -1
  42. package/dist/billing/postgres/repositories/customer.js.map +1 -1
  43. package/dist/billing/postgres/repositories/dispute.d.ts +2 -1
  44. package/dist/billing/postgres/repositories/dispute.d.ts.map +1 -1
  45. package/dist/billing/postgres/repositories/dispute.js.map +1 -1
  46. package/dist/billing/postgres/repositories/event.d.ts +2 -2
  47. package/dist/billing/postgres/repositories/event.d.ts.map +1 -1
  48. package/dist/billing/postgres/repositories/event.js.map +1 -1
  49. package/dist/billing/postgres/repositories/invoice.d.ts +2 -1
  50. package/dist/billing/postgres/repositories/invoice.d.ts.map +1 -1
  51. package/dist/billing/postgres/repositories/invoice.js +8 -12
  52. package/dist/billing/postgres/repositories/invoice.js.map +1 -1
  53. package/dist/billing/postgres/repositories/offer.d.ts.map +1 -1
  54. package/dist/billing/postgres/repositories/offer.js +5 -0
  55. package/dist/billing/postgres/repositories/offer.js.map +1 -1
  56. package/dist/billing/postgres/repositories/payment.d.ts +4 -4
  57. package/dist/billing/postgres/repositories/payment.d.ts.map +1 -1
  58. package/dist/billing/postgres/repositories/payment.js +1 -1
  59. package/dist/billing/postgres/repositories/payment.js.map +1 -1
  60. package/dist/billing/postgres/repositories/preferences.d.ts.map +1 -1
  61. package/dist/billing/postgres/repositories/preferences.js.map +1 -1
  62. package/dist/billing/postgres/repositories/refund.d.ts.map +1 -1
  63. package/dist/billing/postgres/repositories/refund.js.map +1 -1
  64. package/dist/billing/postgres/repositories/subscription-change.d.ts.map +1 -1
  65. package/dist/billing/postgres/repositories/subscription-change.js +1 -9
  66. package/dist/billing/postgres/repositories/subscription-change.js.map +1 -1
  67. package/dist/billing/postgres/repositories/subscription.d.ts +11 -11
  68. package/dist/billing/postgres/repositories/subscription.d.ts.map +1 -1
  69. package/dist/billing/postgres/repositories/subscription.js +29 -30
  70. package/dist/billing/postgres/repositories/subscription.js.map +1 -1
  71. package/dist/billing/postgres/repositories/topup.d.ts +1 -1
  72. package/dist/billing/postgres/repositories/topup.d.ts.map +1 -1
  73. package/dist/billing/postgres/repositories/topup.js.map +1 -1
  74. package/dist/billing/postgres/store.d.ts +6 -5
  75. package/dist/billing/postgres/store.d.ts.map +1 -1
  76. package/dist/billing/postgres/store.js +15 -13
  77. package/dist/billing/postgres/store.js.map +1 -1
  78. package/dist/billing/types/auto-recharge.d.ts +2 -1
  79. package/dist/billing/types/auto-recharge.d.ts.map +1 -1
  80. package/dist/billing/types/auto-recharge.js.map +1 -1
  81. package/dist/billing/types/documents.d.ts +2 -1
  82. package/dist/billing/types/documents.d.ts.map +1 -1
  83. package/dist/billing/types/documents.js.map +1 -1
  84. package/dist/billing/types/events.d.ts +3 -2
  85. package/dist/billing/types/events.d.ts.map +1 -1
  86. package/dist/billing/types/events.js +73 -39
  87. package/dist/billing/types/events.js.map +1 -1
  88. package/dist/billing/types/subscriptions.d.ts +4 -1
  89. package/dist/billing/types/subscriptions.d.ts.map +1 -1
  90. package/dist/billing/types/subscriptions.js.map +1 -1
  91. package/dist/breakdown.d.ts +3 -2
  92. package/dist/breakdown.d.ts.map +1 -1
  93. package/dist/breakdown.js.map +1 -1
  94. package/dist/bursar.d.ts.map +1 -1
  95. package/dist/bursar.js +4 -3
  96. package/dist/bursar.js.map +1 -1
  97. package/dist/catalog.d.ts.map +1 -1
  98. package/dist/catalog.js +45 -42
  99. package/dist/catalog.js.map +1 -1
  100. package/dist/commerce/errors.d.ts.map +1 -1
  101. package/dist/commerce/errors.js.map +1 -1
  102. package/dist/commerce/provider-registry.d.ts.map +1 -1
  103. package/dist/commerce/provider-registry.js +11 -6
  104. package/dist/commerce/provider-registry.js.map +1 -1
  105. package/dist/commerce/service.d.ts +1 -1
  106. package/dist/commerce/service.d.ts.map +1 -1
  107. package/dist/commerce/service.js +16 -22
  108. package/dist/commerce/service.js.map +1 -1
  109. package/dist/commerce/types.d.ts.map +1 -1
  110. package/dist/commerce/types.js.map +1 -1
  111. package/dist/config/parse-access.d.ts +5 -2
  112. package/dist/config/parse-access.d.ts.map +1 -1
  113. package/dist/config/parse-access.js +60 -41
  114. package/dist/config/parse-access.js.map +1 -1
  115. package/dist/config/parse-commerce.d.ts +2 -1
  116. package/dist/config/parse-commerce.d.ts.map +1 -1
  117. package/dist/config/parse-commerce.js +49 -29
  118. package/dist/config/parse-commerce.js.map +1 -1
  119. package/dist/config/parse-credits.d.ts +2 -1
  120. package/dist/config/parse-credits.d.ts.map +1 -1
  121. package/dist/config/parse-credits.js +39 -23
  122. package/dist/config/parse-credits.js.map +1 -1
  123. package/dist/config/parse-plans.d.ts +7 -2
  124. package/dist/config/parse-plans.d.ts.map +1 -1
  125. package/dist/config/parse-plans.js +49 -22
  126. package/dist/config/parse-plans.js.map +1 -1
  127. package/dist/config/parse-pricing.d.ts +2 -1
  128. package/dist/config/parse-pricing.d.ts.map +1 -1
  129. package/dist/config/parse-pricing.js +41 -31
  130. package/dist/config/parse-pricing.js.map +1 -1
  131. package/dist/config/parse-utils.d.ts +15 -11
  132. package/dist/config/parse-utils.d.ts.map +1 -1
  133. package/dist/config/parse-utils.js +90 -27
  134. package/dist/config/parse-utils.js.map +1 -1
  135. package/dist/config/types.d.ts.map +1 -1
  136. package/dist/config/types.js.map +1 -1
  137. package/dist/config.d.ts +6 -5
  138. package/dist/config.d.ts.map +1 -1
  139. package/dist/config.js +65 -35
  140. package/dist/config.js.map +1 -1
  141. package/dist/credits/amount.d.ts +1 -1
  142. package/dist/credits/amount.d.ts.map +1 -1
  143. package/dist/credits/amount.js +5 -4
  144. package/dist/credits/amount.js.map +1 -1
  145. package/dist/credits/catalog-runtime.d.ts.map +1 -1
  146. package/dist/credits/catalog-runtime.js +2 -3
  147. package/dist/credits/catalog-runtime.js.map +1 -1
  148. package/dist/credits/events.d.ts +12 -1
  149. package/dist/credits/events.d.ts.map +1 -1
  150. package/dist/credits/events.js +35 -21
  151. package/dist/credits/events.js.map +1 -1
  152. package/dist/credits/lease-workflow.d.ts +2 -1
  153. package/dist/credits/lease-workflow.d.ts.map +1 -1
  154. package/dist/credits/lease-workflow.js +3 -2
  155. package/dist/credits/lease-workflow.js.map +1 -1
  156. package/dist/credits/low-balance-monitor.d.ts +2 -1
  157. package/dist/credits/low-balance-monitor.d.ts.map +1 -1
  158. package/dist/credits/low-balance-monitor.js.map +1 -1
  159. package/dist/credits/postgres/repositories/analytics.d.ts +2 -2
  160. package/dist/credits/postgres/repositories/analytics.d.ts.map +1 -1
  161. package/dist/credits/postgres/repositories/analytics.js +14 -6
  162. package/dist/credits/postgres/repositories/analytics.js.map +1 -1
  163. package/dist/credits/postgres/repositories/balance.d.ts.map +1 -1
  164. package/dist/credits/postgres/repositories/balance.js +6 -6
  165. package/dist/credits/postgres/repositories/balance.js.map +1 -1
  166. package/dist/credits/postgres/repositories/bucket.d.ts.map +1 -1
  167. package/dist/credits/postgres/repositories/bucket.js.map +1 -1
  168. package/dist/credits/postgres/repositories/catalog.d.ts +5 -4
  169. package/dist/credits/postgres/repositories/catalog.d.ts.map +1 -1
  170. package/dist/credits/postgres/repositories/catalog.js +4 -3
  171. package/dist/credits/postgres/repositories/catalog.js.map +1 -1
  172. package/dist/credits/postgres/repositories/deduction.d.ts.map +1 -1
  173. package/dist/credits/postgres/repositories/deduction.js +2 -2
  174. package/dist/credits/postgres/repositories/deduction.js.map +1 -1
  175. package/dist/credits/postgres/repositories/lease.d.ts +2 -2
  176. package/dist/credits/postgres/repositories/lease.d.ts.map +1 -1
  177. package/dist/credits/postgres/repositories/lease.js.map +1 -1
  178. package/dist/credits/postgres/repositories/plan.d.ts +11 -11
  179. package/dist/credits/postgres/repositories/plan.d.ts.map +1 -1
  180. package/dist/credits/postgres/repositories/plan.js.map +1 -1
  181. package/dist/credits/postgres/repositories/team.d.ts +2 -2
  182. package/dist/credits/postgres/repositories/team.d.ts.map +1 -1
  183. package/dist/credits/postgres/repositories/team.js.map +1 -1
  184. package/dist/credits/postgres/store.d.ts +3 -2
  185. package/dist/credits/postgres/store.d.ts.map +1 -1
  186. package/dist/credits/postgres/store.js +17 -10
  187. package/dist/credits/postgres/store.js.map +1 -1
  188. package/dist/credits/postgres/value-mappers.d.ts +4 -3
  189. package/dist/credits/postgres/value-mappers.d.ts.map +1 -1
  190. package/dist/credits/postgres/value-mappers.js +10 -11
  191. package/dist/credits/postgres/value-mappers.js.map +1 -1
  192. package/dist/credits/queries.d.ts.map +1 -1
  193. package/dist/credits/queries.js.map +1 -1
  194. package/dist/credits/service.d.ts.map +1 -1
  195. package/dist/credits/service.js +10 -5
  196. package/dist/credits/service.js.map +1 -1
  197. package/dist/credits/store.d.ts +5 -4
  198. package/dist/credits/store.d.ts.map +1 -1
  199. package/dist/credits/store.js.map +1 -1
  200. package/dist/credits/types/account.d.ts +5 -4
  201. package/dist/credits/types/account.d.ts.map +1 -1
  202. package/dist/credits/types/account.js.map +1 -1
  203. package/dist/credits/types/catalog.d.ts +2 -1
  204. package/dist/credits/types/catalog.d.ts.map +1 -1
  205. package/dist/credits/types/catalog.js.map +1 -1
  206. package/dist/credits/types/grants.d.ts.map +1 -1
  207. package/dist/credits/types/grants.js.map +1 -1
  208. package/dist/credits/types/ledger.d.ts +3 -2
  209. package/dist/credits/types/ledger.d.ts.map +1 -1
  210. package/dist/credits/types/ledger.js.map +1 -1
  211. package/dist/engine.d.ts +2 -2
  212. package/dist/engine.d.ts.map +1 -1
  213. package/dist/engine.js +39 -10
  214. package/dist/engine.js.map +1 -1
  215. package/dist/errors.d.ts +7 -4
  216. package/dist/errors.d.ts.map +1 -1
  217. package/dist/errors.js +18 -11
  218. package/dist/errors.js.map +1 -1
  219. package/dist/expr/ast.d.ts.map +1 -1
  220. package/dist/expr/ast.js.map +1 -1
  221. package/dist/expr/evaluator.js.map +1 -1
  222. package/dist/expr/parser.d.ts.map +1 -1
  223. package/dist/expr/parser.js.map +1 -1
  224. package/dist/expr/tokenizer.d.ts.map +1 -1
  225. package/dist/expr/tokenizer.js +34 -12
  226. package/dist/expr/tokenizer.js.map +1 -1
  227. package/dist/expr.d.ts.map +1 -1
  228. package/dist/expr.js +12 -6
  229. package/dist/expr.js.map +1 -1
  230. package/dist/generated/pricing-config.schema.json +0 -12
  231. package/dist/generated/pricing-config.types.d.ts +2 -8
  232. package/dist/generated/pricing-config.types.d.ts.map +1 -1
  233. package/dist/generated/pricing-config.types.js.map +1 -1
  234. package/dist/integrations/better-auth.d.ts +4 -1
  235. package/dist/integrations/better-auth.d.ts.map +1 -1
  236. package/dist/integrations/better-auth.js +7 -4
  237. package/dist/integrations/better-auth.js.map +1 -1
  238. package/dist/load-config-file.d.ts +2 -1
  239. package/dist/load-config-file.d.ts.map +1 -1
  240. package/dist/load-config-file.js +19 -13
  241. package/dist/load-config-file.js.map +1 -1
  242. package/dist/metrics.d.ts +2 -1
  243. package/dist/metrics.d.ts.map +1 -1
  244. package/dist/metrics.js.map +1 -1
  245. package/dist/node.d.ts +1 -1
  246. package/dist/node.d.ts.map +1 -1
  247. package/dist/node.js.map +1 -1
  248. package/dist/providers/_shared.d.ts +8 -5
  249. package/dist/providers/_shared.d.ts.map +1 -1
  250. package/dist/providers/_shared.js +15 -11
  251. package/dist/providers/_shared.js.map +1 -1
  252. package/dist/providers/dodo/better-auth-core.d.ts +30 -0
  253. package/dist/providers/dodo/better-auth-core.d.ts.map +1 -0
  254. package/dist/providers/dodo/better-auth-core.js +14 -0
  255. package/dist/providers/dodo/better-auth-core.js.map +1 -0
  256. package/dist/providers/dodo/better-auth.d.ts +5 -9
  257. package/dist/providers/dodo/better-auth.d.ts.map +1 -1
  258. package/dist/providers/dodo/better-auth.js +16 -13
  259. package/dist/providers/dodo/better-auth.js.map +1 -1
  260. package/dist/providers/dodo/client-contract.d.ts +12 -10
  261. package/dist/providers/dodo/client-contract.d.ts.map +1 -1
  262. package/dist/providers/dodo/client-contract.js.map +1 -1
  263. package/dist/providers/dodo/event-mapper.d.ts +7 -4
  264. package/dist/providers/dodo/event-mapper.d.ts.map +1 -1
  265. package/dist/providers/dodo/event-mapper.js +121 -113
  266. package/dist/providers/dodo/event-mapper.js.map +1 -1
  267. package/dist/providers/dodo/nextjs-core.d.ts +22 -0
  268. package/dist/providers/dodo/nextjs-core.d.ts.map +1 -0
  269. package/dist/providers/dodo/nextjs-core.js +14 -0
  270. package/dist/providers/dodo/nextjs-core.js.map +1 -0
  271. package/dist/providers/dodo/nextjs.d.ts +5 -7
  272. package/dist/providers/dodo/nextjs.d.ts.map +1 -1
  273. package/dist/providers/dodo/nextjs.js +11 -10
  274. package/dist/providers/dodo/nextjs.js.map +1 -1
  275. package/dist/providers/dodo/provider.d.ts +3 -3
  276. package/dist/providers/dodo/provider.d.ts.map +1 -1
  277. package/dist/providers/dodo/provider.js +42 -35
  278. package/dist/providers/dodo/provider.js.map +1 -1
  279. package/dist/providers/dodo/react-native-core.d.ts +56 -0
  280. package/dist/providers/dodo/react-native-core.d.ts.map +1 -0
  281. package/dist/providers/dodo/react-native-core.js +56 -0
  282. package/dist/providers/dodo/react-native-core.js.map +1 -0
  283. package/dist/providers/dodo/react-native.d.ts +6 -50
  284. package/dist/providers/dodo/react-native.d.ts.map +1 -1
  285. package/dist/providers/dodo/react-native.js +5 -49
  286. package/dist/providers/dodo/react-native.js.map +1 -1
  287. package/dist/providers/dodo/webhook-bridge.d.ts +4 -2
  288. package/dist/providers/dodo/webhook-bridge.d.ts.map +1 -1
  289. package/dist/providers/dodo/webhook-bridge.js.map +1 -1
  290. package/dist/providers/environment.d.ts +1 -1
  291. package/dist/providers/environment.d.ts.map +1 -1
  292. package/dist/providers/environment.js +4 -2
  293. package/dist/providers/environment.js.map +1 -1
  294. package/dist/providers/mock/provider.d.ts.map +1 -1
  295. package/dist/providers/mock/provider.js +5 -10
  296. package/dist/providers/mock/provider.js.map +1 -1
  297. package/dist/providers/stripe/event-mapper.d.ts.map +1 -1
  298. package/dist/providers/stripe/event-mapper.js +33 -9
  299. package/dist/providers/stripe/event-mapper.js.map +1 -1
  300. package/dist/providers/stripe/provider.d.ts.map +1 -1
  301. package/dist/providers/stripe/provider.js +101 -61
  302. package/dist/providers/stripe/provider.js.map +1 -1
  303. package/dist/providers/types.d.ts.map +1 -1
  304. package/dist/providers/types.js.map +1 -1
  305. package/dist/retry.d.ts.map +1 -1
  306. package/dist/retry.js +16 -9
  307. package/dist/retry.js.map +1 -1
  308. package/dist/shared/diagnostics.d.ts +5 -5
  309. package/dist/shared/diagnostics.d.ts.map +1 -1
  310. package/dist/shared/diagnostics.js +32 -22
  311. package/dist/shared/diagnostics.js.map +1 -1
  312. package/dist/shared/idempotency.d.ts +4 -3
  313. package/dist/shared/idempotency.d.ts.map +1 -1
  314. package/dist/shared/idempotency.js +21 -10
  315. package/dist/shared/idempotency.js.map +1 -1
  316. package/dist/shared/json.d.ts +28 -0
  317. package/dist/shared/json.d.ts.map +1 -0
  318. package/dist/shared/json.js +41 -0
  319. package/dist/shared/json.js.map +1 -0
  320. package/dist/shared/logger.d.ts +10 -4
  321. package/dist/shared/logger.d.ts.map +1 -1
  322. package/dist/shared/logger.js +28 -4
  323. package/dist/shared/logger.js.map +1 -1
  324. package/dist/shared/postgres-client.d.ts +8 -6
  325. package/dist/shared/postgres-client.d.ts.map +1 -1
  326. package/dist/shared/postgres-client.js +69 -47
  327. package/dist/shared/postgres-client.js.map +1 -1
  328. package/dist/shared/postgres-errors.d.ts +1 -1
  329. package/dist/shared/postgres-errors.d.ts.map +1 -1
  330. package/dist/shared/postgres-errors.js +32 -31
  331. package/dist/shared/postgres-errors.js.map +1 -1
  332. package/dist/shared/postgres-types.d.ts +3 -2
  333. package/dist/shared/postgres-types.d.ts.map +1 -1
  334. package/dist/shared/postgres-types.js.map +1 -1
  335. package/dist/shared/postgres-validation.d.ts +7 -6
  336. package/dist/shared/postgres-validation.d.ts.map +1 -1
  337. package/dist/shared/postgres-validation.js +17 -10
  338. package/dist/shared/postgres-validation.js.map +1 -1
  339. package/dist/storage/adapters/clickhouse.d.ts +11 -4
  340. package/dist/storage/adapters/clickhouse.d.ts.map +1 -1
  341. package/dist/storage/adapters/clickhouse.js +8 -6
  342. package/dist/storage/adapters/clickhouse.js.map +1 -1
  343. package/dist/storage/adapters/s3.d.ts +28 -5
  344. package/dist/storage/adapters/s3.d.ts.map +1 -1
  345. package/dist/storage/adapters/s3.js +48 -33
  346. package/dist/storage/adapters/s3.js.map +1 -1
  347. package/dist/storage/diagnostics.d.ts +1 -1
  348. package/dist/storage/diagnostics.d.ts.map +1 -1
  349. package/dist/storage/diagnostics.js +13 -12
  350. package/dist/storage/diagnostics.js.map +1 -1
  351. package/dist/storage/maintenance.d.ts.map +1 -1
  352. package/dist/storage/maintenance.js +31 -25
  353. package/dist/storage/maintenance.js.map +1 -1
  354. package/dist/storage/outbox-worker.d.ts +1 -1
  355. package/dist/storage/outbox-worker.d.ts.map +1 -1
  356. package/dist/storage/outbox-worker.js +18 -18
  357. package/dist/storage/outbox-worker.js.map +1 -1
  358. package/dist/storage/ports.d.ts +10 -7
  359. package/dist/storage/ports.d.ts.map +1 -1
  360. package/dist/storage/ports.js.map +1 -1
  361. package/dist/storage/postgres-repository.d.ts +3 -1
  362. package/dist/storage/postgres-repository.d.ts.map +1 -1
  363. package/dist/storage/postgres-repository.js +10 -4
  364. package/dist/storage/postgres-repository.js.map +1 -1
  365. package/dist/storage/runtime.d.ts +1 -1
  366. package/dist/storage/runtime.d.ts.map +1 -1
  367. package/dist/storage/runtime.js +165 -182
  368. package/dist/storage/runtime.js.map +1 -1
  369. package/dist/telemetry/index.d.ts +10 -6
  370. package/dist/telemetry/index.d.ts.map +1 -1
  371. package/dist/telemetry/index.js +26 -23
  372. package/dist/telemetry/index.js.map +1 -1
  373. package/dist/telemetry/opentelemetry.d.ts.map +1 -1
  374. package/dist/telemetry/opentelemetry.js +3 -3
  375. package/dist/telemetry/opentelemetry.js.map +1 -1
  376. package/package.json +40 -40
@@ -1 +1 @@
1
- {"version":3,"file":"dispute.js","sourceRoot":"","sources":["../../../../src/billing/postgres/repositories/dispute.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAC;AAE1F,MAAM,OAAO,wBAAwB;IACf;IAApB,YAAoB,KAAc;QAAd,UAAK,GAAL,KAAK,CAAS;IAAG,CAAC;IAEtC,KAAK,CAAC,MAAM,CACV,QAAgB,EAChB,iBAAyB,EACzB,SAAiB,EACjB,MAAc,EACd,MAAqB,EACrB,QAAiC,EACjC,iBAAyB;QAEzB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,KAAK,CAC3B,qFAAqF,EACrF;YACE,QAAQ;YACR,iBAAiB;YACjB,SAAS;YACT,MAAM;YACN,MAAM;YACN,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC;YACxB,iBAAiB;SAClB,CACF,CAAC;QACF,kBAAkB,CAAC,IAAI,EAAE,IAAI,EAAE,YAAY,EAAE,iCAAiC,CAAC,CAAC;IAClF,CAAC;CACF","sourcesContent":["import type { QueryFn } from \"../../../shared/postgres-types.js\";\nimport { postgresUuid, requireResultField } from \"../../../shared/postgres-validation.js\";\n\nexport class BillingDisputeRepository {\n constructor(private query: QueryFn) {}\n\n async upsert(\n provider: string,\n providerDisputeId: string,\n paymentId: string,\n status: string,\n reason: string | null,\n metadata: Record<string, unknown>,\n providerUpdatedAt: string,\n ): Promise<void> {\n const rows = await this.query(\n `SELECT bursar.upsert_billing_dispute($1, $2, $3::uuid, $4, $5, $6::jsonb, $7) AS id`,\n [\n provider,\n providerDisputeId,\n paymentId,\n status,\n reason,\n JSON.stringify(metadata),\n providerUpdatedAt,\n ],\n );\n requireResultField(rows, \"id\", postgresUuid, \"BillingDisputeRepository.upsert\");\n }\n}\n"]}
1
+ {"version":3,"file":"dispute.js","sourceRoot":"","sources":["../../../../src/billing/postgres/repositories/dispute.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAC;AAE1F,MAAM,OAAO,wBAAwB;IACf,KAAK;IAAzB,YAAoB,KAAc;qBAAd,KAAK;IAAY,CAAC;IAEtC,KAAK,CAAC,MAAM,CACV,QAAgB,EAChB,iBAAyB,EACzB,SAAiB,EACjB,MAAc,EACd,MAAqB,EACrB,QAAoB,EACpB,iBAAyB;QAEzB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,KAAK,CAC3B,qFAAqF,EACrF;YACE,QAAQ;YACR,iBAAiB;YACjB,SAAS;YACT,MAAM;YACN,MAAM;YACN,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC;YACxB,iBAAiB;SAClB,CACF,CAAC;QACF,kBAAkB,CAAC,IAAI,EAAE,IAAI,EAAE,YAAY,EAAE,iCAAiC,CAAC,CAAC;IAClF,CAAC;CACF","sourcesContent":["import type { QueryFn } from \"../../../shared/postgres-types.js\";\nimport type { JsonObject } from \"../../../shared/json.js\";\nimport { postgresUuid, requireResultField } from \"../../../shared/postgres-validation.js\";\n\nexport class BillingDisputeRepository {\n constructor(private query: QueryFn) {}\n\n async upsert(\n provider: string,\n providerDisputeId: string,\n paymentId: string,\n status: string,\n reason: string | null,\n metadata: JsonObject,\n providerUpdatedAt: string,\n ): Promise<void> {\n const rows = await this.query(\n `SELECT bursar.upsert_billing_dispute($1, $2, $3::uuid, $4, $5, $6::jsonb, $7) AS id`,\n [\n provider,\n providerDisputeId,\n paymentId,\n status,\n reason,\n JSON.stringify(metadata),\n providerUpdatedAt,\n ],\n );\n requireResultField(rows, \"id\", postgresUuid, \"BillingDisputeRepository.upsert\");\n }\n}\n"]}
@@ -2,11 +2,11 @@ import { z } from "zod";
2
2
  import type { QueryFn } from "../../../shared/postgres-types.js";
3
3
  declare const BillingEventRowSchema: z.ZodObject<{
4
4
  status: z.ZodEnum<{
5
- invalid_request: "invalid_request";
5
+ busy: "busy";
6
6
  claimed: "claimed";
7
7
  duplicate: "duplicate";
8
- busy: "busy";
9
8
  idempotency_conflict: "idempotency_conflict";
9
+ invalid_request: "invalid_request";
10
10
  max_retries_exceeded: "max_retries_exceeded";
11
11
  }>;
12
12
  event_id: z.ZodNullable<z.ZodString>;
@@ -1 +1 @@
1
- {"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../../../../src/billing/postgres/repositories/event.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AASjE,QAAA,MAAM,qBAAqB;;;;;;;;;;;kBA6CvB,CAAC;AAEL,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAMpE,yDAAyD;AACzD,qBAAa,sBAAsB;IACrB,OAAO,CAAC,KAAK;gBAAL,KAAK,EAAE,OAAO;IAElC,+DAA+D;IACzD,KAAK,CACT,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,eAAe,CAAC;IAgB3B,yCAAyC;IACnC,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAQvF,sCAAsC;IAChC,IAAI,CACR,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,OAAO,CAAC;CAOpB"}
1
+ {"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../../../../src/billing/postgres/repositories/event.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAUjE,QAAA,MAAM,qBAAqB;;;;;;;;;;;kBA6CvB,CAAC;AAEL,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAMpE,yDAAyD;AACzD,qBAAa,sBAAsB;IACrB,OAAO,CAAC,KAAK;IAAzB,YAAoB,KAAK,EAAE,OAAO,EAAI;IAEtC,+DAA+D;IACzD,KAAK,CACT,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,eAAe,CAAC,CAc1B;IAED,yCAAyC;IACnC,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAMtF;IAED,sCAAsC;IAChC,IAAI,CACR,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,OAAO,CAAC,CAMlB;CACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"event.js","sourceRoot":"","sources":["../../../../src/billing/postgres/repositories/event.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EACL,SAAS,EACT,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,EAClB,SAAS,GACV,MAAM,wCAAwC,CAAC;AAEhD,MAAM,qBAAqB,GAAG,CAAC;KAC5B,MAAM,CAAC;IACN,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC;QACb,SAAS;QACT,WAAW;QACX,MAAM;QACN,iBAAiB;QACjB,sBAAsB;QACtB,sBAAsB;KACvB,CAAC;IACF,QAAQ,EAAE,YAAY,CAAC,QAAQ,EAAE;IACjC,WAAW,EAAE,YAAY,CAAC,QAA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import { z } from \"zod\";\nimport type { QueryFn } from \"../../../shared/postgres-types.js\";\nimport {\n pgBoolean,\n postgresUuid,\n requireRecordRow,\n requireResultField,\n safeParse,\n} from \"../../../shared/postgres-validation.js\";\n\nconst BillingEventRowSchema = z\n .object({\n status: z.enum([\n \"claimed\",\n \"duplicate\",\n \"busy\",\n \"invalid_request\",\n \"idempotency_conflict\",\n \"max_retries_exceeded\",\n ]),\n event_id: postgresUuid.nullable(),\n claim_token: postgresUuid.nullable(),\n })\n .strict()\n .superRefine((row, ctx) => {\n if (row.status === \"claimed\") {\n if (row.event_id === null || row.claim_token === null) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: \"claimed billing event requires event_id and claim_token\",\n });\n }\n return;\n }\n if (row.claim_token !== null) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: \"unclaimed billing event cannot expose a claim_token\",\n });\n }\n if (row.status === \"invalid_request\") {\n if (row.event_id !== null) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: \"invalid billing event request cannot identify a stored event\",\n });\n }\n return;\n }\n if (row.event_id === null) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: \"stored billing event outcome requires event_id\",\n });\n }\n });\n\nexport type BillingEventRow = z.infer<typeof BillingEventRowSchema>;\n\nfunction booleanResult(rows: unknown[], key: string, context: string): boolean {\n return requireResultField(rows, key, pgBoolean, context);\n}\n\n/** Repository for billing event lifecycle operations. */\nexport class BillingEventRepository {\n constructor(private query: QueryFn) {}\n\n /** Claim a billing event for processing (idempotent claim). */\n async claim(\n provider: string,\n eventId: string,\n eventType: string,\n metadata: string,\n ): Promise<BillingEventRow> {\n const rows = await this.query(\"SELECT * FROM bursar.claim_billing_event($1, $2, $3, $4)\", [\n provider,\n eventId,\n eventType,\n metadata,\n ]);\n const row = requireRecordRow(rows, \"BillingEventRepository.claim\");\n return safeParse(\n BillingEventRowSchema,\n { event_id: row.event_id, status: row.result, claim_token: row.claim_token },\n \"BillingEventRepository.claim\",\n { indeterminate: true },\n );\n }\n\n /** Mark a billing event as completed. */\n async complete(provider: string, eventId: string, claimToken: string): Promise<boolean> {\n const rows = await this.query(\n \"SELECT bursar.complete_billing_event($1, $2, $3::uuid) AS completed\",\n [provider, eventId, claimToken],\n );\n return booleanResult(rows, \"completed\", \"BillingEventRepository.complete\");\n }\n\n /** Mark a billing event as failed. */\n async fail(\n provider: string,\n eventId: string,\n claimToken: string,\n error?: string,\n ): Promise<boolean> {\n const rows = await this.query(\n \"SELECT bursar.fail_billing_event($1, $2, $3::uuid, $4) AS failed\",\n [provider, eventId, claimToken, error ?? null],\n );\n return booleanResult(rows, \"failed\", \"BillingEventRepository.fail\");\n }\n}\n"]}
1
+ {"version":3,"file":"event.js","sourceRoot":"","sources":["../../../../src/billing/postgres/repositories/event.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EACL,SAAS,EACT,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,EAClB,SAAS,GACV,MAAM,wCAAwC,CAAC;AAEhD,MAAM,qBAAqB,GAAG,CAAC;KAC5B,MAAM,CAAC;IACN,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC;QACb,SAAS;QACT,WAAW;QACX,MAAM;QACN,iBAAiB;QACjB,sBAAsB;QACtB,sBAAsB;KACvB,CAAC;IACF,QAAQ,EAAE,YAAY,CAAC,QAAQ,EAAE;IACjC,WAAW,EAAE,YAAY,CAAC,QAAQ,EAAE;CACrC,CAAC;KACD,MAAM,EAAE;KACR,WAAW,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;IACxB,IAAI,GAAG,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;QAC7B,IAAI,GAAG,CAAC,QAAQ,KAAK,IAAI,IAAI,GAAG,CAAC,WAAW,KAAK,IAAI,EAAE,CAAC;YACtD,GAAG,CAAC,QAAQ,CAAC;gBACX,IAAI,EAAE,CAAC,CAAC,YAAY,CAA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QACH,MAAM,GAAG,GAAG,gBAAgB,CAAC,IAAI,EAAE,8BAA8B,CAAC,CAAC;QACnE,OAAO,SAAS,CACd,qBAAqB,EACrB,EAAE,QAAQ,EAAE,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,EAAE,GAAG,CAAC,WAAW,EAAE,EAC5E,8BAA8B,EAC9B,EAAE,aAAa,EAAE,IAAI,EAAE,CACxB,CAAC;IACJ,CAAC;IAED,yCAAyC;IACzC,KAAK,CAAC,QAAQ,CAAC,QAAgB,EAAE,OAAe,EAAE,UAAkB;QAClE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,KAAK,CAC3B,qEAAqE,EACrE,CAAC,QAAQ,EAAE,OAAO,EAAE,UAAU,CAAC,CAChC,CAAC;QACF,OAAO,aAAa,CAAC,IAAI,EAAE,WAAW,EAAE,iCAAiC,CAAC,CAAC;IAC7E,CAAC;IAED,sCAAsC;IACtC,KAAK,CAAC,IAAI,CACR,QAAgB,EAChB,OAAe,EACf,UAAkB,EAClB,KAAc;QAEd,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,KAAK,CAC3B,kEAAkE,EAClE,CAAC,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,IAAI,IAAI,CAAC,CAC/C,CAAC;QACF,OAAO,aAAa,CAAC,IAAI,EAAE,QAAQ,EAAE,6BAA6B,CAAC,CAAC;IACtE,CAAC;CACF","sourcesContent":["import { z } from \"zod\";\nimport type { QueryFn } from \"../../../shared/postgres-types.js\";\nimport type { PostgresValue } from \"../../../shared/json.js\";\nimport {\n pgBoolean,\n postgresUuid,\n requireRecordRow,\n requireResultField,\n safeParse,\n} from \"../../../shared/postgres-validation.js\";\n\nconst BillingEventRowSchema = z\n .object({\n status: z.enum([\n \"claimed\",\n \"duplicate\",\n \"busy\",\n \"invalid_request\",\n \"idempotency_conflict\",\n \"max_retries_exceeded\",\n ]),\n event_id: postgresUuid.nullable(),\n claim_token: postgresUuid.nullable(),\n })\n .strict()\n .superRefine((row, ctx) => {\n if (row.status === \"claimed\") {\n if (row.event_id === null || row.claim_token === null) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: \"claimed billing event requires event_id and claim_token\",\n });\n }\n return;\n }\n if (row.claim_token !== null) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: \"unclaimed billing event cannot expose a claim_token\",\n });\n }\n if (row.status === \"invalid_request\") {\n if (row.event_id !== null) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: \"invalid billing event request cannot identify a stored event\",\n });\n }\n return;\n }\n if (row.event_id === null) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: \"stored billing event outcome requires event_id\",\n });\n }\n });\n\nexport type BillingEventRow = z.infer<typeof BillingEventRowSchema>;\n\nfunction booleanResult(rows: PostgresValue[], key: string, context: string): boolean {\n return requireResultField(rows, key, pgBoolean, context);\n}\n\n/** Repository for billing event lifecycle operations. */\nexport class BillingEventRepository {\n constructor(private query: QueryFn) {}\n\n /** Claim a billing event for processing (idempotent claim). */\n async claim(\n provider: string,\n eventId: string,\n eventType: string,\n metadata: string,\n ): Promise<BillingEventRow> {\n const rows = await this.query(\"SELECT * FROM bursar.claim_billing_event($1, $2, $3, $4)\", [\n provider,\n eventId,\n eventType,\n metadata,\n ]);\n const row = requireRecordRow(rows, \"BillingEventRepository.claim\");\n return safeParse(\n BillingEventRowSchema,\n { event_id: row.event_id, status: row.result, claim_token: row.claim_token },\n \"BillingEventRepository.claim\",\n { indeterminate: true },\n );\n }\n\n /** Mark a billing event as completed. */\n async complete(provider: string, eventId: string, claimToken: string): Promise<boolean> {\n const rows = await this.query(\n \"SELECT bursar.complete_billing_event($1, $2, $3::uuid) AS completed\",\n [provider, eventId, claimToken],\n );\n return booleanResult(rows, \"completed\", \"BillingEventRepository.complete\");\n }\n\n /** Mark a billing event as failed. */\n async fail(\n provider: string,\n eventId: string,\n claimToken: string,\n error?: string,\n ): Promise<boolean> {\n const rows = await this.query(\n \"SELECT bursar.fail_billing_event($1, $2, $3::uuid, $4) AS failed\",\n [provider, eventId, claimToken, error ?? null],\n );\n return booleanResult(rows, \"failed\", \"BillingEventRepository.fail\");\n }\n}\n"]}
@@ -1,9 +1,10 @@
1
1
  import type { QueryFn } from "../../../shared/postgres-types.js";
2
+ import type { JsonObject } from "../../../shared/json.js";
2
3
  import type { BillingInvoiceRecord } from "../../types/index.js";
3
4
  export declare class BillingInvoiceRepository {
4
5
  private query;
5
6
  constructor(query: QueryFn);
6
7
  listForUser(userId: string): Promise<BillingInvoiceRecord[]>;
7
- upsert(subjectId: string, provider: string, providerInvoiceId: string, subscriptionId: string | null, status: "draft" | "open" | "paid" | "void" | "uncollectible", amountPaidMinor: number, amountDueMinor: number, currency: string, periodStart: string | null, periodEnd: string | null, metadata: Record<string, unknown>, providerUpdatedAt: string): Promise<void>;
8
+ upsert(subjectId: string, provider: string, providerInvoiceId: string, subscriptionId: string | null, status: "draft" | "open" | "paid" | "void" | "uncollectible", amountPaidMinor: number, amountDueMinor: number, currency: string, periodStart: string | null, periodEnd: string | null, metadata: JsonObject, providerUpdatedAt: string): Promise<void>;
8
9
  }
9
10
  //# sourceMappingURL=invoice.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"invoice.d.ts","sourceRoot":"","sources":["../../../../src/billing/postgres/repositories/invoice.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AACjE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAgCjE,qBAAa,wBAAwB;IACvB,OAAO,CAAC,KAAK;gBAAL,KAAK,EAAE,OAAO;IAE5B,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,EAAE,CAAC;IAkC5D,MAAM,CACV,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,iBAAiB,EAAE,MAAM,EACzB,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mBf;CACF"}
@@ -31,19 +31,15 @@ export class BillingInvoiceRepository {
31
31
  async listForUser(userId) {
32
32
  const rows = await this.query(`SELECT * FROM bursar.list_billing_invoices($1::uuid)`, [userId]);
33
33
  return rows.map((row) => {
34
- if (typeof row !== "object" || row === null || Array.isArray(row)) {
35
- throw new TypeError("BillingInvoiceRepository.listForUser expected an object row");
36
- }
37
- const raw = row;
38
34
  const parsed = safeParse(InvoiceRowSchema, {
39
- provider: raw.provider,
40
- provider_invoice_id: raw.provider_invoice_id,
41
- status: raw.status,
42
- amount_paid_minor: raw.amount_paid_minor,
43
- amount_due_minor: raw.amount_due_minor,
44
- currency: raw.currency,
45
- period_start: raw.period_start,
46
- period_end: raw.period_end,
35
+ provider: row.provider,
36
+ provider_invoice_id: row.provider_invoice_id,
37
+ status: row.status,
38
+ amount_paid_minor: row.amount_paid_minor,
39
+ amount_due_minor: row.amount_due_minor,
40
+ currency: row.currency,
41
+ period_start: row.period_start,
42
+ period_end: row.period_end,
47
43
  }, "BillingInvoiceRepository.listForUser");
48
44
  return {
49
45
  provider: parsed.provider,
@@ -1 +1 @@
1
- {"version":3,"file":"invoice.js","sourceRoot":"","sources":["../../../../src/billing/postgres/repositories/invoice.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,SAAS,GACV,MAAM,wCAAwC,CAAC;AAEhD,MAAM,cAAc,GAAG,CAAC;KACrB,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;KACzE,SAAS,CAAC,MAAM,CAAC;KACjB,MAAM,CAAC,MAAM,CAAC,aAAa,EAAE,2DAA2D,CAAC,CAAC;AAC7F,MAAM,iBAAiB,GAAG,CAAC;KACxB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AAC,KAAK,CAC3B,kHAAkH,EAClH;YACE,SAAS;YACT,QAAQ;YACR,iBAAiB;YACjB,cAAc;YACd,MAAM;YACN,cAAc;YACd,eAAe;YACf,QAAQ;YACR,WAAW;YACX,SAAS;YACT,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC;YACxB,iBAAiB;SAClB,CACF,CAAC;QACF,kBAAkB,CAAC,IAAI,EAAE,IAAI,EAAE,YAAY,EAAE,iCAAiC,CAAC,CAAC;IAClF,CAAC;CACF","sourcesContent":["import { z } from \"zod\";\nimport type { QueryFn } from \"../../../shared/postgres-types.js\";\nimport type { BillingInvoiceRecord } from \"../../types/index.js\";\nimport {\n postgresUuid,\n requireResultField,\n safeParse,\n} from \"../../../shared/postgres-validation.js\";\n\nconst safeMinorUnits = z\n .union([z.number().int().nonnegative().safe(), z.string().regex(/^\\d+$/)])\n .transform(Number)\n .refine(Number.isSafeInteger, \"minor-unit amount exceeds JavaScript's safe integer range\");\nconst optionalTimestamp = z\n .union([\n z.date().refine((value) => !Number.isNaN(value.getTime())),\n z.string().datetime({ offset: true }),\n ])\n .transform((value) => (value instanceof Date ? value.toISOString() : value))\n .nullable();\n\nconst InvoiceRowSchema = z\n .object({\n provider: z.string().min(1),\n provider_invoice_id: z.string().min(1),\n status: z.enum([\"draft\", \"open\", \"paid\", \"void\", \"uncollectible\"]),\n amount_paid_minor: safeMinorUnits,\n amount_due_minor: safeMinorUnits,\n currency: z.string().regex(/^[A-Z]{3}$/),\n period_start: optionalTimestamp,\n period_end: optionalTimestamp,\n })\n .strict();\n\nexport class BillingInvoiceRepository {\n constructor(private query: QueryFn) {}\n\n async listForUser(userId: string): Promise<BillingInvoiceRecord[]> {\n const rows = await this.query(`SELECT * FROM bursar.list_billing_invoices($1::uuid)`, [userId]);\n return rows.map((row) => {\n if (typeof row !== \"object\" || row === null || Array.isArray(row)) {\n throw new TypeError(\"BillingInvoiceRepository.listForUser expected an object row\");\n }\n const raw = row as Record<string, unknown>;\n const parsed = safeParse(\n InvoiceRowSchema,\n {\n provider: raw.provider,\n provider_invoice_id: raw.provider_invoice_id,\n status: raw.status,\n amount_paid_minor: raw.amount_paid_minor,\n amount_due_minor: raw.amount_due_minor,\n currency: raw.currency,\n period_start: raw.period_start,\n period_end: raw.period_end,\n },\n \"BillingInvoiceRepository.listForUser\",\n );\n return {\n provider: parsed.provider,\n providerInvoiceId: parsed.provider_invoice_id,\n status: parsed.status,\n amountPaidMinor: parsed.amount_paid_minor,\n amountDueMinor: parsed.amount_due_minor,\n currency: parsed.currency,\n periodStart: parsed.period_start,\n periodEnd: parsed.period_end,\n } satisfies BillingInvoiceRecord;\n });\n }\n\n async upsert(\n subjectId: string,\n provider: string,\n providerInvoiceId: string,\n subscriptionId: string | null,\n status: \"draft\" | \"open\" | \"paid\" | \"void\" | \"uncollectible\",\n amountPaidMinor: number,\n amountDueMinor: number,\n currency: string,\n periodStart: string | null,\n periodEnd: string | null,\n metadata: Record<string, unknown>,\n providerUpdatedAt: string,\n ): Promise<void> {\n const rows = await this.query(\n `SELECT bursar.upsert_billing_invoice($1::uuid, $2, $3, $4::uuid, $5, $6, $7, $8, $9, $10, $11::jsonb, $12) AS id`,\n [\n subjectId,\n provider,\n providerInvoiceId,\n subscriptionId,\n status,\n amountDueMinor,\n amountPaidMinor,\n currency,\n periodStart,\n periodEnd,\n JSON.stringify(metadata),\n providerUpdatedAt,\n ],\n );\n requireResultField(rows, \"id\", postgresUuid, \"BillingInvoiceRepository.upsert\");\n }\n}\n"]}
1
+ {"version":3,"file":"invoice.js","sourceRoot":"","sources":["../../../../src/billing/postgres/repositories/invoice.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,SAAS,GACV,MAAM,wCAAwC,CAAC;AAEhD,MAAM,cAAc,GAAG,CAAC;KACrB,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,E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AAG,MAAM,IAAI,CAAC,KAAK,CAC3B,kHAAkH,EAClH;YACE,SAAS;YACT,QAAQ;YACR,iBAAiB;YACjB,cAAc;YACd,MAAM;YACN,cAAc;YACd,eAAe;YACf,QAAQ;YACR,WAAW;YACX,SAAS;YACT,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC;YACxB,iBAAiB;SAClB,CACF,CAAC;QACF,kBAAkB,CAAC,IAAI,EAAE,IAAI,EAAE,YAAY,EAAE,iCAAiC,CAAC,CAAC;IAClF,CAAC;CACF","sourcesContent":["import { z } from \"zod\";\nimport type { QueryFn } from \"../../../shared/postgres-types.js\";\nimport type { JsonObject } from \"../../../shared/json.js\";\nimport type { BillingInvoiceRecord } from \"../../types/index.js\";\nimport {\n postgresUuid,\n requireResultField,\n safeParse,\n} from \"../../../shared/postgres-validation.js\";\n\nconst safeMinorUnits = z\n .union([z.number().int().nonnegative().safe(), z.string().regex(/^\\d+$/)])\n .transform(Number)\n .refine(Number.isSafeInteger, \"minor-unit amount exceeds JavaScript's safe integer range\");\nconst optionalTimestamp = z\n .union([\n z.date().refine((value) => !Number.isNaN(value.getTime())),\n z.string().datetime({ offset: true }),\n ])\n .transform((value) => (value instanceof Date ? value.toISOString() : value))\n .nullable();\n\nconst InvoiceRowSchema = z\n .object({\n provider: z.string().min(1),\n provider_invoice_id: z.string().min(1),\n status: z.enum([\"draft\", \"open\", \"paid\", \"void\", \"uncollectible\"]),\n amount_paid_minor: safeMinorUnits,\n amount_due_minor: safeMinorUnits,\n currency: z.string().regex(/^[A-Z]{3}$/),\n period_start: optionalTimestamp,\n period_end: optionalTimestamp,\n })\n .strict();\n\nexport class BillingInvoiceRepository {\n constructor(private query: QueryFn) {}\n\n async listForUser(userId: string): Promise<BillingInvoiceRecord[]> {\n const rows = await this.query(`SELECT * FROM bursar.list_billing_invoices($1::uuid)`, [userId]);\n return rows.map((row) => {\n const parsed = safeParse(\n InvoiceRowSchema,\n {\n provider: row.provider,\n provider_invoice_id: row.provider_invoice_id,\n status: row.status,\n amount_paid_minor: row.amount_paid_minor,\n amount_due_minor: row.amount_due_minor,\n currency: row.currency,\n period_start: row.period_start,\n period_end: row.period_end,\n },\n \"BillingInvoiceRepository.listForUser\",\n );\n return {\n provider: parsed.provider,\n providerInvoiceId: parsed.provider_invoice_id,\n status: parsed.status,\n amountPaidMinor: parsed.amount_paid_minor,\n amountDueMinor: parsed.amount_due_minor,\n currency: parsed.currency,\n periodStart: parsed.period_start,\n periodEnd: parsed.period_end,\n } satisfies BillingInvoiceRecord;\n });\n }\n\n async upsert(\n subjectId: string,\n provider: string,\n providerInvoiceId: string,\n subscriptionId: string | null,\n status: \"draft\" | \"open\" | \"paid\" | \"void\" | \"uncollectible\",\n amountPaidMinor: number,\n amountDueMinor: number,\n currency: string,\n periodStart: string | null,\n periodEnd: string | null,\n metadata: JsonObject,\n providerUpdatedAt: string,\n ): Promise<void> {\n const rows = await this.query(\n `SELECT bursar.upsert_billing_invoice($1::uuid, $2, $3, $4::uuid, $5, $6, $7, $8, $9, $10, $11::jsonb, $12) AS id`,\n [\n subjectId,\n provider,\n providerInvoiceId,\n subscriptionId,\n status,\n amountDueMinor,\n amountPaidMinor,\n currency,\n periodStart,\n periodEnd,\n JSON.stringify(metadata),\n providerUpdatedAt,\n ],\n );\n requireResultField(rows, \"id\", postgresUuid, \"BillingInvoiceRepository.upsert\");\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"offer.d.ts","sourceRoot":"","sources":["../../../../src/billing/postgres/repositories/offer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAGrC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAgDjE,UAAU,mBAAmB;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,KAAK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I,CAAC;IACnB,WAAW,EAAE,IAAI,CAAC;IAClB,iBAAiB,EAAE,KAAK,CAAC;CAC1B,GACD;IACE,YAAY,EAAE,OAAO,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,iBAAiB,EAAE,OAAO,CAAC;CAC5B,CACJ,CAAC;AAEJ,+CAA+C;AAC/C,qBAAa,sBAAsB;IACrB,OAAO,CAAC,QAAQ,CAAC,KAAK;IAAlC,YAA6B,KAAK,EAAE,OAAO,EAAI;IAEzC,cAAc,CAClB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,GAAG,IAAI,EACtB,SAAS,EAAE,MAAM,GAAG,IAAI,GACvB,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAGjC;IAEK,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAE1F;YAEa,OAAO;CAuGtB"}
@@ -92,6 +92,11 @@ export class BillingOfferRepository {
92
92
  });
93
93
  }
94
94
  const rawContext = contextRows[0];
95
+ if (rawContext === undefined) {
96
+ throw new StoreError("BillingOfferRepository: catalog plan context is missing", {
97
+ details: { offerId: offer.id, catalogRevisionId: offer.catalog_revision_id },
98
+ });
99
+ }
95
100
  const offerContext = safeParse(OfferContextRowSchema, {
96
101
  offer_key: rawContext.offer_key,
97
102
  plan_id: rawContext.plan_id,
@@ -1 +1 @@
1
- {"version":3,"file":"offer.js","sourceRoot":"","sources":["../../../../src/billing/postgres/repositories/offer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,wCAAwC,CAAC;AAE9F,MAAM,qBAAqB,GAAG,CAAC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,CAAC,OAAO;YAC5B,QAAQ,EAAE,KAAK,CAAC,SAAS;YACzB,IAAI,EAAE,KAAK,CAAC,QAAQ;YACpB,QAAQ,EAAE,KAAK,CAAC,YAAY;YAC5B,aAAa,EAAE,KAAK,CAAC,aAAa;SACnC,CAAC;QACF,IAAI,KAAK,CAAC,kBAAkB,KAAK,IAAI,EAAE,CAAC;YACtC,OAAO;gBACL,GAAG,aAAa;gBAChB,YAAY,EAAE,IAAI;gBAClB,WAAW,EAAE,IAAI;gBACjB,iBAAiB,EAAE,KAAK;aACzB,CAAC;QACJ,CAAC;QACD,IAAI,KAAK,CAAC,sBAAsB,KAAK,IAAI,IAAI,KAAK,CAAC,mBAAmB,KAAK,IAAI,EAAE,CAAC;YAChF,MAAM,IAAI,UAAU,CAAC,GAAG,OAAO,gDAAgD,EAAE;gBAC/E,OAAO,EAAE,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,EAAE,iBAAiB,EAAE,KAAK,CAAC,mBAAmB,EAAE;aAC7E,CAAC,CAAC;QACL,CAAC;QACD,OAAO;YACL,GAAG,aAAa;YAChB,YAAY,EAAE,KAAK,CAAC,kBAAkB;YACtC,WAAW,EAAE,KAAK,CAAC,sBAAsB;YACzC,iBAAiB,EAAE,KAAK,CAAC,mBAAmB,KAAK,kBAAkB;SACpE,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { Decimal } from \"decimal.js\";\nimport { z } from \"zod\";\nimport { StoreError } from \"../../../errors.js\";\nimport type { QueryFn } from \"../../../shared/postgres-types.js\";\nimport { postgresUuid, safeParse, unwrapJsonb } from \"../../../shared/postgres-validation.js\";\n\nconst PositiveDecimalSchema = z\n .union([z.string(), z.number(), z.instanceof(Decimal)])\n .transform((value) => new Decimal(value))\n .refine((value) => value.isFinite() && value.gt(0), \"expected a finite positive decimal\");\n\nconst CatalogOfferRowSchema = z\n .object({\n id: postgresUuid,\n catalog_revision_id: postgresUuid,\n offer_key: z.string().min(1),\n plan_key: z.string().min(1),\n billing_unit: z.enum([\"day\", \"week\", \"month\", \"year\"]),\n billing_count: z.number().int().positive(),\n cycle_grant_amount: PositiveDecimalSchema.nullable(),\n cycle_grant_bucket_key: z.string().min(1).nullable(),\n cycle_grant_renewal: z.enum([\"replace_previous\", \"accumulate\"]).nullable(),\n })\n .strict()\n .superRefine((row, ctx) => {\n const grantFields = [\n row.cycle_grant_amount,\n row.cycle_grant_bucket_key,\n row.cycle_grant_renewal,\n ];\n if (\n grantFields.some((value) => value !== null) &&\n grantFields.some((value) => value === null)\n ) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: \"cycle grant fields must either all be set or all be null\",\n });\n }\n });\n\nconst OfferContextRowSchema = z\n .object({\n offer_key: z.string().min(1),\n plan_id: postgresUuid,\n plan_key: z.string().min(1),\n billing_unit: z.enum([\"day\", \"week\", \"month\", \"year\"]),\n billing_count: z.number().int().positive(),\n })\n .strict();\n\ninterface BillingOfferRowBase {\n id: string;\n planId: string;\n offerKey: string;\n plan: string;\n interval: \"day\" | \"week\" | \"month\" | \"year\";\n intervalCount: number;\n}\n\nexport type BillingOfferRow = BillingOfferRowBase &\n (\n | {\n grantCredits: null;\n grantBucket: null;\n grantReplacePrior: false;\n }\n | {\n grantCredits: Decimal;\n grantBucket: string;\n grantReplacePrior: boolean;\n }\n );\n\n/** Repository for billing offer resolution. */\nexport class BillingOfferRepository {\n constructor(private readonly query: QueryFn) {}\n\n async resolveByPrice(\n provider: string,\n priceId: string | null,\n productId: string | null,\n ): Promise<BillingOfferRow | null> {\n const lookupType = priceId !== null ? \"price_id\" : \"product_id\";\n return this.resolve(provider, lookupType, priceId ?? productId, \"resolveByPrice\");\n }\n\n async resolveByLookup(provider: string, lookupKey: string): Promise<BillingOfferRow | null> {\n return this.resolve(provider, \"external_id\", lookupKey, \"resolveByLookup\");\n }\n\n private async resolve(\n provider: string,\n lookupType: \"price_id\" | \"product_id\" | \"external_id\",\n lookupValue: string | null,\n operation: string,\n ): Promise<BillingOfferRow | null> {\n if (!provider.trim()) throw new TypeError(\"provider must not be empty\");\n if (!lookupValue?.trim()) return null;\n\n const context = `BillingOfferRepository.${operation}`;\n const rows = await this.query(\"SELECT * FROM bursar.resolve_catalog_offer($1, $2, $3)\", [\n provider,\n lookupType,\n lookupValue,\n ]);\n if (rows.length > 1) {\n throw new StoreError(`${context}: expected at most one offer`, {\n details: { rowCount: rows.length },\n });\n }\n const raw = unwrapJsonb(rows);\n if (raw?.id == null) return null;\n const offer = safeParse(\n CatalogOfferRowSchema,\n {\n id: raw.id,\n catalog_revision_id: raw.catalog_revision_id,\n offer_key: raw.offer_key,\n plan_key: raw.plan_key,\n billing_unit: raw.billing_unit,\n billing_count: raw.billing_count,\n cycle_grant_amount: raw.cycle_grant_amount,\n cycle_grant_bucket_key: raw.cycle_grant_bucket_key,\n cycle_grant_renewal: raw.cycle_grant_renewal,\n },\n context,\n );\n\n const contextRows = await this.query(\n \"SELECT * FROM bursar.get_catalog_offer_context($1::uuid, $2::uuid)\",\n [offer.id, offer.catalog_revision_id],\n );\n if (contextRows.length !== 1) {\n throw new StoreError(`${context}: catalog plan context is missing`, {\n details: { offerId: offer.id, catalogRevisionId: offer.catalog_revision_id },\n });\n }\n const rawContext = contextRows[0] as Record<string, unknown>;\n const offerContext = safeParse(\n OfferContextRowSchema,\n {\n offer_key: rawContext.offer_key,\n plan_id: rawContext.plan_id,\n plan_key: rawContext.plan_key,\n billing_unit: rawContext.billing_unit,\n billing_count: rawContext.billing_count,\n },\n `${context}.context`,\n );\n if (\n offerContext.offer_key !== offer.offer_key ||\n offerContext.plan_key !== offer.plan_key ||\n offerContext.billing_unit !== offer.billing_unit ||\n offerContext.billing_count !== offer.billing_count\n ) {\n throw new StoreError(`${context}: catalog plan context does not match the resolved offer`, {\n details: { offerId: offer.id, catalogRevisionId: offer.catalog_revision_id },\n });\n }\n\n const resolvedOffer: BillingOfferRowBase = {\n id: offer.id,\n planId: offerContext.plan_id,\n offerKey: offer.offer_key,\n plan: offer.plan_key,\n interval: offer.billing_unit,\n intervalCount: offer.billing_count,\n };\n if (offer.cycle_grant_amount === null) {\n return {\n ...resolvedOffer,\n grantCredits: null,\n grantBucket: null,\n grantReplacePrior: false,\n };\n }\n if (offer.cycle_grant_bucket_key === null || offer.cycle_grant_renewal === null) {\n throw new StoreError(`${context}: resolved offer has an incomplete cycle grant`, {\n details: { offerId: offer.id, catalogRevisionId: offer.catalog_revision_id },\n });\n }\n return {\n ...resolvedOffer,\n grantCredits: offer.cycle_grant_amount,\n grantBucket: offer.cycle_grant_bucket_key,\n grantReplacePrior: offer.cycle_grant_renewal === \"replace_previous\",\n };\n }\n}\n"]}
1
+ {"version":3,"file":"offer.js","sourceRoot":"","sources":["../../../../src/billing/postgres/repositories/offer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,wCAAwC,CAAC;AAE9F,MAAM,qBAAqB,GAAG,CAAC;KAC5B,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC;KACtD,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC;KACxC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,oCAAoC,CAAC,CAAC;AAE5F,MAAM,qBAAqB,GAAG,CAAC;KAC5B,MAAM,CAAC;IACN,EAAE,EAAE,YAAY;IAChB,mBAAmB,EAAE,YAAY;IACjC,SAAS,EAAE,CAAC,CAAC,MAAM,EAA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AW,EAAE,IAAI;gBACjB,iBAAiB,EAAE,KAAK;aACzB,CAAC;QACJ,CAAC;QACD,IAAI,KAAK,CAAC,sBAAsB,KAAK,IAAI,IAAI,KAAK,CAAC,mBAAmB,KAAK,IAAI,EAAE,CAAC;YAChF,MAAM,IAAI,UAAU,CAAC,GAAG,OAAO,gDAAgD,EAAE;gBAC/E,OAAO,EAAE,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,EAAE,iBAAiB,EAAE,KAAK,CAAC,mBAAmB,EAAE;aAC7E,CAAC,CAAC;QACL,CAAC;QACD,OAAO;YACL,GAAG,aAAa;YAChB,YAAY,EAAE,KAAK,CAAC,kBAAkB;YACtC,WAAW,EAAE,KAAK,CAAC,sBAAsB;YACzC,iBAAiB,EAAE,KAAK,CAAC,mBAAmB,KAAK,kBAAkB;SACpE,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { Decimal } from \"decimal.js\";\nimport { z } from \"zod\";\nimport { StoreError } from \"../../../errors.js\";\nimport type { QueryFn } from \"../../../shared/postgres-types.js\";\nimport { postgresUuid, safeParse, unwrapJsonb } from \"../../../shared/postgres-validation.js\";\n\nconst PositiveDecimalSchema = z\n .union([z.string(), z.number(), z.instanceof(Decimal)])\n .transform((value) => new Decimal(value))\n .refine((value) => value.isFinite() && value.gt(0), \"expected a finite positive decimal\");\n\nconst CatalogOfferRowSchema = z\n .object({\n id: postgresUuid,\n catalog_revision_id: postgresUuid,\n offer_key: z.string().min(1),\n plan_key: z.string().min(1),\n billing_unit: z.enum([\"day\", \"week\", \"month\", \"year\"]),\n billing_count: z.number().int().positive(),\n cycle_grant_amount: PositiveDecimalSchema.nullable(),\n cycle_grant_bucket_key: z.string().min(1).nullable(),\n cycle_grant_renewal: z.enum([\"replace_previous\", \"accumulate\"]).nullable(),\n })\n .strict()\n .superRefine((row, ctx) => {\n const grantFields = [\n row.cycle_grant_amount,\n row.cycle_grant_bucket_key,\n row.cycle_grant_renewal,\n ];\n if (\n grantFields.some((value) => value !== null) &&\n grantFields.some((value) => value === null)\n ) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: \"cycle grant fields must either all be set or all be null\",\n });\n }\n });\n\nconst OfferContextRowSchema = z\n .object({\n offer_key: z.string().min(1),\n plan_id: postgresUuid,\n plan_key: z.string().min(1),\n billing_unit: z.enum([\"day\", \"week\", \"month\", \"year\"]),\n billing_count: z.number().int().positive(),\n })\n .strict();\n\ninterface BillingOfferRowBase {\n id: string;\n planId: string;\n offerKey: string;\n plan: string;\n interval: \"day\" | \"week\" | \"month\" | \"year\";\n intervalCount: number;\n}\n\nexport type BillingOfferRow = BillingOfferRowBase &\n (\n | {\n grantCredits: null;\n grantBucket: null;\n grantReplacePrior: false;\n }\n | {\n grantCredits: Decimal;\n grantBucket: string;\n grantReplacePrior: boolean;\n }\n );\n\n/** Repository for billing offer resolution. */\nexport class BillingOfferRepository {\n constructor(private readonly query: QueryFn) {}\n\n async resolveByPrice(\n provider: string,\n priceId: string | null,\n productId: string | null,\n ): Promise<BillingOfferRow | null> {\n const lookupType = priceId !== null ? \"price_id\" : \"product_id\";\n return this.resolve(provider, lookupType, priceId ?? productId, \"resolveByPrice\");\n }\n\n async resolveByLookup(provider: string, lookupKey: string): Promise<BillingOfferRow | null> {\n return this.resolve(provider, \"external_id\", lookupKey, \"resolveByLookup\");\n }\n\n private async resolve(\n provider: string,\n lookupType: \"price_id\" | \"product_id\" | \"external_id\",\n lookupValue: string | null,\n operation: string,\n ): Promise<BillingOfferRow | null> {\n if (!provider.trim()) throw new TypeError(\"provider must not be empty\");\n if (!lookupValue?.trim()) return null;\n\n const context = `BillingOfferRepository.${operation}`;\n const rows = await this.query(\"SELECT * FROM bursar.resolve_catalog_offer($1, $2, $3)\", [\n provider,\n lookupType,\n lookupValue,\n ]);\n if (rows.length > 1) {\n throw new StoreError(`${context}: expected at most one offer`, {\n details: { rowCount: rows.length },\n });\n }\n const raw = unwrapJsonb(rows);\n if (raw?.id == null) return null;\n const offer = safeParse(\n CatalogOfferRowSchema,\n {\n id: raw.id,\n catalog_revision_id: raw.catalog_revision_id,\n offer_key: raw.offer_key,\n plan_key: raw.plan_key,\n billing_unit: raw.billing_unit,\n billing_count: raw.billing_count,\n cycle_grant_amount: raw.cycle_grant_amount,\n cycle_grant_bucket_key: raw.cycle_grant_bucket_key,\n cycle_grant_renewal: raw.cycle_grant_renewal,\n },\n context,\n );\n\n const contextRows = await this.query(\n \"SELECT * FROM bursar.get_catalog_offer_context($1::uuid, $2::uuid)\",\n [offer.id, offer.catalog_revision_id],\n );\n if (contextRows.length !== 1) {\n throw new StoreError(`${context}: catalog plan context is missing`, {\n details: { offerId: offer.id, catalogRevisionId: offer.catalog_revision_id },\n });\n }\n const rawContext = contextRows[0];\n if (rawContext === undefined) {\n throw new StoreError(\"BillingOfferRepository: catalog plan context is missing\", {\n details: { offerId: offer.id, catalogRevisionId: offer.catalog_revision_id },\n });\n }\n const offerContext = safeParse(\n OfferContextRowSchema,\n {\n offer_key: rawContext.offer_key,\n plan_id: rawContext.plan_id,\n plan_key: rawContext.plan_key,\n billing_unit: rawContext.billing_unit,\n billing_count: rawContext.billing_count,\n },\n `${context}.context`,\n );\n if (\n offerContext.offer_key !== offer.offer_key ||\n offerContext.plan_key !== offer.plan_key ||\n offerContext.billing_unit !== offer.billing_unit ||\n offerContext.billing_count !== offer.billing_count\n ) {\n throw new StoreError(`${context}: catalog plan context does not match the resolved offer`, {\n details: { offerId: offer.id, catalogRevisionId: offer.catalog_revision_id },\n });\n }\n\n const resolvedOffer: BillingOfferRowBase = {\n id: offer.id,\n planId: offerContext.plan_id,\n offerKey: offer.offer_key,\n plan: offer.plan_key,\n interval: offer.billing_unit,\n intervalCount: offer.billing_count,\n };\n if (offer.cycle_grant_amount === null) {\n return {\n ...resolvedOffer,\n grantCredits: null,\n grantBucket: null,\n grantReplacePrior: false,\n };\n }\n if (offer.cycle_grant_bucket_key === null || offer.cycle_grant_renewal === null) {\n throw new StoreError(`${context}: resolved offer has an incomplete cycle grant`, {\n details: { offerId: offer.id, catalogRevisionId: offer.catalog_revision_id },\n });\n }\n return {\n ...resolvedOffer,\n grantCredits: offer.cycle_grant_amount,\n grantBucket: offer.cycle_grant_bucket_key,\n grantReplacePrior: offer.cycle_grant_renewal === \"replace_previous\",\n };\n }\n}\n"]}
@@ -10,17 +10,17 @@ declare const BillingPaymentRowSchema: z.ZodObject<{
10
10
  tax_minor: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
11
11
  currency: z.ZodString;
12
12
  purpose: z.ZodEnum<{
13
- subscription: "subscription";
14
13
  credit_topup: "credit_topup";
14
+ subscription: "subscription";
15
15
  }>;
16
16
  status: z.ZodEnum<{
17
+ canceled: "canceled";
18
+ failed: "failed";
17
19
  pending: "pending";
18
20
  succeeded: "succeeded";
19
- failed: "failed";
20
- canceled: "canceled";
21
21
  }>;
22
22
  provider_updated_at: z.ZodUnion<readonly [z.ZodString, z.ZodDate]>;
23
- metadata: z.ZodRecord<z.ZodString, z.ZodUnknown>;
23
+ metadata: z.ZodRecord<z.ZodString, z.ZodJSONSchema>;
24
24
  }, z.core.$strict>;
25
25
  export type BillingPaymentRow = z.infer<typeof BillingPaymentRowSchema>;
26
26
  export type ForRefundRow = BillingPaymentRow;
@@ -1 +1 @@
1
- {"version":3,"file":"payment.d.ts","sourceRoot":"","sources":["../../../../src/billing/postgres/repositories/payment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAajE,QAAA,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;kBAelB,CAAC;AACZ,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AACxE,MAAM,MAAM,YAAY,GAAG,iBAAiB,CAAC;AAuB7C,qBAAa,wBAAwB;IACvB,OAAO,CAAC,KAAK;gBAAL,KAAK,EAAE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AE,MAAM,EACnB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,cAAc,GAAG,cAAc,EACxC,QAAQ,EAAE,MAAM,GAAG,IAAI,EACvB,MAAM,EAAE,SAAS,GAAG,WAAW,GAAG,QAAQ,GAAG,UAAU,EACvD,iBAAiB,EAAE,MAAM,GACxB,OAAO,CAAC,MAAM,CAAC,CAwBjB;IACK,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAO5F;IACK,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAO9F;CACF"}
@@ -17,7 +17,7 @@ const BillingPaymentRowSchema = z
17
17
  purpose: z.enum(["subscription", "credit_topup"]),
18
18
  status: z.enum(["pending", "succeeded", "failed", "canceled"]),
19
19
  provider_updated_at: z.union([z.string().datetime({ offset: true }), z.date()]),
20
- metadata: z.record(z.string(), z.unknown()),
20
+ metadata: z.record(z.string(), z.json()),
21
21
  })
22
22
  .strict();
23
23
  function parsePaymentRow(row, context) {
@@ -1 +1 @@
1
- {"version":3,"file":"payment.js","sourceRoot":"","sources":["../../../../src/billing/postgres/repositories/payment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EACL,iBAAiB,EACjB,YAAY,EACZ,kBAAkB,EAClB,SAAS,GACV,MAAM,wCAAwC,CAAC;AAEhD,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC;IACrC,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC;IACzB,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE;CACtC,CAAC,CAAC;AAEH,MAAM,uBAAuB,GAAG,CAA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BAAiB,CAAC,IAAI,EAAE,uCAAuC,CAAC,CAAC;QAC7E,OAAO,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,eAAe,CAAC,GAAG,EAAE,uCAAuC,CAAC,CAAC;IAC7F,CAAC;IACD,KAAK,CAAC,SAAS,CAAC,QAAgB,EAAE,iBAAyB;QACzD,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,6DAA6D,EAAE;YAC3F,QAAQ;YACR,iBAAiB;SAClB,CAAC,CAAC;QACH,MAAM,GAAG,GAAG,iBAAiB,CAAC,IAAI,EAAE,oCAAoC,CAAC,CAAC;QAC1E,OAAO,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,eAAe,CAAC,GAAG,EAAE,oCAAoC,CAAC,CAAC;IAC1F,CAAC;CACF","sourcesContent":["import { z } from \"zod\";\nimport type { QueryFn } from \"../../../shared/postgres-types.js\";\nimport {\n optionalRecordRow,\n postgresUuid,\n requireResultField,\n safeParse,\n} from \"../../../shared/postgres-validation.js\";\n\nconst PgSafeMinorUnitsSchema = z.union([\n z.string().regex(/^\\d+$/),\n z.number().int().nonnegative().safe(),\n]);\n\nconst BillingPaymentRowSchema = z\n .object({\n id: postgresUuid,\n provider: z.string().min(1),\n provider_payment_id: z.string().min(1),\n provider_invoice_id: z.string().nullable(),\n subject_id: postgresUuid,\n amount_minor: PgSafeMinorUnitsSchema,\n tax_minor: PgSafeMinorUnitsSchema,\n currency: z.string().regex(/^[A-Z]{3}$/),\n purpose: z.enum([\"subscription\", \"credit_topup\"]),\n status: z.enum([\"pending\", \"succeeded\", \"failed\", \"canceled\"]),\n provider_updated_at: z.union([z.string().datetime({ offset: true }), z.date()]),\n metadata: z.record(z.string(), z.unknown()),\n })\n .strict();\nexport type BillingPaymentRow = z.infer<typeof BillingPaymentRowSchema>;\nexport type ForRefundRow = BillingPaymentRow;\n\nfunction parsePaymentRow(row: Record<string, unknown>, context: string): BillingPaymentRow {\n return safeParse(\n BillingPaymentRowSchema,\n {\n id: row.id,\n provider: row.provider,\n provider_payment_id: row.provider_payment_id,\n provider_invoice_id: row.provider_invoice_id,\n subject_id: row.subject_id,\n amount_minor: row.amount_minor,\n tax_minor: row.tax_minor,\n currency: row.currency,\n purpose: row.purpose,\n status: row.status,\n provider_updated_at: row.provider_updated_at,\n metadata: row.metadata,\n },\n context,\n );\n}\n\nexport class BillingPaymentRepository {\n constructor(private query: QueryFn) {}\n async upsert(\n provider: string,\n providerPaymentId: string,\n providerInvoiceId: string | null,\n userId: string,\n amountMinor: number,\n taxMinor: number,\n currency: string,\n purpose: \"subscription\" | \"credit_topup\",\n metadata: string | null,\n status: \"pending\" | \"succeeded\" | \"failed\" | \"canceled\",\n providerUpdatedAt: string,\n ): Promise<string> {\n if (!userId) throw new TypeError(\"billing payment requires a subject\");\n if (purpose !== \"subscription\" && purpose !== \"credit_topup\") {\n throw new TypeError(\"billing payment requires a known purpose\");\n }\n const rows = await this.query(\n `SELECT bursar.upsert_billing_payment(\n $1::uuid,$2,$3,$4,$5,$6,$7,$8::bursar.billing_payment_status,$9,$10,$11::jsonb\n ) AS id`,\n [\n userId,\n provider,\n providerPaymentId,\n amountMinor,\n taxMinor,\n currency,\n purpose,\n status,\n providerUpdatedAt,\n providerInvoiceId,\n metadata ?? \"{}\",\n ],\n );\n return requireResultField(rows, \"id\", postgresUuid, \"BillingPaymentRepository.upsert\");\n }\n async getForRefund(provider: string, providerPaymentId: string): Promise<ForRefundRow | null> {\n const rows = await this.query(\"SELECT * FROM bursar.get_billing_payment_by_provider($1,$2)\", [\n provider,\n providerPaymentId,\n ]);\n const row = optionalRecordRow(rows, \"BillingPaymentRepository.getForRefund\");\n return row === null ? null : parsePaymentRow(row, \"BillingPaymentRepository.getForRefund\");\n }\n async getDirect(provider: string, providerPaymentId: string): Promise<BillingPaymentRow | null> {\n const rows = await this.query(\"SELECT * FROM bursar.get_billing_payment_by_provider($1,$2)\", [\n provider,\n providerPaymentId,\n ]);\n const row = optionalRecordRow(rows, \"BillingPaymentRepository.getDirect\");\n return row === null ? null : parsePaymentRow(row, \"BillingPaymentRepository.getDirect\");\n }\n}\n"]}
1
+ {"version":3,"file":"payment.js","sourceRoot":"","sources":["../../../../src/billing/postgres/repositories/payment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EACL,iBAAiB,EACjB,YAAY,EACZ,kBAAkB,EAClB,SAAS,GACV,MAAM,wCAAwC,CAAC;AAEhD,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC;IACrC,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC;IACzB,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE;CACtC,CAAC,CAAC;AAEH,MAAM,uBAAuB,GAAG,CAAC;KAC9B,MAAM,CAAC;IACN,EAAE,EAAE,YAAY;IAChB,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC3B,mBAAmB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACtC,mBAAmB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC1C,UAAU,EAAE,YAAY;IACxB,YAAY,EAAE,sBAAsB;IACpC,SAAS,EAAE,sBAAsB;IACjC,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,YAAY,CAAC;IACxC,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC;IACjD,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC;IAC9D,mBAAmB,EAAE,CAAC,CAAC,KAAK,CAAC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AE,CAAC;YAC7D,MAAM,IAAI,SAAS,CAAC,0CAA0C,CAAC,CAAC;QAClE,CAAC;QACD,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,KAAK,CAC3B;;eAES,EACT;YACE,MAAM;YACN,QAAQ;YACR,iBAAiB;YACjB,WAAW;YACX,QAAQ;YACR,QAAQ;YACR,OAAO;YACP,MAAM;YACN,iBAAiB;YACjB,iBAAiB;YACjB,QAAQ,IAAI,IAAI;SACjB,CACF,CAAC;QACF,OAAO,kBAAkB,CAAC,IAAI,EAAE,IAAI,EAAE,YAAY,EAAE,iCAAiC,CAAC,CAAC;IACzF,CAAC;IACD,KAAK,CAAC,YAAY,CAAC,QAAgB,EAAE,iBAAyB;QAC5D,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,6DAA6D,EAAE;YAC3F,QAAQ;YACR,iBAAiB;SAClB,CAAC,CAAC;QACH,MAAM,GAAG,GAAG,iBAAiB,CAAC,IAAI,EAAE,uCAAuC,CAAC,CAAC;QAC7E,OAAO,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,eAAe,CAAC,GAAG,EAAE,uCAAuC,CAAC,CAAC;IAC7F,CAAC;IACD,KAAK,CAAC,SAAS,CAAC,QAAgB,EAAE,iBAAyB;QACzD,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,6DAA6D,EAAE;YAC3F,QAAQ;YACR,iBAAiB;SAClB,CAAC,CAAC;QACH,MAAM,GAAG,GAAG,iBAAiB,CAAC,IAAI,EAAE,oCAAoC,CAAC,CAAC;QAC1E,OAAO,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,eAAe,CAAC,GAAG,EAAE,oCAAoC,CAAC,CAAC;IAC1F,CAAC;CACF","sourcesContent":["import { z } from \"zod\";\nimport type { QueryFn } from \"../../../shared/postgres-types.js\";\nimport type { PostgresRow } from \"../../../shared/json.js\";\nimport {\n optionalRecordRow,\n postgresUuid,\n requireResultField,\n safeParse,\n} from \"../../../shared/postgres-validation.js\";\n\nconst PgSafeMinorUnitsSchema = z.union([\n z.string().regex(/^\\d+$/),\n z.number().int().nonnegative().safe(),\n]);\n\nconst BillingPaymentRowSchema = z\n .object({\n id: postgresUuid,\n provider: z.string().min(1),\n provider_payment_id: z.string().min(1),\n provider_invoice_id: z.string().nullable(),\n subject_id: postgresUuid,\n amount_minor: PgSafeMinorUnitsSchema,\n tax_minor: PgSafeMinorUnitsSchema,\n currency: z.string().regex(/^[A-Z]{3}$/),\n purpose: z.enum([\"subscription\", \"credit_topup\"]),\n status: z.enum([\"pending\", \"succeeded\", \"failed\", \"canceled\"]),\n provider_updated_at: z.union([z.string().datetime({ offset: true }), z.date()]),\n metadata: z.record(z.string(), z.json()),\n })\n .strict();\nexport type BillingPaymentRow = z.infer<typeof BillingPaymentRowSchema>;\nexport type ForRefundRow = BillingPaymentRow;\n\nfunction parsePaymentRow(row: PostgresRow, context: string): BillingPaymentRow {\n return safeParse(\n BillingPaymentRowSchema,\n {\n id: row.id,\n provider: row.provider,\n provider_payment_id: row.provider_payment_id,\n provider_invoice_id: row.provider_invoice_id,\n subject_id: row.subject_id,\n amount_minor: row.amount_minor,\n tax_minor: row.tax_minor,\n currency: row.currency,\n purpose: row.purpose,\n status: row.status,\n provider_updated_at: row.provider_updated_at,\n metadata: row.metadata,\n },\n context,\n );\n}\n\nexport class BillingPaymentRepository {\n constructor(private query: QueryFn) {}\n async upsert(\n provider: string,\n providerPaymentId: string,\n providerInvoiceId: string | null,\n userId: string,\n amountMinor: number,\n taxMinor: number,\n currency: string,\n purpose: \"subscription\" | \"credit_topup\",\n metadata: string | null,\n status: \"pending\" | \"succeeded\" | \"failed\" | \"canceled\",\n providerUpdatedAt: string,\n ): Promise<string> {\n if (!userId) throw new TypeError(\"billing payment requires a subject\");\n if (purpose !== \"subscription\" && purpose !== \"credit_topup\") {\n throw new TypeError(\"billing payment requires a known purpose\");\n }\n const rows = await this.query(\n `SELECT bursar.upsert_billing_payment(\n $1::uuid,$2,$3,$4,$5,$6,$7,$8::bursar.billing_payment_status,$9,$10,$11::jsonb\n ) AS id`,\n [\n userId,\n provider,\n providerPaymentId,\n amountMinor,\n taxMinor,\n currency,\n purpose,\n status,\n providerUpdatedAt,\n providerInvoiceId,\n metadata ?? \"{}\",\n ],\n );\n return requireResultField(rows, \"id\", postgresUuid, \"BillingPaymentRepository.upsert\");\n }\n async getForRefund(provider: string, providerPaymentId: string): Promise<ForRefundRow | null> {\n const rows = await this.query(\"SELECT * FROM bursar.get_billing_payment_by_provider($1,$2)\", [\n provider,\n providerPaymentId,\n ]);\n const row = optionalRecordRow(rows, \"BillingPaymentRepository.getForRefund\");\n return row === null ? null : parsePaymentRow(row, \"BillingPaymentRepository.getForRefund\");\n }\n async getDirect(provider: string, providerPaymentId: string): Promise<BillingPaymentRow | null> {\n const rows = await this.query(\"SELECT * FROM bursar.get_billing_payment_by_provider($1,$2)\", [\n provider,\n providerPaymentId,\n ]);\n const row = optionalRecordRow(rows, \"BillingPaymentRepository.getDirect\");\n return row === null ? null : parsePaymentRow(row, \"BillingPaymentRepository.getDirect\");\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"preferences.d.ts","sourceRoot":"","sources":["../../../../src/billing/postgres/repositories/preferences.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAEjE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAoB/D,qBAAa,4BAA4B;IAC3B,OAAO,CAAC,KAAK;gBAAL,KAAK,EAAE,OAAO;IAE5B,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;IA8BvD,MAAM,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;CAwBvD"}
1
+ {"version":3,"file":"preferences.d.ts","sourceRoot":"","sources":["../../../../src/billing/postgres/repositories/preferences.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAEjE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAoB/D,qBAAa,4BAA4B;IAC3B,OAAO,CAAC,KAAK;IAAzB,YAAoB,KAAK,EAAE,OAAO,EAAI;IAEhC,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC,CA4B5D;IAEK,MAAM,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAuBrD;CACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"preferences.js","sourceRoot":"","sources":["../../../../src/billing/postgres/repositories/preferences.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EACL,iBAAiB,EACjB,SAAS,EACT,YAAY,EACZ,kBAAkB,EAClB,SAAS,GACV,MAAM,wCAAwC,CAAC;AAEhD,MAAM,2BAA2B,GAAG,CAAC;KAClC,MAAM,CAAC;IACN,UAAU,EAAE,YAAY;IACxB,aAAa,EAAE,SAAS;IACxB,kBAAkB,EAAE,SAAS;IAC7B,mBAAmB,EAAE,SAAS;IAC9B,YAAY,EAAE,SAAS;IACvB,iBAAiB,EAAE,SAAS;CAC7B,CAAC;KACD,MAAM,EAAE,CAAC;AAEZ,MAAM,OAAO,4BAA4B;IACnB;IAApB,YAAoB,KAAc;QAAd,UAAK,GAAL,KAAK,CAAS;IAAG,CAAC;IAEtC,KAAK,CAAC,GAAG,CAAC,MAAc;QACtB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,wDAAwD,EAAE;YACtF,MAAM;SACP,CAAC,CAAC;QACH,MAAM,GAAG,GAAG,iBAAiB,CA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\";\nimport type { QueryFn } from \"../../../shared/postgres-types.js\";\nimport { StoreError } from \"../../../errors.js\";\nimport type { BillingPreferences } from \"../../types/index.js\";\nimport {\n optionalRecordRow,\n pgBoolean,\n postgresUuid,\n requireResultField,\n safeParse,\n} from \"../../../shared/postgres-validation.js\";\n\nconst BillingPreferencesRowSchema = z\n .object({\n subject_id: postgresUuid,\n auto_recharge: pgBoolean,\n overage_protection: pgBoolean,\n email_notifications: pgBoolean,\n usage_alerts: pgBoolean,\n invoice_reminders: pgBoolean,\n })\n .strict();\n\nexport class BillingPreferencesRepository {\n constructor(private query: QueryFn) {}\n\n async get(userId: string): Promise<BillingPreferences | null> {\n const rows = await this.query(\"SELECT * FROM bursar.get_billing_preferences($1::uuid)\", [\n userId,\n ]);\n const row = optionalRecordRow(rows, \"BillingPreferencesRepository.get\");\n if (row === null) {\n return null;\n }\n const parsed = safeParse(\n BillingPreferencesRowSchema,\n {\n subject_id: row.subject_id,\n auto_recharge: row.auto_recharge,\n overage_protection: row.overage_protection,\n email_notifications: row.email_notifications,\n usage_alerts: row.usage_alerts,\n invoice_reminders: row.invoice_reminders,\n },\n \"BillingPreferencesRepository.get\",\n );\n return {\n userId: parsed.subject_id,\n autoRecharge: parsed.auto_recharge,\n overageProtection: parsed.overage_protection,\n emailNotifications: parsed.email_notifications,\n usageAlerts: parsed.usage_alerts,\n invoiceReminders: parsed.invoice_reminders,\n };\n }\n\n async upsert(prefs: BillingPreferences): Promise<void> {\n const rows = await this.query(\n \"SELECT bursar.upsert_billing_preferences($1::uuid, $2, $3, $4, $5, $6) AS updated\",\n [\n prefs.userId,\n prefs.autoRecharge,\n prefs.overageProtection,\n prefs.emailNotifications,\n prefs.usageAlerts,\n prefs.invoiceReminders,\n ],\n );\n const updated = requireResultField(\n rows,\n \"updated\",\n pgBoolean,\n \"BillingPreferencesRepository.upsert\",\n );\n if (!updated) {\n throw new StoreError(\"BillingPreferencesRepository.upsert: update was rejected\", {\n indeterminate: true,\n });\n }\n }\n}\n"]}
1
+ {"version":3,"file":"preferences.js","sourceRoot":"","sources":["../../../../src/billing/postgres/repositories/preferences.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EACL,iBAAiB,EACjB,SAAS,EACT,YAAY,EACZ,kBAAkB,EAClB,SAAS,GACV,MAAM,wCAAwC,CAAC;AAEhD,MAAM,2BAA2B,GAAG,CAAC;KAClC,MAAM,CAAC;IACN,UAAU,EAAE,YAAY;IACxB,aAAa,EAAE,SAAS;IACxB,kBAAkB,EAAE,SAAS;IAC7B,mBAAmB,EAAE,SAAS;IAC9B,YAAY,EAAE,SAAS;IACvB,iBAAiB,EAAE,SAAS;CAC7B,CAAC;KACD,MAAM,EAAE,CAAC;AAEZ,MAAM,OAAO,4BAA4B;IACnB,KAAK;IAAzB,YAAoB,KAAc;qBAAd,KAAK;IAAY,CAAC;IAEtC,KAAK,CAAC,GAAG,CAAC,MAAc;QACtB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,wDAAwD,EAAE;YACtF,MAAM;SACP,CAAC,CAAC;QACH,MAAM,GAAG,GAAG,iBAAiB,CAAC,IAAI,EAAE,kCAAkC,CAAC,CAAC;QACxE,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;YACjB,OAAO,IAAI,CAAC;QACd,CAAC;QACD,MAAM,MAAM,GAAG,SAAS,CACtB,2BAA2B,EAC3B;YACE,UAAU,EAAE,GAAG,CAAC,UAAU;YAC1B,aAAa,EAAE,GAAG,CAAC,aAAa;YAChC,kBAAkB,EAAE,GAAG,CAAC,kBAAkB;YAC1C,mBAAmB,EAAE,GAAG,CAAC,mBAAmB;YAC5C,YAAY,EAAE,GAAG,CAAC,YAAY;YAC9B,iBAAiB,EAAE,GAAG,CAAC,iBAAiB;SACzC,EACD,kCAAkC,CACnC,CAAC;QACF,OAAO;YACL,MAAM,EAAE,MAAM,CAAC,UAAU;YACzB,YAAY,EAAE,MAAM,CAAC,aAAa;YAClC,iBAAiB,EAAE,MAAM,CAAC,kBAAkB;YAC5C,kBAAkB,EAAE,MAAM,CAAC,mBAAmB;YAC9C,WAAW,EAAE,MAAM,CAAC,YAAY;YAChC,gBAAgB,EAAE,MAAM,CAAC,iBAAiB;SAC3C,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,KAAyB;QACpC,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,KAAK,CAC3B,mFAAmF,EACnF;YACE,KAAK,CAAC,MAAM;YACZ,KAAK,CAAC,YAAY;YAClB,KAAK,CAAC,iBAAiB;YACvB,KAAK,CAAC,kBAAkB;YACxB,KAAK,CAAC,WAAW;YACjB,KAAK,CAAC,gBAAgB;SACvB,CACF,CAAC;QACF,MAAM,OAAO,GAAG,kBAAkB,CAChC,IAAI,EACJ,SAAS,EACT,SAAS,EACT,qCAAqC,CACtC,CAAC;QACF,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,UAAU,CAAC,0DAA0D,EAAE;gBAC/E,aAAa,EAAE,IAAI;aACpB,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF","sourcesContent":["import { z } from \"zod\";\nimport type { QueryFn } from \"../../../shared/postgres-types.js\";\nimport { StoreError } from \"../../../errors.js\";\nimport type { BillingPreferences } from \"../../types/index.js\";\nimport {\n optionalRecordRow,\n pgBoolean,\n postgresUuid,\n requireResultField,\n safeParse,\n} from \"../../../shared/postgres-validation.js\";\n\nconst BillingPreferencesRowSchema = z\n .object({\n subject_id: postgresUuid,\n auto_recharge: pgBoolean,\n overage_protection: pgBoolean,\n email_notifications: pgBoolean,\n usage_alerts: pgBoolean,\n invoice_reminders: pgBoolean,\n })\n .strict();\n\nexport class BillingPreferencesRepository {\n constructor(private query: QueryFn) {}\n\n async get(userId: string): Promise<BillingPreferences | null> {\n const rows = await this.query(\"SELECT * FROM bursar.get_billing_preferences($1::uuid)\", [\n userId,\n ]);\n const row = optionalRecordRow(rows, \"BillingPreferencesRepository.get\");\n if (row === null) {\n return null;\n }\n const parsed = safeParse(\n BillingPreferencesRowSchema,\n {\n subject_id: row.subject_id,\n auto_recharge: row.auto_recharge,\n overage_protection: row.overage_protection,\n email_notifications: row.email_notifications,\n usage_alerts: row.usage_alerts,\n invoice_reminders: row.invoice_reminders,\n },\n \"BillingPreferencesRepository.get\",\n );\n return {\n userId: parsed.subject_id,\n autoRecharge: parsed.auto_recharge,\n overageProtection: parsed.overage_protection,\n emailNotifications: parsed.email_notifications,\n usageAlerts: parsed.usage_alerts,\n invoiceReminders: parsed.invoice_reminders,\n };\n }\n\n async upsert(prefs: BillingPreferences): Promise<void> {\n const rows = await this.query(\n \"SELECT bursar.upsert_billing_preferences($1::uuid, $2, $3, $4, $5, $6) AS updated\",\n [\n prefs.userId,\n prefs.autoRecharge,\n prefs.overageProtection,\n prefs.emailNotifications,\n prefs.usageAlerts,\n prefs.invoiceReminders,\n ],\n );\n const updated = requireResultField(\n rows,\n \"updated\",\n pgBoolean,\n \"BillingPreferencesRepository.upsert\",\n );\n if (!updated) {\n throw new StoreError(\"BillingPreferencesRepository.upsert: update was rejected\", {\n indeterminate: true,\n });\n }\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"refund.d.ts","sourceRoot":"","sources":["../../../../src/billing/postgres/repositories/refund.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAQjE,qBAAa,uBAAuB;IACtB,OAAO,CAAC,KAAK;gBAAL,KAAK,EAAE,OAAO;IAE5B,MAAM,CACV,QAAQ,EAAE,MAAM,EAChB,gBAAgB,EAAE,MAAM,EACxB,iBAAiB,EAAE,MAAM,EACzB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,GAAG,IAAI,EACrB,QAAQ,EAAE,MAAM,GAAG,IAAI,EACvB,MAAM,EAAE,MAAM,EACd,iBAAiB,EAAE,MAAM,GACxB,OAAO,CAAC,MAAM,CAAC;CAoCnB"}
1
+ {"version":3,"file":"refund.d.ts","sourceRoot":"","sources":["../../../../src/billing/postgres/repositories/refund.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAQjE,qBAAa,uBAAuB;IACtB,OAAO,CAAC,KAAK;IAAzB,YAAoB,KAAK,EAAE,OAAO,EAAI;IAEhC,MAAM,CACV,QAAQ,EAAE,MAAM,EAChB,gBAAgB,EAAE,MAAM,EACxB,iBAAiB,EAAE,MAAM,EACzB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,GAAG,IAAI,EACrB,QAAQ,EAAE,MAAM,GAAG,IAAI,EACvB,MAAM,EAAE,MAAM,EACd,iBAAiB,EAAE,MAAM,GACxB,OAAO,CAAC,MAAM,CAAC,CAmCjB;CACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"refund.js","sourceRoot":"","sources":["../../../../src/billing/postgres/repositories/refund.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EACL,iBAAiB,EACjB,YAAY,EACZ,kBAAkB,EAClB,SAAS,GACV,MAAM,wCAAwC,CAAC;AAEhD,MAAM,OAAO,uBAAuB;IACd;IAApB,YAAoB,KAAc;QAAd,UAAK,GAAL,KAAK,CAAS;IAAG,CAAC;IAEtC,KAAK,CAAC,MAAM,CACV,QAAgB,EAChB,gBAAwB,EACxB,iBAAyB,EACzB,MAAc,EACd,WAAmB,EACnB,QAAgB,EAChB,MAAqB,EACrB,QAAuB,EACvB,MAAc,EACd,iBAAyB;QAEzB,IAAI,CAAC,iBAAiB;YAAE,MAAM,IAAI,SAAS,CAAC,mCAAmC,CAAC,CAAC;QACjF,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,KAAK,CAC/B,8DAA8D,EAC9D,CAAC,QAAQ,EAAE,iBAAiB,CAAC,CAC9B,CAAC;QACF,MAAM,OAAO,GAAG,iBAAiB,CAAC,QAAQ,EAAE,wCAAwC,CAAC,CAAC;QACtF,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;YACrB,MAAM,IAAI,UAAU,CAAC,0BAA0B,EAAE;gBAC/C,SAAS,EAAE,IAAI;gBACf,OAAO,EAAE,EAAE,QAAQ,EAAE,iBAAiB,EAAE;aACzC,CAAC,CAAC;QACL,CAAC;QACD,MAAM,SAAS,GAAG,SAAS,CACzB,YAAY,EACZ,OAAO,CAAC,EAAE,EACV,2CAA2C,CAC5C,CAAC;QACF,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,KAAK,CAC3B;;eAES,EACT;YACE,SAAS;YACT,gBAAgB;YAChB,WAAW;YACX,MAAM;YACN,MAAM;YACN,iBAAiB;YACjB,MAAM;YACN,QAAQ;YACR,QAAQ,IAAI,IAAI;SACjB,CACF,CAAC;QACF,OAAO,kBAAkB,CAAC,IAAI,EAAE,IAAI,EAAE,YAAY,EAAE,gCAAgC,CAAC,CAAC;IACxF,CAAC;CACF","sourcesContent":["import { StoreError } from \"../../../errors.js\";\nimport type { QueryFn } from \"../../../shared/postgres-types.js\";\nimport {\n optionalRecordRow,\n postgresUuid,\n requireResultField,\n safeParse,\n} from \"../../../shared/postgres-validation.js\";\n\nexport class BillingRefundRepository {\n constructor(private query: QueryFn) {}\n\n async upsert(\n provider: string,\n providerRefundId: string,\n providerPaymentId: string,\n userId: string,\n amountMinor: number,\n currency: string,\n reason: string | null,\n metadata: string | null,\n status: string,\n providerUpdatedAt: string,\n ): Promise<string> {\n if (!providerPaymentId) throw new TypeError(\"refund requires providerPaymentId\");\n const payments = await this.query(\n \"SELECT * FROM bursar.get_billing_payment_by_provider($1, $2)\",\n [provider, providerPaymentId],\n );\n const payment = optionalRecordRow(payments, \"BillingRefundRepository.upsert.payment\");\n if (payment === null) {\n throw new StoreError(\"refund payment not found\", {\n retryable: true,\n details: { provider, providerPaymentId },\n });\n }\n const paymentId = safeParse(\n postgresUuid,\n payment.id,\n \"BillingRefundRepository.upsert.payment.id\",\n );\n const rows = await this.query(\n `SELECT bursar.upsert_billing_refund(\n $1::uuid, $2, $3, $4, $5, $6, $7::uuid, $8::char(3), $9::jsonb\n ) AS id`,\n [\n paymentId,\n providerRefundId,\n amountMinor,\n status,\n reason,\n providerUpdatedAt,\n userId,\n currency,\n metadata ?? \"{}\",\n ],\n );\n return requireResultField(rows, \"id\", postgresUuid, \"BillingRefundRepository.upsert\");\n }\n}\n"]}
1
+ {"version":3,"file":"refund.js","sourceRoot":"","sources":["../../../../src/billing/postgres/repositories/refund.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EACL,iBAAiB,EACjB,YAAY,EACZ,kBAAkB,EAClB,SAAS,GACV,MAAM,wCAAwC,CAAC;AAEhD,MAAM,OAAO,uBAAuB;IACd,KAAK;IAAzB,YAAoB,KAAc;qBAAd,KAAK;IAAY,CAAC;IAEtC,KAAK,CAAC,MAAM,CACV,QAAgB,EAChB,gBAAwB,EACxB,iBAAyB,EACzB,MAAc,EACd,WAAmB,EACnB,QAAgB,EAChB,MAAqB,EACrB,QAAuB,EACvB,MAAc,EACd,iBAAyB;QAEzB,IAAI,CAAC,iBAAiB;YAAE,MAAM,IAAI,SAAS,CAAC,mCAAmC,CAAC,CAAC;QACjF,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,KAAK,CAC/B,8DAA8D,EAC9D,CAAC,QAAQ,EAAE,iBAAiB,CAAC,CAC9B,CAAC;QACF,MAAM,OAAO,GAAG,iBAAiB,CAAC,QAAQ,EAAE,wCAAwC,CAAC,CAAC;QACtF,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;YACrB,MAAM,IAAI,UAAU,CAAC,0BAA0B,EAAE;gBAC/C,SAAS,EAAE,IAAI;gBACf,OAAO,EAAE,EAAE,QAAQ,EAAE,iBAAiB,EAAE;aACzC,CAAC,CAAC;QACL,CAAC;QACD,MAAM,SAAS,GAAG,SAAS,CACzB,YAAY,EACZ,OAAO,CAAC,EAAE,EACV,2CAA2C,CAC5C,CAAC;QACF,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,KAAK,CAC3B;;eAES,EACT;YACE,SAAS;YACT,gBAAgB;YAChB,WAAW;YACX,MAAM;YACN,MAAM;YACN,iBAAiB;YACjB,MAAM;YACN,QAAQ;YACR,QAAQ,IAAI,IAAI;SACjB,CACF,CAAC;QACF,OAAO,kBAAkB,CAAC,IAAI,EAAE,IAAI,EAAE,YAAY,EAAE,gCAAgC,CAAC,CAAC;IACxF,CAAC;CACF","sourcesContent":["import { StoreError } from \"../../../errors.js\";\nimport type { QueryFn } from \"../../../shared/postgres-types.js\";\nimport {\n optionalRecordRow,\n postgresUuid,\n requireResultField,\n safeParse,\n} from \"../../../shared/postgres-validation.js\";\n\nexport class BillingRefundRepository {\n constructor(private query: QueryFn) {}\n\n async upsert(\n provider: string,\n providerRefundId: string,\n providerPaymentId: string,\n userId: string,\n amountMinor: number,\n currency: string,\n reason: string | null,\n metadata: string | null,\n status: string,\n providerUpdatedAt: string,\n ): Promise<string> {\n if (!providerPaymentId) throw new TypeError(\"refund requires providerPaymentId\");\n const payments = await this.query(\n \"SELECT * FROM bursar.get_billing_payment_by_provider($1, $2)\",\n [provider, providerPaymentId],\n );\n const payment = optionalRecordRow(payments, \"BillingRefundRepository.upsert.payment\");\n if (payment === null) {\n throw new StoreError(\"refund payment not found\", {\n retryable: true,\n details: { provider, providerPaymentId },\n });\n }\n const paymentId = safeParse(\n postgresUuid,\n payment.id,\n \"BillingRefundRepository.upsert.payment.id\",\n );\n const rows = await this.query(\n `SELECT bursar.upsert_billing_refund(\n $1::uuid, $2, $3, $4, $5, $6, $7::uuid, $8::char(3), $9::jsonb\n ) AS id`,\n [\n paymentId,\n providerRefundId,\n amountMinor,\n status,\n reason,\n providerUpdatedAt,\n userId,\n currency,\n metadata ?? \"{}\",\n ],\n );\n return requireResultField(rows, \"id\", postgresUuid, \"BillingRefundRepository.upsert\");\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"subscription-change.d.ts","sourceRoot":"","sources":["../../../../src/billing/postgres/repositories/subscription-change.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,KAAK,EACV,yBAAyB,EACzB,8BAA8B,EAE/B,MAAM,sBAAsB,CAAC;AAG9B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AA2HjE,uEAAuE;AACvE,qBAAa,mCAAmC;IAClC,OAAO,CAAC,QAAQ,CAAC,KAAK;gBAAL,KAAK,EAAE,OAAO;IAErC,MAAM,CACV,cAAc,EAAE,MAAM,EACtB,KAAK,EAAE,8BAA8B,GACpC,OAAO,CAAC,yBAAyB,CAAC;IAuC/B,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,yBAAyB,GAAG,IAAI,CAAC;IAQ9D,OAAO,CACX,QAAQ,EAAE,MAAM,EAChB,sBAAsB,EAAE,MAAM,GAC7B,OAAO,CAAC,yBAAyB,GAAG,IAAI,CAAC;IAQtC,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,+BAA+B,GAAG,OAAO,CAAC,IAAI,CAAC;YAoBlE,aAAa;YAyBb,gBAAgB;CAmD/B"}
1
+ {"version":3,"file":"subscription-change.d.ts","sourceRoot":"","sources":["../../../../src/billing/postgres/repositories/subscription-change.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,KAAK,EACV,yBAAyB,EACzB,8BAA8B,EAE/B,MAAM,sBAAsB,CAAC;AAG9B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AA4HjE,uEAAuE;AACvE,qBAAa,mCAAmC;IAClC,OAAO,CAAC,QAAQ,CAAC,KAAK;IAAlC,YAA6B,KAAK,EAAE,OAAO,EAAI;IAEzC,MAAM,CACV,cAAc,EAAE,MAAM,EACtB,KAAK,EAAE,8BAA8B,GACpC,OAAO,CAAC,yBAAyB,CAAC,CAqCpC;IAEK,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,yBAAyB,GAAG,IAAI,CAAC,CAMnE;IAEK,OAAO,CACX,QAAQ,EAAE,MAAM,EAChB,sBAAsB,EAAE,MAAM,GAC7B,OAAO,CAAC,yBAAyB,GAAG,IAAI,CAAC,CAM3C;IAEK,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,+BAA+B,GAAG,OAAO,CAAC,IAAI,CAAC,CAkB/E;YAEa,aAAa;YAyBb,gBAAgB;CA6C/B"}
@@ -206,15 +206,7 @@ export class BillingSubscriptionChangeRepository {
206
206
  details: { subscriptionChangeId: row.id, rowCount: rows.length },
207
207
  });
208
208
  }
209
- const parsed = rows.map((candidate, index) => {
210
- if (typeof candidate !== "object" || candidate === null || Array.isArray(candidate)) {
211
- throw new StoreError(`${context}: malformed subscription-change offer context`, {
212
- details: { subscriptionChangeId: row.id, index },
213
- });
214
- }
215
- const record = candidate;
216
- return safeParse(OfferContextRowSchema, projectContext(record), `${context}.context`);
217
- });
209
+ const parsed = rows.map((candidate) => safeParse(OfferContextRowSchema, projectContext(candidate), `${context}.context`));
218
210
  const bySide = new Map(parsed.map((candidate) => [candidate.side, candidate]));
219
211
  const from = bySide.get("from");
220
212
  const to = bySide.get("to");
@@ -1 +1 @@
1
- {"version":3,"file":"subscription-change.js","sourceRoot":"","sources":["../../../../src/billing/postgres/repositories/subscription-change.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAOxB,OAAO,EAAE,UAAU,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,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;QAC/E,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAChC,MAAM,EAAE,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC5B,IAAI,MAAM,CAAC,IAAI,KAAK,CAAC,IAAI,IAAI,KAAK,SAAS,IAAI,EAAE,KAAK,SAAS,EAAE,CAAC;YAChE,MAAM,IAAI,UAAU,CAAC,GAAG,OAAO,0DAA0D,EAAE;gBACzF,OAAO,EAAE,EAAE,oBAAoB,EAAE,GAAG,CAAC,EAAE,EAAE;aAC1C,CAAC,CAAC;QACL,CAAC;QACD,IAAI,IAAI,CAAC,QAAQ,KAAK,GAAG,CAAC,aAAa,IAAI,EAAE,CAAC,QAAQ,KAAK,GAAG,CAAC,WAAW,EAAE,CAAC;YAC3E,MAAM,IAAI,UAAU,CAAC,GAAG,OAAO,oDAAoD,EAAE;gBACnF,OAAO,EAAE,EAAE,oBAAoB,EAAE,GAAG,CAAC,EAAE,EAAE;aAC1C,CAAC,CAAC;QACL,CAAC;QACD,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;IACtB,CAAC;CACF","sourcesContent":["import { z } from \"zod\";\nimport type { BillingSubscriptionChangeUpdate } from \"../../contracts.js\";\nimport type {\n BillingSubscriptionChange,\n BillingSubscriptionChangeInput,\n BillingSubscriptionOfferContext,\n} from \"../../types/index.js\";\nimport { StoreError } from \"../../../errors.js\";\nimport { optionalBoundedDiagnosticMessage } from \"../../../shared/diagnostics.js\";\nimport type { QueryFn } from \"../../../shared/postgres-types.js\";\nimport {\n optionalRecordRow,\n pgBoolean,\n postgresUuid,\n requireRecordRow,\n requireResultField,\n safeParse,\n} from \"../../../shared/postgres-validation.js\";\n\nconst timestamp = z\n .union([\n z.string().datetime({ offset: true }),\n z.date().refine((value) => !Number.isNaN(value.getTime())),\n ])\n .transform((value) => (value instanceof Date ? value.toISOString() : value));\nconst positiveBigint = z\n .union([z.string().regex(/^[1-9]\\d*$/), z.number().int().positive().safe()])\n .transform(String);\nconst changeState = z.enum([\"awaiting_payment\", \"scheduled\", \"applied\", \"failed\", \"canceled\"]);\nconst effectiveBehavior = z.enum([\"immediate\", \"renewal\"]);\nconst prorationBehavior = z.enum([\"provider_default\", \"invoice_immediately\", \"none\"]);\n\nconst OpenChangeResultSchema = z\n .object({\n change_id: positiveBigint.nullable(),\n state: changeState.nullable(),\n error_code: z\n .enum([\n \"invalid_request\",\n \"missing_subscription\",\n \"invalid_target_offer\",\n \"idempotency_conflict\",\n \"open_change_exists\",\n ])\n .nullable(),\n })\n .strict()\n .superRefine((row, ctx) => {\n const succeeded = row.error_code === null;\n if (succeeded !== (row.change_id !== null && row.state !== null)) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: \"subscription-change result has inconsistent success fields\",\n });\n }\n });\n\nconst ChangeRowSchema = z\n .object({\n id: positiveBigint,\n subscription_id: postgresUuid,\n from_offer_id: postgresUuid,\n from_catalog_revision_id: postgresUuid,\n to_offer_id: postgresUuid,\n to_catalog_revision_id: postgresUuid,\n effective_at: timestamp.nullable(),\n effective_behavior: effectiveBehavior,\n state: changeState,\n proration_behavior: prorationBehavior,\n idempotency_key: z.string().min(1),\n provider_operation_id: z.string().min(1).nullable(),\n error_message: z.string().min(1).max(8192).nullable(),\n })\n .strict();\n\ntype ChangeRow = z.infer<typeof ChangeRowSchema>;\n\nconst OfferContextRowSchema = z\n .object({\n side: z.enum([\"from\", \"to\"]),\n offer_id: postgresUuid,\n offer_key: z.string().min(1),\n plan_id: postgresUuid,\n plan_key: z.string().min(1),\n billing_unit: z.enum([\"day\", \"week\", \"month\", \"year\"]),\n billing_count: z.number().int().positive(),\n })\n .strict();\n\ntype OfferContextRow = z.infer<typeof OfferContextRowSchema>;\n\nfunction projectChange(row: Record<string, unknown>): Record<string, unknown> {\n return {\n id: row.id,\n subscription_id: row.subscription_id,\n from_offer_id: row.from_offer_id,\n from_catalog_revision_id: row.from_catalog_revision_id,\n to_offer_id: row.to_offer_id,\n to_catalog_revision_id: row.to_catalog_revision_id,\n effective_at: row.effective_at,\n effective_behavior: row.effective_behavior,\n state: row.state,\n proration_behavior: row.proration_behavior,\n idempotency_key: row.idempotency_key,\n provider_operation_id: row.provider_operation_id,\n error_message: row.error_message,\n };\n}\n\nfunction projectContext(row: Record<string, unknown>): Record<string, unknown> {\n return {\n side: row.side,\n offer_id: row.offer_id,\n offer_key: row.offer_key,\n plan_id: row.plan_id,\n plan_key: row.plan_key,\n billing_unit: row.billing_unit,\n billing_count: row.billing_count,\n };\n}\n\nfunction publicContext(row: OfferContextRow): BillingSubscriptionOfferContext {\n return {\n offerId: row.offer_id,\n offerKey: row.offer_key,\n planId: row.plan_id,\n plan: row.plan_key,\n interval: row.billing_unit,\n intervalCount: row.billing_count,\n };\n}\n\n/** Persistence boundary for durable subscription offer transitions. */\nexport class BillingSubscriptionChangeRepository {\n constructor(private readonly query: QueryFn) {}\n\n async create(\n subscriptionId: string,\n input: BillingSubscriptionChangeInput,\n ): Promise<BillingSubscriptionChange> {\n const rows = await this.query(\n `SELECT * FROM bursar.open_subscription_change(\n $1::uuid, $2::uuid, $3::timestamptz, $4, $5, $6\n )`,\n [\n subscriptionId,\n input.toOfferId,\n input.effectiveAt,\n input.effective,\n input.idempotencyKey,\n input.prorationBehavior ?? \"provider_default\",\n ],\n );\n const raw = requireRecordRow(rows, \"BillingSubscriptionChangeRepository.create\");\n const result = safeParse(\n OpenChangeResultSchema,\n { change_id: raw.change_id, state: raw.state, error_code: raw.error_code },\n \"BillingSubscriptionChangeRepository.create\",\n { indeterminate: true },\n );\n if (result.error_code !== null) {\n throw new StoreError(`subscription change rejected: ${result.error_code}`, {\n details: { errorCode: result.error_code },\n });\n }\n if (result.change_id === null) {\n throw new StoreError(\"subscription change returned no identifier\", { indeterminate: true });\n }\n const change = await this.getById(result.change_id);\n if (change === null) {\n throw new StoreError(\"subscription change could not be read after creation\", {\n indeterminate: true,\n details: { subscriptionChangeId: result.change_id },\n });\n }\n return change;\n }\n\n async getById(id: string): Promise<BillingSubscriptionChange | null> {\n const rows = await this.query(\n \"SELECT * FROM bursar.get_billing_subscription_change($1::bigint)\",\n [id],\n );\n return this.parseOptional(rows, \"BillingSubscriptionChangeRepository.getById\");\n }\n\n async getOpen(\n provider: string,\n providerSubscriptionId: string,\n ): Promise<BillingSubscriptionChange | null> {\n const rows = await this.query(\n \"SELECT * FROM bursar.get_open_billing_subscription_change($1, $2)\",\n [provider, providerSubscriptionId],\n );\n return this.parseOptional(rows, \"BillingSubscriptionChangeRepository.getOpen\");\n }\n\n async update(id: string, update: BillingSubscriptionChangeUpdate): Promise<void> {\n if (update.state === undefined) return;\n const rows = await this.query(\n \"SELECT bursar.advance_subscription_change($1::bigint, $2, $3, $4) AS advanced\",\n [\n id,\n update.state,\n update.providerOperationId ?? null,\n optionalBoundedDiagnosticMessage(update.errorMessage),\n ],\n );\n if (\n !requireResultField(rows, \"advanced\", pgBoolean, \"BillingSubscriptionChangeRepository.update\")\n ) {\n throw new StoreError(`subscription change transition rejected: ${id}`, {\n details: { subscriptionChangeId: id },\n });\n }\n }\n\n private async parseOptional(\n rows: readonly unknown[],\n context: string,\n ): Promise<BillingSubscriptionChange | null> {\n const raw = optionalRecordRow(rows, context);\n if (raw === null) return null;\n const row = safeParse(ChangeRowSchema, projectChange(raw), context);\n const contexts = await this.getOfferContexts(row, context);\n return {\n id: row.id,\n subscriptionId: row.subscription_id,\n fromOfferId: row.from_offer_id,\n toOfferId: row.to_offer_id,\n fromOffer: publicContext(contexts.from),\n toOffer: publicContext(contexts.to),\n effectiveAt: row.effective_at,\n effective: row.effective_behavior,\n state: row.state,\n prorationBehavior: row.proration_behavior,\n idempotencyKey: row.idempotency_key,\n providerOperationId: row.provider_operation_id,\n errorMessage: row.error_message,\n };\n }\n\n private async getOfferContexts(\n row: ChangeRow,\n context: string,\n ): Promise<{ from: OfferContextRow; to: OfferContextRow }> {\n const rows = await this.query(\n `SELECT requested.side, requested.offer_id, offer_context.*\n FROM (\n VALUES\n ('from', $1::uuid, $2::uuid),\n ('to', $3::uuid, $4::uuid)\n ) AS requested(side, offer_id, catalog_revision_id)\n CROSS JOIN LATERAL bursar.get_catalog_offer_context(\n requested.offer_id,\n requested.catalog_revision_id\n ) AS offer_context`,\n [\n row.from_offer_id,\n row.from_catalog_revision_id,\n row.to_offer_id,\n row.to_catalog_revision_id,\n ],\n );\n if (rows.length !== 2) {\n throw new StoreError(`${context}: expected both subscription-change offer contexts`, {\n details: { subscriptionChangeId: row.id, rowCount: rows.length },\n });\n }\n const parsed = rows.map((candidate, index) => {\n if (typeof candidate !== \"object\" || candidate === null || Array.isArray(candidate)) {\n throw new StoreError(`${context}: malformed subscription-change offer context`, {\n details: { subscriptionChangeId: row.id, index },\n });\n }\n const record = candidate as Record<string, unknown>;\n return safeParse(OfferContextRowSchema, projectContext(record), `${context}.context`);\n });\n const bySide = new Map(parsed.map((candidate) => [candidate.side, candidate]));\n const from = bySide.get(\"from\");\n const to = bySide.get(\"to\");\n if (bySide.size !== 2 || from === undefined || to === undefined) {\n throw new StoreError(`${context}: duplicate or missing subscription-change offer context`, {\n details: { subscriptionChangeId: row.id },\n });\n }\n if (from.offer_id !== row.from_offer_id || to.offer_id !== row.to_offer_id) {\n throw new StoreError(`${context}: subscription-change offer context does not match`, {\n details: { subscriptionChangeId: row.id },\n });\n }\n return { from, to };\n }\n}\n"]}
1
+ {"version":3,"file":"subscription-change.js","sourceRoot":"","sources":["../../../../src/billing/postgres/repositories/subscription-change.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAOxB,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,gCAAgC,EAAE,MAAM,gCAAgC,CAA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,EAAE,oBAAoB,EAAE,GAAG,CAAC,EAAE,EAAE;aAC1C,CAAC,CAAC;QACL,CAAC;QACD,IAAI,IAAI,CAAC,QAAQ,KAAK,GAAG,CAAC,aAAa,IAAI,EAAE,CAAC,QAAQ,KAAK,GAAG,CAAC,WAAW,EAAE,CAAC;YAC3E,MAAM,IAAI,UAAU,CAAC,GAAG,OAAO,oDAAoD,EAAE;gBACnF,OAAO,EAAE,EAAE,oBAAoB,EAAE,GAAG,CAAC,EAAE,EAAE;aAC1C,CAAC,CAAC;QACL,CAAC;QACD,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;IACtB,CAAC;CACF","sourcesContent":["import { z } from \"zod\";\nimport type { BillingSubscriptionChangeUpdate } from \"../../contracts.js\";\nimport type {\n BillingSubscriptionChange,\n BillingSubscriptionChangeInput,\n BillingSubscriptionOfferContext,\n} from \"../../types/index.js\";\nimport { StoreError } from \"../../../errors.js\";\nimport { optionalBoundedDiagnosticMessage } from \"../../../shared/diagnostics.js\";\nimport type { QueryFn } from \"../../../shared/postgres-types.js\";\nimport type { PostgresRow } from \"../../../shared/json.js\";\nimport {\n optionalRecordRow,\n pgBoolean,\n postgresUuid,\n requireRecordRow,\n requireResultField,\n safeParse,\n} from \"../../../shared/postgres-validation.js\";\n\nconst timestamp = z\n .union([\n z.string().datetime({ offset: true }),\n z.date().refine((value) => !Number.isNaN(value.getTime())),\n ])\n .transform((value) => (value instanceof Date ? value.toISOString() : value));\nconst positiveBigint = z\n .union([z.string().regex(/^[1-9]\\d*$/), z.number().int().positive().safe()])\n .transform(String);\nconst changeState = z.enum([\"awaiting_payment\", \"scheduled\", \"applied\", \"failed\", \"canceled\"]);\nconst effectiveBehavior = z.enum([\"immediate\", \"renewal\"]);\nconst prorationBehavior = z.enum([\"provider_default\", \"invoice_immediately\", \"none\"]);\n\nconst OpenChangeResultSchema = z\n .object({\n change_id: positiveBigint.nullable(),\n state: changeState.nullable(),\n error_code: z\n .enum([\n \"invalid_request\",\n \"missing_subscription\",\n \"invalid_target_offer\",\n \"idempotency_conflict\",\n \"open_change_exists\",\n ])\n .nullable(),\n })\n .strict()\n .superRefine((row, ctx) => {\n const succeeded = row.error_code === null;\n if (succeeded !== (row.change_id !== null && row.state !== null)) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: \"subscription-change result has inconsistent success fields\",\n });\n }\n });\n\nconst ChangeRowSchema = z\n .object({\n id: positiveBigint,\n subscription_id: postgresUuid,\n from_offer_id: postgresUuid,\n from_catalog_revision_id: postgresUuid,\n to_offer_id: postgresUuid,\n to_catalog_revision_id: postgresUuid,\n effective_at: timestamp.nullable(),\n effective_behavior: effectiveBehavior,\n state: changeState,\n proration_behavior: prorationBehavior,\n idempotency_key: z.string().min(1),\n provider_operation_id: z.string().min(1).nullable(),\n error_message: z.string().min(1).max(8192).nullable(),\n })\n .strict();\n\ntype ChangeRow = z.infer<typeof ChangeRowSchema>;\n\nconst OfferContextRowSchema = z\n .object({\n side: z.enum([\"from\", \"to\"]),\n offer_id: postgresUuid,\n offer_key: z.string().min(1),\n plan_id: postgresUuid,\n plan_key: z.string().min(1),\n billing_unit: z.enum([\"day\", \"week\", \"month\", \"year\"]),\n billing_count: z.number().int().positive(),\n })\n .strict();\n\ntype OfferContextRow = z.infer<typeof OfferContextRowSchema>;\n\nfunction projectChange(row: PostgresRow) {\n return {\n id: row.id,\n subscription_id: row.subscription_id,\n from_offer_id: row.from_offer_id,\n from_catalog_revision_id: row.from_catalog_revision_id,\n to_offer_id: row.to_offer_id,\n to_catalog_revision_id: row.to_catalog_revision_id,\n effective_at: row.effective_at,\n effective_behavior: row.effective_behavior,\n state: row.state,\n proration_behavior: row.proration_behavior,\n idempotency_key: row.idempotency_key,\n provider_operation_id: row.provider_operation_id,\n error_message: row.error_message,\n };\n}\n\nfunction projectContext(row: PostgresRow) {\n return {\n side: row.side,\n offer_id: row.offer_id,\n offer_key: row.offer_key,\n plan_id: row.plan_id,\n plan_key: row.plan_key,\n billing_unit: row.billing_unit,\n billing_count: row.billing_count,\n };\n}\n\nfunction publicContext(row: OfferContextRow): BillingSubscriptionOfferContext {\n return {\n offerId: row.offer_id,\n offerKey: row.offer_key,\n planId: row.plan_id,\n plan: row.plan_key,\n interval: row.billing_unit,\n intervalCount: row.billing_count,\n };\n}\n\n/** Persistence boundary for durable subscription offer transitions. */\nexport class BillingSubscriptionChangeRepository {\n constructor(private readonly query: QueryFn) {}\n\n async create(\n subscriptionId: string,\n input: BillingSubscriptionChangeInput,\n ): Promise<BillingSubscriptionChange> {\n const rows = await this.query(\n `SELECT * FROM bursar.open_subscription_change(\n $1::uuid, $2::uuid, $3::timestamptz, $4, $5, $6\n )`,\n [\n subscriptionId,\n input.toOfferId,\n input.effectiveAt,\n input.effective,\n input.idempotencyKey,\n input.prorationBehavior ?? \"provider_default\",\n ],\n );\n const raw = requireRecordRow(rows, \"BillingSubscriptionChangeRepository.create\");\n const result = safeParse(\n OpenChangeResultSchema,\n { change_id: raw.change_id, state: raw.state, error_code: raw.error_code },\n \"BillingSubscriptionChangeRepository.create\",\n { indeterminate: true },\n );\n if (result.error_code !== null) {\n throw new StoreError(`subscription change rejected: ${result.error_code}`, {\n details: { errorCode: result.error_code },\n });\n }\n if (result.change_id === null) {\n throw new StoreError(\"subscription change returned no identifier\", { indeterminate: true });\n }\n const change = await this.getById(result.change_id);\n if (change === null) {\n throw new StoreError(\"subscription change could not be read after creation\", {\n indeterminate: true,\n details: { subscriptionChangeId: result.change_id },\n });\n }\n return change;\n }\n\n async getById(id: string): Promise<BillingSubscriptionChange | null> {\n const rows = await this.query(\n \"SELECT * FROM bursar.get_billing_subscription_change($1::bigint)\",\n [id],\n );\n return this.parseOptional(rows, \"BillingSubscriptionChangeRepository.getById\");\n }\n\n async getOpen(\n provider: string,\n providerSubscriptionId: string,\n ): Promise<BillingSubscriptionChange | null> {\n const rows = await this.query(\n \"SELECT * FROM bursar.get_open_billing_subscription_change($1, $2)\",\n [provider, providerSubscriptionId],\n );\n return this.parseOptional(rows, \"BillingSubscriptionChangeRepository.getOpen\");\n }\n\n async update(id: string, update: BillingSubscriptionChangeUpdate): Promise<void> {\n if (update.state === undefined) return;\n const rows = await this.query(\n \"SELECT bursar.advance_subscription_change($1::bigint, $2, $3, $4) AS advanced\",\n [\n id,\n update.state,\n update.providerOperationId ?? null,\n optionalBoundedDiagnosticMessage(update.errorMessage),\n ],\n );\n if (\n !requireResultField(rows, \"advanced\", pgBoolean, \"BillingSubscriptionChangeRepository.update\")\n ) {\n throw new StoreError(`subscription change transition rejected: ${id}`, {\n details: { subscriptionChangeId: id },\n });\n }\n }\n\n private async parseOptional(\n rows: readonly PostgresRow[],\n context: string,\n ): Promise<BillingSubscriptionChange | null> {\n const raw = optionalRecordRow(rows, context);\n if (raw === null) return null;\n const row = safeParse(ChangeRowSchema, projectChange(raw), context);\n const contexts = await this.getOfferContexts(row, context);\n return {\n id: row.id,\n subscriptionId: row.subscription_id,\n fromOfferId: row.from_offer_id,\n toOfferId: row.to_offer_id,\n fromOffer: publicContext(contexts.from),\n toOffer: publicContext(contexts.to),\n effectiveAt: row.effective_at,\n effective: row.effective_behavior,\n state: row.state,\n prorationBehavior: row.proration_behavior,\n idempotencyKey: row.idempotency_key,\n providerOperationId: row.provider_operation_id,\n errorMessage: row.error_message,\n };\n }\n\n private async getOfferContexts(\n row: ChangeRow,\n context: string,\n ): Promise<{ from: OfferContextRow; to: OfferContextRow }> {\n const rows = await this.query(\n `SELECT requested.side, requested.offer_id, offer_context.*\n FROM (\n VALUES\n ('from', $1::uuid, $2::uuid),\n ('to', $3::uuid, $4::uuid)\n ) AS requested(side, offer_id, catalog_revision_id)\n CROSS JOIN LATERAL bursar.get_catalog_offer_context(\n requested.offer_id,\n requested.catalog_revision_id\n ) AS offer_context`,\n [\n row.from_offer_id,\n row.from_catalog_revision_id,\n row.to_offer_id,\n row.to_catalog_revision_id,\n ],\n );\n if (rows.length !== 2) {\n throw new StoreError(`${context}: expected both subscription-change offer contexts`, {\n details: { subscriptionChangeId: row.id, rowCount: rows.length },\n });\n }\n const parsed = rows.map((candidate) =>\n safeParse(OfferContextRowSchema, projectContext(candidate), `${context}.context`),\n );\n const bySide = new Map(parsed.map((candidate) => [candidate.side, candidate]));\n const from = bySide.get(\"from\");\n const to = bySide.get(\"to\");\n if (bySide.size !== 2 || from === undefined || to === undefined) {\n throw new StoreError(`${context}: duplicate or missing subscription-change offer context`, {\n details: { subscriptionChangeId: row.id },\n });\n }\n if (from.offer_id !== row.from_offer_id || to.offer_id !== row.to_offer_id) {\n throw new StoreError(`${context}: subscription-change offer context does not match`, {\n details: { subscriptionChangeId: row.id },\n });\n }\n return { from, to };\n }\n}\n"]}
@@ -1,6 +1,7 @@
1
1
  import { z } from "zod";
2
- import type { BillingSubscriptionState } from "../../types/subscriptions.js";
2
+ import type { BillingSubscriptionState, BillingSubscriptionStatus, SubscriptionEntitlementOutcome } from "../../types/subscriptions.js";
3
3
  import type { QueryFn } from "../../../shared/postgres-types.js";
4
+ import type { JsonObject } from "../../../shared/json.js";
4
5
  declare const SubscriptionRowSchema: z.ZodObject<{
5
6
  id: z.ZodString;
6
7
  user_id: z.ZodString;
@@ -12,15 +13,15 @@ declare const SubscriptionRowSchema: z.ZodObject<{
12
13
  plan_id: z.ZodString;
13
14
  plan: z.ZodString;
14
15
  status: z.ZodEnum<{
16
+ active: "active";
15
17
  canceled: "canceled";
18
+ expired: "expired";
16
19
  incomplete: "incomplete";
17
20
  incomplete_expired: "incomplete_expired";
18
- trialing: "trialing";
19
- active: "active";
20
21
  past_due: "past_due";
21
- unpaid: "unpaid";
22
22
  paused: "paused";
23
- expired: "expired";
23
+ trialing: "trialing";
24
+ unpaid: "unpaid";
24
25
  }>;
25
26
  current_period_start: z.ZodNullable<z.ZodPipe<z.ZodUnion<readonly [z.ZodDate, z.ZodString]>, z.ZodTransform<string, string | Date>>>;
26
27
  current_period_end: z.ZodNullable<z.ZodPipe<z.ZodUnion<readonly [z.ZodDate, z.ZodString]>, z.ZodTransform<string, string | Date>>>;
@@ -33,12 +34,12 @@ declare const SubscriptionRowSchema: z.ZodObject<{
33
34
  cancel_at_period_end: z.ZodBoolean;
34
35
  interval: z.ZodEnum<{
35
36
  day: "day";
36
- week: "week";
37
37
  month: "month";
38
+ week: "week";
38
39
  year: "year";
39
40
  }>;
40
41
  interval_count: z.ZodNumber;
41
- metadata: z.ZodRecord<z.ZodString, z.ZodUnknown>;
42
+ metadata: z.ZodRecord<z.ZodString, z.ZodJSONSchema>;
42
43
  }, z.core.$strict>;
43
44
  export type SubscriptionRow = z.infer<typeof SubscriptionRowSchema>;
44
45
  export declare class BillingSubscriptionRepository {
@@ -51,17 +52,16 @@ export declare class BillingSubscriptionRepository {
51
52
  getUserSubscription(userId: string, statuses?: string[]): Promise<SubscriptionRow | null>;
52
53
  getUserSubscriptions(userId: string): Promise<SubscriptionRow[]>;
53
54
  listExpiredGraceSubscriptions(now: string, limit?: number): Promise<SubscriptionRow[]>;
54
- markGraceExpired(subscriptionId: string, expectedGraceEndsAt: string, expiredAt: string): Promise<boolean>;
55
+ reconcileEntitlement(subjectId: string, subscriptionId: string, billingEventId: string, expectedStatus: BillingSubscriptionStatus, expectedProviderUpdatedAt: string, planAssignedAt: Date | string | null, applyEntitlement: boolean, terminalPlanKey: string | null, reason: string): Promise<SubscriptionEntitlementOutcome>;
56
+ expireGracePeriod(subjectId: string, subscriptionId: string, expectedGraceEndsAt: string, expiredAt: string, terminalPlanKey: string | null): Promise<boolean>;
55
57
  recordConflict(input: {
56
58
  userId?: string | null;
57
59
  provider: string;
58
60
  duplicateSubscriptionId: string;
59
61
  existingSubscriptionId?: string | null;
60
62
  eventId?: string | null;
61
- metadata?: Record<string, unknown>;
63
+ metadata?: JsonObject;
62
64
  }): Promise<string>;
63
- /** Select a provider subscription without modifying provider-reported state. */
64
- selectEntitlementSource(userId: string, provider: string, providerSubscriptionId?: string | null): Promise<boolean>;
65
65
  }
66
66
  export {};
67
67
  //# sourceMappingURL=subscription.d.ts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