Skip to content
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

Closed
wants to merge 3 commits into from
Closed

Conversation

nsingh-branch
Copy link
Contributor

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

  • New feature (non-breaking change which adds functionality)

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's componentDidMount works in that case.

cc @BranchMetrics/saas-sdk-devs for visibility.

Copy link

codecov bot commented Mar 27, 2024

Codecov Report

Attention: Patch coverage is 20.00000% with 4 lines in your changes are missing coverage. Please review.

Project coverage is 43.81%. Comparing base (895c2bd) to head (3fc2816).

Files Patch % Lines
src/index.js 20.00% 3 Missing and 1 partial ⚠️
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.
📢 Have feedback on the report? Share it here.

@@ -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) => {
Copy link
Contributor

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")) {

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);

@nsingh-branch
Copy link
Contributor Author

Closing in favor of using branch.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants