@chipmobilesdk/rn-payment 0.5.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 (317) hide show
  1. package/CHANGELOG.md +172 -0
  2. package/README.md +47 -16
  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
  296. package/skills/sdk-rn-payment/SKILL.md +4 -4
  297. package/src/adapter/iap-adapter.ts +12 -216
  298. package/src/adapter/iapShapes.ts +232 -0
  299. package/src/config/types.ts +8 -0
  300. package/src/config/validate.ts +19 -4
  301. package/src/core/retry.ts +1 -58
  302. package/src/diagnostics/events.ts +1 -1
  303. package/src/engine/connection.ts +194 -0
  304. package/src/engine/engine.ts +140 -700
  305. package/src/engine/internals.ts +40 -0
  306. package/src/engine/products.ts +39 -17
  307. package/src/engine/purchase.ts +22 -130
  308. package/src/engine/purchaseFailure.ts +48 -0
  309. package/src/engine/receiptValidation.ts +101 -0
  310. package/src/engine/state.ts +253 -0
  311. package/src/engine/sync.ts +161 -0
  312. package/src/entitlements/aggregate.ts +3 -5
  313. package/src/entitlements/mapping.ts +0 -22
  314. package/src/persistence/mmkv-store.ts +10 -3
  315. package/src/persistence/snapshot.ts +102 -27
  316. package/src/react/PaymentProvider.tsx +73 -24
  317. package/src/react/hooks.ts +13 -3
