@odynn/awayz-flights 0.9.7 → 0.9.9

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.
Files changed (36) hide show
  1. package/dist/BookingOption-V-FzaupW.js +196 -0
  2. package/dist/FlightItinerary-C4KPpVcF.js +94 -0
  3. package/dist/assets/FlightItinerary.css +1 -1
  4. package/dist/assets/FlightItineraryDropdown.css +1 -0
  5. package/dist/assets/MiniFlightItinerary.css +1 -0
  6. package/dist/assets/_styles.css +1 -1
  7. package/dist/assets/_styles2.css +1 -1
  8. package/dist/components/BookingOption/BookingOption.js +3 -4
  9. package/dist/components/Dialog/Dialog.js +1 -1
  10. package/dist/components/FlightItinerary/FlightItinerary.js +3 -4
  11. package/dist/components/FlightItineraryDropdown/FlightItineraryDropdown.js +22 -30
  12. package/dist/components/FlightResult/FlightResult.js +173 -183
  13. package/dist/components/HorizontalScroller/HorizontalScroller.js +3 -3
  14. package/dist/components/MiniFlightItinerary/MiniFlightItinerary.js +89 -7
  15. package/dist/components/index.js +5 -5
  16. package/dist/constants/endpoints.js +1 -1
  17. package/dist/enums-tLvxh02p.js +4 -0
  18. package/dist/hooks/index.js +3 -3
  19. package/dist/hooks/useFlightSearch/useFlightSearch.js +420 -11
  20. package/dist/{index-D8ljJLcr.js → index-9LVJi5JO.js} +7 -7
  21. package/dist/index-Kopwbl-x.js +19 -0
  22. package/dist/lib/components/FlightItinerary/FlightItinerary.d.ts +1 -6
  23. package/dist/lib/components/FlightItineraryDropdown/FlightItineraryDropdown.d.ts +2 -4
  24. package/dist/lib/constants/endpoints.d.ts +2 -1
  25. package/dist/lib/services/flights/FlightsService.d.ts +1 -0
  26. package/dist/main.js +35 -34
  27. package/dist/services/flights/FlightsService.js +37 -28
  28. package/dist/utils/flightUtils.js +39 -40
  29. package/package.json +1 -1
  30. package/dist/BookingOption-BTupJyHW.js +0 -192
  31. package/dist/FlightItinerary-BYXRMQUD.js +0 -262
  32. package/dist/MiniFlightItinerary-D2tFssaK.js +0 -106
  33. package/dist/assets/_styles5.css +0 -1
  34. package/dist/index-Gj4bRuCQ.js +0 -15
  35. package/dist/index-nI16-czT.js +0 -4
  36. package/dist/useFlightSearch-Dxoeykpk.js +0 -420
