badmfck-api-server 2.4.7 → 2.5.1
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/apiServer/APIService.js +8 -4
- package/dist/apiServer/APIService.js.map +1 -0
- package/dist/apiServer/BaseEndpoint.js +1 -0
- package/dist/apiServer/BaseEndpoint.js.map +1 -0
- package/dist/apiServer/BaseService.js +1 -0
- package/dist/apiServer/BaseService.js.map +1 -0
- package/dist/apiServer/ClusterService.d.ts +18 -5
- package/dist/apiServer/ClusterService.js +45 -14
- package/dist/apiServer/ClusterService.js.map +1 -0
- package/dist/apiServer/DocumentService.js +1 -0
- package/dist/apiServer/DocumentService.js.map +1 -0
- package/dist/apiServer/HUBService.d.ts +11 -4
- package/dist/apiServer/HUBService.js +79 -18
- package/dist/apiServer/HUBService.js.map +1 -0
- package/dist/apiServer/LocalRequest.js +1 -0
- package/dist/apiServer/LocalRequest.js.map +1 -0
- package/dist/apiServer/LogService.js +1 -0
- package/dist/apiServer/LogService.js.map +1 -0
- package/dist/apiServer/MysqlService.js +4 -3
- package/dist/apiServer/MysqlService.js.map +1 -0
- package/dist/apiServer/WSAPITransport.js +1 -0
- package/dist/apiServer/WSAPITransport.js.map +1 -0
- package/dist/apiServer/WebSocketHandler.d.ts +0 -0
- package/dist/apiServer/WebSocketHandler.js +2 -0
- package/dist/apiServer/WebSocketHandler.js.map +1 -0
- package/dist/apiServer/WebsocketService.js +1 -0
- package/dist/apiServer/WebsocketService.js.map +1 -0
- package/dist/apiServer/cluster/HUBConnection.d.ts +25 -25
- package/dist/apiServer/cluster/HUBConnection.js +107 -88
- package/dist/apiServer/cluster/HUBConnection.js.map +1 -0
- package/dist/apiServer/cluster/HUBHandlres.d.ts +0 -0
- package/dist/apiServer/cluster/HUBHandlres.js +2 -0
- package/dist/apiServer/cluster/HUBHandlres.js.map +1 -0
- package/dist/apiServer/deployment/Deployment.js +1 -0
- package/dist/apiServer/deployment/Deployment.js.map +1 -0
- package/dist/apiServer/helper/DataProvider.js +1 -0
- package/dist/apiServer/helper/DataProvider.js.map +1 -0
- package/dist/apiServer/helper/Sleep.d.ts +1 -0
- package/dist/apiServer/helper/Sleep.js +6 -0
- package/dist/apiServer/helper/Sleep.js.map +1 -0
- package/dist/apiServer/helper/UID.js +1 -0
- package/dist/apiServer/helper/UID.js.map +1 -0
- package/dist/apiServer/helper/Validator.js +1 -0
- package/dist/apiServer/helper/Validator.js.map +1 -0
- package/dist/apiServer/monitor/Monitor.js +1 -0
- package/dist/apiServer/monitor/Monitor.js.map +1 -0
- package/dist/apiServer/routes/Liveness.js +1 -0
- package/dist/apiServer/routes/Liveness.js.map +1 -0
- package/dist/apiServer/routes/Readiness.js +1 -0
- package/dist/apiServer/routes/Readiness.js.map +1 -0
- package/dist/apiServer/structures/DefaultErrors.js +1 -0
- package/dist/apiServer/structures/DefaultErrors.js.map +1 -0
- package/dist/apiServer/structures/HTTPStatus.js +1 -0
- package/dist/apiServer/structures/HTTPStatus.js.map +1 -0
- package/dist/apiServer/structures/Interfaces.js +1 -0
- package/dist/apiServer/structures/Interfaces.js.map +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -0
- package/package.json +2 -2
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"MysqlService.js","sourceRoot":"","sources":["../../src/apiServer/MysqlService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,+CAA4C;AAC5C,iEAA6C;AAC7C,mCAAqE;AACrE,6CAAmE;AACnE,sDAAuC;AACvC,4CAAmB;AACnB,gDAAuB;AAGV,QAAA,eAAe,GAAC,IAAI,wBAAM,EAAQ,CAAA;AAClC,QAAA,eAAe,GAAG,IAAI,oBAAG,CAAwC,SAAS,EAAC,iBAAiB,CAAC,CAAC;AAG9F,QAAA,gBAAgB,GAAG,IAAI,oBAAG,CAAyB,SAAS,EAAC,8BAA8B,CAAC,CAAC;AAC7F,QAAA,gBAAgB,GAAC,IAAI,oBAAG,CAA4C,SAAS,EAAC,qCAAqC,CAAC,CAAC;AACrH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Q,CAAC,MAAM,CAAC,SAAS,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;QAC7D,SAAS,IAAI,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QACpC,OAAO,SAAS,CAAC;KACpB;IAAA,OAAM,CAAC,EAAC;QACL,OAAO,IAAI,CAAC;KACf;AACH,CAAC,CAAA;AAED,MAAM,OAAO,GAAG,CAAC,GAAU,EAAa,EAAE;IACxC,IAAG;QACC,IAAI,QAAQ,GAAG,IAAA,uBAAc,EAAC,aAAa,EAAE,GAAG,EAAE,EAAE,CAAC,EACrD,SAAS,GAAG,QAAQ,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;QACnD,SAAS,IAAI,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QACtC,OAAO,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;KAC9D;IAAA,OAAM,CAAC,EAAC;QACL,OAAO,IAAI,CAAC;KACf;AACH,CAAC,CAAA;AAED,kBAAe,YAAY,CAAC","sourcesContent":["//import mysql, { FieldInfo, MysqlError, Pool, PoolConnection } from \"mysql\"\n\nimport { BaseService } from \"./BaseService\";\nimport Signal, { Req } from \"badmfck-signal\";\nimport { createCipheriv, createDecipheriv, createHash } from \"crypto\"\nimport { logCrit, logError, logInfo, logWarn } from \"./LogService\";\nimport * as mysql from \"mysql2/promise\"\nimport fs from \"fs\"\nimport path from \"path\"\nimport { IError } from \"./structures/Interfaces\";\n\nexport const S_MYSQL_STARTED=new Signal<void>()\nexport const REQ_MYSQL_QUERY = new Req<MySqlQuery|MySqlQuery[],MysqlResult[]>(undefined,\"REQ_MYSQL_QUERY\");\n//export const REQ_MYSQL_TRANSACTION = new Req<MySqlQuery[],MysqlResult>(undefined,\"REQ_MYSQL_TRANSACTION\");\n\nexport const REQ_MYSQL_TBEGIN = new Req<void,MysqlError|number>(undefined,\"REQ_MYSQL_TRANSACTION_BEGING\"); // return transaction id or mysql error\nexport const REQ_MYSQL_TQUERY=new Req<{query:MySqlQuery,tid:number},MysqlResult>(undefined,\"REQ_MYSQL_TRANSACTION_ADD_OPERATION\"); // tid means transaction id\nexport const REQ_MYSQL_TCOMMIT=new Req<number,MysqlError|null>(undefined,\"REQ_MYSQL_TCOMMIT\"); // tid\nexport const REQ_MYSQL_TROLLBACK=new Req<number,MysqlError|null>(undefined,\"REQ_MYSQL_TROLLBACK\"); // tid\n\nexport const executeQuery = async (query:MySqlQuery|MySqlQuery[]):Promise<MysqlResult[]>=>{return await REQ_MYSQL_QUERY.request(query)}\n\nexport interface MysqlServiceOptions{\n connectionLimit:number,\n host:string,\n user:string,\n password:string,\n port:number,\n database:string, \n queueLimit?:number,\n transactionFailReport?:(trx:ITransaction,message:string)=>void,\n transactionFailReportDir?:string,\n debug?:boolean,\n naxTransactionWaitTime?:number,\n\tmigrations?:{\n\t\tdir:string,\n\t\tcallback:()=>void\n\t}|null\n}\n\nexport interface MysqlError{\n code: string,\n errno: number,\n sql: string,\n name:string,\n message:string\n fatal?:boolean\n}\n\nexport interface MysqlResult{\n error?:MysqlError|null,\n rollbackError?:MysqlError|null,\n isDuplicateError?:boolean\n data:any\n}\n\nexport interface MySqlQuery{\n query:string\n fields:MysqlQueryField[]|MysqlQueryFieldObject,\n rollbackQuery?:string|null\n transactionID?:number\n}\n\nexport interface MysqlQueryField{\n name:string,\n value:string|number|boolean|null|undefined,\n system?:boolean,\n ignoreInInsert?:boolean,\n ignoreInUpdate?:boolean\n useInReplace?:boolean,\n _parsedValue?:string|number|boolean|null\n}\n\nexport interface ITransaction{\n id:number\n timestamp:number,\n conn:mysql.PoolConnection,\n queries:{sql:string,status:string}[]\n}\n\nexport interface MysqlQueryFieldObject extends Record<string,string|number|boolean|null|undefined|{name?:string|null,value:string|number|boolean|null|undefined,system?:boolean,ignoreInInsert?:boolean,ignoreInUpdate?:boolean,useInReplace?:boolean}>{\n\n}\n \n\n/**\n * Mysql Services, execute queries\n * MySqlQuery.query:\n * @fields - replaced by field's names\n * @values - replaced by parsed values\n * @onupdate - repalced by pair field name = value\n * @onduplicate - replaced by pair field name = value\n */\n\nexport class MysqlService extends BaseService{\n\n reconnectionTimeout=1000*3;\n reconnecting=false;\n pool:mysql.Pool|null=null;\n options:MysqlServiceOptions;\n serviceStarted=false;\n timeoutID:any\n\n debug=false;\n\n queries=[]; // TODO: STORE QUERIES SENTS BEFORE THE SERVICE IS STARTED!\n static nextTransactionID=1;\n transactions:ITransaction[]=[]\n\n maxTransactionWaitTime = 1000*60*1; // 1 min and detelete transaction\n\n failReportFileStream:fs.WriteStream|null=null;\n failReportFileStreamName:string|null=null;\n failReportLastAccessTime:number=0;\n\n constructor(options:MysqlServiceOptions){\n super(\"mysql\");\n this.options = options;\n \n\n // decrypt when needed\n if(this.options.host.startsWith(\"_\"))\n this.options.host = decrypt(this.options.host.substring(1)) ?? this.options.host\n if(this.options.user.startsWith(\"_\"))\n this.options.user = decrypt(this.options.user.substring(1)) ?? this.options.user\n if(this.options.database.startsWith(\"_\"))\n this.options.database = decrypt(this.options.database.substring(1)) ?? this.options.database\n if(this.options.password.startsWith(\"_\"))\n this.options.password = decrypt(this.options.password.substring(1)) ?? this.options.password\n\n if(this.options.debug)\n this.debug = true\n if(this.options.naxTransactionWaitTime)\n this.maxTransactionWaitTime = this.options.naxTransactionWaitTime;\n\n setInterval(()=>{\n // check transactions\n const now = Date.now();\n const count = this.transactions.length;\n const removedIDs:number[]=[];\n for(let i of this.transactions){\n if(now-i.timestamp>this.maxTransactionWaitTime){\n logError(\"Release transaction connection due to timeout\")\n this.rollbackTransaction(i,true);\n removedIDs.push(i.id)\n }\n }\n\n this.transactions = this.transactions.filter(i=>!removedIDs.includes(i.id))\n \n if(this.debug)\n console.log(\"Removed: \",count-this.transactions.length)\n\n \n\n },1000*30)\n\n setInterval(()=>{\n if(!this.failReportFileStream)\n return;\n \n // after 15 min of inactivity, close file\n if(Date.now()-this.failReportLastAccessTime>1000*60*15){\n this.failReportFileStream.end();\n this.failReportFileStream=null;\n }\n\n },1000*60*5)\n\n if(options.transactionFailReportDir){\n try{\n if (!fs.existsSync(options.transactionFailReportDir)){\n fs.mkdirSync(options.transactionFailReportDir);\n }\n }catch(e){\n options.transactionFailReportDir=undefined;\n logCrit(\"${MysqlService.js}\",\"Can't create transaction fail report dir\")\n }\n }\n }\n\n static async executeQuery (query:MySqlQuery|MySqlQuery[]):Promise<MysqlResult[]>{ return await REQ_MYSQL_QUERY.request(query) }\n\n async init(){\n super.init();\n\n // setup process exit handlers interrupt (ctrl+c)\n process.on('SIGINT', async () => {\n await this.finishApp();\n process.exit(0);\n });\n \n // terminate (kill)\n process.on('SIGTERM',async () => {\n await this.finishApp();\n process.exit(0);\n });\n\n this.serviceStarted=false;\n let poolCreated:boolean = false;\n\n while(!poolCreated){\n logInfo(\"${MysqlService.js}\",\"Connecting to MYSQL!\")\n poolCreated = await this.recreatePool();\n if(!poolCreated){\n logCrit(\"${MysqlService.js}\",\"Can't connect to MYSQL! Retrying in 3 seconds...\")\n await new Promise((resolve)=>setTimeout(resolve,3000))\n }\n }\n\n REQ_MYSQL_QUERY.listener=async data =>{\n if(!Array.isArray(data))\n data=[data];\n const promises=[]\n for(let i of data){\n const query = MysqlService.prepareQuery(i.query,i.fields);\n promises.push(this.execute(query,i.rollbackQuery ?? null,i.transactionID ?? 0));\n }\n \n if(this.debug)\n console.log(\"Execute queries: \",data.length)\n \n return await Promise.all(promises);\n }\n\n REQ_MYSQL_TBEGIN.listener=async ()=>{ \n const conn = await this.pool?.getConnection();\n if(!conn)\n return {code:\"NO_POOL\",errno:100000,fatal:true,sql:\"\",name:\"NO_POOL\",message:\"Mysql pool not created\"}\n\n // find conn in transactions\n for(let i of this.transactions){\n if(i.conn===conn){\n logInfo(\"Your connection is in transaction\")\n return {code:\"CONN_IN_TRX\",errno:100005,fatal:true,sql:\"\",name:\"CONN_IN_TRX\",message:\"Connection is in transaction\"}\n }\n }\n\n const tid = MysqlService.nextTransactionID++;\n if(this.debug)\n console.log(\"Begin transaction with id \",tid)\n\n try{\n \n // await conn.beginTransaction();\n await conn.query(\"START TRANSACTION\");\n //const res = await conn.query(\"SET autocommit=0\");\n if(this.debug)\n console.log(\"Transaction started\")\n\n }catch(e){\n this.rollbackTransaction({id:tid,conn:conn,timestamp:Date.now(),queries:[{sql:\"START TRANSACTION\",status:\"error\"}]})\n return this.createMysqlQueryError(e);\n }\n\n this.transactions.push({\n id:tid,\n timestamp:Date.now(),\n conn:conn,\n queries:[]\n })\n\n if(this.debug)\n console.log(\"Transactions pool: \",this.transactions)\n\n return tid;\n }\n \n REQ_MYSQL_TQUERY.listener=async data=>{\n const trx = this.transactions.find(i=>i.id===data.tid);\n if(!trx)\n return {err: {\n code:\"NO_TRX\",\n errno:100004,\n fatal:true,\n sql:\"\",\n name:\"NO_TRX\",\n message:\"Transaction not found\"\n },data:null,rollbackError:null}\n\n const query = MysqlService.prepareQuery(data.query.query,data.query.fields);\n let err=null;\n let sqlData = null;\n\n if(this.debug)\n console.log(\"Execute query on transaction: \",trx)\n\n try{\n sqlData = await trx.conn.query(query);\n }catch(e){ err = this.createMysqlQueryError(e);}\n\n if(err)\n this.rollbackTransaction(trx);\n\n if(this.debug)\n console.log(\"Query execution status:\",err?err.message:\"completed\")\n\n trx.queries.push({sql:query,status:err?err.message:\"completed\"})\n\n return {\n data:sqlData?sqlData[0]:null,\n error:err,\n };\n }\n\n REQ_MYSQL_TROLLBACK.listener=async (tid:number)=>{\n const trx = this.transactions.find(i=>i.id===tid);\n if(!trx){\n return {\n code:\"NO_TRX\",\n errno:100004,\n fatal:true,\n sql:\"\",\n name:\"NO_TRX\",\n message:\"Transaction not found\"\n }\n }\n\n await this.rollbackTransaction(trx);\n return null;\n }\n\n REQ_MYSQL_TCOMMIT.listener=async (tid:number)=>{\n const trx = this.transactions.find(i=>i.id===tid);\n if(!trx){\n return {\n code:\"NO_TRX\",\n errno:100004,\n fatal:true,\n sql:\"\",\n name:\"NO_TRX\",\n message:\"Transaction not found\"\n }\n }\n\n\n if(this.debug)\n console.log(\"Commit transaction:\",trx)\n \n // remove from transactions\n this.transactions = this.transactions.filter(i=>i.id!==tid);\n\n if(this.debug)\n console.log(\"Transaction pool:\",this.transactions )\n \n const err = await this.commit(trx);\n\n return err;\n }\n }\n\n async commit(trx:ITransaction):Promise<MysqlError|null>{\n \n try{\n await trx.conn.commit();\n //await trx.conn.query(\"COMMIT\");\n trx.conn.removeAllListeners();\n trx.conn.release();\n }catch(e){\n await this.rollbackTransaction(trx);\n return this.createMysqlQueryError(e);\n }\n return null;\n\n }\n\n async rollbackTransaction(trx:ITransaction,donNotRemove?:boolean):Promise<MysqlError|null>{\n let err=null;\n try{\n console.log(\"Rollback started\",trx.conn)\n await trx.conn.rollback();\n await trx.conn.commit();\n //await trx.conn.query(\"ROLLBACK\");\n trx.conn.removeAllListeners();\n trx.conn.release();\n if(!donNotRemove)\n this.transactions = this.transactions.filter(i=>i.id!==trx.id);\n if(this.debug)\n console.log(\"Rollback complete\",trx.conn)\n }catch(e){\n logCrit(\"${MysqlService.js}\",\"Can't rollback transaction\",trx)\n err = this.createMysqlQueryError(e);\n }\n this.storeTransactionAsProblem(trx,\"rollback\")\n return err;\n }\n\n async finishApp(){\n console.log(\"Finishing mysql service\")\n for(let i of this.transactions)\n this.rollbackTransaction(i);\n\n if(this.pool){\n try{await this.pool.end();}catch(e){\n logCrit(\"${MysqlService.js}\",\"Can't close MYSQL pool!\")\n }\n }\n\n if(this.failReportFileStream)\n this.failReportFileStream.end();\n this.failReportFileStream=null;\n }\n\n async storeTransactionAsProblem(trx:ITransaction,message:string){\n\n if(!this.options.transactionFailReport && !this.options.transactionFailReportDir){\n logCrit(\"${MysqlService.js}\",\"Can't report failed transaction, no report function: transactionFailReport in options, and transactionFailReportDir isnt set\")\n return;\n }\n\n\n if(this.options.transactionFailReportDir){\n const yyymmdd = new Date().toISOString().substring(0,10).replaceAll(\"-\",\"\");\n\n //store transaction\n const date = new Date();\n const file = path.resolve(this.options.transactionFailReportDir,yyymmdd+\".json\");\n if(this.failReportFileStream){\n if(this.failReportFileStreamName!==file){\n this.failReportFileStream.end();\n this.failReportFileStream=null;\n }\n }\n\n\n if(this.failReportFileStreamName){\n this.failReportFileStream = fs.createWriteStream(file,{flags:'a'});\n this.failReportFileStreamName=file;\n }\n \n if(this.debug)\n console.log(\"Store transaction fail report: \",file,trx,message)\n\n if(!this.failReportFileStream)\n this.failReportFileStream = fs.createWriteStream(file,{flags:'a'});\n\n this.failReportFileStream.write(JSON.stringify({queries:trx.queries,time:trx.timestamp,date,message})+\"\\n}EOB{\\n\",err=>{\n if(err)\n logCrit(\"${MysqlService.js}\",\"Can't write to transaction fail report file\")\n else\n logInfo(\"${MysqlService.js}\",\"Transaction fail report stored\")\n });\n\n this.failReportLastAccessTime = Date.now();\n\n }\n\n \n if(this.options.transactionFailReport)\n this.options.transactionFailReport(trx,message);\n }\n\n\n async recreatePool():Promise<boolean>{\n\n logInfo(\"${MysqlService.js}\",\"Connecting to mysql: \\n HOST: \"+this.options.host+'\\n PORT:'+this.options.port)\n\n if(this.pool){\n this.pool.removeAllListeners();\n try{await this.pool.end();}catch(e){\n logCrit(\"${MysqlService.js}\",\"Can't close MYSQL pool!\")\n }\n this.pool = null;\n }\n\n try{\n this.pool =mysql.createPool({\n host: this.options.host\n ,user: this.options.user\n ,password: this.options.password\n ,database: this.options.database\n ,port: this.options.port\n ,connectionLimit: this.options.connectionLimit\n ,queueLimit: 10\n ,multipleStatements: true\n });\n }catch(e){\n logCrit(\"${MysqlService.js}\",\"Can't connect to MYSQL!\")\n return false;\n }\n\n this.pool?.on('connection', (connection) => {\n logInfo(\"${MysqlService.js}\",\"MYSQL CONNECTION CREATED\")\n });\n this.pool?.on('acquire', (connection) => {\n logInfo(\"${MysqlService.js}\",\"MYSQL CONNECTION ACQUIRED\")\n })\n this.pool?.on('release', (connection) => {\n logInfo(\"${MysqlService.js}\",\"MYSQL CONNECTION RELEASED\")\n })\n this.pool?.on('enqueue', () => {\n logInfo(\"${MysqlService.js}\",\"MYSQL CONNECTION ENQUEUED\")\n })\n \n // Check connection\n if(this.debug)\n console.log(\"Check mysql connection\")\n return new Promise(async (resolve,reject)=>{\n try{\n const conn = await this.pool?.getConnection()\n if(conn){\n conn?.release();\n logInfo(\"${MysqlService.js}\",\"Connected to MYSQL!\")\n resolve(true)\n \n }else\n resolve(false)\n }catch(e){\n logCrit(\"${MysqlService.js}\",\"Can't connect to MYSQL!\")\n resolve(false)\n }\n });\n\n }\n\n async onApplicationReady() {}\n\n\n static fieldsToObject(fields:MysqlQueryField[]|MysqlQueryFieldObject,ignoreSystemParameters?:boolean):MysqlQueryFieldObject{\n if(!Array.isArray(fields))\n return fields;\n const obj:MysqlQueryFieldObject={};\n for(let i of fields){\n if(!i.name)\n continue;\n if(typeof i.value!== \"object\")\n obj[i.name]=i.value;\n else{\n if(!ignoreSystemParameters){\n obj[i.name]={\n value:i.value,\n system:i.system,\n ignoreInInsert:i.ignoreInInsert,\n ignoreInUpdate:i.ignoreInUpdate,\n useInReplace:i.useInReplace,\n name:i.name\n }\n }else\n obj[i.name]=i.value\n }\n\n }\n return obj;\n }\n\n static objectToFields(obj:MysqlQueryFieldObject|MysqlQueryField[]):MysqlQueryField[]{\n if(Array.isArray(obj))\n return obj;\n const fields:MysqlQueryField[]=[];\n for(let i in obj){\n if(obj[i] && typeof obj[i] === \"object\"){\n let mo = obj[i] as Record<string,string|number|boolean|null|undefined>;\n if(!mo){\n mo={\n name:i,\n value:null,\n system:false,\n ignoreInInsert:false,\n ignoreInUpdate:false,\n useInReplace:false\n }\n }\n fields.push({\n name:mo.name as string ?? i,\n value:mo.value,\n system:mo.system as boolean,\n ignoreInInsert:mo.system as boolean,\n ignoreInUpdate:mo.system as boolean,\n useInReplace:mo.system as boolean\n })\n }else{\n fields.push({\n name:i,\n value:obj[i] as string|number|boolean|null|undefined\n })\n }\n }\n return fields;\n }\n\n static prepareQuery(query:string,fields:MysqlQueryField[]|MysqlQueryFieldObject):string{\n \n if(!Array.isArray(fields))\n fields = MysqlService.objectToFields(fields);\n\n for(let i of fields){\n const val =this.prepareQueryFieldValue(i.value,i.system);\n i._parsedValue=val;\n query=query.replaceAll(\"@\"+i.name,val+\"\")\n }\n\n const tmp = query.toLowerCase();\n if(tmp.indexOf(\"select\")===0 && tmp.indexOf(\"limit\")===-1)\n query+=\" LIMIT 100\"\n \n query = query.replaceAll(\"@NOLIMIT\",\"\")\n\n\n if(query.indexOf(\"@fields\")!==-1){\n let insertFieldNames=[]\n let insertFieldValues=[]\n for(let i of fields){\n if(i.ignoreInInsert)\n continue;\n\n insertFieldNames.push('`'+i.name.replaceAll(\"`\",'').replaceAll('\\\"',\"\").replaceAll('\\'',\"\")+'`')\n insertFieldValues.push(i._parsedValue)\n }\n\n query=query\n .replaceAll('@fields',insertFieldNames.join(\",\"))\n .replaceAll('@values',insertFieldValues.join(\",\"))\n }\n\n if(query.indexOf(\"@insert\")!==-1){\n let oninsertNames=[]\n let oninsertValues=[]\n for(let i of fields){\n if(i.ignoreInInsert)\n continue;\n oninsertNames.push(i.name)\n oninsertValues.push(i._parsedValue)\n }\n query = query.replaceAll(\"@insert\",`(${oninsertNames.join(\",\")}) VALUES (${oninsertValues.join(\",\")})`)\n }\n\n if(query.indexOf(\"@onupdate\")!==-1){\n let onUpdate=[]\n for(let i of fields){\n if(i.ignoreInUpdate)\n continue;\n onUpdate.push('`'+i.name.replaceAll(\"`\",'').replaceAll('\\\"',\"\").replaceAll('\\'',\"\")+'` = '+i._parsedValue)\n }\n query = query.replaceAll(\"@onupdate\",onUpdate.join(\" , \"))\n \n }\n\n if(query.indexOf('@onduplicate')!==-1){\n let onDuplicate=[];\n for(let i of fields){\n if(!i.useInReplace)\n continue;\n onDuplicate.push('`'+i.name.replaceAll(\"`\",'').replaceAll('\\\"',\"\").replaceAll('\\'',\"\")+'` = '+i._parsedValue)\n }\n query = query.replaceAll(\"@onduplicate\",onDuplicate.join(\" , \"))\n }\n \n \n return query;\n }\n\n static prepareQueryFieldValue(value:string|number|boolean|null|undefined,system?:boolean):string|number|boolean|null|undefined{\n if(!system && typeof value === \"string\"){\n value = value?value.replaceAll('\"','\\\\\"'):null\n if(value!==null)\n value = '\"'+value+'\"'\n else\n value = \"NULL\"\n }\n if(value === null || value === undefined)\n return \"NULL\"\n return value;\n }\n\n\n async execute(query:string,rollbackQuery:string|null,transactionID:number):Promise<MysqlResult>{\n return new Promise(async (resolve:(data:MysqlResult)=>void,reject)=>{\n // Check pool\n if(!this.pool){\n logError(\"${MysqlService.js}\",\"No pool\")\n resolve({\n error:{\n code: \"NO_POOL\",\n errno: 100000,\n fatal: true,\n sql: query,\n name:\"NO_POOL\",\n message:\"Mysql pool not created\"\n },\n data:null,\n })\n return;\n }\n\n \n try{\n let conn:mysql.PoolConnection|null=null\n if(transactionID && transactionID>0){\n conn = this.transactions.find(i=>i.id===transactionID)?.conn ?? null;\n if(this.debug)\n console.log(\"Execute query on transaction: \",conn)\n }else{\n conn = await this.pool.getConnection();\n }\n\n if(this.debug)\n console.log(\"Execute query\",conn)\n\n // if connection not created\n if(!conn){\n logCrit(\"${MysqlService.js}\",`No connection created!`)\n resolve({\n error:{\n code: \"NO_CONN\",\n errno: 100001,\n fatal: true,\n sql: query,\n name:\"NO_CONN\",\n message:\"Mysql pool cant get connection\"\n },\n data:null,\n })\n return;\n }\n\n // Do send query\n for(let i of this.transactions){\n if(i.conn===conn){\n logInfo(\"Your connection is in transaction\")\n break;\n }\n }\n this.sendQuery(conn,query,resolve,rollbackQuery);\n\n }catch(e){\n logError(\"${MysqlService.js}\",e);\n \n // recreate pool, connection error\n if(`${e}`.indexOf('ECONNREFUSED')!==-1)\n this.recreatePool();\n \n resolve({\n error:{\n code: \"NO_CONN\",\n errno: 100001,\n fatal: true,\n sql: query,\n name:\"NO_CONN\",\n message:(e && typeof e === \"object\" && \"message\" in e as any)?(e as any).message:\"Mysql cant get connection\"\n },\n data:null\n })\n return;\n }\n });\n }\n\n async sendQuery(conn:mysql.PoolConnection,query:string,resolve:(data:MysqlResult)=>void,rollback:string|null){\n \n let errCatched=false;\n\n conn.on(\"error\",async err=>{\n errCatched=true;\n\n let rollbackError = null;\n if(rollback)\n rollbackError=(await this.queryAsync(conn,rollback)).err\n \n logError(\"${MysqlService.js}->conn.on('error')\",err)\n\n // close conn on success\n try{\n conn.release();\n conn.removeAllListeners();\n }catch(e){}\n \n resolve({\n error:{\n code: \"CONN_ERR\",\n errno: 100003,\n fatal: true,\n sql: query,\n name:\"CONN_ERR\",\n message:\"Error: \"+err\n },\n data:null,\n rollbackError:rollbackError\n })\n })\n\n\n\n logInfo(\"${MysqlService.js}\",query)\n\n // send query\n const queryResult = await this.queryAsync(conn,query);\n\n // handle error\n if(queryResult.err){\n \n // rollback\n let rollbackError=null;\n if(rollback)\n rollbackError=(await this.queryAsync(conn,rollback)).err\n\n // close connection\n try{\n conn.release();\n conn.removeAllListeners();\n }catch(e){}\n\n // determine duplicate error\n const dup = `${queryResult.err}`.toLowerCase().indexOf(\"er_dup_entry\")!==-1;\n\n logError(\"${MysqlService.js}->query error\",queryResult.err);\n\n resolve({\n error:queryResult.err,\n data:null,\n rollbackError:rollbackError,\n isDuplicateError:dup\n })\n }\n\n\n // close conn on success\n try{\n conn.release();\n conn.removeAllListeners();\n }catch(e){}\n\n // handle success\n resolve({\n error:queryResult.err,\n data:queryResult.results,\n })\n\n }\n\n\n // Async query wrapper to conn.query\n async queryAsync(conn:mysql.PoolConnection,query:string):Promise<{err:MysqlError|null,results?:any}>{\n\n let result=null;\n try{\n result = await conn.query(query);\n }catch(e){\n return {err:this.createMysqlQueryError(e)};\n }\n\n return {\n err:null,\n results:result[0],\n }\n }\n\n createMysqlQueryError(err:any):MysqlError{\n if(err && typeof err===\"object\" && \"code\" in err && \"errno\" in err && \"sql\" in err && \"name\" in err && \"message\" in err){\n return {\n code: err.code,\n errno: err.errno,\n sql: err.sql,\n name:err.name,\n message:err.message\n \n }\n }else{\n return {\n code: \"QUERY_ERR\",\n errno: 100002,\n fatal: true,\n sql: \"no query\",\n name:\"QUERY_ERR\",\n message:\"Error: \"+(err)?err:\"\"\n }\n }\n }\n}\n\n\nconst secret_key=\"AKLWkajw%^&dgwqhw#98453i23bfk23rn2knknglrgjeit\"\nconst secret_iv=\"rthadrfk23rn2kn#*FNKA@gt44df3tslrgj##!it\"\n\n// Generate secret hash with crypto to use for encryption\nconst key = createHash('sha512').update(secret_key).digest('hex').substring(0, 32)\nconst iv = createHash('sha512').update(secret_iv).digest('hex').substring(0, 16)\n\nconst decrypt =(encrypted:string):string|null=>{\n try{\n encrypted = Buffer.from(encrypted, 'base64').toString('binary');\n const decipher = createDecipheriv('aes-256-cbc', key, iv);\n let decrypted = decipher.update(encrypted, 'binary', 'utf8');\n decrypted += decipher.final('utf8');\n return decrypted;\n }catch(e){\n return null;\n }\n}\n\nconst encrypt = (txt:string):string|null=>{\n try{\n let encipher = createCipheriv('aes-256-cbc', key, iv),\n encrypted = encipher.update(txt, 'utf8', 'binary');\n encrypted += encipher.final('binary');\n return Buffer.from(encrypted, 'binary').toString('base64');\n }catch(e){\n return null;\n }\n}\n\nexport default MysqlService;"]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"WSAPITransport.js","sourceRoot":"","sources":["../../src/apiServer/WSAPITransport.ts"],"names":[],"mappings":"","sourcesContent":[""]}
|
File without changes
|
@@ -0,0 +1,2 @@
|
|
1
|
+
"use strict";
|
2
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiV2ViU29ja2V0SGFuZGxlci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9hcGlTZXJ2ZXIvV2ViU29ja2V0SGFuZGxlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiIiwic291cmNlc0NvbnRlbnQiOlsiIl19
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"WebSocketHandler.js","sourceRoot":"","sources":["../../src/apiServer/WebSocketHandler.ts"],"names":[],"mappings":"","sourcesContent":[""]}
|
@@ -16,3 +16,4 @@ class WebsocketService extends BaseService_1.BaseService {
|
|
16
16
|
}
|
17
17
|
}
|
18
18
|
exports.WebsocketService = WebsocketService;
|
19
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiV2Vic29ja2V0U2VydmljZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9hcGlTZXJ2ZXIvV2Vic29ja2V0U2VydmljZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFBQSwrQ0FBNEM7QUFNNUMsTUFBTSxpQ0FBaUMsR0FBRyxHQUEyQixFQUFFO0lBQ25FLE9BQU8sRUFFTixDQUFBO0FBQ0wsQ0FBQyxDQUFBO0FBR0QsTUFBYSxnQkFBaUIsU0FBUSx5QkFBVztJQUM3QyxPQUFPLENBQTBCO0lBQ2pDLFlBQVksR0FBNkI7UUFDckMsS0FBSyxDQUFDLGtCQUFrQixDQUFDLENBQUM7UUFDMUIsSUFBSSxDQUFDLE9BQU8sR0FBRyxFQUFDLEdBQUcsaUNBQWlDLEVBQUUsRUFBQyxHQUFHLEVBQUMsQ0FBQTtJQUMvRCxDQUFDO0lBRUQsS0FBSyxDQUFDLElBQUk7UUFDTixLQUFLLENBQUMsSUFBSSxFQUFFLENBQUM7SUFDakIsQ0FBQztDQUNKO0FBVkQsNENBVUMiLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgeyBCYXNlU2VydmljZSB9IGZyb20gXCIuL0Jhc2VTZXJ2aWNlXCI7XG5cbmV4cG9ydCBpbnRlcmZhY2UgSVdlYlNvY2tldFNlcnZpY2VPcHRpb25ze1xuXG59XG5cbmNvbnN0IGdldERlZmF1bHRXZWJTb2NrZXRTZXJ2aWNlT3B0aW9ucyA9ICgpOklXZWJTb2NrZXRTZXJ2aWNlT3B0aW9ucz0+e1xuICAgIHJldHVybiB7XG5cbiAgICB9XG59XG5cblxuZXhwb3J0IGNsYXNzIFdlYnNvY2tldFNlcnZpY2UgZXh0ZW5kcyBCYXNlU2VydmljZXtcbiAgICBvcHRpb25zOklXZWJTb2NrZXRTZXJ2aWNlT3B0aW9ucztcbiAgICBjb25zdHJ1Y3RvcihvcHQ/OklXZWJTb2NrZXRTZXJ2aWNlT3B0aW9ucyl7XG4gICAgICAgIHN1cGVyKFwiV2Vic29ja2V0U2VydmljZVwiKTtcbiAgICAgICAgdGhpcy5vcHRpb25zID0gey4uLmdldERlZmF1bHRXZWJTb2NrZXRTZXJ2aWNlT3B0aW9ucygpLG9wdH1cbiAgICB9XG5cbiAgICBhc3luYyBpbml0KCl7XG4gICAgICAgIHN1cGVyLmluaXQoKTtcbiAgICB9XG59Il19
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"WebsocketService.js","sourceRoot":"","sources":["../../src/apiServer/WebsocketService.ts"],"names":[],"mappings":";;;AAAA,+CAA4C;AAM5C,MAAM,iCAAiC,GAAG,GAA2B,EAAE;IACnE,OAAO,EAEN,CAAA;AACL,CAAC,CAAA;AAGD,MAAa,gBAAiB,SAAQ,yBAAW;IAC7C,OAAO,CAA0B;IACjC,YAAY,GAA6B;QACrC,KAAK,CAAC,kBAAkB,CAAC,CAAC;QAC1B,IAAI,CAAC,OAAO,GAAG,EAAC,GAAG,iCAAiC,EAAE,EAAC,GAAG,EAAC,CAAA;IAC/D,CAAC;IAED,KAAK,CAAC,IAAI;QACN,KAAK,CAAC,IAAI,EAAE,CAAC;IACjB,CAAC;CACJ;AAVD,4CAUC","sourcesContent":["import { BaseService } from \"./BaseService\";\n\nexport interface IWebSocketServiceOptions{\n\n}\n\nconst getDefaultWebSocketServiceOptions = ():IWebSocketServiceOptions=>{\n return {\n\n }\n}\n\n\nexport class WebsocketService extends BaseService{\n options:IWebSocketServiceOptions;\n constructor(opt?:IWebSocketServiceOptions){\n super(\"WebsocketService\");\n this.options = {...getDefaultWebSocketServiceOptions(),opt}\n }\n\n async init(){\n super.init();\n }\n}"]}
|
@@ -7,33 +7,33 @@ export interface IClusterPacket {
|
|
7
7
|
error?: IError;
|
8
8
|
callbackID: number;
|
9
9
|
}
|
10
|
+
export interface IHUBConnectionOptions {
|
11
|
+
direction: "incoming" | "outgoing";
|
12
|
+
ws: WebSocket;
|
13
|
+
hostID: string;
|
14
|
+
hostPrivateKey: string;
|
15
|
+
hostPublicKey: string;
|
16
|
+
hostURL: string;
|
17
|
+
targetID: string | null;
|
18
|
+
targetPublicKey: string | null;
|
19
|
+
targetURL: string | null;
|
20
|
+
onAuthorized: () => void;
|
21
|
+
onClose: () => void;
|
22
|
+
handlers: (Req<any, any> | Signal<any>)[];
|
23
|
+
maxTimeout?: number;
|
24
|
+
}
|
10
25
|
export declare class HUBConnection {
|
11
26
|
static callbackID: number;
|
12
|
-
callbacks
|
13
|
-
time: number;
|
14
|
-
callback: (packet: IClusterPacket) => void;
|
15
|
-
}>;
|
27
|
+
private callbacks;
|
16
28
|
authorized: boolean;
|
17
|
-
ws
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
ws: WebSocket;
|
27
|
-
privateKey: string;
|
28
|
-
hubID: string;
|
29
|
-
onAuthorized: () => void;
|
30
|
-
onClose: () => void;
|
31
|
-
handlers: (Req<any, any> | Signal<any>)[];
|
32
|
-
authorized?: boolean;
|
33
|
-
maxTimeout?: number;
|
34
|
-
});
|
35
|
-
authorize(data: any): Promise<boolean | IError>;
|
36
|
-
sendCallback(packet: IClusterPacket, data: IError | any): void;
|
37
|
-
send(packet: IClusterPacket): Promise<IClusterPacket | IError | null>;
|
29
|
+
private ws;
|
30
|
+
private onAuthorized;
|
31
|
+
options: IHUBConnectionOptions;
|
32
|
+
constructor(options: IHUBConnectionOptions);
|
33
|
+
sendAuth(): Promise<void>;
|
34
|
+
authorize(data: any): Promise<any | IError>;
|
35
|
+
handleCallback(data: IClusterPacket): void;
|
36
|
+
sendCallback(callbackID: number, data: IError | any): void;
|
37
|
+
send(packet: IClusterPacket): Promise<any | IError | null>;
|
38
38
|
close(): void;
|
39
39
|
}
|
@@ -27,28 +27,18 @@ exports.HUBConnection = void 0;
|
|
27
27
|
const ws_1 = require("ws");
|
28
28
|
const LogService_1 = require("../LogService");
|
29
29
|
const DefaultErrors_1 = __importStar(require("../structures/DefaultErrors"));
|
30
|
-
const crypto_1 = require("crypto");
|
31
30
|
class HUBConnection {
|
32
31
|
static callbackID = 1;
|
33
32
|
callbacks = new Map();
|
34
33
|
authorized = false;
|
35
34
|
ws;
|
36
|
-
privateKey;
|
37
|
-
publicKey;
|
38
|
-
hubID;
|
39
|
-
clientID = null;
|
40
|
-
url = null;
|
41
35
|
onAuthorized;
|
42
|
-
|
36
|
+
options;
|
43
37
|
constructor(options) {
|
44
|
-
(0, LogService_1.logInfo)("HUBConnection: new connection", options.ws.url);
|
45
|
-
this.
|
46
|
-
this.publicKey = null;
|
47
|
-
this.hubID = options.hubID;
|
38
|
+
(0, LogService_1.logInfo)("HUBConnection: new connection", options.hostID, options.targetID, options.direction === "outgoing" ? options.ws.url + " -->" : " <--");
|
39
|
+
this.options = options;
|
48
40
|
this.ws = options.ws;
|
49
41
|
this.onAuthorized = options.onAuthorized;
|
50
|
-
if (options.authorized)
|
51
|
-
this.authorized = true;
|
52
42
|
this.ws.on("close", () => {
|
53
43
|
if (!this.authorized)
|
54
44
|
return;
|
@@ -60,99 +50,85 @@ class HUBConnection {
|
|
60
50
|
(0, LogService_1.logError)("HUBConnection: connection error", e);
|
61
51
|
});
|
62
52
|
this.ws.on("open", () => {
|
63
|
-
(0, LogService_1.logInfo)("HUBConnection: connection opened");
|
64
|
-
if (options.
|
65
|
-
(0, LogService_1.logInfo)("HUBConnection:
|
66
|
-
|
67
|
-
this.onAuthorized();
|
53
|
+
(0, LogService_1.logInfo)("HUBConnection: connection opened", options.direction);
|
54
|
+
if (options.direction === "outgoing") {
|
55
|
+
(0, LogService_1.logInfo)("HUBConnection: send authroization");
|
56
|
+
this.sendAuth();
|
68
57
|
}
|
69
58
|
});
|
70
59
|
this.ws.on("message", async (msg, isBinary) => {
|
71
|
-
if (
|
60
|
+
if (isBinary) {
|
61
|
+
(0, LogService_1.logError)("HUBConnection: invalid packet type, must be a string");
|
72
62
|
return;
|
63
|
+
}
|
73
64
|
let data = null;
|
74
65
|
try {
|
75
|
-
data = JSON.parse(msg.toString());
|
66
|
+
data = JSON.parse(msg.toString("utf8"));
|
76
67
|
}
|
77
68
|
catch (e) { }
|
78
|
-
if (!data || !data.method
|
69
|
+
if (!data || !data.method) {
|
79
70
|
(0, LogService_1.logError)("HUBConnection: invalid packet structure", data);
|
80
71
|
return;
|
81
72
|
}
|
82
|
-
if (typeof data.method !== "string"
|
73
|
+
if (typeof data.method !== "string") {
|
83
74
|
(0, LogService_1.logError)("HUBConnection: invalid packet structure", data);
|
84
75
|
return;
|
85
76
|
}
|
77
|
+
const callbackID = parseInt(data.callbackID);
|
78
|
+
if (data.method === "callback") {
|
79
|
+
this.handleCallback(data);
|
80
|
+
return;
|
81
|
+
}
|
82
|
+
;
|
86
83
|
if (!this.authorized && data.method === "auth") {
|
87
84
|
const result = await this.authorize(data.data);
|
88
85
|
if (DefaultErrors_1.ErrorUtils.isError(result)) {
|
89
86
|
(0, LogService_1.logError)("HUBConnection: authorization failed", result);
|
90
|
-
this.sendCallback(
|
87
|
+
this.sendCallback(callbackID, result);
|
91
88
|
return;
|
92
89
|
}
|
93
90
|
this.authorized = true;
|
94
91
|
if (this.onAuthorized)
|
95
92
|
this.onAuthorized();
|
96
|
-
this.sendCallback(
|
93
|
+
this.sendCallback(callbackID, result);
|
97
94
|
return;
|
98
95
|
}
|
99
96
|
if (!this.authorized) {
|
100
97
|
(0, LogService_1.logError)("HUBConnection: not authorized");
|
101
|
-
this.sendCallback(
|
102
|
-
return;
|
103
|
-
}
|
104
|
-
if (typeof data.data !== "string")
|
105
|
-
return this.sendCallback(data, { ...DefaultErrors_1.default.BAD_REQUEST, details: "invalid data, must be a string" });
|
106
|
-
let packetData = null;
|
107
|
-
try {
|
108
|
-
const encryptedPacketData = (0, crypto_1.privateDecrypt)(this.privateKey, data.data).toString("utf8");
|
109
|
-
packetData = JSON.parse(encryptedPacketData);
|
110
|
-
}
|
111
|
-
catch (e) {
|
112
|
-
return this.sendCallback(data, { ...DefaultErrors_1.default.BAD_REQUEST, details: "invalid data type, must be a json" });
|
113
|
-
}
|
114
|
-
if (data.method === "callback") {
|
115
|
-
if (!this.callbacks.has(data.callbackID)) {
|
116
|
-
(0, LogService_1.logError)("HUBConnection: callback not found", data);
|
117
|
-
return;
|
118
|
-
}
|
119
|
-
const cb = this.callbacks.get(data.callbackID);
|
120
|
-
if (cb) {
|
121
|
-
cb.callback({
|
122
|
-
method: "callback",
|
123
|
-
data: packetData,
|
124
|
-
callbackID: data.callbackID,
|
125
|
-
error: data.error
|
126
|
-
});
|
127
|
-
this.callbacks.delete(data.callbackID);
|
128
|
-
}
|
98
|
+
this.sendCallback(callbackID, DefaultErrors_1.default.UNAUTHORIZED);
|
129
99
|
return;
|
130
100
|
}
|
131
|
-
;
|
132
101
|
for (let i of options.handlers) {
|
133
102
|
if (i.name === data.method) {
|
103
|
+
const requestPacket = {
|
104
|
+
data: data.data,
|
105
|
+
authorized: this.authorized,
|
106
|
+
connection: this
|
107
|
+
};
|
134
108
|
if (i.type === "signal") {
|
135
|
-
i.invoke(
|
109
|
+
i.invoke(requestPacket);
|
136
110
|
if (data.callbackID > 0)
|
137
|
-
this.sendCallback(
|
111
|
+
this.sendCallback(callbackID, {});
|
138
112
|
return;
|
139
113
|
}
|
140
114
|
else if (i.type === "request") {
|
141
|
-
const result = await i.request(
|
142
|
-
this.sendCallback(
|
115
|
+
const result = await i.request(requestPacket);
|
116
|
+
this.sendCallback(callbackID, result);
|
143
117
|
return;
|
144
118
|
}
|
145
119
|
}
|
146
120
|
}
|
147
|
-
|
121
|
+
if (callbackID > 0)
|
122
|
+
this.sendCallback(callbackID, { ...DefaultErrors_1.default.NOT_IMPLEMENTED, details: "method not found: " + data.method });
|
123
|
+
else
|
124
|
+
(0, LogService_1.logError)("HUBConnection: method not found", data.method);
|
148
125
|
});
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
}
|
126
|
+
setTimeout(() => {
|
127
|
+
if (!this.authorized) {
|
128
|
+
(0, LogService_1.logError)("HUBConnection: authorization timeout", this.authorized);
|
129
|
+
this.close();
|
130
|
+
}
|
131
|
+
}, 15000);
|
156
132
|
setInterval(() => {
|
157
133
|
const now = +new Date();
|
158
134
|
for (let [key, value] of this.callbacks) {
|
@@ -163,42 +139,74 @@ class HUBConnection {
|
|
163
139
|
}
|
164
140
|
}, options.maxTimeout || 1000 * 60 * 15);
|
165
141
|
}
|
166
|
-
async
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
142
|
+
async sendAuth() {
|
143
|
+
const response = await this.send({
|
144
|
+
method: "auth",
|
145
|
+
data: {
|
146
|
+
hostID: this.options.targetID,
|
147
|
+
targetPublicKey: this.options.hostPublicKey,
|
148
|
+
targetURL: this.options.hostURL,
|
149
|
+
targetID: this.options.hostID
|
150
|
+
},
|
151
|
+
callbackID: 1
|
152
|
+
});
|
153
|
+
if (DefaultErrors_1.ErrorUtils.isError(response)) {
|
154
|
+
(0, LogService_1.logError)("HUBConnection: auth failed", response);
|
155
|
+
this.close();
|
156
|
+
return;
|
173
157
|
}
|
174
|
-
|
175
|
-
|
158
|
+
this.authorized = true;
|
159
|
+
if (!response || !response.hostID || !response.hostPublicKey || !response.hostURL) {
|
160
|
+
(0, LogService_1.logError)("HUBConnection: invalid auth response", response);
|
161
|
+
this.close();
|
162
|
+
return;
|
176
163
|
}
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
164
|
+
this.options.targetID = response.hostID;
|
165
|
+
this.options.targetPublicKey = response.hostPublicKey;
|
166
|
+
this.options.targetURL = response.hostURL;
|
167
|
+
if (this.onAuthorized)
|
168
|
+
this.onAuthorized();
|
169
|
+
}
|
170
|
+
async authorize(data) {
|
171
|
+
if (typeof data !== "object" || !data || !data.hostID || !data.targetPublicKey || !data.targetID || !data.targetURL)
|
172
|
+
return { ...DefaultErrors_1.default.BAD_REQUEST, stack: [data], details: "expecting {hostID:string,targetPublicKey:string,targetID:string,targetURL:string}" };
|
173
|
+
if (data.hostID !== this.options.hostID)
|
174
|
+
return { ...DefaultErrors_1.default.UNAUTHORIZED, details: "invalid targetID" };
|
175
|
+
this.options.targetID = data.targetID;
|
176
|
+
this.options.targetPublicKey = data.targetPublicKey;
|
177
|
+
this.options.targetURL = data.targetURL;
|
178
|
+
return {
|
179
|
+
hostID: this.options.hostID,
|
180
|
+
hostPublicKey: this.options.hostPublicKey,
|
181
|
+
hostURL: this.options.hostURL
|
182
|
+
};
|
183
|
+
}
|
184
|
+
handleCallback(data) {
|
185
|
+
if (!this.callbacks.has(data.callbackID)) {
|
186
|
+
(0, LogService_1.logError)("HUBConnection: callback not found", data);
|
187
|
+
return;
|
181
188
|
}
|
182
|
-
|
183
|
-
|
189
|
+
const cb = this.callbacks.get(data.callbackID);
|
190
|
+
if (cb) {
|
191
|
+
cb.callback(data.data ?? data.error);
|
192
|
+
this.callbacks.delete(data.callbackID);
|
184
193
|
}
|
185
|
-
if (!this.publicKey)
|
186
|
-
return { ...DefaultErrors_1.default.UNAUTHORIZED, details: "wrong public key" };
|
187
|
-
return true;
|
188
194
|
}
|
189
|
-
sendCallback(
|
190
|
-
if (
|
195
|
+
sendCallback(callbackID, data) {
|
196
|
+
if (isNaN(callbackID) || callbackID <= 0) {
|
197
|
+
(0, LogService_1.logError)("HUBConnection: invalid callbackID", callbackID, data);
|
191
198
|
return;
|
199
|
+
}
|
192
200
|
if (this.ws && this.ws.readyState === ws_1.WebSocket.OPEN) {
|
193
201
|
this.ws.send(JSON.stringify({
|
194
202
|
method: "callback",
|
195
203
|
error: DefaultErrors_1.ErrorUtils.isError(data) ? data : null,
|
196
204
|
data: DefaultErrors_1.ErrorUtils.isError(data) ? null : data,
|
197
|
-
callbackID:
|
205
|
+
callbackID: callbackID
|
198
206
|
}));
|
199
207
|
}
|
200
208
|
else {
|
201
|
-
(0, LogService_1.logError)("HUBConnection: ws not connected, cant send callback",
|
209
|
+
(0, LogService_1.logError)("HUBConnection: ws not connected, cant send callback", this.options.direction, data);
|
202
210
|
}
|
203
211
|
}
|
204
212
|
async send(packet) {
|
@@ -213,20 +221,31 @@ class HUBConnection {
|
|
213
221
|
this.callbacks.set(callbackID, { time: +new Date(), callback: cb });
|
214
222
|
packet.callbackID = callbackID;
|
215
223
|
}
|
216
|
-
this.ws.send(JSON.stringify(packet)
|
224
|
+
this.ws.send(JSON.stringify(packet), err => {
|
225
|
+
if (err) {
|
226
|
+
(0, LogService_1.logError)("HUBConnection: cant send packet", err);
|
227
|
+
if (packet.callbackID > 0)
|
228
|
+
this.callbacks.delete(packet.callbackID);
|
229
|
+
cb(DefaultErrors_1.default.SERVICE_NOT_WORKING);
|
230
|
+
}
|
231
|
+
});
|
217
232
|
if (packet.callbackID === 0)
|
218
233
|
return null;
|
219
234
|
return promise;
|
220
235
|
}
|
221
236
|
close() {
|
237
|
+
(0, LogService_1.logInfo)("HUBConnection: close connection");
|
222
238
|
this.callbacks.clear();
|
239
|
+
this.authorized = false;
|
223
240
|
if (this.ws) {
|
224
241
|
try {
|
225
242
|
this.ws.removeAllListeners();
|
226
243
|
this.ws.close();
|
244
|
+
this.ws.terminate();
|
227
245
|
}
|
228
246
|
catch (e) { }
|
229
247
|
}
|
230
248
|
}
|
231
249
|
}
|
232
250
|
exports.HUBConnection = HUBConnection;
|
251
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiSFV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29pbmdcIil7XG4gICAgICAgICAgICAgICAgbG9nSW5mbyhcIkhVQkNvbm5lY3Rpb246IHNlbmQgYXV0aHJvaXphdGlvblwiKVxuICAgICAgICAgICAgICAgIHRoaXMuc2VuZEF1dGgoKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSlcblxuICAgICAgICB0aGlzLndzLm9uKFwibWVzc2FnZVwiLGFzeW5jIChtc2c6UmF3RGF0YSxpc0JpbmFyeSk9PntcbiAgICAgICAgICAgIFxuICAgICAgICAgICAgaWYoaXNCaW5hcnkpe1xuICAgICAgICAgICAgICAgIGxvZ0Vycm9yKFwiSFVCQ29ubmVjdGlvbjogaW52YWxpZCBwYWNrZXQgdHlwZSwgbXVzdCBiZSBhIHN0cmluZ1wiKTtcbiAgICAgICAgICAgICAgICByZXR1cm47XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGxldCBkYXRhID0gbnVsbDtcbiAgICAgICAgICAgIHRyeXtcbiAgICAgICAgICAgICAgICBkYXRhID0gSlNPTi5wYXJzZShtc2cudG9TdHJpbmcoXCJ1dGY4XCIpKVxuICAgICAgICAgICAgfWNhdGNoKGUpe31cblxuICAgICAgICAgICAgLy9sb2dJbmZvKFwiSFVCQ29ubmVjdGlvbjogbWVzc2FnZSByZWNlaXZlZFwiLHRoaXMub3B0aW9ucy5kaXJlY3Rpb24sZGF0YSk7XG5cbiAgICAgICAgICAgIC8vIGNoZWNrIHBhY2tldCBzdHJ1Y3R1cmVcbiAgICAgICAgICAgIGlmKCFkYXRhIHx8ICFkYXRhLm1ldGhvZCl7XG4gICAgICAgICAgICAgICAgbG9nRXJyb3IoXCJIVUJDb25uZWN0aW9uOiBpbnZhbGlkIHBhY2tldCBzdHJ1Y3R1cmVcIixkYXRhKTtcbiAgICAgICAgICAgICAgICByZXR1cm47XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIC8vIGhhbmRsZSBwYWNrZXRzXG4gICAgICAgICAgICBpZih0eXBlb2YgZGF0YS5tZXRob2QgIT09IFwic3RyaW5nXCIpe1xuICAgICAgICAgICAgICAgIGxvZ0Vycm9yKFwiSFVCQ29ubmVjdGlvbjogaW52YWxpZCBwYWNrZXQgc3RydWN0dXJlXCIsZGF0YSk7XG4gICAgICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAvLyBjYWxsYmFja0lEXG4gICAgICAgICAgICBjb25zdCBjYWxsYmFja0lEID0gcGFyc2VJbnQoZGF0YS5jYWxsYmFja0lEKTtcbiAgICAgICAgICAgICBcbiAgICAgICAgICAgIC8vIGhhbmRsZSBjYWxsYmFja3NcbiAgICAgICAgICAgICBpZihkYXRhLm1ldGhvZD09PVwiY2FsbGJhY2tcIil7XG4gICAgICAgICAgICAgICAgdGhpcy5oYW5kbGVDYWxsYmFjayhkYXRhKTtcbiAgICAgICAgICAgICAgICByZXR1cm47XG4gICAgICAgICAgICB9O1xuXG4gICAgICAgICAgICBcbiAgICAgICAgICAgIGlmKCF0aGlzLmF1dGhvcml6ZWQgJiYgZGF0YS5tZXRob2Q9PT1cImF1dGhcIil7XG4gICAgICAgICAgICAgICAgLy8gZG8gYXV0aG9yaXphdGlvbiAgICAgICAgICAgICAgICBcbiAgICAgICAgICAgICAgICBjb25zdCByZXN1bHQgPSBhd2FpdCB0aGlzLmF1dGhvcml6ZShkYXRhLmRhdGEpO1xuICAgICAgICAgICAgICAgIGlmKEVycm9yVXRpbHMuaXNFcnJvcihyZXN1bHQpKXtcbiAgICAgICAgICAgICAgICAgICAgbG9nRXJyb3IoXCJIVUJDb25uZWN0aW9uOiBhdXRob3JpemF0aW9uIGZhaWxlZFwiLHJlc3VsdCk7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuc2VuZENhbGxiYWNrKGNhbGxiYWNrSUQscmVzdWx0KTtcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB0aGlzLmF1dGhvcml6ZWQgPSB0cnVlO1xuICAgICAgICAgICAgICAgIGlmKHRoaXMub25BdXRob3JpemVkKVxuICAgICAgICAgICAgICAgICAgICB0aGlzLm9uQXV0aG9yaXplZCgpO1xuICAgICAgICAgICAgICAgIHRoaXMuc2VuZENhbGxiYWNrKGNhbGxiYWNrSUQscmVzdWx0KTtcbiAgICAgICAgICAgICAgICByZXR1cm47XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgXG4gICAgICAgICAgICBcbiAgICAgICAgICAgIGlmKCF0aGlzLmF1dGhvcml6ZWQpe1xuICAgICAgICAgICAgICAgIGxvZ0Vycm9yKFwiSFVCQ29ubmVjdGlvbjogbm90IGF1dGhvcml6ZWRcIik7XG4gICAgICAgICAgICAgICAgdGhpcy5zZW5kQ2FsbGJhY2soY2FsbGJhY2tJRCxEZWZhdWx0RXJyb3JzLlVOQVVUSE9SSVpFRCk7XG4gICAgICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAvLyBoYW5kbGUgbWV0aG9kc1xuICAgICAgICAgICAgZm9yKGxldCBpIG9mIG9wdGlvbnMuaGFuZGxlcnMpe1xuICAgICAgICAgICAgICAgIGlmKGkubmFtZSA9PT0gZGF0YS5tZXRob2Qpe1xuXG4gICAgICAgICAgICAgICAgICAgIGNvbnN0IHJlcXVlc3RQYWNrZXQ6SVdlYnNvY2tldFBhY2tldD17XG4gICAgICAgICAgICAgICAgICAgICAgICBkYXRhOmRhdGEuZGF0YSxcbiAgICAgICAgICAgICAgICAgICAgICAgIGF1dGhvcml6ZWQ6dGhpcy5hdXRob3JpemVkLFxuICAgICAgICAgICAgICAgICAgICAgICAgY29ubmVjdGlvbjp0aGlzXG4gICAgICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICAgICAgICBpZihpLnR5cGUgPT09IFwic2lnbmFsXCIpe1xuICAgICAgICAgICAgICAgICAgICAgICAgKGkgYXMgU2lnbmFsPElXZWJzb2NrZXRQYWNrZXQ+KS5pbnZva2UocmVxdWVzdFBhY2tldCk7XG4gICAgICAgICAgICAgICAgICAgICAgICBpZihkYXRhLmNhbGxiYWNrSUQ+MClcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB0aGlzLnNlbmRDYWxsYmFjayhjYWxsYmFja0lELHt9KTtcbiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgICAgICAgICAgICAgfWVsc2UgaWYoaS50eXBlID09PSBcInJlcXVlc3RcIil7XG4gICAgICAgICAgICAgICAgICAgICAgICBjb25zdCByZXN1bHQgPSBhd2FpdCAoaSBhcyBSZXE8SVdlYnNvY2tldFBhY2tldCxhbnk+KS5yZXF1ZXN0KHJlcXVlc3RQYWNrZXQpO1xuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5zZW5kQ2FsbGJhY2soY2FsbGJhY2tJRCxyZXN1bHQpO1xuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBpZihjYWxsYmFja0lEPjApXG4gICAgICAgICAgICAgICAgdGhpcy5zZW5kQ2FsbGJhY2soY2FsbGJhY2tJRCx7Li4uRGVmYXVsdEVycm9ycy5OT1RfSU1QTEVNRU5URUQsZGV0YWlsczpcIm1ldGhvZCBub3QgZm91bmQ6IFwiK2RhdGEubWV0aG9kfSk7XG4gICAgICAgICAgICBlbHNlXG4gICAgICAgICAgICAgICAgbG9nRXJyb3IoXCJIVUJDb25uZWN0aW9uOiBtZXRob2Qgbm90IGZvdW5kXCIsZGF0YS5tZXRob2QpO1xuICAgICAgICAgICAgICAgIFxuICAgICAgICB9KVxuXG4gICAgICAgIFxuICAgICAgICBzZXRUaW1lb3V0KCgpPT57XG4gICAgICAgICAgICBpZighdGhpcy5hdXRob3JpemVkKXtcbiAgICAgICAgICAgICAgICBsb2dFcnJvcihcIkhVQkNvbm5lY3Rpb246IGF1dGhvcml6YXRpb24gdGltZW91dFwiLHRoaXMuYXV0aG9yaXplZClcbiAgICAgICAgICAgICAgICB0aGlzLmNsb3NlKCk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH0sMTUwMDApOyAvLyAxNXNlYyBmb3IgYXV0aG9yaXphdGlvblxuICAgICAgICBcblxuICAgICAgICBzZXRJbnRlcnZhbCgoKT0+e1xuICAgICAgICAgICAgY29uc3Qgbm93ID0gK25ldyBEYXRlKCk7XG4gICAgICAgICAgICBmb3IobGV0IFtrZXksdmFsdWVdIG9mIHRoaXMuY2FsbGJhY2tzKXtcbiAgICAgICAgICAgICAgICBpZihub3ctdmFsdWUudGltZT4ob3B0aW9ucy5tYXhUaW1lb3V0ID8/IDEwMDAqNjAqMTUpKXtcbiAgICAgICAgICAgICAgICAgICAgdmFsdWUuY2FsbGJhY2soe21ldGhvZDpcImNhbGxiYWNrXCIsZGF0YTpudWxsLGNhbGxiYWNrSUQ6a2V5LGVycm9yOnsuLi5EZWZhdWx0RXJyb3JzLlRJTUVPVVR9fSk7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuY2FsbGJhY2tzLmRlbGV0ZShrZXkpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfSxvcHRpb25zLm1heFRpbWVvdXQgfHwgMTAwMCo2MCoxNSk7XG5cbiAgICB9XG5cblxuICAgIGFzeW5jIHNlbmRBdXRoKCl7XG4gICAgICAgLy8gbG9nSW5mbyhcIkhVQkNvbm5lY3Rpb246IHNlbmQgYXV0aCBwYWNrZXRcIilcbiAgICAgICAgY29uc3QgcmVzcG9uc2UgPSBhd2FpdCB0aGlzLnNlbmQoe1xuICAgICAgICAgICAgbWV0aG9kOlwiYXV0aFwiLFxuICAgICAgICAgICAgZGF0YTp7XG4gICAgICAgICAgICAgICAgaG9zdElEOnRoaXMub3B0aW9ucy50YXJnZXRJRCwgLy8gUkVNT1RFIEhPU1QgSURcbiAgICAgICAg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IHBhY2tldC5jYWxsYmFja0lEID0gY2FsbGJhY2tJRDtcbiAgICAgICAgfVxuXG4gICAgICAgIC8vdG9kbyAtIGVuY3J5cHQgZGF0YVxuXG4gICAgICAgIHRoaXMud3Muc2VuZChKU09OLnN0cmluZ2lmeShwYWNrZXQpLGVycj0+e1xuICAgICAgICAgICAgaWYoZXJyKXtcbiAgICAgICAgICAgICAgICBsb2dFcnJvcihcIkhVQkNvbm5lY3Rpb246IGNhbnQgc2VuZCBwYWNrZXRcIixlcnIpO1xuICAgICAgICAgICAgICAgIGlmKHBhY2tldC5jYWxsYmFja0lEPjApXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuY2FsbGJhY2tzLmRlbGV0ZShwYWNrZXQuY2FsbGJhY2tJRCk7XG4gICAgICAgICAgICAgICAgY2IhKERlZmF1bHRFcnJvcnMuU0VSVklDRV9OT1RfV09SS0lORyk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH0pO1xuXG4gICAgICAgIGlmKHBhY2tldC5jYWxsYmFja0lEPT09MClcbiAgICAgICAgICAgIHJldHVybiBudWxsO1xuXG4gICAgICAgIHJldHVybiBwcm9taXNlO1xuICAgIH1cblxuXG4gICAgY2xvc2UoKXtcbiAgICAgICAgbG9nSW5mbyhcIkhVQkNvbm5lY3Rpb246IGNsb3NlIGNvbm5lY3Rpb25cIilcbiAgICAgICAgdGhpcy5jYWxsYmFja3MuY2xlYXIoKTtcbiAgICAgICAgdGhpcy5hdXRob3JpemVkPWZhbHNlO1xuXG4gICAgICAgIGlmKHRoaXMud3Mpe1xuICAgICAgICAgICAgdHJ5e1xuICAgICAgICAgICAgICAgIHRoaXMud3MucmVtb3ZlQWxsTGlzdGVuZXJzKCk7XG4gICAgICAgICAgICAgICAgdGhpcy53cy5jbG9zZSgpO1xuICAgICAgICAgICAgICAgIHRoaXMud3MudGVybWluYXRlKCk7XG4gICAgICAgICAgICB9Y2F0Y2goZSl7fVxuICAgICAgICB9XG4gICAgfVxuXG59XG5cbiJdfQ==
|