fix(core): update

This commit is contained in:
Philipp Kunz 2019-09-01 17:04:25 +02:00
parent e8f09c1b7a
commit 52db86c929
11 changed files with 60 additions and 28 deletions

View File

@ -38,17 +38,17 @@ snyk:
# test stage # test stage
# ==================== # ====================
testLTS: testStable:
stage: test stage: test
script: script:
- npmci npm prepare - npmci npm prepare
- npmci node install lts - npmci node install stable
- npmci npm install - npmci npm install
- npmci npm test - npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- docker - docker
- notpriv - priv
testBuild: testBuild:
stage: test stage: test
@ -100,7 +100,7 @@ trigger:
pages: pages:
image: hosttoday/ht-docker-dbase:npmci image: hosttoday/ht-docker-dbase:npmci
services: services:
- docker:18-dind - docker:stable-dind
stage: metadata stage: metadata
script: script:
- npmci command npm install -g @gitzone/tsdoc - npmci command npm install -g @gitzone/tsdoc

View File

@ -49,4 +49,4 @@
"npmextra.json", "npmextra.json",
"readme.md" "readme.md"
] ]
} }

View File

@ -50,6 +50,6 @@ All your microservices represents clients in the universe that may talk to each
For further information read the linked docs at the top of this readme. For further information read the linked docs at the top of this readme.
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh) > MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html) | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://maintainedby.lossless.com) [![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)

View File

