@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.
@@ -475,277 +475,33 @@ const BUCKET_TOKEN_PARAMS = {
475
475
  };
476
476
 
477
477
  /**
478
- * SDK Telemetry constants
478
+ * SDK Telemetry constants.
479
+ *
480
+ * Only the SDK's identity (version, service name, role name, …) lives
481
+ * here. The Application Insights connection string is injected into
482
+ * `@uipath/core-telemetry` itself at publish time, and the generic attribute
483
+ * keys (`Version`, `Service`, `CloudOrganizationName`, …) are owned by
484
+ * `@uipath/core-telemetry` and consumed there — they are not part of the
485
+ * SDK's public API.
479
486
  */
480
- // Connection string placeholder that will be replaced during build
481
- 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";
482
- // SDK Version placeholder
483
- const SDK_VERSION = "1.3.8";
484
- const VERSION = "Version";
485
- const SERVICE = "Service";
486
- const CLOUD_ORGANIZATION_NAME = "CloudOrganizationName";
487
- const CLOUD_TENANT_NAME = "CloudTenantName";
488
- const CLOUD_URL = "CloudUrl";
489
- const CLOUD_CLIENT_ID = "CloudClientId";
490
- const CLOUD_REDIRECT_URI = "CloudRedirectUri";
491
- const APP_NAME = "ApplicationName";
492
- const CLOUD_ROLE_NAME = "uipath-ts-sdk";
493
- // Service and logger names
494
- const SDK_SERVICE_NAME = "UiPath.TypeScript.Sdk";
495
- const SDK_LOGGER_NAME = "uipath-ts-sdk-telemetry";
496
- // Event names
497
- const SDK_RUN_EVENT = "Sdk.Run";
498
- // Default value for unknown/empty attributes
499
- const UNKNOWN = "";
487
+ /** SDK version placeholder patched by the SDK publish workflow. */
488
+ const CLOUD_ROLE_NAME = 'uipath-ts-sdk';
500
489
 
