@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
|
|
3
|
-
import { e as
|
|
4
|
-
import { a as
|
|
5
|
-
import { useState as f, useCallback as I, useEffect as
|
|
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
|
|
17
|
-
const
|
|
18
|
-
var g,
|
|
19
|
-
let
|
|
20
|
-
typeof c == "string" ?
|
|
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
|
-
}) :
|
|
25
|
+
}) : i = c.message, (S = window.parent) == null || S.postMessage(
|
|
26
26
|
{
|
|
27
27
|
type: "auth_error",
|
|
28
|
-
details: { message:
|
|
28
|
+
details: { message: i, action: s, info: y }
|
|
29
29
|
},
|
|
30
30
|
"*"
|
|
31
31
|
);
|
|
32
|
-
},
|
|
33
|
-
const [c,
|
|
34
|
-
async (
|
|
35
|
-
|
|
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
|
-
[
|
|
37
|
+
[s]
|
|
38
38
|
), u = I(
|
|
39
|
-
async (
|
|
40
|
-
if (
|
|
41
|
-
return
|
|
42
|
-
|
|
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
|
-
[
|
|
45
|
-
),
|
|
44
|
+
[s]
|
|
45
|
+
), R = async (t, e, r) => {
|
|
46
46
|
try {
|
|
47
|
-
const { success: a, data: n, message:
|
|
48
|
-
|
|
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(
|
|
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(
|
|
61
|
-
const { data:
|
|
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
|
-
|
|
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
|
-
|
|
78
|
+
i(!1);
|
|
79
79
|
}
|
|
80
80
|
}, v = async () => {
|
|
81
81
|
try {
|
|
82
|
-
const { success:
|
|
82
|
+
const { success: t, data: e } = await O.ensureQueryData({
|
|
83
83
|
queryKey: [N.CHECK_USER],
|
|
84
84
|
queryFn: l.checkUser
|
|
85
85
|
});
|
|
86
|
-
if (!
|
|
86
|
+
if (!t) {
|
|
87
87
|
u(e);
|
|
88
88
|
return;
|
|
89
89
|
}
|
|
90
90
|
await E({
|
|
91
91
|
user: e,
|
|
92
|
-
token: localStorage.getItem(
|
|
92
|
+
token: localStorage.getItem(o.TOKEN)
|
|
93
93
|
});
|
|
94
|
-
} catch (
|
|
95
|
-
u(
|
|
94
|
+
} catch (t) {
|
|
95
|
+
u(t);
|
|
96
96
|
} finally {
|
|
97
|
-
|
|
97
|
+
i(!1);
|
|
98
98
|
}
|
|
99
99
|
};
|
|
100
|
-
|
|
101
|
-
if (
|
|
102
|
-
localStorage.getItem(
|
|
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
|
|
106
|
-
_(
|
|
107
|
-
const e =
|
|
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:
|
|
109
|
+
symbol: M(n) || n
|
|
110
110
|
}));
|
|
111
111
|
p(a);
|
|
112
112
|
};
|
|
113
|
-
return
|
|
113
|
+
return h(() => {
|
|
114
114
|
U();
|
|
115
|
-
}, []),
|
|
116
|
-
if (
|
|
117
|
-
const
|
|
118
|
-
let a = (
|
|
119
|
-
e &&
|
|
120
|
-
}, []),
|
|
121
|
-
if (
|
|
122
|
-
const
|
|
123
|
-
var
|
|
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 = (
|
|
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
|
|
127
|
+
const d = `received message ${JSON.stringify(
|
|
128
128
|
e.data
|
|
129
129
|
)}
|
|
130
130
|
no idToken in body`;
|
|
131
|
-
u(
|
|
131
|
+
u(d);
|
|
132
132
|
return;
|
|
133
133
|
}
|
|
134
|
-
localStorage.setItem(
|
|
134
|
+
localStorage.setItem(o.REFRESH_TOKEN, a), await R(r, a, n);
|
|
135
135
|
};
|
|
136
|
-
return window.addEventListener("message",
|
|
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",
|
|
143
|
+
window.removeEventListener("message", t);
|
|
144
144
|
};
|
|
145
145
|
}, []), {
|
|
146
146
|
isAuthenticating: c,
|
|
147
|
-
isAuthenticated:
|
|
148
|
-
token:
|
|
147
|
+
isAuthenticated: y,
|
|
148
|
+
token: S,
|
|
149
149
|
user: m,
|
|
150
150
|
supportedRegions: C,
|
|
151
151
|
supportedCurrencies: F,
|
|
152
|
-
signIn: async (
|
|
152
|
+
signIn: async (t) => {
|
|
153
153
|
var r;
|
|
154
|
-
const e = await l.login(
|
|
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(
|
|
159
|
+
localStorage.setItem(o.REFRESH_TOKEN, a), await E(e.data);
|
|
160
160
|
}
|
|
161
161
|
return e;
|
|
162
162
|
},
|
|
163
|
-
signUp: async (
|
|
163
|
+
signUp: async (t) => {
|
|
164
164
|
var r;
|
|
165
|
-
const e = await l.signUp(
|
|
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(
|
|
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(
|
|
175
|
+
localStorage.removeItem(o.TOKEN), localStorage.removeItem(o.REFRESH_TOKEN), g(!1), A(void 0), k(void 0);
|
|
176
176
|
},
|
|
177
|
-
continueWithGoogle: async (
|
|
177
|
+
continueWithGoogle: async (t, e) => {
|
|
178
178
|
var a;
|
|
179
179
|
const r = await l.getOrCreateGoogleUser(
|
|
180
|
-
|
|
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(
|
|
187
|
+
localStorage.setItem(o.REFRESH_TOKEN, n), await E(r.data);
|
|
188
188
|
}
|
|
189
189
|
return r;
|
|
190
190
|
},
|
|
191
|
-
resendVerificationEmail: async (
|
|
192
|
-
setTokens: (
|
|
193
|
-
localStorage.setItem(
|
|
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 (
|
|
196
|
-
const e = await q.setCurrency(
|
|
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
|
-
|
|
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
|
-
|
|
217
|
-
|
|
216
|
+
x as authFailurePostMessage,
|
|
217
|
+
ie as useAwayzAuth
|
|
218
218
|
};
|