@odynn/awayz-core 0.3.23 → 0.3.25

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.
@@ -3,21 +3,21 @@ import * as i from "react";
3
3
  import { useMemo as nt } from "react";
4
4
  import { u as D, a as ot, c as A, b as q, d as ve, e as st, f as it, g as G, o as at, s as lt, h as ct, i as dt, j as ut, k as pt, l as ft, m as ht, n as vt, p as mt, P as me } from "../../index-BC-KTkxU.js";
5
5
  import { r as yt, R as gt } from "../../index-Cv-wvFlM.js";
6
- import { b as ue } from "../../index-CDh8vAM_.js";
6
+ import { useQuery as Ct } from "@tanstack/react-query";
7
7
  import "../../arrayExtensions-DlcBOj5a.js";
8
- import { E as Ct } from "../../AccountService-cvx__9rR.js";
9
- import { useQuery as Et } from "@tanstack/react-query";
10
- import { CurrencyService as wt } from "../../services/currency/CurrencyService.js";
11
- import '../../assets/_styles5.css';import '../../assets/_styles4.css';import '../../assets/_styles3.css';import '../../assets/_styles2.css';import '../../assets/_styles.css';/* empty css */
8
+ import { E as Et } from "../../AccountService-cvx__9rR.js";
9
+ import { b as ue } from "../../index-CDh8vAM_.js";
12
10
  import "../../context/AwayzContext.js";
13
11
  import "../../configs/awayzClient.js";
14
- import { useAwayzContext as Pt } from "../../hooks/useAwayzContext.js";
12
+ import { useAwayzContext as wt } from "../../hooks/useAwayzContext.js";
15
13
  import "../../services/noRetryInstance.js";
14
+ import { CurrencyService as Pt } from "../../services/currency/CurrencyService.js";
16
15
  import { EInvalidAmountDisplayOption as N, EToolTipPosition as bt } from "./CashValueTypes.js";
17
- /* empty css */
16
+ import '../../assets/_styles.css';import '../../assets/_styles5.css';import '../../assets/_styles4.css';import '../../assets/_styles3.css';import '../../assets/_styles2.css';/* empty css */
18
17
  /* empty css */
19
18
  /* empty css */
20
19
  /* empty css */
