@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.
- package/dist/hooks/useFlightSearch/useFlightSearch.js +21 -16
- package/dist/lib/hooks/useFlightSearch/useFlightSearch.types.d.ts +1 -0
- package/dist/lib/services/flights/FlightsService.d.ts +9 -1
- package/dist/services/flights/FlightsService.js +28 -25
- package/dist/utils/flightUtils.js +28 -26
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useState as
|
|
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] =
|
|
14
|
+
const [r, c] = n(""), [l, f] = n([]), [p, h] = n([]), u = ({
|
|
15
15
|
data: t,
|
|
16
|
-
previousResults:
|
|
16
|
+
previousResults: o,
|
|
17
17
|
inbound: s
|
|
18
18
|
}) => {
|
|
19
|
-
const e = S(t,
|
|
19
|
+
const e = S(t, o);
|
|
20
20
|
return (s ? h : f)(_(e)), e;
|
|
21
21
|
}, {
|
|
22
22
|
mutate: b,
|
|
23
|
-
status:
|
|
24
|
-
error:
|
|
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.
|
|
54
|
-
data: e.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
|
-
|
|
61
|
-
|
|
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:
|
|
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:
|
|
81
|
-
|
|
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:
|
|
92
|
-
outboundError:
|
|
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:
|
|
104
|
+
searchInboundFlights: R
|
|
100
105
|
};
|
|
101
106
|
};
|
|
102
107
|
export {
|
|
@@ -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<
|
|
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
|
|
3
|
+
var d = (t, s, a) => l(t, typeof s != "symbol" ? s + "" : s, a);
|
|
4
4
|
import "../../arrayExtensions-DWKenJCh.js";
|
|
5
|
-
import { EFlightEndpoint as
|
|
6
|
-
import { clientInstance as
|
|
7
|
-
function
|
|
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
|
|
11
|
-
const n =
|
|
12
|
-
return s[n] =
|
|
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
|
|
14
|
+
class g {
|
|
15
15
|
constructor() {
|
|
16
|
-
|
|
16
|
+
d(this, "getAirports", async (s) => {
|
|
17
17
|
try {
|
|
18
|
-
const { data: a } = await
|
|
19
|
-
`${
|
|
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
|
-
|
|
47
|
+
d(this, "cashOnlySearch", async (s) => {
|
|
48
48
|
var a, n, e, u;
|
|
49
49
|
try {
|
|
50
|
-
const { data: c } = await
|
|
51
|
-
|
|
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:
|
|
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
|
-
|
|
73
|
+
d(this, "roundTripOutboundSearch", async (s) => {
|
|
74
74
|
var a, n;
|
|
75
75
|
try {
|
|
76
|
-
const { data: e } = await
|
|
77
|
-
|
|
78
|
-
{ ...s, to:
|
|
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
|
|
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
|
-
|
|
92
|
+
d(this, "roundTripInboundSearch", async (s) => {
|
|
90
93
|
var a, n;
|
|
91
94
|
try {
|
|
92
|
-
const { data: e } = await
|
|
93
|
-
|
|
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
|
|
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 = (
|
|
4
|
-
var c,
|
|
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 || ((
|
|
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 = (
|
|
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 = (
|
|
48
|
+
}), O = (r, e) => {
|
|
48
49
|
if (!(e != null && e.length))
|
|
49
|
-
return L(
|
|
50
|
+
return L(r);
|
|
50
51
|
const c = [...e];
|
|
51
|
-
let
|
|
52
|
+
let a = [];
|
|
52
53
|
const t = {};
|
|
53
|
-
for (const i of
|
|
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,
|
|
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 ===
|
|
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
|
-
|
|
95
|
+
a.push(i);
|
|
95
96
|
} else
|
|
96
|
-
|
|
97
|
+
a.push(i);
|
|
97
98
|
}
|
|
98
99
|
return [
|
|
99
100
|
...c,
|
|
100
|
-
...L(
|
|
101
|
+
...L(a) ?? []
|
|
101
102
|
];
|
|
102
|
-
}, A = (
|
|
103
|
-
const e =
|
|
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:
|
|
107
|
+
originCode: r,
|
|
107
108
|
destinationCode: e,
|
|
108
109
|
departureDate: c,
|
|
109
|
-
cabinClass:
|
|
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=${
|
|
115
|
-
}, $ = (
|
|
116
|
-
const e =
|
|
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
|
|
119
|
+
return a[o] || (a[o] = []), a[o].push(t), a;
|
|
119
120
|
}, {});
|
|
120
121
|
return Object.values(e).map(
|
|
121
|
-
(
|
|
122
|
-
const 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:
|
|
141
|
+
lowestCash: a.reduce(
|
|
140
142
|
(s, l) => Math.min(s, l.cash),
|
|
141
143
|
1 / 0
|
|
142
144
|
),
|
|
143
|
-
lowestPoints:
|
|
145
|
+
lowestPoints: a.reduce(
|
|
144
146
|
(s, l) => Math.min(s, l.points),
|
|
145
147
|
1 / 0
|
|
146
148
|
),
|
|
147
|
-
paymentOptions:
|
|
149
|
+
paymentOptions: a.map((s) => ({
|
|
148
150
|
id: s.id,
|
|
149
151
|
cash: s.cash,
|
|
150
152
|
points: s.points,
|