@odynn/awayz-hotels 0.2.21 → 0.2.23

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.
@@ -0,0 +1,11 @@
1
+ import { h as t } from "./moment-BGjjqtLQ.js";
2
+ import "./arrayExtensions-CFEBYUok.js";
3
+ const r = (a, s) => Math.abs(
4
+ t(t(a).startOf("day")).diff(
5
+ t(t(s).endOf("day")),
6
+ "days"
7
+ )
8
+ );
9
+ export {
10
+ r as g
11
+ };
@@ -0,0 +1,8 @@
1
+ const e = [
2
+ "IHG Rewards Club Premier",
3
+ "IHG Rewards Club Traveler",
4
+ "IHG Rewards Premier Business Credit Card"
5
+ ];
6
+ export {
7
+ e as IhgFreeNightCards
8
+ };
@@ -0,0 +1,4 @@
1
+ var R = /* @__PURE__ */ ((C) => (C.LOCATIONS = "LOCATIONS", C.CHECK_USER = "CHECK_USER", C.USER_REGIONS = "USER_REGIONS", C.CONVERT_CURRENCY = "CONVERT_CURRENCY", C.CLIENT_COMPONENT_KEY = "CLIENT_COMPONENT_KEY", C.SEARCH_LIMIT = "SEARCH_LIMIT", C.PROGRAMS = "PROGRAMS", C.BANKS = "BANKS", C.CARDS = "CARDS", C))(R || {});
2
+ export {
3
+ R as E
4
+ };
@@ -1,49 +1,48 @@
1
- import { useState as Q, useMemo as W } from "react";
2
- import { h as i } from "../../moment-BGjjqtLQ.js";
1
+ import { useState as M, useMemo as Q } from "react";
2
+ import { g as W } from "../../dateUtils-C1hKW8MF.js";
3
3
  import "../../arrayExtensions-CFEBYUok.js";
