@odynn/awayz-hotels 0.10.2 → 0.11.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.
@@ -1,74 +1,74 @@
1
- import { useAwayzContext as G, useWallet as N, awayzClient as m } from "@odynn/awayz-core";
2
- import { useMutation as p } from "@tanstack/react-query";
3
- import { g as B } from "../../dateUtils-C1hKW8MF.js";
4
- import { D as F, a as f } from "../../index-CJj9N0Xq.js";
5
- import { E as k } from "../../enums-tLvxh02p.js";
1
+ import { useAwayzContext as F, useWallet as P, awayzClient as p } from "@odynn/awayz-core";
2
+ import { useMutation as f } from "@tanstack/react-query";
3
+ import { g as k } from "../../dateUtils-C1hKW8MF.js";
4
+ import { D as R, a as D } from "../../index-CJj9N0Xq.js";
5
+ import { E as y } from "../../enums-tLvxh02p.js";
6
6
  import "../../arrayExtensions-CFEBYUok.js";
7
- import "react";
8
- import { h as l } from "../../moment-BGjjqtLQ.js";
9
- import { HotelChains as c } from "../../definitions/HotelChains.js";
10
- import { HotelService as D } from "../../services/hotel/HotelService.js";
11
- import { ESearchType as y } from "../../services/hotel/HotelService.types.js";
12
- import R from "../../stores/useHotelsStore.js";
13
- import { checkNthNightFree as x } from "../../utilities/hotelUtils/freeNightUtils.js";
14
- import { getHaversineDistanceKm as _ } from "../../utilities/hotelUtils/hotelUtils.js";
15
- const g = (t) => {
7
+ import { useEffect as x } from "react";
8
+ import { h as d } from "../../moment-BGjjqtLQ.js";
9
+ import { HotelChains as a } from "../../definitions/HotelChains.js";
10
+ import { HotelService as _ } from "../../services/hotel/HotelService.js";
11
+ import { ESearchType as E } from "../../services/hotel/HotelService.types.js";
12
+ import w from "../../stores/useHotelsStore.js";
13
+ import { checkNthNightFree as S } from "../../utilities/hotelUtils/freeNightUtils.js";
14
+ import { getHaversineDistanceKm as C } from "../../utilities/hotelUtils/hotelUtils.js";
15
+ const K = (t) => {
16
16
  if (!t.checkinDate || !t.checkoutDate)
17
17
  throw new Error("Check-in and checkout dates are required.");
18
18
  if (!t.coordinates)
19
19
  throw new Error("Coordinates are required.");
20
- t.hotelGroups && t.hotelGroups.forEach((a) => {
21
- if (!c.toList().includes(a))
20
+ t.hotelGroups && t.hotelGroups.forEach((s) => {
21
+ if (!a.toList().includes(s))
22
22
  throw new Error(
23
- `Invalid hotel group: ${a}. Please use one of the following: ${c.toList().join(
23
+ `Invalid hotel group: ${s}. Please use one of the following: ${a.toList().join(
24
24
  ", "
25
25
  )}`
26
26
  );
27
27
  });
28
- }, K = (t) => {
28
+ }, O = (t) => {
29
29
  if (!t.checkinDate || !t.checkoutDate)
30
30
  throw new Error("Check-in and checkout dates are required.");
31
31
  if (!t.hotelName)
32
32
  throw new Error("Hotel name is required");
33
33
  if (!t.hotelGroup)
34
34
  throw new Error("Hotel group is required");
35
- if (!c.toList().includes(t.hotelGroup))
35
+ if (!a.toList().includes(t.hotelGroup))
36
36
  throw new Error(
37
- `Invalid hotel group: ${t.hotelGroup}. Please use one of the following: ${c.toList().join(", ")}`
37
+ `Invalid hotel group: ${t.hotelGroup}. Please use one of the following: ${a.toList().join(", ")}`
38
38
  );
39
- }, ee = () => {
40
- const { setHotels: t, hotels: a, setSearchParams: d } = R(), { config: s } = G(), { userCards: w } = N(), {
41
- mutate: E,
42
- isPending: S,
43
- status: C,
44
- isError: I,
45
- error: H
46
- } = p({
39
+ }, te = () => {
40
+ const { setHotels: t, hotels: s, setSearchParams: m } = w(), { config: c } = F(), { userCards: h } = P(), {
41
+ mutate: I,
42
+ isPending: H,
43
+ status: L,
44
+ isError: T,
45
+ error: v
46
+ } = f({
47
47
  mutationFn: async (e) => {
48
- g(e), t([]), d({
49
- checkinDate: l(e.checkinDate),
50
- checkoutDate: l(e.checkoutDate),
48
+ K(e), t([]), m({
49
+ checkinDate: d(e.checkinDate),
50
+ checkoutDate: d(e.checkoutDate),
51
51
  guests: e.guests || 2,
52
52
  rooms: e.rooms || 1
53
53
  });
54
- const r = {
54
+ const o = {
55
55
  check_in_date: e.checkinDate,
56
56
  check_out_date: e.checkoutDate,
57
57
  guests: e.guests || 2,
58
58
  rooms: e.rooms || 1,
59
59
  cash_or_points: e.cashOrPoints || ["cash", "points"],
60
- region_code: e.userRegion || f,
60
+ region_code: e.userRegion || D,
61
61
  lat: e.coordinates.latitude,
62
62
  lon: e.coordinates.longitude,
63
63
  search_range: e.searchRange || 10,
64
- range_type: e.rangeType || F,
65
- hotel_groups: e.hotelGroups || c.toList(),
66
- type: e.searchType || y.CITY,
67
- external_inventory: (s == null ? void 0 : s.externalInventory) || !1,
68
- use_duffel: s == null ? void 0 : s.supportsDuffel
64
+ range_type: e.rangeType || R,
65
+ hotel_groups: e.hotelGroups || a.toList(),
66
+ type: e.searchType || E.CITY,
67
+ external_inventory: (c == null ? void 0 : c.externalInventory) || !1,
68
+ use_duffel: c == null ? void 0 : c.supportsDuffel
69
69
  };
70
70
  return {
71
- ...await D.searchByCoords(r),
71
+ ...await _.searchByCoords(o),
72
72
  checkinDate: e.checkinDate,
73
73
  checkoutDate: e.checkoutDate,
74
74
  searchCoordinates: e.coordinates
@@ -76,76 +76,76 @@ const g = (t) => {
76
76
  },
77
77
  onSuccess: (e) => {
78
78
  if (e.success) {
79
- const { checkinDate: r, checkoutDate: n, searchCoordinates: i } = e, h = B(r, n), o = e.data.map((u) => ({
80
- ...u,
81
- distance: _(
79
+ const { checkinDate: o, checkoutDate: n, searchCoordinates: i } = e, u = k(o, n), r = e.data.map((l) => ({
80
+ ...l,
81
+ distance: C(
82
82
  i.latitude,
83
83
  i.longitude,
84
- u.coordinates.latitude,
85
- u.coordinates.longitude
84
+ l.coordinates.latitude,
85
+ l.coordinates.longitude
86
86
  ),
87
- nthNightFree: x({
88
- hotel: u,
89
- cards: w ?? [],
90
- nights: h
87
+ nthNightFree: S({
88
+ hotel: l,
89
+ cards: h ?? [],
90
+ nights: u
91
91
  })
92
92
  }));
93
- t(o);
93
+ t(r);
94
94
  }
95
95
  },
96
96
  onSettled: () => {
97
- m.invalidateQueries({ queryKey: [k.SEARCH_LIMIT] });
97
+ p.invalidateQueries({ queryKey: [y.SEARCH_LIMIT] });
98
98
  }
99
99
  });
100
- function L(e, r) {
100
+ function g(e, o) {
101
101
  let n = 0;
102
- const i = e.length < r.length ? e : r, h = e.length >= r.length ? e : r;
103
- for (let o = 0; o < i.length; o++)
104
- e[o] === r[o] && n++;
105
- return n / h.length;
102
+ const i = e.length < o.length ? e : o, u = e.length >= o.length ? e : o;
103
+ for (let r = 0; r < i.length; r++)
104
+ e[r] === o[r] && n++;
105
+ return n / u.length;
106
106
  }
107
107
  const {
108
- mutate: T,
109
- isPending: v,
110
- status: q,
111
- isError: P,
112
- error: A
113
- } = p({
108
+ mutate: q,
109
+ isPending: N,
110
+ status: A,
111
+ isError: G,
112
+ error: B
113
+ } = f({
114
114
  mutationFn: async (e) => {
115
- K(e), t([]), d({
116
- checkinDate: l(e.checkinDate),
117
- checkoutDate: l(e.checkoutDate),
115
+ O(e), t([]), m({
116
+ checkinDate: d(e.checkinDate),
117
+ checkoutDate: d(e.checkoutDate),
118
118
  guests: e.guests || 2,
119
119
  rooms: e.rooms || 1
120
120
  });
121
- const r = {
121
+ const o = {
122
122
  check_in_date: e.checkinDate,
123
123
  check_out_date: e.checkoutDate,
124
124
  guests: e.guests || 2,
125
125
  rooms: e.rooms || 1,
126
126
  cash_or_points: e.cashOrPoints || ["cash", "points"],
127
- region_code: e.userRegion || f,
127
+ region_code: e.userRegion || D,
128
128
  lat: e.coordinates.latitude,
129
129
  lon: e.coordinates.longitude,
130
130
  search_range: 0.5,
131
131
  range_type: "km",
132
132
  hotel_groups: [e.hotelGroup],
133
- type: y.HOTEL,
133
+ type: E.HOTEL,
134
134
  external_inventory: !1,
135
- use_duffel: s == null ? void 0 : s.supportsDuffel
136
- }, n = await D.searchByCoords(r);
135
+ use_duffel: c == null ? void 0 : c.supportsDuffel
136
+ }, n = await _.searchByCoords(o);
137
137
  if (!n.success)
138
138
  throw new Error(n.message || "Hotel search failed");
139
139
  const i = 0.8;
140
140
  return n.data.filter(
141
- (o) => L(o.name.toLowerCase(), e.hotelName.toLowerCase()) >= i
142
- ).map((o) => ({
143
- ...o,
144
- distance: _(
141
+ (r) => g(r.name.toLowerCase(), e.hotelName.toLowerCase()) >= i
142
+ ).map((r) => ({
143
+ ...r,
144
+ distance: C(
145
145
  e.coordinates.latitude,
146
146
  e.coordinates.longitude,
147
- o.coordinates.latitude,
148
- o.coordinates.longitude
147
+ r.coordinates.latitude,
148
+ r.coordinates.longitude
149
149
  )
150
150
  }));
151
151
  },
@@ -153,22 +153,38 @@ const g = (t) => {
153
153
  t(e);
154
154
  },
155
155
  onSettled: () => {
156
- m.invalidateQueries({ queryKey: [k.SEARCH_LIMIT] });
156
+ p.invalidateQueries({ queryKey: [y.SEARCH_LIMIT] });
157
157
  }
158
158
  });
159
- return {
160
- results: a,
161
- loading: C === "pending" || q === "pending" || S || v,
162
- isCoordsSearchError: I,
163
- coordsSearchError: H,
164
- isHotelIdSearchError: P,
165
- hotelIdSearchError: A,
166
- searchByCoords: E,
167
- searchByHotelId: T
159
+ return x(() => {
160
+ if (!s.length || !h) return;
161
+ const { searchParams: e } = w.getState();
162
+ if (!(e != null && e.checkinDate) || !(e != null && e.checkoutDate)) return;
163
+ const o = k(
164
+ e.checkinDate,
165
+ e.checkoutDate
166
+ ), n = s.map((i) => ({
167
+ ...i,
168
+ nthNightFree: S({
169
+ hotel: i,
170
+ cards: h,
171
+ nights: o
172
+ })
173
+ }));
174
+ t(n);
175
+ }, [h, s.length]), {
176
+ results: s,
177
+ loading: L === "pending" || A === "pending" || H || N,
178
+ isCoordsSearchError: T,
179
+ coordsSearchError: v,
180
+ isHotelIdSearchError: G,
181
+ hotelIdSearchError: B,
182
+ searchByCoords: I,
183
+ searchByHotelId: q
168
184
  };
169
185
  };
170
186
  export {
171
- ee as useHotelSearch,
172
- g as validateSearchByCoordsArgs,
173
- K as validateSearchByHotelIdArgs
187
+ te as useHotelSearch,
188
+ K as validateSearchByCoordsArgs,
189
+ O as validateSearchByHotelIdArgs
174
190
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@odynn/awayz-hotels",
3
3
  "private": false,
4
- "version": "0.10.2",
4
+ "version": "0.11.0",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"