@odynn/awayz-core 0.3.22 → 0.3.24

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.
Files changed (37) hide show
  1. package/dist/{AccountService-D_6U8vP6.js → AccountService-cvx__9rR.js} +55 -55
  2. package/dist/{TripsService-BbbkMtx6.js → TripsService-G1T_Co8r.js} +1 -1
  3. package/dist/components/CashValue/CashValue.js +47 -47
  4. package/dist/components/CashValue/CashValue.stories.js +2 -2
  5. package/dist/components/Wallet/Card/Card.stories.js +2 -2
  6. package/dist/configs/endpoints.js +3 -2
  7. package/dist/context/AwayzContext.js +4 -3
  8. package/dist/hooks/useAwayzAuth/useAwayzAuth.js +100 -83
  9. package/dist/hooks/useBookingManagement/useBookingManagement.js +1 -1
  10. package/dist/hooks/useBookingManagement/useBookingManagement.test.js +1 -1
  11. package/dist/hooks/useSearchLimit.js +17 -15
  12. package/dist/hooks/useTripManagement/useTripManagement.js +2 -2
  13. package/dist/hooks/useTripManagement/useTripManagement.test.js +3 -3
  14. package/dist/hooks/useWallet/useWallet.js +72 -42
  15. package/dist/hooks/useWallet/useWallet.test.js +80 -46
  16. package/dist/lib/components/CashValue/CashValue.d.ts +1 -1
  17. package/dist/lib/configs/endpoints.d.ts +3 -0
  18. package/dist/lib/context/AwayzContext.d.ts +2 -1
  19. package/dist/lib/hooks/useAwayzAuth/useAwayzAuth.d.ts +2 -1
  20. package/dist/lib/hooks/useSearchLimit.d.ts +3 -1
  21. package/dist/lib/hooks/useWallet/useWallet.types.d.ts +16 -2
  22. package/dist/lib/services/account/AccountServices.types.d.ts +4 -0
  23. package/dist/lib/services/preferences/PreferencesService.d.ts +7 -0
  24. package/dist/lib/services/wallet/WalletService.d.ts +3 -0
  25. package/dist/main.js +1 -1
  26. package/dist/providers/AwayzProvider.js +1 -1
  27. package/dist/services/account/AccountService.js +1 -1
  28. package/dist/services/bookings/BookingService.js +1 -1
  29. package/dist/services/currency/CurrencyService.js +1 -1
  30. package/dist/services/index.js +1 -1
  31. package/dist/services/instance.js +1 -1
  32. package/dist/services/instanceConfig.js +1 -1
  33. package/dist/services/noRetryInstance.js +1 -1
  34. package/dist/services/preferences/PreferencesService.js +35 -0
  35. package/dist/services/trips/TripsService.js +2 -2
  36. package/dist/services/wallet/WalletService.js +55 -26
  37. package/package.json +1 -1
