tf-checkout-react-native 1.0.42 → 1.0.43

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
@@ -9429,7 +9429,7 @@ function setCustomCookie(name, value, days = 5) {
9429
9429
  date2.setTime(date2.getTime() + days * 24 * 60 * 60 * 1e3);
9430
9430
  expires = "; expires=" + date2.toUTCString();
9431
9431
  }
9432
- if (typeof window === "undefined") {
9432
+ if (typeof window === "undefined" || typeof document === "undefined") {
9433
9433
  return;
9434
9434
  }
9435
9435
  const { hostname } = window.location;
@@ -9447,7 +9447,7 @@ function setCustomCookie(name, value, days = 5) {
9447
9447
  generalDomain = domain;
9448
9448
  }
9449
9449
  function getCookieByName(cname) {
9450
- if (typeof window === "undefined") return "";
9450
+ if (typeof window === "undefined" || typeof document === "undefined") return "";
9451
9451
  const name = cname + "=";
9452
9452
  const ca = document.cookie.split(";");
9453
9453
  for (let i = 0; i < ca.length; i++) {
@@ -9465,7 +9465,7 @@ function deleteCookieByName(name) {
9465
9465
  if (getCookieByName(name) === "") {
9466
9466
  return;
9467
9467
  }
9468
- if (typeof window === "undefined") {
9468
+ if (typeof window === "undefined" || typeof document === "undefined") {
9469
9469
  return;
9470
9470
  }
9471
9471
  const { hostname } = window.location;
@@ -9482,13 +9482,70 @@ function deleteCookieByName(name) {
9482
9482
  } while (getCookieByName(name) !== "" && hostname !== domain);
9483
9483
  generalDomain = domain;
9484
9484
  }
9485
+ var UniversalStorage = class {
9486
+ constructor() {
9487
+ this.adapter = null;
9488
+ this.memoryStorage = /* @__PURE__ */ (() => {
9489
+ const store = /* @__PURE__ */ new Map();
9490
+ return {
9491
+ getItem: (key) => {
9492
+ var _a;
9493
+ return (_a = store.get(key)) != null ? _a : null;
9494
+ },
9495
+ setItem: (key, value) => {
9496
+ store.set(key, value);
9497
+ },
9498
+ removeItem: (key) => {
9499
+ store.delete(key);
9500
+ }
9501
+ };
9502
+ })();
9503
+ }
9504
+ setAdapter(adapter) {
9505
+ this.adapter = adapter;
9506
+ }
9507
+ getStorage() {
9508
+ if (this.adapter) {
9509
+ return this.adapter;
9510
+ }
9511
+ if (typeof window !== "undefined" && window.localStorage) {
9512
+ return window.localStorage;
9513
+ }
9514
+ console.warn(
9515
+ "No storage adapter available. Using in-memory storage. Data will not persist."
9516
+ );
9517
+ return this.memoryStorage;
9518
+ }
9519
+ getItem(key) {
9520
+ try {
9521
+ return this.getStorage().getItem(key);
9522
+ } catch (error) {
9523
+ console.error(`Storage getItem error for key "${key}":`, error);
9524
+ return null;
9525
+ }
9526
+ }
9527
+ setItem(key, value) {
9528
+ try {
9529
+ this.getStorage().setItem(key, value);
9530
+ } catch (error) {
9531
+ console.error(`Storage setItem error for key "${key}":`, error);
9532
+ }
9533
+ }
9534
+ removeItem(key) {
9535
+ try {
9536
+ this.getStorage().removeItem(key);
9537
+ } catch (error) {
9538
+ console.error(`Storage removeItem error for key "${key}":`, error);
9539
+ }
9540
+ }
9541
+ };
9542
+ var storage = new UniversalStorage();
9485
9543
  var headers = {
9486
9544
  Accept: "application/vnd.api+json",
9487
9545
  "Content-Type": "application/vnd.api+json"
9488
9546
  };
9489
- var isWindowDefined = typeof window !== "undefined";
9490
- var authGuestToken = isWindowDefined ? localStorage.getItem("auth_guest_token") : "";
9491
- if (isWindowDefined && authGuestToken) {
9547
+ var authGuestToken = storage.getItem("auth_guest_token");
9548
+ if (authGuestToken) {
9492
9549
  headers["Authorization-Guest"] = authGuestToken;
9493
9550
  }
9494
9551
  var setAxiosHeader = (key, value) => {
@@ -9593,12 +9650,14 @@ var logoutUser = async ({
9593
9650
  try {
9594
9651
  await logout();
9595
9652
  onLogoutSuccess && onLogoutSuccess();
9653
+ storage.removeItem("user_data");
9596
9654
  if (isBrowser) {
9597
- window.localStorage.removeItem("user_data");
9598
9655
  setIsLogged && setIsLogged(false);
9599
- const event = new window.CustomEvent("tf-logout");
9600
9656
  deleteCookieByName("X-TF-ECOMMERCE");
9601
- window.document.dispatchEvent(event);
9657
+ if (typeof document !== "undefined") {
9658
+ const event = new window.CustomEvent("tf-logout");
9659
+ document.dispatchEvent(event);
9660
+ }
9602
9661
  }
9603
9662
  } catch (e) {
9604
9663
  onLogoutError && onLogoutError(e);
@@ -9617,9 +9676,18 @@ var getQueryVariable = (variable) => {
9617
9676
  }
9618
9677
  return false;
9619
9678
  };
9679
+ var priceWithCurrency = (value = "", currency = "US$") => {
9680
+ const num = parseFloat(value);
9681
+ const safe = Number.isFinite(num) ? num : 0;
9682
+ const formatted = safe.toLocaleString("en-US", {
9683
+ minimumFractionDigits: 2,
9684
+ maximumFractionDigits: 2
9685
+ });
9686
+ return `${currency} ${formatted}`;
9687
+ };
9620
9688
  publicRequest.interceptors.request.use((config) => {
9621
9689
  var _a;
9622
- const guestToken = isBrowser ? window.localStorage.getItem("auth_guest_token") : null;
9690
+ const guestToken = storage.getItem("auth_guest_token");
9623
9691
  if (guestToken) {
9624
9692
  config.headers["Authorization-Guest"] = guestToken;
9625
9693
  }
@@ -9627,7 +9695,7 @@ publicRequest.interceptors.request.use((config) => {
9627
9695
  if (xtfCookie) {
9628
9696
  config.headers["X-TF-ECOMMERCE"] = xtfCookie;
9629
9697
  }
9630
- const additionalCookiesHeaderValue = isBrowser ? (_a = document.cookie) != null ? _a : "" : "";
9698
+ const additionalCookiesHeaderValue = isBrowser && typeof document !== "undefined" ? (_a = document.cookie) != null ? _a : "" : "";
9631
9699
  if (additionalCookiesHeaderValue !== "") {
9632
9700
  config.headers["Additional-Cookies"] = additionalCookiesHeaderValue;
9633
9701
  }
@@ -9646,8 +9714,8 @@ publicRequest.interceptors.response.use(
9646
9714
  "headers.authorization-guest",
9647
9715
  ""
9648
9716
  );
9649
- if (isBrowser && authGuestToken2) {
9650
- window.localStorage.setItem("auth_guest_token", authGuestToken2);
9717
+ if (authGuestToken2) {
9718
+ storage.setItem("auth_guest_token", authGuestToken2);
9651
9719
  publicRequest.setGuestToken(authGuestToken2);
9652
9720
  }
9653
9721
  const xtfCookie = _get2(response, "headers.x-tf-ecommerce");
@@ -9661,8 +9729,8 @@ publicRequest.interceptors.response.use(
9661
9729
  (error) => {
9662
9730
  var _a;
9663
9731
  if (((_a = error == null ? void 0 : error.response) == null ? void 0 : _a.status) === 401) {
9732
+ storage.removeItem("user_data");
9664
9733
  if (isBrowser) {
9665
- window.localStorage.removeItem("user_data");
9666
9734
  const errorType = _get2(error, "response.data.error");
9667
9735
  if (errorType === "invalid_token") {
9668
9736
  window.location.href = "/";
@@ -9670,8 +9738,8 @@ publicRequest.interceptors.response.use(
9670
9738
  }
9671
9739
  }
9672
9740
  const authGuestToken2 = _get2(error, "response.headers.authorization-guest");
9673
- if (isBrowser && authGuestToken2) {
9674
- window.localStorage.setItem("auth_guest_token", authGuestToken2);
9741
+ if (authGuestToken2) {
9742
+ storage.setItem("auth_guest_token", authGuestToken2);
9675
9743
  publicRequest.setGuestToken(authGuestToken2);
9676
9744
  }
9677
9745
  return Promise.reject(error);
@@ -9684,7 +9752,7 @@ var addToCart2 = async (id, data) => {
9684
9752
  {
9685
9753
  headers: {
9686
9754
  ...publicRequest.defaults.headers.common,
9687
- "Referer-Url": isBrowser ? document.referrer : ""
9755
+ "Referer-Url": isBrowser && typeof document !== "undefined" ? document.referrer : ""
9688
9756
  }
9689
9757
  }
9690
9758
  );
@@ -9714,7 +9782,7 @@ var getEvent = async (id, pk) => {
9714
9782
  if (isBrowser) {
9715
9783
  const params = new URL(`${window.location}`);
9716
9784
  const referralId = params.searchParams.get("ttf_r") || "";
9717
- const referral_key = window.localStorage.getItem("referral_key");
9785
+ const referral_key = storage.getItem("referral_key");
9718
9786
  const [, referralIdlocal] = (referral_key || "").split(".");
9719
9787
  referralValue = referralId || (referralIdlocal != null ? referralIdlocal : "");
9720
9788
  invitationHash = params.searchParams.get("invitation-hash") || null;
@@ -9723,7 +9791,7 @@ var getEvent = async (id, pk) => {
9723
9791
  params: { pk, invitationHash },
9724
9792
  headers: {
9725
9793
  ...publicRequest.defaults.headers.common,
9726
- "Referer-Url": isBrowser ? document.referrer : "",
9794
+ "Referer-Url": isBrowser && typeof document !== "undefined" ? document.referrer : "",
9727
9795
  "Referrer-Id": isBrowser ? referralValue : ""
9728
9796
  }
9729
9797
  });
@@ -9733,9 +9801,9 @@ var getTickets = async (eventId, promoCode, pk) => {
9733
9801
  const invitationHash = getQueryVariable("invitation-hash");
9734
9802
  const referralId = getQueryVariable("ttf_r");
9735
9803
  if (referralId) {
9736
- window.localStorage.setItem("promoter_id", referralId);
9804
+ storage.setItem("promoter_id", referralId);
9737
9805
  }
9738
- const promoterId = window.localStorage.getItem("promoter_id");
9806
+ const promoterId = storage.getItem("promoter_id");
9739
9807
  const params = { pk };
9740
9808
  if (invitationHash) {
9741
9809
  params["invitation-hash"] = invitationHash;
@@ -9748,7 +9816,7 @@ var getTickets = async (eventId, promoCode, pk) => {
9748
9816
  if (promoCode) {
9749
9817
  headers2["Promotion-Event"] = String(eventId);
9750
9818
  headers2["Promotion-Code"] = promoCode;
9751
- window.localStorage.removeItem("promoter_id");
9819
+ storage.removeItem("promoter_id");
9752
9820
  }
9753
9821
  const response = await publicRequest.get(`v1/event/${eventId}/tickets/`, {
9754
9822
  params,
@@ -9778,9 +9846,9 @@ var getTimeSlotsByDate = async (eventId, date2, promoCode, pk) => {
9778
9846
  const invitationHash = getQueryVariable("invitation-hash");
9779
9847
  const referralId = getQueryVariable("ttf_r");
9780
9848
  if (referralId) {
9781
- window.localStorage.setItem("promoter_id", referralId);
9849
+ storage.setItem("promoter_id", referralId);
9782
9850
  }
9783
- const promoterId = window.localStorage.getItem("promoter_id");
9851
+ const promoterId = storage.getItem("promoter_id");
9784
9852
  const params = { pk };
9785
9853
  if (invitationHash) {
9786
9854
  params["invitation-hash"] = invitationHash;
@@ -9793,7 +9861,7 @@ var getTimeSlotsByDate = async (eventId, date2, promoCode, pk) => {
9793
9861
  if (promoCode) {
9794
9862
  headers2["Promotion-Event"] = String(eventId);
9795
9863
  headers2["Promotion-Code"] = promoCode;
9796
- window.localStorage.removeItem("promoter_id");
9864
+ storage.removeItem("promoter_id");
9797
9865
  }
9798
9866
  const response = await publicRequest.get(`v1/event/${eventId}/timeslots`, {
9799
9867
  params: {
@@ -9846,7 +9914,7 @@ var getOrderDetails = async (orderId) => {
9846
9914
  };
9847
9915
  var getPaymentData = async (hash) => {
9848
9916
  const response = await publicRequest.get(`v1/order/${hash}/review`, {
9849
- headers: { "Referer-Url": isBrowser ? document.referrer : "" }
9917
+ headers: { "Referer-Url": isBrowser && typeof document !== "undefined" ? document.referrer : "" }
9850
9918
  });
9851
9919
  return response.data;
9852
9920
  };
@@ -9854,7 +9922,7 @@ var handlePaymentSuccess = async (orderHash) => {
9854
9922
  const response = await publicRequest.post(`v1/order/${orderHash}/success`, void 0, {
9855
9923
  headers: {
9856
9924
  ...publicRequest.defaults.headers.common,
9857
- "Referer-Url": isBrowser ? document.referrer : ""
9925
+ "Referer-Url": isBrowser && typeof document !== "undefined" ? document.referrer : ""
9858
9926
  }
9859
9927
  });
9860
9928
  return response.data;
@@ -9863,7 +9931,7 @@ var handleFreeSuccess = async (orderHash) => {
9863
9931
  const response = await publicRequest.post(
9864
9932
  `v1/order/${orderHash}/complete_free_registration`,
9865
9933
  void 0,
9866
- { headers: { "Referer-Url": isBrowser ? document.referrer : "" } }
9934
+ { headers: { "Referer-Url": isBrowser && typeof document !== "undefined" ? document.referrer : "" } }
9867
9935
  );
9868
9936
  return response.data;
9869
9937
  };
@@ -11811,7 +11879,7 @@ var Checkout = forwardRef15(
11811
11879
  if (item.id === key) {
11812
11880
  item.title = (_b2 = (_a3 = texts == null ? void 0 : texts.orderReviewItems) == null ? void 0 : _a3[key]) != null ? _b2 : item.title;
11813
11881
  if (key === "price" || key === "total") {
11814
- item.value = priceWithCurrency2(value, currency);
11882
+ item.value = priceWithCurrency(value, currency);
11815
11883
  } else {
11816
11884
  item.value = value;
11817
11885
  }
@@ -14434,7 +14502,7 @@ var TicketListItem2 = ({
14434
14502
  const feesIncluded = ticket.feeIncluded ? feesIncludedText : feesExcludedText;
14435
14503
  const showOldPrice = ticket.price !== ticket.oldPrice;
14436
14504
  const isTicketFree = +ticket.price === 0;
14437
- const ticketPrice = isSoldOut ? soldOutText : isTicketFree ? freeText : priceWithCurrency3(ticket.price.toFixed(2).toString(), ticket.priceSymbol);
14505
+ const ticketPrice = isSoldOut ? soldOutText : isTicketFree ? freeText : priceWithCurrency(ticket.price.toFixed(2).toString(), ticket.priceSymbol);
14438
14506
  const maximumOption = (_a = _maxBy(dropdownOptions, (o) => o.value)) == null ? void 0 : _a.value;
14439
14507
  let rightContent = /* @__PURE__ */ jsx63(Fragment18, {});
14440
14508
  if (ticket.soldOut || ticket.sold_out || !ticket.displayTicket) {
@@ -14456,7 +14524,7 @@ var TicketListItem2 = ({
14456
14524
  /* @__PURE__ */ jsx63(Text32, { style: [CartListItemStyles.ticketNumber, styles3 == null ? void 0 : styles3.ticketName], numberOfLines: 2, children: ticket.displayName.toUpperCase() || `${ticketText} ${ticketNumber}` }),
14457
14525
  isSoldOut ? /* @__PURE__ */ jsx63(View40, { style: [CartListItemStyles.soldOutContainer, styles3 == null ? void 0 : styles3.soldOutContainer], children: /* @__PURE__ */ jsx63(Text32, { style: [CartListItemStyles.soldOut, styles3 == null ? void 0 : styles3.soldOutText], children: soldOutMessage }) }) : /* @__PURE__ */ jsxs33(Fragment18, { children: [
14458
14526
  /* @__PURE__ */ jsxs33(View40, { style: styles3 == null ? void 0 : styles3.pricesContainer, children: [
14459
- showOldPrice && /* @__PURE__ */ jsx63(Text32, { style: [CartListItemStyles.oldPrice, styles3 == null ? void 0 : styles3.oldPrice], children: priceWithCurrency3((_b = ticket.oldPrice) == null ? void 0 : _b.toString(), ticket.priceSymbol) }),
14527
+ showOldPrice && /* @__PURE__ */ jsx63(Text32, { style: [CartListItemStyles.oldPrice, styles3 == null ? void 0 : styles3.oldPrice], children: priceWithCurrency((_b = ticket.oldPrice) == null ? void 0 : _b.toString(), ticket.priceSymbol) }),
14460
14528
  /* @__PURE__ */ jsx63(Text32, { style: [CartListItemStyles.price, styles3 == null ? void 0 : styles3.price], children: ticketPrice })
14461
14529
  ] }),
14462
14530
  /* @__PURE__ */ jsx63(Text32, { style: [CartListItemStyles.tax, styles3 == null ? void 0 : styles3.fees], children: feesIncluded.toUpperCase() })
@@ -15981,11 +16049,11 @@ var useCheckoutFlow = ({
15981
16049
  updatedOrderItems.push({
15982
16050
  id: ticket.ticket_type_id,
15983
16051
  title: ticket.ticket_type_name,
15984
- subtitle: `${ticket.quantity} x ${priceWithCurrency5(
16052
+ subtitle: `${ticket.quantity} x ${priceWithCurrency(
15985
16053
  ticket.price_per_ticket,
15986
16054
  currency
15987
16055
  )}`,
15988
- value: priceWithCurrency5(ticket.total_price.toString(), currency)
16056
+ value: priceWithCurrency(ticket.total_price.toString(), currency)
15989
16057
  });
15990
16058
  });
15991
16059
  }
@@ -15994,11 +16062,11 @@ var useCheckoutFlow = ({
15994
16062
  updatedOrderItems.push({
15995
16063
  id: `addon_${addon.add_on_name}`,
15996
16064
  title: `${addon.add_on_name} (Add-on)`,
15997
- subtitle: `${addon.quantity} x ${priceWithCurrency5(
16065
+ subtitle: `${addon.quantity} x ${priceWithCurrency(
15998
16066
  addon.price_per_add_on,
15999
16067
  currency
16000
16068
  )}`,
16001
- value: priceWithCurrency5(addon.total_price.toString(), currency)
16069
+ value: priceWithCurrency(addon.total_price.toString(), currency)
16002
16070
  });
16003
16071
  });
16004
16072
  }
@@ -16006,13 +16074,13 @@ var useCheckoutFlow = ({
16006
16074
  updatedOrderItems.push({
16007
16075
  id: "tax",
16008
16076
  title: cartPriceBreakdown.goods_tax_name || "Tax",
16009
- value: priceWithCurrency5(cartPriceBreakdown.goods_tax.toString(), currency)
16077
+ value: priceWithCurrency(cartPriceBreakdown.goods_tax.toString(), currency)
16010
16078
  });
16011
16079
  }
16012
16080
  updatedOrderItems.push({
16013
16081
  id: "total",
16014
16082
  title: "Total",
16015
- value: priceWithCurrency5(cartPriceBreakdown.total.toString(), currency)
16083
+ value: priceWithCurrency(cartPriceBreakdown.total.toString(), currency)
16016
16084
  });
16017
16085
  setOrderItems(updatedOrderItems);
16018
16086
  },
@@ -16114,14 +16182,14 @@ var useCheckoutFlow = ({
16114
16182
  items.push({
16115
16183
  id: "price",
16116
16184
  title: "Ticket Price",
16117
- value: priceWithCurrency5(cartData.cart[0].price, currency)
16185
+ value: priceWithCurrency(cartData.cart[0].price, currency)
16118
16186
  });
16119
16187
  }
16120
16188
  const total = ((_m2 = (_l2 = cartData.cart) == null ? void 0 : _l2[0]) == null ? void 0 : _m2.price) || 0;
16121
16189
  items.push({
16122
16190
  id: "total",
16123
16191
  title: "Total",
16124
- value: priceWithCurrency5(total, currency)
16192
+ value: priceWithCurrency(total, currency)
16125
16193
  });
16126
16194
  setOrderItems(items);
16127
16195
  }
@@ -16398,7 +16466,7 @@ var AddonsContainer = ({
16398
16466
  const priceWithFees = addonData.price || 0;
16399
16467
  const addonCurrency = addonData.currency || currency;
16400
16468
  const isAddonFree = Number(priceWithFees) === 0;
16401
- const basePriceFormatted = isAddonFree ? "FREE" : priceWithCurrency6((priceWithFees / 100).toString(), addonCurrency);
16469
+ const basePriceFormatted = isAddonFree ? "FREE" : priceWithCurrency((priceWithFees / 100).toString(), addonCurrency);
16402
16470
  return /* @__PURE__ */ jsxs36(View42, { style: [customStyles == null ? void 0 : customStyles.addonItem], children: [
16403
16471
  /* @__PURE__ */ jsxs36(View42, { style: [customStyles == null ? void 0 : customStyles.addonRow], children: [
16404
16472
  /* @__PURE__ */ jsxs36(View42, { style: [customStyles == null ? void 0 : customStyles.addonInfo], children: [
@@ -18063,6 +18131,38 @@ var CheckoutProvider = ({ children }) => {
18063
18131
 
18064
18132
  // src/index.tsx
18065
18133
  import { LogBox, NativeModules } from "react-native";
18134
+
18135
+ // src/utils/storageAdapter.ts
18136
+ import { MMKV } from "react-native-mmkv";
18137
+ var mmkvStorage = new MMKV();
18138
+ var reactNativeStorageAdapter = {
18139
+ getItem: (key) => {
18140
+ try {
18141
+ const value = mmkvStorage.getString(key);
18142
+ return value != null ? value : null;
18143
+ } catch (error) {
18144
+ console.error(`[StorageAdapter] getItem error for key "${key}":`, error);
18145
+ return null;
18146
+ }
18147
+ },
18148
+ setItem: (key, value) => {
18149
+ try {
18150
+ mmkvStorage.set(key, value);
18151
+ } catch (error) {
18152
+ console.error(`[StorageAdapter] setItem error for key "${key}":`, error);
18153
+ }
18154
+ },
18155
+ removeItem: (key) => {
18156
+ try {
18157
+ mmkvStorage.delete(key);
18158
+ } catch (error) {
18159
+ console.error(`[StorageAdapter] removeItem error for key "${key}":`, error);
18160
+ }
18161
+ }
18162
+ };
18163
+
18164
+ // src/index.tsx
18165
+ storage.setAdapter(reactNativeStorageAdapter);
18066
18166
  LogBox.ignoreAllLogs();
18067
18167
  var index_default = NativeModules.TFCheckoutRNModule;
18068
18168
  export {
@@ -18139,6 +18239,7 @@ export {
18139
18239
  setConfigs,
18140
18240
  setCustomCookie,
18141
18241
  setLoggedUserData,
18242
+ storage,
18142
18243
  updateCheckout,
18143
18244
  useAddToCart,
18144
18245
  useAddons,