@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.
@@ -612,14 +612,25 @@ class ApiClient {
612
612
  if (!text) {
613
613
  return undefined;
614
614
  }
615
- return JSON.parse(text);
615
+ try {
616
+ return JSON.parse(text);
617
+ }
618
+ catch (error) {
619
+ if (error instanceof SyntaxError) {
620
+ throw new ServerError({
621
+ message: `Server returned non-JSON response (${response.status} ${response.url}): ${error.message}`,
622
+ statusCode: response.status,
623
+ });
624
+ }
625
+ throw error;
626
+ }
616
627
  }
617
628
  catch (error) {
618
629
  // If it's already one of our errors, re-throw it
619
630
  if (error.type && error.type.includes('Error')) {
620
631
  throw error;
621
632
  }
622
- // Otherwise, it's likely a network error
633
+ // Otherwise, it's a genuine network/fetch failure
623
634
  throw ErrorFactory.createNetworkError(error);
624
635
  }
625
636
  }
@@ -1149,9 +1160,9 @@ class PaginationHelpers {
1149
1160
  * @returns Promise resolving to a paginated result
1150
1161
  */
1151
1162
  static async getAllPaginated(params) {
1152
- const { serviceAccess, getEndpoint, folderId, paginationParams, additionalParams, transformFn, method = HTTP_METHODS.GET, options = {} } = params;
1163
+ const { serviceAccess, getEndpoint, folderId, headers: providedHeaders, paginationParams, additionalParams, transformFn, method = HTTP_METHODS.GET, options = {} } = params;
1153
1164
  const endpoint = getEndpoint(folderId);
1154
- const headers = folderId ? createHeaders({ [FOLDER_ID]: folderId }) : {};
1165
+ const headers = providedHeaders ?? (folderId ? createHeaders({ [FOLDER_ID]: folderId }) : {});
1155
1166
  const paginatedResponse = await serviceAccess.requestWithPagination(method, endpoint, paginationParams, {
1156
1167
  headers,
1157
1168
  params: additionalParams,
@@ -1179,13 +1190,13 @@ class PaginationHelpers {
1179
1190
  * @returns Promise resolving to an object with data and totalCount
1180
1191
  */
1181
1192
  static async getAllNonPaginated(params) {
1182
- const { serviceAccess, getAllEndpoint, getByFolderEndpoint, folderId, additionalParams, transformFn, method = HTTP_METHODS.GET, options = {} } = params;
1193
+ const { serviceAccess, getAllEndpoint, getByFolderEndpoint, folderId, headers: providedHeaders, additionalParams, transformFn, method = HTTP_METHODS.GET, options = {} } = params;
1183
1194
  // Set default field names
1184
1195
  const itemsField = options.itemsField || DEFAULT_ITEMS_FIELD;
1185
1196
  const totalCountField = options.totalCountField || DEFAULT_TOTAL_COUNT_FIELD;
1186
1197
  // Determine endpoint and headers based on folderId
1187
1198
  const endpoint = folderId ? getByFolderEndpoint : getAllEndpoint;
1188
- const headers = folderId ? createHeaders({ [FOLDER_ID]: folderId }) : {};
1199
+ const headers = providedHeaders ?? (folderId ? createHeaders({ [FOLDER_ID]: folderId }) : {});
1189
1200
  // Make the API call based on method
1190
1201
  let response;
1191
1202
  if (method === HTTP_METHODS.POST) {
@@ -1244,6 +1255,7 @@ class PaginationHelpers {
1244
1255
  serviceAccess: config.serviceAccess,
1245
1256
  getEndpoint: config.getEndpoint,
1246
1257
  folderId,
1258
+ headers: config.headers,
1247
1259
  paginationParams: cursor ? { cursor, pageSize } : jumpToPage ? { jumpToPage, pageSize } : { pageSize },
1248
1260
  additionalParams: prefixedOptions,
1249
1261
  transformFn: config.transformFn,
@@ -1261,6 +1273,7 @@ class PaginationHelpers {
1261
1273
  getAllEndpoint: config.getEndpoint(),
1262
1274
  getByFolderEndpoint: byFolderEndpoint,
1263
1275
  folderId,
1276
+ headers: config.headers,
1264
1277
  additionalParams: prefixedOptions,
1265
1278
  transformFn: config.transformFn,
1266
1279
  method: config.method,
@@ -1615,278 +1628,33 @@ const FEEDBACK_ENDPOINTS = {
1615
1628
  };
1616
1629
 
1617
1630
  /**
1618
- * SDK Telemetry constants
1631
+ * SDK Telemetry constants.
1632
+ *
1633
+ * Only the SDK's identity (version, service name, role name, …) lives
1634
+ * here. The Application Insights connection string is injected into
1635
+ * `@uipath/core-telemetry` itself at publish time, and the generic attribute
1636
+ * keys (`Version`, `Service`, `CloudOrganizationName`, …) are owned by
1637
+ * `@uipath/core-telemetry` and consumed there — they are not part of the
1638
+ * SDK's public API.
1619
1639
  */
1620
- // Connection string placeholder that will be replaced during build
1621
- 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";
1622
- // SDK Version placeholder
1623
- const SDK_VERSION = "1.3.8";
1624
- const VERSION = "Version";
1625
- const SERVICE = "Service";
1626
- const CLOUD_ORGANIZATION_NAME = "CloudOrganizationName";
1627
- const CLOUD_TENANT_NAME = "CloudTenantName";
1628
- const CLOUD_URL = "CloudUrl";
1629
- const CLOUD_CLIENT_ID = "CloudClientId";
1630
- const CLOUD_REDIRECT_URI = "CloudRedirectUri";
1631
- const APP_NAME = "ApplicationName";
1632
- const CLOUD_ROLE_NAME = "uipath-ts-sdk";
1633
- // Service and logger names
1634
- const SDK_SERVICE_NAME = "UiPath.TypeScript.Sdk";
1635
- const SDK_LOGGER_NAME = "uipath-ts-sdk-telemetry";
1636
- // Event names
1637
- const SDK_RUN_EVENT = "Sdk.Run";
1638
- // Default value for unknown/empty attributes
1639
- const UNKNOWN = "";
1640
+ /** SDK version placeholder patched by the SDK publish workflow. */
1641
+ const CLOUD_ROLE_NAME = 'uipath-ts-sdk';
1640
1642
 
1641
1643
  /**
1642
- * Log exporter that sends ALL logs as Application Insights custom events
1643
- */
1644
- class ApplicationInsightsEventExporter {
1645
- constructor(connectionString) {
1646
- this.connectionString = connectionString;
1647
- }
1648
- export(logs, resultCallback) {
1649
- try {
1650
- logs.forEach(logRecord => {
1651
- this.sendAsCustomEvent(logRecord);
1652
- });
1653
- resultCallback({ code: 0 });
1654
- }
1655
- catch (error) {
1656
- console.debug('Failed to export logs to Application Insights:', error);
1657
- resultCallback({ code: 2, error });
1658
- }
1659
- }
1660
- shutdown() {
1661
- return Promise.resolve();
1662
- }
1663
- sendAsCustomEvent(logRecord) {
1664
- // Get event name from body or attributes
1665
- const eventName = logRecord.body || SDK_RUN_EVENT;
1666
- const payload = {
1667
- name: 'Microsoft.ApplicationInsights.Event',
1668
- time: new Date().toISOString(),
1669
- iKey: this.extractInstrumentationKey(),
1670
- data: {
1671
- baseType: 'EventData',
1672
- baseData: {
1673
- ver: 2,
1674
- name: eventName,
1675
- properties: this.convertAttributesToProperties(logRecord.attributes || {})
1676
- }
1677
- },
1678
- tags: {
1679
- 'ai.cloud.role': CLOUD_ROLE_NAME,
1680
- 'ai.cloud.roleInstance': SDK_VERSION
1681
- }
1682
- };
1683
- this.sendToApplicationInsights(payload);
1684
- }
1685
- extractInstrumentationKey() {
1686
- const match = this.connectionString.match(/InstrumentationKey=([^;]+)/);
1687
- return match ? match[1] : '';
1688
- }
1689
- convertAttributesToProperties(attributes) {
1690
- const properties = {};
1691
- Object.entries(attributes || {}).forEach(([key, value]) => {
1692
- properties[key] = String(value);
1693
- });
1694
- return properties;
1695
- }
1696
- async sendToApplicationInsights(payload) {
1697
- try {
1698
- const ingestionEndpoint = this.extractIngestionEndpoint();
1699
- if (!ingestionEndpoint) {
1700
- console.debug('No ingestion endpoint found in connection string');
1701
- return;
1702
- }
1703
- const url = `${ingestionEndpoint}/v2/track`;
1704
- const response = await fetch(url, {
1705
- method: 'POST',
1706
- headers: {
1707
- 'Content-Type': 'application/json',
1708
- },
1709
- body: JSON.stringify(payload)
1710
- });
1711
- if (!response.ok) {
1712
- console.debug(`Failed to send event telemetry: ${response.status} ${response.statusText}`);
1713
- }
1714
- }
1715
- catch (error) {
1716
- console.debug('Error sending event telemetry to Application Insights:', error);
1717
- }
1718
- }
1719
- extractIngestionEndpoint() {
1720
- const match = this.connectionString.match(/IngestionEndpoint=([^;]+)/);
1721
- return match ? match[1] : '';
1722
- }
1723
- }
1724
- /**
1725
- * Singleton telemetry client
1726
- */
1727
- class TelemetryClient {
1728
- constructor() {
1729
- this.isInitialized = false;
1730
- }
1731
- static getInstance() {
1732
- if (!TelemetryClient.instance) {
1733
- TelemetryClient.instance = new TelemetryClient();
1734
- }
1735
- return TelemetryClient.instance;
1736
- }
1737
- /**
1738
- * Initialize telemetry
1739
- */
1740
- initialize(config) {
1741
- if (this.isInitialized) {
1742
- return;
1743
- }
1744
- this.isInitialized = true;
1745
- if (config) {
1746
- this.telemetryContext = config;
1747
- }
1748
- try {
1749
- const connectionString = this.getConnectionString();
1750
- if (!connectionString) {
1751
- return;
1752
- }
1753
- this.setupTelemetryProvider(connectionString);
1754
- }
1755
- catch (error) {
1756
- // Silent failure - telemetry errors shouldn't break functionality
1757
- console.debug('Failed to initialize OpenTelemetry:', error);
1758
- }
1759
- }
1760
- getConnectionString() {
1761
- const connectionString = CONNECTION_STRING;
1762
- return connectionString;
1763
- }
1764
- setupTelemetryProvider(connectionString) {
1765
- const exporter = new ApplicationInsightsEventExporter(connectionString);
1766
- const processor = new sdkLogs.BatchLogRecordProcessor(exporter);
1767
- this.logProvider = new sdkLogs.LoggerProvider({
1768
- processors: [processor]
1769
- });
1770
- this.logger = this.logProvider.getLogger(SDK_LOGGER_NAME);
1771
- }
1772
- /**
1773
- * Track a telemetry event
1774
- */
1775
- track(eventName, name, extraAttributes = {}) {
1776
- try {
1777
- // Skip if logger not initialized
1778
- if (!this.logger) {
1779
- return;
1780
- }
1781
- const finalDisplayName = name || eventName;
1782
- const attributes = this.getEnrichedAttributes(extraAttributes, eventName);
1783
- // Emit as log
1784
- this.logger.emit({
1785
- body: finalDisplayName,
1786
- attributes: attributes,
1787
- timestamp: Date.now(),
1788
- });
1789
- }
1790
- catch (error) {
1791
- // Silent failure
1792
- console.debug('Failed to track telemetry event:', error);
1793
- }
1794
- }
1795
- /**
1796
- * Get enriched attributes for telemetry events
1797
- */
1798
- getEnrichedAttributes(extraAttributes, eventName) {
1799
- const attributes = {
1800
- [APP_NAME]: SDK_SERVICE_NAME,
1801
- [VERSION]: SDK_VERSION,
1802
- [SERVICE]: eventName,
1803
- [CLOUD_URL]: this.createCloudUrl(),
1804
- [CLOUD_ORGANIZATION_NAME]: this.telemetryContext?.orgName || UNKNOWN,
1805
- [CLOUD_TENANT_NAME]: this.telemetryContext?.tenantName || UNKNOWN,
1806
- [CLOUD_REDIRECT_URI]: this.telemetryContext?.redirectUri || UNKNOWN,
1807
- [CLOUD_CLIENT_ID]: this.telemetryContext?.clientId || UNKNOWN,
1808
- ...extraAttributes,
1809
- };
1810
- return attributes;
1811
- }
1812
- /**
1813
- * Create cloud URL from base URL, organization ID, and tenant ID
1814
- */
1815
- createCloudUrl() {
1816
- const baseUrl = this.telemetryContext?.baseUrl;
1817
- const orgId = this.telemetryContext?.orgName;
1818
- const tenantId = this.telemetryContext?.tenantName;
1819
- if (!baseUrl || !orgId || !tenantId) {
1820
- return UNKNOWN;
1821
- }
1822
- return `${baseUrl}/${orgId}/${tenantId}`;
1823
- }
1824
- }
1825
- // Export singleton instance
1826
- const telemetryClient = TelemetryClient.getInstance();
1827
-
1828
- /**
1829
- * SDK Track decorator and function for telemetry
1830
- */
1831
- /**
1832
- * Common tracking logic shared between method and function decorators
1833
- */
1834
- function createTrackedFunction(originalFunction, nameOrOptions, fallbackName, opts) {
1835
- return function (...args) {
1836
- // Determine if we should track this call
1837
- let shouldTrack = true;
1838
- if (opts.condition !== undefined) {
1839
- if (typeof opts.condition === 'function') {
1840
- shouldTrack = opts.condition.apply(this, args);
1841
- }
1842
- else {
1843
- shouldTrack = opts.condition;
1844
- }
1845
- }
1846
- // Track the event if enabled
1847
- if (shouldTrack) {
1848
- // Use the full name provided in the decorator (e.g., "Queue.GetAll")
1849
- const serviceMethod = typeof nameOrOptions === 'string'
1850
- ? nameOrOptions
1851
- : fallbackName;
1852
- // Use 'Sdk.Run' as the name and serviceMethod as the service
1853
- telemetryClient.track(serviceMethod, SDK_RUN_EVENT, opts.attributes);
1854
- }
1855
- // Execute the original function
1856
- return originalFunction.apply(this, args);
1857
- };
1858
- }
1859
- /**
1860
- * Track decorator that can be used to automatically track function calls
1861
- *
1862
- * Usage:
1863
- * @track("Service.Method")
1864
- * function myFunction() { ... }
1644
+ * UiPath TypeScript SDK Telemetry
1865
1645
  *
1866
- * @track("Queue.GetAll")
1867
- * async getAll() { ... }
1868
- *
1869
- * @track("Tasks.Create")
1870
- * async create() { ... }
1871
- *
1872
- * @track("Assets.Update", { condition: false })
1873
- * function myFunction() { ... }
1874
- *
1875
- * @track("Processes.Start", { attributes: { customProp: "value" } })
1876
- * function myFunction() { ... }
1646
+ * Constructs the SDK's own `TelemetryClient` and binds the SDK-local
1647
+ * `track` / `trackEvent` to it. Each consumer of `@uipath/core-telemetry`
1648
+ * does this independently, so events carry their own consumer's identity
1649
+ * and tenant context.
1877
1650
  */
1878
- function track(nameOrOptions, options) {
1879
- return function decorator(_target, propertyKey, descriptor) {
1880
- const opts = typeof nameOrOptions === 'object' ? nameOrOptions : {};
1881
- if (descriptor && typeof descriptor.value === 'function') {
1882
- // Method decorator
1883
- descriptor.value = createTrackedFunction(descriptor.value, nameOrOptions, propertyKey || 'unknown_method', opts);
1884
- return descriptor;
1885
- }
1886
- // Function decorator
1887
- return (originalFunction) => createTrackedFunction(originalFunction, nameOrOptions, originalFunction.name || 'unknown_function', opts);
1888
- };
1889
- }
1651
+ // Keyed by `CLOUD_ROLE_NAME` so every SDK subpath bundle resolves to the
1652
+ // same `TelemetryClient` instance at runtime. A single `initialize(...)`
1653
+ // from the `UiPath` constructor therefore wires up `@track` decorators
1654
+ // across every subpath bundle (`assets`, `feedback`, `tasks`, …).
1655
+ const sdkClient = coreTelemetry.getOrCreateClient(CLOUD_ROLE_NAME);
1656
+ const track = coreTelemetry.createTrack(sdkClient);
1657
+ coreTelemetry.createTrackEvent(sdkClient);
1890
1658
 
1891
1659
  /**
1892
1660
  * Service for interacting with UiPath Agent Feedback API