@@ -1,8 +1,9 @@
1
- var r = /* @__PURE__ */ ((e) => (e.SIGN_IN = "auth/user-login", e.SIGN_UP = "auth/sign-up", e.ME = "user", e.RESEND_VERIFICATION_EMAIL = "auth/resend-verification-email", e.UPDATE_USER_DETAILS = "account/update/user", e.CONFIRM_EMAIL = "account/verifyAccount", e.FORGOT_PASSWORD = "email/sendVeri", e.RESEND_OTP = "email/sendForgotPasswordVerification", e.RESET_PASSWORD = "account/updateUserPassword", e.REQUEST_LIMIT = "user/request-limit", e.APPLE_SOCIAL_SIGN_UP = "tp/apple/get/user", e.GOOGLE_SOCIAL_SIGN_UP = "tp/google/get/user", e.UPDATE_USER = "account/details/addUserDetails", e.ACKNOWLEDGEMENT = "account/update/userAcknowledgement", e.REGIONS = "user/region", e.UPDATE_USER_REGION = "/account/update/userRegion", e.UPDATE_PASSENGER_DETAILS = "/account/awayz", e.REFRESH_TOKEN = "auth/refresh-token", e.EXCHANGE_TOKEN = "user/exchange-token", e.REFRESH_EMBED_TOKEN = "user/refresh-token", e.OAUTH_INITIATE = "user/oauth2/initiate", e.OAUTH_CALLBACK = "user/oauth2/callback", e))(r || {}), a = /* @__PURE__ */ ((e) => (e.CURRENCY_CONVERSION = "currency/convert", e))(a || {}), _ = /* @__PURE__ */ ((e) => (e.USER_AWARDS = "user/rewards", e.USER_CARDS = "user/cards", e.ADD_USER_CARDS = "user/cards/add", e.REMOVE_USER_CARDS = "user/cards/remove", e.BANKS = "banks", e.CARDS = "cards", e))(_ || {}), S = /* @__PURE__ */ ((e) => (e.TRIPS = "user/trips", e.ADD_BOOKING = "user/trips/add-booking-to-trip", e.REMOVE_BOOKING = "user/trips/remove-booking-from-trip", e.UNCATEGORISED_BOOKINGS = "/user/trips/get-uncategorized-bookings", e))(S || {}), O = /* @__PURE__ */ ((e) => (e.USER_HOTEL_BOOKINGS = "/user/bookings/hotels", e.USER_FLIGHT_BOOKINGS = "/user/bookings/flights", e.INITIATE_FLIGHT_CANCEL = "/duffel/flights/initiate-order-cancellation", e.CONFIRM_FLIGHT_CANCEL = "/duffel/flights/confirm-order-cancellation", e.CANCEL_HOTEL_BOOKING = "/duffel/hotels/cancel", e))(O || {});
1
+ var r = /* @__PURE__ */ ((e) => (e.SIGN_IN = "auth/user-login", e.SIGN_UP = "auth/sign-up", e.ME = "user", e.RESEND_VERIFICATION_EMAIL = "auth/resend-verification-email", e.UPDATE_USER_DETAILS = "account/update/user", e.CONFIRM_EMAIL = "account/verifyAccount", e.FORGOT_PASSWORD = "email/sendVeri", e.RESEND_OTP = "email/sendForgotPasswordVerification", e.RESET_PASSWORD = "account/updateUserPassword", e.REQUEST_LIMIT = "user/request-limit", e.APPLE_SOCIAL_SIGN_UP = "tp/apple/get/user", e.GOOGLE_SOCIAL_SIGN_UP = "tp/google/get/user", e.UPDATE_USER = "account/details/addUserDetails", e.ACKNOWLEDGEMENT = "account/update/userAcknowledgement", e.REGIONS = "user/region", e.UPDATE_USER_REGION = "/account/update/userRegion", e.UPDATE_PASSENGER_DETAILS = "/account/awayz", e.REFRESH_TOKEN = "auth/refresh-token", e.EXCHANGE_TOKEN = "user/exchange-token", e.REFRESH_EMBED_TOKEN = "user/refresh-token", e.OAUTH_INITIATE = "user/oauth2/initiate", e.OAUTH_CALLBACK = "user/oauth2/callback", e))(r || {}), a = /* @__PURE__ */ ((e) => (e.CURRENCY_CONVERSION = "currency/convert", e))(a || {}), _ = /* @__PURE__ */ ((e) => (e.USER_AWARDS = "user/rewards", e.USER_CARDS = "user/cards", e.ADD_USER_CARDS = "user/cards/add", e.REMOVE_USER_CARDS = "user/cards/remove", e.BANKS = "banks", e.CARDS = "cards", e))(_ || {}), S = /* @__PURE__ */ ((e) => (e.TRIPS = "user/trips", e.ADD_BOOKING = "user/trips/add-booking-to-trip", e.REMOVE_BOOKING = "user/trips/remove-booking-from-trip", e.UNCATEGORISED_BOOKINGS = "/user/trips/get-uncategorized-bookings", e))(S || {}), R = /* @__PURE__ */ ((e) => (e.USER_HOTEL_BOOKINGS = "/user/bookings/hotels", e.USER_FLIGHT_BOOKINGS = "/user/bookings/flights", e.INITIATE_FLIGHT_CANCEL = "/duffel/flights/initiate-order-cancellation", e.CONFIRM_FLIGHT_CANCEL = "/duffel/flights/confirm-order-cancellation", e.CANCEL_HOTEL_BOOKING = "/duffel/hotels/cancel", e))(R || {}), O = /* @__PURE__ */ ((e) => (e.USER_PREFERENCES = "/user/user-preferences", e))(O || {});
2
2
  export {
3
3
  r as EAuthEndpoints,
4
- O as EBookingEndpoints,
4
+ R as EBookingEndpoints,
5
5
  a as ECurrencyEndpoints,
6
6
  S as EMyTripsEndpoints,
7
+ O as EPreferencesEndpoints,
7
8
  _ as EWalletEndpoints
8
9
  };
