@odynn/awayz-flights 0.5.4 → 0.5.8

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,260 @@
1
+ import { jsx as i, jsxs as s, Fragment as Y } from "react/jsx-runtime";
2
+ import { RewardsService as J, CashValue as A, EToolTipPosition as C, EInvalidAmountDisplayOption as W } from "@odynn/awayz-core";
3
+ import { useQuery as X } from "@tanstack/react-query";
4
+ import { g as Z } from "./index-7zRjF0bU.js";
5
+ import { G as w, g as I, a as d, E as N, F as V, b as B } from "./FlightItinerary-Dy-2zMYt.js";
6
+ import { E as rr } from "./enums-DxmoBOKL.js";
7
+ import "./arrayExtensions-DFLvtO8l.js";
8
+ import ir, { useState as M, useMemo as L } from "react";
9
+ import { h as u } from "./moment-BGjjqtLQ.js";
10
+ import { useTranslation as er } from "react-i18next";
11
+ import { EPaymentType as v } from "./enums/EPaymentType.js";
12
+ import { isSameDayFlight as sr } from "./utils/flightDateUtils.js";
13
+ import { DEFAULT_AIRLINE_PROGRAM as tr, getFlightNumber as ar, getFullLogoPath as nr, getLogoPath as or, getAirlineProgram as cr } from "./utils/flightUtils.js";
14
+ import './assets/FlightResult.css';const lr = (r, t, o = t + "s") => r === 1 ? t : o;
15
+ function mr(r) {
16
+ if (!r || isNaN(r) || r < 0) return "N/A";
17
+ let t = r == null ? void 0 : r.toString().split(".")[0];
18
+ return t == null ? void 0 : t.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
19
+ }
20
+ function S(r) {
21
+ return w({ 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: [] }] })(r);
22
+ }
23
+ const Er = ({
24
+ details: r,
25
+ onClick: t,
26
+ showBestValue: o = !1,
27
+ onShowBestValueCalculation: n,
28
+ customStyling: _ = !1
29
+ }) => {
30
+ const { t: c } = er(), [D, $] = M(!1), m = r.origin, p = r.destination, E = r.flightDetails, k = r.paymentOptions || [];
31
+ let O = r.airlineLogo;
32
+ const R = k.filter((e) => e.points === -1).length === 1, z = k.filter((e) => e.points > -1).length === 1, [U, x] = M(tr), G = async () => {
33
+ const e = await cr(r.airlineProgram);
34
+ x(e);
35
+ }, { flightNumbers: y, airlines: K } = L(() => {
36
+ const e = [], a = [];
37
+ return r.flightDetails.slices.forEach((g) => {
38
+ g.segments.forEach((f) => {
39
+ const l = ar(f);
40
+ e.includes(l) || e.push(l), O = nr(
41
+ f.marketingCarrier.iataCode
42
+ );
43
+ const T = f.operatingCarrier;
44
+ a.some((Q) => Q.airline === T.name) || a.push({
45
+ logo: or(T.iataCode),
46
+ airline: T.name
47
+ });
48
+ });
49
+ }), G(), { flightNumbers: e, airlines: a };
50
+ }, [r.flightDetails.slices]), j = () => {
51
+ r.cash > 0 ? t(r, v.CASH) : t(r, v.POINTS);
52
+ }, q = !sr(
53
+ r.departureTime,
54
+ r.arrivalTime
55
+ ), F = r == null ? void 0 : r.airlineProgram, { data: b } = X({
56
+ queryKey: [rr.VALUE_CENTS, F],
57
+ queryFn: () => J.getPointsPerCent(F ?? ""),
58
+ staleTime: 1 / 0,
59
+ placeholderData: 0,
60
+ enabled: !!F && o
61
+ }), H = () => {
62
+ var l;
63
+ if (!r || !b || !r.points || !r.cash)
64
+ return {
65
+ pointsCashValue: 0,
66
+ bestValueStatus: "none"
67
+ /* NONE */
68
+ };
69
+ const e = b * r.points / 100, a = ((l = r.cashFee) == null ? void 0 : l.amount) || 0;
70
+ return {
71
+ bestValueStatus: e + a < r.cash ? "points" : "cash"
72
+ /* CASH */
73
+ };
74
+ }, { bestValueStatus: h } = H(), P = L(() => {
75
+ var e, a;
76
+ return (a = (e = r.paymentOptions) == null ? void 0 : e.find(
77
+ (g) => g.program === r.airlineProgram
78
+ )) == null ? void 0 : a.cashFee;
79
+ }, [r.paymentOptions, r.airlineProgram]);
80
+ return /* @__PURE__ */ i(
81
+ "div",
82
+ {
83
+ className: `${_ ? "" : "awayz-"}flight-result`,
84
+ onClick: j,
85
+ children: /* @__PURE__ */ s("div", { className: "content", children: [
86
+ /* @__PURE__ */ i("div", { className: "flight-info", children: /* @__PURE__ */ s("div", { className: "flight-locations", children: [
87
+ /* @__PURE__ */ i("div", { className: "airlines", children: K.map((e, a) => /* @__PURE__ */ i(ir.Fragment, { children: /* @__PURE__ */ s("div", { className: "tip", children: [
88
+ /* @__PURE__ */ i("img", { src: e.logo, alt: e.airline }),
89
+ /* @__PURE__ */ i("span", { className: "right", children: e.airline })
90
+ ] }, a) }, a)) }),
91
+ /* @__PURE__ */ s("div", { className: "flight-location", children: [
92
+ /* @__PURE__ */ s("p", { className: "show-desktop", children: [
93
+ m.city,
94
+ ",",
95
+ I(m.country)
96
+ ] }),
97
+ /* @__PURE__ */ i("p", { className: "show-desktop", children: u(r.departureTime).format(
98
+ c(d.DATE_TIME_MEDIUM, N.FlightShortDate)
99
+ ) }),
100
+ /* @__PURE__ */ i("p", { className: "show-mobile", children: m.airportCode }),
101
+ /* @__PURE__ */ i("p", { className: "show-mobile", children: u(r.departureTime).format(
102
+ c(d.TIME_ONLY, N.FlightTime)
103
+ ) })
104
+ ] }),
105
+ /* @__PURE__ */ s("div", { className: "flight-duration", children: [
106
+ /* @__PURE__ */ i("span", { className: "line" }),
107
+ /* @__PURE__ */ s("p", { children: [
108
+ Z(E.slices[0].duration),
109
+ " ",
110
+ " - ",
111
+ r.numberOfStops > 0 ? `${r.numberOfStops} ${lr(
112
+ r.numberOfStops,
113
+ "Stop"
114
+ )}` : "Direct"
115
+ ] }),
116
+ /* @__PURE__ */ i("span", { className: "line" })
117
+ ] }),
118
+ /* @__PURE__ */ s("div", { children: [
119
+ /* @__PURE__ */ s("p", { className: "show-desktop", children: [
120
+ p.city,
121
+ ", ",
122
+ I(p.country)
123
+ ] }),
124
+ /* @__PURE__ */ s("p", { className: "show-desktop", children: [
125
+ u(r.arrivalTime).format(
126
+ c(d.DATE_TIME_MEDIUM, N.FlightShortDate)
127
+ ),
128
+ " "
129
+ ] }),
130
+ /* @__PURE__ */ i("p", { className: "show-mobile", children: p.airportCode }),
131
+ /* @__PURE__ */ i("p", { className: "show-mobile", children: u(r.arrivalTime).format(
132
+ c(d.TIME_ONLY, N.FlightTime)
133
+ ) })
134
+ ] })
135
+ ] }) }),
136
+ /* @__PURE__ */ s("div", { className: "flight-footer", children: [
137
+ /* @__PURE__ */ i("div", { className: "flight-detail-container", children: /* @__PURE__ */ s(
138
+ "div",
139
+ {
140
+ className: "flight-detail",
141
+ onClick: (e) => {
142
+ e.stopPropagation(), $(!D);
143
+ },
144
+ children: [
145
+ /* @__PURE__ */ i("p", { children: "Aircraft" }),
146
+ /* @__PURE__ */ s("p", { className: "chevron-text", children: [
147
+ /* @__PURE__ */ i(V, {}),
148
+ /* @__PURE__ */ s("span", { children: [
149
+ y[0],
150
+ y.length > 1 && /* @__PURE__ */ s("sup", { children: [
151
+ "+",
152
+ y.length - 1
153
+ ] })
154
+ ] })
155
+ ] })
156
+ ]
157
+ }
158
+ ) }),
159
+ /* @__PURE__ */ s("div", { className: "booking-options ", children: [
160
+ r.cash > 0 && /* @__PURE__ */ s(
161
+ "div",
162
+ {
163
+ className: `amount-value ${h === "cash" && o ? "show-best-value-flag" : ""}`,
164
+ onClick: (e) => {
165
+ e.stopPropagation(), t(r, v.CASH);
166
+ },
167
+ children: [
168
+ /* @__PURE__ */ i("img", { src: O, alt: "marketing carrier logo" }),
169
+ /* @__PURE__ */ s("div", { children: [
170
+ /* @__PURE__ */ i("label", { children: R ? "Book For" : "From" }),
171
+ /* @__PURE__ */ i(
172
+ A,
173
+ {
174
+ amount: r.cash,
175
+ currency: r.currency,
176
+ position: C.LEFT
177
+ }
178
+ )
179
+ ] }),
180
+ h === "cash" && o && /* @__PURE__ */ s(
181
+ "div",
182
+ {
183
+ className: "best-value-flag tip",
184
+ onClick: (e) => {
185
+ e.stopPropagation(), n == null || n(r);
186
+ },
187
+ children: [
188
+ n && /* @__PURE__ */ i(S, {}),
189
+ /* @__PURE__ */ i("p", { children: "Best Value" }),
190
+ n && /* @__PURE__ */ i("span", { children: "Click to learn more" })
191
+ ]
192
+ }
193
+ )
194
+ ]
195
+ }
196
+ ),
197
+ r.points > 0 && /* @__PURE__ */ s(
198
+ "div",
199
+ {
200
+ className: `amount-value ${h === "points" && o ? "show-best-value-flag" : ""}`,
201
+ onClick: (e) => {
202
+ e.stopPropagation(), t(r, v.POINTS);
203
+ },
204
+ children: [
205
+ h === "points" && o && /* @__PURE__ */ s(
206
+ "div",
207
+ {
208
+ className: "best-value-flag tip",
209
+ onClick: (e) => {
210
+ e.stopPropagation(), n == null || n(r);
211
+ },
212
+ children: [
213
+ n && /* @__PURE__ */ i(S, {}),
214
+ /* @__PURE__ */ i("p", { children: "Best Value" }),
215
+ n && /* @__PURE__ */ i("span", { children: "Click to learn more" })
216
+ ]
217
+ }
218
+ ),
219
+ /* @__PURE__ */ i("img", { src: U.programLogo }),
220
+ /* @__PURE__ */ s("div", { children: [
221
+ /* @__PURE__ */ i("label", { children: z ? "Book For" : "From" }),
222
+ /* @__PURE__ */ s("p", { children: [
223
+ `${mr(r.points)} ${c("miles")}`,
224
+ !!P && /* @__PURE__ */ s(Y, { children: [
225
+ " + ",
226
+ /* @__PURE__ */ i(
227
+ A,
228
+ {
229
+ amount: P.amount,
230
+ currency: P.currency,
231
+ customDisplay: "No fee",
232
+ zeroDisplayOption: W.CUSTOM,
233
+ position: C.LEFT
234
+ }
235
+ )
236
+ ] })
237
+ ] })
238
+ ] })
239
+ ]
240
+ }
241
+ )
242
+ ] })
243
+ ] }),
244
+ /* @__PURE__ */ i("div", { className: `flight-details ${D ? "is-open" : ""}`, children: /* @__PURE__ */ i("div", { className: "inner", children: /* @__PURE__ */ i(
245
+ B,
246
+ {
247
+ itinerary: E.slices[0].segments,
248
+ origin: m,
249
+ destination: p,
250
+ isMultiDayFlight: q
251
+ }
252
+ ) }) })
253
+ ] })
254
+ }
255
+ );
256
+ };
257
+ export {
258
+ Er as F,
259
+ mr as c
260
+ };
@@ -1,10 +1,10 @@
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-CBvQEtrI.js";
4
+ import { F as x } from "../../FlightResult-pDdkYe7D.js";
5
5
  import "../../index-7zRjF0bU.js";
