@odynn/awayz-core 0.9.11 → 0.9.12

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,8 +1,8 @@
1
1
  import "../../arrayExtensions-DlcBOj5a.js";
2
- import { c as P } from "../../cashUtils-sBirmFfL.js";
3
- import { e as M, A as l, E as N } from "../../noRetryInstance-C2dRPIQf.js";
4
- import { a as i } from "../../_styles.flight-booking-DEUJthTJ.js";
5
- import { useState as f, useCallback as I, useEffect as S } from "react";
2
+ import { c as M } from "../../cashUtils-sBirmFfL.js";
3
+ import { e as P, A as l, E as N } from "../../noRetryInstance-C2dRPIQf.js";
4
+ import { a as o } from "../../_styles.flight-booking-DEUJthTJ.js";
5
+ import { useState as f, useCallback as I, useEffect as h } from "react";
6
6
  import { awayzClient as O } from "../../configs/awayzClient.js";
7
7
  import { PreferencesService as q } from "../../services/preferences/PreferencesService.js";
8
8
  import "@tanstack/react-query";
@@ -13,57 +13,57 @@ import '../../assets/_styles3.css';import '../../assets/_styles4.css';import '..
13
13
  /* empty css */
14
14
  import "../../context/AwayzContext.js";
15
15
  /* empty css */