20
+ /* empty css */
21
21
  const Y = (e, t) => {
22
22
  var r = new Intl.NumberFormat("en-US", {
23
23
  style: "currency",
@@ -125,24 +125,24 @@ var _t = "DismissableLayer", z = "dismissableLayer.update", Lt = "dismissableLay
125
125
  onInteractOutside: a,
126
126
  onDismiss: u,
127
127
  ...l
128
- } = e, p = i.useContext(ge), [d, f] = i.useState(null), h = (d == null ? void 0 : d.ownerDocument) ?? (globalThis == null ? void 0 : globalThis.document), [, v] = i.useState({}), m = D(t, (g) => f(g)), y = Array.from(p.layers), [C] = [...p.layersWithOutsidePointerEventsDisabled].slice(-1), w = y.indexOf(C), E = d ? y.indexOf(d) : -1, x = p.layersWithOutsidePointerEventsDisabled.size > 0, P = E >= w, T = kt((g) => {
128
+ } = e, p = i.useContext(ge), [d, f] = i.useState(null), v = (d == null ? void 0 : d.ownerDocument) ?? (globalThis == null ? void 0 : globalThis.document), [, h] = i.useState({}), m = D(t, (g) => f(g)), y = Array.from(p.layers), [C] = [...p.layersWithOutsidePointerEventsDisabled].slice(-1), w = y.indexOf(C), E = d ? y.indexOf(d) : -1, x = p.layersWithOutsidePointerEventsDisabled.size > 0, P = E >= w, T = kt((g) => {
129
129
  const S = g.target, F = [...p.branches].some((I) => I.contains(S));
130
130
  !P || F || (n == null || n(g), a == null || a(g), g.defaultPrevented || u == null || u());
131
- }, h), b = Ft((g) => {
131
+ }, v), b = Ft((g) => {
132
132
  const S = g.target;
133
133
  [...p.branches].some((I) => I.contains(S)) || (s == null || s(g), a == null || a(g), g.defaultPrevented || u == null || u());
134
- }, h);
134
+ }, v);
135
135
  return ot((g) => {
136
136
  E === p.layers.size - 1 && (o == null || o(g), !g.defaultPrevented && u && (g.preventDefault(), u()));
137
- }, h), i.useEffect(() => {
137
+ }, v), i.useEffect(() => {
138
138
  if (d)
139
- return r && (p.layersWithOutsidePointerEventsDisabled.size === 0 && (fe = h.body.style.pointerEvents, h.body.style.pointerEvents = "none"), p.layersWithOutsidePointerEventsDisabled.add(d)), p.layers.add(d), he(), () => {
140
- r && p.layersWithOutsidePointerEventsDisabled.size === 1 && (h.body.style.pointerEvents = fe);
139
+ return r && (p.layersWithOutsidePointerEventsDisabled.size === 0 && (fe = v.body.style.pointerEvents, v.body.style.pointerEvents = "none"), p.layersWithOutsidePointerEventsDisabled.add(d)), p.layers.add(d), he(), () => {
140
+ r && p.layersWithOutsidePointerEventsDisabled.size === 1 && (v.body.style.pointerEvents = fe);
141
141
  };
142
- }, [d, h, r, p]), i.useEffect(() => () => {
142
+ }, [d, v, r, p]), i.useEffect(() => () => {
143
143
  d && (p.layers.delete(d), p.layersWithOutsidePointerEventsDisabled.delete(d), he());
144
144
  }, [d, p]), i.useEffect(() => {
145
- const g = () => v({});
145
+ const g = () => h({});
146
146
  return document.addEventListener(z, g), () => document.removeEventListener(z, g);
147
147
  }, []), /* @__PURE__ */ c(
148
148
  O.div,
@@ -271,8 +271,8 @@ var Q = "PopperContent", [Ut, Yt] = Pe(Q), Oe = i.forwardRef(
271
271
  collisionBoundary: p = [],
272
272
  collisionPadding: d = 0,
273
273
  sticky: f = "partial",
274
- hideWhenDetached: h = !1,
275
- updatePositionStrategy: v = "optimized",
274
+ hideWhenDetached: v = !1,
275
+ updatePositionStrategy: h = "optimized",
276
276
  onPlaced: m,
277
277
  ...y
278
278
  } = e, C = xe(Q, r), [w, E] = i.useState(null), x = D(t, (M) => E(M)), [P, T] = i.useState(null), b = st(P), g = (b == null ? void 0 : b.width) ?? 0, S = (b == null ? void 0 : b.height) ?? 0, F = o + (s !== "center" ? "-" + s : ""), I = typeof d == "number" ? d : { top: 0, right: 0, bottom: 0, left: 0, ...d }, te = Array.isArray(p) ? p : [p], Ye = te.length > 0, $ = {
@@ -285,7 +285,7 @@ var Q = "PopperContent", [Ut, Yt] = Pe(Q), Oe = i.forwardRef(
285
285
  strategy: "fixed",
286
286
  placement: F,
287
287
  whileElementsMounted: (...M) => ht(...M, {
288
- animationFrame: v === "always"
288
+ animationFrame: h === "always"
289
289
  }),
290
290
  elements: {
291
291
  reference: C.anchor
@@ -308,7 +308,7 @@ var Q = "PopperContent", [Ut, Yt] = Pe(Q), Oe = i.forwardRef(
308
308
  }),
309
309
  P && ut({ element: P, padding: u }),
310
310
  Gt({ arrowWidth: g, arrowHeight: S }),
311
- h && pt({ strategy: "referenceHidden", ...$ })
311
+ v && pt({ strategy: "referenceHidden", ...$ })
312
312
  ]
313
313
  }), [ne, Ge] = De(je), B = q(m);
314
314
  G(() => {
@@ -431,9 +431,9 @@ var Gt = (e) => ({
431
431
  options: e,
432
432
  fn(t) {
433
433
  var C, w, E;
434
- const { placement: r, rects: o, middlewareData: n } = t, a = ((C = n.arrow) == null ? void 0 : C.centerOffset) !== 0, u = a ? 0 : e.arrowWidth, l = a ? 0 : e.arrowHeight, [p, d] = De(r), f = { start: "0%", center: "50%", end: "100%" }[d], h = (((w = n.arrow) == null ? void 0 : w.x) ?? 0) + u / 2, v = (((E = n.arrow) == null ? void 0 : E.y) ?? 0) + l / 2;
434
+ const { placement: r, rects: o, middlewareData: n } = t, a = ((C = n.arrow) == null ? void 0 : C.centerOffset) !== 0, u = a ? 0 : e.arrowWidth, l = a ? 0 : e.arrowHeight, [p, d] = De(r), f = { start: "0%", center: "50%", end: "100%" }[d], v = (((w = n.arrow) == null ? void 0 : w.x) ?? 0) + u / 2, h = (((E = n.arrow) == null ? void 0 : E.y) ?? 0) + l / 2;
435
435
  let m = "", y = "";
436
- return p === "bottom" ? (m = a ? f : `${h}px`, y = `${-l}px`) : p === "top" ? (m = a ? f : `${h}px`, y = `${o.floating.height + l}px`) : p === "right" ? (m = `${-l}px`, y = a ? f : `${v}px`) : p === "left" && (m = `${o.floating.width + l}px`, y = a ? f : `${v}px`), { data: { x: m, y } };
436
+ return p === "bottom" ? (m = a ? f : `${v}px`, y = `${-l}px`) : p === "top" ? (m = a ? f : `${v}px`, y = `${o.floating.height + l}px`) : p === "right" ? (m = `${-l}px`, y = a ? f : `${h}px`) : p === "left" && (m = `${o.floating.width + l}px`, y = a ? f : `${h}px`), { data: { x: m, y } };
437
437
  }
438
438
  });
439
439
  function De(e) {
@@ -518,7 +518,7 @@ var H = "Tooltip", [nr, k] = V(H), He = (e) => {
518
518
  onOpenChange: s,
519
519
  disableHoverableContent: a,
520
520
  delayDuration: u
521
- } = e, l = J(H, e.__scopeTooltip), p = j(t), [d, f] = i.useState(null), h = vt(), v = i.useRef(0), m = a ?? l.disableHoverableContent, y = u ?? l.delayDuration, C = i.useRef(!1), [w, E] = mt({
521
+ } = e, l = J(H, e.__scopeTooltip), p = j(t), [d, f] = i.useState(null), v = vt(), h = i.useRef(0), m = a ?? l.disableHoverableContent, y = u ?? l.delayDuration, C = i.useRef(!1), [w, E] = mt({
522
522
  prop: o,
523
523
  defaultProp: n ?? !1,
524
524
  onChange: (g) => {
@@ -526,21 +526,21 @@ var H = "Tooltip", [nr, k] = V(H), He = (e) => {
526
526
  },
527
527
  caller: H
528
528
  }), x = i.useMemo(() => w ? C.current ? "delayed-open" : "instant-open" : "closed", [w]), P = i.useCallback(() => {
529
- window.clearTimeout(v.current), v.current = 0, C.current = !1, E(!0);
529
+ window.clearTimeout(h.current), h.current = 0, C.current = !1, E(!0);
530
530
  }, [E]), T = i.useCallback(() => {
531
- window.clearTimeout(v.current), v.current = 0, E(!1);
531
+ window.clearTimeout(h.current), h.current = 0, E(!1);
532
532
  }, [E]), b = i.useCallback(() => {
533
- window.clearTimeout(v.current), v.current = window.setTimeout(() => {
534
- C.current = !0, E(!0), v.current = 0;
533
+ window.clearTimeout(h.current), h.current = window.setTimeout(() => {
534
+ C.current = !0, E(!0), h.current = 0;
535
535
  }, y);
536
536
  }, [y, E]);
537
537
  return i.useEffect(() => () => {
538
- v.current && (window.clearTimeout(v.current), v.current = 0);
538
+ h.current && (window.clearTimeout(h.current), h.current = 0);
539
539
  }, []), /* @__PURE__ */ c(zt, { ...p, children: /* @__PURE__ */ c(
540
540
  nr,
541
541
  {
542
542
  scope: t,
543
- contentId: h,
543
+ contentId: v,
544
544
  open: w,
545
545
  stateAttribute: x,
546
546
  trigger: d,
@@ -549,7 +549,7 @@ var H = "Tooltip", [nr, k] = V(H), He = (e) => {
549
549
  l.isOpenDelayedRef.current ? b() : P();
550
550
  }, [l.isOpenDelayedRef, b, P]),
551
551
  onTriggerLeave: i.useCallback(() => {
552
- m ? T() : (window.clearTimeout(v.current), v.current = 0);
552
+ m ? T() : (window.clearTimeout(h.current), h.current = 0);
553
553
  }, [T, m]),
554
554
  onOpen: P,
555
555
  onClose: T,
@@ -569,8 +569,8 @@ var Z = "TooltipTrigger", ke = i.forwardRef(
569
569
  "data-state": n.stateAttribute,
570
570
  ...o,
571
571
  ref: l,
572
- onPointerMove: A(e.onPointerMove, (h) => {
573
- h.pointerType !== "touch" && !d.current && !s.isPointerInTransitRef.current && (n.onTriggerEnter(), d.current = !0);
572
+ onPointerMove: A(e.onPointerMove, (v) => {
573
+ v.pointerType !== "touch" && !d.current && !s.isPointerInTransitRef.current && (n.onTriggerEnter(), d.current = !0);
574
574
  }),
575
575
  onPointerLeave: A(e.onPointerLeave, () => {
576
576
  n.onTriggerLeave(), d.current = !1;
@@ -601,31 +601,31 @@ var L = "TooltipContent", $e = i.forwardRef(
601
601
  return /* @__PURE__ */ c(me, { present: o || a.open, children: a.disableHoverableContent ? /* @__PURE__ */ c(We, { side: n, ...s, ref: t }) : /* @__PURE__ */ c(ir, { side: n, ...s, ref: t }) });
602
602
  }
603
603
  ), ir = i.forwardRef((e, t) => {
604
- const r = k(L, e.__scopeTooltip), o = J(L, e.__scopeTooltip), n = i.useRef(null), s = D(t, n), [a, u] = i.useState(null), { trigger: l, onClose: p } = r, d = n.current, { onPointerInTransitChange: f } = o, h = i.useCallback(() => {
604
+ const r = k(L, e.__scopeTooltip), o = J(L, e.__scopeTooltip), n = i.useRef(null), s = D(t, n), [a, u] = i.useState(null), { trigger: l, onClose: p } = r, d = n.current, { onPointerInTransitChange: f } = o, v = i.useCallback(() => {
605
605
  u(null), f(!1);
606
- }, [f]), v = i.useCallback(
606
+ }, [f]), h = i.useCallback(
607
607
  (m, y) => {
608
608
  const C = m.currentTarget, w = { x: m.clientX, y: m.clientY }, E = dr(w, C.getBoundingClientRect()), x = ur(w, E), P = pr(y.getBoundingClientRect()), T = hr([...x, ...P]);
609
609
  u(T), f(!0);
610
610
  },
611
611
  [f]
612
612
  );
613
- return i.useEffect(() => () => h(), [h]), i.useEffect(() => {
613
+ return i.useEffect(() => () => v(), [v]), i.useEffect(() => {
614
614
  if (l && d) {
615
- const m = (C) => v(C, d), y = (C) => v(C, l);
615
+ const m = (C) => h(C, d), y = (C) => h(C, l);
616
616
  return l.addEventListener("pointerleave", m), d.addEventListener("pointerleave", y), () => {
617
617
  l.removeEventListener("pointerleave", m), d.removeEventListener("pointerleave", y);
618
618
  };
619
619
  }
620
- }, [l, d, v, h]), i.useEffect(() => {
620
+ }, [l, d, h, v]), i.useEffect(() => {
621
621
  if (a) {
622
622
  const m = (y) => {
623
623
  const C = y.target, w = { x: y.clientX, y: y.clientY }, E = (l == null ? void 0 : l.contains(C)) || (d == null ? void 0 : d.contains(C)), x = !fr(w, a);
624
- E ? h() : x && (h(), p());
624
+ E ? v() : x && (v(), p());
625
625
  };
626
626
  return document.addEventListener("pointermove", m), () => document.removeEventListener("pointermove", m);
627
627
  }
628
- }, [l, d, a, p, h]), /* @__PURE__ */ c(We, { ...e, ref: s });
628
+ }, [l, d, a, p, v]), /* @__PURE__ */ c(We, { ...e, ref: s });
629
629
  }), [ar, lr] = V(H, { isInside: !1 }), cr = /* @__PURE__ */ At("TooltipContent"), We = i.forwardRef(
630
630
  (e, t) => {
631
631
  const {
@@ -638,9 +638,9 @@ var L = "TooltipContent", $e = i.forwardRef(
638
638
  } = e, l = k(L, r), p = j(r), { onClose: d } = l;
639
639
  return i.useEffect(() => (document.addEventListener(X, d), () => document.removeEventListener(X, d)), [d]), i.useEffect(() => {
640
640
  if (l.trigger) {
641
- const f = (h) => {
642
- const v = h.target;
643
- v != null && v.contains(l.trigger) && d();
641
+ const f = (v) => {
642
+ const h = v.target;
643
+ h != null && h.contains(l.trigger) && d();
644
644
  };
645
645
  return window.addEventListener("scroll", f, { capture: !0 }), () => window.removeEventListener("scroll", f, { capture: !0 });
646
646
  }
@@ -747,8 +747,8 @@ function fr(e, t) {
747
747
  const { x: r, y: o } = e;
748
748
  let n = !1;
749
749
  for (let s = 0, a = t.length - 1; s < t.length; a = s++) {
750
- const u = t[s], l = t[a], p = u.x, d = u.y, f = l.x, h = l.y;
751
- d > o != h > o && r < (f - p) * (o - d) / (h - d) + p && (n = !n);
750
+ const u = t[s], l = t[a], p = u.x, d = u.y, f = l.x, v = l.y;
751
+ d > o != v > o && r < (f - p) * (o - d) / (v - d) + p && (n = !n);
752
752
  }
753
753
  return n;
754
754
  }
@@ -789,10 +789,10 @@ const Pr = 1e3 * 60 * 60, Vr = ({
789
789
  zeroDisplayOption: o = N.NA,
790
790
  customDisplay: n
791
791
  }) => {
792
- var f;
793
- const { user: s } = Pt(), a = (f = s == null ? void 0 : s.userRegion) == null ? void 0 : f.currency, u = a !== t, { data: l, isPending: p } = Et({
794
- queryKey: [Ct.CONVERT_CURRENCY, t],
795
- queryFn: () => wt.convertCurrency({ baseCurrency: t }),
792
+ var f, v;
793
+ const { user: s } = wt(), a = ((f = s == null ? void 0 : s.preferences) == null ? void 0 : f.currency) ?? ((v = s == null ? void 0 : s.userRegion) == null ? void 0 : v.currency), u = a !== t, { data: l, isPending: p } = Ct({
794
+ queryKey: [Et.CONVERT_CURRENCY, t, a],
795
+ queryFn: () => Pt.convertCurrency({ baseCurrency: t }),
796
796
  enabled: u,
797
797
  staleTime: Pr
798
798
  }), d = nt(() => {
@@ -1,8 +1,9 @@
1
- var r = /* @__PURE__ */ ((e) => (e.SIGN_IN = "auth/user-login", e.SIGN_UP = "auth/sign-up", e.ME = "user", e.RESEND_VERIFICATION_EMAIL = "auth/resend-verification-email", e.UPDATE_USER_DETAILS = "account/update/user", e.CONFIRM_EMAIL = "account/verifyAccount", e.FORGOT_PASSWORD = "email/sendVeri", e.RESEND_OTP = "email/sendForgotPasswordVerification", e.RESET_PASSWORD = "account/updateUserPassword", e.REQUEST_LIMIT = "user/request-limit", e.APPLE_SOCIAL_SIGN_UP = "tp/apple/get/user", e.GOOGLE_SOCIAL_SIGN_UP = "tp/google/get/user", e.UPDATE_USER = "account/details/addUserDetails", e.ACKNOWLEDGEMENT = "account/update/userAcknowledgement", e.REGIONS = "user/region", e.UPDATE_USER_REGION = "/account/update/userRegion", e.UPDATE_PASSENGER_DETAILS = "/account/awayz", e.REFRESH_TOKEN = "auth/refresh-token", e.EXCHANGE_TOKEN = "user/exchange-token", e.REFRESH_EMBED_TOKEN = "user/refresh-token", e.OAUTH_INITIATE = "user/oauth2/initiate", e.OAUTH_CALLBACK = "user/oauth2/callback", e))(r || {}), a = /* @__PURE__ */ ((e) => (e.CURRENCY_CONVERSION = "currency/convert", e))(a || {}), _ = /* @__PURE__ */ ((e) => (e.USER_AWARDS = "user/rewards", e.USER_CARDS = "user/cards", e.ADD_USER_CARDS = "user/cards/add", e.REMOVE_USER_CARDS = "user/cards/remove", e.BANKS = "banks", e.CARDS = "cards", e))(_ || {}), S = /* @__PURE__ */ ((e) => (e.TRIPS = "user/trips", e.ADD_BOOKING = "user/trips/add-booking-to-trip", e.REMOVE_BOOKING = "user/trips/remove-booking-from-trip", e.UNCATEGORISED_BOOKINGS = "/user/trips/get-uncategorized-bookings", e))(S || {}), O = /* @__PURE__ */ ((e) => (e.USER_HOTEL_BOOKINGS = "/user/bookings/hotels", e.USER_FLIGHT_BOOKINGS = "/user/bookings/flights", e.INITIATE_FLIGHT_CANCEL = "/duffel/flights/initiate-order-cancellation", e.CONFIRM_FLIGHT_CANCEL = "/duffel/flights/confirm-order-cancellation", e.CANCEL_HOTEL_BOOKING = "/duffel/hotels/cancel", e))(O || {});
1
+ var r = /* @__PURE__ */ ((e) => (e.SIGN_IN = "auth/user-login", e.SIGN_UP = "auth/sign-up", e.ME = "user", e.RESEND_VERIFICATION_EMAIL = "auth/resend-verification-email", e.UPDATE_USER_DETAILS = "account/update/user", e.CONFIRM_EMAIL = "account/verifyAccount", e.FORGOT_PASSWORD = "email/sendVeri", e.RESEND_OTP = "email/sendForgotPasswordVerification", e.RESET_PASSWORD = "account/updateUserPassword", e.REQUEST_LIMIT = "user/request-limit", e.APPLE_SOCIAL_SIGN_UP = "tp/apple/get/user", e.GOOGLE_SOCIAL_SIGN_UP = "tp/google/get/user", e.UPDATE_USER = "account/details/addUserDetails", e.ACKNOWLEDGEMENT = "account/update/userAcknowledgement", e.REGIONS = "user/region", e.UPDATE_USER_REGION = "/account/update/userRegion", e.UPDATE_PASSENGER_DETAILS = "/account/awayz", e.REFRESH_TOKEN = "auth/refresh-token", e.EXCHANGE_TOKEN = "user/exchange-token", e.REFRESH_EMBED_TOKEN = "user/refresh-token", e.OAUTH_INITIATE = "user/oauth2/initiate", e.OAUTH_CALLBACK = "user/oauth2/callback", e))(r || {}), a = /* @__PURE__ */ ((e) => (e.CURRENCY_CONVERSION = "currency/convert", e))(a || {}), _ = /* @__PURE__ */ ((e) => (e.USER_AWARDS = "user/rewards", e.USER_CARDS = "user/cards", e.ADD_USER_CARDS = "user/cards/add", e.REMOVE_USER_CARDS = "user/cards/remove", e.BANKS = "banks", e.CARDS = "cards", e))(_ || {}), S = /* @__PURE__ */ ((e) => (e.TRIPS = "user/trips", e.ADD_BOOKING = "user/trips/add-booking-to-trip", e.REMOVE_BOOKING = "user/trips/remove-booking-from-trip", e.UNCATEGORISED_BOOKINGS = "/user/trips/get-uncategorized-bookings", e))(S || {}), R = /* @__PURE__ */ ((e) => (e.USER_HOTEL_BOOKINGS = "/user/bookings/hotels", e.USER_FLIGHT_BOOKINGS = "/user/bookings/flights", e.INITIATE_FLIGHT_CANCEL = "/duffel/flights/initiate-order-cancellation", e.CONFIRM_FLIGHT_CANCEL = "/duffel/flights/confirm-order-cancellation", e.CANCEL_HOTEL_BOOKING = "/duffel/hotels/cancel", e))(R || {}), O = /* @__PURE__ */ ((e) => (e.USER_PREFERENCES = "/user/user-preferences", e))(O || {});
2
2
  export {
3
3
  r as EAuthEndpoints,
4
- O as EBookingEndpoints,
4
+ R as EBookingEndpoints,
5
5
  a as ECurrencyEndpoints,
6
6
  S as EMyTripsEndpoints,
7
+ O as EPreferencesEndpoints,
7
8
  _ as EWalletEndpoints
8
9
  };
@@ -1,5 +1,5 @@
1
- import { createContext as s } from "react";
2
- const t = s({
1
+ import { createContext as e } from "react";
2
+ const t = e({
3
3
  isAuthenticated: !1,
4
4
  isAuthenticating: !1,
5
5
  supportedRegions: [],
@@ -9,7 +9,8 @@ const t = s({
9
9
  },
10
10
  resendVerificationEmail: async () => !1,
11
11
  setTokens: () => {
12
- }
12
+ },
13
+ setPreferredCurrency: async () => !1
13
14
  });
14
15
  export {
15
16
  t as AwayzContext
@@ -1,54 +1,55 @@
1
1
  import "../../arrayExtensions-DlcBOj5a.js";
2
- import { f as U, d as r, A as o, E as v } from "../../AccountService-cvx__9rR.js";
3
- import { useState as E, useCallback as R, useEffect as y } from "react";
4
- import { EAuthFlow as S } from "../../types/EAuthFlow.js";
5
- import { awayzClient as A } from "../../configs/awayzClient.js";
6
- const H = (s, t) => {
7
- var f, m;
8
- let c = "", d = t;
9
- typeof t == "string" ? c = t : t instanceof U ? (c = t.message, d = {
10
- message: t.message,
11
- cause: t.cause,
12
- status: t.status,
13
- data: (f = t == null ? void 0 : t.response) == null ? void 0 : f.data
14
- }) : c = t.message, (m = window.parent) == null || m.postMessage(
2
+ import { f as P, d as n, A as o, E as U } from "../../AccountService-cvx__9rR.js";
3
+ import { useState as m, useCallback as A, useEffect as S } from "react";
4
+ import { awayzClient as O } from "../../configs/awayzClient.js";
5
+ import { PreferencesService as v } from "../../services/preferences/PreferencesService.js";
6
+ import { EAuthFlow as h } from "../../types/EAuthFlow.js";
7
+ const C = (t, r) => {
8
+ var g, y;
9
+ let c = "", E = r;
10
+ typeof r == "string" ? c = r : r instanceof P ? (c = r.message, E = {
11
+ message: r.message,
12
+ cause: r.cause,
13
+ status: r.status,
14
+ data: (g = r == null ? void 0 : r.response) == null ? void 0 : g.data
15
+ }) : c = r.message, (y = window.parent) == null || y.postMessage(
15
16
  {
16
17
  type: "auth_error",
17
- details: { message: c, action: s, info: d }
18
+ details: { message: c, action: t, info: E }
18
19
  },
19
20
  "*"
20
21
  );
21
- }, G = (s) => {
22
- const [t, c] = E(!0), [d, f] = E(!1), [m, T] = E(), [O, k] = E(), [I, K] = E([]), w = R(
23
- async (a) => {
24
- s != null && s.onSuccess && (s == null || s.onSuccess(a)), s != null && s.onSuccessAsync && await (s == null ? void 0 : s.onSuccessAsync(a)), c(!1), f(!0), T(a.token), k(a.user), A.invalidateQueries();
22
+ }, W = (t) => {
23
+ const [r, c] = m(!0), [E, g] = m(!1), [y, R] = m(), [d, T] = m(), [I, K] = m([]), w = A(
24
+ async (s) => {
25
+ t != null && t.onSuccess && (t == null || t.onSuccess(s)), t != null && t.onSuccessAsync && await (t == null ? void 0 : t.onSuccessAsync(s)), c(!1), g(!0), R(s.token), T(s.user), O.invalidateQueries();
25
26
  },
26
- [s]
27
- ), i = R(
28
- async (a, e) => {
29
- if (s.authFlow !== S.POST_MESSAGE)
30
- return H(e ?? "exchange_token", a);
31
- s != null && s.onError && (s == null || s.onError(a)), s != null && s.onErrorAsync && await (s == null ? void 0 : s.onErrorAsync(a)), c(!1);
27
+ [t]
28
+ ), i = A(
29
+ async (s, e) => {
30
+ if (t.authFlow !== h.POST_MESSAGE)
31
+ return C(e ?? "exchange_token", s);
32
+ t != null && t.onError && (t == null || t.onError(s)), t != null && t.onErrorAsync && await (t == null ? void 0 : t.onErrorAsync(s)), c(!1);
32
33
  },
33
- [s]
34
- ), h = async (a) => {
34
+ [t]
35
+ ), k = async (s) => {
35
36
  try {
36
- const { success: e, data: n, message: u } = await o.authenticateWithToken(a);
37
+ const { success: e, data: a, message: u } = await o.authenticateWithToken(s);
37
38
  if (!e) {
38
39
  i(u);
39
40
  return;
40
41
  }
41
- if (!(n != null && n.token)) {
42
+ if (!(a != null && a.token)) {
42
43
  i("no awayz token returned after exchanging id token");
43
44
  return;
44
45
  }
45
- localStorage.setItem(r.TOKEN, n.token), await w(n);
46
- const { data: l, ...g } = await o.getRequestLimit();
47
- if (!g.success) {
48
- console.error({ reqLimitError: g });
46
+ localStorage.setItem(n.TOKEN, a.token), await w(a);
47
+ const { data: f, ...l } = await o.getRequestLimit();
48
+ if (!l.success) {
49
+ console.error({ reqLimitError: l });
49
50
  return;
50
51
  }
51
- l == null || l.forEach(
52
+ f == null || f.forEach(
52
53
  (_) => window.parent.postMessage(
53
54
  {
54
55
  type: "request_limit",
@@ -64,114 +65,130 @@ const H = (s, t) => {
64
65
  }
65
66
  }, N = async () => {
66
67
  try {
67
- const { success: a, data: e } = await A.ensureQueryData({
68
- queryKey: [v.CHECK_USER],
68
+ const { success: s, data: e } = await O.ensureQueryData({
69
+ queryKey: [U.CHECK_USER],
69
70
  queryFn: o.checkUser
70
71
  });
71
- if (!a) {
72
+ if (!s) {
72
73
  i(e);
73
74
  return;
74
75
  }
75
76
  await w({
76
77
  user: e,
77
- token: localStorage.getItem(r.TOKEN)
78
+ token: localStorage.getItem(n.TOKEN)
78
79
  });
79
- } catch (a) {
80
- i(a);
80
+ } catch (s) {
81
+ i(s);
81
82
  } finally {
82
83
  c(!1);
83
84
  }
84
85
  };
85
- y(() => {
86
- if (s.authFlow !== S.STANDARD) return;
87
- const a = localStorage.getItem(r.TOKEN), e = localStorage.getItem(r.REFRESH_TOKEN);
88
- a && e ? N() : c(!1);
86
+ S(() => {
87
+ if (t.authFlow !== h.STANDARD) return;
88
+ const s = localStorage.getItem(n.TOKEN), e = localStorage.getItem(n.REFRESH_TOKEN);
89
+ s && e ? N() : c(!1);
89
90
  }, []);
90
91
  const F = async () => {
91
- const a = await o.getRegions();
92
- K(a);
92
+ const s = await o.getRegions();
93
+ K(s);
93
94
  };
94
- return y(() => {
95
+ return S(() => {
95
96
  F();
96
- }, []), y(() => {
97
- if (s.authFlow !== S.QUERY) return;
98
- const e = new URLSearchParams(window.location.search).get(r.TOKEN);
99
- e && h(e);
100
- }, []), y(() => {
101
- if (s.authFlow !== S.POST_MESSAGE) return;
102
- const a = async (e) => {
103
- var l;
97
+ }, []), S(() => {
98
+ if (t.authFlow !== h.QUERY) return;
99
+ const e = new URLSearchParams(window.location.search).get(n.TOKEN);
100
+ e && k(e);
101
+ }, []), S(() => {
102
+ if (t.authFlow !== h.POST_MESSAGE) return;
103
+ const s = async (e) => {
104
+ var f;
104
105
  if (e.data.type !== "auth") return;
105
- const n = (l = e.data) == null ? void 0 : l.idToken, u = e.data.refreshToken;
106
- if (!n) {
107
- const g = `received message ${JSON.stringify(
106
+ const a = (f = e.data) == null ? void 0 : f.idToken, u = e.data.refreshToken;
107
+ if (!a) {
108
+ const l = `received message ${JSON.stringify(
108
109
  e.data
109
110
  )}
110
111
  no idToken in body`;
111
- i(g);
112
+ i(l);
112
113
  return;
113
114
  }
114
115
  if (!u) {
115
- const g = `received message: ${JSON.stringify(
116
+ const l = `received message: ${JSON.stringify(
116
117
  e.data
117
118
  )}
118
119
  no refreshToken in body`;
119
120
  i(
120
- g,
121
+ l,
121
122
  "refresh_token"
122
123
  /* REFRESH */
123
124
  );
124
125
  return;
125
126
  }
126
- localStorage.setItem(r.REFRESH_TOKEN, u), await h(n);
127
+ localStorage.setItem(n.REFRESH_TOKEN, u), await k(a);
127
128
  };
128
- return window.addEventListener("message", a), window.parent && window.parent.postMessage(
129
+ return window.addEventListener("message", s), window.parent && window.parent.postMessage(
129
130
  {
130
131
  type: "ready"
131
132
  /* READY */
132
133
  },
133
134
  "*"
134
135
  ), () => {
135
- window.removeEventListener("message", a);
136
+ window.removeEventListener("message", s);
136
137
  };
137
138
  }, []), {
138
- isAuthenticating: t,
139
- isAuthenticated: d,
140
- token: m,
141
- user: O,
139
+ isAuthenticating: r,
140
+ isAuthenticated: E,
141
+ token: y,
142
+ user: d,
142
143
  supportedRegions: I,
143
- signIn: async (a) => {
144
- var n;
145
- const e = await o.login(a);
144
+ signIn: async (s) => {
145
+ var a;
146
+ const e = await o.login(s);
146
147
  if (!e.success)
147
148
  i(e.message);
148
149
  else {
149
- const u = (n = e.data) == null ? void 0 : n.refreshToken;
150
- localStorage.setItem(r.REFRESH_TOKEN, u), await w(e.data);
150
+ const u = (a = e.data) == null ? void 0 : a.refreshToken;
151
+ localStorage.setItem(n.REFRESH_TOKEN, u), await w(e.data);
151
152
  }
152
153
  return e;
153
154
  },
154
- signUp: async (a) => {
155
- var n;
156
- const e = await o.signUp(a);
155
+ signUp: async (s) => {
156
+ var a;
157
+ const e = await o.signUp(s);
157
158
  if (!e.success)
158
159
  i(e.message);
159
160
  else {
160
- const u = (n = e.data) == null ? void 0 : n.refreshToken;
161
- localStorage.setItem(r.REFRESH_TOKEN, u), await w(e.data);
161
+ const u = (a = e.data) == null ? void 0 : a.refreshToken;
162
+ localStorage.setItem(n.REFRESH_TOKEN, u), await w(e.data);
162
163
  }
163
164
  return e;
164
165
  },
165
166
  signOut: () => {
166
- localStorage.removeItem(r.TOKEN), localStorage.removeItem(r.REFRESH_TOKEN), f(!1), T(void 0), k(void 0);
167
+ localStorage.removeItem(n.TOKEN), localStorage.removeItem(n.REFRESH_TOKEN), g(!1), R(void 0), T(void 0);
167
168
  },
168
- resendVerificationEmail: async (a) => (await o.resendVerificationEmail(a)).success,
169
- setTokens: (a, e) => {
170
- localStorage.setItem(r.TOKEN, a), localStorage.setItem(r.REFRESH_TOKEN, e), h(a);
169
+ resendVerificationEmail: async (s) => (await o.resendVerificationEmail(s)).success,
170
+ setTokens: (s, e) => {
171
+ localStorage.setItem(n.TOKEN, s), localStorage.setItem(n.REFRESH_TOKEN, e), k(s);
172
+ },
173
+ setPreferredCurrency: async (s) => {
174
+ const e = await v.setCurrency(s);
175
+ if (!e.success || !e.data)
176
+ return console.error("Failed to set preferred currency:", e), !1;
177
+ if (d) {
178
+ const a = {
179
+ ...d,
180
+ preferences: {
181
+ ...d.preferences,
182
+ currency: e.data.currency || d.preferences.currency
183
+ }
184
+ };
185
+ T(a);
186
+ }
187
+ return !0;
171
188
  }
172
189
  };
173
190
  };
174
191
  export {
175
- H as authFailurePostMessage,
176
- G as useAwayzAuth
192
+ C as authFailurePostMessage,
193
+ W as useAwayzAuth
177
194
  };
@@ -5,9 +5,9 @@ import "react/jsx-runtime";
5
5
  import "react";
6
6
  import "../../context/AwayzContext.js";
7
7
  import { D as f } from "../../TripsService-G1T_Co8r.js";
8
+ import "../../configs/awayzClient.js";
8
9
  import { c } from "../../AccountService-cvx__9rR.js";
9
10
  import { EMyTripsEndpoints as d } from "../../configs/endpoints.js";
10
- import "../../configs/awayzClient.js";
11
11
  import "@tanstack/react-query";
12
12
  import { EBookingType as m } from "../../services/trips/TripService.types.js";
13
13
  import "../../services/noRetryInstance.js";
@@ -3,8 +3,8 @@ import "react/jsx-runtime";
3
3
  import "react";
4
4
  import "../../context/AwayzContext.js";
5
5
  import "../../arrayExtensions-DlcBOj5a.js";
6
- import { c as l } from "../../AccountService-cvx__9rR.js";
7
6
  import "../../configs/awayzClient.js";
7
+ import { c as l } from "../../AccountService-cvx__9rR.js";
8
8
  import "@tanstack/react-query";
9
9
  import { useWallet as t } from "./useWallet.js";
10
10
  import "../../services/noRetryInstance.js";
@@ -1,4 +1,4 @@
1
- import { EToolTipPosition, EInvalidAmountDisplayOption } from './CashValueTypes';
1
+ import { EInvalidAmountDisplayOption, EToolTipPosition } from './CashValueTypes';
2
2
  export interface ICashValueProps {
3
3
  /**
4
4
  * The amount of money to be displayed.
@@ -46,3 +46,6 @@ export declare enum EBookingEndpoints {
46
46
  CONFIRM_FLIGHT_CANCEL = "/duffel/flights/confirm-order-cancellation",
47
47
  CANCEL_HOTEL_BOOKING = "/duffel/hotels/cancel"
48
48
  }
49
+ export declare enum EPreferencesEndpoints {
50
+ USER_PREFERENCES = "/user/user-preferences"
51
+ }
@@ -1,6 +1,6 @@
1
+ import { IAwayzConfig } from '../configs/awayzConfig';
1
2
  import { IRegion, IResendVerificationEmailParams, IUser } from '../services/account/AccountServices.types';
2
3
  import { ISignInParams, ISignUpParams, TAuthResponse } from '../types/auth';
3
- import { IAwayzConfig } from '../configs/awayzConfig';
4
4
  export interface IAwayzContext {
5
5
  config?: IAwayzConfig;
6
6
  token?: string;
@@ -13,5 +13,6 @@ export interface IAwayzContext {
13
13
  signOut: () => void;
14
14
  resendVerificationEmail: (params: IResendVerificationEmailParams) => Promise<boolean>;
15
15
  setTokens: (accessToken: string, refreshToken: string) => void;
16
+ setPreferredCurrency: (currency: string) => Promise<boolean>;
16
17
  }
17
18
  export declare const AwayzContext: import('react').Context<IAwayzContext>;
@@ -1,6 +1,6 @@
1
- import { TEmbeddedAuthOptions } from './useAwayzAuth.types';
2
1
  import { IAuthData, IRegion, IResendVerificationEmailParams, IUser } from '../../services/account/AccountServices.types';
3
2
  import { ISignInParams, ISignUpParams } from '../../types/auth';
3
+ import { TEmbeddedAuthOptions } from './useAwayzAuth.types';
4
4
  declare enum ETokenType {
5
5
  EXCHANGE = "exchange_token",
6
6
  REFRESH = "refresh_token"
@@ -33,5 +33,6 @@ export declare const useAwayzAuth: (options: TEmbeddedAuthOptions) => {
33
33
  signOut: () => void;
34
34
  resendVerificationEmail: (params: IResendVerificationEmailParams) => Promise<any>;
35
35
  setTokens: (accessToken: string, refreshToken: string) => void;
36
+ setPreferredCurrency: (currency: string) => Promise<boolean>;
36
37
  };
37
38
  export {};
@@ -10,6 +10,10 @@ export interface IUser {
10
10
  clientUserId: string;
11
11
  userRegion: IRegion;
12
12
  account: IAccount;
13
+ preferences: IUserPreferences;
14
+ }
15
+ export interface IUserPreferences {
16
+ currency: string;
13
17
  }
14
18
  export interface IAccount {
15
19
  userId: string;
@@ -0,0 +1,7 @@
1
+ import { TServiceResponse } from '@type-op/shared';
2
+ import { IUserPreferences } from '../account/AccountServices.types';
3
+ declare class _PreferencesService {
4
+ setCurrency: (currency: string) => Promise<TServiceResponse<Partial<IUserPreferences>>>;
5
+ }
6
+ export declare const PreferencesService: _PreferencesService;
7
+ export {};
@@ -0,0 +1,35 @@
1
+ var a = Object.defineProperty;
2
+ var o = (s, e, r) => e in s ? a(s, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : s[e] = r;
3
+ var n = (s, e, r) => o(s, typeof e != "symbol" ? e + "" : e, r);
4
+ import { EPreferencesEndpoints as u } from "../../configs/endpoints.js";
5
+ import { c as i } from "../../AccountService-cvx__9rR.js";
6
+ class E {
7
+ constructor() {
8
+ n(this, "setCurrency", async (e) => {
9
+ var r, t;
10
+ try {
11
+ const { data: c } = await i.put(
12
+ u.USER_PREFERENCES,
13
+ {
14
+ currency: e
15
+ }
16
+ );
17
+ return {
18
+ success: !0,
19
+ data: {
20
+ currency: c.data.currency
21
+ }
22
+ };
23
+ } catch (c) {
24
+ return console.error(c), {
25
+ success: !1,
26
+ message: ((t = (r = c == null ? void 0 : c.response) == null ? void 0 : r.data) == null ? void 0 : t.message) || "Failed to set currency"
27
+ };
28
+ }
29
+ });
30
+ }
31
+ }
32
+ const p = new E();
33
+ export {
34
+ p as PreferencesService
35
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@odynn/awayz-core",
3
- "version": "0.3.23",
3
+ "version": "0.3.25",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"