@uipath/uipath-typescript 1.0.0 → 1.1.0

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.
@@ -55,40 +55,31 @@ var ProcessType;
55
55
  })(ProcessType || (ProcessType = {}));
56
56
 
57
57
  /**
58
- * Base error class for all UiPath SDK errors
59
- * Pure TypeScript class with clean interface
58
+ * Type guards for error response types
60
59
  */
61
- class UiPathError {
62
- constructor(type, params) {
63
- this.type = type;
64
- this.message = params.message;
65
- this.statusCode = params.statusCode;
66
- this.requestId = params.requestId;
67
- this.timestamp = new Date();
68
- // Capture stack trace for debugging
69
- this.stack = (new Error()).stack;
70
- }
71
- /**
72
- * Returns a clean JSON representation of the error
73
- */
74
- toJSON() {
75
- return {
76
- type: this.type,
77
- message: this.message,
78
- statusCode: this.statusCode,
79
- requestId: this.requestId,
80
- timestamp: this.timestamp
81
- };
82
- }
83
- /**
84
- * Returns detailed debug information including stack trace
85
- */
86
- getDebugInfo() {
87
- return {
88
- ...this.toJSON(),
89
- stack: this.stack
90
- };
91
- }
60
+ function isOrchestratorError(error) {
61
+ return typeof error === 'object' &&
62
+ error !== null &&
63
+ 'message' in error &&
64
+ 'errorCode' in error &&
65
+ typeof error.message === 'string' &&
66
+ typeof error.errorCode === 'number';
67
+ }
68
+ function isEntityError(error) {
69
+ return typeof error === 'object' &&
70
+ error !== null &&
71
+ 'error' in error &&
72
+ typeof error.error === 'string';
73
+ }
74
+ function isPimsError(error) {
75
+ return typeof error === 'object' &&
76
+ error !== null &&
77
+ 'type' in error &&
78
+ 'title' in error &&
79
+ 'status' in error &&
80
+ typeof error.type === 'string' &&
81
+ typeof error.title === 'string' &&
82
+ typeof error.status === 'number';
92
83
  }
93
84
 
94
85
  /**
@@ -152,161 +143,6 @@ const ErrorMessages = {
152
143
  const ErrorNames = {
153
144
  ABORT_ERROR: 'AbortError'};
154
145
 
155
- /**
156
- * Error thrown when authentication fails (401 errors)
157
- * Common scenarios:
158
- * - Invalid credentials
159
- * - Expired token
160
- * - Missing authentication
161
- */
162
- class AuthenticationError extends UiPathError {
163
- constructor(params = {}) {
164
- super(ErrorType.AUTHENTICATION, {
165
- message: params.message || ErrorMessages.AUTHENTICATION_FAILED,
166
- statusCode: params.statusCode ?? HttpStatus.UNAUTHORIZED,
167
- requestId: params.requestId
168
- });
169
- }
170
- }
171
-
172
- /**
173
- * Error thrown when authorization fails (403 errors)
174
- * Common scenarios:
175
- * - Insufficient permissions
176
- * - Access denied to resource
177
- * - Invalid scope
178
- */
179
- class AuthorizationError extends UiPathError {
180
- constructor(params = {}) {
181
- super(ErrorType.AUTHORIZATION, {
182
- message: params.message || ErrorMessages.ACCESS_DENIED,
183
- statusCode: params.statusCode ?? HttpStatus.FORBIDDEN,
184
- requestId: params.requestId
185
- });
186
- }
187
- }
188
-
189
- /**
190
- * Error thrown when validation fails (400 errors or client-side validation)
191
- * Common scenarios:
192
- * - Invalid input parameters
193
- * - Missing required fields
194
- * - Invalid data format
195
- */
196
- class ValidationError extends UiPathError {
197
- constructor(params = {}) {
198
- super(ErrorType.VALIDATION, {
199
- message: params.message || ErrorMessages.VALIDATION_FAILED,
200
- statusCode: params.statusCode ?? HttpStatus.BAD_REQUEST,
201
- requestId: params.requestId
202
- });
203
- }
204
- }
205
-
206
- /**
207
- * Error thrown when a resource is not found (404 errors)
208
- * Common scenarios:
209
- * - Resource doesn't exist
210
- * - Invalid ID provided
211
- * - Resource deleted
212
- */
213
- class NotFoundError extends UiPathError {
214
- constructor(params = {}) {
215
- super(ErrorType.NOT_FOUND, {
216
- message: params.message || ErrorMessages.RESOURCE_NOT_FOUND,
217
- statusCode: params.statusCode ?? HttpStatus.NOT_FOUND,
218
- requestId: params.requestId
219
- });
220
- }
221
- }
222
-
223
- /**
224
- * Error thrown when rate limit is exceeded (429 errors)
225
- * Common scenarios:
226
- * - Too many requests in a time window
227
- * - API throttling
228
- */
229
- class RateLimitError extends UiPathError {
230
- constructor(params = {}) {
231
- super(ErrorType.RATE_LIMIT, {
232
- message: params.message || ErrorMessages.RATE_LIMIT_EXCEEDED,
233
- statusCode: params.statusCode ?? HttpStatus.TOO_MANY_REQUESTS,
234
- requestId: params.requestId
235
- });
236
- }
237
- }
238
-
239
- /**
240
- * Error thrown when server encounters an error (5xx errors)
241
- * Common scenarios:
242
- * - Internal server error
243
- * - Service unavailable
244
- * - Gateway timeout
245
- */
246
- class ServerError extends UiPathError {
247
- constructor(params = {}) {
248
- super(ErrorType.SERVER, {
249
- message: params.message || ErrorMessages.INTERNAL_SERVER_ERROR,
250
- statusCode: params.statusCode ?? HttpStatus.INTERNAL_SERVER_ERROR,
251
- requestId: params.requestId
252
- });
253
- }
254
- /**
255
- * Checks if this is a temporary error that might succeed on retry
256
- */
257
- get isRetryable() {
258
- return this.statusCode === HttpStatus.BAD_GATEWAY ||
259
- this.statusCode === HttpStatus.SERVICE_UNAVAILABLE ||
260
- this.statusCode === HttpStatus.GATEWAY_TIMEOUT;
261
- }
262
- }
263
-
264
- /**
265
- * Error thrown when network/connection issues occur
266
- * Common scenarios:
267
- * - Connection timeout
268
- * - DNS resolution failure
269
- * - Network unreachable
270
- * - Request aborted
271
- */
272
- class NetworkError extends UiPathError {
273
- constructor(params = {}) {
274
- super(ErrorType.NETWORK, {
275
- message: params.message || ErrorMessages.NETWORK_ERROR,
276
- statusCode: params.statusCode, // Network errors typically don't have HTTP status codes
277
- requestId: params.requestId
278
- });
279
- }
280
- }
281
-
282
- /**
283
- * Type guards for error response types
284
- */
285
- function isOrchestratorError(error) {
286
- return typeof error === 'object' &&
287
- error !== null &&
288
- 'message' in error &&
289
- 'errorCode' in error &&
290
- typeof error.message === 'string' &&
291
- typeof error.errorCode === 'number';
292
- }
293
- function isEntityError(error) {
294
- return typeof error === 'object' &&
295
- error !== null &&
296
- 'error' in error &&
297
- typeof error.error === 'string';
298
- }
299
- function isPimsError(error) {
300
- return typeof error === 'object' &&
301
- error !== null &&
302
- 'type' in error &&
303
- 'title' in error &&
304
- 'status' in error &&
305
- typeof error.type === 'string' &&
306
- typeof error.title === 'string' &&
307
- typeof error.status === 'number';
308
- }
309
-
310
146
  /**
311
147
  * Parser for Orchestrator/Task error format
312
148
  */
@@ -457,6 +293,173 @@ class ErrorResponseParser {
457
293
  // Export singleton instance
458
294
  const errorResponseParser = new ErrorResponseParser();
459
295
 
296
+ /**
297
+ * Base error class for all UiPath SDK errors
298
+ * Extends Error for standard error handling compatibility
299
+ */
300
+ class UiPathError extends Error {
301
+ constructor(type, params) {
302
+ super(params.message);
303
+ this.name = type;
304
+ this.type = type;
305
+ this.statusCode = params.statusCode;
306
+ this.requestId = params.requestId;
307
+ this.timestamp = new Date();
308
+ // Maintains proper stack trace for where our error was thrown
309
+ if (Error.captureStackTrace) {
310
+ Error.captureStackTrace(this, this.constructor);
311
+ }
312
+ }
313
+ /**
314
+ * Returns a clean JSON representation of the error
315
+ */
316
+ toJSON() {
317
+ return {
318
+ type: this.type,
319
+ message: this.message,
320
+ statusCode: this.statusCode,
321
+ requestId: this.requestId,
322
+ timestamp: this.timestamp
323
+ };
324
+ }
325
+ /**
326
+ * Returns detailed debug information including stack trace
327
+ */
328
+ getDebugInfo() {
329
+ return {
330
+ ...this.toJSON(),
331
+ stack: this.stack
332
+ };
333
+ }
334
+ }
335
+
336
+ /**
337
+ * Error thrown when authentication fails (401 errors)
338
+ * Common scenarios:
339
+ * - Invalid credentials
340
+ * - Expired token
341
+ * - Missing authentication
342
+ */
343
+ class AuthenticationError extends UiPathError {
344
+ constructor(params = {}) {
345
+ super(ErrorType.AUTHENTICATION, {
346
+ message: params.message || ErrorMessages.AUTHENTICATION_FAILED,
347
+ statusCode: params.statusCode ?? HttpStatus.UNAUTHORIZED,
348
+ requestId: params.requestId
349
+ });
350
+ }
351
+ }
352
+
353
+ /**
354
+ * Error thrown when authorization fails (403 errors)
355
+ * Common scenarios:
356
+ * - Insufficient permissions
357
+ * - Access denied to resource
358
+ * - Invalid scope
359
+ */
360
+ class AuthorizationError extends UiPathError {
361
+ constructor(params = {}) {
362
+ super(ErrorType.AUTHORIZATION, {
363
+ message: params.message || ErrorMessages.ACCESS_DENIED,
364
+ statusCode: params.statusCode ?? HttpStatus.FORBIDDEN,
365
+ requestId: params.requestId
366
+ });
367
+ }
368
+ }
369
+
370
+ /**
371
+ * Error thrown when validation fails (400 errors or client-side validation)
372
+ * Common scenarios:
373
+ * - Invalid input parameters
374
+ * - Missing required fields
375
+ * - Invalid data format
376
+ */
377
+ class ValidationError extends UiPathError {
378
+ constructor(params = {}) {
379
+ super(ErrorType.VALIDATION, {
380
+ message: params.message || ErrorMessages.VALIDATION_FAILED,
381
+ statusCode: params.statusCode ?? HttpStatus.BAD_REQUEST,
382
+ requestId: params.requestId
383
+ });
384
+ }
385
+ }
386
+
387
+ /**
388
+ * Error thrown when a resource is not found (404 errors)
389
+ * Common scenarios:
390
+ * - Resource doesn't exist
391
+ * - Invalid ID provided
392
+ * - Resource deleted
393
+ */
394
+ class NotFoundError extends UiPathError {
395
+ constructor(params = {}) {
396
+ super(ErrorType.NOT_FOUND, {
397
+ message: params.message || ErrorMessages.RESOURCE_NOT_FOUND,
398
+ statusCode: params.statusCode ?? HttpStatus.NOT_FOUND,
399
+ requestId: params.requestId
400
+ });
401
+ }
402
+ }
403
+
404
+ /**
405
+ * Error thrown when rate limit is exceeded (429 errors)
406
+ * Common scenarios:
407
+ * - Too many requests in a time window
408
+ * - API throttling
409
+ */
410
+ class RateLimitError extends UiPathError {
411
+ constructor(params = {}) {
412
+ super(ErrorType.RATE_LIMIT, {
413
+ message: params.message || ErrorMessages.RATE_LIMIT_EXCEEDED,
414
+ statusCode: params.statusCode ?? HttpStatus.TOO_MANY_REQUESTS,
415
+ requestId: params.requestId
416
+ });
417
+ }
418
+ }
419
+
420
+ /**
421
+ * Error thrown when server encounters an error (5xx errors)
422
+ * Common scenarios:
423
+ * - Internal server error
424
+ * - Service unavailable
425
+ * - Gateway timeout
426
+ */
427
+ class ServerError extends UiPathError {
428
+ constructor(params = {}) {
429
+ super(ErrorType.SERVER, {
430
+ message: params.message || ErrorMessages.INTERNAL_SERVER_ERROR,
431
+ statusCode: params.statusCode ?? HttpStatus.INTERNAL_SERVER_ERROR,
432
+ requestId: params.requestId
433
+ });
434
+ }
435
+ /**
436
+ * Checks if this is a temporary error that might succeed on retry
437
+ */
438
+ get isRetryable() {
439
+ return this.statusCode === HttpStatus.BAD_GATEWAY ||
440
+ this.statusCode === HttpStatus.SERVICE_UNAVAILABLE ||
441
+ this.statusCode === HttpStatus.GATEWAY_TIMEOUT;
442
+ }
443
+ }
444
+
445
+ /**
446
+ * Error thrown when network/connection issues occur
447
+ * Common scenarios:
448
+ * - Connection timeout
449
+ * - DNS resolution failure
450
+ * - Network unreachable
451
+ * - Request aborted
452
+ */
453
+ class NetworkError extends UiPathError {
454
+ constructor(params = {}) {
455
+ super(ErrorType.NETWORK, {
456
+ message: params.message || ErrorMessages.NETWORK_ERROR,
457
+ statusCode: params.statusCode, // Network errors typically don't have HTTP status codes
458
+ requestId: params.requestId
459
+ });
460
+ }
461
+ }
462
+
460
463
  /**
461
464
  * Factory for creating typed errors based on HTTP status codes
462
465
  * Follows the Factory pattern for clean error instantiation
@@ -551,29 +554,7 @@ class ApiClient {
551
554
  * @throws AuthenticationError if no token available or refresh fails
552
555
  */
553
556
  async getValidToken() {
554
- // Try to get token info from context
555
- const tokenInfo = this.executionContext.get('tokenInfo');
556
- if (!tokenInfo) {
557
- throw new AuthenticationError({ message: 'No authentication token available. Make sure to initialize the SDK first.' });
558
- }
559
- // For secret-based tokens, they never expire
560
- if (tokenInfo.type === 'secret') {
561
- return tokenInfo.token;
562
- }
563
- // If token is not expired, return it
564
- if (!this.tokenManager.isTokenExpired(tokenInfo)) {
565
- return tokenInfo.token;
566
- }
567
- try {
568
- const newToken = await this.tokenManager.refreshAccessToken();
569
- return newToken.access_token;
570
- }
571
- catch (error) {
572
- throw new AuthenticationError({
573
- message: `Token refresh failed: ${error.message}. Please re-authenticate.`,
574
- statusCode: HttpStatus.UNAUTHORIZED
575
- });
576
- }
557
+ return this.tokenManager.getValidToken();
577
558
  }
578
559
  async getDefaultHeaders() {
579
560
  // Get headers from execution context first
@@ -1430,10 +1411,7 @@ class PaginationHelpers {
1430
1411
  */
1431
1412
  static async getAll(config, options) {
1432
1413
  const optionsWithDefaults = options || {};
1433
- const { folderId, ...restOptions } = optionsWithDefaults;
1434
- const cursor = options?.cursor;
1435
- const pageSize = options?.pageSize;
1436
- const jumpToPage = options?.jumpToPage;
1414
+ const { folderId, pageSize, cursor, jumpToPage, ...restOptions } = optionsWithDefaults;
1437
1415
  // Determine if pagination is requested
1438
1416
  const isPaginationRequested = PaginationHelpers.hasPaginationParameters(options || {});
1439
1417
  // Process parameters (custom processing if provided, otherwise default)
@@ -1786,15 +1764,36 @@ class BaseService {
1786
1764
  }
1787
1765
  _BaseService_apiClient = new WeakMap();
1788
1766
 
1789
- /**
1790
- * API Endpoint Constants
1791
- * Centralized location for all API endpoints used throughout the SDK
1792
- */
1793
1767
  /**
1794
1768
  * Base path constants for different services
1795
1769
  */
1796
1770
  const ORCHESTRATOR_BASE = 'orchestrator_';
1797
1771
  const PIMS_BASE = 'pims_';
1772
+
1773
+ /**
1774
+ * Orchestrator Service Endpoints
1775
+ */
1776
+ /**
1777
+ * Task Service (Action Center) Endpoints
1778
+ */
1779
+ const TASK_ENDPOINTS = {
1780
+ CREATE_GENERIC_TASK: `${ORCHESTRATOR_BASE}/tasks/GenericTasks/CreateTask`,
1781
+ GET_TASK_USERS: (folderId) => `${ORCHESTRATOR_BASE}/odata/Tasks/UiPath.Server.Configuration.OData.GetTaskUsers(organizationUnitId=${folderId})`,
1782
+ GET_TASKS_ACROSS_FOLDERS: `${ORCHESTRATOR_BASE}/odata/Tasks/UiPath.Server.Configuration.OData.GetTasksAcrossFolders`,
1783
+ GET_TASKS_ACROSS_FOLDERS_ADMIN: `${ORCHESTRATOR_BASE}/odata/Tasks/UiPath.Server.Configuration.OData.GetTasksAcrossFoldersForAdmin`,
1784
+ GET_BY_ID: (id) => `${ORCHESTRATOR_BASE}/odata/Tasks(${id})`,
1785
+ ASSIGN_TASKS: `${ORCHESTRATOR_BASE}/odata/Tasks/UiPath.Server.Configuration.OData.AssignTasks`,
1786
+ REASSIGN_TASKS: `${ORCHESTRATOR_BASE}/odata/Tasks/UiPath.Server.Configuration.OData.ReassignTasks`,
1787
+ UNASSIGN_TASKS: `${ORCHESTRATOR_BASE}/odata/Tasks/UiPath.Server.Configuration.OData.UnassignTasks`,
1788
+ COMPLETE_FORM_TASK: `${ORCHESTRATOR_BASE}/forms/TaskForms/CompleteTask`,
1789
+ COMPLETE_APP_TASK: `${ORCHESTRATOR_BASE}/tasks/AppTasks/CompleteAppTask`,
1790
+ COMPLETE_GENERIC_TASK: `${ORCHESTRATOR_BASE}/tasks/GenericTasks/CompleteTask`,
1791
+ GET_TASK_FORM_BY_ID: `${ORCHESTRATOR_BASE}/forms/TaskForms/GetTaskFormById`,
1792
+ };
1793
+
1794
+ /**
1795
+ * Maestro Service Endpoints
1796
+ */
1798
1797
  /**
1799
1798
  * Maestro Process Service Endpoints
1800
1799
  */
@@ -1824,23 +1823,6 @@ const MAESTRO_ENDPOINTS = {
1824
1823
  REOPEN: (instanceId) => `${PIMS_BASE}/api/v1/cases/${instanceId}/reopen`,
1825
1824
  },
1826
1825
  };
1827
- /**
1828
- * Task Service (Action Center) Endpoints
1829
- */
1830
- const TASK_ENDPOINTS = {
1831
- CREATE_GENERIC_TASK: `${ORCHESTRATOR_BASE}/tasks/GenericTasks/CreateTask`,
1832
- GET_TASK_USERS: (folderId) => `${ORCHESTRATOR_BASE}/odata/Tasks/UiPath.Server.Configuration.OData.GetTaskUsers(organizationUnitId=${folderId})`,
1833
- GET_TASKS_ACROSS_FOLDERS: `${ORCHESTRATOR_BASE}/odata/Tasks/UiPath.Server.Configuration.OData.GetTasksAcrossFolders`,
1834
- GET_TASKS_ACROSS_FOLDERS_ADMIN: `${ORCHESTRATOR_BASE}/odata/Tasks/UiPath.Server.Configuration.OData.GetTasksAcrossFoldersForAdmin`,
1835
- GET_BY_ID: (id) => `${ORCHESTRATOR_BASE}/odata/Tasks(${id})`,
1836
- ASSIGN_TASKS: `${ORCHESTRATOR_BASE}/odata/Tasks/UiPath.Server.Configuration.OData.AssignTasks`,
1837
- REASSIGN_TASKS: `${ORCHESTRATOR_BASE}/odata/Tasks/UiPath.Server.Configuration.OData.ReassignTasks`,
1838
- UNASSIGN_TASKS: `${ORCHESTRATOR_BASE}/odata/Tasks/UiPath.Server.Configuration.OData.UnassignTasks`,
1839
- COMPLETE_FORM_TASK: `${ORCHESTRATOR_BASE}/forms/TaskForms/CompleteTask`,
1840
- COMPLETE_APP_TASK: `${ORCHESTRATOR_BASE}/tasks/AppTasks/CompleteAppTask`,
1841
- COMPLETE_GENERIC_TASK: `${ORCHESTRATOR_BASE}/tasks/GenericTasks/CompleteTask`,
1842
- GET_TASK_FORM_BY_ID: `${ORCHESTRATOR_BASE}/forms/TaskForms/GetTaskFormById`,
1843
- };
1844
1826
 
1845
1827
  /**
1846
1828
  * SDK Telemetry constants
@@ -1848,7 +1830,7 @@ const TASK_ENDPOINTS = {
1848
1830
  // Connection string placeholder that will be replaced during build
1849
1831
  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";
1850
1832
  // SDK Version placeholder
1851
- const SDK_VERSION = "1.0.0";
1833
+ const SDK_VERSION = "1.1.0";
1852
1834
  const VERSION = "Version";
1853
1835
  const SERVICE = "Service";
1854
1836
  const CLOUD_ORGANIZATION_NAME = "CloudOrganizationName";
@@ -2025,7 +2007,6 @@ class TelemetryClient {
2025
2007
  */
2026
2008
  getEnrichedAttributes(extraAttributes, eventName) {
2027
2009
  const attributes = {
2028
- ...extraAttributes,
2029
2010
  [APP_NAME]: SDK_SERVICE_NAME,
2030
2011
  [VERSION]: SDK_VERSION,
2031
2012
  [SERVICE]: eventName,
@@ -2034,6 +2015,7 @@ class TelemetryClient {
2034
2015
  [CLOUD_TENANT_NAME]: this.telemetryContext?.tenantName || UNKNOWN,
2035
2016
  [CLOUD_REDIRECT_URI]: this.telemetryContext?.redirectUri || UNKNOWN,
2036
2017
  [CLOUD_CLIENT_ID]: this.telemetryContext?.clientId || UNKNOWN,
2018
+ ...extraAttributes,
2037
2019
  };
2038
2020
  return attributes;
2039
2021
  }