@atian25/zzz-stats-sdk 0.0.0-stage → 0.1.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/drivers.mjs ADDED
@@ -0,0 +1,473 @@
1
+ /**
2
+ * 浏览器驱动适配层
3
+ *
4
+ * 两套实现,接口完全一致,`collect.mjs` 的业务流程只认接口不认实现:
5
+ *
6
+ * cdp —— 只用 Node 内置模块直讲 Chrome DevTools Protocol。零依赖,兜底方案。
7
+ * playwright —— 环境里已经装了 Playwright 就直接用(更好维护:等待、frame、超时都是现成的)。
8
+ *
9
+ * 两者都优先驱动**用户本机的 Chrome**,不要求下载额外浏览器:
10
+ * - cdp 通过 --remote-debugging-port 起本机 Chrome
11
+ * - playwright 用 channel: 'chrome'(找不到再退回它自带的 chromium)
12
+ *
13
+ * 驱动接口(业务侧只用到这 6 个):
14
+ * open(url) 打开页面
15
+ * evaluate(expr) 在主页面上下文执行 JS,支持返回 Promise
16
+ * waitFor(expr, ms) 轮询直到表达式为真
17
+ * loginFrame() 拿到跨域登录 iframe 的句柄(拿不到返回 null)
18
+ * evaluateInFrame(f, e) 在指定 frame 里执行 JS
19
+ * close() 收尾
20
+ */
21
+ import { abortable, throwIfAborted, SdkError } from './errors.mjs';
22
+ import { existsSync } from 'node:fs';
23
+ import { spawn } from 'node:child_process';
24
+ import { join } from 'node:path';
25
+
26
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
27
+
28
+ /*
29
+ * 登录 iframe 的 host 判定。
30
+ *
31
+ * 国服登录框在 user.mihoyo.com,国际服在 hoyolab 的账号域(user / passport)。
32
+ * 过去这里写死 mihoyo,国际服会一直等不到 frame、误报「登录框没出现」。
33
+ * 两个域都认,另外留一个环境变量口子,官方再换域时不用改代码。
34
+ */
35
+ export const LOGIN_FRAME_RE = (() => {
36
+ const custom = process.env.ZZZ_LOGIN_FRAME_RE;
37
+ if (custom) {
38
+ try { return new RegExp(custom); } catch { /* 写错就退回默认 */ }
39
+ }
40
+ return /user\.mihoyo\.com|(user|passport|account)\.hoyolab\.com/;
41
+ })();
42
+
43
+ // ---------------------------------------------------------------- 公共:找 Chrome
44
+
45
+ const CHROME_CANDIDATES = [
46
+ process.env.CHROME_PATH,
47
+ '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
48
+ '/Applications/Chromium.app/Contents/MacOS/Chromium',
49
+ '/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge',
50
+ '/usr/bin/google-chrome',
51
+ '/usr/bin/google-chrome-stable',
52
+ '/usr/bin/chromium',
53
+ '/usr/bin/chromium-browser',
54
+ '/snap/bin/chromium',
55
+ 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe',
56
+ 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe',
57
+ ].filter(Boolean);
58
+
59
+ export function findChrome() {
60
+ return CHROME_CANDIDATES.find((p) => {
61
+ try { return existsSync(p); } catch { return false; }
62
+ }) ?? null;
63
+ }
64
+
65
+ /** 额外启动参数:受限沙箱里 Chrome 自带 sandbox 常起不来。 */
66
+ export function chromeArgs() {
67
+ return process.env.ZZZ_CHROME_ARGS ? process.env.ZZZ_CHROME_ARGS.split(' ').filter(Boolean) : [];
68
+ }
69
+
70
+ // ---------------------------------------------------------------- CDP 驱动
71
+
72
+ class CdpDriver {
73
+ constructor() {
74
+ this.kind = 'cdp';
75
+ this.#id = 1;
76
+ this.#pending = new Map();
77
+ this.#sessionId = null;
78
+ }
79
+
80
+ #ws;
81
+ #id;
82
+ #pending;
83
+ #sessionId;
84
+ #targetId;
85
+ #creatingTarget;
86
+ #child;
87
+ #closePromise;
88
+
89
+ static async connect(host = '127.0.0.1', port = 9222, signal, child = null, protocol = 'http:') {
90
+ throwIfAborted(signal);
91
+ const authority = host.includes(':') ? `[${host}]` : host;
92
+ const info = await (await fetch(`${protocol}//${authority}:${port}/json/version`, { signal })).json();
93
+ const d = new CdpDriver();
94
+ d.signal = signal;
95
+ d.#child = child;
96
+ d.#ws = new WebSocket(info.webSocketDebuggerUrl);
97
+ await abortable(() => new Promise((res, rej) => {
98
+ d.#ws.addEventListener('open', () => res(), { once: true });
99
+ d.#ws.addEventListener('error', rej, { once: true });
100
+ }), signal).catch(e => { d.#ws.close(); throw e; });
101
+ d.#ws.addEventListener('message', (ev) => {
102
+ const msg = JSON.parse(typeof ev.data === 'string' ? ev.data : '');
103
+ if (msg.id && d.#pending.has(msg.id)) {
104
+ const { res, rej } = d.#pending.get(msg.id);
105
+ d.#pending.delete(msg.id);
106
+ msg.error ? rej(new Error(`${msg.error.message} ${JSON.stringify(msg.error.data ?? '')}`)) : res(msg.result);
107
+ }
108
+ });
109
+ d.version = info.Browser;
110
+ return d;
111
+ }
112
+
113
+ #send(method, params = {}, sessionId = this.#sessionId, signal = this.signal) {
114
+ throwIfAborted(signal);
115
+ let id;
116
+ let timer;
117
+ return abortable(() => new Promise((res, rej) => {
118
+ id = this.#id++;
119
+ if (method === 'Target.createTarget' || method === 'Target.closeTarget') {
120
+ timer = setTimeout(() => rej(new Error(`CDP ${method} 请求超时`)), 5000);
121
+ }
122
+ this.#pending.set(id, { res, rej });
123
+ this.#ws.send(JSON.stringify({ id, method, params, ...(sessionId ? { sessionId } : {}) }));
124
+ }), signal).finally(() => { clearTimeout(timer); this.#pending.delete(id); });
125
+ }
126
+
127
+ async open(url) {
128
+ if (this.#closePromise) throw new Error('CDP driver 已关闭');
129
+ if (!this.#targetId) {
130
+ throwIfAborted(this.signal);
131
+ // 保留原始创建结果:取消后若 target 迟到,close 仍能回收它。
132
+ this.#creatingTarget ??= this.#send('Target.createTarget', { url: 'about:blank' }, null, null)
133
+ .then(({ targetId }) => { this.#targetId = targetId; return targetId; });
134
+ await abortable(() => this.#creatingTarget, this.signal);
135
+ }
136
+ const targetId = this.#targetId;
137
+ const { sessionId } = await this.#send('Target.attachToTarget', { targetId, flatten: true });
138
+ this.#sessionId = sessionId;
139
+ await this.#send('Page.enable');
140
+ await this.#send('Runtime.enable');
141
+ await this.#send('Emulation.setDeviceMetricsOverride', {
142
+ width: 1440, height: 900, deviceScaleFactor: 1, mobile: false,
143
+ }).catch(() => {});
144
+ await this.#send('Target.activateTarget', { targetId }).catch(() => {});
145
+ await this.#send('Page.navigate', { url });
146
+ }
147
+
148
+ async evaluate(expression, contextId) {
149
+ const r = await this.#send('Runtime.evaluate', {
150
+ expression,
151
+ returnByValue: true,
152
+ awaitPromise: true,
153
+ ...(contextId ? { contextId } : {}),
154
+ });
155
+ if (r.exceptionDetails) return { __error: r.exceptionDetails.text };
156
+ return r.result?.value;
157
+ }
158
+
159
+ async waitFor(expression, timeoutMs = 30000, every = 400) {
160
+ const deadline = Date.now() + timeoutMs;
161
+ while (Date.now() < deadline) {
162
+ const v = await this.evaluate(expression);
163
+ if (v && v !== false && !(v && v.__error)) return v;
164
+ await abortable(() => sleep(every), this.signal);
165
+ }
166
+ return null;
167
+ }
168
+
169
+ async #frames() {
170
+ const tree = await this.#send('Page.getFrameTree');
171
+ const out = [];
172
+ (function walk(n) {
173
+ out.push(n.frame);
174
+ (n.childFrames || []).forEach(walk);
175
+ })(tree.frameTree);
176
+ return out;
177
+ }
178
+
179
+ /**
180
+ * 等跨域登录 frame 出现。
181
+ * 必须轮询:外层 iframe 挂上 ≠ 登录 frame 已经建好执行上下文,
182
+ * 只查一次会偶发拿不到(Playwright 的 frames() 同理)。
183
+ */
184
+ async loginFrame() {
185
+ for (let i = 0; i < 40; i += 1) {
186
+ const f = (await this.#frames()).find((x) => LOGIN_FRAME_RE.test(x.url));
187
+ if (f) {
188
+ try {
189
+ const { executionContextId } = await this.#send('Page.createIsolatedWorld', {
190
+ frameId: f.id,
191
+ worldName: 'zzz-collect',
192
+ });
193
+ return { __cdpContext: executionContextId, url: f.url };
194
+ } catch {
195
+ // frame 刚建好又导航了,下一轮再试
196
+ }
197
+ }
198
+ await abortable(() => sleep(500), this.signal);
199
+ }
200
+ return null;
201
+ }
202
+
203
+ async evaluateInFrame(frame, expression) {
204
+ return this.evaluate(expression, frame.__cdpContext);
205
+ }
206
+
207
+ close() {
208
+ return this.#closePromise ??= (async () => {
209
+ try {
210
+ await this.#creatingTarget;
211
+ if (this.#targetId) await this.#send('Target.closeTarget', { targetId: this.#targetId }, null, null);
212
+ } catch { /* 连接已断开时无法关闭 target,仍须释放自有进程。 */ }
213
+ finally {
214
+ for (const { rej } of this.#pending.values()) rej(new Error('CDP driver 已关闭'));
215
+ this.#pending.clear();
216
+ try { this.#ws.close(); } catch {}
217
+ if (this.#child) await stopChrome(this.#child);
218
+ }
219
+ })();
220
+ }
221
+ }
222
+
223
+ /** 只终止本次 spawn 的进程;等待 exit,SIGTERM 超时后 SIGKILL 兜底。 */
224
+ async function stopChrome(child) {
225
+ if (!child.pid || child.exitCode !== null || child.signalCode !== null) return;
226
+ await new Promise((resolve, reject) => {
227
+ const done = () => { clearTimeout(timer); resolve(); };
228
+ child.once('exit', done);
229
+ const timer = setTimeout(() => {
230
+ try { child.kill('SIGKILL'); } catch (cause) { child.removeListener('exit', done); reject(cause); }
231
+ }, 2000);
232
+ try { child.kill('SIGTERM'); }
233
+ catch (cause) { clearTimeout(timer); child.removeListener('exit', done); reject(cause); }
234
+ });
235
+ }
236
+
237
+ /** 起一个带 CDP 端口的本机 Chrome(已在跑就直接连,不取得进程所有权)。 */
238
+ async function launchCdp({ port, profile, bin, log, signal }) {
239
+ try {
240
+ return await CdpDriver.connect('127.0.0.1', port, signal);
241
+ } catch (e) { throwIfAborted(signal); }
242
+
243
+ throwIfAborted(signal);
244
+ log(`启动本机 Chrome:${bin}`);
245
+ const child = spawn(bin, [
246
+ `--remote-debugging-port=${port}`,
247
+ `--user-data-dir=${profile}`,
248
+ '--no-first-run',
249
+ '--no-default-browser-check',
250
+ ...chromeArgs(),
251
+ 'about:blank',
252
+ ], { stdio: ['ignore', 'ignore', 'pipe'] });
253
+
254
+ let stderr = '';
255
+ let spawnError;
256
+ child.on('error', cause => { spawnError = cause; });
257
+ child.stderr?.on('data', (b) => { stderr = (stderr + b.toString()).slice(-8192); });
258
+
259
+ try {
260
+ for (let i = 0; i < 60; i += 1) {
261
+ await abortable(() => sleep(500), signal);
262
+ if (spawnError) throw spawnError;
263
+ if (child.exitCode !== null || child.signalCode !== null) break;
264
+ try {
265
+ const d = await CdpDriver.connect('127.0.0.1', port, signal, child);
266
+ if (signal?.aborted) { await d.close(); throwIfAborted(signal); }
267
+ return d;
268
+ } catch (e) { throwIfAborted(signal); }
269
+ }
270
+ const hint = stderr.trim().split('\n').slice(-3).join('\n');
271
+ throw new Error(
272
+ `Chrome 没在端口 ${port} 起来。\n` +
273
+ ` 1) profile 被另一个 Chrome 占用 → 换 --profile 或先关掉\n` +
274
+ ` 2) 受限沙箱 → 设 ZZZ_CHROME_ARGS='--no-sandbox --headless=new'\n` +
275
+ ` 3) 改用已开着的 Chrome:--cdp http://127.0.0.1:9222\n` +
276
+ (hint ? `Chrome 输出:\n${hint}` : ''),
277
+ );
278
+ } catch (cause) {
279
+ await stopChrome(child);
280
+ throw cause;
281
+ }
282
+ }
283
+
284
+ // ----------------------------------------------------------- Playwright 驱动
285
+
286
+ class PlaywrightDriver {
287
+ constructor(browser, page, context = null) {
288
+ this.kind = 'playwright';
289
+ this.browser = browser;
290
+ this.page = page;
291
+ // 持久化上下文:关闭时要关 context,否则 profile 不会被正确落盘
292
+ this.context = context;
293
+ this.version = browser ? browser.version() : 'persistent';
294
+ }
295
+
296
+ async open(url) {
297
+ throwIfAborted(this.signal);
298
+ await this.page.goto(url, { waitUntil: 'domcontentloaded', timeout: 45000 });
299
+ }
300
+
301
+ async evaluate(expression) {
302
+ // Playwright 接受字符串表达式;Promise 会自动 await
303
+ try {
304
+ return await abortable(() => this.page.evaluate(expression), this.signal);
305
+ } catch (e) {
306
+ if (e instanceof SdkError) throw e;
307
+ return { __error: e.message };
308
+ }
309
+ }
310
+
311
+ async waitFor(expression, timeoutMs = 30000, every = 400) {
312
+ const deadline = Date.now() + timeoutMs;
313
+ while (Date.now() < deadline) {
314
+ const v = await this.evaluate(expression);
315
+ if (v && v !== false && !(v && v.__error)) return v;
316
+ await abortable(() => sleep(every), this.signal);
317
+ }
318
+ return null;
319
+ }
320
+
321
+ async loginFrame() {
322
+ for (let i = 0; i < 40; i += 1) {
323
+ const f = this.page.frames().find((x) => LOGIN_FRAME_RE.test(x.url()));
324
+ if (f) return f;
325
+ await abortable(() => sleep(500), this.signal);
326
+ }
327
+ return null;
328
+ }
329
+
330
+ async evaluateInFrame(frame, expression) {
331
+ try {
332
+ return await abortable(() => frame.evaluate(expression), this.signal);
333
+ } catch (e) {
334
+ if (e instanceof SdkError) throw e;
335
+ return { __error: e.message };
336
+ }
337
+ }
338
+
339
+ async close() {
340
+ try {
341
+ if (this.context) await this.context.close();
342
+ else await this.browser.close();
343
+ } catch {}
344
+ }
345
+ }
346
+
347
+ /**
348
+ * 尝试用 Playwright 起浏览器。
349
+ * 用 channel:'chrome' 驱动本机 Chrome —— 这样不需要 Playwright 下载自带浏览器,
350
+ * 用户装了 Chrome 就能用。找不到 Chrome 才退回 Playwright 自带的 chromium。
351
+ */
352
+ async function launchPlaywright({ headless, log, modulePath, profile, chromium: injectedChromium, signal }) {
353
+ const mod = injectedChromium ? null : await import(modulePath);
354
+ const chromium = injectedChromium ?? mod.chromium ?? mod.default?.chromium;
355
+ if (!chromium) throw new Error('Playwright 模块里没有 chromium');
356
+
357
+ throwIfAborted(signal);
358
+ const args = chromeArgs();
359
+ const base = { headless, args };
360
+ /*
361
+ * 传了 profile 就用持久化上下文。
362
+ * 否则每次都是全新临时 profile —— 登录态存不住,
363
+ * 「先扫码、再单独跑一次取数」这种分两次执行的降级路线就没法用。
364
+ */
365
+ if (profile) {
366
+ const ctx = await chromium.launchPersistentContext(profile, {
367
+ channel: findChrome() ? 'chrome' : undefined,
368
+ viewport: { width: 1440, height: 900 },
369
+ ...base,
370
+ });
371
+ if (signal?.aborted) { await ctx.close(); throwIfAborted(signal); }
372
+ log(`Playwright 就绪(持久化 profile:${profile})`);
373
+ // 持久化上下文自带页面;没有就新建一个
374
+ let page;
375
+ try { page = ctx.pages()[0] ?? (await abortable(() => ctx.newPage(), signal)); }
376
+ catch (cause) { await ctx.close(); throw cause; }
377
+ if (signal?.aborted) { await ctx.close(); throwIfAborted(signal); }
378
+ return new PlaywrightDriver(ctx.browser(), page, ctx);
379
+ }
380
+
381
+ let browser = null;
382
+ if (findChrome()) {
383
+ try {
384
+ browser = await chromium.launch({ channel: 'chrome', ...base });
385
+ log('Playwright 就绪(驱动本机 Chrome)');
386
+ } catch (e) {
387
+ throwIfAborted(signal);
388
+ log(`Playwright 走 channel:chrome 失败,改用自带 chromium:${e.message.split('\n')[0]}`);
389
+ }
390
+ }
391
+ if (signal?.aborted) { await browser?.close(); throwIfAborted(signal); }
392
+ if (!browser) {
393
+ browser = await chromium.launch(base);
394
+ log('Playwright 就绪(使用自带 chromium)');
395
+ }
396
+ if (signal?.aborted) { await browser.close(); throwIfAborted(signal); }
397
+ let page;
398
+ try { page = await browser.newPage({ viewport: { width: 1440, height: 900 } }); }
399
+ catch (cause) { await browser.close(); throw cause; }
400
+ if (signal?.aborted) { await browser.close(); throwIfAborted(signal); }
401
+ return new PlaywrightDriver(browser, page);
402
+ }
403
+
404
+ /** 正常模块解析或调用方显式指定模块;不搜索宿主 profile。 */
405
+ async function resolvePlaywright(modulePath) {
406
+ const explicit = modulePath ?? process.env.ZZZ_PLAYWRIGHT_PATH;
407
+ if (explicit) return import.meta.resolve(explicit);
408
+ for (const name of ['playwright', 'playwright-core']) {
409
+ try { return import.meta.resolve(name); } catch {}
410
+ }
411
+ return null;
412
+ }
413
+
414
+ // ------------------------------------------------------------------ 统一入口
415
+
416
+ /**
417
+ * 按优先级挑一个驱动:
418
+ * 1) --cdp <url> 用户已开着的 Chrome
419
+ * 2) --driver <name> 强制指定 cdp / playwright
420
+ * 3) 默认:有 Playwright 就用它(更稳),否则用零依赖的 cdp(起本机 Chrome)
421
+ *
422
+ * @returns {Promise<CdpDriver|PlaywrightDriver>}
423
+ */
424
+ export async function openDriver({ cdpUrl, driver, port, profile, chromium, playwrightModule, headless = true, log = console.log, signal }) {
425
+ throwIfAborted(signal);
426
+ // 取消后迟到的创建结果也收尾;已发出的启动动作无法撤销。
427
+ const acquire = async (operation, awaitCleanup = false) => {
428
+ const pending = Promise.resolve().then(() => { throwIfAborted(signal); return operation(); });
429
+ pending.then(d => { if (signal?.aborted) void d.close?.(); }, () => {});
430
+ let d;
431
+ try { d = await abortable(() => pending, signal); }
432
+ catch (cause) {
433
+ // CDP 启动/连接本身支持取消,等待其进程清理;外部 Playwright 可迟到。
434
+ if (awaitCleanup) await pending.then(d => d.close?.(), () => {});
435
+ throw cause;
436
+ }
437
+ if (signal?.aborted) { await d.close?.(); throwIfAborted(signal); }
438
+ d.signal = signal;
439
+ return d;
440
+ };
441
+ const want = driver ?? (cdpUrl ? 'cdp' : (chromium || playwrightModule ? 'playwright' : null));
442
+
443
+ if (want === 'cdp' || cdpUrl) {
444
+ if (cdpUrl) {
445
+ const url = new URL(cdpUrl);
446
+ const d = await acquire(() => CdpDriver.connect(url.hostname.replace(/^\[|\]$/g, ''), url.port || 9222, signal, null, url.protocol));
447
+ log(`已连接现有 Chrome(CDP ${cdpUrl})`);
448
+ return d;
449
+ }
450
+ const bin = findChrome();
451
+ if (!bin) throw new Error('本机没找到 Chrome/Chromium。用 CHROME_PATH 指定路径。');
452
+ return acquire(() => launchCdp({ port, profile, bin, log, signal }), true);
453
+ }
454
+
455
+ if (want === 'playwright' || want === null) {
456
+ const pw = chromium ? null : await resolvePlaywright(playwrightModule);
457
+ if (chromium || pw) {
458
+ try {
459
+ return await acquire(() => launchPlaywright({ headless, log, modulePath: pw, profile, chromium, signal }));
460
+ } catch (e) {
461
+ throwIfAborted(signal);
462
+ if (want === 'playwright') throw e;
463
+ log(`Playwright 启动失败,退回零依赖 CDP:${e.message.split('\n')[0]}`);
464
+ }
465
+ } else if (want === 'playwright') {
466
+ throw new Error('没找到 Playwright。用 --driver cdp,或先装 playwright。');
467
+ }
468
+ }
469
+
470
+ const bin = findChrome();
471
+ if (!bin) throw new Error('本机没找到 Chrome/Chromium。用 CHROME_PATH 指定路径。');
472
+ return acquire(() => launchCdp({ port, profile, bin, log, signal }), true);
473
+ }
package/errors.mjs ADDED
@@ -0,0 +1,42 @@
1
+ /** 公共错误形状。cause 仅供本地诊断,不应序列化到页面或日志。 */
2
+ export class SdkError extends Error {
3
+ constructor(code, message, { stage = 'validate', retcode, httpStatus, endpoint, cause } = {}) {
4
+ super(message, cause === undefined ? undefined : { cause });
5
+ this.name = 'SdkError';
6
+ this.code = code;
7
+ this.stage = stage;
8
+ if (retcode !== undefined) this.retcode = retcode;
9
+ if (httpStatus !== undefined) this.httpStatus = httpStatus;
10
+ if (endpoint !== undefined) this.endpoint = endpoint;
11
+ }
12
+ }
13
+
14
+ export function throwIfAborted(signal) {
15
+ if (signal?.aborted) throw new SdkError('ABORTED', '操作已取消', { cause: signal.reason });
16
+ }
17
+
18
+ /** 可结束对未配合取消的外部 Promise 的等待,但不能撤销它的副作用。 */
19
+ export function abortable(operation, signal) {
20
+ throwIfAborted(signal);
21
+ if (!signal) return Promise.resolve().then(operation);
22
+ return new Promise((resolve, reject) => {
23
+ const abort = () => reject(new SdkError('ABORTED', '操作已取消', { cause: signal.reason }));
24
+ signal.addEventListener('abort', abort, { once: true });
25
+ Promise.resolve().then(() => { throwIfAborted(signal); return operation(); })
26
+ .then(resolve, reject).finally(() => signal.removeEventListener('abort', abort));
27
+ });
28
+ }
29
+
30
+ /** 不关闭借入驱动;取消仅终止等待,不能撤销已发送的浏览器操作。 */
31
+ export function guardDriver(driver, signal, stage = 'driver') {
32
+ return new Proxy(driver, {
33
+ get(target, key) {
34
+ const value = Reflect.get(target, key);
35
+ if (typeof value !== 'function' || key === 'close') return typeof value === 'function' ? value.bind(target) : value;
36
+ return (...args) => abortable(() => value.apply(target, args), signal).catch(cause => {
37
+ if (cause instanceof SdkError) throw cause;
38
+ throw new SdkError('BROWSER_UNAVAILABLE', '浏览器操作失败', { stage, cause });
39
+ });
40
+ },
41
+ });
42
+ }
package/index.mjs ADDED
@@ -0,0 +1,6 @@
1
+ /** 采集 SDK 公共入口:仅登录、取数、完整流程、二维码编码与错误类型。
2
+ * 不读报表资源、不保存采集产物、不解析 argv;内部工具不构成公共 API。
3
+ */
4
+ export { collectData, login, collect } from './api.mjs';
5
+ export { encodeQrDataUrl } from './qr.mjs';
6
+ export { SdkError } from './errors.mjs';