501
490
  /**
502
- * Log exporter that sends ALL logs as Application Insights custom events
503
- */
504
- class ApplicationInsightsEventExporter {
505
- constructor(connectionString) {
506
- this.connectionString = connectionString;
507
- }
508
- export(logs, resultCallback) {
509
- try {
510
- logs.forEach(logRecord => {
511
- this.sendAsCustomEvent(logRecord);
512
- });
513
- resultCallback({ code: 0 });
514
- }
515
- catch (error) {
516
- console.debug('Failed to export logs to Application Insights:', error);
517
- resultCallback({ code: 2, error });
518
- }
519
- }
520
- shutdown() {
521
- return Promise.resolve();
522
- }
523
- sendAsCustomEvent(logRecord) {
524
- // Get event name from body or attributes
525
- const eventName = logRecord.body || SDK_RUN_EVENT;
526
- const payload = {
527
- name: 'Microsoft.ApplicationInsights.Event',
528
- time: new Date().toISOString(),
529
- iKey: this.extractInstrumentationKey(),
530
- data: {
531
- baseType: 'EventData',
532
- baseData: {
533
- ver: 2,
534
- name: eventName,
535
- properties: this.convertAttributesToProperties(logRecord.attributes || {})
536
- }
537
- },
538
- tags: {
539
- 'ai.cloud.role': CLOUD_ROLE_NAME,
540
- 'ai.cloud.roleInstance': SDK_VERSION
541
- }
542
- };
543
- this.sendToApplicationInsights(payload);
544
- }
545
- extractInstrumentationKey() {
546
- const match = this.connectionString.match(/InstrumentationKey=([^;]+)/);
547
- return match ? match[1] : '';
548
- }
549
- convertAttributesToProperties(attributes) {
550
- const properties = {};
551
- Object.entries(attributes || {}).forEach(([key, value]) => {
552
- properties[key] = String(value);
553
- });
554
- return properties;
555
- }
556
- async sendToApplicationInsights(payload) {
557
- try {
558
- const ingestionEndpoint = this.extractIngestionEndpoint();
559
- if (!ingestionEndpoint) {
560
- console.debug('No ingestion endpoint found in connection string');
561
- return;
562
- }
563
- const url = `${ingestionEndpoint}/v2/track`;
564
- const response = await fetch(url, {
565
- method: 'POST',
566
- headers: {
567
- 'Content-Type': 'application/json',
568
- },
569
- body: JSON.stringify(payload)
570
- });
571
- if (!response.ok) {
572
- console.debug(`Failed to send event telemetry: ${response.status} ${response.statusText}`);
573
- }
574
- }
575
- catch (error) {
576
- console.debug('Error sending event telemetry to Application Insights:', error);
577
- }
578
- }
579
- extractIngestionEndpoint() {
580
- const match = this.connectionString.match(/IngestionEndpoint=([^;]+)/);
581
- return match ? match[1] : '';
582
- }
583
- }
584
- /**
585
- * Singleton telemetry client
586
- */
587
- class TelemetryClient {
588
- constructor() {
589
- this.isInitialized = false;
590
- }
591
- static getInstance() {
592
- if (!TelemetryClient.instance) {
593
- TelemetryClient.instance = new TelemetryClient();
594
- }
595
- return TelemetryClient.instance;
596
- }
597
- /**
598
- * Initialize telemetry
599
- */
600
- initialize(config) {
601
- if (this.isInitialized) {
602
- return;
603
- }
604
- this.isInitialized = true;
605
- if (config) {
606
- this.telemetryContext = config;
607
- }
608
- try {
609
- const connectionString = this.getConnectionString();
610
- if (!connectionString) {
611
- return;
612
- }
613
- this.setupTelemetryProvider(connectionString);
614
- }
615
- catch (error) {
616
- // Silent failure - telemetry errors shouldn't break functionality
617
- console.debug('Failed to initialize OpenTelemetry:', error);
618
- }
619
- }
620
- getConnectionString() {
621
- const connectionString = CONNECTION_STRING;
622
- return connectionString;
623
- }
624
- setupTelemetryProvider(connectionString) {
625
- const exporter = new ApplicationInsightsEventExporter(connectionString);
626
- const processor = new sdkLogs.BatchLogRecordProcessor(exporter);
627
- this.logProvider = new sdkLogs.LoggerProvider({
628
- processors: [processor]
629
- });
630
- this.logger = this.logProvider.getLogger(SDK_LOGGER_NAME);
631
- }
632
- /**
633
- * Track a telemetry event
634
- */
635
- track(eventName, name, extraAttributes = {}) {
636
- try {
637
- // Skip if logger not initialized
638
- if (!this.logger) {
639
- return;
640
- }
641
- const finalDisplayName = name || eventName;
642
- const attributes = this.getEnrichedAttributes(extraAttributes, eventName);
643
- // Emit as log
644
- this.logger.emit({
645
- body: finalDisplayName,
646
- attributes: attributes,
647
- timestamp: Date.now(),
648
- });
649
- }
650
- catch (error) {
651
- // Silent failure
652
- console.debug('Failed to track telemetry event:', error);
653
- }
654
- }
655
- /**
656
- * Get enriched attributes for telemetry events
657
- */
658
- getEnrichedAttributes(extraAttributes, eventName) {
659
- const attributes = {
660
- [APP_NAME]: SDK_SERVICE_NAME,
661
- [VERSION]: SDK_VERSION,
662
- [SERVICE]: eventName,
663
- [CLOUD_URL]: this.createCloudUrl(),
664
- [CLOUD_ORGANIZATION_NAME]: this.telemetryContext?.orgName || UNKNOWN,
665
- [CLOUD_TENANT_NAME]: this.telemetryContext?.tenantName || UNKNOWN,
666
- [CLOUD_REDIRECT_URI]: this.telemetryContext?.redirectUri || UNKNOWN,
667
- [CLOUD_CLIENT_ID]: this.telemetryContext?.clientId || UNKNOWN,
668
- ...extraAttributes,
669
- };
670
- return attributes;
671
- }
672
- /**
673
- * Create cloud URL from base URL, organization ID, and tenant ID
674
- */
675
- createCloudUrl() {
676
- const baseUrl = this.telemetryContext?.baseUrl;
677
- const orgId = this.telemetryContext?.orgName;
678
- const tenantId = this.telemetryContext?.tenantName;
679
- if (!baseUrl || !orgId || !tenantId) {
680
- return UNKNOWN;
681
- }
682
- return `${baseUrl}/${orgId}/${tenantId}`;
683
- }
684
- }
685
- // Export singleton instance
686
- const telemetryClient = TelemetryClient.getInstance();
687
-
688
- /**
689
- * SDK Track decorator and function for telemetry
690
- */
691
- /**
692
- * Common tracking logic shared between method and function decorators
693
- */
694
- function createTrackedFunction(originalFunction, nameOrOptions, fallbackName, opts) {
695
- return function (...args) {
696
- // Determine if we should track this call
697
- let shouldTrack = true;
698
- if (opts.condition !== undefined) {
699
- if (typeof opts.condition === 'function') {
700
- shouldTrack = opts.condition.apply(this, args);
701
- }
702
- else {
703
- shouldTrack = opts.condition;
704
- }
705
- }
706
- // Track the event if enabled
707
- if (shouldTrack) {
708
- // Use the full name provided in the decorator (e.g., "Queue.GetAll")
709
- const serviceMethod = nameOrOptions
710
- ;
711
- // Use 'Sdk.Run' as the name and serviceMethod as the service
712
- telemetryClient.track(serviceMethod, SDK_RUN_EVENT, opts.attributes);
713
- }
714
- // Execute the original function
715
- return originalFunction.apply(this, args);
716
- };
717
- }
718
- /**
719
- * Track decorator that can be used to automatically track function calls
720
- *
721
- * Usage:
722
- * @track("Service.Method")
723
- * function myFunction() { ... }
491
+ * UiPath TypeScript SDK Telemetry
724
492
  *
725
- * @track("Queue.GetAll")
726
- * async getAll() { ... }
727
- *
728
- * @track("Tasks.Create")
729
- * async create() { ... }
730
- *
731
- * @track("Assets.Update", { condition: false })
732
- * function myFunction() { ... }
733
- *
734
- * @track("Processes.Start", { attributes: { customProp: "value" } })
735
- * function myFunction() { ... }
493
+ * Constructs the SDK's own `TelemetryClient` and binds the SDK-local
494
+ * `track` / `trackEvent` to it. Each consumer of `@uipath/core-telemetry`
495
+ * does this independently, so events carry their own consumer's identity
496
+ * and tenant context.
736
497
  */
