@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.
@@ -43,40 +43,31 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
43
43
  };
44
44
 
45
45
  /**
46
- * Base error class for all UiPath SDK errors
47
- * Pure TypeScript class with clean interface
46
+ * Type guards for error response types
48
47
  */
49
- class UiPathError {
50
- constructor(type, params) {
51
- this.type = type;
52
- this.message = params.message;
53
- this.statusCode = params.statusCode;
54
- this.requestId = params.requestId;
55
- this.timestamp = new Date();
56
- // Capture stack trace for debugging
57
- this.stack = (new Error()).stack;
58
- }
59
- /**
60
- * Returns a clean JSON representation of the error
61
- */
62
- toJSON() {
63
- return {
64
- type: this.type,
65
- message: this.message,
66
- statusCode: this.statusCode,
67
- requestId: this.requestId,
68
- timestamp: this.timestamp
69
- };
70
- }
71
- /**
72
- * Returns detailed debug information including stack trace
73
- */
74
- getDebugInfo() {
75
- return {
76
- ...this.toJSON(),
77
- stack: this.stack
78
- };
79
- }
48
+ function isOrchestratorError(error) {
49
+ return typeof error === 'object' &&
50
+ error !== null &&
51
+ 'message' in error &&
52
+ 'errorCode' in error &&
53
+ typeof error.message === 'string' &&
54
+ typeof error.errorCode === 'number';
55
+ }
56
+ function isEntityError(error) {
57
+ return typeof error === 'object' &&
58
+ error !== null &&
59
+ 'error' in error &&
60
+ typeof error.error === 'string';
61
+ }
62
+ function isPimsError(error) {
63
+ return typeof error === 'object' &&
64
+ error !== null &&
65
+ 'type' in error &&
66
+ 'title' in error &&
67
+ 'status' in error &&
68
+ typeof error.type === 'string' &&
69
+ typeof error.title === 'string' &&
70
+ typeof error.status === 'number';
80
71
  }
81
72
 
82
73
  /**
@@ -140,161 +131,6 @@ const ErrorMessages = {
140
131
  const ErrorNames = {
141
132
  ABORT_ERROR: 'AbortError'};
142
133
 
143
- /**
144
- * Error thrown when authentication fails (401 errors)
145
- * Common scenarios:
146
- * - Invalid credentials
147
- * - Expired token
148
- * - Missing authentication
149
- */
150
- class AuthenticationError extends UiPathError {
151
- constructor(params = {}) {
152
- super(ErrorType.AUTHENTICATION, {
153
- message: params.message || ErrorMessages.AUTHENTICATION_FAILED,
154
- statusCode: params.statusCode ?? HttpStatus.UNAUTHORIZED,
155
- requestId: params.requestId
156
- });
157
- }
158
- }
159
-
160
- /**
161
- * Error thrown when authorization fails (403 errors)
162
- * Common scenarios:
163
- * - Insufficient permissions
164
- * - Access denied to resource
165
- * - Invalid scope
166
- */
167
- class AuthorizationError extends UiPathError {
168
- constructor(params = {}) {
169
- super(ErrorType.AUTHORIZATION, {
170
- message: params.message || ErrorMessages.ACCESS_DENIED,
171
- statusCode: params.statusCode ?? HttpStatus.FORBIDDEN,
172
- requestId: params.requestId
173
- });
174
- }
175
- }
176
-
177
- /**
178
- * Error thrown when validation fails (400 errors or client-side validation)
179
- * Common scenarios:
180
- * - Invalid input parameters
181
- * - Missing required fields
182
- * - Invalid data format
183
- */
184
- class ValidationError extends UiPathError {
185
- constructor(params = {}) {
186
- super(ErrorType.VALIDATION, {
187
- message: params.message || ErrorMessages.VALIDATION_FAILED,
188
- statusCode: params.statusCode ?? HttpStatus.BAD_REQUEST,
189
- requestId: params.requestId
190
- });
191
- }
192
- }
193
-
194
- /**
195
- * Error thrown when a resource is not found (404 errors)
196
- * Common scenarios:
197
- * - Resource doesn't exist
198
- * - Invalid ID provided
199
- * - Resource deleted
200
- */
201
- class NotFoundError extends UiPathError {
202
- constructor(params = {}) {
203
- super(ErrorType.NOT_FOUND, {
204
- message: params.message || ErrorMessages.RESOURCE_NOT_FOUND,
205
- statusCode: params.statusCode ?? HttpStatus.NOT_FOUND,
206
- requestId: params.requestId
207
- });
208
- }
209
- }
210
-
211
- /**
212
- * Error thrown when rate limit is exceeded (429 errors)
213
- * Common scenarios:
214
- * - Too many requests in a time window
215
- * - API throttling
216
- */
217
- class RateLimitError extends UiPathError {
218
- constructor(params = {}) {
219
- super(ErrorType.RATE_LIMIT, {
220
- message: params.message || ErrorMessages.RATE_LIMIT_EXCEEDED,
221
- statusCode: params.statusCode ?? HttpStatus.TOO_MANY_REQUESTS,
222
- requestId: params.requestId
223
- });
224
- }
225
- }
226
-
227
- /**
228
- * Error thrown when server encounters an error (5xx errors)
229
- * Common scenarios:
230
- * - Internal server error
231
- * - Service unavailable
232
- * - Gateway timeout
233
- */
234
- class ServerError extends UiPathError {
235
- constructor(params = {}) {
236
- super(ErrorType.SERVER, {
237
- message: params.message || ErrorMessages.INTERNAL_SERVER_ERROR,
238
- statusCode: params.statusCode ?? HttpStatus.INTERNAL_SERVER_ERROR,
239
- requestId: params.requestId
240
- });
241
- }
242
- /**
243
- * Checks if this is a temporary error that might succeed on retry
244
- */
245
- get isRetryable() {
246
- return this.statusCode === HttpStatus.BAD_GATEWAY ||
247
- this.statusCode === HttpStatus.SERVICE_UNAVAILABLE ||
248
- this.statusCode === HttpStatus.GATEWAY_TIMEOUT;
249
- }
250
- }
251
-
252
- /**
253
- * Error thrown when network/connection issues occur
254
- * Common scenarios:
255
- * - Connection timeout
256
- * - DNS resolution failure
257
- * - Network unreachable
258
- * - Request aborted
259
- */
260
- class NetworkError extends UiPathError {
261
- constructor(params = {}) {
262
- super(ErrorType.NETWORK, {
263
- message: params.message || ErrorMessages.NETWORK_ERROR,
264
- statusCode: params.statusCode, // Network errors typically don't have HTTP status codes
265
- requestId: params.requestId
266
- });
267
- }
268
- }
269
-
270
- /**
271
- * Type guards for error response types
272
- */
273
- function isOrchestratorError(error) {
274
- return typeof error === 'object' &&
275
- error !== null &&
276
- 'message' in error &&
277
- 'errorCode' in error &&
278
- typeof error.message === 'string' &&
279
- typeof error.errorCode === 'number';
280
- }
281
- function isEntityError(error) {
282
- return typeof error === 'object' &&
283
- error !== null &&
284
- 'error' in error &&
285
- typeof error.error === 'string';
286
- }
287
- function isPimsError(error) {
288
- return typeof error === 'object' &&
289
- error !== null &&
290
- 'type' in error &&
291
- 'title' in error &&
292
- 'status' in error &&
293
- typeof error.type === 'string' &&
294
- typeof error.title === 'string' &&
295
- typeof error.status === 'number';
296
- }
297
-
298
134
  /**
299
135
  * Parser for Orchestrator/Task error format
300
136
  */
@@ -445,6 +281,173 @@ class ErrorResponseParser {
445
281
  // Export singleton instance
446
282
  const errorResponseParser = new ErrorResponseParser();
447
283
 
284
+ /**
285
+ * Base error class for all UiPath SDK errors
286
+ * Extends Error for standard error handling compatibility
287
+ */
288
+ class UiPathError extends Error {
289
+ constructor(type, params) {
290
+ super(params.message);
291
+ this.name = type;
292
+ this.type = type;
293
+ this.statusCode = params.statusCode;
294
+ this.requestId = params.requestId;
295
+ this.timestamp = new Date();
296
+ // Maintains proper stack trace for where our error was thrown
297
+ if (Error.captureStackTrace) {
298
+ Error.captureStackTrace(this, this.constructor);
299
+ }
300
+ }
301
+ /**
302
+ * Returns a clean JSON representation of the error
303
+ */
304
+ toJSON() {
305
+ return {
306
+ type: this.type,
307
+ message: this.message,
308
+ statusCode: this.statusCode,
309
+ requestId: this.requestId,
310
+ timestamp: this.timestamp
311
+ };
312
+ }
313
+ /**
314
+ * Returns detailed debug information including stack trace
315
+ */
316
+ getDebugInfo() {
317
+ return {
318
+ ...this.toJSON(),
319
+ stack: this.stack
320
+ };
321
+ }
322
+ }
323
+
324
+ /**
325
+ * Error thrown when authentication fails (401 errors)
326
+ * Common scenarios:
327
+ * - Invalid credentials
328
+ * - Expired token
329
+ * - Missing authentication
330
+ */
331
+ class AuthenticationError extends UiPathError {
332
+ constructor(params = {}) {
333
+ super(ErrorType.AUTHENTICATION, {
334
+ message: params.message || ErrorMessages.AUTHENTICATION_FAILED,
335
+ statusCode: params.statusCode ?? HttpStatus.UNAUTHORIZED,
336
+ requestId: params.requestId
337
+ });
338
+ }
339
+ }
340
+
341
+ /**
342
+ * Error thrown when authorization fails (403 errors)
343
+ * Common scenarios:
344
+ * - Insufficient permissions
345
+ * - Access denied to resource
346
+ * - Invalid scope
347
+ */
348
+ class AuthorizationError extends UiPathError {
349
+ constructor(params = {}) {
350
+ super(ErrorType.AUTHORIZATION, {
351
+ message: params.message || ErrorMessages.ACCESS_DENIED,
352
+ statusCode: params.statusCode ?? HttpStatus.FORBIDDEN,
353
+ requestId: params.requestId
354
+ });
355
+ }
356
+ }
357
+
358
+ /**
359
+ * Error thrown when validation fails (400 errors or client-side validation)
360
+ * Common scenarios:
361
+ * - Invalid input parameters
362
+ * - Missing required fields
363
+ * - Invalid data format
364
+ */
365
+ class ValidationError extends UiPathError {
366
+ constructor(params = {}) {
367
+ super(ErrorType.VALIDATION, {
368
+ message: params.message || ErrorMessages.VALIDATION_FAILED,
369
+ statusCode: params.statusCode ?? HttpStatus.BAD_REQUEST,
370
+ requestId: params.requestId
371
+ });
372
+ }
373
+ }
374
+
375
+ /**
376
+ * Error thrown when a resource is not found (404 errors)
377
+ * Common scenarios:
378
+ * - Resource doesn't exist
379
+ * - Invalid ID provided
380
+ * - Resource deleted
381
+ */
382
+ class NotFoundError extends UiPathError {
383
+ constructor(params = {}) {
384
+ super(ErrorType.NOT_FOUND, {
385
+ message: params.message || ErrorMessages.RESOURCE_NOT_FOUND,
386
+ statusCode: params.statusCode ?? HttpStatus.NOT_FOUND,
387
+ requestId: params.requestId
388
+ });
389
+ }
390
+ }
391
+
392
+ /**
393
+ * Error thrown when rate limit is exceeded (429 errors)
394
+ * Common scenarios:
395
+ * - Too many requests in a time window
396
+ * - API throttling
397
+ */
398
+ class RateLimitError extends UiPathError {
399
+ constructor(params = {}) {
400
+ super(ErrorType.RATE_LIMIT, {
401
+ message: params.message || ErrorMessages.RATE_LIMIT_EXCEEDED,
402
+ statusCode: params.statusCode ?? HttpStatus.TOO_MANY_REQUESTS,
403
+ requestId: params.requestId
404
+ });
405
+ }
406
+ }
407
+
408
+ /**
409
+ * Error thrown when server encounters an error (5xx errors)
410
+ * Common scenarios:
411
+ * - Internal server error
412
+ * - Service unavailable
413
+ * - Gateway timeout
414
+ */
415
+ class ServerError extends UiPathError {
416
+ constructor(params = {}) {
417
+ super(ErrorType.SERVER, {
418
+ message: params.message || ErrorMessages.INTERNAL_SERVER_ERROR,
419
+ statusCode: params.statusCode ?? HttpStatus.INTERNAL_SERVER_ERROR,
420
+ requestId: params.requestId
421
+ });
422
+ }
423
+ /**
424
+ * Checks if this is a temporary error that might succeed on retry
425
+ */
426
+ get isRetryable() {
427
+ return this.statusCode === HttpStatus.BAD_GATEWAY ||
428
+ this.statusCode === HttpStatus.SERVICE_UNAVAILABLE ||
429
+ this.statusCode === HttpStatus.GATEWAY_TIMEOUT;
430
+ }
431
+ }
432
+
433
+ /**
434
+ * Error thrown when network/connection issues occur
435
+ * Common scenarios:
436
+ * - Connection timeout
437
+ * - DNS resolution failure
438
+ * - Network unreachable
439
+ * - Request aborted
440
+ */
441
+ class NetworkError extends UiPathError {
442
+ constructor(params = {}) {
443
+ super(ErrorType.NETWORK, {
444
+ message: params.message || ErrorMessages.NETWORK_ERROR,
445
+ statusCode: params.statusCode, // Network errors typically don't have HTTP status codes
446
+ requestId: params.requestId
447
+ });
448
+ }
449
+ }
450
+
448
451
  /**
449
452
  * Factory for creating typed errors based on HTTP status codes
450
453
  * Follows the Factory pattern for clean error instantiation
@@ -538,29 +541,7 @@ class ApiClient {
538
541
  * @throws AuthenticationError if no token available or refresh fails
539
542
  */
540
543
  async getValidToken() {
541
- // Try to get token info from context
542
- const tokenInfo = this.executionContext.get('tokenInfo');
543
- if (!tokenInfo) {
544
- throw new AuthenticationError({ message: 'No authentication token available. Make sure to initialize the SDK first.' });
545
- }
546
- // For secret-based tokens, they never expire
547
- if (tokenInfo.type === 'secret') {
548
- return tokenInfo.token;
549
- }
550
- // If token is not expired, return it
551
- if (!this.tokenManager.isTokenExpired(tokenInfo)) {
552
- return tokenInfo.token;
553
- }
554
- try {
555
- const newToken = await this.tokenManager.refreshAccessToken();
556
- return newToken.access_token;
557
- }
558
- catch (error) {
559
- throw new AuthenticationError({
560
- message: `Token refresh failed: ${error.message}. Please re-authenticate.`,
561
- statusCode: HttpStatus.UNAUTHORIZED
562
- });
563
- }
544
+ return this.tokenManager.getValidToken();
564
545
  }
565
546
  async getDefaultHeaders() {
566
547
  // Get headers from execution context first
@@ -1275,10 +1256,7 @@ class PaginationHelpers {
1275
1256
  */
1276
1257
  static async getAll(config, options) {
1277
1258
  const optionsWithDefaults = options || {};
1278
- const { folderId, ...restOptions } = optionsWithDefaults;
1279
- const cursor = options?.cursor;
1280
- const pageSize = options?.pageSize;
1281
- const jumpToPage = options?.jumpToPage;
1259
+ const { folderId, pageSize, cursor, jumpToPage, ...restOptions } = optionsWithDefaults;
1282
1260
  // Determine if pagination is requested
1283
1261
  const isPaginationRequested = PaginationHelpers.hasPaginationParameters(options || {});
1284
1262
  // Process parameters (custom processing if provided, otherwise default)
@@ -1666,14 +1644,14 @@ class FolderScopedService extends BaseService {
1666
1644
  }
1667
1645
  }
1668
1646
 
1669
- /**
1670
- * API Endpoint Constants
1671
- * Centralized location for all API endpoints used throughout the SDK
1672
- */
1673
1647
  /**
1674
1648
  * Base path constants for different services
1675
1649
  */
1676
1650
  const ORCHESTRATOR_BASE = 'orchestrator_';
1651
+
1652
+ /**
1653
+ * Orchestrator Service Endpoints
1654
+ */
1677
1655
  /**
1678
1656
  * Orchestrator Asset Service Endpoints
1679
1657
  */
@@ -1697,7 +1675,7 @@ const AssetMap = {
1697
1675
  // Connection string placeholder that will be replaced during build
1698
1676
  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";
1699
1677
  // SDK Version placeholder
1700
- const SDK_VERSION = "1.0.0";
1678
+ const SDK_VERSION = "1.1.1";
1701
1679
  const VERSION = "Version";
1702
1680
  const SERVICE = "Service";
1703
1681
  const CLOUD_ORGANIZATION_NAME = "CloudOrganizationName";
@@ -1874,7 +1852,6 @@ class TelemetryClient {
1874
1852
  */
1875
1853
  getEnrichedAttributes(extraAttributes, eventName) {
1876
1854
  const attributes = {
1877
- ...extraAttributes,
1878
1855
  [APP_NAME]: SDK_SERVICE_NAME,
1879
1856
  [VERSION]: SDK_VERSION,
1880
1857
  [SERVICE]: eventName,
@@ -1883,6 +1860,7 @@ class TelemetryClient {
1883
1860
  [CLOUD_TENANT_NAME]: this.telemetryContext?.tenantName || UNKNOWN,
1884
1861
  [CLOUD_REDIRECT_URI]: this.telemetryContext?.redirectUri || UNKNOWN,
1885
1862
  [CLOUD_CLIENT_ID]: this.telemetryContext?.clientId || UNKNOWN,
1863
+ ...extraAttributes,
1886
1864
  };
1887
1865
  return attributes;
1888
1866
  }