@odynn/awayz-hotels 0.5.9 → 0.5.11

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.
@@ -9,47 +9,47 @@ const w = async (t) => await f.getTransferPartners(
9
9
  hotel: t,
10
10
  checkinDate: o,
11
11
  checkoutDate: e,
12
- updateHotel: s
12
+ updateHotel: a
13
13
  }) => {
14
- let i = t, n = t.rooms ?? [];
14
+ let s = t, i = t.rooms ?? [];
15
15
  if (!t.liveScrapingCheckNeeded || t.hotelGroup === l.Marriott)
16
16
  return {
17
17
  pointsHotelDetails: t,
18
- pointsRooms: n
18
+ pointsRooms: i
19
19
  };
20
20
  let r = !1, c = null;
21
21
  try {
22
- const a = await f.hotelPointsCheck({
22
+ const n = await f.hotelPointsCheck({
23
23
  hotelGroup: t.hotelGroup,
24
24
  hotelId: t.hotelId,
25
25
  checkinDate: o,
26
26
  checkoutDate: e
27
27
  });
28
- r = a.success, c = a.data;
28
+ r = n.success, c = n.data;
29
29
  } catch {
30
30
  r = !1, c = null;
31
31
  }
32
32
  if (r) {
33
- const a = c, u = !(a.points.pointsValue > 0) && t.bestValue === m.POINTS;
34
- i = {
33
+ const n = c, u = !(n.points.pointsValue > 0) && t.bestValue === m.POINTS;
34
+ s = {
35
35
  ...t,
36
- awardPoints: a.points.awardPointsValue ?? a.points.pointsValue,
37
- points: a.points.pointsValue,
38
- pointsType: a.points.pointsType,
36
+ awardPoints: n.points.awardPointsValue ?? n.points.pointsValue,
37
+ points: n.points.pointsValue,
38
+ pointsType: n.points.pointsType,
39
39
  bestValue: u ? m.NONE : t.bestValue
40
- }, n = a.rooms ?? t.rooms ?? [], s(t.hotelId, t.hotelGroup, i);
40
+ }, i = n.rooms ?? t.rooms ?? [], a(t.hotelId, t.hotelGroup, s);
41
41
  }
42
42
  return {
43
- pointsHotelDetails: i,
44
- pointsRooms: n
43
+ pointsHotelDetails: s,
44
+ pointsRooms: i
45
45
  };
46
46
  }, A = async ({
47
47
  hotel: t,
48
48
  checkinDate: o,
49
49
  checkoutDate: e,
50
- guests: s,
51
- rooms: i,
52
- updateHotel: n,
50
+ guests: a,
51
+ rooms: s,
52
+ updateHotel: i,
53
53
  numberOfNights: r
54
54
  }) => {
55
55
  var u;
@@ -58,48 +58,47 @@ const w = async (t) => await f.getTransferPartners(
58
58
  cashHotelDetails: t,
59
59
  cashRooms: []
60
60
  };
61
- const c = (h) => Array.from({ length: h }, () => ({ type: y.ADULT })), a = await d.getAvailableRooms({
61
+ const c = (h) => Array.from({ length: h }, () => ({ type: y.ADULT })), n = await d.getAvailableRooms({
62
62
  checkinDate: o,
63
63
  checkoutDate: e,
64
64
  accommodationId: t.cashBookingOffers.accommodationId,
65
- guests: c(s),
66
- rooms: i
65
+ guests: c(a),
66
+ rooms: s
67
67
  }), p = {
68
68
  ...t,
69
69
  cashValue: {
70
70
  ...t.cashValue,
71
- amount: a.cheapestRate / r || t.cashValue.amount || 0,
72
- currency: a.currency ?? t.cashValue.currency
71
+ amount: n.cheapestRate / r || t.cashValue.amount || 0,
72
+ currency: n.currency ?? t.cashValue.currency
73
73
  }
74
74
  };
75
- return n(t.hotelId, t.hotelGroup, p), {
75
+ return i(t.hotelId, t.hotelGroup, p), {
76
76
  cashHotelDetails: p,
77
- cashRooms: a.availableRooms
77
+ cashRooms: n.availableRooms
78
78
  };
79
- }, G = async (t, o, e, s) => {
80
- const { success: i, data: n } = await f.getRecommendations({
79
+ }, G = async (t, o, e) => {
80
+ const { success: a, data: s } = await f.getRecommendations({
81
81
  days: o,
82
- hotels: [t],
83
- userCurrency: e
82
+ hotel: t
84
83
  });
85
- return i && n ? {
84
+ return a && s ? {
86
85
  bestCheckout: {
87
- ...n,
88
- nightlyPointsCost: s ? n.awardPoints : n.nightlyPointsCost
86
+ ...s,
87
+ nightlyPointsCost: e ? s.awardPoints : s.nightlyPointsCost
89
88
  },
90
- isAvailable: n.nightlyPointsCost > 0 || n.nightlyCashCost > 0
89
+ isAvailable: s.nightlyPointsCost > 0 || s.nightlyCashCost > 0
91
90
  } : {
92
91
  bestCheckout: P(t, o),
93
92
  isAvailable: !1
94
93
  };
95
94
  }, P = (t, o) => {
96
- var s, i;
95
+ var a, s;
97
96
  return {
98
97
  bestCheckoutMethod: l.isHotelChain(t.hotelGroup) ? t.bestValue : m.CASH,
99
- nightlyCashCost: ((s = t.cashValue) == null ? void 0 : s.amount) || 0,
98
+ nightlyCashCost: ((a = t.cashValue) == null ? void 0 : a.amount) || 0,
100
99
  nightlyPointsCost: t.points || 0,
101
100
  awardPoints: t.points || 0,
102
- totalCashCost: (((i = t.cashValue) == null ? void 0 : i.amount) || 0) * o,
101
+ totalCashCost: (((s = t.cashValue) == null ? void 0 : s.amount) || 0) * o,
103
102
  totalPointsCost: (t.points || 0) * o,
104
103
  currency: "USD",
105
104
  sufficientPoints: !0,
@@ -111,18 +110,18 @@ const w = async (t) => await f.getTransferPartners(
111
110
  }
112
111
  };
113
112
  }, B = (t, o, e) => {
114
- let s = t;
115
- return o && (s = {
113
+ let a = t;
114
+ return o && (a = {
116
115
  ...t,
117
116
  points: o.points,
118
117
  awardPoints: o.awardPoints,
119
118
  pointsType: o.pointsType,
120
119
  bestValue: o.bestValue
121
- }), e && (s = {
122
- ...s,
120
+ }), e && (a = {
121
+ ...a,
123
122
  cashValue: e.cashValue,
124
123
  rooms: e.rooms
125
- }), s;
124
+ }), a;
126
125
  };
127
126
  export {
128
127
  B as combineUpdatedHotelData,
@@ -1,52 +1,52 @@
1
- import { g as Y } from "../../dateUtils-C1hKW8MF.js";
1
+ import { g as _ } from "../../dateUtils-C1hKW8MF.js";
2
2
  import "../../arrayExtensions-CFEBYUok.js";
3
- import { useState as j, useMemo as I } from "react";
4
- import J from "../../stores/useHotelsStore.js";
5
- import { fetchTransferPartners as V, fetchPointsCheck as X, fetchAvailableRooms as Z, fallbackBestCheckout as $, fetchBestCheckout as ee, combineUpdatedHotelData as G } from "./useHotelDetails.api.js";
6
- import { useAwayzContext as te, useWallet as oe } from "@odynn/awayz-core";
7
- import { useQuery as c } from "@tanstack/react-query";
8
- import { h as B } from "../../moment-BGjjqtLQ.js";
9
- import { HotelChains as ce } from "../../definitions/HotelChains.js";
10
- import { IhgFreeNightCards as ae } from "../../definitions/IhgFreeNightCards.js";
11
- import { calculatePointsAsCash as se } from "../../utilities/pointsAsCashUtils.js";
12
- const ie = "USD", ye = (t) => {
13
- var d, y, C, g, b, v, F, R, H, q, O, A;
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
14
  if (!t)
15
15
  throw new Error(
16
16
  "Hotel is required in order to initiate the hotel details flow"
17
17
  );
18
- const { user: i } = te(), w = ((d = i == null ? void 0 : i.userRegion) == null ? void 0 : d.currency) || ie, { updateHotel: u, searchParams: o } = J(), [e, S] = j({
18
+ const { updateHotel: l, searchParams: o } = z(), [e, G] = j({
19
19
  checkinDate: o == null ? void 0 : o.checkinDate,
20
20
  checkoutDate: o == null ? void 0 : o.checkoutDate
21
- }), a = I(() => Y(e.checkinDate, e.checkoutDate), [e]), K = (n, r) => {
22
- S({
23
- checkinDate: B(n),
24
- checkoutDate: B(r)
21
+ }), c = h(() => _(e.checkinDate, e.checkoutDate), [e]), B = (r, u) => {
22
+ G({
23
+ checkinDate: I(r),
24
+ checkoutDate: I(u)
25
25
  });
26
- }, { userCards: s } = oe(), h = I(() => (t == null ? void 0 : t.hotelGroup) === ce.IHG ? ae.some(
27
- (n) => s == null ? void 0 : s.some((r) => r.name === n)
28
- ) : !0, [s]), { data: N, isFetching: P } = c({
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({
29
29
  queryKey: ["transferPartners", t.hotelGroup],
30
- queryFn: () => V(t.hotelGroup),
30
+ queryFn: () => J(t.hotelGroup),
31
31
  enabled: !!t.hotelGroup,
32
32
  placeholderData: []
33
33
  }), {
34
- data: U,
35
- isFetching: l,
36
- isFetched: E
37
- } = c({
34
+ data: S,
35
+ isFetching: D,
36
+ isFetched: N
37
+ } = a({
38
38
  queryKey: [
39
39
  "hotelPointsCheck",
40
40
  t.hotelId,
41
41
  t.hotelGroup,
42
- (y = e == null ? void 0 : e.checkinDate) == null ? void 0 : y.valueOf(),
43
- (C = e == null ? void 0 : e.checkoutDate) == null ? void 0 : C.valueOf()
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()
44
44
  ],
45
- queryFn: () => X({
45
+ queryFn: () => V({
46
46
  hotel: t,
47
47
  checkinDate: e.checkinDate,
48
48
  checkoutDate: e.checkoutDate,
49
- updateHotel: u
49
+ updateHotel: l
50
50
  }),
51
51
  enabled: !!e.checkinDate && !!e.checkoutDate && !!t.liveScrapingCheckNeeded,
52
52
  // We don't throw an error on fail so we can gracefully handle fallback
@@ -55,103 +55,105 @@ const ie = "USD", ye = (t) => {
55
55
  pointsHotelDetails: t,
56
56
  pointsRooms: t.rooms ?? []
57
57
  }
58
- }), { pointsRooms: T, pointsHotelDetails: D } = U || {
58
+ }), { pointsRooms: P, pointsHotelDetails: i } = S || {
59
59
  pointsHotelDetails: t,
60
60
  pointsRooms: []
61
61
  }, {
62
- data: x,
63
- isFetching: f,
64
- isFetched: L
65
- } = c({
62
+ data: T,
63
+ isFetching: k,
64
+ isFetched: W
65
+ } = a({
66
66
  queryKey: [
67
67
  "fetchAvailableRooms",
68
- (g = t.cashBookingOffers) == null ? void 0 : g.accommodationId,
69
- (b = e == null ? void 0 : e.checkinDate) == null ? void 0 : b.valueOf(),
70
- (v = e == null ? void 0 : e.checkoutDate) == null ? void 0 : v.valueOf(),
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(),
71
71
  o == null ? void 0 : o.guests,
72
72
  o == null ? void 0 : o.rooms
73
73
  ],
74
- queryFn: () => Z({
74
+ queryFn: () => X({
75
75
  hotel: t,
76
76
  checkinDate: e.checkinDate,
77
77
  checkoutDate: e.checkoutDate,
78
78
  guests: o.guests,
79
79
  rooms: o.rooms,
80
- updateHotel: u,
81
- numberOfNights: a
80
+ updateHotel: l,
81
+ numberOfNights: c
82
82
  }),
83
- enabled: !!e.checkinDate && !!e.checkoutDate && !!((F = t.cashBookingOffers) != null && F.accommodationId),
83
+ enabled: !!e.checkinDate && !!e.checkoutDate && !!((v = t.cashBookingOffers) != null && v.accommodationId),
84
84
  retry: !1,
85
85
  placeholderData: {
86
86
  cashHotelDetails: t,
87
87
  cashRooms: []
88
88
  }
89
- }), { cashRooms: W, cashHotelDetails: k } = x || {
89
+ }), { cashRooms: x, cashHotelDetails: n } = T || {
90
90
  cashHotelDetails: t,
91
91
  cashRooms: []
92
- }, {
93
- data: _,
94
- isFetching: z,
95
- isFetched: M
96
- } = c({
92
+ }, E = h(
93
+ () => A(t, i, n),
94
+ [t, i, n]
95
+ ), {
96
+ data: L,
97
+ isFetching: M,
98
+ isFetched: Q
99
+ } = a({
97
100
  queryKey: [
98
101
  "bestCheckout",
99
102
  t.hotelId,
100
103
  t.hotelGroup,
101
- (R = e == null ? void 0 : e.checkinDate) == null ? void 0 : R.valueOf(),
104
+ (F = e == null ? void 0 : e.checkinDate) == null ? void 0 : F.valueOf(),
102
105
  (H = e == null ? void 0 : e.checkoutDate) == null ? void 0 : H.valueOf(),
103
- h
106
+ f
104
107
  ],
105
- queryFn: () => ee(
106
- G(t, D, k),
107
- a,
108
- w,
109
- h
108
+ queryFn: () => Z(
109
+ E,
110
+ c,
111
+ f
110
112
  ),
111
- enabled: !t.hotelId.startsWith("duff_") && !l && (t.liveScrapingCheckNeeded ? E : !0) && !f && ((q = t.cashBookingOffers) != null && q.accommodationId ? L : !0) && a > 0 && t.points >= 0,
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,
112
114
  retry: !1,
113
115
  placeholderData: {
114
- bestCheckout: $(t, a),
116
+ bestCheckout: Y(t, c),
115
117
  isAvailable: !1
116
118
  }
117
- }), { bestCheckout: m, isAvailable: p } = _ || {
119
+ }), { bestCheckout: m, isAvailable: p } = L || {
118
120
  isAvailable: !1
119
- }, { data: Q } = c({
121
+ }, { data: U } = a({
120
122
  queryKey: [
121
123
  "pointsAsCash",
122
124
  t.hotelId,
123
125
  t.hotelGroup,
124
- (O = e == null ? void 0 : e.checkinDate) == null ? void 0 : O.valueOf(),
125
- (A = e == null ? void 0 : e.checkoutDate) == null ? void 0 : A.valueOf()
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()
126
128
  ],
127
- queryFn: () => se(m.totalCashCost),
128
- enabled: M && p,
129
+ queryFn: () => oe(m.totalCashCost),
130
+ enabled: Q && p,
129
131
  retry: !1
130
132
  });
131
133
  return {
132
- transferPartners: N || [],
133
- loadingTransferPartners: P,
134
+ transferPartners: w || [],
135
+ loadingTransferPartners: K,
134
136
  // Points Check
135
- pointsRooms: T || [],
136
- loadingLivePointsCheck: l,
137
+ pointsRooms: P || [],
138
+ loadingLivePointsCheck: D,
137
139
  // Cash Rooms
138
- cashRooms: W || [],
139
- loadingCashRooms: f,
140
+ cashRooms: x || [],
141
+ loadingCashRooms: k,
140
142
  // Best Checkout
141
143
  bestCheckout: m,
142
- loadingBestCheckout: z,
144
+ loadingBestCheckout: M,
143
145
  // Combined availability
144
146
  isAvailable: p,
145
147
  // Points as Cash
146
- pointsAsCash: Q,
147
- hotelDetails: G(
148
+ pointsAsCash: U,
149
+ hotelDetails: A(
148
150
  t,
149
- D,
150
- k
151
+ i,
152
+ n
151
153
  ),
152
- updateDates: K
154
+ updateDates: B
153
155
  };
154
156
  };
155
157
  export {
156
- ye as useHotelDetails
158
+ ke as useHotelDetails
157
159
  };
@@ -49,7 +49,7 @@ interface IFetchBestCheckoutResponse {
49
49
  bestCheckout: IBestCheckout | undefined;
50
50
  isAvailable: boolean;
51
51
  }
52
- export declare const fetchBestCheckout: (hotel: IHotelDetails, numberOfNights: number, userCurrency: string, qualifiesForAwardPoints: boolean) => Promise<IFetchBestCheckoutResponse>;
52
+ export declare const fetchBestCheckout: (hotel: IHotelDetails, numberOfNights: number, qualifiesForAwardPoints: boolean) => Promise<IFetchBestCheckoutResponse>;
53
53
  export declare const fallbackBestCheckout: (selectedHotelData: IHotelDetails, numberOfNights: number) => IBestCheckout;
54
54
  export declare const combineUpdatedHotelData: (base: IHotelDetails, liveScraperData: IHotelDetails, cashRoomsData: IHotelDetails) => IHotelDetails;
55
55
  export {};
@@ -120,6 +120,14 @@ export interface IBestCheckout {
120
120
  * `IBestCheckoutResponse.optimal_user_program_checkout.programs.is_transfer_program`
121
121
  */
122
122
  isTransferProgram: boolean;
123
+ /**
124
+ * ---
125
+ * ### The Program logo.
126
+ *
127
+ * Maps to:
128
+ * `IBestCheckoutResponse.optimal_user_program_checkout.programs.logo`
129
+ */
130
+ logo?: string;
123
131
  }[];
124
132
  };
125
133
  /**
@@ -16,7 +16,10 @@ declare class _HotelService {
16
16
  data: null;
17
17
  message: string;
18
18
  }>;
19
- getRecommendations: (args: any) => Promise<{
19
+ getRecommendations: ({ hotel, days }: {
20
+ hotel: IHotelDetails;
21
+ days: number;
22
+ }) => Promise<{
20
23
  success: boolean;
21
24
  data: IBestCheckout;
22
25
  message?: undefined;
@@ -1,56 +1,55 @@
1
- var f = Object.defineProperty;
2
- var C = (i, s, e) => s in i ? f(i, s, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[s] = e;
3
- var n = (i, s, e) => C(i, typeof s != "symbol" ? s + "" : s, e);
4
- import { clientInstance as l } from "@odynn/awayz-core";
5
- import { s as E } from "../../stringUtils-DFhHh7H1.js";
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";
6
6
  import "../../moment-BGjjqtLQ.js";
7
7
  import "../../arrayExtensions-CFEBYUok.js";
8
- import { c as m } from "../../objectUtils-DOsrxUF7.js";
8
+ import { c as _ } from "../../objectUtils-DOsrxUF7.js";
9
9
  import { E as h } from "../../DateFormats-DZD30Nea.js";
10
10
  import "react";
11
- import { EHotelEndpoints as _ } from "../../configs/endpoints.js";
12
- import { EBestCheckoutType as d } from "../../enums/EBestCheckoutType.js";
11
+ import { EHotelEndpoints as l } from "../../configs/endpoints.js";
12
+ import { EBestCheckoutType as p } from "../../enums/EBestCheckoutType.js";
13
13
  import { EBestValueType as T } from "../../enums/EBestValueType.js";
14
- import { BestCheckoutHelper as v } from "./BestCheckoutHelper.js";
15
- import { ESearchType as H } from "./HotelService.types.js";
16
- class P {
14
+ import { ESearchType as P } from "./HotelService.types.js";
15
+ class S {
17
16
  constructor() {
18
- n(this, "getLocations", async (s) => {
17
+ c(this, "getLocations", async (a) => {
19
18
  try {
20
- const { data: e } = await l.get(
21
- _.GET_LOCATIONS,
19
+ const { data: s } = await u.get(
20
+ l.GET_LOCATIONS,
22
21
  {
23
22
  params: {
24
- search: E(s)
23
+ search: C(a)
25
24
  }
26
25
  }
27
26
  );
28
- if (!(e != null && e.success))
27
+ if (!(s != null && s.success))
29
28
  return {
30
29
  success: !1,
31
- message: (e == null ? void 0 : e.message) || "Error fetching location data"
30
+ message: (s == null ? void 0 : s.message) || "Error fetching location data"
32
31
  };
33
- const o = (a) => a.search_type === H.HOTEL;
32
+ const o = (e) => e.search_type === P.HOTEL;
34
33
  return {
35
34
  success: !0,
36
- data: e.data.cities.map(
37
- (a) => {
38
- const { search_id: c, search_type: p, description: r, coordinates: g, city: y } = a, u = {
39
- searchId: c,
40
- searchType: p,
41
- description: r,
35
+ data: s.data.cities.map(
36
+ (e) => {
37
+ const { search_id: m, search_type: r, description: d, coordinates: g, city: f } = e, i = {
38
+ searchId: m,
39
+ searchType: r,
40
+ description: d,
42
41
  coordinates: g,
43
- city: y
42
+ city: f
44
43
  };
45
- return o(a) ? (u.country = {
46
- code: a.country_code,
47
- name: a.country
48
- }, u.hotelChain = a.hotel_group, u.hotelName = a.hotel_name) : (u.country = a.country, u.state = a.state), u;
44
+ return o(e) ? (i.country = {
45
+ code: e.country_code,
46
+ name: e.country
47
+ }, i.hotelChain = e.hotel_group, i.hotelName = e.hotel_name) : (i.country = e.country, i.state = e.state), i;
49
48
  }
50
49
  )
51
50
  };
52
- } catch (e) {
53
- const o = e;
51
+ } catch (s) {
52
+ const o = s;
54
53
  return {
55
54
  success: !1,
56
55
  data: [],
@@ -58,17 +57,17 @@ class P {
58
57
  };
59
58
  }
60
59
  });
61
- n(this, "searchByCoords", async (s) => {
62
- var e, o;
60
+ c(this, "searchByCoords", async (a) => {
61
+ var s, o;
63
62
  try {
64
- const { data: t } = await l.post(_.SEARCH_HOTELS, {
65
- ...s,
63
+ const { data: t } = await u.post(l.SEARCH_HOTELS, {
64
+ ...a,
66
65
  use_duffel: !0
67
66
  });
68
67
  return t != null && t.success ? {
69
68
  success: !0,
70
- data: m(
71
- (e = t.data) == null ? void 0 : e.hotels
69
+ data: _(
70
+ (s = t.data) == null ? void 0 : s.hotels
72
71
  )
73
72
  } : {
74
73
  success: !1,
@@ -81,17 +80,17 @@ class P {
81
80
  };
82
81
  }
83
82
  });
84
- n(this, "searchByHotelId", async (s) => {
85
- var e, o;
83
+ c(this, "searchByHotelId", async (a) => {
84
+ var s, o;
86
85
  try {
87
- const { data: t } = await l.post(_.GET_HOTEL_DATA, {
88
- ...s,
86
+ const { data: t } = await u.post(l.GET_HOTEL_DATA, {
87
+ ...a,
89
88
  use_duffel: !0
90
89
  });
91
90
  return t != null && t.success ? {
92
91
  success: !0,
93
- data: m(
94
- (e = t.data) == null ? void 0 : e.hotels
92
+ data: _(
93
+ (s = t.data) == null ? void 0 : s.hotels
95
94
  )
96
95
  } : {
97
96
  success: !1,
@@ -104,83 +103,85 @@ class P {
104
103
  };
105
104
  }
106
105
  });
107
- n(this, "getTransferPartners", async (s) => {
106
+ c(this, "getTransferPartners", async (a) => {
108
107
  try {
109
- const { data: e } = await l.get(
110
- _.GET_TRANSFER_PARTNERS,
108
+ const { data: s } = await u.get(
109
+ l.GET_TRANSFER_PARTNERS,
111
110
  {
112
111
  params: {
113
- program: s
112
+ program: a
114
113
  }
115
114
  }
116
115
  );
117
- return m(e.data);
116
+ return _(s.data);
118
117
  } catch {
119
118
  return [];
120
119
  }
121
120
  });
122
- n(this, "hotelPointsCheck", async (s) => {
121
+ c(this, "hotelPointsCheck", async (a) => {
123
122
  var o;
124
- const e = {
125
- hotel_group: s.hotelGroup,
126
- hotel_id: s.hotelId,
127
- check_in_date: s.checkinDate.format(h.ServerDate),
128
- check_out_date: s.checkoutDate.format(h.ServerDate)
123
+ const s = {
124
+ hotel_group: a.hotelGroup,
125
+ hotel_id: a.hotelId,
126
+ check_in_date: a.checkinDate.format(h.ServerDate),
127
+ check_out_date: a.checkoutDate.format(h.ServerDate)
129
128
  };
130
129
  try {
131
- const { data: t } = await l.post(
132
- _.HOTEL_POINTS_CHECK,
133
- e
134
- ), a = ((o = t.data) == null ? void 0 : o.length) > 0 ? t.data[0] : null;
130
+ const { data: t } = await u.post(
131
+ l.HOTEL_POINTS_CHECK,
132
+ s
133
+ ), e = ((o = t.data) == null ? void 0 : o.length) > 0 ? t.data[0] : null;
135
134
  return {
136
135
  success: t.success,
137
- data: a == null ? null : m(a)
136
+ data: e == null ? null : _(e)
138
137
  };
139
138
  } catch (t) {
140
- const a = t;
139
+ const e = t;
141
140
  return {
142
141
  success: !1,
143
142
  data: null,
144
- message: (a == null ? void 0 : a.message) ?? "Error fetching hotel data"
143
+ message: (e == null ? void 0 : e.message) ?? "Error fetching hotel data"
145
144
  };
146
145
  }
147
146
  });
148
- n(this, "getRecommendations", async (s) => {
147
+ c(this, "getRecommendations", async ({
148
+ hotel: a,
149
+ days: s
150
+ }) => {
149
151
  try {
150
- const t = {
151
- hotels: (await new v(s.hotels).getConvertedHotels(
152
- s.userCurrency
153
- )).map((r) => ({
154
- hotel_id: r.hotelId,
155
- hotel_group: r.hotelGroup,
156
- cash_value: r.cashValue,
157
- currency: r.cashValue.currency,
158
- award_points: r.awardPoints,
159
- points: r.points
160
- })),
161
- days: s.days,
152
+ const o = {
153
+ hotels: [
154
+ {
155
+ hotel_id: a.hotelId,
156
+ hotel_group: a.hotelGroup,
157
+ cash_value: a.cashValue,
158
+ award_points: a.awardPoints,
159
+ points: a.points
160
+ }
161
+ ],
162
+ days: s,
162
163
  cash_or_points: ["cash", "points"]
163
- }, { data: a } = await l.post(
164
- _.GET_BEST_CHECKOUT,
165
- t
166
- ), c = a.data[0];
164
+ }, { data: t } = await u.post(
165
+ l.GET_BEST_CHECKOUT,
166
+ o
167
+ ), e = t.data[0];
167
168
  return {
168
169
  success: !0,
169
170
  data: {
170
- totalPointsCost: c.total_hotel_points_cost,
171
- nightlyPointsCost: c.points,
172
- totalCashCost: c.total_cash_cost,
173
- nightlyCashCost: c.cash_value.amount,
174
- currency: c.cash_value.currency,
175
- sufficientPoints: c.user_has_sufficient_points,
176
- awardPoints: c.award_points,
177
- rewardsProgram: c.hotel_rewards_program,
178
- valueCents: c.value_cents,
179
- bestCheckoutMethod: c.best_user_checkout_method === T.CASH ? d.CASH : d.POINTS,
171
+ totalPointsCost: e.total_hotel_points_cost,
172
+ nightlyPointsCost: e.points,
173
+ totalCashCost: e.total_cash_cost,
174
+ nightlyCashCost: e.cash_value.amount,
175
+ currency: e.cash_value.currency,
176
+ sufficientPoints: e.user_has_sufficient_points,
177
+ awardPoints: e.award_points,
178
+ rewardsProgram: e.hotel_rewards_program,
179
+ valueCents: e.value_cents,
180
+ bestCheckoutMethod: e.best_user_checkout_method === T.CASH ? p.CASH : p.POINTS,
180
181
  optimalProgram: {
181
- totalProgramPointsValuation: c.optimal_user_program_checkout.total_program_points_valuation,
182
- remainingPointsBalance: c.optimal_user_program_checkout.primary_offer_remaining_points_balance,
183
- programs: c.optimal_user_program_checkout.programs.map(
182
+ totalProgramPointsValuation: e.optimal_user_program_checkout.total_program_points_valuation,
183
+ remainingPointsBalance: e.optimal_user_program_checkout.primary_offer_remaining_points_balance,
184
+ programs: e.optimal_user_program_checkout.programs.map(
184
185
  (r) => ({
185
186
  convertedPoints: r.converted_program_points,
186
187
  program: r.program,
@@ -195,17 +196,17 @@ class P {
195
196
  }
196
197
  }
197
198
  };
198
- } catch (e) {
199
- const o = e;
199
+ } catch (o) {
200
+ const t = o;
200
201
  return {
201
202
  success: !1,
202
- message: o == null ? void 0 : o.message
203
+ message: t == null ? void 0 : t.message
203
204
  };
204
205
  }
205
206
  });
206
207
  }
207
208
  }
208
- const b = new P();
209
+ const L = new S();
209
210
  export {
210
- b as HotelService
211
+ L as HotelService
211
212
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@odynn/awayz-hotels",
3
3
  "private": false,
4
- "version": "0.5.9",
4
+ "version": "0.5.11",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"
@@ -1,12 +0,0 @@
1
- import { IHotelDetails } from '../../main';
2
- /**
3
- * The `BestCheckoutHelper` class handles hotel currency conversions for a list of hotels.
4
- * It filters hotels not in the user's currency, converts their amounts using a single API call
5
- * per unique currency, and returns all hotels with amounts in the user's currency.
6
- */
7
- export declare class BestCheckoutHelper {
8
- #private;
9
- constructor(hotels: IHotelDetails[]);
10
- getConvertedHotels: (userCurrency: string) => Promise<IHotelDetails[]>;
11
- private getRate;
12
- }
@@ -1,67 +0,0 @@
1
- var V = Object.defineProperty;
2
- var i = (t) => {
3
- throw TypeError(t);
4
- };
5
- var p = (t, r, e) => r in t ? V(t, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[r] = e;
6
- var u = (t, r, e) => p(t, typeof r != "symbol" ? r + "" : r, e), f = (t, r, e) => r.has(t) || i("Cannot " + e);
7
- var o = (t, r, e) => (f(t, r, "read from private field"), e ? e.call(t) : r.get(t)), h = (t, r, e) => r.has(t) ? i("Cannot add the same private member more than once") : r instanceof WeakSet ? r.add(t) : r.set(t, e), l = (t, r, e, c) => (f(t, r, "write to private field"), c ? c.call(t, e) : r.set(t, e), e);
8
- import { CurrencyService as v } from "@odynn/awayz-core";
9
- var s;
10
- class H {
11
- constructor(r) {
12
- h(this, s);
13
- u(this, "getConvertedHotels", async (r) => {
14
- if (o(this, s).length === 0)
15
- return [];
16
- const e = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map();
17
- o(this, s).forEach((a) => {
18
- if (!a.cashValue || !a.cashValue.currency || !a.cashValue.amount) {
19
- console.error(`Invalid hotel data for hotel ${a.hotelId || "unknown"}`);
20
- return;
21
- }
22
- const n = a.cashValue.currency;
23
- c.has(n) || c.set(n, []), c.get(n).push(a);
24
- });
25
- const y = Array.from(c.keys()).filter((a) => a !== r).map(async (a) => {
26
- try {
27
- const n = await this.getRate(a);
28
- e.set(a, n);
29
- } catch (n) {
30
- console.error(`Error fetching rate for ${a}:`, n), e.set(a, 1);
31
- }
32
- });
33
- return await Promise.all(y), o(this, s).map((a) => {
34
- if (!a.cashValue || !a.cashValue.currency || !a.cashValue.amount)
35
- return a;
36
- const n = a.cashValue.currency;
37
- if (n === r)
38
- return a;
39
- const m = e.get(n) || 1;
40
- return {
41
- ...a,
42
- cashValue: {
43
- amount: a.cashValue.amount * m,
44
- currency: r
45
- }
46
- };
47
- });
48
- });
49
- u(this, "getRate", async (r) => {
50
- try {
51
- const e = await v.convertCurrency({
52
- baseCurrency: r
53
- });
54
- return typeof e == "number" && e > 0 ? e : 1;
55
- } catch (e) {
56
- return console.error(`Error converting from ${r}:`, e), 1;
57
- }
58
- });
59
- if (!Array.isArray(r))
60
- throw new Error("Hotels must be an array");
61
- l(this, s, r);
62
- }
63
- }
64
- s = new WeakMap();
65
- export {
66
- H as BestCheckoutHelper
67
- };