@uipath/common 1.0.4 → 1.195.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.
@@ -0,0 +1,19 @@
1
+ import { type Command, Option } from "commander";
2
+ export interface OptionAliasResult<T> {
3
+ value: T | undefined;
4
+ usedDeprecated: boolean;
5
+ error?: {
6
+ message: string;
7
+ instructions: string;
8
+ };
9
+ }
10
+ export declare function resolveDeprecatedOptionAlias<T>({ preferredValue, deprecatedValue, preferredFlag, deprecatedFlag, }: {
11
+ preferredValue: T | undefined;
12
+ deprecatedValue: T | undefined;
13
+ preferredFlag: string;
14
+ deprecatedFlag: string;
15
+ }): OptionAliasResult<T>;
16
+ export declare function warnDeprecatedOptionAlias(deprecatedFlag: string, preferredFlag: string): void;
17
+ export declare function createHiddenDeprecatedTenantOption(flags?: string): Option;
18
+ export declare function addHiddenDeprecatedTenantOption<T extends Command>(command: T, flags?: string): T;
19
+ export declare function warnDeprecatedTenantOption(tenant?: string): void;
@@ -19,8 +19,7 @@
19
19
  *
20
20
  * The `path` argument on {@link buildOrchestratorUrl} is left as a string
21
21
  * **without** automatic encoding so callers can include OData filter syntax
22
- * and existing URL-encoded query strings; this matches the existing inline
23
- * pattern used in `solution-tool/src/services/apps-binding-sync.ts`.
22
+ * and existing URL-encoded query strings.
24
23
  *
25
24
  * For the Studio Web URL pattern (`/{org}/studio_/...`) — which has no
26
25
  * tenant segment by design — see `packages/maestro-sdk` instead. That
@@ -1,5 +1,7 @@
1
1
  export { createPollAbortController } from "./abort-controller";
2
2
  export { msToDuration } from "./format-utils";
3
+ export type { PollFailureMapped, PollFailureReason, } from "./poll-failure-mapping";
4
+ export { mapPollFailure } from "./poll-failure-mapping";
3
5
  export { pollUntil } from "./poll-until";
4
6
  export { isFailureStatus, isSuccessStatus, isTerminalStatus, } from "./terminal-statuses";
5
7
  export type { BackoffConfig, OnErrorCallback, PollContext, PollUntilOptions, PollUntilResult, } from "./types";
