@maiyunnet/kebab 9.25.2 → 9.26.1
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 +254 -203
- package/doc/kebab-rag.md +259 -233
- package/index.d.ts +1 -2
- package/index.js +1 -2
- package/lib/session.d.ts +6 -1
- package/lib/session.js +36 -18
- package/package.json +30 -23
- package/sys/ctr.d.ts +5 -3
- package/sys/ctr.js +11 -6
- package/sys/route.js +0 -1
package/index.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Project: Kebab, User: JianSuoQiYue
|
|
3
3
|
* Date: 2019-3-30 12:46:41
|
|
4
|
-
* Last: 2020-3-8 21:04:24, 2022-07-22 14:20:34, 2023-5-24 01:34:57, 2025-6-13 14:49:27, 2025-10-1 10:11:54, 2026-07-14 17:40:00
|
|
5
4
|
* --- 本文件用来定义每个目录实体地址的常量 ---
|
|
6
5
|
*/
|
|
7
6
|
/** --- 当前系统版本号 --- */
|
|
8
|
-
export declare const VER = "9.
|
|
7
|
+
export declare const VER = "9.26.1";
|
|
9
8
|
/** --- 框架根目录,以 / 结尾 --- */
|
|
10
9
|
export declare const ROOT_PATH: string;
|
|
11
10
|
/** --- 框架的 LIB,以 / 结尾 --- */
|
package/index.js
CHANGED
|
@@ -2,11 +2,10 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Project: Kebab, User: JianSuoQiYue
|
|
4
4
|
* Date: 2019-3-30 12:46:41
|
|
5
|
-
* Last: 2020-3-8 21:04:24, 2022-07-22 14:20:34, 2023-5-24 01:34:57, 2025-6-13 14:49:27, 2025-10-1 10:11:54, 2026-07-14 17:40:00
|
|
6
5
|
* --- 本文件用来定义每个目录实体地址的常量 ---
|
|
7
6
|
*/
|
|
8
7
|
/** --- 当前系统版本号 --- */
|
|
9
|
-
export const VER = '9.
|
|
8
|
+
export const VER = '9.26.1';
|
|
10
9
|
// --- 服务端用的路径 ---
|
|
11
10
|
const imu = decodeURIComponent(import.meta.url).replace('file://', '').replace(/^\/(\w:)/, '$1');
|
|
12
11
|
/** --- /xxx/xxx --- */
|
package/lib/session.d.ts
CHANGED
|
@@ -12,7 +12,12 @@ export interface IOptions {
|
|
|
12
12
|
'ssl'?: boolean;
|
|
13
13
|
'domain'?: string;
|
|
14
14
|
'sqlPre'?: string;
|
|
15
|
+
/** --- 显式指定 Session ID,优先于请求凭据;空字符串表示新建匿名会话 --- */
|
|
15
16
|
'token'?: string;
|
|
17
|
+
/** --- auth 开启时读取的专用头名,值为原始 Session ID;未设置则读取 Authorization / _auth --- */
|
|
18
|
+
'header'?: string;
|
|
19
|
+
/** --- 是否读取和写入 Cookie,默认 true;false 时也不会发送 Set-Cookie --- */
|
|
20
|
+
'cookie'?: boolean;
|
|
16
21
|
}
|
|
17
22
|
export declare class Session {
|
|
18
23
|
/** --- 数据库操作对象 --- */
|
|
@@ -31,7 +36,7 @@ export declare class Session {
|
|
|
31
36
|
* --- 初始化函数,相当于 construct ---
|
|
32
37
|
* @param ctr 模型实例
|
|
33
38
|
* @param link Kv 或 Db 实例
|
|
34
|
-
* @param auth
|
|
39
|
+
* @param auth 开启请求凭据读取,使用 opt.header 或 Authorization / GET、POST 的 _auth;提供无效凭据不回退 Cookie
|
|
35
40
|
* @param opt 选项
|
|
36
41
|
* @returns false 表示系统错误
|
|
37
42
|
*/
|
package/lib/session.js
CHANGED
|
@@ -52,7 +52,7 @@ export class Session {
|
|
|
52
52
|
* --- 初始化函数,相当于 construct ---
|
|
53
53
|
* @param ctr 模型实例
|
|
54
54
|
* @param link Kv 或 Db 实例
|
|
55
|
-
* @param auth
|
|
55
|
+
* @param auth 开启请求凭据读取,使用 opt.header 或 Authorization / GET、POST 的 _auth;提供无效凭据不回退 Cookie
|
|
56
56
|
* @param opt 选项
|
|
57
57
|
* @returns false 表示系统错误
|
|
58
58
|
*/
|
|
@@ -63,22 +63,38 @@ export class Session {
|
|
|
63
63
|
this._ttl = opt.ttl ?? config.session.ttl ?? 172800;
|
|
64
64
|
const tim = lTime.stamp();
|
|
65
65
|
this._ctr = ctr;
|
|
66
|
-
|
|
66
|
+
this._token = '';
|
|
67
|
+
/** --- 用户是否已明确提供了凭据,空值或格式错误也禁止回退 Cookie --- */
|
|
68
|
+
let supplied = false;
|
|
69
|
+
if (opt.token !== undefined) {
|
|
70
|
+
supplied = true;
|
|
67
71
|
this._token = opt.token;
|
|
68
72
|
}
|
|
69
73
|
else if (auth) {
|
|
70
|
-
const
|
|
71
|
-
if (
|
|
72
|
-
|
|
73
|
-
|
|
74
|
+
const headers = ctr.getPrototype('_headers');
|
|
75
|
+
if (opt.header !== undefined) {
|
|
76
|
+
const value = headers[opt.header.toLowerCase()];
|
|
77
|
+
supplied = value !== undefined;
|
|
78
|
+
if (typeof value === 'string') {
|
|
79
|
+
this._token = value.trim();
|
|
80
|
+
}
|
|
74
81
|
}
|
|
75
|
-
else
|
|
76
|
-
|
|
77
|
-
|
|
82
|
+
else {
|
|
83
|
+
supplied = headers['authorization'] !== undefined ||
|
|
84
|
+
ctr.getPrototype('_get')['_auth'] !== undefined ||
|
|
85
|
+
ctr.getPrototype('_post')['_auth'] !== undefined;
|
|
86
|
+
const a = ctr.getAuthorization();
|
|
87
|
+
if (a && a.type === 'bearer') {
|
|
88
|
+
this._token = a.token;
|
|
89
|
+
}
|
|
90
|
+
else if (a && a.type === 'basic' && a.user === 'token') {
|
|
91
|
+
// --- 已有客户端以 Basic 的密码字段传递 Session ID ---
|
|
92
|
+
this._token = a.pwd;
|
|
93
|
+
}
|
|
78
94
|
}
|
|
79
95
|
}
|
|
80
96
|
const cookie = ctr.getPrototype('_cookie');
|
|
81
|
-
if (
|
|
97
|
+
if (opt.cookie !== false && !supplied && cookie[this._name]) {
|
|
82
98
|
this._token = cookie[this._name];
|
|
83
99
|
}
|
|
84
100
|
this._link = link;
|
|
@@ -126,12 +142,12 @@ export class Session {
|
|
|
126
142
|
needInsert = true;
|
|
127
143
|
}
|
|
128
144
|
}
|
|
129
|
-
ctr.setPrototype('_session', session);
|
|
130
145
|
}
|
|
131
146
|
else {
|
|
132
147
|
// --- 全新的机子 ---
|
|
133
148
|
needInsert = true;
|
|
134
149
|
}
|
|
150
|
+
ctr.setPrototype('_session', session);
|
|
135
151
|
// --- 本来就该添加个新 Session ---
|
|
136
152
|
// --- 内存和数据库里没找到的也该添加个新 Session ---
|
|
137
153
|
// --- 数据库的 Session 已经过期加新 Session ---
|
|
@@ -173,13 +189,15 @@ export class Session {
|
|
|
173
189
|
}
|
|
174
190
|
}
|
|
175
191
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
192
|
+
if (opt.cookie !== false) {
|
|
193
|
+
lCore.setCookie(ctr, this._name, this._token, {
|
|
194
|
+
'ttl': this._ttl,
|
|
195
|
+
'domain': opt.domain,
|
|
196
|
+
'ssl': ssl,
|
|
197
|
+
'httponly': true,
|
|
198
|
+
'samesite': 'Lax',
|
|
199
|
+
});
|
|
200
|
+
}
|
|
183
201
|
return true;
|
|
184
202
|
}
|
|
185
203
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maiyunnet/kebab",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.26.1",
|
|
4
4
|
"description": "Simple, easy-to-use, and fully-featured Node.js framework that is ready-to-use out of the box.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"scripts": {
|
|
16
16
|
"build-doc": "bash ./utils/build-doc.sh",
|
|
17
17
|
"test:formdata": "node abox/test/formdata.mjs",
|
|
18
|
+
"test:session": "node abox/test/session.mjs",
|
|
18
19
|
"test:rpc": "node --test --test-isolation=none abox/test/rpc.mjs",
|
|
19
20
|
"test:master": "node --test --test-isolation=none abox/test/master.mjs"
|
|
20
21
|
},
|
|
@@ -25,49 +26,55 @@
|
|
|
25
26
|
"#kebab/*": "./*"
|
|
26
27
|
},
|
|
27
28
|
"dependencies": {
|
|
28
|
-
"@aws-sdk/client-s3": "^3.
|
|
29
|
-
"@aws-sdk/lib-storage": "^3.
|
|
30
|
-
"@litert/http-client": "^1.
|
|
29
|
+
"@aws-sdk/client-s3": "^3.1161.0",
|
|
30
|
+
"@aws-sdk/lib-storage": "^3.1161.0",
|
|
31
|
+
"@litert/http-client": "^1.2.0",
|
|
31
32
|
"@litert/mime": "^2.0.0",
|
|
32
33
|
"@litert/redis": "^3.2.1",
|
|
33
|
-
"@radix-ui/react-checkbox": "^1.
|
|
34
|
-
"@radix-ui/react-label": "^2.1.
|
|
35
|
-
"@radix-ui/react-slot": "^1.
|
|
36
|
-
"@radix-ui/react-switch": "^1.
|
|
37
|
-
"@tailwindcss/cli": "^4.3.
|
|
34
|
+
"@radix-ui/react-checkbox": "^1.4.1",
|
|
35
|
+
"@radix-ui/react-label": "^2.1.17",
|
|
36
|
+
"@radix-ui/react-slot": "^1.5.0",
|
|
37
|
+
"@radix-ui/react-switch": "^1.4.1",
|
|
38
|
+
"@tailwindcss/cli": "^4.3.4",
|
|
38
39
|
"@types/ssh2": "^1.15.6",
|
|
39
40
|
"ajv": "^8.20.0",
|
|
40
|
-
"ajv-formats": "^3.0.1",
|
|
41
|
+
"ajv-formats": "^3.0.1",
|
|
41
42
|
"class-variance-authority": "^0.7.1",
|
|
42
43
|
"clsx": "^2.1.1",
|
|
43
44
|
"ejs": "^6.0.1",
|
|
44
45
|
"esbuild": "^0.28.2",
|
|
45
46
|
"jszip": "^3.10.2",
|
|
46
|
-
"mysql2": "^3.24.
|
|
47
|
+
"mysql2": "^3.24.6",
|
|
47
48
|
"node-cron": "^4.6.0",
|
|
48
|
-
"openai": "^7.
|
|
49
|
-
"pg": "^8.23.
|
|
50
|
-
"react": "^19.3.
|
|
51
|
-
"react-dom": "^19.3.
|
|
52
|
-
"react-router-dom": "^7.18.
|
|
49
|
+
"openai": "^7.47.0",
|
|
50
|
+
"pg": "^8.23.1",
|
|
51
|
+
"react": "^19.3.1",
|
|
52
|
+
"react-dom": "^19.3.1",
|
|
53
|
+
"react-router-dom": "^7.18.5",
|
|
53
54
|
"ssh2": "^1.17.0",
|
|
54
55
|
"svg-captcha": "^1.4.0",
|
|
55
|
-
"tailwind-merge": "^3.
|
|
56
|
-
"tencentcloud-sdk-nodejs": "^4.1.
|
|
57
|
-
"undici": "^8.
|
|
56
|
+
"tailwind-merge": "^3.7.0",
|
|
57
|
+
"tencentcloud-sdk-nodejs": "^4.1.338",
|
|
58
|
+
"undici": "^8.12.3",
|
|
58
59
|
"valibot": "^1.5.0",
|
|
59
|
-
"ws": "^8.
|
|
60
|
+
"ws": "^8.22.1"
|
|
60
61
|
},
|
|
61
62
|
"devDependencies": {
|
|
62
63
|
"@litert/eslint-plugin-rules": "^0.3.1",
|
|
63
64
|
"@types/ejs": "^3.1.5",
|
|
64
|
-
"@types/node": "^26.
|
|
65
|
+
"@types/node": "^26.6.6",
|
|
65
66
|
"@types/pg": "^8.23.1",
|
|
66
67
|
"@types/react": "^19.3.0",
|
|
67
68
|
"@types/react-dom": "^19.3.0",
|
|
68
|
-
"@types/ws": "^8.18.
|
|
69
|
+
"@types/ws": "^8.18.2",
|
|
69
70
|
"typedoc": "^0.28.20",
|
|
70
|
-
"typedoc-plugin-markdown": "^4.
|
|
71
|
+
"typedoc-plugin-markdown": "^4.14.1",
|
|
71
72
|
"typescript": "^6.0.3"
|
|
73
|
+
},
|
|
74
|
+
"allowScripts": {
|
|
75
|
+
"esbuild": true,
|
|
76
|
+
"@parcel/watcher": true,
|
|
77
|
+
"cpu-features": true,
|
|
78
|
+
"ssh2": true
|
|
72
79
|
}
|
|
73
80
|
}
|
package/sys/ctr.d.ts
CHANGED
|
@@ -323,7 +323,8 @@ export declare class Ctr {
|
|
|
323
323
|
/** --- auth 对象 --- */
|
|
324
324
|
private _authorization;
|
|
325
325
|
/**
|
|
326
|
-
* ---
|
|
326
|
+
* --- 按 Authorization、GET _auth、POST _auth 顺序读取鉴权信息,空值或格式错误不回退 ---
|
|
327
|
+
* @returns Basic Auth、Bearer Token 或 false(未提供或格式无效)
|
|
327
328
|
*/
|
|
328
329
|
getAuthorization(): {
|
|
329
330
|
'type': 'basic';
|
|
@@ -347,8 +348,9 @@ export declare class Ctr {
|
|
|
347
348
|
/**
|
|
348
349
|
* --- 开启 Session ---
|
|
349
350
|
* @param link Kv 或 Db 实例
|
|
350
|
-
* @param auth
|
|
351
|
-
* @param opt
|
|
351
|
+
* @param auth 开启请求凭据读取,使用 opt.header 或 Authorization / GET、POST 的 _auth;提供无效凭据不回退 Cookie
|
|
352
|
+
* @param opt Session 选项,cookie 为 false 时不读取或写入 Cookie
|
|
353
|
+
* @returns 是否初始化成功,匿名会话也返回 true
|
|
352
354
|
*/
|
|
353
355
|
protected _startSession(link: lDb.Pool | lKv.Kv, auth?: boolean, opt?: lSession.IOptions): Promise<boolean>;
|
|
354
356
|
/**
|
package/sys/ctr.js
CHANGED
|
@@ -712,20 +712,21 @@ export class Ctr {
|
|
|
712
712
|
/** --- auth 对象 --- */
|
|
713
713
|
_authorization = null;
|
|
714
714
|
/**
|
|
715
|
-
* ---
|
|
715
|
+
* --- 按 Authorization、GET _auth、POST _auth 顺序读取鉴权信息,空值或格式错误不回退 ---
|
|
716
|
+
* @returns Basic Auth、Bearer Token 或 false(未提供或格式无效)
|
|
716
717
|
*/
|
|
717
718
|
getAuthorization() {
|
|
718
719
|
if (this._authorization !== null) {
|
|
719
720
|
return this._authorization;
|
|
720
721
|
}
|
|
721
722
|
let auth = '';
|
|
722
|
-
if (this._headers['authorization']) {
|
|
723
|
+
if (this._headers['authorization'] !== undefined) {
|
|
723
724
|
auth = this._headers['authorization'];
|
|
724
725
|
}
|
|
725
|
-
else if (this._get['_auth']) {
|
|
726
|
+
else if (this._get['_auth'] !== undefined) {
|
|
726
727
|
auth = this._get['_auth'];
|
|
727
728
|
}
|
|
728
|
-
else if (this._post['_auth']) {
|
|
729
|
+
else if (this._post['_auth'] !== undefined) {
|
|
729
730
|
auth = this._post['_auth'];
|
|
730
731
|
}
|
|
731
732
|
if (typeof auth !== 'string') {
|
|
@@ -744,6 +745,9 @@ export class Ctr {
|
|
|
744
745
|
this._authorization = { 'type': 'bearer', 'token': credential };
|
|
745
746
|
return this._authorization;
|
|
746
747
|
}
|
|
748
|
+
if (scheme !== 'basic') {
|
|
749
|
+
return false;
|
|
750
|
+
}
|
|
747
751
|
// --- Basic Auth: base64(user:pwd) ---
|
|
748
752
|
const decoded = lCrypto.base64Decode(credential);
|
|
749
753
|
if (!decoded) {
|
|
@@ -791,8 +795,9 @@ export class Ctr {
|
|
|
791
795
|
/**
|
|
792
796
|
* --- 开启 Session ---
|
|
793
797
|
* @param link Kv 或 Db 实例
|
|
794
|
-
* @param auth
|
|
795
|
-
* @param opt
|
|
798
|
+
* @param auth 开启请求凭据读取,使用 opt.header 或 Authorization / GET、POST 的 _auth;提供无效凭据不回退 Cookie
|
|
799
|
+
* @param opt Session 选项,cookie 为 false 时不读取或写入 Cookie
|
|
800
|
+
* @returns 是否初始化成功,匿名会话也返回 true
|
|
796
801
|
*/
|
|
797
802
|
_startSession(link, auth = false, opt = {}) {
|
|
798
803
|
this._sess = new lSession.Session();
|
package/sys/route.js
CHANGED
|
@@ -293,7 +293,6 @@ export async function run(data) {
|
|
|
293
293
|
for (const key in data.req.headers) {
|
|
294
294
|
setInputValue(headers, key.toLowerCase(), data.req.headers[key]);
|
|
295
295
|
}
|
|
296
|
-
headers['authorization'] ??= '';
|
|
297
296
|
/** --- 开发者返回值 --- */
|
|
298
297
|
let rtn;
|
|
299
298
|
if (data.socket && (data.req instanceof http.IncomingMessage)) {
|