diff --git a/.gitignore b/.gitignore index 91c0db0..ef13c79 100644 --- a/.gitignore +++ b/.gitignore @@ -15,8 +15,6 @@ node_modules/ # builds dist/ -dist_web/ -dist_serve/ -dist_ts_web/ +dist_*/ # custom \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 938529d..9a4467e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,14 +3,14 @@ image: registry.gitlab.com/hosttoday/ht-docker-node:npmci cache: paths: - - .npmci_cache/ - key: "$CI_BUILD_STAGE" + - .npmci_cache/ + key: '$CI_BUILD_STAGE' stages: -- security -- test -- release -- metadata + - security + - test + - release + - metadata # ==================== # security stage @@ -18,60 +18,74 @@ stages: mirror: stage: security script: - - npmci git mirror + - npmci git mirror + only: + - tags tags: - - docker - - notpriv + - lossless + - docker + - notpriv -snyk: +auditProductionDependencies: + image: registry.gitlab.com/hosttoday/ht-docker-node:npmci stage: security script: - npmci npm prepare - - npmci command npm install -g snyk - - npmci command npm install --ignore-scripts - - npmci command snyk test + - npmci command npm install --production --ignore-scripts + - npmci command npm config set registry https://registry.npmjs.org + - npmci command npm audit --audit-level=high --only=prod --production tags: - - docker - - notpriv + - docker + +auditDevDependencies: + image: registry.gitlab.com/hosttoday/ht-docker-node:npmci + stage: security + script: + - npmci npm prepare + - npmci command npm install --ignore-scripts + - npmci command npm config set registry https://registry.npmjs.org + - npmci command npm audit --audit-level=high --only=dev + tags: + - docker + allow_failure: true # ==================== # test stage # ==================== -testLTS: +testStable: stage: test script: - - npmci npm prepare - - npmci node install lts - - npmci npm install - - npmci npm test + - npmci npm prepare + - npmci node install stable + - npmci npm install + - npmci npm test coverage: /\d+.?\d+?\%\s*coverage/ tags: - - docker - - notpriv + - docker testBuild: stage: test script: - - npmci npm prepare - - npmci node install lts - - npmci npm install - - npmci command npm run build + - npmci npm prepare + - npmci node install stable + - npmci npm install + - npmci command npm run build coverage: /\d+.?\d+?\%\s*coverage/ tags: - - docker - - notpriv + - docker release: stage: release script: - - npmci node install lts - - npmci npm publish + - npmci node install stable + - npmci npm publish only: - - tags + - tags tags: - - docker - - notpriv + - lossless + - docker + - notpriv # ==================== # metadata stage @@ -79,35 +93,39 @@ release: codequality: stage: metadata allow_failure: true + only: + - tags script: - npmci command npm install -g tslint typescript + - npmci npm prepare - npmci npm install - npmci command "tslint -c tslint.json ./ts/**/*.ts" tags: - - docker - - priv + - lossless + - docker + - priv trigger: stage: metadata script: - - npmci trigger + - npmci trigger only: - - tags + - tags tags: - - docker - - notpriv + - lossless + - docker + - notpriv pages: - image: hosttoday/ht-docker-dbase:npmci - services: - - docker:18-dind stage: metadata script: + - npmci node install lts - npmci command npm install -g @gitzone/tsdoc - npmci npm prepare - npmci npm install - npmci command tsdoc tags: + - lossless - docker - notpriv only: @@ -115,5 +133,5 @@ pages: artifacts: expire_in: 1 week paths: - - public + - public allow_failure: true diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..3648eaa --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,26 @@ +{ + "json.schemas": [ + { + "fileMatch": ["/npmextra.json"], + "schema": { + "type": "object", + "properties": { + "npmci": { + "type": "object", + "description": "settings for npmci" + }, + "gitzone": { + "type": "object", + "description": "settings for gitzone", + "properties": { + "projectType": { + "type": "string", + "enum": ["website", "element", "service", "npm", "wcc"] + } + } + } + } + } + } + ] +} diff --git a/npmextra.json b/npmextra.json index 32c9eef..2c6a918 100644 --- a/npmextra.json +++ b/npmextra.json @@ -1,5 +1,6 @@ { "gitzone": { + "projectType": "npm", "module": { "githost": "gitlab.com", "gitscope": "pushrocks", diff --git a/package.json b/package.json index 5b39e68..2ae4c3d 100644 --- a/package.json +++ b/package.json @@ -2,8 +2,8 @@ "name": "@pushrocks/smartsocket", "version": "1.1.59", "description": "easy and secure websocket communication", - "main": "dist/index.js", - "typings": "dist/index.d.ts", + "main": "dist_ts/index.js", + "typings": "dist_ts/index.d.ts", "scripts": { "test": "(tstest test/)", "build": "(tsbuild --web)" @@ -44,14 +44,18 @@ }, "private": false, "files": [ - "ts/*", - "ts_web/*", - "dist/*", - "dist_web/*", - "dist_ts_web/*", - "assets/*", + "ts/**/*", + "ts_web/**/*", + "dist/**/*", + "dist_*/**/*", + "dist_ts/**/*", + "dist_ts_web/**/*", + "assets/**/*", "cli.js", "npmextra.json", "readme.md" + ], + "browserslist": [ + "last 1 chrome versions" ] -} +} \ No newline at end of file diff --git a/test/test.expressserver.ts b/test/test.expressserver.ts index e032e89..6be955f 100644 --- a/test/test.expressserver.ts +++ b/test/test.expressserver.ts @@ -15,7 +15,7 @@ let testSocketFunction1: smartsocket.SocketFunction; let myseServer: smartexpress.Server; const testConfig = { - port: 3000 + port: 3000, }; // class smartsocket @@ -28,7 +28,7 @@ tap.test('Should accept an smartExpressServer as server', async () => { myseServer = new smartexpress.Server({ cors: true, forceSsl: false, - port: testConfig.port + port: testConfig.port, }); testSmartsocket.setExternalServer('smartexpress', myseServer); @@ -40,7 +40,7 @@ tap.test('Should accept an smartExpressServer as server', async () => { tap.test('should add a socketrole', async () => { testSocketRole1 = new smartsocket.SocketRole({ name: 'testRole1', - passwordHash: smarthash.sha256FromStringSync('testPassword') + passwordHash: smarthash.sha256FromStringSync('testPassword'), }); testSmartsocket.addSocketRoles([testSocketRole1]); }); @@ -52,7 +52,7 @@ tap.test('should register a new Function', async () => { funcDef: async (dataArg, socketConnectionArg) => { return dataArg; }, - funcName: 'testFunction1' + funcName: 'testFunction1', }); testSmartsocket.addSocketFunction(testSocketFunction1); console.log(testSmartsocket.socketFunctions); @@ -69,14 +69,14 @@ tap.test('should react to a new websocket connection from client', async () => { url: 'http://localhost', password: 'testPassword', alias: 'testClient1', - role: 'testRole1' + role: 'testRole1', }); testSmartsocketClient.addSocketFunction(testSocketFunction1); console.log(testSmartsocketClient.socketFunctions); await testSmartsocketClient.connect(); }); -tap.test('client should disconnect and reconnect', async tools => { +tap.test('client should disconnect and reconnect', async (tools) => { await testSmartsocketClient.disconnect(); await tools.delayFor(100); await testSmartsocketClient.connect(); @@ -88,7 +88,7 @@ tap.test('2 clients should connect in parallel', async () => { tap.test('should be able to make a functionCall from client to server', async () => { const response = await testSmartsocketClient.serverCall('testFunction1', { - value1: 'hello' + value1: 'hello', }); console.log(response); }); diff --git a/test/test.ts b/test/test.ts index fa6b87b..fa35b23 100644 --- a/test/test.ts +++ b/test/test.ts @@ -30,12 +30,12 @@ export interface IReqResServer { hi: string; }; response: { - hi: string - } + hi: string; + }; } const testConfig = { - port: 3000 + port: 3000, }; // class smartsocket @@ -48,7 +48,7 @@ tap.test('should create a new smartsocket', async () => { tap.test('should add a socketrole', async () => { testSocketRole1 = new smartsocket.SocketRole({ name: 'testRole1', - passwordHash: smarthash.sha256FromStringSync('testPassword') + passwordHash: smarthash.sha256FromStringSync('testPassword'), }); testSmartsocket.addSocketRoles([testSocketRole1]); }); @@ -60,7 +60,7 @@ tap.test('should register a new Function', async () => { funcDef: async (dataArg, socketConnectionArg) => { return dataArg; }, - funcName: 'testFunction1' + funcName: 'testFunction1', }); testSmartsocket.addSocketFunction(testSocketFunctionForServer); @@ -69,7 +69,7 @@ tap.test('should register a new Function', async () => { funcDef: async (dataArg, socketConnectionArg) => { return dataArg; }, - funcName: 'testFunction2' + funcName: 'testFunction2', }); testSmartsocket.addSocketFunction(testSocketFunctionForServer); console.log(testSmartsocket.socketFunctions); @@ -86,7 +86,7 @@ tap.test('should react to a new websocket connection from client', async () => { url: 'http://localhost', password: 'testPassword', alias: 'testClient1', - role: 'testRole1' + role: 'testRole1', }); testSmartsocketClient.addSocketFunction(testSocketFunctionClient); console.log(testSmartsocketClient.socketFunctions); @@ -99,7 +99,7 @@ tap.test('2 clients should connect in parallel', async () => { tap.test('should be able to make a functionCall from client to server', async () => { const response = await testSmartsocketClient.serverCall('testFunction1', { - value1: 'hello' + value1: 'hello', }); console.log(response); expect(response.value1).to.equal('hello'); @@ -109,9 +109,9 @@ tap.test('should be able to make a functionCall from server to client', async () const response = await testSmartsocket.clientCall( 'testFunction2', { - hi: 'hi there from server' + hi: 'hi there from server', }, - testSmartsocket.socketConnections.find(socketConnection => { + testSmartsocket.socketConnections.find((socketConnection) => { return true; }) ); @@ -119,7 +119,7 @@ tap.test('should be able to make a functionCall from server to client', async () expect(response.hi).to.equal('hi there from server'); }); -tap.test('client should disconnect and reconnect', async tools => { +tap.test('client should disconnect and reconnect', async (tools) => { await testSmartsocketClient.disconnect(); await tools.delayFor(100); await testSmartsocketClient.connect(); diff --git a/ts/interfaces/connection.ts b/ts/interfaces/connection.ts index 0a805a8..5ef7694 100644 --- a/ts/interfaces/connection.ts +++ b/ts/interfaces/connection.ts @@ -2,4 +2,9 @@ export interface IRequestAuthPayload { serverShortId: string; } -export type TConnectionStatus = 'new' | 'connecting' | 'connected' | 'disconnecting' | 'disconnected'; +export type TConnectionStatus = + | 'new' + | 'connecting' + | 'connected' + | 'disconnecting' + | 'disconnected'; diff --git a/ts/smartsocket.classes.smartsocket.ts b/ts/smartsocket.classes.smartsocket.ts index ed5fe47..4baf7d9 100644 --- a/ts/smartsocket.classes.smartsocket.ts +++ b/ts/smartsocket.classes.smartsocket.ts @@ -2,7 +2,11 @@ import * as plugins from './smartsocket.plugins'; // classes import { SocketConnection } from './smartsocket.classes.socketconnection'; -import { ISocketFunctionCallDataRequest, SocketFunction, ISocketFunctionCallDataResponse } from './smartsocket.classes.socketfunction'; +import { + ISocketFunctionCallDataRequest, + SocketFunction, + ISocketFunctionCallDataResponse, +} from './smartsocket.classes.socketfunction'; import { SocketRequest } from './smartsocket.classes.socketrequest'; import { SocketRole } from './smartsocket.classes.socketrole'; import { SocketServer } from './smartsocket.classes.socketserver'; @@ -44,7 +48,7 @@ export class Smartsocket { public async start() { this.io = plugins.socketIo(this.socketServer.getServerForSocketIo()); await this.socketServer.start(); - this.io.on('connection', socketArg => { + this.io.on('connection', (socketArg) => { this._handleSocketConnection(socketArg); }); } @@ -55,10 +59,7 @@ export class Smartsocket { public async stop() { await plugins.smartdelay.delayFor(1000); this.socketConnections.forEach((socketObjectArg: SocketConnection) => { - logger.log( - 'info', - `disconnect socket with >>alias ${socketObjectArg.alias}` - ); + logger.log('info', `disconnect socket with >>alias ${socketObjectArg.alias}`); socketObjectArg.socket.disconnect(); }); this.socketConnections.wipe(); @@ -81,11 +82,11 @@ export class Smartsocket { const socketRequest = new SocketRequest(this, { funcCallData: { funcDataArg: dataArg, - funcName: functionNameArg + funcName: functionNameArg, }, originSocketConnection: targetSocketConnectionArg, shortId: plugins.smartunique.shortId(), - side: 'requesting' + side: 'requesting', }); const response: ISocketFunctionCallDataResponse = await socketRequest.dispatch(); const result = response.funcDataArg; @@ -116,7 +117,7 @@ export class Smartsocket { role: undefined, side: 'server', smartsocketHost: this, - socket: socketArg + socket: socketArg, }); logger.log('info', 'Socket connected. Trying to authenticate...'); this.socketConnections.add(socketConnection); diff --git a/ts/smartsocket.classes.smartsocketclient.ts b/ts/smartsocket.classes.smartsocketclient.ts index 0475713..eee3c38 100644 --- a/ts/smartsocket.classes.smartsocketclient.ts +++ b/ts/smartsocket.classes.smartsocketclient.ts @@ -2,7 +2,10 @@ import * as plugins from './smartsocket.plugins'; import * as interfaces from './interfaces'; import { SocketConnection } from './smartsocket.classes.socketconnection'; -import { ISocketFunctionCallDataRequest, SocketFunction } from './smartsocket.classes.socketfunction'; +import { + ISocketFunctionCallDataRequest, + SocketFunction, +} from './smartsocket.classes.socketfunction'; import { ISocketRequestDataObject, SocketRequest } from './smartsocket.classes.socketrequest'; import { SocketRole } from './smartsocket.classes.socketrole'; import { logger } from './smartsocket.logging'; @@ -47,7 +50,7 @@ export class SmartsocketClient { this.serverPort = optionsArg.port; this.socketRole = new SocketRole({ name: optionsArg.role, - passwordHash: optionsArg.password + passwordHash: optionsArg.password, }); this.autoReconnect = optionsArg.autoReconnect; } @@ -73,7 +76,7 @@ export class SmartsocketClient { socket: plugins.socketIoClient(socketUrl, { multiplex: false, reconnectionAttempts: 5, - }) + }), }); const timer = new plugins.smarttime.Timer(5000); @@ -84,33 +87,35 @@ export class SmartsocketClient { }); // authentication flow - this.socketConnection.socket.on('requestAuth', (requestAuthPayload: interfaces.IRequestAuthPayload) => { - timer.reset(); - logger.log('info', 'server requested authentication'); - - // lets register the authenticated event - this.socketConnection.socket.on('authenticated', () => { - this.remoteShortId = requestAuthPayload.serverShortId; - logger.log('info', 'client is authenticated'); - this.socketConnection.authenticated = true; - this.socketConnection.listenToFunctionRequests(); - done.resolve(); - }); + this.socketConnection.socket.on( + 'requestAuth', + (requestAuthPayload: interfaces.IRequestAuthPayload) => { + timer.reset(); + logger.log('info', 'server requested authentication'); - // lets register the forbidden event - this.socketConnection.socket.on('forbidden', async () => { - logger.log('warn', `disconnecting due to being forbidden to use the ressource`); - await this.disconnect(); - }); + // lets register the authenticated event + this.socketConnection.socket.on('authenticated', () => { + this.remoteShortId = requestAuthPayload.serverShortId; + logger.log('info', 'client is authenticated'); + this.socketConnection.authenticated = true; + this.socketConnection.listenToFunctionRequests(); + done.resolve(); + }); - // lets provide the actual auth data - this.socketConnection.socket.emit('dataAuth', { - role: this.socketRole.name, - password: this.socketRole.passwordHash, - alias: this.alias - }); + // lets register the forbidden event + this.socketConnection.socket.on('forbidden', async () => { + logger.log('warn', `disconnecting due to being forbidden to use the ressource`); + await this.disconnect(); + }); - }); + // lets provide the actual auth data + this.socketConnection.socket.emit('dataAuth', { + role: this.socketRole.name, + password: this.socketRole.passwordHash, + alias: this.alias, + }); + } + ); // handle connection this.socketConnection.socket.on('connect', async () => { @@ -159,10 +164,13 @@ export class SmartsocketClient { /** * dispatches a server call - * @param functionNameArg - * @param dataArg + * @param functionNameArg + * @param dataArg */ - public async serverCall(functionNameArg: T['method'], dataArg: T['request']): Promise { + public async serverCall( + functionNameArg: T['method'], + dataArg: T['request'] + ): Promise { const done = plugins.smartpromise.defer(); const socketRequest = new SocketRequest(this, { side: 'requesting', @@ -170,15 +178,15 @@ export class SmartsocketClient { shortId: plugins.smartunique.shortId(), funcCallData: { funcName: functionNameArg, - funcDataArg: dataArg - } + funcDataArg: dataArg, + }, }); const response = await socketRequest.dispatch(); const result = response.funcDataArg; return result; } - private updateStatus (statusArg: interfaces.TConnectionStatus) { + private updateStatus(statusArg: interfaces.TConnectionStatus) { if (this.eventStatus !== statusArg) { this.eventSubject.next(statusArg); } diff --git a/ts/smartsocket.classes.socketconnection.ts b/ts/smartsocket.classes.socketconnection.ts index e2f85c6..cda1a73 100644 --- a/ts/smartsocket.classes.socketconnection.ts +++ b/ts/smartsocket.classes.socketconnection.ts @@ -90,10 +90,7 @@ export class SocketConnection { public authenticate() { const done = plugins.smartpromise.defer(); this.socket.on('dataAuth', async (dataArg: ISocketConnectionAuthenticationObject) => { - logger.log( - 'info', - 'received authentication data. now hashing and comparing...' - ); + logger.log('info', 'received authentication data. now hashing and comparing...'); this.socket.removeListener('dataAuth', () => {}); if (SocketRole.checkPasswordForRole(dataArg, this.smartsocketRef)) { // TODO: authenticate password @@ -101,10 +98,7 @@ export class SocketConnection { this.authenticated = true; this.role = SocketRole.getSocketRoleByName(this.smartsocketRef, dataArg.role); this.socket.emit('authenticated'); - logger.log( - 'ok', - `socket with >>alias ${this.alias} >>role ${this.role} is authenticated!` - ); + logger.log('ok', `socket with >>alias ${this.alias} >>role ${this.role} is authenticated!`); done.resolve(this); } else { this.authenticated = false; @@ -113,7 +107,7 @@ export class SocketConnection { } }); const requestAuthPayload: interfaces.IRequestAuthPayload = { - serverShortId: this.smartsocketRef.shortId + serverShortId: this.smartsocketRef.shortId, }; this.socket.emit('requestAuth', requestAuthPayload); return done.promise; @@ -131,7 +125,7 @@ export class SocketConnection { // check if requested function is available to the socket's scope logger.log('info', 'function request received'); const referencedFunction: SocketFunction = this.role.allowedFunctions.find( - socketFunctionArg => { + (socketFunctionArg) => { return socketFunctionArg.name === dataArg.funcCallData.funcName; } ); @@ -141,31 +135,22 @@ export class SocketConnection { side: 'responding', originSocketConnection: this, shortId: dataArg.shortId, - funcCallData: dataArg.funcCallData + funcCallData: dataArg.funcCallData, }); localSocketRequest.createResponse(); // takes care of creating response and sending it back } else { - logger.log( - 'warn', - 'function not existent or out of access scope' - ); + logger.log('warn', 'function not existent or out of access scope'); } }); this.socket.on('functionResponse', (dataArg: ISocketRequestDataObject) => { - logger.log( - 'info', - `received response for request with id ${dataArg.shortId}` - ); + logger.log('info', `received response for request with id ${dataArg.shortId}`); const targetSocketRequest = SocketRequest.getSocketRequestById( this.smartsocketRef, dataArg.shortId ); targetSocketRequest.handleResponse(dataArg); }); - logger.log( - 'info', - `now listening to function requests for ${this.alias}` - ); + logger.log('info', `now listening to function requests for ${this.alias}`); done.resolve(this); } else { const errMessage = 'socket needs to be authenticated first'; @@ -181,7 +166,7 @@ export class SocketConnection { this.updateStatus('disconnected'); } - private updateStatus (statusArg: interfaces.TConnectionStatus) { + private updateStatus(statusArg: interfaces.TConnectionStatus) { if (this.eventStatus !== statusArg) { this.eventSubject.next(statusArg); } diff --git a/ts/smartsocket.classes.socketfunction.ts b/ts/smartsocket.classes.socketfunction.ts index 441aa79..2be3049 100644 --- a/ts/smartsocket.classes.socketfunction.ts +++ b/ts/smartsocket.classes.socketfunction.ts @@ -11,7 +11,9 @@ import { SmartsocketClient } from './smartsocket.classes.smartsocketclient'; /** * interface of the contructor options of class SocketFunction */ -export interface ISocketFunctionConstructorOptions { +export interface ISocketFunctionConstructorOptions< + T extends plugins.typedrequestInterfaces.ITypedRequest +> { funcName: T['method']; funcDef: TFuncDef; allowedRoles: SocketRole[]; // all roles that are allowed to execute a SocketFunction @@ -20,7 +22,9 @@ export interface ISocketFunctionConstructorOptions { +export interface ISocketFunctionCallDataRequest< + T extends plugins.typedrequestInterfaces.ITypedRequest +> { funcName: T['method']; funcDataArg: T['request']; } @@ -28,7 +32,9 @@ export interface ISocketFunctionCallDataRequest { +export interface ISocketFunctionCallDataResponse< + T extends plugins.typedrequestInterfaces.ITypedRequest +> { funcName: T['method']; funcDataArg: T['response']; } @@ -36,7 +42,10 @@ export interface ISocketFunctionCallDataResponse = (dataArg: T['request'], connectionArg: SocketConnection) => PromiseLike; +export type TFuncDef = ( + dataArg: T['request'], + connectionArg: SocketConnection +) => PromiseLike; // export classes @@ -49,7 +58,7 @@ export class SocketFunction { - return smartsocketRefArg.socketFunctions.find(socketFunctionArg => { + return smartsocketRefArg.socketFunctions.find((socketFunctionArg) => { return socketFunctionArg.name === functionNameArg; }); } @@ -74,11 +83,14 @@ export class SocketFunction, socketConnectionArg: SocketConnection): Promise> { + public async invoke( + dataArg: ISocketFunctionCallDataRequest, + socketConnectionArg: SocketConnection + ): Promise> { if (dataArg.funcName === this.name) { const funcResponseData: ISocketFunctionCallDataResponse = { funcName: this.name, - funcDataArg: await this.funcDef(dataArg.funcDataArg, socketConnectionArg) + funcDataArg: await this.funcDef(dataArg.funcDataArg, socketConnectionArg), }; return funcResponseData; } else { diff --git a/ts/smartsocket.classes.socketrequest.ts b/ts/smartsocket.classes.socketrequest.ts index 4294b7c..adba270 100644 --- a/ts/smartsocket.classes.socketrequest.ts +++ b/ts/smartsocket.classes.socketrequest.ts @@ -1,7 +1,11 @@ import * as plugins from './smartsocket.plugins'; // import interfaces -import { SocketFunction, ISocketFunctionCallDataRequest, ISocketFunctionCallDataResponse } from './smartsocket.classes.socketfunction'; +import { + SocketFunction, + ISocketFunctionCallDataRequest, + ISocketFunctionCallDataResponse, +} from './smartsocket.classes.socketfunction'; // import classes import { SocketConnection } from './smartsocket.classes.socketconnection'; @@ -16,7 +20,9 @@ export type TSocketRequestSide = 'requesting' | 'responding'; /** * interface of constructor of class SocketRequest */ -export interface ISocketRequestConstructorOptions { +export interface ISocketRequestConstructorOptions< + T extends plugins.typedrequestInterfaces.ITypedRequest +> { side: TSocketRequestSide; originSocketConnection: SocketConnection; shortId: string; @@ -39,7 +45,7 @@ export class SocketRequest { - return smartsocketRef.socketRequests.find(socketRequestArg => { + return smartsocketRef.socketRequests.find((socketRequestArg) => { return socketRequestArg.shortid === shortIdArg; }); } @@ -74,7 +80,7 @@ export class SocketRequest> { const requestData: ISocketRequestDataObject = { funcCallData: this.funcCallData, - shortId: this.shortid + shortId: this.shortid, }; this.originSocketConnection.socket.emit('function', requestData); return this.done.promise; @@ -101,22 +107,21 @@ export class SocketRequest { - logger.log('info', 'got resultData. Sending it to requesting party.'); - const responseData: ISocketRequestDataObject = { - funcCallData: resultData, - shortId: this.shortid - }; - this.originSocketConnection.socket.emit('functionResponse', responseData); - this.smartsocketRef.socketRequests.remove(this); - }); + targetSocketFunction + .invoke(this.funcCallData, this.originSocketConnection) + .then((resultData) => { + logger.log('info', 'got resultData. Sending it to requesting party.'); + const responseData: ISocketRequestDataObject = { + funcCallData: resultData, + shortId: this.shortid, + }; + this.originSocketConnection.socket.emit('functionResponse', responseData); + this.smartsocketRef.socketRequests.remove(this); + }); } } diff --git a/ts/smartsocket.classes.socketrole.ts b/ts/smartsocket.classes.socketrole.ts index f530043..4bbf458 100644 --- a/ts/smartsocket.classes.socketrole.ts +++ b/ts/smartsocket.classes.socketrole.ts @@ -23,7 +23,7 @@ export class SocketRole { referenceSmartsocket: Smartsocket | SmartsocketClient, socketRoleNameArg: string ): SocketRole { - return referenceSmartsocket.socketRoles.find(socketRoleArg => { + return referenceSmartsocket.socketRoles.find((socketRoleArg) => { return socketRoleArg.name === socketRoleNameArg; }); } diff --git a/ts/smartsocket.classes.socketserver.ts b/ts/smartsocket.classes.socketserver.ts index e3fa17b..fd1679f 100644 --- a/ts/smartsocket.classes.socketserver.ts +++ b/ts/smartsocket.classes.socketserver.ts @@ -60,7 +60,10 @@ export class SocketServer { throw new Error('there should be a port specified for smartsocket'); } this.httpServer.listen(this.smartsocket.options.port, () => { - logger.log('success', `Server started in standalone mode on ${this.smartsocket.options.port}`); + logger.log( + 'success', + `Server started in standalone mode on ${this.smartsocket.options.port}` + ); done.resolve(); }); } else { diff --git a/ts/smartsocket.logging.ts b/ts/smartsocket.logging.ts index 98bc7ed..b4586ba 100644 --- a/ts/smartsocket.logging.ts +++ b/ts/smartsocket.logging.ts @@ -1,3 +1,3 @@ import * as plugins from './smartsocket.plugins'; -export const logger = new plugins.smartlog.ConsoleLog(); \ No newline at end of file +export const logger = new plugins.smartlog.ConsoleLog(); diff --git a/ts/smartsocket.plugins.ts b/ts/smartsocket.plugins.ts index f7ee5aa..9064528 100644 --- a/ts/smartsocket.plugins.ts +++ b/ts/smartsocket.plugins.ts @@ -1,7 +1,7 @@ // apiglobal scope import * as typedrequestInterfaces from '@apiglobal/typedrequest-interfaces'; -export {typedrequestInterfaces}; +export { typedrequestInterfaces }; // pushrocks scope import * as lik from '@pushrocks/lik'; @@ -14,7 +14,6 @@ import * as smarttime from '@pushrocks/smarttime'; import * as smartunique from '@pushrocks/smartunique'; import * as smartrx from '@pushrocks/smartrx'; - export { lik, smartlog, @@ -24,14 +23,11 @@ export { smartpromise, smarttime, smartunique, - smartrx + smartrx, }; // third party scope import socketIo from 'socket.io'; import socketIoClient from 'socket.io-client'; -export { - socketIo, - socketIoClient -}; +export { socketIo, socketIoClient };