@uipath/automation-hub-tool 1.201.0-preview.123

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.
@@ -0,0 +1,99 @@
1
+ import {
2
+ getGlobalThis
3
+ } from "./tool-9qecd4wb.js";
4
+ import {
5
+ AUTH_CANCELLED_ERROR_CODE
6
+ } from "./tool-5arsyj36.js";
7
+ import"./tool-0v6na3yp.js";
8
+
9
+ // ../auth/src/strategies/browser-strategy.ts
10
+ class BrowserAuthStrategy {
11
+ async execute(url, _redirectUri, expectedState, opts) {
12
+ const global = getGlobalThis();
13
+ if (!global?.window) {
14
+ throw new Error("Browser environment required for authentication");
15
+ }
16
+ const screenWidth = global.window.screen?.width ?? 1024;
17
+ const screenHeight = global.window.screen?.height ?? 768;
18
+ const width = 600;
19
+ const height = 700;
20
+ const left = screenWidth / 2 - width / 2;
21
+ const top = screenHeight / 2 - height / 2;
22
+ if (!global.window.open) {
23
+ throw new Error("window.open is not available");
24
+ }
25
+ const popupResult = global.window.open(url, "uip_auth", `width=${width},height=${height},left=${left},top=${top},resizable=yes,scrollbars=yes,status=yes`);
26
+ const popup = popupResult;
27
+ if (!popup) {
28
+ throw new Error(`Authentication popup was blocked by your browser.
29
+
30
+ ` + `To continue:
31
+ ` + `1. Look for a popup blocker icon in your address bar
32
+ ` + `2. Allow popups for this site
33
+ ` + `3. Try logging in again
34
+
35
+ ` + "If using an ad blocker, you may need to temporarily disable it.");
36
+ }
37
+ return new Promise((resolve, reject) => {
38
+ let timer;
39
+ const messageHandler = (event) => {
40
+ if (event.data?.type === "UIP_AUTH_CODE" && event.data.code) {
41
+ if (event.data.state !== expectedState) {
42
+ cleanup();
43
+ reject(new Error("OAuth state mismatch — the callback state does not match the expected value. " + "This may indicate a CSRF attack. Please try signing in again."));
44
+ popup.close();
45
+ return;
46
+ }
47
+ cleanup();
48
+ resolve(event.data.code);
49
+ popup.close();
50
+ } else if (event.data?.type === "UIP_AUTH_ERROR") {
51
+ cleanup();
52
+ const errorMsg = event.data.error || "Authentication failed";
53
+ reject(new Error(`Authentication failed: ${errorMsg}
54
+
55
+ ` + "Please check your credentials and try again. " + "If the problem persists, verify your UiPath account is active."));
56
+ popup.close();
57
+ }
58
+ };
59
+ const cleanup = () => {
60
+ global.window?.removeEventListener?.("message", messageHandler);
61
+ opts?.signal?.removeEventListener("abort", onAbort);
62
+ if (timer)
63
+ clearInterval(timer);
64
+ };
65
+ const onAbort = () => {
66
+ cleanup();
67
+ const err = new Error(`Authentication was cancelled.
68
+
69
+ ` + "The sign-in was cancelled before completing the login process. " + "Please try again and complete the authentication flow.");
70
+ err.code = AUTH_CANCELLED_ERROR_CODE;
71
+ reject(err);
72
+ popup.close();
73
+ };
74
+ if (opts?.signal) {
75
+ if (opts.signal.aborted) {
76
+ onAbort();
77
+ return;
78
+ }
79
+ opts.signal.addEventListener("abort", onAbort, { once: true });
80
+ }
81
+ if (global.window?.addEventListener) {
82
+ global.window.addEventListener("message", messageHandler);
83
+ }
84
+ timer = setInterval(() => {
85
+ if (popup.closed) {
86
+ cleanup();
87
+ reject(new Error(`Authentication was cancelled.
88
+
89
+ ` + "The authentication popup was closed before completing the login process. " + "Please try again and complete the authentication flow."));
90
+ }
91
+ }, 1000);
92
+ });
93
+ }
94
+ }
95
+ export {
96
+ BrowserAuthStrategy
97
+ };
98
+
99
+ //# debugId=B13A3005E9EE6C6564756E2164756E21