diff --git a/readme.md b/readme.md index 89e4460..16c23a8 100644 --- a/readme.md +++ b/readme.md @@ -1,13 +1,16 @@ # @pushrocks/smartuniverse + messaging service for micro services ## Availabililty and Links -* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartuniverse) -* [gitlab.com (source)](https://gitlab.com/pushrocks/smartuniverse) -* [github.com (source mirror)](https://github.com/pushrocks/smartuniverse) -* [docs (typedoc)](https://pushrocks.gitlab.io/smartuniverse/) + +- [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartuniverse) +- [gitlab.com (source)](https://gitlab.com/pushrocks/smartuniverse) +- [github.com (source mirror)](https://github.com/pushrocks/smartuniverse) +- [docs (typedoc)](https://pushrocks.gitlab.io/smartuniverse/) ## Status for master + [![build status](https://gitlab.com/pushrocks/smartuniverse/badges/master/build.svg)](https://gitlab.com/pushrocks/smartuniverse/commits/master) [![coverage report](https://gitlab.com/pushrocks/smartuniverse/badges/master/coverage.svg)](https://gitlab.com/pushrocks/smartuniverse/commits/master) [![npm downloads per month](https://img.shields.io/npm/dm/@pushrocks/smartuniverse.svg)](https://www.npmjs.com/package/@pushrocks/smartuniverse) @@ -20,13 +23,27 @@ messaging service for micro services Use TypeScript for best in class instellisense. -### What does smartuniverse all about? +### What is smartuniverse all about? Think WhatsApp, but for your microservices architecture. It allows your services to securely talk to each other in **private, shielded channels** without having to expose anything to the outside world. This allows the use of **reactive programming across your entire stack**. +```typescript +import * as smartuniverse from '@pushrocks/smartuniverse'; + +const myUniverse = new smartuniverse.Universe({ + messageExpiryInMilliseconds: 60000 // the standard time in milliseconds until a message expires +}); + +// create as many channels as you like +myUniverse.addChannel('awesomeChannel', 'awesomeChannelPass'); +myUniverse.addChannel('awesomeChannel2', 'jhkjhfsdf87eerkjslkfja9'); + +myUniverse.start(8765); // start the server and provide the port on which to listen on +``` + 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.html) [![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://maintainedby.lossless.com) diff --git a/test/test.ts b/test/test.ts index 813ae16..0df42fa 100644 --- a/test/test.ts +++ b/test/test.ts @@ -8,6 +8,11 @@ let testUniverse: smartuniverse.Universe; let testUniverseClient: smartuniverse.ClientUniverse; let testClientChannel: smartuniverse.ClientUniverseChannel; +const testChannelData = { + channelName: 'awesomeTestChannel', + channelPass: 'awesomeChannelPAss' +} + tap.test('first test', async () => { testUniverse = new smartuniverse.Universe({ messageExpiryInMilliseconds: 1000 @@ -15,7 +20,7 @@ tap.test('first test', async () => { }); tap.test('add a message to the SmartUniverse', async () => { - await testUniverse.initServer(8765); + await testUniverse.start(8765); }); // testing message handling @@ -31,7 +36,7 @@ tap.test('should add a channel to the universe', async () => { }); tap.test('should get a observable correctly', async () => { - testClientChannel = await testUniverseClient.getChannel('testChannel'); + testClientChannel = await testUniverseClient.getChannel(testChannelData.channelName, testChannelData.channelPass); expect(testClientChannel).to.be.instanceof(smartuniverse.ClientUniverseChannel); }); diff --git a/ts/interfaces/universemessage.interfaces.ts b/ts/interfaces/universemessage.interfaces.ts index a65ee3d..01ac2b2 100644 --- a/ts/interfaces/universemessage.interfaces.ts +++ b/ts/interfaces/universemessage.interfaces.ts @@ -1 +1,7 @@ -export interface IUniverseMessage {} +export interface IUniverseMessage { + messageText: string; + targetChannelName: string; + passphrase: string; + payload?: string | number | any; + payloadStringType?: 'Buffer' | 'string' | 'object'; +} diff --git a/ts/smartuniverse.classes.clientuniverse.ts b/ts/smartuniverse.classes.clientuniverse.ts index a30b04d..fda1871 100644 --- a/ts/smartuniverse.classes.clientuniverse.ts +++ b/ts/smartuniverse.classes.clientuniverse.ts @@ -31,11 +31,8 @@ export class ClientUniverse { this.options = optionsArg; } - public async sendMessage(messageArg, payloadArg) { - const requestBody: interfaces.IUniverseMessage = { - message: messageArg, - payload: payloadArg - }; + public async sendMessage(messageArg: interfaces.IUniverseMessage) { + const requestBody: interfaces.IUniverseMessage = messageArg; const requestBodyString = JSON.stringify(requestBody); // TODO: User websocket connection if available const response = await plugins.smartrequest.postJson(`${this.options.serverAddress}/sendmessage` , { diff --git a/ts/smartuniverse.classes.universe.ts b/ts/smartuniverse.classes.universe.ts index 3dc0b2d..b0bf736 100644 --- a/ts/smartuniverse.classes.universe.ts +++ b/ts/smartuniverse.classes.universe.ts @@ -67,7 +67,7 @@ export class Universe { /** * initiates a server */ - public async initServer(portArg: number | string) { + public async start(portArg: number | string) { // lets create the base smartexpress server this.smartexpressServer = new plugins.smartexpress.Server({ cors: true, diff --git a/ts/smartuniverse.classes.universemessage.ts b/ts/smartuniverse.classes.universemessage.ts index 2e68b52..15c6c19 100644 --- a/ts/smartuniverse.classes.universemessage.ts +++ b/ts/smartuniverse.classes.universemessage.ts @@ -1,4 +1,5 @@ import * as plugins from './smartuniverse.plugins'; +import * as interfaces from './interfaces'; import { Objectmap } from '@pushrocks/lik'; @@ -11,7 +12,7 @@ import { UniverseCache } from './smartuniverse.classes.universecache'; * represents a message within a universe * acts as a container to save message states like authentication status */ -export class UniverseMessage { +export class UniverseMessage implements interfaces.IUniverseMessage { /** * public and unique id * numeric ascending