@uipath/integrationservice-sdk 1.1.0 → 1.2.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/dist/index.js CHANGED
@@ -706,6 +706,7 @@ var init_open = __esm(() => {
706
706
  });
707
707
 
708
708
  // ../filesystem/src/node.ts
709
+ import { randomUUID } from "node:crypto";
709
710
  import { existsSync } from "node:fs";
710
711
  import * as fs6 from "node:fs/promises";
711
712
  import * as os2 from "node:os";
@@ -787,6 +788,90 @@ class NodeFileSystem {
787
788
  async mkdir(dirPath) {
788
789
  await fs6.mkdir(dirPath, { recursive: true });
789
790
  }
791
+ async acquireLock(lockPath) {
792
+ const canonicalPath = await this.canonicalizeLockTarget(lockPath);
793
+ const lockFile = `${canonicalPath}.lock`;
794
+ const ownerId = randomUUID();
795
+ const start = Date.now();
796
+ while (true) {
797
+ try {
798
+ await fs6.writeFile(lockFile, ownerId, { flag: "wx" });
799
+ return this.createLockRelease(lockFile, ownerId);
800
+ } catch (error) {
801
+ if (!this.hasErrnoCode(error, "EEXIST")) {
802
+ throw error;
803
+ }
804
+ const stats = await fs6.stat(lockFile).catch(() => null);
805
+ if (stats && Date.now() - stats.mtimeMs > LOCK_STALE_MS) {
806
+ const reclaimed = await fs6.rm(lockFile, { force: true }).then(() => true).catch(() => false);
807
+ if (reclaimed)
808
+ continue;
809
+ }
810
+ if (Date.now() - start > LOCK_MAX_WAIT_MS) {
811
+ throw new Error(`ELOCKED: timed out waiting for lock on ${canonicalPath}`);
812
+ }
813
+ await new Promise((resolve2) => setTimeout(resolve2, LOCK_RETRY_MIN_MS + Math.random() * LOCK_RETRY_JITTER_MS));
814
+ }
815
+ }
816
+ }
817
+ async canonicalizeLockTarget(lockPath) {
818
+ const absolute = path2.resolve(lockPath);
819
+ const fullReal = await fs6.realpath(absolute).catch(() => null);
820
+ if (fullReal)
821
+ return fullReal;
822
+ const parent = path2.dirname(absolute);
823
+ const base = path2.basename(absolute);
824
+ const canonicalParent = await fs6.realpath(parent).catch(() => parent);
825
+ return path2.join(canonicalParent, base);
826
+ }
827
+ createLockRelease(lockFile, ownerId) {
828
+ const heartbeatStart = Date.now();
829
+ let heartbeatTimer;
830
+ let stopped = false;
831
+ const stopHeartbeat = () => {
832
+ stopped = true;
833
+ if (heartbeatTimer)
834
+ clearTimeout(heartbeatTimer);
835
+ };
836
+ const scheduleNextHeartbeat = () => {
837
+ if (stopped)
838
+ return;
839
+ if (Date.now() - heartbeatStart >= LOCK_MAX_HOLD_MS) {
840
+ stopped = true;
841
+ return;
842
+ }
843
+ heartbeatTimer = setTimeout(() => {
844
+ runHeartbeat();
845
+ }, LOCK_HEARTBEAT_MS);
846
+ heartbeatTimer.unref?.();
847
+ };
848
+ const runHeartbeat = async () => {
849
+ if (stopped)
850
+ return;
851
+ const current = await fs6.readFile(lockFile, "utf-8").catch(() => null);
852
+ if (stopped)
853
+ return;
854
+ if (current !== ownerId) {
855
+ stopped = true;
856
+ return;
857
+ }
858
+ const now = Date.now() / 1000;
859
+ await fs6.utimes(lockFile, now, now).catch(() => {});
860
+ scheduleNextHeartbeat();
861
+ };
862
+ scheduleNextHeartbeat();
863
+ let released = false;
864
+ return async () => {
865
+ if (released)
866
+ return;
867
+ released = true;
868
+ stopHeartbeat();
869
+ const current = await fs6.readFile(lockFile, "utf-8").catch(() => null);
870
+ if (current === ownerId) {
871
+ await fs6.rm(lockFile, { force: true });
872
+ }
873
+ };
874
+ }
790
875
  async rm(filePath) {
791
876
  await fs6.rm(filePath, { recursive: true, force: true });
792
877
  }
@@ -832,9 +917,13 @@ class NodeFileSystem {
832
917
  }
833
918
  }
834
919
  isEnoent(error) {
835
- return typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT";
920
+ return this.hasErrnoCode(error, "ENOENT");
921
+ }
922
+ hasErrnoCode(error, code) {
923
+ return typeof error === "object" && error !== null && "code" in error && error.code === code;
836
924
  }
837
925
  }
926
+ var LOCK_HEARTBEAT_MS = 5000, LOCK_STALE_MS = 15000, LOCK_MAX_WAIT_MS = 20000, LOCK_MAX_HOLD_MS = 60000, LOCK_RETRY_MIN_MS = 100, LOCK_RETRY_JITTER_MS = 200;
838
927
  var init_node = __esm(() => {
839
928
  init_open();
840
929
  });
