@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,67 @@
1
+ import type { CreatedDiscount, DiscountTerms } from "../../data/discount";
2
+ import type { PaymentsPaddleCredentials } from "../../secret/registry";
3
+ import type { ListedDiscount } from "../contract";
4
+ import { type PaddleEnvironment, type PaddleHttpFetch } from "./api";
5
+ /**
6
+ * Minting a discount at Paddle, from the normalized terms.
7
+ *
8
+ * One object, like Lemon Squeezy's and unlike Stripe's pair: a Paddle discount carries the money, the
9
+ * duration, the redemption limit, the expiry and the code together.
10
+ *
11
+ * ## The two translations that decide whether a customer is charged correctly
12
+ *
13
+ * **Duration.** `recur: false` is `once`. `recur: true` with `maximum_recurring_intervals: null` is
14
+ * `forever`. `recur: true` with a number is `repeating`, and **Paddle counts billing periods** — the same
15
+ * unit `DiscountDuration` already uses, so the number passes through unconverted. This is the second rail
16
+ * where it does not convert; Stripe is the one where it must, because `duration_in_months` counts months.
17
+ * Round-tripped live: `recur: true, maximum_recurring_intervals: 12` came back as `12` on a percentage
18
+ * discount, which is twelve renewals and not twelve months.
19
+ *
20
+ * **Expiry.** `redeemableUntil` means the code can no longer be *claimed*. Paddle's `expires_at` stops
21
+ * redemption and leaves an existing subscriber's discount running, which is the same meaning — so it maps
22
+ * directly.
23
+ *
24
+ * ## The charset, which is Paddle's and narrower than the shared schema's
25
+ *
26
+ * `DiscountCode` allows `[A-Za-z0-9_-]` up to 64 characters and promises "a code this project mints is
27
+ * redeemable on either rail". Paddle enforces `^[a-zA-Z0-9]{1,32}$` — verified live, where
28
+ * `PITHY_RECON-25` was refused with a bare `"Invalid request."` and nothing else.
29
+ *
30
+ * **The shared schema is not narrowed, and the refusal lands here instead.** Narrowing `DiscountCode`
31
+ * would be a behavior change for every Stripe and Lemon Squeezy adopter, refusing codes those rails
32
+ * accept today, in service of a rail they do not run. So this rail checks its own rule and says what it
33
+ * is — the adopter reads a sentence naming the two characters Paddle will not take, rather than an
34
+ * opaque 400 from Paddle. `DiscountCode`'s promise is now conditional, and `docs/paddle.md` says so.
35
+ *
36
+ * ## Amount, and the currency that arrives at the customer
37
+ *
38
+ * `currency_code` is **uppercase** at Paddle where `DiscountAmount.currency` is lowercase — verified
39
+ * live. A fixed amount in a currency no restricted price uses is refused at creation naming both, because
40
+ * at Paddle it would fail at redemption, in front of whoever typed the code.
41
+ *
42
+ * Paddle sends and takes amounts as **strings** in the currency's lowest denomination, including for the
43
+ * zero-decimal currencies: ¥725 is `"725"`, not `"72500"`. Nothing here scales.
44
+ */
45
+ /** What creating or listing a discount needs. */
46
+ export interface PaddleDiscountOptions {
47
+ /** The rail's credentials. */
48
+ credentials: PaymentsPaddleCredentials;
49
+ /** Which Paddle account to reach. */
50
+ environment: PaddleEnvironment;
51
+ /**
52
+ * The currency this project's Paddle catalog prices in, when the project declared one.
53
+ *
54
+ * Only used to refuse a fixed discount in another currency before it reaches Paddle. Absent means the
55
+ * check cannot be made and Paddle's own judgment stands — better than inventing a currency.
56
+ */
57
+ storeCurrency?: string;
58
+ /** The HTTP seam. Defaults to the runtime's `fetch`. */
59
+ transport?: PaddleHttpFetch;
60
+ }
61
+ /** What Paddle accepts as a discount code. Narrower than the shared schema's — see the module doc. */
62
+ export declare const PADDLE_DISCOUNT_CODE: RegExp;
63
+ /** Create a discount and return the code a customer will type. */
64
+ export declare function createPaddleDiscount(terms: DiscountTerms, options: PaddleDiscountOptions): Promise<CreatedDiscount>;
65
+ /** Every discount this account holds, newest first. Never reaches a browser — see {@link ListedDiscount}. */
66
+ export declare function listPaddleDiscounts(options: PaddleDiscountOptions): Promise<readonly ListedDiscount[]>;
67
+ //# sourceMappingURL=discounts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"discounts.d.ts","sourceRoot":"","sources":["../../../src/rails/paddle/discounts.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAE1E,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,KAAK,iBAAiB,EAAE,KAAK,eAAe,EAA+B,MAAM,OAAO,CAAC;AAElG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH,iDAAiD;AACjD,MAAM,WAAW,qBAAqB;IACpC,8BAA8B;IAC9B,WAAW,EAAE,yBAAyB,CAAC;IACvC,qCAAqC;IACrC,WAAW,EAAE,iBAAiB,CAAC;IAC/B;;;;;OAKG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,wDAAwD;IACxD,SAAS,CAAC,EAAE,eAAe,CAAC;CAC7B;AAED,sGAAsG;AACtG,eAAO,MAAM,oBAAoB,QAAwB,CAAC;AAe1D,kEAAkE;AAClE,wBAAsB,oBAAoB,CACxC,KAAK,EAAE,aAAa,EACpB,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,eAAe,CAAC,CAyD1B;AAED,6GAA6G;AAC7G,wBAAsB,mBAAmB,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,SAAS,cAAc,EAAE,CAAC,CA2B5G"}
@@ -0,0 +1,73 @@
1
+ import { PaymentsDiscountInvalidError } from "../../error/errors.js";
2
+ import { paddleHttpFetch, paddleJson } from "./api.js";
3
+ import { z } from "zod";
4
+ //#region src/rails/paddle/discounts.ts
5
+ /** What Paddle accepts as a discount code. Narrower than the shared schema's — see the module doc. */
6
+ const PADDLE_DISCOUNT_CODE = /^[a-zA-Z0-9]{1,32}$/;
7
+ /** A discount as Paddle returns it. */
8
+ const PaddleDiscount = z.object({
9
+ id: z.string().min(1).describe("The discount — `dsc_…`."),
10
+ code: z.string().nullish().describe("The code a customer types, or null for one applicable only by id."),
11
+ type: z.string().nullish().describe("`percentage` or `flat`."),
12
+ amount: z.string().nullish().describe("The figure, as a string: a percentage, or a lowest-denomination amount."),
13
+ currency_code: z.string().nullish().describe("Uppercase ISO 4217, on a flat discount."),
14
+ times_used: z.number().nullish().describe("How many times it has been claimed.")
15
+ }).loose().describe("A Paddle discount, as much of one as this package reads back.");
16
+ /** Create a discount and return the code a customer will type. */
17
+ async function createPaddleDiscount(terms, options) {
18
+ if (terms.code !== void 0 && !PADDLE_DISCOUNT_CODE.test(terms.code)) throw new PaymentsDiscountInvalidError({
19
+ message: "Paddle won't take that code.",
20
+ action: "Use letters and digits only, up to 32 characters — no dashes and no underscores.",
21
+ detail: `Paddle enforces ^[a-zA-Z0-9]{1,32}$ on a discount code and refused "${terms.code}" with a bare "Invalid request.". The shared \`DiscountCode\` schema is deliberately wider, because narrowing it would refuse codes the Stripe and Lemon Squeezy rails accept today.`
22
+ });
23
+ if (terms.amount.kind === "fixed" && options.storeCurrency !== void 0 && options.storeCurrency.toLowerCase() !== terms.amount.currency.toLowerCase()) throw new PaymentsDiscountInvalidError({
24
+ message: "That discount is in a currency this catalog does not sell in.",
25
+ action: `Create it in ${options.storeCurrency.toUpperCase()}, or use a percentage instead.`,
26
+ detail: `A fixed discount of ${terms.amount.amountMinor} ${terms.amount.currency.toUpperCase()} cannot apply to prices in ${options.storeCurrency.toUpperCase()}. Paddle accepts the object and refuses it at redemption, in front of the customer.`
27
+ });
28
+ const body = {
29
+ description: terms.code ?? "Pithy discount",
30
+ type: terms.amount.kind === "percent" ? "percentage" : "flat",
31
+ amount: terms.amount.kind === "percent" ? String(terms.amount.percent) : String(terms.amount.amountMinor),
32
+ recur: terms.duration.kind !== "once",
33
+ enabled_for_checkout: terms.code !== void 0
34
+ };
35
+ if (terms.amount.kind === "fixed") body.currency_code = terms.amount.currency.toUpperCase();
36
+ if (terms.code !== void 0) body.code = terms.code;
37
+ if (terms.duration.kind === "repeating") body.maximum_recurring_intervals = terms.duration.billingPeriods;
38
+ if (terms.maxRedemptions !== void 0) body.usage_limit = terms.maxRedemptions;
39
+ if (terms.redeemableUntil !== void 0) body.expires_at = terms.redeemableUntil.toISOString();
40
+ const answer = await paddleJson(options.transport ?? paddleHttpFetch, "/discounts", {
41
+ what: "a discount",
42
+ apiKey: options.credentials.apiKey,
43
+ environment: options.environment,
44
+ body
45
+ });
46
+ const parsed = PaddleDiscount.safeParse(answer?.data);
47
+ const code = parsed.success ? parsed.data.code : null;
48
+ if (!parsed.success || typeof code !== "string" || code === "") throw new PaymentsDiscountInvalidError({ detail: "Paddle created a discount and returned no code for it." });
49
+ return {
50
+ code,
51
+ providerDiscountId: parsed.data.id,
52
+ terms
53
+ };
54
+ }
55
+ /** Every discount this account holds, newest first. Never reaches a browser — see {@link ListedDiscount}. */
56
+ async function listPaddleDiscounts(options) {
57
+ const answer = await paddleJson(options.transport ?? paddleHttpFetch, "/discounts", {
58
+ what: "the discount list",
59
+ apiKey: options.credentials.apiKey,
60
+ environment: options.environment,
61
+ query: [["order_by", "created_at[DESC]"], ["per_page", "200"]]
62
+ });
63
+ const parsed = z.array(PaddleDiscount).safeParse(answer?.data);
64
+ if (!parsed.success) return [];
65
+ return parsed.data.filter((discount) => typeof discount.code === "string").map((discount) => ({
66
+ code: discount.code,
67
+ providerDiscountId: discount.id,
68
+ amount: discount.type === "percentage" ? `${discount.amount ?? "?"}%` : `${discount.amount ?? "?"} ${(discount.currency_code ?? "").toLowerCase()}`.trim(),
69
+ redemptions: typeof discount.times_used === "number" ? discount.times_used : null
70
+ }));
71
+ }
72
+ //#endregion
73
+ export { PADDLE_DISCOUNT_CODE, createPaddleDiscount, listPaddleDiscounts };
@@ -0,0 +1,140 @@
1
+ import type { PaymentsPaddleCredentials } from "../../secret/registry";
2
+ import type { VerifiedNotification } from "../contract";
3
+ import { type PaddleEnvironment, type PaddleHttpFetch } from "./api";
4
+ import { type ParsePaddleNotificationOptions } from "./webhook";
5
+ /**
6
+ * The events sweep — the repair `refresh` cannot make.
7
+ *
8
+ * `refresh` re-reads rows this deployment already holds. A purchase whose webhook was never delivered and
9
+ * which no client submitted has no row, so it is invisible to `refresh` forever. Paddle publishes an
10
+ * account-wide event stream, so this rail can find those, and no other rail in this package can.
11
+ *
12
+ * **It does repair a delivery that arrived and failed, though that is not what it is for.** The sweep
13
+ * writes through the same table on the same `UNIQUE (rail, providerEventId)`, and since #337 both readers
14
+ * agree that a delivery which errored is still outstanding — `completeWebhook` leaves `processedAt` null
15
+ * beside its reason — so a swept event whose webhook failed is tried again rather than counted a
16
+ * duplicate. The primary repair for that case is the *next delivery*, on every rail; Paddle's replay
17
+ * endpoint reuses the same `event_id` and now reprocesses. What only this sweep can repair is a webhook
18
+ * that was never delivered at all — the case that has no row and is invisible to `refresh` forever.
19
+ *
20
+ * ## The stream is account-wide, and that is a hazard rather than a convenience
21
+ *
22
+ * Verified live: the assigned sandbox's own stream carries `api_key.created` and `client_token.created`.
23
+ * The `api_key` payload's `key` is redacted by Paddle; **the `client_token` payload's `token` is not.**
24
+ * Projecting every swept event through the webhook writer would fill `pithy_payments_webhook_events` with
25
+ * product, price, api-key and client-token rows — and persist live client tokens into a table an operator
26
+ * greps.
27
+ *
28
+ * There are therefore **two** controls, and only one of them is ours.
29
+ *
30
+ * The **query filter** asks Paddle for exactly {@link PADDLE_SWEPT_EVENT_TYPES}. It is sent in the form
31
+ * Paddle documents for an `array[string]` parameter — one key, values comma-separated,
32
+ * `event_type=a,b,c` — verified against the live sandbox API on 2026-08-13: filtering on two of the six
33
+ * types in that account's stream returned four events of exactly those two types, and an unrecognised
34
+ * value is refused with `Request does not pass validation` rather than ignored. An earlier build sent
35
+ * `event_type=a&event_type=b&…`, a repeated-key form Paddle documents nowhere; whether that form is read
36
+ * as an array, as one of its values, or not at all is not something this package can know.
37
+ *
38
+ * The **recording allowlist** is the control this package owns. A returned event whose type is not on
39
+ * that list yields a `null` notification, and the sweep writes no row for it at all. So an unhonoured
40
+ * filter costs a wasted page rather than a client token in D1, and the safety of this module does not
41
+ * rest on a query parameter being obeyed by someone else's service. See `recorded.ts` for the same
42
+ * argument on the webhook path, where there is no query to filter and the subscribed-event list is set
43
+ * by a human in Paddle's dashboard.
44
+ *
45
+ * ## The cursor, and the 90-day cliff
46
+ *
47
+ * `order_by=id[ASC]&after=<cursor>`, with the cursor persisted in `pithy_payments_sync_cursors`. It
48
+ * advances only past events fully projected, so a failure halts advancement and the step retries next run
49
+ * — for a bounded number of runs, after which the event is quarantined and the stream moves on. That bound
50
+ * belongs to the caller: see `workflows/paddleSweep.ts`, which owns the row and the attempt count.
51
+ *
52
+ * This function's own part in it is {@link SweptEvent.failure}: an event whose second read fails is
53
+ * returned carrying its failure rather than thrown, so the caller can halt at that one event instead of
54
+ * losing every healthy event on the page with it.
55
+ *
56
+ * **Paddle retains 90 days.** A cursor older than that can never be caught up — the events between it and
57
+ * the retention window are gone — so this reports a gap naming the window rather than silently restarting
58
+ * from the beginning and re-projecting three months of history.
59
+ */
60
+ /** How many events one page asks for. Paddle's maximum, so a backlog is walked in as few calls as possible. */
61
+ export declare const PADDLE_SWEEP_PAGE_SIZE = 200;
62
+ /** How long Paddle keeps an event. Confirmed in the API reference and in the endpoint's own description. */
63
+ export declare const PADDLE_EVENT_RETENTION_DAYS = 90;
64
+ /**
65
+ * Every event type the sweep asks for — exactly the ones {@link readPaddleEvent} can act on.
66
+ *
67
+ * A type absent here is a type never fetched, never recorded, and therefore never a client token in a
68
+ * table. Adding a projection to the event map means adding its type here; a test asserts the two agree,
69
+ * because a map that grew a case the sweep never fetches would repair through the webhook path and not
70
+ * through the sweep, which is precisely the asymmetry the sweep exists to remove.
71
+ */
72
+ export declare const PADDLE_SWEPT_EVENT_TYPES: readonly string[];
73
+ /** What one sweep page needs. */
74
+ export interface PaddleSweepOptions extends ParsePaddleNotificationOptions {
75
+ /** The rail's credentials. */
76
+ credentials: PaymentsPaddleCredentials;
77
+ /** Which Paddle account to sweep. */
78
+ environment: PaddleEnvironment;
79
+ /** The event id to resume after, or undefined to start at the oldest retained event. */
80
+ cursor?: string;
81
+ /** How many events to ask for. Defaults to Paddle's maximum. */
82
+ pageSize?: number;
83
+ /** The HTTP seam. Defaults to the runtime's `fetch`. */
84
+ transport?: PaddleHttpFetch;
85
+ }
86
+ /** One swept event: what it is, and what the shared event map made of it. */
87
+ export interface SweptEvent {
88
+ /** Paddle's own event id — the same key the webhook path records, because the stream carries no other. */
89
+ eventId: string;
90
+ /** The event type, for the operator reading a run's report. */
91
+ eventType: string;
92
+ /**
93
+ * What the event map made of it, or **null for a type this build does not record at all**.
94
+ *
95
+ * Null is not "projects nothing" — that is a notification whose `event` is null, and it still earns a
96
+ * row. Null here means the type is off {@link PADDLE_SWEPT_EVENT_TYPES}, so Paddle returned something
97
+ * the query asked it not to, and the caller must advance its cursor past the event without writing
98
+ * anything. The body is never even read, so there is nothing to leak. It is also null when
99
+ * {@link SweptEvent.failure} is set, because there is nothing the map could make of it.
100
+ */
101
+ notification: VerifiedNotification | null;
102
+ /**
103
+ * Why this event could not be read, and the body to record against it — or null when it read cleanly.
104
+ *
105
+ * **Carried rather than thrown, because a page is not an event.** Reading an `adjustment.created`
106
+ * reaches Paddle a second time for the transaction it names, and that read can fail on its own — an
107
+ * outage, a deleted transaction, a shape a later Paddle changed. Throwing out of this function threw
108
+ * away the whole page with it, including every event *ahead* of the bad one that had already read
109
+ * perfectly, and the caller's per-event failure handling never saw any of them.
110
+ *
111
+ * The body travels with the failure so the caller can still record a row for the event, and it goes
112
+ * through `recordedPayload` on the way — a write to `pithy_payments_webhook_events` is a write to
113
+ * `pithy_payments_webhook_events` whichever branch reached it. It is present only on this branch: a
114
+ * withheld type carries no payload here, which is the point of the allowlist.
115
+ */
116
+ failure: {
117
+ cause: unknown;
118
+ payload: Record<string, unknown>;
119
+ } | null;
120
+ }
121
+ /** One page of the sweep. */
122
+ export interface PaddleSweepPage {
123
+ /** The events on this page, oldest first. */
124
+ events: readonly SweptEvent[];
125
+ /** The cursor to resume after, or undefined when nothing was returned. */
126
+ cursor?: string;
127
+ /** Whether Paddle has more beyond this page. */
128
+ hasMore: boolean;
129
+ /**
130
+ * A gap this run cannot close, or null.
131
+ *
132
+ * Set when the sweep was asked to resume from a cursor Paddle no longer knows — which is what a cursor
133
+ * older than the retention window looks like. Reported rather than repaired: restarting from the
134
+ * beginning would re-project three months, and pretending the gap is not there would leave it forever.
135
+ */
136
+ gap: string | null;
137
+ }
138
+ /** Sweep one page of Paddle's event stream, projecting each event through the same map a webhook uses. */
139
+ export declare function sweepPaddleEvents(options: PaddleSweepOptions): Promise<PaddleSweepPage>;
140
+ //# sourceMappingURL=events.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../../src/rails/paddle/events.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,KAAK,iBAAiB,EAAE,KAAK,eAAe,EAA+B,MAAM,OAAO,CAAC;AAIlG,OAAO,EAAE,KAAK,8BAA8B,EAAmB,MAAM,WAAW,CAAC;AAEjF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AAEH,+GAA+G;AAC/G,eAAO,MAAM,sBAAsB,MAAM,CAAC;AAE1C,4GAA4G;AAC5G,eAAO,MAAM,2BAA2B,KAAK,CAAC;AAE9C;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB,EAAE,SAAS,MAAM,EAoBrD,CAAC;AAKF,iCAAiC;AACjC,MAAM,WAAW,kBAAmB,SAAQ,8BAA8B;IACxE,8BAA8B;IAC9B,WAAW,EAAE,yBAAyB,CAAC;IACvC,qCAAqC;IACrC,WAAW,EAAE,iBAAiB,CAAC;IAC/B,wFAAwF;IACxF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gEAAgE;IAChE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,wDAAwD;IACxD,SAAS,CAAC,EAAE,eAAe,CAAC;CAC7B;AAED,6EAA6E;AAC7E,MAAM,WAAW,UAAU;IACzB,0GAA0G;IAC1G,OAAO,EAAE,MAAM,CAAC;IAChB,+DAA+D;IAC/D,SAAS,EAAE,MAAM,CAAC;IAClB;;;;;;;;OAQG;IACH,YAAY,EAAE,oBAAoB,GAAG,IAAI,CAAC;IAC1C;;;;;;;;;;;;;OAaG;IACH,OAAO,EAAE;QAAE,KAAK,EAAE,OAAO,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,GAAG,IAAI,CAAC;CACtE;AAED,6BAA6B;AAC7B,MAAM,WAAW,eAAe;IAC9B,6CAA6C;IAC7C,MAAM,EAAE,SAAS,UAAU,EAAE,CAAC;IAC9B,0EAA0E;IAC1E,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gDAAgD;IAChD,OAAO,EAAE,OAAO,CAAC;IACjB;;;;;;OAMG;IACH,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CACpB;AAED,0GAA0G;AAC1G,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,eAAe,CAAC,CAqG7F"}
@@ -0,0 +1,183 @@
1
+ import { paddleHttpFetch, paddleJson } from "./api.js";
2
+ import { PaddleEvent } from "./objects.js";
3
+ import { PADDLE_ADJUSTMENTS_INCLUDE, readTransaction } from "./read.js";
4
+ import { recordedPayload } from "./recorded.js";
5
+ import { readPaddleEvent } from "./webhook.js";
6
+ import { z } from "zod";
7
+ //#region src/rails/paddle/events.ts
8
+ /**
9
+ * The events sweep — the repair `refresh` cannot make.
10
+ *
11
+ * `refresh` re-reads rows this deployment already holds. A purchase whose webhook was never delivered and
12
+ * which no client submitted has no row, so it is invisible to `refresh` forever. Paddle publishes an
13
+ * account-wide event stream, so this rail can find those, and no other rail in this package can.
14
+ *
15
+ * **It does repair a delivery that arrived and failed, though that is not what it is for.** The sweep
16
+ * writes through the same table on the same `UNIQUE (rail, providerEventId)`, and since #337 both readers
17
+ * agree that a delivery which errored is still outstanding — `completeWebhook` leaves `processedAt` null
18
+ * beside its reason — so a swept event whose webhook failed is tried again rather than counted a
19
+ * duplicate. The primary repair for that case is the *next delivery*, on every rail; Paddle's replay
20
+ * endpoint reuses the same `event_id` and now reprocesses. What only this sweep can repair is a webhook
21
+ * that was never delivered at all — the case that has no row and is invisible to `refresh` forever.
22
+ *
23
+ * ## The stream is account-wide, and that is a hazard rather than a convenience
24
+ *
25
+ * Verified live: the assigned sandbox's own stream carries `api_key.created` and `client_token.created`.
26
+ * The `api_key` payload's `key` is redacted by Paddle; **the `client_token` payload's `token` is not.**
27
+ * Projecting every swept event through the webhook writer would fill `pithy_payments_webhook_events` with
28
+ * product, price, api-key and client-token rows — and persist live client tokens into a table an operator
29
+ * greps.
30
+ *
31
+ * There are therefore **two** controls, and only one of them is ours.
32
+ *
33
+ * The **query filter** asks Paddle for exactly {@link PADDLE_SWEPT_EVENT_TYPES}. It is sent in the form
34
+ * Paddle documents for an `array[string]` parameter — one key, values comma-separated,
35
+ * `event_type=a,b,c` — verified against the live sandbox API on 2026-08-13: filtering on two of the six
36
+ * types in that account's stream returned four events of exactly those two types, and an unrecognised
37
+ * value is refused with `Request does not pass validation` rather than ignored. An earlier build sent
38
+ * `event_type=a&event_type=b&…`, a repeated-key form Paddle documents nowhere; whether that form is read
39
+ * as an array, as one of its values, or not at all is not something this package can know.
40
+ *
41
+ * The **recording allowlist** is the control this package owns. A returned event whose type is not on
42
+ * that list yields a `null` notification, and the sweep writes no row for it at all. So an unhonoured
43
+ * filter costs a wasted page rather than a client token in D1, and the safety of this module does not
44
+ * rest on a query parameter being obeyed by someone else's service. See `recorded.ts` for the same
45
+ * argument on the webhook path, where there is no query to filter and the subscribed-event list is set
46
+ * by a human in Paddle's dashboard.
47
+ *
48
+ * ## The cursor, and the 90-day cliff
49
+ *
50
+ * `order_by=id[ASC]&after=<cursor>`, with the cursor persisted in `pithy_payments_sync_cursors`. It
51
+ * advances only past events fully projected, so a failure halts advancement and the step retries next run
52
+ * — for a bounded number of runs, after which the event is quarantined and the stream moves on. That bound
53
+ * belongs to the caller: see `workflows/paddleSweep.ts`, which owns the row and the attempt count.
54
+ *
55
+ * This function's own part in it is {@link SweptEvent.failure}: an event whose second read fails is
56
+ * returned carrying its failure rather than thrown, so the caller can halt at that one event instead of
57
+ * losing every healthy event on the page with it.
58
+ *
59
+ * **Paddle retains 90 days.** A cursor older than that can never be caught up — the events between it and
60
+ * the retention window are gone — so this reports a gap naming the window rather than silently restarting
61
+ * from the beginning and re-projecting three months of history.
62
+ */
63
+ /** How many events one page asks for. Paddle's maximum, so a backlog is walked in as few calls as possible. */
64
+ const PADDLE_SWEEP_PAGE_SIZE = 200;
65
+ /** How long Paddle keeps an event. Confirmed in the API reference and in the endpoint's own description. */
66
+ const PADDLE_EVENT_RETENTION_DAYS = 90;
67
+ /**
68
+ * Every event type the sweep asks for — exactly the ones {@link readPaddleEvent} can act on.
69
+ *
70
+ * A type absent here is a type never fetched, never recorded, and therefore never a client token in a
71
+ * table. Adding a projection to the event map means adding its type here; a test asserts the two agree,
72
+ * because a map that grew a case the sweep never fetches would repair through the webhook path and not
73
+ * through the sweep, which is precisely the asymmetry the sweep exists to remove.
74
+ */
75
+ const PADDLE_SWEPT_EVENT_TYPES = [
76
+ "transaction.paid",
77
+ "transaction.completed",
78
+ "transaction.payment_failed",
79
+ "transaction.past_due",
80
+ "transaction.canceled",
81
+ "transaction.updated",
82
+ "transaction.revised",
83
+ "transaction.billed",
84
+ "subscription.created",
85
+ "subscription.activated",
86
+ "subscription.resumed",
87
+ "subscription.trialing",
88
+ "subscription.past_due",
89
+ "subscription.paused",
90
+ "subscription.canceled",
91
+ "subscription.updated",
92
+ "subscription.imported",
93
+ "adjustment.created",
94
+ "adjustment.updated"
95
+ ];
96
+ /** The same list as a set, for the lookup that decides whether an event is recorded at all. */
97
+ const SWEPT_EVENT_TYPES = new Set(PADDLE_SWEPT_EVENT_TYPES);
98
+ /** Sweep one page of Paddle's event stream, projecting each event through the same map a webhook uses. */
99
+ async function sweepPaddleEvents(options) {
100
+ const query = [
101
+ ["order_by", "id[ASC]"],
102
+ ["per_page", String(options.pageSize ?? 200)],
103
+ ["event_type", PADDLE_SWEPT_EVENT_TYPES.join(",")]
104
+ ];
105
+ if (options.cursor !== void 0) query.push(["after", options.cursor]);
106
+ let answer;
107
+ try {
108
+ answer = await paddleJson(options.transport ?? paddleHttpFetch, "/events", {
109
+ what: "the event stream",
110
+ apiKey: options.credentials.apiKey,
111
+ environment: options.environment,
112
+ query
113
+ });
114
+ } catch (cause) {
115
+ if (options.cursor !== void 0 && isUnknownCursor(cause)) return {
116
+ events: [],
117
+ cursor: options.cursor,
118
+ hasMore: false,
119
+ gap: `Paddle no longer knows event ${options.cursor}, so the sweep cannot resume from it. Paddle retains 90 days of events, and anything between that cursor and the retention window is gone. Reconcile the affected purchases with \`pithy payments reconcile --rail paddle\`, then clear the cursor to restart from the oldest retained event.`
120
+ };
121
+ throw cause;
122
+ }
123
+ const parsed = z.array(PaddleEvent).safeParse(answer?.data);
124
+ if (!parsed.success) return {
125
+ events: [],
126
+ cursor: options.cursor,
127
+ hasMore: false,
128
+ gap: null
129
+ };
130
+ const read = {
131
+ ...options,
132
+ readTransaction: options.readTransaction ?? ((id) => readTransaction(id, {
133
+ credentials: options.credentials,
134
+ environment: options.environment,
135
+ transport: options.transport ?? paddleHttpFetch
136
+ }, PADDLE_ADJUSTMENTS_INCLUDE))
137
+ };
138
+ const events = [];
139
+ for (const event of parsed.data) {
140
+ if (!SWEPT_EVENT_TYPES.has(event.event_type)) {
141
+ events.push({
142
+ eventId: event.event_id,
143
+ eventType: event.event_type,
144
+ notification: null,
145
+ failure: null
146
+ });
147
+ continue;
148
+ }
149
+ try {
150
+ events.push({
151
+ eventId: event.event_id,
152
+ eventType: event.event_type,
153
+ notification: await readPaddleEvent(event, read),
154
+ failure: null
155
+ });
156
+ } catch (cause) {
157
+ events.push({
158
+ eventId: event.event_id,
159
+ eventType: event.event_type,
160
+ notification: null,
161
+ failure: {
162
+ cause,
163
+ payload: recordedPayload(event)
164
+ }
165
+ });
166
+ }
167
+ }
168
+ return {
169
+ events,
170
+ cursor: events.at(-1)?.eventId ?? options.cursor,
171
+ hasMore: answer?.hasMore === true,
172
+ gap: null
173
+ };
174
+ }
175
+ /** Whether Paddle's refusal is "I do not know that cursor" rather than a credential or an outage. */
176
+ function isUnknownCursor(cause) {
177
+ if (typeof cause !== "object" || cause === null) return false;
178
+ const payload = cause.payload;
179
+ if (payload?.code !== "payments/rail_not_configured") return false;
180
+ return /not_found|invalid_field|entity_not_found/i.test(payload.detail ?? "");
181
+ }
182
+ //#endregion
183
+ export { PADDLE_EVENT_RETENTION_DAYS, PADDLE_SWEEP_PAGE_SIZE, PADDLE_SWEPT_EVENT_TYPES, sweepPaddleEvents };
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Two `custom_data` objects a browser wrote onto real Paddle transactions, recorded from the live sandbox.
3
+ *
4
+ * Not invented. Both were produced on 2026-08-13 by a page holding nothing but a publishable client token,
5
+ * driving `Paddle.Checkout.open` and paying with `4242 4242 4242 4242`; both are what Paddle stored and
6
+ * handed back from `GET /transactions/{id}` afterwards. That distinction is the point of the file: a
7
+ * forgery a test author typed proves the reader agrees with the author, and a forgery Paddle stored proves
8
+ * the attack exists.
9
+ *
10
+ * They matter because #309's design rested on the opposite belief — that `custom_data` could only be
11
+ * written by the server, so an ownership stamp needed no proof. It rested on that belief being true of the
12
+ * `transactionId` form in particular. **It is true of neither.**
13
+ */
14
+ /**
15
+ * The `items[]` forgery: a checkout the page opened for a price the page chose, stamped by the page.
16
+ *
17
+ * Recorded from `txn_01kzybmw15rve4bhj3zsbf1k5d`, which Paddle recorded with `origin: "web"` and a paid
18
+ * total of `544`. No server was involved at any point. The `pithy_` key names are exported constants in an
19
+ * open-source package and the environment is one of three, so an attacker guesses nothing here — which is
20
+ * why the third key exists and why it is a MAC.
21
+ */
22
+ export declare const BROWSER_ITEMS_FORGERY: Record<string, unknown>;
23
+ /**
24
+ * The overwrite: a checkout opened for a transaction **the server created and stamped**, whose stamp the
25
+ * browser replaced on its way through.
26
+ *
27
+ * Recorded from `txn_01kzybt89pnvvnwgkabefsjy2z`. The server created it with
28
+ * `{ pithy_user: "server-owner", pithy_env: "prod", pithy_ref_proof: "aa…aa" }`; the page called
29
+ * `Paddle.Checkout.open({ transactionId, customData: { … } })` and paid, and this is what the transaction
30
+ * carried afterwards. Paddle kept `origin: "api"`, so even *that* field does not distinguish the two.
31
+ *
32
+ * **This is the measurement that settles the issue's open question.** Choosing `transactionId` over
33
+ * `items[]` is still right — it fixes the price and the buyer, which a page must never name — but it buys
34
+ * nothing at all for `custom_data`. The stamp is protected by the MAC and by nothing else, on either form.
35
+ *
36
+ * **And the overwrite lands on open, not on payment.** A second probe opened a checkout for a `draft`
37
+ * transaction and closed it without paying; the transaction's `custom_data` had already been replaced. So
38
+ * the stamp on any pending transaction is writable by anyone who knows its id — which is one more reason
39
+ * the field is a claim to be proved rather than a record to be read.
40
+ */
41
+ export declare const BROWSER_OVERWROTE_SERVER_STAMP: Record<string, unknown>;
42
+ //# sourceMappingURL=browserForged.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browserForged.d.ts","sourceRoot":"","sources":["../../../../src/rails/paddle/fixtures/browserForged.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;GAYG;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAIzD,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,8BAA8B,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAIlE,CAAC"}
@@ -0,0 +1,52 @@
1
+ //#region src/rails/paddle/fixtures/browserForged.ts
2
+ /**
3
+ * Two `custom_data` objects a browser wrote onto real Paddle transactions, recorded from the live sandbox.
4
+ *
5
+ * Not invented. Both were produced on 2026-08-13 by a page holding nothing but a publishable client token,
6
+ * driving `Paddle.Checkout.open` and paying with `4242 4242 4242 4242`; both are what Paddle stored and
7
+ * handed back from `GET /transactions/{id}` afterwards. That distinction is the point of the file: a
8
+ * forgery a test author typed proves the reader agrees with the author, and a forgery Paddle stored proves
9
+ * the attack exists.
10
+ *
11
+ * They matter because #309's design rested on the opposite belief — that `custom_data` could only be
12
+ * written by the server, so an ownership stamp needed no proof. It rested on that belief being true of the
13
+ * `transactionId` form in particular. **It is true of neither.**
14
+ */
15
+ /**
16
+ * The `items[]` forgery: a checkout the page opened for a price the page chose, stamped by the page.
17
+ *
18
+ * Recorded from `txn_01kzybmw15rve4bhj3zsbf1k5d`, which Paddle recorded with `origin: "web"` and a paid
19
+ * total of `544`. No server was involved at any point. The `pithy_` key names are exported constants in an
20
+ * open-source package and the environment is one of three, so an attacker guesses nothing here — which is
21
+ * why the third key exists and why it is a MAC.
22
+ */
23
+ const BROWSER_ITEMS_FORGERY = {
24
+ pithy_env: "prod",
25
+ pithy_user: "victim",
26
+ pithy_ref_proof: "0000000000000000000000000000000000000000000000000000000000000000"
27
+ };
28
+ /**
29
+ * The overwrite: a checkout opened for a transaction **the server created and stamped**, whose stamp the
30
+ * browser replaced on its way through.
31
+ *
32
+ * Recorded from `txn_01kzybt89pnvvnwgkabefsjy2z`. The server created it with
33
+ * `{ pithy_user: "server-owner", pithy_env: "prod", pithy_ref_proof: "aa…aa" }`; the page called
34
+ * `Paddle.Checkout.open({ transactionId, customData: { … } })` and paid, and this is what the transaction
35
+ * carried afterwards. Paddle kept `origin: "api"`, so even *that* field does not distinguish the two.
36
+ *
37
+ * **This is the measurement that settles the issue's open question.** Choosing `transactionId` over
38
+ * `items[]` is still right — it fixes the price and the buyer, which a page must never name — but it buys
39
+ * nothing at all for `custom_data`. The stamp is protected by the MAC and by nothing else, on either form.
40
+ *
41
+ * **And the overwrite lands on open, not on payment.** A second probe opened a checkout for a `draft`
42
+ * transaction and closed it without paying; the transaction's `custom_data` had already been replaced. So
43
+ * the stamp on any pending transaction is writable by anyone who knows its id — which is one more reason
44
+ * the field is a claim to be proved rather than a record to be read.
45
+ */
46
+ const BROWSER_OVERWROTE_SERVER_STAMP = {
47
+ pithy_env: "prod",
48
+ pithy_user: "attacker",
49
+ pithy_ref_proof: "bb"
50
+ };
51
+ //#endregion
52
+ export { BROWSER_ITEMS_FORGERY, BROWSER_OVERWROTE_SERVER_STAMP };
@@ -0,0 +1,78 @@
1
+ /**
2
+ * What Paddle actually stores on a paused subscription, recorded from the live sandbox on 2026-08-15.
3
+ *
4
+ * Not invented. `sub_01kzybh940drg5p1dagqv4xj37` was paused through the API twice — once with a resume
5
+ * date, once without — and read back with `GET /subscriptions/{id}` each time. Every value below is from
6
+ * those responses: the pause fields from the paused reads, which were narrowed to exactly these, and the
7
+ * identity fields (`id`, `customer_id`, `created_at`, the item's price) from the same subscription, which
8
+ * was resumed afterwards and is active again. Nothing is here that was not read back.
9
+ *
10
+ * **The recording refutes the obvious fix.** #369 describes the Paddle half as "`scheduled_change.resume_at`
11
+ * is the same story", and a change keyed on that field would have shipped null for every paused Paddle
12
+ * subscription while reading as if it worked: pausing with `resume_at: "2026-10-01T00:00:00Z"` moves the
13
+ * date onto a **`resume` scheduled change's `effective_at`** and leaves `resume_at` **null**. That field
14
+ * carries a date only while a `pause` is scheduled and the subscription is still `active`, which is not a
15
+ * paused subscription at all.
16
+ *
17
+ * The pair also pins the other half of the design: an open-ended pause is `scheduled_change: null`, so a
18
+ * null resume date on a paused Paddle row is Paddle saying "indefinitely" rather than this rail declining
19
+ * to look.
20
+ */
21
+ /** The date the pause was asked to end at, verbatim as it was sent and as Paddle echoed it back. */
22
+ export declare const PADDLE_PAUSE_RESUME_AT = "2026-10-01T00:00:00Z";
23
+ /**
24
+ * A subscription paused **with** a resume date — `pause({ effective_from: "immediately", resume_at })`.
25
+ *
26
+ * Note `resume_at: null` beside an `effective_at` carrying the date. That inversion is the whole reason
27
+ * `subscriptionResumesAt` reads the action rather than the field named after the answer.
28
+ */
29
+ export declare const PADDLE_PAUSED_WITH_RESUME_DATE: {
30
+ id: string;
31
+ status: string;
32
+ customer_id: string;
33
+ paused_at: string;
34
+ scheduled_change: {
35
+ action: string;
36
+ effective_at: string;
37
+ resume_at: null;
38
+ items: null;
39
+ };
40
+ current_billing_period: {
41
+ starts_at: string;
42
+ ends_at: string;
43
+ };
44
+ next_billed_at: string;
45
+ items: {
46
+ price: {
47
+ id: string;
48
+ };
49
+ status: string;
50
+ }[];
51
+ created_at: string;
52
+ };
53
+ /**
54
+ * The same subscription paused **without** one — `pause({ effective_from: "immediately" })`.
55
+ *
56
+ * `scheduled_change` is null and so is `next_billed_at`: Paddle has nothing to say about when this comes
57
+ * back, because nothing decided it. That is the indefinite pause, and it is a real state rather than a gap.
58
+ */
59
+ export declare const PADDLE_PAUSED_INDEFINITELY: {
60
+ id: string;
61
+ status: string;
62
+ customer_id: string;
63
+ paused_at: string;
64
+ scheduled_change: null;
65
+ current_billing_period: {
66
+ starts_at: string;
67
+ ends_at: string;
68
+ };
69
+ next_billed_at: null;
70
+ items: {
71
+ price: {
72
+ id: string;
73
+ };
74
+ status: string;
75
+ }[];
76
+ created_at: string;
77
+ };
78
+ //# sourceMappingURL=pausedSubscription.d.ts.map