@odynn/awayz-core 0.9.27 → 0.9.29

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.
@@ -0,0 +1,34 @@
1
+ const o = "USD", a = 0.03, m = (r, t) => {
2
+ var n = new Intl.NumberFormat("en-US", {
3
+ style: "currency",
4
+ currency: t ?? o
5
+ });
6
+ if (!r) return n.format(0);
7
+ const e = parseFloat(r.toString());
8
+ return n.format(e);
9
+ }, i = (r, t) => {
10
+ var n = new Intl.NumberFormat("en-US", {
11
+ style: "currency",
12
+ currency: t ?? o
13
+ });
14
+ return n.format(Math.round(r)).toString().split(".")[0];
15
+ }, u = (r, t, n = 0) => {
16
+ const e = parseFloat((r == null ? void 0 : r.toString()) || "0");
17
+ return new Intl.NumberFormat("en-US", {
18
+ style: "currency",
19
+ currency: t ?? o,
20
+ maximumFractionDigits: n
21
+ }).format(isNaN(e) ? 0 : e);
22
+ }, s = (r, t = "en") => 0 .toLocaleString(t, {
23
+ style: "currency",
24
+ currency: r,
25
+ minimumFractionDigits: 0,
26
+ maximumFractionDigits: 0
27
+ }).replace(/\d/g, "").trim();
28
+ export {
29
+ a as E,
30
+ m as a,
31
+ u as b,
32
+ s as c,
33
+ i as g
34
+ };
@@ -1,107 +1,111 @@
1
- import { jsx as r, jsxs as l } from "react/jsx-runtime";
2
- import { useQuery as E } from "@tanstack/react-query";
1
+ import { jsx as e, jsxs as p } from "react/jsx-runtime";
2
+ import { useQuery as R } from "@tanstack/react-query";
3
3
  import "../../arrayExtensions-DlcBOj5a.js";
4
- import { g as R, a as N, b as u } from "../../cashUtils-sBirmFfL.js";
5
- import { E as _ } from "../../noRetryInstance-DKhe8ju0.js";
6
- import { useMemo as S } from "react";
7
- import { a as f } from "../../index-C8p5kinH.js";
4
+ import { E as g, g as _, a as C, b as u } from "../../cashUtils-CrBZrS6N.js";
5
+ import { E as S } from "../../noRetryInstance-DKhe8ju0.js";
6
+ import { useMemo as T } from "react";
7
+ import { a as N } from "../../index-C8p5kinH.js";
8
8
  import "react-i18next";
9
9
  import '../../assets/_styles3.css';import '../../assets/_styles.css';import '../../assets/_styles2.css';/* empty css */
10
10
  import "../../_styles.flight-booking-CaUgKcMC.js";
11
11
  /* empty css */
12
- import { EInvalidAmountDisplayOption as t, EToolTipPosition as T } from "./CashValueTypes.js";
13
- import { useAwayzContext as D } from "../../hooks/useAwayzContext.js";
12
+ import { EInvalidAmountDisplayOption as t, EToolTipPosition as D } from "./CashValueTypes.js";
13
+ import { useAwayzContext as I } from "../../hooks/useAwayzContext.js";
14
14
  import "../../configs/awayzClient.js";
15
15
  /* empty css */
16
16
  import "../../context/AwayzContext.js";
17
- import { CurrencyService as I } from "../../services/currency/CurrencyService.js";
17
+ import { CurrencyService as x } from "../../services/currency/CurrencyService.js";
18
18
  import { Tooltip as M } from "../Tooltip/Tooltip.js";
