@voidhash/nitro-ui 0.0.0-stage → 0.4.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 (442) hide show
  1. package/LICENSE.md +21 -0
  2. package/Package.swift +161 -0
  3. package/README.md +127 -2
  4. package/android/nitro-ui.gradle +35 -0
  5. package/android/src/main/java/com/margelo/nitro/voidhash/HybridVoidhashNativeClient.kt +53 -0
  6. package/android/src/main/java/com/margelo/nitro/voidhash/VoidhashNitroUIModule.kt +65 -0
  7. package/android/src/main/java/com/margelo/nitro/voidhash/client/LegacyStorageImporter.kt +526 -0
  8. package/android/src/main/java/com/margelo/nitro/voidhash/client/SdkBackedNativeClient.kt +1131 -0
  9. package/android/src/main/java/com/margelo/nitro/voidhash/client/StoreMapping.kt +257 -0
  10. package/android/src/main/java/com/margelo/nitro/voidhash/client/VoidhashFlowPermissionHandlers.kt +23 -0
  11. package/android/src/main/java/com/margelo/nitro/voidhash/flows/VoidhashFlowsCore.kt +93 -0
  12. package/build/chunk-Z6TDMZMZ.js +326 -0
  13. package/build/chunk-Z6TDMZMZ.js.map +1 -0
  14. package/build/index.d.ts +2866 -0
  15. package/build/index.js +4182 -0
  16. package/build/index.js.map +1 -0
  17. package/build/navigation.d.ts +66 -0
  18. package/build/navigation.js +72 -0
  19. package/build/navigation.js.map +1 -0
  20. package/ios/HybridVoidhashNativeClient.swift +427 -0
  21. package/ios/Shared/NativeClientMapping.swift +184 -0
  22. package/ios/Shared/NativeStoreJson.swift +126 -0
  23. package/ios/Shared/VoidhashCoreExports.swift +5 -0
  24. package/ios/Shared/VoidhashLegacyImporter.swift +686 -0
  25. package/ios/Shared/VoidhashNativeClientCore.swift +1400 -0
  26. package/nitro.json +8 -0
  27. package/nitrogen/generated/.gitattributes +1 -0
  28. package/nitrogen/generated/android/NitroVoidhash+autolinking.cmake +86 -0
  29. package/nitrogen/generated/android/NitroVoidhash+autolinking.gradle +10 -0
  30. package/nitrogen/generated/android/NitroVoidhashOnLoad.cpp +22 -0
  31. package/nitrogen/generated/android/c++/JCallback_Promise_std__string__std__string_std__string.cpp +57 -0
  32. package/nitrogen/generated/android/c++/JCallback_void_NativeClientEvent.cpp +55 -0
  33. package/nitrogen/generated/android/c++/JHybridVoidhashNativeClientSpec.cpp +387 -0
  34. package/nitrogen/generated/android/c++/JNativeAnalyticsConsent.cpp +55 -0
  35. package/nitrogen/generated/android/c++/JNativeAppStoreMessages.cpp +52 -0
  36. package/nitrogen/generated/android/c++/JNativeAppStorePurchaseOptions.cpp +36 -0
  37. package/nitrogen/generated/android/c++/JNativeAppStoreSubscriptionState.cpp +64 -0
  38. package/nitrogen/generated/android/c++/JNativeAppStoreSubscriptionStatus.cpp +38 -0
  39. package/nitrogen/generated/android/c++/JNativeClientConfiguration.cpp +75 -0
  40. package/nitrogen/generated/android/c++/JNativeClientEvent.cpp +52 -0
  41. package/nitrogen/generated/android/c++/JNativeClientEventType.cpp +70 -0
  42. package/nitrogen/generated/android/c++/JNativeDiagnostic.cpp +44 -0
  43. package/nitrogen/generated/android/c++/JNativeDiagnosticKind.cpp +67 -0
  44. package/nitrogen/generated/android/c++/JNativeEnvironment.cpp +61 -0
  45. package/nitrogen/generated/android/c++/JNativeFeatureFlag.cpp +41 -0
  46. package/nitrogen/generated/android/c++/JNativeFeatureFlagsResult.cpp +45 -0
  47. package/nitrogen/generated/android/c++/JNativeFlowCapability.cpp +58 -0
  48. package/nitrogen/generated/android/c++/JNativeFlowLoading.cpp +52 -0
  49. package/nitrogen/generated/android/c++/JNativeFlowPresentation.cpp +42 -0
  50. package/nitrogen/generated/android/c++/JNativeFlowRevision.cpp +37 -0
  51. package/nitrogen/generated/android/c++/JNativeFlowRuntime.cpp +52 -0
  52. package/nitrogen/generated/android/c++/JNativeFlushStatus.cpp +40 -0
  53. package/nitrogen/generated/android/c++/JNativeFreshnessReason.cpp +58 -0
  54. package/nitrogen/generated/android/c++/JNativeGooglePlayPurchaseOptions.cpp +40 -0
  55. package/nitrogen/generated/android/c++/JNativeIdentifyResult.cpp +40 -0
  56. package/nitrogen/generated/android/c++/JNativeIdentityChange.cpp +38 -0
  57. package/nitrogen/generated/android/c++/JNativeInAppMessageResult.cpp +38 -0
  58. package/nitrogen/generated/android/c++/JNativeInAppMessageStatus.cpp +52 -0
  59. package/nitrogen/generated/android/c++/JNativeOffer.cpp +44 -0
  60. package/nitrogen/generated/android/c++/JNativeOfferKind.cpp +61 -0
  61. package/nitrogen/generated/android/c++/JNativeOfferSelection.cpp +55 -0
  62. package/nitrogen/generated/android/c++/JNativePaymentMode.cpp +58 -0
  63. package/nitrogen/generated/android/c++/JNativePendingAnalytics.cpp +52 -0
  64. package/nitrogen/generated/android/c++/JNativePeriod.cpp +39 -0
  65. package/nitrogen/generated/android/c++/JNativePeriodUnit.cpp +61 -0
  66. package/nitrogen/generated/android/c++/JNativePersonState.cpp +44 -0
  67. package/nitrogen/generated/android/c++/JNativePersonWriteResult.cpp +38 -0
  68. package/nitrogen/generated/android/c++/JNativePrice.cpp +39 -0
  69. package/nitrogen/generated/android/c++/JNativePricingPhase.cpp +40 -0
  70. package/nitrogen/generated/android/c++/JNativeProduct.cpp +55 -0
  71. package/nitrogen/generated/android/c++/JNativeProductType.cpp +61 -0
  72. package/nitrogen/generated/android/c++/JNativePurchaseIntent.cpp +38 -0
  73. package/nitrogen/generated/android/c++/JNativePurchaseIntents.cpp +52 -0
  74. package/nitrogen/generated/android/c++/JNativePurchaseOptions.cpp +49 -0
  75. package/nitrogen/generated/android/c++/JNativePurchaseOutcome.cpp +55 -0
  76. package/nitrogen/generated/android/c++/JNativePurchaseResult.cpp +40 -0
  77. package/nitrogen/generated/android/c++/JNativeRefundRequestStatus.cpp +52 -0
  78. package/nitrogen/generated/android/c++/JNativeReportedPurchaseState.cpp +55 -0
  79. package/nitrogen/generated/android/c++/JNativeReportedTransaction.cpp +42 -0
  80. package/nitrogen/generated/android/c++/JNativeStore.cpp +58 -0
  81. package/nitrogen/generated/android/c++/JNativeStorePlatform.cpp +52 -0
  82. package/nitrogen/generated/android/c++/JNativeStorefront.cpp +37 -0
  83. package/nitrogen/generated/android/c++/JNativeSubscriptionInfo.cpp +45 -0
  84. package/nitrogen/generated/android/c++/JNativeSubscriptionReplacement.cpp +36 -0
  85. package/nitrogen/generated/android/c++/JNativeSubscriptionReplacementMode.cpp +61 -0
  86. package/nitrogen/generated/android/c++/JNativeTransaction.cpp +53 -0
  87. package/nitrogen/generated/android/c++/JNativeTransactionOffer.cpp +40 -0
  88. package/nitrogen/generated/android/c++/JNativeTransactionOfferKind.cpp +64 -0
  89. package/nitrogen/generated/android/c++/JNativeTransactionUpdate.cpp +36 -0
  90. package/nitrogen/generated/android/c++/JNativeWriteStatus.cpp +55 -0
  91. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JCallback_Promise_std__string__std__string_std__string.hpp +55 -0
  92. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JCallback_void_NativeClientEvent.hpp +54 -0
  93. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JHybridVoidhashNativeClientSpec.hpp +166 -0
  94. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JHybridVoidhashNativeClientSpecJavaPart.hpp +26 -0
  95. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativeAnalyticsConsent.hpp +77 -0
  96. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativeAppStoreMessages.hpp +72 -0
  97. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativeAppStorePurchaseOptions.hpp +51 -0
  98. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativeAppStoreSubscriptionState.hpp +92 -0
  99. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativeAppStoreSubscriptionStatus.hpp +61 -0
  100. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativeClientConfiguration.hpp +190 -0
  101. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativeClientEvent.hpp +99 -0
  102. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativeClientEventType.hpp +102 -0
  103. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativeDiagnostic.hpp +79 -0
  104. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativeDiagnosticKind.hpp +97 -0
  105. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativeEnvironment.hpp +87 -0
  106. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativeFeatureFlag.hpp +68 -0
  107. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativeFeatureFlagsResult.hpp +76 -0
  108. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativeFlowCapability.hpp +82 -0
  109. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativeFlowLoading.hpp +72 -0
  110. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativeFlowPresentation.hpp +65 -0
  111. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativeFlowRevision.hpp +56 -0
  112. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativeFlowRuntime.hpp +72 -0
  113. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativeFlushStatus.hpp +63 -0
  114. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativeFreshnessReason.hpp +82 -0
  115. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativeGooglePlayPurchaseOptions.hpp +63 -0
  116. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativeIdentifyResult.hpp +63 -0
  117. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativeIdentityChange.hpp +61 -0
  118. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativeInAppMessageResult.hpp +57 -0
  119. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativeInAppMessageStatus.hpp +72 -0
  120. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativeOffer.hpp +71 -0
  121. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativeOfferKind.hpp +87 -0
  122. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativeOfferSelection.hpp +77 -0
  123. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativePaymentMode.hpp +82 -0
  124. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativePendingAnalytics.hpp +72 -0
  125. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativePeriod.hpp +62 -0
  126. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativePeriodUnit.hpp +87 -0
  127. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativePersonState.hpp +79 -0
  128. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativePersonWriteResult.hpp +57 -0
  129. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativePrice.hpp +66 -0
  130. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativePricingPhase.hpp +67 -0
  131. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativeProduct.hpp +118 -0
  132. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativeProductType.hpp +87 -0
  133. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativePurchaseIntent.hpp +57 -0
  134. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativePurchaseIntents.hpp +72 -0
  135. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativePurchaseOptions.hpp +88 -0
  136. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativePurchaseOutcome.hpp +77 -0
  137. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativePurchaseResult.hpp +63 -0
  138. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativeRefundRequestStatus.hpp +72 -0
  139. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativeReportedPurchaseState.hpp +77 -0
  140. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativeReportedTransaction.hpp +73 -0
  141. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativeStore.hpp +82 -0
  142. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativeStorePlatform.hpp +72 -0
  143. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativeStorefront.hpp +56 -0
  144. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativeSubscriptionInfo.hpp +84 -0
  145. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativeSubscriptionReplacement.hpp +55 -0
  146. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativeSubscriptionReplacementMode.hpp +87 -0
  147. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativeTransaction.hpp +116 -0
  148. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativeTransactionOffer.hpp +63 -0
  149. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativeTransactionOfferKind.hpp +92 -0
  150. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativeTransactionUpdate.hpp +55 -0
  151. package/nitrogen/generated/android/c++/include/NitroVoidhash/private/JNativeWriteStatus.hpp +77 -0
  152. package/nitrogen/generated/android/include/NitroVoidhash/private/NitroVoidhashOnLoad.hpp +13 -0
  153. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/Callback_Promise_std__string__std__string_std__string.kt +69 -0
  154. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/Callback_void_NativeClientEvent.kt +69 -0
  155. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/HybridVoidhashNativeClientSpec.kt +278 -0
  156. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativeAnalyticsConsent.kt +49 -0
  157. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativeAppStoreMessages.kt +46 -0
  158. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativeAppStorePurchaseOptions.kt +46 -0
  159. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativeAppStoreSubscriptionState.kt +58 -0
  160. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativeAppStoreSubscriptionStatus.kt +57 -0
  161. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativeClientConfiguration.kt +172 -0
  162. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativeClientEvent.kt +87 -0
  163. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativeClientEventType.kt +64 -0
  164. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativeDiagnostic.kt +72 -0
  165. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativeDiagnosticKind.kt +61 -0
  166. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativeEnvironment.kt +55 -0
  167. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativeFeatureFlag.kt +62 -0
  168. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativeFeatureFlagsResult.kt +67 -0
  169. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativeFlowCapability.kt +52 -0
  170. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativeFlowLoading.kt +46 -0
  171. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativeFlowPresentation.kt +57 -0
  172. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativeFlowRevision.kt +52 -0
  173. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativeFlowRuntime.kt +46 -0
  174. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativeFlushStatus.kt +57 -0
  175. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativeFreshnessReason.kt +52 -0
  176. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativeGooglePlayPurchaseOptions.kt +57 -0
  177. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativeIdentifyResult.kt +57 -0
  178. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativeIdentityChange.kt +57 -0
  179. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativeInAppMessageResult.kt +52 -0
  180. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativeInAppMessageStatus.kt +46 -0
  181. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativeOffer.kt +62 -0
  182. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativeOfferKind.kt +55 -0
  183. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativeOfferSelection.kt +49 -0
  184. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativePaymentMode.kt +52 -0
  185. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativePendingAnalytics.kt +46 -0
  186. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativePeriod.kt +57 -0
  187. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativePeriodUnit.kt +55 -0
  188. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativePersonState.kt +72 -0
  189. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativePersonWriteResult.kt +52 -0
  190. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativePrice.kt +62 -0
  191. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativePricingPhase.kt +62 -0
  192. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativeProduct.kt +107 -0
  193. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativeProductType.kt +55 -0
  194. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativePurchaseIntent.kt +52 -0
  195. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativePurchaseIntents.kt +46 -0
  196. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativePurchaseOptions.kt +77 -0
  197. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativePurchaseOutcome.kt +49 -0
  198. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativePurchaseResult.kt +57 -0
  199. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativeRefundRequestStatus.kt +46 -0
  200. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativeReportedPurchaseState.kt +49 -0
  201. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativeReportedTransaction.kt +67 -0
  202. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativeStore.kt +52 -0
  203. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativeStorePlatform.kt +46 -0
  204. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativeStorefront.kt +52 -0
  205. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativeSubscriptionInfo.kt +77 -0
  206. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativeSubscriptionReplacement.kt +52 -0
  207. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativeSubscriptionReplacementMode.kt +55 -0
  208. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativeTransaction.kt +107 -0
  209. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativeTransactionOffer.kt +57 -0
  210. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativeTransactionOfferKind.kt +58 -0
  211. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativeTransactionUpdate.kt +52 -0
  212. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NativeWriteStatus.kt +49 -0
  213. package/nitrogen/generated/android/kotlin/com/margelo/nitro/voidhash/NitroVoidhashOnLoad.kt +22 -0
  214. package/nitrogen/generated/apple/NitroVoidhash-Swift-Cxx-Bridge.cpp +381 -0
  215. package/nitrogen/generated/apple/NitroVoidhashAppleCxx/NitroVoidhashAppleCxx.cpp +9 -0
  216. package/nitrogen/generated/apple/NitroVoidhashAppleCxx/include/NitroVoidhashAppleCxx/NitroVoidhashAppleCxx.h +265 -0
  217. package/nitrogen/generated/apple/NitroVoidhashAutolinking.cpp +20 -0
  218. package/nitrogen/generated/apple/NitroVoidhashAutolinking.mm +24 -0
  219. package/nitrogen/generated/apple/c++/HybridVoidhashNativeClientSpecSwift.cpp +555 -0
  220. package/nitrogen/generated/apple/c++/HybridVoidhashNativeClientSpec_cxx-Swift.cpp +28 -0
  221. package/nitrogen/generated/apple/c++/NativeAnalyticsConsent-Swift.cpp +49 -0
  222. package/nitrogen/generated/apple/c++/NativeAppStoreMessages-Swift.cpp +46 -0
  223. package/nitrogen/generated/apple/c++/NativeAppStorePurchaseOptions-Swift.cpp +32 -0
  224. package/nitrogen/generated/apple/c++/NativeAppStoreSubscriptionState-Swift.cpp +58 -0
  225. package/nitrogen/generated/apple/c++/NativeAppStoreSubscriptionStatus-Swift.cpp +34 -0
  226. package/nitrogen/generated/apple/c++/NativeClientConfiguration-Swift.cpp +57 -0
  227. package/nitrogen/generated/apple/c++/NativeClientEvent-Swift.cpp +40 -0
  228. package/nitrogen/generated/apple/c++/NativeClientEventType-Swift.cpp +64 -0
  229. package/nitrogen/generated/apple/c++/NativeDiagnostic-Swift.cpp +37 -0
  230. package/nitrogen/generated/apple/c++/NativeDiagnosticKind-Swift.cpp +61 -0
  231. package/nitrogen/generated/apple/c++/NativeEnvironment-Swift.cpp +55 -0
  232. package/nitrogen/generated/apple/c++/NativeFeatureFlag-Swift.cpp +35 -0
  233. package/nitrogen/generated/apple/c++/NativeFeatureFlagsResult-Swift.cpp +36 -0
  234. package/nitrogen/generated/apple/c++/NativeFlowCapability-Swift.cpp +52 -0
  235. package/nitrogen/generated/apple/c++/NativeFlowLoading-Swift.cpp +46 -0
  236. package/nitrogen/generated/apple/c++/NativeFlowPresentation-Swift.cpp +34 -0
  237. package/nitrogen/generated/apple/c++/NativeFlowRevision-Swift.cpp +33 -0
  238. package/nitrogen/generated/apple/c++/NativeFlowRuntime-Swift.cpp +46 -0
  239. package/nitrogen/generated/apple/c++/NativeFlushStatus-Swift.cpp +34 -0
  240. package/nitrogen/generated/apple/c++/NativeFreshnessReason-Swift.cpp +52 -0
  241. package/nitrogen/generated/apple/c++/NativeGooglePlayPurchaseOptions-Swift.cpp +34 -0
  242. package/nitrogen/generated/apple/c++/NativeIdentifyResult-Swift.cpp +34 -0
  243. package/nitrogen/generated/apple/c++/NativeIdentityChange-Swift.cpp +34 -0
  244. package/nitrogen/generated/apple/c++/NativeInAppMessageResult-Swift.cpp +33 -0
  245. package/nitrogen/generated/apple/c++/NativeInAppMessageStatus-Swift.cpp +46 -0
  246. package/nitrogen/generated/apple/c++/NativeOffer-Swift.cpp +35 -0
  247. package/nitrogen/generated/apple/c++/NativeOfferKind-Swift.cpp +55 -0
  248. package/nitrogen/generated/apple/c++/NativeOfferSelection-Swift.cpp +49 -0
  249. package/nitrogen/generated/apple/c++/NativePaymentMode-Swift.cpp +52 -0
  250. package/nitrogen/generated/apple/c++/NativePendingAnalytics-Swift.cpp +46 -0
  251. package/nitrogen/generated/apple/c++/NativePeriod-Swift.cpp +34 -0
  252. package/nitrogen/generated/apple/c++/NativePeriodUnit-Swift.cpp +55 -0
  253. package/nitrogen/generated/apple/c++/NativePersonState-Swift.cpp +37 -0
  254. package/nitrogen/generated/apple/c++/NativePersonWriteResult-Swift.cpp +33 -0
  255. package/nitrogen/generated/apple/c++/NativePrice-Swift.cpp +35 -0
  256. package/nitrogen/generated/apple/c++/NativePricingPhase-Swift.cpp +35 -0
  257. package/nitrogen/generated/apple/c++/NativeProduct-Swift.cpp +44 -0
  258. package/nitrogen/generated/apple/c++/NativeProductType-Swift.cpp +55 -0
  259. package/nitrogen/generated/apple/c++/NativePurchaseIntent-Swift.cpp +33 -0
  260. package/nitrogen/generated/apple/c++/NativePurchaseIntents-Swift.cpp +46 -0
  261. package/nitrogen/generated/apple/c++/NativePurchaseOptions-Swift.cpp +38 -0
  262. package/nitrogen/generated/apple/c++/NativePurchaseOutcome-Swift.cpp +49 -0
  263. package/nitrogen/generated/apple/c++/NativePurchaseResult-Swift.cpp +34 -0
  264. package/nitrogen/generated/apple/c++/NativeRefundRequestStatus-Swift.cpp +46 -0
  265. package/nitrogen/generated/apple/c++/NativeReportedPurchaseState-Swift.cpp +49 -0
  266. package/nitrogen/generated/apple/c++/NativeReportedTransaction-Swift.cpp +36 -0
  267. package/nitrogen/generated/apple/c++/NativeStore-Swift.cpp +52 -0
  268. package/nitrogen/generated/apple/c++/NativeStorePlatform-Swift.cpp +46 -0
  269. package/nitrogen/generated/apple/c++/NativeStorefront-Swift.cpp +33 -0
  270. package/nitrogen/generated/apple/c++/NativeSubscriptionInfo-Swift.cpp +38 -0
  271. package/nitrogen/generated/apple/c++/NativeSubscriptionReplacement-Swift.cpp +33 -0
  272. package/nitrogen/generated/apple/c++/NativeSubscriptionReplacementMode-Swift.cpp +55 -0
  273. package/nitrogen/generated/apple/c++/NativeTransaction-Swift.cpp +44 -0
  274. package/nitrogen/generated/apple/c++/NativeTransactionOffer-Swift.cpp +34 -0
  275. package/nitrogen/generated/apple/c++/NativeTransactionOfferKind-Swift.cpp +58 -0
  276. package/nitrogen/generated/apple/c++/NativeTransactionUpdate-Swift.cpp +33 -0
  277. package/nitrogen/generated/apple/c++/NativeWriteStatus-Swift.cpp +49 -0
  278. package/nitrogen/generated/apple/c++/Record_swift__String_bool-Swift.cpp +26 -0
  279. package/nitrogen/generated/apple/c++/Record_swift__String_swift__String-Swift.cpp +26 -0
  280. package/nitrogen/generated/apple/c++/SwiftContainer_swift__Array___NitroVoidhash__NativeAppStoreSubscriptionStatus_-Swift.cpp +38 -0
  281. package/nitrogen/generated/apple/c++/SwiftContainer_swift__Array___NitroVoidhash__NativeProduct_-Swift.cpp +41 -0
  282. package/nitrogen/generated/apple/c++/SwiftContainer_swift__Array___NitroVoidhash__NativeTransaction_-Swift.cpp +36 -0
  283. package/nitrogen/generated/apple/c++/SwiftContainer_swift__Optional___NitroVoidhash__NativeStorefront_-Swift.cpp +30 -0
  284. package/nitrogen/generated/apple/c++/include/NitroVoidhash/NitroVoidhashAutolinking.hpp +13 -0
  285. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/HybridVoidhashNativeClientSpecSwift.hpp +121 -0
  286. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/HybridVoidhashNativeClientSpec_cxx-Swift.hpp +23 -0
  287. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativeAnalyticsConsent-Swift.hpp +23 -0
  288. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativeAppStoreMessages-Swift.hpp +23 -0
  289. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativeAppStorePurchaseOptions-Swift.hpp +23 -0
  290. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativeAppStoreSubscriptionState-Swift.hpp +23 -0
  291. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativeAppStoreSubscriptionStatus-Swift.hpp +23 -0
  292. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativeClientConfiguration-Swift.hpp +23 -0
  293. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativeClientEvent-Swift.hpp +23 -0
  294. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativeClientEventType-Swift.hpp +23 -0
  295. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativeDiagnostic-Swift.hpp +23 -0
  296. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativeDiagnosticKind-Swift.hpp +23 -0
  297. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativeEnvironment-Swift.hpp +23 -0
  298. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativeFeatureFlag-Swift.hpp +23 -0
  299. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativeFeatureFlagsResult-Swift.hpp +23 -0
  300. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativeFlowCapability-Swift.hpp +23 -0
  301. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativeFlowLoading-Swift.hpp +23 -0
  302. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativeFlowPresentation-Swift.hpp +23 -0
  303. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativeFlowRevision-Swift.hpp +23 -0
  304. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativeFlowRuntime-Swift.hpp +23 -0
  305. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativeFlushStatus-Swift.hpp +23 -0
  306. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativeFreshnessReason-Swift.hpp +23 -0
  307. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativeGooglePlayPurchaseOptions-Swift.hpp +23 -0
  308. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativeIdentifyResult-Swift.hpp +23 -0
  309. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativeIdentityChange-Swift.hpp +23 -0
  310. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativeInAppMessageResult-Swift.hpp +23 -0
  311. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativeInAppMessageStatus-Swift.hpp +23 -0
  312. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativeOffer-Swift.hpp +23 -0
  313. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativeOfferKind-Swift.hpp +23 -0
  314. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativeOfferSelection-Swift.hpp +23 -0
  315. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativePaymentMode-Swift.hpp +23 -0
  316. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativePendingAnalytics-Swift.hpp +23 -0
  317. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativePeriod-Swift.hpp +23 -0
  318. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativePeriodUnit-Swift.hpp +23 -0
  319. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativePersonState-Swift.hpp +23 -0
  320. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativePersonWriteResult-Swift.hpp +23 -0
  321. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativePrice-Swift.hpp +23 -0
  322. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativePricingPhase-Swift.hpp +23 -0
  323. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativeProduct-Swift.hpp +23 -0
  324. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativeProductType-Swift.hpp +23 -0
  325. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativePurchaseIntent-Swift.hpp +23 -0
  326. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativePurchaseIntents-Swift.hpp +23 -0
  327. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativePurchaseOptions-Swift.hpp +23 -0
  328. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativePurchaseOutcome-Swift.hpp +23 -0
  329. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativePurchaseResult-Swift.hpp +23 -0
  330. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativeRefundRequestStatus-Swift.hpp +23 -0
  331. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativeReportedPurchaseState-Swift.hpp +23 -0
  332. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativeReportedTransaction-Swift.hpp +23 -0
  333. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativeStore-Swift.hpp +23 -0
  334. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativeStorePlatform-Swift.hpp +23 -0
  335. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativeStorefront-Swift.hpp +23 -0
  336. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativeSubscriptionInfo-Swift.hpp +23 -0
  337. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativeSubscriptionReplacement-Swift.hpp +23 -0
  338. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativeSubscriptionReplacementMode-Swift.hpp +23 -0
  339. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativeTransaction-Swift.hpp +23 -0
  340. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativeTransactionOffer-Swift.hpp +23 -0
  341. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativeTransactionOfferKind-Swift.hpp +23 -0
  342. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativeTransactionUpdate-Swift.hpp +23 -0
  343. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NativeWriteStatus-Swift.hpp +23 -0
  344. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/NitroVoidhash-Swift-Cxx-Umbrella.hpp +100 -0
  345. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/Record_swift__String_bool-Swift.hpp +23 -0
  346. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/Record_swift__String_swift__String-Swift.hpp +23 -0
  347. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/SwiftContainer_swift__Array___NitroVoidhash__NativeAppStoreSubscriptionStatus_-Swift.hpp +23 -0
  348. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/SwiftContainer_swift__Array___NitroVoidhash__NativeProduct_-Swift.hpp +23 -0
  349. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/SwiftContainer_swift__Array___NitroVoidhash__NativeTransaction_-Swift.hpp +23 -0
  350. package/nitrogen/generated/apple/c++/include/NitroVoidhash/private/SwiftContainer_swift__Optional___NitroVoidhash__NativeStorefront_-Swift.hpp +23 -0
  351. package/nitrogen/generated/apple/c++/include/module.modulemap +12 -0
  352. package/nitrogen/generated/apple/swift/Callback_Promise_swift__String__swift__String_swift__String.swift +73 -0
  353. package/nitrogen/generated/apple/swift/Callback_void___NitroVoidhash__NativeClientEvent.swift +66 -0
  354. package/nitrogen/generated/apple/swift/HybridVoidhashNativeClientSpec.swift +113 -0
  355. package/nitrogen/generated/apple/swift/HybridVoidhashNativeClientSpec_cxx.swift +629 -0
  356. package/nitrogen/generated/apple/swift/NativeAnalyticsConsent.swift +59 -0
  357. package/nitrogen/generated/apple/swift/NativeAppStoreMessages.swift +54 -0
  358. package/nitrogen/generated/apple/swift/NativeAppStorePurchaseOptions.swift +28 -0
  359. package/nitrogen/generated/apple/swift/NativeAppStoreSubscriptionState.swift +74 -0
  360. package/nitrogen/generated/apple/swift/NativeAppStoreSubscriptionStatus.swift +42 -0
  361. package/nitrogen/generated/apple/swift/NativeClientConfiguration.swift +203 -0
  362. package/nitrogen/generated/apple/swift/NativeClientEvent.swift +84 -0
  363. package/nitrogen/generated/apple/swift/NativeClientEventType.swift +84 -0
  364. package/nitrogen/generated/apple/swift/NativeDiagnostic.swift +63 -0
  365. package/nitrogen/generated/apple/swift/NativeDiagnosticKind.swift +79 -0
  366. package/nitrogen/generated/apple/swift/NativeEnvironment.swift +69 -0
  367. package/nitrogen/generated/apple/swift/NativeFeatureFlag.swift +49 -0
  368. package/nitrogen/generated/apple/swift/NativeFeatureFlagsResult.swift +56 -0
  369. package/nitrogen/generated/apple/swift/NativeFlowCapability.swift +64 -0
  370. package/nitrogen/generated/apple/swift/NativeFlowLoading.swift +54 -0
  371. package/nitrogen/generated/apple/swift/NativeFlowPresentation.swift +42 -0
  372. package/nitrogen/generated/apple/swift/NativeFlowRevision.swift +35 -0
  373. package/nitrogen/generated/apple/swift/NativeFlowRuntime.swift +54 -0
  374. package/nitrogen/generated/apple/swift/NativeFlushStatus.swift +42 -0
  375. package/nitrogen/generated/apple/swift/NativeFreshnessReason.swift +64 -0
  376. package/nitrogen/generated/apple/swift/NativeGooglePlayPurchaseOptions.swift +42 -0
  377. package/nitrogen/generated/apple/swift/NativeIdentifyResult.swift +42 -0
  378. package/nitrogen/generated/apple/swift/NativeIdentityChange.swift +42 -0
  379. package/nitrogen/generated/apple/swift/NativeInAppMessageResult.swift +35 -0
  380. package/nitrogen/generated/apple/swift/NativeInAppMessageStatus.swift +54 -0
  381. package/nitrogen/generated/apple/swift/NativeOffer.swift +49 -0
  382. package/nitrogen/generated/apple/swift/NativeOfferKind.swift +69 -0
  383. package/nitrogen/generated/apple/swift/NativeOfferSelection.swift +59 -0
  384. package/nitrogen/generated/apple/swift/NativePaymentMode.swift +64 -0
  385. package/nitrogen/generated/apple/swift/NativePendingAnalytics.swift +54 -0
  386. package/nitrogen/generated/apple/swift/NativePeriod.swift +42 -0
  387. package/nitrogen/generated/apple/swift/NativePeriodUnit.swift +69 -0
  388. package/nitrogen/generated/apple/swift/NativePersonState.swift +63 -0
  389. package/nitrogen/generated/apple/swift/NativePersonWriteResult.swift +35 -0
  390. package/nitrogen/generated/apple/swift/NativePrice.swift +49 -0
  391. package/nitrogen/generated/apple/swift/NativePricingPhase.swift +49 -0
  392. package/nitrogen/generated/apple/swift/NativeProduct.swift +112 -0
  393. package/nitrogen/generated/apple/swift/NativeProductType.swift +69 -0
  394. package/nitrogen/generated/apple/swift/NativePurchaseIntent.swift +35 -0
  395. package/nitrogen/generated/apple/swift/NativePurchaseIntents.swift +54 -0
  396. package/nitrogen/generated/apple/swift/NativePurchaseOptions.swift +70 -0
  397. package/nitrogen/generated/apple/swift/NativePurchaseOutcome.swift +59 -0
  398. package/nitrogen/generated/apple/swift/NativePurchaseResult.swift +42 -0
  399. package/nitrogen/generated/apple/swift/NativeRefundRequestStatus.swift +54 -0
  400. package/nitrogen/generated/apple/swift/NativeReportedPurchaseState.swift +59 -0
  401. package/nitrogen/generated/apple/swift/NativeReportedTransaction.swift +56 -0
  402. package/nitrogen/generated/apple/swift/NativeStore.swift +64 -0
  403. package/nitrogen/generated/apple/swift/NativeStorePlatform.swift +54 -0
  404. package/nitrogen/generated/apple/swift/NativeStorefront.swift +35 -0
  405. package/nitrogen/generated/apple/swift/NativeSubscriptionInfo.swift +70 -0
  406. package/nitrogen/generated/apple/swift/NativeSubscriptionReplacement.swift +35 -0
  407. package/nitrogen/generated/apple/swift/NativeSubscriptionReplacementMode.swift +69 -0
  408. package/nitrogen/generated/apple/swift/NativeTransaction.swift +112 -0
  409. package/nitrogen/generated/apple/swift/NativeTransactionOffer.swift +42 -0
  410. package/nitrogen/generated/apple/swift/NativeTransactionOfferKind.swift +74 -0
  411. package/nitrogen/generated/apple/swift/NativeTransactionUpdate.swift +35 -0
  412. package/nitrogen/generated/apple/swift/NativeWriteStatus.swift +59 -0
  413. package/nitrogen/generated/apple/swift/Promise_Promise_swift__String_.swift +100 -0
  414. package/nitrogen/generated/apple/swift/Promise___NitroVoidhash__NativeFeatureFlagsResult.swift +102 -0
  415. package/nitrogen/generated/apple/swift/Promise___NitroVoidhash__NativeFlushStatus.swift +102 -0
  416. package/nitrogen/generated/apple/swift/Promise___NitroVoidhash__NativeIdentifyResult.swift +102 -0
  417. package/nitrogen/generated/apple/swift/Promise___NitroVoidhash__NativeIdentityChange.swift +102 -0
  418. package/nitrogen/generated/apple/swift/Promise___NitroVoidhash__NativeInAppMessageResult.swift +102 -0
  419. package/nitrogen/generated/apple/swift/Promise___NitroVoidhash__NativePersonState.swift +102 -0
  420. package/nitrogen/generated/apple/swift/Promise___NitroVoidhash__NativePersonWriteResult.swift +102 -0
  421. package/nitrogen/generated/apple/swift/Promise___NitroVoidhash__NativePurchaseResult.swift +102 -0
  422. package/nitrogen/generated/apple/swift/Promise___NitroVoidhash__NativeRefundRequestStatus.swift +102 -0
  423. package/nitrogen/generated/apple/swift/Promise___NitroVoidhash__SwiftContainer_swift__Array___NitroVoidhash__NativeAppStoreSubscriptionStatus_.swift +102 -0
  424. package/nitrogen/generated/apple/swift/Promise___NitroVoidhash__SwiftContainer_swift__Array___NitroVoidhash__NativeProduct_.swift +102 -0
  425. package/nitrogen/generated/apple/swift/Promise___NitroVoidhash__SwiftContainer_swift__Array___NitroVoidhash__NativeTransaction_.swift +102 -0
  426. package/nitrogen/generated/apple/swift/Promise___NitroVoidhash__SwiftContainer_swift__Optional___NitroVoidhash__NativeStorefront_.swift +102 -0
  427. package/nitrogen/generated/apple/swift/Promise_bool.swift +100 -0
  428. package/nitrogen/generated/apple/swift/Promise_swift__String.swift +102 -0
  429. package/nitrogen/generated/apple/swift/Promise_void.swift +100 -0
  430. package/nitrogen/generated/apple/swift/Record_swift__String_bool.swift +48 -0
  431. package/nitrogen/generated/apple/swift/Record_swift__String_swift__String.swift +48 -0
  432. package/nitrogen/generated/apple/swift/SwiftContainer_swift__Array___NitroVoidhash__NativeAppStoreSubscriptionStatus_.swift +21 -0
  433. package/nitrogen/generated/apple/swift/SwiftContainer_swift__Array___NitroVoidhash__NativeProduct_.swift +21 -0
  434. package/nitrogen/generated/apple/swift/SwiftContainer_swift__Array___NitroVoidhash__NativeTransaction_.swift +21 -0
  435. package/nitrogen/generated/apple/swift/SwiftContainer_swift__Optional___NitroVoidhash__NativeStorefront_.swift +21 -0
  436. package/nitrogen/generated/hybrid-classes.json +19 -0
  437. package/nitrogen/generated/shared/c++/NitroVoidhashCxxModule.cpp +2 -0
  438. package/nitrogen/generated/shared/c++/include/NitroVoidhash/NitroVoidhashCxxModule.hpp +2 -0
  439. package/nitrogen/generated/shared/javascript/VoidhashNativeClient.cjs +19 -0
  440. package/nitrogen/generated/shared/javascript/VoidhashNativeClient.d.cts +9 -0
  441. package/package.json +103 -3
  442. package/src/specs/VoidhashNativeClient.nitro.ts +1162 -0
