@pithy-sh/payments 0.1.2 → 0.1.4

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,35 @@
1
+ import type { ControlPlaneScope } from "@pithy-sh/core/src/controlPlane/scope/scope";
2
+ import type { PaymentsTables } from "../data/tables";
3
+ /**
4
+ * What a management client may learn from each table payments owns.
5
+ *
6
+ * **This is a decision, taken once, where the tables are.** Issue #247 was not a missing route so much
7
+ * as a missing question: payments stored a customer's whole purchase history and their entitlement read
8
+ * model, shipped two control-plane writes against the second, and nobody ever asked whether a management
9
+ * client could *see* either. Three panes in the first adopter computed `absent` and dropped out of the
10
+ * rail. Absent, not blocked — no grant restores a route that does not exist.
11
+ *
12
+ * So every table declares which side of the line it is on, and the type is
13
+ * `Record<keyof PaymentsTables, …>` rather than a partial map: **a sixth table does not compile until
14
+ * somebody decides what a management client may see of it.** That is the structural half of the gate.
15
+ * `coverage.test.ts` is the other half — it checks that a table declaring a read has a control-plane
16
+ * `GET` demanding exactly that scope, and that every resource this capability can *write* it can also
17
+ * read.
18
+ *
19
+ * A withheld table states its reason here rather than in a test's exclusion list, because the reason is
20
+ * a property of the table and belongs next to it. Neither reason below is "no pane asked for it".
21
+ */
22
+ /** One table's disclosure decision: the reads that return its rows, or why there are none. */
23
+ export type PaymentsDisclosure = {
24
+ /**
25
+ * Every control-plane scope that returns rows from this table. Non-empty by construction, so
26
+ * "readable" cannot degrade into "readable by nothing" through an edit.
27
+ */
28
+ readonly reads: readonly [ControlPlaneScope, ...ControlPlaneScope[]];
29
+ } | {
30
+ /** Why no management client may read this table. A property of the table, not an exemption. */
31
+ readonly withheld: string;
32
+ };
33
+ /** Every payments table, and what a management client may learn from it. */
34
+ export declare const PAYMENTS_TABLE_DISCLOSURE: Record<keyof PaymentsTables, PaymentsDisclosure>;
35
+ //# sourceMappingURL=coverage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"coverage.d.ts","sourceRoot":"","sources":["../../src/admin/coverage.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,6CAA6C,CAAC;AACrF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAQrD;;;;;;;;;;;;;;;;;;GAkBG;AAEH,8FAA8F;AAC9F,MAAM,MAAM,kBAAkB,GAC1B;IACE;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC,iBAAiB,EAAE,GAAG,iBAAiB,EAAE,CAAC,CAAC;CACtE,GACD;IACE,+FAA+F;IAC/F,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEN,4EAA4E;AAC5E,eAAO,MAAM,yBAAyB,EAAE,MAAM,CAAC,MAAM,cAAc,EAAE,kBAAkB,CA2DtF,CAAC"}
@@ -0,0 +1,56 @@
1
+ import { PAYMENTS_ENTITLEMENTS_READ_SCOPE, PAYMENTS_PURCHASES_READ_SCOPE, PAYMENTS_RECONCILE_READ_SCOPE, PAYMENTS_SUBSCRIPTIONS_READ_SCOPE } from "../http/scopes.js";
2
+ //#region src/admin/coverage.ts
3
+ /** Every payments table, and what a management client may learn from it. */
4
+ const PAYMENTS_TABLE_DISCLOSURE = {
5
+ /**
6
+ * The purchase log, read two ways. `payments:purchases:read` is the whole projection of provider
7
+ * truth; `payments:subscriptions:read` is the same rows narrowed to the ones that renew, so a tool
8
+ * watching renewals can be granted the forward-looking half without the customer's entire order
9
+ * history. Neither read ever selects `payload` — see `read.ts`.
10
+ */
11
+ pithyPaymentsPurchases: { reads: [PAYMENTS_PURCHASES_READ_SCOPE, PAYMENTS_SUBSCRIPTIONS_READ_SCOPE] },
12
+ /** The entitlement read model — what a subject holds right now, and why. */
13
+ pithyPaymentsEntitlements: { reads: [PAYMENTS_ENTITLEMENTS_READ_SCOPE] },
14
+ /**
15
+ * Withheld, and the argument is stronger now that the far side is a subject rather than a user. Every row
16
+ * is a *provider-side* identity — `cus_PithyAda`, an Apple `appAccountToken` — paired with the subject
17
+ * that holds it: a Pithy user, or an organization whose id came out of the adopter's own membership
18
+ * model. Listing it in bulk hands a management client a cross-reference from a store account to the
19
+ * adopter's internal id space, and under organization billing that maps a company to its billing
20
+ * identity at every store it sells through.
21
+ *
22
+ * There is nothing an operator can do with the page that a purchase does not already answer: a purchase
23
+ * names its own subject and its own rail. The one legitimate question it settles — "which Stripe customer
24
+ * is this holder" — belongs to a route that answers it for one named subject, if it is ever wanted, and
25
+ * not to a page of a thousand of them.
26
+ */
27
+ pithyPaymentsProviderAccounts: { withheld: "Every row pairs a provider-side account identifier with a subject — a Pithy user, or an organization from the adopter's own membership model. In bulk that is a cross-reference from a store's id space into the adopter's, and nothing on this surface needs it: a purchase already names its subject and its rail." },
28
+ /**
29
+ * Withheld. Each row holds the raw verified provider notification exactly as it arrived, and that
30
+ * payload is a bearer artifact — the same thing `responses.ts` refuses to put on a purchase view, for
31
+ * the same reason. There is no projection of a delivery log worth a read scope either: what an operator
32
+ * wants from it is "why did this purchase not update", and that question is answered by the purchase's
33
+ * own status and the audit trail's `payments/webhook_received` events, neither of which is a receipt.
34
+ */
35
+ pithyPaymentsWebhookEvents: { withheld: "Each row is a raw verified provider payload — a bearer artifact. The question a delivery log is read for is answered by the purchase's status and the audit trail, without handing anyone a receipt." },
36
+ /**
37
+ * The reconciliation run log — operational state, on its own scope.
38
+ *
39
+ * Readable, and readable *separately*, because it is the one table here that is not about a customer. A
40
+ * run names no account, no transaction and no amount; it says whether the compensating control for a
41
+ * delivery mechanism that is known to fail has been firing. A health monitor should be able to hold
42
+ * exactly this, and an adopter granting it should not thereby disclose what anybody bought.
43
+ */
44
+ pithyPaymentsReconcileRuns: { reads: [PAYMENTS_RECONCILE_READ_SCOPE] },
45
+ /**
46
+ * Withheld. One opaque resume token per stream, and nothing else — no amount, no customer, no event.
47
+ *
48
+ * Withheld because there is nothing here a management client could act on and one thing it could break:
49
+ * a pane that could read a cursor invites a pane that could write one, and a cursor moved forward skips
50
+ * every event between the old value and the new, silently and unrepairably. The sweep's own state is
51
+ * the sweep's; what it *found* is in the purchases and webhook-event tables, which are readable.
52
+ */
53
+ pithyPaymentsSyncCursors: { withheld: "A sweep's resume token is internal bookkeeping, not a fact about a customer. Reading it answers nothing a management client asks, and the write it invites would silently skip every event between two cursor values." }
54
+ };
55
+ //#endregion
56
+ export { PAYMENTS_TABLE_DISCLOSURE };
@@ -0,0 +1,222 @@
1
+ import type { D1Database } from "@cloudflare/workers-types";
2
+ import type { z } from "zod";
3
+ import { PaymentsEntitlement } from "../data/entitlement";
4
+ import { type PurchaseEnvironment } from "../data/purchase";
5
+ import type { PaymentsRail } from "../data/rail";
6
+ import { PaymentsReconcileRun } from "../data/reconcileRun";
7
+ import type { PurchaseStatus } from "../data/status";
8
+ import type { PaymentsSubject } from "../data/subject";
9
+ /**
10
+ * The management read model — the queries behind the control-plane reads, and nothing else.
11
+ *
12
+ * **It lives beside the projection rather than inside it.** Everything in `projection/` writes or reads
13
+ * one subject's own rows; these read across *every* subject, which is a different operation with a
14
+ * different blast radius. Keeping it out of the projection means no in-process caller reaches it by
15
+ * accident, and it is the same arrangement `@pithy-sh/ledger`'s `admin/read.ts` makes for the same
16
+ * reason.
17
+ *
18
+ * ## The payload is not projected, and it is not selected either
19
+ *
20
+ * `pithy_payments_purchases.payload` is the whole verified provider response: a bearer artifact on Apple
21
+ * and Google, and on Stripe a document carrying the buyer's email address, name and billing details.
22
+ * Every query below names its columns, and that column is not among them — so the receipt does not reach
23
+ * the Worker's memory on a management read at all, let alone the response. A projection that dropped it
24
+ * afterwards would be one refactor away from leaking it; a `SELECT` that never asks for it is not.
25
+ *
26
+ * That is also the honest answer to the masking question `@pithy-sh/email` answers by masking a
27
+ * recipient. Payments stores **no** direct personal identifier of its own — the only identity on either
28
+ * table is the **subject pair**, `(subjectType, subjectId)`, opaque ids the adopter's auth capability and
29
+ * the adopter's own membership model issued, and already the address a management client must name to ask
30
+ * about a holder. The single field that would have carried an email address into a purchases list is
31
+ * `payload`, and the control is stronger than a mask: it is never read.
32
+ *
33
+ * ## A subject filter is the pair or it is nothing
34
+ *
35
+ * Every query below takes its owner filter as one {@link PaymentsSubject}, never as a loose id. Nothing in
36
+ * the kit keeps an organization id from equalling some user's id, so a `WHERE subject_id = ?` alone would
37
+ * hand a management client asking about a person the rows of an organization that happens to share the id.
38
+ * The object is what makes the two halves inseparable at every call site — `data/subject.ts` states the
39
+ * argument once.
40
+ *
41
+ * ## Keyset, never offset
42
+ *
43
+ * Every listing pages on `(sort, id)` descending through core's shared cursor helper. `OFFSET` shifts
44
+ * under a reader whenever a row is inserted, and a purchase table is written to by three paths at once —
45
+ * a client submission, three providers' webhooks, and the nightly reconciliation pass. A page 2 fetched
46
+ * a second later would repeat rows it already showed and skip rows it never did.
47
+ *
48
+ * The primary key here is a **text UUID**, deliberately (sequential ids would leak order volume), so it
49
+ * is no use as a sort: it is unique but it is not monotonic. Purchases therefore sort on `purchasedAt`
50
+ * with the id as the tiebreak, and entitlements on `createdAt` with the same. Both columns are indexed
51
+ * for exactly this by `payments_0001_purchases` — without those indexes a purchases pane would sort a
52
+ * customer's entire order history on every page load.
53
+ */
54
+ /** One page of a keyset listing, and where the next one resumes. */
55
+ export interface PaymentsPage<T> {
56
+ /** The rows, newest first. */
57
+ items: T[];
58
+ /** The cursor for the next page, or null at the end of the list. Opaque; hand it back verbatim. */
59
+ nextCursor: string | null;
60
+ }
61
+ /**
62
+ * A purchase as a management read sees it — every column but the stored provider payload, the provider
63
+ * SKU, and the bookkeeping timestamps the projection keeps for itself.
64
+ *
65
+ * Derived from {@link PaymentsPurchase} with `.pick`, never restated, so the row schema stays the one
66
+ * definition of the table and the codecs still decode dates on the way out of D1. `providerProductId`
67
+ * is left behind because `productId` and `rail` already name what was bought and the SKU is the
68
+ * adopter's own config; `providerEventAt` and `createdAt` because they describe when *we* processed
69
+ * something, which is a question for the audit trail rather than for a purchases pane.
70
+ */
71
+ export declare const PaymentsPurchaseRecord: z.ZodObject<{
72
+ id: z.ZodString;
73
+ subjectType: z.ZodEnum<{
74
+ organization: "organization";
75
+ user: "user";
76
+ }>;
77
+ subjectId: z.ZodString;
78
+ rail: z.ZodEnum<{
79
+ apple: "apple";
80
+ google: "google";
81
+ lemonSqueezy: "lemonSqueezy";
82
+ paddle: "paddle";
83
+ stripe: "stripe";
84
+ }>;
85
+ providerTransactionId: z.ZodString;
86
+ productId: z.ZodString;
87
+ type: z.ZodEnum<{
88
+ consumable: "consumable";
89
+ non_consumable: "non_consumable";
90
+ subscription: "subscription";
91
+ }>;
92
+ status: z.ZodEnum<{
93
+ active: "active";
94
+ canceled: "canceled";
95
+ expired: "expired";
96
+ in_grace: "in_grace";
97
+ never_paid: "never_paid";
98
+ on_hold: "on_hold";
99
+ paused: "paused";
100
+ refunded: "refunded";
101
+ revoked: "revoked";
102
+ }>;
103
+ environment: z.ZodEnum<{
104
+ production: "production";
105
+ sandbox: "sandbox";
106
+ }>;
107
+ purchasedAt: z.ZodCodec<z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodDate]>, z.ZodDate>;
108
+ expiresAt: z.ZodNullable<z.ZodCodec<z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodDate]>, z.ZodDate>>;
109
+ revokedAt: z.ZodNullable<z.ZodCodec<z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodDate]>, z.ZodDate>>;
110
+ resumesAt: z.ZodNullable<z.ZodCodec<z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodDate]>, z.ZodDate>>;
111
+ originalTransactionId: z.ZodNullable<z.ZodString>;
112
+ amountMinor: z.ZodNullable<z.ZodNumber>;
113
+ currency: z.ZodNullable<z.ZodString>;
114
+ updatedAt: z.ZodCodec<z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodDate]>, z.ZodDate>;
115
+ }, z.core.$strip>;
116
+ export type PaymentsPurchaseRecord = z.output<typeof PaymentsPurchaseRecord>;
117
+ /** What {@link listPurchases} accepts. Every filter is optional; together they are an AND. */
118
+ export interface PurchasesQuery {
119
+ /** Restrict to one subject's purchases — the pair, so an id shared across kinds cannot cross. */
120
+ subject?: PaymentsSubject;
121
+ /** Restrict to one store. */
122
+ rail?: PaymentsRail;
123
+ /** Restrict to one normalized status. */
124
+ status?: PurchaseStatus;
125
+ /** Restrict to one store environment — the filter that separates real money from test transactions. */
126
+ environment?: PurchaseEnvironment;
127
+ /** Where to resume, from a previous page's `nextCursor`. A malformed one is a first page. */
128
+ cursor?: string;
129
+ /** How many rows to return, clamped by `pageLimit`. */
130
+ limit?: number;
131
+ }
132
+ /** What {@link listSubscriptions} accepts. No `rail`: a subscription is read forwards, not by store. */
133
+ export interface SubscriptionsQuery {
134
+ /** Restrict to one subject's subscriptions — the pair, never an id on its own. */
135
+ subject?: PaymentsSubject;
136
+ /** Restrict to one normalized status — `active`, `in_grace`, `canceled`. */
137
+ status?: PurchaseStatus;
138
+ /** Where to resume, from a previous page's `nextCursor`. A malformed one is a first page. */
139
+ cursor?: string;
140
+ /** How many rows to return, clamped by `pageLimit`. */
141
+ limit?: number;
142
+ }
143
+ /** What {@link listEntitlements} accepts. */
144
+ export interface EntitlementsQuery {
145
+ /** Restrict to one subject — the pair, never an id on its own. */
146
+ subject?: PaymentsSubject;
147
+ /** Restrict to one entitlement key — "who holds `pro`". */
148
+ entitlement?: string;
149
+ /** Where to resume, from a previous page's `nextCursor`. A malformed one is a first page. */
150
+ cursor?: string;
151
+ /** How many rows to return, clamped by `pageLimit`. */
152
+ limit?: number;
153
+ }
154
+ /**
155
+ * The purchase log, newest first, filtered.
156
+ *
157
+ * Ordered on `purchasedAt` — when the *store* recorded the sale — rather than on when we first heard of
158
+ * it. A reconciliation pass backfilling a week-old purchase must land in the week-old position, or a
159
+ * purchases pane becomes a log of our own processing rather than of the customer's commerce.
160
+ */
161
+ export declare function listPurchases(d1: D1Database, query?: PurchasesQuery): Promise<PaymentsPage<PaymentsPurchaseRecord>>;
162
+ /**
163
+ * The purchases that renew, newest first.
164
+ *
165
+ * A separate function rather than a `type` filter {@link listPurchases} would accept, because a caller
166
+ * that could name the type could hold `payments:subscriptions:read` and read the whole purchase log
167
+ * through it. The narrowing is applied here, where no request reaches it.
168
+ */
169
+ export declare function listSubscriptions(d1: D1Database, query?: SubscriptionsQuery): Promise<PaymentsPage<PaymentsPurchaseRecord>>;
170
+ /**
171
+ * The entitlement model, newest first, filtered.
172
+ *
173
+ * Sorted on `createdAt` rather than `updatedAt`, and the difference matters on this table: the
174
+ * projection re-derives every affected row on every purchase write, so `updatedAt` moves constantly for
175
+ * reasons that have nothing to do with the grant. Ordering on it would shuffle rows under a reader. When
176
+ * a key first appeared for a subject never moves.
177
+ *
178
+ * A lapsed row is returned rather than filtered out. Whether it still grants is the projection's question
179
+ * in `http/view.ts`, resolved against `expiresAt` at read time exactly as the hot path resolves it — and an
180
+ * operator answering "when did their Pro end" needs the row and its date to survive the read.
181
+ */
182
+ export declare function listEntitlements(d1: D1Database, query?: EntitlementsQuery): Promise<PaymentsPage<PaymentsEntitlement>>;
183
+ /**
184
+ * Every entitlement one subject holds, ordered by key.
185
+ *
186
+ * Unpaginated on purpose, and for the reason `@pithy-sh/ledger`'s `readAccounts` is: the table is keyed
187
+ * `UNIQUE (subjectType, subjectId, entitlement)`, so this returns at most one row per key the catalog
188
+ * sells plus whatever has been comped by hand. A cursor over a list that short would be ceremony.
189
+ *
190
+ * The subject is one argument because it is one fact. Two positional strings would typecheck transposed,
191
+ * and the pair leads the unique index in that order — so this read is a covering prefix scan rather than
192
+ * a filter over every holder of the key.
193
+ *
194
+ * A subject holding nothing is an empty list, not a 404. An entitlement row appears with the first
195
+ * purchase that grants one, so its absence is not a missing holder — and answering 404 would make this
196
+ * surface an existence oracle for user and organization ids alike.
197
+ */
198
+ export declare function readEntitlements(d1: D1Database, subject: PaymentsSubject): Promise<PaymentsEntitlement[]>;
199
+ /** What {@link listReconcileRuns} accepts. */
200
+ export interface ReconcileRunsQuery {
201
+ /** Restrict to the passes narrowed to one store. Never matches a pass that ran against every rail. */
202
+ rail?: PaymentsRail;
203
+ /** Restrict to one store environment. */
204
+ environment?: PurchaseEnvironment;
205
+ /** Where to resume, from a previous page's `nextCursor`. A malformed one is a first page. */
206
+ cursor?: string;
207
+ /** How many rows to return, clamped by `pageLimit`. */
208
+ limit?: number;
209
+ }
210
+ /**
211
+ * The reconciliation passes this deployment has run, newest first.
212
+ *
213
+ * Ordered on `startedAt`, not `finishedAt`, and the difference is the health question: a pass that began and
214
+ * never ended is the failure worth seeing, and ordering on the timestamp it never wrote would hide it behind
215
+ * every pass that did. The id is the tiebreak, on the index the migration creates for exactly this.
216
+ *
217
+ * `selectAll` here where the purchase read names its columns, and the reason is the point of the table: there
218
+ * is no column to withhold. Every field is a count, a timestamp or an enum, so there is no bearer artifact to
219
+ * leave behind and no personal identifier to mask — see `data/reconcileRun.ts`.
220
+ */
221
+ export declare function listReconcileRuns(d1: D1Database, query?: ReconcileRunsQuery): Promise<PaymentsPage<PaymentsReconcileRun>>;
222
+ //# sourceMappingURL=read.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../../src/admin/read.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,159 @@
1
+ import { PaymentsEntitlement } from "../data/entitlement.js";
2
+ import { PaymentsPurchase } from "../data/purchase.js";
3
+ import { PaymentsReconcileRun } from "../data/reconcileRun.js";
4
+ import { PAYMENTS_ENTITLEMENTS_TABLE, PAYMENTS_PURCHASES_TABLE, PAYMENTS_RECONCILE_RUNS_TABLE, paymentsDatabase } from "../data/tables.js";
5
+ import { decodeCursor, pageLimit, toPage } from "@pithy-sh/core/src/data/cursor";
6
+ //#region src/admin/read.ts
7
+ /**
8
+ * A purchase as a management read sees it — every column but the stored provider payload, the provider
9
+ * SKU, and the bookkeeping timestamps the projection keeps for itself.
10
+ *
11
+ * Derived from {@link PaymentsPurchase} with `.pick`, never restated, so the row schema stays the one
12
+ * definition of the table and the codecs still decode dates on the way out of D1. `providerProductId`
13
+ * is left behind because `productId` and `rail` already name what was bought and the SKU is the
14
+ * adopter's own config; `providerEventAt` and `createdAt` because they describe when *we* processed
15
+ * something, which is a question for the audit trail rather than for a purchases pane.
16
+ */
17
+ const PaymentsPurchaseRecord = PaymentsPurchase.pick({
18
+ id: true,
19
+ subjectType: true,
20
+ subjectId: true,
21
+ rail: true,
22
+ providerTransactionId: true,
23
+ originalTransactionId: true,
24
+ productId: true,
25
+ type: true,
26
+ status: true,
27
+ environment: true,
28
+ amountMinor: true,
29
+ currency: true,
30
+ purchasedAt: true,
31
+ expiresAt: true,
32
+ revokedAt: true,
33
+ resumesAt: true,
34
+ updatedAt: true
35
+ }).describe("One purchase as a management read selects it — never the stored provider payload.");
36
+ /** The columns {@link PaymentsPurchaseRecord} covers, as Kysely needs them. One list, derived from the schema. */
37
+ const PURCHASE_COLUMNS = Object.keys(PaymentsPurchaseRecord.shape);
38
+ /**
39
+ * A cursor this table can resume from, or undefined.
40
+ *
41
+ * `PageCursor.sort` is a union because Better Auth stores ISO text where Pithy's own tables store
42
+ * ms-epoch numbers, and comparing a string against an integer column in SQLite silently orders by
43
+ * something nobody meant. Both tables here store a number, so anything else is treated exactly as a
44
+ * malformed cursor is: undefined, and the caller gets a first page rather than an error it could probe.
45
+ */
46
+ function resume(raw) {
47
+ const cursor = decodeCursor(raw);
48
+ if (!cursor || typeof cursor.sort !== "number") return void 0;
49
+ return {
50
+ sort: cursor.sort,
51
+ id: String(cursor.id)
52
+ };
53
+ }
54
+ /**
55
+ * The purchase log, newest first, filtered.
56
+ *
57
+ * Ordered on `purchasedAt` — when the *store* recorded the sale — rather than on when we first heard of
58
+ * it. A reconciliation pass backfilling a week-old purchase must land in the week-old position, or a
59
+ * purchases pane becomes a log of our own processing rather than of the customer's commerce.
60
+ */
61
+ async function listPurchases(d1, query = {}) {
62
+ return await purchasePage(d1, query, void 0);
63
+ }
64
+ /**
65
+ * The purchases that renew, newest first.
66
+ *
67
+ * A separate function rather than a `type` filter {@link listPurchases} would accept, because a caller
68
+ * that could name the type could hold `payments:subscriptions:read` and read the whole purchase log
69
+ * through it. The narrowing is applied here, where no request reaches it.
70
+ */
71
+ async function listSubscriptions(d1, query = {}) {
72
+ return await purchasePage(d1, query, "subscription");
73
+ }
74
+ /** One page of the purchases table, with the product type fixed by the caller rather than by a request. */
75
+ async function purchasePage(d1, query, type) {
76
+ const limit = pageLimit(query.limit);
77
+ const after = resume(query.cursor);
78
+ let selection = paymentsDatabase(d1).selectFrom(PAYMENTS_PURCHASES_TABLE).select(PURCHASE_COLUMNS).orderBy("purchasedAt", "desc").orderBy("id", "desc").limit(limit + 1);
79
+ if (type !== void 0) selection = selection.where("type", "=", type);
80
+ if (query.subject !== void 0) selection = selection.where("subjectType", "=", query.subject.subjectType).where("subjectId", "=", query.subject.subjectId);
81
+ if (query.rail !== void 0) selection = selection.where("rail", "=", query.rail);
82
+ if (query.status !== void 0) selection = selection.where("status", "=", query.status);
83
+ if (query.environment !== void 0) selection = selection.where("environment", "=", query.environment);
84
+ if (after) selection = selection.where((eb) => eb.or([eb("purchasedAt", "<", after.sort), eb.and([eb("purchasedAt", "=", after.sort), eb("id", "<", after.id)])]));
85
+ const rows = await selection.execute();
86
+ return toPage(rows.map((row) => PaymentsPurchaseRecord.parse(row)), limit, (purchase) => ({
87
+ sort: purchase.purchasedAt.getTime(),
88
+ id: purchase.id
89
+ }));
90
+ }
91
+ /**
92
+ * The entitlement model, newest first, filtered.
93
+ *
94
+ * Sorted on `createdAt` rather than `updatedAt`, and the difference matters on this table: the
95
+ * projection re-derives every affected row on every purchase write, so `updatedAt` moves constantly for
96
+ * reasons that have nothing to do with the grant. Ordering on it would shuffle rows under a reader. When
97
+ * a key first appeared for a subject never moves.
98
+ *
99
+ * A lapsed row is returned rather than filtered out. Whether it still grants is the projection's question
100
+ * in `http/view.ts`, resolved against `expiresAt` at read time exactly as the hot path resolves it — and an
101
+ * operator answering "when did their Pro end" needs the row and its date to survive the read.
102
+ */
103
+ async function listEntitlements(d1, query = {}) {
104
+ const limit = pageLimit(query.limit);
105
+ const after = resume(query.cursor);
106
+ let selection = paymentsDatabase(d1).selectFrom(PAYMENTS_ENTITLEMENTS_TABLE).selectAll().orderBy("createdAt", "desc").orderBy("id", "desc").limit(limit + 1);
107
+ if (query.subject !== void 0) selection = selection.where("subjectType", "=", query.subject.subjectType).where("subjectId", "=", query.subject.subjectId);
108
+ if (query.entitlement !== void 0) selection = selection.where("entitlement", "=", query.entitlement);
109
+ if (after) selection = selection.where((eb) => eb.or([eb("createdAt", "<", after.sort), eb.and([eb("createdAt", "=", after.sort), eb("id", "<", after.id)])]));
110
+ const rows = await selection.execute();
111
+ return toPage(rows.map((row) => PaymentsEntitlement.parse(row)), limit, (entitlement) => ({
112
+ sort: entitlement.createdAt.getTime(),
113
+ id: entitlement.id
114
+ }));
115
+ }
116
+ /**
117
+ * Every entitlement one subject holds, ordered by key.
118
+ *
119
+ * Unpaginated on purpose, and for the reason `@pithy-sh/ledger`'s `readAccounts` is: the table is keyed
120
+ * `UNIQUE (subjectType, subjectId, entitlement)`, so this returns at most one row per key the catalog
121
+ * sells plus whatever has been comped by hand. A cursor over a list that short would be ceremony.
122
+ *
123
+ * The subject is one argument because it is one fact. Two positional strings would typecheck transposed,
124
+ * and the pair leads the unique index in that order — so this read is a covering prefix scan rather than
125
+ * a filter over every holder of the key.
126
+ *
127
+ * A subject holding nothing is an empty list, not a 404. An entitlement row appears with the first
128
+ * purchase that grants one, so its absence is not a missing holder — and answering 404 would make this
129
+ * surface an existence oracle for user and organization ids alike.
130
+ */
131
+ async function readEntitlements(d1, subject) {
132
+ return (await paymentsDatabase(d1).selectFrom(PAYMENTS_ENTITLEMENTS_TABLE).selectAll().where("subjectType", "=", subject.subjectType).where("subjectId", "=", subject.subjectId).orderBy("entitlement", "asc").execute()).map((row) => PaymentsEntitlement.parse(row));
133
+ }
134
+ /**
135
+ * The reconciliation passes this deployment has run, newest first.
136
+ *
137
+ * Ordered on `startedAt`, not `finishedAt`, and the difference is the health question: a pass that began and
138
+ * never ended is the failure worth seeing, and ordering on the timestamp it never wrote would hide it behind
139
+ * every pass that did. The id is the tiebreak, on the index the migration creates for exactly this.
140
+ *
141
+ * `selectAll` here where the purchase read names its columns, and the reason is the point of the table: there
142
+ * is no column to withhold. Every field is a count, a timestamp or an enum, so there is no bearer artifact to
143
+ * leave behind and no personal identifier to mask — see `data/reconcileRun.ts`.
144
+ */
145
+ async function listReconcileRuns(d1, query = {}) {
146
+ const limit = pageLimit(query.limit);
147
+ const after = resume(query.cursor);
148
+ let selection = paymentsDatabase(d1).selectFrom(PAYMENTS_RECONCILE_RUNS_TABLE).selectAll().orderBy("startedAt", "desc").orderBy("id", "desc").limit(limit + 1);
149
+ if (query.rail !== void 0) selection = selection.where("rail", "=", query.rail);
150
+ if (query.environment !== void 0) selection = selection.where("environment", "=", query.environment);
151
+ if (after) selection = selection.where((eb) => eb.or([eb("startedAt", "<", after.sort), eb.and([eb("startedAt", "=", after.sort), eb("id", "<", after.id)])]));
152
+ const rows = await selection.execute();
153
+ return toPage(rows.map((row) => PaymentsReconcileRun.parse(row)), limit, (run) => ({
154
+ sort: run.startedAt.getTime(),
155
+ id: run.id
156
+ }));
157
+ }
158
+ //#endregion
159
+ export { PaymentsPurchaseRecord, listEntitlements, listPurchases, listReconcileRuns, listSubscriptions, readEntitlements };