@odynn/awayz-flights 0.5.12 → 0.6.0

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.
@@ -1,11 +1,11 @@
1
1
  import { jsx as r, jsxs as s, Fragment as Q } from "react/jsx-runtime";
2
- import { RewardsService as Y, CashValue as k, EToolTipPosition as A, EInvalidAmountDisplayOption as J } from "@odynn/awayz-core";
2
+ import { RewardsService as Y, CashValue as A, EToolTipPosition as I, EInvalidAmountDisplayOption as J } from "@odynn/awayz-core";
3
3
  import { useQuery as W } from "@tanstack/react-query";
4
4
  import { g as X } from "./index-7zRjF0bU.js";
5
- import { G as Z, g as I, a as f, E as d, F as w, b as V } from "./FlightItinerary-Dy-2zMYt.js";
5
+ import { G as Z, g as k, a as f, E as d, F as w, b as V } from "./FlightItinerary-Dy-2zMYt.js";
6
6
  import { E as B } from "./enums-DxmoBOKL.js";
7
7
  import "./arrayExtensions-DFLvtO8l.js";
8
- import ii, { useState as M, useMemo as C } from "react";
8
+ import ii, { useState as C, useMemo as M } from "react";
9
9
  import { h as N } from "./moment-BGjjqtLQ.js";
10
10
  import { useTranslation as ri } from "react-i18next";
11
11
  import { EPaymentType as u } from "./enums/EPaymentType.js";
@@ -17,7 +17,7 @@ function ci(i) {
17
17
  let t = i == null ? void 0 : i.toString().split(".")[0];
18
18
  return t == null ? void 0 : t.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
19
19
  }
