@odynn/awayz-flights 0.9.6 → 0.9.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/BookingOption-V-FzaupW.js +196 -0
  2. package/dist/FlightItinerary-C4KPpVcF.js +94 -0
  3. package/dist/_commonjsHelpers-MdHo5S7N.js +26 -0
  4. package/dist/{arrayExtensions-DFLvtO8l.js → arrayExtensions-Ce8YopTP.js} +92 -113
  5. package/dist/assets/FlightItinerary.css +1 -1
  6. package/dist/assets/FlightItineraryDropdown.css +1 -1
  7. package/dist/assets/_styles.css +1 -1
  8. package/dist/assets/_styles2.css +1 -1
  9. package/dist/assets/_styles3.css +1 -0
  10. package/dist/assets/_styles4.css +1 -0
  11. package/dist/components/BookingOption/BookingOption.js +5 -6
  12. package/dist/components/Dialog/Dialog.js +20542 -0
  13. package/dist/components/FlightItinerary/FlightItinerary.js +5 -6
  14. package/dist/components/FlightItineraryDropdown/FlightItineraryDropdown.js +23 -29
  15. package/dist/components/FlightResult/FlightResult.js +318 -284
  16. package/dist/components/HorizontalScroller/HorizontalScroller.js +4 -4
  17. package/dist/components/MiniFlightItinerary/MiniFlightItinerary.js +90 -7
  18. package/dist/components/index.js +5 -5
  19. package/dist/constants/endpoints.js +1 -1
  20. package/dist/{dateUtils-CWDSSY2R.js → dateUtils-Cb9VQiIL.js} +1 -1
  21. package/dist/enums-tLvxh02p.js +4 -0
  22. package/dist/hooks/index.js +3 -3
  23. package/dist/hooks/useAirportSearch/useAirportSearch.js +1 -1
  24. package/dist/hooks/useFlightSearch/useFlightSearch.js +422 -12
  25. package/dist/{index-nOT-DH7g.js → index-9LVJi5JO.js} +12 -8
  26. package/dist/index-Kopwbl-x.js +19 -0
  27. package/dist/lib/components/Dialog/Dialog.d.ts +9 -0
  28. package/dist/lib/components/FlightItinerary/FlightItinerary.d.ts +1 -6
  29. package/dist/lib/components/FlightItineraryDropdown/FlightItineraryDropdown.d.ts +2 -4
  30. package/dist/lib/components/FlightResult/FlightResult.d.ts +1 -1
  31. package/dist/lib/constants/endpoints.d.ts +2 -1
  32. package/dist/lib/hooks/useFlightSearch/useFlightSearch.types.d.ts +3 -2
  33. package/dist/lib/services/flights/FlightsService.d.ts +1 -0
  34. package/dist/main.js +36 -35
  35. package/dist/services/flights/FlightsService.js +38 -29
  36. package/dist/services/wallet/WalletService.js +1 -1
  37. package/dist/utils/flightUtils.js +27 -28
  38. package/package.json +2 -1
  39. package/dist/BookingOption-Bf4d2RKS.js +0 -192
  40. package/dist/FlightItinerary-C2Jp2a9c.js +0 -262
  41. package/dist/MiniFlightItinerary-BEdrqoGh.js +0 -105
  42. package/dist/index-Gj4bRuCQ.js +0 -15
  43. package/dist/index-nI16-czT.js +0 -4
  44. package/dist/useFlightSearch-C0DEmnCL.js +0 -412
