tempest-react-sdk 0.81.0 → 0.82.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 +5 -6
- package/bin/create-tempest-app.e2e.test.mjs +31 -0
- package/bin/create-tempest-app.mjs +11 -1
- package/bin/lib/doctor/doctor.e2e.test.mjs +29 -0
- package/bin/lib/doctor/vitest.mjs +120 -0
- package/bin/lib/doctor/vitest.test.mjs +139 -0
- package/bin/lib/fs/contain.mjs +7 -0
- package/bin/lib/openapi/escape.mjs +68 -4
- package/bin/lib/openapi/generate.hostile.test.mjs +137 -0
- package/bin/lib/openapi/generate.mjs +78 -13
- package/bin/lib/openapi/pattern-risk.mjs +134 -0
- package/bin/lib/openapi/pattern-risk.test.mjs +45 -0
- package/bin/tempest-gen.test.mjs +100 -0
- package/bin/tempest.mjs +24 -8
- package/dist/access/use-can.cjs +1 -1
- package/dist/access/use-can.cjs.map +1 -1
- package/dist/access/use-can.js +25 -28
- package/dist/access/use-can.js.map +1 -1
- 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 +192 -149
- package/dist/auth/create-tempest-auth.js.map +1 -1
- package/dist/auth/session-identity.cjs +2 -0
- package/dist/auth/session-identity.cjs.map +1 -0
- package/dist/auth/session-identity.js +12 -0
- package/dist/auth/session-identity.js.map +1 -0
- package/dist/br/boleto.cjs.map +1 -1
- package/dist/br/boleto.js.map +1 -1
- package/dist/components/AuthForm/AuthLinks.cjs +1 -1
- package/dist/components/AuthForm/AuthLinks.cjs.map +1 -1
- package/dist/components/AuthForm/AuthLinks.js +18 -15
- package/dist/components/AuthForm/AuthLinks.js.map +1 -1
- package/dist/components/AuthPage/AuthPage.cjs +1 -1
- package/dist/components/AuthPage/AuthPage.cjs.map +1 -1
- package/dist/components/AuthPage/AuthPage.js +58 -52
- package/dist/components/AuthPage/AuthPage.js.map +1 -1
- package/dist/components/Breadcrumbs/Breadcrumbs.cjs +1 -1
- package/dist/components/Breadcrumbs/Breadcrumbs.cjs.map +1 -1
- package/dist/components/Breadcrumbs/Breadcrumbs.js +22 -21
- package/dist/components/Breadcrumbs/Breadcrumbs.js.map +1 -1
- package/dist/components/Button/Button.cjs +1 -1
- package/dist/components/Button/Button.cjs.map +1 -1
- package/dist/components/Button/Button.js +41 -40
- package/dist/components/Button/Button.js.map +1 -1
- package/dist/components/Chat/ChatAttachments.cjs +1 -1
- package/dist/components/Chat/ChatAttachments.cjs.map +1 -1
- package/dist/components/Chat/ChatAttachments.js +38 -38
- package/dist/components/Form/Form.cjs +1 -1
- package/dist/components/Form/Form.cjs.map +1 -1
- package/dist/components/Form/Form.js +30 -32
- package/dist/components/Form/Form.js.map +1 -1
- package/dist/components/Layout/Layout.cjs +1 -1
- package/dist/components/Layout/Layout.cjs.map +1 -1
- package/dist/components/Layout/Layout.js +25 -24
- package/dist/components/Layout/Layout.js.map +1 -1
- package/dist/components/Layout/gap.cjs +2 -0
- package/dist/components/Layout/gap.cjs.map +1 -0
- package/dist/components/Layout/gap.js +15 -0
- package/dist/components/Layout/gap.js.map +1 -0
- package/dist/components/NavigationMenu/NavigationMenu.cjs +1 -1
- package/dist/components/NavigationMenu/NavigationMenu.cjs.map +1 -1
- package/dist/components/NavigationMenu/NavigationMenu.js +71 -70
- package/dist/components/NavigationMenu/NavigationMenu.js.map +1 -1
- package/dist/components/Sidebar/Sidebar.cjs.map +1 -1
- package/dist/components/Sidebar/Sidebar.js.map +1 -1
- package/dist/components/Sidebar/SidebarEntry.cjs +1 -1
- package/dist/components/Sidebar/SidebarEntry.cjs.map +1 -1
- package/dist/components/Sidebar/SidebarEntry.js +30 -29
- package/dist/components/Sidebar/SidebarEntry.js.map +1 -1
- package/dist/data/create-data-provider.cjs +1 -1
- package/dist/data/create-data-provider.cjs.map +1 -1
- package/dist/data/create-data-provider.js +1 -2
- package/dist/data/create-data-provider.js.map +1 -1
- package/dist/forms/validate-form.cjs +1 -1
- package/dist/forms/validate-form.cjs.map +1 -1
- package/dist/forms/validate-form.js +6 -1
- package/dist/forms/validate-form.js.map +1 -1
- package/dist/forms/zod-resolver.cjs +1 -1
- package/dist/forms/zod-resolver.cjs.map +1 -1
- package/dist/forms/zod-resolver.js +8 -3
- package/dist/forms/zod-resolver.js.map +1 -1
- package/dist/http/api-client.cjs +1 -1
- package/dist/http/api-client.cjs.map +1 -1
- package/dist/http/api-client.js +90 -72
- package/dist/http/api-client.js.map +1 -1
- package/dist/http/credential-scope.cjs +1 -1
- package/dist/http/credential-scope.cjs.map +1 -1
- package/dist/http/credential-scope.js +33 -9
- package/dist/http/credential-scope.js.map +1 -1
- package/dist/http/presigned-post.cjs.map +1 -1
- package/dist/http/presigned-post.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 +90 -84
- 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 +8 -8
- package/dist/http/upload-with-progress.js.map +1 -1
- package/dist/oauth/GoogleSignIn.cjs +1 -1
- package/dist/oauth/GoogleSignIn.cjs.map +1 -1
- package/dist/oauth/GoogleSignIn.js +5 -4
- package/dist/oauth/GoogleSignIn.js.map +1 -1
- package/dist/offline/create-offline-sync.cjs +1 -1
- package/dist/offline/create-offline-sync.cjs.map +1 -1
- package/dist/offline/create-offline-sync.js +87 -69
- package/dist/offline/create-offline-sync.js.map +1 -1
- package/dist/query/offline-persistence.cjs +1 -1
- package/dist/query/offline-persistence.cjs.map +1 -1
- package/dist/query/offline-persistence.js +54 -44
- package/dist/query/offline-persistence.js.map +1 -1
- package/dist/sse/create-event-stream.cjs +1 -1
- package/dist/sse/create-event-stream.cjs.map +1 -1
- package/dist/sse/create-event-stream.js +48 -41
- package/dist/sse/create-event-stream.js.map +1 -1
- package/dist/sse/ticket-event-stream.cjs +1 -1
- package/dist/sse/ticket-event-stream.cjs.map +1 -1
- package/dist/sse/ticket-event-stream.js +48 -19
- package/dist/sse/ticket-event-stream.js.map +1 -1
- package/dist/sse/use-event-stream.cjs +1 -1
- package/dist/sse/use-event-stream.cjs.map +1 -1
- package/dist/sse/use-event-stream.js +19 -14
- package/dist/sse/use-event-stream.js.map +1 -1
- package/dist/sw/background-sync.cjs +1 -1
- package/dist/sw/background-sync.cjs.map +1 -1
- package/dist/sw/background-sync.js +10 -8
- package/dist/sw/background-sync.js.map +1 -1
- package/dist/sw/cache.cjs +1 -1
- package/dist/sw/cache.cjs.map +1 -1
- package/dist/sw/cache.js +36 -30
- package/dist/sw/cache.js.map +1 -1
- package/dist/sw/create-push-handler.cjs +1 -1
- package/dist/sw/create-push-handler.cjs.map +1 -1
- package/dist/sw/create-push-handler.js +20 -10
- package/dist/sw/create-push-handler.js.map +1 -1
- package/dist/sw.d.ts +44 -13
- package/dist/tabular/compact.cjs +1 -1
- package/dist/tabular/compact.cjs.map +1 -1
- package/dist/tabular/compact.js +35 -16
- package/dist/tabular/compact.js.map +1 -1
- package/dist/tabular/manifest.cjs +1 -1
- package/dist/tabular/manifest.cjs.map +1 -1
- package/dist/tabular/manifest.js +33 -15
- package/dist/tabular/manifest.js.map +1 -1
- package/dist/tabular.d.ts +11 -1
- package/dist/tempest-react-sdk.cjs +1 -1
- package/dist/tempest-react-sdk.d.ts +457 -68
- package/dist/tempest-react-sdk.js +224 -224
- package/dist/theme/initial-theme.cjs +4 -4
- package/dist/theme/initial-theme.cjs.map +1 -1
- package/dist/theme/initial-theme.js +8 -5
- package/dist/theme/initial-theme.js.map +1 -1
- package/dist/utils/compressed-storage.cjs +1 -1
- package/dist/utils/compressed-storage.cjs.map +1 -1
- package/dist/utils/compressed-storage.js +13 -7
- package/dist/utils/compressed-storage.js.map +1 -1
- package/dist/utils/objects.cjs +1 -1
- package/dist/utils/objects.cjs.map +1 -1
- package/dist/utils/objects.js +13 -7
- package/dist/utils/objects.js.map +1 -1
- package/dist/utils/safe-url.cjs +1 -1
- package/dist/utils/safe-url.cjs.map +1 -1
- package/dist/utils/safe-url.js +4 -1
- package/dist/utils/safe-url.js.map +1 -1
- package/dist/webrtc/peer-mesh.cjs +1 -1
- package/dist/webrtc/peer-mesh.cjs.map +1 -1
- package/dist/webrtc/peer-mesh.js +7 -1
- package/dist/webrtc/peer-mesh.js.map +1 -1
- package/dist/ws/create-web-socket.cjs +1 -1
- package/dist/ws/create-web-socket.cjs.map +1 -1
- package/dist/ws/create-web-socket.js +77 -61
- package/dist/ws/create-web-socket.js.map +1 -1
- package/dist/ws/use-web-socket.cjs +1 -1
- package/dist/ws/use-web-socket.cjs.map +1 -1
- package/dist/ws/use-web-socket.js +4 -3
- package/dist/ws/use-web-socket.js.map +1 -1
- package/package.json +1 -1
- package/template-pwa/src/pwa.tsx +42 -0
- package/template-pwa/src/sw.ts +5 -4
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { isDevBuild as e } from "../utils/dev-mode.js";
|
|
2
2
|
import { SessionSupersededError as t } from "../http/errors.js";
|
|
3
3
|
import { createApiClient as n } from "../http/api-client.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { bindSessionIdentity as r } from "./session-identity.js";
|
|
5
|
+
import { createAuthStore as i } from "./create-auth-store.js";
|
|
6
|
+
import { createRefreshQueue as a } from "./refresh-queue.js";
|
|
6
7
|
//#region src/auth/create-tempest-auth.ts
|
|
7
|
-
var
|
|
8
|
-
function
|
|
8
|
+
var o = 1e4, s = 1e4;
|
|
9
|
+
function c(e, t) {
|
|
9
10
|
return e.length === 0 ? Promise.resolve() : new Promise((n) => {
|
|
10
11
|
let r = setTimeout(n, t);
|
|
11
12
|
Promise.allSettled(e).then(() => {
|
|
@@ -13,152 +14,186 @@ function o(e, t) {
|
|
|
13
14
|
});
|
|
14
15
|
});
|
|
15
16
|
}
|
|
16
|
-
function
|
|
17
|
+
function ee() {
|
|
18
|
+
let e = globalThis.crypto;
|
|
19
|
+
return typeof e?.randomUUID == "function" ? e.randomUUID() : `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
|
|
20
|
+
}
|
|
21
|
+
var te = "unlineaged", l = /* @__PURE__ */ new Set();
|
|
22
|
+
function ne(t) {
|
|
23
|
+
e() && !l.has(t) && (l.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
|
+
function re(e) {
|
|
17
26
|
let t = e ?? {};
|
|
18
27
|
return {
|
|
19
28
|
token: t.access_token,
|
|
20
29
|
refreshToken: t.refresh_token
|
|
21
30
|
};
|
|
22
31
|
}
|
|
23
|
-
function
|
|
24
|
-
let { baseURL:
|
|
32
|
+
function u(l) {
|
|
33
|
+
let { baseURL: u, prefix: d, loginPath: ie = "/api/auth/login", refreshPath: ae = "/api/auth/refresh", logoutPath: f, onLogoutError: oe, mePath: p, storeName: m = "tempest-auth", storage: h = "local", withCredentials: g = !1, csrf: _, fetcher: se, parseTokens: v = re, parseUser: ce, refreshBody: y = (e) => e ? { refresh_token: e } : void 0, retry: le, redirectTo: b, onSessionEnd: x } = l;
|
|
34
|
+
g && !f && ne(m);
|
|
35
|
+
let S = i({
|
|
25
36
|
name: m,
|
|
26
37
|
storage: h
|
|
27
|
-
}),
|
|
28
|
-
function
|
|
38
|
+
}), C = `${m}-refresh`;
|
|
39
|
+
function w() {
|
|
29
40
|
return typeof window > "u" ? null : h === "session" ? window.sessionStorage : window.localStorage;
|
|
30
41
|
}
|
|
31
|
-
function
|
|
32
|
-
return
|
|
42
|
+
function T() {
|
|
43
|
+
return w()?.getItem(C) ?? null;
|
|
44
|
+
}
|
|
45
|
+
let E = T();
|
|
46
|
+
function D(e) {
|
|
47
|
+
E = e;
|
|
48
|
+
let t = w();
|
|
49
|
+
t && (e ? t.setItem(C, e) : t.removeItem(C));
|
|
33
50
|
}
|
|
34
|
-
let
|
|
35
|
-
function
|
|
36
|
-
|
|
37
|
-
let t =
|
|
38
|
-
t && (e ? t.setItem(
|
|
51
|
+
let O = `${m}-lineage`, ue = `tempest-react-sdk:${m}:refresh`, k = w()?.getItem(O) ?? null;
|
|
52
|
+
function A(e) {
|
|
53
|
+
k = e;
|
|
54
|
+
let t = w();
|
|
55
|
+
t && (e ? t.setItem(O, e) : t.removeItem(O));
|
|
39
56
|
}
|
|
40
|
-
let
|
|
41
|
-
async function
|
|
42
|
-
if (!p) return
|
|
43
|
-
let e =
|
|
57
|
+
let j = () => S.getState(), M = () => j().token;
|
|
58
|
+
async function de() {
|
|
59
|
+
if (!p) return j().user;
|
|
60
|
+
let e = N, n;
|
|
44
61
|
try {
|
|
45
|
-
n = await
|
|
62
|
+
n = await Q.get(p, { skipAuthRetry: !0 });
|
|
46
63
|
} catch (n) {
|
|
47
|
-
throw
|
|
64
|
+
throw N === e ? n : new t();
|
|
48
65
|
}
|
|
49
|
-
if (
|
|
50
|
-
return
|
|
66
|
+
if (N !== e || !Z().continues) throw new t();
|
|
67
|
+
return j().setUser(n), n;
|
|
51
68
|
}
|
|
52
|
-
let
|
|
53
|
-
function
|
|
69
|
+
let N = 0, P = Promise.resolve(), F = 0, I = /* @__PURE__ */ new Set(), L = /* @__PURE__ */ new Set(), R = /* @__PURE__ */ new Set(), z = /* @__PURE__ */ new Set();
|
|
70
|
+
function B(e) {
|
|
54
71
|
let t = e.then(() => void 0, () => void 0);
|
|
55
|
-
return
|
|
72
|
+
return R.add(t), t.then(() => R.delete(t)), e;
|
|
56
73
|
}
|
|
57
|
-
function
|
|
74
|
+
function fe(t) {
|
|
58
75
|
e() && console.warn("[tempest-react-sdk] createTempestAuth: logoutPath revocation failed", t);
|
|
59
76
|
try {
|
|
60
|
-
|
|
77
|
+
oe?.(t);
|
|
61
78
|
} catch {
|
|
62
79
|
return;
|
|
63
80
|
}
|
|
64
81
|
}
|
|
65
|
-
function
|
|
82
|
+
function V(e) {
|
|
66
83
|
let t = (async () => {
|
|
67
84
|
try {
|
|
68
85
|
await e();
|
|
69
86
|
} catch (e) {
|
|
70
|
-
|
|
87
|
+
fe(e);
|
|
71
88
|
}
|
|
72
89
|
})();
|
|
73
|
-
return
|
|
90
|
+
return L.add(t), t.then(() => L.delete(t)), t;
|
|
74
91
|
}
|
|
75
|
-
function
|
|
76
|
-
f && !g && t &&
|
|
92
|
+
function H(e, t) {
|
|
93
|
+
f && !g && t && V(() => U(e).post(f, { body: y(t) }));
|
|
77
94
|
}
|
|
78
|
-
function
|
|
95
|
+
function U(e) {
|
|
79
96
|
return n({
|
|
80
|
-
baseURL:
|
|
81
|
-
prefix:
|
|
97
|
+
baseURL: u,
|
|
98
|
+
prefix: d,
|
|
82
99
|
withCredentials: g,
|
|
83
100
|
csrf: _,
|
|
84
|
-
fetcher:
|
|
101
|
+
fetcher: se,
|
|
85
102
|
getToken: () => e
|
|
86
103
|
});
|
|
87
104
|
}
|
|
88
|
-
function
|
|
89
|
-
|
|
105
|
+
function W() {
|
|
106
|
+
N += 1, K = a(G);
|
|
90
107
|
}
|
|
91
|
-
async function
|
|
92
|
-
let e =
|
|
93
|
-
|
|
94
|
-
if (A() !== e) return;
|
|
95
|
-
let n = j;
|
|
96
|
-
L.add(n);
|
|
108
|
+
async function G() {
|
|
109
|
+
let e = M(), t = N;
|
|
110
|
+
z.add(t);
|
|
97
111
|
try {
|
|
98
|
-
|
|
99
|
-
try {
|
|
100
|
-
e = await R(Z.post(ee, {
|
|
101
|
-
body: b(E()),
|
|
102
|
-
skipAuth: !0
|
|
103
|
-
}));
|
|
104
|
-
} catch (e) {
|
|
105
|
-
throw j === n ? e : new t();
|
|
106
|
-
}
|
|
107
|
-
let { token: r, refreshToken: i } = y(e);
|
|
108
|
-
if (j !== n || !X().continues) throw B(r ?? null, i), new t();
|
|
109
|
-
k().setToken(r), i && O(i);
|
|
112
|
+
await pe(() => me(e));
|
|
110
113
|
} finally {
|
|
111
|
-
|
|
114
|
+
z.delete(t);
|
|
112
115
|
}
|
|
113
116
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
+
async function pe(e) {
|
|
118
|
+
let t = h === "local" && typeof navigator < "u" ? navigator.locks : void 0;
|
|
119
|
+
if (!t) return e();
|
|
120
|
+
let n = new AbortController(), r = setTimeout(() => n.abort(), s), i = !1;
|
|
121
|
+
try {
|
|
122
|
+
await t.request(ue, { signal: n.signal }, async () => {
|
|
123
|
+
i = !0, clearTimeout(r), await e();
|
|
124
|
+
});
|
|
125
|
+
} catch (t) {
|
|
126
|
+
if (i) throw t;
|
|
127
|
+
clearTimeout(r), await e();
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
async function me(e) {
|
|
131
|
+
let n = e !== null || j().user !== null || E !== null, r = Z();
|
|
132
|
+
if (!n && M() !== null) return;
|
|
133
|
+
if (!r.continues) throw new t();
|
|
134
|
+
if (M() !== e) return;
|
|
135
|
+
let i = N, a;
|
|
136
|
+
try {
|
|
137
|
+
a = await B(Q.post(ae, {
|
|
138
|
+
body: y(T()),
|
|
139
|
+
skipAuth: !0
|
|
140
|
+
}));
|
|
141
|
+
} catch (e) {
|
|
142
|
+
throw N === i ? e : new t();
|
|
143
|
+
}
|
|
144
|
+
let { token: o, refreshToken: s } = v(a);
|
|
145
|
+
if (N !== i || !Z().continues) throw H(o ?? null, s), new t();
|
|
146
|
+
j().setToken(o), s && D(s);
|
|
147
|
+
}
|
|
148
|
+
let K = a(G);
|
|
149
|
+
function q(e) {
|
|
150
|
+
let t = M();
|
|
117
151
|
return t === null ? !1 : e.token === null || e.token !== t;
|
|
118
152
|
}
|
|
119
|
-
function
|
|
120
|
-
return
|
|
153
|
+
function J() {
|
|
154
|
+
return M() === null && T() === null;
|
|
121
155
|
}
|
|
122
|
-
async function
|
|
123
|
-
if (!(
|
|
156
|
+
async function he() {
|
|
157
|
+
if (!(I.size > 0 && F === 0 && (await Promise.allSettled([...I]), M() !== null))) throw Error("anonymous 401 with no session");
|
|
124
158
|
}
|
|
125
|
-
async function
|
|
126
|
-
if (e.epoch !== null && e.epoch !==
|
|
127
|
-
if (
|
|
159
|
+
async function ge(e) {
|
|
160
|
+
if (e.epoch !== null && e.epoch !== N) throw new t();
|
|
161
|
+
if (q(e)) {
|
|
128
162
|
if (e.token === null) throw Error("anonymous 401 under a live session");
|
|
129
|
-
} else return e.token === null &&
|
|
163
|
+
} else return e.token === null && J() ? z.has(N) ? K() : he() : K();
|
|
130
164
|
}
|
|
131
|
-
async function
|
|
132
|
-
if (n.epoch !== null && n.epoch !==
|
|
133
|
-
|
|
165
|
+
async function _e(e, n) {
|
|
166
|
+
if (n.epoch !== null && n.epoch !== N || !Z().continues) throw new t();
|
|
167
|
+
q(n) || n.token === null && J() || await Ce();
|
|
134
168
|
}
|
|
135
|
-
async function
|
|
136
|
-
|
|
137
|
-
let t =
|
|
138
|
-
|
|
169
|
+
async function ve(e) {
|
|
170
|
+
L.size > 0 && await c([...L], o);
|
|
171
|
+
let t = ye(e);
|
|
172
|
+
I.add(t);
|
|
139
173
|
try {
|
|
140
174
|
return await t;
|
|
141
175
|
} finally {
|
|
142
|
-
|
|
176
|
+
I.delete(t);
|
|
143
177
|
}
|
|
144
178
|
}
|
|
145
|
-
async function
|
|
146
|
-
let n =
|
|
179
|
+
async function ye(e) {
|
|
180
|
+
let n = N, r = await B(Q.post(ie, {
|
|
147
181
|
body: e,
|
|
148
182
|
skipAuth: !0
|
|
149
|
-
})), { token: i, refreshToken: a } =
|
|
150
|
-
if (
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
183
|
+
})), { token: i, refreshToken: a } = v(r);
|
|
184
|
+
if (N !== n) throw H(i ?? null, a), new t();
|
|
185
|
+
H(M(), T() ?? void 0);
|
|
186
|
+
let { done: o } = Y("switch"), s = N;
|
|
187
|
+
if (await o.catch(() => void 0), N !== s) throw new t();
|
|
188
|
+
A(ee()), j().setToken(i), D(a ?? null);
|
|
189
|
+
let c = ce?.(r);
|
|
190
|
+
return c == null ? de() : (j().setUser(c), c);
|
|
156
191
|
}
|
|
157
|
-
function
|
|
158
|
-
let { user: t, token: n } =
|
|
159
|
-
return (r || e !== "expired") &&
|
|
192
|
+
function Y(e) {
|
|
193
|
+
let { user: t, token: n } = j(), r = n !== null || t !== null || T() !== null;
|
|
194
|
+
return (r || e !== "expired") && W(), j().logout(), D(null), A(null), r ? {
|
|
160
195
|
live: r,
|
|
161
|
-
done:
|
|
196
|
+
done: X({
|
|
162
197
|
reason: e,
|
|
163
198
|
user: t,
|
|
164
199
|
token: n,
|
|
@@ -166,124 +201,132 @@ function c(c) {
|
|
|
166
201
|
})
|
|
167
202
|
} : {
|
|
168
203
|
live: r,
|
|
169
|
-
done: e === "switch" ||
|
|
204
|
+
done: e === "switch" || F === 0 ? P : Promise.resolve()
|
|
170
205
|
};
|
|
171
206
|
}
|
|
172
|
-
function
|
|
173
|
-
if (!
|
|
174
|
-
let t =
|
|
175
|
-
|
|
207
|
+
function X(e) {
|
|
208
|
+
if (!x) return Promise.resolve();
|
|
209
|
+
let t = U(e.token);
|
|
210
|
+
F += 1;
|
|
176
211
|
let n = (async () => {
|
|
177
212
|
try {
|
|
178
|
-
await
|
|
213
|
+
await x({
|
|
179
214
|
...e,
|
|
180
215
|
api: t
|
|
181
216
|
});
|
|
182
217
|
} finally {
|
|
183
|
-
--
|
|
218
|
+
--F;
|
|
184
219
|
}
|
|
185
220
|
})();
|
|
186
|
-
return
|
|
221
|
+
return P = n.then(() => void 0, () => void 0), n.then(() => void 0);
|
|
187
222
|
}
|
|
188
|
-
function
|
|
189
|
-
let e =
|
|
223
|
+
function be() {
|
|
224
|
+
let e = w();
|
|
190
225
|
if (!e) return null;
|
|
191
|
-
let t = e.getItem(
|
|
192
|
-
if (!
|
|
226
|
+
let t = e.getItem(C), n = e.getItem(O), r = e.getItem(m);
|
|
227
|
+
if (!r) return {
|
|
193
228
|
user: null,
|
|
194
229
|
token: null,
|
|
195
|
-
refreshToken: t
|
|
230
|
+
refreshToken: t,
|
|
231
|
+
lineage: n
|
|
196
232
|
};
|
|
197
233
|
try {
|
|
198
|
-
let e = JSON.parse(
|
|
234
|
+
let e = JSON.parse(r);
|
|
199
235
|
return {
|
|
200
236
|
user: e.state?.user ?? null,
|
|
201
237
|
token: e.state?.token ?? null,
|
|
202
|
-
refreshToken: t
|
|
238
|
+
refreshToken: t,
|
|
239
|
+
lineage: n
|
|
203
240
|
};
|
|
204
241
|
} catch {
|
|
205
242
|
return {
|
|
206
243
|
user: null,
|
|
207
244
|
token: null,
|
|
208
|
-
refreshToken: t
|
|
245
|
+
refreshToken: t,
|
|
246
|
+
lineage: n
|
|
209
247
|
};
|
|
210
248
|
}
|
|
211
249
|
}
|
|
212
|
-
function
|
|
213
|
-
let e =
|
|
250
|
+
function Z() {
|
|
251
|
+
let e = be(), { user: t, token: n } = j();
|
|
214
252
|
if (e === null) return {
|
|
215
253
|
continues: !0,
|
|
216
254
|
done: Promise.resolve()
|
|
217
255
|
};
|
|
218
256
|
let r = JSON.stringify(e.user) === JSON.stringify(t);
|
|
219
|
-
if (e.token === n && e.refreshToken ===
|
|
257
|
+
if (e.token === n && e.refreshToken === E && e.lineage === k && r) return {
|
|
220
258
|
continues: !0,
|
|
221
259
|
done: Promise.resolve()
|
|
222
260
|
};
|
|
223
|
-
let i = e.
|
|
224
|
-
if (
|
|
261
|
+
let i = e.lineage !== null || k !== null ? e.lineage === k : e.token === n || n !== null && r, a = e.token !== null && i, o = n !== null || t !== null || E !== null;
|
|
262
|
+
if (a || W(), E = e.refreshToken, k = e.lineage, S.setState({
|
|
225
263
|
user: e.user,
|
|
226
264
|
token: e.token,
|
|
227
265
|
isAuthenticated: e.token !== null
|
|
228
|
-
}),
|
|
229
|
-
continues:
|
|
266
|
+
}), a || !o) return {
|
|
267
|
+
continues: a,
|
|
230
268
|
done: Promise.resolve()
|
|
231
269
|
};
|
|
232
|
-
let
|
|
270
|
+
let s = X({
|
|
233
271
|
reason: e.token === null ? "logout" : "switch",
|
|
234
272
|
user: t,
|
|
235
273
|
token: n,
|
|
236
274
|
elsewhere: !0
|
|
237
275
|
});
|
|
238
|
-
return
|
|
239
|
-
continues:
|
|
240
|
-
done:
|
|
276
|
+
return s.catch(() => void 0), {
|
|
277
|
+
continues: a,
|
|
278
|
+
done: s
|
|
241
279
|
};
|
|
242
280
|
}
|
|
243
|
-
function
|
|
281
|
+
function xe() {
|
|
244
282
|
if (!f) return null;
|
|
245
|
-
let e = f, { token: t, user: n } =
|
|
283
|
+
let e = f, { token: t, user: n } = j(), r = T();
|
|
246
284
|
if (!g && t === null && n === null && r === null) return null;
|
|
247
|
-
let i = g ? [...
|
|
248
|
-
return
|
|
285
|
+
let i = g ? [...R] : [];
|
|
286
|
+
return V(async () => (await c(i, o), U(t).post(e, { body: y(r) })));
|
|
249
287
|
}
|
|
250
|
-
function
|
|
251
|
-
let e =
|
|
288
|
+
function Se() {
|
|
289
|
+
let e = Z();
|
|
252
290
|
if (!e.continues) return e.done;
|
|
253
|
-
let t =
|
|
291
|
+
let t = xe(), { done: n } = Y("logout");
|
|
254
292
|
return t ? Promise.all([t, n]).then(() => void 0) : n;
|
|
255
293
|
}
|
|
256
|
-
async function
|
|
257
|
-
let { live: e, done: t } =
|
|
258
|
-
await t.catch(() => void 0), e &&
|
|
294
|
+
async function Ce() {
|
|
295
|
+
let { live: e, done: t } = Y("expired");
|
|
296
|
+
await t.catch(() => void 0), e && b && typeof window < "u" && window.location.assign(b);
|
|
259
297
|
}
|
|
260
|
-
let
|
|
261
|
-
baseURL:
|
|
262
|
-
prefix:
|
|
298
|
+
let Q = n({
|
|
299
|
+
baseURL: u,
|
|
300
|
+
prefix: d,
|
|
263
301
|
withCredentials: g,
|
|
264
302
|
csrf: _,
|
|
265
|
-
fetcher:
|
|
266
|
-
getToken:
|
|
267
|
-
getSessionEpoch: () =>
|
|
268
|
-
refresh:
|
|
269
|
-
retry:
|
|
270
|
-
onUnauthorized:
|
|
271
|
-
}),
|
|
272
|
-
|
|
273
|
-
|
|
303
|
+
fetcher: se,
|
|
304
|
+
getToken: M,
|
|
305
|
+
getSessionEpoch: () => N,
|
|
306
|
+
refresh: ge,
|
|
307
|
+
retry: le,
|
|
308
|
+
onUnauthorized: _e
|
|
309
|
+
}), we = () => K(), Te = () => M() === null ? null : k ?? te, Ee = {
|
|
310
|
+
current: Te,
|
|
311
|
+
subscribe: (e) => S.subscribe(e)
|
|
312
|
+
};
|
|
313
|
+
r(Q, Ee), r(M, Ee);
|
|
314
|
+
function De(e) {
|
|
315
|
+
e.storageArea === w() && (e.key === null || e.key === m || e.key === C || e.key === O) && Z();
|
|
274
316
|
}
|
|
275
317
|
let $ = typeof window > "u" ? null : window;
|
|
276
|
-
return $?.addEventListener("storage",
|
|
277
|
-
useAuthStore:
|
|
278
|
-
api:
|
|
279
|
-
login:
|
|
280
|
-
logout:
|
|
281
|
-
refresh:
|
|
282
|
-
getToken:
|
|
283
|
-
|
|
318
|
+
return $?.addEventListener("storage", De), {
|
|
319
|
+
useAuthStore: S,
|
|
320
|
+
api: Q,
|
|
321
|
+
login: ve,
|
|
322
|
+
logout: Se,
|
|
323
|
+
refresh: we,
|
|
324
|
+
getToken: M,
|
|
325
|
+
sessionKey: Te,
|
|
326
|
+
dispose: () => $?.removeEventListener("storage", De)
|
|
284
327
|
};
|
|
285
328
|
}
|
|
286
329
|
//#endregion
|
|
287
|
-
export {
|
|
330
|
+
export { u as createTempestAuth };
|
|
288
331
|
|
|
289
332
|
//# sourceMappingURL=create-tempest-auth.js.map
|