@epam/ai-dial-chat-hooks 1.1.0-dev.393 → 1.1.0-dev.395
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/catalog.d.ts +180 -0
- package/catalog.js +3 -3
- package/index.d.ts +177 -0
- package/index.js +20 -20
- package/oauth.js +3 -3
- package/package.json +14 -14
- package/useOAuthCallbackCompletion-CvyTKLER.js +93 -0
- package/{useSkillFilePreview-BYfZUJhr.js → useSkillFilePreview-Dkx9F4D-.js} +530 -291
- package/useToolsetLogin-B05m134e.js +195 -0
- package/toolset-id-CkxRHyU0.js +0 -10
- package/useToolsetLogin-GhFtKs4D.js +0 -276
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { generateUUID as e } from "@epam/ai-dial-chat-shared";
|
|
2
|
+
import { useCallback as t } from "react";
|
|
3
|
+
//#region src/oauth/toolset-id.ts
|
|
4
|
+
var n = "toolsets/", r = "public", i = (e) => e.split("/").map((e) => encodeURIComponent(e)).join("/"), a = (e) => e.split("/").map((e) => {
|
|
5
|
+
try {
|
|
6
|
+
return decodeURIComponent(e);
|
|
7
|
+
} catch {
|
|
8
|
+
return e;
|
|
9
|
+
}
|
|
10
|
+
}).join("/"), o = (e) => e.startsWith(n) ? e.slice(9).split("/")[0] === r : !1, s = /* @__PURE__ */ function(e) {
|
|
11
|
+
return e.None = "NONE", e.ApiKey = "API_KEY", e.OAuth = "OAUTH", e;
|
|
12
|
+
}({}), c = /* @__PURE__ */ function(e) {
|
|
13
|
+
return e.SignedIn = "SIGNED_IN", e.SignedOut = "SIGNED_OUT", e.Failed = "FAILED", e;
|
|
14
|
+
}({}), l = /* @__PURE__ */ function(e) {
|
|
15
|
+
return e.Global = "GLOBAL", e.User = "USER", e.App = "APP", e;
|
|
16
|
+
}({}), u = /* @__PURE__ */ function(e) {
|
|
17
|
+
return e.WithLogin = "with-login", e.WithoutLogin = "without-login", e.WithConfig = "with-config", e;
|
|
18
|
+
}({}), d = /* @__PURE__ */ function(e) {
|
|
19
|
+
return e.Toolset = "toolset", e.ExternalService = "external-service", e.OfflineCredentials = "offline-credentials", e;
|
|
20
|
+
}({}), f = /* @__PURE__ */ function(e) {
|
|
21
|
+
return e.Started = "started", e.Blocked = "blocked", e.InvalidConfig = "invalid-config", e;
|
|
22
|
+
}({}), p = /* @__PURE__ */ function(e) {
|
|
23
|
+
return e.Success = "success", e.Failure = "failure", e.Cancelled = "cancelled", e;
|
|
24
|
+
}({}), m = /* @__PURE__ */ function(e) {
|
|
25
|
+
return e.MissingCode = "missing-code", e.MissingRedirectState = "missing-redirect-state", e.StateMismatch = "state-mismatch", e.LoginRequestFailed = "login-request-failed", e;
|
|
26
|
+
}({}), h = /* @__PURE__ */ function(e) {
|
|
27
|
+
return e.ResultAcknowledged = "result-acknowledged", e;
|
|
28
|
+
}({}), g = /* @__PURE__ */ function(e) {
|
|
29
|
+
return e.Result = "toolsetOAuthResult", e.FailureReason = "toolsetOAuthFailureReason", e;
|
|
30
|
+
}({}), _ = "toolset-redirect-state", v = "toolset-login-success", y = new EventTarget(), b = (e) => {
|
|
31
|
+
y.dispatchEvent(new CustomEvent(v, { detail: e }));
|
|
32
|
+
}, x = (e) => {
|
|
33
|
+
let t = (t) => {
|
|
34
|
+
e(t.detail);
|
|
35
|
+
};
|
|
36
|
+
return y.addEventListener(v, t), () => {
|
|
37
|
+
y.removeEventListener(v, t);
|
|
38
|
+
};
|
|
39
|
+
}, S = "toolset-oauth-", C = (e) => `${S}${e}`, w = 300 * 1e3, T = 500, E = (e) => {
|
|
40
|
+
switch (e) {
|
|
41
|
+
case m.MissingCode:
|
|
42
|
+
case m.MissingRedirectState:
|
|
43
|
+
case m.StateMismatch:
|
|
44
|
+
case m.LoginRequestFailed: return e;
|
|
45
|
+
default: return m.LoginRequestFailed;
|
|
46
|
+
}
|
|
47
|
+
}, D = (e) => typeof e == "object" && !!e && "type" in e && (e.type === p.Success || e.type === p.Failure), O = (e, t, { toolsetId: n, credentialsLevel: r, callbackPath: i, timeoutMs: a = w, pollIntervalMs: o = T }) => new Promise((s) => {
|
|
48
|
+
let c, l = !1, u = () => {
|
|
49
|
+
let e = c;
|
|
50
|
+
c = void 0, e != null && setTimeout(() => e.close(), 0);
|
|
51
|
+
}, d = (e) => {
|
|
52
|
+
l || (l = !0, clearInterval(v), clearTimeout(y), window.removeEventListener("focus", _), u(), s(e));
|
|
53
|
+
}, f = (t) => {
|
|
54
|
+
c?.postMessage({ type: h.ResultAcknowledged });
|
|
55
|
+
try {
|
|
56
|
+
e.close();
|
|
57
|
+
} catch {}
|
|
58
|
+
d(t);
|
|
59
|
+
}, m = () => {
|
|
60
|
+
try {
|
|
61
|
+
let t = new URL(e.location.href);
|
|
62
|
+
if (t.origin !== window.location.origin || t.pathname !== i) return null;
|
|
63
|
+
let a = t.searchParams.get(g.Result);
|
|
64
|
+
if (a === p.Success) return {
|
|
65
|
+
type: p.Success,
|
|
66
|
+
toolsetId: n,
|
|
67
|
+
credentialsLevel: r
|
|
68
|
+
};
|
|
69
|
+
if (a === p.Failure) return {
|
|
70
|
+
type: p.Failure,
|
|
71
|
+
reason: E(t.searchParams.get(g.FailureReason))
|
|
72
|
+
};
|
|
73
|
+
} catch {}
|
|
74
|
+
return null;
|
|
75
|
+
}, _ = () => {
|
|
76
|
+
let t = m();
|
|
77
|
+
if (t != null) {
|
|
78
|
+
f(t);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
e.closed && d({ type: p.Cancelled });
|
|
82
|
+
};
|
|
83
|
+
try {
|
|
84
|
+
c = new BroadcastChannel(C(t)), c.onmessage = (e) => {
|
|
85
|
+
D(e.data) && f(e.data);
|
|
86
|
+
};
|
|
87
|
+
} catch {}
|
|
88
|
+
window.addEventListener("focus", _);
|
|
89
|
+
let v = setInterval(() => {
|
|
90
|
+
let e = m();
|
|
91
|
+
if (e != null) {
|
|
92
|
+
f(e);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
}, o), y = setTimeout(() => {
|
|
96
|
+
e.close(), d({ type: p.Cancelled });
|
|
97
|
+
}, a), b = m();
|
|
98
|
+
b != null && f(b);
|
|
99
|
+
}), k = (e) => `${window.location.origin}${e}`, A = (e) => e === "localhost" || e === "[::1]" || /^127(?:\.\d{1,3}){3}$/.test(e), j = (e) => e.protocol === "https:" ? !0 : e.protocol === "http:" && A(e.hostname), M = (e, t, n) => {
|
|
100
|
+
if (!e.authorizationEndpoint?.trim() || !e.clientId?.trim()) return null;
|
|
101
|
+
try {
|
|
102
|
+
let r = new URL(e.authorizationEndpoint.trim());
|
|
103
|
+
return j(r) ? (r.searchParams.set("response_type", "code"), r.searchParams.set("client_id", e.clientId.trim()), r.searchParams.set("redirect_uri", t), e.codeChallenge && r.searchParams.set("code_challenge", e.codeChallenge), e.codeChallengeMethod && r.searchParams.set("code_challenge_method", e.codeChallengeMethod), r.searchParams.set("state", n), e.scopes && e.scopes.length > 0 && r.searchParams.set("scope", e.scopes.join(" ")), r.toString()) : null;
|
|
104
|
+
} catch {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
}, N = (e, t, n, r, i, a, o = d.Toolset, s) => {
|
|
108
|
+
let c = {
|
|
109
|
+
toolsetId: r,
|
|
110
|
+
credentialsLevel: i,
|
|
111
|
+
redirectUri: a,
|
|
112
|
+
state: n,
|
|
113
|
+
resourceKind: o,
|
|
114
|
+
offlineUsageConsent: s
|
|
115
|
+
};
|
|
116
|
+
return e.sessionStorage.setItem(_, JSON.stringify(c)), e.opener = null, e.location.href = t, {
|
|
117
|
+
type: f.Started,
|
|
118
|
+
popup: e,
|
|
119
|
+
flowId: n
|
|
120
|
+
};
|
|
121
|
+
}, P = () => window.open("", "_blank"), F = (t, n, r, i, a = l.User, o = d.Toolset, s) => {
|
|
122
|
+
let c = k(i), u = e(), p = M(n, c, u);
|
|
123
|
+
return p ? N(t, p, u, r, a, c, o, s) : (t.close(), { type: f.InvalidConfig });
|
|
124
|
+
}, I = (t, n, r, i = l.User, a) => {
|
|
125
|
+
let o = k(r), s = e(), c = M(t, o, s);
|
|
126
|
+
if (!c) return { type: f.InvalidConfig };
|
|
127
|
+
let u = P();
|
|
128
|
+
return u ? N(u, c, s, n, i, o, d.Toolset, a) : { type: f.Blocked };
|
|
129
|
+
}, L = /* @__PURE__ */ function(e) {
|
|
130
|
+
return e.Success = "success", e.Failure = "failure", e.PopupBlocked = "popup-blocked", e.Cancelled = "cancelled", e;
|
|
131
|
+
}({}), R = ({ callbackPath: e, loginToolset: n, logoutToolset: r, getToolset: i }) => {
|
|
132
|
+
let a = t(async (e, t, n) => {
|
|
133
|
+
try {
|
|
134
|
+
await r(e, {
|
|
135
|
+
url: e,
|
|
136
|
+
credentialsLevel: t,
|
|
137
|
+
authenticationType: n
|
|
138
|
+
});
|
|
139
|
+
} catch {}
|
|
140
|
+
}, [r]), o = t(async (t) => {
|
|
141
|
+
let { toolsetId: n, credentialsLevel: r, oauthSettings: o, forceStale: u, offlineUsageConsent: m } = t, h = {
|
|
142
|
+
clientId: o?.clientId,
|
|
143
|
+
authorizationEndpoint: o?.authorizationEndpoint,
|
|
144
|
+
scopes: o?.scopes,
|
|
145
|
+
codeChallenge: o?.codeChallenge,
|
|
146
|
+
codeChallengeMethod: o?.codeChallengeMethod
|
|
147
|
+
}, g = u ? await (async () => {
|
|
148
|
+
let t = P();
|
|
149
|
+
return t ? (await a(n, r, s.OAuth), F(t, h, n, e, r, d.Toolset, m)) : { type: f.Blocked };
|
|
150
|
+
})() : I(h, n, e, r, m);
|
|
151
|
+
if (g.type === f.Blocked) return { type: "popup-blocked" };
|
|
152
|
+
if (g.type !== f.Started) return { type: "failure" };
|
|
153
|
+
let _ = await O(g.popup, g.flowId, {
|
|
154
|
+
toolsetId: n,
|
|
155
|
+
credentialsLevel: r,
|
|
156
|
+
callbackPath: e
|
|
157
|
+
});
|
|
158
|
+
if (_.type === p.Success) return b({
|
|
159
|
+
toolsetId: n,
|
|
160
|
+
credentialsLevel: r
|
|
161
|
+
}), { type: "success" };
|
|
162
|
+
if (_.type === p.Failure) return { type: "failure" };
|
|
163
|
+
try {
|
|
164
|
+
let e = await i(n);
|
|
165
|
+
if ((r === l.User ? e.authSettings?.userLevelAuthStatus : e.authSettings?.globalAuthStatus) === c.SignedIn) return b({
|
|
166
|
+
toolsetId: n,
|
|
167
|
+
credentialsLevel: r
|
|
168
|
+
}), { type: "success" };
|
|
169
|
+
} catch {}
|
|
170
|
+
return { type: "cancelled" };
|
|
171
|
+
}, [
|
|
172
|
+
e,
|
|
173
|
+
i,
|
|
174
|
+
a
|
|
175
|
+
]), u = t(async (e) => {
|
|
176
|
+
let { toolsetId: t, credentialsLevel: r, authenticationType: i, apiKey: o, isCurrentlyFailed: s, forceStale: c, offlineUsageConsent: l } = e;
|
|
177
|
+
try {
|
|
178
|
+
return (c || s) && await a(t, r, i), await n(t, {
|
|
179
|
+
url: t,
|
|
180
|
+
credentialsLevel: r,
|
|
181
|
+
authenticationType: i,
|
|
182
|
+
apiKey: o?.trim(),
|
|
183
|
+
offlineUsageConsent: l
|
|
184
|
+
}), b({
|
|
185
|
+
toolsetId: t,
|
|
186
|
+
credentialsLevel: r
|
|
187
|
+
}), { type: "success" };
|
|
188
|
+
} catch {
|
|
189
|
+
return { type: "failure" };
|
|
190
|
+
}
|
|
191
|
+
}, [n, a]);
|
|
192
|
+
return { login: t((e) => e.authenticationType === s.OAuth ? o(e) : u(e), [o, u]) };
|
|
193
|
+
};
|
|
194
|
+
//#endregion
|
|
195
|
+
export { a as C, u as S, o as T, g as _, P as a, f as b, C as c, x as d, d as f, l as g, s as h, F as i, O as l, c as m, R as n, M as o, _ as p, I as r, k as s, L as t, b as u, h as v, i as w, p as x, m as y };
|
package/toolset-id-CkxRHyU0.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
//#region src/oauth/toolset-id.ts
|
|
2
|
-
var e = "toolsets/", t = "public", n = (e) => e.split("/").map((e) => encodeURIComponent(e)).join("/"), r = (e) => e.split("/").map((e) => {
|
|
3
|
-
try {
|
|
4
|
-
return decodeURIComponent(e);
|
|
5
|
-
} catch {
|
|
6
|
-
return e;
|
|
7
|
-
}
|
|
8
|
-
}).join("/"), i = (n) => n.startsWith(e) ? n.slice(9).split("/")[0] === t : !1;
|
|
9
|
-
//#endregion
|
|
10
|
-
export { n, i as r, r as t };
|
|
@@ -1,276 +0,0 @@
|
|
|
1
|
-
import { generateUUID as e } from "@epam/ai-dial-chat-shared";
|
|
2
|
-
import { useCallback as t, useEffect as n, useRef as r, useState as i } from "react";
|
|
3
|
-
//#region src/oauth/authorize-url.ts
|
|
4
|
-
var a = (e) => `${window.location.origin}${e}`, o = (e) => e === "localhost" || e === "[::1]" || /^127(?:\.\d{1,3}){3}$/.test(e), s = (e) => e.protocol === "https:" ? !0 : e.protocol === "http:" && o(e.hostname), c = (e, t, n) => {
|
|
5
|
-
if (!e.authorizationEndpoint?.trim() || !e.clientId?.trim()) return null;
|
|
6
|
-
try {
|
|
7
|
-
let r = new URL(e.authorizationEndpoint.trim());
|
|
8
|
-
return s(r) ? (r.searchParams.set("response_type", "code"), r.searchParams.set("client_id", e.clientId.trim()), r.searchParams.set("redirect_uri", t), e.codeChallenge && r.searchParams.set("code_challenge", e.codeChallenge), e.codeChallengeMethod && r.searchParams.set("code_challenge_method", e.codeChallengeMethod), r.searchParams.set("state", n), e.scopes && e.scopes.length > 0 && r.searchParams.set("scope", e.scopes.join(" ")), r.toString()) : null;
|
|
9
|
-
} catch {
|
|
10
|
-
return null;
|
|
11
|
-
}
|
|
12
|
-
}, l = /* @__PURE__ */ function(e) {
|
|
13
|
-
return e.None = "NONE", e.ApiKey = "API_KEY", e.OAuth = "OAUTH", e;
|
|
14
|
-
}({}), u = /* @__PURE__ */ function(e) {
|
|
15
|
-
return e.SignedIn = "SIGNED_IN", e.SignedOut = "SIGNED_OUT", e.Failed = "FAILED", e;
|
|
16
|
-
}({}), d = /* @__PURE__ */ function(e) {
|
|
17
|
-
return e.Global = "GLOBAL", e.User = "USER", e.App = "APP", e;
|
|
18
|
-
}({}), f = /* @__PURE__ */ function(e) {
|
|
19
|
-
return e.WithLogin = "with-login", e.WithoutLogin = "without-login", e.WithConfig = "with-config", e;
|
|
20
|
-
}({}), p = /* @__PURE__ */ function(e) {
|
|
21
|
-
return e.Toolset = "toolset", e.ExternalService = "external-service", e.OfflineCredentials = "offline-credentials", e;
|
|
22
|
-
}({}), m = /* @__PURE__ */ function(e) {
|
|
23
|
-
return e.Started = "started", e.Blocked = "blocked", e.InvalidConfig = "invalid-config", e;
|
|
24
|
-
}({}), h = /* @__PURE__ */ function(e) {
|
|
25
|
-
return e.Success = "success", e.Failure = "failure", e.Cancelled = "cancelled", e;
|
|
26
|
-
}({}), g = /* @__PURE__ */ function(e) {
|
|
27
|
-
return e.MissingCode = "missing-code", e.MissingRedirectState = "missing-redirect-state", e.StateMismatch = "state-mismatch", e.LoginRequestFailed = "login-request-failed", e;
|
|
28
|
-
}({}), _ = /* @__PURE__ */ function(e) {
|
|
29
|
-
return e.ResultAcknowledged = "result-acknowledged", e;
|
|
30
|
-
}({}), v = /* @__PURE__ */ function(e) {
|
|
31
|
-
return e.Result = "toolsetOAuthResult", e.FailureReason = "toolsetOAuthFailureReason", e;
|
|
32
|
-
}({}), y = "toolset-redirect-state", b = "toolset-oauth-", x = (e) => `${b}${e}`, S = 300 * 1e3, C = 500, w = (e) => {
|
|
33
|
-
switch (e) {
|
|
34
|
-
case g.MissingCode:
|
|
35
|
-
case g.MissingRedirectState:
|
|
36
|
-
case g.StateMismatch:
|
|
37
|
-
case g.LoginRequestFailed: return e;
|
|
38
|
-
default: return g.LoginRequestFailed;
|
|
39
|
-
}
|
|
40
|
-
}, T = (e) => typeof e == "object" && !!e && "type" in e && (e.type === h.Success || e.type === h.Failure), E = (e, t, { toolsetId: n, credentialsLevel: r, callbackPath: i, timeoutMs: a = S, pollIntervalMs: o = C }) => new Promise((s) => {
|
|
41
|
-
let c, l = !1, u = () => {
|
|
42
|
-
let e = c;
|
|
43
|
-
c = void 0, e != null && setTimeout(() => e.close(), 0);
|
|
44
|
-
}, d = (e) => {
|
|
45
|
-
l || (l = !0, clearInterval(g), clearTimeout(y), window.removeEventListener("focus", m), u(), s(e));
|
|
46
|
-
}, f = (t) => {
|
|
47
|
-
c?.postMessage({ type: _.ResultAcknowledged });
|
|
48
|
-
try {
|
|
49
|
-
e.close();
|
|
50
|
-
} catch {}
|
|
51
|
-
d(t);
|
|
52
|
-
}, p = () => {
|
|
53
|
-
try {
|
|
54
|
-
let t = new URL(e.location.href);
|
|
55
|
-
if (t.origin !== window.location.origin || t.pathname !== i) return null;
|
|
56
|
-
let a = t.searchParams.get(v.Result);
|
|
57
|
-
if (a === h.Success) return {
|
|
58
|
-
type: h.Success,
|
|
59
|
-
toolsetId: n,
|
|
60
|
-
credentialsLevel: r
|
|
61
|
-
};
|
|
62
|
-
if (a === h.Failure) return {
|
|
63
|
-
type: h.Failure,
|
|
64
|
-
reason: w(t.searchParams.get(v.FailureReason))
|
|
65
|
-
};
|
|
66
|
-
} catch {}
|
|
67
|
-
return null;
|
|
68
|
-
}, m = () => {
|
|
69
|
-
let t = p();
|
|
70
|
-
if (t != null) {
|
|
71
|
-
f(t);
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
e.closed && d({ type: h.Cancelled });
|
|
75
|
-
};
|
|
76
|
-
try {
|
|
77
|
-
c = new BroadcastChannel(x(t)), c.onmessage = (e) => {
|
|
78
|
-
T(e.data) && f(e.data);
|
|
79
|
-
};
|
|
80
|
-
} catch {}
|
|
81
|
-
window.addEventListener("focus", m);
|
|
82
|
-
let g = setInterval(() => {
|
|
83
|
-
let e = p();
|
|
84
|
-
if (e != null) {
|
|
85
|
-
f(e);
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
}, o), y = setTimeout(() => {
|
|
89
|
-
e.close(), d({ type: h.Cancelled });
|
|
90
|
-
}, a), b = p();
|
|
91
|
-
b != null && f(b);
|
|
92
|
-
}), D = (e, t, n, r, i, a, o = p.Toolset, s) => {
|
|
93
|
-
let c = {
|
|
94
|
-
toolsetId: r,
|
|
95
|
-
credentialsLevel: i,
|
|
96
|
-
redirectUri: a,
|
|
97
|
-
state: n,
|
|
98
|
-
resourceKind: o,
|
|
99
|
-
offlineUsageConsent: s
|
|
100
|
-
};
|
|
101
|
-
return e.sessionStorage.setItem(y, JSON.stringify(c)), e.opener = null, e.location.href = t, {
|
|
102
|
-
type: m.Started,
|
|
103
|
-
popup: e,
|
|
104
|
-
flowId: n
|
|
105
|
-
};
|
|
106
|
-
}, O = () => window.open("", "_blank"), k = (t, n, r, i, o = d.User, s = p.Toolset, l) => {
|
|
107
|
-
let u = a(i), f = e(), h = c(n, u, f);
|
|
108
|
-
return h ? D(t, h, f, r, o, u, s, l) : (t.close(), { type: m.InvalidConfig });
|
|
109
|
-
}, A = (t, n, r, i = d.User, o) => {
|
|
110
|
-
let s = a(r), l = e(), u = c(t, s, l);
|
|
111
|
-
if (!u) return { type: m.InvalidConfig };
|
|
112
|
-
let f = O();
|
|
113
|
-
return f ? D(f, u, l, n, i, s, p.Toolset, o) : { type: m.Blocked };
|
|
114
|
-
}, j = 500, M = (e) => typeof e == "object" && !!e && "type" in e && e.type === _.ResultAcknowledged, N = () => {
|
|
115
|
-
let e = sessionStorage.getItem(y);
|
|
116
|
-
if (!e) return null;
|
|
117
|
-
try {
|
|
118
|
-
return JSON.parse(e);
|
|
119
|
-
} catch {
|
|
120
|
-
return null;
|
|
121
|
-
}
|
|
122
|
-
}, P = (e) => {
|
|
123
|
-
try {
|
|
124
|
-
window.history.replaceState({}, document.title, `${e.pathname}${e.search}`);
|
|
125
|
-
} catch {}
|
|
126
|
-
}, F = (e, t) => {
|
|
127
|
-
let n = new URL(window.location.pathname, window.location.origin);
|
|
128
|
-
if (n.searchParams.set(v.Result, t.type), t.type === h.Failure && n.searchParams.set(v.FailureReason, t.reason), P(n), !e) {
|
|
129
|
-
window.close();
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
try {
|
|
133
|
-
let n = new BroadcastChannel(x(e));
|
|
134
|
-
n.postMessage(t);
|
|
135
|
-
let r = setInterval(() => {
|
|
136
|
-
n.postMessage(t);
|
|
137
|
-
}, j);
|
|
138
|
-
n.onmessage = (e) => {
|
|
139
|
-
M(e.data) && (clearInterval(r), n.close(), window.close());
|
|
140
|
-
};
|
|
141
|
-
} catch {}
|
|
142
|
-
}, I = ({ searchParams: e, callbackPath: t, exchange: a }) => {
|
|
143
|
-
let [o, s] = i(!0), [c, l] = i(null), u = r(!1), f = r(a);
|
|
144
|
-
f.current = a;
|
|
145
|
-
let p = r(t);
|
|
146
|
-
return p.current = t, n(() => {
|
|
147
|
-
if (u.current) return;
|
|
148
|
-
u.current = !0;
|
|
149
|
-
let t = (e, t) => {
|
|
150
|
-
F(e, t), s(!1), l(t.type === h.Failure ? t.reason : null);
|
|
151
|
-
};
|
|
152
|
-
(async () => {
|
|
153
|
-
let n = e.get("code"), r = e.get("state"), i = N();
|
|
154
|
-
sessionStorage.removeItem(y);
|
|
155
|
-
let a = i?.state ?? r ?? void 0;
|
|
156
|
-
if (P(new URL(window.location.pathname, window.location.origin)), !n || !i?.toolsetId) {
|
|
157
|
-
t(a, {
|
|
158
|
-
type: h.Failure,
|
|
159
|
-
reason: i?.toolsetId ? g.MissingCode : g.MissingRedirectState
|
|
160
|
-
});
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
if (i.state != null && i.state !== r) {
|
|
164
|
-
t(a, {
|
|
165
|
-
type: h.Failure,
|
|
166
|
-
reason: g.StateMismatch
|
|
167
|
-
});
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
let o = i.credentialsLevel ?? d.User, s = i.redirectUri ?? `${window.location.origin}${p.current}`;
|
|
171
|
-
try {
|
|
172
|
-
let e = await f.current({
|
|
173
|
-
code: n,
|
|
174
|
-
redirectUri: s,
|
|
175
|
-
credentialsLevel: o,
|
|
176
|
-
redirectState: i
|
|
177
|
-
});
|
|
178
|
-
if (e != null) {
|
|
179
|
-
t(a, {
|
|
180
|
-
type: h.Failure,
|
|
181
|
-
reason: e
|
|
182
|
-
});
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
t(a, {
|
|
186
|
-
type: h.Success,
|
|
187
|
-
toolsetId: i.toolsetId,
|
|
188
|
-
credentialsLevel: o
|
|
189
|
-
});
|
|
190
|
-
} catch {
|
|
191
|
-
t(a, {
|
|
192
|
-
type: h.Failure,
|
|
193
|
-
reason: g.LoginRequestFailed
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
})();
|
|
197
|
-
}, [e]), {
|
|
198
|
-
isInProgress: o,
|
|
199
|
-
failureReason: c
|
|
200
|
-
};
|
|
201
|
-
}, L = "toolset-login-success", R = new EventTarget(), z = (e) => {
|
|
202
|
-
R.dispatchEvent(new CustomEvent(L, { detail: e }));
|
|
203
|
-
}, B = (e) => {
|
|
204
|
-
let t = (t) => {
|
|
205
|
-
e(t.detail);
|
|
206
|
-
};
|
|
207
|
-
return R.addEventListener(L, t), () => {
|
|
208
|
-
R.removeEventListener(L, t);
|
|
209
|
-
};
|
|
210
|
-
}, V = /* @__PURE__ */ function(e) {
|
|
211
|
-
return e.Success = "success", e.Failure = "failure", e.PopupBlocked = "popup-blocked", e.Cancelled = "cancelled", e;
|
|
212
|
-
}({}), H = ({ callbackPath: e, loginToolset: n, logoutToolset: r, getToolset: i }) => {
|
|
213
|
-
let a = t(async (e, t, n) => {
|
|
214
|
-
try {
|
|
215
|
-
await r(e, {
|
|
216
|
-
url: e,
|
|
217
|
-
credentialsLevel: t,
|
|
218
|
-
authenticationType: n
|
|
219
|
-
});
|
|
220
|
-
} catch {}
|
|
221
|
-
}, [r]), o = t(async (t) => {
|
|
222
|
-
let { toolsetId: n, credentialsLevel: r, oauthSettings: o, forceStale: s, offlineUsageConsent: c } = t, f = {
|
|
223
|
-
clientId: o?.clientId,
|
|
224
|
-
authorizationEndpoint: o?.authorizationEndpoint,
|
|
225
|
-
scopes: o?.scopes,
|
|
226
|
-
codeChallenge: o?.codeChallenge,
|
|
227
|
-
codeChallengeMethod: o?.codeChallengeMethod
|
|
228
|
-
}, g = s ? await (async () => {
|
|
229
|
-
let t = O();
|
|
230
|
-
return t ? (await a(n, r, l.OAuth), k(t, f, n, e, r, p.Toolset, c)) : { type: m.Blocked };
|
|
231
|
-
})() : A(f, n, e, r, c);
|
|
232
|
-
if (g.type === m.Blocked) return { type: "popup-blocked" };
|
|
233
|
-
if (g.type !== m.Started) return { type: "failure" };
|
|
234
|
-
let _ = await E(g.popup, g.flowId, {
|
|
235
|
-
toolsetId: n,
|
|
236
|
-
credentialsLevel: r,
|
|
237
|
-
callbackPath: e
|
|
238
|
-
});
|
|
239
|
-
if (_.type === h.Success) return z({
|
|
240
|
-
toolsetId: n,
|
|
241
|
-
credentialsLevel: r
|
|
242
|
-
}), { type: "success" };
|
|
243
|
-
if (_.type === h.Failure) return { type: "failure" };
|
|
244
|
-
try {
|
|
245
|
-
let e = await i(n);
|
|
246
|
-
if ((r === d.User ? e.authSettings?.userLevelAuthStatus : e.authSettings?.globalAuthStatus) === u.SignedIn) return z({
|
|
247
|
-
toolsetId: n,
|
|
248
|
-
credentialsLevel: r
|
|
249
|
-
}), { type: "success" };
|
|
250
|
-
} catch {}
|
|
251
|
-
return { type: "cancelled" };
|
|
252
|
-
}, [
|
|
253
|
-
e,
|
|
254
|
-
i,
|
|
255
|
-
a
|
|
256
|
-
]), s = t(async (e) => {
|
|
257
|
-
let { toolsetId: t, credentialsLevel: r, authenticationType: i, apiKey: o, isCurrentlyFailed: s, forceStale: c, offlineUsageConsent: l } = e;
|
|
258
|
-
try {
|
|
259
|
-
return (c || s) && await a(t, r, i), await n(t, {
|
|
260
|
-
url: t,
|
|
261
|
-
credentialsLevel: r,
|
|
262
|
-
authenticationType: i,
|
|
263
|
-
apiKey: o?.trim(),
|
|
264
|
-
offlineUsageConsent: l
|
|
265
|
-
}), z({
|
|
266
|
-
toolsetId: t,
|
|
267
|
-
credentialsLevel: r
|
|
268
|
-
}), { type: "success" };
|
|
269
|
-
} catch {
|
|
270
|
-
return { type: "failure" };
|
|
271
|
-
}
|
|
272
|
-
}, [n, a]);
|
|
273
|
-
return { login: t((e) => e.authenticationType === l.OAuth ? o(e) : s(e), [o, s]) };
|
|
274
|
-
};
|
|
275
|
-
//#endregion
|
|
276
|
-
export { a as C, c as S, _, I as a, h as b, O as c, p as d, y as f, v as g, d as h, B as i, x as l, l as m, H as n, A as o, u as p, z as r, k as s, V as t, E as u, g as v, f as x, m as y };
|