@uipath/common 1.197.0 → 1.198.0-preview.100

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.
@@ -45,15 +45,19 @@ export interface ConnectivityError {
45
45
  /** Actionable, user-facing remediation steps. */
46
46
  instructions: string;
47
47
  }
48
+ export declare function formatErrorChain(error: unknown): string;
48
49
  /**
49
- * Classify an outbound connectivity failure by walking the `cause` chain.
50
+ * Classify an outbound connectivity failure by walking the error graph.
50
51
  *
51
52
  * Node's native `fetch` wraps the real failure (a TLS or socket error) inside
52
53
  * a generic `TypeError: fetch failed`, so the useful code/message lives on
53
- * `error.cause` (sometimes nested deeper). This unwraps that chain and, when
54
- * it finds a known TLS or network code, returns the specific message plus
55
- * remediation steps. Returns `undefined` for anything that isn't a recognised
56
- * connectivity failure so callers can fall back to their normal handling.
54
+ * `error.cause` (sometimes nested deeper). When fetch races several addresses
55
+ * (IPv4/IPv6, or proxy fallbacks) it instead collects the per-attempt failures
56
+ * in an `AggregateError.errors` array so the code can hide there rather than
57
+ * on a single `.cause`. This walks both edges and, when it finds a known TLS
58
+ * or network code, returns the specific message plus remediation steps.
59
+ * Returns `undefined` for anything that isn't a recognised connectivity
60
+ * failure so callers can fall back to their normal handling.
57
61
  */
58
62
  export declare function describeConnectivityError(error: unknown): ConnectivityError | undefined;
59
63
  export declare function isHtmlDocument(body: string): boolean;
