Skip to content

Commit

Permalink
Making v2.9.0 pre-release (#1713)
Browse files Browse the repository at this point in the history
### Header
- Policy Differentiation
- Resilient Guardian Service

**Issues Solved**
- Policy Differentiation Feature [#85](#85)
- QA: Disaster Recovery Testing [#362](#362)
- Resilient Guardian Service  [#1596](#1596)
- Support retiring offsets against non-tokenised emissions (i.e. manual retirement) [#1664](#1664)
- Retirement process for assets MVP [#55](#55)
- QA: Soak testing [#1011](#1011)
- Library of Policy examples [#1012](#1012)

**Bugs Fixed**
- CVE-2022-25878 in protobufjs [#1235](#1235)
- setImmediate - the "background process" could be killed by the server without the appropriate timeout [#1589](#1589)
- Presetting conditional fields [#1616](#1616)
- Add URL frontend validations to Registrant form in UI [#1632](#1632)

Changelog:

* restore tokens

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* GitBook: [#210] rearranging the pages

* GitBook: [#211] creating token using UI

* Updated Timestamp of Remote Workflow Policy

* add user topic select

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* fix lint

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* fix validation

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* fix lint

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* fix validation

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* update messages

* update

Signed-off-by: Stepan Kiryakov <stepan.kiryakov@envisionblockchain.com>

* fix typo

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* tmp

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* implement local ipfs node
remove ipfs client

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* update moment.js version

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* update message format

* fix readonly fields in request block

Signed-off-by: artembuslaev <buslaew.ar@mail.ru>

* fix

* fix

* update log

* fix readonly fields
fix save topic keys

* fix lint

* GitBook: [#212] added description to token parameters

* fix save key

* fix

* update swagger

* bump version

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* aggregate documents by custom fields

Signed-off-by: artembuslaev <buslaew.ar@mail.ru>

* update Dovu policy (fix schemas)

* update validation errors

Signed-off-by: Stepan Kiryakov <stepan.kiryakov@envisionblockchain.com>

* update validation errors

Signed-off-by: Stepan Kiryakov <stepan.kiryakov@envisionblockchain.com>

* fix

Signed-off-by: Stepan Kiryakov <stepan.kiryakov@envisionblockchain.com>

* GitBook: [#213] Added GroupByFields property in aggregateBlock

* GitBook: [#214] Setting up local IPFS Node

* Setting Local IPFS node updated in ReadMe

* GitBook: [#215] Added Multi Policy APIs

* update Dovu policy (fix schemas)

* update validation errors

Signed-off-by: Stepan Kiryakov <stepan.kiryakov@envisionblockchain.com>

* update validation errors

Signed-off-by: Stepan Kiryakov <stepan.kiryakov@envisionblockchain.com>

* fix

Signed-off-by: Stepan Kiryakov <stepan.kiryakov@envisionblockchain.com>

* GitBook: [#213] Added GroupByFields property in aggregateBlock

* GitBook: [#214] Setting up local IPFS Node

* Setting Local IPFS node updated in ReadMe

* GitBook: [#215] Added Multi Policy APIs

* MBP projects

* bump version

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* change hedera explorer

Signed-off-by: artembuslaev <buslaew.ar@mail.ru>

* always display delete action on selected block

Signed-off-by: artembuslaev <buslaew.ar@mail.ru>

* update hedera-sdk

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* GitBook: [#220] Multi Policy UI

* GitBook: [#221] corrected local node files

* added message chunk setting

Signed-off-by: artembuslaev <buslaew.ar@mail.ru>

* #1014 MBP projects

* update schemas

* rename

* Updated Verra Timestamp

* added settings to change body request size

Signed-off-by: artembuslaev <buslaew.ar@mail.ru>

* add demo policy

* GitBook: [#224] Changed DragonGlass to Ledger Works in FAQs

* GitBook: [#225] how to change Explorer URL

* add additional events

* update lint

* GitBook: [#227] ImpactAddon block added

* GitBook: [#228] UI Automation Tests

* GitBook: [#229] added AddiitonalMintEvent

* GitBook: [#230] Added Impacts section in ReportBlock

* fix display token type

* fix dependency

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* added IREC 8.1,8.2 in ReadMe

* GitBook: [#231] Added IREC and Verra Intro

* policy comparison

* GitBook: [#232] Remote GHG Policy added

* GitBook: [#233] Remote GHG Policy Demo images

* GitBook: [#234] Artifacts APIs added

* update

* http request block config

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* update

* update

* http-request-block

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* fix lint

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* add validation

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* fix

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* update

* custom logic worker

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* tokens retirement

Signed-off-by: artembuslaev <buslaew.ar@mail.ru>

* fixed endpoints, changed labels

Signed-off-by: artembuslaev <buslaew.ar@mail.ru>

* tokens retirement fixes

Signed-off-by: artembuslaev <buslaew.ar@mail.ru>

* up version

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* fix

Signed-off-by: artembuslaev <buslaew.ar@mail.ru>

* fixed issue with double publishing retire schema

Signed-off-by: artembuslaev <buslaew.ar@mail.ru>

* fix deps

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* GitBook: [#235] Retirement UI and APIs added

* The worker-service now operates on the network specified by guardian-service.

Signed-off-by: Giuseppe Bertone <giuseppe.bertone@swirldslabs.com>

* fix updating token balance in retirement process

Signed-off-by: artembuslaev <buslaew.ar@mail.ru>

* GitBook: [#236] corrected typo in retirement

* added max transaction fee setting to worker

Signed-off-by: artembuslaev <buslaew.ar@mail.ru>

* update default max fee

Signed-off-by: artembuslaev <buslaew.ar@mail.ru>

* GitBook: [#237] Updated env parameters in installation

* up version

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* GitBook: [#239] UI Properties of Interface step Block deprecated

* updated retirement docs, added some checks

Signed-off-by: artembuslaev <buslaew.ar@mail.ru>

* GitBook: [#240] Updated Contract APIs

* fix preset and readonly fields in condition section

Signed-off-by: artembuslaev <buslaew.ar@mail.ru>

* remove setImmidiate

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* update string formats ui validation

Signed-off-by: artembuslaev <buslaew.ar@mail.ru>

* GitBook: [#241] HTTP Request Block added

* GitBook: [#242] Added blocks to available blocks

* remove redundant logs

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* CVE-2022-25878

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* disable autocomplete on tokens count

Signed-off-by: artembuslaev <buslaew.ar@mail.ru>

* change placeholder for url type field

Signed-off-by: artembuslaev <buslaew.ar@mail.ru>

* added retirement contract code

Signed-off-by: artembuslaev <buslaew.ar@mail.ru>

* update

* Changed the iREC User Guide URL in ReadMe

* Updated Verra User Guide link

* fix lint

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* fix tests

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* GitBook: [#243] Corrected Creation of Root API in API Demo Guide of iREC

* compare tokens

* compare conditions

* update

* update

* update

* export in csv

* update tymlez policies

Signed-off-by: artembuslaev <buslaew.ar@mail.ru>

* update

* update

* fix

* fix

* update

* fix

Signed-off-by: Stepan Kiryakov <stepan.kiryakov@envisionblockchain.com>

* fix

Signed-off-by: Stepan Kiryakov <stepan.kiryakov@envisionblockchain.com>

* fix

Signed-off-by: Stepan Kiryakov <stepan.kiryakov@envisionblockchain.com>

* fix

Signed-off-by: Stepan Kiryakov <stepan.kiryakov@envisionblockchain.com>

* GitBook: [#244] Corrected time tracking format in GHG

* fix

Signed-off-by: Stepan Kiryakov <stepan.kiryakov@envisionblockchain.com>

* GitBook: [#245] No subject

* GitBook: [#247] Policy Differentiation UI

* GitBook: [#248] No subject

* GitBook: [#250] No subject

* GitBook: [#251] Policy Differentiation UI

* GitBook: [#252] Policy Differentiation APIs

* GitBook: [#253] Schema Differentiation UI

* GitBook: [#254] Schema Diff APIs

* added possibility to include incomplete pairs

Signed-off-by: artembuslaev <buslaew.ar@mail.ru>

* added contract code, fix

Signed-off-by: artembuslaev <buslaew.ar@mail.ru>

* fix incomplete retire request for nft opposite token

Signed-off-by: artembuslaev <buslaew.ar@mail.ru>

* fix custom logic block error handling

Signed-off-by: artembuslaev <buslaew.ar@mail.ru>

* fix

Signed-off-by: Stepan Kiryakov <stepan.kiryakov@envisionblockchain.com>

* fix

Signed-off-by: Stepan Kiryakov <stepan.kiryakov@envisionblockchain.com>

* fix

Signed-off-by: Stepan Kiryakov <stepan.kiryakov@envisionblockchain.com>

* policy service

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* fixes

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* fix build

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* fix build

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* fix tests

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* add title

* fix

Signed-off-by: artembuslaev <buslaew.ar@mail.ru>

* fix select user role
fix block updates

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* refactor runner

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* fix docker build

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* GitBook: [#255] Updated Retirement screens

* add package lock

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* updated contract file id

Signed-off-by: artembuslaev <buslaew.ar@mail.ru>

* update transmute

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* update transmute

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* Temp fix

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* fix

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* fixes

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* fix available block for interfaceDocumentSourceBlock

Signed-off-by: artembuslaev <buslaew.ar@mail.ru>

* fix trustchain

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* GitBook: [#257] Updated timestamps

* Updated iREC Timestamps

* Updated Verra Timestamps

* Updated GHG timestamp

* GitBook: [#258] Updated Topic ID and Contract ID

* fix lint

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* fix deps

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* refactor

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* fix lint

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* fix receive external data

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* refactor
Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* add .env

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* remove api key

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* fix versions

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* fix policy init

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* fix lint

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* initialization messages

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

* GitBook: [#259] Added Mongo-admin-panel, target deployment

* fix duplicate retire requests

Signed-off-by: artembuslaev <buslaew.ar@mail.ru>

* fix contract query transaction fee

Signed-off-by: artembuslaev <buslaew.ar@mail.ru>

* up version

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>

---------

Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>
Signed-off-by: Stepan Kiryakov <stepan.kiryakov@envisionblockchain.com>
Signed-off-by: artembuslaev <buslaew.ar@mail.ru>
Signed-off-by: Giuseppe Bertone <giuseppe.bertone@swirldslabs.com>
Co-authored-by: prernaa.agarwal <prernaa.agarwal@envisionblockchain.com>
Co-authored-by: prernaadev01 <79293833+prernaadev01@users.noreply.github.com>
Co-authored-by: Stepan Kiryakov <stepan.kiryakov@envisionblockchain.com>
Co-authored-by: artembuslaev <buslaew.ar@mail.ru>
Co-authored-by: Stepan Kirjakov <84465157+Stepan-Kirjakov@users.noreply.github.com>
Co-authored-by: artembuslaev <68849616+artembuslaev@users.noreply.github.com>
Co-authored-by: Giuseppe Bertone <giuseppe.bertone@swirldslabs.com>
  • Loading branch information
8 people authored Jan 30, 2023
1 parent 34a86e4 commit 3e6b8f8
Show file tree
Hide file tree
Showing 518 changed files with 46,833 additions and 1,752 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ jobs:
npm install
npm run build
popd
pushd policy-service
npm install
npm run build
popd
pushd worker-service
npm install
npm run build
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ jobs:
npm install
npm run build
popd
pushd policy-service
npm install
npm run build
popd
pushd guardian-service
npm install
npm run build
Expand Down Expand Up @@ -62,6 +66,9 @@ jobs:
pushd auth-service
npm run lint
popd
pushd policy-service
npm run lint
popd
pushd guardian-service
npm run lint
popd
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,24 @@ jobs:
push: true
tags: 'gcr.io/hedera-registry/api-gateway:${{ steps.package-version.outputs.current-version}}'

- name: policy-service-latest
if: ${{ steps.latestTag.outputs.value == 'latest'}}
uses: docker/build-push-action@v2
with:
context: .
file: ./policy-service/Dockerfile
push: true
tags: 'gcr.io/hedera-registry/policy-service:${{ steps.package-version.outputs.current-version}}, gcr.io/hedera-registry/policy-service:latest'

- name: policy-service
if: ${{ steps.latestTag.outputs.value == 'hotfix'}}
uses: docker/build-push-action@v2
with:
context: .
file: ./policy-service/Dockerfile
push: true
tags: 'gcr.io/hedera-registry/policy-service:${{ steps.package-version.outputs.current-version}}'

- name: guardian-service-latest
if: ${{ steps.latestTag.outputs.value == 'latest'}}
uses: docker/build-push-action@v2
Expand Down
Binary file modified Demo Artifacts/CET & CRU/Tymlez/policies/Tymlez-CET.policy
Binary file not shown.
Binary file modified Demo Artifacts/CET & CRU/Tymlez/policies/Tymlez-CRU.policy
Binary file not shown.
2 changes: 1 addition & 1 deletion Demo Artifacts/Verra/Verra Redd/VM0007/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ For Demo purpose, we have uploaded two versions of Verra Policies into IPFS and

In addition to the above Policy Versions, we have also added Schema Design Template file for demo purpose. Please check : [Sample Design Template](https://github.com/hashgraph/guardian/blob/main/Demo%20Artifacts/Verra/Verra%20Redd/VM0007/REDD%20APD%20Schema%20Design%20Template.xlsx)

For step by step user guide to execute Verra Policy, please refer to https://docs.hedera.com/guardian/demo-guide/verra-redd+-demo-guide.
For step by step user guide to execute Verra Policy, please refer to https://docs.hedera.com/guardian/guardian/demo-guide/carbon-offsets/verra-redd+-demo-guide.

2 changes: 1 addition & 1 deletion Demo Artifacts/iREC/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ As the initial step in IREC Policy involve creation of following Schemas: iRec r

For complete User Guide and API Flow for executing IREC Policy, please refer to :

IREC User Guide : https://docs.hedera.com/guardian/demo-guide/irec-demo-guide
IREC User Guide : https://docs.hedera.com/guardian/guardian/demo-guide/renewable-energy-credits/introduction-to-international-renewable-energy-credit-standard-irec

IREC API Demo Guide : https://docs.hedera.com/guardian/demo-guide/api-workflow-of-irec-demo
2 changes: 1 addition & 1 deletion api-docs/api/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ openapi: 3.0.0
info:
title: "Guardian"
description: "The Guardian is a modular open-source solution that includes best-in-class identity management and decentralized ledger technology (DLT) libraries. At the heart of the Guardian solution is a sophisticated Policy Workflow Engine (PWE) that enables applications to offer a requirements-based tokenization implementation."
version: "2.8.1"
version: "2.9.0"
contact:
name: "API developer"
url: "https://envisionblockchain.com"
Expand Down
5 changes: 3 additions & 2 deletions api-docs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "api-docs",
"version": "2.8.1",
"version": "2.9.0-prerelease",
"description": "Swagger Documentation",
"main": "dist/index.js",
"scripts": {
Expand All @@ -23,5 +23,6 @@
"@types/swagger-ui-express": "^4.1.3",
"tslint": "^6.1.3",
"typescript": "^4.6.3"
}
},
"stableVersion": "2.8.1"
}
7 changes: 4 additions & 3 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 <info@envisionblockchain.com>",
"dependencies": {
"@guardian/common": "^2.8.1",
"@guardian/interfaces": "^2.8.1",
"@guardian/common": "^2.9.0-prerelease",
"@guardian/interfaces": "^2.9.0-prerelease",
"@types/express-fileupload": "^1.4.1",
"dotenv": "^16.0.0",
"express": "^4.17.1",
Expand Down Expand Up @@ -51,5 +51,6 @@
"start": "node dist/index.js",
"test": "mocha tests/**/*.test.js --reporter mocha-junit-reporter --reporter-options mochaFile=../test_results/ui-service.xml"
},
"version": "2.8.1"
"version": "2.9.0-prerelease",
"stableVersion": "2.8.1"
}
94 changes: 94 additions & 0 deletions api-gateway/src/api/service/analytics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { Guardians } from '@helpers/guardians';
import { Response, Router } from 'express';
import { AuthenticatedRequest, Logger } from '@guardian/common';

/**
* User analytics route
*/
export const analyticsAPI = Router();

analyticsAPI.post('/compare/policies', async (req: AuthenticatedRequest, res: Response) => {
const guardians = new Guardians();
const policyId1 = req.body ? req.body.policyId1 : null;
const policyId2 = req.body ? req.body.policyId2 : null;
const eventsLvl = req.body ? req.body.eventsLvl : null;
const propLvl = req.body ? req.body.propLvl : null;
const childrenLvl = req.body ? req.body.childrenLvl : null;
const idLvl = req.body ? req.body.idLvl : null;
const user = req.user;
try {
const result = await guardians.comparePolicies(
user,
null,
policyId1,
policyId2,
eventsLvl,
propLvl,
childrenLvl,
idLvl
);
res.send(result);
} catch (error) {
new Logger().error(error, ['API_GATEWAY']);
res.status(500).send({ code: 500, message: error.message });
}
});

analyticsAPI.post('/compare/schemas', async (req: AuthenticatedRequest, res: Response) => {
const guardians = new Guardians();
const schemaId1 = req.body ? req.body.schemaId1 : null;
const schemaId2 = req.body ? req.body.schemaId2 : null;
const idLvl = req.body ? req.body.idLvl : null;
const user = req.user;
try {
const result = await guardians.compareSchemas(user, null, schemaId1, schemaId2, idLvl);
res.send(result);
} catch (error) {
new Logger().error(error, ['API_GATEWAY']);
res.status(500).send({ code: 500, message: error.message });
}
});

analyticsAPI.post('/compare/policies/export', async (req: AuthenticatedRequest, res: Response) => {
const guardians = new Guardians();
const type = req.query ? req.query.type : null;
const policyId1 = req.body ? req.body.policyId1 : null;
const policyId2 = req.body ? req.body.policyId2 : null;
const eventsLvl = req.body ? req.body.eventsLvl : null;
const propLvl = req.body ? req.body.propLvl : null;
const childrenLvl = req.body ? req.body.childrenLvl : null;
const idLvl = req.body ? req.body.idLvl : null;
const user = req.user;
try {
const result = await guardians.comparePolicies(
user,
type,
policyId1,
policyId2,
eventsLvl,
propLvl,
childrenLvl,
idLvl
);
res.send(result);
} catch (error) {
new Logger().error(error, ['API_GATEWAY']);
res.status(500).send({ code: 500, message: error.message });
}
});

analyticsAPI.post('/compare/schemas/export', async (req: AuthenticatedRequest, res: Response) => {
const guardians = new Guardians();
const type = req.query ? req.query.type : null;
const schemaId1 = req.body ? req.body.schemaId1 : null;
const schemaId2 = req.body ? req.body.schemaId2 : null;
const idLvl = req.body ? req.body.idLvl : null;
const user = req.user;
try {
const result = await guardians.compareSchemas(user, type, schemaId1, schemaId2, idLvl);
res.send(result);
} catch (error) {
new Logger().error(error, ['API_GATEWAY']);
res.status(500).send({ code: 500, message: error.message });
}
});
37 changes: 18 additions & 19 deletions api-gateway/src/api/service/demo.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Request, Response, Router } from 'express';
import { Guardians } from '@helpers/guardians';
import { Users } from '@helpers/users';
import { Logger } from '@guardian/common';
import { Logger, RunFunctionAsync } from '@guardian/common';
import { TaskManager } from '@helpers/task-manager';
import { ServiceError } from '@helpers/service-requests-base';

/**
* Route for demo api
Expand Down Expand Up @@ -58,26 +59,24 @@ demoAPI.get('/push/randomKey', async (req: Request, res: Response) => {
const { taskId, expectation } = taskManager.start('Create random key');

const authHeader = req?.headers?.authorization;
setImmediate(async () => {
try {
const guardians = new Guardians();
let role = null;
if (authHeader) {
try {
const users = new Users();
const token = authHeader.split(' ')[1];
const user = await users.getUserByToken(token) as any;
role = user?.role;
} catch (error) {
role = null;
}
RunFunctionAsync<ServiceError>(async () => {
const guardians = new Guardians();
let role = null;
if (authHeader) {
try {
const users = new Users();
const token = authHeader.split(' ')[1];
const user = await users.getUserByToken(token) as any;
role = user?.role;
} catch (error) {
role = null;
}

await guardians.generateDemoKeyAsync(role, taskId);
} catch (error) {
new Logger().error(error, ['API_GATEWAY']);
taskManager.addError(taskId, { code: 500, message: error.message });
}

await guardians.generateDemoKeyAsync(role, taskId);
}, async (error) => {
new Logger().error(error, ['API_GATEWAY']);
taskManager.addError(taskId, { code: 500, message: error.message });
});

res.status(201).send({ taskId, expectation });
Expand Down
1 change: 1 addition & 0 deletions api-gateway/src/api/service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export {externalAPI} from '@api/service/external';
export {ipfsAPI} from '@api/service/ipfs'
export {loggerAPI} from '@api/service/logger';
export {settingsAPI} from '@api/service/settings';
export {analyticsAPI} from '@api/service/analytics';
Loading

0 comments on commit 3e6b8f8

Please sign in to comment.