737
- function track(nameOrOptions, options) {
738
- return function decorator(_target, propertyKey, descriptor) {
739
- const opts = {};
740
- if (descriptor && typeof descriptor.value === 'function') {
741
- // Method decorator
742
- descriptor.value = createTrackedFunction(descriptor.value, nameOrOptions, propertyKey || 'unknown_method', opts);
743
- return descriptor;
744
- }
745
- // Function decorator
746
- return (originalFunction) => createTrackedFunction(originalFunction, nameOrOptions, originalFunction.name || 'unknown_function', opts);
747
- };
748
- }
498
+ // Keyed by `CLOUD_ROLE_NAME` so every SDK subpath bundle resolves to the
499
+ // same `TelemetryClient` instance at runtime. A single `initialize(...)`
500
+ // from the `UiPath` constructor therefore wires up `@track` decorators
501
+ // across every subpath bundle (`assets`, `feedback`, `tasks`, …).
502
+ const sdkClient = coreTelemetry.getOrCreateClient(CLOUD_ROLE_NAME);
503
+ const track = coreTelemetry.createTrack(sdkClient);
504
+ coreTelemetry.createTrackEvent(sdkClient);
749
505
 
750
506
  /**
751
507
  * Maps fields for Attachment entities to ensure consistent naming
@@ -1094,14 +850,25 @@ class ApiClient {
1094
850
  if (!text) {
1095
851
  return undefined;
1096
852
  }
1097
- return JSON.parse(text);
853
+ try {
854
+ return JSON.parse(text);
855
+ }
856
+ catch (error) {
857
+ if (error instanceof SyntaxError) {
858
+ throw new ServerError({
859
+ message: `Server returned non-JSON response (${response.status} ${response.url}): ${error.message}`,
860
+ statusCode: response.status,
861
+ });
862
+ }
863
+ throw error;
864
+ }
1098
865
  }
1099
866
  catch (error) {
1100
867
  // If it's already one of our errors, re-throw it
1101
868
  if (error.type && error.type.includes('Error')) {
1102
869
  throw error;
1103
870
  }
1104
- // Otherwise, it's likely a network error
871
+ // Otherwise, it's a genuine network/fetch failure
1105
872
  throw ErrorFactory.createNetworkError(error);
1106
873
  }
1107
874
  }
@@ -1506,9 +1273,9 @@ class PaginationHelpers {
1506
1273
  * @returns Promise resolving to a paginated result
1507
1274
  */