@@ -179,6 +179,7 @@ export declare namespace OutputFormatter {
179
179
  function emitList<T extends DataRecord>(code: string, items: T[], opts?: {
180
180
  emptyInstructions?: string;
181
181
  warning?: string;
182
+ pagination?: Pagination;
182
183
  }): void;
183
184
  /**
184
185
  * Log an informational/progress message to stderr.
@@ -21051,9 +21051,47 @@ var TLS_ERROR_CODES = new Set([
21051
21051
  ]);
21052
21052
  var TLS_INSTRUCTIONS = "The server's TLS certificate could not be verified. Most often a " + "corporate proxy/firewall re-signs HTTPS with a root CA that Node does " + "not trust — set NODE_EXTRA_CA_CERTS to that CA's PEM file (and HTTPS_PROXY " + "if you connect through a proxy). If the certificate is instead expired or " + "its hostname does not match, fix the endpoint URL or the system clock. " + "Then retry.";
21053
21053
  var NETWORK_INSTRUCTIONS = "Could not reach the UiPath service. Check your network connection and " + "VPN, confirm any HTTP_PROXY/HTTPS_PROXY/NO_PROXY settings are correct, " + "then retry.";
21054
+ function formatErrorChain(error) {
21055
+ const lines = [];
21056
+ const seen = new Set;
21057
+ const visit = (value, depth) => {
21058
+ if (lines.length >= 32)
21059
+ return;
21060
+ const indent = " ".repeat(depth);
21061
+ if (value === null || typeof value !== "object") {
21062
+ lines.push(`${indent}${String(value)}`);
21063
+ return;
21064
+ }
21065
+ if (seen.has(value))
21066
+ return;
21067
+ seen.add(value);
21068
+ const cur = value;
21069
+ const name = typeof cur.name === "string" ? cur.name : "Error";
21070
+ const message = typeof cur.message === "string" ? cur.message : String(value);
21071
+ const code2 = typeof cur.code === "string" ? ` [${cur.code}]` : "";
21072
+ lines.push(`${indent}${name}: ${message}${code2}`);
21073
+ if (cur.cause !== undefined)
21074
+ visit(cur.cause, depth + 1);
21075
+ if (Array.isArray(cur.errors)) {
21076
+ for (const nested of cur.errors) {
21077
+ visit(nested, depth + 1);
21078
+ }
21079
+ }
21080
+ };
21081
+ visit(error, 0);
21082
+ return lines.join(`
21083
+ `);
21084
+ }
21054
21085
  function describeConnectivityError(error) {
21055
- let current = error;
21056
- for (let depth = 0;depth < 5 && current !== null && typeof current === "object"; depth++) {
21086
+ const queue2 = [error];
21087
+ const seen = new Set;
21088
+ for (let steps = 0;queue2.length > 0 && steps < 32; steps++) {
21089
+ const current = queue2.shift();
21090
+ if (current === null || typeof current !== "object")
21091
+ continue;
21092
+ if (seen.has(current))
21093
+ continue;
21094
+ seen.add(current);
21057
21095
  const cur = current;
21058
21096
  const code2 = typeof cur.code === "string" ? cur.code : undefined;
21059
21097
  const message = typeof cur.message === "string" ? cur.message : undefined;
@@ -21073,7 +21111,10 @@ function describeConnectivityError(error) {
21073
21111
  instructions: NETWORK_INSTRUCTIONS
21074
21112
  };
21075
21113
  }
21076
- current = cur.cause;
21114
+ if (cur.cause !== undefined)
21115
+ queue2.push(cur.cause);
21116
+ if (Array.isArray(cur.errors))
21117
+ queue2.push(...cur.errors);
21077
21118
  }
21078
21119
  return;
21079
21120
  }
@@ -21668,6 +21709,7 @@ function buildActionCenterTaskUrl(baseUrl, org, tenant, taskId) {
21668
21709
  // src/output-format-context.ts
21669
21710
  var formatSlot = singleton("OutputFormat");
21670
21711
  var formatExplicitSlot = singleton("OutputFormatExplicit");
21712
+ var helpRequestedSlot = singleton("HelpRequested");
21671
21713
  var filterSlot = singleton("OutputFilter");
21672
21714
  function setOutputFormat(format4) {
21673
21715
  formatSlot.set(format4);
@@ -21681,6 +21723,12 @@ function setOutputFormatExplicit(explicit) {
21681
21723
  function getOutputFormatExplicit() {
21682
21724
  return formatExplicitSlot.get(false) ?? false;
21683
21725
  }
21726
+ function setHelpRequested(requested) {
21727
+ helpRequestedSlot.set(requested);
21728
+ }
21729
+ function getHelpRequested() {
21730
+ return helpRequestedSlot.get(false) ?? false;
21731
+ }
21684
21732
  function setOutputFilter(filter) {
21685
21733
  filterSlot.set(filter);
21686
21734
  }
@@ -22761,11 +22809,36 @@ class ConsoleTelemetryProvider {
22761
22809
  console.debug(`[Telemetry] Dependency: ${name} [${type}] (${duration}ms, ${success ? "ok" : "fail"})`);
22762
22810
  }
22763
22811
  }
22812
+ // src/telemetry/trace-context.ts
22813
+ var TELEMETRY_TRACEPARENT_ENV = "TRACEPARENT";
22814
+ var TRACEPARENT_PATTERN = /^00-([0-9a-f]{32})-([0-9a-f]{16})-[0-9a-f]{2}$/;
22815
+ function getProcessEnv() {
22816
+ return globalThis.process?.env;
22817
+ }
22818
+ function parseInboundTraceparent(value) {
22819
+ if (!value) {
22820
+ return;
22821
+ }
22822
+ const match = TRACEPARENT_PATTERN.exec(value.trim().toLowerCase());
22823
+ if (!match) {
22824
+ return;
22825
+ }
22826
+ const [, traceId, parentSpanId] = match;
22827
+ if (/^0+$/.test(traceId) || /^0+$/.test(parentSpanId)) {
22828
+ return;
22829
+ }
22830
+ return { traceId, parentSpanId };
22831
+ }
22832
+ function getInboundTraceContext() {
22833
+ return parseInboundTraceparent(getProcessEnv()?.[TELEMETRY_TRACEPARENT_ENV]);
22834
+ }
22835
+
22764
22836
  // src/telemetry/session-id.ts
22765
22837
  var TELEMETRY_SESSION_ID_ENV = "UIPATH_SESSION_ID";
22766
22838
  var TELEMETRY_SESSION_ID_PROPERTY = "session_id";
22767
22839
  var telemetrySessionIdSlot = singleton("TelemetrySessionId");
22768
- function getProcessEnv() {
22840
+ var telemetryOperationIdSlot = singleton("TelemetryOperationId");
22841
+ function getProcessEnv2() {
22769
22842
  return globalThis.process?.env;
22770
22843
  }
22771
22844
  function normalizeSessionId(value) {
@@ -22776,7 +22849,7 @@ function normalizeSessionId(value) {
22776
22849
  return trimmed || undefined;
22777
22850
  }
22778
22851
  function getConfiguredTelemetrySessionId() {
22779
- return normalizeSessionId(getProcessEnv()?.[TELEMETRY_SESSION_ID_ENV]);
22852
+ return normalizeSessionId(getProcessEnv2()?.[TELEMETRY_SESSION_ID_ENV]);
22780
22853
  }
22781
22854
  function getTelemetrySessionId() {
22782
22855
  const envSessionId = getConfiguredTelemetrySessionId();
@@ -22794,6 +22867,16 @@ function getTelemetrySessionId() {
22794
22867
  function resolveTelemetrySessionId(existingSessionId) {
22795
22868
  return getConfiguredTelemetrySessionId() ?? normalizeSessionId(existingSessionId);
22796
22869
  }
22870
+ function getTelemetryOperationId() {
22871
+ const existing = telemetryOperationIdSlot.get();
22872
+ if (existing) {
22873
+ return existing;
22874
+ }
22875
+ const inboundTraceId = getInboundTraceContext()?.traceId;
22876
+ const generated = inboundTraceId ?? crypto.randomUUID().replaceAll("-", "");
22877
+ telemetryOperationIdSlot.set(generated);
22878
+ return generated;
22879
+ }
22797
22880
  // src/telemetry/telemetry-events.ts
22798
22881
  var CommonTelemetryEvents = {
22799
22882
  Error: "uip.error",
@@ -22929,7 +23012,144 @@ function getExecutionContextTelemetryProperties() {
22929
23012
  };
22930
23013
  }
22931
23014
 
23015
+ // src/telemetry/pii-redactor.ts
23016
+ var REDACTED = "[REDACTED]";
23017
+ var MAX_VALUE_LENGTH = 200;
23018
+ var SENSITIVE_NAME_TOKENS = new Set([
23019
+ "token",
23020
+ "tokens",
23021
+ "secret",
23022
+ "secrets",
23023
+ "password",
23024
+ "passwords",
23025
+ "pwd",
23026
+ "credential",
23027
+ "credentials",
23028
+ "auth",
23029
+ "authentication",
23030
+ "authorization",
23031
+ "authority",
23032
+ "cert",
23033
+ "certificate",
23034
+ "certificates"
23035
+ ]);
23036
+ var SENSITIVE_KEY_PREFIXES = new Set([
23037
+ "api",
23038
+ "access",
23039
+ "client",
23040
+ "private",
23041
+ "public",
23042
+ "signing",
23043
+ "encryption",
23044
+ "session",
23045
+ "master",
23046
+ "shared",
23047
+ "root",
23048
+ "ssh",
23049
+ "rsa",
23050
+ "aes",
23051
+ "hmac",
23052
+ "oauth"
23053
+ ]);
23054
+ var UUID_PATTERN = /\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b/gi;
23055
+ var EMAIL_PATTERN = /\b[^\s@]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b/g;
23056
+ var JWT_PATTERN = /\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+/g;
23057
+ var LONG_TOKEN_PATTERN = /\b[A-Za-z0-9_-]{40,}\b/g;
23058
+ var USER_HOME_PATTERN = /([/\\])(Users|home)([/\\])([^/\\]+)/gi;
23059
+ var URL_PATTERN = /\bhttps?:\/\/[^\s,;]+/gi;
23060
+ var URL_TRAILING_PUNCT = /[.,;:!?)\]}>'"]+$/;
23061
+ function shortHash(input) {
23062
+ let hash = 2166136261;
23063
+ for (let i2 = 0;i2 < input.length; i2++) {
23064
+ hash ^= input.charCodeAt(i2);
23065
+ hash = Math.imul(hash, 16777619);
23066
+ }
23067
+ return (hash >>> 0).toString(16).padStart(8, "0");
23068
+ }
23069
+ function redactUrl(raw) {
23070
+ try {
23071
+ const url = new URL(raw);
23072
+ return `${url.protocol}//${url.host}`;
23073
+ } catch {
23074
+ return `url#${shortHash(raw)}`;
23075
+ }
23076
+ }
23077
+ function redactValueDetectors(value) {
23078
+ let out = value;
23079
+ out = out.replace(JWT_PATTERN, () => REDACTED);
23080
+ out = out.replace(URL_PATTERN, (match) => {
23081
+ const trailing = match.match(URL_TRAILING_PUNCT)?.[0] ?? "";
23082
+ const core = trailing ? match.slice(0, -trailing.length) : match;
23083
+ return `${redactUrl(core)}${trailing}`;
23084
+ });
23085
+ out = out.replace(USER_HOME_PATTERN, (_match, sep1, folder, sep2) => `${sep1}${folder}${sep2}<user>`);
23086
+ out = out.replace(EMAIL_PATTERN, (match) => `email#${shortHash(match)}`);
23087
+ out = out.replace(UUID_PATTERN, (match) => `uuid#${shortHash(match)}`);
23088
+ out = out.replace(LONG_TOKEN_PATTERN, () => REDACTED);
23089
+ if (out.length > MAX_VALUE_LENGTH) {
23090
+ out = `${out.slice(0, MAX_VALUE_LENGTH)}…`;
23091
+ }
23092
+ return out;
23093
+ }
23094
+ function redactValue(value) {
23095
+ return redactValueDetectors(value);
23096
+ }
23097
+ function redactError(error) {
23098
+ const safe = new Error(redactValueDetectors(error.message ?? ""));
23099
+ safe.name = error.name;
23100
+ safe.stack = typeof error.stack === "string" ? redactValueDetectors(error.stack) : undefined;
23101
+ return safe;
23102
+ }
23103
+ function nameTokens(name) {
23104
+ return name.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").split(/[\s._-]+/).map((t) => t.toLowerCase()).filter(Boolean);
23105
+ }
23106
+ function isSensitiveName(name) {
23107
+ const tokens = nameTokens(name);
23108
+ for (let i2 = 0;i2 < tokens.length; i2++) {
23109
+ const token = tokens[i2];
23110
+ if (SENSITIVE_NAME_TOKENS.has(token)) {
23111
+ return true;
23112
+ }
23113
+ if (token === "key" || token === "keys") {
23114
+ const prev = tokens[i2 - 1];
23115
+ if (prev && SENSITIVE_KEY_PREFIXES.has(prev)) {
23116
+ return true;
23117
+ }
23118
+ }
23119
+ }
23120
+ return false;
23121
+ }
23122
+ function redactProperty(name, value) {
23123
+ if (value === undefined || value === null) {
23124
+ return;
23125
+ }
23126
+ if (isSensitiveName(name)) {
23127
+ return REDACTED;
23128
+ }
23129
+ if (typeof value === "boolean" || typeof value === "number") {
23130
+ return value;
23131
+ }
23132
+ if (typeof value !== "string") {
23133
+ return "[OBJECT]";
23134
+ }
23135
+ return redactValueDetectors(value);
23136
+ }
23137
+ function redactProperties(properties) {
23138
+ const out = {};
23139
+ for (const [name, value] of Object.entries(properties)) {
23140
+ const redacted = redactProperty(name, value);
23141
+ if (redacted !== undefined) {
23142
+ out[name] = redacted;
23143
+ }
23144
+ }
23145
+ return out;
23146
+ }
23147
+
22932
23148
  // src/telemetry/telemetry-service.ts
23149
+ var TELEMETRY_OPERATION_ID_PROPERTY = "uip.trace.operation_id";
23150
+ var TELEMETRY_PARENT_ID_PROPERTY = "uip.trace.parent_id";
23151
+ var TELEMETRY_SPAN_ID_PROPERTY = "uip.trace.span_id";
23152
+
22933
23153
  class TelemetryService {
22934
23154
  telemetryProvider;
22935
23155
  contextStorage;
@@ -22956,11 +23176,15 @@ class TelemetryService {
22956
23176
  trackException(error, properties) {
22957
23177
  const context = this.getCurrentContext();
22958
23178
  const enrichedProperties = this.enrichPropertiesWithContext(properties, context);
22959
- this.telemetryProvider.trackException(error, enrichedProperties);
23179
+ this.telemetryProvider.trackException(redactError(error), enrichedProperties);
22960
23180
  }
22961
23181
  async trackRequest(name, fn, properties) {
23182
+ const parentContext = this.getCurrentContext();
23183
+ const operationId = parentContext?.operationId ?? this.operationId ?? getTelemetryOperationId();
23184
+ const parentId = parentContext ? parentContext.id : this.inboundParentIdFor(operationId);
22962
23185
  const context = {
22963
- operationId: this.operationId ?? this.generateId(),
23186
+ operationId,
23187
+ ...parentId !== undefined ? { parentId } : {},
22964
23188
  id: this.generateId()
22965
23189
  };
22966
23190
  const startTime = performance.now();
@@ -22978,6 +23202,45 @@ class TelemetryService {
22978
23202
  throw error;
22979
23203
  }
22980
23204
  }
23205
+ trackRequestResult(name, durationMs, success, properties, context) {
23206
+ const requestContext = context ?? {
23207
+ operationId: this.operationId ?? getTelemetryOperationId(),
23208
+ id: this.generateId()
23209
+ };
23210
+ const enrichedProperties = this.enrichPropertiesWithContext(properties, requestContext);
23211
+ this.telemetryProvider.trackRequest(name, durationMs, success, enrichedProperties);
23212
+ }
23213
+ createRequestContext() {
23214
+ const operationId = this.operationId ?? getTelemetryOperationId();
23215
+ const parentId = this.inboundParentIdFor(operationId);
23216
+ return {
23217
+ operationId,
23218
+ ...parentId !== undefined ? { parentId } : {},
23219
+ id: this.generateId()
23220
+ };
23221
+ }
23222
+ inboundParentIdFor(operationId) {
23223
+ const inbound = getInboundTraceContext();
23224
+ return inbound && inbound.traceId === operationId ? inbound.parentSpanId : undefined;
23225
+ }
23226
+ runWithContext(context, fn) {
23227
+ return this.contextStorage.run(context, fn);
23228
+ }
23229
+ createDependencyContext() {
23230
+ const parentContext = this.getCurrentContext();
23231
+ if (!parentContext) {
23232
+ return;
23233
+ }
23234
+ return {
23235
+ operationId: parentContext.operationId,
23236
+ parentId: parentContext.id,
23237
+ id: this.generateId()
23238
+ };
23239
+ }
23240
+ trackDependencyResult(name, type, durationMs, success, properties, context, resultCode) {
23241
+ const enrichedProperties = this.enrichPropertiesWithContext(properties, context);
23242
+ this.telemetryProvider.trackDependency(redactValue(name), type, durationMs, success, enrichedProperties, resultCode);
23243
+ }
22981
23244
  async trackDependencyOperation(name, type, fn, properties) {
22982
23245
  const parentContext = this.getCurrentContext();
22983
23246
  if (!parentContext) {
@@ -23014,8 +23277,12 @@ class TelemetryService {
23014
23277
  ...getExecutionContextTelemetryProperties(),
23015
23278
  ...globalProperties,
23016
23279
  ...this.defaultProperties,
23017
- ...properties,
23018
- ...context
23280
+ ...redactProperties(properties ?? {}),
23281
+ ...context ? {
23282
+ [TELEMETRY_OPERATION_ID_PROPERTY]: context.operationId,
23283
+ ...context.parentId !== undefined ? { [TELEMETRY_PARENT_ID_PROPERTY]: context.parentId } : {},
23284
+ [TELEMETRY_SPAN_ID_PROPERTY]: context.id
23285
+ } : {}
23019
23286
  };
23020
23287
  if (sessionId === undefined) {
23021
23288
  delete enriched[TELEMETRY_SESSION_ID_PROPERTY];
@@ -23025,7 +23292,16 @@ class TelemetryService {
23025
23292
  return enriched;
23026
23293
  }
23027
23294
  generateId() {
23028
- return crypto.randomUUID().replaceAll("-", "");
23295
+ const bytes = new Uint8Array(8);
23296
+ let hex = "";
23297
+ do {
23298
+ crypto.getRandomValues(bytes);
23299
+ hex = "";
23300
+ for (const byte of bytes) {
23301
+ hex += byte.toString(16).padStart(2, "0");
23302
+ }
23303
+ } while (/^0+$/.test(hex));
23304
+ return hex;
23029
23305
  }
23030
23306
  }
23031
23307
  // src/tool-provider.ts
@@ -23049,6 +23325,7 @@ export {
23049
23325
  setOutputFormatExplicit,
23050
23326
  setOutputFormat,
23051
23327
  setOutputFilter,
23328
+ setHelpRequested,
23052
23329
  setGlobalSink,
23053
23330
  setGlobalLogFilePath,
23054
23331
  runWithSink,
@@ -23087,10 +23364,12 @@ export {
23087
23364
  getOutputFormat,
23088
23365
  getOutputFilter,
23089
23366
  getLogFilePath,
23367
+ getHelpRequested,
23090
23368
  getGlobalLogFilePath,
23091
23369
  getConfiguredTelemetrySessionId,
23092
23370
  getCompleter,
23093
23371
  getCommandExamples,
23372
+ formatErrorChain,
23094
23373
  extractFormatFromArgs,
23095
23374
  extractErrorMessageSync,
23096
23375
  extractErrorMessage,
@@ -23135,4 +23414,4 @@ export {
23135
23414
  AUTH_FILENAME
23136
23415
  };
23137
23416
 
23138
- //# debugId=ACC353BBF445886C64756E2164756E21
23417
+ //# debugId=A8F9E8E6B48366FF64756E2164756E21
package/dist/index.d.ts CHANGED
@@ -35,7 +35,7 @@ export * from "./telemetry/command-terminal.js";
35
35
  export { ConsoleTelemetryProvider } from "./telemetry/console-telemetry-provider.js";
36
36
  export * from "./telemetry/node.js";
37
37
  export { setGlobalTelemetryProperties } from "./telemetry/node-appinsights-telemetry-provider.js";
38
- export { redactProperties, redactProperty } from "./telemetry/pii-redactor.js";
38
+ export { redactError, redactProperties, redactProperty, redactValue, } from "./telemetry/pii-redactor.js";
39
39
  export { type ShipSucceededTelemetryPayload, trackShipSucceeded, } from "./telemetry/ship-succeeded.js";
40
40
  export * from "./telemetry/telemetry-events.js";
41
41
  export * from "./telemetry/telemetry-init.js";