@jmartins-tillster/analytics-react-native 2.21.3
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/.editorconfig +10 -0
- package/.eslintignore +11 -0
- package/.eslintrc.js +60 -0
- package/.gitattributes +4 -0
- package/.github/ISSUE_TEMPLATE/BUG_REPORT.md +23 -0
- package/.github/ISSUE_TEMPLATE/FEATURE_REQUEST.md +18 -0
- package/.github/workflows/ci.yml +158 -0
- package/.github/workflows/create_jira.yml +41 -0
- package/.github/workflows/publish.yml +57 -0
- package/.husky/commit-msg +4 -0
- package/.husky/pre-commit +4 -0
- package/.prettierrc.js +7 -0
- package/.yarnrc.yml +2 -0
- package/CODE_OF_CONDUCT.md +84 -0
- package/CONTRIBUTING.md +141 -0
- package/LICENSE +21 -0
- package/MIGRATION_GUIDE.md +185 -0
- package/README.md +944 -0
- package/babel.config.js +3 -0
- package/commitlint.config.js +13 -0
- package/examples/AnalyticsReactNativeExample/.bundle/config +2 -0
- package/examples/AnalyticsReactNativeExample/.eslintrc.js +4 -0
- package/examples/AnalyticsReactNativeExample/.prettierrc.js +7 -0
- package/examples/AnalyticsReactNativeExample/.watchmanconfig +1 -0
- package/examples/AnalyticsReactNativeExample/App.tsx +164 -0
- package/examples/AnalyticsReactNativeExample/Gemfile +9 -0
- package/examples/AnalyticsReactNativeExample/Gemfile.lock +106 -0
- package/examples/AnalyticsReactNativeExample/Home.tsx +206 -0
- package/examples/AnalyticsReactNativeExample/Modal.tsx +25 -0
- package/examples/AnalyticsReactNativeExample/README.md +79 -0
- package/examples/AnalyticsReactNativeExample/SecondPage.tsx +25 -0
- package/examples/AnalyticsReactNativeExample/android/app/build.gradle +119 -0
- package/examples/AnalyticsReactNativeExample/android/app/debug.keystore +0 -0
- package/examples/AnalyticsReactNativeExample/android/app/proguard-rules.pro +10 -0
- package/examples/AnalyticsReactNativeExample/android/app/src/debug/AndroidManifest.xml +9 -0
- package/examples/AnalyticsReactNativeExample/android/app/src/main/AndroidManifest.xml +26 -0
- package/examples/AnalyticsReactNativeExample/android/app/src/main/java/com/analyticsreactnativeexample/MainActivity.kt +22 -0
- package/examples/AnalyticsReactNativeExample/android/app/src/main/java/com/analyticsreactnativeexample/MainApplication.kt +44 -0
- package/examples/AnalyticsReactNativeExample/android/app/src/main/res/drawable/rn_edit_text_material.xml +37 -0
- package/examples/AnalyticsReactNativeExample/android/app/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
- package/examples/AnalyticsReactNativeExample/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png +0 -0
- package/examples/AnalyticsReactNativeExample/android/app/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
- package/examples/AnalyticsReactNativeExample/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png +0 -0
- package/examples/AnalyticsReactNativeExample/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
- package/examples/AnalyticsReactNativeExample/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png +0 -0
- package/examples/AnalyticsReactNativeExample/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
- package/examples/AnalyticsReactNativeExample/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png +0 -0
- package/examples/AnalyticsReactNativeExample/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
- package/examples/AnalyticsReactNativeExample/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png +0 -0
- package/examples/AnalyticsReactNativeExample/android/app/src/main/res/values/strings.xml +3 -0
- package/examples/AnalyticsReactNativeExample/android/app/src/main/res/values/styles.xml +9 -0
- package/examples/AnalyticsReactNativeExample/android/build.gradle +21 -0
- package/examples/AnalyticsReactNativeExample/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/examples/AnalyticsReactNativeExample/android/gradle/wrapper/gradle-wrapper.properties +8 -0
- package/examples/AnalyticsReactNativeExample/android/gradle.properties +39 -0
- package/examples/AnalyticsReactNativeExample/android/gradlew +252 -0
- package/examples/AnalyticsReactNativeExample/android/gradlew.bat +94 -0
- package/examples/AnalyticsReactNativeExample/android/settings.gradle +6 -0
- package/examples/AnalyticsReactNativeExample/app.json +4 -0
- package/examples/AnalyticsReactNativeExample/babel.config.js +3 -0
- package/examples/AnalyticsReactNativeExample/index.js +9 -0
- package/examples/AnalyticsReactNativeExample/ios/.xcode.env +11 -0
- package/examples/AnalyticsReactNativeExample/ios/AnalyticsReactNativeExample/AppDelegate.h +6 -0
- package/examples/AnalyticsReactNativeExample/ios/AnalyticsReactNativeExample/AppDelegate.mm +31 -0
- package/examples/AnalyticsReactNativeExample/ios/AnalyticsReactNativeExample/Images.xcassets/AppIcon.appiconset/Contents.json +53 -0
- package/examples/AnalyticsReactNativeExample/ios/AnalyticsReactNativeExample/Images.xcassets/Contents.json +6 -0
- package/examples/AnalyticsReactNativeExample/ios/AnalyticsReactNativeExample/Info.plist +52 -0
- package/examples/AnalyticsReactNativeExample/ios/AnalyticsReactNativeExample/LaunchScreen.storyboard +47 -0
- package/examples/AnalyticsReactNativeExample/ios/AnalyticsReactNativeExample/PrivacyInfo.xcprivacy +37 -0
- package/examples/AnalyticsReactNativeExample/ios/AnalyticsReactNativeExample/main.m +10 -0
- package/examples/AnalyticsReactNativeExample/ios/AnalyticsReactNativeExample.xcodeproj/project.pbxproj +705 -0
- package/examples/AnalyticsReactNativeExample/ios/AnalyticsReactNativeExample.xcodeproj/xcshareddata/xcschemes/AnalyticsReactNativeExample.xcscheme +88 -0
- package/examples/AnalyticsReactNativeExample/ios/AnalyticsReactNativeExample.xcworkspace/contents.xcworkspacedata +10 -0
- package/examples/AnalyticsReactNativeExample/ios/AnalyticsReactNativeExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- package/examples/AnalyticsReactNativeExample/ios/AnalyticsReactNativeExampleTests/AnalyticsReactNativeExampleTests.m +66 -0
- package/examples/AnalyticsReactNativeExample/ios/AnalyticsReactNativeExampleTests/Info.plist +24 -0
- package/examples/AnalyticsReactNativeExample/ios/Podfile +40 -0
- package/examples/AnalyticsReactNativeExample/ios/Podfile.lock +1961 -0
- package/examples/AnalyticsReactNativeExample/metro.config.js +11 -0
- package/examples/AnalyticsReactNativeExample/package.json +55 -0
- package/examples/AnalyticsReactNativeExample/plugins/ConsentManager.tsx +75 -0
- package/examples/AnalyticsReactNativeExample/plugins/Logger.ts +16 -0
- package/examples/AnalyticsReactNativeExample/react-native.config.js +9 -0
- package/examples/AnalyticsReactNativeExample/tsconfig.json +3 -0
- package/examples/AnalyticsReactNativeExample/workspace.js +5 -0
- package/examples/AnalyticsReactNativeExample/yarn.lock +11110 -0
- package/examples/E2E/.bundle/config +2 -0
- package/examples/E2E/.detoxrc.js +96 -0
- package/examples/E2E/.mise.toml +5 -0
- package/examples/E2E/.prettierrc.js +7 -0
- package/examples/E2E/.watchmanconfig +1 -0
- package/examples/E2E/App.tsx +176 -0
- package/examples/E2E/Gemfile +7 -0
- package/examples/E2E/Gemfile.lock +101 -0
- package/examples/E2E/Home.tsx +206 -0
- package/examples/E2E/Modal.tsx +25 -0
- package/examples/E2E/README.md +79 -0
- package/examples/E2E/SecondPage.tsx +25 -0
- package/examples/E2E/android/app/build.gradle +128 -0
- package/examples/E2E/android/app/debug.keystore +0 -0
- package/examples/E2E/android/app/proguard-rules.pro +10 -0
- package/examples/E2E/android/app/src/androidTest/java/com/segmentanalyticsreactnativeexample/DetoxTest.java +29 -0
- package/examples/E2E/android/app/src/debug/AndroidManifest.xml +13 -0
- package/examples/E2E/android/app/src/debug/java/com/analyticsreactnativeexample/ReactNativeFlipper.java +75 -0
- package/examples/E2E/android/app/src/main/AndroidManifest.xml +26 -0
- package/examples/E2E/android/app/src/main/java/com/analyticsreactnativeexample/MainActivity.java +32 -0
- package/examples/E2E/android/app/src/main/java/com/analyticsreactnativeexample/MainApplication.java +62 -0
- package/examples/E2E/android/app/src/main/res/drawable/rn_edit_text_material.xml +36 -0
- package/examples/E2E/android/app/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
- package/examples/E2E/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png +0 -0
- package/examples/E2E/android/app/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
- package/examples/E2E/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png +0 -0
- package/examples/E2E/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
- package/examples/E2E/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png +0 -0
- package/examples/E2E/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
- package/examples/E2E/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png +0 -0
- package/examples/E2E/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
- package/examples/E2E/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png +0 -0
- package/examples/E2E/android/app/src/main/res/values/strings.xml +3 -0
- package/examples/E2E/android/app/src/main/res/values/styles.xml +9 -0
- package/examples/E2E/android/app/src/main/res/xml/network_security_config.xml +7 -0
- package/examples/E2E/android/app/src/release/java/com/analyticsreactnativeexample/ReactNativeFlipper.java +20 -0
- package/examples/E2E/android/build.gradle +37 -0
- package/examples/E2E/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/examples/E2E/android/gradle/wrapper/gradle-wrapper.properties +6 -0
- package/examples/E2E/android/gradle.properties +44 -0
- package/examples/E2E/android/gradlew +244 -0
- package/examples/E2E/android/gradlew.bat +92 -0
- package/examples/E2E/android/settings.gradle +4 -0
- package/examples/E2E/app.json +4 -0
- package/examples/E2E/babel.config.js +14 -0
- package/examples/E2E/e2e/jest.config.js +13 -0
- package/examples/E2E/e2e/main.e2e.js +192 -0
- package/examples/E2E/e2e/matchers.js +34 -0
- package/examples/E2E/e2e/mockServer.js +56 -0
- package/examples/E2E/index.js +11 -0
- package/examples/E2E/ios/.xcode.env +11 -0
- package/examples/E2E/ios/AnalyticsReactNativeE2E/AppDelegate.h +6 -0
- package/examples/E2E/ios/AnalyticsReactNativeE2E/AppDelegate.mm +26 -0
- package/examples/E2E/ios/AnalyticsReactNativeE2E/Images.xcassets/AppIcon.appiconset/Contents.json +53 -0
- package/examples/E2E/ios/AnalyticsReactNativeE2E/Images.xcassets/Contents.json +6 -0
- package/examples/E2E/ios/AnalyticsReactNativeE2E/Info.plist +55 -0
- package/examples/E2E/ios/AnalyticsReactNativeE2E/LaunchScreen.storyboard +47 -0
- package/examples/E2E/ios/AnalyticsReactNativeE2E/main.m +10 -0
- package/examples/E2E/ios/AnalyticsReactNativeE2E.xcodeproj/project.pbxproj +721 -0
- package/examples/E2E/ios/AnalyticsReactNativeE2E.xcworkspace/contents.xcworkspacedata +10 -0
- package/examples/E2E/ios/AnalyticsReactNativeE2E.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- package/examples/E2E/ios/AnalyticsReactNativeE2ETests/AnalyticsReactNativeExampleTests.m +66 -0
- package/examples/E2E/ios/AnalyticsReactNativeE2ETests/Info.plist +24 -0
- package/examples/E2E/ios/Podfile +62 -0
- package/examples/E2E/ios/Podfile.lock +763 -0
- package/examples/E2E/jest.config.js +3 -0
- package/examples/E2E/metro.config.js +45 -0
- package/examples/E2E/package.json +65 -0
- package/examples/E2E/plugins/Logger.ts +16 -0
- package/examples/E2E/react-native.config.js +7 -0
- package/examples/E2E/workspace.js +5 -0
- package/examples/E2E/yarn.lock +10898 -0
- package/examples/E2E-73/.bundle/config +2 -0
- package/examples/E2E-73/.detoxrc.js +96 -0
- package/examples/E2E-73/.eslintrc.js +4 -0
- package/examples/E2E-73/.mise.toml +5 -0
- package/examples/E2E-73/.prettierrc.js +7 -0
- package/examples/E2E-73/.watchmanconfig +1 -0
- package/examples/E2E-73/App.tsx +175 -0
- package/examples/E2E-73/Gemfile +7 -0
- package/examples/E2E-73/Gemfile.lock +99 -0
- package/examples/E2E-73/Home.tsx +206 -0
- package/examples/E2E-73/Modal.tsx +25 -0
- package/examples/E2E-73/README.md +79 -0
- package/examples/E2E-73/SecondPage.tsx +25 -0
- package/examples/E2E-73/android/app/build.gradle +119 -0
- package/examples/E2E-73/android/app/debug.keystore +0 -0
- package/examples/E2E-73/android/app/proguard-rules.pro +10 -0
- package/examples/E2E-73/android/app/src/debug/AndroidManifest.xml +9 -0
- package/examples/E2E-73/android/app/src/main/AndroidManifest.xml +25 -0
- package/examples/E2E-73/android/app/src/main/java/com/analyticsreactnativee2e73/MainActivity.kt +22 -0
- package/examples/E2E-73/android/app/src/main/java/com/analyticsreactnativee2e73/MainApplication.kt +45 -0
- package/examples/E2E-73/android/app/src/main/res/drawable/rn_edit_text_material.xml +36 -0
- package/examples/E2E-73/android/app/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
- package/examples/E2E-73/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png +0 -0
- package/examples/E2E-73/android/app/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
- package/examples/E2E-73/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png +0 -0
- package/examples/E2E-73/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
- package/examples/E2E-73/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png +0 -0
- package/examples/E2E-73/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
- package/examples/E2E-73/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png +0 -0
- package/examples/E2E-73/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
- package/examples/E2E-73/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png +0 -0
- package/examples/E2E-73/android/app/src/main/res/values/strings.xml +3 -0
- package/examples/E2E-73/android/app/src/main/res/values/styles.xml +9 -0
- package/examples/E2E-73/android/build.gradle +21 -0
- package/examples/E2E-73/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/examples/E2E-73/android/gradle/wrapper/gradle-wrapper.properties +7 -0
- package/examples/E2E-73/android/gradle.properties +41 -0
- package/examples/E2E-73/android/gradlew +249 -0
- package/examples/E2E-73/android/gradlew.bat +92 -0
- package/examples/E2E-73/android/settings.gradle +4 -0
- package/examples/E2E-73/app.json +4 -0
- package/examples/E2E-73/babel.config.js +14 -0
- package/examples/E2E-73/e2e/jest.config.js +13 -0
- package/examples/E2E-73/e2e/main.e2e.js +192 -0
- package/examples/E2E-73/e2e/matchers.js +34 -0
- package/examples/E2E-73/e2e/mockServer.js +56 -0
- package/examples/E2E-73/index.js +9 -0
- package/examples/E2E-73/ios/.xcode.env +11 -0
- package/examples/E2E-73/ios/AnalyticsReactNativeE2E73/AppDelegate.h +6 -0
- package/examples/E2E-73/ios/AnalyticsReactNativeE2E73/AppDelegate.mm +31 -0
- package/examples/E2E-73/ios/AnalyticsReactNativeE2E73/Images.xcassets/AppIcon.appiconset/Contents.json +53 -0
- package/examples/E2E-73/ios/AnalyticsReactNativeE2E73/Images.xcassets/Contents.json +6 -0
- package/examples/E2E-73/ios/AnalyticsReactNativeE2E73/Info.plist +51 -0
- package/examples/E2E-73/ios/AnalyticsReactNativeE2E73/LaunchScreen.storyboard +47 -0
- package/examples/E2E-73/ios/AnalyticsReactNativeE2E73/main.m +10 -0
- package/examples/E2E-73/ios/AnalyticsReactNativeE2E73.xcodeproj/project.pbxproj +700 -0
- package/examples/E2E-73/ios/AnalyticsReactNativeE2E73.xcodeproj/xcshareddata/xcschemes/AnalyticsReactNativeE2E73.xcscheme +88 -0
- package/examples/E2E-73/ios/AnalyticsReactNativeE2E73.xcworkspace/contents.xcworkspacedata +10 -0
- package/examples/E2E-73/ios/AnalyticsReactNativeE2E73Tests/AnalyticsReactNativeE2E73Tests.m +66 -0
- package/examples/E2E-73/ios/AnalyticsReactNativeE2E73Tests/Info.plist +24 -0
- package/examples/E2E-73/ios/Podfile +55 -0
- package/examples/E2E-73/ios/Podfile.lock +1425 -0
- package/examples/E2E-73/jest.config.js +3 -0
- package/examples/E2E-73/metro.config.js +45 -0
- package/examples/E2E-73/package.json +62 -0
- package/examples/E2E-73/plugins/Logger.ts +16 -0
- package/examples/E2E-73/react-native.config.js +12 -0
- package/examples/E2E-73/tsconfig.json +3 -0
- package/examples/E2E-73/workspace.js +5 -0
- package/examples/E2E-73/yarn.lock +10789 -0
- package/examples/README.md +142 -0
- package/examples/linkHelper.js +45 -0
- package/jest.config.js +7 -0
- package/multi-release.config.js +7 -0
- package/package.json +79 -0
- package/packages/core/CHANGELOG.md +274 -0
- package/packages/core/LICENSE +21 -0
- package/packages/core/README.md +3 -0
- package/packages/core/android/build.gradle +96 -0
- package/packages/core/android/gradle.properties +5 -0
- package/packages/core/android/src/main/AndroidManifest.xml +4 -0
- package/packages/core/android/src/main/AndroidManifestNew.xml +3 -0
- package/packages/core/android/src/main/java/com/segmentanalyticsreactnative/AnalyticsReactNativeModule.kt +265 -0
- package/packages/core/android/src/main/java/com/segmentanalyticsreactnative/AnalyticsReactNativePackage.kt +43 -0
- package/packages/core/babel.config.js +3 -0
- package/packages/core/constants-generator.js +17 -0
- package/packages/core/ios/AnalyticsReactNative-Bridging-Header.h +1 -0
- package/packages/core/ios/AnalyticsReactNative.m +7 -0
- package/packages/core/ios/AnalyticsReactNative.swift +142 -0
- package/packages/core/ios/AnalyticsReactNative.xcodeproj/project.pbxproj +281 -0
- package/packages/core/ios/PrivacyInfo.xcprivacy +70 -0
- package/packages/core/jest.config.js +5 -0
- package/packages/core/package.json +85 -0
- package/packages/core/release.config.js +3 -0
- package/packages/core/segment-analytics-react-native.podspec +35 -0
- package/packages/core/src/__tests__/__snapshots__/mapTransform.test.ts.snap +20 -0
- package/packages/core/src/__tests__/analytics.test.ts +252 -0
- package/packages/core/src/__tests__/api.test.ts +91 -0
- package/packages/core/src/__tests__/client.test.ts +27 -0
- package/packages/core/src/__tests__/context.test.ts +122 -0
- package/packages/core/src/__tests__/events.test.ts +234 -0
- package/packages/core/src/__tests__/internal/checkInstalledVersion.test.ts +221 -0
- package/packages/core/src/__tests__/internal/fetchSettings.test.ts +438 -0
- package/packages/core/src/__tests__/internal/handleAppStateChange.test.ts +178 -0
- package/packages/core/src/__tests__/internal/trackDeepLinks.test.ts +121 -0
- package/packages/core/src/__tests__/logger.test.ts +83 -0
- package/packages/core/src/__tests__/mapTransform.test.ts +63 -0
- package/packages/core/src/__tests__/methods/alias.test.ts +89 -0
- package/packages/core/src/__tests__/methods/flush.test.ts +120 -0
- package/packages/core/src/__tests__/methods/group.test.ts +48 -0
- package/packages/core/src/__tests__/methods/identify.test.ts +132 -0
- package/packages/core/src/__tests__/methods/process.test.ts +162 -0
- package/packages/core/src/__tests__/methods/screen.test.ts +48 -0
- package/packages/core/src/__tests__/methods/track.test.ts +49 -0
- package/packages/core/src/__tests__/timeline.test.ts +130 -0
- package/packages/core/src/__tests__/util.test.ts +200 -0
- package/packages/core/src/analytics.ts +1030 -0
- package/packages/core/src/api.ts +23 -0
- package/packages/core/src/client.tsx +76 -0
- package/packages/core/src/constants.ts +18 -0
- package/packages/core/src/context.ts +107 -0
- package/packages/core/src/errors.ts +123 -0
- package/packages/core/src/events.ts +75 -0
- package/packages/core/src/flushPolicies/__tests__/background-flush-policy.test.ts +39 -0
- package/packages/core/src/flushPolicies/__tests__/count-flush-policy.test.ts +28 -0
- package/packages/core/src/flushPolicies/__tests__/flush-policy-executer.test.ts +85 -0
- package/packages/core/src/flushPolicies/__tests__/timer-flush-policy.test.ts +30 -0
- package/packages/core/src/flushPolicies/background-flush-policy.ts +21 -0
- package/packages/core/src/flushPolicies/count-flush-policy.ts +31 -0
- package/packages/core/src/flushPolicies/flush-policy-executer.ts +100 -0
- package/packages/core/src/flushPolicies/index.ts +5 -0
- package/packages/core/src/flushPolicies/startup-flush-policy.ts +20 -0
- package/packages/core/src/flushPolicies/timer-flush-policy.ts +45 -0
- package/packages/core/src/flushPolicies/types.ts +93 -0
- package/packages/core/src/index.ts +28 -0
- package/packages/core/src/logger.ts +37 -0
- package/packages/core/src/mapTransform.ts +48 -0
- package/packages/core/src/plugin.ts +212 -0
- package/packages/core/src/plugins/ConsentPlugin.ts +200 -0
- package/packages/core/src/plugins/DestinationMetadataEnrichment.ts +67 -0
- package/packages/core/src/plugins/QueueFlushingPlugin.ts +149 -0
- package/packages/core/src/plugins/SegmentDestination.ts +153 -0
- package/packages/core/src/plugins/__tests__/QueueFlushingPlugin.test.ts +143 -0
- package/packages/core/src/plugins/__tests__/SegmentDestination.test.ts +549 -0
- package/packages/core/src/plugins/__tests__/consent/consentNotEnabledAtSegment.test.ts +123 -0
- package/packages/core/src/plugins/__tests__/consent/destinationMultipleCategories.test.ts +147 -0
- package/packages/core/src/plugins/__tests__/consent/idfa.test.ts +101 -0
- package/packages/core/src/plugins/__tests__/consent/mockSettings/ConsentNotEnabledAtSegment.json +70 -0
- package/packages/core/src/plugins/__tests__/consent/mockSettings/DestinationsMultipleCategories.json +73 -0
- package/packages/core/src/plugins/__tests__/consent/mockSettings/NoUnmappedDestinations.json +105 -0
- package/packages/core/src/plugins/__tests__/consent/mockSettings/UnmappedDestinations.json +101 -0
- package/packages/core/src/plugins/__tests__/consent/noUnmapped.test.ts +234 -0
- package/packages/core/src/plugins/__tests__/consent/unmapped.test.ts +265 -0
- package/packages/core/src/plugins/__tests__/consent/utils.ts +75 -0
- package/packages/core/src/storage/__tests__/sovranStorage.test.ts +153 -0
- package/packages/core/src/storage/helpers.ts +25 -0
- package/packages/core/src/storage/index.ts +3 -0
- package/packages/core/src/storage/sovranStorage.ts +558 -0
- package/packages/core/src/storage/types.ts +106 -0
- package/packages/core/src/test-helpers/index.ts +7 -0
- package/packages/core/src/test-helpers/mockDestinationPlugin.ts +7 -0
- package/packages/core/src/test-helpers/mockEventStore.ts +35 -0
- package/packages/core/src/test-helpers/mockLogger.ts +10 -0
- package/packages/core/src/test-helpers/mockSegmentStore.ts +266 -0
- package/packages/core/src/test-helpers/mockTimeline.ts +9 -0
- package/packages/core/src/test-helpers/setupSegmentClient.ts +59 -0
- package/packages/core/src/test-helpers/utils.ts +23 -0
- package/packages/core/src/timeline.ts +136 -0
- package/packages/core/src/types.ts +392 -0
- package/packages/core/src/util.ts +288 -0
- package/packages/core/src/uuid.ts +7 -0
- package/packages/core/tsconfig.json +10 -0
- package/packages/core/tsconfig.linter.json +11 -0
- package/packages/plugins/plugin-adjust/CHANGELOG.md +60 -0
- package/packages/plugins/plugin-adjust/LICENSE +21 -0
- package/packages/plugins/plugin-adjust/README.md +72 -0
- package/packages/plugins/plugin-adjust/babel.config.js +3 -0
- package/packages/plugins/plugin-adjust/jest.config.js +5 -0
- package/packages/plugins/plugin-adjust/package.json +72 -0
- package/packages/plugins/plugin-adjust/release.config.js +3 -0
- package/packages/plugins/plugin-adjust/src/AdjustPlugin.tsx +92 -0
- package/packages/plugins/plugin-adjust/src/index.ts +1 -0
- package/packages/plugins/plugin-adjust/src/methods/__mocks__/react-native-adjust.ts +19 -0
- package/packages/plugins/plugin-adjust/src/methods/__tests__/identify.test.ts +34 -0
- package/packages/plugins/plugin-adjust/src/methods/__tests__/reset.test.ts +15 -0
- package/packages/plugins/plugin-adjust/src/methods/__tests__/track.test.ts +148 -0
- package/packages/plugins/plugin-adjust/src/methods/identify.ts +14 -0
- package/packages/plugins/plugin-adjust/src/methods/reset.ts +9 -0
- package/packages/plugins/plugin-adjust/src/methods/track.ts +47 -0
- package/packages/plugins/plugin-adjust/src/util.ts +29 -0
- package/packages/plugins/plugin-adjust/tsconfig.json +10 -0
- package/packages/plugins/plugin-advertising-id/CHANGELOG.md +101 -0
- package/packages/plugins/plugin-advertising-id/CONTRIBUTING.md +196 -0
- package/packages/plugins/plugin-advertising-id/LICENSE +21 -0
- package/packages/plugins/plugin-advertising-id/README.md +40 -0
- package/packages/plugins/plugin-advertising-id/android/build.gradle +96 -0
- package/packages/plugins/plugin-advertising-id/android/gradle.properties +5 -0
- package/packages/plugins/plugin-advertising-id/android/src/main/AndroidManifest.xml +4 -0
- package/packages/plugins/plugin-advertising-id/android/src/main/AndroidManifestNew.xml +3 -0
- package/packages/plugins/plugin-advertising-id/android/src/main/java/com/reactnativeanalyticsreactnativepluginadvertisingid/AnalyticsReactNativePluginAdvertisingIdModule.kt +64 -0
- package/packages/plugins/plugin-advertising-id/android/src/main/java/com/reactnativeanalyticsreactnativepluginadvertisingid/AnalyticsReactNativePluginAdvertisingIdPackage.kt +17 -0
- package/packages/plugins/plugin-advertising-id/babel.config.js +3 -0
- package/packages/plugins/plugin-advertising-id/jest.config.js +5 -0
- package/packages/plugins/plugin-advertising-id/package.json +70 -0
- package/packages/plugins/plugin-advertising-id/release.config.js +3 -0
- package/packages/plugins/plugin-advertising-id/src/AdvertisingIdPlugin.ts +172 -0
- package/packages/plugins/plugin-advertising-id/src/index.ts +1 -0
- package/packages/plugins/plugin-advertising-id/src/types.ts +3 -0
- package/packages/plugins/plugin-advertising-id/tsconfig.json +10 -0
- package/packages/plugins/plugin-amplitudeSession/CHANGELOG.md +46 -0
- package/packages/plugins/plugin-amplitudeSession/LICENSE +21 -0
- package/packages/plugins/plugin-amplitudeSession/README.md +66 -0
- package/packages/plugins/plugin-amplitudeSession/babel.config.js +3 -0
- package/packages/plugins/plugin-amplitudeSession/jest.config.js +5 -0
- package/packages/plugins/plugin-amplitudeSession/package.json +71 -0
- package/packages/plugins/plugin-amplitudeSession/release.config.js +3 -0
- package/packages/plugins/plugin-amplitudeSession/src/AmplitudeSessionPlugin.tsx +327 -0
- package/packages/plugins/plugin-amplitudeSession/src/__tests__/AmplitudeSessionPlugin.test.ts +769 -0
- package/packages/plugins/plugin-amplitudeSession/src/index.ts +1 -0
- package/packages/plugins/plugin-amplitudeSession/tsconfig.json +10 -0
- package/packages/plugins/plugin-appsflyer/CHANGELOG.md +64 -0
- package/packages/plugins/plugin-appsflyer/LICENSE +21 -0
- package/packages/plugins/plugin-appsflyer/README.md +90 -0
- package/packages/plugins/plugin-appsflyer/babel.config.js +3 -0
- package/packages/plugins/plugin-appsflyer/jest.config.js +5 -0
- package/packages/plugins/plugin-appsflyer/package.json +74 -0
- package/packages/plugins/plugin-appsflyer/release.config.js +3 -0
- package/packages/plugins/plugin-appsflyer/src/AppsflyerPlugin.tsx +218 -0
- package/packages/plugins/plugin-appsflyer/src/__tests__/AppsflyerPlugin.test.ts +20 -0
- package/packages/plugins/plugin-appsflyer/src/index.ts +1 -0
- package/packages/plugins/plugin-appsflyer/src/methods/__mocks__/react-native-appsflyer.ts +11 -0
- package/packages/plugins/plugin-appsflyer/src/methods/__tests__/identify.test.ts +57 -0
- package/packages/plugins/plugin-appsflyer/src/methods/__tests__/track.test.ts +99 -0
- package/packages/plugins/plugin-appsflyer/src/methods/identify.ts +42 -0
- package/packages/plugins/plugin-appsflyer/src/methods/track.ts +61 -0
- package/packages/plugins/plugin-appsflyer/src/types.ts +9 -0
- package/packages/plugins/plugin-appsflyer/tsconfig.json +10 -0
- package/packages/plugins/plugin-branch/CHANGELOG.md +51 -0
- package/packages/plugins/plugin-branch/LICENSE +21 -0
- package/packages/plugins/plugin-branch/README.md +71 -0
- package/packages/plugins/plugin-branch/babel.config.js +3 -0
- package/packages/plugins/plugin-branch/jest.config.js +5 -0
- package/packages/plugins/plugin-branch/package.json +74 -0
- package/packages/plugins/plugin-branch/release.config.js +3 -0
- package/packages/plugins/plugin-branch/src/BranchPlugin.ts +42 -0
- package/packages/plugins/plugin-branch/src/index.ts +1 -0
- package/packages/plugins/plugin-branch/src/methods/__mocks__/react-native-branch.ts +16 -0
- package/packages/plugins/plugin-branch/src/methods/__tests__/alias.test.ts +23 -0
- package/packages/plugins/plugin-branch/src/methods/__tests__/identify.test.ts +23 -0
- package/packages/plugins/plugin-branch/src/methods/__tests__/screen.test.ts +38 -0
- package/packages/plugins/plugin-branch/src/methods/__tests__/track.test.ts +73 -0
- package/packages/plugins/plugin-branch/src/methods/alias.ts +9 -0
- package/packages/plugins/plugin-branch/src/methods/identify.ts +9 -0
- package/packages/plugins/plugin-branch/src/methods/parameterMapping.ts +109 -0
- package/packages/plugins/plugin-branch/src/methods/reset.ts +5 -0
- package/packages/plugins/plugin-branch/src/methods/screen.ts +17 -0
- package/packages/plugins/plugin-branch/src/methods/track.ts +18 -0
- package/packages/plugins/plugin-branch/src/methods/util.ts +64 -0
- package/packages/plugins/plugin-branch/tsconfig.json +10 -0
- package/packages/plugins/plugin-braze/CHANGELOG.md +101 -0
- package/packages/plugins/plugin-braze/LICENSE +21 -0
- package/packages/plugins/plugin-braze/README.md +72 -0
- package/packages/plugins/plugin-braze/babel.config.js +3 -0
- package/packages/plugins/plugin-braze/jest.config.js +5 -0
- package/packages/plugins/plugin-braze/package.json +74 -0
- package/packages/plugins/plugin-braze/release.config.js +3 -0
- package/packages/plugins/plugin-braze/src/BrazePlugin.tsx +346 -0
- package/packages/plugins/plugin-braze/src/index.ts +1 -0
- package/packages/plugins/plugin-braze/src/methods/__mocks__/@braze/react-native-sdk.ts +31 -0
- package/packages/plugins/plugin-braze/src/methods/__tests__/flush.test.ts +15 -0
- package/packages/plugins/plugin-braze/src/methods/__tests__/identify.test.ts +114 -0
- package/packages/plugins/plugin-braze/src/methods/__tests__/track.test.ts +321 -0
- package/packages/plugins/plugin-braze/src/methods/flush.ts +5 -0
- package/packages/plugins/plugin-braze/tsconfig.json +10 -0
- package/packages/plugins/plugin-braze-middleware/CHANGELOG.md +32 -0
- package/packages/plugins/plugin-braze-middleware/LICENSE +21 -0
- package/packages/plugins/plugin-braze-middleware/README.md +67 -0
- package/packages/plugins/plugin-braze-middleware/babel.config.js +3 -0
- package/packages/plugins/plugin-braze-middleware/jest.config.js +5 -0
- package/packages/plugins/plugin-braze-middleware/package.json +72 -0
- package/packages/plugins/plugin-braze-middleware/release.config.js +3 -0
- package/packages/plugins/plugin-braze-middleware/src/BrazeMiddlewarePlugin.tsx +38 -0
- package/packages/plugins/plugin-braze-middleware/src/index.ts +1 -0
- package/packages/plugins/plugin-braze-middleware/tsconfig.json +10 -0
- package/packages/plugins/plugin-clevertap/CHANGELOG.md +32 -0
- package/packages/plugins/plugin-clevertap/LICENSE +21 -0
- package/packages/plugins/plugin-clevertap/README.md +71 -0
- package/packages/plugins/plugin-clevertap/babel.config.js +3 -0
- package/packages/plugins/plugin-clevertap/jest.config.js +5 -0
- package/packages/plugins/plugin-clevertap/package.json +72 -0
- package/packages/plugins/plugin-clevertap/release.config.js +3 -0
- package/packages/plugins/plugin-clevertap/src/ClevertapPlugin.ts +75 -0
- package/packages/plugins/plugin-clevertap/src/__mocks__/clevertap-react-native.ts +5 -0
- package/packages/plugins/plugin-clevertap/src/__tests__/ClevertapPlugin.test.ts +164 -0
- package/packages/plugins/plugin-clevertap/src/index.ts +1 -0
- package/packages/plugins/plugin-clevertap/src/parameterMapping.ts +19 -0
- package/packages/plugins/plugin-clevertap/tsconfig.json +10 -0
- package/packages/plugins/plugin-destination-filters/CHANGELOG.md +39 -0
- package/packages/plugins/plugin-destination-filters/LICENSE +21 -0
- package/packages/plugins/plugin-destination-filters/README.md +71 -0
- package/packages/plugins/plugin-destination-filters/babel.config.js +3 -0
- package/packages/plugins/plugin-destination-filters/jest.config.js +5 -0
- package/packages/plugins/plugin-destination-filters/package.json +77 -0
- package/packages/plugins/plugin-destination-filters/release.config.js +3 -0
- package/packages/plugins/plugin-destination-filters/src/DestinationFilters.ts +90 -0
- package/packages/plugins/plugin-destination-filters/src/__tests__/DestinationFilters.test.ts +102 -0
- package/packages/plugins/plugin-destination-filters/src/index.tsx +1 -0
- package/packages/plugins/plugin-destination-filters/tsconfig.json +10 -0
- package/packages/plugins/plugin-device-token/CHANGELOG.md +71 -0
- package/packages/plugins/plugin-device-token/LICENSE +21 -0
- package/packages/plugins/plugin-device-token/README.md +98 -0
- package/packages/plugins/plugin-device-token/babel.config.js +3 -0
- package/packages/plugins/plugin-device-token/jest.config.js +5 -0
- package/packages/plugins/plugin-device-token/package.json +76 -0
- package/packages/plugins/plugin-device-token/release.config.js +3 -0
- package/packages/plugins/plugin-device-token/src/DeviceTokenPlugin.tsx +94 -0
- package/packages/plugins/plugin-device-token/src/index.ts +1 -0
- package/packages/plugins/plugin-device-token/src/methods/___tests__/DeviceTokenPlugin.test.ts +94 -0
- package/packages/plugins/plugin-device-token/tsconfig.json +10 -0
- package/packages/plugins/plugin-facebook-app-events/CHANGELOG.md +78 -0
- package/packages/plugins/plugin-facebook-app-events/LICENSE +21 -0
- package/packages/plugins/plugin-facebook-app-events/README.md +73 -0
- package/packages/plugins/plugin-facebook-app-events/babel.config.js +3 -0
- package/packages/plugins/plugin-facebook-app-events/jest.config.js +5 -0
- package/packages/plugins/plugin-facebook-app-events/package.json +72 -0
- package/packages/plugins/plugin-facebook-app-events/release.config.js +3 -0
- package/packages/plugins/plugin-facebook-app-events/src/FacebookAppEventsPlugin.ts +192 -0
- package/packages/plugins/plugin-facebook-app-events/src/__tests__/FacebookAppEventsPlugin.test.ts +284 -0
- package/packages/plugins/plugin-facebook-app-events/src/index.ts +1 -0
- package/packages/plugins/plugin-facebook-app-events/src/methods/__tests__/screen.test.ts +33 -0
- package/packages/plugins/plugin-facebook-app-events/src/methods/screen.ts +35 -0
- package/packages/plugins/plugin-facebook-app-events/src/parameterMapping.ts +46 -0
- package/packages/plugins/plugin-facebook-app-events/src/utils.ts +12 -0
- package/packages/plugins/plugin-facebook-app-events/tsconfig.json +10 -0
- package/packages/plugins/plugin-firebase/CHANGELOG.md +102 -0
- package/packages/plugins/plugin-firebase/LICENSE +21 -0
- package/packages/plugins/plugin-firebase/README.md +72 -0
- package/packages/plugins/plugin-firebase/babel.config.js +3 -0
- package/packages/plugins/plugin-firebase/jest.config.js +5 -0
- package/packages/plugins/plugin-firebase/package.json +74 -0
- package/packages/plugins/plugin-firebase/release.config.js +3 -0
- package/packages/plugins/plugin-firebase/src/FirebasePlugin.tsx +96 -0
- package/packages/plugins/plugin-firebase/src/index.ts +1 -0
- package/packages/plugins/plugin-firebase/src/methods/___tests__/identify.test.ts +73 -0
- package/packages/plugins/plugin-firebase/src/methods/___tests__/reset.test.ts +20 -0
- package/packages/plugins/plugin-firebase/src/methods/___tests__/screen.test.ts +33 -0
- package/packages/plugins/plugin-firebase/src/methods/___tests__/track.test.ts +85 -0
- package/packages/plugins/plugin-firebase/src/methods/parameterMapping.ts +45 -0
- package/packages/plugins/plugin-firebase/src/methods/reset.ts +5 -0
- package/packages/plugins/plugin-firebase/src/methods/screen.ts +12 -0
- package/packages/plugins/plugin-firebase/src/methods/track.ts +26 -0
- package/packages/plugins/plugin-firebase/tsconfig.json +10 -0
- package/packages/plugins/plugin-idfa/CHANGELOG.md +62 -0
- package/packages/plugins/plugin-idfa/LICENSE +21 -0
- package/packages/plugins/plugin-idfa/README.md +105 -0
- package/packages/plugins/plugin-idfa/babel.config.js +3 -0
- package/packages/plugins/plugin-idfa/ios/AnalyticsReactNativePluginIdfa-Bridging-Header.h +2 -0
- package/packages/plugins/plugin-idfa/ios/AnalyticsReactNativePluginIdfa.m +11 -0
- package/packages/plugins/plugin-idfa/ios/AnalyticsReactNativePluginIdfa.swift +68 -0
- package/packages/plugins/plugin-idfa/ios/AnalyticsReactNativePluginIdfa.xcodeproj/project.pbxproj +293 -0
- package/packages/plugins/plugin-idfa/jest.config.js +5 -0
- package/packages/plugins/plugin-idfa/package.json +70 -0
- package/packages/plugins/plugin-idfa/release.config.js +3 -0
- package/packages/plugins/plugin-idfa/segment-analytics-react-native-plugin-idfa.podspec +19 -0
- package/packages/plugins/plugin-idfa/src/AnalyticsReactNativePluginIdfa.e2e.mock.ts +12 -0
- package/packages/plugins/plugin-idfa/src/AnalyticsReactNativePluginIdfa.ts +18 -0
- package/packages/plugins/plugin-idfa/src/IdfaPlugin.tsx +80 -0
- package/packages/plugins/plugin-idfa/src/index.ts +1 -0
- package/packages/plugins/plugin-idfa/src/types.ts +13 -0
- package/packages/plugins/plugin-idfa/tsconfig.json +10 -0
- package/packages/plugins/plugin-mixpanel/CHANGELOG.md +73 -0
- package/packages/plugins/plugin-mixpanel/LICENSE +21 -0
- package/packages/plugins/plugin-mixpanel/README.md +71 -0
- package/packages/plugins/plugin-mixpanel/babel.config.js +3 -0
- package/packages/plugins/plugin-mixpanel/jest.config.js +5 -0
- package/packages/plugins/plugin-mixpanel/package.json +72 -0
- package/packages/plugins/plugin-mixpanel/release.config.js +3 -0
- package/packages/plugins/plugin-mixpanel/src/MixpanelPlugin.ts +106 -0
- package/packages/plugins/plugin-mixpanel/src/index.ts +1 -0
- package/packages/plugins/plugin-mixpanel/src/methods/__mocks__/mixpanel-react-native.ts +67 -0
- package/packages/plugins/plugin-mixpanel/src/methods/__tests__/MixpanelPlugin.test.ts +57 -0
- package/packages/plugins/plugin-mixpanel/src/methods/__tests__/__helpers__/constants.ts +18 -0
- package/packages/plugins/plugin-mixpanel/src/methods/__tests__/alias.test.ts +47 -0
- package/packages/plugins/plugin-mixpanel/src/methods/__tests__/group.test.ts +49 -0
- package/packages/plugins/plugin-mixpanel/src/methods/__tests__/identify.test.ts +103 -0
- package/packages/plugins/plugin-mixpanel/src/methods/__tests__/screen.test.ts +119 -0
- package/packages/plugins/plugin-mixpanel/src/methods/__tests__/track.test.ts +110 -0
- package/packages/plugins/plugin-mixpanel/src/methods/alias.ts +28 -0
- package/packages/plugins/plugin-mixpanel/src/methods/group.ts +26 -0
- package/packages/plugins/plugin-mixpanel/src/methods/identify.ts +72 -0
- package/packages/plugins/plugin-mixpanel/src/methods/screen.ts +43 -0
- package/packages/plugins/plugin-mixpanel/src/methods/track.ts +60 -0
- package/packages/plugins/plugin-mixpanel/src/types.ts +15 -0
- package/packages/plugins/plugin-mixpanel/tsconfig.json +10 -0
- package/packages/plugins/plugin-onetrust/CHANGELOG.md +16 -0
- package/packages/plugins/plugin-onetrust/LICENSE +21 -0
- package/packages/plugins/plugin-onetrust/README.md +155 -0
- package/packages/plugins/plugin-onetrust/babel.config.js +3 -0
- package/packages/plugins/plugin-onetrust/jest.config.js +6 -0
- package/packages/plugins/plugin-onetrust/package.json +75 -0
- package/packages/plugins/plugin-onetrust/release.config.js +3 -0
- package/packages/plugins/plugin-onetrust/src/OneTrustProvider.ts +71 -0
- package/packages/plugins/plugin-onetrust/src/index.tsx +1 -0
- package/packages/plugins/plugin-onetrust/tsconfig.json +10 -0
- package/packages/shared/__mocks__/context.ts +35 -0
- package/packages/shared/__mocks__/react-native-get-random-values.ts +1 -0
- package/packages/shared/__mocks__/react-native.ts +53 -0
- package/packages/shared/__mocks__/uuid.ts +3 -0
- package/packages/shared/jest.config.base.js +38 -0
- package/packages/shared/package.json +19 -0
- package/packages/shared/src/setup.ts +7 -0
- package/packages/shared/tsconfig.json +15 -0
- package/packages/sovran/CHANGELOG.md +42 -0
- package/packages/sovran/CONTRIBUTING.md +196 -0
- package/packages/sovran/LICENSE +21 -0
- package/packages/sovran/README.md +174 -0
- package/packages/sovran/android/build.gradle +94 -0
- package/packages/sovran/android/gradle.properties +5 -0
- package/packages/sovran/android/src/main/AndroidManifest.xml +4 -0
- package/packages/sovran/android/src/main/AndroidManifestNew.xml +3 -0
- package/packages/sovran/android/src/main/java/com/reactnativesovran/Sovran.kt +45 -0
- package/packages/sovran/android/src/main/java/com/reactnativesovran/SovranModule.kt +55 -0
- package/packages/sovran/babel.config.js +3 -0
- package/packages/sovran/ios/Sovran-Bridging-Header.h +3 -0
- package/packages/sovran/ios/Sovran.m +8 -0
- package/packages/sovran/ios/Sovran.swift +67 -0
- package/packages/sovran/ios/Sovran.xcodeproj/project.pbxproj +279 -0
- package/packages/sovran/jest.config.js +5 -0
- package/packages/sovran/package.json +89 -0
- package/packages/sovran/release.config.js +3 -0
- package/packages/sovran/sovran-react-native.podspec +33 -0
- package/packages/sovran/src/__tests__/bridge.test.ts +39 -0
- package/packages/sovran/src/__tests__/index.test.tsx +1 -0
- package/packages/sovran/src/__tests__/store.test.ts +397 -0
- package/packages/sovran/src/bridge.ts +48 -0
- package/packages/sovran/src/index.tsx +52 -0
- package/packages/sovran/src/persistor/async-storage-persistor.ts +63 -0
- package/packages/sovran/src/persistor/index.ts +2 -0
- package/packages/sovran/src/persistor/persistor.ts +31 -0
- package/packages/sovran/src/store.ts +232 -0
- package/packages/sovran/tsconfig.json +9 -0
- package/release.config.js +13 -0
- package/tsconfig.json +44 -0
- package/tsconfig.linter.json +36 -0
|
@@ -0,0 +1,558 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createStore,
|
|
3
|
+
registerBridgeStore,
|
|
4
|
+
Store,
|
|
5
|
+
Persistor,
|
|
6
|
+
} from '@segment/sovran-react-native';
|
|
7
|
+
import deepmerge from 'deepmerge';
|
|
8
|
+
import type {
|
|
9
|
+
SegmentAPIIntegrations,
|
|
10
|
+
IntegrationSettings,
|
|
11
|
+
SegmentEvent,
|
|
12
|
+
DeepPartial,
|
|
13
|
+
Context,
|
|
14
|
+
UserInfoState,
|
|
15
|
+
RoutingRule,
|
|
16
|
+
DestinationFilters,
|
|
17
|
+
SegmentAPIConsentSettings,
|
|
18
|
+
EdgeFunctionSettings,
|
|
19
|
+
} from '..';
|
|
20
|
+
import { getUUID } from '../uuid';
|
|
21
|
+
import { createGetter } from './helpers';
|
|
22
|
+
import { isObject, isString } from '../util';
|
|
23
|
+
import type {
|
|
24
|
+
Storage,
|
|
25
|
+
StorageConfig,
|
|
26
|
+
DeepLinkData,
|
|
27
|
+
getStateFunc,
|
|
28
|
+
Watchable,
|
|
29
|
+
Settable,
|
|
30
|
+
Dictionary,
|
|
31
|
+
ReadinessStore,
|
|
32
|
+
Queue,
|
|
33
|
+
} from './types';
|
|
34
|
+
|
|
35
|
+
type Data = {
|
|
36
|
+
context: DeepPartial<Context>;
|
|
37
|
+
settings: SegmentAPIIntegrations;
|
|
38
|
+
consentSettings: SegmentAPIConsentSettings | undefined;
|
|
39
|
+
edgeFunctionSettings: EdgeFunctionSettings | undefined;
|
|
40
|
+
userInfo: UserInfoState;
|
|
41
|
+
filters: DestinationFilters;
|
|
42
|
+
pendingEvents: SegmentEvent[];
|
|
43
|
+
enabled: boolean;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const INITIAL_VALUES: Data = {
|
|
47
|
+
context: {},
|
|
48
|
+
settings: {},
|
|
49
|
+
consentSettings: undefined,
|
|
50
|
+
edgeFunctionSettings: undefined,
|
|
51
|
+
filters: {},
|
|
52
|
+
userInfo: {
|
|
53
|
+
anonymousId: getUUID(),
|
|
54
|
+
userId: undefined,
|
|
55
|
+
traits: undefined,
|
|
56
|
+
},
|
|
57
|
+
pendingEvents: [],
|
|
58
|
+
enabled: true,
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const isEverythingReady = (state: ReadinessStore) =>
|
|
62
|
+
Object.values(state).every((v) => v === true);
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Global store for deeplink information
|
|
66
|
+
* A single instance is needed for all SovranStorage objects since only one deeplink data exists at a time
|
|
67
|
+
* No need to persist this information
|
|
68
|
+
*/
|
|
69
|
+
const deepLinkStore = createStore<DeepLinkData>({
|
|
70
|
+
referring_application: '',
|
|
71
|
+
url: '',
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Action to set the referring app and link url
|
|
76
|
+
* @param deepLinkData referring app and link url
|
|
77
|
+
*/
|
|
78
|
+
const addDeepLinkData = (deepLinkData: unknown) => (state: DeepLinkData) => {
|
|
79
|
+
if (!isObject(deepLinkData)) {
|
|
80
|
+
return state;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return {
|
|
84
|
+
referring_application: deepLinkData.referring_application,
|
|
85
|
+
url: deepLinkData.url,
|
|
86
|
+
} as DeepLinkData;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Registers the deeplink store to listen to native events
|
|
91
|
+
*/
|
|
92
|
+
registerBridgeStore({
|
|
93
|
+
store: deepLinkStore,
|
|
94
|
+
actions: {
|
|
95
|
+
'add-deepLink-data': addDeepLinkData,
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Action to set the anonymousId from native
|
|
101
|
+
* @param anonymousId native anonymousId string
|
|
102
|
+
*/
|
|
103
|
+
|
|
104
|
+
const addAnonymousId =
|
|
105
|
+
(payload: unknown) => (state: { userInfo: UserInfoState }) => {
|
|
106
|
+
if (isObject(payload)) {
|
|
107
|
+
const nativeAnonymousId = payload.anonymousId;
|
|
108
|
+
|
|
109
|
+
if (isString(nativeAnonymousId)) {
|
|
110
|
+
return {
|
|
111
|
+
userInfo: {
|
|
112
|
+
...state.userInfo,
|
|
113
|
+
anonymousId: nativeAnonymousId,
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return state;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
function createStoreGetter<
|
|
122
|
+
U extends object,
|
|
123
|
+
Z extends keyof U | undefined = undefined,
|
|
124
|
+
V = undefined
|
|
125
|
+
>(store: Store<U>, key?: Z): getStateFunc<Z extends keyof U ? V : U> {
|
|
126
|
+
type X = Z extends keyof U ? V : U;
|
|
127
|
+
return createGetter(
|
|
128
|
+
() => {
|
|
129
|
+
const state = store.getState();
|
|
130
|
+
if (key !== undefined) {
|
|
131
|
+
return state[key] as unknown as X;
|
|
132
|
+
}
|
|
133
|
+
return state as X;
|
|
134
|
+
},
|
|
135
|
+
async () => {
|
|
136
|
+
const promise = await store.getState(true);
|
|
137
|
+
if (key !== undefined) {
|
|
138
|
+
return promise[key] as unknown as X;
|
|
139
|
+
}
|
|
140
|
+
return promise as unknown as X;
|
|
141
|
+
}
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export class SovranStorage implements Storage {
|
|
146
|
+
private storeId: string;
|
|
147
|
+
private storePersistor?: Persistor;
|
|
148
|
+
private storePersistorSaveDelay?: number;
|
|
149
|
+
private readinessStore: Store<ReadinessStore>;
|
|
150
|
+
private contextStore: Store<{ context: DeepPartial<Context> }>;
|
|
151
|
+
private consentSettingsStore: Store<{
|
|
152
|
+
consentSettings: SegmentAPIConsentSettings | undefined;
|
|
153
|
+
}>;
|
|
154
|
+
private edgeFunctionSettingsStore: Store<{
|
|
155
|
+
edgeFunctionSettings: EdgeFunctionSettings | undefined;
|
|
156
|
+
}>;
|
|
157
|
+
private settingsStore: Store<{ settings: SegmentAPIIntegrations }>;
|
|
158
|
+
private userInfoStore: Store<{ userInfo: UserInfoState }>;
|
|
159
|
+
private deepLinkStore: Store<DeepLinkData> = deepLinkStore;
|
|
160
|
+
private filtersStore: Store<DestinationFilters>;
|
|
161
|
+
private pendingStore: Store<SegmentEvent[]>;
|
|
162
|
+
|
|
163
|
+
readonly isReady: Watchable<boolean>;
|
|
164
|
+
|
|
165
|
+
readonly context: Watchable<DeepPartial<Context> | undefined> &
|
|
166
|
+
Settable<DeepPartial<Context>>;
|
|
167
|
+
|
|
168
|
+
readonly settings: Watchable<SegmentAPIIntegrations | undefined> &
|
|
169
|
+
Settable<SegmentAPIIntegrations> &
|
|
170
|
+
Dictionary<string, IntegrationSettings, SegmentAPIIntegrations>;
|
|
171
|
+
|
|
172
|
+
readonly consentSettings: Watchable<SegmentAPIConsentSettings | undefined> &
|
|
173
|
+
Settable<SegmentAPIConsentSettings | undefined>;
|
|
174
|
+
|
|
175
|
+
readonly edgeFunctionSettings: Watchable<EdgeFunctionSettings | undefined> &
|
|
176
|
+
Settable<EdgeFunctionSettings | undefined>;
|
|
177
|
+
|
|
178
|
+
readonly filters: Watchable<DestinationFilters | undefined> &
|
|
179
|
+
Settable<DestinationFilters> &
|
|
180
|
+
Dictionary<string, RoutingRule, DestinationFilters>;
|
|
181
|
+
|
|
182
|
+
readonly userInfo: Watchable<UserInfoState> & Settable<UserInfoState>;
|
|
183
|
+
|
|
184
|
+
readonly deepLinkData: Watchable<DeepLinkData>;
|
|
185
|
+
|
|
186
|
+
readonly pendingEvents: Watchable<SegmentEvent[]> &
|
|
187
|
+
Settable<SegmentEvent[]> &
|
|
188
|
+
Queue<SegmentEvent, SegmentEvent[]>;
|
|
189
|
+
|
|
190
|
+
readonly enabledStore: Store<{ enabled: boolean }>;
|
|
191
|
+
readonly enabled: Watchable<boolean> & Settable<boolean>;
|
|
192
|
+
|
|
193
|
+
constructor(config: StorageConfig) {
|
|
194
|
+
this.storeId = config.storeId;
|
|
195
|
+
this.storePersistor = config.storePersistor;
|
|
196
|
+
this.storePersistorSaveDelay = config.storePersistorSaveDelay;
|
|
197
|
+
this.readinessStore = createStore<ReadinessStore>({
|
|
198
|
+
hasRestoredContext: false,
|
|
199
|
+
hasRestoredSettings: false,
|
|
200
|
+
hasRestoredUserInfo: false,
|
|
201
|
+
hasRestoredFilters: false,
|
|
202
|
+
hasRestoredPendingEvents: false,
|
|
203
|
+
hasRestoredEnabled: false,
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
const markAsReadyGenerator = (key: keyof ReadinessStore) => () => {
|
|
207
|
+
void this.readinessStore.dispatch((state) => ({
|
|
208
|
+
...state,
|
|
209
|
+
[key]: true,
|
|
210
|
+
}));
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
this.isReady = {
|
|
214
|
+
get: createGetter(
|
|
215
|
+
() => {
|
|
216
|
+
const state = this.readinessStore.getState();
|
|
217
|
+
return isEverythingReady(state);
|
|
218
|
+
},
|
|
219
|
+
async () => {
|
|
220
|
+
const promise = await this.readinessStore
|
|
221
|
+
.getState(true)
|
|
222
|
+
.then(isEverythingReady);
|
|
223
|
+
return promise;
|
|
224
|
+
}
|
|
225
|
+
),
|
|
226
|
+
onChange: (callback: (value: boolean) => void) => {
|
|
227
|
+
return this.readinessStore.subscribe((store) => {
|
|
228
|
+
if (isEverythingReady(store)) {
|
|
229
|
+
callback(true);
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
},
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
// Context Store
|
|
236
|
+
|
|
237
|
+
this.contextStore = createStore(
|
|
238
|
+
{ context: INITIAL_VALUES.context },
|
|
239
|
+
{
|
|
240
|
+
persist: {
|
|
241
|
+
storeId: `${this.storeId}-context`,
|
|
242
|
+
persistor: this.storePersistor,
|
|
243
|
+
onInitialized: markAsReadyGenerator('hasRestoredContext'),
|
|
244
|
+
},
|
|
245
|
+
}
|
|
246
|
+
);
|
|
247
|
+
this.context = {
|
|
248
|
+
get: createStoreGetter(this.contextStore, 'context'),
|
|
249
|
+
onChange: (callback: (value?: DeepPartial<Context>) => void) =>
|
|
250
|
+
this.contextStore.subscribe((store) => callback(store.context)),
|
|
251
|
+
set: async (value) => {
|
|
252
|
+
const { context } = await this.contextStore.dispatch((state) => {
|
|
253
|
+
let newState: typeof state.context;
|
|
254
|
+
if (value instanceof Function) {
|
|
255
|
+
newState = value(state.context);
|
|
256
|
+
} else {
|
|
257
|
+
newState = deepmerge(state.context, value);
|
|
258
|
+
}
|
|
259
|
+
return { context: newState };
|
|
260
|
+
});
|
|
261
|
+
return context;
|
|
262
|
+
},
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
// Settings Store
|
|
266
|
+
|
|
267
|
+
this.settingsStore = createStore(
|
|
268
|
+
{ settings: INITIAL_VALUES.settings },
|
|
269
|
+
{
|
|
270
|
+
persist: {
|
|
271
|
+
storeId: `${this.storeId}-settings`,
|
|
272
|
+
persistor: this.storePersistor,
|
|
273
|
+
saveDelay: this.storePersistorSaveDelay,
|
|
274
|
+
onInitialized: markAsReadyGenerator('hasRestoredSettings'),
|
|
275
|
+
},
|
|
276
|
+
}
|
|
277
|
+
);
|
|
278
|
+
|
|
279
|
+
this.settings = {
|
|
280
|
+
get: createStoreGetter(this.settingsStore, 'settings'),
|
|
281
|
+
onChange: (
|
|
282
|
+
callback: (value?: SegmentAPIIntegrations | undefined) => void
|
|
283
|
+
) => this.settingsStore.subscribe((store) => callback(store.settings)),
|
|
284
|
+
set: async (value) => {
|
|
285
|
+
const { settings } = await this.settingsStore.dispatch((state) => {
|
|
286
|
+
let newState: typeof state.settings;
|
|
287
|
+
if (value instanceof Function) {
|
|
288
|
+
newState = value(state.settings);
|
|
289
|
+
} else {
|
|
290
|
+
newState = { ...state.settings, ...value };
|
|
291
|
+
}
|
|
292
|
+
return { settings: newState };
|
|
293
|
+
});
|
|
294
|
+
return settings;
|
|
295
|
+
},
|
|
296
|
+
add: (key: string, value: IntegrationSettings) => {
|
|
297
|
+
return this.settingsStore.dispatch((state) => ({
|
|
298
|
+
settings: { ...state.settings, [key]: value },
|
|
299
|
+
}));
|
|
300
|
+
},
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
// Consent settings
|
|
304
|
+
|
|
305
|
+
this.consentSettingsStore = createStore(
|
|
306
|
+
{ consentSettings: INITIAL_VALUES.consentSettings },
|
|
307
|
+
{
|
|
308
|
+
persist: {
|
|
309
|
+
storeId: `${this.storeId}-consentSettings`,
|
|
310
|
+
persistor: this.storePersistor,
|
|
311
|
+
saveDelay: this.storePersistorSaveDelay,
|
|
312
|
+
onInitialized: markAsReadyGenerator('hasRestoredSettings'),
|
|
313
|
+
},
|
|
314
|
+
}
|
|
315
|
+
);
|
|
316
|
+
|
|
317
|
+
this.consentSettings = {
|
|
318
|
+
get: createStoreGetter(this.consentSettingsStore, 'consentSettings'),
|
|
319
|
+
onChange: (
|
|
320
|
+
callback: (value?: SegmentAPIConsentSettings | undefined) => void
|
|
321
|
+
) =>
|
|
322
|
+
this.consentSettingsStore.subscribe((store) =>
|
|
323
|
+
callback(store.consentSettings)
|
|
324
|
+
),
|
|
325
|
+
set: async (value) => {
|
|
326
|
+
const { consentSettings } = await this.consentSettingsStore.dispatch(
|
|
327
|
+
(state) => {
|
|
328
|
+
let newState: typeof state.consentSettings;
|
|
329
|
+
if (value instanceof Function) {
|
|
330
|
+
newState = value(state.consentSettings);
|
|
331
|
+
} else {
|
|
332
|
+
newState = Object.assign({}, state.consentSettings, value);
|
|
333
|
+
}
|
|
334
|
+
return { consentSettings: newState };
|
|
335
|
+
}
|
|
336
|
+
);
|
|
337
|
+
return consentSettings;
|
|
338
|
+
},
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
// Edge function settings
|
|
342
|
+
|
|
343
|
+
this.edgeFunctionSettingsStore = createStore(
|
|
344
|
+
{ edgeFunctionSettings: INITIAL_VALUES.edgeFunctionSettings },
|
|
345
|
+
{
|
|
346
|
+
persist: {
|
|
347
|
+
storeId: `${this.storeId}-edgeFunctionSettings`,
|
|
348
|
+
persistor: this.storePersistor,
|
|
349
|
+
saveDelay: this.storePersistorSaveDelay,
|
|
350
|
+
onInitialized: markAsReadyGenerator('hasRestoredSettings'),
|
|
351
|
+
},
|
|
352
|
+
}
|
|
353
|
+
);
|
|
354
|
+
|
|
355
|
+
this.edgeFunctionSettings = {
|
|
356
|
+
get: createStoreGetter(
|
|
357
|
+
this.edgeFunctionSettingsStore,
|
|
358
|
+
'edgeFunctionSettings'
|
|
359
|
+
),
|
|
360
|
+
onChange: (
|
|
361
|
+
callback: (value?: EdgeFunctionSettings | undefined) => void
|
|
362
|
+
) =>
|
|
363
|
+
this.edgeFunctionSettingsStore.subscribe((store) =>
|
|
364
|
+
callback(store.edgeFunctionSettings)
|
|
365
|
+
),
|
|
366
|
+
set: async (value) => {
|
|
367
|
+
const { edgeFunctionSettings } =
|
|
368
|
+
await this.edgeFunctionSettingsStore.dispatch((state) => {
|
|
369
|
+
let newState: typeof state.edgeFunctionSettings;
|
|
370
|
+
if (value instanceof Function) {
|
|
371
|
+
newState = value(state.edgeFunctionSettings);
|
|
372
|
+
} else {
|
|
373
|
+
newState = Object.assign({}, state.edgeFunctionSettings, value);
|
|
374
|
+
}
|
|
375
|
+
return { edgeFunctionSettings: newState };
|
|
376
|
+
});
|
|
377
|
+
return edgeFunctionSettings;
|
|
378
|
+
},
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
// Filters
|
|
382
|
+
|
|
383
|
+
this.filtersStore = createStore(INITIAL_VALUES.filters, {
|
|
384
|
+
persist: {
|
|
385
|
+
storeId: `${this.storeId}-filters`,
|
|
386
|
+
persistor: this.storePersistor,
|
|
387
|
+
saveDelay: this.storePersistorSaveDelay,
|
|
388
|
+
onInitialized: markAsReadyGenerator('hasRestoredFilters'),
|
|
389
|
+
},
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
this.filters = {
|
|
393
|
+
get: createStoreGetter(this.filtersStore),
|
|
394
|
+
onChange: (callback: (value?: DestinationFilters | undefined) => void) =>
|
|
395
|
+
this.filtersStore.subscribe((store) => callback(store)),
|
|
396
|
+
set: async (value) => {
|
|
397
|
+
const filters = await this.filtersStore.dispatch((state) => {
|
|
398
|
+
let newState: typeof state;
|
|
399
|
+
if (value instanceof Function) {
|
|
400
|
+
newState = value(state);
|
|
401
|
+
} else {
|
|
402
|
+
newState = { ...state, ...value };
|
|
403
|
+
}
|
|
404
|
+
return newState;
|
|
405
|
+
});
|
|
406
|
+
return filters;
|
|
407
|
+
},
|
|
408
|
+
add: (key, value) => {
|
|
409
|
+
return this.filtersStore.dispatch((state) => ({
|
|
410
|
+
...state,
|
|
411
|
+
[key]: value,
|
|
412
|
+
}));
|
|
413
|
+
},
|
|
414
|
+
};
|
|
415
|
+
|
|
416
|
+
// User Info Store
|
|
417
|
+
|
|
418
|
+
this.userInfoStore = createStore(
|
|
419
|
+
{ userInfo: INITIAL_VALUES.userInfo },
|
|
420
|
+
{
|
|
421
|
+
persist: {
|
|
422
|
+
storeId: `${this.storeId}-userInfo`,
|
|
423
|
+
persistor: this.storePersistor,
|
|
424
|
+
saveDelay: this.storePersistorSaveDelay,
|
|
425
|
+
onInitialized: markAsReadyGenerator('hasRestoredUserInfo'),
|
|
426
|
+
},
|
|
427
|
+
}
|
|
428
|
+
);
|
|
429
|
+
|
|
430
|
+
this.userInfo = {
|
|
431
|
+
get: createStoreGetter(this.userInfoStore, 'userInfo'),
|
|
432
|
+
onChange: (callback: (value: UserInfoState) => void) =>
|
|
433
|
+
this.userInfoStore.subscribe((store) => callback(store.userInfo)),
|
|
434
|
+
set: async (value) => {
|
|
435
|
+
const { userInfo } = await this.userInfoStore.dispatch((state) => {
|
|
436
|
+
let newState: typeof state.userInfo;
|
|
437
|
+
if (value instanceof Function) {
|
|
438
|
+
newState = value(state.userInfo);
|
|
439
|
+
} else {
|
|
440
|
+
newState = deepmerge(state.userInfo, value);
|
|
441
|
+
}
|
|
442
|
+
return { userInfo: newState };
|
|
443
|
+
});
|
|
444
|
+
return userInfo;
|
|
445
|
+
},
|
|
446
|
+
};
|
|
447
|
+
|
|
448
|
+
// Pending Events
|
|
449
|
+
this.pendingStore = createStore<SegmentEvent[]>(
|
|
450
|
+
INITIAL_VALUES.pendingEvents,
|
|
451
|
+
{
|
|
452
|
+
persist: {
|
|
453
|
+
storeId: `${this.storeId}-pendingEvents`,
|
|
454
|
+
persistor: this.storePersistor,
|
|
455
|
+
saveDelay: this.storePersistorSaveDelay,
|
|
456
|
+
onInitialized: markAsReadyGenerator('hasRestoredPendingEvents'),
|
|
457
|
+
},
|
|
458
|
+
}
|
|
459
|
+
);
|
|
460
|
+
|
|
461
|
+
this.pendingEvents = {
|
|
462
|
+
get: createStoreGetter(this.pendingStore),
|
|
463
|
+
onChange: (callback: (value: SegmentEvent[]) => void) =>
|
|
464
|
+
this.pendingStore.subscribe((store) => callback(store)),
|
|
465
|
+
set: async (value) => {
|
|
466
|
+
return await this.pendingStore.dispatch((state) => {
|
|
467
|
+
let newState: SegmentEvent[];
|
|
468
|
+
if (value instanceof Function) {
|
|
469
|
+
newState = value(state);
|
|
470
|
+
} else {
|
|
471
|
+
newState = [...value];
|
|
472
|
+
}
|
|
473
|
+
return newState;
|
|
474
|
+
});
|
|
475
|
+
},
|
|
476
|
+
add: (event: SegmentEvent) => {
|
|
477
|
+
return this.pendingStore.dispatch((events) => [...events, event]);
|
|
478
|
+
},
|
|
479
|
+
remove: (event: SegmentEvent) => {
|
|
480
|
+
return this.pendingStore.dispatch((events) =>
|
|
481
|
+
events.filter((e) => e.messageId != event.messageId)
|
|
482
|
+
);
|
|
483
|
+
},
|
|
484
|
+
};
|
|
485
|
+
|
|
486
|
+
registerBridgeStore({
|
|
487
|
+
store: this.userInfoStore,
|
|
488
|
+
actions: {
|
|
489
|
+
'add-anonymous-id': addAnonymousId,
|
|
490
|
+
},
|
|
491
|
+
});
|
|
492
|
+
|
|
493
|
+
this.deepLinkData = {
|
|
494
|
+
get: createStoreGetter(this.deepLinkStore),
|
|
495
|
+
onChange: (callback: (value: DeepLinkData) => void) =>
|
|
496
|
+
this.deepLinkStore.subscribe(callback),
|
|
497
|
+
};
|
|
498
|
+
|
|
499
|
+
this.enabledStore = createStore(
|
|
500
|
+
{ enabled: INITIAL_VALUES.enabled },
|
|
501
|
+
{
|
|
502
|
+
persist: {
|
|
503
|
+
storeId: `${this.storeId}-enabled`,
|
|
504
|
+
persistor: this.storePersistor,
|
|
505
|
+
saveDelay: this.storePersistorSaveDelay,
|
|
506
|
+
onInitialized: markAsReadyGenerator('hasRestoredEnabled'),
|
|
507
|
+
},
|
|
508
|
+
}
|
|
509
|
+
);
|
|
510
|
+
// Accessor object for enabled
|
|
511
|
+
this.enabled = {
|
|
512
|
+
get: createGetter(
|
|
513
|
+
() => {
|
|
514
|
+
const state = this.enabledStore.getState();
|
|
515
|
+
return state.enabled;
|
|
516
|
+
},
|
|
517
|
+
async () => {
|
|
518
|
+
const value = await this.enabledStore.getState(true);
|
|
519
|
+
return value.enabled;
|
|
520
|
+
}
|
|
521
|
+
),
|
|
522
|
+
|
|
523
|
+
onChange: (callback: (value: boolean) => void) => {
|
|
524
|
+
return this.enabledStore.subscribe((store) => {
|
|
525
|
+
callback(store.enabled);
|
|
526
|
+
});
|
|
527
|
+
},
|
|
528
|
+
|
|
529
|
+
set: async (value: boolean | ((prev: boolean) => boolean)) => {
|
|
530
|
+
const { enabled } = await this.enabledStore.dispatch((state) => {
|
|
531
|
+
const newEnabled =
|
|
532
|
+
value instanceof Function ? value(state.enabled) : value;
|
|
533
|
+
return { enabled: newEnabled };
|
|
534
|
+
});
|
|
535
|
+
return enabled;
|
|
536
|
+
},
|
|
537
|
+
};
|
|
538
|
+
|
|
539
|
+
|
|
540
|
+
this.fixAnonymousId();
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
/**
|
|
544
|
+
* This is a fix for users that have started the app with the anonymousId set to 'anonymousId' bug
|
|
545
|
+
*/
|
|
546
|
+
private fixAnonymousId = () => {
|
|
547
|
+
const fixUnsubscribe = this.userInfoStore.subscribe((store) => {
|
|
548
|
+
if (store.userInfo.anonymousId === 'anonymousId') {
|
|
549
|
+
void this.userInfoStore.dispatch((state) => {
|
|
550
|
+
return {
|
|
551
|
+
userInfo: { ...state.userInfo, anonymousId: getUUID() },
|
|
552
|
+
};
|
|
553
|
+
});
|
|
554
|
+
}
|
|
555
|
+
fixUnsubscribe();
|
|
556
|
+
});
|
|
557
|
+
};
|
|
558
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { Unsubscribe, Persistor } from '@segment/sovran-react-native';
|
|
2
|
+
import type { SegmentAPIConsentSettings, EdgeFunctionSettings } from '..';
|
|
3
|
+
import type {
|
|
4
|
+
Context,
|
|
5
|
+
DeepPartial,
|
|
6
|
+
DestinationFilters,
|
|
7
|
+
IntegrationSettings,
|
|
8
|
+
RoutingRule,
|
|
9
|
+
SegmentAPIIntegrations,
|
|
10
|
+
SegmentEvent,
|
|
11
|
+
UserInfoState,
|
|
12
|
+
} from '../types';
|
|
13
|
+
|
|
14
|
+
export interface getStateFunc<T> {
|
|
15
|
+
(): T;
|
|
16
|
+
(safe: true): Promise<T>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Implements a value that can be subscribed for changes
|
|
21
|
+
*/
|
|
22
|
+
export interface Watchable<T> {
|
|
23
|
+
/**
|
|
24
|
+
* Get current value
|
|
25
|
+
*/
|
|
26
|
+
get: getStateFunc<T>;
|
|
27
|
+
/**
|
|
28
|
+
* Register a callback to be called when the value changes
|
|
29
|
+
* @returns a function to unsubscribe
|
|
30
|
+
*/
|
|
31
|
+
onChange: (callback: (value: T) => void) => Unsubscribe;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Implements a value that can be set
|
|
36
|
+
*/
|
|
37
|
+
export interface Settable<T> {
|
|
38
|
+
set: (value: T | ((state: T) => T)) => T | Promise<T>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Implements a queue object
|
|
43
|
+
*/
|
|
44
|
+
export interface Queue<T, R> {
|
|
45
|
+
add: (value: T) => Promise<R>;
|
|
46
|
+
remove: (value: T) => Promise<R>;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Implements a map of key value pairs
|
|
51
|
+
*/
|
|
52
|
+
export interface Dictionary<K, T, R> {
|
|
53
|
+
add: (key: K, value: T) => Promise<R>;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface ReadinessStore {
|
|
57
|
+
hasRestoredContext: boolean;
|
|
58
|
+
hasRestoredSettings: boolean;
|
|
59
|
+
hasRestoredUserInfo: boolean;
|
|
60
|
+
hasRestoredFilters: boolean;
|
|
61
|
+
hasRestoredPendingEvents: boolean;
|
|
62
|
+
hasRestoredEnabled: boolean;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Interface for interacting with the storage layer of the client data
|
|
67
|
+
*/
|
|
68
|
+
export interface Storage {
|
|
69
|
+
readonly isReady: Watchable<boolean>;
|
|
70
|
+
|
|
71
|
+
readonly context: Watchable<DeepPartial<Context> | undefined> &
|
|
72
|
+
Settable<DeepPartial<Context>>;
|
|
73
|
+
|
|
74
|
+
readonly settings: Watchable<SegmentAPIIntegrations | undefined> &
|
|
75
|
+
Settable<SegmentAPIIntegrations> &
|
|
76
|
+
Dictionary<string, IntegrationSettings, SegmentAPIIntegrations>;
|
|
77
|
+
|
|
78
|
+
readonly consentSettings: Watchable<SegmentAPIConsentSettings | undefined> &
|
|
79
|
+
Settable<SegmentAPIConsentSettings | undefined>;
|
|
80
|
+
|
|
81
|
+
readonly edgeFunctionSettings: Watchable<EdgeFunctionSettings | undefined> &
|
|
82
|
+
Settable<EdgeFunctionSettings | undefined>;
|
|
83
|
+
|
|
84
|
+
readonly filters: Watchable<DestinationFilters | undefined> &
|
|
85
|
+
Settable<DestinationFilters> &
|
|
86
|
+
Dictionary<string, RoutingRule, DestinationFilters>;
|
|
87
|
+
|
|
88
|
+
readonly userInfo: Watchable<UserInfoState> & Settable<UserInfoState>;
|
|
89
|
+
|
|
90
|
+
readonly deepLinkData: Watchable<DeepLinkData>;
|
|
91
|
+
|
|
92
|
+
readonly pendingEvents: Watchable<SegmentEvent[]> &
|
|
93
|
+
Settable<SegmentEvent[]> &
|
|
94
|
+
Queue<SegmentEvent, SegmentEvent[]>;
|
|
95
|
+
readonly enabled: Watchable<boolean> & Settable<boolean>;
|
|
96
|
+
}
|
|
97
|
+
export type DeepLinkData = {
|
|
98
|
+
referring_application: string;
|
|
99
|
+
url: string;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
export type StorageConfig = {
|
|
103
|
+
storeId: string;
|
|
104
|
+
storePersistor?: Persistor;
|
|
105
|
+
storePersistorSaveDelay?: number;
|
|
106
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { SegmentEvent } from '../types';
|
|
2
|
+
import { createMockStoreGetter } from './mockSegmentStore';
|
|
3
|
+
import { createCallbackManager } from './utils';
|
|
4
|
+
|
|
5
|
+
export class MockEventStore {
|
|
6
|
+
private initialData: SegmentEvent[] = [];
|
|
7
|
+
private events: SegmentEvent[] = [];
|
|
8
|
+
|
|
9
|
+
private callbackManager = createCallbackManager<{ events: SegmentEvent[] }>();
|
|
10
|
+
|
|
11
|
+
constructor(initialData?: SegmentEvent[]) {
|
|
12
|
+
this.events = [...(initialData ?? [])];
|
|
13
|
+
this.initialData = JSON.parse(
|
|
14
|
+
JSON.stringify(initialData ?? [])
|
|
15
|
+
) as SegmentEvent[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
reset = () => {
|
|
19
|
+
this.events = JSON.parse(
|
|
20
|
+
JSON.stringify(this.initialData)
|
|
21
|
+
) as SegmentEvent[];
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
getState = createMockStoreGetter(() => ({ events: this.events }));
|
|
25
|
+
|
|
26
|
+
subscribe = (callback: (value: { events: SegmentEvent[] }) => void) =>
|
|
27
|
+
this.callbackManager.register(callback);
|
|
28
|
+
|
|
29
|
+
dispatch = (
|
|
30
|
+
callback: (value: { events: SegmentEvent[] }) => { events: SegmentEvent[] }
|
|
31
|
+
) => {
|
|
32
|
+
this.events = callback({ events: this.events }).events;
|
|
33
|
+
this.callbackManager.run({ events: this.events });
|
|
34
|
+
};
|
|
35
|
+
}
|