@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,28 @@
1
+ import type { PaymentsLemonSqueezyCredentials } from "../../secret/registry";
2
+ import { type LemonSqueezyHttpFetch } from "./api";
3
+ import { LemonSqueezyOrder, LemonSqueezySubscription } from "./objects";
4
+ /**
5
+ * The reads this rail makes of Lemon Squeezy: a subscription, and an order.
6
+ *
7
+ * Both exist for two callers with different needs, which is why they return `undefined` rather than throwing
8
+ * on an absent object. The webhook parser reads a subscription to learn which variant an invoice bills; the
9
+ * reconciliation pass reads one to find out what a purchase looks like now. For the first, an absent
10
+ * subscription is a delivery that cannot be projected; for the second it is the contract's documented
11
+ * "the store no longer knows this purchase". Neither is a failure of the rail.
12
+ *
13
+ * A store that cannot be *reached* throws `payments/provider_unavailable`, which is what tells the
14
+ * reconciliation Workflow to fail the step and retry, and what makes the webhook guard answer non-2xx so
15
+ * Lemon Squeezy redelivers.
16
+ */
17
+ /** What a read needs: the credentials, and the transport to make it through. */
18
+ export interface LemonSqueezyReadOptions {
19
+ /** The rail's credentials. The API key is read at the point of need and never cached. */
20
+ credentials: PaymentsLemonSqueezyCredentials;
21
+ /** The HTTP seam. */
22
+ transport: LemonSqueezyHttpFetch;
23
+ }
24
+ /** The subscription with this id, or `undefined` when Lemon Squeezy has none. */
25
+ export declare function readSubscription(id: string, options: LemonSqueezyReadOptions): Promise<LemonSqueezySubscription | undefined>;
26
+ /** The order with this id, or `undefined` when Lemon Squeezy has none. */
27
+ export declare function readOrder(id: string, options: LemonSqueezyReadOptions): Promise<LemonSqueezyOrder | undefined>;
28
+ //# sourceMappingURL=read.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../../../src/rails/lemonSqueezy/read.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,uBAAuB,CAAC;AAC7E,OAAO,EAAE,KAAK,qBAAqB,EAAoB,MAAM,OAAO,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAC;AAExE;;;;;;;;;;;;GAYG;AAEH,gFAAgF;AAChF,MAAM,WAAW,uBAAuB;IACtC,yFAAyF;IACzF,WAAW,EAAE,+BAA+B,CAAC;IAC7C,qBAAqB;IACrB,SAAS,EAAE,qBAAqB,CAAC;CAClC;AA6BD,iFAAiF;AACjF,wBAAsB,gBAAgB,CACpC,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,wBAAwB,GAAG,SAAS,CAAC,CAG/C;AAED,0EAA0E;AAC1E,wBAAsB,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,iBAAiB,GAAG,SAAS,CAAC,CAGpH"}
@@ -0,0 +1,37 @@
1
+ import { PaymentsProviderUnavailableError } from "../../error/errors.js";
2
+ import { lemonSqueezyJson } from "./api.js";
3
+ import { LemonSqueezyOrder, LemonSqueezySubscription } from "./objects.js";
4
+ import { z } from "zod";
5
+ //#region src/rails/lemonSqueezy/read.ts
6
+ /** A JSON:API single-resource answer, narrowed to the attributes the caller will parse. */
7
+ const Envelope = z.object({ data: z.object({
8
+ id: z.string(),
9
+ attributes: z.record(z.string(), z.unknown())
10
+ }).loose() });
11
+ /** Read one object, or `undefined` when the store has no such thing. */
12
+ async function readObject(path, what, options) {
13
+ const body = await lemonSqueezyJson(options.transport, path, {
14
+ what,
15
+ apiKey: options.credentials.apiKey,
16
+ absentOn404: true
17
+ });
18
+ if (body === void 0) return void 0;
19
+ const envelope = Envelope.safeParse(body);
20
+ if (!envelope.success) throw new PaymentsProviderUnavailableError({ detail: `Lemon Squeezy answered for ${what} with a body that is not a JSON:API resource.` });
21
+ return {
22
+ id: envelope.data.data.id,
23
+ attributes: envelope.data.data.attributes
24
+ };
25
+ }
26
+ /** The subscription with this id, or `undefined` when Lemon Squeezy has none. */
27
+ async function readSubscription(id, options) {
28
+ const object = await readObject(`/subscriptions/${encodeURIComponent(id)}`, `subscription ${id}`, options);
29
+ return object === void 0 ? void 0 : LemonSqueezySubscription.parse(object.attributes);
30
+ }
31
+ /** The order with this id, or `undefined` when Lemon Squeezy has none. */
32
+ async function readOrder(id, options) {
33
+ const object = await readObject(`/orders/${encodeURIComponent(id)}`, `order ${id}`, options);
34
+ return object === void 0 ? void 0 : LemonSqueezyOrder.parse(object.attributes);
35
+ }
36
+ //#endregion
37
+ export { readOrder, readSubscription };
@@ -0,0 +1,42 @@
1
+ import type { PaymentsPurchase } from "../../data/purchase";
2
+ import type { PaymentsLemonSqueezyCredentials } from "../../secret/registry";
3
+ import type { UnboundProviderEvent } from "../contract";
4
+ import type { LemonSqueezyHttpFetch } from "./api";
5
+ /**
6
+ * Re-read a Lemon Squeezy purchase — the reconciliation path.
7
+ *
8
+ * Webhooks are dropped, endpoints are misconfigured, and a subscription can lapse with no notification
9
+ * arriving at all. This is the question the reconciliation Workflow exists to ask, and this rail answers it
10
+ * for real.
11
+ *
12
+ * ## Which rows it can answer for
13
+ *
14
+ * **State rows.** `providerTransactionId` is `subscription:<id>`, which is exactly the object Lemon Squeezy
15
+ * can be asked about, and the answer is the subscription's standing now — the freshest fact anyone holds.
16
+ *
17
+ * **Order rows.** `order:<id>`, read back the same way.
18
+ *
19
+ * **Money rows are deliberately not refreshed.** A `subscription_invoice:` row records one closed billing
20
+ * period, and it is born `expired` — which is in the Workflow's terminal set, so the pass never selects one.
21
+ * Re-reading a closed invoice could only restate what it already says. Should one somehow reach here it
22
+ * answers `undefined`, which the contract defines as "the store has nothing to say about this purchase" and
23
+ * which leaves the row exactly as it stands.
24
+ *
25
+ * ## The clock is ours
26
+ *
27
+ * `providerEventAt` is `context.now`, not the object's `updated_at`, as the contract requires. A refresh is
28
+ * a read of the state *now*, so it is the freshest fact there is — dating it earlier would let the monotonic
29
+ * write rule discard the very repair this pass exists to make.
30
+ */
31
+ /** What a refresh needs: the credentials, the clock, and the transport. */
32
+ export interface RefreshLemonSqueezyOptions {
33
+ /** The rail's credentials. */
34
+ credentials: PaymentsLemonSqueezyCredentials;
35
+ /** The clock. Stamped onto the returned event, per the contract. */
36
+ now: Date;
37
+ /** The HTTP seam. Defaults to the runtime's `fetch`. */
38
+ transport?: LemonSqueezyHttpFetch;
39
+ }
40
+ /** Re-read one purchase, or `undefined` when Lemon Squeezy has nothing to say about it. */
41
+ export declare function refreshLemonSqueezyPurchase(purchase: PaymentsPurchase, options: RefreshLemonSqueezyOptions): Promise<UnboundProviderEvent | undefined>;
42
+ //# sourceMappingURL=refresh.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"refresh.d.ts","sourceRoot":"","sources":["../../../src/rails/lemonSqueezy/refresh.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,uBAAuB,CAAC;AAC7E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,OAAO,CAAC;AAKnD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,2EAA2E;AAC3E,MAAM,WAAW,0BAA0B;IACzC,8BAA8B;IAC9B,WAAW,EAAE,+BAA+B,CAAC;IAC7C,oEAAoE;IACpE,GAAG,EAAE,IAAI,CAAC;IACV,wDAAwD;IACxD,SAAS,CAAC,EAAE,qBAAqB,CAAC;CACnC;AASD,2FAA2F;AAC3F,wBAAsB,2BAA2B,CAC/C,QAAQ,EAAE,gBAAgB,EAC1B,OAAO,EAAE,0BAA0B,GAClC,OAAO,CAAC,oBAAoB,GAAG,SAAS,CAAC,CA0B3C"}
@@ -0,0 +1,40 @@
1
+ import { lemonSqueezyHttpFetch } from "./api.js";
2
+ import { orderEvent, subscriptionEvent } from "./objects.js";
3
+ import { readOrder, readSubscription } from "./read.js";
4
+ //#region src/rails/lemonSqueezy/refresh.ts
5
+ /** Split a namespaced id back into its type and its Lemon Squeezy id. */
6
+ function split(providerTransactionId) {
7
+ const at = providerTransactionId.indexOf(":");
8
+ if (at <= 0) return void 0;
9
+ return {
10
+ type: providerTransactionId.slice(0, at),
11
+ id: providerTransactionId.slice(at + 1)
12
+ };
13
+ }
14
+ /** Re-read one purchase, or `undefined` when Lemon Squeezy has nothing to say about it. */
15
+ async function refreshLemonSqueezyPurchase(purchase, options) {
16
+ const key = split(purchase.providerTransactionId);
17
+ if (key === void 0) return void 0;
18
+ const read = {
19
+ credentials: options.credentials,
20
+ transport: options.transport ?? lemonSqueezyHttpFetch
21
+ };
22
+ if (key.type === "subscription") {
23
+ const subscription = await readSubscription(key.id, read);
24
+ if (subscription === void 0) return void 0;
25
+ return {
26
+ ...subscriptionEvent(key.id, subscription),
27
+ providerEventAt: options.now
28
+ };
29
+ }
30
+ if (key.type === "order") {
31
+ const order = await readOrder(key.id, read);
32
+ if (order === void 0) return void 0;
33
+ return {
34
+ ...orderEvent(key.id, order),
35
+ providerEventAt: options.now
36
+ };
37
+ }
38
+ }
39
+ //#endregion
40
+ export { refreshLemonSqueezyPurchase };
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Lemon Squeezy's authenticity proof: a bare HMAC over the exact received bytes, in one header.
3
+ *
4
+ * `X-Signature: 5257a8…` — one hex HMAC-SHA256 of the body, keyed with the webhook's signing secret. No
5
+ * timestamp, no scheme prefix, no list.
6
+ *
7
+ * ## Why this does not go through core's `signed-webhook` primitive
8
+ *
9
+ * That primitive implements Stripe's format — `t=…,v1=…` — and every security property it enforces is a
10
+ * property *of that format*: the freshness window in both directions, the timestamp being inside the signed
11
+ * payload, a cap on how many signatures a header may list. Lemon Squeezy's scheme has none of them to
12
+ * enforce. Generalizing the primitive to carry a scheme would mean giving it a variant whose `now` and
13
+ * `toleranceSeconds` are accepted and ignored, and a parameter a caller can set that changes nothing is
14
+ * worse than no parameter: somebody eventually reads the call site and believes the window is there.
15
+ *
16
+ * So the absence is expressed in the type. {@link verifyLemonSqueezySignature} takes no options bag and no
17
+ * clock — there is nowhere to pass a tolerance, so no call site can claim a window this rail does not
18
+ * honor, and the refusal union below has two members where Stripe's has three. There is no `stale`.
19
+ *
20
+ * ## Where replay protection actually lives
21
+ *
22
+ * Entirely in the webhook guard's `UNIQUE (rail, providerEventId)` insert. A captured delivery replayed a
23
+ * year later carries a signature that is still valid — that is a true fact about this scheme, not a defect
24
+ * in this module — and is refused because its event id is already in `pithy_payments_webhook_events`. The
25
+ * projection's monotonic `providerEventAt` rule is the second line: a replayed state claim about a
26
+ * subscription that has since moved on is staler than the row and is ignored.
27
+ *
28
+ * Worth stating plainly because it is the one property an operator might assume from the other rails and
29
+ * not have here.
30
+ *
31
+ * ## What a refusal says
32
+ *
33
+ * `payments/verification_failed`, with the reason in `detail` and nothing the delivery carried — not the
34
+ * body, not the candidate signature, never the secret. `detail` reaches an operator's log, and the webhook
35
+ * guard maps this to `payments/webhook_unverified` (401) before anything reaches the sender, so a forger
36
+ * learns only that it failed. That code is this rail's contract with its guard.
37
+ */
38
+ /** The header Lemon Squeezy puts its proof in. Lower case, because that is how Hono presents a header name. */
39
+ export declare const LEMON_SQUEEZY_SIGNATURE_HEADER = "x-signature";
40
+ /**
41
+ * The signature Lemon Squeezy would send for these bytes — lower-case hex.
42
+ *
43
+ * Exported for the tests and the fixtures, which mint their own so verification is exercised for real
44
+ * rather than stubbed. Nothing in the request path signs anything: this rail only ever verifies.
45
+ */
46
+ export declare function signLemonSqueezyBody(body: string, secret: string): Promise<string>;
47
+ /**
48
+ * Verify one delivery's `X-Signature`. Resolves when Lemon Squeezy signed these exact bytes, and throws
49
+ * `payments/verification_failed` otherwise.
50
+ *
51
+ * The comparison is `crypto.subtle.verify`, never `===` on the hex and never a hand-written loop: the
52
+ * runtime's own compare is constant-time, and a string equality on a MAC leaks how many leading bytes an
53
+ * attacker got right.
54
+ */
55
+ export declare function verifyLemonSqueezySignature(body: string, header: string | null, secret: string): Promise<void>;
56
+ //# sourceMappingURL=signature.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signature.d.ts","sourceRoot":"","sources":["../../../src/rails/lemonSqueezy/signature.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAEH,+GAA+G;AAC/G,eAAO,MAAM,8BAA8B,gBAAgB,CAAC;AA6B5D;;;;;GAKG;AACH,wBAAsB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAGxF;AAED;;;;;;;GAOG;AACH,wBAAsB,2BAA2B,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAapH"}
@@ -0,0 +1,92 @@
1
+ import { PaymentsVerificationFailedError } from "../../error/errors.js";
2
+ //#region src/rails/lemonSqueezy/signature.ts
3
+ /**
4
+ * Lemon Squeezy's authenticity proof: a bare HMAC over the exact received bytes, in one header.
5
+ *
6
+ * `X-Signature: 5257a8…` — one hex HMAC-SHA256 of the body, keyed with the webhook's signing secret. No
7
+ * timestamp, no scheme prefix, no list.
8
+ *
9
+ * ## Why this does not go through core's `signed-webhook` primitive
10
+ *
11
+ * That primitive implements Stripe's format — `t=…,v1=…` — and every security property it enforces is a
12
+ * property *of that format*: the freshness window in both directions, the timestamp being inside the signed
13
+ * payload, a cap on how many signatures a header may list. Lemon Squeezy's scheme has none of them to
14
+ * enforce. Generalizing the primitive to carry a scheme would mean giving it a variant whose `now` and
15
+ * `toleranceSeconds` are accepted and ignored, and a parameter a caller can set that changes nothing is
16
+ * worse than no parameter: somebody eventually reads the call site and believes the window is there.
17
+ *
18
+ * So the absence is expressed in the type. {@link verifyLemonSqueezySignature} takes no options bag and no
19
+ * clock — there is nowhere to pass a tolerance, so no call site can claim a window this rail does not
20
+ * honor, and the refusal union below has two members where Stripe's has three. There is no `stale`.
21
+ *
22
+ * ## Where replay protection actually lives
23
+ *
24
+ * Entirely in the webhook guard's `UNIQUE (rail, providerEventId)` insert. A captured delivery replayed a
25
+ * year later carries a signature that is still valid — that is a true fact about this scheme, not a defect
26
+ * in this module — and is refused because its event id is already in `pithy_payments_webhook_events`. The
27
+ * projection's monotonic `providerEventAt` rule is the second line: a replayed state claim about a
28
+ * subscription that has since moved on is staler than the row and is ignored.
29
+ *
30
+ * Worth stating plainly because it is the one property an operator might assume from the other rails and
31
+ * not have here.
32
+ *
33
+ * ## What a refusal says
34
+ *
35
+ * `payments/verification_failed`, with the reason in `detail` and nothing the delivery carried — not the
36
+ * body, not the candidate signature, never the secret. `detail` reaches an operator's log, and the webhook
37
+ * guard maps this to `payments/webhook_unverified` (401) before anything reaches the sender, so a forger
38
+ * learns only that it failed. That code is this rail's contract with its guard.
39
+ */
40
+ /** The header Lemon Squeezy puts its proof in. Lower case, because that is how Hono presents a header name. */
41
+ const LEMON_SQUEEZY_SIGNATURE_HEADER = "x-signature";
42
+ /** How many bytes an HMAC-SHA256 is. A candidate of any other length cannot be one, whatever it decodes to. */
43
+ const HMAC_SHA256_BYTES = 32;
44
+ /** Decode lower- or upper-case hex, or `undefined` when it is not hex at all. */
45
+ function hexBytes(value) {
46
+ if (value.length === 0 || value.length % 2 !== 0 || !/^[0-9a-fA-F]+$/.test(value)) return void 0;
47
+ const bytes = new Uint8Array(value.length / 2);
48
+ for (let index = 0; index < bytes.length; index += 1) bytes[index] = Number.parseInt(value.slice(index * 2, index * 2 + 2), 16);
49
+ return bytes;
50
+ }
51
+ /** Import a signing secret for HMAC-SHA256. */
52
+ async function signingKey(secret, usage) {
53
+ return await crypto.subtle.importKey("raw", new TextEncoder().encode(secret), {
54
+ name: "HMAC",
55
+ hash: "SHA-256"
56
+ }, false, [usage]);
57
+ }
58
+ /**
59
+ * The signature Lemon Squeezy would send for these bytes — lower-case hex.
60
+ *
61
+ * Exported for the tests and the fixtures, which mint their own so verification is exercised for real
62
+ * rather than stubbed. Nothing in the request path signs anything: this rail only ever verifies.
63
+ */
64
+ async function signLemonSqueezyBody(body, secret) {
65
+ const mac = await crypto.subtle.sign("HMAC", await signingKey(secret, "sign"), new TextEncoder().encode(body));
66
+ return [...new Uint8Array(mac)].map((byte) => byte.toString(16).padStart(2, "0")).join("");
67
+ }
68
+ /**
69
+ * Verify one delivery's `X-Signature`. Resolves when Lemon Squeezy signed these exact bytes, and throws
70
+ * `payments/verification_failed` otherwise.
71
+ *
72
+ * The comparison is `crypto.subtle.verify`, never `===` on the hex and never a hand-written loop: the
73
+ * runtime's own compare is constant-time, and a string equality on a MAC leaks how many leading bytes an
74
+ * attacker got right.
75
+ */
76
+ async function verifyLemonSqueezySignature(body, header, secret) {
77
+ const candidate = header === null ? void 0 : hexBytes(header.trim());
78
+ if (candidate === void 0 || candidate.length !== HMAC_SHA256_BYTES) throw new PaymentsVerificationFailedError({ detail: refusal("unreadable") });
79
+ if (!await crypto.subtle.verify("HMAC", await signingKey(secret, "verify"), candidate, new TextEncoder().encode(body))) throw new PaymentsVerificationFailedError({ detail: refusal("unmatched") });
80
+ }
81
+ /**
82
+ * This rail's wording for its two refusals.
83
+ *
84
+ * Prefixed `Lemon Squeezy:` because a payments Worker composes several rails and `detail` is what an
85
+ * operator reads to find out which one refused. The strings say what failed and what to check, and nothing
86
+ * the delivery carried.
87
+ */
88
+ function refusal(reason) {
89
+ return reason === "unreadable" ? "Lemon Squeezy: the delivery carries no X-Signature header holding 32 bytes of hex." : "Lemon Squeezy: the X-Signature does not match these bytes under the configured signing secret. Check that the secret belongs to this webhook and this store.";
90
+ }
91
+ //#endregion
92
+ export { LEMON_SQUEEZY_SIGNATURE_HEADER, signLemonSqueezyBody, verifyLemonSqueezySignature };
@@ -0,0 +1,33 @@
1
+ import type { VerifiedPurchase } from "../contract";
2
+ /**
3
+ * This rail has no client-submittable receipt, and says so.
4
+ *
5
+ * ## Why refusing is the secure answer
6
+ *
7
+ * `verify` exists so a buyer sees their entitlement without waiting for the webhook. Stripe can do that
8
+ * because a returning buyer carries a Checkout Session id that Stripe substituted into the success URL: an
9
+ * unguessable token this deployment's own server can trade for a session carrying `client_reference_id`.
10
+ *
11
+ * Lemon Squeezy has no equivalent. Its order ids are **sequential integers**, so a `verify` that trusted a
12
+ * submitted order id would let any authenticated caller claim any order in the store by counting — including
13
+ * one belonging to somebody who has not signed in yet, whose purchase would then be bound to the attacker
14
+ * forever, because `linkProviderAccount` never rebinds and the first pairing wins.
15
+ *
16
+ * The order's UUID `identifier` was the obvious repair and is not one. It is unguessable, but it is not a
17
+ * *credential*: it appears in the buyer's own receipt email and in the storefront's return URL, so it proves
18
+ * possession of a value that was never secret, and Lemon Squeezy does not return `custom_data` on the order
19
+ * object in a form this server could check against the caller. Binding on an unguessable-but-unauthenticated
20
+ * identifier is exactly the class of mistake the {@link VerifiedPurchase.accountReference} doc warns about:
21
+ * it lets a client's choice of value decide who a purchase belongs to.
22
+ *
23
+ * ## What it costs, stated plainly
24
+ *
25
+ * A Lemon Squeezy buyer's entitlement appears when the webhook lands rather than the moment they return —
26
+ * seconds, usually. The `successUrl` this rail's config asks for should therefore show a pending state and
27
+ * poll, not post a receipt. `docs/lemon-squeezy.md` says so, and the scaffolded return page does it.
28
+ *
29
+ * The webhook is authoritative on every rail anyway. Here it is simply the only path.
30
+ */
31
+ /** Refuse a submitted Lemon Squeezy receipt. There is no shape of one that could be trusted. */
32
+ export declare function verifyLemonSqueezyOrder(_receipt: string): Promise<VerifiedPurchase>;
33
+ //# sourceMappingURL=verify.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../../../src/rails/lemonSqueezy/verify.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,gGAAgG;AAChG,wBAAsB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAOzF"}
@@ -0,0 +1,41 @@
1
+ import { PaymentsInvalidReceiptError } from "../../error/errors.js";
2
+ //#region src/rails/lemonSqueezy/verify.ts
3
+ /**
4
+ * This rail has no client-submittable receipt, and says so.
5
+ *
6
+ * ## Why refusing is the secure answer
7
+ *
8
+ * `verify` exists so a buyer sees their entitlement without waiting for the webhook. Stripe can do that
9
+ * because a returning buyer carries a Checkout Session id that Stripe substituted into the success URL: an
10
+ * unguessable token this deployment's own server can trade for a session carrying `client_reference_id`.
11
+ *
12
+ * Lemon Squeezy has no equivalent. Its order ids are **sequential integers**, so a `verify` that trusted a
13
+ * submitted order id would let any authenticated caller claim any order in the store by counting — including
14
+ * one belonging to somebody who has not signed in yet, whose purchase would then be bound to the attacker
15
+ * forever, because `linkProviderAccount` never rebinds and the first pairing wins.
16
+ *
17
+ * The order's UUID `identifier` was the obvious repair and is not one. It is unguessable, but it is not a
18
+ * *credential*: it appears in the buyer's own receipt email and in the storefront's return URL, so it proves
19
+ * possession of a value that was never secret, and Lemon Squeezy does not return `custom_data` on the order
20
+ * object in a form this server could check against the caller. Binding on an unguessable-but-unauthenticated
21
+ * identifier is exactly the class of mistake the {@link VerifiedPurchase.accountReference} doc warns about:
22
+ * it lets a client's choice of value decide who a purchase belongs to.
23
+ *
24
+ * ## What it costs, stated plainly
25
+ *
26
+ * A Lemon Squeezy buyer's entitlement appears when the webhook lands rather than the moment they return —
27
+ * seconds, usually. The `successUrl` this rail's config asks for should therefore show a pending state and
28
+ * poll, not post a receipt. `docs/lemon-squeezy.md` says so, and the scaffolded return page does it.
29
+ *
30
+ * The webhook is authoritative on every rail anyway. Here it is simply the only path.
31
+ */
32
+ /** Refuse a submitted Lemon Squeezy receipt. There is no shape of one that could be trusted. */
33
+ async function verifyLemonSqueezyOrder(_receipt) {
34
+ throw new PaymentsInvalidReceiptError({
35
+ message: "Lemon Squeezy purchases confirm themselves.",
36
+ action: "Nothing to submit. Your purchase appears as soon as Lemon Squeezy tells the server about it.",
37
+ detail: "Lemon Squeezy has no client-submittable receipt: an order id is a sequential integer, and the order object carries no reference this server set, so accepting one would let any authenticated caller claim an unprojected order by counting. Purchases on this rail land through the webhook alone."
38
+ });
39
+ }
40
+ //#endregion
41
+ export { verifyLemonSqueezyOrder };
@@ -0,0 +1,53 @@
1
+ import type { PaymentsLemonSqueezyCredentials } from "../../secret/registry";
2
+ import type { VerifiedNotification, WebhookDelivery } from "../contract";
3
+ import { type LemonSqueezyHttpFetch } from "./api";
4
+ /**
5
+ * Verify and read one Lemon Squeezy delivery.
6
+ *
7
+ * ## The event id, and where replay protection lives
8
+ *
9
+ * Lemon Squeezy does not put an event id in the body, so the id this rail reports is composed from what the
10
+ * **signed bytes** always carry: `meta.event_name` and the object it is about. That is stable across
11
+ * redeliveries of the same event — which is the whole property `UNIQUE (rail, providerEventId)` needs — and
12
+ * different for two genuinely different events about one object.
13
+ *
14
+ * **Nothing outside the signed body may contribute to it.** The HMAC covers the body alone, so the
15
+ * `X-Event-Name` header Lemon Squeezy also sends is attacker-controlled on a replayed delivery; composing the
16
+ * id from it would let one captured body be resent under any name, defeating the only replay defense this
17
+ * rail has. Every other rail derives its id from signed content too — Stripe's `event.id`, Apple's
18
+ * `notificationUUID` from inside the JWS — and this one is no exception.
19
+ *
20
+ * It is deliberately *not* unique per delivery attempt. A redelivery must collide, because colliding is how
21
+ * the guard recognizes it and answers 200 without reprojecting.
22
+ *
23
+ * ## Why an invoice event costs a round-trip
24
+ *
25
+ * A Lemon Squeezy subscription invoice carries no `variant_id`, and `providerProductId` is mandatory — the
26
+ * writer resolves the catalog product from it and refuses without one. So an invoice-domain delivery reads
27
+ * its subscription to learn which variant it bills. That is the Google rail's shape exactly, and it is why
28
+ * `payments/provider_unavailable` passes through the webhook guard unchanged: an outage at Lemon Squeezy
29
+ * must make the store redeliver, not make the operator hunt for a rotated signing key.
30
+ *
31
+ * Subscription-domain and order-domain deliveries carry everything they need and cost nothing.
32
+ */
33
+ /** What the parser needs: the credentials, the deployment doing the asking, and the transport. */
34
+ export interface ParseLemonSqueezyNotificationOptions {
35
+ /** The rail's credentials — the signing secret is read from here and never logged. */
36
+ credentials: PaymentsLemonSqueezyCredentials;
37
+ /** This deployment's `ENVIRONMENT`, for the shared-store fence. */
38
+ deployment?: string;
39
+ /** The transport the subscription read goes through. Defaults to the runtime's `fetch`. */
40
+ transport?: LemonSqueezyHttpFetch;
41
+ /**
42
+ * Whether this variant is sold as a subscription, per the adopter's catalog.
43
+ *
44
+ * The rail cannot answer it — a Lemon Squeezy order carries no subscription marker — and it must not
45
+ * guess, because guessing wrong either double-credits a subscriber's first period or drops a one-off
46
+ * sale. `resolveRailProvider` has the config, so it supplies the answer. Absent means "assume one-off",
47
+ * which is the behavior for a project whose catalog the rail was built without.
48
+ */
49
+ sellsSubscription?: (variantId: string) => boolean;
50
+ }
51
+ /** Verify a delivery's signature and read what it says. */
52
+ export declare function parseLemonSqueezyNotification(delivery: WebhookDelivery, options: ParseLemonSqueezyNotificationOptions): Promise<VerifiedNotification>;
53
+ //# sourceMappingURL=webhook.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhook.d.ts","sourceRoot":"","sources":["../../../src/rails/lemonSqueezy/webhook.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,uBAAuB,CAAC;AAC7E,OAAO,KAAK,EAAwB,oBAAoB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC/F,OAAO,EAAE,KAAK,qBAAqB,EAAyB,MAAM,OAAO,CAAC;AAgB1E;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,kGAAkG;AAClG,MAAM,WAAW,oCAAoC;IACnD,sFAAsF;IACtF,WAAW,EAAE,+BAA+B,CAAC;IAC7C,mEAAmE;IACnE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,2FAA2F;IAC3F,SAAS,CAAC,EAAE,qBAAqB,CAAC;IAClC;;;;;;;OAOG;IACH,iBAAiB,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC;CACpD;AA6DD,2DAA2D;AAC3D,wBAAsB,6BAA6B,CACjD,QAAQ,EAAE,eAAe,EACzB,OAAO,EAAE,oCAAoC,GAC5C,OAAO,CAAC,oBAAoB,CAAC,CA4C/B"}
@@ -0,0 +1,179 @@
1
+ import { PaymentsVerificationFailedError } from "../../error/errors.js";
2
+ import { lemonSqueezyHttpFetch } from "./api.js";
3
+ import { LemonSqueezyOrder, LemonSqueezySubscription, LemonSqueezySubscriptionInvoice, LemonSqueezyWebhook, accountReferenceOf, fencedOut, invoiceEvent, namespacedId, orderEvent, subscriptionEvent } from "./objects.js";
4
+ import { readSubscription } from "./read.js";
5
+ import { verifyLemonSqueezySignature } from "./signature.js";
6
+ //#region src/rails/lemonSqueezy/webhook.ts
7
+ /**
8
+ * This delivery's id: the event name, the object, and **the object's own clock**.
9
+ *
10
+ * The clock is the part that makes it an *event* id rather than an object id, and leaving it out was a
11
+ * defect rather than a simplification. `subscription_updated` fires on every renewal, plan change, pause and
12
+ * status move for one subscription, so `subscription_updated:90001` names all of them. The guard inserts
13
+ * `UNIQUE (rail, providerEventId)` and answers a row it has already processed with a 200 and no reprojection
14
+ * — so the first update would be projected and **every later one silently dropped as a replay**, including
15
+ * the cancellation.
16
+ *
17
+ * `updated_at` moves with each of those changes and is inside the signed bytes, so two genuinely different
18
+ * events differ and a redelivery of one event still collides, which is exactly what the guard needs. Where
19
+ * the object carries no clock the id falls back to the pair, which is no worse than before.
20
+ *
21
+ * Not `receivedAt` or a random value: a redelivery **must** collide, because colliding is how a store's
22
+ * at-least-once retry is recognized rather than reprocessed.
23
+ */
24
+ function composeEventId(name, webhook) {
25
+ const clock = webhook.data.attributes.updated_at;
26
+ return typeof clock === "string" && clock !== "" ? `${name}:${webhook.data.id}:${clock}` : `${name}:${webhook.data.id}`;
27
+ }
28
+ /** Every subscription-domain event: the standing changed, and no money moved. */
29
+ const SUBSCRIPTION_EVENTS = /* @__PURE__ */ new Set([
30
+ "subscription_created",
31
+ "subscription_updated",
32
+ "subscription_cancelled",
33
+ "subscription_expired",
34
+ "subscription_paused",
35
+ "subscription_unpaused"
36
+ ]);
37
+ /** Every invoice-domain event: money moved, and the standing is not in the payload. */
38
+ const INVOICE_EVENTS = /* @__PURE__ */ new Set([
39
+ "subscription_payment_success",
40
+ "subscription_payment_failed",
41
+ "subscription_payment_recovered",
42
+ "subscription_payment_refunded"
43
+ ]);
44
+ /** Every order-domain event: a one-off, where money and state are the same object. */
45
+ const ORDER_EVENTS = /* @__PURE__ */ new Set(["order_created", "order_refunded"]);
46
+ /** Nothing at all was learned, but the delivery was authentic. The four-field null tuple every rail returns. */
47
+ function nothing(webhook, providerEventId) {
48
+ return {
49
+ providerEventId,
50
+ payload: { ...webhook },
51
+ event: null,
52
+ providerAccountId: null,
53
+ accountReference: null,
54
+ note: null
55
+ };
56
+ }
57
+ /** Verify a delivery's signature and read what it says. */
58
+ async function parseLemonSqueezyNotification(delivery, options) {
59
+ await verifyLemonSqueezySignature(delivery.body, delivery.headers.get("x-signature"), options.credentials.webhookSecret);
60
+ let parsed;
61
+ try {
62
+ parsed = JSON.parse(delivery.body);
63
+ } catch (cause) {
64
+ throw new PaymentsVerificationFailedError({ detail: "Lemon Squeezy: the delivery body is not JSON." }, { cause });
65
+ }
66
+ const envelope = LemonSqueezyWebhook.safeParse(parsed);
67
+ if (!envelope.success) throw new PaymentsVerificationFailedError({ detail: "Lemon Squeezy: the delivery is not a webhook envelope — no meta.event_name, or no data object." });
68
+ const webhook = envelope.data;
69
+ const name = webhook.meta.event_name;
70
+ const providerEventId = composeEventId(name, webhook);
71
+ if (fencedOut(webhook, options.deployment)) return nothing(webhook, providerEventId);
72
+ if (SUBSCRIPTION_EVENTS.has(name)) return await subscriptionNotification(webhook, providerEventId, options);
73
+ if (INVOICE_EVENTS.has(name)) return await invoiceNotification(webhook, providerEventId, name, options);
74
+ if (ORDER_EVENTS.has(name)) return await orderNotification(webhook, providerEventId, options);
75
+ return nothing(webhook, providerEventId);
76
+ }
77
+ /** A subscription-domain delivery: one state row, no round-trip. */
78
+ async function subscriptionNotification(webhook, providerEventId, options) {
79
+ const subscription = LemonSqueezySubscription.parse(webhook.data.attributes);
80
+ return {
81
+ providerEventId,
82
+ payload: { ...webhook },
83
+ event: subscriptionEvent(webhook.data.id, subscription),
84
+ providerAccountId: subscription.customer_id === void 0 ? null : String(subscription.customer_id),
85
+ accountReference: await accountReferenceOf(webhook, options.deployment, options.credentials.webhookSecret)
86
+ };
87
+ }
88
+ /**
89
+ * An order-domain delivery: one row, money and state together — **unless the order started a subscription**.
90
+ *
91
+ * A payment received is what creates a charge row, and one payment must create exactly one. Lemon Squeezy
92
+ * raises an Order for a subscription purchase as well as the subscription itself, and it raises a
93
+ * subscription invoice for every billing period *including the first* — so for a subscription the order and
94
+ * the first invoice are the **same money**, reported twice. Projecting both credits one period twice, and
95
+ * the order's row would grant forever besides: an order is a one-off, so it carries no expiry, and a
96
+ * never-expiring `active` row outranks the subscription's state row even after a cancellation.
97
+ *
98
+ * A subscription's money is its invoices. So an order that started one records nothing here and says why,
99
+ * and the subscription's own events carry both halves.
100
+ *
101
+ * The discriminator is the **catalog**, not a round-trip: a Lemon Squeezy variant is a subscription variant
102
+ * or a one-off variant and never both, so the product an adopter declared for that variant already answers
103
+ * it. `resolveRailProvider` has the config, so the rail is handed the question rather than guessing at it or
104
+ * paying for an extra call.
105
+ */
106
+ async function orderNotification(webhook, providerEventId, options) {
107
+ const order = LemonSqueezyOrder.parse(webhook.data.attributes);
108
+ const variantId = String(order.first_order_item?.variant_id ?? "");
109
+ if (options.sellsSubscription?.(variantId) === true) return {
110
+ providerEventId,
111
+ payload: { ...webhook },
112
+ event: null,
113
+ providerAccountId: order.customer_id === void 0 ? null : String(order.customer_id),
114
+ accountReference: await accountReferenceOf(webhook, options.deployment, options.credentials.webhookSecret),
115
+ note: null
116
+ };
117
+ return {
118
+ providerEventId,
119
+ payload: { ...webhook },
120
+ event: orderEvent(webhook.data.id, order),
121
+ providerAccountId: order.customer_id === void 0 ? null : String(order.customer_id),
122
+ accountReference: await accountReferenceOf(webhook, options.deployment, options.credentials.webhookSecret)
123
+ };
124
+ }
125
+ /**
126
+ * An invoice-domain delivery: one money row, and on a refund a second event revoking access.
127
+ *
128
+ * The subscription read is needed anyway — the invoice carries no variant — so the refund's state event
129
+ * costs no extra call beyond the one the variant already required.
130
+ */
131
+ async function invoiceNotification(webhook, providerEventId, name, options) {
132
+ const invoice = LemonSqueezySubscriptionInvoice.parse(webhook.data.attributes);
133
+ const subscriptionId = String(invoice.subscription_id);
134
+ const subscription = await readSubscription(subscriptionId, {
135
+ credentials: options.credentials,
136
+ transport: options.transport ?? lemonSqueezyHttpFetch
137
+ });
138
+ if (subscription === void 0) return {
139
+ providerEventId,
140
+ payload: { ...webhook },
141
+ event: null,
142
+ providerAccountId: invoice.customer_id === void 0 ? null : String(invoice.customer_id),
143
+ accountReference: await accountReferenceOf(webhook, options.deployment, options.credentials.webhookSecret),
144
+ note: { read: `Lemon Squeezy no longer knows subscription ${subscriptionId}, which invoice ${webhook.data.id} bills.` }
145
+ };
146
+ const event = invoiceEvent(webhook.data.id, invoice, String(subscription.variant_id ?? ""));
147
+ return {
148
+ providerEventId,
149
+ payload: { ...webhook },
150
+ event,
151
+ providerAccountId: invoice.customer_id === void 0 ? null : String(invoice.customer_id),
152
+ accountReference: await accountReferenceOf(webhook, options.deployment, options.credentials.webhookSecret),
153
+ stateEvent: name === "subscription_payment_refunded" ? revocation(subscriptionId, subscription, event) : null
154
+ };
155
+ }
156
+ /**
157
+ * The state event a refund implies: access stops, now.
158
+ *
159
+ * Deliberately **not** the subscription's current status. Lemon Squeezy is a merchant of record and refunds
160
+ * on its own — for a chargeback, a tax dispute, or its own support decision — and it does not necessarily
161
+ * cancel the subscription when it does, so reading its status back would frequently say `active` and leave a
162
+ * refunded buyer holding the feature. The money went back; the access goes with it.
163
+ *
164
+ * `revoked` rather than `refunded` because the two say different things about this row: the *invoice* was
165
+ * refunded, and the subscription's standing was revoked as a consequence. Neither status grants, and
166
+ * `revoked` on a `state` row never claws back — that is the money row's job, on the row that credited.
167
+ */
168
+ function revocation(subscriptionId, subscription, invoice) {
169
+ return {
170
+ ...subscriptionEvent(subscriptionId, subscription),
171
+ providerTransactionId: namespacedId("subscription", subscriptionId),
172
+ status: "revoked",
173
+ revokedAt: invoice.providerEventAt,
174
+ expiresAt: invoice.providerEventAt,
175
+ providerEventAt: invoice.providerEventAt
176
+ };
177
+ }
178
+ //#endregion
179
+ export { parseLemonSqueezyNotification };