@uipath/common 1.195.0 → 1.197.0-preview.59

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,32 @@
1
+ // src/catch-error.ts
2
+ function isPromiseLike(value) {
3
+ return value !== null && typeof value === "object" && typeof value.then === "function";
4
+ }
5
+ function catchError(fnOrPromise) {
6
+ if (isPromiseLike(fnOrPromise)) {
7
+ return settlePromiseLike(fnOrPromise);
8
+ }
9
+ try {
10
+ const result = fnOrPromise();
11
+ if (isPromiseLike(result)) {
12
+ return settlePromiseLike(result);
13
+ }
14
+ return [undefined, result];
15
+ } catch (error) {
16
+ return [
17
+ error instanceof Error ? error : new Error(String(error)),
18
+ undefined
19
+ ];
20
+ }
21
+ }
22
+ function settlePromiseLike(thenable) {
23
+ return Promise.resolve(thenable).then((data) => [undefined, data]).catch((error) => [
24
+ error instanceof Error ? error : new Error(String(error)),
25
+ undefined
26
+ ]);
27
+ }
28
+ export {
29
+ catchError
30
+ };
31
+
32
+ //# debugId=246638ED7A60E04D64756E2164756E21
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Flags that affirm a destructive operation. `--yes` is the canonical flag for
3
+ * delete/remove commands; `--force` is the established alias used by overwrite
4
+ * commands (`init`, `pull`). Either one satisfies the guard.
5
+ *
6
+ * Add the flag to a command with
7
+ * `.option("-y, --yes", "Confirm this irreversible operation (required; the CLI never prompts)")`
8
+ * and gate the handler with {@link requireConfirmation}.
9
+ */
10
+ export interface ConfirmationFlags {
11
+ yes?: boolean;
12
+ force?: boolean;
13
+ }
14
+ /**
15
+ * Guard a destructive operation. Returns `true` when the caller passed `--yes`
16
+ * (or `--force`). Otherwise emits a structured failure naming the flag to pass,
17
+ * sets a non-zero exit code via {@link processContext}, and returns `false` so
18
+ * the handler can bail in one line:
19
+ *
20
+ * ```ts
21
+ * if (!requireConfirmation(options, `delete folder '${id}'`)) return;
22
+ * ```
23
+ *
24
+ * @param flags - the parsed command options (must carry `yes`/`force`).
25
+ * @param operation - a short description of what will happen, e.g.
26
+ * `"delete folder 'Finance'"`. Surfaced in the error message.
27
+ */
28
+ export declare function requireConfirmation(flags: ConfirmationFlags, operation: string): boolean;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Generate a SHA-256 hex hash of content for change detection.
3
+ * Prefers the Web Crypto API; falls back to node:crypto outside the browser.
4
+ *
5
+ * @param content - String content to hash
6
+ * @returns Hex string of the hash
7
+ */
8
+ export declare function hashContent(content: string): Promise<string>;
@@ -1,12 +1,16 @@
1
- import type { ErrorContext, FailureResultType } from "./formatter";
1
+ import type { CliErrorCode, ErrorContext, FailureResultType, RetryHint } from "./formatter";
2
2
  /**
3
3
  * Structured error details returned by {@link extractErrorDetails}.
4
4
  */
