tf-checkout-react-native 1.0.43 → 1.0.47

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/lib/index.js CHANGED
@@ -9657,24 +9657,66 @@ var setConfigs = (configs) => {
9657
9657
  });
9658
9658
  publicRequest.setBaseUrl(CONFIGS.BASE_URL);
9659
9659
  };
9660
+ var isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
9660
9661
  var authorize2 = async (data) => {
9662
+ var _a, _b, _c, _d;
9663
+ if (!isBrowser) {
9664
+ const step1 = new FormData();
9665
+ step1.append("email", data.email);
9666
+ step1.append("password", data.password);
9667
+ const authResponse = await publicRequest.post(
9668
+ `v1/oauth/authorize-rn?client_id=${CONFIGS.CLIENT_ID}`,
9669
+ step1,
9670
+ { headers: { "Content-Type": "multipart/form-data" } }
9671
+ );
9672
+ const code = (_b = (_a = authResponse.data) == null ? void 0 : _a.data) == null ? void 0 : _b.code;
9673
+ if (!code) throw new Error("Authorization code not received");
9674
+ const step2 = new FormData();
9675
+ step2.append("code", code);
9676
+ step2.append("scope", "profile");
9677
+ step2.append("grant_type", "authorization_code");
9678
+ step2.append("client_id", CONFIGS.CLIENT_ID);
9679
+ step2.append("client_secret", CONFIGS.CLIENT_SECRET);
9680
+ const tokenResponse = await publicRequest.post("v1/oauth/access_token", step2, {
9681
+ headers: { "Content-Type": "multipart/form-data" }
9682
+ });
9683
+ const accessToken = (_c = tokenResponse.data) == null ? void 0 : _c.access_token;
9684
+ const refreshToken = (_d = tokenResponse.data) == null ? void 0 : _d.refresh_token;
9685
+ if (accessToken) {
9686
+ storage.setItem("access_token", accessToken);
9687
+ publicRequest.defaults.headers.common["Authorization"] = `Bearer ${accessToken}`;
9688
+ }
9689
+ if (refreshToken) {
9690
+ storage.setItem("refresh_token", refreshToken);
9691
+ }
9692
+ return getProfileData();
9693
+ }
9661
9694
  const response = await publicRequest.post(
9662
- `/auth?clientId=${CONFIGS.CLIENT_ID || "e9d8f8922797b4621e562255afe90dbf"}`,
9663
- data
9695
+ `/auth?clientId=${CONFIGS.CLIENT_ID}`,
9696
+ data,
9697
+ { withCredentials: true }
9664
9698
  );
9665
9699
  return response.data;
9666
9700
  };
9667
9701
  var register = async (data) => {
9668
- const response = await publicRequest.post("v1/oauth/register-rn", data);
9702
+ const response = await publicRequest.post("v1/oauth/register-rn", data, {
9703
+ headers: { "Content-Type": "multipart/form-data" }
9704
+ });
9669
9705
  return response.data;
9670
9706
  };
9671
9707
  var getProfileData = async () => {
9672
- const response = await publicRequest.get("/customer/profile/");
9708
+ const response = await publicRequest.get("/customer/profile/", { withCredentials: isBrowser });
9673
9709
  return response.data;
9674
9710
  };
9675
9711
  var logout = async () => {
9676
- const response = await publicRequest.delete("/auth");
9677
- return response.data;
9712
+ storage.removeItem("access_token");
9713
+ storage.removeItem("refresh_token");
9714
+ delete publicRequest.defaults.headers.common["Authorization"];
9715
+ if (isBrowser) {
9716
+ const response = await publicRequest.delete("/auth", { withCredentials: true });
9717
+ return response.data;
9718
+ }
9719
+ return { success: true };
9678
9720
  };
9679
9721
  var checkEmailExists = async (email) => {
9680
9722
  var _a;
@@ -9682,16 +9724,12 @@ var checkEmailExists = async (email) => {
9682
9724
  const formData = new FormData();
9683
9725
  formData.append("email", email);
9684
9726
  formData.append("is_checkout_flow", "true");
9685
- const baseUrl = ((_a = publicRequest.defaults.baseURL) == null ? void 0 : _a.replace("/api", "")) || "";
9727
+ const baseUrl = CONFIGS.BASE_URL || ((_a = publicRequest.defaults.baseURL) == null ? void 0 : _a.replace("/api", "")) || "";
9686
9728
  const url = `${baseUrl}/ajax/contact-email`;
9687
9729
  const response = await publicRequest.post(
9688
9730
  url,
9689
9731
  formData,
9690
- {
9691
- headers: {
9692
- "Content-Type": "multipart/form-data"
9693
- }
9694
- }
9732
+ { headers: { "Content-Type": "multipart/form-data" } }
9695
9733
  );
9696
9734
  return {
9697
9735
  exists: response.data.exists === 1,
@@ -9705,7 +9743,6 @@ var checkEmailExists = async (email) => {
9705
9743
  };
9706
9744
  }
9707
9745
  };
9708
- var isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
9709
9746
  var setLoggedUserData = (data) => ({
9710
9747
  id: data.id,
9711
9748
  first_name: data.firstName,
@@ -9782,6 +9819,13 @@ publicRequest.interceptors.request.use((config) => {
9782
9819
  if (CONFIGS.BASE_URL) {
9783
9820
  config.baseURL = CONFIGS.BASE_URL + "/api";
9784
9821
  }
9822
+ if (!isBrowser && !config.headers["Authorization"]) {
9823
+ const accessToken = storage.getItem("access_token");
9824
+ if (accessToken) {
9825
+ config.headers["Authorization"] = `Bearer ${accessToken}`;
9826
+ publicRequest.defaults.headers.common["Authorization"] = `Bearer ${accessToken}`;
9827
+ }
9828
+ }
9785
9829
  return config;
9786
9830
  });
9787
9831
  publicRequest.interceptors.response.use(
@@ -9812,6 +9856,10 @@ publicRequest.interceptors.response.use(
9812
9856
  if (errorType === "invalid_token") {
9813
9857
  window.location.href = "/";
9814
9858
  }
9859
+ } else {
9860
+ storage.removeItem("access_token");
9861
+ storage.removeItem("refresh_token");
9862
+ delete publicRequest.defaults.headers.common["Authorization"];
9815
9863
  }
9816
9864
  }
9817
9865
  const authGuestToken2 = (0, import_get2.default)(error, "response.headers.authorization-guest");