@odynn/awayz-flights 0.9.8 → 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.
@@ -1,11 +1,11 @@
1
- import { useAwayzContext as te, awayzClient as q, getBaseUrl as ne } from "@odynn/awayz-core";
2
- import { useQuery as re, useMutation as j } from "@tanstack/react-query";
1
+ import { useAwayzContext as te, awayzClient as P, getBaseUrl as ne } from "@odynn/awayz-core";
2
+ import { useQuery as re, useMutation as x } from "@tanstack/react-query";
3
3
  import "../../moment-BGjjqtLQ.js";
4
4
  import "../../arrayExtensions-Ce8YopTP.js";
5
5
  import { c as z } from "../../objectUtils-3IeCVocm.js";
6
6
  import { E as A } from "../../enums-tLvxh02p.js";
7
- import { useState as x, useRef as oe } from "react";
8
- import { FlightService as P } from "../../services/flights/FlightsService.js";
7
+ import { useState as D, useRef as oe } from "react";
8
+ import { FlightService as _ } from "../../services/flights/FlightsService.js";
9
9
  import se from "../../stores/useFlightStore.js";
10
10
  import { EFlightType as J, EFlightPaymentType as k } from "../../types/enums.js";
11
11
  import { ECabinClass as ae } from "../../types/ECabinClass.js";
@@ -92,40 +92,40 @@ var he = function(o, t) {
92
92
  };
93
93
  const Q = "text/event-stream", ge = 1e3, Y = "last-event-id";