6
6
  import "../../FlightItinerary-Dy-2zMYt.js";
7
- import "../../enums-B584l_96.js";
7
+ import "../../enums-DxmoBOKL.js";
8
8
  import "../../arrayExtensions-DFLvtO8l.js";
9
9
  import "react";
10
10
  import "../../moment-BGjjqtLQ.js";
@@ -1,4 +1,4 @@
1
- import { F as l } from "../FlightResult-CBvQEtrI.js";
1
+ import { F as l } from "../FlightResult-pDdkYe7D.js";
2
2
  export {
3
3
  l as FlightResult
4
4
  };
@@ -1,4 +1,4 @@
1
- var S = /* @__PURE__ */ ((R) => (R.LOCATIONS = "LOCATIONS", R.CHECK_USER = "CHECK_USER", R.USER_REGIONS = "USER_REGIONS", R.CONVERT_CURRENCY = "CONVERT_CURRENCY", R.CLIENT_COMPONENT_KEY = "CLIENT_COMPONENT_KEY", R.SEARCH_LIMIT = "SEARCH_LIMIT", R.PROGRAMS = "PROGRAMS", R.USER_PROGRAMS = "USER_PROGRAMS", R.LINKED_USER_PROGRAMS = "LINKED_USER_PROGRAMS", R.BANKS = "BANKS", R.CARDS = "CARDS", R.USER_CARDS = "USER_CARDS", R.TRIPS = "TRIPS", R.UNCATEGORISED_BOOKINGS = "UNCATEGORISED_BOOKINGS", R.BOOKING = "BOOKING", R.VALUE_CENTS = "VALUE_CENTS", R))(S || {});
1
+ var S = /* @__PURE__ */ ((R) => (R.LOCATIONS = "LOCATIONS", R.CHECK_USER = "CHECK_USER", R.USER_REGIONS = "USER_REGIONS", R.CONVERT_CURRENCY = "CONVERT_CURRENCY", R.CLIENT_COMPONENT_KEY = "CLIENT_COMPONENT_KEY", R.SEARCH_LIMIT = "SEARCH_LIMIT", R.PROGRAMS = "PROGRAMS", R.USER_PROGRAMS = "USER_PROGRAMS", R.LINKED_USER_PROGRAMS = "LINKED_USER_PROGRAMS", R.BANKS = "BANKS", R.CARDS = "CARDS", R.USER_CARDS = "USER_CARDS", R.TRIPS = "TRIPS", R.UNCATEGORISED_BOOKINGS = "UNCATEGORISED_BOOKINGS", R.BOOKING = "BOOKING", R.VALUE_CENTS = "VALUE_CENTS", R.AVAILABILITY_ALERTS = "AVAILABILITY_ALERTS", R.ALERT_NOTIFICATIONS = "ALERT_NOTIFICATIONS", R))(S || {});
2
2
  export {
3
3
  S as E
4
4
  };
