@chipmobilesdk/rn-payment 0.6.0 → 0.7.0

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 (295) hide show
  1. package/CHANGELOG.md +111 -0
  2. package/README.md +1 -1
  3. package/lib/commonjs/adapter/createStoreProvider.js +110 -0
  4. package/lib/commonjs/adapter/createStoreProvider.js.map +1 -0
  5. package/lib/commonjs/adapter/iap-adapter.js +393 -0
  6. package/lib/commonjs/adapter/iap-adapter.js.map +1 -0
  7. package/lib/commonjs/adapter/iapShapes.js +169 -0
  8. package/lib/commonjs/adapter/iapShapes.js.map +1 -0
  9. package/lib/commonjs/adapter/port.js +6 -0
  10. package/lib/commonjs/adapter/port.js.map +1 -0
  11. package/lib/commonjs/config/types.js +2 -0
  12. package/lib/commonjs/config/types.js.map +1 -0
  13. package/lib/commonjs/config/validate.js +181 -0
  14. package/lib/commonjs/config/validate.js.map +1 -0
  15. package/lib/commonjs/core/mutex.js +31 -0
  16. package/lib/commonjs/core/mutex.js.map +1 -0
  17. package/lib/commonjs/core/retry.js +37 -0
  18. package/lib/commonjs/core/retry.js.map +1 -0
  19. package/lib/commonjs/core/timers.js +207 -0
  20. package/lib/commonjs/core/timers.js.map +1 -0
  21. package/lib/commonjs/diagnostics/errors.js +83 -0
  22. package/lib/commonjs/diagnostics/errors.js.map +1 -0
  23. package/lib/commonjs/diagnostics/events.js +126 -0
  24. package/lib/commonjs/diagnostics/events.js.map +1 -0
  25. package/lib/commonjs/diagnostics/messageKeys.js +70 -0
  26. package/lib/commonjs/diagnostics/messageKeys.js.map +1 -0
  27. package/lib/commonjs/engine/connection.js +189 -0
  28. package/lib/commonjs/engine/connection.js.map +1 -0
  29. package/lib/commonjs/engine/engine.js +279 -0
  30. package/lib/commonjs/engine/engine.js.map +1 -0
  31. package/lib/commonjs/engine/finalize.js +325 -0
  32. package/lib/commonjs/engine/finalize.js.map +1 -0
  33. package/lib/commonjs/engine/foreground.js +26 -0
  34. package/lib/commonjs/engine/foreground.js.map +1 -0
  35. package/lib/commonjs/engine/internals.js +31 -0
  36. package/lib/commonjs/engine/internals.js.map +1 -0
  37. package/lib/commonjs/engine/pending.js +102 -0
  38. package/lib/commonjs/engine/pending.js.map +1 -0
  39. package/lib/commonjs/engine/products.js +198 -0
  40. package/lib/commonjs/engine/products.js.map +1 -0
  41. package/lib/commonjs/engine/purchase.js +395 -0
  42. package/lib/commonjs/engine/purchase.js.map +1 -0
  43. package/lib/commonjs/engine/purchaseFailure.js +77 -0
  44. package/lib/commonjs/engine/purchaseFailure.js.map +1 -0
  45. package/lib/commonjs/engine/receiptValidation.js +90 -0
  46. package/lib/commonjs/engine/receiptValidation.js.map +1 -0
  47. package/lib/commonjs/engine/state.js +201 -0
  48. package/lib/commonjs/engine/state.js.map +1 -0
  49. package/lib/commonjs/engine/subscriptions.js +122 -0
  50. package/lib/commonjs/engine/subscriptions.js.map +1 -0
  51. package/lib/commonjs/engine/sync.js +163 -0
  52. package/lib/commonjs/engine/sync.js.map +1 -0
  53. package/lib/commonjs/entitlements/aggregate.js +212 -0
  54. package/lib/commonjs/entitlements/aggregate.js.map +1 -0
  55. package/lib/commonjs/entitlements/mapping.js +41 -0
  56. package/lib/commonjs/entitlements/mapping.js.map +1 -0
  57. package/lib/commonjs/entitlements/policy.js +110 -0
  58. package/lib/commonjs/entitlements/policy.js.map +1 -0
  59. package/lib/commonjs/index.js +266 -0
  60. package/lib/commonjs/index.js.map +1 -0
  61. package/lib/commonjs/package.json +1 -0
  62. package/lib/commonjs/persistence/mmkv-store.js +149 -0
  63. package/lib/commonjs/persistence/mmkv-store.js.map +1 -0
  64. package/lib/commonjs/persistence/snapshot.js +229 -0
  65. package/lib/commonjs/persistence/snapshot.js.map +1 -0
  66. package/lib/commonjs/react/PaymentProvider.js +96 -0
  67. package/lib/commonjs/react/PaymentProvider.js.map +1 -0
  68. package/lib/commonjs/react/hooks.js +202 -0
  69. package/lib/commonjs/react/hooks.js.map +1 -0
  70. package/lib/commonjs/testing/conformance.js +136 -0
  71. package/lib/commonjs/testing/conformance.js.map +1 -0
  72. package/lib/commonjs/testing/fakeStore.js +281 -0
  73. package/lib/commonjs/testing/fakeStore.js.map +1 -0
  74. package/lib/commonjs/testing/index.js +45 -0
  75. package/lib/commonjs/testing/index.js.map +1 -0
  76. package/lib/module/adapter/createStoreProvider.js +106 -0
  77. package/lib/module/adapter/createStoreProvider.js.map +1 -0
  78. package/lib/module/adapter/iap-adapter.js +383 -0
  79. package/lib/module/adapter/iap-adapter.js.map +1 -0
  80. package/lib/module/adapter/iapShapes.js +160 -0
  81. package/lib/module/adapter/iapShapes.js.map +1 -0
  82. package/lib/module/adapter/port.js +4 -0
  83. package/lib/module/adapter/port.js.map +1 -0
  84. package/lib/module/config/types.js +2 -0
  85. package/lib/module/config/types.js.map +1 -0
  86. package/lib/module/config/validate.js +175 -0
  87. package/lib/module/config/validate.js.map +1 -0
  88. package/lib/module/core/mutex.js +22 -0
  89. package/lib/module/core/mutex.js.map +1 -0
  90. package/lib/module/core/retry.js +33 -0
  91. package/lib/module/core/retry.js.map +1 -0
  92. package/lib/module/core/timers.js +198 -0
  93. package/lib/module/core/timers.js.map +1 -0
  94. package/lib/module/diagnostics/errors.js +76 -0
  95. package/lib/module/diagnostics/errors.js.map +1 -0
  96. package/lib/module/diagnostics/events.js +117 -0
  97. package/lib/module/diagnostics/events.js.map +1 -0
  98. package/lib/module/diagnostics/messageKeys.js +64 -0
  99. package/lib/module/diagnostics/messageKeys.js.map +1 -0
  100. package/lib/module/engine/connection.js +185 -0
  101. package/lib/module/engine/connection.js.map +1 -0
  102. package/lib/module/engine/engine.js +274 -0
  103. package/lib/module/engine/engine.js.map +1 -0
  104. package/lib/module/engine/finalize.js +322 -0
  105. package/lib/module/engine/finalize.js.map +1 -0
  106. package/lib/module/engine/foreground.js +21 -0
  107. package/lib/module/engine/foreground.js.map +1 -0
  108. package/lib/module/engine/internals.js +26 -0
  109. package/lib/module/engine/internals.js.map +1 -0
  110. package/lib/module/engine/pending.js +95 -0
  111. package/lib/module/engine/pending.js.map +1 -0
  112. package/lib/module/engine/products.js +195 -0
  113. package/lib/module/engine/products.js.map +1 -0
  114. package/lib/module/engine/purchase.js +390 -0
  115. package/lib/module/engine/purchase.js.map +1 -0
  116. package/lib/module/engine/purchaseFailure.js +72 -0
  117. package/lib/module/engine/purchaseFailure.js.map +1 -0
  118. package/lib/module/engine/receiptValidation.js +87 -0
  119. package/lib/module/engine/receiptValidation.js.map +1 -0
  120. package/lib/module/engine/state.js +196 -0
  121. package/lib/module/engine/state.js.map +1 -0
  122. package/lib/module/engine/subscriptions.js +119 -0
  123. package/lib/module/engine/subscriptions.js.map +1 -0
  124. package/lib/module/engine/sync.js +158 -0
  125. package/lib/module/engine/sync.js.map +1 -0
  126. package/lib/module/entitlements/aggregate.js +204 -0
  127. package/lib/module/entitlements/aggregate.js.map +1 -0
  128. package/lib/module/entitlements/mapping.js +35 -0
  129. package/lib/module/entitlements/mapping.js.map +1 -0
  130. package/lib/module/entitlements/policy.js +104 -0
  131. package/lib/module/entitlements/policy.js.map +1 -0
  132. package/lib/module/index.js +59 -0
  133. package/lib/module/index.js.map +1 -0
  134. package/lib/module/package.json +1 -0
  135. package/lib/module/persistence/mmkv-store.js +144 -0
  136. package/lib/module/persistence/mmkv-store.js.map +1 -0
  137. package/lib/module/persistence/snapshot.js +221 -0
  138. package/lib/module/persistence/snapshot.js.map +1 -0
  139. package/lib/module/react/PaymentProvider.js +90 -0
  140. package/lib/module/react/PaymentProvider.js.map +1 -0
  141. package/lib/module/react/hooks.js +192 -0
  142. package/lib/module/react/hooks.js.map +1 -0
  143. package/lib/module/testing/conformance.js +130 -0
  144. package/lib/module/testing/conformance.js.map +1 -0
  145. package/lib/module/testing/fakeStore.js +276 -0
  146. package/lib/module/testing/fakeStore.js.map +1 -0
  147. package/lib/module/testing/index.js +13 -0
  148. package/lib/module/testing/index.js.map +1 -0
  149. package/lib/typescript/commonjs/adapter/createStoreProvider.d.ts +45 -0
  150. package/lib/typescript/commonjs/adapter/createStoreProvider.d.ts.map +1 -0
  151. package/lib/typescript/commonjs/adapter/iap-adapter.d.ts +80 -0
  152. package/lib/typescript/commonjs/adapter/iap-adapter.d.ts.map +1 -0
  153. package/lib/typescript/commonjs/adapter/iapShapes.d.ts +94 -0
  154. package/lib/typescript/commonjs/adapter/iapShapes.d.ts.map +1 -0
  155. package/lib/typescript/commonjs/adapter/port.d.ts +184 -0
  156. package/lib/typescript/commonjs/adapter/port.d.ts.map +1 -0
  157. package/lib/typescript/commonjs/config/types.d.ts +326 -0
  158. package/lib/typescript/commonjs/config/types.d.ts.map +1 -0
  159. package/lib/typescript/commonjs/config/validate.d.ts +63 -0
  160. package/lib/typescript/commonjs/config/validate.d.ts.map +1 -0
  161. package/lib/typescript/commonjs/core/mutex.d.ts +17 -0
  162. package/lib/typescript/commonjs/core/mutex.d.ts.map +1 -0
  163. package/lib/typescript/commonjs/core/retry.d.ts +19 -0
  164. package/lib/typescript/commonjs/core/retry.d.ts.map +1 -0
  165. package/lib/typescript/commonjs/core/timers.d.ts +142 -0
  166. package/lib/typescript/commonjs/core/timers.d.ts.map +1 -0
  167. package/lib/typescript/commonjs/diagnostics/errors.d.ts +55 -0
  168. package/lib/typescript/commonjs/diagnostics/errors.d.ts.map +1 -0
  169. package/lib/typescript/commonjs/diagnostics/events.d.ts +158 -0
  170. package/lib/typescript/commonjs/diagnostics/events.d.ts.map +1 -0
  171. package/lib/typescript/commonjs/diagnostics/messageKeys.d.ts +54 -0
  172. package/lib/typescript/commonjs/diagnostics/messageKeys.d.ts.map +1 -0
  173. package/lib/typescript/commonjs/engine/connection.d.ts +30 -0
  174. package/lib/typescript/commonjs/engine/connection.d.ts.map +1 -0
  175. package/lib/typescript/commonjs/engine/engine.d.ts +93 -0
  176. package/lib/typescript/commonjs/engine/engine.d.ts.map +1 -0
  177. package/lib/typescript/commonjs/engine/finalize.d.ts +53 -0
  178. package/lib/typescript/commonjs/engine/finalize.d.ts.map +1 -0
  179. package/lib/typescript/commonjs/engine/foreground.d.ts +15 -0
  180. package/lib/typescript/commonjs/engine/foreground.d.ts.map +1 -0
  181. package/lib/typescript/commonjs/engine/internals.d.ts +28 -0
  182. package/lib/typescript/commonjs/engine/internals.d.ts.map +1 -0
  183. package/lib/typescript/commonjs/engine/pending.d.ts +51 -0
  184. package/lib/typescript/commonjs/engine/pending.d.ts.map +1 -0
  185. package/lib/typescript/commonjs/engine/products.d.ts +82 -0
  186. package/lib/typescript/commonjs/engine/products.d.ts.map +1 -0
  187. package/lib/typescript/commonjs/engine/purchase.d.ts +61 -0
  188. package/lib/typescript/commonjs/engine/purchase.d.ts.map +1 -0
  189. package/lib/typescript/commonjs/engine/purchaseFailure.d.ts +15 -0
  190. package/lib/typescript/commonjs/engine/purchaseFailure.d.ts.map +1 -0
  191. package/lib/typescript/commonjs/engine/receiptValidation.d.ts +42 -0
  192. package/lib/typescript/commonjs/engine/receiptValidation.d.ts.map +1 -0
  193. package/lib/typescript/commonjs/engine/state.d.ts +46 -0
  194. package/lib/typescript/commonjs/engine/state.d.ts.map +1 -0
  195. package/lib/typescript/commonjs/engine/subscriptions.d.ts +61 -0
  196. package/lib/typescript/commonjs/engine/subscriptions.d.ts.map +1 -0
  197. package/lib/typescript/commonjs/engine/sync.d.ts +36 -0
  198. package/lib/typescript/commonjs/engine/sync.d.ts.map +1 -0
  199. package/lib/typescript/commonjs/entitlements/aggregate.d.ts +97 -0
  200. package/lib/typescript/commonjs/entitlements/aggregate.d.ts.map +1 -0
  201. package/lib/typescript/commonjs/entitlements/mapping.d.ts +27 -0
  202. package/lib/typescript/commonjs/entitlements/mapping.d.ts.map +1 -0
  203. package/lib/typescript/commonjs/entitlements/policy.d.ts +75 -0
  204. package/lib/typescript/commonjs/entitlements/policy.d.ts.map +1 -0
  205. package/lib/typescript/commonjs/index.d.ts +44 -0
  206. package/lib/typescript/commonjs/index.d.ts.map +1 -0
  207. package/lib/typescript/commonjs/package.json +1 -0
  208. package/lib/typescript/commonjs/persistence/mmkv-store.d.ts +45 -0
  209. package/lib/typescript/commonjs/persistence/mmkv-store.d.ts.map +1 -0
  210. package/lib/typescript/commonjs/persistence/snapshot.d.ts +106 -0
  211. package/lib/typescript/commonjs/persistence/snapshot.d.ts.map +1 -0
  212. package/lib/typescript/commonjs/react/PaymentProvider.d.ts +57 -0
  213. package/lib/typescript/commonjs/react/PaymentProvider.d.ts.map +1 -0
  214. package/lib/typescript/commonjs/react/hooks.d.ts +80 -0
  215. package/lib/typescript/commonjs/react/hooks.d.ts.map +1 -0
  216. package/lib/typescript/commonjs/testing/conformance.d.ts +41 -0
  217. package/lib/typescript/commonjs/testing/conformance.d.ts.map +1 -0
  218. package/lib/typescript/commonjs/testing/fakeStore.d.ts +69 -0
  219. package/lib/typescript/commonjs/testing/fakeStore.d.ts.map +1 -0
  220. package/lib/typescript/commonjs/testing/index.d.ts +12 -0
  221. package/lib/typescript/commonjs/testing/index.d.ts.map +1 -0
  222. package/lib/typescript/module/adapter/createStoreProvider.d.ts +45 -0
  223. package/lib/typescript/module/adapter/createStoreProvider.d.ts.map +1 -0
  224. package/lib/typescript/module/adapter/iap-adapter.d.ts +80 -0
  225. package/lib/typescript/module/adapter/iap-adapter.d.ts.map +1 -0
  226. package/lib/typescript/module/adapter/iapShapes.d.ts +94 -0
  227. package/lib/typescript/module/adapter/iapShapes.d.ts.map +1 -0
  228. package/lib/typescript/module/adapter/port.d.ts +184 -0
  229. package/lib/typescript/module/adapter/port.d.ts.map +1 -0
  230. package/lib/typescript/module/config/types.d.ts +326 -0
  231. package/lib/typescript/module/config/types.d.ts.map +1 -0
  232. package/lib/typescript/module/config/validate.d.ts +63 -0
  233. package/lib/typescript/module/config/validate.d.ts.map +1 -0
  234. package/lib/typescript/module/core/mutex.d.ts +17 -0
  235. package/lib/typescript/module/core/mutex.d.ts.map +1 -0
  236. package/lib/typescript/module/core/retry.d.ts +19 -0
  237. package/lib/typescript/module/core/retry.d.ts.map +1 -0
  238. package/lib/typescript/module/core/timers.d.ts +142 -0
  239. package/lib/typescript/module/core/timers.d.ts.map +1 -0
  240. package/lib/typescript/module/diagnostics/errors.d.ts +55 -0
  241. package/lib/typescript/module/diagnostics/errors.d.ts.map +1 -0
  242. package/lib/typescript/module/diagnostics/events.d.ts +158 -0
  243. package/lib/typescript/module/diagnostics/events.d.ts.map +1 -0
  244. package/lib/typescript/module/diagnostics/messageKeys.d.ts +54 -0
  245. package/lib/typescript/module/diagnostics/messageKeys.d.ts.map +1 -0
  246. package/lib/typescript/module/engine/connection.d.ts +30 -0
  247. package/lib/typescript/module/engine/connection.d.ts.map +1 -0
  248. package/lib/typescript/module/engine/engine.d.ts +93 -0
  249. package/lib/typescript/module/engine/engine.d.ts.map +1 -0
  250. package/lib/typescript/module/engine/finalize.d.ts +53 -0
  251. package/lib/typescript/module/engine/finalize.d.ts.map +1 -0
  252. package/lib/typescript/module/engine/foreground.d.ts +15 -0
  253. package/lib/typescript/module/engine/foreground.d.ts.map +1 -0
  254. package/lib/typescript/module/engine/internals.d.ts +28 -0
  255. package/lib/typescript/module/engine/internals.d.ts.map +1 -0
  256. package/lib/typescript/module/engine/pending.d.ts +51 -0
  257. package/lib/typescript/module/engine/pending.d.ts.map +1 -0
  258. package/lib/typescript/module/engine/products.d.ts +82 -0
  259. package/lib/typescript/module/engine/products.d.ts.map +1 -0
  260. package/lib/typescript/module/engine/purchase.d.ts +61 -0
  261. package/lib/typescript/module/engine/purchase.d.ts.map +1 -0
  262. package/lib/typescript/module/engine/purchaseFailure.d.ts +15 -0
  263. package/lib/typescript/module/engine/purchaseFailure.d.ts.map +1 -0
  264. package/lib/typescript/module/engine/receiptValidation.d.ts +42 -0
  265. package/lib/typescript/module/engine/receiptValidation.d.ts.map +1 -0
  266. package/lib/typescript/module/engine/state.d.ts +46 -0
  267. package/lib/typescript/module/engine/state.d.ts.map +1 -0
  268. package/lib/typescript/module/engine/subscriptions.d.ts +61 -0
  269. package/lib/typescript/module/engine/subscriptions.d.ts.map +1 -0
  270. package/lib/typescript/module/engine/sync.d.ts +36 -0
  271. package/lib/typescript/module/engine/sync.d.ts.map +1 -0
  272. package/lib/typescript/module/entitlements/aggregate.d.ts +97 -0
  273. package/lib/typescript/module/entitlements/aggregate.d.ts.map +1 -0
  274. package/lib/typescript/module/entitlements/mapping.d.ts +27 -0
  275. package/lib/typescript/module/entitlements/mapping.d.ts.map +1 -0
  276. package/lib/typescript/module/entitlements/policy.d.ts +75 -0
  277. package/lib/typescript/module/entitlements/policy.d.ts.map +1 -0
  278. package/lib/typescript/module/index.d.ts +44 -0
  279. package/lib/typescript/module/index.d.ts.map +1 -0
  280. package/lib/typescript/module/package.json +1 -0
  281. package/lib/typescript/module/persistence/mmkv-store.d.ts +45 -0
  282. package/lib/typescript/module/persistence/mmkv-store.d.ts.map +1 -0
  283. package/lib/typescript/module/persistence/snapshot.d.ts +106 -0
  284. package/lib/typescript/module/persistence/snapshot.d.ts.map +1 -0
  285. package/lib/typescript/module/react/PaymentProvider.d.ts +57 -0
  286. package/lib/typescript/module/react/PaymentProvider.d.ts.map +1 -0
  287. package/lib/typescript/module/react/hooks.d.ts +80 -0
  288. package/lib/typescript/module/react/hooks.d.ts.map +1 -0
  289. package/lib/typescript/module/testing/conformance.d.ts +41 -0
  290. package/lib/typescript/module/testing/conformance.d.ts.map +1 -0
  291. package/lib/typescript/module/testing/fakeStore.d.ts +69 -0
  292. package/lib/typescript/module/testing/fakeStore.d.ts.map +1 -0
  293. package/lib/typescript/module/testing/index.d.ts +12 -0
  294. package/lib/typescript/module/testing/index.d.ts.map +1 -0
  295. package/package.json +49 -13
