@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,71 @@
1
+ import { PaymentsClawbackFailedError } from "../error/errors.js";
2
+ import { ledgerAccountId } from "./ledgerSeam.js";
3
+ import { ledgerGrantFor } from "./apply.js";
4
+ import { PithyError } from "@pithy-sh/core/src/error/pithyError";
5
+ //#region src/grants/clawback.ts
6
+ /**
7
+ * The refund clawback: taking back what a `grants` clause credited, where — and only where — the catalog says
8
+ * to.
9
+ *
10
+ * **A clawback can fail, and that failure is correct behavior.** The ledger's `CHECK (balance >= 0)` refuses
11
+ * a debit the balance cannot cover, and a player who spent their coins before the refund arrived is exactly
12
+ * that case. There are only three things to do about it and two are wrong: allow a negative balance, which
13
+ * breaks the invariant the ledger exists to hold; write the difference off silently, which leaves nothing
14
+ * anywhere to read; or accept the refusal and record it. This module does the third.
15
+ *
16
+ * So the shape is: the refund is projected and audited **unconditionally** by the caller, the clawback is
17
+ * attempted **only** where `clawback: true`, and a refusal is returned as an outcome rather than thrown.
18
+ * `fulfillPurchase` turns that outcome into a `payments/clawback_failed` audit event at `critical` — a
19
+ * recorded, queryable, alertable state, which is what issue #79 asks for and what an exception could not be.
20
+ *
21
+ * **Off by default**, and that default is the honest one. Clawing back is the exception: the user may well
22
+ * have spent the currency legitimately, and a store's refund decision is not automatically a fraud finding. A
23
+ * project that sells hard currency and has decided otherwise says so per product, in one word.
24
+ */
25
+ /** The statuses that mean this charge came back — the two a clawback answers. */
26
+ const REVERSED_STATUSES = /* @__PURE__ */ new Set(["refunded", "revoked"]);
27
+ /** The ledger's own code for the refusal a clawback is expected to meet. Anything else is unknown, not short. */
28
+ const INSUFFICIENT_FUNDS_CODE = "ledger/insufficient_funds";
29
+ /**
30
+ * The idempotency key for one reversal. Distinct from the grant's by its verb: sharing the grant's ref would
31
+ * make the debit look like a replayed credit, which the ledger swallows as success — so the reversal would
32
+ * report success and move nothing.
33
+ */
34
+ function clawbackRef(purchaseId, currency) {
35
+ return `payments:clawback:${purchaseId}:${currency}`;
36
+ }
37
+ /**
38
+ * Reverse what a refunded purchase credited, if the catalog opted in.
39
+ *
40
+ * Runs on every delivery of the refund, not only the first: the debit is idempotent on its ref, so a
41
+ * redelivery is a no-op and a delivery that arrived after an earlier attempt failed is the repair.
42
+ */
43
+ async function clawbackGrants(ledger, projection, options) {
44
+ const { purchase } = projection;
45
+ const product = options.config.products[purchase.productId];
46
+ const grant = ledgerGrantFor(options.config, purchase.productId);
47
+ if (purchase.role === "state") return [];
48
+ if (grant === void 0 || product?.clawback !== true || !REVERSED_STATUSES.has(purchase.status)) return [];
49
+ const ref = clawbackRef(purchase.id, grant.currency);
50
+ const accountId = ledgerAccountId(purchase);
51
+ try {
52
+ await ledger.debit(accountId, grant.currency, grant.amount, ref, { memo: `payments refund ${purchase.rail} ${purchase.productId}` });
53
+ } catch (cause) {
54
+ if (!(cause instanceof PithyError) || cause.payload.code !== INSUFFICIENT_FUNDS_CODE) throw cause;
55
+ return [{
56
+ outcome: "refused",
57
+ currency: grant.currency,
58
+ amount: grant.amount,
59
+ ref,
60
+ error: new PaymentsClawbackFailedError({ detail: `Reversing ${grant.amount} ${grant.currency} for ${accountId} after the refund of ${purchase.rail} transaction ${purchase.providerTransactionId} exceeds their available balance.` }, { cause })
61
+ }];
62
+ }
63
+ return [{
64
+ outcome: "reversed",
65
+ currency: grant.currency,
66
+ amount: grant.amount,
67
+ ref
68
+ }];
69
+ }
70
+ //#endregion
71
+ export { clawbackGrants, clawbackRef };
@@ -0,0 +1,89 @@
1
+ import type { D1Database } from "@cloudflare/workers-types";
2
+ import { type PaymentsSubject } from "../data/subject";
3
+ /**
4
+ * The single point of contact between `@pithy-sh/payments` and `@pithy-sh/ledger`.
5
+ *
6
+ * The ledger is an **optional peer**: most catalogs sell features, not currency, and a project that never
7
+ * declares a `grants` clause must neither install the package nor pay for it in its Worker bundle. So the
8
+ * import is dynamic and it lives in exactly one file — grep `@pithy-sh/ledger` in this package and you find
9
+ * this line and nothing else. Everything downstream depends on {@link PaymentsLedger}, a structural
10
+ * two-method view, which is also what keeps the grant modules testable without resolving an optional package.
11
+ *
12
+ * **An absent ledger is an error, never a skip.** A catalog with a `grants` clause has told us a purchase
13
+ * credits a balance; quietly not crediting it is a support ticket that arrives weeks later as "I paid and got
14
+ * no coins". The normal place this is caught is far earlier — `payments()`'s `compose` hook refuses at
15
+ * assembly when a `grants` product is composed without the ledger, so a deploy fails rather than a purchase.
16
+ * This throw is the backstop for a caller that reached fulfillment some other way, and it names the fix.
17
+ */
18
+ /**
19
+ * The ledger operations payments performs: one to fulfill a purchase, one to reverse it.
20
+ *
21
+ * A structural subset rather than `@pithy-sh/ledger`'s own `Ledger`, because a type imported from an optional
22
+ * package would put that package on the typecheck path of every module that touches fulfillment. Holds,
23
+ * captures, and transfers are absent because a purchase is not a wager — money arrives from a store and, on a
24
+ * refund, leaves again.
25
+ *
26
+ * The leading parameter is `@pithy-sh/ledger`'s own `userId`, named `accountId` here because payments never
27
+ * hands it one — see {@link ledgerAccountId}.
28
+ */
29
+ export interface PaymentsLedger {
30
+ /** Add funds. Idempotent on `ref`, which is `UNIQUE` across the whole ledger. */
31
+ credit(accountId: string, currency: string, amount: number, ref: string, options?: {
32
+ memo?: string;
33
+ }): Promise<unknown>;
34
+ /** Remove funds. Refuses with `ledger/insufficient_funds` rather than letting a balance go negative. */
35
+ debit(accountId: string, currency: string, amount: number, ref: string, options?: {
36
+ memo?: string;
37
+ }): Promise<unknown>;
38
+ }
39
+ /**
40
+ * The ledger account a subject's balance lives in — **the pair, encoded, and the only derivation of it**.
41
+ *
42
+ * `@pithy-sh/ledger` keys an account on `(userId, currency)`: one flat id namespace, with no column saying
43
+ * what kind of thing the id names. Nothing in the kit keeps a user id and an organization id disjoint — they
44
+ * are minted by different systems, and under `billingSubject: "organization"` the id belongs to a membership
45
+ * model this package knows nothing about. So handing the ledger a bare `subjectId` would let an organization
46
+ * called `acme` and a user called `acme` share one balance: coins the company bought spendable by the person,
47
+ * and a refund of either debiting whatever the other had left.
48
+ *
49
+ * **`@pithy-sh/ledger` is a per-user model, deliberately**, and this function's whole job is to respect that.
50
+ * It keys an account `(userId, currency)`, and every route it serves addresses a user: the authenticated
51
+ * balance read, the `:userId` segment on its management routes, its own seeds. So a user's ledger account id
52
+ * **is** their user id — the identity on `subjectId`, nothing composed.
53
+ *
54
+ * It briefly encoded both halves, and that was a bug rather than a stylistic choice: a grant credited to
55
+ * `user:ada` landed in an account nothing reads. The player's balance stayed empty, the grant was invisible
56
+ * from both sides, and no test in either package could see it, because each package was internally
57
+ * consistent while the two disagreed.
58
+ *
59
+ * **An organization never reaches here.** `checkLedgerGrants` in `capability.ts` refuses a catalog carrying a
60
+ * `grants.ledger` clause under `billingSubject: "organization"`, at assembly — there is no account in a
61
+ * per-user ledger for a company's credit to land in, and inventing one would write a non-user into a column
62
+ * that means user. The throw below is the backstop for a path that composition already closed.
63
+ *
64
+ * **One derivation, called by `apply.ts` and `clawback.ts` alike.** A credit and its clawback must address the
65
+ * identical account or the reversal misses, silently, leaving a refunded buyer holding the currency. Keeping
66
+ * that in one function makes it a property of the code rather than of two edits staying in step.
67
+ */
68
+ export declare function ledgerAccountId(subject: PaymentsSubject): string;
69
+ /** How the ledger module is reached. Injectable so the absent-package path is a test rather than a hope. */
70
+ export type PaymentsLedgerLoader = () => Promise<{
71
+ openLedger: (d1: D1Database, now?: () => number) => PaymentsLedger;
72
+ }>;
73
+ /** What {@link openPaymentsLedger} accepts beyond the binding. */
74
+ export interface OpenPaymentsLedgerOptions {
75
+ /** Override the module loader. Tests only; production always resolves the real package. */
76
+ load?: PaymentsLedgerLoader;
77
+ /** The clock the ledger stamps its rows with. Injected so a fulfillment is deterministic under test. */
78
+ now?: () => number;
79
+ }
80
+ /**
81
+ * Open the ledger against the app database, or explain what is missing.
82
+ *
83
+ * The ledger's tables live in the same D1 as payments' own — both capabilities bind `DB` — so there is no
84
+ * second database to reach and no configuration to resolve. That is also why the two write independently and
85
+ * a credit is idempotent on its `ref` rather than on being in the purchase's transaction: D1 has no
86
+ * cross-statement transaction a caller can hold open across two packages.
87
+ */
88
+ export declare function openPaymentsLedger(d1: D1Database, options?: OpenPaymentsLedgerOptions): Promise<PaymentsLedger>;
89
+ //# sourceMappingURL=ledgerSeam.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ledgerSeam.d.ts","sourceRoot":"","sources":["../../src/grants/ledgerSeam.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAE5D,OAAO,EAA0B,KAAK,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAE/E;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;;;;GAUG;AACH,MAAM,WAAW,cAAc;IAC7B,iFAAiF;IACjF,MAAM,CACJ,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GAC1B,OAAO,CAAC,OAAO,CAAC,CAAC;IACpB,wGAAwG;IACxG,KAAK,CACH,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GAC1B,OAAO,CAAC,OAAO,CAAC,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,eAAe,GAAG,MAAM,CAahE;AAED,4GAA4G;AAC5G,MAAM,MAAM,oBAAoB,GAAG,MAAM,OAAO,CAAC;IAC/C,UAAU,EAAE,CAAC,EAAE,EAAE,UAAU,EAAE,GAAG,CAAC,EAAE,MAAM,MAAM,KAAK,cAAc,CAAC;CACpE,CAAC,CAAC;AAKH,kEAAkE;AAClE,MAAM,WAAW,yBAAyB;IACxC,2FAA2F;IAC3F,IAAI,CAAC,EAAE,oBAAoB,CAAC;IAC5B,wGAAwG;IACxG,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CACpB;AAED;;;;;;;GAOG;AACH,wBAAsB,kBAAkB,CACtC,EAAE,EAAE,UAAU,EACd,OAAO,GAAE,yBAA8B,GACtC,OAAO,CAAC,cAAc,CAAC,CAgBzB"}
@@ -0,0 +1,66 @@
1
+ import { encodeSubjectReference } from "../data/subject.js";
2
+ import { InternalError } from "@pithy-sh/core/src/error/pithyError";
3
+ //#region src/grants/ledgerSeam.ts
4
+ /**
5
+ * The ledger account a subject's balance lives in — **the pair, encoded, and the only derivation of it**.
6
+ *
7
+ * `@pithy-sh/ledger` keys an account on `(userId, currency)`: one flat id namespace, with no column saying
8
+ * what kind of thing the id names. Nothing in the kit keeps a user id and an organization id disjoint — they
9
+ * are minted by different systems, and under `billingSubject: "organization"` the id belongs to a membership
10
+ * model this package knows nothing about. So handing the ledger a bare `subjectId` would let an organization
11
+ * called `acme` and a user called `acme` share one balance: coins the company bought spendable by the person,
12
+ * and a refund of either debiting whatever the other had left.
13
+ *
14
+ * **`@pithy-sh/ledger` is a per-user model, deliberately**, and this function's whole job is to respect that.
15
+ * It keys an account `(userId, currency)`, and every route it serves addresses a user: the authenticated
16
+ * balance read, the `:userId` segment on its management routes, its own seeds. So a user's ledger account id
17
+ * **is** their user id — the identity on `subjectId`, nothing composed.
18
+ *
19
+ * It briefly encoded both halves, and that was a bug rather than a stylistic choice: a grant credited to
20
+ * `user:ada` landed in an account nothing reads. The player's balance stayed empty, the grant was invisible
21
+ * from both sides, and no test in either package could see it, because each package was internally
22
+ * consistent while the two disagreed.
23
+ *
24
+ * **An organization never reaches here.** `checkLedgerGrants` in `capability.ts` refuses a catalog carrying a
25
+ * `grants.ledger` clause under `billingSubject: "organization"`, at assembly — there is no account in a
26
+ * per-user ledger for a company's credit to land in, and inventing one would write a non-user into a column
27
+ * that means user. The throw below is the backstop for a path that composition already closed.
28
+ *
29
+ * **One derivation, called by `apply.ts` and `clawback.ts` alike.** A credit and its clawback must address the
30
+ * identical account or the reversal misses, silently, leaving a refunded buyer holding the currency. Keeping
31
+ * that in one function makes it a property of the code rather than of two edits staying in step.
32
+ */
33
+ function ledgerAccountId(subject) {
34
+ if (subject.subjectType !== "user") throw new InternalError({
35
+ message: "A balance cannot be credited to an organization.",
36
+ action: "Set `billingSubject: \"user\"`, or drop the `grants` clause from the products that credit one.",
37
+ detail: `@pithy-sh/ledger keys every account on a user id. Refused an account for ${encodeSubjectReference(subject)}.`
38
+ });
39
+ return subject.subjectId;
40
+ }
41
+ /** The real loader — the only `@pithy-sh/ledger` import in the package. */
42
+ const loadLedgerModule = () => import("@pithy-sh/ledger/src/ledger");
43
+ /**
44
+ * Open the ledger against the app database, or explain what is missing.
45
+ *
46
+ * The ledger's tables live in the same D1 as payments' own — both capabilities bind `DB` — so there is no
47
+ * second database to reach and no configuration to resolve. That is also why the two write independently and
48
+ * a credit is idempotent on its `ref` rather than on being in the purchase's transaction: D1 has no
49
+ * cross-statement transaction a caller can hold open across two packages.
50
+ */
51
+ async function openPaymentsLedger(d1, options = {}) {
52
+ const load = options.load ?? loadLedgerModule;
53
+ let module;
54
+ try {
55
+ module = await load();
56
+ } catch (cause) {
57
+ throw new InternalError({
58
+ message: "This purchase credits a balance, and the ledger is not installed.",
59
+ action: "Install @pithy-sh/ledger and compose ledger(...), or drop the `grants` clause from the product.",
60
+ detail: `Loading @pithy-sh/ledger failed: ${cause instanceof Error ? cause.message : String(cause)}`
61
+ }, { cause });
62
+ }
63
+ return module.openLedger(d1, options.now);
64
+ }
65
+ //#endregion
66
+ export { ledgerAccountId, openPaymentsLedger };
@@ -0,0 +1,35 @@
1
+ import type { Logger } from "@pithy-sh/core/src/logger/logger";
2
+ import { type PaymentsReconcileParams } from "../workflows/specs";
3
+ /**
4
+ * Starting a reconciliation pass from inside a Worker.
5
+ *
6
+ * **One dispatch path, three callers.** The cron in the host worker, an on-demand pass for a single holder,
7
+ * and anything a later surface adds all route through {@link triggerWorkflow} — so a scheduled run and a
8
+ * manual one validate their parameters identically, resolve the binding identically, and log an absent
9
+ * binding identically. Calling `env.PAYMENTS_RECONCILE.create()` directly would skip all three: a mistyped
10
+ * payload would surface as a failed step inside a running instance rather than at the call site, and an
11
+ * unprovisioned project would silently do nothing.
12
+ *
13
+ * **What is handed over is a payload, and that is why a holder is the pair.** `triggerWorkflow` parses
14
+ * `params` through `PaymentsReconcileParams` before it touches the binding, so a narrowing missing half its
15
+ * subject is refused here — where the caller is still on the stack — rather than inside an instance that
16
+ * would otherwise start, scan the wrong rows, and report them as the account somebody asked about. Nothing
17
+ * callable crosses: the instance runs with no subject seam at all, which `workflows/worker.ts` explains.
18
+ *
19
+ * **An absent binding is a logged skip, not a failure.** The job is declared `optional`, because the Workflow
20
+ * lives in the prebuilt reconcile worker and that worker exists only once `pithy payments provision` has run.
21
+ * A support request that cannot start a pass yet must not become a 500 on a route that otherwise works.
22
+ *
23
+ * It lives under `http/` because the on-demand caller is a request handler — support reconciling one holder.
24
+ * The host worker's cron uses the identical function, which is the point: there is one way to start this job.
25
+ */
26
+ /** The dispatch key for the reconciliation pass. Built from core's key builder, never spelled out. */
27
+ export declare const PAYMENTS_RECONCILE_KEY: string;
28
+ /**
29
+ * Start a reconciliation pass.
30
+ *
31
+ * `env` is the raw Worker env rather than a typed binding, because that is what `triggerWorkflow` reads the
32
+ * binding off — and taking the binding itself would let a caller pass one the registry never validated.
33
+ */
34
+ export declare function triggerPaymentsReconcile(env: Record<string, unknown>, params?: PaymentsReconcileParams, log?: Logger): Promise<void>;
35
+ //# sourceMappingURL=dispatch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dispatch.d.ts","sourceRoot":"","sources":["../../src/http/dispatch.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAC;AAG/D,OAAO,EAAuB,KAAK,uBAAuB,EAA4B,MAAM,oBAAoB,CAAC;AAEjH;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,sGAAsG;AACtG,eAAO,MAAM,sBAAsB,QAAgD,CAAC;AAEpF;;;;;GAKG;AACH,wBAAsB,wBAAwB,CAC5C,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,MAAM,GAAE,uBAA4B,EACpC,GAAG,CAAC,EAAE,MAAM,GACX,OAAO,CAAC,IAAI,CAAC,CAEf"}
@@ -0,0 +1,40 @@
1
+ import { PAYMENTS_CAPABILITY, paymentsWorkflowRegistry } from "../workflows/specs.js";
2
+ import { triggerWorkflow } from "@pithy-sh/core/src/workflow/dispatch";
3
+ import { workflowKey } from "@pithy-sh/core/src/workflow/naming";
4
+ //#region src/http/dispatch.ts
5
+ /**
6
+ * Starting a reconciliation pass from inside a Worker.
7
+ *
8
+ * **One dispatch path, three callers.** The cron in the host worker, an on-demand pass for a single holder,
9
+ * and anything a later surface adds all route through {@link triggerWorkflow} — so a scheduled run and a
10
+ * manual one validate their parameters identically, resolve the binding identically, and log an absent
11
+ * binding identically. Calling `env.PAYMENTS_RECONCILE.create()` directly would skip all three: a mistyped
12
+ * payload would surface as a failed step inside a running instance rather than at the call site, and an
13
+ * unprovisioned project would silently do nothing.
14
+ *
15
+ * **What is handed over is a payload, and that is why a holder is the pair.** `triggerWorkflow` parses
16
+ * `params` through `PaymentsReconcileParams` before it touches the binding, so a narrowing missing half its
17
+ * subject is refused here — where the caller is still on the stack — rather than inside an instance that
18
+ * would otherwise start, scan the wrong rows, and report them as the account somebody asked about. Nothing
19
+ * callable crosses: the instance runs with no subject seam at all, which `workflows/worker.ts` explains.
20
+ *
21
+ * **An absent binding is a logged skip, not a failure.** The job is declared `optional`, because the Workflow
22
+ * lives in the prebuilt reconcile worker and that worker exists only once `pithy payments provision` has run.
23
+ * A support request that cannot start a pass yet must not become a 500 on a route that otherwise works.
24
+ *
25
+ * It lives under `http/` because the on-demand caller is a request handler — support reconciling one holder.
26
+ * The host worker's cron uses the identical function, which is the point: there is one way to start this job.
27
+ */
28
+ /** The dispatch key for the reconciliation pass. Built from core's key builder, never spelled out. */
29
+ const PAYMENTS_RECONCILE_KEY = workflowKey(PAYMENTS_CAPABILITY, "reconcile");
30
+ /**
31
+ * Start a reconciliation pass.
32
+ *
33
+ * `env` is the raw Worker env rather than a typed binding, because that is what `triggerWorkflow` reads the
34
+ * binding off — and taking the binding itself would let a caller pass one the registry never validated.
35
+ */
36
+ async function triggerPaymentsReconcile(env, params = {}, log) {
37
+ await triggerWorkflow(env, paymentsWorkflowRegistry, PAYMENTS_RECONCILE_KEY, params, log);
38
+ }
39
+ //#endregion
40
+ export { PAYMENTS_RECONCILE_KEY, triggerPaymentsReconcile };
@@ -0,0 +1,43 @@
1
+ import type { PithyHonoEnv } from "@pithy-sh/core/src/capability/capability";
2
+ import type { MiddlewareHandler } from "hono";
3
+ /**
4
+ * The payments routes' identity gates: the one middleware payments owns.
5
+ *
6
+ * **The scope constants moved to `./scopes`** (#315). A management client reads them to render what a
7
+ * connection may do, and it reads them in a browser — so they cannot live in a module that imports
8
+ * Hono middleware and `PithyHonoEnv`. The gates stayed here; the names they demand are next door, and
9
+ * the routes import both.
10
+ *
11
+ * ## `requireAuth` is copied, not imported
12
+ *
13
+ * These three lines are the same three `@pithy-sh/storage`, `@pithy-sh/media`, and `@pithy-sh/ledger` each
14
+ * carry, and the duplication is deliberate. Importing the gate from `@pithy-sh/auth` would make auth a hard
15
+ * dependency, and a package that *imports its authorization from another package fails open when that package
16
+ * is absent*. Depending on the core `AuthContext` seam instead means `c.var.auth` is simply `null` with no
17
+ * auth capability composed, and every route denies. Failing closed is not a side effect of the copy; it is the
18
+ * reason for it. So `dependsOn` stays free of auth and the manifest lists it under `optionalCapabilities`.
19
+ *
20
+ * ## The control-plane gate is core's, and payments contributes only the scope names
21
+ *
22
+ * `requireControlPlane` lives in `@pithy-sh/core/src/controlPlane/http/guard` and the two admin routes wear it
23
+ * directly. Payments verifies nothing itself: a management call arrives as an EdDSA-signed compact JWS on the
24
+ * `pithy-control-plane` header, and the seam checks the signature against a public key the **adopter**
25
+ * registered, the connection it addresses, that connection's environment, the token's lifetime, a digest of
26
+ * the body, and the token's single use — none of which a capability could re-implement per package without
27
+ * five subtly different answers to the same question.
28
+ *
29
+ * **This is not the opposite of the rule above; it is the same rule.** The rule is never to import
30
+ * authorization from a package that might be absent. `@pithy-sh/auth` is optional, so its gate is copied.
31
+ * `@pithy-sh/core` is a hard dependency of every capability there is, so importing its gate cannot leave a
32
+ * deployment without one — and when the *seam* is not composed the imported gate raises
33
+ * `controlplane/not_connected` rather than passing. Both halves fail closed; only the mechanism differs.
34
+ *
35
+ * **`requireAuth()` must never sit on those two routes.** A management client is not a user of the adopter's
36
+ * app: it holds no session, owns no user row, and the seam deliberately leaves `c.var.auth` null so that a
37
+ * control-plane credential cannot satisfy an ordinary `requireAuth()` anywhere in the tree. An auth gate on an
38
+ * admin route would therefore deny every legitimate management call, permanently, and no credential could fix
39
+ * it. The gate that replaced the interim one is the whole verification strategy, not half of it.
40
+ */
41
+ /** Require an authenticated caller (the core AuthContext seam). */
42
+ export declare function requireAuth(): MiddlewareHandler<PithyHonoEnv>;
43
+ //# sourceMappingURL=guards.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guards.d.ts","sourceRoot":"","sources":["../../src/http/guards.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;AAE7E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AAE9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,mEAAmE;AACnE,wBAAgB,WAAW,IAAI,iBAAiB,CAAC,YAAY,CAAC,CAU7D"}
@@ -0,0 +1,52 @@
1
+ import { UnauthorizedError } from "@pithy-sh/core/src/error/pithyError";
2
+ //#region src/http/guards.ts
3
+ /**
4
+ * The payments routes' identity gates: the one middleware payments owns.
5
+ *
6
+ * **The scope constants moved to `./scopes`** (#315). A management client reads them to render what a
7
+ * connection may do, and it reads them in a browser — so they cannot live in a module that imports
8
+ * Hono middleware and `PithyHonoEnv`. The gates stayed here; the names they demand are next door, and
9
+ * the routes import both.
10
+ *
11
+ * ## `requireAuth` is copied, not imported
12
+ *
13
+ * These three lines are the same three `@pithy-sh/storage`, `@pithy-sh/media`, and `@pithy-sh/ledger` each
14
+ * carry, and the duplication is deliberate. Importing the gate from `@pithy-sh/auth` would make auth a hard
15
+ * dependency, and a package that *imports its authorization from another package fails open when that package
16
+ * is absent*. Depending on the core `AuthContext` seam instead means `c.var.auth` is simply `null` with no
17
+ * auth capability composed, and every route denies. Failing closed is not a side effect of the copy; it is the
18
+ * reason for it. So `dependsOn` stays free of auth and the manifest lists it under `optionalCapabilities`.
19
+ *
20
+ * ## The control-plane gate is core's, and payments contributes only the scope names
21
+ *
22
+ * `requireControlPlane` lives in `@pithy-sh/core/src/controlPlane/http/guard` and the two admin routes wear it
23
+ * directly. Payments verifies nothing itself: a management call arrives as an EdDSA-signed compact JWS on the
24
+ * `pithy-control-plane` header, and the seam checks the signature against a public key the **adopter**
25
+ * registered, the connection it addresses, that connection's environment, the token's lifetime, a digest of
26
+ * the body, and the token's single use — none of which a capability could re-implement per package without
27
+ * five subtly different answers to the same question.
28
+ *
29
+ * **This is not the opposite of the rule above; it is the same rule.** The rule is never to import
30
+ * authorization from a package that might be absent. `@pithy-sh/auth` is optional, so its gate is copied.
31
+ * `@pithy-sh/core` is a hard dependency of every capability there is, so importing its gate cannot leave a
32
+ * deployment without one — and when the *seam* is not composed the imported gate raises
33
+ * `controlplane/not_connected` rather than passing. Both halves fail closed; only the mechanism differs.
34
+ *
35
+ * **`requireAuth()` must never sit on those two routes.** A management client is not a user of the adopter's
36
+ * app: it holds no session, owns no user row, and the seam deliberately leaves `c.var.auth` null so that a
37
+ * control-plane credential cannot satisfy an ordinary `requireAuth()` anywhere in the tree. An auth gate on an
38
+ * admin route would therefore deny every legitimate management call, permanently, and no credential could fix
39
+ * it. The gate that replaced the interim one is the whole verification strategy, not half of it.
40
+ */
41
+ /** Require an authenticated caller (the core AuthContext seam). */
42
+ function requireAuth() {
43
+ return async (c, next) => {
44
+ if (!c.var.auth) throw new UnauthorizedError({
45
+ message: "Authentication required.",
46
+ action: "Sign in and retry with a valid session or bearer token."
47
+ });
48
+ await next();
49
+ };
50
+ }
51
+ //#endregion
52
+ export { requireAuth };
@@ -0,0 +1,38 @@
1
+ import type { CapabilityManifestConfig } from "@pithy-sh/core/src/controlPlane/discovery/configuration";
2
+ import { PaymentsSubjectType } from "../data/subject";
3
+ /**
4
+ * The configured fact payments states into `GET /control-plane/manifest` (#422).
5
+ *
6
+ * **A management client cannot write a grant without it.** `POST {base}/entitlements/grant` names the
7
+ * holder and never assumes it, which is right — the two kinds are different rows and different gates.
8
+ * But `PaymentsConfig.billingSubject` is required with no default, so there is nothing a client may
9
+ * safely assume either: guessing `user` against an organization-billed project writes a row nothing
10
+ * reads, the call succeeds, and the person still cannot use what somebody just gave them.
11
+ *
12
+ * Nothing else on the wire answers it. `GET {base}/admin/catalog` returns products.
13
+ * `PaymentsClientProjection` leaves it out deliberately and is a browser bundle besides. And
14
+ * `GET {base}/admin/entitlements` carries a `subjectType` per *row* — evidence about who happens to hold
15
+ * something, not a statement about what the project bills. An empty table says nothing, and a project
16
+ * that migrated has both kinds in it.
17
+ *
18
+ * **Its own module rather than a block in `scopes.ts`.** That module declares nine `ControlPlaneScope`
19
+ * constants and `tooling/browser-scopes/src/coverage.test.ts` holds every such module to type-only
20
+ * imports, so a scope name compiles in a browser program with no Workers types. This needs
21
+ * `defineManifestConfig` and `PaymentsSubjectType` as values, which is exactly what that gate refuses —
22
+ * so the two live apart rather than the gate being weakened.
23
+ */
24
+ /** The key the fact appears under. The join key a management client reads it back by. */
25
+ export declare const PAYMENTS_BILLING_SUBJECT = "billingSubject";
26
+ /**
27
+ * What this project bills, stated for a client that has to name a holder.
28
+ *
29
+ * **Takes the resolved value rather than reading config itself**, for the same reason
30
+ * `paymentsAdminRoutes` takes the resolved `basePath`: a declaration built from defaults describes a
31
+ * Worker other than this one, and nothing downstream compares the two — a manifest that drifts from the
32
+ * capability is worse than no manifest, because a client believes it.
33
+ *
34
+ * `choices` is read off {@link PaymentsSubjectType} rather than retyped. A third kind of holder is a
35
+ * change to that enum, and reading it here is what makes the manifest learn about it in the same commit.
36
+ */
37
+ export declare function paymentsManifestConfig(billingSubject: PaymentsSubjectType): CapabilityManifestConfig;
38
+ //# sourceMappingURL=manifestConfig.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manifestConfig.d.ts","sourceRoot":"","sources":["../../src/http/manifestConfig.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,yDAAyD,CAAC;AAExG,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtD;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,yFAAyF;AACzF,eAAO,MAAM,wBAAwB,mBAAmB,CAAC;AAEzD;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,CAAC,cAAc,EAAE,mBAAmB,GAAG,wBAAwB,CAYpG"}
@@ -0,0 +1,49 @@
1
+ import { PaymentsSubjectType } from "../data/subject.js";
2
+ import { defineManifestConfig } from "@pithy-sh/core/src/controlPlane/discovery/configuration";
3
+ //#region src/http/manifestConfig.ts
4
+ /**
5
+ * The configured fact payments states into `GET /control-plane/manifest` (#422).
6
+ *
7
+ * **A management client cannot write a grant without it.** `POST {base}/entitlements/grant` names the
8
+ * holder and never assumes it, which is right — the two kinds are different rows and different gates.
9
+ * But `PaymentsConfig.billingSubject` is required with no default, so there is nothing a client may
10
+ * safely assume either: guessing `user` against an organization-billed project writes a row nothing
11
+ * reads, the call succeeds, and the person still cannot use what somebody just gave them.
12
+ *
13
+ * Nothing else on the wire answers it. `GET {base}/admin/catalog` returns products.
14
+ * `PaymentsClientProjection` leaves it out deliberately and is a browser bundle besides. And
15
+ * `GET {base}/admin/entitlements` carries a `subjectType` per *row* — evidence about who happens to hold
16
+ * something, not a statement about what the project bills. An empty table says nothing, and a project
17
+ * that migrated has both kinds in it.
18
+ *
19
+ * **Its own module rather than a block in `scopes.ts`.** That module declares nine `ControlPlaneScope`
20
+ * constants and `tooling/browser-scopes/src/coverage.test.ts` holds every such module to type-only
21
+ * imports, so a scope name compiles in a browser program with no Workers types. This needs
22
+ * `defineManifestConfig` and `PaymentsSubjectType` as values, which is exactly what that gate refuses —
23
+ * so the two live apart rather than the gate being weakened.
24
+ */
25
+ /** The key the fact appears under. The join key a management client reads it back by. */
26
+ const PAYMENTS_BILLING_SUBJECT = "billingSubject";
27
+ /**
28
+ * What this project bills, stated for a client that has to name a holder.
29
+ *
30
+ * **Takes the resolved value rather than reading config itself**, for the same reason
31
+ * `paymentsAdminRoutes` takes the resolved `basePath`: a declaration built from defaults describes a
32
+ * Worker other than this one, and nothing downstream compares the two — a manifest that drifts from the
33
+ * capability is worse than no manifest, because a client believes it.
34
+ *
35
+ * `choices` is read off {@link PaymentsSubjectType} rather than retyped. A third kind of holder is a
36
+ * change to that enum, and reading it here is what makes the manifest learn about it in the same commit.
37
+ */
38
+ function paymentsManifestConfig(billingSubject) {
39
+ return defineManifestConfig({
40
+ keys: [{
41
+ key: PAYMENTS_BILLING_SUBJECT,
42
+ choices: [...PaymentsSubjectType.options],
43
+ summary: "What kind of thing holds a purchase in this project — one person, or one organization. Every entitlement this project grants names a subject of this kind, so a client must state it rather than guess it."
44
+ }],
45
+ values: { [PAYMENTS_BILLING_SUBJECT]: billingSubject }
46
+ });
47
+ }
48
+ //#endregion
49
+ export { PAYMENTS_BILLING_SUBJECT, paymentsManifestConfig };