lexmount 0.2.0 → 0.2.3

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/README.md CHANGED
@@ -14,6 +14,9 @@ Node.js SDK for the Lexmount browser automation service.
14
14
  - Typed public API with ESM and CommonJS support
15
15
  - Session management with pagination support
16
16
  - Persistent context management
17
+ - Extension upload/list/get/delete
18
+ - Session downloads list/get/archive/delete
19
+ - Session creation with upstream proxy support
17
20
  - Structured SDK errors
18
21
  - Configurable SDK logging
19
22
  - TSDoc + TypeDoc based API documentation generation
@@ -93,6 +96,20 @@ const session = await client.sessions.create({
93
96
  });
94
97
  ```
95
98
 
99
+ Create a session with extensions and an upstream proxy:
100
+
101
+ ```ts
102
+ const session = await client.sessions.create({
103
+ extensionIds: ['ext_123'],
104
+ proxy: {
105
+ type: 'external',
106
+ server: 'http://10.3.6.54:28080',
107
+ username: 'user',
108
+ password: 'pass',
109
+ },
110
+ });
111
+ ```
112
+
96
113
  List sessions with pagination metadata:
97
114
 
98
115
  ```ts
@@ -110,6 +127,15 @@ Delete a session:
110
127
  await client.sessions.delete({ sessionId: 'session-id' });
111
128
  ```
112
129
 
130
+ List and archive session downloads:
131
+
132
+ ```ts
133
+ const downloads = await client.sessions.downloads.list(session.id);
134
+ console.log(downloads.summary.count);
135
+
136
+ const archive = await client.sessions.downloads.archive(session.id);
137
+ ```
138
+
113
139
  ### Contexts
114
140
 
115
141
  Create and inspect contexts:
@@ -138,6 +164,30 @@ Force release a stuck lock:
138
164
  await client.contexts.forceRelease('context-id');
139
165
  ```
140
166
 
167
+ ### Extensions
168
+
169
+ Upload an extension archive:
170
+
171
+ ```ts
172
+ const extension = await client.extensions.upload('/absolute/path/to/extension.zip', {
173
+ name: 'demo-extension',
174
+ });
175
+ ```
176
+
177
+ List and inspect extensions:
178
+
179
+ ```ts
180
+ const extensions = await client.extensions.list({ limit: 10 });
181
+ const details = await client.extensions.get(extension.id);
182
+ console.log(details.name);
183
+ ```
184
+
185
+ Delete an uploaded extension:
186
+
187
+ ```ts
188
+ await client.extensions.delete(extension.id);
189
+ ```
190
+
141
191
  ### Playwright Example
142
192
 
143
193
  ```ts
@@ -224,6 +274,9 @@ Example scripts live in [examples](./examples):
224
274
  - `context-list-get.ts`
225
275
  - `context-modes.ts`
226
276
  - `context-lock-handling.ts`
277
+ - `extension-basic.ts`
278
+ - `proxy-session.ts`
279
+ - `session-downloads.ts`
227
280
 
228
281
  Run them with:
229
282
 
@@ -232,6 +285,9 @@ cd examples
232
285
  npm install
233
286
  npm run playwright-basic
234
287
  npm run session-management
288
+ npm run extension-basic
289
+ npm run proxy-session
290
+ npm run session-downloads
235
291
  ```
236
292
 
237
293
  ### Development
@@ -259,6 +315,9 @@ Lexmount 浏览器自动化服务的 Node.js SDK。
259
315
  - 提供完整类型定义,同时支持 ESM 和 CommonJS
260
316
  - 会话管理,支持分页信息
261
317
  - 持久化 context 管理
318
+ - 扩展上传、查询、详情、删除
319
+ - 会话下载的查询、获取、归档、清理
320
+ - 支持通过上游代理创建会话
262
321
  - 结构化 SDK 异常
263
322
  - 可配置 SDK 日志
264
323
  - 基于 TSDoc + TypeDoc 的自动文档生成能力
@@ -338,6 +397,20 @@ const session = await client.sessions.create({
338
397
  });
339
398
  ```
340
399
 
400
+ 结合扩展和上游代理创建会话:
401
+
402
+ ```ts
403
+ const session = await client.sessions.create({
404
+ extensionIds: ['ext_123'],
405
+ proxy: {
406
+ type: 'external',
407
+ server: 'http://10.3.6.54:28080',
408
+ username: 'user',
409
+ password: 'pass',
410
+ },
411
+ });
412
+ ```
413
+
341
414
  分页列出会话:
342
415
 
343
416
  ```ts
