@uipath/uipath-typescript 1.0.0-beta.18 → 1.0.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.
@@ -0,0 +1,406 @@
1
+ interface BaseConfig {
2
+ baseUrl: string;
3
+ orgName: string;
4
+ tenantName: string;
5
+ }
6
+ interface OAuthFields {
7
+ clientId: string;
8
+ redirectUri: string;
9
+ scope: string;
10
+ }
11
+ type UiPathSDKConfig = BaseConfig & ({
12
+ secret: string;
13
+ clientId?: never;
14
+ redirectUri?: never;
15
+ scope?: never;
16
+ } | ({
17
+ secret?: never;
18
+ } & OAuthFields));
19
+
20
+ /**
21
+ * IUiPath - Interface for UiPath SDK instance
22
+ *
23
+ * This interface defines the public contract for the UiPath SDK.
24
+ * Services depend on this interface rather than the concrete UiPath class,
25
+ * enabling proper type sharing across modular imports without #private field issues.
26
+ *
27
+ * @internal This interface is for internal SDK use only
28
+ */
29
+
30
+ interface IUiPath {
31
+ /** Read-only configuration for the SDK instance */
32
+ readonly config: Readonly<BaseConfig>;
33
+ /**
34
+ * Initialize the SDK based on the provided configuration.
35
+ * For secret-based auth, this returns immediately.
36
+ * For OAuth, this handles the authentication flow.
37
+ */
38
+ initialize(): Promise<void>;
39
+ /**
40
+ * Check if the SDK has been initialized
41
+ */
42
+ isInitialized(): boolean;
43
+ /**
44
+ * Check if we're in an OAuth callback state
45
+ */
46
+ isInOAuthCallback(): boolean;
47
+ /**
48
+ * Complete OAuth authentication flow
49
+ */
50
+ completeOAuth(): Promise<boolean>;
51
+ /**
52
+ * Check if the user is authenticated (has valid token)
53
+ */
54
+ isAuthenticated(): boolean;
55
+ /**
56
+ * Get the current authentication token
57
+ */
58
+ getToken(): string | undefined;
59
+ }
60
+
61
+ /**
62
+ * UiPath - Core SDK class for authentication and configuration management.
63
+ *
64
+ * Handles authentication, configuration, and provides access to SDK internals
65
+ * for service instantiation in the modular pattern.
66
+ *
67
+ * @example
68
+ * ```typescript
69
+ * // Modular pattern
70
+ * import { UiPath } from '@uipath/uipath-typescript/core';
71
+ * import { Entities } from '@uipath/uipath-typescript/entities';
72
+ *
73
+ * const sdk = new UiPath({
74
+ * baseUrl: 'https://cloud.uipath.com',
75
+ * orgName: 'myorg',
76
+ * tenantName: 'mytenant',
77
+ * clientId: 'xxx',
78
+ * redirectUri: 'http://localhost:3000/callback',
79
+ * scope: 'OR.Users OR.Robots'
80
+ * });
81
+ *
82
+ * await sdk.initialize();
83
+ *
84
+ * const entitiesService = new Entities(sdk);
85
+ * const allEntities = await entitiesService.getAll();
86
+ * ```
87
+ */
88
+ declare class UiPath implements IUiPath {
89
+ #private;
90
+ /** Read-only config for user convenience */
91
+ readonly config: Readonly<BaseConfig>;
92
+ constructor(config: UiPathSDKConfig);
93
+ /**
94
+ * Initialize the SDK based on the provided configuration.
95
+ * This method handles both OAuth flow initiation and completion automatically.
96
+ * For secret-based authentication, initialization is automatic and this returns immediately.
97
+ */
98
+ initialize(): Promise<void>;
99
+ /**
100
+ * Check if the SDK has been initialized
101
+ */
102
+ isInitialized(): boolean;
103
+ /**
104
+ * Check if we're in an OAuth callback state
105
+ */
106
+ isInOAuthCallback(): boolean;
107
+ /**
108
+ * Complete OAuth authentication flow (only call if isInOAuthCallback() is true)
109
+ */
110
+ completeOAuth(): Promise<boolean>;
111
+ /**
112
+ * Check if the user is authenticated (has valid token)
113
+ */
114
+ isAuthenticated(): boolean;
115
+ /**
116
+ * Get the current authentication token
117
+ */
118
+ getToken(): string | undefined;
119
+ }
120
+
121
+ /**
122
+ * Error thrown when authorization fails (403 errors)
123
+ * Common scenarios:
124
+ * - Insufficient permissions
125
+ * - Access denied to resource
126
+ * - Invalid scope
127
+ */
128
+ declare class AuthorizationError extends UiPathError {
129
+ constructor(params?: Partial<ErrorParams>);
130
+ }
131
+
132
+ /**
133
+ * Error thrown when validation fails (400 errors or client-side validation)
134
+ * Common scenarios:
135
+ * - Invalid input parameters
136
+ * - Missing required fields
137
+ * - Invalid data format
138
+ */
139
+ declare class ValidationError extends UiPathError {
140
+ constructor(params?: Partial<ErrorParams>);
141
+ }
142
+
143
+ /**
144
+ * Error thrown when a resource is not found (404 errors)
145
+ * Common scenarios:
146
+ * - Resource doesn't exist
147
+ * - Invalid ID provided
148
+ * - Resource deleted
149
+ */
150
+ declare class NotFoundError extends UiPathError {
151
+ constructor(params?: Partial<ErrorParams>);
152
+ }
153
+
154
+ /**
155
+ * Error thrown when rate limit is exceeded (429 errors)
156
+ * Common scenarios:
157
+ * - Too many requests in a time window
158
+ * - API throttling
159
+ */
160
+ declare class RateLimitError extends UiPathError {
161
+ constructor(params?: Partial<ErrorParams>);
162
+ }
163
+
164
+ /**
165
+ * Error thrown when server encounters an error (5xx errors)
166
+ * Common scenarios:
167
+ * - Internal server error
168
+ * - Service unavailable
169
+ * - Gateway timeout
170
+ */
171
+ declare class ServerError extends UiPathError {
172
+ constructor(params?: Partial<ErrorParams>);
173
+ /**
174
+ * Checks if this is a temporary error that might succeed on retry
175
+ */
176
+ get isRetryable(): boolean;
177
+ }
178
+
179
+ /**
180
+ * Base error creation parameters - only what's needed
181
+ */
182
+ interface ErrorParams {
183
+ message: string;
184
+ statusCode?: number;
185
+ requestId?: string;
186
+ }
187
+
188
+ /**
189
+ * Base error class for all UiPath SDK errors
190
+ * Pure TypeScript class with clean interface
191
+ */
192
+ declare abstract class UiPathError {
193
+ /**
194
+ * Error type identifier (e.g., "AuthenticationError", "ValidationError")
195
+ */
196
+ readonly type: string;
197
+ /**
198
+ * Error message describing what went wrong
199
+ */
200
+ readonly message: string;
201
+ /**
202
+ * HTTP status code (400, 401, 403, 404, 500, etc.)
203
+ */
204
+ readonly statusCode?: number;
205
+ /**
206
+ * Request ID for tracking with UiPath support
207
+ */
208
+ readonly requestId?: string;
209
+ /**
210
+ * Timestamp when the error occurred
211
+ */
212
+ readonly timestamp: Date;
213
+ /**
214
+ * Stack trace for debugging
215
+ */
216
+ readonly stack?: string;
217
+ protected constructor(type: string, params: ErrorParams);
218
+ /**
219
+ * Returns a clean JSON representation of the error
220
+ */
221
+ private toJSON;
222
+ /**
223
+ * Returns detailed debug information including stack trace
224
+ */
225
+ getDebugInfo(): Record<string, unknown>;
226
+ }
227
+
228
+ /**
229
+ * Error thrown when authentication fails (401 errors)
230
+ * Common scenarios:
231
+ * - Invalid credentials
232
+ * - Expired token
233
+ * - Missing authentication
234
+ */
235
+ declare class AuthenticationError extends UiPathError {
236
+ constructor(params?: Partial<ErrorParams>);
237
+ }
238
+
239
+ /**
240
+ * Error thrown when network/connection issues occur
241
+ * Common scenarios:
242
+ * - Connection timeout
243
+ * - DNS resolution failure
244
+ * - Network unreachable
245
+ * - Request aborted
246
+ */
247
+ declare class NetworkError extends UiPathError {
248
+ constructor(params?: Partial<ErrorParams>);
249
+ }
250
+
251
+ /**
252
+ * Type guard to check if an error is a UiPathError
253
+ */
254
+ declare function isUiPathError(error: unknown): error is UiPathError;
255
+ /**
256
+ * Type guard to check if an error is an AuthenticationError
257
+ */
258
+ declare function isAuthenticationError(error: unknown): error is AuthenticationError;
259
+ /**
260
+ * Type guard to check if an error is an AuthorizationError
261
+ */
262
+ declare function isAuthorizationError(error: unknown): error is AuthorizationError;
263
+ /**
264
+ * Type guard to check if an error is a ValidationError
265
+ */
266
+ declare function isValidationError(error: unknown): error is ValidationError;
267
+ /**
268
+ * Type guard to check if an error is a NotFoundError
269
+ */
270
+ declare function isNotFoundError(error: unknown): error is NotFoundError;
271
+ /**
272
+ * Type guard to check if an error is a RateLimitError
273
+ */
274
+ declare function isRateLimitError(error: unknown): error is RateLimitError;
275
+ /**
276
+ * Type guard to check if an error is a ServerError
277
+ */
278
+ declare function isServerError(error: unknown): error is ServerError;
279
+ /**
280
+ * Type guard to check if an error is a NetworkError
281
+ */
282
+ declare function isNetworkError(error: unknown): error is NetworkError;
283
+ /**
284
+ * Helper to get error details in a safe way
285
+ */
286
+ declare function getErrorDetails(error: unknown): {
287
+ message: string;
288
+ statusCode?: number;
289
+ };
290
+
291
+ /**
292
+ * HTTP status code constants for error handling
293
+ */
294
+ declare const HttpStatus: {
295
+ readonly BAD_REQUEST: 400;
296
+ readonly UNAUTHORIZED: 401;
297
+ readonly FORBIDDEN: 403;
298
+ readonly NOT_FOUND: 404;
299
+ readonly TOO_MANY_REQUESTS: 429;
300
+ readonly INTERNAL_SERVER_ERROR: 500;
301
+ readonly NOT_IMPLEMENTED: 501;
302
+ readonly BAD_GATEWAY: 502;
303
+ readonly SERVICE_UNAVAILABLE: 503;
304
+ readonly GATEWAY_TIMEOUT: 504;
305
+ };
306
+ /**
307
+ * Error type constants for consistent error identification
308
+ */
309
+ declare const ErrorType: {
310
+ readonly AUTHENTICATION: "AuthenticationError";
311
+ readonly AUTHORIZATION: "AuthorizationError";
312
+ readonly VALIDATION: "ValidationError";
313
+ readonly NOT_FOUND: "NotFoundError";
314
+ readonly RATE_LIMIT: "RateLimitError";
315
+ readonly SERVER: "ServerError";
316
+ readonly NETWORK: "NetworkError";
317
+ };
318
+
319
+ /**
320
+ * Simplified universal pagination cursor
321
+ * Used to fetch next/previous pages
322
+ */
323
+ interface PaginationCursor {
324
+ /** Opaque string containing all information needed to fetch next page */
325
+ value: string;
326
+ }
327
+ /**
328
+ * Discriminated union for pagination methods - ensures cursor and jumpToPage are mutually exclusive
329
+ */
330
+ type PaginationMethodUnion = {
331
+ cursor?: PaginationCursor;
332
+ jumpToPage?: never;
333
+ } | {
334
+ cursor?: never;
335
+ jumpToPage?: number;
336
+ } | {
337
+ cursor?: never;
338
+ jumpToPage?: never;
339
+ };
340
+ /**
341
+ * Pagination options. Users cannot specify both cursor and jumpToPage.
342
+ */
343
+ type PaginationOptions = {
344
+ /** Size of the page to fetch (items per page) */
345
+ pageSize?: number;
346
+ } & PaginationMethodUnion;
347
+ /**
348
+ * Paginated response containing items and navigation information
349
+ */
350
+ interface PaginatedResponse<T> {
351
+ /** The items in the current page */
352
+ items: T[];
353
+ /** Total count of items across all pages (if available) */
354
+ totalCount?: number;
355
+ /** Whether more pages are available */
356
+ hasNextPage: boolean;
357
+ /** Cursor to fetch the next page (if available) */
358
+ nextCursor?: PaginationCursor;
359
+ /** Cursor to fetch the previous page (if available) */
360
+ previousCursor?: PaginationCursor;
361
+ /** Current page number (1-based, if available) */
362
+ currentPage?: number;
363
+ /** Total number of pages (if available) */
364
+ totalPages?: number;
365
+ /** Whether this pagination type supports jumping to arbitrary pages */
366
+ supportsPageJump: boolean;
367
+ }
368
+ /**
369
+ * Response for non-paginated calls that includes both data and total count
370
+ */
371
+ interface NonPaginatedResponse<T> {
372
+ items: T[];
373
+ totalCount?: number;
374
+ }
375
+ /**
376
+ * Helper type for defining paginated method overloads
377
+ * Creates a union type of all ways pagination can be triggered
378
+ */
379
+ type HasPaginationOptions<T> = (T & {
380
+ pageSize: number;
381
+ }) | (T & {
382
+ cursor: PaginationCursor;
383
+ }) | (T & {
384
+ jumpToPage: number;
385
+ });
386
+
387
+ /**
388
+ * Constants used throughout the pagination system
389
+ */
390
+ /** Maximum number of items that can be requested in a single page */
391
+ declare const MAX_PAGE_SIZE = 1000;
392
+ /** Default page size when jumpToPage is used without specifying pageSize */
393
+ declare const DEFAULT_PAGE_SIZE = 50;
394
+ /** Default field name for items in a paginated response */
395
+ declare const DEFAULT_ITEMS_FIELD = "value";
396
+ /** Default field name for total count in a paginated response */
397
+ declare const DEFAULT_TOTAL_COUNT_FIELD = "@odata.count";
398
+ /**
399
+ * Limits the page size to the maximum allowed value
400
+ * @param pageSize - Requested page size
401
+ * @returns Limited page size value
402
+ */
403
+ declare function getLimitedPageSize(pageSize?: number): number;
404
+
405
+ export { AuthenticationError, AuthorizationError, DEFAULT_ITEMS_FIELD, DEFAULT_PAGE_SIZE, DEFAULT_TOTAL_COUNT_FIELD, ErrorType, HttpStatus, MAX_PAGE_SIZE, NetworkError, NotFoundError, RateLimitError, ServerError, UiPath, UiPathError, ValidationError, getErrorDetails, getLimitedPageSize, isAuthenticationError, isAuthorizationError, isNetworkError, isNotFoundError, isRateLimitError, isServerError, isUiPathError, isValidationError };
406
+ export type { HasPaginationOptions, NonPaginatedResponse, PaginatedResponse, PaginationCursor, PaginationMethodUnion, PaginationOptions, UiPathSDKConfig };