@odynn/awayz-core 0.4.4 → 0.4.6

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.
@@ -792,7 +792,10 @@ const Pr = 1e3 * 60 * 60, Vr = ({
792
792
  var f, v;
793
793
  const { user: s } = wt(), a = ((f = s == null ? void 0 : s.preferences) == null ? void 0 : f.currency) ?? ((v = s == null ? void 0 : s.userRegion) == null ? void 0 : v.currency), u = a !== t, { data: l, isPending: p } = Ct({
794
794
  queryKey: [Et.CONVERT_CURRENCY, t, a],
795
- queryFn: () => Pt.convertCurrency({ baseCurrency: t }),
795
+ queryFn: () => Pt.convertCurrency({
796
+ baseCurrency: t,
797
+ targetCurrency: a
798
+ }),
796
799
  enabled: u,
797
800
  staleTime: Pr
798
801
  }), d = nt(() => {
@@ -1,13 +1,13 @@
1
1
  import "../../arrayExtensions-DlcBOj5a.js";
2
- import { f as P, d as n, A as o, E as U } from "../../AccountService-DdcBI9BS.js";
3
- import { useState as m, useCallback as A, useEffect as S } from "react";
4
- import { awayzClient as O } from "../../configs/awayzClient.js";
2
+ import { f as U, d as n, A as o, E as K } from "../../AccountService-DdcBI9BS.js";
3
+ import { useState as E, useCallback as A, useEffect as w } from "react";
4
+ import { awayzClient as h } from "../../configs/awayzClient.js";
5
5
  import { PreferencesService as v } from "../../services/preferences/PreferencesService.js";
6
- import { EAuthFlow as h } from "../../types/EAuthFlow.js";
7
- const C = (t, r) => {
6
+ import { EAuthFlow as T } from "../../types/EAuthFlow.js";
7
+ const P = (t, r) => {
8
8
  var g, y;
9
- let c = "", E = r;
10
- typeof r == "string" ? c = r : r instanceof P ? (c = r.message, E = {
9
+ let c = "", m = r;
10
+ typeof r == "string" ? c = r : r instanceof U ? (c = r.message, m = {
11
11
  message: r.message,
12
12
  cause: r.cause,
13
13
  status: r.status,
@@ -15,24 +15,24 @@ const C = (t, r) => {
15
15
  }) : c = r.message, (y = window.parent) == null || y.postMessage(
16
16
  {
17
17
  type: "auth_error",
18
- details: { message: c, action: t, info: E }
18
+ details: { message: c, action: t, info: m }
19
19
  },
20
20
  "*"
21
21
  );
22
- }, W = (t) => {
23
- const [r, c] = m(!0), [E, g] = m(!1), [y, R] = m(), [d, T] = m(), [I, K] = m([]), w = A(
22
+ }, $ = (t) => {
23
+ const [r, c] = E(!0), [m, g] = E(!1), [y, O] = E(), [d, k] = E(), [N, I] = E([]), S = A(
24
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
+ 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), O(s.token), k(s.user), h.invalidateQueries();
26
26
  },
27
27
  [t]
28
28
  ), i = A(
29
29
  async (s, e) => {
30
- if (t.authFlow !== h.POST_MESSAGE)
31
- return C(e ?? "exchange_token", s);
30
+ if (t.authFlow !== T.POST_MESSAGE)
31
+ return P(e ?? "exchange_token", s);
32
32
  t != null && t.onError && (t == null || t.onError(s)), t != null && t.onErrorAsync && await (t == null ? void 0 : t.onErrorAsync(s)), c(!1);
33
33
  },
34
34
  [t]
35
- ), k = async (s) => {
35
+ ), R = async (s) => {
36
36
  try {
37
37
  const { success: e, data: a, message: u } = await o.authenticateWithToken(s);
38
38
  if (!e) {
@@ -43,17 +43,17 @@ const C = (t, r) => {
43
43
  i("no awayz token returned after exchanging id token");
44
44
  return;
45
45
  }
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 });
46
+ localStorage.setItem(n.TOKEN, a.token), await S(a);
47
+ const { data: l, ...f } = await o.getRequestLimit();
48
+ if (!f.success) {
49
+ console.error({ reqLimitError: f });
50
50
  return;
51
51
  }
52
- f == null || f.forEach(
53
- (_) => window.parent.postMessage(
52
+ l == null || l.forEach(
53
+ (C) => window.parent.postMessage(
54
54
  {
55
55
  type: "request_limit",
56
- limit: _
56
+ limit: C
57
57
  },
58
58
  "*"
59
59
  )
@@ -63,17 +63,17 @@ const C = (t, r) => {
63
63
  } finally {
64
64
  c(!1);
65
65
  }
66
- }, N = async () => {
66
+ }, _ = async () => {
67
67
  try {
68
- const { success: s, data: e } = await O.ensureQueryData({
69
- queryKey: [U.CHECK_USER],
68
+ const { success: s, data: e } = await h.ensureQueryData({
69
+ queryKey: [K.CHECK_USER],
70
70
  queryFn: o.checkUser
71
71
  });
72
72
  if (!s) {
73
73
  i(e);
74
74
  return;
75
75
  }
76
- await w({
76
+ await S({
77
77
  user: e,
78
78
  token: localStorage.getItem(n.TOKEN)
79
79
  });
@@ -83,48 +83,48 @@ const C = (t, r) => {
83
83
  c(!1);
84
84
  }
85
85
  };
86
- S(() => {
87
- if (t.authFlow !== h.STANDARD) return;
86
+ w(() => {
87
+ if (t.authFlow !== T.STANDARD) return;
88
88
  const s = localStorage.getItem(n.TOKEN), e = localStorage.getItem(n.REFRESH_TOKEN);
89
- s && e ? N() : c(!1);
89
+ s && e ? _() : c(!1);
90
90
  }, []);
91
91
  const F = async () => {
92
92
  const s = await o.getRegions();
93
- K(s);
93
+ I(s);
94
94
  };
95
- return S(() => {
95
+ return w(() => {
96
96
  F();
97
- }, []), S(() => {
98
- if (t.authFlow !== h.QUERY) return;
97
+ }, []), w(() => {
98
+ if (t.authFlow !== T.QUERY) return;
99
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;
100
+ e && R(e);
101
+ }, []), w(() => {
102
+ if (t.authFlow !== T.POST_MESSAGE) return;
103
103
  const s = async (e) => {
104
- var f;
104
+ var l;
105
105
  if (e.data.type !== "auth") return;
106
- const a = (f = e.data) == null ? void 0 : f.idToken, u = e.data.refreshToken;
106
+ const a = (l = e.data) == null ? void 0 : l.idToken, u = e.data.refreshToken;
107
107
  if (!a) {
108
- const l = `received message ${JSON.stringify(
108
+ const f = `received message ${JSON.stringify(
109
109
  e.data
110
110
  )}
111
111
  no idToken in body`;
112
- i(l);
112
+ i(f);
113
113
  return;
114
114
  }
115
115
  if (!u) {
116
- const l = `received message: ${JSON.stringify(
116
+ const f = `received message: ${JSON.stringify(
117
117
  e.data
118
118
  )}
119
119
  no refreshToken in body`;
120
120
  i(
121
- l,
121
+ f,
122
122
  "refresh_token"
123
123
  /* REFRESH */
124
124
  );
125
125
  return;
126
126
  }
127
- localStorage.setItem(n.REFRESH_TOKEN, u), await k(a);
127
+ localStorage.setItem(n.REFRESH_TOKEN, u), await R(a);
128
128
  };
129
129
  return window.addEventListener("message", s), window.parent && window.parent.postMessage(
130
130
  {
@@ -137,10 +137,10 @@ const C = (t, r) => {
137
137
  };
138
138
  }, []), {
139
139
  isAuthenticating: r,
140
- isAuthenticated: E,
140
+ isAuthenticated: m,
141
141
  token: y,
142
142
  user: d,
143
- supportedRegions: I,
143
+ supportedRegions: N,
144
144
  signIn: async (s) => {
145
145
  var a;
146
146
  const e = await o.login(s);
@@ -148,7 +148,7 @@ const C = (t, r) => {
148
148
  i(e.message);
149
149
  else {
150
150
  const u = (a = e.data) == null ? void 0 : a.refreshToken;
151
- localStorage.setItem(n.REFRESH_TOKEN, u), await w(e.data);
151
+ localStorage.setItem(n.REFRESH_TOKEN, u), await S(e.data);
152
152
  }
153
153
  return e;
154
154
  },
@@ -159,16 +159,16 @@ const C = (t, r) => {
159
159
  i(e.message);
160
160
  else {
161
161
  const u = (a = e.data) == null ? void 0 : a.refreshToken;
162
- localStorage.setItem(n.REFRESH_TOKEN, u), await w(e.data);
162
+ localStorage.setItem(n.REFRESH_TOKEN, u), await S(e.data);
163
163
  }
164
164
  return e;
165
165
  },
166
166
  signOut: () => {
167
- localStorage.removeItem(n.TOKEN), localStorage.removeItem(n.REFRESH_TOKEN), g(!1), R(void 0), T(void 0);
167
+ localStorage.removeItem(n.TOKEN), localStorage.removeItem(n.REFRESH_TOKEN), g(!1), O(void 0), k(void 0);
168
168
  },
169
169
  resendVerificationEmail: async (s) => (await o.resendVerificationEmail(s)).success,
170
170
  setTokens: (s, e) => {
171
- localStorage.setItem(n.TOKEN, s), localStorage.setItem(n.REFRESH_TOKEN, e), k(s);
171
+ localStorage.setItem(n.TOKEN, s), localStorage.setItem(n.REFRESH_TOKEN, e), R(s);
172
172
  },
173
173
  setPreferredCurrency: async (s) => {
174
174
  const e = await v.setCurrency(s);
@@ -182,13 +182,17 @@ const C = (t, r) => {
182
182
  currency: e.data.currency || d.preferences.currency
183
183
  }
184
184
  };
185
- T(a);
185
+ k(a), h.invalidateQueries({
186
+ queryKey: [K.CONVERT_CURRENCY]
187
+ }), h.invalidateQueries({
188
+ queryKey: [K.CHECK_USER]
189
+ });
186
190
  }
187
191
  return !0;
188
192
  }
189
193
  };
190
194
  };
191
195
  export {
192
- C as authFailurePostMessage,
193
- W as useAwayzAuth
196
+ P as authFailurePostMessage,
197
+ $ as useAwayzAuth
194
198
  };
@@ -5,9 +5,9 @@ import "../../services/noRetryInstance.js";
5
5
  import "../../arrayExtensions-DlcBOj5a.js";
6
6
  import "react";
7
7
  import { EBookingEndpoints as c } from "../../configs/endpoints.js";
8
- import "../../configs/awayzClient.js";
9
8
  import "react/jsx-runtime";
10
9
  import "../../context/AwayzContext.js";
10
+ import "../../configs/awayzClient.js";
11
11
  import "@tanstack/react-query";
12
12
  import { EBookingType as n } from "../../services/trips/TripService.types.js";
13
13
  import '../../assets/_styles5.css';import '../../assets/_styles4.css';import '../../assets/_styles3.css';import '../../assets/_styles2.css';import '../../assets/_styles.css';/* empty css */
@@ -1,11 +1,11 @@
1
- import { useQuery as n, useMutation as i } from "@tanstack/react-query";
1
+ import { useQuery as n, useMutation as s } from "@tanstack/react-query";
2
2
  import "../../arrayExtensions-DlcBOj5a.js";
3
3
  import { E as t, a as u } from "../../AccountService-DdcBI9BS.js";
4
4
  import "react";
5
5
  import "react/jsx-runtime";
6
6
  import "../../context/AwayzContext.js";
7
- import { awayzClient as s } from "../../configs/awayzClient.js";
8
- import { useAwayzContext as K } from "../useAwayzContext.js";
7
+ import { awayzClient as i } from "../../configs/awayzClient.js";
8
+ import { useAwayzContext as q } 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 */
@@ -13,17 +13,17 @@ import '../../assets/_styles5.css';import '../../assets/_styles4.css';import '..
13
13
  /* empty css */
14
14
  /* empty css */
15
15
  import { WalletService as o } from "../../services/wallet/WalletService.js";
16
- const N = () => {
17
- const { user: r } = K(), { data: e } = n({
16
+ const I = () => {
17
+ const { user: r } = q(), { data: e } = n({
18
18
  queryKey: [t.PROGRAMS],
19
19
  queryFn: o.getAwards,
20
20
  placeholderData: []
21
- }), { data: l } = n({
21
+ }), { data: y } = n({
22
22
  queryKey: [t.USER_PROGRAMS, r == null ? void 0 : r.id],
23
23
  queryFn: () => r != null && r.id ? o.getUserAwards(r.id) : [],
24
24
  placeholderData: [],
25
25
  enabled: !!(r != null && r.id)
26
- }), { data: y } = n({
26
+ }), { data: c } = n({
27
27
  queryKey: [t.LINKED_USER_PROGRAMS, r == null ? void 0 : r.id],
28
28
  queryFn: () => r != null && r.id ? o.getLinkedUserAwards(r.id) : [],
29
29
  placeholderData: [],
@@ -32,62 +32,64 @@ const N = () => {
32
32
  queryKey: [t.BANKS],
33
33
  queryFn: o.getBanks,
34
34
  placeholderData: []
35
- }), { data: A } = n({
35
+ }), { data: R } = n({
36
36
  queryKey: [t.CARDS],
37
37
  queryFn: o.getCards,
38
38
  placeholderData: []
39
- }), { data: p } = n({
39
+ }), { data: A } = n({
40
40
  queryKey: [t.USER_CARDS],
41
41
  queryFn: o.getUserCards,
42
42
  placeholderData: []
43
- }), { mutate: P } = i({
43
+ }), { mutate: S } = s({
44
44
  mutationFn: async (a) => {
45
45
  const { mainProgram: d, awardsAmount: m } = typeof a == "string" ? { mainProgram: a, awardsAmount: 0 } : a;
46
46
  await o.addAwardProgram(d, m);
47
47
  },
48
48
  onSuccess: () => {
49
- s.invalidateQueries({
50
- queryKey: [t.PROGRAMS]
49
+ i.invalidateQueries({
50
+ queryKey: [t.LINKED_USER_PROGRAMS]
51
51
  });
52
52
  }
53
- }), { mutate: R } = i({
53
+ }), { mutate: P } = s({
54
54
  mutationFn: async (a) => {
55
55
  await o.removeAwardProgram(a);
56
56
  },
57
57
  onSuccess: () => {
58
- s.invalidateQueries({
59
- queryKey: [t.PROGRAMS]
58
+ i.invalidateQueries({
59
+ queryKey: [t.LINKED_USER_PROGRAMS]
60
60
  });
61
61
  }
62
- }), { mutate: S } = i({
62
+ }), { mutate: p } = s({
63
63
  mutationFn: async (a) => {
64
- const { mainProgram: d, awardsAmount: m } = a, c = e == null ? void 0 : e.find(
65
- (q) => q.mainProgram === d
64
+ const { mainProgram: d, awardsAmount: m } = a, l = e == null ? void 0 : e.find(
65
+ (C) => C.mainProgram === d
66
66
  );
67
- if (!c)
67
+ if (!l)
68
68
  throw new Error("Program not found");
69
- await o.setAwardPoints(c.mainProgram, m);
69
+ await o.setAwardPoints(l.mainProgram, m);
70
70
  },
71
71
  onSuccess: () => {
72
- s.invalidateQueries({
73
- queryKey: [t.PROGRAMS]
72
+ i.invalidateQueries({
73
+ queryKey: [t.LINKED_USER_PROGRAMS]
74
+ }), i.invalidateQueries({
75
+ queryKey: [t.USER_PROGRAMS]
74
76
  });
75
77
  }
76
- }), { mutate: C } = i({
78
+ }), { mutate: E } = s({
77
79
  mutationFn: async (a) => {
78
80
  await o.addCardsToWallet(a);
79
81
  },
80
82
  onSuccess: () => {
81
- s.invalidateQueries({
83
+ i.invalidateQueries({
82
84
  queryKey: [t.USER_CARDS]
83
85
  });
84
86
  }
85
- }), { mutate: w } = i({
87
+ }), { mutate: K } = s({
86
88
  mutationFn: async (a) => {
87
89
  await o.removeCardsFromWallet(a);
88
90
  },
89
91
  onSuccess: () => {
90
- s.invalidateQueries({
92
+ i.invalidateQueries({
91
93
  queryKey: [t.USER_CARDS]
92
94
  });
93
95
  }
@@ -95,8 +97,8 @@ const N = () => {
95
97
  return {
96
98
  // Program Management
97
99
  allPrograms: e || [],
98
- userPrograms: l || [],
99
- linkedUserPrograms: y || [],
100
+ userPrograms: y || [],
101
+ linkedUserPrograms: c || [],
100
102
  hotelPrograms: (e == null ? void 0 : e.filter(
101
103
  (a) => a.category.includes(u.HOTEL)
102
104
  )) || [],
@@ -106,17 +108,17 @@ const N = () => {
106
108
  bankPrograms: (e == null ? void 0 : e.filter(
107
109
  (a) => a.category.includes(u.BANK)
108
110
  )) || [],
109
- updatePoints: S,
110
- addAwardProgram: P,
111
- removeAwardProgram: R,
111
+ updatePoints: p,
112
+ addAwardProgram: S,
113
+ removeAwardProgram: P,
112
114
  // Car Management
113
115
  banks: g || [],
114
- allCards: A || [],
115
- userCards: p || [],
116
- addCards: C,
117
- removeCards: w
116
+ allCards: R || [],
117
+ userCards: A || [],
118
+ addCards: E,
119
+ removeCards: K
118
120
  };
119
121
  };
120
122
  export {
121
- N as useWallet
123
+ I as useWallet
122
124
  };
@@ -1,6 +1,6 @@
1
1
  import { IConvertCurrencyArgs } from './CurrencyService.types';
2
2
  declare class _CurrencyService {
3
- convertCurrency: ({ baseCurrency }: IConvertCurrencyArgs) => Promise<number>;
3
+ convertCurrency: ({ baseCurrency, targetCurrency }: IConvertCurrencyArgs) => Promise<number>;
4
4
  /**
5
5
  * Convert from base currency to target currency for the amount provided
6
6
  * @param param0 IConvertCurrencyArgs
@@ -1,13 +1,13 @@
1
- import '../../assets/_styles5.css';import '../../assets/_styles4.css';import '../../assets/_styles3.css';import '../../assets/_styles2.css';import '../../assets/_styles.css';var u = Object.defineProperty;
2
- var y = (t, r, e) => r in t ? u(t, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[r] = e;
3
- var n = (t, r, e) => y(t, typeof r != "symbol" ? r + "" : r, e);
1
+ import '../../assets/_styles5.css';import '../../assets/_styles4.css';import '../../assets/_styles3.css';import '../../assets/_styles2.css';import '../../assets/_styles.css';var p = Object.defineProperty;
2
+ var m = (t, r, e) => r in t ? p(t, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[r] = e;
3
+ var n = (t, r, e) => m(t, typeof r != "symbol" ? r + "" : r, e);
4
4
  import "../../arrayExtensions-DlcBOj5a.js";
5
- import { A as p, E as m, c as a } from "../../AccountService-DdcBI9BS.js";
5
+ import { A as C, E, c as s } from "../../AccountService-DdcBI9BS.js";
6
6
  import "react";
7
- import { ECurrencyEndpoints as s } from "../../configs/endpoints.js";
7
+ import { ECurrencyEndpoints as a } from "../../configs/endpoints.js";
8
8
  import "react/jsx-runtime";
9
9
  import "../../context/AwayzContext.js";
10
- import { awayzClient as C } from "../../configs/awayzClient.js";
10
+ import { awayzClient as _ } from "../../configs/awayzClient.js";
11
11
  import "@tanstack/react-query";
12
12
  import "../noRetryInstance.js";
13
13
  /* empty css */
@@ -15,26 +15,27 @@ import "../noRetryInstance.js";
15
15
  /* empty css */
16
16
  /* empty css */
17
17
  /* empty css */
18
- class E {
18
+ class d {
19
19
  constructor() {
20
20
  n(this, "convertCurrency", async ({
21
- baseCurrency: r
21
+ baseCurrency: r,
22
+ targetCurrency: e
22
23
  }) => {
23
24
  try {
24
- const { success: e, data: o } = await C.ensureQueryData({
25
- queryKey: [m.CHECK_USER],
26
- queryFn: p.checkUser
25
+ const { success: c, data: o } = await _.ensureQueryData({
26
+ queryKey: [E.CHECK_USER],
27
+ queryFn: C.checkUser
27
28
  });
28
- if (!e)
29
+ if (!c)
29
30
  throw new Error("Failed to fetch user data");
30
- const { userRegion: c } = o, { data: i } = await a.post(s.CURRENCY_CONVERSION, {
31
- target_currency: c.currency,
31
+ const { userRegion: i, preferences: u } = o, { data: y } = await s.post(a.CURRENCY_CONVERSION, {
32
+ target_currency: e ?? u.currency ?? i.currency,
32
33
  base_currency: r
33
34
  });
34
- if (e)
35
- return i.data.conversion_rate;
36
- } catch (e) {
37
- console.error(e);
35
+ if (c)
36
+ return y.data.conversion_rate;
37
+ } catch (c) {
38
+ console.error(c);
38
39
  }
39
40
  return 0;
40
41
  });
@@ -49,24 +50,24 @@ class E {
49
50
  n(this, "convertToCurrency", async ({
50
51
  baseCurrency: r,
51
52
  targetCurrency: e,
52
- amount: o
53
+ amount: c
53
54
  }) => {
54
55
  try {
55
- const { data: c } = await a.post(s.CURRENCY_CONVERSION, {
56
+ const { data: o } = await s.post(a.CURRENCY_CONVERSION, {
56
57
  target_currency: e,
57
58
  base_currency: r,
58
- amount: o
59
+ amount: c
59
60
  });
60
- if (c.success)
61
- return c.data.conversion_result;
62
- } catch (c) {
63
- console.error(c);
61
+ if (o.success)
62
+ return o.data.conversion_result;
63
+ } catch (o) {
64
+ console.error(o);
64
65
  }
65
66
  return 0;
66
67
  });
67
68
  }
68
69
  }
69
- const b = new E();
70
+ const A = new d();
70
71
  export {
71
- b as CurrencyService
72
+ A as CurrencyService
72
73
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@odynn/awayz-core",
3
- "version": "0.4.4",
3
+ "version": "0.4.6",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"