@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,350 @@
1
+ import { PaymentsProviderUnavailableError, PaymentsRailNotConfiguredError, PaymentsVerificationFailedError } from "../../error/errors.js";
2
+ import { googleHttpFetch, googleJson } from "./http.js";
3
+ import { base64UrlEncode, pemPrivateKey } from "./jwt.js";
4
+ import { pauseResumesAt } from "../../data/pause.js";
5
+ import { z } from "zod";
6
+ //#region src/rails/google/playApi.ts
7
+ /**
8
+ * The Play Developer API — the call that turns a purchase token into a state, and the mapping of Play's
9
+ * vocabulary into the normalized status set.
10
+ *
11
+ * This is the half of Google's rail that has no Apple equivalent. A StoreKit transaction *is* the state, signed;
12
+ * a Play purchase token is a pointer, so every Google projection costs a network round-trip. Two, in fact — the
13
+ * API is OAuth-protected, so a service-account assertion buys an access token first.
14
+ *
15
+ * ## Two statuses Play has and the other rails do not
16
+ *
17
+ * `on_hold` and `paused` are Play's own. **On hold** is a subscription whose billing retry window has run out:
18
+ * Google keeps trying for up to 30 days and access is withdrawn throughout, which is why `on_hold` never
19
+ * grants. **Paused** is a subscription the *user* suspended, usually with an `autoResumeTime` set; they will
20
+ * come back, and until they do they are not entitled — so that date lands on the row as `resumesAt`, and its
21
+ * absence is Play reporting an indefinite pause rather than this rail declining to look (`data/pause.ts`).
22
+ * Neither state has an Apple analog, and both would be lost by a status set built from Apple's
23
+ * notifications alone.
24
+ *
25
+ * ## What Play does not report, and what follows
26
+ *
27
+ * **No price.** Neither `purchases.subscriptionsv2.get` nor `purchases.products.get` returns an amount or a
28
+ * currency, so `amountMinor` and `currency` are null on every Google purchase. That is what those columns are
29
+ * nullable for. Revenue figures for the Play rail come from Google's own reporting, not from here.
30
+ *
31
+ * **No last-modified time.** So the caller supplies the event time: the notification's `eventTimeMillis` on the
32
+ * webhook path, and the clock on a client submission. Both are honest — a submission is a read of the current
33
+ * state, so treating it as the freshest fact is right — and both feed the monotonic write rule, which is why
34
+ * neither may be invented here.
35
+ *
36
+ * ## The environment check
37
+ *
38
+ * A test purchase is a real Play purchase made by a license-tested account, and it must never grant a
39
+ * production entitlement. Play marks one differently in each shape: `testPurchase` is present on a
40
+ * subscription, `purchaseType: 0` on a one-time product. Both are read, and anything unmarked is production —
41
+ * which is safe because Play only ever omits the marker on a real purchase.
42
+ */
43
+ /** Google's OAuth token endpoint. The audience of the service-account assertion as well as its destination. */
44
+ const GOOGLE_TOKEN_URL = "https://oauth2.googleapis.com/token";
45
+ /** The Play Developer API's base. Public, so it is pinned here rather than configured. */
46
+ const PLAY_API_BASE = "https://androidpublisher.googleapis.com/androidpublisher/v3";
47
+ /** The one OAuth scope payments asks for. Read-and-acknowledge on purchases, nothing else in the console. */
48
+ const PLAY_SCOPE = "https://www.googleapis.com/auth/androidpublisher";
49
+ /** RSASSA-PKCS1-v1_5 with SHA-256 — `RS256`, the algorithm a Google service-account assertion is signed with. */
50
+ const RS256 = {
51
+ name: "RSASSA-PKCS1-v1_5",
52
+ hash: "SHA-256"
53
+ };
54
+ /** How long an assertion claims to be good for. Google's ceiling is an hour and there is no reason to ask less. */
55
+ const ASSERTION_LIFETIME_SECONDS = 3600;
56
+ /** Play's `purchaseType` for a license-test purchase. The one-time equivalent of `testPurchase`. */
57
+ const PLAY_PURCHASE_TYPE_TEST = 0;
58
+ /**
59
+ * Play's subscription states, mapped.
60
+ *
61
+ * Two are worth reading twice. **`CANCELED` still grants**: the user turned auto-renew off and keeps the period
62
+ * they paid for, which `expiresAt` ends — mapping it to anything non-granting would strip access from somebody
63
+ * who is still paid up. And **`PENDING` does not**: a deferred-payment purchase (cash, direct debit) has not
64
+ * been paid yet, so it is treated as `on_hold` — not `expired`, because it may still become active.
65
+ *
66
+ * `PENDING_PURCHASE_CANCELED` is `never_paid`: the deferred payment never arrived and never will. Deliberately
67
+ * not `canceled`, which grants; not `refunded`, because no money moved; and **not `expired`**, because an
68
+ * expired period is one we were paid for and a `grants` clause credits on it.
69
+ */
70
+ const SUBSCRIPTION_STATES = {
71
+ SUBSCRIPTION_STATE_ACTIVE: "active",
72
+ SUBSCRIPTION_STATE_IN_GRACE_PERIOD: "in_grace",
73
+ SUBSCRIPTION_STATE_ON_HOLD: "on_hold",
74
+ SUBSCRIPTION_STATE_PAUSED: "paused",
75
+ SUBSCRIPTION_STATE_CANCELED: "canceled",
76
+ SUBSCRIPTION_STATE_EXPIRED: "expired",
77
+ SUBSCRIPTION_STATE_PENDING: "on_hold",
78
+ SUBSCRIPTION_STATE_PENDING_PURCHASE_CANCELED: "never_paid"
79
+ };
80
+ /**
81
+ * Play's one-time purchase states, mapped.
82
+ *
83
+ * `1` is Play's `Canceled`, and it is the trap in this table. It must **not** become the normalized `canceled`,
84
+ * which means "auto-renew off, still granting" — Play means the order was taken back. It is mapped to
85
+ * `refunded`, which is the normalized member for "taken back", does not grant, and is the state an opt-in
86
+ * clawback acts on. Play cannot distinguish a refunded order from a deferred purchase that was canceled before
87
+ * payment, so a clawback on the latter finds nothing to debit and is refused into a recorded state — which is
88
+ * the designed behavior for a failed clawback rather than a defect.
89
+ *
90
+ * `2` is `Pending`: awaiting a deferred payment, so it does not grant, and `on_hold` is the member that says so
91
+ * without claiming the purchase is over.
92
+ */
93
+ const PRODUCT_STATES = {
94
+ 0: "active",
95
+ 1: "refunded",
96
+ 2: "on_hold"
97
+ };
98
+ /** Google's OAuth token response, narrowed to the one field that matters. */
99
+ const GoogleAccessToken = z.object({
100
+ access_token: z.string().min(1).describe("The bearer token the Play Developer API is called with."),
101
+ expires_in: z.number().int().optional().describe("How long it lasts, in seconds. Informational here."),
102
+ token_type: z.string().min(1).optional().describe("Always `Bearer` in practice.")
103
+ }).loose().describe("Google's OAuth 2.0 token response to a service-account assertion.");
104
+ /** One line item on a subscription — the product, and when its paid period ends. */
105
+ const PlaySubscriptionLineItem = z.object({
106
+ productId: z.string().min(1).describe("The subscription product id as listed in the Play Console — the SKU the catalog maps."),
107
+ expiryTime: z.string().min(1).optional().describe("When the paid period ends, RFC 3339. Absent on a paused or never-paid subscription."),
108
+ autoRenewingPlan: z.object({ autoRenewEnabled: z.boolean().optional().describe("Whether the plan will renew. Reported, never mapped.") }).loose().optional().describe("The auto-renewing plan's own state, when the line item is one.")
109
+ }).loose().describe("One line item of a Play subscription purchase.");
110
+ /**
111
+ * `purchases.subscriptionsv2.get`, as much of it as the projection reads. `.loose()` keeps the rest: Play adds
112
+ * fields, the whole response is stored for reconciliation, and a strict object would refuse a real purchase for
113
+ * carrying something new.
114
+ */
115
+ const PlaySubscriptionPurchase = z.object({
116
+ subscriptionState: z.string().min(1).describe("Play's own state for the subscription. Mapped to a normalized status; an unknown one is refused."),
117
+ latestOrderId: z.string().min(1).optional().describe("The most recent order. This is the transaction identity — it changes every renewal, which is what makes each period its own purchase row."),
118
+ startTime: z.string().min(1).optional().describe("When the subscription began, RFC 3339."),
119
+ linkedPurchaseToken: z.string().min(1).optional().describe("The token this purchase replaced, on an upgrade or a resubscribe."),
120
+ acknowledgementState: z.string().min(1).optional().describe("Whether the app has acknowledged the purchase. Recorded, never mapped: an unacknowledged purchase is still paid, and acknowledging is the app's job through Play Billing."),
121
+ testPurchase: z.object({}).loose().optional().describe("Present only for a license-test purchase. Its presence is the whole environment decision for a subscription."),
122
+ pausedStateContext: z.object({ autoResumeTime: z.string().min(1).optional().describe("When a paused subscription resumes, RFC 3339.") }).loose().optional().describe("Present while the subscription is paused."),
123
+ externalAccountIdentifiers: z.object({
124
+ obfuscatedExternalAccountId: z.string().min(1).optional().describe("The identifier the app set at purchase time — the only hook back to the subject that bought."),
125
+ obfuscatedExternalProfileId: z.string().min(1).optional().describe("The profile identifier, if the app set one.")
126
+ }).loose().optional().describe("The identifiers the app attached to the purchase."),
127
+ lineItems: z.array(PlaySubscriptionLineItem).min(1).describe("What the subscription includes. The first line item is the product this purchase is projected as.")
128
+ }).loose().describe("Play's SubscriptionPurchaseV2, as much of it as the projection reads.");
129
+ /** `purchases.products.get`, as much of it as the projection reads. `.loose()` for the same reason. */
130
+ const PlayProductPurchase = z.object({
131
+ purchaseState: z.number().int().describe("0 purchased, 1 canceled, 2 pending. Mapped to a normalized status; an unknown one is refused."),
132
+ purchaseTimeMillis: z.string().regex(/^\d+$/).optional().describe("When the purchase was made, as a decimal string of milliseconds since the epoch."),
133
+ orderId: z.string().min(1).optional().describe("The order. This is the transaction identity for a one-time purchase. Absent until it is paid."),
134
+ purchaseType: z.number().int().optional().describe("0 test, 1 promo, 2 rewarded — and absent for an ordinary paid purchase. Only 0 makes it a sandbox purchase."),
135
+ acknowledgementState: z.number().int().optional().describe("0 unacknowledged, 1 acknowledged. Recorded, never mapped — the app owns acknowledging."),
136
+ consumptionState: z.number().int().optional().describe("0 yet to be consumed, 1 consumed. Recorded only."),
137
+ quantity: z.number().int().optional().describe("How many were bought. One unless the product allows more."),
138
+ obfuscatedExternalAccountId: z.string().min(1).optional().describe("The identifier the app set at purchase time — the only hook back to the subject that bought."),
139
+ regionCode: z.string().min(1).optional().describe("Where the purchase was made. Recorded only.")
140
+ }).loose().describe("Play's ProductPurchase, as much of it as the projection reads.");
141
+ /**
142
+ * Mint an access token for the Play Developer API from the service-account key.
143
+ *
144
+ * The JWT-bearer grant: we sign an assertion saying who we are and what we want, Google hands back a token. No
145
+ * refresh token, no user consent, nothing stored — which is why the credential bundle holds a private key
146
+ * rather than an OAuth client.
147
+ */
148
+ async function mintPlayAccessToken(credentials, options) {
149
+ let key;
150
+ try {
151
+ key = await crypto.subtle.importKey("pkcs8", pemPrivateKey(credentials.privateKey), RS256, false, ["sign"]);
152
+ } catch (cause) {
153
+ if (cause instanceof PaymentsRailNotConfiguredError) throw cause;
154
+ throw new PaymentsRailNotConfiguredError({ detail: "Google: the service-account private key could not be imported as a PKCS#8 RSA key." }, { cause });
155
+ }
156
+ const issuedAt = Math.floor(options.now.getTime() / 1e3);
157
+ const encoder = new TextEncoder();
158
+ const head = base64UrlEncode(encoder.encode(JSON.stringify({
159
+ alg: "RS256",
160
+ typ: "JWT"
161
+ })));
162
+ const body = base64UrlEncode(encoder.encode(JSON.stringify({
163
+ iss: credentials.serviceAccountEmail,
164
+ scope: PLAY_SCOPE,
165
+ aud: GOOGLE_TOKEN_URL,
166
+ iat: issuedAt,
167
+ exp: issuedAt + ASSERTION_LIFETIME_SECONDS
168
+ })));
169
+ const signature = new Uint8Array(await crypto.subtle.sign(RS256.name, key, encoder.encode(`${head}.${body}`)));
170
+ const assertion = `${head}.${body}.${base64UrlEncode(signature)}`;
171
+ const answered = await googleJson(options.transport ?? googleHttpFetch, GOOGLE_TOKEN_URL, {
172
+ what: "an access token for the Play Developer API",
173
+ method: "POST",
174
+ headers: { "content-type": "application/x-www-form-urlencoded" },
175
+ body: new URLSearchParams({
176
+ grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer",
177
+ assertion
178
+ }).toString()
179
+ });
180
+ const parsed = GoogleAccessToken.safeParse(answered);
181
+ if (!parsed.success) throw new PaymentsProviderUnavailableError({ detail: "Google: the token endpoint answered without an access token." });
182
+ return parsed.data.access_token;
183
+ }
184
+ /** The access token for one lookup: the caller's, or a freshly minted one. */
185
+ async function bearer(options) {
186
+ return options.accessToken ?? await mintPlayAccessToken(options.credentials, options);
187
+ }
188
+ /**
189
+ * The current state of a subscription purchase token, or `undefined` when Play has no subscription under it.
190
+ *
191
+ * `undefined` is how a one-time purchase identifies itself: Play has no "what kind of purchase is this" call, so
192
+ * the subscription endpoint's 404 is the answer. That is why this is the probe and the product lookup is the
193
+ * fallback — the subscription call takes a token alone, while the product call needs a product id we would
194
+ * otherwise have to take on a client's word.
195
+ */
196
+ async function fetchPlaySubscription(purchaseToken, options) {
197
+ const url = `${PLAY_API_BASE}/applications/${encodeURIComponent(options.credentials.packageName)}/purchases/subscriptionsv2/tokens/${encodeURIComponent(purchaseToken)}`;
198
+ const answered = await googleJson(options.transport ?? googleHttpFetch, url, {
199
+ what: "the subscription purchase",
200
+ headers: { authorization: `Bearer ${await bearer(options)}` },
201
+ absentOn404: true
202
+ });
203
+ if (answered === void 0) return void 0;
204
+ return parseOrRefuse(PlaySubscriptionPurchase, answered, "SubscriptionPurchaseV2");
205
+ }
206
+ /**
207
+ * The current state of a one-time purchase token under one product id, or `undefined` when Play has none.
208
+ *
209
+ * The product id is part of the URL, which is what makes a client-declared one safe to use: Play answers 404
210
+ * when the token does not belong to that product, so presenting a cheap token under an expensive SKU fails at
211
+ * Google rather than being believed here.
212
+ */
213
+ async function fetchPlayProduct(productId, purchaseToken, options) {
214
+ const url = `${PLAY_API_BASE}/applications/${encodeURIComponent(options.credentials.packageName)}/purchases/products/${encodeURIComponent(productId)}/tokens/${encodeURIComponent(purchaseToken)}`;
215
+ const answered = await googleJson(options.transport ?? googleHttpFetch, url, {
216
+ what: "the one-time purchase",
217
+ headers: { authorization: `Bearer ${await bearer(options)}` },
218
+ absentOn404: true
219
+ });
220
+ if (answered === void 0) return void 0;
221
+ return parseOrRefuse(PlayProductPurchase, answered, "ProductPurchase");
222
+ }
223
+ /** The normalized status for a Play subscription state. An unmapped state is refused, never granted. */
224
+ function playSubscriptionStatus(state) {
225
+ const status = SUBSCRIPTION_STATES[state];
226
+ if (status === void 0) throw new PaymentsVerificationFailedError({ detail: `Google: subscription state "${state}" is not one this build maps. The purchase was left as it stood.` });
227
+ return status;
228
+ }
229
+ /** The normalized status for a Play one-time purchase state. An unmapped state is refused, never granted. */
230
+ function playProductStatus(purchaseState) {
231
+ const status = PRODUCT_STATES[purchaseState];
232
+ if (status === void 0) throw new PaymentsVerificationFailedError({ detail: `Google: purchase state ${purchaseState} is not one this build maps. The purchase was left as it stood.` });
233
+ return status;
234
+ }
235
+ /** One Play subscription purchase, normalized. */
236
+ function playSubscriptionEvent(purchase, context) {
237
+ const item = purchase.lineItems[0];
238
+ const status = context.statusOverride ?? playSubscriptionStatus(purchase.subscriptionState);
239
+ const expiresAt = item.expiryTime === void 0 ? null : timestamp(item.expiryTime, "the expiry time");
240
+ return {
241
+ event: {
242
+ rail: "google",
243
+ providerTransactionId: purchase.latestOrderId ?? context.purchaseToken,
244
+ providerProductId: item.productId,
245
+ status,
246
+ environment: subscriptionEnvironment(purchase),
247
+ purchasedAt: purchase.startTime === void 0 ? context.eventAt : timestamp(purchase.startTime, "the start time"),
248
+ expiresAt,
249
+ revokedAt: status === "revoked" || status === "refunded" ? context.eventAt : null,
250
+ resumesAt: pauseResumesAt({
251
+ rail: "google",
252
+ status,
253
+ reported: purchase.pausedStateContext?.autoResumeTime
254
+ }),
255
+ originalTransactionId: context.purchaseToken,
256
+ amountMinor: null,
257
+ currency: null,
258
+ providerEventAt: context.eventAt,
259
+ payload: purchase
260
+ },
261
+ providerAccountId: purchase.externalAccountIdentifiers?.obfuscatedExternalAccountId ?? null
262
+ };
263
+ }
264
+ /** One Play one-time purchase, normalized. */
265
+ function playProductEvent(purchase, context) {
266
+ const status = context.statusOverride ?? playProductStatus(purchase.purchaseState);
267
+ return {
268
+ event: {
269
+ rail: "google",
270
+ providerTransactionId: purchase.orderId ?? context.purchaseToken,
271
+ providerProductId: context.productId,
272
+ status,
273
+ environment: purchase.purchaseType === PLAY_PURCHASE_TYPE_TEST ? "sandbox" : "production",
274
+ purchasedAt: purchase.purchaseTimeMillis === void 0 ? context.eventAt : new Date(Number(purchase.purchaseTimeMillis)),
275
+ expiresAt: null,
276
+ revokedAt: status === "revoked" || status === "refunded" ? context.eventAt : null,
277
+ originalTransactionId: null,
278
+ amountMinor: null,
279
+ currency: null,
280
+ providerEventAt: context.eventAt,
281
+ payload: purchase
282
+ },
283
+ providerAccountId: purchase.obfuscatedExternalAccountId ?? null
284
+ };
285
+ }
286
+ /**
287
+ * Resolve one notification pointer to a state, or `undefined` when Play has no purchase under that token.
288
+ *
289
+ * The pointer says which lookup to make, so there is no probing on this path — the notification already told us
290
+ * whether it concerns a subscription or a one-time product.
291
+ */
292
+ async function resolvePlayPointer(pointer, options) {
293
+ const context = {
294
+ purchaseToken: pointer.purchaseToken,
295
+ eventAt: pointer.eventAt,
296
+ statusOverride: pointer.statusOverride
297
+ };
298
+ if (pointer.kind === "subscription") {
299
+ const purchase = await fetchPlaySubscription(pointer.purchaseToken, options);
300
+ return purchase === void 0 ? void 0 : playSubscriptionEvent(purchase, context);
301
+ }
302
+ if (pointer.productId === null) return void 0;
303
+ const purchase = await fetchPlayProduct(pointer.productId, pointer.purchaseToken, options);
304
+ return purchase === void 0 ? void 0 : playProductEvent(purchase, {
305
+ ...context,
306
+ productId: pointer.productId
307
+ });
308
+ }
309
+ /**
310
+ * Re-read one stored purchase at Play, normalized — the reconciliation path for this rail.
311
+ *
312
+ * **Subscriptions only, and the reason is what the row keeps.** A Play purchase is addressed by its *purchase
313
+ * token*, and only a subscription row stores one: `originalTransactionId` is the token, because the token is
314
+ * the family key every renewal shares. A one-time row is keyed on Play's order id and stores no token at all,
315
+ * and `purchases.products.get` takes a token — so there is no call this function could make for one. That is a
316
+ * real gap rather than a shortcut: a refunded one-time Play purchase reaches this deployment as a
317
+ * voided-purchase notification, which is recorded with its order id and its reason, and repairing it needs the
318
+ * token recovered from somewhere the row does not have it.
319
+ *
320
+ * A subscription that has never been paid has no order id yet and is keyed on its own token, so
321
+ * `originalTransactionId` is null and `providerTransactionId` is the token. Both spellings resolve.
322
+ */
323
+ async function refreshPlayPurchase(purchase, options) {
324
+ if (purchase.type !== "subscription") return void 0;
325
+ const purchaseToken = purchase.originalTransactionId ?? purchase.providerTransactionId;
326
+ const found = await fetchPlaySubscription(purchaseToken, options);
327
+ if (found === void 0) return void 0;
328
+ return playSubscriptionEvent(found, {
329
+ purchaseToken,
330
+ eventAt: options.now
331
+ }).event;
332
+ }
333
+ /** A subscription's environment. `testPurchase` present is the whole decision; absent means a real purchase. */
334
+ function subscriptionEnvironment(purchase) {
335
+ return purchase.testPurchase === void 0 ? "production" : "sandbox";
336
+ }
337
+ /** One RFC 3339 timestamp from Play. An unreadable one is refused rather than becoming an Invalid Date. */
338
+ function timestamp(value, what) {
339
+ const parsed = new Date(value);
340
+ if (Number.isNaN(parsed.getTime())) throw new PaymentsVerificationFailedError({ detail: `Google: ${what} "${value}" is not a timestamp.` });
341
+ return parsed;
342
+ }
343
+ /** Parse a Play response, or refuse it. Never echoes the body: the response quotes the purchase token. */
344
+ function parseOrRefuse(schema, value, what) {
345
+ const parsed = schema.safeParse(value);
346
+ if (!parsed.success) throw new PaymentsVerificationFailedError({ detail: `Google: the answer is not a ${what} — ${parsed.error.issues.map((issue) => `${issue.path.join(".") || "<root>"}:${issue.code}`).join(", ")}.` });
347
+ return parsed.data;
348
+ }
349
+ //#endregion
350
+ export { GOOGLE_TOKEN_URL, PLAY_API_BASE, PLAY_SCOPE, PlayProductPurchase, PlaySubscriptionPurchase, fetchPlayProduct, fetchPlaySubscription, mintPlayAccessToken, playProductEvent, playProductStatus, playSubscriptionEvent, playSubscriptionStatus, refreshPlayPurchase, resolvePlayPointer };
@@ -0,0 +1,57 @@
1
+ import type { PaymentsGoogleCredentials } from "../../secret/registry";
2
+ import type { PaymentsRailProvider } from "../contract";
3
+ import type { GoogleHttpFetch } from "./http";
4
+ import { type GoogleJwk } from "./oidc";
5
+ /**
6
+ * The Google Play rail as one provider object — the two halves of the contract, closed over the app's identity.
7
+ *
8
+ * Built per request from credentials the caller resolved through the secrets store, rather than reading them
9
+ * itself. That keeps the rail a pure function of its inputs, and it keeps the secret read at the point of need.
10
+ *
11
+ * ## Three checks, in this order, and each covers what the one before it cannot
12
+ *
13
+ * 1. **The OIDC token proves Google sent the delivery.** It arrives in the `Authorization` header rather than in
14
+ * the body, because a Pub/Sub push is not signed — the token is the whole proof.
15
+ * 2. **The audience claim proves it was minted for *this* endpoint.** Google signs these tokens for every push
16
+ * subscription in the world with the same keys, so the signature alone is worth nothing. See `oidc.ts`.
17
+ * 3. **The package name proves it concerns *this app*.** A token says who delivered it and nothing about what it
18
+ * is about, so without this any Play developer who can reach the endpoint could name a SKU in our catalog.
19
+ *
20
+ * ## And then a fourth call, which is Google's own doing
21
+ *
22
+ * A Real-time Developer Notification is a pointer: a purchase token and a notification type, with no state. So
23
+ * every projectable notification costs a Play Developer API lookup. That is the shape of Play's API rather than
24
+ * a choice here, and it is why an unreachable Play API is `payments/provider_unavailable` (503) — the route
25
+ * rethrows that so Pub/Sub redelivers, because the alternative is projecting a guess.
26
+ *
27
+ * ## One gap, recorded rather than papered over
28
+ *
29
+ * A **voided one-time purchase** cannot be resolved on this path. Play's voided-purchase notification names an
30
+ * order id and no product, and Play's one-time lookup takes the product id as a path segment — so there is no
31
+ * call this module can make that turns that token into a state. The delivery is recorded with a note carrying
32
+ * the order id, which is the key the purchase row is already stored under, and the reconciliation Workflow
33
+ * resolves it with one query. Subscription refunds have no such gap: they arrive as `SUBSCRIPTION_REVOKED` and
34
+ * project immediately.
35
+ */
36
+ /**
37
+ * How the Google rail's trust and transport may be widened, and the only callers with a reason to.
38
+ *
39
+ * `trustedKeys` is additive, so nothing can narrow production's trust: a token whose `kid` these do not cover is
40
+ * still resolved against Google's published set. It exists for the tests, which mint their own key so the
41
+ * signature check is exercised for real, and for a local **Pub/Sub emulator**, whose tokens are signed by a key
42
+ * Google never saw.
43
+ */
44
+ export interface GoogleRailOptions {
45
+ /** Verification keys accepted in addition to Google's published set, matched by `kid`. */
46
+ trustedKeys?: readonly GoogleJwk[];
47
+ /** The HTTP seam Google's two endpoints are reached through. Defaults to the runtime's `fetch`. */
48
+ transport?: GoogleHttpFetch;
49
+ /**
50
+ * A Play access token already minted, so a batch of refreshes pays for one round-trip instead of one each.
51
+ * Passed down by the reconciliation Workflow; absent everywhere else, where one call mints its own.
52
+ */
53
+ accessToken?: string;
54
+ }
55
+ /** The Google Play rail. Verifies client submissions at Play, and Pub/Sub pushes on the webhook. */
56
+ export declare function googleRail(credentials: PaymentsGoogleCredentials, options?: GoogleRailOptions): PaymentsRailProvider;
57
+ //# sourceMappingURL=rail.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rail.d.ts","sourceRoot":"","sources":["../../../src/rails/google/rail.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,KAAK,EACV,oBAAoB,EAMrB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,KAAK,SAAS,EAAyB,MAAM,QAAQ,CAAC;AAK/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH;;;;;;;GAOG;AACH,MAAM,WAAW,iBAAiB;IAChC,0FAA0F;IAC1F,WAAW,CAAC,EAAE,SAAS,SAAS,EAAE,CAAC;IACnC,mGAAmG;IACnG,SAAS,CAAC,EAAE,eAAe,CAAC;IAC5B;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAKD,oGAAoG;AACpG,wBAAgB,UAAU,CACxB,WAAW,EAAE,yBAAyB,EACtC,OAAO,GAAE,iBAAsB,GAC9B,oBAAoB,CA8FtB"}
@@ -0,0 +1,70 @@
1
+ import { PaymentsVerificationFailedError } from "../../error/errors.js";
2
+ import { verifyGoogleOidcToken } from "./oidc.js";
3
+ import { refreshPlayPurchase, resolvePlayPointer } from "./playApi.js";
4
+ import { parseGoogleNotification } from "./rtdn.js";
5
+ import { verifyGooglePurchase } from "./verify.js";
6
+ //#region src/rails/google/rail.ts
7
+ /** The `Authorization` scheme a Pub/Sub push uses for its OIDC token. */
8
+ const BEARER = "bearer ";
9
+ /** The Google Play rail. Verifies client submissions at Play, and Pub/Sub pushes on the webhook. */
10
+ function googleRail(credentials, options = {}) {
11
+ return {
12
+ rail: "google",
13
+ async verify(receipt, context) {
14
+ return await verifyGooglePurchase(receipt, {
15
+ credentials,
16
+ now: context.now,
17
+ transport: options.transport
18
+ });
19
+ },
20
+ async parseNotification(delivery, context) {
21
+ const authorization = delivery.headers.get("authorization") ?? "";
22
+ if (!authorization.toLowerCase().startsWith(BEARER)) throw new PaymentsVerificationFailedError({ detail: "Google: the push carries no Authorization bearer token. Configure the Pub/Sub push subscription to authenticate with a service account." });
23
+ await verifyGoogleOidcToken(authorization.slice(7).trim(), {
24
+ audience: credentials.pubsubAudience,
25
+ serviceAccountEmail: credentials.serviceAccountEmail,
26
+ now: context.now,
27
+ transport: options.transport,
28
+ trustedKeys: options.trustedKeys
29
+ });
30
+ const parsed = parseGoogleNotification(delivery.body, { packageName: credentials.packageName });
31
+ if (parsed.pointer === null) return {
32
+ providerEventId: parsed.providerEventId,
33
+ payload: parsed.payload,
34
+ event: null,
35
+ providerAccountId: null,
36
+ voidedOrderId: parsed.voidedOrderId,
37
+ note: parsed.note === null ? null : { stated: parsed.note }
38
+ };
39
+ const state = await resolvePlayPointer(parsed.pointer, {
40
+ credentials,
41
+ now: context.now,
42
+ transport: options.transport
43
+ });
44
+ if (state === void 0) return {
45
+ providerEventId: parsed.providerEventId,
46
+ payload: parsed.payload,
47
+ event: null,
48
+ providerAccountId: null,
49
+ note: { read: `google: Play has no ${parsed.pointer.kind === "subscription" ? "subscription" : "one-time purchase"} under the token this notification points at.` }
50
+ };
51
+ return {
52
+ providerEventId: parsed.providerEventId,
53
+ payload: parsed.payload,
54
+ event: state.event,
55
+ providerAccountId: state.providerAccountId,
56
+ note: null
57
+ };
58
+ },
59
+ async refresh(purchase, context) {
60
+ return await refreshPlayPurchase(purchase, {
61
+ credentials,
62
+ now: context.now,
63
+ transport: options.transport,
64
+ accessToken: options.accessToken
65
+ });
66
+ }
67
+ };
68
+ }
69
+ //#endregion
70
+ export { googleRail };
@@ -0,0 +1,105 @@
1
+ import { z } from "zod";
2
+ import type { PurchaseStatus } from "../../data/status";
3
+ /** The Pub/Sub push envelope. `.loose()` so a new envelope field never refuses a real notification. */
4
+ export declare const GooglePubSubPush: z.ZodObject<{
5
+ message: z.ZodObject<{
6
+ data: z.ZodString;
7
+ messageId: z.ZodString;
8
+ publishTime: z.ZodOptional<z.ZodString>;
9
+ }, z.core.$loose>;
10
+ subscription: z.ZodOptional<z.ZodString>;
11
+ }, z.core.$loose>;
12
+ export type GooglePubSubPush = z.infer<typeof GooglePubSubPush>;
13
+ /** One Play Developer Notification. Exactly one of the four notification blocks is present. */
14
+ export declare const GoogleDeveloperNotification: z.ZodObject<{
15
+ version: z.ZodString;
16
+ packageName: z.ZodString;
17
+ eventTimeMillis: z.ZodString;
18
+ subscriptionNotification: z.ZodOptional<z.ZodObject<{
19
+ version: z.ZodString;
20
+ notificationType: z.ZodNumber;
21
+ purchaseToken: z.ZodString;
22
+ subscriptionId: z.ZodString;
23
+ }, z.core.$loose>>;
24
+ oneTimeProductNotification: z.ZodOptional<z.ZodObject<{
25
+ version: z.ZodString;
26
+ notificationType: z.ZodNumber;
27
+ purchaseToken: z.ZodString;
28
+ sku: z.ZodString;
29
+ }, z.core.$loose>>;
30
+ voidedPurchaseNotification: z.ZodOptional<z.ZodObject<{
31
+ purchaseToken: z.ZodString;
32
+ orderId: z.ZodString;
33
+ productType: z.ZodNumber;
34
+ refundType: z.ZodOptional<z.ZodNumber>;
35
+ }, z.core.$loose>>;
36
+ testNotification: z.ZodOptional<z.ZodObject<{
37
+ version: z.ZodString;
38
+ }, z.core.$loose>>;
39
+ }, z.core.$loose>;
40
+ export type GoogleDeveloperNotification = z.infer<typeof GoogleDeveloperNotification>;
41
+ /** Which Play lookup resolves a pointer. The two take different endpoints and different path parameters. */
42
+ export type GoogleNotificationKind = "subscription" | "one_time";
43
+ /**
44
+ * Which purchase a notification is about. Deliberately carries no state — see the module doc.
45
+ */
46
+ export interface GoogleNotificationPointer {
47
+ /** Which Play lookup resolves it. */
48
+ kind: GoogleNotificationKind;
49
+ /** The purchase token the lookup is keyed by. */
50
+ purchaseToken: string;
51
+ /** The product id, when the notification names one. Required for a one-time lookup, informational otherwise. */
52
+ productId: string | null;
53
+ /** Play's own notification type. Reported and audited; never mapped to a status. */
54
+ notificationType: number;
55
+ /**
56
+ * The one status the Play API cannot report and the notification can. `revoked` for a revoked subscription,
57
+ * which the API reports as merely expired, and null for everything else.
58
+ */
59
+ statusOverride: PurchaseStatus | null;
60
+ /** Google's own event time. What the monotonic write rule compares against. */
61
+ eventAt: Date;
62
+ }
63
+ /** A verified, decoded notification: what to record, and what to resolve. */
64
+ export interface ParsedGoogleNotification {
65
+ /** Pub/Sub's message id — the dedupe key. */
66
+ providerEventId: string;
67
+ /** What to store on the webhook row: the decoded notification plus the envelope's own metadata. */
68
+ payload: Record<string, unknown>;
69
+ /** The app the notification concerns, already checked against ours. */
70
+ packageName: string;
71
+ /** Google's own event time. */
72
+ eventAt: Date;
73
+ /** Which purchase changed, or null when the notification concerns none. */
74
+ pointer: GoogleNotificationPointer | null;
75
+ /**
76
+ * Why a notification with no pointer had none, when that is worth recording. Null when there is nothing to
77
+ * say — a test notification needs no explanation.
78
+ */
79
+ note: string | null;
80
+ /**
81
+ * The order a voided-purchase notification refunded, or null. Reported rather than only described, because
82
+ * an order id is exactly what a Google purchase's `providerTransactionId` is — so the route can find the
83
+ * row this refund is about even though Play offers no lookup that would.
84
+ */
85
+ voidedOrderId: string | null;
86
+ }
87
+ /** What parsing needs: our own application id, and nothing else. */
88
+ export interface ParseGoogleNotificationOptions {
89
+ /** Our Android application id. A notification for any other app is refused. */
90
+ packageName: string;
91
+ }
92
+ /**
93
+ * Decode one Pub/Sub push into a pointer.
94
+ *
95
+ * Authenticity is not established here — that is `verifyGoogleOidcToken`, and it runs first. What this adds is
96
+ * the check a token cannot make: Google signs a push token for every Pub/Sub subscription there is, so a valid
97
+ * token says nothing about which app a notification concerns. Without the package check, any Play developer who
98
+ * can reach our endpoint can send us a SKU that happens to match our catalog.
99
+ *
100
+ * @throws {@link PaymentsInvalidReceiptError} when the body cannot be read as a Pub/Sub push carrying a
101
+ * Developer Notification.
102
+ * @throws {@link PaymentsVerificationFailedError} when it is readable and concerns another app.
103
+ */
104
+ export declare function parseGoogleNotification(body: string, options: ParseGoogleNotificationOptions): ParsedGoogleNotification;
105
+ //# sourceMappingURL=rtdn.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rtdn.d.ts","sourceRoot":"","sources":["../../../src/rails/google/rtdn.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AA0CxD,uGAAuG;AACvG,eAAO,MAAM,gBAAgB;;;;;;;iBAyB4B,CAAC;AAC1D,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAEhE,+FAA+F;AAC/F,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;iBAiEsD,CAAC;AAC/F,MAAM,MAAM,2BAA2B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAEtF,4GAA4G;AAC5G,MAAM,MAAM,sBAAsB,GAAG,cAAc,GAAG,UAAU,CAAC;AAEjE;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,qCAAqC;IACrC,IAAI,EAAE,sBAAsB,CAAC;IAC7B,iDAAiD;IACjD,aAAa,EAAE,MAAM,CAAC;IACtB,gHAAgH;IAChH,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,oFAAoF;IACpF,gBAAgB,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,cAAc,EAAE,cAAc,GAAG,IAAI,CAAC;IACtC,+EAA+E;IAC/E,OAAO,EAAE,IAAI,CAAC;CACf;AAED,6EAA6E;AAC7E,MAAM,WAAW,wBAAwB;IACvC,6CAA6C;IAC7C,eAAe,EAAE,MAAM,CAAC;IACxB,mGAAmG;IACnG,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,uEAAuE;IACvE,WAAW,EAAE,MAAM,CAAC;IACpB,+BAA+B;IAC/B,OAAO,EAAE,IAAI,CAAC;IACd,2EAA2E;IAC3E,OAAO,EAAE,yBAAyB,GAAG,IAAI,CAAC;IAC1C;;;OAGG;IACH,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB;;;;OAIG;IACH,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B;AAED,oEAAoE;AACpE,MAAM,WAAW,8BAA8B;IAC7C,+EAA+E;IAC/E,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,8BAA8B,GACtC,wBAAwB,CA0G1B"}