@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,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var sdkLogs = require('@opentelemetry/sdk-logs');
3
+ var coreTelemetry = require('@uipath/core-telemetry');
4
4
 
5
5
  /******************************************************************************
6
6
  Copyright (c) Microsoft Corporation.
@@ -613,14 +613,25 @@ class ApiClient {
613
613
  if (!text) {
614
614
  return undefined;
615
615
  }
616
- return JSON.parse(text);
616
+ try {
617
+ return JSON.parse(text);
618
+ }
619
+ catch (error) {
620
+ if (error instanceof SyntaxError) {
621
+ throw new ServerError({
622
+ message: `Server returned non-JSON response (${response.status} ${response.url}): ${error.message}`,
623
+ statusCode: response.status,
624
+ });
625
+ }
626
+ throw error;
627
+ }
617
628
  }
618
629
  catch (error) {
619
630
  // If it's already one of our errors, re-throw it
620
631
  if (error.type && error.type.includes('Error')) {
621
632
  throw error;
622
633
  }
623
- // Otherwise, it's likely a network error
634
+ // Otherwise, it's a genuine network/fetch failure
624
635
  throw ErrorFactory.createNetworkError(error);
625
636
  }
626
637
  }
@@ -1221,9 +1232,9 @@ class PaginationHelpers {
1221
1232
  * @returns Promise resolving to a paginated result
1222
1233
  */
