siluzan-tso-cli 1.0.0-beta.19 → 1.0.0-beta.20

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
@@ -20,7 +20,7 @@ siluzan-tso init -d /path/to/skills # 写入自定义目录
20
20
  siluzan-tso init --force # 强制覆盖已存在文件
21
21
  ```
22
22
 
23
- > **注意**:当前为测试版(1.0.0-beta.19),供内部测试使用。正式发布后安装命令将改为 `npm install -g siluzan-tso-cli`。
23
+ > **注意**:当前为测试版(1.0.0-beta.20),供内部测试使用。正式发布后安装命令将改为 `npm install -g siluzan-tso-cli`。
24
24
 
25
25
  | 助手 | 建议 `--ai` |
26
26
  |------|-------------|
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/index.ts
4
- import * as fs7 from "fs";
5
- import * as path8 from "path";
4
+ import * as fs8 from "fs";
5
+ import * as path9 from "path";
6
6
  import { fileURLToPath as fileURLToPath3 } from "url";
7
7
  import { Command } from "commander";
8
8
 
@@ -17,6 +17,9 @@ import * as path from "path";
17
17
  import * as os from "os";
18
18
  import * as https from "https";
19
19
  import * as http from "http";
20
+ import * as fs2 from "fs";
21
+ import * as path2 from "path";
22
+ import { fileURLToPath } from "url";
20
23
  var SILUZAN_DIR = path.join(os.homedir(), ".siluzan");
21
24
  var CONFIG_FILE = path.join(SILUZAN_DIR, "config.json");
22
25
  function readStr(raw, key) {
@@ -170,6 +173,46 @@ async function apiFetch(url, config, options = {}, verbose = false) {
170
173
  function sleep(ms) {
171
174
  return new Promise((resolve2) => setTimeout(resolve2, ms));
172
175
  }
176
+ function getCurrentVersion(importMetaUrl) {
177
+ try {
178
+ const __dirname2 = path2.dirname(fileURLToPath(importMetaUrl));
179
+ const pkgPath = path2.join(__dirname2, "..", "..", "package.json");
180
+ const pkg = JSON.parse(fs2.readFileSync(pkgPath, "utf8"));
181
+ return pkg.version ?? "0.0.0";
182
+ } catch {
183
+ return "0.0.0";
184
+ }
185
+ }
186
+ function isNewer(a, b) {
187
+ const parse = (v) => {
188
+ const [base, pre] = v.replace(/^v/, "").split("-beta.");
189
+ const nums = base.split(".").map(Number);
190
+ nums.push(pre !== void 0 ? Number(pre) : Infinity);
191
+ return nums;
192
+ };
193
+ const av = parse(a);
194
+ const bv = parse(b);
195
+ for (let i = 0; i < Math.max(av.length, bv.length); i++) {
196
+ const ai = av[i] ?? 0;
197
+ const bi = bv[i] ?? 0;
198
+ if (bi !== ai) return bi > ai;
199
+ }
200
+ return false;
201
+ }
202
+ async function fetchNpmVersion(pkgName, tag, timeoutMs = 4e3) {
203
+ try {
204
+ const url = `https://registry.npmjs.org/${pkgName}/${tag}`;
205
+ const controller = new AbortController();
206
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
207
+ const res = await fetch(url, { signal: controller.signal });
208
+ clearTimeout(timer);
209
+ if (!res.ok) return null;
210
+ const data = await res.json();
211
+ return data.version ?? null;
212
+ } catch {
213
+ return null;
214
+ }
215
+ }
173
216
 
174
217
  // src/utils/auth.ts
