@uipath/uipath-typescript 1.3.8 → 1.3.10

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 (41) hide show
  1. package/dist/assets/index.cjs +44 -276
  2. package/dist/assets/index.mjs +44 -276
  3. package/dist/attachments/index.cjs +42 -273
  4. package/dist/attachments/index.mjs +42 -273
  5. package/dist/buckets/index.cjs +195 -276
  6. package/dist/buckets/index.d.ts +213 -1
  7. package/dist/buckets/index.mjs +195 -276
  8. package/dist/cases/index.cjs +427 -343
  9. package/dist/cases/index.d.ts +534 -2
  10. package/dist/cases/index.mjs +428 -344
  11. package/dist/conversational-agent/index.cjs +90 -287
  12. package/dist/conversational-agent/index.d.ts +62 -12
  13. package/dist/conversational-agent/index.mjs +90 -288
  14. package/dist/core/index.cjs +39 -289
  15. package/dist/core/index.d.ts +9 -98
  16. package/dist/core/index.mjs +40 -275
  17. package/dist/document-understanding/index.cjs +18 -1
  18. package/dist/document-understanding/index.d.ts +636 -610
  19. package/dist/document-understanding/index.mjs +18 -1
  20. package/dist/entities/index.cjs +251 -277
  21. package/dist/entities/index.d.ts +305 -2
  22. package/dist/entities/index.mjs +251 -277
  23. package/dist/feedback/index.cjs +42 -274
  24. package/dist/feedback/index.mjs +42 -274
  25. package/dist/index.cjs +998 -351
  26. package/dist/index.d.ts +2159 -762
  27. package/dist/index.mjs +998 -337
  28. package/dist/index.umd.js +1208 -237
  29. package/dist/jobs/index.cjs +44 -276
  30. package/dist/jobs/index.mjs +44 -276
  31. package/dist/maestro-processes/index.cjs +1761 -1717
  32. package/dist/maestro-processes/index.d.ts +430 -2
  33. package/dist/maestro-processes/index.mjs +1762 -1718
  34. package/dist/processes/index.cjs +72 -305
  35. package/dist/processes/index.d.ts +76 -26
  36. package/dist/processes/index.mjs +72 -305
  37. package/dist/queues/index.cjs +44 -276
  38. package/dist/queues/index.mjs +44 -276
  39. package/dist/tasks/index.cjs +44 -276
  40. package/dist/tasks/index.mjs +44 -276
  41. package/package.json +8 -10
@@ -1,4 +1,4 @@
1
- import { BatchLogRecordProcessor, LoggerProvider } from '@opentelemetry/sdk-logs';
1
+ import { getOrCreateClient, createTrack, createTrackEvent } from '@uipath/core-telemetry';
2
2
 
3
3
  /******************************************************************************
4
4
  Copyright (c) Microsoft Corporation.
@@ -611,14 +611,25 @@ class ApiClient {
611
611
  if (!text) {
612
612
  return undefined;
613
613
  }
614
- return JSON.parse(text);
614
+ try {
615
+ return JSON.parse(text);
616
+ }
617
+ catch (error) {
618
+ if (error instanceof SyntaxError) {
619
+ throw new ServerError({
620
+ message: `Server returned non-JSON response (${response.status} ${response.url}): ${error.message}`,
621
+ statusCode: response.status,
622
+ });
623
+ }
624
+ throw error;
625
+ }
615
626
  }
616
627
  catch (error) {
617
628
  // If it's already one of our errors, re-throw it
618
629
  if (error.type && error.type.includes('Error')) {
619
630
  throw error;
620
631
  }
621
- // Otherwise, it's likely a network error
632
+ // Otherwise, it's a genuine network/fetch failure
622
633
  throw ErrorFactory.createNetworkError(error);
623
634
  }
624
635
  }
@@ -1219,9 +1230,9 @@ class PaginationHelpers {
1219
1230
  * @returns Promise resolving to a paginated result
1220
1231
  */
