@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,74 @@
1
+ import { z } from "zod";
2
+ //#region src/data/rail.ts
3
+ /**
4
+ * The five payment rails, as one normalized name each. Nothing downstream of a rail's own module ever
5
+ * branches on a store's vocabulary — Apple's `originalTransactionId`, Google's `purchaseToken`, Stripe's
6
+ * `subscription` and Paddle's `sub_…` all arrive as a `(rail, providerTransactionId)` pair, which is what
7
+ * lets one projection serve five stores and one entitlement resolve across them.
8
+ *
9
+ * Adding a sixth rail (Amazon Appstore) is a member here plus a provider module. Nothing else in the
10
+ * package knows how many there are.
11
+ *
12
+ * `lemonSqueezy` and `paddle` are the two **merchants of record**: each owns the tax registration, the VAT
13
+ * thresholds, the invoices and the chargebacks, where the other three leave every one of those to the
14
+ * adopter. That is a commercial difference rather than a technical one, and the only place it shows in
15
+ * this package is that a refund can arrive with no local write preceding it — both issue them on their own.
16
+ */
17
+ const PaymentsRail = z.enum([
18
+ "apple",
19
+ "google",
20
+ "stripe",
21
+ "lemonSqueezy",
22
+ "paddle"
23
+ ]).describe("Which store a transaction came from — Apple's App Store, Google Play, Stripe, Lemon Squeezy, or Paddle.");
24
+ /** Every rail, in a stable order — for iterating the catalog's per-rail blocks and cross-checking them. */
25
+ const PAYMENTS_RAILS = PaymentsRail.options;
26
+ /**
27
+ * The rails that sell in a browser — and mint a billing portal, which is the same statement.
28
+ *
29
+ * **One name, because it is one question.** {@link CheckoutRail} declares `createCheckoutSession` and
30
+ * `createPortalSession` together, so a rail cannot start a purchase on the web without also having a
31
+ * portal to send that buyer back to. "Sells in a browser" and "mints a portal we can link to" are not
32
+ * two lists that happen to match today; they are one list, held that way by an interface. Two names
33
+ * would suggest a divergence the type system does not permit, and the next person would have to read
34
+ * both to learn they are the same.
35
+ *
36
+ * The day a rail sells without a portal, `CheckoutRail` splits first — and `providers.test.ts`, which
37
+ * compares this list against the rails that actually satisfy `isCheckoutRail`, goes red. That is the
38
+ * moment a second name is earned, and it arrives with a failing test rather than a judgment call.
39
+ *
40
+ * **Enumerated rather than computed**, because nothing can compute it. A screen cannot construct a rail
41
+ * provider to discover what it implements, and `PaymentsRail.options` cannot answer it either — Apple and
42
+ * Google are rails and are not hosted. So it is a named subset with a gate over it, in both programs: this
43
+ * one, and its DOM-safe mirror in `src/client/api.ts`, which stays a hand-written union because pulling
44
+ * Zod into an adopter's browser program is what that file exists to avoid.
45
+ *
46
+ * Ordered, and the order is only used to make a refusal deterministic when a product sells on two rails
47
+ * and the caller named neither. See `checkoutRailFor`.
48
+ *
49
+ * **Extracted from {@link PaymentsRail} rather than spelled again.** A member misspelled here is a
50
+ * compile error rather than a rail that silently never matches, and the extraction is what lets the four
51
+ * schemas that narrow to this subset share one definition instead of four literals.
52
+ *
53
+ * **One subset, not two.** These are also exactly the rails that mint discount codes today, and both
54
+ * discount schemas narrow to this. A second constant would be a mirror with nothing to mirror. The day a
55
+ * rail mints and does not sell, or sells and does not mint, `providers.test.ts` disagrees with itself and
56
+ * the subset splits — with a failing test rather than a judgment call, which is the same bargain
57
+ * `CheckoutRail` makes for selling and portal-minting.
58
+ */
59
+ const PaymentsHostedRail = PaymentsRail.extract([
60
+ "stripe",
61
+ "lemonSqueezy",
62
+ "paddle"
63
+ ]).describe("Which hosted rail — the three that sell in a browser, mint a portal, and mint a discount code.");
64
+ /**
65
+ * The same three as a plain array, for the callers that iterate rather than parse.
66
+ *
67
+ * Derived from the schema rather than written beside it. Four request and response schemas wrote this
68
+ * subset out by hand and Paddle reached none of them (#465), so a rail that sold, minted portals and minted
69
+ * discount codes was a 400 at every point a caller had to name it. One list, one edit — and
70
+ * `providers.test.ts` holds it to the rails that satisfy the interfaces at runtime, in both directions.
71
+ */
72
+ const PAYMENTS_HOSTED_RAILS = PaymentsHostedRail.options;
73
+ //#endregion
74
+ export { PAYMENTS_HOSTED_RAILS, PAYMENTS_RAILS, PaymentsHostedRail, PaymentsRail };
@@ -0,0 +1,120 @@
1
+ import type { D1Database } from "@cloudflare/workers-types";
2
+ import { z } from "zod";
3
+ import { PurchaseEnvironment } from "./purchase";
4
+ import { PaymentsRail } from "./rail";
5
+ /**
6
+ * One reconciliation pass, kept — the row in `pithy_payments_reconcile_runs`.
7
+ *
8
+ * **Reconciliation is the compensating control for a delivery mechanism that is known to fail.** Webhooks are
9
+ * dropped, delayed and delivered out of order, which is the whole reason the pass exists. So the run that
10
+ * *repaired* something is the most operationally valuable event this capability produces: it is the proof that
11
+ * a delivery went missing and that a customer was briefly wrong.
12
+ *
13
+ * Before this table, that was unobservable after the fact. The pass wrote its tally to a `Logger` and its
14
+ * repairs to an `AuditEmit`, and *"has reconciliation been running"* had no answer but reading logs, while
15
+ * *"what did it fix last month"* had none at all. An adopter could not tell a healthy integration from one
16
+ * whose cron stopped firing, because a silent nightly job and a job that is not running look identical.
17
+ *
18
+ * ## A run is a summary, not a second audit trail
19
+ *
20
+ * An audit event is one thing that happened; a run is the statement over many — started, finished, how much
21
+ * was compared, how much was repaired, what failed. That tally cannot be reconstructed by grouping events,
22
+ * because nothing in the events says where one pass ended and the next began.
23
+ *
24
+ * So the repairs stay in the audit trail, once, and **the run points at them rather than copying them**: the
25
+ * run's `id` travels on every `payments/purchase_reconciled` event the pass emits, as `runId`. Copying the
26
+ * repairs here would build a second, weaker copy of the trail inside a table with different access rules —
27
+ * the mistake `admin/coverage.ts` refuses on the webhook log for the same reason.
28
+ *
29
+ * ## A clean run is stored
30
+ *
31
+ * *"It ran and found nothing"* is the answer to *"is it healthy"*. Storing only the passes that repaired
32
+ * something would make silence ambiguous — indistinguishable from a cron that stopped firing, which is
33
+ * precisely the failure this table exists to make visible.
34
+ *
35
+ * ## Retention
36
+ *
37
+ * {@link RECONCILE_RUN_RETENTION_DAYS} days, pruned by the writer on every run. Runs are small and frequent —
38
+ * a daily cron is one row a day — so the table is bounded by the schedule rather than by the catalog, and a
39
+ * ninety-day window covers "did it run last quarter" while never growing without limit. It is stated here and
40
+ * enforced in {@link recordReconcileRun}, rather than left to be discovered when a table is large.
41
+ *
42
+ * ## No provider payload, and structurally so
43
+ *
44
+ * Every field below is a count, a timestamp, an enum or this deployment's own id. There is no column a
45
+ * store's response could be written into, so a run record cannot carry one — the same control
46
+ * `admin/read.ts` applies to a purchase by never selecting `payload`, taken one step further by never
47
+ * having the column.
48
+ */
49
+ /** How long a run record is kept. Days, pruned by the writer — see the module doc. */
50
+ export declare const RECONCILE_RUN_RETENTION_DAYS = 90;
51
+ /** One reconciliation pass, as stored. `z.output` is the app shape; `z.input` is the SQLite row. */
52
+ export declare const PaymentsReconcileRun: z.ZodObject<{
53
+ id: z.ZodString;
54
+ startedAt: z.ZodCodec<z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodDate]>, z.ZodDate>;
55
+ finishedAt: z.ZodCodec<z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodDate]>, z.ZodDate>;
56
+ environment: z.ZodEnum<{
57
+ production: "production";
58
+ sandbox: "sandbox";
59
+ }>;
60
+ rail: z.ZodNullable<z.ZodEnum<{
61
+ apple: "apple";
62
+ google: "google";
63
+ lemonSqueezy: "lemonSqueezy";
64
+ paddle: "paddle";
65
+ stripe: "stripe";
66
+ }>>;
67
+ pages: z.ZodNumber;
68
+ scanned: z.ZodNumber;
69
+ unchanged: z.ZodNumber;
70
+ drifted: z.ZodNumber;
71
+ superseded: z.ZodNumber;
72
+ skipped: z.ZodNumber;
73
+ failed: z.ZodNumber;
74
+ truncated: z.ZodCodec<z.ZodUnion<readonly [z.ZodLiteral<0>, z.ZodLiteral<1>, z.ZodBoolean, z.ZodString]>, z.ZodBoolean>;
75
+ dryRun: z.ZodCodec<z.ZodUnion<readonly [z.ZodLiteral<0>, z.ZodLiteral<1>, z.ZodBoolean, z.ZodString]>, z.ZodBoolean>;
76
+ createdAt: z.ZodCodec<z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodDate]>, z.ZodDate>;
77
+ }, z.core.$strip>;
78
+ export type PaymentsReconcileRun = z.output<typeof PaymentsReconcileRun>;
79
+ export type PaymentsReconcileRunRow = z.input<typeof PaymentsReconcileRun>;
80
+ /** What the pass hands the writer. The row, minus the two fields the writer owns. */
81
+ export interface ReconcileRunInput {
82
+ /** The run's id — minted before the pass so the repairs it audits can name it. */
83
+ id: string;
84
+ /** When the pass began. */
85
+ startedAt: Date;
86
+ /** When it finished. */
87
+ finishedAt: Date;
88
+ /** The deployment's store environment. */
89
+ environment: PurchaseEnvironment;
90
+ /** The rail the pass was narrowed to, or null for every enabled one. */
91
+ rail: PaymentsRail | null;
92
+ /** The tally, as `reconcilePayments` reports it. */
93
+ report: {
94
+ pages: number;
95
+ scanned: number;
96
+ unchanged: number;
97
+ drifted: number;
98
+ superseded: number;
99
+ skipped: number;
100
+ failed: number;
101
+ truncated: boolean;
102
+ dryRun: boolean;
103
+ };
104
+ }
105
+ /**
106
+ * Write one run record, and prune the ones past retention.
107
+ *
108
+ * Idempotent on the run's id: a Workflow step that wrote the row and then failed to journal its result
109
+ * replays the whole body, and a second insert for one pass would make the health read count a pass twice.
110
+ * `ON CONFLICT (id) DO UPDATE` is what makes the replay land on the same row it already wrote.
111
+ *
112
+ * The prune shares the write rather than living in a second scheduled job, because a job that prunes is a job
113
+ * that can stop — and the only thing that ever writes here is the thing that would then also stop pruning.
114
+ * Retention is therefore a property of the writer, and a table nobody writes to does not grow.
115
+ */
116
+ export declare function recordReconcileRun(d1: D1Database, input: ReconcileRunInput, options?: {
117
+ now?: Date;
118
+ retentionDays?: number;
119
+ }): Promise<PaymentsReconcileRun>;
120
+ //# sourceMappingURL=reconcileRun.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reconcileRun.d.ts","sourceRoot":"","sources":["../../src/data/reconcileRun.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAI5D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAGtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAEH,sFAAsF;AACtF,eAAO,MAAM,4BAA4B,KAAK,CAAC;AAE/C,oGAAoG;AACpG,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;iBA8C9B,CAAC;AACJ,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,oBAAoB,CAAC,CAAC;AACzE,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAE3E,qFAAqF;AACrF,MAAM,WAAW,iBAAiB;IAChC,kFAAkF;IAClF,EAAE,EAAE,MAAM,CAAC;IACX,2BAA2B;IAC3B,SAAS,EAAE,IAAI,CAAC;IAChB,wBAAwB;IACxB,UAAU,EAAE,IAAI,CAAC;IACjB,0CAA0C;IAC1C,WAAW,EAAE,mBAAmB,CAAC;IACjC,wEAAwE;IACxE,IAAI,EAAE,YAAY,GAAG,IAAI,CAAC;IAC1B,oDAAoD;IACpD,MAAM,EAAE;QACN,KAAK,EAAE,MAAM,CAAC;QACd,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,EAAE,MAAM,CAAC;QAClB,OAAO,EAAE,MAAM,CAAC;QAChB,UAAU,EAAE,MAAM,CAAC;QACnB,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,EAAE,MAAM,CAAC;QACf,SAAS,EAAE,OAAO,CAAC;QACnB,MAAM,EAAE,OAAO,CAAC;KACjB,CAAC;CACH;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,kBAAkB,CACtC,EAAE,EAAE,UAAU,EACd,KAAK,EAAE,iBAAiB,EACxB,OAAO,GAAE;IAAE,GAAG,CAAC,EAAE,IAAI,CAAC;IAAC,aAAa,CAAC,EAAE,MAAM,CAAA;CAAO,GACnD,OAAO,CAAC,oBAAoB,CAAC,CAuD/B"}
@@ -0,0 +1,120 @@
1
+ import { PaymentsRail } from "./rail.js";
2
+ import { PurchaseEnvironment } from "./purchase.js";
3
+ import { PAYMENTS_RECONCILE_RUNS_TABLE, paymentsDatabase } from "./tables.js";
4
+ import { InternalError } from "@pithy-sh/core/src/error/pithyError";
5
+ import { z } from "zod";
6
+ import { SQLiteBoolean, SQLiteDate } from "@pithy-sh/core/src/data/codecs";
7
+ import { withD1Retry } from "@pithy-sh/core/src/data/withD1Retry";
8
+ //#region src/data/reconcileRun.ts
9
+ /**
10
+ * One reconciliation pass, kept — the row in `pithy_payments_reconcile_runs`.
11
+ *
12
+ * **Reconciliation is the compensating control for a delivery mechanism that is known to fail.** Webhooks are
13
+ * dropped, delayed and delivered out of order, which is the whole reason the pass exists. So the run that
14
+ * *repaired* something is the most operationally valuable event this capability produces: it is the proof that
15
+ * a delivery went missing and that a customer was briefly wrong.
16
+ *
17
+ * Before this table, that was unobservable after the fact. The pass wrote its tally to a `Logger` and its
18
+ * repairs to an `AuditEmit`, and *"has reconciliation been running"* had no answer but reading logs, while
19
+ * *"what did it fix last month"* had none at all. An adopter could not tell a healthy integration from one
20
+ * whose cron stopped firing, because a silent nightly job and a job that is not running look identical.
21
+ *
22
+ * ## A run is a summary, not a second audit trail
23
+ *
24
+ * An audit event is one thing that happened; a run is the statement over many — started, finished, how much
25
+ * was compared, how much was repaired, what failed. That tally cannot be reconstructed by grouping events,
26
+ * because nothing in the events says where one pass ended and the next began.
27
+ *
28
+ * So the repairs stay in the audit trail, once, and **the run points at them rather than copying them**: the
29
+ * run's `id` travels on every `payments/purchase_reconciled` event the pass emits, as `runId`. Copying the
30
+ * repairs here would build a second, weaker copy of the trail inside a table with different access rules —
31
+ * the mistake `admin/coverage.ts` refuses on the webhook log for the same reason.
32
+ *
33
+ * ## A clean run is stored
34
+ *
35
+ * *"It ran and found nothing"* is the answer to *"is it healthy"*. Storing only the passes that repaired
36
+ * something would make silence ambiguous — indistinguishable from a cron that stopped firing, which is
37
+ * precisely the failure this table exists to make visible.
38
+ *
39
+ * ## Retention
40
+ *
41
+ * {@link RECONCILE_RUN_RETENTION_DAYS} days, pruned by the writer on every run. Runs are small and frequent —
42
+ * a daily cron is one row a day — so the table is bounded by the schedule rather than by the catalog, and a
43
+ * ninety-day window covers "did it run last quarter" while never growing without limit. It is stated here and
44
+ * enforced in {@link recordReconcileRun}, rather than left to be discovered when a table is large.
45
+ *
46
+ * ## No provider payload, and structurally so
47
+ *
48
+ * Every field below is a count, a timestamp, an enum or this deployment's own id. There is no column a
49
+ * store's response could be written into, so a run record cannot carry one — the same control
50
+ * `admin/read.ts` applies to a purchase by never selecting `payload`, taken one step further by never
51
+ * having the column.
52
+ */
53
+ /** How long a run record is kept. Days, pruned by the writer — see the module doc. */
54
+ const RECONCILE_RUN_RETENTION_DAYS = 90;
55
+ /** One reconciliation pass, as stored. `z.output` is the app shape; `z.input` is the SQLite row. */
56
+ const PaymentsReconcileRun = z.object({
57
+ id: z.string().describe("The run's UUID. Travels on every repair the pass audits, as `runId`."),
58
+ startedAt: SQLiteDate.describe("When the pass began, from the run's own clock."),
59
+ finishedAt: SQLiteDate.describe("When the pass finished. Equal to `startedAt` for a run that read nothing."),
60
+ environment: PurchaseEnvironment.describe("The store environment the host was deployed to. A sandbox pass and a production pass are different facts about different money, and a table that mixed them would answer the health question wrong."),
61
+ rail: PaymentsRail.nullable().describe("The single store this pass was narrowed to, or null for every enabled rail. Null is the scheduled behavior; a value means somebody ran it by hand against one store."),
62
+ pages: z.number().int().describe("Durable steps read — one per page of purchases."),
63
+ scanned: z.number().int().describe("Purchases examined."),
64
+ unchanged: z.number().int().describe("Purchases whose stored state already matched the store's."),
65
+ drifted: z.number().int().describe("Purchases whose stored state disagreed and was repaired. The number that matters: a rising one means webhooks are being lost."),
66
+ superseded: z.number().int().describe("Old periods a later transaction has replaced, settled on this pass. Falls back to zero once a catalog's history has been walked once, which is why it is counted apart from `drifted`."),
67
+ skipped: z.number().int().describe("Purchases no store could be asked about — a rail switched off, or unaddressable."),
68
+ failed: z.number().int().describe("Purchases a store refused to answer for. Counted rather than thrown, so one bad row cannot end a pass."),
69
+ truncated: SQLiteBoolean.describe("Whether the pass stopped at its page cap with catalog left unread. True means the tally is a floor, not a total."),
70
+ dryRun: SQLiteBoolean.describe("Whether this pass only reported. A dry run repairs nothing, so its `drifted` is a finding rather than a fix."),
71
+ createdAt: SQLiteDate.describe("When this row was written.")
72
+ }).describe("One reconciliation pass — when it ran, what it was narrowed to, and its tally. Never a provider payload: there is no column for one.");
73
+ /**
74
+ * Write one run record, and prune the ones past retention.
75
+ *
76
+ * Idempotent on the run's id: a Workflow step that wrote the row and then failed to journal its result
77
+ * replays the whole body, and a second insert for one pass would make the health read count a pass twice.
78
+ * `ON CONFLICT (id) DO UPDATE` is what makes the replay land on the same row it already wrote.
79
+ *
80
+ * The prune shares the write rather than living in a second scheduled job, because a job that prunes is a job
81
+ * that can stop — and the only thing that ever writes here is the thing that would then also stop pruning.
82
+ * Retention is therefore a property of the writer, and a table nobody writes to does not grow.
83
+ */
84
+ async function recordReconcileRun(d1, input, options = {}) {
85
+ const now = options.now ?? /* @__PURE__ */ new Date();
86
+ const retentionDays = options.retentionDays ?? 90;
87
+ const db = paymentsDatabase(d1);
88
+ const row = PaymentsReconcileRun.encode({
89
+ id: input.id,
90
+ startedAt: input.startedAt,
91
+ finishedAt: input.finishedAt,
92
+ environment: input.environment,
93
+ rail: input.rail,
94
+ ...input.report,
95
+ createdAt: now
96
+ });
97
+ await withD1Retry(() => db.insertInto(PAYMENTS_RECONCILE_RUNS_TABLE).values(row).onConflict((oc) => oc.column("id").doUpdateSet({
98
+ finishedAt: row.finishedAt,
99
+ pages: row.pages,
100
+ scanned: row.scanned,
101
+ unchanged: row.unchanged,
102
+ drifted: row.drifted,
103
+ superseded: row.superseded,
104
+ skipped: row.skipped,
105
+ failed: row.failed,
106
+ truncated: row.truncated,
107
+ dryRun: row.dryRun
108
+ })).execute());
109
+ const cutoff = /* @__PURE__ */ new Date(now.getTime() - retentionDays * 864e5);
110
+ await withD1Retry(() => db.deleteFrom(PAYMENTS_RECONCILE_RUNS_TABLE).where("startedAt", "<", SQLiteDate.encode(cutoff)).execute());
111
+ const written = await db.selectFrom(PAYMENTS_RECONCILE_RUNS_TABLE).selectAll().where("id", "=", input.id).executeTakeFirst();
112
+ if (written === void 0) throw new InternalError({
113
+ message: "The reconciliation run could not be recorded.",
114
+ action: "Retry. If it persists, check the app database for the pithy_payments_* tables.",
115
+ detail: `Wrote reconcile run ${input.id} but could not read it back.`
116
+ });
117
+ return PaymentsReconcileRun.parse(written);
118
+ }
119
+ //#endregion
120
+ export { PaymentsReconcileRun, RECONCILE_RUN_RETENTION_DAYS, recordReconcileRun };
@@ -0,0 +1,85 @@
1
+ /**
2
+ * An integer in a currency's minor unit, as a sentence a customer reads — `6582` to `$65.82`.
3
+ *
4
+ * ## Why this exists at all, when `client/paddle.ts` says never to format a price
5
+ *
6
+ * That rule stands, and this does not break it: **it never decides an amount.** Paddle's integer goes in
7
+ * and comes back out, digit for digit, with a separator placed and a symbol attached. Nothing here
8
+ * divides, rounds, sums or nets, and the minor amount stays on the shape beside the string, so a consumer
9
+ * that wants the integer still gets the integer (see `QuotedMoney`).
10
+ *
11
+ * The reason the kit gave for never doing this was wrong, and it was measured wrong on 2026-08-28 (#465).
12
+ * `client/paddle.ts` argued that `Intl.NumberFormat` "would have to carry a table of which currencies have
13
+ * two decimals, and would get one wrong". It carries exactly that table, from CLDR, and it is right about
14
+ * the zero-decimal currencies: `resolvedOptions().maximumFractionDigits` answers 2 for `USD` and `GBP` and
15
+ * 0 for `JPY`, `KRW` and `CLP`. Paddle's own documentation instructs adopters to do this — "use a currency
16
+ * library to format monetary values to the correct number of decimals… symbols and decimal separators are
17
+ * placed correctly" (api-reference/about/data-types) — and offers `formatted_totals` only on the
18
+ * pricing-preview endpoint, "for convenience". `subscriptions.preview` and `transactions.preview` return no
19
+ * formatted field at any depth, verified against the recordings. So a plan-change quote has minor units or
20
+ * it has nothing, and a confirmation screen with no figure on it is a customer agreeing to an amount they
21
+ * were never shown.
22
+ *
23
+ * ## The exponent is the store's, and `Intl`'s own is not it
24
+ *
25
+ * This is the part the correction above would get wrong if it stopped one sentence early. **CLDR's
26
+ * fraction digits are a display convention, not the denomination the money arrived in**, and they are
27
+ * maintained by different people for a different purpose.
28
+ *
29
+ * The example this originally carried was wrong and is worth keeping as the correction. It claimed
30
+ * `Intl` renders 6582 forint as `66 Ft`, from CLDR giving `HUF` no fraction. CLDR carries **two**
31
+ * fraction tables — standard digits, and `cashDigits` for rounding physical currency — and `HUF` and
32
+ * `COP` are zero only in the second. `Intl.NumberFormat` reads the first, answers 2 for both, and
33
+ * renders `65,82 Ft`. Re-measured on ICU 75.1: across every code this package can be paid in, CLDR and
34
+ * ISO 4217 agree on all of them, so there is no live divergence to point at.
35
+ *
36
+ * The pinning stays anyway, and agreement today is the reason it is cheap rather than the reason to
37
+ * drop it: `Intl` is asked for a symbol and separators, and a renderer that let it choose the exponent
38
+ * would be taking the denomination from a table that can move under a runtime upgrade.
39
+ *
40
+ * So the digits come from {@link minorUnitDigits} — ISO 4217, the table this package already converts
41
+ * every rail's amounts through and the one `client/wholeUnits.ts` already trusts against Paddle's own
42
+ * strings — and `Intl` is **pinned** to it on both ends. `Intl` decides the symbol, the separators, the
43
+ * grouping and the placement; it does not decide how much money this is.
44
+ *
45
+ * ## The scaling is a string operation, deliberately
46
+ *
47
+ * `9007199254740991 / 100` is `90071992547409.9` in binary floating point — a cent, gone, on the largest
48
+ * figure this package can hold. `Intl.NumberFormat.prototype.format` accepts a decimal **string** (ES2023,
49
+ * and available in Workers and Node 22 alike), so the point is placed by moving characters and the digits
50
+ * that arrived are the digits that render. There is no arithmetic to be wrong.
51
+ *
52
+ * ## Where the locale comes from
53
+ *
54
+ * Not from here, and not from a request field. `Translator.formattingLocale` — `c.var.t` on every route —
55
+ * is what the kit already negotiates per reader, and `@pithy-sh/email` sets the precedent by building a
56
+ * per-recipient translator from a stored locale rather than inventing a second rule. This module takes
57
+ * that string as a value, which is the seam's stated contract for exactly this case: "an adopter who
58
+ * already owns their date and number rendering needs the locale as a *value* to hand to `Intl`".
59
+ *
60
+ * When nothing resolves it, the answer is {@link RENDER_FALLBACK_LOCALE} and it is *stated*: a quote
61
+ * rendered in the wrong language is recoverable, and a quote with no figure on it is not.
62
+ */
63
+ /**
64
+ * The language a figure is rendered in when the reader's own did not resolve.
65
+ *
66
+ * Core's `DEFAULT_LOCALE` rather than a second constant: it is already the locale a project falls back to
67
+ * and the one the kit writes in, and two answers to "what language when we do not know" is how a screen
68
+ * ends up in one and its money in another.
69
+ */
70
+ export declare const RENDER_FALLBACK_LOCALE = "en";
71
+ /**
72
+ * `amountMinor` of `currency`, rendered for a reader of `locale` — or `null` when the currency cannot be
73
+ * named.
74
+ *
75
+ * Null rather than a guess, which is the idiom `minorAmount` and `minorUnitsFromScaled` already set in this
76
+ * package: a store that answered `"dollars"` where a currency goes has answered with something no amount can
77
+ * be denominated in, and the caller refuses the whole quote on it rather than letting a `RangeError` out of
78
+ * `Intl` reach a confirmation screen as a 500. A **locale** `Intl` refuses is the other case entirely, and
79
+ * costs the reader only their language — see {@link RENDER_FALLBACK_LOCALE}.
80
+ *
81
+ * `locale` is optional so that a caller with nothing to pass writes nothing, rather than writing `"en"` at
82
+ * a call site and putting the fallback in two places.
83
+ */
84
+ export declare function renderMoney(amountMinor: number, currency: string, locale?: string): string | null;
85
+ //# sourceMappingURL=renderMoney.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderMoney.d.ts","sourceRoot":"","sources":["../../src/data/renderMoney.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,OAAiB,CAAC;AAgDrD;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CAAC,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAcjG"}
@@ -0,0 +1,146 @@
1
+ import { minorUnitDigits } from "./money.js";
2
+ import { DEFAULT_LOCALE } from "@pithy-sh/core/src/i18n/translator";
3
+ //#region src/data/renderMoney.ts
4
+ /**
5
+ * An integer in a currency's minor unit, as a sentence a customer reads — `6582` to `$65.82`.
6
+ *
7
+ * ## Why this exists at all, when `client/paddle.ts` says never to format a price
8
+ *
9
+ * That rule stands, and this does not break it: **it never decides an amount.** Paddle's integer goes in
10
+ * and comes back out, digit for digit, with a separator placed and a symbol attached. Nothing here
11
+ * divides, rounds, sums or nets, and the minor amount stays on the shape beside the string, so a consumer
12
+ * that wants the integer still gets the integer (see `QuotedMoney`).
13
+ *
14
+ * The reason the kit gave for never doing this was wrong, and it was measured wrong on 2026-08-28 (#465).
15
+ * `client/paddle.ts` argued that `Intl.NumberFormat` "would have to carry a table of which currencies have
16
+ * two decimals, and would get one wrong". It carries exactly that table, from CLDR, and it is right about
17
+ * the zero-decimal currencies: `resolvedOptions().maximumFractionDigits` answers 2 for `USD` and `GBP` and
18
+ * 0 for `JPY`, `KRW` and `CLP`. Paddle's own documentation instructs adopters to do this — "use a currency
19
+ * library to format monetary values to the correct number of decimals… symbols and decimal separators are
20
+ * placed correctly" (api-reference/about/data-types) — and offers `formatted_totals` only on the
21
+ * pricing-preview endpoint, "for convenience". `subscriptions.preview` and `transactions.preview` return no
22
+ * formatted field at any depth, verified against the recordings. So a plan-change quote has minor units or
23
+ * it has nothing, and a confirmation screen with no figure on it is a customer agreeing to an amount they
24
+ * were never shown.
25
+ *
26
+ * ## The exponent is the store's, and `Intl`'s own is not it
27
+ *
28
+ * This is the part the correction above would get wrong if it stopped one sentence early. **CLDR's
29
+ * fraction digits are a display convention, not the denomination the money arrived in**, and they are
30
+ * maintained by different people for a different purpose.
31
+ *
32
+ * The example this originally carried was wrong and is worth keeping as the correction. It claimed
33
+ * `Intl` renders 6582 forint as `66 Ft`, from CLDR giving `HUF` no fraction. CLDR carries **two**
34
+ * fraction tables — standard digits, and `cashDigits` for rounding physical currency — and `HUF` and
35
+ * `COP` are zero only in the second. `Intl.NumberFormat` reads the first, answers 2 for both, and
36
+ * renders `65,82 Ft`. Re-measured on ICU 75.1: across every code this package can be paid in, CLDR and
37
+ * ISO 4217 agree on all of them, so there is no live divergence to point at.
38
+ *
39
+ * The pinning stays anyway, and agreement today is the reason it is cheap rather than the reason to
40
+ * drop it: `Intl` is asked for a symbol and separators, and a renderer that let it choose the exponent
41
+ * would be taking the denomination from a table that can move under a runtime upgrade.
42
+ *
43
+ * So the digits come from {@link minorUnitDigits} — ISO 4217, the table this package already converts
44
+ * every rail's amounts through and the one `client/wholeUnits.ts` already trusts against Paddle's own
45
+ * strings — and `Intl` is **pinned** to it on both ends. `Intl` decides the symbol, the separators, the
46
+ * grouping and the placement; it does not decide how much money this is.
47
+ *
48
+ * ## The scaling is a string operation, deliberately
49
+ *
50
+ * `9007199254740991 / 100` is `90071992547409.9` in binary floating point — a cent, gone, on the largest
51
+ * figure this package can hold. `Intl.NumberFormat.prototype.format` accepts a decimal **string** (ES2023,
52
+ * and available in Workers and Node 22 alike), so the point is placed by moving characters and the digits
53
+ * that arrived are the digits that render. There is no arithmetic to be wrong.
54
+ *
55
+ * ## Where the locale comes from
56
+ *
57
+ * Not from here, and not from a request field. `Translator.formattingLocale` — `c.var.t` on every route —
58
+ * is what the kit already negotiates per reader, and `@pithy-sh/email` sets the precedent by building a
59
+ * per-recipient translator from a stored locale rather than inventing a second rule. This module takes
60
+ * that string as a value, which is the seam's stated contract for exactly this case: "an adopter who
61
+ * already owns their date and number rendering needs the locale as a *value* to hand to `Intl`".
62
+ *
63
+ * When nothing resolves it, the answer is {@link RENDER_FALLBACK_LOCALE} and it is *stated*: a quote
64
+ * rendered in the wrong language is recoverable, and a quote with no figure on it is not.
65
+ */
66
+ /**
67
+ * The language a figure is rendered in when the reader's own did not resolve.
68
+ *
69
+ * Core's `DEFAULT_LOCALE` rather than a second constant: it is already the locale a project falls back to
70
+ * and the one the kit writes in, and two answers to "what language when we do not know" is how a screen
71
+ * ends up in one and its money in another.
72
+ */
73
+ const RENDER_FALLBACK_LOCALE = DEFAULT_LOCALE;
74
+ /**
75
+ * A currency code `Intl` can be asked about at all: three ASCII letters, which is every code ISO 4217
76
+ * issues.
77
+ *
78
+ * **The shape, deliberately, and not a list of codes.** `Intl` throws a `RangeError` only on a code that is
79
+ * not well-formed; a well-formed one nobody has heard of renders with the code itself standing in for the
80
+ * symbol, which is the honest answer and is what CLDR does for `XTS`. A second allowlist of currencies here
81
+ * would be a table to keep current and a way for a real currency to become unrenderable.
82
+ */
83
+ const CURRENCY_CODE = /^[A-Za-z]{3}$/;
84
+ /**
85
+ * The amount as a decimal string, with the point moved `digits` places left.
86
+ *
87
+ * Lexical from end to end. The caller's integer is documented as a safe integer — `minorAmount` refuses
88
+ * anything else and `QuotedMoney` refuses a float — and when that is violated the split produces a string
89
+ * `Intl` renders as `NaN`. That is the intended direction of the failure: loud, and impossible to mistake
90
+ * for a figure, where a rounded or truncated one would be a wrong number nobody notices.
91
+ */
92
+ function decimalOf(amountMinor, digits) {
93
+ const sign = amountMinor < 0 ? "-" : "";
94
+ const magnitude = String(Math.abs(amountMinor));
95
+ if (digits === 0) return `${sign}${magnitude}`;
96
+ const padded = magnitude.padStart(digits + 1, "0");
97
+ const point = padded.length - digits;
98
+ return `${sign}${padded.slice(0, point)}.${padded.slice(point)}`;
99
+ }
100
+ /**
101
+ * `amountMinor` of `currency`, rendered for a reader of `locale` — or `null` when the currency cannot be
102
+ * named.
103
+ *
104
+ * Null rather than a guess, which is the idiom `minorAmount` and `minorUnitsFromScaled` already set in this
105
+ * package: a store that answered `"dollars"` where a currency goes has answered with something no amount can
106
+ * be denominated in, and the caller refuses the whole quote on it rather than letting a `RangeError` out of
107
+ * `Intl` reach a confirmation screen as a 500. A **locale** `Intl` refuses is the other case entirely, and
108
+ * costs the reader only their language — see {@link RENDER_FALLBACK_LOCALE}.
109
+ *
110
+ * `locale` is optional so that a caller with nothing to pass writes nothing, rather than writing `"en"` at
111
+ * a call site and putting the fallback in two places.
112
+ */
113
+ function renderMoney(amountMinor, currency, locale) {
114
+ if (!CURRENCY_CODE.test(currency)) return null;
115
+ const digits = minorUnitDigits(currency);
116
+ return formatter({
117
+ style: "currency",
118
+ currency: currency.toUpperCase(),
119
+ minimumFractionDigits: digits,
120
+ maximumFractionDigits: digits
121
+ }, locale).format(decimalOf(amountMinor, digits));
122
+ }
123
+ /**
124
+ * A formatter for `locale`, or one for {@link RENDER_FALLBACK_LOCALE} when `locale` is not a tag `Intl`
125
+ * accepts.
126
+ *
127
+ * The chain negotiates and canonicalizes every reader-supplied tag before it reaches a route, so the only
128
+ * way an unconstructible one arrives here is an adopter's own configured default. That is a mistake worth
129
+ * surviving rather than raising through a confirmation screen: the fallback keeps the amount readable and
130
+ * the misconfiguration is visible in the language, not in a 500.
131
+ *
132
+ * The fallback formatter cannot throw in turn — the currency was checked before this was called, and
133
+ * `RENDER_FALLBACK_LOCALE` is a constant.
134
+ */
135
+ function formatter(options, locale) {
136
+ if (locale !== void 0 && locale !== "") try {
137
+ return decimalFormatter(locale, options);
138
+ } catch {}
139
+ return decimalFormatter(RENDER_FALLBACK_LOCALE, options);
140
+ }
141
+ /** The one assertion in this module. See {@link DecimalFormatter} for what it asserts and what proves it. */
142
+ function decimalFormatter(locale, options) {
143
+ return new Intl.NumberFormat(locale, options);
144
+ }
145
+ //#endregion
146
+ export { RENDER_FALLBACK_LOCALE, renderMoney };
@@ -0,0 +1,58 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * The normalized purchase status set. Each rail's events map into these nine, so nothing downstream of
4
+ * a rail module ever sees `DID_RENEW`, `SUBSCRIPTION_ON_HOLD`, or `invoice.payment_failed`.
5
+ *
6
+ * The set is deliberately about *state*, not about the event that produced it: a projection is keyed on a
7
+ * transaction, and a transaction has one current state however many notifications described it.
8
+ *
9
+ * ## Two endings, and the difference between them is the money
10
+ *
11
+ * **`expired` is a period we were paid for, ended.** A subscription that ran its course, a Stripe
12
+ * subscription Stripe closed, an Apple period past its `expiresDate`. It grants no access — the period is
13
+ * over — but it **credits**, because the invoice behind it cleared.
14
+ *
15
+ * **`never_paid` is a purchase that terminated before any money moved.** A delayed-payment checkout whose
16
+ * bank debit bounced, a Stripe subscription abandoned at `incomplete_expired`, a Play deferred purchase
17
+ * canceled before payment. It grants nothing and credits nothing, and no clawback ever follows one, because
18
+ * there is no payment to reverse. Leaning on `expired` for these is how a coin pack gets handed out for money
19
+ * that never arrived — see `UNPAID_STATUSES` in `grants/apply.ts`. Apple maps nothing here: StoreKit issues
20
+ * no transaction until the money moves.
21
+ */
22
+ export declare const PurchaseStatus: z.ZodEnum<{
23
+ active: "active";
24
+ canceled: "canceled";
25
+ expired: "expired";
26
+ in_grace: "in_grace";
27
+ never_paid: "never_paid";
28
+ on_hold: "on_hold";
29
+ paused: "paused";
30
+ refunded: "refunded";
31
+ revoked: "revoked";
32
+ }>;
33
+ export type PurchaseStatus = z.infer<typeof PurchaseStatus>;
34
+ /**
35
+ * The statuses a purchase can grant access from — the candidate set the projection's SQL filters on
36
+ * before the expiry check. `in_grace`'s membership is then narrowed per project by
37
+ * {@link statusGrantsAccess}, so this set and that predicate must stay in step; a test asserts both.
38
+ *
39
+ * **`canceled` still grants**, and it is the member most often got wrong. A user who turns off
40
+ * auto-renew has not lost access — they have declined the *next* period. The period they paid for runs
41
+ * to its end, and `expiresAt` is what ends it.
42
+ */
43
+ export declare const ACCESS_GRANTING_STATUSES: ReadonlySet<PurchaseStatus>;
44
+ /**
45
+ * Whether a purchase in this status grants its entitlements, given the project's grace policy. The
46
+ * expiry check is separate and applied alongside it — a status says whether the purchase is still
47
+ * standing, `expiresAt` says whether the period it paid for is over.
48
+ *
49
+ * `in_grace` granting access is the point of grace: a failed card should not lock a paying subscriber
50
+ * out mid-period. It is a described config flag rather than hardcoded policy because an app that sells
51
+ * something expensive may reasonably decide otherwise. `on_hold` never grants — by then the retry window
52
+ * is exhausted and the renewal has genuinely failed. `never_paid` never grants either, and never can: it
53
+ * says no money ever moved.
54
+ */
55
+ export declare function statusGrantsAccess(status: PurchaseStatus, graceGrantsAccess: boolean): boolean;
56
+ /** The statuses that grant access under this project's grace policy — what the projection's SQL filters on. */
57
+ export declare function grantingStatuses(graceGrantsAccess: boolean): PurchaseStatus[];
58
+ //# sourceMappingURL=status.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../../src/data/status.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,cAAc;;;;;;;;;;EAIxB,CAAC;AACJ,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC;AAE5D;;;;;;;;GAQG;AACH,eAAO,MAAM,wBAAwB,EAAE,WAAW,CAAC,cAAc,CAI/D,CAAC;AAEH;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,cAAc,EAAE,iBAAiB,EAAE,OAAO,GAAG,OAAO,CAG9F;AAED,+GAA+G;AAC/G,wBAAgB,gBAAgB,CAAC,iBAAiB,EAAE,OAAO,GAAG,cAAc,EAAE,CAE7E"}