@rsdoctor/sdk 1.5.14-beta.0 → 1.5.15
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/index.cjs +54 -14
- package/dist/index.js +53 -12
- package/dist/sdk/server/index.d.cts +4 -0
- package/dist/sdk/server/index.d.ts +4 -0
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -5675,9 +5675,7 @@ var __webpack_modules__ = {
|
|
|
5675
5675
|
return enc && (headers['Content-Encoding'] = enc), isEtag && (headers.ETag = `W/"${stats.size}-${stats.mtime.getTime()}"`), headers;
|
|
5676
5676
|
}
|
|
5677
5677
|
let common_namespaceObject = require("@rsdoctor/utils/common"), external_assert_namespaceObject = require("assert");
|
|
5678
|
-
var external_assert_default = __webpack_require__.n(external_assert_namespaceObject), body_parser = __webpack_require__("../../node_modules/.pnpm/body-parser@2.2.2/node_modules/body-parser/index.js"), body_parser_default = __webpack_require__.n(body_parser);
|
|
5679
|
-
let cors_index_js_namespaceObject = require("../compiled/cors/index.js");
|
|
5680
|
-
var cors_index_js_default = __webpack_require__.n(cors_index_js_namespaceObject), external_stream_ = __webpack_require__("stream");
|
|
5678
|
+
var external_assert_default = __webpack_require__.n(external_assert_namespaceObject), body_parser = __webpack_require__("../../node_modules/.pnpm/body-parser@2.2.2/node_modules/body-parser/index.js"), body_parser_default = __webpack_require__.n(body_parser), external_stream_ = __webpack_require__("stream");
|
|
5681
5679
|
let external_socket_io_namespaceObject = require("socket.io");
|
|
5682
5680
|
var external_util_ = __webpack_require__("util");
|
|
5683
5681
|
class SocketAPILoader {
|
|
@@ -6131,10 +6129,6 @@ var __webpack_modules__ = {
|
|
|
6131
6129
|
plugin_ts_metadata("design:returntype", Promise)
|
|
6132
6130
|
], PluginAPI.prototype, "getPluginData", null);
|
|
6133
6131
|
var external_os_ = __webpack_require__("os"), external_os_default = __webpack_require__.n(external_os_);
|
|
6134
|
-
function getLocalIpAddress() {
|
|
6135
|
-
for (let iface of Object.values(external_os_default().networkInterfaces()))for (let alias of iface)if ('IPv4' === alias.family && !alias.internal) return alias.address;
|
|
6136
|
-
return '127.0.0.1';
|
|
6137
|
-
}
|
|
6138
6132
|
function project_ts_decorate(decorators, target, key, desc) {
|
|
6139
6133
|
var d, c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc;
|
|
6140
6134
|
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -6148,7 +6142,10 @@ var __webpack_modules__ = {
|
|
|
6148
6142
|
async env() {
|
|
6149
6143
|
let { server } = this.ctx;
|
|
6150
6144
|
return {
|
|
6151
|
-
ip:
|
|
6145
|
+
ip: function() {
|
|
6146
|
+
for (let iface of Object.values(external_os_default().networkInterfaces()))for (let alias of iface)if ('IPv4' === alias.family && !alias.internal) return alias.address;
|
|
6147
|
+
return '127.0.0.1';
|
|
6148
|
+
}(),
|
|
6152
6149
|
port: server.port
|
|
6153
6150
|
};
|
|
6154
6151
|
}
|
|
@@ -6273,7 +6270,12 @@ var __webpack_modules__ = {
|
|
|
6273
6270
|
return logger_namespaceObject.logger.error('Failed to open Rsdoctor URL.'), logger_namespaceObject.logger.error(err), !1;
|
|
6274
6271
|
}
|
|
6275
6272
|
}
|
|
6276
|
-
let server_require = (0, external_module_namespaceObject.createRequire)(__rslib_import_meta_url__)
|
|
6273
|
+
let server_require = (0, external_module_namespaceObject.createRequire)(__rslib_import_meta_url__), LOCAL_HOSTNAMES = new Set([
|
|
6274
|
+
'localhost',
|
|
6275
|
+
'127.0.0.1',
|
|
6276
|
+
'[::1]',
|
|
6277
|
+
'::1'
|
|
6278
|
+
]);
|
|
6277
6279
|
class RsdoctorServer {
|
|
6278
6280
|
constructor(sdk, port = build_namespaceObject.Server.defaultPort, config){
|
|
6279
6281
|
this.sdk = sdk, this.disposed = !0, this.get = (route, cb)=>{
|
|
@@ -6298,7 +6300,7 @@ var __webpack_modules__ = {
|
|
|
6298
6300
|
return this._server.app;
|
|
6299
6301
|
}
|
|
6300
6302
|
get host() {
|
|
6301
|
-
return
|
|
6303
|
+
return build_namespaceObject.Server.defaultHost;
|
|
6302
6304
|
}
|
|
6303
6305
|
get origin() {
|
|
6304
6306
|
return `http://${this.host}:${this.port}`;
|
|
@@ -6312,14 +6314,52 @@ var __webpack_modules__ = {
|
|
|
6312
6314
|
get innerClientPath() {
|
|
6313
6315
|
return this._innerClientPath;
|
|
6314
6316
|
}
|
|
6317
|
+
isLocalOrigin(origin) {
|
|
6318
|
+
try {
|
|
6319
|
+
let url = new URL(origin);
|
|
6320
|
+
return ('http:' === url.protocol || 'https:' === url.protocol) && LOCAL_HOSTNAMES.has(url.hostname);
|
|
6321
|
+
} catch {
|
|
6322
|
+
return !1;
|
|
6323
|
+
}
|
|
6324
|
+
}
|
|
6325
|
+
setCorsHeaders(req, res) {
|
|
6326
|
+
let origin = req.headers.origin;
|
|
6327
|
+
return 'string' == typeof origin && !!this.isLocalOrigin(origin) && (res.setHeader('Access-Control-Allow-Origin', origin), res.setHeader('Vary', 'Origin'), res.setHeader('Access-Control-Allow-Headers', 'Content-Type'), res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS'), !0);
|
|
6328
|
+
}
|
|
6329
|
+
createSecurityMiddleware() {
|
|
6330
|
+
return (req, res, next)=>{
|
|
6331
|
+
let isCorsAllowed = this.setCorsHeaders(req, res);
|
|
6332
|
+
if (req.method?.toUpperCase() === 'OPTIONS') {
|
|
6333
|
+
res.statusCode = isCorsAllowed ? 204 : 403, res.end();
|
|
6334
|
+
return;
|
|
6335
|
+
}
|
|
6336
|
+
next();
|
|
6337
|
+
};
|
|
6338
|
+
}
|
|
6339
|
+
async createInnerServer() {
|
|
6340
|
+
let lastError, expectedPort = this.port;
|
|
6341
|
+
for(let retry = 0; retry < 10; retry++){
|
|
6342
|
+
let port = build_namespaceObject.Server.getPortSync(expectedPort, this.host);
|
|
6343
|
+
try {
|
|
6344
|
+
return {
|
|
6345
|
+
port,
|
|
6346
|
+
server: await build_namespaceObject.Server.createServer(port, this.host)
|
|
6347
|
+
};
|
|
6348
|
+
} catch (error) {
|
|
6349
|
+
if ('EADDRINUSE' !== error.code) throw error;
|
|
6350
|
+
lastError = error, expectedPort = port + 1;
|
|
6351
|
+
}
|
|
6352
|
+
}
|
|
6353
|
+
throw lastError;
|
|
6354
|
+
}
|
|
6315
6355
|
async bootstrap() {
|
|
6316
6356
|
if (!this.disposed) return;
|
|
6317
|
-
let port =
|
|
6318
|
-
this.port = port, this._server =
|
|
6357
|
+
let { port, server } = await this.createInnerServer();
|
|
6358
|
+
this.port = port, this._server = server, this._socket = new Socket({
|
|
6319
6359
|
sdk: this.sdk,
|
|
6320
6360
|
server: this._server.server,
|
|
6321
6361
|
port: this.port
|
|
6322
|
-
}), await this._socket.bootstrap(), common_namespaceObject.GlobalConfig.writeMcpPort(this.port, this.sdk.name), logger_namespaceObject.logger.debug(`Successfully wrote mcp.json for ${logger_namespaceObject.chalk.cyan(this.sdk.name)} builder`), this.disposed = !1, this.app.use(
|
|
6362
|
+
}), await this._socket.bootstrap(), common_namespaceObject.GlobalConfig.writeMcpPort(this.port, this.sdk.name), logger_namespaceObject.logger.debug(`Successfully wrote mcp.json for ${logger_namespaceObject.chalk.cyan(this.sdk.name)} builder`), this.disposed = !1, this.app.use(this.createSecurityMiddleware()), this.app.use(body_parser_default().json({
|
|
6323
6363
|
limit: '500mb'
|
|
6324
6364
|
}));
|
|
6325
6365
|
let clientHtmlPath = this._innerClientPath ? this._innerClientPath : server_require.resolve('@rsdoctor/client'), clientDistPath = external_path_default().resolve(clientHtmlPath, '..');
|
|
@@ -6425,7 +6465,7 @@ var __webpack_modules__ = {
|
|
|
6425
6465
|
if (req.method?.toUpperCase() === method) {
|
|
6426
6466
|
try {
|
|
6427
6467
|
let body = await cb(req, res, next);
|
|
6428
|
-
if (res.
|
|
6468
|
+
if (res.statusCode = 200, Buffer.isBuffer(body)) {
|
|
6429
6469
|
res.setHeader('Content-Length', body.byteLength);
|
|
6430
6470
|
let ps = new external_stream_.PassThrough();
|
|
6431
6471
|
ps.write(body), ps.end(), ps.pipe(res);
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,6 @@ import node_path, { join, normalize, resolve as external_node_path_resolve, sep
|
|
|
14
14
|
import fs, { readdirSync, statSync } from "fs";
|
|
15
15
|
import { Algorithm, Bundle, Data, GlobalConfig, Lodash, decycle } from "@rsdoctor/utils/common";
|
|
16
16
|
import assert from "assert";
|
|
17
|
-
import cors from "../compiled/cors/index.js";
|
|
18
17
|
import { PassThrough } from "stream";
|
|
19
18
|
import { Server as external_socket_io_Server } from "socket.io";
|
|
20
19
|
import { isDeepStrictEqual } from "util";
|
|
@@ -6138,10 +6137,6 @@ class PluginAPI extends BaseAPI {
|
|
|
6138
6137
|
});
|
|
6139
6138
|
}
|
|
6140
6139
|
}
|
|
6141
|
-
function getLocalIpAddress() {
|
|
6142
|
-
for (let iface of Object.values(os.networkInterfaces()))for (let alias of iface)if ('IPv4' === alias.family && !alias.internal) return alias.address;
|
|
6143
|
-
return '127.0.0.1';
|
|
6144
|
-
}
|
|
6145
6140
|
function project_ts_decorate(decorators, target, key, desc) {
|
|
6146
6141
|
var d, c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc;
|
|
6147
6142
|
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -6166,7 +6161,10 @@ class ProjectAPI extends BaseAPI {
|
|
|
6166
6161
|
async env() {
|
|
6167
6162
|
let { server } = this.ctx;
|
|
6168
6163
|
return {
|
|
6169
|
-
ip:
|
|
6164
|
+
ip: function() {
|
|
6165
|
+
for (let iface of Object.values(os.networkInterfaces()))for (let alias of iface)if ('IPv4' === alias.family && !alias.internal) return alias.address;
|
|
6166
|
+
return '127.0.0.1';
|
|
6167
|
+
}(),
|
|
6170
6168
|
port: server.port
|
|
6171
6169
|
};
|
|
6172
6170
|
}
|
|
@@ -6293,7 +6291,12 @@ async function openBrowser(url, needEncodeURI = !0) {
|
|
|
6293
6291
|
}
|
|
6294
6292
|
let body_parser = __webpack_require__("../../node_modules/.pnpm/body-parser@2.2.2/node_modules/body-parser/index.js");
|
|
6295
6293
|
var body_parser_default = __webpack_require__.n(body_parser);
|
|
6296
|
-
let server_require = createRequire(import.meta.url)
|
|
6294
|
+
let server_require = createRequire(import.meta.url), LOCAL_HOSTNAMES = new Set([
|
|
6295
|
+
'localhost',
|
|
6296
|
+
'127.0.0.1',
|
|
6297
|
+
'[::1]',
|
|
6298
|
+
'::1'
|
|
6299
|
+
]);
|
|
6297
6300
|
class RsdoctorServer {
|
|
6298
6301
|
constructor(sdk, port = Server.defaultPort, config){
|
|
6299
6302
|
this.sdk = sdk, this.disposed = !0, this.get = (route, cb)=>{
|
|
@@ -6318,7 +6321,7 @@ class RsdoctorServer {
|
|
|
6318
6321
|
return this._server.app;
|
|
6319
6322
|
}
|
|
6320
6323
|
get host() {
|
|
6321
|
-
return
|
|
6324
|
+
return Server.defaultHost;
|
|
6322
6325
|
}
|
|
6323
6326
|
get origin() {
|
|
6324
6327
|
return `http://${this.host}:${this.port}`;
|
|
@@ -6332,14 +6335,52 @@ class RsdoctorServer {
|
|
|
6332
6335
|
get innerClientPath() {
|
|
6333
6336
|
return this._innerClientPath;
|
|
6334
6337
|
}
|
|
6338
|
+
isLocalOrigin(origin) {
|
|
6339
|
+
try {
|
|
6340
|
+
let url = new URL(origin);
|
|
6341
|
+
return ('http:' === url.protocol || 'https:' === url.protocol) && LOCAL_HOSTNAMES.has(url.hostname);
|
|
6342
|
+
} catch {
|
|
6343
|
+
return !1;
|
|
6344
|
+
}
|
|
6345
|
+
}
|
|
6346
|
+
setCorsHeaders(req, res) {
|
|
6347
|
+
let origin = req.headers.origin;
|
|
6348
|
+
return 'string' == typeof origin && !!this.isLocalOrigin(origin) && (res.setHeader('Access-Control-Allow-Origin', origin), res.setHeader('Vary', 'Origin'), res.setHeader('Access-Control-Allow-Headers', 'Content-Type'), res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS'), !0);
|
|
6349
|
+
}
|
|
6350
|
+
createSecurityMiddleware() {
|
|
6351
|
+
return (req, res, next)=>{
|
|
6352
|
+
let isCorsAllowed = this.setCorsHeaders(req, res);
|
|
6353
|
+
if (req.method?.toUpperCase() === 'OPTIONS') {
|
|
6354
|
+
res.statusCode = isCorsAllowed ? 204 : 403, res.end();
|
|
6355
|
+
return;
|
|
6356
|
+
}
|
|
6357
|
+
next();
|
|
6358
|
+
};
|
|
6359
|
+
}
|
|
6360
|
+
async createInnerServer() {
|
|
6361
|
+
let lastError, expectedPort = this.port;
|
|
6362
|
+
for(let retry = 0; retry < 10; retry++){
|
|
6363
|
+
let port = Server.getPortSync(expectedPort, this.host);
|
|
6364
|
+
try {
|
|
6365
|
+
return {
|
|
6366
|
+
port,
|
|
6367
|
+
server: await Server.createServer(port, this.host)
|
|
6368
|
+
};
|
|
6369
|
+
} catch (error) {
|
|
6370
|
+
if ('EADDRINUSE' !== error.code) throw error;
|
|
6371
|
+
lastError = error, expectedPort = port + 1;
|
|
6372
|
+
}
|
|
6373
|
+
}
|
|
6374
|
+
throw lastError;
|
|
6375
|
+
}
|
|
6335
6376
|
async bootstrap() {
|
|
6336
6377
|
if (!this.disposed) return;
|
|
6337
|
-
let port =
|
|
6338
|
-
this.port = port, this._server =
|
|
6378
|
+
let { port, server } = await this.createInnerServer();
|
|
6379
|
+
this.port = port, this._server = server, this._socket = new Socket({
|
|
6339
6380
|
sdk: this.sdk,
|
|
6340
6381
|
server: this._server.server,
|
|
6341
6382
|
port: this.port
|
|
6342
|
-
}), await this._socket.bootstrap(), GlobalConfig.writeMcpPort(this.port, this.sdk.name), logger.debug(`Successfully wrote mcp.json for ${chalk.cyan(this.sdk.name)} builder`), this.disposed = !1, this.app.use(
|
|
6383
|
+
}), await this._socket.bootstrap(), GlobalConfig.writeMcpPort(this.port, this.sdk.name), logger.debug(`Successfully wrote mcp.json for ${chalk.cyan(this.sdk.name)} builder`), this.disposed = !1, this.app.use(this.createSecurityMiddleware()), this.app.use(body_parser_default().json({
|
|
6343
6384
|
limit: '500mb'
|
|
6344
6385
|
}));
|
|
6345
6386
|
let clientHtmlPath = this._innerClientPath ? this._innerClientPath : server_require.resolve('@rsdoctor/client'), clientDistPath = path_0.resolve(clientHtmlPath, '..');
|
|
@@ -6444,7 +6485,7 @@ class RsdoctorServer {
|
|
|
6444
6485
|
if (req.method?.toUpperCase() === method) {
|
|
6445
6486
|
try {
|
|
6446
6487
|
let body = await cb(req, res, next);
|
|
6447
|
-
if (res.
|
|
6488
|
+
if (res.statusCode = 200, Buffer.isBuffer(body)) {
|
|
6448
6489
|
res.setHeader('Content-Length', body.byteLength);
|
|
6449
6490
|
let ps = new PassThrough();
|
|
6450
6491
|
ps.write(body), ps.end(), ps.pipe(res);
|
|
@@ -22,6 +22,10 @@ export declare class RsdoctorServer implements SDK.RsdoctorServerInstance {
|
|
|
22
22
|
get origin(): string;
|
|
23
23
|
get socketUrl(): ISocketType;
|
|
24
24
|
get innerClientPath(): string;
|
|
25
|
+
private isLocalOrigin;
|
|
26
|
+
private setCorsHeaders;
|
|
27
|
+
private createSecurityMiddleware;
|
|
28
|
+
private createInnerServer;
|
|
25
29
|
bootstrap(): Promise<void>;
|
|
26
30
|
protected wrapNextHandleFunction(method: 'GET' | 'POST', cb: (...args: Parameters<Thirdparty.connect.NextHandleFunction>) => Common.PlainObject | string): Thirdparty.connect.NextHandleFunction;
|
|
27
31
|
proxy(api: SDK.ServerAPI.API, method: 'GET' | 'POST', cb: (...args: Parameters<Thirdparty.connect.NextHandleFunction>) => Common.PlainObject | string): void;
|
|
@@ -22,6 +22,10 @@ export declare class RsdoctorServer implements SDK.RsdoctorServerInstance {
|
|
|
22
22
|
get origin(): string;
|
|
23
23
|
get socketUrl(): ISocketType;
|
|
24
24
|
get innerClientPath(): string;
|
|
25
|
+
private isLocalOrigin;
|
|
26
|
+
private setCorsHeaders;
|
|
27
|
+
private createSecurityMiddleware;
|
|
28
|
+
private createInnerServer;
|
|
25
29
|
bootstrap(): Promise<void>;
|
|
26
30
|
protected wrapNextHandleFunction(method: 'GET' | 'POST', cb: (...args: Parameters<Thirdparty.connect.NextHandleFunction>) => Common.PlainObject | string): Thirdparty.connect.NextHandleFunction;
|
|
27
31
|
proxy(api: SDK.ServerAPI.API, method: 'GET' | 'POST', cb: (...args: Parameters<Thirdparty.connect.NextHandleFunction>) => Common.PlainObject | string): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsdoctor/sdk",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.15",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/web-infra-dev/rsdoctor",
|
|
@@ -32,10 +32,10 @@
|
|
|
32
32
|
"safer-buffer": "2.1.2",
|
|
33
33
|
"socket.io": "4.8.1",
|
|
34
34
|
"tapable": "2.3.3",
|
|
35
|
-
"@rsdoctor/client": "1.5.
|
|
36
|
-
"@rsdoctor/
|
|
37
|
-
"@rsdoctor/
|
|
38
|
-
"@rsdoctor/graph": "1.5.
|
|
35
|
+
"@rsdoctor/client": "1.5.15",
|
|
36
|
+
"@rsdoctor/types": "1.5.15",
|
|
37
|
+
"@rsdoctor/utils": "1.5.15",
|
|
38
|
+
"@rsdoctor/graph": "1.5.15"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/body-parser": "1.19.6",
|