@uipath/auth 1.206.0-preview.303 → 1.207.0-preview.305
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/dist/constants.d.ts +7 -0
- package/dist/index.browser.d.ts +1 -0
- package/dist/index.browser.js +64 -6
- package/dist/index.d.ts +1 -0
- package/dist/index.js +92 -14
- package/dist/utils/lockedEnvFile.d.ts +19 -0
- package/package.json +2 -2
package/dist/constants.d.ts
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
export declare const UIPATH_HOME_DIR = ".uipath";
|
|
3
3
|
/** Auth credentials filename within the UiPath home directory. */
|
|
4
4
|
export declare const AUTH_FILENAME = ".auth";
|
|
5
|
+
/**
|
|
6
|
+
* Permission bits for credential files (owner read/write) and for a
|
|
7
|
+
* directory created to hold them (owner only). Every write or mkdir of an
|
|
8
|
+
* auth path passes these, so tokens are never readable by other local users.
|
|
9
|
+
*/
|
|
10
|
+
export declare const AUTH_FILE_MODE = 384;
|
|
11
|
+
export declare const AUTH_DIR_MODE = 448;
|
|
5
12
|
/** Default UiPath cloud base URL. */
|
|
6
13
|
export declare const DEFAULT_BASE_URL = "https://cloud.uipath.com";
|
|
7
14
|
/** Auth callback server timeout (5 minutes). */
|
package/dist/index.browser.d.ts
CHANGED
|
@@ -11,4 +11,5 @@ export * from "./tokenRefresh";
|
|
|
11
11
|
export { AUTH_FLOW_ENV_VAR, type AuthFlow, type BaseCredentials, } from "./types";
|
|
12
12
|
export { DEFAULT_AUTH_FILENAME, DEFAULT_ENV_FILENAME, type EnvFileErrorCode, type EnvFileLocation, type EnvFileSource, type EnvFileUnusable, type EnvFileUnusableReason, loadEnvFileAsync, resolveEnvFileLocationAsync, resolveEnvFilePathAsync, saveEnvFileAsync, } from "./utils/envFile";
|
|
13
13
|
export { parseJWT } from "./utils/jwt";
|
|
14
|
+
export { updateEnvFileLockedAsync } from "./utils/lockedEnvFile";
|
|
14
15
|
export { isBrowser, isNode } from "./utils/platform";
|
package/dist/index.browser.js
CHANGED
|
@@ -18180,6 +18180,8 @@ function settlePromiseLike(thenable) {
|
|
|
18180
18180
|
// src/constants.ts
|
|
18181
18181
|
var UIPATH_HOME_DIR = ".uipath";
|
|
18182
18182
|
var AUTH_FILENAME = ".auth";
|
|
18183
|
+
var AUTH_FILE_MODE = 384;
|
|
18184
|
+
var AUTH_DIR_MODE = 448;
|
|
18183
18185
|
var DEFAULT_BASE_URL = "https://cloud.uipath.com";
|
|
18184
18186
|
var DEFAULT_AUTH_TIMEOUT_MS = 5 * 60 * 1000;
|
|
18185
18187
|
var AUTH_CANCELLED_ERROR_CODE = "EAUTHCANCELLED";
|
|
@@ -19107,6 +19109,38 @@ var loadEnvFileAsync = async ({ envPath }) => {
|
|
|
19107
19109
|
}
|
|
19108
19110
|
return parseEnvContent(content);
|
|
19109
19111
|
};
|
|
19112
|
+
var findAuthHomeDir = (fs, dir) => {
|
|
19113
|
+
let current = dir;
|
|
19114
|
+
for (;; ) {
|
|
19115
|
+
if (fs.path.basename(current) === UIPATH_HOME_DIR)
|
|
19116
|
+
return current;
|
|
19117
|
+
const parent = fs.path.dirname(current);
|
|
19118
|
+
if (parent === current)
|
|
19119
|
+
return;
|
|
19120
|
+
current = parent;
|
|
19121
|
+
}
|
|
19122
|
+
};
|
|
19123
|
+
var TEMP_FILE_ATTEMPTS = 5;
|
|
19124
|
+
var isFileExists = (error) => error instanceof Error && error.code === "EEXIST";
|
|
19125
|
+
var writeTempFile = async (fs, targetPath, content) => {
|
|
19126
|
+
for (let attempt = 1;; attempt++) {
|
|
19127
|
+
const tempPath = `${targetPath}.${crypto.randomUUID()}.tmp`;
|
|
19128
|
+
try {
|
|
19129
|
+
await fs.writeFile(tempPath, content, {
|
|
19130
|
+
mode: AUTH_FILE_MODE,
|
|
19131
|
+
exclusive: true
|
|
19132
|
+
});
|
|
19133
|
+
return tempPath;
|
|
19134
|
+
} catch (error) {
|
|
19135
|
+
if (!isFileExists(error)) {
|
|
19136
|
+
await fs.rm(tempPath).catch(() => {});
|
|
19137
|
+
throw error;
|
|
19138
|
+
}
|
|
19139
|
+
if (attempt === TEMP_FILE_ATTEMPTS)
|
|
19140
|
+
throw error;
|
|
19141
|
+
}
|
|
19142
|
+
}
|
|
19143
|
+
};
|
|
19110
19144
|
var saveEnvFileAsync = async ({
|
|
19111
19145
|
envPath,
|
|
19112
19146
|
data,
|
|
@@ -19134,10 +19168,18 @@ var saveEnvFileAsync = async ({
|
|
|
19134
19168
|
`)}
|
|
19135
19169
|
`;
|
|
19136
19170
|
const dir = fs.path.dirname(absolutePath);
|
|
19137
|
-
await fs.mkdir(dir);
|
|
19138
|
-
const
|
|
19139
|
-
|
|
19140
|
-
|
|
19171
|
+
await fs.mkdir(dir, { mode: AUTH_DIR_MODE });
|
|
19172
|
+
const authHomeDir = findAuthHomeDir(fs, dir);
|
|
19173
|
+
if (authHomeDir !== undefined) {
|
|
19174
|
+
await fs.chmod?.(authHomeDir, AUTH_DIR_MODE);
|
|
19175
|
+
}
|
|
19176
|
+
const tempPath = await writeTempFile(fs, absolutePath, content);
|
|
19177
|
+
try {
|
|
19178
|
+
await fs.rename(tempPath, absolutePath);
|
|
19179
|
+
} catch (error) {
|
|
19180
|
+
await fs.rm(tempPath).catch(() => {});
|
|
19181
|
+
throw error;
|
|
19182
|
+
}
|
|
19141
19183
|
};
|
|
19142
19184
|
|
|
19143
19185
|
// src/loginStatus.ts
|
|
@@ -19992,6 +20034,21 @@ class BrowserAuthStrategy {
|
|
|
19992
20034
|
});
|
|
19993
20035
|
}
|
|
19994
20036
|
}
|
|
20037
|
+
// src/utils/lockedEnvFile.ts
|
|
20038
|
+
import { getFileSystem as getFileSystem7 } from "@uipath/filesystem";
|
|
20039
|
+
var updateEnvFileLockedAsync = async ({
|
|
20040
|
+
envPath,
|
|
20041
|
+
data
|
|
20042
|
+
}) => {
|
|
20043
|
+
const fs = getFileSystem7();
|
|
20044
|
+
const absolutePath = fs.path.isAbsolute(envPath) ? envPath : fs.path.join(fs.env.homedir(), envPath);
|
|
20045
|
+
const release = await fs.acquireLock(absolutePath);
|
|
20046
|
+
try {
|
|
20047
|
+
await saveEnvFileAsync({ envPath: absolutePath, data, merge: true });
|
|
20048
|
+
} finally {
|
|
20049
|
+
await release().catch(() => {});
|
|
20050
|
+
}
|
|
20051
|
+
};
|
|
19995
20052
|
export {
|
|
19996
20053
|
AUTH_FLOW_ENV_VAR,
|
|
19997
20054
|
AuthContextUnavailableError,
|
|
@@ -20037,7 +20094,8 @@ export {
|
|
|
20037
20094
|
runWithAuthProfile,
|
|
20038
20095
|
saveEnvFileAsync,
|
|
20039
20096
|
setActiveAuthProfile,
|
|
20040
|
-
setAuthFileConfig
|
|
20097
|
+
setAuthFileConfig,
|
|
20098
|
+
updateEnvFileLockedAsync
|
|
20041
20099
|
};
|
|
20042
20100
|
|
|
20043
|
-
//# debugId=
|
|
20101
|
+
//# debugId=945C2814A2DFA86564756E2164756E21
|
package/dist/index.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export * from "./tokenRefresh";
|
|
|
18
18
|
export { AUTH_FLOW_ENV_VAR, type AuthFlow, type BaseCredentials, } from "./types";
|
|
19
19
|
export { DEFAULT_AUTH_FILENAME, DEFAULT_ENV_FILENAME, type EnvFileErrorCode, type EnvFileLocation, type EnvFileSource, type EnvFileUnusable, type EnvFileUnusableReason, loadEnvFileAsync, resolveEnvFileLocationAsync, resolveEnvFilePathAsync, saveEnvFileAsync, } from "./utils/envFile";
|
|
20
20
|
export { parseJWT } from "./utils/jwt";
|
|
21
|
+
export { updateEnvFileLockedAsync } from "./utils/lockedEnvFile";
|
|
21
22
|
export { isBrowser, isNode } from "./utils/platform";
|
|
22
23
|
interface AuthenticateOptions {
|
|
23
24
|
baseUrl?: string;
|
package/dist/index.js
CHANGED
|
@@ -41,7 +41,7 @@ function settlePromiseLike(thenable) {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
// src/constants.ts
|
|
44
|
-
var UIPATH_HOME_DIR = ".uipath", AUTH_FILENAME = ".auth", DEFAULT_BASE_URL = "https://cloud.uipath.com", DEFAULT_AUTH_TIMEOUT_MS, AUTH_TIMEOUT_ERROR_CODE = "EAUTHTIMEOUT", AUTH_CANCELLED_ERROR_CODE = "EAUTHCANCELLED", AUTH_RECLAIMED_ERROR_CODE = "EAUTHRECLAIMED", DEFAULT_REDIRECT_URI = "http://localhost:8104/oidc/login";
|
|
44
|
+
var UIPATH_HOME_DIR = ".uipath", AUTH_FILENAME = ".auth", AUTH_FILE_MODE = 384, AUTH_DIR_MODE = 448, DEFAULT_BASE_URL = "https://cloud.uipath.com", DEFAULT_AUTH_TIMEOUT_MS, AUTH_TIMEOUT_ERROR_CODE = "EAUTHTIMEOUT", AUTH_CANCELLED_ERROR_CODE = "EAUTHCANCELLED", AUTH_RECLAIMED_ERROR_CODE = "EAUTHRECLAIMED", DEFAULT_REDIRECT_URI = "http://localhost:8104/oidc/login";
|
|
45
45
|
var init_constants = __esm(() => {
|
|
46
46
|
DEFAULT_AUTH_TIMEOUT_MS = 5 * 60 * 1000;
|
|
47
47
|
});
|
|
@@ -733,12 +733,26 @@ class NodeFileSystem {
|
|
|
733
733
|
throw error;
|
|
734
734
|
}
|
|
735
735
|
}
|
|
736
|
-
async writeFile(filePath, data) {
|
|
736
|
+
async writeFile(filePath, data, options) {
|
|
737
737
|
const dir = path2.dirname(filePath);
|
|
738
738
|
if (dir) {
|
|
739
739
|
await fs6.mkdir(dir, { recursive: true });
|
|
740
740
|
}
|
|
741
|
-
|
|
741
|
+
if (options?.mode === undefined || process.platform === "win32") {
|
|
742
|
+
if (options?.exclusive) {
|
|
743
|
+
await fs6.writeFile(filePath, data, { flag: "wx" });
|
|
744
|
+
} else {
|
|
745
|
+
await fs6.writeFile(filePath, data);
|
|
746
|
+
}
|
|
747
|
+
return;
|
|
748
|
+
}
|
|
749
|
+
const handle = await fs6.open(filePath, options.exclusive ? "wx" : "w", options.mode);
|
|
750
|
+
try {
|
|
751
|
+
await handle.chmod(options.mode);
|
|
752
|
+
await handle.writeFile(data);
|
|
753
|
+
} finally {
|
|
754
|
+
await handle.close();
|
|
755
|
+
}
|
|
742
756
|
}
|
|
743
757
|
async appendFile(filePath, data) {
|
|
744
758
|
const dir = path2.dirname(filePath);
|
|
@@ -773,7 +787,8 @@ class NodeFileSystem {
|
|
|
773
787
|
isDirectory: () => stats.isDirectory(),
|
|
774
788
|
size: stats.size,
|
|
775
789
|
mtimeMs: stats.mtimeMs,
|
|
776
|
-
ctimeMs: stats.ctimeMs
|
|
790
|
+
ctimeMs: stats.ctimeMs,
|
|
791
|
+
mode: stats.mode
|
|
777
792
|
};
|
|
778
793
|
} catch (error) {
|
|
779
794
|
if (this.isEnoent(error))
|
|
@@ -784,8 +799,13 @@ class NodeFileSystem {
|
|
|
784
799
|
async exists(filePath) {
|
|
785
800
|
return existsSync(filePath);
|
|
786
801
|
}
|
|
787
|
-
async mkdir(dirPath) {
|
|
788
|
-
await fs6.mkdir(dirPath, { recursive: true });
|
|
802
|
+
async mkdir(dirPath, options) {
|
|
803
|
+
await fs6.mkdir(dirPath, { recursive: true, mode: options?.mode });
|
|
804
|
+
}
|
|
805
|
+
async chmod(targetPath, mode) {
|
|
806
|
+
if (process.platform === "win32")
|
|
807
|
+
return;
|
|
808
|
+
await fs6.chmod(targetPath, mode);
|
|
789
809
|
}
|
|
790
810
|
async acquireLock(lockPath) {
|
|
791
811
|
const canonicalPath = await this.canonicalizeLockTarget(lockPath);
|
|
@@ -935,7 +955,7 @@ class NodeFileSystem {
|
|
|
935
955
|
async getTempDir() {
|
|
936
956
|
return await fs6.mkdtemp(path2.join(os2.tmpdir(), "uipath-fs-"));
|
|
937
957
|
}
|
|
938
|
-
async copyDirectory(sourcePath, destPath) {
|
|
958
|
+
async copyDirectory(sourcePath, destPath, options) {
|
|
939
959
|
const sourceStats = await this.stat(sourcePath);
|
|
940
960
|
if (!sourceStats) {
|
|
941
961
|
throw new Error(`Source directory does not exist: ${sourcePath}`);
|
|
@@ -952,7 +972,9 @@ class NodeFileSystem {
|
|
|
952
972
|
if (!entryStats)
|
|
953
973
|
continue;
|
|
954
974
|
if (entryStats.isDirectory()) {
|
|
955
|
-
|
|
975
|
+
if (options?.skipDirectoryNames?.includes(entry))
|
|
976
|
+
continue;
|
|
977
|
+
await this.copyDirectory(srcEntry, destEntry, options);
|
|
956
978
|
} else if (entryStats.isFile()) {
|
|
957
979
|
const content = await this.readFile(srcEntry);
|
|
958
980
|
if (content !== null) {
|
|
@@ -2789,6 +2811,38 @@ var loadEnvFileAsync = async ({ envPath }) => {
|
|
|
2789
2811
|
}
|
|
2790
2812
|
return parseEnvContent(content);
|
|
2791
2813
|
};
|
|
2814
|
+
var findAuthHomeDir = (fs, dir) => {
|
|
2815
|
+
let current = dir;
|
|
2816
|
+
for (;; ) {
|
|
2817
|
+
if (fs.path.basename(current) === UIPATH_HOME_DIR)
|
|
2818
|
+
return current;
|
|
2819
|
+
const parent = fs.path.dirname(current);
|
|
2820
|
+
if (parent === current)
|
|
2821
|
+
return;
|
|
2822
|
+
current = parent;
|
|
2823
|
+
}
|
|
2824
|
+
};
|
|
2825
|
+
var TEMP_FILE_ATTEMPTS = 5;
|
|
2826
|
+
var isFileExists = (error) => error instanceof Error && error.code === "EEXIST";
|
|
2827
|
+
var writeTempFile = async (fs, targetPath, content) => {
|
|
2828
|
+
for (let attempt = 1;; attempt++) {
|
|
2829
|
+
const tempPath = `${targetPath}.${crypto.randomUUID()}.tmp`;
|
|
2830
|
+
try {
|
|
2831
|
+
await fs.writeFile(tempPath, content, {
|
|
2832
|
+
mode: AUTH_FILE_MODE,
|
|
2833
|
+
exclusive: true
|
|
2834
|
+
});
|
|
2835
|
+
return tempPath;
|
|
2836
|
+
} catch (error) {
|
|
2837
|
+
if (!isFileExists(error)) {
|
|
2838
|
+
await fs.rm(tempPath).catch(() => {});
|
|
2839
|
+
throw error;
|
|
2840
|
+
}
|
|
2841
|
+
if (attempt === TEMP_FILE_ATTEMPTS)
|
|
2842
|
+
throw error;
|
|
2843
|
+
}
|
|
2844
|
+
}
|
|
2845
|
+
};
|
|
2792
2846
|
var saveEnvFileAsync = async ({
|
|
2793
2847
|
envPath,
|
|
2794
2848
|
data,
|
|
@@ -2816,10 +2870,18 @@ var saveEnvFileAsync = async ({
|
|
|
2816
2870
|
`)}
|
|
2817
2871
|
`;
|
|
2818
2872
|
const dir = fs.path.dirname(absolutePath);
|
|
2819
|
-
await fs.mkdir(dir);
|
|
2820
|
-
const
|
|
2821
|
-
|
|
2822
|
-
|
|
2873
|
+
await fs.mkdir(dir, { mode: AUTH_DIR_MODE });
|
|
2874
|
+
const authHomeDir = findAuthHomeDir(fs, dir);
|
|
2875
|
+
if (authHomeDir !== undefined) {
|
|
2876
|
+
await fs.chmod?.(authHomeDir, AUTH_DIR_MODE);
|
|
2877
|
+
}
|
|
2878
|
+
const tempPath = await writeTempFile(fs, absolutePath, content);
|
|
2879
|
+
try {
|
|
2880
|
+
await fs.rename(tempPath, absolutePath);
|
|
2881
|
+
} catch (error) {
|
|
2882
|
+
await fs.rm(tempPath).catch(() => {});
|
|
2883
|
+
throw error;
|
|
2884
|
+
}
|
|
2823
2885
|
};
|
|
2824
2886
|
|
|
2825
2887
|
// src/loginStatus.ts
|
|
@@ -3978,6 +4040,21 @@ async function logoutWithDeps(options, deps = {}) {
|
|
|
3978
4040
|
async function logout(options) {
|
|
3979
4041
|
return logoutWithDeps(options);
|
|
3980
4042
|
}
|
|
4043
|
+
// src/utils/lockedEnvFile.ts
|
|
4044
|
+
init_src();
|
|
4045
|
+
var updateEnvFileLockedAsync = async ({
|
|
4046
|
+
envPath,
|
|
4047
|
+
data
|
|
4048
|
+
}) => {
|
|
4049
|
+
const fs = getFileSystem();
|
|
4050
|
+
const absolutePath = fs.path.isAbsolute(envPath) ? envPath : fs.path.join(fs.env.homedir(), envPath);
|
|
4051
|
+
const release = await fs.acquireLock(absolutePath);
|
|
4052
|
+
try {
|
|
4053
|
+
await saveEnvFileAsync({ envPath: absolutePath, data, merge: true });
|
|
4054
|
+
} finally {
|
|
4055
|
+
await release().catch(() => {});
|
|
4056
|
+
}
|
|
4057
|
+
};
|
|
3981
4058
|
|
|
3982
4059
|
// src/index.ts
|
|
3983
4060
|
var authenticate = async ({
|
|
@@ -4131,7 +4208,8 @@ export {
|
|
|
4131
4208
|
saveRefreshBreaker,
|
|
4132
4209
|
selectTenantWithDeps,
|
|
4133
4210
|
setActiveAuthProfile,
|
|
4134
|
-
setAuthFileConfig
|
|
4211
|
+
setAuthFileConfig,
|
|
4212
|
+
updateEnvFileLockedAsync
|
|
4135
4213
|
};
|
|
4136
4214
|
|
|
4137
|
-
//# debugId=
|
|
4215
|
+
//# debugId=BB829F089EE9C96A64756E2164756E21
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
interface UpdateEnvFileLockedProps {
|
|
2
|
+
/** Path to the credentials file (absolute, or relative to the home directory). */
|
|
3
|
+
envPath: string;
|
|
4
|
+
/** Keys to merge into the file; an `undefined` value drops the key. */
|
|
5
|
+
data: Record<string, string | undefined>;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Merge keys into a credentials file under the file's advisory lock — the
|
|
9
|
+
* lock token refresh in `getLoginStatusAsync` holds while it rotates the
|
|
10
|
+
* one-time-use refresh token. Without it, a merge that reads the file before
|
|
11
|
+
* the refresh saves and writes after would put the spent token back.
|
|
12
|
+
*
|
|
13
|
+
* Strict, like refresh: if the lock cannot be taken (held past the lock
|
|
14
|
+
* timeout, or the lock file cannot be created) this throws and writes
|
|
15
|
+
* nothing. An unlocked fallback would reintroduce the race exactly when
|
|
16
|
+
* another writer is active.
|
|
17
|
+
*/
|
|
18
|
+
export declare const updateEnvFileLockedAsync: ({ envPath, data, }: UpdateEnvFileLockedProps) => Promise<void>;
|
|
19
|
+
export {};
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@uipath/auth",
|
|
3
3
|
"author": "UiPath",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
5
|
-
"version": "1.
|
|
5
|
+
"version": "1.207.0-preview.305",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "https://github.com/UiPath/cli.git",
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"mihaigirleanu",
|
|
39
39
|
"vlad-uipath"
|
|
40
40
|
],
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "1600aa89255c37c1b8bc68d9882c3395c1d5bff4"
|
|
42
42
|
}
|