@uipath/common 0.1.5 → 0.1.6

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 (2) hide show
  1. package/README.md +46 -84
  2. package/package.json +44 -44
package/README.md CHANGED
@@ -1,110 +1,72 @@
1
- # common
1
+ # @uipath/common
2
2
 
3
- This package is the holder for common infrastructure needed by `uip` tools.
3
+ Shared infrastructure for the UiPath CLI. Provides output formatting, logging, error handling, and telemetry.
4
4
 
5
- # Functionalities:
5
+ ## Installation
6
6
 
7
- ## 1. Output Formatter
8
-
9
- A small utility set of functions used to format a `typescript` data object in one of the data formats supported by [uip](https://github.com/UiPath/uipcli).
10
-
11
- Currently supported data formats are:
12
- ```
13
- type OutputFormat = "table" | "json" | "yaml" | "plain";
7
+ ```bash
8
+ npm install @uipath/common
14
9
  ```
15
10
 
16
- Functions exposed:
11
+ ## Usage
17
12
 
18
- ### OutputFormatter.success
13
+ ### Output Formatting
19
14
 
20
- - Format message and logs to `console.info`
21
- - Default `OutputFormat` is "table"
22
-
23
- ```
24
- export namespace OutputFormatter {
25
-
26
- export class SuccessOutput {
27
- Result: "Success" = "Success";
28
- Code: string;
29
- Data: Record<string, any>[] | Record<string, any>;
30
- }
31
-
32
- export function success(
33
- data: SuccessOutput,
34
- format: OutputFormat = "table",
35
- ): void {
36
- ...
37
- }
38
- }
15
+ ```ts
16
+ import { OutputFormatter } from "@uipath/common";
39
17
 
18
+ OutputFormatter.success({ Result: "Success", Code: "AssetList", Data: assets });
19
+ OutputFormatter.error({ Result: "Failure", Message: "Not found", Instructions: "Check the ID" });
40
20
  ```
41
21
 
42
- ### OutputFormatter.error
43
-
44
- - Format message and logs to `console.error`
45
- - Default `OutputFormat` is "table"
46
-
47
- ```
48
- export namespace OutputFormatter {
49
-
50
- export class FailureOutput {
51
- Result: FailureResultType;
52
- Message: string;
53
- Instructions: string;
54
- }
55
-
56
- export function error(
57
- data: FailureOutput,
58
- format: OutputFormat = "table",
59
- ): void {
60
- ...
61
- }
62
- }
22
+ Supported formats: `table`, `json`, `yaml`, `plain`.
63
23
 
64
- ```
24
+ ### Error Handling
65
25
 
66
- ### OutputFormatter.log
26
+ Go-style `[error, data]` tuple returns via `catchError`:
67
27
 
68
- - Format message and logs to `console.log`
69
- - Default `OutputFormat` is "table"
28
+ ```ts
29
+ import { catchError } from "@uipath/common";
70
30
 
71
- ```
72
- export namespace OutputFormatter {
73
-
74
- export class LogOutput {
75
- Message: string;
76
- [key: string]: unknown;
77
- }
78
-
79
- export function log(data: LogOutput, format: OutputFormat = "table"): void {
80
- ...
81
- }
31
+ const [error, result] = await catchError(api.getData());
32
+ if (error) {
33
+ OutputFormatter.error({ Result: "Failure", Message: error.message, Instructions: "Retry" });
34
+ return;
82
35
  }
83
36
  ```
84
37
 
85
- ## 2. Logger
86
-
87
- A simple console wrapper that works in both Node.js/Bun and browser environments. Supports four log levels and respects a `DEBUG` flag to enable verbose output.
88
-
89
- - **Node/Bun**: reads `process.env.DEBUG`
90
- - **Browser**: reads `localStorage.debug` (same convention as the `debug` npm package)
38
+ ### Logging
91
39
 
92
40
  ```ts
93
41
  import { logger, LogLevel } from "@uipath/common";
94
42
 
95
- logger.debug("only visible when DEBUG is set");
96
- logger.info("general info");
97
- logger.warn("warning");
98
- logger.error("error");
43
+ logger.info("Fetching resources...");
44
+ logger.debug("Request payload:", payload);
99
45
 
100
- // Override the level at runtime
46
+ // Override level at runtime
101
47
  logger.setLevel(LogLevel.DEBUG);
102
48
  ```
103
49
 
104
- | Method | Level | Node stream | Visible by default |
105
- |-----------------|---------|-------------|--------------------|
106
- | `logger.debug` | DEBUG | stdout | No |
107
- | `logger.info` | INFO | stdout | Yes |
108
- | `logger.warn` | WARN | stdout | Yes |
109
- | `logger.error` | ERROR | stderr | Yes |
50
+ | Method | Level | Stream | Visible by default |
51
+ | :--- | :--- | :--- | :--- |
52
+ | `logger.debug` | DEBUG | stdout | No |
53
+ | `logger.info` | INFO | stdout | Yes |
54
+ | `logger.warn` | WARN | stdout | Yes |
55
+ | `logger.error` | ERROR | stderr | Yes |
56
+
57
+ Debug output is enabled via `DEBUG` env var (Node/Bun) or `localStorage.debug` (browser).
58
+
59
+ ## API
60
+
61
+ | Export | Description |
62
+ | :--- | :--- |
63
+ | `OutputFormatter` | Structured output in table, JSON, YAML, or plain text |
64
+ | `catchError(promise)` | Go-style error handling returning `[error, data]` tuples |
65
+ | `logger` | Cross-platform logger with debug/info/warn/error levels |
66
+ | `trackedAction` | Commander.js extension for automatic telemetry tracking |
67
+ | `CommandWalker` | CLI command introspection utility |
68
+ | `OutputSink` | Abstraction for output destinations |
69
+
70
+ ## License
110
71
 
72
+ See the [root repository](https://github.com/UiPath/uipcli) for license information.
package/package.json CHANGED
@@ -1,46 +1,46 @@
1
1
  {
2
- "name": "@uipath/common",
3
- "version": "0.1.5",
4
- "description": "Common infrastructure needed by uipcli tools.",
5
- "repository": {
6
- "type": "git",
7
- "url": "https://github.com/UiPath/uipcli.git",
8
- "directory": "packages/common"
9
- },
10
- "publishConfig": {
11
- "registry": "https://registry.npmjs.org/"
12
- },
13
- "type": "module",
14
- "main": "./dist/index.js",
15
- "exports": {
16
- ".": "./dist/index.js"
17
- },
18
- "files": [
19
- "dist"
20
- ],
21
- "maintainers": [
22
- "aoltean16",
23
- "mihaigirleanu",
24
- "vlad-uipath"
25
- ],
26
- "scripts": {
27
- "build": "bun build ./src/index.ts --outdir dist --format esm --target node --external commander --external applicationinsights",
28
- "lint": "biome check .",
29
- "test": "vitest run",
30
- "test:coverage": "vitest run --coverage"
31
- },
32
- "dependencies": {
33
- "@jmespath-community/jmespath": "^1.3.0",
34
- "@uipath/telemetry": "0.0.3",
35
- "js-yaml": "^4.1.0",
36
- "jsonpath-plus": "^10.4.0"
37
- },
38
- "devDependencies": {
39
- "@types/js-yaml": "^4.0.9",
40
- "@types/node": "^25.2.3",
41
- "typescript": "^5"
42
- },
43
- "peerDependencies": {
44
- "commander": "^14.0.3"
45
- }
2
+ "name": "@uipath/common",
3
+ "version": "0.1.6",
4
+ "description": "Common infrastructure needed by uipcli tools.",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/UiPath/uipcli.git",
8
+ "directory": "packages/common"
9
+ },
10
+ "publishConfig": {
11
+ "registry": "https://registry.npmjs.org/"
12
+ },
13
+ "type": "module",
14
+ "main": "./dist/index.js",
15
+ "exports": {
16
+ ".": "./dist/index.js"
17
+ },
18
+ "files": [
19
+ "dist"
20
+ ],
21
+ "maintainers": [
22
+ "aoltean16",
23
+ "mihaigirleanu",
24
+ "vlad-uipath"
25
+ ],
26
+ "scripts": {
27
+ "build": "bun build ./src/index.ts --outdir dist --format esm --target node --external commander --external applicationinsights",
28
+ "lint": "biome check .",
29
+ "test": "vitest run",
30
+ "test:coverage": "vitest run --coverage"
31
+ },
32
+ "dependencies": {
33
+ "@jmespath-community/jmespath": "^1.3.0",
34
+ "@uipath/telemetry": "0.0.3",
35
+ "js-yaml": "^4.1.0",
36
+ "jsonpath-plus": "^10.4.0"
37
+ },
38
+ "devDependencies": {
39
+ "@types/js-yaml": "^4.0.9",
40
+ "@types/node": "^25.2.3",
41
+ "typescript": "^5"
42
+ },
43
+ "peerDependencies": {
44
+ "commander": "^14.0.3"
45
+ }
46
46
  }