react-native-nitro-amplitude 0.1.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.
- package/.watchmanconfig +6 -0
- package/LICENSE +21 -0
- package/README.md +139 -0
- package/android/CMakeLists.txt +34 -0
- package/android/build.gradle +85 -0
- package/android/consumer-rules.pro +35 -0
- package/android/gradle.properties +4 -0
- package/android/src/main/cpp/AndroidAmplitudeAdapterCpp.cpp +126 -0
- package/android/src/main/cpp/AndroidAmplitudeAdapterCpp.hpp +48 -0
- package/android/src/main/cpp/cpp-adapter.cpp +9 -0
- package/android/src/main/java/com/nitroamplitude/AndroidAmplitudeAdapter.kt +147 -0
- package/android/src/main/java/com/nitroamplitude/NitroAmplitudePackage.kt +24 -0
- package/app.plugin.js +36 -0
- package/cpp/bindings/HybridAmplitudeContext.cpp +83 -0
- package/cpp/bindings/HybridAmplitudeContext.hpp +29 -0
- package/cpp/bindings/HybridAmplitudeStorage.cpp +163 -0
- package/cpp/bindings/HybridAmplitudeStorage.hpp +38 -0
- package/cpp/bindings/HybridAmplitudeWorker.cpp +162 -0
- package/cpp/bindings/HybridAmplitudeWorker.hpp +74 -0
- package/cpp/core/NativeAmplitudeAdapter.hpp +44 -0
- package/ios/IOSAmplitudeAdapterCpp.hpp +37 -0
- package/ios/IOSAmplitudeAdapterCpp.mm +155 -0
- package/lib/commonjs/AmplitudeContext.nitro.js +6 -0
- package/lib/commonjs/AmplitudeContext.nitro.js.map +1 -0
- package/lib/commonjs/AmplitudeStorage.nitro.js +6 -0
- package/lib/commonjs/AmplitudeStorage.nitro.js.map +1 -0
- package/lib/commonjs/AmplitudeWorker.nitro.js +6 -0
- package/lib/commonjs/AmplitudeWorker.nitro.js.map +1 -0
- package/lib/commonjs/analytics/campaign/campaign-tracker.js +105 -0
- package/lib/commonjs/analytics/campaign/campaign-tracker.js.map +1 -0
- package/lib/commonjs/analytics/campaign/types.js +6 -0
- package/lib/commonjs/analytics/campaign/types.js.map +1 -0
- package/lib/commonjs/analytics/config.js +283 -0
- package/lib/commonjs/analytics/config.js.map +1 -0
- package/lib/commonjs/analytics/cookie-migration/index.js +59 -0
- package/lib/commonjs/analytics/cookie-migration/index.js.map +1 -0
- package/lib/commonjs/analytics/index.js +95 -0
- package/lib/commonjs/analytics/index.js.map +1 -0
- package/lib/commonjs/analytics/migration/remnant-data-migration.js +177 -0
- package/lib/commonjs/analytics/migration/remnant-data-migration.js.map +1 -0
- package/lib/commonjs/analytics/nitro-transport.js +31 -0
- package/lib/commonjs/analytics/nitro-transport.js.map +1 -0
- package/lib/commonjs/analytics/plugins/context.js +140 -0
- package/lib/commonjs/analytics/plugins/context.js.map +1 -0
- package/lib/commonjs/analytics/react-native-client.js +352 -0
- package/lib/commonjs/analytics/react-native-client.js.map +1 -0
- package/lib/commonjs/analytics/storage/local-storage.js +73 -0
- package/lib/commonjs/analytics/storage/local-storage.js.map +1 -0
- package/lib/commonjs/analytics/types.js +175 -0
- package/lib/commonjs/analytics/types.js.map +1 -0
- package/lib/commonjs/analytics/typings/browser-snippet.d.js +6 -0
- package/lib/commonjs/analytics/typings/browser-snippet.d.js.map +1 -0
- package/lib/commonjs/analytics/typings/ua-parser.d.js +2 -0
- package/lib/commonjs/analytics/typings/ua-parser.d.js.map +1 -0
- package/lib/commonjs/analytics/utils/platform.js +16 -0
- package/lib/commonjs/analytics/utils/platform.js.map +1 -0
- package/lib/commonjs/analytics/version.js +8 -0
- package/lib/commonjs/analytics/version.js.map +1 -0
- package/lib/commonjs/experiment/experimentClient.js +792 -0
- package/lib/commonjs/experiment/experimentClient.js.map +1 -0
- package/lib/commonjs/experiment/factory.js +77 -0
- package/lib/commonjs/experiment/factory.js.map +1 -0
- package/lib/commonjs/experiment/gen/version.js +9 -0
- package/lib/commonjs/experiment/gen/version.js.map +1 -0
- package/lib/commonjs/experiment/index.js +143 -0
- package/lib/commonjs/experiment/index.js.map +1 -0
- package/lib/commonjs/experiment/integration/NativeExperimentReactNativeClient.js +11 -0
- package/lib/commonjs/experiment/integration/NativeExperimentReactNativeClient.js.map +1 -0
- package/lib/commonjs/experiment/integration/connector.js +67 -0
- package/lib/commonjs/experiment/integration/connector.js.map +1 -0
- package/lib/commonjs/experiment/integration/default.js +92 -0
- package/lib/commonjs/experiment/integration/default.js.map +1 -0
- package/lib/commonjs/experiment/logger/ampLogger.js +80 -0
- package/lib/commonjs/experiment/logger/ampLogger.js.map +1 -0
- package/lib/commonjs/experiment/logger/consoleLogger.js +60 -0
- package/lib/commonjs/experiment/logger/consoleLogger.js.map +1 -0
- package/lib/commonjs/experiment/storage/cache.js +197 -0
- package/lib/commonjs/experiment/storage/cache.js.map +1 -0
- package/lib/commonjs/experiment/storage/local-storage.js +25 -0
- package/lib/commonjs/experiment/storage/local-storage.js.map +1 -0
- package/lib/commonjs/experiment/stubClient.js +46 -0
- package/lib/commonjs/experiment/stubClient.js.map +1 -0
- package/lib/commonjs/experiment/transport/http.js +72 -0
- package/lib/commonjs/experiment/transport/http.js.map +1 -0
- package/lib/commonjs/experiment/types/client.js +6 -0
- package/lib/commonjs/experiment/types/client.js.map +1 -0
- package/lib/commonjs/experiment/types/config.js +67 -0
- package/lib/commonjs/experiment/types/config.js.map +1 -0
- package/lib/commonjs/experiment/types/exposure.js +2 -0
- package/lib/commonjs/experiment/types/exposure.js.map +1 -0
- package/lib/commonjs/experiment/types/logger.js +42 -0
- package/lib/commonjs/experiment/types/logger.js.map +1 -0
- package/lib/commonjs/experiment/types/source.js +54 -0
- package/lib/commonjs/experiment/types/source.js.map +1 -0
- package/lib/commonjs/experiment/types/storage.js +2 -0
- package/lib/commonjs/experiment/types/storage.js.map +1 -0
- package/lib/commonjs/experiment/types/transport.js +2 -0
- package/lib/commonjs/experiment/types/transport.js.map +1 -0
- package/lib/commonjs/experiment/types/user.js +2 -0
- package/lib/commonjs/experiment/types/user.js.map +1 -0
- package/lib/commonjs/experiment/types/variant.js +2 -0
- package/lib/commonjs/experiment/types/variant.js.map +1 -0
- package/lib/commonjs/experiment/util/backoff.js +54 -0
- package/lib/commonjs/experiment/util/backoff.js.map +1 -0
- package/lib/commonjs/experiment/util/base64.js +23 -0
- package/lib/commonjs/experiment/util/base64.js.map +1 -0
- package/lib/commonjs/experiment/util/convert.js +78 -0
- package/lib/commonjs/experiment/util/convert.js.map +1 -0
- package/lib/commonjs/experiment/util/index.js +25 -0
- package/lib/commonjs/experiment/util/index.js.map +1 -0
- package/lib/commonjs/experiment/util/platform.js +16 -0
- package/lib/commonjs/experiment/util/platform.js.map +1 -0
- package/lib/commonjs/experiment/util/randomstring.js +16 -0
- package/lib/commonjs/experiment/util/randomstring.js.map +1 -0
- package/lib/commonjs/experiment/util/userSessionExposureTracker.js +40 -0
- package/lib/commonjs/experiment/util/userSessionExposureTracker.js.map +1 -0
- package/lib/commonjs/index.js +298 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/index.web.js +22 -0
- package/lib/commonjs/index.web.js.map +1 -0
- package/lib/commonjs/native/context.js +43 -0
- package/lib/commonjs/native/context.js.map +1 -0
- package/lib/commonjs/native/http.js +62 -0
- package/lib/commonjs/native/http.js.map +1 -0
- package/lib/commonjs/native/hybrid.js +31 -0
- package/lib/commonjs/native/hybrid.js.map +1 -0
- package/lib/commonjs/native/storage.js +93 -0
- package/lib/commonjs/native/storage.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/module/AmplitudeContext.nitro.js +4 -0
- package/lib/module/AmplitudeContext.nitro.js.map +1 -0
- package/lib/module/AmplitudeStorage.nitro.js +4 -0
- package/lib/module/AmplitudeStorage.nitro.js.map +1 -0
- package/lib/module/AmplitudeWorker.nitro.js +4 -0
- package/lib/module/AmplitudeWorker.nitro.js.map +1 -0
- package/lib/module/analytics/campaign/campaign-tracker.js +100 -0
- package/lib/module/analytics/campaign/campaign-tracker.js.map +1 -0
- package/lib/module/analytics/campaign/types.js +4 -0
- package/lib/module/analytics/campaign/types.js.map +1 -0
- package/lib/module/analytics/config.js +272 -0
- package/lib/module/analytics/config.js.map +1 -0
- package/lib/module/analytics/cookie-migration/index.js +51 -0
- package/lib/module/analytics/cookie-migration/index.js.map +1 -0
- package/lib/module/analytics/index.js +34 -0
- package/lib/module/analytics/index.js.map +1 -0
- package/lib/module/analytics/migration/remnant-data-migration.js +172 -0
- package/lib/module/analytics/migration/remnant-data-migration.js.map +1 -0
- package/lib/module/analytics/nitro-transport.js +26 -0
- package/lib/module/analytics/nitro-transport.js.map +1 -0
- package/lib/module/analytics/plugins/context.js +134 -0
- package/lib/module/analytics/plugins/context.js.map +1 -0
- package/lib/module/analytics/react-native-client.js +346 -0
- package/lib/module/analytics/react-native-client.js.map +1 -0
- package/lib/module/analytics/storage/local-storage.js +68 -0
- package/lib/module/analytics/storage/local-storage.js.map +1 -0
- package/lib/module/analytics/types.js +4 -0
- package/lib/module/analytics/types.js.map +1 -0
- package/lib/module/analytics/typings/browser-snippet.d.js +4 -0
- package/lib/module/analytics/typings/browser-snippet.d.js.map +1 -0
- package/lib/module/analytics/typings/ua-parser.d.js +2 -0
- package/lib/module/analytics/typings/ua-parser.d.js.map +1 -0
- package/lib/module/analytics/utils/platform.js +10 -0
- package/lib/module/analytics/utils/platform.js.map +1 -0
- package/lib/module/analytics/version.js +4 -0
- package/lib/module/analytics/version.js.map +1 -0
- package/lib/module/experiment/experimentClient.js +788 -0
- package/lib/module/experiment/experimentClient.js.map +1 -0
- package/lib/module/experiment/factory.js +73 -0
- package/lib/module/experiment/factory.js.map +1 -0
- package/lib/module/experiment/gen/version.js +5 -0
- package/lib/module/experiment/gen/version.js.map +1 -0
- package/lib/module/experiment/index.js +16 -0
- package/lib/module/experiment/index.js.map +1 -0
- package/lib/module/experiment/integration/NativeExperimentReactNativeClient.js +7 -0
- package/lib/module/experiment/integration/NativeExperimentReactNativeClient.js.map +1 -0
- package/lib/module/experiment/integration/connector.js +61 -0
- package/lib/module/experiment/integration/connector.js.map +1 -0
- package/lib/module/experiment/integration/default.js +87 -0
- package/lib/module/experiment/integration/default.js.map +1 -0
- package/lib/module/experiment/logger/ampLogger.js +76 -0
- package/lib/module/experiment/logger/ampLogger.js.map +1 -0
- package/lib/module/experiment/logger/consoleLogger.js +55 -0
- package/lib/module/experiment/logger/consoleLogger.js.map +1 -0
- package/lib/module/experiment/storage/cache.js +187 -0
- package/lib/module/experiment/storage/cache.js.map +1 -0
- package/lib/module/experiment/storage/local-storage.js +19 -0
- package/lib/module/experiment/storage/local-storage.js.map +1 -0
- package/lib/module/experiment/stubClient.js +41 -0
- package/lib/module/experiment/stubClient.js.map +1 -0
- package/lib/module/experiment/transport/http.js +66 -0
- package/lib/module/experiment/transport/http.js.map +1 -0
- package/lib/module/experiment/types/client.js +4 -0
- package/lib/module/experiment/types/client.js.map +1 -0
- package/lib/module/experiment/types/config.js +64 -0
- package/lib/module/experiment/types/config.js.map +1 -0
- package/lib/module/experiment/types/exposure.js +2 -0
- package/lib/module/experiment/types/exposure.js.map +1 -0
- package/lib/module/experiment/types/logger.js +39 -0
- package/lib/module/experiment/types/logger.js.map +1 -0
- package/lib/module/experiment/types/source.js +51 -0
- package/lib/module/experiment/types/source.js.map +1 -0
- package/lib/module/experiment/types/storage.js +2 -0
- package/lib/module/experiment/types/storage.js.map +1 -0
- package/lib/module/experiment/types/transport.js +2 -0
- package/lib/module/experiment/types/transport.js.map +1 -0
- package/lib/module/experiment/types/user.js +2 -0
- package/lib/module/experiment/types/user.js.map +1 -0
- package/lib/module/experiment/types/variant.js +2 -0
- package/lib/module/experiment/types/variant.js.map +1 -0
- package/lib/module/experiment/util/backoff.js +49 -0
- package/lib/module/experiment/util/backoff.js.map +1 -0
- package/lib/module/experiment/util/base64.js +16 -0
- package/lib/module/experiment/util/base64.js.map +1 -0
- package/lib/module/experiment/util/convert.js +71 -0
- package/lib/module/experiment/util/convert.js.map +1 -0
- package/lib/module/experiment/util/index.js +17 -0
- package/lib/module/experiment/util/index.js.map +1 -0
- package/lib/module/experiment/util/platform.js +10 -0
- package/lib/module/experiment/util/platform.js.map +1 -0
- package/lib/module/experiment/util/randomstring.js +11 -0
- package/lib/module/experiment/util/randomstring.js.map +1 -0
- package/lib/module/experiment/util/userSessionExposureTracker.js +35 -0
- package/lib/module/experiment/util/userSessionExposureTracker.js.map +1 -0
- package/lib/module/index.js +50 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/index.web.js +14 -0
- package/lib/module/index.web.js.map +1 -0
- package/lib/module/native/context.js +35 -0
- package/lib/module/native/context.js.map +1 -0
- package/lib/module/native/http.js +57 -0
- package/lib/module/native/http.js.map +1 -0
- package/lib/module/native/hybrid.js +24 -0
- package/lib/module/native/hybrid.js.map +1 -0
- package/lib/module/native/storage.js +86 -0
- package/lib/module/native/storage.js.map +1 -0
- package/lib/typescript/AmplitudeContext.nitro.d.ts +17 -0
- package/lib/typescript/AmplitudeContext.nitro.d.ts.map +1 -0
- package/lib/typescript/AmplitudeStorage.nitro.d.ts +17 -0
- package/lib/typescript/AmplitudeStorage.nitro.d.ts.map +1 -0
- package/lib/typescript/AmplitudeWorker.nitro.d.ts +11 -0
- package/lib/typescript/AmplitudeWorker.nitro.d.ts.map +1 -0
- package/lib/typescript/analytics/campaign/campaign-tracker.d.ts +85 -0
- package/lib/typescript/analytics/campaign/campaign-tracker.d.ts.map +1 -0
- package/lib/typescript/analytics/campaign/types.d.ts +11 -0
- package/lib/typescript/analytics/campaign/types.d.ts.map +1 -0
- package/lib/typescript/analytics/config.d.ts +68 -0
- package/lib/typescript/analytics/config.d.ts.map +1 -0
- package/lib/typescript/analytics/cookie-migration/index.d.ts +6 -0
- package/lib/typescript/analytics/cookie-migration/index.d.ts.map +1 -0
- package/lib/typescript/analytics/index.d.ts +7 -0
- package/lib/typescript/analytics/index.d.ts.map +1 -0
- package/lib/typescript/analytics/migration/remnant-data-migration.d.ts +20 -0
- package/lib/typescript/analytics/migration/remnant-data-migration.d.ts.map +1 -0
- package/lib/typescript/analytics/nitro-transport.d.ts +9 -0
- package/lib/typescript/analytics/nitro-transport.d.ts.map +1 -0
- package/lib/typescript/analytics/plugins/context.d.ts +14 -0
- package/lib/typescript/analytics/plugins/context.d.ts.map +1 -0
- package/lib/typescript/analytics/react-native-client.d.ts +55 -0
- package/lib/typescript/analytics/react-native-client.d.ts.map +1 -0
- package/lib/typescript/analytics/storage/local-storage.d.ts +14 -0
- package/lib/typescript/analytics/storage/local-storage.d.ts.map +1 -0
- package/lib/typescript/analytics/types.d.ts +2 -0
- package/lib/typescript/analytics/types.d.ts.map +1 -0
- package/lib/typescript/analytics/utils/platform.d.ts +3 -0
- package/lib/typescript/analytics/utils/platform.d.ts.map +1 -0
- package/lib/typescript/analytics/version.d.ts +2 -0
- package/lib/typescript/analytics/version.d.ts.map +1 -0
- package/lib/typescript/experiment/experimentClient.d.ts +234 -0
- package/lib/typescript/experiment/experimentClient.d.ts.map +1 -0
- package/lib/typescript/experiment/factory.d.ts +11 -0
- package/lib/typescript/experiment/factory.d.ts.map +1 -0
- package/lib/typescript/experiment/gen/version.d.ts +2 -0
- package/lib/typescript/experiment/gen/version.d.ts.map +1 -0
- package/lib/typescript/experiment/index.d.ts +15 -0
- package/lib/typescript/experiment/index.d.ts.map +1 -0
- package/lib/typescript/experiment/integration/NativeExperimentReactNativeClient.d.ts +16 -0
- package/lib/typescript/experiment/integration/NativeExperimentReactNativeClient.d.ts.map +1 -0
- package/lib/typescript/experiment/integration/connector.d.ts +16 -0
- package/lib/typescript/experiment/integration/connector.d.ts.map +1 -0
- package/lib/typescript/experiment/integration/default.d.ts +20 -0
- package/lib/typescript/experiment/integration/default.d.ts.map +1 -0
- package/lib/typescript/experiment/logger/ampLogger.d.ts +47 -0
- package/lib/typescript/experiment/logger/ampLogger.d.ts.map +1 -0
- package/lib/typescript/experiment/logger/consoleLogger.d.ts +40 -0
- package/lib/typescript/experiment/logger/consoleLogger.d.ts.map +1 -0
- package/lib/typescript/experiment/storage/cache.d.ts +35 -0
- package/lib/typescript/experiment/storage/cache.d.ts.map +1 -0
- package/lib/typescript/experiment/storage/local-storage.d.ts +11 -0
- package/lib/typescript/experiment/storage/local-storage.d.ts.map +1 -0
- package/lib/typescript/experiment/stubClient.d.ts +21 -0
- package/lib/typescript/experiment/stubClient.d.ts.map +1 -0
- package/lib/typescript/experiment/transport/http.d.ts +17 -0
- package/lib/typescript/experiment/transport/http.d.ts.map +1 -0
- package/lib/typescript/experiment/types/client.d.ts +36 -0
- package/lib/typescript/experiment/types/client.d.ts.map +1 -0
- package/lib/typescript/experiment/types/config.d.ts +164 -0
- package/lib/typescript/experiment/types/config.d.ts.map +1 -0
- package/lib/typescript/experiment/types/exposure.d.ts +107 -0
- package/lib/typescript/experiment/types/exposure.d.ts.map +1 -0
- package/lib/typescript/experiment/types/logger.d.ts +67 -0
- package/lib/typescript/experiment/types/logger.d.ts.map +1 -0
- package/lib/typescript/experiment/types/source.d.ts +43 -0
- package/lib/typescript/experiment/types/source.d.ts.map +1 -0
- package/lib/typescript/experiment/types/storage.d.ts +7 -0
- package/lib/typescript/experiment/types/storage.d.ts.map +1 -0
- package/lib/typescript/experiment/types/transport.d.ts +8 -0
- package/lib/typescript/experiment/types/transport.d.ts.map +1 -0
- package/lib/typescript/experiment/types/user.d.ts +106 -0
- package/lib/typescript/experiment/types/user.d.ts.map +1 -0
- package/lib/typescript/experiment/types/variant.d.ts +33 -0
- package/lib/typescript/experiment/types/variant.d.ts.map +1 -0
- package/lib/typescript/experiment/util/backoff.d.ts +14 -0
- package/lib/typescript/experiment/util/backoff.d.ts.map +1 -0
- package/lib/typescript/experiment/util/base64.d.ts +3 -0
- package/lib/typescript/experiment/util/base64.d.ts.map +1 -0
- package/lib/typescript/experiment/util/convert.d.ts +7 -0
- package/lib/typescript/experiment/util/convert.d.ts.map +1 -0
- package/lib/typescript/experiment/util/index.d.ts +6 -0
- package/lib/typescript/experiment/util/index.d.ts.map +1 -0
- package/lib/typescript/experiment/util/platform.d.ts +3 -0
- package/lib/typescript/experiment/util/platform.d.ts.map +1 -0
- package/lib/typescript/experiment/util/randomstring.d.ts +2 -0
- package/lib/typescript/experiment/util/randomstring.d.ts.map +1 -0
- package/lib/typescript/experiment/util/userSessionExposureTracker.d.ts +16 -0
- package/lib/typescript/experiment/util/userSessionExposureTracker.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +31 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/index.web.d.ts +12 -0
- package/lib/typescript/index.web.d.ts.map +1 -0
- package/lib/typescript/native/context.d.ts +29 -0
- package/lib/typescript/native/context.d.ts.map +1 -0
- package/lib/typescript/native/http.d.ts +6 -0
- package/lib/typescript/native/http.d.ts.map +1 -0
- package/lib/typescript/native/hybrid.d.ts +8 -0
- package/lib/typescript/native/hybrid.d.ts.map +1 -0
- package/lib/typescript/native/storage.d.ts +29 -0
- package/lib/typescript/native/storage.d.ts.map +1 -0
- package/nitro.json +33 -0
- package/nitrogen/generated/.gitattributes +1 -0
- package/nitrogen/generated/android/NitroAmplitude+autolinking.cmake +83 -0
- package/nitrogen/generated/android/NitroAmplitude+autolinking.gradle +27 -0
- package/nitrogen/generated/android/NitroAmplitudeOnLoad.cpp +69 -0
- package/nitrogen/generated/android/NitroAmplitudeOnLoad.hpp +34 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/com/nitroamplitude/NitroAmplitudeOnLoad.kt +35 -0
- package/nitrogen/generated/ios/NitroAmplitude+autolinking.rb +62 -0
- package/nitrogen/generated/ios/NitroAmplitude-Swift-Cxx-Bridge.cpp +17 -0
- package/nitrogen/generated/ios/NitroAmplitude-Swift-Cxx-Bridge.hpp +27 -0
- package/nitrogen/generated/ios/NitroAmplitude-Swift-Cxx-Umbrella.hpp +38 -0
- package/nitrogen/generated/ios/NitroAmplitudeAutolinking.mm +55 -0
- package/nitrogen/generated/ios/NitroAmplitudeAutolinking.swift +16 -0
- package/nitrogen/generated/shared/c++/HybridAmplitudeContextSpec.cpp +25 -0
- package/nitrogen/generated/shared/c++/HybridAmplitudeContextSpec.hpp +67 -0
- package/nitrogen/generated/shared/c++/HybridAmplitudeStorageSpec.cpp +30 -0
- package/nitrogen/generated/shared/c++/HybridAmplitudeStorageSpec.hpp +73 -0
- package/nitrogen/generated/shared/c++/HybridAmplitudeWorkerSpec.cpp +24 -0
- package/nitrogen/generated/shared/c++/HybridAmplitudeWorkerSpec.hpp +66 -0
- package/package.json +130 -0
- package/react-native-nitro-amplitude.podspec +36 -0
- package/src/AmplitudeContext.nitro.ts +21 -0
- package/src/AmplitudeStorage.nitro.ts +17 -0
- package/src/AmplitudeWorker.nitro.ts +25 -0
- package/src/analytics/campaign/campaign-tracker.ts +162 -0
- package/src/analytics/campaign/types.ts +18 -0
- package/src/analytics/config.ts +373 -0
- package/src/analytics/cookie-migration/index.ts +69 -0
- package/src/analytics/index.ts +36 -0
- package/src/analytics/migration/remnant-data-migration.ts +206 -0
- package/src/analytics/nitro-transport.ts +35 -0
- package/src/analytics/plugins/context.ts +166 -0
- package/src/analytics/react-native-client.ts +573 -0
- package/src/analytics/storage/local-storage.ts +76 -0
- package/src/analytics/types.ts +30 -0
- package/src/analytics/typings/browser-snippet.d.ts +7 -0
- package/src/analytics/typings/ua-parser.d.ts +4 -0
- package/src/analytics/utils/platform.ts +9 -0
- package/src/analytics/version.ts +1 -0
- package/src/experiment/experimentClient.ts +987 -0
- package/src/experiment/factory.ts +86 -0
- package/src/experiment/gen/version.ts +2 -0
- package/src/experiment/index.ts +14 -0
- package/src/experiment/integration/NativeExperimentReactNativeClient.ts +25 -0
- package/src/experiment/integration/connector.ts +82 -0
- package/src/experiment/integration/default.ts +107 -0
- package/src/experiment/logger/ampLogger.ts +76 -0
- package/src/experiment/logger/consoleLogger.ts +54 -0
- package/src/experiment/storage/cache.ts +271 -0
- package/src/experiment/storage/local-storage.ts +23 -0
- package/src/experiment/stubClient.ts +61 -0
- package/src/experiment/transport/http.ts +105 -0
- package/src/experiment/types/client.ts +38 -0
- package/src/experiment/types/config.ts +210 -0
- package/src/experiment/types/exposure.ts +107 -0
- package/src/experiment/types/logger.ts +71 -0
- package/src/experiment/types/source.ts +52 -0
- package/src/experiment/types/storage.ts +6 -0
- package/src/experiment/types/transport.ts +14 -0
- package/src/experiment/types/user.ts +132 -0
- package/src/experiment/types/variant.ts +36 -0
- package/src/experiment/util/backoff.ts +67 -0
- package/src/experiment/util/base64.ts +20 -0
- package/src/experiment/util/convert.ts +78 -0
- package/src/experiment/util/index.ts +23 -0
- package/src/experiment/util/platform.ts +9 -0
- package/src/experiment/util/randomstring.ts +12 -0
- package/src/experiment/util/userSessionExposureTracker.ts +47 -0
- package/src/index.ts +66 -0
- package/src/index.web.ts +19 -0
- package/src/native/context.ts +73 -0
- package/src/native/http.ts +77 -0
- package/src/native/hybrid.ts +32 -0
- package/src/native/storage.ts +107 -0
package/app.plugin.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const { withMainApplication, createRunOncePlugin } = require("@expo/config-plugins");
|
|
2
|
+
|
|
3
|
+
const withNitroAmplitude = (config) => {
|
|
4
|
+
return withMainApplication(config, (config) => {
|
|
5
|
+
const { modResults } = config;
|
|
6
|
+
const { language, contents } = modResults;
|
|
7
|
+
|
|
8
|
+
if (language === "kt") {
|
|
9
|
+
if (!contents.includes("AndroidAmplitudeAdapter.setContext")) {
|
|
10
|
+
const importStatement =
|
|
11
|
+
"import com.nitroamplitude.AndroidAmplitudeAdapter";
|
|
12
|
+
const initStatement = " AndroidAmplitudeAdapter.setContext(this)";
|
|
13
|
+
|
|
14
|
+
if (!contents.includes(importStatement)) {
|
|
15
|
+
modResults.contents = contents.replace(
|
|
16
|
+
/(package .*\n)/,
|
|
17
|
+
`$1\n${importStatement}\n`,
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
modResults.contents = modResults.contents.replace(
|
|
22
|
+
/(super\.onCreate\(\))/,
|
|
23
|
+
`$1\n${initStatement}`,
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return config;
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
module.exports = createRunOncePlugin(
|
|
33
|
+
withNitroAmplitude,
|
|
34
|
+
"react-native-nitro-amplitude",
|
|
35
|
+
"1.0.0",
|
|
36
|
+
);
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
#include "HybridAmplitudeContext.hpp"
|
|
2
|
+
|
|
3
|
+
#ifndef NITRO_AMPLITUDE_DISABLE_PLATFORM_ADAPTER
|
|
4
|
+
#if __APPLE__
|
|
5
|
+
#include "../../ios/IOSAmplitudeAdapterCpp.hpp"
|
|
6
|
+
#elif __ANDROID__
|
|
7
|
+
#include "../../android/src/main/cpp/AndroidAmplitudeAdapterCpp.hpp"
|
|
8
|
+
#include <fbjni/fbjni.h>
|
|
9
|
+
#endif
|
|
10
|
+
#endif
|
|
11
|
+
|
|
12
|
+
#include <cmath>
|
|
13
|
+
#include <stdexcept>
|
|
14
|
+
|
|
15
|
+
namespace margelo::nitro::NitroAmplitude {
|
|
16
|
+
|
|
17
|
+
namespace {
|
|
18
|
+
std::shared_ptr<::NitroAmplitude::NativeAmplitudeAdapter> createPlatformAdapter() {
|
|
19
|
+
#ifndef NITRO_AMPLITUDE_DISABLE_PLATFORM_ADAPTER
|
|
20
|
+
#if __APPLE__
|
|
21
|
+
return std::make_shared<::NitroAmplitude::IOSAmplitudeAdapterCpp>();
|
|
22
|
+
#elif __ANDROID__
|
|
23
|
+
auto context = ::NitroAmplitude::AndroidAmplitudeAdapterJava::getContext();
|
|
24
|
+
return std::make_shared<::NitroAmplitude::AndroidAmplitudeAdapterCpp>(context);
|
|
25
|
+
#else
|
|
26
|
+
return nullptr;
|
|
27
|
+
#endif
|
|
28
|
+
#else
|
|
29
|
+
return nullptr;
|
|
30
|
+
#endif
|
|
31
|
+
}
|
|
32
|
+
} // namespace
|
|
33
|
+
|
|
34
|
+
HybridAmplitudeContext::HybridAmplitudeContext()
|
|
35
|
+
: HybridObject(TAG), HybridAmplitudeContextSpec() {
|
|
36
|
+
adapter_ = createPlatformAdapter();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
void HybridAmplitudeContext::prefetch() {
|
|
40
|
+
if (adapter_) {
|
|
41
|
+
adapter_->prefetchContext();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
std::string HybridAmplitudeContext::getApplicationContextJson(
|
|
46
|
+
const std::string& optionsJson) {
|
|
47
|
+
if (!adapter_) {
|
|
48
|
+
return "{}";
|
|
49
|
+
}
|
|
50
|
+
return adapter_->getApplicationContextJson(optionsJson);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
std::string HybridAmplitudeContext::getLegacySessionDataJson(
|
|
54
|
+
const std::string& instanceName) {
|
|
55
|
+
if (!adapter_) {
|
|
56
|
+
return "{}";
|
|
57
|
+
}
|
|
58
|
+
return adapter_->getLegacySessionDataJson(instanceName);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
std::vector<std::string> HybridAmplitudeContext::getLegacyEventsJson(
|
|
62
|
+
const std::string& instanceName,
|
|
63
|
+
const std::string& eventKind) {
|
|
64
|
+
if (!adapter_) {
|
|
65
|
+
return {};
|
|
66
|
+
}
|
|
67
|
+
return adapter_->getLegacyEventsJson(instanceName, eventKind);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
void HybridAmplitudeContext::removeLegacyEvent(
|
|
71
|
+
const std::string& instanceName,
|
|
72
|
+
const std::string& eventKind,
|
|
73
|
+
double eventId) {
|
|
74
|
+
if (!adapter_) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (std::isnan(eventId) || std::isinf(eventId)) {
|
|
78
|
+
throw std::runtime_error("NitroAmplitude: Invalid eventId");
|
|
79
|
+
}
|
|
80
|
+
adapter_->removeLegacyEvent(instanceName, eventKind, static_cast<int64_t>(eventId));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
} // namespace margelo::nitro::NitroAmplitude
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "HybridAmplitudeContextSpec.hpp"
|
|
4
|
+
#include "../core/NativeAmplitudeAdapter.hpp"
|
|
5
|
+
#include <memory>
|
|
6
|
+
|
|
7
|
+
namespace margelo::nitro::NitroAmplitude {
|
|
8
|
+
|
|
9
|
+
class HybridAmplitudeContext : public HybridAmplitudeContextSpec {
|
|
10
|
+
public:
|
|
11
|
+
HybridAmplitudeContext();
|
|
12
|
+
~HybridAmplitudeContext() override = default;
|
|
13
|
+
|
|
14
|
+
void prefetch() override;
|
|
15
|
+
std::string getApplicationContextJson(const std::string& optionsJson) override;
|
|
16
|
+
std::string getLegacySessionDataJson(const std::string& instanceName) override;
|
|
17
|
+
std::vector<std::string> getLegacyEventsJson(
|
|
18
|
+
const std::string& instanceName,
|
|
19
|
+
const std::string& eventKind) override;
|
|
20
|
+
void removeLegacyEvent(
|
|
21
|
+
const std::string& instanceName,
|
|
22
|
+
const std::string& eventKind,
|
|
23
|
+
double eventId) override;
|
|
24
|
+
|
|
25
|
+
private:
|
|
26
|
+
std::shared_ptr<::NitroAmplitude::NativeAmplitudeAdapter> adapter_;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
} // namespace margelo::nitro::NitroAmplitude
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
#include "HybridAmplitudeStorage.hpp"
|
|
2
|
+
|
|
3
|
+
#ifndef NITRO_AMPLITUDE_DISABLE_PLATFORM_ADAPTER
|
|
4
|
+
#if __APPLE__
|
|
5
|
+
#include "../../ios/IOSAmplitudeAdapterCpp.hpp"
|
|
6
|
+
#elif __ANDROID__
|
|
7
|
+
#include "../../android/src/main/cpp/AndroidAmplitudeAdapterCpp.hpp"
|
|
8
|
+
#include <fbjni/fbjni.h>
|
|
9
|
+
#endif
|
|
10
|
+
#endif
|
|
11
|
+
|
|
12
|
+
#include <stdexcept>
|
|
13
|
+
|
|
14
|
+
namespace margelo::nitro::NitroAmplitude {
|
|
15
|
+
|
|
16
|
+
namespace {
|
|
17
|
+
constexpr auto kBatchMissingSentinel = "__nitro_amplitude_batch_missing__::v1";
|
|
18
|
+
|
|
19
|
+
std::shared_ptr<::NitroAmplitude::NativeAmplitudeAdapter> createPlatformAdapter() {
|
|
20
|
+
#ifndef NITRO_AMPLITUDE_DISABLE_PLATFORM_ADAPTER
|
|
21
|
+
#if __APPLE__
|
|
22
|
+
return std::make_shared<::NitroAmplitude::IOSAmplitudeAdapterCpp>();
|
|
23
|
+
#elif __ANDROID__
|
|
24
|
+
auto context = ::NitroAmplitude::AndroidAmplitudeAdapterJava::getContext();
|
|
25
|
+
return std::make_shared<::NitroAmplitude::AndroidAmplitudeAdapterCpp>(context);
|
|
26
|
+
#else
|
|
27
|
+
return nullptr;
|
|
28
|
+
#endif
|
|
29
|
+
#else
|
|
30
|
+
return nullptr;
|
|
31
|
+
#endif
|
|
32
|
+
}
|
|
33
|
+
} // namespace
|
|
34
|
+
|
|
35
|
+
HybridAmplitudeStorage::HybridAmplitudeStorage()
|
|
36
|
+
: HybridObject(TAG), HybridAmplitudeStorageSpec() {
|
|
37
|
+
adapter_ = createPlatformAdapter();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
void HybridAmplitudeStorage::set(
|
|
41
|
+
const std::string& key,
|
|
42
|
+
const std::string& value,
|
|
43
|
+
bool persist) {
|
|
44
|
+
if (persist) {
|
|
45
|
+
if (!adapter_) {
|
|
46
|
+
throw std::runtime_error("NitroAmplitude: Disk adapter unavailable");
|
|
47
|
+
}
|
|
48
|
+
adapter_->setDisk(key, value);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
std::lock_guard<std::mutex> lock(memoryMutex_);
|
|
52
|
+
memoryStore_[key] = value;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
std::optional<std::string> HybridAmplitudeStorage::get(
|
|
56
|
+
const std::string& key,
|
|
57
|
+
bool persist) {
|
|
58
|
+
if (persist) {
|
|
59
|
+
if (!adapter_) {
|
|
60
|
+
return std::nullopt;
|
|
61
|
+
}
|
|
62
|
+
return adapter_->getDisk(key);
|
|
63
|
+
}
|
|
64
|
+
std::lock_guard<std::mutex> lock(memoryMutex_);
|
|
65
|
+
auto it = memoryStore_.find(key);
|
|
66
|
+
if (it == memoryStore_.end()) {
|
|
67
|
+
return std::nullopt;
|
|
68
|
+
}
|
|
69
|
+
return it->second;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
void HybridAmplitudeStorage::remove(const std::string& key, bool persist) {
|
|
73
|
+
if (persist) {
|
|
74
|
+
if (adapter_) {
|
|
75
|
+
adapter_->deleteDisk(key);
|
|
76
|
+
}
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
std::lock_guard<std::mutex> lock(memoryMutex_);
|
|
80
|
+
memoryStore_.erase(key);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
void HybridAmplitudeStorage::clear(bool persist) {
|
|
84
|
+
if (persist) {
|
|
85
|
+
if (!adapter_) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
for (const auto& key : adapter_->getAllDiskKeys()) {
|
|
89
|
+
adapter_->deleteDisk(key);
|
|
90
|
+
}
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
std::lock_guard<std::mutex> lock(memoryMutex_);
|
|
94
|
+
memoryStore_.clear();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
bool HybridAmplitudeStorage::has(const std::string& key, bool persist) {
|
|
98
|
+
if (persist) {
|
|
99
|
+
return adapter_ ? adapter_->hasDisk(key) : false;
|
|
100
|
+
}
|
|
101
|
+
std::lock_guard<std::mutex> lock(memoryMutex_);
|
|
102
|
+
return memoryStore_.find(key) != memoryStore_.end();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
std::vector<std::string> HybridAmplitudeStorage::getAllKeys(bool persist) {
|
|
106
|
+
if (persist) {
|
|
107
|
+
return adapter_ ? adapter_->getAllDiskKeys() : std::vector<std::string>{};
|
|
108
|
+
}
|
|
109
|
+
std::lock_guard<std::mutex> lock(memoryMutex_);
|
|
110
|
+
std::vector<std::string> keys;
|
|
111
|
+
keys.reserve(memoryStore_.size());
|
|
112
|
+
for (const auto& entry : memoryStore_) {
|
|
113
|
+
keys.push_back(entry.first);
|
|
114
|
+
}
|
|
115
|
+
return keys;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
std::vector<std::string> HybridAmplitudeStorage::getKeysByPrefix(
|
|
119
|
+
const std::string& prefix,
|
|
120
|
+
bool persist) {
|
|
121
|
+
const auto keys = getAllKeys(persist);
|
|
122
|
+
std::vector<std::string> filtered;
|
|
123
|
+
for (const auto& key : keys) {
|
|
124
|
+
if (key.rfind(prefix, 0) == 0) {
|
|
125
|
+
filtered.push_back(key);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return filtered;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
void HybridAmplitudeStorage::setBatch(
|
|
132
|
+
const std::vector<std::string>& keys,
|
|
133
|
+
const std::vector<std::string>& values,
|
|
134
|
+
bool persist) {
|
|
135
|
+
if (keys.size() != values.size()) {
|
|
136
|
+
throw std::runtime_error("NitroAmplitude: setBatch key/value length mismatch");
|
|
137
|
+
}
|
|
138
|
+
for (size_t i = 0; i < keys.size(); ++i) {
|
|
139
|
+
set(keys[i], values[i], persist);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
std::vector<std::string> HybridAmplitudeStorage::getBatch(
|
|
144
|
+
const std::vector<std::string>& keys,
|
|
145
|
+
bool persist) {
|
|
146
|
+
std::vector<std::string> values;
|
|
147
|
+
values.reserve(keys.size());
|
|
148
|
+
for (const auto& key : keys) {
|
|
149
|
+
const auto value = get(key, persist);
|
|
150
|
+
values.push_back(value.value_or(kBatchMissingSentinel));
|
|
151
|
+
}
|
|
152
|
+
return values;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
void HybridAmplitudeStorage::removeBatch(
|
|
156
|
+
const std::vector<std::string>& keys,
|
|
157
|
+
bool persist) {
|
|
158
|
+
for (const auto& key : keys) {
|
|
159
|
+
remove(key, persist);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
} // namespace margelo::nitro::NitroAmplitude
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "HybridAmplitudeStorageSpec.hpp"
|
|
4
|
+
#include "../core/NativeAmplitudeAdapter.hpp"
|
|
5
|
+
#include <memory>
|
|
6
|
+
#include <mutex>
|
|
7
|
+
#include <unordered_map>
|
|
8
|
+
|
|
9
|
+
namespace margelo::nitro::NitroAmplitude {
|
|
10
|
+
|
|
11
|
+
class HybridAmplitudeStorage : public HybridAmplitudeStorageSpec {
|
|
12
|
+
public:
|
|
13
|
+
HybridAmplitudeStorage();
|
|
14
|
+
~HybridAmplitudeStorage() override = default;
|
|
15
|
+
|
|
16
|
+
void set(const std::string& key, const std::string& value, bool persist) override;
|
|
17
|
+
std::optional<std::string> get(const std::string& key, bool persist) override;
|
|
18
|
+
void remove(const std::string& key, bool persist) override;
|
|
19
|
+
void clear(bool persist) override;
|
|
20
|
+
bool has(const std::string& key, bool persist) override;
|
|
21
|
+
std::vector<std::string> getAllKeys(bool persist) override;
|
|
22
|
+
std::vector<std::string> getKeysByPrefix(const std::string& prefix, bool persist) override;
|
|
23
|
+
void setBatch(
|
|
24
|
+
const std::vector<std::string>& keys,
|
|
25
|
+
const std::vector<std::string>& values,
|
|
26
|
+
bool persist) override;
|
|
27
|
+
std::vector<std::string> getBatch(
|
|
28
|
+
const std::vector<std::string>& keys,
|
|
29
|
+
bool persist) override;
|
|
30
|
+
void removeBatch(const std::vector<std::string>& keys, bool persist) override;
|
|
31
|
+
|
|
32
|
+
private:
|
|
33
|
+
std::shared_ptr<::NitroAmplitude::NativeAmplitudeAdapter> adapter_;
|
|
34
|
+
std::unordered_map<std::string, std::string> memoryStore_;
|
|
35
|
+
std::mutex memoryMutex_;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
} // namespace margelo::nitro::NitroAmplitude
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
#include "HybridAmplitudeWorker.hpp"
|
|
2
|
+
|
|
3
|
+
#ifndef NITRO_AMPLITUDE_DISABLE_PLATFORM_ADAPTER
|
|
4
|
+
#if __APPLE__
|
|
5
|
+
#include "../../ios/IOSAmplitudeAdapterCpp.hpp"
|
|
6
|
+
#elif __ANDROID__
|
|
7
|
+
#include "../../android/src/main/cpp/AndroidAmplitudeAdapterCpp.hpp"
|
|
8
|
+
#include <fbjni/fbjni.h>
|
|
9
|
+
#endif
|
|
10
|
+
#endif
|
|
11
|
+
|
|
12
|
+
#include <algorithm>
|
|
13
|
+
#include <cmath>
|
|
14
|
+
#include <stdexcept>
|
|
15
|
+
|
|
16
|
+
namespace margelo::nitro::NitroAmplitude {
|
|
17
|
+
|
|
18
|
+
namespace {
|
|
19
|
+
std::shared_ptr<::NitroAmplitude::NativeAmplitudeAdapter> createPlatformAdapter() {
|
|
20
|
+
#ifndef NITRO_AMPLITUDE_DISABLE_PLATFORM_ADAPTER
|
|
21
|
+
#if __APPLE__
|
|
22
|
+
return std::make_shared<::NitroAmplitude::IOSAmplitudeAdapterCpp>();
|
|
23
|
+
#elif __ANDROID__
|
|
24
|
+
auto context = ::NitroAmplitude::AndroidAmplitudeAdapterJava::getContext();
|
|
25
|
+
return std::make_shared<::NitroAmplitude::AndroidAmplitudeAdapterCpp>(context);
|
|
26
|
+
#else
|
|
27
|
+
return nullptr;
|
|
28
|
+
#endif
|
|
29
|
+
#else
|
|
30
|
+
return nullptr;
|
|
31
|
+
#endif
|
|
32
|
+
}
|
|
33
|
+
} // namespace
|
|
34
|
+
|
|
35
|
+
HybridAmplitudeWorker::HybridAmplitudeWorker()
|
|
36
|
+
: HybridObject(TAG), HybridAmplitudeWorkerSpec() {
|
|
37
|
+
adapter_ = createPlatformAdapter();
|
|
38
|
+
workerThread_ = std::thread([this]() { workerLoop(); });
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
HybridAmplitudeWorker::~HybridAmplitudeWorker() {
|
|
42
|
+
{
|
|
43
|
+
std::lock_guard<std::mutex> lock(queueMutex_);
|
|
44
|
+
running_ = false;
|
|
45
|
+
}
|
|
46
|
+
queueCv_.notify_all();
|
|
47
|
+
if (workerThread_.joinable()) {
|
|
48
|
+
workerThread_.join();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
void HybridAmplitudeWorker::enqueue(
|
|
53
|
+
const std::string& requestId,
|
|
54
|
+
const std::string& url,
|
|
55
|
+
const std::string& method,
|
|
56
|
+
const std::string& headersJson,
|
|
57
|
+
const std::string& body,
|
|
58
|
+
double timeoutMillis) {
|
|
59
|
+
if (requestId.empty() || url.empty()) {
|
|
60
|
+
throw std::runtime_error("NitroAmplitude: Invalid HTTP request");
|
|
61
|
+
}
|
|
62
|
+
if (std::isnan(timeoutMillis) || std::isinf(timeoutMillis) || timeoutMillis <= 0.0) {
|
|
63
|
+
timeoutMillis = 10000.0;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
WorkerRequest request{
|
|
67
|
+
requestId,
|
|
68
|
+
url,
|
|
69
|
+
method,
|
|
70
|
+
headersJson,
|
|
71
|
+
body,
|
|
72
|
+
static_cast<int>(timeoutMillis),
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
{
|
|
76
|
+
std::lock_guard<std::mutex> lock(queueMutex_);
|
|
77
|
+
cancelledRequests_.erase(requestId);
|
|
78
|
+
queue_.push(std::move(request));
|
|
79
|
+
queueSize_ = queue_.size();
|
|
80
|
+
}
|
|
81
|
+
queueCv_.notify_one();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
void HybridAmplitudeWorker::cancel(const std::string& requestId) {
|
|
85
|
+
std::lock_guard<std::mutex> lock(queueMutex_);
|
|
86
|
+
cancelledRequests_.insert(requestId);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
std::function<void()> HybridAmplitudeWorker::addOnComplete(
|
|
90
|
+
const std::function<void(
|
|
91
|
+
const std::string&,
|
|
92
|
+
double,
|
|
93
|
+
const std::string&,
|
|
94
|
+
const std::string&)>& callback) {
|
|
95
|
+
std::lock_guard<std::mutex> lock(listenersMutex_);
|
|
96
|
+
const size_t listenerId = ++nextListenerId_;
|
|
97
|
+
listeners_.push_back(Listener{listenerId, callback});
|
|
98
|
+
return [this, listenerId]() {
|
|
99
|
+
std::lock_guard<std::mutex> innerLock(listenersMutex_);
|
|
100
|
+
listeners_.erase(
|
|
101
|
+
std::remove_if(
|
|
102
|
+
listeners_.begin(),
|
|
103
|
+
listeners_.end(),
|
|
104
|
+
[listenerId](const Listener& listener) { return listener.id == listenerId; }),
|
|
105
|
+
listeners_.end());
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
double HybridAmplitudeWorker::queueSize() {
|
|
110
|
+
return static_cast<double>(queueSize_.load());
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
void HybridAmplitudeWorker::workerLoop() {
|
|
114
|
+
while (true) {
|
|
115
|
+
WorkerRequest request;
|
|
116
|
+
{
|
|
117
|
+
std::unique_lock<std::mutex> lock(queueMutex_);
|
|
118
|
+
queueCv_.wait(lock, [this]() { return !running_ || !queue_.empty(); });
|
|
119
|
+
if (!running_ && queue_.empty()) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
request = std::move(queue_.front());
|
|
123
|
+
queue_.pop();
|
|
124
|
+
queueSize_ = queue_.size();
|
|
125
|
+
if (cancelledRequests_.erase(request.requestId) > 0) {
|
|
126
|
+
notifyComplete(request.requestId, 0, "", "cancelled");
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (!adapter_) {
|
|
132
|
+
notifyComplete(request.requestId, 0, "", "Native adapter unavailable");
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const auto result = adapter_->performHttpRequest(
|
|
137
|
+
request.url,
|
|
138
|
+
request.method,
|
|
139
|
+
request.headersJson,
|
|
140
|
+
request.body,
|
|
141
|
+
request.timeoutMillis);
|
|
142
|
+
|
|
143
|
+
notifyComplete(
|
|
144
|
+
request.requestId,
|
|
145
|
+
static_cast<double>(result.statusCode),
|
|
146
|
+
result.body,
|
|
147
|
+
result.error);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
void HybridAmplitudeWorker::notifyComplete(
|
|
152
|
+
const std::string& requestId,
|
|
153
|
+
double statusCode,
|
|
154
|
+
const std::string& body,
|
|
155
|
+
const std::string& error) {
|
|
156
|
+
std::lock_guard<std::mutex> lock(listenersMutex_);
|
|
157
|
+
for (const auto& listener : listeners_) {
|
|
158
|
+
listener.callback(requestId, statusCode, body, error);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
} // namespace margelo::nitro::NitroAmplitude
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "HybridAmplitudeWorkerSpec.hpp"
|
|
4
|
+
#include "../core/NativeAmplitudeAdapter.hpp"
|
|
5
|
+
#include <atomic>
|
|
6
|
+
#include <condition_variable>
|
|
7
|
+
#include <functional>
|
|
8
|
+
#include <memory>
|
|
9
|
+
#include <mutex>
|
|
10
|
+
#include <queue>
|
|
11
|
+
#include <string>
|
|
12
|
+
#include <thread>
|
|
13
|
+
#include <unordered_set>
|
|
14
|
+
#include <vector>
|
|
15
|
+
|
|
16
|
+
namespace margelo::nitro::NitroAmplitude {
|
|
17
|
+
|
|
18
|
+
struct WorkerRequest {
|
|
19
|
+
std::string requestId;
|
|
20
|
+
std::string url;
|
|
21
|
+
std::string method;
|
|
22
|
+
std::string headersJson;
|
|
23
|
+
std::string body;
|
|
24
|
+
int timeoutMillis = 10000;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
class HybridAmplitudeWorker : public HybridAmplitudeWorkerSpec {
|
|
28
|
+
public:
|
|
29
|
+
HybridAmplitudeWorker();
|
|
30
|
+
~HybridAmplitudeWorker() override;
|
|
31
|
+
|
|
32
|
+
void enqueue(
|
|
33
|
+
const std::string& requestId,
|
|
34
|
+
const std::string& url,
|
|
35
|
+
const std::string& method,
|
|
36
|
+
const std::string& headersJson,
|
|
37
|
+
const std::string& body,
|
|
38
|
+
double timeoutMillis) override;
|
|
39
|
+
void cancel(const std::string& requestId) override;
|
|
40
|
+
std::function<void()> addOnComplete(
|
|
41
|
+
const std::function<void(
|
|
42
|
+
const std::string&,
|
|
43
|
+
double,
|
|
44
|
+
const std::string&,
|
|
45
|
+
const std::string&)>& callback) override;
|
|
46
|
+
double queueSize() override;
|
|
47
|
+
|
|
48
|
+
private:
|
|
49
|
+
void workerLoop();
|
|
50
|
+
void notifyComplete(
|
|
51
|
+
const std::string& requestId,
|
|
52
|
+
double statusCode,
|
|
53
|
+
const std::string& body,
|
|
54
|
+
const std::string& error);
|
|
55
|
+
|
|
56
|
+
std::shared_ptr<::NitroAmplitude::NativeAmplitudeAdapter> adapter_;
|
|
57
|
+
std::thread workerThread_;
|
|
58
|
+
std::mutex queueMutex_;
|
|
59
|
+
std::condition_variable queueCv_;
|
|
60
|
+
std::queue<WorkerRequest> queue_;
|
|
61
|
+
std::unordered_set<std::string> cancelledRequests_;
|
|
62
|
+
std::atomic<bool> running_{true};
|
|
63
|
+
std::atomic<size_t> queueSize_{0};
|
|
64
|
+
|
|
65
|
+
std::mutex listenersMutex_;
|
|
66
|
+
struct Listener {
|
|
67
|
+
size_t id;
|
|
68
|
+
std::function<void(const std::string&, double, const std::string&, const std::string&)> callback;
|
|
69
|
+
};
|
|
70
|
+
std::vector<Listener> listeners_;
|
|
71
|
+
size_t nextListenerId_ = 0;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
} // namespace margelo::nitro::NitroAmplitude
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <optional>
|
|
4
|
+
#include <string>
|
|
5
|
+
#include <vector>
|
|
6
|
+
|
|
7
|
+
namespace NitroAmplitude {
|
|
8
|
+
|
|
9
|
+
struct HttpResult {
|
|
10
|
+
int statusCode = 0;
|
|
11
|
+
std::string body;
|
|
12
|
+
std::string error;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
class NativeAmplitudeAdapter {
|
|
16
|
+
public:
|
|
17
|
+
virtual ~NativeAmplitudeAdapter() = default;
|
|
18
|
+
|
|
19
|
+
virtual void prefetchContext() = 0;
|
|
20
|
+
virtual std::string getApplicationContextJson(const std::string& optionsJson) = 0;
|
|
21
|
+
virtual std::string getLegacySessionDataJson(const std::string& instanceName) = 0;
|
|
22
|
+
virtual std::vector<std::string> getLegacyEventsJson(
|
|
23
|
+
const std::string& instanceName,
|
|
24
|
+
const std::string& eventKind) = 0;
|
|
25
|
+
virtual void removeLegacyEvent(
|
|
26
|
+
const std::string& instanceName,
|
|
27
|
+
const std::string& eventKind,
|
|
28
|
+
int64_t eventId) = 0;
|
|
29
|
+
|
|
30
|
+
virtual void setDisk(const std::string& key, const std::string& value) = 0;
|
|
31
|
+
virtual std::optional<std::string> getDisk(const std::string& key) = 0;
|
|
32
|
+
virtual void deleteDisk(const std::string& key) = 0;
|
|
33
|
+
virtual bool hasDisk(const std::string& key) = 0;
|
|
34
|
+
virtual std::vector<std::string> getAllDiskKeys() = 0;
|
|
35
|
+
|
|
36
|
+
virtual HttpResult performHttpRequest(
|
|
37
|
+
const std::string& url,
|
|
38
|
+
const std::string& method,
|
|
39
|
+
const std::string& headersJson,
|
|
40
|
+
const std::string& body,
|
|
41
|
+
int timeoutMillis) = 0;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
} // namespace NitroAmplitude
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "../../cpp/core/NativeAmplitudeAdapter.hpp"
|
|
4
|
+
|
|
5
|
+
namespace NitroAmplitude {
|
|
6
|
+
|
|
7
|
+
class IOSAmplitudeAdapterCpp : public NativeAmplitudeAdapter {
|
|
8
|
+
public:
|
|
9
|
+
IOSAmplitudeAdapterCpp();
|
|
10
|
+
~IOSAmplitudeAdapterCpp() override = default;
|
|
11
|
+
|
|
12
|
+
void prefetchContext() override;
|
|
13
|
+
std::string getApplicationContextJson(const std::string& optionsJson) override;
|
|
14
|
+
std::string getLegacySessionDataJson(const std::string& instanceName) override;
|
|
15
|
+
std::vector<std::string> getLegacyEventsJson(
|
|
16
|
+
const std::string& instanceName,
|
|
17
|
+
const std::string& eventKind) override;
|
|
18
|
+
void removeLegacyEvent(
|
|
19
|
+
const std::string& instanceName,
|
|
20
|
+
const std::string& eventKind,
|
|
21
|
+
int64_t eventId) override;
|
|
22
|
+
|
|
23
|
+
void setDisk(const std::string& key, const std::string& value) override;
|
|
24
|
+
std::optional<std::string> getDisk(const std::string& key) override;
|
|
25
|
+
void deleteDisk(const std::string& key) override;
|
|
26
|
+
bool hasDisk(const std::string& key) override;
|
|
27
|
+
std::vector<std::string> getAllDiskKeys() override;
|
|
28
|
+
|
|
29
|
+
HttpResult performHttpRequest(
|
|
30
|
+
const std::string& url,
|
|
31
|
+
const std::string& method,
|
|
32
|
+
const std::string& headersJson,
|
|
33
|
+
const std::string& body,
|
|
34
|
+
int timeoutMillis) override;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
} // namespace NitroAmplitude
|