20
- function L(i) {
20
+ function S(i) {
21
21
  return Z({ attr: { viewBox: "0 0 512 512" }, child: [{ tag: "path", attr: { d: "M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512zM216 336l24 0 0-64-24 0c-13.3 0-24-10.7-24-24s10.7-24 24-24l48 0c13.3 0 24 10.7 24 24l0 88 8 0c13.3 0 24 10.7 24 24s-10.7 24-24 24l-80 0c-13.3 0-24-10.7-24-24s10.7-24 24-24zm40-208a32 32 0 1 1 0 64 32 32 0 1 1 0-64z" }, child: [] }] })(i);
22
22
  }
23
23
  const Ti = ({
@@ -25,12 +25,12 @@ const Ti = ({
25
25
  onClick: t,
26
26
  showBestValue: a = !1,
27
27
  onShowBestValueCalculation: o,
28
- customStyling: S = !1
28
+ customStyling: L = !1
29
29
  }) => {
30
- const { t: l } = ri(), [T, _] = M(!1), m = i.origin, p = i.destination, D = i.flightDetails, E = i.paymentOptions || [], $ = E.filter((e) => e.points === -1).length === 1, R = E.filter((e) => e.points > -1).length === 1, [z, U] = M(si), x = async () => {
30
+ const { t: l } = ri(), [T, _] = C(!1), m = i.origin, p = i.destination, E = i.flightDetails, D = i.paymentOptions || [], $ = D.filter((e) => e.points === -1).length === 1, R = D.filter((e) => e.points > -1).length === 1, [z, U] = C(si), x = async () => {
31
31
  const e = await oi(i.airlineProgram);
32
32
  U(e);
33
- }, { flightNumbers: v, airlines: G } = C(() => {
33
+ }, { flightNumbers: v, airlines: G } = M(() => {
34
34
  const e = [], n = [];
35
35
  return i.flightDetails.slices.forEach((g) => {
36
36
  g.segments.forEach((P) => {
@@ -50,11 +50,10 @@ const Ti = ({
50
50
  i.arrivalTime
51
51
  ), y = i == null ? void 0 : i.airlineProgram, { data: O } = W({
52
52
  queryKey: [B.VALUE_CENTS, y],
53
- queryFn: () => Y.getPointsPerCent(y ?? ""),
53
+ queryFn: () => Y.getCentPerPoint(y ?? ""),
54
54
  staleTime: 1 / 0,
55
- placeholderData: 0,
56
55
  enabled: !!y && a
57
- }), c = C(() => {
56
+ }), c = M(() => {
58
57
  var e, n;
59
58
  return (n = (e = i.paymentOptions) == null ? void 0 : e.find(
60
59
  (g) => g.program === i.airlineProgram
@@ -66,7 +65,7 @@ const Ti = ({
66
65
  bestValueStatus: "none"
67
66
  /* NONE */
68
67
  };
69
- const e = O * i.points / 100, n = (c == null ? void 0 : c.amount) || 0;
68
+ const e = O.valueCents * i.points / 100, n = (c == null ? void 0 : c.amount) || 0;
70
69
  return {
71
70
  bestValueStatus: e + n < i.cash ? "points" : "cash"
72
71
  /* CASH */
@@ -75,7 +74,7 @@ const Ti = ({
75
74
  return /* @__PURE__ */ r(
76
75
  "div",
77
76
  {
78
- className: `${S ? "" : "awayz-"}flight-result`,
77
+ className: `${L ? "" : "awayz-"}flight-result`,
79
78
  onClick: K,
80
79
  children: /* @__PURE__ */ s("div", { className: "content", children: [
81
80
  /* @__PURE__ */ r("div", { className: "flight-info", children: /* @__PURE__ */ s("div", { className: "flight-locations", children: [
@@ -87,7 +86,7 @@ const Ti = ({
87
86
  /* @__PURE__ */ s("p", { className: "show-desktop", children: [
88
87
  m.city,
89
88
  ",",
90
- I(m.country)
89
+ k(m.country)
91
90
  ] }),
92
91
  /* @__PURE__ */ r("p", { className: "show-desktop", children: N(i.departureTime).format(
93
92
  l(f.DATE_TIME_MEDIUM, d.FlightShortDate)
@@ -100,7 +99,7 @@ const Ti = ({
100
99
  /* @__PURE__ */ s("div", { className: "flight-duration", children: [
101
100
  /* @__PURE__ */ r("span", { className: "line" }),
102
101
  /* @__PURE__ */ s("p", { children: [
103
- X(D.slices[0].duration),
102
+ X(E.slices[0].duration),
104
103
  " ",
105
104
  " - ",
106
105
  i.numberOfStops > 0 ? `${i.numberOfStops} ${ai(
@@ -114,7 +113,7 @@ const Ti = ({
114
113
  /* @__PURE__ */ s("p", { className: "show-desktop", children: [
115
114
  p.city,
116
115
  ", ",
117
- I(p.country)
116
+ k(p.country)
118
117
  ] }),
119
118
  /* @__PURE__ */ s("p", { className: "show-desktop", children: [
120
119
  N(i.arrivalTime).format(
@@ -160,21 +159,14 @@ const Ti = ({
160
159
  e.stopPropagation(), t(i, u.CASH);
161
160
  },
162
161
  children: [
163
- /* @__PURE__ */ r(
164
- "img",
165
- {
166
- src: i.marketingLogo ?? i.airlineLogo,
167
- alt: "marketing carrier logo"
168
- }
169
- ),
170
162
  /* @__PURE__ */ s("div", { children: [
171
163
  /* @__PURE__ */ r("label", { children: $ ? "Book For" : "From" }),
172
164
  /* @__PURE__ */ r(
173
- k,
165
+ A,
174
166
  {
175
167
  amount: i.cash,
176
168
  currency: i.currency,
177
- position: A.LEFT
169
+ position: I.LEFT
178
170
  }
179
171
  )
180
172
  ] }),
@@ -186,7 +178,7 @@ const Ti = ({
186
178
  e.stopPropagation(), o == null || o(i);
187
179
  },
188
180
  children: [
189
- o && /* @__PURE__ */ r(L, {}),
181
+ o && /* @__PURE__ */ r(S, {}),
190
182
  /* @__PURE__ */ r("p", { children: "Best Value" }),
191
183
  o && /* @__PURE__ */ r("span", { children: "Click to learn more" })
192
184
  ]
@@ -211,7 +203,7 @@ const Ti = ({
211
203
  e.stopPropagation(), o == null || o(i);
212
204
  },
213
205
  children: [
214
- o && /* @__PURE__ */ r(L, {}),
206
+ o && /* @__PURE__ */ r(S, {}),
215
207
  /* @__PURE__ */ r("p", { children: "Best Value" }),
216
208
  o && /* @__PURE__ */ r("span", { children: "Click to learn more" })
217
209
  ]
@@ -225,13 +217,13 @@ const Ti = ({
225
217
  !!c && /* @__PURE__ */ s(Q, { children: [
226
218
  " + ",
227
219
  /* @__PURE__ */ r(
228
- k,
220
+ A,
229
221
  {
230
222
  amount: c.amount,
231
223
  currency: c.currency,
232
224
  customDisplay: "No fee",
233
225
  zeroDisplayOption: J.CUSTOM,
234
- position: A.LEFT
226
+ position: I.LEFT
235
227
  }
236
228
  )
237
229
  ] })
@@ -245,7 +237,7 @@ const Ti = ({
245
237
  /* @__PURE__ */ r("div", { className: `flight-details ${T ? "is-open" : ""}`, children: /* @__PURE__ */ r("div", { className: "inner", children: /* @__PURE__ */ r(
246
238
  V,
247
239
  {
248
- itinerary: D.slices[0].segments,
240
+ itinerary: E.slices[0].segments,
249
241
  origin: m,
250
242
  destination: p,
251
243
  isMultiDayFlight: j
@@ -1,7 +1,7 @@
1
1
  import "react/jsx-runtime";
2
2
  import "@odynn/awayz-core";
3
3
  import "@tanstack/react-query";
4
- import { F as x } from "../../FlightResult-BOOft6zl.js";
4
+ import { F as x } from "../../FlightResult-C-qxQLhu.js";
5
5
  import "../../index-7zRjF0bU.js";
6
6
  import "../../FlightItinerary-Dy-2zMYt.js";
7
7
  import "../../enums-DxmoBOKL.js";
@@ -1,4 +1,4 @@
1
- import { F as l } from "../FlightResult-BOOft6zl.js";
1
+ import { F as l } from "../FlightResult-C-qxQLhu.js";
2
2
  export {
3
3
  l as FlightResult
4
4
  };
@@ -150,7 +150,6 @@ export interface IFlightResult {
150
150
  awayzGroupId: string;
151
151
  duration: string;
152
152
  airlineProgram: string;
153
- marketingLogo?: string;
154
153
  durationMinutes: number;
155
154
  flightDetails: IFlightOffer;
156
155
  paymentOptions: IFlightPaymentOption[];
@@ -8,6 +8,11 @@ import { ECabinClass } from '../types/ECabinClass';
8
8
  * @returns {IFlightResult[]} - correctly formatted flight details array
9
9
  */
10
10
  export declare const mapDataToFlightDetails: (data: IFlightOffer[]) => IFlightResult[];
11
+ /**
12
+ * Flight number is unique for an operating carrier as well as a marketing carrier
13
+ * @param segment
14
+ * @returns
15
+ */
11
16
  export declare const getFlightNumber: (segment: ISegment) => string;
12
17
  /**
13
18
  * Builds a flight search query URL with the provided parameters.
package/dist/main.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { useFlightSearch as o } from "./hooks/useFlightSearch/useFlightSearch.js";
2
2
  import { useAirportSearch as g } from "./hooks/useAirportSearch/useAirportSearch.js";
3
3
  import { EBaggage as s } from "./hooks/useFlightSearch/useFlightSearch.types.js";
4
- import { F as f, c as l } from "./FlightResult-BOOft6zl.js";
4
+ import { F as f, c as l } from "./FlightResult-C-qxQLhu.js";
5
5
  import { EPaymentType as x } from "./enums/EPaymentType.js";
6
6
  import { DEFAULT_AIRLINE_PROGRAM as C, getAirlineProgram as E, getFlightNumber as F, getLogoPath as c } from "./utils/flightUtils.js";
7
7
  import { isSameDayFlight as y } from "./utils/flightDateUtils.js";
@@ -7,36 +7,33 @@ import { mapBaggageType as V } from "../hooks/useFlightSearch/useFlightSearch.ty
7
7
  import { WalletService as Y } from "../services/wallet/WalletService.js";
8
8
  import { ERewardProgramCategories as x } from "../services/wallet/WalletService.types.js";
9
9
  const ne = (t) => t == null ? void 0 : t.map((e) => {
10
- var n, r, g, m, s, a, i, o, l, c, d, y, C, b, F, D, L, k, A, T, P, O, h, v, R, E, I, _, M, z, N, S, Z, $;
10
+ var a, g, l, n, s, i, r, o, c, m, u, d, y, b, F, D, L, h, A, T, O, P, k, v, R, E, I, _, z, M, N, S, Z, $;
11
11
  return {
12
12
  id: e.id,
13
13
  points: (e == null ? void 0 : e.points) >= 0 ? e.points : -1,
14
14
  partial: e == null ? void 0 : e.partial,
15
15
  origin: {
16
- city: ((n = e.slices[0].segments[0].origin) == null ? void 0 : n.cityName) || ((g = (r = e.slices[0].segments[0].origin) == null ? void 0 : r.city) == null ? void 0 : g.name),
17
- country: ((m = e.slices[0].segments[0].origin) == null ? void 0 : m.iataCountryCode) || ((a = (s = e.slices[0].segments[0].origin) == null ? void 0 : s.city) == null ? void 0 : a.iataCountryCode),
18
- airportCode: ((i = e.slices[0].segments[0].origin) == null ? void 0 : i.iataCityCode) || ((l = (o = e.slices[0].segments[0].origin) == null ? void 0 : o.city) == null ? void 0 : l.iataCode),
16
+ city: ((a = e.slices[0].segments[0].origin) == null ? void 0 : a.cityName) || ((l = (g = e.slices[0].segments[0].origin) == null ? void 0 : g.city) == null ? void 0 : l.name),
17
+ country: ((n = e.slices[0].segments[0].origin) == null ? void 0 : n.iataCountryCode) || ((i = (s = e.slices[0].segments[0].origin) == null ? void 0 : s.city) == null ? void 0 : i.iataCountryCode),
18
+ airportCode: ((r = e.slices[0].segments[0].origin) == null ? void 0 : r.iataCityCode) || ((c = (o = e.slices[0].segments[0].origin) == null ? void 0 : o.city) == null ? void 0 : c.iataCode),
19
19
  coordinates: {
20
- latitude: (d = (c = e.slices[0].segments[0].origin) == null ? void 0 : c.city) == null ? void 0 : d.latitude,
21
- longitude: (C = (y = e.slices[0].segments[0].origin) == null ? void 0 : y.city) == null ? void 0 : C.longitude
20
+ latitude: (u = (m = e.slices[0].segments[0].origin) == null ? void 0 : m.city) == null ? void 0 : u.latitude,
21
+ longitude: (y = (d = e.slices[0].segments[0].origin) == null ? void 0 : d.city) == null ? void 0 : y.longitude
22
22
  }
23
23
  },
24
24
  destination: {
25
- city: ((F = (b = e.slices[0].segments.getLast()) == null ? void 0 : b.destination) == null ? void 0 : F.cityName) || ((k = (L = (D = e.slices[0].segments.getLast()) == null ? void 0 : D.destination) == null ? void 0 : L.city) == null ? void 0 : k.name),
26
- country: ((T = (A = e.slices[0].segments.getLast()) == null ? void 0 : A.destination) == null ? void 0 : T.iataCountryCode) || ((h = (O = (P = e.slices[0].segments.getLast()) == null ? void 0 : P.destination) == null ? void 0 : O.city) == null ? void 0 : h.iataCountryCode),
25
+ city: ((F = (b = e.slices[0].segments.getLast()) == null ? void 0 : b.destination) == null ? void 0 : F.cityName) || ((h = (L = (D = e.slices[0].segments.getLast()) == null ? void 0 : D.destination) == null ? void 0 : L.city) == null ? void 0 : h.name),
26
+ country: ((T = (A = e.slices[0].segments.getLast()) == null ? void 0 : A.destination) == null ? void 0 : T.iataCountryCode) || ((k = (P = (O = e.slices[0].segments.getLast()) == null ? void 0 : O.destination) == null ? void 0 : P.city) == null ? void 0 : k.iataCountryCode),
27
27
  airportCode: ((R = (v = e.slices[0].segments.getLast()) == null ? void 0 : v.destination) == null ? void 0 : R.iataCityCode) || ((_ = (I = (E = e.slices[0].segments.getLast()) == null ? void 0 : E.destination) == null ? void 0 : I.city) == null ? void 0 : _.iataCode),
28
28
  coordinates: {
29
- latitude: (N = (z = (M = e.slices[0].segments.getLast()) == null ? void 0 : M.destination) == null ? void 0 : z.city) == null ? void 0 : N.latitude,
29
+ latitude: (N = (M = (z = e.slices[0].segments.getLast()) == null ? void 0 : z.destination) == null ? void 0 : M.city) == null ? void 0 : N.latitude,
30
30
  longitude: ($ = (Z = (S = e.slices[0].segments.getLast()) == null ? void 0 : S.destination) == null ? void 0 : Z.city) == null ? void 0 : $.longitude
31
31
  }
32
32
  },
33
33
  airline: e.owner.name,
34
- airlineLogo: u(
34
+ airlineLogo: w(
35
35
  e.slices[0].segments[0].operatingCarrier.iataCode
36
36
  ),
37
- marketingLogo: u(
38
- e.slices[0].segments[0].marketingCarrier.iataCode
39
- ),
40
37
  cash: e.totalAmount ? parseFloat(e.totalAmount) : 0,
41
38
  currency: e.baseCurrency,
42
39
  flightNumber: K(e.slices[0].segments[0]),
@@ -61,41 +58,41 @@ const ne = (t) => t == null ? void 0 : t.map((e) => {
61
58
  cabinClass: e.slices[0].segments[0].passengers[0].cabinClass || e.slices[0].segments[0].passengers[0].cabin.name || e.slices[0].segments[0].passengers[0].cabinClassMarketingName || e.slices[0].segments[0].passengers[0].cabin.marketingName
62
59
  };
63
60
  }), K = (t) => {
64
- const e = t.operatingCarrierFlightNumber ? t.operatingCarrier : t.marketingCarrier, n = t.operatingCarrierFlightNumber ?? t.marketingCarrierFlightNumber;
65
- return e.iataCode + " " + W(n);
61
+ const e = t.operatingCarrierFlightNumber ? t.operatingCarrier : t.marketingCarrier, a = t.operatingCarrierFlightNumber ?? t.marketingCarrierFlightNumber;
62
+ return e.iataCode + " " + W(a);
66
63
  }, re = ({
67
64
  originCode: t,
68
65
  destinationCode: e,
69
- departureDate: n,
70
- cabinClass: r,
71
- passengerCount: g,
72
- paymentType: m
66
+ departureDate: a,
67
+ cabinClass: g,
68
+ passengerCount: l,
69
+ paymentType: n
73
70
  }) => {
74
71
  let s = "/flights/search/one-way/points-cash?";
75
- return s += `origin=${t}`, s += `&destination=${e}`, s += `&departure_date=${n}`, s += `&cabin_class=${r}`, s += `&adults=${g}`, s += `&cash_or_points=[${m}]`, s;
76
- }, H = (t) => t.flightDetails.slices[0].segments.map((n) => K(n)).join("_"), oe = (t) => {
72
+ return s += `origin=${t}`, s += `&destination=${e}`, s += `&departure_date=${a}`, s += `&cabin_class=${g}`, s += `&adults=${l}`, s += `&cash_or_points=[${n}]`, s;
73
+ }, H = (t) => t.flightDetails.slices[0].segments.map((a) => K(a)).join("_"), oe = (t) => {
77
74
  const e = {};
78
75
  t.forEach((s) => {
79
- const a = H(s);
80
- if (e[a]) {
81
- const i = U(s);
82
- e[a].flight.paymentOptions.push(i);
83
- const o = w(
84
- e[a].flight.paymentOptions
76
+ const i = H(s);
77
+ if (e[i]) {
78
+ const r = U(s);
79
+ e[i].flight.paymentOptions.push(r);
80
+ const { lowestCash: o, currency: c, lowestPoints: m } = C(
81
+ e[i].flight.paymentOptions
85
82
  );
86
- e[a].flight.cash = o.lowestCash, e[a].flight.points = o.lowestPoints;
83
+ e[i].flight.points = m, e[i].flight.cash = o, c && (e[i].flight.currency = c);
87
84
  } else {
88
- const { origin: i, destination: o } = s, l = [U(s)], c = w(l);
89
- e[a] = {
85
+ const { origin: r, destination: o } = s, c = [U(s)], m = C(c);
86
+ e[i] = {
90
87
  programs: [],
91
88
  flight: {
92
89
  id: s.awayzGroupId,
93
90
  partial: s.partial,
94
91
  origin: {
95
- city: i.city,
96
- country: i.country,
97
- airportCode: i.airportCode,
98
- coordinates: i.coordinates
92
+ city: r.city,
93
+ country: r.country,
94
+ airportCode: r.airportCode,
95
+ coordinates: r.coordinates
99
96
  },
100
97
  destination: {
101
98
  city: o.city,
@@ -104,18 +101,15 @@ const ne = (t) => t == null ? void 0 : t.map((e) => {
104
101
  coordinates: o.coordinates
105
102
  },
106
103
  airline: s.airline,
107
- airlineLogo: u(
104
+ airlineLogo: w(
108
105
  s.flightDetails.slices[0].segments[0].operatingCarrier.iataCode
109
106
  ),
110
- marketingLogo: u(
111
- s.flightDetails.slices[0].segments[0].marketingCarrier.iataCode
112
- ),
113
107
  flightNumber: s.flightNumber,
114
- paymentOptions: l,
108
+ paymentOptions: c,
115
109
  numberOfStops: s.numberOfStops,
116
110
  departureTime: s.departureTime,
117
111
  arrivalTime: s.arrivalTime,
118
- awayzGroupId: a,
112
+ awayzGroupId: i,
119
113
  duration: s.duration,
120
114
  airlineProgram: s.airlineProgram,
121
115
  durationMinutes: B({
@@ -129,8 +123,8 @@ const ne = (t) => t == null ? void 0 : t.map((e) => {
129
123
  destinationTimeZone: s.flightDetails.slices[0].segments.getLast().destination.timeZone,
130
124
  duration: s.flightDetails.slices[0].duration
131
125
  }),
132
- cash: c.lowestCash,
133
- points: c.lowestPoints,
126
+ cash: m.lowestCash,
127
+ points: m.lowestPoints,
134
128
  flightDetails: s.flightDetails,
135
129
  currency: s.flightDetails.baseCurrency,
136
130
  cashFee: s.cashFee,
@@ -138,65 +132,65 @@ const ne = (t) => t == null ? void 0 : t.map((e) => {
138
132
  }
139
133
  };
140
134
  }
141
- s.airlineProgram && !e[a].programs.includes(s.airlineProgram) && e[a].programs.push(s.airlineProgram);
135
+ s.airlineProgram && !e[i].programs.includes(s.airlineProgram) && e[i].programs.push(s.airlineProgram);
142
136
  });
143
- const n = [];
137
+ const a = [];
144
138
  Object.values(e).forEach((s) => {
145
- const a = [
139
+ const i = [
146
140
  ...new Set(
147
- s.flight.paymentOptions.map((i) => i.carrier.name)
141
+ s.flight.paymentOptions.map((r) => r.carrier.name)
148
142
  )
149
143
  ];
150
- s.programs.length > 0 ? s.programs.forEach((i) => {
151
- a.forEach((o) => {
152
- var c;
153
- const l = w(
144
+ s.programs.length > 0 ? s.programs.forEach((r) => {
145
+ i.forEach((o) => {
146
+ var m;
147
+ const c = C(
154
148
  s.flight.paymentOptions.filter(
155
- (d) => d.program === i || d.cash > 0 && d.carrier.name === o
149
+ (u) => u.program === r || u.cash > 0 && u.carrier.name === o
156
150
  )
157
151
  );
158
- n.push({
152
+ a.push({
159
153
  ...s.flight,
160
154
  airline: o,
161
- airlineLogo: u(
162
- (c = s.flight.paymentOptions.find(
163
- (d) => d.carrier.name === o
164
- )) == null ? void 0 : c.carrier.iataCode
155
+ airlineLogo: w(
156
+ (m = s.flight.paymentOptions.find(
157
+ (u) => u.carrier.name === o
158
+ )) == null ? void 0 : m.carrier.iataCode
165
159
  ),
166
- airlineProgram: i,
167
- cash: l.lowestCash,
168
- points: l.lowestPoints
160
+ airlineProgram: r,
161
+ cash: c.lowestCash,
162
+ points: c.lowestPoints
169
163
  });
170
164
  });
171
- }) : a.forEach((i) => {
172
- var l;
173
- const { lowestCash: o } = w(
165
+ }) : i.forEach((r) => {
166
+ var c;
167
+ const { lowestCash: o } = C(
174
168
  s.flight.paymentOptions.filter(
175
- (c) => c.carrier.name === i
169
+ (m) => m.carrier.name === r
176
170
  )
177
171
  );
178
- n.push({
172
+ a.push({
179
173
  ...s.flight,
180
- airline: i,
181
- airlineLogo: u(
182
- (l = s.flight.paymentOptions.find(
183
- (c) => c.carrier.name === i
184
- )) == null ? void 0 : l.carrier.iataCode
174
+ airline: r,
175
+ airlineLogo: w(
176
+ (c = s.flight.paymentOptions.find(
177
+ (m) => m.carrier.name === r
178
+ )) == null ? void 0 : c.carrier.iataCode
185
179
  ),
186
180
  cash: o
187
181
  });
188
182
  });
189
183
  });
190
- const { cashlessResults: r, otherResults: g } = n.reduce(
191
- (s, a) => (a.cash <= 0 && a.points > 0 ? s.cashlessResults.push(a) : a.cash > 0 && s.otherResults.push(a), s),
184
+ const { cashlessResults: g, otherResults: l } = a.reduce(
185
+ (s, i) => (i.cash <= 0 && i.points > 0 ? s.cashlessResults.push(i) : i.cash > 0 && s.otherResults.push(i), s),
192
186
  { cashlessResults: [], otherResults: [] }
193
- ), m = g;
194
- return r.forEach((s) => {
195
- m.find(
196
- (i) => i.awayzGroupId === s.awayzGroupId
197
- ) || m.push(s);
198
- }), m;
199
- }, W = (t) => t ? t.replace(/^0+/, "") : "", ce = (t) => `https://assets.duffel.com/img/airlines/for-light-background/full-color-logo/${t}.svg`, u = (t) => `${Q}${t}.svg`, G = "/img/logo/odynn-eye.svg", q = {
187
+ ), n = l;
188
+ return g.forEach((s) => {
189
+ n.find(
190
+ (r) => r.awayzGroupId === s.awayzGroupId
191
+ ) || n.push(s);
192
+ }), n;
193
+ }, W = (t) => t ? t.replace(/^0+/, "") : "", ce = (t) => `https://assets.duffel.com/img/airlines/for-light-background/full-color-logo/${t}.svg`, w = (t) => `${Q}${t}.svg`, G = "/img/logo/odynn-eye.svg", q = {
200
194
  categoryLogo: G,
201
195
  programLogo: G,
202
196
  awayzActive: [],
@@ -215,24 +209,24 @@ const ne = (t) => t == null ? void 0 : t.map((e) => {
215
209
  staleTime: 864e5
216
210
  // 24 hours
217
211
  });
218
- let n = e.find(
219
- (r) => {
220
- var g, m, s, a;
221
- return ((m = (g = r.mainProgram) == null ? void 0 : g.toLowerCase()) == null ? void 0 : m.includes(t == null ? void 0 : t.toLowerCase())) || ((a = (s = r.displayProgram) == null ? void 0 : s.toLowerCase()) == null ? void 0 : a.includes(t == null ? void 0 : t.toLowerCase()));
212
+ let a = e.find(
213
+ (g) => {
214
+ var l, n, s, i;
215
+ return ((n = (l = g.mainProgram) == null ? void 0 : l.toLowerCase()) == null ? void 0 : n.includes(t == null ? void 0 : t.toLowerCase())) || ((i = (s = g.displayProgram) == null ? void 0 : s.toLowerCase()) == null ? void 0 : i.includes(t == null ? void 0 : t.toLowerCase()));
222
216
  }
223
217
  ) ?? q;
224
- return n || (n = {
218
+ return a || (a = {
225
219
  ...q,
226
220
  mainProgram: t,
227
221
  displayProgram: t,
228
222
  id: t
229
- }), n;
223
+ }), a;
230
224
  }, U = (t) => {
231
- var g, m, s, a, i, o, l, c, d, y;
232
- const e = ((s = (m = (g = t.flightDetails.slices.getFirst()) == null ? void 0 : g.segments.getFirst()) == null ? void 0 : m.passengers.getFirst()) == null ? void 0 : s.baggages) ?? [], n = ((o = (i = (a = t.flightDetails.slices.getFirst()) == null ? void 0 : a.segments.getFirst()) == null ? void 0 : i.passengers.getFirst()) == null ? void 0 : o.cabinClassMarketingName) ?? ((d = (c = (l = t.flightDetails.slices.getFirst()) == null ? void 0 : l.segments.getFirst()) == null ? void 0 : c.passengers.getFirst()) == null ? void 0 : d.cabinClass), r = e.map(
233
- (C) => ({
234
- type: V(C.type),
235
- quantity: C.quantity
225
+ var l, n, s, i, r, o, c, m, u, d;
226
+ const e = ((s = (n = (l = t.flightDetails.slices.getFirst()) == null ? void 0 : l.segments.getFirst()) == null ? void 0 : n.passengers.getFirst()) == null ? void 0 : s.baggages) ?? [], a = ((o = (r = (i = t.flightDetails.slices.getFirst()) == null ? void 0 : i.segments.getFirst()) == null ? void 0 : r.passengers.getFirst()) == null ? void 0 : o.cabinClassMarketingName) ?? ((u = (m = (c = t.flightDetails.slices.getFirst()) == null ? void 0 : c.segments.getFirst()) == null ? void 0 : m.passengers.getFirst()) == null ? void 0 : u.cabinClass), g = e.map(
227
+ (y) => ({
228
+ type: V(y.type),
229
+ quantity: y.quantity
236
230
  })
237
231
  );
238
232
  return {
@@ -241,25 +235,28 @@ const ne = (t) => t == null ? void 0 : t.map((e) => {
241
235
  points: t.points,
242
236
  program: t.airlineProgram,
243
237
  baseCurrency: t.flightDetails.baseCurrency,
244
- fareBrandName: (y = t.flightDetails.slices.getFirst()) == null ? void 0 : y.fareBrandName,
245
- cabinClass: n,
238
+ fareBrandName: (d = t.flightDetails.slices.getFirst()) == null ? void 0 : d.fareBrandName,
239
+ cabinClass: a,
246
240
  cashFee: t.cashFee,
247
241
  conditions: t.flightDetails.conditions,
248
- baggages: r,
242
+ baggages: g,
249
243
  carrier: {
250
244
  iataCode: t.flightDetails.slices.getFirst().segments.getFirst().marketingCarrier.iataCode,
251
245
  name: t.flightDetails.slices.getFirst().segments.getFirst().marketingCarrier.name
252
246
  }
253
247
  };
254
- }, w = (t) => {
255
- const e = Math.min(
256
- ...t.filter((r) => r.cash > 0).map((r) => r.cash)
257
- ), n = Math.min(
258
- ...t.filter((r) => r.points > 0).map((r) => r.points)
259
- );
248
+ }, C = (t) => {
249
+ const e = t.filter((n) => n.cash > 0);
250
+ let a = { cash: 1 / 0, baseCurrency: "" };
251
+ for (const n of e)
252
+ n.cash < a.cash && (a = n);
253
+ const g = Math.min(
254
+ ...t.filter((n) => n.points > 0).map((n) => n.points)
255
+ ), l = a.cash;
260
256
  return {
261
- lowestCash: e === 1 / 0 ? -1 : e,
262
- lowestPoints: n === 1 / 0 ? -1 : n
257
+ lowestCash: l === 1 / 0 ? -1 : l,
258
+ lowestPoints: g === 1 / 0 ? -1 : g,
259
+ currency: a.baseCurrency === "" ? null : a.baseCurrency
263
260
  };
264
261
  };
265
262
  export {
@@ -267,7 +264,7 @@ export {
267
264
  re as buildFlightSearchQuery,
268
265
  me as getAirlineProgram,
269
266
  K as getFlightNumber,
270
- u as getFullLogoPath,
267
+ w as getFullLogoPath,
271
268
  ce as getLogoPath,
272
269
  oe as groupFlightResults,
273
270
  ne as mapDataToFlightDetails,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@odynn/awayz-flights",
3
- "version": "0.5.12",
3
+ "version": "0.6.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"
@@ -68,7 +68,7 @@
68
68
  },
69
69
  "dependencies": {
70
70
  "@microsoft/fetch-event-source": "^2.0.1",
71
- "@odynn/awayz-core": ">= 0.5.0",
71
+ "@odynn/awayz-core": "^0.6.0",
72
72
  "@tanstack/react-query": "^5.67.1",
73
73
  "country-code-lookup": "^0.1.3"
74
74
  }