@odynn/awayz-flights 0.1.16 → 0.1.18
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/components/FlightResult/FlightResult.js +63 -53
- package/dist/constants/endpoints.js +3 -2
- package/dist/hooks/useAirportSearch/useAirportSearch.js +1 -1
- package/dist/hooks/useFlightSearch/useFlightSearch.js +314 -95
- package/dist/lib/constants/endpoints.d.ts +4 -0
- package/dist/lib/hooks/useFlightSearch/useFlightSearch.d.ts +33 -9
- package/dist/lib/services/wallet/WalletService.d.ts +7 -0
- package/dist/lib/services/wallet/WalletService.types.d.ts +144 -0
- package/dist/lib/utils/flightUtils.d.ts +10 -0
- package/dist/objectUtils-CyIaVmog.js +10 -0
- package/dist/services/flights/FlightsService.js +131 -4
- package/dist/services/wallet/WalletService.js +49 -0
- package/dist/services/wallet/WalletService.types.js +4 -0
- package/dist/utils/flightUtils.js +147 -108
- package/package.json +2 -2
- package/dist/FlightsService-DddArKLm.js +0 -142
|
@@ -1,54 +1,60 @@
|
|
|
1
1
|
import { jsx as r, jsxs as e } from "react/jsx-runtime";
|
|
2
|
-
import
|
|
3
|
-
import { g as f, E as
|
|
4
|
-
import { getFlightNumber as
|
|
5
|
-
import { h as
|
|
6
|
-
import { g as
|
|
2
|
+
import O, { useState as d, useMemo as E } from "react";
|
|
3
|
+
import { g as f, E as N, F as I, a as M } from "../../FlightItinerary-DgpK1LYF.js";
|
|
4
|
+
import { DEFAULT_AIRLINE_PROGRAM as R, getFlightNumber as T, getLogoPath as B, getAirlineProgram as L } from "../../utils/flightUtils.js";
|
|
5
|
+
import { h as u } from "../../arrayExtensions-DWKenJCh.js";
|
|
6
|
+
import { g as $ } from "../../dateUtils-DeNLG5hw.js";
|
|
7
7
|
import { EPaymentType as v } from "../../enums/EPaymentType.js";
|
|
8
|
-
import '../../assets/FlightResult.css';
|
|
8
|
+
import '../../assets/FlightResult.css';function b(i) {
|
|
9
|
+
if (!i || isNaN(i) || i < 0) return "N/A";
|
|
10
|
+
let n = i == null ? void 0 : i.toString().split(".")[0];
|
|
11
|
+
return n == null ? void 0 : n.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
12
|
+
}
|
|
13
|
+
const x = (i, n) => {
|
|
9
14
|
if (i <= 0) return "N/A";
|
|
10
|
-
var
|
|
15
|
+
var l = new Intl.NumberFormat("en-US", {
|
|
11
16
|
style: "currency",
|
|
12
|
-
currency:
|
|
17
|
+
currency: n
|
|
13
18
|
});
|
|
14
|
-
return i ?
|
|
15
|
-
},
|
|
16
|
-
const [
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
19
|
+
return i ? l.format(Math.round(i)).toString().split(".")[0] : l.format(0);
|
|
20
|
+
}, z = ({ details: i, onClick: n }) => {
|
|
21
|
+
const [l, D] = d(!1), o = i.origin, c = i.destination, g = i.flightDetails, S = i.paymentOptions.length === 1, [y, F] = d(R), C = async () => {
|
|
22
|
+
const t = await L(i.airlineProgram);
|
|
23
|
+
F(t);
|
|
24
|
+
}, { flightNumbers: h, airlines: P } = E(() => {
|
|
25
|
+
const t = [], a = [];
|
|
26
|
+
return i.flightDetails.slices.forEach((A) => {
|
|
27
|
+
A.segments.forEach((s) => {
|
|
28
|
+
const p = T(s);
|
|
29
|
+
t.includes(p) || t.push(p);
|
|
30
|
+
const m = s.operatingCarrierFlightNumber ? s.operatingCarrier : s.marketingCarrier;
|
|
31
|
+
a.some((k) => k.airline === m.name) || a.push({
|
|
32
|
+
logo: B(m.iataCode),
|
|
33
|
+
airline: m.name
|
|
28
34
|
});
|
|
29
35
|
});
|
|
30
|
-
}), { flightNumbers:
|
|
36
|
+
}), C(), { flightNumbers: t, airlines: a };
|
|
31
37
|
}, [i.flightDetails.slices]);
|
|
32
|
-
return /* @__PURE__ */ r("div", { className: "flight-result", onClick: () =>
|
|
38
|
+
return /* @__PURE__ */ r("div", { className: "flight-result", onClick: () => n(i), children: /* @__PURE__ */ e("div", { className: "content", children: [
|
|
33
39
|
/* @__PURE__ */ r("div", { className: "flight-info", children: /* @__PURE__ */ e("div", { className: "flight-locations", children: [
|
|
34
|
-
/* @__PURE__ */ r("div", { className: "airlines", children:
|
|
40
|
+
/* @__PURE__ */ r("div", { className: "airlines", children: P.map((t, a) => /* @__PURE__ */ r(O.Fragment, { children: /* @__PURE__ */ r("div", { className: "tip", children: /* @__PURE__ */ r("img", { src: t.logo, alt: t.airline }) }, a) }, a)) }),
|
|
35
41
|
/* @__PURE__ */ e("div", { className: "flight-location", children: [
|
|
36
42
|
/* @__PURE__ */ e("p", { children: [
|
|
37
|
-
|
|
43
|
+
o.city,
|
|
38
44
|
",",
|
|
39
|
-
f(
|
|
45
|
+
f(o.country)
|
|
40
46
|
] }),
|
|
41
|
-
/* @__PURE__ */ r("p", { children:
|
|
47
|
+
/* @__PURE__ */ r("p", { children: u(i.departureTime).format(
|
|
42
48
|
// isMobile
|
|
43
49
|
// ? EDateFormats.FlightTime
|
|
44
50
|
// :
|
|
45
|
-
|
|
51
|
+
N.FlightShortDate
|
|
46
52
|
) })
|
|
47
53
|
] }),
|
|
48
54
|
/* @__PURE__ */ e("div", { className: "flight-duration", children: [
|
|
49
55
|
/* @__PURE__ */ r("span", { className: "line" }),
|
|
50
56
|
/* @__PURE__ */ e("p", { children: [
|
|
51
|
-
|
|
57
|
+
$(g.slices[0].duration),
|
|
52
58
|
" ",
|
|
53
59
|
" - ",
|
|
54
60
|
i.numberOfStops > 0 ? `${i.numberOfStops} Stop${i.numberOfStops > 1 ? "s" : ""}` : "Direct"
|
|
@@ -57,16 +63,16 @@ import '../../assets/FlightResult.css';const M = (i, l) => {
|
|
|
57
63
|
] }),
|
|
58
64
|
/* @__PURE__ */ e("div", { children: [
|
|
59
65
|
/* @__PURE__ */ e("p", { children: [
|
|
60
|
-
|
|
66
|
+
c.city,
|
|
61
67
|
", ",
|
|
62
|
-
f(
|
|
68
|
+
f(c.country)
|
|
63
69
|
] }),
|
|
64
70
|
/* @__PURE__ */ e("p", { children: [
|
|
65
|
-
|
|
71
|
+
u(i.arrivalTime).format(
|
|
66
72
|
// isMobile
|
|
67
73
|
// ? EDateFormats.FlightTime
|
|
68
74
|
// :
|
|
69
|
-
|
|
75
|
+
N.FlightShortDate
|
|
70
76
|
),
|
|
71
77
|
" "
|
|
72
78
|
] })
|
|
@@ -78,18 +84,18 @@ import '../../assets/FlightResult.css';const M = (i, l) => {
|
|
|
78
84
|
"div",
|
|
79
85
|
{
|
|
80
86
|
className: "flight-detail",
|
|
81
|
-
onClick: (
|
|
82
|
-
|
|
87
|
+
onClick: (t) => {
|
|
88
|
+
t.stopPropagation(), D(!l);
|
|
83
89
|
},
|
|
84
90
|
children: [
|
|
85
91
|
/* @__PURE__ */ r("p", { children: "Aircraft" }),
|
|
86
92
|
/* @__PURE__ */ e("p", { className: "chevron-text", children: [
|
|
87
|
-
/* @__PURE__ */ r(
|
|
93
|
+
/* @__PURE__ */ r(I, {}),
|
|
88
94
|
/* @__PURE__ */ e("span", { children: [
|
|
89
|
-
|
|
90
|
-
|
|
95
|
+
h[0],
|
|
96
|
+
h.length > 1 && /* @__PURE__ */ e("sup", { children: [
|
|
91
97
|
"+",
|
|
92
|
-
|
|
98
|
+
h.length - 1
|
|
93
99
|
] })
|
|
94
100
|
] })
|
|
95
101
|
] })
|
|
@@ -111,36 +117,40 @@ import '../../assets/FlightResult.css';const M = (i, l) => {
|
|
|
111
117
|
"div",
|
|
112
118
|
{
|
|
113
119
|
className: "cash-value",
|
|
114
|
-
onClick: (
|
|
115
|
-
|
|
120
|
+
onClick: (t) => {
|
|
121
|
+
t.stopPropagation(), n(i, v.CASH);
|
|
116
122
|
},
|
|
117
123
|
children: [
|
|
118
|
-
/* @__PURE__ */ r("p", { children:
|
|
119
|
-
/* @__PURE__ */ r("p", { children:
|
|
124
|
+
/* @__PURE__ */ r("p", { children: S ? "Book For" : "From" }),
|
|
125
|
+
/* @__PURE__ */ r("p", { children: x(i.cash, "USD") })
|
|
120
126
|
]
|
|
121
127
|
}
|
|
122
128
|
),
|
|
123
|
-
i.points > 0 && /* @__PURE__ */
|
|
129
|
+
i.points > 0 && /* @__PURE__ */ e(
|
|
124
130
|
"div",
|
|
125
131
|
{
|
|
126
132
|
className: "points-value",
|
|
127
|
-
onClick: (
|
|
128
|
-
|
|
129
|
-
}
|
|
133
|
+
onClick: (t) => {
|
|
134
|
+
t.stopPropagation(), n(i, v.POINTS);
|
|
135
|
+
},
|
|
136
|
+
children: [
|
|
137
|
+
/* @__PURE__ */ r("img", { src: y.programLogo }),
|
|
138
|
+
/* @__PURE__ */ r("p", { children: `${b(i.points)} miles` })
|
|
139
|
+
]
|
|
130
140
|
}
|
|
131
141
|
)
|
|
132
142
|
] })
|
|
133
143
|
] }),
|
|
134
|
-
/* @__PURE__ */ r("div", { className: `flight-details ${
|
|
135
|
-
|
|
144
|
+
/* @__PURE__ */ r("div", { className: `flight-details ${l ? "is-open" : ""}`, children: /* @__PURE__ */ r("div", { className: "inner", children: /* @__PURE__ */ r(
|
|
145
|
+
M,
|
|
136
146
|
{
|
|
137
147
|
itinerary: g.slices[0].segments,
|
|
138
|
-
origin:
|
|
139
|
-
destination:
|
|
148
|
+
origin: o,
|
|
149
|
+
destination: c
|
|
140
150
|
}
|
|
141
151
|
) }) })
|
|
142
152
|
] }) });
|
|
143
153
|
};
|
|
144
154
|
export {
|
|
145
|
-
|
|
155
|
+
z as FlightResult
|
|
146
156
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
var
|
|
1
|
+
var s = /* @__PURE__ */ ((r) => (r.GET_AIRPORTS = "/flights/search/airports", r.CASH_FLIGHT_SEARCH = "/flights/search/one-way/cash", r.CASH_OUTBOUND_SEARCH = "/flights/search/multi/outbound", r.CASH_INBOUND_SEARCH = "/flights/search/multi/inbound", r.ROUND_TRIP_FARES = "/flights/search/multi/fares", r))(s || {}), a = /* @__PURE__ */ ((r) => (r.GET_AWARDS = "user/rewards", r.GET_USER_CARDS = "user/cards", r))(a || {});
|
|
2
2
|
export {
|
|
3
|
-
|
|
3
|
+
s as EFlightEndpoint,
|
|
4
|
+
a as EWalletEndpoints
|
|
4
5
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useQuery as i } from "@tanstack/react-query";
|
|
2
|
-
import {
|
|
2
|
+
import { FlightService as n } from "../../services/flights/FlightsService.js";
|
|
3
3
|
import "../../arrayExtensions-DWKenJCh.js";
|
|
4
4
|
import { useState as a, useEffect as m } from "react";
|
|
5
5
|
const c = 500, u = (t, e = c) => {
|
|
@@ -1,145 +1,364 @@
|
|
|
1
|
-
import { useState as
|
|
2
|
-
import { useMutation as
|
|
3
|
-
import { ECabinClass as
|
|
4
|
-
import {
|
|
5
|
-
import { parseFlightDetails as
|
|
1
|
+
import { useState as N, useRef as $ } from "react";
|
|
2
|
+
import { useMutation as P } from "@tanstack/react-query";
|
|
3
|
+
import { ECabinClass as J, EFlightType as Y, EFlightPaymentType as k } from "../../types/enums.js";
|
|
4
|
+
import { FlightService as A } from "../../services/flights/FlightsService.js";
|
|
5
|
+
import { parseFlightDetails as K, groupFlightResults as Q, buildFlightSearchQuery as V } from "../../utils/flightUtils.js";
|
|
6
6
|
import "../../arrayExtensions-DWKenJCh.js";
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
import { c as x } from "../../objectUtils-CyIaVmog.js";
|
|
8
|
+
import G from "../../stores/useFlightStore.js";
|
|
9
|
+
import { useAwayzContext as X, getBaseUrl as Z } from "@odynn/awayz-auth";
|
|
10
|
+
async function ee(o, t) {
|
|
11
|
+
const r = o.getReader();
|
|
12
|
+
let n;
|
|
13
|
+
for (; !(n = await r.read()).done; )
|
|
14
|
+
t(n.value);
|
|
15
|
+
}
|
|
16
|
+
function te(o) {
|
|
17
|
+
let t, r, n, s = !1;
|
|
18
|
+
return function(c) {
|
|
19
|
+
t === void 0 ? (t = c, r = 0, n = -1) : t = re(t, c);
|
|
20
|
+
const u = t.length;
|
|
21
|
+
let a = 0;
|
|
22
|
+
for (; r < u; ) {
|
|
23
|
+
s && (t[r] === 10 && (a = ++r), s = !1);
|
|
24
|
+
let d = -1;
|
|
25
|
+
for (; r < u && d === -1; ++r)
|
|
26
|
+
switch (t[r]) {
|
|
27
|
+
case 58:
|
|
28
|
+
n === -1 && (n = r - a);
|
|
29
|
+
break;
|
|
30
|
+
case 13:
|
|
31
|
+
s = !0;
|
|
32
|
+
case 10:
|
|
33
|
+
d = r;
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
if (d === -1)
|
|
37
|
+
break;
|
|
38
|
+
o(t.subarray(a, d), n), a = r, n = -1;
|
|
39
|
+
}
|
|
40
|
+
a === u ? t = void 0 : a !== 0 && (t = t.subarray(a), r -= a);
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function ne(o, t, r) {
|
|
44
|
+
let n = H();
|
|
45
|
+
const s = new TextDecoder();
|
|
46
|
+
return function(c, u) {
|
|
47
|
+
if (c.length === 0)
|
|
48
|
+
r == null || r(n), n = H();
|
|
49
|
+
else if (u > 0) {
|
|
50
|
+
const a = s.decode(c.subarray(0, u)), d = u + (c[u + 1] === 32 ? 2 : 1), b = s.decode(c.subarray(d));
|
|
51
|
+
switch (a) {
|
|
52
|
+
case "data":
|
|
53
|
+
n.data = n.data ? n.data + `
|
|
54
|
+
` + b : b;
|
|
55
|
+
break;
|
|
56
|
+
case "event":
|
|
57
|
+
n.event = b;
|
|
58
|
+
break;
|
|
59
|
+
case "id":
|
|
60
|
+
o(n.id = b);
|
|
61
|
+
break;
|
|
62
|
+
case "retry":
|
|
63
|
+
const g = parseInt(b, 10);
|
|
64
|
+
isNaN(g) || t(n.retry = g);
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function re(o, t) {
|
|
71
|
+
const r = new Uint8Array(o.length + t.length);
|
|
72
|
+
return r.set(o), r.set(t, o.length), r;
|
|
73
|
+
}
|
|
74
|
+
function H() {
|
|
75
|
+
return {
|
|
76
|
+
data: "",
|
|
77
|
+
event: "",
|
|
78
|
+
id: "",
|
|
79
|
+
retry: void 0
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
var oe = function(o, t) {
|
|
83
|
+
var r = {};
|
|
84
|
+
for (var n in o) Object.prototype.hasOwnProperty.call(o, n) && t.indexOf(n) < 0 && (r[n] = o[n]);
|
|
85
|
+
if (o != null && typeof Object.getOwnPropertySymbols == "function")
|
|
86
|
+
for (var s = 0, n = Object.getOwnPropertySymbols(o); s < n.length; s++)
|
|
87
|
+
t.indexOf(n[s]) < 0 && Object.prototype.propertyIsEnumerable.call(o, n[s]) && (r[n[s]] = o[n[s]]);
|
|
88
|
+
return r;
|
|
89
|
+
};
|
|
90
|
+
const L = "text/event-stream", se = 1e3, M = "last-event-id";
|
|
91
|
+
function ae(o, t) {
|
|
92
|
+
var { signal: r, headers: n, onopen: s, onmessage: v, onclose: c, onerror: u, openWhenHidden: a, fetch: d } = t, b = oe(t, ["signal", "headers", "onopen", "onmessage", "onclose", "onerror", "openWhenHidden", "fetch"]);
|
|
93
|
+
return new Promise((g, D) => {
|
|
94
|
+
const p = Object.assign({}, n);
|
|
95
|
+
p.accept || (p.accept = L);
|
|
96
|
+
let m;
|
|
97
|
+
function w() {
|
|
98
|
+
m.abort(), document.hidden || R();
|
|
99
|
+
}
|
|
100
|
+
a || document.addEventListener("visibilitychange", w);
|
|
101
|
+
let F = se, E = 0;
|
|
102
|
+
function S() {
|
|
103
|
+
document.removeEventListener("visibilitychange", w), window.clearTimeout(E), m.abort();
|
|
104
|
+
}
|
|
105
|
+
r == null || r.addEventListener("abort", () => {
|
|
106
|
+
S(), g();
|
|
107
|
+
});
|
|
108
|
+
const _ = d ?? window.fetch, q = s ?? ie;
|
|
109
|
+
async function R() {
|
|
110
|
+
var T;
|
|
111
|
+
m = new AbortController();
|
|
112
|
+
try {
|
|
113
|
+
const O = await _(o, Object.assign(Object.assign({}, b), { headers: p, signal: m.signal }));
|
|
114
|
+
await q(O), await ee(O.body, te(ne((h) => {
|
|
115
|
+
h ? p[M] = h : delete p[M];
|
|
116
|
+
}, (h) => {
|
|
117
|
+
F = h;
|
|
118
|
+
}, v))), c == null || c(), S(), g();
|
|
119
|
+
} catch (O) {
|
|
120
|
+
if (!m.signal.aborted)
|
|
121
|
+
try {
|
|
122
|
+
const h = (T = u == null ? void 0 : u(O)) !== null && T !== void 0 ? T : F;
|
|
123
|
+
window.clearTimeout(E), E = window.setTimeout(R, h);
|
|
124
|
+
} catch (h) {
|
|
125
|
+
S(), D(h);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
R();
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
function ie(o) {
|
|
133
|
+
const t = o.headers.get("content-type");
|
|
134
|
+
if (!(t != null && t.startsWith(L)))
|
|
135
|
+
throw new Error(`Expected content-type to be ${L}, Actual: ${t}`);
|
|
136
|
+
}
|
|
137
|
+
const U = 1, W = J.ECONOMY, z = new AbortController(), ue = 3 * 60 * 1e3, B = (o) => {
|
|
138
|
+
if (!o.origin || !o.destination)
|
|
10
139
|
throw new Error("Origin and destination are required.");
|
|
11
|
-
if (!
|
|
140
|
+
if (!o.departureDate)
|
|
12
141
|
throw new Error("Departure date is required.");
|
|
13
|
-
if (
|
|
142
|
+
if (o.flightType === Y.ROUND_TRIP && !o.returnDate)
|
|
14
143
|
throw new Error("Return date is required for round-trip flights.");
|
|
15
|
-
},
|
|
16
|
-
const [
|
|
17
|
-
inboundResults:
|
|
144
|
+
}, Oe = () => {
|
|
145
|
+
const { token: o, config: t } = X(), [r, n] = N(""), [s, v] = N([]), [c, u] = N(!1), a = $(null), {
|
|
146
|
+
inboundResults: d,
|
|
18
147
|
outboundResults: b,
|
|
19
148
|
setInboundResults: g,
|
|
20
|
-
setOutboundResults:
|
|
21
|
-
partialOfferRequestId:
|
|
22
|
-
setPartialOfferRequestId:
|
|
23
|
-
} =
|
|
24
|
-
data:
|
|
25
|
-
previousResults:
|
|
26
|
-
inbound:
|
|
149
|
+
setOutboundResults: D,
|
|
150
|
+
partialOfferRequestId: p,
|
|
151
|
+
setPartialOfferRequestId: m
|
|
152
|
+
} = G(), w = ({
|
|
153
|
+
data: e,
|
|
154
|
+
previousResults: l,
|
|
155
|
+
inbound: f
|
|
27
156
|
}) => {
|
|
28
|
-
const
|
|
29
|
-
return (
|
|
157
|
+
const i = K(e, l);
|
|
158
|
+
return (f ? g : D)(Q(i)), i;
|
|
30
159
|
}, {
|
|
31
|
-
mutate:
|
|
32
|
-
status:
|
|
33
|
-
error:
|
|
34
|
-
} =
|
|
35
|
-
mutationFn: async (
|
|
36
|
-
|
|
37
|
-
const
|
|
160
|
+
mutate: F,
|
|
161
|
+
status: E,
|
|
162
|
+
error: S
|
|
163
|
+
} = P({
|
|
164
|
+
mutationFn: async (e) => {
|
|
165
|
+
B(e);
|
|
166
|
+
const f = {
|
|
38
167
|
passengers: Array.from(
|
|
39
|
-
{ length:
|
|
168
|
+
{ length: e.passengers ?? U },
|
|
40
169
|
() => ({ type: "adult" })
|
|
41
170
|
),
|
|
42
|
-
origin:
|
|
43
|
-
destination:
|
|
44
|
-
cabin_class:
|
|
171
|
+
origin: e.origin || "",
|
|
172
|
+
destination: e.destination || "",
|
|
173
|
+
cabin_class: e.cabinClass || W
|
|
45
174
|
};
|
|
46
|
-
if (
|
|
47
|
-
const
|
|
48
|
-
...
|
|
49
|
-
departure_date:
|
|
175
|
+
if (e.flightType === Y.ONE_WAY) {
|
|
176
|
+
const i = await A.cashOnlySearch({
|
|
177
|
+
...f,
|
|
178
|
+
departure_date: e.departureDate
|
|
50
179
|
});
|
|
51
180
|
return {
|
|
52
|
-
success:
|
|
53
|
-
data:
|
|
181
|
+
success: i.success,
|
|
182
|
+
data: i.data
|
|
54
183
|
};
|
|
55
184
|
} else {
|
|
56
|
-
const
|
|
57
|
-
...
|
|
58
|
-
departure_date:
|
|
59
|
-
return_date:
|
|
185
|
+
const i = await A.roundTripOutboundSearch({
|
|
186
|
+
...f,
|
|
187
|
+
departure_date: e.departureDate,
|
|
188
|
+
return_date: e.returnDate
|
|
60
189
|
});
|
|
61
190
|
return {
|
|
62
|
-
success:
|
|
63
|
-
data:
|
|
64
|
-
partialOfferRequestId:
|
|
191
|
+
success: i.success,
|
|
192
|
+
data: i.data.offers,
|
|
193
|
+
partialOfferRequestId: i.data.id
|
|
65
194
|
};
|
|
66
195
|
}
|
|
67
196
|
},
|
|
68
|
-
onSuccess: (
|
|
69
|
-
console.log({ result:
|
|
70
|
-
const { success:
|
|
71
|
-
if (!
|
|
197
|
+
onSuccess: (e) => {
|
|
198
|
+
console.log({ result: e });
|
|
199
|
+
const { success: l, data: f, partialOfferRequestId: i } = e;
|
|
200
|
+
if (!l) {
|
|
72
201
|
console.log("oh lol, it didn't work");
|
|
73
202
|
return;
|
|
74
203
|
}
|
|
75
|
-
|
|
204
|
+
w({ data: f }), i && m(i);
|
|
76
205
|
},
|
|
77
|
-
onError: (
|
|
78
|
-
console.error("Error in outbound flight search:",
|
|
206
|
+
onError: (e) => {
|
|
207
|
+
console.error("Error in outbound flight search:", e);
|
|
79
208
|
}
|
|
80
209
|
}), {
|
|
81
|
-
mutate:
|
|
82
|
-
status:
|
|
83
|
-
error:
|
|
84
|
-
} =
|
|
85
|
-
mutationFn: async (
|
|
86
|
-
if (!
|
|
210
|
+
mutate: _,
|
|
211
|
+
status: q,
|
|
212
|
+
error: R
|
|
213
|
+
} = P({
|
|
214
|
+
mutationFn: async (e) => {
|
|
215
|
+
if (!p)
|
|
87
216
|
throw new Error("No partialOfferRequestId found for inbound search.");
|
|
88
|
-
return
|
|
89
|
-
outboundOfferId:
|
|
90
|
-
outboundOfferRequestId:
|
|
217
|
+
return n(e), await A.roundTripInboundSearch({
|
|
218
|
+
outboundOfferId: e,
|
|
219
|
+
outboundOfferRequestId: p
|
|
91
220
|
});
|
|
92
221
|
},
|
|
93
|
-
onSuccess: (
|
|
94
|
-
const { success:
|
|
95
|
-
|
|
96
|
-
data:
|
|
222
|
+
onSuccess: (e) => {
|
|
223
|
+
const { success: l, data: f } = e;
|
|
224
|
+
l && w({
|
|
225
|
+
data: f.offers,
|
|
97
226
|
inbound: !0
|
|
98
227
|
});
|
|
99
228
|
},
|
|
100
|
-
onError: (
|
|
101
|
-
console.error("Error in inbound flight search:",
|
|
229
|
+
onError: (e) => {
|
|
230
|
+
console.error("Error in inbound flight search:", e);
|
|
102
231
|
}
|
|
103
232
|
}), {
|
|
104
233
|
mutate: T,
|
|
105
|
-
status:
|
|
106
|
-
error:
|
|
107
|
-
} =
|
|
108
|
-
mutationFn: async (
|
|
109
|
-
if (!
|
|
234
|
+
status: O,
|
|
235
|
+
error: h
|
|
236
|
+
} = P({
|
|
237
|
+
mutationFn: async (e) => {
|
|
238
|
+
if (!p)
|
|
110
239
|
throw new Error("No partialOfferRequestId found for round-trip fares.");
|
|
111
|
-
return await
|
|
112
|
-
outboundOfferId:
|
|
113
|
-
outboundOfferRequestId:
|
|
114
|
-
inboundOfferId:
|
|
240
|
+
return await A.getRoundTripFares({
|
|
241
|
+
outboundOfferId: r,
|
|
242
|
+
outboundOfferRequestId: p,
|
|
243
|
+
inboundOfferId: e
|
|
115
244
|
});
|
|
116
245
|
},
|
|
117
|
-
onSuccess: (
|
|
118
|
-
const { success:
|
|
119
|
-
if (!
|
|
120
|
-
const
|
|
121
|
-
|
|
246
|
+
onSuccess: (e) => {
|
|
247
|
+
const { success: l, data: f } = e;
|
|
248
|
+
if (!l) return;
|
|
249
|
+
const i = f.offers;
|
|
250
|
+
v(x(i));
|
|
122
251
|
},
|
|
123
|
-
onError: (
|
|
124
|
-
console.error("Error in round-trip fare search:",
|
|
252
|
+
onError: (e) => {
|
|
253
|
+
console.error("Error in round-trip fare search:", e);
|
|
125
254
|
}
|
|
126
|
-
})
|
|
255
|
+
}), j = async (e) => {
|
|
256
|
+
u(!0);
|
|
257
|
+
const l = e.paymentType === k.CASH_AND_MILES ? ['"cash"', '"points"'] : ['"points"'], f = V({
|
|
258
|
+
originCode: e.origin,
|
|
259
|
+
destinationCode: e.destination,
|
|
260
|
+
departureDate: e.departureDate,
|
|
261
|
+
cabinClass: e.cabinClass || W,
|
|
262
|
+
passengerCount: e.passengers || U,
|
|
263
|
+
paymentType: l
|
|
264
|
+
});
|
|
265
|
+
let i = [];
|
|
266
|
+
a.current = setTimeout(() => {
|
|
267
|
+
I();
|
|
268
|
+
}, ue), await ae(Z() + f, {
|
|
269
|
+
headers: {
|
|
270
|
+
"Content-Type": "application/json",
|
|
271
|
+
Authorization: o || "",
|
|
272
|
+
"client-id": (t == null ? void 0 : t.clientId) || ""
|
|
273
|
+
},
|
|
274
|
+
signal: z.signal,
|
|
275
|
+
onmessage(C) {
|
|
276
|
+
try {
|
|
277
|
+
const y = x(JSON.parse(C.data));
|
|
278
|
+
if (y.success === !1) {
|
|
279
|
+
I();
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
if (y.close === !0) {
|
|
283
|
+
I();
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
y.meta, y.flights && (i = w({
|
|
287
|
+
data: y.flights,
|
|
288
|
+
previousResults: i
|
|
289
|
+
}));
|
|
290
|
+
} catch (y) {
|
|
291
|
+
console.error("Error parsing message:", y);
|
|
292
|
+
}
|
|
293
|
+
},
|
|
294
|
+
onerror(C) {
|
|
295
|
+
throw console.error("EventSource error:", C), I(), C;
|
|
296
|
+
},
|
|
297
|
+
onclose() {
|
|
298
|
+
console.log("EventSource closed"), u(!1);
|
|
299
|
+
},
|
|
300
|
+
keepalive: !1
|
|
301
|
+
});
|
|
302
|
+
}, I = () => {
|
|
303
|
+
c && (z.abort(), a.current && (clearTimeout(a.current), a.current = null), u(!1));
|
|
304
|
+
};
|
|
127
305
|
return {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
306
|
+
/**
|
|
307
|
+
* Loading status for searching both outbound and inbound flights
|
|
308
|
+
* @type {boolean}
|
|
309
|
+
* @default false
|
|
310
|
+
*/
|
|
311
|
+
loading: E === "pending" || q === "pending" || c,
|
|
312
|
+
/**
|
|
313
|
+
* Loading status for fares
|
|
314
|
+
* @type {boolean}
|
|
315
|
+
* @default false
|
|
316
|
+
*/
|
|
317
|
+
loadingFares: O === "pending",
|
|
318
|
+
outboundError: S,
|
|
319
|
+
inboundError: R,
|
|
320
|
+
roundTripFaresError: h,
|
|
133
321
|
// Results
|
|
134
322
|
outboundResults: b,
|
|
135
|
-
inboundResults:
|
|
136
|
-
roundTripFares:
|
|
323
|
+
inboundResults: d,
|
|
324
|
+
roundTripFares: s,
|
|
137
325
|
// Mutation triggers
|
|
138
|
-
|
|
139
|
-
|
|
326
|
+
/**
|
|
327
|
+
* Used to search for outbound flights
|
|
328
|
+
* @type {function}
|
|
329
|
+
*
|
|
330
|
+
* @param {ISearchFlightArgs} args - The search arguments
|
|
331
|
+
*/
|
|
332
|
+
searchOutboundFlights: async (e) => {
|
|
333
|
+
switch (B(e), e.paymentType) {
|
|
334
|
+
default:
|
|
335
|
+
case k.CASH_AND_MILES:
|
|
336
|
+
j(e);
|
|
337
|
+
break;
|
|
338
|
+
case k.CASH:
|
|
339
|
+
F(e);
|
|
340
|
+
break;
|
|
341
|
+
case k.MILES:
|
|
342
|
+
j(e);
|
|
343
|
+
break;
|
|
344
|
+
}
|
|
345
|
+
},
|
|
346
|
+
/**
|
|
347
|
+
* Used to search for inbound flights after selecting an outbound flight
|
|
348
|
+
* @type {function}
|
|
349
|
+
*
|
|
350
|
+
* @param {string} outboundOfferId - The ID of the outbound offer
|
|
351
|
+
*/
|
|
352
|
+
searchInboundFlights: _,
|
|
353
|
+
/**
|
|
354
|
+
* Used to get round-trip fares after selecting both outbound and inbound flights
|
|
355
|
+
* @type {function}
|
|
356
|
+
*
|
|
357
|
+
* @param {string} inboundOfferId - The ID of the inbound offer
|
|
358
|
+
*/
|
|
140
359
|
getRoundTripFares: T
|
|
141
360
|
};
|
|
142
361
|
};
|
|
143
362
|
export {
|
|
144
|
-
|
|
363
|
+
Oe as useFlightSearch
|
|
145
364
|
};
|