@@ -3,7 +3,7 @@ import { useMutation as N } from "@tanstack/react-query";
3
3
  import "../../moment-BGjjqtLQ.js";
4
4
  import "../../arrayExtensions-DFLvtO8l.js";
5
5
  import { c as W } from "../../objectUtils-CyIaVmog.js";
6
- import { E as q } from "../../enums-B584l_96.js";
6
+ import { E as q } from "../../enums-DxmoBOKL.js";
7
7
  import { useState as M, useRef as X } from "react";
8
8
  import { FlightService as D } from "../../services/flights/FlightsService.js";
9
9
  import Z from "../../stores/useFlightStore.js";
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-CBvQEtrI.js";
4
+ import { F as f, c as l } from "./FlightResult-pDdkYe7D.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";
@@ -1,23 +1,23 @@
1
- import { mapBaggageType as Q } from "../hooks/useFlightSearch/useFlightSearch.types.js";
2
- import { h as g } from "../moment-BGjjqtLQ.js";
3
- import { d as K, D as V } from "../index-7zRjF0bU.js";
1
+ import { mapBaggageType as j } from "../hooks/useFlightSearch/useFlightSearch.types.js";
2
+ import { h as p } from "../moment-BGjjqtLQ.js";
3
+ import { d as B, D as Q } from "../index-7zRjF0bU.js";
4
4
  import "../arrayExtensions-DFLvtO8l.js";
5
5
  import "react";
