@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.
@@ -273,278 +273,33 @@ class NetworkError extends UiPathError {
273
273
  }
274
274
 
275
275
  /**
276
- * SDK Telemetry constants
277
- */
278
- // Connection string placeholder that will be replaced during build
279
- 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";
280
- // SDK Version placeholder
281
- const SDK_VERSION = "1.3.8";
282
- const VERSION = "Version";
283
- const SERVICE = "Service";
284
- const CLOUD_ORGANIZATION_NAME = "CloudOrganizationName";
285
- const CLOUD_TENANT_NAME = "CloudTenantName";
286
- const CLOUD_URL = "CloudUrl";
287
- const CLOUD_CLIENT_ID = "CloudClientId";
288
- const CLOUD_REDIRECT_URI = "CloudRedirectUri";
289
- const APP_NAME = "ApplicationName";
290
- const CLOUD_ROLE_NAME = "uipath-ts-sdk";
291
- // Service and logger names
292
- const SDK_SERVICE_NAME = "UiPath.TypeScript.Sdk";
293
- const SDK_LOGGER_NAME = "uipath-ts-sdk-telemetry";
294
- // Event names
295
- const SDK_RUN_EVENT = "Sdk.Run";
296
- // Default value for unknown/empty attributes
297
- const UNKNOWN = "";
298
-
299
- /**
300
- * Log exporter that sends ALL logs as Application Insights custom events
301
- */
302
- class ApplicationInsightsEventExporter {
303
- constructor(connectionString) {
304
- this.connectionString = connectionString;
305
- }
306
- export(logs, resultCallback) {
307
- try {
308
- logs.forEach(logRecord => {
309
- this.sendAsCustomEvent(logRecord);
310
- });
311
- resultCallback({ code: 0 });
312
- }
313
- catch (error) {
314
- console.debug('Failed to export logs to Application Insights:', error);
315
- resultCallback({ code: 2, error });
316
- }
317
- }
318
- shutdown() {
319
- return Promise.resolve();
320
- }
321
- sendAsCustomEvent(logRecord) {
322
- // Get event name from body or attributes
323
- const eventName = logRecord.body || SDK_RUN_EVENT;
324
- const payload = {
325
- name: 'Microsoft.ApplicationInsights.Event',
326
- time: new Date().toISOString(),
327
- iKey: this.extractInstrumentationKey(),
328
- data: {
329
- baseType: 'EventData',
330
- baseData: {
331
- ver: 2,
332
- name: eventName,
333
- properties: this.convertAttributesToProperties(logRecord.attributes || {})
334
- }
335
- },
336
- tags: {
337
- 'ai.cloud.role': CLOUD_ROLE_NAME,
338
- 'ai.cloud.roleInstance': SDK_VERSION
339
- }
340
- };
341
- this.sendToApplicationInsights(payload);
342
- }
343
- extractInstrumentationKey() {
344
- const match = this.connectionString.match(/InstrumentationKey=([^;]+)/);
345
- return match ? match[1] : '';
346
- }
347
- convertAttributesToProperties(attributes) {
348
- const properties = {};
349
- Object.entries(attributes || {}).forEach(([key, value]) => {
350
- properties[key] = String(value);
351
- });
352
- return properties;
353
- }
354
- async sendToApplicationInsights(payload) {
355
- try {
356
- const ingestionEndpoint = this.extractIngestionEndpoint();
357
- if (!ingestionEndpoint) {
358
- console.debug('No ingestion endpoint found in connection string');
359
- return;
360
- }
361
- const url = `${ingestionEndpoint}/v2/track`;
362
- const response = await fetch(url, {
363
- method: 'POST',
364
- headers: {
365
- 'Content-Type': 'application/json',
366
- },
367
- body: JSON.stringify(payload)
368
- });
369
- if (!response.ok) {
370
- console.debug(`Failed to send event telemetry: ${response.status} ${response.statusText}`);
371
- }
372
- }
373
- catch (error) {
374
- console.debug('Error sending event telemetry to Application Insights:', error);
375
- }
376
- }
377
- extractIngestionEndpoint() {
378
- const match = this.connectionString.match(/IngestionEndpoint=([^;]+)/);
379
- return match ? match[1] : '';
380
- }
381
- }
382
- /**
383
- * Singleton telemetry client
384
- */
385
- class TelemetryClient {
386
- constructor() {
387
- this.isInitialized = false;
388
- }
389
- static getInstance() {
390
- if (!TelemetryClient.instance) {
391
- TelemetryClient.instance = new TelemetryClient();
392
- }
393
- return TelemetryClient.instance;
394
- }
395
- /**
396
- * Initialize telemetry
397
- */
398
- initialize(config) {
399
- if (this.isInitialized) {
400
- return;
401
- }
402
- this.isInitialized = true;
403
- if (config) {
404
- this.telemetryContext = config;
405
- }
406
- try {
407
- const connectionString = this.getConnectionString();
408
- if (!connectionString) {
409
- return;
410
- }
411
- this.setupTelemetryProvider(connectionString);
412
- }
413
- catch (error) {
414
- // Silent failure - telemetry errors shouldn't break functionality
415
- console.debug('Failed to initialize OpenTelemetry:', error);
416
- }
417
- }
418
- getConnectionString() {
419
- const connectionString = CONNECTION_STRING;
420
- return connectionString;
421
- }
422
- setupTelemetryProvider(connectionString) {
423
- const exporter = new ApplicationInsightsEventExporter(connectionString);
424
- const processor = new sdkLogs.BatchLogRecordProcessor(exporter);
425
- this.logProvider = new sdkLogs.LoggerProvider({
426
- processors: [processor]
427
- });
428
- this.logger = this.logProvider.getLogger(SDK_LOGGER_NAME);
429
- }
430
- /**
431
- * Track a telemetry event
432
- */
433
- track(eventName, name, extraAttributes = {}) {
434
- try {
435
- // Skip if logger not initialized
436
- if (!this.logger) {
437
- return;
438
- }
439
- const finalDisplayName = name || eventName;
440
- const attributes = this.getEnrichedAttributes(extraAttributes, eventName);
441
- // Emit as log
442
- this.logger.emit({
443
- body: finalDisplayName,
444
- attributes: attributes,
445
- timestamp: Date.now(),
446
- });
447
- }
448
- catch (error) {
449
- // Silent failure
450
- console.debug('Failed to track telemetry event:', error);
451
- }
452
- }
453
- /**
454
- * Get enriched attributes for telemetry events
455
- */
456
- getEnrichedAttributes(extraAttributes, eventName) {
457
- const attributes = {
458
- [APP_NAME]: SDK_SERVICE_NAME,
459
- [VERSION]: SDK_VERSION,
460
- [SERVICE]: eventName,
461
- [CLOUD_URL]: this.createCloudUrl(),
462
- [CLOUD_ORGANIZATION_NAME]: this.telemetryContext?.orgName || UNKNOWN,
463
- [CLOUD_TENANT_NAME]: this.telemetryContext?.tenantName || UNKNOWN,
464
- [CLOUD_REDIRECT_URI]: this.telemetryContext?.redirectUri || UNKNOWN,
465
- [CLOUD_CLIENT_ID]: this.telemetryContext?.clientId || UNKNOWN,
466
- ...extraAttributes,
467
- };
468
- return attributes;
469
- }
470
- /**
471
- * Create cloud URL from base URL, organization ID, and tenant ID
472
- */
473
- createCloudUrl() {
474
- const baseUrl = this.telemetryContext?.baseUrl;
475
- const orgId = this.telemetryContext?.orgName;
476
- const tenantId = this.telemetryContext?.tenantName;
477
- if (!baseUrl || !orgId || !tenantId) {
478
- return UNKNOWN;
479
- }
480
- return `${baseUrl}/${orgId}/${tenantId}`;
481
- }
482
- }
483
- // Export singleton instance
484
- const telemetryClient = TelemetryClient.getInstance();
276
+ * SDK Telemetry constants.
277
+ *
278
+ * Only the SDK's identity (version, service name, role name, …) lives
279
+ * here. The Application Insights connection string is injected into
280
+ * `@uipath/core-telemetry` itself at publish time, and the generic attribute
281
+ * keys (`Version`, `Service`, `CloudOrganizationName`, …) are owned by
282
+ * `@uipath/core-telemetry` and consumed there — they are not part of the
283
+ * SDK's public API.
284
+ */
285
+ /** SDK version placeholder — patched by the SDK publish workflow. */
286
+ const CLOUD_ROLE_NAME = 'uipath-ts-sdk';
485
287
 