@@ -0,0 +1,160 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * The binding's shapes, and their translation into the port's vocabulary
5
+ * (PAY-12).
6
+ *
7
+ * The binding speaks Google Play: prices as micros in strings, offer tokens,
8
+ * numeric purchase states, store error codes. The port speaks this package's
9
+ * own. Keeping the translation here, with no I/O, no listeners and no module
10
+ * loading, is what makes it checkable against recorded payloads — and leaves
11
+ * the adapter next door about the calls it actually makes.
12
+ *
13
+ * The raw types are declared narrowly on purpose: they document the coupling,
14
+ * and a binding upgrade that changes one of these shapes fails to typecheck
15
+ * here rather than failing silently on a user's device.
16
+ */
17
+
18
+ /** What `purchaseErrorListener` delivers. */
19
+
20
+ /** Play's `PurchaseState`: 0 unspecified, 1 purchased, 2 pending. */
21
+ const PLAY_STATE_PURCHASED = 1;
22
+ const PLAY_STATE_PENDING = 2;
23
+
24
+ // Required lazily (rn-core's lazy peer) so importing the package does not require
25
+ // the native module.
26
+
27
+ export function toMicros(value) {
28
+ if (typeof value === 'number') {
29
+ return value;
30
+ }
31
+ if (typeof value === 'string') {
32
+ const parsed = Number.parseInt(value, 10);
33
+ return Number.isFinite(parsed) ? parsed : 0;
34
+ }
35
+ return 0;
36
+ }
37
+ export function normalizeProduct(raw, productType) {
38
+ const oneTime = raw.oneTimePurchaseOfferDetails;
39
+ const currencyCode = oneTime?.priceCurrencyCode ?? raw.currencyCode ?? raw.currency ?? '';
40
+ return {
41
+ storeProductId: raw.id ?? raw.productId ?? '',
42
+ productType,
43
+ title: raw.title ?? raw.name ?? '',
44
+ description: raw.description ?? '',
45
+ // Store-formatted, never built here: only the store knows the right currency
46
+ // symbol, separator, and placement for the user's locale (FR-028).
47
+ formattedPrice: oneTime?.formattedPrice ?? raw.displayPrice ?? raw.localizedPrice ?? '',
48
+ currencyCode,
49
+ priceAmountMicros: toMicros(oneTime?.priceAmountMicros ?? raw.price),
50
+ offers: (raw.subscriptionOfferDetails ?? []).map(offer => normalizeOffer(offer, currencyCode))
51
+ };
52
+ }
53
+ export function normalizeOffer(offer, fallbackCurrency) {
54
+ const phases = offer.pricingPhases?.pricingPhaseList ?? [];
55
+ // The last phase is the recurring price; earlier ones are trial or
56
+ // introductory. Play orders them that way.
57
+ const recurring = phases[phases.length - 1];
58
+ const intro = phases.length > 1 ? phases[0] : undefined;
59
+ const isFreeTrial = intro !== undefined && toMicros(intro.priceAmountMicros) === 0;
60
+ return {
61
+ offerKey: offer.offerToken ?? offer.offerId ?? offer.basePlanId ?? '',
62
+ billingPeriod: recurring?.billingPeriod ?? '',
63
+ formattedPrice: recurring?.formattedPrice ?? '',
64
+ priceAmountMicros: toMicros(recurring?.priceAmountMicros),
65
+ currencyCode: recurring?.priceCurrencyCode ?? fallbackCurrency,
66
+ trialPeriod: isFreeTrial ? intro?.billingPeriod : undefined,
67
+ introductoryPrice: intro && !isFreeTrial ? {
68
+ formattedPrice: intro.formattedPrice ?? '',
69
+ period: intro.billingPeriod ?? '',
70
+ cycles: intro.billingCycleCount ?? 1
71
+ } : undefined,
72
+ // Play decides eligibility by only returning offers the user qualifies for,
73
+ // so forwarding `true` reports the store's determination rather than
74
+ // computing our own (FR-026).
75
+ isEligible: true
76
+ };
77
+ }
78
+
79
+ /**
80
+ * Reads the purchase state from whichever field the binding filled.
81
+ *
82
+ * Pending is preserved, never flattened to purchased: that distinction is what
83
+ * stops an entitlement being granted for money that has not arrived (FR-037).
84
+ * And an unrecognized or missing state is `unspecified`, never `purchased`.
85
+ *
86
+ * 0.1.0 read only Play's numeric state and treated anything else as purchased.
87
+ * The 16.x binding hands JavaScript the *string* state and does not carry the
88
+ * numeric one across, so on a device every pending purchase arrived as a string,
89
+ * fell through to the default, and was granted. Unit tests could not see it: they
90
+ * drive the fake store, which never passes through here.
91
+ */
92
+ export function toProviderPurchaseState(raw) {
93
+ let numeric;
94
+ if (typeof raw.purchaseStateAndroid === 'number') {
95
+ numeric = raw.purchaseStateAndroid;
96
+ } else if (typeof raw.purchaseState === 'number') {
97
+ numeric = raw.purchaseState;
98
+ }
99
+ if (numeric !== undefined) {
100
+ if (numeric === PLAY_STATE_PENDING) {
101
+ return 'pending';
102
+ }
103
+ return numeric === PLAY_STATE_PURCHASED ? 'purchased' : 'unspecified';
104
+ }
105
+ switch (typeof raw.purchaseState === 'string' ? raw.purchaseState.toLowerCase() : '') {
106
+ case 'purchased':
107
+ case 'restored':
108
+ return 'purchased';
109
+ case 'pending':
110
+ case 'deferred':
111
+ return 'pending';
112
+ default:
113
+ return 'unspecified';
114
+ }
115
+ }
116
+ export function normalizePurchase(raw) {
117
+ return {
118
+ storeProductId: raw.productId ?? raw.ids?.[0] ?? '',
119
+ transactionId: raw.id ?? raw.transactionId ?? raw.purchaseToken ?? '',
120
+ token: raw.purchaseToken ?? '',
121
+ state: toProviderPurchaseState(raw),
122
+ purchasedAt: raw.transactionDate ?? Date.now(),
123
+ isAcknowledged: raw.isAcknowledgedAndroid ?? raw.isAcknowledged ?? false,
124
+ expiresAt: raw.expirationDateAndroid,
125
+ willAutoRenew: raw.autoRenewingAndroid ?? raw.isAutoRenewing,
126
+ // Opaque material for the app's backend. Carried here and handed to the
127
+ // validation hook only — never logged or put in an event (FR-074).
128
+ verificationPayload: raw.transactionReceipt ?? raw.dataAndroid
129
+ };
130
+ }
131
+
132
+ /** Maps a binding error code onto the port's vocabulary, so no store code escapes. */
133
+ export function mapErrorCode(code) {
134
+ switch (code) {
135
+ case 'E_USER_CANCELLED':
136
+ case 'user-cancelled':
137
+ return 'user_cancelled';
138
+ case 'E_ALREADY_OWNED':
139
+ case 'already-owned':
140
+ case 'item-already-owned':
141
+ return 'already_owned';
142
+ case 'E_ITEM_UNAVAILABLE':
143
+ case 'item-unavailable':
144
+ case 'sku-not-found':
145
+ return 'unknown_product';
146
+ case 'E_NOT_PREPARED':
147
+ case 'not-prepared':
148
+ return 'not_ready';
149
+ case 'E_NETWORK_ERROR':
150
+ case 'network-error':
151
+ return 'network_error';
152
+ case 'E_DEFERRED_PAYMENT':
153
+ // Not a failure — a pending purchase. The caller resolves it from the
154
+ // purchase update rather than from this error.
155
+ return 'store_error';
156
+ default:
157
+ return 'store_error';
158
+ }
159
+ }
160
+ //# sourceMappingURL=iapShapes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["PLAY_STATE_PURCHASED","PLAY_STATE_PENDING","toMicros","value","parsed","Number","parseInt","isFinite","normalizeProduct","raw","productType","oneTime","oneTimePurchaseOfferDetails","currencyCode","priceCurrencyCode","currency","storeProductId","id","productId","title","name","description","formattedPrice","displayPrice","localizedPrice","priceAmountMicros","price","offers","subscriptionOfferDetails","map","offer","normalizeOffer","fallbackCurrency","phases","pricingPhases","pricingPhaseList","recurring","length","intro","undefined","isFreeTrial","offerKey","offerToken","offerId","basePlanId","billingPeriod","trialPeriod","introductoryPrice","period","cycles","billingCycleCount","isEligible","toProviderPurchaseState","numeric","purchaseStateAndroid","purchaseState","toLowerCase","normalizePurchase","ids","transactionId","purchaseToken","token","state","purchasedAt","transactionDate","Date","now","isAcknowledged","isAcknowledgedAndroid","expiresAt","expirationDateAndroid","willAutoRenew","autoRenewingAndroid","isAutoRenewing","verificationPayload","transactionReceipt","dataAndroid","mapErrorCode","code"],"sourceRoot":"../../../src","sources":["adapter/iapShapes.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AA0DA;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AAK;IACxEE,SAAS,EAAE5D,GAAG,CAAC6D,qBAAqB;IACpCC,aAAa,EAAE9D,GAAG,CAAC+D,mBAAmB,IAAI/D,GAAG,CAACgE,cAAc;IAC5D;IACA;IACAC,mBAAmB,EAAEjE,GAAG,CAACkE,kBAAkB,IAAIlE,GAAG,CAACmE;EACpD,CAAC;AACF;;AAEA;AACA,OAAO,SAASC,YAAYA,CAACC,IAAwB,EAAyB;EAC7E,QAAQA,IAAI;IACX,KAAK,kBAAkB;IACvB,KAAK,gBAAgB;MACpB,OAAO,gBAAgB;IACxB,KAAK,iBAAiB;IACtB,KAAK,eAAe;IACpB,KAAK,oBAAoB;MACxB,OAAO,eAAe;IACvB,KAAK,oBAAoB;IACzB,KAAK,kBAAkB;IACvB,KAAK,eAAe;MACnB,OAAO,iBAAiB;IACzB,KAAK,gBAAgB;IACrB,KAAK,cAAc;MAClB,OAAO,WAAW;IACnB,KAAK,iBAAiB;IACtB,KAAK,eAAe;MACnB,OAAO,eAAe;IACvB,KAAK,oBAAoB;MACxB;MACA;MACA,OAAO,aAAa;IACrB;MACC,OAAO,aAAa;EACtB;AACD","ignoreList":[]}
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+
3
+ export {};
4
+ //# sourceMappingURL=port.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../../src","sources":["adapter/port.ts"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../../src","sources":["config/types.ts"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,175 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Catalog validation (FR-011).
5
+ *
6
+ * Runs at `configure`, before any connection is opened, so a bad catalog fails
7
+ * at configuration time rather than at the moment a user taps Buy. Every failure
8
+ * **names the offending entry** — "invalid catalog" alone is useless in an app
9
+ * with thirty products.
10
+ *
11
+ * All problems are collected rather than thrown one at a time, so a developer
12
+ * fixes the catalog in one pass instead of rerunning to find the next fault.
13
+ */
14
+
15
+ import { PaymentConfigError } from "../diagnostics/errors.js";
16
+ import { resolveForegroundSyncMinIntervalMs, resolveProductCacheTtlMs, resolveRetry, resolveStaleAfterMs, resolveTimeouts } from "../core/timers.js";
17
+ const PRODUCT_TYPES = ['one_time_permanent', 'one_time_consumable', 'subscription'];
18
+
19
+ /** The platform whose store identifiers a catalog must supply. */
20
+
21
+ /**
22
+ * A validated, indexed catalog plus every resolved policy value.
23
+ *
24
+ * Produced once so the hot paths never re-derive it, and so `getEntitlement` can
25
+ * stay a synchronous in-memory read (PERF-001).
26
+ */
27
+
28
+ export function validateConfig(config, platform = 'android') {
29
+ const problems = [];
30
+ const offenders = [];
31
+ const entries = new Map();
32
+ const grants = new Map();
33
+ const sources = new Map();
34
+ const byStoreId = new Map();
35
+ if (config.catalog.length === 0) {
36
+ problems.push('catalog is empty');
37
+ offenders.push('catalog');
38
+ }
39
+ for (const entry of config.catalog) {
40
+ const key = entry.productKey;
41
+ if (!key || key.trim() === '') {
42
+ problems.push('a catalog entry has an empty productKey');
43
+ offenders.push('(empty productKey)');
44
+ continue;
45
+ }
46
+ if (entries.has(key)) {
47
+ problems.push(`duplicate productKey "${key}"`);
48
+ offenders.push(key);
49
+ continue;
50
+ }
51
+ if (!PRODUCT_TYPES.includes(entry.productType)) {
52
+ problems.push(`productKey "${key}" has invalid productType "${String(entry.productType)}"`);
53
+ offenders.push(key);
54
+ }
55
+ const storeId = entry.storeProductIds[platform];
56
+ if (!storeId || storeId.trim() === '') {
57
+ problems.push(`productKey "${key}" is missing a store product id for platform "${platform}"`);
58
+ offenders.push(key);
59
+ } else {
60
+ const existing = byStoreId.get(storeId);
61
+ if (existing !== undefined) {
62
+ // Two product keys pointing at one store id would make a store callback
63
+ // ambiguous, so the wrong entitlement could be granted.
64
+ problems.push(`store product id "${storeId}" is used by both "${existing}" and "${key}"`);
65
+ offenders.push(key);
66
+ } else {
67
+ byStoreId.set(storeId, key);
68
+ }
69
+ }
70
+ if (!Array.isArray(entry.grants) || entry.grants.length === 0) {
71
+ problems.push(`productKey "${key}" grants no entitlement`);
72
+ offenders.push(key);
73
+ }
74
+ entries.set(key, entry);
75
+ grants.set(key, [...(entry.grants ?? [])]);
76
+ for (const entitlement of entry.grants ?? []) {
77
+ const list = sources.get(entitlement);
78
+ if (list) {
79
+ list.push(key);
80
+ } else {
81
+ sources.set(entitlement, [key]);
82
+ }
83
+ }
84
+ }
85
+
86
+ // An entitlement the app intends to query but no product can grant is almost
87
+ // always a typo, and it would otherwise sit at `not_entitled` forever with no
88
+ // indication why.
89
+ for (const entitlement of config.entitlements) {
90
+ if (!sources.has(entitlement)) {
91
+ problems.push(`entitlement "${entitlement}" is declared but no catalog product grants it`);
92
+ offenders.push(entitlement);
93
+ }
94
+ }
95
+
96
+ // A product granting something the app never declared is the mirror problem:
97
+ // harmless at runtime, but a strong signal of a rename half-applied.
98
+ const declared = new Set(config.entitlements);
99
+ for (const entitlement of sources.keys()) {
100
+ if (!declared.has(entitlement)) {
101
+ problems.push(`entitlement "${entitlement}" is granted by a product but not declared in config.entitlements`);
102
+ offenders.push(entitlement);
103
+ }
104
+ }
105
+ if (problems.length > 0) {
106
+ throw new PaymentConfigError({
107
+ code: 'PAYMENT_INVALID_CATALOG',
108
+ message: `Payment catalog is invalid: ${problems.join('; ')}`,
109
+ operation: 'configure',
110
+ offenders: [...new Set(offenders)]
111
+ });
112
+ }
113
+ return {
114
+ entries,
115
+ grants,
116
+ sources: new Map([...sources].map(([k, v]) => [k, [...v]])),
117
+ byStoreId,
118
+ entitlementKeys: [...config.entitlements],
119
+ platform,
120
+ enabled: config.enabled ?? true,
121
+ gracePolicy: config.gracePolicy ?? 'grant',
122
+ holdPolicy: config.holdPolicy ?? 'withhold',
123
+ staleAfterMs: resolveStaleAfterMs(config.staleAfterMs),
124
+ productCacheTtlMs: resolveProductCacheTtlMs(config.productCacheTtlMs),
125
+ foregroundSyncMinIntervalMs: resolveForegroundSyncMinIntervalMs(config.foregroundSyncMinIntervalMs),
126
+ timeouts: resolveTimeouts(config.timeouts),
127
+ retry: resolveRetry(config.retry),
128
+ onValidationUnavailable: config.onValidationUnavailable ?? 'grant_and_queue'
129
+ };
130
+ }
131
+
132
+ /**
133
+ * The fail-closed environment guard (FR-015).
134
+ *
135
+ * Separate from catalog validation because it is not about the catalog's shape
136
+ * but about whether this binary is allowed to move real money at all. Checked
137
+ * before connecting, and it refuses rather than warns: a non-production build
138
+ * that declares `production` is one tap away from charging a real card, and
139
+ * continuing silently is exactly the failure this package exists to prevent.
140
+ */
141
+ export function assertEnvironmentSafe(config) {
142
+ if (config.allowStoreTestPurchases === true && config.environment !== 'test') {
143
+ throw new PaymentConfigError({
144
+ code: 'PAYMENT_INVALID_CONFIG',
145
+ message: `allowStoreTestPurchases is only accepted with environment "test", not ` + `"${config.environment}": it exists for license testers, not for real users.`,
146
+ operation: 'configure',
147
+ offenders: ['allowStoreTestPurchases']
148
+ });
149
+ }
150
+ if (config.environment === 'production' && !config.isProductionBuild) {
151
+ throw new PaymentConfigError({
152
+ code: 'PAYMENT_PRODUCTION_CONFIG_IN_NON_PRODUCTION_BUILD',
153
+ message: 'environment is "production" but isProductionBuild is false. Refusing to ' + 'initialize: a non-production build must not be able to create a real ' + 'transaction.',
154
+ operation: 'configure',
155
+ offenders: ['environment']
156
+ });
157
+ }
158
+ }
159
+
160
+ /**
161
+ * Whether this configuration may hand a purchase to a real store (FR-014).
162
+ *
163
+ * True in a production build configured for production, and in a `test`
164
+ * environment that opted in with `allowStoreTestPurchases` (PAY-16). False
165
+ * everywhere else. The engine records each refusal in observable status so a
166
+ * test can assert the block happened — the difference between a guarantee and a
167
+ * hope.
168
+ */
169
+ export function mayCreateRealTransaction(config) {
170
+ if (config.environment === 'test' && config.allowStoreTestPurchases === true) {
171
+ return true;
172
+ }
173
+ return config.environment === 'production' && config.isProductionBuild;
174
+ }
175
+ //# sourceMappingURL=validate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["PaymentConfigError","resolveForegroundSyncMinIntervalMs","resolveProductCacheTtlMs","resolveRetry","resolveStaleAfterMs","resolveTimeouts","PRODUCT_TYPES","validateConfig","config","platform","problems","offenders","entries","Map","grants","sources","byStoreId","catalog","length","push","entry","key","productKey","trim","has","includes","productType","String","storeId","storeProductIds","existing","get","undefined","set","Array","isArray","entitlement","list","entitlements","declared","Set","keys","code","message","join","operation","map","k","v","entitlementKeys","enabled","gracePolicy","holdPolicy","staleAfterMs","productCacheTtlMs","foregroundSyncMinIntervalMs","timeouts","retry","onValidationUnavailable","assertEnvironmentSafe","allowStoreTestPurchases","environment","isProductionBuild","mayCreateRealTransaction"],"sourceRoot":"../../../src","sources":["config/validate.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,kBAAkB,QAAQ,0BAAuB;AAC1D,SACCC,kCAAkC,EAClCC,wBAAwB,EACxBC,YAAY,EACZC,mBAAmB,EACnBC,eAAe,QAGT,mBAAgB;AAWvB,MAAMC,aAAqC,GAAG,CAC7C,oBAAoB,EACpB,qBAAqB,EACrB,cAAc,CACd;;AAED;;AAGA;AACA;AACA;AACA;AACA;AACA;;AAsBA,OAAO,SAASC,cAAcA,CAC7BC,MAAqB,EACrBC,QAAwB,GAAG,SAAS,EACnB;EACjB,MAAMC,QAAkB,GAAG,EAAE;EAC7B,MAAMC,SAAmB,GAAG,EAAE;EAE9B,MAAMC,OAAO,GAAG,IAAIC,GAAG,CAA2B,CAAC;EACnD,MAAMC,MAAM,GAAG,IAAID,GAAG,CAAwC,CAAC;EAC/D,MAAME,OAAO,GAAG,IAAIF,GAAG,CAA+B,CAAC;EACvD,MAAMG,SAAS,GAAG,IAAIH,GAAG,CAAqB,CAAC;EAE/C,IAAIL,MAAM,CAACS,OAAO,CAACC,MAAM,KAAK,CAAC,EAAE;IAChCR,QAAQ,CAACS,IAAI,CAAC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concurrency primitives.
5
+ *
6
+ * These are what make three of the specification's guarantees structurally true
7
+ * rather than hoped for: concurrent initialization opens exactly one connection
8
+ * (FR-018), concurrent syncs make exactly one store request (FR-063), and a
9
+ * second purchase while one is open is refused rather than queued (FR-031).
10
+ *
11
+ * The distinction between the two primitives matters. `singleFlight` **joins**
12
+ * concurrent callers onto one operation — correct for init and sync, where every
13
+ * caller wants the same answer. `exclusive` **refuses** the second caller —
14
+ * correct for purchase, where joining would silently give two callers one
15
+ * transaction, and queueing would open a store surface the user no longer
16
+ * expects.
17
+ */
18
+
19
+ // The primitives themselves are rn-core's; the reasoning above is why rn-payment
20
+ // uses each where it does.
21
+ export { createExclusive, createRateLimiter, createSingleFlight, withTimeout } from '@chipmobilesdk/rn-core';
22
+ //# sourceMappingURL=mutex.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createExclusive","createRateLimiter","createSingleFlight","withTimeout"],"sourceRoot":"../../../src","sources":["core/mutex.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,SACCA,eAAe,EACfC,iBAAiB,EACjBC,kBAAkB,EAClBC,WAAW,QAEL,wBAAwB","ignoreList":[]}
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Bounded backoff.
5
+ *
6
+ * "Bounded" is the whole point (FR-020, FR-045): an unbounded reconnect loop
7
+ * against a billing service that is down drains battery and hammers a system
8
+ * service, and an unbounded finalize loop hides a real failure behind noise.
9
+ *
10
+ * Delay computation is pure and separated from waiting so tests can assert the
11
+ * schedule without burning real time.
12
+ */
13
+
14
+ import { computeBackoff } from '@chipmobilesdk/rn-core';
15
+ /**
16
+ * Delay before `attempt` (1-based), capped and optionally jittered.
17
+ *
18
+ * Jitter is full jitter over [0, capped]: several devices that lost the billing
19
+ * connection at the same moment should not retry in lockstep.
20
+ */
21
+ export function backoffDelayMs(attempt, config, random = Math.random) {
22
+ return computeBackoff(attempt, toSpec(config), random);
23
+ }
24
+ function toSpec(config) {
25
+ return {
26
+ initialDelayMs: config.initialDelayMs,
27
+ maxDelayMs: config.maxDelayMs,
28
+ factor: config.factor,
29
+ jitter: config.jitter ? 'full' : 'none',
30
+ maxAttempts: config.maxAttempts
31
+ };
32
+ }
33
+ //# sourceMappingURL=retry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["computeBackoff","backoffDelayMs","attempt","config","random","Math","toSpec","initialDelayMs","maxDelayMs","factor","jitter","maxAttempts"],"sourceRoot":"../../../src","sources":["core/retry.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,cAAc,QAAQ,wBAAwB;AAIvD;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,cAAcA,CAC7BC,OAAe,EACfC,MAA+B,EAC/BC,MAAoB,GAAGC,IAAI,CAACD,MAAM,EACzB;EACT,OAAOJ,cAAc,CAACE,OAAO,EAAEI,MAAM,CAACH,MAAM,CAAC,EAAEC,MAAM,CAAC;AACvD;AAEA,SAASE,MAAMA,CAACH,MAA+B,EAAE;EAChD,OAAO;IACNI,cAAc,EAAEJ,MAAM,CAACI,cAAc;IACrCC,UAAU,EAAEL,MAAM,CAACK,UAAU;IAC7BC,MAAM,EAAEN,MAAM,CAACM,MAAM;IACrBC,MAAM,EAAEP,MAAM,CAACO,MAAM,GAAI,MAAM,GAAc,MAAgB;IAC7DC,WAAW,EAAER,MAAM,CAACQ;EACrB,CAAC;AACF","ignoreList":[]}
@@ -0,0 +1,198 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Timeout, retry, and cache policy.
5
+ *
6
+ * Defaults and bounds live here rather than at each call site so there is one
7
+ * place to read what the package will wait for, and so consumers can read the
8
+ * values they are bound by instead of discovering them from a timeout in
9
+ * production.
10
+ *
11
+ * Out-of-band values are a configuration error rather than being silently
12
+ * clamped: quietly turning a 1-second timeout into 3 seconds would tell the app
13
+ * it configured something it did not.
14
+ */
15
+
16
+ import { checkRange } from '@chipmobilesdk/rn-core';
17
+ import { PaymentConfigError } from "../diagnostics/errors.js";
18
+ /** Local IPC to Play Services. Slower than this means unavailable, not busy. */
19
+ export const DEFAULT_CONNECT_TIMEOUT_MS = 10_000;
20
+ /** A network round trip; a paywall that hangs longer should show its error state. */
21
+ export const DEFAULT_PRODUCT_QUERY_TIMEOUT_MS = 15_000;
22
+ /** Runs at startup, so it must not hold the first render hostage. */
23
+ export const DEFAULT_SYNC_TIMEOUT_MS = 20_000;
24
+ /**
25
+ * Covers opening the store surface only.
26
+ *
27
+ * Time the user spends *inside* the store's own UI is deliberately excluded
28
+ * (FR-035): a user reading the terms, switching to their banking app for an OTP,
29
+ * or simply hesitating must never have their purchase cancelled by our clock.
30
+ */
31
+ export const DEFAULT_PURCHASE_LAUNCH_TIMEOUT_MS = 30_000;
32
+ /** Per finalize attempt, not per transaction — the queue owns overall persistence. */
33
+ export const DEFAULT_FINALIZE_ATTEMPT_TIMEOUT_MS = 15_000;
34
+ /** The app's backend hook. A user is waiting on a purchase result behind it. */
35
+ export const DEFAULT_VALIDATE_TIMEOUT_MS = 15_000;
36
+ /**
37
+ * The ceiling on a purchase flow whose outcome includes the user's own time in
38
+ * the store UI, so is otherwise untimed (FR-035). Not a timeout on the user: it
39
+ * exists only so a binding that never answers cannot hold the purchase lock for
40
+ * the rest of the session. A purchase that completes later still arrives through
41
+ * the store update channel and is granted then.
42
+ */
43
+ export const PURCHASE_FLOW_CEILING_MS = 10 * 60_000;
44
+ export const CONNECT_TIMEOUT_BOUNDS = {
45
+ min: 3_000,
46
+ max: 60_000
47
+ };
48
+ export const PRODUCT_QUERY_TIMEOUT_BOUNDS = {
49
+ min: 3_000,
50
+ max: 60_000
51
+ };
52
+ export const SYNC_TIMEOUT_BOUNDS = {
53
+ min: 5_000,
54
+ max: 120_000
55
+ };
56
+ export const PURCHASE_LAUNCH_TIMEOUT_BOUNDS = {
57
+ min: 5_000,
58
+ max: 120_000
59
+ };
60
+ export const FINALIZE_ATTEMPT_TIMEOUT_BOUNDS = {
61
+ min: 3_000,
62
+ max: 60_000
63
+ };
64
+ export const VALIDATE_TIMEOUT_BOUNDS = {
65
+ min: 3_000,
66
+ max: 120_000
67
+ };
68
+
69
+ /**
70
+ * Prices and offer eligibility are shown at the moment of purchase, so a short
71
+ * TTL with on-demand refresh beats a long one (FR-029).
72
+ */
73
+ export const DEFAULT_PRODUCT_CACHE_TTL_MS = 900_000;
74
+ export const PRODUCT_CACHE_TTL_BOUNDS = {
75
+ min: 60_000,
76
+ max: 86_400_000
77
+ };
78
+
79
+ /**
80
+ * How long a successful sync keeps entitlements trustworthy offline: **7 days**.
81
+ *
82
+ * Fixed by the specification (FR-055) after weighing both failure directions.
83
+ * The realistic offline cases — travel, poor coverage, a device left unused —
84
+ * resolve within days. Seven days covers a holiday without connectivity while
85
+ * bounding how long a refunded entitlement can outlive its refund to one week.
86
+ *
87
+ * Past this the entitlement becomes `unknown`, never `not_entitled` (FR-055a):
88
+ * the package stops asserting rather than telling a paying customer they did not
89
+ * pay.
90
+ */
91
+ export const DEFAULT_STALE_AFTER_MS = 604_800_000;
92
+ export const STALE_AFTER_BOUNDS = {
93
+ min: 3_600_000,
94
+ max: 7_776_000_000
95
+ };
96
+
97
+ /** Keeps rapid app switching from becoming a request storm (PERF-002). */
98
+ export const DEFAULT_FOREGROUND_SYNC_MIN_INTERVAL_MS = 60_000;
99
+ export const FOREGROUND_SYNC_MIN_INTERVAL_BOUNDS = {
100
+ min: 0,
101
+ max: 3_600_000
102
+ };
103
+
104
+ /** Bounded so a dropped billing connection cannot become a retry storm (FR-020). */
105
+ export const DEFAULT_RECONNECT_BACKOFF = {
106
+ initialDelayMs: 1_000,
107
+ maxDelayMs: 30_000,
108
+ factor: 2,
109
+ maxAttempts: 5,
110
+ jitter: true
111
+ };
112
+
113
+ /**
114
+ * Finalize retry.
115
+ *
116
+ * Bounded **per session** but never permanently abandoned: Google auto-refunds
117
+ * an unacknowledged purchase after three days, so exhausting this session's
118
+ * attempts must leave the transaction queued for the next launch, not dropped
119
+ * (FR-045).
120
+ */
121
+ export const DEFAULT_FINALIZE_BACKOFF = {
122
+ initialDelayMs: 2_000,
123
+ maxDelayMs: 60_000,
124
+ factor: 2,
125
+ maxAttempts: 5,
126
+ jitter: true
127
+ };
128
+ export const BACKOFF_MAX_DELAY_BOUNDS = {
129
+ min: 5_000,
130
+ max: 600_000
131
+ };
132
+ export const BACKOFF_ATTEMPT_BOUNDS = {
133
+ min: 1,
134
+ max: 10
135
+ };
136
+ /** A first retry sooner than this is a storm; later than this, the user has given up. */
137
+ export const BACKOFF_INITIAL_DELAY_BOUNDS = {
138
+ min: 100,
139
+ max: 60_000
140
+ };
141
+ /** 1 is a constant delay; 0 or below would retry at once, forever (CORE-05). */
142
+ export const BACKOFF_FACTOR_BOUNDS = {
143
+ min: 1,
144
+ max: 10
145
+ };
146
+ function invalidConfig(label) {
147
+ return message => new PaymentConfigError({
148
+ code: 'PAYMENT_INVALID_CONFIG',
149
+ message,
150
+ operation: 'configure',
151
+ offenders: [label]
152
+ });
153
+ }
154
+ function requireInBounds(label, value, fallback, bounds, unit = 'ms') {
155
+ return value === undefined ? fallback : checkRange(label, value, bounds, invalidConfig(label), unit);
156
+ }
157
+ export function resolveTimeouts(config) {
158
+ return {
159
+ connectMs: requireInBounds('timeouts.connectMs', config?.connectMs, DEFAULT_CONNECT_TIMEOUT_MS, CONNECT_TIMEOUT_BOUNDS),
160
+ productQueryMs: requireInBounds('timeouts.productQueryMs', config?.productQueryMs, DEFAULT_PRODUCT_QUERY_TIMEOUT_MS, PRODUCT_QUERY_TIMEOUT_BOUNDS),
161
+ syncMs: requireInBounds('timeouts.syncMs', config?.syncMs, DEFAULT_SYNC_TIMEOUT_MS, SYNC_TIMEOUT_BOUNDS),
162
+ purchaseLaunchMs: requireInBounds('timeouts.purchaseLaunchMs', config?.purchaseLaunchMs, DEFAULT_PURCHASE_LAUNCH_TIMEOUT_MS, PURCHASE_LAUNCH_TIMEOUT_BOUNDS),
163
+ finalizeAttemptMs: requireInBounds('timeouts.finalizeAttemptMs', config?.finalizeAttemptMs, DEFAULT_FINALIZE_ATTEMPT_TIMEOUT_MS, FINALIZE_ATTEMPT_TIMEOUT_BOUNDS),
164
+ validateMs: requireInBounds('timeouts.validateMs', config?.validateMs, DEFAULT_VALIDATE_TIMEOUT_MS, VALIDATE_TIMEOUT_BOUNDS)
165
+ };
166
+ }
167
+ function resolveBackoff(label, config, fallback) {
168
+ const maxDelayMs = requireInBounds(`${label}.maxDelayMs`, config?.maxDelayMs, fallback.maxDelayMs, BACKOFF_MAX_DELAY_BOUNDS);
169
+ const maxAttempts = requireInBounds(`${label}.maxAttempts`, config?.maxAttempts, fallback.maxAttempts, BACKOFF_ATTEMPT_BOUNDS, '');
170
+ const initialDelayMs = requireInBounds(`${label}.initialDelayMs`, config?.initialDelayMs, fallback.initialDelayMs, BACKOFF_INITIAL_DELAY_BOUNDS);
171
+ const factor = requireInBounds(`${label}.factor`, config?.factor, fallback.factor, BACKOFF_FACTOR_BOUNDS, '');
172
+ if (initialDelayMs > maxDelayMs) {
173
+ throw invalidConfig(`${label}.initialDelayMs`)(`${label}.initialDelayMs (${initialDelayMs}ms) exceeds ${label}.maxDelayMs (${maxDelayMs}ms)`);
174
+ }
175
+ return {
176
+ initialDelayMs,
177
+ maxDelayMs,
178
+ factor,
179
+ maxAttempts,
180
+ jitter: config?.jitter ?? fallback.jitter
181
+ };
182
+ }
183
+ export function resolveRetry(config) {
184
+ return {
185
+ reconnect: resolveBackoff('retry.reconnect', config?.reconnect, DEFAULT_RECONNECT_BACKOFF),
186
+ finalize: resolveBackoff('retry.finalize', config?.finalize, DEFAULT_FINALIZE_BACKOFF)
187
+ };
188
+ }
189
+ export function resolveStaleAfterMs(value) {
190
+ return requireInBounds('staleAfterMs', value, DEFAULT_STALE_AFTER_MS, STALE_AFTER_BOUNDS);
191
+ }
192
+ export function resolveProductCacheTtlMs(value) {
193
+ return requireInBounds('productCacheTtlMs', value, DEFAULT_PRODUCT_CACHE_TTL_MS, PRODUCT_CACHE_TTL_BOUNDS);
194
+ }
195
+ export function resolveForegroundSyncMinIntervalMs(value) {
196
+ return requireInBounds('foregroundSyncMinIntervalMs', value, DEFAULT_FOREGROUND_SYNC_MIN_INTERVAL_MS, FOREGROUND_SYNC_MIN_INTERVAL_BOUNDS);
197
+ }
198
+ //# sourceMappingURL=timers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["checkRange","PaymentConfigError","DEFAULT_CONNECT_TIMEOUT_MS","DEFAULT_PRODUCT_QUERY_TIMEOUT_MS","DEFAULT_SYNC_TIMEOUT_MS","DEFAULT_PURCHASE_LAUNCH_TIMEOUT_MS","DEFAULT_FINALIZE_ATTEMPT_TIMEOUT_MS","DEFAULT_VALIDATE_TIMEOUT_MS","PURCHASE_FLOW_CEILING_MS","CONNECT_TIMEOUT_BOUNDS","min","max","PRODUCT_QUERY_TIMEOUT_BOUNDS","SYNC_TIMEOUT_BOUNDS","PURCHASE_LAUNCH_TIMEOUT_BOUNDS","FINALIZE_ATTEMPT_TIMEOUT_BOUNDS","VALIDATE_TIMEOUT_BOUNDS","DEFAULT_PRODUCT_CACHE_TTL_MS","PRODUCT_CACHE_TTL_BOUNDS","DEFAULT_STALE_AFTER_MS","STALE_AFTER_BOUNDS","DEFAULT_FOREGROUND_SYNC_MIN_INTERVAL_MS","FOREGROUND_SYNC_MIN_INTERVAL_BOUNDS","DEFAULT_RECONNECT_BACKOFF","initialDelayMs","maxDelayMs","factor","maxAttempts","jitter","DEFAULT_FINALIZE_BACKOFF","BACKOFF_MAX_DELAY_BOUNDS","BACKOFF_ATTEMPT_BOUNDS","BACKOFF_INITIAL_DELAY_BOUNDS","BACKOFF_FACTOR_BOUNDS","invalidConfig","label","message","code","operation","offenders","requireInBounds","value","fallback","bounds","unit","undefined","resolveTimeouts","config","connectMs","productQueryMs","syncMs","purchaseLaunchMs","finalizeAttemptMs","validateMs","resolveBackoff","resolveRetry","reconnect","finalize","resolveStaleAfterMs","resolveProductCacheTtlMs","resolveForegroundSyncMinIntervalMs"],"sourceRoot":"../../../src","sources":["core/timers.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,UAAU,QAAoB,wBAAwB;AAE/D,SAASC,kBAAkB,QAAQ,0BAAuB;AAG1D;AACA,OAAO,MAAMC,0BAA0B,GAAG,MAAM;AAChD;AACA,OAAO,MAAMC,gCAAgC,GAAG,MAAM;AACtD;AACA,OAAO,MAAMC,uBAAuB,GAAG,MAAM;AAC7C;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,kCAAkC,GAAG,MAAM;AACxD;AACA,OAAO,MAAMC,mCAAmC,GAAG,MAAM;AACzD;AACA,OAAO,MAAMC,2BAA2B,GAAG,MAAM;AACjD;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,wBAAwB,GAAG,EAAE,GAAG,MAAM;AAEnD,OAAO,MAAMC,sBAAsB,GAAG;EAAEC,GAAG,EAAE,KAAK;EAAEC,GAAG,EAAE;AAAO,CAAU;AAC1E,OAAO,MAAMC,4BAA4B,GAAG;EAAEF,GAAG,EAAE,KAAK;EAAEC,GAAG,EAAE;AAAO,CAAU;AAChF,OAAO,MAAME,mBAAmB,GAAG;EAAEH,GAAG,EAAE,KAAK;EAAEC,GAAG,EAAE;AAAQ,CAAU;AACxE,OAAO,MAAMG,8BAA8B,GAAG;EAC7CJ,GAAG,EAAE,KAAK;EACVC,GAAG,EAAE;AACN,CAAU;AACV,OAAO,MAAMI,+BAA+B,GAAG;EAC9CL,GAAG,EAAE,KAAK;EACVC,GAAG,EAAE;AACN,CAAU;AACV,OAAO,MAAMK,uBAAuB,GAAG;EAAEN,GAAG,EAAE,KAAK;EAAEC,GAAG,EAAE;AAAQ,CAAU;;AAE5E;AACA;AACA;AACA;AACA,OAAO,MAAM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