@mearl/client 2.9.2 → 2.9.4

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/dist/check.js CHANGED
@@ -1,4 +1,4 @@
1
- import { UnifiedClient } from './unified.js';
1
+ import { UnifiedClient, normalizeBrowserSelector, } from './unified.js';
2
2
  function formatError(error) {
3
3
  return error instanceof Error ? error.message : String(error);
4
4
  }
@@ -16,7 +16,7 @@ function redactServerUrl(serverUrl) {
16
16
  }
17
17
  }
18
18
  function browserMatches(browser, selector) {
19
- const normalized = selector.trim().toLowerCase();
19
+ const normalized = normalizeBrowserSelector(selector);
20
20
  return (browser.browserId.toLowerCase() === normalized ||
21
21
  browser.originalBrowserId?.toLowerCase() === normalized ||
22
22
  browser.name.toLowerCase() === normalized ||
@@ -26,7 +26,7 @@ function findBrowsers(browsers, selector) {
26
26
  const exact = browsers.filter(browser => browserMatches(browser, selector));
27
27
  if (exact.length > 0)
28
28
  return exact;
29
- const normalized = selector.trim().toLowerCase();
29
+ const normalized = normalizeBrowserSelector(selector);
30
30
  return browsers.filter(browser => browser.browserId.toLowerCase().includes(normalized) ||
31
31
  browser.originalBrowserId?.toLowerCase().includes(normalized) ||
32
32
  browser.name.toLowerCase().includes(normalized) ||
@@ -336,15 +336,15 @@ export declare const COMMANDS: readonly [{
336
336
  readonly examples: ["send_mtop_request --payload '{\"api\":\"mtop.trade.order.detail\",\"data\":{\"orderId\":\"123\"}}'"];
337
337
  }, {
338
338
  readonly name: "tdbank_account";
339
- readonly description: "TDBank 账号操作:获取当前账号、账号列表、切换账号、快速借用并切换账号";
339
+ readonly description: "TDBank 账号操作:获取扫码登录二维码、当前账号、账号列表、切换账号、快速借用并切换账号";
340
340
  readonly params: [{
341
341
  readonly name: "tabId";
342
342
  readonly type: "number";
343
- readonly description: "CDP 模式下可指定用于读取 Cookie 的标签页 ID";
343
+ readonly description: "login 后续查询或选身份时复用首次返回的标签页 ID;其他操作在 CDP 模式下用于读取 Cookie";
344
344
  }, {
345
345
  readonly name: "operation";
346
- readonly type: "\"current\" | \"list\" | \"switch\" | \"borrow\"";
347
- readonly description: "操作类型,默认 list";
346
+ readonly type: "\"current\" | \"list\" | \"login\" | \"switch\" | \"borrow\"";
347
+ readonly description: "操作类型,默认 current";
348
348
  }, {
349
349
  readonly name: "refresh";
350
350
  readonly type: "boolean";
@@ -360,17 +360,25 @@ export declare const COMMANDS: readonly [{
360
360
  }, {
361
361
  readonly name: "havanaId";
362
362
  readonly type: "string | number";
363
- readonly description: "switch 时也可直接指定 havanaId";
363
+ readonly description: "switch 时直接指定 havanaId;TDBank 方式需配合 site,免密方式需配合 ssoKey";
364
364
  }, {
365
365
  readonly name: "site";
366
366
  readonly type: "string | number";
367
- readonly description: "直接指定 havanaId 时必填";
367
+ readonly description: "TDBank 方式直接指定 havanaId 时必填";
368
+ }, {
369
+ readonly name: "ssoKey";
370
+ readonly type: "string";
371
+ readonly description: "switch 免密方式的秘钥;必须同时传 havanaId,site 固定为 taobao";
368
372
  }, {
369
373
  readonly name: "query";
370
374
  readonly type: "string";
371
375
  readonly description: "borrow 时输入要借用的账号 loginId/关键词";
376
+ }, {
377
+ readonly name: "identityId";
378
+ readonly type: "string | number";
379
+ readonly description: "login 返回 identity_required 后,传用户明确选择的 identityId";
372
380
  }];
373
- readonly examples: ["tdbank_account --payload '{\"operation\":\"current\"}'", "tdbank_account --payload '{\"operation\":\"list\",\"refresh\":true}'", "tdbank_account --payload '{\"operation\":\"switch\",\"accountId\":12345}'", "tdbank_account --payload '{\"operation\":\"borrow\",\"query\":\"test_account\"}'"];
381
+ readonly examples: ["tdbank_account --payload '{\"operation\":\"login\"}'", "tdbank_account --payload '{\"operation\":\"login\",\"tabId\":12345}'", "tdbank_account --payload '{\"operation\":\"login\",\"tabId\":12345,\"identityId\":\"10001\"}'", "tdbank_account --payload '{\"operation\":\"current\"}'", "tdbank_account --payload '{\"operation\":\"list\",\"refresh\":true}'", "tdbank_account --payload '{\"operation\":\"switch\",\"accountId\":12345}'", "tdbank_account --payload '{\"operation\":\"switch\",\"havanaId\":\"1234567890\",\"ssoKey\":\"<secret>\"}'", "tdbank_account --payload '{\"operation\":\"borrow\",\"query\":\"test_account\"}'"];
374
382
  }, {
375
383
  readonly name: "browser_list";
376
384
  readonly description: "列出所有浏览器及其连接状态、类型和托管实例信息;AgentBay 可包含镜像与持久化 Context";
package/dist/commands.js CHANGED
@@ -236,29 +236,47 @@ export const COMMANDS = [
236
236
  },
237
237
  {
238
238
  name: 'tdbank_account',
239
- description: 'TDBank 账号操作:获取当前账号、账号列表、切换账号、快速借用并切换账号',
239
+ description: 'TDBank 账号操作:获取扫码登录二维码、当前账号、账号列表、切换账号、快速借用并切换账号',
240
240
  params: [
241
241
  {
242
242
  name: 'tabId',
243
243
  type: 'number',
244
- description: 'CDP 模式下可指定用于读取 Cookie 的标签页 ID',
244
+ description: 'login 后续查询或选身份时复用首次返回的标签页 ID;其他操作在 CDP 模式下用于读取 Cookie',
245
245
  },
246
246
  {
247
247
  name: 'operation',
248
- type: '"current" | "list" | "switch" | "borrow"',
249
- description: '操作类型,默认 list',
248
+ type: '"current" | "list" | "login" | "switch" | "borrow"',
249
+ description: '操作类型,默认 current',
250
250
  },
251
251
  { name: 'refresh', type: 'boolean', description: 'list 时是否强制刷新账号列表' },
252
252
  { name: 'pageIndex', type: 'number', description: 'list 时的页码,默认 1' },
253
253
  { name: 'accountId', type: 'string | number', description: 'switch 时使用账号列表中的 id' },
254
- { name: 'havanaId', type: 'string | number', description: 'switch 时也可直接指定 havanaId' },
255
- { name: 'site', type: 'string | number', description: '直接指定 havanaId 时必填' },
254
+ {
255
+ name: 'havanaId',
256
+ type: 'string | number',
257
+ description: 'switch 时直接指定 havanaId;TDBank 方式需配合 site,免密方式需配合 ssoKey',
258
+ },
259
+ { name: 'site', type: 'string | number', description: 'TDBank 方式直接指定 havanaId 时必填' },
260
+ {
261
+ name: 'ssoKey',
262
+ type: 'string',
263
+ description: 'switch 免密方式的秘钥;必须同时传 havanaId,site 固定为 taobao',
264
+ },
256
265
  { name: 'query', type: 'string', description: 'borrow 时输入要借用的账号 loginId/关键词' },
266
+ {
267
+ name: 'identityId',
268
+ type: 'string | number',
269
+ description: 'login 返回 identity_required 后,传用户明确选择的 identityId',
270
+ },
257
271
  ],
258
272
  examples: [
273
+ `tdbank_account --payload '{"operation":"login"}'`,
274
+ `tdbank_account --payload '{"operation":"login","tabId":12345}'`,
275
+ `tdbank_account --payload '{"operation":"login","tabId":12345,"identityId":"10001"}'`,
259
276
  `tdbank_account --payload '{"operation":"current"}'`,
260
277
  `tdbank_account --payload '{"operation":"list","refresh":true}'`,
261
278
  `tdbank_account --payload '{"operation":"switch","accountId":12345}'`,
279
+ `tdbank_account --payload '{"operation":"switch","havanaId":"1234567890","ssoKey":"<secret>"}'`,
262
280
  `tdbank_account --payload '{"operation":"borrow","query":"test_account"}'`,
263
281
  ],
264
282
  },
@@ -112,14 +112,16 @@ export interface SendMtopRequestParams {
112
112
  ttid?: string;
113
113
  }
114
114
  export interface TdbankAccountParams {
115
- operation?: 'current' | 'list' | 'switch' | 'borrow';
115
+ operation?: 'current' | 'list' | 'login' | 'switch' | 'borrow';
116
116
  pageIndex?: number;
117
117
  refresh?: boolean;
118
118
  query?: string;
119
119
  accountId?: string | number;
120
120
  havanaId?: string | number;
121
121
  site?: string | number;
122
+ ssoKey?: string;
122
123
  tabId?: number;
124
+ identityId?: string | number;
123
125
  }
124
126
  export type BrowserStatus = 'connected' | 'running_disconnected' | 'stopped';
125
127
  export interface BrowserSource {
package/dist/unified.d.ts CHANGED
@@ -23,6 +23,7 @@ interface BrowserTarget {
23
23
  connector?: string;
24
24
  }
25
25
  export declare function decodeBrowserTarget(selector: string | undefined): BrowserTarget | undefined;
26
+ export declare function normalizeBrowserSelector(selector: string): string;
26
27
  export declare class UnifiedClient {
27
28
  private readonly options;
28
29
  private defaultBrowser;
package/dist/unified.js CHANGED
@@ -6,7 +6,7 @@ import { loadCloudServerConfig, loadLocalConnectorId } from './unifiedConfig.js'
6
6
  const RESPONSE_GRACE_MS = 1_000;
7
7
  const GLOBAL_BROWSER_PREFIX = 'mearl:';
8
8
  function encodeBrowserTarget(target) {
9
- const browser = encodeURIComponent(target.browser);
9
+ const browser = encodeURIComponent(target.browser).replace(/%3A/g, ':');
10
10
  return target.connector
11
11
  ? `${GLOBAL_BROWSER_PREFIX}remote:${encodeURIComponent(target.connector)}:${browser}`
12
12
  : `${GLOBAL_BROWSER_PREFIX}local:${browser}`;
@@ -21,14 +21,18 @@ export function decodeBrowserTarget(selector) {
21
21
  if (!selector?.startsWith(GLOBAL_BROWSER_PREFIX))
22
22
  return undefined;
23
23
  try {
24
- const parts = selector.slice(GLOBAL_BROWSER_PREFIX.length).split(':');
25
- if (parts[0] === 'local' && parts.length === 2) {
26
- const browser = decodeURIComponent(parts[1]);
24
+ const target = selector.slice(GLOBAL_BROWSER_PREFIX.length);
25
+ if (target.startsWith('local:')) {
26
+ const browser = decodeURIComponent(target.slice('local:'.length));
27
27
  return browser ? { browser } : undefined;
28
28
  }
29
- if (parts[0] === 'remote' && parts.length === 3) {
30
- const connector = decodeURIComponent(parts[1]);
31
- const browser = decodeURIComponent(parts[2]);
29
+ if (target.startsWith('remote:')) {
30
+ const remoteTarget = target.slice('remote:'.length);
31
+ const separator = remoteTarget.indexOf(':');
32
+ if (separator < 0)
33
+ return undefined;
34
+ const connector = decodeURIComponent(remoteTarget.slice(0, separator));
35
+ const browser = decodeURIComponent(remoteTarget.slice(separator + 1));
32
36
  return connector && browser ? { connector, browser } : undefined;
33
37
  }
34
38
  }
@@ -37,6 +41,10 @@ export function decodeBrowserTarget(selector) {
37
41
  }
38
42
  return undefined;
39
43
  }
44
+ export function normalizeBrowserSelector(selector) {
45
+ const decodedTarget = decodeBrowserTarget(selector);
46
+ return (decodedTarget ? encodeBrowserTarget(decodedTarget) : selector.trim()).toLowerCase();
47
+ }
40
48
  function decorateBrowser(browser, source) {
41
49
  const safeBrowser = omitTransientBrowserSecrets(browser);
42
50
  const originalBrowserId = String(browser.browserId);
@@ -57,7 +65,7 @@ function decorateBrowser(browser, source) {
57
65
  };
58
66
  }
59
67
  function browserMatches(browser, selector) {
60
- const normalized = selector.trim().toLowerCase();
68
+ const normalized = normalizeBrowserSelector(selector);
61
69
  return (browser.browserId.toLowerCase() === normalized ||
62
70
  browser.originalBrowserId?.toLowerCase() === normalized ||
63
71
  browser.name.toLowerCase() === normalized ||
@@ -70,7 +78,7 @@ function findBrowsers(browsers, selector, connectedOnly = true) {
70
78
  const exact = candidates.filter(browser => browserMatches(browser, selector));
71
79
  if (exact.length > 0)
72
80
  return exact;
73
- const normalized = selector.trim().toLowerCase();
81
+ const normalized = normalizeBrowserSelector(selector);
74
82
  return candidates.filter(browser => browser.browserId.toLowerCase().includes(normalized) ||
75
83
  browser.originalBrowserId?.toLowerCase().includes(normalized) ||
76
84
  browser.name.toLowerCase().includes(normalized) ||
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mearl/client",
3
- "version": "2.9.2",
3
+ "version": "2.9.4",
4
4
  "description": "Unified Mearl SDK & CLI for local and remote browsers",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -55,7 +55,7 @@
55
55
  "commander": "^15.0.0",
56
56
  "fastest-levenshtein": "^1.0.16",
57
57
  "ws": "^8.18.0",
58
- "@mearl/cloud-types": "2.9.2"
58
+ "@mearl/cloud-types": "2.9.4"
59
59
  },
60
60
  "devDependencies": {
61
61
  "@types/node": "^24.9.1",