@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.
@@ -1,54 +1,60 @@
1
1
  import { jsx as r, jsxs as e } from "react/jsx-runtime";
2
- import b, { useState as C, useMemo as k } from "react";
3
- import { g as f, E as u, F as O, a as E } from "../../FlightItinerary-DgpK1LYF.js";
4
- import { getFlightNumber as P } from "../../utils/flightUtils.js";
5
- import { h as N } from "../../arrayExtensions-DWKenJCh.js";
6
- import { g as I } from "../../dateUtils-DeNLG5hw.js";
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';const M = (i, l) => {
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 a = new Intl.NumberFormat("en-US", {
15
+ var l = new Intl.NumberFormat("en-US", {
11
16
  style: "currency",
12
- currency: l
17
+ currency: n
13
18
  });
14
- return i ? a.format(Math.round(i)).toString().split(".")[0] : a.format(0);
15
- }, w = ({ details: i, onClick: l }) => {
16
- const [a, y] = C(!1), c = i.origin, h = i.destination, g = i.flightDetails, D = i.paymentOptions.length === 1, { flightNumbers: m, airlines: S } = k(() => {
17
- const n = [], t = [];
18
- return i.flightDetails.slices.forEach((F) => {
19
- F.segments.forEach((s) => {
20
- const p = P(s);
21
- n.includes(p) || n.push(p);
22
- const o = s.operatingCarrierFlightNumber ? s.operatingCarrier : s.marketingCarrier;
23
- t.some(
24
- (d) => d.logo === o.logoSymbolUrl && d.airline === o.name
25
- ) || t.push({
26
- logo: o.logoSymbolUrl,
27
- airline: o.name
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: n, airlines: t };
36
+ }), C(), { flightNumbers: t, airlines: a };
31
37
  }, [i.flightDetails.slices]);
32
- return /* @__PURE__ */ r("div", { className: "flight-result", onClick: () => l(i), children: /* @__PURE__ */ e("div", { className: "content", children: [
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: S.map((n, t) => /* @__PURE__ */ r(b.Fragment, { children: /* @__PURE__ */ r("div", { className: "tip", children: /* @__PURE__ */ r("img", { src: n.logo, alt: n.airline }) }, t) }, t)) }),
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
- c.city,
43
+ o.city,
38
44
  ",",
39
- f(c.country)
45
+ f(o.country)
40
46
  ] }),
41
- /* @__PURE__ */ r("p", { children: N(i.departureTime).format(
47
+ /* @__PURE__ */ r("p", { children: u(i.departureTime).format(
42
48
  // isMobile
43
49
  // ? EDateFormats.FlightTime
44
50
  // :
45
- u.FlightShortDate
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
- I(g.slices[0].duration),
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
- h.city,
66
+ c.city,
61
67
  ", ",
62
- f(h.country)
68
+ f(c.country)
63
69
  ] }),
64
70
  /* @__PURE__ */ e("p", { children: [
65
- N(i.arrivalTime).format(
71
+ u(i.arrivalTime).format(
66
72
  // isMobile
67
73
  // ? EDateFormats.FlightTime
68
74
  // :
69
- u.FlightShortDate
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: (n) => {
82
- n.stopPropagation(), y(!a);
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(O, {}),
93
+ /* @__PURE__ */ r(I, {}),
88
94
  /* @__PURE__ */ e("span", { children: [
89
- m[0],
90
- m.length > 1 && /* @__PURE__ */ e("sup", { children: [
95
+ h[0],
96
+ h.length > 1 && /* @__PURE__ */ e("sup", { children: [
91
97
  "+",
92
- m.length - 1
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: (n) => {
115
- n.stopPropagation(), l(i, v.CASH);
120
+ onClick: (t) => {
121
+ t.stopPropagation(), n(i, v.CASH);
116
122
  },
117
123
  children: [
118
- /* @__PURE__ */ r("p", { children: D ? "Book For" : "From" }),
119
- /* @__PURE__ */ r("p", { children: M(i.cash, "USD") })
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__ */ r(
129
+ i.points > 0 && /* @__PURE__ */ e(
124
130
  "div",
125
131
  {
126
132
  className: "points-value",
127
- onClick: (n) => {
128
- n.stopPropagation(), l(i, v.POINTS);
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 ${a ? "is-open" : ""}`, children: /* @__PURE__ */ r("div", { className: "inner", children: /* @__PURE__ */ r(
135
- E,
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: c,
139
- destination: h
148
+ origin: o,
149
+ destination: c
140
150
  }
141
151
  ) }) })
142
152
  ] }) });
143
153
  };
144
154
  export {
145
- w as FlightResult
155
+ z as FlightResult
146
156
  };
@@ -1,4 +1,5 @@
1
- var r = /* @__PURE__ */ ((s) => (s.GET_AIRPORTS = "/flights/search/airports", s.CASH_FLIGHT_SEARCH = "/flights/search/one-way/cash", s.CASH_OUTBOUND_SEARCH = "/flights/search/multi/outbound", s.CASH_INBOUND_SEARCH = "/flights/search/multi/inbound", s.ROUND_TRIP_FARES = "/flights/search/multi/fares", s))(r || {});
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
- r as EFlightEndpoint
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 { F as n } from "../../FlightsService-DddArKLm.js";
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 d } from "react";
2
- import { useMutation as u } from "@tanstack/react-query";
3
- import { ECabinClass as C, EFlightType as c } from "../../types/enums.js";
4
- import { F as a, c as D } from "../../FlightsService-DddArKLm.js";
5
- import { parseFlightDetails as _, groupFlightResults as N } from "../../utils/flightUtils.js";
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 P from "../../stores/useFlightStore.js";
8
- const v = 1, A = C.ECONOMY, M = (s) => {
9
- if (!s.origin || !s.destination)
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 (!s.departureDate)
140
+ if (!o.departureDate)
12
141
  throw new Error("Departure date is required.");
13
- if (s.flightType === c.ROUND_TRIP && !s.returnDate)
142
+ if (o.flightType === Y.ROUND_TRIP && !o.returnDate)
14
143
  throw new Error("Return date is required for round-trip flights.");
15
- }, G = () => {
16
- const [s, f] = d(""), [l, p] = d([]), {
17
- inboundResults: h,
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: m,
21
- partialOfferRequestId: n,
22
- setPartialOfferRequestId: R
23
- } = P(), i = ({
24
- data: r,
25
- previousResults: t,
26
- inbound: o
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 e = _(r, t);
29
- return (o ? g : m)(N(e)), e;
157
+ const i = K(e, l);
158
+ return (f ? g : D)(Q(i)), i;
30
159
  }, {
31
- mutate: O,
32
- status: F,
33
- error: E
34
- } = u({
35
- mutationFn: async (r) => {
36
- M(r);
37
- const o = {
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: r.passengers ?? v },
168
+ { length: e.passengers ?? U },
40
169
  () => ({ type: "adult" })
41
170
  ),
42
- origin: r.origin || "",
43
- destination: r.destination || "",
44
- cabin_class: r.cabinClass || A
171
+ origin: e.origin || "",
172
+ destination: e.destination || "",
173
+ cabin_class: e.cabinClass || W
45
174
  };
46
- if (r.flightType === c.ONE_WAY) {
47
- const e = await a.cashOnlySearch({
48
- ...o,
49
- departure_date: r.departureDate
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: e.success,
53
- data: e.data
181
+ success: i.success,
182
+ data: i.data
54
183
  };
55
184
  } else {
56
- const e = await a.roundTripOutboundSearch({
57
- ...o,
58
- departure_date: r.departureDate,
59
- return_date: r.returnDate
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: e.success,
63
- data: e.data.offers,
64
- partialOfferRequestId: e.data.id
191
+ success: i.success,
192
+ data: i.data.offers,
193
+ partialOfferRequestId: i.data.id
65
194
  };
66
195
  }
67
196
  },
68
- onSuccess: (r) => {
69
- console.log({ result: r });
70
- const { success: t, data: o, partialOfferRequestId: e } = r;
71
- if (!t) {
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
- i({ data: o }), e && R(e);
204
+ w({ data: f }), i && m(i);
76
205
  },
77
- onError: (r) => {
78
- console.error("Error in outbound flight search:", r);
206
+ onError: (e) => {
207
+ console.error("Error in outbound flight search:", e);
79
208
  }
80
209
  }), {
81
- mutate: w,
82
- status: I,
83
- error: S
84
- } = u({
85
- mutationFn: async (r) => {
86
- if (!n)
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 f(r), await a.roundTripInboundSearch({
89
- outboundOfferId: r,
90
- outboundOfferRequestId: n
217
+ return n(e), await A.roundTripInboundSearch({
218
+ outboundOfferId: e,
219
+ outboundOfferRequestId: p
91
220
  });
92
221
  },
93
- onSuccess: (r) => {
94
- const { success: t, data: o } = r;
95
- t && i({
96
- data: o.offers,
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: (r) => {
101
- console.error("Error in inbound flight search:", r);
229
+ onError: (e) => {
230
+ console.error("Error in inbound flight search:", e);
102
231
  }
103
232
  }), {
104
233
  mutate: T,
105
- status: q,
106
- error: y
107
- } = u({
108
- mutationFn: async (r) => {
109
- if (!n)
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 a.getRoundTripFares({
112
- outboundOfferId: s,
113
- outboundOfferRequestId: n,
114
- inboundOfferId: r
240
+ return await A.getRoundTripFares({
241
+ outboundOfferId: r,
242
+ outboundOfferRequestId: p,
243
+ inboundOfferId: e
115
244
  });
116
245
  },
117
- onSuccess: (r) => {
118
- const { success: t, data: o } = r;
119
- if (!t) return;
120
- const e = o.offers;
121
- p(D(e));
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: (r) => {
124
- console.error("Error in round-trip fare search:", r);
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
- loading: F === "pending" || I === "pending",
129
- loadingFares: q === "pending",
130
- outboundError: E,
131
- inboundError: S,
132
- roundTripFaresError: y,
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: h,
136
- roundTripFares: l,
323
+ inboundResults: d,
324
+ roundTripFares: s,
137
325
  // Mutation triggers
138
- searchOutboundFlights: O,
139
- searchInboundFlights: w,
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
- G as useFlightSearch
363
+ Oe as useFlightSearch
145
364
  };