@@ -0,0 +1,1400 @@
1
+ // Copied from ../react-native/ios/VoidhashNativeClientCore.swift by `pnpm build`. Edit the original, not this copy.
2
+ import Foundation
3
+ import VoidhashCore
4
+
5
+ @_spi(VoidhashHost) import Voidhash
6
+
7
+ /// A failure the bridge reports to JavaScript, whose message is `"<CODE>: <detail>"`.
8
+ struct NativeClientError: Error, CustomStringConvertible, LocalizedError, Equatable {
9
+ let code: String
10
+ let detail: String
11
+
12
+ var description: String {
13
+ return "\(code): \(detail)"
14
+ }
15
+
16
+ var errorDescription: String? {
17
+ return description
18
+ }
19
+
20
+ static func notInitialized(_ detail: String = "the client is not started") -> NativeClientError {
21
+ return NativeClientError(code: "NOT_INITIALIZED", detail: detail)
22
+ }
23
+
24
+ static func invalidArgument(_ detail: String) -> NativeClientError {
25
+ return NativeClientError(code: "INVALID_ARGUMENT", detail: detail)
26
+ }
27
+
28
+ /// What a Google Play member answers on iOS, where it does nothing.
29
+ static func unsupportedPlatform(_ member: String) -> NativeClientError {
30
+ return NativeClientError(
31
+ code: "UNSUPPORTED_PLATFORM", detail: "\(member) is available on Google Play only")
32
+ }
33
+
34
+ /// The coded error a native failure reaches JavaScript as: its own code where it has one,
35
+ /// `fallback` otherwise.
36
+ static func from(_ error: any Error, fallback: String = "NATIVE_ERROR") -> NativeClientError {
37
+ switch error {
38
+ case let error as NativeClientError:
39
+ return error
40
+ case let error as VoidhashStoreError:
41
+ return NativeClientError(code: error.code, detail: error.message)
42
+ case let error as VoidhashApiError:
43
+ return NativeClientError(code: error.code, detail: error.message)
44
+ case let error as ReconcileTransactionsError:
45
+ return NativeClientError(code: error.code, detail: error.message)
46
+ case is CancellationError:
47
+ return NativeClientError(code: "CANCELLED", detail: "the call was cancelled")
48
+ default:
49
+ return NativeClientError(code: fallback, detail: String(describing: error))
50
+ }
51
+ }
52
+ }
53
+
54
+ /// The configuration the facade validated, see `NativeClientConfiguration` in the spec.
55
+ /// Runs an app action in JavaScript: takes the action's name and its arguments as a JSON object,
56
+ /// and returns the reply as a JSON object or throws.
57
+ typealias NativeFlowAction =
58
+ @Sendable (_ name: String, _ argumentsJson: String) async throws -> String
59
+
60
+ /// A flow result as the facade reads it; `productId` is present for a purchase only.
61
+ private struct NativeFlowResultPayload: Encodable {
62
+ let outcome: String
63
+ let output: [String: FlowValue]
64
+ let productId: String?
65
+ /// `false` when the presentation ended before the flow was shown.
66
+ let wasShown: Bool
67
+
68
+ init(_ result: FlowResult) {
69
+ outcome = result.outcome
70
+ output = result.output
71
+ productId = result.productId
72
+ wasShown = result.wasShown
73
+ }
74
+ }
75
+
76
+ struct NativeClientCoreConfiguration: Sendable, Equatable {
77
+ var publishableKey: String
78
+ var baseUrl: String
79
+ var ingestUrl: String?
80
+ var debug: Bool
81
+ var developmentMode: Bool
82
+ var distinctId: String?
83
+ var readOnly: Bool
84
+ var analyticsConsent: AnalyticsConsent
85
+ var chosenAnalyticsConsent: AnalyticsConsent?
86
+ var analyticsWhilePending: PendingAnalytics = .drop
87
+ var grantConsentOnIdentify: Bool = false
88
+ var automaticLifecycleEvents: Bool
89
+ var installAttribution: Bool
90
+ var preloadLocations: [String]
91
+ /// The interface revision the app was built against, by location slug.
92
+ var flowRevisions: [String: Int]
93
+ var flowCapabilities: Set<FlowCapability>
94
+ /// Flows are drawn with flow runtime modules (the `flowRuntime` option); `false` leaves the
95
+ /// renderer as it is.
96
+ var flowRuntimeModules: Bool = false
97
+ /// The linked renderer shows its loading screen (the `flowLoading` option); `false` turns it
98
+ /// off.
99
+ var showsFlowLoading: Bool = true
100
+ var screenTrackingEnabled: Bool
101
+ /// `nil` keeps the native client's default wait.
102
+ var featureFlagMaxWaitMilliseconds: Double? = nil
103
+ var featureFlagDefaults: [String: Bool] = [:]
104
+ var internalSchemaJson: String?
105
+ var appStoreMessages: VoidhashAppStoreMessagesHandling = .deferWhileFlowPresented
106
+ var purchaseIntents: VoidhashPurchaseIntentHandling = .purchaseWhenReady
107
+ var sdkVersion: String
108
+ }
109
+
110
+ /// A person answer as the bridge carries it.
111
+ struct NativePersonPayload: Sendable, Equatable {
112
+ let distinctId: String
113
+ let generation: Int
114
+ let personJson: String?
115
+ let isStale: Bool
116
+ let isExpired: Bool
117
+ let reason: StaleReason
118
+ }
119
+
120
+ struct NativeFlagPayload: Sendable, Equatable {
121
+ let key: String
122
+ let enabled: Bool
123
+ let variantKey: String?
124
+ let payloadJson: String?
125
+ }
126
+
127
+ struct NativeFlagsPayload: Sendable, Equatable {
128
+ let distinctId: String
129
+ let generation: Int
130
+ let flagKeys: [String]?
131
+ let flags: [NativeFlagPayload]
132
+ let isStale: Bool
133
+ }
134
+
135
+ struct NativeIdentifyPayload: Sendable, Equatable {
136
+ let identity: VoidhashIdentityChange
137
+ let status: PersonWriteStatus
138
+ let personJson: String?
139
+ }
140
+
141
+ struct NativePersonWritePayload: Sendable, Equatable {
142
+ let status: PersonWriteStatus
143
+ let personJson: String?
144
+ }
145
+
146
+ /// What `purchase()` buys beyond the product, see `NativePurchaseOptions` in the spec. Google
147
+ /// Play's options and `replacing` are left out: the App Store ignores them.
148
+ struct NativePurchaseRequest: Sendable, Equatable {
149
+ enum Offer: Sendable, Equatable {
150
+ case automatic
151
+ case regularPrice
152
+ /// The offer `id` names among the product's current offers, of `kind` when the app passed
153
+ /// an offer rather than an id.
154
+ case offer(id: String, kind: VoidhashOfferKind?)
155
+ }
156
+
157
+ var offer: Offer = .automatic
158
+ /// As JavaScript sent it; a whole number of at least 1.
159
+ var quantity: Double = 1
160
+ var simulatesAskToBuyInSandbox: Bool = false
161
+ }
162
+
163
+ /// A purchase another billing integration reported.
164
+ struct NativeReportedTransactionPayload: Sendable, Equatable {
165
+ /// `ios` or `android`.
166
+ let platform: String
167
+ let transactionId: String?
168
+ let purchaseToken: String?
169
+ /// `purchased`, `pending` or `unspecified`; `nil` counts as purchased.
170
+ let purchaseState: String?
171
+ /// The App Store transaction's JWS, when the host's purchase flow returned it.
172
+ var signedTransaction: String? = nil
173
+ }
174
+
175
+ /// One event for the bridge's listener, see `NativeClientEvent` in the spec.
176
+ enum NativeClientCoreEvent: Sendable {
177
+ case identity(VoidhashIdentityChange)
178
+ case person(NativePersonPayload)
179
+ case flags(NativeFlagsPayload)
180
+ case schema(String)
181
+ case consent(AnalyticsConsent)
182
+ case diagnostic(VoidhashDiagnostic)
183
+ /// An element of the client's ``VoidhashClient/transactionUpdates()``.
184
+ case transaction(VoidhashTransactionUpdate)
185
+ /// An App Store purchase intent, with `purchaseIntents: manual`.
186
+ case purchaseIntent(VoidhashPurchaseIntent)
187
+ }
188
+
189
+ /// Calls in flight, so `shutdown()` can settle every one of them before it resolves: a call
190
+ /// that has not finished by then rejects `NOT_INITIALIZED`, and its late result is dropped.
191
+ final class PendingNativeCalls: @unchecked Sendable {
192
+ private let lock = NSLock()
193
+ private var nextId: UInt64 = 0
194
+ private var rejecters: [UInt64: @Sendable (NativeClientError) -> Void] = [:]
195
+
196
+ func run<Value: Sendable>(
197
+ _ operation: @escaping @Sendable () async throws -> Value
198
+ ) async throws -> Value {
199
+ let settle = SettleOnce<Value>()
200
+ return try await withCheckedThrowingContinuation { continuation in
201
+ let id = lock.withLock { () -> UInt64 in
202
+ nextId += 1
203
+ rejecters[nextId] = { error in settle.resume(continuation, .failure(error)) }
204
+ return nextId
205
+ }
206
+ Task {
207
+ let result: Result<Value, any Error>
208
+ do {
209
+ result = .success(try await operation())
210
+ } catch {
211
+ result = .failure(error)
212
+ }
213
+ _ = lock.withLock { rejecters.removeValue(forKey: id) }
214
+ settle.resume(continuation, result)
215
+ }
216
+ }
217
+ }
218
+
219
+ /// Rejects every call still in flight with `error`.
220
+ func rejectAll(_ error: NativeClientError) {
221
+ let pending = lock.withLock { () -> [@Sendable (NativeClientError) -> Void] in
222
+ defer { rejecters.removeAll() }
223
+ return Array(rejecters.values)
224
+ }
225
+ pending.forEach { $0(error) }
226
+ }
227
+ }
228
+
229
+ /// Runs work strictly in submission order. Submitting is synchronous, so calls made one after
230
+ /// the other on the JavaScript thread run in that order, whatever thread their promise settles on.
231
+ final class OrderedNativeCalls: @unchecked Sendable {
232
+ private let lock = NSLock()
233
+ private var last: Task<Void, Never>?
234
+
235
+ func submit<Value: Sendable>(
236
+ _ operation: @escaping @Sendable () async throws -> Value
237
+ ) -> Task<Value, any Error> {
238
+ return lock.withLock {
239
+ let previous = last
240
+ let task = Task {
241
+ await previous?.value
242
+ return try await operation()
243
+ }
244
+ last = Task { _ = await task.result }
245
+ return task
246
+ }
247
+ }
248
+ }
249
+
250
+ /// A `start()` in flight: the callers joined to it, and its outcome once settled. Guarded by the
251
+ /// core's lock.
252
+ final class StartInFlight: @unchecked Sendable {
253
+ let signal = OneShotSignal()
254
+ var settles: [@Sendable (Result<Void, any Error>) -> Void]
255
+ var outcome: Result<Void, any Error>?
256
+
257
+ init(_ settle: @escaping @Sendable (Result<Void, any Error>) -> Void) {
258
+ settles = [settle]
259
+ }
260
+ }
261
+
262
+ /// Resolves the callers waiting for it once fired; later callers do not wait.
263
+ final class OneShotSignal: @unchecked Sendable {
264
+ private let lock = NSLock()
265
+ private var fired = false
266
+ private var waiters: [CheckedContinuation<Void, Never>] = []
267
+
268
+ func fire() {
269
+ let waiting = lock.withLock { () -> [CheckedContinuation<Void, Never>] in
270
+ fired = true
271
+ defer { waiters = [] }
272
+ return waiters
273
+ }
274
+ waiting.forEach { $0.resume() }
275
+ }
276
+
277
+ func wait() async {
278
+ await withCheckedContinuation { continuation in
279
+ let resumeNow = lock.withLock { () -> Bool in
280
+ if fired { return true }
281
+ waiters.append(continuation)
282
+ return false
283
+ }
284
+ if resumeNow { continuation.resume() }
285
+ }
286
+ }
287
+ }
288
+
289
+ /// Resumes a continuation once, whichever of the call and the shutdown gets there first.
290
+ private final class SettleOnce<Value: Sendable>: @unchecked Sendable {
291
+ private let lock = NSLock()
292
+ private var resumed = false
293
+
294
+ func resume(
295
+ _ continuation: CheckedContinuation<Value, any Error>, _ result: Result<Value, any Error>
296
+ ) {
297
+ let first = lock.withLock { () -> Bool in
298
+ defer { resumed = true }
299
+ return !resumed
300
+ }
301
+ if first {
302
+ continuation.resume(with: result)
303
+ }
304
+ }
305
+ }
306
+
307
+ /// The React Native client's native side, over the native ``VoidhashClient``: the behaviour
308
+ /// behind `HybridVoidhashNativeClient`, kept free of Nitro so it can be tested with SwiftPM.
309
+ ///
310
+ /// `configure()` only records the options; `start()` imports what the TypeScript core left on
311
+ /// the device, creates the native client and starts it from local state. Every later call goes
312
+ /// to that client and rejects `NOT_INITIALIZED` once it was shut down, or retired by a newer
313
+ /// instance over the same storage (a JavaScript reload).
314
+ final class VoidhashNativeClientCore: @unchecked Sendable {
315
+ /// Events taken before `start()`, kept with their call time; past this the oldest is dropped.
316
+ static let maxCapturesBeforeStart = 100
317
+ /// The version of the bridge contract (`src/specs/VoidhashNativeClient.nitro.ts`) this module
318
+ /// implements: the facade's `NATIVE_CONTRACT_VERSION`, which starts no client of another.
319
+ static let contractVersion = 1
320
+
321
+ /// Whether some client of this process started already: the `distinctId` option applies to
322
+ /// the first start of the process only.
323
+ private static let processStarted = AtomicBool(false)
324
+
325
+ private struct HeldCapture {
326
+ let name: String
327
+ let properties: [String: JSONValue]
328
+ let capturedAt: Double
329
+ }
330
+
331
+ private let lock = NSLock()
332
+ private let calls = PendingNativeCalls()
333
+ private let sdkName: String
334
+ private let makeClient: @Sendable (String, VoidhashOptions, VoidhashHostOptions) -> VoidhashClient
335
+ private let importLegacyData: @Sendable (NativeClientCoreConfiguration) async -> Void
336
+ private let now: @Sendable () -> Double
337
+ private let shutdownAwaitsStart: @Sendable () -> Void
338
+ private var configuration: NativeClientCoreConfiguration?
339
+ private var client: VoidhashClient?
340
+ /// The client `start()` created and is still starting: captures go to it from then on (its
341
+ /// intake holds them until it opens), and `shutdown()` can stop it.
342
+ private var startingClient: VoidhashClient?
343
+ /// The `start()` in progress. Its signal fires once it settled, resolved or rejected, so a
344
+ /// `shutdown()` that overtook it resolves only after it: a start then answers before the
345
+ /// next one runs.
346
+ private var inFlightStart: StartInFlight?
347
+ /// Identity changes and person writes, in call order.
348
+ private let ordered = OrderedNativeCalls()
349
+ /// Bumped by every `shutdown()`, so a `start()` it overtook rejects instead of leaving a live
350
+ /// client behind.
351
+ private var run = 0
352
+ private var listener: (@Sendable (NativeClientCoreEvent) -> Void)?
353
+ private var heldCaptures: [HeldCapture] = []
354
+ private var droppedCaptures = 0
355
+ /// The products the started client's last `getProducts()` answered, by slug: the ones
356
+ /// `purchase()` buys and `showManageSubscriptions()` names. Dropped once a purchase or a
357
+ /// restore may have changed the offers the end user is eligible for.
358
+ private var heldProducts: [String: VoidhashProduct] = [:]
359
+ /// Counts the products loads begun and the drops of the products held: only the latest load
360
+ /// begun since the last drop is held, so an earlier, slower one never replaces its answer.
361
+ private var productsLoads = 0
362
+ /// Forward the started client's transaction updates and purchase intents as events, until
363
+ /// `shutdown()` ends them.
364
+ private var updateForwarders: [Task<Void, Never>] = []
365
+
366
+ /// - Parameters:
367
+ /// - sdkName: The value of `x-sdk` and `$sdk`: the package this bridge ships in, such as
368
+ /// `react-native`.
369
+ /// - makeClient: Creates the native client; tests inject one over stubbed dependencies.
370
+ /// - importLegacyData: Imports what the TypeScript core persisted, before the client loads.
371
+ /// - shutdownAwaitsStart: Called when a `shutdown()` found no client yet and waits for the
372
+ /// start still building it; tests synchronize on it.
373
+ init(
374
+ sdkName: String,
375
+ makeClient: @escaping @Sendable (String, VoidhashOptions, VoidhashHostOptions) ->
376
+ VoidhashClient = { key, options, host in
377
+ VoidhashClient(publishableKey: key, options: options, host: host)
378
+ },
379
+ importLegacyData: @escaping @Sendable (NativeClientCoreConfiguration) async -> Void = {
380
+ configuration in
381
+ await VoidhashLegacyImporter.forConfiguration(configuration)?.run()
382
+ },
383
+ now: @escaping @Sendable () -> Double = { Date().timeIntervalSince1970 * 1000 },
384
+ shutdownAwaitsStart: @escaping @Sendable () -> Void = {}
385
+ ) {
386
+ self.sdkName = sdkName
387
+ self.makeClient = makeClient
388
+ self.importLegacyData = importLegacyData
389
+ self.now = now
390
+ self.shutdownAwaitsStart = shutdownAwaitsStart
391
+ }
392
+
393
+ // MARK: - Lifecycle
394
+
395
+ func configure(_ configuration: NativeClientCoreConfiguration) {
396
+ lock.withLock { self.configuration = configuration }
397
+ }
398
+
399
+ /// Starts the configured client. A start while one is in flight joins it, with its outcome;
400
+ /// one on a started client resolves without effect. `settle` receives the outcome before a
401
+ /// `shutdown()` that overtook the start resolves, so the bridge rejects the start's promise
402
+ /// first.
403
+ func start(
404
+ settle: @escaping @Sendable (Result<Void, any Error>) -> Void = { _ in }
405
+ ) async throws {
406
+ enum Entry {
407
+ case begin(NativeClientCoreConfiguration, run: Int, StartInFlight)
408
+ case join(StartInFlight)
409
+ case started
410
+ }
411
+ let entry: Entry
412
+ do {
413
+ entry = try lock.withLock { () -> Entry in
414
+ if client != nil {
415
+ return .started
416
+ }
417
+ if let inFlightStart {
418
+ inFlightStart.settles.append(settle)
419
+ return .join(inFlightStart)
420
+ }
421
+ guard let configuration = self.configuration else {
422
+ throw NativeClientError.notInitialized("configure() first")
423
+ }
424
+ let inFlight = StartInFlight(settle)
425
+ inFlightStart = inFlight
426
+ return .begin(configuration, run: run, inFlight)
427
+ }
428
+ } catch {
429
+ settle(.failure(error))
430
+ throw error
431
+ }
432
+ switch entry {
433
+ case .started:
434
+ settle(.success(()))
435
+ case .join(let inFlight):
436
+ await inFlight.signal.wait()
437
+ try lock.withLock { inFlight.outcome }?.get()
438
+ case .begin(let configuration, let startRun, let inFlight):
439
+ let result: Result<Void, any Error>
440
+ do {
441
+ try await performStart(configuration, run: startRun)
442
+ result = .success(())
443
+ } catch {
444
+ result = .failure(error)
445
+ }
446
+ // Joined in under the lock until here; none can join once the start is cleared.
447
+ let settles = lock.withLock { () -> [@Sendable (Result<Void, any Error>) -> Void] in
448
+ inFlight.outcome = result
449
+ inFlightStart = nil
450
+ return inFlight.settles
451
+ }
452
+ settles.forEach { $0(result) }
453
+ inFlight.signal.fire()
454
+ try result.get()
455
+ }
456
+ }
457
+
458
+ /// Builds and starts the client of `run`. A `shutdown()` since ends `run`: the client it
459
+ /// built is shut down here, as nothing else holds it.
460
+ private func performStart(_ configuration: NativeClientCoreConfiguration, run startRun: Int)
461
+ async throws
462
+ {
463
+ guard let baseUrl = URL(string: configuration.baseUrl) else {
464
+ throw NativeClientError.invalidArgument("baseUrl is not a URL")
465
+ }
466
+ let internalSchema = try configuration.internalSchemaJson.map { json in
467
+ do {
468
+ return try JSONDecoder().decode(RuntimeSchema.self, from: Data(json.utf8))
469
+ } catch {
470
+ throw NativeClientError.invalidArgument("internalSchemaJson is not a schema")
471
+ }
472
+ }
473
+
474
+ var options = VoidhashOptions(
475
+ baseUrl: baseUrl,
476
+ ingestUrl: configuration.ingestUrl.flatMap(URL.init(string:)),
477
+ debug: configuration.debug,
478
+ distinctId: VoidhashNativeClientCore.processStarted.exchange(true)
479
+ ? nil : configuration.distinctId,
480
+ readOnly: configuration.readOnly,
481
+ dev: configuration.developmentMode,
482
+ preloadLocations: configuration.preloadLocations,
483
+ flowRevisions: configuration.flowRevisions,
484
+ // Screens arrive through `screen()`, already mapped by the facade.
485
+ screenTracking: ScreenTrackingOptions(automatic: false),
486
+ automaticLifecycleEvents: configuration.automaticLifecycleEvents,
487
+ analyticsConsent: configuration.analyticsConsent,
488
+ flowRenderer: FlowRendererDiscovery.linkedRenderer(
489
+ runtimeModules: configuration.flowRuntimeModules,
490
+ showsLoading: configuration.showsFlowLoading),
491
+ flowCapabilities: configuration.flowCapabilities,
492
+ flowPermissionHandlers: VoidhashFlowPermissionHandlers.registered,
493
+ featureFlags: FeatureFlagOptions(
494
+ maxWaitMilliseconds: configuration.featureFlagMaxWaitMilliseconds
495
+ ?? FeatureFlagOptions().maxWaitMilliseconds,
496
+ defaults: configuration.featureFlagDefaults),
497
+ installAttribution: configuration.installAttribution,
498
+ analyticsWhilePending: configuration.analyticsWhilePending,
499
+ grantConsentOnIdentify: configuration.grantConsentOnIdentify,
500
+ appStoreMessages: configuration.appStoreMessages,
501
+ purchaseIntents: configuration.purchaseIntents)
502
+ // Diagnostics reach the facade as events, which its `onDiagnostic` dispatches.
503
+ options.onWarning = VoidhashWarnings.ignore
504
+ let host = VoidhashHostOptions(
505
+ sdkName: sdkName, sdkVersion: configuration.sdkVersion,
506
+ internalSchema: internalSchema, resolvesPaywalls: true,
507
+ // Imported once the client holds the storage, after a client still holding it (a
508
+ // JavaScript reload leaves one running) retired and handed its queues over.
509
+ prepareStorage: { [weak self, importLegacyData] in
510
+ if !VoidhashLegacyImporter.namespaceMatches(configuration) {
511
+ self?.deliver(
512
+ .diagnostic(
513
+ VoidhashDiagnostic(
514
+ kind: .cache, code: "LEGACY_IMPORT_SKIPPED",
515
+ operation: "start",
516
+ message:
517
+ "The base URL as configured maps to a different storage namespace than the native client's; data stored by the earlier SDK version is not imported"
518
+ )))
519
+ }
520
+ await importLegacyData(configuration)
521
+ },
522
+ events: { [weak self] event in self?.forward(event) })
523
+ let client = makeClient(configuration.publishableKey, options, host)
524
+ // Subscribed before the client starts, so nothing it reports while starting is missed,
525
+ // and forwarded once it started: after the identity and state it announces.
526
+ let transactionUpdates = client.transactionUpdates()
527
+ let purchaseIntents =
528
+ configuration.purchaseIntents == .manual ? client.appStore.purchaseIntents() : nil
529
+ // From here on captures go to the client, in order after the ones held so far.
530
+ let published = lock.withLock { () -> Int? in
531
+ guard run == startRun else {
532
+ return nil
533
+ }
534
+ for capture in heldCaptures {
535
+ client.captureNow(
536
+ capture.name, properties: capture.properties, capturedAt: capture.capturedAt)
537
+ }
538
+ let dropped = droppedCaptures
539
+ heldCaptures = []
540
+ droppedCaptures = 0
541
+ startingClient = client
542
+ return dropped
543
+ }
544
+ guard let dropped = published else {
545
+ await client.shutdown()
546
+ throw NativeClientError.notInitialized("shutdown() ended the start")
547
+ }
548
+ if let chosen = configuration.chosenAnalyticsConsent {
549
+ await client.setAnalyticsConsent(chosen)
550
+ }
551
+ await client.hostStart()
552
+ let stopped = lock.withLock { () -> Bool in
553
+ startingClient = nil
554
+ guard run == startRun else {
555
+ return true
556
+ }
557
+ self.client = client
558
+ updateForwarders = [
559
+ Task { [weak self] in
560
+ for await update in transactionUpdates {
561
+ // A renewal of a subscription the end user has changes no offer.
562
+ if update.transaction.isRenewal != true {
563
+ self?.dropHeldProducts()
564
+ }
565
+ self?.deliver(.transaction(update))
566
+ }
567
+ }
568
+ ]
569
+ if let purchaseIntents {
570
+ updateForwarders.append(
571
+ Task { [weak self] in
572
+ for await intent in purchaseIntents {
573
+ self?.deliver(.purchaseIntent(intent))
574
+ }
575
+ })
576
+ }
577
+ return false
578
+ }
579
+ guard !stopped else {
580
+ await client.shutdown()
581
+ throw NativeClientError.notInitialized("shutdown() ended the start")
582
+ }
583
+ if dropped > 0 {
584
+ deliver(
585
+ .diagnostic(
586
+ VoidhashDiagnostic(
587
+ kind: .eviction, code: "ANALYTICS_EVENT_DROPPED", operation: "capture",
588
+ message:
589
+ "Dropped the \(dropped) oldest event(s) captured before start(); \(VoidhashNativeClientCore.maxCapturesBeforeStart) are kept"
590
+ )))
591
+ }
592
+ }
593
+
594
+ /// How many calls joined the `start()` in flight, beyond the one that began it. Test
595
+ /// affordance.
596
+ var startsJoinedForTesting: Int {
597
+ return lock.withLock { (inFlightStart?.settles.count ?? 1) - 1 }
598
+ }
599
+
600
+ func shutdown() async throws -> FlushStatus {
601
+ let overtakenStart = lock.withLock { inFlightStart?.signal }
602
+ let (stopping, forwarders) = lock.withLock {
603
+ () -> (VoidhashClient?, [Task<Void, Never>]) in
604
+ defer {
605
+ self.client = nil
606
+ startingClient = nil
607
+ heldCaptures = []
608
+ droppedCaptures = 0
609
+ heldProducts = [:]
610
+ productsLoads += 1
611
+ updateForwarders = []
612
+ run += 1
613
+ }
614
+ return (self.client ?? startingClient, updateForwarders)
615
+ }
616
+ guard let client = stopping else {
617
+ // A start that has not built its client yet sees the shutdown and stops it itself.
618
+ if let overtakenStart {
619
+ shutdownAwaitsStart()
620
+ await overtakenStart.wait()
621
+ }
622
+ throw NativeClientError.notInitialized()
623
+ }
624
+ let status = await client.shutdownAfterFlush()
625
+ // The client ended its streams; what they still hold is not delivered after shutdown.
626
+ for forwarder in forwarders {
627
+ forwarder.cancel()
628
+ await forwarder.value
629
+ }
630
+ calls.rejectAll(.notInitialized("the client was shut down"))
631
+ await overtakenStart?.wait()
632
+ return status
633
+ }
634
+
635
+ func setEventListener(_ listener: @escaping @Sendable (NativeClientCoreEvent) -> Void) {
636
+ lock.withLock { self.listener = listener }
637
+ }
638
+
639
+ func removeEventListener() {
640
+ lock.withLock { listener = nil }
641
+ }
642
+
643
+ private func forward(_ event: VoidhashClientEvent) {
644
+ deliver(VoidhashNativeClientCore.coreEvent(event))
645
+ }
646
+
647
+ private func deliver(_ event: NativeClientCoreEvent) {
648
+ lock.withLock { listener }?(event)
649
+ }
650
+
651
+ /// The started client, or `NOT_INITIALIZED` before `start()`, after `shutdown()` and once a
652
+ /// newer instance over the same storage retired it.
653
+ private func started() throws -> VoidhashClient {
654
+ guard let client = lock.withLock({ client }), !client.isRetired else {
655
+ throw NativeClientError.notInitialized()
656
+ }
657
+ return client
658
+ }
659
+
660
+ /// Runs `operation` on the started client, settled by `shutdown()` at the latest.
661
+ private func call<Value: Sendable>(
662
+ _ operation: @escaping @Sendable (VoidhashClient) async throws -> Value
663
+ ) async throws -> Value {
664
+ let client = try started()
665
+ do {
666
+ return try await calls.run { try await operation(client) }
667
+ } catch {
668
+ throw NativeClientError.from(error)
669
+ }
670
+ }
671
+
672
+ // MARK: - Identity and person
673
+
674
+ func getDistinctId() async throws -> String {
675
+ return try await call { client in await client.getDistinctId() }
676
+ }
677
+
678
+ /// Identity changes and person writes run in call order: an un-awaited `identify(u)` then
679
+ /// `setPersonAttributes(x)` writes `x` for `u`, and `setPersonAttributes(x)` then `reset()`
680
+ /// writes it for the identity being reset. A call therefore waits for the ones before it to
681
+ /// settle: a `setPersonAttributes(x)` behind an un-awaited `identify(u)` resolves only once
682
+ /// that identify did, which may take its whole wait on Voidhash for the profile write.
683
+ func identify(externalUserId: String, email: String?, name: String?)
684
+ -> Task<NativeIdentifyPayload, any Error>
685
+ {
686
+ return ordered.submit {
687
+ try await self.performIdentify(externalUserId: externalUserId, email: email, name: name)
688
+ }
689
+ }
690
+
691
+ func reset() -> Task<VoidhashIdentityChange, any Error> {
692
+ return ordered.submit { try await self.performReset() }
693
+ }
694
+
695
+ func signOut() -> Task<VoidhashIdentityChange, any Error> {
696
+ return ordered.submit { try await self.performSignOut() }
697
+ }
698
+
699
+ func setPersonAttributes(_ attributesJson: String) -> Task<Void, any Error> {
700
+ return ordered.submit { try await self.performSetPersonAttributes(attributesJson) }
701
+ }
702
+
703
+ /// Puts the end user in a group, in call order with identity changes: a `group` made right
704
+ /// after an un-awaited `reset()` belongs to the identity the reset switched to.
705
+ func group(type: String, key: String, propertiesJson: String?) -> Task<Void, any Error> {
706
+ return ordered.submit {
707
+ if let reason = IdentityStore.invalidGroupReason(type: type, key: key) {
708
+ throw NativeClientError.invalidArgument(reason)
709
+ }
710
+ let properties = try propertiesJson.map { json in
711
+ guard let properties = VoidhashNativeClientCore.object(json) else {
712
+ throw NativeClientError.invalidArgument("group properties must be a JSON object")
713
+ }
714
+ return properties
715
+ }
716
+ try await self.call { client in
717
+ await client.group(type: type, key: key, properties: properties)
718
+ }
719
+ }
720
+ }
721
+
722
+ /// Replaces every group the end user is in, in call order with identity changes.
723
+ /// `groupsJson` is an object from group type to `{ id, properties? }`.
724
+ func setGroups(groupsJson: String) -> Task<Void, any Error> {
725
+ return ordered.submit {
726
+ guard let document = VoidhashNativeClientCore.object(groupsJson) else {
727
+ throw NativeClientError.invalidArgument("groups must be a JSON object")
728
+ }
729
+ let groups = try document.mapValues { value in
730
+ guard case .object(let group) = value, case .string(let id)? = group["id"] else {
731
+ throw NativeClientError.invalidArgument("a group must be an object with a string id")
732
+ }
733
+ guard case .object(let properties)? = group["properties"] else {
734
+ return VoidhashGroup(id: id)
735
+ }
736
+ return VoidhashGroup(id: id, properties: properties)
737
+ }
738
+ try await self.call { client in await client.setGroups(groups) }
739
+ }
740
+ }
741
+
742
+ func resetGroups() -> Task<Void, any Error> {
743
+ return ordered.submit { try await self.call { client in await client.resetGroups() } }
744
+ }
745
+
746
+ /// The groups the end user belongs to, read synchronously; empty before `start()`.
747
+ func getGroups() -> [String: String] {
748
+ return lock.withLock { client }?.currentGroups ?? [:]
749
+ }
750
+
751
+ func setPersonAttributesState(_ attributesJson: String)
752
+ -> Task<NativePersonWritePayload, any Error>
753
+ {
754
+ return ordered.submit { try await self.performSetPersonAttributesState(attributesJson) }
755
+ }
756
+
757
+ private func performIdentify(externalUserId: String, email: String?, name: String?)
758
+ async throws -> NativeIdentifyPayload
759
+ {
760
+ return try await call { client in
761
+ let result = try await client.identifyState(
762
+ externalUserId: externalUserId, email: email, name: name)
763
+ guard let identity = client.currentIdentity else {
764
+ throw NativeClientError.notInitialized()
765
+ }
766
+ return NativeIdentifyPayload(
767
+ identity: identity, status: result.status,
768
+ personJson: VoidhashNativeClientCore.json(result.person))
769
+ }
770
+ }
771
+
772
+ private func performReset() async throws -> VoidhashIdentityChange {
773
+ return try await call { client in
774
+ let wasSignedIn =
775
+ client.currentIdentity.map { !Voidhash.isAnonymousDistinctId($0.distinctId) } ?? false
776
+ await client.reset()
777
+ let identity = try VoidhashNativeClientCore.identity(of: client)
778
+ // Someone signed in was signed out: what they left queued goes out now, as after
779
+ // `signOut()`. A fresh visitor in place of an anonymous one sends nothing.
780
+ if wasSignedIn {
781
+ _ = await client.flush()
782
+ }
783
+ return identity
784
+ }
785
+ }
786
+
787
+ private func performSignOut() async throws -> VoidhashIdentityChange {
788
+ return try await call { client in
789
+ let previous = client.currentIdentity?.distinctId
790
+ await client.signOut()
791
+ let identity = try VoidhashNativeClientCore.identity(of: client)
792
+ // The identity switched at once; what the person signing out left queued goes out
793
+ // now. Nobody signed in means nothing switched, and nothing is sent.
794
+ if identity.distinctId != previous {
795
+ _ = await client.flush()
796
+ }
797
+ return identity
798
+ }
799
+ }
800
+
801
+ private func performSetPersonAttributes(_ attributesJson: String) async throws {
802
+ let attributes = try VoidhashNativeClientCore.attributes(attributesJson)
803
+ // On disk, in call order, before the promise resolves; only the delivery is left to the
804
+ // queue.
805
+ try await call { client in try await client.queuePersonAttributes(attributes) }
806
+ }
807
+
808
+ private func performSetPersonAttributesState(_ attributesJson: String) async throws
809
+ -> NativePersonWritePayload
810
+ {
811
+ let attributes = try VoidhashNativeClientCore.attributes(attributesJson)
812
+ return try await call { client in
813
+ let result = try await client.setPersonAttributesState(attributes)
814
+ return NativePersonWritePayload(
815
+ status: result.status, personJson: VoidhashNativeClientCore.json(result.person))
816
+ }
817
+ }
818
+
819
+ func getPersonState(forceFetch: Bool) async throws -> NativePersonPayload {
820
+ return try await call { client in
821
+ VoidhashNativeClientCore.personPayload(
822
+ try await client.hostPersonState(forceFetch: forceFetch))
823
+ }
824
+ }
825
+
826
+ func resetPersonCache() async throws {
827
+ try await call { client in await client.resetPersonCache() }
828
+ }
829
+
830
+ // MARK: - Flags, paywalls and products
831
+
832
+ func getFeatureFlags(_ flagKeys: [String]?) async throws -> NativeFlagsPayload {
833
+ return try await call { client in
834
+ VoidhashNativeClientCore.flagsPayload(try await client.hostFeatureFlags(flagKeys))
835
+ }
836
+ }
837
+
838
+ func getPaywall(location: String) async throws -> String {
839
+ return try await call { client in
840
+ let state = try await client.getPaywallState(location: location)
841
+ if state.value == nil, state.isStale, state.isExpired {
842
+ throw NativeClientError(
843
+ code: "PAYWALL_UNAVAILABLE",
844
+ detail: "nothing is cached for \"\(location)\" and Voidhash cannot be reached")
845
+ }
846
+ return VoidhashNativeClientCore.json(state.value) ?? "null"
847
+ }
848
+ }
849
+
850
+ /// Every product the App Store sells, sorted by slug, held for `purchase()`.
851
+ func getProducts() async throws -> [VoidhashProduct] {
852
+ let load = lock.withLock { () -> Int in
853
+ productsLoads += 1
854
+ return productsLoads
855
+ }
856
+ return try await call { client in
857
+ let products = try await client.getProducts()
858
+ self.lock.withLock {
859
+ // A load that a shutdown, a later load or a purchase overtook is not held: it
860
+ // belongs to a client no longer started, or answers for outdated offers.
861
+ guard self.client === client, self.productsLoads == load else { return }
862
+ self.heldProducts = Dictionary(
863
+ products.map { ($0.slug, $0) }, uniquingKeysWith: { _, last in last })
864
+ }
865
+ return products
866
+ }
867
+ }
868
+
869
+ /// Forgets the products held, and any load running, after a purchase or a restore: what the
870
+ /// end user bought can change the offers they are eligible for. Until the facade loads them
871
+ /// again, `purchase()` asks the App Store for the product it buys.
872
+ private func dropHeldProducts() {
873
+ lock.withLock {
874
+ heldProducts = [:]
875
+ productsLoads += 1
876
+ }
877
+ }
878
+
879
+ /// The product `slug` names: the one the last `getProducts()` answered, else the App Store's
880
+ /// answer now. `nil` when Studio has no such product or the App Store does not sell it.
881
+ private func product(_ slug: String, of client: VoidhashClient) async throws
882
+ -> VoidhashProduct?
883
+ {
884
+ if let held = lock.withLock({ heldProducts[slug] }) {
885
+ return held
886
+ }
887
+ return try await client.getProducts(slugs: [slug]).first ?? nil
888
+ }
889
+
890
+ // MARK: - Purchases
891
+
892
+ /// Buys the product `productSlug` names. A cancelled sheet and a pending payment are
893
+ /// results; a client that buys nothing (retired, or before the first unlock) rejects
894
+ /// `NOT_INITIALIZED`. An offer the App Store refused as the user is not eligible for it
895
+ /// rejects `INELIGIBLE_FOR_OFFER`, as on Android, and outdates the products held.
896
+ func purchase(productSlug: String, request: NativePurchaseRequest) async throws
897
+ -> VoidhashPurchaseResult
898
+ {
899
+ return try await call { client in
900
+ guard let product = try await self.product(productSlug, of: client) else {
901
+ throw NativeClientError.invalidArgument(
902
+ "no product with the slug \"\(productSlug)\" is sold in the App Store")
903
+ }
904
+ let options = try VoidhashNativeClientCore.purchaseOptions(request, for: product)
905
+ let result: VoidhashPurchaseResult
906
+ do {
907
+ result = try await client.purchase(product, options: options)
908
+ } catch let error as VoidhashStoreError where error.reason == .ineligibleForOffer {
909
+ self.dropHeldProducts()
910
+ throw NativeClientError(code: "INELIGIBLE_FOR_OFFER", detail: error.message)
911
+ }
912
+ if result == .disabled {
913
+ throw NativeClientError.notInitialized(
914
+ "the client is disabled or was replaced; nothing was bought")
915
+ }
916
+ if case .purchased = result {
917
+ self.dropHeldProducts()
918
+ }
919
+ return result
920
+ }
921
+ }
922
+
923
+ /// The native purchase options of `request` for `product`. An introductory kind means the
924
+ /// product's current intro offer, whatever the id says: the App Store's has none.
925
+ ///
926
+ /// - Throws: `OFFER_UNAVAILABLE` for an offer the product does not have for this user, and
927
+ /// `INVALID_ARGUMENT` for a quantity that is not a whole number.
928
+ static func purchaseOptions(_ request: NativePurchaseRequest, for product: VoidhashProduct)
929
+ throws -> VoidhashPurchaseOptions
930
+ {
931
+ guard let quantity = Int(exactly: request.quantity) else {
932
+ throw NativeClientError.invalidArgument("\(request.quantity) is not a quantity to buy")
933
+ }
934
+ let offer: VoidhashOfferSelection
935
+ switch request.offer {
936
+ case .automatic:
937
+ offer = .automatic
938
+ case .regularPrice:
939
+ offer = .none
940
+ case .offer(_, kind: .introductory?):
941
+ guard let introOffer = product.subscription?.introOffer else {
942
+ throw VoidhashStoreError.offerUnavailable(
943
+ "\(product.slug) has no introductory offer for this user")
944
+ }
945
+ offer = .offer(introOffer)
946
+ case .offer(let id, kind: let kind?):
947
+ let available = product.offers + [product.subscription?.introOffer].compactMap { $0 }
948
+ guard let match = available.first(where: { $0.id == id && $0.kind == kind }) else {
949
+ throw VoidhashStoreError.offerUnavailable(
950
+ "\(product.slug) has no \(kind.rawValue) offer \"\(id)\" for this user")
951
+ }
952
+ offer = .offer(match)
953
+ case .offer(let id, kind: nil):
954
+ offer = .id(id)
955
+ }
956
+ return VoidhashPurchaseOptions(
957
+ offer: offer, quantity: quantity,
958
+ appStore: VoidhashPurchaseOptions.AppStore(
959
+ simulatesAskToBuyInSandbox: request.simulatesAskToBuyInSandbox))
960
+ }
961
+
962
+ /// Restores purchases and answers the person the restore refreshed, as a cache-first read
963
+ /// answers it, as on Android: with the freshness it really has (`fresh` only when the refresh
964
+ /// after the restore got an answer) and the generation it is read under.
965
+ func restorePurchases() async throws -> NativePersonPayload {
966
+ return try await call { client in
967
+ _ = try await client.restorePurchases()
968
+ self.dropHeldProducts()
969
+ return VoidhashNativeClientCore.personPayload(
970
+ try await client.hostPersonState(forceFetch: false))
971
+ }
972
+ }
973
+
974
+ func syncPurchases() async throws {
975
+ try await call { client in try await client.syncPurchases() }
976
+ }
977
+
978
+ func reportTransaction(_ transaction: NativeReportedTransactionPayload, isRestore: Bool)
979
+ async throws
980
+ {
981
+ guard transaction.platform == "ios" else {
982
+ throw NativeClientError(
983
+ code: "UNSUPPORTED_PLATFORM",
984
+ detail: "only App Store transactions can be reported on iOS")
985
+ }
986
+ guard let transactionId = transaction.transactionId,
987
+ !transactionId.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
988
+ else {
989
+ throw NativeClientError.invalidArgument("an App Store transaction id is required")
990
+ }
991
+ try await call { client in
992
+ try await client.reportTransaction(
993
+ transactionId: transactionId, signedTransaction: transaction.signedTransaction,
994
+ isRestore: isRestore)
995
+ }
996
+ }
997
+
998
+ // MARK: - Store actions
999
+
1000
+ /// Opens subscription management on the group of the product `productSlug` names; on no
1001
+ /// group when it names none, or one the App Store does not sell.
1002
+ func showManageSubscriptions(productSlug: String?) async throws {
1003
+ try await call { client in
1004
+ var product: VoidhashProduct?
1005
+ if let productSlug {
1006
+ // Only picks the group the sheet opens on: without one it opens on them all.
1007
+ product = try? await self.product(productSlug, of: client)
1008
+ }
1009
+ try await client.showManageSubscriptions(product: product)
1010
+ }
1011
+ }
1012
+
1013
+ /// Shows the offer code sheet. A transaction it hands back is synced and arrives as a
1014
+ /// `transaction` event, as on OS versions where it arrives through the store observer.
1015
+ func presentCodeRedemption() async throws {
1016
+ try await call { client in _ = try await client.presentCodeRedemption() }
1017
+ }
1018
+
1019
+ func getStorefront() async throws -> VoidhashStorefront? {
1020
+ return try await call { client in await client.getStorefront() }
1021
+ }
1022
+
1023
+ func canMakePayments() async throws -> Bool {
1024
+ return try await call { client in await client.canMakePayments() }
1025
+ }
1026
+
1027
+ // MARK: - App Store
1028
+
1029
+ func appStoreBeginRefundRequest(transactionId: String) async throws
1030
+ -> VoidhashRefundRequestStatus
1031
+ {
1032
+ return try await call { client in
1033
+ try await client.appStore.beginRefundRequest(transactionId: transactionId)
1034
+ }
1035
+ }
1036
+
1037
+ /// The group's statuses, the current person's first. One whose renewal info StoreKit could
1038
+ /// not verify is left out: the contract carries verified renewal info only.
1039
+ func appStoreSubscriptionStatus(groupId: String) async throws
1040
+ -> [VoidhashAppStoreSubscriptionStatus]
1041
+ {
1042
+ return try await call { client in
1043
+ try await client.appStore.subscriptionStatus(groupId: groupId).filter {
1044
+ $0.renewalInfo != nil
1045
+ }
1046
+ }
1047
+ }
1048
+
1049
+ func appStoreCurrentEntitlements() async throws -> [VoidhashTransaction] {
1050
+ return try await call { client in try await client.appStore.currentEntitlements() }
1051
+ }
1052
+
1053
+ /// The app transaction as the JSON the facade reads it from.
1054
+ func appStoreAppTransaction() async throws -> String {
1055
+ return try await call { client in
1056
+ NativeStoreJson.appTransaction(try await client.appStore.appTransaction())
1057
+ }
1058
+ }
1059
+
1060
+ // MARK: - Configuration at runtime
1061
+
1062
+ /// Records the consent. Before `start()` it becomes the chosen consent `start()` applies,
1063
+ /// and one other than `granted` discards the events taken meanwhile; it is stored once the
1064
+ /// client starts, so the answer is `false` then.
1065
+ func setAnalyticsConsent(_ consent: AnalyticsConsent) async throws -> Bool {
1066
+ let startedClient = lock.withLock { () -> VoidhashClient? in
1067
+ guard let client else {
1068
+ configuration?.chosenAnalyticsConsent = consent
1069
+ // A denial discards what was captured so far, as it does on a running client.
1070
+ if consent == .denied {
1071
+ heldCaptures = []
1072
+ droppedCaptures = 0
1073
+ }
1074
+ return nil
1075
+ }
1076
+ return client
1077
+ }
1078
+ guard startedClient != nil else {
1079
+ return false
1080
+ }
1081
+ return try await call { client in
1082
+ await client.setAnalyticsConsent(consent)
1083
+ return true
1084
+ }
1085
+ }
1086
+
1087
+ func getAnalyticsConsent() -> AnalyticsConsent {
1088
+ if let client = lock.withLock({ client }) {
1089
+ return client.analyticsConsent
1090
+ }
1091
+ let configuration = lock.withLock { self.configuration }
1092
+ return configuration?.chosenAnalyticsConsent ?? configuration?.analyticsConsent
1093
+ ?? .granted
1094
+ }
1095
+
1096
+ func setReadOnly(_ readOnly: Bool) {
1097
+ if let client = lock.withLock({ client }) {
1098
+ client.setReadOnly(readOnly)
1099
+ }
1100
+ lock.withLock { configuration?.readOnly = readOnly }
1101
+ }
1102
+
1103
+ func isReadOnly() -> Bool {
1104
+ if let client = lock.withLock({ client }) {
1105
+ return client.isReadOnly
1106
+ }
1107
+ return lock.withLock { configuration?.readOnly ?? false }
1108
+ }
1109
+
1110
+ // MARK: - Analytics
1111
+
1112
+ /// Queues an event synchronously; never throws. One whose properties are not a JSON object
1113
+ /// is dropped and reported. `capturedAt` is the time of an event the facade held back, in
1114
+ /// milliseconds since the epoch; the time of this call without it.
1115
+ func capture(_ eventName: String, propertiesJson: String, capturedAt: Double? = nil) {
1116
+ guard let properties = VoidhashNativeClientCore.object(propertiesJson) else {
1117
+ deliver(
1118
+ .diagnostic(
1119
+ VoidhashDiagnostic(
1120
+ kind: .eviction, code: "ANALYTICS_EVENT_DROPPED", operation: "capture",
1121
+ message: "Dropped \"\(eventName)\": its properties are not a JSON object")))
1122
+ return
1123
+ }
1124
+ let capturedAt = capturedAt ?? now()
1125
+ let target = lock.withLock { () -> VoidhashClient? in
1126
+ guard let client = client ?? startingClient else {
1127
+ heldCaptures.append(
1128
+ HeldCapture(name: eventName, properties: properties, capturedAt: capturedAt))
1129
+ if heldCaptures.count > VoidhashNativeClientCore.maxCapturesBeforeStart {
1130
+ heldCaptures.removeFirst()
1131
+ droppedCaptures += 1
1132
+ }
1133
+ return nil
1134
+ }
1135
+ return client
1136
+ }
1137
+ target?.captureNow(eventName, properties: properties, capturedAt: capturedAt)
1138
+ }
1139
+
1140
+ /// Queues a `$screen` view the facade's screen tracker built, with its properties as they are.
1141
+ func screen(_ name: String, propertiesJson: String, capturedAt: Double? = nil) {
1142
+ guard lock.withLock({ configuration?.screenTrackingEnabled ?? true }) else {
1143
+ return
1144
+ }
1145
+ capture("$screen", propertiesJson: propertiesJson, capturedAt: capturedAt)
1146
+ }
1147
+
1148
+ func flush() async throws -> FlushStatus {
1149
+ return try await call { client in await client.flush() }
1150
+ }
1151
+
1152
+ func getSessionId() -> String {
1153
+ return lock.withLock { client }?.currentSessionId() ?? ""
1154
+ }
1155
+
1156
+ // MARK: - Flows
1157
+
1158
+ /// Presents the flow at `location` and resolves with how it ended, as JSON: an outcome with
1159
+ /// its outputs, or the failure that kept the flow from being shown. A flow that could not be
1160
+ /// shown is part of that answer, never a thrown error.
1161
+ ///
1162
+ /// - Parameters:
1163
+ /// - revision: The interface revision the app was built against; `nil` for the one the
1164
+ /// configuration names for the location.
1165
+ /// - inputJson: The app's inputs as a JSON object of strings, numbers and booleans.
1166
+ /// - actions: The app actions JavaScript handles.
1167
+ /// - onAction: Runs one of `actions` in JavaScript: takes its name and its arguments as a
1168
+ /// JSON object, and returns the reply as a JSON object or throws.
1169
+ func presentFlow(
1170
+ location: String, revision: Int?, inputJson: String, actions: [String],
1171
+ onAction: @escaping NativeFlowAction
1172
+ ) async throws -> String {
1173
+ return try await call { client in
1174
+ do {
1175
+ let result = try await client.presentFlow(
1176
+ location: location, revision: revision,
1177
+ input: VoidhashNativeClientCore.flowValues(inputJson) ?? [:],
1178
+ actions: VoidhashNativeClientCore.flowActionHandlers(
1179
+ actions, onAction: onAction))
1180
+ // A flow that ended in a purchase or a restore outdates the products held.
1181
+ if result.outcome == FlowResult.purchased || result.outcome == FlowResult.restored {
1182
+ self.dropHeldProducts()
1183
+ }
1184
+ return VoidhashNativeClientCore.flowResultJson(result)
1185
+ } catch let error as FlowError {
1186
+ return VoidhashNativeClientCore.flowFailureJson(error)
1187
+ }
1188
+ }
1189
+ }
1190
+
1191
+ /// Changes inputs of the flow on screen; `valuesJson` is a JSON object of strings, numbers
1192
+ /// and booleans.
1193
+ func updateFlowInput(valuesJson: String) async throws {
1194
+ guard let values = VoidhashNativeClientCore.flowValues(valuesJson) else {
1195
+ throw NativeClientError(
1196
+ code: "INVALID_ARGUMENT", detail: "flow inputs must be a JSON object")
1197
+ }
1198
+ try await call { client in await client.updateFlowInput(values) }
1199
+ }
1200
+
1201
+ func dismissFlow() async throws {
1202
+ try await call { client in await client.dismissFlow() }
1203
+ }
1204
+
1205
+ // MARK: - Mapping
1206
+
1207
+ /// How a presentation ended, as the JSON the facade reads a flow result from.
1208
+ static func flowResultJson(_ result: FlowResult) -> String {
1209
+ return json(NativeFlowResultPayload(result))
1210
+ ?? flowFailureJson(.presentationFailed("the flow's result could not be encoded"))
1211
+ }
1212
+
1213
+ /// Why a flow could not be shown, as the JSON the facade reads a flow failure from.
1214
+ static func flowFailureJson(_ error: FlowError) -> String {
1215
+ let failure: JSONValue = .object([
1216
+ "failure": .object([
1217
+ "code": .string(flowErrorCode(error)), "message": .string(error.description),
1218
+ ])
1219
+ ])
1220
+ return json(failure)
1221
+ ?? #"{"failure":{"code":"FLOW_PRESENTATION_FAILED","message":"FLOW_PRESENTATION_FAILED: unencodable"}}"#
1222
+ }
1223
+
1224
+ /// The strings, numbers, booleans and lists of strings of a JSON object, by name; `nil` when
1225
+ /// `json` is not an object. Entries of any other type, and arrays holding anything but
1226
+ /// strings, are left out.
1227
+ static func flowValues(_ json: String) -> [String: FlowValue]? {
1228
+ return object(json)?.compactMapValues { value in
1229
+ switch value {
1230
+ case .string(let string): return .string(string)
1231
+ case .number(let number): return .number(number)
1232
+ case .bool(let bool): return .bool(bool)
1233
+ case .array(let items):
1234
+ let strings = items.compactMap { item -> String? in
1235
+ guard case .string(let string) = item else { return nil }
1236
+ return string
1237
+ }
1238
+ return strings.count == items.count ? .list(strings) : nil
1239
+ case .null, .object: return nil
1240
+ }
1241
+ }
1242
+ }
1243
+
1244
+ /// A handler per action JavaScript handles, each running `onAction` with the action's name
1245
+ /// and its arguments as JSON, and reading the reply back from JSON.
1246
+ static func flowActionHandlers(_ actions: [String], onAction: @escaping NativeFlowAction)
1247
+ -> [String: FlowActionHandler]
1248
+ {
1249
+ var handlers: [String: FlowActionHandler] = [:]
1250
+ for name in actions {
1251
+ handlers[name] = { arguments in
1252
+ guard let argumentsJson = json(arguments) else {
1253
+ throw NativeClientError(
1254
+ code: "INVALID_ARGUMENT",
1255
+ detail: "the arguments of \"\(name)\" could not be encoded")
1256
+ }
1257
+ guard let reply = flowValues(try await onAction(name, argumentsJson)) else {
1258
+ throw NativeClientError(
1259
+ code: "INVALID_ARGUMENT",
1260
+ detail: "the handler of \"\(name)\" must resolve with an object")
1261
+ }
1262
+ return reply
1263
+ }
1264
+ }
1265
+ return handlers
1266
+ }
1267
+
1268
+ static func flowErrorCode(_ error: FlowError) -> String {
1269
+ switch error {
1270
+ case .disabled: return "FLOW_DISABLED"
1271
+ case .notAssigned: return "FLOW_NOT_ASSIGNED"
1272
+ case .unavailable: return "FLOW_UNAVAILABLE"
1273
+ case .rendererMissing: return "FLOW_RENDERER_MISSING"
1274
+ case .unsupportedPackage: return "FLOW_UNSUPPORTED_PACKAGE"
1275
+ case .presentationFailed: return "FLOW_PRESENTATION_FAILED"
1276
+ }
1277
+ }
1278
+
1279
+ /// The contract's name for the operation a diagnostic comes from: a products load is named
1280
+ /// after the facade method that makes it, `getProducts`, as on Android.
1281
+ static func diagnosticOperation(_ operation: String) -> String {
1282
+ return operation == "products.load" ? "getProducts" : operation
1283
+ }
1284
+
1285
+ /// The contract's name for a diagnostic kind. The SDK's `store` kind (a product the store
1286
+ /// did not return, or sells otherwise than configured) is the contract's `configuration`.
1287
+ static func diagnosticKind(_ kind: VoidhashDiagnosticKind) -> String {
1288
+ switch kind {
1289
+ case .transport: return "transport"
1290
+ case .eviction: return "eviction"
1291
+ case .breaker: return "breaker"
1292
+ case .auth: return "auth"
1293
+ case .cache: return "cache"
1294
+ case .consent: return "consent"
1295
+ case .store: return "configuration"
1296
+ }
1297
+ }
1298
+
1299
+ private static func identity(of client: VoidhashClient) throws -> VoidhashIdentityChange {
1300
+ guard let identity = client.currentIdentity else {
1301
+ throw NativeClientError.notInitialized()
1302
+ }
1303
+ return identity
1304
+ }
1305
+
1306
+ static func coreEvent(_ event: VoidhashClientEvent) -> NativeClientCoreEvent {
1307
+ switch event {
1308
+ case .identity(let change):
1309
+ return .identity(change)
1310
+ case .person(let answer):
1311
+ return .person(personPayload(answer))
1312
+ case .flags(let answer):
1313
+ return .flags(flagsPayload(answer))
1314
+ case .schema(let json):
1315
+ return .schema(json)
1316
+ case .consent(let consent):
1317
+ return .consent(consent)
1318
+ case .diagnostic(let diagnostic):
1319
+ return .diagnostic(diagnostic)
1320
+ }
1321
+ }
1322
+
1323
+ static func personPayload(_ answer: VoidhashPersonAnswer) -> NativePersonPayload {
1324
+ return NativePersonPayload(
1325
+ distinctId: answer.distinctId, generation: answer.generation,
1326
+ personJson: json(answer.state.value), isStale: answer.state.isStale,
1327
+ isExpired: answer.state.isExpired, reason: answer.state.reason)
1328
+ }
1329
+
1330
+ static func flagsPayload(_ answer: VoidhashFlagsAnswer) -> NativeFlagsPayload {
1331
+ return NativeFlagsPayload(
1332
+ distinctId: answer.distinctId, generation: answer.generation, flagKeys: answer.keys,
1333
+ flags: answer.state.value.map { flag in
1334
+ NativeFlagPayload(
1335
+ key: flag.key, enabled: flag.enabled, variantKey: flag.variantKey,
1336
+ payloadJson: flag.payload.flatMap { json($0) })
1337
+ },
1338
+ isStale: answer.state.isStale)
1339
+ }
1340
+
1341
+ static func json<Value: Encodable>(_ value: Value?) -> String? {
1342
+ guard let value, let data = try? JSONEncoder().encode(value) else {
1343
+ return nil
1344
+ }
1345
+ return String(decoding: data, as: UTF8.self)
1346
+ }
1347
+
1348
+ /// A JSON object string as values the SDK takes; `nil` for anything else.
1349
+ static func object(_ json: String) -> [String: JSONValue]? {
1350
+ guard let value = try? JSONDecoder().decode(JSONValue.self, from: Data(json.utf8)),
1351
+ case .object(let object) = value
1352
+ else {
1353
+ return nil
1354
+ }
1355
+ return object
1356
+ }
1357
+
1358
+ /// Person attributes as the SDK takes them: a JSON object of flat values.
1359
+ static func attributes(_ json: String) throws -> [String: JSONValue] {
1360
+ guard let attributes = object(json) else {
1361
+ throw NativeClientError.invalidArgument("person attributes must be a JSON object")
1362
+ }
1363
+ let nested = attributes.filter { _, value in
1364
+ if case .array = value { return true }
1365
+ if case .object = value { return true }
1366
+ return false
1367
+ }.keys.sorted()
1368
+ guard nested.isEmpty else {
1369
+ throw NativeClientError.invalidArgument(
1370
+ "person attributes must be flat values; nested: \(nested.joined(separator: ", "))")
1371
+ }
1372
+ return attributes
1373
+ }
1374
+ }
1375
+
1376
+ /// The app's own handlers of the permissions flows ask for, which JavaScript cannot supply:
1377
+ /// register them in native code before the JavaScript client starts (in the app delegate's
1378
+ /// `application(_:didFinishLaunchingWithOptions:)`), by the permission's name. A client started
1379
+ /// afterwards uses them; see ``FlowPermissionHandler`` for when the SDK calls one. Tracking
1380
+ /// needs one: the SDK has no tracking prompt of its own.
1381
+ ///
1382
+ /// ```swift
1383
+ /// VoidhashFlowPermissionHandlers.register(
1384
+ /// FlowCapability.tracking.rawValue,
1385
+ /// FlowPermissionHandler(status: { … }, request: { … }))
1386
+ /// ```
1387
+ public enum VoidhashFlowPermissionHandlers {
1388
+ private static let lock = NSLock()
1389
+ nonisolated(unsafe) private static var handlers: [String: FlowPermissionHandler] = [:]
1390
+
1391
+ /// Uses `handler` for `permission` in the clients started from now on.
1392
+ public static func register(_ permission: String, _ handler: FlowPermissionHandler) {
1393
+ lock.withLock { handlers[permission] = handler }
1394
+ }
1395
+
1396
+ static var registered: [String: FlowPermissionHandler] {
1397
+ lock.withLock { handlers }
1398
+ }
1399
+ }
1400
+