tempest-react-sdk 0.81.0 → 0.83.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 +9 -10
- 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 +228 -0
- package/bin/lib/openapi/generate.mjs +119 -15
- 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 +189 -143
- 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 +167 -112
- 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 +100 -44
- 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 +67 -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 +111 -55
- 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 +65 -14
- 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 +543 -70
- 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/vite/base-url.cjs +1 -1
- package/dist/vite/base-url.cjs.map +1 -1
- package/dist/vite/base-url.js +5 -1
- package/dist/vite/base-url.js.map +1 -1
- package/dist/vite/tempest-pwa-dev-sw.cjs +1 -1
- package/dist/vite/tempest-pwa-dev-sw.cjs.map +1 -1
- package/dist/vite/tempest-pwa-dev-sw.js +96 -31
- package/dist/vite/tempest-pwa-dev-sw.js.map +1 -1
- package/dist/vite/tempest-pwa-manifest.cjs +2 -2
- package/dist/vite/tempest-pwa-manifest.cjs.map +1 -1
- package/dist/vite/tempest-pwa-manifest.js +32 -16
- package/dist/vite/tempest-pwa-manifest.js.map +1 -1
- package/dist/vite.cjs +1 -1
- package/dist/vite.d.ts +63 -12
- package/dist/vite.js +4 -4
- 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,20 +14,30 @@ function o(e, t) {
|
|
|
13
14
|
});
|
|
14
15
|
});
|
|
15
16
|
}
|
|
16
|
-
function
|
|
17
|
+
function l() {
|
|
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 u = /* @__PURE__ */ new Set();
|
|
22
|
+
function ee(t) {
|
|
23
|
+
e() && !u.has(t) && (u.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 te(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:
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
32
|
+
function d(u) {
|
|
33
|
+
let { baseURL: d, prefix: f, loginPath: ne = "/api/auth/login", refreshPath: re = "/api/auth/refresh", logoutPath: p, onLogoutError: ie, mePath: m, storeName: h = "tempest-auth", storage: g = "local", withCredentials: _ = !1, csrf: ae, fetcher: v, parseTokens: y = te, parseUser: oe, refreshBody: b = (e) => e ? { refresh_token: e } : void 0, retry: se, redirectTo: x, onSessionEnd: S } = u;
|
|
34
|
+
_ && !p && ee(h);
|
|
35
|
+
let C = i({
|
|
36
|
+
name: h,
|
|
37
|
+
storage: g
|
|
38
|
+
}), w = `${h}-refresh`;
|
|
28
39
|
function T() {
|
|
29
|
-
return typeof window > "u" ? null :
|
|
40
|
+
return typeof window > "u" ? null : g === "session" ? window.sessionStorage : window.localStorage;
|
|
30
41
|
}
|
|
31
42
|
function E() {
|
|
32
43
|
return T()?.getItem(w) ?? null;
|
|
@@ -37,128 +48,152 @@ function c(c) {
|
|
|
37
48
|
let t = T();
|
|
38
49
|
t && (e ? t.setItem(w, e) : t.removeItem(w));
|
|
39
50
|
}
|
|
40
|
-
let k =
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
let
|
|
51
|
+
let k = `${h}-lineage`, ce = `tempest-react-sdk:${h}:refresh`, A = T()?.getItem(k) ?? null;
|
|
52
|
+
function j(e) {
|
|
53
|
+
A = e;
|
|
54
|
+
let t = T();
|
|
55
|
+
t && (e ? t.setItem(k, e) : t.removeItem(k));
|
|
56
|
+
}
|
|
57
|
+
let M = () => C.getState(), N = () => M().token;
|
|
58
|
+
async function le() {
|
|
59
|
+
if (!m) return M().user;
|
|
60
|
+
let e = P, n;
|
|
44
61
|
try {
|
|
45
|
-
n = await
|
|
62
|
+
n = await Q.get(m, { skipAuthRetry: !0 });
|
|
46
63
|
} catch (n) {
|
|
47
|
-
throw
|
|
64
|
+
throw P === e ? n : new t();
|
|
48
65
|
}
|
|
49
|
-
if (
|
|
50
|
-
return
|
|
66
|
+
if (P !== e || !Z().continues) throw new t();
|
|
67
|
+
return M().setUser(n), n;
|
|
51
68
|
}
|
|
52
|
-
let
|
|
53
|
-
function
|
|
69
|
+
let P = 0, ue = 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 de(t) {
|
|
58
75
|
e() && console.warn("[tempest-react-sdk] createTempestAuth: logoutPath revocation failed", t);
|
|
59
76
|
try {
|
|
60
|
-
|
|
77
|
+
ie?.(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
|
+
de(e);
|
|
71
88
|
}
|
|
72
89
|
})();
|
|
73
|
-
return
|
|
90
|
+
return L.add(t), t.then(() => L.delete(t)), t;
|
|
74
91
|
}
|
|
75
|
-
function
|
|
76
|
-
|
|
92
|
+
function H(e, t) {
|
|
93
|
+
p && !_ && t && V(() => U(e).post(p, { body: b(t) }));
|
|
77
94
|
}
|
|
78
|
-
function
|
|
95
|
+
function U(e) {
|
|
79
96
|
return n({
|
|
80
|
-
baseURL:
|
|
81
|
-
prefix:
|
|
82
|
-
withCredentials:
|
|
83
|
-
csrf:
|
|
97
|
+
baseURL: d,
|
|
98
|
+
prefix: f,
|
|
99
|
+
withCredentials: _,
|
|
100
|
+
csrf: ae,
|
|
84
101
|
fetcher: v,
|
|
85
102
|
getToken: () => e
|
|
86
103
|
});
|
|
87
104
|
}
|
|
88
|
-
function
|
|
89
|
-
|
|
105
|
+
function W() {
|
|
106
|
+
P += 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 = N(), t = P;
|
|
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 fe(() => pe(e));
|
|
110
113
|
} finally {
|
|
111
|
-
|
|
114
|
+
z.delete(t);
|
|
112
115
|
}
|
|
113
116
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
+
async function fe(e) {
|
|
118
|
+
let t = g === "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(ce, { 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 pe(e) {
|
|
131
|
+
let n = e !== null || M().user !== null || D !== null, r = Z();
|
|
132
|
+
if (!n && N() !== null) return;
|
|
133
|
+
if (!r.continues) throw new t();
|
|
134
|
+
if (N() !== e) return;
|
|
135
|
+
let i = P, a;
|
|
136
|
+
try {
|
|
137
|
+
a = await B(Q.post(re, {
|
|
138
|
+
body: b(E()),
|
|
139
|
+
skipAuth: !0
|
|
140
|
+
}));
|
|
141
|
+
} catch (e) {
|
|
142
|
+
throw P === i ? e : new t();
|
|
143
|
+
}
|
|
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
|
+
}
|
|
148
|
+
let K = a(G);
|
|
149
|
+
function q(e) {
|
|
150
|
+
let t = N();
|
|
117
151
|
return t === null ? !1 : e.token === null || e.token !== t;
|
|
118
152
|
}
|
|
119
|
-
function
|
|
120
|
-
return
|
|
153
|
+
function J() {
|
|
154
|
+
return N() === null && E() === null;
|
|
121
155
|
}
|
|
122
|
-
async function
|
|
123
|
-
if (!(
|
|
156
|
+
async function me() {
|
|
157
|
+
if (!(I.size > 0 && F === 0 && (await Promise.allSettled([...I]), N() !== 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 he(e) {
|
|
160
|
+
if (e.epoch !== null && e.epoch !== P) 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(P) ? K() : me() : K();
|
|
130
164
|
}
|
|
131
|
-
async function
|
|
132
|
-
if (n.epoch !== null && n.epoch !==
|
|
133
|
-
|
|
165
|
+
async function ge(e, n) {
|
|
166
|
+
if (n.epoch !== null && n.epoch !== P || !Z().continues) throw new t();
|
|
167
|
+
q(n) || n.token === null && J() || await Se();
|
|
134
168
|
}
|
|
135
|
-
async function
|
|
136
|
-
|
|
137
|
-
let t =
|
|
138
|
-
|
|
169
|
+
async function _e(e) {
|
|
170
|
+
L.size > 0 && await c([...L], o);
|
|
171
|
+
let t = ve(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 ve(e) {
|
|
180
|
+
let n = P, r = await B(Q.post(ne, {
|
|
147
181
|
body: e,
|
|
148
182
|
skipAuth: !0
|
|
149
183
|
})), { token: i, refreshToken: a } = y(r);
|
|
150
|
-
if (
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
184
|
+
if (P !== n) throw H(i ?? null, a), new t();
|
|
185
|
+
H(N(), E() ?? void 0);
|
|
186
|
+
let { done: o } = Y("switch"), s = P;
|
|
187
|
+
if (await o.catch(() => void 0), P !== s) throw new t();
|
|
188
|
+
j(l()), M().setToken(i), O(a ?? null);
|
|
189
|
+
let c = oe?.(r);
|
|
190
|
+
return c == null ? le() : (M().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 } = M(), r = n !== null || t !== null || E() !== null;
|
|
194
|
+
return (r || e !== "expired") && W(), M().logout(), O(null), j(null), r ? {
|
|
160
195
|
live: r,
|
|
161
|
-
done:
|
|
196
|
+
done: X({
|
|
162
197
|
reason: e,
|
|
163
198
|
user: t,
|
|
164
199
|
token: n,
|
|
@@ -166,13 +201,13 @@ function c(c) {
|
|
|
166
201
|
})
|
|
167
202
|
} : {
|
|
168
203
|
live: r,
|
|
169
|
-
done: e === "switch" ||
|
|
204
|
+
done: e === "switch" || F === 0 ? ue : Promise.resolve()
|
|
170
205
|
};
|
|
171
206
|
}
|
|
172
|
-
function
|
|
207
|
+
function X(e) {
|
|
173
208
|
if (!S) return Promise.resolve();
|
|
174
|
-
let t =
|
|
175
|
-
|
|
209
|
+
let t = U(e.token);
|
|
210
|
+
F += 1;
|
|
176
211
|
let n = (async () => {
|
|
177
212
|
try {
|
|
178
213
|
await S({
|
|
@@ -180,110 +215,121 @@ function c(c) {
|
|
|
180
215
|
api: t
|
|
181
216
|
});
|
|
182
217
|
} finally {
|
|
183
|
-
--
|
|
218
|
+
--F;
|
|
184
219
|
}
|
|
185
220
|
})();
|
|
186
|
-
return
|
|
221
|
+
return ue = n.then(() => void 0, () => void 0), n.then(() => void 0);
|
|
187
222
|
}
|
|
188
|
-
function
|
|
223
|
+
function ye() {
|
|
189
224
|
let e = T();
|
|
190
225
|
if (!e) return null;
|
|
191
|
-
let t = e.getItem(w), n = e.getItem(
|
|
192
|
-
if (!
|
|
226
|
+
let t = e.getItem(w), n = e.getItem(k), r = e.getItem(h);
|
|
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 = ye(), { user: t, token: n } = M();
|
|
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 === D && r) return {
|
|
257
|
+
if (e.token === n && e.refreshToken === D && e.lineage === A && 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 || A !== null ? e.lineage === A : e.token === n || n !== null && r, a = e.token !== null && i, o = n !== null || t !== null || D !== null;
|
|
262
|
+
if (a || W(), D = e.refreshToken, A = e.lineage, C.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
|
|
244
|
-
if (!
|
|
245
|
-
let e =
|
|
246
|
-
if (!
|
|
247
|
-
let i =
|
|
248
|
-
return
|
|
281
|
+
function be() {
|
|
282
|
+
if (!p) return null;
|
|
283
|
+
let e = p, { token: t, user: n } = M(), r = E();
|
|
284
|
+
if (!_ && t === null && n === null && r === null) return null;
|
|
285
|
+
let i = _ ? [...R] : [];
|
|
286
|
+
return V(async () => (await c(i, o), U(t).post(e, { body: b(r) })));
|
|
249
287
|
}
|
|
250
|
-
function
|
|
251
|
-
let e =
|
|
288
|
+
function xe() {
|
|
289
|
+
let e = Z();
|
|
252
290
|
if (!e.continues) return e.done;
|
|
253
|
-
let t =
|
|
291
|
+
let t = be(), { 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 } =
|
|
294
|
+
async function Se() {
|
|
295
|
+
let { live: e, done: t } = Y("expired");
|
|
258
296
|
await t.catch(() => void 0), e && x && typeof window < "u" && window.location.assign(x);
|
|
259
297
|
}
|
|
260
|
-
let
|
|
261
|
-
baseURL:
|
|
262
|
-
prefix:
|
|
263
|
-
withCredentials:
|
|
264
|
-
csrf:
|
|
298
|
+
let Q = n({
|
|
299
|
+
baseURL: d,
|
|
300
|
+
prefix: f,
|
|
301
|
+
withCredentials: _,
|
|
302
|
+
csrf: ae,
|
|
265
303
|
fetcher: v,
|
|
266
|
-
getToken:
|
|
267
|
-
getSessionEpoch: () =>
|
|
268
|
-
refresh:
|
|
269
|
-
retry:
|
|
270
|
-
onUnauthorized:
|
|
271
|
-
}),
|
|
272
|
-
|
|
273
|
-
|
|
304
|
+
getToken: N,
|
|
305
|
+
getSessionEpoch: () => P,
|
|
306
|
+
refresh: he,
|
|
307
|
+
retry: se,
|
|
308
|
+
onUnauthorized: ge
|
|
309
|
+
}), Ce = () => K(), $ = null, we = () => N() === null ? null : A === null ? ($?.epoch !== P && ($ = {
|
|
310
|
+
epoch: P,
|
|
311
|
+
key: l()
|
|
312
|
+
}), $.key) : A, Te = {
|
|
313
|
+
current: we,
|
|
314
|
+
subscribe: (e) => C.subscribe(e)
|
|
315
|
+
};
|
|
316
|
+
r(Q, Te), r(N, Te);
|
|
317
|
+
function Ee(e) {
|
|
318
|
+
e.storageArea === T() && (e.key === null || e.key === h || e.key === w || e.key === k) && Z();
|
|
274
319
|
}
|
|
275
|
-
let
|
|
276
|
-
return
|
|
320
|
+
let De = typeof window > "u" ? null : window;
|
|
321
|
+
return De?.addEventListener("storage", Ee), {
|
|
277
322
|
useAuthStore: C,
|
|
278
|
-
api:
|
|
279
|
-
login:
|
|
280
|
-
logout:
|
|
281
|
-
refresh:
|
|
282
|
-
getToken:
|
|
283
|
-
|
|
323
|
+
api: Q,
|
|
324
|
+
login: _e,
|
|
325
|
+
logout: xe,
|
|
326
|
+
refresh: Ce,
|
|
327
|
+
getToken: N,
|
|
328
|
+
sessionKey: we,
|
|
329
|
+
dispose: () => De?.removeEventListener("storage", Ee)
|
|
284
330
|
};
|
|
285
331
|
}
|
|
286
332
|
//#endregion
|
|
287
|
-
export {
|
|
333
|
+
export { d as createTempestAuth };
|
|
288
334
|
|
|
289
335
|
//# sourceMappingURL=create-tempest-auth.js.map
|