@uipath/common 0.1.5

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 (3) hide show
  1. package/README.md +110 -0
  2. package/dist/index.js +7134 -0
  3. package/package.json +46 -0
package/README.md ADDED
@@ -0,0 +1,110 @@
1
+ # common
2
+
3
+ This package is the holder for common infrastructure needed by `uip` tools.
4
+
5
+ # Functionalities:
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";
14
+ ```
15
+
16
+ Functions exposed:
17
+
18
+ ### OutputFormatter.success
19
+
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
+ }
39
+
40
+ ```
41
+
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
+ }
63
+
64
+ ```
65
+
66
+ ### OutputFormatter.log
67
+
68
+ - Format message and logs to `console.log`
69
+ - Default `OutputFormat` is "table"
70
+
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
+ }
82
+ }
83
+ ```
84
+
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)
91
+
92
+ ```ts
93
+ import { logger, LogLevel } from "@uipath/common";
94
+
95
+ logger.debug("only visible when DEBUG is set");
96
+ logger.info("general info");
97
+ logger.warn("warning");
98
+ logger.error("error");
99
+
100
+ // Override the level at runtime
101
+ logger.setLevel(LogLevel.DEBUG);
102
+ ```
103
+
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 |
110
+