@@ -1,412 +0,0 @@
1
- import { useAwayzContext as ee, useWallet as te, awayzClient as P, getBaseUrl as ne } from "@odynn/awayz-core";
2
- import { useMutation as G } from "@tanstack/react-query";
3
- import "./moment-BGjjqtLQ.js";
4
- import "./arrayExtensions-DFLvtO8l.js";
5
- import { c as Y } from "./objectUtils-3IeCVocm.js";
6
- import { useState as D, useRef as re } from "react";
7
- import { FlightService as F } from "./services/flights/FlightsService.js";
8
- import oe from "./stores/useFlightStore.js";
9
- import { EFlightType as J, EFlightPaymentType as U } from "./types/enums.js";
10
- import { ECabinClass as se } from "./types/ECabinClass.js";
11
- import { mapDataToFlightDetails as ae, groupFlightResults as ie, buildFlightSearchQuery as ce } from "./utils/flightUtils.js";
12
- async function ue(e, n) {
13
- const o = e.getReader();
14
- let r;
15
- for (; !(r = await o.read()).done; )
16
- n(r.value);
17
- }
18
- function le(e) {
19
- let n, o, r, s = !1;
20
- return function(d) {
21
- n === void 0 ? (n = d, o = 0, r = -1) : n = fe(n, d);
22
- const f = n.length;
23
- let u = 0;
24
- for (; o < f; ) {
25
- s && (n[o] === 10 && (u = ++o), s = !1);
26
- let l = -1;
27
- for (; o < f && 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 === f ? n = void 0 : u !== 0 && (n = n.subarray(u), o -= u);
43
- };
44
- }
45
- function de(e, n, o) {
46
- let r = V();
47
- const s = new TextDecoder();
48
- return function(d, f) {
49
- if (d.length === 0)
50
- o == null || o(r), r = V();
51
- else if (f > 0) {
52
- const u = s.decode(d.subarray(0, f)), l = f + (d[f + 1] === 32 ? 2 : 1), R = s.decode(d.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 fe(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 V() {
77
- return {
78
- data: "",
79
- event: "",
80
- id: "",
81
- retry: void 0
82
- };
83
- }
84
- var pe = 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 B = "text/event-stream", he = 1e3, W = "last-event-id";
93
- function Se(e, n) {
94
- var { signal: o, headers: r, onopen: s, onmessage: E, onclose: d, onerror: f, openWhenHidden: u, fetch: l } = n, R = pe(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 = B);
98
- let h;
99
- function A() {
100
- h.abort(), document.hidden || _();
101
- }
102
- u || document.addEventListener("visibilitychange", A);
103
- let L = he, 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 ?? Re;
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 ue(T.body, le(de((S) => {
117
- S ? g[W] = S : delete g[W];
118
- }, (S) => {
119
- L = S;
120
- }, E))), d == null || d(), b(), m();
121
- } catch (T) {
122
- if (!h.signal.aborted)
123
- try {
124
- const S = (w = f == null ? void 0 : f(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 Re(e) {
135
- const n = e.headers.get("content-type");
136
- if (!(n != null && n.startsWith(B)))
137
- throw new Error(`Expected content-type to be ${B}, 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 z = 1, y = se.ECONOMY;
141
- let k = new AbortController();
142
- const ge = 3 * 60 * 1e3, $ = (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 === J.ROUND_TRIP && e.dates.length != 2)
148
- throw new Error(
149
- "Two dates are required for round-trip flights: departure and return."
150
- );
151
- }, Fe = () => {
152
- const { token: e, config: n } = ee(), [o, r] = D(""), { airlinePrograms: s } = te(), [E, d] = D([]), [f, u] = D(!1), l = re(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
- } = oe(), b = ({
162
- data: t,
163
- inbound: i
164
- }) => {
165
- const a = ae(t);
166
- return (i ? N : g)(ie(a)), a;
167
- }, {
168
- mutate: M,
169
- status: H,
170
- error: _
171
- } = G({
172
- mutationFn: async (t) => {
173
- $(t);
174
- const a = {
175
- passengers: Array.from(
176
- { length: t.passengers ?? z },
177
- () => ({ type: "adult" })
178
- ),
179
- origin: t.origin || "",
180
- destination: t.destination || "",
181
- cabin_class: t.cabinClass ?? y
182
- };
183
- if (t.flightType === J.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
- } = G({
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: X,
251
- status: Z,
252
- error: K
253
- } = G({
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
- d(Y(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
- }), j = async (t) => {
280
- var x;
281
- I(() => ({
282
- ...s.reduce((C, p) => (C[p.mainProgram] = -1, C), {})
283
- })), u(!0);
284
- const i = t.paymentType === U.CASH_AND_MILES ? ['"cash"', '"points"'] : ['"points"'], a = ce({
285
- originCode: t.origin,
286
- destinationCode: t.destination,
287
- dates: t.dates,
288
- cabinClass: t.cabinClass ?? y,
289
- passengerCount: t.passengers ?? z,
290
- paymentType: i
291
- });
292
- let c = [], q = 0;
293
- k = new AbortController(), l.current = setTimeout(
294
- () => {
295
- O();
296
- },
297
- (((x = n == null ? void 0 : n.flightsConfig) == null ? void 0 : x.streamTimeoutTotalSeconds) ?? ge) * 1e3
298
- ), Se(ne() + 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: k.signal,
306
- onmessage(C) {
307
- try {
308
- const p = Y(JSON.parse(C.data));
309
- if (p.success === !1)
310
- return;
311
- if (p.close === !0) {
312
- O();
313
- return;
314
- }
315
- p.airlineProgram && I((Q) => ({
316
- ...Q,
317
- [p.airlineProgram]: p.status
318
- })), p.status === 200 && p.flights && p.flights.length > 0 && (q = 0, c = [...c, ...p.flights], b({ data: c })), p.ping && (q++, q >= n.flightsConfig.streamTimeoutPingCount && O());
319
- } catch (p) {
320
- console.error("Error parsing message:", p), O();
321
- }
322
- },
323
- onerror(C) {
324
- throw console.error("EventSource error:", C), O(), C;
325
- },
326
- onclose() {
327
- O();
328
- },
329
- keepalive: !1
330
- });
331
- }, O = () => {
332
- k.abort(), l.current && (clearTimeout(l.current), l.current = null), u(!1), P.invalidateQueries({ queryKey: [v.SEARCH_LIMIT] }), I((t) => {
333
- const i = {};
334
- for (const a in t)
335
- i[a] = t[a] === -1 ? 300 : t[a];
336
- return i;
337
- });
338
- };
339
- return {
340
- /**
341
- * Loading status for searching both outbound and inbound flights
342
- * @type {boolean}
343
- * @default false
344
- */
345
- loading: H === "pending" || T === "pending" || f,
346
- /**
347
- * Loading status for fares
348
- * @type {boolean}
349
- * @default false
350
- */
351
- loadingFares: Z === "pending",
352
- outboundError: _,
353
- inboundError: S,
354
- roundTripFaresError: K,
355
- // Results
356
- outboundResults: m,
357
- inboundResults: R,
358
- roundTripFares: E,
359
- // Mutation triggers
360
- /**
361
- * Used to search for outbound flights
362
- * @type {function}
363
- *
364
- * @param {ISearchFlightArgs} args - The search arguments
365
- */
366
- searchOutboundFlights: async (t) => {
367
- switch ($(t), g([]), O(), t.paymentType) {
368
- case U.CASH_AND_MILES:
369
- j(t);
370
- break;
371
- case U.CASH:
372
- M(t);
373
- break;
374
- case U.MILES:
375
- j(t);
376
- break;
377
- }
378
- },
379
- /**
380
- * Used to search for inbound flights after selecting an outbound flight
381
- * @type {function}
382
- *
383
- * @param {{ outboundOfferId: string; cabinClass: ECabinClass }} args - The search arguments
384
- */
385
- searchInboundFlights: w,
386
- /**
387
- * Used to get round-trip fares after selecting both outbound and inbound flights
388
- * @type {function}
389
- *
390
- * @param {{ inboundOfferId: string; cabinClass: ECabinClass }} args - The fare search arguments
391
- */
392
- getRoundTripFares: X,
393
- /**
394
- * Resets the flight search state, clearing all results and selections
395
- * @type {function}
396
- *
397
- * @returns {void}
398
- */
399
- reset: () => {
400
- O(), g([]), N([]), d([]), A(""), r("");
401
- },
402
- /**
403
- * Points search statuses of airlines during the flight search
404
- * @type {IAirlineStatuses}
405
- */
406
- airlineStatuses: L
407
- };
408
- };
409
- export {
410
- v as E,
411
- Fe as u
412
- };