@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.
@@ -45,40 +45,31 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
45
45
  };
46
46
 
47
47
  /**
48
- * Base error class for all UiPath SDK errors
49
- * Pure TypeScript class with clean interface
48
+ * Type guards for error response types
50
49
  */
51
- class UiPathError {
52
- constructor(type, params) {
53
- this.type = type;
54
- this.message = params.message;
55
- this.statusCode = params.statusCode;
56
- this.requestId = params.requestId;
57
- this.timestamp = new Date();
58
- // Capture stack trace for debugging
59
- this.stack = (new Error()).stack;
60
- }
61
- /**
62
- * Returns a clean JSON representation of the error
63
- */
64
- toJSON() {
65
- return {
66
- type: this.type,
67
- message: this.message,
68
- statusCode: this.statusCode,
69
- requestId: this.requestId,
70
- timestamp: this.timestamp
71
- };
72
- }
73
- /**
74
- * Returns detailed debug information including stack trace
75
- */
76
- getDebugInfo() {
77
- return {
78
- ...this.toJSON(),
79
- stack: this.stack
80
- };
81
- }
50
+ function isOrchestratorError(error) {
51
+ return typeof error === 'object' &&
52
+ error !== null &&
53
+ 'message' in error &&
54
+ 'errorCode' in error &&
55
+ typeof error.message === 'string' &&
56
+ typeof error.errorCode === 'number';
57
+ }
58
+ function isEntityError(error) {
59
+ return typeof error === 'object' &&
60
+ error !== null &&
61
+ 'error' in error &&
62
+ typeof error.error === 'string';
63
+ }
64
+ function isPimsError(error) {
65
+ return typeof error === 'object' &&
66
+ error !== null &&
67
+ 'type' in error &&
68
+ 'title' in error &&
69
+ 'status' in error &&
70
+ typeof error.type === 'string' &&
71
+ typeof error.title === 'string' &&
72
+ typeof error.status === 'number';
82
73
  }
83
74
 
84
75
  /**
@@ -142,161 +133,6 @@ const ErrorMessages = {
142
133
  const ErrorNames = {
143
134
  ABORT_ERROR: 'AbortError'};
144
135
 
145
- /**
146
- * Error thrown when authentication fails (401 errors)
147
- * Common scenarios:
148
- * - Invalid credentials
149
- * - Expired token
150
- * - Missing authentication
151
- */
152
- class AuthenticationError extends UiPathError {
153
- constructor(params = {}) {
154
- super(ErrorType.AUTHENTICATION, {
155
- message: params.message || ErrorMessages.AUTHENTICATION_FAILED,
156
- statusCode: params.statusCode ?? HttpStatus.UNAUTHORIZED,
157
- requestId: params.requestId
158
- });
159
- }
160
- }
161
-
162
- /**
163
- * Error thrown when authorization fails (403 errors)
164
- * Common scenarios:
165
- * - Insufficient permissions
166
- * - Access denied to resource
167
- * - Invalid scope
168
- */
169
- class AuthorizationError extends UiPathError {
170
- constructor(params = {}) {
171
- super(ErrorType.AUTHORIZATION, {
172
- message: params.message || ErrorMessages.ACCESS_DENIED,
173
- statusCode: params.statusCode ?? HttpStatus.FORBIDDEN,
174
- requestId: params.requestId
175
- });
176
- }
177
- }
178
-
179
- /**
180
- * Error thrown when validation fails (400 errors or client-side validation)
181
- * Common scenarios:
182
- * - Invalid input parameters
183
- * - Missing required fields
184
- * - Invalid data format
185
- */
186
- class ValidationError extends UiPathError {
187
- constructor(params = {}) {
188
- super(ErrorType.VALIDATION, {
189
- message: params.message || ErrorMessages.VALIDATION_FAILED,
190
- statusCode: params.statusCode ?? HttpStatus.BAD_REQUEST,
191
- requestId: params.requestId
192
- });
193
- }
194
- }
195
-
196
- /**
197
- * Error thrown when a resource is not found (404 errors)
198
- * Common scenarios:
199
- * - Resource doesn't exist
200
- * - Invalid ID provided
201
- * - Resource deleted
202
- */
203
- class NotFoundError extends UiPathError {
204
- constructor(params = {}) {
205
- super(ErrorType.NOT_FOUND, {
206
- message: params.message || ErrorMessages.RESOURCE_NOT_FOUND,
207
- statusCode: params.statusCode ?? HttpStatus.NOT_FOUND,
208
- requestId: params.requestId
209
- });
210
- }
211
- }
212
-
213
- /**
214
- * Error thrown when rate limit is exceeded (429 errors)
215
- * Common scenarios:
216
- * - Too many requests in a time window
217
- * - API throttling
218
- */
219
- class RateLimitError extends UiPathError {
220
- constructor(params = {}) {
221
- super(ErrorType.RATE_LIMIT, {
222
- message: params.message || ErrorMessages.RATE_LIMIT_EXCEEDED,
223
- statusCode: params.statusCode ?? HttpStatus.TOO_MANY_REQUESTS,
224
- requestId: params.requestId
225
- });
226
- }
227
- }
228
-
229
- /**
230
- * Error thrown when server encounters an error (5xx errors)
231
- * Common scenarios:
232
- * - Internal server error
233
- * - Service unavailable
234
- * - Gateway timeout
235
- */
236
- class ServerError extends UiPathError {
237
- constructor(params = {}) {
238
- super(ErrorType.SERVER, {
239
- message: params.message || ErrorMessages.INTERNAL_SERVER_ERROR,
240
- statusCode: params.statusCode ?? HttpStatus.INTERNAL_SERVER_ERROR,
241
- requestId: params.requestId
242
- });
243
- }
244
- /**
245
- * Checks if this is a temporary error that might succeed on retry
246
- */
247
- get isRetryable() {
248
- return this.statusCode === HttpStatus.BAD_GATEWAY ||
249
- this.statusCode === HttpStatus.SERVICE_UNAVAILABLE ||
250
- this.statusCode === HttpStatus.GATEWAY_TIMEOUT;
251
- }
252
- }
253
-
254
- /**
255
- * Error thrown when network/connection issues occur
256
- * Common scenarios:
257
- * - Connection timeout
258
- * - DNS resolution failure
259
- * - Network unreachable
260
- * - Request aborted
261
- */
262
- class NetworkError extends UiPathError {
263
- constructor(params = {}) {
264
- super(ErrorType.NETWORK, {
265
- message: params.message || ErrorMessages.NETWORK_ERROR,
266
- statusCode: params.statusCode, // Network errors typically don't have HTTP status codes
267
- requestId: params.requestId
268
- });
269
- }
270
- }
271
-
272
- /**
273
- * Type guards for error response types
274
- */
275
- function isOrchestratorError(error) {
276
- return typeof error === 'object' &&
277
- error !== null &&
278
- 'message' in error &&
279
- 'errorCode' in error &&
280
- typeof error.message === 'string' &&
281
- typeof error.errorCode === 'number';
282
- }
283
- function isEntityError(error) {
284
- return typeof error === 'object' &&
285
- error !== null &&
286
- 'error' in error &&
287
- typeof error.error === 'string';
288
- }
289
- function isPimsError(error) {
290
- return typeof error === 'object' &&
291
- error !== null &&
292
- 'type' in error &&
293
- 'title' in error &&
294
- 'status' in error &&
295
- typeof error.type === 'string' &&
296
- typeof error.title === 'string' &&
297
- typeof error.status === 'number';
298
- }
299
-
300
136
  /**
301
137
  * Parser for Orchestrator/Task error format
302
138
  */
@@ -447,6 +283,173 @@ class ErrorResponseParser {
447
283
  // Export singleton instance
448
284
  const errorResponseParser = new ErrorResponseParser();
449
285
 
286
+ /**
287
+ * Base error class for all UiPath SDK errors
288
+ * Extends Error for standard error handling compatibility
289
+ */
290
+ class UiPathError extends Error {
291
+ constructor(type, params) {
292
+ super(params.message);
293
+ this.name = type;
294
+ this.type = type;
295
+ this.statusCode = params.statusCode;
296
+ this.requestId = params.requestId;
297
+ this.timestamp = new Date();
298
+ // Maintains proper stack trace for where our error was thrown
299
+ if (Error.captureStackTrace) {
300
+ Error.captureStackTrace(this, this.constructor);
301
+ }
302
+ }
303
+ /**
304
+ * Returns a clean JSON representation of the error
305
+ */
306
+ toJSON() {
307
+ return {
308
+ type: this.type,
309
+ message: this.message,
310
+ statusCode: this.statusCode,
311
+ requestId: this.requestId,
312
+ timestamp: this.timestamp
313
+ };
314
+ }
315
+ /**
316
+ * Returns detailed debug information including stack trace
317
+ */
318
+ getDebugInfo() {
319
+ return {
320
+ ...this.toJSON(),
321
+ stack: this.stack
322
+ };
323
+ }
324
+ }
325
+
326
+ /**
327
+ * Error thrown when authentication fails (401 errors)
328
+ * Common scenarios:
329
+ * - Invalid credentials
330
+ * - Expired token
331
+ * - Missing authentication
332
+ */
333
+ class AuthenticationError extends UiPathError {
334
+ constructor(params = {}) {
335
+ super(ErrorType.AUTHENTICATION, {
336
+ message: params.message || ErrorMessages.AUTHENTICATION_FAILED,
337
+ statusCode: params.statusCode ?? HttpStatus.UNAUTHORIZED,
338
+ requestId: params.requestId
339
+ });
340
+ }
341
+ }
342
+
343
+ /**
344
+ * Error thrown when authorization fails (403 errors)
345
+ * Common scenarios:
346
+ * - Insufficient permissions
347
+ * - Access denied to resource
348
+ * - Invalid scope
349
+ */
350
+ class AuthorizationError extends UiPathError {
351
+ constructor(params = {}) {
352
+ super(ErrorType.AUTHORIZATION, {
353
+ message: params.message || ErrorMessages.ACCESS_DENIED,
354
+ statusCode: params.statusCode ?? HttpStatus.FORBIDDEN,
355
+ requestId: params.requestId
356
+ });
357
+ }
358
+ }
359
+
360
+ /**
361
+ * Error thrown when validation fails (400 errors or client-side validation)
362
+ * Common scenarios:
363
+ * - Invalid input parameters
364
+ * - Missing required fields
365
+ * - Invalid data format
366
+ */
367
+ class ValidationError extends UiPathError {
368
+ constructor(params = {}) {
369
+ super(ErrorType.VALIDATION, {
370
+ message: params.message || ErrorMessages.VALIDATION_FAILED,
371
+ statusCode: params.statusCode ?? HttpStatus.BAD_REQUEST,
372
+ requestId: params.requestId
373
+ });
374
+ }
375
+ }
376
+
377
+ /**
378
+ * Error thrown when a resource is not found (404 errors)
379
+ * Common scenarios:
380
+ * - Resource doesn't exist
381
+ * - Invalid ID provided
382
+ * - Resource deleted
383
+ */
384
+ class NotFoundError extends UiPathError {
385
+ constructor(params = {}) {
386
+ super(ErrorType.NOT_FOUND, {
387
+ message: params.message || ErrorMessages.RESOURCE_NOT_FOUND,
388
+ statusCode: params.statusCode ?? HttpStatus.NOT_FOUND,
389
+ requestId: params.requestId
390
+ });
391
+ }
392
+ }
393
+
394
+ /**
395
+ * Error thrown when rate limit is exceeded (429 errors)
396
+ * Common scenarios:
397
+ * - Too many requests in a time window
398
+ * - API throttling
399
+ */
400
+ class RateLimitError extends UiPathError {
401
+ constructor(params = {}) {
402
+ super(ErrorType.RATE_LIMIT, {
403
+ message: params.message || ErrorMessages.RATE_LIMIT_EXCEEDED,
404
+ statusCode: params.statusCode ?? HttpStatus.TOO_MANY_REQUESTS,
405
+ requestId: params.requestId
406
+ });
407
+ }
408
+ }
409
+
410
+ /**
411
+ * Error thrown when server encounters an error (5xx errors)
412
+ * Common scenarios:
413
+ * - Internal server error
414
+ * - Service unavailable
415
+ * - Gateway timeout
416
+ */
417
+ class ServerError extends UiPathError {
418
+ constructor(params = {}) {
419
+ super(ErrorType.SERVER, {
420
+ message: params.message || ErrorMessages.INTERNAL_SERVER_ERROR,
421
+ statusCode: params.statusCode ?? HttpStatus.INTERNAL_SERVER_ERROR,
422
+ requestId: params.requestId
423
+ });
424
+ }
425
+ /**
426
+ * Checks if this is a temporary error that might succeed on retry
427
+ */
428
+ get isRetryable() {
429
+ return this.statusCode === HttpStatus.BAD_GATEWAY ||
430
+ this.statusCode === HttpStatus.SERVICE_UNAVAILABLE ||
431
+ this.statusCode === HttpStatus.GATEWAY_TIMEOUT;
432
+ }
433
+ }
434
+
435
+ /**
436
+ * Error thrown when network/connection issues occur
437
+ * Common scenarios:
438
+ * - Connection timeout
439
+ * - DNS resolution failure
440
+ * - Network unreachable
441
+ * - Request aborted
442
+ */
443
+ class NetworkError extends UiPathError {
444
+ constructor(params = {}) {
445
+ super(ErrorType.NETWORK, {
446
+ message: params.message || ErrorMessages.NETWORK_ERROR,
447
+ statusCode: params.statusCode, // Network errors typically don't have HTTP status codes
448
+ requestId: params.requestId
449
+ });
450
+ }
451
+ }
452
+
450
453
  /**
451
454
  * Factory for creating typed errors based on HTTP status codes
452
455
  * Follows the Factory pattern for clean error instantiation
@@ -541,29 +544,7 @@ class ApiClient {
541
544
  * @throws AuthenticationError if no token available or refresh fails
542
545
  */
543
546
  async getValidToken() {
544
- // Try to get token info from context
545
- const tokenInfo = this.executionContext.get('tokenInfo');
546
- if (!tokenInfo) {
547
- throw new AuthenticationError({ message: 'No authentication token available. Make sure to initialize the SDK first.' });
548
- }
549
- // For secret-based tokens, they never expire
550
- if (tokenInfo.type === 'secret') {
551
- return tokenInfo.token;
552
- }
553
- // If token is not expired, return it
554
- if (!this.tokenManager.isTokenExpired(tokenInfo)) {
555
- return tokenInfo.token;
556
- }
557
- try {
558
- const newToken = await this.tokenManager.refreshAccessToken();
559
- return newToken.access_token;
560
- }
561
- catch (error) {
562
- throw new AuthenticationError({
563
- message: `Token refresh failed: ${error.message}. Please re-authenticate.`,
564
- statusCode: HttpStatus.UNAUTHORIZED
565
- });
566
- }
547
+ return this.tokenManager.getValidToken();
567
548
  }
568
549
  async getDefaultHeaders() {
569
550
  // Get headers from execution context first
@@ -1207,10 +1188,7 @@ class PaginationHelpers {
1207
1188
  */
1208
1189
  static async getAll(config, options) {
1209
1190
  const optionsWithDefaults = options || {};
1210
- const { folderId, ...restOptions } = optionsWithDefaults;
1211
- const cursor = options?.cursor;
1212
- const pageSize = options?.pageSize;
1213
- const jumpToPage = options?.jumpToPage;
1191
+ const { folderId, pageSize, cursor, jumpToPage, ...restOptions } = optionsWithDefaults;
1214
1192
  // Determine if pagination is requested
1215
1193
  const isPaginationRequested = PaginationHelpers.hasPaginationParameters(options || {});
1216
1194
  // Process parameters (custom processing if provided, otherwise default)
@@ -1563,14 +1541,14 @@ class BaseService {
1563
1541
  }
1564
1542
  _BaseService_apiClient = new WeakMap();
1565
1543
 
1566
- /**
1567
- * API Endpoint Constants
1568
- * Centralized location for all API endpoints used throughout the SDK
1569
- */
1570
1544
  /**
1571
1545
  * Base path constants for different services
1572
1546
  */
1573
1547
  const PIMS_BASE = 'pims_';
1548
+
1549
+ /**
1550
+ * Maestro Service Endpoints
1551
+ */
1574
1552
  /**
1575
1553
  * Maestro Process Service Endpoints
1576
1554
  */
@@ -1756,7 +1734,7 @@ class BpmnHelpers {
1756
1734
  // Connection string placeholder that will be replaced during build
1757
1735
  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";
1758
1736
  // SDK Version placeholder
1759
- const SDK_VERSION = "1.0.0";
1737
+ const SDK_VERSION = "1.1.1";
1760
1738
  const VERSION = "Version";
1761
1739
  const SERVICE = "Service";
1762
1740
  const CLOUD_ORGANIZATION_NAME = "CloudOrganizationName";
@@ -1933,7 +1911,6 @@ class TelemetryClient {
1933
1911
  */
1934
1912
  getEnrichedAttributes(extraAttributes, eventName) {
1935
1913
  const attributes = {
1936
- ...extraAttributes,
1937
1914
  [APP_NAME]: SDK_SERVICE_NAME,
1938
1915
  [VERSION]: SDK_VERSION,
1939
1916
  [SERVICE]: eventName,
@@ -1942,6 +1919,7 @@ class TelemetryClient {
1942
1919
  [CLOUD_TENANT_NAME]: this.telemetryContext?.tenantName || UNKNOWN,
1943
1920
  [CLOUD_REDIRECT_URI]: this.telemetryContext?.redirectUri || UNKNOWN,
1944
1921
  [CLOUD_CLIENT_ID]: this.telemetryContext?.clientId || UNKNOWN,
1922
+ ...extraAttributes,
1945
1923
  };
1946
1924
  return attributes;
1947
1925
  }