@odynn/awayz-flights 0.1.22 → 0.1.24
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/utils/flightUtils.js +70 -67
- package/package.json +1 -1
|
@@ -5,15 +5,15 @@ import { awayzClient as Z } from "@odynn/awayz-auth";
|
|
|
5
5
|
import { WalletService as B } from "../services/wallet/WalletService.js";
|
|
6
6
|
import { ERewardProgramCategories as S } from "../services/wallet/WalletService.types.js";
|
|
7
7
|
const v = (s) => s == null ? void 0 : s.map((e) => {
|
|
8
|
-
var
|
|
8
|
+
var o, a, t, n, i, l, d, r, m, L, A, M, N, F, w, u, y, c, C, h, b, g, p, f, T, k, P, z;
|
|
9
9
|
return {
|
|
10
10
|
id: e.id,
|
|
11
11
|
points: (e == null ? void 0 : e.points) >= 0 ? e.points : -1,
|
|
12
12
|
partial: e.partial,
|
|
13
13
|
origin: {
|
|
14
|
-
city: e.slices[0].segments[0].origin.cityName || ((a = (
|
|
15
|
-
country: e.slices[0].segments[0].origin.iataCountryCode || ((
|
|
16
|
-
airportCode: e.slices[0].segments[0].origin.iataCityCode || ((
|
|
14
|
+
city: e.slices[0].segments[0].origin.cityName || ((a = (o = e.slices[0].segments[0].origin) == null ? void 0 : o.city) == null ? void 0 : a.name),
|
|
15
|
+
country: e.slices[0].segments[0].origin.iataCountryCode || ((n = (t = e.slices[0].segments[0].origin) == null ? void 0 : t.city) == null ? void 0 : n.iataCountryCode),
|
|
16
|
+
airportCode: e.slices[0].segments[0].origin.iataCityCode || ((i = e.slices[0].segments[0].origin.city) == null ? void 0 : i.iataCode),
|
|
17
17
|
coordinates: {
|
|
18
18
|
latitude: (l = e.slices[0].segments[0].origin.city) == null ? void 0 : l.latitude,
|
|
19
19
|
longitude: (d = e.slices[0].segments[0].origin.city) == null ? void 0 : d.longitude
|
|
@@ -22,7 +22,7 @@ const v = (s) => s == null ? void 0 : s.map((e) => {
|
|
|
22
22
|
destination: {
|
|
23
23
|
city: ((m = (r = e.slices[0].segments.getLast()) == null ? void 0 : r.destination) == null ? void 0 : m.cityName) || ((M = (A = (L = e.slices[0].segments.getLast()) == null ? void 0 : L.destination) == null ? void 0 : A.city) == null ? void 0 : M.name),
|
|
24
24
|
country: ((F = (N = e.slices[0].segments.getLast()) == null ? void 0 : N.destination) == null ? void 0 : F.iataCountryCode) || ((y = (u = (w = e.slices[0].segments.getLast()) == null ? void 0 : w.destination) == null ? void 0 : u.city) == null ? void 0 : y.iataCountryCode),
|
|
25
|
-
airportCode: ((C = (
|
|
25
|
+
airportCode: ((C = (c = e.slices[0].segments.getLast()) == null ? void 0 : c.destination) == null ? void 0 : C.iataCityCode) || ((g = (b = (h = e.slices[0].segments.getLast()) == null ? void 0 : h.destination) == null ? void 0 : b.city) == null ? void 0 : g.iataCode),
|
|
26
26
|
coordinates: {
|
|
27
27
|
latitude: (T = (f = (p = e.slices[0].segments.getLast()) == null ? void 0 : p.destination) == null ? void 0 : f.city) == null ? void 0 : T.latitude,
|
|
28
28
|
longitude: (z = (P = (k = e.slices[0].segments.getLast()) == null ? void 0 : k.destination) == null ? void 0 : P.city) == null ? void 0 : z.longitude
|
|
@@ -52,11 +52,11 @@ const v = (s) => s == null ? void 0 : s.map((e) => {
|
|
|
52
52
|
}), Q = (s, e) => {
|
|
53
53
|
if (!(e != null && e.length))
|
|
54
54
|
return v(s);
|
|
55
|
-
const
|
|
55
|
+
const o = [...e];
|
|
56
56
|
let a = [];
|
|
57
|
-
const
|
|
58
|
-
for (const
|
|
59
|
-
const l =
|
|
57
|
+
const t = {};
|
|
58
|
+
for (const i of s) {
|
|
59
|
+
const l = i.slices[0].segments, d = l[0], r = {
|
|
60
60
|
iataCode: d.operatingCarrier.iataCode,
|
|
61
61
|
flightNumber: I(
|
|
62
62
|
d.operatingCarrierFlightNumber
|
|
@@ -66,86 +66,86 @@ const v = (s) => s == null ? void 0 : s.map((e) => {
|
|
|
66
66
|
flightNumber: I(
|
|
67
67
|
d.marketingCarrierFlightNumber
|
|
68
68
|
)
|
|
69
|
-
}, L =
|
|
70
|
-
const
|
|
69
|
+
}, L = i.awayzMatchId, A = `${r.iataCode}_${m.iataCode}-${m.flightNumber}`, M = i.awayzMarketerMatchId, N = !!r.flightNumber && r.flightNumber != "", F = !!m.flightNumber && m.flightNumber != "", w = o.filter((u, y) => {
|
|
70
|
+
const c = u.flightDetails, C = u.flightDetails.slices[0].segments[0].operatingCarrierFlightNumber, h = c.id && // TODO: Maybe expand on this - Id check ensures it is a duffel flight
|
|
71
71
|
!!C && C !== "";
|
|
72
|
-
if (!(
|
|
72
|
+
if (!(c.slices[0].segments.length === (l == null ? void 0 : l.length) && !c.slices[0].segments.find(
|
|
73
73
|
(p, f) => p.departingAt !== l[f].departingAt || p.arrivingAt !== l[f].arrivingAt || p.duration !== l[f].duration
|
|
74
74
|
)))
|
|
75
75
|
return !1;
|
|
76
76
|
let g = !1;
|
|
77
|
-
return (F && N &&
|
|
77
|
+
return (F && N && c.awayzMatchId === L || !h && c.awayzMatchId === A || N && !F && c.awayzMarketerMatchId === M) && (g = !0), g && (t[c.id] = y), g;
|
|
78
78
|
});
|
|
79
79
|
if (w.length) {
|
|
80
|
-
|
|
80
|
+
i.slices[0].comparisonKey = w[0].awayzGroupId;
|
|
81
81
|
const u = w.find((y) => {
|
|
82
82
|
var h, b, g, p;
|
|
83
|
-
const
|
|
84
|
-
return C ===
|
|
83
|
+
const c = (h = y.flightDetails.slices[0].fareBrandName) == null ? void 0 : h.toLowerCase(), C = (b = i.slices[0].fareBrandName) == null ? void 0 : b.toLowerCase();
|
|
84
|
+
return C === c || // Special Case for AC Only match on first word
|
|
85
85
|
// Due to differences in scraped points data and Duffel format
|
|
86
|
-
m.iataCode === "AC" && ((g = C.split(" ")) == null ? void 0 : g[0]) === ((p =
|
|
86
|
+
m.iataCode === "AC" && ((g = C.split(" ")) == null ? void 0 : g[0]) === ((p = c.split(" ")) == null ? void 0 : p[0]);
|
|
87
87
|
});
|
|
88
88
|
if (u) {
|
|
89
|
-
const y =
|
|
90
|
-
...
|
|
89
|
+
const y = t[u.id], c = {
|
|
90
|
+
...i,
|
|
91
91
|
...u,
|
|
92
|
-
points:
|
|
93
|
-
airlineProgram:
|
|
92
|
+
points: i.points,
|
|
93
|
+
airlineProgram: i.airlineProgram,
|
|
94
94
|
flightDetails: {
|
|
95
|
-
...
|
|
95
|
+
...i,
|
|
96
96
|
...u.flightDetails,
|
|
97
|
-
points:
|
|
98
|
-
airlineProgram:
|
|
97
|
+
points: i.points,
|
|
98
|
+
airlineProgram: i.airlineProgram
|
|
99
99
|
}
|
|
100
100
|
};
|
|
101
|
-
|
|
101
|
+
o[y] = c;
|
|
102
102
|
} else
|
|
103
|
-
a.push(
|
|
103
|
+
a.push(i);
|
|
104
104
|
} else
|
|
105
|
-
a.push(
|
|
105
|
+
a.push(i);
|
|
106
106
|
}
|
|
107
107
|
return [
|
|
108
|
-
...
|
|
108
|
+
...o,
|
|
109
109
|
...v(a) ?? []
|
|
110
110
|
];
|
|
111
111
|
}, $ = (s) => {
|
|
112
|
-
const e = s.operatingCarrierFlightNumber ? s.operatingCarrier : s.marketingCarrier,
|
|
113
|
-
return e.iataCode + " " + I(
|
|
112
|
+
const e = s.operatingCarrierFlightNumber ? s.operatingCarrier : s.marketingCarrier, o = s.operatingCarrierFlightNumber ?? s.marketingCarrierFlightNumber;
|
|
113
|
+
return e.iataCode + " " + I(o);
|
|
114
114
|
}, Y = ({
|
|
115
115
|
originCode: s,
|
|
116
116
|
destinationCode: e,
|
|
117
|
-
departureDate:
|
|
117
|
+
departureDate: o,
|
|
118
118
|
cabinClass: a,
|
|
119
|
-
passengerCount:
|
|
120
|
-
paymentType:
|
|
119
|
+
passengerCount: t,
|
|
120
|
+
paymentType: n
|
|
121
121
|
}) => {
|
|
122
|
-
let
|
|
123
|
-
return
|
|
122
|
+
let i = "/flights/search/one-way/points-cash?";
|
|
123
|
+
return i += `origin=${s}`, i += `&destination=${e}`, i += `&departure_date=${o}`, i += `&cabin_class=${a}`, i += `&adults=${t}`, i += `&cash_or_points=[${n}]`, i;
|
|
124
124
|
}, x = (s) => {
|
|
125
|
-
const e = s.reduce((a,
|
|
126
|
-
const
|
|
127
|
-
return a[
|
|
125
|
+
const e = s.reduce((a, t) => {
|
|
126
|
+
const n = t.flightDetails.slices[0].segments.map((i) => I($(i))).join("_");
|
|
127
|
+
return a[n] || (a[n] = []), a[n].push(t), a;
|
|
128
128
|
}, {});
|
|
129
129
|
return Object.values(e).map(
|
|
130
130
|
(a) => {
|
|
131
|
-
const
|
|
131
|
+
const t = a[0], { origin: n, destination: i } = t, l = a.filter((r) => r.cash > 0).reduce((r, m) => Math.min(r, m.cash), 1 / 0), d = a.filter((r) => r.points > 0).reduce((r, m) => Math.min(r, m.points), 1 / 0);
|
|
132
132
|
return {
|
|
133
|
-
id:
|
|
134
|
-
partial:
|
|
133
|
+
id: t.awayzGroupId,
|
|
134
|
+
partial: t.partial,
|
|
135
135
|
origin: {
|
|
136
|
-
city:
|
|
137
|
-
country:
|
|
138
|
-
airportCode:
|
|
139
|
-
coordinates:
|
|
136
|
+
city: n.city,
|
|
137
|
+
country: n.country,
|
|
138
|
+
airportCode: n.airportCode,
|
|
139
|
+
coordinates: n.coordinates
|
|
140
140
|
},
|
|
141
141
|
destination: {
|
|
142
|
-
city:
|
|
143
|
-
country:
|
|
144
|
-
airportCode:
|
|
145
|
-
coordinates:
|
|
142
|
+
city: i.city,
|
|
143
|
+
country: i.country,
|
|
144
|
+
airportCode: i.airportCode,
|
|
145
|
+
coordinates: i.coordinates
|
|
146
146
|
},
|
|
147
|
-
airline:
|
|
148
|
-
flightNumber:
|
|
147
|
+
airline: t.airline,
|
|
148
|
+
flightNumber: t.flightNumber,
|
|
149
149
|
paymentOptions: a.map((r) => ({
|
|
150
150
|
id: r.id,
|
|
151
151
|
cash: r.cash,
|
|
@@ -165,26 +165,26 @@ const v = (s) => s == null ? void 0 : s.map((e) => {
|
|
|
165
165
|
name: r.flightDetails.slices[0].segments[0].marketingCarrier.name
|
|
166
166
|
}
|
|
167
167
|
})),
|
|
168
|
-
numberOfStops:
|
|
169
|
-
departureTime:
|
|
170
|
-
arrivalTime:
|
|
171
|
-
awayzGroupId:
|
|
172
|
-
duration:
|
|
173
|
-
airlineProgram:
|
|
168
|
+
numberOfStops: t.numberOfStops,
|
|
169
|
+
departureTime: t.departureTime,
|
|
170
|
+
arrivalTime: t.arrivalTime,
|
|
171
|
+
awayzGroupId: t.awayzGroupId,
|
|
172
|
+
duration: t.duration,
|
|
173
|
+
airlineProgram: t.airlineProgram,
|
|
174
174
|
durationMinutes: _({
|
|
175
175
|
departureTime: D(
|
|
176
|
-
|
|
176
|
+
t.flightDetails.slices[0].segments[0].departingAt
|
|
177
177
|
),
|
|
178
178
|
arrivalTime: D(
|
|
179
|
-
|
|
179
|
+
t.flightDetails.slices[0].segments.getLast().arrivingAt
|
|
180
180
|
),
|
|
181
|
-
originTimeZone:
|
|
182
|
-
destinationTimeZone:
|
|
183
|
-
duration:
|
|
181
|
+
originTimeZone: t.flightDetails.slices[0].segments[0].origin.timeZone,
|
|
182
|
+
destinationTimeZone: t.flightDetails.slices[0].segments.getLast().destination.timeZone,
|
|
183
|
+
duration: t.flightDetails.slices[0].duration
|
|
184
184
|
}),
|
|
185
185
|
cash: l === 1 / 0 ? -1 : l,
|
|
186
186
|
points: d === 1 / 0 ? -1 : d,
|
|
187
|
-
flightDetails:
|
|
187
|
+
flightDetails: t.flightDetails
|
|
188
188
|
};
|
|
189
189
|
}
|
|
190
190
|
);
|
|
@@ -207,15 +207,18 @@ const v = (s) => s == null ? void 0 : s.map((e) => {
|
|
|
207
207
|
staleTime: 864e5
|
|
208
208
|
// 24 hours
|
|
209
209
|
});
|
|
210
|
-
let
|
|
211
|
-
(a) =>
|
|
210
|
+
let o = e.find(
|
|
211
|
+
(a) => {
|
|
212
|
+
var t, n;
|
|
213
|
+
return ((t = a.mainProgram) == null ? void 0 : t.toLowerCase().includes(s.toLowerCase())) || ((n = a.displayProgram) == null ? void 0 : n.toLowerCase().includes(s.toLowerCase()));
|
|
214
|
+
}
|
|
212
215
|
) ?? G;
|
|
213
|
-
return
|
|
216
|
+
return o || (o = {
|
|
214
217
|
...G,
|
|
215
218
|
mainProgram: s,
|
|
216
219
|
displayProgram: s,
|
|
217
220
|
id: s
|
|
218
|
-
}),
|
|
221
|
+
}), o;
|
|
219
222
|
};
|
|
220
223
|
export {
|
|
221
224
|
G as DEFAULT_AIRLINE_PROGRAM,
|