@uipath/common 0.2.0 → 0.9.1
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.
- package/README.md +3 -3
- package/dist/catch-error.d.ts +5 -0
- package/dist/command-examples.d.ts +36 -0
- package/dist/command-help.d.ts +53 -0
- package/dist/command-walker.d.ts +14 -0
- package/dist/completer.d.ts +48 -0
- package/dist/console-guard.d.ts +24 -0
- package/dist/constants.d.ts +18 -0
- package/dist/env-reference.d.ts +10 -0
- package/dist/error-handler.d.ts +52 -0
- package/dist/error-instructions.d.ts +2 -0
- package/dist/formatter.d.ts +101 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +1316 -161
- package/dist/jsonpath.d.ts +11 -0
- package/dist/logger.d.ts +116 -0
- package/dist/option-validators.d.ts +33 -0
- package/dist/output-context.d.ts +28 -0
- package/dist/output-format-context.d.ts +27 -0
- package/dist/output-sink.d.ts +23 -0
- package/dist/polling/abort-controller.d.ts +1 -0
- package/dist/polling/format-utils.d.ts +13 -0
- package/dist/polling/index.d.ts +6 -0
- package/dist/polling/poll-until.d.ts +60 -0
- package/dist/polling/terminal-statuses.d.ts +50 -0
- package/dist/polling/types.d.ts +247 -0
- package/dist/registry.d.ts +6 -0
- package/dist/screen-logger.d.ts +9 -0
- package/dist/singleton.d.ts +42 -0
- package/dist/telemetry/browser-context-storage.d.ts +29 -0
- package/dist/telemetry/console-telemetry-provider.d.ts +12 -0
- package/dist/telemetry/context-storage.d.ts +19 -0
- package/dist/telemetry/debug-telemetry-provider.d.ts +12 -0
- package/dist/telemetry/detect-agent.d.ts +13 -0
- package/dist/telemetry/index.d.ts +7 -0
- package/dist/telemetry/index.js +256 -0
- package/dist/telemetry/logger-telemetry-provider.d.ts +15 -0
- package/dist/telemetry/node-appinsights-telemetry-provider.d.ts +62 -0
- package/dist/telemetry/node-context-storage.d.ts +11 -0
- package/dist/telemetry/node.d.ts +7 -0
- package/dist/telemetry/pii-redactor.d.ts +32 -0
- package/dist/telemetry/telemetry-events.d.ts +3 -0
- package/dist/telemetry/telemetry-init.d.ts +53 -0
- package/dist/telemetry/telemetry-provider.d.ts +27 -0
- package/dist/telemetry/telemetry-service.d.ts +157 -0
- package/dist/tool-provider.d.ts +6 -0
- package/dist/trackedAction.d.ts +38 -0
- package/package.json +14 -6
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import type { IContextStorage } from "./context-storage.js";
|
|
2
|
+
import type { ITelemetryProvider } from "./telemetry-provider.js";
|
|
3
|
+
/**
|
|
4
|
+
* Properties that can be attached to telemetry events
|
|
5
|
+
*/
|
|
6
|
+
export interface TelemetryProperties {
|
|
7
|
+
[key: string]: string | number | boolean | undefined;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Telemetry correlation context for tracking parent-child relationships
|
|
11
|
+
*/
|
|
12
|
+
export interface TelemetryContext {
|
|
13
|
+
/**
|
|
14
|
+
* Operation ID - unique identifier for the entire operation tree
|
|
15
|
+
*/
|
|
16
|
+
operationId: string;
|
|
17
|
+
/**
|
|
18
|
+
* Parent ID - identifier of the parent operation (for correlation)
|
|
19
|
+
*/
|
|
20
|
+
parentId?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Current operation ID - identifier for this specific operation
|
|
23
|
+
*/
|
|
24
|
+
id: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Interface for tracking telemetry events.
|
|
28
|
+
*
|
|
29
|
+
* @remarks
|
|
30
|
+
* Telemetry context (operationId, parentId) is managed automatically using IContextStorage.
|
|
31
|
+
* You don't need to pass context around - it's stored and retrieved automatically.
|
|
32
|
+
*
|
|
33
|
+
* Once a `trackRequest` is called, all subsequent telemetry operations (trackEvent,
|
|
34
|
+
* trackException, trackDependencyOperation) within the same async execution context
|
|
35
|
+
* will automatically include the operationId for correlation. This enables full
|
|
36
|
+
* distributed tracing and operation correlation across the entire request tree.
|
|
37
|
+
*/
|
|
38
|
+
export interface ITelemetryService {
|
|
39
|
+
/**
|
|
40
|
+
* Sets the operation ID for telemetry correlation.
|
|
41
|
+
* @param operationId - The operation ID to set, or undefined to clear it
|
|
42
|
+
*
|
|
43
|
+
* @remarks
|
|
44
|
+
* This method allows setting a custom operation ID that will be used by trackRequest
|
|
45
|
+
* if provided. If not set, trackRequest will generate a new operation ID automatically.
|
|
46
|
+
*/
|
|
47
|
+
setOperationId(operationId: string | undefined): void;
|
|
48
|
+
/**
|
|
49
|
+
* Replaces the telemetry provider at runtime.
|
|
50
|
+
* @param provider - The new telemetry provider to use
|
|
51
|
+
*
|
|
52
|
+
* @remarks
|
|
53
|
+
* Useful for switching between providers (e.g. AppInsights vs Console) without
|
|
54
|
+
* recreating the service. Default properties and operation context are preserved.
|
|
55
|
+
*/
|
|
56
|
+
setProvider(provider: ITelemetryProvider): void;
|
|
57
|
+
/**
|
|
58
|
+
* Sets default properties that will be included in all telemetry entries.
|
|
59
|
+
* @param properties - The default properties to set. Pass undefined to clear.
|
|
60
|
+
*
|
|
61
|
+
* @remarks
|
|
62
|
+
* These properties are merged into every telemetry call (trackEvent, trackException,
|
|
63
|
+
* trackRequest, trackDependencyOperation). Per-call properties take precedence
|
|
64
|
+
* over default properties when there are key conflicts.
|
|
65
|
+
*/
|
|
66
|
+
setDefaultProperties(properties?: TelemetryProperties): void;
|
|
67
|
+
/**
|
|
68
|
+
* Track a telemetry event
|
|
69
|
+
* @param name - The name of the event
|
|
70
|
+
* @param properties - Optional properties to attach to the event
|
|
71
|
+
*
|
|
72
|
+
* @remarks
|
|
73
|
+
* If called within a trackRequest block, automatically includes operationId for correlation.
|
|
74
|
+
*/
|
|
75
|
+
trackEvent(name: string, properties?: TelemetryProperties): void;
|
|
76
|
+
/**
|
|
77
|
+
* Track an exception
|
|
78
|
+
* @param error - The error to track
|
|
79
|
+
* @param properties - Optional properties to attach to the exception
|
|
80
|
+
*
|
|
81
|
+
* @remarks
|
|
82
|
+
* If called within a trackRequest block, automatically includes operationId for correlation.
|
|
83
|
+
*/
|
|
84
|
+
trackException(error: Error, properties?: TelemetryProperties): void;
|
|
85
|
+
/**
|
|
86
|
+
* Track a request operation (top-level operation in the dependency tree).
|
|
87
|
+
* Use this for main entry point.
|
|
88
|
+
*
|
|
89
|
+
* @template T The return type of the function
|
|
90
|
+
* @param name The request name (e.g., 'PackSolution')
|
|
91
|
+
* @param fn The async function to execute and track
|
|
92
|
+
* @param properties Base properties to include in telemetry
|
|
93
|
+
* @returns A promise that resolves to the function result
|
|
94
|
+
*
|
|
95
|
+
* @remarks
|
|
96
|
+
* Creates a new operation ID and tracks this as a request in Application Insights.
|
|
97
|
+
* All nested trackDependencyOperation calls will be automatically correlated to this request.
|
|
98
|
+
*/
|
|
99
|
+
trackRequest<T>(name: string, fn: () => Promise<T>, properties?: TelemetryProperties): Promise<T>;
|
|
100
|
+
/**
|
|
101
|
+
* Track a dependency operation (child operation in the dependency tree).
|
|
102
|
+
* Use this for operations that are part of a larger request.
|
|
103
|
+
*
|
|
104
|
+
* @template T The return type of the function
|
|
105
|
+
* @param name The dependency name
|
|
106
|
+
* @param type The dependency type
|
|
107
|
+
* @param fn The async function to execute and track
|
|
108
|
+
* @param properties Base properties to include in telemetry
|
|
109
|
+
* @returns A promise that resolves to the function result
|
|
110
|
+
*
|
|
111
|
+
* @remarks
|
|
112
|
+
* Tracks this operation as a dependency in Application Insights, automatically correlated
|
|
113
|
+
* to the parent request using the context from IContextStorage.
|
|
114
|
+
*/
|
|
115
|
+
trackDependencyOperation<T>(name: string, type: string, fn: () => Promise<T>, properties?: TelemetryProperties): Promise<T>;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* TelemetryService implementation that manages context storage and orchestrates telemetry operations.
|
|
119
|
+
* This service handles all common logic:
|
|
120
|
+
* - Context creation and correlation (operationId, id, parentId)
|
|
121
|
+
* - Duration measurement
|
|
122
|
+
* - Error handling and success/failure tracking
|
|
123
|
+
* - Context propagation via storage
|
|
124
|
+
*
|
|
125
|
+
* ITelemetryProvider implementations are simple adapters that receive pre-measured data.
|
|
126
|
+
*/
|
|
127
|
+
export declare class TelemetryService implements ITelemetryService {
|
|
128
|
+
private telemetryProvider;
|
|
129
|
+
private readonly contextStorage;
|
|
130
|
+
private operationId?;
|
|
131
|
+
private defaultProperties?;
|
|
132
|
+
constructor(telemetryProvider: ITelemetryProvider, contextStorage: IContextStorage<TelemetryContext>);
|
|
133
|
+
/**
|
|
134
|
+
* Sets the operation ID for telemetry correlation.
|
|
135
|
+
* @param operationId - The operation ID to set, or undefined to clear it
|
|
136
|
+
*/
|
|
137
|
+
setOperationId(operationId: string | undefined): void;
|
|
138
|
+
setProvider(provider: ITelemetryProvider): void;
|
|
139
|
+
setDefaultProperties(properties?: TelemetryProperties): void;
|
|
140
|
+
trackEvent(name: string, properties?: TelemetryProperties): void;
|
|
141
|
+
trackException(error: Error, properties?: TelemetryProperties): void;
|
|
142
|
+
trackRequest<T>(name: string, fn: () => Promise<T>, properties?: TelemetryProperties): Promise<T>;
|
|
143
|
+
trackDependencyOperation<T>(name: string, type: string, fn: () => Promise<T>, properties?: TelemetryProperties): Promise<T>;
|
|
144
|
+
/**
|
|
145
|
+
* Gets the current telemetry context from the context storage.
|
|
146
|
+
* Returns undefined if no context is available (not within a trackRequest block).
|
|
147
|
+
*/
|
|
148
|
+
private getCurrentContext;
|
|
149
|
+
/**
|
|
150
|
+
* Enriches properties with context information (operationId, parentId, id)
|
|
151
|
+
*/
|
|
152
|
+
private enrichPropertiesWithContext;
|
|
153
|
+
/**
|
|
154
|
+
* Generate a unique ID for telemetry correlation
|
|
155
|
+
*/
|
|
156
|
+
private generateId;
|
|
157
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-module bridge for packager factory resolution.
|
|
3
|
+
*/
|
|
4
|
+
export type PackagerFactoryProvider = (verb: string) => Promise<void>;
|
|
5
|
+
export declare function setPackagerFactoryProvider(provider: PackagerFactoryProvider): void;
|
|
6
|
+
export declare function ensurePackagerFactory(verb: string): Promise<void>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import type { TelemetryProperties } from "./telemetry/telemetry-service.js";
|
|
3
|
+
export interface CommandContext {
|
|
4
|
+
exit: (code: number) => void;
|
|
5
|
+
/** AbortSignal wired to SIGINT/SIGTERM. Pass to `pollUntil({ signal })` for graceful cancellation. */
|
|
6
|
+
pollSignal?: AbortSignal;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Default CommandContext for tool packages that sets process.exitCode
|
|
10
|
+
* instead of calling process.exit().
|
|
11
|
+
*
|
|
12
|
+
* `pollSignal` is resolved from globalThis so it works across bundle
|
|
13
|
+
* boundaries — the CLI sets it once, all tool bundles see the same signal.
|
|
14
|
+
*/
|
|
15
|
+
export declare const processContext: CommandContext;
|
|
16
|
+
/**
|
|
17
|
+
* Wire an AbortSignal into the process-wide shared slot so all bundles
|
|
18
|
+
* of `@uipath/common` see it via `processContext.pollSignal`.
|
|
19
|
+
*
|
|
20
|
+
* Call once at CLI startup after creating the poll abort controller.
|
|
21
|
+
*/
|
|
22
|
+
export declare function setProcessContextPollSignal(signal: AbortSignal): void;
|
|
23
|
+
/**
|
|
24
|
+
* Derives a telemetry event name from the command hierarchy.
|
|
25
|
+
* Walks up the parent chain, collects command names, strips the root,
|
|
26
|
+
* and always prepends "uip" so all events share a uniform prefix.
|
|
27
|
+
* Names are lowercase dot-separated, mirroring the CLI invocation.
|
|
28
|
+
*
|
|
29
|
+
* Example: `uip maestro processes list` → `"uip.maestro.processes.list"`
|
|
30
|
+
* Example: `uip login` → `"uip.login"`
|
|
31
|
+
*/
|
|
32
|
+
declare function deriveCommandPath(cmd: Command): string;
|
|
33
|
+
declare module "commander" {
|
|
34
|
+
interface Command {
|
|
35
|
+
trackedAction(context: CommandContext, fn: (...args: any[]) => Promise<void>, properties?: TelemetryProperties | ((...args: any[]) => TelemetryProperties)): this;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export { deriveCommandPath };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uipath/common",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Common infrastructure needed by
|
|
3
|
+
"version": "0.9.1",
|
|
4
|
+
"description": "Common infrastructure needed by uip tools.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/UiPath/cli.git",
|
|
@@ -13,7 +13,14 @@
|
|
|
13
13
|
"type": "module",
|
|
14
14
|
"main": "./dist/index.js",
|
|
15
15
|
"exports": {
|
|
16
|
-
".":
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"default": "./dist/index.js"
|
|
19
|
+
},
|
|
20
|
+
"./telemetry": {
|
|
21
|
+
"types": "./dist/telemetry/index.d.ts",
|
|
22
|
+
"default": "./dist/telemetry/index.js"
|
|
23
|
+
}
|
|
17
24
|
},
|
|
18
25
|
"files": [
|
|
19
26
|
"dist"
|
|
@@ -24,7 +31,7 @@
|
|
|
24
31
|
"vlad-uipath"
|
|
25
32
|
],
|
|
26
33
|
"scripts": {
|
|
27
|
-
"build": "bun build ./src/index.ts --outdir dist --format esm --target node --external applicationinsights",
|
|
34
|
+
"build": "bun build ./src/index.ts --outdir dist --format esm --target node --external applicationinsights && bun build ./src/telemetry/index.ts --outfile dist/telemetry/index.js --format esm --target browser && tsc -p tsconfig.build.json --noCheck",
|
|
28
35
|
"typecheck": "tsc --noEmit",
|
|
29
36
|
"lint": "biome check .",
|
|
30
37
|
"test": "vitest run",
|
|
@@ -34,10 +41,11 @@
|
|
|
34
41
|
"@jmespath-community/jmespath": "^1.3.0",
|
|
35
42
|
"@types/js-yaml": "^4.0.9",
|
|
36
43
|
"@types/node": "^25.5.0",
|
|
37
|
-
"@uipath/
|
|
44
|
+
"@uipath/filesystem": "0.9.1",
|
|
38
45
|
"commander": "^14.0.3",
|
|
39
46
|
"js-yaml": "^4.1.0",
|
|
40
47
|
"jsonpath-plus": "^10.4.0",
|
|
41
48
|
"typescript": "^5"
|
|
42
|
-
}
|
|
49
|
+
},
|
|
50
|
+
"gitHead": "e8da2857e37a9495c4907cd39f47c9d6ed1a5566"
|
|
43
51
|
}
|