siluzan-tso-cli 1.1.30-beta.2 → 1.1.30-beta.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
@@ -51,7 +51,7 @@ siluzan-tso init -d /path/to/skills # 写入自定义目录
51
51
  siluzan-tso init --force # 强制覆盖已存在文件
52
52
  ```
53
53
 
54
- > **注意**:当前为测试版(1.1.30-beta.2),供内部测试使用。正式发布后安装命令将改为 `npm install -g siluzan-tso-cli`。
54
+ > **注意**:当前为测试版(1.1.30-beta.3),供内部测试使用。正式发布后安装命令将改为 `npm install -g siluzan-tso-cli`。
55
55
 
56
56
  | 助手 | 建议 `--ai` |
57
57
  | ----------------------- | ------------------------------------ |
package/dist/index.js CHANGED
@@ -2119,6 +2119,62 @@ function validateBaseUrl(raw) {
2119
2119
  }
2120
2120
  return null;
2121
2121
  }
2122
+ function hasSiluzanAgentCredentials() {
2123
+ const apiKey = process.env.SILUZAN_API_KEY?.trim();
2124
+ const authToken = process.env.SILUZAN_AUTH_TOKEN?.trim();
2125
+ return Boolean(apiKey || authToken);
2126
+ }
2127
+ function isSiluzanAgentEnv() {
2128
+ const raw = process.env.IS_SILUZAN_AGENT_ENV?.trim().toLowerCase();
2129
+ return raw === "true" || raw === "1";
2130
+ }
2131
+ function skipAuthSetupInAgentEnv(commandLabel) {
2132
+ if (!isSiluzanAgentEnv()) return false;
2133
+ if (hasSiluzanAgentCredentials()) {
2134
+ console.log(
2135
+ `
2136
+ \u2139\uFE0F \u68C0\u6D4B\u5230 Siluzan Agent \u73AF\u5883\uFF08IS_SILUZAN_AGENT_ENV=true\uFF09\uFF0C\u51ED\u636E\u5DF2\u7531\u6C99\u7BB1\u6CE8\u5165\uFF0C\u65E0\u9700\u6267\u884C ${commandLabel}\u3002
2137
+ `
2138
+ );
2139
+ } else {
2140
+ console.log(
2141
+ `
2142
+ \u2139\uFE0F \u68C0\u6D4B\u5230 Siluzan Agent \u73AF\u5883\uFF08IS_SILUZAN_AGENT_ENV=true\uFF09\u3002
2143
+ ${commandLabel} \u5DF2\u8DF3\u8FC7\uFF1B\u8BF7\u7531 Agent \u6C99\u7BB1\u6CE8\u5165 SILUZAN_API_KEY \u6216 SILUZAN_AUTH_TOKEN\u3002
2144
+ `
2145
+ );
2146
+ }
2147
+ return true;
2148
+ }
2149
+ function trimOrUndefined(value) {
2150
+ const trimmed = value?.trim();
2151
+ return trimmed ? trimmed : void 0;
2152
+ }
2153
+ function resolveAgentEnvCredentials() {
2154
+ const envToken = trimOrUndefined(process.env.SILUZAN_AUTH_TOKEN);
2155
+ if (envToken) return { authToken: envToken, apiKey: void 0 };
2156
+ const envApiKey = trimOrUndefined(process.env.SILUZAN_API_KEY);
2157
+ if (envApiKey) return { authToken: "", apiKey: envApiKey };
2158
+ return { authToken: "", apiKey: void 0 };
2159
+ }
2160
+ function resolveSiluzanCredentials(opts) {
2161
+ if (isSiluzanAgentEnv()) {
2162
+ return resolveAgentEnvCredentials();
2163
+ }
2164
+ const apiKey = trimOrUndefined(process.env.SILUZAN_API_KEY) ?? trimOrUndefined(opts.configApiKey);
2165
+ const authToken = trimOrUndefined(opts.tokenArg) ?? trimOrUndefined(process.env.SILUZAN_AUTH_TOKEN) ?? trimOrUndefined(opts.configAuthToken) ?? "";
2166
+ return { authToken, apiKey };
2167
+ }
2168
+ function resolveRequestAuth(config) {
2169
+ if (isSiluzanAgentEnv()) {
2170
+ return resolveAgentEnvCredentials();
2171
+ }
2172
+ return { authToken: config.authToken, apiKey: config.apiKey };
2173
+ }
2174
+ function buildSiluzanAuthHeaders(config) {
2175
+ const auth = resolveRequestAuth(config);
2176
+ return auth.apiKey ? { "x-api-key": auth.apiKey } : { Authorization: `Bearer ${auth.authToken}` };
2177
+ }
2122
2178
  function isPerfEnabled() {
2123
2179
  const v = process.env.SILUZAN_HTTP_PERF;
2124
2180
  return v === "1" || v === "true";
@@ -2264,15 +2320,17 @@ function redactSensitive(input) {
2264
2320
  );
2265
2321
  return output;
2266
2322
  }
2323
+ function buildAuthHeaders(config) {
2324
+ return buildSiluzanAuthHeaders(config);
2325
+ }
2267
2326
  async function apiFetch(url, config, options = {}, verbose = false) {
2268
2327
  const method = options.method ?? "GET";
2269
- const authHeaders2 = config.apiKey ? { "x-api-key": config.apiKey } : { Authorization: `Bearer ${config.authToken}` };
2270
2328
  const reqHeaders = {
2271
2329
  "Content-Type": "application/json",
2272
2330
  "Accept-Language": "zh-CN",
2273
2331
  // 声明支持 gzip/deflate/br;服务端不支持则按 identity 返回,rawRequest 会原样收取
2274
2332
  "Accept-Encoding": "gzip, deflate, br",
2275
- ...authHeaders2,
2333
+ ...buildAuthHeaders(config),
2276
2334
  // dataPermission 仅 TSO 使用;CSO 未设置时为空字符串,服务端忽略该头
2277
2335
  Datapermission: config.dataPermission ?? "",
2278
2336
  ...options.headers ?? {}
@@ -2300,12 +2358,11 @@ async function apiFetch(url, config, options = {}, verbose = false) {
2300
2358
  }
2301
2359
  async function apiFetchWithHeaders(url, config, options = {}, verbose = false) {
2302
2360
  const method = options.method ?? "GET";
2303
- const authHeaders2 = config.apiKey ? { "x-api-key": config.apiKey } : { Authorization: `Bearer ${config.authToken}` };
2304
2361
  const reqHeaders = {
2305
2362
  "Content-Type": "application/json",
2306
2363
  "Accept-Language": "zh-CN",
2307
2364
  "Accept-Encoding": "gzip, deflate, br",
2308
- ...authHeaders2,
2365
+ ...buildAuthHeaders(config),
2309
2366
  Datapermission: config.dataPermission ?? "",
2310
2367
  ...options.headers ?? {}
2311
2368
  };
@@ -2820,33 +2877,6 @@ function installProcessHandlers() {
2820
2877
  process.exit(1);
2821
2878
  });
2822
2879
  }
2823
- function hasSiluzanAgentCredentials() {
2824
- const apiKey = process.env.SILUZAN_API_KEY?.trim();
2825
- const authToken = process.env.SILUZAN_AUTH_TOKEN?.trim();
2826
- return Boolean(apiKey || authToken);
2827
- }
2828
- function isSiluzanAgentEnv() {
2829
- const raw = process.env.IS_SILUZAN_AGENT_ENV?.trim().toLowerCase();
2830
- return raw === "true" || raw === "1";
2831
- }
2832
- function skipAuthSetupInAgentEnv(commandLabel) {
2833
- if (!isSiluzanAgentEnv()) return false;
2834
- if (hasSiluzanAgentCredentials()) {
2835
- console.log(
2836
- `
2837
- \u2139\uFE0F \u68C0\u6D4B\u5230 Siluzan Agent \u73AF\u5883\uFF08IS_SILUZAN_AGENT_ENV=true\uFF09\uFF0C\u51ED\u636E\u5DF2\u7531\u6C99\u7BB1\u6CE8\u5165\uFF0C\u65E0\u9700\u6267\u884C ${commandLabel}\u3002
2838
- `
2839
- );
2840
- } else {
2841
- console.log(
2842
- `
2843
- \u2139\uFE0F \u68C0\u6D4B\u5230 Siluzan Agent \u73AF\u5883\uFF08IS_SILUZAN_AGENT_ENV=true\uFF09\u3002
2844
- ${commandLabel} \u5DF2\u8DF3\u8FC7\uFF1B\u8BF7\u7531 Agent \u6C99\u7BB1\u6CE8\u5165 SILUZAN_API_KEY \u6216 SILUZAN_AUTH_TOKEN\u3002
2845
- `
2846
- );
2847
- }
2848
- return true;
2849
- }
2850
2880
  function printAuthMissingHelp(binName) {
2851
2881
  if (isSiluzanAgentEnv()) {
2852
2882
  console.error(
@@ -2923,7 +2953,7 @@ function parseMeResponse(text) {
2923
2953
  async function fetchSiluzanCurrentUser(apiBase, config) {
2924
2954
  const mainOrigin = deriveMainApiOrigin(apiBase);
2925
2955
  const meUrl = `${mainOrigin.replace(/\/$/, "")}/query/account/me`;
2926
- const authHeaders2 = config.apiKey ? { "x-api-key": config.apiKey } : { Authorization: `Bearer ${config.authToken}` };
2956
+ const authHeaders2 = buildSiluzanAuthHeaders(config);
2927
2957
  try {
2928
2958
  const res = await rawRequest(meUrl, {
2929
2959
  method: "GET",
@@ -3704,7 +3734,7 @@ async function fetchDataPermission(mainApiUrl, auth) {
3704
3734
  const headers = {
3705
3735
  "Content-Type": "application/json",
3706
3736
  "Accept-Language": "zh-CN",
3707
- ...auth.apiKey ? { "x-api-key": auth.apiKey } : { Authorization: `Bearer ${auth.authToken}` }
3737
+ ...buildSiluzanAuthHeaders(auth)
3708
3738
  };
3709
3739
  try {
3710
3740
  const res = await fetch(url, { headers });
@@ -3985,7 +4015,7 @@ async function apiDeleteRaw(url, config, options = {}) {
3985
4015
  "Content-Type": "application/json; charset=utf-8",
3986
4016
  Accept: "application/json, text/plain, */*",
3987
4017
  "Accept-Language": "zh-CN",
3988
- ...config.apiKey ? { "x-api-key": config.apiKey } : { Authorization: `Bearer ${config.authToken}` },
4018
+ ...buildSiluzanAuthHeaders(config),
3989
4019
  Datapermission: config.dataPermission ?? "",
3990
4020
  "Content-Length": String(Buffer.byteLength(bodyStr, "utf8"))
3991
4021
  };
@@ -4024,8 +4054,11 @@ var init_fetch_wrapper = __esm({
4024
4054
  // src/utils/auth.ts
4025
4055
  function loadConfig(tokenArg) {
4026
4056
  const shared = readSharedConfig();
4027
- const apiKey = process.env.SILUZAN_API_KEY ?? (shared.apiKey ? shared.apiKey : void 0);
4028
- const authToken = tokenArg ?? process.env.SILUZAN_AUTH_TOKEN ?? shared.authToken ?? "";
4057
+ const { authToken, apiKey } = resolveSiluzanCredentials({
4058
+ tokenArg,
4059
+ configApiKey: shared.apiKey,
4060
+ configAuthToken: shared.authToken
4061
+ });
4029
4062
  if (!apiKey && !authToken) {
4030
4063
  printAuthMissingHelp("siluzan-tso");
4031
4064
  }
@@ -103381,10 +103414,13 @@ function buildTsoPageWebUrl(webUrl, tsoSubRoute, extraQuery) {
103381
103414
  }
103382
103415
  function cmdConfigShow() {
103383
103416
  const shared = readSharedConfig();
103417
+ const { authToken: effectiveAuthToken, apiKey: effectiveApiKeyRaw } = resolveSiluzanCredentials({
103418
+ configApiKey: shared.apiKey,
103419
+ configAuthToken: shared.authToken
103420
+ });
103421
+ const effectiveApiKey = effectiveApiKeyRaw ?? "";
103384
103422
  const envApiKey = process.env.SILUZAN_API_KEY;
103385
103423
  const envAuthToken = process.env.SILUZAN_AUTH_TOKEN;
103386
- const effectiveApiKey = envApiKey ?? shared.apiKey ?? "";
103387
- const effectiveAuthToken = envAuthToken ?? shared.authToken ?? "";
103388
103424
  const apiBaseUrl = process.env.SILUZAN_TSO_API_BASE ?? DEFAULT_API_BASE;
103389
103425
  const googleApiUrl = process.env.SILUZAN_GOOGLE_API ?? deriveGoogleApiUrl(apiBaseUrl);
103390
103426
  const webUrl = deriveWebUrl(apiBaseUrl);
@@ -103408,12 +103444,12 @@ function cmdConfigShow() {
103408
103444
  console.log(` googleApiUrl : ${googleApiUrl}`);
103409
103445
  console.log(` webUrl : ${webUrl}`);
103410
103446
  if (effectiveApiKey) {
103411
- const src = envApiKey ? "env:SILUZAN_API_KEY" : "config.json";
103447
+ const src = isSiluzanAgentEnv() ? "env:SILUZAN_API_KEY (agent)" : envApiKey ? "env:SILUZAN_API_KEY" : "config.json";
103412
103448
  const active = " \u2190 \u5F53\u524D\u751F\u6548\uFF08X-Api-Key \u9274\u6743\uFF09";
103413
103449
  console.log(` apiKey : ${maskSecret(effectiveApiKey)} [${src}]${active}`);
103414
103450
  }
103415
103451
  if (effectiveAuthToken) {
103416
- const src = envAuthToken ? "env:SILUZAN_AUTH_TOKEN" : "config.json";
103452
+ const src = isSiluzanAgentEnv() ? "env:SILUZAN_AUTH_TOKEN (agent)" : envAuthToken ? "env:SILUZAN_AUTH_TOKEN" : "config.json";
103417
103453
  const note = effectiveApiKey ? " \uFF08\u5DF2\u88AB apiKey \u8986\u76D6\uFF09" : " \u2190 \u5F53\u524D\u751F\u6548\uFF08Bearer \u9274\u6743\uFF09";
103418
103454
  console.log(` authToken : ${maskSecret(effectiveAuthToken)} [${src}]${note}`);
103419
103455
  }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "slug": "siluzan-tso",
3
- "version": "1.1.30-beta.2",
4
- "publishedAt": 1782286975360
3
+ "version": "1.1.30-beta.3",
4
+ "publishedAt": 1782294259539
5
5
  }
@@ -9,7 +9,7 @@ $ErrorActionPreference = 'Stop'
9
9
  # -- Package info (injected at build time) ------------------------------------
10
10
  $PKG_NAME = 'siluzan-tso-cli'
11
11
  # PKG_VERSION 锁定到与本脚本同批构建产物一致的版本,避免与 dist/skill 错位
12
- $PKG_VERSION = '1.1.30-beta.2'
12
+ $PKG_VERSION = '1.1.30-beta.3'
13
13
  $CLI_BIN = 'siluzan-tso'
14
14
  $SKILL_LABEL = 'Siluzan TSO'
15
15
  $INSTALL_CMD = 'npm install -g siluzan-tso-cli@beta'
@@ -9,7 +9,7 @@ set -euo pipefail
9
9
  # -- Package info (injected at build time) ------------------------------------
10
10
  readonly PKG_NAME="siluzan-tso-cli"
11
11
  # PKG_VERSION 锁定到与本脚本同批构建产物一致的版本,避免与 dist/skill 错位
12
- readonly PKG_VERSION="1.1.30-beta.2"
12
+ readonly PKG_VERSION="1.1.30-beta.3"
13
13
  readonly CLI_BIN="siluzan-tso"
14
14
  readonly SKILL_LABEL="Siluzan TSO"
15
15
  readonly INSTALL_CMD="npm install -g siluzan-tso-cli@beta"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "siluzan-tso-cli",
3
- "version": "1.1.30-beta.2",
3
+ "version": "1.1.30-beta.3",
4
4
  "description": "Siluzan 广告账户管理 CLI — 查询账户、余额、消耗数据,管理绑定关系与充值。",
5
5
  "keywords": [
6
6
  "ad-account",