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

View File

@ -49,4 +49,4 @@
"npmextra.json",
"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.
> 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 () => {
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 () => {
@ -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 () => {
await testClientUniverse.start();
})
});
tap.test('should get a observable correctly', async () => {
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 () => {
await (testClientUniverse.getChannel(testChannelData.channelName)).sendMessage({
await testClientUniverse.getChannel(testChannelData.channelName).sendMessage({
messageText: 'hello'
});
});

View File

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

View File

@ -40,7 +40,11 @@ export class ClientUniverse {
}
// lets create the channel
const clientUniverseChannel = ClientUniverseChannel.createClientUniverseChannel(this, channelNameArg, passphraseArg);
const clientUniverseChannel = ClientUniverseChannel.createClientUniverseChannel(
this,
channelNameArg,
passphraseArg
);
return clientUniverseChannel;
}
@ -61,9 +65,11 @@ export class ClientUniverse {
* @param messageArg
*/
public removeChannel(channelNameArg, notifyServer = true) {
const clientUniverseChannel = this.clientUniverseCache.channelMap.findOneAndRemove(channelItemArg => {
return channelItemArg.name === channelNameArg;
});
const clientUniverseChannel = this.clientUniverseCache.channelMap.findOneAndRemove(
channelItemArg => {
return channelItemArg.name === channelNameArg;
}
);
}
public async start() {
@ -112,7 +118,9 @@ export class ClientUniverse {
allowedRoles: [],
funcDef: async (messageDescriptorArg: interfaces.IUniverseMessage) => {
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,
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,
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
);
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 {
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 {
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(
this.universeCache,
unauthenticatedMessage

View File

@ -121,7 +121,8 @@ export class UniverseChannel {
}
});
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 = {
id: messageArg.id,
timestamp: messageArg.timestamp,
@ -131,7 +132,11 @@ export class UniverseChannel {
payload: messageArg.payload,
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
): Promise<UniverseConnection> {
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) {
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
*/
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);
universeMessageInstance.socketConnection = socketConnectionArg;
return universeMessageInstance;
@ -69,9 +72,7 @@ export class UniverseMessage implements interfaces.IUniverseMessage {
this.universeCache = universeCacheArg;
}
public setTargetChannel() {
}
public setTargetChannel() {}
public setDestructionTimer(selfdestructAfterArg: number) {
if (selfdestructAfterArg) {