@odynn/awayz-flights 0.6.4 → 0.6.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{FlightResult-Dy1E7ip1.js → FlightResult-Ci2XCEPV.js} +87 -79
- package/dist/components/FlightResult/FlightResult.js +1 -1
- package/dist/components/index.js +1 -1
- package/dist/hooks/useFlightSearch/useFlightSearch.js +134 -130
- package/dist/lib/hooks/useFlightSearch/useFlightSearch.d.ts +11 -4
- package/dist/lib/stores/useFlightStore.d.ts +0 -2
- package/dist/main.js +1 -1
- package/dist/stores/useFlightStore.js +6 -8
- package/dist/utils/flightUtils.js +71 -71
- package/package.json +2 -2
|
@@ -1,82 +1,82 @@
|
|
|
1
|
-
import { jsx as i, jsxs as n, Fragment as
|
|
2
|
-
import { RewardsService as
|
|
3
|
-
import { useQuery as
|
|
4
|
-
import { g as
|
|
5
|
-
import { G as
|
|
6
|
-
import { E as
|
|
1
|
+
import { jsx as i, jsxs as n, Fragment as B } from "react/jsx-runtime";
|
|
2
|
+
import { useAwayzContext as rr, RewardsService as _, CashValue as L, EToolTipPosition as R, EInvalidAmountDisplayOption as er, awayzClient as x, CurrencyService as ir } from "@odynn/awayz-core";
|
|
3
|
+
import { useQuery as nr } from "@tanstack/react-query";
|
|
4
|
+
import { g as tr } from "./index-7zRjF0bU.js";
|
|
5
|
+
import { G as ar, g as U, a as d, E as N, F as sr, b as or } from "./FlightItinerary-Dy-2zMYt.js";
|
|
6
|
+
import { E as A } from "./enums-DxmoBOKL.js";
|
|
7
7
|
import "./arrayExtensions-DFLvtO8l.js";
|
|
8
|
-
import
|
|
8
|
+
import cr, { useState as O, useMemo as $, useEffect as lr } from "react";
|
|
9
9
|
import { h as v } from "./moment-BGjjqtLQ.js";
|
|
10
|
-
import { useTranslation as
|
|
10
|
+
import { useTranslation as mr } from "react-i18next";
|
|
11
11
|
import { EPaymentType as P } from "./enums/EPaymentType.js";
|
|
12
|
-
import { isSameDayFlight as
|
|
13
|
-
import { DEFAULT_AIRLINE_PROGRAM as
|
|
14
|
-
import './assets/FlightResult.css';const
|
|
15
|
-
function
|
|
12
|
+
import { isSameDayFlight as pr } from "./utils/flightDateUtils.js";
|
|
13
|
+
import { DEFAULT_AIRLINE_PROGRAM as hr, getFlightNumber as gr, getLogoPath as fr, getAirlineProgram as ur } from "./utils/flightUtils.js";
|
|
14
|
+
import './assets/FlightResult.css';const yr = (r, t, o = t + "s") => r === 1 ? t : o;
|
|
15
|
+
function dr(r) {
|
|
16
16
|
if (!r || isNaN(r) || r < 0) return "N/A";
|
|
17
17
|
let t = r == null ? void 0 : r.toString().split(".")[0];
|
|
18
18
|
return t == null ? void 0 : t.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
19
19
|
}
|
|
20
|
-
function
|
|
21
|
-
return
|
|
20
|
+
function z(r) {
|
|
21
|
+
return ar({ 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
22
|
}
|
|
23
23
|
async function q(r, t, o) {
|
|
24
24
|
if (!r || t === o) return r;
|
|
25
|
-
const s = await
|
|
26
|
-
queryKey: [
|
|
25
|
+
const s = await x.ensureQueryData({
|
|
26
|
+
queryKey: [A.CONVERT_CURRENCY, t, o],
|
|
27
27
|
staleTime: 1e3 * 60 * 60,
|
|
28
28
|
// 1 hour
|
|
29
|
-
queryFn: () =>
|
|
29
|
+
queryFn: () => ir.convertCurrency({
|
|
30
30
|
baseCurrency: t,
|
|
31
31
|
targetCurrency: o
|
|
32
32
|
})
|
|
33
33
|
});
|
|
34
34
|
return r * s;
|
|
35
35
|
}
|
|
36
|
-
const
|
|
36
|
+
const Mr = ({
|
|
37
37
|
details: r,
|
|
38
38
|
onClick: t,
|
|
39
39
|
showBestValue: o = !1,
|
|
40
40
|
onShowBestValueCalculation: s,
|
|
41
41
|
customStyling: K = !1
|
|
42
42
|
}) => {
|
|
43
|
-
const { t: l } =
|
|
43
|
+
const { t: l } = mr(), [b, w] = O(!1), [m, Q] = O(
|
|
44
44
|
"none"
|
|
45
45
|
/* NONE */
|
|
46
|
-
), p = r.origin, h = r.destination,
|
|
47
|
-
const e = await
|
|
48
|
-
|
|
49
|
-
}, { flightNumbers:
|
|
46
|
+
), { config: F } = rr(), p = r.origin, h = r.destination, I = r.flightDetails, k = r.paymentOptions || [], G = k.filter((e) => e.points === -1).length === 1, Y = k.filter((e) => e.points > -1).length === 1, [j, H] = O(hr), J = async () => {
|
|
47
|
+
const e = await ur(r.airlineProgram);
|
|
48
|
+
H(e);
|
|
49
|
+
}, { flightNumbers: T, airlines: W } = $(() => {
|
|
50
50
|
const e = [], a = [];
|
|
51
51
|
return r.flightDetails.slices.forEach((c) => {
|
|
52
52
|
c.segments.forEach((f) => {
|
|
53
|
-
const u =
|
|
53
|
+
const u = gr(f);
|
|
54
54
|
e.includes(u) || e.push(u);
|
|
55
55
|
const y = f.operatingCarrier;
|
|
56
|
-
a.some((
|
|
57
|
-
logo:
|
|
56
|
+
a.some((C) => C.airline === y.name) || a.push({
|
|
57
|
+
logo: fr(y.iataCode),
|
|
58
58
|
airline: y.name
|
|
59
59
|
});
|
|
60
60
|
});
|
|
61
|
-
}),
|
|
62
|
-
}, [r.flightDetails.slices]),
|
|
61
|
+
}), J(), { flightNumbers: e, airlines: a };
|
|
62
|
+
}, [r.flightDetails.slices]), X = () => {
|
|
63
63
|
r.cash > 0 ? t(r, P.CASH) : t(r, P.POINTS);
|
|
64
|
-
},
|
|
64
|
+
}, Z = !pr(
|
|
65
65
|
r.departureTime,
|
|
66
66
|
r.arrivalTime
|
|
67
|
-
),
|
|
68
|
-
queryKey: [
|
|
69
|
-
queryFn: () =>
|
|
67
|
+
), E = r == null ? void 0 : r.airlineProgram, { data: M } = nr({
|
|
68
|
+
queryKey: [A.VALUE_CENTS, E, "test"],
|
|
69
|
+
queryFn: () => _.getCentPerPoint(E),
|
|
70
70
|
staleTime: 1 / 0,
|
|
71
|
-
enabled: !!
|
|
71
|
+
enabled: !!E && o
|
|
72
72
|
}), g = $(() => {
|
|
73
73
|
var e, a;
|
|
74
74
|
return (a = (e = r.paymentOptions) == null ? void 0 : e.find(
|
|
75
75
|
(c) => c.program === r.airlineProgram
|
|
76
76
|
)) == null ? void 0 : a.cashFee;
|
|
77
|
-
}, [r.paymentOptions, r.airlineProgram]),
|
|
78
|
-
var
|
|
79
|
-
if (!r || !
|
|
77
|
+
}, [r.paymentOptions, r.airlineProgram]), V = async () => {
|
|
78
|
+
var S;
|
|
79
|
+
if (!r || !M || !r.points || !r.cash)
|
|
80
80
|
return;
|
|
81
81
|
const e = r.currency;
|
|
82
82
|
let a = {
|
|
@@ -84,21 +84,22 @@ const Ir = ({
|
|
|
84
84
|
currency: e
|
|
85
85
|
};
|
|
86
86
|
try {
|
|
87
|
-
a = await
|
|
88
|
-
queryKey: [
|
|
87
|
+
a = await x.ensureQueryData({
|
|
88
|
+
queryKey: [A.VALUE_CENTS, r.airlineProgram],
|
|
89
89
|
staleTime: 1e3 * 60 * 60,
|
|
90
90
|
// 1 hour
|
|
91
|
-
queryFn: () =>
|
|
91
|
+
queryFn: () => _.getCentPerPoint(r.airlineProgram)
|
|
92
92
|
});
|
|
93
|
-
} catch {
|
|
93
|
+
} catch (D) {
|
|
94
94
|
console.warn(
|
|
95
95
|
"Failed to fetch value cents for airline program:",
|
|
96
|
-
r.airlineProgram
|
|
96
|
+
r.airlineProgram,
|
|
97
|
+
D
|
|
97
98
|
);
|
|
98
99
|
}
|
|
99
|
-
const c = ((
|
|
100
|
-
(
|
|
101
|
-
)) == null ? void 0 :
|
|
100
|
+
const c = ((S = r.paymentOptions.find(
|
|
101
|
+
(D) => D.program === r.airlineProgram
|
|
102
|
+
)) == null ? void 0 : S.cashFee) ?? {
|
|
102
103
|
amount: 0,
|
|
103
104
|
currency: e
|
|
104
105
|
}, [f, u] = await Promise.all([
|
|
@@ -108,30 +109,37 @@ const Ir = ({
|
|
|
108
109
|
a.currency,
|
|
109
110
|
e
|
|
110
111
|
)
|
|
111
|
-
]),
|
|
112
|
+
]), C = u * r.points / 100 + f < r.cash;
|
|
112
113
|
Q(
|
|
113
|
-
|
|
114
|
+
C ? "points" : "cash"
|
|
114
115
|
/* CASH */
|
|
115
116
|
);
|
|
116
117
|
};
|
|
117
|
-
return
|
|
118
|
-
|
|
119
|
-
}, [r,
|
|
118
|
+
return lr(() => {
|
|
119
|
+
V();
|
|
120
|
+
}, [r, M, g]), /* @__PURE__ */ i(
|
|
120
121
|
"div",
|
|
121
122
|
{
|
|
122
123
|
className: `${K ? "" : "awayz-"}flight-result`,
|
|
123
|
-
onClick:
|
|
124
|
+
onClick: X,
|
|
124
125
|
children: /* @__PURE__ */ n("div", { className: "content", children: [
|
|
125
126
|
/* @__PURE__ */ i("div", { className: "flight-info", children: /* @__PURE__ */ n("div", { className: "flight-locations", children: [
|
|
126
|
-
/* @__PURE__ */ i("div", { className: "airlines", children:
|
|
127
|
-
/* @__PURE__ */ i(
|
|
127
|
+
/* @__PURE__ */ i("div", { className: "airlines", children: W.map((e, a) => /* @__PURE__ */ i(cr.Fragment, { children: /* @__PURE__ */ n("div", { className: "tip", children: [
|
|
128
|
+
/* @__PURE__ */ i(
|
|
129
|
+
"img",
|
|
130
|
+
{
|
|
131
|
+
src: e.logo,
|
|
132
|
+
alt: e.airline,
|
|
133
|
+
onError: (c) => c.currentTarget.src = (F == null ? void 0 : F.logoFallbackImageUrl) ?? ""
|
|
134
|
+
}
|
|
135
|
+
),
|
|
128
136
|
/* @__PURE__ */ i("span", { className: "right", children: e.airline })
|
|
129
137
|
] }, a) }, a)) }),
|
|
130
138
|
/* @__PURE__ */ n("div", { className: "flight-location", children: [
|
|
131
139
|
/* @__PURE__ */ n("p", { className: "show-desktop", children: [
|
|
132
140
|
p.city,
|
|
133
141
|
",",
|
|
134
|
-
|
|
142
|
+
U(p.country)
|
|
135
143
|
] }),
|
|
136
144
|
/* @__PURE__ */ i("p", { className: "show-desktop", children: v(r.departureTime).format(
|
|
137
145
|
l(d.DATE_TIME_MEDIUM, N.FlightShortDate)
|
|
@@ -144,10 +152,10 @@ const Ir = ({
|
|
|
144
152
|
/* @__PURE__ */ n("div", { className: "flight-duration", children: [
|
|
145
153
|
/* @__PURE__ */ i("span", { className: "line" }),
|
|
146
154
|
/* @__PURE__ */ n("p", { children: [
|
|
147
|
-
|
|
155
|
+
tr(I.slices[0].duration),
|
|
148
156
|
" ",
|
|
149
157
|
" - ",
|
|
150
|
-
r.numberOfStops > 0 ? `${r.numberOfStops} ${
|
|
158
|
+
r.numberOfStops > 0 ? `${r.numberOfStops} ${yr(
|
|
151
159
|
r.numberOfStops,
|
|
152
160
|
"Stop"
|
|
153
161
|
)}` : "Direct"
|
|
@@ -158,7 +166,7 @@ const Ir = ({
|
|
|
158
166
|
/* @__PURE__ */ n("p", { className: "show-desktop", children: [
|
|
159
167
|
h.city,
|
|
160
168
|
", ",
|
|
161
|
-
|
|
169
|
+
U(h.country)
|
|
162
170
|
] }),
|
|
163
171
|
/* @__PURE__ */ n("p", { className: "show-desktop", children: [
|
|
164
172
|
v(r.arrivalTime).format(
|
|
@@ -178,17 +186,17 @@ const Ir = ({
|
|
|
178
186
|
{
|
|
179
187
|
className: "flight-detail",
|
|
180
188
|
onClick: (e) => {
|
|
181
|
-
e.stopPropagation(),
|
|
189
|
+
e.stopPropagation(), w(!b);
|
|
182
190
|
},
|
|
183
191
|
children: [
|
|
184
192
|
/* @__PURE__ */ i("p", { children: "Aircraft" }),
|
|
185
193
|
/* @__PURE__ */ n("p", { className: "chevron-text", children: [
|
|
186
|
-
/* @__PURE__ */ i(
|
|
194
|
+
/* @__PURE__ */ i(sr, {}),
|
|
187
195
|
/* @__PURE__ */ n("span", { children: [
|
|
188
|
-
|
|
189
|
-
|
|
196
|
+
T[0],
|
|
197
|
+
T.length > 1 && /* @__PURE__ */ n("sup", { children: [
|
|
190
198
|
"+",
|
|
191
|
-
|
|
199
|
+
T.length - 1
|
|
192
200
|
] })
|
|
193
201
|
] })
|
|
194
202
|
] })
|
|
@@ -206,13 +214,13 @@ const Ir = ({
|
|
|
206
214
|
children: [
|
|
207
215
|
/* @__PURE__ */ i("b", { children: "Cash" }),
|
|
208
216
|
/* @__PURE__ */ n("div", { children: [
|
|
209
|
-
/* @__PURE__ */ i("label", { children:
|
|
217
|
+
/* @__PURE__ */ i("label", { children: G ? "Book For" : "From" }),
|
|
210
218
|
/* @__PURE__ */ i(
|
|
211
|
-
|
|
219
|
+
L,
|
|
212
220
|
{
|
|
213
221
|
amount: r.cash,
|
|
214
222
|
currency: r.currency,
|
|
215
|
-
position:
|
|
223
|
+
position: R.LEFT
|
|
216
224
|
}
|
|
217
225
|
)
|
|
218
226
|
] }),
|
|
@@ -224,7 +232,7 @@ const Ir = ({
|
|
|
224
232
|
e.stopPropagation(), s == null || s(r);
|
|
225
233
|
},
|
|
226
234
|
children: [
|
|
227
|
-
s && /* @__PURE__ */ i(
|
|
235
|
+
s && /* @__PURE__ */ i(z, {}),
|
|
228
236
|
/* @__PURE__ */ i("p", { children: "Best Value" }),
|
|
229
237
|
s && /* @__PURE__ */ i("span", { children: "Click to learn more" })
|
|
230
238
|
]
|
|
@@ -249,27 +257,27 @@ const Ir = ({
|
|
|
249
257
|
e.stopPropagation(), s == null || s(r);
|
|
250
258
|
},
|
|
251
259
|
children: [
|
|
252
|
-
s && /* @__PURE__ */ i(
|
|
260
|
+
s && /* @__PURE__ */ i(z, {}),
|
|
253
261
|
/* @__PURE__ */ i("p", { children: "Best Value" }),
|
|
254
262
|
s && /* @__PURE__ */ i("span", { children: "Click to learn more" })
|
|
255
263
|
]
|
|
256
264
|
}
|
|
257
265
|
),
|
|
258
|
-
/* @__PURE__ */ i("img", { src:
|
|
266
|
+
/* @__PURE__ */ i("img", { src: j.programLogo }),
|
|
259
267
|
/* @__PURE__ */ n("div", { children: [
|
|
260
|
-
/* @__PURE__ */ i("label", { children:
|
|
268
|
+
/* @__PURE__ */ i("label", { children: Y ? "Book For" : "From" }),
|
|
261
269
|
/* @__PURE__ */ n("p", { children: [
|
|
262
|
-
`${
|
|
263
|
-
!!g && /* @__PURE__ */ n(
|
|
270
|
+
`${dr(r.points)} ${l("miles")}`,
|
|
271
|
+
!!g && /* @__PURE__ */ n(B, { children: [
|
|
264
272
|
" + ",
|
|
265
273
|
/* @__PURE__ */ i(
|
|
266
|
-
|
|
274
|
+
L,
|
|
267
275
|
{
|
|
268
276
|
amount: g.amount,
|
|
269
277
|
currency: g.currency,
|
|
270
278
|
customDisplay: "No fee",
|
|
271
|
-
zeroDisplayOption:
|
|
272
|
-
position:
|
|
279
|
+
zeroDisplayOption: er.CUSTOM,
|
|
280
|
+
position: R.LEFT
|
|
273
281
|
}
|
|
274
282
|
)
|
|
275
283
|
] })
|
|
@@ -280,13 +288,13 @@ const Ir = ({
|
|
|
280
288
|
)
|
|
281
289
|
] })
|
|
282
290
|
] }),
|
|
283
|
-
/* @__PURE__ */ i("div", { className: `flight-details ${
|
|
284
|
-
|
|
291
|
+
/* @__PURE__ */ i("div", { className: `flight-details ${b ? "is-open" : ""}`, children: /* @__PURE__ */ i("div", { className: "inner", children: /* @__PURE__ */ i(
|
|
292
|
+
or,
|
|
285
293
|
{
|
|
286
|
-
itinerary:
|
|
294
|
+
itinerary: I.slices[0].segments,
|
|
287
295
|
origin: p,
|
|
288
296
|
destination: h,
|
|
289
|
-
isMultiDayFlight:
|
|
297
|
+
isMultiDayFlight: Z
|
|
290
298
|
}
|
|
291
299
|
) }) })
|
|
292
300
|
] })
|
|
@@ -294,6 +302,6 @@ const Ir = ({
|
|
|
294
302
|
);
|
|
295
303
|
};
|
|
296
304
|
export {
|
|
297
|
-
|
|
298
|
-
|
|
305
|
+
Mr as F,
|
|
306
|
+
dr as c
|
|
299
307
|
};
|
|
@@ -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-
|
|
4
|
+
import { F as x } from "../../FlightResult-Ci2XCEPV.js";
|
|
5
5
|
import "../../index-7zRjF0bU.js";
|
|
6
6
|
import "../../FlightItinerary-Dy-2zMYt.js";
|
|
7
7
|
import "../../enums-DxmoBOKL.js";
|
package/dist/components/index.js
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import { useAwayzContext as
|
|
2
|
-
import { useMutation as
|
|
1
|
+
import { useAwayzContext as V, awayzClient as _, getBaseUrl as G } from "@odynn/awayz-core";
|
|
2
|
+
import { useMutation as M } from "@tanstack/react-query";
|
|
3
3
|
import "../../moment-BGjjqtLQ.js";
|
|
4
4
|
import "../../arrayExtensions-DFLvtO8l.js";
|
|
5
|
-
import { c as
|
|
5
|
+
import { c as U } from "../../objectUtils-CyIaVmog.js";
|
|
6
6
|
import { E as q } from "../../enums-DxmoBOKL.js";
|
|
7
|
-
import { useState as
|
|
7
|
+
import { useState as j, useRef as X } from "react";
|
|
8
8
|
import { FlightService as D } from "../../services/flights/FlightsService.js";
|
|
9
|
-
import
|
|
9
|
+
import Z from "../../stores/useFlightStore.js";
|
|
10
10
|
import { EFlightType as J, EFlightPaymentType as k } from "../../types/enums.js";
|
|
11
|
-
import { ECabinClass as
|
|
12
|
-
import { mapDataToFlightDetails as
|
|
13
|
-
async function
|
|
11
|
+
import { ECabinClass as ee } from "../../types/ECabinClass.js";
|
|
12
|
+
import { mapDataToFlightDetails as te, groupFlightResults as ne, buildFlightSearchQuery as re } from "../../utils/flightUtils.js";
|
|
13
|
+
async function oe(o, t) {
|
|
14
14
|
const r = o.getReader();
|
|
15
15
|
let n;
|
|
16
16
|
for (; !(n = await r.read()).done; )
|
|
17
17
|
t(n.value);
|
|
18
18
|
}
|
|
19
|
-
function
|
|
19
|
+
function se(o) {
|
|
20
20
|
let t, r, n, s = !1;
|
|
21
|
-
return function(
|
|
22
|
-
t === void 0 ? (t =
|
|
21
|
+
return function(d) {
|
|
22
|
+
t === void 0 ? (t = d, r = 0, n = -1) : t = ie(t, d);
|
|
23
23
|
const u = t.length;
|
|
24
24
|
let a = 0;
|
|
25
25
|
for (; r < u; ) {
|
|
26
26
|
s && (t[r] === 10 && (a = ++r), s = !1);
|
|
27
|
-
let
|
|
28
|
-
for (; r < u &&
|
|
27
|
+
let f = -1;
|
|
28
|
+
for (; r < u && f === -1; ++r)
|
|
29
29
|
switch (t[r]) {
|
|
30
30
|
case 58:
|
|
31
31
|
n === -1 && (n = r - a);
|
|
@@ -33,48 +33,48 @@ function ie(o) {
|
|
|
33
33
|
case 13:
|
|
34
34
|
s = !0;
|
|
35
35
|
case 10:
|
|
36
|
-
|
|
36
|
+
f = r;
|
|
37
37
|
break;
|
|
38
38
|
}
|
|
39
|
-
if (
|
|
39
|
+
if (f === -1)
|
|
40
40
|
break;
|
|
41
|
-
o(t.subarray(a,
|
|
41
|
+
o(t.subarray(a, f), n), a = r, n = -1;
|
|
42
42
|
}
|
|
43
43
|
a === u ? t = void 0 : a !== 0 && (t = t.subarray(a), r -= a);
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
|
-
function
|
|
47
|
-
let n =
|
|
46
|
+
function ae(o, t, r) {
|
|
47
|
+
let n = z();
|
|
48
48
|
const s = new TextDecoder();
|
|
49
|
-
return function(
|
|
50
|
-
if (
|
|
51
|
-
r == null || r(n), n =
|
|
49
|
+
return function(d, u) {
|
|
50
|
+
if (d.length === 0)
|
|
51
|
+
r == null || r(n), n = z();
|
|
52
52
|
else if (u > 0) {
|
|
53
|
-
const a = s.decode(
|
|
53
|
+
const a = s.decode(d.subarray(0, u)), f = u + (d[u + 1] === 32 ? 2 : 1), b = s.decode(d.subarray(f));
|
|
54
54
|
switch (a) {
|
|
55
55
|
case "data":
|
|
56
56
|
n.data = n.data ? n.data + `
|
|
57
|
-
` +
|
|
57
|
+
` + b : b;
|
|
58
58
|
break;
|
|
59
59
|
case "event":
|
|
60
|
-
n.event =
|
|
60
|
+
n.event = b;
|
|
61
61
|
break;
|
|
62
62
|
case "id":
|
|
63
|
-
o(n.id =
|
|
63
|
+
o(n.id = b);
|
|
64
64
|
break;
|
|
65
65
|
case "retry":
|
|
66
|
-
const g = parseInt(
|
|
66
|
+
const g = parseInt(b, 10);
|
|
67
67
|
isNaN(g) || t(n.retry = g);
|
|
68
68
|
break;
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
};
|
|
72
72
|
}
|
|
73
|
-
function
|
|
73
|
+
function ie(o, t) {
|
|
74
74
|
const r = new Uint8Array(o.length + t.length);
|
|
75
75
|
return r.set(o), r.set(t, o.length), r;
|
|
76
76
|
}
|
|
77
|
-
function
|
|
77
|
+
function z() {
|
|
78
78
|
return {
|
|
79
79
|
data: "",
|
|
80
80
|
event: "",
|
|
@@ -82,7 +82,7 @@ function U() {
|
|
|
82
82
|
retry: void 0
|
|
83
83
|
};
|
|
84
84
|
}
|
|
85
|
-
var
|
|
85
|
+
var ue = function(o, t) {
|
|
86
86
|
var r = {};
|
|
87
87
|
for (var n in o) Object.prototype.hasOwnProperty.call(o, n) && t.indexOf(n) < 0 && (r[n] = o[n]);
|
|
88
88
|
if (o != null && typeof Object.getOwnPropertySymbols == "function")
|
|
@@ -90,97 +90,95 @@ var le = function(o, t) {
|
|
|
90
90
|
t.indexOf(n[s]) < 0 && Object.prototype.propertyIsEnumerable.call(o, n[s]) && (r[n[s]] = o[n[s]]);
|
|
91
91
|
return r;
|
|
92
92
|
};
|
|
93
|
-
const
|
|
94
|
-
function
|
|
95
|
-
var { signal: r, headers: n, onopen: s, onmessage:
|
|
93
|
+
const K = "text/event-stream", ce = 1e3, B = "last-event-id";
|
|
94
|
+
function le(o, t) {
|
|
95
|
+
var { signal: r, headers: n, onopen: s, onmessage: v, onclose: d, onerror: u, openWhenHidden: a, fetch: f } = t, b = ue(t, ["signal", "headers", "onopen", "onmessage", "onclose", "onerror", "openWhenHidden", "fetch"]);
|
|
96
96
|
return new Promise((g, S) => {
|
|
97
97
|
const p = Object.assign({}, n);
|
|
98
|
-
p.accept || (p.accept =
|
|
98
|
+
p.accept || (p.accept = K);
|
|
99
99
|
let y;
|
|
100
|
-
function
|
|
101
|
-
y.abort(), document.hidden ||
|
|
100
|
+
function O() {
|
|
101
|
+
y.abort(), document.hidden || I();
|
|
102
102
|
}
|
|
103
|
-
a || document.addEventListener("visibilitychange",
|
|
104
|
-
let F =
|
|
103
|
+
a || document.addEventListener("visibilitychange", O);
|
|
104
|
+
let F = ce, C = 0;
|
|
105
105
|
function T() {
|
|
106
|
-
document.removeEventListener("visibilitychange",
|
|
106
|
+
document.removeEventListener("visibilitychange", O), window.clearTimeout(C), y.abort();
|
|
107
107
|
}
|
|
108
108
|
r == null || r.addEventListener("abort", () => {
|
|
109
109
|
T(), g();
|
|
110
110
|
});
|
|
111
|
-
const
|
|
112
|
-
async function
|
|
113
|
-
var
|
|
111
|
+
const P = f ?? window.fetch, H = s ?? de;
|
|
112
|
+
async function I() {
|
|
113
|
+
var R;
|
|
114
114
|
y = new AbortController();
|
|
115
115
|
try {
|
|
116
|
-
const
|
|
117
|
-
await
|
|
118
|
-
h ? p[
|
|
116
|
+
const E = await P(o, Object.assign(Object.assign({}, b), { headers: p, signal: y.signal }));
|
|
117
|
+
await H(E), await oe(E.body, se(ae((h) => {
|
|
118
|
+
h ? p[B] = h : delete p[B];
|
|
119
119
|
}, (h) => {
|
|
120
120
|
F = h;
|
|
121
|
-
},
|
|
122
|
-
} catch (
|
|
121
|
+
}, v))), d == null || d(), T(), g();
|
|
122
|
+
} catch (E) {
|
|
123
123
|
if (!y.signal.aborted)
|
|
124
124
|
try {
|
|
125
|
-
const h = (
|
|
126
|
-
window.clearTimeout(
|
|
125
|
+
const h = (R = u == null ? void 0 : u(E)) !== null && R !== void 0 ? R : F;
|
|
126
|
+
window.clearTimeout(C), C = window.setTimeout(I, h);
|
|
127
127
|
} catch (h) {
|
|
128
128
|
T(), S(h);
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
|
-
|
|
132
|
+
I();
|
|
133
133
|
});
|
|
134
134
|
}
|
|
135
|
-
function
|
|
135
|
+
function de(o) {
|
|
136
136
|
const t = o.headers.get("content-type");
|
|
137
|
-
if (!(t != null && t.startsWith(
|
|
138
|
-
throw new Error(`Expected content-type to be ${
|
|
137
|
+
if (!(t != null && t.startsWith(K)))
|
|
138
|
+
throw new Error(`Expected content-type to be ${K}, Actual: ${t}`);
|
|
139
139
|
}
|
|
140
|
-
const
|
|
141
|
-
let
|
|
142
|
-
const
|
|
140
|
+
const Y = 1, L = ee.ECONOMY;
|
|
141
|
+
let x = new AbortController();
|
|
142
|
+
const fe = 3 * 60 * 1e3, $ = (o) => {
|
|
143
143
|
if (!o.origin || !o.destination)
|
|
144
144
|
throw new Error("Origin and destination are required.");
|
|
145
145
|
if (!o.departureDate)
|
|
146
146
|
throw new Error("Departure date is required.");
|
|
147
147
|
if (o.flightType === J.ROUND_TRIP && !o.returnDate)
|
|
148
148
|
throw new Error("Return date is required for round-trip flights.");
|
|
149
|
-
},
|
|
150
|
-
const { token: o, config: t } =
|
|
151
|
-
inboundResults:
|
|
152
|
-
outboundResults:
|
|
149
|
+
}, Fe = () => {
|
|
150
|
+
const { token: o, config: t } = V(), [r, n] = j(""), [s, v] = j([]), [d, u] = j(!1), a = X(null), {
|
|
151
|
+
inboundResults: f,
|
|
152
|
+
outboundResults: b,
|
|
153
153
|
setInboundResults: g,
|
|
154
154
|
setOutboundResults: S,
|
|
155
155
|
partialOfferRequestId: p,
|
|
156
|
-
setPartialOfferRequestId: y
|
|
157
|
-
|
|
158
|
-
setCabinClass: F
|
|
159
|
-
} = te(), v = ({
|
|
156
|
+
setPartialOfferRequestId: y
|
|
157
|
+
} = Z(), O = ({
|
|
160
158
|
data: e,
|
|
161
|
-
inbound:
|
|
159
|
+
inbound: l
|
|
162
160
|
}) => {
|
|
163
|
-
const
|
|
164
|
-
return (
|
|
161
|
+
const c = te(e);
|
|
162
|
+
return (l ? g : S)(ne(c)), c;
|
|
165
163
|
}, {
|
|
166
|
-
mutate:
|
|
167
|
-
status:
|
|
168
|
-
error:
|
|
169
|
-
} =
|
|
164
|
+
mutate: F,
|
|
165
|
+
status: C,
|
|
166
|
+
error: T
|
|
167
|
+
} = M({
|
|
170
168
|
mutationFn: async (e) => {
|
|
171
169
|
$(e);
|
|
172
|
-
const
|
|
170
|
+
const c = {
|
|
173
171
|
passengers: Array.from(
|
|
174
|
-
{ length: e.passengers ??
|
|
172
|
+
{ length: e.passengers ?? Y },
|
|
175
173
|
() => ({ type: "adult" })
|
|
176
174
|
),
|
|
177
175
|
origin: e.origin || "",
|
|
178
176
|
destination: e.destination || "",
|
|
179
|
-
cabin_class: e.cabinClass ??
|
|
177
|
+
cabin_class: e.cabinClass ?? L
|
|
180
178
|
};
|
|
181
179
|
if (e.flightType === J.ONE_WAY) {
|
|
182
180
|
const i = await D.cashOnlySearch({
|
|
183
|
-
...
|
|
181
|
+
...c,
|
|
184
182
|
departure_date: e.departureDate
|
|
185
183
|
});
|
|
186
184
|
return {
|
|
@@ -189,7 +187,7 @@ const he = 3 * 60 * 1e3, $ = (o) => {
|
|
|
189
187
|
};
|
|
190
188
|
} else {
|
|
191
189
|
const i = await D.roundTripOutboundSearch({
|
|
192
|
-
...
|
|
190
|
+
...c,
|
|
193
191
|
departure_date: e.departureDate,
|
|
194
192
|
return_date: e.returnDate
|
|
195
193
|
});
|
|
@@ -201,12 +199,12 @@ const he = 3 * 60 * 1e3, $ = (o) => {
|
|
|
201
199
|
}
|
|
202
200
|
},
|
|
203
201
|
onSuccess: (e) => {
|
|
204
|
-
const { success:
|
|
205
|
-
if (!
|
|
202
|
+
const { success: l, data: c, partialOfferRequestId: i } = e;
|
|
203
|
+
if (!l) {
|
|
206
204
|
console.log("oh lol, it didn't work");
|
|
207
205
|
return;
|
|
208
206
|
}
|
|
209
|
-
|
|
207
|
+
O({ data: c }), i && y(i);
|
|
210
208
|
},
|
|
211
209
|
onError: (e) => {
|
|
212
210
|
console.error("Error in outbound flight search:", e);
|
|
@@ -215,23 +213,26 @@ const he = 3 * 60 * 1e3, $ = (o) => {
|
|
|
215
213
|
_.invalidateQueries({ queryKey: [q.SEARCH_LIMIT] });
|
|
216
214
|
}
|
|
217
215
|
}), {
|
|
218
|
-
mutate:
|
|
219
|
-
status:
|
|
220
|
-
error:
|
|
221
|
-
} =
|
|
222
|
-
mutationFn: async (
|
|
216
|
+
mutate: P,
|
|
217
|
+
status: H,
|
|
218
|
+
error: I
|
|
219
|
+
} = M({
|
|
220
|
+
mutationFn: async ({
|
|
221
|
+
outboundOfferId: e,
|
|
222
|
+
cabinClass: l
|
|
223
|
+
}) => {
|
|
223
224
|
if (!p)
|
|
224
225
|
throw new Error("No partialOfferRequestId found for inbound search.");
|
|
225
226
|
return n(e), await D.roundTripInboundSearch({
|
|
226
227
|
outboundOfferId: e,
|
|
227
228
|
outboundOfferRequestId: p,
|
|
228
|
-
cabinClass:
|
|
229
|
+
cabinClass: l || L
|
|
229
230
|
});
|
|
230
231
|
},
|
|
231
232
|
onSuccess: (e) => {
|
|
232
|
-
const { success:
|
|
233
|
-
|
|
234
|
-
data:
|
|
233
|
+
const { success: l, data: c } = e;
|
|
234
|
+
l && O({
|
|
235
|
+
data: c.offers,
|
|
235
236
|
inbound: !0
|
|
236
237
|
});
|
|
237
238
|
},
|
|
@@ -242,25 +243,28 @@ const he = 3 * 60 * 1e3, $ = (o) => {
|
|
|
242
243
|
_.invalidateQueries({ queryKey: [q.SEARCH_LIMIT] });
|
|
243
244
|
}
|
|
244
245
|
}), {
|
|
245
|
-
mutate:
|
|
246
|
-
status:
|
|
247
|
-
error:
|
|
248
|
-
} =
|
|
249
|
-
mutationFn: async (
|
|
246
|
+
mutate: R,
|
|
247
|
+
status: E,
|
|
248
|
+
error: h
|
|
249
|
+
} = M({
|
|
250
|
+
mutationFn: async ({
|
|
251
|
+
inboundOfferId: e,
|
|
252
|
+
cabinClass: l
|
|
253
|
+
}) => {
|
|
250
254
|
if (!p)
|
|
251
255
|
throw new Error("No partialOfferRequestId found for round-trip fares.");
|
|
252
256
|
return await D.getRoundTripFares({
|
|
253
257
|
outboundOfferId: r,
|
|
254
258
|
outboundOfferRequestId: p,
|
|
255
259
|
inboundOfferId: e,
|
|
256
|
-
cabinClass:
|
|
260
|
+
cabinClass: l || L
|
|
257
261
|
});
|
|
258
262
|
},
|
|
259
263
|
onSuccess: (e) => {
|
|
260
|
-
const { success:
|
|
261
|
-
if (!
|
|
262
|
-
const i =
|
|
263
|
-
|
|
264
|
+
const { success: l, data: c } = e;
|
|
265
|
+
if (!l) return;
|
|
266
|
+
const i = c.offers;
|
|
267
|
+
v(U(i));
|
|
264
268
|
},
|
|
265
269
|
onError: (e) => {
|
|
266
270
|
console.error("Error in round-trip fare search:", e);
|
|
@@ -268,40 +272,40 @@ const he = 3 * 60 * 1e3, $ = (o) => {
|
|
|
268
272
|
onSettled: () => {
|
|
269
273
|
_.invalidateQueries({ queryKey: [q.SEARCH_LIMIT] });
|
|
270
274
|
}
|
|
271
|
-
}),
|
|
272
|
-
var
|
|
275
|
+
}), Q = async (e) => {
|
|
276
|
+
var W;
|
|
273
277
|
u(!0);
|
|
274
|
-
const
|
|
278
|
+
const l = e.paymentType === k.CASH_AND_MILES ? ['"cash"', '"points"'] : ['"points"'], c = re({
|
|
275
279
|
originCode: e.origin,
|
|
276
280
|
destinationCode: e.destination,
|
|
277
281
|
departureDate: e.departureDate,
|
|
278
|
-
cabinClass: e.cabinClass ??
|
|
279
|
-
passengerCount: e.passengers ??
|
|
280
|
-
paymentType:
|
|
282
|
+
cabinClass: e.cabinClass ?? L,
|
|
283
|
+
passengerCount: e.passengers ?? Y,
|
|
284
|
+
paymentType: l
|
|
281
285
|
});
|
|
282
|
-
let i = [],
|
|
283
|
-
|
|
286
|
+
let i = [], N = 0;
|
|
287
|
+
x = new AbortController(), a.current = setTimeout(() => {
|
|
284
288
|
w();
|
|
285
|
-
}, (((
|
|
289
|
+
}, (((W = t == null ? void 0 : t.flightsConfig) == null ? void 0 : W.streamTimeoutTotalSeconds) ?? fe) * 1e3), le(G() + c, {
|
|
286
290
|
headers: {
|
|
287
291
|
"Content-Type": "application/json",
|
|
288
292
|
Authorization: o ?? "",
|
|
289
293
|
"client-id": (t == null ? void 0 : t.clientId) ?? ""
|
|
290
294
|
},
|
|
291
295
|
openWhenHidden: !0,
|
|
292
|
-
signal:
|
|
296
|
+
signal: x.signal,
|
|
293
297
|
onmessage(A) {
|
|
294
298
|
try {
|
|
295
|
-
const
|
|
296
|
-
if (
|
|
299
|
+
const m = U(JSON.parse(A.data));
|
|
300
|
+
if (m.success === !1)
|
|
297
301
|
return;
|
|
298
|
-
if (
|
|
302
|
+
if (m.close === !0) {
|
|
299
303
|
w();
|
|
300
304
|
return;
|
|
301
305
|
}
|
|
302
|
-
|
|
303
|
-
} catch (
|
|
304
|
-
console.error("Error parsing message:",
|
|
306
|
+
m.status === 200 && m.flights && m.flights.length > 0 && (N = 0, i = [...i, ...m.flights], O({ data: i })), m.ping && (N++, N >= t.flightsConfig.streamTimeoutPingCount && w());
|
|
307
|
+
} catch (m) {
|
|
308
|
+
console.error("Error parsing message:", m), w();
|
|
305
309
|
}
|
|
306
310
|
},
|
|
307
311
|
onerror(A) {
|
|
@@ -313,7 +317,7 @@ const he = 3 * 60 * 1e3, $ = (o) => {
|
|
|
313
317
|
keepalive: !1
|
|
314
318
|
});
|
|
315
319
|
}, w = () => {
|
|
316
|
-
|
|
320
|
+
x.abort(), a.current && (clearTimeout(a.current), a.current = null), u(!1), _.invalidateQueries({ queryKey: [q.SEARCH_LIMIT] });
|
|
317
321
|
};
|
|
318
322
|
return {
|
|
319
323
|
/**
|
|
@@ -321,19 +325,19 @@ const he = 3 * 60 * 1e3, $ = (o) => {
|
|
|
321
325
|
* @type {boolean}
|
|
322
326
|
* @default false
|
|
323
327
|
*/
|
|
324
|
-
loading:
|
|
328
|
+
loading: C === "pending" || H === "pending" || d,
|
|
325
329
|
/**
|
|
326
330
|
* Loading status for fares
|
|
327
331
|
* @type {boolean}
|
|
328
332
|
* @default false
|
|
329
333
|
*/
|
|
330
|
-
loadingFares:
|
|
331
|
-
outboundError:
|
|
332
|
-
inboundError:
|
|
333
|
-
roundTripFaresError:
|
|
334
|
+
loadingFares: E === "pending",
|
|
335
|
+
outboundError: T,
|
|
336
|
+
inboundError: I,
|
|
337
|
+
roundTripFaresError: h,
|
|
334
338
|
// Results
|
|
335
|
-
outboundResults:
|
|
336
|
-
inboundResults:
|
|
339
|
+
outboundResults: b,
|
|
340
|
+
inboundResults: f,
|
|
337
341
|
roundTripFares: s,
|
|
338
342
|
// Mutation triggers
|
|
339
343
|
/**
|
|
@@ -345,13 +349,13 @@ const he = 3 * 60 * 1e3, $ = (o) => {
|
|
|
345
349
|
searchOutboundFlights: async (e) => {
|
|
346
350
|
switch ($(e), S([]), w(), e.paymentType) {
|
|
347
351
|
case k.CASH_AND_MILES:
|
|
348
|
-
|
|
352
|
+
Q(e);
|
|
349
353
|
break;
|
|
350
354
|
case k.CASH:
|
|
351
|
-
|
|
355
|
+
F(e);
|
|
352
356
|
break;
|
|
353
357
|
case k.MILES:
|
|
354
|
-
|
|
358
|
+
Q(e);
|
|
355
359
|
break;
|
|
356
360
|
}
|
|
357
361
|
},
|
|
@@ -359,16 +363,16 @@ const he = 3 * 60 * 1e3, $ = (o) => {
|
|
|
359
363
|
* Used to search for inbound flights after selecting an outbound flight
|
|
360
364
|
* @type {function}
|
|
361
365
|
*
|
|
362
|
-
* @param {string}
|
|
366
|
+
* @param {{ outboundOfferId: string; cabinClass: ECabinClass }} args - The search arguments
|
|
363
367
|
*/
|
|
364
|
-
searchInboundFlights:
|
|
368
|
+
searchInboundFlights: P,
|
|
365
369
|
/**
|
|
366
370
|
* Used to get round-trip fares after selecting both outbound and inbound flights
|
|
367
371
|
* @type {function}
|
|
368
372
|
*
|
|
369
|
-
* @param {string}
|
|
373
|
+
* @param {{ inboundOfferId: string; cabinClass: ECabinClass }} args - The fare search arguments
|
|
370
374
|
*/
|
|
371
|
-
getRoundTripFares:
|
|
375
|
+
getRoundTripFares: R,
|
|
372
376
|
/**
|
|
373
377
|
* Resets the flight search state, clearing all results and selections
|
|
374
378
|
* @type {function}
|
|
@@ -376,10 +380,10 @@ const he = 3 * 60 * 1e3, $ = (o) => {
|
|
|
376
380
|
* @returns {void}
|
|
377
381
|
*/
|
|
378
382
|
reset: () => {
|
|
379
|
-
w(), S([]), g([]),
|
|
383
|
+
w(), S([]), g([]), v([]), y(""), n("");
|
|
380
384
|
}
|
|
381
385
|
};
|
|
382
386
|
};
|
|
383
387
|
export {
|
|
384
|
-
|
|
388
|
+
Fe as useFlightSearch
|
|
385
389
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ECabinClass } from '../../types/ECabinClass';
|
|
1
2
|
import { IFlightOffer, ISearchFlightArgs } from './useFlightSearch.types';
|
|
2
3
|
/**
|
|
3
4
|
* Flights hook for searching outbound, inbound, and round-trip flights
|
|
@@ -33,16 +34,22 @@ export declare const useFlightSearch: () => {
|
|
|
33
34
|
* Used to search for inbound flights after selecting an outbound flight
|
|
34
35
|
* @type {function}
|
|
35
36
|
*
|
|
36
|
-
* @param {string}
|
|
37
|
+
* @param {{ outboundOfferId: string; cabinClass: ECabinClass }} args - The search arguments
|
|
37
38
|
*/
|
|
38
|
-
searchInboundFlights: import('@tanstack/react-query').UseMutateFunction<any, Error,
|
|
39
|
+
searchInboundFlights: import('@tanstack/react-query').UseMutateFunction<any, Error, {
|
|
40
|
+
outboundOfferId: string;
|
|
41
|
+
cabinClass: ECabinClass;
|
|
42
|
+
}, unknown>;
|
|
39
43
|
/**
|
|
40
44
|
* Used to get round-trip fares after selecting both outbound and inbound flights
|
|
41
45
|
* @type {function}
|
|
42
46
|
*
|
|
43
|
-
* @param {string}
|
|
47
|
+
* @param {{ inboundOfferId: string; cabinClass: ECabinClass }} args - The fare search arguments
|
|
44
48
|
*/
|
|
45
|
-
getRoundTripFares: import('@tanstack/react-query').UseMutateFunction<any, Error,
|
|
49
|
+
getRoundTripFares: import('@tanstack/react-query').UseMutateFunction<any, Error, {
|
|
50
|
+
inboundOfferId: string;
|
|
51
|
+
cabinClass: ECabinClass;
|
|
52
|
+
}, unknown>;
|
|
46
53
|
/**
|
|
47
54
|
* Resets the flight search state, clearing all results and selections
|
|
48
55
|
* @type {function}
|
|
@@ -6,8 +6,6 @@ interface IFlightStore {
|
|
|
6
6
|
setInboundResults: (inboundResults: IFlightResult[]) => void;
|
|
7
7
|
partialOfferRequestId: string;
|
|
8
8
|
setPartialOfferRequestId: (partialOfferRequestId: string) => void;
|
|
9
|
-
cabinClass: string;
|
|
10
|
-
setCabinClass: (cabinClass: string) => void;
|
|
11
9
|
}
|
|
12
10
|
declare const useFlightStore: import('zustand').UseBoundStore<import('zustand').StoreApi<IFlightStore>>;
|
|
13
11
|
export default useFlightStore;
|
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-
|
|
4
|
+
import { F as f, c as l } from "./FlightResult-Ci2XCEPV.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,22 +1,22 @@
|
|
|
1
|
-
import
|
|
1
|
+
import a from "react";
|
|
2
2
|
const l = (e) => {
|
|
3
3
|
let t;
|
|
4
|
-
const s = /* @__PURE__ */ new Set(), u = (n,
|
|
4
|
+
const s = /* @__PURE__ */ new Set(), u = (n, r) => {
|
|
5
5
|
const o = typeof n == "function" ? n(t) : n;
|
|
6
6
|
if (!Object.is(o, t)) {
|
|
7
7
|
const d = t;
|
|
8
|
-
t =
|
|
8
|
+
t = r ?? (typeof o != "object" || o === null) ? o : Object.assign({}, t, o), s.forEach((f) => f(t, d));
|
|
9
9
|
}
|
|
10
10
|
}, c = () => t, i = { setState: u, getState: c, getInitialState: () => S, subscribe: (n) => (s.add(n), () => s.delete(n)) }, S = t = e(u, c, i);
|
|
11
11
|
return i;
|
|
12
12
|
}, g = (e) => e ? l(e) : l, I = (e) => e;
|
|
13
13
|
function R(e, t = I) {
|
|
14
|
-
const s =
|
|
14
|
+
const s = a.useSyncExternalStore(
|
|
15
15
|
e.subscribe,
|
|
16
16
|
() => t(e.getState()),
|
|
17
17
|
() => t(e.getInitialState())
|
|
18
18
|
);
|
|
19
|
-
return
|
|
19
|
+
return a.useDebugValue(s), s;
|
|
20
20
|
}
|
|
21
21
|
const b = (e) => {
|
|
22
22
|
const t = g(e), s = (u) => R(t, u);
|
|
@@ -27,9 +27,7 @@ const b = (e) => {
|
|
|
27
27
|
setOutboundResults: (t) => e({ outboundResults: t }),
|
|
28
28
|
setInboundResults: (t) => e({ inboundResults: t }),
|
|
29
29
|
partialOfferRequestId: "",
|
|
30
|
-
setPartialOfferRequestId: (t) => e({ partialOfferRequestId: t })
|
|
31
|
-
cabinClass: "",
|
|
32
|
-
setCabinClass: (t) => e({ cabinClass: t })
|
|
30
|
+
setPartialOfferRequestId: (t) => e({ partialOfferRequestId: t })
|
|
33
31
|
}));
|
|
34
32
|
export {
|
|
35
33
|
y as default
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { d as
|
|
1
|
+
import { defaultAwayzConfig as j, awayzClient as Q } from "@odynn/awayz-core";
|
|
2
|
+
import { d as q, D as x } from "../index-7zRjF0bU.js";
|
|
3
3
|
import "../arrayExtensions-DFLvtO8l.js";
|
|
4
4
|
import "react";
|
|
5
5
|
import { h as p } from "../moment-BGjjqtLQ.js";
|
|
6
|
-
import { mapBaggageType as
|
|
7
|
-
import { WalletService as
|
|
8
|
-
import { ERewardProgramCategories as
|
|
9
|
-
const
|
|
10
|
-
var
|
|
6
|
+
import { mapBaggageType as H } from "../hooks/useFlightSearch/useFlightSearch.types.js";
|
|
7
|
+
import { WalletService as W } from "../services/wallet/WalletService.js";
|
|
8
|
+
import { ERewardProgramCategories as J } from "../services/wallet/WalletService.types.js";
|
|
9
|
+
const re = (t) => t == null ? void 0 : t.map((e) => {
|
|
10
|
+
var i, l, c, n, s, a, r, o, g, m, u, d, y, b, w, F, L, D, A, h, P, T, O, k, I, R, v, _, z, E, M, G, 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: ((
|
|
17
|
-
country: ((n = e.slices[0].segments[0].origin) == null ? void 0 : n.iataCountryCode) || ((
|
|
16
|
+
city: ((i = e.slices[0].segments[0].origin) == null ? void 0 : i.cityName) || ((c = (l = e.slices[0].segments[0].origin) == null ? void 0 : l.city) == null ? void 0 : c.name),
|
|
17
|
+
country: ((n = e.slices[0].segments[0].origin) == null ? void 0 : n.iataCountryCode) || ((a = (s = e.slices[0].segments[0].origin) == null ? void 0 : s.city) == null ? void 0 : a.iataCountryCode),
|
|
18
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
20
|
latitude: (u = (m = e.slices[0].segments[0].origin) == null ? void 0 : m.city) == null ? void 0 : u.latitude,
|
|
@@ -22,12 +22,12 @@ const ne = (t) => t == null ? void 0 : t.map((e) => {
|
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
24
|
destination: {
|
|
25
|
-
city: ((w = (b = e.slices[0].segments.getLast()) == null ? void 0 : b.destination) == null ? void 0 : w.cityName) || ((
|
|
26
|
-
country: ((
|
|
27
|
-
airportCode: ((
|
|
25
|
+
city: ((w = (b = e.slices[0].segments.getLast()) == null ? void 0 : b.destination) == null ? void 0 : w.cityName) || ((D = (L = (F = e.slices[0].segments.getLast()) == null ? void 0 : F.destination) == null ? void 0 : L.city) == null ? void 0 : D.name),
|
|
26
|
+
country: ((h = (A = e.slices[0].segments.getLast()) == null ? void 0 : A.destination) == null ? void 0 : h.iataCountryCode) || ((O = (T = (P = e.slices[0].segments.getLast()) == null ? void 0 : P.destination) == null ? void 0 : T.city) == null ? void 0 : O.iataCountryCode),
|
|
27
|
+
airportCode: ((I = (k = e.slices[0].segments.getLast()) == null ? void 0 : k.destination) == null ? void 0 : I.iataCityCode) || ((_ = (v = (R = e.slices[0].segments.getLast()) == null ? void 0 : R.destination) == null ? void 0 : v.city) == null ? void 0 : _.iataCode),
|
|
28
28
|
coordinates: {
|
|
29
|
-
latitude: (M = (
|
|
30
|
-
longitude: ($ = (Z = (
|
|
29
|
+
latitude: (M = (E = (z = e.slices[0].segments.getLast()) == null ? void 0 : z.destination) == null ? void 0 : E.city) == null ? void 0 : M.latitude,
|
|
30
|
+
longitude: ($ = (Z = (G = e.slices[0].segments.getLast()) == null ? void 0 : G.destination) == null ? void 0 : Z.city) == null ? void 0 : $.longitude
|
|
31
31
|
}
|
|
32
32
|
},
|
|
33
33
|
airline: e.owner.name,
|
|
@@ -47,7 +47,7 @@ const ne = (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:
|
|
50
|
+
durationMinutes: q({
|
|
51
51
|
departureTime: p(e.slices[0].segments[0].departingAt),
|
|
52
52
|
arrivalTime: p(e.slices[0].segments.getLast().arrivingAt),
|
|
53
53
|
originTimeZone: e.slices[0].segments[0].origin.timeZone,
|
|
@@ -58,32 +58,32 @@ const ne = (t) => t == null ? void 0 : t.map((e) => {
|
|
|
58
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
60
|
}), K = (t) => {
|
|
61
|
-
const e = t.operatingCarrierFlightNumber ? t.operatingCarrier : t.marketingCarrier,
|
|
62
|
-
return e.iataCode + " " +
|
|
63
|
-
},
|
|
61
|
+
const e = t.operatingCarrierFlightNumber ? t.operatingCarrier : t.marketingCarrier, i = t.operatingCarrierFlightNumber ?? t.marketingCarrierFlightNumber;
|
|
62
|
+
return e.iataCode + " " + X(i);
|
|
63
|
+
}, oe = ({
|
|
64
64
|
originCode: t,
|
|
65
65
|
destinationCode: e,
|
|
66
|
-
departureDate:
|
|
66
|
+
departureDate: i,
|
|
67
67
|
cabinClass: l,
|
|
68
68
|
passengerCount: c,
|
|
69
69
|
paymentType: n
|
|
70
70
|
}) => {
|
|
71
71
|
let s = "/flights/search/one-way/points-cash?";
|
|
72
|
-
return s += `origin=${t}`, s += `&destination=${e}`, s += `&departure_date=${
|
|
73
|
-
}, V = (t) => t.flightDetails.slices[0].segments.map((
|
|
72
|
+
return s += `origin=${t}`, s += `&destination=${e}`, s += `&departure_date=${i}`, s += `&cabin_class=${l}`, s += `&adults=${c}`, s += `&cash_or_points=[${n}]`, s;
|
|
73
|
+
}, V = (t) => t.flightDetails.slices[0].segments.map((i) => K(i)).join("_"), ce = (t) => {
|
|
74
74
|
const e = {};
|
|
75
75
|
t.forEach((s) => {
|
|
76
|
-
const
|
|
77
|
-
if (e[
|
|
76
|
+
const a = V(s);
|
|
77
|
+
if (e[a]) {
|
|
78
78
|
const r = U(s);
|
|
79
|
-
e[
|
|
80
|
-
const { lowestCash: o, currency: g, lowestPoints: m } =
|
|
81
|
-
e[
|
|
79
|
+
e[a].flight.paymentOptions.push(r);
|
|
80
|
+
const { lowestCash: o, currency: g, lowestPoints: m } = B(
|
|
81
|
+
e[a].flight.paymentOptions
|
|
82
82
|
);
|
|
83
|
-
e[
|
|
83
|
+
e[a].flight.points = m, e[a].flight.cash = o, g && (e[a].flight.currency = g);
|
|
84
84
|
} else {
|
|
85
|
-
const { origin: r, destination: o } = s, g = [U(s)], m =
|
|
86
|
-
e[
|
|
85
|
+
const { origin: r, destination: o } = s, g = [U(s)], m = B(g);
|
|
86
|
+
e[a] = {
|
|
87
87
|
programs: [],
|
|
88
88
|
flight: {
|
|
89
89
|
id: s.awayzGroupId,
|
|
@@ -109,10 +109,10 @@ const ne = (t) => t == null ? void 0 : t.map((e) => {
|
|
|
109
109
|
numberOfStops: s.numberOfStops,
|
|
110
110
|
departureTime: s.departureTime,
|
|
111
111
|
arrivalTime: s.arrivalTime,
|
|
112
|
-
awayzGroupId:
|
|
112
|
+
awayzGroupId: a,
|
|
113
113
|
duration: s.duration,
|
|
114
114
|
airlineProgram: s.airlineProgram,
|
|
115
|
-
durationMinutes:
|
|
115
|
+
durationMinutes: q({
|
|
116
116
|
departureTime: p(
|
|
117
117
|
s.flightDetails.slices[0].segments[0].departingAt
|
|
118
118
|
),
|
|
@@ -132,11 +132,11 @@ const ne = (t) => t == null ? void 0 : t.map((e) => {
|
|
|
132
132
|
}
|
|
133
133
|
};
|
|
134
134
|
}
|
|
135
|
-
s.airlineProgram && !e[
|
|
135
|
+
s.airlineProgram && !e[a].programs.includes(s.airlineProgram) && e[a].programs.push(s.airlineProgram);
|
|
136
136
|
});
|
|
137
|
-
const
|
|
137
|
+
const i = [];
|
|
138
138
|
Object.values(e).forEach((s) => {
|
|
139
|
-
const
|
|
139
|
+
const a = s.flight.paymentOptions.filter((r) => r.cash > 0).reduce(
|
|
140
140
|
(r, o) => o.cash < r.cash ? o : r,
|
|
141
141
|
{ cash: 1 / 0, carrier: { name: "", iataCode: "" } }
|
|
142
142
|
);
|
|
@@ -144,23 +144,23 @@ const ne = (t) => t == null ? void 0 : t.map((e) => {
|
|
|
144
144
|
const o = s.flight.paymentOptions.filter(
|
|
145
145
|
(m) => m.program === r && m.points > 0
|
|
146
146
|
), g = o.length > 0 ? Math.min(...o.map((m) => m.points)) : -1;
|
|
147
|
-
|
|
147
|
+
i.push({
|
|
148
148
|
...s.flight,
|
|
149
|
-
airline:
|
|
150
|
-
airlineLogo: C(
|
|
149
|
+
airline: a.carrier.name,
|
|
150
|
+
airlineLogo: C(a.carrier.iataCode),
|
|
151
151
|
airlineProgram: r,
|
|
152
|
-
cash:
|
|
152
|
+
cash: a.cash !== 1 / 0 ? a.cash : -1,
|
|
153
153
|
points: g
|
|
154
154
|
});
|
|
155
|
-
}) :
|
|
155
|
+
}) : i.push({
|
|
156
156
|
...s.flight,
|
|
157
|
-
airline:
|
|
158
|
-
airlineLogo: C(
|
|
159
|
-
cash:
|
|
157
|
+
airline: a.carrier.name,
|
|
158
|
+
airlineLogo: C(a.carrier.iataCode),
|
|
159
|
+
cash: a.cash !== 1 / 0 ? a.cash : -1
|
|
160
160
|
});
|
|
161
161
|
});
|
|
162
|
-
const { cashlessResults: l, otherResults: c } =
|
|
163
|
-
(s,
|
|
162
|
+
const { cashlessResults: l, otherResults: c } = i.reduce(
|
|
163
|
+
(s, a) => (a.cash <= 0 && a.points > 0 ? s.cashlessResults.push(a) : a.cash > 0 && s.otherResults.push(a), s),
|
|
164
164
|
{ cashlessResults: [], otherResults: [] }
|
|
165
165
|
), n = c;
|
|
166
166
|
return l.forEach((s) => {
|
|
@@ -168,42 +168,42 @@ const ne = (t) => t == null ? void 0 : t.map((e) => {
|
|
|
168
168
|
(r) => r.awayzGroupId === s.awayzGroupId
|
|
169
169
|
) || n.push(s);
|
|
170
170
|
}), n;
|
|
171
|
-
},
|
|
172
|
-
categoryLogo:
|
|
173
|
-
programLogo:
|
|
171
|
+
}, X = (t) => t ? t.replace(/^0+/, "") : "", me = (t) => `https://assets.duffel.com/img/airlines/for-light-background/full-color-logo/${t}.svg`, C = (t) => `${x}${t}.svg`, N = j.logoFallbackImageUrl, S = {
|
|
172
|
+
categoryLogo: N,
|
|
173
|
+
programLogo: N,
|
|
174
174
|
awayzActive: [],
|
|
175
175
|
mainProgram: "Unknown",
|
|
176
176
|
displayProgram: "Unknown",
|
|
177
177
|
id: "Unknown",
|
|
178
178
|
totalAccumulatedPoints: 0,
|
|
179
|
-
category:
|
|
179
|
+
category: J.Airline,
|
|
180
180
|
colour: "#fff",
|
|
181
181
|
// Using App Foreground Colour
|
|
182
182
|
url: "https://www.odynn.com"
|
|
183
|
-
},
|
|
184
|
-
const { airlines: e } = await
|
|
183
|
+
}, le = async (t) => {
|
|
184
|
+
const { airlines: e } = await Q.ensureQueryData({
|
|
185
185
|
queryKey: ["walletAwards"],
|
|
186
|
-
queryFn:
|
|
186
|
+
queryFn: W.getAwards,
|
|
187
187
|
staleTime: 864e5
|
|
188
188
|
// 24 hours
|
|
189
189
|
});
|
|
190
|
-
let
|
|
190
|
+
let i = e.find(
|
|
191
191
|
(l) => {
|
|
192
|
-
var c, n, s,
|
|
193
|
-
return ((n = (c = l.mainProgram) == null ? void 0 : c.toLowerCase()) == null ? void 0 : n.includes(t == null ? void 0 : t.toLowerCase())) || ((
|
|
192
|
+
var c, n, s, a;
|
|
193
|
+
return ((n = (c = l.mainProgram) == null ? void 0 : c.toLowerCase()) == null ? void 0 : n.includes(t == null ? void 0 : t.toLowerCase())) || ((a = (s = l.displayProgram) == null ? void 0 : s.toLowerCase()) == null ? void 0 : a.includes(t == null ? void 0 : t.toLowerCase()));
|
|
194
194
|
}
|
|
195
195
|
) ?? S;
|
|
196
|
-
return
|
|
196
|
+
return i || (i = {
|
|
197
197
|
...S,
|
|
198
198
|
mainProgram: t,
|
|
199
199
|
displayProgram: t,
|
|
200
200
|
id: t
|
|
201
|
-
}),
|
|
201
|
+
}), i;
|
|
202
202
|
}, U = (t) => {
|
|
203
|
-
var c, n, s,
|
|
204
|
-
const e = ((s = (n = (c = t.flightDetails.slices.getFirst()) == null ? void 0 : c.segments.getFirst()) == null ? void 0 : n.passengers.getFirst()) == null ? void 0 : s.baggages) ?? [],
|
|
203
|
+
var c, n, s, a, r, o, g, m, u, d;
|
|
204
|
+
const e = ((s = (n = (c = t.flightDetails.slices.getFirst()) == null ? void 0 : c.segments.getFirst()) == null ? void 0 : n.passengers.getFirst()) == null ? void 0 : s.baggages) ?? [], i = ((o = (r = (a = t.flightDetails.slices.getFirst()) == null ? void 0 : a.segments.getFirst()) == null ? void 0 : r.passengers.getFirst()) == null ? void 0 : o.cabinClassMarketingName) ?? ((u = (m = (g = t.flightDetails.slices.getFirst()) == null ? void 0 : g.segments.getFirst()) == null ? void 0 : m.passengers.getFirst()) == null ? void 0 : u.cabinClass), l = e.map(
|
|
205
205
|
(y) => ({
|
|
206
|
-
type:
|
|
206
|
+
type: H(y.type),
|
|
207
207
|
quantity: y.quantity
|
|
208
208
|
})
|
|
209
209
|
);
|
|
@@ -214,7 +214,7 @@ const ne = (t) => t == null ? void 0 : t.map((e) => {
|
|
|
214
214
|
program: t.airlineProgram,
|
|
215
215
|
baseCurrency: t.flightDetails.baseCurrency,
|
|
216
216
|
fareBrandName: (d = t.flightDetails.slices.getFirst()) == null ? void 0 : d.fareBrandName,
|
|
217
|
-
cabinClass:
|
|
217
|
+
cabinClass: i,
|
|
218
218
|
cashFee: t.cashFee,
|
|
219
219
|
conditions: t.flightDetails.conditions,
|
|
220
220
|
baggages: l,
|
|
@@ -223,28 +223,28 @@ const ne = (t) => t == null ? void 0 : t.map((e) => {
|
|
|
223
223
|
name: t.flightDetails.slices.getFirst().segments.getFirst().marketingCarrier.name
|
|
224
224
|
}
|
|
225
225
|
};
|
|
226
|
-
},
|
|
226
|
+
}, B = (t) => {
|
|
227
227
|
const e = t.filter((n) => n.cash > 0);
|
|
228
|
-
let
|
|
228
|
+
let i = { cash: 1 / 0, baseCurrency: "" };
|
|
229
229
|
for (const n of e)
|
|
230
|
-
n.cash <
|
|
230
|
+
n.cash < i.cash && (i = n);
|
|
231
231
|
const l = Math.min(
|
|
232
232
|
...t.filter((n) => n.points > 0).map((n) => n.points)
|
|
233
|
-
), c =
|
|
233
|
+
), c = i.cash;
|
|
234
234
|
return {
|
|
235
235
|
lowestCash: c === 1 / 0 ? -1 : c,
|
|
236
236
|
lowestPoints: l === 1 / 0 ? -1 : l,
|
|
237
|
-
currency:
|
|
237
|
+
currency: i.baseCurrency === "" ? null : i.baseCurrency
|
|
238
238
|
};
|
|
239
239
|
};
|
|
240
240
|
export {
|
|
241
241
|
S as DEFAULT_AIRLINE_PROGRAM,
|
|
242
|
-
|
|
243
|
-
|
|
242
|
+
oe as buildFlightSearchQuery,
|
|
243
|
+
le as getAirlineProgram,
|
|
244
244
|
K as getFlightNumber,
|
|
245
245
|
C as getFullLogoPath,
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
246
|
+
me as getLogoPath,
|
|
247
|
+
ce as groupFlightResults,
|
|
248
|
+
re as mapDataToFlightDetails,
|
|
249
|
+
X as removeLeadingZeros
|
|
250
250
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@odynn/awayz-flights",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.5",
|
|
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": "
|
|
71
|
+
"@odynn/awayz-core": "^0.6.4",
|
|
72
72
|
"@tanstack/react-query": "^5.67.1",
|
|
73
73
|
"country-code-lookup": "^0.1.3"
|
|
74
74
|
}
|