@uipath/guardrails-tool 1.200.0-preview.118

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,98 @@
1
+ import {
2
+ getGlobalThis
3
+ } from "./tool-eb3gcj08.js";
4
+ import {
5
+ AUTH_CANCELLED_ERROR_CODE
6
+ } from "./tool-e850pwaz.js";
7
+
8
+ // ../../auth/src/strategies/browser-strategy.ts
9
+ class BrowserAuthStrategy {
10
+ async execute(url, _redirectUri, expectedState, opts) {
11
+ const global = getGlobalThis();
12
+ if (!global?.window) {
13
+ throw new Error("Browser environment required for authentication");
14
+ }
15
+ const screenWidth = global.window.screen?.width ?? 1024;
16
+ const screenHeight = global.window.screen?.height ?? 768;
17
+ const width = 600;
18
+ const height = 700;
19
+ const left = screenWidth / 2 - width / 2;
20
+ const top = screenHeight / 2 - height / 2;
21
+ if (!global.window.open) {
22
+ throw new Error("window.open is not available");
23
+ }
24
+ const popupResult = global.window.open(url, "uip_auth", `width=${width},height=${height},left=${left},top=${top},resizable=yes,scrollbars=yes,status=yes`);
25
+ const popup = popupResult;
26
+ if (!popup) {
27
+ throw new Error(`Authentication popup was blocked by your browser.
28
+
29
+ ` + `To continue:
30
+ ` + `1. Look for a popup blocker icon in your address bar
31
+ ` + `2. Allow popups for this site
32
+ ` + `3. Try logging in again
33
+
34
+ ` + "If using an ad blocker, you may need to temporarily disable it.");
35
+ }
36
+ return new Promise((resolve, reject) => {
37
+ let timer;
38
+ const messageHandler = (event) => {
39
+ if (event.data?.type === "UIP_AUTH_CODE" && event.data.code) {
40
+ if (event.data.state !== expectedState) {
41
+ cleanup();
42
+ 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."));
43
+ popup.close();
44
+ return;
45
+ }
46
+ cleanup();
47
+ resolve(event.data.code);
48
+ popup.close();
49
+ } else if (event.data?.type === "UIP_AUTH_ERROR") {
50
+ cleanup();
51
+ const errorMsg = event.data.error || "Authentication failed";
52
+ reject(new Error(`Authentication failed: ${errorMsg}
53
+
54
+ ` + "Please check your credentials and try again. " + "If the problem persists, verify your UiPath account is active."));
55
+ popup.close();
56
+ }
57
+ };
58
+ const cleanup = () => {
59
+ global.window?.removeEventListener?.("message", messageHandler);
60
+ opts?.signal?.removeEventListener("abort", onAbort);
61
+ if (timer)
62
+ clearInterval(timer);
63
+ };
64
+ const onAbort = () => {
65
+ cleanup();
66
+ const err = new Error(`Authentication was cancelled.
67
+
68
+ ` + "The sign-in was cancelled before completing the login process. " + "Please try again and complete the authentication flow.");
69
+ err.code = AUTH_CANCELLED_ERROR_CODE;
70
+ reject(err);
71
+ popup.close();
72
+ };
73
+ if (opts?.signal) {
74
+ if (opts.signal.aborted) {
75
+ onAbort();
76
+ return;
77
+ }
78
+ opts.signal.addEventListener("abort", onAbort, { once: true });
79
+ }
80
+ if (global.window?.addEventListener) {
81
+ global.window.addEventListener("message", messageHandler);
82
+ }
83
+ timer = setInterval(() => {
84
+ if (popup.closed) {
85
+ cleanup();
86
+ reject(new Error(`Authentication was cancelled.
87
+
88
+ ` + "The authentication popup was closed before completing the login process. " + "Please try again and complete the authentication flow."));
89
+ }
90
+ }, 1000);
91
+ });
92
+ }
93
+ }
94
+ export {
95
+ BrowserAuthStrategy
96
+ };
97
+
98
+ //# debugId=22C92539C97D452164756E2164756E21
@@ -0,0 +1,62 @@
1
+ import {
2
+ catchError,
3
+ getFileSystem,
4
+ startServer
5
+ } from "./tool-z1g01crb.js";
6
+ import"./tool-e850pwaz.js";
7
+
8
+ // ../../auth/src/strategies/node-strategy.ts
9
+ class NodeAuthStrategy {
10
+ async execute(url, redirectUri, expectedState, opts) {
11
+ const fs = getFileSystem();
12
+ const callbackUrl = await startServer({
13
+ redirectUri,
14
+ timeoutMs: opts?.timeoutMs,
15
+ signal: opts?.signal,
16
+ onListening: async () => {
17
+ let safeUrl = "";
18
+ for (const ch of url) {
19
+ const c = ch.charCodeAt(0);
20
+ if (c > 31 && (c < 128 || c > 159))
21
+ safeUrl += ch;
22
+ }
23
+ if (opts?.noBrowser) {
24
+ if (!opts.onAuthUrl) {
25
+ throw new Error("Headless login (noBrowser) requires an onAuthUrl handler " + "to surface the authorize URL, but none was provided.");
26
+ }
27
+ opts.onAuthUrl(safeUrl);
28
+ return;
29
+ }
30
+ const [openError] = await catchError(fs.utils.open(url));
31
+ if (!openError)
32
+ return;
33
+ const isSpawnError = "code" in openError && openError.code === "ENOENT";
34
+ if (isSpawnError) {
35
+ throw new Error("Could not open a browser. No supported browser launcher was found. " + `On a headless or minimal system, use non-interactive login instead:
36
+
37
+ ` + ` uip login --client-id <id> --client-secret <secret> -t <tenant>
38
+
39
+ ` + "Or install a browser opener for your OS (e.g. xdg-utils on Linux).", { cause: openError });
40
+ }
41
+ throw new Error("Could not open the browser automatically. " + `Visit this URL to authenticate:
42
+
43
+ ${safeUrl}
44
+ `, { cause: openError });
45
+ }
46
+ });
47
+ const returnedState = callbackUrl.searchParams.get("state");
48
+ if (returnedState !== expectedState) {
49
+ throw 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.");
50
+ }
51
+ const code = callbackUrl.searchParams.get("code");
52
+ if (!code) {
53
+ throw new Error("No authorization code received");
54
+ }
55
+ return code;
56
+ }
57
+ }
58
+ export {
59
+ NodeAuthStrategy
60
+ };
61
+
62
+ //# debugId=46F5130EBB60941464756E2164756E21
@@ -0,0 +1,44 @@
1
+ import { createRequire } from "node:module";
2
+ var __create = Object.create;
3
+ var __getProtoOf = Object.getPrototypeOf;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ function __accessProp(key) {
8
+ return this[key];
9
+ }
10
+ var __toESMCache_node;
11
+ var __toESMCache_esm;
12
+ var __toESM = (mod, isNodeMode, target) => {
13
+ var canCache = mod != null && typeof mod === "object";
14
+ if (canCache) {
15
+ var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
16
+ var cached = cache.get(mod);
17
+ if (cached)
18
+ return cached;
19
+ }
20
+ target = mod != null ? __create(__getProtoOf(mod)) : {};
21
+ const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
22
+ for (let key of __getOwnPropNames(mod))
23
+ if (!__hasOwnProp.call(to, key))
24
+ __defProp(to, key, {
25
+ get: __accessProp.bind(mod, key),
26
+ enumerable: true
27
+ });
28
+ if (canCache)
29
+ cache.set(mod, to);
30
+ return to;
31
+ };
32
+ var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
33
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
34
+
35
+ // ../../auth/src/constants.ts
36
+ var UIPATH_HOME_DIR = ".uipath";
37
+ var AUTH_FILENAME = ".auth";
38
+ var DEFAULT_BASE_URL = "https://cloud.uipath.com";
39
+ var DEFAULT_AUTH_TIMEOUT_MS = 5 * 60 * 1000;
40
+ var AUTH_CANCELLED_ERROR_CODE = "EAUTHCANCELLED";
41
+
42
+ export { __toESM, __commonJS, __require, UIPATH_HOME_DIR, AUTH_FILENAME, DEFAULT_BASE_URL, DEFAULT_AUTH_TIMEOUT_MS, AUTH_CANCELLED_ERROR_CODE };
43
+
44
+ //# debugId=20519AAB1C8D508164756E2164756E21
@@ -0,0 +1,14 @@
1
+ // ../../auth/src/utils/platform.ts
2
+ function isBrowser() {
3
+ return typeof globalThis !== "undefined" && "window" in globalThis && "document" in globalThis;
4
+ }
5
+ function getGlobalThis() {
6
+ if (typeof globalThis !== "undefined") {
7
+ return globalThis;
8
+ }
9
+ return;
10
+ }
11
+
12
+ export { isBrowser, getGlobalThis };
13
+
14
+ //# debugId=386466AAF1112A2264756E2164756E21