@maiyunnet/kebab 3.2.25 → 3.2.27

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/index.d.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * --- 本文件用来定义每个目录实体地址的常量 ---
6
6
  */
7
7
  /** --- 当前系统版本号 --- */
8
- export declare const VER = "3.2.25";
8
+ export declare const VER = "3.2.27";
9
9
  /** --- 框架根目录,以 / 结尾 --- */
10
10
  export declare const ROOT_PATH: string;
11
11
  export declare const LIB_PATH: string;
package/index.js CHANGED
@@ -6,7 +6,7 @@
6
6
  * --- 本文件用来定义每个目录实体地址的常量 ---
7
7
  */
8
8
  /** --- 当前系统版本号 --- */
9
- export const VER = '3.2.25';
9
+ export const VER = '3.2.27';
10
10
  // --- 服务端用的路径 ---
11
11
  const imu = decodeURIComponent(import.meta.url).replace('file://', '').replace(/^\/(\w:)/, '$1');
12
12
  /** --- /xxx/xxx --- */
package/lib/net.d.ts CHANGED
@@ -47,6 +47,19 @@ export declare function postJson(u: string, data: kebab.Json[] | Record<string,
47
47
  * @returns JSON 数据,失败时返回 null
48
48
  */
49
49
  export declare function postJsonResponseJson(u: string, data: kebab.Json[] | Record<string, kebab.Json>, opt?: IRequestOptions): Promise<any | null>;
50
+ /**
51
+ * --- 发起一个原生 fetch 请求,增加了一些框架选项,注意:会抛出错误 ---
52
+ * @param input 请求的 URL 或 Request 对象
53
+ * @param init 增加 mproxy
54
+ */
55
+ export declare function fetch(input: string | URL | Request, init?: RequestInit & {
56
+ /** --- 正向 mproxy 代理,url 如 https://xxx/abc --- */
57
+ 'mproxy'?: {
58
+ 'url': string;
59
+ 'auth': string;
60
+ 'data'?: any;
61
+ };
62
+ }): Promise<Response>;
50
63
  /**
51
64
  * --- 发起一个请求 ---
52
65
  * @param opt 配置项
package/lib/net.js CHANGED
@@ -88,6 +88,29 @@ export async function postJsonResponseJson(u, data, opt = {}) {
88
88
  }
89
89
  return json;
90
90
  }
91
+ /**
92
+ * --- 发起一个原生 fetch 请求,增加了一些框架选项,注意:会抛出错误 ---
93
+ * @param input 请求的 URL 或 Request 对象
94
+ * @param init 增加 mproxy
95
+ */
96
+ export function fetch(input, init = {}) {
97
+ const u = (input instanceof Request) ?
98
+ input.url :
99
+ input instanceof URL ? input.toString() : input;
100
+ const uri = lText.parseUrl(u);
101
+ /** --- 正向代理的地址 --- */
102
+ const puri = init.mproxy ? lText.parseUrl(init.mproxy.url) : null;
103
+ /** --- 定义请求 host --- */
104
+ const hostname = (puri ? puri.hostname : uri.hostname) ?? '';
105
+ if (!hostname) {
106
+ throw new Error('Kebab TypeError: Hostname is empty');
107
+ }
108
+ return global.fetch(init.mproxy ? init.mproxy.url + (init.mproxy.url.includes('?') ? '&' : '?') + lText.queryStringify({
109
+ 'url': u,
110
+ 'auth': init.mproxy.auth,
111
+ 'data': init.mproxy.data ? lText.stringifyJson(init.mproxy.data) : '{}',
112
+ }) : u, init);
113
+ }
91
114
  /**
92
115
  * --- 发起一个请求 ---
93
116
  * @param opt 配置项
@@ -149,19 +172,19 @@ export async function request(u, data, opt = {}) {
149
172
  // --- 发起请求 ---
150
173
  let req;
151
174
  try {
152
- // --- 重定义 IP ---
153
- const host = (puri ? puri.hostname : uri.hostname) ?? '';
154
- if (!host) {
175
+ /** --- 定义请求 host --- */
176
+ const hostname = (puri ? puri.hostname : uri.hostname) ?? '';
177
+ if (!hostname) {
155
178
  const res = new lResponse.Response(null);
156
179
  res.error = {
157
180
  'name': 'Possible mProxy error',
158
- 'message': 'host not found',
181
+ 'message': 'hostname not found',
159
182
  };
160
183
  return res;
161
184
  }
162
185
  if (typeof hosts === 'string' ?
163
186
  !hosts :
164
- (hosts[host] !== undefined && !hosts[host])) {
187
+ (hosts[hostname] !== undefined && !hosts[hostname])) {
165
188
  const res = new lResponse.Response(null);
166
189
  res.error = {
167
190
  'name': 'hosts error',
@@ -185,7 +208,7 @@ export async function request(u, data, opt = {}) {
185
208
  'localAddress': local,
186
209
  'ca': ca,
187
210
  'connectionOptions': {
188
- 'remoteHost': typeof hosts === 'string' ? hosts : hosts[host],
211
+ 'remoteHost': typeof hosts === 'string' ? hosts : hosts[hostname],
189
212
  },
190
213
  });
191
214
  }
package/lib/ws.d.ts CHANGED
@@ -81,7 +81,7 @@ export interface IRproxyOptions {
81
81
  export declare class Socket {
82
82
  /** --- 当前的 ws 对象 --- */
83
83
  private _ws;
84
- constructor(request?: http.IncomingMessage, socket?: net.Socket, options?: {
84
+ constructor(request?: http.IncomingMessage, socket?: net.Socket, head?: Buffer, options?: {
85
85
  'headers'?: http.OutgoingHttpHeaders;
86
86
  'timeout'?: number;
87
87
  });
@@ -142,7 +142,7 @@ export declare function connect(u: string, opt?: IConnectOptions): Promise<Socke
142
142
  * @param request Http 请求端
143
143
  * @param socket 响应双向 socket
144
144
  */
145
- export declare function createServer(request: http.IncomingMessage, socket: net.Socket, options?: {
145
+ export declare function createServer(request: http.IncomingMessage, socket: net.Socket, head?: Buffer, options?: {
146
146
  'headers'?: http.OutgoingHttpHeaders;
147
147
  'timeout'?: number;
148
148
  }): Socket;
package/lib/ws.js CHANGED
@@ -24,7 +24,7 @@ const liwsServer = liws.createServer({
24
24
  'frameReceiveMode': EFrameReceiveMode.SIMPLE,
25
25
  });
26
26
  export class Socket {
27
- constructor(request, socket, options = {}) {
27
+ constructor(request, socket, head, options = {}) {
28
28
  /** --- 还未开启监听时来的数据将存在这里 --- */
29
29
  this._waitMsg = [];
30
30
  /** --- 还未开启 error 监听时产生的 error 错误对象 --- */
@@ -62,6 +62,7 @@ export class Socket {
62
62
  'socket': socket,
63
63
  'headers': options.headers,
64
64
  'timeout': options.timeout,
65
+ 'clientEarlyDataPayload': head,
65
66
  });
66
67
  this._bindEvent();
67
68
  }
@@ -279,8 +280,8 @@ export function connect(u, opt = {}) {
279
280
  * @param request Http 请求端
280
281
  * @param socket 响应双向 socket
281
282
  */
282
- export function createServer(request, socket, options = {}) {
283
- return new Socket(request, socket, options);
283
+ export function createServer(request, socket, head, options = {}) {
284
+ return new Socket(request, socket, head, options);
284
285
  }
285
286
  /**
286
287
  * --- 绑定 socket 管道 ---
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maiyunnet/kebab",
3
- "version": "3.2.25",
3
+ "version": "3.2.27",
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": [
@@ -19,26 +19,26 @@
19
19
  "#kebab/*": "./*"
20
20
  },
21
21
  "dependencies": {
22
- "@aws-sdk/client-s3": "^3.917.0",
23
- "@aws-sdk/lib-storage": "^3.917.0",
22
+ "@aws-sdk/client-s3": "^3.922.0",
23
+ "@aws-sdk/lib-storage": "^3.922.0",
24
24
  "@litert/http-client": "^1.1.2",
25
25
  "@litert/mime": "^0.1.3",
26
26
  "@litert/redis": "^3.0.5",
27
27
  "@litert/websocket": "^0.2.7",
28
28
  "@types/ssh2": "^1.15.5",
29
- "@zilliz/milvus2-sdk-node": "^2.6.2",
29
+ "@zilliz/milvus2-sdk-node": "^2.6.3",
30
30
  "ejs": "^3.1.10",
31
31
  "jszip": "^3.10.1",
32
32
  "mysql2": "^3.15.3",
33
33
  "openai": "^6.7.0",
34
34
  "ssh2": "^1.17.0",
35
35
  "svg-captcha": "^1.4.0",
36
- "tencentcloud-sdk-nodejs": "^4.1.135"
36
+ "tencentcloud-sdk-nodejs": "^4.1.136"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@litert/eslint-plugin-rules": "^0.3.1",
40
40
  "@types/ejs": "^3.1.5",
41
- "@types/node": "^24.9.1",
41
+ "@types/node": "^24.9.2",
42
42
  "tsc-alias": "^1.8.16",
43
43
  "typescript": "^5.9.3"
44
44
  }
package/sys/child.js CHANGED
@@ -113,7 +113,7 @@ async function run() {
113
113
  });
114
114
  }).on('tlsClientError', (err, socket) => {
115
115
  socket.destroy();
116
- }).on('upgrade', function (req, socket) {
116
+ }).on('upgrade', function (req, socket, head) {
117
117
  const host = (req.headers['host'] ?? '');
118
118
  if (!host) {
119
119
  socket.destroy();
@@ -125,7 +125,7 @@ async function run() {
125
125
  linkCount[key] = 0;
126
126
  }
127
127
  ++linkCount[key];
128
- await upgradeHandler(req, socket, true);
128
+ await upgradeHandler(req, socket, true, head);
129
129
  --linkCount[key];
130
130
  if (!linkCount[key]) {
131
131
  delete linkCount[key];
@@ -164,7 +164,7 @@ async function run() {
164
164
  delete linkCount[key];
165
165
  }
166
166
  });
167
- }).on('upgrade', function (req, socket) {
167
+ }).on('upgrade', function (req, socket, head) {
168
168
  const host = (req.headers['host'] ?? '');
169
169
  if (!host) {
170
170
  socket.destroy();
@@ -176,7 +176,7 @@ async function run() {
176
176
  linkCount[key] = 0;
177
177
  }
178
178
  ++linkCount[key];
179
- await upgradeHandler(req, socket, false);
179
+ await upgradeHandler(req, socket, false, head);
180
180
  --linkCount[key];
181
181
  if (!linkCount[key]) {
182
182
  delete linkCount[key];
@@ -373,8 +373,9 @@ async function requestHandler(req, res, https) {
373
373
  * @param req 请求对象
374
374
  * @param socket socket 对象
375
375
  * @param https 是否是 https
376
+ * @param head head 数据
376
377
  */
377
- async function upgradeHandler(req, socket, https) {
378
+ async function upgradeHandler(req, socket, https, head) {
378
379
  socket.removeAllListeners('error');
379
380
  // --- 当前 uri ---
380
381
  const uri = lText.parseUrl(`ws${https ? 's' : ''}://${req.headers['host'] ?? ''}${req.url ?? ''}`);
@@ -413,10 +414,11 @@ async function upgradeHandler(req, socket, https) {
413
414
  if (await sRoute.run({
414
415
  'req': req,
415
416
  'socket': socket,
417
+ 'head': head,
416
418
  'uri': uri,
417
419
  'rootPath': vhost.real + now,
418
420
  'urlBase': '/' + now,
419
- 'path': path.slice(('/' + pathList.slice(0, i).join('/')).length + 1)
421
+ 'path': path.slice(('/' + pathList.slice(0, i).join('/')).length + 1),
420
422
  })) {
421
423
  return;
422
424
  }
@@ -440,6 +442,7 @@ async function upgradeHandler(req, socket, https) {
440
442
  if (await sRoute.run({
441
443
  'req': req,
442
444
  'socket': socket,
445
+ 'head': head,
443
446
  'uri': uri,
444
447
  'rootPath': vhost.real + now,
445
448
  'urlBase': '/' + now,
package/sys/route.d.ts CHANGED
@@ -19,7 +19,10 @@ export declare function clearKebabConfigs(): void;
19
19
  export declare function run(data: {
20
20
  'req': http2.Http2ServerRequest | http.IncomingMessage;
21
21
  'res'?: http2.Http2ServerResponse | http.ServerResponse;
22
+ /** --- WebSocket 连接的 socket 对象 --- */
22
23
  'socket'?: net.Socket;
24
+ /** --- WebSocket 的 head 数据 --- */
25
+ 'head'?: Buffer;
23
26
  'uri': kebab.IUrlParse;
24
27
  /** --- 虚拟主机当前动态目录的绝对根目录,末尾带 / --- */
25
28
  'rootPath': string;
package/sys/route.js CHANGED
@@ -239,7 +239,7 @@ export async function run(data) {
239
239
  const options = cctr.onUpgrade();
240
240
  // --- 默认无消息发送 3 分钟 ---
241
241
  options.timeout ??= 60_000 * 3;
242
- wsSocket = lWs.createServer(data.req, data.socket, options);
242
+ wsSocket = lWs.createServer(data.req, data.socket, data.head, options);
243
243
  cctr.setPrototype('_socket', wsSocket);
244
244
  }
245
245
  catch (e) {
@@ -75,6 +75,8 @@ export default class extends sCtr.Ctr {
75
75
  netMproxy1(): Promise<string | boolean>;
76
76
  netMproxy2(): any[];
77
77
  netFilterheaders(): string;
78
+ netFetch(): Promise<string | boolean>;
79
+ netFetch1(): any[];
78
80
  scan(): Promise<kebab.Json>;
79
81
  scan1(): Promise<kebab.Json>;
80
82
  scan2(): Promise<kebab.Json>;
@@ -166,6 +166,7 @@ export default class extends sCtr.Ctr {
166
166
  `<br><a href="${this._config.const.urlBase}test/net-rproxy/dist/core.js">View "test/net-rproxy/dist/core.js"</a> <a href="${this._config.const.urlBase}test/net-rproxy/package.json">View "package.json"</a>`,
167
167
  `<br><a href="${this._config.const.urlBase}test/net-mproxy">View "test/net-mproxy"</a>`,
168
168
  `<br><a href="${this._config.const.urlBase}test/net-filterheaders">View "test/net-filterheaders"</a>`,
169
+ `<br><a href="${this._config.const.urlBase}test/net-fetch">View "test/net-fetch"</a>`,
169
170
  '<br><br><b>Scan:</b>',
170
171
  `<br><br><a href="${this._config.const.urlBase}test/scan?s=db">View "test/scan?s=db"</a>`,
171
172
  `<br><a href="${this._config.const.urlBase}test/scan?s=kv">View "test/scan?s=kv"</a>`,
@@ -1888,6 +1889,68 @@ error: <pre>${JSON.stringify(res.error, null, 4)}</pre>`);
1888
1889
  echo.push(`const filtered = lNet.filterHeaders(headers);<pre>${JSON.stringify(filtered, null, 4)}</pre>`);
1889
1890
  return echo.join('') + this._getEnd();
1890
1891
  }
1892
+ async netFetch() {
1893
+ const echo = [];
1894
+ try {
1895
+ const res = await lNet.fetch(this._internalUrl + 'test/net-fetch1', {
1896
+ 'method': 'POST',
1897
+ 'headers': {
1898
+ 'content-type': 'application/json',
1899
+ },
1900
+ 'body': JSON.stringify({ 'test': '123' }),
1901
+ });
1902
+ echo.push(`<pre>lNet.fetch('${this._internalUrl}test/net-fetch1', {
1903
+ 'method': 'POST',
1904
+ 'headers': {
1905
+ 'content-type': 'application/json',
1906
+ },
1907
+ 'body': JSON.stringify({ 'test': '123' }),
1908
+ });</pre>
1909
+ headers: <pre>${JSON.stringify(Object.fromEntries(res.headers.entries()), null, 4)}</pre>
1910
+ content: <pre>${await res.text()}</pre>`);
1911
+ }
1912
+ catch (e) {
1913
+ echo.push(`error: <pre>${JSON.stringify(e)}</pre>`);
1914
+ }
1915
+ echo.push(`mproxy:`);
1916
+ try {
1917
+ const res = await lNet.fetch(this._internalUrl + 'test/net-fetch1', {
1918
+ 'method': 'POST',
1919
+ 'headers': {
1920
+ 'content-type': 'application/json',
1921
+ },
1922
+ 'body': JSON.stringify({ 'test': '456' }),
1923
+ 'mproxy': {
1924
+ 'url': this._internalUrl + 'test/net-mproxy1',
1925
+ 'auth': '123456',
1926
+ 'data': { 'test': '789' },
1927
+ },
1928
+ });
1929
+ echo.push(`<pre>lNet.fetch('${this._internalUrl}test/net-fetch1', {
1930
+ 'method': 'POST',
1931
+ 'headers': {
1932
+ 'content-type': 'application/json',
1933
+ },
1934
+ 'body': JSON.stringify({ 'test': '123' }),
1935
+ 'mproxy': {
1936
+ 'url': this._internalUrl + 'test/net-mproxy1',
1937
+ 'auth': '123456',
1938
+ 'data': { 'test': '789' },
1939
+ },
1940
+ });</pre>
1941
+ headers: <pre>${JSON.stringify(Object.fromEntries(res.headers.entries()), null, 4)}</pre>
1942
+ content: <pre>${await res.text()}</pre>`);
1943
+ }
1944
+ catch (e) {
1945
+ echo.push(`error: <pre>${JSON.stringify(e)}</pre>`);
1946
+ }
1947
+ return echo.join('') + '<br>' + this._getEnd();
1948
+ }
1949
+ netFetch1() {
1950
+ return [1, {
1951
+ 'post': this._post,
1952
+ }];
1953
+ }
1891
1954
  async scan() {
1892
1955
  const link = await this._scanLink();
1893
1956
  if (!link) {