@odynn/awayz-core 0.9.7 → 0.9.8

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,6 +1,6 @@
1
1
  import { useQuery as u, useMutation as m } from "@tanstack/react-query";
2
2
  import "../../arrayExtensions-DlcBOj5a.js";
3
- import { E as a } from "../../noRetryInstance-oiHCni_Z.js";
3
+ import { E as o } from "../../noRetryInstance-oiHCni_Z.js";
4
4
  import "react";
5
5
  import "react/jsx-runtime";
6
6
  import "react-i18next";
@@ -10,41 +10,41 @@ import "../../_styles.flight-booking-DEUJthTJ.js";
10
10
  import { awayzClient as k } from "../../configs/awayzClient.js";
11
11
  /* empty css */
12
12
  import "../../context/AwayzContext.js";
13
- import { EBookingType as o } from "../../services/trips/TripService.types.js";
13
+ import { EBookingType as n } from "../../services/trips/TripService.types.js";
14
14
  /* empty css */
15
15
  import { BookingService as e } from "../../services/bookings/BookingService.js";
16
16
  const b = (r, t) => {
17
17
  const {
18
18
  data: s,
19
- isError: g,
20
- error: d
19
+ isError: B,
20
+ error: p
21
21
  } = u({
22
- queryKey: [a.BOOKING, r, o.HOTEL],
22
+ queryKey: [o.BOOKING, r, n.HOTEL],
23
23
  queryFn: () => e.getHotelBooking(r),
24
- enabled: t === o.HOTEL && !!r
24
+ enabled: t === n.HOTEL && !!r
25
25
  }), {
26
- data: n,
27
- isError: B,
28
- error: f
26
+ data: i,
27
+ isError: f,
28
+ error: F
29
29
  } = u({
30
- queryKey: [a.BOOKING, r, o.FLIGHT],
30
+ queryKey: [o.BOOKING, r, n.FLIGHT],
31
31
  queryFn: () => e.getFlightBooking(r),
32
- enabled: t === o.FLIGHT && !!r
33
- }), { data: i, isLoading: F } = u({
34
- queryKey: [a.BOOKING, r],
32
+ enabled: t === n.FLIGHT && !!r
33
+ }), { data: a, isLoading: O } = u({
34
+ queryKey: [o.BOOKING, r],
35
35
  queryFn: () => e.getPointsAsCash(r),
36
36
  enabled: !!r
37
37
  }), {
38
- mutate: O,
39
- isPending: A,
40
- isError: y,
41
- error: H,
42
- isSuccess: L
38
+ mutate: d,
39
+ isPending: y,
40
+ isError: H,
41
+ error: A,
42
+ isSuccess: G
43
43
  } = m({
44
44
  mutationFn: async () => {
45
- if (i)
45
+ if (a)
46
46
  throw new Error("Not supported for bookings made with Points as Cash");
47
- if (t === o.FLIGHT)
47
+ if (t === n.FLIGHT)
48
48
  return e.initiateCancelFlightBooking(r);
49
49
  throw new Error("Not supported for hotel bookings");
50
50
  },
@@ -52,51 +52,37 @@ const b = (r, t) => {
52
52
  c();
53
53
  }
54
54
  }), {
55
- mutate: G,
56
- isPending: C,
55
+ mutate: L,
56
+ isPending: E,
57
57
  isError: S,
58
58
  error: w,
59
- isSuccess: I
59
+ isSuccess: K
60
60
  } = m({
61
61
  mutationFn: async () => {
62
- if (t === o.FLIGHT)
63
- return i && n && await e.cancelPointsBooking({
64
- confirmationCode: i.confirmationCode,
65
- orderId: n.orderId,
66
- provider: i.provider,
67
- type: o.FLIGHT,
68
- pointsAmount: i.points,
69
- cashAmount: i.cashValue.amount
70
- }), e.confirmCancelFlightBooking(r);
71
- if (t === o.HOTEL)
72
- return i && s && await e.cancelPointsBooking({
73
- confirmationCode: i.confirmationCode,
74
- orderId: s.bookingId,
75
- provider: i.provider,
76
- type: o.HOTEL,
77
- pointsAmount: i.points,
78
- cashAmount: i.cashValue.amount
79
- }), e.cancelHotelBooking(r);
62
+ if (t === n.FLIGHT)
63
+ return a && i && await e.cancelPointsBooking(i.id), e.confirmCancelFlightBooking(r);
64
+ if (t === n.HOTEL)
65
+ return a && s && await e.cancelPointsBooking(s.id), e.cancelHotelBooking(r);
80
66
  },
81
67
  onSuccess: () => {
82
68
  c();
83
69
  }
84
70
  }), {
85
- mutate: K,
86
- isPending: P,
87
- isError: N,
88
- error: v
71
+ mutate: P,
72
+ isPending: N,
73
+ isError: q,
74
+ error: T
89
75
  } = m({
90
76
  mutationFn: async (l) => {
91
- var h, p;
92
- const E = (p = (h = n == null ? void 0 : n.airlineInitiatedChanges) == null ? void 0 : h.filter(
77
+ var g, h;
78
+ const C = (h = (g = i == null ? void 0 : i.airlineInitiatedChanges) == null ? void 0 : g.filter(
93
79
  (Q) => !Q.actionTaken
94
- )) == null ? void 0 : p[0];
95
- if (t === o.FLIGHT && (n != null && n.airlineInitiatedChanges) && E)
80
+ )) == null ? void 0 : h[0];
81
+ if (t === n.FLIGHT && (i != null && i.airlineInitiatedChanges) && C)
96
82
  return e.actionAirlineChanges({
97
83
  bookingId: r,
98
84
  acceptChanges: l,
99
- aicId: E.id
85
+ aicId: C.id
100
86
  });
101
87
  throw new Error("Not supported for hotel bookings");
102
88
  },
@@ -105,34 +91,34 @@ const b = (r, t) => {
105
91
  }
106
92
  }), c = () => {
107
93
  [
108
- [a.BOOKING, r, t],
109
- [a.TRIPS],
110
- [a.UNCATEGORISED_BOOKINGS]
94
+ [o.BOOKING, r, t],
95
+ [o.TRIPS],
96
+ [o.UNCATEGORISED_BOOKINGS]
111
97
  ].forEach((l) => {
112
98
  k.invalidateQueries({ queryKey: l });
113
99
  });
114
- }, T = g || B, q = d || f;
100
+ }, I = B || f, v = p || F;
115
101
  return {
116
- details: t === o.HOTEL ? s : n,
117
- isError: T,
118
- error: q,
119
- initiateCancellation: O,
120
- isInitiatingCancellation: A,
121
- isInitiateCancellationError: y,
122
- initiateCancellationError: H,
123
- isInitiateCancellationSuccess: L,
124
- cancelBooking: G,
125
- isCancellingBooking: C,
126
- isCancelingBooking: C,
102
+ details: t === n.HOTEL ? s : i,
103
+ isError: I,
104
+ error: v,
105
+ initiateCancellation: d,
106
+ isInitiatingCancellation: y,
107
+ isInitiateCancellationError: H,
108
+ initiateCancellationError: A,
109
+ isInitiateCancellationSuccess: G,
110
+ cancelBooking: L,
111
+ isCancellingBooking: E,
112
+ isCancelingBooking: E,
127
113
  isCancelBookingError: S,
128
114
  cancelBookingError: w,
129
- isCancelBookingSuccess: I,
130
- actionAirlineChanges: K,
131
- isActionAirlineChangesPending: P,
132
- isActionAirlineChangesError: N,
133
- actionAirlineChangesError: v,
134
- pointsAsCashDetails: i,
135
- isLoadingPointsAsCash: F
115
+ isCancelBookingSuccess: K,
116
+ actionAirlineChanges: P,
117
+ isActionAirlineChangesPending: N,
118
+ isActionAirlineChangesError: q,
119
+ actionAirlineChangesError: T,
120
+ pointsAsCashDetails: a,
121
+ isLoadingPointsAsCash: O
136
122
  };