175
218
  function deriveMainApiUrl(tsoApiBaseUrl) {
@@ -343,26 +386,26 @@ function cmdConfigClear() {
343
386
  }
344
387
 
345
388
  // src/commands/init.ts
346
- import * as fs3 from "fs/promises";
389
+ import * as fs4 from "fs/promises";
347
390
  import * as fsSync from "fs";
348
391
  import * as os2 from "os";
349
- import * as path3 from "path";
350
- import { fileURLToPath } from "url";
392
+ import * as path4 from "path";
393
+ import { fileURLToPath as fileURLToPath2 } from "url";
351
394
 
352
395
  // src/templates/load-templates.ts
353
- import * as fs2 from "fs/promises";
354
- import * as path2 from "path";
396
+ import * as fs3 from "fs/promises";
397
+ import * as path3 from "path";
355
398
  async function getSkillFiles(skillDir) {
356
399
  const out = {};
357
400
  async function walk(dir, prefix) {
358
- const entries = await fs2.readdir(dir, { withFileTypes: true });
401
+ const entries = await fs3.readdir(dir, { withFileTypes: true });
359
402
  for (const ent of entries) {
360
403
  const rel = prefix ? `${prefix}/${ent.name}` : ent.name;
361
- const full = path2.join(dir, ent.name);
404
+ const full = path3.join(dir, ent.name);
362
405
  if (ent.isDirectory()) {
363
406
  await walk(full, rel);
364
407
  } else {
365
- out[rel] = await fs2.readFile(full, "utf8");
408
+ out[rel] = await fs3.readFile(full, "utf8");
366
409
  }
367
410
  }
368
411
  }
@@ -371,14 +414,14 @@ async function getSkillFiles(skillDir) {
371
414
  }
372
415
 
373
416
  // src/commands/init.ts
374
- var __dirname = path3.dirname(fileURLToPath(import.meta.url));
417
+ var __dirname = path4.dirname(fileURLToPath2(import.meta.url));
375
418
  var TARGET_DIRS = {
376
- cursor: (cwd) => path3.join(cwd, ".cursor", "skills", "siluzan-tso"),
377
- claude: (cwd) => path3.join(cwd, ".claude", "skills", "siluzan-tso"),
378
- "openclaw-workspace": (cwd) => path3.join(cwd, "skills", "siluzan-tso"),
379
- "openclaw-global": (_cwd, home) => path3.join(home, ".openclaw", "skills", "siluzan-tso"),
380
- "workbuddy-workspace": (cwd) => path3.join(cwd, ".workbuddy", "skills", "siluzan-tso"),
381
- "workbuddy-global": (_cwd, home) => path3.join(home, ".workbuddy", "skills", "siluzan-tso")
419
+ cursor: (cwd) => path4.join(cwd, ".cursor", "skills", "siluzan-tso"),
420
+ claude: (cwd) => path4.join(cwd, ".claude", "skills", "siluzan-tso"),
421
+ "openclaw-workspace": (cwd) => path4.join(cwd, "skills", "siluzan-tso"),
422
+ "openclaw-global": (_cwd, home) => path4.join(home, ".openclaw", "skills", "siluzan-tso"),
423
+ "workbuddy-workspace": (cwd) => path4.join(cwd, ".workbuddy", "skills", "siluzan-tso"),
424
+ "workbuddy-global": (_cwd, home) => path4.join(home, ".workbuddy", "skills", "siluzan-tso")
382
425
  };
383
426
  function parseTargets(raw) {
384
427
  const normalized = raw.trim().toLowerCase();
@@ -419,32 +462,32 @@ function parseTargets(raw) {
419
462
  return [...new Set(result)];
420
463
  }
421
464
  function skillRoot() {
422
- return path3.join(__dirname, "..", "skill");
465
+ return path4.join(__dirname, "..", "skill");
423
466
  }
424
467
  async function writeSkillFilesToDir(destDir, skillFiles, force) {
425
- await fs3.mkdir(destDir, { recursive: true });
468
+ await fs4.mkdir(destDir, { recursive: true });
426
469
  let anyWritten = false;
427
470
  for (const [relativePath, content] of Object.entries(skillFiles)) {
428
- const fullPath = path3.join(destDir, relativePath);
429
- await fs3.mkdir(path3.dirname(fullPath), { recursive: true });
471
+ const fullPath = path4.join(destDir, relativePath);
472
+ await fs4.mkdir(path4.dirname(fullPath), { recursive: true });
430
473
  try {
431
- await fs3.access(fullPath);
474
+ await fs4.access(fullPath);
432
475
  if (!force) {
433
476
  console.warn(`\u8DF3\u8FC7\uFF08\u5DF2\u5B58\u5728\uFF0C\u4F7F\u7528 --force \u8986\u76D6\uFF09: ${fullPath}`);
434
477
  continue;
435
478
  }
436
479
  } catch {
437
480
  }
438
- await fs3.writeFile(fullPath, content, "utf8");
481
+ await fs4.writeFile(fullPath, content, "utf8");
439
482
  console.log(`\u5DF2\u5199\u5165: ${fullPath}`);
440
483
  anyWritten = true;
441
484
  }
442
485
  return anyWritten;
443
486
  }
444
487
  function saveInstalledTargets(entries) {
445
- const CONFIG_FILE3 = path3.join(os2.homedir(), ".siluzan", "config.json");
488
+ const CONFIG_FILE3 = path4.join(os2.homedir(), ".siluzan", "config.json");
446
489
  try {
447
- fsSync.mkdirSync(path3.dirname(CONFIG_FILE3), { recursive: true });
490
+ fsSync.mkdirSync(path4.dirname(CONFIG_FILE3), { recursive: true });
448
491
  let existing = {};
449
492
  if (fsSync.existsSync(CONFIG_FILE3)) {
450
493
  existing = JSON.parse(fsSync.readFileSync(CONFIG_FILE3, "utf8"));
@@ -470,7 +513,7 @@ async function runInit(options) {
470
513
  const skillFiles = await getSkillFiles(skillRoot());
471
514
  const installedEntries = [];
472
515
  if (options.dir) {
473
- const destDir = path3.resolve(options.cwd, options.dir);
516
+ const destDir = path4.resolve(options.cwd, options.dir);
474
517
  console.log(`\u5B89\u88C5\u76EE\u6807\u76EE\u5F55\uFF1A${destDir}`);
475
518
  const anyWritten = await writeSkillFilesToDir(destDir, skillFiles, options.force);
476
519
  if (anyWritten) installedEntries.push({ target: "custom", cwd: "", dir: destDir });
@@ -1403,19 +1446,19 @@ async function runTransferList(opts) {
1403
1446
  }
1404
1447
 
1405
1448
  // src/commands/invoice.ts
1406
- import * as fs4 from "fs";
1407
- import * as path4 from "path";
1449
+ import * as fs5 from "fs";
1450
+ import * as path5 from "path";
1408
1451
  import * as os3 from "os";
1409
1452
  async function ensureDataPermission(config) {
1410
1453
  if (config.dataPermission) return config;
1411
1454
  if (!config.mainApiUrl) return config;
1412
1455
  const dp = await fetchDataPermission(config.mainApiUrl, config.authToken);
1413
1456
  if (!dp) return config;
1414
- const configPath = path4.join(os3.homedir(), ".siluzan", "config.json");
1457
+ const configPath = path5.join(os3.homedir(), ".siluzan", "config.json");
1415
1458
  try {
1416
- const raw = fs4.existsSync(configPath) ? JSON.parse(fs4.readFileSync(configPath, "utf8")) : {};
1459
+ const raw = fs5.existsSync(configPath) ? JSON.parse(fs5.readFileSync(configPath, "utf8")) : {};
1417
1460
  raw.dataPermission = dp;
1418
- fs4.writeFileSync(configPath, JSON.stringify(raw, null, 2), "utf8");
1461
+ fs5.writeFileSync(configPath, JSON.stringify(raw, null, 2), "utf8");
1419
1462
  } catch {
1420
1463
  }
1421
1464
  return { ...config, dataPermission: dp };
@@ -3123,7 +3166,7 @@ async function runOptimizeChildren(opts) {
3123
3166
 
3124
3167
  // src/commands/forewarning.ts
3125
3168
  import os4 from "os";
3126
- import path5 from "path";
3169
+ import path6 from "path";
3127
3170
  import QRCode from "qrcode";
3128
3171
  import open from "open";
3129
3172
  var VALID_MEDIA_TYPES7 = ["Google", "TikTok"];
@@ -3330,7 +3373,7 @@ async function runForewarningNotifyAccounts(opts) {
3330
3373
  console.log(" \u901A\u77E5\u6E20\u9053\uFF1A\u4E1D\u8DEF\u8D5E\u5E73\u53F0\u5FAE\u4FE1\u670D\u52A1\u53F7\uFF08\u9700\u626B\u7801\u5173\u6CE8\u540E\u624D\u80FD\u6536\u5230\u9884\u8B66\u901A\u77E5\uFF09\n");
3331
3374
  if (qrLink) {
3332
3375
  try {
3333
- const imgPath = path5.join(os4.tmpdir(), "siluzan-wechat-qr.png");
3376
+ const imgPath = path6.join(os4.tmpdir(), "siluzan-wechat-qr.png");
3334
3377
  await QRCode.toFile(imgPath, qrLink, { width: 300 });
3335
3378
  await open(imgPath);
3336
3379
  console.log(` \u{1F4F7} \u4E8C\u7EF4\u7801\u5DF2\u5728\u6D4F\u89C8\u5668\u4E2D\u6253\u5F00\uFF0C\u8BF7\u7528\u624B\u673A\u5FAE\u4FE1\u626B\u7801\u5173\u6CE8"\u4E1D\u8DEF\u8D5E\u5E73\u53F0"\u670D\u52A1\u53F7
@@ -5929,8 +5972,8 @@ async function runAccountBmBind(opts) {
5929
5972
  }
5930
5973
 
5931
5974
  // src/commands/open-account.ts
5932
- import * as fs5 from "fs";
5933
- import * as path6 from "path";
5975
+ import * as fs6 from "fs";
5976
+ import * as path7 from "path";
5934
5977
  import * as readline from "readline/promises";
5935
5978
  import { stdin as stdinStream, stdout as stdoutStream } from "process";
5936
5979
  async function runListAdvertiserGroups(opts) {
@@ -6179,8 +6222,8 @@ async function runOpenAccountYandex(opts) {
6179
6222
  }
6180
6223
  }
6181
6224
  async function uploadAttachment(filePath, apiBaseUrl, config, verbose) {
6182
- const fileName = path6.basename(filePath);
6183
- const fileBuffer = fs5.readFileSync(filePath);
6225
+ const fileName = path7.basename(filePath);
6226
+ const fileBuffer = fs6.readFileSync(filePath);
6184
6227
  const mimeType = guessContentType(fileName);
6185
6228
  const form = new FormData();
6186
6229
  form.append("file", new Blob([fileBuffer], { type: mimeType }), fileName);
@@ -6206,7 +6249,7 @@ async function uploadAttachment(filePath, apiBaseUrl, config, verbose) {
6206
6249
  return { id: data.id, fileName };
6207
6250
  }
6208
6251
  function guessContentType(fileName) {
6209
- const ext = path6.extname(fileName).toLowerCase();
6252
+ const ext = path7.extname(fileName).toLowerCase();
6210
6253
  const map = {
6211
6254
  ".jpg": "image/jpeg",
6212
6255
  ".jpeg": "image/jpeg",
@@ -6219,7 +6262,7 @@ function guessContentType(fileName) {
6219
6262
  }
6220
6263
  async function runOpenAccountBing(opts) {
6221
6264
  const config = loadConfig(opts.token);
6222
- if (!fs5.existsSync(opts.licenseFile)) {
6265
+ if (!fs6.existsSync(opts.licenseFile)) {
6223
6266
  console.error(`
6224
6267
  \u274C \u8425\u4E1A\u6267\u7167\u6587\u4EF6\u4E0D\u5B58\u5728\uFF1A${opts.licenseFile}
6225
6268
  `);
@@ -6294,9 +6337,9 @@ async function runOpenAccountBing(opts) {
6294
6337
  }
6295
6338
  }
6296
6339
  async function uploadToKwai(filePath, apiBaseUrl, config, verbose) {
6297
- const ext = path6.extname(filePath).toLowerCase().replace(".", "").replace("jpg", "jpeg");
6340
+ const ext = path7.extname(filePath).toLowerCase().replace(".", "").replace("jpg", "jpeg");
6298
6341
  const imageType = ext || "jpeg";
6299
- const fileBuffer = fs5.readFileSync(filePath);
6342
+ const fileBuffer = fs6.readFileSync(filePath);
6300
6343
  const base64Image = fileBuffer.toString("base64");
6301
6344
  const res = await apiFetch2(
6302
6345
  `${apiBaseUrl}/KwaiAccount/Management/Upload`,
@@ -6315,7 +6358,7 @@ async function uploadToKwai(filePath, apiBaseUrl, config, verbose) {
6315
6358
  }
6316
6359
  async function runOpenAccountKwai(opts) {
6317
6360
  const config = loadConfig(opts.token);
6318
- if (!fs5.existsSync(opts.licenseFile)) {
6361
+ if (!fs6.existsSync(opts.licenseFile)) {
6319
6362
  console.error(`
6320
6363
  \u274C \u8425\u4E1A\u6267\u7167\u6587\u4EF6\u4E0D\u5B58\u5728\uFF1A${opts.licenseFile}
6321
6364
  `);
@@ -6631,8 +6674,8 @@ async function runOpenAccountGoogle(opts) {
6631
6674
  }
6632
6675
  }
6633
6676
  async function uploadLicenseToTikTok(filePath, businessCentreType, config, verbose) {
6634
- const fileName = path6.basename(filePath);
6635
- const fileBuffer = fs5.readFileSync(filePath);
6677
+ const fileName = path7.basename(filePath);
6678
+ const fileBuffer = fs6.readFileSync(filePath);
6636
6679
  const base64Image = fileBuffer.toString("base64");
6637
6680
  const res = await apiFetch2(
6638
6681
  `${config.apiBaseUrl}/command/media-account/tiktok/Upload`,
@@ -6675,7 +6718,7 @@ async function checkUnionpayRequired(licenseNo, company, businessCentreType, con
6675
6718
  async function runOpenAccountTikTok(opts) {
6676
6719
  const config = loadConfig(opts.token);
6677
6720
  const bcType = opts.businessCentreType ?? "Shop";
6678
- if (!fs5.existsSync(opts.licenseFile)) {
6721
+ if (!fs6.existsSync(opts.licenseFile)) {
6679
6722
  console.error(`
6680
6723
  \u274C \u8425\u4E1A\u6267\u7167\u6587\u4EF6\u4E0D\u5B58\u5728\uFF1A${opts.licenseFile}
6681
6724
  `);
@@ -7038,54 +7081,30 @@ async function runLogin(opts = {}) {
7038
7081
  }
7039
7082
 
7040
7083
  // src/utils/version.ts
7041
- import * as fs6 from "fs";
7042
- import * as path7 from "path";
7084
+ import * as fs7 from "fs";
7085
+ import * as path8 from "path";
7043
7086
  import * as os5 from "os";
7044
- import { fileURLToPath as fileURLToPath2 } from "url";
7045
- var CONFIG_FILE2 = path7.join(os5.homedir(), ".siluzan", "config.json");
7046
7087
  var PKG_NAME = "siluzan-tso-cli";
7047
- function getCurrentVersion() {
7048
- try {
7049
- const __dirname2 = path7.dirname(fileURLToPath2(import.meta.url));
7050
- const pkgPath = path7.join(__dirname2, "..", "..", "package.json");
7051
- const pkg = JSON.parse(fs6.readFileSync(pkgPath, "utf8"));
7052
- return pkg.version ?? "0.0.0";
7053
- } catch {
7054
- return "0.0.0";
7055
- }
7088
+ var CONFIG_FILE2 = path8.join(os5.homedir(), ".siluzan", "config.json");
7089
+ function getCurrentVersion2() {
7090
+ return getCurrentVersion(import.meta.url);
7056
7091
  }
7057
7092
  function isBetaVersion(version) {
7058
7093
  return version.includes("-beta");
7059
7094
  }
7060
- function isNewer(a, b) {
7061
- const parse = (v) => {
7062
- const [base, pre] = v.replace(/^v/, "").split("-beta.");
7063
- const nums = base.split(".").map(Number);
7064
- nums.push(pre !== void 0 ? Number(pre) : Infinity);
7065
- return nums;
7066
- };
7067
- const av = parse(a);
7068
- const bv = parse(b);
7069
- for (let i = 0; i < Math.max(av.length, bv.length); i++) {
7070
- const ai = av[i] ?? 0;
7071
- const bi = bv[i] ?? 0;
7072
- if (bi !== ai) return bi > ai;
7073
- }
7074
- return false;
7075
- }
7076
7095
  function readConfigRaw() {
7077
7096
  try {
7078
- return JSON.parse(fs6.readFileSync(CONFIG_FILE2, "utf8"));
7097
+ return JSON.parse(fs7.readFileSync(CONFIG_FILE2, "utf8"));
7079
7098
  } catch {
7080
7099
  return {};
7081
7100
  }
7082
7101
  }
7083
7102
  function writeConfigRaw(data) {
7084
7103
  try {
7085
- fs6.mkdirSync(path7.dirname(CONFIG_FILE2), { recursive: true });
7086
- fs6.writeFileSync(CONFIG_FILE2, JSON.stringify(data, null, 2), "utf8");
7104
+ fs7.mkdirSync(path8.dirname(CONFIG_FILE2), { recursive: true });
7105
+ fs7.writeFileSync(CONFIG_FILE2, JSON.stringify(data, null, 2), "utf8");
7087
7106
  if (process.platform !== "win32") {
7088
- fs6.chmodSync(CONFIG_FILE2, 384);
7107
+ fs7.chmodSync(CONFIG_FILE2, 384);
7089
7108
  }
7090
7109
  } catch {
7091
7110
  }
@@ -7099,22 +7118,11 @@ async function fetchVersionByTag(tag, cfg) {
7099
7118
  return cfg[cacheKey];
7100
7119
  }
7101
7120
  }
7102
- try {
7103
- const url = `https://registry.npmjs.org/${PKG_NAME}/${tag}`;
7104
- const controller = new AbortController();
7105
- const timer = setTimeout(() => controller.abort(), 4e3);
7106
- const res = await fetch(url, { signal: controller.signal });
7107
- clearTimeout(timer);
7108
- if (!res.ok) return null;
7109
- const data = await res.json();
7110
- return data.version ?? null;
7111
- } catch {
7112
- return null;
7113
- }
7121
+ return fetchNpmVersion(PKG_NAME, tag);
7114
7122
  }
7115
7123
  async function notifyIfOutdated() {
7116
7124
  try {
7117
- const current = getCurrentVersion();
7125
+ const current = getCurrentVersion2();
7118
7126
  const isBeta = isBetaVersion(current);
7119
7127
  const tag = isBeta ? "beta" : "latest";
7120
7128
  const cfg = readConfigRaw();
@@ -7142,9 +7150,9 @@ async function notifyIfOutdated() {
7142
7150
  // src/index.ts
7143
7151
  function getVersion() {
7144
7152
  try {
7145
- const __dirname2 = path8.dirname(fileURLToPath3(import.meta.url));
7146
- const pkgPath = path8.join(__dirname2, "..", "package.json");
7147
- const pkg = JSON.parse(fs7.readFileSync(pkgPath, "utf8"));
7153
+ const __dirname2 = path9.dirname(fileURLToPath3(import.meta.url));
7154
+ const pkgPath = path9.join(__dirname2, "..", "package.json");
7155
+ const pkg = JSON.parse(fs8.readFileSync(pkgPath, "utf8"));
7148
7156
  return pkg.version ?? "0.0.0";
7149
7157
  } catch {
7150
7158
  return "0.0.0";
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "slug": "siluzan-tso",
3
- "version": "1.0.0-beta.19",
4
- "publishedAt": 1774403927434
3
+ "version": "1.0.0-beta.20",
4
+ "publishedAt": 1774406904337
5
5
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "siluzan-tso-cli",
3
- "version": "1.0.0-beta.19",
3
+ "version": "1.0.0-beta.20",
4
4
  "description": "Siluzan 广告账户管理 CLI — 查询账户、余额、消耗数据,管理绑定关系与充值。",
5
5
  "type": "module",
6
6
  "bin": {