Skip to content

Commit

Permalink
Fixes for pre-release 2.11.0 from develop into main (#1963)
Browse files Browse the repository at this point in the history
* set ids for nested objects

Signed-off-by: artembuslaev <[email protected]>

* update

* fix validation

Signed-off-by: simvalery <[email protected]>

* fix bad state answers

Signed-off-by: simvalery <[email protected]>

* Using the new kubo 0.18 docker image;

Signed-off-by: Giuseppe Bertone <[email protected]>

* update

* remove inputFields property from custom logic block

Signed-off-by: artembuslaev <[email protected]>

* update

Signed-off-by: Stepan Kiryakov <[email protected]>

* GITBOOK-282: updated retirement screenshots

* added new verra redd policy [skip ci]

Signed-off-by: artembuslaev <[email protected]>

* added not found documents item to trustchain

Signed-off-by: artembuslaev <[email protected]>

* fix artifact's error messages, added comments

Signed-off-by: artembuslaev <[email protected]>

* fix lint

Signed-off-by: artembuslaev <[email protected]>

* fix payload too large issue

Signed-off-by: artembuslaev <[email protected]>

* change default value for json request limit

Signed-off-by: artembuslaev <[email protected]>

* гзвфеу

* update

* fix display image fields

Signed-off-by: artembuslaev <[email protected]>

* create tokens when policy publish

Signed-off-by: simvalery <[email protected]>

* merge develop

Signed-off-by: simvalery <[email protected]>

* ipfs node version

Signed-off-by: simvalery <[email protected]>

* fix validation

Signed-off-by: simvalery <[email protected]>

* fix validation

Signed-off-by: simvalery <[email protected]>

* update

* update

* update

* remove

* remove

* Update CONTRIBUTING.md

new PRs shoud go to develop

Signed-off-by: noel garcia <[email protected]>

* remove hardcoded transaction fee

Signed-off-by: artembuslaev <[email protected]>

* added nodes settings

Signed-off-by: artembuslaev <[email protected]>

* fix

Signed-off-by: artembuslaev <[email protected]>

* added custom nodes to policy process

Signed-off-by: artembuslaev <[email protected]>

* up hedera sdk version

Signed-off-by: artembuslaev <[email protected]>

* update

* fix

Signed-off-by: artembuslaev <[email protected]>

* remove CUSTOM_CLIENT_NODES setting

Signed-off-by: artembuslaev <[email protected]>

* fix lint

Signed-off-by: artembuslaev <[email protected]>

* fixed convert bytes to base64 image

Signed-off-by: artembuslaev <[email protected]>

* fix visible for draft tokens in retire dialog

Signed-off-by: artembuslaev <[email protected]>

* fix create and import draft tokens

Signed-off-by: artembuslaev <[email protected]>

* update

Signed-off-by: Stepan Kiryakov <[email protected]>

* fix

Signed-off-by: Stepan Kiryakov <[email protected]>

* fix

Signed-off-by: Stepan Kiryakov <[email protected]>

* publish tokens

Signed-off-by: simvalery <[email protected]>

* fix

Signed-off-by: Stepan Kiryakov <[email protected]>

* fix header

* fix token type visible for dynamic tokens

Signed-off-by: artembuslaev <[email protected]>

* fix validation

Signed-off-by: Stepan Kiryakov <[email protected]>

* fix

Signed-off-by: Stepan Kiryakov <[email protected]>

* fix undo\redo

Signed-off-by: Stepan Kiryakov <[email protected]>

* fix

Signed-off-by: Stepan Kiryakov <[email protected]>

* fix

Signed-off-by: Stepan Kiryakov <[email protected]>

* fix

Signed-off-by: Stepan Kiryakov <[email protected]>

* GITBOOK-286: Selective Disclosure changes

* GITBOOK-287: Added env parameters for hedera custom nodes

* fix

* fix

* GITBOOK-288: updated docs : docker config for M1

* Create README.md

* Create README.md

* fix

* Add files via upload

* Updated Description

* added modules api to swagger

Signed-off-by: artembuslaev <[email protected]>

* remove logs from modules api

Signed-off-by: artembuslaev <[email protected]>

* fix module validation

Signed-off-by: Stepan Kiryakov <[email protected]>

* fix

Signed-off-by: Stepan Kiryakov <[email protected]>

* fix import module

Signed-off-by: Stepan Kiryakov <[email protected]>

* fix

Signed-off-by: Stepan Kiryakov <[email protected]>

* fix worker exceptions

Signed-off-by: simvalery <[email protected]>

* added menu modules endpoint, fixes

Signed-off-by: artembuslaev <[email protected]>

* add new config

Signed-off-by: Stepan Kiryakov <[email protected]>

* refactor

Signed-off-by: simvalery <[email protected]>

* fix create new module

Signed-off-by: Stepan Kiryakov <[email protected]>

* fix style

Signed-off-by: Stepan Kiryakov <[email protected]>

* add demo artifacts

Signed-off-by: Stepan Kiryakov <[email protected]>

* fix mint draft tokens

Signed-off-by: artembuslaev <[email protected]>

* moved verra redd 4 [skip ci]

Signed-off-by: artembuslaev <[email protected]>

* bump version

Signed-off-by: simvalery <[email protected]>

* Rename "Demo Artifacts" to "Methodology Library"

Signed-off-by: simvalery <[email protected]>

* fix search

Signed-off-by: Stepan Kiryakov <[email protected]>

* GITBOOK-289: Module APIs

* Corrected links in ReadMe of Methodology Library

* corrected links in ReadMe

* corrected links in irec readme

* fix mathjs

Signed-off-by: Stepan Kiryakov <[email protected]>

* Updated links in Verra ReadMe

* fix mathjs

Signed-off-by: Stepan Kiryakov <[email protected]>

* Added VM0017 ReadMe

* Updated ReadMe

* Delete

* GITBOOK-290: Added enable individual filters property

* fix workflow

Signed-off-by: simvalery <[email protected]>

* fix workflow

Signed-off-by: simvalery <[email protected]>

* fix workflow

Signed-off-by: simvalery <[email protected]>

* fix workflow

Signed-off-by: simvalery <[email protected]>

* add workflow_dispatch to publish workflow

Signed-off-by: simvalery <[email protected]>

* fix root tag

Signed-off-by: Stepan Kiryakov <[email protected]>

* fix menu style

Signed-off-by: Stepan Kiryakov <[email protected]>

* fix convert to module

Signed-off-by: Stepan Kiryakov <[email protected]>

* added disabling user grouping

Signed-off-by: artembuslaev <[email protected]>

* fix displaying sub menu for safari

Signed-off-by: artembuslaev <[email protected]>

* #1882 update error message

* #1882 update error message

* update nav menu

* GITBOOK-291: Modules Demo using UI

* fix

Signed-off-by: artembuslaev <[email protected]>

* added custom pattern to schema configuration

Signed-off-by: artembuslaev <[email protected]>

* fix string type with custom pattern

Signed-off-by: artembuslaev <[email protected]>

* fix pattern property for other types

Signed-off-by: artembuslaev <[email protected]>

* clickable user info

Signed-off-by: artembuslaev <[email protected]>

* fix

Signed-off-by: artembuslaev <[email protected]>

* updates swagger [skip ci]

Signed-off-by: artembuslaev <[email protected]>

* GITBOOK-292: Added pattern input description for String field type

* GITBOOK-293: Added timestamp for modules

* fix

Signed-off-by: Stepan Kiryakov <[email protected]>

* added geoJSON type

Signed-off-by: artembuslaev <[email protected]>

* update swagger [skip ci]

Signed-off-by: artembuslaev <[email protected]>

* change type name

Signed-off-by: artembuslaev <[email protected]>

* fix publish policy file

* GITBOOK-295: Added GeoJSON Schema type

* GITBOOK-296: added Map API

* added verra redd 5 policy [skip ci]

Signed-off-by: artembuslaev <[email protected]>

* GITBOOK-298: added operator id and key note

* fix

Signed-off-by: artembuslaev <[email protected]>

* GITBOOK-299: added prerequisites version

* added uri schema type

Signed-off-by: artembuslaev <[email protected]>

* multiple instances

Signed-off-by: simvalery <[email protected]>

* fix policy start

Signed-off-by: simvalery <[email protected]>

* fix lint

Signed-off-by: simvalery <[email protected]>

* fix build
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* fix
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* fix build

Signed-off-by: simvalery <[email protected]>

* fix logs

Signed-off-by: simvalery <[email protected]>

* fix lint

Signed-off-by: simvalery <[email protected]>

* fix build

Signed-off-by: simvalery <[email protected]>

* temporary skip tests

Signed-off-by: simvalery <[email protected]>

* fix tests exit

Signed-off-by: simvalery <[email protected]>

* fix

Signed-off-by: artembuslaev <[email protected]>

* GITBOOK-300: Added INITIALIZATION TOPIC IDs for networks

* GITBOOK-302: Updated Roadmap

* fixed type polygon in geojson

Signed-off-by: artembuslaev <[email protected]>

* update document state entity in guardian-service

Signed-off-by: artembuslaev <[email protected]>

* fix import policy

Signed-off-by: simvalery <[email protected]>

* fix login crash

Signed-off-by: simvalery <[email protected]>

* update verra redd 5 policy [skip ci]

Signed-off-by: artembuslaev <[email protected]>

* fix

Signed-off-by: artembuslaev <[email protected]>

* fix uri ui validator

Signed-off-by: artembuslaev <[email protected]>

* swap coordinates for geojson

Signed-off-by: artembuslaev <[email protected]>

* rework worker-queue

Signed-off-by: simvalery <[email protected]>

* fix policy processes

Signed-off-by: artembuslaev <[email protected]>

* fix lint

Signed-off-by: simvalery <[email protected]>

* GITBOOK-303: Removed UI Properties of InterfaceStep Block

* fix map api authorization error
increase workers queues speed

Signed-off-by: simvalery <[email protected]>

* fix policy ready receiver

Signed-off-by: simvalery <[email protected]>

* worker tasks optimization

Signed-off-by: simvalery <[email protected]>

* start instance script

Signed-off-by: simvalery <[email protected]>

* fix litn
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* bump version

Signed-off-by: simvalery <[email protected]>

* GITBOOK-306: Added Agrecalc demo

* GITBOOK-307: Added Improve Cookstove

* pack messages

Signed-off-by: simvalery <[email protected]>

* fix block update

Signed-off-by: simvalery <[email protected]>

* fix task completion

Signed-off-by: simvalery <[email protected]>

* fix task queue

Signed-off-by: simvalery <[email protected]>

* fix error

Signed-off-by: simvalery <[email protected]>

* fix task retry

Signed-off-by: simvalery <[email protected]>

* fix lint

Signed-off-by: simvalery <[email protected]>

* fix docker compose

Signed-off-by: simvalery <[email protected]>

* delete folder

Signed-off-by: simvalery <[email protected]>

* fixes

Signed-off-by: simvalery <[email protected]>

* share tasks

Signed-off-by: simvalery <[email protected]>

* service scripts

Signed-off-by: simvalery <[email protected]>

* clean code

Signed-off-by: simvalery <[email protected]>

* policy instance container

Signed-off-by: simvalery <[email protected]>

* fix tests

Signed-off-by: simvalery <[email protected]>

* corrected broken links in ReadMe

* added versions to ReadMe

* increase max hedera timeout

Signed-off-by: simvalery <[email protected]>

* bump version

Signed-off-by: simvalery <[email protected]>

* fix workers queue

Signed-off-by: simvalery <[email protected]>

* test fix

Signed-off-by: simvalery <[email protected]>

* wss updates

Signed-off-by: simvalery <[email protected]>

* fix

Signed-off-by: simvalery <[email protected]>

* fix

Signed-off-by: simvalery <[email protected]>

* fix block errors

Signed-off-by: simvalery <[email protected]>

* fix messageId

Signed-off-by: simvalery <[email protected]>

---------

Signed-off-by: artembuslaev <[email protected]>
Signed-off-by: simvalery <[email protected]>
Signed-off-by: Giuseppe Bertone <[email protected]>
Signed-off-by: Stepan Kiryakov <[email protected]>
Signed-off-by: noel garcia <[email protected]>
Co-authored-by: artembuslaev <[email protected]>
Co-authored-by: Stepan Kiryakov <[email protected]>
Co-authored-by: Giuseppe Bertone <[email protected]>
Co-authored-by: prernaa.agarwal <[email protected]>
Co-authored-by: artembuslaev <[email protected]>
Co-authored-by: Noel Garcia <[email protected]>
Co-authored-by: prernaadev01 <[email protected]>
Co-authored-by: Stepan Kirjakov <[email protected]>
Co-authored-by: dubgeis <[email protected]>
  • Loading branch information
10 people authored Mar 31, 2023
1 parent 75da2df commit 6ecd859
Show file tree
Hide file tree
Showing 185 changed files with 1,142 additions and 679 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ When building the reference implementation, you can [manually build every compon

* [Docker](https://www.docker.com)

If you build with docker [MongoDB](https://www.mongodb.com), [NodeJS](https://nodejs.org) and [Nats](https://nats.io/) will be installed and configured automatically.
If you build with docker [MongoDB V6](https://www.mongodb.com), [NodeJS V16](https://nodejs.org) and [Nats 1.12.2](https://nats.io/) will be installed and configured automatically.

### Installation

Expand Down Expand Up @@ -95,7 +95,7 @@ If you build with docker [MongoDB](https://www.mongodb.com), [NodeJS](https://no
IPFS_PROVIDER="web3storage"
```

To generate Web3.Storage API KEY. Please follow the steps from <https://web3.storage/docs/#quickstart> to obtain it.To know complete information on generating API Key please check [How to Create Web3.Storage API Key](https://docs.hedera.com/guardian/getting-started/getting-started/how-to-create-web3.storage-api-key).
To generate Web3.Storage API KEY. Please follow the steps from <https://web3.storage/docs/#quickstart> to obtain it.To know complete information on generating API Key please check [How to Create Web3.Storage API Key](https://docs.hedera.com/guardian/guardian/readme/getting-started/how-to-generate-web3.storage-api-key).

4. Build and launch with Docker. Please note that this build is meant to be used in production and will not contain any debug information. From the project's root folder:

Expand All @@ -111,9 +111,9 @@ If you want to manually build every component with debug information, then build

### Prerequisites for manual installation

* [MongoDB](https://www.mongodb.com)
* [NodeJS](https://nodejs.org)
* [Nats](https://nats.io/)
* [MongoDB V6](https://www.mongodb.com)
* [NodeJS V16](https://nodejs.org)
* [Nats 1.12.2](https://nats.io/)

### Build and start each component

Expand Down
5 changes: 2 additions & 3 deletions api-docs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "api-docs",
"version": "2.11.0-prerelease",
"version": "2.11.0",
"description": "Swagger Documentation",
"main": "dist/index.js",
"scripts": {
Expand All @@ -24,6 +24,5 @@
"@types/swagger-ui-express": "^4.1.3",
"tslint": "^6.1.3",
"typescript": "^4.6.3"
},
"stableVersion": "2.10.0"
}
}
7 changes: 3 additions & 4 deletions api-gateway/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
},
"author": "Envision Blockchain Solutions <[email protected]>",
"dependencies": {
"@guardian/common": "^2.11.0-prerelease",
"@guardian/interfaces": "^2.11.0-prerelease",
"@guardian/common": "^2.11.0",
"@guardian/interfaces": "^2.11.0",
"@types/express-fileupload": "^1.4.1",
"dotenv": "^16.0.0",
"express": "^4.17.1",
Expand Down Expand Up @@ -52,6 +52,5 @@
"start": "node dist/index.js",
"test": "mocha tests/**/*.test.js --reporter mocha-junit-reporter --reporter-options mochaFile=../test_results/ui-service.xml"
},
"version": "2.11.0-prerelease",
"stableVersion": "2.10.0"
"version": "2.11.0"
}
86 changes: 55 additions & 31 deletions api-gateway/src/api/service/websockets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class WebSocketsServiceChannel extends NatsService {
/**
* Message queue name
*/
public messageQueueName = 'wss-queue';
public messageQueueName = 'wss-queue-' + GenerateUUIDv4();

/**
* Reply subject
Expand Down Expand Up @@ -102,19 +102,30 @@ export class WebSocketsService {
* @private
*/
private registerMessageHandler(): void {
this.channel.registerListener('update-block', async (msg) => {
this.wss.clients.forEach((client: any) => {
if (this.checkUserByDid(client, msg)) {
this.send(client, {
type: 'update-event',
data: msg.uuid
});
}
});
let updateArray = [];

setInterval(() => {
const a = updateArray;
updateArray = [];
for (const msg of a) {
this.wss.clients.forEach((client: any) => {
if (this.checkUserByDid(client, msg)) {
this.send(client, {
type: 'update-event',
data: msg.uuid
});
}
});
}
}, 500);

this.channel.subscribe('update-block', async (msg) => {
updateArray.push(msg);

return new MessageResponse({})
});

this.channel.registerListener('block-error', async (msg) => {
this.channel.subscribe('block-error', async (msg) => {
this.wss.clients.forEach((client: any) => {
if (this.checkUserByDid(client, msg)) {
this.send(client, {
Expand All @@ -129,7 +140,7 @@ export class WebSocketsService {
return new MessageResponse({})
});

this.channel.registerListener('update-user-info', async (msg) => {
this.channel.subscribe('update-user-info', async (msg) => {
this.wss.clients.forEach((client: any) => {
if (this.checkUserByDid(client, msg)) {
this.send(client, {
Expand All @@ -141,7 +152,7 @@ export class WebSocketsService {
return new MessageResponse({});
});

this.channel.registerListener('update-user-balance', async (msg) => {
this.channel.subscribe('update-user-balance', async (msg) => {
this.wss.clients.forEach(client => {
new Users().getUserByAccount(msg.operatorAccountId).then(user => {{
Object.assign(msg, {
Expand All @@ -162,7 +173,7 @@ export class WebSocketsService {
return new MessageResponse({});
});

this.channel.registerListener(MessageAPI.UPDATE_STATUS, async (msg) => {
this.channel.subscribe(MessageAPI.UPDATE_STATUS, async (msg) => {
this.wss.clients.forEach((client: any) => {
for (const [key, value] of Object.entries(msg)) {
this.knownServices[key] = value as any;
Expand Down Expand Up @@ -216,28 +227,41 @@ export class WebSocketsService {
}
break;
case MessageAPI.GET_STATUS:
// const logger = new Logger();
// const guardians = new Guardians();
// const auth = new Users();
const channel = new WebSocketsServiceChannel();

const statuses = {
LOGGER_SERVICE: [],
GUARDIAN_SERVICE: [],
AUTH_SERVICE: [],
WORKER: [],
POLICY_SERVICE: []
};

const getStatuses = (): Promise<void> => {
channel.publish(MessageAPI.GET_STATUS);
return new Promise(resolve => {
const sub = channel.subscribe(MessageAPI.SEND_STATUS, (msg) => {
const { name, state } = msg;

// const [
// LOGGER_SERVICE,
// GUARDIAN_SERVICE,
// AUTH_SERVICE
// ] = await Promise.all([
// logger.getStatus(),
// guardians.getStatus(),
// auth.getStatus()
// ]);
if (!statuses[name]) {
statuses[name] = [];
}
statuses[name].push(state);
})

setTimeout(() => {
sub.unsubscribe();
resolve();
}, 300);
})
}

await getStatuses();

ws.send(JSON.stringify(
{
type: MessageAPI.GET_STATUS,
data: Object.assign(this.knownServices, {
// LOGGER_SERVICE,
// GUARDIAN_SERVICE,
// AUTH_SERVICE
})
data: statuses
}
));
break;
Expand Down
12 changes: 11 additions & 1 deletion api-gateway/src/helpers/task-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class TaskManager {
this.wsService = wsService;
this.channel = new TaskManagerChannel();
this.channel.setConnection(cn);
this.channel.registerListener(MessageAPI.UPDATE_TASK_STATUS, async (msg) => {
this.channel.subscribe(MessageAPI.UPDATE_TASK_STATUS, async (msg) => {
const { taskId, statuses, result, error } = msg;
if (taskId) {
if (statuses) {
Expand All @@ -96,6 +96,12 @@ export class TaskManager {

return new MessageResponse({});
});
this.channel.subscribe(MessageAPI.PUBLISH_TASK, async (msg) => {
const {taskId, taskName} = msg;
if (!this.tasks[taskId]) {
this.tasks[taskId] = new Task(taskName);
}
})
}

/**
Expand All @@ -110,6 +116,10 @@ export class TaskManager {
}

this.tasks[taskId] = new Task(taskName);
this.channel.publish(MessageAPI.PUBLISH_TASK, {
taskId,
taskName
})

const expectation = this.getExpectation(taskName);
return { taskId, expectation };
Expand Down
3 changes: 1 addition & 2 deletions api-tests/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "api-tests",
"version": "2.11.0-prerelease",
"stableVersion": "2.10.0",
"version": "2.11.0",
"description": "API Tests",
"main": "index.js",
"scripts": {
Expand Down
7 changes: 3 additions & 4 deletions auth-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
},
"author": "Envision Blockchain Solutions <[email protected]>",
"dependencies": {
"@guardian/common": "^2.11.0-prerelease",
"@guardian/interfaces": "^2.11.0-prerelease",
"@guardian/common": "^2.11.0",
"@guardian/interfaces": "^2.11.0",
"@mikro-orm/core": "~5.3.0",
"@mikro-orm/mongodb": "~5.3.0",
"dotenv": "^16.0.0",
Expand Down Expand Up @@ -47,6 +47,5 @@
"start": "node dist/index.js",
"test": "mocha tests/**/*.test.js --reporter mocha-junit-reporter --reporter-options mochaFile=../test_results/ui-service.xml"
},
"version": "2.11.0-prerelease",
"stableVersion": "2.10.0"
"version": "2.11.0"
}
5 changes: 2 additions & 3 deletions auth-service/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ Promise.all([
InitializeVault(process.env.VAULT_PROVIDER)
]).then(async ([_, db, cn, vault]) => {
DB_DI.orm = db;
const state = new ApplicationState('AUTH_SERVICE');

state.setConnection(cn);
const state = new ApplicationState();
await state.setServiceName('AUTH_SERVICE').setConnection(cn).init();
state.updateState(ApplicationStates.INITIALIZING);
try {
await fixtures();
Expand Down
5 changes: 2 additions & 3 deletions common/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"author": "Envision Blockchain Solutions <[email protected]>",
"dependencies": {
"@guardian/interfaces": "^2.11.0-prerelease",
"@guardian/interfaces": "^2.11.0",
"@mikro-orm/core": "~5.3.0",
"@mikro-orm/migrations-mongodb": "~5.3.0",
"@mikro-orm/mongodb": "~5.3.0",
Expand Down Expand Up @@ -36,6 +36,5 @@
"prepack": "npm run build:prod",
"test": "echo \"Error: no test specified\" && exit 1"
},
"version": "2.11.0-prerelease",
"stableVersion": "2.10.0"
"version": "2.11.0"
}
61 changes: 20 additions & 41 deletions common/src/helpers/application-state.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { Singleton } from '../decorators/singleton';
import { NatsService } from '../mq';
import { ApplicationStates, GenerateUUIDv4, MessageAPI } from '@guardian/interfaces';
import { MessageResponse, MessageError } from '../models';
import { NatsConnection } from 'nats';

/**
* PolicyEngineChannel
* Application state container
*/
@Singleton
export class ApplicationStateChannel extends NatsService {
export class ApplicationState extends NatsService {
/**
* Message queue name
*/
Expand All @@ -19,27 +17,6 @@ export class ApplicationStateChannel extends NatsService {
* @private
*/
public replySubject = 'application-state-queue-reply-' + GenerateUUIDv4();

/**
* Register listener
* @param event
* @param cb
*/
registerListener(event: string, cb: Function): void {
this.getMessages(event, cb);
}
}

/**
* Application state container
*/
@Singleton
export class ApplicationState {
/**
* Message broker channel
* @private
*/
private channel: ApplicationStateChannel;
/**
* Current state
* @private
Expand All @@ -49,34 +26,36 @@ export class ApplicationState {
* Service name
* @private
*/
private readonly serviceName: string;
private serviceName: string;

/**
* Register channel
* @param channel: MessageBrokerChannel
* Init
*/
public async setConnection(cn: NatsConnection): Promise<any> {
this.channel = new ApplicationStateChannel();
this.channel.setConnection(cn);
await this.channel.registerListener(MessageAPI.GET_STATUS, async () => {
try {
return new MessageResponse(this.state);
}
catch (error) {
return new MessageError(error);
}
public async init(): Promise<void> {
await super.init();
await this.subscribe(MessageAPI.GET_STATUS, async () => {
this.publish(MessageAPI.SEND_STATUS, {
name: this.serviceName,
state: this.state
})
});
}

constructor(serviceName?: string) {
this.serviceName = serviceName;
/**
* Set service name
* @param serviceName
*/
setServiceName(serviceName: string): ApplicationState {
this.serviceName = serviceName
return this;
}

/**
* Get current state
*/
public getState(): ApplicationStates {
return this.state;
return ApplicationStates.READY;
}

/**
Expand All @@ -88,7 +67,7 @@ export class ApplicationState {
if (this.serviceName) {
const res = {};
res[this.serviceName] = state;
this.channel.sendMessage(MessageAPI.UPDATE_STATUS, res);
this.publish(MessageAPI.UPDATE_STATUS, res);
}
}
}
Loading

0 comments on commit 6ecd859

Please sign in to comment.