lexmount 0.2.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.
- package/LICENSE +21 -0
- package/README.md +493 -0
- package/dist/index.d.mts +492 -0
- package/dist/index.d.ts +492 -0
- package/dist/index.js +903 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +846 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +75 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,492 @@
|
|
|
1
|
+
import { AxiosResponse } from 'axios';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Supported SDK log levels.
|
|
5
|
+
*/
|
|
6
|
+
type LogLevel = 'DEBUG' | 'INFO' | 'WARNING' | 'ERROR' | 'CRITICAL' | 'SILENT';
|
|
7
|
+
/**
|
|
8
|
+
* Shared SDK logger.
|
|
9
|
+
*/
|
|
10
|
+
declare class LexmountLogger {
|
|
11
|
+
/**
|
|
12
|
+
* Current SDK log level.
|
|
13
|
+
*/
|
|
14
|
+
get level(): LogLevel;
|
|
15
|
+
debug(...args: unknown[]): void;
|
|
16
|
+
info(...args: unknown[]): void;
|
|
17
|
+
warn(...args: unknown[]): void;
|
|
18
|
+
error(...args: unknown[]): void;
|
|
19
|
+
critical(...args: unknown[]): void;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Return the shared SDK logger instance.
|
|
23
|
+
*/
|
|
24
|
+
declare function getLogger(): LexmountLogger;
|
|
25
|
+
/**
|
|
26
|
+
* Set the SDK log level.
|
|
27
|
+
*/
|
|
28
|
+
declare function setLogLevel(level: LogLevel | string): void;
|
|
29
|
+
/**
|
|
30
|
+
* Disable all SDK logging.
|
|
31
|
+
*/
|
|
32
|
+
declare function disableLogging(): void;
|
|
33
|
+
/**
|
|
34
|
+
* Re-enable SDK logging.
|
|
35
|
+
*/
|
|
36
|
+
declare function enableLogging(level?: LogLevel | string): void;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Browser modes supported by the Lexmount API.
|
|
40
|
+
*/
|
|
41
|
+
type BrowserMode = 'normal' | 'light';
|
|
42
|
+
/**
|
|
43
|
+
* Session status returned by the API.
|
|
44
|
+
*/
|
|
45
|
+
type SessionStatus = 'active' | 'closed' | string;
|
|
46
|
+
/**
|
|
47
|
+
* Context status returned by the API.
|
|
48
|
+
*/
|
|
49
|
+
type ContextStatus = 'available' | 'locked' | string;
|
|
50
|
+
/**
|
|
51
|
+
* Supported context access modes.
|
|
52
|
+
*
|
|
53
|
+
* The camelCase values are recommended for the Node SDK.
|
|
54
|
+
* The snake_case values are accepted for convenience and mapped internally.
|
|
55
|
+
*/
|
|
56
|
+
type ContextAccessMode = 'readWrite' | 'readOnly' | 'read_write' | 'read_only';
|
|
57
|
+
/**
|
|
58
|
+
* Context selection when creating a session.
|
|
59
|
+
*/
|
|
60
|
+
interface SessionContext {
|
|
61
|
+
/**
|
|
62
|
+
* Context identifier.
|
|
63
|
+
*/
|
|
64
|
+
id: string;
|
|
65
|
+
/**
|
|
66
|
+
* Context access mode.
|
|
67
|
+
*/
|
|
68
|
+
mode: ContextAccessMode;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* SDK client configuration.
|
|
72
|
+
*/
|
|
73
|
+
interface LexmountConfig {
|
|
74
|
+
/**
|
|
75
|
+
* API key for authentication.
|
|
76
|
+
*/
|
|
77
|
+
apiKey?: string;
|
|
78
|
+
/**
|
|
79
|
+
* Project identifier.
|
|
80
|
+
*/
|
|
81
|
+
projectId?: string;
|
|
82
|
+
/**
|
|
83
|
+
* API base URL.
|
|
84
|
+
*
|
|
85
|
+
* Defaults to `https://api.lexmount.cn`.
|
|
86
|
+
*/
|
|
87
|
+
baseUrl?: string;
|
|
88
|
+
/**
|
|
89
|
+
* Request timeout in milliseconds.
|
|
90
|
+
*
|
|
91
|
+
* Defaults to 60000.
|
|
92
|
+
*/
|
|
93
|
+
timeout?: number;
|
|
94
|
+
/**
|
|
95
|
+
* Optional SDK log level.
|
|
96
|
+
*/
|
|
97
|
+
logLevel?: LogLevel;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Session creation options.
|
|
101
|
+
*/
|
|
102
|
+
interface SessionCreateOptions {
|
|
103
|
+
/**
|
|
104
|
+
* Override the default project identifier.
|
|
105
|
+
*/
|
|
106
|
+
projectId?: string;
|
|
107
|
+
/**
|
|
108
|
+
* Browser mode to start.
|
|
109
|
+
*/
|
|
110
|
+
browserMode?: BrowserMode;
|
|
111
|
+
/**
|
|
112
|
+
* Optional persistent context configuration.
|
|
113
|
+
*/
|
|
114
|
+
context?: SessionContext;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Session list options.
|
|
118
|
+
*/
|
|
119
|
+
interface SessionListOptions {
|
|
120
|
+
/**
|
|
121
|
+
* Override the default project identifier.
|
|
122
|
+
*/
|
|
123
|
+
projectId?: string;
|
|
124
|
+
/**
|
|
125
|
+
* Optional session status filter.
|
|
126
|
+
*/
|
|
127
|
+
status?: SessionStatus;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Session deletion options.
|
|
131
|
+
*/
|
|
132
|
+
interface SessionDeleteOptions {
|
|
133
|
+
/**
|
|
134
|
+
* Session identifier to delete.
|
|
135
|
+
*/
|
|
136
|
+
sessionId: string;
|
|
137
|
+
/**
|
|
138
|
+
* Override the default project identifier.
|
|
139
|
+
*/
|
|
140
|
+
projectId?: string;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Metadata attached to a context.
|
|
144
|
+
*/
|
|
145
|
+
type ContextMetadata = Record<string, unknown>;
|
|
146
|
+
/**
|
|
147
|
+
* Context creation options.
|
|
148
|
+
*/
|
|
149
|
+
interface ContextCreateOptions {
|
|
150
|
+
/**
|
|
151
|
+
* Optional metadata used to organize contexts.
|
|
152
|
+
*/
|
|
153
|
+
metadata?: ContextMetadata;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Context list options.
|
|
157
|
+
*/
|
|
158
|
+
interface ContextListOptions {
|
|
159
|
+
/**
|
|
160
|
+
* Optional context status filter.
|
|
161
|
+
*/
|
|
162
|
+
status?: ContextStatus;
|
|
163
|
+
/**
|
|
164
|
+
* Maximum number of contexts to return.
|
|
165
|
+
*
|
|
166
|
+
* Defaults to 20.
|
|
167
|
+
*/
|
|
168
|
+
limit?: number;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Context force-release response.
|
|
172
|
+
*/
|
|
173
|
+
interface ForceReleaseResponse {
|
|
174
|
+
status: string;
|
|
175
|
+
message: string;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Session pagination metadata.
|
|
179
|
+
*/
|
|
180
|
+
interface PaginationInfoShape {
|
|
181
|
+
currentPage: number;
|
|
182
|
+
pageSize: number;
|
|
183
|
+
totalCount: number;
|
|
184
|
+
totalPages: number;
|
|
185
|
+
activeCount: number;
|
|
186
|
+
closedCount: number;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Context resource implementation.
|
|
191
|
+
*/
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Context information returned by the API.
|
|
195
|
+
*/
|
|
196
|
+
declare class ContextInfo {
|
|
197
|
+
readonly id: string;
|
|
198
|
+
readonly status: ContextStatus;
|
|
199
|
+
readonly metadata: ContextMetadata;
|
|
200
|
+
readonly createdAt: string | null;
|
|
201
|
+
readonly updatedAt: string | null;
|
|
202
|
+
constructor(options: {
|
|
203
|
+
id: string;
|
|
204
|
+
status: ContextStatus;
|
|
205
|
+
metadata?: ContextMetadata;
|
|
206
|
+
createdAt?: string | null;
|
|
207
|
+
updatedAt?: string | null;
|
|
208
|
+
});
|
|
209
|
+
get createdAtDate(): Date | null;
|
|
210
|
+
get updatedAtDate(): Date | null;
|
|
211
|
+
isLocked(): boolean;
|
|
212
|
+
isAvailable(): boolean;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Response object from `contexts.list()`.
|
|
216
|
+
*/
|
|
217
|
+
declare class ContextListResponse implements Iterable<ContextInfo> {
|
|
218
|
+
readonly data: ContextInfo[];
|
|
219
|
+
constructor(data: ContextInfo[]);
|
|
220
|
+
get length(): number;
|
|
221
|
+
[Symbol.iterator](): Iterator<ContextInfo>;
|
|
222
|
+
at(index: number): ContextInfo | undefined;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Context resource operations.
|
|
226
|
+
*/
|
|
227
|
+
declare class ContextsResource {
|
|
228
|
+
private readonly client;
|
|
229
|
+
constructor(client: Lexmount);
|
|
230
|
+
/**
|
|
231
|
+
* Create a new persistent context.
|
|
232
|
+
*/
|
|
233
|
+
create(options?: ContextCreateOptions): Promise<ContextInfo>;
|
|
234
|
+
/**
|
|
235
|
+
* List contexts in the current project.
|
|
236
|
+
*/
|
|
237
|
+
list(options?: ContextListOptions): Promise<ContextListResponse>;
|
|
238
|
+
/**
|
|
239
|
+
* Fetch a single context.
|
|
240
|
+
*/
|
|
241
|
+
get(contextId: string): Promise<ContextInfo>;
|
|
242
|
+
/**
|
|
243
|
+
* Delete a persistent context.
|
|
244
|
+
*/
|
|
245
|
+
delete(contextId: string): Promise<void>;
|
|
246
|
+
/**
|
|
247
|
+
* Force-release a stuck lock on a context.
|
|
248
|
+
*/
|
|
249
|
+
forceRelease(contextId: string): Promise<ForceReleaseResponse>;
|
|
250
|
+
private handleError;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Session resource implementation.
|
|
255
|
+
*/
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Session pagination information.
|
|
259
|
+
*/
|
|
260
|
+
declare class PaginationInfo implements PaginationInfoShape {
|
|
261
|
+
readonly currentPage: number;
|
|
262
|
+
readonly pageSize: number;
|
|
263
|
+
readonly totalCount: number;
|
|
264
|
+
readonly totalPages: number;
|
|
265
|
+
readonly activeCount: number;
|
|
266
|
+
readonly closedCount: number;
|
|
267
|
+
constructor(shape: PaginationInfoShape);
|
|
268
|
+
}
|
|
269
|
+
interface SessionInfoOptions {
|
|
270
|
+
id: string;
|
|
271
|
+
status: SessionStatus;
|
|
272
|
+
apiKey: string;
|
|
273
|
+
projectId: string;
|
|
274
|
+
browserType: BrowserMode | string;
|
|
275
|
+
createdAt: string;
|
|
276
|
+
inspectUrl: string;
|
|
277
|
+
containerId: string | null;
|
|
278
|
+
inspectUrlDbg?: string;
|
|
279
|
+
ws?: string | null;
|
|
280
|
+
client?: Lexmount;
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Session information returned by the API.
|
|
284
|
+
*/
|
|
285
|
+
declare class SessionInfo {
|
|
286
|
+
readonly id: string;
|
|
287
|
+
readonly sessionId: string;
|
|
288
|
+
readonly status: SessionStatus;
|
|
289
|
+
readonly apiKey: string;
|
|
290
|
+
readonly projectId: string;
|
|
291
|
+
readonly browserType: BrowserMode | string;
|
|
292
|
+
readonly createdAt: string;
|
|
293
|
+
readonly inspectUrl: string;
|
|
294
|
+
readonly containerId: string | null;
|
|
295
|
+
readonly inspectUrlDbg?: string;
|
|
296
|
+
readonly ws: string | null;
|
|
297
|
+
private readonly client?;
|
|
298
|
+
private closed;
|
|
299
|
+
/** @internal */
|
|
300
|
+
constructor(options: SessionInfoOptions);
|
|
301
|
+
/**
|
|
302
|
+
* Playwright/CDP connection URL.
|
|
303
|
+
*/
|
|
304
|
+
get connectUrl(): string;
|
|
305
|
+
/**
|
|
306
|
+
* Parsed session creation time.
|
|
307
|
+
*/
|
|
308
|
+
get createdAtDate(): Date | null;
|
|
309
|
+
/**
|
|
310
|
+
* Close the current session.
|
|
311
|
+
*
|
|
312
|
+
* This method is idempotent. Errors are logged and swallowed to keep cleanup safe.
|
|
313
|
+
*/
|
|
314
|
+
close(): Promise<void>;
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Response object from `sessions.list()`.
|
|
318
|
+
*/
|
|
319
|
+
declare class SessionListResponse implements Iterable<SessionInfo> {
|
|
320
|
+
readonly sessions: SessionInfo[];
|
|
321
|
+
readonly pagination: PaginationInfo;
|
|
322
|
+
constructor(sessions: SessionInfo[], pagination: PaginationInfo);
|
|
323
|
+
/**
|
|
324
|
+
* Number of sessions in the current page.
|
|
325
|
+
*/
|
|
326
|
+
get length(): number;
|
|
327
|
+
[Symbol.iterator](): Iterator<SessionInfo>;
|
|
328
|
+
at(index: number): SessionInfo | undefined;
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Alias kept for parity with the Python SDK.
|
|
332
|
+
*/
|
|
333
|
+
type SessionCreateResponse = SessionInfo;
|
|
334
|
+
/**
|
|
335
|
+
* Session resource operations.
|
|
336
|
+
*/
|
|
337
|
+
declare class SessionsResource {
|
|
338
|
+
private readonly client;
|
|
339
|
+
constructor(client: Lexmount);
|
|
340
|
+
/**
|
|
341
|
+
* Create a new browser session.
|
|
342
|
+
*/
|
|
343
|
+
create(options?: SessionCreateOptions): Promise<SessionCreateResponse>;
|
|
344
|
+
/**
|
|
345
|
+
* List sessions for the current project.
|
|
346
|
+
*/
|
|
347
|
+
list(options?: SessionListOptions): Promise<SessionListResponse>;
|
|
348
|
+
/**
|
|
349
|
+
* Delete a browser session.
|
|
350
|
+
*/
|
|
351
|
+
delete(options: SessionDeleteOptions): Promise<void>;
|
|
352
|
+
/**
|
|
353
|
+
* Fetch the debugger WebSocket URL for a session.
|
|
354
|
+
*
|
|
355
|
+
* @internal
|
|
356
|
+
*/
|
|
357
|
+
_getWebSocketDebuggerUrl(sessionId: string): Promise<string | null>;
|
|
358
|
+
private handleCreateError;
|
|
359
|
+
private handleListError;
|
|
360
|
+
private handleDeleteError;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Lexmount API client.
|
|
365
|
+
*/
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* Main Lexmount SDK client.
|
|
369
|
+
*/
|
|
370
|
+
declare class Lexmount {
|
|
371
|
+
/**
|
|
372
|
+
* API key used for authentication.
|
|
373
|
+
*/
|
|
374
|
+
readonly apiKey: string;
|
|
375
|
+
/**
|
|
376
|
+
* Default project identifier used by resource methods.
|
|
377
|
+
*/
|
|
378
|
+
readonly projectId: string;
|
|
379
|
+
/**
|
|
380
|
+
* API base URL.
|
|
381
|
+
*/
|
|
382
|
+
readonly baseUrl: string;
|
|
383
|
+
/**
|
|
384
|
+
* Session operations.
|
|
385
|
+
*/
|
|
386
|
+
readonly sessions: SessionsResource;
|
|
387
|
+
/**
|
|
388
|
+
* Persistent context operations.
|
|
389
|
+
*/
|
|
390
|
+
readonly contexts: ContextsResource;
|
|
391
|
+
private readonly httpClient;
|
|
392
|
+
constructor(config?: LexmountConfig);
|
|
393
|
+
/**
|
|
394
|
+
* Internal POST request helper with timeout and network error mapping.
|
|
395
|
+
*
|
|
396
|
+
* @internal
|
|
397
|
+
*/
|
|
398
|
+
_post<T = unknown>(url: string, data: Record<string, unknown>): Promise<AxiosResponse<T>>;
|
|
399
|
+
/**
|
|
400
|
+
* Internal GET request helper with timeout and network error mapping.
|
|
401
|
+
*
|
|
402
|
+
* @internal
|
|
403
|
+
*/
|
|
404
|
+
_get<T = unknown>(url: string, params: Record<string, unknown>): Promise<AxiosResponse<T>>;
|
|
405
|
+
/**
|
|
406
|
+
* Internal DELETE request helper with timeout and network error mapping.
|
|
407
|
+
*
|
|
408
|
+
* @internal
|
|
409
|
+
*/
|
|
410
|
+
_delete<T = unknown>(url: string, data: Record<string, unknown>): Promise<AxiosResponse<T>>;
|
|
411
|
+
/**
|
|
412
|
+
* Close the client.
|
|
413
|
+
*
|
|
414
|
+
* Axios does not require explicit teardown, but the method is kept for API symmetry.
|
|
415
|
+
*/
|
|
416
|
+
close(): void;
|
|
417
|
+
/**
|
|
418
|
+
* String representation of the client.
|
|
419
|
+
*/
|
|
420
|
+
toString(): string;
|
|
421
|
+
private request;
|
|
422
|
+
private normalizeRequestError;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* Lexmount SDK error hierarchy.
|
|
427
|
+
*/
|
|
428
|
+
/**
|
|
429
|
+
* Base error for all Lexmount SDK failures.
|
|
430
|
+
*/
|
|
431
|
+
declare class LexmountError extends Error {
|
|
432
|
+
constructor(message: string);
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Raised when API authentication fails.
|
|
436
|
+
*/
|
|
437
|
+
declare class AuthenticationError extends LexmountError {
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* Raised when a session cannot be found.
|
|
441
|
+
*/
|
|
442
|
+
declare class SessionNotFoundError extends LexmountError {
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* Raised when a context cannot be found.
|
|
446
|
+
*/
|
|
447
|
+
declare class ContextNotFoundError extends LexmountError {
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Raised when a context is locked by another active session.
|
|
451
|
+
*/
|
|
452
|
+
declare class ContextLockedError extends LexmountError {
|
|
453
|
+
readonly activeSessionId?: string;
|
|
454
|
+
readonly retryAfter?: number;
|
|
455
|
+
constructor(message: string, options?: {
|
|
456
|
+
activeSessionId?: string;
|
|
457
|
+
retryAfter?: number;
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* Raised when the Lexmount API returns a non-success response.
|
|
462
|
+
*/
|
|
463
|
+
declare class APIError extends LexmountError {
|
|
464
|
+
readonly statusCode?: number;
|
|
465
|
+
readonly response?: unknown;
|
|
466
|
+
constructor(message: string, options?: {
|
|
467
|
+
statusCode?: number;
|
|
468
|
+
response?: unknown;
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* Raised when a network error prevents the request from reaching the API.
|
|
473
|
+
*/
|
|
474
|
+
declare class NetworkError extends LexmountError {
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Raised when input validation fails.
|
|
478
|
+
*/
|
|
479
|
+
declare class ValidationError extends LexmountError {
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* Raised when a request exceeds the configured timeout.
|
|
483
|
+
*/
|
|
484
|
+
declare class TimeoutError extends LexmountError {
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
/**
|
|
488
|
+
* Lexmount Node.js SDK.
|
|
489
|
+
*/
|
|
490
|
+
declare const VERSION = "0.2.0";
|
|
491
|
+
|
|
492
|
+
export { APIError, AuthenticationError, type BrowserMode, type ContextAccessMode, type ContextCreateOptions, ContextInfo, type ContextListOptions, ContextListResponse, ContextLockedError, type ContextMetadata, ContextNotFoundError, type ContextStatus, ContextsResource, type ForceReleaseResponse, Lexmount, type LexmountConfig, LexmountError, LexmountLogger, type LogLevel, NetworkError, PaginationInfo, type PaginationInfoShape, type SessionContext, type SessionCreateOptions, type SessionCreateResponse, type SessionDeleteOptions, SessionInfo, type SessionListOptions, SessionListResponse, SessionNotFoundError, type SessionStatus, SessionsResource, TimeoutError, VERSION, ValidationError, Lexmount as default, disableLogging, enableLogging, getLogger, setLogLevel };
|