From d9638e9d8d91d6c743102b7a3c43a6ada0cc9a5d Mon Sep 17 00:00:00 2001 From: Alan Charles Date: Fri, 19 May 2023 14:03:54 -0600 Subject: [PATCH 1/3] feat: add config option for cdn proxy --- .../project.pbxproj | 4 ---- example/ios/Podfile.lock | 20 ------------------- packages/core/src/analytics.ts | 12 ++++++++++- packages/core/src/types.ts | 1 + 4 files changed, 12 insertions(+), 25 deletions(-) diff --git a/example/ios/AnalyticsReactNativeExample.xcodeproj/project.pbxproj b/example/ios/AnalyticsReactNativeExample.xcodeproj/project.pbxproj index b3709a06..81168eb9 100644 --- a/example/ios/AnalyticsReactNativeExample.xcodeproj/project.pbxproj +++ b/example/ios/AnalyticsReactNativeExample.xcodeproj/project.pbxproj @@ -206,14 +206,10 @@ ); inputPaths = ( "${PODS_ROOT}/Target Support Files/Pods-AnalyticsReactNativeExample/Pods-AnalyticsReactNativeExample-resources.sh", - "${PODS_CONFIGURATION_BUILD_DIR}/BrazeKit/BrazeKit.bundle", - "${PODS_CONFIGURATION_BUILD_DIR}/BrazeUI/BrazeUI.bundle", "${PODS_CONFIGURATION_BUILD_DIR}/React-Core/AccessibilityResources.bundle", ); name = "[CP] Copy Pods Resources"; outputPaths = ( - "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/BrazeKit.bundle", - "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/BrazeUI.bundle", "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/AccessibilityResources.bundle", ); runOnlyForDeploymentPostprocessing = 0; diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index b231e83d..33d3cc4e 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -1,15 +1,5 @@ PODS: - boost (1.76.0) - - braze-react-native-sdk (4.1.0): - - BrazeKit (~> 5.13.0) - - BrazeLocation (~> 5.13.0) - - BrazeUI (~> 5.13.0) - - React-Core - - BrazeKit (5.13.0) - - BrazeLocation (5.13.0): - - BrazeKit (= 5.13.0) - - BrazeUI (5.13.0): - - BrazeKit (= 5.13.0) - DoubleConversion (1.1.6) - FBLazyVector (0.69.7) - FBReactNativeSpec (0.69.7): @@ -321,7 +311,6 @@ PODS: DEPENDENCIES: - boost (from `../node_modules/react-native/third-party-podspecs/boost.podspec`) - - "braze-react-native-sdk (from `../node_modules/@braze/react-native-sdk`)" - DoubleConversion (from `../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec`) - FBLazyVector (from `../node_modules/react-native/Libraries/FBLazyVector`) - FBReactNativeSpec (from `../node_modules/react-native/React/FBReactNativeSpec`) @@ -367,16 +356,11 @@ DEPENDENCIES: SPEC REPOS: trunk: - - BrazeKit - - BrazeLocation - - BrazeUI - fmt EXTERNAL SOURCES: boost: :podspec: "../node_modules/react-native/third-party-podspecs/boost.podspec" - braze-react-native-sdk: - :path: "../node_modules/@braze/react-native-sdk" DoubleConversion: :podspec: "../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec" FBLazyVector: @@ -462,10 +446,6 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: boost: a7c83b31436843459a1961bfd74b96033dc77234 - braze-react-native-sdk: 686da10a997500422984bd4b39c78fc19fcd701a - BrazeKit: 97f6875bf05920a46a2f0c9d0e452b6b840c5f99 - BrazeLocation: 571ee6bf6b2f5c1aba20d9a75e4da190f8db7e5b - BrazeUI: 31dd9f0235149f05d6f7e37f273be7293e000587 DoubleConversion: 5189b271737e1565bdce30deb4a08d647e3f5f54 FBLazyVector: 6b7f5692909b4300d50e7359cdefbcd09dd30faa FBReactNativeSpec: affcf71d996f6b0c01f68883482588297b9d5e6e diff --git a/packages/core/src/analytics.ts b/packages/core/src/analytics.ts index 8cfda5ff..1c79c1f5 100644 --- a/packages/core/src/analytics.ts +++ b/packages/core/src/analytics.ts @@ -293,7 +293,17 @@ export class SegmentClient { } async fetchSettings() { - const settingsEndpoint = `${settingsCDN}/${this.config.writeKey}/settings`; + let settingsEndpoint: string; + + if (this.config.cdnProxy !== undefined && this.config.cdnProxy !== null) { + // Sets an alternative CDN host for settings retrieval. This is useful when + // a proxy is in use, or settings need to be queried from certain locales at + // all times (such as the EU). The default value is `https://cdn-settings.segment.com/v1/projects`. + + settingsEndpoint = this.config.cdnProxy; + } else { + settingsEndpoint = `${settingsCDN}/${this.config.writeKey}/settings`; + } try { const res = await fetch(settingsEndpoint); diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index f73f885f..a208cd19 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -146,6 +146,7 @@ export type Config = { collectDeviceId?: boolean; storePersistor?: Persistor; proxy?: string; + cdnProxy?: string; errorHandler?: (error: SegmentError) => void; }; From 2eaca8c7035fe9c784b61f02c4711fd8b18cf56f Mon Sep 17 00:00:00 2001 From: Alan Charles Date: Fri, 19 May 2023 14:08:41 -0600 Subject: [PATCH 2/3] fix: add writekey and settings to cdn proxy --- packages/core/src/analytics.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/analytics.ts b/packages/core/src/analytics.ts index 1c79c1f5..851f7984 100644 --- a/packages/core/src/analytics.ts +++ b/packages/core/src/analytics.ts @@ -300,7 +300,7 @@ export class SegmentClient { // a proxy is in use, or settings need to be queried from certain locales at // all times (such as the EU). The default value is `https://cdn-settings.segment.com/v1/projects`. - settingsEndpoint = this.config.cdnProxy; + settingsEndpoint = `${this.config.cdnProxy}}/${this.config.writeKey}/settings`; } else { settingsEndpoint = `${settingsCDN}/${this.config.writeKey}/settings`; } From 26bc032d31df3cd3f4328d91de8e52354101f661 Mon Sep 17 00:00:00 2001 From: Alan Charles Date: Mon, 22 May 2023 10:49:59 -0600 Subject: [PATCH 3/3] fix: make conditional one line add to readme --- README.md | 1 + packages/core/src/analytics.ts | 13 ++----------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 00e32df4..fc16d940 100644 --- a/README.md +++ b/README.md @@ -133,6 +133,7 @@ You must pass at least the `writeKey`. Additional configuration options are list | `storePersistor` | undefined | A custom persistor for the store that `analytics-react-native` leverages. Must match [`Persistor`](https://github.com/segmentio/analytics-react-native/blob/master/packages/sovran/src/persistor/persistor.ts#L1-L18) interface exported from [sovran-react-native](https://github.com/segmentio/analytics-react-native/blob/master/packages/sovran).| | `proxy` | undefined | `proxy` is a batch url to post to instead of 'https://api.segment.io/v1/b'. | | `errorHandler` | undefined | Create custom actions when errors happen, see [Handling errors](#handling-errors) | +| `cdnProxy` | undefined | Sets an alternative CDN host for settings retrieval | \* The default value of `debug` will be false in production. diff --git a/packages/core/src/analytics.ts b/packages/core/src/analytics.ts index 851f7984..f006a04a 100644 --- a/packages/core/src/analytics.ts +++ b/packages/core/src/analytics.ts @@ -293,17 +293,8 @@ export class SegmentClient { } async fetchSettings() { - let settingsEndpoint: string; - - if (this.config.cdnProxy !== undefined && this.config.cdnProxy !== null) { - // Sets an alternative CDN host for settings retrieval. This is useful when - // a proxy is in use, or settings need to be queried from certain locales at - // all times (such as the EU). The default value is `https://cdn-settings.segment.com/v1/projects`. - - settingsEndpoint = `${this.config.cdnProxy}}/${this.config.writeKey}/settings`; - } else { - settingsEndpoint = `${settingsCDN}/${this.config.writeKey}/settings`; - } + const settingsPrefix: string = this.config.cdnProxy ?? settingsCDN; + const settingsEndpoint = `${settingsPrefix}/${this.config.writeKey}/settings`; try { const res = await fetch(settingsEndpoint);