@odynn/awayz-flights 0.1.8 → 0.1.10

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,4 +1,4 @@
1
- import { useState as o } from "react";
1
+ import { useState as n } from "react";
2
2
  import { useMutation as i } from "@tanstack/react-query";
3
3
  import { ECabinClass as w, EFlightType as d } from "../../types/enums.js";
4
4
  import { FlightService as a } from "../../services/flights/FlightsService.js";
@@ -11,17 +11,17 @@ const q = 1, F = w.ECONOMY, I = (r) => {
11
11
  if (r.flightType === d.ROUND_TRIP && !r.returnDate)
12
12
  throw new Error("Return date is required for round-trip flights.");
13
13
  }, v = () => {
14
- const [r, c] = o(""), [l, f] = o([]), [p, h] = o([]), u = ({
14
+ const [r, c] = n(""), [l, f] = n([]), [p, h] = n([]), u = ({
15
15
  data: t,
16
- previousResults: n,
16
+ previousResults: o,
17
17
  inbound: s
18
18
  }) => {
19
- const e = S(t, n);
19
+ const e = S(t, o);
20
20
  return (s ? h : f)(_(e)), e;
21
21
  }, {
22
22
  mutate: b,
23
- status: m,
24
- error: R
23
+ status: g,
24
+ error: m
25
25
  } = i({
26
26
  mutationFn: async (t) => {
27
27
  I(t);
@@ -50,21 +50,26 @@ const q = 1, F = w.ECONOMY, I = (r) => {
50
50
  return_date: t.returnDate
51
51
  });
52
52
  return {
53
- success: e.data.success,
54
- data: e.data.data,
53
+ success: e.success,
54
+ data: e.data.offers,
55
55
  partialOfferRequestId: e.data.id
56
56
  };
57
57
  }
58
58
  },
59
59
  onSuccess: (t) => {
60
- const { success: n, data: s, partialOfferRequestId: e } = t;
61
- n && (u({ data: s }), e && c(e));
60
+ console.log({ result: t });
61
+ const { success: o, data: s, partialOfferRequestId: e } = t;
62
+ if (!o) {
63
+ console.log("oh lol, it didn't work");
64
+ return;
65
+ }
66
+ u({ data: s }), e && c(e);
62
67
  },
63
68
  onError: (t) => {
64
69
  console.error("Error in outbound flight search:", t);
65
70
  }
66
71
  }), {
67
- mutate: g,
72
+ mutate: R,
68
73
  status: O,
69
74
  error: E
70
75
  } = i({
@@ -77,8 +82,8 @@ const q = 1, F = w.ECONOMY, I = (r) => {
77
82
  });
78
83
  },
79
84
  onSuccess: (t) => {
80
- const { success: n, data: s } = t;
81
- n && u({
85
+ const { success: o, data: s } = t;
86
+ o && u({
82
87
  data: s.offers,
83
88
  inbound: !0
84
89
  });
@@ -88,15 +93,15 @@ const q = 1, F = w.ECONOMY, I = (r) => {
88
93
  }
89
94
  });
90
95
  return {
91
- loading: m === "pending" || O === "pending",
92
- outboundError: R,
96
+ loading: g === "pending" || O === "pending",
97
+ outboundError: m,
93
98
  inboundError: E,
94
99
  // Results
95
100
  outboundResults: l,
96
101
  inboundResults: p,
97
102
  // Mutation triggers
98
103
  searchOutboundFlights: b,
99
- searchInboundFlights: g
104
+ searchInboundFlights: R
100
105
  };
101
106
  };
102
107
  export {
@@ -90,6 +90,7 @@ export interface IFlightPaymentOption {
90
90
  }
91
91
  export interface IFlightResult {
92
92
  id: string;
93
+ partial: boolean;
93
94
  airline: string;
94
95
  flightNumber: string;
95
96
  origin: IAirportLocation;
@@ -5,7 +5,15 @@ import { IAirport } from '../../hooks/useAirportSearch/useAirportSearch.types';
5
5
  declare class _FlightService {
6
6
  getAirports: (searchTerm: string) => Promise<IAirport[]>;
7
7
  cashOnlySearch: (args: IOneWayCashOnlyFlightSearchArgs) => Promise<TServiceResponse<IFlightOffer[]>>;
8
- roundTripOutboundSearch: (args: IRoundCashOnlyFlightSearchArgs) => Promise<any>;
8
+ roundTripOutboundSearch: (args: IRoundCashOnlyFlightSearchArgs) => Promise<{
9
+ success: any;
10
+ data: any;
11
+ message?: undefined;
12
+ } | {
13
+ success: boolean;
14
+ message: any;
15
+ data?: undefined;
16
+ }>;
9
17
  roundTripInboundSearch: (args: any) => Promise<any>;
10
18
  }
11
19
  export declare const FlightService: _FlightService;
@@ -1,22 +1,22 @@
1
1
  var r = Object.defineProperty;
2
2
  var l = (t, s, a) => s in t ? r(t, s, { enumerable: !0, configurable: !0, writable: !0, value: a }) : t[s] = a;
3
- var o = (t, s, a) => l(t, typeof s != "symbol" ? s + "" : s, a);
3
+ var d = (t, s, a) => l(t, typeof s != "symbol" ? s + "" : s, a);
4
4
  import "../../arrayExtensions-DWKenJCh.js";
5
- import { EFlightEndpoint as d } from "../../constants/endpoints.js";
6
- import { clientInstance as m } from "@odynn/awayz-auth";
7
- function g(t) {
5
+ import { EFlightEndpoint as m } from "../../constants/endpoints.js";
6
+ import { clientInstance as i } from "@odynn/awayz-auth";
7
+ function y(t) {
8
8
  return t = t.replace(/^_+/, ""), t.replace(/_([a-z])/g, (s, a) => a.toUpperCase());
9
9
  }
10
- const i = (t) => Array.isArray(t) ? t.map((s) => i(s)) : typeof t == "object" && t !== null ? Object.keys(t).reduce((s, a) => {
11
- const n = g(a);
12
- return s[n] = i(t[a]), s;
10
+ const o = (t) => Array.isArray(t) ? t.map((s) => o(s)) : typeof t == "object" && t !== null ? Object.keys(t).reduce((s, a) => {
11
+ const n = y(a);
12
+ return s[n] = o(t[a]), s;
13
13
  }, {}) : t;
14
- class y {
14
+ class g {
15
15
  constructor() {
16
- o(this, "getAirports", async (s) => {
16
+ d(this, "getAirports", async (s) => {
17
17
  try {
18
- const { data: a } = await m.get(
19
- `${d.GET_AIRPORTS}?search_term=${s}`
18
+ const { data: a } = await i.get(
19
+ `${m.GET_AIRPORTS}?search_term=${s}`
20
20
  );
21
21
  return a.data.map((e) => {
22
22
  var u;
@@ -44,16 +44,16 @@ class y {
44
44
  return [];
45
45
  }
46
46
  });
47
- o(this, "cashOnlySearch", async (s) => {
47
+ d(this, "cashOnlySearch", async (s) => {
48
48
  var a, n, e, u;
49
49
  try {
50
- const { data: c } = await m.post(
51
- d.CASH_FLIGHT_SEARCH,
50
+ const { data: c } = await i.post(
51
+ m.CASH_FLIGHT_SEARCH,
52
52
  s
53
53
  );
54
54
  return c.success ? {
55
55
  success: !0,
56
- data: i(
56
+ data: o(
57
57
  c.data.offers
58
58
  )
59
59
  } : {
@@ -70,15 +70,18 @@ class y {
70
70
  };
71
71
  }
72
72
  });
73
- o(this, "roundTripOutboundSearch", async (s) => {
73
+ d(this, "roundTripOutboundSearch", async (s) => {
74
74
  var a, n;
75
75
  try {
76
- const { data: e } = await m.post(
77
- d.CASH_OUTBOUND_SEARCH,
78
- { ...s, to: "2025-06-07", from: s.departure_date }
76
+ const { data: e } = await i.post(
77
+ m.CASH_OUTBOUND_SEARCH,
78
+ { ...s, to: s.return_date, from: s.departure_date }
79
79
  );
80
80
  if (!e.success) throw e;
81
- return e;
81
+ return {
82
+ success: e.success,
83
+ data: o(e.data)
84
+ };
82
85
  } catch (e) {
83
86
  return {
84
87
  success: !1,
@@ -86,17 +89,17 @@ class y {
86
89
  };
87
90
  }
88
91
  });
89
- o(this, "roundTripInboundSearch", async (s) => {
92
+ d(this, "roundTripInboundSearch", async (s) => {
90
93
  var a, n;
91
94
  try {
92
- const { data: e } = await m.get(
93
- d.CASH_INBOUND_SEARCH,
95
+ const { data: e } = await i.get(
96
+ m.CASH_INBOUND_SEARCH,
94
97
  {
95
98
  params: s
96
99
  }
97
100
  );
98
101
  if (!e.success) throw e;
99
- return e;
102
+ return o(e);
100
103
  } catch (e) {
101
104
  return {
102
105
  success: !1,
@@ -106,7 +109,7 @@ class y {
106
109
  });
107
110
  }
108
111
  }
109
- const C = new y();
112
+ const C = new g();
110
113
  export {
111
114
  C as FlightService
112
115
  };
@@ -1,12 +1,13 @@
1
1
  import { h as F } from "../arrayExtensions-DWKenJCh.js";
2
2
  import { c as z } from "../dateUtils-DeNLG5hw.js";
3
- const L = (a) => a == null ? void 0 : a.map((e) => {
4
- var c, r, t, o, i, s, l, h, g, I, f, T, M, w, b, d, p, n, y, C, N, m, u, D;
3
+ const L = (r) => r == null ? void 0 : r.map((e) => {
4
+ var c, a, t, o, i, s, l, h, g, I, T, f, M, w, b, d, p, n, y, C, N, m, u, D;
5
5
  return {
6
6
  id: e.id,
7
7
  points: (e == null ? void 0 : e.points) >= 0 ? e.points : -1,
8
+ partial: e.partial,
8
9
  origin: {
9
- city: e.slices[0].segments[0].origin.cityName || ((r = (c = e.slices[0].segments[0].origin) == null ? void 0 : c.city) == null ? void 0 : r.name),
10
+ city: e.slices[0].segments[0].origin.cityName || ((a = (c = e.slices[0].segments[0].origin) == null ? void 0 : c.city) == null ? void 0 : a.name),
10
11
  country: e.slices[0].segments[0].origin.iataCountryCode || ((t = e.slices[0].segments[0].origin) == null ? void 0 : t.city.iataCountryCode),
11
12
  airportCode: e.slices[0].segments[0].origin.iataCityCode || e.slices[0].segments[0].origin.city.iataCode,
12
13
  coordinates: {
@@ -16,7 +17,7 @@ const L = (a) => a == null ? void 0 : a.map((e) => {
16
17
  },
17
18
  destination: {
18
19
  city: ((i = (o = e.slices[0].segments.getLast()) == null ? void 0 : o.destination) == null ? void 0 : i.cityName) || ((h = (l = (s = e.slices[0].segments.getLast()) == null ? void 0 : s.destination) == null ? void 0 : l.city) == null ? void 0 : h.name),
19
- country: ((I = (g = e.slices[0].segments.getLast()) == null ? void 0 : g.destination) == null ? void 0 : I.iataCountryCode) || ((M = (T = (f = e.slices[0].segments.getLast()) == null ? void 0 : f.destination) == null ? void 0 : T.city) == null ? void 0 : M.iataCountryCode),
20
+ country: ((I = (g = e.slices[0].segments.getLast()) == null ? void 0 : g.destination) == null ? void 0 : I.iataCountryCode) || ((M = (f = (T = e.slices[0].segments.getLast()) == null ? void 0 : T.destination) == null ? void 0 : f.city) == null ? void 0 : M.iataCountryCode),
20
21
  airportCode: ((b = (w = e.slices[0].segments.getLast()) == null ? void 0 : w.destination) == null ? void 0 : b.iataCityCode) || ((n = (p = (d = e.slices[0].segments.getLast()) == null ? void 0 : d.destination) == null ? void 0 : p.city) == null ? void 0 : n.iataCode),
21
22
  coordinates: {
22
23
  latitude: (N = (C = (y = e.slices[0].segments.getLast()) == null ? void 0 : y.destination) == null ? void 0 : C.city) == null ? void 0 : N.latitude,
@@ -44,20 +45,20 @@ const L = (a) => a == null ? void 0 : a.map((e) => {
44
45
  duration: e.slices[0].duration
45
46
  })
46
47
  };
47
- }), O = (a, e) => {
48
+ }), O = (r, e) => {
48
49
  if (!(e != null && e.length))
49
- return L(a);
50
+ return L(r);
50
51
  const c = [...e];
51
- let r = [];
52
+ let a = [];
52
53
  const t = {};
53
- for (const i of a) {
54
+ for (const i of r) {
54
55
  const s = i.slices[0].segments, l = s[0], h = {
55
56
  iataCode: l.operatingCarrier.iataCode,
56
57
  flightNumber: l.operatingCarrierFlightNumber
57
58
  }, g = {
58
59
  iataCode: l.marketingCarrier.iataCode,
59
60
  flightNumber: l.marketingCarrierFlightNumber
60
- }, I = i.awayzMatchId, f = `${h.iataCode}_${g.iataCode}-${g.flightNumber}`, T = i.awayzMarketerMatchId, M = !!h.flightNumber && h.flightNumber != "", w = !!g.flightNumber && g.flightNumber != "", b = c.filter((d, p) => {
61
+ }, I = i.awayzMatchId, T = `${h.iataCode}_${g.iataCode}-${g.flightNumber}`, f = i.awayzMarketerMatchId, M = !!h.flightNumber && h.flightNumber != "", w = !!g.flightNumber && g.flightNumber != "", b = c.filter((d, p) => {
61
62
  const n = d.flightDetails, y = d.flightDetails.slices[0].segments[0].operatingCarrierFlightNumber, C = n.id && // TODO: Maybe expand on this - Id check ensures it is a duffel flight
62
63
  !!y && y !== "";
63
64
  if (!(n.slices[0].segments.length === (s == null ? void 0 : s.length) && !n.slices[0].segments.find(
@@ -65,7 +66,7 @@ const L = (a) => a == null ? void 0 : a.map((e) => {
65
66
  )))
66
67
  return !1;
67
68
  let m = !1;
68
- return (w && M && n.awayzMatchId === I || !C && n.awayzMatchId === f || M && !w && n.awayzMarketerMatchId === T) && (m = !0), m && (t[n.id] = p), m;
69
+ return (w && M && n.awayzMatchId === I || !C && n.awayzMatchId === T || M && !w && n.awayzMarketerMatchId === f) && (m = !0), m && (t[n.id] = p), m;
69
70
  });
70
71
  if (b.length) {
71
72
  i.slices[0].comparisonKey = b[0].awayzGroupId;
@@ -91,37 +92,38 @@ const L = (a) => a == null ? void 0 : a.map((e) => {
91
92
  };
92
93
  c[p] = n;
93
94
  } else
94
- r.push(i);
95
+ a.push(i);
95
96
  } else
96
- r.push(i);
97
+ a.push(i);
97
98
  }
98
99
  return [
99
100
  ...c,
100
- ...L(r) ?? []
101
+ ...L(a) ?? []
101
102
  ];
102
- }, A = (a) => {
103
- const e = a.operatingCarrierFlightNumber ? a.operatingCarrier : a.marketingCarrier, c = a.operatingCarrierFlightNumber ?? a.marketingCarrierFlightNumber;
103
+ }, A = (r) => {
104
+ const e = r.operatingCarrierFlightNumber ? r.operatingCarrier : r.marketingCarrier, c = r.operatingCarrierFlightNumber ?? r.marketingCarrierFlightNumber;
104
105
  return e.iataCode + " " + c;
105
106
  }, P = ({
106
- originCode: a,
107
+ originCode: r,
107
108
  destinationCode: e,
108
109
  departureDate: c,
109
- cabinClass: r,
110
+ cabinClass: a,
110
111
  passengerCount: t,
111
112
  paymentType: o
112
113
  }) => {
113
114
  let i = "/flights/search/one-way/points-cash?";
114
- return i += `origin=${a}`, i += `&destination=${e}`, i += `&departure_date=${c}`, i += `&cabin_class=${r}`, i += `&adults=${t}`, i += `&cash_or_points=[${o}]`, i;
115
- }, $ = (a) => {
116
- const e = a.reduce((r, t) => {
115
+ return i += `origin=${r}`, i += `&destination=${e}`, i += `&departure_date=${c}`, i += `&cabin_class=${a}`, i += `&adults=${t}`, i += `&cash_or_points=[${o}]`, i;
116
+ }, $ = (r) => {
117
+ const e = r.reduce((a, t) => {
117
118
  const o = t.awayzGroupId;
118
- return r[o] || (r[o] = []), r[o].push(t), r;
119
+ return a[o] || (a[o] = []), a[o].push(t), a;
119
120
  }, {});
120
121
  return Object.values(e).map(
121
- (r) => {
122
- const t = r[0], { origin: o, destination: i } = t;
122
+ (a) => {
123
+ const t = a[0], { origin: o, destination: i } = t;
123
124
  return {
124
125
  id: t.awayzGroupId,
126
+ partial: t.partial,
125
127
  origin: {
126
128
  city: o.city,
127
129
  country: o.country,
@@ -136,15 +138,15 @@ const L = (a) => a == null ? void 0 : a.map((e) => {
136
138
  },
137
139
  airline: t.airline,
138
140
  flightNumber: t.flightNumber,
139
- lowestCash: r.reduce(
141
+ lowestCash: a.reduce(
140
142
  (s, l) => Math.min(s, l.cash),
141
143
  1 / 0
142
144
  ),
143
- lowestPoints: r.reduce(
145
+ lowestPoints: a.reduce(
144
146
  (s, l) => Math.min(s, l.points),
145
147
  1 / 0
146
148
  ),
147
- paymentOptions: r.map((s) => ({
149
+ paymentOptions: a.map((s) => ({
148
150
  id: s.id,
149
151
  cash: s.cash,
150
152
  points: s.points,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@odynn/awayz-flights",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"