tempest-react-sdk 0.83.0 → 0.85.0
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.
- package/README.md +1 -0
- package/dist/auth/create-tempest-auth.cjs +1 -1
- package/dist/auth/create-tempest-auth.cjs.map +1 -1
- package/dist/auth/create-tempest-auth.js +294 -178
- package/dist/auth/create-tempest-auth.js.map +1 -1
- package/dist/components/Markdown/Markdown.cjs +1 -1
- package/dist/components/Markdown/Markdown.cjs.map +1 -1
- package/dist/components/Markdown/Markdown.js +29 -28
- package/dist/components/Markdown/Markdown.js.map +1 -1
- package/dist/components/Markdown/markdown-parse.cjs +6 -5
- package/dist/components/Markdown/markdown-parse.cjs.map +1 -1
- package/dist/components/Markdown/markdown-parse.js +195 -160
- package/dist/components/Markdown/markdown-parse.js.map +1 -1
- package/dist/http/resumable-upload.cjs +1 -1
- package/dist/http/resumable-upload.cjs.map +1 -1
- package/dist/http/resumable-upload.js +1 -1
- package/dist/http/resumable-upload.js.map +1 -1
- package/dist/http/upload-with-progress.cjs +1 -1
- package/dist/http/upload-with-progress.cjs.map +1 -1
- package/dist/http/upload-with-progress.js +47 -39
- package/dist/http/upload-with-progress.js.map +1 -1
- package/dist/payments/PixCheckout.cjs +2 -0
- package/dist/payments/PixCheckout.cjs.map +1 -0
- package/dist/payments/PixCheckout.js +171 -0
- package/dist/payments/PixCheckout.js.map +1 -0
- package/dist/payments/PixCheckout.module.cjs +3 -0
- package/dist/payments/PixCheckout.module.cjs.map +1 -0
- package/dist/payments/PixCheckout.module.js +22 -0
- package/dist/payments/PixCheckout.module.js.map +1 -0
- package/dist/payments/format.cjs +2 -0
- package/dist/payments/format.cjs.map +1 -0
- package/dist/payments/format.js +9 -0
- package/dist/payments/format.js.map +1 -0
- package/dist/payments/mercado-pago.cjs +2 -0
- package/dist/payments/mercado-pago.cjs.map +1 -0
- package/dist/payments/mercado-pago.js +27 -0
- package/dist/payments/mercado-pago.js.map +1 -0
- package/dist/payments/outcome.cjs +2 -0
- package/dist/payments/outcome.cjs.map +1 -0
- package/dist/payments/outcome.js +111 -0
- package/dist/payments/outcome.js.map +1 -0
- package/dist/payments/types.cjs +2 -0
- package/dist/payments/types.cjs.map +1 -0
- package/dist/payments/types.js +16 -0
- package/dist/payments/types.js.map +1 -0
- package/dist/payments/use-mercado-pago-card.cjs +2 -0
- package/dist/payments/use-mercado-pago-card.cjs.map +1 -0
- package/dist/payments/use-mercado-pago-card.js +128 -0
- package/dist/payments/use-mercado-pago-card.js.map +1 -0
- package/dist/payments/use-pix-charge.cjs +2 -0
- package/dist/payments/use-pix-charge.cjs.map +1 -0
- package/dist/payments/use-pix-charge.js +71 -0
- package/dist/payments/use-pix-charge.js.map +1 -0
- package/dist/query/offline-persistence.cjs +1 -1
- package/dist/query/offline-persistence.cjs.map +1 -1
- package/dist/query/offline-persistence.js +100 -54
- package/dist/query/offline-persistence.js.map +1 -1
- package/dist/styles/PixCheckout.css +2 -0
- package/dist/styles/component/PixCheckout.css +18 -0
- package/dist/styles/manifest.json +6 -0
- package/dist/styles/payments.css +18 -0
- package/dist/styles.css +1 -1
- package/dist/sw/cache.cjs +1 -1
- package/dist/sw/cache.cjs.map +1 -1
- package/dist/sw/cache.js +1 -1
- package/dist/sw/cache.js.map +1 -1
- package/dist/tempest-react-sdk.cjs +1 -1
- package/dist/tempest-react-sdk.d.ts +913 -29
- package/dist/tempest-react-sdk.js +104 -97
- package/package.json +1 -1
|
@@ -3,10 +3,11 @@ import { SessionSupersededError as t } from "../http/errors.js";
|
|
|
3
3
|
import { createApiClient as n } from "../http/api-client.js";
|
|
4
4
|
import { bindSessionIdentity as r } from "./session-identity.js";
|
|
5
5
|
import { createAuthStore as i } from "./create-auth-store.js";
|
|
6
|
-
import {
|
|
6
|
+
import { decodeJWT as a } from "./jwt.js";
|
|
7
|
+
import { createRefreshQueue as o } from "./refresh-queue.js";
|
|
7
8
|
//#region src/auth/create-tempest-auth.ts
|
|
8
|
-
var
|
|
9
|
-
function
|
|
9
|
+
var s = 1e4, c = 1e4, l = "sign-in-pending";
|
|
10
|
+
function u(e, t) {
|
|
10
11
|
return e.length === 0 ? Promise.resolve() : new Promise((n) => {
|
|
11
12
|
let r = setTimeout(n, t);
|
|
12
13
|
Promise.allSettled(e).then(() => {
|
|
@@ -14,64 +15,73 @@ function c(e, t) {
|
|
|
14
15
|
});
|
|
15
16
|
});
|
|
16
17
|
}
|
|
17
|
-
function
|
|
18
|
+
function d() {
|
|
18
19
|
let e = globalThis.crypto;
|
|
19
20
|
return typeof e?.randomUUID == "function" ? e.randomUUID() : `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
|
|
20
21
|
}
|
|
21
|
-
var
|
|
22
|
+
var f = /* @__PURE__ */ new Set();
|
|
22
23
|
function ee(t) {
|
|
23
|
-
e() && !
|
|
24
|
+
e() && !f.has(t) && (f.add(t), console.warn("[tempest-react-sdk] createTempestAuth: withCredentials is set without logoutPath. logout() cannot clear the HttpOnly refresh cookie, so the next refresh() — the boot restore — signs the same account back in. Pass logoutPath (the backend's cookie logout route) so the server revokes it."));
|
|
24
25
|
}
|
|
25
26
|
function te(e) {
|
|
27
|
+
if (!e) return null;
|
|
28
|
+
try {
|
|
29
|
+
let { sub: t } = a(e).payload;
|
|
30
|
+
return typeof t == "string" && t !== "" ? t : null;
|
|
31
|
+
} catch {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function ne(e) {
|
|
26
36
|
let t = e ?? {};
|
|
27
37
|
return {
|
|
28
38
|
token: t.access_token,
|
|
29
39
|
refreshToken: t.refresh_token
|
|
30
40
|
};
|
|
31
41
|
}
|
|
32
|
-
function
|
|
33
|
-
let { baseURL:
|
|
34
|
-
|
|
35
|
-
let
|
|
36
|
-
name:
|
|
37
|
-
storage:
|
|
38
|
-
}),
|
|
39
|
-
function
|
|
40
|
-
return typeof window > "u" ? null :
|
|
41
|
-
}
|
|
42
|
-
function
|
|
43
|
-
return
|
|
44
|
-
}
|
|
45
|
-
let
|
|
46
|
-
function
|
|
47
|
-
|
|
48
|
-
let t =
|
|
49
|
-
t && (e ? t.setItem(
|
|
50
|
-
}
|
|
51
|
-
let
|
|
52
|
-
function
|
|
53
|
-
|
|
54
|
-
let t =
|
|
55
|
-
t && (e ? t.setItem(
|
|
56
|
-
}
|
|
57
|
-
let
|
|
58
|
-
async function
|
|
59
|
-
if (!
|
|
60
|
-
let e =
|
|
42
|
+
function p(a) {
|
|
43
|
+
let { baseURL: f, prefix: p, loginPath: re = "/api/auth/login", refreshPath: m = "/api/auth/refresh", logoutPath: h, onLogoutError: ie, mePath: ae, storeName: g = "tempest-auth", storage: _ = "local", withCredentials: v = !1, csrf: oe, fetcher: se, parseTokens: y = ne, parseUser: ce, refreshBody: b = (e) => e ? { refresh_token: e } : void 0, retry: le, redirectTo: ue, onSessionEnd: de } = a;
|
|
44
|
+
v && !h && ee(g);
|
|
45
|
+
let x = i({
|
|
46
|
+
name: g,
|
|
47
|
+
storage: _
|
|
48
|
+
}), S = `${g}-refresh`;
|
|
49
|
+
function C() {
|
|
50
|
+
return typeof window > "u" ? null : _ === "session" ? window.sessionStorage : window.localStorage;
|
|
51
|
+
}
|
|
52
|
+
function w() {
|
|
53
|
+
return C()?.getItem(S) ?? null;
|
|
54
|
+
}
|
|
55
|
+
let T = w();
|
|
56
|
+
function E(e) {
|
|
57
|
+
T = e;
|
|
58
|
+
let t = C();
|
|
59
|
+
t && (e ? t.setItem(S, e) : t.removeItem(S));
|
|
60
|
+
}
|
|
61
|
+
let D = `${g}-lineage`, fe = `tempest-react-sdk:${g}:refresh`, pe = `tempest-react-sdk:${g}:sign-in`, O = C()?.getItem(D) ?? null;
|
|
62
|
+
function k(e) {
|
|
63
|
+
O = e;
|
|
64
|
+
let t = C();
|
|
65
|
+
t && (e ? t.setItem(D, e) : t.removeItem(D));
|
|
66
|
+
}
|
|
67
|
+
let A = () => x.getState(), j = () => A().token;
|
|
68
|
+
async function me() {
|
|
69
|
+
if (!ae) return A().user;
|
|
70
|
+
let e = M, n;
|
|
61
71
|
try {
|
|
62
|
-
n = await
|
|
72
|
+
n = await Y.get(ae, { skipAuthRetry: !0 });
|
|
63
73
|
} catch (n) {
|
|
64
|
-
throw
|
|
74
|
+
throw M === e ? n : new t();
|
|
65
75
|
}
|
|
66
|
-
if (
|
|
67
|
-
return
|
|
76
|
+
if (M !== e || !J().continues) throw new t();
|
|
77
|
+
return A().setUser(n), n;
|
|
68
78
|
}
|
|
69
|
-
let
|
|
70
|
-
function
|
|
79
|
+
let M = 0, he = Promise.resolve(), N = 0, P = /* @__PURE__ */ new Set(), F = 0, I = /* @__PURE__ */ new Set(), L = /* @__PURE__ */ new Set(), R = /* @__PURE__ */ new Set();
|
|
80
|
+
function z(e) {
|
|
71
81
|
let t = e.then(() => void 0, () => void 0);
|
|
72
|
-
return
|
|
82
|
+
return L.add(t), t.then(() => L.delete(t)), e;
|
|
73
83
|
}
|
|
74
|
-
function
|
|
84
|
+
function ge(t) {
|
|
75
85
|
e() && console.warn("[tempest-react-sdk] createTempestAuth: logoutPath revocation failed", t);
|
|
76
86
|
try {
|
|
77
87
|
ie?.(t);
|
|
@@ -79,121 +89,224 @@ function d(u) {
|
|
|
79
89
|
return;
|
|
80
90
|
}
|
|
81
91
|
}
|
|
82
|
-
function
|
|
92
|
+
function _e(e) {
|
|
83
93
|
let t = (async () => {
|
|
84
94
|
try {
|
|
85
95
|
await e();
|
|
86
96
|
} catch (e) {
|
|
87
|
-
|
|
97
|
+
ge(e);
|
|
88
98
|
}
|
|
89
99
|
})();
|
|
90
|
-
return
|
|
100
|
+
return I.add(t), t.then(() => I.delete(t)), t;
|
|
91
101
|
}
|
|
92
|
-
function
|
|
93
|
-
|
|
102
|
+
function B(e, t) {
|
|
103
|
+
h && !v && t && _e(() => V(e).post(h, { body: b(t) }));
|
|
94
104
|
}
|
|
95
|
-
function
|
|
105
|
+
function V(e) {
|
|
96
106
|
return n({
|
|
97
|
-
baseURL:
|
|
98
|
-
prefix:
|
|
99
|
-
withCredentials:
|
|
100
|
-
csrf:
|
|
101
|
-
fetcher:
|
|
107
|
+
baseURL: f,
|
|
108
|
+
prefix: p,
|
|
109
|
+
withCredentials: v,
|
|
110
|
+
csrf: oe,
|
|
111
|
+
fetcher: se,
|
|
102
112
|
getToken: () => e
|
|
103
113
|
});
|
|
104
114
|
}
|
|
105
|
-
function
|
|
106
|
-
|
|
115
|
+
function ve() {
|
|
116
|
+
M += 1, W = o(ye);
|
|
107
117
|
}
|
|
108
|
-
async function
|
|
109
|
-
let e =
|
|
110
|
-
|
|
118
|
+
async function ye() {
|
|
119
|
+
let e = j(), n = M;
|
|
120
|
+
R.add(n);
|
|
121
|
+
let r;
|
|
122
|
+
try {
|
|
123
|
+
r = await H(() => Se(e)), r === l && (await xe(), r = await H(() => Se(e)));
|
|
124
|
+
} finally {
|
|
125
|
+
R.delete(n);
|
|
126
|
+
}
|
|
127
|
+
if (r === l) throw new t();
|
|
128
|
+
if (!r) return;
|
|
129
|
+
let i = r;
|
|
111
130
|
try {
|
|
112
|
-
|
|
131
|
+
if (M !== n || F > 0) throw B(i.token ?? null, i.refreshToken), new t();
|
|
132
|
+
await G(K(i));
|
|
113
133
|
} finally {
|
|
114
|
-
|
|
134
|
+
i.release();
|
|
115
135
|
}
|
|
116
136
|
}
|
|
117
|
-
async function
|
|
118
|
-
let t =
|
|
137
|
+
async function H(e) {
|
|
138
|
+
let t = U();
|
|
119
139
|
if (!t) return e();
|
|
120
|
-
let n = new AbortController(), r = setTimeout(() => n.abort(),
|
|
140
|
+
let n = new AbortController(), r = setTimeout(() => n.abort(), c), i = !1, a;
|
|
121
141
|
try {
|
|
122
|
-
await t.request(
|
|
123
|
-
i = !0, clearTimeout(r), await e();
|
|
142
|
+
await t.request(fe, { signal: n.signal }, async () => {
|
|
143
|
+
i = !0, clearTimeout(r), a = await e();
|
|
124
144
|
});
|
|
125
145
|
} catch (t) {
|
|
126
146
|
if (i) throw t;
|
|
127
|
-
clearTimeout(r),
|
|
147
|
+
return clearTimeout(r), e();
|
|
148
|
+
}
|
|
149
|
+
return a;
|
|
150
|
+
}
|
|
151
|
+
function U() {
|
|
152
|
+
return _ === "local" && typeof navigator < "u" ? navigator.locks : void 0;
|
|
153
|
+
}
|
|
154
|
+
async function be() {
|
|
155
|
+
let e = U();
|
|
156
|
+
if (!e) return () => void 0;
|
|
157
|
+
let t, n = new Promise((e) => {
|
|
158
|
+
t = e;
|
|
159
|
+
});
|
|
160
|
+
try {
|
|
161
|
+
return await new Promise((r, i) => {
|
|
162
|
+
e.request(pe, { ifAvailable: !0 }, (e) => {
|
|
163
|
+
if (e === null) r(null);
|
|
164
|
+
else return r(t), n;
|
|
165
|
+
}).catch(i);
|
|
166
|
+
});
|
|
167
|
+
} catch {
|
|
168
|
+
return () => void 0;
|
|
128
169
|
}
|
|
129
170
|
}
|
|
130
|
-
async function
|
|
131
|
-
let
|
|
132
|
-
if (!
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
171
|
+
async function xe() {
|
|
172
|
+
let e = U();
|
|
173
|
+
if (!e) return;
|
|
174
|
+
let t = new AbortController(), n = setTimeout(() => t.abort(), c);
|
|
175
|
+
await e.request(pe, { signal: t.signal }, () => void 0).catch(() => void 0), clearTimeout(n);
|
|
176
|
+
}
|
|
177
|
+
async function Se(e) {
|
|
178
|
+
let n = await be();
|
|
179
|
+
if (!n) return l;
|
|
180
|
+
let r = !1;
|
|
136
181
|
try {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
182
|
+
let i = e !== null || A().user !== null || T !== null, a = J();
|
|
183
|
+
if (!i && j() !== null) return null;
|
|
184
|
+
if (!a.continues) throw new t();
|
|
185
|
+
if (j() !== e) return null;
|
|
186
|
+
let o = M, s;
|
|
187
|
+
try {
|
|
188
|
+
s = await z(Y.post(m, {
|
|
189
|
+
body: b(w()),
|
|
190
|
+
skipAuth: !0
|
|
191
|
+
}));
|
|
192
|
+
} catch (e) {
|
|
193
|
+
throw M === o ? e : new t();
|
|
194
|
+
}
|
|
195
|
+
let { token: c, refreshToken: l } = y(s);
|
|
196
|
+
if (M !== o || !J().continues) throw B(c ?? null, l), new t();
|
|
197
|
+
let u = te(e), f = te(c);
|
|
198
|
+
return u !== null && f !== null && u !== f ? (r = !0, {
|
|
199
|
+
data: s,
|
|
200
|
+
token: c,
|
|
201
|
+
refreshToken: l,
|
|
202
|
+
release: n
|
|
203
|
+
}) : (i || k(d()), A().setToken(c), l && E(l), null);
|
|
204
|
+
} finally {
|
|
205
|
+
r || n();
|
|
143
206
|
}
|
|
144
|
-
let { token: o, refreshToken: s } = y(a);
|
|
145
|
-
if (P !== i || !Z().continues) throw H(o ?? null, s), new t();
|
|
146
|
-
n || j(l()), M().setToken(o), s && O(s);
|
|
147
207
|
}
|
|
148
|
-
let
|
|
149
|
-
function
|
|
150
|
-
let t =
|
|
208
|
+
let W = o(ye);
|
|
209
|
+
function Ce(e) {
|
|
210
|
+
let t = j();
|
|
151
211
|
return t === null ? !1 : e.token === null || e.token !== t;
|
|
152
212
|
}
|
|
153
|
-
function
|
|
154
|
-
return
|
|
213
|
+
function we() {
|
|
214
|
+
return j() === null && w() === null;
|
|
155
215
|
}
|
|
156
|
-
async function
|
|
157
|
-
if (!(
|
|
216
|
+
async function Te() {
|
|
217
|
+
if (!(P.size > 0 && N === 0 && (await Promise.allSettled([...P]), j() !== null))) throw Error("anonymous 401 with no session");
|
|
158
218
|
}
|
|
159
|
-
async function
|
|
160
|
-
if (e.epoch !== null && e.epoch !==
|
|
161
|
-
if (
|
|
219
|
+
async function Ee(e) {
|
|
220
|
+
if (e.epoch !== null && e.epoch !== M) throw new t();
|
|
221
|
+
if (Ce(e)) {
|
|
162
222
|
if (e.token === null) throw Error("anonymous 401 under a live session");
|
|
163
|
-
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
if (e.token === null && we()) return R.has(M) ? W() : Te();
|
|
226
|
+
let n = M;
|
|
227
|
+
if (await W(), M !== n) throw new t();
|
|
228
|
+
}
|
|
229
|
+
async function De(e, n) {
|
|
230
|
+
if (n.epoch !== null && n.epoch !== M || !J().continues) throw new t();
|
|
231
|
+
Ce(n) || n.token === null && we() || await Le();
|
|
164
232
|
}
|
|
165
|
-
async function
|
|
166
|
-
|
|
167
|
-
|
|
233
|
+
async function Oe(e) {
|
|
234
|
+
F += 1;
|
|
235
|
+
try {
|
|
236
|
+
return I.size > 0 && await u([...I], s), await G(Me(e));
|
|
237
|
+
} finally {
|
|
238
|
+
--F;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
async function ke() {
|
|
242
|
+
return I.size > 0 && await u([...I], s), G(Ae());
|
|
243
|
+
}
|
|
244
|
+
async function G(e) {
|
|
245
|
+
P.add(e);
|
|
246
|
+
try {
|
|
247
|
+
return await e;
|
|
248
|
+
} finally {
|
|
249
|
+
P.delete(e);
|
|
250
|
+
}
|
|
168
251
|
}
|
|
169
|
-
async function
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
252
|
+
async function Ae() {
|
|
253
|
+
let e = M, n = await H(async () => {
|
|
254
|
+
let e = await be();
|
|
255
|
+
if (!e) return null;
|
|
256
|
+
try {
|
|
257
|
+
return {
|
|
258
|
+
data: await z(Y.post(m, {
|
|
259
|
+
body: b(w()),
|
|
260
|
+
skipAuth: !0
|
|
261
|
+
})),
|
|
262
|
+
release: e
|
|
263
|
+
};
|
|
264
|
+
} catch (t) {
|
|
265
|
+
throw e(), t;
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
if (!n) return je(e);
|
|
173
269
|
try {
|
|
174
|
-
|
|
270
|
+
let { token: r, refreshToken: i } = y(n.data);
|
|
271
|
+
if (M !== e) throw B(r ?? null, i), new t();
|
|
272
|
+
return await K({
|
|
273
|
+
data: n.data,
|
|
274
|
+
token: r,
|
|
275
|
+
refreshToken: i
|
|
276
|
+
});
|
|
175
277
|
} finally {
|
|
176
|
-
|
|
278
|
+
n.release();
|
|
177
279
|
}
|
|
178
280
|
}
|
|
179
|
-
async function
|
|
180
|
-
|
|
281
|
+
async function je(e) {
|
|
282
|
+
if (await xe(), M !== e || (await J().done.catch(() => void 0), j() === null)) throw new t();
|
|
283
|
+
let n = A().user;
|
|
284
|
+
return n === null ? me() : n;
|
|
285
|
+
}
|
|
286
|
+
async function Me(e) {
|
|
287
|
+
let n = M, r = await z(Y.post(re, {
|
|
181
288
|
body: e,
|
|
182
289
|
skipAuth: !0
|
|
183
290
|
})), { token: i, refreshToken: a } = y(r);
|
|
184
|
-
if (
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
291
|
+
if (M !== n) throw B(i ?? null, a), new t();
|
|
292
|
+
return B(j(), w() ?? void 0), K({
|
|
293
|
+
data: r,
|
|
294
|
+
token: i,
|
|
295
|
+
refreshToken: a
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
async function K(e) {
|
|
299
|
+
let { done: n } = q("switch"), r = M;
|
|
300
|
+
if (await n.catch(() => void 0), M !== r) throw new t();
|
|
301
|
+
k(d()), A().setToken(e.token), E(e.refreshToken ?? null);
|
|
302
|
+
let i = ce?.(e.data);
|
|
303
|
+
return i == null ? me() : (A().setUser(i), i);
|
|
304
|
+
}
|
|
305
|
+
function q(e) {
|
|
306
|
+
let { user: t, token: n } = A(), r = n !== null || t !== null || w() !== null;
|
|
307
|
+
return (r || e !== "expired") && ve(), A().logout(), E(null), k(null), r ? {
|
|
195
308
|
live: r,
|
|
196
|
-
done:
|
|
309
|
+
done: Ne({
|
|
197
310
|
reason: e,
|
|
198
311
|
user: t,
|
|
199
312
|
token: n,
|
|
@@ -201,29 +314,29 @@ function d(u) {
|
|
|
201
314
|
})
|
|
202
315
|
} : {
|
|
203
316
|
live: r,
|
|
204
|
-
done: e === "switch" ||
|
|
317
|
+
done: e === "switch" || N === 0 ? he : Promise.resolve()
|
|
205
318
|
};
|
|
206
319
|
}
|
|
207
|
-
function
|
|
208
|
-
if (!
|
|
209
|
-
let t =
|
|
210
|
-
|
|
320
|
+
function Ne(e) {
|
|
321
|
+
if (!de) return Promise.resolve();
|
|
322
|
+
let t = V(e.token);
|
|
323
|
+
N += 1;
|
|
211
324
|
let n = (async () => {
|
|
212
325
|
try {
|
|
213
|
-
await
|
|
326
|
+
await de({
|
|
214
327
|
...e,
|
|
215
328
|
api: t
|
|
216
329
|
});
|
|
217
330
|
} finally {
|
|
218
|
-
--
|
|
331
|
+
--N;
|
|
219
332
|
}
|
|
220
333
|
})();
|
|
221
|
-
return
|
|
334
|
+
return he = n.then(() => void 0, () => void 0), n.then(() => void 0);
|
|
222
335
|
}
|
|
223
|
-
function
|
|
224
|
-
let e =
|
|
336
|
+
function Pe() {
|
|
337
|
+
let e = C();
|
|
225
338
|
if (!e) return null;
|
|
226
|
-
let t = e.getItem(
|
|
339
|
+
let t = e.getItem(S), n = e.getItem(D), r = e.getItem(g);
|
|
227
340
|
if (!r) return {
|
|
228
341
|
user: null,
|
|
229
342
|
token: null,
|
|
@@ -247,19 +360,19 @@ function d(u) {
|
|
|
247
360
|
};
|
|
248
361
|
}
|
|
249
362
|
}
|
|
250
|
-
function
|
|
251
|
-
let e =
|
|
363
|
+
function J() {
|
|
364
|
+
let e = Pe(), { user: t, token: n } = A();
|
|
252
365
|
if (e === null) return {
|
|
253
366
|
continues: !0,
|
|
254
367
|
done: Promise.resolve()
|
|
255
368
|
};
|
|
256
369
|
let r = JSON.stringify(e.user) === JSON.stringify(t);
|
|
257
|
-
if (e.token === n && e.refreshToken ===
|
|
370
|
+
if (e.token === n && e.refreshToken === T && e.lineage === O && r) return {
|
|
258
371
|
continues: !0,
|
|
259
372
|
done: Promise.resolve()
|
|
260
373
|
};
|
|
261
|
-
let i = e.lineage !== null ||
|
|
262
|
-
if (a ||
|
|
374
|
+
let i = e.lineage !== null || O !== null ? e.lineage === O : e.token === n || n !== null && r, a = e.token !== null && i, o = n !== null || t !== null || T !== null;
|
|
375
|
+
if (a || ve(), T = e.refreshToken, O = e.lineage, x.setState({
|
|
263
376
|
user: e.user,
|
|
264
377
|
token: e.token,
|
|
265
378
|
isAuthenticated: e.token !== null
|
|
@@ -267,7 +380,7 @@ function d(u) {
|
|
|
267
380
|
continues: a,
|
|
268
381
|
done: Promise.resolve()
|
|
269
382
|
};
|
|
270
|
-
let s =
|
|
383
|
+
let s = Ne({
|
|
271
384
|
reason: e.token === null ? "logout" : "switch",
|
|
272
385
|
user: t,
|
|
273
386
|
token: n,
|
|
@@ -278,58 +391,61 @@ function d(u) {
|
|
|
278
391
|
done: s
|
|
279
392
|
};
|
|
280
393
|
}
|
|
281
|
-
function
|
|
282
|
-
if (!
|
|
283
|
-
let e =
|
|
284
|
-
if (!
|
|
285
|
-
let i =
|
|
286
|
-
return
|
|
394
|
+
function Fe() {
|
|
395
|
+
if (!h) return null;
|
|
396
|
+
let e = h, { token: t, user: n } = A(), r = w();
|
|
397
|
+
if (!v && t === null && n === null && r === null) return null;
|
|
398
|
+
let i = v ? [...L] : [];
|
|
399
|
+
return _e(async () => (await u(i, s), V(t).post(e, { body: b(r) })));
|
|
287
400
|
}
|
|
288
|
-
function
|
|
289
|
-
let e =
|
|
401
|
+
function Ie() {
|
|
402
|
+
let e = J();
|
|
290
403
|
if (!e.continues) return e.done;
|
|
291
|
-
let t =
|
|
404
|
+
let t = Fe(), { done: n } = q("logout");
|
|
292
405
|
return t ? Promise.all([t, n]).then(() => void 0) : n;
|
|
293
406
|
}
|
|
294
|
-
async function
|
|
295
|
-
let { live: e, done: t } =
|
|
296
|
-
await t.catch(() => void 0), e &&
|
|
297
|
-
}
|
|
298
|
-
let
|
|
299
|
-
baseURL:
|
|
300
|
-
prefix:
|
|
301
|
-
withCredentials:
|
|
302
|
-
csrf:
|
|
303
|
-
fetcher:
|
|
304
|
-
getToken:
|
|
305
|
-
getSessionEpoch: () =>
|
|
306
|
-
refresh:
|
|
307
|
-
retry:
|
|
308
|
-
onUnauthorized:
|
|
309
|
-
}),
|
|
310
|
-
epoch:
|
|
311
|
-
key:
|
|
312
|
-
}),
|
|
313
|
-
current:
|
|
314
|
-
subscribe: (e) =>
|
|
407
|
+
async function Le() {
|
|
408
|
+
let { live: e, done: t } = q("expired");
|
|
409
|
+
await t.catch(() => void 0), e && ue && typeof window < "u" && window.location.assign(ue);
|
|
410
|
+
}
|
|
411
|
+
let Y = n({
|
|
412
|
+
baseURL: f,
|
|
413
|
+
prefix: p,
|
|
414
|
+
withCredentials: v,
|
|
415
|
+
csrf: oe,
|
|
416
|
+
fetcher: se,
|
|
417
|
+
getToken: j,
|
|
418
|
+
getSessionEpoch: () => M,
|
|
419
|
+
refresh: Ee,
|
|
420
|
+
retry: le,
|
|
421
|
+
onUnauthorized: De
|
|
422
|
+
}), Re = () => W(), X = null, Z = () => j() === null ? null : O === null ? (X?.epoch !== M && (X = {
|
|
423
|
+
epoch: M,
|
|
424
|
+
key: d()
|
|
425
|
+
}), X.key) : O, Q = {
|
|
426
|
+
current: Z,
|
|
427
|
+
subscribe: (e) => x.subscribe(e)
|
|
315
428
|
};
|
|
316
|
-
r(Q,
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
429
|
+
r(Y, Q), r(j, Q), r(Z, Q);
|
|
430
|
+
let ze = () => P.size === 0 && !(R.size > 0 && j() === null);
|
|
431
|
+
function Be(e) {
|
|
432
|
+
e.storageArea === C() && (e.key === null || e.key === g || e.key === S || e.key === D) && J();
|
|
433
|
+
}
|
|
434
|
+
let $ = typeof window > "u" ? null : window;
|
|
435
|
+
return $?.addEventListener("storage", Be), {
|
|
436
|
+
useAuthStore: x,
|
|
437
|
+
api: Y,
|
|
438
|
+
login: Oe,
|
|
439
|
+
logout: Ie,
|
|
440
|
+
refresh: Re,
|
|
441
|
+
restore: ke,
|
|
442
|
+
getToken: j,
|
|
443
|
+
sessionKey: Z,
|
|
444
|
+
isSessionKnown: ze,
|
|
445
|
+
dispose: () => $?.removeEventListener("storage", Be)
|
|
330
446
|
};
|
|
331
447
|
}
|
|
332
448
|
//#endregion
|
|
333
|
-
export {
|
|
449
|
+
export { p as createTempestAuth };
|
|
334
450
|
|
|
335
451
|
//# sourceMappingURL=create-tempest-auth.js.map
|