486
288
  /**
487
- * SDK Track decorator and function for telemetry
488
- */
489
- /**
490
- * Common tracking logic shared between method and function decorators
491
- */
492
- function createTrackedFunction(originalFunction, nameOrOptions, fallbackName, opts) {
493
- return function (...args) {
494
- // Determine if we should track this call
495
- let shouldTrack = true;
496
- if (opts.condition !== undefined) {
497
- if (typeof opts.condition === 'function') {
498
- shouldTrack = opts.condition.apply(this, args);
499
- }
500
- else {
501
- shouldTrack = opts.condition;
502
- }
503
- }
504
- // Track the event if enabled
505
- if (shouldTrack) {
506
- // Use the full name provided in the decorator (e.g., "Queue.GetAll")
507
- const serviceMethod = typeof nameOrOptions === 'string'
508
- ? nameOrOptions
509
- : fallbackName;
510
- // Use 'Sdk.Run' as the name and serviceMethod as the service
511
- telemetryClient.track(serviceMethod, SDK_RUN_EVENT, opts.attributes);
512
- }
513
- // Execute the original function
514
- return originalFunction.apply(this, args);
515
- };
516
- }
517
- /**
518
- * Track decorator that can be used to automatically track function calls
519
- *
520
- * Usage:
521
- * @track("Service.Method")
522
- * function myFunction() { ... }
523
- *
524
- * @track("Queue.GetAll")
525
- * async getAll() { ... }
289
+ * UiPath TypeScript SDK Telemetry
526
290
  *
527
- * @track("Tasks.Create")
528
- * async create() { ... }
529
- *
530
- * @track("Assets.Update", { condition: false })
531
- * function myFunction() { ... }
532
- *
533
- * @track("Processes.Start", { attributes: { customProp: "value" } })
534
- * function myFunction() { ... }
535
- */
536
- function track(nameOrOptions, options) {
537
- return function decorator(_target, propertyKey, descriptor) {
538
- const opts = typeof nameOrOptions === 'object' ? nameOrOptions : {};
539
- if (descriptor && typeof descriptor.value === 'function') {
540
- // Method decorator
541
- descriptor.value = createTrackedFunction(descriptor.value, nameOrOptions, propertyKey || 'unknown_method', opts);
542
- return descriptor;
543
- }
544
- // Function decorator
545
- return (originalFunction) => createTrackedFunction(originalFunction, nameOrOptions, originalFunction.name || 'unknown_function', opts);
546
- };
547
- }
291
+ * Constructs the SDK's own `TelemetryClient` and binds the SDK-local
292
+ * `track` / `trackEvent` to it. Each consumer of `@uipath/core-telemetry`
293
+ * does this independently, so events carry their own consumer's identity
294
+ * and tenant context.
295
+ */
296
+ // Keyed by `CLOUD_ROLE_NAME` so every SDK subpath bundle resolves to the
297
+ // same `TelemetryClient` instance at runtime. A single `initialize(...)`
298
+ // from the `UiPath` constructor therefore wires up `@track` decorators
299
+ // across every subpath bundle (`assets`, `feedback`, `tasks`, …).
300
+ const sdkClient = coreTelemetry.getOrCreateClient(CLOUD_ROLE_NAME);
301
+ const track = coreTelemetry.createTrack(sdkClient);
302
+ coreTelemetry.createTrackEvent(sdkClient);
548
303
 
