react-native-iap 13.0.4 → 14.0.0-rc.1

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 (381) hide show
  1. package/NitroIap.podspec +33 -0
  2. package/README.md +163 -51
  3. package/android/CMakeLists.txt +32 -0
  4. package/android/build.gradle +107 -138
  5. package/android/fix-prefab.gradle +51 -0
  6. package/android/gradle.properties +5 -13
  7. package/android/src/main/AndroidManifest.xml +1 -4
  8. package/android/src/main/cpp/cpp-adapter.cpp +6 -0
  9. package/android/src/main/java/com/margelo/nitro/iap/HybridRnIap.kt +843 -0
  10. package/android/src/main/java/com/margelo/nitro/iap/NitroIapPackage.java +33 -0
  11. package/android/src/main/java/com/margelo/nitro/iap/Types.kt +173 -0
  12. package/ios/Bridge.h +8 -0
  13. package/ios/ErrorUtils.swift +153 -0
  14. package/ios/HybridRnIap.swift +1326 -0
  15. package/ios/ProductStore.swift +33 -0
  16. package/ios/reactnativeiap.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  17. package/ios/reactnativeiap.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  18. package/lib/module/helpers/subscription.js +56 -0
  19. package/lib/module/helpers/subscription.js.map +1 -0
  20. package/lib/module/hooks/useIAP.js +175 -123
  21. package/lib/module/hooks/useIAP.js.map +1 -1
  22. package/lib/module/index.js +1015 -9
  23. package/lib/module/index.js.map +1 -1
  24. package/lib/module/package.json +1 -0
  25. package/lib/module/specs/RnIap.nitro.js +4 -0
  26. package/lib/{commonjs/modules/common.js.map → module/specs/RnIap.nitro.js.map} +1 -1
  27. package/lib/module/types.js +187 -0
  28. package/lib/module/types.js.map +1 -0
  29. package/lib/module/utils/error.js +80 -0
  30. package/lib/module/utils/error.js.map +1 -0
  31. package/lib/module/utils/type-bridge.js +202 -0
  32. package/lib/module/utils/type-bridge.js.map +1 -0
  33. package/lib/typescript/package.json +1 -0
  34. package/lib/typescript/plugin/src/withIAP.d.ts +2 -7
  35. package/lib/typescript/plugin/src/withIAP.d.ts.map +1 -1
  36. package/lib/typescript/scripts/check-nitro-versions.d.ts +3 -0
  37. package/lib/typescript/scripts/check-nitro-versions.d.ts.map +1 -0
  38. package/lib/typescript/src/helpers/subscription.d.ts +14 -0
  39. package/lib/typescript/src/helpers/subscription.d.ts.map +1 -0
  40. package/lib/typescript/src/hooks/useIAP.d.ts +42 -26
  41. package/lib/typescript/src/hooks/useIAP.d.ts.map +1 -1
  42. package/lib/typescript/src/index.d.ts +356 -8
  43. package/lib/typescript/src/index.d.ts.map +1 -1
  44. package/lib/typescript/src/specs/RnIap.nitro.d.ts +404 -0
  45. package/lib/typescript/src/specs/RnIap.nitro.d.ts.map +1 -0
  46. package/lib/typescript/src/types.d.ts +544 -0
  47. package/lib/typescript/src/types.d.ts.map +1 -0
  48. package/lib/typescript/src/utils/error.d.ts +30 -0
  49. package/lib/typescript/src/utils/error.d.ts.map +1 -0
  50. package/lib/typescript/src/utils/type-bridge.d.ts +40 -0
  51. package/lib/typescript/src/utils/type-bridge.d.ts.map +1 -0
  52. package/nitro.json +17 -0
  53. package/nitrogen/generated/android/NitroIap+autolinking.cmake +80 -0
  54. package/nitrogen/generated/android/NitroIap+autolinking.gradle +27 -0
  55. package/nitrogen/generated/android/NitroIapOnLoad.cpp +50 -0
  56. package/nitrogen/generated/android/NitroIapOnLoad.hpp +25 -0
  57. package/nitrogen/generated/android/c++/JFunc_void_NitroProduct.hpp +78 -0
  58. package/nitrogen/generated/android/c++/JFunc_void_NitroPurchase.hpp +78 -0
  59. package/nitrogen/generated/android/c++/JFunc_void_NitroPurchaseResult.hpp +78 -0
  60. package/nitrogen/generated/android/c++/JHybridRnIapSpec.cpp +577 -0
  61. package/nitrogen/generated/android/c++/JHybridRnIapSpec.hpp +93 -0
  62. package/nitrogen/generated/android/c++/JNitroAndroidReceiptValidationOptions.hpp +66 -0
  63. package/nitrogen/generated/android/c++/JNitroAvailablePurchasesAndroidOptions.hpp +54 -0
  64. package/nitrogen/generated/android/c++/JNitroAvailablePurchasesIosOptions.hpp +65 -0
  65. package/nitrogen/generated/android/c++/JNitroAvailablePurchasesOptions.hpp +62 -0
  66. package/nitrogen/generated/android/c++/JNitroFinishTransactionAndroidParams.hpp +58 -0
  67. package/nitrogen/generated/android/c++/JNitroFinishTransactionIosParams.hpp +53 -0
  68. package/nitrogen/generated/android/c++/JNitroFinishTransactionParams.hpp +62 -0
  69. package/nitrogen/generated/android/c++/JNitroProduct.hpp +154 -0
  70. package/nitrogen/generated/android/c++/JNitroPurchase.hpp +122 -0
  71. package/nitrogen/generated/android/c++/JNitroPurchaseRequest.hpp +66 -0
  72. package/nitrogen/generated/android/c++/JNitroPurchaseResult.hpp +70 -0
  73. package/nitrogen/generated/android/c++/JNitroReceiptValidationParams.hpp +60 -0
  74. package/nitrogen/generated/android/c++/JNitroReceiptValidationResultAndroid.hpp +122 -0
  75. package/nitrogen/generated/android/c++/JNitroReceiptValidationResultIOS.hpp +68 -0
  76. package/nitrogen/generated/android/c++/JNitroRequestPurchaseAndroid.hpp +115 -0
  77. package/nitrogen/generated/android/c++/JNitroRequestPurchaseIos.hpp +84 -0
  78. package/nitrogen/generated/android/c++/JNitroSubscriptionOffer.hpp +57 -0
  79. package/nitrogen/generated/android/c++/JNitroSubscriptionRenewalInfo.hpp +74 -0
  80. package/nitrogen/generated/android/c++/JNitroSubscriptionStatus.hpp +64 -0
  81. package/nitrogen/generated/android/c++/JVariant_Boolean_NitroPurchaseResult.cpp +26 -0
  82. package/nitrogen/generated/android/c++/JVariant_Boolean_NitroPurchaseResult.hpp +71 -0
  83. package/nitrogen/generated/android/c++/JVariant_NitroReceiptValidationResultIOS_NitroReceiptValidationResultAndroid.cpp +26 -0
  84. package/nitrogen/generated/android/c++/JVariant_NitroReceiptValidationResultIOS_NitroReceiptValidationResultAndroid.hpp +75 -0
  85. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/Func_void_NitroProduct.kt +81 -0
  86. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/Func_void_NitroPurchase.kt +81 -0
  87. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/Func_void_NitroPurchaseResult.kt +81 -0
  88. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/HybridRnIapSpec.kt +198 -0
  89. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroAndroidReceiptValidationOptions.kt +38 -0
  90. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroAvailablePurchasesAndroidOptions.kt +29 -0
  91. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroAvailablePurchasesIosOptions.kt +38 -0
  92. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroAvailablePurchasesOptions.kt +32 -0
  93. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroFinishTransactionAndroidParams.kt +32 -0
  94. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroFinishTransactionIosParams.kt +29 -0
  95. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroFinishTransactionParams.kt +32 -0
  96. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroIapOnLoad.kt +35 -0
  97. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroProduct.kt +104 -0
  98. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroPurchase.kt +80 -0
  99. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroPurchaseRequest.kt +32 -0
  100. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroPurchaseResult.kt +41 -0
  101. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroReceiptValidationParams.kt +32 -0
  102. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroReceiptValidationResultAndroid.kt +80 -0
  103. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroReceiptValidationResultIOS.kt +38 -0
  104. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroRequestPurchaseAndroid.kt +47 -0
  105. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroRequestPurchaseIos.kt +41 -0
  106. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroSubscriptionOffer.kt +32 -0
  107. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroSubscriptionRenewalInfo.kt +44 -0
  108. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroSubscriptionStatus.kt +35 -0
  109. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/Variant_Boolean_NitroPurchaseResult.kt +42 -0
  110. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/Variant_NitroReceiptValidationResultIOS_NitroReceiptValidationResultAndroid.kt +42 -0
  111. package/nitrogen/generated/ios/NitroIap+autolinking.rb +60 -0
  112. package/nitrogen/generated/ios/NitroIap-Swift-Cxx-Bridge.cpp +152 -0
  113. package/nitrogen/generated/ios/NitroIap-Swift-Cxx-Bridge.hpp +1061 -0
  114. package/nitrogen/generated/ios/NitroIap-Swift-Cxx-Umbrella.hpp +107 -0
  115. package/nitrogen/generated/ios/NitroIapAutolinking.mm +33 -0
  116. package/nitrogen/generated/ios/NitroIapAutolinking.swift +25 -0
  117. package/nitrogen/generated/ios/c++/HybridRnIapSpecSwift.cpp +11 -0
  118. package/nitrogen/generated/ios/c++/HybridRnIapSpecSwift.hpp +355 -0
  119. package/nitrogen/generated/ios/swift/Func_void.swift +47 -0
  120. package/nitrogen/generated/ios/swift/Func_void_NitroProduct.swift +47 -0
  121. package/nitrogen/generated/ios/swift/Func_void_NitroPurchase.swift +47 -0
  122. package/nitrogen/generated/ios/swift/Func_void_NitroPurchaseResult.swift +47 -0
  123. package/nitrogen/generated/ios/swift/Func_void_bool.swift +47 -0
  124. package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +47 -0
  125. package/nitrogen/generated/ios/swift/Func_void_std__optional_NitroProduct_.swift +54 -0
  126. package/nitrogen/generated/ios/swift/Func_void_std__optional_NitroPurchase_.swift +54 -0
  127. package/nitrogen/generated/ios/swift/Func_void_std__optional_std__string_.swift +54 -0
  128. package/nitrogen/generated/ios/swift/Func_void_std__optional_std__vector_NitroSubscriptionStatus__.swift +54 -0
  129. package/nitrogen/generated/ios/swift/Func_void_std__string.swift +47 -0
  130. package/nitrogen/generated/ios/swift/Func_void_std__variant_NitroReceiptValidationResultIOS__NitroReceiptValidationResultAndroid_.swift +59 -0
  131. package/nitrogen/generated/ios/swift/Func_void_std__variant_bool__NitroPurchaseResult_.swift +59 -0
  132. package/nitrogen/generated/ios/swift/Func_void_std__vector_NitroProduct_.swift +47 -0
  133. package/nitrogen/generated/ios/swift/Func_void_std__vector_NitroPurchase_.swift +47 -0
  134. package/nitrogen/generated/ios/swift/HybridRnIapSpec.swift +78 -0
  135. package/nitrogen/generated/ios/swift/HybridRnIapSpec_cxx.swift +750 -0
  136. package/nitrogen/generated/ios/swift/NitroAndroidReceiptValidationOptions.swift +80 -0
  137. package/nitrogen/generated/ios/swift/NitroAvailablePurchasesAndroidOptions.swift +54 -0
  138. package/nitrogen/generated/ios/swift/NitroAvailablePurchasesIosOptions.swift +116 -0
  139. package/nitrogen/generated/ios/swift/NitroAvailablePurchasesOptions.swift +84 -0
  140. package/nitrogen/generated/ios/swift/NitroFinishTransactionAndroidParams.swift +58 -0
  141. package/nitrogen/generated/ios/swift/NitroFinishTransactionIosParams.swift +35 -0
  142. package/nitrogen/generated/ios/swift/NitroFinishTransactionParams.swift +84 -0
  143. package/nitrogen/generated/ios/swift/NitroProduct.swift +653 -0
  144. package/nitrogen/generated/ios/swift/NitroPurchase.swift +453 -0
  145. package/nitrogen/generated/ios/swift/NitroPurchaseRequest.swift +84 -0
  146. package/nitrogen/generated/ios/swift/NitroPurchaseResult.swift +117 -0
  147. package/nitrogen/generated/ios/swift/NitroReceiptValidationParams.swift +65 -0
  148. package/nitrogen/generated/ios/swift/NitroReceiptValidationResultAndroid.swift +258 -0
  149. package/nitrogen/generated/ios/swift/NitroReceiptValidationResultIOS.swift +87 -0
  150. package/nitrogen/generated/ios/swift/NitroRequestPurchaseAndroid.swift +225 -0
  151. package/nitrogen/generated/ios/swift/NitroRequestPurchaseIos.swift +161 -0
  152. package/nitrogen/generated/ios/swift/NitroSubscriptionOffer.swift +46 -0
  153. package/nitrogen/generated/ios/swift/NitroSubscriptionRenewalInfo.swift +152 -0
  154. package/nitrogen/generated/ios/swift/NitroSubscriptionStatus.swift +76 -0
  155. package/nitrogen/generated/ios/swift/Variant_Bool_NitroPurchaseResult.swift +18 -0
  156. package/nitrogen/generated/ios/swift/Variant_NitroReceiptValidationResultIOS_NitroReceiptValidationResultAndroid.swift +18 -0
  157. package/nitrogen/generated/shared/c++/HybridRnIapSpec.cpp +50 -0
  158. package/nitrogen/generated/shared/c++/HybridRnIapSpec.hpp +125 -0
  159. package/nitrogen/generated/shared/c++/NitroAndroidReceiptValidationOptions.hpp +80 -0
  160. package/nitrogen/generated/shared/c++/NitroAvailablePurchasesAndroidOptions.hpp +68 -0
  161. package/nitrogen/generated/shared/c++/NitroAvailablePurchasesIosOptions.hpp +79 -0
  162. package/nitrogen/generated/shared/c++/NitroAvailablePurchasesOptions.hpp +76 -0
  163. package/nitrogen/generated/shared/c++/NitroFinishTransactionAndroidParams.hpp +72 -0
  164. package/nitrogen/generated/shared/c++/NitroFinishTransactionIosParams.hpp +67 -0
  165. package/nitrogen/generated/shared/c++/NitroFinishTransactionParams.hpp +76 -0
  166. package/nitrogen/generated/shared/c++/NitroProduct.hpp +168 -0
  167. package/nitrogen/generated/shared/c++/NitroPurchase.hpp +136 -0
  168. package/nitrogen/generated/shared/c++/NitroPurchaseRequest.hpp +76 -0
  169. package/nitrogen/generated/shared/c++/NitroPurchaseResult.hpp +84 -0
  170. package/nitrogen/generated/shared/c++/NitroReceiptValidationParams.hpp +74 -0
  171. package/nitrogen/generated/shared/c++/NitroReceiptValidationResultAndroid.hpp +136 -0
  172. package/nitrogen/generated/shared/c++/NitroReceiptValidationResultIOS.hpp +82 -0
  173. package/nitrogen/generated/shared/c++/NitroRequestPurchaseAndroid.hpp +95 -0
  174. package/nitrogen/generated/shared/c++/NitroRequestPurchaseIos.hpp +85 -0
  175. package/nitrogen/generated/shared/c++/NitroSubscriptionOffer.hpp +71 -0
  176. package/nitrogen/generated/shared/c++/NitroSubscriptionRenewalInfo.hpp +88 -0
  177. package/nitrogen/generated/shared/c++/NitroSubscriptionStatus.hpp +78 -0
  178. package/package.json +145 -104
  179. package/plugin/build/src/withIAP.d.ts +3 -0
  180. package/plugin/build/src/withIAP.js +81 -0
  181. package/plugin/build/tsconfig.tsbuildinfo +1 -0
  182. package/plugin/build/withIAP.d.ts +2 -7
  183. package/plugin/build/withIAP.js +62 -51
  184. package/plugin/src/withIAP.ts +119 -0
  185. package/plugin/tsconfig.json +18 -0
  186. package/plugin/tsconfig.tsbuildinfo +1 -0
  187. package/src/helpers/subscription.ts +65 -0
  188. package/src/hooks/useIAP.ts +361 -222
  189. package/src/index.ts +1194 -9
  190. package/src/specs/RnIap.nitro.ts +501 -0
  191. package/src/types.ts +680 -0
  192. package/src/utils/error.ts +97 -0
  193. package/src/utils/type-bridge.ts +209 -0
  194. package/LICENSE +0 -21
  195. package/RNIap.podspec +0 -36
  196. package/android/src/amazon/AndroidManifest.xml +0 -14
  197. package/android/src/amazon/java/com/dooboolab/rniap/EventSender.kt +0 -10
  198. package/android/src/amazon/java/com/dooboolab/rniap/PurchasingServiceProxy.kt +0 -29
  199. package/android/src/amazon/java/com/dooboolab/rniap/PurchasingServiceProxyAmazonImpl.kt +0 -31
  200. package/android/src/amazon/java/com/dooboolab/rniap/RNIapActivityListener.kt +0 -55
  201. package/android/src/amazon/java/com/dooboolab/rniap/RNIapAmazonListener.kt +0 -325
  202. package/android/src/amazon/java/com/dooboolab/rniap/RNIapAmazonModule.kt +0 -244
  203. package/android/src/amazon/java/com/dooboolab/rniap/RNIapPackage.kt +0 -17
  204. package/android/src/amazon/java/com/dooboolab/rniap/modifysubscription/RNIapAmazonModifySubscriptionListener.kt +0 -88
  205. package/android/src/amazon/java/com/dooboolab/rniap/utils/Extensions.kt +0 -22
  206. package/android/src/main/java/com/dooboolab/rniap/PromiseUtils.kt +0 -62
  207. package/android/src/main/java/com/dooboolab/rniap/PromiseUtlis.kt +0 -43
  208. package/android/src/play/java/com/dooboolab/rniap/PlayUtils.kt +0 -114
  209. package/android/src/play/java/com/dooboolab/rniap/RNIapActivityListener.kt +0 -15
  210. package/android/src/play/java/com/dooboolab/rniap/RNIapModule.kt +0 -911
  211. package/android/src/play/java/com/dooboolab/rniap/RNIapPackage.kt +0 -17
  212. package/android/src/testAmazon/java/com/dooboolab/rniap/RNIapAmazonModuleTest.kt +0 -170
  213. package/app.plugin.js +0 -1
  214. package/ios/IapSerializationUtils.swift +0 -290
  215. package/ios/IapTypes.swift +0 -56
  216. package/ios/IapUtils.swift +0 -40
  217. package/ios/LatestPromiseKeeper.swift +0 -52
  218. package/ios/RNIapIos-Bridging-Header.h +0 -2
  219. package/ios/RNIapIos.m +0 -69
  220. package/ios/RNIapIos.swift +0 -868
  221. package/ios/RNIapIos.xcodeproj/project.pbxproj +0 -289
  222. package/ios/RNIapIosSk2.m +0 -126
  223. package/ios/RNIapIosSk2.swift +0 -1413
  224. package/ios/ThreadSafe.swift +0 -18
  225. package/lib/commonjs/eventEmitter.js +0 -195
  226. package/lib/commonjs/eventEmitter.js.map +0 -1
  227. package/lib/commonjs/hooks/index.js +0 -17
  228. package/lib/commonjs/hooks/index.js.map +0 -1
  229. package/lib/commonjs/hooks/useIAP.js +0 -203
  230. package/lib/commonjs/hooks/useIAP.js.map +0 -1
  231. package/lib/commonjs/hooks/withIAPContext.js +0 -95
  232. package/lib/commonjs/hooks/withIAPContext.js.map +0 -1
  233. package/lib/commonjs/iap.js +0 -836
  234. package/lib/commonjs/iap.js.map +0 -1
  235. package/lib/commonjs/index.js +0 -105
  236. package/lib/commonjs/index.js.map +0 -1
  237. package/lib/commonjs/internal/enhancedFetch.js +0 -26
  238. package/lib/commonjs/internal/enhancedFetch.js.map +0 -1
  239. package/lib/commonjs/internal/fillProductsWithAdditionalData.js +0 -50
  240. package/lib/commonjs/internal/fillProductsWithAdditionalData.js.map +0 -1
  241. package/lib/commonjs/internal/index.js +0 -39
  242. package/lib/commonjs/internal/index.js.map +0 -1
  243. package/lib/commonjs/internal/platform.js +0 -119
  244. package/lib/commonjs/internal/platform.js.map +0 -1
  245. package/lib/commonjs/modules/amazon.js +0 -50
  246. package/lib/commonjs/modules/amazon.js.map +0 -1
  247. package/lib/commonjs/modules/android.js +0 -92
  248. package/lib/commonjs/modules/android.js.map +0 -1
  249. package/lib/commonjs/modules/common.js +0 -2
  250. package/lib/commonjs/modules/index.js +0 -50
  251. package/lib/commonjs/modules/index.js.map +0 -1
  252. package/lib/commonjs/modules/ios.js +0 -160
  253. package/lib/commonjs/modules/ios.js.map +0 -1
  254. package/lib/commonjs/modules/iosSk2.js +0 -113
  255. package/lib/commonjs/modules/iosSk2.js.map +0 -1
  256. package/lib/commonjs/purchaseError.js +0 -170
  257. package/lib/commonjs/purchaseError.js.map +0 -1
  258. package/lib/commonjs/types/amazon.js +0 -2
  259. package/lib/commonjs/types/amazon.js.map +0 -1
  260. package/lib/commonjs/types/android.js +0 -67
  261. package/lib/commonjs/types/android.js.map +0 -1
  262. package/lib/commonjs/types/apple.js +0 -24
  263. package/lib/commonjs/types/apple.js.map +0 -1
  264. package/lib/commonjs/types/appleSk2.js +0 -137
  265. package/lib/commonjs/types/appleSk2.js.map +0 -1
  266. package/lib/commonjs/types/index.js +0 -67
  267. package/lib/commonjs/types/index.js.map +0 -1
  268. package/lib/commonjs/utils/errorMapping.js +0 -83
  269. package/lib/commonjs/utils/errorMapping.js.map +0 -1
  270. package/lib/commonjs/utils/typeGuards.js +0 -74
  271. package/lib/commonjs/utils/typeGuards.js.map +0 -1
  272. package/lib/module/eventEmitter.js +0 -185
  273. package/lib/module/eventEmitter.js.map +0 -1
  274. package/lib/module/hooks/index.js +0 -2
  275. package/lib/module/hooks/index.js.map +0 -1
  276. package/lib/module/hooks/withIAPContext.js +0 -86
  277. package/lib/module/hooks/withIAPContext.js.map +0 -1
  278. package/lib/module/iap.js +0 -805
  279. package/lib/module/iap.js.map +0 -1
  280. package/lib/module/internal/enhancedFetch.js +0 -19
  281. package/lib/module/internal/enhancedFetch.js.map +0 -1
  282. package/lib/module/internal/fillProductsWithAdditionalData.js +0 -43
  283. package/lib/module/internal/fillProductsWithAdditionalData.js.map +0 -1
  284. package/lib/module/internal/index.js +0 -4
  285. package/lib/module/internal/index.js.map +0 -1
  286. package/lib/module/internal/platform.js +0 -102
  287. package/lib/module/internal/platform.js.map +0 -1
  288. package/lib/module/modules/amazon.js +0 -42
  289. package/lib/module/modules/amazon.js.map +0 -1
  290. package/lib/module/modules/android.js +0 -81
  291. package/lib/module/modules/android.js.map +0 -1
  292. package/lib/module/modules/common.js +0 -2
  293. package/lib/module/modules/common.js.map +0 -1
  294. package/lib/module/modules/index.js +0 -5
  295. package/lib/module/modules/index.js.map +0 -1
  296. package/lib/module/modules/ios.js +0 -145
  297. package/lib/module/modules/ios.js.map +0 -1
  298. package/lib/module/modules/iosSk2.js +0 -96
  299. package/lib/module/modules/iosSk2.js.map +0 -1
  300. package/lib/module/purchaseError.js +0 -164
  301. package/lib/module/purchaseError.js.map +0 -1
  302. package/lib/module/types/amazon.js +0 -2
  303. package/lib/module/types/amazon.js.map +0 -1
  304. package/lib/module/types/android.js +0 -63
  305. package/lib/module/types/android.js.map +0 -1
  306. package/lib/module/types/apple.js +0 -17
  307. package/lib/module/types/apple.js.map +0 -1
  308. package/lib/module/types/appleSk2.js +0 -129
  309. package/lib/module/types/appleSk2.js.map +0 -1
  310. package/lib/module/types/index.js +0 -75
  311. package/lib/module/types/index.js.map +0 -1
  312. package/lib/module/utils/errorMapping.js +0 -75
  313. package/lib/module/utils/errorMapping.js.map +0 -1
  314. package/lib/module/utils/typeGuards.js +0 -61
  315. package/lib/module/utils/typeGuards.js.map +0 -1
  316. package/lib/typescript/src/eventEmitter.d.ts +0 -151
  317. package/lib/typescript/src/eventEmitter.d.ts.map +0 -1
  318. package/lib/typescript/src/hooks/index.d.ts +0 -2
  319. package/lib/typescript/src/hooks/index.d.ts.map +0 -1
  320. package/lib/typescript/src/hooks/withIAPContext.d.ts +0 -27
  321. package/lib/typescript/src/hooks/withIAPContext.d.ts.map +0 -1
  322. package/lib/typescript/src/iap.d.ts +0 -503
  323. package/lib/typescript/src/iap.d.ts.map +0 -1
  324. package/lib/typescript/src/internal/enhancedFetch.d.ts +0 -6
  325. package/lib/typescript/src/internal/enhancedFetch.d.ts.map +0 -1
  326. package/lib/typescript/src/internal/fillProductsWithAdditionalData.d.ts +0 -7
  327. package/lib/typescript/src/internal/fillProductsWithAdditionalData.d.ts.map +0 -1
  328. package/lib/typescript/src/internal/index.d.ts +0 -4
  329. package/lib/typescript/src/internal/index.d.ts.map +0 -1
  330. package/lib/typescript/src/internal/platform.d.ts +0 -27
  331. package/lib/typescript/src/internal/platform.d.ts.map +0 -1
  332. package/lib/typescript/src/modules/amazon.d.ts +0 -55
  333. package/lib/typescript/src/modules/amazon.d.ts.map +0 -1
  334. package/lib/typescript/src/modules/android.d.ts +0 -74
  335. package/lib/typescript/src/modules/android.d.ts.map +0 -1
  336. package/lib/typescript/src/modules/common.d.ts +0 -14
  337. package/lib/typescript/src/modules/common.d.ts.map +0 -1
  338. package/lib/typescript/src/modules/index.d.ts +0 -5
  339. package/lib/typescript/src/modules/index.d.ts.map +0 -1
  340. package/lib/typescript/src/modules/ios.d.ts +0 -117
  341. package/lib/typescript/src/modules/ios.d.ts.map +0 -1
  342. package/lib/typescript/src/modules/iosSk2.d.ts +0 -140
  343. package/lib/typescript/src/modules/iosSk2.d.ts.map +0 -1
  344. package/lib/typescript/src/purchaseError.d.ts +0 -133
  345. package/lib/typescript/src/purchaseError.d.ts.map +0 -1
  346. package/lib/typescript/src/types/amazon.d.ts +0 -33
  347. package/lib/typescript/src/types/amazon.d.ts.map +0 -1
  348. package/lib/typescript/src/types/android.d.ts +0 -66
  349. package/lib/typescript/src/types/android.d.ts.map +0 -1
  350. package/lib/typescript/src/types/apple.d.ts +0 -27
  351. package/lib/typescript/src/types/apple.d.ts.map +0 -1
  352. package/lib/typescript/src/types/appleSk2.d.ts +0 -129
  353. package/lib/typescript/src/types/appleSk2.d.ts.map +0 -1
  354. package/lib/typescript/src/types/index.d.ts +0 -302
  355. package/lib/typescript/src/types/index.d.ts.map +0 -1
  356. package/lib/typescript/src/utils/errorMapping.d.ts +0 -29
  357. package/lib/typescript/src/utils/errorMapping.d.ts.map +0 -1
  358. package/lib/typescript/src/utils/typeGuards.d.ts +0 -53
  359. package/lib/typescript/src/utils/typeGuards.d.ts.map +0 -1
  360. package/src/eventEmitter.ts +0 -212
  361. package/src/hooks/index.ts +0 -1
  362. package/src/hooks/withIAPContext.tsx +0 -179
  363. package/src/iap.ts +0 -1046
  364. package/src/internal/enhancedFetch.ts +0 -25
  365. package/src/internal/fillProductsWithAdditionalData.ts +0 -47
  366. package/src/internal/index.ts +0 -3
  367. package/src/internal/platform.ts +0 -135
  368. package/src/modules/amazon.ts +0 -94
  369. package/src/modules/android.ts +0 -179
  370. package/src/modules/common.ts +0 -16
  371. package/src/modules/index.ts +0 -4
  372. package/src/modules/ios.ts +0 -229
  373. package/src/modules/iosSk2.ts +0 -194
  374. package/src/purchaseError.ts +0 -196
  375. package/src/types/amazon.ts +0 -40
  376. package/src/types/android.ts +0 -89
  377. package/src/types/apple.ts +0 -44
  378. package/src/types/appleSk2.ts +0 -275
  379. package/src/types/index.ts +0 -379
  380. package/src/utils/errorMapping.ts +0 -88
  381. package/src/utils/typeGuards.ts +0 -90
