@uipath/common 0.1.15 → 0.9.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.
Files changed (48) hide show
  1. package/README.md +3 -3
  2. package/dist/catch-error.d.ts +5 -0
  3. package/dist/command-examples.d.ts +36 -0
  4. package/dist/command-help.d.ts +53 -0
  5. package/dist/command-walker.d.ts +14 -0
  6. package/dist/completer.d.ts +48 -0
  7. package/dist/console-guard.d.ts +24 -0
  8. package/dist/constants.d.ts +18 -0
  9. package/dist/env-reference.d.ts +10 -0
  10. package/dist/error-handler.d.ts +52 -0
  11. package/dist/error-instructions.d.ts +2 -0
  12. package/dist/formatter.d.ts +101 -0
  13. package/dist/index.d.ts +26 -0
  14. package/dist/index.js +1316 -161
  15. package/dist/jsonpath.d.ts +11 -0
  16. package/dist/logger.d.ts +116 -0
  17. package/dist/option-validators.d.ts +33 -0
  18. package/dist/output-context.d.ts +28 -0
  19. package/dist/output-format-context.d.ts +27 -0
  20. package/dist/output-sink.d.ts +23 -0
  21. package/dist/polling/abort-controller.d.ts +1 -0
  22. package/dist/polling/format-utils.d.ts +13 -0
  23. package/dist/polling/index.d.ts +6 -0
  24. package/dist/polling/poll-until.d.ts +60 -0
  25. package/dist/polling/terminal-statuses.d.ts +50 -0
  26. package/dist/polling/types.d.ts +247 -0
  27. package/dist/registry.d.ts +6 -0
  28. package/dist/screen-logger.d.ts +9 -0
  29. package/dist/singleton.d.ts +42 -0
  30. package/dist/telemetry/browser-context-storage.d.ts +29 -0
  31. package/dist/telemetry/console-telemetry-provider.d.ts +12 -0
  32. package/dist/telemetry/context-storage.d.ts +19 -0
  33. package/dist/telemetry/debug-telemetry-provider.d.ts +12 -0
  34. package/dist/telemetry/detect-agent.d.ts +13 -0
  35. package/dist/telemetry/index.d.ts +7 -0
  36. package/dist/telemetry/index.js +256 -0
  37. package/dist/telemetry/logger-telemetry-provider.d.ts +15 -0
  38. package/dist/telemetry/node-appinsights-telemetry-provider.d.ts +62 -0
  39. package/dist/telemetry/node-context-storage.d.ts +11 -0
  40. package/dist/telemetry/node.d.ts +7 -0
  41. package/dist/telemetry/pii-redactor.d.ts +32 -0
  42. package/dist/telemetry/telemetry-events.d.ts +3 -0
  43. package/dist/telemetry/telemetry-init.d.ts +53 -0
  44. package/dist/telemetry/telemetry-provider.d.ts +27 -0
  45. package/dist/telemetry/telemetry-service.d.ts +157 -0
  46. package/dist/tool-provider.d.ts +6 -0
  47. package/dist/trackedAction.d.ts +38 -0
  48. package/package.json +14 -6
package/README.md CHANGED
@@ -16,7 +16,7 @@ npm install @uipath/common
16
16
  import { OutputFormatter } from "@uipath/common";
17
17
 
18
18
  OutputFormatter.success({ Result: "Success", Code: "AssetList", Data: assets });
19
- OutputFormatter.error({ Result: "Failure", Message: "Not found", Instructions: "Check the ID" });
19
+ OutputFormatter.error({ Result: RESULTS.Failure, Message: "Not found", Instructions: "Check the ID" });
20
20
  ```
21
21
 
22
22
  Supported formats: `table`, `json`, `yaml`, `plain`.
@@ -30,7 +30,7 @@ import { catchError } from "@uipath/common";
30
30
 
31
31
  const [error, result] = await catchError(api.getData());
32
32
  if (error) {
33
- OutputFormatter.error({ Result: "Failure", Message: error.message, Instructions: "Retry" });
33
+ OutputFormatter.error({ Result: RESULTS.Failure, Message: error.message, Instructions: "Retry" });
34
34
  return;
35
35
  }
36
36
  ```
