@odynn/awayz-core 0.4.5 → 0.4.7

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";
5
- import { PreferencesService as v } from "../../services/preferences/PreferencesService.js";
2
+ import { f as v, d as n, A as o, E as K } from "../../AccountService-DdcBI9BS.js";
3
+ import { useState as E, useCallback as O, useEffect as w } from "react";
4
+ import { awayzClient as R } from "../../configs/awayzClient.js";
5
+ import { PreferencesService as C } from "../../services/preferences/PreferencesService.js";
6
6
  import { EAuthFlow as h } from "../../types/EAuthFlow.js";
7
- const C = (t, r) => {
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 v ? (c = r.message, m = {
11
11
  message: r.message,
12
12
  cause: r.cause,
13
13
  status: r.status,
@@ -15,20 +15,20 @@ 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
22
  }, W = (t) => {
23
- const [r, c] = m(!0), [E, g] = m(!1), [y, R] = m(), [d, T] = m(), [I, K] = m([]), w = A(
23
+ const [r, c] = E(!0), [m, g] = E(!1), [y, A] = E(), [d, T] = E(), [I, N] = E([]), S = O(
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), A(s.token), T(s.user), R.invalidateQueries();
26
26
  },
27
27
  [t]
28
- ), i = A(
28
+ ), i = O(
29
29
  async (s, e) => {
30
30
  if (t.authFlow !== h.POST_MESSAGE)
31
- return C(e ?? "exchange_token", s);
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]
@@ -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);
46
+ localStorage.setItem(n.TOKEN, a.token), await S(a);
47
47
  const { data: f, ...l } = await o.getRequestLimit();
48
48
  if (!l.success) {
49
49
  console.error({ reqLimitError: l });
50
50
  return;
51
51
  }
52
52
  f == null || f.forEach(
53
- (_) => window.parent.postMessage(
53
+ (U) => window.parent.postMessage(
54
54
  {
55
55
  type: "request_limit",
56
- limit: _
56
+ limit: U
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
+ }, F = 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 R.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,22 +83,22 @@ const C = (t, r) => {
83
83
  c(!1);
84
84
  }
85
85
  };
86
- S(() => {
86
+ w(() => {
87
87
  if (t.authFlow !== h.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 ? F() : c(!1);
90
90
  }, []);
91
- const F = async () => {
91
+ const _ = async () => {
92
92
  const s = await o.getRegions();
93
- K(s);
93
+ N(s);
94
94
  };
95
- return S(() => {
96
- F();
97
- }, []), S(() => {
95
+ return w(() => {
96
+ _();
97
+ }, []), w(() => {
98
98
  if (t.authFlow !== h.QUERY) return;
99
99
  const e = new URLSearchParams(window.location.search).get(n.TOKEN);
100
100
  e && k(e);
101
- }, []), S(() => {
101
+ }, []), w(() => {
102
102
  if (t.authFlow !== h.POST_MESSAGE) return;
103
103
  const s = async (e) => {
104
104
  var f;
@@ -137,7 +137,7 @@ 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
143
  supportedRegions: I,
@@ -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,19 +159,19 @@ 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), A(void 0), T(void 0);
168
168
  },
169
169
  resendVerificationEmail: async (s) => (await o.resendVerificationEmail(s)).success,
170
170
  setTokens: (s, e) => {
171
171
  localStorage.setItem(n.TOKEN, s), localStorage.setItem(n.REFRESH_TOKEN, e), k(s);
172
172
  },
173
173
  setPreferredCurrency: async (s) => {
174
- const e = await v.setCurrency(s);
174
+ const e = await C.setCurrency(s);
175
175
  if (!e.success || !e.data)
176
176
  return console.error("Failed to set preferred currency:", e), !1;
177
177
  if (d) {
@@ -182,13 +182,15 @@ const C = (t, r) => {
182
182
  currency: e.data.currency || d.preferences.currency
183
183
  }
184
184
  };
185
- T(a);
185
+ T(a), R.invalidateQueries({
186
+ queryKey: [K.CHECK_USER]
187
+ });
186
188
  }
187
189
  return !0;
188
190
  }
189
191
  };
190
192
  };
191
193
  export {
192
- C as authFailurePostMessage,
194
+ P as authFailurePostMessage,
193
195
  W as useAwayzAuth
194
196
  };
@@ -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,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.5",
3
+ "version": "0.4.7",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"