@xbrowser/cli 0.14.0 → 0.14.2

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.
@@ -1,7 +1,3 @@
1
- import {
2
- getCaptchaConfig
3
- } from "./chunk-M7CMBPCA.js";
4
-
5
1
  // src/human-interaction.ts
6
2
  import { execSync } from "child_process";
7
3
 
@@ -279,6 +275,90 @@ var WebhookNotifier = class {
279
275
  }
280
276
  };
281
277
 
278
+ // src/config.ts
279
+ import { existsSync, mkdirSync, writeFileSync as writeFileSync2 } from "fs";
280
+ import { join } from "path";
281
+ import { homedir, tmpdir } from "os";
282
+
283
+ // src/utils/json-file.ts
284
+ import { readFileSync, writeFileSync } from "fs";
285
+ function readJsonFile(filePath, defaultValue) {
286
+ try {
287
+ const content = readFileSync(filePath, "utf-8");
288
+ return JSON.parse(content);
289
+ } catch {
290
+ return defaultValue;
291
+ }
292
+ }
293
+
294
+ // src/config.ts
295
+ function getConfigFile() {
296
+ return join(homedir() || tmpdir(), ".xbrowser", "config.json");
297
+ }
298
+ function loadConfig() {
299
+ const configFile = getConfigFile();
300
+ if (!existsSync(configFile)) return {};
301
+ return readJsonFile(configFile, {});
302
+ }
303
+ function saveConfig(config) {
304
+ const dir = join(homedir() || tmpdir(), ".xbrowser");
305
+ const configFile = getConfigFile();
306
+ if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
307
+ writeFileSync2(configFile, JSON.stringify(config, null, 2), "utf-8");
308
+ }
309
+ function getConfigValue(key) {
310
+ return loadConfig()[key];
311
+ }
312
+ function setConfigValue(key, value) {
313
+ const config = loadConfig();
314
+ config[key] = value;
315
+ saveConfig(config);
316
+ }
317
+ var DEFAULT_MARKETPLACE_URL = "https://marketplace.xbrowser.dev";
318
+ var NPM_REGISTRY_URL = "https://registry.npmjs.org";
319
+ var NPM_SCOPE = "@xbrowser/";
320
+ function getMarketplaceUrl() {
321
+ return process.env.XBROWSER_MARKETPLACE_URL || getConfigValue("marketplaceUrl") || DEFAULT_MARKETPLACE_URL;
322
+ }
323
+ function resolveNpmPackageName(name) {
324
+ if (name.startsWith("@")) return name;
325
+ return `${NPM_SCOPE}${name}`;
326
+ }
327
+ var NPM_NAME_ALIASES = {
328
+ "1688": "alibaba-1688"
329
+ };
330
+ function generateNpmCandidates(name) {
331
+ if (name.startsWith("@")) return [name];
332
+ const resolved = NPM_NAME_ALIASES[name] ?? name;
333
+ return [
334
+ `${NPM_SCOPE}xbrowser-plugin-${resolved}`,
335
+ `${NPM_SCOPE}${resolved}`,
336
+ `xbrowser-plugin-${resolved}`
337
+ ];
338
+ }
339
+ async function resolveNpmPackageWithFallback(name) {
340
+ const candidates = generateNpmCandidates(name);
341
+ for (const candidate of candidates) {
342
+ try {
343
+ const encoded = encodeURIComponent(candidate);
344
+ const res = await fetch(`${NPM_REGISTRY_URL}/${encoded}`);
345
+ if (res.ok) return candidate;
346
+ } catch {
347
+ continue;
348
+ }
349
+ }
350
+ return resolveNpmPackageName(name);
351
+ }
352
+ function getCaptchaConfig() {
353
+ const config = loadConfig();
354
+ return {
355
+ notifyUrl: process.env.XBROWSER_NOTIFY_URL || config.captcha?.notifyUrl,
356
+ autoOpen: process.env.XBROWSER_AUTO_OPEN === "true" || config.captcha?.autoOpen === true,
357
+ timeout: parseInt(process.env.XBROWSER_CAPTCHA_TIMEOUT || "") || config.captcha?.timeout || 120,
358
+ previewPort: parseInt(process.env.XBROWSER_PREVIEW_PORT || "") || config.preview?.port || 9223
359
+ };
360
+ }
361
+
282
362
  // src/utils/shell-escape.ts
283
363
  function shellEscape(value) {
284
364
  return `'${value.replace(/'/g, "'\\''")}'`;
@@ -430,8 +510,17 @@ var HumanInteractionManager = class {
430
510
  };
431
511
 
432
512
  export {
513
+ readJsonFile,
433
514
  ScreencastCapturer,
434
515
  CaptchaDetector,
435
516
  WebhookNotifier,
517
+ loadConfig,
518
+ getConfigValue,
519
+ setConfigValue,
520
+ NPM_REGISTRY_URL,
521
+ NPM_SCOPE,
522
+ getMarketplaceUrl,
523
+ resolveNpmPackageWithFallback,
524
+ getCaptchaConfig,
436
525
  HumanInteractionManager
437
526
  };