@odynn/awayz-core 0.10.17 → 0.10.18

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,47 +1,43 @@
1
- import { jsxs as c } from "react/jsx-runtime";
2
- import { useQuery as p } from "@tanstack/react-query";
1
+ import { jsxs as u } from "react/jsx-runtime";
2
+ import { useQuery as c } from "@tanstack/react-query";
3
3
  import "../../arrayExtensions-DlcBOj5a.js";
4
- import { E as u } from "../../noRetryInstance-BpBfY3E5.js";
5
- import { useMemo as f } from "react";
4
+ import { c as p } from "../../numberUtils-B4wd-SGR.js";
5
+ import { E as f } from "../../noRetryInstance-BpBfY3E5.js";
6
+ import { useMemo as C } from "react";
6
7
  import { useAwayzContext as l } from "../../hooks/useAwayzContext.js";
7
8
  import "react-i18next";
8
9
  import '../../assets/_styles4.css';import '../../assets/_styles6.css';import '../../assets/_styles5.css';import '../../assets/_styles2.css';import '../../assets/_styles.css';import '../../assets/_styles3.css';/* empty css */
9
10
  /* empty css */
10
11
  /* empty css */
11
- import { CurrencyService as C } from "../../services/currency/CurrencyService.js";
12
+ import { CurrencyService as y } from "../../services/currency/CurrencyService.js";
12
13
  /* empty css */
13
14
  /* empty css */
14
15
  import "../../index-Cv-wvFlM.js";
15
16
  /* empty css */
16
17
  import "../../configs/awayzClient.js";
17
18
  import "../../context/AwayzContext.js";
