@uipath/uipath-typescript 1.0.0 → 1.1.1

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