6
- import { awayzClient as Y } from "@odynn/awayz-core";
7
- import { WalletService as x } from "../services/wallet/WalletService.js";
8
- import { ERewardProgramCategories as H } from "../services/wallet/WalletService.types.js";
9
- const re = (t) => t == null ? void 0 : t.map((e) => {
10
- var i, n, l, m, s, a, r, c, o, d, u, C, w, b, D, F, L, A, T, P, k, h, O, v, R, E, I, _, N, z, M, S, Z, $, G;
6
+ import { awayzClient as V } from "@odynn/awayz-core";
7
+ import { WalletService as Y } from "../services/wallet/WalletService.js";
8
+ import { ERewardProgramCategories as x } from "../services/wallet/WalletService.types.js";
9
+ const ne = (t) => t == null ? void 0 : t.map((e) => {
10
+ var i, n, m, c, s, a, r, o, g, l, d, C, w, b, D, F, L, A, T, P, k, h, O, v, R, E, I, _, z, M, S, Z, $, G;
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: ((i = e.slices[0].segments[0].origin) == null ? void 0 : i.cityName) || ((l = (n = e.slices[0].segments[0].origin) == null ? void 0 : n.city) == null ? void 0 : l.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: ((r = e.slices[0].segments[0].origin) == null ? void 0 : r.iataCityCode) || ((o = (c = e.slices[0].segments[0].origin) == null ? void 0 : c.city) == null ? void 0 : o.iataCode),
16
+ city: ((i = e.slices[0].segments[0].origin) == null ? void 0 : i.cityName) || ((m = (n = e.slices[0].segments[0].origin) == null ? void 0 : n.city) == null ? void 0 : m.name),
17
+ country: ((c = e.slices[0].segments[0].origin) == null ? void 0 : c.iataCountryCode) || ((a = (s = e.slices[0].segments[0].origin) == null ? void 0 : s.city) == null ? void 0 : a.iataCountryCode),
18
+ airportCode: ((r = e.slices[0].segments[0].origin) == null ? void 0 : r.iataCityCode) || ((g = (o = e.slices[0].segments[0].origin) == null ? void 0 : o.city) == null ? void 0 : g.iataCode),
19
19
  coordinates: {
20
- latitude: (u = (d = e.slices[0].segments[0].origin) == null ? void 0 : d.city) == null ? void 0 : u.latitude,
20
+ latitude: (d = (l = e.slices[0].segments[0].origin) == null ? void 0 : l.city) == null ? void 0 : d.latitude,
21
21
  longitude: (w = (C = e.slices[0].segments[0].origin) == null ? void 0 : C.city) == null ? void 0 : w.longitude
22
22
  }
23
23
  },
@@ -26,8 +26,8 @@ const re = (t) => t == null ? void 0 : t.map((e) => {
26
26
  country: ((P = (T = e.slices[0].segments.getLast()) == null ? void 0 : T.destination) == null ? void 0 : P.iataCountryCode) || ((O = (h = (k = e.slices[0].segments.getLast()) == null ? void 0 : k.destination) == null ? void 0 : h.city) == null ? void 0 : O.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: (M = (z = (N = e.slices[0].segments.getLast()) == null ? void 0 : N.destination) == null ? void 0 : z.city) == null ? void 0 : M.latitude,
30
- longitude: ($ = (Z = (S = e.slices[0].segments.getLast()) == null ? void 0 : S.destination) == null ? void 0 : Z.city) == null ? void 0 : $.longitude
29
+ latitude: (S = (M = (z = e.slices[0].segments.getLast()) == null ? void 0 : z.destination) == null ? void 0 : M.city) == null ? void 0 : S.latitude,
30
+ longitude: (G = ($ = (Z = e.slices[0].segments.getLast()) == null ? void 0 : Z.destination) == null ? void 0 : $.city) == null ? void 0 : G.longitude
31
31
  }
32
32
  },
33
33
  airline: e.owner.name,
@@ -36,10 +36,10 @@ const re = (t) => t == null ? void 0 : t.map((e) => {
36
36
  ),
37
37
  cash: e.totalAmount ? parseFloat(e.totalAmount) : 0,
38
38
  currency: e.baseCurrency,
39
- flightNumber: j(e.slices[0].segments[0]),
39
+ flightNumber: K(e.slices[0].segments[0]),
40
40
  awayzGroupId: e.slices[0].comparisonKey || e.awayzRouteId || e.awayzGroupId || e.id,
41
- departureTime: g(e.slices[0].segments[0].departingAt).toDate(),
42
- arrivalTime: g(
41
+ departureTime: p(e.slices[0].segments[0].departingAt).toDate(),
42
+ arrivalTime: p(
43
43
  e.slices[0].segments[e.slices[0].segments.length - 1].arrivingAt
44
44
  ).toDate(),
45
45
  numberOfStops: e.slices[0].segments.length - 1,
@@ -47,53 +47,52 @@ const re = (t) => t == null ? void 0 : t.map((e) => {
47
47
  duration: e.slices[0].duration,
48
48
  airlineProgram: e.airlineProgram,
49
49
  paymentOptions: [],
50
- durationMinutes: K({
51
- departureTime: g(e.slices[0].segments[0].departingAt),
52
- arrivalTime: g(e.slices[0].segments.getLast().arrivingAt),
50
+ durationMinutes: B({
51
+ departureTime: p(e.slices[0].segments[0].departingAt),
52
+ arrivalTime: p(e.slices[0].segments.getLast().arrivingAt),
53
53
  originTimeZone: e.slices[0].segments[0].origin.timeZone,
54
54
  destinationTimeZone: e.slices[0].segments.getLast().destination.timeZone,
55
55
  duration: e.slices[0].duration
56
56
  }),
57
57
  cashFee: e.cashFee,
58
- cabinClass: e.slices[0].fareBrandName || e.slices[0].segments[0].passengers[0].cabinClassMarketingName || ((G = e.slices[0].segments[0].passengers[0].cabin) == null ? void 0 : G.marketingName)
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
59
59
  };
60
- }), j = (t) => {
60
+ }), K = (t) => {
61
61
  const e = t.operatingCarrierFlightNumber ? t.operatingCarrier : t.marketingCarrier, i = t.operatingCarrierFlightNumber ?? t.marketingCarrierFlightNumber;
62
- return e.iataCode + " " + J(i);
63
- }, oe = ({
62
+ return e.iataCode + " " + W(i);
63
+ }, re = ({
64
64
  originCode: t,
65
65
  destinationCode: e,
66
66
  departureDate: i,
67
67
  cabinClass: n,
68
- passengerCount: l,
69
- paymentType: m
68
+ passengerCount: m,
69
+ paymentType: c
70
70
  }) => {
71
71
  let s = "/flights/search/one-way/points-cash?";
72
- return s += `origin=${t}`, s += `&destination=${e}`, s += `&departure_date=${i}`, s += `&cabin_class=${n}`, s += `&adults=${l}`, s += `&cash_or_points=[${m}]`, s;
73
- }, W = (t) => t.flightDetails.slices[0].segments.map((i) => j(i)).join("_"), ce = (t) => {
72
+ return s += `origin=${t}`, s += `&destination=${e}`, s += `&departure_date=${i}`, s += `&cabin_class=${n}`, s += `&adults=${m}`, s += `&cash_or_points=[${c}]`, s;
73
+ }, H = (t) => t.flightDetails.slices[0].segments.map((i) => K(i)).join("_"), oe = (t) => {
74
74
  const e = {};
75
75
  t.forEach((s) => {
76
- var r;
77
- const a = W(s);
76
+ const a = H(s);
78
77
  if (e[a]) {
79
- const c = U(s);
80
- e[a].flight.paymentOptions.push(c);
81
- const o = p(
78
+ const r = U(s);
79
+ e[a].flight.paymentOptions.push(r);
80
+ const o = u(
82
81
  e[a].flight.paymentOptions
83
82
  );
84
83
  e[a].flight.cash = o.lowestCash, e[a].flight.points = o.lowestPoints;
85
84
  } else {
86
- const { origin: c, destination: o } = s, d = [U(s)], u = p(d);
85
+ const { origin: r, destination: o } = s, g = [U(s)], l = u(g);
87
86
  e[a] = {
88
87
  programs: [],
89
88
  flight: {
90
89
  id: s.awayzGroupId,
91
90
  partial: s.partial,
92
91
  origin: {
93
- city: c.city,
94
- country: c.country,
95
- airportCode: c.airportCode,
96
- coordinates: c.coordinates
92
+ city: r.city,
93
+ country: r.country,
94
+ airportCode: r.airportCode,
95
+ coordinates: r.coordinates
97
96
  },
98
97
  destination: {
99
98
  city: o.city,
@@ -106,30 +105,30 @@ const re = (t) => t == null ? void 0 : t.map((e) => {
106
105
  s.flightDetails.slices[0].segments[0].marketingCarrier.iataCode
107
106
  ),
108
107
  flightNumber: s.flightNumber,
109
- paymentOptions: d,
108
+ paymentOptions: g,
110
109
  numberOfStops: s.numberOfStops,
111
110
  departureTime: s.departureTime,
112
111
  arrivalTime: s.arrivalTime,
113
112
  awayzGroupId: a,
114
113
  duration: s.duration,
115
114
  airlineProgram: s.airlineProgram,
116
- durationMinutes: K({
117
- departureTime: g(
115
+ durationMinutes: B({
116
+ departureTime: p(
118
117
  s.flightDetails.slices[0].segments[0].departingAt
119
118
  ),
120
- arrivalTime: g(
119
+ arrivalTime: p(
121
120
  s.flightDetails.slices[0].segments.getLast().arrivingAt
122
121
  ),
123
122
  originTimeZone: s.flightDetails.slices[0].segments[0].origin.timeZone,
124
123
  destinationTimeZone: s.flightDetails.slices[0].segments.getLast().destination.timeZone,
125
124
  duration: s.flightDetails.slices[0].duration
126
125
  }),
127
- cash: u.lowestCash,
128
- points: u.lowestPoints,
126
+ cash: l.lowestCash,
127
+ points: l.lowestPoints,
129
128
  flightDetails: s.flightDetails,
130
129
  currency: s.flightDetails.baseCurrency,
131
130
  cashFee: s.cashFee,
132
- cabinClass: s.flightDetails.slices[0].fareBrandName || s.flightDetails.slices[0].segments[0].passengers[0].cabinClassMarketingName || ((r = s.flightDetails.slices[0].segments[0].passengers[0].cabin) == null ? void 0 : r.marketingName)
131
+ cabinClass: s.flightDetails.slices[0].segments[0].passengers[0].cabinClass || s.flightDetails.slices[0].segments[0].passengers[0].cabin.name || s.flightDetails.slices[0].segments[0].passengers[0].cabinClassMarketingName || s.flightDetails.slices[0].segments[0].passengers[0].cabin.marketingName
133
132
  }
134
133
  };
135
134
  }
@@ -143,77 +142,77 @@ const re = (t) => t == null ? void 0 : t.map((e) => {
143
142
  )
144
143
  ];
145
144
  s.programs.length > 0 ? s.programs.forEach((r) => {
146
- a.forEach((c) => {
147
- var d;
148
- const o = p(
145
+ a.forEach((o) => {
146
+ var l;
147
+ const g = u(
149
148
  s.flight.paymentOptions.filter(
150
- (u) => u.program === r || u.cash > 0 && u.carrier.name === c
149
+ (d) => d.program === r || d.cash > 0 && d.carrier.name === o
151
150
  )
152
151
  );
153
152
  i.push({
154
153
  ...s.flight,
155
- airline: c,
154
+ airline: o,
156
155
  airlineLogo: y(
157
- (d = s.flight.paymentOptions.find(
158
- (u) => u.carrier.name === c
159
- )) == null ? void 0 : d.carrier.iataCode
156
+ (l = s.flight.paymentOptions.find(
157
+ (d) => d.carrier.name === o
158
+ )) == null ? void 0 : l.carrier.iataCode
160
159
  ),
161
160
  airlineProgram: r,
162
- cash: o.lowestCash,
163
- points: o.lowestPoints
161
+ cash: g.lowestCash,
162
+ points: g.lowestPoints
164
163
  });
165
164
  });
166
165
  }) : a.forEach((r) => {
167
- var o;
168
- const { lowestCash: c } = p(
166
+ var g;
167
+ const { lowestCash: o } = u(
169
168
  s.flight.paymentOptions.filter(
170
- (d) => d.carrier.name === r
169
+ (l) => l.carrier.name === r
171
170
  )
172
171
  );
173
172
  i.push({
174
173
  ...s.flight,
175
174
  airline: r,
176
175
  airlineLogo: y(
177
- (o = s.flight.paymentOptions.find(
178
- (d) => d.carrier.name === r
179
- )) == null ? void 0 : o.carrier.iataCode
176
+ (g = s.flight.paymentOptions.find(
177
+ (l) => l.carrier.name === r
178
+ )) == null ? void 0 : g.carrier.iataCode
180
179
  ),
181
- cash: c
180
+ cash: o
182
181
  });
183
182
  });
184
183
  });
185
- const { cashlessResults: n, otherResults: l } = i.reduce(
184
+ const { cashlessResults: n, otherResults: m } = i.reduce(
186
185
  (s, a) => (a.cash <= 0 && a.points > 0 ? s.cashlessResults.push(a) : a.cash > 0 && s.otherResults.push(a), s),
187
186
  { cashlessResults: [], otherResults: [] }
188
- ), m = l;
187
+ ), c = m;
189
188
  return n.forEach((s) => {
190
- m.find(
189
+ c.find(
191
190
  (r) => r.awayzGroupId === s.awayzGroupId
192
- ) || m.push(s);
193
- }), m;
194
- }, J = (t) => t ? t.replace(/^0+/, "") : "", me = (t) => `https://assets.duffel.com/img/airlines/for-light-background/full-color-logo/${t}.svg`, y = (t) => `${V}${t}.svg`, B = "/img/logo/odynn-eye.svg", q = {
195
- categoryLogo: B,
196
- programLogo: B,
191
+ ) || c.push(s);
192
+ }), c;
193
+ }, W = (t) => t ? t.replace(/^0+/, "") : "", ce = (t) => `https://assets.duffel.com/img/airlines/for-light-background/full-color-logo/${t}.svg`, y = (t) => `${Q}${t}.svg`, N = "/img/logo/odynn-eye.svg", q = {
194
+ categoryLogo: N,
195
+ programLogo: N,
197
196
  awayzActive: [],
198
197
  mainProgram: "Unknown",
199
198
  displayProgram: "Unknown",
200
199
  id: "Unknown",
201
200
  totalAccumulatedPoints: 0,
202
- category: H.Airline,
201
+ category: x.Airline,
203
202
  colour: "#fff",
204
203
  // Using App Foreground Colour
205
204
  url: "https://www.odynn.com"
206
- }, le = async (t) => {
207
- const { airlines: e } = await Y.ensureQueryData({
205
+ }, me = async (t) => {
206
+ const { airlines: e } = await V.ensureQueryData({
208
207
  queryKey: ["walletAwards"],
209
- queryFn: x.getAwards,
208
+ queryFn: Y.getAwards,
210
209
  staleTime: 864e5
211
210
  // 24 hours
212
211
  });
213
212
  let i = e.find(
214
213
  (n) => {
215
- var l, m, s, a;
216
- return ((m = (l = n.mainProgram) == null ? void 0 : l.toLowerCase()) == null ? void 0 : m.includes(t == null ? void 0 : t.toLowerCase())) || ((a = (s = n.displayProgram) == null ? void 0 : s.toLowerCase()) == null ? void 0 : a.includes(t == null ? void 0 : t.toLowerCase()));
214
+ var m, c, s, a;
215
+ return ((c = (m = n.mainProgram) == null ? void 0 : m.toLowerCase()) == null ? void 0 : c.includes(t == null ? void 0 : t.toLowerCase())) || ((a = (s = n.displayProgram) == null ? void 0 : s.toLowerCase()) == null ? void 0 : a.includes(t == null ? void 0 : t.toLowerCase()));
217
216
  }
218
217
  ) ?? q;
219
218
  return i || (i = {
@@ -223,10 +222,10 @@ const re = (t) => t == null ? void 0 : t.map((e) => {
223
222
  id: t
224
223
  }), i;
225
224
  }, U = (t) => {
226
- var n, l, m, s;
227
- const i = (((m = (l = (n = t.flightDetails.slices.getFirst()) == null ? void 0 : n.segments.getFirst()) == null ? void 0 : l.passengers.getFirst()) == null ? void 0 : m.baggages) ?? []).map(
225
+ var n, m, c, s;
226
+ const i = (((c = (m = (n = t.flightDetails.slices.getFirst()) == null ? void 0 : n.segments.getFirst()) == null ? void 0 : m.passengers.getFirst()) == null ? void 0 : c.baggages) ?? []).map(
228
227
  (a) => ({
229
- type: Q(a.type),
228
+ type: j(a.type),
230
229
  quantity: a.quantity
231
230
  })
232
231
  );
@@ -245,7 +244,7 @@ const re = (t) => t == null ? void 0 : t.map((e) => {
245
244
  name: t.flightDetails.slices.getFirst().segments.getFirst().marketingCarrier.name
246
245
  }
247
246
  };
248
- }, p = (t) => {
247
+ }, u = (t) => {
249
248
  const e = Math.min(
250
249
  ...t.filter((n) => n.cash > 0).map((n) => n.cash)
251
250
  ), i = Math.min(
@@ -258,12 +257,12 @@ const re = (t) => t == null ? void 0 : t.map((e) => {
258
257
  };
259
258
  export {
260
259
  q as DEFAULT_AIRLINE_PROGRAM,
261
- oe as buildFlightSearchQuery,
262
- le as getAirlineProgram,
263
- j as getFlightNumber,
260
+ re as buildFlightSearchQuery,
261
+ me as getAirlineProgram,
262
+ K as getFlightNumber,
264
263
  y as getFullLogoPath,
265
- me as getLogoPath,
266
- ce as groupFlightResults,
267
- re as mapDataToFlightDetails,
268
- J as removeLeadingZeros
264
+ ce as getLogoPath,
265
+ oe as groupFlightResults,
266
+ ne as mapDataToFlightDetails,
267
+ W as removeLeadingZeros
269
268
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@odynn/awayz-flights",
3
- "version": "0.5.4",
3
+ "version": "0.5.8",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"
@@ -1,257 +0,0 @@
1
- import { jsx as r, jsxs as s, Fragment as J } from "react/jsx-runtime";
2
- import { RewardsService as W, CashValue as C, EToolTipPosition as M, EInvalidAmountDisplayOption as X } from "@odynn/awayz-core";
3
- import { useQuery as Z } from "@tanstack/react-query";
4
- import { g as w } from "./index-7zRjF0bU.js";
5
- import { G as V, g as b, a as u, E as v, F as B, b as ii } from "./FlightItinerary-Dy-2zMYt.js";
6
- import { E as ri } from "./enums-B584l_96.js";
7
- import "./arrayExtensions-DFLvtO8l.js";
8
- import ei, { useState as L, useMemo as _ } from "react";
9
- import { h as y } from "./moment-BGjjqtLQ.js";
10
- import { useTranslation as si } from "react-i18next";
11
- import { EPaymentType as P } from "./enums/EPaymentType.js";
12
- import { isSameDayFlight as ni } from "./utils/flightDateUtils.js";
13
- import { DEFAULT_AIRLINE_PROGRAM as ai, getFlightNumber as oi, getLogoPath as $, getAirlineProgram as ti } from "./utils/flightUtils.js";
14
- import './assets/FlightResult.css';const ci = (i, a, t = a + "s") => i === 1 ? a : t;
15
- function li(i) {
16
- if (!i || isNaN(i) || i < 0) return "N/A";
17
- let a = i == null ? void 0 : i.toString().split(".")[0];
18
- return a == null ? void 0 : a.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
19
- }
20
- function S(i) {
21
- return V({ 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
- }
23
- const Di = ({
24
- details: i,
25
- onClick: a,
26
- showBestValue: t = !1,
27
- onShowBestValueCalculation: o,
28
- customStyling: R = !1
29
- }) => {
30
- const { t: c } = si(), [O, z] = L(!1), p = i.origin, h = i.destination, k = i.flightDetails, A = i.paymentOptions || [], U = A.filter((e) => e.points === -1).length === 1, x = A.filter((e) => e.points > -1).length === 1, [G, K] = L(ai), j = async () => {
31
- const e = await ti(i.airlineProgram);
32
- K(e);
33
- }, { flightNumbers: F, airlines: q } = _(() => {
34
- const e = [], n = [];
35
- return i.flightDetails.slices.forEach((f) => {
36
- f.segments.forEach((d) => {
37
- const l = oi(d);
38
- e.includes(l) || e.push(l);
39
- const m = d.marketingCarrier, N = d.operatingCarrier;
40
- n.some((E) => E.airline === N.name) || n.push({
41
- logo: $(N.iataCode),
42
- airline: N.name
43
- }), m && N.name !== m.name && !n.some((E) => E.airline === m.name) && n.push({
44
- logo: $(m.iataCode),
45
- airline: m.name
46
- });
47
- });
48
- }), j(), { flightNumbers: e, airlines: n };
49
- }, [i.flightDetails.slices]), H = () => {
50
- i.cash > 0 ? a(i, P.CASH) : a(i, P.POINTS);
51
- }, Q = !ni(
52
- i.departureTime,
53
- i.arrivalTime
54
- ), T = i == null ? void 0 : i.airlineProgram, { data: I } = Z({
55
- queryKey: [ri.VALUE_CENTS, T],
56
- queryFn: () => W.getPointsPerCent(T ?? ""),
57
- staleTime: 1 / 0,
58
- placeholderData: 0,
59
- enabled: !!T && t
60
- }), Y = () => {
61
- var l;
62
- if (!i || !I || !i.points || !i.cash)
63
- return {
64
- pointsCashValue: 0,
65
- isBestValue: !1
66
- };
67
- const e = I * i.points / 100, n = ((l = i.cashFee) == null ? void 0 : l.amount) || 0;
68
- return {
69
- isPointsBestValue: e + n < i.cash
70
- };
71
- }, { isPointsBestValue: g } = Y(), D = _(() => {
72
- var e, n;
73
- return (n = (e = i.paymentOptions) == null ? void 0 : e.find(
74
- (f) => f.program === i.airlineProgram
75
- )) == null ? void 0 : n.cashFee;
76
- }, [i.paymentOptions, i.airlineProgram]);
77
- return /* @__PURE__ */ r(
78
- "div",
79
- {
80
- className: `${R ? "" : "awayz-"}flight-result`,
81
- onClick: H,
82
- children: /* @__PURE__ */ s("div", { className: "content", children: [
83
- /* @__PURE__ */ r("div", { className: "flight-info", children: /* @__PURE__ */ s("div", { className: "flight-locations", children: [
84
- /* @__PURE__ */ r("div", { className: "airlines", children: q.map((e, n) => /* @__PURE__ */ r(ei.Fragment, { children: /* @__PURE__ */ s("div", { className: "tip", children: [
85
- /* @__PURE__ */ r("img", { src: e.logo, alt: e.airline }),
86
- /* @__PURE__ */ r("span", { className: "right", children: e.airline })
87
- ] }, n) }, n)) }),
88
- /* @__PURE__ */ s("div", { className: "flight-location", children: [
89
- /* @__PURE__ */ s("p", { className: "show-desktop", children: [
90
- p.city,
91
- ",",
92
- b(p.country)
93
- ] }),
94
- /* @__PURE__ */ r("p", { className: "show-desktop", children: y(i.departureTime).format(
95
- c(u.DATE_TIME_MEDIUM, v.FlightShortDate)
96
- ) }),
97
- /* @__PURE__ */ r("p", { className: "show-mobile", children: p.airportCode }),
98
- /* @__PURE__ */ r("p", { className: "show-mobile", children: y(i.departureTime).format(
99
- c(u.TIME_ONLY, v.FlightTime)
100
- ) })
101
- ] }),
102
- /* @__PURE__ */ s("div", { className: "flight-duration", children: [
103
- /* @__PURE__ */ r("span", { className: "line" }),
104
- /* @__PURE__ */ s("p", { children: [
105
- w(k.slices[0].duration),
106
- " ",
107
- " - ",
108
- i.numberOfStops > 0 ? `${i.numberOfStops} ${ci(
109
- i.numberOfStops,
110
- "Stop"
111
- )}` : "Direct"
112
- ] }),
113
- /* @__PURE__ */ r("span", { className: "line" })
114
- ] }),
115
- /* @__PURE__ */ s("div", { children: [
116
- /* @__PURE__ */ s("p", { className: "show-desktop", children: [
117
- h.city,
118
- ", ",
119
- b(h.country)
120
- ] }),
121
- /* @__PURE__ */ s("p", { className: "show-desktop", children: [
122
- y(i.arrivalTime).format(
123
- c(u.DATE_TIME_MEDIUM, v.FlightShortDate)
124
- ),
125
- " "
126
- ] }),
127
- /* @__PURE__ */ r("p", { className: "show-mobile", children: h.airportCode }),
128
- /* @__PURE__ */ r("p", { className: "show-mobile", children: y(i.arrivalTime).format(
129
- c(u.TIME_ONLY, v.FlightTime)
130
- ) })
131
- ] })
132
- ] }) }),
133
- /* @__PURE__ */ s("div", { className: "flight-footer", children: [
134
- /* @__PURE__ */ r("div", { className: "flight-detail-container", children: /* @__PURE__ */ s(
135
- "div",
136
- {
137
- className: "flight-detail",
138
- onClick: (e) => {
139
- e.stopPropagation(), z(!O);
140
- },
141
- children: [
142
- /* @__PURE__ */ r("p", { children: "Aircraft" }),
143
- /* @__PURE__ */ s("p", { className: "chevron-text", children: [
144
- /* @__PURE__ */ r(B, {}),
145
- /* @__PURE__ */ s("span", { children: [
146
- F[0],
147
- F.length > 1 && /* @__PURE__ */ s("sup", { children: [
148
- "+",
149
- F.length - 1
150
- ] })
151
- ] })
152
- ] })
153
- ]
154
- }
155
- ) }),
156
- /* @__PURE__ */ s("div", { className: "booking-options ", children: [
157
- i.cash > 0 && /* @__PURE__ */ s(
158
- "div",
159
- {
160
- className: `amount-value ${!g && t ? "show-best-value-flag" : ""}`,
161
- onClick: (e) => {
162
- e.stopPropagation(), a(i, P.CASH);
163
- },
164
- children: [
165
- /* @__PURE__ */ r("img", { src: i.airlineLogo }),
166
- /* @__PURE__ */ s("div", { children: [
167
- /* @__PURE__ */ r("label", { children: U ? "Book For" : "From" }),
168
- /* @__PURE__ */ r(
169
- C,
170
- {
171
- amount: i.cash,
172
- currency: i.currency,
173
- position: M.LEFT
174
- }
175
- )
176
- ] }),
177
- !g && t && /* @__PURE__ */ s(
178
- "div",
179
- {
180
- className: "best-value-flag tip",
181
- onClick: (e) => {
182
- e.stopPropagation(), o == null || o(i);
183
- },
184
- children: [
185
- o && /* @__PURE__ */ r(S, {}),
186
- /* @__PURE__ */ r("p", { children: "Best Value" }),
187
- o && /* @__PURE__ */ r("span", { children: "Click to learn more" })
188
- ]
189
- }
190
- )
191
- ]
192
- }
193
- ),
194
- i.points > 0 && /* @__PURE__ */ s(
195
- "div",
196
- {
197
- className: `amount-value ${g && t ? "show-best-value-flag" : ""}`,
198
- onClick: (e) => {
199
- e.stopPropagation(), a(i, P.POINTS);
200
- },
201
- children: [
202
- g && t && /* @__PURE__ */ s(
203
- "div",
204
- {
205
- className: "best-value-flag tip",
206
- onClick: (e) => {
207
- e.stopPropagation(), o == null || o(i);
208
- },
209
- children: [
210
- o && /* @__PURE__ */ r(S, {}),
211
- /* @__PURE__ */ r("p", { children: "Best Value" }),
212
- o && /* @__PURE__ */ r("span", { children: "Click to learn more" })
213
- ]
214
- }
215
- ),
216
- /* @__PURE__ */ r("img", { src: G.programLogo }),
217
- /* @__PURE__ */ s("div", { children: [
218
- /* @__PURE__ */ r("label", { children: x ? "Book For" : "From" }),
219
- /* @__PURE__ */ s("p", { children: [
220
- `${li(i.points)} ${c("miles")}`,
221
- !!D && /* @__PURE__ */ s(J, { children: [
222
- " + ",
223
- /* @__PURE__ */ r(
224
- C,
225
- {
226
- amount: D.amount,
227
- currency: D.currency,
228
- customDisplay: "No fee",
229
- zeroDisplayOption: X.CUSTOM,
230
- position: M.LEFT
231
- }
232
- )
233
- ] })
234
- ] })
235
- ] })
236
- ]
237
- }
238
- )
239
- ] })
240
- ] }),
241
- /* @__PURE__ */ r("div", { className: `flight-details ${O ? "is-open" : ""}`, children: /* @__PURE__ */ r("div", { className: "inner", children: /* @__PURE__ */ r(
242
- ii,
243
- {
244
- itinerary: k.slices[0].segments,
245
- origin: p,
246
- destination: h,
247
- isMultiDayFlight: Q
248
- }
249
- ) }) })
250
- ] })
251
- }
252
- );
253
- };
254
- export {
255
- Di as F,
256
- li as c
257
- };