@odynn/awayz-hotels 0.2.2 → 0.2.4
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/components/Banners/Ratings/Ratings.js +12 -11
- package/dist/hooks/useHotelDetails/useHotelDetails.api.js +54 -48
- package/dist/hooks/useHotelSort/useHotelSort.js +123 -0
- package/dist/hooks/useHotelSort/useHotelSort.types.js +5 -0
- package/dist/lib/hooks/useHotelDetails/useHotelDetails.api.d.ts +1 -1
- package/dist/lib/hooks/useHotelSort/useHotelSort.d.ts +6 -0
- package/dist/lib/hooks/useHotelSort/useHotelSort.types.d.ts +16 -0
- package/package.json +1 -1
|
@@ -1,23 +1,24 @@
|
|
|
1
|
-
import { jsxs as a, jsx as
|
|
2
|
-
import { a as
|
|
1
|
+
import { jsxs as a, jsx as n } from "react/jsx-runtime";
|
|
2
|
+
import { a as m, b as d } from "../../../index-D8bHwbxH.js";
|
|
3
3
|
import '../../../assets/Ratings.css';var p = /* @__PURE__ */ ((r) => (r.INHERIT = "inherit", r.PRIMARY = "primary", r.LIGHT = "light", r.DARK = "dark", r))(p || {});
|
|
4
|
-
const
|
|
4
|
+
const u = ({
|
|
5
5
|
starRating: r,
|
|
6
6
|
userRating: e,
|
|
7
|
-
color:
|
|
7
|
+
color: t = "dark",
|
|
8
8
|
fill: c = !1,
|
|
9
|
-
starColor:
|
|
9
|
+
starColor: s = "primary"
|
|
10
10
|
/* PRIMARY */
|
|
11
11
|
}) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
const l = !e || e === 0 || e.toString().toLowerCase() === "none";
|
|
13
|
+
if (!r && l) return null;
|
|
14
|
+
const i = r ? c ? /* @__PURE__ */ n(m, { className: s }) : /* @__PURE__ */ n(d, { className: s }) : null;
|
|
15
|
+
return /* @__PURE__ */ a("div", { className: `rating ${t}`, children: [
|
|
16
|
+
i,
|
|
16
17
|
r ? /* @__PURE__ */ a("p", { children: [
|
|
17
18
|
r,
|
|
18
19
|
"-star"
|
|
19
20
|
] }) : null,
|
|
20
|
-
|
|
21
|
+
l ? null : /* @__PURE__ */ a("p", { children: [
|
|
21
22
|
"(",
|
|
22
23
|
e,
|
|
23
24
|
" rating)"
|
|
@@ -26,5 +27,5 @@ const o = ({
|
|
|
26
27
|
};
|
|
27
28
|
export {
|
|
28
29
|
p as ERatingColor,
|
|
29
|
-
|
|
30
|
+
u as default
|
|
30
31
|
};
|
|
@@ -1,81 +1,87 @@
|
|
|
1
|
-
import { HotelService as
|
|
2
|
-
import { BookingService as
|
|
3
|
-
import { HotelChains as
|
|
4
|
-
import { EBestCheckoutType as
|
|
1
|
+
import { HotelService as f } from "../../services/hotel/HotelService.js";
|
|
2
|
+
import { BookingService as d } from "../../services/booking/BookingService.js";
|
|
3
|
+
import { HotelChains as l } from "../../definitions/HotelChains.js";
|
|
4
|
+
import { EBestCheckoutType as m } from "../../enums/EBestCheckoutType.js";
|
|
5
5
|
import { EGuestType as y } from "../../services/booking/BookingService.enums.js";
|
|
6
|
-
const w = async (o) => await
|
|
7
|
-
|
|
6
|
+
const w = async (o) => await f.getTransferPartners(
|
|
7
|
+
l.toProgram(o)
|
|
8
8
|
), T = async ({
|
|
9
9
|
hotel: o,
|
|
10
10
|
checkinDate: s,
|
|
11
|
-
checkoutDate:
|
|
11
|
+
checkoutDate: n,
|
|
12
12
|
updateHotel: t
|
|
13
13
|
}) => {
|
|
14
|
-
let
|
|
15
|
-
if (!o.liveScrapingCheckNeeded || o.hotelGroup ===
|
|
14
|
+
let e = o, i = o.rooms ?? [];
|
|
15
|
+
if (!o.liveScrapingCheckNeeded || o.hotelGroup === l.Marriott)
|
|
16
16
|
return {
|
|
17
17
|
pointsHotelDetails: o,
|
|
18
18
|
pointsRooms: i
|
|
19
19
|
};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
20
|
+
let r = !1, c = null;
|
|
21
|
+
try {
|
|
22
|
+
const a = await f.hotelPointsCheck({
|
|
23
|
+
hotelGroup: o.hotelGroup,
|
|
24
|
+
hotelId: o.hotelId,
|
|
25
|
+
checkinDate: s,
|
|
26
|
+
checkoutDate: n
|
|
27
|
+
});
|
|
28
|
+
r = a.success, c = a.data;
|
|
29
|
+
} catch {
|
|
30
|
+
r = !1, c = null;
|
|
31
|
+
}
|
|
32
|
+
if (r) {
|
|
33
|
+
const a = c, u = !(a.points.pointsValue > 0) && o.bestValue === m.POINTS;
|
|
34
|
+
e = {
|
|
29
35
|
...o,
|
|
30
|
-
awardPoints:
|
|
31
|
-
points:
|
|
32
|
-
pointsType:
|
|
33
|
-
bestValue: u ?
|
|
34
|
-
}, i =
|
|
36
|
+
awardPoints: a.points.awardPointsValue ?? a.points.pointsValue,
|
|
37
|
+
points: a.points.pointsValue,
|
|
38
|
+
pointsType: a.points.pointsType,
|
|
39
|
+
bestValue: u ? m.NONE : o.bestValue
|
|
40
|
+
}, i = a.rooms ?? o.rooms ?? [], t(o.hotelId, o.hotelGroup, e);
|
|
35
41
|
}
|
|
36
42
|
return {
|
|
37
|
-
pointsHotelDetails:
|
|
43
|
+
pointsHotelDetails: e,
|
|
38
44
|
pointsRooms: i
|
|
39
45
|
};
|
|
40
46
|
}, A = async ({
|
|
41
47
|
hotel: o,
|
|
42
48
|
checkinDate: s,
|
|
43
|
-
checkoutDate:
|
|
49
|
+
checkoutDate: n,
|
|
44
50
|
guests: t,
|
|
45
|
-
rooms:
|
|
51
|
+
rooms: e,
|
|
46
52
|
updateHotel: i,
|
|
47
53
|
numberOfNights: r
|
|
48
54
|
}) => {
|
|
49
|
-
var
|
|
50
|
-
if (!((
|
|
55
|
+
var u;
|
|
56
|
+
if (!((u = o == null ? void 0 : o.cashBookingOffers) != null && u.accommodationId))
|
|
51
57
|
return {
|
|
52
58
|
cashHotelDetails: o,
|
|
53
59
|
cashRooms: []
|
|
54
60
|
};
|
|
55
|
-
const
|
|
61
|
+
const c = (h) => Array.from({ length: h }, () => ({ type: y.ADULT })), a = await d.getAvailableRooms({
|
|
56
62
|
checkinDate: s,
|
|
57
|
-
checkoutDate:
|
|
63
|
+
checkoutDate: n,
|
|
58
64
|
accommodationId: o.cashBookingOffers.accommodationId,
|
|
59
|
-
guests:
|
|
60
|
-
rooms:
|
|
61
|
-
}),
|
|
65
|
+
guests: c(t),
|
|
66
|
+
rooms: e
|
|
67
|
+
}), p = {
|
|
62
68
|
...o,
|
|
63
69
|
cashValue: {
|
|
64
70
|
...o.cashValue,
|
|
65
|
-
amount:
|
|
66
|
-
currency:
|
|
71
|
+
amount: a.cheapestRate / r || o.cashValue.amount || 0,
|
|
72
|
+
currency: a.currency ?? o.cashValue.currency
|
|
67
73
|
}
|
|
68
74
|
};
|
|
69
|
-
return i(o.hotelId, o.hotelGroup,
|
|
70
|
-
cashHotelDetails:
|
|
71
|
-
cashRooms:
|
|
75
|
+
return i(o.hotelId, o.hotelGroup, p), {
|
|
76
|
+
cashHotelDetails: p,
|
|
77
|
+
cashRooms: a.availableRooms
|
|
72
78
|
};
|
|
73
79
|
}, G = async (o, s) => {
|
|
74
|
-
const { success:
|
|
80
|
+
const { success: n, data: t } = await f.getRecommendations({
|
|
75
81
|
days: s,
|
|
76
82
|
hotels: [o]
|
|
77
83
|
});
|
|
78
|
-
return
|
|
84
|
+
return n ? {
|
|
79
85
|
bestCheckout: t,
|
|
80
86
|
isAvailable: t.nightlyPointsCost > 0 || t.nightlyCashCost > 0
|
|
81
87
|
} : {
|
|
@@ -83,23 +89,23 @@ const w = async (o) => await m.getTransferPartners(
|
|
|
83
89
|
isAvailable: !1
|
|
84
90
|
};
|
|
85
91
|
}, C = (o, s) => {
|
|
86
|
-
var t,
|
|
92
|
+
var t, e;
|
|
87
93
|
return {
|
|
88
|
-
bestCheckoutMethod:
|
|
94
|
+
bestCheckoutMethod: l.isHotelChain(o.hotelGroup) ? o.bestValue : m.CASH,
|
|
89
95
|
nightlyCashCost: ((t = o.cashValue) == null ? void 0 : t.amount) || 0,
|
|
90
96
|
nightlyPointsCost: o.points || 0,
|
|
91
97
|
awardPoints: o.points || 0,
|
|
92
|
-
totalCashCost: (((
|
|
98
|
+
totalCashCost: (((e = o.cashValue) == null ? void 0 : e.amount) || 0) * s,
|
|
93
99
|
totalPointsCost: (o.points || 0) * s,
|
|
94
100
|
currency: "USD",
|
|
95
101
|
sufficientPoints: !0,
|
|
96
|
-
rewardsProgram:
|
|
102
|
+
rewardsProgram: l.toProgram(o.hotelGroup),
|
|
97
103
|
optimalProgram: {
|
|
98
104
|
programs: [],
|
|
99
105
|
remainingPointsBalance: 0
|
|
100
106
|
}
|
|
101
107
|
};
|
|
102
|
-
}, B = (o, s,
|
|
108
|
+
}, B = (o, s, n) => {
|
|
103
109
|
let t = o;
|
|
104
110
|
return s && (t = {
|
|
105
111
|
...o,
|
|
@@ -107,10 +113,10 @@ const w = async (o) => await m.getTransferPartners(
|
|
|
107
113
|
awardPoints: s.awardPoints,
|
|
108
114
|
pointsType: s.pointsType,
|
|
109
115
|
bestValue: s.bestValue
|
|
110
|
-
}),
|
|
116
|
+
}), n && (t = {
|
|
111
117
|
...t,
|
|
112
|
-
cashValue:
|
|
113
|
-
rooms:
|
|
118
|
+
cashValue: n.cashValue,
|
|
119
|
+
rooms: n.rooms
|
|
114
120
|
}), t;
|
|
115
121
|
};
|
|
116
122
|
export {
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { HotelChains as N } from "../../definitions/HotelChains.js";
|
|
2
|
+
import { EHotelSortOption as m, ESortingOrder as a } from "./useHotelSort.types.js";
|
|
3
|
+
const H = (n) => {
|
|
4
|
+
var o;
|
|
5
|
+
return Math.round(
|
|
6
|
+
((o = n.cashBookingOffers) == null ? void 0 : o.cheapestRateTotalAmount) || n.cashValue.amount
|
|
7
|
+
);
|
|
8
|
+
}, I = (n, e, o) => {
|
|
9
|
+
const u = H(n), t = H(e);
|
|
10
|
+
return u <= 0 ? 1 : o === a.DESCENDING ? t - u : u - t;
|
|
11
|
+
}, R = (n, e, o) => {
|
|
12
|
+
const u = n.hotelGroup == "other", t = e.hotelGroup == "other";
|
|
13
|
+
return u && !t ? 1 : !u && t ? -1 : o === a.DESCENDING ? e.chainRating - n.chainRating : n.chainRating - e.chainRating;
|
|
14
|
+
}, g = (n, e, o) => o === a.DESCENDING ? e.distance - n.distance : n.distance - e.distance, w = (n, e, o) => {
|
|
15
|
+
const u = n.points <= 0 ? Number.MAX_VALUE : n.points, t = e.points <= 0 ? Number.MAX_VALUE : e.points;
|
|
16
|
+
return o === a.DESCENDING ? t * e.hotelProgram.valueCent - u * n.hotelProgram.valueCent : u * n.hotelProgram.valueCent - t * e.hotelProgram.valueCent;
|
|
17
|
+
}, p = (n, e, o) => n.chainRating !== e.chainRating ? R(n, e, o) : g(n, e, a.ASCENDING), O = (n) => {
|
|
18
|
+
if (!n.hotelData)
|
|
19
|
+
throw new Error("hotelData is required");
|
|
20
|
+
if (!n.orderBy)
|
|
21
|
+
throw new Error("orderBy is required");
|
|
22
|
+
if (!n.sortOrder)
|
|
23
|
+
throw new Error("sortOrder is required");
|
|
24
|
+
if (!Object.values(m).includes(n.orderBy))
|
|
25
|
+
throw new Error(
|
|
26
|
+
`Invalid orderBy: ${n.orderBy}. Please use one of the following: ${Object.values(
|
|
27
|
+
m
|
|
28
|
+
).join(", ")}`
|
|
29
|
+
);
|
|
30
|
+
if (!Object.values(a).includes(n.sortOrder))
|
|
31
|
+
throw new Error(
|
|
32
|
+
`Invalid sortOrder: ${n.sortOrder}. Please use one of the following: ${Object.values(a).join(
|
|
33
|
+
", "
|
|
34
|
+
)}`
|
|
35
|
+
);
|
|
36
|
+
}, P = () => ({
|
|
37
|
+
sortHotelResults: ({
|
|
38
|
+
hotelData: o,
|
|
39
|
+
orderBy: u,
|
|
40
|
+
sortOrder: t
|
|
41
|
+
}) => {
|
|
42
|
+
O({ hotelData: o, orderBy: u, sortOrder: t });
|
|
43
|
+
const l = () => {
|
|
44
|
+
const { chainHotels: r, nonChainHotels: h } = o.reduce(
|
|
45
|
+
(s, i) => (N.isMajorChain(i.hotelGroup) ? s.chainHotels.push(i) : s.nonChainHotels.push(i), s),
|
|
46
|
+
{
|
|
47
|
+
chainHotels: [],
|
|
48
|
+
nonChainHotels: []
|
|
49
|
+
}
|
|
50
|
+
), {
|
|
51
|
+
majorChainsWithAccommodationIds: f,
|
|
52
|
+
majorChainsWithoutAccommodationIds: C
|
|
53
|
+
} = r.reduce(
|
|
54
|
+
(s, i) => {
|
|
55
|
+
var E;
|
|
56
|
+
return (E = i.cashBookingOffers) != null && E.accommodationId ? s.majorChainsWithAccommodationIds.push(i) : s.majorChainsWithoutAccommodationIds.push(i), s;
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
majorChainsWithAccommodationIds: [],
|
|
60
|
+
majorChainsWithoutAccommodationIds: []
|
|
61
|
+
}
|
|
62
|
+
);
|
|
63
|
+
f.sort(
|
|
64
|
+
(s, i) => p(s, i, t)
|
|
65
|
+
), C.sort(
|
|
66
|
+
(s, i) => p(s, i, t)
|
|
67
|
+
);
|
|
68
|
+
const { luxuryHotels: A, otherProperties: S } = h.reduce(
|
|
69
|
+
(s, i) => (i.hotelGroup !== "other" ? s.luxuryHotels.push(i) : s.otherProperties.push(i), s),
|
|
70
|
+
{
|
|
71
|
+
luxuryHotels: [],
|
|
72
|
+
otherProperties: []
|
|
73
|
+
}
|
|
74
|
+
);
|
|
75
|
+
return A.sort((s, i) => p(s, i, t)), S.sort((s, i) => p(s, i, t)), [
|
|
76
|
+
...f,
|
|
77
|
+
// available to book on Duffel
|
|
78
|
+
...C,
|
|
79
|
+
// unavailable to book on Duffel
|
|
80
|
+
...A,
|
|
81
|
+
// luxury hotels
|
|
82
|
+
...S
|
|
83
|
+
// other properties
|
|
84
|
+
];
|
|
85
|
+
};
|
|
86
|
+
let c = [], d = [];
|
|
87
|
+
switch (u) {
|
|
88
|
+
case m.CASH:
|
|
89
|
+
return c = o == null ? void 0 : o.filter((r) => r.cashValue.amount > 0).sort((r, h) => I(r, h, t)), d = o == null ? void 0 : o.filter(
|
|
90
|
+
(r) => r.cashValue.amount <= 0
|
|
91
|
+
), c == null ? void 0 : c.concat(d);
|
|
92
|
+
case m.POINTS:
|
|
93
|
+
return c = o == null ? void 0 : o.filter((r) => r.points > 0).sort((r, h) => w(r, h, t)), d = o == null ? void 0 : o.filter((r) => r.points <= 0).sort((r, h) => I(r, h, t)), c == null ? void 0 : c.concat(d);
|
|
94
|
+
case m.STAR_RATING:
|
|
95
|
+
return c = o == null ? void 0 : o.filter(
|
|
96
|
+
(r) => r.cashValue.amount > 0 || r.points > 0
|
|
97
|
+
).sort((r, h) => r.cashValue.amount <= 0 && r.points <= 0 ? 1 : r.chainRating === h.chainRating ? g(r, h, t) : R(r, h, t)), d = o == null ? void 0 : o.filter(
|
|
98
|
+
(r) => r.cashValue.amount <= 0 && r.points <= 0
|
|
99
|
+
), c == null ? void 0 : c.concat(d);
|
|
100
|
+
case m.BOOKABLE:
|
|
101
|
+
return l();
|
|
102
|
+
default:
|
|
103
|
+
return l();
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
hotelSortOptionsToString: (o) => {
|
|
107
|
+
switch (o) {
|
|
108
|
+
case m.CASH:
|
|
109
|
+
return "Cash";
|
|
110
|
+
case m.POINTS:
|
|
111
|
+
return "Points";
|
|
112
|
+
case m.STAR_RATING:
|
|
113
|
+
return "Star Rating";
|
|
114
|
+
case m.BOOKABLE:
|
|
115
|
+
return "Bookable";
|
|
116
|
+
default:
|
|
117
|
+
return "Not specified";
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
export {
|
|
122
|
+
P as useHotelSort
|
|
123
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
var N = /* @__PURE__ */ ((A) => (A.ASCENDING = "ASC", A.DESCENDING = "DESC", A))(N || {}), C = /* @__PURE__ */ ((A) => (A.CASH = "CASH", A.POINTS = "POINTS", A.STAR_RATING = "STAR_RATING", A.BOOKABLE = "BOOKABLE", A))(C || {});
|
|
2
|
+
export {
|
|
3
|
+
C as EHotelSortOption,
|
|
4
|
+
N as ESortingOrder
|
|
5
|
+
};
|
|
@@ -51,5 +51,5 @@ interface IFetchBestCheckoutResponse {
|
|
|
51
51
|
}
|
|
52
52
|
export declare const fetchBestCheckout: (hotel: IHotelDetails, numberOfNights: number) => Promise<IFetchBestCheckoutResponse>;
|
|
53
53
|
export declare const fallbackBestCheckout: (selectedHotelData: IHotelDetails, numberOfNights: number) => IBestCheckout;
|
|
54
|
-
export declare const combineUpdatedHotelData: (base: IHotelDetails,
|
|
54
|
+
export declare const combineUpdatedHotelData: (base: IHotelDetails, liveScraperData: IHotelDetails, cashRoomsData: IHotelDetails) => IHotelDetails;
|
|
55
55
|
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { IHotelDetails } from '../../main';
|
|
2
|
+
import { EHotelSortOption, ISortHotelResultsParams } from './useHotelSort.types';
|
|
3
|
+
export declare const useHotelSort: () => {
|
|
4
|
+
sortHotelResults: ({ hotelData, orderBy, sortOrder }: ISortHotelResultsParams) => IHotelDetails[];
|
|
5
|
+
hotelSortOptionsToString: (type: EHotelSortOption) => "Bookable" | "Cash" | "Points" | "Star Rating" | "Not specified";
|
|
6
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { IHotelDetails } from '../../main';
|
|
2
|
+
export declare enum ESortingOrder {
|
|
3
|
+
ASCENDING = "ASC",
|
|
4
|
+
DESCENDING = "DESC"
|
|
5
|
+
}
|
|
6
|
+
export declare enum EHotelSortOption {
|
|
7
|
+
CASH = "CASH",
|
|
8
|
+
POINTS = "POINTS",
|
|
9
|
+
STAR_RATING = "STAR_RATING",
|
|
10
|
+
BOOKABLE = "BOOKABLE"
|
|
11
|
+
}
|
|
12
|
+
export interface ISortHotelResultsParams {
|
|
13
|
+
hotelData: IHotelDetails[];
|
|
14
|
+
orderBy: EHotelSortOption;
|
|
15
|
+
sortOrder: ESortingOrder;
|
|
16
|
+
}
|