@ -37,7 +37,7 @@ tap.test('create smartuniverse client', async () => {
}); });
tap.test('should add a channel to the universe', async () => { tap.test('should add a channel to the universe', async () => {
testUniverse.addChannel(testChannelData.channelName, testChannelData.channelPass); testUniverse.addChannel(testChannelData.channelName, testChannelData.channelPass);
}); });
tap.test('should add the same channel to the client universe in the same way', async () => { tap.test('should add the same channel to the client universe in the same way', async () => {
@ -46,7 +46,7 @@ tap.test('should add the same channel to the client universe in the same way', a
tap.test('should start the ClientUniverse', async () => { tap.test('should start the ClientUniverse', async () => {
await testClientUniverse.start(); await testClientUniverse.start();
}) });
tap.test('should get a observable correctly', async () => { tap.test('should get a observable correctly', async () => {
testClientChannel = testClientUniverse.getChannel(testChannelData.channelName); testClientChannel = testClientUniverse.getChannel(testChannelData.channelName);
@ -54,7 +54,7 @@ tap.test('should get a observable correctly', async () => {
}); });
tap.test('should send a message correctly', async () => { tap.test('should send a message correctly', async () => {
await (testClientUniverse.getChannel(testChannelData.channelName)).sendMessage({ await testClientUniverse.getChannel(testChannelData.channelName).sendMessage({
messageText: 'hello' messageText: 'hello'
}); });
}); });

View File

@ -5,7 +5,7 @@ export interface IMessageCreator {
} }
/** /**
* *
*/ */
export interface IUniverseMessage extends IMessageCreator { export interface IUniverseMessage extends IMessageCreator {
id: string; id: string;

View File

@ -40,7 +40,11 @@ export class ClientUniverse {
} }
// lets create the channel // lets create the channel
const clientUniverseChannel = ClientUniverseChannel.createClientUniverseChannel(this, channelNameArg, passphraseArg); const clientUniverseChannel = ClientUniverseChannel.createClientUniverseChannel(
this,
channelNameArg,
passphraseArg
);
return clientUniverseChannel; return clientUniverseChannel;
} }
@ -61,9 +65,11 @@ export class ClientUniverse {
* @param messageArg * @param messageArg
*/ */
public removeChannel(channelNameArg, notifyServer = true) { public removeChannel(channelNameArg, notifyServer = true) {
const clientUniverseChannel = this.clientUniverseCache.channelMap.findOneAndRemove(channelItemArg => { const clientUniverseChannel = this.clientUniverseCache.channelMap.findOneAndRemove(
return channelItemArg.name === channelNameArg; channelItemArg => {
}); return channelItemArg.name === channelNameArg;
}
);
} }
public async start() { public async start() {
@ -112,7 +118,9 @@ export class ClientUniverse {
allowedRoles: [], allowedRoles: [],
funcDef: async (messageDescriptorArg: interfaces.IUniverseMessage) => { funcDef: async (messageDescriptorArg: interfaces.IUniverseMessage) => {
plugins.smartlog.defaultLogger.log('info', 'Got message from server'); plugins.smartlog.defaultLogger.log('info', 'Got message from server');
this.observableIntake.push(ClientUniverseMessage.createMessageFromMessageDescriptor(messageDescriptorArg)); this.observableIntake.push(
ClientUniverseMessage.createMessageFromMessageDescriptor(messageDescriptorArg)
);
} }
}); });

View File

@ -54,7 +54,10 @@ export class ClientUniverseChannel implements interfaces.IUniverseChannel {
name: this.name, name: this.name,
passphrase: this.passphrase passphrase: this.passphrase
}; };
await this.clientUniverseRef.smartsocketClient.serverCall(serverCallActionName, serverCallActionPayload); await this.clientUniverseRef.smartsocketClient.serverCall(
serverCallActionName,
serverCallActionPayload
);
} }
/** /**
@ -72,6 +75,9 @@ export class ClientUniverseChannel implements interfaces.IUniverseChannel {
payload: messageArg.payload, payload: messageArg.payload,
payloadStringType: messageArg.payloadStringType payloadStringType: messageArg.payloadStringType
}; };
await this.clientUniverseRef.smartsocketClient.serverCall('processMessage', universeMessageToSend); await this.clientUniverseRef.smartsocketClient.serverCall(
'processMessage',
universeMessageToSend
);
} }
} }

View File

@ -126,14 +126,23 @@ export class Universe {
socketConnectionArg socketConnectionArg
); );
if (universeConnection) { if (universeConnection) {
plugins.smartlog.defaultLogger.log('ok', 'found UniverseConnection for socket for incoming message'); plugins.smartlog.defaultLogger.log(
'ok',
'found UniverseConnection for socket for incoming message'
);
} else { } else {
plugins.smartlog.defaultLogger.log('warn', 'found no Authorized channel for incoming message'); plugins.smartlog.defaultLogger.log(
'warn',
'found no Authorized channel for incoming message'
);
return { return {
error: 'You need to authenticate for a channel' error: 'You need to authenticate for a channel'
}; };
} }
const unauthenticatedMessage = UniverseMessage.createMessageFromPayload(socketConnectionArg, dataArg); const unauthenticatedMessage = UniverseMessage.createMessageFromPayload(
socketConnectionArg,
dataArg
);
const foundChannel = await UniverseChannel.authorizeAMessageForAChannel( const foundChannel = await UniverseChannel.authorizeAMessageForAChannel(
this.universeCache, this.universeCache,
unauthenticatedMessage unauthenticatedMessage

View File

@ -121,7 +121,8 @@ export class UniverseChannel {
} }
}); });
for (const universeConnection of universeConnectionsWithChannelAccess) { for (const universeConnection of universeConnectionsWithChannelAccess) {
const smartsocket = universeConnection.socketConnection.smartsocketRef as plugins.smartsocket.Smartsocket; const smartsocket = universeConnection.socketConnection
.smartsocketRef as plugins.smartsocket.Smartsocket;
const universeMessageToSend: interfaces.IUniverseMessage = { const universeMessageToSend: interfaces.IUniverseMessage = {
id: messageArg.id, id: messageArg.id,
timestamp: messageArg.timestamp, timestamp: messageArg.timestamp,
@ -131,7 +132,11 @@ export class UniverseChannel {
payload: messageArg.payload, payload: messageArg.payload,
payloadStringType: messageArg.payloadStringType payloadStringType: messageArg.payloadStringType
}; };
smartsocket.clientCall('processMessage', universeMessageToSend, universeConnection.socketConnection); smartsocket.clientCall(
'processMessage',
universeMessageToSend,
universeConnection.socketConnection
);
} }
} }
} }

View File

@ -58,7 +58,10 @@ export class UniverseConnection {
universeConnectionArg: UniverseConnection universeConnectionArg: UniverseConnection
): Promise<UniverseConnection> { ): Promise<UniverseConnection> {
for (const authenticationRequest of universeConnectionArg.authenticationRequests) { for (const authenticationRequest of universeConnectionArg.authenticationRequests) {
const universeChannelToAuthenticateAgainst = UniverseChannel.getUniverseChannelByName(universeRef, authenticationRequest.name); const universeChannelToAuthenticateAgainst = UniverseChannel.getUniverseChannelByName(
universeRef,
authenticationRequest.name
);
if (universeChannelToAuthenticateAgainst.passphrase === authenticationRequest.passphrase) { if (universeChannelToAuthenticateAgainst.passphrase === authenticationRequest.passphrase) {
universeConnectionArg.authenticatedChannels.push(universeChannelToAuthenticateAgainst); universeConnectionArg.authenticatedChannels.push(universeChannelToAuthenticateAgainst);
} }

View File

@ -14,7 +14,10 @@ import { SocketConnection } from '@pushrocks/smartsocket';
* acts as a container to save message states like authentication status * acts as a container to save message states like authentication status
*/ */
export class UniverseMessage implements interfaces.IUniverseMessage { export class UniverseMessage implements interfaces.IUniverseMessage {
public static createMessageFromPayload(socketConnectionArg: SocketConnection, dataArg: interfaces.IUniverseMessage) { public static createMessageFromPayload(
socketConnectionArg: SocketConnection,
dataArg: interfaces.IUniverseMessage
) {
const universeMessageInstance = new UniverseMessage(dataArg); const universeMessageInstance = new UniverseMessage(dataArg);
universeMessageInstance.socketConnection = socketConnectionArg; universeMessageInstance.socketConnection = socketConnectionArg;
return universeMessageInstance; return universeMessageInstance;
@ -69,9 +72,7 @@ export class UniverseMessage implements interfaces.IUniverseMessage {
this.universeCache = universeCacheArg; this.universeCache = universeCacheArg;
} }
public setTargetChannel() { public setTargetChannel() {}
}
public setDestructionTimer(selfdestructAfterArg: number) { public setDestructionTimer(selfdestructAfterArg: number) {
if (selfdestructAfterArg) { if (selfdestructAfterArg) {