@@ -355,6 +428,15 @@ for (const session of result) {
355
428
  await client.sessions.delete({ sessionId: 'session-id' });
356
429
  ```
357
430
 
431
+ 列出并归档会话下载:
432
+
433
+ ```ts
434
+ const downloads = await client.sessions.downloads.list(session.id);
435
+ console.log(downloads.summary.count);
436
+
437
+ const archive = await client.sessions.downloads.archive(session.id);
438
+ ```
439
+
358
440
  ### Contexts
359
441
 
360
442
  创建并查看 context:
@@ -383,6 +465,30 @@ const contexts = await client.contexts.list({
383
465
  await client.contexts.forceRelease('context-id');
384
466
  ```
385
467
 
468
+ ### Extensions
469
+
470
+ 上传扩展压缩包:
471
+
472
+ ```ts
473
+ const extension = await client.extensions.upload('/absolute/path/to/extension.zip', {
474
+ name: 'demo-extension',
475
+ });
476
+ ```
477
+
478
+ 列出并查看扩展详情:
479
+
480
+ ```ts
481
+ const extensions = await client.extensions.list({ limit: 10 });
482
+ const details = await client.extensions.get(extension.id);
483
+ console.log(details.name);
484
+ ```
485
+
486
+ 删除已上传扩展:
487
+
488
+ ```ts
489
+ await client.extensions.delete(extension.id);
490
+ ```
491
+
386
492
  ### Playwright 示例
387
493
 
388
494
  ```ts
@@ -469,6 +575,9 @@ npm run docs:html
469
575
  - `context-list-get.ts`
470
576
  - `context-modes.ts`
471
577
  - `context-lock-handling.ts`
578
+ - `extension-basic.ts`
579
+ - `proxy-session.ts`
580
+ - `session-downloads.ts`
472
581
 
473
582
  运行方式:
474
583
 
@@ -477,6 +586,9 @@ cd examples
477
586
  npm install
478
587
  npm run playwright-basic
479
588
  npm run session-management
589
+ npm run extension-basic
590
+ npm run proxy-session
591
+ npm run session-downloads
480
592
  ```
481
593
 
482
594
  ### 开发
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { AxiosResponse } from 'axios';
1
+ import { AxiosRequestConfig, AxiosResponse } from 'axios';
2
2
 
3
3
  /**
4
4
  * Supported SDK log levels.
@@ -67,6 +67,27 @@ interface SessionContext {
67
67
  */
68
68
  mode: ContextAccessMode;
69
69
  }
70
+ /**
71
+ * Upstream proxy configuration for a session.
72
+ */
73
+ interface SessionProxyConfig {
74
+ /**
75
+ * Proxy type. Currently `external` is supported by the API.
76
+ */
77
+ type?: 'external' | string;
78
+ /**
79
+ * Upstream proxy server URL.
80
+ */
81
+ server: string;
82
+ /**
83
+ * Optional upstream proxy username.
84
+ */
85
+ username?: string;
86
+ /**
87
+ * Optional upstream proxy password.
88
+ */
89
+ password?: string;
90
+ }
70
91
  /**
71
92
  * SDK client configuration.
72
93
  */
@@ -112,6 +133,14 @@ interface SessionCreateOptions {
112
133
  * Optional persistent context configuration.
113
134
  */
114
135
  context?: SessionContext;
136
+ /**
137
+ * Optional uploaded browser extension identifiers to mount.
138
+ */
139
+ extensionIds?: string[];
140
+ /**
141
+ * Optional upstream proxy configuration.
142
+ */
143
+ proxy?: SessionProxyConfig;
115
144
  }