94
94
  function me(o, t) {
95
- var { signal: r, headers: n, onopen: s, onmessage: O, onclose: f, onerror: d, openWhenHidden: u, fetch: p } = t, m = he(t, ["signal", "headers", "onopen", "onmessage", "onclose", "onerror", "openWhenHidden", "fetch"]);
96
- return new Promise((y, T) => {
95
+ var { signal: r, headers: n, onopen: s, onmessage: E, onclose: f, onerror: d, openWhenHidden: u, fetch: p } = t, m = he(t, ["signal", "headers", "onopen", "onmessage", "onclose", "onerror", "openWhenHidden", "fetch"]);
96
+ return new Promise((y, R) => {
97
97
  const h = Object.assign({}, n);
98
98
  h.accept || (h.accept = Q);
99
99
  let b;
100
- function _() {
100
+ function q() {
101
101
  b.abort(), document.hidden || I();
102
102
  }
103
- u || document.addEventListener("visibilitychange", _);
104
- let E = ge, R = 0;
105
- function v() {
106
- document.removeEventListener("visibilitychange", _), window.clearTimeout(R), b.abort();
103
+ u || document.addEventListener("visibilitychange", q);
104
+ let C = ge, v = 0;
105
+ function S() {
106
+ document.removeEventListener("visibilitychange", q), window.clearTimeout(v), b.abort();
107
107
  }
108
108
  r == null || r.addEventListener("abort", () => {
109
- v(), y();
109
+ S(), y();
110
110
  });
111
111
  const N = p ?? window.fetch, H = s ?? ye;
112
112
  async function I() {
113
113
  var F;
114
114
  b = new AbortController();
115
115
  try {
116
- const C = await N(o, Object.assign(Object.assign({}, m), { headers: h, signal: b.signal }));
117
- await H(C), await le(C.body, de(fe((g) => {
116
+ const T = await N(o, Object.assign(Object.assign({}, m), { headers: h, signal: b.signal }));
117
+ await H(T), await le(T.body, de(fe((g) => {
118
118
  g ? h[Y] = g : delete h[Y];
119
119
  }, (g) => {
120
- E = g;
121
- }, O))), f == null || f(), v(), y();
122
- } catch (C) {
120
+ C = g;
121
+ }, E))), f == null || f(), S(), y();
122
+ } catch (T) {
123
123
  if (!b.signal.aborted)
124
124
  try {
125
- const g = (F = d == null ? void 0 : d(C)) !== null && F !== void 0 ? F : E;
126
- window.clearTimeout(R), R = window.setTimeout(I, g);
125
+ const g = (F = d == null ? void 0 : d(T)) !== null && F !== void 0 ? F : C;
126
+ window.clearTimeout(v), v = window.setTimeout(I, g);
127
127
  } catch (g) {
128
- v(), T(g);
128
+ S(), R(g);
129
129
  }
130
130
  }
131
131
  }
@@ -149,30 +149,29 @@ const be = 3 * 60 * 1e3, G = (o) => {
149
149
  "Two dates are required for round-trip flights: departure and return."
150
150
  );
151
151
  }, Le = () => {
152
- const { token: o, config: t } = te(), [r, n] = x(""), [s, O] = x([]), [f, d] = x(!1), u = oe(null), {
152
+ const { token: o, config: t } = te(), [r, n] = D(""), [s, E] = D([]), [f, d] = D(!1), u = oe(null), {
153
153
  inboundResults: p,
154
154
  outboundResults: m,
155
155
  setInboundResults: y,
156
- setOutboundResults: T,
156
+ setOutboundResults: R,
157
157
  partialOfferRequestId: h,
158
158
  setPartialOfferRequestId: b,
159
- airlineStatuses: _,
160
- setAirlineStatuses: E
161
- } = se(), { data: R } = re({
159
+ airlineStatuses: q,
160
+ setAirlineStatuses: C
161
+ } = se(), { data: v } = re({
162
162
  queryKey: [A.SUPPORTED_AIRLINE_PROGRAMS],
163
- queryFn: P.getSupportedAirlinePrograms,
164
- initialData: []
165
- }), v = ({
163
+ queryFn: _.getSupportedAirlinePrograms
164
+ }), S = ({
166
165
  data: e,
167
166
  inbound: c
168
167
  }) => {
169
168
  const i = ie(e);
170
- return (c ? y : T)(ue(i)), i;
169
+ return (c ? y : R)(ue(i)), i;
171
170
  }, {
172
171
  mutate: N,
173
172
  status: H,
174
173
  error: I
175
- } = j({
174
+ } = x({
176
175
  mutationFn: async (e) => {
177
176
  G(e);
178
177
  const i = {
@@ -185,7 +184,7 @@ const be = 3 * 60 * 1e3, G = (o) => {
185
184
  cabin_class: e.cabinClass ?? L
186
185
  };
187
186
  if (e.flightType === J.ONE_WAY) {
188
- const a = await P.cashOnlySearch({
187
+ const a = await _.cashOnlySearch({
189
188
  ...i,
190
189
  departure_dates: e.dates
191
190
  });
@@ -194,7 +193,7 @@ const be = 3 * 60 * 1e3, G = (o) => {
194
193
  data: a.data
195
194
  };
196
195
  } else {
197
- const a = await P.roundTripOutboundSearch({
196
+ const a = await _.roundTripOutboundSearch({
198
197
  ...i,
199
198
  departure_date: e.dates[0],
200
199
  return_date: e.dates[1]
@@ -212,26 +211,26 @@ const be = 3 * 60 * 1e3, G = (o) => {
212
211
  console.log("oh lol, it didn't work");
213
212
  return;
214
213
  }
215
- v({ data: i }), a && b(a);
214
+ S({ data: i }), a && b(a);
216
215
  },
217
216
  onError: (e) => {
218
217
  console.error("Error in outbound flight search:", e);
219
218
  },
220
219
  onSettled: () => {
221
- q.invalidateQueries({ queryKey: [A.SEARCH_LIMIT] });
220
+ P.invalidateQueries({ queryKey: [A.SEARCH_LIMIT] });
222
221
  }
223
222
  }), {
224
223
  mutate: F,
225
- status: C,
224
+ status: T,
226
225
  error: g
227
- } = j({
226
+ } = x({
228
227
  mutationFn: async ({
229
228
  outboundOfferId: e,
230
229
  cabinClass: c
231
230
  }) => {
232
231
  if (!h)
233
232
  throw new Error("No partialOfferRequestId found for inbound search.");
234
- return n(e), await P.roundTripInboundSearch({
233
+ return n(e), await _.roundTripInboundSearch({
235
234
  outboundOfferId: e,
236
235
  outboundOfferRequestId: h,
237
236
  cabinClass: c || L
@@ -239,7 +238,7 @@ const be = 3 * 60 * 1e3, G = (o) => {
239
238
  },
240
239
  onSuccess: (e) => {
241
240
  const { success: c, data: i } = e;
242
- c && v({
241
+ c && S({
243
242
  data: i.offers,
244
243
  inbound: !0
245
244
  });
@@ -248,20 +247,20 @@ const be = 3 * 60 * 1e3, G = (o) => {
248
247
  console.error("Error in inbound flight search:", e);
249
248
  },
250
249
  onSettled: () => {
251
- q.invalidateQueries({ queryKey: [A.SEARCH_LIMIT] });
250
+ P.invalidateQueries({ queryKey: [A.SEARCH_LIMIT] });
252
251
  }
253
252
  }), {
254
253
  mutate: V,
255
254
  status: X,
256
255
  error: Z
257
- } = j({
256
+ } = x({
258
257
  mutationFn: async ({
259
258
  inboundOfferId: e,
260
259
  cabinClass: c
261
260
  }) => {
262
261
  if (!h)
263
262
  throw new Error("No partialOfferRequestId found for round-trip fares.");
264
- return await P.getRoundTripFares({
263
+ return await _.getRoundTripFares({
265
264
  outboundOfferId: r,
266
265
  outboundOfferRequestId: h,
267
266
  inboundOfferId: e,
@@ -272,18 +271,18 @@ const be = 3 * 60 * 1e3, G = (o) => {
272
271
  const { success: c, data: i } = e;
273
272
  if (!c) return;
274
273
  const a = i.offers;
275
- O(z(a));
274
+ E(z(a));
276
275
  },
277
276
  onError: (e) => {
278
277
  console.error("Error in round-trip fare search:", e);
279
278
  },
280
279
  onSettled: () => {
281
- q.invalidateQueries({ queryKey: [A.SEARCH_LIMIT] });
280
+ P.invalidateQueries({ queryKey: [A.SEARCH_LIMIT] });
282
281
  }
283
282
  }), W = async (e) => {
284
283
  var U;
285
- E(() => ({
286
- ...R.reduce((S, l) => (S[l] = -1, S), {})
284
+ C(() => ({
285
+ ...v == null ? void 0 : v.reduce((O, l) => (O[l] = -1, O), {})
287
286
  })), d(!0);
288
287
  const c = e.paymentType === k.CASH_AND_MILES ? ['"cash"', '"points"'] : ['"points"'], i = ce({
289
288
  originCode: e.origin,
@@ -307,33 +306,33 @@ const be = 3 * 60 * 1e3, G = (o) => {
307
306
  },
308
307
  openWhenHidden: !0,
309
308
  signal: K.signal,
310
- onmessage(S) {
309
+ onmessage(O) {
311
310
  try {
312
- const l = z(JSON.parse(S.data));
311
+ const l = z(JSON.parse(O.data));
313
312
  if (l.success === !1)
314
313
  return;
315
314
  if (l.close === !0) {
316
315
  w();
317
316
  return;
318
317
  }
319
- if (l.airlineProgram && E((D) => ({
320
- ...D,
318
+ if (l.airlineProgram && C((j) => ({
319
+ ...j,
321
320
  [l.airlineProgram]: l.status ?? l.statusCode ?? 300
322
321
  })), l.status === 200 && l.flights && l.flights.length > 0) {
323
322
  M = 0;
324
- const D = l.flights.map((ee) => ({
323
+ const j = l.flights.map((ee) => ({
325
324
  ...ee,
326
325
  partners: l.partners ?? []
327
326
  }));
328
- a = [...a, ...D], v({ data: a });
327
+ a = [...a, ...j], S({ data: a });
329
328
  }
330
329
  l.ping && (M++, M >= t.flightsConfig.streamTimeoutPingCount && w());
331
330
  } catch (l) {
332
331
  console.error("Error parsing message:", l), w();
333
332
  }
334
333
  },
335
- onerror(S) {
336
- throw console.error("EventSource error:", S), w(), S;
334
+ onerror(O) {
335
+ throw console.error("EventSource error:", O), w(), O;
337
336
  },
338
337
  onclose() {
339
338
  w();
@@ -341,7 +340,7 @@ const be = 3 * 60 * 1e3, G = (o) => {
341
340
  keepalive: !1
342
341
  });
343
342
  }, w = () => {
344
- K.abort(), u.current && (clearTimeout(u.current), u.current = null), d(!1), q.invalidateQueries({ queryKey: [A.SEARCH_LIMIT] }), E((e) => {
343
+ K.abort(), u.current && (clearTimeout(u.current), u.current = null), d(!1), P.invalidateQueries({ queryKey: [A.SEARCH_LIMIT] }), C((e) => {
345
344
  const c = {};
346
345
  for (const i in e) {
347
346
  const a = e[i];
@@ -356,7 +355,7 @@ const be = 3 * 60 * 1e3, G = (o) => {
356
355
  * @type {boolean}
357
356
  * @default false
358
357
  */
359
- loading: H === "pending" || C === "pending" || f,
358
+ loading: H === "pending" || T === "pending" || f,
360
359
  /**
361
360
  * Loading status for fares
362
361
  * @type {boolean}
@@ -378,7 +377,7 @@ const be = 3 * 60 * 1e3, G = (o) => {
378
377
  * @param {ISearchFlightArgs} args - The search arguments
379
378
  */
380
379
  searchOutboundFlights: async (e) => {
381
- switch (G(e), T([]), w(), e.paymentType) {
380
+ switch (G(e), R([]), w(), e.paymentType) {
382
381
  case k.CASH_AND_MILES:
383
382
  W(e);
384
383
  break;
@@ -411,13 +410,13 @@ const be = 3 * 60 * 1e3, G = (o) => {
411
410
  * @returns {void}
412
411
  */
413
412
  reset: () => {
414
- w(), T([]), y([]), O([]), b(""), n("");
413
+ w(), R([]), y([]), E([]), b(""), n("");
415
414
  },
416
415
  /**
417
416
  * Points search statuses of airlines during the flight search
418
417
  * @type {IAirlineStatuses}
419
418
  */
420
- airlineStatuses: _
419
+ airlineStatuses: q
421
420
  };
422
421
  };
423
422
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@odynn/awayz-flights",
3
- "version": "0.9.8",
3
+ "version": "0.9.9",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"