badmfck-api-server 3.9.86 → 3.9.88
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/apiServer/APIService.d.ts +0 -1
- package/dist/apiServer/APIService.js +1 -2
- package/dist/apiServer/BaseEndpoint.js +2 -2
- package/dist/apiServer/structures/DefaultErrors.d.ts +4 -3
- package/dist/apiServer/structures/DefaultErrors.js +5 -4
- package/package.json +1 -1
- package/dist/apiServer/APIService.js.map +0 -1
- package/dist/apiServer/BaseEndpoint.js.map +0 -1
- package/dist/apiServer/BaseService.js.map +0 -1
- package/dist/apiServer/ClusterService.d.ts +0 -30
- package/dist/apiServer/ClusterService.js +0 -81
- package/dist/apiServer/ClusterService.js.map +0 -1
- package/dist/apiServer/DocumentService.js.map +0 -1
- package/dist/apiServer/HUBService.d.ts +0 -37
- package/dist/apiServer/HUBService.js +0 -132
- package/dist/apiServer/HUBService.js.map +0 -1
- package/dist/apiServer/LocalRequest.js.map +0 -1
- package/dist/apiServer/LogService.js.map +0 -1
- package/dist/apiServer/MysqlService.js.map +0 -1
- package/dist/apiServer/WSAPITransport.js.map +0 -1
- package/dist/apiServer/WebSocketHandler.js.map +0 -1
- package/dist/apiServer/Websocket.d.ts +0 -8
- package/dist/apiServer/Websocket.js +0 -15
- package/dist/apiServer/WebsocketService.d.ts +0 -8
- package/dist/apiServer/WebsocketService.js +0 -18
- package/dist/apiServer/WebsocketService.js.map +0 -1
- package/dist/apiServer/cluster/HUBConnection.d.ts +0 -39
- package/dist/apiServer/cluster/HUBConnection.js +0 -251
- package/dist/apiServer/cluster/HUBConnection.js.map +0 -1
- package/dist/apiServer/cluster/HUBHandlres.d.ts +0 -0
- package/dist/apiServer/cluster/HUBHandlres.js +0 -2
- package/dist/apiServer/cluster/HUBHandlres.js.map +0 -1
- package/dist/apiServer/deployment/Deployment.js.map +0 -1
- package/dist/apiServer/helper/DataProvider.js.map +0 -1
- package/dist/apiServer/helper/Sleep.js.map +0 -1
- package/dist/apiServer/helper/UID.js.map +0 -1
- package/dist/apiServer/helper/Validator.js.map +0 -1
- package/dist/apiServer/monitor/Monitor.js.map +0 -1
- package/dist/apiServer/routes/Liveness.js.map +0 -1
- package/dist/apiServer/routes/Monitor.d.ts +0 -9
- package/dist/apiServer/routes/Monitor.js +0 -77
- package/dist/apiServer/routes/Readiness.js.map +0 -1
- package/dist/apiServer/structures/DefaultErrors.js.map +0 -1
- package/dist/apiServer/structures/HTTPStatus.js.map +0 -1
- package/dist/apiServer/structures/Interfaces.js.map +0 -1
- /package/dist/apiServer/helper/{zipUtils.d.ts → ZipUtils.d.ts} +0 -0
- /package/dist/apiServer/helper/{zipUtils.js → ZipUtils.js} +0 -0
@@ -48,7 +48,6 @@ type InferInterceptor<T> = T extends IInterceptor<infer U> ? U : unknown;
|
|
48
48
|
export declare const getDefaultOptions: <I extends IInterceptor<any> | undefined>(overrides?: (Omit<Partial<APIServiceOptions<InferInterceptor<NonNullable<I>>>>, "interceptor"> & {
|
49
49
|
interceptor?: I | undefined;
|
50
50
|
}) | undefined) => APIServiceOptions<InferInterceptor<NonNullable<I>>>;
|
51
|
-
export declare const REQ_DEPREACTED_CREATE_NET_LOG: Req<void, APIServiceNetworkLogItem>;
|
52
51
|
export declare const REQ_HTTP_LOG: Req<void, APIServiceNetworkLogItem[]>;
|
53
52
|
export declare const REQ_HTTP_REQUESTS_COUNT: Req<void, number>;
|
54
53
|
export declare const REQ_HTTP_SERVER: Req<void, {
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
27
27
|
};
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
29
|
-
exports.APIService = exports.Initializer = exports.REQ_DOC_USERS = exports.REQ_MONITOR_USERS = exports.REQ_INTERNAL_CALL = exports.REQ_HTTP_SERVER = exports.REQ_HTTP_REQUESTS_COUNT = exports.REQ_HTTP_LOG = exports.
|
29
|
+
exports.APIService = exports.Initializer = exports.REQ_DOC_USERS = exports.REQ_MONITOR_USERS = exports.REQ_INTERNAL_CALL = exports.REQ_HTTP_SERVER = exports.REQ_HTTP_REQUESTS_COUNT = exports.REQ_HTTP_LOG = exports.getDefaultOptions = void 0;
|
30
30
|
const express_1 = __importDefault(require("express"));
|
31
31
|
const BaseService_1 = require("./BaseService");
|
32
32
|
const cors_1 = __importDefault(require("cors"));
|
@@ -72,7 +72,6 @@ const getDefaultOptions = (overrides) => {
|
|
72
72
|
return { ...base, ...overrides };
|
73
73
|
};
|
74
74
|
exports.getDefaultOptions = getDefaultOptions;
|
75
|
-
exports.REQ_DEPREACTED_CREATE_NET_LOG = new badmfck_signal_1.Req(undefined, "REQ_CREATE_NET_LOG");
|
76
75
|
exports.REQ_HTTP_LOG = new badmfck_signal_1.Req(undefined, "REQ_HTTP_LOG");
|
77
76
|
exports.REQ_HTTP_REQUESTS_COUNT = new badmfck_signal_1.Req(undefined, "REQ_HTTP_REQUESTS_COUNT");
|
78
77
|
exports.REQ_HTTP_SERVER = new badmfck_signal_1.Req(undefined, "REQ_HTTP_SERVER");
|
@@ -122,10 +122,10 @@ class BaseEndpoint {
|
|
122
122
|
if (!structure)
|
123
123
|
return;
|
124
124
|
if (typeof structure === "object" && (!req.data || typeof req.data !== "object"))
|
125
|
-
throw { ...DefaultErrors_1.default.
|
125
|
+
throw { ...DefaultErrors_1.default.WRONG_PARAMS, details: "empty or invalid request" };
|
126
126
|
const report = await Validator_1.Validator.validateStructure(structure, req.data);
|
127
127
|
if (report)
|
128
|
-
throw { ...DefaultErrors_1.default.
|
128
|
+
throw { ...DefaultErrors_1.default.WRONG_PARAMS, details: report };
|
129
129
|
Validator_1.Validator.filterStructure(structure, req.data);
|
130
130
|
}
|
131
131
|
createStream(req) {
|
@@ -15,15 +15,16 @@ declare class DefaultErrors {
|
|
15
15
|
static FORBIDDEN: IError;
|
16
16
|
static NOT_FOUND: IError;
|
17
17
|
static INTERNAL_SERVER_ERROR: IError;
|
18
|
-
static EXTERNAL_SERVICE_ERROR: IError;
|
19
|
-
static MAINTENANCE_MODE: IError;
|
20
|
-
static CONFLICT: IError;
|
21
18
|
static INVALID_TOKEN: IError;
|
22
19
|
static INVALID_CREDENTIALS: IError;
|
23
20
|
static INVALID_DATA: IError;
|
24
21
|
static INVALID_FILE: IError;
|
22
|
+
static EXTERNAL_SERVICE_ERROR: IError;
|
23
|
+
static MAINTENANCE_MODE: IError;
|
24
|
+
static CONFLICT: IError;
|
25
25
|
static WRONG_DATA_TYPE: IError;
|
26
26
|
static UPROCESSIABLE_CONTENT: IError;
|
27
|
+
static WRONG_PARAMS: IError;
|
27
28
|
}
|
28
29
|
export declare class ErrorUtils {
|
29
30
|
static isError(obj: any): obj is IError;
|
@@ -18,15 +18,16 @@ class DefaultErrors {
|
|
18
18
|
static FORBIDDEN = { code: 12, message: "Forbidden", httpStatus: 403 };
|
19
19
|
static NOT_FOUND = { code: 13, message: "Not found", httpStatus: 404 };
|
20
20
|
static INTERNAL_SERVER_ERROR = { code: 14, message: "Internal server error.", httpStatus: 500 };
|
21
|
-
static EXTERNAL_SERVICE_ERROR = { code: 19, message: "External service error", httpStatus: 502 };
|
22
|
-
static MAINTENANCE_MODE = { code: 21, message: "Service in maintenance mode", httpStatus: 503 };
|
23
|
-
static CONFLICT = { code: 22, message: "Conflict", httpStatus: 409 };
|
24
21
|
static INVALID_TOKEN = { code: 15, message: "Invalid token", httpStatus: 401 };
|
25
22
|
static INVALID_CREDENTIALS = { code: 16, message: "Invalid credentials", httpStatus: 401 };
|
26
23
|
static INVALID_DATA = { code: 17, message: "Invalid data", httpStatus: 422 };
|
27
24
|
static INVALID_FILE = { code: 18, message: "Invalid file", httpStatus: 422 };
|
25
|
+
static EXTERNAL_SERVICE_ERROR = { code: 19, message: "External service error", httpStatus: 502 };
|
26
|
+
static MAINTENANCE_MODE = { code: 21, message: "Service in maintenance mode", httpStatus: 503 };
|
27
|
+
static CONFLICT = { code: 22, message: "Conflict", httpStatus: 409 };
|
28
28
|
static WRONG_DATA_TYPE = { code: 23, message: "Wrong data type", httpStatus: 422 };
|
29
|
-
static UPROCESSIABLE_CONTENT = { code:
|
29
|
+
static UPROCESSIABLE_CONTENT = { code: 24, message: "Unprocessable content", httpStatus: 422 };
|
30
|
+
static WRONG_PARAMS = { code: 25, message: "Wrong params", httpStatus: 400 };
|
30
31
|
}
|
31
32
|
class ErrorUtils {
|
32
33
|
static isError(obj) {
|
package/package.json
CHANGED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"APIService.js","sourceRoot":"","sources":["../../src/apiServer/APIService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAAwD;AACxD,+CAAyD;AACzD,gDAAuB;AAEvB,iDAA4D;AAC5D,4EAAsE;AAEtE,mDAAkC;AAClC,6CAAyD;AACzD,+CAA2C;AAC3C,gDAAuB;AACvB,oDAA4B;AAC5B,4CAAmB;AACnB,4EAA2C;AAC3C,4CAAmB;AACnB,gDAA4C;AAC5C,kDAA8C;AAC9C,gDAAuB;AAiCvB,SAAgB,iBAAiB;IAChC,OAAO;QACN,IAAI,EAAE,IAAI;QACV,YAAY,EAAE,OAAO;QACrB,iBAAiB,EAAE;YAClB,uBAAuB;SACvB;QACD,SAAS,EAAE,EAAE;QACb,SAAS,EAAC,MAAM;QAChB,YAAY,EAAE,UAAU,GAA6B;YACpD,IAAA,oBAAO,EAAC,kBAAkB,EAAC,GAAG,CAAC,CAAA;QAChC,CAAC;QACD,OAAO,EAAC,UAAS,GAAO;YACvB,IAAA,qBAAQ,EAAC,kBAAkB,EAAC,GAAG,CAAC,CAAC;QAClC,CAAC;QACD,uBAAuB,EAAC,KAAK;QAC7B,SAAS,EAAC,EAAE,GAAC,IAAI,GAAC,IAAI;QACtB,WAAW,EAAC,cAAI,CAAC,OAAO,CAAC,YAAE,CAAC,MAAM,EAAE,EAAC,aAAa,CAAC;KACnD,CAAA;AACF,CAAC;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,IAAI,IAAI,EAAC;gBACjB,MAAM,CAAC,CAAC,CAAC,GAAC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,EAAC,MAAM,CAAC,CAAC,CAAC,EAAC,GAAG,GAAC,CAAC,CAAC,CAAC;gBACxD,MAAM,EAAE,CAAC;gBACT,IAAG,MAAM,IAAE,CAAC,EAAC;oBACZ,MAAM,CAAC,KAAK,CAAC,GAAC,aAAa,GAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA,CAAC,CAAA,IAAI,CAAC,MAAM,CAAA,CAAC,CAAA,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC;oBACrF,MAAM;iBACN;aACD;SACD;QACD,OAAO,MAAM,IAAI,IAAI,CAAC;IACvB,CAAC;;AAvcF,gCAycC","sourcesContent":["import express, { Application, Response } from 'express'\nimport { BaseService, IBaseService } from './BaseService'\nimport cors from 'cors'\nimport { IncomingMessage } from 'http'\nimport { BaseEndpoint, IBaseEndpoint } from './BaseEndpoint'\nimport DefaultErrors, { ErrorUtils } from './structures/DefaultErrors'\nimport { HTTPRequestVO, IError, TransferPacketVO } from './structures/Interfaces'\nimport {Req} from \"badmfck-signal\"\nimport { logCrit, logError, logInfo } from './LogService'\nimport { Monitor } from './monitor/Monitor'\nimport path from \"path\"\nimport crypto from \"crypto\";\nimport fs from \"fs\"\nimport fileUpload from 'express-fileupload'\nimport os from \"os\"\nimport { Liveness } from './routes/Liveness'\nimport { Readiness } from './routes/Readiness'\nimport http from 'http'\n\nexport interface APIServiceNetworkLogItem{\t\n\tid:number,\n\tcreated:number,\n\ttime:number,\n\treferer?:string,\n\trequest:{[key:string]:any},\n\tresponse:{[key:string]:any}\n\terror?:string|null\n}\n\nexport interface APIServiceOptions{\n\tport:number,\n\tbaseEndPoint:string // \"/api/\"\n\tcorsHostWhiteList:string[],\n\tendpoints:IBaseEndpoint[],\n\tjsonLimit:string // \"10mb\"\n\tonNetworkLog?:((log:APIServiceNetworkLogItem)=>void)|null\n\tonError?:((...rest:any[])=>void)|null\n\tisProductionEnvironment:boolean,\n\tinterceptor?:IBaseEndpoint,\n\tpostproducer?:(req:HTTPRequestVO|undefined|null,res:Response,data:TransferPacketVO<any>,requestTime:number,endpoint?:string,log?:APIServiceNetworkLogItem|null)=>Promise<TransferPacketVO>\n\tpreproducer?:(req:HTTPRequestVO|undefined|null)=>any\n\t\n\tmonitor?:{login:string,password:string}[]\n\t//deployment?:{login:string,password:string}\n\tappVersion?:string\n\n\tfileTempDir:string;\n\tfileLimit:number // b\n}\n\nexport function getDefaultOptions():APIServiceOptions{\n\treturn {\n\t\tport: 8091,\n\t\tbaseEndPoint: '/api/',\n\t\tcorsHostWhiteList: [\n\t\t\t'http://localhost:3000',\n\t\t],\n\t\tendpoints: [],\n\t\tjsonLimit:\"10mb\",\n\t\tonNetworkLog: function (log: APIServiceNetworkLogItem): void {\n\t\t\tlogInfo(\"${APIService.js}\",log)\n\t\t},\n\t\tonError:function(err:any){\n\t\t\tlogError(\"${APIService.js}\",err);\n\t\t},\n\t\tisProductionEnvironment:false,\n\t\tfileLimit:50*1024*1024,\n\t\tfileTempDir:path.resolve(os.tmpdir(),\"fileTempDir\")\n\t}\n}\n\nexport const REQ_CREATE_NET_LOG:Req<void,APIServiceNetworkLogItem> = new Req(undefined,\"REQ_CREATE_NET_LOG\");\nexport const REQ_HTTP_LOG:Req<void,APIServiceNetworkLogItem[]> = new Req(undefined,\"REQ_HTTP_LOG\");\nexport const REQ_HTTP_REQUESTS_COUNT:Req<void,number> = new Req(undefined,\"REQ_HTTP_REQUESTS_COUNT\");\nexport const REQ_HTTP_SERVER:Req<void,{express:Application,http:http.Server}> = new Req(undefined,\"REQ_HTTP_SERVER\");\nexport const REQ_INTERNAL_CALL:Req<HTTPRequestVO,IError|any> = new Req(undefined,\"REQ_INTERNAL_CALL\");\n\n\nconst activeServices:String[]=[]\nconst entryPoints:String[]=[]\n\nexport async function Initializer(services:IBaseService[]){\n for (let i of services) { await i.init();activeServices.push(i.getName()) }\n for (let i of services) { i.applicationReady() }\n}\n\nexport class APIService extends BaseService {\n\n\t// NET LOG\n\tprivate static nextLogID=0;\n\tprivate version = \"2.4.9\"\n\tprivate options:APIServiceOptions;\n\tprivate monitor?:Monitor\n\tprivate monitorIndexFile?:Buffer\n\tprivate started:Date = new Date();\n\tprivate requestsCount=0;\n\tprivate server=http\n\n\tnetLog:APIServiceNetworkLogItem[]=[];\n\n\tconstructor(options?:APIServiceOptions|null) {\n\t\tsuper('HTTP Service')\n\t\tthis.options=options ?? getDefaultOptions();\n\t\tif(!this.options.corsHostWhiteList)\n\t\t\tthis.options.corsHostWhiteList=[];\n\t\tconst self = \"http://localhost:\"+this.options.port;\n\t\tif(!this.options.corsHostWhiteList.find(val=>val===self))\n\t\t\tthis.options.corsHostWhiteList.push()\n\n\t\tif(this.options.monitor && this.options.monitor.length>0){\n\t\t\tthis.monitor=new Monitor();\n\t\t\tthis.options.endpoints.push(this.monitor)\n\t\t\tconsole.warn(\"Service Monitor initialized\")\n\t\t\tconsole.warn(\"monitor links:\")\n\t\t\tfor(let i of this.options.monitor){\n\t\t\t\tconst hash = crypto.createHash(\"sha256\").update(i.login+i.password).digest().toString(\"hex\")\n\t\t\t\tconsole.warn(i.login+\" -> /sm-\"+hash)\t\t\t\t\t\t\n\t\t\t}\n\t\t}\n\n\t\t// create liveness, readiness\n\t\tthis.options.endpoints.push(new Liveness(this.started),new Readiness(this.started))\n\t\tREQ_HTTP_REQUESTS_COUNT.listener = async () => this.requestsCount;\n\t}\n\n\n\toverride async init(): Promise<void> {\n\n\t\tREQ_HTTP_LOG.listener=async ignore=>this.netLog;\n\t\tREQ_CREATE_NET_LOG.listener = async ignore=>{\n\t\t\tconst log:APIServiceNetworkLogItem = {\n\t\t\t\tcreated: +new Date(),\n\t\t\t\ttime: 0,\n\t\t\t\trequest: {},\n\t\t\t\tresponse: {},\n\t\t\t\terror:null,\n\t\t\t\tid: APIService.nextLogID++\n\t\t\t}\n\t\t\tthis.netLog.push(log)\n\t\t\tif(this.netLog.length>1000)\n\t\t\t\tthis.netLog.shift()\n\t\t\treturn log;\n\t\t}\n\n\t\t// internal call\n\t\tREQ_INTERNAL_CALL.listener = async (req)=>{\n\t\t\tfor(let i of this.options.endpoints){\n\t\t\t\tif(!i || !i.endpoints)\n\t\t\t\t\tcontinue;\n\t\t\t\tfor(let j of i.endpoints){\n\t\t\t\t\tlet ep = BaseEndpoint.getEntryPoint()+j.endpoint;\n\t\t\t\t\tep = ep.replaceAll(\"//\",\"/\")\n\t\t\t\t\tif(ep=== req.endpoint){\n\t\t\t\t\t\tconst response = await i.execute(req)\n\t\t\t\t\t\tif(response.error)\n\t\t\t\t\t\t\treturn response.error;\n\t\t\t\t\t\treturn response.data;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn {error:DefaultErrors.UNKNOWN_REQUEST,data:null,httpStatus:404}\n\t\t}\n\n\t\t// initialize express\n\t\tconst app = express()\n\t\tconst server = http.createServer(app);\n\n\t\tREQ_HTTP_SERVER.listener = async ignore=>{return {express:app,http:server}};\n\n\t\tif(this.options.isProductionEnvironment)\n\t\t\tapp.set(\"env\",'production');\n\n\t\tapp.use(express.json({ limit: '10mb' })) // for parsing application/json\n\t\tapp.use(express.urlencoded({ limit: '10mb', extended: true })) // for parsing application/x-www-form-urlencoded\n\n\t\tapp.use(fileUpload({\n\t\t\tlimitHandler: (req, res, next)=>{\n\t\t\t\tthis.sendResponse(req.get(\"Referer\")??\"\",res,{\n\t\t\t\t\terror:DefaultErrors.FILE_TOO_LARGE,\n\t\t\t\t\tdata:null,\n\t\t\t\t\thttpStatus:413,\n\t\t\t\t},+new Date(),req.path);\n\t\t\t},\n\t\t\tlimits: { fileSize: this.options.fileLimit },\n\t\t\tuseTempFiles: true,\n\t\t\turiDecodeFileNames: true,\n\t\t\ttempFileDir: this.options.fileTempDir,\n\t\t\t//safeFileNames: true,\n\t\t\tabortOnLimit:true\n\t\t}))\n\n\t\tapp.use(async (err:any,req:any,resp:any,next:any)=>{\n\t\t\t\n\t\t\tif(!err){\n\t\t\t\tnext();\n\t\t\t\treturn\n\t\t\t}\n\t\t\t\t//request start time\n\t\t\tconst tme = +new Date();\n\t\t\tconst log = await REQ_CREATE_NET_LOG.request();\n\t\t\tlog.request={\n\t\t\t\tmethod:req.method,\n\t\t\t\tdata:\"\",\n\t\t\t\tparams:req.params\n\t\t\t}\n\n\t\t\tlet responseError=DefaultErrors.UNKNOWN_REQUEST;\n\t\t\tif (typeof err === \"object\" && err.status === 400 && 'body' in err && err.type === 'entity.parse.failed') {\n\t\t\t\tresponseError = DefaultErrors.JSON_MALFORMED\n\t\t\t}\n \n\n\t\t\tthis.sendResponse(req.get(\"Referer\")??\"\",resp,{\n\t\t\t\terror:responseError,\n\t\t\t\tdata:null,\n\t\t\t\thttpStatus:400\n\t\t\t},tme,\"\",log)\n\n\t\t})\n\n\t\tconst corsOptions = {\n\t\t\torigin: (origin: any, callback: any) => {\n\t\t\t\tconst originIsWhitelisted = this.options.corsHostWhiteList.includes(origin)\n\t\t\t\tcallback(null, originIsWhitelisted)\n\t\t\t},\n\t\t\tcredentials: true\n\t\t}\n\t\tapp.use(cors(corsOptions))\n\n\t\t// registrate endpoints\n\t\tBaseEndpoint.setEntryPoint(this.options.baseEndPoint)\n\t\t\n\t\tfor(let i of this.options.endpoints){\n\t\t\tawait i.init();\n\t\t\tif(!i.endpoints)\n\t\t\t\tcontinue;\n\t\t\tfor(let j of i.endpoints){\n\t\t\t\tlet ep = BaseEndpoint.getEntryPoint()+j.endpoint;\n\t\t\t\tep = ep.replaceAll(\"//\",\"/\")\n\t\t\t\t\n\n\t\t\t\t// incoming request\n\t\t\t\tapp.all(ep,async (req,res)=>{\n\t\t\t\t\tthis.requestsCount++;\n\t\t\t\t\tconst tme = +new Date();\n\t\t\t\t\tlet log:APIServiceNetworkLogItem|null = null;\n\t\t\t\t\tif(!i.ignoreHttpLogging){\n\t\t\t\t\t\tlog = await REQ_CREATE_NET_LOG.request();\n\t\t\t\t\t\tlog.request={\n\t\t\t\t\t\t\turl:req.url,\n\t\t\t\t\t\t\tmethod:req.method,\n\t\t\t\t\t\t\tdata:this.checkDataLength(req.body),\n\t\t\t\t\t\t\tparams:this.checkDataLength(req.params)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tconst execute = async ()=>{\n\n\t\t\t\t\t\tconst body = req.body;\n\t\t\t\t\t\tif(req.query && typeof req.query === \"object\"){\n\t\t\t\t\t\t\tfor(let i in req.query){\n\t\t\t\t\t\t\t\tbody[i]=req.query[i];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst httpRequest:HTTPRequestVO = {\n\t\t\t\t\t\t\traw:req as IncomingMessage,\n\t\t\t\t\t\t\tmethod:req.method,\n\t\t\t\t\t\t\tdata:req.body,\n\t\t\t\t\t\t\tparams:req.params,\n\t\t\t\t\t\t\theaders:req.headers as any,\n\t\t\t\t\t\t\tendpoint:ep,\n\t\t\t\t\t\t\tfiles:req.files ?? null,\n\t\t\t\t\t\t\treferer:req.get(\"Referer\"),\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif(this.options.preproducer){\n\t\t\t\t\t\t\ttry{\n\t\t\t\t\t\t\tconst preproducerResult = await this.options.preproducer(httpRequest);\n\t\t\t\t\t\t\tif(preproducerResult)\n\t\t\t\t\t\t\t\thttpRequest.preproducerResult = preproducerResult;\n\t\t\t\t\t\t\t}catch(e){\n\t\t\t\t\t\t\t\tthis.sendResponse(req.get(\"Referer\")??\"\",res,{error:{code:10002,message:\"Internal server error\",details:`${e}`},data:null,httpStatus:500},tme,ep,log,httpRequest);\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tlet result\n\t\t\t\t\t\ttry{\n\t\t\t\t\t\t\t// Execute interceptor if exists\n\t\t\t\t\t\t\tif(!j.ignoreInterceptor){\n\t\t\t\t\t\t\t\tlet interceptorResult;\n\t\t\t\t\t\t\t\tif(this.options.interceptor){\n\t\t\t\t\t\t\t\t\tinterceptorResult=await this.options.interceptor.execute(httpRequest);\n\t\t\t\t\t\t\t\t\tif(interceptorResult.error && !j.allowInterceptorError){\n\t\t\t\t\t\t\t\t\t\tthis.sendResponse(req.get(\"Referer\")??\"\",res,interceptorResult,tme,ep,log,httpRequest);\n\t\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\thttpRequest.interceptorResult = interceptorResult\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// Precheck\n\t\t\t\t\t\t\tif(i === this.monitor)\n\t\t\t\t\t\t\t\thttpRequest.precheck={data:this.options.monitor}\n\n\t\t\t\t\t\t\tconst precheck=await i.precheck(httpRequest)\n\t\t\t\t\t\t\tif(precheck && precheck.error){\n\t\t\t\t\t\t\t\tthis.sendResponse(req.get(\"Referer\")??\"\",res,precheck,tme,ep,log,httpRequest);\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\thttpRequest.precheck=precheck;\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t// If interceptor has no errors, execute main handler\n\t\t\t\t\t\t\tresult = await i.execute(httpRequest)\n\t\t\t\t\t\t\t \n\t\t\t\t\t\t}catch(e){\n\t\t\t\t\t\t\tconsole.error(e);\n\t\t\t\t\t\t\tif(this.options.onError)\n\t\t\t\t\t\t\t\tthis.options.onError(e)\n\t\t\t\t\t\t\tif(this.monitor)\n\t\t\t\t\t\t\t\tthis.monitor.registrateFatalError(ep);\n\t\t\t\t\t\t\tthis.sendResponse(req.get(\"Referer\")??\"\",res,{\n\t\t\t\t\t\t\t\thttpStatus:500,\n\t\t\t\t\t\t\t\terror:{\n\t\t\t\t\t\t\t\t\tcode:10002,\n\t\t\t\t\t\t\t\t\tmessage:\"Internal server error\",\n\t\t\t\t\t\t\t\t\tdetails:`${e}`\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t},tme,ep,log,httpRequest);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.sendResponse(req.get(\"Referer\")??\"\",res,result,tme,ep,log,httpRequest);\n\t\t\t\t\t}\n\n\t\t\t\t\texecute()\n\t\t\t\t});// handle incoming request\n\n\t\t\t}\n\t\t}\n\n\t\n\n\t\t// final handler\n\t\tapp.use((req, res, next) => {\n\t\t\t\n\t\t\tconst tme = +new Date()\n\n\t\t\tif(this.monitor && this.options && this.options.monitor){\n\t\t\t\t//check if requesting monitor\n\t\t\t\tif(req.method===\"GET\"){\n\t\t\t\t\t\n\t\t\t\t\tlet monitorRequest=false;\n\t\t\t\t\tfor(let i of this.options.monitor){\n\t\t\t\t\t\tconst hash = crypto.createHash(\"sha256\").update(i.login+i.password).digest().toString(\"hex\")\n\t\t\t\t\t\tif(req.originalUrl.endsWith(\"/sm-\"+hash)){\n\t\t\t\t\t\t\tmonitorRequest=true;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif(monitorRequest){\n\t\t\t\t\t\t// send index Thu, 16 Nov 2023 23:33:35 GMT\n\t\t\t\t\t\tconst date = new Date();\n\t\t\t\t\t\ttry{\n\t\t\t\t\t\t\tif(!this.monitorIndexFile)\n\t\t\t\t\t\t\tthis.monitorIndexFile = fs.readFileSync(path.resolve(__dirname,\"monitor\",\"index.html\"));\n\t\t\t\t\t\t\tres.setHeader(\"Content-Type\",\"text/html\")\n\t\t\t\t\t\t\tres.setHeader(\"Content-Length\",this.monitorIndexFile.byteLength)\n\t\t\t\t\t\t\tres.status(200).send(this.monitorIndexFile);\n\t\t\t\t\t\t}catch(e){\n\t\t\t\t\t\t\tthis.sendResponse(req.get(\"Referer\")??\"\",res,{\n\t\t\t\t\t\t\t\terror:{\n\t\t\t\t\t\t\t\t\tcode:10002,\n\t\t\t\t\t\t\t\t\tmessage:\"Internal server error\",\n\t\t\t\t\t\t\t\t\tdetails:`${e}`\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tdata:null,\n\t\t\t\t\t\t\t\thttpStatus:500\n\t\t\t\t\t\t\t},tme,req.path);\t\t\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t\n\t\t\tthis.sendResponse(req.get(\"Referer\")??\"\",res,{\n\t\t\t\terror:DefaultErrors.UNKNOWN_REQUEST,\n\t\t\t\tdata:null,\n\t\t\t\thttpStatus:404\n\t\t\t},tme,req.path);\n\t\t})\n\n\t\tserver.listen(this.options.port, () => {\n\t\t\tlogCrit('${APIService.js}','API Service started at: '+this.options.port+\", with base endpoint:\"+this.options.baseEndPoint+\", ver.: \"+this.version)\n\t\t})\n\n\t\t/*app.listen(this.options.port, () => {\n\t\t\tlogCrit('${APIService.js}','API Service started at: '+this.options.port+\", with base endpoint:\"+this.options.baseEndPoint+\", ver.: \"+this.version)\n\t\t})*/\n\t}\n\n\tasync sendResponse(ref:string,res:Response,data:TransferPacketVO<any>,requestTime:number,endpoint?:string,log?:APIServiceNetworkLogItem|null,req?:HTTPRequestVO){\n\n\t\tif(this.options.postproducer){\n\t\t\ttry{\n\t\t\t\tdata = await this.options.postproducer(req,res,data,requestTime,endpoint,log);\n\t\t\t}catch(e){\n\t\t\t\tlogError(\"Postproducer error\",e)\n\t\t\t}\n\t\t}\n\n\t\tif(ErrorUtils.isError(data))\n\t\t\tdata = {error:data as IError,data:null}\n\t\t\n data.responseTime = (+new Date()) - requestTime;\n data.core = this.version\n data.endpoint = endpoint ?? \"no_endpoint\"\n\t\t\n\t\tif(this.options.appVersion)\n\t\t\tdata.version=this.options.appVersion\n\n\t\t\n\t\tif(log){\n\t\t\tlog.time = data.responseTime\n\t\t\tlog.referer=ref;\n\t\t}\n\n\t\tif(this.monitor)\n\t\t\tthis.monitor.registrateResponse(data.endpoint,data.responseTime)\n\n if(res.destroyed || res.closed){\n\n\t\t\tif(log)\n\t\t\t\tlog.error = \"Connection already closed, can't send response for: \"+data.endpoint\n\t\t\tif(this.options.onError)\n \tthis.options.onError(\"Connection already closed, can't send response: \"+data.endpoint,data)\n \n\t\t\tif(this.monitor)\n\t\t\t\tthis.monitor.registrateError(data.endpoint);\n\n }else{\n\t\t\ttry{\n\n\t\t\t\tif(data.file){\n\n\t\t\t\t\tres.sendFile(data.file,err=>{\n\t\t\t\t\t\tif(err){\n\t\t\t\t\t\t\tif(log)\n\t\t\t\t\t\t\t\tlog.error = \"Can't send file: \"+data.file\n\t\t\t\t\t\t\tif(this.options.onError)\n\t\t\t\t\t\t\t\tthis.options.onError(\"Can't send file: \"+data.file,err)\n\t\t\t\t\t\t\tif(this.monitor && data.endpoint)\n\t\t\t\t\t\t\t\tthis.monitor.registrateAPIError(data.endpoint);\n\n\t\t\t\t\t\t\tthis.sendResponse(ref,res,{\n\t\t\t\t\t\t\t\terror:DefaultErrors.CANT_SEND_FILE,\n\t\t\t\t\t\t\t\tdata:null,\n\t\t\t\t\t\t\t\thttpStatus:500\n\t\t\t\t\t\t\t},requestTime,data.endpoint);\n\t\t\t\t\t\t}\n\t\t\t\t\t\t\n\t\t\t\t\t})\n\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif(data.redirect){\n\t\t\t\t\tres.redirect(data.redirect);\n\t\t\t\t\tif(log)\n\t\t\t\t\t\tlog.response = {redirect:data.redirect}\n\t\t\t\t}else{\n\t\t\t\t\t// setup headers\n\t\t\t\t\tif(data.headers){\n\t\t\t\t\t\tfor(let i in data.headers)\n\t\t\t\t\t\t\tres.setHeader(i,data.headers[i]);\n\t\t\t\t\t}\n\n\t\t\t\t\tif(data.error && data.error.httpStatus && data.error.httpStatus>99)\n\t\t\t\t\t\tres.statusCode = data.error.httpStatus\n\t\t\t\t\telse\n\t\t\t\t\t\tres.statusCode=data.httpStatus ?? 200\n\t\t\t\t\t\n\t\t\t\t\tif(data.rawResponse){\n\t\t\t\t\t\tres.send(data.data)\n\t\t\t\t\t\tif(log)\n\t\t\t\t\t\t\tlog.response = this.checkDataLength(data)\n\t\t\t\t\t}\n\t\t\t\t\telse{\n\t\t\t\t\t\tres.send(data);\n\t\t\t\t\t\tif(log)\n\t\t\t\t\t\t\tlog.response = this.checkDataLength(data)\n\n\t\t\t\t\t\tif(data.error && this.monitor)\n\t\t\t\t\t\t\tthis.monitor.registrateAPIError(data.endpoint)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}catch(e){\n\t\t\t\tif(this.options.onError)\n\t\t\t\t\tthis.options.onError(\"Can't send response\",e);\n\t\t\t\tif(log)\n\t\t\t\t\tlog.error=\"Can't send response\"\n\t\t\t\tif(this.monitor)\n\t\t\t\t\tthis.monitor.registrateError(data.endpoint);\n\t\t\t}\n\t\t}\n\n\t\t// show log\n\t\tif(this.options.onNetworkLog && log)\n\t\t\tthis.options.onNetworkLog(log)\n }\n\n\n\tcheckDataLength(data:any,result?:any,lvl?:number):any{\n\t\t\n\t\tif(!lvl)\n\t\t\tlvl=0;\n\n\t\tif(typeof data !== \"object\"){\n\t\t\tif(typeof data===\"string\" && data.length>1024)\n\t\t\t\treturn data.substring(0,1000)+\"... (total:\" + data.length + \")\"\n\t\t\treturn data;\n\t\t}\n\n\t\tif(typeof data === \"object\"){\n\t\t\tif(!result)\n\t\t\t\tresult={};\n\t\t\tlet arrcnt = 100;\n\t\t\tfor(let i in data){\n\t\t\t\tresult[i]=this.checkDataLength(data[i],result[i],lvl+1);\n\t\t\t\tarrcnt--;\n\t\t\t\tif(arrcnt<=0){\n\t\t\t\t\tresult[\"...\"]=\"... total: \"+Array.isArray(data)?data.length:Object.keys(data).length;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn result ?? null;\n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OAAO,CAAC,CAAC,CAAC;YAC1H,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,GAAC,uBAAuB,GAAC,CAAC,CAAC,CAAC,iBAAiB,IAAI,OAAO,CAAC,CAAC,CAAA;SACxG;IACL,CAAC;IAAA,CAAC;IAEF,0BAA0B;QACtB,OAAO,IAAI,CAAC,sBAAsB,CAAC;IACvC,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,GAAiB,IAAsC,OAAO,IAAI,CAAA,CAAA,CAAC;IAElF,KAAK,CAAC,OAAO,CAAC,GAAiB;QAC3B,IAAG,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,GAAC,CAAC,EAAC;YACzC,KAAI,IAAI,CAAC,IAAI,IAAI,CAAC,SAAS,EAAC;gBACxB,IAAI,QAAQ,GAAG,YAAY,CAAC,UAAU,GAAC,CAAC,CAAC,QAAQ,CAAA;gBACjD,QAAQ,GAAG,QAAQ,CAAC,UAAU,CAAC,IAAI,EAAC,GAAG,CAAC,CAAA;gBACxC,IAAI,QAAQ,KAAK,GAAG,CAAC,QAAQ,IAAI,CAAC,CAAC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,KAAI,UAAU;oBACxE,OAAO,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAC,GAAG,CAAC,CAAA;aACtC;SACJ;QAED,IAAA,oBAAO,EAAC,oBAAoB,EAAC,wBAAwB,GAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QAEpE,OAAO;YACH,KAAK,EAAC,uBAAa,CAAC,eAAe;YACnC,IAAI,EAAC,IAAI;SACZ,CAAA;IACL,CAAC;;AAzFL,oCA0FC","sourcesContent":["import { logCrit, logInfo, logWarn } from \"./LogService\";\nimport DefaultErrors from \"./structures/DefaultErrors\";\nimport { HTTPRequestVO, TransferPacketVO } from \"./structures/Interfaces\";\n\n\nexport interface IBaseEndpoint{\n endpoints?:IEndpointHandler[]\n execute:(req:HTTPRequestVO)=>Promise<TransferPacketVO<any>>\n precheck:(req:HTTPRequestVO)=>Promise<TransferPacketVO<any>|null>\n init:() => Promise<void>\n ignoreHttpLogging:boolean,\n}\n\nexport interface IEndpointHandler{\n endpoint:string,\n handler?:(req:HTTPRequestVO)=>Promise<TransferPacketVO<any>>\n ignoreInterceptor?:boolean\n independed?:boolean\n allowInterceptorError?:boolean\n httpMethod?:\"GET\"|\"POST\"|\"PUT\"|\"DELETE\"\n}\n\nexport class BaseEndpoint implements IBaseEndpoint{\n\n private inializedEndpointNames:String[]=[];\n\n endpoints?:IEndpointHandler[]\n public ignoreHttpLogging = false\n private static entrypoint:string=\"/\";\n private endpoint=\"\"\n \n\n // global entrypoint\n static setEntryPoint=(ep:string)=>{\n this.entrypoint = ep;\n if(!this.entrypoint.endsWith(\"/\")){\n this.entrypoint+=\"/\"\n }\n if(!ep.startsWith(\"/\"))\n this.entrypoint=\"/\"+ep;\n }\n static getEntryPoint=():string=>{\n return this.entrypoint;\n }\n \n constructor(endpoint:string){\n if(endpoint.startsWith(\"/\"))\n endpoint=endpoint.substring(1)\n if(!endpoint.endsWith(\"/\"))\n endpoint=endpoint+\"/\"\n this.endpoint=endpoint;\n }\n \n\n registerEndpoints(endpoints:IEndpointHandler[]){\n for(let i of endpoints){\n \n // base point\n if(i.endpoint===\"\" || i.endpoint===\"/\"){\n let empty=i.endpoint === \"\";\n i.endpoint=this.endpoint\n if(i.endpoint.endsWith(\"/\") && empty)\n i.endpoint=i.endpoint.substring(0,i.endpoint.length-1)\n continue;\n }\n\n if(i.endpoint.startsWith(\"/\"))\n i.endpoint = i.endpoint.substring(1)\n if(i.endpoint.endsWith(\"/\"))\n i.endpoint=i.endpoint.substring(0,i.endpoint.length-1)\n\n if(!i.independed)\n i.endpoint = this.endpoint+i.endpoint\n }\n this.endpoints =endpoints;\n }\n\n \n async init(){\n if(!this.endpoints){\n logCrit(\"${BaseEndpoint.js}\",\"No endpoints registered for \"+this.endpoint)\n return;\n }\n for(let i of this.endpoints){\n logInfo(\"${BaseEndpoint.js}\",\"endpoint: \"+i.endpoint+\" initalized, ignoreInterceptor: \"+(i.ignoreInterceptor ?? \"false\"));\n this.inializedEndpointNames.push(i.endpoint+\" ignore interceptor: \"+(i.ignoreInterceptor ?? \"false\"))\n }\n };\n\n getInitalizedEndpointNames():String[]{\n return this.inializedEndpointNames;\n }\n\n async precheck(req:HTTPRequestVO):Promise<TransferPacketVO<any>|null>{return null}\n\n async execute(req:HTTPRequestVO):Promise<TransferPacketVO<any>>{\n if(this.endpoints && this.endpoints.length>0){\n for(let i of this.endpoints){\n let targetEP = BaseEndpoint.entrypoint+i.endpoint\n targetEP = targetEP.replaceAll(\"//\",\"/\")\n if( targetEP === req.endpoint && i.handler && typeof i.handler ===\"function\")\n return i.handler.call(this,req)\n }\n }\n\n logWarn(\"${BaseEndpoint.js}\",\"Unhandled entrypoint: \"+this.endpoint)\n \n return {\n error:DefaultErrors.NOT_IMPLEMENTED,\n data:null\n }\n }\n}"]}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"BaseService.js","sourceRoot":"","sources":["../../src/apiServer/BaseService.ts"],"names":[],"mappings":";;;AAMA,MAAa,WAAW;IAEZ,IAAI,CAAQ;IACtB,YAAa,IAAY;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;IAED,KAAK,CAAC,IAAI;QACR,OAAO,CAAC,GAAG,CAAC,WAAW,GAAC,IAAI,CAAC,IAAI,GAAC,cAAc,CAAC,CAAC;IACpD,CAAC;IAED,OAAO;QACL,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED,gBAAgB,KAAY,CAAC;CAC9B;AAhBD,kCAgBC","sourcesContent":["export interface IBaseService {\n init: () => Promise<void>\n applicationReady: () => void\n getName: () => string\n}\n\nexport class BaseService implements IBaseService {\n\n protected name: string\n constructor (name: string) {\n this.name = name\n }\n\n async init (): Promise<void> { \n console.log(\"Service: \"+this.name+\" initialized\");\n }\n \n getName():string{\n return this.name;\n }\n\n applicationReady (): void { }\n}\n"]}
|
@@ -1,30 +0,0 @@
|
|
1
|
-
import { BaseService } from "./BaseService";
|
2
|
-
import { HUBConnection } from "./cluster/HUBConnection";
|
3
|
-
import Signal, { Req } from "badmfck-signal";
|
4
|
-
import { HUBServiceOptions, IWebsocketPacket } from "./external/ExternalService";
|
5
|
-
export interface IParty {
|
6
|
-
name: string;
|
7
|
-
handlers: (Signal<IWebsocketPacket> | Req<IWebsocketPacket, any>)[];
|
8
|
-
}
|
9
|
-
export interface IPartyHost {
|
10
|
-
url: string;
|
11
|
-
publicKey: string;
|
12
|
-
id: string;
|
13
|
-
}
|
14
|
-
export interface ClusterServiceOptions extends HUBServiceOptions {
|
15
|
-
targetID: string;
|
16
|
-
targetPublicKey: string;
|
17
|
-
targetURL: string;
|
18
|
-
party: IParty[];
|
19
|
-
}
|
20
|
-
export declare class ClusterService extends BaseService {
|
21
|
-
options: ClusterServiceOptions;
|
22
|
-
ws: HUBConnection | null;
|
23
|
-
handlers: (Signal<IWebsocketPacket> | Req<IWebsocketPacket, any>)[];
|
24
|
-
parites: Map<string, IPartyHost>;
|
25
|
-
constructor(opt: ClusterServiceOptions);
|
26
|
-
init(): Promise<void>;
|
27
|
-
close(): Promise<void>;
|
28
|
-
connectToHUB(): Promise<void>;
|
29
|
-
addPartyHost(party: IPartyHost): void;
|
30
|
-
}
|
@@ -1,81 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
-
};
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.ClusterService = void 0;
|
7
|
-
const ws_1 = __importDefault(require("ws"));
|
8
|
-
const BaseService_1 = require("./BaseService");
|
9
|
-
const LogService_1 = require("./LogService");
|
10
|
-
const HUBConnection_1 = require("./cluster/HUBConnection");
|
11
|
-
const badmfck_signal_1 = __importDefault(require("badmfck-signal"));
|
12
|
-
const DefaultErrors_1 = require("./structures/DefaultErrors");
|
13
|
-
const Sleep_1 = require("./helper/Sleep");
|
14
|
-
class ClusterService extends BaseService_1.BaseService {
|
15
|
-
options;
|
16
|
-
ws = null;
|
17
|
-
handlers = [];
|
18
|
-
parites = new Map();
|
19
|
-
constructor(opt) {
|
20
|
-
super("ClusterService");
|
21
|
-
this.options = opt;
|
22
|
-
this.handlers = [
|
23
|
-
new badmfck_signal_1.default("S_PARTY_AVAILABLE", undefined, async (req) => {
|
24
|
-
this.addPartyHost(req.data);
|
25
|
-
})
|
26
|
-
];
|
27
|
-
}
|
28
|
-
async init() {
|
29
|
-
(0, LogService_1.logInfo)("ClusterService: initialized");
|
30
|
-
this.connectToHUB();
|
31
|
-
}
|
32
|
-
async close() {
|
33
|
-
(0, LogService_1.logInfo)("ClusterService: closing");
|
34
|
-
if (this.ws)
|
35
|
-
this.ws.close();
|
36
|
-
this.parites.clear();
|
37
|
-
}
|
38
|
-
async connectToHUB() {
|
39
|
-
(0, LogService_1.logInfo)("ClusterService: connecting to HUB");
|
40
|
-
if (this.ws)
|
41
|
-
this.ws.close();
|
42
|
-
this.ws = new HUBConnection_1.HUBConnection({
|
43
|
-
direction: "outgoing",
|
44
|
-
ws: new ws_1.default(this.options.targetURL),
|
45
|
-
hostID: this.options.hostID,
|
46
|
-
hostPrivateKey: this.options.hostPrivateKey,
|
47
|
-
hostPublicKey: this.options.hostPublicKey,
|
48
|
-
hostURL: this.options.hostURL,
|
49
|
-
targetID: this.options.targetID,
|
50
|
-
targetPublicKey: this.options.targetPublicKey,
|
51
|
-
targetURL: this.options.targetURL,
|
52
|
-
handlers: this.handlers,
|
53
|
-
onAuthorized: async () => {
|
54
|
-
(0, LogService_1.logInfo)("ClusterService: connected to HUB");
|
55
|
-
await (0, Sleep_1.Sleep)(1000);
|
56
|
-
const parites = this.options.party.map((party) => party.name);
|
57
|
-
const response = await this.ws?.send({
|
58
|
-
method: "REQ_PARTY",
|
59
|
-
data: parites,
|
60
|
-
callbackID: 1
|
61
|
-
});
|
62
|
-
if (DefaultErrors_1.ErrorUtils.isError(response)) {
|
63
|
-
(0, LogService_1.logError)("ClusterService: error while registrating parties", response);
|
64
|
-
return;
|
65
|
-
}
|
66
|
-
for (let i of response)
|
67
|
-
this.addPartyHost(i);
|
68
|
-
},
|
69
|
-
onClose: () => {
|
70
|
-
console.log("ClusterService: connection to HUB closed");
|
71
|
-
this.connectToHUB();
|
72
|
-
},
|
73
|
-
});
|
74
|
-
}
|
75
|
-
addPartyHost(party) {
|
76
|
-
(0, LogService_1.logInfo)("ClusterService: add party host", party);
|
77
|
-
this.parites.set(party.id, party);
|
78
|
-
}
|
79
|
-
}
|
80
|
-
exports.ClusterService = ClusterService;
|
81
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQ2x1c3RlclNlcnZpY2UuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvYXBpU2VydmVyL0NsdXN0ZXJTZXJ2aWNlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7OztBQUFBLDRDQUF3QztBQUN4QywrQ0FBNEM7QUFDNUMsNkNBQWlEO0FBQ2pELDJEQUF3RTtBQUV4RSxvRUFBNkM7QUFFN0MsOERBQXdEO0FBQ3hELDBDQUF1QztBQTJCdkMsTUFBYSxjQUFlLFNBQVEseUJBQVc7SUFHM0MsT0FBTyxDQUF1QjtJQUM5QixFQUFFLEdBQW9CLElBQUksQ0FBQztJQUMzQixRQUFRLEdBQThELEVBQUUsQ0FBQztJQUN6RSxPQUFPLEdBQTBCLElBQUksR0FBRyxFQUFFLENBQUM7SUFFM0MsWUFBWSxHQUF5QjtRQUNqQyxLQUFLLENBQUMsZ0JBQWdCLENBQUMsQ0FBQTtRQUN2QixJQUFJLENBQUMsT0FBTyxHQUFHLEdBQUcsQ0FBQztRQUVuQixJQUFJ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ICAgIHRoaXMud3MgPSBuZXcgSFVCQ29ubmVjdGlvbih7XG4gICAgICAgICAgICBkaXJlY3Rpb246XCJvdXRnb2luZ1wiLFxuICAgICAgICAgICAgd3M6bmV3IFdlYlNvY2tldCh0aGlzLm9wdGlvbnMudGFyZ2V0VVJMKSxcblxuICAgICAgICAgICAgaG9zdElEOnRoaXMub3B0aW9ucy5ob3N0SUQsXG4gICAgICAgICAgICBob3N0UHJpdmF0ZUtleTp0aGlzLm9wdGlvbnMuaG9zdFByaXZhdGVLZXksXG4gICAgICAgICAgICBob3N0UHVibGljS2V5OnRoaXMub3B0aW9ucy5ob3N0UHVibGljS2V5LFxuICAgICAgICAgICAgaG9zdFVSTDp0aGlzLm9wdGlvbnMuaG9zdFVSTCxcblxuICAgICAgICAgICAgdGFyZ2V0SUQ6dGhpcy5vcHRpb25zLnRhcmdldElELFxuICAgICAgICAgICAgdGFyZ2V0UHVibGljS2V5OnRoaXMub3B0aW9ucy50YXJnZXRQdWJsaWNLZXksXG4gICAgICAgICAgICB0YXJnZXRVUkw6dGhpcy5vcHRpb25zLnRhcmdldFVSTCxcblxuICAgICAgICAgICAgaGFuZGxlcnM6dGhpcy5oYW5kbGVycyxcblxuICAgICAgICAgICAgb25BdXRob3JpemVkOmFzeW5jICgpPT57XG4gICAgICAgICAgICAgICAgbG9nSW5mbyhcIkNsdXN0ZXJTZXJ2aWNlOiBjb25uZWN0ZWQgdG8gSFVCXCIpXG5cbiAgICAgICAgICAgICAgICBhd2FpdCBTbGVlcCgxMDAwKVxuXG4gICAgICAgICAgICAgICAgLy8gcmVnaXN0cmF0ZSBwYXJ0aWVzXG4gICAgICAgICAgICAgICAgY29uc3QgcGFyaXRlcyA9IHRoaXMub3B0aW9ucy5wYXJ0eS5tYXAoKHBhcnR5KT0+cGFydHkubmFtZSk7XG4gICAgICAgICAgICAgICAgY29uc3QgcmVzcG9uc2UgPSBhd2FpdCB0aGlzLndzPy5zZW5kKHtcbiAgICAgICAgICAgICAgICAgICAgbWV0aG9kOiBcIlJFUV9QQVJUWVwiLFxuICAgICAgICAgICAgICAgICAgICBkYXRhOiBwYXJpdGVzLFxuICAgICAgICAgICAgICAgICAgICBjYWxsYmFja0lEOjFcbiAgICAgICAgICAgICAgICB9KSBhcyBJUGFydHlIb3N0W11cblxuICAgICAgICAgICAgICAgIGlmKEVycm9yVXRpbHMuaXNFcnJvcihyZXNwb25zZSkpe1xuICAgICAgICAgICAgICAgICAgICBsb2dFcnJvcihcIkNsdXN0ZXJTZXJ2aWNlOiBlcnJvciB3aGlsZSByZWdpc3RyYXRpbmcgcGFydGllc1wiLHJlc3BvbnNlKVxuICAgICAgICAgICAgICAgICAgICAvL3RvZG8gcmV0YWtlIHBhcml0ZXNcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICBcbiAgICAgICAgICAgICAgICBmb3IobGV0IGkgb2YgcmVzcG9uc2UpXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuYWRkUGFydHlIb3N0KGkpO1xuICAgICAgICAgICAgfSxcblxuICAgICAgICAgICAgXG4gICAgICAgICAgICBvbkNsb3NlOigpPT57XG4gICAgICAgICAgICAgICAgY29uc29sZS5sb2coXCJDbHVzdGVyU2VydmljZTogY29ubmVjdGlvbiB0byBIVUIgY2xvc2VkXCIpXG4gICAgICAgICAgICAgICAgdGhpcy5jb25uZWN0VG9IVUIoKTtcbiAgICAgICAgICAgIH0sXG4gICAgICAgIH0pXG4gICAgfVxuXG5cbiAgICBhZGRQYXJ0eUhvc3QocGFydHk6SVBhcnR5SG9zdCl7XG4gICAgICAgIGxvZ0luZm8oXCJDbHVzdGVyU2VydmljZTogYWRkIHBhcnR5IGhvc3RcIixwYXJ0eSlcbiAgICAgICAgdGhpcy5wYXJpdGVzLnNldChwYXJ0eS5pZCxwYXJ0eSk7XG4gICAgfVxuXG59Il19
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"ClusterService.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EAAC,kCAAkC,CAAC,CAAA;gBAE3C,MAAM,IAAA,aAAK,EAAC,IAAI,CAAC,CAAA;gBAGjB,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,EAAC,EAAE,CAAA,KAAK,CAAC,IAAI,CAAC,CAAC;gBAC5D,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC;oBACjC,MAAM,EAAE,WAAW;oBACnB,IAAI,EAAE,OAAO;oBACb,UAAU,EAAC,CAAC;iBACf,CAAiB,CAAA;gBAElB,IAAG,0BAAU,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAC;oBAC5B,IAAA,qBAAQ,EAAC,kDAAkD,EAAC,QAAQ,CAAC,CAAA;oBAErE,OAAO;iBACV;gBAED,KAAI,IAAI,CAAC,IAAI,QAAQ;oBACjB,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;YAC7B,CAAC;YAGD,OAAO,EAAC,GAAE,EAAE;gBACR,OAAO,CAAC,GAAG,CAAC,0CAA0C,CAAC,CAAA;gBACvD,IAAI,CAAC,YAAY,EAAE,CAAC;YACxB,CAAC;SACJ,CAAC,CAAA;IACN,CAAC;IAGD,YAAY,CAAC,IAAe;QACxB,IAAA,oBAAO,EAAC,gCAAgC,EAAC,IAAI,CAAC,CAAA;IAClD,CAAC;CAEJ;AA5ED,wCA4EC","sourcesContent":["import WebSocket, { RawData } from \"ws\";\nimport { BaseService } from \"./BaseService\";\nimport { logError, logInfo } from \"./LogService\";\nimport { HUBConnection, IClusterPacket } from \"./cluster/HUBConnection\";\nimport { privateDecrypt } from \"crypto\";\nimport Signal, { Req } from \"badmfck-signal\";\nimport { HUBServiceOptions, IWebsocketPacket } from \"./HUBService\";\nimport { ErrorUtils } from \"./structures/DefaultErrors\";\nimport { Sleep } from \"./helper/Sleep\";\n\n\nexport interface IParty{\n name:string,\n handlers:(Signal<IWebsocketPacket>|Req<IWebsocketPacket,any>)[],\n}\n\nexport interface IPartyHost{\n url:string,\n\tpublicKey:string,\n\tid:string\t\n}\n\n/**\n * ClusterServiceOptions\n * id: string - id of the service, must be sha256 hash or stronger\n * \n */\nexport interface ClusterServiceOptions extends HUBServiceOptions{\n \n targetID:string,\n targetPublicKey:string,\n targetURL:string,\n party:IParty[], // list of ids of parties that I can connect to\n}\n\nexport class ClusterService extends BaseService{\n \n \n options:ClusterServiceOptions;\n ws:HUBConnection|null=null;\n\n parites:Map<string,IParty> = new Map();\n\n constructor(opt:ClusterServiceOptions){\n super(\"ClusterService\")\n this.options = opt;\n }\n\n async init(){\n logInfo(\"ClusterService: initialized\")\n this.connectToHUB();\n }\n\n async connectToHUB(){\n\n logInfo(\"ClusterService: connecting to HUB\")\n\n if(this.ws)\n this.ws.close();\n \n this.ws = new HUBConnection({\n direction:\"outgoing\",\n ws:new WebSocket(this.options.targetURL),\n\n hostID:this.options.hostID,\n hostPrivateKey:this.options.hostPrivateKey,\n hostPublicKey:this.options.hostPublicKey,\n hostURL:this.options.hostURL,\n\n targetID:this.options.targetID,\n targetPublicKey:this.options.targetPublicKey,\n targetURL:this.options.targetURL,\n\n handlers:[],\n\n onAuthorized:async ()=>{\n logInfo(\"ClusterService: connected to HUB\")\n\n await Sleep(1000)\n\n // registrate parties\n const parites = this.options.party.map((party)=>party.name);\n const response = await this.ws?.send({\n method: \"REQ_PARTY\",\n data: parites,\n callbackID:1\n }) as IPartyHost[]\n\n if(ErrorUtils.isError(response)){\n logError(\"ClusterService: error while registrating parties\",response)\n //todo retake parites\n return;\n }\n \n for(let i of response)\n this.addPartyHost(i);\n },\n\n \n onClose:()=>{\n console.log(\"ClusterService: connection to HUB closed\")\n this.connectToHUB();\n },\n })\n }\n\n\n addPartyHost(host:IPartyHost){\n logInfo(\"ClusterService: add party host\",host)\n }\n\n}"]}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"DocumentService.js","sourceRoot":"","sources":["../../src/apiServer/Docum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I,CAAC,gBAAgB,CAAC,GAAG,CAAC,WAAW,CAAC;iBACnD,CAAC,CAAC;gBACH,MAAM;SACP;QAED,OAAO,QAAQ,CAAC;IACjB,CAAC;IAUO,gBAAgB,CAAC,IAAY,EAAE,QAAgB,aAAa;QACnE,QAAQ,KAAK,EAAE;YACd,KAAK,aAAa;gBACjB,IAAI,GAAG,IAAI;qBACT,IAAI,EAAE;qBACN,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC;qBACrB,IAAI,EAAE,CAAC;gBAET,MAAM;YAEP,KAAK,MAAM;gBACV,IAAI,IAAI,KAAK,GAAG,EAAE;oBACjB,IAAI,GAAG,EAAE,CAAC;iBACV;gBAED,MAAM;SACP;QAED,OAAO,IAAI,CAAC;IACb,CAAC;IAEO,iBAAiB;QAExB,MAAM,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC;QACzC,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC;QAErE,EAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IACpE,CAAC;IAEM,gBAAgB;QACtB,OAAO,IAAI,CAAC,aAAa,CAAC;IAC3B,CAAC;CA0DD;AAhSD,8CAgSC;AAGD,IAAI,iBAAiB,CAAC;IACrB,UAAU,EAAE,WAAW;IACvB,WAAW,EAAE,QAAQ;IACrB,QAAQ,EAAE,QAAQ;IAClB,gBAAgB,EAAE,UAAU;CAC5B,CAAC,CAAC","sourcesContent":["import * as fs from \"fs\";\nimport * as path from \"path\";\nimport { parse, Spec } from \"comment-parser\";\n\n//TODO: api endpoint, sourcepath, .doc file - from config\n\ndeclare type DocumentGeneratorConfig = {\n\tsourcePath: string;\n\tapiEndpoint: string;\n\tsavePath: string;\n\tsavePathFileName: string;\n};\n\ndeclare type DocumentGeneratorDocumentation = {\n\t[baseEndpointName: string]: {\n\t\t[endPointName: string]: DocumentGeneratorDocumentationEndpoint;\n\t};\n};\n\ndeclare type DocumentGeneratorDocumentationEndpoint = {\n\thandler: string;\n\tfullPath: string;\n\tignoreInterceptor?: string;\n\n\tdescription?: string;\n\tparameters: DocumentGeneratorDocumentationEndpointParameter[];\n\treturns?: Omit<DocumentGeneratorDocumentationEndpointParameter, \"optional\">;\n\texample?: string[];\n\tthrows?: Omit<DocumentGeneratorDocumentationEndpointParameter, \"optional\">[];\n};\n\ndeclare type DocumentGeneratorDocumentationEndpointParameter = {\n\tname: string;\n\ttype: string;\n\tdescription: string;\n\toptional?: boolean;\n};\n\nexport class DocumentGenerator {\n\tprivate documentation: DocumentGeneratorDocumentation = {};\n\tprivate config: DocumentGeneratorConfig;\n\n\tconstructor(config: DocumentGeneratorConfig) {\n\t\tthis.config = config;\n\n\t\tthis.generateDocumentation();\n\t}\n\n\tprivate getFiles(): string[] {\n\t\treturn fs.readdirSync(this.config.sourcePath);\n\t}\n\n\tprivate getFileContent(file: string) {\n\t\treturn fs.readFileSync(path.resolve(this.config.sourcePath, file), \"utf-8\");\n\t}\n\n\tprivate generateDocumentation = () => {\n\t\tfor (const file of this.getFiles()) {\n\t\t\tconst fileContent = this.getFileContent(file);\n\n\t\t\t// get base endpoint\n\t\t\tconst baseEndpoint = fileContent.match(/super\\(['\"](.*?)['\"]\\)/);\n\t\t\tif (!baseEndpoint) {\n\t\t\t\tconsole.error(`No base endpoint found in ${file}`);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst nodeEndpoint = this.config.apiEndpoint + \"/\" + baseEndpoint[1];\n\n\t\t\t// get all endpoints\n\t\t\tconst regex = /{\\s*endpoint:\\s*\"(.*?)\",\\s*handler:\\s*this\\.(.*?)(?:,\\s*ignoreInterceptor:\\s*(true|false))?\\s*}/g;\n\n\t\t\tconst endpoints = fileContent.matchAll(regex);\n\n\t\t\tfor (const match of endpoints) {\n\t\t\t\tconst endpointName: string = match[1];\n\t\t\t\tconst handler = match[2];\n\t\t\t\tconst ignoreInterceptor = match[3];\n\n\t\t\t\tif (!this.documentation.hasOwnProperty(nodeEndpoint)) {\n\t\t\t\t\tthis.documentation[nodeEndpoint] = {};\n\t\t\t\t}\n\n\t\t\t\tconst endpoint: DocumentGeneratorDocumentationEndpoint = {\n\t\t\t\t\thandler,\n\t\t\t\t\tignoreInterceptor,\n\t\t\t\t\tfullPath: nodeEndpoint + \"/\" + endpointName,\n\t\t\t\t\tdescription: \"\",\n\t\t\t\t\tparameters: [],\n\t\t\t\t};\n\n\t\t\t\tthis.documentation[nodeEndpoint][endpointName] = this.parseEndPointComments(\n\t\t\t\t\tthis.getCommentsByEndpoint(fileContent, handler),\n\t\t\t\t\tendpoint,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tthis.saveDocumentation();\n\n\t\tconsole.log(\"Documentation generated and saved successfully\");\n\t};\n\n\tprivate getCommentsByEndpoint(fileContent: string, handler: string): string {\n\t\tlet comments: string = \"\";\n\n\t\t//TODO: change to regex\n\t\t//const regex = new RegExp(`/\\\\*\\\\*([\\\\s\\\\S]*?)\\\\*/\\\\s*async\\\\s+${handler}\\\\s*\\\\(`, \"g\");\n\t\t//const regex = new RegExp(`/\\\\*\\\\*([\\\\s\\\\S]*?)\\\\*\\\\/\\\\s*async\\\\s+${handler}\\\\s*\\\\(`, \"g\");\n\t\t//const match2 = fileContent.match(regex);\n\n\t\t//if (match2) {\n\t\t// \tcomments = match2[0];\n\t\t// \t// formatJavaDoc(match2[0], description);\n\t\t//}\n\n\t\tconst regex = new RegExp(`(async )*${handler}(\\\\s*)\\\\(`, \"g\");\n\t\tconst match = fileContent.match(regex);\n\n\t\tif (match) {\n\t\t\t// const indexHandler = fileContent.indexOf(`async ${handler}(`);\n\t\t\tconst indexHandler = fileContent.indexOf(`${match[0]}`);\n\n\t\t\t// if (indexHandler === -1) {\n\t\t\t// \tindexHandler = fileContent.indexOf(`${handler}(`);\n\t\t\t// }\n\n\t\t\tif (indexHandler != -1) {\n\t\t\t\tconst indexCommentStart = fileContent.lastIndexOf(\"/**\", indexHandler);\n\t\t\t\tif (indexCommentStart != -1) {\n\t\t\t\t\tconst indexCommentEnd = fileContent.indexOf(\"*/\", indexCommentStart);\n\n\t\t\t\t\tif (indexCommentEnd != -1) {\n\t\t\t\t\t\tconst commentsSubstring = fileContent.substring(indexCommentStart, indexCommentEnd + 2);\n\n\t\t\t\t\t\tif (commentsSubstring) {\n\t\t\t\t\t\t\tconst regexToCheckCommentWithMethod = new RegExp(\n\t\t\t\t\t\t\t\t`${commentsSubstring.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\")}([\\\\s]*?)(async )*${handler}(\\\\s*)\\\\(`,\n\t\t\t\t\t\t\t\t\"g\",\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\tconst matchToCheckCommentWithMethod = fileContent.match(regexToCheckCommentWithMethod);\n\n\t\t\t\t\t\t\tif (matchToCheckCommentWithMethod) {\n\t\t\t\t\t\t\t\tcomments = commentsSubstring;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn comments;\n\t}\n\n\tprivate parseEndPointComments(\n\t\tcomments: string,\n\t\tendpoint: DocumentGeneratorDocumentationEndpoint,\n\t): DocumentGeneratorDocumentationEndpoint {\n\t\tif (comments) {\n\t\t\tconst parsed = parse(comments, { spacing: \"preserve\" });\n\t\t\tif (parsed[0]) {\n\t\t\t\tconst firstParsed = parsed[0];\n\t\t\t\t// console.log(firstParsed.tags);\n\n\t\t\t\tendpoint.description = this.tagModifications(firstParsed.description);\n\n\t\t\t\tfirstParsed.tags.forEach((tag) => {\n\t\t\t\t\tendpoint = this.tagToEndpoint(tag, endpoint);\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\treturn endpoint;\n\t}\n\n\t/**\n\t * From comment-parser library to json\n\t *\n\t * @param tag\n\t * @param endpoint\n\t * @returns\n\t */\n\tprivate tagToEndpoint(\n\t\ttag: Spec,\n\t\tendpoint: DocumentGeneratorDocumentationEndpoint,\n\t): DocumentGeneratorDocumentationEndpoint {\n\t\tswitch (tag.tag) {\n\t\t\tcase \"param\":\n\t\t\t\tendpoint.parameters.push({\n\t\t\t\t\tname: this.tagModifications(tag.name, \"name\"),\n\t\t\t\t\ttype: tag.type,\n\t\t\t\t\tdescription: this.tagModifications(tag.description),\n\t\t\t\t\toptional: tag.optional,\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t\tcase \"description\":\n\t\t\t\tendpoint.description = this.tagModifications(tag.description);\n\t\t\t\tbreak;\n\t\t\tcase \"example\":\n\t\t\t\tif (!endpoint.example) {\n\t\t\t\t\tendpoint.example = [];\n\t\t\t\t}\n\n\t\t\t\tendpoint.example.push(this.tagModifications(tag.description));\n\t\t\t\tbreak;\n\t\t\tcase \"returns\":\n\t\t\t\tendpoint.returns = {\n\t\t\t\t\tname: this.tagModifications(tag.name, \"name\"),\n\t\t\t\t\ttype: tag.type,\n\t\t\t\t\tdescription: this.tagModifications(tag.description),\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\tcase \"throws\":\n\t\t\t\tif (!endpoint.throws) {\n\t\t\t\t\tendpoint.throws = [];\n\t\t\t\t}\n\n\t\t\t\tendpoint.throws.push({\n\t\t\t\t\tname: this.tagModifications(tag.name, \"name\"),\n\t\t\t\t\ttype: tag.type,\n\t\t\t\t\tdescription: this.tagModifications(tag.description),\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t}\n\n\t\treturn endpoint;\n\t}\n\n\t/**\n\t *\n\t * modification after comment-parser library parsings with \"-\" in description\n\t *\n\t * @param text\n\t * @param field\n\t * @returns\n\t */\n\tprivate tagModifications(text: string, field: string = \"description\"): string {\n\t\tswitch (field) {\n\t\t\tcase \"description\":\n\t\t\t\ttext = text\n\t\t\t\t\t.trim()\n\t\t\t\t\t.replace(/^(\\-.)/, \"\")\n\t\t\t\t\t.trim();\n\n\t\t\t\tbreak;\n\n\t\t\tcase \"name\":\n\t\t\t\tif (text === \"-\") {\n\t\t\t\t\ttext = \"\";\n\t\t\t\t}\n\n\t\t\t\tbreak;\n\t\t}\n\n\t\treturn text;\n\t}\n\n\tprivate saveDocumentation(): void {\n\t\t// const formatForSave = { data: this.documentation };\n\t\tconst formatForSave = this.documentation;\n\t\tconst filePath = this.config.savePath + this.config.savePathFileName;\n\n\t\tfs.writeFileSync(filePath, JSON.stringify(formatForSave, null, 2));\n\t}\n\n\tpublic getDocumentation(): DocumentGeneratorDocumentation {\n\t\treturn this.documentation;\n\t}\n\n\t// const formatJavaDoc = (comment, finalDescription) => {\n\t// \t// Регулярные выражения для различных частей комментария\n\t// \tconst descriptionRegex = /\\/\\*\\*([\\s\\S]*?)(?=\\s*\\*\\s*@|\\s*\\*\\/)/g;\n\t// \tconst paramRegex = /@param\\s+(\\w+)\\s+([^\\s]+)\\s*-\\s*(.+?)(?=\\s+\\*|$)/g;\n\t// \tconst returnRegex = /@returns?\\s+([^\\s]+)\\s*-\\s*(.+?)(?=\\s+\\*|$)/g;\n\t// \tconst throwsRegex = /@throws\\s+([^\\s]+)\\s*-\\s*(.+?)(?=\\s+\\*|$)/g;\n\t// \tconst seeRegex = /@see\\s+([^\\s]+)(?=\\s+\\*|$)/g;\n\n\t// \t// Извлекаем описание\n\t// \tconst descriptionMatch = descriptionRegex.exec(comment);\n\t// \tconst description = descriptionMatch ? descriptionMatch[1].trim().replace(/\\*\\s+/g, \"\").replace(/\\n/g, \" \") : \"\";\n\n\t// \tfinalDescription.info = description;\n\n\t// \t// Извлекаем параметры\n\t// \tconst params = [];\n\t// \tlet paramMatch;\n\t// \twhile ((paramMatch = paramRegex.exec(comment)) !== null) {\n\t// \t\tparams.push({\n\t// \t\t\tname: paramMatch[1],\n\t// \t\t\ttype: paramMatch[2],\n\t// \t\t\tdescription: paramMatch[3].trim(),\n\t// \t\t});\n\t// \t}\n\t// \tdescription.params = params;\n\n\t// \t// Извлекаем возвращаемое значение\n\t// \tconst returnMatch = returnRegex.exec(comment);\n\t// \tconst returnType = returnMatch ? returnMatch[1] : \"\";\n\t// \tconst returnDescription = returnMatch ? returnMatch[2].trim() : \"\";\n\n\t// \tfinalDescription.return = {\n\t// \t\ttype: returnType,\n\t// \t\tdescription: returnDescription,\n\t// \t};\n\n\t// \t// Извлекаем исключения\n\t// \tconst throws = [];\n\t// \tlet throwsMatch;\n\t// \twhile ((throwsMatch = throwsRegex.exec(comment)) !== null) {\n\t// \t\tthrows.push({\n\t// \t\t\texception: throwsMatch[1],\n\t// \t\t\tdescription: throwsMatch[2].trim(),\n\t// \t\t});\n\t// \t}\n\t// \tdescription.throws = throws;\n\n\t// \t// Извлекаем теги @see\n\t// \tconst seeReferences = [];\n\t// \tlet seeMatch;\n\t// \twhile ((seeMatch = seeRegex.exec(comment)) !== null) {\n\t// \t\tseeReferences.push(seeMatch[1]);\n\t// \t}\n\n\t// \tdescription.see = seeReferences;\n\t// };\n}\n\n// const documentGenerator =\nnew DocumentGenerator({\n\tsourcePath: \"./src/api\",\n\tapiEndpoint: \"api/v1\",\n\tsavePath: \"./bin/\",\n\tsavePathFileName: \"doc.json\",\n});\n\n// console.log(documentGenerator.getDocumentation());"]}
|
@@ -1,37 +0,0 @@
|
|
1
|
-
import { BaseService } from "./BaseService";
|
2
|
-
import { HUBConnection } from "./cluster/HUBConnection";
|
3
|
-
import Signal, { Req } from "badmfck-signal";
|
4
|
-
import { IError } from "./structures/Interfaces";
|
5
|
-
export interface HUBServiceOptions {
|
6
|
-
hostID: string;
|
7
|
-
hostPublicKey: string;
|
8
|
-
hostPrivateKey: string;
|
9
|
-
hostURL: string;
|
10
|
-
}
|
11
|
-
export interface IClusterNode {
|
12
|
-
clusterID: string;
|
13
|
-
url: string;
|
14
|
-
publicKey: string;
|
15
|
-
privateKey: string;
|
16
|
-
ws: HUBConnection[];
|
17
|
-
watchlist: string[];
|
18
|
-
}
|
19
|
-
export interface IWebsocketPacket<T = any> {
|
20
|
-
data: T;
|
21
|
-
authorized: boolean;
|
22
|
-
connection: HUBConnection;
|
23
|
-
}
|
24
|
-
export declare const REQ_CLUSTER_NODE: Req<string, IError | {
|
25
|
-
url: string;
|
26
|
-
publicKey: string;
|
27
|
-
}>;
|
28
|
-
export declare class HUBService extends BaseService {
|
29
|
-
options: HUBServiceOptions;
|
30
|
-
nodes: Map<string, IClusterNode>;
|
31
|
-
handlers: (Signal<IWebsocketPacket> | Req<IWebsocketPacket, any>)[];
|
32
|
-
constructor(options: HUBServiceOptions);
|
33
|
-
init(): Promise<void>;
|
34
|
-
applicationReady(): Promise<void>;
|
35
|
-
onConnectionAuthorized(conn: HUBConnection): void;
|
36
|
-
onConnectionClosed(conn: HUBConnection): void;
|
37
|
-
}
|
@@ -1,132 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
-
};
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.HUBService = exports.REQ_CLUSTER_NODE = void 0;
|
7
|
-
const ws_1 = require("ws");
|
8
|
-
const APIService_1 = require("./APIService");
|
9
|
-
const BaseService_1 = require("./BaseService");
|
10
|
-
const HUBConnection_1 = require("./cluster/HUBConnection");
|
11
|
-
const LogService_1 = require("./LogService");
|
12
|
-
const badmfck_signal_1 = require("badmfck-signal");
|
13
|
-
const DefaultErrors_1 = __importDefault(require("./structures/DefaultErrors"));
|
14
|
-
exports.REQ_CLUSTER_NODE = new badmfck_signal_1.Req(undefined, "REQ_CLUSTER_NODE");
|
15
|
-
class HUBService extends BaseService_1.BaseService {
|
16
|
-
options;
|
17
|
-
nodes = new Map();
|
18
|
-
handlers = [];
|
19
|
-
constructor(options) {
|
20
|
-
super("HUBService");
|
21
|
-
this.options = options;
|
22
|
-
this.handlers = [
|
23
|
-
new badmfck_signal_1.Req(async (req) => {
|
24
|
-
if (!req.data || !Array.isArray(req.data))
|
25
|
-
return { ...DefaultErrors_1.default.BAD_REQUEST, details: "data array is not set" };
|
26
|
-
const incomingCluster = this.nodes.get(req.connection.options.targetID ?? "");
|
27
|
-
if (!incomingCluster)
|
28
|
-
return { ...DefaultErrors_1.default.BAD_REQUEST, details: "cluster for incoming connection not found" };
|
29
|
-
const result = [];
|
30
|
-
for (let i of req.data) {
|
31
|
-
const clusterNode = this.nodes.get(i);
|
32
|
-
if (clusterNode) {
|
33
|
-
result.push({
|
34
|
-
url: clusterNode.url,
|
35
|
-
publicKey: clusterNode.publicKey,
|
36
|
-
id: clusterNode.clusterID
|
37
|
-
});
|
38
|
-
}
|
39
|
-
if (incomingCluster.watchlist.filter(x => x === i).length === 0)
|
40
|
-
incomingCluster.watchlist.push(i + "");
|
41
|
-
}
|
42
|
-
return result;
|
43
|
-
}, "REQ_PARTY")
|
44
|
-
];
|
45
|
-
}
|
46
|
-
async init() {
|
47
|
-
super.init();
|
48
|
-
}
|
49
|
-
async applicationReady() {
|
50
|
-
const server = await APIService_1.REQ_HTTP_SERVER.request();
|
51
|
-
const wss = new ws_1.WebSocketServer({
|
52
|
-
server: server.http,
|
53
|
-
path: "/hub"
|
54
|
-
});
|
55
|
-
wss.on("connection", (ws) => {
|
56
|
-
const conn = new HUBConnection_1.HUBConnection({
|
57
|
-
ws: ws,
|
58
|
-
direction: "incoming",
|
59
|
-
hostID: this.options.hostID,
|
60
|
-
hostPrivateKey: this.options.hostPrivateKey,
|
61
|
-
hostPublicKey: this.options.hostPublicKey,
|
62
|
-
hostURL: this.options.hostURL + "/hub",
|
63
|
-
targetID: null,
|
64
|
-
targetPublicKey: null,
|
65
|
-
targetURL: null,
|
66
|
-
onAuthorized: () => this.onConnectionAuthorized(conn),
|
67
|
-
onClose: () => this.onConnectionClosed(conn),
|
68
|
-
handlers: this.handlers
|
69
|
-
});
|
70
|
-
});
|
71
|
-
wss.on("error", (err) => {
|
72
|
-
console.error("HUBService: error: ", err);
|
73
|
-
});
|
74
|
-
}
|
75
|
-
onConnectionAuthorized(conn) {
|
76
|
-
if (!conn.options.targetID) {
|
77
|
-
(0, LogService_1.logError)("HUBService: connection targetID is not set");
|
78
|
-
return;
|
79
|
-
}
|
80
|
-
let clusterNode = this.nodes.get(conn.options.targetID);
|
81
|
-
if (!clusterNode) {
|
82
|
-
(0, LogService_1.logInfo)("HUBService: new cluster node connected");
|
83
|
-
clusterNode = {
|
84
|
-
clusterID: conn.options.targetID,
|
85
|
-
url: conn.options.targetURL,
|
86
|
-
publicKey: conn.options.targetPublicKey,
|
87
|
-
privateKey: conn.options.hostPrivateKey,
|
88
|
-
ws: [],
|
89
|
-
watchlist: []
|
90
|
-
};
|
91
|
-
this.nodes.set(conn.options.targetID, clusterNode);
|
92
|
-
}
|
93
|
-
clusterNode.ws.push(conn);
|
94
|
-
(0, LogService_1.logInfo)("HUBService: new authorized connection added to cluster node");
|
95
|
-
for (let [id, cluster] of this.nodes) {
|
96
|
-
for (let i of cluster.watchlist) {
|
97
|
-
if (i === clusterNode.clusterID) {
|
98
|
-
cluster.ws.forEach(x => {
|
99
|
-
x.send({
|
100
|
-
method: "S_PARTY_AVAILABLE",
|
101
|
-
data: {
|
102
|
-
url: clusterNode.url,
|
103
|
-
publicKey: clusterNode.publicKey,
|
104
|
-
id: clusterNode.clusterID
|
105
|
-
},
|
106
|
-
callbackID: 0
|
107
|
-
});
|
108
|
-
});
|
109
|
-
}
|
110
|
-
}
|
111
|
-
}
|
112
|
-
}
|
113
|
-
onConnectionClosed(conn) {
|
114
|
-
if (!conn.options.targetID) {
|
115
|
-
(0, LogService_1.logError)("HUBService: connection targetID is not set");
|
116
|
-
return;
|
117
|
-
}
|
118
|
-
const clusterNode = this.nodes.get(conn.options.targetID);
|
119
|
-
if (!clusterNode) {
|
120
|
-
(0, LogService_1.logError)("HUBService: cluster node not found");
|
121
|
-
return;
|
122
|
-
}
|
123
|
-
clusterNode.ws = clusterNode.ws.filter(x => x !== conn);
|
124
|
-
(0, LogService_1.logInfo)("HUBService: connection closed");
|
125
|
-
if (!clusterNode.ws.length) {
|
126
|
-
(0, LogService_1.logInfo)("HUBService: cluster node disconnected");
|
127
|
-
this.nodes.delete(conn.options.targetID);
|
128
|
-
}
|
129
|
-
}
|
130
|
-
}
|
131
|
-
exports.HUBService = HUBService;
|
132
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiSFVCU2VydmljZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9hcGlTZXJ2ZXIvSFVCU2VydmljZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7QUFBQSwyQkFBZ0Q7QUFDaEQsNkNBQStDO0FBQy9DLCtDQUE0QztBQUM1QywyREFBd0Q7QUFDeEQsNkNBQWlEO0FBQ2pELG1EQUE2QztBQUU3QywrRUFBdUQ7QUEwQjFDLFFBQUEsZ0JBQWdCLEdBQUcsSUFBSSxvQkFBRyxDQUFzRCxTQUFTLEVBQUUsa0JBQWtCLENBQUMsQ0FBQztBQUU1SCxNQUFhLFVBQVcsU0FBUSx5QkFBVztJQUUxQyxPQUFPLENBQW9CO0lBQzNCLEtBQUssR0FBOEIsSUFBSSxHQUFHLEVBQUUsQ0FBQztJQUM3QyxRQUFRLEdBQThELEVBQUUsQ0FBQztJQUV6RSxZQUFZLE9BQTBCO1FBQ3JDLEtBQUssQ0FBQyxZQUFZLENBQUMsQ0FBQTtRQUNuQixJQUFJLENBQUMsT0FBTyxHQUFHLE9BQU8sQ0FBQztRQUN2QixJQUFJLENBQUMsUUFBUSxHQUFHO1lBQ2YsSUFBSSxvQkFBRyxDQUF3QyxLQUFLLEVBQUUsR0FBRyxFQUFFLEVBQUU7Z0JBRTVELElBQUcsQ0FBQyxHQUFHLENBQUMsSUFBSSxJQUFJLENBQUMsS0FBSyxDQUFDLE9BQU8sQ0FBQyxHQUFHLENBQUMsSUFBSSxDQUFDO29CQ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AAC,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC;QAExD,IAAA,oBAAO,EAAC,+BAA+B,CAAC,CAAA;QACxC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE;YAC3B,IAAA,oBAAO,EAAC,uCAAuC,CAAC,CAAA;YAChD,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;SACzC;IACF,CAAC;CACD;AAxJD,gCAwJC","sourcesContent":["import WebSocket, { WebSocketServer } from \"ws\";\nimport { REQ_HTTP_SERVER } from \"./APIService\";\nimport { BaseService } from \"./BaseService\";\nimport { HUBConnection } from \"./cluster/HUBConnection\";\nimport { logError, logInfo } from \"./LogService\";\nimport Signal, { Req } from \"badmfck-signal\";\nimport { IError } from \"./structures/Interfaces\";\nimport DefaultErrors from \"./structures/DefaultErrors\";\nimport { IPartyHost } from \"./ClusterService\";\n\n\nexport interface HUBServiceOptions {\n\thostID: string,\n\thostPublicKey: string,\n\thostPrivateKey: string,\n\thostURL: string,\n}\n\nexport interface IClusterNode {\n\tclusterID: string,\n\turl: string,\n\tpublicKey: string,\n\tprivateKey: string,\n\tws: HUBConnection[],\n\twatchlist:string[] // parties id that this cluster can connect to\n}\n\nexport interface IWebsocketPacket<T = any> {\n\tdata: T,\n\tauthorized: boolean\n\tconnection: HUBConnection\n}\n\nexport const REQ_CLUSTER_NODE = new Req<string, { url: string, publicKey: string } | IError>(undefined, \"REQ_CLUSTER_NODE\");\n\nexport class HUBService extends BaseService {\n\n\toptions: HUBServiceOptions;\n\tnodes: Map<string, IClusterNode> = new Map();\n\thandlers: (Signal<IWebsocketPacket> | Req<IWebsocketPacket, any>)[] = [];\n\n\tconstructor(options: HUBServiceOptions) {\n\t\tsuper(\"HUBService\")\n\t\tthis.options = options;\n\t\tthis.handlers = [\n\t\t\tnew Req<IWebsocketPacket, IPartyHost[]|IError>(async (req) => {\n\t\t\t\t// check incoming params\n\t\t\t\tif(!req.data || !Array.isArray(req.data))\n\t\t\t\t\treturn {...DefaultErrors.BAD_REQUEST,details:\"data array is not set\"}\n\n\t\t\t\t// get incoming cluster\n\t\t\t\tconst incomingCluster = this.nodes.get(req.connection.options.targetID ?? \"\");\n\t\t\t\tif(!incomingCluster)\n\t\t\t\t\treturn {...DefaultErrors.BAD_REQUEST,details:\"cluster for incoming connection not found\"}\n\n\t\t\t\t// check\n\t\t\t\tconst result = []; \n\t\t\t\tfor(let i of req.data){\n\t\t\t\t\tconst clusterNode = this.nodes.get(i);\n\t\t\t\t\tif(clusterNode){\n\t\t\t\t\t\tresult.push({\n\t\t\t\t\t\t\turl:clusterNode.url,\n\t\t\t\t\t\t\tpublicKey:clusterNode.publicKey,\n\t\t\t\t\t\t\tid:clusterNode.clusterID\t\t\n\t\t\t\t\t\t})\n\t\t\t\t\t}\n\n\t\t\t\t\tif(incomingCluster.watchlist.filter(x=>x===i).length===0)\n\t\t\t\t\t\tincomingCluster.watchlist.push(i+\"\");\n\t\t\t\t}\n\n\t\t\t\treturn result;\n\n\t\t\t}, \"REQ_PARTY\")\n\t\t];\n\t}\n\n\tasync init() {\n\t\tsuper.init();\n\t}\n\n\tasync applicationReady() {\n\t\tconst server = await REQ_HTTP_SERVER.request();\n\n\t\tconst wss = new WebSocketServer({\n\t\t\tserver: server.http,\n\t\t\tpath: \"/hub\"\n\t\t})\n\n\t\twss.on(\"connection\", (ws) => {\n\t\t\tconst conn: HUBConnection = new HUBConnection({\n\t\t\t\tws: ws,\n\t\t\t\tdirection: \"incoming\",\n\n\t\t\t\thostID: this.options.hostID,\n\t\t\t\thostPrivateKey: this.options.hostPrivateKey,\n\t\t\t\thostPublicKey: this.options.hostPublicKey,\n\t\t\t\thostURL: this.options.hostURL + \"/hub\",\n\n\t\t\t\t// will be filled after authorization\n\t\t\t\ttargetID: null,\n\t\t\t\ttargetPublicKey: null,\n\t\t\t\ttargetURL: null,\n\n\t\t\t\tonAuthorized: () => this.onConnectionAuthorized(conn),\n\t\t\t\tonClose: () => this.onConnectionClosed(conn),\n\t\t\t\thandlers: this.handlers\n\t\t\t})\n\t\t})\n\n\t\twss.on(\"error\", (err) => {\n\t\t\tconsole.error(\"HUBService: error: \", err)\n\t\t})\n\n\t}\n\n\tonConnectionAuthorized(conn: HUBConnection) {\n\t\t\n\t\tif (!conn.options.targetID) {\n\t\t\tlogError(\"HUBService: connection targetID is not set\")\n\t\t\treturn;\n\t\t}\n\n\t\tlet clusterNode = this.nodes.get(conn.options.targetID)\n\n\t\tif (!clusterNode) {\n\t\t\tlogInfo(\"HUBService: new cluster node connected\")\n\t\t\tclusterNode = {\n\t\t\t\tclusterID: conn.options.targetID,\n\t\t\t\turl: conn.options.targetURL!,\n\t\t\t\tpublicKey: conn.options.targetPublicKey!,\n\t\t\t\tprivateKey: conn.options.hostPrivateKey,\n\t\t\t\tws: [],\n\t\t\t\twatchlist:[]\n\t\t\t}\n\t\t\tthis.nodes.set(conn.options.targetID, clusterNode);\n\t\t}\n\n\t\tclusterNode.ws.push(conn);\n\t\tlogInfo(\"HUBService: new authorized connection added to cluster node\")\n\n\t\t// FIND IN WATCHLIST\n\t\tfor(let [id,cluster] of this.nodes){\n\t\t\tconsole.log(\"find id in watchlist throught clusters\")\n\t\t\tfor(let i of cluster.watchlist){\n\t\t\t\tif(i===clusterNode.clusterID){\n\t\t\t\t\t// send to cluster\n\t\t\t\t\tcluster.ws.forEach(x=>{\n\t\t\t\t\t\tx.send({\n\t\t\t\t\t\t\tmethod:\"S_PARTY_AVAILABLE\",\n\t\t\t\t\t\t\tdata:{\n\t\t\t\t\t\t\t\turl:clusterNode!.url,\n\t\t\t\t\t\t\t\tpublicKey:clusterNode!.publicKey,\n\t\t\t\t\t\t\t\tid:clusterNode!.clusterID\t\t\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tcallbackID:1\n\t\t\t\t\t\t})\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t}\n\n\n\tonConnectionClosed(conn: HUBConnection) {\n\t\t\n\t\tif (!conn.options.targetID) {\n\t\t\tlogError(\"HUBService: connection targetID is not set\")\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tconst clusterNode = this.nodes.get(conn.options.targetID);\n\n\t\tif (!clusterNode) {\n\t\t\tlogError(\"HUBService: cluster node not found\")\n\t\t\treturn;\n\t\t}\n\n\t\tclusterNode.ws = clusterNode.ws.filter(x => x !== conn);\n\n\t\tlogInfo(\"HUBService: connection closed\")\n\t\tif (!clusterNode.ws.length) {\n\t\t\tlogInfo(\"HUBService: cluster node disconnected\")\n\t\t\tthis.nodes.delete(conn.options.targetID);\n\t\t}\n\t}\n}"]}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"LocalRequest.js","sourceRoot":"","sources":["../../src/apiServer/LocalRequest.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAwE;AAsCjE,MAAM,YAAY,GAAG,KAAK,EAAE,EAAU,EAAE,IAAU,EAAE,MAAe,EAAC,OAA8B,EAAE,EAAE;IAC5G,IAAI,CAAC,GAAG,KAAK,CAAA;IACb,IAAI,MAAM;QACT,CAAC,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC;IAC1B,IAAI,IAAI,IAAI,CAAC,MAAM;QAClB,CAAC,GAAG,MAAM,CAAA;IAEX,IAAI,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC;QACrB,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;IACrB,IAAI,GAAG,GAAG,wBAAwB,GAAG,EAAE,CAAC;IAExC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC;QACtC,GAAG,GAAG,EAAE,CAAC;IAEV,IAAI,IAAI,GAAG,IAAI,CAAC;IAChB,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,GAAG,CAAC,CAAA;IAC9B,IAAI;QACH,IAAI,CAAC,KAAK,KAAK;YACd,IAAI,GAAG,MAAM,eAAK,CAAC,GAAG,CAAC,GAAG,EAAC,EAAC,OAAO,EAAC,OAAO,EAAC,CAAC,CAAC;QAC/C,IAAI,CAAC,KAAK,MAAM;YACf,IAAI,GAAG,MAAM,eAAK,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,EAAC,EAAC,OAAO,EAAC,OAAO,EAAC,CAAC,CAAA;KACrD;IAAC,OAAO,CAAC,EAAE;QACX,OAAO,CAAC,GAAG,CAAC,sBAAsB,EAAC,CAAC,CAAC,CAAA;KACrC;IACD,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;AAClB,CAAC,CAAA;AAzBY,QAAA,YAAY,gBAyBxB","sourcesContent":["import axios, { AxiosResponse, InternalAxiosRequestConfig } from \"axios\"\n\n/*axios.interceptors.request.use((x:InternalAxiosRequestConfig<any>)=>{\n\tconsole.log(`AXIOS REQ:\\n\\turl:${x.url}\\n\\tmethod: ${x.method}\\n\\tdata: ${(()=>{\n\t\tif(typeof x.data === \"string\" )\n\t\t\treturn x.data\n\n\t\treturn JSON.stringify(x.data,null,\"\\t\\t\");\n\t})()}\\n\\theaders:\\n${(()=>{\n\t\tlet h = \"\";\n\t\tfor(let i in x.headers){\n\t\t\tif(h!==\"\")\n\t\t\t\th+=\"\\n\"\n\t\t\th+=\"\\t\\t\"+i+\" = \"+x.headers[i]\n\t\t}\n\t\treturn h\n\t})()}`)\n\treturn x;\n})\n\naxios.interceptors.response.use((x:AxiosResponse)=>{\n\tconsole.log(`AXIOS RESP:\\n\\tdata: ${(()=>{\n\t\tif(typeof x.data === \"string\" )\n\t\t\treturn x.data\n\n\t\treturn JSON.stringify(x.data,null,\"\\t\\t\");\n\t})()}\\n\\theaders:\\n${(()=>{\n\t\tlet h = \"\";\n\t\tfor(let i in x.headers){\n\t\t\tif(h!==\"\")\n\t\t\t\th+=\"\\n\"\n\t\t\th+=\"\\t\\t\"+i+\" = \"+x.headers[i]\n\t\t}\n\t\treturn h\n\t})()}`)\n\treturn x;\n})*/\n\nexport const LocalRequest = async (ep: string, data?: any, method?: string,headers?:{[key:string]:string}) => {\n\tlet m = \"get\"\n\tif (method)\n\t\tm = method.toLowerCase();\n\tif (data && !method)\n\t\tm = \"post\"\n\n\tif (ep.startsWith(\"/\"))\n\t\tep = ep.substring(1)\n\tlet url = \"http://localhost:8091/\" + ep;\n\t\n\tif (ep.toLowerCase().startsWith(\"http\"))\n\t\turl = ep;\n\n\tlet resp = null;\n\tconsole.log(\"open url: \", url)\n\ttry {\n\t\tif (m === \"get\")\n\t\t\tresp = await axios.get(url,{headers:headers});\n\t\tif (m === \"post\")\n\t\t\tresp = await axios.post(url, data,{headers:headers})\n\t} catch (e) {\n\t\tconsole.log(\"ERROR! cant open url\",e)\n\t}\n\tconsole.log(resp)\n}\n"]}
|