@odynn/awayz-flights 0.6.7 → 0.7.0

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.
@@ -3,7 +3,7 @@ import { useAwayzContext as ir, RewardsService as S, CashValue as U, EToolTipPos
3
3
  import { useQuery as sr } from "@tanstack/react-query";
4
4
  import { g as ar } from "./index-7zRjF0bU.js";
5
5
  import { G as or, g as L, a as N, E as v, F as cr, b as lr } from "./FlightItinerary-Dy-2zMYt.js";
6
- import { E as O } from "./enums-DxmoBOKL.js";
6
+ import { E as O } from "./enums-D9aZqf8G.js";
7
7
  import "./arrayExtensions-DFLvtO8l.js";
8
8
  import mr, { useState as P, useMemo as R, useEffect as $ } from "react";
9
9
  import { h as m } from "./moment-BGjjqtLQ.js";
@@ -1,10 +1,10 @@
1
1
  import "react/jsx-runtime";
2
2
  import "@odynn/awayz-core";
3
3
  import "@tanstack/react-query";
4
- import { F as x } from "../../FlightResult-D2vAu8jO.js";
4
+ import { F as x } from "../../FlightResult-Caes2vM3.js";
5
5
  import "../../index-7zRjF0bU.js";
6
6
  import "../../FlightItinerary-Dy-2zMYt.js";
7
- import "../../enums-DxmoBOKL.js";
7
+ import "../../enums-D9aZqf8G.js";
8
8
  import "../../arrayExtensions-DFLvtO8l.js";
9
9
  import "react";
10
10
  import "../../moment-BGjjqtLQ.js";
@@ -1,4 +1,4 @@
1
- import { F as l } from "../FlightResult-D2vAu8jO.js";
1
+ import { F as l } from "../FlightResult-Caes2vM3.js";
2
2
  export {
3
3
  l as FlightResult
4
4
  };
@@ -1,4 +1,4 @@
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 || {});
1
+ var s = /* @__PURE__ */ ((r) => (r.GET_AIRPORTS = "/flights/search/airports", r.CASH_FLIGHT_SEARCH = "/flights/search/multi/one-way/cash/", r.CASH_POINTS_FLIGHT_SEARCH = "/flights/search/multi/one-way/points-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
4
  a as EWalletEndpoints
@@ -0,0 +1,4 @@
1
+ var R = /* @__PURE__ */ ((S) => (S.LOCATIONS = "LOCATIONS", S.CHECK_USER = "CHECK_USER", S.USER_REGIONS = "USER_REGIONS", S.CONVERT_CURRENCY = "CONVERT_CURRENCY", S.CLIENT_COMPONENT_KEY = "CLIENT_COMPONENT_KEY", S.SEARCH_LIMIT = "SEARCH_LIMIT", S.PROGRAMS = "PROGRAMS", S.USER_PROGRAMS = "USER_PROGRAMS", S.LINKED_USER_PROGRAMS = "LINKED_USER_PROGRAMS", S.BANKS = "BANKS", S.CARDS = "CARDS", S.USER_CARDS = "USER_CARDS", S.TRIPS = "TRIPS", S.UNCATEGORISED_BOOKINGS = "UNCATEGORISED_BOOKINGS", S.BOOKING = "BOOKING", S.VALUE_CENTS = "VALUE_CENTS", S.AVAILABILITY_ALERTS = "AVAILABILITY_ALERTS", S.ALERT_NOTIFICATIONS = "ALERT_NOTIFICATIONS", S.POINTS_AS_CASH = "POINTS_AS_CASH", S))(R || {});
2
+ export {
3
+ R as E
4
+ };
@@ -1,13 +1,13 @@
1
1
  import { useAwayzContext as V, awayzClient as _, getBaseUrl as G } from "@odynn/awayz-core";
2
- import { useMutation as M } from "@tanstack/react-query";
2
+ import { useMutation as j } from "@tanstack/react-query";
3
3
  import "../../moment-BGjjqtLQ.js";
4
4
  import "../../arrayExtensions-DFLvtO8l.js";
5
5
  import { c as U } from "../../objectUtils-CyIaVmog.js";
6
- import { E as q } from "../../enums-DxmoBOKL.js";
7
- import { useState as j, useRef as X } from "react";
8
- import { FlightService as D } from "../../services/flights/FlightsService.js";
6
+ import { E as q } from "../../enums-D9aZqf8G.js";
7
+ import { useState as x, useRef as X } from "react";
8
+ import { FlightService as k } from "../../services/flights/FlightsService.js";
9
9
  import Z from "../../stores/useFlightStore.js";
10
- import { EFlightType as J, EFlightPaymentType as k } from "../../types/enums.js";
10
+ import { EFlightType as J, EFlightPaymentType as L } from "../../types/enums.js";
11
11
  import { ECabinClass as ee } from "../../types/ECabinClass.js";
12
12
  import { mapDataToFlightDetails as te, groupFlightResults as ne, buildFlightSearchQuery as re } from "../../utils/flightUtils.js";
13
13
  async function oe(o, t) {
@@ -18,8 +18,8 @@ async function oe(o, t) {
18
18
  }
19
19
  function se(o) {
20
20
  let t, r, n, s = !1;
21
- return function(d) {
22
- t === void 0 ? (t = d, r = 0, n = -1) : t = ie(t, d);
21
+ return function(l) {
22
+ t === void 0 ? (t = l, r = 0, n = -1) : t = ie(t, l);
23
23
  const u = t.length;
24
24
  let a = 0;
25
25
  for (; r < u; ) {
@@ -46,11 +46,11 @@ function se(o) {
46
46
  function ae(o, t, r) {
47
47
  let n = z();
48
48
  const s = new TextDecoder();
49
- return function(d, u) {
50
- if (d.length === 0)
49
+ return function(l, u) {
50
+ if (l.length === 0)
51
51
  r == null || r(n), n = z();
52
52
  else if (u > 0) {
53
- const a = s.decode(d.subarray(0, u)), f = u + (d[u + 1] === 32 ? 2 : 1), b = s.decode(d.subarray(f));
53
+ const a = s.decode(l.subarray(0, u)), f = u + (l[u + 1] === 32 ? 2 : 1), b = s.decode(l.subarray(f));
54
54
  switch (a) {
55
55
  case "data":
56
56
  n.data = n.data ? n.data + `
@@ -63,8 +63,8 @@ function ae(o, t, r) {
63
63
  o(n.id = b);
64
64
  break;
65
65
  case "retry":
66
- const g = parseInt(b, 10);
67
- isNaN(g) || t(n.retry = g);
66
+ const m = parseInt(b, 10);
67
+ isNaN(m) || t(n.retry = m);
68
68
  break;
69
69
  }
70
70
  }
@@ -91,9 +91,9 @@ var ue = function(o, t) {
91
91
  return r;
92
92
  };
93
93
  const K = "text/event-stream", ce = 1e3, B = "last-event-id";
94
- function le(o, t) {
95
- var { signal: r, headers: n, onopen: s, onmessage: v, onclose: d, onerror: u, openWhenHidden: a, fetch: f } = t, b = ue(t, ["signal", "headers", "onopen", "onmessage", "onclose", "onerror", "openWhenHidden", "fetch"]);
96
- return new Promise((g, S) => {
94
+ function de(o, t) {
95
+ var { signal: r, headers: n, onopen: s, onmessage: v, onclose: l, onerror: u, openWhenHidden: a, fetch: f } = t, b = ue(t, ["signal", "headers", "onopen", "onmessage", "onclose", "onerror", "openWhenHidden", "fetch"]);
96
+ return new Promise((m, S) => {
97
97
  const p = Object.assign({}, n);
98
98
  p.accept || (p.accept = K);
99
99
  let y;
@@ -106,19 +106,19 @@ function le(o, t) {
106
106
  document.removeEventListener("visibilitychange", O), window.clearTimeout(C), y.abort();
107
107
  }
108
108
  r == null || r.addEventListener("abort", () => {
109
- T(), g();
109
+ T(), m();
110
110
  });
111
- const P = f ?? window.fetch, H = s ?? de;
111
+ const H = f ?? window.fetch, N = s ?? le;
112
112
  async function I() {
113
113
  var R;
114
114
  y = new AbortController();
115
115
  try {
116
- const E = await P(o, Object.assign(Object.assign({}, b), { headers: p, signal: y.signal }));
117
- await H(E), await oe(E.body, se(ae((h) => {
116
+ const E = await H(o, Object.assign(Object.assign({}, b), { headers: p, signal: y.signal }));
117
+ await N(E), await oe(E.body, se(ae((h) => {
118
118
  h ? p[B] = h : delete p[B];
119
119
  }, (h) => {
120
120
  F = h;
121
- }, v))), d == null || d(), T(), g();
121
+ }, v))), l == null || l(), T(), m();
122
122
  } catch (E) {
123
123
  if (!y.signal.aborted)
124
124
  try {
@@ -132,39 +132,41 @@ function le(o, t) {
132
132
  I();
133
133
  });
134
134
  }
135
- function de(o) {
135
+ function le(o) {
136
136
  const t = o.headers.get("content-type");
137
137
  if (!(t != null && t.startsWith(K)))
138
138
  throw new Error(`Expected content-type to be ${K}, Actual: ${t}`);
139
139
  }
140
- const Y = 1, L = ee.ECONOMY;
141
- let x = new AbortController();
140
+ const Y = 1, P = ee.ECONOMY;
141
+ let D = new AbortController();
142
142
  const fe = 3 * 60 * 1e3, $ = (o) => {
143
143
  if (!o.origin || !o.destination)
144
144
  throw new Error("Origin and destination are required.");
145
- if (!o.departureDate)
146
- throw new Error("Departure date is required.");
147
- if (o.flightType === J.ROUND_TRIP && !o.returnDate)
148
- throw new Error("Return date is required for round-trip flights.");
145
+ if (!o.dates)
146
+ throw new Error("At least one date is required.");
147
+ if (o.flightType === J.ROUND_TRIP && o.dates.length != 2)
148
+ throw new Error(
149
+ "Two dates are required for round-trip flights: departure and return."
150
+ );
149
151
  }, Fe = () => {
150
- const { token: o, config: t } = V(), [r, n] = j(""), [s, v] = j([]), [d, u] = j(!1), a = X(null), {
152
+ const { token: o, config: t } = V(), [r, n] = x(""), [s, v] = x([]), [l, u] = x(!1), a = X(null), {
151
153
  inboundResults: f,
152
154
  outboundResults: b,
153
- setInboundResults: g,
155
+ setInboundResults: m,
154
156
  setOutboundResults: S,
155
157
  partialOfferRequestId: p,
156
158
  setPartialOfferRequestId: y
157
159
  } = Z(), O = ({
158
160
  data: e,
159
- inbound: l
161
+ inbound: d
160
162
  }) => {
161
163
  const c = te(e);
162
- return (l ? g : S)(ne(c)), c;
164
+ return (d ? m : S)(ne(c)), c;
163
165
  }, {
164
166
  mutate: F,
165
167
  status: C,
166
168
  error: T
167
- } = M({
169
+ } = j({
168
170
  mutationFn: async (e) => {
169
171
  $(e);
170
172
  const c = {
@@ -174,22 +176,22 @@ const fe = 3 * 60 * 1e3, $ = (o) => {
174
176
  ),
175
177
  origin: e.origin || "",
176
178
  destination: e.destination || "",
177
- cabin_class: e.cabinClass ?? L
179
+ cabin_class: e.cabinClass ?? P
178
180
  };
179
181
  if (e.flightType === J.ONE_WAY) {
180
- const i = await D.cashOnlySearch({
182
+ const i = await k.cashOnlySearch({
181
183
  ...c,
182
- departure_date: e.departureDate
184
+ departure_dates: e.dates
183
185
  });
184
186
  return {
185
187
  success: i.success,
186
188
  data: i.data
187
189
  };
188
190
  } else {
189
- const i = await D.roundTripOutboundSearch({
191
+ const i = await k.roundTripOutboundSearch({
190
192
  ...c,
191
- departure_date: e.departureDate,
192
- return_date: e.returnDate
193
+ departure_date: e.dates[0],
194
+ return_date: e.dates[1]
193
195
  });
194
196
  return {
195
197
  success: i.success,
@@ -199,8 +201,8 @@ const fe = 3 * 60 * 1e3, $ = (o) => {
199
201
  }
200
202
  },
201
203
  onSuccess: (e) => {
202
- const { success: l, data: c, partialOfferRequestId: i } = e;
203
- if (!l) {
204
+ const { success: d, data: c, partialOfferRequestId: i } = e;
205
+ if (!d) {
204
206
  console.log("oh lol, it didn't work");
205
207
  return;
206
208
  }
@@ -213,25 +215,25 @@ const fe = 3 * 60 * 1e3, $ = (o) => {
213
215
  _.invalidateQueries({ queryKey: [q.SEARCH_LIMIT] });
214
216
  }
215
217
  }), {
216
- mutate: P,
217
- status: H,
218
+ mutate: H,
219
+ status: N,
218
220
  error: I
219
- } = M({
221
+ } = j({
220
222
  mutationFn: async ({
221
223
  outboundOfferId: e,
222
- cabinClass: l
224
+ cabinClass: d
223
225
  }) => {
224
226
  if (!p)
225
227
  throw new Error("No partialOfferRequestId found for inbound search.");
226
- return n(e), await D.roundTripInboundSearch({
228
+ return n(e), await k.roundTripInboundSearch({
227
229
  outboundOfferId: e,
228
230
  outboundOfferRequestId: p,
229
- cabinClass: l || L
231
+ cabinClass: d || P
230
232
  });
231
233
  },
232
234
  onSuccess: (e) => {
233
- const { success: l, data: c } = e;
234
- l && O({
235
+ const { success: d, data: c } = e;
236
+ d && O({
235
237
  data: c.offers,
236
238
  inbound: !0
237
239
  });
@@ -246,23 +248,23 @@ const fe = 3 * 60 * 1e3, $ = (o) => {
246
248
  mutate: R,
247
249
  status: E,
248
250
  error: h
249
- } = M({
251
+ } = j({
250
252
  mutationFn: async ({
251
253
  inboundOfferId: e,
252
- cabinClass: l
254
+ cabinClass: d
253
255
  }) => {
254
256
  if (!p)
255
257
  throw new Error("No partialOfferRequestId found for round-trip fares.");
256
- return await D.getRoundTripFares({
258
+ return await k.getRoundTripFares({
257
259
  outboundOfferId: r,
258
260
  outboundOfferRequestId: p,
259
261
  inboundOfferId: e,
260
- cabinClass: l || L
262
+ cabinClass: d || P
261
263
  });
262
264
  },
263
265
  onSuccess: (e) => {
264
- const { success: l, data: c } = e;
265
- if (!l) return;
266
+ const { success: d, data: c } = e;
267
+ if (!d) return;
266
268
  const i = c.offers;
267
269
  v(U(i));
268
270
  },
@@ -275,37 +277,37 @@ const fe = 3 * 60 * 1e3, $ = (o) => {
275
277
  }), Q = async (e) => {
276
278
  var W;
277
279
  u(!0);
278
- const l = e.paymentType === k.CASH_AND_MILES ? ['"cash"', '"points"'] : ['"points"'], c = re({
280
+ const d = e.paymentType === L.CASH_AND_MILES ? ['"cash"', '"points"'] : ['"points"'], c = re({
279
281
  originCode: e.origin,
280
282
  destinationCode: e.destination,
281
- departureDate: e.departureDate,
282
- cabinClass: e.cabinClass ?? L,
283
+ dates: e.dates,
284
+ cabinClass: e.cabinClass ?? P,
283
285
  passengerCount: e.passengers ?? Y,
284
- paymentType: l
286
+ paymentType: d
285
287
  });
286
- let i = [], N = 0;
287
- x = new AbortController(), a.current = setTimeout(() => {
288
+ let i = [], M = 0;
289
+ D = new AbortController(), a.current = setTimeout(() => {
288
290
  w();
289
- }, (((W = t == null ? void 0 : t.flightsConfig) == null ? void 0 : W.streamTimeoutTotalSeconds) ?? fe) * 1e3), le(G() + c, {
291
+ }, (((W = t == null ? void 0 : t.flightsConfig) == null ? void 0 : W.streamTimeoutTotalSeconds) ?? fe) * 1e3), de(G() + c, {
290
292
  headers: {
291
293
  "Content-Type": "application/json",
292
294
  Authorization: o ?? "",
293
295
  "client-id": (t == null ? void 0 : t.clientId) ?? ""
294
296
  },
295
297
  openWhenHidden: !0,
296
- signal: x.signal,
298
+ signal: D.signal,
297
299
  onmessage(A) {
298
300
  try {
299
- const m = U(JSON.parse(A.data));
300
- if (m.success === !1)
301
+ const g = U(JSON.parse(A.data));
302
+ if (g.success === !1)
301
303
  return;
302
- if (m.close === !0) {
304
+ if (g.close === !0) {
303
305
  w();
304
306
  return;
305
307
  }
306
- m.status === 200 && m.flights && m.flights.length > 0 && (N = 0, i = [...i, ...m.flights], O({ data: i })), m.ping && (N++, N >= t.flightsConfig.streamTimeoutPingCount && w());
307
- } catch (m) {
308
- console.error("Error parsing message:", m), w();
308
+ g.status === 200 && g.flights && g.flights.length > 0 && (M = 0, i = [...i, ...g.flights], O({ data: i })), g.ping && (M++, M >= t.flightsConfig.streamTimeoutPingCount && w());
309
+ } catch (g) {
310
+ console.error("Error parsing message:", g), w();
309
311
  }
310
312
  },
311
313
  onerror(A) {
@@ -317,7 +319,7 @@ const fe = 3 * 60 * 1e3, $ = (o) => {
317
319
  keepalive: !1
318
320
  });
319
321
  }, w = () => {
320
- x.abort(), a.current && (clearTimeout(a.current), a.current = null), u(!1), _.invalidateQueries({ queryKey: [q.SEARCH_LIMIT] });
322
+ D.abort(), a.current && (clearTimeout(a.current), a.current = null), u(!1), _.invalidateQueries({ queryKey: [q.SEARCH_LIMIT] });
321
323
  };
322
324
  return {
323
325
  /**
@@ -325,7 +327,7 @@ const fe = 3 * 60 * 1e3, $ = (o) => {
325
327
  * @type {boolean}
326
328
  * @default false
327
329
  */
328
- loading: C === "pending" || H === "pending" || d,
330
+ loading: C === "pending" || N === "pending" || l,
329
331
  /**
330
332
  * Loading status for fares
331
333
  * @type {boolean}
@@ -348,13 +350,13 @@ const fe = 3 * 60 * 1e3, $ = (o) => {
348
350
  */
349
351
  searchOutboundFlights: async (e) => {
350
352
  switch ($(e), S([]), w(), e.paymentType) {
351
- case k.CASH_AND_MILES:
353
+ case L.CASH_AND_MILES:
352
354
  Q(e);
353
355
  break;
354
- case k.CASH:
356
+ case L.CASH:
355
357
  F(e);
356
358
  break;
357
- case k.MILES:
359
+ case L.MILES:
358
360
  Q(e);
359
361
  break;
360
362
  }
@@ -365,7 +367,7 @@ const fe = 3 * 60 * 1e3, $ = (o) => {
365
367
  *
366
368
  * @param {{ outboundOfferId: string; cabinClass: ECabinClass }} args - The search arguments
367
369
  */
368
- searchInboundFlights: P,
370
+ searchInboundFlights: H,
369
371
  /**
370
372
  * Used to get round-trip fares after selecting both outbound and inbound flights
371
373
  * @type {function}
@@ -380,7 +382,7 @@ const fe = 3 * 60 * 1e3, $ = (o) => {
380
382
  * @returns {void}
381
383
  */
382
384
  reset: () => {
383
- w(), S([]), g([]), v([]), y(""), n("");
385
+ w(), S([]), m([]), v([]), y(""), n("");
384
386
  }
385
387
  };
386
388
  };
@@ -1,6 +1,7 @@
1
1
  export declare enum EFlightEndpoint {
2
2
  GET_AIRPORTS = "/flights/search/airports",
3
- CASH_FLIGHT_SEARCH = "/flights/search/one-way/cash",
3
+ CASH_FLIGHT_SEARCH = "/flights/search/multi/one-way/cash/",
4
+ CASH_POINTS_FLIGHT_SEARCH = "/flights/search/multi/one-way/points-cash/",
4
5
  CASH_OUTBOUND_SEARCH = "/flights/search/multi/outbound",
5
6
  CASH_INBOUND_SEARCH = "/flights/search/multi/inbound",
6
7
  ROUND_TRIP_FARES = "/flights/search/multi/fares"
@@ -15,17 +15,11 @@ export interface ISearchFlightArgs {
15
15
  */
16
16
  destination: string;
17
17
  /**
18
- * Required departure date
19
- * @type string
20
- * @example '2021-12-31'
21
- */
22
- departureDate: string;
23
- /**
24
- * Optional return date
25
- * @type string
26
- * @example '2022-01-01'
18
+ * Required dates
19
+ * @type string[]
20
+ * @example ['2021-12-31', '2022-01-05']
27
21
  */
28
- returnDate?: string;
22
+ dates: string[];
29
23
  /**
30
24
  * Optional flight type
31
25
  * @default EFlightType.ONE_WAY
@@ -30,7 +30,7 @@ export interface IAirportResponse {
30
30
  export interface IOneWayCashOnlyFlightSearchArgs {
31
31
  origin: string;
32
32
  destination: string;
33
- departure_date: string;
33
+ departure_dates: string[];
34
34
  cabin_class: string;
35
35
  passengers: TPassengerSearchArgs[];
36
36
  }
@@ -27,10 +27,10 @@ export declare const getFlightNumber: (segment: ISegment) => string;
27
27
  * @param {EFlightPaymentType} params.paymentType - The type of payment (e.g., cash, points).
28
28
  * @returns {string} The constructed flight search query URL.
29
29
  */
30
- export declare const buildFlightSearchQuery: ({ originCode, destinationCode, departureDate, cabinClass, passengerCount, paymentType }: {
30
+ export declare const buildFlightSearchQuery: ({ originCode, destinationCode, dates, cabinClass, passengerCount, paymentType }: {
31
31
  originCode: string;
32
32
  destinationCode: string;
33
- departureDate: string;
33
+ dates: string[];
34
34
  cabinClass: ECabinClass;
35
35
  passengerCount: number;
36
36
  paymentType: string[];
package/dist/main.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { useFlightSearch as o } from "./hooks/useFlightSearch/useFlightSearch.js";
2
2
  import { useAirportSearch as g } from "./hooks/useAirportSearch/useAirportSearch.js";
3
3
  import { EBaggage as s } from "./hooks/useFlightSearch/useFlightSearch.types.js";
4
- import { F as f, c as l } from "./FlightResult-D2vAu8jO.js";
4
+ import { F as f, c as l } from "./FlightResult-Caes2vM3.js";
5
5
  import { EPaymentType as x } from "./enums/EPaymentType.js";
6
6
  import { DEFAULT_AIRLINE_PROGRAM as C, getAirlineProgram as E, getFlightNumber as F, getLogoPath as c } from "./utils/flightUtils.js";
7
7
  import { isSameDayFlight as y } from "./utils/flightDateUtils.js";
@@ -1,33 +1,34 @@
1
- import { defaultAwayzConfig as K, awayzClient as j } from "@odynn/awayz-core";
2
- import { d as B, D as Q } from "../index-7zRjF0bU.js";
1
+ import { defaultAwayzConfig as H, awayzClient as K } from "@odynn/awayz-core";
2
+ import { d as B, D as Y } from "../index-7zRjF0bU.js";
3
3
  import "../arrayExtensions-DFLvtO8l.js";
4
4
  import "react";
5
- import { h as p } from "../moment-BGjjqtLQ.js";
6
- import { mapBaggageType as H } from "../hooks/useFlightSearch/useFlightSearch.types.js";
5
+ import { h as g } from "../moment-BGjjqtLQ.js";
6
+ import { EFlightEndpoint as j } from "../constants/endpoints.js";
7
+ import { mapBaggageType as Q } from "../hooks/useFlightSearch/useFlightSearch.types.js";
7
8
  import { WalletService as W } from "../services/wallet/WalletService.js";
8
9
  import { ERewardProgramCategories as J } from "../services/wallet/WalletService.types.js";
9
- const re = (t) => t == null ? void 0 : t.map((e) => {
10
- var i, l, c, n, s, a, r, o, g, m, u, d, y, b, w, F, L, D, A, h, P, T, O, k, I, R, v, _, z, E, M, G, Z, $;
10
+ const ce = (t) => t == null ? void 0 : t.map((e) => {
11
+ var a, l, c, n, s, i, r, o, p, m, u, d, y, b, F, w, L, D, A, T, P, O, h, I, k, R, _, v, E, M, $, z, G, S;
11
12
  return {
12
13
  id: e.id,
13
14
  points: (e == null ? void 0 : e.points) >= 0 ? e.points : -1,
14
15
  partial: e == null ? void 0 : e.partial,
15
16
  origin: {
16
- city: ((i = e.slices[0].segments[0].origin) == null ? void 0 : i.cityName) || ((c = (l = e.slices[0].segments[0].origin) == null ? void 0 : l.city) == null ? void 0 : c.name),
17
- country: ((n = e.slices[0].segments[0].origin) == null ? void 0 : n.iataCountryCode) || ((a = (s = e.slices[0].segments[0].origin) == null ? void 0 : s.city) == null ? void 0 : a.iataCountryCode),
18
- airportCode: ((r = e.slices[0].segments[0].origin) == null ? void 0 : r.iataCityCode) || ((g = (o = e.slices[0].segments[0].origin) == null ? void 0 : o.city) == null ? void 0 : g.iataCode),
17
+ city: ((a = e.slices[0].segments[0].origin) == null ? void 0 : a.cityName) || ((c = (l = e.slices[0].segments[0].origin) == null ? void 0 : l.city) == null ? void 0 : c.name),
18
+ country: ((n = e.slices[0].segments[0].origin) == null ? void 0 : n.iataCountryCode) || ((i = (s = e.slices[0].segments[0].origin) == null ? void 0 : s.city) == null ? void 0 : i.iataCountryCode),
19
+ airportCode: ((r = e.slices[0].segments[0].origin) == null ? void 0 : r.iataCityCode) || ((p = (o = e.slices[0].segments[0].origin) == null ? void 0 : o.city) == null ? void 0 : p.iataCode),
19
20
  coordinates: {
20
21
  latitude: (u = (m = e.slices[0].segments[0].origin) == null ? void 0 : m.city) == null ? void 0 : u.latitude,
21
22
  longitude: (y = (d = e.slices[0].segments[0].origin) == null ? void 0 : d.city) == null ? void 0 : y.longitude
22
23
  }
23
24
  },
24
25
  destination: {
25
- city: ((w = (b = e.slices[0].segments.getLast()) == null ? void 0 : b.destination) == null ? void 0 : w.cityName) || ((D = (L = (F = e.slices[0].segments.getLast()) == null ? void 0 : F.destination) == null ? void 0 : L.city) == null ? void 0 : D.name),
26
- country: ((h = (A = e.slices[0].segments.getLast()) == null ? void 0 : A.destination) == null ? void 0 : h.iataCountryCode) || ((O = (T = (P = e.slices[0].segments.getLast()) == null ? void 0 : P.destination) == null ? void 0 : T.city) == null ? void 0 : O.iataCountryCode),
27
- airportCode: ((I = (k = e.slices[0].segments.getLast()) == null ? void 0 : k.destination) == null ? void 0 : I.iataCityCode) || ((_ = (v = (R = e.slices[0].segments.getLast()) == null ? void 0 : R.destination) == null ? void 0 : v.city) == null ? void 0 : _.iataCode),
26
+ city: ((F = (b = e.slices[0].segments.getLast()) == null ? void 0 : b.destination) == null ? void 0 : F.cityName) || ((D = (L = (w = e.slices[0].segments.getLast()) == null ? void 0 : w.destination) == null ? void 0 : L.city) == null ? void 0 : D.name),
27
+ country: ((T = (A = e.slices[0].segments.getLast()) == null ? void 0 : A.destination) == null ? void 0 : T.iataCountryCode) || ((h = (O = (P = e.slices[0].segments.getLast()) == null ? void 0 : P.destination) == null ? void 0 : O.city) == null ? void 0 : h.iataCountryCode),
28
+ airportCode: ((k = (I = e.slices[0].segments.getLast()) == null ? void 0 : I.destination) == null ? void 0 : k.iataCityCode) || ((v = (_ = (R = e.slices[0].segments.getLast()) == null ? void 0 : R.destination) == null ? void 0 : _.city) == null ? void 0 : v.iataCode),
28
29
  coordinates: {
29
- latitude: (M = (E = (z = e.slices[0].segments.getLast()) == null ? void 0 : z.destination) == null ? void 0 : E.city) == null ? void 0 : M.latitude,
30
- longitude: ($ = (Z = (G = e.slices[0].segments.getLast()) == null ? void 0 : G.destination) == null ? void 0 : Z.city) == null ? void 0 : $.longitude
30
+ latitude: ($ = (M = (E = e.slices[0].segments.getLast()) == null ? void 0 : E.destination) == null ? void 0 : M.city) == null ? void 0 : $.latitude,
31
+ longitude: (S = (G = (z = e.slices[0].segments.getLast()) == null ? void 0 : z.destination) == null ? void 0 : G.city) == null ? void 0 : S.longitude
31
32
  }
32
33
  },
33
34
  airline: e.owner.name,
@@ -38,8 +39,8 @@ const re = (t) => t == null ? void 0 : t.map((e) => {
38
39
  currency: e.baseCurrency,
39
40
  flightNumber: q(e.slices[0].segments[0]),
40
41
  awayzGroupId: e.slices[0].comparisonKey || e.awayzRouteId || e.awayzGroupId || e.id,
41
- departureTime: p(e.slices[0].segments[0].departingAt).toDate(),
42
- arrivalTime: p(
42
+ departureTime: g(e.slices[0].segments[0].departingAt).toDate(),
43
+ arrivalTime: g(
43
44
  e.slices[0].segments[e.slices[0].segments.length - 1].arrivingAt
44
45
  ).toDate(),
45
46
  numberOfStops: e.slices[0].segments.length - 1,
@@ -48,8 +49,8 @@ const re = (t) => t == null ? void 0 : t.map((e) => {
48
49
  airlineProgram: e.airlineProgram,
49
50
  paymentOptions: [],
50
51
  durationMinutes: B({
51
- departureTime: p(e.slices[0].segments[0].departingAt),
52
- arrivalTime: p(e.slices[0].segments.getLast().arrivingAt),
52
+ departureTime: g(e.slices[0].segments[0].departingAt),
53
+ arrivalTime: g(e.slices[0].segments.getLast().arrivingAt),
53
54
  originTimeZone: e.slices[0].segments[0].origin.timeZone,
54
55
  destinationTimeZone: e.slices[0].segments.getLast().destination.timeZone,
55
56
  duration: e.slices[0].duration
@@ -59,32 +60,32 @@ const re = (t) => t == null ? void 0 : t.map((e) => {
59
60
  expiresAt: e.expiresAt
60
61
  };
61
62
  }), q = (t) => {
62
- const e = t.operatingCarrierFlightNumber ? t.operatingCarrier : t.marketingCarrier, i = t.operatingCarrierFlightNumber ?? t.marketingCarrierFlightNumber;
63
- return e.iataCode + " " + X(i);
64
- }, oe = ({
63
+ const e = t.operatingCarrierFlightNumber ? t.operatingCarrier : t.marketingCarrier, a = t.operatingCarrierFlightNumber ?? t.marketingCarrierFlightNumber;
64
+ return e.iataCode + " " + X(a);
65
+ }, me = ({
65
66
  originCode: t,
66
67
  destinationCode: e,
67
- departureDate: i,
68
+ dates: a,
68
69
  cabinClass: l,
69
70
  passengerCount: c,
70
71
  paymentType: n
71
72
  }) => {
72
- let s = "/flights/search/one-way/points-cash?";
73
- return s += `origin=${t}`, s += `&destination=${e}`, s += `&departure_date=${i}`, s += `&cabin_class=${l}`, s += `&adults=${c}`, s += `&cash_or_points=[${n}]`, s;
74
- }, V = (t) => t.flightDetails.slices[0].segments.map((i) => q(i)).join("_"), ce = (t) => {
73
+ let s = `${j.CASH_POINTS_FLIGHT_SEARCH}?`;
74
+ return s += `origin=${t}`, s += `&destination=${e}`, s += `&departure_dates=[${a.map((i) => `"${i}"`).join(",")}]`, s += `&cabin_class=${l}`, s += `&adults=${c}`, s += `&cash_or_points=[${n}]`, s;
75
+ }, V = (t) => t.flightDetails.slices[0].segments.map((a) => q(a)).join("_") + "_" + g(t.departureTime).format("YYYYMMDD"), le = (t) => {
75
76
  const e = {};
76
77
  t.forEach((s) => {
77
- const a = V(s);
78
- if (e[a]) {
78
+ const i = V(s);
79
+ if (e[i]) {
79
80
  const r = U(s);
80
- e[a].flight.paymentOptions.push(r);
81
- const { lowestCash: o, currency: g, lowestPoints: m } = x(
82
- e[a].flight.paymentOptions
81
+ e[i].flight.paymentOptions.push(r);
82
+ const { lowestCash: o, currency: p, lowestPoints: m } = x(
83
+ e[i].flight.paymentOptions
83
84
  );
84
- e[a].flight.points = m, e[a].flight.cash = o, g && (e[a].flight.currency = g);
85
+ e[i].flight.points = m, e[i].flight.cash = o, p && (e[i].flight.currency = p);
85
86
  } else {
86
- const { origin: r, destination: o } = s, g = [U(s)], m = x(g);
87
- e[a] = {
87
+ const { origin: r, destination: o } = s, p = [U(s)], m = x(p);
88
+ e[i] = {
88
89
  programs: [],
89
90
  flight: {
90
91
  id: s.awayzGroupId,
@@ -106,18 +107,18 @@ const re = (t) => t == null ? void 0 : t.map((e) => {
106
107
  s.flightDetails.slices[0].segments[0].operatingCarrier.iataCode
107
108
  ),
108
109
  flightNumber: s.flightNumber,
109
- paymentOptions: g,
110
+ paymentOptions: p,
110
111
  numberOfStops: s.numberOfStops,
111
112
  departureTime: s.departureTime,
112
113
  arrivalTime: s.arrivalTime,
113
- awayzGroupId: a,
114
+ awayzGroupId: i,
114
115
  duration: s.duration,
115
116
  airlineProgram: s.airlineProgram,
116
117
  durationMinutes: B({
117
- departureTime: p(
118
+ departureTime: g(
118
119
  s.flightDetails.slices[0].segments[0].departingAt
119
120
  ),
120
- arrivalTime: p(
121
+ arrivalTime: g(
121
122
  s.flightDetails.slices[0].segments.getLast().arrivingAt
122
123
  ),
123
124
  originTimeZone: s.flightDetails.slices[0].segments[0].origin.timeZone,
@@ -134,35 +135,35 @@ const re = (t) => t == null ? void 0 : t.map((e) => {
134
135
  }
135
136
  };
136
137
  }
137
- s.airlineProgram && !e[a].programs.includes(s.airlineProgram) && e[a].programs.push(s.airlineProgram);
138
+ s.airlineProgram && !e[i].programs.includes(s.airlineProgram) && e[i].programs.push(s.airlineProgram);
138
139
  });
139
- const i = [];
140
+ const a = [];
140
141
  Object.values(e).forEach((s) => {
141
- const a = s.flight.paymentOptions.filter((r) => r.cash > 0).reduce(
142
+ const i = s.flight.paymentOptions.filter((r) => r.cash > 0).reduce(
142
143
  (r, o) => o.cash < r.cash ? o : r,
143
144
  { cash: 1 / 0, carrier: { name: "", iataCode: "" } }
144
145
  );
145
146
  s.programs.length > 0 ? s.programs.forEach((r) => {
146
147
  const o = s.flight.paymentOptions.filter(
147
148
  (m) => m.program === r && m.points > 0
148
- ), g = o.length > 0 ? Math.min(...o.map((m) => m.points)) : -1;
149
- i.push({
149
+ ), p = o.length > 0 ? Math.min(...o.map((m) => m.points)) : -1;
150
+ a.push({
150
151
  ...s.flight,
151
- airline: a.carrier.name,
152
- airlineLogo: C(a.carrier.iataCode),
152
+ airline: i.carrier.name,
153
+ airlineLogo: C(i.carrier.iataCode),
153
154
  airlineProgram: r,
154
- cash: a.cash !== 1 / 0 ? a.cash : -1,
155
- points: g
155
+ cash: i.cash !== 1 / 0 ? i.cash : -1,
156
+ points: p
156
157
  });
157
- }) : i.push({
158
+ }) : a.push({
158
159
  ...s.flight,
159
- airline: a.carrier.name,
160
- airlineLogo: C(a.carrier.iataCode),
161
- cash: a.cash !== 1 / 0 ? a.cash : -1
160
+ airline: i.carrier.name,
161
+ airlineLogo: C(i.carrier.iataCode),
162
+ cash: i.cash !== 1 / 0 ? i.cash : -1
162
163
  });
163
164
  });
164
- const { cashlessResults: l, otherResults: c } = i.reduce(
165
- (s, a) => (a.cash <= 0 && a.points > 0 ? s.cashlessResults.push(a) : a.cash > 0 && s.otherResults.push(a), s),
165
+ const { cashlessResults: l, otherResults: c } = a.reduce(
166
+ (s, i) => (i.cash <= 0 && i.points > 0 ? s.cashlessResults.push(i) : i.cash > 0 && s.otherResults.push(i), s),
166
167
  { cashlessResults: [], otherResults: [] }
167
168
  ), n = c;
168
169
  return l.forEach((s) => {
@@ -170,9 +171,9 @@ const re = (t) => t == null ? void 0 : t.map((e) => {
170
171
  (r) => r.awayzGroupId === s.awayzGroupId
171
172
  ) || n.push(s);
172
173
  }), n;
173
- }, X = (t) => t ? t.replace(/^0+/, "") : "", me = (t) => `https://assets.duffel.com/img/airlines/for-light-background/full-color-logo/${t}.svg`, C = (t) => `${Q}${t}.svg`, N = K.logoFallbackImageUrl, S = {
174
- categoryLogo: N,
175
- programLogo: N,
174
+ }, X = (t) => t ? t.replace(/^0+/, "") : "", pe = (t) => `https://assets.duffel.com/img/airlines/for-light-background/full-color-logo/${t}.svg`, C = (t) => `${Y}${t}.svg`, Z = H.logoFallbackImageUrl, N = {
175
+ categoryLogo: Z,
176
+ programLogo: Z,
176
177
  awayzActive: [],
177
178
  mainProgram: "Unknown",
178
179
  displayProgram: "Unknown",
@@ -182,30 +183,30 @@ const re = (t) => t == null ? void 0 : t.map((e) => {
182
183
  colour: "#fff",
183
184
  // Using App Foreground Colour
184
185
  url: "https://www.odynn.com"
185
- }, le = async (t) => {
186
- const { airlines: e } = await j.ensureQueryData({
186
+ }, ge = async (t) => {
187
+ const { airlines: e } = await K.ensureQueryData({
187
188
  queryKey: ["walletAwards"],
188
189
  queryFn: W.getAwards,
189
190
  staleTime: 864e5
190
191
  // 24 hours
191
192
  });
192
- let i = e.find(
193
+ let a = e.find(
193
194
  (l) => {
194
- var c, n, s, a;
195
- return ((n = (c = l.mainProgram) == null ? void 0 : c.toLowerCase()) == null ? void 0 : n.includes(t == null ? void 0 : t.toLowerCase())) || ((a = (s = l.displayProgram) == null ? void 0 : s.toLowerCase()) == null ? void 0 : a.includes(t == null ? void 0 : t.toLowerCase()));
195
+ var c, n, s, i;
196
+ return ((n = (c = l.mainProgram) == null ? void 0 : c.toLowerCase()) == null ? void 0 : n.includes(t == null ? void 0 : t.toLowerCase())) || ((i = (s = l.displayProgram) == null ? void 0 : s.toLowerCase()) == null ? void 0 : i.includes(t == null ? void 0 : t.toLowerCase()));
196
197
  }
197
- ) ?? S;
198
- return i || (i = {
199
- ...S,
198
+ ) ?? N;
199
+ return a || (a = {
200
+ ...N,
200
201
  mainProgram: t,
201
202
  displayProgram: t,
202
203
  id: t
203
- }), i;
204
+ }), a;
204
205
  }, U = (t) => {
205
- var c, n, s, a, r, o, g, m, u, d;
206
- const e = ((s = (n = (c = t.flightDetails.slices.getFirst()) == null ? void 0 : c.segments.getFirst()) == null ? void 0 : n.passengers.getFirst()) == null ? void 0 : s.baggages) ?? [], i = ((o = (r = (a = t.flightDetails.slices.getFirst()) == null ? void 0 : a.segments.getFirst()) == null ? void 0 : r.passengers.getFirst()) == null ? void 0 : o.cabinClassMarketingName) ?? ((u = (m = (g = t.flightDetails.slices.getFirst()) == null ? void 0 : g.segments.getFirst()) == null ? void 0 : m.passengers.getFirst()) == null ? void 0 : u.cabinClass), l = e.map(
206
+ var c, n, s, i, r, o, p, m, u, d;
207
+ const e = ((s = (n = (c = t.flightDetails.slices.getFirst()) == null ? void 0 : c.segments.getFirst()) == null ? void 0 : n.passengers.getFirst()) == null ? void 0 : s.baggages) ?? [], a = ((o = (r = (i = t.flightDetails.slices.getFirst()) == null ? void 0 : i.segments.getFirst()) == null ? void 0 : r.passengers.getFirst()) == null ? void 0 : o.cabinClassMarketingName) ?? ((u = (m = (p = t.flightDetails.slices.getFirst()) == null ? void 0 : p.segments.getFirst()) == null ? void 0 : m.passengers.getFirst()) == null ? void 0 : u.cabinClass), l = e.map(
207
208
  (y) => ({
208
- type: H(y.type),
209
+ type: Q(y.type),
209
210
  quantity: y.quantity
210
211
  })
211
212
  );
@@ -216,7 +217,7 @@ const re = (t) => t == null ? void 0 : t.map((e) => {
216
217
  program: t.airlineProgram,
217
218
  baseCurrency: t.flightDetails.baseCurrency,
218
219
  fareBrandName: (d = t.flightDetails.slices.getFirst()) == null ? void 0 : d.fareBrandName,
219
- cabinClass: i,
220
+ cabinClass: a,
220
221
  cashFee: t.cashFee,
221
222
  conditions: t.flightDetails.conditions,
222
223
  baggages: l,
@@ -227,26 +228,26 @@ const re = (t) => t == null ? void 0 : t.map((e) => {
227
228
  };
228
229
  }, x = (t) => {
229
230
  const e = t.filter((n) => n.cash > 0);
230
- let i = { cash: 1 / 0, baseCurrency: "" };
231
+ let a = { cash: 1 / 0, baseCurrency: "" };
231
232
  for (const n of e)
232
- n.cash < i.cash && (i = n);
233
+ n.cash < a.cash && (a = n);
233
234
  const l = Math.min(
234
235
  ...t.filter((n) => n.points > 0).map((n) => n.points)
235
- ), c = i.cash;
236
+ ), c = a.cash;
236
237
  return {
237
238
  lowestCash: c === 1 / 0 ? -1 : c,
238
239
  lowestPoints: l === 1 / 0 ? -1 : l,
239
- currency: i.baseCurrency === "" ? null : i.baseCurrency
240
+ currency: a.baseCurrency === "" ? null : a.baseCurrency
240
241
  };
241
242
  };
242
243
  export {
243
- S as DEFAULT_AIRLINE_PROGRAM,
244
- oe as buildFlightSearchQuery,
245
- le as getAirlineProgram,
244
+ N as DEFAULT_AIRLINE_PROGRAM,
245
+ me as buildFlightSearchQuery,
246
+ ge as getAirlineProgram,
246
247
  q as getFlightNumber,
247
248
  C as getFullLogoPath,
248
- me as getLogoPath,
249
- ce as groupFlightResults,
250
- re as mapDataToFlightDetails,
249
+ pe as getLogoPath,
250
+ le as groupFlightResults,
251
+ ce as mapDataToFlightDetails,
251
252
  X as removeLeadingZeros
252
253
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@odynn/awayz-flights",
3
- "version": "0.6.7",
3
+ "version": "0.7.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"
@@ -1,4 +0,0 @@
1
- var S = /* @__PURE__ */ ((R) => (R.LOCATIONS = "LOCATIONS", R.CHECK_USER = "CHECK_USER", R.USER_REGIONS = "USER_REGIONS", R.CONVERT_CURRENCY = "CONVERT_CURRENCY", R.CLIENT_COMPONENT_KEY = "CLIENT_COMPONENT_KEY", R.SEARCH_LIMIT = "SEARCH_LIMIT", R.PROGRAMS = "PROGRAMS", R.USER_PROGRAMS = "USER_PROGRAMS", R.LINKED_USER_PROGRAMS = "LINKED_USER_PROGRAMS", R.BANKS = "BANKS", R.CARDS = "CARDS", R.USER_CARDS = "USER_CARDS", R.TRIPS = "TRIPS", R.UNCATEGORISED_BOOKINGS = "UNCATEGORISED_BOOKINGS", R.BOOKING = "BOOKING", R.VALUE_CENTS = "VALUE_CENTS", R.AVAILABILITY_ALERTS = "AVAILABILITY_ALERTS", R.ALERT_NOTIFICATIONS = "ALERT_NOTIFICATIONS", R))(S || {});
2
- export {
3
- S as E
4
- };