16
- import { EAuthFlow as w } from "../../types/EAuthFlow.js";
17
- const G = (t, c) => {
18
- var g, y;
19
- let o = "", d = c;
20
- typeof c == "string" ? o = c : c instanceof M ? (o = c.message, d = {
16
+ import { EAuthFlow as T } from "../../types/EAuthFlow.js";
17
+ const x = (s, c) => {
18
+ var g, S;
19
+ let i = "", y = c;
20
+ typeof c == "string" ? i = c : c instanceof P ? (i = c.message, y = {
21
21
  message: c.message,
22
22
  cause: c.cause,
23
23
  status: c.status,
24
24
  data: (g = c == null ? void 0 : c.response) == null ? void 0 : g.data
25
- }) : o = c.message, (y = window.parent) == null || y.postMessage(
25
+ }) : i = c.message, (S = window.parent) == null || S.postMessage(
26
26
  {
27
27
  type: "auth_error",
28
- details: { message: o, action: t, info: d }
28
+ details: { message: i, action: s, info: y }
29
29
  },
30
30
  "*"
31
31
  );
32
- }, oe = (t) => {
33
- const [c, o] = f(!0), [d, g] = f(!1), [y, A] = f(), [m, h] = f(), [C, _] = f([]), [F, p] = f([]), E = I(
34
- async (s) => {
35
- t != null && t.onSuccess && (t == null || t.onSuccess(s)), t != null && t.onSuccessAsync && await (t == null ? void 0 : t.onSuccessAsync(s)), o(!1), g(!0), A(s.token), h(s.user), O.invalidateQueries();
32
+ }, ie = (s) => {
33
+ const [c, i] = f(!0), [y, g] = f(!1), [S, A] = f(), [m, k] = f(), [C, _] = f([]), [F, p] = f([]), E = I(
34
+ async (t) => {
35
+ s != null && s.onSuccess && (s == null || s.onSuccess(t)), s != null && s.onSuccessAsync && await (s == null ? void 0 : s.onSuccessAsync(t)), i(!1), g(!0), A(t.token), k(t.user), O.invalidateQueries();
36
36
  },
37
- [t]
37
+ [s]
38
38
  ), u = I(
39
- async (s, e) => {
40
- if (t.authFlow !== w.POST_MESSAGE)
41
- return G(e ?? "exchange_token", s);
42
- t != null && t.onError && (t == null || t.onError(s)), t != null && t.onErrorAsync && await (t == null ? void 0 : t.onErrorAsync(s)), o(!1);
39
+ async (t, e) => {
40
+ if (s.authFlow !== T.POST_MESSAGE)
41
+ return x(e ?? "exchange_token", t);
42
+ s != null && s.onError && (s == null || s.onError(t)), s != null && s.onErrorAsync && await (s == null ? void 0 : s.onErrorAsync(t)), i(!1);
43
43
  },
44
- [t]
45
- ), T = async (s, e, r) => {
44
+ [s]
45
+ ), R = async (t, e, r) => {
46
46
  try {
47
- const { success: a, data: n, message: k } = await l.authenticateWithToken(
48
- s,
47
+ const { success: a, data: n, message: w } = await l.authenticateWithToken(
48
+ t,
49
49
  e,
50
50
  r
51
51
  );
52
52
  if (!a) {
53
- u(k);
53
+ u(w);
54
54
  return;
55
55
  }
56
56
  if (!(n != null && n.token)) {
57
57
  u("no awayz token returned after exchanging id token");
58
58
  return;
59
59
  }
60
- localStorage.setItem(i.TOKEN, n.token), await E(n);
61
- const { data: R, ...K } = await l.getRequestLimit();
60
+ localStorage.setItem(o.TOKEN, n.token), await E(n);
61
+ const { data: d, ...K } = await l.getRequestLimit();
62
62
  if (!K.success) {
63
63
  console.error({ reqLimitError: K });
64
64
  return;
65
65
  }
66
- R == null || R.forEach(
66
+ d == null || d.forEach(
67
67
  (H) => window.parent.postMessage(
68
68
  {
69
69
  type: "request_limit",
@@ -75,125 +75,125 @@ const G = (t, c) => {
75
75
  } catch (a) {
76
76
  console.error("error handling message", a);
77
77
  } finally {
78
- o(!1);
78
+ i(!1);
79
79
  }
80
80
  }, v = async () => {
81
81
  try {
82
- const { success: s, data: e } = await O.ensureQueryData({
82
+ const { success: t, data: e } = await O.ensureQueryData({
83
83
  queryKey: [N.CHECK_USER],
84
84
  queryFn: l.checkUser
85
85
  });
86
- if (!s) {
86
+ if (!t) {
87
87
  u(e);
88
88
  return;
89
89
  }
90
90
  await E({
91
91
  user: e,
92
- token: localStorage.getItem(i.TOKEN)
92
+ token: localStorage.getItem(o.TOKEN)
93
93
  });
94
- } catch (s) {
95
- u(s);
94
+ } catch (t) {
95
+ u(t);
96
96
  } finally {
97
- o(!1);
97
+ i(!1);
98
98
  }
99
99
  };
100
- S(() => {
101
- if (t.authFlow !== w.STANDARD) return;
102
- localStorage.getItem(i.TOKEN) ? v() : o(!1);
100
+ h(() => {
101
+ if (s.authFlow !== T.STANDARD) return;
102
+ localStorage.getItem(o.TOKEN) ? v() : i(!1);
103
103
  }, []);
104
104
  const U = async () => {
105
- const s = await l.getRegions();
106
- _(s);
107
- const e = s.map((n) => n.currency), a = Array.from(new Set(e)).map((n) => ({
105
+ const t = await l.getRegions();
106
+ _(t);
107
+ const e = t.map((n) => n.currency), a = Array.from(new Set(e)).map((n) => ({
108
108
  code: n,
109
- symbol: P(n) || n
109
+ symbol: M(n) || n
110
110
  }));
111
111
  p(a);
112
112
  };
113
- return S(() => {
113
+ return h(() => {
114
114
  U();
115
- }, []), S(() => {
116
- if (t.authFlow !== w.QUERY) return;
117
- const s = new URLSearchParams(window.location.search), e = s.get(i.TOKEN), r = s.get(i.REFRESH_TOKEN);
118
- let a = (t.isTestMode ? s.get(i.OVERRIDE_TOKEN_EXCHANGE_ENDPOINT) : void 0) || void 0;
119
- e && T(e, r ?? "", a);
120
- }, []), S(() => {
121
- if (t.authFlow !== w.POST_MESSAGE) return;
122
- const s = async (e) => {
123
- var n;
115
+ }, []), h(() => {
116
+ if (s.authFlow !== T.QUERY) return;
117
+ const t = new URLSearchParams(window.location.search), e = t.get(o.TOKEN), r = t.get(o.REFRESH_TOKEN);
118
+ let a = (s.isTestMode ? t.get(o.OVERRIDE_TOKEN_EXCHANGE_ENDPOINT) : void 0) || void 0;
119
+ e && R(e, r ?? "", a);
120
+ }, []), h(() => {
121
+ if (s.authFlow !== T.POST_MESSAGE) return;
122
+ const t = async (e) => {
123
+ var w;
124
124
  if (e.data.type !== "auth") return;
125
- const r = (n = e.data) == null ? void 0 : n.idToken, a = e.data.refreshToken;
125
+ const r = (w = e.data) == null ? void 0 : w.idToken, a = e.data.refreshToken, n = s.isTestMode ? e.data.overrideTokenExchangeEndpoint : void 0;
126
126
  if (!r) {
127
- const k = `received message ${JSON.stringify(
127
+ const d = `received message ${JSON.stringify(
128
128
  e.data
129
129
  )}
130
130
  no idToken in body`;
131
- u(k);
131
+ u(d);
132
132
  return;
133
133
  }
134
- localStorage.setItem(i.REFRESH_TOKEN, a), await T(r, a);
134
+ localStorage.setItem(o.REFRESH_TOKEN, a), await R(r, a, n);
135
135
  };
136
- return window.addEventListener("message", s), window.parent && window.parent.postMessage(
136
+ return window.addEventListener("message", t), window.parent && window.parent.postMessage(
137
137
  {
138
138
  type: "ready"
139
139
  /* READY */
140
140
  },
141
141
  "*"
142
142
  ), () => {
143
- window.removeEventListener("message", s);
143
+ window.removeEventListener("message", t);
144
144
  };
145
145
  }, []), {
146
146
  isAuthenticating: c,
147
- isAuthenticated: d,
148
- token: y,
147
+ isAuthenticated: y,
148
+ token: S,
149
149
  user: m,
150
150
  supportedRegions: C,
151
151
  supportedCurrencies: F,
152
- signIn: async (s) => {
152
+ signIn: async (t) => {
153
153
  var r;
154
- const e = await l.login(s);
154
+ const e = await l.login(t);
155
155
  if (!e.success)
156
156
  u(e.message);
157
157
  else {
158
158
  const a = (r = e.data) == null ? void 0 : r.refreshToken;
159
- localStorage.setItem(i.REFRESH_TOKEN, a), await E(e.data);
159
+ localStorage.setItem(o.REFRESH_TOKEN, a), await E(e.data);
160
160
  }
161
161
  return e;
162
162
  },
163
- signUp: async (s) => {
163
+ signUp: async (t) => {
164
164
  var r;
165
- const e = await l.signUp(s);
165
+ const e = await l.signUp(t);
166
166
  if (!e.success)
167
167
  u(e.message);
168
168
  else {
169
169
  const a = (r = e.data) == null ? void 0 : r.refreshToken;
170
- localStorage.setItem(i.REFRESH_TOKEN, a), await E(e.data);
170
+ localStorage.setItem(o.REFRESH_TOKEN, a), await E(e.data);
171
171
  }
172
172
  return e;
173
173
  },
174
174
  signOut: () => {
175
- localStorage.removeItem(i.TOKEN), localStorage.removeItem(i.REFRESH_TOKEN), g(!1), A(void 0), h(void 0);
175
+ localStorage.removeItem(o.TOKEN), localStorage.removeItem(o.REFRESH_TOKEN), g(!1), A(void 0), k(void 0);
176
176
  },
177
- continueWithGoogle: async (s, e) => {
177
+ continueWithGoogle: async (t, e) => {
178
178
  var a;
179
179
  const r = await l.getOrCreateGoogleUser(
180
- s,
180
+ t,
181
181
  e
182
182
  );
183
183
  if (!r.success)
184
184
  u(r.message);
185
185
  else {
186
186
  const n = (a = r.data) == null ? void 0 : a.refreshToken;
187
- localStorage.setItem(i.REFRESH_TOKEN, n), await E(r.data);
187
+ localStorage.setItem(o.REFRESH_TOKEN, n), await E(r.data);
188
188
  }
189
189
  return r;
190
190
  },
191
- resendVerificationEmail: async (s) => (await l.resendVerificationEmail(s)).success,
192
- setTokens: (s, e) => {
193
- localStorage.setItem(i.TOKEN, s), localStorage.setItem(i.REFRESH_TOKEN, e), T(s, e);
191
+ resendVerificationEmail: async (t) => (await l.resendVerificationEmail(t)).success,
192
+ setTokens: (t, e) => {
193
+ localStorage.setItem(o.TOKEN, t), localStorage.setItem(o.REFRESH_TOKEN, e), R(t, e);
194
194
  },
195
- setPreferredCurrency: async (s) => {
196
- const e = await q.setCurrency(s);
195
+ setPreferredCurrency: async (t) => {
196
+ const e = await q.setCurrency(t);
197
197
  if (!e.success || !e.data)
198
198
  return console.error("Failed to set preferred currency:", e), !1;
199
199
  if (m) {
@@ -204,7 +204,7 @@ const G = (t, c) => {
204
204
  currency: e.data.currency || m.preferences.currency
205
205
  }
206
206
  };
207
- h(r), O.invalidateQueries({
207
+ k(r), O.invalidateQueries({
208
208
  queryKey: [N.CHECK_USER]
209
209
  });
210
210
  }
@@ -213,6 +213,6 @@ const G = (t, c) => {
213
213
  };
214
214
  };
215
215
  export {
216
- G as authFailurePostMessage,
217
- oe as useAwayzAuth
216
+ x as authFailurePostMessage,
217
+ ie as useAwayzAuth
218
218
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@odynn/awayz-core",
3
- "version": "0.9.11",
3
+ "version": "0.9.12",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"