@@ -1,10 +1,1016 @@
1
- export * from './iap';
2
- export * from './types';
3
- export * from './eventEmitter';
4
- export * from './hooks/useIAP';
5
- export * from './hooks/withIAPContext';
6
- export * from './purchaseError';
7
- export * from './modules';
8
- export * from './utils/errorMapping';
9
- export * from './utils/typeGuards';
1
+ "use strict";
2
+
3
+ // External dependencies
4
+ import { Platform } from 'react-native';
5
+ import { NitroModules } from 'react-native-nitro-modules';
6
+
7
+ // Internal modules
8
+
9
+ import { convertNitroProductToProduct, convertNitroPurchaseToPurchase, validateNitroProduct, validateNitroPurchase } from "./utils/type-bridge.js";
10
+ import { parseErrorStringToJsonObj } from "./utils/error.js";
11
+
12
+ // Export all types
13
+
14
+ export * from "./types.js";
15
+ export * from "./utils/error.js";
16
+
17
+ // Types for event listeners
18
+
19
+ // ActiveSubscription and PurchaseError types are already exported via 'export * from ./types'
20
+
21
+ // Export hooks
22
+ export { useIAP } from "./hooks/useIAP.js";
23
+
24
+ // Development utilities removed - use type bridge functions directly if needed
25
+
26
+ // Create the RnIap HybridObject instance (internal use only)
27
+ const iap = NitroModules.createHybridObject('RnIap');
28
+
29
+ /**
30
+ * Initialize connection to the store
31
+ */
32
+ export const initConnection = async () => {
33
+ try {
34
+ return await iap.initConnection();
35
+ } catch (error) {
36
+ console.error('Failed to initialize IAP connection:', error);
37
+ throw error;
38
+ }
39
+ };
40
+
41
+ /**
42
+ * End connection to the store
43
+ */
44
+ export const endConnection = async () => {
45
+ try {
46
+ return await iap.endConnection();
47
+ } catch (error) {
48
+ console.error('Failed to end IAP connection:', error);
49
+ throw error;
50
+ }
51
+ };
52
+
53
+ /**
54
+ * Fetch products from the store
55
+ * @param params - Product request configuration
56
+ * @param params.skus - Array of product SKUs to fetch
57
+ * @param params.type - Type of products: 'inapp' for regular products (default) or 'subs' for subscriptions
58
+ * @returns Promise<Product[]> - Array of products from the store
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * // Regular products
63
+ * const products = await fetchProducts({
64
+ * skus: ['product1', 'product2'],
65
+ * type: 'inapp'
66
+ * });
67
+ *
68
+ * // Subscriptions
69
+ * const subscriptions = await fetchProducts({
70
+ * skus: ['sub1', 'sub2'],
71
+ * type: 'subs'
72
+ * });
73
+ * ```
74
+ */
75
+ export const fetchProducts = async ({
76
+ skus,
77
+ type = 'inapp'
78
+ }) => {
79
+ try {
80
+ if (!skus || skus.length === 0) {
81
+ throw new Error('No SKUs provided');
82
+ }
83
+ const nitroProducts = await iap.fetchProducts(skus, type);
84
+
85
+ // Validate and convert NitroProducts to TypeScript Products
86
+ const validProducts = nitroProducts.filter(validateNitroProduct);
87
+ if (validProducts.length !== nitroProducts.length) {
88
+ console.warn(`[fetchProducts] Some products failed validation: ${nitroProducts.length - validProducts.length} invalid`);
89
+ }
90
+ const typedProducts = validProducts.map(convertNitroProductToProduct);
91
+ return typedProducts;
92
+ } catch (error) {
93
+ console.error('[fetchProducts] Failed:', error);
94
+ throw error;
95
+ }
96
+ };
97
+
98
+ /**
99
+ * Request a purchase for products or subscriptions
100
+ * @param params - Purchase request configuration
101
+ * @param params.request - Platform-specific purchase parameters
102
+ * @param params.type - Type of purchase: 'inapp' for products (default) or 'subs' for subscriptions
103
+ *
104
+ * @example
105
+ * ```typescript
106
+ * // Product purchase
107
+ * await requestPurchase({
108
+ * request: {
109
+ * ios: { sku: productId },
110
+ * android: { skus: [productId] }
111
+ * },
112
+ * type: 'inapp'
113
+ * });
114
+ *
115
+ * // Subscription purchase
116
+ * await requestPurchase({
117
+ * request: {
118
+ * ios: { sku: subscriptionId },
119
+ * android: {
120
+ * skus: [subscriptionId],
121
+ * subscriptionOffers: [{ sku: subscriptionId, offerToken: 'token' }]
122
+ * }
123
+ * },
124
+ * type: 'subs'
125
+ * });
126
+ * ```
127
+ */
128
+ /**
129
+ * Request a purchase for products or subscriptions
130
+ * ⚠️ Important: This is an event-based operation, not promise-based.
131
+ * Listen for events through purchaseUpdatedListener or purchaseErrorListener.
132
+ * @param params - Purchase request configuration
133
+ * @param params.request - Platform-specific purchase parameters
134
+ * @param params.type - Type of purchase: 'inapp' for products (default) or 'subs' for subscriptions
135
+ */
136
+ export const requestPurchase = async ({
137
+ request,
138
+ type = 'inapp'
139
+ }) => {
140
+ try {
141
+ // Validate platform-specific requests
142
+ if (Platform.OS === 'ios') {
143
+ const iosRequest = request.ios;
144
+ if (!iosRequest?.sku) {
145
+ throw new Error('Invalid request for iOS. The `sku` property is required.');
146
+ }
147
+ } else if (Platform.OS === 'android') {
148
+ const androidRequest = request.android;
149
+ if (!androidRequest?.skus?.length) {
150
+ throw new Error('Invalid request for Android. The `skus` property is required and must be a non-empty array.');
151
+ }
152
+ } else {
153
+ throw new Error('Unsupported platform');
154
+ }
155
+
156
+ // Transform the request for the unified interface
157
+ const unifiedRequest = {};
158
+ if (Platform.OS === 'ios' && request.ios) {
159
+ unifiedRequest.ios = {
160
+ ...request.ios
161
+ };
162
+ }
163
+ if (Platform.OS === 'android' && request.android) {
164
+ if (type === 'subs') {
165
+ const subsRequest = request.android;
166
+ unifiedRequest.android = {
167
+ ...subsRequest,
168
+ subscriptionOffers: subsRequest.subscriptionOffers || []
169
+ };
170
+ } else {
171
+ unifiedRequest.android = request.android;
172
+ }
173
+ }
174
+
175
+ // Call unified method - returns void, listen for events instead
176
+ await iap.requestPurchase(unifiedRequest);
177
+ } catch (error) {
178
+ console.error('Failed to request purchase:', error);
179
+ throw error;
180
+ }
181
+ };
182
+
183
+ /**
184
+ * Get available purchases (purchased items not yet consumed/finished)
185
+ * @param params - Options for getting available purchases
186
+ * @param params.alsoPublishToEventListenerIOS - Whether to also publish to event listener (iOS only)
187
+ * @param params.onlyIncludeActiveItemsIOS - Whether to only include active items (iOS only)
188
+ * @param params.alsoPublishToEventListener - @deprecated Use alsoPublishToEventListenerIOS instead
189
+ * @param params.onlyIncludeActiveItems - @deprecated Use onlyIncludeActiveItemsIOS instead
190
+ *
191
+ * @example
192
+ * ```typescript
193
+ * const purchases = await getAvailablePurchases({
194
+ * onlyIncludeActiveItemsIOS: true
195
+ * });
196
+ * ```
197
+ */
198
+ export const getAvailablePurchases = async ({
199
+ alsoPublishToEventListener = false,
200
+ onlyIncludeActiveItems = true,
201
+ alsoPublishToEventListenerIOS,
202
+ onlyIncludeActiveItemsIOS
203
+ } = {}) => {
204
+ try {
205
+ // Create unified options
206
+ const options = {};
207
+ if (Platform.OS === 'ios') {
208
+ // Use new IOS suffixed parameters if provided, fallback to deprecated ones
209
+ options.ios = {
210
+ alsoPublishToEventListenerIOS: alsoPublishToEventListenerIOS ?? alsoPublishToEventListener,
211
+ onlyIncludeActiveItemsIOS: onlyIncludeActiveItemsIOS ?? onlyIncludeActiveItems,
212
+ // Keep deprecated parameters for backward compatibility
213
+ alsoPublishToEventListener: alsoPublishToEventListenerIOS ?? alsoPublishToEventListener,
214
+ onlyIncludeActiveItems: onlyIncludeActiveItemsIOS ?? onlyIncludeActiveItems
215
+ };
216
+ } else if (Platform.OS === 'android') {
217
+ // For Android, we need to call twice for inapp and subs
218
+ const inappNitroPurchases = await iap.getAvailablePurchases({
219
+ android: {
220
+ type: 'inapp'
221
+ }
222
+ });
223
+ const subsNitroPurchases = await iap.getAvailablePurchases({
224
+ android: {
225
+ type: 'subs'
226
+ }
227
+ });
228
+
229
+ // Validate and convert both sets of purchases
230
+ const allNitroPurchases = [...inappNitroPurchases, ...subsNitroPurchases];
231
+ const validPurchases = allNitroPurchases.filter(validateNitroPurchase);
232
+ if (validPurchases.length !== allNitroPurchases.length) {
233
+ console.warn(`[getAvailablePurchases] Some Android purchases failed validation: ${allNitroPurchases.length - validPurchases.length} invalid`);
234
+ }
235
+ return validPurchases.map(convertNitroPurchaseToPurchase);
236
+ } else {
237
+ throw new Error('Unsupported platform');
238
+ }
239
+ const nitroPurchases = await iap.getAvailablePurchases(options);
240
+
241
+ // Validate and convert NitroPurchases to TypeScript Purchases
242
+ const validPurchases = nitroPurchases.filter(validateNitroPurchase);
243
+ if (validPurchases.length !== nitroPurchases.length) {
244
+ console.warn(`[getAvailablePurchases] Some purchases failed validation: ${nitroPurchases.length - validPurchases.length} invalid`);
245
+ }
246
+ return validPurchases.map(convertNitroPurchaseToPurchase);
247
+ } catch (error) {
248
+ console.error('Failed to get available purchases:', error);
249
+ throw error;
250
+ }
251
+ };
252
+
253
+ /**
254
+ * Finish a transaction (consume or acknowledge)
255
+ * @param params - Transaction finish parameters
256
+ * @param params.purchase - The purchase to finish
257
+ * @param params.isConsumable - Whether this is a consumable product (Android only)
258
+ *
259
+ * @example
260
+ * ```typescript
261
+ * await finishTransaction({
262
+ * purchase: myPurchase,
263
+ * isConsumable: true
264
+ * });
265
+ * ```
266
+ */
267
+ export const finishTransaction = async ({
268
+ purchase,
269
+ isConsumable = false
270
+ }) => {
271
+ try {
272
+ // Create unified params
273
+ const params = {};
274
+ if (Platform.OS === 'ios') {
275
+ if (!purchase.id) {
276
+ throw new Error('purchase.id required to finish iOS transaction');
277
+ }
278
+ params.ios = {
279
+ transactionId: purchase.id
280
+ };
281
+ } else if (Platform.OS === 'android') {
282
+ const androidPurchase = purchase;
283
+ const token = androidPurchase.purchaseToken || androidPurchase.purchaseTokenAndroid;
284
+ if (!token) {
285
+ throw new Error('purchaseToken required to finish Android transaction');
286
+ }
287
+ params.android = {
288
+ purchaseToken: token,
289
+ isConsumable
290
+ };
291
+ } else {
292
+ throw new Error('Unsupported platform');
293
+ }
294
+ const result = await iap.finishTransaction(params);
295
+
296
+ // Handle variant return type
297
+ if (typeof result === 'boolean') {
298
+ return result;
299
+ }
300
+ // It's a PurchaseResult
301
+ return result;
302
+ } catch (error) {
303
+ console.error('Failed to finish transaction:', error);
304
+ throw error;
305
+ }
306
+ };
307
+
308
+ /**
309
+ * Acknowledge a purchase (Android only)
310
+ * @param purchaseToken - The purchase token to acknowledge
311
+ *
312
+ * @example
313
+ * ```typescript
314
+ * await acknowledgePurchaseAndroid('purchase_token_here');
315
+ * ```
316
+ */
317
+ export const acknowledgePurchaseAndroid = async purchaseToken => {
318
+ try {
319
+ if (Platform.OS !== 'android') {
320
+ throw new Error('acknowledgePurchaseAndroid is only available on Android');
321
+ }
322
+ const result = await iap.finishTransaction({
323
+ android: {
324
+ purchaseToken,
325
+ isConsumable: false
326
+ }
327
+ });
328
+
329
+ // Result is a variant, extract PurchaseResult
330
+ if (typeof result === 'boolean') {
331
+ // This shouldn't happen for Android, but handle it
332
+ return {
333
+ responseCode: 0,
334
+ code: '0',
335
+ message: 'Success',
336
+ purchaseToken
337
+ };
338
+ }
339
+ return result;
340
+ } catch (error) {
341
+ console.error('Failed to acknowledge purchase Android:', error);
342
+ throw error;
343
+ }
344
+ };
345
+
346
+ /**
347
+ * Consume a purchase (Android only)
348
+ * @param purchaseToken - The purchase token to consume
349
+ *
350
+ * @example
351
+ * ```typescript
352
+ * await consumePurchaseAndroid('purchase_token_here');
353
+ * ```
354
+ */
355
+ export const consumePurchaseAndroid = async purchaseToken => {
356
+ try {
357
+ if (Platform.OS !== 'android') {
358
+ throw new Error('consumePurchaseAndroid is only available on Android');
359
+ }
360
+ const result = await iap.finishTransaction({
361
+ android: {
362
+ purchaseToken,
363
+ isConsumable: true
364
+ }
365
+ });
366
+
367
+ // Result is a variant, extract PurchaseResult
368
+ if (typeof result === 'boolean') {
369
+ // This shouldn't happen for Android, but handle it
370
+ return {
371
+ responseCode: 0,
372
+ code: '0',
373
+ message: 'Success',
374
+ purchaseToken
375
+ };
376
+ }
377
+ return result;
378
+ } catch (error) {
379
+ console.error('Failed to consume purchase Android:', error);
380
+ throw error;
381
+ }
382
+ };
383
+
384
+ // ============================================================================
385
+ // EVENT LISTENERS
386
+ // ============================================================================
387
+
388
+ // Store wrapped listeners for proper removal
389
+ const listenerMap = new WeakMap();
390
+
391
+ /**
392
+ * Purchase updated event listener
393
+ * Fired when a purchase is successful or when a pending purchase is completed.
394
+ *
395
+ * @param listener - Function to call when a purchase is updated
396
+ * @returns EventSubscription object with remove method
397
+ *
398
+ * @example
399
+ * ```typescript
400
+ * const subscription = purchaseUpdatedListener((purchase) => {
401
+ * console.log('Purchase successful:', purchase);
402
+ * // 1. Validate receipt with backend
403
+ * // 2. Deliver content to user
404
+ * // 3. Call finishTransaction to acknowledge
405
+ * });
406
+ *
407
+ * // Later, clean up
408
+ * subscription.remove();
409
+ * ```
410
+ */
411
+ export const purchaseUpdatedListener = listener => {
412
+ // Wrap the listener to convert NitroPurchase to Purchase
413
+ const wrappedListener = nitroPurchase => {
414
+ if (validateNitroPurchase(nitroPurchase)) {
415
+ const convertedPurchase = convertNitroPurchaseToPurchase(nitroPurchase);
416
+ listener(convertedPurchase);
417
+ } else {
418
+ console.error('Invalid purchase data received from native:', nitroPurchase);
419
+ }
420
+ };
421
+
422
+ // Store the wrapped listener for removal
423
+ listenerMap.set(listener, wrappedListener);
424
+ iap.addPurchaseUpdatedListener(wrappedListener);
425
+ return {
426
+ remove: () => {
427
+ const wrapped = listenerMap.get(listener);
428
+ if (wrapped) {
429
+ iap.removePurchaseUpdatedListener(wrapped);
430
+ listenerMap.delete(listener);
431
+ }
432
+ }
433
+ };
434
+ };
435
+
436
+ /**
437
+ * Purchase error event listener
438
+ * Fired when a purchase fails or is cancelled by the user.
439
+ *
440
+ * @param listener - Function to call when a purchase error occurs
441
+ * @returns EventSubscription object with remove method
442
+ *
443
+ * @example
444
+ * ```typescript
445
+ * const subscription = purchaseErrorListener((error) => {
446
+ * switch (error.code) {
447
+ * case 'E_USER_CANCELLED':
448
+ * // User cancelled - no action needed
449
+ * break;
450
+ * case 'E_ITEM_UNAVAILABLE':
451
+ * // Product not available
452
+ * break;
453
+ * case 'E_NETWORK_ERROR':
454
+ * // Retry with backoff
455
+ * break;
456
+ * }
457
+ * });
458
+ *
459
+ * // Later, clean up
460
+ * subscription.remove();
461
+ * ```
462
+ */
463
+ export const purchaseErrorListener = listener => {
464
+ // Store the listener for removal
465
+ listenerMap.set(listener, listener);
466
+ iap.addPurchaseErrorListener(listener);
467
+ return {
468
+ remove: () => {
469
+ iap.removePurchaseErrorListener(listener);
470
+ listenerMap.delete(listener);
471
+ }
472
+ };
473
+ };
474
+
475
+ /**
476
+ * iOS-only listener for App Store promoted product events.
477
+ * Fired when a user clicks on a promoted in-app purchase in the App Store.
478
+ *
479
+ * @param listener - Callback function that receives the promoted product
480
+ * @returns EventSubscription object with remove method
481
+ *
482
+ * @example
483
+ * ```typescript
484
+ * const subscription = promotedProductListenerIOS((product) => {
485
+ * console.log('Promoted product:', product);
486
+ * // Trigger purchase flow for the promoted product
487
+ * });
488
+ *
489
+ * // Later, clean up
490
+ * subscription.remove();
491
+ * ```
492
+ *
493
+ * @platform iOS
494
+ */
495
+ export const promotedProductListenerIOS = listener => {
496
+ if (Platform.OS !== 'ios') {
497
+ console.warn('promotedProductListenerIOS: This listener is only available on iOS');
498
+ return {
499
+ remove: () => {}
500
+ };
501
+ }
502
+
503
+ // Wrap the listener to convert NitroProduct to Product
504
+ const wrappedListener = nitroProduct => {
505
+ if (validateNitroProduct(nitroProduct)) {
506
+ const convertedProduct = convertNitroProductToProduct(nitroProduct);
507
+ listener(convertedProduct);
508
+ } else {
509
+ console.error('Invalid promoted product data received from native:', nitroProduct);
510
+ }
511
+ };
512
+
513
+ // Store the wrapped listener for removal
514
+ listenerMap.set(listener, wrappedListener);
515
+ iap.addPromotedProductListenerIOS(wrappedListener);
516
+ return {
517
+ remove: () => {
518
+ const wrapped = listenerMap.get(listener);
519
+ if (wrapped) {
520
+ iap.removePromotedProductListenerIOS(wrapped);
521
+ listenerMap.delete(listener);
522
+ }
523
+ }
524
+ };
525
+ };
526
+
527
+ // ============================================================================
528
+ // iOS-SPECIFIC FUNCTIONS
529
+ // ============================================================================
530
+
531
+ /**
532
+ * Validate receipt on both iOS and Android platforms
533
+ * @param sku - Product SKU
534
+ * @param androidOptions - Android-specific validation options (required for Android)
535
+ * @returns Promise<ReceiptValidationResultIOS | ReceiptValidationResultAndroid> - Platform-specific receipt validation result
536
+ */
537
+ export const validateReceipt = async (sku, androidOptions) => {
538
+ if (!iap) {
539
+ const errorJson = parseErrorStringToJsonObj('RnIap: Service not initialized. Call initConnection() first.');
540
+ throw new Error(errorJson.message);
541
+ }
542
+ try {
543
+ const params = {
544
+ sku,
545
+ androidOptions
546
+ };
547
+ const nitroResult = await iap.validateReceipt(params);
548
+
549
+ // Convert Nitro result to public API result
550
+ if (Platform.OS === 'ios') {
551
+ const iosResult = nitroResult;
552
+ const result = {
553
+ isValid: iosResult.isValid,
554
+ receiptData: iosResult.receiptData,
555
+ jwsRepresentation: iosResult.jwsRepresentation,
556
+ latestTransaction: iosResult.latestTransaction ? convertNitroPurchaseToPurchase(iosResult.latestTransaction) : undefined
557
+ };
558
+ return result;
559
+ } else {
560
+ // Android
561
+ const androidResult = nitroResult;
562
+ const result = {
563
+ autoRenewing: androidResult.autoRenewing,
564
+ betaProduct: androidResult.betaProduct,
565
+ cancelDate: androidResult.cancelDate,
566
+ cancelReason: androidResult.cancelReason,
567
+ deferredDate: androidResult.deferredDate,
568
+ deferredSku: androidResult.deferredSku,
569
+ freeTrialEndDate: androidResult.freeTrialEndDate,
570
+ gracePeriodEndDate: androidResult.gracePeriodEndDate,
571
+ parentProductId: androidResult.parentProductId,
572
+ productId: androidResult.productId,
573
+ productType: androidResult.productType,
574
+ purchaseDate: androidResult.purchaseDate,
575
+ quantity: androidResult.quantity,
576
+ receiptId: androidResult.receiptId,
577
+ renewalDate: androidResult.renewalDate,
578
+ term: androidResult.term,
579
+ termSku: androidResult.termSku,
580
+ testTransaction: androidResult.testTransaction
581
+ };
582
+ return result;
583
+ }
584
+ } catch (error) {
585
+ console.error('[validateReceipt] Failed:', error);
586
+ const errorJson = parseErrorStringToJsonObj(error);
587
+ throw new Error(errorJson.message);
588
+ }
589
+ };
590
+
591
+ /**
592
+ * Sync iOS purchases with App Store (iOS only)
593
+ * @returns Promise<boolean>
594
+ * @platform iOS
595
+ */
596
+ export const syncIOS = async () => {
597
+ if (Platform.OS !== 'ios') {
598
+ throw new Error('syncIOS is only available on iOS');
599
+ }
600
+ if (!iap) {
601
+ const errorJson = parseErrorStringToJsonObj('RnIap: Service not initialized. Call initConnection() first.');
602
+ throw new Error(errorJson.message);
603
+ }
604
+ try {
605
+ return await iap.syncIOS();
606
+ } catch (error) {
607
+ console.error('[syncIOS] Failed:', error);
608
+ const errorJson = parseErrorStringToJsonObj(error);
609
+ throw new Error(errorJson.message);
610
+ }
611
+ };
612
+
613
+ /**
614
+ * Request the promoted product from the App Store (iOS only)
615
+ * @returns Promise<Product | null> - The promoted product or null if none available
616
+ * @platform iOS
617
+ */
618
+ export const requestPromotedProductIOS = async () => {
619
+ if (Platform.OS !== 'ios') {
620
+ return null;
621
+ }
622
+ if (!iap) {
623
+ const errorJson = parseErrorStringToJsonObj('RnIap: Service not initialized. Call initConnection() first.');
624
+ throw new Error(errorJson.message);
625
+ }
626
+ try {
627
+ const nitroProduct = await iap.requestPromotedProductIOS();
628
+ if (nitroProduct) {
629
+ return convertNitroProductToProduct(nitroProduct);
630
+ }
631
+ return null;
632
+ } catch (error) {
633
+ console.error('[getPromotedProductIOS] Failed:', error);
634
+ const errorJson = parseErrorStringToJsonObj(error);
635
+ throw new Error(errorJson.message);
636
+ }
637
+ };
638
+
639
+ /**
640
+ * Present the code redemption sheet for offer codes (iOS only)
641
+ * @returns Promise<boolean> - True if the sheet was presented successfully
642
+ * @platform iOS
643
+ */
644
+ export const presentCodeRedemptionSheetIOS = async () => {
645
+ if (Platform.OS !== 'ios') {
646
+ return false;
647
+ }
648
+ if (!iap) {
649
+ const errorJson = parseErrorStringToJsonObj('RnIap: Service not initialized. Call initConnection() first.');
650
+ throw new Error(errorJson.message);
651
+ }
652
+ try {
653
+ return await iap.presentCodeRedemptionSheetIOS();
654
+ } catch (error) {
655
+ console.error('[presentCodeRedemptionSheetIOS] Failed:', error);
656
+ const errorJson = parseErrorStringToJsonObj(error);
657
+ throw new Error(errorJson.message);
658
+ }
659
+ };
660
+
661
+ /**
662
+ * Buy promoted product on iOS
663
+ * @returns Promise<void>
664
+ * @platform iOS
665
+ */
666
+ export const buyPromotedProductIOS = async () => {
667
+ if (Platform.OS !== 'ios') {
668
+ throw new Error('buyPromotedProductIOS is only available on iOS');
669
+ }
670
+ if (!iap) {
671
+ const errorJson = parseErrorStringToJsonObj('RnIap: Service not initialized. Call initConnection() first.');
672
+ throw new Error(errorJson.message);
673
+ }
674
+ try {
675
+ await iap.buyPromotedProductIOS();
676
+ } catch (error) {
677
+ console.error('[buyPromotedProductIOS] Failed:', error);
678
+ const errorJson = parseErrorStringToJsonObj(error);
679
+ throw new Error(errorJson.message);
680
+ }
681
+ };
682
+
683
+ /**
684
+ * Clear unfinished transactions on iOS
685
+ * @returns Promise<void>
686
+ * @platform iOS
687
+ */
688
+ export const clearTransactionIOS = async () => {
689
+ if (Platform.OS !== 'ios') {
690
+ return;
691
+ }
692
+ if (!iap) {
693
+ const errorJson = parseErrorStringToJsonObj('RnIap: Service not initialized. Call initConnection() first.');
694
+ throw new Error(errorJson.message);
695
+ }
696
+ try {
697
+ await iap.clearTransactionIOS();
698
+ } catch (error) {
699
+ console.error('[clearTransactionIOS] Failed:', error);
700
+ const errorJson = parseErrorStringToJsonObj(error);
701
+ throw new Error(errorJson.message);
702
+ }
703
+ };
704
+
705
+ /**
706
+ * Begin a refund request for a product on iOS 15+
707
+ * @param sku - The product SKU to refund
708
+ * @returns Promise<string | null> - The refund status or null if not available
709
+ * @platform iOS
710
+ */
711
+ export const beginRefundRequestIOS = async sku => {
712
+ if (Platform.OS !== 'ios') {
713
+ return null;
714
+ }
715
+ if (!iap) {
716
+ const errorJson = parseErrorStringToJsonObj('RnIap: Service not initialized. Call initConnection() first.');
717
+ throw new Error(errorJson.message);
718
+ }
719
+ try {
720
+ return await iap.beginRefundRequestIOS(sku);
721
+ } catch (error) {
722
+ console.error('[beginRefundRequestIOS] Failed:', error);
723
+ const errorJson = parseErrorStringToJsonObj(error);
724
+ throw new Error(errorJson.message);
725
+ }
726
+ };
727
+
728
+ /**
729
+ * Get subscription status for a product (iOS only)
730
+ * @param sku - The product SKU
731
+ * @returns Promise<any[]> - Array of subscription status objects
732
+ * @platform iOS
733
+ */
734
+ export const subscriptionStatusIOS = async sku => {
735
+ if (Platform.OS !== 'ios') {
736
+ throw new Error('subscriptionStatusIOS is only available on iOS');
737
+ }
738
+ if (!iap) {
739
+ const errorJson = parseErrorStringToJsonObj('RnIap: Service not initialized. Call initConnection() first.');
740
+ throw new Error(errorJson.message);
741
+ }
742
+ try {
743
+ const statuses = await iap.subscriptionStatusIOS(sku);
744
+ return statuses || [];
745
+ } catch (error) {
746
+ console.error('[subscriptionStatusIOS] Failed:', error);
747
+ const errorJson = parseErrorStringToJsonObj(error);
748
+ throw new Error(errorJson.message);
749
+ }
750
+ };
751
+
752
+ /**
753
+ * Get current entitlement for a product (iOS only)
754
+ * @param sku - The product SKU
755
+ * @returns Promise<Purchase | null> - Current entitlement or null
756
+ * @platform iOS
757
+ */
758
+ export const currentEntitlementIOS = async sku => {
759
+ if (Platform.OS !== 'ios') {
760
+ return null;
761
+ }
762
+ if (!iap) {
763
+ const errorJson = parseErrorStringToJsonObj('RnIap: Service not initialized. Call initConnection() first.');
764
+ throw new Error(errorJson.message);
765
+ }
766
+ try {
767
+ const nitroPurchase = await iap.currentEntitlementIOS(sku);
768
+ if (nitroPurchase) {
769
+ return convertNitroPurchaseToPurchase(nitroPurchase);
770
+ }
771
+ return null;
772
+ } catch (error) {
773
+ console.error('[currentEntitlementIOS] Failed:', error);
774
+ const errorJson = parseErrorStringToJsonObj(error);
775
+ throw new Error(errorJson.message);
776
+ }
777
+ };
778
+
779
+ /**
780
+ * Get latest transaction for a product (iOS only)
781
+ * @param sku - The product SKU
782
+ * @returns Promise<Purchase | null> - Latest transaction or null
783
+ * @platform iOS
784
+ */
785
+ export const latestTransactionIOS = async sku => {
786
+ if (Platform.OS !== 'ios') {
787
+ return null;
788
+ }
789
+ if (!iap) {
790
+ const errorJson = parseErrorStringToJsonObj('RnIap: Service not initialized. Call initConnection() first.');
791
+ throw new Error(errorJson.message);
792
+ }
793
+ try {
794
+ const nitroPurchase = await iap.latestTransactionIOS(sku);
795
+ if (nitroPurchase) {
796
+ return convertNitroPurchaseToPurchase(nitroPurchase);
797
+ }
798
+ return null;
799
+ } catch (error) {
800
+ console.error('[latestTransactionIOS] Failed:', error);
801
+ const errorJson = parseErrorStringToJsonObj(error);
802
+ throw new Error(errorJson.message);
803
+ }
804
+ };
805
+
806
+ /**
807
+ * Get pending transactions (iOS only)
808
+ * @returns Promise<Purchase[]> - Array of pending transactions
809
+ * @platform iOS
810
+ */
811
+ export const getPendingTransactionsIOS = async () => {
812
+ if (Platform.OS !== 'ios') {
813
+ return [];
814
+ }
815
+ if (!iap) {
816
+ const errorJson = parseErrorStringToJsonObj('RnIap: Service not initialized. Call initConnection() first.');
817
+ throw new Error(errorJson.message);
818
+ }
819
+ try {
820
+ const nitroPurchases = await iap.getPendingTransactionsIOS();
821
+ return nitroPurchases.map(convertNitroPurchaseToPurchase);
822
+ } catch (error) {
823
+ console.error('[getPendingTransactionsIOS] Failed:', error);
824
+ const errorJson = parseErrorStringToJsonObj(error);
825
+ throw new Error(errorJson.message);
826
+ }
827
+ };
828
+
829
+ /**
830
+ * Show manage subscriptions screen (iOS only)
831
+ * @returns Promise<boolean> - Success flag
832
+ * @platform iOS
833
+ */
834
+ export const showManageSubscriptionsIOS = async () => {
835
+ if (Platform.OS !== 'ios') {
836
+ return false;
837
+ }
838
+ if (!iap) {
839
+ const errorJson = parseErrorStringToJsonObj('RnIap: Service not initialized. Call initConnection() first.');
840
+ throw new Error(errorJson.message);
841
+ }
842
+ try {
843
+ return await iap.showManageSubscriptionsIOS();
844
+ } catch (error) {
845
+ console.error('[showManageSubscriptionsIOS] Failed:', error);
846
+ const errorJson = parseErrorStringToJsonObj(error);
847
+ throw new Error(errorJson.message);
848
+ }
849
+ };
850
+
851
+ /**
852
+ * Check if user is eligible for intro offer (iOS only)
853
+ * @param groupID - The subscription group ID
854
+ * @returns Promise<boolean> - Eligibility status
855
+ * @platform iOS
856
+ */
857
+ export const isEligibleForIntroOfferIOS = async groupID => {
858
+ if (Platform.OS !== 'ios') {
859
+ return false;
860
+ }
861
+ if (!iap) {
862
+ const errorJson = parseErrorStringToJsonObj('RnIap: Service not initialized. Call initConnection() first.');
863
+ throw new Error(errorJson.message);
864
+ }
865
+ try {
866
+ return await iap.isEligibleForIntroOfferIOS(groupID);
867
+ } catch (error) {
868
+ console.error('[isEligibleForIntroOfferIOS] Failed:', error);
869
+ const errorJson = parseErrorStringToJsonObj(error);
870
+ throw new Error(errorJson.message);
871
+ }
872
+ };
873
+
874
+ /**
875
+ * Get receipt data (iOS only)
876
+ * @returns Promise<string> - Base64 encoded receipt data
877
+ * @platform iOS
878
+ */
879
+ export const getReceiptDataIOS = async () => {
880
+ if (Platform.OS !== 'ios') {
881
+ throw new Error('getReceiptDataIOS is only available on iOS');
882
+ }
883
+ if (!iap) {
884
+ const errorJson = parseErrorStringToJsonObj('RnIap: Service not initialized. Call initConnection() first.');
885
+ throw new Error(errorJson.message);
886
+ }
887
+ try {
888
+ return await iap.getReceiptDataIOS();
889
+ } catch (error) {
890
+ console.error('[getReceiptDataIOS] Failed:', error);
891
+ const errorJson = parseErrorStringToJsonObj(error);
892
+ throw new Error(errorJson.message);
893
+ }
894
+ };
895
+
896
+ /**
897
+ * Check if transaction is verified (iOS only)
898
+ * @param sku - The product SKU
899
+ * @returns Promise<boolean> - Verification status
900
+ * @platform iOS
901
+ */
902
+ export const isTransactionVerifiedIOS = async sku => {
903
+ if (Platform.OS !== 'ios') {
904
+ return false;
905
+ }
906
+ if (!iap) {
907
+ const errorJson = parseErrorStringToJsonObj('RnIap: Service not initialized. Call initConnection() first.');
908
+ throw new Error(errorJson.message);
909
+ }
910
+ try {
911
+ return await iap.isTransactionVerifiedIOS(sku);
912
+ } catch (error) {
913
+ console.error('[isTransactionVerifiedIOS] Failed:', error);
914
+ const errorJson = parseErrorStringToJsonObj(error);
915
+ throw new Error(errorJson.message);
916
+ }
917
+ };
918
+
919
+ /**
920
+ * Get transaction JWS representation (iOS only)
921
+ * @param sku - The product SKU
922
+ * @returns Promise<string | null> - JWS representation or null
923
+ * @platform iOS
924
+ */
925
+ export const getTransactionJwsIOS = async sku => {
926
+ if (Platform.OS !== 'ios') {
927
+ return null;
928
+ }
929
+ if (!iap) {
930
+ const errorJson = parseErrorStringToJsonObj('RnIap: Service not initialized. Call initConnection() first.');
931
+ throw new Error(errorJson.message);
932
+ }
933
+ try {
934
+ return await iap.getTransactionJwsIOS(sku);
935
+ } catch (error) {
936
+ console.error('[getTransactionJwsIOS] Failed:', error);
937
+ const errorJson = parseErrorStringToJsonObj(error);
938
+ throw new Error(errorJson.message);
939
+ }
940
+ };
941
+
942
+ /**
943
+ * Get the storefront identifier for the user's App Store account (iOS only)
944
+ * @returns Promise<string> - The storefront identifier (e.g., 'USA' for United States)
945
+ * @platform iOS
946
+ *
947
+ * @example
948
+ * ```typescript
949
+ * const storefront = await getStorefrontIOS();
950
+ * console.log('User storefront:', storefront); // e.g., 'USA', 'GBR', 'KOR'
951
+ * ```
952
+ */
953
+ export const getStorefrontIOS = async () => {
954
+ if (Platform.OS !== 'ios') {
955
+ throw new Error('getStorefrontIOS is only available on iOS');
956
+ }
957
+ try {
958
+ // Call the native method to get storefront
959
+ const storefront = await iap.getStorefrontIOS();
960
+ return storefront;
961
+ } catch (error) {
962
+ console.error('Failed to get storefront:', error);
963
+ throw error;
964
+ }
965
+ };
966
+
967
+ /**
968
+ * iOS only - Gets the original app transaction ID if the app was purchased from the App Store
969
+ * @platform iOS
970
+ * @description
971
+ * This function retrieves the original app transaction information if the app was purchased
972
+ * from the App Store. Returns null if the app was not purchased (e.g., free app or TestFlight).
973
+ *
974
+ * @returns {Promise<string | null>} The original app transaction ID or null
975
+ *
976
+ * @example
977
+ * ```typescript
978
+ * const appTransaction = await getAppTransactionIOS();
979
+ * if (appTransaction) {
980
+ * console.log('App was purchased, transaction ID:', appTransaction);
981
+ * } else {
982
+ * console.log('App was not purchased from App Store');
983
+ * }
984
+ * ```
985
+ */
986
+ export const getAppTransactionIOS = async () => {
987
+ if (Platform.OS !== 'ios') {
988
+ throw new Error('getAppTransactionIOS is only available on iOS');
989
+ }
990
+ try {
991
+ // Call the native method to get app transaction
992
+ const appTransaction = await iap.getAppTransactionIOS();
993
+ return appTransaction;
994
+ } catch (error) {
995
+ console.error('Failed to get app transaction:', error);
996
+ throw error;
997
+ }
998
+ };
999
+
1000
+ // Export subscription helpers
1001
+ export { getActiveSubscriptions, hasActiveSubscriptions } from "./helpers/subscription.js";
1002
+
1003
+ // Type conversion utilities
1004
+ export { convertNitroProductToProduct, convertNitroPurchaseToPurchase, convertProductToSubscriptionProduct, validateNitroProduct, validateNitroPurchase, checkTypeSynchronization } from "./utils/type-bridge.js";
1005
+
1006
+ // Deprecated exports for backward compatibility
1007
+ /**
1008
+ * @deprecated Use acknowledgePurchaseAndroid instead
1009
+ */
1010
+ export const acknowledgePurchase = acknowledgePurchaseAndroid;
1011
+
1012
+ /**
1013
+ * @deprecated Use consumePurchaseAndroid instead
1014
+ */
1015
+ export const consumePurchase = consumePurchaseAndroid;
10
1016
  //# sourceMappingURL=index.js.map