116
145
  /**
117
146
  * Session list options.
@@ -174,6 +203,72 @@ interface ForceReleaseResponse {
174
203
  status: string;
175
204
  message: string;
176
205
  }
206
+ /**
207
+ * Extension metadata returned by the API.
208
+ */
209
+ interface ExtensionInfoShape {
210
+ id: string;
211
+ name: string;
212
+ projectId: string;
213
+ createdAt?: string;
214
+ updatedAt?: string;
215
+ }
216
+ /**
217
+ * Extension upload options.
218
+ */
219
+ interface ExtensionUploadOptions {
220
+ /**
221
+ * Optional display name for the uploaded extension.
222
+ */
223
+ name?: string;
224
+ /**
225
+ * Override the default project identifier.
226
+ */
227
+ projectId?: string;
228
+ }
229
+ /**
230
+ * Extension list options.
231
+ */
232
+ interface ExtensionListOptions {
233
+ /**
234
+ * Override the default project identifier.
235
+ */
236
+ projectId?: string;
237
+ /**
238
+ * Maximum number of extensions to return.
239
+ */
240
+ limit?: number;
241
+ /**
242
+ * Number of extensions to skip.
243
+ */
244
+ offset?: number;
245
+ }
246
+ /**
247
+ * Session download metadata returned by the API.
248
+ */
249
+ interface SessionDownloadInfoShape {
250
+ id: string;
251
+ filename: string;
252
+ contentType: string | null;
253
+ size: number;
254
+ sha256: string | null;
255
+ status: string;
256
+ createdAt: string;
257
+ }
258
+ /**
259
+ * Structured response from session download listing.
260
+ */
261
+ interface SessionDownloadsListResponseShape {
262
+ count: number;
263
+ totalSize: number;
264
+ }
265
+ /**
266
+ * Structured response from session download deletion.
267
+ */
268
+ interface SessionDownloadsDeleteResponseShape {
269
+ status: string;
270
+ deletedCount: number;
271
+ }
177
272
  /**
178
273
  * Session pagination metadata.
179
274
  */
@@ -250,6 +345,35 @@ declare class ContextsResource {
250
345
  private handleError;
251
346
  }
252
347
 
348
+ /**
349
+ * Extension resource implementation.
350
+ */
351
+
352
+ /**
353
+ * Extension metadata returned by the API.
354
+ */
355
+ declare class ExtensionInfo implements ExtensionInfoShape {
356
+ readonly id: string;
357
+ readonly name: string;
358
+ readonly projectId: string;
359
+ readonly createdAt?: string;
360
+ readonly updatedAt?: string;
361
+ constructor(shape: ExtensionInfoShape);
362
+ }
363
+ /**
364
+ * Browser extension resource operations.
365
+ */
366
+ declare class ExtensionsResource {
367
+ private readonly client;
368
+ constructor(client: Lexmount);
369
+ upload(filePath: string, options?: ExtensionUploadOptions): Promise<ExtensionInfo>;
370
+ list(options?: ExtensionListOptions): Promise<ExtensionInfo[]>;
371
+ get(extensionId: string, projectId?: string): Promise<ExtensionInfo>;
372
+ delete(extensionId: string): Promise<void>;
373
+ private parseInfo;
374
+ private handleError;
375
+ }
376
+
253
377
  /**
254
378
  * Session resource implementation.
255
379
  */
@@ -327,6 +451,47 @@ declare class SessionListResponse implements Iterable<SessionInfo> {
327
451
  [Symbol.iterator](): Iterator<SessionInfo>;
328
452
  at(index: number): SessionInfo | undefined;
329
453
  }
454
+ /**
455
+ * Session download metadata returned by the API.
456
+ */
457
+ declare class SessionDownloadInfo implements SessionDownloadInfoShape {
458
+ readonly id: string;
459
+ readonly filename: string;
460
+ readonly contentType: string | null;
461
+ readonly size: number;
462
+ readonly sha256: string | null;
463
+ readonly status: string;
464
+ readonly createdAt: string;
465
+ constructor(shape: SessionDownloadInfoShape);
466
+ }
467
+ /**
468
+ * Structured response from `sessions.downloads.list()`.
469
+ */
470
+ declare class SessionDownloadsListResponse {
471
+ readonly downloads: SessionDownloadInfo[];
472
+ readonly summary: SessionDownloadsListResponseShape;
473
+ constructor(downloads: SessionDownloadInfo[], summary: SessionDownloadsListResponseShape);
474
+ }
475
+ /**
476
+ * Structured response from `sessions.downloads.delete()`.
477
+ */
478
+ declare class SessionDownloadsDeleteResponse implements SessionDownloadsDeleteResponseShape {
479
+ readonly status: string;
480
+ readonly deletedCount: number;
481
+ constructor(shape: SessionDownloadsDeleteResponseShape);
482
+ }
483
+ /**
484
+ * Session download operations.
485
+ */
486
+ declare class SessionDownloadsResource {
487
+ private readonly client;
488
+ constructor(client: Lexmount);
489
+ list(sessionId: string, projectId?: string): Promise<SessionDownloadsListResponse>;
490
+ get(sessionId: string, downloadId: string, projectId?: string): Promise<Buffer>;
491
+ archive(sessionId: string, projectId?: string): Promise<Buffer>;
492
+ delete(sessionId: string, projectId?: string): Promise<SessionDownloadsDeleteResponse>;
493
+ private handleError;
494
+ }
330
495
  /**
331
496
  * Alias kept for parity with the Python SDK.
332
497
  */
