@uipath/common 1.0.4 → 1.1.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;
@@ -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,6 +1,6 @@
1
1
  {
2
2
  "name": "@uipath/common",
3
- "version": "1.0.4",
3
+ "version": "1.1.0",
4
4
  "description": "Common infrastructure needed by uip tools.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,8 +14,14 @@
14
14
  "main": "./dist/index.js",
15
15
  "exports": {
16
16
  ".": {
17
- "types": "./dist/index.d.ts",
18
- "default": "./dist/index.js"
17
+ "browser": {
18
+ "types": "./dist/index.browser.d.ts",
19
+ "default": "./dist/index.browser.js"
20
+ },
21
+ "default": {
22
+ "types": "./dist/index.d.ts",
23
+ "default": "./dist/index.js"
24
+ }
19
25
  },
20
26
  "./telemetry": {
21
27
  "types": "./dist/telemetry/index.d.ts",
@@ -30,22 +36,15 @@
30
36
  "mihaigirleanu",
31
37
  "vlad-uipath"
32
38
  ],
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
39
  "devDependencies": {
41
40
  "@jmespath-community/jmespath": "^1.3.0",
42
41
  "@types/js-yaml": "^4.0.9",
43
42
  "@types/node": "^25.5.2",
44
- "@uipath/filesystem": "1.0.4",
43
+ "@uipath/filesystem": "1.1.0",
45
44
  "commander": "^14.0.3",
46
45
  "js-yaml": "^4.1.0",
47
46
  "jsonpath-plus": "^10.4.0",
48
47
  "typescript": "^6.0.2"
49
48
  },
50
- "gitHead": "e496ee5b65951c8047259ab50d7d6a284eea58a9"
49
+ "gitHead": "06e8c8f566df4b87da4a008635483c62f64f33f0"
51
50
  }