@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,397 @@
|
|
|
1
|
+
import type { Persistor } from '..';
|
|
2
|
+
import { createStore, Store, StoreConfig } from '../store';
|
|
3
|
+
|
|
4
|
+
interface Event {
|
|
5
|
+
id: string;
|
|
6
|
+
description: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
type EventStore = { events: Event[] };
|
|
10
|
+
|
|
11
|
+
describe('Sovran', () => {
|
|
12
|
+
it('should work', async () => {
|
|
13
|
+
// Create a new store
|
|
14
|
+
const sovran = createStore<EventStore>({ events: [] });
|
|
15
|
+
|
|
16
|
+
// Setup a subscription callback
|
|
17
|
+
const subscription = jest.fn();
|
|
18
|
+
sovran.subscribe(subscription);
|
|
19
|
+
|
|
20
|
+
const sampleEvent: Event = {
|
|
21
|
+
id: '1',
|
|
22
|
+
description: 'test',
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const expectedState = {
|
|
26
|
+
events: [sampleEvent],
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// Dispatch an action to add a new event in our store
|
|
30
|
+
await sovran.dispatch((state) => {
|
|
31
|
+
return {
|
|
32
|
+
events: [...state.events, sampleEvent],
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// Subscription gets called
|
|
37
|
+
expect(subscription).toHaveBeenCalledWith(expectedState);
|
|
38
|
+
|
|
39
|
+
// And we can also access state from here
|
|
40
|
+
expect(sovran.getState()).toEqual(expectedState);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('should work with multiple stores', async () => {
|
|
44
|
+
const sovran = createStore<EventStore>({ events: [] });
|
|
45
|
+
const sovran2 = createStore<EventStore>({ events: [] });
|
|
46
|
+
const subscription = jest.fn();
|
|
47
|
+
const subscription2 = jest.fn();
|
|
48
|
+
sovran.subscribe(subscription);
|
|
49
|
+
sovran2.subscribe(subscription2);
|
|
50
|
+
|
|
51
|
+
const sampleEvent: Event = {
|
|
52
|
+
id: '1',
|
|
53
|
+
description: 'test',
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const expectedState = {
|
|
57
|
+
events: [sampleEvent],
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
await sovran.dispatch((state) => {
|
|
61
|
+
return {
|
|
62
|
+
events: [...state.events, sampleEvent],
|
|
63
|
+
};
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
expect(subscription).toHaveBeenCalledWith(expectedState);
|
|
67
|
+
expect(subscription2).not.toHaveBeenCalled();
|
|
68
|
+
|
|
69
|
+
expect(sovran.getState()).toEqual(expectedState);
|
|
70
|
+
expect(sovran2.getState()).toEqual({ events: [] });
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('should work with multiple subscribers', async () => {
|
|
74
|
+
const sovran = createStore<EventStore>({ events: [] });
|
|
75
|
+
const subscription = jest.fn();
|
|
76
|
+
const subscription2 = jest.fn();
|
|
77
|
+
sovran.subscribe(subscription);
|
|
78
|
+
sovran.subscribe(subscription2);
|
|
79
|
+
|
|
80
|
+
const sampleEvent: Event = {
|
|
81
|
+
id: '1',
|
|
82
|
+
description: 'test',
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const expectedState = {
|
|
86
|
+
events: [sampleEvent],
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
await sovran.dispatch((state) => {
|
|
90
|
+
return {
|
|
91
|
+
events: [...state.events, sampleEvent],
|
|
92
|
+
};
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
expect(subscription).toHaveBeenCalledWith(expectedState);
|
|
96
|
+
expect(subscription2).toHaveBeenCalledWith(expectedState);
|
|
97
|
+
|
|
98
|
+
expect(sovran.getState()).toEqual(expectedState);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('should work with multiple events sent', async () => {
|
|
102
|
+
const sovran = createStore<EventStore>({ events: [] });
|
|
103
|
+
const n = 100;
|
|
104
|
+
|
|
105
|
+
for (let i = 0; i < n; i++) {
|
|
106
|
+
const sampleEvent: Event = {
|
|
107
|
+
id: i.toString(),
|
|
108
|
+
description: `test ${i}`,
|
|
109
|
+
};
|
|
110
|
+
await sovran.dispatch((state) => {
|
|
111
|
+
return {
|
|
112
|
+
events: [...state.events, sampleEvent],
|
|
113
|
+
};
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
expect(sovran.getState().events.length).toEqual(n);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('should handle unsubscribe', async () => {
|
|
121
|
+
// Create a new store
|
|
122
|
+
const sovran = createStore<EventStore>({ events: [] });
|
|
123
|
+
|
|
124
|
+
// Setup a subscription callback
|
|
125
|
+
const subscription = jest.fn();
|
|
126
|
+
const unsubscribe = sovran.subscribe(subscription);
|
|
127
|
+
|
|
128
|
+
// Now unsubscribe
|
|
129
|
+
unsubscribe();
|
|
130
|
+
|
|
131
|
+
const sampleEvent: Event = {
|
|
132
|
+
id: '1',
|
|
133
|
+
description: 'test',
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const expectedState = {
|
|
137
|
+
events: [sampleEvent],
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
// Dispatch an action to add a new event in our store
|
|
141
|
+
await sovran.dispatch((state) => {
|
|
142
|
+
return {
|
|
143
|
+
events: [...state.events, sampleEvent],
|
|
144
|
+
};
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
// Subscription gets called
|
|
148
|
+
expect(subscription).not.toHaveBeenCalled();
|
|
149
|
+
|
|
150
|
+
// And we can also access state from here
|
|
151
|
+
expect(sovran.getState()).toEqual(expectedState);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it("should not call subscribers if the state didn't change", async () => {
|
|
155
|
+
const sampleEvent: Event = {
|
|
156
|
+
id: '1',
|
|
157
|
+
description: 'test',
|
|
158
|
+
};
|
|
159
|
+
// Create a new store
|
|
160
|
+
const sovran = createStore<EventStore>({ events: [sampleEvent] });
|
|
161
|
+
|
|
162
|
+
// Setup a subscription callback
|
|
163
|
+
const subscription = jest.fn();
|
|
164
|
+
sovran.subscribe(subscription);
|
|
165
|
+
|
|
166
|
+
const expectedState = {
|
|
167
|
+
events: [sampleEvent],
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
// Dispatch an action that doesn't change the state
|
|
171
|
+
await sovran.dispatch((state) => {
|
|
172
|
+
return state;
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
// Subscription gets called
|
|
176
|
+
expect(subscription).not.toHaveBeenCalled();
|
|
177
|
+
|
|
178
|
+
// And we can also access state from here
|
|
179
|
+
expect(sovran.getState()).toEqual(expectedState);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it('should handle gracefully errors in actions', async () => {
|
|
183
|
+
const sampleEvent: Event = {
|
|
184
|
+
id: '1',
|
|
185
|
+
description: 'test',
|
|
186
|
+
};
|
|
187
|
+
// Create a new store
|
|
188
|
+
const sovran = createStore<EventStore>({ events: [sampleEvent] });
|
|
189
|
+
|
|
190
|
+
// Setup a subscription callback
|
|
191
|
+
const subscription = jest.fn();
|
|
192
|
+
sovran.subscribe(subscription);
|
|
193
|
+
|
|
194
|
+
const expectedState = {
|
|
195
|
+
events: [sampleEvent],
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
// Dispatch an action that doesn't change the state
|
|
199
|
+
await sovran.dispatch(() => {
|
|
200
|
+
throw new Error('Whoops!');
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
// Subscription gets called
|
|
204
|
+
expect(subscription).not.toHaveBeenCalled();
|
|
205
|
+
|
|
206
|
+
// And we can also access state from here
|
|
207
|
+
expect(sovran.getState()).toEqual(expectedState);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it('should support listeners calling unsubscribe from their handling code', async () => {
|
|
211
|
+
// Create a new store
|
|
212
|
+
const sovran = createStore<EventStore>({ events: [] });
|
|
213
|
+
|
|
214
|
+
// Setup a couple of subscriptions
|
|
215
|
+
const onlyOnceSubscription = jest.fn();
|
|
216
|
+
const unsubscribe = sovran.subscribe(
|
|
217
|
+
onlyOnceSubscription.mockImplementation(() => {
|
|
218
|
+
unsubscribe();
|
|
219
|
+
})
|
|
220
|
+
);
|
|
221
|
+
const anotherSubscription = jest.fn();
|
|
222
|
+
sovran.subscribe(anotherSubscription);
|
|
223
|
+
|
|
224
|
+
// Dispatch an action to add a new event in our store
|
|
225
|
+
await sovran.dispatch((state) => {
|
|
226
|
+
return {
|
|
227
|
+
events: [
|
|
228
|
+
...state.events,
|
|
229
|
+
{
|
|
230
|
+
id: '1',
|
|
231
|
+
description: 'test',
|
|
232
|
+
},
|
|
233
|
+
],
|
|
234
|
+
};
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
// Now send another event
|
|
238
|
+
await sovran.dispatch((state) => {
|
|
239
|
+
return {
|
|
240
|
+
events: [
|
|
241
|
+
...state.events,
|
|
242
|
+
{
|
|
243
|
+
id: '2',
|
|
244
|
+
description: 'test',
|
|
245
|
+
},
|
|
246
|
+
],
|
|
247
|
+
};
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
// The once subscription should have been called only once, the other one every update
|
|
251
|
+
expect(onlyOnceSubscription).toHaveBeenCalledTimes(1);
|
|
252
|
+
expect(anotherSubscription).toHaveBeenCalledTimes(2);
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Tests the persistence calls of the Store to comply to the interface
|
|
257
|
+
*/
|
|
258
|
+
describe('Persistence', () => {
|
|
259
|
+
const getMockPersistor = <T>(initialState: T): Persistor => {
|
|
260
|
+
return {
|
|
261
|
+
get: jest.fn().mockResolvedValue(initialState),
|
|
262
|
+
set: jest.fn(),
|
|
263
|
+
};
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
const getAwaitableSovranConstructor = async <T extends object>(
|
|
267
|
+
initialState: T,
|
|
268
|
+
config: StoreConfig
|
|
269
|
+
): Promise<Store<T>> => {
|
|
270
|
+
// This weird looking thing is to block the jest runner to wait until the persistor is initialized using the usual async/await instead of weird callbacks
|
|
271
|
+
return await new Promise((resolve) => {
|
|
272
|
+
const sovran: Store<T> = createStore<T>(initialState, {
|
|
273
|
+
...config,
|
|
274
|
+
persist: {
|
|
275
|
+
storeId: 'test',
|
|
276
|
+
...config.persist,
|
|
277
|
+
onInitialized: () => resolve(sovran),
|
|
278
|
+
},
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
beforeEach(() => {
|
|
284
|
+
// Using legacy fake timers cause the modern type have a conflict with async/await that we use everywhere here
|
|
285
|
+
jest.useFakeTimers({ legacyFakeTimers: true });
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
it('calls the persistor on init and after the delay', async () => {
|
|
289
|
+
const ID = 'persistorTest';
|
|
290
|
+
const INTERVAL = 5000;
|
|
291
|
+
|
|
292
|
+
const persistedEvent: Event = {
|
|
293
|
+
id: '0',
|
|
294
|
+
description: 'myPersistedEvent',
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
const persistedState = { events: [persistedEvent] };
|
|
298
|
+
|
|
299
|
+
const mockPesistor: Persistor = getMockPersistor(persistedState);
|
|
300
|
+
|
|
301
|
+
const sovran = await getAwaitableSovranConstructor<EventStore>(
|
|
302
|
+
{ events: [] },
|
|
303
|
+
{
|
|
304
|
+
persist: {
|
|
305
|
+
storeId: ID,
|
|
306
|
+
saveDelay: INTERVAL,
|
|
307
|
+
persistor: mockPesistor,
|
|
308
|
+
},
|
|
309
|
+
}
|
|
310
|
+
);
|
|
311
|
+
|
|
312
|
+
// The persistor should have been called and the state should be updated
|
|
313
|
+
expect(sovran.getState()).toEqual(persistedState);
|
|
314
|
+
expect(mockPesistor.get).toHaveBeenCalledTimes(1);
|
|
315
|
+
|
|
316
|
+
// Now add a new event, then see if the state is persisted after a timeout
|
|
317
|
+
|
|
318
|
+
const sampleEvent: Event = {
|
|
319
|
+
id: '1',
|
|
320
|
+
description: 'test',
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
const expectedState = {
|
|
324
|
+
events: [persistedEvent, sampleEvent],
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
// Dispatch an action to add a new event in our store
|
|
328
|
+
await sovran.dispatch((state) => {
|
|
329
|
+
return {
|
|
330
|
+
events: [...state.events, sampleEvent],
|
|
331
|
+
};
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
// And we can also access state from here
|
|
335
|
+
expect(sovran.getState()).toEqual(expectedState);
|
|
336
|
+
|
|
337
|
+
jest.advanceTimersByTime(INTERVAL);
|
|
338
|
+
|
|
339
|
+
expect(mockPesistor.set).toHaveBeenCalledWith(ID, expectedState);
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
it('saves initial state if storage is empty on startup', async () => {
|
|
343
|
+
const ID = 'persistorTest';
|
|
344
|
+
const INTERVAL = 5000;
|
|
345
|
+
|
|
346
|
+
// Nothing is in the persisted state
|
|
347
|
+
const persistedState = undefined;
|
|
348
|
+
// But we have a default initial state for sovran
|
|
349
|
+
const sampleEvent: Event = {
|
|
350
|
+
id: '1',
|
|
351
|
+
description: 'test',
|
|
352
|
+
};
|
|
353
|
+
const initialState = { events: [sampleEvent] };
|
|
354
|
+
|
|
355
|
+
const mockPesistor: Persistor = getMockPersistor(persistedState);
|
|
356
|
+
|
|
357
|
+
const sovran = await getAwaitableSovranConstructor<EventStore>(
|
|
358
|
+
initialState,
|
|
359
|
+
{
|
|
360
|
+
persist: {
|
|
361
|
+
storeId: ID,
|
|
362
|
+
saveDelay: INTERVAL,
|
|
363
|
+
persistor: mockPesistor,
|
|
364
|
+
},
|
|
365
|
+
}
|
|
366
|
+
);
|
|
367
|
+
|
|
368
|
+
// The initial state should have been persisted, state should match initial
|
|
369
|
+
expect(sovran.getState()).toEqual(initialState);
|
|
370
|
+
expect(mockPesistor.get).toHaveBeenCalledTimes(1);
|
|
371
|
+
expect(mockPesistor.set).toHaveBeenCalledWith(ID, initialState);
|
|
372
|
+
});
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
describe('Concurrency', () => {
|
|
376
|
+
it('handles concurrent writes and reads with the safe option', async () => {
|
|
377
|
+
const sovran = createStore<EventStore>({ events: [] });
|
|
378
|
+
|
|
379
|
+
const p1 = sovran.dispatch(() => {
|
|
380
|
+
return {
|
|
381
|
+
events: [
|
|
382
|
+
{
|
|
383
|
+
id: '1',
|
|
384
|
+
description: 'test',
|
|
385
|
+
},
|
|
386
|
+
],
|
|
387
|
+
};
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
const p2 = sovran.getState(true);
|
|
391
|
+
|
|
392
|
+
await Promise.all([p1, p2]).then(([s1, s2]) => {
|
|
393
|
+
expect(s1).toEqual(s2);
|
|
394
|
+
});
|
|
395
|
+
});
|
|
396
|
+
});
|
|
397
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { Action, Store } from './store';
|
|
2
|
+
|
|
3
|
+
type ActionCreator<P, S> = (payload: P) => Action<S>;
|
|
4
|
+
|
|
5
|
+
interface BridgeStore<T extends object> {
|
|
6
|
+
store: Store<T>;
|
|
7
|
+
actions: { [key: string]: ActionCreator<unknown, T> };
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface StoreAction<P, S extends object> {
|
|
11
|
+
key: string;
|
|
12
|
+
store: Store<S>;
|
|
13
|
+
actionCreator: ActionCreator<P, S>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const actionMap: { [key: string]: StoreAction<unknown, object>[] } = {};
|
|
17
|
+
|
|
18
|
+
export const registerBridgeStore = <T extends object>(
|
|
19
|
+
...stores: BridgeStore<T>[]
|
|
20
|
+
): void => {
|
|
21
|
+
for (const store of stores) {
|
|
22
|
+
for (const [key, actionCreator] of Object.entries(store.actions)) {
|
|
23
|
+
if (actionMap[key] === undefined) {
|
|
24
|
+
actionMap[key] = [];
|
|
25
|
+
}
|
|
26
|
+
actionMap[key].push({
|
|
27
|
+
key,
|
|
28
|
+
store: store.store as unknown as Store<object>,
|
|
29
|
+
actionCreator: actionCreator as unknown as ActionCreator<
|
|
30
|
+
unknown,
|
|
31
|
+
object
|
|
32
|
+
>,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export const onStoreAction = async <T>(
|
|
39
|
+
event: string,
|
|
40
|
+
payload: T
|
|
41
|
+
): Promise<void> => {
|
|
42
|
+
if (actionMap[event] !== undefined && actionMap[event].length > 0) {
|
|
43
|
+
const actions = actionMap[event];
|
|
44
|
+
for (const action of actions) {
|
|
45
|
+
await action.store.dispatch(action.actionCreator(payload));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import {
|
|
2
|
+
NativeEventEmitter,
|
|
3
|
+
NativeModule,
|
|
4
|
+
NativeModules,
|
|
5
|
+
Platform,
|
|
6
|
+
TurboModule,
|
|
7
|
+
} from 'react-native';
|
|
8
|
+
import { onStoreAction } from './bridge';
|
|
9
|
+
|
|
10
|
+
const LINKING_ERROR =
|
|
11
|
+
"The package 'sovran-react-native' doesn't seem to be linked. Make sure: \n\n" +
|
|
12
|
+
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
|
|
13
|
+
'- You rebuilt the app after installing the package\n' +
|
|
14
|
+
'- You are not using Expo managed workflow\n';
|
|
15
|
+
|
|
16
|
+
const Sovran = NativeModules.Sovran as NativeModule;
|
|
17
|
+
|
|
18
|
+
type NativeModuleConstants = { ON_STORE_ACTION: string };
|
|
19
|
+
|
|
20
|
+
if (Sovran !== undefined && Sovran !== null) {
|
|
21
|
+
const { ON_STORE_ACTION } = ((
|
|
22
|
+
Sovran as unknown as TurboModule
|
|
23
|
+
).getConstants?.() as NativeModuleConstants) ?? {
|
|
24
|
+
ON_STORE_ACTION: '',
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const SovranBridge = new NativeEventEmitter(Sovran);
|
|
28
|
+
|
|
29
|
+
// Listen to Native events
|
|
30
|
+
SovranBridge.addListener(
|
|
31
|
+
ON_STORE_ACTION,
|
|
32
|
+
(event: { type: string; payload: unknown }) => {
|
|
33
|
+
void (async () => {
|
|
34
|
+
try {
|
|
35
|
+
await onStoreAction(event.type, event.payload);
|
|
36
|
+
} catch (error) {
|
|
37
|
+
console.warn(error);
|
|
38
|
+
}
|
|
39
|
+
})();
|
|
40
|
+
}
|
|
41
|
+
);
|
|
42
|
+
} else {
|
|
43
|
+
console.warn(LINKING_ERROR);
|
|
44
|
+
}
|
|
45
|
+
export {
|
|
46
|
+
createStore,
|
|
47
|
+
type Store,
|
|
48
|
+
type Notify,
|
|
49
|
+
type Unsubscribe,
|
|
50
|
+
} from './store';
|
|
51
|
+
export { registerBridgeStore } from './bridge';
|
|
52
|
+
export * from './persistor';
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { Persistor } from './persistor';
|
|
2
|
+
|
|
3
|
+
let AsyncStorage: {
|
|
4
|
+
getItem: (key: string) => Promise<string | null>;
|
|
5
|
+
setItem: (key: string, value: string) => Promise<void>;
|
|
6
|
+
} | null;
|
|
7
|
+
|
|
8
|
+
try {
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
10
|
+
AsyncStorage = require('@react-native-async-storage/async-storage').default;
|
|
11
|
+
} catch (error) {
|
|
12
|
+
AsyncStorage = null;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
let hasShownWarning = false;
|
|
16
|
+
|
|
17
|
+
function warnIfMissingPackage() {
|
|
18
|
+
if (AsyncStorage === null) {
|
|
19
|
+
if (!hasShownWarning) {
|
|
20
|
+
console.warn(
|
|
21
|
+
"Segment: Tried to access AsyncStoragePersistor but couldn't find package @react-native-async-storage/async-storage.\n\
|
|
22
|
+
- Install '@react-native-async-storage/async-storage' to use the default persistence layer you need\n\
|
|
23
|
+
- You might be missing the 'storePersistor' argument in your client configuration to use your own persistence layer\n\
|
|
24
|
+
Execution will continue but no information will be persisted. This warning will only show once."
|
|
25
|
+
);
|
|
26
|
+
hasShownWarning = true;
|
|
27
|
+
}
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Persistor implementation using AsyncStorage
|
|
35
|
+
*/
|
|
36
|
+
export const AsyncStoragePersistor: Persistor = {
|
|
37
|
+
get: async <T>(key: string): Promise<T | undefined> => {
|
|
38
|
+
if (warnIfMissingPackage()) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
const persistedStateJSON = await AsyncStorage?.getItem?.(key);
|
|
43
|
+
if (persistedStateJSON !== null && persistedStateJSON !== undefined) {
|
|
44
|
+
return JSON.parse(persistedStateJSON) as unknown as T;
|
|
45
|
+
}
|
|
46
|
+
} catch (e) {
|
|
47
|
+
console.error(e);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return undefined;
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
set: async <T>(key: string, state: T): Promise<void> => {
|
|
54
|
+
if (warnIfMissingPackage()) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
await AsyncStorage?.setItem?.(key, JSON.stringify(state));
|
|
59
|
+
} catch (e) {
|
|
60
|
+
console.error(e);
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface PersistenceConfig {
|
|
2
|
+
/**
|
|
3
|
+
* Unique identifier for the store
|
|
4
|
+
*/
|
|
5
|
+
storeId: string;
|
|
6
|
+
/**
|
|
7
|
+
* Delay in ms to wait before saving state
|
|
8
|
+
*/
|
|
9
|
+
saveDelay?: number;
|
|
10
|
+
/**
|
|
11
|
+
* Persistor
|
|
12
|
+
*/
|
|
13
|
+
persistor?: Persistor;
|
|
14
|
+
/**
|
|
15
|
+
* Callback to be called when the store is initialized
|
|
16
|
+
*/
|
|
17
|
+
onInitialized?: (state: unknown) => void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface Persistor {
|
|
21
|
+
/**
|
|
22
|
+
* Retrieves an item from Storage
|
|
23
|
+
* @param key storeId
|
|
24
|
+
* @returns State object or undefined if no state is in the storage
|
|
25
|
+
*/
|
|
26
|
+
get: <T>(key: string) => Promise<T | undefined>;
|
|
27
|
+
/**
|
|
28
|
+
* Saves a state object to Storage
|
|
29
|
+
*/
|
|
30
|
+
set: <T>(key: string, state: T) => Promise<void>;
|
|
31
|
+
}
|