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