@@ -0,0 +1,195 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Product query, normalization, and the in-memory price cache (US11).
5
+ *
6
+ * Two rules shape this module:
7
+ *
8
+ * - **Prices come from the store, formatted.** An app must never build a price
9
+ * string (FR-028): only the store knows the right currency symbol, its
10
+ * placement, the decimal separator, and the grouping for the user's locale. A
11
+ * hand-built "$9.99" is wrong in most of the world.
12
+ * - **Offer eligibility is reported, never computed.** The store decides who
13
+ * qualifies for a trial or an introductory price (FR-026). Guessing locally
14
+ * would promise a trial the store then refuses at checkout.
15
+ *
16
+ * The cache is in **memory only** and short-lived. Persisting prices would risk
17
+ * showing a stale one as current in a later session, and a paywall is exactly
18
+ * where that matters.
19
+ */
20
+
21
+ import { PaymentError } from "../diagnostics/errors.js";
22
+ import { withTimeout } from "../core/mutex.js";
23
+ import { storeIdForProductKey } from "../entitlements/mapping.js";
24
+
25
+ /** Why a requested product produced nothing, kept distinct from a network error. */
26
+
27
+ function normalize(raw, productKey, productType) {
28
+ return {
29
+ productKey,
30
+ productType,
31
+ title: raw.title,
32
+ description: raw.description,
33
+ formattedPrice: raw.formattedPrice,
34
+ currencyCode: raw.currencyCode,
35
+ priceAmountMicros: raw.priceAmountMicros,
36
+ offers: raw.offers.map(offer => ({
37
+ offerKey: offer.offerKey,
38
+ billingPeriod: offer.billingPeriod,
39
+ formattedPrice: offer.formattedPrice,
40
+ priceAmountMicros: offer.priceAmountMicros,
41
+ currencyCode: offer.currencyCode,
42
+ trialPeriod: offer.trialPeriod,
43
+ introductoryPrice: offer.introductoryPrice,
44
+ isEligible: offer.isEligible
45
+ }))
46
+ };
47
+ }
48
+ export function createProducts(deps) {
49
+ const {
50
+ resolved
51
+ } = deps;
52
+ const cache = new Map();
53
+ const isFresh = entry => deps.now() - entry.cachedAt < resolved.productCacheTtlMs;
54
+ const query = async (productKeys, useCache) => {
55
+ const missing = [];
56
+ const resolvedProducts = [];
57
+ const toFetch = [];
58
+ for (const productKey of productKeys) {
59
+ const entry = resolved.entries.get(productKey);
60
+ const storeProductId = storeIdForProductKey(resolved, productKey);
61
+ if (!entry || !storeProductId) {
62
+ // A configuration problem, not a store one. Distinguishing them tells a
63
+ // developer whether to fix the catalog or check Play Console.
64
+ missing.push({
65
+ productKey,
66
+ reason: 'not_in_catalog'
67
+ });
68
+ continue;
69
+ }
70
+ const cached = useCache ? cache.get(productKey) : undefined;
71
+ if (cached && isFresh(cached)) {
72
+ resolvedProducts.push(cached.product);
73
+ continue;
74
+ }
75
+ toFetch.push({
76
+ productKey,
77
+ storeProductId,
78
+ productType: entry.productType
79
+ });
80
+ }
81
+ if (toFetch.length === 0) {
82
+ deps.emit({
83
+ type: 'products_queried',
84
+ productKeys,
85
+ found: resolvedProducts.length,
86
+ missing: missing.map(m => m.productKey),
87
+ fromCache: true
88
+ });
89
+ return {
90
+ ok: true,
91
+ products: resolvedProducts,
92
+ missing,
93
+ fromCache: true
94
+ };
95
+ }
96
+
97
+ // Grouped by product type because the store queries in-app products and
98
+ // subscriptions through separate calls.
99
+ const byType = new Map();
100
+ for (const item of toFetch) {
101
+ const list = byType.get(item.productType) ?? [];
102
+ list.push(item);
103
+ byType.set(item.productType, list);
104
+ }
105
+ try {
106
+ // In parallel: a paywall offering a subscription and a one-time purchase
107
+ // used to wait for one store round-trip after the other (PAY-20).
108
+ const groups = await Promise.all([...byType].map(async ([productType, items]) => ({
109
+ items,
110
+ raw: await withTimeout(deps.provider.queryProducts(items.map(i => i.storeProductId), productType), resolved.timeouts.productQueryMs, () => new PaymentError({
111
+ code: 'PAYMENT_TIMEOUT',
112
+ message: 'Querying products timed out',
113
+ operation: 'getProducts',
114
+ retryable: true
115
+ }))
116
+ })));
117
+ for (const {
118
+ items,
119
+ raw
120
+ } of groups) {
121
+ const returned = new Map(raw.map(p => [p.storeProductId, p]));
122
+ for (const item of items) {
123
+ const found = returned.get(item.storeProductId);
124
+ if (!found) {
125
+ // The store knows the id but will not sell it here: unapproved, or
126
+ // not available in this country. Never conflated with a network
127
+ // failure (FR-027).
128
+ missing.push({
129
+ productKey: item.productKey,
130
+ reason: 'not_available_from_store'
131
+ });
132
+ continue;
133
+ }
134
+ const product = normalize(found, item.productKey, item.productType);
135
+ cache.set(item.productKey, {
136
+ product,
137
+ cachedAt: deps.now()
138
+ });
139
+ resolvedProducts.push(product);
140
+ }
141
+ }
142
+ } catch (error) {
143
+ const paymentError = error instanceof PaymentError ? error : new PaymentError({
144
+ code: 'PAYMENT_NETWORK_ERROR',
145
+ message: 'Could not reach the store to query products',
146
+ operation: 'getProducts',
147
+ retryable: true
148
+ });
149
+ deps.emit({
150
+ type: 'internal_error',
151
+ code: paymentError.code,
152
+ operation: 'getProducts'
153
+ });
154
+ return {
155
+ ok: false,
156
+ error: paymentError
157
+ };
158
+ }
159
+ deps.emit({
160
+ type: 'products_queried',
161
+ productKeys,
162
+ found: resolvedProducts.length,
163
+ missing: missing.map(m => m.productKey),
164
+ fromCache: false
165
+ });
166
+ return {
167
+ ok: true,
168
+ products: resolvedProducts,
169
+ missing,
170
+ fromCache: false
171
+ };
172
+ };
173
+
174
+ /**
175
+ * Identical requests in flight share one store call (PAY-20): several screens
176
+ * mounting `useProducts` for the same paywall ask once.
177
+ */
178
+ const flights = new Map();
179
+ const joined = (productKeys, useCache) => {
180
+ const key = `${useCache ? 'get' : 'refresh'}:${productKeys.join('|')}`;
181
+ const running = flights.get(key);
182
+ if (running) {
183
+ return running;
184
+ }
185
+ const promise = query(productKeys, useCache).finally(() => flights.delete(key));
186
+ flights.set(key, promise);
187
+ return promise;
188
+ };
189
+ return {
190
+ get: productKeys => joined(productKeys, true),
191
+ refresh: productKeys => joined(productKeys, false),
192
+ invalidate: () => cache.clear()
193
+ };
194
+ }
195
+ //# sourceMappingURL=products.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["PaymentError","withTimeout","storeIdForProductKey","normalize","raw","productKey","productType","title","description","formattedPrice","currencyCode","priceAmountMicros","offers","map","offer","offerKey","billingPeriod","trialPeriod","introductoryPrice","isEligible","createProducts","deps","resolved","cache","Map","isFresh","entry","now","cachedAt","productCacheTtlMs","query","productKeys","useCache","missing","resolvedProducts","toFetch","entries","get","storeProductId","push","reason","cached","undefined","product","length","emit","type","found","m","fromCache","ok","products","byType","item","list","set","groups","Promise","all","items","provider","queryProducts","i","timeouts","productQueryMs","code","message","operation","retryable","returned","p","error","paymentError","flights","joined","key","join","running","promise","finally","delete","refresh","invalidate","clear"],"sourceRoot":"../../../src","sources":["engine/products.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAKA,SAASA,YAAY,QAAQ,0BAAuB;AACpD,SAASC,WAAW,QAAQ,kBAAe;AAE3C,SAASC,oBAAoB,QAAQ,4BAAyB;;AA+B9D;;AAyCA,SAASC,SAASA,CACjBC,GAAoB,EACpBC,UAAsB,EACtBC,WAAwB,EACV;EACd,OAAO;IACND,UAAU;IACVC,WAAW;IACXC,KAAK,EAAEH,GAAG,CAACG,KAAK;IAChBC,WAAW,EAAEJ,GAAG,CAACI,WAAW;IAC5BC,cAAc,EAAEL,GAAG,CAACK,cAAc;IAClCC,YAAY,EAAEN,GAAG,CAACM,YAAY;IAC9BC,iBAAiB,EAAEP,GAAG,CAACO,iBAAiB;IACxCC,MAAM,EAAER,GAAG,CAACQ,MAAM,CAACC,GAAG,CAACC,KAAK,KAAK;MAChCC,QAAQ,EAAED,KAAK,CAACC,QAAQ;MACxBC,aAAa,EAAEF,KAAK,CAACE,aAAa;MAClCP,cAAc,EAAEK,KAAK,CAACL,cAAc;MACpCE,iBAAiB,EAAEG,KAAK,CAACH,iBAAiB;MAC1CD,YAAY,EAAEI,KAAK,CAACJ,YAAY;MAChCO,WAAW,EAAEH,KAAK,CAACG,WAAW;MAC9BC,iBAAiB,EAAEJ,KAAK,CAACI,iBAAiB;MAC1CC,UAAU,EAAEL,KAAK,CAACK;IACnB,CAAC,CAAC;EACH,CAAC;AACF;AAEA,OAAO,SAASC,cAAcA,CAACC,IAAkB,EAAY;EAC5D,MAAM;IAAEC;EAAS,CAAC,GAAGD,IAAI;EACzB,MAAME,KAAK,GAAG,IAAIC,GAAG,CAAyB,CAAC;EAE/C,MAAMC,OAAO,GAAIC,KAAiB,IACjCL,IAAI,CAACM,GAAG,CAAC,CAAC,GAAGD,KAA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C,CAAC;IAEF,OAAO;MAAEC,EAAE,EAAE,IAAI;MAAEC,QAAQ,EAAEjB,gBAAgB;MAAED,OAAO;MAAEgB,SAAS,EAAE;IAAM,CAAC;EAC3E,CAAC;;EAED;AACD;AACA;AACA;EACC,MAAMwB,OAAO,GAAG,IAAIjD,GAAG,CAAsC,CAAC;EAC9D,MAAMkD,MAAM,GAAGA,CAAC3C,WAAyB,EAAEC,QAAiB,KAAkC;IAC7F,MAAM2C,GAAG,GAAG,GAAG3C,QAAQ,GAAG,KAAK,GAAG,SAAS,IAAID,WAAW,CAAC6C,IAAI,CAAC,GAAG,CAAC,EAAE;IACtE,MAAMC,OAAO,GAAGJ,OAAO,CAACpC,GAAG,CAACsC,GAAG,CAAC;IAChC,IAAIE,OAAO,EAAE;MACZ,OAAOA,OAAO;IACf;IACA,MAAMC,OAAO,GAAGhD,KAAK,CAACC,WAAW,EAAEC,QAAQ,CAAC,CAAC+C,OAAO,CAAC,MAAMN,OAAO,CAACO,MAAM,CAACL,GAAG,CAAC,CAAC;IAC/EF,OAAO,CAAClB,GAAG,CAACoB,GAAG,EAAEG,OAAO,CAAC;IACzB,OAAOA,OAAO;EACf,CAAC;EAED,OAAO;IACNzC,GAAG,EAAEN,WAAW,IAAI2C,MAAM,CAAC3C,WAAW,EAAE,IAAI,CAAC;IAC7CkD,OAAO,EAAElD,WAAW,IAAI2C,MAAM,CAAC3C,WAAW,EAAE,KAAK,CAAC;IAClDmD,UAAU,EAAEA,CAAA,KAAM3D,KAAK,CAAC4D,KAAK,CAAC;EAC/B,CAAC;AACF","ignoreList":[]}
@@ -0,0 +1,390 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * The purchase flow.
5
+ *
6
+ * Ordering here is deliberate and load-bearing:
7
+ *
8
+ * 1. Refuse early and cheaply — disabled, not ready, already busy, environment
9
+ * blocked, unknown product — so nothing reaches the store that should not.
10
+ * 2. Launch, and map every store outcome onto a typed result (FR-005).
11
+ * 3. Pending stops here: it is persisted and signalled, but **never granted**
12
+ * (FR-037).
13
+ * 4. Validate with the app's backend, if one is configured, and only for a
14
+ * **newly completed** purchase (FR-069a).
15
+ * 5. Grant the entitlement, then finalize. In that order — the user gets what
16
+ * they paid for before the bookkeeping completes, so a finalize failure never
17
+ * withholds a paid entitlement. Finalization is still guaranteed, by the
18
+ * persisted queue.
19
+ */
20
+
21
+ import { withTimeout } from "../core/mutex.js";
22
+ import { PURCHASE_FLOW_CEILING_MS } from "../core/timers.js";
23
+ import { PaymentError } from "../diagnostics/errors.js";
24
+ import { storeIdForProductKey } from "../entitlements/mapping.js";
25
+ import { toPersistedRecord } from "./sync.js";
26
+ /** The error code each failed purchase kind is reported under (PAY-19). */
27
+ import { createReceiptValidation } from "./receiptValidation.js";
28
+ import { FAILURE_CODES, mapFailure } from "./purchaseFailure.js";
29
+ export function createPurchaseFlow(deps) {
30
+ const {
31
+ resolved
32
+ } = deps;
33
+ // The backend check and what to do when it cannot answer (receiptValidation).
34
+ const {
35
+ askHook,
36
+ validate
37
+ } = createReceiptValidation({
38
+ config: deps.config,
39
+ platform: deps.platform,
40
+ resolved,
41
+ emit: deps.emit
42
+ });
43
+ const toRef = record => ({
44
+ transactionId: record.transactionId,
45
+ productKey: record.productKey
46
+ });
47
+
48
+ /** Writes or replaces the record for one transaction. */
49
+ const upsert = record => {
50
+ const snapshot = deps.snapshot();
51
+ const others = snapshot.purchases.filter(p => p.transactionId !== record.transactionId);
52
+ deps.commit({
53
+ ...snapshot,
54
+ purchases: [...others, record]
55
+ });
56
+ };
57
+ const recordFor = (purchase, productKey) => toPersistedRecord(resolved, purchase, productKey, deps.snapshot().purchases.find(p => p.transactionId === purchase.transactionId));
58
+
59
+ /**
60
+ * Calls the app's hook under `timeouts.validateMs`.
61
+ *
62
+ * Unbounded, a hook that never answers held the purchase lock and, through
63
+ * revalidation, the sync flight for the rest of the session. A timeout rejects,
64
+ * so callers treat it exactly like a hook that throws: unavailable (FR-072b).
65
+ */
66
+ /**
67
+ * Settlements in progress, by transaction.
68
+ *
69
+ * The Play binding delivers a launched purchase twice: to the launch and, at
70
+ * the same moment, to the session-long update listener. Both paths reach
71
+ * `settle`, and without this the hook ran twice and the purchase was settled
72
+ * twice. The second caller joins the first and gets the same result.
73
+ */
74
+ const inFlightSettle = new Map();
75
+ const settleOnce = (purchase, productKey, correlationId) => {
76
+ const running = inFlightSettle.get(purchase.transactionId);
77
+ if (running) {
78
+ return running;
79
+ }
80
+ const flight = settle(purchase, productKey, correlationId).finally(() => {
81
+ inFlightSettle.delete(purchase.transactionId);
82
+ });
83
+ inFlightSettle.set(purchase.transactionId, flight);
84
+ return flight;
85
+ };
86
+
87
+ /** Persists a completed purchase, grants it, then finalizes. */
88
+ const settle = async (purchase, productKey, correlationId) => {
89
+ const decision = await validate(purchase, productKey, correlationId);
90
+ if (decision.outcome === 'rejected') {
91
+ upsert({
92
+ ...recordFor(purchase, productKey),
93
+ validationState: 'rejected',
94
+ finalizeState: 'queued'
95
+ });
96
+ // Still finalized with the store: the money moved, so leaving it
97
+ // unacknowledged would have Google refund it while our backend has
98
+ // already decided the user is not entitled. Refunding is the app owner's
99
+ // call, not a side effect of a bookkeeping omission.
100
+ await deps.finalizer.enqueue(purchase.transactionId);
101
+ return {
102
+ kind: 'validation_rejected',
103
+ productKey,
104
+ reason: decision.reason
105
+ };
106
+ }
107
+ upsert({
108
+ ...recordFor(purchase, productKey),
109
+ validationState: decision.outcome === 'granted_pending_revalidation' ? 'queued_for_revalidation' : 'approved',
110
+ finalizeState: 'queued'
111
+ });
112
+
113
+ // Grant is already live at this point: `commit` recomputed entitlements.
114
+ // Finalize second, so a store hiccup cannot withhold what was paid for.
115
+ await deps.finalizer.enqueue(purchase.transactionId);
116
+ const record = deps.snapshot().purchases.find(p => p.transactionId === purchase.transactionId);
117
+ return {
118
+ kind: 'success',
119
+ productKey,
120
+ transaction: record ? toRef(record) : {
121
+ transactionId: purchase.transactionId,
122
+ productKey
123
+ }
124
+ };
125
+ };
126
+ const handlePending = (purchase, productKey) => {
127
+ // The same pending transaction arrives from the launch and from the update
128
+ // listener (see `inFlightSettle`). The signal is about a purchase becoming
129
+ // pending, so it fires once per transaction, not once per delivery.
130
+ const alreadyPending = deps.snapshot().purchases.some(p => p.transactionId === purchase.transactionId && p.state === 'pending');
131
+ upsert(recordFor(purchase, productKey));
132
+ if (!alreadyPending) {
133
+ deps.emit({
134
+ type: 'purchase_pending',
135
+ productKey
136
+ });
137
+ }
138
+ return {
139
+ kind: 'pending',
140
+ productKey,
141
+ transaction: {
142
+ transactionId: purchase.transactionId,
143
+ productKey
144
+ }
145
+ };
146
+ };
147
+
148
+ /**
149
+ * The store returned a purchase in a state it could not name — neither paid
150
+ * nor pending. Nothing is granted, persisted or acknowledged on it.
151
+ *
152
+ * Retrying is the repair path: if the money did move, the store answers
153
+ * `already_owned`, which re-syncs and grants (FR-033).
154
+ */
155
+ const handleUnspecified = (productKey, correlationId) => {
156
+ deps.emit({
157
+ type: 'purchase_failed',
158
+ productKey,
159
+ code: 'PAYMENT_STORE_ERROR',
160
+ retryable: true,
161
+ correlationId
162
+ });
163
+ return {
164
+ kind: 'store_error',
165
+ productKey,
166
+ code: 'PAYMENT_STORE_ERROR'
167
+ };
168
+ };
169
+
170
+ /** What the store is asked for: the product and, for a plan change, what it replaces. */
171
+ const launchRequest = (productKey, storeProductId, options) => {
172
+ const replaceKey = options?.replaceProductKey;
173
+ return {
174
+ storeProductId,
175
+ productType: resolved.entries.get(productKey)?.productType ?? 'one_time_permanent',
176
+ offerKey: options?.offerKey,
177
+ obfuscatedAccountId: options?.obfuscatedAccountId,
178
+ // Present only for a plan change. The store needs the token of the
179
+ // subscription being replaced so it migrates the existing purchase instead
180
+ // of creating a second one (FR-065), and its product id to apply the
181
+ // replacement mode.
182
+ replacePurchaseToken: replaceKey ? deps.snapshot().purchases.find(p => p.productKey === replaceKey && p.state === 'purchased')?.token : undefined,
183
+ replaceStoreProductId: replaceKey ? storeIdForProductKey(resolved, replaceKey) : undefined,
184
+ prorationMode: options?.prorationMode
185
+ };
186
+ };
187
+
188
+ /**
189
+ * The launch timeout covers opening the store surface only; time the user
190
+ * spends inside it is the store's, not ours (FR-035). A provider that reports
191
+ * nothing until the flow ends gives no "opened" moment to time, so it gets only
192
+ * `PURCHASE_FLOW_CEILING_MS`: far beyond any real purchase, there so a binding
193
+ * that never answers cannot hold the purchase lock for the whole session.
194
+ */
195
+ const launch = request => {
196
+ const launched = deps.provider.launchPurchase(request);
197
+ const includesStoreTime = deps.provider.capabilities().purchaseOutcomeIncludesStoreTime;
198
+ return withTimeout(launched, includesStoreTime ? PURCHASE_FLOW_CEILING_MS : resolved.timeouts.purchaseLaunchMs, () => new PaymentError({
199
+ code: 'PAYMENT_TIMEOUT',
200
+ message: 'Opening the purchase surface timed out',
201
+ operation: 'purchase',
202
+ retryable: true
203
+ }));
204
+ };
205
+ return {
206
+ async purchase(productKey, options) {
207
+ if (!resolved.enabled) {
208
+ return {
209
+ kind: 'disabled'
210
+ };
211
+ }
212
+ const status = deps.statusKind();
213
+ if (status !== 'ready') {
214
+ return {
215
+ kind: 'not_ready',
216
+ status
217
+ };
218
+ }
219
+ const storeProductId = storeIdForProductKey(resolved, productKey);
220
+ if (!storeProductId) {
221
+ return {
222
+ kind: 'unknown_product',
223
+ productKey
224
+ };
225
+ }
226
+
227
+ // The block that makes a developer mistake unable to move real money.
228
+ // Gated on the provider actually being one that would: the fake store
229
+ // must still be able to complete a purchase in a test (FR-014).
230
+ if (deps.provider.capabilities().createsRealTransactions && !deps.mayCreateRealTransaction()) {
231
+ deps.recordBlockedOperation(productKey);
232
+ return {
233
+ kind: 'environment_blocked',
234
+ productKey,
235
+ environment: deps.config.environment
236
+ };
237
+ }
238
+ const correlationId = deps.nextCorrelationId();
239
+
240
+ // Exclusive, not single-flight: a second purchase is refused rather than
241
+ // joined or queued, so no second store surface opens (FR-031).
242
+ const attempt = await deps.runExclusive(async () => {
243
+ deps.emit({
244
+ type: 'purchase_started',
245
+ productKey,
246
+ correlationId
247
+ });
248
+ let outcome;
249
+ try {
250
+ outcome = await launch(launchRequest(productKey, storeProductId, options));
251
+ } catch {
252
+ deps.emit({
253
+ type: 'purchase_failed',
254
+ productKey,
255
+ code: 'PAYMENT_TIMEOUT',
256
+ retryable: true,
257
+ correlationId
258
+ });
259
+ return {
260
+ kind: 'timeout',
261
+ productKey
262
+ };
263
+ }
264
+ if (!outcome.ok) {
265
+ const mapped = mapFailure(outcome.reason, productKey, deps.statusKind());
266
+ if (mapped.kind === 'user_cancelled') {
267
+ // A normal outcome. Reported on its own channel so it is never
268
+ // counted as a technical failure (FR-032).
269
+ deps.emit({
270
+ type: 'purchase_cancelled',
271
+ productKey,
272
+ correlationId
273
+ });
274
+ return mapped;
275
+ }
276
+ if (mapped.kind === 'already_owned') {
277
+ // How a reinstall or a new device repairs itself (FR-033).
278
+ deps.requestSync('already_owned');
279
+ return mapped;
280
+ }
281
+ deps.emit({
282
+ type: 'purchase_failed',
283
+ productKey,
284
+ code: FAILURE_CODES[mapped.kind] ?? 'PAYMENT_STORE_ERROR',
285
+ retryable: mapped.kind === 'network_error',
286
+ correlationId
287
+ });
288
+ return mapped;
289
+ }
290
+ if (outcome.purchase.state === 'pending') {
291
+ return handlePending(outcome.purchase, productKey);
292
+ }
293
+ if (outcome.purchase.state === 'unspecified') {
294
+ return handleUnspecified(productKey, correlationId);
295
+ }
296
+ deps.emit({
297
+ type: 'purchase_succeeded',
298
+ productKey,
299
+ correlationId
300
+ });
301
+ return settleOnce(outcome.purchase, productKey, correlationId);
302
+ });
303
+ if (!attempt.acquired) {
304
+ return {
305
+ kind: 'purchase_in_progress'
306
+ };
307
+ }
308
+ return attempt.value;
309
+ },
310
+ /**
311
+ * A store-pushed update.
312
+ *
313
+ * This is how a pending purchase that settled between sessions is granted
314
+ * without the user buying again (FR-039). It runs outside the exclusive lock
315
+ * because it is not a user-initiated purchase and must not be refused just
316
+ * because one is open.
317
+ */
318
+ async ingest(purchase) {
319
+ const productKey = resolved.byStoreId.get(purchase.storeProductId);
320
+ if (!productKey) {
321
+ return;
322
+ }
323
+ if (purchase.state === 'pending') {
324
+ handlePending(purchase, productKey);
325
+ return;
326
+ }
327
+ if (purchase.state === 'unspecified') {
328
+ // No basis to grant or to end anything. The next sync reports what
329
+ // the store actually holds.
330
+ return;
331
+ }
332
+ const existing = deps.snapshot().purchases.find(p => p.transactionId === purchase.transactionId);
333
+
334
+ // Already settled and validated: nothing to redo, and re-running the hook
335
+ // here would break FR-069a's "new purchases only" rule.
336
+ if (existing && existing.state === 'purchased' && existing.validationState !== 'not_required') {
337
+ await deps.finalizer.enqueue(purchase.transactionId);
338
+ return;
339
+ }
340
+ await settleOnce(purchase, productKey, deps.nextCorrelationId());
341
+ },
342
+ async revalidate() {
343
+ const hook = deps.config.validateTransaction;
344
+ if (!hook) {
345
+ return;
346
+ }
347
+ const queued = deps.snapshot().purchases.filter(p => p.validationState === 'queued_for_revalidation');
348
+ for (const record of queued) {
349
+ const entry = resolved.entries.get(record.productKey);
350
+ let approved;
351
+ try {
352
+ const decision = await askHook(hook, {
353
+ productKey: record.productKey,
354
+ productType: entry?.productType ?? 'one_time_permanent',
355
+ // Re-validation deliberately carries no payload: the original
356
+ // verification material is not persisted (FR-056), so the backend
357
+ // re-checks by transaction against its own record of the purchase —
358
+ // which is why the transaction id has to travel with it.
359
+ verificationPayload: '',
360
+ correlationId: deps.nextCorrelationId(),
361
+ transactionId: record.transactionId,
362
+ platform: deps.platform
363
+ });
364
+ approved = decision.approved;
365
+ } catch {
366
+ // Still unreachable. Leave it queued and try again next sync rather
367
+ // than revoking from a paying user because our backend is down.
368
+ continue;
369
+ }
370
+ const snapshot = deps.snapshot();
371
+ deps.commit({
372
+ ...snapshot,
373
+ purchases: snapshot.purchases.map(p => p.transactionId === record.transactionId ? {
374
+ ...p,
375
+ validationState: approved ? 'approved' : 'rejected',
376
+ // A rejection on recovery revokes, which is the bound on the
377
+ // exposure `grant_and_queue` accepts (FR-072a).
378
+ state: approved ? p.state : 'revoked'
379
+ } : p)
380
+ });
381
+ deps.emit({
382
+ type: 'validation_decided',
383
+ productKey: record.productKey,
384
+ decision: approved ? 'approved' : 'rejected'
385
+ });
386
+ }
387
+ }
388
+ };
389
+ }
390
+ //# sourceMappingURL=purchase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["withTimeout","PURCHASE_FLOW_CEILING_MS","PaymentError","storeIdForProductKey","toPersistedRecord","createReceiptValidation","FAILURE_CODES","mapFailure","createPurchaseFlow","deps","resolved","askHook","validate","config","platform","emit","toRef","record","transactionId","productKey","upsert","snapshot","others","purchases","filter","p","commit","recordFor","purchase","find","inFlightSettle","Map","settleOnce","correlationId","running","get","flight","settle","finally","delete","set","decision","outcome","validationState","finalizeState","finalizer","enqueue","kind","reason","transaction","handlePending","alreadyPending","some","state","type","handleUnspecified","code","retryable","launchRequest","storeProductId","options","replaceKey","replaceProductKey","productType","entries","offerKey","obfuscatedAccountId","replacePurchaseToken","token","undefined","replaceStoreProductId","prorationMode","launch","request","launched","provider","launchPurchase","includesStoreTime","capabilities","purchaseOutcomeIncludesStoreTime","timeouts","purchaseLaunchMs","message","operation","enabled","status","statusKind","createsRealTransactions","mayCreateRealTransaction","recordBlockedOperation","environment","nextCorrelationId","attempt","runExclusive","ok","mapped","requestSync","acquired","value","ingest","byStoreId","existing","revalidate","hook","validateTransaction","queued","entry","approved","verificationPayload","map"],"sourceRoot":"../../../src","sources":["engine/purchase.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAmBA,SAASA,WAAW,QAAQ,kBAAe;AAC3C,SAASC,wBAAwB,QAAQ,mBAAgB;AACzD,SAASC,YAAY,QAAQ,0BAAuB;AAGpD,SAASC,oBAAoB,QAAQ,4BAAyB;AAE9D,SAASC,iBAAiB,QAAQ,WAAQ;AAoB1C;AACA,SAASC,uBAAuB,QAAQ,wBAAqB;AAC7D,SAASC,aAAa,EAA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