@pithy-sh/payments 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (402) hide show
  1. package/dist/admin/coverage.d.ts +35 -0
  2. package/dist/admin/coverage.d.ts.map +1 -0
  3. package/dist/admin/coverage.js +56 -0
  4. package/dist/admin/read.d.ts +222 -0
  5. package/dist/admin/read.d.ts.map +1 -0
  6. package/dist/admin/read.js +159 -0
  7. package/dist/audit/actions.d.ts +211 -0
  8. package/dist/audit/actions.d.ts.map +1 -0
  9. package/dist/audit/actions.js +211 -0
  10. package/dist/capability.d.ts +72 -0
  11. package/dist/capability.d.ts.map +1 -0
  12. package/dist/capability.js +228 -0
  13. package/dist/client/api.d.ts +435 -0
  14. package/dist/client/api.d.ts.map +1 -0
  15. package/dist/client/api.js +415 -0
  16. package/dist/client/checkout.d.ts +144 -0
  17. package/dist/client/checkout.d.ts.map +1 -0
  18. package/dist/client/checkout.js +173 -0
  19. package/dist/client/fixtures/price-preview-de.js +89 -0
  20. package/dist/client/fixtures/price-preview-gb.js +89 -0
  21. package/dist/client/fixtures/price-preview-jp-yen.js +89 -0
  22. package/dist/client/fixtures/price-preview-us-country-only.js +89 -0
  23. package/dist/client/fixtures/price-preview-us-new-york.js +89 -0
  24. package/dist/client/fixtures/pricePreview.d.ts +54 -0
  25. package/dist/client/fixtures/pricePreview.d.ts.map +1 -0
  26. package/dist/client/fixtures/pricePreview.js +61 -0
  27. package/dist/client/hooks.d.ts +235 -0
  28. package/dist/client/hooks.d.ts.map +1 -0
  29. package/dist/client/hooks.js +428 -0
  30. package/dist/client/paddle.d.ts +433 -0
  31. package/dist/client/paddle.d.ts.map +1 -0
  32. package/dist/client/paddle.js +391 -0
  33. package/dist/client/paddleCache.d.ts +123 -0
  34. package/dist/client/paddleCache.d.ts.map +1 -0
  35. package/dist/client/paddleCache.js +159 -0
  36. package/dist/client/paddlePrices.d.ts +94 -0
  37. package/dist/client/paddlePrices.d.ts.map +1 -0
  38. package/dist/client/paddlePrices.js +55 -0
  39. package/dist/client/paddlePricesTag.d.ts +127 -0
  40. package/dist/client/paddlePricesTag.d.ts.map +1 -0
  41. package/dist/client/paddlePricesTag.js +207 -0
  42. package/dist/client/projection.d.ts +128 -0
  43. package/dist/client/projection.d.ts.map +1 -0
  44. package/dist/client/projection.js +0 -0
  45. package/dist/client/test-utils/cacheStore.d.ts +18 -0
  46. package/dist/client/test-utils/cacheStore.d.ts.map +1 -0
  47. package/dist/client/test-utils/cacheStore.js +42 -0
  48. package/dist/client/wholeUnits.d.ts +18 -0
  49. package/dist/client/wholeUnits.d.ts.map +1 -0
  50. package/dist/client/wholeUnits.js +120 -0
  51. package/dist/config/config.d.ts +238 -0
  52. package/dist/config/config.d.ts.map +1 -0
  53. package/dist/config/config.js +249 -0
  54. package/dist/data/discount.d.ts +127 -0
  55. package/dist/data/discount.d.ts.map +1 -0
  56. package/dist/data/discount.js +91 -0
  57. package/dist/data/entitlement.d.ts +43 -0
  58. package/dist/data/entitlement.d.ts.map +1 -0
  59. package/dist/data/entitlement.js +43 -0
  60. package/dist/data/money.d.ts +15 -0
  61. package/dist/data/money.d.ts.map +1 -0
  62. package/dist/data/money.js +76 -0
  63. package/dist/data/pause.d.ts +133 -0
  64. package/dist/data/pause.d.ts.map +1 -0
  65. package/dist/data/pause.js +63 -0
  66. package/dist/data/providerAccount.d.ts +40 -0
  67. package/dist/data/providerAccount.d.ts.map +1 -0
  68. package/dist/data/providerAccount.js +34 -0
  69. package/dist/data/purchase.d.ts +107 -0
  70. package/dist/data/purchase.d.ts.map +1 -0
  71. package/dist/data/purchase.js +77 -0
  72. package/dist/data/rail.d.ts +74 -0
  73. package/dist/data/rail.d.ts.map +1 -0
  74. package/dist/data/rail.js +74 -0
  75. package/dist/data/reconcileRun.d.ts +120 -0
  76. package/dist/data/reconcileRun.d.ts.map +1 -0
  77. package/dist/data/reconcileRun.js +120 -0
  78. package/dist/data/renderMoney.d.ts +85 -0
  79. package/dist/data/renderMoney.d.ts.map +1 -0
  80. package/dist/data/renderMoney.js +146 -0
  81. package/dist/data/status.d.ts +58 -0
  82. package/dist/data/status.d.ts.map +1 -0
  83. package/dist/data/status.js +68 -0
  84. package/dist/data/subject.d.ts +111 -0
  85. package/dist/data/subject.d.ts.map +1 -0
  86. package/dist/data/subject.js +125 -0
  87. package/dist/data/subscription.d.ts +624 -0
  88. package/dist/data/subscription.d.ts.map +1 -0
  89. package/dist/data/subscription.js +497 -0
  90. package/dist/data/syncCursor.d.ts +33 -0
  91. package/dist/data/syncCursor.d.ts.map +1 -0
  92. package/dist/data/syncCursor.js +29 -0
  93. package/dist/data/tables.d.ts +37 -0
  94. package/dist/data/tables.d.ts.map +1 -0
  95. package/dist/data/tables.js +44 -0
  96. package/dist/data/webhookEvent.d.ts +134 -0
  97. package/dist/data/webhookEvent.d.ts.map +1 -0
  98. package/dist/data/webhookEvent.js +128 -0
  99. package/dist/entitlement/manual.d.ts +101 -0
  100. package/dist/entitlement/manual.d.ts.map +1 -0
  101. package/dist/entitlement/manual.js +84 -0
  102. package/dist/entitlement/resolver.d.ts +60 -0
  103. package/dist/entitlement/resolver.d.ts.map +1 -0
  104. package/dist/entitlement/resolver.js +101 -0
  105. package/dist/entitlement/subjectSeam.d.ts +102 -0
  106. package/dist/entitlement/subjectSeam.d.ts.map +1 -0
  107. package/dist/entitlement/subjectSeam.js +85 -0
  108. package/dist/error/errors.d.ts +247 -0
  109. package/dist/error/errors.d.ts.map +1 -0
  110. package/dist/error/errors.js +326 -0
  111. package/dist/grants/apply.d.ts +74 -0
  112. package/dist/grants/apply.d.ts.map +1 -0
  113. package/dist/grants/apply.js +148 -0
  114. package/dist/grants/clawback.d.ts +43 -0
  115. package/dist/grants/clawback.d.ts.map +1 -0
  116. package/dist/grants/clawback.js +71 -0
  117. package/dist/grants/ledgerSeam.d.ts +89 -0
  118. package/dist/grants/ledgerSeam.d.ts.map +1 -0
  119. package/dist/grants/ledgerSeam.js +66 -0
  120. package/dist/http/dispatch.d.ts +35 -0
  121. package/dist/http/dispatch.d.ts.map +1 -0
  122. package/dist/http/dispatch.js +40 -0
  123. package/dist/http/guards.d.ts +43 -0
  124. package/dist/http/guards.d.ts.map +1 -0
  125. package/dist/http/guards.js +52 -0
  126. package/dist/http/manifestConfig.d.ts +38 -0
  127. package/dist/http/manifestConfig.d.ts.map +1 -0
  128. package/dist/http/manifestConfig.js +49 -0
  129. package/dist/http/responses.d.ts +1455 -0
  130. package/dist/http/responses.d.ts.map +1 -0
  131. package/dist/http/responses.js +728 -0
  132. package/dist/http/routes.d.ts +315 -0
  133. package/dist/http/routes.d.ts.map +1 -0
  134. package/dist/http/routes.js +1966 -0
  135. package/dist/http/schemas.d.ts +404 -0
  136. package/dist/http/schemas.d.ts.map +1 -0
  137. package/dist/http/schemas.js +359 -0
  138. package/dist/http/scopes.d.ts +160 -0
  139. package/dist/http/scopes.d.ts.map +1 -0
  140. package/dist/http/scopes.js +240 -0
  141. package/dist/http/view.d.ts +96 -0
  142. package/dist/http/view.d.ts.map +1 -0
  143. package/dist/http/view.js +170 -0
  144. package/dist/http/webhookGuard.d.ts +109 -0
  145. package/dist/http/webhookGuard.d.ts.map +1 -0
  146. package/dist/http/webhookGuard.js +206 -0
  147. package/dist/index.d.ts +64 -0
  148. package/dist/index.d.ts.map +1 -0
  149. package/dist/index.js +43 -0
  150. package/dist/migrations/0001_purchases.d.ts +35 -0
  151. package/dist/migrations/0001_purchases.d.ts.map +1 -0
  152. package/dist/migrations/0001_purchases.js +80 -0
  153. package/dist/pricing/location.d.ts +138 -0
  154. package/dist/pricing/location.d.ts.map +1 -0
  155. package/dist/pricing/location.js +81 -0
  156. package/dist/pricing/visitor.d.ts +56 -0
  157. package/dist/pricing/visitor.d.ts.map +1 -0
  158. package/dist/pricing/visitor.js +35 -0
  159. package/dist/projection/event.d.ts +66 -0
  160. package/dist/projection/event.d.ts.map +1 -0
  161. package/dist/projection/event.js +45 -0
  162. package/dist/projection/orphans.d.ts +114 -0
  163. package/dist/projection/orphans.d.ts.map +1 -0
  164. package/dist/projection/orphans.js +162 -0
  165. package/dist/projection/owner.d.ts +121 -0
  166. package/dist/projection/owner.d.ts.map +1 -0
  167. package/dist/projection/owner.js +114 -0
  168. package/dist/projection/resolve.d.ts +30 -0
  169. package/dist/projection/resolve.d.ts.map +1 -0
  170. package/dist/projection/resolve.js +42 -0
  171. package/dist/projection/writer.d.ts +103 -0
  172. package/dist/projection/writer.d.ts.map +1 -0
  173. package/dist/projection/writer.js +280 -0
  174. package/dist/provision/resolvePaymentsConfig.d.ts +48 -0
  175. package/dist/provision/resolvePaymentsConfig.d.ts.map +1 -0
  176. package/dist/provision/resolvePaymentsConfig.js +41 -0
  177. package/dist/rails/apple/certs.d.ts +7 -0
  178. package/dist/rails/apple/certs.d.ts.map +1 -0
  179. package/dist/rails/apple/certs.js +8 -0
  180. package/dist/rails/apple/der.d.ts +107 -0
  181. package/dist/rails/apple/der.d.ts.map +1 -0
  182. package/dist/rails/apple/der.js +217 -0
  183. package/dist/rails/apple/fixtures/chain.d.ts +117 -0
  184. package/dist/rails/apple/fixtures/chain.d.ts.map +1 -0
  185. package/dist/rails/apple/fixtures/chain.js +289 -0
  186. package/dist/rails/apple/http.d.ts +74 -0
  187. package/dist/rails/apple/http.d.ts.map +1 -0
  188. package/dist/rails/apple/http.js +32 -0
  189. package/dist/rails/apple/jws.d.ts +17 -0
  190. package/dist/rails/apple/jws.d.ts.map +1 -0
  191. package/dist/rails/apple/jws.js +75 -0
  192. package/dist/rails/apple/notification.d.ts +116 -0
  193. package/dist/rails/apple/notification.d.ts.map +1 -0
  194. package/dist/rails/apple/notification.js +199 -0
  195. package/dist/rails/apple/rail.d.ts +25 -0
  196. package/dist/rails/apple/rail.d.ts.map +1 -0
  197. package/dist/rails/apple/rail.js +68 -0
  198. package/dist/rails/apple/serverApi.d.ts +120 -0
  199. package/dist/rails/apple/serverApi.d.ts.map +1 -0
  200. package/dist/rails/apple/serverApi.js +244 -0
  201. package/dist/rails/apple/verify.d.ts +36 -0
  202. package/dist/rails/apple/verify.d.ts.map +1 -0
  203. package/dist/rails/apple/verify.js +46 -0
  204. package/dist/rails/apple/x509.d.ts +85 -0
  205. package/dist/rails/apple/x509.d.ts.map +1 -0
  206. package/dist/rails/apple/x509.js +273 -0
  207. package/dist/rails/contract.d.ts +871 -0
  208. package/dist/rails/contract.d.ts.map +1 -0
  209. package/dist/rails/contract.js +60 -0
  210. package/dist/rails/google/fixtures/push.d.ts +71 -0
  211. package/dist/rails/google/fixtures/push.d.ts.map +1 -0
  212. package/dist/rails/google/fixtures/push.js +107 -0
  213. package/dist/rails/google/http.d.ts +77 -0
  214. package/dist/rails/google/http.d.ts.map +1 -0
  215. package/dist/rails/google/http.js +39 -0
  216. package/dist/rails/google/jwt.d.ts +53 -0
  217. package/dist/rails/google/jwt.d.ts.map +1 -0
  218. package/dist/rails/google/jwt.js +94 -0
  219. package/dist/rails/google/oidc.d.ts +112 -0
  220. package/dist/rails/google/oidc.d.ts.map +1 -0
  221. package/dist/rails/google/oidc.js +179 -0
  222. package/dist/rails/google/playApi.d.ts +188 -0
  223. package/dist/rails/google/playApi.d.ts.map +1 -0
  224. package/dist/rails/google/playApi.js +350 -0
  225. package/dist/rails/google/rail.d.ts +57 -0
  226. package/dist/rails/google/rail.d.ts.map +1 -0
  227. package/dist/rails/google/rail.js +70 -0
  228. package/dist/rails/google/rtdn.d.ts +105 -0
  229. package/dist/rails/google/rtdn.d.ts.map +1 -0
  230. package/dist/rails/google/rtdn.js +179 -0
  231. package/dist/rails/google/verify.d.ts +20 -0
  232. package/dist/rails/google/verify.d.ts.map +1 -0
  233. package/dist/rails/google/verify.js +76 -0
  234. package/dist/rails/lemonSqueezy/api.d.ts +92 -0
  235. package/dist/rails/lemonSqueezy/api.d.ts.map +1 -0
  236. package/dist/rails/lemonSqueezy/api.js +121 -0
  237. package/dist/rails/lemonSqueezy/checkout.d.ts +52 -0
  238. package/dist/rails/lemonSqueezy/checkout.d.ts.map +1 -0
  239. package/dist/rails/lemonSqueezy/checkout.js +84 -0
  240. package/dist/rails/lemonSqueezy/discounts.d.ts +50 -0
  241. package/dist/rails/lemonSqueezy/discounts.d.ts.map +1 -0
  242. package/dist/rails/lemonSqueezy/discounts.js +75 -0
  243. package/dist/rails/lemonSqueezy/fixtures/events.d.ts +56 -0
  244. package/dist/rails/lemonSqueezy/fixtures/events.d.ts.map +1 -0
  245. package/dist/rails/lemonSqueezy/fixtures/events.js +144 -0
  246. package/dist/rails/lemonSqueezy/objects.d.ts +229 -0
  247. package/dist/rails/lemonSqueezy/objects.d.ts.map +1 -0
  248. package/dist/rails/lemonSqueezy/objects.js +379 -0
  249. package/dist/rails/lemonSqueezy/portal.d.ts +35 -0
  250. package/dist/rails/lemonSqueezy/portal.d.ts.map +1 -0
  251. package/dist/rails/lemonSqueezy/portal.js +18 -0
  252. package/dist/rails/lemonSqueezy/pricing.d.ts +25 -0
  253. package/dist/rails/lemonSqueezy/pricing.d.ts.map +1 -0
  254. package/dist/rails/lemonSqueezy/pricing.js +54 -0
  255. package/dist/rails/lemonSqueezy/rail.d.ts +41 -0
  256. package/dist/rails/lemonSqueezy/rail.d.ts.map +1 -0
  257. package/dist/rails/lemonSqueezy/rail.js +67 -0
  258. package/dist/rails/lemonSqueezy/read.d.ts +28 -0
  259. package/dist/rails/lemonSqueezy/read.d.ts.map +1 -0
  260. package/dist/rails/lemonSqueezy/read.js +37 -0
  261. package/dist/rails/lemonSqueezy/refresh.d.ts +42 -0
  262. package/dist/rails/lemonSqueezy/refresh.d.ts.map +1 -0
  263. package/dist/rails/lemonSqueezy/refresh.js +40 -0
  264. package/dist/rails/lemonSqueezy/signature.d.ts +56 -0
  265. package/dist/rails/lemonSqueezy/signature.d.ts.map +1 -0
  266. package/dist/rails/lemonSqueezy/signature.js +92 -0
  267. package/dist/rails/lemonSqueezy/verify.d.ts +33 -0
  268. package/dist/rails/lemonSqueezy/verify.d.ts.map +1 -0
  269. package/dist/rails/lemonSqueezy/verify.js +41 -0
  270. package/dist/rails/lemonSqueezy/webhook.d.ts +53 -0
  271. package/dist/rails/lemonSqueezy/webhook.d.ts.map +1 -0
  272. package/dist/rails/lemonSqueezy/webhook.js +179 -0
  273. package/dist/rails/paddle/adjustments.d.ts +60 -0
  274. package/dist/rails/paddle/adjustments.d.ts.map +1 -0
  275. package/dist/rails/paddle/adjustments.js +66 -0
  276. package/dist/rails/paddle/api.d.ts +138 -0
  277. package/dist/rails/paddle/api.d.ts.map +1 -0
  278. package/dist/rails/paddle/api.js +152 -0
  279. package/dist/rails/paddle/checkout.d.ts +69 -0
  280. package/dist/rails/paddle/checkout.d.ts.map +1 -0
  281. package/dist/rails/paddle/checkout.js +100 -0
  282. package/dist/rails/paddle/discounts.d.ts +67 -0
  283. package/dist/rails/paddle/discounts.d.ts.map +1 -0
  284. package/dist/rails/paddle/discounts.js +73 -0
  285. package/dist/rails/paddle/events.d.ts +140 -0
  286. package/dist/rails/paddle/events.d.ts.map +1 -0
  287. package/dist/rails/paddle/events.js +183 -0
  288. package/dist/rails/paddle/fixtures/browserForged.d.ts +42 -0
  289. package/dist/rails/paddle/fixtures/browserForged.d.ts.map +1 -0
  290. package/dist/rails/paddle/fixtures/browserForged.js +52 -0
  291. package/dist/rails/paddle/fixtures/pausedSubscription.d.ts +78 -0
  292. package/dist/rails/paddle/fixtures/pausedSubscription.d.ts.map +1 -0
  293. package/dist/rails/paddle/fixtures/pausedSubscription.js +76 -0
  294. package/dist/rails/paddle/objects.d.ts +519 -0
  295. package/dist/rails/paddle/objects.d.ts.map +1 -0
  296. package/dist/rails/paddle/objects.js +588 -0
  297. package/dist/rails/paddle/portal.d.ts +45 -0
  298. package/dist/rails/paddle/portal.d.ts.map +1 -0
  299. package/dist/rails/paddle/portal.js +42 -0
  300. package/dist/rails/paddle/rail.d.ts +55 -0
  301. package/dist/rails/paddle/rail.d.ts.map +1 -0
  302. package/dist/rails/paddle/rail.js +117 -0
  303. package/dist/rails/paddle/read.d.ts +53 -0
  304. package/dist/rails/paddle/read.d.ts.map +1 -0
  305. package/dist/rails/paddle/read.js +66 -0
  306. package/dist/rails/paddle/recorded.d.ts +49 -0
  307. package/dist/rails/paddle/recorded.d.ts.map +1 -0
  308. package/dist/rails/paddle/recorded.js +79 -0
  309. package/dist/rails/paddle/refresh.d.ts +54 -0
  310. package/dist/rails/paddle/refresh.d.ts.map +1 -0
  311. package/dist/rails/paddle/refresh.js +94 -0
  312. package/dist/rails/paddle/refund.d.ts +82 -0
  313. package/dist/rails/paddle/refund.d.ts.map +1 -0
  314. package/dist/rails/paddle/refund.js +175 -0
  315. package/dist/rails/paddle/signature.d.ts +83 -0
  316. package/dist/rails/paddle/signature.d.ts.map +1 -0
  317. package/dist/rails/paddle/signature.js +163 -0
  318. package/dist/rails/paddle/subscription.d.ts +137 -0
  319. package/dist/rails/paddle/subscription.d.ts.map +1 -0
  320. package/dist/rails/paddle/subscription.js +538 -0
  321. package/dist/rails/paddle/verify.d.ts +46 -0
  322. package/dist/rails/paddle/verify.d.ts.map +1 -0
  323. package/dist/rails/paddle/verify.js +43 -0
  324. package/dist/rails/paddle/webhook.d.ts +98 -0
  325. package/dist/rails/paddle/webhook.d.ts.map +1 -0
  326. package/dist/rails/paddle/webhook.js +181 -0
  327. package/dist/rails/providers.d.ts +73 -0
  328. package/dist/rails/providers.d.ts.map +1 -0
  329. package/dist/rails/providers.js +62 -0
  330. package/dist/rails/stripe/api.d.ts +118 -0
  331. package/dist/rails/stripe/api.d.ts.map +1 -0
  332. package/dist/rails/stripe/api.js +153 -0
  333. package/dist/rails/stripe/checkout.d.ts +60 -0
  334. package/dist/rails/stripe/checkout.d.ts.map +1 -0
  335. package/dist/rails/stripe/checkout.js +86 -0
  336. package/dist/rails/stripe/discounts.d.ts +50 -0
  337. package/dist/rails/stripe/discounts.d.ts.map +1 -0
  338. package/dist/rails/stripe/discounts.js +87 -0
  339. package/dist/rails/stripe/fixtures/events.d.ts +64 -0
  340. package/dist/rails/stripe/fixtures/events.d.ts.map +1 -0
  341. package/dist/rails/stripe/fixtures/events.js +67 -0
  342. package/dist/rails/stripe/objects.d.ts +237 -0
  343. package/dist/rails/stripe/objects.d.ts.map +1 -0
  344. package/dist/rails/stripe/objects.js +389 -0
  345. package/dist/rails/stripe/portal.d.ts +29 -0
  346. package/dist/rails/stripe/portal.d.ts.map +1 -0
  347. package/dist/rails/stripe/portal.js +41 -0
  348. package/dist/rails/stripe/pricing.d.ts +25 -0
  349. package/dist/rails/stripe/pricing.d.ts.map +1 -0
  350. package/dist/rails/stripe/pricing.js +68 -0
  351. package/dist/rails/stripe/rail.d.ts +28 -0
  352. package/dist/rails/stripe/rail.d.ts.map +1 -0
  353. package/dist/rails/stripe/rail.js +81 -0
  354. package/dist/rails/stripe/refresh.d.ts +33 -0
  355. package/dist/rails/stripe/refresh.d.ts.map +1 -0
  356. package/dist/rails/stripe/refresh.js +21 -0
  357. package/dist/rails/stripe/signature.d.ts +71 -0
  358. package/dist/rails/stripe/signature.d.ts.map +1 -0
  359. package/dist/rails/stripe/signature.js +92 -0
  360. package/dist/rails/stripe/verify.d.ts +15 -0
  361. package/dist/rails/stripe/verify.d.ts.map +1 -0
  362. package/dist/rails/stripe/verify.js +63 -0
  363. package/dist/rails/stripe/webhook.d.ts +26 -0
  364. package/dist/rails/stripe/webhook.d.ts.map +1 -0
  365. package/dist/rails/stripe/webhook.js +31 -0
  366. package/dist/secret/registry.d.ts +192 -0
  367. package/dist/secret/registry.d.ts.map +1 -0
  368. package/dist/secret/registry.js +154 -0
  369. package/dist/seeds/example.d.ts +3 -0
  370. package/dist/seeds/example.d.ts.map +1 -0
  371. package/dist/seeds/example.js +171 -0
  372. package/dist/version.generated.d.ts +5 -0
  373. package/dist/version.generated.d.ts.map +1 -0
  374. package/dist/version.generated.js +7 -0
  375. package/dist/workflows/paddleSweep.d.ts +175 -0
  376. package/dist/workflows/paddleSweep.d.ts.map +1 -0
  377. package/dist/workflows/paddleSweep.js +433 -0
  378. package/dist/workflows/railAccess.d.ts +48 -0
  379. package/dist/workflows/railAccess.d.ts.map +1 -0
  380. package/dist/workflows/railAccess.js +36 -0
  381. package/dist/workflows/reconcile.d.ts +161 -0
  382. package/dist/workflows/reconcile.d.ts.map +1 -0
  383. package/dist/workflows/reconcile.js +352 -0
  384. package/dist/workflows/report.d.ts +28 -0
  385. package/dist/workflows/report.d.ts.map +1 -0
  386. package/dist/workflows/report.js +54 -0
  387. package/dist/workflows/retryPolicy.d.ts +29 -0
  388. package/dist/workflows/retryPolicy.d.ts.map +1 -0
  389. package/dist/workflows/retryPolicy.js +37 -0
  390. package/dist/workflows/specs.d.ts +102 -0
  391. package/dist/workflows/specs.d.ts.map +1 -0
  392. package/dist/workflows/specs.js +84 -0
  393. package/dist/workflows/worker.d.ts +62 -0
  394. package/dist/workflows/worker.d.ts.map +1 -0
  395. package/dist/workflows/worker.js +92 -0
  396. package/dist/workflows/workerConfig.d.ts +46 -0
  397. package/dist/workflows/workerConfig.d.ts.map +1 -0
  398. package/dist/workflows/workerConfig.js +38 -0
  399. package/package.json +22 -13
  400. package/pithy.manifest.json +19 -13
  401. package/src/version.generated.ts +1 -1
  402. package/src/client/paddlePrices.iife.ts +0 -43
