@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,379 @@
1
+ import { decodeSubjectReference } from "../../data/subject.js";
2
+ import { PaymentsVerificationFailedError } from "../../error/errors.js";
3
+ import { pauseResumesAt } from "../../data/pause.js";
4
+ import { z } from "zod";
5
+ //#region src/rails/lemonSqueezy/objects.ts
6
+ /**
7
+ * Lemon Squeezy's objects, and the mapping from what its webhooks say to what this package stores.
8
+ *
9
+ * ## Identifiers are namespaced, and that is not a style choice
10
+ *
11
+ * Lemon Squeezy numbers **each object type from one**, and renders the number as a JSON:API string. So order
12
+ * `8801` and subscription-invoice `8801` are different objects wearing the same `data.id`. A purchase row's
13
+ * identity is `UNIQUE (rail, providerTransactionId)`, so storing the bare id would silently fuse an order and
14
+ * an invoice into one row — one buyer's refund landing on another buyer's subscription.
15
+ *
16
+ * Stripe never faced this because `pi_`, `in_` and `sub_` are globally distinct, so the Stripe rail stores its
17
+ * ids verbatim. Here the type has to be part of the key, and {@link namespacedId} is the only way an id is
18
+ * allowed to reach the writer. The prefix is stable forever: it is inside the row's identity.
19
+ *
20
+ * ## Two rows per subscription, and why
21
+ *
22
+ * Lemon Squeezy splits money from state at the source. `subscription_payment_*` delivers a **subscription
23
+ * invoice**: an amount, a currency, and nothing about whether the subscription is still live.
24
+ * `subscription_*` delivers a **subscription**: a status and a renewal date, and no charge. Neither names the
25
+ * other's key — an LS subscription has no latest-invoice pointer — so there is no honest way to collapse them
26
+ * onto one row.
27
+ *
28
+ * Collapsing them anyway would mean stamping two different clocks into one monotonic `providerEventAt`: the
29
+ * invoice's `updated_at` lives in the invoice domain and moves when a refund is issued months later, while the
30
+ * subscription's moves on every renewal. That is the defect the CMS learned expensively — an invoice timestamp
31
+ * written into a subscription's watermark drops the `subscription_updated` that follows a renewal.
32
+ *
33
+ * So: a **state row** keyed on the subscription, and a **money row** per invoice, distinguished by
34
+ * `PurchaseRole`. Each row is monotonic on exactly one provider clock, and an invoice event physically cannot
35
+ * address the state row because the keys differ. That is a property of the schema rather than of careful code.
36
+ * Only the money rows fulfill a `grants` clause, which is what makes N renewals credit exactly N times.
37
+ *
38
+ * ## The environment fence
39
+ *
40
+ * A Lemon Squeezy store is **one namespace across every environment** — test mode is a flag on an object, not
41
+ * a separate store — so a `dev` deployment and a `staging` deployment pointed at one store both hear
42
+ * everything the other's buyers do. `createCheckoutSession` stamps this deployment's `ENVIRONMENT` into
43
+ * `checkout_data.custom`, the store echoes it back as `meta.custom_data`, and an event stamped for somebody
44
+ * else projects nothing: no row, no entitlement, no audit warning, and a 200.
45
+ *
46
+ * An event carrying **no** stamp is not fenced. An order placed in the Lemon Squeezy storefront rather than
47
+ * through our checkout carries no `custom_data` at all, and fencing on absence would silently drop real sales.
48
+ *
49
+ * `test_mode` is a separate axis and drives `environment`, which the projection writer refuses across.
50
+ *
51
+ * ## Custom data is snake_case, in both directions
52
+ *
53
+ * Lemon Squeezy normalizes custom keys to snake_case before echoing them back. What checkout sends and what
54
+ * this module reads must therefore both be snake_case, even though the rest of this codebase is camelCase.
55
+ * Sending `pithyEnv` and reading `pithy_env` silently never matches, and the binding never happens — so the
56
+ * two constants below are the single source for both sides and the round-trip is pinned by a test.
57
+ */
58
+ /**
59
+ * The `checkout_data.custom` key carrying the subject reference. snake_case, because LS normalizes to it.
60
+ *
61
+ * **The name is frozen even though its meaning moved.** What travels here is now
62
+ * `encodeSubjectReference`'s output — `user:ada`, `organization:acme` — because a purchase can be held by an
63
+ * organization. This string is a wire contract with Lemon Squeezy rather than an identifier of ours: a
64
+ * checkout stamped today is a hosted page open in somebody's browser and a subscription that renews for
65
+ * months, and the store echoes whatever it was given back on every delivery that purchase ever produces. A
66
+ * renamed key reads nothing on any of them — every in-flight purchase would come back naming nobody,
67
+ * permanently, with a `linkProviderAccount` that never rebinds behind it. Rename it and the loss is silent.
68
+ */
69
+ const LEMON_SQUEEZY_CUSTOM_ACCOUNT = "pithy_account_reference";
70
+ /** The `checkout_data.custom` key carrying this deployment's environment. snake_case, for the same reason. */
71
+ const LEMON_SQUEEZY_CUSTOM_ENV = "pithy_env";
72
+ /**
73
+ * The `checkout_data.custom` key carrying the proof that **this deployment's server** wrote the two above.
74
+ *
75
+ * Without it the other two prove nothing. Lemon Squeezy's public storefront buy links accept
76
+ * `checkout[custom][...]` parameters and the webhook echoes them exactly as an API-created checkout's would,
77
+ * so anyone can set `pithy_account_reference`. The environment stamp does not save it: these key names are
78
+ * exported constants in an open-source package and the value is one of three (`dev`, `staging`, `prod`), so
79
+ * requiring it asks an attacker to guess nothing at all.
80
+ *
81
+ * A MAC is the only thing that distinguishes the two, because it is the only thing a stranger cannot
82
+ * produce. See {@link accountReferenceProof}.
83
+ */
84
+ const LEMON_SQUEEZY_CUSTOM_PROOF = "pithy_ref_proof";
85
+ /**
86
+ * One identifier, prefixed by the object type it came from.
87
+ *
88
+ * The prefix is part of the row's identity forever, so it is never derived from anything that could change
89
+ * spelling. Three values, and they are the only three.
90
+ */
91
+ function namespacedId(type, id) {
92
+ return `${type}:${id}`;
93
+ }
94
+ /** A JSON:API envelope, narrowed to what any of this rail's objects need. `.loose()` — LS adds fields. */
95
+ const LemonSqueezyObject = z.object({
96
+ id: z.string().describe("The object's own id — an integer as a string, unique only within its type."),
97
+ attributes: z.record(z.string(), z.unknown()).describe("The object's fields, whose shape depends on its type.")
98
+ }).loose();
99
+ /** The webhook envelope every delivery arrives in. */
100
+ const LemonSqueezyWebhook = z.object({
101
+ meta: z.object({
102
+ event_name: z.string().describe("Which event this is — `order_created`, `subscription_updated`, and so on."),
103
+ test_mode: z.boolean().optional().describe("Whether the object belongs to the store's test mode. Drives `environment`, never the fence."),
104
+ custom_data: z.record(z.string(), z.unknown()).optional().describe("What this deployment's own server attached when it created the checkout, echoed back with keys normalized to snake_case. Absent for a storefront purchase.")
105
+ }).loose().describe("The delivery's metadata — what happened, and what we asked to have echoed back."),
106
+ data: LemonSqueezyObject.describe("The object the event is about: an order, a subscription, or an invoice.")
107
+ }).loose().describe("One Lemon Squeezy webhook delivery, as received.");
108
+ /** A subscription's fields, as a `subscription_*` webhook and the API both present them. */
109
+ const LemonSqueezySubscription = z.object({
110
+ store_id: z.number().optional().describe("The store the subscription belongs to."),
111
+ customer_id: z.number().optional().describe("The Lemon Squeezy customer — this rail's `providerAccountId`."),
112
+ variant_id: z.number().optional().describe("The variant sold, which is this rail's SKU."),
113
+ status: z.string().describe("Lemon Squeezy's own status vocabulary, normalized by `subscriptionStatus`."),
114
+ renews_at: z.string().nullish().describe("When the current period renews, if it is going to."),
115
+ ends_at: z.string().nullish().describe("When access ends for a canceled subscription, if it is ending."),
116
+ pause: z.object({
117
+ mode: z.string().nullish().describe("`void` or `free` — what the subscriber keeps while paused. Recorded."),
118
+ resumes_at: z.string().nullish().describe("When the pause ends, as Lemon Squeezy states it. Null for an open-ended pause.")
119
+ }).loose().nullish().describe("The pause in force, when one is. Null while the subscription is not paused."),
120
+ created_at: z.string().describe("When the subscription began."),
121
+ updated_at: z.string().describe("The subscription's own clock — the state row's `providerEventAt`."),
122
+ test_mode: z.boolean().optional().describe("Whether this is a test-mode subscription.")
123
+ }).loose().describe("A Lemon Squeezy subscription — the standing of a recurring purchase, carrying no charge.");
124
+ /** A subscription invoice's fields — one billing period's money. */
125
+ const LemonSqueezySubscriptionInvoice = z.object({
126
+ store_id: z.number().optional().describe("The store the invoice belongs to."),
127
+ subscription_id: z.number().describe("The subscription this invoice bills — the family key."),
128
+ customer_id: z.number().optional().describe("The Lemon Squeezy customer charged."),
129
+ status: z.string().describe("The invoice's own status — `paid`, `pending`, `void`, `refunded`."),
130
+ refunded: z.boolean().optional().describe("Whether this invoice was refunded, in whole or in part."),
131
+ refunded_at: z.string().nullish().describe("When it was refunded, if it was."),
132
+ currency: z.string().optional().describe("The ISO currency the total is in."),
133
+ total: z.number().optional().describe("The amount charged, in the currency's minor unit."),
134
+ created_at: z.string().describe("When the invoice was raised — the money row's `purchasedAt`."),
135
+ updated_at: z.string().describe("The invoice's own clock — the money row's `providerEventAt`."),
136
+ test_mode: z.boolean().optional().describe("Whether this is a test-mode invoice.")
137
+ }).loose().describe("A Lemon Squeezy subscription invoice — one billing period's charge, carrying no subscription state.");
138
+ /** An order's fields — a one-off purchase. */
139
+ const LemonSqueezyOrder = z.object({
140
+ store_id: z.number().optional().describe("The store the order belongs to."),
141
+ customer_id: z.number().optional().describe("The Lemon Squeezy customer who bought."),
142
+ status: z.string().describe("The order's status — `paid`, `refunded`, `pending`, `failed`."),
143
+ refunded: z.boolean().optional().describe("Whether the order was refunded."),
144
+ refunded_at: z.string().nullish().describe("When it was refunded, if it was."),
145
+ currency: z.string().optional().describe("The ISO currency the total is in."),
146
+ total: z.number().optional().describe("The amount charged, in the currency's minor unit."),
147
+ first_order_item: z.object({ variant_id: z.number().optional().describe("The variant bought — this rail's SKU.") }).loose().optional().describe("The order's first line item, which is where a single-product order carries its variant."),
148
+ created_at: z.string().describe("When the order was placed."),
149
+ updated_at: z.string().describe("The order's own clock."),
150
+ test_mode: z.boolean().optional().describe("Whether this is a test-mode order.")
151
+ }).loose().describe("A Lemon Squeezy order — a one-off purchase, where money and state are the same object.");
152
+ /**
153
+ * Which store environment an object belongs to.
154
+ *
155
+ * `=== false ? "production"` and never `=== true ? "sandbox"`, so an absent flag lands on sandbox. The
156
+ * failure directions are not symmetric: treating production as sandbox loses a purchase that reconciliation
157
+ * repairs, while treating sandbox as production hands out real entitlements for test transactions.
158
+ */
159
+ function environment(testMode) {
160
+ return testMode === false ? "production" : "sandbox";
161
+ }
162
+ /** A Lemon Squeezy timestamp, or a refusal. Its API emits ISO-8601 throughout. */
163
+ function at(value, what) {
164
+ const parsed = new Date(value);
165
+ if (Number.isNaN(parsed.getTime())) throw new PaymentsVerificationFailedError({ detail: `Lemon Squeezy: ${what} is not a readable timestamp.` });
166
+ return parsed;
167
+ }
168
+ /**
169
+ * A subscription's status, normalized.
170
+ *
171
+ * `on_trial` grants: a trial is access the store is currently giving, and refusing it would lock a user out
172
+ * of the thing they signed up for. `unpaid` is `on_hold` rather than `expired` — Lemon Squeezy has exhausted
173
+ * its dunning and the money never arrived, so nothing was paid and nothing may be credited. An unknown
174
+ * status refuses rather than guessing, which is the Stripe rail's rule too: a status this package has never
175
+ * seen is a shape change worth failing loudly on.
176
+ */
177
+ function subscriptionStatus(status) {
178
+ switch (status) {
179
+ case "on_trial":
180
+ case "active": return "active";
181
+ case "paused": return "paused";
182
+ case "past_due": return "in_grace";
183
+ case "unpaid": return "on_hold";
184
+ case "cancelled": return "canceled";
185
+ case "expired": return "expired";
186
+ default: throw new PaymentsVerificationFailedError({ detail: `Lemon Squeezy: subscription status "${status}" is not one this build maps.` });
187
+ }
188
+ }
189
+ /**
190
+ * A subscription invoice's status, normalized — the money's own story, not the subscription's.
191
+ *
192
+ * A paid invoice is `expired` rather than `active`, and that is deliberate: it records a billing period that
193
+ * was paid for and has closed, and `expired` is the status that credits a `grants` clause without granting
194
+ * access. Access comes from the state row. A `void` or `failed` invoice is `never_paid`, which credits
195
+ * nothing and is never clawed back, because no money ever moved.
196
+ */
197
+ function invoiceStatus(invoice) {
198
+ if (invoice.refunded === true || invoice.status === "refunded") return "refunded";
199
+ switch (invoice.status) {
200
+ case "paid": return "expired";
201
+ case "pending": return "on_hold";
202
+ case "void":
203
+ case "failed": return "never_paid";
204
+ default: throw new PaymentsVerificationFailedError({ detail: `Lemon Squeezy: subscription invoice status "${invoice.status}" is not one this build maps.` });
205
+ }
206
+ }
207
+ /** An order's status, normalized. An order is money and state at once, so a paid one grants. */
208
+ function orderStatus(order) {
209
+ if (order.refunded === true || order.status === "refunded") return "refunded";
210
+ switch (order.status) {
211
+ case "paid": return "active";
212
+ case "pending": return "on_hold";
213
+ case "failed": return "never_paid";
214
+ default: throw new PaymentsVerificationFailedError({ detail: `Lemon Squeezy: order status "${order.status}" is not one this build maps.` });
215
+ }
216
+ }
217
+ /** The state row a subscription object implies. Carries no amount — a subscription is not a charge. */
218
+ function subscriptionEvent(id, subscription) {
219
+ const status = subscriptionStatus(subscription.status);
220
+ const ends = subscription.ends_at ?? subscription.renews_at ?? null;
221
+ return {
222
+ rail: "lemonSqueezy",
223
+ providerTransactionId: namespacedId("subscription", id),
224
+ originalTransactionId: namespacedId("subscription", id),
225
+ providerProductId: String(subscription.variant_id ?? ""),
226
+ role: "state",
227
+ status,
228
+ environment: environment(subscription.test_mode),
229
+ purchasedAt: at(subscription.created_at, "a subscription's created_at"),
230
+ expiresAt: ends === null ? null : at(ends, "a subscription's ends_at"),
231
+ revokedAt: null,
232
+ resumesAt: pauseResumesAt({
233
+ rail: "lemonSqueezy",
234
+ status,
235
+ reported: subscription.pause?.resumes_at
236
+ }),
237
+ amountMinor: null,
238
+ currency: null,
239
+ providerEventAt: at(subscription.updated_at, "a subscription's updated_at"),
240
+ payload: { ...subscription }
241
+ };
242
+ }
243
+ /** The money row a subscription invoice implies, given the variant its subscription is for. */
244
+ function invoiceEvent(id, invoice, variantId) {
245
+ const status = invoiceStatus(invoice);
246
+ const raised = at(invoice.created_at, "an invoice's created_at");
247
+ return {
248
+ rail: "lemonSqueezy",
249
+ providerTransactionId: namespacedId("subscription_invoice", id),
250
+ originalTransactionId: namespacedId("subscription", String(invoice.subscription_id)),
251
+ providerProductId: variantId,
252
+ role: "charge",
253
+ status,
254
+ environment: environment(invoice.test_mode),
255
+ purchasedAt: raised,
256
+ expiresAt: raised,
257
+ revokedAt: status === "refunded" ? at(invoice.refunded_at ?? invoice.updated_at, "an invoice's refunded_at") : null,
258
+ amountMinor: invoice.total ?? null,
259
+ currency: invoice.currency ?? null,
260
+ providerEventAt: at(invoice.updated_at, "an invoice's updated_at"),
261
+ payload: { ...invoice }
262
+ };
263
+ }
264
+ /** The row a one-off order implies. Money and state at once, so one row does both jobs. */
265
+ function orderEvent(id, order) {
266
+ const status = orderStatus(order);
267
+ return {
268
+ rail: "lemonSqueezy",
269
+ providerTransactionId: namespacedId("order", id),
270
+ originalTransactionId: null,
271
+ providerProductId: String(order.first_order_item?.variant_id ?? ""),
272
+ role: "charge",
273
+ status,
274
+ environment: environment(order.test_mode),
275
+ purchasedAt: at(order.created_at, "an order's created_at"),
276
+ expiresAt: null,
277
+ revokedAt: status === "refunded" ? at(order.refunded_at ?? order.updated_at, "an order's refunded_at") : null,
278
+ amountMinor: order.total ?? null,
279
+ currency: order.currency ?? null,
280
+ providerEventAt: at(order.updated_at, "an order's updated_at"),
281
+ payload: { ...order }
282
+ };
283
+ }
284
+ /**
285
+ * The account reference this deployment stamped into the checkout, or null.
286
+ *
287
+ * **Honored only when this deployment's own environment stamp is beside it**, and that condition is the
288
+ * whole security of the field. `accountReference`'s contract says it is "a value this deployment's own
289
+ * server wrote and the store returned unchanged" — the route writes the provider-account link from it, and
290
+ * `linkProviderAccount` never rebinds, so the first pairing is permanent.
291
+ *
292
+ * Lemon Squeezy's public storefront buy links accept `checkout[custom][...]` query parameters, and the
293
+ * resulting webhook echoes them in `meta.custom_data` exactly as an API-created checkout's would. So
294
+ * `custom_data` on its own is **not** evidence our server wrote anything: an unauthenticated stranger can
295
+ * put any string in it and permanently bind their store customer to an account they chose. The env stamp is
296
+ * the discriminator, because it is written only by {@link createLemonSqueezyCheckoutSession}, and a checkout
297
+ * a stranger built through the storefront carries either no stamp or another deployment's.
298
+ *
299
+ * A deployment that does not know its own `ENVIRONMENT` trusts no reference at all. That is the safe
300
+ * direction: the cost is a purchase that lands unbound and is repairable from the trail, where the other way
301
+ * round is an unauthenticated write into the account map that nothing ever undoes.
302
+ *
303
+ * **And the value must be the subject encoding, which the MAC alone does not make it.** A stamp can be
304
+ * authentic and still name nobody: a bare id is what this rail wrote before subjects existed, and reading
305
+ * one as a user would hand a purchase to whoever else holds that id. So the reference is put through
306
+ * `decodeSubjectReference` — the one decoder, never a split written here — and anything that is not exactly
307
+ * the encoding is refused in the same direction as everything else above. The string is returned rather than
308
+ * the pair because a rail reports `accountReference` as a string; the route decodes it again through the same
309
+ * function, and gets the same answer.
310
+ */
311
+ async function accountReferenceOf(webhook, deployment, secret) {
312
+ if (deployment === void 0) return null;
313
+ const custom = webhook.meta.custom_data;
314
+ const reference = custom?.[LEMON_SQUEEZY_CUSTOM_ACCOUNT];
315
+ const stampedEnv = custom?.[LEMON_SQUEEZY_CUSTOM_ENV];
316
+ const proof = custom?.[LEMON_SQUEEZY_CUSTOM_PROOF];
317
+ if (typeof reference !== "string" || reference === "") return null;
318
+ if (typeof stampedEnv !== "string" || typeof proof !== "string") return null;
319
+ if (decodeSubjectReference(reference) === void 0) return null;
320
+ if (stampedEnv !== deployment) return null;
321
+ return await accountReferenceProofMatches(reference, deployment, secret, proof) ? reference : null;
322
+ }
323
+ /**
324
+ * The proof this deployment stamps beside an account reference, and the only reason the reference is worth
325
+ * anything.
326
+ *
327
+ * An HMAC over the environment and the subject reference, keyed with a secret a stranger does not have. The
328
+ * message is domain-separated by a fixed prefix so this MAC can never be confused with the webhook-body
329
+ * signature that shares its key: the two answer different questions, and a value that satisfied both would be
330
+ * a cross-protocol attack waiting to be found.
331
+ *
332
+ * The key is the webhook signing secret because it is already per-environment, already rotated with the
333
+ * rail, and already known only to this deployment and to Lemon Squeezy — and Lemon Squeezy is not the
334
+ * attacker here. The attacker is anyone who can open a storefront buy link, which is everyone.
335
+ */
336
+ async function accountReferenceProof(reference, deployment, secret) {
337
+ const key = await crypto.subtle.importKey("raw", new TextEncoder().encode(secret), {
338
+ name: "HMAC",
339
+ hash: "SHA-256"
340
+ }, false, ["sign"]);
341
+ const message = `${ACCOUNT_REFERENCE_DOMAIN}${deployment}:${reference}`;
342
+ const mac = await crypto.subtle.sign("HMAC", key, new TextEncoder().encode(message));
343
+ return [...new Uint8Array(mac)].map((byte) => byte.toString(16).padStart(2, "0")).join("");
344
+ }
345
+ /** Domain separation, so this MAC and the webhook body signature can never be mistaken for one another. */
346
+ const ACCOUNT_REFERENCE_DOMAIN = "pithy:lemonSqueezy:account-reference:v1:";
347
+ /** Whether a stamped proof matches, compared in constant time by the runtime rather than by `===`. */
348
+ async function accountReferenceProofMatches(reference, deployment, secret, candidate) {
349
+ const expected = await accountReferenceProof(reference, deployment, secret);
350
+ if (candidate.length !== expected.length) return false;
351
+ const key = await crypto.subtle.importKey("raw", new TextEncoder().encode(secret), {
352
+ name: "HMAC",
353
+ hash: "SHA-256"
354
+ }, false, ["verify"]);
355
+ const bytes = hexToBytes(candidate);
356
+ if (bytes === void 0) return false;
357
+ return await crypto.subtle.verify("HMAC", key, bytes, new TextEncoder().encode(`${ACCOUNT_REFERENCE_DOMAIN}${deployment}:${reference}`));
358
+ }
359
+ /** Decode hex, or undefined when it is not hex. */
360
+ function hexToBytes(value) {
361
+ if (value.length === 0 || value.length % 2 !== 0 || !/^[0-9a-fA-F]+$/.test(value)) return void 0;
362
+ const bytes = new Uint8Array(value.length / 2);
363
+ for (let index = 0; index < bytes.length; index += 1) bytes[index] = Number.parseInt(value.slice(index * 2, index * 2 + 2), 16);
364
+ return bytes;
365
+ }
366
+ /**
367
+ * Whether this delivery belongs to another deployment sharing the same store.
368
+ *
369
+ * True only when both sides named an environment and they differ. An unstamped delivery is ours to consider
370
+ * — a storefront order has no `custom_data` — and a deployment that does not know its own environment
371
+ * fences nothing, which is precisely how the other three rails behave.
372
+ */
373
+ function fencedOut(webhook, deployment) {
374
+ const stamped = webhook.meta.custom_data?.[LEMON_SQUEEZY_CUSTOM_ENV];
375
+ if (typeof stamped !== "string" || stamped === "" || deployment === void 0) return false;
376
+ return stamped !== deployment;
377
+ }
378
+ //#endregion
379
+ export { LEMON_SQUEEZY_CUSTOM_ACCOUNT, LEMON_SQUEEZY_CUSTOM_ENV, LEMON_SQUEEZY_CUSTOM_PROOF, LemonSqueezyOrder, LemonSqueezySubscription, LemonSqueezySubscriptionInvoice, LemonSqueezyWebhook, accountReferenceOf, accountReferenceProof, fencedOut, invoiceEvent, invoiceStatus, namespacedId, orderEvent, orderStatus, subscriptionEvent, subscriptionStatus };
@@ -0,0 +1,35 @@
1
+ import type { PaymentsLemonSqueezyCredentials } from "../../secret/registry";
2
+ import type { PortalHandoff, PortalSessionInput } from "../contract";
3
+ import { type LemonSqueezyHttpFetch } from "./api";
4
+ /**
5
+ * The customer portal — where a Lemon Squeezy subscriber changes a card or cancels, under Lemon Squeezy's
6
+ * own rules.
7
+ *
8
+ * ## Why this is a read and not a create
9
+ *
10
+ * Stripe mints a Billing Portal *session* per caller. Lemon Squeezy does not: the portal link is an
11
+ * attribute of the customer object, already signed and already expiring, and reading the customer is how you
12
+ * get it. So this asks for the customer the provider-account map resolved and returns the link it carries.
13
+ *
14
+ * That is why there is no `returnUrl` here. Lemon Squeezy's portal takes no return parameter — the
15
+ * subscriber closes the tab — and {@link PortalSessionInput.returnUrl} is optional precisely so this rail
16
+ * can decline it in the type rather than accept one and silently drop it. A project running this rail alone
17
+ * is never asked to configure a URL that nothing would use.
18
+ *
19
+ * ## The caller never names the customer
20
+ *
21
+ * `providerAccountId` comes from the provider-account map, keyed on the authenticated caller — never from a
22
+ * request body. The `/portal` route takes no body at all, which is the request contract that makes this
23
+ * safe: a `customer` field there would let anyone read anyone's billing portal, and the link is a bearer
24
+ * credential for that account's subscription.
25
+ */
26
+ /** What creating a portal link needs: the credentials, and the transport. */
27
+ export interface LemonSqueezyPortalOptions {
28
+ /** The rail's credentials. Only `apiKey` is used here. */
29
+ credentials: PaymentsLemonSqueezyCredentials;
30
+ /** The HTTP seam. Defaults to the runtime's `fetch`. */
31
+ transport?: LemonSqueezyHttpFetch;
32
+ }
33
+ /** The portal link for one customer. */
34
+ export declare function createLemonSqueezyPortalSession(input: PortalSessionInput, options: LemonSqueezyPortalOptions): Promise<PortalHandoff>;
35
+ //# sourceMappingURL=portal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"portal.d.ts","sourceRoot":"","sources":["../../../src/rails/lemonSqueezy/portal.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,uBAAuB,CAAC;AAC7E,OAAO,KAAK,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,KAAK,qBAAqB,EAA2C,MAAM,OAAO,CAAC;AAE5F;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,6EAA6E;AAC7E,MAAM,WAAW,yBAAyB;IACxC,0DAA0D;IAC1D,WAAW,EAAE,+BAA+B,CAAC;IAC7C,wDAAwD;IACxD,SAAS,CAAC,EAAE,qBAAqB,CAAC;CACnC;AAuBD,wCAAwC;AACxC,wBAAsB,+BAA+B,CACnD,KAAK,EAAE,kBAAkB,EACzB,OAAO,EAAE,yBAAyB,GACjC,OAAO,CAAC,aAAa,CAAC,CAgBxB"}
@@ -0,0 +1,18 @@
1
+ import { PaymentsProviderUnavailableError } from "../../error/errors.js";
2
+ import { lemonSqueezyHttpFetch, lemonSqueezyJson } from "./api.js";
3
+ import { z } from "zod";
4
+ //#region src/rails/lemonSqueezy/portal.ts
5
+ /** A customer, narrowed to the portal link it carries. */
6
+ const LemonSqueezyCustomer = z.object({ data: z.object({ attributes: z.object({ urls: z.object({ customer_portal: z.string().min(1).describe("The signed, expiring portal link. A bearer credential for this account's billing.") }).loose().describe("The customer's links.") }).loose() }).loose() });
7
+ /** The portal link for one customer. */
8
+ async function createLemonSqueezyPortalSession(input, options) {
9
+ const customer = await lemonSqueezyJson(options.transport ?? lemonSqueezyHttpFetch, `/customers/${encodeURIComponent(input.providerAccountId)}`, {
10
+ what: "a customer portal link",
11
+ apiKey: options.credentials.apiKey
12
+ });
13
+ const parsed = LemonSqueezyCustomer.safeParse(customer);
14
+ if (!parsed.success) throw new PaymentsProviderUnavailableError({ detail: `Lemon Squeezy returned customer ${input.providerAccountId} with no customer_portal link.` });
15
+ return { url: parsed.data.data.attributes.urls.customer_portal };
16
+ }
17
+ //#endregion
18
+ export { createLemonSqueezyPortalSession };
@@ -0,0 +1,25 @@
1
+ import type { SubscriptionPricing } from "../../data/discount";
2
+ import type { PaymentsPurchase } from "../../data/purchase";
3
+ import type { PaymentsLemonSqueezyCredentials } from "../../secret/registry";
4
+ import { type LemonSqueezyHttpFetch } from "./api";
5
+ /**
6
+ * What a Lemon Squeezy subscription pays now, what it becomes, and when.
7
+ *
8
+ * Read from the store rather than computed: the subscription object carries the discounted total for the
9
+ * next renewal, the list total, and the discount in force. Pithy multiplies nothing — a second calculation
10
+ * here would be a second answer to the one question a customer checks against their statement.
11
+ *
12
+ * Only a `subscription:` row can be asked. A money row records one closed period and has no "next", and an
13
+ * order has no renewal at all, so both answer `undefined` — the same "nothing to say about this purchase"
14
+ * the refresh path uses.
15
+ */
16
+ /** What reading pricing needs. */
17
+ export interface LemonSqueezyPricingOptions {
18
+ /** The rail's credentials. */
19
+ credentials: PaymentsLemonSqueezyCredentials;
20
+ /** The HTTP seam. Defaults to the runtime's `fetch`. */
21
+ transport?: LemonSqueezyHttpFetch;
22
+ }
23
+ /** Read what this subscription pays, or `undefined` when the store has nothing to say. */
24
+ export declare function readLemonSqueezyPricing(purchase: PaymentsPurchase, options: LemonSqueezyPricingOptions): Promise<SubscriptionPricing | undefined>;
25
+ //# sourceMappingURL=pricing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pricing.d.ts","sourceRoot":"","sources":["../../../src/rails/lemonSqueezy/pricing.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,uBAAuB,CAAC;AAC7E,OAAO,EAAE,KAAK,qBAAqB,EAA2C,MAAM,OAAO,CAAC;AAE5F;;;;;;;;;;GAUG;AAEH,kCAAkC;AAClC,MAAM,WAAW,0BAA0B;IACzC,8BAA8B;IAC9B,WAAW,EAAE,+BAA+B,CAAC;IAC7C,wDAAwD;IACxD,SAAS,CAAC,EAAE,qBAAqB,CAAC;CACnC;AA4CD,0FAA0F;AAC1F,wBAAsB,uBAAuB,CAC3C,QAAQ,EAAE,gBAAgB,EAC1B,OAAO,EAAE,0BAA0B,GAClC,OAAO,CAAC,mBAAmB,GAAG,SAAS,CAAC,CAgD1C"}
@@ -0,0 +1,54 @@
1
+ import { lemonSqueezyHttpFetch, lemonSqueezyJson } from "./api.js";
2
+ import { z } from "zod";
3
+ //#region src/rails/lemonSqueezy/pricing.ts
4
+ /** A subscription, narrowed to what pricing needs. `.loose()` — the store adds fields. */
5
+ const PricedSubscription = z.object({ data: z.object({ attributes: z.object({ first_subscription_item: z.object({ price_id: z.number().optional() }).loose().nullish() }).loose() }).loose() }).loose();
6
+ /**
7
+ * The subscription's invoices — a **collection**, which is what `/v1/subscription-invoices` returns.
8
+ *
9
+ * `data` is an array. Parsing it as a single resource is the defect this replaced: `safeParse` failed
10
+ * silently, every amount fell back to null, and `GET /payments/pricing` reported nothing for every Lemon
11
+ * Squeezy subscriber while looking like it had worked.
12
+ */
13
+ const PricedInvoices = z.object({ data: z.array(z.object({ attributes: z.object({
14
+ currency: z.string().nullish(),
15
+ subtotal: z.number().nullish(),
16
+ total: z.number().nullish(),
17
+ discount_total: z.number().nullish(),
18
+ created_at: z.string().nullish()
19
+ }).loose() }).loose()) }).loose();
20
+ /** Read what this subscription pays, or `undefined` when the store has nothing to say. */
21
+ async function readLemonSqueezyPricing(purchase, options) {
22
+ const key = purchase.providerTransactionId;
23
+ if (!key.startsWith("subscription:")) return void 0;
24
+ const id = key.slice(13);
25
+ const transport = options.transport ?? lemonSqueezyHttpFetch;
26
+ const body = await lemonSqueezyJson(transport, `/subscriptions/${encodeURIComponent(id)}`, {
27
+ what: `subscription ${id} pricing`,
28
+ apiKey: options.credentials.apiKey,
29
+ absentOn404: true
30
+ });
31
+ if (body === void 0) return void 0;
32
+ if (!PricedSubscription.safeParse(body).success) return void 0;
33
+ const invoices = await lemonSqueezyJson(transport, "/subscription-invoices", {
34
+ what: `subscription ${id} invoices`,
35
+ apiKey: options.credentials.apiKey,
36
+ query: {
37
+ "filter[subscription_id]": id,
38
+ "page[size]": "1",
39
+ sort: "-created_at"
40
+ },
41
+ absentOn404: true
42
+ });
43
+ const priced = invoices === void 0 ? void 0 : PricedInvoices.safeParse(invoices);
44
+ const amounts = priced?.success === true ? priced.data.data[0]?.attributes : void 0;
45
+ return {
46
+ currency: amounts?.currency ?? null,
47
+ currentAmountMinor: amounts?.total ?? null,
48
+ listAmountMinor: amounts?.subtotal ?? amounts?.total ?? null,
49
+ discountCode: null,
50
+ discountEndsAt: null
51
+ };
52
+ }
53
+ //#endregion
54
+ export { readLemonSqueezyPricing };
@@ -0,0 +1,41 @@
1
+ import type { PaymentsLemonSqueezyCredentials } from "../../secret/registry";
2
+ import type { CheckoutRail, DiscountRail, PaymentsRailProvider, PricingRail } from "../contract";
3
+ import type { LemonSqueezyHttpFetch } from "./api";
4
+ /**
5
+ * The Lemon Squeezy rail as one provider object — the second to implement both halves of the contract.
6
+ *
7
+ * Like Stripe, this rail *initiates* purchases: `/checkout` creates a hosted checkout and sends the browser
8
+ * to it, so it implements {@link CheckoutRail} as well as {@link PaymentsRailProvider}. Unlike Stripe, it
9
+ * refuses `verify` outright — there is no client-submittable receipt here that could be trusted, and
10
+ * `verify.ts` explains at length why the obvious candidates are not one.
11
+ *
12
+ * Built per request from credentials the caller resolved through the secrets store, rather than reading
13
+ * them itself. That keeps the rail a pure function of its inputs and keeps the secret read at the point of
14
+ * need.
15
+ *
16
+ * **Hosted only, and merchant of record.** Lemon Squeezy owns the payment page, the sales tax, the VAT
17
+ * registration, the invoice, the dunning and the chargebacks. That is the entire reason an adopter reaches
18
+ * for this rail over Stripe, and nothing in this module is a small edit away from taking any of it back.
19
+ */
20
+ /** How the Lemon Squeezy rail's transport is varied. One seam, for the tests and for the reconciliation pass. */
21
+ export interface LemonSqueezyRailOptions {
22
+ /** The HTTP seam Lemon Squeezy's API is reached through. Defaults to the runtime's `fetch`. */
23
+ transport?: LemonSqueezyHttpFetch;
24
+ /**
25
+ * Whether a variant is sold as a subscription, answered from the adopter's catalog.
26
+ *
27
+ * Supplied by `resolveRailProvider`, which has the config. It decides whether an `order_created` is a
28
+ * one-off sale or the container a subscription arrived in — the second of which is not its own payment.
29
+ */
30
+ sellsSubscription?: (variantId: string) => boolean;
31
+ /**
32
+ * The currency this store prices in, when the project declared one.
33
+ *
34
+ * Only used to refuse a fixed discount in another currency before it reaches the store — see
35
+ * `discounts.ts` for why that refusal has to happen at creation rather than at redemption.
36
+ */
37
+ storeCurrency?: string;
38
+ }
39
+ /** The Lemon Squeezy rail. Parses webhooks, re-reads purchases, and creates hosted checkouts and portal links. */
40
+ export declare function lemonSqueezyRail(credentials: PaymentsLemonSqueezyCredentials, options?: LemonSqueezyRailOptions): PaymentsRailProvider & CheckoutRail & DiscountRail & PricingRail;
41
+ //# sourceMappingURL=rail.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rail.d.ts","sourceRoot":"","sources":["../../../src/rails/lemonSqueezy/rail.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,uBAAuB,CAAC;AAC7E,OAAO,KAAK,EAEV,YAAY,EAEZ,YAAY,EAEZ,oBAAoB,EAGpB,WAAW,EAMZ,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,OAAO,CAAC;AASnD;;;;;;;;;;;;;;;GAeG;AAEH,iHAAiH;AACjH,MAAM,WAAW,uBAAuB;IACtC,+FAA+F;IAC/F,SAAS,CAAC,EAAE,qBAAqB,CAAC;IAClC;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC;IACnD;;;;;OAKG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,kHAAkH;AAClH,wBAAgB,gBAAgB,CAC9B,WAAW,EAAE,+BAA+B,EAC5C,OAAO,GAAE,uBAA4B,GACpC,oBAAoB,GAAG,YAAY,GAAG,YAAY,GAAG,WAAW,CAgElE"}
@@ -0,0 +1,67 @@
1
+ import { createLemonSqueezyCheckoutSession } from "./checkout.js";
2
+ import { createLemonSqueezyDiscount, listLemonSqueezyDiscounts } from "./discounts.js";
3
+ import { createLemonSqueezyPortalSession } from "./portal.js";
4
+ import { readLemonSqueezyPricing } from "./pricing.js";
5
+ import { refreshLemonSqueezyPurchase } from "./refresh.js";
6
+ import { verifyLemonSqueezyOrder } from "./verify.js";
7
+ import { parseLemonSqueezyNotification } from "./webhook.js";
8
+ //#region src/rails/lemonSqueezy/rail.ts
9
+ /** The Lemon Squeezy rail. Parses webhooks, re-reads purchases, and creates hosted checkouts and portal links. */
10
+ function lemonSqueezyRail(credentials, options = {}) {
11
+ return {
12
+ rail: "lemonSqueezy",
13
+ async verify(receipt) {
14
+ return await verifyLemonSqueezyOrder(receipt);
15
+ },
16
+ async parseNotification(delivery, context) {
17
+ return await parseLemonSqueezyNotification(delivery, {
18
+ credentials,
19
+ deployment: context.deployment,
20
+ transport: options.transport,
21
+ sellsSubscription: options.sellsSubscription
22
+ });
23
+ },
24
+ async refresh(purchase, context) {
25
+ return await refreshLemonSqueezyPurchase(purchase, {
26
+ credentials,
27
+ now: context.now,
28
+ transport: options.transport
29
+ });
30
+ },
31
+ async createCheckoutSession(input, context) {
32
+ return await createLemonSqueezyCheckoutSession(input, {
33
+ credentials,
34
+ deployment: context.deployment,
35
+ transport: options.transport
36
+ });
37
+ },
38
+ async createPortalSession(input) {
39
+ return await createLemonSqueezyPortalSession(input, {
40
+ credentials,
41
+ transport: options.transport
42
+ });
43
+ },
44
+ async readPricing(purchase, _context) {
45
+ return await readLemonSqueezyPricing(purchase, {
46
+ credentials,
47
+ transport: options.transport
48
+ });
49
+ },
50
+ async listDiscounts() {
51
+ return await listLemonSqueezyDiscounts({
52
+ credentials,
53
+ storeCurrency: options.storeCurrency,
54
+ transport: options.transport
55
+ });
56
+ },
57
+ async createDiscount(terms) {
58
+ return await createLemonSqueezyDiscount(terms, {
59
+ credentials,
60
+ storeCurrency: options.storeCurrency,
61
+ transport: options.transport
62
+ });
63
+ }
64
+ };
65
+ }
66
+ //#endregion
67
+ export { lemonSqueezyRail };