@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,228 @@
1
+ import { PaymentsConfig } from "./config/config.js";
2
+ import { paymentsTables } from "./data/tables.js";
3
+ import { installEntitlementResolver } from "./entitlement/resolver.js";
4
+ import { paymentsManifestConfig } from "./http/manifestConfig.js";
5
+ import { paymentsSecretsRegistry } from "./secret/registry.js";
6
+ import { paymentsWorkflows } from "./workflows/specs.js";
7
+ import { paymentsAdminRoutes } from "./http/scopes.js";
8
+ import { registerPaymentsRoutes } from "./http/routes.js";
9
+ import { payments_0001_purchases } from "./migrations/0001_purchases.js";
10
+ import { paymentsExampleSeed } from "./seeds/example.js";
11
+ import { PACKAGE_VERSION } from "./version.generated.js";
12
+ import { defineCapability } from "@pithy-sh/core/src/capability/capability";
13
+ import { ValidationError } from "@pithy-sh/core/src/error/pithyError";
14
+ import { workflowBindings } from "@pithy-sh/core/src/workflow/bindings";
15
+ //#region src/capability.ts
16
+ /**
17
+ * Where payments' migrations sort in the app database. Unique per database; the registry composes keys
18
+ * like `1000_payments_0001_purchases`. Sits after vector (900), and was `NEXT_FREE_ORDER` when it was
19
+ * taken — see `packages/cli/src/migrations/orders.test.ts`, which is the only place an order is allocated.
20
+ */
21
+ const PAYMENTS_MIGRATION_ORDER = 1e3;
22
+ /** The database name every capability sharing the app D1 coordinates on. `DB` is the binding. */
23
+ const PAYMENTS_DATABASE_NAME = "app";
24
+ /** Whether a composed capability is the ledger, carrying its parsed currency set. */
25
+ function isLedgerPeer(capability) {
26
+ return capability.name === "ledger" && "ledgerConfig" in capability;
27
+ }
28
+ /**
29
+ * Validate every `grants.currency` against the composed ledger, at assembly.
30
+ *
31
+ * `openLedger` validates nothing — it is a primitive, and `credit()` on an unconfigured currency happily
32
+ * opens a real account row. Nobody can reach that row: the ledger's own routes resolve a currency from config
33
+ * and 404 an unknown code, so the balance exists, is correct, and is invisible. The player is told their
34
+ * purchase worked. A typo in a currency code is therefore a defect that produces no error anywhere at
35
+ * runtime, which makes the deploy the only place left to catch it.
36
+ *
37
+ * Every mismatch is reported in one message rather than the first, because an operator fixing one typo per
38
+ * deploy is a bad afternoon.
39
+ */
40
+ function checkLedgerGrants({ capabilities }, config) {
41
+ const granting = Object.entries(config.products).flatMap(([id, product]) => product.grants?.ledger === void 0 ? [] : [{
42
+ id,
43
+ currency: product.grants.ledger.currency
44
+ }]);
45
+ if (granting.length === 0) return;
46
+ if (config.billingSubject !== "user") throw new ValidationError({
47
+ message: "This catalog credits a balance, and this project bills organizations.",
48
+ action: "Set `billingSubject: \"user\"`, or drop the `grants` clause from the products that credit a balance.",
49
+ detail: `@pithy-sh/ledger keys every account on a user id and every route it serves reads one, so there is no account an organization's credit could land in that anything would read. Products with a \`grants.ledger\` clause: ${granting.map((entry) => entry.id).join(", ")}.`
50
+ });
51
+ const peer = capabilities.find(isLedgerPeer);
52
+ if (!peer) throw new ValidationError({
53
+ message: "This catalog credits a balance, and no ledger is composed.",
54
+ action: "Add `ledger(...)` to this Worker's capabilities, or drop the `grants` clause from the product.",
55
+ detail: `Products with a \`grants.ledger\` clause: ${granting.map((entry) => entry.id).join(", ")}. Crediting needs @pithy-sh/ledger composed in the same Worker.`
56
+ });
57
+ const declared = new Set(peer.ledgerConfig.currencies.map((currency) => currency.code));
58
+ const unknown = granting.filter((entry) => !declared.has(entry.currency));
59
+ if (unknown.length === 0) return;
60
+ throw new ValidationError({
61
+ message: "A product grants a currency the ledger does not have.",
62
+ action: "Add the currency to the ledger's `currencies`, or correct the product's `grants.ledger.currency`.",
63
+ detail: `${unknown.map((entry) => `product "${entry.id}" grants "${entry.currency}"`).join("; ")}. The ledger declares: ${[...declared].sort().join(", ") || "nothing"}.`
64
+ });
65
+ }
66
+ /**
67
+ * Refuse the one composition that can never entitle anybody: organization billing with no resolver.
68
+ *
69
+ * **A throw at assembly, not a `pithy doctor` finding**, and the difference from the entitlement-gap check
70
+ * is where the evidence lives. That check must read the adopter's *route code* to know whether anything
71
+ * gates at all, which is a question no capability can ask about itself — so it belongs to a tool that reads
72
+ * the project. This one needs nothing but the two arguments already in hand: `billingSubject` from the
73
+ * config being parsed on the line above, and `resolveSubject` from the same call. Where a capability can
74
+ * see the whole fault by itself, it says so at the deploy, which is what `checkLedgerGrants` does two
75
+ * functions down and for the same reason.
76
+ *
77
+ * And the fault is total. Under `"organization"` there is no default resolver — deliberately, because a
78
+ * capability that guessed would key a company's plan to whoever logged in first — so with none supplied
79
+ * `resolvePaymentsSubject` answers nobody for every request. Every entitlement gate denies, every write
80
+ * raises `payments/subject_unresolved`, and both look exactly like a customer who has not paid. There is no
81
+ * request that ever works, so there is nothing to lose by refusing to boot, and a Worker that boots into
82
+ * that state is one whose first symptom is a support ticket from a paying company.
83
+ */
84
+ function requireResolvableSubject(config, resolveSubject) {
85
+ if (config.billingSubject !== "organization" || resolveSubject !== void 0) return;
86
+ throw new ValidationError({
87
+ message: "This project bills organizations, and nothing can say which one a caller is acting for.",
88
+ action: "Pass `resolveSubject` to `payments(...)` in this Worker's pithy.config.ts, or set `billingSubject: \"user\"`.",
89
+ detail: "billingSubject is \"organization\" and no subject resolver was supplied. Payments has no members table and never guesses a holder, so every entitlement gate would deny and every write would raise payments/subject_unresolved, for every caller, forever."
90
+ });
91
+ }
92
+ /**
93
+ * What a browser may know about this project's payments — the `virtual:pithy/payments` module.
94
+ *
95
+ * The list is short and each entry earns its place. **Enabled rails**, so a paywall can show an Apple-only
96
+ * product as owned-elsewhere rather than offering a buy button nothing on the web can honor. **The base
97
+ * path**, because the client calls these routes. And **per product** its id, type, entitlement keys,
98
+ * display name, and its SKU on each web rail — a price id is publishable by design, since it is the thing
99
+ * a checkout names and the store's own page shows back to the buyer. Plus, for Paddle, the three facts
100
+ * Paddle.js needs to initialize: the publishable client token, the account, and the display mode.
101
+ *
102
+ * **Nothing else can cross, and not merely by discipline.** Apple's issuer id and key, Google's
103
+ * service-account credentials, and Stripe's secret and webhook signing keys live in the secrets store
104
+ * behind `paymentsSecretsRegistry` — they are not in the config this closure can see, so there is no
105
+ * expression here that would reach them. What discipline does cover is the rest of the catalog: a
106
+ * product's Apple and Google SKUs stay server-side because a browser has no use for them, and the
107
+ * `grants` block stays server-side because a currency code and an amount describe the economy.
108
+ * `capability.test.ts` locks the key set and sweeps the serialized result for every credential shape.
109
+ *
110
+ * `?? null`, never `undefined`: the projection is inlined into a bundle with `JSON.stringify`, which
111
+ * drops an undefined value and leaves the screen reading a key that is simply absent.
112
+ *
113
+ * An empty catalog projects `{ enabled: false }`. A screen branches on `enabled` rather than guarding, so
114
+ * "composed with nothing to sell" must read the same as "not composed" — both are a paywall with nothing
115
+ * on it.
116
+ *
117
+ * The return type is {@link PaymentsClientProjection}, and the catalog's element type is
118
+ * {@link PaymentsClientProduct} — **declared, not inferred**. `ClientProjection` is `{ enabled: boolean }`
119
+ * plus a JSON catchall, which accepts anything this function could return. The declared types are what
120
+ * make a dropped field a compile error here rather than a browser's problem, and what make a fourth
121
+ * product kind or a fourth Paddle checkout mode in `PaymentsConfig` a red line here rather than a silent
122
+ * widening of what every adopter's bundle carries. The element type is annotated
123
+ * separately because the `.map` is where inference is weakest: it would take the shape of whatever the
124
+ * first product happened to be.
125
+ */
126
+ function clientProjection(config, environment) {
127
+ const products = Object.entries(config.products).map(([id, product]) => ({
128
+ id,
129
+ type: product.type,
130
+ entitlements: [...product.entitlements],
131
+ name: product.name,
132
+ skus: {
133
+ stripe: product.stripe?.priceId ?? null,
134
+ lemonSqueezy: product.lemonSqueezy?.variantId ?? null,
135
+ paddle: product.paddle?.priceId ?? null
136
+ }
137
+ }));
138
+ if (products.length === 0) return { enabled: false };
139
+ return {
140
+ enabled: true,
141
+ environment,
142
+ rails: {
143
+ apple: config.rails.apple,
144
+ google: config.rails.google,
145
+ stripe: config.rails.stripe,
146
+ lemonSqueezy: config.rails.lemonSqueezy,
147
+ paddle: config.rails.paddle
148
+ },
149
+ basePath: config.basePath,
150
+ paddle: config.paddle === void 0 ? null : {
151
+ clientToken: config.paddle.clientToken,
152
+ environment: config.paddle.environment,
153
+ checkout: config.paddle.checkout
154
+ },
155
+ products
156
+ };
157
+ }
158
+ /**
159
+ * Three rails — Apple, Google, Stripe — projecting onto one cross-rail entitlement, in the adopter's own
160
+ * D1. The catalog is config, not rows: a product's entitlement mapping is policy, so it is diffable in
161
+ * git and not mutable at runtime.
162
+ *
163
+ * `providesEntitlements` is what makes payments the seam's provider, and it is read in two places. At
164
+ * runtime the middleware below replaces core's fail-closed `noEntitlementProvider` with the D1-backed
165
+ * resolver. At development time `pithy doctor` and `pithy dev` read the flag to answer a question no
166
+ * amount of runtime care can: a Worker whose routes call `requireEntitlement()` while composing no
167
+ * provider is not broken, it is silently paywalled shut, and the seam's own fail-closed default makes
168
+ * that indistinguishable from a user who has not bought anything.
169
+ *
170
+ * `dependsOn: ["secrets"]` is real. Every rail's credentials are read through the aggregated secret
171
+ * registry, so a project composing payments without `@pithy-sh/secrets` must fail at assembly rather
172
+ * than at the first receipt. Auth is *not* listed — it is a seam: under `billingSubject: "user"` a purchase
173
+ * scopes to the authenticated caller, so with no auth capability composed every route denies, which is the
174
+ * right failure and needs no dependency edge. `@pithy-sh/ledger` is likewise a seam, reached through one
175
+ * guarded dynamic import and only for products whose catalog entry declares `grants`. Both belong in the
176
+ * manifest's `optionalCapabilities`.
177
+ *
178
+ * Under `billingSubject: "organization"` the holder is not the caller and cannot be derived from them, so
179
+ * the adopter supplies `resolveSubject` and a composition without one is refused outright — see
180
+ * {@link requireResolvableSubject}.
181
+ */
182
+ function payments(options) {
183
+ const { resolveSubject, ...catalog } = options;
184
+ const resolved = PaymentsConfig.parse(catalog);
185
+ requireResolvableSubject(resolved, resolveSubject);
186
+ const subject = {
187
+ billingSubject: resolved.billingSubject,
188
+ ...resolveSubject ? { resolveSubject } : {}
189
+ };
190
+ const migrations = { "0001_purchases": payments_0001_purchases };
191
+ const requiredBindings = [{
192
+ type: "d1",
193
+ name: "DB"
194
+ }, ...workflowBindings(paymentsWorkflows)];
195
+ const capability = defineCapability({
196
+ name: "payments",
197
+ version: PACKAGE_VERSION,
198
+ dependsOn: ["secrets"],
199
+ providesEntitlements: true,
200
+ secretRegistry: paymentsSecretsRegistry,
201
+ workflows: paymentsWorkflows,
202
+ compose: (context) => checkLedgerGrants(context, resolved),
203
+ client: ({ environment }) => clientProjection(resolved, environment),
204
+ requiredBindings,
205
+ config: PaymentsConfig,
206
+ databases: { [PAYMENTS_DATABASE_NAME]: {
207
+ binding: "DB",
208
+ tables: paymentsTables(),
209
+ migrationOrder: PAYMENTS_MIGRATION_ORDER,
210
+ migrations
211
+ } },
212
+ middleware: [installEntitlementResolver(PAYMENTS_DATABASE_NAME, subject)],
213
+ adminRoutes: paymentsAdminRoutes(resolved.basePath),
214
+ manifestConfig: paymentsManifestConfig(resolved.billingSubject),
215
+ routes: registerPaymentsRoutes({
216
+ config: resolved,
217
+ subject
218
+ }),
219
+ seeds: [paymentsExampleSeed]
220
+ });
221
+ return Object.assign(capability, { paymentsConfig: resolved });
222
+ }
223
+ /** Whether a capability is the payments capability — carries its resolved catalog. */
224
+ function isPaymentsCapability(capability) {
225
+ return capability.name === "payments" && "paymentsConfig" in capability;
226
+ }
227
+ //#endregion
228
+ export { PAYMENTS_MIGRATION_ORDER, isPaymentsCapability, payments };
@@ -0,0 +1,435 @@
1
+ /**
2
+ * The framework-free half of the client surface: five calls against this project's own payments routes,
3
+ * and the guards that make their answers safe to read.
4
+ *
5
+ * **This module lives in the package on purpose.** `pithy ui add` writes a screen once and may never
6
+ * rewrite it, and a frozen paywall ages badly — store rules move under it, so price-change consent
7
+ * prompts, external purchase link entitlements, and subscription-management requirements all arrive
8
+ * after the file was written. So the calls, the error mapping, and the redirect-and-return dance ship
9
+ * here and upgrade with a minor release; the scaffolded stub renders and styles, and calls these.
10
+ *
11
+ * **Cookie/session, same origin.** Every request carries `credentials: "include"` and nothing else. No
12
+ * token in `localStorage` or `sessionStorage`, no `Authorization` header, no refresh rotation. The SPA
13
+ * and its Worker share an origin, so the session rides an httpOnly cookie that JavaScript cannot read
14
+ * and the server's same-origin check covers CSRF. Bearer is the mobile path — supported by the same
15
+ * routes, documented rather than scaffolded.
16
+ *
17
+ * **Nothing here throws, and nothing here hides a failure either.** An unreachable Worker, an HTML error
18
+ * page from a proxy, a 500 — each becomes a renderable {@link PaymentsFailure} on a `PaymentsResult`, and
19
+ * every reader answers one. Failing shut is a decision for a caller to make and to write down: a route
20
+ * guard does `result.ok && result.value.some(…)`, a screen that names the plan reports the failure
21
+ * instead. A reader that collapsed the two would make the choice for callers that must not have it made
22
+ * for them, which is what `api.test.ts` now holds the module to.
23
+ *
24
+ * The server's `requireEntitlement()` is still the security boundary. Nothing on this side of the wire
25
+ * protects a feature; it only decides what a screen shows.
26
+ *
27
+ * **No absolute URL literals, and no schema library.** Paths are relative, so the calls follow whatever
28
+ * origin the bundle is served from. Answers are narrowed by hand-written `is…(value: unknown): value is T`
29
+ * guards rather than Zod: this file is compiled into a browser bundle, and it must not drag the server's
30
+ * schema graph in behind it.
31
+ */
32
+ /** Where the payments routes mount by default — the same default `PaymentsConfig.basePath` carries. */
33
+ export declare const PAYMENTS_BASE_PATH = "/payments";
34
+ /**
35
+ * The query parameter a returning Stripe buyer carries the Checkout Session id in.
36
+ *
37
+ * It is a default, not a rule: `config.stripe.successUrl` is the adopter's own URL, and the documented
38
+ * shape puts `{CHECKOUT_SESSION_ID}` in `?session=`. A project that named it something else passes the
39
+ * name to {@link returnedCheckoutSession}.
40
+ */
41
+ export declare const CHECKOUT_SESSION_PARAM = "session";
42
+ /**
43
+ * The wire unions, declared literally rather than imported from `../data/*`.
44
+ *
45
+ * Those modules pull core's codecs and Zod into whatever TypeScript program typechecks this file, and
46
+ * this file is typechecked inside an adopter's DOM-typed *browser* program, where the Worker's type
47
+ * graph does not belong. `api.test.ts` pins each of these against the schema it mirrors, so the
48
+ * duplication cannot drift.
49
+ */
50
+ export type PaymentsClientRail = "apple" | "google" | "stripe" | "lemonSqueezy" | "paddle";
51
+ /**
52
+ * The rails that create a hosted checkout a browser can be sent to.
53
+ *
54
+ * A strict subset of {@link PaymentsClientRail}: Apple and Google purchases happen inside a store SDK, so
55
+ * there is no page to send anyone to. Nameable from a browser because a rail decides *who takes the money*,
56
+ * not how much or on whose behalf — a paywall for a product sold on both can put two buttons on the page,
57
+ * and a product sold on one needs no field at all.
58
+ */
59
+ export type PaymentsHostedRail = "stripe" | "lemonSqueezy" | "paddle";
60
+ /**
61
+ * The runtime mirror of {@link PaymentsHostedRail} — and the one list a screen gates a billing button on.
62
+ *
63
+ * Exported rather than private, because the screens need it. A scaffolded subscription page shows
64
+ * "Manage billing" when any hosted rail is on, and a scaffolded paywall offers to sell on any hosted
65
+ * rail a product is listed on: both are the same question, and both were open-coding the answer. A rail
66
+ * added to the package now reaches a template that was copied into an adopter's repo a year ago,
67
+ * because the template imports this rather than repeating it.
68
+ *
69
+ * Selling and portal-minting are one list, not two that agree — `CheckoutRail` declares both methods
70
+ * together, so a rail cannot have one without the other. `../data/rail.ts` carries the argument in full,
71
+ * and `providers.test.ts` holds this list to the rails that actually implement the interface.
72
+ */
73
+ export declare const PAYMENTS_HOSTED_RAILS: readonly PaymentsHostedRail[];
74
+ /** Which Paddle account a handoff belongs to. `Paddle.Environment.set` takes it verbatim. */
75
+ export type PaymentsPaddleEnvironment = "sandbox" | "production";
76
+ /** Whether a Paddle checkout opens over the page or inside a container the screen provides. */
77
+ export type PaymentsPaddleDisplayMode = "overlay" | "inline";
78
+ /**
79
+ * How the browser reaches checkout — a page to go to, or a transaction to open in place.
80
+ *
81
+ * A union rather than `{ url }`, because one rail has no URL to give: Paddle's overlay and inline modes
82
+ * never leave this page. A screen narrows on `kind`, which is a compile error where it is missing rather
83
+ * than a runtime navigation to an empty string.
84
+ */
85
+ export type PaymentsCheckoutHandoff = {
86
+ kind: "redirect";
87
+ url: string;
88
+ } | PaddleCheckoutHandoff;
89
+ /**
90
+ * The handoff a Paddle checkout returns: a transaction, and what a browser needs to open it.
91
+ *
92
+ * Named rather than inlined because a screen holds one — `useCheckout` exposes it, and a `Paddle.Checkout
93
+ * .open` call site needs a type to write against.
94
+ */
95
+ export interface PaddleCheckoutHandoff {
96
+ /** Discriminates this from a redirect. */
97
+ kind: "paddle";
98
+ /** The transaction the server created — `txn_…`. */
99
+ transactionId: string;
100
+ /** Paddle's publishable client token, which is designed to reach a browser. */
101
+ clientToken: string;
102
+ /** Which Paddle account the token belongs to. */
103
+ environment: PaymentsPaddleEnvironment;
104
+ /** Whether the checkout opens over the page or inside a container. */
105
+ displayMode: PaymentsPaddleDisplayMode;
106
+ /**
107
+ * Where a buyer who paid is sent, from `config.paddle.successUrl`.
108
+ *
109
+ * **On the handoff rather than in the screen's hands, and that is the same rule the redirect rails
110
+ * follow.** `settings.successUrl` is a URL the browser is sent to with a completed purchase behind it;
111
+ * a screen that could name it could send a paying customer to a page it controls. So it comes from the
112
+ * server, on the response, exactly as a Stripe session's return URLs do — and it is checked here as a
113
+ * navigable URL before anything hands it to Paddle.
114
+ */
115
+ successUrl: string;
116
+ }
117
+ /** One subscription's authenticated portal deep links. */
118
+ export interface PaymentsPortalSubscription {
119
+ /** The store's own subscription id. */
120
+ subscriptionId: string;
121
+ /** Where this subscription is canceled. */
122
+ cancel: string;
123
+ /** Where this subscription's payment method is changed. */
124
+ updatePaymentMethod: string;
125
+ }
126
+ /**
127
+ * The caller's billing portal: an overview page, and any per-subscription deep links the store minted.
128
+ *
129
+ * **Every URL here is a bearer credential for that customer's billing.** Paddle's overview link carries a
130
+ * token good for 24 hours with scopes covering subscription updates and transaction creation, so a screen
131
+ * navigates to one and never stores it, logs it, or puts it in a query string something else will read.
132
+ */
133
+ export interface PaymentsPortalHandoff {
134
+ /** The portal's overview page. */
135
+ url: string;
136
+ /** Per-subscription deep links, for the store that offers them. */
137
+ subscriptions?: readonly PaymentsPortalSubscription[];
138
+ }
139
+ /** What kind of thing a product is, as a browser reads it. */
140
+ export type PaymentsClientProductType = "consumable" | "non_consumable" | "subscription";
141
+ /** The normalized purchase status, as a browser reads it. */
142
+ export type PaymentsClientStatus = "active" | "in_grace" | "on_hold" | "canceled" | "expired" | "never_paid" | "refunded" | "revoked" | "paused";
143
+ /** Which store environment a purchase happened in, as a browser reads it. */
144
+ export type PaymentsClientEnvironment = "production" | "sandbox";
145
+ /** One entitlement as `GET /payments/entitlements` returns it. */
146
+ export interface EntitlementView {
147
+ /** The entitlement key gating code names — `pro`, never a SKU. */
148
+ key: string;
149
+ /** Whether it grants access right now. The server rechecks expiry on every read. */
150
+ granted: boolean;
151
+ /** When it lapses, as an ISO string, or null for one that never does. */
152
+ expiresAt: string | null;
153
+ }
154
+ /** One purchase as the write routes return it. Deliberately not the row — a client has no use for its own receipt. */
155
+ export interface PurchaseView {
156
+ /** The purchase's id. */
157
+ id: string;
158
+ /** Which store it came from. */
159
+ rail: PaymentsClientRail;
160
+ /** The logical catalog product id. */
161
+ productId: string;
162
+ /** What kind of product it is. */
163
+ type: PaymentsClientProductType;
164
+ /** The normalized status. */
165
+ status: PaymentsClientStatus;
166
+ /** Which store environment it happened in. */
167
+ environment: PaymentsClientEnvironment;
168
+ /** When the store recorded it, as an ISO string. */
169
+ purchasedAt: string;
170
+ /** When access lapses, as an ISO string, or null. */
171
+ expiresAt: string | null;
172
+ /**
173
+ * When a paused subscription resumes, as an ISO string, or null.
174
+ *
175
+ * Null means two different things and `status` tells them apart: with `paused`, the store put no end on
176
+ * the pause; with anything else, the subscription is not paused. A screen that renders "paused until"
177
+ * has to branch on both.
178
+ */
179
+ resumesAt: string | null;
180
+ /** What this submission did to the projection. `ignored` is a replay, and a replay is a success. */
181
+ outcome: "created" | "updated" | "ignored";
182
+ }
183
+ /** A refusal a screen can render: the namespaced code, the public message, and what to do next. */
184
+ export interface PaymentsFailure {
185
+ /** The namespaced code — `payments/product_not_found`, or a `client/*` sentinel this module minted. */
186
+ code: string;
187
+ /** The public message. The server's `detail` never crosses the HTTP codec, so this is all there is. */
188
+ message: string;
189
+ /** What to do next, when the server offered one. */
190
+ action: string | null;
191
+ /**
192
+ * The values a translating client interpolates into its own wording for `code`, when the server sent
193
+ * any.
194
+ *
195
+ * **Carried because the documented contract is `t.maybe(code, params) ?? message`**, and a decoder
196
+ * that drops `params` makes the first half of it a lie: `interpolate` leaves an unsupplied
197
+ * placeholder exactly as written, so a screen renders `That board does not exist: {board}.` — worse
198
+ * than the English it was trying to improve on. No kit throw site passes `params` today, which is
199
+ * precisely why this is easy to leave out and expensive to notice later.
200
+ */
201
+ params?: Record<string, string | number | boolean>;
202
+ }
203
+ /** Either the value, or a failure to render. Never a throw. */
204
+ export type PaymentsResult<T> = {
205
+ ok: true;
206
+ value: T;
207
+ } | {
208
+ ok: false;
209
+ failure: PaymentsFailure;
210
+ };
211
+ /** What `POST /payments/purchases` answers with. */
212
+ export interface PurchaseReceipt {
213
+ /** The purchase as it now stands. */
214
+ purchase: PurchaseView;
215
+ /** The caller's entitlements after the write, so a screen needs no second round trip. */
216
+ entitlements: readonly EntitlementView[];
217
+ }
218
+ /** What `POST /payments/restore` answers with. */
219
+ export interface RestoredPurchases {
220
+ /** Every purchase the batch projected. */
221
+ purchases: readonly PurchaseView[];
222
+ /** The caller's entitlements after the restore. */
223
+ entitlements: readonly EntitlementView[];
224
+ }
225
+ /**
226
+ * The slice of `fetch` this module uses, declared structurally.
227
+ *
228
+ * Not `typeof fetch`: the package compiles against `@cloudflare/workers-types`, whose `RequestInit` has
229
+ * no `credentials` — and `credentials: "include"` is the entire cookie story. Declaring the shape keeps
230
+ * one signature true in a Worker-typed program, in a browser, and in a test that injects a stub.
231
+ */
232
+ export interface PaymentsRequestInit {
233
+ /** The HTTP method. Absent means GET. */
234
+ method?: string;
235
+ /** Request headers. */
236
+ headers?: Record<string, string>;
237
+ /** The JSON body, already serialized. */
238
+ body?: string;
239
+ /** Cookie policy. Always `include` here — same-origin, httpOnly session cookie. */
240
+ credentials?: "include" | "same-origin" | "omit";
241
+ }
242
+ /** The slice of `Response` this module reads. */
243
+ export interface PaymentsResponse {
244
+ /** Whether the status was 2xx. */
245
+ ok: boolean;
246
+ /** The HTTP status. */
247
+ status: number;
248
+ /** The parsed body, or a rejection when it was not JSON. */
249
+ json(): Promise<unknown>;
250
+ }
251
+ /** A fetch this module can call. */
252
+ export type PaymentsFetch = (input: string, init?: PaymentsRequestInit) => Promise<PaymentsResponse>;
253
+ /** Leaving the page for a hosted Stripe flow. */
254
+ export type Navigate = (url: string) => void;
255
+ /**
256
+ * The browser globals this module reaches for, as an injectable seam.
257
+ *
258
+ * Reached through an object rather than `window` because the package compiles in a program with no DOM
259
+ * lib, alongside the Worker code — the same collision `@pithy-sh/ui-react` keeps a second tsconfig to
260
+ * avoid. Injecting it is also what lets a test prove the no-browser path without a DOM.
261
+ */
262
+ export interface PaymentsGlobal {
263
+ /** The browser's fetch. */
264
+ fetch?: PaymentsFetch;
265
+ /** The browser's location — read for the return query string, called to leave for a hosted page. */
266
+ location?: {
267
+ search?: string;
268
+ assign?: (url: string) => void;
269
+ };
270
+ }
271
+ /** What every call takes: where the routes are, and the seams a test replaces. */
272
+ export interface PaymentsClientOptions {
273
+ /** Where the payments routes mount. Defaults to {@link PAYMENTS_BASE_PATH}. */
274
+ basePath?: string;
275
+ /** The fetch to use. Defaults to the one on {@link PaymentsClientOptions.global}. */
276
+ fetch?: PaymentsFetch;
277
+ /** How to leave for a hosted page. Defaults to the browser's own `location.assign`. */
278
+ navigate?: Navigate;
279
+ /** The global object the defaults come off. Defaults to `globalThis`. */
280
+ global?: PaymentsGlobal;
281
+ }
282
+ /** The worker could not be reached at all. Offline, or a DNS failure, or a hard CORS refusal. */
283
+ export declare const PAYMENTS_UNREACHABLE: PaymentsFailure;
284
+ /** The worker answered with something this client cannot read. A proxy's HTML page, or a shape change. */
285
+ export declare const PAYMENTS_UNREADABLE: PaymentsFailure;
286
+ /** There is no browser here to send anywhere — server-side rendering, or a test with no DOM. */
287
+ export declare const PAYMENTS_NO_BROWSER: PaymentsFailure;
288
+ /** Whether a value is one entitlement as the route returns it. */
289
+ export declare function isEntitlementView(value: unknown): value is EntitlementView;
290
+ /** Whether a value is one purchase as the write routes return it. */
291
+ export declare function isPurchaseView(value: unknown): value is PurchaseView;
292
+ /**
293
+ * One call: same-origin, cookie-carrying, never throwing. **The only producer of that request.**
294
+ *
295
+ * The body is read before the status is judged, because a refusal's body is the failure a screen renders.
296
+ * A body that will not parse is the generic failure rather than a crash — a corporate proxy's HTML page
297
+ * reaches a browser far more often than anyone expects.
298
+ *
299
+ * **Exported, and that is the point of it.** This was private, so `../pricing/visitor.ts` wrote a second
300
+ * fetch with the same base-path default, the same `credentials: "include"`, and the same three failure
301
+ * directions — two producers of one rule, which is the shape of every recurring defect this kit has
302
+ * shipped. The second producer is always the cheap one to add and the one that drifts. Every browser
303
+ * program that asks this Worker a question calls this, and `sameOrigin.test.ts` fails the build on any
304
+ * module that grows its own (#346).
305
+ *
306
+ * **Zod-free, like everything on this side of the wire.** The answer is narrowed by the hand-written
307
+ * `guard` a caller passes, never by a schema: this compiles into an adopter's browser bundle, and
308
+ * dragging the Worker's schema graph in behind it would break their build.
309
+ */
310
+ export declare function callPayments<T>(path: string, init: PaymentsRequestInit, options: PaymentsClientOptions | undefined, guard: (value: unknown) => value is T): Promise<PaymentsResult<T>>;
311
+ /**
312
+ * The caller's own entitlements. Always the caller's — the id comes from the session, never from here.
313
+ *
314
+ * **A failure is not an empty list**, and the distinction is the whole point of the return type. Failing
315
+ * shut is still the right default for a *lock*, because a lock is a refusal and the caller can carry an
316
+ * escape route on it. It is wrong for a caller that **names** the plan: free is the floor of every ladder,
317
+ * carrying no entitlement key and matching unconditionally, so `[]` is a positive assertion that this
318
+ * customer is on the cheapest tier. A screen rendering that from a failed read tells an Enterprise
319
+ * customer they are on Free and offers to sell them what they already pay for.
320
+ *
321
+ * So the failure `call` already built travels out intact, and a caller that wants fail-shut writes
322
+ * `result.ok ? result.value : []` — one line, and it reads as the decision it is rather than as the
323
+ * absence of one. {@link useEntitlement} does exactly that; {@link useSubscription} reports the failure.
324
+ */
325
+ export declare function getEntitlements(options?: PaymentsClientOptions): Promise<PaymentsResult<readonly EntitlementView[]>>;
326
+ /**
327
+ * Submit one receipt for verification, so the buyer sees their entitlement without waiting for the webhook.
328
+ *
329
+ * On the web this is the Stripe return path: `successUrl` carries the Checkout Session id, and posting it
330
+ * here projects the purchase at once. On a native client it is the store SDK's transaction. A replay by
331
+ * its own owner is a 200 with `outcome: "ignored"` — the write path is idempotent, so repeating is free.
332
+ */
333
+ export declare function submitPurchase(input: {
334
+ rail: PaymentsClientRail;
335
+ receipt: string;
336
+ }, options?: PaymentsClientOptions): Promise<PaymentsResult<PurchaseReceipt>>;
337
+ /**
338
+ * Restore Purchases — rebind a store account's history to the signed-in user.
339
+ *
340
+ * Native only in practice: only the device can enumerate what its store account owns. One bad receipt
341
+ * fails the whole batch by design, and every receipt that did project stays projected.
342
+ */
343
+ export declare function restorePurchases(input: {
344
+ rail: PaymentsClientRail;
345
+ receipts: readonly string[];
346
+ }, options?: PaymentsClientOptions): Promise<PaymentsResult<RestoredPurchases>>;
347
+ /** Create a checkout for a product, and say how the browser reaches it. */
348
+ export declare function createCheckout(input: {
349
+ productId: string;
350
+ rail?: PaymentsHostedRail;
351
+ discountCode?: string;
352
+ }, options?: PaymentsClientOptions): Promise<PaymentsResult<PaymentsCheckoutHandoff>>;
353
+ /**
354
+ * Create a Billing Portal session for the caller's own store account.
355
+ *
356
+ * No body, and that is the request contract: there is exactly one customer this caller may manage, and
357
+ * the server resolves it from the provider-account map. A `customer` field here would be the whole
358
+ * vulnerability.
359
+ */
360
+ export declare function createPortal(options?: PaymentsClientOptions): Promise<PaymentsResult<PaymentsPortalHandoff>>;
361
+ /**
362
+ * What starting a checkout did. Three outcomes, and a screen must tell them apart.
363
+ *
364
+ * `left` is a redirect rail: the browser is already going, and there is nothing to render. `paddle` is a
365
+ * rail with nowhere to go — the screen opens the handoff with Paddle.js, over its own page. `refused` is
366
+ * a failure worth showing.
367
+ *
368
+ * Deliberately not `PaymentsFailure | null` any more. That shape could only say "went" or "did not", and
369
+ * a Paddle handoff is neither: collapsing it into `null` would leave a buyer on a paywall whose button
370
+ * silently did nothing.
371
+ */
372
+ export type PaymentsCheckoutStart = {
373
+ kind: "left";
374
+ } | {
375
+ kind: "paddle";
376
+ handoff: PaddleCheckoutHandoff;
377
+ } | {
378
+ kind: "refused";
379
+ failure: PaymentsFailure;
380
+ };
381
+ /**
382
+ * Buy a product: create the checkout, and either hand the browser over or hand the caller the handoff.
383
+ *
384
+ * A redirect rail needs no SDK script and no client-side key — the server mints a session and answers
385
+ * with a URL, and a full page load is the whole integration. Paddle's overlay and inline modes need
386
+ * Paddle.js and the publishable token the server returned, and opening it is the screen's job because
387
+ * that is where the container lives. Pithy never owns payment UI, SCA, tax, or proration either way.
388
+ */
389
+ export declare function startCheckout(input: {
390
+ productId: string;
391
+ rail?: PaymentsHostedRail;
392
+ discountCode?: string;
393
+ }, options?: PaymentsClientOptions): Promise<PaymentsCheckoutStart>;
394
+ /** Open the billing portal — where a subscriber changes a card, or cancels, under the store's own rules. */
395
+ export declare function openBillingPortal(options?: PaymentsClientOptions): Promise<PaymentsFailure | null>;
396
+ /**
397
+ * Where a store sends a subscriber to manage a subscription they bought in an app.
398
+ *
399
+ * These live in the package rather than in a scaffolded screen for the reason the whole client surface
400
+ * does: they are Apple's and Google's URLs, not the adopter's, and when a store moves one the fix should
401
+ * be a minor release rather than an edit to a file Pithy may never rewrite. It is also what keeps the
402
+ * scaffolded templates free of absolute URLs, which the CLI's own scaffold check enforces.
403
+ *
404
+ * There is no Stripe entry. Stripe's equivalent is a *session* the server mints per caller — see
405
+ * {@link openBillingPortal} — and a static URL there would be a link to nobody's account.
406
+ */
407
+ export declare const STORE_SUBSCRIPTION_URLS: Readonly<Record<"apple" | "google", string>>;
408
+ /**
409
+ * Send the browser to a store's own subscription-management page.
410
+ *
411
+ * Returns false only when there is no browser to send. A web page cannot cancel a StoreKit or Play
412
+ * Billing subscription — the store owns that, by its own rules — so linking there is the whole of what a
413
+ * web screen can honestly offer.
414
+ */
415
+ export declare function openStoreSubscriptions(rail: "apple" | "google", options?: PaymentsClientOptions): boolean;
416
+ /** What {@link returnedCheckoutSession} reads, and where from. */
417
+ export interface CheckoutReturnOptions {
418
+ /** The query string to read. Defaults to the browser's own `location.search`. */
419
+ search?: string;
420
+ /** The parameter carrying the session id. Defaults to {@link CHECKOUT_SESSION_PARAM}. */
421
+ param?: string;
422
+ /** The global object `location` comes off. Defaults to `globalThis`. */
423
+ global?: PaymentsGlobal;
424
+ }
425
+ /**
426
+ * The Checkout Session id a returning buyer arrived with, or null.
427
+ *
428
+ * This is the second half of the redirect-and-return dance. Stripe substitutes the real id into the
429
+ * `{CHECKOUT_SESSION_ID}` token in the adopter's `successUrl`, and posting it to `/payments/purchases`
430
+ * projects the purchase immediately instead of waiting for the webhook. The webhook is still
431
+ * authoritative and still arrives — this only decides whether the buyer sees their entitlement now or in
432
+ * a few seconds.
433
+ */
434
+ export declare function returnedCheckoutSession(options?: CheckoutReturnOptions): string | null;
435
+ //# sourceMappingURL=api.d.ts.map