@maiyunnet/kebab 8.5.3 → 8.6.0

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/doc/kebab-rag.md CHANGED
@@ -1410,7 +1410,7 @@ index/variables/VER.md
1410
1410
 
1411
1411
  # Variable: VER
1412
1412
 
1413
- > `const` **VER**: `"8.5.3"` = `'8.5.3'`
1413
+ > `const` **VER**: `"8.6.0"` = `'8.6.0'`
1414
1414
 
1415
1415
  Defined in: [index.ts:10](https://github.com/maiyunnet/kebab/blob/master/index.ts#L10)
1416
1416
 
@@ -12771,7 +12771,7 @@ lib/session/classes/Session.md
12771
12771
 
12772
12772
  # Class: Session
12773
12773
 
12774
- Defined in: [lib/session.ts:38](https://github.com/maiyunnet/kebab/blob/master/lib/session.ts#L38)
12774
+ Defined in: [lib/session.ts:39](https://github.com/maiyunnet/kebab/blob/master/lib/session.ts#L39)
12775
12775
 
12776
12776
  ## Constructors
12777
12777
 
@@ -12789,7 +12789,7 @@ Defined in: [lib/session.ts:38](https://github.com/maiyunnet/kebab/blob/master/l
12789
12789
 
12790
12790
  > **getName**(): `string`
12791
12791
 
12792
- Defined in: [lib/session.ts:203](https://github.com/maiyunnet/kebab/blob/master/lib/session.ts#L203)
12792
+ Defined in: [lib/session.ts:207](https://github.com/maiyunnet/kebab/blob/master/lib/session.ts#L207)
12793
12793
 
12794
12794
  获取当前的 cookie 的 name 值
12795
12795
 
@@ -12803,7 +12803,7 @@ Defined in: [lib/session.ts:203](https://github.com/maiyunnet/kebab/blob/master/
12803
12803
 
12804
12804
  > **getToken**(): `string`
12805
12805
 
12806
- Defined in: [lib/session.ts:196](https://github.com/maiyunnet/kebab/blob/master/lib/session.ts#L196)
12806
+ Defined in: [lib/session.ts:200](https://github.com/maiyunnet/kebab/blob/master/lib/session.ts#L200)
12807
12807
 
12808
12808
  获取当前的 token 值
12809
12809
 
@@ -12817,7 +12817,7 @@ Defined in: [lib/session.ts:196](https://github.com/maiyunnet/kebab/blob/master/
12817
12817
 
12818
12818
  > **init**(`ctr`, `link`, `auth?`, `opt?`): `Promise`\<`boolean`\>
12819
12819
 
12820
- Defined in: [lib/session.ts:66](https://github.com/maiyunnet/kebab/blob/master/lib/session.ts#L66)
12820
+ Defined in: [lib/session.ts:67](https://github.com/maiyunnet/kebab/blob/master/lib/session.ts#L67)
12821
12821
 
12822
12822
  初始化函数,相当于 construct
12823
12823
 
@@ -12859,7 +12859,7 @@ false 表示系统错误
12859
12859
 
12860
12860
  > **update**(): `Promise`\<`void`\>
12861
12861
 
12862
- Defined in: [lib/session.ts:210](https://github.com/maiyunnet/kebab/blob/master/lib/session.ts#L210)
12862
+ Defined in: [lib/session.ts:214](https://github.com/maiyunnet/kebab/blob/master/lib/session.ts#L214)
12863
12863
 
12864
12864
  页面整体结束时,要写入到 Kv 或 数据库
12865
12865
 
@@ -12933,6 +12933,14 @@ Defined in: [lib/session.ts:33](https://github.com/maiyunnet/kebab/blob/master/l
12933
12933
 
12934
12934
  ***
12935
12935
 
12936
+ ### token?
12937
+
12938
+ > `optional` **token**: `string`
12939
+
12940
+ Defined in: [lib/session.ts:36](https://github.com/maiyunnet/kebab/blob/master/lib/session.ts#L36)
12941
+
12942
+ ***
12943
+
12936
12944
  ### ttl?
12937
12945
 
12938
12946
  > `optional` **ttl**: `number`
@@ -20423,7 +20431,7 @@ Kv 或 Db 实例
20423
20431
 
20424
20432
  [`IOptions`](../../../lib/session/interfaces/IOptions.md) = `{}`
20425
20433
 
20426
- name, ttl, ssl, sqlPre
20434
+ 选项
20427
20435
 
20428
20436
  #### Returns
20429
20437
 
package/index.d.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * --- 本文件用来定义每个目录实体地址的常量 ---
6
6
  */
7
7
  /** --- 当前系统版本号 --- */
8
- export declare const VER = "8.5.3";
8
+ export declare const VER = "8.6.0";
9
9
  /** --- 框架根目录,以 / 结尾 --- */
10
10
  export declare const ROOT_PATH: string;
11
11
  /** --- 框架的 LIB,以 / 结尾 --- */
package/index.js CHANGED
@@ -6,7 +6,7 @@
6
6
  * --- 本文件用来定义每个目录实体地址的常量 ---
7
7
  */
8
8
  /** --- 当前系统版本号 --- */
9
- export const VER = '8.5.3';
9
+ export const VER = '8.6.0';
10
10
  // --- 服务端用的路径 ---
11
11
  const imu = decodeURIComponent(import.meta.url).replace('file://', '').replace(/^\/(\w:)/, '$1');
12
12
  /** --- /xxx/xxx --- */
package/lib/session.d.ts CHANGED
@@ -12,6 +12,7 @@ export interface IOptions {
12
12
  'ssl'?: boolean;
13
13
  'domain'?: string;
14
14
  'sqlPre'?: string;
15
+ 'token'?: string;
15
16
  }
16
17
  export declare class Session {
17
18
  /** --- 数据库操作对象 --- */
package/lib/session.js CHANGED
@@ -51,7 +51,10 @@ export class Session {
51
51
  this._ttl = opt.ttl ?? config.session.ttl ?? 172800;
52
52
  const tim = lTime.stamp();
53
53
  this._ctr = ctr;
54
- if (auth) {
54
+ if (opt.token) {
55
+ this._token = opt.token;
56
+ }
57
+ else if (auth) {
55
58
  const a = ctr.getAuthorization();
56
59
  if (a && typeof a !== 'string' && (a.user === 'token')) {
57
60
  this._token = a.pwd;
@@ -125,7 +128,7 @@ export class Session {
125
128
  }
126
129
  this._token = lCore.random(16, lCore.RANDOM_LUN);
127
130
  ++count;
128
- } while (!await this._link.set(this._name + '_' + this._token, [], this._ttl, 'nx'));
131
+ } while (!await this._link.set(this._name + '_' + this._token, {}, this._ttl, 'nx'));
129
132
  }
130
133
  else {
131
134
  let count = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maiyunnet/kebab",
3
- "version": "8.5.3",
3
+ "version": "8.6.0",
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": [
package/sys/child.js CHANGED
@@ -113,7 +113,12 @@ async function run() {
113
113
  cb(err);
114
114
  },
115
115
  'ciphers': 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS',
116
- 'allowHTTP1': true
116
+ 'allowHTTP1': true,
117
+ // --- 防止 CDN 回源时 HTTP/2 流异常导致 RST_STREAM ---
118
+ 'maxSessionMemory': 32,
119
+ 'settings': {
120
+ 'maxConcurrentStreams': 128,
121
+ }
117
122
  }, function (req, res) {
118
123
  const host = (req.headers[':authority'] ?? req.headers['host'] ?? '');
119
124
  if (!host) {
@@ -133,6 +138,8 @@ async function run() {
133
138
  }
134
139
  wrapWithLinkCount(host + (req.url ?? ''), () => upgradeHandler(req, socket, true, head), '[CHILD][http2][upgrade]', 'UPGRADE');
135
140
  }).listen(lCore.globalConfig.httpsPort);
141
+ // --- 增大 HTTP/2 超时,防止 CDN 预建连接被 Node.js 过早关闭 ---
142
+ http2Server.setTimeout(120_000);
136
143
  httpServer = http.createServer(function (req, res) {
137
144
  const host = (req.headers['host'] ?? '');
138
145
  if (!host) {
@@ -157,6 +164,9 @@ async function run() {
157
164
  }
158
165
  wrapWithLinkCount(host + (req.url ?? ''), () => upgradeHandler(req, socket, false, head), '[CHILD][http][upgrade]', 'UPGRADE');
159
166
  }).listen(lCore.globalConfig.httpPort);
167
+ // --- 增大超时,防止 CDN 回源 Keep-Alive 连接被 Node.js 过早关闭导致 net_exception_peer_error ---
168
+ httpServer.headersTimeout = 120_000;
169
+ httpServer.keepAliveTimeout = 65_000;
160
170
  // --- 启动性能监控 ---
161
171
  sMonitor.start();
162
172
  }
package/sys/ctr.d.ts CHANGED
@@ -213,7 +213,7 @@ export declare class Ctr {
213
213
  * --- 开启 Session ---
214
214
  * @param link Kv 或 Db 实例
215
215
  * @param auth 设为 true 则从头 Authorization 或 post _auth 值读取 token
216
- * @param opt name, ttl, ssl, sqlPre
216
+ * @param opt 选项
217
217
  */
218
218
  protected _startSession(link: lDb.Pool | lKv.Kv, auth?: boolean, opt?: lSession.IOptions): Promise<boolean>;
219
219
  /**
package/sys/ctr.js CHANGED
@@ -549,7 +549,7 @@ export class Ctr {
549
549
  * --- 开启 Session ---
550
550
  * @param link Kv 或 Db 实例
551
551
  * @param auth 设为 true 则从头 Authorization 或 post _auth 值读取 token
552
- * @param opt name, ttl, ssl, sqlPre
552
+ * @param opt 选项
553
553
  */
554
554
  _startSession(link, auth = false, opt = {}) {
555
555
  this._sess = new lSession.Session();
@@ -28,6 +28,7 @@ export default class extends sCtr.Ctr {
28
28
  ctrAsynctask(): any[];
29
29
  ctrTimeoutLong(): Promise<any[]>;
30
30
  ctrTimeoutShort(): Promise<any[]>;
31
+ ctrSessionToken(): Promise<kebab.Json[]>;
31
32
  ctr500(): Promise<void>;
32
33
  modTest(): Promise<kebab.Json[] | string | boolean>;
33
34
  modSplit(): Promise<string>;
@@ -115,6 +115,7 @@ export default class extends sCtr.Ctr {
115
115
  `<br><a href="${this._config.const.urlBase}test/ctr-asynctask">View "test/ctr-asynctask"</a>`,
116
116
  `<br><a href="${this._config.const.urlBase}test/ctr-timeout-long">View "test/ctr-timeout-long"</a>`,
117
117
  `<br><a href="${this._config.const.urlBase}test/ctr-timeout-short">View "test/ctr-timeout-short"</a>`,
118
+ `<br><a href="${this._config.const.urlBase}test/ctr-session-token">View "test/ctr-session-token"</a>`,
118
119
  `<br><a href="${this._config.const.urlBase}test/ctr-500">View "test/ctr-500"</a>`,
119
120
  '<br><br><b>Middle:</b>',
120
121
  `<br><br><a href="${this._config.const.urlBase}test/middle">View "test/middle"</a>`,
@@ -611,6 +612,14 @@ Result:<pre id="result">Nothing.</pre>` + this._getEnd();
611
612
  echo.push('5');
612
613
  return [1, { 'list': echo }];
613
614
  }
615
+ async ctrSessionToken() {
616
+ const link = lDb.get(this);
617
+ await this._startSession(link, false, {
618
+ 'token': 'TEST_TOKEN_1234'
619
+ });
620
+ const currentToken = this._sess?.getToken();
621
+ return [1, { 'status': currentToken === 'TEST_TOKEN_1234' ? 'success' : 'failed', 'token': currentToken }];
622
+ }
614
623
  async ctr500() {
615
624
  await lCore.sleep(100);
616
625
  lCore.writeHead(this._res, 200);