1223
1234
  static async getAllPaginated(params) {
1224
- const { serviceAccess, getEndpoint, folderId, paginationParams, additionalParams, transformFn, method = HTTP_METHODS.GET, options = {} } = params;
1235
+ const { serviceAccess, getEndpoint, folderId, headers: providedHeaders, paginationParams, additionalParams, transformFn, method = HTTP_METHODS.GET, options = {} } = params;
1225
1236
  const endpoint = getEndpoint(folderId);
1226
- const headers = folderId ? createHeaders({ [FOLDER_ID]: folderId }) : {};
1237
+ const headers = providedHeaders ?? (folderId ? createHeaders({ [FOLDER_ID]: folderId }) : {});
1227
1238
  const paginatedResponse = await serviceAccess.requestWithPagination(method, endpoint, paginationParams, {
1228
1239
  headers,
1229
1240
  params: additionalParams,
@@ -1251,13 +1262,13 @@ class PaginationHelpers {
1251
1262
  * @returns Promise resolving to an object with data and totalCount
1252
1263
  */
1253
1264
  static async getAllNonPaginated(params) {
1254
- const { serviceAccess, getAllEndpoint, getByFolderEndpoint, folderId, additionalParams, transformFn, method = HTTP_METHODS.GET, options = {} } = params;
1265
+ const { serviceAccess, getAllEndpoint, getByFolderEndpoint, folderId, headers: providedHeaders, additionalParams, transformFn, method = HTTP_METHODS.GET, options = {} } = params;
1255
1266
  // Set default field names
1256
1267
  const itemsField = options.itemsField || DEFAULT_ITEMS_FIELD;
1257
1268
  const totalCountField = options.totalCountField || DEFAULT_TOTAL_COUNT_FIELD;
1258
1269
  // Determine endpoint and headers based on folderId
1259
1270
  const endpoint = folderId ? getByFolderEndpoint : getAllEndpoint;
1260
- const headers = folderId ? createHeaders({ [FOLDER_ID]: folderId }) : {};
1271
+ const headers = providedHeaders ?? (folderId ? createHeaders({ [FOLDER_ID]: folderId }) : {});
1261
1272
  // Make the API call based on method
1262
1273
  let response;
1263
1274
  if (method === HTTP_METHODS.POST) {
@@ -1316,6 +1327,7 @@ class PaginationHelpers {
1316
1327
  serviceAccess: config.serviceAccess,
1317
1328
  getEndpoint: config.getEndpoint,
1318
1329
  folderId,
1330
+ headers: config.headers,
1319
1331
  paginationParams: cursor ? { cursor, pageSize } : jumpToPage ? { jumpToPage, pageSize } : { pageSize },
1320
1332
  additionalParams: prefixedOptions,
1321
1333
  transformFn: config.transformFn,
@@ -1333,6 +1345,7 @@ class PaginationHelpers {
1333
1345
  getAllEndpoint: config.getEndpoint(),
1334
1346
  getByFolderEndpoint: byFolderEndpoint,
1335
1347
  folderId,
1348
+ headers: config.headers,
1336
1349
  additionalParams: prefixedOptions,
1337
1350
  transformFn: config.transformFn,
1338
1351
  method: config.method,
@@ -1953,278 +1966,33 @@ const JobMap = {
1953
1966
  };
1954
1967
 
1955
1968
  /**
1956
- * SDK Telemetry constants
1957
- */
1958
- // Connection string placeholder that will be replaced during build
1959
- 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";
1960
- // SDK Version placeholder
1961
- const SDK_VERSION = "1.3.8";
1962
- const VERSION = "Version";
1963
- const SERVICE = "Service";
1964
- const CLOUD_ORGANIZATION_NAME = "CloudOrganizationName";
1965
- const CLOUD_TENANT_NAME = "CloudTenantName";
1966
- const CLOUD_URL = "CloudUrl";
1967
- const CLOUD_CLIENT_ID = "CloudClientId";
1968
- const CLOUD_REDIRECT_URI = "CloudRedirectUri";
1969
- const APP_NAME = "ApplicationName";
1970
- const CLOUD_ROLE_NAME = "uipath-ts-sdk";
1971
- // Service and logger names
1972
- const SDK_SERVICE_NAME = "UiPath.TypeScript.Sdk";
1973
- const SDK_LOGGER_NAME = "uipath-ts-sdk-telemetry";
1974
- // Event names
1975
- const SDK_RUN_EVENT = "Sdk.Run";
1976
- // Default value for unknown/empty attributes
1977
- const UNKNOWN = "";
1978
-
1979
- /**
1980
- * Log exporter that sends ALL logs as Application Insights custom events
1981
- */
1982
- class ApplicationInsightsEventExporter {
1983
- constructor(connectionString) {
1984
- this.connectionString = connectionString;
1985
- }
1986
- export(logs, resultCallback) {
1987
- try {
1988
- logs.forEach(logRecord => {
1989
- this.sendAsCustomEvent(logRecord);
1990
- });
1991
- resultCallback({ code: 0 });
1992
- }
1993
- catch (error) {
1994
- console.debug('Failed to export logs to Application Insights:', error);
1995
- resultCallback({ code: 2, error });
1996
- }
1997
- }
1998
- shutdown() {
1999
- return Promise.resolve();
2000
- }
2001
- sendAsCustomEvent(logRecord) {
2002
- // Get event name from body or attributes
2003
- const eventName = logRecord.body || SDK_RUN_EVENT;
2004
- const payload = {
2005
- name: 'Microsoft.ApplicationInsights.Event',
2006
- time: new Date().toISOString(),
2007
- iKey: this.extractInstrumentationKey(),
2008
- data: {
2009
- baseType: 'EventData',
2010
- baseData: {
2011
- ver: 2,
2012
- name: eventName,
2013
- properties: this.convertAttributesToProperties(logRecord.attributes || {})
2014
- }
2015
- },
2016
- tags: {
2017
- 'ai.cloud.role': CLOUD_ROLE_NAME,
2018
- 'ai.cloud.roleInstance': SDK_VERSION
2019
- }
2020
- };
2021
- this.sendToApplicationInsights(payload);
2022
- }
2023
- extractInstrumentationKey() {
2024
- const match = this.connectionString.match(/InstrumentationKey=([^;]+)/);
2025
- return match ? match[1] : '';
2026
- }
2027
- convertAttributesToProperties(attributes) {
2028
- const properties = {};
2029
- Object.entries(attributes || {}).forEach(([key, value]) => {
2030
- properties[key] = String(value);
2031
- });
2032
- return properties;
2033
- }
2034
- async sendToApplicationInsights(payload) {
2035
- try {
2036
- const ingestionEndpoint = this.extractIngestionEndpoint();
2037
- if (!ingestionEndpoint) {
2038
- console.debug('No ingestion endpoint found in connection string');
2039
- return;
2040
- }
2041
- const url = `${ingestionEndpoint}/v2/track`;
2042
- const response = await fetch(url, {
2043
- method: 'POST',
2044
- headers: {
2045
- 'Content-Type': 'application/json',
2046
- },
2047
- body: JSON.stringify(payload)
2048
- });
2049
- if (!response.ok) {
2050
- console.debug(`Failed to send event telemetry: ${response.status} ${response.statusText}`);
2051
- }
2052
- }
2053
- catch (error) {
2054
- console.debug('Error sending event telemetry to Application Insights:', error);
2055
- }
2056
- }
2057
- extractIngestionEndpoint() {
2058
- const match = this.connectionString.match(/IngestionEndpoint=([^;]+)/);
2059
- return match ? match[1] : '';
2060
- }
2061
- }
2062
- /**
2063
- * Singleton telemetry client
2064
- */
2065
- class TelemetryClient {
2066
- constructor() {
2067
- this.isInitialized = false;
2068
- }
2069
- static getInstance() {
2070
- if (!TelemetryClient.instance) {
2071
- TelemetryClient.instance = new TelemetryClient();
2072
- }
2073
- return TelemetryClient.instance;
2074
- }
2075
- /**
2076
- * Initialize telemetry
2077
- */
2078
- initialize(config) {
2079
- if (this.isInitialized) {
2080
- return;
2081
- }
2082
- this.isInitialized = true;
2083
- if (config) {
2084
- this.telemetryContext = config;
2085
- }
2086
- try {
2087
- const connectionString = this.getConnectionString();
2088
- if (!connectionString) {
2089
- return;
2090
- }
2091
- this.setupTelemetryProvider(connectionString);
2092
- }
2093
- catch (error) {
2094
- // Silent failure - telemetry errors shouldn't break functionality
2095
- console.debug('Failed to initialize OpenTelemetry:', error);
2096
- }
2097
- }
2098
- getConnectionString() {
2099
- const connectionString = CONNECTION_STRING;
2100
- return connectionString;
2101
- }
2102
- setupTelemetryProvider(connectionString) {
2103
- const exporter = new ApplicationInsightsEventExporter(connectionString);
2104
- const processor = new sdkLogs.BatchLogRecordProcessor(exporter);
2105
- this.logProvider = new sdkLogs.LoggerProvider({
2106
- processors: [processor]
2107
- });
2108
- this.logger = this.logProvider.getLogger(SDK_LOGGER_NAME);
2109
- }
2110
- /**
2111
- * Track a telemetry event
2112
- */
2113
- track(eventName, name, extraAttributes = {}) {
2114
- try {
2115
- // Skip if logger not initialized
2116
- if (!this.logger) {
2117
- return;
2118
- }
2119
- const finalDisplayName = name || eventName;
2120
- const attributes = this.getEnrichedAttributes(extraAttributes, eventName);
2121
- // Emit as log
2122
- this.logger.emit({
2123
- body: finalDisplayName,
2124
- attributes: attributes,
2125
- timestamp: Date.now(),
2126
- });
2127
- }
2128
- catch (error) {
2129
- // Silent failure
2130
- console.debug('Failed to track telemetry event:', error);
2131
- }
2132
- }
2133
- /**
2134
- * Get enriched attributes for telemetry events
2135
- */
2136
- getEnrichedAttributes(extraAttributes, eventName) {
2137
- const attributes = {
2138
- [APP_NAME]: SDK_SERVICE_NAME,
2139
- [VERSION]: SDK_VERSION,
2140
- [SERVICE]: eventName,
2141
- [CLOUD_URL]: this.createCloudUrl(),
2142
- [CLOUD_ORGANIZATION_NAME]: this.telemetryContext?.orgName || UNKNOWN,
2143
- [CLOUD_TENANT_NAME]: this.telemetryContext?.tenantName || UNKNOWN,
2144
- [CLOUD_REDIRECT_URI]: this.telemetryContext?.redirectUri || UNKNOWN,
2145
- [CLOUD_CLIENT_ID]: this.telemetryContext?.clientId || UNKNOWN,
2146
- ...extraAttributes,
2147
- };
2148
- return attributes;
2149
- }
2150
- /**
2151
- * Create cloud URL from base URL, organization ID, and tenant ID
2152
- */
2153
- createCloudUrl() {
2154
- const baseUrl = this.telemetryContext?.baseUrl;
2155
- const orgId = this.telemetryContext?.orgName;
2156
- const tenantId = this.telemetryContext?.tenantName;
2157
- if (!baseUrl || !orgId || !tenantId) {
2158
- return UNKNOWN;
2159
- }
2160
- return `${baseUrl}/${orgId}/${tenantId}`;
2161
- }
2162
- }
2163
- // Export singleton instance
2164
- const telemetryClient = TelemetryClient.getInstance();
1969
+ * SDK Telemetry constants.
1970
+ *
1971
+ * Only the SDK's identity (version, service name, role name, …) lives
1972
+ * here. The Application Insights connection string is injected into
1973
+ * `@uipath/core-telemetry` itself at publish time, and the generic attribute
1974
+ * keys (`Version`, `Service`, `CloudOrganizationName`, …) are owned by
1975
+ * `@uipath/core-telemetry` and consumed there — they are not part of the
1976
+ * SDK's public API.
1977
+ */
1978
+ /** SDK version placeholder — patched by the SDK publish workflow. */
1979
+ const CLOUD_ROLE_NAME = 'uipath-ts-sdk';
2165
1980
 
2166
1981
  /**
2167
- * SDK Track decorator and function for telemetry
2168
- */
2169
- /**
2170
- * Common tracking logic shared between method and function decorators
2171
- */
2172
- function createTrackedFunction(originalFunction, nameOrOptions, fallbackName, opts) {
2173
- return function (...args) {
2174
- // Determine if we should track this call
2175
- let shouldTrack = true;
2176
- if (opts.condition !== undefined) {
2177
- if (typeof opts.condition === 'function') {
2178
- shouldTrack = opts.condition.apply(this, args);
2179
- }
2180
- else {
2181
- shouldTrack = opts.condition;
2182
- }
2183
- }
2184
- // Track the event if enabled
2185
- if (shouldTrack) {
2186
- // Use the full name provided in the decorator (e.g., "Queue.GetAll")
2187
- const serviceMethod = typeof nameOrOptions === 'string'
2188
- ? nameOrOptions
2189
- : fallbackName;
2190
- // Use 'Sdk.Run' as the name and serviceMethod as the service
2191
- telemetryClient.track(serviceMethod, SDK_RUN_EVENT, opts.attributes);
2192
- }
2193
- // Execute the original function
2194
- return originalFunction.apply(this, args);
2195
- };
2196
- }
2197
- /**
2198
- * Track decorator that can be used to automatically track function calls
2199
- *
2200
- * Usage:
2201
- * @track("Service.Method")
2202
- * function myFunction() { ... }
1982
+ * UiPath TypeScript SDK Telemetry
2203
1983
  *
2204
- * @track("Queue.GetAll")
2205
- * async getAll() { ... }
2206
- *
2207
- * @track("Tasks.Create")
2208
- * async create() { ... }
2209
- *
2210
- * @track("Assets.Update", { condition: false })
2211
- * function myFunction() { ... }
2212
- *
2213
- * @track("Processes.Start", { attributes: { customProp: "value" } })
2214
- * function myFunction() { ... }
2215
- */
2216
- function track(nameOrOptions, options) {
2217
- return function decorator(_target, propertyKey, descriptor) {
2218
- const opts = typeof nameOrOptions === 'object' ? nameOrOptions : {};
2219
- if (descriptor && typeof descriptor.value === 'function') {
2220
- // Method decorator
2221
- descriptor.value = createTrackedFunction(descriptor.value, nameOrOptions, propertyKey || 'unknown_method', opts);
2222
- return descriptor;
2223
- }
2224
- // Function decorator
2225
- return (originalFunction) => createTrackedFunction(originalFunction, nameOrOptions, originalFunction.name || 'unknown_function', opts);
2226
- };
2227
- }
1984
+ * Constructs the SDK's own `TelemetryClient` and binds the SDK-local
1985
+ * `track` / `trackEvent` to it. Each consumer of `@uipath/core-telemetry`
1986
+ * does this independently, so events carry their own consumer's identity
1987
+ * and tenant context.
1988
+ */
1989
+ // Keyed by `CLOUD_ROLE_NAME` so every SDK subpath bundle resolves to the
1990
+ // same `TelemetryClient` instance at runtime. A single `initialize(...)`
1991
+ // from the `UiPath` constructor therefore wires up `@track` decorators
1992
+ // across every subpath bundle (`assets`, `feedback`, `tasks`, …).
1993
+ const sdkClient = coreTelemetry.getOrCreateClient(CLOUD_ROLE_NAME);
1994
+ const track = coreTelemetry.createTrack(sdkClient);
1995
+ coreTelemetry.createTrackEvent(sdkClient);
2228
1996
 
2229
1997
  /**
2230
1998
  * Maps fields for Attachment entities to ensure consistent naming