@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,392 @@
|
|
|
1
|
+
import type { Persistor } from '@segment/sovran-react-native';
|
|
2
|
+
import type { Rule } from '@segment/tsub/dist/store';
|
|
3
|
+
import type { SegmentError } from './errors';
|
|
4
|
+
import type { FlushPolicy } from './flushPolicies';
|
|
5
|
+
import type { NativeModule } from 'react-native';
|
|
6
|
+
|
|
7
|
+
export type JsonValue =
|
|
8
|
+
| boolean
|
|
9
|
+
| number
|
|
10
|
+
| string
|
|
11
|
+
| null
|
|
12
|
+
| JsonList
|
|
13
|
+
| JsonMap
|
|
14
|
+
| undefined;
|
|
15
|
+
export interface JsonMap {
|
|
16
|
+
[key: string]: JsonValue;
|
|
17
|
+
[index: number]: JsonValue;
|
|
18
|
+
}
|
|
19
|
+
export type JsonList = Array<JsonValue>;
|
|
20
|
+
|
|
21
|
+
export type SegmentEvent =
|
|
22
|
+
| TrackEventType
|
|
23
|
+
| ScreenEventType
|
|
24
|
+
| IdentifyEventType
|
|
25
|
+
| GroupEventType
|
|
26
|
+
| AliasEventType;
|
|
27
|
+
|
|
28
|
+
interface BaseEventType {
|
|
29
|
+
anonymousId?: string;
|
|
30
|
+
messageId?: string;
|
|
31
|
+
userId?: string;
|
|
32
|
+
timestamp?: string;
|
|
33
|
+
|
|
34
|
+
context?: PartialContext;
|
|
35
|
+
integrations?: SegmentAPIIntegrations;
|
|
36
|
+
_metadata?: DestinationMetadata;
|
|
37
|
+
enrichment?: EnrichmentClosure;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface TrackEventType extends BaseEventType {
|
|
41
|
+
type: EventType.TrackEvent;
|
|
42
|
+
event: string;
|
|
43
|
+
properties?: JsonMap;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface ScreenEventType extends BaseEventType {
|
|
47
|
+
type: EventType.ScreenEvent;
|
|
48
|
+
name: string;
|
|
49
|
+
properties: JsonMap;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface IdentifyEventType extends BaseEventType {
|
|
53
|
+
type: EventType.IdentifyEvent;
|
|
54
|
+
traits?: UserTraits;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface GroupEventType extends BaseEventType {
|
|
58
|
+
type: EventType.GroupEvent;
|
|
59
|
+
groupId: string;
|
|
60
|
+
traits?: GroupTraits;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface AliasEventType extends BaseEventType {
|
|
64
|
+
type: EventType.AliasEvent;
|
|
65
|
+
userId?: string;
|
|
66
|
+
previousId: string;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export type UserTraits = JsonMap & {
|
|
70
|
+
address?: {
|
|
71
|
+
city?: string;
|
|
72
|
+
country?: string;
|
|
73
|
+
postalCode?: string;
|
|
74
|
+
state?: string;
|
|
75
|
+
street?: string;
|
|
76
|
+
};
|
|
77
|
+
age?: number;
|
|
78
|
+
avatar?: string;
|
|
79
|
+
birthday?: string;
|
|
80
|
+
company?: {
|
|
81
|
+
name?: string;
|
|
82
|
+
id?: string | number;
|
|
83
|
+
industry?: string;
|
|
84
|
+
employee_count?: number;
|
|
85
|
+
plan?: string;
|
|
86
|
+
};
|
|
87
|
+
createdAt?: string;
|
|
88
|
+
description?: string;
|
|
89
|
+
email?: string;
|
|
90
|
+
firstName?: string;
|
|
91
|
+
gender?: string;
|
|
92
|
+
id?: string;
|
|
93
|
+
lastName?: string;
|
|
94
|
+
name?: string;
|
|
95
|
+
phone?: string;
|
|
96
|
+
title?: string;
|
|
97
|
+
username?: string;
|
|
98
|
+
website?: string;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
export type GroupTraits = JsonMap & {
|
|
102
|
+
address?: {
|
|
103
|
+
city?: string;
|
|
104
|
+
country?: string;
|
|
105
|
+
postalCode?: string;
|
|
106
|
+
state?: string;
|
|
107
|
+
street?: string;
|
|
108
|
+
};
|
|
109
|
+
avatar?: string;
|
|
110
|
+
createdAt?: string;
|
|
111
|
+
description?: string;
|
|
112
|
+
email?: string;
|
|
113
|
+
employees?: string;
|
|
114
|
+
id?: string;
|
|
115
|
+
industry?: string;
|
|
116
|
+
name?: string;
|
|
117
|
+
phone?: string;
|
|
118
|
+
website?: string;
|
|
119
|
+
plan?: string;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
export interface LoggerType {
|
|
123
|
+
info(message?: unknown, ...optionalParams: unknown[]): void;
|
|
124
|
+
warn(message?: unknown, ...optionalParams: unknown[]): void;
|
|
125
|
+
error(message?: unknown, ...optionalParams: unknown[]): void;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export interface DeactivableLoggerType extends LoggerType {
|
|
129
|
+
enable(): void;
|
|
130
|
+
disable(): void;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export type Config = {
|
|
134
|
+
writeKey: string;
|
|
135
|
+
debug?: boolean;
|
|
136
|
+
logger?: DeactivableLoggerType;
|
|
137
|
+
// Legacy, for compat only
|
|
138
|
+
flushAt?: number;
|
|
139
|
+
flushInterval?: number;
|
|
140
|
+
// New flush policies
|
|
141
|
+
flushPolicies?: FlushPolicy[];
|
|
142
|
+
trackAppLifecycleEvents?: boolean;
|
|
143
|
+
maxBatchSize?: number;
|
|
144
|
+
trackDeepLinks?: boolean;
|
|
145
|
+
defaultSettings?: SegmentAPISettings;
|
|
146
|
+
autoAddSegmentDestination?: boolean;
|
|
147
|
+
collectDeviceId?: boolean;
|
|
148
|
+
storePersistor?: Persistor;
|
|
149
|
+
storePersistorSaveDelay?: number;
|
|
150
|
+
proxy?: string;
|
|
151
|
+
cdnProxy?: string;
|
|
152
|
+
useSegmentEndpoints?: boolean; // Use if you want to use Segment endpoints
|
|
153
|
+
errorHandler?: (error: SegmentError) => void;
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
export type ClientMethods = {
|
|
157
|
+
screen: (
|
|
158
|
+
name: string,
|
|
159
|
+
properties?: JsonMap,
|
|
160
|
+
enrichment?: EnrichmentClosure
|
|
161
|
+
) => Promise<void>;
|
|
162
|
+
track: (
|
|
163
|
+
event: string,
|
|
164
|
+
properties?: JsonMap,
|
|
165
|
+
enrichment?: EnrichmentClosure
|
|
166
|
+
) => Promise<void>;
|
|
167
|
+
identify: (
|
|
168
|
+
userId?: string,
|
|
169
|
+
userTraits?: UserTraits,
|
|
170
|
+
enrichment?: EnrichmentClosure
|
|
171
|
+
) => Promise<void>;
|
|
172
|
+
flush: () => Promise<void>;
|
|
173
|
+
group: (
|
|
174
|
+
groupId: string,
|
|
175
|
+
groupTraits?: GroupTraits,
|
|
176
|
+
enrichment?: EnrichmentClosure
|
|
177
|
+
) => Promise<void>;
|
|
178
|
+
alias: (newUserId: string, enrichment?: EnrichmentClosure) => Promise<void>;
|
|
179
|
+
reset: (resetAnonymousId?: boolean) => Promise<void>;
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
type ContextApp = {
|
|
183
|
+
build: string;
|
|
184
|
+
name: string;
|
|
185
|
+
namespace: string;
|
|
186
|
+
version: string;
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
export type ContextDevice = {
|
|
190
|
+
id?: string;
|
|
191
|
+
manufacturer: string;
|
|
192
|
+
model: string;
|
|
193
|
+
name: string;
|
|
194
|
+
type: string;
|
|
195
|
+
|
|
196
|
+
adTrackingEnabled?: boolean; // ios only
|
|
197
|
+
advertisingId?: string; // ios only
|
|
198
|
+
trackingStatus?: string;
|
|
199
|
+
token?: string;
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
type ContextLibrary = {
|
|
203
|
+
name: string;
|
|
204
|
+
version: string;
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
type ContextNetwork = {
|
|
208
|
+
cellular: boolean;
|
|
209
|
+
wifi: boolean;
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
type ContextOS = {
|
|
213
|
+
name: string;
|
|
214
|
+
version: string;
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
type ContextScreen = {
|
|
218
|
+
height: number;
|
|
219
|
+
width: number;
|
|
220
|
+
density?: number; // android only
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
export type Context = {
|
|
224
|
+
app: ContextApp;
|
|
225
|
+
device: ContextDevice;
|
|
226
|
+
library: ContextLibrary;
|
|
227
|
+
locale: string;
|
|
228
|
+
network: ContextNetwork;
|
|
229
|
+
os: ContextOS;
|
|
230
|
+
screen: ContextScreen;
|
|
231
|
+
timezone: string;
|
|
232
|
+
traits: UserTraits;
|
|
233
|
+
instanceId: string;
|
|
234
|
+
consent?: {
|
|
235
|
+
categoryPreferences: Record<string, boolean>;
|
|
236
|
+
};
|
|
237
|
+
__eventOrigin?: {
|
|
238
|
+
type: string;
|
|
239
|
+
version?: string;
|
|
240
|
+
};
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Makes all the properties in an object optional
|
|
245
|
+
*/
|
|
246
|
+
export type DeepPartial<T> = {
|
|
247
|
+
[Property in keyof T]?: Property extends object
|
|
248
|
+
? DeepPartial<T[Property]>
|
|
249
|
+
: Partial<T[Property]>;
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
export type PartialContext = DeepPartial<Context>;
|
|
253
|
+
|
|
254
|
+
export type NativeContextInfo = {
|
|
255
|
+
appName: string;
|
|
256
|
+
appVersion: string;
|
|
257
|
+
buildNumber: string;
|
|
258
|
+
bundleId: string;
|
|
259
|
+
locale: string;
|
|
260
|
+
networkType: string;
|
|
261
|
+
osName: string;
|
|
262
|
+
osVersion: string;
|
|
263
|
+
screenHeight: number;
|
|
264
|
+
screenWidth: number;
|
|
265
|
+
screenDensity?: number; // android only
|
|
266
|
+
timezone: string;
|
|
267
|
+
manufacturer: string;
|
|
268
|
+
model: string;
|
|
269
|
+
deviceName: string;
|
|
270
|
+
deviceId?: string;
|
|
271
|
+
deviceType: string;
|
|
272
|
+
adTrackingEnabled?: boolean; // ios only
|
|
273
|
+
advertisingId?: string; // ios only
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
export type SegmentAPIIntegration<T = object> = {
|
|
277
|
+
apiKey: string;
|
|
278
|
+
apiHost: string;
|
|
279
|
+
consentSettings?: {
|
|
280
|
+
categories: string[];
|
|
281
|
+
};
|
|
282
|
+
} & T;
|
|
283
|
+
|
|
284
|
+
type SegmentAmplitudeIntegration = {
|
|
285
|
+
session_id: number;
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
export type SegmentAdjustSettings = {
|
|
289
|
+
appToken: string;
|
|
290
|
+
setEnvironmentProduction?: boolean;
|
|
291
|
+
trackAttributionData?: boolean;
|
|
292
|
+
customEvents?: { [key: string]: string };
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
export type SegmentBrazeSettings = {
|
|
296
|
+
logPurchaseWhenRevenuePresent: boolean;
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
export type IntegrationSettings =
|
|
300
|
+
// Strongly typed known integration settings
|
|
301
|
+
| SegmentAPIIntegration<SegmentAmplitudeIntegration>
|
|
302
|
+
| SegmentAPIIntegration<SegmentAdjustSettings>
|
|
303
|
+
// Support any kind of configuration in the future
|
|
304
|
+
| Record<string, unknown>
|
|
305
|
+
// enable/disable the integration at cloud level
|
|
306
|
+
| boolean;
|
|
307
|
+
|
|
308
|
+
export type SegmentAPIIntegrations = {
|
|
309
|
+
[key: string]: IntegrationSettings;
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
export type SegmentAPIConsentSettings = {
|
|
313
|
+
allCategories: string[];
|
|
314
|
+
hasUnmappedDestinations: boolean;
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
export type RoutingRule = Rule;
|
|
318
|
+
|
|
319
|
+
export interface MetricsOptions {
|
|
320
|
+
host?: string;
|
|
321
|
+
sampleRate?: number;
|
|
322
|
+
flushTimer?: number;
|
|
323
|
+
maxQueueSize?: number;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
export interface DestinationFilters {
|
|
327
|
+
[key: string]: RoutingRule;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
export interface EdgeFunctionSettings {
|
|
331
|
+
downloadURL: string;
|
|
332
|
+
version: string;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
export type SegmentAPISettings = {
|
|
336
|
+
integrations: SegmentAPIIntegrations;
|
|
337
|
+
edgeFunction?: EdgeFunctionSettings;
|
|
338
|
+
middlewareSettings?: {
|
|
339
|
+
routingRules: RoutingRule[];
|
|
340
|
+
};
|
|
341
|
+
metrics?: MetricsOptions;
|
|
342
|
+
consentSettings?: SegmentAPIConsentSettings;
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
export type DestinationMetadata = {
|
|
346
|
+
bundled: string[];
|
|
347
|
+
unbundled: string[];
|
|
348
|
+
bundledIds: string[];
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
export enum PluginType {
|
|
352
|
+
// Executed before event processing begins.
|
|
353
|
+
'before' = 'before',
|
|
354
|
+
// Executed as the first level of event processing.
|
|
355
|
+
'enrichment' = 'enrichment',
|
|
356
|
+
// Executed as events begin to pass off to destinations.
|
|
357
|
+
'destination' = 'destination',
|
|
358
|
+
// Executed after all event processing is completed. This can be used to perform cleanup operations, etc.
|
|
359
|
+
'after' = 'after',
|
|
360
|
+
// Executed only when called manually, such as Logging.
|
|
361
|
+
'utility' = 'utility',
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
export enum UpdateType {
|
|
365
|
+
'initial' = 'initial',
|
|
366
|
+
'refresh' = 'refresh',
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
export enum EventType {
|
|
370
|
+
'TrackEvent' = 'track',
|
|
371
|
+
'IdentifyEvent' = 'identify',
|
|
372
|
+
'ScreenEvent' = 'screen',
|
|
373
|
+
'GroupEvent' = 'group',
|
|
374
|
+
'AliasEvent' = 'alias',
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
export type UserInfoState = {
|
|
378
|
+
anonymousId: string;
|
|
379
|
+
userId?: string;
|
|
380
|
+
traits?: UserTraits | GroupTraits;
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
// Native Module types
|
|
384
|
+
export interface GetContextConfig {
|
|
385
|
+
collectDeviceId: boolean;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
export type AnalyticsReactNativeModule = NativeModule & {
|
|
389
|
+
getContextInfo: (config: GetContextConfig) => Promise<NativeContextInfo>;
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
export type EnrichmentClosure = (event: SegmentEvent) => SegmentEvent;
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import { NativeModule, NativeModules, Platform } from 'react-native';
|
|
2
|
+
import type { EventPlugin } from './plugin';
|
|
3
|
+
import type { Timeline } from './timeline';
|
|
4
|
+
|
|
5
|
+
const sizeOf = (obj: unknown): number => {
|
|
6
|
+
const size = encodeURI(JSON.stringify(obj)).split(/%..|./).length - 1;
|
|
7
|
+
return size / 1024;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const warnMissingNativeModule = () => {
|
|
11
|
+
const MISSING_NATIVE_MODULE_WARNING =
|
|
12
|
+
"The package 'analytics-react-native' can't access a custom native module. Make sure: \n\n" +
|
|
13
|
+
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
|
|
14
|
+
'- You rebuilt the app after installing the package\n' +
|
|
15
|
+
'- You are not using Expo managed workflow\n';
|
|
16
|
+
console.warn(MISSING_NATIVE_MODULE_WARNING);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const getNativeModule = (moduleName: string) => {
|
|
20
|
+
const module = (NativeModules[moduleName] as NativeModule) ?? undefined;
|
|
21
|
+
if (module === undefined) {
|
|
22
|
+
warnMissingNativeModule();
|
|
23
|
+
}
|
|
24
|
+
return module;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const chunk = <T>(array: T[], count: number, maxKB?: number): T[][] => {
|
|
28
|
+
if (!array.length || !count) {
|
|
29
|
+
return [];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
let currentChunk = 0;
|
|
33
|
+
let rollingKBSize = 0;
|
|
34
|
+
const result: T[][] = array.reduce(
|
|
35
|
+
(chunks: T[][], item: T, index: number) => {
|
|
36
|
+
if (maxKB !== undefined) {
|
|
37
|
+
rollingKBSize += sizeOf(item);
|
|
38
|
+
// If we overflow chunk until the previous index, else keep going
|
|
39
|
+
if (rollingKBSize >= maxKB) {
|
|
40
|
+
chunks[++currentChunk] = [item];
|
|
41
|
+
return chunks;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (index !== 0 && index % count === 0) {
|
|
46
|
+
chunks[++currentChunk] = [item];
|
|
47
|
+
} else {
|
|
48
|
+
if (chunks[currentChunk] === undefined) {
|
|
49
|
+
chunks[currentChunk] = [];
|
|
50
|
+
}
|
|
51
|
+
chunks[currentChunk].push(item);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return chunks;
|
|
55
|
+
},
|
|
56
|
+
[]
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
return result;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export const getAllPlugins = (timeline: Timeline) => {
|
|
63
|
+
const allPlugins = Object.values(timeline.plugins);
|
|
64
|
+
if (allPlugins.length) {
|
|
65
|
+
return allPlugins.reduce((prev = [], curr = []) => prev.concat(curr));
|
|
66
|
+
}
|
|
67
|
+
return [];
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export const getPluginsWithFlush = (timeline: Timeline) => {
|
|
71
|
+
const allPlugins = getAllPlugins(timeline);
|
|
72
|
+
|
|
73
|
+
// checking for the existence of .flush()
|
|
74
|
+
const eventPlugins = allPlugins?.filter(
|
|
75
|
+
(f) => (f as EventPlugin).flush !== undefined
|
|
76
|
+
) as EventPlugin[];
|
|
77
|
+
|
|
78
|
+
return eventPlugins;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export const getPluginsWithReset = (timeline: Timeline) => {
|
|
82
|
+
const allPlugins = getAllPlugins(timeline);
|
|
83
|
+
|
|
84
|
+
// checking for the existence of .reset()
|
|
85
|
+
const eventPlugins = allPlugins?.filter(
|
|
86
|
+
(f) => (f as EventPlugin).reset !== undefined
|
|
87
|
+
) as EventPlugin[];
|
|
88
|
+
|
|
89
|
+
return eventPlugins;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
type PromiseResult<T> =
|
|
93
|
+
| {
|
|
94
|
+
status: 'fulfilled';
|
|
95
|
+
value: T;
|
|
96
|
+
}
|
|
97
|
+
| {
|
|
98
|
+
status: 'rejected';
|
|
99
|
+
reason: unknown;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const settlePromise = async <T>(
|
|
103
|
+
promise: Promise<T> | T
|
|
104
|
+
): Promise<PromiseResult<T>> => {
|
|
105
|
+
try {
|
|
106
|
+
const result = await promise;
|
|
107
|
+
return {
|
|
108
|
+
status: 'fulfilled',
|
|
109
|
+
value: result,
|
|
110
|
+
};
|
|
111
|
+
} catch (error) {
|
|
112
|
+
return {
|
|
113
|
+
status: 'rejected',
|
|
114
|
+
reason: error,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
export const allSettled = async <T>(
|
|
120
|
+
promises: (Promise<T> | T)[]
|
|
121
|
+
): Promise<PromiseResult<T>[]> => {
|
|
122
|
+
return Promise.all(promises.map(settlePromise));
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
export function isNumber(x: unknown): x is number {
|
|
126
|
+
return typeof x === 'number';
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export function isString(x: unknown): x is string {
|
|
130
|
+
return typeof x === 'string';
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export function isBoolean(x: unknown): x is boolean {
|
|
134
|
+
return typeof x === 'boolean';
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function isDate(value: unknown): value is Date {
|
|
138
|
+
return (
|
|
139
|
+
value instanceof Date ||
|
|
140
|
+
(typeof value === 'object' &&
|
|
141
|
+
Object.prototype.toString.call(value) === '[object Date]')
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export function objectToString(value: object, json = true): string | undefined {
|
|
146
|
+
// If the object has a custom toString we well use that
|
|
147
|
+
if (value.toString !== Object.prototype.toString) {
|
|
148
|
+
return value.toString();
|
|
149
|
+
}
|
|
150
|
+
if (json) {
|
|
151
|
+
return JSON.stringify(value);
|
|
152
|
+
}
|
|
153
|
+
return undefined;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export function unknownToString(
|
|
157
|
+
value: unknown,
|
|
158
|
+
stringifyJSON = true,
|
|
159
|
+
replaceNull: string | undefined = '',
|
|
160
|
+
replaceUndefined: string | undefined = ''
|
|
161
|
+
): string | undefined {
|
|
162
|
+
if (value === null) {
|
|
163
|
+
if (replaceNull !== undefined) {
|
|
164
|
+
return replaceNull;
|
|
165
|
+
} else {
|
|
166
|
+
return undefined;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (value === undefined) {
|
|
171
|
+
if (replaceUndefined !== undefined) {
|
|
172
|
+
return replaceUndefined;
|
|
173
|
+
} else {
|
|
174
|
+
return undefined;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (isNumber(value) || isBoolean(value) || isString(value)) {
|
|
179
|
+
return value.toString();
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (isObject(value)) {
|
|
183
|
+
return objectToString(value, stringifyJSON);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (stringifyJSON) {
|
|
187
|
+
return JSON.stringify(value);
|
|
188
|
+
}
|
|
189
|
+
return undefined;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Checks if value is a dictionary like object
|
|
194
|
+
* @param value unknown object
|
|
195
|
+
* @returns typeguard, value is dicitonary
|
|
196
|
+
*/
|
|
197
|
+
export const isObject = (value: unknown): value is Record<string, unknown> =>
|
|
198
|
+
value !== null &&
|
|
199
|
+
value !== undefined &&
|
|
200
|
+
typeof value === 'object' &&
|
|
201
|
+
!Array.isArray(value);
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Utility to deeply compare 2 objects
|
|
205
|
+
* @param a unknown object
|
|
206
|
+
* @param b unknown object
|
|
207
|
+
* @returns true if both objects have the same keys and values
|
|
208
|
+
*/
|
|
209
|
+
export function deepCompare<T>(a: T, b: T): boolean {
|
|
210
|
+
// Shallow compare first, just in case
|
|
211
|
+
if (a === b) {
|
|
212
|
+
return true;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// If not objects then compare values directly
|
|
216
|
+
if (!isObject(a) || !isObject(b)) {
|
|
217
|
+
return a === b;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const keysA = Object.keys(a);
|
|
221
|
+
const keysB = Object.keys(b);
|
|
222
|
+
|
|
223
|
+
if (keysA.length !== keysB.length) {
|
|
224
|
+
return false;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
for (const key of keysA) {
|
|
228
|
+
if (!keysB.includes(key) || !deepCompare(a[key], b[key])) {
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
return true;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export const createPromise = <T>(
|
|
237
|
+
timeout: number | undefined = undefined,
|
|
238
|
+
_errorHandler: (err: Error) => void = (_: Error) => {
|
|
239
|
+
//
|
|
240
|
+
}
|
|
241
|
+
): { promise: Promise<T>; resolve: (value: T) => void } => {
|
|
242
|
+
let resolver: (value: T) => void;
|
|
243
|
+
const promise = new Promise<T>((resolve, reject) => {
|
|
244
|
+
resolver = resolve;
|
|
245
|
+
if (timeout !== undefined) {
|
|
246
|
+
setTimeout(() => {
|
|
247
|
+
reject(new Error('Promise timed out'));
|
|
248
|
+
}, timeout);
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
promise.catch(_errorHandler);
|
|
253
|
+
|
|
254
|
+
return {
|
|
255
|
+
promise: promise,
|
|
256
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
257
|
+
resolve: resolver!,
|
|
258
|
+
};
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
export function getURL(host: string, path: string) {
|
|
262
|
+
if (!host.startsWith('https://') && !host.startsWith('http://')) {
|
|
263
|
+
host = 'https://' + host;
|
|
264
|
+
}
|
|
265
|
+
const s = `${host}${path}`;
|
|
266
|
+
if (!validateURL(s)) {
|
|
267
|
+
console.error('Invalid URL has been passed');
|
|
268
|
+
console.log(`Invalid Url passed is ${s}`);
|
|
269
|
+
throw new Error('Invalid URL has been passed');
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
return s;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
export function validateURL(url: string): boolean {
|
|
276
|
+
const urlRegex = new RegExp(
|
|
277
|
+
'^(?:https?:\\/\\/)' + // Protocol (http or https)
|
|
278
|
+
'(?:\\S+(?::\\S*)?@)?' + // Optional user:pass@
|
|
279
|
+
'(?:(localhost|\\d{1,3}(?:\\.\\d{1,3}){3})|' + // Localhost or IP address
|
|
280
|
+
'(?:(?!-)[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*(?:\\.[a-zA-Z]{2,})))' + // Domain validation (supports hyphens)
|
|
281
|
+
'(?::\\d{2,5})?' + // Optional port
|
|
282
|
+
'(\\/[^\\s?#]*)?' + // Path (allows `/projects/yup/settings`)
|
|
283
|
+
'(\\?[a-zA-Z0-9_.-]+=[a-zA-Z0-9_.-]+(&[a-zA-Z0-9_.-]+=[a-zA-Z0-9_.-]+)*)?' + // Query params
|
|
284
|
+
'(#[^\\s]*)?$', // Fragment (optional)
|
|
285
|
+
'i' // Case-insensitive
|
|
286
|
+
);
|
|
287
|
+
return urlRegex.test(url);
|
|
288
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "lib/typescript",
|
|
5
|
+
"rootDir": ".",
|
|
6
|
+
"baseUrl": "."
|
|
7
|
+
},
|
|
8
|
+
"include": ["src/**/*", "types.d.ts"],
|
|
9
|
+
"exclude": ["**/__fixtures__/**/*", "**/__snapshots__/**/*"],
|
|
10
|
+
"references": [{ "path": "../sovran" }] // Add refereneces to any packages you require
|
|
11
|
+
}
|