4
- import _ from "../../stores/useHotelsStore.js";
5
- import { fetchTransferPartners as j, fetchPointsCheck as J, fetchAvailableRooms as V, fallbackBestCheckout as X, fetchBestCheckout as Y, combineUpdatedHotelData as q } from "./useHotelDetails.api.js";
6
- import { calculatePointsAsCash as Z } from "../../utilities/pointsAsCashUtils.js";
7
- import { useQuery as a } from "@tanstack/react-query";
8
- import { useAwayzContext as $ } from "@odynn/awayz-core";
9
- const ee = (t, c) => Math.abs(
10
- i(t.startOf("day")).diff(i(c.endOf("day")), "days")
11
- ), ue = (t) => {
12
- var k, d, p, m, y, C, b, g, v, F, O, R;
4
+ import Y from "../../stores/useHotelsStore.js";
5
+ import { fetchTransferPartners as j, fetchPointsCheck as J, fetchAvailableRooms as V, fallbackBestCheckout as X, fetchBestCheckout as Z, combineUpdatedHotelData as O } from "./useHotelDetails.api.js";
6
+ import { calculatePointsAsCash as $ } from "../../utilities/pointsAsCashUtils.js";
7
+ import { useQuery as c } from "@tanstack/react-query";
8
+ import { h as q } from "../../moment-BGjjqtLQ.js";
9
+ import { useAwayzContext as ee } from "@odynn/awayz-core";
10
+ const te = "USD", le = (t) => {
11
+ var k, f, p, m, d, y, C, g, b, v, F, R;
13
12
  if (!t)
14
13
  throw new Error(
15
14
  "Hotel is required in order to initiate the hotel details flow"
16
15
  );
17
- const { user: c } = $(), H = ((k = c == null ? void 0 : c.userRegion) == null ? void 0 : k.currency) || "USD", { updateHotel: n, searchParams: o } = _(), [e, A] = Q({
16
+ const { user: s } = ee(), H = ((k = s == null ? void 0 : s.userRegion) == null ? void 0 : k.currency) || te, { updateHotel: i, searchParams: o } = Y(), [e, A] = M({
18
17
  checkinDate: o == null ? void 0 : o.checkinDate,
19
18
  checkoutDate: o == null ? void 0 : o.checkoutDate
20
- }), s = W(() => ee(e.checkinDate, e.checkoutDate), [e]), B = (E, L) => {
19
+ }), a = Q(() => W(e.checkinDate, e.checkoutDate), [e]), B = (_, z) => {
21
20
  A({
22
- checkinDate: i(E),
23
- checkoutDate: i(L)
21
+ checkinDate: q(_),
22
+ checkoutDate: q(z)
24
23
  });
25
- }, { data: I, isFetching: G } = a({
24
+ }, { data: I, isFetching: G } = c({
26
25
  queryKey: ["transferPartners", t.hotelGroup],
27
26
  queryFn: () => j(t.hotelGroup),
28
27
  enabled: !!t.hotelGroup,
29
28
  placeholderData: []
30
29
  }), {
31
30
  data: S,
32
- isFetching: r,
31
+ isFetching: n,
33
32
  isFetched: w
34
- } = a({
33
+ } = c({
35
34
  queryKey: [
36
35
  "hotelPointsCheck",
37
36
  t.hotelId,
38
37
  t.hotelGroup,
39
- (d = e == null ? void 0 : e.checkinDate) == null ? void 0 : d.valueOf(),
38
+ (f = e == null ? void 0 : e.checkinDate) == null ? void 0 : f.valueOf(),
40
39
  (p = e == null ? void 0 : e.checkoutDate) == null ? void 0 : p.valueOf()
41
40
  ],
42
41
  queryFn: () => J({
43
42
  hotel: t,
44
43
  checkinDate: e.checkinDate,
45
44
  checkoutDate: e.checkoutDate,
46
- updateHotel: n
45
+ updateHotel: i
47
46
  }),
48
47
  enabled: !!e.checkinDate && !!e.checkoutDate && !!t.liveScrapingCheckNeeded,
49
48
  // We don't throw an error on fail so we can gracefully handle fallback
@@ -52,19 +51,19 @@ const ee = (t, c) => Math.abs(
52
51
  pointsHotelDetails: t,
53
52
  pointsRooms: t.rooms ?? []
54
53
  }
55
- }), { pointsRooms: K, pointsHotelDetails: u } = S || {
54
+ }), { pointsRooms: K, pointsHotelDetails: r } = S || {
56
55
  pointsHotelDetails: t,
57
56
  pointsRooms: []
58
57
  }, {
59
58
  data: N,
60
- isFetching: h,
61
- isFetched: x
62
- } = a({
59
+ isFetching: u,
60
+ isFetched: U
61
+ } = c({
63
62
  queryKey: [
64
63
  "fetchAvailableRooms",
65
64
  (m = t.cashBookingOffers) == null ? void 0 : m.accommodationId,
66
- (y = e == null ? void 0 : e.checkinDate) == null ? void 0 : y.valueOf(),
67
- (C = e == null ? void 0 : e.checkoutDate) == null ? void 0 : C.valueOf(),
65
+ (d = e == null ? void 0 : e.checkinDate) == null ? void 0 : d.valueOf(),
66
+ (y = e == null ? void 0 : e.checkoutDate) == null ? void 0 : y.valueOf(),
68
67
  o == null ? void 0 : o.guests,
69
68
  o == null ? void 0 : o.rooms
70
69
  ],
@@ -74,53 +73,53 @@ const ee = (t, c) => Math.abs(
74
73
  checkoutDate: e.checkoutDate,
75
74
  guests: o.guests,
76
75
  rooms: o.rooms,
77
- updateHotel: n,
78
- numberOfNights: s
76
+ updateHotel: i,
77
+ numberOfNights: a
79
78
  }),
80
- enabled: !!e.checkinDate && !!e.checkoutDate && !!((b = t.cashBookingOffers) != null && b.accommodationId),
79
+ enabled: !!e.checkinDate && !!e.checkoutDate && !!((C = t.cashBookingOffers) != null && C.accommodationId),
81
80
  retry: !1,
82
81
  placeholderData: {
83
82
  cashHotelDetails: t,
84
83
  cashRooms: []
85
84
  }
86
- }), { cashRooms: M, cashHotelDetails: l } = N || {
85
+ }), { cashRooms: E, cashHotelDetails: h } = N || {
87
86
  cashHotelDetails: t,
88
87
  cashRooms: []
89
88
  }, {
90
- data: P,
91
- isFetching: T,
92
- isFetched: U
93
- } = a({
89
+ data: T,
90
+ isFetching: x,
91
+ isFetched: L
92
+ } = c({
94
93
  queryKey: [
95
94
  "bestCheckout",
96
95
  t.hotelId,
97
96
  t.hotelGroup,
98
97
  (g = e == null ? void 0 : e.checkinDate) == null ? void 0 : g.valueOf(),
99
- (v = e == null ? void 0 : e.checkoutDate) == null ? void 0 : v.valueOf()
98
+ (b = e == null ? void 0 : e.checkoutDate) == null ? void 0 : b.valueOf()
100
99
  ],
101
- queryFn: () => Y(
102
- q(t, u, l),
103
- s,
100
+ queryFn: () => Z(
101
+ O(t, r, h),
102
+ a,
104
103
  H
105
104
  ),
106
- enabled: !t.hotelId.startsWith("duff_") && !r && (t.liveScrapingCheckNeeded ? w : !0) && !h && ((F = t.cashBookingOffers) != null && F.accommodationId ? x : !0) && s > 0,
105
+ enabled: !t.hotelId.startsWith("duff_") && !n && (t.liveScrapingCheckNeeded ? w : !0) && !u && ((v = t.cashBookingOffers) != null && v.accommodationId ? U : !0) && a > 0 && t.points >= 0,
107
106
  retry: !1,
108
107
  placeholderData: {
109
- bestCheckout: X(t, s),
108
+ bestCheckout: X(t, a),
110
109
  isAvailable: !1
111
110
  }
112
- }), { bestCheckout: D, isAvailable: f } = P || {
111
+ }), { bestCheckout: l, isAvailable: D } = T || {
113
112
  isAvailable: !1
114
- }, { data: z } = a({
113
+ }, { data: P } = c({
115
114
  queryKey: [
116
115
  "pointsAsCash",
117
116
  t.hotelId,
118
117
  t.hotelGroup,
119
- (O = e == null ? void 0 : e.checkinDate) == null ? void 0 : O.valueOf(),
118
+ (F = e == null ? void 0 : e.checkinDate) == null ? void 0 : F.valueOf(),
120
119
  (R = e == null ? void 0 : e.checkoutDate) == null ? void 0 : R.valueOf()
121
120
  ],
122
- queryFn: () => Z(D.totalCashCost),
123
- enabled: U && f,
121
+ queryFn: () => $(l.totalCashCost),
122
+ enabled: L && D,
124
123
  retry: !1
125
124
  });
126
125
  return {
@@ -128,25 +127,25 @@ const ee = (t, c) => Math.abs(
128
127
  loadingTransferPartners: G,
129
128
  // Points Check
130
129
  pointsRooms: K,
131
- loadingLivePointsCheck: r,
130
+ loadingLivePointsCheck: n,
132
131
  // Cash Rooms
133
- cashRooms: M,
134
- loadingCashRooms: h,
132
+ cashRooms: E,
133
+ loadingCashRooms: u,
135
134
  // Best Checkout
136
- bestCheckout: D,
137
- loadingBestCheckout: T,
135
+ bestCheckout: l,
136
+ loadingBestCheckout: x,
138
137
  // Combined availability
139
- isAvailable: f,
138
+ isAvailable: D,
140
139
  // Points as Cash
141
- pointsAsCash: z,
142
- hotelDetails: q(
140
+ pointsAsCash: P,
141
+ hotelDetails: O(
143
142
  t,
144
- u,
145
- l
143
+ r,
144
+ h
146
145
  ),
147
146
  updateDates: B
148
147
  };
149
148
  };
150
149
  export {
151
- ue as useHotelDetails
150
+ le as useHotelDetails
152
151
  };
@@ -1,52 +1,55 @@
1
- import { useMutation as h } from "@tanstack/react-query";
2
- import { HotelService as u } from "../../services/hotel/HotelService.js";
3
- import { ESearchType as _ } from "../../services/hotel/HotelService.types.js";
4
- import { HotelChains as t } from "../../definitions/HotelChains.js";
5
- import { h as c } from "../../moment-BGjjqtLQ.js";
6
- import D from "../../stores/useHotelsStore.js";
7
- import { useAwayzContext as E, awayzClient as a } from "@odynn/awayz-core";
1
+ import { useMutation as d } from "@tanstack/react-query";
2
+ import { HotelService as m } from "../../services/hotel/HotelService.js";
3
+ import { ESearchType as p } from "../../services/hotel/HotelService.types.js";
4
+ import { HotelChains as s } from "../../definitions/HotelChains.js";
5
+ import { h as a } from "../../moment-BGjjqtLQ.js";
6
+ import P from "../../stores/useHotelsStore.js";
7
+ import { useAwayzContext as T, useWallet as B, awayzClient as f } from "@odynn/awayz-core";
8
+ import { g as G } from "../../dateUtils-C1hKW8MF.js";
9
+ import { E as k } from "../../enums-Boat1JS-.js";
8
10
  import "../../arrayExtensions-CFEBYUok.js";
9
- import { E as l } from "../../enums-BIly_FuI.js";
10
11
  import "react";
11
- const I = (o) => {
12
- if (!o.checkinDate || !o.checkoutDate)
13
- throw new Error("Checkin and checkout dates are required");
14
- if (!o.coordinates)
15
- throw new Error("Coordinates are required");
16
- o.hotelGroups && o.hotelGroups.forEach((r) => {
17
- if (!t.toList().includes(r))
12
+ import { checkNthNightFree as x } from "../../utilities/hotelUtils/freeNightUtils.js";
13
+ const A = (t) => {
14
+ if (!t.checkinDate || !t.checkoutDate)
15
+ throw new Error("Check-in and checkout dates are required.");
16
+ if (!t.coordinates)
17
+ throw new Error("Coordinates are required.");
18
+ t.hotelGroups && t.hotelGroups.forEach((i) => {
19
+ if (!s.toList().includes(i))
18
20
  throw new Error(
19
- `Invalid hotel group: ${r}. Please use one of the following: ${t.toList().join(
21
+ `Invalid hotel group: ${i}. Please use one of the following: ${s.toList().join(
20
22
  ", "
21
23
  )}`
22
24
  );
23
25
  });
24
- }, C = (o) => {
25
- if (!o.checkinDate || !o.checkoutDate)
26
- throw new Error("Checkin and checkout dates are required");
27
- if (!o.hotelId)
28
- throw new Error("Hotel ID is required");
29
- if (!o.hotelGroup)
26
+ }, N = (t) => {
27
+ if (!t.checkinDate || !t.checkoutDate)
28
+ throw new Error("Check-in and checkout dates are required.");
29
+ if (!t.hotelName)
30
+ throw new Error("Hotel name is required");
31
+ if (!t.hotelGroup)
30
32
  throw new Error("Hotel group is required");
31
- if (!t.toList().includes(o.hotelGroup))
33
+ if (!s.toList().includes(t.hotelGroup))
32
34
  throw new Error(
33
- `Invalid hotel group: ${o.hotelGroup}. Please use one of the following: ${t.toList().join(", ")}`
35
+ `Invalid hotel group: ${t.hotelGroup}. Please use one of the following: ${s.toList().join(", ")}`
34
36
  );
35
- }, $ = () => {
36
- const { setHotels: o, hotels: r, setSearchParams: s } = D(), { config: i } = E(), {
37
- mutate: d,
38
- status: m,
39
- isError: p,
40
- error: y
41
- } = h({
37
+ }, Y = () => {
38
+ const { setHotels: t, hotels: i, setSearchParams: l } = P(), { config: u } = T(), { cards: y } = B(), {
39
+ mutate: D,
40
+ isPending: w,
41
+ status: S,
42
+ isError: _,
43
+ error: E
44
+ } = d({
42
45
  mutationFn: async (e) => {
43
- I(e), o([]), s({
44
- checkinDate: c(e.checkinDate),
45
- checkoutDate: c(e.checkoutDate),
46
+ A(e), t([]), l({
47
+ checkinDate: a(e.checkinDate),
48
+ checkoutDate: a(e.checkoutDate),
46
49
  guests: e.guests || 2,
47
50
  rooms: e.rooms || 1
48
51
  });
49
- const n = {
52
+ const o = {
50
53
  check_in_date: e.checkinDate,
51
54
  check_out_date: e.checkoutDate,
52
55
  guests: e.guests || 2,
@@ -57,61 +60,96 @@ const I = (o) => {
57
60
  lon: e.coordinates.longitude,
58
61
  search_range: e.searchRange || 10,
59
62
  range_type: e.rangeType || "mi",
60
- hotel_groups: e.hotelGroups || t.toList(),
61
- type: e.searchType || _.CITY,
62
- external_inventory: (i == null ? void 0 : i.externalInventory) || !1
63
+ hotel_groups: e.hotelGroups || s.toList(),
64
+ type: e.searchType || p.CITY,
65
+ external_inventory: (u == null ? void 0 : u.externalInventory) || !1
66
+ };
67
+ return {
68
+ ...await m.searchByCoords(o),
69
+ checkinDate: e.checkinDate,
70
+ checkoutDate: e.checkoutDate
63
71
  };
64
- return await u.searchByCoords(n);
65
72
  },
66
73
  onSuccess: (e) => {
67
- e.success && o(e.data);
74
+ if (e.success) {
75
+ const { checkinDate: o, checkoutDate: r } = e, n = G(o, r), h = e.data.map((c) => ({
76
+ ...c,
77
+ nthNightFree: x({
78
+ hotel: c,
79
+ cards: y ?? [],
80
+ nights: n
81
+ })
82
+ }));
83
+ t(h);
84
+ }
68
85
  },
69
86
  onSettled: () => {
70
- a.invalidateQueries({ queryKey: [l.SEARCH_LIMIT] });
87
+ f.invalidateQueries({ queryKey: [k.SEARCH_LIMIT] });
71
88
  }
72
- }), {
73
- mutate: k,
74
- status: f,
75
- isError: S,
76
- error: w
77
- } = h({
89
+ });
90
+ function C(e, o) {
91
+ let r = 0;
92
+ const n = e.length < o.length ? e : o, h = e.length >= o.length ? e : o;
93
+ for (let c = 0; c < n.length; c++)
94
+ e[c] === o[c] && r++;
95
+ return r / h.length;
96
+ }
97
+ const {
98
+ mutate: H,
99
+ isPending: I,
100
+ status: v,
101
+ isError: L,
102
+ error: q
103
+ } = d({
78
104
  mutationFn: async (e) => {
79
- C(e), o([]), s({
80
- checkinDate: c(e.checkinDate),
81
- checkoutDate: c(e.checkoutDate),
105
+ N(e), t([]), l({
106
+ checkinDate: a(e.checkinDate),
107
+ checkoutDate: a(e.checkoutDate),
82
108
  guests: e.guests || 2,
83
109
  rooms: e.rooms || 1
84
110
  });
85
- const n = {
111
+ const o = {
86
112
  check_in_date: e.checkinDate,
87
113
  check_out_date: e.checkoutDate,
88
- hotel_id: e.hotelId,
89
- rooms: e.rooms || 1,
90
114
  guests: e.guests || 2,
91
- currency: e.currency || "USD",
115
+ rooms: e.rooms || 1,
92
116
  cash_or_points: e.cashOrPoints || ["cash", "points"],
93
- hotel_group: e.hotelGroup
94
- };
95
- return await u.searchByHotelId(n);
117
+ currency: e.currency || "USD",
118
+ lat: e.coordinates.latitude,
119
+ lon: e.coordinates.longitude,
120
+ search_range: 0.5,
121
+ range_type: "km",
122
+ hotel_groups: [e.hotelGroup],
123
+ type: p.HOTEL,
124
+ external_inventory: !1
125
+ }, r = await m.searchByCoords(o);
126
+ if (!r.success)
127
+ throw new Error(r.message || "Hotel search failed");
128
+ const n = 0.8;
129
+ return r.data.filter(
130
+ (c) => C(c.name.toLowerCase(), e.hotelName.toLowerCase()) >= n
131
+ );
96
132
  },
97
133
  onSuccess: (e) => {
98
- e.success && o(e.data);
134
+ t(e);
99
135
  },
100
136
  onSettled: () => {
101
- a.invalidateQueries({ queryKey: [l.SEARCH_LIMIT] });
137
+ f.invalidateQueries({ queryKey: [k.SEARCH_LIMIT] });
102
138
  }
103
139
  });
104
140
  return {
105
- results: r,
106
- loading: m === "pending" || f === "pending",
107
- isCoordsSearchError: p,
108
- coordsSearchError: y,
109
- isHotelIdSearchError: S,
110
- hotelIdSearchError: w,
111
- searchByCoords: d,
112
- searchByHotelId: k
141
+ results: i,
142
+ loading: S === "pending" || v === "pending" || w || I,
143
+ isCoordsSearchError: _,
144
+ coordsSearchError: E,
145
+ isHotelIdSearchError: L,
146
+ hotelIdSearchError: q,
147
+ searchByCoords: D,
148
+ searchByHotelId: H
113
149
  };
114
150
  };
115
151
  export {
116
- $ as useHotelSearch
152
+ Y as useHotelSearch,
153
+ A as validateSearchByCoordsArgs,
154
+ N as validateSearchByHotelIdArgs
117
155
  };
@@ -2,7 +2,7 @@ import { useQuery as a } from "@tanstack/react-query";
2
2
  import { HotelService as m } from "../../services/hotel/HotelService.js";
3
3
  import "../../moment-BGjjqtLQ.js";
4
4
  import "../../arrayExtensions-CFEBYUok.js";
5
- import { E as u } from "../../enums-BIly_FuI.js";
5
+ import { E as u } from "../../enums-Boat1JS-.js";
6
6
  import { useState as l, useEffect as d } from "react";
7
7
  import { defaultSimilarityThreshold as L, defaultLocationSortOrder as f } from "../../configs/defaults.js";
8
8
  import { sortLocationResults as p } from "../../utilities/hotelUtils/hotelUtils.js";
@@ -0,0 +1 @@
1
+ export declare const IhgFreeNightCards: string[];
@@ -1,4 +1,49 @@
1
1
  import { ISearchByCoordsParams, ISearchByHotelIdParams } from './useHotelSearch.types';
2
+ import { IHotelDetails } from '../../main';
3
+ /**
4
+ * Utility function to validate search-by-coordinates input
5
+ */
6
+ export declare const validateSearchByCoordsArgs: (args: ISearchByCoordsParams) => void;
7
+ /**
8
+ * Utility function to validate search-by-hotel-id input
9
+ */
10
+ export declare const validateSearchByHotelIdArgs: (args: ISearchByHotelIdParams) => void;
11
+ export interface IUseHotelSearch {
12
+ /**
13
+ * The list of hotels returned by the search.
14
+ */
15
+ results: IHotelDetails[];
16
+ /**
17
+ * A boolean indicating if a search is currently in progress.
18
+ */
19
+ loading: boolean;
20
+ /**
21
+ * A boolean indicating if there was an error during the coordinates search.
22
+ */
23
+ isCoordsSearchError: boolean;
24
+ /**
25
+ * The error object for the coordinates search, if any.
26
+ */
27
+ coordsSearchError: Error | null;
28
+ /**
29
+ * A boolean indicating if there was an error during the hotel ID search.
30
+ */
31
+ isHotelIdSearchError: boolean;
32
+ /**
33
+ * The error object for the hotel ID search, if any.
34
+ */
35
+ hotelIdSearchError: Error | null;
36
+ /**
37
+ * A function to initiate a search by coordinates.
38
+ * @param args The parameters for the search.
39
+ */
40
+ searchByCoords: (args: ISearchByCoordsParams) => void;
41
+ /**
42
+ * A function to initiate a search by hotel ID.
43
+ * @param args The parameters for the search.
44
+ */
45
+ searchByHotelId: (args: ISearchByHotelIdParams) => void;
46
+ }
2
47
  /**
3
48
  * Awayz hook to handle hotel search functionality.
4
49
  *
@@ -15,13 +60,4 @@ import { ISearchByCoordsParams, ISearchByHotelIdParams } from './useHotelSearch.
15
60
  * - `searchByCoords`: A function to initiate a search by coordinates.
16
61
  * - `searchByHotelId`: A function to initiate a search by hotel ID.
17
62
  */
18
- export declare const useHotelSearch: () => {
19
- results: import('../../main').IHotelDetails[];
20
- loading: boolean;
21
- isCoordsSearchError: boolean;
22
- coordsSearchError: Error | null;
23
- isHotelIdSearchError: boolean;
24
- hotelIdSearchError: Error | null;
25
- searchByCoords: import('@tanstack/react-query').UseMutateFunction<import('@type-op/shared').TServiceResponse<import('../../main').IHotelDetails[]>, Error, ISearchByCoordsParams, unknown>;
26
- searchByHotelId: import('@tanstack/react-query').UseMutateFunction<import('@type-op/shared').TServiceResponse<import('../../main').IHotelDetails[]>, Error, ISearchByHotelIdParams, unknown>;
27
- };
63
+ export declare const useHotelSearch: () => IUseHotelSearch;
@@ -34,15 +34,21 @@ export interface ISearchByCoordsParams extends ISearchByParams {
34
34
  }
35
35
  export interface ISearchByHotelIdParams extends ISearchByParams {
36
36
  /**
37
- * Required hotel ID
38
- * @type string
37
+ * Required search coordinates
38
+ * @type ICoordinates
39
+ * @example { latitude: 123.456, longitude: 123.456 }
39
40
  */
40
- hotelId: string;
41
+ coordinates: ICoordinates;
41
42
  /**
42
43
  * Required hotel group
43
44
  * @type string
44
45
  */
45
46
  hotelGroup: string;
47
+ /**
48
+ * Required hotel name
49
+ * @type string
50
+ */
51
+ hotelName: string;
46
52
  }
47
53
  interface ISearchByParams {
48
54
  /**
@@ -0,0 +1,34 @@
1
+ import { IHotelDetails } from '../../main.js';
2
+ import { ICard } from '@odynn/awayz-core';
3
+ interface CheckNthNightFreeParams {
4
+ /**
5
+ * Hotel result returned from the backend
6
+ */
7
+ hotel: IHotelDetails;
8
+ /**
9
+ * Cards available for the user
10
+ */
11
+ cards: ICard[];
12
+ /**
13
+ * Number of nights
14
+ */
15
+ nights: number;
16
+ }
17
+ /**
18
+ * Checks if a hotel offers a free night based on the hotel chain and the number of nights booked.
19
+ * - Hilton and Marriott offer a 5th night free when booking 5+ nights.
20
+ * - IHG offers a 4th night free when booking 4+ nights, but only if the user has specific IHG cards.
21
+ * - Other hotel chains do not offer free nights.
22
+ *
23
+ * @param {Object} params - The parameters for checking free night offers
24
+ * @param {Object} params.hotel - The hotel object containing hotel information
25
+ * @param {string} params.hotel.hotelGroup - The hotel chain/group identifier
26
+ * @param {Array<Object>} [params.cards] - The user's cards that may qualify for special offers
27
+ * @param {boolean} params.cards[].activeCard - Whether the card is active
28
+ * @param {string} params.cards[].name - The name of the card
29
+ * @param {number} params.nights - The number of nights being booked
30
+ *
31
+ * @returns {number} The nth night that is free (e.g., 4 for 4th night free, 5 for 5th night free), or 0 if no free night
32
+ */
33
+ export declare const checkNthNightFree: ({ hotel, cards, nights }: CheckNthNightFreeParams) => number;
34
+ export {};
@@ -0,0 +1,24 @@
1
+ import { HotelChains as r } from "../../definitions/HotelChains.js";
2
+ import { IhgFreeNightCards as h } from "../../definitions/IhgFreeNightCards.js";
3
+ const s = ({
4
+ hotel: i,
5
+ cards: e,
6
+ nights: t
7
+ }) => {
8
+ switch (i.hotelGroup) {
9
+ // for Hilton and Marriot, we have a 5th-night free
10
+ case r.Hilton:
11
+ return t >= 5 ? 5 : 0;
12
+ case r.Marriott:
13
+ return t >= 5 ? 5 : 0;
14
+ case r.IHG:
15
+ return t >= 4 && (e != null && e.some(
16
+ (o) => o.activeCard && h.includes(o.name)
17
+ )) ? 4 : 0;
18
+ default:
19
+ return 0;
20
+ }
21
+ };
22
+ export {
23
+ s as checkNthNightFree
24
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@odynn/awayz-hotels",
3
3
  "private": false,
4
- "version": "0.2.21",
4
+ "version": "0.2.23",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"
@@ -9,15 +9,11 @@
9
9
  "main": "dist/main.js",
10
10
  "types": "./dist/lib/main.d.ts",
11
11
  "scripts": {
12
- "test": "vitest",
13
- "dev": "npm run storybook",
12
+ "test": "echo \"NOTE: Please run tests from the root\"",
14
13
  "build": "tsc -b ./tsconfig.lib.json && vite build",
15
- "stoot": "npm publish --access public",
16
- "push": "npm publish --access public",
17
- "lint": "eslint .",
18
- "preview": "vite preview",
19
- "storybook": "storybook dev -p 6006",
20
- "build-storybook": "storybook build"
14
+ "patch": "npm run build && npm version patch && npm publish --access public",
15
+ "minor": "npm run build && npm version minor && npm publish --access public",
16
+ "major": "npm run build && npm version major && npm publish --access public"
21
17
  },
22
18
  "peerDependencies": {
23
19
  "react": "^18.3.1",
@@ -65,7 +61,7 @@
65
61
  ]
66
62
  },
67
63
  "dependencies": {
68
- "@odynn/awayz-core": "^0.2.22",
64
+ "@odynn/awayz-core": "^0.2.28",
69
65
  "@tanstack/react-query": "^5.66.9",
70
66
  "string-comparison": "^1.3.0"
71
67
  }
@@ -1,4 +0,0 @@
1
- var E = /* @__PURE__ */ ((C) => (C.LOCATIONS = "LOCATIONS", C.CHECK_USER = "CHECK_USER", C.USER_REGIONS = "USER_REGIONS", C.CONVERT_CURRENCY = "CONVERT_CURRENCY", C.CLIENT_COMPONENT_KEY = "CLIENT_COMPONENT_KEY", C.SEARCH_LIMIT = "SEARCH_LIMIT", C))(E || {});
2
- export {
3
- E
4
- };