@@ -0,0 +1,21 @@
1
+ import { PollOutcome } from "./types";
2
+ /** Canonical taxonomy for poll-loop failures; library callers branch on this without parsing the message. */
3
+ export type PollFailureReason = "poll_timeout" | "poll_failed" | "poll_aborted";
4
+ export interface PollFailureMapped {
5
+ reason: PollFailureReason;
6
+ /** `${label} polling {timed out | failed: <err> | was interrupted | was aborted}`. */
7
+ message: string;
8
+ /** `2` for Timeout, `1` otherwise. */
9
+ exitCode: number;
10
+ }
11
+ /**
12
+ * Maps a non-completed `pollUntil` result to `{ reason, message, exitCode }`.
13
+ * `label` prefixes the message (e.g. `"Deployment"` → `"Deployment polling timed out"`).
14
+ * Caller must check the outcome is non-completed before invoking.
15
+ */
16
+ export declare function mapPollFailure(pollResult: {
17
+ outcome: PollOutcome;
18
+ error?: {
19
+ message?: string;
20
+ };
21
+ }, label: string): PollFailureMapped;
@@ -0,0 +1,12 @@
1
+ export interface SdkUserAgentPackageInfo {
2
+ name: string;
3
+ version: string;
4
+ }
5
+ export type SdkHttpHeaders = Record<string, string>;
6
+ export declare function getSdkUserAgentToken(pkg: SdkUserAgentPackageInfo): string;
7
+ export declare function setSdkUserAgentHostToken(token: string | undefined): void;
8
+ export declare function addSdkUserAgentHeader(headers: SdkHttpHeaders | undefined, userAgent: string): SdkHttpHeaders;
9
+ export declare function withSdkUserAgentHeader(headers: unknown, userAgent: string): unknown;
10
+ export declare function installSdkUserAgentHeader(BaseApiClass: {
11
+ prototype: unknown;
12
+ }, userAgent: string): void;
@@ -0,0 +1,143 @@
1
+ // src/singleton.ts
2
+ var PREFIX = "@uipath/common/";
3
+ var _g = globalThis;
4
+ function singleton(ctorOrName) {
5
+ const name = typeof ctorOrName === "string" ? ctorOrName : ctorOrName.name;
6
+ const key = Symbol.for(PREFIX + name);
7
+ return {
8
+ get(fallback) {
9
+ return _g[key] ?? fallback;
10
+ },
11
+ set(value) {
12
+ _g[key] = value;
13
+ },
14
+ clear() {
15
+ delete _g[key];
16
+ },
17
+ getOrInit(factory, guard) {
18
+ const existing = _g[key];
19
+ if (existing != null && typeof existing === "object") {
20
+ if (!guard || guard(existing)) {
21
+ return existing;
22
+ }
23
+ }
24
+ const instance = factory();
25
+ _g[key] = instance;
26
+ return instance;
27
+ }
28
+ };
29
+ }
30
+
31
+ // src/sdk-user-agent.ts
32
+ var USER_AGENT_HEADER = "User-Agent";
33
+ var sdkUserAgentHostToken = singleton("SdkUserAgentHostToken");
34
+ function userAgentPatchKey(userAgent) {
35
+ return Symbol.for(`@uipath/common/sdk-user-agent/${userAgent}`);
36
+ }
37
+ function splitUserAgentTokens(value) {
38
+ return value?.trim().split(/\s+/).filter(Boolean) ?? [];
39
+ }
40
+ function appendUserAgentToken(value, userAgent) {
41
+ const tokens = splitUserAgentTokens(value);
42
+ const seen = new Set(tokens);
43
+ for (const token of splitUserAgentTokens(userAgent)) {
44
+ if (!seen.has(token)) {
45
+ tokens.push(token);
46
+ seen.add(token);
47
+ }
48
+ }
49
+ return tokens.join(" ");
50
+ }
51
+ function getEffectiveUserAgent(userAgent) {
52
+ return appendUserAgentToken(sdkUserAgentHostToken.get(), userAgent);
53
+ }
54
+ function isHeadersLike(headers) {
55
+ return typeof headers === "object" && headers !== null && "get" in headers && typeof headers.get === "function" && "set" in headers && typeof headers.set === "function";
56
+ }
57
+ function getSdkUserAgentToken(pkg) {
58
+ const packageName = pkg.name.replace(/^@uipath\//, "");
59
+ return getEffectiveUserAgent(`${packageName}/${pkg.version}`);
60
+ }
61
+ function setSdkUserAgentHostToken(token) {
62
+ if (token === undefined) {
63
+ sdkUserAgentHostToken.clear();
64
+ return;
65
+ }
66
+ sdkUserAgentHostToken.set(token);
67
+ }
68
+ function addSdkUserAgentHeader(headers, userAgent) {
69
+ const result = { ...headers ?? {} };
70
+ const effectiveUserAgent = getEffectiveUserAgent(userAgent);
71
+ const headerName = Object.keys(result).find((key) => key.toLowerCase() === USER_AGENT_HEADER.toLowerCase());
72
+ if (headerName) {
73
+ result[headerName] = appendUserAgentToken(result[headerName], effectiveUserAgent);
74
+ } else {
75
+ result[USER_AGENT_HEADER] = effectiveUserAgent;
76
+ }
77
+ return result;
78
+ }
79
+ function withSdkUserAgentHeader(headers, userAgent) {
80
+ const effectiveUserAgent = getEffectiveUserAgent(userAgent);
81
+ if (isHeadersLike(headers)) {
82
+ headers.set(USER_AGENT_HEADER, appendUserAgentToken(headers.get(USER_AGENT_HEADER), effectiveUserAgent));
83
+ return headers;
84
+ }
85
+ if (Array.isArray(headers)) {
86
+ const result = headers.map((entry) => {
87
+ const [key, value] = entry;
88
+ return [key, value];
89
+ });
90
+ const headerIndex = result.findIndex(([key]) => key.toLowerCase() === USER_AGENT_HEADER.toLowerCase());
91
+ if (headerIndex >= 0) {
92
+ const [key, value] = result[headerIndex];
93
+ result[headerIndex] = [
94
+ key,
95
+ appendUserAgentToken(value, effectiveUserAgent)
96
+ ];
97
+ } else {
98
+ result.push([USER_AGENT_HEADER, effectiveUserAgent]);
99
+ }
100
+ return result;
101
+ }
102
+ return addSdkUserAgentHeader(typeof headers === "object" && headers !== null ? { ...headers } : {}, effectiveUserAgent);
103
+ }
104
+ function withUserAgentInitOverride(initOverrides, userAgent) {
105
+ return async (requestContext) => {
106
+ const initWithUserAgent = {
107
+ ...requestContext.init,
108
+ headers: withSdkUserAgentHeader(requestContext.init.headers, userAgent)
109
+ };
110
+ const override = typeof initOverrides === "function" ? await initOverrides({
111
+ ...requestContext,
112
+ init: initWithUserAgent
113
+ }) : initOverrides;
114
+ return {
115
+ ...override ?? {},
116
+ headers: withSdkUserAgentHeader(override?.headers ?? initWithUserAgent.headers, userAgent)
117
+ };
118
+ };
119
+ }
120
+ function installSdkUserAgentHeader(BaseApiClass, userAgent) {
121
+ const prototype = BaseApiClass.prototype;
122
+ const patchKey = userAgentPatchKey(userAgent);
123
+ if (prototype[patchKey]) {
124
+ return;
125
+ }
126
+ if (typeof prototype.request !== "function") {
127
+ throw new Error("Generated BaseAPI request function not found.");
128
+ }
129
+ const originalRequest = prototype.request;
130
+ prototype.request = function requestWithUserAgent(context, initOverrides) {
131
+ return originalRequest.call(this, context, withUserAgentInitOverride(initOverrides, userAgent));
132
+ };
133
+ Object.defineProperty(prototype, patchKey, {
134
+ value: true
135
+ });
136
+ }
137
+ export {
138
+ withSdkUserAgentHeader,
139
+ setSdkUserAgentHostToken,
140
+ installSdkUserAgentHeader,
141
+ getSdkUserAgentToken,
142
+ addSdkUserAgentHeader
143
+ };
package/package.json CHANGED
@@ -1,51 +1,45 @@
1
1
  {
2
- "name": "@uipath/common",
3
- "version": "1.0.4",
4
- "description": "Common infrastructure needed by uip tools.",
5
- "repository": {
6
- "type": "git",
7
- "url": "https://github.com/UiPath/cli.git",
8
- "directory": "packages/common"
2
+ "name": "@uipath/common",
3
+ "license": "MIT",
4
+ "version": "1.195.0",
5
+ "description": "Common infrastructure needed by uip tools.",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/UiPath/cli.git",
9
+ "directory": "packages/common"
10
+ },
11
+ "publishConfig": {
12
+ "registry": "https://registry.npmjs.org/"
13
+ },
14
+ "type": "module",
15
+ "main": "./dist/index.js",
16
+ "exports": {
17
+ ".": {
18
+ "browser": {
19
+ "types": "./dist/index.browser.d.ts",
20
+ "default": "./dist/index.browser.js"
21
+ },
22
+ "default": {
23
+ "types": "./dist/index.d.ts",
24
+ "default": "./dist/index.js"
25
+ }
9
26
  },
10
- "publishConfig": {
11
- "registry": "https://registry.npmjs.org/"
27
+ "./sdk-user-agent": {
28
+ "types": "./dist/sdk-user-agent.d.ts",
29
+ "default": "./dist/sdk-user-agent.js"
12
30
  },
13
- "type": "module",
14
- "main": "./dist/index.js",
15
- "exports": {
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
- }
24
- },
25
- "files": [
26
- "dist"
27
- ],
28
- "maintainers": [
29
- "aoltean16",
30
- "mihaigirleanu",
31
- "vlad-uipath"
32
- ],
33
- "scripts": {
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",
35
- "typecheck": "tsc --noEmit",
36
- "lint": "biome check .",
37
- "test": "vitest run",
38
- "test:coverage": "vitest run --coverage"
39
- },
40
- "devDependencies": {
41
- "@jmespath-community/jmespath": "^1.3.0",
42
- "@types/js-yaml": "^4.0.9",
43
- "@types/node": "^25.5.2",
44
- "@uipath/filesystem": "1.0.4",
45
- "commander": "^14.0.3",
46
- "js-yaml": "^4.1.0",
47
- "jsonpath-plus": "^10.4.0",
48
- "typescript": "^6.0.2"
49
- },
50
- "gitHead": "e496ee5b65951c8047259ab50d7d6a284eea58a9"
31
+ "./telemetry": {
32
+ "types": "./dist/telemetry/index.d.ts",
33
+ "default": "./dist/telemetry/index.js"
34
+ }
35
+ },
36
+ "files": [
37
+ "dist"
38
+ ],
39
+ "maintainers": [
40
+ "aoltean16",
41
+ "mihaigirleanu",
42
+ "vlad-uipath"
43
+ ],
44
+ "gitHead": "65fabb84552758b2710d8ca68470e70a9b1d19bc"
51
45
  }