@@ -69,4 +69,4 @@ Debug output is enabled via `DEBUG` env var (Node/Bun) or `localStorage.debug` (
69
69
 
70
70
  ## License
71
71
 
72
- See the [root repository](https://github.com/UiPath/uipcli) for license information.
72
+ See the [root repository](https://github.com/UiPath/cli) for license information.
@@ -0,0 +1,5 @@
1
+ type CatchErrorResult<T> = [undefined, T] | [Error, undefined];
2
+ export declare function catchError<T>(fnOrPromise: Promise<T>): Promise<CatchErrorResult<T>>;
3
+ export declare function catchError<T>(fnOrPromise: () => Promise<T>): Promise<CatchErrorResult<T>>;
4
+ export declare function catchError<T>(fnOrPromise: () => T): CatchErrorResult<T>;
5
+ export {};
@@ -0,0 +1,36 @@
1
+ import { Command } from "commander";
2
+ /**
3
+ * Structured example output data, stored as objects for format-agnostic rendering.
4
+ * The `Code` mirrors the SuccessOutput.Code the real command would emit;
5
+ * `Data` holds anonymized sample records.
6
+ */
7
+ export interface CommandExampleOutput {
8
+ Code: string;
9
+ Data: Record<string, unknown> | Record<string, unknown>[];
10
+ }
11
+ /**
12
+ * A single usage example for a leaf command.
13
+ *
14
+ * Displayed in the "Examples" section of `--help` output.
15
+ * The `Output.Data` is stored as plain objects so the help renderer
16
+ * can format it in whatever `--output` mode is active (table, json, yaml, plain).
17
+ */
18
+ export interface CommandExample {
19
+ /** Short description of what this example demonstrates (optional). */
20
+ Description?: string;
21
+ /** The anonymized command invocation (e.g. "uip or machines list --limit 2"). */
22
+ Command: string;
23
+ /** Example response data the command would produce. */
24
+ Output: CommandExampleOutput;
25
+ }
26
+ /** Retrieve examples registered on a command (empty array if none). */
27
+ export declare function getCommandExamples(cmd: Command): CommandExample[];
28
+ declare module "commander" {
29
+ interface Command {
30
+ /**
31
+ * Register usage examples displayed in the "Examples" help section.
32
+ * Only meaningful on leaf commands (those with a `.trackedAction`).
33
+ */
34
+ examples(examples: CommandExample[]): this;
35
+ }
36
+ }
@@ -0,0 +1,53 @@
1
+ import { type Command, Help } from "commander";
2
+ import { type CommandExample } from "./command-examples";
3
+ import { type OutputFormat } from "./formatter";
4
+ export interface CommandHelpOption {
5
+ Flags: string;
6
+ Description: string;
7
+ Default?: string;
8
+ }
9
+ export interface CommandHelpArgument {
10
+ Name: string;
11
+ Description: string;
12
+ Required: boolean;
13
+ Default?: string;
14
+ }
15
+ export interface CommandHelpData {
16
+ Command: string;
17
+ Description: string;
18
+ Usage: string;
19
+ Arguments: CommandHelpArgument[];
20
+ Options: CommandHelpOption[];
21
+ Examples?: CommandExample[];
22
+ }
23
+ /**
24
+ * Extract structured help metadata from a Commander Command object.
25
+ * Uses Commander's Help utility methods (visibleOptions, visibleArguments)
26
+ * to ensure consistency with the default help text.
27
+ */
28
+ export declare function extractCommandHelp(cmd: Command, helper: Help): CommandHelpData;
29
+ /**
30
+ * Build a string representation of a command tree rooted at `command`.
31
+ *
32
+ * Table/plain format: delegates to Commander's built-in Help.formatHelp per command.
33
+ * Structured formats: aggregates extractCommandHelp data into a single envelope
34
+ * with full command paths.
35
+ */
36
+ export declare function formatHelpAll(command: Command, baseName?: string): string;
37
+ /**
38
+ * Pre-scan raw argv for --output <value> before Commander parses.
39
+ * Falls back to the environment-aware default ("table" for TTY, "json" otherwise).
40
+ */
41
+ export declare function extractFormatFromArgs(args: string[]): OutputFormat;
42
+ /**
43
+ * Register --help-all on a command. When triggered, prints the full
44
+ * recursive help for that command's subtree and exits.
45
+ *
46
+ * Uses Commander's `on('option:help-all')` event which fires during
47
+ * parseOptions — before subcommand routing — so it works on container
48
+ * commands that have no action handler.
49
+ *
50
+ * Output and exit use Commander's own infrastructure (configureOutput,
51
+ * CommanderError) — the same pattern Commander uses for --version.
52
+ */
53
+ export declare function registerHelpAll(command: Command): void;
@@ -0,0 +1,14 @@
1
+ import type { Command } from "commander";
2
+ export interface CommandEntry {
3
+ command: Command;
4
+ fullName: string;
5
+ }
6
+ /**
7
+ * Recursively walks the Commander program tree and collects all actionable
8
+ * commands — those with an action handler, or leaf commands without subcommands.
9
+ *
10
+ * Returns raw Commander Command objects paired with their full path name
11
+ * (e.g. "is connectors list"). Does NOT filter or format — consumers apply
12
+ * their own logic on top.
13
+ */
14
+ export declare function collectCommands(command: Command, parentName: string, result: CommandEntry[]): void;
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Declarative shell-completion API.
3
+ *
4
+ * Tools attach a `CompletionSpec` to a Commander Option or Argument. The spec
5
+ * describes a real user-facing CLI command whose JSON output supplies the
6
+ * candidate list at TAB time. The `uip completion <shell>` generator inlines
7
+ * this information into the emitted completion script, so TAB completion
8
+ * invokes the same commands a user would run directly — no hidden dispatch,
9
+ * no separate process-init path.
10
+ *
11
+ * Cross-bundle detail: each tool bundles its own copy of commander, so
12
+ * `instanceof Option` checks fail across bundles. Specs are stored on the
13
+ * target via a `Symbol.for()` key, which is shared process-wide.
14
+ *
15
+ * Example:
16
+ * withCompleter(option, {
17
+ * command: ["uip", "solution", "packages", "list", "--output", "json", "--take", "200"],
18
+ * valueSelector: "[.Data[].name] | unique | .[]",
19
+ * });
20
+ */
21
+ export interface CompletionSpec {
22
+ /**
23
+ * Argv of the public CLI command to invoke at TAB time. Tokens wrapped in
24
+ * `{name}` are substituted with the value of the option `--name` that the
25
+ * user has already typed (camelCase keys, matching Commander's attribute
26
+ * names).
27
+ */
28
+ command: string[];
29
+ /**
30
+ * `jq` filter applied to the command's stdout. Each non-empty line of the
31
+ * filtered output becomes a candidate value. `{name}` placeholders are
32
+ * substituted with `$name` (a jq variable) and bound at TAB time via
33
+ * `--arg name "$_req_name"`, so user-supplied values cannot escape the
34
+ * jq string context. `requiresOptions` must list each placeholder name.
35
+ * Missing `jq` or a non-zero exit silently yields no candidates (falls
36
+ * through to shell defaults).
37
+ */
38
+ valueSelector: string;
39
+ /**
40
+ * Option names (camelCase) that must be set on the current command before
41
+ * this completer is invoked. If any required option is absent, no TAB is
42
+ * performed — avoids useless network calls when context is incomplete.
43
+ */
44
+ requiresOptions?: string[];
45
+ }
46
+ /** Attach a completion spec to a Commander Option or Argument. */
47
+ export declare function withCompleter<T extends object>(target: T, spec: CompletionSpec): T;
48
+ export declare function getCompleter(target: object | null | undefined): CompletionSpec | undefined;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Global console interception guard.
3
+ *
4
+ * Patches `console.log`, `console.info`, `console.warn`, `console.error`,
5
+ * and `console.debug` so that output from third-party dependencies
6
+ * (e.g. applicationinsights, future npm packages) is routed through the
7
+ * OutputSink abstraction instead of writing directly to the terminal.
8
+ *
9
+ * Install once at CLI startup, after the sink is configured:
10
+ *
11
+ * configureLogger({ sink: new TerminalSink() });
12
+ * installConsoleGuard();
13
+ */
14
+ /**
15
+ * Install the console guard. Idempotent — calling twice is a no-op.
16
+ *
17
+ * Must be called **after** `configureLogger({ sink })` so that
18
+ * `getOutputSink()` resolves to the correct sink.
19
+ */
20
+ export declare function installConsoleGuard(): void;
21
+ /**
22
+ * Restore the original console methods. Intended for testing teardown.
23
+ */
24
+ export declare function restoreConsole(): void;
@@ -0,0 +1,18 @@
1
+ /** Home directory for all UiPath CLI data: ~/.uipath/ */
2
+ export declare const UIPATH_HOME_DIR = ".uipath";
3
+ /** Auth credentials filename within home directory */
4
+ export declare const AUTH_FILENAME = ".auth";
5
+ /** CLI config filename */
6
+ export declare const CONFIG_FILENAME = "config.json";
7
+ /** Local project config filename (looked up in CWD) */
8
+ export declare const LOCAL_CONFIG_FILENAME = "uipath.config.json";
9
+ /** Default UiPath cloud base URL */
10
+ export declare const DEFAULT_BASE_URL = "https://cloud.uipath.com";
11
+ /** Default page size for paginated API list commands */
12
+ export declare const DEFAULT_PAGE_SIZE = 50;
13
+ /** Auth callback server timeout (5 minutes) */
14
+ export declare const DEFAULT_AUTH_TIMEOUT_MS: number;
15
+ /** HTTP fetch timeout (30 seconds) */
16
+ export declare const DEFAULT_FETCH_TIMEOUT_MS = 30000;
17
+ /** Localhost OIDC redirect URI */
18
+ export declare const DEFAULT_REDIRECT_URI = "http://localhost:8104/oidc/login";
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Resolves a CLI argument value that may reference an environment variable.
3
+ * Supported syntax:
4
+ * env.ENV_NAME — e.g., env.UIPATH_CLIENT_ID
5
+ * Returns the value as-is if it doesn't match the pattern.
6
+ * Throws if the referenced env var is not set.
7
+ */
8
+ export declare function resolveEnvReference(value: string): string;
9
+ export declare function resolveEnvReference(value: undefined): undefined;
10
+ export declare function resolveEnvReference(value: string | undefined): string | undefined;
@@ -0,0 +1,52 @@
1
+ import type { ErrorContext, FailureResultType } from "./formatter";
2
+ /**
3
+ * Structured error details returned by {@link extractErrorDetails}.
4
+ */
5
+ export interface ErrorDetails {
6
+ /** Categorised failure type suitable for OutputFormatter.error() Result field */
7
+ result: FailureResultType;
8
+ /** Human-readable error message suitable for OutputFormatter.error() */
9
+ message: string;
10
+ /** Raw details from the response body or error object for debugging */
11
+ details: string;
12
+ /** Machine-readable context for agents (HTTP status, request ID, retry-after, etc.) */
13
+ context?: ErrorContext;
14
+ }
15
+ /**
16
+ * Options for customising error extraction behaviour.
17
+ */
18
+ export interface ExtractErrorOptions {
19
+ /** Custom message for HTTP 403 Forbidden errors. Uses a generic default if omitted. */
20
+ forbiddenMessage?: string;
21
+ }
22
+ /**
23
+ * Extract a structured error message and details from an unknown thrown value.
24
+ *
25
+ * Handles the common shapes seen across UiPath API SDKs:
26
+ * - Objects with `.status` and/or `.response.status` (HTTP-like errors)
27
+ * - JSON response bodies with `message`, `errorMessage`, `title`, or nested `errors`
28
+ * - Standard `Error` objects
29
+ * - Arbitrary values (stringified as fallback)
30
+ *
31
+ * HTTP status code handling:
32
+ * - 401 → authentication prompt
33
+ * - 403 → permissions message (customisable via `options.forbiddenMessage`)
34
+ * - 405 → endpoint hint
35
+ * - Other → `HTTP {status}: {body message}`
36
+ */
37
+ export declare function extractErrorDetails(error: unknown, options?: ExtractErrorOptions): Promise<ErrorDetails>;
38
+ /**
39
+ * Extract a human-readable error message from an unknown thrown value.
40
+ *
41
+ * Convenience wrapper around {@link extractErrorDetails} that returns only the
42
+ * message string.
43
+ */
44
+ export declare function extractErrorMessage(error: unknown, options?: ExtractErrorOptions): Promise<string>;
45
+ /**
46
+ * Synchronous variant of {@link extractErrorMessage}.
47
+ *
48
+ * Does NOT attempt to read response bodies (which requires async I/O).
49
+ * Suitable for MCP SDK errors and other contexts where errors are always
50
+ * plain `Error` objects.
51
+ */
52
+ export declare function extractErrorMessageSync(error: unknown): string;
@@ -0,0 +1,2 @@
1
+ export type ErrorInstructionContext = "auth" | "identity" | "input-parse" | "input-validate" | "flag-format" | "backend" | "permissions";
2
+ export declare function instructionsFor(ctx: ErrorInstructionContext, err?: unknown): string;
@@ -0,0 +1,101 @@
1
+ export type OutputFormat = "table" | "json" | "yaml" | "plain";
2
+ export type ResultType = "Success" | "Failure" | "ConfigError" | "AuthenticationError" | "ValidationError" | "TimeoutError";
3
+ export type FailureResultType = Exclude<ResultType, "Success">;
4
+ /** Canonical string constants for {@link ResultType} values. */
5
+ export declare const RESULTS: {
6
+ readonly Success: "Success";
7
+ readonly Failure: "Failure";
8
+ readonly ConfigError: "ConfigError";
9
+ readonly AuthenticationError: "AuthenticationError";
10
+ readonly ValidationError: "ValidationError";
11
+ /** Reserved — no code path emits this yet; here so the exit-code contract is stable. */
12
+ readonly TimeoutError: "TimeoutError";
13
+ };
14
+ /**
15
+ * Maps each {@link ResultType} to a numeric process exit code.
16
+ *
17
+ * | Code | Meaning |
18
+ * |------|--------------------------------|
19
+ * | 0 | Success |
20
+ * | 1 | Failure / ConfigError (generic)|
21
+ * | 2 | AuthenticationError |
22
+ * | 3 | ValidationError |
23
+ * | 4 | TimeoutError |
24
+ */
25
+ export declare const EXIT_CODES: {
26
+ readonly Success: 0;
27
+ readonly Failure: 1;
28
+ readonly ConfigError: 1;
29
+ readonly AuthenticationError: 2;
30
+ readonly ValidationError: 3;
31
+ readonly TimeoutError: 4;
32
+ };
33
+ /** Widened record type that accepts interface types (which lack an implicit
34
+ * index signature in TypeScript) while still representing keyed objects. */
35
+ export type DataRecord = Record<string, unknown> | (object & Record<never, never>);
36
+ export declare class SuccessOutput {
37
+ Result: "Success";
38
+ Code: string;
39
+ Data: DataRecord | DataRecord[];
40
+ Instructions?: string;
41
+ Log?: string;
42
+ constructor(code: string, data: DataRecord | DataRecord[]);
43
+ }
44
+ export interface ErrorContext {
45
+ httpStatus?: number;
46
+ errorCode?: string;
47
+ requestId?: string;
48
+ retryAfter?: number;
49
+ }
50
+ export declare class FailureOutput {
51
+ Result: FailureResultType;
52
+ Message: string;
53
+ Instructions: string;
54
+ Context?: ErrorContext;
55
+ Log?: string;
56
+ constructor(result: FailureResultType, message: string, instructions: string, context?: ErrorContext);
57
+ }
58
+ export type StructuredOutput = SuccessOutput | FailureOutput;
59
+ /**
60
+ * Check whether `filter` is a syntactically valid JMESPath expression.
61
+ * Returns `null` when valid, otherwise the parser error.
62
+ *
63
+ * Call this at CLI startup to fail fast with a ValidationError instead of
64
+ * letting {@link applyFilter} throw mid-command and be reported as a generic
65
+ * Failure.
66
+ *
67
+ * NOTE: this is a parse-time check only. JMESPath expressions that compile
68
+ * successfully can still throw at evaluation time (e.g. type-coercion errors
69
+ * when functions receive unexpected types). Callers that need a fully
70
+ * closed-box guarantee must additionally wrap {@link applyFilter}.
71
+ */
72
+ export declare function validateOutputFilter(filter: string): Error | null;
73
+ /**
74
+ * OutputFormatter namespace for formatting and displaying output.
75
+ */
76
+ export declare namespace OutputFormatter {
77
+ function success(data: SuccessOutput): void;
78
+ /**
79
+ * Format and display an error, then set {@link process.exitCode} to the
80
+ * value from {@link EXIT_CODES} for `data.Result` (falls back to 1).
81
+ *
82
+ * **Side-effect:** sets `process.exitCode` so the process exits with a
83
+ * non-zero status even if no explicit `process.exit()` call follows.
84
+ */
85
+ function error(data: FailureOutput): void;
86
+ /** Emit a list result. Always uses `Result: "Success"` — an empty list is not an error. */
87
+ function emitList<T extends DataRecord>(code: string, items: T[], opts?: {
88
+ emptyInstructions?: string;
89
+ warning?: string;
90
+ }): void;
91
+ /**
92
+ * Log an informational/progress message to stderr.
93
+ * Accepts a simple object (e.g., `{ Message: "..." }` or `{ Warning: "..." }`).
94
+ */
95
+ function log(data: Record<string, unknown>): void;
96
+ /**
97
+ * Format structured output to a string without writing to console.
98
+ * Useful when the caller needs the formatted string (e.g., Commander's formatHelp).
99
+ */
100
+ function formatToString(data: StructuredOutput): string;
101
+ }
@@ -0,0 +1,26 @@
1
+ export * from "./catch-error";
2
+ export * from "./command-examples";
3
+ export * from "./command-help";
4
+ export * from "./command-walker";
5
+ export * from "./completer";
6
+ export { installConsoleGuard, restoreConsole } from "./console-guard";
7
+ export * from "./constants";
8
+ export * from "./env-reference";
9
+ export * from "./error-handler";
10
+ export * from "./error-instructions";
11
+ export * from "./formatter";
12
+ export * from "./jsonpath";
13
+ export * from "./logger";
14
+ export * from "./option-validators";
15
+ export * from "./output-context";
16
+ export * from "./output-format-context";
17
+ export * from "./output-sink";
18
+ export * from "./polling";
19
+ export * from "./registry";
20
+ export * from "./screen-logger";
21
+ export * from "./telemetry/node.js";
22
+ export { setGlobalTelemetryProperties } from "./telemetry/node-appinsights-telemetry-provider.js";
23
+ export * from "./telemetry/telemetry-events.js";
24
+ export * from "./telemetry/telemetry-init.js";
25
+ export * from "./tool-provider";
26
+ export * from "./trackedAction.js";