549
304
  exports.TaskUserType = void 0;
550
305
  (function (TaskUserType) {
@@ -1404,9 +1159,9 @@ class PaginationHelpers {
1404
1159
  * @returns Promise resolving to a paginated result
1405
1160
  */
1406
1161
  static async getAllPaginated(params) {
1407
- const { serviceAccess, getEndpoint, folderId, paginationParams, additionalParams, transformFn, method = HTTP_METHODS.GET, options = {} } = params;
1162
+ const { serviceAccess, getEndpoint, folderId, headers: providedHeaders, paginationParams, additionalParams, transformFn, method = HTTP_METHODS.GET, options = {} } = params;
1408
1163
  const endpoint = getEndpoint(folderId);
1409
- const headers = folderId ? createHeaders({ [FOLDER_ID]: folderId }) : {};
1164
+ const headers = providedHeaders ?? (folderId ? createHeaders({ [FOLDER_ID]: folderId }) : {});
1410
1165
  const paginatedResponse = await serviceAccess.requestWithPagination(method, endpoint, paginationParams, {
1411
1166
  headers,
1412
1167
  params: additionalParams,
@@ -1434,13 +1189,13 @@ class PaginationHelpers {
1434
1189
  * @returns Promise resolving to an object with data and totalCount
1435
1190
  */
1436
1191
  static async getAllNonPaginated(params) {
1437
- const { serviceAccess, getAllEndpoint, getByFolderEndpoint, folderId, additionalParams, transformFn, method = HTTP_METHODS.GET, options = {} } = params;
1192
+ const { serviceAccess, getAllEndpoint, getByFolderEndpoint, folderId, headers: providedHeaders, additionalParams, transformFn, method = HTTP_METHODS.GET, options = {} } = params;
1438
1193
  // Set default field names
1439
1194
  const itemsField = options.itemsField || DEFAULT_ITEMS_FIELD;
1440
1195
  const totalCountField = options.totalCountField || DEFAULT_TOTAL_COUNT_FIELD;
1441
1196
  // Determine endpoint and headers based on folderId
1442
1197
  const endpoint = folderId ? getByFolderEndpoint : getAllEndpoint;
1443
- const headers = folderId ? createHeaders({ [FOLDER_ID]: folderId }) : {};
1198
+ const headers = providedHeaders ?? (folderId ? createHeaders({ [FOLDER_ID]: folderId }) : {});
1444
1199
  // Make the API call based on method
1445
1200
  let response;
1446
1201
  if (method === HTTP_METHODS.POST) {
@@ -1499,6 +1254,7 @@ class PaginationHelpers {
1499
1254
  serviceAccess: config.serviceAccess,
1500
1255
  getEndpoint: config.getEndpoint,
1501
1256
  folderId,
1257
+ headers: config.headers,
1502
1258
  paginationParams: cursor ? { cursor, pageSize } : jumpToPage ? { jumpToPage, pageSize } : { pageSize },
1503
1259
  additionalParams: prefixedOptions,
1504
1260
  transformFn: config.transformFn,
@@ -1516,6 +1272,7 @@ class PaginationHelpers {
1516
1272
  getAllEndpoint: config.getEndpoint(),
1517
1273
  getByFolderEndpoint: byFolderEndpoint,
1518
1274
  folderId,
1275
+ headers: config.headers,
1519
1276
  additionalParams: prefixedOptions,
1520
1277
  transformFn: config.transformFn,
1521
1278
  method: config.method,
@@ -1845,14 +1602,25 @@ class ApiClient {
1845
1602
  if (!text) {
1846
1603
  return undefined;
1847
1604
  }
1848
- return JSON.parse(text);
1605
+ try {
1606
+ return JSON.parse(text);
1607
+ }
1608
+ catch (error) {
1609
+ if (error instanceof SyntaxError) {
1610
+ throw new ServerError({
1611
+ message: `Server returned non-JSON response (${response.status} ${response.url}): ${error.message}`,
1612
+ statusCode: response.status,
1613
+ });
1614
+ }
1615
+ throw error;
1616
+ }
1849
1617
  }
1850
1618
  catch (error) {
1851
1619
  // If it's already one of our errors, re-throw it
1852
1620
  if (error.type && error.type.includes('Error')) {
1853
1621
  throw error;
1854
1622
  }
1855
- // Otherwise, it's likely a network error
1623
+ // Otherwise, it's a genuine network/fetch failure
1856
1624
  throw ErrorFactory.createNetworkError(error);
1857
1625
  }
1858
1626
  }