137
123
  };
138
124
  export {
@@ -1,4 +1,4 @@
1
- import { IActionAirlineChangesRequest, ICancelPointsBookingArgs, IFlightBookingDetails, IHotelBookingDetails, IPointsAsCash } from './BookingService.types';
1
+ import { IActionAirlineChangesRequest, IFlightBookingDetails, IHotelBookingDetails, IPointsAsCash } from './BookingService.types';
2
2
  declare class _BookingService {
3
3
  getHotelBooking: (bookingId: string) => Promise<IHotelBookingDetails>;
4
4
  getFlightBooking: (bookingId: string) => Promise<IFlightBookingDetails>;
@@ -6,7 +6,7 @@ declare class _BookingService {
6
6
  confirmCancelFlightBooking: (bookingId: string) => Promise<any>;
7
7
  cancelHotelBooking: (bookingId: string) => Promise<any>;
8
8
  actionAirlineChanges: ({ bookingId, acceptChanges, aicId }: IActionAirlineChangesRequest) => Promise<any>;
9
- cancelPointsBooking: (args: ICancelPointsBookingArgs) => Promise<any>;
9
+ cancelPointsBooking: (bookingId: string) => Promise<any>;
10
10
  getPointsAsCash: (bookingId: string) => Promise<IPointsAsCash>;
11
11
  }
12
12
  export declare const BookingService: _BookingService;
@@ -1,5 +1,4 @@
1
1
  import { IAirport, ICoordinates, ISlice } from '@type-op/shared';
2
- import { EBookingType } from '../trips/TripService.types';
3
2
  export interface IGuest {
4
3
  familyName: string;
5
4
  givenName: string;
@@ -134,11 +133,3 @@ export interface IAirlineInitiatedChanges {
134
133
  added: ISlice[];
135
134
  removed: ISlice[];
136
135
  }
137
- export interface ICancelPointsBookingArgs {
138
- confirmationCode: string;
139
- orderId: string;
140
- provider: string;
141
- type: EBookingType;
142
- pointsAmount: number;
143
- cashAmount: number;
144
- }
@@ -1,24 +1,24 @@
1
1
  var g = Object.defineProperty;
2
2
  var y = (r, t, a) => t in r ? g(r, t, { enumerable: !0, configurable: !0, writable: !0, value: a }) : r[t] = a;
3
- var i = (r, t, a) => y(r, typeof t != "symbol" ? t + "" : t, a);
3
+ var c = (r, t, a) => y(r, typeof t != "symbol" ? t + "" : t, a);
4
4
  import "../../arrayExtensions-DlcBOj5a.js";
5
- import { c as d, b as l, g as p } from "../../noRetryInstance-oiHCni_Z.js";
5
+ import { c as d, b as u, g as p } from "../../noRetryInstance-oiHCni_Z.js";
6
6
  import "react";
7
- import { EBookingEndpoints as c } from "../../configs/endpoints.js";
7
+ import { EBookingEndpoints as i } from "../../configs/endpoints.js";
8
8
  const f = (r) => {
9
9
  const t = /P((\d+)D)?T((\d+)H)?((\d+)M)?/, a = r.match(t);
10
10
  if (a) {
11
- const o = a[2] ? `${a[2]}d ` : "", e = a[4] ? `${a[4]}h ` : "", m = a[6] ? `${a[6]}m` : "";
12
- return `${o}${e}${m}`.trim();
11
+ const o = a[2] ? `${a[2]}d ` : "", e = a[4] ? `${a[4]}h ` : "", l = a[6] ? `${a[6]}m` : "";
12
+ return `${o}${e}${l}`.trim();
13
13
  } else
14
14
  return r;
15
15
  };
16
16
  class h {
17
17
  constructor() {
18
- i(this, "getHotelBooking", async (t) => {
19
- var m, _;
18
+ c(this, "getHotelBooking", async (t) => {
19
+ var l, _;
20
20
  const { data: a } = await d.get(
21
- `${c.USER_HOTEL_BOOKINGS}/${t}`
21
+ `${i.USER_HOTEL_BOOKINGS}/${t}`
22
22
  ), o = a.data.accommodation.rooms[0].rates[0];
23
23
  return {
24
24
  id: a.data._id,
@@ -54,15 +54,15 @@ class h {
54
54
  longitude: a.data.accommodation.location.geographic_coordinates.longitude
55
55
  },
56
56
  images: a.data.accommodation.photos.map((n) => n.url),
57
- guests: a.data.guests.map((n, u) => {
57
+ guests: a.data.guests.map((n, m) => {
58
58
  var s;
59
59
  return {
60
60
  familyName: n.family_name,
61
61
  givenName: n.given_name,
62
- type: (s = a.data.guest_types[u]) == null ? void 0 : s.type
62
+ type: (s = a.data.guest_types[m]) == null ? void 0 : s.type
63
63
  };
64
64
  }),
65
- numberOfRooms: (m = a.data.rooms) == null ? void 0 : m.length,
65
+ numberOfRooms: (l = a.data.rooms) == null ? void 0 : l.length,
66
66
  cancellationTimeline: o.cancellation_timeline.map(
67
67
  (n) => ({
68
68
  refundAmount: parseFloat(n.refund_amount),
@@ -71,9 +71,9 @@ class h {
71
71
  })
72
72
  ),
73
73
  rooms: (_ = a.data.rooms) == null ? void 0 : _.map((n) => {
74
- var u;
74
+ var m;
75
75
  return {
76
- beds: (u = n.beds) == null ? void 0 : u.map((s) => ({
76
+ beds: (m = n.beds) == null ? void 0 : m.map((s) => ({
77
77
  type: s.type,
78
78
  count: s.count
79
79
  })),
@@ -84,9 +84,9 @@ class h {
84
84
  createdAt: a.data.created_at
85
85
  };
86
86
  });
87
- i(this, "getFlightBooking", async (t) => {
87
+ c(this, "getFlightBooking", async (t) => {
88
88
  const { data: a } = await d.get(
89
- `${c.USER_FLIGHT_BOOKINGS}/${t}`
89
+ `${i.USER_FLIGHT_BOOKINGS}/${t}`
90
90
  );
91
91
  return {
92
92
  id: a.data._id,
@@ -137,38 +137,38 @@ class h {
137
137
  numberOfStops: e.segments.length - 1,
138
138
  reference: a.data.booking_reference,
139
139
  durationInMinutes: f(e.duration),
140
- origin: l(e.origin),
141
- destination: l(e.destination)
140
+ origin: u(e.origin),
141
+ destination: u(e.destination)
142
142
  })),
143
143
  availableActions: a.data.available_actions,
144
- airlineInitiatedChanges: l(a.data.airline_initiated_changes) || []
144
+ airlineInitiatedChanges: u(a.data.airline_initiated_changes) || []
145
145
  };
146
146
  });
147
- i(this, "initiateCancelFlightBooking", async (t) => {
147
+ c(this, "initiateCancelFlightBooking", async (t) => {
148
148
  const { data: a } = await d.put(
149
- `${c.INITIATE_FLIGHT_CANCEL}/${t}`
149
+ `${i.INITIATE_FLIGHT_CANCEL}/${t}`
150
150
  );
151
151
  return a.success;
152
152
  });
153
- i(this, "confirmCancelFlightBooking", async (t) => {
153
+ c(this, "confirmCancelFlightBooking", async (t) => {
154
154
  const { data: a } = await d.put(
155
- `${c.CONFIRM_FLIGHT_CANCEL}/${t}`
155
+ `${i.CONFIRM_FLIGHT_CANCEL}/${t}`
156
156
  );
157
157
  return a.success;
158
158
  });
159
- i(this, "cancelHotelBooking", async (t) => {
159
+ c(this, "cancelHotelBooking", async (t) => {
160
160
  const { data: a } = await d.post(
161
- `${c.CANCEL_HOTEL_BOOKING}/${t}`
161
+ `${i.CANCEL_HOTEL_BOOKING}/${t}`
162
162
  );
163
163
  return a.success;
164
164
  });
165
- i(this, "actionAirlineChanges", async ({
165
+ c(this, "actionAirlineChanges", async ({
166
166
  bookingId: t,
167
167
  acceptChanges: a,
168
168
  aicId: o
169
169
  }) => {
170
170
  const { data: e } = await d.post(
171
- c.ACTION_AIRLINE_CHANGES,
171
+ i.ACTION_AIRLINE_CHANGES,
172
172
  {
173
173
  booking_id: t,
174
174
  action_taken: a ? "accepted" : "cancelled",
@@ -177,23 +177,18 @@ class h {
177
177
  );
178
178
  return e.success;
179
179
  });
180
- i(this, "cancelPointsBooking", async (t) => {
180
+ c(this, "cancelPointsBooking", async (t) => {
181
181
  const { data: a } = await p.post(
182
- `${c.REFUND_POINTS_BOOKING}`,
182
+ `${i.REFUND_POINTS_BOOKING}`,
183
183
  {
184
- confirmationCode: t.confirmationCode,
185
- orderId: t.orderId,
186
- provider: t.provider,
187
- type: t.type,
188
- pointsAmount: t.pointsAmount,
189
- cashAmount: t.cashAmount
184
+ bookingId: t
190
185
  }
191
186
  );
192
187
  return a.success;
193
188
  });
194
- i(this, "getPointsAsCash", async (t) => {
189
+ c(this, "getPointsAsCash", async (t) => {
195
190
  const { data: a } = await p.get(
196
- `${c.BOOKING_POINTS_AS_CASH}/${t}`
191
+ `${i.BOOKING_POINTS_AS_CASH}/${t}`
197
192
  );
198
193
  return {
199
194
  ...a.data,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@odynn/awayz-core",
3
- "version": "0.9.7",
3
+ "version": "0.9.8",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"