@odynn/awayz-flights 0.1.9 → 0.1.11
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/constants/endpoints.js +2 -2
- package/dist/hooks/useFlightSearch/useFlightSearch.js +89 -64
- package/dist/lib/constants/endpoints.d.ts +3 -2
- package/dist/lib/hooks/useFlightSearch/useFlightSearch.d.ts +4 -0
- package/dist/lib/services/flights/FlightsService.d.ts +3 -2
- package/dist/lib/services/flights/FlightsService.types.d.ts +7 -0
- package/dist/services/flights/FlightsService.js +70 -45
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
1
|
+
var r = /* @__PURE__ */ ((s) => (s.GET_AIRPORTS = "/flights/search/airports", s.CASH_FLIGHT_SEARCH = "/flights/search/one-way/cash", s.CASH_OUTBOUND_SEARCH = "/flights/search/multi/outbound", s.CASH_INBOUND_SEARCH = "/flights/search/multi/inbound", s.ROUND_TRIP_FARES = "/flights/search/multi/fares", s))(r || {});
|
|
2
2
|
export {
|
|
3
|
-
|
|
3
|
+
r as EFlightEndpoint
|
|
4
4
|
};
|
|
@@ -1,53 +1,53 @@
|
|
|
1
1
|
import { useState as n } from "react";
|
|
2
|
-
import { useMutation as
|
|
3
|
-
import { ECabinClass as
|
|
4
|
-
import { FlightService as
|
|
5
|
-
import { parseFlightDetails as
|
|
6
|
-
const
|
|
7
|
-
if (!
|
|
2
|
+
import { useMutation as a } from "@tanstack/react-query";
|
|
3
|
+
import { ECabinClass as D, EFlightType as d } from "../../types/enums.js";
|
|
4
|
+
import { FlightService as u } from "../../services/flights/FlightsService.js";
|
|
5
|
+
import { parseFlightDetails as C, groupFlightResults as _ } from "../../utils/flightUtils.js";
|
|
6
|
+
const N = 1, P = D.ECONOMY, A = (t) => {
|
|
7
|
+
if (!t.origin || !t.destination)
|
|
8
8
|
throw new Error("Origin and destination are required.");
|
|
9
|
-
if (!
|
|
9
|
+
if (!t.departureDate)
|
|
10
10
|
throw new Error("Departure date is required.");
|
|
11
|
-
if (
|
|
11
|
+
if (t.flightType === d.ROUND_TRIP && !t.returnDate)
|
|
12
12
|
throw new Error("Return date is required for round-trip flights.");
|
|
13
|
-
},
|
|
14
|
-
const [
|
|
15
|
-
data:
|
|
16
|
-
previousResults:
|
|
17
|
-
inbound:
|
|
13
|
+
}, j = () => {
|
|
14
|
+
const [t, c] = n(""), [f, l] = n(""), [p, h] = n([]), [b, R] = n([]), [g, O] = n([]), i = ({
|
|
15
|
+
data: r,
|
|
16
|
+
previousResults: s,
|
|
17
|
+
inbound: o
|
|
18
18
|
}) => {
|
|
19
|
-
const e =
|
|
20
|
-
return (
|
|
19
|
+
const e = C(r, s);
|
|
20
|
+
return (o ? R : h)(_(e)), e;
|
|
21
21
|
}, {
|
|
22
|
-
mutate:
|
|
23
|
-
status:
|
|
24
|
-
error:
|
|
25
|
-
} =
|
|
26
|
-
mutationFn: async (
|
|
27
|
-
|
|
28
|
-
const
|
|
22
|
+
mutate: m,
|
|
23
|
+
status: E,
|
|
24
|
+
error: F
|
|
25
|
+
} = a({
|
|
26
|
+
mutationFn: async (r) => {
|
|
27
|
+
A(r);
|
|
28
|
+
const o = {
|
|
29
29
|
passengers: Array.from(
|
|
30
|
-
{ length:
|
|
30
|
+
{ length: r.passengers ?? N },
|
|
31
31
|
() => ({ type: "adult" })
|
|
32
32
|
),
|
|
33
|
-
origin:
|
|
34
|
-
destination:
|
|
35
|
-
cabin_class:
|
|
33
|
+
origin: r.origin || "",
|
|
34
|
+
destination: r.destination || "",
|
|
35
|
+
cabin_class: r.cabinClass || P
|
|
36
36
|
};
|
|
37
|
-
if (
|
|
38
|
-
const e = await
|
|
39
|
-
...
|
|
40
|
-
departure_date:
|
|
37
|
+
if (r.flightType === d.ONE_WAY) {
|
|
38
|
+
const e = await u.cashOnlySearch({
|
|
39
|
+
...o,
|
|
40
|
+
departure_date: r.departureDate
|
|
41
41
|
});
|
|
42
42
|
return {
|
|
43
43
|
success: e.success,
|
|
44
44
|
data: e.data
|
|
45
45
|
};
|
|
46
46
|
} else {
|
|
47
|
-
const e = await
|
|
48
|
-
...
|
|
49
|
-
departure_date:
|
|
50
|
-
return_date:
|
|
47
|
+
const e = await u.roundTripOutboundSearch({
|
|
48
|
+
...o,
|
|
49
|
+
departure_date: r.departureDate,
|
|
50
|
+
return_date: r.returnDate
|
|
51
51
|
});
|
|
52
52
|
return {
|
|
53
53
|
success: e.success,
|
|
@@ -56,54 +56,79 @@ const q = 1, F = w.ECONOMY, I = (r) => {
|
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
58
|
},
|
|
59
|
-
onSuccess: (
|
|
60
|
-
console.log({ result:
|
|
61
|
-
const { success:
|
|
62
|
-
if (!
|
|
59
|
+
onSuccess: (r) => {
|
|
60
|
+
console.log({ result: r });
|
|
61
|
+
const { success: s, data: o, partialOfferRequestId: e } = r;
|
|
62
|
+
if (!s) {
|
|
63
63
|
console.log("oh lol, it didn't work");
|
|
64
64
|
return;
|
|
65
65
|
}
|
|
66
|
-
|
|
66
|
+
i({ data: o }), e && c(e);
|
|
67
67
|
},
|
|
68
|
-
onError: (
|
|
69
|
-
console.error("Error in outbound flight search:",
|
|
68
|
+
onError: (r) => {
|
|
69
|
+
console.error("Error in outbound flight search:", r);
|
|
70
70
|
}
|
|
71
71
|
}), {
|
|
72
|
-
mutate:
|
|
73
|
-
status:
|
|
74
|
-
error:
|
|
75
|
-
} =
|
|
76
|
-
mutationFn: async (
|
|
77
|
-
if (!
|
|
72
|
+
mutate: w,
|
|
73
|
+
status: I,
|
|
74
|
+
error: S
|
|
75
|
+
} = a({
|
|
76
|
+
mutationFn: async (r) => {
|
|
77
|
+
if (!t)
|
|
78
78
|
throw new Error("No partialOfferRequestId found for inbound search.");
|
|
79
|
-
return await
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
return l(r), await u.roundTripInboundSearch({
|
|
80
|
+
outboundOfferId: r,
|
|
81
|
+
outboundOfferRequestId: t
|
|
82
82
|
});
|
|
83
83
|
},
|
|
84
|
-
onSuccess: (
|
|
85
|
-
const { success:
|
|
86
|
-
|
|
87
|
-
data:
|
|
84
|
+
onSuccess: (r) => {
|
|
85
|
+
const { success: s, data: o } = r;
|
|
86
|
+
s && i({
|
|
87
|
+
data: o.offers,
|
|
88
88
|
inbound: !0
|
|
89
89
|
});
|
|
90
90
|
},
|
|
91
|
-
onError: (
|
|
92
|
-
console.error("Error in inbound flight search:",
|
|
91
|
+
onError: (r) => {
|
|
92
|
+
console.error("Error in inbound flight search:", r);
|
|
93
|
+
}
|
|
94
|
+
}), {
|
|
95
|
+
mutate: q,
|
|
96
|
+
status: T,
|
|
97
|
+
error: y
|
|
98
|
+
} = a({
|
|
99
|
+
mutationFn: async (r) => {
|
|
100
|
+
if (!t)
|
|
101
|
+
throw new Error("No partialOfferRequestId found for round-trip fares.");
|
|
102
|
+
return await u.getRoundTripFares({
|
|
103
|
+
outboundOfferId: f,
|
|
104
|
+
outboundOfferRequestId: t,
|
|
105
|
+
inboundOfferId: r
|
|
106
|
+
});
|
|
107
|
+
},
|
|
108
|
+
onSuccess: (r) => {
|
|
109
|
+
const { success: s, data: o } = r;
|
|
110
|
+
s && O(o);
|
|
111
|
+
},
|
|
112
|
+
onError: (r) => {
|
|
113
|
+
console.error("Error in round-trip fare search:", r);
|
|
93
114
|
}
|
|
94
115
|
});
|
|
95
116
|
return {
|
|
96
|
-
loading:
|
|
97
|
-
|
|
98
|
-
|
|
117
|
+
loading: E === "pending" || I === "pending",
|
|
118
|
+
loadingFares: T === "pending",
|
|
119
|
+
outboundError: F,
|
|
120
|
+
inboundError: S,
|
|
121
|
+
roundTripFaresError: y,
|
|
99
122
|
// Results
|
|
100
|
-
outboundResults:
|
|
101
|
-
inboundResults:
|
|
123
|
+
outboundResults: p,
|
|
124
|
+
inboundResults: b,
|
|
125
|
+
roundTripFares: g,
|
|
102
126
|
// Mutation triggers
|
|
103
|
-
searchOutboundFlights:
|
|
104
|
-
searchInboundFlights:
|
|
127
|
+
searchOutboundFlights: m,
|
|
128
|
+
searchInboundFlights: w,
|
|
129
|
+
getRoundTripFares: q
|
|
105
130
|
};
|
|
106
131
|
};
|
|
107
132
|
export {
|
|
108
|
-
|
|
133
|
+
j as useFlightSearch
|
|
109
134
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export declare enum EFlightEndpoint {
|
|
2
2
|
GET_AIRPORTS = "/flights/search/airports",
|
|
3
3
|
CASH_FLIGHT_SEARCH = "/flights/search/one-way/cash",
|
|
4
|
-
CASH_OUTBOUND_SEARCH = "flights/search/multi/outbound",
|
|
5
|
-
CASH_INBOUND_SEARCH = "flights/search/multi/inbound"
|
|
4
|
+
CASH_OUTBOUND_SEARCH = "/flights/search/multi/outbound",
|
|
5
|
+
CASH_INBOUND_SEARCH = "/flights/search/multi/inbound",
|
|
6
|
+
ROUND_TRIP_FARES = "/flights/search/multi/fares"
|
|
6
7
|
}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { IFlightOffer, IFlightResult, ISearchFlightArgs } from './useFlightSearch.types';
|
|
2
2
|
export declare const useFlightSearch: () => {
|
|
3
3
|
loading: boolean;
|
|
4
|
+
loadingFares: boolean;
|
|
4
5
|
outboundError: Error | null;
|
|
5
6
|
inboundError: Error | null;
|
|
7
|
+
roundTripFaresError: Error | null;
|
|
6
8
|
outboundResults: IFlightResult[];
|
|
7
9
|
inboundResults: IFlightResult[];
|
|
10
|
+
roundTripFares: IFlightOffer[];
|
|
8
11
|
searchOutboundFlights: import('@tanstack/react-query').UseMutateFunction<{
|
|
9
12
|
success: boolean;
|
|
10
13
|
data: [] | IFlightOffer[] | undefined;
|
|
@@ -15,4 +18,5 @@ export declare const useFlightSearch: () => {
|
|
|
15
18
|
partialOfferRequestId: any;
|
|
16
19
|
}, Error, ISearchFlightArgs, unknown>;
|
|
17
20
|
searchInboundFlights: import('@tanstack/react-query').UseMutateFunction<any, Error, string, unknown>;
|
|
21
|
+
getRoundTripFares: import('@tanstack/react-query').UseMutateFunction<any, Error, string, unknown>;
|
|
18
22
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TServiceResponse } from '@type-op/shared';
|
|
2
|
-
import { IOneWayCashOnlyFlightSearchArgs, IRoundCashOnlyFlightSearchArgs } from './FlightsService.types';
|
|
2
|
+
import { IOneWayCashOnlyFlightSearchArgs, IRoundCashOnlyFlightSearchArgs, IRoundTripFareSearchArgs, IRoundTripInboundSearchArgs } from './FlightsService.types';
|
|
3
3
|
import { IFlightOffer } from '../../hooks/useFlightSearch/useFlightSearch.types';
|
|
4
4
|
import { IAirport } from '../../hooks/useAirportSearch/useAirportSearch.types';
|
|
5
5
|
declare class _FlightService {
|
|
@@ -14,7 +14,8 @@ declare class _FlightService {
|
|
|
14
14
|
message: any;
|
|
15
15
|
data?: undefined;
|
|
16
16
|
}>;
|
|
17
|
-
roundTripInboundSearch: (args:
|
|
17
|
+
roundTripInboundSearch: (args: IRoundTripInboundSearchArgs) => Promise<any>;
|
|
18
|
+
getRoundTripFares: (args: IRoundTripFareSearchArgs) => Promise<any>;
|
|
18
19
|
}
|
|
19
20
|
export declare const FlightService: _FlightService;
|
|
20
21
|
export {};
|
|
@@ -198,4 +198,11 @@ export interface IOwnerResponse {
|
|
|
198
198
|
name: string;
|
|
199
199
|
id: string;
|
|
200
200
|
}
|
|
201
|
+
export interface IRoundTripInboundSearchArgs {
|
|
202
|
+
outboundOfferRequestId: string;
|
|
203
|
+
outboundOfferId: string;
|
|
204
|
+
}
|
|
205
|
+
export interface IRoundTripFareSearchArgs extends IRoundTripInboundSearchArgs {
|
|
206
|
+
inboundOfferId: string;
|
|
207
|
+
}
|
|
201
208
|
export {};
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
1
|
+
var f = Object.defineProperty;
|
|
2
|
+
var m = (a, s, t) => s in a ? f(a, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[s] = t;
|
|
3
|
+
var u = (a, s, t) => m(a, typeof s != "symbol" ? s + "" : s, t);
|
|
4
4
|
import "../../arrayExtensions-DWKenJCh.js";
|
|
5
|
-
import { EFlightEndpoint as
|
|
6
|
-
import { clientInstance as
|
|
7
|
-
function
|
|
8
|
-
return
|
|
5
|
+
import { EFlightEndpoint as d } from "../../constants/endpoints.js";
|
|
6
|
+
import { clientInstance as i } from "@odynn/awayz-auth";
|
|
7
|
+
function _(a) {
|
|
8
|
+
return a = a.replace(/^_+/, ""), a.replace(/_([a-z])/g, (s, t) => t.toUpperCase());
|
|
9
9
|
}
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
return s[
|
|
13
|
-
}, {}) :
|
|
14
|
-
class
|
|
10
|
+
const r = (a) => Array.isArray(a) ? a.map((s) => r(s)) : typeof a == "object" && a !== null ? Object.keys(a).reduce((s, t) => {
|
|
11
|
+
const c = _(t);
|
|
12
|
+
return s[c] = r(a[t]), s;
|
|
13
|
+
}, {}) : a;
|
|
14
|
+
class l {
|
|
15
15
|
constructor() {
|
|
16
|
-
|
|
16
|
+
u(this, "getAirports", async (s) => {
|
|
17
17
|
try {
|
|
18
|
-
const { data:
|
|
19
|
-
`${
|
|
18
|
+
const { data: t } = await i.get(
|
|
19
|
+
`${d.GET_AIRPORTS}?search_term=${s}`
|
|
20
20
|
);
|
|
21
|
-
return
|
|
22
|
-
var
|
|
21
|
+
return t.data.map((e) => {
|
|
22
|
+
var o;
|
|
23
23
|
return {
|
|
24
24
|
city: {
|
|
25
25
|
name: e.city_name,
|
|
@@ -31,7 +31,7 @@ class g {
|
|
|
31
31
|
},
|
|
32
32
|
country: {
|
|
33
33
|
code: e.iata_country_code,
|
|
34
|
-
name: (
|
|
34
|
+
name: (o = e.country) == null ? void 0 : o.name
|
|
35
35
|
},
|
|
36
36
|
name: e.name,
|
|
37
37
|
iataCode: e.iata_code,
|
|
@@ -44,72 +44,97 @@ class g {
|
|
|
44
44
|
return [];
|
|
45
45
|
}
|
|
46
46
|
});
|
|
47
|
-
|
|
48
|
-
var
|
|
47
|
+
u(this, "cashOnlySearch", async (s) => {
|
|
48
|
+
var t, c, e, o;
|
|
49
49
|
try {
|
|
50
|
-
const { data:
|
|
51
|
-
|
|
50
|
+
const { data: n } = await i.post(
|
|
51
|
+
d.CASH_FLIGHT_SEARCH,
|
|
52
52
|
s
|
|
53
53
|
);
|
|
54
|
-
return
|
|
54
|
+
return n.success ? {
|
|
55
55
|
success: !0,
|
|
56
|
-
data:
|
|
57
|
-
|
|
56
|
+
data: r(
|
|
57
|
+
n.data.offers
|
|
58
58
|
)
|
|
59
59
|
} : {
|
|
60
60
|
success: !1,
|
|
61
|
-
message:
|
|
61
|
+
message: n.message
|
|
62
62
|
};
|
|
63
|
-
} catch (
|
|
64
|
-
return console.error(JSON.stringify(
|
|
63
|
+
} catch (n) {
|
|
64
|
+
return console.error(JSON.stringify(n)), n.message === "canceled" ? {
|
|
65
65
|
success: !1,
|
|
66
|
-
message: ((
|
|
66
|
+
message: ((c = (t = n == null ? void 0 : n.response) == null ? void 0 : t.data) == null ? void 0 : c.message) || (n == null ? void 0 : n.message)
|
|
67
67
|
} : {
|
|
68
68
|
success: !1,
|
|
69
|
-
message: ((
|
|
69
|
+
message: ((o = (e = n == null ? void 0 : n.response) == null ? void 0 : e.data) == null ? void 0 : o.message) || (n == null ? void 0 : n.message)
|
|
70
70
|
};
|
|
71
71
|
}
|
|
72
72
|
});
|
|
73
|
-
|
|
74
|
-
var
|
|
73
|
+
u(this, "roundTripOutboundSearch", async (s) => {
|
|
74
|
+
var t, c;
|
|
75
75
|
try {
|
|
76
|
-
const { data: e } = await
|
|
77
|
-
|
|
76
|
+
const { data: e } = await i.post(
|
|
77
|
+
d.CASH_OUTBOUND_SEARCH,
|
|
78
78
|
{ ...s, to: s.return_date, from: s.departure_date }
|
|
79
79
|
);
|
|
80
80
|
if (!e.success) throw e;
|
|
81
81
|
return {
|
|
82
82
|
success: e.success,
|
|
83
|
-
data:
|
|
83
|
+
data: r(e.data)
|
|
84
84
|
};
|
|
85
85
|
} catch (e) {
|
|
86
86
|
return {
|
|
87
87
|
success: !1,
|
|
88
|
-
message: ((
|
|
88
|
+
message: ((c = (t = e == null ? void 0 : e.response) == null ? void 0 : t.data) == null ? void 0 : c.message) || (e == null ? void 0 : e.message)
|
|
89
89
|
};
|
|
90
90
|
}
|
|
91
91
|
});
|
|
92
|
-
|
|
93
|
-
var
|
|
92
|
+
u(this, "roundTripInboundSearch", async (s) => {
|
|
93
|
+
var t, c;
|
|
94
94
|
try {
|
|
95
|
-
const { data: e } = await
|
|
96
|
-
|
|
95
|
+
const { data: e } = await i.get(
|
|
96
|
+
d.CASH_INBOUND_SEARCH,
|
|
97
97
|
{
|
|
98
|
-
params:
|
|
98
|
+
params: {
|
|
99
|
+
outbound_offer_id: s.outboundOfferId,
|
|
100
|
+
outbound_offer_request_id: s.outboundOfferRequestId
|
|
101
|
+
}
|
|
99
102
|
}
|
|
100
103
|
);
|
|
101
104
|
if (!e.success) throw e;
|
|
102
|
-
return e;
|
|
105
|
+
return r(e);
|
|
103
106
|
} catch (e) {
|
|
104
107
|
return {
|
|
105
108
|
success: !1,
|
|
106
|
-
message: ((
|
|
109
|
+
message: ((c = (t = e == null ? void 0 : e.response) == null ? void 0 : t.data) == null ? void 0 : c.message) || (e == null ? void 0 : e.message)
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
u(this, "getRoundTripFares", async (s) => {
|
|
114
|
+
var t, c;
|
|
115
|
+
try {
|
|
116
|
+
const { data: e } = await i.get(
|
|
117
|
+
d.ROUND_TRIP_FARES,
|
|
118
|
+
{
|
|
119
|
+
params: {
|
|
120
|
+
outbound_offer_id: s.outboundOfferId,
|
|
121
|
+
outbound_offer_request_id: s.outboundOfferRequestId,
|
|
122
|
+
inbound_offer_id: s.inboundOfferId
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
);
|
|
126
|
+
if (!e.success) throw e;
|
|
127
|
+
return e;
|
|
128
|
+
} catch (e) {
|
|
129
|
+
return console.error(JSON.stringify(e)), {
|
|
130
|
+
success: !1,
|
|
131
|
+
message: ((c = (t = e == null ? void 0 : e.response) == null ? void 0 : t.data) == null ? void 0 : c.message) || (e == null ? void 0 : e.message)
|
|
107
132
|
};
|
|
108
133
|
}
|
|
109
134
|
});
|
|
110
135
|
}
|
|
111
136
|
}
|
|
112
|
-
const
|
|
137
|
+
const O = new l();
|
|
113
138
|
export {
|
|
114
|
-
|
|
139
|
+
O as FlightService
|
|
115
140
|
};
|