@@ -1,5 +1,5 @@
1
- import { createContext as s } from "react";
2
- const t = s({
1
+ import { createContext as e } from "react";
2
+ const t = e({
3
3
  isAuthenticated: !1,
4
4
  isAuthenticating: !1,
5
5
  supportedRegions: [],
@@ -9,7 +9,8 @@ const t = s({
9
9
  },
10
10
  resendVerificationEmail: async () => !1,
11
11
  setTokens: () => {
12
- }
12
+ },
13
+ setPreferredCurrency: async () => !1
13
14
  });
14
15
  export {
15
16
  t as AwayzContext
@@ -1,54 +1,55 @@
1
1
  import "../../arrayExtensions-DlcBOj5a.js";
2
- import { f as U, d as r, A as o, E as v } from "../../AccountService-D_6U8vP6.js";
3
- import { useState as E, useCallback as R, useEffect as y } from "react";
4
- import { EAuthFlow as S } from "../../types/EAuthFlow.js";
5
- import { awayzClient as A } from "../../configs/awayzClient.js";
6
- const H = (s, t) => {
7
- var f, m;
8
- let c = "", d = t;
9
- typeof t == "string" ? c = t : t instanceof U ? (c = t.message, d = {
10
- message: t.message,
11
- cause: t.cause,
12
- status: t.status,
13
- data: (f = t == null ? void 0 : t.response) == null ? void 0 : f.data
14
- }) : c = t.message, (m = window.parent) == null || m.postMessage(
2
+ import { f as P, d as n, A as o, E as U } from "../../AccountService-cvx__9rR.js";
3
+ import { useState as m, useCallback as A, useEffect as S } from "react";
4
+ import { awayzClient as O } from "../../configs/awayzClient.js";
5
+ import { PreferencesService as v } from "../../services/preferences/PreferencesService.js";
6
+ import { EAuthFlow as h } from "../../types/EAuthFlow.js";
7
+ const C = (t, r) => {
8
+ var g, y;
9
+ let c = "", E = r;
10
+ typeof r == "string" ? c = r : r instanceof P ? (c = r.message, E = {
11
+ message: r.message,
12
+ cause: r.cause,
13
+ status: r.status,
14
+ data: (g = r == null ? void 0 : r.response) == null ? void 0 : g.data
15
+ }) : c = r.message, (y = window.parent) == null || y.postMessage(
15
16
  {
16
17
  type: "auth_error",
17
- details: { message: c, action: s, info: d }
18
+ details: { message: c, action: t, info: E }
18
19
  },
19
20
  "*"
20
21
  );
21
- }, G = (s) => {
22
- const [t, c] = E(!0), [d, f] = E(!1), [m, T] = E(), [O, k] = E(), [I, K] = E([]), w = R(
23
- async (a) => {
24
- s != null && s.onSuccess && (s == null || s.onSuccess(a)), s != null && s.onSuccessAsync && await (s == null ? void 0 : s.onSuccessAsync(a)), c(!1), f(!0), T(a.token), k(a.user), A.invalidateQueries();
22
+ }, W = (t) => {
23
+ const [r, c] = m(!0), [E, g] = m(!1), [y, R] = m(), [d, T] = m(), [I, K] = m([]), w = A(
24
+ async (s) => {
25
+ t != null && t.onSuccess && (t == null || t.onSuccess(s)), t != null && t.onSuccessAsync && await (t == null ? void 0 : t.onSuccessAsync(s)), c(!1), g(!0), R(s.token), T(s.user), O.invalidateQueries();
25
26
  },
26
- [s]
27
- ), i = R(
28
- async (a, e) => {
29
- if (s.authFlow !== S.POST_MESSAGE)
30
- return H(e ?? "exchange_token", a);
31
- s != null && s.onError && (s == null || s.onError(a)), s != null && s.onErrorAsync && await (s == null ? void 0 : s.onErrorAsync(a)), c(!1);
27
+ [t]
28
+ ), i = A(
29
+ async (s, e) => {
30
+ if (t.authFlow !== h.POST_MESSAGE)
31
+ return C(e ?? "exchange_token", s);
32
+ t != null && t.onError && (t == null || t.onError(s)), t != null && t.onErrorAsync && await (t == null ? void 0 : t.onErrorAsync(s)), c(!1);
32
33
  },
33
- [s]
34
- ), h = async (a) => {
34
+ [t]
35
+ ), k = async (s) => {
35
36
  try {
36
- const { success: e, data: n, message: u } = await o.authenticateWithToken(a);
37
+ const { success: e, data: a, message: u } = await o.authenticateWithToken(s);
37
38
  if (!e) {
38
39
  i(u);
39
40
  return;
40
41
  }
41
- if (!(n != null && n.token)) {
42
+ if (!(a != null && a.token)) {
42
43
  i("no awayz token returned after exchanging id token");
43
44
  return;
44
45
  }
45
- localStorage.setItem(r.TOKEN, n.token), await w(n);
46
- const { data: l, ...g } = await o.getRequestLimit();
47
- if (!g.success) {
48
- console.error({ reqLimitError: g });
46
+ localStorage.setItem(n.TOKEN, a.token), await w(a);
47
+ const { data: f, ...l } = await o.getRequestLimit();
48
+ if (!l.success) {
49
+ console.error({ reqLimitError: l });
49
50
  return;
50
51
  }
51
- l == null || l.forEach(
52
+ f == null || f.forEach(
52
53
  (_) => window.parent.postMessage(
53
54
  {
54
55
  type: "request_limit",
@@ -64,114 +65,130 @@ const H = (s, t) => {
64
65
  }
65
66
  }, N = async () => {
66
67
  try {
67
- const { success: a, data: e } = await A.ensureQueryData({
68
- queryKey: [v.CHECK_USER],
68
+ const { success: s, data: e } = await O.ensureQueryData({
69
+ queryKey: [U.CHECK_USER],
69
70
  queryFn: o.checkUser
70
71
  });
71
- if (!a) {
72
+ if (!s) {
72
73
  i(e);
73
74
  return;
74
75
  }
75
76
  await w({
76
77
  user: e,
77
- token: localStorage.getItem(r.TOKEN)
78
+ token: localStorage.getItem(n.TOKEN)
78
79
  });
79
- } catch (a) {
80
- i(a);
80
+ } catch (s) {
81
+ i(s);
81
82
  } finally {
82
83
  c(!1);
83
84
  }
84
85
  };
85
- y(() => {
86
- if (s.authFlow !== S.STANDARD) return;
87
- const a = localStorage.getItem(r.TOKEN), e = localStorage.getItem(r.REFRESH_TOKEN);
88
- a && e ? N() : c(!1);
86
+ S(() => {
87
+ if (t.authFlow !== h.STANDARD) return;
88
+ const s = localStorage.getItem(n.TOKEN), e = localStorage.getItem(n.REFRESH_TOKEN);
89
+ s && e ? N() : c(!1);
89
90
  }, []);
90
91
  const F = async () => {
91
- const a = await o.getRegions();
92
- K(a);
92
+ const s = await o.getRegions();
93
+ K(s);
93
94
  };
94
- return y(() => {
95
+ return S(() => {
95
96
  F();
96
- }, []), y(() => {
97
- if (s.authFlow !== S.QUERY) return;
98
- const e = new URLSearchParams(window.location.search).get(r.TOKEN);
99
- e && h(e);
100
- }, []), y(() => {
101
- if (s.authFlow !== S.POST_MESSAGE) return;
102
- const a = async (e) => {
103
- var l;
97
+ }, []), S(() => {
98
+ if (t.authFlow !== h.QUERY) return;
99
+ const e = new URLSearchParams(window.location.search).get(n.TOKEN);
100
+ e && k(e);
101
+ }, []), S(() => {
102
+ if (t.authFlow !== h.POST_MESSAGE) return;
103
+ const s = async (e) => {
104
+ var f;
104
105
  if (e.data.type !== "auth") return;
105
- const n = (l = e.data) == null ? void 0 : l.idToken, u = e.data.refreshToken;
106
- if (!n) {
107
- const g = `received message ${JSON.stringify(
106
+ const a = (f = e.data) == null ? void 0 : f.idToken, u = e.data.refreshToken;
107
+ if (!a) {
108
+ const l = `received message ${JSON.stringify(
108
109
  e.data
109
110
  )}
110
111
  no idToken in body`;
111
- i(g);
112
+ i(l);
112
113
  return;
113
114
  }
114
115
  if (!u) {
115
- const g = `received message: ${JSON.stringify(
116
+ const l = `received message: ${JSON.stringify(
116
117
  e.data
117
118
  )}
118
119
  no refreshToken in body`;
119
120
  i(
120
- g,
121
+ l,
121
122
  "refresh_token"
122
123
  /* REFRESH */
123
124
  );
124
125
  return;
125
126
  }
126
- localStorage.setItem(r.REFRESH_TOKEN, u), await h(n);
127
+ localStorage.setItem(n.REFRESH_TOKEN, u), await k(a);
127
128
  };
128
- return window.addEventListener("message", a), window.parent && window.parent.postMessage(
129
+ return window.addEventListener("message", s), window.parent && window.parent.postMessage(
129
130
  {
130
131
  type: "ready"
131
132
  /* READY */
132
133
  },
133
134
  "*"
134
135
  ), () => {
135
- window.removeEventListener("message", a);
136
+ window.removeEventListener("message", s);
136
137
  };
137
138
  }, []), {
138
- isAuthenticating: t,
139
- isAuthenticated: d,
140
- token: m,
141
- user: O,
139
+ isAuthenticating: r,
140
+ isAuthenticated: E,
141
+ token: y,
142
+ user: d,
142
143
  supportedRegions: I,
143
- signIn: async (a) => {
144
- var n;
145
- const e = await o.login(a);
144
+ signIn: async (s) => {
145
+ var a;
146
+ const e = await o.login(s);
146
147
  if (!e.success)
147
148
  i(e.message);
148
149
  else {
149
- const u = (n = e.data) == null ? void 0 : n.refreshToken;
150
- localStorage.setItem(r.REFRESH_TOKEN, u), await w(e.data);
150
+ const u = (a = e.data) == null ? void 0 : a.refreshToken;
151
+ localStorage.setItem(n.REFRESH_TOKEN, u), await w(e.data);
151
152
  }
152
153
  return e;
153
154
  },
154
- signUp: async (a) => {
155
- var n;
156
- const e = await o.signUp(a);
155
+ signUp: async (s) => {
156
+ var a;
157
+ const e = await o.signUp(s);
157
158
  if (!e.success)
158
159
  i(e.message);
159
160
  else {
160
- const u = (n = e.data) == null ? void 0 : n.refreshToken;
161
- localStorage.setItem(r.REFRESH_TOKEN, u), await w(e.data);
161
+ const u = (a = e.data) == null ? void 0 : a.refreshToken;
162
+ localStorage.setItem(n.REFRESH_TOKEN, u), await w(e.data);
162
163
  }
163
164
  return e;
164
165
  },
165
166
  signOut: () => {
166
- localStorage.removeItem(r.TOKEN), localStorage.removeItem(r.REFRESH_TOKEN), f(!1), T(void 0), k(void 0);
167
+ localStorage.removeItem(n.TOKEN), localStorage.removeItem(n.REFRESH_TOKEN), g(!1), R(void 0), T(void 0);
167
168
  },
168
- resendVerificationEmail: async (a) => (await o.resendVerificationEmail(a)).success,
169
- setTokens: (a, e) => {
170
- localStorage.setItem(r.TOKEN, a), localStorage.setItem(r.REFRESH_TOKEN, e), h(a);
169
+ resendVerificationEmail: async (s) => (await o.resendVerificationEmail(s)).success,
170
+ setTokens: (s, e) => {
171
+ localStorage.setItem(n.TOKEN, s), localStorage.setItem(n.REFRESH_TOKEN, e), k(s);
172
+ },
173
+ setPreferredCurrency: async (s) => {
174
+ const e = await v.setCurrency(s);
175
+ if (!e.success || !e.data)
176
+ return console.error("Failed to set preferred currency:", e), !1;
177
+ if (d) {
178
+ const a = {
179
+ ...d,
180
+ preferences: {
181
+ ...d.preferences,
182
+ currency: e.data.currency || d.preferences.currency
183
+ }
184
+ };
185
+ T(a);
186
+ }
187
+ return !0;
171
188
  }
172
189
  };
173
190
  };
174
191
  export {
175
- H as authFailurePostMessage,
176
- G as useAwayzAuth
192
+ C as authFailurePostMessage,
193
+ W as useAwayzAuth
177
194
  };
@@ -1,7 +1,7 @@
1
1
  import { useQuery as a, useMutation as s } from "@tanstack/react-query";
2
2
  import { EBookingType as e } from "../../services/trips/TripService.types.js";
3
3
  import "../../arrayExtensions-DlcBOj5a.js";
4
- import { E as t } from "../../AccountService-D_6U8vP6.js";
4
+ import { E as t } from "../../AccountService-cvx__9rR.js";
5
5
  import "react";
6
6
  import { BookingService as o } from "../../services/bookings/BookingService.js";
7
7
  import "react/jsx-runtime";
@@ -1,6 +1,6 @@
1
1
  import { renderHook as t, waitFor as r } from "../../tests/TestWrapper.js";
2
2
  import { useBookingManagement as a } from "./useBookingManagement.js";
3
- import { c as i } from "../../AccountService-D_6U8vP6.js";
3
+ import { c as i } from "../../AccountService-cvx__9rR.js";
4
4
  import "../../services/noRetryInstance.js";
5
5
  import "../../arrayExtensions-DlcBOj5a.js";
6
6
  import "react";
@@ -1,26 +1,28 @@
1
- import { E as s, A as i, b as n } from "../AccountService-D_6U8vP6.js";
2
1
  import { useQuery as u } from "@tanstack/react-query";
3
2
  import "../arrayExtensions-DlcBOj5a.js";
4
- import "react";
5
- import { useAwayzContext as c } from "./useAwayzContext.js";
6
- var o = /* @__PURE__ */ ((e) => (e.HOTEL = "Hotel", e.FLIGHT = "Flight", e))(o || {});
7
- const f = () => {
8
- const { isAuthenticated: e } = c(), { data: a } = u({
9
- queryKey: [s.SEARCH_LIMIT],
3
+ import { E as m, A as c, b as f } from "../AccountService-cvx__9rR.js";
4
+ import { useEffect as d } from "react";
5
+ import { useAwayzContext as y } from "./useAwayzContext.js";
6
+ var i = /* @__PURE__ */ ((r) => (r.HOTEL = "Hotel", r.FLIGHT = "Flight", r))(i || {});
7
+ const H = (r) => {
8
+ const { isAuthenticated: o } = y(), { data: t } = u({
9
+ queryKey: [m.SEARCH_LIMIT],
10
10
  queryFn: async () => {
11
- const { data: t, ...r } = await i.getRequestLimit();
12
- if (!r.success) {
13
- console.error({ reqLimitError: r });
11
+ const { data: s, ...e } = await c.getRequestLimit();
12
+ if (!e.success) {
13
+ console.error({ reqLimitError: e });
14
14
  return;
15
15
  }
16
- return n(t);
16
+ return f(s);
17
17
  },
18
- enabled: e
18
+ enabled: o
19
19
  });
20
- return a ? [o.FLIGHT, o.HOTEL].map(
21
- (t) => a.find((r) => r.searchType === t)
20
+ return d(() => {
21
+ t && (r == null || r());
22
+ }, [t, r]), t ? [i.FLIGHT, i.HOTEL].map(
23
+ (s) => t.find((e) => e.searchType === s)
22
24
  ) : [void 0, void 0];
23
25
  };
24
26
  export {
25
- f as useSearchLimit
27
+ H as useSearchLimit
26
28
  };
@@ -1,8 +1,8 @@
1
1
  import { useQuery as p, useMutation as s } from "@tanstack/react-query";
2
2
  import { h as m } from "../../arrayExtensions-DlcBOj5a.js";
3
- import { E as e } from "../../AccountService-D_6U8vP6.js";
3
+ import { E as e } from "../../AccountService-cvx__9rR.js";
4
4
  import "react";
5
- import { T as t } from "../../TripsService-BbbkMtx6.js";
5
+ import { T as t } from "../../TripsService-G1T_Co8r.js";
6
6
  import "react/jsx-runtime";
7
7
  import "../../context/AwayzContext.js";
8
8
  import { awayzClient as o } from "../../configs/awayzClient.js";
@@ -4,10 +4,10 @@ import { useTripManagement as n } from "./useTripManagement.js";
4
4
  import "react/jsx-runtime";
5
5
  import "react";
6
6
  import "../../context/AwayzContext.js";
7
- import { D as f } from "../../TripsService-BbbkMtx6.js";
8
- import { c } from "../../AccountService-D_6U8vP6.js";
9
- import { EMyTripsEndpoints as d } from "../../configs/endpoints.js";
7
+ import { D as f } from "../../TripsService-G1T_Co8r.js";
10
8
  import "../../configs/awayzClient.js";
9
+ import { c } from "../../AccountService-cvx__9rR.js";
10
+ import { EMyTripsEndpoints as d } from "../../configs/endpoints.js";
11
11
  import "@tanstack/react-query";
12
12
  import { EBookingType as m } from "../../services/trips/TripService.types.js";
13
13
  import "../../services/noRetryInstance.js";
@@ -1,86 +1,116 @@
1
- import { useQuery as o, useMutation as n } from "@tanstack/react-query";
1
+ import { useQuery as n, useMutation as i } from "@tanstack/react-query";
2
2
  import "../../arrayExtensions-DlcBOj5a.js";
3
- import { E as t, a as s } from "../../AccountService-D_6U8vP6.js";
3
+ import { E as t, a as d } from "../../AccountService-cvx__9rR.js";
4
4
  import "react";
5
- import { WalletService as a } from "../../services/wallet/WalletService.js";
6
5
  import "react/jsx-runtime";
7
6
  import "../../context/AwayzContext.js";
8
- import { awayzClient as i } from "../../configs/awayzClient.js";
7
+ import { awayzClient as s } from "../../configs/awayzClient.js";
8
+ import { useAwayzContext as f } from "../useAwayzContext.js";
9
9
  import "../../services/noRetryInstance.js";
10
10
  import '../../assets/_styles5.css';import '../../assets/_styles4.css';import '../../assets/_styles3.css';import '../../assets/_styles2.css';import '../../assets/_styles.css';/* empty css */
11
11
  /* empty css */
12
12
  /* empty css */
13
13
  /* empty css */
14
14
  /* empty css */
15
- const b = () => {
16
- const { data: r } = o({
15
+ import { WalletService as o } from "../../services/wallet/WalletService.js";
16
+ const B = () => {
17
+ const { user: e } = f(), { data: a } = n({
17
18
  queryKey: [t.PROGRAMS],
18
- queryFn: a.getAwards,
19
+ queryFn: o.getAwards,
19
20
  placeholderData: []
20
- }), { data: u } = o({
21
+ }), { data: y } = n({
22
+ queryKey: [t.USER_PROGRAMS, e == null ? void 0 : e.id],
23
+ queryFn: () => e != null && e.id ? o.getUserAwards(e.id) : [],
24
+ placeholderData: [],
25
+ enabled: !!(e != null && e.id)
26
+ }), { data: l } = n({
21
27
  queryKey: [t.BANKS],
22
- queryFn: a.getBanks,
28
+ queryFn: o.getBanks,
23
29
  placeholderData: []
24
- }), { data: l } = o({
30
+ }), { data: g } = n({
25
31
  queryKey: [t.CARDS],
26
- queryFn: a.getCards,
32
+ queryFn: o.getCards,
27
33
  placeholderData: []
28
- }), { data: c } = o({
34
+ }), { data: p } = n({
29
35
  queryKey: [t.USER_CARDS],
30
- queryFn: a.getUserCards,
36
+ queryFn: o.getUserCards,
31
37
  placeholderData: []
32
- }), { mutate: y } = n({
33
- mutationFn: async (e) => {
34
- const { mainProgram: g, awardsAmount: C } = e, m = r == null ? void 0 : r.find(
35
- (S) => S.mainProgram === g
38
+ }), { mutate: A } = i({
39
+ mutationFn: async (r) => {
40
+ const { mainProgram: m, awardsAmount: u } = typeof r == "string" ? { mainProgram: r, awardsAmount: 0 } : r;
41
+ await o.addAwardProgram(m, u);
42
+ },
43
+ onSuccess: () => {
44
+ s.invalidateQueries({
45
+ queryKey: [t.PROGRAMS]
46
+ });
47
+ }
48
+ }), { mutate: P } = i({
49
+ mutationFn: async (r) => {
50
+ await o.removeAwardProgram(r);
51
+ },
52
+ onSuccess: () => {
53
+ s.invalidateQueries({
54
+ queryKey: [t.PROGRAMS]
55
+ });
56
+ }
57
+ }), { mutate: R } = i({
58
+ mutationFn: async (r) => {
59
+ const { mainProgram: m, awardsAmount: u } = r, c = a == null ? void 0 : a.find(
60
+ (w) => w.mainProgram === m
36
61
  );
37
- if (!m)
62
+ if (!c)
38
63
  throw new Error("Program not found");
39
- await a.setAwardPoints(m.mainProgram, C);
64
+ await o.setAwardPoints(c.mainProgram, u);
40
65
  },
41
66
  onSuccess: () => {
42
- i.invalidateQueries({
67
+ s.invalidateQueries({
43
68
  queryKey: [t.PROGRAMS]
44
69
  });
45
70
  }
46
- }), { mutate: d } = n({
47
- mutationFn: async (e) => {
48
- await a.addCardsToWallet(e);
71
+ }), { mutate: S } = i({
72
+ mutationFn: async (r) => {
73
+ await o.addCardsToWallet(r);
49
74
  },
50
75
  onSuccess: () => {
51
- i.invalidateQueries({
76
+ s.invalidateQueries({
52
77
  queryKey: [t.USER_CARDS]
53
78
  });
54
79
  }
55
- }), { mutate: p } = n({
56
- mutationFn: async (e) => {
57
- await a.removeCardsFromWallet(e);
80
+ }), { mutate: C } = i({
81
+ mutationFn: async (r) => {
82
+ await o.removeCardsFromWallet(r);
58
83
  },
59
84
  onSuccess: () => {
60
- i.invalidateQueries({
85
+ s.invalidateQueries({
61
86
  queryKey: [t.USER_CARDS]
62
87
  });
63
88
  }
64
89
  });
65
90
  return {
66
- allPrograms: r || [],
67
- hotelPrograms: (r == null ? void 0 : r.filter(
68
- (e) => e.category.includes(s.HOTEL)
91
+ // Program Management
92
+ allPrograms: a || [],
93
+ userPrograms: y || [],
94
+ hotelPrograms: (a == null ? void 0 : a.filter(
95
+ (r) => r.category.includes(d.HOTEL)
69
96
  )) || [],
70
- airlinePrograms: (r == null ? void 0 : r.filter(
71
- (e) => e.category.includes(s.AIRLINE)
97
+ airlinePrograms: (a == null ? void 0 : a.filter(
98
+ (r) => r.category.includes(d.AIRLINE)
72
99
  )) || [],
73
- bankPrograms: (r == null ? void 0 : r.filter(
74
- (e) => e.category.includes(s.BANK)
100
+ bankPrograms: (a == null ? void 0 : a.filter(
101
+ (r) => r.category.includes(d.BANK)
75
102
  )) || [],
76
- updatePoints: y,
77
- banks: u || [],
78
- allCards: l || [],
79
- userCards: c || [],
80
- addCards: d,
81
- removeCards: p
103
+ updatePoints: R,
104
+ addAwardProgram: A,
105
+ removeAwardProgram: P,
106
+ // Car Management
107
+ banks: l || [],
108
+ allCards: g || [],
109
+ userCards: p || [],
110
+ addCards: S,
111
+ removeCards: C
82
112
  };
83
113
  };
84
114
  export {
85
- b as useWallet
115
+ B as useWallet
86
116
  };