@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,120 @@
1
+ import { z } from "zod";
2
+ import type { PaymentsPurchase, PurchaseEnvironment } from "../../data/purchase";
3
+ import type { PurchaseStatus } from "../../data/status";
4
+ import type { PaymentsAppleCredentials } from "../../secret/registry";
5
+ import type { UnboundProviderEvent } from "../contract";
6
+ import { type AppleHttpFetch } from "./http";
7
+ /**
8
+ * The App Store Server API — the call that answers "what is this subscription doing now", and the mapping of
9
+ * Apple's status vocabulary into the normalized set.
10
+ *
11
+ * This is the half of Apple's rail nothing else needs. A client submission and a notification both arrive
12
+ * signed, so they verify offline and cost no round-trip. Reconciliation has neither: the whole point of it is
13
+ * the subscription **nothing arrived about**, because Apple stopped renewing and sent nothing, or sent
14
+ * something that never reached us. Asking Apple is the only way to learn that, and this is where it is asked.
15
+ *
16
+ * ## Two facts, and only one of them is in the transaction
17
+ *
18
+ * `GET /inApps/v1/subscriptions/{originalTransactionId}` returns, per subscription group, the last transaction
19
+ * plus a **numeric status** — and the numeric status carries what the signed transaction cannot. A transaction
20
+ * says when it expires; it does not say that Apple is in a billing retry, or that the subscriber is inside a
21
+ * grace period, or how long that grace runs, or that auto-renew was switched off. So the status **and the
22
+ * access window** come from Apple's number and the renewal info beside it, and everything else — the product,
23
+ * the purchase date, the price, the account token — comes from the signed transaction, verified against the
24
+ * same pinned chain every other Apple payload is.
25
+ *
26
+ * ## The two hosts are not interchangeable
27
+ *
28
+ * Sandbox and production are separate services with separate data. A production transaction id asked of the
29
+ * sandbox host is a 404, not an error, so the host is chosen from the **stored row's own environment** rather
30
+ * than from the deployment's or from a probe. That also means a sandbox row in a production database — which
31
+ * the writer refuses to create — could never be refreshed into one.
32
+ *
33
+ * ## What is not here
34
+ *
35
+ * **One-time purchases.** Apple's subscription endpoint is for auto-renewables only, and a consumable or
36
+ * non-consumable does not drift: it is bought once, and the single thing that can change it — a refund —
37
+ * arrives as a `REFUND` notification. There is a transaction-history endpoint that would answer for one, and
38
+ * nothing in this module needs it, so nothing here calls it.
39
+ */
40
+ /**
41
+ * The App Store Server API's two bases, one per store environment.
42
+ *
43
+ * Public and stable, so they are pinned rather than configured. The keying is on the *purchase's* environment,
44
+ * which is why this is a record rather than a single constant.
45
+ */
46
+ export declare const APPLE_API_BASES: Readonly<Record<PurchaseEnvironment, string>>;
47
+ /** The audience every App Store Connect API token claims. Apple's own literal, not a URL. */
48
+ export declare const APPLE_API_AUDIENCE = "appstoreconnect-v1";
49
+ /**
50
+ * How long a minted token claims to be good for. Apple refuses anything over an hour, and a token minted at
51
+ * the ceiling is one clock-skew away from being refused — so this sits comfortably under it.
52
+ */
53
+ export declare const APPLE_TOKEN_LIFETIME_SECONDS = 1800;
54
+ /**
55
+ * The App Store Server API's answer to a subscription-status query.
56
+ *
57
+ * `data` is one entry per subscription group, and each carries every transaction in the family the queried id
58
+ * belongs to. In practice one id resolves to one group with one transaction; the shape allows more, so the
59
+ * caller matches on the id rather than trusting position.
60
+ */
61
+ export declare const AppleSubscriptionStatuses: z.ZodObject<{
62
+ environment: z.ZodString;
63
+ bundleId: z.ZodString;
64
+ data: z.ZodArray<z.ZodObject<{
65
+ lastTransactions: z.ZodArray<z.ZodObject<{
66
+ originalTransactionId: z.ZodString;
67
+ status: z.ZodNumber;
68
+ signedTransactionInfo: z.ZodString;
69
+ signedRenewalInfo: z.ZodOptional<z.ZodString>;
70
+ }, z.core.$loose>>;
71
+ }, z.core.$loose>>;
72
+ }, z.core.$loose>;
73
+ export type AppleSubscriptionStatuses = z.infer<typeof AppleSubscriptionStatuses>;
74
+ /** What an App Store Server API call needs: the credentials, a clock, the transport, and the trust set. */
75
+ export interface AppleServerApiOptions {
76
+ /** Apple's credential block. The key signs the token; the bundle id is checked on the answer. */
77
+ credentials: PaymentsAppleCredentials;
78
+ /** The clock. It dates the token, and it becomes the refreshed event's provider event time. */
79
+ now: Date;
80
+ /** The HTTP seam. Defaults to the runtime's `fetch`. */
81
+ transport?: AppleHttpFetch;
82
+ /** Roots accepted in addition to Apple's pinned ones, base64 DER. Additive only, and empty in production. */
83
+ roots?: readonly string[];
84
+ /**
85
+ * A token already minted, so a batch of lookups pays for one.
86
+ *
87
+ * Deliberately a parameter rather than a module-level cache: a bearer credential derived from a secret is
88
+ * exactly what CLAUDE.md forbids caching in a module variable. So a single call mints one and drops it, and
89
+ * the reconciliation Workflow — the caller that makes hundreds — mints one and passes it down.
90
+ */
91
+ token?: string;
92
+ }
93
+ /**
94
+ * Mint an App Store Connect API token from the `.p8` key.
95
+ *
96
+ * A plain ES256 JWT: Apple issues no OAuth flow for this API, so the assertion *is* the credential. The `bid`
97
+ * claim is what scopes it to one app — a token without it is refused, which is why the bundle id sits in the
98
+ * credential block beside the key rather than in config.
99
+ */
100
+ export declare function mintAppleApiToken(credentials: PaymentsAppleCredentials, options: {
101
+ now: Date;
102
+ }): Promise<string>;
103
+ /** The normalized status for an Apple subscription status code and its renewal flag. */
104
+ export declare function appleSubscriptionStatus(status: number, autoRenewStatus: number | undefined): PurchaseStatus;
105
+ /**
106
+ * The current state of a subscription family, or `undefined` when Apple has none under that id.
107
+ *
108
+ * `undefined` is a real answer, not a failure: a transaction id from the other store environment, or one from
109
+ * an app this key does not cover, is a 404. A store that cannot be reached throws instead.
110
+ */
111
+ export declare function fetchAppleSubscriptionStatuses(originalTransactionId: string, environment: PurchaseEnvironment, options: AppleServerApiOptions): Promise<AppleSubscriptionStatuses | undefined>;
112
+ /**
113
+ * Re-read one stored subscription at Apple, normalized — the reconciliation path for this rail.
114
+ *
115
+ * Returns `undefined` for a purchase Apple's subscription endpoint cannot speak for: a one-time purchase, or a
116
+ * transaction id the queried environment does not know. Both leave the row untouched, which is right — a
117
+ * subscription we cannot read is not evidence of anything.
118
+ */
119
+ export declare function refreshAppleSubscription(purchase: PaymentsPurchase, options: AppleServerApiOptions): Promise<UnboundProviderEvent | undefined>;
120
+ //# sourceMappingURL=serverApi.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serverApi.d.ts","sourceRoot":"","sources":["../../../src/rails/apple/serverApi.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AACjF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAExD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AACtE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAExD,OAAO,EAAE,KAAK,cAAc,EAA6B,MAAM,QAAQ,CAAC;AAWxE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH;;;;;GAKG;AACH,eAAO,MAAM,eAAe,EAAE,QAAQ,CAAC,MAAM,CAAC,mBAAmB,EAAE,MAAM,CAAC,CAGzE,CAAC;AAEF,6FAA6F;AAC7F,eAAO,MAAM,kBAAkB,uBAAuB,CAAC;AAEvD;;;GAGG;AACH,eAAO,MAAM,4BAA4B,OAAO,CAAC;AAwDjD;;;;;;GAMG;AACH,eAAO,MAAM,yBAAyB;;;;;;;;;;;iBAqB6C,CAAC;AACpF,MAAM,MAAM,yBAAyB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAElF,2GAA2G;AAC3G,MAAM,WAAW,qBAAqB;IACpC,iGAAiG;IACjG,WAAW,EAAE,wBAAwB,CAAC;IACtC,+FAA+F;IAC/F,GAAG,EAAE,IAAI,CAAC;IACV,wDAAwD;IACxD,SAAS,CAAC,EAAE,cAAc,CAAC;IAC3B,6GAA6G;IAC7G,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1B;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AA6CD;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CACrC,WAAW,EAAE,wBAAwB,EACrC,OAAO,EAAE;IAAE,GAAG,EAAE,IAAI,CAAA;CAAE,GACrB,OAAO,CAAC,MAAM,CAAC,CAsCjB;AAOD,wFAAwF;AACxF,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,SAAS,GAAG,cAAc,CAc3G;AAED;;;;;GAKG;AACH,wBAAsB,8BAA8B,CAClD,qBAAqB,EAAE,MAAM,EAC7B,WAAW,EAAE,mBAAmB,EAChC,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,yBAAyB,GAAG,SAAS,CAAC,CAmBhD;AAED;;;;;;GAMG;AACH,wBAAsB,wBAAwB,CAC5C,QAAQ,EAAE,gBAAgB,EAC1B,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,oBAAoB,GAAG,SAAS,CAAC,CAuD3C"}
@@ -0,0 +1,244 @@
1
+ import { PaymentsRailNotConfiguredError, PaymentsVerificationFailedError } from "../../error/errors.js";
2
+ import { minorUnitsFromScaled } from "../../data/money.js";
3
+ import { decodeBase64 } from "./der.js";
4
+ import { verifyAppleJws } from "./jws.js";
5
+ import { APPLE_PRICE_SCALE, AppleRenewalInfo, AppleTransactionInfo, appleEnvironment, appleExpiresAt, requireAppleBundle } from "./notification.js";
6
+ import { appleHttpFetch, appleJson } from "./http.js";
7
+ import { z } from "zod";
8
+ //#region src/rails/apple/serverApi.ts
9
+ /**
10
+ * The App Store Server API — the call that answers "what is this subscription doing now", and the mapping of
11
+ * Apple's status vocabulary into the normalized set.
12
+ *
13
+ * This is the half of Apple's rail nothing else needs. A client submission and a notification both arrive
14
+ * signed, so they verify offline and cost no round-trip. Reconciliation has neither: the whole point of it is
15
+ * the subscription **nothing arrived about**, because Apple stopped renewing and sent nothing, or sent
16
+ * something that never reached us. Asking Apple is the only way to learn that, and this is where it is asked.
17
+ *
18
+ * ## Two facts, and only one of them is in the transaction
19
+ *
20
+ * `GET /inApps/v1/subscriptions/{originalTransactionId}` returns, per subscription group, the last transaction
21
+ * plus a **numeric status** — and the numeric status carries what the signed transaction cannot. A transaction
22
+ * says when it expires; it does not say that Apple is in a billing retry, or that the subscriber is inside a
23
+ * grace period, or how long that grace runs, or that auto-renew was switched off. So the status **and the
24
+ * access window** come from Apple's number and the renewal info beside it, and everything else — the product,
25
+ * the purchase date, the price, the account token — comes from the signed transaction, verified against the
26
+ * same pinned chain every other Apple payload is.
27
+ *
28
+ * ## The two hosts are not interchangeable
29
+ *
30
+ * Sandbox and production are separate services with separate data. A production transaction id asked of the
31
+ * sandbox host is a 404, not an error, so the host is chosen from the **stored row's own environment** rather
32
+ * than from the deployment's or from a probe. That also means a sandbox row in a production database — which
33
+ * the writer refuses to create — could never be refreshed into one.
34
+ *
35
+ * ## What is not here
36
+ *
37
+ * **One-time purchases.** Apple's subscription endpoint is for auto-renewables only, and a consumable or
38
+ * non-consumable does not drift: it is bought once, and the single thing that can change it — a refund —
39
+ * arrives as a `REFUND` notification. There is a transaction-history endpoint that would answer for one, and
40
+ * nothing in this module needs it, so nothing here calls it.
41
+ */
42
+ /**
43
+ * The App Store Server API's two bases, one per store environment.
44
+ *
45
+ * Public and stable, so they are pinned rather than configured. The keying is on the *purchase's* environment,
46
+ * which is why this is a record rather than a single constant.
47
+ */
48
+ const APPLE_API_BASES = {
49
+ production: "https://api.storekit.itunes.apple.com/inApps/v1",
50
+ sandbox: "https://api.storekit-sandbox.itunes.apple.com/inApps/v1"
51
+ };
52
+ /** The audience every App Store Connect API token claims. Apple's own literal, not a URL. */
53
+ const APPLE_API_AUDIENCE = "appstoreconnect-v1";
54
+ /**
55
+ * How long a minted token claims to be good for. Apple refuses anything over an hour, and a token minted at
56
+ * the ceiling is one clock-skew away from being refused — so this sits comfortably under it.
57
+ */
58
+ const APPLE_TOKEN_LIFETIME_SECONDS = 1800;
59
+ /** ECDSA over P-256 with SHA-256 — `ES256`, the only algorithm App Store Connect accepts. */
60
+ const ES256 = {
61
+ name: "ECDSA",
62
+ namedCurve: "P-256"
63
+ };
64
+ /** The PEM armour an App Store Connect `.p8` carries. Apple issues PKCS#8 and nothing else. */
65
+ const PKCS8_HEADER = "-----BEGIN PRIVATE KEY-----";
66
+ /**
67
+ * Apple's subscription status codes, mapped.
68
+ *
69
+ * Three are worth reading twice. **3 is billing retry and does not grant**: Apple is retrying the card and the
70
+ * subscriber's access has already ended, which is what `on_hold` means. **4 is the grace period and does
71
+ * grant** — that is the point of grace, a failed card should not lock a paying subscriber out mid-period, and
72
+ * the window it grants through is the renewal info's `gracePeriodExpiresDate` rather than the transaction's
73
+ * expiry, which has already passed by the time Apple says 4. And
74
+ * **auto-renew off is `canceled`, which also grants**: declining the *next* period does not forfeit the one
75
+ * already paid for, and `expiresAt` is what ends it.
76
+ */
77
+ const SUBSCRIPTION_STATUSES = {
78
+ 1: "active",
79
+ 2: "expired",
80
+ 3: "on_hold",
81
+ 4: "in_grace",
82
+ 5: "revoked"
83
+ };
84
+ /** Apple's `autoRenewStatus` for a subscription the user has switched off. */
85
+ const AUTO_RENEW_OFF = 0;
86
+ /** One entry of a subscription group's `lastTransactions` array. */
87
+ const AppleLastTransaction = z.object({
88
+ originalTransactionId: z.string().min(1).describe("The transaction that started this subscription — how the right entry is picked out of the group."),
89
+ status: z.number().int().describe("Apple's numeric subscription status: 1 active, 2 expired, 3 billing retry, 4 grace period, 5 revoked. The one fact the signed transaction does not carry."),
90
+ signedTransactionInfo: z.string().min(1).describe("The latest transaction, as its own JWS. Verified against the pinned chain like every other one."),
91
+ signedRenewalInfo: z.string().min(1).optional().describe("The renewal state, as its own JWS. Absent for a subscription with no renewal left to describe.")
92
+ }).loose().describe("One subscription's latest transaction and its status, as the App Store Server API reports it.");
93
+ /**
94
+ * The App Store Server API's answer to a subscription-status query.
95
+ *
96
+ * `data` is one entry per subscription group, and each carries every transaction in the family the queried id
97
+ * belongs to. In practice one id resolves to one group with one transaction; the shape allows more, so the
98
+ * caller matches on the id rather than trusting position.
99
+ */
100
+ const AppleSubscriptionStatuses = z.object({
101
+ environment: z.string().min(1).describe("`Production` or `Sandbox`, as the answering host reports it. Checked against the row's own."),
102
+ bundleId: z.string().min(1).describe("The app the subscription belongs to. Checked against our own."),
103
+ data: z.array(z.object({ lastTransactions: z.array(AppleLastTransaction).describe("The latest transaction per subscription in this group, with its status.") }).loose().describe("One subscription group's latest state.")).describe("One entry per subscription group the queried transaction belongs to.")
104
+ }).loose().describe("Apple's StatusResponse — the current state of a subscription family.");
105
+ /**
106
+ * The DER bytes of an App Store Connect `.p8`.
107
+ *
108
+ * A copy of what the Google rail does with its service-account key, and a copy on purpose: a rail reaching
109
+ * into another rail's module for a helper would make the two fail together, and the same choice was already
110
+ * made for the two spellings of the webhook body schema. Twelve lines is the cheaper coupling.
111
+ */
112
+ function applePrivateKey(pem) {
113
+ const text = pem.replaceAll("\\n", "\n");
114
+ if (!text.includes(PKCS8_HEADER)) throw new PaymentsRailNotConfiguredError({ detail: text.includes("PRIVATE KEY") ? "Apple: the App Store Connect key is not PKCS#8. Store the downloaded `.p8` verbatim — it begins `-----BEGIN PRIVATE KEY-----`." : "Apple: the App Store Connect key carries no PEM armour. Store the downloaded `.p8` file's contents verbatim, header and footer included." });
115
+ const body = text.slice(text.indexOf(PKCS8_HEADER) + 27).replace(/-----END PRIVATE KEY-----[\s\S]*$/, "").replaceAll(/\s+/g, "");
116
+ try {
117
+ return decodeBase64(body);
118
+ } catch (cause) {
119
+ throw new PaymentsRailNotConfiguredError({ detail: "Apple: the App Store Connect key's PEM body is not valid base64." }, { cause });
120
+ }
121
+ }
122
+ /** base64url of raw bytes, unpadded — the encoding every JWT segment uses. */
123
+ function base64Url(bytes) {
124
+ let binary = "";
125
+ for (const byte of bytes) binary += String.fromCharCode(byte);
126
+ return btoa(binary).replaceAll("+", "-").replaceAll("/", "_").replaceAll("=", "");
127
+ }
128
+ /** base64url of a JSON value — a JWT header or claim set. */
129
+ function base64UrlJson(value) {
130
+ return base64Url(new TextEncoder().encode(JSON.stringify(value)));
131
+ }
132
+ /**
133
+ * Mint an App Store Connect API token from the `.p8` key.
134
+ *
135
+ * A plain ES256 JWT: Apple issues no OAuth flow for this API, so the assertion *is* the credential. The `bid`
136
+ * claim is what scopes it to one app — a token without it is refused, which is why the bundle id sits in the
137
+ * credential block beside the key rather than in config.
138
+ */
139
+ async function mintAppleApiToken(credentials, options) {
140
+ let key;
141
+ try {
142
+ key = await crypto.subtle.importKey("pkcs8", applePrivateKey(credentials.privateKey), ES256, false, ["sign"]);
143
+ } catch (cause) {
144
+ if (cause instanceof PaymentsRailNotConfiguredError) throw cause;
145
+ throw new PaymentsRailNotConfiguredError({ detail: "Apple: the App Store Connect private key could not be imported as a P-256 key. Check that the `.p8` was stored whole and belongs to an App Store Connect API key." }, { cause });
146
+ }
147
+ const issuedAt = Math.floor(options.now.getTime() / 1e3);
148
+ const header = base64UrlJson({
149
+ alg: "ES256",
150
+ kid: credentials.keyId,
151
+ typ: "JWT"
152
+ });
153
+ const claims = base64UrlJson({
154
+ iss: credentials.issuerId,
155
+ iat: issuedAt,
156
+ exp: issuedAt + APPLE_TOKEN_LIFETIME_SECONDS,
157
+ aud: APPLE_API_AUDIENCE,
158
+ bid: credentials.bundleId
159
+ });
160
+ const signature = await crypto.subtle.sign({
161
+ name: "ECDSA",
162
+ hash: "SHA-256"
163
+ }, key, new TextEncoder().encode(`${header}.${claims}`));
164
+ return `${header}.${claims}.${base64Url(new Uint8Array(signature))}`;
165
+ }
166
+ /** The token to send: the one the caller minted for the batch, or one minted for this call alone. */
167
+ async function bearer(options) {
168
+ return options.token ?? await mintAppleApiToken(options.credentials, { now: options.now });
169
+ }
170
+ /** The normalized status for an Apple subscription status code and its renewal flag. */
171
+ function appleSubscriptionStatus(status, autoRenewStatus) {
172
+ const mapped = SUBSCRIPTION_STATUSES[status];
173
+ if (mapped === void 0) throw new PaymentsVerificationFailedError({ detail: `Apple: subscription status ${status} is not one this build maps. The purchase was left as it stood.` });
174
+ return mapped === "active" && autoRenewStatus === AUTO_RENEW_OFF ? "canceled" : mapped;
175
+ }
176
+ /**
177
+ * The current state of a subscription family, or `undefined` when Apple has none under that id.
178
+ *
179
+ * `undefined` is a real answer, not a failure: a transaction id from the other store environment, or one from
180
+ * an app this key does not cover, is a 404. A store that cannot be reached throws instead.
181
+ */
182
+ async function fetchAppleSubscriptionStatuses(originalTransactionId, environment, options) {
183
+ const url = `${APPLE_API_BASES[environment]}/subscriptions/${encodeURIComponent(originalTransactionId)}`;
184
+ const answered = await appleJson(options.transport ?? appleHttpFetch, url, {
185
+ what: "the subscription statuses",
186
+ headers: { authorization: `Bearer ${await bearer(options)}` },
187
+ absentOn404: true
188
+ });
189
+ if (answered === void 0) return void 0;
190
+ const parsed = AppleSubscriptionStatuses.safeParse(answered);
191
+ if (!parsed.success) throw new PaymentsVerificationFailedError({ detail: `Apple: the answer is not a StatusResponse — ${parsed.error.issues.map((issue) => `${issue.path.join(".") || "<root>"}:${issue.code}`).join(", ")}.` });
192
+ return parsed.data;
193
+ }
194
+ /**
195
+ * Re-read one stored subscription at Apple, normalized — the reconciliation path for this rail.
196
+ *
197
+ * Returns `undefined` for a purchase Apple's subscription endpoint cannot speak for: a one-time purchase, or a
198
+ * transaction id the queried environment does not know. Both leave the row untouched, which is right — a
199
+ * subscription we cannot read is not evidence of anything.
200
+ */
201
+ async function refreshAppleSubscription(purchase, options) {
202
+ if (purchase.type !== "subscription") return void 0;
203
+ const familyId = purchase.originalTransactionId ?? purchase.providerTransactionId;
204
+ const statuses = await fetchAppleSubscriptionStatuses(familyId, purchase.environment, options);
205
+ if (statuses === void 0) return void 0;
206
+ requireAppleBundle(statuses.bundleId, options.credentials.bundleId, "subscription status");
207
+ const entry = statuses.data.flatMap((group) => group.lastTransactions).find((candidate) => candidate.originalTransactionId === familyId);
208
+ if (entry === void 0) return void 0;
209
+ const transaction = await verify(entry.signedTransactionInfo, AppleTransactionInfo, "transaction", options);
210
+ requireAppleBundle(transaction.bundleId, options.credentials.bundleId, "transaction");
211
+ const renewal = entry.signedRenewalInfo === void 0 ? void 0 : await verify(entry.signedRenewalInfo, AppleRenewalInfo, "renewal info", options);
212
+ const status = transaction.revocationDate === void 0 ? appleSubscriptionStatus(entry.status, renewal?.autoRenewStatus) : "refunded";
213
+ return {
214
+ rail: "apple",
215
+ providerTransactionId: transaction.transactionId,
216
+ providerProductId: transaction.productId,
217
+ status,
218
+ environment: appleEnvironment(transaction.environment),
219
+ purchasedAt: new Date(transaction.purchaseDate),
220
+ expiresAt: appleExpiresAt(status, transaction.expiresDate, renewal?.gracePeriodExpiresDate),
221
+ revokedAt: transaction.revocationDate === void 0 ? null : new Date(transaction.revocationDate),
222
+ originalTransactionId: transaction.originalTransactionId ?? null,
223
+ amountMinor: minorUnitsFromScaled(transaction.price ?? null, APPLE_PRICE_SCALE, transaction.currency ?? null),
224
+ currency: transaction.currency ?? null,
225
+ providerEventAt: options.now,
226
+ payload: {
227
+ transaction,
228
+ status: entry.status,
229
+ renewalInfo: renewal ?? null
230
+ }
231
+ };
232
+ }
233
+ /** Verify one nested JWS against the pinned chain and parse it, naming the field in any refusal. */
234
+ async function verify(jws, schema, field, options) {
235
+ const payload = await verifyAppleJws(jws, {
236
+ roots: options.roots,
237
+ now: options.now
238
+ });
239
+ const parsed = schema.safeParse(payload);
240
+ if (!parsed.success) throw new PaymentsVerificationFailedError({ detail: `Apple: the ${field} in the subscription status rejected — ${parsed.error.issues.map((issue) => `${issue.path.join(".") || "<root>"}:${issue.code}`).join(", ")}.` });
241
+ return parsed.data;
242
+ }
243
+ //#endregion
244
+ export { APPLE_API_AUDIENCE, APPLE_API_BASES, APPLE_TOKEN_LIFETIME_SECONDS, AppleSubscriptionStatuses, appleSubscriptionStatus, fetchAppleSubscriptionStatuses, mintAppleApiToken, refreshAppleSubscription };
@@ -0,0 +1,36 @@
1
+ import type { VerifiedPurchase } from "../contract";
2
+ /**
3
+ * The client-submission path: a StoreKit 2 signed transaction, verified locally.
4
+ *
5
+ * **There is no store round-trip here, and that is Apple's own design.** StoreKit 2 hands the app a JWS that
6
+ * Apple signed; verifying it against Apple's certificate chain is exactly as strong as asking the App Store
7
+ * Server API, and it is what Apple documents. So this route can be fast and offline, which is what it is
8
+ * for: the buying user sees their entitlement the moment they buy, without waiting for a webhook that is
9
+ * authoritative but not prompt.
10
+ *
11
+ * Nothing about correctness rests on this path. The webhook produces the identical row through the same
12
+ * idempotent writer, so a dropped submission costs nothing and a replayed one changes nothing.
13
+ *
14
+ * Status has to be derived differently from the webhook path. A notification says what *happened*; a
15
+ * transaction only says what it *is*, so there are two facts to read and an order to read them in:
16
+ *
17
+ * 1. **A revocation date wins.** A refunded transaction inside its paid period must not grant, and the
18
+ * revocation is the later fact.
19
+ * 2. **Otherwise the expiry decides.** A subscription past its `expiresDate` is expired even though no
20
+ * notification ever said so — which is the case the read-time recheck exists for. Apple stops renewing
21
+ * and sends nothing; a client resubmitting its stale transaction must not be handed an active row.
22
+ *
23
+ * Everything else is active. A transaction Apple signed, that was not revoked and has not lapsed, is paid.
24
+ */
25
+ /** What verification needs: our bundle id, the roots to trust, and the clock the expiry is judged against. */
26
+ export interface VerifyAppleTransactionOptions {
27
+ /** Our own bundle id. A transaction from any other app is refused, whoever signed it. */
28
+ bundleId: string;
29
+ /** base64 DER of every acceptable root. Defaults to the pinned Apple roots. */
30
+ roots?: readonly string[];
31
+ /** The clock. Also what `expiresDate` is compared against, so a lapse is deterministic in tests. */
32
+ now: Date;
33
+ }
34
+ /** Verify a StoreKit 2 signed transaction and normalize it. The caller binds the authenticated purchaser. */
35
+ export declare function verifyAppleTransaction(receipt: string, options: VerifyAppleTransactionOptions): Promise<VerifiedPurchase>;
36
+ //# sourceMappingURL=verify.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../../../src/rails/apple/verify.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAwB,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAI1E;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,8GAA8G;AAC9G,MAAM,WAAW,6BAA6B;IAC5C,yFAAyF;IACzF,QAAQ,EAAE,MAAM,CAAC;IACjB,+EAA+E;IAC/E,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1B,oGAAoG;IACpG,GAAG,EAAE,IAAI,CAAC;CACX;AAED,6GAA6G;AAC7G,wBAAsB,sBAAsB,CAC1C,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,6BAA6B,GACrC,OAAO,CAAC,gBAAgB,CAAC,CA+B3B"}
@@ -0,0 +1,46 @@
1
+ import { PaymentsInvalidReceiptError } from "../../error/errors.js";
2
+ import { minorUnitsFromScaled } from "../../data/money.js";
3
+ import { verifyAppleJws } from "./jws.js";
4
+ import { APPLE_PRICE_SCALE, AppleTransactionInfo, appleEnvironment, requireAppleBundle } from "./notification.js";
5
+ //#region src/rails/apple/verify.ts
6
+ /** Verify a StoreKit 2 signed transaction and normalize it. The caller binds the authenticated purchaser. */
7
+ async function verifyAppleTransaction(receipt, options) {
8
+ const payload = await verifyAppleJws(receipt, {
9
+ roots: options.roots,
10
+ now: options.now
11
+ });
12
+ const parsed = AppleTransactionInfo.safeParse(payload);
13
+ if (!parsed.success) throw new PaymentsInvalidReceiptError({ detail: `Apple: the submitted transaction is not a StoreKit transaction — ${issues(parsed.error)}.` });
14
+ const transaction = parsed.data;
15
+ requireAppleBundle(transaction.bundleId, options.bundleId, "transaction");
16
+ return {
17
+ event: {
18
+ rail: "apple",
19
+ providerTransactionId: transaction.transactionId,
20
+ providerProductId: transaction.productId,
21
+ status: transactionStatus(transaction, options.now),
22
+ environment: appleEnvironment(transaction.environment),
23
+ purchasedAt: new Date(transaction.purchaseDate),
24
+ expiresAt: transaction.expiresDate === void 0 ? null : new Date(transaction.expiresDate),
25
+ revokedAt: transaction.revocationDate === void 0 ? null : new Date(transaction.revocationDate),
26
+ originalTransactionId: transaction.originalTransactionId ?? null,
27
+ amountMinor: minorUnitsFromScaled(transaction.price ?? null, APPLE_PRICE_SCALE, transaction.currency ?? null),
28
+ currency: transaction.currency ?? null,
29
+ providerEventAt: new Date(transaction.signedDate),
30
+ payload: transaction
31
+ },
32
+ providerAccountId: transaction.appAccountToken ?? null
33
+ };
34
+ }
35
+ /** The status a transaction implies on its own: revoked, then lapsed, then paid. */
36
+ function transactionStatus(transaction, now) {
37
+ if (transaction.revocationDate !== void 0) return "refunded";
38
+ if (transaction.expiresDate !== void 0 && transaction.expiresDate <= now.getTime()) return "expired";
39
+ return "active";
40
+ }
41
+ /** Zod issues as `path:code` pairs — never `message` or `received`, which would echo the receipt. */
42
+ function issues(error) {
43
+ return error.issues.map((issue) => `${issue.path.join(".") || "<root>"}:${issue.code}`).join(", ");
44
+ }
45
+ //#endregion
46
+ export { verifyAppleTransaction };
@@ -0,0 +1,85 @@
1
+ /**
2
+ * Apple's marker on the certificate that signs App Store Server Notifications and transactions, and on the
3
+ * WWDR intermediate that issues it. Published by Apple and checked by Apple's own `app-store-server-library`,
4
+ * which is where these values come from; they are identifiers, not secrets.
5
+ *
6
+ * They are what make the chain check an identity check. Rooting in Apple Root CA - G3 proves Apple issued
7
+ * something in the path; these prove the path is Apple's App-Store-data-signing path specifically.
8
+ */
9
+ export declare const APPLE_RECEIPT_SIGNER_OID = "1.2.840.113635.100.6.11.1";
10
+ export declare const APPLE_WWDR_INTERMEDIATE_OID = "1.2.840.113635.100.6.2.1";
11
+ /** One certificate extension: whether it was marked critical, and its own DER. */
12
+ export interface CertificateExtension {
13
+ critical: boolean;
14
+ value: Uint8Array;
15
+ }
16
+ /** `basicConstraints`, decoded. Absent from a certificate means "not a CA" (the ASN.1 default for `cA`). */
17
+ export interface BasicConstraints {
18
+ ca: boolean;
19
+ pathLen?: number;
20
+ }
21
+ /** One parsed certificate — only the fields a chain check needs, and nothing else. */
22
+ export interface ParsedCertificate {
23
+ /** The whole certificate's DER, for byte-comparing against a pinned root. */
24
+ der: Uint8Array;
25
+ /** The `tbsCertificate` as encoded, tag and length included — exactly the bytes the issuer signed. */
26
+ tbs: Uint8Array;
27
+ /** The issuer Name's DER, compared against the next certificate's subject to link the chain. */
28
+ issuer: Uint8Array;
29
+ /** The subject Name's DER. */
30
+ subject: Uint8Array;
31
+ /** When the certificate becomes valid. */
32
+ notBefore: Date;
33
+ /** When it stops being valid. */
34
+ notAfter: Date;
35
+ /** The SubjectPublicKeyInfo, ready for `crypto.subtle.importKey("spki", …)`. */
36
+ spki: Uint8Array;
37
+ /** The curve the subject's key is on. */
38
+ curve: "P-256" | "P-384";
39
+ /** The OID of the algorithm the issuer signed this certificate with. */
40
+ signatureAlgorithm: string;
41
+ /** The signature value — a DER `SEQUENCE { INTEGER r, INTEGER s }`. */
42
+ signature: Uint8Array;
43
+ /** Every extension, by OID. Unknown ones are kept rather than refused; only the checked ones are decoded. */
44
+ extensions: Map<string, CertificateExtension>;
45
+ /** `basicConstraints`, or undefined when the certificate carries none — which means it is not a CA. */
46
+ basicConstraints?: BasicConstraints;
47
+ /** Whether `keyUsage` is present and grants `keyCertSign`; undefined when the extension is absent. */
48
+ keyCertSign?: boolean;
49
+ }
50
+ /** A leaf's verifying key and the curve it is on. The curve is returned because ES256 requires P-256. */
51
+ export interface VerifiedLeaf {
52
+ key: CryptoKey;
53
+ curve: "P-256" | "P-384";
54
+ }
55
+ /** What the chain check needs: which roots to trust, and the clock to judge validity against. */
56
+ export interface VerifyChainOptions {
57
+ /** base64 DER of every acceptable root. The chain's last certificate must equal one of them. */
58
+ roots: readonly string[];
59
+ /** The clock. Injected, so a validity refusal is deterministic. */
60
+ now: Date;
61
+ /**
62
+ * An extension OID the leaf must carry. Defaults to {@link APPLE_RECEIPT_SIGNER_OID}. Pass `null` only
63
+ * where a chain genuinely is not Apple's App-Store-signing chain — there is no such caller in the package,
64
+ * and the option exists so the requirement is visible at the boundary rather than buried.
65
+ */
66
+ requiredLeafExtension?: string | null;
67
+ /** An extension OID the leaf's issuer must carry. Defaults to {@link APPLE_WWDR_INTERMEDIATE_OID}. */
68
+ requiredIssuerExtension?: string | null;
69
+ }
70
+ /**
71
+ * Parse one DER certificate.
72
+ *
73
+ * `Certificate ::= SEQUENCE { tbsCertificate, signatureAlgorithm, signatureValue }`, and inside the tbs,
74
+ * `SEQUENCE { [0] version, serialNumber, signature, issuer, validity, subject, subjectPublicKeyInfo, … }`.
75
+ * The version field is optional, so the fields after it are located by counting from the end of whichever
76
+ * prefix is present rather than by fixed index.
77
+ */
78
+ export declare function parseCertificate(der: Uint8Array): ParsedCertificate;
79
+ /**
80
+ * Verify a certificate chain — leaf first, root last, the order `x5c` uses — and return the leaf's
81
+ * verifying key. Throws rather than returning a boolean: there is no caller that wants to carry on with an
82
+ * unverified chain, and a boolean invites one.
83
+ */
84
+ export declare function verifyCertificateChain(chain: readonly Uint8Array[], options: VerifyChainOptions): Promise<VerifiedLeaf>;
85
+ //# sourceMappingURL=x509.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"x509.d.ts","sourceRoot":"","sources":["../../../src/rails/apple/x509.ts"],"names":[],"mappings":"AAqFA;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB,8BAA8B,CAAC;AACpE,eAAO,MAAM,2BAA2B,6BAA6B,CAAC;AAStE,kFAAkF;AAClF,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,OAAO,CAAC;IAClB,KAAK,EAAE,UAAU,CAAC;CACnB;AAED,4GAA4G;AAC5G,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,OAAO,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,sFAAsF;AACtF,MAAM,WAAW,iBAAiB;IAChC,6EAA6E;IAC7E,GAAG,EAAE,UAAU,CAAC;IAChB,sGAAsG;IACtG,GAAG,EAAE,UAAU,CAAC;IAChB,gGAAgG;IAChG,MAAM,EAAE,UAAU,CAAC;IACnB,8BAA8B;IAC9B,OAAO,EAAE,UAAU,CAAC;IACpB,0CAA0C;IAC1C,SAAS,EAAE,IAAI,CAAC;IAChB,iCAAiC;IACjC,QAAQ,EAAE,IAAI,CAAC;IACf,gFAAgF;IAChF,IAAI,EAAE,UAAU,CAAC;IACjB,yCAAyC;IACzC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;IACzB,wEAAwE;IACxE,kBAAkB,EAAE,MAAM,CAAC;IAC3B,uEAAuE;IACvE,SAAS,EAAE,UAAU,CAAC;IACtB,6GAA6G;IAC7G,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC;IAC9C,uGAAuG;IACvG,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC,sGAAsG;IACtG,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,yGAAyG;AACzG,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,SAAS,CAAC;IACf,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;CAC1B;AAED,iGAAiG;AACjG,MAAM,WAAW,kBAAkB;IACjC,gGAAgG;IAChG,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IACzB,mEAAmE;IACnE,GAAG,EAAE,IAAI,CAAC;IACV;;;;OAIG;IACH,qBAAqB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtC,sGAAsG;IACtG,uBAAuB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACzC;AA6FD;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,UAAU,GAAG,iBAAiB,CAuCnE;AAiCD;;;;GAIG;AACH,wBAAsB,sBAAsB,CAC1C,KAAK,EAAE,SAAS,UAAU,EAAE,EAC5B,OAAO,EAAE,kBAAkB,GAC1B,OAAO,CAAC,YAAY,CAAC,CA6EvB"}