@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
@@ -539,29 +542,7 @@ class ApiClient {
539
542
  * @throws AuthenticationError if no token available or refresh fails
540
543
  */
541
544
  async getValidToken() {
542
- // Try to get token info from context
543
- const tokenInfo = this.executionContext.get('tokenInfo');
544
- if (!tokenInfo) {
545
- throw new AuthenticationError({ message: 'No authentication token available. Make sure to initialize the SDK first.' });
546
- }
547
- // For secret-based tokens, they never expire
548
- if (tokenInfo.type === 'secret') {
549
- return tokenInfo.token;
550
- }
551
- // If token is not expired, return it
552
- if (!this.tokenManager.isTokenExpired(tokenInfo)) {
553
- return tokenInfo.token;
554
- }
555
- try {
556
- const newToken = await this.tokenManager.refreshAccessToken();
557
- return newToken.access_token;
558
- }
559
- catch (error) {
560
- throw new AuthenticationError({
561
- message: `Token refresh failed: ${error.message}. Please re-authenticate.`,
562
- statusCode: HttpStatus.UNAUTHORIZED
563
- });
564
- }
545
+ return this.tokenManager.getValidToken();
565
546
  }
566
547
  async getDefaultHeaders() {
567
548
  // Get headers from execution context first
@@ -1205,10 +1186,7 @@ class PaginationHelpers {
1205
1186
  */
1206
1187
  static async getAll(config, options) {
1207
1188
  const optionsWithDefaults = options || {};
1208
- const { folderId, ...restOptions } = optionsWithDefaults;
1209
- const cursor = options?.cursor;
1210
- const pageSize = options?.pageSize;
1211
- const jumpToPage = options?.jumpToPage;
1189
+ const { folderId, pageSize, cursor, jumpToPage, ...restOptions } = optionsWithDefaults;
1212
1190
  // Determine if pagination is requested
1213
1191
  const isPaginationRequested = PaginationHelpers.hasPaginationParameters(options || {});
1214
1192
  // Process parameters (custom processing if provided, otherwise default)
@@ -1561,14 +1539,14 @@ class BaseService {
1561
1539
  }
1562
1540
  _BaseService_apiClient = new WeakMap();
1563
1541
 
1564
- /**
1565
- * API Endpoint Constants
1566
- * Centralized location for all API endpoints used throughout the SDK
1567
- */
1568
1542
  /**
1569
1543
  * Base path constants for different services
1570
1544
  */
1571
1545
  const PIMS_BASE = 'pims_';
1546
+
1547
+ /**
1548
+ * Maestro Service Endpoints
1549
+ */
1572
1550
  /**
1573
1551
  * Maestro Process Service Endpoints
1574
1552
  */
@@ -1754,7 +1732,7 @@ class BpmnHelpers {
1754
1732
  // Connection string placeholder that will be replaced during build
1755
1733
  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";
1756
1734
  // SDK Version placeholder
1757
- const SDK_VERSION = "1.0.0";
1735
+ const SDK_VERSION = "1.1.1";
1758
1736
  const VERSION = "Version";
1759
1737
  const SERVICE = "Service";
1760
1738
  const CLOUD_ORGANIZATION_NAME = "CloudOrganizationName";
@@ -1931,7 +1909,6 @@ class TelemetryClient {
1931
1909
  */
1932
1910
  getEnrichedAttributes(extraAttributes, eventName) {
1933
1911
  const attributes = {
1934
- ...extraAttributes,
1935
1912
  [APP_NAME]: SDK_SERVICE_NAME,
1936
1913
  [VERSION]: SDK_VERSION,
1937
1914
  [SERVICE]: eventName,
@@ -1940,6 +1917,7 @@ class TelemetryClient {
1940
1917
  [CLOUD_TENANT_NAME]: this.telemetryContext?.tenantName || UNKNOWN,
1941
1918
  [CLOUD_REDIRECT_URI]: this.telemetryContext?.redirectUri || UNKNOWN,
1942
1919
  [CLOUD_CLIENT_ID]: this.telemetryContext?.clientId || UNKNOWN,
1920
+ ...extraAttributes,
1943
1921
  };
1944
1922
  return attributes;
1945
1923
  }