ai-world-sdk 1.2.3 → 1.2.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/dist/config.d.ts +4 -3
- package/dist/config.js +58 -11
- package/dist/login.d.ts +1 -0
- package/dist/login.js +23 -14
- package/package.json +1 -1
package/dist/config.d.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*
|
|
10
10
|
* 注意: {VERSION} 占位符会在构建时被替换为实际版本号
|
|
11
11
|
*/
|
|
12
|
-
export declare const SDK_SIGNATURE = "AI_WORLD_SDK_V:1.2.
|
|
12
|
+
export declare const SDK_SIGNATURE = "AI_WORLD_SDK_V:1.2.5";
|
|
13
13
|
/**
|
|
14
14
|
* 版本兼容性错误
|
|
15
15
|
*/
|
|
@@ -34,8 +34,8 @@ declare class SDKConfig {
|
|
|
34
34
|
private _authenticated;
|
|
35
35
|
private _authCheckPromise;
|
|
36
36
|
private _currentUser;
|
|
37
|
-
readonly sdkSignature = "AI_WORLD_SDK_V:1.2.
|
|
38
|
-
readonly sdkVersion = "1.2.
|
|
37
|
+
readonly sdkSignature = "AI_WORLD_SDK_V:1.2.5";
|
|
38
|
+
readonly sdkVersion = "1.2.5";
|
|
39
39
|
constructor();
|
|
40
40
|
/**
|
|
41
41
|
* Set global base URL
|
|
@@ -92,6 +92,7 @@ declare class SDKConfig {
|
|
|
92
92
|
*/
|
|
93
93
|
checkAuthentication(): Promise<boolean>;
|
|
94
94
|
private _performAuthCheck;
|
|
95
|
+
private _nodeAuthCheck;
|
|
95
96
|
/**
|
|
96
97
|
* 获取当前登录状态
|
|
97
98
|
*/
|
package/dist/config.js
CHANGED
|
@@ -7,7 +7,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
7
7
|
exports.sdkConfig = exports.VersionCompatibilityError = exports.SDK_SIGNATURE = void 0;
|
|
8
8
|
// SDK 版本号(构建时自动从 package.json 更新)
|
|
9
9
|
// 此版本号会在运行 npm run build 时自动从 package.json 读取并更新
|
|
10
|
-
const SDK_VERSION = "1.2.
|
|
10
|
+
const SDK_VERSION = "1.2.5";
|
|
11
11
|
/**
|
|
12
12
|
* SDK 特征码 - 用于在构建后的 JS 文件中识别 SDK 版本
|
|
13
13
|
* 格式: AI_WORLD_SDK_V:版本号
|
|
@@ -15,7 +15,7 @@ const SDK_VERSION = "1.2.3";
|
|
|
15
15
|
*
|
|
16
16
|
* 注意: {VERSION} 占位符会在构建时被替换为实际版本号
|
|
17
17
|
*/
|
|
18
|
-
exports.SDK_SIGNATURE = "AI_WORLD_SDK_V:1.2.
|
|
18
|
+
exports.SDK_SIGNATURE = "AI_WORLD_SDK_V:1.2.5";
|
|
19
19
|
/**
|
|
20
20
|
* 版本兼容性错误
|
|
21
21
|
*/
|
|
@@ -225,15 +225,29 @@ class SDKConfig {
|
|
|
225
225
|
return false;
|
|
226
226
|
}
|
|
227
227
|
try {
|
|
228
|
-
const
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
228
|
+
const isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined';
|
|
229
|
+
let ok = false;
|
|
230
|
+
let user = null;
|
|
231
|
+
if (isBrowser) {
|
|
232
|
+
const response = await fetch(`${baseUrl}/api/auth/me`, {
|
|
233
|
+
method: 'GET',
|
|
234
|
+
headers: {
|
|
235
|
+
'Authorization': `Bearer ${this._token}`,
|
|
236
|
+
'Content-Type': 'application/json',
|
|
237
|
+
},
|
|
238
|
+
});
|
|
239
|
+
if (response.ok) {
|
|
240
|
+
user = await response.json();
|
|
241
|
+
ok = true;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
// Node.js 环境:使用 https/http 模块,支持自签名证书
|
|
246
|
+
const result = await this._nodeAuthCheck(baseUrl, this._token);
|
|
247
|
+
ok = result.ok;
|
|
248
|
+
user = result.user;
|
|
249
|
+
}
|
|
250
|
+
if (ok && user) {
|
|
237
251
|
this._authenticated = true;
|
|
238
252
|
this._currentUser = user;
|
|
239
253
|
if (this._debug) {
|
|
@@ -251,6 +265,39 @@ class SDKConfig {
|
|
|
251
265
|
return false;
|
|
252
266
|
}
|
|
253
267
|
}
|
|
268
|
+
_nodeAuthCheck(baseUrl, token) {
|
|
269
|
+
return new Promise((resolve) => {
|
|
270
|
+
try {
|
|
271
|
+
const url = new URL(`${baseUrl}/api/auth/me`);
|
|
272
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
273
|
+
const mod = url.protocol === 'https:' ? require('https') : require('http');
|
|
274
|
+
const req = mod.get(url.href, {
|
|
275
|
+
headers: { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json' },
|
|
276
|
+
rejectUnauthorized: false,
|
|
277
|
+
}, (res) => {
|
|
278
|
+
let body = '';
|
|
279
|
+
res.on('data', (chunk) => { body += chunk; });
|
|
280
|
+
res.on('end', () => {
|
|
281
|
+
if (res.statusCode >= 200 && res.statusCode < 300) {
|
|
282
|
+
try {
|
|
283
|
+
resolve({ ok: true, user: JSON.parse(body) });
|
|
284
|
+
}
|
|
285
|
+
catch {
|
|
286
|
+
resolve({ ok: true, user: null });
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
else {
|
|
290
|
+
resolve({ ok: false, user: null });
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
});
|
|
294
|
+
req.on('error', () => resolve({ ok: false, user: null }));
|
|
295
|
+
}
|
|
296
|
+
catch {
|
|
297
|
+
resolve({ ok: false, user: null });
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
}
|
|
254
301
|
/**
|
|
255
302
|
* 获取当前登录状态
|
|
256
303
|
*/
|
package/dist/login.d.ts
CHANGED
package/dist/login.js
CHANGED
|
@@ -43,6 +43,7 @@ exports.readEnvLocal = readEnvLocal;
|
|
|
43
43
|
exports.writeEnvLocal = writeEnvLocal;
|
|
44
44
|
exports.performLogin = performLogin;
|
|
45
45
|
const http = __importStar(require("http"));
|
|
46
|
+
const https = __importStar(require("https"));
|
|
46
47
|
const fs = __importStar(require("fs"));
|
|
47
48
|
const path = __importStar(require("path"));
|
|
48
49
|
const child_process_1 = require("child_process");
|
|
@@ -79,21 +80,29 @@ const LOGIN_TIMEOUT_MS = 60000;
|
|
|
79
80
|
const DEFAULT_BASE_URL = "https://aiworld.local:8000";
|
|
80
81
|
/**
|
|
81
82
|
* 验证 token 是否有效
|
|
83
|
+
* 使用 https/http 模块替代 fetch,以支持自签名证书(rejectUnauthorized: false)
|
|
82
84
|
*/
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
85
|
+
function validateToken(baseUrl, token) {
|
|
86
|
+
return new Promise((resolve) => {
|
|
87
|
+
try {
|
|
88
|
+
const url = new URL(`${baseUrl}/api/auth/me`);
|
|
89
|
+
const mod = url.protocol === "https:" ? https : http;
|
|
90
|
+
const req = mod.get(url.href, {
|
|
91
|
+
headers: {
|
|
92
|
+
Authorization: `Bearer ${token}`,
|
|
93
|
+
"Content-Type": "application/json",
|
|
94
|
+
},
|
|
95
|
+
rejectUnauthorized: false,
|
|
96
|
+
}, (res) => {
|
|
97
|
+
res.resume();
|
|
98
|
+
resolve(res.statusCode !== undefined && res.statusCode >= 200 && res.statusCode < 300);
|
|
99
|
+
});
|
|
100
|
+
req.on("error", () => resolve(false));
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
resolve(false);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
97
106
|
}
|
|
98
107
|
/**
|
|
99
108
|
* 强制确保端口可用:如果被占用则 kill 占用进程
|
package/package.json
CHANGED