@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,240 @@
1
+ //#region src/http/scopes.ts
2
+ /**
3
+ * Payments' control-plane scopes, and the admin surface a manifest advertises.
4
+ *
5
+ * **Separate from `guards.ts` because a scope name is a client's business** (#315). A management
6
+ * client reads these to render what a connection may do, and `pithy-sh/dashboard`'s scope builder
7
+ * writes the `pithy dashboard connect --scope …` command from exactly these constants — in a browser
8
+ * program, with the DOM lib and no Workers types. While they sat beside the Hono middleware, naming
9
+ * one compiled `PithyHonoEnv`, which reached core's `capability.ts`, which named Worker globals that
10
+ * program has none of. **This module imports types and nothing else, and a gate holds it there**:
11
+ * `tooling/browser-scopes` compiles a DOM-only program against every scope the kit declares.
12
+ *
13
+ * ## Two scopes, not one admin flag
14
+ *
15
+ * The interim gate checked a single `payments:admin` scope on the `AuthContext`. That string is a valid
16
+ * {@link ControlPlaneScope} — it matches the seam's pattern, so nothing forced this change — but it names a
17
+ * *credential holder*, and the seam's scopes name *operations*. Under that model one flag is wrong on the
18
+ * merits: granting and revoking an entitlement are two operations with different blast radii and different
19
+ * holders. **Grant** mints paid product out of nothing, so a compromised comp tool costs revenue and can
20
+ * escalate itself into anything the catalog sells. **Revoke** takes paid access away from a live customer, so
21
+ * a compromised refund tool is an outage for people who paid. A refund tool needs revoke and never grant; a
22
+ * support-comp tool needs grant and never revoke. One flag makes each of them the other, and an adopter who
23
+ * wanted to hand out only the safer half had no way to say so.
24
+ *
25
+ * The split is real rather than cosmetic because `scopeCovers` matches exactly, with no prefix or wildcard
26
+ * rule: `payments:entitlements` confers neither of these, and holding one confers nothing about the other.
27
+ *
28
+ * The names are constants rather than config, for the reason the old comment gave and which has not changed: a
29
+ * configurable scope name is a way to misconfigure a default-denied gate into a differently-named one, and
30
+ * support tooling that read the docs would then quietly hold a scope nothing checks. They are also the join
31
+ * key with what `pithy dashboard connect` offers an adopter to grant, so they must be the same strings in both
32
+ * places.
33
+ */
34
+ /**
35
+ * Minting a discount — an administrative act with a cost attached, and its own scope for that reason.
36
+ *
37
+ * Deliberately not covered by, and not covering, the entitlement grants. Comping somebody an entitlement and
38
+ * creating a code that reduces what everybody who holds it pays are different powers with different blast
39
+ * radii, and a tool that needs one must not acquire the other. `scopeCovers` matches exactly.
40
+ */
41
+ const PAYMENTS_DISCOUNT_CREATE_SCOPE = "payments:discounts:create";
42
+ /**
43
+ * Reading the codes this project has issued.
44
+ *
45
+ * Separate from creating one, and strictly narrower: a pane that lists what was minted does not need the
46
+ * power to mint. The read exists because the write does — a management client that can create a code and
47
+ * never see it leaves a pane computing *absent* rather than blocked, which no grant repairs (#247).
48
+ */
49
+ const PAYMENTS_DISCOUNT_READ_SCOPE = "payments:discounts:read";
50
+ /**
51
+ * Write an entitlement nobody paid for — a comp, or the repair of a purchase that verified and never
52
+ * projected. The more dangerous of the two: a connection holding this can give any account anything the
53
+ * catalog sells.
54
+ */
55
+ const PAYMENTS_ENTITLEMENT_GRANT_SCOPE = "payments:entitlements:grant";
56
+ /**
57
+ * Take an entitlement back — a chargeback, an abuse decision, a comp withdrawn. Effective on the account's
58
+ * next request, which is exactly why it is granted separately from the ability to hand one out.
59
+ */
60
+ const PAYMENTS_ENTITLEMENT_REVOKE_SCOPE = "payments:entitlements:revoke";
61
+ /**
62
+ * Read the purchase log — every verified provider transaction, across every account.
63
+ *
64
+ * Strictly more disclosure than {@link PAYMENTS_SUBSCRIPTIONS_READ_SCOPE}, which is why the two are
65
+ * separate: a renewal monitor needs to know who is still paying and when their period ends, and has no
66
+ * business reading what everybody ever bought. Neither read reaches a stored provider payload.
67
+ */
68
+ const PAYMENTS_PURCHASES_READ_SCOPE = "payments:purchases:read";
69
+ /**
70
+ * Read the purchases that renew — the same rows as the purchase log, narrowed to `type: subscription`.
71
+ *
72
+ * The narrower of the two grants, and the one a renewal or churn tool should hold on its own. Holding it
73
+ * confers nothing about the rest of the log: `scopeCovers` matches exactly, with no prefix rule.
74
+ */
75
+ const PAYMENTS_SUBSCRIPTIONS_READ_SCOPE = "payments:subscriptions:read";
76
+ /**
77
+ * Read the entitlement model — what accounts hold, whether it grants right now, and where it came from.
78
+ *
79
+ * **The read that had to exist for grant and revoke to be honest.** Payments shipped both writes with no
80
+ * read beside them, so a management client could comp an entitlement and take one back while never being
81
+ * able to list one; a console that cannot see what it changed is asking an operator to act blind. It is
82
+ * still granted separately, because seeing what every account is entitled to and deciding what they are
83
+ * entitled to are different operations with different blast radii.
84
+ */
85
+ const PAYMENTS_ENTITLEMENTS_READ_SCOPE = "payments:entitlements:read";
86
+ /**
87
+ * Read what this project **sells** — each product's id, type, display name, and the entitlement keys it
88
+ * grants. Not what anybody bought.
89
+ *
90
+ * **Its own scope, and the reason is that the two disclosures are unrelated.** Every other read here is a
91
+ * page of the adopter's customers: who paid, what they hold, when it lapses. This one names no account and
92
+ * no transaction, and would read identically against a database with no rows in it. A tool that populates a
93
+ * "comp this person an entitlement" list needs exactly this and nothing else, and it should be able to hold
94
+ * exactly this and nothing else — a dropdown is not a reason to hand a client the purchase log.
95
+ *
96
+ * The converse matters as much and is why it is not folded into {@link PAYMENTS_ENTITLEMENTS_READ_SCOPE}: a
97
+ * catalog is a commercial fact — every tier a company sells and every feature it gates — and a connection
98
+ * granted the entitlement model should not acquire it by implication. `scopeCovers` matches exactly, so
99
+ * neither scope confers the other.
100
+ */
101
+ const PAYMENTS_CATALOG_READ_SCOPE = "payments:catalog:read";
102
+ /**
103
+ * Read what **reconciliation** did — the log of passes, their tallies, and when they last ran.
104
+ *
105
+ * Its own scope because it is operational state rather than anybody's commerce. A run record names no
106
+ * account, no transaction and no amount; it says whether the compensating control for a delivery mechanism
107
+ * that is known to fail has been firing, and how much it had to repair. An adopter should be able to give a
108
+ * health monitor exactly that and nothing else — a "has the cron stopped" alarm has no business holding the
109
+ * purchase log, and `scopeCovers` matches exactly, so neither confers the other.
110
+ */
111
+ const PAYMENTS_RECONCILE_READ_SCOPE = "payments:reconcile:read";
112
+ /**
113
+ * Start a reconciliation pass now.
114
+ *
115
+ * **Separate from the read, and it is the sharpest split in this list.** Reading the run log says whether the
116
+ * nightly repair has been firing; starting one calls the store, walks the catalog, and *writes entitlements* —
117
+ * granting what a dropped webhook never granted and revoking what a missed cancellation left standing. The
118
+ * health monitor that holds `:read` to alarm on a stopped cron must not be able to move somebody's access, and
119
+ * `scopeCovers` matches exactly, so it cannot.
120
+ *
121
+ * **A trigger exists because the cron is not enough.** `pithy payments reconcile` runs the same pass, and it
122
+ * needs a laptop, a checkout, and a Cloudflare API token for the project — so the answer to "my subscription
123
+ * isn't showing up" at 4pm on a Saturday is either this route or nothing until 04:00 UTC. Adopted from
124
+ * `pithy-sh/dashboard#96`, where the operator with the run log open had no way to act on it.
125
+ *
126
+ * Idempotent by construction, so the scope carries no warning about pressing twice: `reconcilePayments` finds
127
+ * a reconciled catalog already matching and writes nothing.
128
+ */
129
+ const PAYMENTS_RECONCILE_RUN_SCOPE = "payments:reconcile:run";
130
+ /**
131
+ * Every control-plane scope payments defines — what `pithy dashboard connect` offers for this capability, and
132
+ * the list a manifest or a doc quotes rather than re-typing. Core's `SEAM_SCOPES` is the same idea for the
133
+ * seam's own routes.
134
+ *
135
+ * Reads first, writes after, because that is the order an adopter should read them in: the reads are the
136
+ * grant most connections want and the smallest one that makes a dashboard useful.
137
+ */
138
+ const PAYMENTS_CONTROL_PLANE_SCOPES = [
139
+ PAYMENTS_CATALOG_READ_SCOPE,
140
+ PAYMENTS_PURCHASES_READ_SCOPE,
141
+ PAYMENTS_SUBSCRIPTIONS_READ_SCOPE,
142
+ PAYMENTS_ENTITLEMENTS_READ_SCOPE,
143
+ PAYMENTS_DISCOUNT_READ_SCOPE,
144
+ PAYMENTS_RECONCILE_READ_SCOPE,
145
+ PAYMENTS_ENTITLEMENT_GRANT_SCOPE,
146
+ PAYMENTS_ENTITLEMENT_REVOKE_SCOPE,
147
+ PAYMENTS_DISCOUNT_CREATE_SCOPE,
148
+ PAYMENTS_RECONCILE_RUN_SCOPE
149
+ ];
150
+ /**
151
+ * Payments' management surface, as `GET /control-plane/manifest` reports it.
152
+ *
153
+ * Declared beside the scopes rather than in `routes.ts` so the scope a route demands and the scope a
154
+ * manifest advertises are the same constant, read from one place. `basePath` is a parameter and never a
155
+ * default: an adopter who mounted payments at `/billing` must get a manifest naming
156
+ * `/billing/entitlements/grant`, or a management client composing its calls from it would 404 against
157
+ * exactly the adopters who customized anything.
158
+ *
159
+ * The summaries say what the operation *is for*, not what it does mechanically. A client renders these
160
+ * next to a button somebody is about to press on a paying customer's account.
161
+ *
162
+ * **Everything sits under an `admin/` segment.** The player surface already owns `${basePath}/purchases`
163
+ * and `${basePath}/entitlements`, and the second of those is a `GET` — so a management read mounted at
164
+ * the bare path would either collide outright or sit behind whichever of the two Hono matched first, with
165
+ * a route's gate decided by registration order. The extra segment makes the two sets disjoint by
166
+ * construction rather than by luck. It also keeps the reads at the shape a management client looks for: a
167
+ * `GET`, with a declared scope, no `:` segment, ending in the resource's own noun.
168
+ */
169
+ function paymentsAdminRoutes(basePath) {
170
+ return [
171
+ {
172
+ method: "GET",
173
+ path: `${basePath}/admin/catalog`,
174
+ scope: PAYMENTS_CATALOG_READ_SCOPE,
175
+ summary: "What this project sells — each product's id, kind, display name, and the entitlement keys it grants. The list a comp control fills its dropdown from."
176
+ },
177
+ {
178
+ method: "GET",
179
+ path: `${basePath}/admin/purchases`,
180
+ scope: PAYMENTS_PURCHASES_READ_SCOPE,
181
+ summary: "Page the purchase log — every verified transaction, newest first, filtered by holder (both halves of the subject), store, status or store environment."
182
+ },
183
+ {
184
+ method: "GET",
185
+ path: `${basePath}/admin/subscriptions`,
186
+ scope: PAYMENTS_SUBSCRIPTIONS_READ_SCOPE,
187
+ summary: "Page the purchases that renew — who is still paying, and when the period they paid for ends."
188
+ },
189
+ {
190
+ method: "GET",
191
+ path: `${basePath}/admin/entitlements`,
192
+ scope: PAYMENTS_ENTITLEMENTS_READ_SCOPE,
193
+ summary: "Page what accounts hold — whether each entitlement grants right now, and which purchase is the reason."
194
+ },
195
+ {
196
+ method: "GET",
197
+ path: `${basePath}/admin/entitlements/:subjectType/:subjectId`,
198
+ scope: PAYMENTS_ENTITLEMENTS_READ_SCOPE,
199
+ summary: "Everything one subject is entitled to, resolved now — addressed by both halves, `user`/`organization` and the id. The answer to “why can this person not use what they paid for”."
200
+ },
201
+ {
202
+ method: "GET",
203
+ path: `${basePath}/admin/discounts`,
204
+ scope: PAYMENTS_DISCOUNT_READ_SCOPE,
205
+ summary: "The discount codes this project has issued, read from the store that holds them."
206
+ },
207
+ {
208
+ method: "POST",
209
+ path: `${basePath}/admin/discounts`,
210
+ scope: PAYMENTS_DISCOUNT_CREATE_SCOPE,
211
+ summary: "Mint a discount code at one store, from terms stated in the units a customer experiences."
212
+ },
213
+ {
214
+ method: "GET",
215
+ path: `${basePath}/admin/reconcile-runs`,
216
+ scope: PAYMENTS_RECONCILE_READ_SCOPE,
217
+ summary: "The reconciliation passes this deployment has run — when each ran, what it compared, and what it had to repair. The answer to whether the nightly repair is still firing."
218
+ },
219
+ {
220
+ method: "POST",
221
+ path: `${basePath}/admin/reconcile-runs`,
222
+ scope: PAYMENTS_RECONCILE_RUN_SCOPE,
223
+ summary: "Start a reconciliation pass now, rather than waiting for the nightly one. The repair path for a purchase a dropped webhook never projected."
224
+ },
225
+ {
226
+ method: "POST",
227
+ path: `${basePath}/entitlements/grant`,
228
+ scope: PAYMENTS_ENTITLEMENT_GRANT_SCOPE,
229
+ summary: "Comp an entitlement, or repair a purchase that verified but never projected."
230
+ },
231
+ {
232
+ method: "POST",
233
+ path: `${basePath}/entitlements/revoke`,
234
+ scope: PAYMENTS_ENTITLEMENT_REVOKE_SCOPE,
235
+ summary: "Take an entitlement back, effective immediately."
236
+ }
237
+ ];
238
+ }
239
+ //#endregion
240
+ export { PAYMENTS_CATALOG_READ_SCOPE, PAYMENTS_CONTROL_PLANE_SCOPES, PAYMENTS_DISCOUNT_CREATE_SCOPE, PAYMENTS_DISCOUNT_READ_SCOPE, PAYMENTS_ENTITLEMENTS_READ_SCOPE, PAYMENTS_ENTITLEMENT_GRANT_SCOPE, PAYMENTS_ENTITLEMENT_REVOKE_SCOPE, PAYMENTS_PURCHASES_READ_SCOPE, PAYMENTS_RECONCILE_READ_SCOPE, PAYMENTS_RECONCILE_RUN_SCOPE, PAYMENTS_SUBSCRIPTIONS_READ_SCOPE, paymentsAdminRoutes };
@@ -0,0 +1,96 @@
1
+ import type { PaymentsPurchaseRecord } from "../admin/read";
2
+ import type { PaymentsConfig } from "../config/config";
3
+ import type { PaymentsEntitlement } from "../data/entitlement";
4
+ import type { PaymentsReconcileRun } from "../data/reconcileRun";
5
+ import type { PurchaseProjection } from "../projection/writer";
6
+ import type { PaymentsAdminCatalogResponse, PaymentsAdminEntitlementView, PaymentsAdminPurchaseView, PaymentsAdminReconcileRunView, PaymentsEntitlementView, PaymentsPurchaseView } from "./responses";
7
+ /**
8
+ * What a client is shown. Nothing in this package ever returns a raw row.
9
+ *
10
+ * ## What payments holds, and therefore what this can leak
11
+ *
12
+ * There is exactly one column across all four tables that is personal data in the ordinary sense, and it
13
+ * is `pithy_payments_purchases.payload` — the verified provider response, retained as received. On Apple
14
+ * and Google it is a bearer artifact. On Stripe it is a document carrying the buyer's email address,
15
+ * their name, and their billing details. So the question `@pithy-sh/email` answers by masking a
16
+ * recipient has a different answer here, and a stronger one: **the payload is not masked, it is not
17
+ * projected, and the management queries do not select it** (`admin/read.ts`). A field that never reaches
18
+ * the Worker's memory cannot reach a response.
19
+ *
20
+ * Everything else payments stores is an identifier or a fact about a transaction. The only identity is the
21
+ * **subject pair**, `(subjectType, subjectId)` — opaque ids the adopter's auth capability and its own
22
+ * membership model issued, and already the address a management client must name to ask about a holder.
23
+ * Turning either into a name or an address needs `auth:users:read`, which is a separate grant against a
24
+ * separate capability.
25
+ *
26
+ * The two halves are projected together or not at all. A view carrying `subjectId` alone would read as a
27
+ * person whenever an adopter's organization ids and user ids met on a value, so the management
28
+ * projections below copy the pair off one row and never assemble one from config and a column.
29
+ *
30
+ * ## The two audiences, and why their projections differ
31
+ *
32
+ * {@link purchaseView} and {@link entitlementView} answer the adopter's own app, over `requireAuth()`,
33
+ * always about the caller's own rows. {@link adminPurchaseView} and {@link adminEntitlementView} answer a
34
+ * management client, over the control-plane seam, about everybody's. The management views are wider by
35
+ * the facts an operator cannot work without — who owns it, what was charged, whether a human granted it,
36
+ * and which purchase is the reason — and narrower by `outcome`, which describes a write and has no
37
+ * meaning on a read. The client views name no subject at all: the caller is the holder, and a body
38
+ * echoing that back would be the protocol offering a field a client could one day fill in.
39
+ *
40
+ * ## The field lists live in `responses.ts`
41
+ *
42
+ * Every return type below is `z.output` of the Zod object there, so there is one declaration of what a
43
+ * client receives rather than an interface here and a hand-written mirror of it in every management
44
+ * client. A field added to one and not the other does not compile.
45
+ *
46
+ * Dates render as ISO-8601 strings. They are ms-epoch integers in SQLite and `Date`s in TypeScript, and
47
+ * a JSON number would leave every client guessing which unit it was in.
48
+ */
49
+ /**
50
+ * A purchase as its own buyer may see it — the projection a write hands back.
51
+ *
52
+ * Deliberately not the row: the stored `payload` is the whole provider response, and a client has no use
53
+ * for its own receipt read back to it.
54
+ */
55
+ export declare function purchaseView(projection: PurchaseProjection): PaymentsPurchaseView;
56
+ /** An entitlement as its holder reads it: the key, whether it grants right now, and when it lapses. */
57
+ export declare function entitlementView(entitlement: {
58
+ key: string;
59
+ active: boolean;
60
+ expiresAt: Date | null;
61
+ }): PaymentsEntitlementView;
62
+ /**
63
+ * Project the catalog for a management client — what this project sells, and nothing about who bought it.
64
+ *
65
+ * The one projection in this file built from **config** rather than from a row, and that is the whole
66
+ * reason it is safe: the value it reads is `pithy.config.ts`, so a credential, a stored payload, and a
67
+ * customer's identity are not merely withheld here, they are not in the input. What *is* in the input and
68
+ * must not cross is the commercial half of the catalog — every rail's SKU, the Stripe price id, and the
69
+ * `grants` block's currency and amount — and the four fields below are the whole of what does.
70
+ *
71
+ * `{ enabled: false }` when the project defines nothing, matching `clientProjection`'s answer for the same
72
+ * state and for the same reason: a client branches on `enabled`, so "composed with nothing to sell" must
73
+ * read as its own state rather than as an empty list that looks like a failed load.
74
+ */
75
+ export declare function adminCatalogView(config: PaymentsConfig): PaymentsAdminCatalogResponse;
76
+ /** Project one purchase for a management client. The record's columns, verbatim, with dates as strings. */
77
+ export declare function adminPurchaseView(purchase: PaymentsPurchaseRecord): PaymentsAdminPurchaseView;
78
+ /**
79
+ * Project one entitlement row for a management client, resolving `granted` against `now`.
80
+ *
81
+ * The stored `active` flag is what the projection last wrote; `expiresAt` is the truth. A subscription
82
+ * can lapse with no notification arriving at all, so a row can say `active` with an expiry in the past —
83
+ * and the gate the adopter's own app calls applies the timestamp on every request. A dashboard that
84
+ * rendered the flag would disagree with that gate, and the customer would believe the dashboard.
85
+ */
86
+ export declare function adminEntitlementView(row: PaymentsEntitlement, now: Date): PaymentsAdminEntitlementView;
87
+ /**
88
+ * Project one reconciliation run for a management client.
89
+ *
90
+ * The row's columns verbatim, with the dates as ISO strings and `createdAt` left behind — when the row was
91
+ * *written* is bookkeeping, and `finishedAt` already answers the only version of that question an operator
92
+ * asks. Nothing is withheld beyond it, because there is nothing to withhold: the table has no column a
93
+ * store's response could reach.
94
+ */
95
+ export declare function adminReconcileRunView(run: PaymentsReconcileRun): PaymentsAdminReconcileRunView;
96
+ //# sourceMappingURL=view.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"view.d.ts","sourceRoot":"","sources":["../../src/http/view.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,KAAK,EACV,4BAA4B,EAC5B,4BAA4B,EAC5B,yBAAyB,EACzB,6BAA6B,EAC7B,uBAAuB,EACvB,oBAAoB,EACrB,MAAM,aAAa,CAAC;AAErB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AAEH;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,UAAU,EAAE,kBAAkB,GAAG,oBAAoB,CAcjF;AAED,uGAAuG;AACvG,wBAAgB,eAAe,CAAC,WAAW,EAAE;IAC3C,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,OAAO,CAAC;IAChB,SAAS,EAAE,IAAI,GAAG,IAAI,CAAC;CACxB,GAAG,uBAAuB,CAE1B;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,cAAc,GAAG,4BAA4B,CAYrF;AAED,2GAA2G;AAC3G,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,sBAAsB,GAAG,yBAAyB,CAoB7F;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,mBAAmB,EAAE,GAAG,EAAE,IAAI,GAAG,4BAA4B,CAWtG;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,oBAAoB,GAAG,6BAA6B,CAiB9F"}
@@ -0,0 +1,170 @@
1
+ //#region src/http/view.ts
2
+ /**
3
+ * What a client is shown. Nothing in this package ever returns a raw row.
4
+ *
5
+ * ## What payments holds, and therefore what this can leak
6
+ *
7
+ * There is exactly one column across all four tables that is personal data in the ordinary sense, and it
8
+ * is `pithy_payments_purchases.payload` — the verified provider response, retained as received. On Apple
9
+ * and Google it is a bearer artifact. On Stripe it is a document carrying the buyer's email address,
10
+ * their name, and their billing details. So the question `@pithy-sh/email` answers by masking a
11
+ * recipient has a different answer here, and a stronger one: **the payload is not masked, it is not
12
+ * projected, and the management queries do not select it** (`admin/read.ts`). A field that never reaches
13
+ * the Worker's memory cannot reach a response.
14
+ *
15
+ * Everything else payments stores is an identifier or a fact about a transaction. The only identity is the
16
+ * **subject pair**, `(subjectType, subjectId)` — opaque ids the adopter's auth capability and its own
17
+ * membership model issued, and already the address a management client must name to ask about a holder.
18
+ * Turning either into a name or an address needs `auth:users:read`, which is a separate grant against a
19
+ * separate capability.
20
+ *
21
+ * The two halves are projected together or not at all. A view carrying `subjectId` alone would read as a
22
+ * person whenever an adopter's organization ids and user ids met on a value, so the management
23
+ * projections below copy the pair off one row and never assemble one from config and a column.
24
+ *
25
+ * ## The two audiences, and why their projections differ
26
+ *
27
+ * {@link purchaseView} and {@link entitlementView} answer the adopter's own app, over `requireAuth()`,
28
+ * always about the caller's own rows. {@link adminPurchaseView} and {@link adminEntitlementView} answer a
29
+ * management client, over the control-plane seam, about everybody's. The management views are wider by
30
+ * the facts an operator cannot work without — who owns it, what was charged, whether a human granted it,
31
+ * and which purchase is the reason — and narrower by `outcome`, which describes a write and has no
32
+ * meaning on a read. The client views name no subject at all: the caller is the holder, and a body
33
+ * echoing that back would be the protocol offering a field a client could one day fill in.
34
+ *
35
+ * ## The field lists live in `responses.ts`
36
+ *
37
+ * Every return type below is `z.output` of the Zod object there, so there is one declaration of what a
38
+ * client receives rather than an interface here and a hand-written mirror of it in every management
39
+ * client. A field added to one and not the other does not compile.
40
+ *
41
+ * Dates render as ISO-8601 strings. They are ms-epoch integers in SQLite and `Date`s in TypeScript, and
42
+ * a JSON number would leave every client guessing which unit it was in.
43
+ */
44
+ /**
45
+ * A purchase as its own buyer may see it — the projection a write hands back.
46
+ *
47
+ * Deliberately not the row: the stored `payload` is the whole provider response, and a client has no use
48
+ * for its own receipt read back to it.
49
+ */
50
+ function purchaseView(projection) {
51
+ const { purchase } = projection;
52
+ return {
53
+ id: purchase.id,
54
+ rail: purchase.rail,
55
+ productId: purchase.productId,
56
+ type: purchase.type,
57
+ status: purchase.status,
58
+ environment: purchase.environment,
59
+ purchasedAt: purchase.purchasedAt.toISOString(),
60
+ expiresAt: purchase.expiresAt?.toISOString() ?? null,
61
+ resumesAt: purchase.resumesAt?.toISOString() ?? null,
62
+ outcome: projection.outcome
63
+ };
64
+ }
65
+ /** An entitlement as its holder reads it: the key, whether it grants right now, and when it lapses. */
66
+ function entitlementView(entitlement) {
67
+ return {
68
+ key: entitlement.key,
69
+ granted: entitlement.active,
70
+ expiresAt: entitlement.expiresAt?.toISOString() ?? null
71
+ };
72
+ }
73
+ /**
74
+ * Project the catalog for a management client — what this project sells, and nothing about who bought it.
75
+ *
76
+ * The one projection in this file built from **config** rather than from a row, and that is the whole
77
+ * reason it is safe: the value it reads is `pithy.config.ts`, so a credential, a stored payload, and a
78
+ * customer's identity are not merely withheld here, they are not in the input. What *is* in the input and
79
+ * must not cross is the commercial half of the catalog — every rail's SKU, the Stripe price id, and the
80
+ * `grants` block's currency and amount — and the four fields below are the whole of what does.
81
+ *
82
+ * `{ enabled: false }` when the project defines nothing, matching `clientProjection`'s answer for the same
83
+ * state and for the same reason: a client branches on `enabled`, so "composed with nothing to sell" must
84
+ * read as its own state rather than as an empty list that looks like a failed load.
85
+ */
86
+ function adminCatalogView(config) {
87
+ const products = Object.entries(config.products).map(([id, product]) => ({
88
+ id,
89
+ type: product.type,
90
+ name: product.name,
91
+ entitlements: [...product.entitlements]
92
+ }));
93
+ const manualEntitlements = [...config.manualEntitlements];
94
+ if (products.length === 0 && manualEntitlements.length === 0) return { enabled: false };
95
+ return {
96
+ enabled: true,
97
+ products,
98
+ manualEntitlements
99
+ };
100
+ }
101
+ /** Project one purchase for a management client. The record's columns, verbatim, with dates as strings. */
102
+ function adminPurchaseView(purchase) {
103
+ return {
104
+ id: purchase.id,
105
+ subjectType: purchase.subjectType,
106
+ subjectId: purchase.subjectId,
107
+ rail: purchase.rail,
108
+ providerTransactionId: purchase.providerTransactionId,
109
+ originalTransactionId: purchase.originalTransactionId,
110
+ productId: purchase.productId,
111
+ type: purchase.type,
112
+ status: purchase.status,
113
+ environment: purchase.environment,
114
+ amountMinor: purchase.amountMinor,
115
+ currency: purchase.currency,
116
+ purchasedAt: purchase.purchasedAt.toISOString(),
117
+ expiresAt: purchase.expiresAt?.toISOString() ?? null,
118
+ revokedAt: purchase.revokedAt?.toISOString() ?? null,
119
+ resumesAt: purchase.resumesAt?.toISOString() ?? null,
120
+ updatedAt: purchase.updatedAt.toISOString()
121
+ };
122
+ }
123
+ /**
124
+ * Project one entitlement row for a management client, resolving `granted` against `now`.
125
+ *
126
+ * The stored `active` flag is what the projection last wrote; `expiresAt` is the truth. A subscription
127
+ * can lapse with no notification arriving at all, so a row can say `active` with an expiry in the past —
128
+ * and the gate the adopter's own app calls applies the timestamp on every request. A dashboard that
129
+ * rendered the flag would disagree with that gate, and the customer would believe the dashboard.
130
+ */
131
+ function adminEntitlementView(row, now) {
132
+ const lapsed = row.expiresAt !== null && row.expiresAt.getTime() <= now.getTime();
133
+ return {
134
+ subjectType: row.subjectType,
135
+ subjectId: row.subjectId,
136
+ key: row.entitlement,
137
+ granted: row.active && !lapsed,
138
+ expiresAt: row.expiresAt?.toISOString() ?? null,
139
+ manual: row.manual,
140
+ source: row.sourcePurchaseId
141
+ };
142
+ }
143
+ /**
144
+ * Project one reconciliation run for a management client.
145
+ *
146
+ * The row's columns verbatim, with the dates as ISO strings and `createdAt` left behind — when the row was
147
+ * *written* is bookkeeping, and `finishedAt` already answers the only version of that question an operator
148
+ * asks. Nothing is withheld beyond it, because there is nothing to withhold: the table has no column a
149
+ * store's response could reach.
150
+ */
151
+ function adminReconcileRunView(run) {
152
+ return {
153
+ id: run.id,
154
+ startedAt: run.startedAt.toISOString(),
155
+ finishedAt: run.finishedAt.toISOString(),
156
+ environment: run.environment,
157
+ rail: run.rail,
158
+ pages: run.pages,
159
+ scanned: run.scanned,
160
+ unchanged: run.unchanged,
161
+ drifted: run.drifted,
162
+ superseded: run.superseded,
163
+ skipped: run.skipped,
164
+ failed: run.failed,
165
+ truncated: run.truncated,
166
+ dryRun: run.dryRun
167
+ };
168
+ }
169
+ //#endregion
170
+ export { adminCatalogView, adminEntitlementView, adminPurchaseView, adminReconcileRunView, entitlementView, purchaseView };
@@ -0,0 +1,109 @@
1
+ import type { D1Database } from "@cloudflare/workers-types";
2
+ import type { PithyHonoEnv } from "@pithy-sh/core/src/capability/capability";
3
+ import type { Context, MiddlewareHandler } from "hono";
4
+ import type { PaymentsConfig } from "../config/config";
5
+ import type { PaymentsRail } from "../data/rail";
6
+ import type { VerifiedNotification } from "../rails/contract";
7
+ import { type RailTrustOptions } from "../rails/providers";
8
+ /** A verified delivery, as the handler receives it: the notification, and the row recording it. */
9
+ export interface VerifiedWebhook {
10
+ /** Which rail delivered it. */
11
+ rail: PaymentsRail;
12
+ /** The verified, parsed notification. `event` is null when it reports no transaction state. */
13
+ notification: VerifiedNotification;
14
+ /** The `pithy_payments_webhook_events` row id, so the handler can mark it processed or failed. */
15
+ eventRowId: string;
16
+ }
17
+ /**
18
+ * The verified delivery for this request. Throws when the gate did not run, because a handler reading an
19
+ * absent verification would be a handler processing an unverified notification.
20
+ */
21
+ export declare function verifiedWebhook(c: Context<PithyHonoEnv>): VerifiedWebhook;
22
+ /** What the guard needs beyond the request: the catalog, and an injectable clock. */
23
+ export interface WebhookGuardOptions {
24
+ /** The resolved catalog. Decides whether the rail is enabled at all. */
25
+ config: PaymentsConfig;
26
+ /** The clock, for signature freshness and `receivedAt`. Injected so tests are deterministic. */
27
+ now?: () => Date;
28
+ /** Additional certificate roots, additive only. Absent in production. */
29
+ trust?: RailTrustOptions;
30
+ }
31
+ /**
32
+ * Verify, record, and de-duplicate one rail's notification.
33
+ *
34
+ * Every failure to establish authenticity becomes `payments/webhook_unverified` (401), whatever the rail threw
35
+ * underneath. The rails distinguish malformed from unverified for the client-submission path, where the
36
+ * distinction helps a developer; on a webhook it would only tell a forger how close it got. The original code
37
+ * rides in `detail`, which the HTTP codec strips.
38
+ *
39
+ * **Two codes pass through unchanged, because they are not the caller's failure.** A rail that cannot reach its
40
+ * store (`payments/provider_unavailable`) or cannot use its own credentials (`payments/rail_not_configured`) has
41
+ * not judged the delivery at all — Google's rail must call the Play Developer API to resolve a notification, and
42
+ * an outage there is ours, not the sender's. Reporting either as a failed signature would send an operator
43
+ * hunting for a rotated key while the real answer is in a status page, and would tell the audit trail a forgery
44
+ * arrived when none did. Both remain non-2xx, so the provider still redelivers.
45
+ */
46
+ export declare function requireSignedWebhook(rail: PaymentsRail, options: WebhookGuardOptions): MiddlewareHandler<PithyHonoEnv>;
47
+ /**
48
+ * What became of a verified delivery, as the handler reports it. **Three cases, because there are three.**
49
+ *
50
+ * `{ at }` — it projected. Finished.
51
+ *
52
+ * `{ at, note }` — it was never going to project, and here is why. The rail read the notification and said
53
+ * it carries no transaction state: a partial refund that takes nothing away, a token Play will not show us
54
+ * — its rail's own words are "the answer will not change" — a subscription Lemon Squeezy no longer knows, a
55
+ * type the store shipped after this package did. Also finished. **A later delivery of the same bytes gets
56
+ * the same answer from the same build**, so the note is an explanation attached to a finished row, not a
57
+ * failure.
58
+ *
59
+ * `{ at, error }` — it arrived carrying a purchase and did not project, and a later attempt still could.
60
+ * The orphan whose account link has not arrived, the void naming a purchase not yet submitted, the SKU not
61
+ * yet in the catalog. `processedAt` stays null so the redelivery, the replay, or the sweep runs it again.
62
+ *
63
+ * **Why `note` and `error` are separate when both land in the same column.** #337 made the presence of a
64
+ * reason the discriminant, which split one state in two: a delivery with nothing to project was finished
65
+ * when the rail said nothing about it, and outstanding when the rail explained why. The *explanation* was
66
+ * the only difference, and an explanation must not be able to change a state.
67
+ *
68
+ * What that cost is the two things this column is read for. A null `processedAt` under an old `receivedAt`
69
+ * is this table's documented drift signal, and every explained delivery became one permanently. And the
70
+ * short-circuit is what makes a retry storm cost one insert instead of a projection — four of the five
71
+ * rails have no repair pass at all, so those rows never settled, and each of the store's retries ran the
72
+ * whole handler again.
73
+ *
74
+ * The three are a union rather than two optional fields so no call site can pass both and no reader has to
75
+ * decide what a row means that claims to be finished and failed at once. That contradiction was #337.
76
+ */
77
+ export type WebhookCompletion = {
78
+ readonly at: Date;
79
+ } | {
80
+ readonly at: Date;
81
+ readonly note: string;
82
+ } | {
83
+ readonly at: Date;
84
+ readonly error: string;
85
+ };
86
+ /**
87
+ * Mark a recorded notification finished, or record why it is not.
88
+ *
89
+ * The outcome decides whether `processedAt` is written at all — see {@link WebhookCompletion}. Only the
90
+ * repairable case withholds it, and withholding it is what keeps the row reprocessable: the guard's
91
+ * short-circuit and the Paddle sweep's freshness check both read that column.
92
+ *
93
+ * That reverses what this function did before #337. Setting the timestamp beside an error read as "the
94
+ * notification *was* handled" — but the guard short-circuits on that column, so it also meant a failed
95
+ * delivery could never be repaired: the provider's retry was answered 200, a manual replay reuses the same
96
+ * event id and was answered 200, and the sweep skipped it. Nothing in this package repaired a failed
97
+ * delivery, on any rail. #339 is the other edge of the same cut: the fix withheld the timestamp from
98
+ * deliveries that had nothing to repair, and made a repair pass chase them.
99
+ *
100
+ * **`abandonedAt` is never touched here.** It belongs to the repair pass that wrote it, and a webhook that
101
+ * projects one of those rows sets `processedAt` — which wins, so the event reads finished while the row
102
+ * still records that a sweep once gave up on it.
103
+ *
104
+ * A genuine D1 failure propagates rather than being swallowed, and that is the right direction: the store
105
+ * would answer a 5xx by retrying, the projection is idempotent, and an unmarked row would otherwise leave a
106
+ * notification looking permanently unprocessed.
107
+ */
108
+ export declare function completeWebhook(d1: D1Database, eventRowId: string, outcome: WebhookCompletion): Promise<void>;
109
+ //# sourceMappingURL=webhookGuard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhookGuard.d.ts","sourceRoot":"","sources":["../../src/http/webhookGuard.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;AAM7E,OAAO,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AAEvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAIjD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EAAE,KAAK,gBAAgB,EAAuB,MAAM,oBAAoB,CAAC;AAoEhF,mGAAmG;AACnG,MAAM,WAAW,eAAe;IAC9B,+BAA+B;IAC/B,IAAI,EAAE,YAAY,CAAC;IACnB,+FAA+F;IAC/F,YAAY,EAAE,oBAAoB,CAAC;IACnC,kGAAkG;IAClG,UAAU,EAAE,MAAM,CAAC;CACpB;AAQD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,eAAe,CAQzE;AAED,qFAAqF;AACrF,MAAM,WAAW,mBAAmB;IAClC,wEAAwE;IACxE,MAAM,EAAE,cAAc,CAAC;IACvB,gGAAgG;IAChG,GAAG,CAAC,EAAE,MAAM,IAAI,CAAC;IACjB,yEAAyE;IACzE,KAAK,CAAC,EAAE,gBAAgB,CAAC;CAC1B;AAeD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,YAAY,EAClB,OAAO,EAAE,mBAAmB,GAC3B,iBAAiB,CAAC,YAAY,CAAC,CA6GjC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,MAAM,iBAAiB,GACzB;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAA;CAAE,GACrB;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC5C;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAElD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,eAAe,CAAC,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAenH"}