yuanflow-cli 0.1.3 → 0.1.5

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/src/request.js CHANGED
@@ -5,16 +5,12 @@ import { findEndpointByPath, normalizeSocialPath } from './registry.js';
5
5
  export async function callEndpoint(socialPath, options = {}) {
6
6
  const config = await readConfig();
7
7
  const baseUrl = cleanBaseUrl(options.baseUrl || config.baseUrl);
8
- const token = options.token || config.token || process.env.YUANFLOW_TOKEN || '';
8
+ const token = options.token || process.env.YUANCHUANG_API_TOKEN || config.token || '';
9
9
  const normalizedPath = normalizeSocialPath(socialPath);
10
10
  const endpoint = findEndpointByPath(normalizedPath);
11
11
  const method = options.method || endpoint?.method || 'POST';
12
12
  const url = new URL(`/social${normalizedPath}`, baseUrl);
13
13
 
14
- if (!token) {
15
- throw new Error('缺少 token。请先执行 yuanflow-cli config set-token <你的令牌>');
16
- }
17
-
18
14
  const body = await resolveBody(options);
19
15
  if (method.toUpperCase() === 'GET' && body && typeof body === 'object') {
20
16
  for (const [key, value] of Object.entries(body)) {
@@ -30,12 +26,16 @@ export async function callEndpoint(socialPath, options = {}) {
30
26
  method: method.toUpperCase(),
31
27
  url: url.toString(),
32
28
  headers: {
33
- Authorization: `Bearer ${maskToken(token)}`,
29
+ ...(token ? { Authorization: `Bearer ${maskToken(token)}` } : {}),
34
30
  },
35
31
  body: method.toUpperCase() === 'GET' ? undefined : body || {},
36
32
  };
37
33
  }
38
34
 
35
+ if (!token) {
36
+ throw new Error('缺少 token。请设置 YUANCHUANG_API_TOKEN,或执行 yuanflow-cli config set-token <你的令牌>');
37
+ }
38
+
39
39
  const response = await fetch(url, {
40
40
  method: method.toUpperCase(),
41
41
  headers: {