1221
1232
  static async getAllPaginated(params) {
1222
- const { serviceAccess, getEndpoint, folderId, paginationParams, additionalParams, transformFn, method = HTTP_METHODS.GET, options = {} } = params;
1233
+ const { serviceAccess, getEndpoint, folderId, headers: providedHeaders, paginationParams, additionalParams, transformFn, method = HTTP_METHODS.GET, options = {} } = params;
1223
1234
  const endpoint = getEndpoint(folderId);
1224
- const headers = folderId ? createHeaders({ [FOLDER_ID]: folderId }) : {};
1235
+ const headers = providedHeaders ?? (folderId ? createHeaders({ [FOLDER_ID]: folderId }) : {});
1225
1236
  const paginatedResponse = await serviceAccess.requestWithPagination(method, endpoint, paginationParams, {
1226
1237
  headers,
1227
1238
  params: additionalParams,
@@ -1249,13 +1260,13 @@ class PaginationHelpers {
1249
1260
  * @returns Promise resolving to an object with data and totalCount
1250
1261
  */
1251
1262
  static async getAllNonPaginated(params) {
1252
- const { serviceAccess, getAllEndpoint, getByFolderEndpoint, folderId, additionalParams, transformFn, method = HTTP_METHODS.GET, options = {} } = params;
1263
+ const { serviceAccess, getAllEndpoint, getByFolderEndpoint, folderId, headers: providedHeaders, additionalParams, transformFn, method = HTTP_METHODS.GET, options = {} } = params;
1253
1264
  // Set default field names
1254
1265
  const itemsField = options.itemsField || DEFAULT_ITEMS_FIELD;
1255
1266
  const totalCountField = options.totalCountField || DEFAULT_TOTAL_COUNT_FIELD;
1256
1267
  // Determine endpoint and headers based on folderId
1257
1268
  const endpoint = folderId ? getByFolderEndpoint : getAllEndpoint;
1258
- const headers = folderId ? createHeaders({ [FOLDER_ID]: folderId }) : {};
1269
+ const headers = providedHeaders ?? (folderId ? createHeaders({ [FOLDER_ID]: folderId }) : {});
1259
1270
  // Make the API call based on method
1260
1271
  let response;
1261
1272
  if (method === HTTP_METHODS.POST) {
@@ -1314,6 +1325,7 @@ class PaginationHelpers {
1314
1325
  serviceAccess: config.serviceAccess,
1315
1326
  getEndpoint: config.getEndpoint,
1316
1327
  folderId,
1328
+ headers: config.headers,
1317
1329
  paginationParams: cursor ? { cursor, pageSize } : jumpToPage ? { jumpToPage, pageSize } : { pageSize },
1318
1330
  additionalParams: prefixedOptions,
1319
1331
  transformFn: config.transformFn,
@@ -1331,6 +1343,7 @@ class PaginationHelpers {
1331
1343
  getAllEndpoint: config.getEndpoint(),
1332
1344
  getByFolderEndpoint: byFolderEndpoint,
1333
1345
  folderId,
1346
+ headers: config.headers,
1334
1347
  additionalParams: prefixedOptions,
1335
1348
  transformFn: config.transformFn,
1336
1349
  method: config.method,
@@ -1883,278 +1896,33 @@ const AssetMap = {
1883
1896
  };
1884
1897
 
1885
1898
  /**
1886
- * SDK Telemetry constants
1887
- */
1888
- // Connection string placeholder that will be replaced during build
1889
- const CONNECTION_STRING = "InstrumentationKey=a6efa11d-1feb-4508-9738-e13e12dcae5e;IngestionEndpoint=https://westeurope-5.in.applicationinsights.azure.com/;LiveEndpoint=https://westeurope.livediagnostics.monitor.azure.com/;ApplicationId=7c58eb1c-9581-4ba6-839e-11725848a037";
1890
- // SDK Version placeholder
1891
- const SDK_VERSION = "1.3.8";
1892
- const VERSION = "Version";
1893
- const SERVICE = "Service";
1894
- const CLOUD_ORGANIZATION_NAME = "CloudOrganizationName";
1895
- const CLOUD_TENANT_NAME = "CloudTenantName";
1896
- const CLOUD_URL = "CloudUrl";
1897
- const CLOUD_CLIENT_ID = "CloudClientId";
1898
- const CLOUD_REDIRECT_URI = "CloudRedirectUri";
1899
- const APP_NAME = "ApplicationName";
1900
- const CLOUD_ROLE_NAME = "uipath-ts-sdk";
1901
- // Service and logger names
1902
- const SDK_SERVICE_NAME = "UiPath.TypeScript.Sdk";
1903
- const SDK_LOGGER_NAME = "uipath-ts-sdk-telemetry";
1904
- // Event names
1905
- const SDK_RUN_EVENT = "Sdk.Run";
1906
- // Default value for unknown/empty attributes
1907
- const UNKNOWN = "";
1908
-
1909
- /**
1910
- * Log exporter that sends ALL logs as Application Insights custom events
1911
- */
1912
- class ApplicationInsightsEventExporter {
1913
- constructor(connectionString) {
1914
- this.connectionString = connectionString;
1915
- }
1916
- export(logs, resultCallback) {
1917
- try {
1918
- logs.forEach(logRecord => {
1919
- this.sendAsCustomEvent(logRecord);
1920
- });
1921
- resultCallback({ code: 0 });
1922
- }
1923
- catch (error) {
1924
- console.debug('Failed to export logs to Application Insights:', error);
1925
- resultCallback({ code: 2, error });
1926
- }
1927
- }
1928
- shutdown() {
1929
- return Promise.resolve();
1930
- }
1931
- sendAsCustomEvent(logRecord) {
1932
- // Get event name from body or attributes
1933
- const eventName = logRecord.body || SDK_RUN_EVENT;
1934
- const payload = {
1935
- name: 'Microsoft.ApplicationInsights.Event',
1936
- time: new Date().toISOString(),
1937
- iKey: this.extractInstrumentationKey(),
1938
- data: {
1939
- baseType: 'EventData',
1940
- baseData: {
1941
- ver: 2,
1942
- name: eventName,
1943
- properties: this.convertAttributesToProperties(logRecord.attributes || {})
1944
- }
1945
- },
1946
- tags: {
1947
- 'ai.cloud.role': CLOUD_ROLE_NAME,
1948
- 'ai.cloud.roleInstance': SDK_VERSION
1949
- }
1950
- };
1951
- this.sendToApplicationInsights(payload);
1952
- }
1953
- extractInstrumentationKey() {
1954
- const match = this.connectionString.match(/InstrumentationKey=([^;]+)/);
1955
- return match ? match[1] : '';
1956
- }
1957
- convertAttributesToProperties(attributes) {
1958
- const properties = {};
1959
- Object.entries(attributes || {}).forEach(([key, value]) => {
1960
- properties[key] = String(value);
1961
- });
1962
- return properties;
1963
- }
1964
- async sendToApplicationInsights(payload) {
1965
- try {
1966
- const ingestionEndpoint = this.extractIngestionEndpoint();
1967
- if (!ingestionEndpoint) {
1968
- console.debug('No ingestion endpoint found in connection string');
1969
- return;
1970
- }
1971
- const url = `${ingestionEndpoint}/v2/track`;
1972
- const response = await fetch(url, {
1973
- method: 'POST',
1974
- headers: {
1975
- 'Content-Type': 'application/json',
1976
- },
1977
- body: JSON.stringify(payload)
1978
- });
1979
- if (!response.ok) {
1980
- console.debug(`Failed to send event telemetry: ${response.status} ${response.statusText}`);
1981
- }
1982
- }
1983
- catch (error) {
1984
- console.debug('Error sending event telemetry to Application Insights:', error);
1985
- }
1986
- }
1987
- extractIngestionEndpoint() {
1988
- const match = this.connectionString.match(/IngestionEndpoint=([^;]+)/);
1989
- return match ? match[1] : '';
1990
- }
1991
- }
1992
- /**
1993
- * Singleton telemetry client
1994
- */
1995
- class TelemetryClient {
1996
- constructor() {
1997
- this.isInitialized = false;
1998
- }
1999
- static getInstance() {
2000
- if (!TelemetryClient.instance) {
2001
- TelemetryClient.instance = new TelemetryClient();
2002
- }
2003
- return TelemetryClient.instance;
2004
- }
2005
- /**
2006
- * Initialize telemetry
2007
- */
2008
- initialize(config) {
2009
- if (this.isInitialized) {
2010
- return;
2011
- }
2012
- this.isInitialized = true;
2013
- if (config) {
2014
- this.telemetryContext = config;
2015
- }
2016
- try {
2017
- const connectionString = this.getConnectionString();
2018
- if (!connectionString) {
2019
- return;
2020
- }
2021
- this.setupTelemetryProvider(connectionString);
2022
- }
2023
- catch (error) {
2024
- // Silent failure - telemetry errors shouldn't break functionality
2025
- console.debug('Failed to initialize OpenTelemetry:', error);
2026
- }
2027
- }
2028
- getConnectionString() {
2029
- const connectionString = CONNECTION_STRING;
2030
- return connectionString;
2031
- }
2032
- setupTelemetryProvider(connectionString) {
2033
- const exporter = new ApplicationInsightsEventExporter(connectionString);
2034
- const processor = new BatchLogRecordProcessor(exporter);
2035
- this.logProvider = new LoggerProvider({
2036
- processors: [processor]
2037
- });
2038
- this.logger = this.logProvider.getLogger(SDK_LOGGER_NAME);
2039
- }
2040
- /**
2041
- * Track a telemetry event
2042
- */
2043
- track(eventName, name, extraAttributes = {}) {
2044
- try {
2045
- // Skip if logger not initialized
2046
- if (!this.logger) {
2047
- return;
2048
- }
2049
- const finalDisplayName = name || eventName;
2050
- const attributes = this.getEnrichedAttributes(extraAttributes, eventName);
2051
- // Emit as log
2052
- this.logger.emit({
2053
- body: finalDisplayName,
2054
- attributes: attributes,
2055
- timestamp: Date.now(),
2056
- });
2057
- }
2058
- catch (error) {
2059
- // Silent failure
2060
- console.debug('Failed to track telemetry event:', error);
2061
- }
2062
- }
2063
- /**
2064
- * Get enriched attributes for telemetry events
2065
- */
2066
- getEnrichedAttributes(extraAttributes, eventName) {
2067
- const attributes = {
2068
- [APP_NAME]: SDK_SERVICE_NAME,
2069
- [VERSION]: SDK_VERSION,
2070
- [SERVICE]: eventName,
2071
- [CLOUD_URL]: this.createCloudUrl(),
2072
- [CLOUD_ORGANIZATION_NAME]: this.telemetryContext?.orgName || UNKNOWN,
2073
- [CLOUD_TENANT_NAME]: this.telemetryContext?.tenantName || UNKNOWN,
2074
- [CLOUD_REDIRECT_URI]: this.telemetryContext?.redirectUri || UNKNOWN,
2075
- [CLOUD_CLIENT_ID]: this.telemetryContext?.clientId || UNKNOWN,
2076
- ...extraAttributes,
2077
- };
2078
- return attributes;
2079
- }
2080
- /**
2081
- * Create cloud URL from base URL, organization ID, and tenant ID
2082
- */
2083
- createCloudUrl() {
2084
- const baseUrl = this.telemetryContext?.baseUrl;
2085
- const orgId = this.telemetryContext?.orgName;
2086
- const tenantId = this.telemetryContext?.tenantName;
2087
- if (!baseUrl || !orgId || !tenantId) {
2088
- return UNKNOWN;
2089
- }
2090
- return `${baseUrl}/${orgId}/${tenantId}`;
2091
- }
2092
- }
2093
- // Export singleton instance
2094
- const telemetryClient = TelemetryClient.getInstance();
1899
+ * SDK Telemetry constants.
1900
+ *
1901
+ * Only the SDK's identity (version, service name, role name, …) lives
1902
+ * here. The Application Insights connection string is injected into
1903
+ * `@uipath/core-telemetry` itself at publish time, and the generic attribute
1904
+ * keys (`Version`, `Service`, `CloudOrganizationName`, …) are owned by
1905
+ * `@uipath/core-telemetry` and consumed there — they are not part of the
1906
+ * SDK's public API.
1907
+ */
1908
+ /** SDK version placeholder — patched by the SDK publish workflow. */
1909
+ const CLOUD_ROLE_NAME = 'uipath-ts-sdk';
2095
1910
 
2096
1911
  /**
2097
- * SDK Track decorator and function for telemetry
2098
- */
2099
- /**
2100
- * Common tracking logic shared between method and function decorators
2101
- */
2102
- function createTrackedFunction(originalFunction, nameOrOptions, fallbackName, opts) {
2103
- return function (...args) {
2104
- // Determine if we should track this call
2105
- let shouldTrack = true;
2106
- if (opts.condition !== undefined) {
2107
- if (typeof opts.condition === 'function') {
2108
- shouldTrack = opts.condition.apply(this, args);
2109
- }
2110
- else {
2111
- shouldTrack = opts.condition;
2112
- }
2113
- }
2114
- // Track the event if enabled
2115
- if (shouldTrack) {
2116
- // Use the full name provided in the decorator (e.g., "Queue.GetAll")
2117
- const serviceMethod = typeof nameOrOptions === 'string'
2118
- ? nameOrOptions
2119
- : fallbackName;
2120
- // Use 'Sdk.Run' as the name and serviceMethod as the service
2121
- telemetryClient.track(serviceMethod, SDK_RUN_EVENT, opts.attributes);
2122
- }
2123
- // Execute the original function
2124
- return originalFunction.apply(this, args);
2125
- };
2126
- }
2127
- /**
2128
- * Track decorator that can be used to automatically track function calls
2129
- *
2130
- * Usage:
2131
- * @track("Service.Method")
2132
- * function myFunction() { ... }
1912
+ * UiPath TypeScript SDK Telemetry
2133
1913
  *
2134
- * @track("Queue.GetAll")
2135
- * async getAll() { ... }
2136
- *
2137
- * @track("Tasks.Create")
2138
- * async create() { ... }
2139
- *
2140
- * @track("Assets.Update", { condition: false })
2141
- * function myFunction() { ... }
2142
- *
2143
- * @track("Processes.Start", { attributes: { customProp: "value" } })
2144
- * function myFunction() { ... }
2145
- */
2146
- function track(nameOrOptions, options) {
2147
- return function decorator(_target, propertyKey, descriptor) {
2148
- const opts = typeof nameOrOptions === 'object' ? nameOrOptions : {};
2149
- if (descriptor && typeof descriptor.value === 'function') {
2150
- // Method decorator
2151
- descriptor.value = createTrackedFunction(descriptor.value, nameOrOptions, propertyKey || 'unknown_method', opts);
2152
- return descriptor;
2153
- }
2154
- // Function decorator
2155
- return (originalFunction) => createTrackedFunction(originalFunction, nameOrOptions, originalFunction.name || 'unknown_function', opts);
2156
- };
2157
- }
1914
+ * Constructs the SDK's own `TelemetryClient` and binds the SDK-local
1915
+ * `track` / `trackEvent` to it. Each consumer of `@uipath/core-telemetry`
1916
+ * does this independently, so events carry their own consumer's identity
1917
+ * and tenant context.
1918
+ */
1919
+ // Keyed by `CLOUD_ROLE_NAME` so every SDK subpath bundle resolves to the
1920
+ // same `TelemetryClient` instance at runtime. A single `initialize(...)`
1921
+ // from the `UiPath` constructor therefore wires up `@track` decorators
1922
+ // across every subpath bundle (`assets`, `feedback`, `tasks`, …).
1923
+ const sdkClient = getOrCreateClient(CLOUD_ROLE_NAME);
1924
+ const track = createTrack(sdkClient);
1925
+ createTrackEvent(sdkClient);
2158
1926
 
2159
1927
  /**
2160
1928
  * Service for interacting with UiPath Orchestrator Assets API