@maiyunnet/kebab 8.5.4 → 8.6.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/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.4"` = `'8.5.4'`
1413
+ > `const` **VER**: `"8.6.1"` = `'8.6.1'`
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`
@@ -20051,7 +20059,7 @@ Defined in: [sys/ctr.ts:548](https://github.com/maiyunnet/kebab/blob/master/sys/
20051
20059
 
20052
20060
  > `protected` **\_cross**(): `boolean`
20053
20061
 
20054
- Defined in: [sys/ctr.ts:762](https://github.com/maiyunnet/kebab/blob/master/sys/ctr.ts#L762)
20062
+ Defined in: [sys/ctr.ts:765](https://github.com/maiyunnet/kebab/blob/master/sys/ctr.ts#L765)
20055
20063
 
20056
20064
  开启跨域请求
20057
20065
  返回 true 接续执行,返回 false 需要中断用户本次访问(options请求)
@@ -20066,7 +20074,7 @@ Defined in: [sys/ctr.ts:762](https://github.com/maiyunnet/kebab/blob/master/sys/
20066
20074
 
20067
20075
  > `protected` **\_device**(): `"unknown"` \| `"android"` \| `"linux"` \| `"windows"` \| `"macintosh"` \| `"ipad"`
20068
20076
 
20069
- Defined in: [sys/ctr.ts:587](https://github.com/maiyunnet/kebab/blob/master/sys/ctr.ts#L587)
20077
+ Defined in: [sys/ctr.ts:590](https://github.com/maiyunnet/kebab/blob/master/sys/ctr.ts#L590)
20070
20078
 
20071
20079
  根据用户 ua 获取当前用户的设备类型
20072
20080
 
@@ -20078,13 +20086,21 @@ Defined in: [sys/ctr.ts:587](https://github.com/maiyunnet/kebab/blob/master/sys/
20078
20086
 
20079
20087
  ### \_enabledXsrf()
20080
20088
 
20081
- > `protected` **\_enabledXsrf**(): `void`
20089
+ > `protected` **\_enabledXsrf**(`opt?`): `void`
20082
20090
 
20083
20091
  Defined in: [sys/ctr.ts:559](https://github.com/maiyunnet/kebab/blob/master/sys/ctr.ts#L559)
20084
20092
 
20085
20093
  当前页面开启 XSRF 支持(主要检测 cookie 是否存在)
20086
20094
  如果当前页面有 CDN,请不要使用
20087
20095
 
20096
+ #### Parameters
20097
+
20098
+ ##### opt?
20099
+
20100
+ ###### domain?
20101
+
20102
+ `string`
20103
+
20088
20104
  #### Returns
20089
20105
 
20090
20106
  `void`
@@ -20095,7 +20111,7 @@ Defined in: [sys/ctr.ts:559](https://github.com/maiyunnet/kebab/blob/master/sys/
20095
20111
 
20096
20112
  > `protected` **\_end**(): `void`
20097
20113
 
20098
- Defined in: [sys/ctr.ts:845](https://github.com/maiyunnet/kebab/blob/master/sys/ctr.ts#L845)
20114
+ Defined in: [sys/ctr.ts:848](https://github.com/maiyunnet/kebab/blob/master/sys/ctr.ts#L848)
20099
20115
 
20100
20116
  主动关闭当前 socket 连接
20101
20117
 
@@ -20109,7 +20125,7 @@ Defined in: [sys/ctr.ts:845](https://github.com/maiyunnet/kebab/blob/master/sys/
20109
20125
 
20110
20126
  > `protected` **\_getBasicAuth**(`user`, `pwd`): `string`
20111
20127
 
20112
- Defined in: [sys/ctr.ts:580](https://github.com/maiyunnet/kebab/blob/master/sys/ctr.ts#L580)
20128
+ Defined in: [sys/ctr.ts:583](https://github.com/maiyunnet/kebab/blob/master/sys/ctr.ts#L583)
20113
20129
 
20114
20130
  获取 Auth 字符串,用于客户端提交
20115
20131
 
@@ -20137,7 +20153,7 @@ Defined in: [sys/ctr.ts:580](https://github.com/maiyunnet/kebab/blob/master/sys/
20137
20153
 
20138
20154
  > `protected` **\_getLocale**(): `string`
20139
20155
 
20140
- Defined in: [sys/ctr.ts:754](https://github.com/maiyunnet/kebab/blob/master/sys/ctr.ts#L754)
20156
+ Defined in: [sys/ctr.ts:757](https://github.com/maiyunnet/kebab/blob/master/sys/ctr.ts#L757)
20141
20157
 
20142
20158
  获取当前语言名
20143
20159
 
@@ -20151,7 +20167,7 @@ Defined in: [sys/ctr.ts:754](https://github.com/maiyunnet/kebab/blob/master/sys/
20151
20167
 
20152
20168
  > `protected` **\_getLocaleJsonString**(): `string`
20153
20169
 
20154
- Defined in: [sys/ctr.ts:742](https://github.com/maiyunnet/kebab/blob/master/sys/ctr.ts#L742)
20170
+ Defined in: [sys/ctr.ts:745](https://github.com/maiyunnet/kebab/blob/master/sys/ctr.ts#L745)
20155
20171
 
20156
20172
  根据当前后台语言包设置情况获取 JSON 字符串传输到前台
20157
20173
 
@@ -20203,7 +20219,7 @@ Defined in: [sys/ctr.ts:315](https://github.com/maiyunnet/kebab/blob/master/sys/
20203
20219
 
20204
20220
  > `protected` **\_handleFormData**(`events?`): `Promise`\<`boolean`\>
20205
20221
 
20206
- Defined in: [sys/ctr.ts:853](https://github.com/maiyunnet/kebab/blob/master/sys/ctr.ts#L853)
20222
+ Defined in: [sys/ctr.ts:856](https://github.com/maiyunnet/kebab/blob/master/sys/ctr.ts#L856)
20207
20223
 
20208
20224
  获取 formdata 的信息
20209
20225
 
@@ -20235,7 +20251,7 @@ Defined in: [sys/ctr.ts:853](https://github.com/maiyunnet/kebab/blob/master/sys/
20235
20251
 
20236
20252
  > **\_l**(`key`, `data?`): `string`
20237
20253
 
20238
- Defined in: [sys/ctr.ts:780](https://github.com/maiyunnet/kebab/blob/master/sys/ctr.ts#L780)
20254
+ Defined in: [sys/ctr.ts:783](https://github.com/maiyunnet/kebab/blob/master/sys/ctr.ts#L783)
20239
20255
 
20240
20256
  获取语言包值
20241
20257
 
@@ -20261,7 +20277,7 @@ Defined in: [sys/ctr.ts:780](https://github.com/maiyunnet/kebab/blob/master/sys/
20261
20277
 
20262
20278
  > `protected` **\_loadData**(`path`): `Promise`\<`Record`\<`string`, `string`\> \| `null`\>
20263
20279
 
20264
- Defined in: [sys/ctr.ts:645](https://github.com/maiyunnet/kebab/blob/master/sys/ctr.ts#L645)
20280
+ Defined in: [sys/ctr.ts:648](https://github.com/maiyunnet/kebab/blob/master/sys/ctr.ts#L648)
20265
20281
 
20266
20282
  获取 data 数据
20267
20283
 
@@ -20283,7 +20299,7 @@ Defined in: [sys/ctr.ts:645](https://github.com/maiyunnet/kebab/blob/master/sys/
20283
20299
 
20284
20300
  > `protected` **\_loadLocale**(`loc`, `pkg?`): `Promise`\<`boolean`\>
20285
20301
 
20286
- Defined in: [sys/ctr.ts:693](https://github.com/maiyunnet/kebab/blob/master/sys/ctr.ts#L693)
20302
+ Defined in: [sys/ctr.ts:696](https://github.com/maiyunnet/kebab/blob/master/sys/ctr.ts#L696)
20287
20303
 
20288
20304
  设定语言并加载语言包
20289
20305
 
@@ -20335,7 +20351,7 @@ Defined in: [sys/ctr.ts:332](https://github.com/maiyunnet/kebab/blob/master/sys/
20335
20351
 
20336
20352
  > `protected` **\_location**(`location`): `false`
20337
20353
 
20338
- Defined in: [sys/ctr.ts:663](https://github.com/maiyunnet/kebab/blob/master/sys/ctr.ts#L663)
20354
+ Defined in: [sys/ctr.ts:666](https://github.com/maiyunnet/kebab/blob/master/sys/ctr.ts#L666)
20339
20355
 
20340
20356
  跳转(302临时跳转),支持相对本项目根路径的路径或绝对路径
20341
20357
 
@@ -20357,7 +20373,7 @@ Defined in: [sys/ctr.ts:663](https://github.com/maiyunnet/kebab/blob/master/sys/
20357
20373
 
20358
20374
  > `protected` **\_ping**(`data?`): `boolean`
20359
20375
 
20360
- Defined in: [sys/ctr.ts:830](https://github.com/maiyunnet/kebab/blob/master/sys/ctr.ts#L830)
20376
+ Defined in: [sys/ctr.ts:833](https://github.com/maiyunnet/kebab/blob/master/sys/ctr.ts#L833)
20361
20377
 
20362
20378
  发送 socket ping
20363
20379
 
@@ -20379,7 +20395,7 @@ Defined in: [sys/ctr.ts:830](https://github.com/maiyunnet/kebab/blob/master/sys/
20379
20395
 
20380
20396
  > `protected` **\_pong**(`data?`): `boolean`
20381
20397
 
20382
- Defined in: [sys/ctr.ts:838](https://github.com/maiyunnet/kebab/blob/master/sys/ctr.ts#L838)
20398
+ Defined in: [sys/ctr.ts:841](https://github.com/maiyunnet/kebab/blob/master/sys/ctr.ts#L841)
20383
20399
 
20384
20400
  发送 socket pong
20385
20401
 
@@ -20401,7 +20417,7 @@ Defined in: [sys/ctr.ts:838](https://github.com/maiyunnet/kebab/blob/master/sys/
20401
20417
 
20402
20418
  > `protected` **\_startSession**(`link`, `auth?`, `opt?`): `Promise`\<`boolean`\>
20403
20419
 
20404
- Defined in: [sys/ctr.ts:677](https://github.com/maiyunnet/kebab/blob/master/sys/ctr.ts#L677)
20420
+ Defined in: [sys/ctr.ts:680](https://github.com/maiyunnet/kebab/blob/master/sys/ctr.ts#L680)
20405
20421
 
20406
20422
  开启 Session
20407
20423
 
@@ -20423,7 +20439,7 @@ Kv 或 Db 实例
20423
20439
 
20424
20440
  [`IOptions`](../../../lib/session/interfaces/IOptions.md) = `{}`
20425
20441
 
20426
- name, ttl, ssl, sqlPre
20442
+ 选项
20427
20443
 
20428
20444
  #### Returns
20429
20445
 
@@ -20435,7 +20451,7 @@ name, ttl, ssl, sqlPre
20435
20451
 
20436
20452
  > `protected` **\_writeBinary**(`data`): `boolean`
20437
20453
 
20438
- Defined in: [sys/ctr.ts:822](https://github.com/maiyunnet/kebab/blob/master/sys/ctr.ts#L822)
20454
+ Defined in: [sys/ctr.ts:825](https://github.com/maiyunnet/kebab/blob/master/sys/ctr.ts#L825)
20439
20455
 
20440
20456
  发送 socket 二进制
20441
20457
 
@@ -20457,7 +20473,7 @@ Defined in: [sys/ctr.ts:822](https://github.com/maiyunnet/kebab/blob/master/sys/
20457
20473
 
20458
20474
  > `protected` **\_writeResult**(`data`): `boolean`
20459
20475
 
20460
- Defined in: [sys/ctr.ts:814](https://github.com/maiyunnet/kebab/blob/master/sys/ctr.ts#L814)
20476
+ Defined in: [sys/ctr.ts:817](https://github.com/maiyunnet/kebab/blob/master/sys/ctr.ts#L817)
20461
20477
 
20462
20478
  发送结果对象文本
20463
20479
 
@@ -20479,7 +20495,7 @@ Defined in: [sys/ctr.ts:814](https://github.com/maiyunnet/kebab/blob/master/sys/
20479
20495
 
20480
20496
  > `protected` **\_writeText**(`data`): `boolean`
20481
20497
 
20482
- Defined in: [sys/ctr.ts:806](https://github.com/maiyunnet/kebab/blob/master/sys/ctr.ts#L806)
20498
+ Defined in: [sys/ctr.ts:809](https://github.com/maiyunnet/kebab/blob/master/sys/ctr.ts#L809)
20483
20499
 
20484
20500
  发送 socket 文本
20485
20501
 
@@ -20501,7 +20517,7 @@ Defined in: [sys/ctr.ts:806](https://github.com/maiyunnet/kebab/blob/master/sys/
20501
20517
 
20502
20518
  > **getAuthorization**(): `string` \| `false` \| \{ `pwd`: `string`; `user`: `string`; \}
20503
20519
 
20504
- Defined in: [sys/ctr.ts:608](https://github.com/maiyunnet/kebab/blob/master/sys/ctr.ts#L608)
20520
+ Defined in: [sys/ctr.ts:611](https://github.com/maiyunnet/kebab/blob/master/sys/ctr.ts#L611)
20505
20521
 
20506
20522
  通过 header 或 _auth 获取鉴权信息或 JWT 信息(不解析)
20507
20523
 
package/index.d.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * --- 本文件用来定义每个目录实体地址的常量 ---
6
6
  */
7
7
  /** --- 当前系统版本号 --- */
8
- export declare const VER = "8.5.4";
8
+ export declare const VER = "8.6.1";
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.4';
9
+ export const VER = '8.6.1';
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.4",
3
+ "version": "8.6.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": [
package/sys/ctr.d.ts CHANGED
@@ -179,7 +179,9 @@ export declare class Ctr {
179
179
  * --- 当前页面开启 XSRF 支持(主要检测 cookie 是否存在) ---
180
180
  * --- 如果当前页面有 CDN,请不要使用 ---
181
181
  */
182
- protected _enabledXsrf(): void;
182
+ protected _enabledXsrf(opt?: {
183
+ 'domain'?: string;
184
+ }): void;
183
185
  /**
184
186
  * --- 获取 Auth 字符串,用于客户端提交 ---
185
187
  * @param user 用户名
@@ -213,7 +215,7 @@ export declare class Ctr {
213
215
  * --- 开启 Session ---
214
216
  * @param link Kv 或 Db 实例
215
217
  * @param auth 设为 true 则从头 Authorization 或 post _auth 值读取 token
216
- * @param opt name, ttl, ssl, sqlPre
218
+ * @param opt 选项
217
219
  */
218
220
  protected _startSession(link: lDb.Pool | lKv.Kv, auth?: boolean, opt?: lSession.IOptions): Promise<boolean>;
219
221
  /**
package/sys/ctr.js CHANGED
@@ -440,14 +440,15 @@ export class Ctr {
440
440
  * --- 当前页面开启 XSRF 支持(主要检测 cookie 是否存在) ---
441
441
  * --- 如果当前页面有 CDN,请不要使用 ---
442
442
  */
443
- _enabledXsrf() {
443
+ _enabledXsrf(opt) {
444
444
  // --- 设置 XSRF 值 ---
445
445
  if (this._cookie['XSRF-TOKEN'] === undefined) {
446
446
  const xsrf = lCore.random(16, lCore.RANDOM_LUN);
447
447
  this._xsrf = xsrf;
448
448
  lCore.setCookie(this, 'XSRF-TOKEN', xsrf, {
449
449
  'path': '/',
450
- 'httponly': true
450
+ 'httponly': true,
451
+ 'domain': opt?.domain,
451
452
  });
452
453
  this._cookie['XSRF-TOKEN'] = xsrf;
453
454
  }
@@ -549,7 +550,7 @@ export class Ctr {
549
550
  * --- 开启 Session ---
550
551
  * @param link Kv 或 Db 实例
551
552
  * @param auth 设为 true 则从头 Authorization 或 post _auth 值读取 token
552
- * @param opt name, ttl, ssl, sqlPre
553
+ * @param opt 选项
553
554
  */
554
555
  _startSession(link, auth = false, opt = {}) {
555
556
  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);