@odynn/awayz-core 0.4.6 → 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.
@@ -1,13 +1,13 @@
1
1
  import "../../arrayExtensions-DlcBOj5a.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
- import { PreferencesService as v } from "../../services/preferences/PreferencesService.js";
6
- import { EAuthFlow as T } from "../../types/EAuthFlow.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
+ import { EAuthFlow as h } from "../../types/EAuthFlow.js";
7
7
  const P = (t, r) => {
8
8
  var g, y;
9
9
  let c = "", m = r;
10
- typeof r == "string" ? c = r : r instanceof U ? (c = r.message, m = {
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,
@@ -19,20 +19,20 @@ const P = (t, r) => {
19
19
  },
20
20
  "*"
21
21
  );
22
- }, $ = (t) => {
23
- const [r, c] = E(!0), [m, g] = E(!1), [y, O] = E(), [d, k] = E(), [N, I] = E([]), S = A(
22
+ }, W = (t) => {
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), O(s.token), k(s.user), h.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
- if (t.authFlow !== T.POST_MESSAGE)
30
+ if (t.authFlow !== h.POST_MESSAGE)
31
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
- ), R = async (s) => {
35
+ ), k = async (s) => {
36
36
  try {
37
37
  const { success: e, data: a, message: u } = await o.authenticateWithToken(s);
38
38
  if (!e) {
@@ -44,16 +44,16 @@ const P = (t, r) => {
44
44
  return;
45
45
  }
46
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 });
47
+ const { data: f, ...l } = await o.getRequestLimit();
48
+ if (!l.success) {
49
+ console.error({ reqLimitError: l });
50
50
  return;
51
51
  }
52
- l == null || l.forEach(
53
- (C) => window.parent.postMessage(
52
+ f == null || f.forEach(
53
+ (U) => window.parent.postMessage(
54
54
  {
55
55
  type: "request_limit",
56
- limit: C
56
+ limit: U
57
57
  },
58
58
  "*"
59
59
  )
@@ -63,9 +63,9 @@ const P = (t, r) => {
63
63
  } finally {
64
64
  c(!1);
65
65
  }
66
- }, _ = async () => {
66
+ }, F = async () => {
67
67
  try {
68
- const { success: s, data: e } = await h.ensureQueryData({
68
+ const { success: s, data: e } = await R.ensureQueryData({
69
69
  queryKey: [K.CHECK_USER],
70
70
  queryFn: o.checkUser
71
71
  });
@@ -84,47 +84,47 @@ const P = (t, r) => {
84
84
  }
85
85
  };
86
86
  w(() => {
87
- if (t.authFlow !== T.STANDARD) return;
87
+ if (t.authFlow !== h.STANDARD) return;
88
88
  const s = localStorage.getItem(n.TOKEN), e = localStorage.getItem(n.REFRESH_TOKEN);
89
- s && e ? _() : 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
- I(s);
93
+ N(s);
94
94
  };
95
95
  return w(() => {
96
- F();
96
+ _();
97
97
  }, []), w(() => {
98
- if (t.authFlow !== T.QUERY) return;
98
+ if (t.authFlow !== h.QUERY) return;
99
99
  const e = new URLSearchParams(window.location.search).get(n.TOKEN);
100
- e && R(e);
100
+ e && k(e);
101
101
  }, []), w(() => {
102
- if (t.authFlow !== T.POST_MESSAGE) return;
102
+ if (t.authFlow !== h.POST_MESSAGE) return;
103
103
  const s = async (e) => {
104
- var l;
104
+ var f;
105
105
  if (e.data.type !== "auth") return;
106
- const a = (l = e.data) == null ? void 0 : l.idToken, u = e.data.refreshToken;
106
+ const a = (f = e.data) == null ? void 0 : f.idToken, u = e.data.refreshToken;
107
107
  if (!a) {
108
- const f = `received message ${JSON.stringify(
108
+ const l = `received message ${JSON.stringify(
109
109
  e.data
110
110
  )}
111
111
  no idToken in body`;
112
- i(f);
112
+ i(l);
113
113
  return;
114
114
  }
115
115
  if (!u) {
116
- const f = `received message: ${JSON.stringify(
116
+ const l = `received message: ${JSON.stringify(
117
117
  e.data
118
118
  )}
119
119
  no refreshToken in body`;
120
120
  i(
121
- f,
121
+ l,
122
122
  "refresh_token"
123
123
  /* REFRESH */
124
124
  );
125
125
  return;
126
126
  }
127
- localStorage.setItem(n.REFRESH_TOKEN, u), await R(a);
127
+ localStorage.setItem(n.REFRESH_TOKEN, u), await k(a);
128
128
  };
129
129
  return window.addEventListener("message", s), window.parent && window.parent.postMessage(
130
130
  {
@@ -140,7 +140,7 @@ const P = (t, r) => {
140
140
  isAuthenticated: m,
141
141
  token: y,
142
142
  user: d,
143
- supportedRegions: N,
143
+ supportedRegions: I,
144
144
  signIn: async (s) => {
145
145
  var a;
146
146
  const e = await o.login(s);
@@ -164,14 +164,14 @@ const P = (t, r) => {
164
164
  return e;
165
165
  },
166
166
  signOut: () => {
167
- localStorage.removeItem(n.TOKEN), localStorage.removeItem(n.REFRESH_TOKEN), g(!1), O(void 0), k(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
- localStorage.setItem(n.TOKEN, s), localStorage.setItem(n.REFRESH_TOKEN, e), R(s);
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,9 +182,7 @@ const P = (t, r) => {
182
182
  currency: e.data.currency || d.preferences.currency
183
183
  }
184
184
  };
185
- k(a), h.invalidateQueries({
186
- queryKey: [K.CONVERT_CURRENCY]
187
- }), h.invalidateQueries({
185
+ T(a), R.invalidateQueries({
188
186
  queryKey: [K.CHECK_USER]
189
187
  });
190
188
  }
@@ -194,5 +192,5 @@ const P = (t, r) => {
194
192
  };
195
193
  export {
196
194
  P as authFailurePostMessage,
197
- $ as useAwayzAuth
195
+ W as useAwayzAuth
198
196
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@odynn/awayz-core",
3
- "version": "0.4.6",
3
+ "version": "0.4.7",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"