-
Notifications
You must be signed in to change notification settings - Fork 207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SDK-2326] Add setAPIUrl to the JS layer #967
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #967 +/- ##
==========================================
- Coverage 44.24% 43.81% -0.43%
==========================================
Files 4 4
Lines 278 283 +5
Branches 88 89 +1
==========================================
+ Hits 123 124 +1
- Misses 116 119 +3
- Partials 39 40 +1 ☔ View full report in Codecov by Sentry. |
@@ -164,6 +164,17 @@ class Branch { | |||
console.warn("setDMAParamsForEEA: Unable to set DMA params."); | |||
} | |||
}; | |||
|
|||
/*** Set the Branch API's base URL (eg. "https://api2.branch.io") ***/ | |||
setAPIUrl = (apiUrl) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend removing the JavaScript API and moving this to the native JSON api. The JS <> native runtime switch will be a race condition against this setting which must be called before session init.
Instead, the json can be read on the native init's start up.
|
||
/*** Set the Branch API's base URL (eg. "https://api2.branch.io") ***/ | ||
setAPIUrl = (apiUrl) => { | ||
if (!apiUrl || typeof apiUrl !== "string" || !apiUrl.startsWith("http")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A full url validation
const urlPattern = new RegExp('^(https?)://((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|((\\d{1,3}\\.){3}\\d{1,3}))(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*(\\?[;&a-z\\d%_.~+=-]*)?(\\#[-a-z\\d_]*)?$', 'i');
urlPattern.test(apiUrl);
Closing in favor of using branch.json |
Reference
SDK-2326 -- Expose the setAPIUrl method in the JS layer
Summary
Added the setAPIUrl to the JS layer now that it exists on both of the native layers.
Motivation
Bring the React Native SDK to parity with out iOS and Android native SDKs.
Type Of Change
Testing Instructions
Call the new method with a cusrtom API URL. To have the initial open/install use the endpoint, it needs to be set early.
Calling
branch.setAPIUrl('https://api3.branch.io')
in the Testbed'scomponentDidMount
works in that case.cc @BranchMetrics/saas-sdk-devs for visibility.