5
5
  export interface ErrorDetails {
6
6
  /** Categorised failure type suitable for OutputFormatter.error() Result field */
7
7
  result: FailureResultType;
8
+ /** Stable CLI-owned error code suitable for agent control flow */
9
+ errorCode: CliErrorCode;
8
10
  /** Human-readable error message suitable for OutputFormatter.error() */
9
11
  message: string;
12
+ /** Stable retry guidance suitable for agent control flow */
13
+ retry: RetryHint;
10
14
  /** Raw details from the response body or error object for debugging */
11
15
  details: string;
12
16
  /** Machine-readable context for agents (HTTP status, request ID, retry-after, etc.) */
@@ -27,6 +31,31 @@ export interface ExtractErrorOptions {
27
31
  /** Custom message for HTTP 403 Forbidden errors. Uses a generic default if omitted. */
28
32
  forbiddenMessage?: string;
29
33
  }
34
+ /**
35
+ * A connectivity failure (TLS trust or socket/DNS), already classified with
36
+ * actionable guidance. Returned by {@link describeConnectivityError}.
37
+ */
38
+ export interface ConnectivityError {
39
+ /** The OS/TLS error code, e.g. `SELF_SIGNED_CERT_IN_CHAIN`. */
40
+ code: string;
41
+ /** Whether the failure is a TLS trust problem or a plain network problem. */
42
+ kind: "tls" | "network";
43
+ /** The most specific message found while walking the cause chain. */
44
+ message: string;
45
+ /** Actionable, user-facing remediation steps. */
46
+ instructions: string;
47
+ }
48
+ /**
49
+ * Classify an outbound connectivity failure by walking the `cause` chain.
50
+ *
51
+ * Node's native `fetch` wraps the real failure (a TLS or socket error) inside
52
+ * 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.
57
+ */
58
+ export declare function describeConnectivityError(error: unknown): ConnectivityError | undefined;
30
59
  export declare function isHtmlDocument(body: string): boolean;
31
60
  /**
32
61
  * Extract a structured error message and details from an unknown thrown value.
@@ -1,6 +1,10 @@
1
1
  export type OutputFormat = "table" | "json" | "yaml" | "plain";
2
2
  export type ResultType = "Success" | "Failure" | "ConfigError" | "AuthenticationError" | "ValidationError" | "TimeoutError";
3
3
  export type FailureResultType = Exclude<ResultType, "Success">;
4
+ export declare const CLI_ERROR_CODES: readonly ["invalid_argument", "authentication_required", "permission_denied", "not_found", "rate_limited", "network_error", "timeout", "server_error", "method_not_allowed", "configuration_error", "unknown_error"];
5
+ export type CliErrorCode = (typeof CLI_ERROR_CODES)[number];
6
+ export declare const RETRY_HINTS: readonly ["RetryWillNotFix", "RetryLater", "RetryAfter1Second", "RetryAfter10Seconds", "RetryAfter30Seconds", "RetryAfter60Seconds"];
7
+ export type RetryHint = (typeof RETRY_HINTS)[number];
4
8
  /** Canonical string constants for {@link ResultType} values. */
5
9
  export declare const RESULTS: {
6
10
  readonly Success: "Success";
@@ -76,8 +80,10 @@ export interface ErrorContext {
76
80
  export declare class FailureOutput {
77
81
  Result: FailureResultType;
78
82
  Code?: string;
83
+ ErrorCode?: CliErrorCode;
79
84
  Message: string;
80
85
  Instructions: string;
86
+ Retry?: RetryHint;
81
87
  Context?: ErrorContext;
82
88
  Log?: string;
83
89
  /**
@@ -88,7 +94,13 @@ export declare class FailureOutput {
88
94
  * across success / failure paths.
89
95
  */
90
96
  Data?: DataRecord | DataRecord[];
91
- constructor(result: FailureResultType, message: string, instructions: string, context?: ErrorContext);
97
+ /**
98
+ * Print the error and set the exit code, but don't emit the `uip.error`
99
+ * telemetry event — rate-limits high-frequency identical failures (e.g. a
100
+ * stuck auth-refresh loop). Stripped before the envelope is rendered.
101
+ */
102
+ SuppressTelemetry?: boolean;
103
+ constructor(result: FailureResultType, message: string, instructions: string, context?: ErrorContext, errorCode?: CliErrorCode, retry?: RetryHint);
92
104
  }
93
105
  export type StructuredOutput = SuccessOutput | FailureOutput;
94
106
  /**
@@ -119,7 +131,9 @@ export declare function validateOutputFilter(filter: string): Error | null;
119
131
  export declare class FilterEvaluationError extends Error {
120
132
  readonly __brand: "FilterEvaluationError";
121
133
  readonly filter: string;
134
+ readonly errorCode: CliErrorCode;
122
135
  readonly instructions: string;
136
+ readonly retry: RetryHint;
123
137
  readonly result: FailureResultType;
124
138
  constructor(filter: string, cause: unknown);
125
139
  }
@@ -5,19 +5,27 @@ export * from "./command-walker";
5
5
  export * from "./completer";
6
6
  export { installConsoleGuard, restoreConsole } from "./console-guard";
7
7
  export * from "./constants";
8
+ export * from "./content-hash";
8
9
  export * from "./env-reference";
9
10
  export * from "./error-handler";
10
11
  export * from "./error-instructions";
11
12
  export * from "./guid";
12
- export * from "./jsonpath";
13
13
  export * from "./logger";
14
14
  export * from "./option-validators";
15
15
  export * from "./orchestrator-urls";
16
16
  export * from "./output-context";
17
17
  export * from "./output-format-context";
18
18
  export * from "./output-sink";
19
+ export * from "./package-metadata-options";
19
20
  export * from "./polling";
20
21
  export * from "./screen-logger";
22
+ export * from "./sdk-user-agent";
21
23
  export * from "./singleton";
24
+ export { BrowserContextStorage } from "./telemetry/browser-context-storage.js";
25
+ export { ConsoleTelemetryProvider } from "./telemetry/console-telemetry-provider.js";
26
+ export type { IContextStorage } from "./telemetry/context-storage.js";
22
27
  export * from "./telemetry/telemetry-events.js";
28
+ export type { ITelemetryProvider } from "./telemetry/telemetry-provider.js";
29
+ export type { ITelemetryService, TelemetryContext, TelemetryProperties, } from "./telemetry/telemetry-service.js";
30
+ export { TelemetryService } from "./telemetry/telemetry-service.js";
23
31
  export * from "./tool-provider";