@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,60 @@
1
+ import { type PaddleAdjustment, type PaddleTransaction } from "./objects";
2
+ /**
3
+ * What a transaction has had taken back off it — every approved adjustment, not just the one in hand.
4
+ *
5
+ * ## Why one adjustment's own total is not the answer
6
+ *
7
+ * Paddle raises an adjustment per refund, not per transaction. A seller refunding 99.00 in two goes
8
+ * raises **two** approved `refund` adjustments of 49.50, and neither one on its own reaches the
9
+ * transaction's grand total. A comparison against a single adjustment therefore calls both of them
10
+ * partial, revokes nothing, and leaves a fully refunded customer holding what they bought.
11
+ *
12
+ * So the comparison is against the **sum**, and the sum comes from Paddle: `GET /transactions/{id}` with
13
+ * `include=adjustments` returns every adjustment raised against it. See `read.ts`.
14
+ *
15
+ * ## Why the adjustment in hand is merged in by id rather than trusted to be in the list
16
+ *
17
+ * The delivery that carries an `adjustment.created` can reach us before that adjustment is visible on the
18
+ * transaction's own include, and Paddle makes no ordering promise between the two. Merging by id is
19
+ * therefore both safe and necessary: present in the list, the in-hand copy replaces a staler one; absent,
20
+ * it is added, and the very refund being processed still counts toward its own total.
21
+ *
22
+ * ## Why an unreadable amount is null and never zero
23
+ *
24
+ * A figure this build cannot parse is not evidence of a small refund. Summing it as zero would call a full
25
+ * refund partial; summing it as the total would revoke an entitlement on a guess. Null, and the caller
26
+ * says so in a note an operator can act on.
27
+ */
28
+ /**
29
+ * The adjustment actions that revoke an entitlement when approved, and the ones that do not.
30
+ *
31
+ * `chargeback_warning` and its **reverse** are both here as stated rows rather than as an omission — the
32
+ * live `action` enum carries `chargeback_warning_reverse`, which the issue's table does not name. A
33
+ * warning is a notice that a dispute has been opened, not a decision, so neither moves anything. A
34
+ * `credit` against a balance is not a revocation either.
35
+ */
36
+ export declare const REVOKING_ACTIONS: ReadonlySet<string>;
37
+ /** The adjustment actions that restore what a revocation took. */
38
+ export declare const RESTORING_ACTIONS: ReadonlySet<string>;
39
+ /** What every approved revoking adjustment against one transaction comes to, and what that means. */
40
+ export interface AdjustmentTally {
41
+ /**
42
+ * Every approved revoking adjustment against the transaction, summed, in the currency's lowest
43
+ * denomination — or null when any one of them carries an amount this build could not read.
44
+ */
45
+ revokedMinor: number | null;
46
+ /** The transaction's own grand total, or null when this build could not read one. */
47
+ totalMinor: number | null;
48
+ /** How many adjustments the sum counted. Two is the case a single-adjustment comparison gets wrong. */
49
+ counted: number;
50
+ /**
51
+ * Whether what has been taken back covers the whole transaction.
52
+ *
53
+ * False whenever either figure is null, deliberately: a full refund is a claim, and an unreadable amount
54
+ * is not evidence for it.
55
+ */
56
+ full: boolean;
57
+ }
58
+ /** Sum every approved revoking adjustment against this transaction, the one in hand included. */
59
+ export declare function tallyAdjustments(adjustment: PaddleAdjustment, transaction: PaddleTransaction): AdjustmentTally;
60
+ //# sourceMappingURL=adjustments.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adjustments.d.ts","sourceRoot":"","sources":["../../../src/rails/paddle/adjustments.ts"],"names":[],"mappings":"AAGA,OAAO,EAAe,KAAK,gBAAgB,EAAE,KAAK,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAEvF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,EAAE,WAAW,CAAC,MAAM,CAAqC,CAAC;AAEvF,kEAAkE;AAClE,eAAO,MAAM,iBAAiB,EAAE,WAAW,CAAC,MAAM,CAAmC,CAAC;AAEtF,qGAAqG;AACrG,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,qFAAqF;IACrF,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,uGAAuG;IACvG,OAAO,EAAE,MAAM,CAAC;IAChB;;;;;OAKG;IACH,IAAI,EAAE,OAAO,CAAC;CACf;AAED,iGAAiG;AACjG,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,gBAAgB,EAAE,WAAW,EAAE,iBAAiB,GAAG,eAAe,CA2B9G"}
@@ -0,0 +1,66 @@
1
+ import { minorAmount } from "./objects.js";
2
+ //#region src/rails/paddle/adjustments.ts
3
+ /**
4
+ * What a transaction has had taken back off it — every approved adjustment, not just the one in hand.
5
+ *
6
+ * ## Why one adjustment's own total is not the answer
7
+ *
8
+ * Paddle raises an adjustment per refund, not per transaction. A seller refunding 99.00 in two goes
9
+ * raises **two** approved `refund` adjustments of 49.50, and neither one on its own reaches the
10
+ * transaction's grand total. A comparison against a single adjustment therefore calls both of them
11
+ * partial, revokes nothing, and leaves a fully refunded customer holding what they bought.
12
+ *
13
+ * So the comparison is against the **sum**, and the sum comes from Paddle: `GET /transactions/{id}` with
14
+ * `include=adjustments` returns every adjustment raised against it. See `read.ts`.
15
+ *
16
+ * ## Why the adjustment in hand is merged in by id rather than trusted to be in the list
17
+ *
18
+ * The delivery that carries an `adjustment.created` can reach us before that adjustment is visible on the
19
+ * transaction's own include, and Paddle makes no ordering promise between the two. Merging by id is
20
+ * therefore both safe and necessary: present in the list, the in-hand copy replaces a staler one; absent,
21
+ * it is added, and the very refund being processed still counts toward its own total.
22
+ *
23
+ * ## Why an unreadable amount is null and never zero
24
+ *
25
+ * A figure this build cannot parse is not evidence of a small refund. Summing it as zero would call a full
26
+ * refund partial; summing it as the total would revoke an entitlement on a guess. Null, and the caller
27
+ * says so in a note an operator can act on.
28
+ */
29
+ /**
30
+ * The adjustment actions that revoke an entitlement when approved, and the ones that do not.
31
+ *
32
+ * `chargeback_warning` and its **reverse** are both here as stated rows rather than as an omission — the
33
+ * live `action` enum carries `chargeback_warning_reverse`, which the issue's table does not name. A
34
+ * warning is a notice that a dispute has been opened, not a decision, so neither moves anything. A
35
+ * `credit` against a balance is not a revocation either.
36
+ */
37
+ const REVOKING_ACTIONS = /* @__PURE__ */ new Set(["refund", "chargeback"]);
38
+ /** The adjustment actions that restore what a revocation took. */
39
+ const RESTORING_ACTIONS = /* @__PURE__ */ new Set(["chargeback_reverse"]);
40
+ /** Sum every approved revoking adjustment against this transaction, the one in hand included. */
41
+ function tallyAdjustments(adjustment, transaction) {
42
+ const byId = /* @__PURE__ */ new Map();
43
+ for (const other of transaction.adjustments ?? []) byId.set(other.id, other);
44
+ byId.set(adjustment.id, adjustment);
45
+ let revokedMinor = 0;
46
+ let counted = 0;
47
+ for (const one of byId.values()) {
48
+ if (one.status !== "approved" || !REVOKING_ACTIONS.has(one.action)) continue;
49
+ counted += 1;
50
+ const amount = minorAmount(one.totals?.total);
51
+ if (amount === null) {
52
+ revokedMinor = null;
53
+ continue;
54
+ }
55
+ if (revokedMinor !== null) revokedMinor += amount;
56
+ }
57
+ const totalMinor = minorAmount(transaction.details?.totals?.grand_total);
58
+ return {
59
+ revokedMinor,
60
+ totalMinor,
61
+ counted,
62
+ full: totalMinor !== null && revokedMinor !== null && revokedMinor >= totalMinor
63
+ };
64
+ }
65
+ //#endregion
66
+ export { RESTORING_ACTIONS, REVOKING_ACTIONS, tallyAdjustments };
@@ -0,0 +1,138 @@
1
+ /**
2
+ * The one door out to Paddle, and the mapping from how it answered to what that means.
3
+ *
4
+ * Reached with `fetch` and JSON rather than through `@paddle/paddle-node-sdk`, for the reason
5
+ * `stripe/api.ts` and `lemonSqueezy/api.ts` both give: a handful of calls are needed and each is one
6
+ * request. Every other third-party API in this repo is spoken to the same way — `fetch` out, Zod in — and
7
+ * a Node SDK in a Workers bundle buys nothing but weight.
8
+ *
9
+ * **Paddle Billing, not Paddle Classic.** `api.paddle.com` in production and `sandbox-api.paddle.com` in
10
+ * sandbox, with `Paddle-Version: 1` pinned on every request so a future default at Paddle cannot silently
11
+ * reshape a response this package parses.
12
+ *
13
+ * ## How an answer is read
14
+ *
15
+ * **A 5xx or a 429 is `payments/provider_unavailable` (503).** Paddle is up but not answering. The caller
16
+ * retries, and on the webhook path that code passes through the guard unchanged so Paddle redelivers
17
+ * rather than being told its signature was bad.
18
+ *
19
+ * **Every other 4xx is `payments/rail_not_configured` (404).** A 4xx here is never the buyer's fault:
20
+ * these requests are built from config, from the credential bundle, and from rows we wrote. A rejected
21
+ * API key, a price that is not in this account, a customer that is not ours — one statement, that this
22
+ * project's Paddle rail is not set up to do what it was asked.
23
+ *
24
+ * **A 404 is an absent resource only for a caller that said it was probing.** `absentOn404` is how a
25
+ * refresh distinguishes "Paddle no longer knows this subscription" — a normal answer, which the contract
26
+ * says is `undefined` — from "our API key is wrong". Only a caller that knows the difference may claim it.
27
+ *
28
+ * ## Two of Paddle's refusals are the adopter's account rather than their credentials
29
+ *
30
+ * `transactions.create` refuses account-wide with *"Cannot create a transaction or open a checkout as no
31
+ * default payment link has been set for this account"* until somebody sets one in the Paddle dashboard.
32
+ * Verified live against the assigned sandbox, where it is still true. It arrives as an ordinary 4xx and
33
+ * would read as "the rail is misconfigured", which is correct but useless — so {@link paddleSaid} keeps
34
+ * Paddle's own sentence in `detail`, and `pithy doctor` asks the same question before a buyer does.
35
+ *
36
+ * **Nothing in a refusal carries the API key.** `detail` is written to an operator's logs, so anything
37
+ * key-shaped in a message is redacted before it gets there.
38
+ */
39
+ /** Paddle's production API. Public and stable, so it is pinned rather than configured. */
40
+ export declare const PADDLE_API_BASE = "https://api.paddle.com";
41
+ /** Paddle's sandbox API. A separate host, not a flag — sandbox and live are separate accounts entirely. */
42
+ export declare const PADDLE_SANDBOX_API_BASE = "https://sandbox-api.paddle.com";
43
+ /**
44
+ * The API version every request pins.
45
+ *
46
+ * Sent on every call so a future default at Paddle cannot reshape a response this package's schemas parse
47
+ * — the failure would be a webhook that stops projecting, discovered by a customer.
48
+ */
49
+ export declare const PADDLE_API_VERSION = "1";
50
+ /** Which Paddle account a deployment sells through. Two hosts, two sets of credentials, one code path. */
51
+ export type PaddleEnvironment = "sandbox" | "production";
52
+ /** The base URL for an environment. */
53
+ export declare function paddleApiBase(environment: PaddleEnvironment): string;
54
+ /** One outbound request, narrowed to what this rail's endpoints need. */
55
+ export interface PaddleHttpRequest {
56
+ /** The HTTP method. */
57
+ method?: string;
58
+ /** Request headers — the bearer key, the pinned version, and any idempotency key. */
59
+ headers?: Record<string, string>;
60
+ /** The JSON body, on a POST. */
61
+ body?: string;
62
+ }
63
+ /** What this rail needs of a response. Structural, so a test can answer without building a `Response`. */
64
+ export interface PaddleHttpResponse {
65
+ /** Whether the status is 2xx. */
66
+ ok: boolean;
67
+ /** The HTTP status. */
68
+ status: number;
69
+ /** The body as text — read once, then parsed here, so a non-JSON body is reportable rather than a throw. */
70
+ text(): Promise<string>;
71
+ }
72
+ /** The HTTP seam. One explicit parameter defaulting to the runtime's `fetch`, as every rail has. */
73
+ export type PaddleHttpFetch = (url: string, init?: PaddleHttpRequest) => Promise<PaddleHttpResponse>;
74
+ /** The runtime's own `fetch`, adapted to the seam. */
75
+ export declare const paddleHttpFetch: PaddleHttpFetch;
76
+ /** What one call needs: what it is for, the key, and optionally a body, a query, or a probe flag. */
77
+ export interface PaddleJsonOptions {
78
+ /** What was being asked for, in an operator's words. Lands in every refusal's `detail`. */
79
+ what: string;
80
+ /** The Paddle API key — `pdl_live_apikey_…` or `pdl_sdbx_apikey_…`. */
81
+ apiKey: string;
82
+ /** Which account to reach. Decides the host, and nothing else. */
83
+ environment: PaddleEnvironment;
84
+ /** The HTTP method. Defaults to GET, or POST when a body is present. */
85
+ method?: string;
86
+ /** The JSON request body. */
87
+ body?: unknown;
88
+ /**
89
+ * The query string as pairs, appended in order.
90
+ *
91
+ * Pairs rather than a record so order is this caller's to decide and a key may legitimately repeat.
92
+ * **An array parameter is not one of those cases.** Paddle documents every `array[string]` parameter as
93
+ * one key with comma-separated values — `event_type=a,b,c`, `include=x,y` — and a repeated key is a form
94
+ * it documents nowhere. Build the comma-separated value at the call site.
95
+ */
96
+ query?: readonly (readonly [string, string])[];
97
+ /**
98
+ * An idempotency key, so a request Paddle already performed is not performed twice.
99
+ *
100
+ * The one place this matters is checkout: a double-submitted buy button must create one transaction,
101
+ * not two, and Paddle's own header is what guarantees that rather than a check of ours.
102
+ */
103
+ idempotencyKey?: string;
104
+ /** Whether a 404 means "no such object" rather than "this rail is misconfigured". */
105
+ absentOn404?: boolean;
106
+ }
107
+ /** One Paddle answer: the entity, and whether the list it came from has more. */
108
+ export interface PaddleAnswer {
109
+ /** The `data` member, unnarrowed — the caller parses it with its own Zod object. */
110
+ data: unknown;
111
+ /** Whether a paginated list has another page. False for a single entity. */
112
+ hasMore: boolean;
113
+ }
114
+ /**
115
+ * One call to Paddle. Returns the parsed envelope, or `undefined` for a probing caller's 404.
116
+ *
117
+ * `unknown` inside rather than a typed answer: what a subscription looks like is `objects.ts`'s business
118
+ * and not this module's.
119
+ */
120
+ export declare function paddleJson(transport: PaddleHttpFetch, path: string, options: PaddleJsonOptions): Promise<PaddleAnswer | undefined>;
121
+ /**
122
+ * Paddle's own account of the failure, redacted. Empty when the body was not its error envelope.
123
+ *
124
+ * Worth carrying rather than dropping, because Paddle's most consequential refusal is a sentence and not
125
+ * a code: *"Cannot create a transaction or open a checkout as no default payment link has been set for
126
+ * this account."* Without it an operator sees a 400 on `/transactions` and has nothing to act on.
127
+ */
128
+ export declare function paddleSaid(body: string): string;
129
+ /**
130
+ * Blank out anything key-shaped in text bound for a log.
131
+ *
132
+ * Paddle's credentials carry fixed prefixes, which makes this sharper than the Lemon Squeezy equivalent:
133
+ * an API key is `pdl_live_apikey_…` or `pdl_sdbx_apikey_…`, a destination secret is `pdl_ntfset_…`, and a
134
+ * client token is `live_…` or `test_…`. The token is publishable, but a log is not where it belongs
135
+ * either, and a rule with an exception is a rule somebody eventually reads wrong.
136
+ */
137
+ export declare function redactPaddleSecrets(text: string): string;
138
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/rails/paddle/api.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,0FAA0F;AAC1F,eAAO,MAAM,eAAe,2BAA2B,CAAC;AAExD,2GAA2G;AAC3G,eAAO,MAAM,uBAAuB,mCAAmC,CAAC;AAExE;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,MAAM,CAAC;AAEtC,0GAA0G;AAC1G,MAAM,MAAM,iBAAiB,GAAG,SAAS,GAAG,YAAY,CAAC;AAEzD,uCAAuC;AACvC,wBAAgB,aAAa,CAAC,WAAW,EAAE,iBAAiB,GAAG,MAAM,CAEpE;AAED,yEAAyE;AACzE,MAAM,WAAW,iBAAiB;IAChC,uBAAuB;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,qFAAqF;IACrF,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,gCAAgC;IAChC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,0GAA0G;AAC1G,MAAM,WAAW,kBAAkB;IACjC,iCAAiC;IACjC,EAAE,EAAE,OAAO,CAAC;IACZ,uBAAuB;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,4GAA4G;IAC5G,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;CACzB;AAED,oGAAoG;AACpG,MAAM,MAAM,eAAe,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,iBAAiB,KAAK,OAAO,CAAC,kBAAkB,CAAC,CAAC;AAErG,sDAAsD;AACtD,eAAO,MAAM,eAAe,EAAE,eAC6C,CAAC;AAwB5E,qGAAqG;AACrG,MAAM,WAAW,iBAAiB;IAChC,2FAA2F;IAC3F,IAAI,EAAE,MAAM,CAAC;IACb,uEAAuE;IACvE,MAAM,EAAE,MAAM,CAAC;IACf,kEAAkE;IAClE,WAAW,EAAE,iBAAiB,CAAC;IAC/B,wEAAwE;IACxE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,6BAA6B;IAC7B,IAAI,CAAC,EAAE,OAAO,CAAC;IACf;;;;;;;OAOG;IACH,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC;IAC/C;;;;;OAKG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,qFAAqF;IACrF,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,iFAAiF;AACjF,MAAM,WAAW,YAAY;IAC3B,oFAAoF;IACpF,IAAI,EAAE,OAAO,CAAC;IACd,4EAA4E;IAC5E,OAAO,EAAE,OAAO,CAAC;CAClB;AAED;;;;;GAKG;AACH,wBAAsB,UAAU,CAC9B,SAAS,EAAE,eAAe,EAC1B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC,CAmDnC;AAgBD;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAa/C;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAExD"}
@@ -0,0 +1,152 @@
1
+ import { PaymentsProviderUnavailableError, PaymentsRailNotConfiguredError } from "../../error/errors.js";
2
+ import { z } from "zod";
3
+ //#region src/rails/paddle/api.ts
4
+ /**
5
+ * The one door out to Paddle, and the mapping from how it answered to what that means.
6
+ *
7
+ * Reached with `fetch` and JSON rather than through `@paddle/paddle-node-sdk`, for the reason
8
+ * `stripe/api.ts` and `lemonSqueezy/api.ts` both give: a handful of calls are needed and each is one
9
+ * request. Every other third-party API in this repo is spoken to the same way — `fetch` out, Zod in — and
10
+ * a Node SDK in a Workers bundle buys nothing but weight.
11
+ *
12
+ * **Paddle Billing, not Paddle Classic.** `api.paddle.com` in production and `sandbox-api.paddle.com` in
13
+ * sandbox, with `Paddle-Version: 1` pinned on every request so a future default at Paddle cannot silently
14
+ * reshape a response this package parses.
15
+ *
16
+ * ## How an answer is read
17
+ *
18
+ * **A 5xx or a 429 is `payments/provider_unavailable` (503).** Paddle is up but not answering. The caller
19
+ * retries, and on the webhook path that code passes through the guard unchanged so Paddle redelivers
20
+ * rather than being told its signature was bad.
21
+ *
22
+ * **Every other 4xx is `payments/rail_not_configured` (404).** A 4xx here is never the buyer's fault:
23
+ * these requests are built from config, from the credential bundle, and from rows we wrote. A rejected
24
+ * API key, a price that is not in this account, a customer that is not ours — one statement, that this
25
+ * project's Paddle rail is not set up to do what it was asked.
26
+ *
27
+ * **A 404 is an absent resource only for a caller that said it was probing.** `absentOn404` is how a
28
+ * refresh distinguishes "Paddle no longer knows this subscription" — a normal answer, which the contract
29
+ * says is `undefined` — from "our API key is wrong". Only a caller that knows the difference may claim it.
30
+ *
31
+ * ## Two of Paddle's refusals are the adopter's account rather than their credentials
32
+ *
33
+ * `transactions.create` refuses account-wide with *"Cannot create a transaction or open a checkout as no
34
+ * default payment link has been set for this account"* until somebody sets one in the Paddle dashboard.
35
+ * Verified live against the assigned sandbox, where it is still true. It arrives as an ordinary 4xx and
36
+ * would read as "the rail is misconfigured", which is correct but useless — so {@link paddleSaid} keeps
37
+ * Paddle's own sentence in `detail`, and `pithy doctor` asks the same question before a buyer does.
38
+ *
39
+ * **Nothing in a refusal carries the API key.** `detail` is written to an operator's logs, so anything
40
+ * key-shaped in a message is redacted before it gets there.
41
+ */
42
+ /** Paddle's production API. Public and stable, so it is pinned rather than configured. */
43
+ const PADDLE_API_BASE = "https://api.paddle.com";
44
+ /** Paddle's sandbox API. A separate host, not a flag — sandbox and live are separate accounts entirely. */
45
+ const PADDLE_SANDBOX_API_BASE = "https://sandbox-api.paddle.com";
46
+ /**
47
+ * The API version every request pins.
48
+ *
49
+ * Sent on every call so a future default at Paddle cannot reshape a response this package's schemas parse
50
+ * — the failure would be a webhook that stops projecting, discovered by a customer.
51
+ */
52
+ const PADDLE_API_VERSION = "1";
53
+ /** The base URL for an environment. */
54
+ function paddleApiBase(environment) {
55
+ return environment === "production" ? PADDLE_API_BASE : PADDLE_SANDBOX_API_BASE;
56
+ }
57
+ /** The runtime's own `fetch`, adapted to the seam. */
58
+ const paddleHttpFetch = (url, init) => fetch(url, init);
59
+ /** Paddle's error envelope, of which only the human parts are worth reporting. */
60
+ const PaddleApiError = z.object({ error: z.object({
61
+ type: z.string().optional(),
62
+ code: z.string().optional(),
63
+ detail: z.string().optional()
64
+ }).loose() });
65
+ /** A Paddle success envelope: the entity under `data`, and pagination under `meta` for a list. */
66
+ const PaddleEnvelope = z.object({
67
+ data: z.unknown(),
68
+ meta: z.object({ pagination: z.object({ has_more: z.boolean().optional() }).loose().optional() }).loose().optional()
69
+ }).loose();
70
+ /**
71
+ * One call to Paddle. Returns the parsed envelope, or `undefined` for a probing caller's 404.
72
+ *
73
+ * `unknown` inside rather than a typed answer: what a subscription looks like is `objects.ts`'s business
74
+ * and not this module's.
75
+ */
76
+ async function paddleJson(transport, path, options) {
77
+ const search = new URLSearchParams();
78
+ for (const [key, value] of options.query ?? []) search.append(key, value);
79
+ const query = [...search].length === 0 ? "" : `?${search.toString()}`;
80
+ const headers = {
81
+ authorization: `Bearer ${options.apiKey}`,
82
+ accept: "application/json",
83
+ "paddle-version": "1"
84
+ };
85
+ if (options.body !== void 0) headers["content-type"] = "application/json";
86
+ if (options.idempotencyKey !== void 0) headers["paddle-idempotency-key"] = options.idempotencyKey;
87
+ let response;
88
+ try {
89
+ response = await transport(`${paddleApiBase(options.environment)}${path}${query}`, {
90
+ method: options.method ?? (options.body === void 0 ? "GET" : "POST"),
91
+ headers,
92
+ body: options.body === void 0 ? void 0 : JSON.stringify(options.body)
93
+ });
94
+ } catch (cause) {
95
+ throw new PaymentsProviderUnavailableError({ detail: `Paddle did not answer when asked for ${options.what}.` }, { cause });
96
+ }
97
+ const text = await response.text();
98
+ if (!response.ok) {
99
+ if (response.status === 404 && options.absentOn404) return void 0;
100
+ throw refusal(response.status, text, options);
101
+ }
102
+ let parsed;
103
+ try {
104
+ parsed = JSON.parse(text);
105
+ } catch (cause) {
106
+ throw new PaymentsProviderUnavailableError({ detail: `Paddle answered with a non-JSON body when asked for ${options.what}.` }, { cause });
107
+ }
108
+ const envelope = PaddleEnvelope.safeParse(parsed);
109
+ if (!envelope.success) throw new PaymentsProviderUnavailableError({ detail: `Paddle answered for ${options.what} with a body carrying no \`data\`.` });
110
+ return {
111
+ data: envelope.data.data,
112
+ hasMore: envelope.data.meta?.pagination?.has_more === true
113
+ };
114
+ }
115
+ /** The refusal for a non-2xx answer: retryable if Paddle is struggling, a configuration failure otherwise. */
116
+ function refusal(status, body, options) {
117
+ if (status === 429 || status >= 500) return new PaymentsProviderUnavailableError({ detail: `Paddle answered ${status} when asked for ${options.what}. ${paddleSaid(body)}` });
118
+ const key = status === 401 || status === 403 ? " Check the API key stored for this environment." : "";
119
+ return new PaymentsRailNotConfiguredError({ detail: `Paddle refused the request for ${options.what} with ${status}.${key} ${paddleSaid(body)}` });
120
+ }
121
+ /**
122
+ * Paddle's own account of the failure, redacted. Empty when the body was not its error envelope.
123
+ *
124
+ * Worth carrying rather than dropping, because Paddle's most consequential refusal is a sentence and not
125
+ * a code: *"Cannot create a transaction or open a checkout as no default payment link has been set for
126
+ * this account."* Without it an operator sees a 400 on `/transactions` and has nothing to act on.
127
+ */
128
+ function paddleSaid(body) {
129
+ let parsed;
130
+ try {
131
+ parsed = JSON.parse(body);
132
+ } catch {
133
+ return "";
134
+ }
135
+ const envelope = PaddleApiError.safeParse(parsed);
136
+ if (!envelope.success) return "";
137
+ const parts = [envelope.data.error.code, envelope.data.error.detail].filter((part) => part !== void 0 && part !== "");
138
+ return parts.length === 0 ? "" : `Paddle said: ${redactPaddleSecrets(parts.join(" / "))}.`;
139
+ }
140
+ /**
141
+ * Blank out anything key-shaped in text bound for a log.
142
+ *
143
+ * Paddle's credentials carry fixed prefixes, which makes this sharper than the Lemon Squeezy equivalent:
144
+ * an API key is `pdl_live_apikey_…` or `pdl_sdbx_apikey_…`, a destination secret is `pdl_ntfset_…`, and a
145
+ * client token is `live_…` or `test_…`. The token is publishable, but a log is not where it belongs
146
+ * either, and a rule with an exception is a rule somebody eventually reads wrong.
147
+ */
148
+ function redactPaddleSecrets(text) {
149
+ return text.replace(/\bpdl_[A-Za-z0-9_]+/g, "…").replace(/\b(?:live|test)_[A-Za-z0-9]{16,}\b/g, "…");
150
+ }
151
+ //#endregion
152
+ export { PADDLE_API_BASE, PADDLE_API_VERSION, PADDLE_SANDBOX_API_BASE, paddleApiBase, paddleHttpFetch, paddleJson, paddleSaid, redactPaddleSecrets };
@@ -0,0 +1,69 @@
1
+ import type { PaymentsPaddleCredentials } from "../../secret/registry";
2
+ import type { CheckoutHandoff, CheckoutSessionInput } from "../contract";
3
+ import { type PaddleEnvironment, type PaddleHttpFetch } from "./api";
4
+ /**
5
+ * Checkout: one server path, three ways of handing it to a browser.
6
+ *
7
+ * The server does the same thing in every mode — `POST /transactions` with the price from the catalog,
8
+ * the customer when the buyer has one, the ownership stamp, and the resolved discount. What differs is
9
+ * only the handoff: `hosted` returns `transaction.checkout.url`, and `overlay` and `inline` return the
10
+ * transaction for Paddle.js to open in place.
11
+ *
12
+ * ## What this call stamps, and why each of them
13
+ *
14
+ * **The resolved subject, in `custom_data.pithy_user`.** A Paddle purchase is heard about through a webhook
15
+ * carrying `ctm_…` and no Pithy holder. This is the pairing, and it is why the `/checkout` route resolves the
16
+ * subject through the configured seam and never from a request body.
17
+ *
18
+ * The value is `encodeSubjectReference`'s output — `user:ada`, `organization:acme` — and **both halves travel
19
+ * or neither does**. Nothing keeps an organization id from equalling some user's, so a bare id read back at
20
+ * the far end would eventually hand one holder's subscription to the other. A bare id is also exactly what
21
+ * this rail stamped before subjects existed, and `decodeSubjectReference` refuses one on purpose: the
22
+ * purchase orphans, replayable, rather than being attributed to a stranger. The key name is unchanged
23
+ * through all of that — see `objects.ts`.
24
+ *
25
+ * **This deployment's environment, beside it.** `dev` is not publicly routable, so a dev checkout's
26
+ * webhooks land at `staging`, and both point at one Paddle sandbox with one set of destinations. The
27
+ * stamp is what lets each ignore the other's traffic.
28
+ *
29
+ * **A MAC over both, which is the only part that makes either mean anything.** `Paddle.Checkout.open`
30
+ * accepts `customData` beside an `items[]` array of price ids with nothing but the publishable client
31
+ * token — the token this rail ships to every browser that loads a paywall. So a stranger can write the
32
+ * first two values. They cannot write the third. See `objects.ts`.
33
+ *
34
+ * ## The idempotency key
35
+ *
36
+ * `Paddle-Idempotency-Key`, derived from the buyer, the price and the deployment. A double-submitted buy
37
+ * button then creates one transaction rather than two — enforced by Paddle rather than by a check here,
38
+ * which is the only place it can be enforced, since the two requests may land on different isolates.
39
+ *
40
+ * ## What it deliberately does not do
41
+ *
42
+ * No quantity and no amount. The price *is* the price — that is Paddle's model — and a checkout that could
43
+ * name an amount would be a checkout a client could name an amount on.
44
+ *
45
+ * **No plan change either, and that is now a fact about this module rather than about the kit.** #79's
46
+ * locked decision 2 was amended on 2026-08-28: a rail may invoke a plan change and pass the provider's own
47
+ * figures through unmodified, and this rail does — `rails/paddle/subscription.ts`, behind
48
+ * {@link SubscriptionRail}. It is a different verb on a subscription that already exists, so it does not
49
+ * belong on the call that creates one. Checkout still computes no proration and no tax; nothing here
50
+ * derives an amount from another amount, and `rails/contract.ts` states the line in full.
51
+ */
52
+ /** What creating a checkout needs beyond the input. */
53
+ export interface PaddleCheckoutOptions {
54
+ /** The rail's credentials. `apiKey` creates the transaction; `webhookSecret` keys the ownership proof. */
55
+ credentials: PaymentsPaddleCredentials;
56
+ /** Which Paddle account to sell through. */
57
+ environment: PaddleEnvironment;
58
+ /** The publishable client token a browser initializes Paddle.js with. */
59
+ clientToken: string;
60
+ /** Which of the three modes this project uses. */
61
+ checkout: "overlay" | "inline" | "hosted";
62
+ /** This deployment's `ENVIRONMENT`, stamped so its own webhooks are recognizable. */
63
+ deployment?: string;
64
+ /** The HTTP seam. Defaults to the runtime's `fetch`. */
65
+ transport?: PaddleHttpFetch;
66
+ }
67
+ /** Create a checkout for one product, and say how the browser reaches it. */
68
+ export declare function createPaddleCheckoutSession(input: CheckoutSessionInput, options: PaddleCheckoutOptions): Promise<CheckoutHandoff>;
69
+ //# sourceMappingURL=checkout.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkout.d.ts","sourceRoot":"","sources":["../../../src/rails/paddle/checkout.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,KAAK,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,EAAE,KAAK,iBAAiB,EAAE,KAAK,eAAe,EAA+B,MAAM,OAAO,CAAC;AASlG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AAEH,uDAAuD;AACvD,MAAM,WAAW,qBAAqB;IACpC,0GAA0G;IAC1G,WAAW,EAAE,yBAAyB,CAAC;IACvC,4CAA4C;IAC5C,WAAW,EAAE,iBAAiB,CAAC;IAC/B,yEAAyE;IACzE,WAAW,EAAE,MAAM,CAAC;IACpB,kDAAkD;IAClD,QAAQ,EAAE,SAAS,GAAG,QAAQ,GAAG,QAAQ,CAAC;IAC1C,qFAAqF;IACrF,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,wDAAwD;IACxD,SAAS,CAAC,EAAE,eAAe,CAAC;CAC7B;AAKD,6EAA6E;AAC7E,wBAAsB,2BAA2B,CAC/C,KAAK,EAAE,oBAAoB,EAC3B,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,eAAe,CAAC,CAuF1B"}
@@ -0,0 +1,100 @@
1
+ import { encodeSubjectReference } from "../../data/subject.js";
2
+ import { PaymentsDiscountInvalidError, PaymentsRailNotConfiguredError } from "../../error/errors.js";
3
+ import { paddleHttpFetch, paddleJson } from "./api.js";
4
+ import { PADDLE_CUSTOM_ACCOUNT, PADDLE_CUSTOM_ENV, PADDLE_CUSTOM_PROOF, PaddleTransaction, accountReferenceProof } from "./objects.js";
5
+ import { PithyError } from "@pithy-sh/core/src/error/pithyError";
6
+ import { z } from "zod";
7
+ //#region src/rails/paddle/checkout.ts
8
+ /** Paddle's discount list, narrowed to the id a transaction needs. */
9
+ const PaddleDiscountMatches = z.array(z.object({ id: z.string().min(1) }).loose());
10
+ /** Create a checkout for one product, and say how the browser reaches it. */
11
+ async function createPaddleCheckoutSession(input, options) {
12
+ const transport = options.transport ?? paddleHttpFetch;
13
+ const discountId = input.discountCode === void 0 ? void 0 : await resolveDiscount(input.discountCode, options, transport);
14
+ const accountReference = encodeSubjectReference(input.subject);
15
+ const custom = { [PADDLE_CUSTOM_ACCOUNT]: accountReference };
16
+ if (options.deployment !== void 0) {
17
+ custom[PADDLE_CUSTOM_ENV] = options.deployment;
18
+ custom[PADDLE_CUSTOM_PROOF] = await accountReferenceProof(accountReference, options.deployment, options.credentials.webhookSecret);
19
+ }
20
+ const answer = await paddleJson(transport, "/transactions", {
21
+ what: "a transaction",
22
+ apiKey: options.credentials.apiKey,
23
+ environment: options.environment,
24
+ idempotencyKey: `pithy:${options.deployment ?? "unknown"}:${accountReference}:${input.providerProductId}:${input.discountCode ?? ""}`,
25
+ body: {
26
+ items: [{
27
+ price_id: input.providerProductId,
28
+ quantity: 1
29
+ }],
30
+ ...input.providerAccountId ? { customer_id: input.providerAccountId } : {},
31
+ ...discountId === void 0 ? {} : { discount_id: discountId },
32
+ collection_mode: "automatic",
33
+ custom_data: custom
34
+ }
35
+ });
36
+ const parsed = PaddleTransaction.safeParse(answer?.data);
37
+ if (!parsed.success) throw new PaymentsRailNotConfiguredError({ detail: "Paddle created a transaction this build cannot read. Check `Paddle-Version: 1` against the account's default." });
38
+ const transaction = parsed.data;
39
+ if (options.checkout !== "hosted") return {
40
+ kind: "paddle",
41
+ transactionId: transaction.id,
42
+ clientToken: options.clientToken,
43
+ environment: options.environment,
44
+ displayMode: options.checkout,
45
+ successUrl: input.successUrl
46
+ };
47
+ const url = transaction.checkout?.url;
48
+ if (typeof url !== "string" || url === "") throw new PaymentsRailNotConfiguredError({ detail: `Paddle created transaction ${transaction.id} with no checkout URL. Set a default payment link under Checkout → Checkout settings in the Paddle dashboard, or use \`paddle.checkout: "overlay"\`.` });
49
+ return {
50
+ kind: "redirect",
51
+ url
52
+ };
53
+ }
54
+ /**
55
+ * Turn the code a customer typed into the discount id a transaction wants.
56
+ *
57
+ * Paddle's `discount_id` takes a `dsc_…`, not the customer-facing string, so this lookup is unavoidable.
58
+ * It is also where the code's validity is learned, and learning it *here* is what makes the refusal a good
59
+ * one: an unknown, expired or exhausted code is refused before a transaction exists, as
60
+ * `payments/discount_invalid` naming the code, rather than becoming a checkout that fails in front of the
61
+ * customer with nothing to say but that something went wrong.
62
+ *
63
+ * `status=active` is part of the query rather than a check afterwards, so an expired or exhausted code
64
+ * simply does not come back. Paddle decides what active means — nothing here reads `expires_at` or counts
65
+ * redemptions, for the same reason nothing here computes a discounted price.
66
+ *
67
+ * **One refusal for all three cases**, and that is a decision rather than an omission. Naming which of
68
+ * "no such code", "expired" and "limit reached" it was helps the buyer a little and tells an
69
+ * unauthenticated enumerator which codes exist, which is worth more to them.
70
+ */
71
+ async function resolveDiscount(code, options, transport) {
72
+ let answer;
73
+ try {
74
+ answer = await paddleJson(transport, "/discounts", {
75
+ what: `the discount code ${code}`,
76
+ apiKey: options.credentials.apiKey,
77
+ environment: options.environment,
78
+ query: [
79
+ ["code", code],
80
+ ["status", "active"],
81
+ ["per_page", "1"]
82
+ ]
83
+ });
84
+ } catch (cause) {
85
+ if (cause instanceof PithyError && cause.payload.code === "payments/rail_not_configured") throw new PaymentsDiscountInvalidError({
86
+ message: `"${code}" is not a discount code we can accept.`,
87
+ detail: `Paddle refused a lookup of discount code "${code}". ${cause.payload.detail ?? ""}`
88
+ }, { cause });
89
+ throw cause;
90
+ }
91
+ const matches = PaddleDiscountMatches.safeParse(answer?.data);
92
+ const found = matches.success ? matches.data[0] : void 0;
93
+ if (found === void 0) throw new PaymentsDiscountInvalidError({
94
+ message: `"${code}" is not a discount code we can accept.`,
95
+ detail: `Paddle has no active discount matching "${code}" — unknown, expired, or fully redeemed.`
96
+ });
97
+ return found.id;
98
+ }
99
+ //#endregion
100
+ export { createPaddleCheckoutSession };