@@ -336,6 +501,7 @@ type SessionCreateResponse = SessionInfo;
336
501
  */
337
502
  declare class SessionsResource {
338
503
  private readonly client;
504
+ readonly downloads: SessionDownloadsResource;
339
505
  constructor(client: Lexmount);
340
506
  /**
341
507
  * Create a new browser session.
@@ -355,6 +521,7 @@ declare class SessionsResource {
355
521
  * @internal
356
522
  */
357
523
  _getWebSocketDebuggerUrl(sessionId: string): Promise<string | null>;
524
+ private normalizeProxy;
358
525
  private handleCreateError;
359
526
  private handleListError;
360
527
  private handleDeleteError;
@@ -388,6 +555,10 @@ declare class Lexmount {
388
555
  * Persistent context operations.
389
556
  */
390
557
  readonly contexts: ContextsResource;
558
+ /**
559
+ * Browser extension operations.
560
+ */
561
+ readonly extensions: ExtensionsResource;
391
562
  private readonly httpClient;
392
563
  constructor(config?: LexmountConfig);
393
564
  /**
@@ -395,19 +566,19 @@ declare class Lexmount {
395
566
  *
396
567
  * @internal
397
568
  */
398
- _post<T = unknown>(url: string, data: Record<string, unknown>): Promise<AxiosResponse<T>>;
569
+ _post<T = unknown>(url: string, data?: unknown, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>;
399
570
  /**
400
571
  * Internal GET request helper with timeout and network error mapping.
401
572
  *
402
573
  * @internal
403
574
  */
404
- _get<T = unknown>(url: string, params: Record<string, unknown>): Promise<AxiosResponse<T>>;
575
+ _get<T = unknown>(url: string, params?: Record<string, unknown>, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>;
405
576
  /**
406
577
  * Internal DELETE request helper with timeout and network error mapping.
407
578
  *
408
579
  * @internal
409
580
  */
410
- _delete<T = unknown>(url: string, data: Record<string, unknown>): Promise<AxiosResponse<T>>;
581
+ _delete<T = unknown>(url: string, data?: unknown, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>;
411
582
  /**
412
583
  * Close the client.
413
584
  *
@@ -420,6 +591,7 @@ declare class Lexmount {
420
591
  toString(): string;
421
592
  private request;
422
593
  private normalizeRequestError;
594
+ private getDefaultHeaders;
423
595
  }
424
596
 
425
597
  /**
@@ -489,4 +661,4 @@ declare class TimeoutError extends LexmountError {
489
661
  */
490
662
  declare const VERSION = "0.2.0";
491
663
 
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 };
664
+ export { APIError, AuthenticationError, type BrowserMode, type ContextAccessMode, type ContextCreateOptions, ContextInfo, type ContextListOptions, ContextListResponse, ContextLockedError, type ContextMetadata, ContextNotFoundError, type ContextStatus, ContextsResource, ExtensionInfo, type ExtensionInfoShape, type ExtensionListOptions, type ExtensionUploadOptions, ExtensionsResource, type ForceReleaseResponse, Lexmount, type LexmountConfig, LexmountError, LexmountLogger, type LogLevel, NetworkError, PaginationInfo, type PaginationInfoShape, type SessionContext, type SessionCreateOptions, type SessionCreateResponse, type SessionDeleteOptions, SessionDownloadInfo, type SessionDownloadInfoShape, SessionDownloadsDeleteResponse, type SessionDownloadsDeleteResponseShape, SessionDownloadsListResponse, type SessionDownloadsListResponseShape, SessionDownloadsResource, SessionInfo, type SessionListOptions, SessionListResponse, SessionNotFoundError, type SessionProxyConfig, type SessionStatus, SessionsResource, TimeoutError, VERSION, ValidationError, Lexmount as default, disableLogging, enableLogging, getLogger, setLogLevel };