@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,266 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "BACKOFF_ATTEMPT_BOUNDS", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _timers.BACKOFF_ATTEMPT_BOUNDS;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "BACKOFF_MAX_DELAY_BOUNDS", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _timers.BACKOFF_MAX_DELAY_BOUNDS;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "CONNECT_TIMEOUT_BOUNDS", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _timers.CONNECT_TIMEOUT_BOUNDS;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "DEFAULT_CONNECT_TIMEOUT_MS", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _timers.DEFAULT_CONNECT_TIMEOUT_MS;
28
+ }
29
+ });
30
+ Object.defineProperty(exports, "DEFAULT_DEVELOPER_MESSAGES", {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _messageKeys.DEFAULT_DEVELOPER_MESSAGES;
34
+ }
35
+ });
36
+ Object.defineProperty(exports, "DEFAULT_FINALIZE_ATTEMPT_TIMEOUT_MS", {
37
+ enumerable: true,
38
+ get: function () {
39
+ return _timers.DEFAULT_FINALIZE_ATTEMPT_TIMEOUT_MS;
40
+ }
41
+ });
42
+ Object.defineProperty(exports, "DEFAULT_FINALIZE_BACKOFF", {
43
+ enumerable: true,
44
+ get: function () {
45
+ return _timers.DEFAULT_FINALIZE_BACKOFF;
46
+ }
47
+ });
48
+ Object.defineProperty(exports, "DEFAULT_FOREGROUND_SYNC_MIN_INTERVAL_MS", {
49
+ enumerable: true,
50
+ get: function () {
51
+ return _timers.DEFAULT_FOREGROUND_SYNC_MIN_INTERVAL_MS;
52
+ }
53
+ });
54
+ Object.defineProperty(exports, "DEFAULT_MESSAGES", {
55
+ enumerable: true,
56
+ get: function () {
57
+ return _messageKeys.DEFAULT_MESSAGES;
58
+ }
59
+ });
60
+ Object.defineProperty(exports, "DEFAULT_PRODUCT_CACHE_TTL_MS", {
61
+ enumerable: true,
62
+ get: function () {
63
+ return _timers.DEFAULT_PRODUCT_CACHE_TTL_MS;
64
+ }
65
+ });
66
+ Object.defineProperty(exports, "DEFAULT_PRODUCT_QUERY_TIMEOUT_MS", {
67
+ enumerable: true,
68
+ get: function () {
69
+ return _timers.DEFAULT_PRODUCT_QUERY_TIMEOUT_MS;
70
+ }
71
+ });
72
+ Object.defineProperty(exports, "DEFAULT_PURCHASE_LAUNCH_TIMEOUT_MS", {
73
+ enumerable: true,
74
+ get: function () {
75
+ return _timers.DEFAULT_PURCHASE_LAUNCH_TIMEOUT_MS;
76
+ }
77
+ });
78
+ Object.defineProperty(exports, "DEFAULT_RECONNECT_BACKOFF", {
79
+ enumerable: true,
80
+ get: function () {
81
+ return _timers.DEFAULT_RECONNECT_BACKOFF;
82
+ }
83
+ });
84
+ Object.defineProperty(exports, "DEFAULT_STALE_AFTER_MS", {
85
+ enumerable: true,
86
+ get: function () {
87
+ return _timers.DEFAULT_STALE_AFTER_MS;
88
+ }
89
+ });
90
+ Object.defineProperty(exports, "DEFAULT_SYNC_TIMEOUT_MS", {
91
+ enumerable: true,
92
+ get: function () {
93
+ return _timers.DEFAULT_SYNC_TIMEOUT_MS;
94
+ }
95
+ });
96
+ Object.defineProperty(exports, "DEFAULT_USER_MESSAGES", {
97
+ enumerable: true,
98
+ get: function () {
99
+ return _messageKeys.DEFAULT_USER_MESSAGES;
100
+ }
101
+ });
102
+ Object.defineProperty(exports, "DEVELOPER_MESSAGE_KEYS", {
103
+ enumerable: true,
104
+ get: function () {
105
+ return _messageKeys.DEVELOPER_MESSAGE_KEYS;
106
+ }
107
+ });
108
+ Object.defineProperty(exports, "FINALIZE_ATTEMPT_TIMEOUT_BOUNDS", {
109
+ enumerable: true,
110
+ get: function () {
111
+ return _timers.FINALIZE_ATTEMPT_TIMEOUT_BOUNDS;
112
+ }
113
+ });
114
+ Object.defineProperty(exports, "FOREGROUND_SYNC_MIN_INTERVAL_BOUNDS", {
115
+ enumerable: true,
116
+ get: function () {
117
+ return _timers.FOREGROUND_SYNC_MIN_INTERVAL_BOUNDS;
118
+ }
119
+ });
120
+ Object.defineProperty(exports, "PAYMENT_ERROR_CODES", {
121
+ enumerable: true,
122
+ get: function () {
123
+ return _errors.PAYMENT_ERROR_CODES;
124
+ }
125
+ });
126
+ Object.defineProperty(exports, "PRODUCT_CACHE_TTL_BOUNDS", {
127
+ enumerable: true,
128
+ get: function () {
129
+ return _timers.PRODUCT_CACHE_TTL_BOUNDS;
130
+ }
131
+ });
132
+ Object.defineProperty(exports, "PRODUCT_QUERY_TIMEOUT_BOUNDS", {
133
+ enumerable: true,
134
+ get: function () {
135
+ return _timers.PRODUCT_QUERY_TIMEOUT_BOUNDS;
136
+ }
137
+ });
138
+ Object.defineProperty(exports, "PURCHASE_LAUNCH_TIMEOUT_BOUNDS", {
139
+ enumerable: true,
140
+ get: function () {
141
+ return _timers.PURCHASE_LAUNCH_TIMEOUT_BOUNDS;
142
+ }
143
+ });
144
+ Object.defineProperty(exports, "PaymentConfigError", {
145
+ enumerable: true,
146
+ get: function () {
147
+ return _errors.PaymentConfigError;
148
+ }
149
+ });
150
+ Object.defineProperty(exports, "PaymentError", {
151
+ enumerable: true,
152
+ get: function () {
153
+ return _errors.PaymentError;
154
+ }
155
+ });
156
+ Object.defineProperty(exports, "PaymentProvider", {
157
+ enumerable: true,
158
+ get: function () {
159
+ return _PaymentProvider.PaymentProvider;
160
+ }
161
+ });
162
+ Object.defineProperty(exports, "STALE_AFTER_BOUNDS", {
163
+ enumerable: true,
164
+ get: function () {
165
+ return _timers.STALE_AFTER_BOUNDS;
166
+ }
167
+ });
168
+ Object.defineProperty(exports, "SYNC_TIMEOUT_BOUNDS", {
169
+ enumerable: true,
170
+ get: function () {
171
+ return _timers.SYNC_TIMEOUT_BOUNDS;
172
+ }
173
+ });
174
+ Object.defineProperty(exports, "USER_MESSAGE_KEYS", {
175
+ enumerable: true,
176
+ get: function () {
177
+ return _messageKeys.USER_MESSAGE_KEYS;
178
+ }
179
+ });
180
+ Object.defineProperty(exports, "createEngine", {
181
+ enumerable: true,
182
+ get: function () {
183
+ return _engine.createEngine;
184
+ }
185
+ });
186
+ Object.defineProperty(exports, "createStoreProvider", {
187
+ enumerable: true,
188
+ get: function () {
189
+ return _createStoreProvider.createStoreProvider;
190
+ }
191
+ });
192
+ Object.defineProperty(exports, "isUserMessageKey", {
193
+ enumerable: true,
194
+ get: function () {
195
+ return _messageKeys.isUserMessageKey;
196
+ }
197
+ });
198
+ Object.defineProperty(exports, "paymentMessages", {
199
+ enumerable: true,
200
+ get: function () {
201
+ return _messageKeys.paymentMessages;
202
+ }
203
+ });
204
+ Object.defineProperty(exports, "syncOnForeground", {
205
+ enumerable: true,
206
+ get: function () {
207
+ return _foreground.syncOnForeground;
208
+ }
209
+ });
210
+ Object.defineProperty(exports, "useEntitlement", {
211
+ enumerable: true,
212
+ get: function () {
213
+ return _hooks.useEntitlement;
214
+ }
215
+ });
216
+ Object.defineProperty(exports, "useEntitlements", {
217
+ enumerable: true,
218
+ get: function () {
219
+ return _hooks.useEntitlements;
220
+ }
221
+ });
222
+ Object.defineProperty(exports, "usePaymentEngine", {
223
+ enumerable: true,
224
+ get: function () {
225
+ return _PaymentProvider.usePaymentEngine;
226
+ }
227
+ });
228
+ Object.defineProperty(exports, "usePaymentStatus", {
229
+ enumerable: true,
230
+ get: function () {
231
+ return _hooks.usePaymentStatus;
232
+ }
233
+ });
234
+ Object.defineProperty(exports, "usePendingPurchases", {
235
+ enumerable: true,
236
+ get: function () {
237
+ return _hooks.usePendingPurchases;
238
+ }
239
+ });
240
+ Object.defineProperty(exports, "useProducts", {
241
+ enumerable: true,
242
+ get: function () {
243
+ return _hooks.useProducts;
244
+ }
245
+ });
246
+ Object.defineProperty(exports, "usePurchase", {
247
+ enumerable: true,
248
+ get: function () {
249
+ return _hooks.usePurchase;
250
+ }
251
+ });
252
+ Object.defineProperty(exports, "useSync", {
253
+ enumerable: true,
254
+ get: function () {
255
+ return _hooks.useSync;
256
+ }
257
+ });
258
+ var _timers = require("./core/timers.js");
259
+ var _createStoreProvider = require("./adapter/createStoreProvider.js");
260
+ var _engine = require("./engine/engine.js");
261
+ var _foreground = require("./engine/foreground.js");
262
+ var _PaymentProvider = require("./react/PaymentProvider.js");
263
+ var _hooks = require("./react/hooks.js");
264
+ var _errors = require("./diagnostics/errors.js");
265
+ var _messageKeys = require("./diagnostics/messageKeys.js");
266
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_timers","require","_createStoreProvider","_engine","_foreground","_PaymentProvider","_hooks","_errors","_messageKeys"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4DA,IAAAA,OAAA,GAAAC,OAAA;AAiDA,IAAAC,oBAAA,GAAAD,OAAA;AAIA,IAAAE,OAAA,GAAAF,OAAA;AASA,IAAAG,WAAA,GAAAH,OAAA;AAGA,IAAAI,gBAAA,GAAAJ,OAAA;AAEA,IAAAK,MAAA,GAAAL,OAAA;AAYA,IAAAM,OAAA,GAAAN,OAAA;AAYA,IAAAO,YAAA,GAAAP,OAAA","ignoreList":[]}
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createMemorySnapshotStore = createMemorySnapshotStore;
7
+ exports.createSnapshotStore = createSnapshotStore;
8
+ var _rnCore = require("@chipmobilesdk/rn-core");
9
+ var _snapshot = require("./snapshot.js");
10
+ /**
11
+ * MMKV-backed snapshot store.
12
+ *
13
+ * Every MMKV import is confined to this file, so the rest of the package stays
14
+ * testable without a native module.
15
+ *
16
+ * MMKV is chosen because it is **synchronous**, which is what lets
17
+ * `getEntitlement` be an in-memory read with no I/O on render paths (PERF-001).
18
+ * An async store would force either an async entitlement read or a hidden
19
+ * hydration race on every call.
20
+ *
21
+ * Records are partitioned by cache-scope token (FR-057a). The token is a
22
+ * partition key and nothing more: never interpreted, never transmitted, never
23
+ * attached to a transaction.
24
+ */
25
+
26
+ const INSTANCE_ID = 'chipmobilesdk.payment';
27
+ const KEY_PREFIX = 'snapshot';
28
+ const mmkv = (0, _rnCore.lazyPeer)('react-native-mmkv', () => {
29
+ // Inside `try`, so Metro bundles an app that leaves this optional peer out.
30
+ try {
31
+ return require('react-native-mmkv');
32
+ } catch (cause) {
33
+ throw cause;
34
+ }
35
+ });
36
+ function scopeKey(scopeToken) {
37
+ // An explicit sentinel rather than an empty segment, so the unscoped record
38
+ // can never collide with a scope whose token happens to be empty.
39
+ return `${KEY_PREFIX}:${scopeToken ?? '__default__'}`;
40
+ }
41
+
42
+ /**
43
+ * Opens the MMKV instance through v4's `createMMKV`.
44
+ *
45
+ * Up to 0.2.0 this called `new MMKV()`, the v3 constructor. In v4 — the only
46
+ * major the peer range allows — `MMKV` is a type, not a value, so the call threw
47
+ * and the store fell back to memory on every device: entitlements read `unknown`
48
+ * after each cold start, and a pending purchase was forgotten after an app kill.
49
+ * Tests could not see it, because the test double still exported a v3 class.
50
+ */
51
+ function resolveBacking() {
52
+ // rn-core's port: MMKV when it opens, otherwise memory with `durable: false`.
53
+ const port = (0, _rnCore.openDurable)(() => mmkv.require(peer => new Error(`${peer} is not installed`)).createMMKV({
54
+ id: INSTANCE_ID
55
+ }));
56
+ return {
57
+ backing: {
58
+ getString: key => port.getString(key),
59
+ set: (key, value) => port.set(key, value),
60
+ remove: key => port.remove(key),
61
+ clearAll: () => port.clearAll(),
62
+ getAllKeys: () => port.keys()
63
+ },
64
+ durable: port.durable
65
+ };
66
+ }
67
+
68
+ /**
69
+ * Creates the store.
70
+ *
71
+ * The memory fallback is a **documented degradation**, not a silent one: without
72
+ * MMKV the snapshot does not survive a cold start, so entitlements read `unknown`
73
+ * until the first sync. That is safe by construction — `unknown`, never
74
+ * `not_entitled` (FR-047) — and FR-059's startup sync repairs it. `isDurable()`
75
+ * lets the engine warn, so the condition is visible rather than mysterious.
76
+ */
77
+ function createSnapshotStore(injected) {
78
+ const {
79
+ backing,
80
+ durable
81
+ } = injected ?? resolveBacking();
82
+ return {
83
+ load(scopeToken) {
84
+ const raw = backing.getString(scopeKey(scopeToken));
85
+ if (raw === undefined) {
86
+ return (0, _snapshot.emptySnapshot)(scopeToken);
87
+ }
88
+ let parsed;
89
+ try {
90
+ parsed = JSON.parse(raw);
91
+ } catch {
92
+ // Corrupt JSON is discarded rather than repaired: the store is the
93
+ // authoritative source and the next sync rebuilds from it.
94
+ return (0, _snapshot.emptySnapshot)(scopeToken);
95
+ }
96
+ const outcome = (0, _snapshot.migrateSnapshot)(parsed);
97
+ if (!outcome.ok) {
98
+ return (0, _snapshot.emptySnapshot)(scopeToken);
99
+ }
100
+
101
+ // A record whose stored token disagrees with the requested scope must not
102
+ // be served: that is precisely the account-switch inheritance FR-057a
103
+ // exists to prevent.
104
+ if (outcome.snapshot.scopeToken !== scopeToken) {
105
+ return (0, _snapshot.emptySnapshot)(scopeToken);
106
+ }
107
+ return outcome.snapshot;
108
+ },
109
+ save(snapshot) {
110
+ try {
111
+ backing.set(scopeKey(snapshot.scopeToken), JSON.stringify(snapshot));
112
+ return true;
113
+ } catch {
114
+ // A failed write must never take down a purchase flow. The in-memory
115
+ // state stays correct for this session and the next sync re-derives it;
116
+ // the engine reports it (PAY-13).
117
+ return false;
118
+ }
119
+ },
120
+ clearAll() {
121
+ try {
122
+ for (const key of backing.getAllKeys()) {
123
+ if (key.startsWith(`${KEY_PREFIX}:`)) {
124
+ backing.remove(key);
125
+ }
126
+ }
127
+ } catch {
128
+ // Best effort; a failure here must not throw into a logout flow.
129
+ }
130
+ },
131
+ isDurable: () => durable
132
+ };
133
+ }
134
+
135
+ /** Test seam for driving the store without the native module. */
136
+ function createMemorySnapshotStore() {
137
+ const memory = (0, _rnCore.createMemoryKeyValue)();
138
+ return createSnapshotStore({
139
+ backing: {
140
+ getString: key => memory.getString(key),
141
+ set: (key, value) => memory.set(key, value),
142
+ remove: key => memory.remove(key),
143
+ clearAll: () => memory.clearAll(),
144
+ getAllKeys: () => memory.keys()
145
+ },
146
+ durable: false
147
+ });
148
+ }
149
+ //# sourceMappingURL=mmkv-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_rnCore","require","_snapshot","INSTANCE_ID","KEY_PREFIX","mmkv","lazyPeer","cause","scopeKey","scopeToken","resolveBacking","port","openDurable","peer","Error","createMMKV","id","backing","getString","key","set","value","remove","clearAll","getAllKeys","keys","durable","createSnapshotStore","injected","load","raw","undefined","emptySnapshot","parsed","JSON","parse","outcome","migrateSnapshot","ok","snapshot","save","stringify","startsWith","isDurable","createMemorySnapshotStore","memory","createMemoryKeyValue"],"sourceRoot":"../../../src","sources":["persistence/mmkv-store.ts"],"mappings":";;;;;;;AAgBA,IAAAA,OAAA,GAAAC,OAAA;AAEA,IAAAC,SAAA,GAAAD,OAAA;AAlBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAMA,MAAME,WAAW,GAAG,uBAAuB;AAC3C,MAAMC,UAAU,GAAG,UAAU;AAE7B,MAAMC,IAAI,GAAG,IAAAC,gBAAQ,EAAC,mBAAmB,EAAE,MAAM;EAChD;EACA,IAAI;IACH,OAAOL,OAAO,CAAC,mBAAmB,CAAC;EACpC,CAAC,CAAC,OAAOM,KAAK,EAAE;IACf,MAAMA,KAAK;EACZ;AACD,CAAC,CAAC;AAeF,SAASC,QAAQA,CAACC,UAAmB,EAAU;EAC9C;EACA;EACA,OAAO,GAAGL,UAAU,IAAIK,UAAU,IAAI,aAAa,EAAE;AACtD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A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KAAKwB,MAAM,CAACzB,GAAG,CAACD,GAAG,EAAEE,KAAK,CAAC;MAC3CC,MAAM,EAAEH,GAAG,IAAI0B,MAAM,CAACvB,MAAM,CAACH,GAAG,CAAC;MACjCI,QAAQ,EAAEA,CAAA,KAAMsB,MAAM,CAACtB,QAAQ,CAAC,CAAC;MACjCC,UAAU,EAAEA,CAAA,KAAMqB,MAAM,CAACpB,IAAI,CAAC;IAC/B,CAAC;IACDC,OAAO,EAAE;EACV,CAAC,CAAC;AACH","ignoreList":[]}
@@ -0,0 +1,229 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.SNAPSHOT_SCHEMA_VERSION = exports.SNAPSHOT_MIGRATIONS = void 0;
7
+ exports.emptySnapshot = emptySnapshot;
8
+ exports.migrateSnapshot = migrateSnapshot;
9
+ exports.pendingFinalizations = pendingFinalizations;
10
+ exports.resolveFinalizeState = resolveFinalizeState;
11
+ /**
12
+ * The persisted snapshot: schema, versioning, and migration.
13
+ *
14
+ * What is stored here is **exhaustively** what the package keeps on the device,
15
+ * and the README repeats this list so an app owner can complete a Data safety
16
+ * declaration accurately (FR-056, POL-002).
17
+ *
18
+ * Deliberately absent: payment details, card data, billing address, user
19
+ * identity, raw receipts, verification payloads, and backend tokens.
20
+ */
21
+
22
+ /**
23
+ * 2 since 0.6.0: the never-written `entitlements` map and `finalized` state are
24
+ * gone (PAY-12). Entitlements are always derived from purchases, never stored.
25
+ */
26
+ const SNAPSHOT_SCHEMA_VERSION = exports.SNAPSHOT_SCHEMA_VERSION = 2;
27
+
28
+ /** Where a transaction stands with the store. */
29
+
30
+ /**
31
+ * Where a transaction stands in the finalization queue.
32
+ *
33
+ * `queued` is the load-bearing value: it is written **before** the store call is
34
+ * attempted, so an app killed mid-finalize leaves a recoverable record rather
35
+ * than a paid purchase that Google will auto-refund (FR-041, FR-042).
36
+ */
37
+
38
+ /** Whether the app's backend has ruled on this transaction (FR-072a). */
39
+
40
+ function emptySnapshot(scopeToken) {
41
+ return {
42
+ schemaVersion: SNAPSHOT_SCHEMA_VERSION,
43
+ scopeToken,
44
+ purchases: [],
45
+ lastSyncedAt: undefined
46
+ };
47
+ }
48
+
49
+ /**
50
+ * A migration from one schema version to the next.
51
+ *
52
+ * Kept as an ordered chain rather than a switch so each step stays small and
53
+ * independently testable, and so a device several versions behind is carried
54
+ * forward one hop at a time (NFR-009).
55
+ */
56
+
57
+ /** Registered migrations, one hop each. */
58
+ const SNAPSHOT_MIGRATIONS = exports.SNAPSHOT_MIGRATIONS = [{
59
+ // v1 stored an `entitlements` map nothing ever wrote to, and a `finalized`
60
+ // purchase state nothing ever set (PAY-12). Both go; a `finalized` record,
61
+ // should one exist, is a purchased one whose finalize progress is kept.
62
+ from: 1,
63
+ to: 2,
64
+ migrate(input) {
65
+ const rest = {
66
+ ...input
67
+ };
68
+ delete rest.entitlements;
69
+ const purchases = Array.isArray(rest.purchases) ? rest.purchases.map(record => typeof record === 'object' && record !== null && record.state === 'finalized' ? {
70
+ ...record,
71
+ state: 'purchased'
72
+ } : record) : rest.purchases;
73
+ return {
74
+ ...rest,
75
+ schemaVersion: 2,
76
+ purchases
77
+ };
78
+ }
79
+ }];
80
+ function migrateSnapshot(raw) {
81
+ if (typeof raw !== 'object' || raw === null) {
82
+ return {
83
+ ok: false,
84
+ reason: 'unreadable'
85
+ };
86
+ }
87
+ let working = {
88
+ ...raw
89
+ };
90
+ const version = working.schemaVersion;
91
+ if (typeof version !== 'number' || !Number.isInteger(version) || version < 1) {
92
+ return {
93
+ ok: false,
94
+ reason: 'unreadable'
95
+ };
96
+ }
97
+ if (version > SNAPSHOT_SCHEMA_VERSION) {
98
+ // A newer app version wrote this. Downgrading cannot know what was added,
99
+ // so refuse rather than silently drop fields.
100
+ return {
101
+ ok: false,
102
+ reason: 'unsupported_version'
103
+ };
104
+ }
105
+ let current = version;
106
+ let migrated = false;
107
+ while (current < SNAPSHOT_SCHEMA_VERSION) {
108
+ const step = SNAPSHOT_MIGRATIONS.find(m => m.from === current);
109
+ if (!step) {
110
+ return {
111
+ ok: false,
112
+ reason: 'unsupported_version'
113
+ };
114
+ }
115
+ working = step.migrate(working);
116
+ current = step.to;
117
+ migrated = true;
118
+ }
119
+ const snapshot = coerceSnapshot(working);
120
+ return snapshot ? {
121
+ ok: true,
122
+ snapshot,
123
+ migrated
124
+ } : {
125
+ ok: false,
126
+ reason: 'unreadable'
127
+ };
128
+ }
129
+
130
+ /**
131
+ * Validates shape after migration.
132
+ *
133
+ * Runs even on a non-migrated record because the bytes came off a device where
134
+ * anything could have happened to them — a partial write, a rooted user, a
135
+ * truncated file.
136
+ */
137
+ function coerceSnapshot(input) {
138
+ const purchases = input.purchases;
139
+ if (!Array.isArray(purchases)) {
140
+ return null;
141
+ }
142
+ const lastSyncedAt = typeof input.lastSyncedAt === 'number' ? input.lastSyncedAt : undefined;
143
+ const scopeToken = typeof input.scopeToken === 'string' ? input.scopeToken : undefined;
144
+ return {
145
+ schemaVersion: SNAPSHOT_SCHEMA_VERSION,
146
+ scopeToken,
147
+ // Record by record: one damaged entry is dropped, not trusted and not
148
+ // allowed to discard the rest (PAY-13). A dropped record comes back with the
149
+ // next sync, if the store still reports it.
150
+ purchases: purchases.flatMap(record => {
151
+ const valid = coercePurchase(record);
152
+ return valid ? [valid] : [];
153
+ }),
154
+ lastSyncedAt
155
+ };
156
+ }
157
+ const PURCHASE_STATES = new Set(['pending', 'purchased', 'consumed', 'revoked']);
158
+ const FINALIZE_STATES = new Set(['not_required', 'queued', 'in_flight', 'done', 'failed']);
159
+ const VALIDATION_STATES = new Set(['not_required', 'approved', 'rejected', 'queued_for_revalidation']);
160
+ const PRODUCT_TYPES = new Set(['one_time_permanent', 'one_time_consumable', 'subscription']);
161
+
162
+ /** A persisted purchase with every field checked, or null when any is wrong. */
163
+ function coercePurchase(input) {
164
+ if (typeof input !== 'object' || input === null) {
165
+ return null;
166
+ }
167
+ const record = input;
168
+ const text = value => typeof value === 'string' && value !== '';
169
+ const count = value => typeof value === 'number' && Number.isFinite(value) && value >= 0;
170
+ if (!text(record.transactionId) || !text(record.productKey) || !text(record.token) || !PRODUCT_TYPES.has(record.productType) || !PURCHASE_STATES.has(record.state) || !FINALIZE_STATES.has(record.finalizeState) || !VALIDATION_STATES.has(record.validationState) || !count(record.purchasedAt) || !count(record.attempts) || record.expiresAt !== undefined && !count(record.expiresAt) || record.willAutoRenew !== undefined && typeof record.willAutoRenew !== 'boolean') {
171
+ return null;
172
+ }
173
+ return {
174
+ transactionId: record.transactionId,
175
+ productKey: record.productKey,
176
+ productType: record.productType,
177
+ token: record.token,
178
+ state: record.state,
179
+ purchasedAt: record.purchasedAt,
180
+ finalizeState: record.finalizeState,
181
+ attempts: record.attempts,
182
+ validationState: record.validationState,
183
+ expiresAt: record.expiresAt,
184
+ willAutoRenew: record.willAutoRenew
185
+ };
186
+ }
187
+
188
+ /**
189
+ * Decides a purchase's finalization state from the store's view plus what we
190
+ * already knew.
191
+ *
192
+ * Shared by the sync path and the purchase path so they cannot drift — and they
193
+ * must not, because a disagreement here is how a paid transaction goes
194
+ * unacknowledged and gets auto-refunded three days later.
195
+ *
196
+ * The subtle case is a **pending purchase that settles**. Its record was written
197
+ * with `not_required`, which was correct while the money had not arrived. Once the
198
+ * store reports it `purchased`, that value must be re-evaluated rather than
199
+ * preserved — otherwise the transaction is never queued, never acknowledged, and
200
+ * Google revokes it. Progress is preserved only for a transaction that was
201
+ * already in the queue.
202
+ */
203
+ function resolveFinalizeState(incoming, existing) {
204
+ if (incoming.state === 'pending') {
205
+ // Nothing to settle: there is no entitlement to report as delivered.
206
+ return 'not_required';
207
+ }
208
+
209
+ // Already settled at the store, whatever we thought locally.
210
+ if (incoming.isAcknowledged) {
211
+ return 'done';
212
+ }
213
+
214
+ // Genuine in-queue progress is preserved, so a sync cannot reset an attempt
215
+ // count or lose an in-flight finalize.
216
+ if (existing && existing.finalizeState !== 'not_required' && existing.finalizeState !== 'done') {
217
+ return existing.finalizeState;
218
+ }
219
+
220
+ // Covers both a brand-new purchase and a previously-pending one that just
221
+ // settled. Either way it is now owed a finalize call.
222
+ return 'queued';
223
+ }
224
+
225
+ /** Transactions still owed a finalize call, drained at startup and on foreground (FR-042). */
226
+ function pendingFinalizations(snapshot) {
227
+ return snapshot.purchases.filter(p => (p.finalizeState === 'queued' || p.finalizeState === 'in_flight' || p.finalizeState === 'failed') && p.state !== 'revoked');
228
+ }
229
+ //# sourceMappingURL=snapshot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["SNAPSHOT_SCHEMA_VERSION","exports","emptySnapshot","scopeToken","schemaVersion","purchases","lastSyncedAt","undefined","SNAPSHOT_MIGRATIONS","from","to","migrate","input","rest","entitlements","Array","isArray","map","record","state","migrateSnapshot","raw","ok","reason","working","version","Number","isInteger","current","migrated","step","find","m","snapshot","coerceSnapshot","flatMap","valid","coercePurchase","PURCHASE_STATES","Set","FINALIZE_STATES","VALIDATION_STATES","PRODUCT_TYPES","text","value","count","isFinite","transactionId","productKey","token","has","productType","finalizeState","validationState","purchasedAt","attempts","expiresAt","willAutoRenew","resolveFinalizeState","incoming","existing","isAcknowledged","pendingFinalizations","filter","p"],"sourceRoot":"../../../src","sources":["persistence/snapshot.ts"],"mappings":";;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACO,MAAMA,uBAAuB,GAAAC,OAAA,CAAAD,uBAAA,GAAG,CAAC;;AAExC;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA;;AA2BO,SAASE,aAAaA,CAACC,UAAmB,EAAqB;EACrE,OAAO;IACNC,aAAa,EAAEJ,uBAAuB;IACtCG,UAAU;IACVE,SAAS,EAAE,EAAE;IACbC,YAAY,EAAEC;EACf,CAAC;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAOA;AACO,MAAMC,mBAAiD,GAAAP,OAAA,CAAAO,mBAAA,GAAG,CAChE;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