1508
1275
  static async getAllPaginated(params) {
1509
- const { serviceAccess, getEndpoint, folderId, paginationParams, additionalParams, transformFn, method = HTTP_METHODS.GET, options = {} } = params;
1276
+ const { serviceAccess, getEndpoint, folderId, headers: providedHeaders, paginationParams, additionalParams, transformFn, method = HTTP_METHODS.GET, options = {} } = params;
1510
1277
  const endpoint = getEndpoint(folderId);
1511
- const headers = folderId ? createHeaders({ [FOLDER_ID]: folderId }) : {};
1278
+ const headers = providedHeaders ?? (folderId ? createHeaders({ [FOLDER_ID]: folderId }) : {});
1512
1279
  const paginatedResponse = await serviceAccess.requestWithPagination(method, endpoint, paginationParams, {
1513
1280
  headers,
1514
1281
  params: additionalParams,
@@ -1536,13 +1303,13 @@ class PaginationHelpers {
1536
1303
  * @returns Promise resolving to an object with data and totalCount
1537
1304
  */
1538
1305
  static async getAllNonPaginated(params) {
1539
- const { serviceAccess, getAllEndpoint, getByFolderEndpoint, folderId, additionalParams, transformFn, method = HTTP_METHODS.GET, options = {} } = params;
1306
+ const { serviceAccess, getAllEndpoint, getByFolderEndpoint, folderId, headers: providedHeaders, additionalParams, transformFn, method = HTTP_METHODS.GET, options = {} } = params;
1540
1307
  // Set default field names
1541
1308
  const itemsField = options.itemsField || DEFAULT_ITEMS_FIELD;
1542
1309
  const totalCountField = options.totalCountField || DEFAULT_TOTAL_COUNT_FIELD;
1543
1310
  // Determine endpoint and headers based on folderId
1544
1311
  const endpoint = folderId ? getByFolderEndpoint : getAllEndpoint;
1545
- const headers = folderId ? createHeaders({ [FOLDER_ID]: folderId }) : {};
1312
+ const headers = providedHeaders ?? (folderId ? createHeaders({ [FOLDER_ID]: folderId }) : {});
1546
1313
  // Make the API call based on method
1547
1314
  let response;
1548
1315
  if (method === HTTP_METHODS.POST) {
@@ -1601,6 +1368,7 @@ class PaginationHelpers {
1601
1368
  serviceAccess: config.serviceAccess,
1602
1369
  getEndpoint: config.getEndpoint,
1603
1370
  folderId,
1371
+ headers: config.headers,
1604
1372
  paginationParams: cursor ? { cursor, pageSize } : jumpToPage ? { jumpToPage, pageSize } : { pageSize },
1605
1373
  additionalParams: prefixedOptions,
1606
1374
  transformFn: config.transformFn,
@@ -1618,6 +1386,7 @@ class PaginationHelpers {
1618
1386
  getAllEndpoint: config.getEndpoint(),
1619
1387
  getByFolderEndpoint: byFolderEndpoint,
1620
1388
  folderId,
1389
+ headers: config.headers,
1621
1390
  additionalParams: prefixedOptions,
1622
1391
  transformFn: config.transformFn,
1623
1392
  method: config.method,