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.mjs CHANGED
@@ -9580,24 +9580,66 @@ var setConfigs = (configs) => {
9580
9580
  });
9581
9581
  publicRequest.setBaseUrl(CONFIGS.BASE_URL);
9582
9582
  };
9583
+ var isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
9583
9584
  var authorize2 = async (data) => {
9585
+ var _a, _b, _c, _d;
9586
+ if (!isBrowser) {
9587
+ const step1 = new FormData();
9588
+ step1.append("email", data.email);
9589
+ step1.append("password", data.password);
9590
+ const authResponse = await publicRequest.post(
9591
+ `v1/oauth/authorize-rn?client_id=${CONFIGS.CLIENT_ID}`,
9592
+ step1,
9593
+ { headers: { "Content-Type": "multipart/form-data" } }
9594
+ );
9595
+ const code = (_b = (_a = authResponse.data) == null ? void 0 : _a.data) == null ? void 0 : _b.code;
9596
+ if (!code) throw new Error("Authorization code not received");
9597
+ const step2 = new FormData();
9598
+ step2.append("code", code);
9599
+ step2.append("scope", "profile");
9600
+ step2.append("grant_type", "authorization_code");
9601
+ step2.append("client_id", CONFIGS.CLIENT_ID);
9602
+ step2.append("client_secret", CONFIGS.CLIENT_SECRET);
9603
+ const tokenResponse = await publicRequest.post("v1/oauth/access_token", step2, {
9604
+ headers: { "Content-Type": "multipart/form-data" }
9605
+ });
9606
+ const accessToken = (_c = tokenResponse.data) == null ? void 0 : _c.access_token;
9607
+ const refreshToken = (_d = tokenResponse.data) == null ? void 0 : _d.refresh_token;
9608
+ if (accessToken) {
9609
+ storage.setItem("access_token", accessToken);
9610
+ publicRequest.defaults.headers.common["Authorization"] = `Bearer ${accessToken}`;
9611
+ }
9612
+ if (refreshToken) {
9613
+ storage.setItem("refresh_token", refreshToken);
9614
+ }
9615
+ return getProfileData();
9616
+ }
9584
9617
  const response = await publicRequest.post(
9585
- `/auth?clientId=${CONFIGS.CLIENT_ID || "e9d8f8922797b4621e562255afe90dbf"}`,
9586
- data
9618
+ `/auth?clientId=${CONFIGS.CLIENT_ID}`,
9619
+ data,
9620
+ { withCredentials: true }
9587
9621
  );
9588
9622
  return response.data;
9589
9623
  };
9590
9624
  var register = async (data) => {
9591
- const response = await publicRequest.post("v1/oauth/register-rn", data);
9625
+ const response = await publicRequest.post("v1/oauth/register-rn", data, {
9626
+ headers: { "Content-Type": "multipart/form-data" }
9627
+ });
9592
9628
  return response.data;
9593
9629
  };
9594
9630
  var getProfileData = async () => {
9595
- const response = await publicRequest.get("/customer/profile/");
9631
+ const response = await publicRequest.get("/customer/profile/", { withCredentials: isBrowser });
9596
9632
  return response.data;
9597
9633
  };
9598
9634
  var logout = async () => {
9599
- const response = await publicRequest.delete("/auth");
9600
- return response.data;
9635
+ storage.removeItem("access_token");
9636
+ storage.removeItem("refresh_token");
9637
+ delete publicRequest.defaults.headers.common["Authorization"];
9638
+ if (isBrowser) {
9639
+ const response = await publicRequest.delete("/auth", { withCredentials: true });
9640
+ return response.data;
9641
+ }
9642
+ return { success: true };
9601
9643
  };
9602
9644
  var checkEmailExists = async (email) => {
9603
9645
  var _a;
@@ -9605,16 +9647,12 @@ var checkEmailExists = async (email) => {
9605
9647
  const formData = new FormData();
9606
9648
  formData.append("email", email);
9607
9649
  formData.append("is_checkout_flow", "true");
9608
- const baseUrl = ((_a = publicRequest.defaults.baseURL) == null ? void 0 : _a.replace("/api", "")) || "";
9650
+ const baseUrl = CONFIGS.BASE_URL || ((_a = publicRequest.defaults.baseURL) == null ? void 0 : _a.replace("/api", "")) || "";
9609
9651
  const url = `${baseUrl}/ajax/contact-email`;
9610
9652
  const response = await publicRequest.post(
9611
9653
  url,
9612
9654
  formData,
9613
- {
9614
- headers: {
9615
- "Content-Type": "multipart/form-data"
9616
- }
9617
- }
9655
+ { headers: { "Content-Type": "multipart/form-data" } }
9618
9656
  );
9619
9657
  return {
9620
9658
  exists: response.data.exists === 1,
@@ -9628,7 +9666,6 @@ var checkEmailExists = async (email) => {
9628
9666
  };
9629
9667
  }
9630
9668
  };
9631
- var isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
9632
9669
  var setLoggedUserData = (data) => ({
9633
9670
  id: data.id,
9634
9671
  first_name: data.firstName,
@@ -9705,6 +9742,13 @@ publicRequest.interceptors.request.use((config) => {
9705
9742
  if (CONFIGS.BASE_URL) {
9706
9743
  config.baseURL = CONFIGS.BASE_URL + "/api";
9707
9744
  }
9745
+ if (!isBrowser && !config.headers["Authorization"]) {
9746
+ const accessToken = storage.getItem("access_token");
9747
+ if (accessToken) {
9748
+ config.headers["Authorization"] = `Bearer ${accessToken}`;
9749
+ publicRequest.defaults.headers.common["Authorization"] = `Bearer ${accessToken}`;
9750
+ }
9751
+ }
9708
9752
  return config;
9709
9753
  });
9710
9754
  publicRequest.interceptors.response.use(
@@ -9735,6 +9779,10 @@ publicRequest.interceptors.response.use(
9735
9779
  if (errorType === "invalid_token") {
9736
9780
  window.location.href = "/";
9737
9781
  }
9782
+ } else {
9783
+ storage.removeItem("access_token");
9784
+ storage.removeItem("refresh_token");
9785
+ delete publicRequest.defaults.headers.common["Authorization"];
9738
9786
  }
9739
9787
  }
9740
9788
  const authGuestToken2 = _get2(error, "response.headers.authorization-guest");