19
- const O = 1e3 * 60 * 60, G = ({
20
- amount: o,
21
- currency: n,
22
- position: A = T.RIGHT,
23
- zeroDisplayOption: v = t.NA,
24
- customDisplay: y,
25
- decimalPlaces: p = 0,
26
- showConversion: g = !0
19
+ const O = 1e3 * 60 * 60, B = ({
20
+ amount: i,
21
+ currency: r,
22
+ position: f = D.RIGHT,
23
+ zeroDisplayOption: A = t.NA,
24
+ customDisplay: E,
25
+ decimalPlaces: m = 2,
26
+ showConversion: v = !1,
27
+ addBuffer: y = !0
27
28
  }) => {
28
- var h, C;
29
- const { user: i } = D(), e = ((h = i == null ? void 0 : i.preferences) == null ? void 0 : h.currency) ?? ((C = i == null ? void 0 : i.userRegion) == null ? void 0 : C.currency), s = e !== n, { data: c, isPending: m } = E({
30
- queryKey: [_.CONVERT_CURRENCY, n, e],
31
- queryFn: () => I.convertCurrency({
32
- baseCurrency: n,
33
- targetCurrency: e
34
- }),
35
- enabled: s && !!n && !!o,
29
+ var h;
30
+ const { user: s } = I(), n = ((h = s == null ? void 0 : s.preferences) == null ? void 0 : h.currency) ?? r, a = n !== r, { data: c, isPending: d } = R({
31
+ queryKey: [S.CONVERT_CURRENCY, r, n],
32
+ queryFn: async () => {
33
+ const o = await x.convertCurrency({
34
+ baseCurrency: r,
35
+ targetCurrency: n
36
+ });
37
+ return y ? o * (1 + g) : o;
38
+ },
39
+ enabled: a && !!r && !!i,
36
40
  staleTime: O
37
- }), a = S(() => {
38
- if (!i)
41
+ }), l = T(() => {
42
+ if (!s)
39
43
  return null;
40
- let d = typeof o == "string" ? parseFloat(o) : o;
41
- if (s) {
42
- if (m || !c) return null;
43
- d = d * c;
44
+ let o = typeof i == "string" ? parseFloat(i) : i;
45
+ if (a) {
46
+ if (d || !c) return null;
47
+ o = o * c;
44
48
  }
45
- return d;
46
- }, [o, i, m, s, c]);
47
- if (m && s)
48
- return /* @__PURE__ */ r("span", { className: "currency-conversion loading", children: o });
49
- if (!e || !a || a < 0)
50
- switch (v) {
49
+ return o;
50
+ }, [i, s, d, a, c]);
51
+ if (d && a)
52
+ return /* @__PURE__ */ e("span", { className: "currency-conversion loading", children: i });
53
+ if (!n || !l || l < 0)
54
+ switch (A) {
51
55
  case t.NA:
52
- return /* @__PURE__ */ r("span", { children: "N/A" });
56
+ return /* @__PURE__ */ e("span", { children: "N/A" });
53
57
  case t.HIDDEN:
54
- return /* @__PURE__ */ r("span", { className: "hidden", children: "N/A" });
58
+ return /* @__PURE__ */ e("span", { className: "hidden", children: "N/A" });
55
59
  case t.DISPLAY_AS_ZERO:
56
- return /* @__PURE__ */ r("span", { children: "0" });
60
+ return /* @__PURE__ */ e("span", { children: "0" });
57
61
  case t.DISPLAY_AS_ZERO_WITH_CURRENCY:
58
- return /* @__PURE__ */ r("span", { children: N(0, e ?? n) });
62
+ return /* @__PURE__ */ e("span", { children: C(0, n ?? r) });
59
63
  case t.DISPLAY_AS_ZERO_WITH_CURRENCY_NO_DECIMAL:
60
- return /* @__PURE__ */ r("span", { children: R(0, e ?? n) });
64
+ return /* @__PURE__ */ e("span", { children: _(0, n ?? r) });
61
65
  case t.CUSTOM:
62
- return /* @__PURE__ */ r("span", { children: a == 0 ? y : "N/A" });
66
+ return /* @__PURE__ */ e("span", { children: l == 0 ? E : "N/A" });
63
67
  default:
64
- return /* @__PURE__ */ r("span", { children: "N/A" });
68
+ return /* @__PURE__ */ e("span", { children: "N/A" });
65
69
  }
66
- return /* @__PURE__ */ l("span", { className: "currency-conversion", children: [
70
+ return /* @__PURE__ */ p("span", { className: "currency-conversion", children: [
67
71
  u(
68
- a,
69
- e,
70
- p
72
+ l,
73
+ n,
74
+ m
71
75
  ),
72
- s && g && /* @__PURE__ */ r(
76
+ a && v && /* @__PURE__ */ e(
73
77
  M,
74
78
  {
75
- trigger: /* @__PURE__ */ r("sup", { children: /* @__PURE__ */ r(f, {}) }),
76
- position: A,
77
- children: /* @__PURE__ */ l("div", { className: "currency-conversion-container", children: [
78
- /* @__PURE__ */ l("p", { children: [
79
+ trigger: /* @__PURE__ */ e("sup", { children: /* @__PURE__ */ e(N, {}) }),
80
+ position: f,
81
+ children: /* @__PURE__ */ p("div", { className: "currency-conversion-container", children: [
82
+ /* @__PURE__ */ p("p", { children: [
79
83
  "Converted from ",
80
- n,
84
+ r,
81
85
  " to ",
82
- e
86
+ n
83
87
  ] }),
84
- /* @__PURE__ */ l("div", { className: "currency-conversion-amounts", children: [
85
- /* @__PURE__ */ r("div", { children: /* @__PURE__ */ r("p", { children: u(o, n, p) }) }),
86
- /* @__PURE__ */ r("div", { children: /* @__PURE__ */ r("p", { children: u(
87
- a,
88
- e,
89
- p
88
+ /* @__PURE__ */ p("div", { className: "currency-conversion-amounts", children: [
89
+ /* @__PURE__ */ e("div", { children: /* @__PURE__ */ e("p", { children: u(i, r, m) }) }),
90
+ /* @__PURE__ */ e("div", { children: /* @__PURE__ */ e("p", { children: u(
91
+ l,
92
+ n,
93
+ m
90
94
  ) }) }),
91
- /* @__PURE__ */ r("span", { className: "conversion-icon", children: /* @__PURE__ */ r(f, {}) })
95
+ /* @__PURE__ */ e("span", { className: "conversion-icon", children: /* @__PURE__ */ e(N, {}) })
92
96
  ] }),
93
- /* @__PURE__ */ r("div", { className: "currency-conversion-rate", children: /* @__PURE__ */ l("p", { children: [
97
+ /* @__PURE__ */ e("div", { className: "currency-conversion-rate", children: /* @__PURE__ */ p("p", { children: [
94
98
  "Current Rate:",
95
99
  " ",
96
100
  c ? (
97
101
  // only leaving 2 decimal places for the conversion rate is
98
102
  // not enough, can lead to confusion
99
103
  // use Number constructor to strip unnecessary trailing zeros
100
- `${Number((1 / c).toFixed(5))} ${n}`
104
+ `${Number((1 / c).toFixed(5))} ${r}`
101
105
  ) : "N/A",
102
106
  " ",
103
107
  "≈ ",
104
- N(1, e)
108
+ C(1, n)
105
109
  ] }) })
106
110
  ] })
107
111
  }
@@ -109,6 +113,6 @@ const O = 1e3 * 60 * 60, G = ({
109
113
  ] });
110
114
  };
111
115
  export {
112
- G as CashValue,
116
+ B as CashValue,
113
117
  O as CurrencyCallStaleTimeMs
114
118
  };
@@ -1,5 +1,5 @@
1
1
  import "../../arrayExtensions-DlcBOj5a.js";
2
- import { c as M } from "../../cashUtils-sBirmFfL.js";
2
+ import { c as M } from "../../cashUtils-CrBZrS6N.js";
3
3
  import { e as P, A as l, E as N } from "../../noRetryInstance-DKhe8ju0.js";
4
4
  import { a as o } from "../../_styles.flight-booking-CaUgKcMC.js";
5
5
  import { useState as f, useCallback as I, useEffect as h } from "react";
@@ -17,22 +17,22 @@ import "../../context/AwayzContext.js";
17
17
  /* empty css */
18
18
  import { EAuthFlow as T } from "../../types/EAuthFlow.js";
19
19
  const x = (s, c) => {
20
- var m, S;
21
- let i = "", y = c;
22
- typeof c == "string" ? i = c : c instanceof P ? (i = c.message, y = {
20
+ var m, y;
21
+ let i = "", d = c;
22
+ typeof c == "string" ? i = c : c instanceof P ? (i = c.message, d = {
23
23
  message: c.message,
24
24
  cause: c.cause,
25
25
  status: c.status,
26
26
  data: (m = c == null ? void 0 : c.response) == null ? void 0 : m.data
27
- }) : i = c.message, (S = window.parent) == null || S.postMessage(
27
+ }) : i = c.message, (y = window.parent) == null || y.postMessage(
28
28
  {
29
29
  type: "auth_error",
30
- details: { message: i, action: s, info: y }
30
+ details: { message: i, action: s, info: d }
31
31
  },
32
32
  "*"
33
33
  );
34
34
  }, le = (s) => {
35
- const [c, i] = f(!0), [y, m] = f(!1), [S, A] = f(), [g, k] = f(), [C, _] = f([]), [p, F] = f([]), E = I(
35
+ const [c, i] = f(!0), [d, m] = f(!1), [y, A] = f(), [S, k] = f(), [C, _] = f([]), [p, F] = f([]), g = I(
36
36
  async (t) => {
37
37
  s != null && s.onSuccess && (s == null || s.onSuccess(t)), s != null && s.onSuccessAsync && await (s == null ? void 0 : s.onSuccessAsync(t)), i(!1), m(!0), A(t.token), k(t.user), O.invalidateQueries();
38
38
  },
@@ -59,13 +59,13 @@ const x = (s, c) => {
59
59
  u("no awayz token returned after exchanging id token");
60
60
  return;
61
61
  }
62
- localStorage.setItem(o.TOKEN, n.token), await E(n);
63
- const { data: d, ...K } = await l.getRequestLimit();
62
+ localStorage.setItem(o.TOKEN, n.token), await g(n);
63
+ const { data: E, ...K } = await l.getRequestLimit();
64
64
  if (!K.success) {
65
65
  console.error({ reqLimitError: K });
66
66
  return;
67
67
  }
68
- d == null || d.forEach(
68
+ E == null || E.forEach(
69
69
  (H) => window.parent.postMessage(
70
70
  {
71
71
  type: "request_limit",
@@ -89,7 +89,7 @@ const x = (s, c) => {
89
89
  u(e);
90
90
  return;
91
91
  }
92
- await E({
92
+ await g({
93
93
  user: e,
94
94
  token: localStorage.getItem(o.TOKEN)
95
95
  });
@@ -126,11 +126,11 @@ const x = (s, c) => {
126
126
  if (e.data.type !== "auth") return;
127
127
  const r = (w = e.data) == null ? void 0 : w.idToken, a = e.data.refreshToken, n = s.isTestMode ? e.data.overrideTokenExchangeEndpoint : void 0;
128
128
  if (!r) {
129
- const d = `received message ${JSON.stringify(
129
+ const E = `received message ${JSON.stringify(
130
130
  e.data
131
131
  )}
132
132
  no idToken in body`;
133
- u(d);
133
+ u(E);
134
134
  return;
135
135
  }
136
136
  localStorage.setItem(o.REFRESH_TOKEN, a), await R(r, a, n);
@@ -146,9 +146,9 @@ const x = (s, c) => {
146
146
  };
147
147
  }, []), {
148
148
  isAuthenticating: c,
149
- isAuthenticated: y,
150
- token: S,
151
- user: g,
149
+ isAuthenticated: d,
150
+ token: y,
151
+ user: S,
152
152
  supportedRegions: C,
153
153
  supportedCurrencies: p,
154
154
  signIn: async (t) => {
@@ -158,7 +158,7 @@ const x = (s, c) => {
158
158
  u(e.message);
159
159
  else {
160
160
  const a = (r = e.data) == null ? void 0 : r.refreshToken;
161
- localStorage.setItem(o.REFRESH_TOKEN, a), await E(e.data);
161
+ localStorage.setItem(o.REFRESH_TOKEN, a), await g(e.data);
162
162
  }
163
163
  return e;
164
164
  },
@@ -169,7 +169,7 @@ const x = (s, c) => {
169
169
  u(e.message);
170
170
  else {
171
171
  const a = (r = e.data) == null ? void 0 : r.refreshToken;
172
- localStorage.setItem(o.REFRESH_TOKEN, a), await E(e.data);
172
+ localStorage.setItem(o.REFRESH_TOKEN, a), await g(e.data);
173
173
  }
174
174
  return e;
175
175
  },
@@ -186,7 +186,7 @@ const x = (s, c) => {
186
186
  u(r.message);
187
187
  else {
188
188
  const n = (a = r.data) == null ? void 0 : a.refreshToken;
189
- localStorage.setItem(o.REFRESH_TOKEN, n), await E(r.data);
189
+ localStorage.setItem(o.REFRESH_TOKEN, n), await g(r.data);
190
190
  }
191
191
  return r;
192
192
  },
@@ -198,12 +198,12 @@ const x = (s, c) => {
198
198
  const e = await q.setCurrency(t);
199
199
  if (!e.success || !e.data)
200
200
  return console.error("Failed to set preferred currency:", e), !1;
201
- if (g) {
201
+ if (S) {
202
202
  const r = {
203
- ...g,
203
+ ...S,
204
204
  preferences: {
205
- ...g.preferences,
206
- currency: e.data.currency || g.preferences.currency
205
+ ...S.preferences,
206
+ currency: e.data.currency
207
207
  }
208
208
  };
209
209
  k(r), O.invalidateQueries({
@@ -7,10 +7,10 @@ import '../../assets/_styles3.css';import '../../assets/_styles5.css';import '..
7
7
  import "../../_styles.flight-booking-CaUgKcMC.js";
8
8
  /* empty css */
9
9
  import "@tanstack/react-query";
10
- import { c } from "../../noRetryInstance-DKhe8ju0.js";
11
10
  /* empty css */
12
11
  /* empty css */
13
12
  import "../../index-Cv-wvFlM.js";
13
+ import { c } from "../../noRetryInstance-DKhe8ju0.js";
14
14
  import "../../context/AwayzContext.js";
15
15
  import { useBookingManagement as t } from "./useBookingManagement.js";
16
16
  import "../../configs/awayzClient.js";
@@ -38,6 +38,7 @@ export interface ICashValueProps {
38
38
  * Defaults to true, but can be set to false to hide it.
39
39
  */
40
40
  showConversion?: boolean;
41
+ addBuffer?: boolean;
41
42
  }
42
43
  export declare const CurrencyCallStaleTimeMs: number;
43
44
  /**
@@ -47,4 +48,4 @@ export declare const CurrencyCallStaleTimeMs: number;
47
48
  * If the original currency differs from the user's currency, it shows a conversion
48
49
  * tooltip with details about the conversion rate and original amount.
49
50
  */
50
- export declare const CashValue: ({ amount, currency, position, zeroDisplayOption, customDisplay, decimalPlaces, showConversion }: ICashValueProps) => import("react/jsx-runtime").JSX.Element;
51
+ export declare const CashValue: ({ amount, currency, position, zeroDisplayOption, customDisplay, decimalPlaces, showConversion, addBuffer }: ICashValueProps) => import("react/jsx-runtime").JSX.Element;
@@ -2,7 +2,7 @@ import { StoryObj } from '@storybook/react';
2
2
  import { EInvalidAmountDisplayOption, EToolTipPosition } from './CashValueTypes';
3
3
  declare const meta: {
4
4
  title: string;
5
- component: ({ amount, currency, position, zeroDisplayOption, customDisplay, decimalPlaces, showConversion }: import('./CashValue').ICashValueProps) => import("react/jsx-runtime").JSX.Element;
5
+ component: ({ amount, currency, position, zeroDisplayOption, customDisplay, decimalPlaces, showConversion, addBuffer }: import('./CashValue').ICashValueProps) => import("react/jsx-runtime").JSX.Element;
6
6
  parameters: {
7
7
  layout: string;
8
8
  };
@@ -14,7 +14,7 @@ export interface IUser {
14
14
  isSocialUser: boolean;
15
15
  }
16
16
  export interface IUserPreferences {
17
- currency: string;
17
+ currency?: string;
18
18
  }
19
19
  export interface IAccount {
20
20
  userId: string;
@@ -1,4 +1,4 @@
1
- import { IAirport, ICoordinates, ISlice } from '@type-op/shared';
1
+ import { IAirport, ICoordinates, ISegment, ISlice } from '@type-op/shared';
2
2
  export interface IGuest {
3
3
  familyName: string;
4
4
  givenName: string;
@@ -121,6 +121,7 @@ export interface IFlight {
121
121
  numberOfStops: number;
122
122
  durationInMinutes: number;
123
123
  reference: string;
124
+ segments: ISegment[];
124
125
  }
125
126
  export interface IActionAirlineChangesRequest {
126
127
  bookingId: string;
@@ -138,7 +138,8 @@ class h {
138
138
  reference: a.data.booking_reference,
139
139
  durationInMinutes: f(e.duration),
140
140
  origin: u(e.origin),
141
- destination: u(e.destination)
141
+ destination: u(e.destination),
142
+ segments: u(e.segments)
142
143
  })),
143
144
  availableActions: a.data.available_actions,
144
145
  airlineInitiatedChanges: u(a.data.airline_initiated_changes) || []
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@odynn/awayz-core",
3
- "version": "0.9.27",
3
+ "version": "0.9.29",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"
@@ -1,33 +0,0 @@
1
- const o = "USD", a = (r, t) => {
2
- var e = new Intl.NumberFormat("en-US", {
3
- style: "currency",
4
- currency: t ?? o
5
- });
6
- if (!r) return e.format(0);
7
- const n = parseFloat(r.toString());
8
- return e.format(n);
9
- }, m = (r, t) => {
10
- var e = new Intl.NumberFormat("en-US", {
11
- style: "currency",
12
- currency: t ?? o
13
- });
14
- return e.format(Math.round(r)).toString().split(".")[0];
15
- }, i = (r, t, e = 0) => {
16
- const n = parseFloat((r == null ? void 0 : r.toString()) || "0");
17
- return new Intl.NumberFormat("en-US", {
18
- style: "currency",
19
- currency: t ?? o,
20
- maximumFractionDigits: e
21
- }).format(isNaN(n) ? 0 : n);
22
- }, u = (r, t = "en") => 0 .toLocaleString(t, {
23
- style: "currency",
24
- currency: r,
25
- minimumFractionDigits: 0,
26
- maximumFractionDigits: 0
27
- }).replace(/\d/g, "").trim();
28
- export {
29
- a,
30
- i as b,
31
- u as c,
32
- m as g
33
- };