@@ -0,0 +1,538 @@
1
+ import { PaymentsProviderUnavailableError, PaymentsSubscriptionChangeRefusedError } from "../../error/errors.js";
2
+ import { SubscriptionChangeQuote, SubscriptionStanding } from "../../data/subscription.js";
3
+ import { paddleHttpFetch, paddleJson } from "./api.js";
4
+ import { PaddleSubscription, PaddleSubscriptionPreview, currencyOf, minorAmount, subscriptionPendingChange, subscriptionStatus } from "./objects.js";
5
+ import { renderMoney } from "../../data/renderMoney.js";
6
+ import { z } from "zod";
7
+ //#region src/rails/paddle/subscription.ts
8
+ /**
9
+ * What happens to a change that cannot be collected: nothing.
10
+ *
11
+ * `prevent_change` is Paddle's own default and it is sent anyway, on every write, so the invariant lives in
12
+ * this file rather than in Paddle's release notes. The alternative values let a subscription move to a plan
13
+ * whose first payment failed, which is an upgrade granted and unpaid — and it is not configurable here for
14
+ * the reason no billing enum is: a parameter is a thing a caller eventually sets.
15
+ */
16
+ const ON_PAYMENT_FAILURE = "prevent_change";
17
+ /** A price's unit cost, as Paddle states one. */
18
+ const PaddleUnitPrice = z.object({
19
+ amount: z.string().describe("What one unit costs, as an integer string in the currency's lowest denomination. Never scaled here."),
20
+ currency_code: z.string().nullish().describe("The currency, uppercase ISO 4217, as Paddle sends it.")
21
+ }).loose().describe("What one unit of a price costs. Compared against another price's, and never arithmetic'd.");
22
+ /**
23
+ * How often a price bills.
24
+ *
25
+ * Read only to answer one question — whether a change alters the billing frequency — because Paddle permits
26
+ * only immediate proration modes when it does. See {@link prorationModeFor}.
27
+ */
28
+ const PaddleBillingCycle = z.object({
29
+ interval: z.string().describe("`day`, `week`, `month`, or `year`."),
30
+ frequency: z.number().describe("How many of that interval one billing period spans.")
31
+ }).loose().describe("A price's billing period, as the two halves Paddle states it in.");
32
+ /**
33
+ * One line on a subscription, as this rail has to be able to reproduce it.
34
+ *
35
+ * Declared here rather than widened onto `PaddleSubscription` in `objects.ts`, whose item shape reads only
36
+ * the price id: four modules already depend on that type, and adding required-feeling fields to it in the
37
+ * commit that adds a subscription rail is how a shape used by the webhook parser changes for a reason the
38
+ * webhook parser has nothing to do with.
39
+ *
40
+ * **`quantity` is `unknown` on purpose.** A typed `z.number()` here would fail the whole item's parse when
41
+ * Paddle sent something else, and the refusal a caller reads would name the item rather than the quantity —
42
+ * where the quantity is precisely the thing this rail refuses to guess. It is checked below, by hand, so the
43
+ * sentence names it.
44
+ */
45
+ const PaddleItemLine = z.object({
46
+ price: z.object({
47
+ id: z.string().min(1).describe("The price this line bills at — `pri_…`."),
48
+ unit_price: PaddleUnitPrice.nullish().describe("What one unit costs. The left-hand side of a direction."),
49
+ billing_cycle: PaddleBillingCycle.nullish().describe("How often it bills, when Paddle stated it.")
50
+ }).loose().describe("The price on this line, with the two facts a change needs from it."),
51
+ quantity: z.unknown().describe("How many. Read untyped so an unusable value refuses by name rather than by shape.")
52
+ }).loose().describe("One priced line on a subscription — everything needed to send it back unchanged.");
53
+ /** A price entity, as `GET /prices/{id}` answers one. */
54
+ const PaddlePriceEntity = z.object({
55
+ id: z.string().min(1).describe("The price — `pri_…`."),
56
+ unit_price: PaddleUnitPrice.nullish().describe("What one unit costs. The right-hand side of a direction."),
57
+ billing_cycle: PaddleBillingCycle.nullish().describe("How often it bills, when Paddle stated it.")
58
+ }).loose().describe("A Paddle price, narrowed to what choosing a proration mode needs of one.");
59
+ /**
60
+ * A change preview, plus the one entity field a quote's dates come from.
61
+ *
62
+ * `next_billed_at` is not part of `PaddleSubscriptionPreview` because that shape claims only the three keys
63
+ * the recordings measured. A preview response is a whole subscription entity carrying those three, and the
64
+ * day the deferred credit lands is the entity's own `next_billed_at` — recorded `2026-09-15T11:42:21.789736Z`
65
+ * on the downgrade, and equal there to `next_transaction.billing_period.starts_at`. The entity field is the
66
+ * one read, because the other lives inside a block that is absent whenever nothing is deferred.
67
+ */
68
+ const PaddleChangePreview = PaddleSubscriptionPreview.extend({ next_billed_at: z.string().nullish().describe("When the next invoice falls — the day a deferred credit lands, and the day a new rate starts.") }).describe("Paddle's preview of a subscription change, with the entity date the quote's two moments come from.");
69
+ /** A subscription cannot be changed the way it was asked. 409, with the reason in `detail`. */
70
+ function refuse(detail) {
71
+ throw new PaymentsSubscriptionChangeRefusedError({ detail });
72
+ }
73
+ /**
74
+ * Paddle answered something this build cannot read. 503, so the screen says it could not look.
75
+ *
76
+ * Not a refusal: nothing about the subscription is wrong, and telling a customer their plan cannot be
77
+ * changed because a response had an unfamiliar shape would be a true sentence about the wrong thing.
78
+ */
79
+ function unreadable(detail) {
80
+ throw new PaymentsProviderUnavailableError({ detail });
81
+ }
82
+ /** A string worth reading, or null. `""` is not a date and not a currency. */
83
+ function orNull(value) {
84
+ return value === null || value === void 0 || value === "" ? null : value;
85
+ }
86
+ /**
87
+ * The subscription this purchase names, or null when it names none.
88
+ *
89
+ * Paddle's ids are globally prefixed, so the row's own key says what it is — `refreshPaddlePurchase`'s rule,
90
+ * and for the same reason: a money row's family key is `sub_…`, and falling back to it would act on a
91
+ * subscription from a row that is not one.
92
+ */
93
+ function subscriptionIdOf(purchase) {
94
+ const id = purchase.providerTransactionId;
95
+ return id.startsWith("sub_") ? id : null;
96
+ }
97
+ /** The subscription, or a refusal. Used by the write verbs, which have nothing to do without it. */
98
+ async function loadSubscription(id, options) {
99
+ const subscription = await readOne(id, options);
100
+ if (subscription === void 0) refuse(`Paddle has no subscription ${id}, so there is nothing on it to change.`);
101
+ return subscription;
102
+ }
103
+ /** The subscription, or `undefined` when Paddle has none. */
104
+ async function readOne(id, options) {
105
+ const answer = await paddleJson(options.transport ?? paddleHttpFetch, `/subscriptions/${encodeURIComponent(id)}`, {
106
+ what: `subscription ${id}`,
107
+ apiKey: options.credentials.apiKey,
108
+ environment: options.environment,
109
+ absentOn404: true
110
+ });
111
+ if (answer === void 0) return void 0;
112
+ const parsed = PaddleSubscription.safeParse(answer.data);
113
+ if (!parsed.success) unreadable(`Paddle answered for subscription ${id} in a shape this build cannot read.`);
114
+ return parsed.data;
115
+ }
116
+ /**
117
+ * The one line this subscription bills, and the quantity to send back — or a refusal naming what stopped it.
118
+ *
119
+ * **Paddle's update replaces the items array.** An item omitted from the request is removed from the
120
+ * subscription, and a quantity left out of an item Paddle has never seen is a quantity Paddle picks. So both
121
+ * failures are silent writes to somebody's billing: a five-seat subscription rewritten as `quantity: 1` is
122
+ * four seats canceled, and a two-item subscription rewritten as one item is an add-on deleted. Neither is
123
+ * distinguishable afterwards from a change the customer asked for.
124
+ *
125
+ * A 409 is recoverable by a human in a minute. A dropped add-on is discovered on an invoice. So anything
126
+ * this rail cannot reproduce exactly, it refuses.
127
+ */
128
+ function currentLine(subscription) {
129
+ const items = subscription.items ?? [];
130
+ if (items.length !== 1) refuse(`Paddle subscription ${subscription.id} carries ${items.length} items, and this rail rewrites the whole array on a change. Reproducing anything but a single line would mean guessing which to keep.`);
131
+ const parsed = PaddleItemLine.safeParse(items[0]);
132
+ if (!parsed.success) refuse(`Paddle subscription ${subscription.id} carries an item this rail cannot reproduce: ${parsed.error.message}`);
133
+ const line = parsed.data;
134
+ if (typeof line.quantity !== "number" || !Number.isSafeInteger(line.quantity) || line.quantity < 1) refuse(`Paddle subscription ${subscription.id} states a quantity of ${JSON.stringify(line.quantity)} on price ${line.price.id}, and a rewritten items array has to carry it back exactly. Guessing one over- or under-charges a real card.`);
135
+ return {
136
+ point: pricePointOf(line.price.id, line.price, `subscription ${subscription.id}`),
137
+ quantity: line.quantity
138
+ };
139
+ }
140
+ /** A comparable price point, or a refusal — a direction cannot be read from an amount that is not there. */
141
+ function pricePointOf(priceId, price, where) {
142
+ const amountMinor = minorAmount(price.unit_price?.amount);
143
+ const currency = currencyOf(price.unit_price?.currency_code);
144
+ if (amountMinor === null || currency === null) refuse(`Paddle states no readable unit price for ${priceId} on ${where}, so this rail cannot tell an upgrade from a downgrade. Charging immediately on a guess takes money a downgrading customer is owed.`);
145
+ const cycle = PaddleBillingCycle.safeParse(price.billing_cycle);
146
+ return {
147
+ priceId,
148
+ amountMinor,
149
+ currency,
150
+ cycle: cycle.success ? `${cycle.data.interval}:${cycle.data.frequency}` : null
151
+ };
152
+ }
153
+ /** The price being moved to. Needs `price.read` on the key, which the refusal names. */
154
+ async function readTargetPrice(priceId, options) {
155
+ const answer = await paddleJson(options.transport ?? paddleHttpFetch, `/prices/${encodeURIComponent(priceId)}`, {
156
+ what: `price ${priceId} (this key needs the price.read permission)`,
157
+ apiKey: options.credentials.apiKey,
158
+ environment: options.environment
159
+ });
160
+ const parsed = PaddlePriceEntity.safeParse(answer?.data);
161
+ if (!parsed.success) unreadable(`Paddle answered for price ${priceId} in a shape this build cannot read.`);
162
+ return pricePointOf(priceId, parsed.data, "the price being moved to");
163
+ }
164
+ /**
165
+ * Which of Paddle's two behaviors a change routes to. **This chooses a behavior; it does not compute money.**
166
+ *
167
+ * The settled policy (2026-08-28), and the direction is the whole input:
168
+ *
169
+ * - **Up, or sideways at the same price — `prorated_immediately`.** The customer is charged the difference
170
+ * now, and the recorded upgrade takes 6582 today.
171
+ * - **Down — `prorated_next_billing_period`.** The tier moves now and the credit lands on the next invoice.
172
+ * The recorded downgrade owes 6558 on 15 September and settles nothing today.
173
+ *
174
+ * **Equal counts as up**, and the boundary is deliberate. A move between two prices of the same size settles
175
+ * nothing either way, and deferring it would leave a plan changed today with a phantom line waiting on an
176
+ * invoice a month out.
177
+ *
178
+ * **A currency mismatch refuses rather than comparing.** 600 EUR against 11000 USD is not a comparison, and
179
+ * the wrong answer either takes money from a downgrading customer today or defers a charge the store
180
+ * expected to collect.
181
+ *
182
+ * **A change of billing frequency is immediate whatever the direction, because Paddle allows nothing else.**
183
+ * Its documentation is explicit that only `prorated_immediately`, `full_immediately` and `do_not_bill` are
184
+ * accepted when the billing cycle changes, so a monthly→annual downgrade sent deferred is a 400 — which this
185
+ * rail maps to `rail_not_configured`, sending an operator to check a key that is fine. `do_not_bill` is a
186
+ * free change and unreachable here, so `prorated_immediately` is the only mode left; the recorded downgrade
187
+ * under it settles `grand_total: "0"` with the whole credit on the customer's balance, which is the honest
188
+ * outcome rather than a surprise charge. It fires only when Paddle stated both cycles: an unstated one is
189
+ * not evidence of a difference.
190
+ */
191
+ function prorationModeFor(current, target) {
192
+ if (current.currency !== target.currency) refuse(`Paddle prices ${current.priceId} in ${current.currency} and ${target.priceId} in ${target.currency}, and two currencies do not order. This rail picks a proration mode from the direction of the change, and there is no direction to read.`);
193
+ if (current.cycle !== null && target.cycle !== null && current.cycle !== target.cycle) return "prorated_immediately";
194
+ return target.amountMinor >= current.amountMinor ? "prorated_immediately" : "prorated_next_billing_period";
195
+ }
196
+ /** The body both writes send, and the one the preview sends — identical, as Paddle's own guidance requires. */
197
+ function changeBody(priceId, quantity, mode) {
198
+ return {
199
+ items: [{
200
+ price_id: priceId,
201
+ quantity
202
+ }],
203
+ proration_billing_mode: mode,
204
+ on_payment_failure: ON_PAYMENT_FAILURE
205
+ };
206
+ }
207
+ /** Where a subscription stands, from an entity Paddle answered with. */
208
+ function standingOf(subscription) {
209
+ const pending = subscriptionPendingChange(subscription);
210
+ const currency = subscription.currency_code;
211
+ const parsed = SubscriptionStanding.safeParse({
212
+ status: subscriptionStatus(subscription.status),
213
+ currency: currencyOf(typeof currency === "string" ? currency : null),
214
+ currentPeriodEndsAt: orNull(subscription.current_billing_period?.ends_at),
215
+ nextBilledAt: orNull(subscription.next_billed_at),
216
+ scheduledChange: pending === null ? null : {
217
+ action: pending.action,
218
+ effectiveAt: pending.effectiveAt,
219
+ resumesAt: pending.resumeAt
220
+ }
221
+ });
222
+ if (!parsed.success) unreadable(`Paddle described subscription ${subscription.id} in a way this build cannot state: ${parsed.error.message}`);
223
+ return parsed.data;
224
+ }
225
+ /**
226
+ * What settles, from Paddle's own reconciliation of the change.
227
+ *
228
+ * `update_summary.result` and nothing else. The alternative — the immediate transaction's totals — is right
229
+ * on an upgrade and silently wrong on a downgrade, where `grand_total` is `"0"` while 6581 sits in
230
+ * `credit_to_balance`: a screen wired to it says "you will be charged $0.00" and never mentions the money.
231
+ *
232
+ * An action this build does not map refuses rather than being rendered as itself, which is `subscriptionStatus`'s
233
+ * rule. A third verb quietly read as a charge is the wrong direction in front of a paying customer.
234
+ *
235
+ * **`DeferredSubscriptionSettlement`, not `SubscriptionSettlement`** — the union without `nothing`. What
236
+ * Paddle summarized is always a charge or a credit; `nothing` is a statement about *today* that this function
237
+ * has no standing to make, and typing it wider let a `nothing` compile into `nextInvoice.settlement`, which
238
+ * is a row about no money, dated. The narrower union is what refused it, at build time (#465).
239
+ *
240
+ * **The whole summary rather than its `result`, since #96.** The reconciliation Paddle performed is three
241
+ * figures and the net is one of them; a function handed only the net cannot report the two it reconciles, and
242
+ * the screen that showed it had a customer asking why $48.83 was neither of the prices in front of them. The
243
+ * halves are read here, beside the net, from the same object — never carried in separately, which is how they
244
+ * would come to describe a different change than the amount they sit under.
245
+ */
246
+ function settlementOf(summary, locale) {
247
+ const result = summary.result;
248
+ if (result.action !== "charge" && result.action !== "credit") unreadable(`Paddle summarized a subscription change as "${result.action}", which is not an outcome this build maps.`);
249
+ const amountMinor = minorAmount(result.amount);
250
+ const currency = currencyOf(result.currency_code);
251
+ if (amountMinor === null || currency === null) unreadable(`Paddle summarized a subscription change as ${result.action} of ${JSON.stringify(result.amount)} ${JSON.stringify(result.currency_code)}, which is not an amount this build can state.`);
252
+ return {
253
+ outcome: result.action,
254
+ amount: quotedMoney(amountMinor, currency, locale, result.action),
255
+ madeUpOf: partsOf(summary, locale)
256
+ };
257
+ }
258
+ /**
259
+ * The charge and the credit the net reconciles, or null when Paddle did not state both in full.
260
+ *
261
+ * **Null is the whole of the failure handling here, and that is deliberate.** Everywhere else in this file an
262
+ * unreadable figure throws, because everywhere else the figure *is* the answer. This one is an explanation of
263
+ * an answer that already parsed: refusing the quote because a supporting number lacked a currency would take a
264
+ * working confirmation screen away over a detail the customer never asked for. `update_summary.credit` arrived
265
+ * as `{ amount: "-6936" }` with no `currency_code` on a real recording, so this is a shape Paddle sends.
266
+ *
267
+ * **No currency is borrowed from the net.** It is the one shortcut available and it renders a guess as a
268
+ * price. A missing half is reported as missing.
269
+ */
270
+ function partsOf(summary, locale) {
271
+ const charge = quotedOrNull(summary.charge?.amount, summary.charge?.currency_code, locale);
272
+ const credit = quotedOrNull(summary.credit?.amount, summary.credit?.currency_code, locale);
273
+ return charge === null || credit === null ? null : {
274
+ charge,
275
+ credit
276
+ };
277
+ }
278
+ /**
279
+ * One supporting figure, or null when it is not a stateable amount. **Never throws** — see {@link partsOf}.
280
+ *
281
+ * The amount and the currency arrive separately because the two blocks this reads carry them that way:
282
+ * `update_summary` puts a `currency_code` on each half, and a totals block states one for the whole block.
283
+ * Taking a money object would have made the second call site build one, which is a shape invented to fit a
284
+ * signature rather than to describe anything.
285
+ */
286
+ function quotedOrNull(amount, currencyCode, locale) {
287
+ if (amount === null || amount === void 0) return null;
288
+ const amountMinor = minorAmount(amount);
289
+ const currency = currencyOf(currencyCode);
290
+ if (amountMinor === null || currency === null) return null;
291
+ const rendered = renderMoney(amountMinor, currency, locale);
292
+ return rendered === null ? null : {
293
+ amountMinor,
294
+ currency,
295
+ rendered
296
+ };
297
+ }
298
+ /**
299
+ * One figure, with the string a screen shows it as.
300
+ *
301
+ * **Rendering is not the same check as parsing, and this is where the second one fails.** `currencyOf`
302
+ * lowercases whatever Paddle sent and answers null only for an empty string, so a store answering
303
+ * `currency_code: "dollars"` reaches here with an amount that parses and a currency nothing can put a
304
+ * symbol on. `renderMoney` answers null for it, and null is refused the way every other unreadable figure
305
+ * in this file is — a shape change reported as one, rather than a `RangeError` out of `Intl` arriving at a
306
+ * customer's confirmation screen as a 500.
307
+ */
308
+ function quotedMoney(amountMinor, currency, locale, what) {
309
+ const rendered = renderMoney(amountMinor, currency, locale);
310
+ if (rendered === null) unreadable(`Paddle stated the ${what} of a subscription change in ${JSON.stringify(currency)}, which is not a currency this build can name. The amount parses and cannot be shown to anybody.`);
311
+ return {
312
+ amountMinor,
313
+ currency,
314
+ rendered
315
+ };
316
+ }
317
+ /**
318
+ * A quote, from a preview response.
319
+ *
320
+ * **`update_summary.result` says *what* the change is worth; whether an `immediate_transaction` exists says
321
+ * *when* it lands.** That is the rule the recordings established and the one a two-part quote could not hold:
322
+ * the deferred downgrade answers `immediate_transaction: null` *and* `result: { action: "credit", amount:
323
+ * "6558" }` at the same time. Read `result` as today's headline and the screen promises money the customer
324
+ * will look for and not find; read the missing transaction as the whole answer and 65.58 dollars disappear
325
+ * from the quote.
326
+ *
327
+ * A missing summary is a shape change and not a free change, so it throws rather than settling `nothing`.
328
+ * "This costs you nothing" is a sentence that must come from Paddle, never from a field being absent.
329
+ */
330
+ function quoteOf(data, priceId, locale) {
331
+ const preview = PaddleChangePreview.safeParse(data);
332
+ if (!preview.success) unreadable(`Paddle previewed a move to ${priceId} in a shape this build cannot read.`);
333
+ const answer = preview.data;
334
+ const summary = answer.update_summary;
335
+ if (summary === null || summary === void 0) unreadable(`Paddle previewed a move to ${priceId} with no \`update_summary\`, so what the change costs is unstated. A quote cannot be built from its absence.`);
336
+ const settlement = settlementOf(summary, locale);
337
+ const settlesToday = answer.immediate_transaction !== null && answer.immediate_transaction !== void 0;
338
+ const nextBilledAt = orNull(answer.next_billed_at);
339
+ if (!settlesToday && nextBilledAt === null) unreadable(`Paddle previewed a move to ${priceId} that settles nothing today and named no next billing date, so the ${settlement.outcome} of ${settlement.amount.amountMinor} has no day to land on.`);
340
+ const quote = {
341
+ settlesToday: settlesToday ? settlement : { outcome: "nothing" },
342
+ nextInvoice: settlesToday || nextBilledAt === null ? null : {
343
+ settlement,
344
+ at: new Date(nextBilledAt)
345
+ },
346
+ recurring: recurringOf(answer, nextBilledAt, priceId, locale)
347
+ };
348
+ const parsed = SubscriptionChangeQuote.safeParse(quote);
349
+ if (!parsed.success) unreadable(`Paddle's preview of a move to ${priceId} does not state a quote: ${parsed.error.message}`);
350
+ return parsed.data;
351
+ }
352
+ /**
353
+ * What the subscription pays each period after the change, or null when nothing renews.
354
+ *
355
+ * **The two nulls this separates are not the same claim, and collapsing them costs one of them.** No next
356
+ * billing date is Paddle saying the subscription is ending — reachable today, because a preview may be asked
357
+ * for on a subscription with a cancellation already scheduled, where `next_billed_at` is blank and the
358
+ * status is still `active` (recorded 2026-08-28). That is a sentence a screen writes, so it is a null. A
359
+ * *stated* renewal date with no readable recurring block is the provider declining to answer, which is a
360
+ * shape change and throws — because the alternative is inventing a figure, and the invented one is zero.
361
+ */
362
+ function recurringOf(answer, nextBilledAt, priceId, locale) {
363
+ if (nextBilledAt === null) return null;
364
+ const totals = answer.recurring_transaction_details?.totals;
365
+ const amountMinor = minorAmount(totals?.grand_total ?? totals?.total);
366
+ const currency = currencyOf(totals?.currency_code);
367
+ if (amountMinor === null || currency === null) unreadable(`Paddle previewed a move to ${priceId} renewing on ${nextBilledAt} without saying what it pays then. A rail with no recurring answer has a shape change to report, not a null to invent.`);
368
+ return {
369
+ amount: quotedMoney(amountMinor, currency, locale, "renewal"),
370
+ startsAt: new Date(nextBilledAt),
371
+ madeUpOf: recurringPartsOf(totals, locale)
372
+ };
373
+ }
374
+ /**
375
+ * The base and the tax the renewal figure is the sum of, or null when Paddle did not state both in full.
376
+ *
377
+ * **Null rather than a throw, for {@link partsOf}'s reason exactly**: the renewal amount has already been
378
+ * read and refused if unreadable, and this explains that amount rather than being it. A preview whose
379
+ * totals block omits `tax` is a screen with one figure instead of three, not a plan change a customer
380
+ * cannot make.
381
+ *
382
+ * **`subtotal` and not `total - tax`.** Paddle states the base, after any discount; deriving it would be
383
+ * this package computing money, and it would be right only for as long as `discount` stays `"0"`.
384
+ */
385
+ function recurringPartsOf(totals, locale) {
386
+ const beforeTax = quotedOrNull(totals?.subtotal, totals?.currency_code, locale);
387
+ const tax = quotedOrNull(totals?.tax, totals?.currency_code, locale);
388
+ return beforeTax === null || tax === null ? null : {
389
+ beforeTax,
390
+ tax
391
+ };
392
+ }
393
+ /**
394
+ * Where this subscription stands now, or `undefined` when Paddle has nothing to say about this purchase.
395
+ *
396
+ * Read live, because the one fact it exists to report is the one a projected row does not carry: with a
397
+ * cancellation scheduled Paddle answers `status: "active"`, `canceled_at: null` and `next_billed_at: null`
398
+ * (recorded 2026-08-28). Two of those say the subscription is fine and the third says nothing, so the end
399
+ * date lives only on `scheduled_change.effective_at` — and a webhook announcing it can be dropped.
400
+ */
401
+ async function readPaddleStanding(purchase, options) {
402
+ const id = subscriptionIdOf(purchase);
403
+ if (id === null) return void 0;
404
+ const subscription = await readOne(id, options);
405
+ return subscription === void 0 ? void 0 : standingOf(subscription);
406
+ }
407
+ /**
408
+ * What moving to this price would cost, as Paddle previews it.
409
+ *
410
+ * **A read, so the no-op rule does not apply.** Previewing the plan already held is a question with an honest
411
+ * answer and asking it takes nothing; skipping the call would mean inventing a recurring figure to fill the
412
+ * quote with, which is the one thing this package will not do.
413
+ *
414
+ * The item refusals *do* apply, because the preview body is the update body: a preview built from a rewritten
415
+ * items array quotes a change that is not the one the update would make.
416
+ *
417
+ * A subscription with a change already scheduled is not refused here. Refusing a read on the grounds of state
418
+ * would hide the figures from the screen that has to explain why the move cannot be made yet, and `changePlan`
419
+ * is where the write is stopped.
420
+ *
421
+ * `locale` is the reader the figures are rendered for, and it is a parameter of this method alone: the other
422
+ * four verbs answer a standing, which carries no amount. Absent, the rendering falls back to the kit's own
423
+ * locale rather than failing — see `data/renderMoney.ts`.
424
+ */
425
+ async function previewPaddleChange(input, options, locale) {
426
+ const id = subscriptionIdOf(input.purchase);
427
+ if (id === null) refuse(`Purchase ${input.purchase.id} names no Paddle subscription, so there is nothing to quote.`);
428
+ const { point, quantity } = currentLine(await loadSubscription(id, options));
429
+ const mode = prorationModeFor(point, await readTargetPrice(input.providerProductId, options));
430
+ return quoteOf((await paddleJson(options.transport ?? paddleHttpFetch, `/subscriptions/${encodeURIComponent(id)}/preview`, {
431
+ what: `a preview of subscription ${id} moving to ${input.providerProductId}`,
432
+ apiKey: options.credentials.apiKey,
433
+ environment: options.environment,
434
+ method: "PATCH",
435
+ body: changeBody(input.providerProductId, quantity, mode)
436
+ }))?.data, input.providerProductId, locale);
437
+ }
438
+ /**
439
+ * Move the subscription to a different plan, and answer where it now stands.
440
+ *
441
+ * The answer is Paddle's, not a prediction: the screen that just wrote renders what the store says rather than
442
+ * what the request asked for, and the recorded responses are why — a cancel leaves `status` at `active`, and
443
+ * an update's response is the only place the resulting standing exists.
444
+ *
445
+ * **The plan already held is a success and writes nothing.** These verbs sit behind a network, callers retry,
446
+ * and a second delivery of the same instruction must not become a second proration. A 409 for the state the
447
+ * caller asked for would also simply be wrong — the subscription is how they wanted it. The subscription is
448
+ * still re-read, because the standing that comes back has to be the store's; the rule is about not *writing*
449
+ * twice, and a read takes and gives nothing.
450
+ *
451
+ * **A subscription with a change already scheduled is refused.** Honoring the move means discarding the
452
+ * pending action, and Paddle's own refusal for it arrives as an ordinary 4xx that this rail maps to
453
+ * `rail_not_configured` — a refusal naming the wrong thing. Withdraw the schedule first; that is what
454
+ * {@link keepPaddleSubscription} is for, and it is a separate act the audit trail records separately.
455
+ */
456
+ async function changePaddlePlan(input, options) {
457
+ const id = subscriptionIdOf(input.purchase);
458
+ if (id === null) refuse(`Purchase ${input.purchase.id} names no Paddle subscription, so there is nothing to change.`);
459
+ const subscription = await loadSubscription(id, options);
460
+ const { point, quantity } = currentLine(subscription);
461
+ if (point.priceId === input.providerProductId) return standingOf(subscription);
462
+ const pending = subscriptionPendingChange(subscription);
463
+ if (pending !== null) refuse(`Paddle subscription ${id} is already scheduled to ${pending.action} on ${pending.effectiveAt ?? "an unstated date"}, and moving it to ${input.providerProductId} would discard that. Withdraw the scheduled change first.`);
464
+ const mode = prorationModeFor(point, await readTargetPrice(input.providerProductId, options));
465
+ return standingAnswered((await paddleJson(options.transport ?? paddleHttpFetch, `/subscriptions/${encodeURIComponent(id)}`, {
466
+ what: `subscription ${id} moving to ${input.providerProductId}`,
467
+ apiKey: options.credentials.apiKey,
468
+ environment: options.environment,
469
+ method: "PATCH",
470
+ body: changeBody(input.providerProductId, quantity, mode)
471
+ }))?.data, id);
472
+ }
473
+ /**
474
+ * Stop the subscription renewing, and answer where it now stands.
475
+ *
476
+ * `at_period_end` is Paddle's `next_billing_period` and the settled policy: the tier holds until the paid
477
+ * period runs out. `now` is `immediately`, and it exists because support occasionally has to end one today —
478
+ * and because a policy with no legitimate exit gets departed from by a direct provider call nothing audits.
479
+ *
480
+ * **The no-op is per timing, not per verb.** A subscription scheduled to end on the 15th is not a subscription
481
+ * that ended today, so `now` against a scheduled cancel is a real request and reaches Paddle. What is already
482
+ * true is what is skipped: a period-end cancel on one already scheduled, and an immediate cancel on one the
483
+ * store has already ended.
484
+ */
485
+ async function cancelPaddleSubscription(input, options) {
486
+ const id = subscriptionIdOf(input.purchase);
487
+ if (id === null) refuse(`Purchase ${input.purchase.id} names no Paddle subscription, so there is nothing to cancel.`);
488
+ const subscription = await loadSubscription(id, options);
489
+ const pending = subscriptionPendingChange(subscription);
490
+ const alreadyScheduled = input.timing === "at_period_end" && pending?.action === "cancel";
491
+ const alreadyEnded = input.timing === "now" && subscriptionStatus(subscription.status) === "canceled";
492
+ if (alreadyScheduled || alreadyEnded) return standingOf(subscription);
493
+ return standingAnswered((await paddleJson(options.transport ?? paddleHttpFetch, `/subscriptions/${encodeURIComponent(id)}/cancel`, {
494
+ what: `canceling subscription ${id}`,
495
+ apiKey: options.credentials.apiKey,
496
+ environment: options.environment,
497
+ method: "POST",
498
+ body: { effective_from: input.timing === "now" ? "immediately" : "next_billing_period" }
499
+ }))?.data, id);
500
+ }
501
+ /**
502
+ * Withdraw a scheduled cancellation, so the subscription renews after all.
503
+ *
504
+ * **It withdraws a cancellation, and only a cancellation.** Paddle has no verb for that: the update clears
505
+ * `scheduled_change` *wholesale*, and that field also holds a scheduled pause and a scheduled resume. A rail
506
+ * that simply sent the clear would silently un-pause a paused subscription — the customer's account restarts
507
+ * billing, on a request that said nothing about pausing. So the subscription is re-read and anything but a
508
+ * pending `cancel` is refused, with what was actually scheduled named in `detail`.
509
+ *
510
+ * The check cannot move to the route: the route holds a projected row, and the pending action lives only at
511
+ * the store.
512
+ *
513
+ * **Nothing scheduled is the no-op, not a refusal.** The subscription already renews, which is what the caller
514
+ * asked for, and a retry after a successful withdrawal is exactly that request arriving twice.
515
+ */
516
+ async function keepPaddleSubscription(purchase, options) {
517
+ const id = subscriptionIdOf(purchase);
518
+ if (id === null) refuse(`Purchase ${purchase.id} names no Paddle subscription, so there is nothing to withdraw.`);
519
+ const subscription = await loadSubscription(id, options);
520
+ const pending = subscriptionPendingChange(subscription);
521
+ if (pending === null) return standingOf(subscription);
522
+ if (pending.action !== "cancel") refuse(`Paddle subscription ${id} is scheduled to ${pending.action}, not to cancel. Clearing the schedule is the only withdrawal Paddle offers and it clears the whole field, so honoring this would ${pending.action === "pause" ? "restart billing on a paused account" : "discard a scheduled resume"}.`);
523
+ return standingAnswered((await paddleJson(options.transport ?? paddleHttpFetch, `/subscriptions/${encodeURIComponent(id)}`, {
524
+ what: `withdrawing the scheduled cancellation of subscription ${id}`,
525
+ apiKey: options.credentials.apiKey,
526
+ environment: options.environment,
527
+ method: "PATCH",
528
+ body: { scheduled_change: null }
529
+ }))?.data, id);
530
+ }
531
+ /** The standing in a write's own response. Every write answers the entity, so none of them predicts one. */
532
+ function standingAnswered(data, id) {
533
+ const parsed = PaddleSubscription.safeParse(data);
534
+ if (!parsed.success) unreadable(`Paddle answered a write to subscription ${id} in a shape this build cannot read.`);
535
+ return standingOf(parsed.data);
536
+ }
537
+ //#endregion
538
+ export { cancelPaddleSubscription, changePaddlePlan, keepPaddleSubscription, previewPaddleChange, readPaddleStanding };
@@ -0,0 +1,46 @@
1
+ import type { PaymentsPaddleCredentials } from "../../secret/registry";
2
+ import type { VerifiedPurchase } from "../contract";
3
+ import type { PaddleEnvironment, PaddleHttpFetch } from "./api";
4
+ /**
5
+ * Verifying a transaction id a returning buyer handed back — and why this rail has one where Lemon
6
+ * Squeezy does not.
7
+ *
8
+ * ## What makes a submitted `txn_…` trustworthy here
9
+ *
10
+ * Not that it is unguessable. Lemon Squeezy's order UUID is unguessable too, and `verify.ts` there
11
+ * refuses it at length: an unguessable-but-unauthenticated identifier lets a client's choice of value
12
+ * decide who a purchase belongs to.
13
+ *
14
+ * What makes this one safe is the **check against the caller**, not the id. The transaction is read from
15
+ * Paddle, and its `custom_data.pithy_user` — a value this deployment's own server wrote, with a MAC only
16
+ * this deployment could produce — has to name the authenticated caller. A submitted id that names somebody
17
+ * else is refused, and one carrying no proven reference is refused too. So the id is a *pointer*; the
18
+ * authorization is the stamp.
19
+ *
20
+ * ## Why the rail needs it at all
21
+ *
22
+ * `dev` is not publicly routable, so a dev checkout's webhooks land at `staging` and the dev deployment
23
+ * never hears about its own purchase. The overlay's `checkout.completed` callback hands the browser a
24
+ * `txn_…`; the screen posts it here; this binds it. That is what makes local development work, and it is
25
+ * why `verify` is not optional on this rail the way it is on Lemon Squeezy.
26
+ *
27
+ * It is also the ordinary web nicety: a buyer sees their entitlement the moment the overlay closes rather
28
+ * than when the webhook lands. The webhook stays authoritative, produces the identical row, and the write
29
+ * is idempotent on `(rail, providerTransactionId)`.
30
+ */
31
+ /** What verifying a submitted transaction needs. */
32
+ export interface VerifyPaddleTransactionOptions {
33
+ /** The rail's credentials. `webhookSecret` keys the ownership proof; `apiKey` reads the transaction. */
34
+ credentials: PaymentsPaddleCredentials;
35
+ /** Which Paddle account to read from. */
36
+ environment: PaddleEnvironment;
37
+ /** This deployment's `ENVIRONMENT`. Without it no reference is trusted, so no submission is accepted. */
38
+ deployment?: string;
39
+ /** The clock — the returned event's `providerEventAt`, because a read is a fact about now. */
40
+ now: Date;
41
+ /** The HTTP seam. */
42
+ transport: PaddleHttpFetch;
43
+ }
44
+ /** Verify one submitted Paddle transaction id, and report who it says it belongs to. */
45
+ export declare function verifyPaddleTransaction(receipt: string, options: VerifyPaddleTransactionOptions): Promise<VerifiedPurchase>;
46
+ //# sourceMappingURL=verify.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../../../src/rails/paddle/verify.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AAIhE;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,oDAAoD;AACpD,MAAM,WAAW,8BAA8B;IAC7C,wGAAwG;IACxG,WAAW,EAAE,yBAAyB,CAAC;IACvC,yCAAyC;IACzC,WAAW,EAAE,iBAAiB,CAAC;IAC/B,yGAAyG;IACzG,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,8FAA8F;IAC9F,GAAG,EAAE,IAAI,CAAC;IACV,qBAAqB;IACrB,SAAS,EAAE,eAAe,CAAC;CAC5B;AAKD,wFAAwF;AACxF,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,8BAA8B,GACtC,OAAO,CAAC,gBAAgB,CAAC,CA2D3B"}
@@ -0,0 +1,43 @@
1
+ import { PaymentsInvalidReceiptError, PaymentsVerificationFailedError } from "../../error/errors.js";
2
+ import { PADDLE_CUSTOM_ACCOUNT, accountReferenceOf, transactionEvent } from "./objects.js";
3
+ import { readTransaction } from "./read.js";
4
+ //#region src/rails/paddle/verify.ts
5
+ /** Paddle's transaction ids. Checked before a round trip, so a malformed one costs nothing. */
6
+ const TRANSACTION_ID = /^txn_[a-z0-9]+$/;
7
+ /** Verify one submitted Paddle transaction id, and report who it says it belongs to. */
8
+ async function verifyPaddleTransaction(receipt, options) {
9
+ const id = receipt.trim();
10
+ if (!TRANSACTION_ID.test(id)) throw new PaymentsInvalidReceiptError({
11
+ message: "That isn't a Paddle transaction.",
12
+ action: "Submit the `txn_…` the checkout's completion callback handed back.",
13
+ detail: `A Paddle receipt is a transaction id of the form txn_…; this one is ${id.length} characters and does not match.`
14
+ });
15
+ const transaction = await readTransaction(id, {
16
+ credentials: options.credentials,
17
+ environment: options.environment,
18
+ transport: options.transport
19
+ });
20
+ if (transaction === void 0) throw new PaymentsVerificationFailedError({
21
+ message: "We couldn't confirm that purchase.",
22
+ detail: `Paddle does not know transaction ${id} on this account.`
23
+ });
24
+ const reference = await accountReferenceOf(transaction.custom_data, options.deployment, options.credentials.webhookSecret);
25
+ if (reference === null) {
26
+ const claimed = transaction.custom_data?.[PADDLE_CUSTOM_ACCOUNT];
27
+ throw new PaymentsVerificationFailedError({
28
+ message: "We couldn't confirm that purchase.",
29
+ detail: `Paddle transaction ${id} carries no account reference this deployment can prove it wrote${typeof claimed === "string" ? " (a claimed reference was present but unproven)" : ""}.`
30
+ });
31
+ }
32
+ const environment = options.environment === "production" ? "production" : "sandbox";
33
+ return {
34
+ event: {
35
+ ...transactionEvent(transaction, options.now, environment),
36
+ providerEventAt: options.now
37
+ },
38
+ providerAccountId: transaction.customer_id ?? null,
39
+ accountReference: reference
40
+ };
41
+ }
42
+ //#endregion
43
+ export { verifyPaddleTransaction };