@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,153 @@
1
+ import { PaymentsProviderUnavailableError, PaymentsRailNotConfiguredError } from "../../error/errors.js";
2
+ import { z } from "zod";
3
+ //#region src/rails/stripe/api.ts
4
+ /**
5
+ * The one door out to Stripe, and the mapping from how it answered to what that means.
6
+ *
7
+ * Stripe is reached with `fetch` and form encoding rather than through the `stripe` npm package, deliberately.
8
+ * Three calls are needed for hosted-only payments — create a Checkout Session, create a Billing Portal session,
9
+ * retrieve a Checkout Session — and each is one form POST or GET. The SDK would add a dependency with its own
10
+ * runtime shims, its own retry policy, and its own idea of what an error is, to save perhaps forty lines. Every
11
+ * other third-party API in this repo is spoken to the same way: `fetch` out, Zod in.
12
+ *
13
+ * **The API version is pinned.** Stripe decides response shapes from the *account's* default version unless a
14
+ * request names one, so an account upgraded in the dashboard would silently change what this code parses. Pinning
15
+ * it here means an upgrade is a deliberate edit with a test run behind it. Webhook payload shapes are a separate
16
+ * matter — those follow the endpoint's own configured version, which is why `objects.ts` accepts both spellings of
17
+ * the fields Stripe has moved.
18
+ *
19
+ * ## How an answer is read
20
+ *
21
+ * **A 5xx or a 429 is `payments/provider_unavailable` (503).** Stripe is up but not answering, or is asking us to
22
+ * slow down. The caller retries and the reconciliation pass covers whatever a retry never fixes.
23
+ *
24
+ * **Every other 4xx is `payments/rail_not_configured` (404), and that is the deliberate part.** A 4xx from Stripe
25
+ * is never the buyer's fault — we build these requests entirely from config and from rows we wrote, so "No such
26
+ * price", "No such customer", a rejected key, and a missing Billing Portal configuration are all one statement:
27
+ * this project's Stripe rail is not set up to do what it was asked. 503 would tell a caller to retry something
28
+ * that will never succeed; 400 would blame a request the caller did not make. 404 says the payment method is not
29
+ * available here, which is true, and `detail` carries Stripe's own sentence for the operator who can fix it.
30
+ *
31
+ * **A 404 is an absent resource only for a caller that said it was probing.** `absentOn404` is how a Checkout
32
+ * Session retrieve distinguishes "no such session" from "our Stripe account is wrong", and only a caller that
33
+ * knows the difference may claim it.
34
+ *
35
+ * **Nothing in a refusal carries the secret key.** Stripe redacts keys in its own messages, but `detail` is
36
+ * written to an operator's logs, so anything key-shaped in a message is redacted again here before it gets there.
37
+ */
38
+ /** Stripe's REST base. Public and stable, so it is pinned rather than configured. */
39
+ const STRIPE_API_BASE = "https://api.stripe.com/v1";
40
+ /**
41
+ * The API version every request pins.
42
+ *
43
+ * To move it: read Stripe's changelog for the shape changes between the two, adjust `objects.ts`, run the suite,
44
+ * and change this line. Never bump it to match an account — the point of pinning is that the account cannot
45
+ * decide what this code parses.
46
+ */
47
+ const STRIPE_API_VERSION = "2025-04-30.basil";
48
+ /** The default transport: the runtime's own `fetch`. */
49
+ const stripeHttpFetch = (url, init) => fetch(url, init);
50
+ /**
51
+ * Encode a nested object the way Stripe's API reads a form body: `line_items[0][price]=price_1`.
52
+ *
53
+ * `URLSearchParams` alone cannot produce that, which is the whole reason this exists. `undefined` and `null` are
54
+ * dropped rather than sent empty, because Stripe reads an empty value as "unset this field" — so omitting an
55
+ * optional parameter and sending it blank are two different requests.
56
+ */
57
+ function stripeForm(input) {
58
+ const params = new URLSearchParams();
59
+ append(params, "", input);
60
+ return params.toString();
61
+ }
62
+ /** Stripe's error envelope, as much of it as a `detail` line needs. */
63
+ const StripeApiError = z.object({ error: z.object({
64
+ type: z.string().min(1).optional().describe("Stripe's error class — `invalid_request_error`, `api_error`."),
65
+ code: z.string().min(1).optional().describe("The machine-readable reason — `resource_missing`."),
66
+ param: z.string().min(1).optional().describe("Which request parameter Stripe blamed."),
67
+ message: z.string().min(1).optional().describe("Stripe's own sentence. Redacted before it reaches a log.")
68
+ }).loose().describe("The error Stripe reported.") }).loose().describe("Stripe's error response envelope.");
69
+ /**
70
+ * One request to Stripe, and its parsed JSON body — or `undefined` when a 404 was a legitimate answer.
71
+ *
72
+ * The body comes back as `unknown`. Reaching an endpoint proves who answered, never what they said, so every
73
+ * caller Zod-parses its own shape.
74
+ */
75
+ async function stripeJson(transport, path, options) {
76
+ const query = options.query === void 0 ? "" : `?${stripeForm(options.query)}`;
77
+ const url = `${STRIPE_API_BASE}${path}${query}`;
78
+ const headers = {
79
+ authorization: `Bearer ${options.secretKey}`,
80
+ "stripe-version": STRIPE_API_VERSION
81
+ };
82
+ if (options.form !== void 0) headers["content-type"] = "application/x-www-form-urlencoded";
83
+ let response;
84
+ try {
85
+ response = await transport(url, {
86
+ method: options.form === void 0 ? "GET" : "POST",
87
+ headers,
88
+ body: options.form === void 0 ? void 0 : stripeForm(options.form)
89
+ });
90
+ } catch (cause) {
91
+ throw new PaymentsProviderUnavailableError({ detail: `Stripe did not answer when asked for ${options.what}.` }, { cause });
92
+ }
93
+ const text = await response.text();
94
+ if (!response.ok) {
95
+ if (response.status === 404 && options.absentOn404) return void 0;
96
+ throw refusal(response.status, text, options);
97
+ }
98
+ try {
99
+ return JSON.parse(text);
100
+ } catch (cause) {
101
+ throw new PaymentsProviderUnavailableError({ detail: `Stripe answered with a non-JSON body when asked for ${options.what}.` }, { cause });
102
+ }
103
+ }
104
+ /** The refusal for a non-2xx answer: retryable if Stripe is struggling, a configuration failure otherwise. */
105
+ function refusal(status, body, options) {
106
+ if (status === 429 || status >= 500) return new PaymentsProviderUnavailableError({ detail: `Stripe answered ${status} when asked for ${options.what}. ${stripeSaid(body)}` });
107
+ const key = status === 401 || status === 403 ? " Check the secret key stored for this environment." : "";
108
+ return new PaymentsRailNotConfiguredError({ detail: `Stripe refused the request for ${options.what} with ${status}.${key} ${stripeSaid(body)}` });
109
+ }
110
+ /** Stripe's own account of the failure, redacted. Empty when the body was not a Stripe error envelope. */
111
+ function stripeSaid(body) {
112
+ let parsed;
113
+ try {
114
+ parsed = JSON.parse(body);
115
+ } catch {
116
+ return "";
117
+ }
118
+ const envelope = StripeApiError.safeParse(parsed);
119
+ if (!envelope.success) return "";
120
+ const { type, code, param, message } = envelope.data.error;
121
+ const parts = [
122
+ type,
123
+ code,
124
+ param === void 0 ? void 0 : `param ${param}`,
125
+ message
126
+ ].filter((part) => part !== void 0);
127
+ return parts.length === 0 ? "" : `Stripe said: ${redactStripeSecrets(parts.join(" / "))}.`;
128
+ }
129
+ /**
130
+ * Blank out anything key-shaped in text bound for a log.
131
+ *
132
+ * Stripe already redacts keys in its messages, so this is belt and braces — but `detail` is written to an
133
+ * operator's logs and read by whoever has them, and a credential that reaches one has to be rotated. Cheap
134
+ * insurance against a message format changing.
135
+ */
136
+ function redactStripeSecrets(text) {
137
+ return text.replace(/\b(sk|rk|whsec)_(test_|live_)?[A-Za-z0-9]+/g, (_match, prefix, mode) => `${prefix}_${mode ?? ""}…`);
138
+ }
139
+ /** Append one value under a bracketed key path, recursing into objects and arrays. */
140
+ function append(params, prefix, value) {
141
+ if (value === void 0 || value === null) return;
142
+ if (Array.isArray(value)) {
143
+ for (const [index, entry] of value.entries()) append(params, `${prefix}[${index}]`, entry);
144
+ return;
145
+ }
146
+ if (typeof value === "object") {
147
+ for (const [key, entry] of Object.entries(value)) append(params, prefix === "" ? key : `${prefix}[${key}]`, entry);
148
+ return;
149
+ }
150
+ params.append(prefix, String(value));
151
+ }
152
+ //#endregion
153
+ export { STRIPE_API_BASE, STRIPE_API_VERSION, redactStripeSecrets, stripeForm, stripeHttpFetch, stripeJson };
@@ -0,0 +1,60 @@
1
+ import type { PaymentsStripeCredentials } from "../../secret/registry";
2
+ import type { CheckoutHandoff, CheckoutSessionInput } from "../contract";
3
+ import { type StripeHttpFetch } from "./api";
4
+ /**
5
+ * Hosted Checkout, and nothing else.
6
+ *
7
+ * Stripe presents the payment page, handles the card, and owns SCA, tax, and every regulatory surface that comes
8
+ * with taking money. Pithy sends a browser there and hears the outcome on a webhook. There is no Payment Element
9
+ * here and no card fields, and nothing computes proration or tax — that half of issue #79's locked decision 2
10
+ * still stands, and it is the difference between a backend kit and a payments processor.
11
+ *
12
+ * **The other half was amended on 2026-08-28: the kit may now *invoke* a plan change**, passing the store's own
13
+ * figures through unmodified — see {@link SubscriptionRail} in `rails/contract.ts` for the line between asking a
14
+ * store what a change costs and answering that question ourselves. **Stripe does not implement it.** Paddle is
15
+ * the only rail that does, so a Stripe subscriber changes plan in the Billing Portal exactly as before, and
16
+ * `providers.test.ts` is where that stops being a claim. The amendment permits the seam; it does not oblige
17
+ * every rail to have one.
18
+ *
19
+ * ## What this call puts on the session, and why each of them
20
+ *
21
+ * **`client_reference_id`, the resolved subject as `encodeSubjectReference` writes it.** A Stripe purchase is only
22
+ * ever heard about through a webhook, and that webhook carries `cus_…` and no Pithy holder. This is the pairing,
23
+ * and it is the reason the `/checkout` route resolves the subject through the configured seam and never from a
24
+ * request body: a client that could name it could attach its purchase to somebody else's account — or, worse,
25
+ * attach somebody else's purchase to its own.
26
+ *
27
+ * **Both halves of the subject, always — `user:ada`, never `ada`.** Nothing keeps an organization id from
28
+ * equalling some user's, so an id alone paired with a kind at the far end would eventually grant one holder's
29
+ * subscription to the other. The bare id is also what this rail stamped before subjects existed, and
30
+ * `decodeSubjectReference` refuses it on purpose: a lenient read would attribute a stranger's renewal to whoever
31
+ * holds that id. So a stamp that is not the encoding orphans its purchase, which is the safe direction and the
32
+ * reason nothing here builds the string by hand.
33
+ *
34
+ * **The same reference in `metadata`, and again in `subscription_data[metadata]`.** Stripe copies subscription
35
+ * metadata onto the subscription it creates, so every later `customer.subscription.*` event carries the pairing
36
+ * too. Without that, Stripe delivering `customer.subscription.created` before `checkout.session.completed` — which
37
+ * it may — would leave the first renewal notification with nobody to project it against.
38
+ *
39
+ * **The price id in `metadata`.** A Checkout Session's `line_items` are expandable, and a webhook payload never
40
+ * expands anything, so the price a session was created for is otherwise unknowable from its own notification.
41
+ *
42
+ * **The customer, when the buyer already has one.** One buyer, one Stripe customer. Left out, every checkout mints
43
+ * a fresh customer and a buyer's second purchase would be invisible from the billing portal their first one made.
44
+ * On a first one-time purchase there is no customer to reuse, so Stripe is asked to create one — payment mode
45
+ * makes none by default, and a one-time buyer would otherwise never enter the account map at all.
46
+ */
47
+ /** What creating a session needs beyond the input: the API key, and the transport to reach Stripe through. */
48
+ export interface StripeCheckoutOptions {
49
+ /** Stripe's credential block. Only `secretKey` is used here. */
50
+ credentials: PaymentsStripeCredentials;
51
+ /** The HTTP seam. Defaults to the runtime's `fetch`. */
52
+ transport?: StripeHttpFetch;
53
+ }
54
+ /** Create a hosted Checkout Session for one product, and return where to send the browser. */
55
+ export declare function createStripeCheckoutSession(input: CheckoutSessionInput, options: StripeCheckoutOptions): Promise<CheckoutHandoff>;
56
+ /** Read a created session's URL, or refuse. Shared with the Billing Portal, which answers the same shape. */
57
+ export declare function hostedSession(created: unknown, what: string): CheckoutHandoff & {
58
+ kind: "redirect";
59
+ };
60
+ //# sourceMappingURL=checkout.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkout.d.ts","sourceRoot":"","sources":["../../../src/rails/stripe/checkout.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,KAAK,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,EAAyB,KAAK,eAAe,EAA+B,MAAM,OAAO,CAAC;AAGjG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AAEH,8GAA8G;AAC9G,MAAM,WAAW,qBAAqB;IACpC,gEAAgE;IAChE,WAAW,EAAE,yBAAyB,CAAC;IACvC,wDAAwD;IACxD,SAAS,CAAC,EAAE,eAAe,CAAC;CAC7B;AAcD,8FAA8F;AAC9F,wBAAsB,2BAA2B,CAC/C,KAAK,EAAE,oBAAoB,EAC3B,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,eAAe,CAAC,CA6C1B;AAED,6GAA6G;AAC7G,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,eAAe,GAAG;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,CAUpG"}
@@ -0,0 +1,86 @@
1
+ import { encodeSubjectReference } from "../../data/subject.js";
2
+ import { PaymentsDiscountInvalidError, PaymentsProviderUnavailableError } from "../../error/errors.js";
3
+ import { stripeHttpFetch, stripeJson } from "./api.js";
4
+ import { STRIPE_METADATA_ACCOUNT_REFERENCE, STRIPE_METADATA_PRICE } from "./objects.js";
5
+ import { z } from "zod";
6
+ //#region src/rails/stripe/checkout.ts
7
+ /** A created hosted session, narrowed to the one field a browser needs. */
8
+ const StripeHostedSession = z.object({
9
+ id: z.string().min(1).describe("The session id. Returned to the browser in the success URL's template token."),
10
+ url: z.string().min(1).describe("The hosted page to send the browser to. Absent only for an embedded session, which this is not.")
11
+ }).loose().describe("A hosted Stripe session — Checkout or Billing Portal — as much of it as a redirect needs.");
12
+ /** Create a hosted Checkout Session for one product, and return where to send the browser. */
13
+ async function createStripeCheckoutSession(input, options) {
14
+ const promotionCodeId = input.discountCode === void 0 ? void 0 : await resolvePromotionCode(input.discountCode, options);
15
+ const accountReference = encodeSubjectReference(input.subject);
16
+ const reference = { [STRIPE_METADATA_ACCOUNT_REFERENCE]: accountReference };
17
+ const metadata = {
18
+ ...reference,
19
+ [STRIPE_METADATA_PRICE]: input.providerProductId
20
+ };
21
+ const form = {
22
+ mode: input.subscription ? "subscription" : "payment",
23
+ line_items: [{
24
+ price: input.providerProductId,
25
+ quantity: 1
26
+ }],
27
+ success_url: input.successUrl,
28
+ cancel_url: input.cancelUrl,
29
+ client_reference_id: accountReference,
30
+ metadata,
31
+ customer: input.providerAccountId ?? void 0,
32
+ customer_creation: input.subscription || input.providerAccountId ? void 0 : "always",
33
+ subscription_data: input.subscription ? { metadata: reference } : void 0,
34
+ payment_intent_data: input.subscription ? void 0 : { metadata },
35
+ discounts: promotionCodeId === void 0 ? void 0 : [{ promotion_code: promotionCodeId }]
36
+ };
37
+ return hostedSession(await stripeJson(options.transport ?? stripeHttpFetch, "/checkout/sessions", {
38
+ what: "a Checkout Session",
39
+ secretKey: options.credentials.secretKey,
40
+ form
41
+ }), "a Checkout Session");
42
+ }
43
+ /** Read a created session's URL, or refuse. Shared with the Billing Portal, which answers the same shape. */
44
+ function hostedSession(created, what) {
45
+ const parsed = StripeHostedSession.safeParse(created);
46
+ if (!parsed.success) throw new PaymentsProviderUnavailableError({ detail: `Stripe created ${what} with no URL to redirect to.` });
47
+ return {
48
+ kind: "redirect",
49
+ url: parsed.data.url
50
+ };
51
+ }
52
+ /**
53
+ * Turn the code a customer typed into the promotion code id Stripe's session wants.
54
+ *
55
+ * Stripe's `discounts[].promotion_code` takes a `promo_…` id, not the customer-facing string, so this lookup
56
+ * is unavoidable. It is also where the code's validity is learned, and learning it *here* is what makes the
57
+ * refusal a good one: an unknown, expired or exhausted code is refused before a session exists, as
58
+ * `payments/discount_invalid` naming the code, rather than becoming a checkout that fails in front of the
59
+ * customer with nothing to say but that something went wrong.
60
+ *
61
+ * `active: true` is part of the query rather than a check afterwards, so an expired or exhausted code simply
62
+ * does not come back. Stripe decides what active means — Pithy does not read `expires_at` or count
63
+ * redemptions itself, for the same reason it does not compute the discounted price.
64
+ */
65
+ async function resolvePromotionCode(code, options) {
66
+ const found = await stripeJson(options.transport ?? stripeHttpFetch, "/promotion_codes", {
67
+ what: `the discount code ${code}`,
68
+ secretKey: options.credentials.secretKey,
69
+ query: {
70
+ code,
71
+ active: true,
72
+ limit: 1
73
+ }
74
+ });
75
+ const parsed = StripePromotionCodes.safeParse(found);
76
+ const promotion = parsed.success ? parsed.data.data[0] : void 0;
77
+ if (promotion === void 0) throw new PaymentsDiscountInvalidError({
78
+ message: `"${code}" is not a discount code we can accept.`,
79
+ detail: `Stripe has no active promotion code matching "${code}" — unknown, expired, or fully redeemed.`
80
+ });
81
+ return promotion.id;
82
+ }
83
+ /** Stripe's promotion-code list, narrowed to the id a session needs. */
84
+ const StripePromotionCodes = z.object({ data: z.array(z.object({ id: z.string().min(1) }).loose()) }).loose().describe("A Stripe promotion-code list response.");
85
+ //#endregion
86
+ export { createStripeCheckoutSession, hostedSession };
@@ -0,0 +1,50 @@
1
+ import type { CreatedDiscount, DiscountTerms } from "../../data/discount";
2
+ import type { PaymentsStripeCredentials } from "../../secret/registry";
3
+ import type { ListedDiscount } from "../contract";
4
+ import { type StripeHttpFetch } from "./api";
5
+ /**
6
+ * Minting a discount at Stripe, from the normalized terms.
7
+ *
8
+ * Stripe models a discount as **two objects**: a Coupon, which carries the money and the duration, and a
9
+ * Promotion Code, which is the string a customer types and carries the redemption limit and the redeem-by
10
+ * date. Both are created here, in that order, because the second references the first.
11
+ *
12
+ * ## The two translations that decide whether a customer is charged correctly
13
+ *
14
+ * **Duration.** `DiscountDuration` counts **billing periods**, because that is what a customer experiences.
15
+ * Stripe's `duration_in_months` counts **months**. On a monthly plan they coincide, which is exactly why the
16
+ * mistranslation survives review: on an annual plan `12` means one year to the customer and twelve years to
17
+ * Stripe. So the conversion multiplies by the plan's interval, and `billingInterval` is required on the
18
+ * terms rather than assumed — `discounts.test.ts` pins an annual plan in both directions.
19
+ *
20
+ * **Expiry.** `redeemableUntil` means the code can no longer be *claimed*, and anyone already holding it
21
+ * keeps their rate. Stripe's `redeem_by` on a Promotion Code is exactly that, and deliberately not the
22
+ * Coupon's own `redeem_by`, which would be the same word applied one level up. A test asserts an existing
23
+ * redemption survives the date.
24
+ *
25
+ * ## What Stripe decides and Pithy does not
26
+ *
27
+ * Whether a code is still usable, what a discounted invoice comes to, and whether a fixed amount can apply
28
+ * to a given subscription. Pithy refuses a currency mismatch it can see before creation, because that
29
+ * failure would otherwise arrive at the customer at redemption rather than at the adopter at creation — but
30
+ * it computes no prices and re-checks no redemptions.
31
+ */
32
+ /** What creating a discount needs: the key, and the transport to reach Stripe through. */
33
+ export interface StripeDiscountOptions {
34
+ /** Stripe's credential block. Only `secretKey` is used here. */
35
+ credentials: PaymentsStripeCredentials;
36
+ /** The HTTP seam. Defaults to the runtime's `fetch`. */
37
+ transport?: StripeHttpFetch;
38
+ }
39
+ /**
40
+ * How many months Stripe should be told, for a duration this package counts in billing periods.
41
+ *
42
+ * The whole of the annual-plan defect lives in this function, which is why it is one named thing with a test
43
+ * against it rather than an expression inline.
44
+ */
45
+ export declare function durationInMonths(billingPeriods: number, interval: "month" | "year"): number;
46
+ /** Create a Coupon and a Promotion Code for it, and return the code a customer will type. */
47
+ export declare function createStripeDiscount(terms: DiscountTerms, options: StripeDiscountOptions): Promise<CreatedDiscount>;
48
+ /** The promotion codes this account holds, newest first. */
49
+ export declare function listStripeDiscounts(options: StripeDiscountOptions): Promise<readonly ListedDiscount[]>;
50
+ //# sourceMappingURL=discounts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"discounts.d.ts","sourceRoot":"","sources":["../../../src/rails/stripe/discounts.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAE1E,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAyB,KAAK,eAAe,EAA+B,MAAM,OAAO,CAAC;AAEjG;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,0FAA0F;AAC1F,MAAM,WAAW,qBAAqB;IACpC,gEAAgE;IAChE,WAAW,EAAE,yBAAyB,CAAC;IACvC,wDAAwD;IACxD,SAAS,CAAC,EAAE,eAAe,CAAC;CAC7B;AAQD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,cAAc,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,CAE3F;AAED,6FAA6F;AAC7F,wBAAsB,oBAAoB,CACxC,KAAK,EAAE,aAAa,EACpB,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,eAAe,CAAC,CAwD1B;AAyBD,4DAA4D;AAC5D,wBAAsB,mBAAmB,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,SAAS,cAAc,EAAE,CAAC,CAiB5G"}
@@ -0,0 +1,87 @@
1
+ import { PaymentsDiscountInvalidError, PaymentsProviderUnavailableError } from "../../error/errors.js";
2
+ import { stripeHttpFetch, stripeJson } from "./api.js";
3
+ import { z } from "zod";
4
+ //#region src/rails/stripe/discounts.ts
5
+ /** A created Coupon, narrowed to its id. */
6
+ const StripeCoupon = z.object({ id: z.string().min(1) }).loose();
7
+ /** A created Promotion Code, narrowed to what an adopter needs back. */
8
+ const StripePromotionCode = z.object({
9
+ id: z.string().min(1),
10
+ code: z.string().min(1)
11
+ }).loose();
12
+ /**
13
+ * How many months Stripe should be told, for a duration this package counts in billing periods.
14
+ *
15
+ * The whole of the annual-plan defect lives in this function, which is why it is one named thing with a test
16
+ * against it rather than an expression inline.
17
+ */
18
+ function durationInMonths(billingPeriods, interval) {
19
+ return interval === "year" ? billingPeriods * 12 : billingPeriods;
20
+ }
21
+ /** Create a Coupon and a Promotion Code for it, and return the code a customer will type. */
22
+ async function createStripeDiscount(terms, options) {
23
+ const transport = options.transport ?? stripeHttpFetch;
24
+ const coupon = terms.amount.kind === "percent" ? { percent_off: terms.amount.percent } : {
25
+ amount_off: terms.amount.amountMinor,
26
+ currency: terms.amount.currency
27
+ };
28
+ coupon.duration = terms.duration.kind;
29
+ if (terms.duration.kind === "repeating") {
30
+ if (terms.billingInterval === void 0) throw new PaymentsDiscountInvalidError({ detail: "A repeating discount reached the Stripe rail with no `billingInterval`. Stripe counts a duration in months, so billing periods cannot be converted without it. Build terms through `DiscountTerms.parse`." });
31
+ coupon.duration_in_months = durationInMonths(terms.duration.billingPeriods, terms.billingInterval);
32
+ }
33
+ const created = await stripeJson(transport, "/coupons", {
34
+ what: "a discount",
35
+ secretKey: options.credentials.secretKey,
36
+ form: coupon
37
+ });
38
+ const parsedCoupon = StripeCoupon.safeParse(created);
39
+ if (!parsedCoupon.success) throw new PaymentsProviderUnavailableError({ detail: "Stripe created a coupon and returned no id." });
40
+ const promotion = { coupon: parsedCoupon.data.id };
41
+ if (terms.code !== void 0) promotion.code = terms.code;
42
+ if (terms.maxRedemptions !== void 0) promotion.max_redemptions = terms.maxRedemptions;
43
+ if (terms.redeemableUntil !== void 0) promotion.redeem_by = Math.floor(terms.redeemableUntil.getTime() / 1e3);
44
+ const madeCode = await stripeJson(transport, "/promotion_codes", {
45
+ what: "a discount code",
46
+ secretKey: options.credentials.secretKey,
47
+ form: promotion
48
+ });
49
+ const parsedCode = StripePromotionCode.safeParse(madeCode);
50
+ if (!parsedCode.success) throw new PaymentsDiscountInvalidError({ detail: `Stripe created coupon ${parsedCoupon.data.id} but would not attach a promotion code to it.` });
51
+ return {
52
+ code: parsedCode.data.code,
53
+ providerDiscountId: parsedCode.data.id,
54
+ terms
55
+ };
56
+ }
57
+ /** Stripe's promotion-code list, narrowed to what a management pane shows. */
58
+ const StripePromotionList = z.object({ data: z.array(z.object({
59
+ id: z.string().min(1),
60
+ code: z.string().min(1),
61
+ times_redeemed: z.number().nullish(),
62
+ coupon: z.object({
63
+ percent_off: z.number().nullish(),
64
+ amount_off: z.number().nullish(),
65
+ currency: z.string().nullish()
66
+ }).loose().nullish()
67
+ }).loose()) }).loose();
68
+ /** The promotion codes this account holds, newest first. */
69
+ async function listStripeDiscounts(options) {
70
+ const found = await stripeJson(options.transport ?? stripeHttpFetch, "/promotion_codes", {
71
+ what: "the discount codes",
72
+ secretKey: options.credentials.secretKey,
73
+ query: { limit: DISCOUNT_PAGE }
74
+ });
75
+ const parsed = StripePromotionList.safeParse(found);
76
+ if (!parsed.success) return [];
77
+ return parsed.data.data.map((promotion) => ({
78
+ code: promotion.code,
79
+ providerDiscountId: promotion.id,
80
+ amount: promotion.coupon?.percent_off != null ? `${promotion.coupon.percent_off}%` : `${promotion.coupon?.amount_off ?? 0} ${promotion.coupon?.currency ?? ""}`.trim(),
81
+ redemptions: promotion.times_redeemed ?? null
82
+ }));
83
+ }
84
+ /** One page of codes. A discount list is small by nature; this bounds it without inventing pagination. */
85
+ const DISCOUNT_PAGE = 100;
86
+ //#endregion
87
+ export { createStripeDiscount, durationInMonths, listStripeDiscounts };
@@ -0,0 +1,64 @@
1
+ import type { StripeHttpFetch, StripeHttpRequest } from "../api";
2
+ /**
3
+ * Test material for Stripe's rail: a known signing secret, a real HMAC over real bytes, and a transport that
4
+ * answers the way Stripe's API does.
5
+ *
6
+ * Stripe's authenticity proof is symmetric — the same secret signs and verifies — so a test can produce a
7
+ * genuinely valid `Stripe-Signature` header rather than stubbing the verifier. That is the whole point: the
8
+ * negative cases below are real failures of real cryptography. A tampered body produces a signature that does
9
+ * not match because the bytes changed, not because a mock was told to say no.
10
+ *
11
+ * The recorded event payloads live beside this module as JSON, unsigned, because a signature is over the exact
12
+ * bytes a test sends — so it must be computed at send time and cannot be recorded.
13
+ *
14
+ * This module signs; the shipped code only verifies. That is why it lives under `fixtures/`.
15
+ */
16
+ /**
17
+ * The signing secret every Stripe suite uses. Shaped like Stripe's own (`whsec_` + base64-ish) so a test that
18
+ * accidentally logged it would be recognizable, and obviously fake so nobody mistakes it for a real one.
19
+ */
20
+ export declare const STRIPE_TEST_WEBHOOK_SECRET = "whsec_pithyTestSigningSecretNotARealOne00";
21
+ /** The secret key the API fixtures pretend to call Stripe with. Test-mode shaped, and not a real key. */
22
+ export declare const STRIPE_TEST_SECRET_KEY = "sk_test_pithyTestKeyNotARealOne00";
23
+ /** What a test varies about the signature header. */
24
+ export interface StripeSignatureOptions {
25
+ /** The signing secret. The suite's own unless a case is proving a wrong one is refused. */
26
+ secret?: string;
27
+ /** The timestamp the header claims and the signature covers. Defaults to the clock the case passes in. */
28
+ timestamp?: Date;
29
+ /** The scheme label. `v1` unless a case is proving an unknown scheme is not accepted. */
30
+ scheme?: string;
31
+ /** Extra signature values to list before the real one — how Stripe presents a secret mid-rotation. */
32
+ extra?: readonly string[];
33
+ }
34
+ /**
35
+ * Sign a body the way Stripe signs a webhook delivery: HMAC-SHA256 over `<timestamp>.<body>`, keyed with the
36
+ * endpoint's signing secret, presented as `t=<timestamp>,v1=<hex>`.
37
+ *
38
+ * The timestamp is inside the signed payload as well as beside it, which is what makes the replay window real:
39
+ * a delivery cannot be re-dated without invalidating its own signature.
40
+ */
41
+ export declare function stripeSignatureHeader(body: string, now: Date, options?: StripeSignatureOptions): Promise<string>;
42
+ /** One recorded outbound call, so a suite can assert what left the Worker and not only what came back. */
43
+ export interface StripeRecordedCall {
44
+ /** The full URL, query string included. */
45
+ url: string;
46
+ /** The request as the transport received it. */
47
+ init?: StripeHttpRequest;
48
+ }
49
+ /** What the stub answers with. A status alone is a failure; a body alone is a 200. */
50
+ export interface StripeStubAnswer {
51
+ /** The status to answer with. 200 unless a case is proving a failure path. */
52
+ status?: number;
53
+ /** The JSON body. Absent answers `{}`. */
54
+ body?: unknown;
55
+ }
56
+ /**
57
+ * A transport that answers Stripe's endpoints from a table keyed on a path fragment, recording every call.
58
+ *
59
+ * A fragment rather than a full URL because a retrieve carries an id and a query string, and a test that had to
60
+ * spell those out would be asserting its own string building. An unmatched call is a 404, which is the honest
61
+ * answer for an endpoint the case did not stub.
62
+ */
63
+ export declare function stripeStubTransport(answers: Record<string, StripeStubAnswer>, calls?: StripeRecordedCall[]): StripeHttpFetch;
64
+ //# sourceMappingURL=events.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../../../src/rails/stripe/fixtures/events.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAEjE;;;;;;;;;;;;;GAaG;AAEH;;;GAGG;AACH,eAAO,MAAM,0BAA0B,8CAA8C,CAAC;AAEtF,yGAAyG;AACzG,eAAO,MAAM,sBAAsB,sCAAsC,CAAC;AAE1E,qDAAqD;AACrD,MAAM,WAAW,sBAAsB;IACrC,2FAA2F;IAC3F,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,0GAA0G;IAC1G,SAAS,CAAC,EAAE,IAAI,CAAC;IACjB,yFAAyF;IACzF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,sGAAsG;IACtG,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC3B;AAOD;;;;;;GAMG;AACH,wBAAsB,qBAAqB,CACzC,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,IAAI,EACT,OAAO,GAAE,sBAA2B,GACnC,OAAO,CAAC,MAAM,CAAC,CAcjB;AAED,0GAA0G;AAC1G,MAAM,WAAW,kBAAkB;IACjC,2CAA2C;IAC3C,GAAG,EAAE,MAAM,CAAC;IACZ,gDAAgD;IAChD,IAAI,CAAC,EAAE,iBAAiB,CAAC;CAC1B;AAED,sFAAsF;AACtF,MAAM,WAAW,gBAAgB;IAC/B,8EAA8E;IAC9E,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,0CAA0C;IAC1C,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,EACzC,KAAK,GAAE,kBAAkB,EAAO,GAC/B,eAAe,CAWjB"}
@@ -0,0 +1,67 @@
1
+ //#region src/rails/stripe/fixtures/events.ts
2
+ /**
3
+ * Test material for Stripe's rail: a known signing secret, a real HMAC over real bytes, and a transport that
4
+ * answers the way Stripe's API does.
5
+ *
6
+ * Stripe's authenticity proof is symmetric — the same secret signs and verifies — so a test can produce a
7
+ * genuinely valid `Stripe-Signature` header rather than stubbing the verifier. That is the whole point: the
8
+ * negative cases below are real failures of real cryptography. A tampered body produces a signature that does
9
+ * not match because the bytes changed, not because a mock was told to say no.
10
+ *
11
+ * The recorded event payloads live beside this module as JSON, unsigned, because a signature is over the exact
12
+ * bytes a test sends — so it must be computed at send time and cannot be recorded.
13
+ *
14
+ * This module signs; the shipped code only verifies. That is why it lives under `fixtures/`.
15
+ */
16
+ /**
17
+ * The signing secret every Stripe suite uses. Shaped like Stripe's own (`whsec_` + base64-ish) so a test that
18
+ * accidentally logged it would be recognizable, and obviously fake so nobody mistakes it for a real one.
19
+ */
20
+ const STRIPE_TEST_WEBHOOK_SECRET = "whsec_pithyTestSigningSecretNotARealOne00";
21
+ /** The secret key the API fixtures pretend to call Stripe with. Test-mode shaped, and not a real key. */
22
+ const STRIPE_TEST_SECRET_KEY = "sk_test_pithyTestKeyNotARealOne00";
23
+ /** Hex, lower case — the encoding Stripe puts a `v1` signature in. */
24
+ function hex(bytes) {
25
+ return [...bytes].map((byte) => byte.toString(16).padStart(2, "0")).join("");
26
+ }
27
+ /**
28
+ * Sign a body the way Stripe signs a webhook delivery: HMAC-SHA256 over `<timestamp>.<body>`, keyed with the
29
+ * endpoint's signing secret, presented as `t=<timestamp>,v1=<hex>`.
30
+ *
31
+ * The timestamp is inside the signed payload as well as beside it, which is what makes the replay window real:
32
+ * a delivery cannot be re-dated without invalidating its own signature.
33
+ */
34
+ async function stripeSignatureHeader(body, now, options = {}) {
35
+ const timestamp = Math.floor((options.timestamp ?? now).getTime() / 1e3);
36
+ const key = await crypto.subtle.importKey("raw", new TextEncoder().encode(options.secret ?? "whsec_pithyTestSigningSecretNotARealOne00"), {
37
+ name: "HMAC",
38
+ hash: "SHA-256"
39
+ }, false, ["sign"]);
40
+ const signature = new Uint8Array(await crypto.subtle.sign("HMAC", key, new TextEncoder().encode(`${timestamp}.${body}`)));
41
+ const values = [...options.extra ?? [], hex(signature)];
42
+ return [`t=${timestamp}`, ...values.map((value) => `${options.scheme ?? "v1"}=${value}`)].join(",");
43
+ }
44
+ /**
45
+ * A transport that answers Stripe's endpoints from a table keyed on a path fragment, recording every call.
46
+ *
47
+ * A fragment rather than a full URL because a retrieve carries an id and a query string, and a test that had to
48
+ * spell those out would be asserting its own string building. An unmatched call is a 404, which is the honest
49
+ * answer for an endpoint the case did not stub.
50
+ */
51
+ function stripeStubTransport(answers, calls = []) {
52
+ return async (url, init) => {
53
+ calls.push({
54
+ url,
55
+ init
56
+ });
57
+ const matched = Object.entries(answers).find(([fragment]) => url.includes(fragment))?.[1];
58
+ const status = matched?.status ?? (matched === void 0 ? 404 : 200);
59
+ return {
60
+ ok: status >= 200 && status < 300,
61
+ status,
62
+ text: async () => JSON.stringify(matched?.body ?? {})
63
+ };
64
+ };
65
+ }
66
+ //#endregion
67
+ export { STRIPE_TEST_SECRET_KEY, STRIPE_TEST_WEBHOOK_SECRET, stripeSignatureHeader, stripeStubTransport };