18
- import { getCurrency as y } from "../../utils/currency.js";
19
- import { useFeatureFlags as d } from "../../hooks/useFeatureFlags.js";
20
- import { useWallet as v } from "../../hooks/useWallet/useWallet.js";
21
- function g(e, r = !0) {
22
- if ((!e || isNaN(e) || e < 0) && r) return "N/A";
23
- let t = e == null ? void 0 : e.toString().split(".")[0];
24
- return t == null ? void 0 : t.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
25
- }
19
+ import { getCurrency as d } from "../../utils/currency.js";
20
+ import { useFeatureFlags as v } from "../../hooks/useFeatureFlags.js";
21
+ import { useWallet as R } from "../../hooks/useWallet/useWallet.js";
26
22
  const Y = ({
27
- cashAmount: e,
28
- currency: r
23
+ cashAmount: m,
24
+ currency: e
29
25
  }) => {
30
- const { pointsAsCash: t } = v(), { user: o } = l(), { featureFlags: s } = d(), i = f(
31
- () => y(s.defaultCurrencyFeature, o),
32
- [o]
33
- ), { data: n } = p({
34
- queryKey: [u.CONVERT_CURRENCY, r, t.currency],
35
- queryFn: () => C.convertCurrency({
36
- baseCurrency: r,
37
- targetCurrency: t.currency
26
+ const { pointsAsCash: r } = R(), { user: t } = l(), { featureFlags: n } = v(), o = C(
27
+ () => d(n.defaultCurrencyFeature, t),
28
+ [t]
29
+ ), { data: s } = c({
30
+ queryKey: [f.CONVERT_CURRENCY, e, r.currency],
31
+ queryFn: () => y.convertCurrency({
32
+ baseCurrency: e,
33
+ targetCurrency: r.currency
38
34
  }),
39
35
  staleTime: 1e3 * 60 * 60,
40
36
  // 1 hour
41
- enabled: !!r && !!i && r !== i && t.currency !== r && !!t.currency
42
- }), a = e * (n ?? 1), m = Math.round(a / t.valuePerPoint);
43
- return /* @__PURE__ */ c("p", { className: "client-points-amount", children: [
44
- g(m),
37
+ enabled: !!e && !!o && e !== o && r.currency !== e && !!r.currency
38
+ }), i = m * (s ?? 1), a = Math.round(i / r.valuePerPoint);
39
+ return /* @__PURE__ */ u("p", { className: "client-points-amount", children: [
40
+ p(a),
45
41
  " pts."
46
42
  ] });
47
43
  };
@@ -1,58 +1,61 @@
1
1
  import { useQuery as g, useMutation as u } from "@tanstack/react-query";
2
2
  import "../../arrayExtensions-DlcBOj5a.js";
3
3
  import { E as s } from "../../noRetryInstance-BpBfY3E5.js";
4
- import { useState as M } from "react";
4
+ import { useState as x } from "react";
5
5
  import "react/jsx-runtime";
6
6
  import "react-i18next";
7
7
  import '../../assets/_styles4.css';import '../../assets/_styles6.css';import '../../assets/_styles5.css';import '../../assets/_styles2.css';import '../../assets/_styles.css';import '../../assets/_styles3.css';/* empty css */
8
8
  /* empty css */
9
9
  /* empty css */
10
- import { awayzClient as x } from "../../configs/awayzClient.js";
10
+ import { awayzClient as z } from "../../configs/awayzClient.js";
11
11
  /* empty css */
12
12
  /* empty css */
13
13
  import "../../index-Cv-wvFlM.js";
14
14
  import "../../context/AwayzContext.js";
15
- import { EBookingType as i } from "../../services/trips/TripService.types.js";
15
+ import { EBookingType as t } from "../../services/trips/TripService.types.js";
16
16
  import { ECancelStatus as e } from "./useBookingManagement.types.js";
17
17
  /* empty css */
18
18
  import { BookingService as o } from "../../services/bookings/BookingService.js";
19
- const cr = (r, n) => {
19
+ const lr = (r, i) => {
20
20
  const {
21
21
  data: E,
22
22
  isError: L,
23
23
  error: O
24
24
  } = g({
25
- queryKey: [s.BOOKING, r, i.HOTEL],
25
+ queryKey: [s.BOOKING, r, t.HOTEL],
26
26
  queryFn: () => o.getHotelBooking(r),
27
- enabled: n === i.HOTEL && !!r
27
+ enabled: i === t.HOTEL && !!r
28
28
  }), {
29
- data: t,
29
+ data: n,
30
30
  isError: A,
31
- error: N
31
+ error: d
32
32
  } = g({
33
- queryKey: [s.BOOKING, r, i.FLIGHT],
33
+ queryKey: [s.BOOKING, r, t.FLIGHT],
34
34
  queryFn: () => o.getFlightBooking(r),
35
- enabled: n === i.FLIGHT && !!r
36
- }), [C, a] = M(e.IDLE), d = () => a(e.IDLE), { data: m, isLoading: H } = g({
35
+ enabled: i === t.FLIGHT && !!r
36
+ }), [C, a] = x(
37
+ e.IDLE
38
+ ), N = () => a(e.IDLE), { data: m, isLoading: H } = g({
37
39
  queryKey: [s.BOOKING, r],
38
40
  queryFn: () => o.getPointsAsCash(r),
39
41
  enabled: !!r
40
42
  }), {
41
- mutate: P,
42
- isPending: G,
43
- isError: I,
44
- error: y,
45
- isSuccess: w
43
+ data: P,
44
+ mutate: G,
45
+ isPending: I,
46
+ isError: y,
47
+ error: w,
48
+ isSuccess: K
46
49
  } = u({
47
50
  mutationFn: async () => {
48
- if (n === i.FLIGHT)
51
+ if (i === t.FLIGHT)
49
52
  return o.initiateCancelFlightBooking(r);
50
53
  throw m ? new Error("Not supported for bookings made with Points as Cash") : new Error("Not supported for hotel bookings");
51
54
  }
52
55
  }), {
53
56
  mutate: B,
54
57
  isPending: S,
55
- error: K
58
+ error: D
56
59
  } = u({
57
60
  mutationFn: async (c) => o.cancelPointsBooking(c),
58
61
  onSuccess: () => {
@@ -67,9 +70,9 @@ const cr = (r, n) => {
67
70
  error: q
68
71
  } = u({
69
72
  mutationFn: async () => {
70
- if (n === i.FLIGHT)
73
+ if (i === t.FLIGHT)
71
74
  return await o.confirmCancelFlightBooking(r);
72
- if (n === i.HOTEL)
75
+ if (i === t.HOTEL)
73
76
  return await o.cancelHotelBooking(r);
74
77
  },
75
78
  onMutate: () => {
@@ -77,9 +80,9 @@ const cr = (r, n) => {
77
80
  },
78
81
  onSuccess: () => {
79
82
  if (m) {
80
- if (n === i.FLIGHT && t)
81
- return B(t.id);
82
- if (n === i.HOTEL && E)
83
+ if (i === t.FLIGHT && n)
84
+ return B(n.id);
85
+ if (i === t.HOTEL && E)
83
86
  return B(E.id);
84
87
  } else
85
88
  l(), a(e.SUCCESS);
@@ -88,17 +91,17 @@ const cr = (r, n) => {
88
91
  a(e.CANCEL_FAILED);
89
92
  }
90
93
  }), {
91
- mutate: D,
92
- isPending: U,
93
- isError: _,
94
- error: v
94
+ mutate: U,
95
+ isPending: _,
96
+ isError: v,
97
+ error: Q
95
98
  } = u({
96
99
  mutationFn: async (c) => {
97
100
  var F, f;
98
- const p = (f = (F = t == null ? void 0 : t.airlineInitiatedChanges) == null ? void 0 : F.filter(
99
- (k) => !k.actionTaken
101
+ const p = (f = (F = n == null ? void 0 : n.airlineInitiatedChanges) == null ? void 0 : F.filter(
102
+ (M) => !M.actionTaken
100
103
  )) == null ? void 0 : f[0];
101
- if (n === i.FLIGHT && (t != null && t.airlineInitiatedChanges) && p)
104
+ if (i === t.FLIGHT && (n != null && n.airlineInitiatedChanges) && p)
102
105
  return o.actionAirlineChanges({
103
106
  bookingId: r,
104
107
  acceptChanges: c,
@@ -115,36 +118,37 @@ const cr = (r, n) => {
115
118
  [s.TRIPS],
116
119
  [s.UNCATEGORISED_BOOKINGS]
117
120
  ].forEach((c) => {
118
- x.invalidateQueries({ queryKey: c });
121
+ z.invalidateQueries({ queryKey: c });
119
122
  });
120
- }, Q = L || A, R = O || N;
123
+ }, R = L || A, k = O || d;
121
124
  return {
122
- details: n === i.HOTEL ? E : t,
123
- isError: Q,
124
- error: R,
125
- initiateCancellation: P,
126
- isInitiatingCancellation: G,
127
- isInitiateCancellationError: I,
128
- initiateCancellationError: y,
129
- isInitiateCancellationSuccess: w,
125
+ details: i === t.HOTEL ? E : n,
126
+ isError: R,
127
+ error: k,
128
+ initiateCancellation: G,
129
+ isInitiatingCancellation: I,
130
+ isInitiateCancellationError: y,
131
+ initiateCancellationError: w,
132
+ isInitiateCancellationSuccess: K,
133
+ initiateCancellationData: P,
130
134
  cancelBooking: T,
131
135
  cancelStatus: C,
132
- resetCancelStatus: d,
136
+ resetCancelStatus: N,
133
137
  cancelBookingError: q,
134
- pointsRefundError: K,
138
+ pointsRefundError: D,
135
139
  isCancellingBooking: h || S,
136
140
  // Deprecated – remove once awayz-tenant has migrated to cancelStatus
137
141
  isCancelingBooking: h || S,
138
142
  isCancelBookingSuccess: C === e.SUCCESS,
139
143
  isCancelBookingError: C === e.CANCEL_FAILED,
140
- actionAirlineChanges: D,
141
- isActionAirlineChangesPending: U,
142
- isActionAirlineChangesError: _,
143
- actionAirlineChangesError: v,
144
+ actionAirlineChanges: U,
145
+ isActionAirlineChangesPending: _,
146
+ isActionAirlineChangesError: v,
147
+ actionAirlineChangesError: Q,
144
148
  pointsAsCashDetails: m,
145
149
  isLoadingPointsAsCash: H
146
150
  };
147
151
  };
148
152
  export {
149
- cr as useBookingManagement
153
+ lr as useBookingManagement
150
154
  };
@@ -1,4 +1,4 @@
1
- import { IFlightBookingDetails, IHotelBookingDetails, IPointsAsCash } from '../../services/bookings/BookingService.types';
1
+ import { IFlightBookingDetails, IHotelBookingDetails, IInitiateFlightCancellationData, IPointsAsCash } from '../../services/bookings/BookingService.types';
2
2
  export declare enum ECancelStatus {
3
3
  IDLE = "idle",
4
4
  PENDING = "pending",
@@ -41,6 +41,10 @@ export interface IUseBookingManagement {
41
41
  * The error object if there was an error while initiating the cancellation
42
42
  */
43
43
  initiateCancellationError: Error | null;
44
+ /**
45
+ * Refund information for flight booking cancellation
46
+ * */
47
+ initiateCancellationData?: IInitiateFlightCancellationData;
44
48
  /**
45
49
  * Function to cancel the booking
46
50
  * This can be used for both flight and hotel bookings
@@ -2,7 +2,17 @@ import { IActionAirlineChangesRequest, IFlightBookingDetails, IHotelBookingDetai
2
2
  declare class _BookingService {
3
3
  getHotelBooking: (bookingId: string) => Promise<IHotelBookingDetails>;
4
4
  getFlightBooking: (bookingId: string) => Promise<IFlightBookingDetails>;
5
- initiateCancelFlightBooking: (bookingId: string) => Promise<any>;
5
+ initiateCancelFlightBooking: (bookingId: string) => Promise<{
6
+ refundAmount: number;
7
+ refundTo: string;
8
+ refundCurrency: string;
9
+ confirmedAt: string;
10
+ orderId: string;
11
+ liveMode: boolean;
12
+ createdAt: string;
13
+ expiresAt: string;
14
+ id: string;
15
+ }>;
6
16
  confirmCancelFlightBooking: (bookingId: string) => Promise<any>;
7
17
  cancelHotelBooking: (bookingId: string) => Promise<any>;
8
18
  actionAirlineChanges: ({ bookingId, acceptChanges, aicId }: IActionAirlineChangesRequest) => Promise<any>;
@@ -174,3 +174,14 @@ export interface IFlightServiceMetadata {
174
174
  type: string;
175
175
  maximumWeightKg: number;
176
176
  }
177
+ export interface IInitiateFlightCancellationData {
178
+ refundTo: string;
179
+ refundCurrency: string;
180
+ refundAmount: number;
181
+ confirmedAt: string;
182
+ orderId: string;
183
+ liveMode: boolean;
184
+ createdAt: string;
185
+ expiresAt: string;
186
+ id: string;
187
+ }
@@ -0,0 +1,19 @@
1
+ function e(t, r = !0) {
2
+ if ((!t || isNaN(t) || t < 0) && r) return "N/A";
3
+ let i = t == null ? void 0 : t.toString().split(".")[0];
4
+ return i == null ? void 0 : i.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
5
+ }
6
+ const n = (t, r = 0) => {
7
+ if (t == null) return r;
8
+ if (typeof t == "number")
9
+ return Number.isFinite(t) ? t : r;
10
+ if (typeof t == "string") {
11
+ const i = Number(t);
12
+ return Number.isFinite(i) ? i : r;
13
+ }
14
+ return r;
15
+ };
16
+ export {
17
+ e as c,
18
+ n as t
19
+ };
@@ -1,21 +1,22 @@
1
1
  var g = Object.defineProperty;
2
- var f = (c, t, a) => t in c ? g(c, t, { enumerable: !0, configurable: !0, writable: !0, value: a }) : c[t] = a;
3
- var r = (c, t, a) => f(c, typeof t != "symbol" ? t + "" : t, a);
2
+ var f = (r, t, a) => t in r ? g(r, t, { enumerable: !0, configurable: !0, writable: !0, value: a }) : r[t] = a;
3
+ var c = (r, t, a) => f(r, typeof t != "symbol" ? t + "" : t, a);
4
4
  import "../../arrayExtensions-DlcBOj5a.js";
5
- import { c as l, b as m, g as p } from "../../noRetryInstance-BpBfY3E5.js";
5
+ import { t as y } from "../../numberUtils-B4wd-SGR.js";
6
+ import { c as l, b as u, g as p } from "../../noRetryInstance-BpBfY3E5.js";
6
7
  import "react";
7
8
  import { EBookingEndpoints as i } from "../../configs/endpoints.js";
8
- const y = (c) => {
9
- const t = /P((\d+)D)?T((\d+)H)?((\d+)M)?/, a = c.match(t);
9
+ const h = (r) => {
10
+ const t = /P((\d+)D)?T((\d+)H)?((\d+)M)?/, a = r.match(t);
10
11
  if (a) {
11
12
  const n = a[2] ? `${a[2]}d ` : "", d = a[4] ? `${a[4]}h ` : "", s = a[6] ? `${a[6]}m` : "";
12
13
  return `${n}${d}${s}`.trim();
13
14
  } else
14
- return c;
15
+ return r;
15
16
  };
16
- class h {
17
+ class b {
17
18
  constructor() {
18
- r(this, "getHotelBooking", async (t) => {
19
+ c(this, "getHotelBooking", async (t) => {
19
20
  var s, e;
20
21
  const { data: a } = await l.get(
21
22
  `${i.USER_HOTEL_BOOKINGS}/${t}`
@@ -55,11 +56,11 @@ class h {
55
56
  },
56
57
  images: a.data.accommodation.photos.map((o) => o.url),
57
58
  guests: a.data.guests.map((o, _) => {
58
- var u;
59
+ var m;
59
60
  return {
60
61
  familyName: o.family_name,
61
62
  givenName: o.given_name,
62
- type: (u = a.data.guest_types[_]) == null ? void 0 : u.type
63
+ type: (m = a.data.guest_types[_]) == null ? void 0 : m.type
63
64
  };
64
65
  }),
65
66
  numberOfRooms: (s = a.data.rooms) == null ? void 0 : s.length,
@@ -73,9 +74,9 @@ class h {
73
74
  rooms: (e = a.data.rooms) == null ? void 0 : e.map((o) => {
74
75
  var _;
75
76
  return {
76
- beds: (_ = o.beds) == null ? void 0 : _.map((u) => ({
77
- type: u.type,
78
- count: u.count
77
+ beds: (_ = o.beds) == null ? void 0 : _.map((m) => ({
78
+ type: m.type,
79
+ count: m.count
79
80
  })),
80
81
  totalAmount: parseFloat(o.total_amount),
81
82
  name: o.name
@@ -84,7 +85,7 @@ class h {
84
85
  createdAt: a.data.created_at
85
86
  };
86
87
  });
87
- r(this, "getFlightBooking", async (t) => {
88
+ c(this, "getFlightBooking", async (t) => {
88
89
  var d, s;
89
90
  const { data: a } = await l.get(
90
91
  `${i.USER_FLIGHT_BOOKINGS}/${t}`
@@ -137,13 +138,13 @@ class h {
137
138
  arrivingAt: e.segments.getLast().arriving_at,
138
139
  numberOfStops: e.segments.length - 1,
139
140
  reference: a.data.booking_reference,
140
- durationInMinutes: y(e.duration),
141
- origin: m(e.origin),
142
- destination: m(e.destination),
143
- segments: m(e.segments)
141
+ durationInMinutes: h(e.duration),
142
+ origin: u(e.origin),
143
+ destination: u(e.destination),
144
+ segments: u(e.segments)
144
145
  })),
145
146
  availableActions: a.data.available_actions,
146
- airlineInitiatedChanges: m(a.data.airline_initiated_changes) || [],
147
+ airlineInitiatedChanges: u(a.data.airline_initiated_changes) || [],
147
148
  cancellationDetails: a.data.cancellation_details ? {
148
149
  refundAmount: parseFloat(
149
150
  a.data.cancellation_details.refund_amount
@@ -152,28 +153,34 @@ class h {
152
153
  refundTo: a.data.cancellation_details.refund_to,
153
154
  confirmedAt: a.data.cancellation_details.confirmed_at
154
155
  } : void 0,
155
- services: m(a.data.services)
156
+ services: u(a.data.services)
156
157
  };
157
158
  });
158
- r(this, "initiateCancelFlightBooking", async (t) => {
159
+ c(this, "initiateCancelFlightBooking", async (t) => {
159
160
  const { data: a } = await l.put(
160
161
  `${i.INITIATE_FLIGHT_CANCEL}/${t}`
161
162
  );
162
- return a.success;
163
+ if (!a.success)
164
+ throw new Error("Failed to initiate cancellation");
165
+ const n = u(a.data);
166
+ return {
167
+ ...n,
168
+ refundAmount: y(n.refundAmount)
169
+ };
163
170
  });
164
- r(this, "confirmCancelFlightBooking", async (t) => {
171
+ c(this, "confirmCancelFlightBooking", async (t) => {
165
172
  const { data: a } = await l.put(
166
173
  `${i.CONFIRM_FLIGHT_CANCEL}/${t}`
167
174
  );
168
175
  return a.success;
169
176
  });
170
- r(this, "cancelHotelBooking", async (t) => {
177
+ c(this, "cancelHotelBooking", async (t) => {
171
178
  const { data: a } = await l.post(
172
179
  `${i.CANCEL_HOTEL_BOOKING}/${t}`
173
180
  );
174
181
  return a.success;
175
182
  });
176
- r(this, "actionAirlineChanges", async ({
183
+ c(this, "actionAirlineChanges", async ({
177
184
  bookingId: t,
178
185
  acceptChanges: a,
179
186
  aicId: n
@@ -188,7 +195,7 @@ class h {
188
195
  );
189
196
  return d.success;
190
197
  });
191
- r(this, "cancelPointsBooking", async (t) => {
198
+ c(this, "cancelPointsBooking", async (t) => {
192
199
  const { data: a } = await p.post(
193
200
  `${i.REFUND_POINTS_BOOKING}`,
194
201
  {
@@ -197,7 +204,7 @@ class h {
197
204
  );
198
205
  return a.success;
199
206
  });
200
- r(this, "getPointsAsCash", async (t) => {
207
+ c(this, "getPointsAsCash", async (t) => {
201
208
  const { data: a } = await p.get(
202
209
  `${i.BOOKING_POINTS_AS_CASH}/${t}`
203
210
  );
@@ -208,7 +215,7 @@ class h {
208
215
  });
209
216
  }
210
217
  }
211
- const N = new h();
218
+ const O = new b();
212
219
  export {
213
- N as BookingService
220
+ O as BookingService
214
221
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@odynn/awayz-core",
3
- "version": "0.10.17",
3
+ "version": "0.10.18",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"