@odynn/awayz-flights 0.1.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.
- package/README.md +50 -0
- package/dist/FlightItinerary-C2U8MR2H.js +396 -0
- package/dist/FlightsService-Bc_71ary.js +4536 -0
- package/dist/arrayExtensions-BS8S8Zke.js +3116 -0
- package/dist/assets/_styles.css +1 -0
- package/dist/assets/_styles2.css +1 -0
- package/dist/components/FlightItinerary/FlightItinerary.js +11 -0
- package/dist/components/FlightResult/FlightResult.js +138 -0
- package/dist/components/index.js +6 -0
- package/dist/constants/constants.js +4 -0
- package/dist/constants/endpoints.js +4 -0
- package/dist/enums/EPaymentType.js +4 -0
- package/dist/enums/index.js +4 -0
- package/dist/hooks/index.js +6 -0
- package/dist/hooks/useAirportSearch/useAirportSearch.js +37 -0
- package/dist/hooks/useAirportSearch/useAirportSearch.types.js +1 -0
- package/dist/hooks/useFlightSearch/useFlightSearch.js +265 -0
- package/dist/hooks/useFlightSearch/useFlightSearch.types.js +4 -0
- package/dist/lib/components/FlightItinerary/FlightItinerary.d.ts +10 -0
- package/dist/lib/components/FlightResult/FlightResult.d.ts +8 -0
- package/dist/lib/components/index.d.ts +1 -0
- package/dist/lib/constants/constants.d.ts +1 -0
- package/dist/lib/constants/endpoints.d.ts +6 -0
- package/dist/lib/enums/EPaymentType.d.ts +4 -0
- package/dist/lib/enums/index.d.ts +1 -0
- package/dist/lib/hooks/index.d.ts +2 -0
- package/dist/lib/hooks/useAirportSearch/useAirportSearch.d.ts +6 -0
- package/dist/lib/hooks/useAirportSearch/useAirportSearch.types.d.ts +11 -0
- package/dist/lib/hooks/useFlightSearch/useFlightSearch.d.ts +8 -0
- package/dist/lib/hooks/useFlightSearch/useFlightSearch.types.d.ts +277 -0
- package/dist/lib/main.d.ts +3 -0
- package/dist/lib/services/flights/FlightsService.d.ts +11 -0
- package/dist/lib/services/flights/FlightsService.types.d.ts +201 -0
- package/dist/lib/types/enums.d.ts +15 -0
- package/dist/lib/types/index.d.ts +1 -0
- package/dist/lib/utils/flightUtils.d.ts +45 -0
- package/dist/main.js +14 -0
- package/dist/moment-BGjjqtLQ.js +2594 -0
- package/dist/services/flights/FlightsService.js +9 -0
- package/dist/services/flights/FlightsService.types.js +1 -0
- package/dist/types/enums.js +6 -0
- package/dist/types/index.js +6 -0
- package/dist/utils/flightUtils.js +181 -0
- package/package.json +72 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
var O = /* @__PURE__ */ ((r) => (r.CASH = "Cash Only", r.MILES = "Miles Only", r.CASH_AND_MILES = "Cash & Miles", r))(O || {}), M = /* @__PURE__ */ ((r) => (r.ROUND_TRIP = "Round Trip", r.ONE_WAY = "One Way", r))(M || {}), S = /* @__PURE__ */ ((r) => (r.ECONOMY = "economy", r.PREMIUM_ECONOMY = "premium_economy", r.BUSINESS = "business", r.FIRST = "first", r))(S || {});
|
|
2
|
+
export {
|
|
3
|
+
S as ECabinClass,
|
|
4
|
+
O as EFlightPaymentType,
|
|
5
|
+
M as EFlightType
|
|
6
|
+
};
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { h as z } from "../moment-BGjjqtLQ.js";
|
|
2
|
+
const k = (s) => s == null ? void 0 : s.map((e) => {
|
|
3
|
+
var c, a, i, o, t, r, d, C, g, D, I, f, w, M, b, u, p, n, y, h, N, l, m, F;
|
|
4
|
+
return {
|
|
5
|
+
id: e.id,
|
|
6
|
+
points: (e == null ? void 0 : e.points) >= 0 ? e.points : -1,
|
|
7
|
+
origin: {
|
|
8
|
+
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),
|
|
9
|
+
country: e.slices[0].segments[0].origin.iataCountryCode || ((i = e.slices[0].segments[0].origin) == null ? void 0 : i.city.iataCountryCode),
|
|
10
|
+
airportCode: e.slices[0].segments[0].origin.iataCityCode || e.slices[0].segments[0].origin.city.iataCode,
|
|
11
|
+
coordinates: {
|
|
12
|
+
latitude: e.slices[0].segments[0].origin.city.latitude,
|
|
13
|
+
longitude: e.slices[0].segments[0].origin.city.longitude
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
destination: {
|
|
17
|
+
city: ((t = (o = e.slices[0].segments.getLast()) == null ? void 0 : o.destination) == null ? void 0 : t.cityName) || ((C = (d = (r = e.slices[0].segments.getLast()) == null ? void 0 : r.destination) == null ? void 0 : d.city) == null ? void 0 : C.name),
|
|
18
|
+
country: ((D = (g = e.slices[0].segments.getLast()) == null ? void 0 : g.destination) == null ? void 0 : D.iataCountryCode) || ((w = (f = (I = e.slices[0].segments.getLast()) == null ? void 0 : I.destination) == null ? void 0 : f.city) == null ? void 0 : w.iataCountryCode),
|
|
19
|
+
airportCode: ((b = (M = e.slices[0].segments.getLast()) == null ? void 0 : M.destination) == null ? void 0 : b.iataCityCode) || ((n = (p = (u = e.slices[0].segments.getLast()) == null ? void 0 : u.destination) == null ? void 0 : p.city) == null ? void 0 : n.iataCode),
|
|
20
|
+
coordinates: {
|
|
21
|
+
latitude: (N = (h = (y = e.slices[0].segments.getLast()) == null ? void 0 : y.destination) == null ? void 0 : h.city) == null ? void 0 : N.latitude,
|
|
22
|
+
longitude: (F = (m = (l = e.slices[0].segments.getLast()) == null ? void 0 : l.destination) == null ? void 0 : m.city) == null ? void 0 : F.longitude
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
airline: e.owner.name,
|
|
26
|
+
cash: parseFloat(e.totalAmount),
|
|
27
|
+
flightNumber: L(e.slices[0].segments[0]),
|
|
28
|
+
awayzGroupId: e.slices[0].comparisonKey || e.awayzRouteId || e.awayzGroupId || e.id,
|
|
29
|
+
departureTime: z(e.slices[0].segments[0].departingAt).toDate(),
|
|
30
|
+
arrivalTime: z(
|
|
31
|
+
e.slices[0].segments[e.slices[0].segments.length - 1].arrivingAt
|
|
32
|
+
).toDate(),
|
|
33
|
+
numberOfStops: e.slices[0].segments.length - 1,
|
|
34
|
+
flightDetails: e,
|
|
35
|
+
duration: e.slices[0].duration,
|
|
36
|
+
airlineProgram: e.airlineProgram,
|
|
37
|
+
durationMinutes: 2e3
|
|
38
|
+
// TODO: Finalize this
|
|
39
|
+
// calculateTotalMinutes({
|
|
40
|
+
// departureTime: moment(flight.slices[0].segments[0].departingAt),
|
|
41
|
+
// arrivalTime: moment(flight.slices[0].segments.getLast().arrivingAt),
|
|
42
|
+
// origin: flight.slices[0].segments[0].origin.timeZone,
|
|
43
|
+
// destination: flight.slices[0].segments.getLast().destination.timeZone,
|
|
44
|
+
// duration: flight.slices[0].duration
|
|
45
|
+
// })
|
|
46
|
+
};
|
|
47
|
+
}), G = (s, e) => {
|
|
48
|
+
if (!(e != null && e.length))
|
|
49
|
+
return k(s);
|
|
50
|
+
const c = [...e];
|
|
51
|
+
let a = [];
|
|
52
|
+
const i = {};
|
|
53
|
+
for (const t of s) {
|
|
54
|
+
const r = t.slices[0].segments, d = r[0], C = {
|
|
55
|
+
iataCode: d.operatingCarrier.iataCode,
|
|
56
|
+
flightNumber: d.operatingCarrierFlightNumber
|
|
57
|
+
}, g = {
|
|
58
|
+
iataCode: d.marketingCarrier.iataCode,
|
|
59
|
+
flightNumber: d.marketingCarrierFlightNumber
|
|
60
|
+
}, D = t.awayzMatchId, I = `${C.iataCode}_${g.iataCode}-${g.flightNumber}`, f = t.awayzMarketerMatchId, w = !!C.flightNumber && C.flightNumber != "", M = !!g.flightNumber && g.flightNumber != "", b = c.filter((u, p) => {
|
|
61
|
+
const n = u.flightDetails, y = u.flightDetails.slices[0].segments[0].operatingCarrierFlightNumber, h = n.id && // TODO: Maybe expand on this - Id check ensures it is a duffel flight
|
|
62
|
+
!!y && y !== "";
|
|
63
|
+
if (!(n.slices[0].segments.length === (r == null ? void 0 : r.length) && !n.slices[0].segments.find(
|
|
64
|
+
(m, F) => m.departingAt !== r[F].departingAt || m.arrivingAt !== r[F].arrivingAt || m.duration !== r[F].duration
|
|
65
|
+
)))
|
|
66
|
+
return !1;
|
|
67
|
+
let l = !1;
|
|
68
|
+
return (M && w && n.awayzMatchId === D || !h && n.awayzMatchId === I || w && !M && n.awayzMarketerMatchId === f) && (l = !0), l && (i[n.id] = p), l;
|
|
69
|
+
});
|
|
70
|
+
if (b.length) {
|
|
71
|
+
t.slices[0].comparisonKey = b[0].awayzGroupId;
|
|
72
|
+
const u = b.find((p) => {
|
|
73
|
+
var h, N, l, m;
|
|
74
|
+
const n = (h = p.flightDetails.slices[0].fareBrandName) == null ? void 0 : h.toLowerCase(), y = (N = t.slices[0].fareBrandName) == null ? void 0 : N.toLowerCase();
|
|
75
|
+
return y === n || // Special Case for AC Only match on first word
|
|
76
|
+
// Due to differences in scraped points data and Duffel format
|
|
77
|
+
g.iataCode === "AC" && ((l = y.split(" ")) == null ? void 0 : l[0]) === ((m = n.split(" ")) == null ? void 0 : m[0]);
|
|
78
|
+
});
|
|
79
|
+
if (u) {
|
|
80
|
+
const p = i[u.id], n = {
|
|
81
|
+
...t,
|
|
82
|
+
...u,
|
|
83
|
+
points: t.points,
|
|
84
|
+
airlineProgram: t.airlineProgram,
|
|
85
|
+
flightDetails: {
|
|
86
|
+
...t,
|
|
87
|
+
...u.flightDetails,
|
|
88
|
+
points: t.points,
|
|
89
|
+
airlineProgram: t.airlineProgram
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
c[p] = n;
|
|
93
|
+
} else
|
|
94
|
+
a.push(t);
|
|
95
|
+
} else
|
|
96
|
+
a.push(t);
|
|
97
|
+
}
|
|
98
|
+
return [
|
|
99
|
+
...c,
|
|
100
|
+
...k(a) ?? []
|
|
101
|
+
];
|
|
102
|
+
}, L = (s) => {
|
|
103
|
+
const e = s.operatingCarrierFlightNumber ? s.operatingCarrier : s.marketingCarrier, c = s.operatingCarrierFlightNumber ?? s.marketingCarrierFlightNumber;
|
|
104
|
+
return e.iataCode + " " + c;
|
|
105
|
+
}, P = ({
|
|
106
|
+
originCode: s,
|
|
107
|
+
destinationCode: e,
|
|
108
|
+
departureDate: c,
|
|
109
|
+
cabinClass: a,
|
|
110
|
+
passengerCount: i,
|
|
111
|
+
paymentType: o
|
|
112
|
+
}) => {
|
|
113
|
+
let t = "/flights/search/one-way/points-cash?";
|
|
114
|
+
return t += `origin=${s}`, t += `&destination=${e}`, t += `&departure_date=${c}`, t += `&cabin_class=${a}`, t += `&adults=${i}`, t += `&cash_or_points=[${o}]`, t;
|
|
115
|
+
}, $ = (s) => {
|
|
116
|
+
const e = s.reduce((a, i) => {
|
|
117
|
+
const o = i.awayzGroupId;
|
|
118
|
+
return a[o] || (a[o] = []), a[o].push(i), a;
|
|
119
|
+
}, {});
|
|
120
|
+
return Object.values(e).map(
|
|
121
|
+
(a) => {
|
|
122
|
+
const i = a[0], { origin: o, destination: t } = i;
|
|
123
|
+
return {
|
|
124
|
+
id: i.awayzGroupId,
|
|
125
|
+
origin: {
|
|
126
|
+
city: o.city,
|
|
127
|
+
country: o.country,
|
|
128
|
+
airportCode: o.airportCode,
|
|
129
|
+
coordinates: o.coordinates
|
|
130
|
+
},
|
|
131
|
+
destination: {
|
|
132
|
+
city: t.city,
|
|
133
|
+
country: t.country,
|
|
134
|
+
airportCode: t.airportCode,
|
|
135
|
+
coordinates: t.coordinates
|
|
136
|
+
},
|
|
137
|
+
airline: i.airline,
|
|
138
|
+
flightNumber: i.flightNumber,
|
|
139
|
+
lowestCash: a.reduce(
|
|
140
|
+
(r, d) => Math.min(r, d.cash),
|
|
141
|
+
1 / 0
|
|
142
|
+
),
|
|
143
|
+
lowestPoints: a.reduce(
|
|
144
|
+
(r, d) => Math.min(r, d.points),
|
|
145
|
+
1 / 0
|
|
146
|
+
),
|
|
147
|
+
paymentOptions: a.map((r) => ({
|
|
148
|
+
id: r.id,
|
|
149
|
+
cash: r.cash,
|
|
150
|
+
points: r.points,
|
|
151
|
+
cashFeeCurrency: "USD",
|
|
152
|
+
cashFeeAmount: 0,
|
|
153
|
+
baseCurrency: "USD",
|
|
154
|
+
fareBrandName: r.flightDetails.slices[0].fareBrandName,
|
|
155
|
+
conditions: {
|
|
156
|
+
refundBeforeDeparture: !0,
|
|
157
|
+
changeBeforeDeparture: !0
|
|
158
|
+
}
|
|
159
|
+
})),
|
|
160
|
+
numberOfStops: i.numberOfStops,
|
|
161
|
+
departureTime: i.departureTime,
|
|
162
|
+
arrivalTime: i.arrivalTime,
|
|
163
|
+
awayzGroupId: i.awayzGroupId,
|
|
164
|
+
duration: i.duration,
|
|
165
|
+
airlineProgram: i.airlineProgram,
|
|
166
|
+
durationMinutes: 2e3,
|
|
167
|
+
//TODO: Finalize this
|
|
168
|
+
cash: i.cash,
|
|
169
|
+
points: i.points,
|
|
170
|
+
flightDetails: i.flightDetails
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
);
|
|
174
|
+
};
|
|
175
|
+
export {
|
|
176
|
+
P as buildFlightSearchQuery,
|
|
177
|
+
L as getFlightNumber,
|
|
178
|
+
$ as groupFlightResults,
|
|
179
|
+
k as mapFlightDetailsToResults,
|
|
180
|
+
G as parseFlightDetails
|
|
181
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@odynn/awayz-flights",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist"
|
|
7
|
+
],
|
|
8
|
+
"main": "dist/main.js",
|
|
9
|
+
"types": "./dist/lib/main.d.ts",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test": "vite",
|
|
12
|
+
"dev": "npm run storybook",
|
|
13
|
+
"build": "tsc -b ./tsconfig.lib.json && vite build",
|
|
14
|
+
"stoot": "npm publish --access public",
|
|
15
|
+
"push": "npm publish --access public",
|
|
16
|
+
"lint": "eslint .",
|
|
17
|
+
"preview": "vite preview",
|
|
18
|
+
"storybook": "storybook dev -p 6006",
|
|
19
|
+
"build-storybook": "storybook build"
|
|
20
|
+
},
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"react": "^18.0.0",
|
|
23
|
+
"react-dom": "^18.0.0"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@chromatic-com/storybook": "^3.2.4",
|
|
27
|
+
"@eslint/js": "^9.17.0",
|
|
28
|
+
"@storybook/addon-essentials": "^8.5.0",
|
|
29
|
+
"@storybook/addon-interactions": "^8.5.0",
|
|
30
|
+
"@storybook/addon-onboarding": "^8.5.0",
|
|
31
|
+
"@storybook/blocks": "^8.5.0",
|
|
32
|
+
"@storybook/react": "^8.5.0",
|
|
33
|
+
"@storybook/react-vite": "^8.5.0",
|
|
34
|
+
"@storybook/test": "^8.5.0",
|
|
35
|
+
"@type-op/shared": "^1.0.0",
|
|
36
|
+
"@types/node": "^22.10.7",
|
|
37
|
+
"@types/react": "^18.3.18",
|
|
38
|
+
"@types/react-dom": "^18.3.5",
|
|
39
|
+
"@vitejs/plugin-react": "^4.3.4",
|
|
40
|
+
"axios": "^1.7.9",
|
|
41
|
+
"eslint": "^9.17.0",
|
|
42
|
+
"eslint-plugin-react-hooks": "^5.0.0",
|
|
43
|
+
"eslint-plugin-react-refresh": "^0.4.16",
|
|
44
|
+
"eslint-plugin-storybook": "^0.11.2",
|
|
45
|
+
"glob": "^11.0.1",
|
|
46
|
+
"globals": "^15.14.0",
|
|
47
|
+
"moment": "^2.30.1",
|
|
48
|
+
"moment-timezone": "^0.5.47",
|
|
49
|
+
"react": "^18.3.1",
|
|
50
|
+
"react-dom": "^18.3.1",
|
|
51
|
+
"react-icons": "^5.4.0",
|
|
52
|
+
"sass": "^1.83.4",
|
|
53
|
+
"storybook": "^8.5.0",
|
|
54
|
+
"typescript": "~5.6.2",
|
|
55
|
+
"typescript-eslint": "^8.18.2",
|
|
56
|
+
"vite": "^6.0.5",
|
|
57
|
+
"vite-plugin-dts": "^4.5.0",
|
|
58
|
+
"vite-plugin-lib-inject-css": "^2.2.1"
|
|
59
|
+
},
|
|
60
|
+
"sideEffects": [
|
|
61
|
+
"**/*.css"
|
|
62
|
+
],
|
|
63
|
+
"eslintConfig": {
|
|
64
|
+
"extends": [
|
|
65
|
+
"plugin:storybook/recommended"
|
|
66
|
+
]
|
|
67
|
+
},
|
|
68
|
+
"dependencies": {
|
|
69
|
+
"@microsoft/fetch-event-source": "^2.0.1",
|
|
70
|
+
"@odynn/awayz-auth": "^0.1.7"
|
|
71
|
+
}
|
|
72
|
+
}
|