@odynn/awayz-hotels 0.6.14 → 0.6.15

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.
@@ -6,7 +6,7 @@ const o = {
6
6
  [e.LANDMARK]: 4,
7
7
  [e.HOTEL]: 5,
8
8
  [e.AIRPORT]: 6
9
- }, c = 60, l = {
9
+ }, c = 60, i = 15e3, l = {
10
10
  searchId: "duffel_test_hotel_search",
11
11
  searchType: e.HOTEL,
12
12
  description: "Duffel Test Hotel",
@@ -25,5 +25,6 @@ const o = {
25
25
  export {
26
26
  o as defaultLocationSortOrder,
27
27
  c as defaultSimilarityThreshold,
28
- l as duffelTestHotelLocation
28
+ l as duffelTestHotelLocation,
29
+ i as livePointsCheckTimeout
29
30
  };
@@ -1,107 +1,111 @@
1
1
  import { HotelChains as p } from "../../definitions/HotelChains.js";
2
- import { EBestCheckoutType as m } from "../../enums/EBestCheckoutType.js";
2
+ import { EBestCheckoutType as h } from "../../enums/EBestCheckoutType.js";
3
3
  import { BookingService as y } from "../../services/booking/BookingService.js";
4
4
  import { EGuestType as C } from "../../services/booking/BookingService.enums.js";
5
- import { HotelService as h } from "../../services/hotel/HotelService.js";
6
- const w = async (s) => await h.getTransferPartners(
5
+ import { HotelService as f } from "../../services/hotel/HotelService.js";
6
+ const w = async (s) => await f.getTransferPartners(
7
7
  p.toProgram(s)
8
- ), T = async ({
8
+ ), T = (s) => !!s.hotelGroup && !!s.hotelId && !!s.checkinDate && !!s.checkoutDate && !!s.rooms && !!s.guests, A = async ({
9
9
  hotel: s,
10
10
  checkinDate: t,
11
- checkoutDate: n,
12
- updateHotel: e
11
+ checkoutDate: o,
12
+ updateHotel: a,
13
+ signal: e
13
14
  }) => {
14
- let a = s, i = s.rooms ?? [];
15
+ let r = s, c = s.rooms ?? [];
15
16
  if (!s.liveScrapingCheckNeeded || s.hotelGroup === p.Marriott)
16
17
  return {
17
18
  pointsHotelDetails: s,
18
- pointsRooms: i
19
+ pointsRooms: c
19
20
  };
20
- let r = !1, c = null;
21
+ let u = !1, i = null;
21
22
  try {
22
- const o = await h.hotelPointsCheck({
23
- hotelGroup: s.hotelGroup,
24
- hotelId: s.hotelId,
25
- checkinDate: t,
26
- checkoutDate: n
27
- });
28
- r = o.success, c = o.data;
23
+ const n = await f.hotelPointsCheck(
24
+ {
25
+ hotelGroup: s.hotelGroup,
26
+ hotelId: s.hotelId,
27
+ checkinDate: t,
28
+ checkoutDate: o
29
+ },
30
+ e
31
+ );
32
+ u = n.success, i = n.data;
29
33
  } catch {
30
- r = !1, c = null;
34
+ u = !1, i = null;
31
35
  }
32
- if (r) {
33
- const o = c, u = !(o.points.pointsValue > 0) && s.bestValue === m.POINTS;
34
- a = {
36
+ if (u) {
37
+ const n = i, m = !(n.points.pointsValue > 0) && s.bestValue === h.POINTS;
38
+ r = {
35
39
  ...s,
36
- awardPoints: o.points.awardPointsValue ?? o.points.pointsValue,
37
- points: o.points.pointsValue,
38
- pointsType: o.points.pointsType,
39
- bestValue: u ? m.NONE : s.bestValue
40
- }, i = o.rooms ?? s.rooms ?? [], e(s.hotelId, s.hotelGroup, a);
40
+ awardPoints: n.points.awardPointsValue ?? n.points.pointsValue,
41
+ points: n.points.pointsValue,
42
+ pointsType: n.points.pointsType,
43
+ bestValue: m ? h.NONE : s.bestValue
44
+ }, c = n.rooms ?? s.rooms ?? [], a(s.hotelId, s.hotelGroup, r);
41
45
  }
42
46
  return {
43
- pointsHotelDetails: a,
44
- pointsRooms: i
47
+ pointsHotelDetails: r,
48
+ pointsRooms: c
45
49
  };
46
- }, A = async ({
50
+ }, B = async ({
47
51
  hotel: s,
48
52
  checkinDate: t,
49
- checkoutDate: n,
50
- guests: e,
51
- rooms: a,
52
- updateHotel: i,
53
- numberOfNights: r
53
+ checkoutDate: o,
54
+ guests: a,
55
+ rooms: e,
56
+ updateHotel: r,
57
+ numberOfNights: c
54
58
  }) => {
55
- var u;
56
- if (!((u = s == null ? void 0 : s.cashBookingOffers) != null && u.accommodationId))
59
+ var l;
60
+ if (!((l = s == null ? void 0 : s.cashBookingOffers) != null && l.accommodationId))
57
61
  return {
58
62
  cashHotelDetails: s,
59
63
  cashRooms: []
60
64
  };
61
- const c = (f) => Array.from({ length: f }, () => ({ type: C.ADULT })), o = await y.getAvailableRooms({
65
+ const u = (m) => Array.from({ length: m }, () => ({ type: C.ADULT })), i = await y.getAvailableRooms({
62
66
  checkinDate: t,
63
- checkoutDate: n,
67
+ checkoutDate: o,
64
68
  accommodationId: s.cashBookingOffers.accommodationId,
65
- guests: c(e),
66
- rooms: a
67
- }), l = {
69
+ guests: u(a),
70
+ rooms: e
71
+ }), n = {
68
72
  ...s,
69
73
  cashValue: {
70
74
  ...s.cashValue,
71
- amount: o.cheapestRate / r || s.cashValue.amount || 0,
72
- currency: o.currency ?? s.cashValue.currency
75
+ amount: i.cheapestRate / c || s.cashValue.amount || 0,
76
+ currency: i.currency ?? s.cashValue.currency
73
77
  }
74
78
  };
75
- return i(s.hotelId, s.hotelGroup, l), {
76
- cashHotelDetails: l,
77
- cashRooms: o.availableRooms
79
+ return r(s.hotelId, s.hotelGroup, n), {
80
+ cashHotelDetails: n,
81
+ cashRooms: i.availableRooms
78
82
  };
79
- }, B = async (s, t, n) => {
80
- const { success: e, data: a } = await h.getRecommendations({
83
+ }, G = async (s, t, o) => {
84
+ const { success: a, data: e } = await f.getRecommendations({
81
85
  days: t,
82
86
  hotel: s
83
87
  });
84
- return e && a ? {
88
+ return a && e ? {
85
89
  bestCheckout: {
86
- ...a,
87
- nightlyPointsCost: n ? a.awardPoints : a.nightlyPointsCost
90
+ ...e,
91
+ nightlyPointsCost: o ? e.awardPoints : e.nightlyPointsCost
88
92
  },
89
- isAvailable: a.nightlyPointsCost > 0 || a.nightlyCashCost > 0
93
+ isAvailable: e.nightlyPointsCost > 0 || e.nightlyCashCost > 0
90
94
  } : {
91
95
  bestCheckout: d(s, t),
92
96
  isAvailable: !1
93
97
  };
94
98
  }, d = (s, t) => {
95
- var i, r, c, o;
96
- const n = ((i = s.cashBookingOffers) == null ? void 0 : i.cheapestRateTotalAmount) ?? ((r = s.cashValue) == null ? void 0 : r.amount) ?? 0, e = ((c = s.cashBookingOffers) == null ? void 0 : c.cheapestRateCurrency) ?? ((o = s.cashValue) == null ? void 0 : o.currency) ?? "USD";
99
+ var r, c, u, i;
100
+ const o = ((r = s.cashBookingOffers) == null ? void 0 : r.cheapestRateTotalAmount) ?? ((c = s.cashValue) == null ? void 0 : c.amount) ?? 0, a = ((u = s.cashBookingOffers) == null ? void 0 : u.cheapestRateCurrency) ?? ((i = s.cashValue) == null ? void 0 : i.currency) ?? "USD";
97
101
  return {
98
- bestCheckoutMethod: p.isHotelChain(s.hotelGroup) ? s.bestValue : m.CASH,
99
- nightlyCashCost: n,
102
+ bestCheckoutMethod: p.isHotelChain(s.hotelGroup) ? s.bestValue : h.CASH,
103
+ nightlyCashCost: o,
100
104
  nightlyPointsCost: s.points || 0,
101
105
  awardPoints: s.points || 0,
102
- totalCashCost: n * t,
106
+ totalCashCost: o * t,
103
107
  totalPointsCost: (s.points || 0) * t,
104
- currency: e,
108
+ currency: a,
105
109
  sufficientPoints: !0,
106
110
  rewardsProgram: p.toProgram(s.hotelGroup),
107
111
  optimalProgram: {
@@ -110,25 +114,26 @@ const w = async (s) => await h.getTransferPartners(
110
114
  totalProgramPointsValuation: 0
111
115
  }
112
116
  };
113
- }, G = (s, t, n) => {
114
- let e = s;
115
- return t && (e = {
117
+ }, I = (s, t, o) => {
118
+ let a = s;
119
+ return t && (a = {
116
120
  ...s,
117
121
  points: t.points,
118
122
  awardPoints: t.awardPoints,
119
123
  pointsType: t.pointsType,
120
124
  bestValue: t.bestValue
121
- }), n && (e = {
122
- ...e,
123
- cashValue: n.cashValue,
124
- rooms: n.rooms
125
- }), e;
125
+ }), o && (a = {
126
+ ...a,
127
+ cashValue: o.cashValue,
128
+ rooms: o.rooms
129
+ }), a;
126
130
  };
127
131
  export {
128
- G as combineUpdatedHotelData,
132
+ I as combineUpdatedHotelData,
129
133
  d as fallbackBestCheckout,
130
- A as fetchAvailableRooms,
131
- B as fetchBestCheckout,
132
- T as fetchPointsCheck,
133
- w as fetchTransferPartners
134
+ B as fetchAvailableRooms,
135
+ G as fetchBestCheckout,
136
+ A as fetchPointsCheck,
137
+ w as fetchTransferPartners,
138
+ T as isPartialHotelDetails
134
139
  };
@@ -1,159 +1,204 @@
1
- import { g as _ } from "../../dateUtils-C1hKW8MF.js";
1
+ import { g as oe } from "../../dateUtils-C1hKW8MF.js";
2
+ import { E as N } from "../../DateFormats-DZD30Nea.js";
2
3
  import "../../arrayExtensions-CFEBYUok.js";
3
- import { useState as j, useMemo as h } from "react";
4
- import z from "../../stores/useHotelsStore.js";
5
- import { fetchTransferPartners as J, fetchPointsCheck as V, fetchAvailableRooms as X, combineUpdatedHotelData as A, fallbackBestCheckout as Y, fetchBestCheckout as Z } from "./useHotelDetails.api.js";
6
- import { useWallet as $ } from "@odynn/awayz-core";
7
- import { useQuery as a } from "@tanstack/react-query";
8
- import { h as I } from "../../moment-BGjjqtLQ.js";
9
- import { HotelChains as ee } from "../../definitions/HotelChains.js";
10
- import { IhgFreeNightCards as te } from "../../definitions/IhgFreeNightCards.js";
11
- import { calculatePointsAsCash as oe } from "../../utilities/pointsAsCashUtils.js";
12
- const ke = (t) => {
13
- var d, g, y, C, b, v, F, H, R, q, O;
14
- if (!t)
4
+ import { useState as ce, useMemo as D } from "react";
5
+ import ae from "../../stores/useHotelsStore.js";
6
+ import { isPartialHotelDetails as se, fetchTransferPartners as ie, fetchPointsCheck as re, fetchAvailableRooms as ne, combineUpdatedHotelData as T, fallbackBestCheckout as le, fetchBestCheckout as he } from "./useHotelDetails.api.js";
7
+ import { useAwayzContext as ue, useWallet as De } from "@odynn/awayz-core";
8
+ import { useQuery as r } from "@tanstack/react-query";
9
+ import { h as n } from "../../moment-BGjjqtLQ.js";
10
+ import { livePointsCheckTimeout as fe } from "../../configs/defaults.js";
11
+ import { HotelChains as me } from "../../definitions/HotelChains.js";
12
+ import { IhgFreeNightCards as ke } from "../../definitions/IhgFreeNightCards.js";
13
+ import { HotelService as de } from "../../services/hotel/HotelService.js";
14
+ import { calculatePointsAsCash as pe } from "../../utilities/pointsAsCashUtils.js";
15
+ const ge = "USD", we = (c) => {
16
+ var b, H, R, O, q, A, S, G, _, B, w, K, P, E;
17
+ if (!c)
15
18
  throw new Error(
16
19
  "Hotel is required in order to initiate the hotel details flow"
17
20
  );
18
- const { updateHotel: l, searchParams: o } = z(), [e, G] = j({
19
- checkinDate: o == null ? void 0 : o.checkinDate,
20
- checkoutDate: o == null ? void 0 : o.checkoutDate
21
- }), c = h(() => _(e.checkinDate, e.checkoutDate), [e]), B = (r, u) => {
22
- G({
23
- checkinDate: I(r),
24
- checkoutDate: I(u)
21
+ const { user: f } = ue(), { updateHotel: p, searchParams: o } = ae(), s = se(c), [e, U] = ce({
22
+ checkinDate: s ? n(c.checkinDate) : o == null ? void 0 : o.checkinDate,
23
+ checkoutDate: s ? n(c.checkoutDate) : o == null ? void 0 : o.checkoutDate
24
+ }), {
25
+ data: i,
26
+ isFetching: W,
27
+ isFetched: m
28
+ } = r({
29
+ queryKey: [
30
+ "hotelDetails",
31
+ c.hotelId,
32
+ c.hotelGroup,
33
+ (b = e == null ? void 0 : e.checkinDate) == null ? void 0 : b.valueOf(),
34
+ (H = e == null ? void 0 : e.checkoutDate) == null ? void 0 : H.valueOf()
35
+ ],
36
+ queryFn: () => {
37
+ var a;
38
+ return de.searchByHotelId({
39
+ hotel_group: c.hotelGroup,
40
+ hotel_id: c.hotelId,
41
+ check_in_date: n(e.checkinDate).format(
42
+ N.ServerDate
43
+ ),
44
+ check_out_date: n(e.checkoutDate).format(
45
+ N.ServerDate
46
+ ),
47
+ guests: c.guests,
48
+ rooms: c.rooms,
49
+ currency: ((a = f == null ? void 0 : f.userRegion) == null ? void 0 : a.currency) || ge,
50
+ cash_or_points: ["cash", "points"]
51
+ });
52
+ },
53
+ enabled: s && !!e.checkinDate && !!e.checkoutDate,
54
+ retry: !1
55
+ }), t = D(() => {
56
+ var a;
57
+ return s ? i != null && i.success && ((a = i.data) != null && a[0]) ? i.data[0] : {} : c;
58
+ }, [s, i, c]), h = D(() => oe(e.checkinDate, e.checkoutDate), [e]), x = (a, l) => {
59
+ U({
60
+ checkinDate: n(a),
61
+ checkoutDate: n(l)
25
62
  });
26
- }, { userCards: s } = $(), f = h(() => (t == null ? void 0 : t.hotelGroup) === ee.IHG ? te.some(
27
- (r) => s == null ? void 0 : s.some((u) => u.name === r)
28
- ) : !0, [s]), { data: w, isFetching: K } = a({
63
+ }, { userCards: u } = De(), g = D(() => (t == null ? void 0 : t.hotelGroup) === me.IHG ? ke.some(
64
+ (a) => u == null ? void 0 : u.some((l) => l.name === a)
65
+ ) : !0, [u]), { data: L, isFetching: z } = r({
29
66
  queryKey: ["transferPartners", t.hotelGroup],
30
- queryFn: () => J(t.hotelGroup),
67
+ queryFn: () => ie(t.hotelGroup),
31
68
  enabled: !!t.hotelGroup,
32
69
  placeholderData: []
33
70
  }), {
34
- data: S,
35
- isFetching: D,
36
- isFetched: N
37
- } = a({
71
+ data: I,
72
+ isFetching: y,
73
+ isFetched: M
74
+ } = r({
38
75
  queryKey: [
39
76
  "hotelPointsCheck",
40
77
  t.hotelId,
41
78
  t.hotelGroup,
42
- (d = e == null ? void 0 : e.checkinDate) == null ? void 0 : d.valueOf(),
43
- (g = e == null ? void 0 : e.checkoutDate) == null ? void 0 : g.valueOf()
79
+ (R = e == null ? void 0 : e.checkinDate) == null ? void 0 : R.valueOf(),
80
+ (O = e == null ? void 0 : e.checkoutDate) == null ? void 0 : O.valueOf()
44
81
  ],
45
- queryFn: () => V({
46
- hotel: t,
47
- checkinDate: e.checkinDate,
48
- checkoutDate: e.checkoutDate,
49
- updateHotel: l
50
- }),
51
- enabled: !!e.checkinDate && !!e.checkoutDate && !!t.liveScrapingCheckNeeded,
82
+ queryFn: ({ signal: a }) => {
83
+ const l = AbortSignal.timeout(fe), te = AbortSignal.any([a, l]);
84
+ return re({
85
+ hotel: t,
86
+ checkinDate: e.checkinDate,
87
+ checkoutDate: e.checkoutDate,
88
+ updateHotel: p,
89
+ signal: te
90
+ });
91
+ },
92
+ enabled: !!e.checkinDate && !!e.checkoutDate && !!t.liveScrapingCheckNeeded && (!s || m),
52
93
  // We don't throw an error on fail so we can gracefully handle fallback
53
94
  retry: !1,
95
+ refetchOnWindowFocus: !1,
96
+ // stop refetching on tab focus
54
97
  placeholderData: {
55
98
  pointsHotelDetails: t,
56
99
  pointsRooms: t.rooms ?? []
57
100
  }
58
- }), { pointsRooms: P, pointsHotelDetails: i } = S || {
101
+ }), { pointsRooms: Q, pointsHotelDetails: k } = I || {
59
102
  pointsHotelDetails: t,
60
103
  pointsRooms: []
61
104
  }, {
62
- data: T,
63
- isFetching: k,
64
- isFetched: W
65
- } = a({
105
+ data: Y,
106
+ isFetching: v,
107
+ isFetched: j
108
+ } = r({
66
109
  queryKey: [
67
110
  "fetchAvailableRooms",
68
- (y = t.cashBookingOffers) == null ? void 0 : y.accommodationId,
69
- (C = e == null ? void 0 : e.checkinDate) == null ? void 0 : C.valueOf(),
70
- (b = e == null ? void 0 : e.checkoutDate) == null ? void 0 : b.valueOf(),
111
+ (q = t.cashBookingOffers) == null ? void 0 : q.accommodationId,
112
+ (A = e == null ? void 0 : e.checkinDate) == null ? void 0 : A.valueOf(),
113
+ (S = e == null ? void 0 : e.checkoutDate) == null ? void 0 : S.valueOf(),
71
114
  o == null ? void 0 : o.guests,
72
115
  o == null ? void 0 : o.rooms
73
116
  ],
74
- queryFn: () => X({
117
+ queryFn: () => ne({
75
118
  hotel: t,
76
119
  checkinDate: e.checkinDate,
77
120
  checkoutDate: e.checkoutDate,
78
121
  guests: o.guests,
79
122
  rooms: o.rooms,
80
- updateHotel: l,
81
- numberOfNights: c
123
+ updateHotel: p,
124
+ numberOfNights: h
82
125
  }),
83
- enabled: !!e.checkinDate && !!e.checkoutDate && !!((v = t.cashBookingOffers) != null && v.accommodationId),
126
+ enabled: !!e.checkinDate && !!e.checkoutDate && !!((G = t.cashBookingOffers) != null && G.accommodationId) && (!s || m),
84
127
  retry: !1,
85
128
  placeholderData: {
86
129
  cashHotelDetails: t,
87
130
  cashRooms: []
88
131
  }
89
- }), { cashRooms: x, cashHotelDetails: n } = T || {
132
+ }), { cashRooms: J, cashHotelDetails: d } = Y || {
90
133
  cashHotelDetails: t,
91
134
  cashRooms: []
92
- }, E = h(
93
- () => A(t, i, n),
94
- [t, i, n]
135
+ }, V = D(
136
+ () => T(t, k, d),
137
+ [t, k, d]
95
138
  ), {
96
- data: L,
97
- isFetching: M,
98
- isFetched: Q
99
- } = a({
139
+ data: X,
140
+ isFetching: Z,
141
+ isFetched: $
142
+ } = r({
100
143
  queryKey: [
101
144
  "bestCheckout",
102
145
  t.hotelId,
103
146
  t.hotelGroup,
104
- (F = e == null ? void 0 : e.checkinDate) == null ? void 0 : F.valueOf(),
105
- (H = e == null ? void 0 : e.checkoutDate) == null ? void 0 : H.valueOf(),
106
- f
147
+ (_ = e == null ? void 0 : e.checkinDate) == null ? void 0 : _.valueOf(),
148
+ (B = e == null ? void 0 : e.checkoutDate) == null ? void 0 : B.valueOf(),
149
+ g
107
150
  ],
108
- queryFn: () => Z(
109
- E,
110
- c,
111
- f
151
+ queryFn: () => he(
152
+ V,
153
+ h,
154
+ g
112
155
  ),
113
- enabled: !t.hotelId.startsWith("duff_") && !D && (t.liveScrapingCheckNeeded ? N : !0) && !k && ((R = t.cashBookingOffers) != null && R.accommodationId ? W : !0) && c > 0 && t.points >= 0,
156
+ enabled: !((w = t.hotelId) != null && w.startsWith("duff_")) && !y && (t.liveScrapingCheckNeeded ? M : !0) && !v && ((K = t.cashBookingOffers) != null && K.accommodationId ? j : !0) && h > 0 && t.points >= 0 && (!s || m),
114
157
  retry: !1,
115
158
  placeholderData: {
116
- bestCheckout: Y(t, c),
159
+ bestCheckout: le(t, h),
117
160
  isAvailable: !1
118
161
  }
119
- }), { bestCheckout: m, isAvailable: p } = L || {
162
+ }), { bestCheckout: C, isAvailable: F } = X || {
120
163
  isAvailable: !1
121
- }, { data: U } = a({
164
+ }, { data: ee } = r({
122
165
  queryKey: [
123
166
  "pointsAsCash",
124
167
  t.hotelId,
125
168
  t.hotelGroup,
126
- (q = e == null ? void 0 : e.checkinDate) == null ? void 0 : q.valueOf(),
127
- (O = e == null ? void 0 : e.checkoutDate) == null ? void 0 : O.valueOf()
169
+ (P = e == null ? void 0 : e.checkinDate) == null ? void 0 : P.valueOf(),
170
+ (E = e == null ? void 0 : e.checkoutDate) == null ? void 0 : E.valueOf()
128
171
  ],
129
- queryFn: () => oe(m.totalCashCost),
130
- enabled: Q && p,
172
+ queryFn: () => pe(C.totalCashCost),
173
+ enabled: $ && F,
131
174
  retry: !1
132
175
  });
133
176
  return {
134
- transferPartners: w || [],
135
- loadingTransferPartners: K,
177
+ transferPartners: L || [],
178
+ loadingTransferPartners: z,
179
+ // Hotel Details
180
+ loadingHotelDetails: W,
136
181
  // Points Check
137
- pointsRooms: P || [],
138
- loadingLivePointsCheck: D,
182
+ pointsRooms: Q || [],
183
+ loadingLivePointsCheck: y,
139
184
  // Cash Rooms
140
- cashRooms: x || [],
141
- loadingCashRooms: k,
185
+ cashRooms: J || [],
186
+ loadingCashRooms: v,
142
187
  // Best Checkout
143
- bestCheckout: m,
144
- loadingBestCheckout: M,
188
+ bestCheckout: C,
189
+ loadingBestCheckout: Z,
145
190
  // Combined availability
146
- isAvailable: p,
191
+ isAvailable: F,
147
192
  // Points as Cash
148
- pointsAsCash: U,
149
- hotelDetails: A(
193
+ pointsAsCash: ee,
194
+ hotelDetails: T(
150
195
  t,
151
- i,
152
- n
196
+ k,
197
+ d
153
198
  ),
154
- updateDates: B
199
+ updateDates: x
155
200
  };
156
201
  };
157
202
  export {
158
- ke as useHotelDetails
203
+ we as useHotelDetails
159
204
  };
@@ -8,6 +8,7 @@ export declare const defaultLocationSortOrder: {
8
8
  readonly "Airport Search": 6;
9
9
  };
10
10
  export declare const defaultSimilarityThreshold = 60;
11
+ export declare const livePointsCheckTimeout = 15000;
11
12
  export declare const duffelTestHotelLocation: {
12
13
  searchId: string;
13
14
  searchType: ESearchType;
@@ -14,6 +14,27 @@ interface IHotelPointsCheckParams {
14
14
  checkoutDate: Moment;
15
15
  updateHotel: (hotelId: string, hotelGroup: string, updated: IHotelDetails) => void;
16
16
  }
17
+ export interface IPartialHotelDetails {
18
+ hotelId: string;
19
+ hotelGroup: string;
20
+ checkinDate: Date;
21
+ checkoutDate: Date;
22
+ rooms: number;
23
+ guests: number;
24
+ }
25
+ /**
26
+ * Type guard to determine if a hotel object is of type IPartialHotelDetails.
27
+ *
28
+ * Checks for the existence of required properties in a partial hotel details object:
29
+ * - hotelGroup
30
+ * - hotelId
31
+ * - checkinDate
32
+ * - checkoutDate
33
+ *
34
+ * @param hotel - The hotel object to check, can be either IHotelDetails or IPartialHotelDetails
35
+ * @returns {boolean} True if the object is an IPartialHotelDetails
36
+ */
37
+ export declare const isPartialHotelDetails: (hotel: IHotelDetails | IPartialHotelDetails) => hotel is IPartialHotelDetails;
17
38
  /**
18
39
  * Fetches the points check for a given hotel and updates the hotel details accordingly.
19
40
  *
@@ -29,7 +50,9 @@ interface IHotelPointsCheckParams {
29
50
  * - If points are available, the hotel details are updated with the points information.
30
51
  * - If points are not available and the best value was points, the best value is updated to none.
31
52
  */
32
- export declare const fetchPointsCheck: ({ hotel, checkinDate, checkoutDate, updateHotel }: IHotelPointsCheckParams) => Promise<IPointsCheckResult>;
53
+ export declare const fetchPointsCheck: ({ hotel, checkinDate, checkoutDate, updateHotel, signal }: IHotelPointsCheckParams & {
54
+ signal?: AbortSignal;
55
+ }) => Promise<IPointsCheckResult>;
33
56
  interface IRoomsResult {
34
57
  cashHotelDetails: IHotelDetails;
35
58
  cashRooms: IRoom[];
@@ -1,7 +1,9 @@
1
+ import { IPartialHotelDetails } from './useHotelDetails.api';
1
2
  import { IHotelDetails } from '../../components/HotelResult/HotelResult.types';
2
- export declare const useHotelDetails: (hotel: IHotelDetails) => {
3
+ export declare const useHotelDetails: (hotelInput: IHotelDetails | IPartialHotelDetails) => {
3
4
  transferPartners: import('./useHotelDetails.types').ITransferPartner[];
4
5
  loadingTransferPartners: boolean;
6
+ loadingHotelDetails: boolean;
5
7
  pointsRooms: import('../../main').IRoom[];
6
8
  loadingLivePointsCheck: boolean;
7
9
  cashRooms: import('../../main').IRoom[];
@@ -7,7 +7,7 @@ declare class _HotelService {
7
7
  searchByCoords: (request: ISearchHotelsParams) => Promise<TServiceResponse<IHotelDetails[]>>;
8
8
  searchByHotelId: (request: ISearchByHotelIdRequest) => Promise<TServiceResponse<IHotelDetails[]>>;
9
9
  getTransferPartners: (program: string) => Promise<ITransferPartner[]>;
10
- hotelPointsCheck: (args: IHotelPointsCheckArgs) => Promise<{
10
+ hotelPointsCheck: (args: IHotelPointsCheckArgs, signal?: AbortSignal) => Promise<{
11
11
  success: any;
12
12
  data: ILiveHotelCheck | null;
13
13
  message?: undefined;
@@ -1,26 +1,26 @@
1
- var y = Object.defineProperty;
2
- var E = (n, a, s) => a in n ? y(n, a, { enumerable: !0, configurable: !0, writable: !0, value: s }) : n[a] = s;
3
- var c = (n, a, s) => E(n, typeof a != "symbol" ? a + "" : a, s);
4
- import { clientInstance as u } from "@odynn/awayz-core";
5
- import { s as C } from "../../stringUtils-DFhHh7H1.js";
1
+ var f = Object.defineProperty;
2
+ var E = (i, a, s) => a in i ? f(i, a, { enumerable: !0, configurable: !0, writable: !0, value: s }) : i[a] = s;
3
+ var n = (i, a, s) => E(i, typeof a != "symbol" ? a + "" : a, s);
4
+ import { clientInstance as _, clientNoRetryInstance as C } from "@odynn/awayz-core";
5
+ import { s as T } from "../../stringUtils-DFhHh7H1.js";
6
6
  import "../../moment-BGjjqtLQ.js";
7
7
  import "../../arrayExtensions-CFEBYUok.js";
8
- import { c as _ } from "../../objectUtils-DOsrxUF7.js";
8
+ import { c as m } from "../../objectUtils-DOsrxUF7.js";
9
9
  import { E as h } from "../../DateFormats-DZD30Nea.js";
10
10
  import "react";
11
11
  import { EHotelEndpoints as l } from "../../configs/endpoints.js";
12
12
  import { EBestCheckoutType as p } from "../../enums/EBestCheckoutType.js";
13
- import { EBestValueType as T } from "../../enums/EBestValueType.js";
14
- import { ESearchType as P } from "./HotelService.types.js";
15
- class S {
13
+ import { EBestValueType as P } from "../../enums/EBestValueType.js";
14
+ import { ESearchType as S } from "./HotelService.types.js";
15
+ class v {
16
16
  constructor() {
17
- c(this, "getLocations", async (a) => {
17
+ n(this, "getLocations", async (a) => {
18
18
  try {
19
- const { data: s } = await u.get(
19
+ const { data: s } = await _.get(
20
20
  l.GET_LOCATIONS,
21
21
  {
22
22
  params: {
23
- search: C(a)
23
+ search: T(a)
24
24
  }
25
25
  }
26
26
  );
@@ -29,22 +29,22 @@ class S {
29
29
  success: !1,
30
30
  message: (s == null ? void 0 : s.message) || "Error fetching location data"
31
31
  };
32
- const o = (e) => e.search_type === P.HOTEL;
32
+ const o = (e) => e.search_type === S.HOTEL;
33
33
  return {
34
34
  success: !0,
35
35
  data: s.data.cities.map(
36
36
  (e) => {
37
- const { search_id: m, search_type: r, description: d, coordinates: g, city: f } = e, i = {
38
- searchId: m,
37
+ const { search_id: c, search_type: r, description: d, coordinates: g, city: y } = e, u = {
38
+ searchId: c,
39
39
  searchType: r,
40
40
  description: d,
41
41
  coordinates: g,
42
- city: f
42
+ city: y
43
43
  };
44
- return o(e) ? (i.country = {
44
+ return o(e) ? (u.country = {
45
45
  code: e.country_code,
46
46
  name: e.country
47
- }, i.hotelChain = e.hotel_group, i.hotelName = e.hotel_name) : (i.country = e.country, i.state = e.state), i;
47
+ }, u.hotelChain = e.hotel_group, u.hotelName = e.hotel_name) : (u.country = e.country, u.state = e.state), u;
48
48
  }
49
49
  )
50
50
  };
@@ -57,16 +57,16 @@ class S {
57
57
  };
58
58
  }
59
59
  });
60
- c(this, "searchByCoords", async (a) => {
60
+ n(this, "searchByCoords", async (a) => {
61
61
  var s, o;
62
62
  try {
63
- const { data: t } = await u.post(l.SEARCH_HOTELS, {
63
+ const { data: t } = await _.post(l.SEARCH_HOTELS, {
64
64
  ...a,
65
65
  use_duffel: !0
66
66
  });
67
67
  return t != null && t.success ? {
68
68
  success: !0,
69
- data: _(
69
+ data: m(
70
70
  (s = t.data) == null ? void 0 : s.hotels
71
71
  )
72
72
  } : {
@@ -80,16 +80,16 @@ class S {
80
80
  };
81
81
  }
82
82
  });
83
- c(this, "searchByHotelId", async (a) => {
83
+ n(this, "searchByHotelId", async (a) => {
84
84
  var s, o;
85
85
  try {
86
- const { data: t } = await u.post(l.GET_HOTEL_DATA, {
86
+ const { data: t } = await _.post(l.GET_HOTEL_DATA, {
87
87
  ...a,
88
88
  use_duffel: !0
89
89
  });
90
90
  return t != null && t.success ? {
91
91
  success: !0,
92
- data: _(
92
+ data: m(
93
93
  (s = t.data) == null ? void 0 : s.hotels
94
94
  )
95
95
  } : {
@@ -103,9 +103,9 @@ class S {
103
103
  };
104
104
  }
105
105
  });
106
- c(this, "getTransferPartners", async (a) => {
106
+ n(this, "getTransferPartners", async (a) => {
107
107
  try {
108
- const { data: s } = await u.get(
108
+ const { data: s } = await _.get(
109
109
  l.GET_TRANSFER_PARTNERS,
110
110
  {
111
111
  params: {
@@ -113,38 +113,39 @@ class S {
113
113
  }
114
114
  }
115
115
  );
116
- return _(s.data);
116
+ return m(s.data);
117
117
  } catch {
118
118
  return [];
119
119
  }
120
120
  });
121
- c(this, "hotelPointsCheck", async (a) => {
122
- var o;
123
- const s = {
121
+ n(this, "hotelPointsCheck", async (a, s) => {
122
+ var t;
123
+ const o = {
124
124
  hotel_group: a.hotelGroup,
125
125
  hotel_id: a.hotelId,
126
126
  check_in_date: a.checkinDate.format(h.ServerDate),
127
127
  check_out_date: a.checkoutDate.format(h.ServerDate)
128
128
  };
129
129
  try {
130
- const { data: t } = await u.post(
130
+ const { data: e } = await C.post(
131
131
  l.HOTEL_POINTS_CHECK,
132
- s
133
- ), e = ((o = t.data) == null ? void 0 : o.length) > 0 ? t.data[0] : null;
132
+ o,
133
+ { signal: s }
134
+ ), c = ((t = e.data) == null ? void 0 : t.length) > 0 ? e.data[0] : null;
134
135
  return {
135
- success: t.success,
136
- data: e == null ? null : _(e)
136
+ success: e.success,
137
+ data: c == null ? null : m(c)
137
138
  };
138
- } catch (t) {
139
- const e = t;
139
+ } catch (e) {
140
+ const c = e;
140
141
  return {
141
142
  success: !1,
142
143
  data: null,
143
- message: (e == null ? void 0 : e.message) ?? "Error fetching hotel data"
144
+ message: (c == null ? void 0 : c.message) ?? "Error fetching hotel data"
144
145
  };
145
146
  }
146
147
  });
147
- c(this, "getRecommendations", async ({
148
+ n(this, "getRecommendations", async ({
148
149
  hotel: a,
149
150
  days: s
150
151
  }) => {
@@ -161,7 +162,7 @@ class S {
161
162
  ],
162
163
  days: s,
163
164
  cash_or_points: ["cash", "points"]
164
- }, { data: t } = await u.post(
165
+ }, { data: t } = await _.post(
165
166
  l.GET_BEST_CHECKOUT,
166
167
  o
167
168
  ), e = t.data[0];
@@ -177,7 +178,7 @@ class S {
177
178
  awardPoints: e.award_points,
178
179
  rewardsProgram: e.hotel_rewards_program,
179
180
  valueCents: e.value_cents,
180
- bestCheckoutMethod: e.best_user_checkout_method === T.CASH ? p.CASH : p.POINTS,
181
+ bestCheckoutMethod: e.best_user_checkout_method === P.CASH ? p.CASH : p.POINTS,
181
182
  optimalProgram: {
182
183
  totalProgramPointsValuation: e.optimal_user_program_checkout.total_program_points_valuation,
183
184
  remainingPointsBalance: e.optimal_user_program_checkout.primary_offer_remaining_points_balance,
@@ -206,7 +207,7 @@ class S {
206
207
  });
207
208
  }
208
209
  }
209
- const L = new S();
210
+ const b = new v();
210
211
  export {
211
- L as HotelService
212
+ b as HotelService
212
213
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@odynn/awayz-hotels",
3
3
  "private": false,
4
- "version": "0.6.14",
4
+ "version": "0.6.15",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"