@@ -1,420 +0,0 @@
1
- import { useAwayzContext as te, useWallet as ne, awayzClient as P, getBaseUrl as re } from "@odynn/awayz-core";
2
- import { useMutation as D } from "@tanstack/react-query";
3
- import "./moment-BGjjqtLQ.js";
4
- import "./arrayExtensions-Ce8YopTP.js";
5
- import { c as V } from "./objectUtils-3IeCVocm.js";
6
- import { useState as k, useRef as oe } from "react";
7
- import { FlightService as F } from "./services/flights/FlightsService.js";
8
- import se from "./stores/useFlightStore.js";
9
- import { EFlightType as X, EFlightPaymentType as U } from "./types/enums.js";
10
- import { ECabinClass as ae } from "./types/ECabinClass.js";
11
- import { mapDataToFlightDetails as ie, groupFlightResults as ce, buildFlightSearchQuery as ue } from "./utils/flightUtils.js";
12
- async function le(e, n) {
13
- const o = e.getReader();
14
- let r;
15
- for (; !(r = await o.read()).done; )
16
- n(r.value);
17
- }
18
- function de(e) {
19
- let n, o, r, s = !1;
20
- return function(f) {
21
- n === void 0 ? (n = f, o = 0, r = -1) : n = pe(n, f);
22
- const p = n.length;
23
- let u = 0;
24
- for (; o < p; ) {
25
- s && (n[o] === 10 && (u = ++o), s = !1);
26
- let l = -1;
27
- for (; o < p && l === -1; ++o)
28
- switch (n[o]) {
29
- case 58:
30
- r === -1 && (r = o - u);
31
- break;
32
- case 13:
33
- s = !0;
34
- case 10:
35
- l = o;
36
- break;
37
- }
38
- if (l === -1)
39
- break;
40
- e(n.subarray(u, l), r), u = o, r = -1;
41
- }
42
- u === p ? n = void 0 : u !== 0 && (n = n.subarray(u), o -= u);
43
- };
44
- }
45
- function fe(e, n, o) {
46
- let r = W();
47
- const s = new TextDecoder();
48
- return function(f, p) {
49
- if (f.length === 0)
50
- o == null || o(r), r = W();
51
- else if (p > 0) {
52
- const u = s.decode(f.subarray(0, p)), l = p + (f[p + 1] === 32 ? 2 : 1), R = s.decode(f.subarray(l));
53
- switch (u) {
54
- case "data":
55
- r.data = r.data ? r.data + `
56
- ` + R : R;
57
- break;
58
- case "event":
59
- r.event = R;
60
- break;
61
- case "id":
62
- e(r.id = R);
63
- break;
64
- case "retry":
65
- const m = parseInt(R, 10);
66
- isNaN(m) || n(r.retry = m);
67
- break;
68
- }
69
- }
70
- };
71
- }
72
- function pe(e, n) {
73
- const o = new Uint8Array(e.length + n.length);
74
- return o.set(e), o.set(n, e.length), o;
75
- }
76
- function W() {
77
- return {
78
- data: "",
79
- event: "",
80
- id: "",
81
- retry: void 0
82
- };
83
- }
84
- var he = function(e, n) {
85
- var o = {};
86
- for (var r in e) Object.prototype.hasOwnProperty.call(e, r) && n.indexOf(r) < 0 && (o[r] = e[r]);
87
- if (e != null && typeof Object.getOwnPropertySymbols == "function")
88
- for (var s = 0, r = Object.getOwnPropertySymbols(e); s < r.length; s++)
89
- n.indexOf(r[s]) < 0 && Object.prototype.propertyIsEnumerable.call(e, r[s]) && (o[r[s]] = e[r[s]]);
90
- return o;
91
- };
92
- const j = "text/event-stream", Se = 1e3, z = "last-event-id";
93
- function Re(e, n) {
94
- var { signal: o, headers: r, onopen: s, onmessage: E, onclose: f, onerror: p, openWhenHidden: u, fetch: l } = n, R = he(n, ["signal", "headers", "onopen", "onmessage", "onclose", "onerror", "openWhenHidden", "fetch"]);
95
- return new Promise((m, N) => {
96
- const g = Object.assign({}, r);
97
- g.accept || (g.accept = j);
98
- let h;
99
- function A() {
100
- h.abort(), document.hidden || _();
101
- }
102
- u || document.addEventListener("visibilitychange", A);
103
- let L = Se, I = 0;
104
- function b() {
105
- document.removeEventListener("visibilitychange", A), window.clearTimeout(I), h.abort();
106
- }
107
- o == null || o.addEventListener("abort", () => {
108
- b(), m();
109
- });
110
- const M = l ?? window.fetch, H = s ?? ge;
111
- async function _() {
112
- var w;
113
- h = new AbortController();
114
- try {
115
- const T = await M(e, Object.assign(Object.assign({}, R), { headers: g, signal: h.signal }));
116
- await H(T), await le(T.body, de(fe((S) => {
117
- S ? g[z] = S : delete g[z];
118
- }, (S) => {
119
- L = S;
120
- }, E))), f == null || f(), b(), m();
121
- } catch (T) {
122
- if (!h.signal.aborted)
123
- try {
124
- const S = (w = p == null ? void 0 : p(T)) !== null && w !== void 0 ? w : L;
125
- window.clearTimeout(I), I = window.setTimeout(_, S);
126
- } catch (S) {
127
- b(), N(S);
128
- }
129
- }
130
- }
131
- _();
132
- });
133
- }
134
- function ge(e) {
135
- const n = e.headers.get("content-type");
136
- if (!(n != null && n.startsWith(j)))
137
- throw new Error(`Expected content-type to be ${j}, Actual: ${n}`);
138
- }
139
- var v = /* @__PURE__ */ ((e) => (e.LOCATIONS = "LOCATIONS", e.CHECK_USER = "CHECK_USER", e.USER_REGIONS = "USER_REGIONS", e.CONVERT_CURRENCY = "CONVERT_CURRENCY", e.CLIENT_COMPONENT_KEY = "CLIENT_COMPONENT_KEY", e.SEARCH_LIMIT = "SEARCH_LIMIT", e.PROGRAMS = "PROGRAMS", e.USER_PROGRAMS = "USER_PROGRAMS", e.LINKED_USER_PROGRAMS = "LINKED_USER_PROGRAMS", e.BANKS = "BANKS", e.CARDS = "CARDS", e.USER_CARDS = "USER_CARDS", e.TRIPS = "TRIPS", e.UNCATEGORISED_BOOKINGS = "UNCATEGORISED_BOOKINGS", e.BOOKING = "BOOKING", e.VALUE_CENTS = "VALUE_CENTS", e.AVAILABILITY_ALERTS = "AVAILABILITY_ALERTS", e.ALERT_NOTIFICATIONS = "ALERT_NOTIFICATIONS", e.POINTS_AS_CASH = "POINTS_AS_CASH", e.GET_USER_REGION = "get_user_region", e.PRICING = "pricing", e.FAQS = "faqs", e.FEATURES = "features", e.AIRLINE_HEALTH = "airline_health", e))(v || {});
140
- const $ = 1, y = ae.ECONOMY;
141
- let B = new AbortController();
142
- const Oe = 3 * 60 * 1e3, J = (e) => {
143
- if (!e.origin || !e.destination)
144
- throw new Error("Origin and destination are required.");
145
- if (!e.dates)
146
- throw new Error("At least one date is required.");
147
- if (e.flightType === X.ROUND_TRIP && e.dates.length != 2)
148
- throw new Error(
149
- "Two dates are required for round-trip flights: departure and return."
150
- );
151
- }, Ue = () => {
152
- const { token: e, config: n } = te(), [o, r] = k(""), { airlinePrograms: s } = ne(), [E, f] = k([]), [p, u] = k(!1), l = oe(null), {
153
- inboundResults: R,
154
- outboundResults: m,
155
- setInboundResults: N,
156
- setOutboundResults: g,
157
- partialOfferRequestId: h,
158
- setPartialOfferRequestId: A,
159
- airlineStatuses: L,
160
- setAirlineStatuses: I
161
- } = se(), b = ({
162
- data: t,
163
- inbound: i
164
- }) => {
165
- const a = ie(t);
166
- return (i ? N : g)(ce(a)), a;
167
- }, {
168
- mutate: M,
169
- status: H,
170
- error: _
171
- } = D({
172
- mutationFn: async (t) => {
173
- J(t);
174
- const a = {
175
- passengers: Array.from(
176
- { length: t.passengers ?? $ },
177
- () => ({ type: "adult" })
178
- ),
179
- origin: t.origin || "",
180
- destination: t.destination || "",
181
- cabin_class: t.cabinClass ?? y
182
- };
183
- if (t.flightType === X.ONE_WAY) {
184
- const c = await F.cashOnlySearch({
185
- ...a,
186
- departure_dates: t.dates
187
- });
188
- return {
189
- success: c.success,
190
- data: c.data
191
- };
192
- } else {
193
- const c = await F.roundTripOutboundSearch({
194
- ...a,
195
- departure_date: t.dates[0],
196
- return_date: t.dates[1]
197
- });
198
- return {
199
- success: c.success,
200
- data: c.data.offers,
201
- partialOfferRequestId: c.data.id
202
- };
203
- }
204
- },
205
- onSuccess: (t) => {
206
- const { success: i, data: a, partialOfferRequestId: c } = t;
207
- if (!i) {
208
- console.log("oh lol, it didn't work");
209
- return;
210
- }
211
- b({ data: a }), c && A(c);
212
- },
213
- onError: (t) => {
214
- console.error("Error in outbound flight search:", t);
215
- },
216
- onSettled: () => {
217
- P.invalidateQueries({ queryKey: [v.SEARCH_LIMIT] });
218
- }
219
- }), {
220
- mutate: w,
221
- status: T,
222
- error: S
223
- } = D({
224
- mutationFn: async ({
225
- outboundOfferId: t,
226
- cabinClass: i
227
- }) => {
228
- if (!h)
229
- throw new Error("No partialOfferRequestId found for inbound search.");
230
- return r(t), await F.roundTripInboundSearch({
231
- outboundOfferId: t,
232
- outboundOfferRequestId: h,
233
- cabinClass: i || y
234
- });
235
- },
236
- onSuccess: (t) => {
237
- const { success: i, data: a } = t;
238
- i && b({
239
- data: a.offers,
240
- inbound: !0
241
- });
242
- },
243
- onError: (t) => {
244
- console.error("Error in inbound flight search:", t);
245
- },
246
- onSettled: () => {
247
- P.invalidateQueries({ queryKey: [v.SEARCH_LIMIT] });
248
- }
249
- }), {
250
- mutate: Z,
251
- status: K,
252
- error: Q
253
- } = D({
254
- mutationFn: async ({
255
- inboundOfferId: t,
256
- cabinClass: i
257
- }) => {
258
- if (!h)
259
- throw new Error("No partialOfferRequestId found for round-trip fares.");
260
- return await F.getRoundTripFares({
261
- outboundOfferId: o,
262
- outboundOfferRequestId: h,
263
- inboundOfferId: t,
264
- cabinClass: i || y
265
- });
266
- },
267
- onSuccess: (t) => {
268
- const { success: i, data: a } = t;
269
- if (!i) return;
270
- const c = a.offers;
271
- f(V(c));
272
- },
273
- onError: (t) => {
274
- console.error("Error in round-trip fare search:", t);
275
- },
276
- onSettled: () => {
277
- P.invalidateQueries({ queryKey: [v.SEARCH_LIMIT] });
278
- }
279
- }), x = async (t) => {
280
- var Y;
281
- I(() => ({
282
- ...s.reduce((C, d) => (C[d.mainProgram] = -1, C), {})
283
- })), u(!0);
284
- const i = t.paymentType === U.CASH_AND_MILES ? ['"cash"', '"points"'] : ['"points"'], a = ue({
285
- originCode: t.origin,
286
- destinationCode: t.destination,
287
- dates: t.dates,
288
- cabinClass: t.cabinClass ?? y,
289
- passengerCount: t.passengers ?? $,
290
- paymentType: i
291
- });
292
- let c = [], q = 0;
293
- B = new AbortController(), l.current = setTimeout(
294
- () => {
295
- O();
296
- },
297
- (((Y = n == null ? void 0 : n.flightsConfig) == null ? void 0 : Y.streamTimeoutTotalSeconds) ?? Oe) * 1e3
298
- ), Re(re() + a, {
299
- headers: {
300
- "Content-Type": "application/json",
301
- Authorization: e ?? "",
302
- "client-id": (n == null ? void 0 : n.clientId) ?? ""
303
- },
304
- openWhenHidden: !0,
305
- signal: B.signal,
306
- onmessage(C) {
307
- try {
308
- const d = V(JSON.parse(C.data));
309
- if (d.success === !1)
310
- return;
311
- if (d.close === !0) {
312
- O();
313
- return;
314
- }
315
- if (d.airlineProgram && I((G) => ({
316
- ...G,
317
- [d.airlineProgram]: d.status
318
- })), d.status === 200 && d.flights && d.flights.length > 0) {
319
- q = 0;
320
- const G = d.flights.map((ee) => ({
321
- ...ee,
322
- partners: d.partners ?? []
323
- }));
324
- c = [...c, ...G], b({ data: c });
325
- }
326
- d.ping && (q++, q >= n.flightsConfig.streamTimeoutPingCount && O());
327
- } catch (d) {
328
- console.error("Error parsing message:", d), O();
329
- }
330
- },
331
- onerror(C) {
332
- throw console.error("EventSource error:", C), O(), C;
333
- },
334
- onclose() {
335
- O();
336
- },
337
- keepalive: !1
338
- });
339
- }, O = () => {
340
- B.abort(), l.current && (clearTimeout(l.current), l.current = null), u(!1), P.invalidateQueries({ queryKey: [v.SEARCH_LIMIT] }), I((t) => {
341
- const i = {};
342
- for (const a in t)
343
- i[a] = t[a] === -1 ? 300 : t[a];
344
- return i;
345
- });
346
- };
347
- return {
348
- /**
349
- * Loading status for searching both outbound and inbound flights
350
- * @type {boolean}
351
- * @default false
352
- */
353
- loading: H === "pending" || T === "pending" || p,
354
- /**
355
- * Loading status for fares
356
- * @type {boolean}
357
- * @default false
358
- */
359
- loadingFares: K === "pending",
360
- outboundError: _,
361
- inboundError: S,
362
- roundTripFaresError: Q,
363
- // Results
364
- outboundResults: m,
365
- inboundResults: R,
366
- roundTripFares: E,
367
- // Mutation triggers
368
- /**
369
- * Used to search for outbound flights
370
- * @type {function}
371
- *
372
- * @param {ISearchFlightArgs} args - The search arguments
373
- */
374
- searchOutboundFlights: async (t) => {
375
- switch (J(t), g([]), O(), t.paymentType) {
376
- case U.CASH_AND_MILES:
377
- x(t);
378
- break;
379
- case U.CASH:
380
- M(t);
381
- break;
382
- case U.MILES:
383
- x(t);
384
- break;
385
- }
386
- },
387
- /**
388
- * Used to search for inbound flights after selecting an outbound flight
389
- * @type {function}
390
- *
391
- * @param {{ outboundOfferId: string; cabinClass: ECabinClass }} args - The search arguments
392
- */
393
- searchInboundFlights: w,
394
- /**
395
- * Used to get round-trip fares after selecting both outbound and inbound flights
396
- * @type {function}
397
- *
398
- * @param {{ inboundOfferId: string; cabinClass: ECabinClass }} args - The fare search arguments
399
- */
400
- getRoundTripFares: Z,
401
- /**
402
- * Resets the flight search state, clearing all results and selections
403
- * @type {function}
404
- *
405
- * @returns {void}
406
- */
407
- reset: () => {
408
- O(), g([]), N([]), f([]), A(""), r("");
409
- },
410
- /**
411
- * Points search statuses of airlines during the flight search
412
- * @type {IAirlineStatuses}
413
- */
414
- airlineStatuses: L
415
- };
416
- };
417
- export {
418
- v as E,
419
- Ue as u
420
- };