@odynn/awayz-hotels 0.1.15 → 0.1.17

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.
@@ -1,9 +1,9 @@
1
- import { HotelService as h } from "../../services/hotel/HotelService.js";
2
- import { BookingService as d } from "../../services/booking/BookingService.js";
1
+ import { HotelService as m } from "../../services/hotel/HotelService.js";
2
+ import { BookingService as h } from "../../services/booking/BookingService.js";
3
3
  import { HotelChains as p } from "../../definitions/HotelChains.js";
4
- import { EBestCheckoutType as m } from "../../enums/EBestCheckoutType.js";
4
+ import { EBestCheckoutType as l } from "../../enums/EBestCheckoutType.js";
5
5
  import { EGuestType as y } from "../../services/booking/BookingService.enums.js";
6
- const w = async (o) => await h.getTransferPartners(
6
+ const w = async (o) => await m.getTransferPartners(
7
7
  p.toProgram(o)
8
8
  ), T = async ({
9
9
  hotel: o,
@@ -11,69 +11,67 @@ const w = async (o) => await h.getTransferPartners(
11
11
  checkoutDate: a,
12
12
  updateHotel: t
13
13
  }) => {
14
- let e = !1, i = o, r = o.rooms ?? [];
14
+ let n = o, i = o.rooms ?? [];
15
15
  if (!o.liveScrapingCheckNeeded || o.hotelGroup === p.Marriott)
16
16
  return {
17
17
  pointsHotelDetails: o,
18
- pointsRooms: r,
19
- shouldFallbackBestCheckout: e
18
+ pointsRooms: i
20
19
  };
21
- const u = await h.hotelPointsCheck({
20
+ const r = await m.hotelPointsCheck({
22
21
  hotelGroup: o.hotelGroup,
23
22
  hotelId: o.hotelId,
24
23
  checkinDate: s,
25
24
  checkoutDate: a
26
25
  });
27
- if (u.success) {
28
- const n = u.data[0], c = !(n.points.pointsValue > 0) && o.bestValue === m.POINTS;
29
- i = {
26
+ if (r.success) {
27
+ const e = r.data[0], u = !(e.points.pointsValue > 0) && o.bestValue === l.POINTS;
28
+ n = {
30
29
  ...o,
31
- awardPoints: n.points.awardPointsValue ?? n.points.pointsValue,
32
- points: n.points.pointsValue,
33
- pointsType: n.points.pointsType,
34
- bestValue: c ? m.NONE : o.bestValue
35
- }, r = n.rooms ?? o.rooms ?? [], t(o.hotelId, o.hotelGroup, i), e = c;
30
+ awardPoints: e.points.awardPointsValue ?? e.points.pointsValue,
31
+ points: e.points.pointsValue,
32
+ pointsType: e.points.pointsType,
33
+ bestValue: u ? l.NONE : o.bestValue
34
+ }, i = e.rooms ?? o.rooms ?? [], t(o.hotelId, o.hotelGroup, n);
36
35
  }
37
36
  return {
38
- pointsHotelDetails: i,
39
- pointsRooms: r,
40
- shouldFallbackBestCheckout: e
37
+ pointsHotelDetails: n,
38
+ pointsRooms: i
41
39
  };
42
40
  }, A = async ({
43
41
  hotel: o,
44
42
  checkinDate: s,
45
43
  checkoutDate: a,
46
44
  guests: t,
47
- rooms: e,
45
+ rooms: n,
48
46
  updateHotel: i,
49
47
  numberOfNights: r
50
48
  }) => {
51
- var c;
52
- if (!((c = o == null ? void 0 : o.cashBookingOffers) != null && c.accommodationId))
49
+ var f;
50
+ if (!((f = o == null ? void 0 : o.cashBookingOffers) != null && f.accommodationId))
53
51
  return {
54
52
  cashHotelDetails: o,
55
53
  cashRooms: []
56
54
  };
57
- const u = (f) => Array.from({ length: f }, () => ({ type: y.ADULT })), n = await d.getAvailableRooms({
55
+ const e = (d) => Array.from({ length: d }, () => ({ type: y.ADULT })), c = await h.getAvailableRooms({
58
56
  checkinDate: s,
59
57
  checkoutDate: a,
60
58
  accommodationId: o.cashBookingOffers.accommodationId,
61
- guests: u(t),
62
- rooms: e
63
- }), l = {
59
+ guests: e(t),
60
+ rooms: n
61
+ }), u = {
64
62
  ...o,
65
63
  cashValue: {
66
64
  ...o.cashValue,
67
- amount: n.cheapestRate / r || o.cashValue.amount || 0,
68
- currency: n.currency ?? o.cashValue.currency
65
+ amount: c.cheapestRate / r || o.cashValue.amount || 0,
66
+ currency: c.currency ?? o.cashValue.currency
69
67
  }
70
68
  };
71
- return i(o.hotelId, o.hotelGroup, l), {
72
- cashHotelDetails: l,
73
- cashRooms: n.availableRooms
69
+ return i(o.hotelId, o.hotelGroup, u), {
70
+ cashHotelDetails: u,
71
+ cashRooms: c.availableRooms
74
72
  };
75
- }, B = async (o, s) => {
76
- const { success: a, data: t } = await h.getRecommendations({
73
+ }, G = async (o, s) => {
74
+ const { success: a, data: t } = await m.getRecommendations({
77
75
  days: s,
78
76
  hotels: [o]
79
77
  });
@@ -85,15 +83,15 @@ const w = async (o) => await h.getTransferPartners(
85
83
  isAvailable: !1
86
84
  };
87
85
  }, C = (o, s) => {
88
- var t, e, i;
86
+ var t, n;
89
87
  return {
90
- bestCheckoutMethod: p.isHotelChain(o.hotelGroup) ? o.bestValue : m.CASH,
88
+ bestCheckoutMethod: p.isHotelChain(o.hotelGroup) ? o.bestValue : l.CASH,
91
89
  nightlyCashCost: ((t = o.cashValue) == null ? void 0 : t.amount) || 0,
92
90
  nightlyPointsCost: o.points || 0,
93
91
  awardPoints: o.points || 0,
94
- totalCashCost: (((e = o.cashValue) == null ? void 0 : e.amount) || 0) * s,
92
+ totalCashCost: (((n = o.cashValue) == null ? void 0 : n.amount) || 0) * s,
95
93
  totalPointsCost: (o.points || 0) * s,
96
- currency: ((i = o.cashValue) == null ? void 0 : i.currency) ?? "USD",
94
+ currency: "USD",
97
95
  sufficientPoints: !0,
98
96
  rewardsProgram: p.toProgram(o.hotelGroup),
99
97
  optimalProgram: {
@@ -101,7 +99,7 @@ const w = async (o) => await h.getTransferPartners(
101
99
  remainingPointsBalance: 0
102
100
  }
103
101
  };
104
- }, G = (o, s, a) => {
102
+ }, B = (o, s, a) => {
105
103
  let t = o;
106
104
  return s && (t = {
107
105
  ...o,
@@ -116,10 +114,10 @@ const w = async (o) => await h.getTransferPartners(
116
114
  }), t;
117
115
  };
118
116
  export {
119
- G as combineUpdatedHotelData,
117
+ B as combineUpdatedHotelData,
120
118
  C as fallbackBestCheckout,
121
119
  A as fetchAvailableRooms,
122
- B as fetchBestCheckout,
120
+ G as fetchBestCheckout,
123
121
  T as fetchPointsCheck,
124
122
  w as fetchTransferPartners
125
123
  };
@@ -1,30 +1,30 @@
1
- import { useMemo as S } from "react";
2
- import { h as g } from "../../moment-BGjjqtLQ.js";
1
+ import { useMemo as M } from "react";
2
+ import { h as v } from "../../moment-BGjjqtLQ.js";
3
3
  import "../../arrayExtensions-cyilNkdJ.js";
4
- import N from "../../stores/useHotelsStore.js";
5
- import { fetchTransferPartners as M, fetchPointsCheck as T, fetchAvailableRooms as x, fetchBestCheckout as E, combineUpdatedHotelData as m, fallbackBestCheckout as Q } from "./useHotelDetails.api.js";
6
- import { calculatePointsAsCash as U } from "../../utilities/pointsAsCashUtils.js";
4
+ import T from "../../stores/useHotelsStore.js";
5
+ import { fetchTransferPartners as x, fetchPointsCheck as E, fetchAvailableRooms as L, fetchBestCheckout as Q, combineUpdatedHotelData as F, fallbackBestCheckout as U } from "./useHotelDetails.api.js";
6
+ import { calculatePointsAsCash as j } from "../../utilities/pointsAsCashUtils.js";
7
7
  import { useQuery as o } from "@tanstack/react-query";
8
- const j = (t, a) => Math.abs(
9
- g(t.startOf("day")).diff(g(a.endOf("day")), "days")
10
- ), _ = (t) => {
11
- var d, h, k, f, D, p, y, C, b, v;
8
+ const z = (t, c) => Math.abs(
9
+ v(t.startOf("day")).diff(v(c.endOf("day")), "days")
10
+ ), $ = (t) => {
11
+ var d, h, f, k, D, p, y, b, C, g, m;
12
12
  if (!t)
13
13
  throw new Error(
14
14
  "Hotel is required in order to initiate the hotel details flow"
15
15
  );
16
- const { updateHotel: a, searchParams: e } = N(), s = S(() => e ? j(
16
+ const { updateHotel: c, searchParams: e } = T(), a = M(() => e ? z(
17
17
  e.checkinDate,
18
18
  e.checkoutDate
19
- ) : 0, [e]), { data: O, isLoading: q } = o({
19
+ ) : 0, [e]), { data: O, isFetching: q } = o({
20
20
  queryKey: ["transferPartners", t.hotelGroup],
21
- queryFn: () => M(t.hotelGroup),
21
+ queryFn: () => x(t.hotelGroup),
22
22
  enabled: !!t.hotelGroup,
23
23
  placeholderData: []
24
24
  }), {
25
25
  data: H,
26
- isLoading: i,
27
- isPlaceholderData: R
26
+ isFetching: i,
27
+ isFetched: R
28
28
  } = o({
29
29
  queryKey: [
30
30
  "hotelPointsCheck",
@@ -33,45 +33,43 @@ const j = (t, a) => Math.abs(
33
33
  (d = e == null ? void 0 : e.checkinDate) == null ? void 0 : d.valueOf(),
34
34
  (h = e == null ? void 0 : e.checkoutDate) == null ? void 0 : h.valueOf()
35
35
  ],
36
- queryFn: () => T({
36
+ queryFn: () => E({
37
37
  hotel: t,
38
38
  checkinDate: e.checkinDate,
39
39
  checkoutDate: e.checkoutDate,
40
- updateHotel: a
40
+ updateHotel: c
41
41
  }),
42
42
  enabled: !!e && !!e.checkinDate && !!e.checkoutDate && !!t.liveScrapingCheckNeeded,
43
43
  // We don't throw an error on fail so we can gracefully handle fallback
44
44
  retry: !1,
45
45
  placeholderData: {
46
46
  pointsHotelDetails: t,
47
- pointsRooms: t.rooms ?? [],
48
- shouldFallbackBestCheckout: !1
47
+ pointsRooms: t.rooms ?? []
49
48
  }
50
- }), { pointsRooms: B, pointsHotelDetails: l, shouldFallbackBestCheckout: A } = H || {
49
+ }), { pointsRooms: A, pointsHotelDetails: s } = H || {
51
50
  pointsHotelDetails: t,
52
- pointsRooms: [],
53
- shouldFallbackBestCheckout: !1
51
+ pointsRooms: []
54
52
  }, {
55
- data: F,
56
- isLoading: n,
57
- isPlaceholderData: G
53
+ data: B,
54
+ isFetching: n,
55
+ isFetched: G
58
56
  } = o({
59
57
  queryKey: [
60
58
  "fetchAvailableRooms",
61
- (k = t.cashBookingOffers) == null ? void 0 : k.accommodationId,
62
- (f = e == null ? void 0 : e.checkinDate) == null ? void 0 : f.valueOf(),
59
+ (f = t.cashBookingOffers) == null ? void 0 : f.accommodationId,
60
+ (k = e == null ? void 0 : e.checkinDate) == null ? void 0 : k.valueOf(),
63
61
  (D = e == null ? void 0 : e.checkoutDate) == null ? void 0 : D.valueOf(),
64
62
  e == null ? void 0 : e.guests,
65
63
  e == null ? void 0 : e.rooms
66
64
  ],
67
- queryFn: () => x({
65
+ queryFn: () => L({
68
66
  hotel: t,
69
67
  checkinDate: e.checkinDate,
70
68
  checkoutDate: e.checkoutDate,
71
69
  guests: e.guests,
72
70
  rooms: e.rooms,
73
- updateHotel: a,
74
- numberOfNights: s
71
+ updateHotel: c,
72
+ numberOfNights: a
75
73
  }),
76
74
  enabled: !!e && !!e.checkinDate && !!e.checkoutDate && !!((p = t.cashBookingOffers) != null && p.accommodationId),
77
75
  retry: !1,
@@ -79,64 +77,68 @@ const j = (t, a) => Math.abs(
79
77
  cashHotelDetails: t,
80
78
  cashRooms: []
81
79
  }
82
- }), { cashRooms: L, cashHotelDetails: u } = F || {
80
+ }), { cashRooms: I, cashHotelDetails: u } = B || {
83
81
  cashHotelDetails: t,
84
82
  cashRooms: []
85
- }, { data: I, isLoading: K } = o({
83
+ }, {
84
+ data: K,
85
+ isFetching: w,
86
+ isFetched: S
87
+ } = o({
86
88
  queryKey: [
87
89
  "bestCheckout",
88
90
  t.hotelId,
89
91
  t.hotelGroup,
90
92
  (y = e == null ? void 0 : e.checkinDate) == null ? void 0 : y.valueOf(),
91
- (C = e == null ? void 0 : e.checkoutDate) == null ? void 0 : C.valueOf()
93
+ (b = e == null ? void 0 : e.checkoutDate) == null ? void 0 : b.valueOf()
92
94
  ],
93
- queryFn: () => E(
94
- m(t, l, u),
95
- s
95
+ queryFn: () => Q(
96
+ F(t, s, u),
97
+ a
96
98
  ),
97
- enabled: !i && (t.liveScrapingCheckNeeded ? !R : !0) && !n && !G && !A && s > 0,
99
+ enabled: !i && (t.liveScrapingCheckNeeded ? R : !0) && !n && ((C = t.cashBookingOffers) != null && C.accommodationId ? G : !0) && a > 0,
98
100
  retry: !1,
99
101
  placeholderData: {
100
- bestCheckout: Q(t, s),
102
+ bestCheckout: U(t, a),
101
103
  isAvailable: !1
102
104
  }
103
- }), { bestCheckout: c, isAvailable: r } = I || {
105
+ }), { bestCheckout: l, isAvailable: r } = K || {
104
106
  isAvailable: !1
105
- }, { data: w } = o({
107
+ }, { data: N } = o({
106
108
  queryKey: [
107
109
  "pointsAsCash",
108
110
  t.hotelId,
109
111
  t.hotelGroup,
110
- (b = e == null ? void 0 : e.checkinDate) == null ? void 0 : b.valueOf(),
111
- (v = e == null ? void 0 : e.checkoutDate) == null ? void 0 : v.valueOf()
112
+ (g = e == null ? void 0 : e.checkinDate) == null ? void 0 : g.valueOf(),
113
+ (m = e == null ? void 0 : e.checkoutDate) == null ? void 0 : m.valueOf()
112
114
  ],
113
- queryFn: () => U(c.totalCashCost),
114
- enabled: !!c && r,
115
+ queryFn: () => j(l.totalCashCost),
116
+ enabled: S && r,
115
117
  retry: !1
116
118
  });
117
119
  return {
118
120
  transferPartners: O,
119
121
  loadingTransferPartners: q,
120
122
  // Points Check
121
- pointsRooms: B,
123
+ pointsRooms: A,
122
124
  loadingLivePointsCheck: i,
123
125
  // Cash Rooms
124
- cashRooms: L,
126
+ cashRooms: I,
125
127
  loadingCashRooms: n,
126
128
  // Best Checkout
127
- bestCheckout: c,
128
- loadingBestCheckout: K,
129
+ bestCheckout: l,
130
+ loadingBestCheckout: w,
129
131
  // Combined availability
130
132
  isAvailable: r,
131
133
  // Points as Cash
132
- pointsAsCash: w,
133
- hotelDetails: m(
134
+ pointsAsCash: N,
135
+ hotelDetails: F(
134
136
  t,
135
- l,
137
+ s,
136
138
  u
137
139
  )
138
140
  };
139
141
  };
140
142
  export {
141
- _ as useHotelDetails
143
+ $ as useHotelDetails
142
144
  };
@@ -1,17 +1,17 @@
1
- import { useQuery as n } from "@tanstack/react-query";
2
- import { HotelService as r } from "../../services/hotel/HotelService.js";
3
- const l = (e) => {
4
- const { data: o, isLoading: i } = n({
5
- queryKey: ["locations", e],
6
- queryFn: () => r.getLocations(e),
7
- enabled: !!e
1
+ import { useQuery as r } from "@tanstack/react-query";
2
+ import { HotelService as t } from "../../services/hotel/HotelService.js";
3
+ const c = (o) => {
4
+ const { data: e, isLoading: i } = r({
5
+ queryKey: ["locations", o],
6
+ queryFn: () => t.getLocations(o),
7
+ enabled: !!o
8
8
  // Only run the query if searchInput is not empty
9
9
  });
10
- return console.log({ data: o }), {
11
- locations: (o == null ? void 0 : o.data) || [],
10
+ return {
11
+ locations: (e == null ? void 0 : e.data) || [],
12
12
  loading: i
13
13
  };
14
14
  };
15
15
  export {
16
- l as useLocationSearch
16
+ c as useLocationSearch
17
17
  };
@@ -7,7 +7,6 @@ export declare const fetchTransferPartners: (hotelGroup: string) => Promise<any>
7
7
  interface IPointsCheckResult {
8
8
  pointsHotelDetails: IHotelDetails;
9
9
  pointsRooms: IRoom[];
10
- shouldFallbackBestCheckout: boolean;
11
10
  }
12
11
  interface IHotelPointsCheckParams {
13
12
  hotel: IHotelDetails;
@@ -33,7 +33,7 @@ class H {
33
33
  success: !0,
34
34
  data: e.data.cities.map(
35
35
  (o) => {
36
- const { search_id: p, type: _, description: d, coordinates: y, city: g } = o, n = {
36
+ const { search_id: p, search_type: _, description: d, coordinates: y, city: g } = o, n = {
37
37
  searchId: p,
38
38
  searchType: _,
39
39
  description: d,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@odynn/awayz-hotels",
3
3
  "private": false,
4
- "version": "0.1.15",
4
+ "version": "0.1.17",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"