Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
c1a03fec0f | |||
8b650c5ea7 | |||
4fc6e327ec | |||
7991baf2bf | |||
d033780015 | |||
eae46e6461 | |||
785acfaba4 | |||
5a4dceb75d | |||
a17834a8f0 | |||
01765fa50f | |||
547c159dc4 | |||
046d7d646d | |||
f6985bd7b2 | |||
241e44e19d |
@ -10,15 +10,18 @@ stages:
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- trigger
|
||||
- pages
|
||||
- metadata
|
||||
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
mirror:
|
||||
stage: security
|
||||
script:
|
||||
- npmci git mirror
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
snyk:
|
||||
stage: security
|
||||
@ -28,7 +31,11 @@ snyk:
|
||||
- npmci command snyk test
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
# ====================
|
||||
# test stage
|
||||
# ====================
|
||||
testLEGACY:
|
||||
stage: test
|
||||
script:
|
||||
@ -38,6 +45,7 @@ testLEGACY:
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
allow_failure: true
|
||||
|
||||
testLTS:
|
||||
@ -49,6 +57,7 @@ testLTS:
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
testSTABLE:
|
||||
stage: test
|
||||
@ -59,34 +68,60 @@ testSTABLE:
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
release:
|
||||
stage: release
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm publish
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
# ====================
|
||||
# metadata stage
|
||||
# ====================
|
||||
codequality:
|
||||
stage: metadata
|
||||
image: docker:stable
|
||||
allow_failure: true
|
||||
services:
|
||||
- docker:stable-dind
|
||||
script:
|
||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
||||
- docker run
|
||||
--env SOURCE_CODE="$PWD"
|
||||
--volume "$PWD":/code
|
||||
--volume /var/run/docker.sock:/var/run/docker.sock
|
||||
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
|
||||
artifacts:
|
||||
paths: [codeclimate.json]
|
||||
tags:
|
||||
- docker
|
||||
- priv
|
||||
|
||||
trigger:
|
||||
stage: trigger
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci trigger
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
pages:
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
stage: pages
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci command yarn global add npmpage
|
||||
- npmci command npmpage
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
only:
|
||||
- tags
|
||||
artifacts:
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"npmci": {
|
||||
"npmGlobalTools": [
|
||||
"@shipzone/npmts",
|
||||
"@gitzone/npmts",
|
||||
"ts-node"
|
||||
],
|
||||
"npmAccessLevel": "public"
|
||||
|
2491
package-lock.json
generated
Normal file
2491
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
11
package.json
11
package.json
@ -1,24 +1,29 @@
|
||||
{
|
||||
"name": "@pushrocks/smartuniverse",
|
||||
"version": "1.0.12",
|
||||
"version": "1.0.19",
|
||||
"private": false,
|
||||
"description": "messaging service for your micro services",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"author": "Lossless GmbH",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"test": "ts-node test/test.ts",
|
||||
"test": "(ts-node -O '{\"lib\": [ \"es2015\" ]}' test/test.ts)",
|
||||
"build": "(npmts)",
|
||||
"format": "(gitzone format)"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^9.6.0",
|
||||
"tapbundle": "^2.0.0"
|
||||
"tapbundle": "^2.0.0",
|
||||
"ts-node": "^6.0.3",
|
||||
"typescript": "^2.8.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"lik": "^2.0.5",
|
||||
"nodehash": "^1.0.4",
|
||||
"rxjs": "^5.5.8",
|
||||
"smartcli": "^2.0.12",
|
||||
"smartdelay": "^1.0.4",
|
||||
"smartexpress": "^1.0.21",
|
||||
"smartfile": "^4.2.28",
|
||||
"smartq": "^1.1.8",
|
||||
|
@ -1,22 +0,0 @@
|
||||
import * as plugins from './smartuniverse.plugins';
|
||||
|
||||
import { Objectmap } from 'lik';
|
||||
import { UniverseChannel } from './smartuniverse.classes.universechannel';
|
||||
|
||||
export class UniverseManager {
|
||||
public channelStore = new Objectmap<UniverseChannel>();
|
||||
|
||||
/**
|
||||
* register a new member
|
||||
*/
|
||||
public async registerMember() {}
|
||||
|
||||
/**
|
||||
* register a new channel within the universe
|
||||
* @param channelName the name of the channel
|
||||
* @param authSecret the secret against which to verify members of the channel
|
||||
*/
|
||||
public async registerChannel(channelName: string, authSecret: string) {
|
||||
|
||||
}
|
||||
}
|
@ -1,8 +1,6 @@
|
||||
import * as plugins from './smartuniverse.plugins';
|
||||
|
||||
import { Handler, Route, Server } from 'smartexpress';
|
||||
|
||||
import { UniverseManager } from './smartuniverse.classes.manager';
|
||||
import { UniverseChannel } from './smartuniverse.classes.universechannel';
|
||||
import { UniverseMessage } from './smartuniverse.classes.universemessage';
|
||||
import { UniverseStore } from './smartuniverse.classes.universestore';
|
||||
@ -19,15 +17,22 @@ export interface IServerGetMessagesRequestBody {
|
||||
youngerThan: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* the interface for a standard request
|
||||
*/
|
||||
export interface IServerPutMessageRequestBody {
|
||||
channel: string;
|
||||
passphrase: string;
|
||||
message: string;
|
||||
payload: any;
|
||||
}
|
||||
|
||||
/**
|
||||
* main class that setsup a Universe
|
||||
*/
|
||||
export class Universe {
|
||||
// subinstances
|
||||
public universeStore: UniverseStore;
|
||||
public universeManager: UniverseManager;
|
||||
|
||||
// options
|
||||
private options: ISmartUniverseConstructorOptions;
|
||||
@ -50,7 +55,6 @@ export class Universe {
|
||||
constructor(optionsArg: ISmartUniverseConstructorOptions) {
|
||||
this.options = optionsArg;
|
||||
this.universeStore = new UniverseStore(this.options.messageExpiryInMilliseconds);
|
||||
this.universeManager = new UniverseManager();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -67,8 +71,9 @@ export class Universe {
|
||||
// message handling
|
||||
// adds messages
|
||||
const addMessageHandler = new Handler('PUT', request => {
|
||||
const requestBody = request.body;
|
||||
this.universeStore.addMessage(requestBody.message, requestBody.payload);
|
||||
const requestBody: IServerPutMessageRequestBody = request.body;
|
||||
const message = new UniverseMessage(requestBody.message, requestBody.channel, requestBody.passphrase, requestBody.payload);
|
||||
this.universeStore.addMessage(message);
|
||||
console.log(requestBody);
|
||||
return true;
|
||||
});
|
||||
|
@ -6,27 +6,80 @@ import { Objectmap } from 'lik';
|
||||
* enables messages to stay within a certain scope.
|
||||
*/
|
||||
export class UniverseChannel {
|
||||
|
||||
// ======
|
||||
// STATIC
|
||||
// ======
|
||||
|
||||
/**
|
||||
* stores the channels that are available within the universe
|
||||
*/
|
||||
public static channelStore = new Objectmap();
|
||||
public static channelStore = new Objectmap<UniverseChannel>();
|
||||
|
||||
/**
|
||||
* allows messages to be processed in a blacklist mode for further analysis
|
||||
*/
|
||||
public static blackListChannel = new UniverseChannel('blacklist', 'nada');
|
||||
|
||||
/**
|
||||
* creates new channels
|
||||
* @param channelArg the name of the topic
|
||||
* @param secretArg the secret thats used for a certain topic.
|
||||
* @param passphraseArg the secret thats used for a certain topic.
|
||||
*/
|
||||
public static createChannel = (channelArg: string, secretArg: string) => {
|
||||
public static createChannel (channelNameArg: string, passphraseArg: string) {
|
||||
const newChannel = new UniverseChannel(channelNameArg, passphraseArg);
|
||||
return newChannel;
|
||||
};
|
||||
|
||||
/**
|
||||
* returns boolean wether certain channel exists
|
||||
*/
|
||||
public static async doesChannelExists (channelNameArg: string) {
|
||||
const channel = this.channelStore.find(channelArg => {
|
||||
return channelArg.name === channelNameArg;
|
||||
});
|
||||
if(channel) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
credentials: {
|
||||
user: string;
|
||||
password: string;
|
||||
public static authorizeForChannel (channelNameArg: string, passphraseArg: string) {
|
||||
const foundChannel = this.channelStore.find(universeChannel => {
|
||||
const result = universeChannel.authenticate(channelNameArg, passphraseArg);
|
||||
return result;
|
||||
});
|
||||
if(foundChannel) {
|
||||
return foundChannel;
|
||||
} else {
|
||||
return this.blackListChannel;
|
||||
}
|
||||
};
|
||||
|
||||
// ========
|
||||
// INSTANCE
|
||||
// ========
|
||||
/**
|
||||
* the name of the channel
|
||||
*/
|
||||
public name: string;
|
||||
|
||||
/**
|
||||
* the passphrase for the channel
|
||||
*/
|
||||
public passphrase: string;
|
||||
|
||||
constructor(channelNameArg: string, passphraseArg: string) {
|
||||
this.name = channelNameArg;
|
||||
this.passphrase = passphraseArg;
|
||||
UniverseChannel.channelStore.add(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* authenticates a client on the server side
|
||||
*/
|
||||
async authenticateClient() {}
|
||||
public authenticate(channelNameArg: string, passphraseArg: string): boolean {
|
||||
return (this.name === channelNameArg && this.passphrase === passphraseArg);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
import * as plugins from './smartuniverse.plugins';
|
||||
|
||||
import { Timer, TimeStamp } from 'smarttime';
|
||||
import { UniverseChannel } from './smartuniverse.classes.universechannel';
|
||||
import { UniverseStore } from './smartuniverse.classes.universestore';
|
||||
import { Universe } from './smartuniverse.classes.universe';
|
||||
|
||||
/**
|
||||
* represents a message within a universe
|
||||
@ -14,36 +16,71 @@ export class UniverseMessage {
|
||||
* avoids duplications though
|
||||
*/
|
||||
public id: number;
|
||||
|
||||
/**
|
||||
* the universe store the message is attached to
|
||||
*/
|
||||
public universeStore: UniverseStore;
|
||||
public timestamp: TimeStamp; // when has this message been created
|
||||
public topic: string; // enables unprotected grouping of messages for efficiency purposes.
|
||||
public message: string; // the actual message
|
||||
public attachedPayload: any; // any attached payloads. Can be of binary format.
|
||||
/**
|
||||
* enables unprotected grouping of messages for efficiency purposes.
|
||||
*/
|
||||
public universeChannel: UniverseChannel;
|
||||
|
||||
/**
|
||||
* time of creation
|
||||
*/
|
||||
public timestamp: TimeStamp;
|
||||
|
||||
/**
|
||||
* the actual message
|
||||
*/
|
||||
public message: string;
|
||||
|
||||
/**
|
||||
* any attached payloads. Can be of binary format.
|
||||
*/
|
||||
public attachedPayload: any;
|
||||
public destructionTimer: Timer; // a timer to take care of message destruction
|
||||
|
||||
/**
|
||||
* the constructor to create a universe message
|
||||
* @param parentUniverseStore
|
||||
* @param messageArg
|
||||
* @param attachedPayloadArg
|
||||
* @param selfdestructAfterArg
|
||||
* @param messageArg
|
||||
* @param attachedPayloadArg
|
||||
*/
|
||||
constructor(
|
||||
parentUniverseStore: UniverseStore,
|
||||
messageArg: string,
|
||||
attachedPayloadArg: any,
|
||||
selfdestructAfterArg: number
|
||||
) {
|
||||
this.universeStore = parentUniverseStore;
|
||||
constructor(messageArg: string, channelNameArg: string, passphraseArg: string, attachedPayloadArg: any) {
|
||||
this.timestamp = new TimeStamp();
|
||||
this.message = messageArg;
|
||||
this.universeChannel = UniverseChannel.authorizeForChannel(channelNameArg, passphraseArg);
|
||||
this.attachedPayload = attachedPayloadArg;
|
||||
this.destructionTimer = new Timer(selfdestructAfterArg);
|
||||
this.destructionTimer.start();
|
||||
this.fallBackDestruction();
|
||||
}
|
||||
|
||||
// set up self destruction by removing this from the parent messageStore
|
||||
this.destructionTimer.completed.then(async () => {
|
||||
this.universeStore.messageStore.remove(this);
|
||||
public setUniverseStore(universeStoreArg: UniverseStore) {
|
||||
this.universeStore = universeStoreArg;
|
||||
}
|
||||
|
||||
public setDestructionTimer(selfdestructAfterArg: number) {
|
||||
if (selfdestructAfterArg) {
|
||||
this.destructionTimer = new Timer(selfdestructAfterArg);
|
||||
this.destructionTimer.start();
|
||||
|
||||
// set up self destruction by removing this from the parent messageStore
|
||||
this.destructionTimer.completed.then(async () => {
|
||||
this.universeStore.messageStore.remove(this);
|
||||
});
|
||||
} else {
|
||||
this.fallBackDestruction();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* prevents memory leaks if channels have no default
|
||||
*/
|
||||
private fallBackDestruction() {
|
||||
plugins.smartdelay.delayFor(1000).then(() => {
|
||||
if (!this.destructionTimer) {
|
||||
this.setDestructionTimer(6000);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -25,10 +25,8 @@ export class UniverseStore {
|
||||
* @param messageArg
|
||||
* @param attachedPayloadArg
|
||||
*/
|
||||
public addMessage(messageArg, attachedPayloadArg) {
|
||||
this.messageStore.add(
|
||||
new UniverseMessage(this, messageArg, attachedPayloadArg, this.destructionTime)
|
||||
);
|
||||
public addMessage(messageArg: UniverseMessage) {
|
||||
this.messageStore.add(messageArg);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,6 +1,8 @@
|
||||
import * as lik from 'lik';
|
||||
import * as nodehash from 'nodehash';
|
||||
import * as path from 'path';
|
||||
import * as smartcli from 'smartcli';
|
||||
import * as smartdelay from 'smartdelay';
|
||||
import * as smartexpress from 'smartexpress';
|
||||
import * as smartfile from 'smartfile';
|
||||
import * as smartq from 'smartq';
|
||||
@ -11,8 +13,10 @@ import * as smarttime from 'smarttime';
|
||||
|
||||
export {
|
||||
lik,
|
||||
nodehash,
|
||||
path,
|
||||
smartcli,
|
||||
smartdelay,
|
||||
smartexpress,
|
||||
smartfile,
|
||||
smartq,
|
||||
|
Reference in New Issue
Block a user