@@ -848,7 +937,7 @@ var init_src = __esm(() => {
848
937
 
849
938
  // ../../node_modules/@uipath/coreipc/index.js
850
939
  var require_coreipc = __commonJS((exports, module) => {
851
- var __dirname = "/Users/alexandru.oltean/github/cli/node_modules/@uipath/coreipc";
940
+ var __dirname = "/home/runner/work/cli/cli/node_modules/@uipath/coreipc";
852
941
  /*! For license information please see index.js.LICENSE.txt */
853
942
  (function(e, t) {
854
943
  typeof exports == "object" && typeof module == "object" ? module.exports = t() : typeof define == "function" && define.amd ? define([], t) : typeof exports == "object" ? exports.ipc = t() : e.ipc = t();
@@ -19040,6 +19129,140 @@ var require_dist = __commonJS((exports) => {
19040
19129
  exports.RobotProxyConstructor = RobotProxyConstructor;
19041
19130
  __exportStar(require_agent(), exports);
19042
19131
  });
19132
+ // ../auth/src/server.ts
19133
+ var init_server = __esm(() => {
19134
+ init_constants();
19135
+ });
19136
+
19137
+ // ../common/src/singleton.ts
19138
+ var PREFIX = "@uipath/common/";
19139
+ var _g = globalThis;
19140
+ function singleton(ctorOrName) {
19141
+ const name = typeof ctorOrName === "string" ? ctorOrName : ctorOrName.name;
19142
+ const key = Symbol.for(PREFIX + name);
19143
+ return {
19144
+ get(fallback) {
19145
+ return _g[key] ?? fallback;
19146
+ },
19147
+ set(value) {
19148
+ _g[key] = value;
19149
+ },
19150
+ clear() {
19151
+ delete _g[key];
19152
+ },
19153
+ getOrInit(factory, guard) {
19154
+ const existing = _g[key];
19155
+ if (existing != null && typeof existing === "object") {
19156
+ if (!guard || guard(existing)) {
19157
+ return existing;
19158
+ }
19159
+ }
19160
+ const instance = factory();
19161
+ _g[key] = instance;
19162
+ return instance;
19163
+ }
19164
+ };
19165
+ }
19166
+
19167
+ // ../common/src/sdk-user-agent.ts
19168
+ var USER_AGENT_HEADER = "User-Agent";
19169
+ var sdkUserAgentHostToken = singleton("SdkUserAgentHostToken");
19170
+ function userAgentPatchKey(userAgent) {
19171
+ return Symbol.for(`@uipath/common/sdk-user-agent/${userAgent}`);
19172
+ }
19173
+ function splitUserAgentTokens(value) {
19174
+ return value?.trim().split(/\s+/).filter(Boolean) ?? [];
19175
+ }
19176
+ function appendUserAgentToken(value, userAgent) {
19177
+ const tokens = splitUserAgentTokens(value);
19178
+ const seen = new Set(tokens);
19179
+ for (const token of splitUserAgentTokens(userAgent)) {
19180
+ if (!seen.has(token)) {
19181
+ tokens.push(token);
19182
+ seen.add(token);
19183
+ }
19184
+ }
19185
+ return tokens.join(" ");
19186
+ }
19187
+ function getEffectiveUserAgent(userAgent) {
19188
+ return appendUserAgentToken(sdkUserAgentHostToken.get(), userAgent);
19189
+ }
19190
+ function isHeadersLike(headers) {
19191
+ return typeof headers === "object" && headers !== null && "get" in headers && typeof headers.get === "function" && "set" in headers && typeof headers.set === "function";
19192
+ }
19193
+ function getSdkUserAgentToken(pkg) {
19194
+ const packageName = pkg.name.replace(/^@uipath\//, "");
19195
+ return getEffectiveUserAgent(`${packageName}/${pkg.version}`);
19196
+ }
19197
+ function addSdkUserAgentHeader(headers, userAgent) {
19198
+ const result = { ...headers ?? {} };
19199
+ const effectiveUserAgent = getEffectiveUserAgent(userAgent);
19200
+ const headerName = Object.keys(result).find((key) => key.toLowerCase() === USER_AGENT_HEADER.toLowerCase());
19201
+ if (headerName) {
19202
+ result[headerName] = appendUserAgentToken(result[headerName], effectiveUserAgent);
19203
+ } else {
19204
+ result[USER_AGENT_HEADER] = effectiveUserAgent;
19205
+ }
19206
+ return result;
19207
+ }
19208
+ function withSdkUserAgentHeader(headers, userAgent) {
19209
+ const effectiveUserAgent = getEffectiveUserAgent(userAgent);
19210
+ if (isHeadersLike(headers)) {
19211
+ headers.set(USER_AGENT_HEADER, appendUserAgentToken(headers.get(USER_AGENT_HEADER), effectiveUserAgent));
19212
+ return headers;
19213
+ }
19214
+ if (Array.isArray(headers)) {
19215
+ const result = headers.map((entry) => {
19216
+ const [key, value] = entry;
19217
+ return [key, value];
19218
+ });
19219
+ const headerIndex = result.findIndex(([key]) => key.toLowerCase() === USER_AGENT_HEADER.toLowerCase());
19220
+ if (headerIndex >= 0) {
19221
+ const [key, value] = result[headerIndex];
19222
+ result[headerIndex] = [
19223
+ key,
19224
+ appendUserAgentToken(value, effectiveUserAgent)
19225
+ ];
19226
+ } else {
19227
+ result.push([USER_AGENT_HEADER, effectiveUserAgent]);
19228
+ }
19229
+ return result;
19230
+ }
19231
+ return addSdkUserAgentHeader(typeof headers === "object" && headers !== null ? { ...headers } : {}, effectiveUserAgent);
19232
+ }
19233
+ function withUserAgentInitOverride(initOverrides, userAgent) {
19234
+ return async (requestContext) => {
19235
+ const initWithUserAgent = {
19236
+ ...requestContext.init,
19237
+ headers: withSdkUserAgentHeader(requestContext.init.headers, userAgent)
19238
+ };
19239
+ const override = typeof initOverrides === "function" ? await initOverrides({
19240
+ ...requestContext,
19241
+ init: initWithUserAgent
19242
+ }) : initOverrides;
19243
+ return {
19244
+ ...override ?? {},
19245
+ headers: withSdkUserAgentHeader(override?.headers ?? initWithUserAgent.headers, userAgent)
19246
+ };
19247
+ };
19248
+ }
19249
+ function installSdkUserAgentHeader(BaseApiClass, userAgent) {
19250
+ const prototype = BaseApiClass.prototype;
19251
+ const patchKey = userAgentPatchKey(userAgent);
19252
+ if (prototype[patchKey]) {
19253
+ return;
19254
+ }
19255
+ if (typeof prototype.request !== "function") {
19256
+ throw new Error("Generated BaseAPI request function not found.");
19257
+ }
19258
+ const originalRequest = prototype.request;
19259
+ prototype.request = function requestWithUserAgent(context, initOverrides) {
19260
+ return originalRequest.call(this, context, withUserAgentInitOverride(initOverrides, userAgent));
19261
+ };
19262
+ Object.defineProperty(prototype, patchKey, {
19263
+ value: true
19264
+ });
19265
+ }
19043
19266
 
19044
19267
  // generated/connections/src/runtime.ts
19045
19268
  var BASE_PATH = "https://alpha.uipath.com/entity/Azure/connections_".replace(/\/+$/, "");
@@ -19336,6 +19559,327 @@ class TextApiResponse {
19336
19559
  return await this.raw.text();
19337
19560
  }
19338
19561
  }
19562
+
19563
+ // generated/elements/src/runtime.ts
19564
+ var BASE_PATH2 = "http://localhost:8086/v3/element".replace(/\/+$/, "");
19565
+
19566
+ class Configuration2 {
19567
+ configuration;
19568
+ constructor(configuration = {}) {
19569
+ this.configuration = configuration;
19570
+ }
19571
+ set config(configuration) {
19572
+ this.configuration = configuration;
19573
+ }
19574
+ get basePath() {
19575
+ return this.configuration.basePath != null ? this.configuration.basePath : BASE_PATH2;
19576
+ }
19577
+ get fetchApi() {
19578
+ return this.configuration.fetchApi;
19579
+ }
19580
+ get middleware() {
19581
+ return this.configuration.middleware || [];
19582
+ }
19583
+ get queryParamsStringify() {
19584
+ return this.configuration.queryParamsStringify || querystring2;
19585
+ }
19586
+ get username() {
19587
+ return this.configuration.username;
19588
+ }
19589
+ get password() {
19590
+ return this.configuration.password;
19591
+ }
19592
+ get apiKey() {
19593
+ const apiKey = this.configuration.apiKey;
19594
+ if (apiKey) {
19595
+ return typeof apiKey === "function" ? apiKey : () => apiKey;
19596
+ }
19597
+ return;
19598
+ }
19599
+ get accessToken() {
19600
+ const accessToken = this.configuration.accessToken;
19601
+ if (accessToken) {
19602
+ return typeof accessToken === "function" ? accessToken : async () => accessToken;
19603
+ }
19604
+ return;
19605
+ }
19606
+ get headers() {
19607
+ return this.configuration.headers;
19608
+ }
19609
+ get credentials() {
19610
+ return this.configuration.credentials;
19611
+ }
19612
+ }
19613
+ var DefaultConfig2 = new Configuration2;
19614
+
19615
+ class BaseAPI2 {
19616
+ configuration;
19617
+ static jsonRegex = new RegExp("^(:?application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(:?;.*)?$", "i");
19618
+ middleware;
19619
+ constructor(configuration = DefaultConfig2) {
19620
+ this.configuration = configuration;
19621
+ this.middleware = configuration.middleware;
19622
+ }
19623
+ withMiddleware(...middlewares) {
19624
+ const next = this.clone();
19625
+ next.middleware = next.middleware.concat(...middlewares);
19626
+ return next;
19627
+ }
19628
+ withPreMiddleware(...preMiddlewares) {
19629
+ const middlewares = preMiddlewares.map((pre) => ({ pre }));
19630
+ return this.withMiddleware(...middlewares);
19631
+ }
19632
+ withPostMiddleware(...postMiddlewares) {
19633
+ const middlewares = postMiddlewares.map((post) => ({ post }));
19634
+ return this.withMiddleware(...middlewares);
19635
+ }
19636
+ isJsonMime(mime) {
19637
+ if (!mime) {
19638
+ return false;
19639
+ }
19640
+ return BaseAPI2.jsonRegex.test(mime);
19641
+ }
19642
+ async request(context, initOverrides) {
19643
+ const { url, init } = await this.createFetchParams(context, initOverrides);
19644
+ const response = await this.fetchApi(url, init);
19645
+ if (response && (response.status >= 200 && response.status < 300)) {
19646
+ return response;
19647
+ }
19648
+ throw new ResponseError2(response, "Response returned an error code");
19649
+ }
19650
+ async createFetchParams(context, initOverrides) {
19651
+ let url = this.configuration.basePath + context.path;
19652
+ if (context.query !== undefined && Object.keys(context.query).length !== 0) {
19653
+ url += "?" + this.configuration.queryParamsStringify(context.query);
19654
+ }
19655
+ const headers = Object.assign({}, this.configuration.headers, context.headers);
19656
+ Object.keys(headers).forEach((key) => headers[key] === undefined ? delete headers[key] : {});
19657
+ const initOverrideFn = typeof initOverrides === "function" ? initOverrides : async () => initOverrides;
19658
+ const initParams = {
19659
+ method: context.method,
19660
+ headers,
19661
+ body: context.body,
19662
+ credentials: this.configuration.credentials
19663
+ };
19664
+ const overriddenInit = {
19665
+ ...initParams,
19666
+ ...await initOverrideFn({
19667
+ init: initParams,
19668
+ context
19669
+ })
19670
+ };
19671
+ let body;
19672
+ if (isFormData2(overriddenInit.body) || overriddenInit.body instanceof URLSearchParams || isBlob2(overriddenInit.body)) {
19673
+ body = overriddenInit.body;
19674
+ } else if (this.isJsonMime(headers["Content-Type"])) {
19675
+ body = JSON.stringify(overriddenInit.body);
19676
+ } else {
19677
+ body = overriddenInit.body;
19678
+ }
19679
+ const init = {
19680
+ ...overriddenInit,
19681
+ body
19682
+ };
19683
+ return { url, init };
19684
+ }
19685
+ fetchApi = async (url, init) => {
19686
+ let fetchParams = { url, init };
19687
+ for (const middleware of this.middleware) {
19688
+ if (middleware.pre) {
19689
+ fetchParams = await middleware.pre({
19690
+ fetch: this.fetchApi,
19691
+ ...fetchParams
19692
+ }) || fetchParams;
19693
+ }
19694
+ }
19695
+ let response = undefined;
19696
+ try {
19697
+ response = await (this.configuration.fetchApi || fetch)(fetchParams.url, fetchParams.init);
19698
+ } catch (e) {
19699
+ for (const middleware of this.middleware) {
19700
+ if (middleware.onError) {
19701
+ response = await middleware.onError({
19702
+ fetch: this.fetchApi,
19703
+ url: fetchParams.url,
19704
+ init: fetchParams.init,
19705
+ error: e,
19706
+ response: response ? response.clone() : undefined
19707
+ }) || response;
19708
+ }
19709
+ }
19710
+ if (response === undefined) {
19711
+ if (e instanceof Error) {
19712
+ throw new FetchError2(e, "The request failed and the interceptors did not return an alternative response");
19713
+ } else {
19714
+ throw e;
19715
+ }
19716
+ }
19717
+ }
19718
+ for (const middleware of this.middleware) {
19719
+ if (middleware.post) {
19720
+ response = await middleware.post({
19721
+ fetch: this.fetchApi,
19722
+ url: fetchParams.url,
19723
+ init: fetchParams.init,
19724
+ response: response.clone()
19725
+ }) || response;
19726
+ }
19727
+ }
19728
+ return response;
19729
+ };
19730
+ clone() {
19731
+ const constructor = this.constructor;
19732
+ const next = new constructor(this.configuration);
19733
+ next.middleware = this.middleware.slice();
19734
+ return next;
19735
+ }
19736
+ }
19737
+ function isBlob2(value) {
19738
+ return typeof Blob !== "undefined" && value instanceof Blob;
19739
+ }
19740
+ function isFormData2(value) {
19741
+ return typeof FormData !== "undefined" && value instanceof FormData;
19742
+ }
19743
+
19744
+ class ResponseError2 extends Error {
19745
+ response;
19746
+ name = "ResponseError";
19747
+ constructor(response, msg) {
19748
+ super(msg);
19749
+ this.response = response;
19750
+ }
19751
+ }
19752
+
19753
+ class FetchError2 extends Error {
19754
+ cause;
19755
+ name = "FetchError";
19756
+ constructor(cause, msg) {
19757
+ super(msg);
19758
+ this.cause = cause;
19759
+ }
19760
+ }
19761
+
19762
+ class RequiredError2 extends Error {
19763
+ field;
19764
+ name = "RequiredError";
19765
+ constructor(field, msg) {
19766
+ super(msg);
19767
+ this.field = field;
19768
+ }
19769
+ }
19770
+ function querystring2(params, prefix = "") {
19771
+ return Object.keys(params).map((key) => querystringSingleKey2(key, params[key], prefix)).filter((part) => part.length > 0).join("&");
19772
+ }
19773
+ function querystringSingleKey2(key, value, keyPrefix = "") {
19774
+ const fullKey = keyPrefix + (keyPrefix.length ? `[${key}]` : key);
19775
+ if (value instanceof Array) {
19776
+ const multiValue = value.map((singleValue) => encodeURIComponent(String(singleValue))).join(`&${encodeURIComponent(fullKey)}=`);
19777
+ return `${encodeURIComponent(fullKey)}=${multiValue}`;
19778
+ }
19779
+ if (value instanceof Set) {
19780
+ const valueAsArray = Array.from(value);
19781
+ return querystringSingleKey2(key, valueAsArray, keyPrefix);
19782
+ }
19783
+ if (value instanceof Date) {
19784
+ return `${encodeURIComponent(fullKey)}=${encodeURIComponent(value.toISOString())}`;
19785
+ }
19786
+ if (value instanceof Object) {
19787
+ return querystring2(value, fullKey);
19788
+ }
19789
+ return `${encodeURIComponent(fullKey)}=${encodeURIComponent(String(value))}`;
19790
+ }
19791
+ class JSONApiResponse2 {
19792
+ raw;
19793
+ transformer;
19794
+ constructor(raw, transformer = (jsonValue) => jsonValue) {
19795
+ this.raw = raw;
19796
+ this.transformer = transformer;
19797
+ }
19798
+ async value() {
19799
+ return this.transformer(await this.raw.json());
19800
+ }
19801
+ }
19802
+
19803
+ class VoidApiResponse2 {
19804
+ raw;
19805
+ constructor(raw) {
19806
+ this.raw = raw;
19807
+ }
19808
+ async value() {
19809
+ return;
19810
+ }
19811
+ }
19812
+
19813
+ class BlobApiResponse2 {
19814
+ raw;
19815
+ constructor(raw) {
19816
+ this.raw = raw;
19817
+ }
19818
+ async value() {
19819
+ return await this.raw.blob();
19820
+ }
19821
+ }
19822
+
19823
+ class TextApiResponse2 {
19824
+ raw;
19825
+ constructor(raw) {
19826
+ this.raw = raw;
19827
+ }
19828
+ async value() {
19829
+ return await this.raw.text();
19830
+ }
19831
+ }
19832
+ // package.json
19833
+ var package_default = {
19834
+ name: "@uipath/integrationservice-sdk",
19835
+ license: "MIT",
19836
+ version: "1.2.0",
19837
+ repository: {
19838
+ type: "git",
19839
+ url: "https://github.com/UiPath/cli.git",
19840
+ directory: "packages/integrationservice-sdk"
19841
+ },
19842
+ publishConfig: {
19843
+ registry: "https://npm.pkg.github.com/@uipath"
19844
+ },
19845
+ keywords: [
19846
+ "uipath",
19847
+ "integrationservice",
19848
+ "sdk"
19849
+ ],
19850
+ type: "module",
19851
+ main: "./dist/index.js",
19852
+ types: "./dist/src/index.d.ts",
19853
+ exports: {
19854
+ ".": {
19855
+ types: "./dist/src/index.d.ts",
19856
+ default: "./dist/index.js"
19857
+ }
19858
+ },
19859
+ files: [
19860
+ "dist"
19861
+ ],
19862
+ scripts: {
19863
+ build: "bun build ./src/index.ts --outdir dist --format esm --target node && tsc -p tsconfig.build.json --noCheck",
19864
+ generate: "bun run src/scripts/generate-sdk.ts",
19865
+ lint: "biome check .",
19866
+ test: "vitest run",
19867
+ "test:coverage": "vitest run --coverage"
19868
+ },
19869
+ devDependencies: {
19870
+ "@uipath/auth": "workspace:*",
19871
+ "@uipath/common": "workspace:*",
19872
+ "@openapitools/openapi-generator-cli": "^2.31.1",
19873
+ "@types/node": "^25.5.2",
19874
+ typescript: "^6.0.2",
19875
+ uuid: "^14.0.0"
19876
+ }
19877
+ };
19878
+
19879
+ // src/user-agent.ts
19880
+ var SDK_USER_AGENT = getSdkUserAgentToken(package_default);
19881
+ installSdkUserAgentHeader(BaseAPI, SDK_USER_AGENT);
19882
+ installSdkUserAgentHeader(BaseAPI2, SDK_USER_AGENT);
19339
19883
  // generated/connections/src/models/AccessTokenResponse.ts
19340
19884
  function instanceOfAccessTokenResponse(value) {
19341
19885
  return true;
@@ -22011,276 +22555,6 @@ class SessionsApi extends BaseAPI {
22011
22555
  return await response.value();
22012
22556
  }
22013
22557
  }
22014
- // generated/elements/src/runtime.ts
22015
- var BASE_PATH2 = "http://localhost:8086/v3/element".replace(/\/+$/, "");
22016
-
22017
- class Configuration2 {
22018
- configuration;
22019
- constructor(configuration = {}) {
22020
- this.configuration = configuration;
22021
- }
22022
- set config(configuration) {
22023
- this.configuration = configuration;
22024
- }
22025
- get basePath() {
22026
- return this.configuration.basePath != null ? this.configuration.basePath : BASE_PATH2;
22027
- }
22028
- get fetchApi() {
22029
- return this.configuration.fetchApi;
22030
- }
22031
- get middleware() {
22032
- return this.configuration.middleware || [];
22033
- }
22034
- get queryParamsStringify() {
22035
- return this.configuration.queryParamsStringify || querystring2;
22036
- }
22037
- get username() {
22038
- return this.configuration.username;
22039
- }
22040
- get password() {
22041
- return this.configuration.password;
22042
- }
22043
- get apiKey() {
22044
- const apiKey = this.configuration.apiKey;
22045
- if (apiKey) {
22046
- return typeof apiKey === "function" ? apiKey : () => apiKey;
22047
- }
22048
- return;
22049
- }
22050
- get accessToken() {
22051
- const accessToken = this.configuration.accessToken;
22052
- if (accessToken) {
22053
- return typeof accessToken === "function" ? accessToken : async () => accessToken;
22054
- }
22055
- return;
22056
- }
22057
- get headers() {
22058
- return this.configuration.headers;
22059
- }
22060
- get credentials() {
22061
- return this.configuration.credentials;
22062
- }
22063
- }
22064
- var DefaultConfig2 = new Configuration2;
22065
-
22066
- class BaseAPI2 {
22067
- configuration;
22068
- static jsonRegex = new RegExp("^(:?application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(:?;.*)?$", "i");
22069
- middleware;
22070
- constructor(configuration = DefaultConfig2) {
22071
- this.configuration = configuration;
22072
- this.middleware = configuration.middleware;
22073
- }
22074
- withMiddleware(...middlewares) {
22075
- const next = this.clone();
22076
- next.middleware = next.middleware.concat(...middlewares);
22077
- return next;
22078
- }
22079
- withPreMiddleware(...preMiddlewares) {
22080
- const middlewares = preMiddlewares.map((pre) => ({ pre }));
22081
- return this.withMiddleware(...middlewares);
22082
- }
22083
- withPostMiddleware(...postMiddlewares) {
22084
- const middlewares = postMiddlewares.map((post) => ({ post }));
22085
- return this.withMiddleware(...middlewares);
22086
- }
22087
- isJsonMime(mime) {
22088
- if (!mime) {
22089
- return false;
22090
- }
22091
- return BaseAPI2.jsonRegex.test(mime);
22092
- }
22093
- async request(context, initOverrides) {
22094
- const { url, init } = await this.createFetchParams(context, initOverrides);
22095
- const response = await this.fetchApi(url, init);
22096
- if (response && (response.status >= 200 && response.status < 300)) {
22097
- return response;
22098
- }
22099
- throw new ResponseError2(response, "Response returned an error code");
22100
- }
22101
- async createFetchParams(context, initOverrides) {
22102
- let url = this.configuration.basePath + context.path;
22103
- if (context.query !== undefined && Object.keys(context.query).length !== 0) {
22104
- url += "?" + this.configuration.queryParamsStringify(context.query);
22105
- }
22106
- const headers = Object.assign({}, this.configuration.headers, context.headers);
22107
- Object.keys(headers).forEach((key) => headers[key] === undefined ? delete headers[key] : {});
22108
- const initOverrideFn = typeof initOverrides === "function" ? initOverrides : async () => initOverrides;
22109
- const initParams = {
22110
- method: context.method,
22111
- headers,
22112
- body: context.body,
22113
- credentials: this.configuration.credentials
22114
- };
22115
- const overriddenInit = {
22116
- ...initParams,
22117
- ...await initOverrideFn({
22118
- init: initParams,
22119
- context
22120
- })
22121
- };
22122
- let body;
22123
- if (isFormData2(overriddenInit.body) || overriddenInit.body instanceof URLSearchParams || isBlob2(overriddenInit.body)) {
22124
- body = overriddenInit.body;
22125
- } else if (this.isJsonMime(headers["Content-Type"])) {
22126
- body = JSON.stringify(overriddenInit.body);
22127
- } else {
22128
- body = overriddenInit.body;
22129
- }
22130
- const init = {
22131
- ...overriddenInit,
22132
- body
22133
- };
22134
- return { url, init };
22135
- }
22136
- fetchApi = async (url, init) => {
22137
- let fetchParams = { url, init };
22138
- for (const middleware of this.middleware) {
22139
- if (middleware.pre) {
22140
- fetchParams = await middleware.pre({
22141
- fetch: this.fetchApi,
22142
- ...fetchParams
22143
- }) || fetchParams;
22144
- }
22145
- }
22146
- let response = undefined;
22147
- try {
22148
- response = await (this.configuration.fetchApi || fetch)(fetchParams.url, fetchParams.init);
22149
- } catch (e) {
22150
- for (const middleware of this.middleware) {
22151
- if (middleware.onError) {
22152
- response = await middleware.onError({
22153
- fetch: this.fetchApi,
22154
- url: fetchParams.url,
22155
- init: fetchParams.init,
22156
- error: e,
22157
- response: response ? response.clone() : undefined
22158
- }) || response;
22159
- }
22160
- }
22161
- if (response === undefined) {
22162
- if (e instanceof Error) {
22163
- throw new FetchError2(e, "The request failed and the interceptors did not return an alternative response");
22164
- } else {
22165
- throw e;
22166
- }
22167
- }
22168
- }
22169
- for (const middleware of this.middleware) {
22170
- if (middleware.post) {
22171
- response = await middleware.post({
22172
- fetch: this.fetchApi,
22173
- url: fetchParams.url,
22174
- init: fetchParams.init,
22175
- response: response.clone()
22176
- }) || response;
22177
- }
22178
- }
22179
- return response;
22180
- };
22181
- clone() {
22182
- const constructor = this.constructor;
22183
- const next = new constructor(this.configuration);
22184
- next.middleware = this.middleware.slice();
22185
- return next;
22186
- }
22187
- }
22188
- function isBlob2(value) {
22189
- return typeof Blob !== "undefined" && value instanceof Blob;
22190
- }
22191
- function isFormData2(value) {
22192
- return typeof FormData !== "undefined" && value instanceof FormData;
22193
- }
22194
-
22195
- class ResponseError2 extends Error {
22196
- response;
22197
- name = "ResponseError";
22198
- constructor(response, msg) {
22199
- super(msg);
22200
- this.response = response;
22201
- }
22202
- }
22203
-
22204
- class FetchError2 extends Error {
22205
- cause;
22206
- name = "FetchError";
22207
- constructor(cause, msg) {
22208
- super(msg);
22209
- this.cause = cause;
22210
- }
22211
- }
22212
-
22213
- class RequiredError2 extends Error {
22214
- field;
22215
- name = "RequiredError";
22216
- constructor(field, msg) {
22217
- super(msg);
22218
- this.field = field;
22219
- }
22220
- }
22221
- function querystring2(params, prefix = "") {
22222
- return Object.keys(params).map((key) => querystringSingleKey2(key, params[key], prefix)).filter((part) => part.length > 0).join("&");
22223
- }
22224
- function querystringSingleKey2(key, value, keyPrefix = "") {
22225
- const fullKey = keyPrefix + (keyPrefix.length ? `[${key}]` : key);
22226
- if (value instanceof Array) {
22227
- const multiValue = value.map((singleValue) => encodeURIComponent(String(singleValue))).join(`&${encodeURIComponent(fullKey)}=`);
22228
- return `${encodeURIComponent(fullKey)}=${multiValue}`;
22229
- }
22230
- if (value instanceof Set) {
22231
- const valueAsArray = Array.from(value);
22232
- return querystringSingleKey2(key, valueAsArray, keyPrefix);
22233
- }
22234
- if (value instanceof Date) {
22235
- return `${encodeURIComponent(fullKey)}=${encodeURIComponent(value.toISOString())}`;
22236
- }
22237
- if (value instanceof Object) {
22238
- return querystring2(value, fullKey);
22239
- }
22240
- return `${encodeURIComponent(fullKey)}=${encodeURIComponent(String(value))}`;
22241
- }
22242
- class JSONApiResponse2 {
22243
- raw;
22244
- transformer;
22245
- constructor(raw, transformer = (jsonValue) => jsonValue) {
22246
- this.raw = raw;
22247
- this.transformer = transformer;
22248
- }
22249
- async value() {
22250
- return this.transformer(await this.raw.json());
22251
- }
22252
- }
22253
-
22254
- class VoidApiResponse2 {
22255
- raw;
22256
- constructor(raw) {
22257
- this.raw = raw;
22258
- }
22259
- async value() {
22260
- return;
22261
- }
22262
- }
22263
-
22264
- class BlobApiResponse2 {
22265
- raw;
22266
- constructor(raw) {
22267
- this.raw = raw;
22268
- }
22269
- async value() {
22270
- return await this.raw.blob();
22271
- }
22272
- }
22273
-
22274
- class TextApiResponse2 {
22275
- raw;
22276
- constructor(raw) {
22277
- this.raw = raw;
22278
- }
22279
- async value() {
22280
- return await this.raw.text();
22281
- }
22282
- }
22283
-
22284
22558
  // generated/elements/src/models/UnknownFieldSet.ts
22285
22559
  function instanceOfUnknownFieldSet(value) {
22286
22560
  return true;
@@ -38559,32 +38833,7 @@ class InvalidBaseUrlError extends Error {
38559
38833
  this.name = "InvalidBaseUrlError";
38560
38834
  }
38561
38835
  }
38562
- var DEFAULT_SCOPES = [
38563
- "offline_access",
38564
- "ProcessMining",
38565
- "OrchestratorApiUserAccess",
38566
- "StudioWebBackend",
38567
- "IdentityServerApi",
38568
- "ConnectionService",
38569
- "DataService",
38570
- "DataServiceApiUserAccess",
38571
- "DocumentUnderstanding",
38572
- "EnterpriseContextService",
38573
- "Directory",
38574
- "JamJamApi",
38575
- "LLMGateway",
38576
- "LLMOps",
38577
- "OMS",
38578
- "RCS.FolderAuthorization",
38579
- "RCS.TagsManagement",
38580
- "TestmanagerApiUserAccess",
38581
- "AutomationSolutions",
38582
- "StudioWebTypeCacheService",
38583
- "Docs.GPT.Search",
38584
- "Insights",
38585
- "ReferenceToken",
38586
- "Audit.Read"
38587
- ];
38836
+ var DEFAULT_SCOPES = ["openid", "profile", "offline_access"];
38588
38837
  var normalizeAndValidateBaseUrl = (rawUrl) => {
38589
38838
  let baseUrl = rawUrl;
38590
38839
  if (baseUrl.endsWith("/identity_/")) {
@@ -38634,7 +38883,8 @@ var resolveConfigAsync = async ({
38634
38883
  if (!clientSecret && fileAuth.clientSecret) {
38635
38884
  clientSecret = fileAuth.clientSecret;
38636
38885
  }
38637
- const scopes = customScopes && customScopes.length > 0 ? customScopes : fileAuth.scopes && fileAuth.scopes.length > 0 ? fileAuth.scopes : DEFAULT_SCOPES;
38886
+ const isExternalAppAuth = clientId !== DEFAULT_CLIENT_ID && Boolean(clientSecret);
38887
+ const scopes = customScopes && customScopes.length > 0 ? customScopes : fileAuth.scopes && fileAuth.scopes.length > 0 ? fileAuth.scopes : isExternalAppAuth ? [] : DEFAULT_SCOPES;
38638
38888
  return {
38639
38889
  clientId,
38640
38890
  clientSecret,
@@ -39134,6 +39384,129 @@ function normalizeTokenRefreshFailure() {
39134
39384
  function normalizeTokenRefreshUnavailableFailure() {
39135
39385
  return "token refresh failed before authentication completed";
39136
39386
  }
39387
+ function errorMessage(error) {
39388
+ return error instanceof Error ? error.message : String(error);
39389
+ }
39390
+ function computeExpirationThreshold(ensureTokenValidityMinutes) {
39391
+ return new Date(Date.now() + (ensureTokenValidityMinutes ?? 0) * 60 * 1000);
39392
+ }
39393
+ async function runRefreshLocked(inputs) {
39394
+ const {
39395
+ absolutePath,
39396
+ refreshToken: callerRefreshToken,
39397
+ customAuthority,
39398
+ ensureTokenValidityMinutes,
39399
+ loadEnvFile,
39400
+ saveEnvFile,
39401
+ refreshFn,
39402
+ resolveConfig
39403
+ } = inputs;
39404
+ const expirationThreshold = computeExpirationThreshold(ensureTokenValidityMinutes);
39405
+ let fresh;
39406
+ try {
39407
+ fresh = await loadEnvFile({ envPath: absolutePath });
39408
+ } catch (error) {
39409
+ return {
39410
+ kind: "fail",
39411
+ status: {
39412
+ loginStatus: "Refresh Failed",
39413
+ hint: "Could not read the auth file while refreshing. Retry, or run 'uip login' to re-authenticate.",
39414
+ tokenRefresh: {
39415
+ attempted: false,
39416
+ success: false,
39417
+ errorMessage: `auth file read failed: ${errorMessage(error)}`
39418
+ }
39419
+ }
39420
+ };
39421
+ }
39422
+ const freshAccess = fresh.UIPATH_ACCESS_TOKEN;
39423
+ const freshExp = freshAccess ? getTokenExpiration(freshAccess) : undefined;
39424
+ if (freshAccess && freshExp && freshExp > expirationThreshold) {
39425
+ return {
39426
+ kind: "ok",
39427
+ accessToken: freshAccess,
39428
+ refreshToken: fresh.UIPATH_REFRESH_TOKEN ?? callerRefreshToken,
39429
+ expiration: freshExp,
39430
+ tokenRefresh: { attempted: false, success: true }
39431
+ };
39432
+ }
39433
+ const tokenForIdP = fresh.UIPATH_REFRESH_TOKEN ?? callerRefreshToken;
39434
+ let refreshedAccess;
39435
+ let refreshedRefresh;
39436
+ try {
39437
+ const config = await resolveConfig({ customAuthority });
39438
+ const refreshed = await refreshFn({
39439
+ refreshToken: tokenForIdP,
39440
+ tokenEndpoint: config.tokenEndpoint,
39441
+ clientId: config.clientId,
39442
+ expectedAuthority: customAuthority
39443
+ });
39444
+ refreshedAccess = refreshed.accessToken;
39445
+ refreshedRefresh = refreshed.refreshToken;
39446
+ } catch (error) {
39447
+ const isOAuthFailure = isTokenRefreshOAuthFailure(error);
39448
+ const hint = isOAuthFailure ? "Run 'uip login' to re-authenticate — the stored refresh token is invalid or expired." : "Token refresh failed. Check your network connection, then retry or run 'uip login' to re-authenticate.";
39449
+ const message = isOAuthFailure ? normalizeTokenRefreshFailure() : normalizeTokenRefreshUnavailableFailure();
39450
+ return {
39451
+ kind: "fail",
39452
+ status: {
39453
+ loginStatus: "Refresh Failed",
39454
+ hint,
39455
+ tokenRefresh: {
39456
+ attempted: true,
39457
+ success: false,
39458
+ errorMessage: message
39459
+ }
39460
+ }
39461
+ };
39462
+ }
39463
+ const refreshedExp = getTokenExpiration(refreshedAccess);
39464
+ if (!refreshedExp || refreshedExp <= new Date) {
39465
+ return {
39466
+ kind: "fail",
39467
+ status: {
39468
+ loginStatus: "Refresh Failed",
39469
+ hint: "The identity server returned an unusable token. Run 'uip login' to re-authenticate.",
39470
+ tokenRefresh: {
39471
+ attempted: true,
39472
+ success: false,
39473
+ errorMessage: "refreshed token has no valid expiration claim"
39474
+ }
39475
+ }
39476
+ };
39477
+ }
39478
+ try {
39479
+ await saveEnvFile({
39480
+ envPath: absolutePath,
39481
+ data: {
39482
+ UIPATH_ACCESS_TOKEN: refreshedAccess,
39483
+ UIPATH_REFRESH_TOKEN: refreshedRefresh
39484
+ },
39485
+ merge: true
39486
+ });
39487
+ return {
39488
+ kind: "ok",
39489
+ accessToken: refreshedAccess,
39490
+ refreshToken: refreshedRefresh,
39491
+ expiration: refreshedExp,
39492
+ tokenRefresh: { attempted: true, success: true }
39493
+ };
39494
+ } catch (error) {
39495
+ const msg = errorMessage(error);
39496
+ return {
39497
+ kind: "ok",
39498
+ accessToken: refreshedAccess,
39499
+ refreshToken: refreshedRefresh,
39500
+ expiration: refreshedExp,
39501
+ persistenceWarning: `Access token refreshed in memory but could not be written to ${absolutePath}: ${msg}. The next CLI invocation will fail until the file can be updated — run 'uip login' to re-authenticate.`,
39502
+ tokenRefresh: {
39503
+ attempted: true,
39504
+ success: true,
39505
+ errorMessage: `persistence failed: ${msg}`
39506
+ }
39507
+ };
39508
+ }
39509
+ }
39137
39510
  var getLoginStatusWithDeps = async (options = {}, deps = {}) => {
39138
39511
  const {
39139
39512
  resolveEnvFilePath = resolveEnvFilePathAsync,
@@ -39208,73 +39581,103 @@ var getLoginStatusWithDeps = async (options = {}, deps = {}) => {
39208
39581
  let refreshToken = credentials.UIPATH_REFRESH_TOKEN;
39209
39582
  let expiration = getTokenExpiration(accessToken);
39210
39583
  let persistenceWarning;
39584
+ let lockReleaseFailed = false;
39211
39585
  let tokenRefresh;
39212
- const expirationThreshold = new Date(Date.now() + (ensureTokenValidityMinutes ?? 0) * 60 * 1000);
39213
- if (expiration && expiration <= expirationThreshold && refreshToken) {
39214
- let refreshedAccess;
39215
- let refreshedRefresh;
39586
+ const outerThreshold = computeExpirationThreshold(ensureTokenValidityMinutes);
39587
+ const tryGlobalCredsHint = async () => {
39588
+ const fs7 = getFs();
39589
+ const globalPath = fs7.path.join(fs7.env.homedir(), envFilePath);
39590
+ if (absolutePath === globalPath)
39591
+ return;
39592
+ if (!await fs7.exists(globalPath))
39593
+ return;
39216
39594
  try {
39217
- const config = await resolveConfig({
39218
- customAuthority: credentials.UIPATH_URL
39219
- });
39220
- const refreshed = await refreshTokenFn({
39221
- refreshToken,
39222
- tokenEndpoint: config.tokenEndpoint,
39223
- clientId: config.clientId,
39224
- expectedAuthority: credentials.UIPATH_URL
39225
- });
39226
- refreshedAccess = refreshed.accessToken;
39227
- refreshedRefresh = refreshed.refreshToken;
39228
- } catch (error) {
39229
- const isOAuthFailure = isTokenRefreshOAuthFailure(error);
39230
- const hint = isOAuthFailure ? "Run 'uip login' to re-authenticate — the stored refresh token is invalid or expired." : "Token refresh failed. Check your network connection, then retry or run 'uip login' to re-authenticate.";
39231
- const errorMessage = isOAuthFailure ? normalizeTokenRefreshFailure() : normalizeTokenRefreshUnavailableFailure();
39232
- return {
39233
- loginStatus: "Refresh Failed",
39234
- hint,
39235
- tokenRefresh: {
39236
- attempted: true,
39237
- success: false,
39238
- errorMessage
39239
- }
39240
- };
39595
+ const globalCreds = await loadEnvFile({ envPath: globalPath });
39596
+ if (!globalCreds.UIPATH_ACCESS_TOKEN)
39597
+ return;
39598
+ const globalExp = getTokenExpiration(globalCreds.UIPATH_ACCESS_TOKEN);
39599
+ if (globalExp && globalExp <= new Date)
39600
+ return;
39601
+ return `Local credentials file at ${absolutePath} has expired credentials. Valid credentials exist in ${globalPath}. Remove the local file or run 'uip login' to re-authenticate.`;
39602
+ } catch {
39603
+ return;
39241
39604
  }
39242
- const refreshedExp = getTokenExpiration(refreshedAccess);
39243
- if (!refreshedExp || refreshedExp <= new Date) {
39605
+ };
39606
+ if (expiration && expiration <= outerThreshold && refreshToken) {
39607
+ let release;
39608
+ try {
39609
+ release = await getFs().acquireLock(absolutePath);
39610
+ } catch (error) {
39611
+ const msg = errorMessage(error);
39612
+ const globalHint = await tryGlobalCredsHint();
39613
+ if (globalHint) {
39614
+ return {
39615
+ loginStatus: "Expired",
39616
+ accessToken,
39617
+ refreshToken,
39618
+ baseUrl: credentials.UIPATH_URL,
39619
+ organizationName: credentials.UIPATH_ORGANIZATION_NAME,
39620
+ organizationId: credentials.UIPATH_ORGANIZATION_ID,
39621
+ tenantName: credentials.UIPATH_TENANT_NAME,
39622
+ tenantId: credentials.UIPATH_TENANT_ID,
39623
+ expiration,
39624
+ source: "file" /* File */,
39625
+ hint: globalHint,
39626
+ tokenRefresh: {
39627
+ attempted: false,
39628
+ success: false,
39629
+ errorMessage: `lock acquisition failed: ${msg}`
39630
+ }
39631
+ };
39632
+ }
39244
39633
  return {
39245
39634
  loginStatus: "Refresh Failed",
39246
- hint: "The identity server returned an unusable token. Run 'uip login' to re-authenticate.",
39635
+ hint: "Could not acquire the auth-file lock — too many concurrent `uip` processes, or a permission issue on the auth directory. Retry, or run 'uip login' to re-authenticate.",
39247
39636
  tokenRefresh: {
39248
- attempted: true,
39637
+ attempted: false,
39249
39638
  success: false,
39250
- errorMessage: "refreshed token has no valid expiration claim"
39639
+ errorMessage: `lock acquisition failed: ${msg}`
39251
39640
  }
39252
39641
  };
39253
39642
  }
39254
- accessToken = refreshedAccess;
39255
- refreshToken = refreshedRefresh;
39256
- expiration = refreshedExp;
39643
+ let lockedFailure;
39257
39644
  try {
39258
- await saveEnvFile({
39259
- envPath: absolutePath,
39260
- data: {
39261
- UIPATH_ACCESS_TOKEN: accessToken,
39262
- UIPATH_REFRESH_TOKEN: refreshToken
39263
- },
39264
- merge: true
39645
+ const outcome = await runRefreshLocked({
39646
+ absolutePath,
39647
+ refreshToken,
39648
+ customAuthority: credentials.UIPATH_URL,
39649
+ ensureTokenValidityMinutes,
39650
+ loadEnvFile,
39651
+ saveEnvFile,
39652
+ refreshFn: refreshTokenFn,
39653
+ resolveConfig
39265
39654
  });
39266
- tokenRefresh = {
39267
- attempted: true,
39268
- success: true
39269
- };
39270
- } catch (error) {
39271
- const msg = error instanceof Error ? error.message : String(error);
39272
- persistenceWarning = `Access token refreshed in memory but could not be written to ${absolutePath}: ${msg}. The next CLI invocation will fail until the file can be updated — run 'uip login' to re-authenticate.`;
39273
- tokenRefresh = {
39274
- attempted: true,
39275
- success: true,
39276
- errorMessage: `persistence failed: ${msg}`
39277
- };
39655
+ if (outcome.kind === "fail") {
39656
+ lockedFailure = outcome.status;
39657
+ } else {
39658
+ accessToken = outcome.accessToken;
39659
+ refreshToken = outcome.refreshToken;
39660
+ expiration = outcome.expiration;
39661
+ tokenRefresh = outcome.tokenRefresh;
39662
+ if (outcome.persistenceWarning) {
39663
+ persistenceWarning = outcome.persistenceWarning;
39664
+ }
39665
+ }
39666
+ } finally {
39667
+ try {
39668
+ await release();
39669
+ } catch {
39670
+ lockReleaseFailed = true;
39671
+ }
39672
+ }
39673
+ if (lockedFailure) {
39674
+ const globalHint = await tryGlobalCredsHint();
39675
+ const base = globalHint ? {
39676
+ ...lockedFailure,
39677
+ loginStatus: "Expired",
39678
+ hint: globalHint
39679
+ } : lockedFailure;
39680
+ return lockReleaseFailed ? { ...base, lockReleaseFailed: true } : base;
39278
39681
  }
39279
39682
  }
39280
39683
  const result = {
@@ -39289,23 +39692,13 @@ var getLoginStatusWithDeps = async (options = {}, deps = {}) => {
39289
39692
  expiration,
39290
39693
  source: "file" /* File */,
39291
39694
  ...persistenceWarning ? { hint: persistenceWarning, persistenceFailed: true } : {},
39695
+ ...lockReleaseFailed ? { lockReleaseFailed: true } : {},
39292
39696
  ...tokenRefresh ? { tokenRefresh } : {}
39293
39697
  };
39294
39698
  if (result.loginStatus === "Expired") {
39295
- const fs7 = getFs();
39296
- const globalPath = fs7.path.join(fs7.env.homedir(), envFilePath);
39297
- if (absolutePath !== globalPath && await fs7.exists(globalPath)) {
39298
- try {
39299
- const globalCreds = await loadEnvFile({
39300
- envPath: globalPath
39301
- });
39302
- if (globalCreds.UIPATH_ACCESS_TOKEN) {
39303
- const globalExp = getTokenExpiration(globalCreds.UIPATH_ACCESS_TOKEN);
39304
- if (!globalExp || globalExp > new Date) {
39305
- result.hint = `Local credentials file at ${absolutePath} has expired credentials. Valid credentials exist in ${globalPath}. Remove the local file or run 'uip login' to re-authenticate.`;
39306
- }
39307
- }
39308
- } catch {}
39699
+ const globalHint = await tryGlobalCredsHint();
39700
+ if (globalHint) {
39701
+ result.hint = globalHint;
39309
39702
  }
39310
39703
  }
39311
39704
  return result;
@@ -39353,6 +39746,10 @@ var getAuthContext = async (options = {}) => {
39353
39746
  init_src();
39354
39747
  // ../auth/src/logout.ts
39355
39748
  init_src();
39749
+
39750
+ // ../auth/src/index.ts
39751
+ init_server();
39752
+
39356
39753
  // src/client-factory.ts
39357
39754
  var API_DOMAIN_MAP = new Map([
39358
39755
  [ConnectorsApi, "connections"],
@@ -39381,7 +39778,9 @@ async function createConnectionsConfig(options) {
39381
39778
  return new Configuration({
39382
39779
  basePath: `${baseUrl}/${organizationId}/${tenantName}/connections_`,
39383
39780
  accessToken: async () => accessToken,
39384
- headers: { "x-uipath-source": "UiPath.CodingAgent" }
39781
+ headers: addSdkUserAgentHeader({
39782
+ "x-uipath-source": "UiPath.CodingAgent"
39783
+ }, SDK_USER_AGENT)
39385
39784
  });
39386
39785
  }
39387
39786
  async function createElementsConfig(options) {
@@ -39389,7 +39788,9 @@ async function createElementsConfig(options) {
39389
39788
  return new Configuration2({
39390
39789
  basePath: `${baseUrl}/${organizationId}/${tenantName}/elements_/v3/element`,
39391
39790
  accessToken: async () => accessToken,
39392
- headers: { "x-uipath-source": "UiPath.CodingAgent" }
39791
+ headers: addSdkUserAgentHeader({
39792
+ "x-uipath-source": "UiPath.CodingAgent"
39793
+ }, SDK_USER_AGENT)
39393
39794
  });
39394
39795
  }
39395
39796
  async function createApiClient(ApiClass, options) {
@@ -39410,11 +39811,11 @@ async function executeOperation(options, connectionId, objectName, httpMethod =
39410
39811
  }
39411
39812
  const requestOptions = {
39412
39813
  method: httpMethod,
39413
- headers: {
39814
+ headers: addSdkUserAgentHeader({
39414
39815
  Authorization: `Bearer ${accessToken}`,
39415
39816
  "Content-Type": "application/json",
39416
39817
  "x-uipath-source": "UiPath.CodingAgent"
39417
- }
39818
+ }, SDK_USER_AGENT)
39418
39819
  };
39419
39820
  if (body && ["POST", "PUT", "PATCH"].includes(httpMethod)) {
39420
39821
  requestOptions.body = JSON.stringify(body);
@@ -39443,11 +39844,11 @@ async function fetchMetadataAsSchema(options, pathSuffix) {
39443
39844
  const { baseUrl, accessToken, organizationId, tenantName } = await getValidatedAuthContext(options);
39444
39845
  const url = `${baseUrl}/${organizationId}/${tenantName}/elements_/v3/element${pathSuffix}`;
39445
39846
  const response = await fetch(url, {
39446
- headers: {
39847
+ headers: addSdkUserAgentHeader({
39447
39848
  Authorization: `Bearer ${accessToken}`,
39448
39849
  Accept: "application/schema+json",
39449
39850
  "x-uipath-source": "UiPath.CodingAgent"
39450
- }
39851
+ }, SDK_USER_AGENT)
39451
39852
  });
39452
39853
  if (!response.ok) {
39453
39854
  const errorText = await response.text();
@@ -39464,11 +39865,11 @@ async function getInstanceObjectMetadataAsSchema(options, connectionOrInstanceId
39464
39865
  async function runInstanceDesignAction(options, connectionOrInstanceId, method, relativeUrl, body) {
39465
39866
  const { baseUrl, accessToken, organizationId, tenantName } = await getValidatedAuthContext(options);
39466
39867
  const url = `${baseUrl}/${organizationId}/${tenantName}/elements_/v3/element/instances/${encodeURIComponent(connectionOrInstanceId)}${relativeUrl}`;
39467
- const headers = {
39868
+ const headers = addSdkUserAgentHeader({
39468
39869
  Authorization: `Bearer ${accessToken}`,
39469
39870
  Accept: "application/json",
39470
39871
  "x-uipath-source": "UiPath.CodingAgent"
39471
- };
39872
+ }, SDK_USER_AGENT);
39472
39873
  const init = { method, headers };
39473
39874
  if (body && Object.keys(body).length > 0) {
39474
39875
  headers["Content-Type"] = "application/json";
@@ -39503,11 +39904,11 @@ async function getWebhookConfig(options, connectionId, elementInstanceId, connec
39503
39904
  });
39504
39905
  const url = `${baseUrl}/${organizationId}/${tenantName}/elements_/v1/webhooks/subscribers/${encodeURIComponent(connectionId)}/webhook/config?${params.toString()}`;
39505
39906
  const response = await fetch(url, {
39506
- headers: {
39907
+ headers: addSdkUserAgentHeader({
39507
39908
  Authorization: `Bearer ${accessToken}`,
39508
39909
  Accept: "application/json",
39509
39910
  "x-uipath-source": "UiPath.CodingAgent"
39510
- }
39911
+ }, SDK_USER_AGENT)
39511
39912
  });
39512
39913
  if (!response.ok) {
39513
39914
  const errorText = await response.text();
@@ -39520,12 +39921,12 @@ async function getHttpRequestPreview(options, connectionId) {
39520
39921
  const url = `${baseUrl}/${organizationId}/${tenantName}/elements_/v3/element/instances/${encodeURIComponent(connectionId)}/http-request-preview`;
39521
39922
  const response = await fetch(url, {
39522
39923
  method: "POST",
39523
- headers: {
39924
+ headers: addSdkUserAgentHeader({
39524
39925
  Authorization: `Bearer ${accessToken}`,
39525
39926
  "Content-Type": "application/json",
39526
39927
  Accept: "application/json",
39527
39928
  "x-uipath-source": "UiPath.CodingAgent"
39528
- },
39929
+ }, SDK_USER_AGENT),
39529
39930
  body: "{}"
39530
39931
  });
39531
39932
  if (!response.ok) {
@@ -39542,11 +39943,11 @@ async function getEventOperationObjects(options, elementInstanceId, connectorKey
39542
39943
  const { baseUrl, accessToken, organizationId, tenantName } = await getValidatedAuthContext(options);
39543
39944
  const url = `${baseUrl}/${organizationId}/${tenantName}/elements_/v3/element/instances/${encodeURIComponent(String(elementInstanceId))}/elements/${encodeURIComponent(connectorKey)}/events/operations/${encodeURIComponent(eventOperation)}/objects`;
39544
39945
  const response = await fetch(url, {
39545
- headers: {
39946
+ headers: addSdkUserAgentHeader({
39546
39947
  Authorization: `Bearer ${accessToken}`,
39547
39948
  Accept: "application/json",
39548
39949
  "x-uipath-source": "UiPath.CodingAgent"
39549
- }
39950
+ }, SDK_USER_AGENT)
39550
39951
  });
39551
39952
  if (!response.ok) {
39552
39953
  const errorText = await response.text();
@@ -41487,6 +41888,7 @@ export {
41487
41888
  SecurityRequirementToJSON,
41488
41889
  SecurityRequirementFromJSONTyped,
41489
41890
  SecurityRequirementFromJSON,
41891
+ SDK_USER_AGENT,
41490
41892
  RuntimeMetadataToJSONTyped,
41491
41893
  RuntimeMetadataToJSON,
41492
41894
  RuntimeMetadataOrBuilderToJSONTyped,