Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/1155 #1970

Merged
merged 19 commits into from
Apr 10, 2023
6 changes: 6 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ jobs:
CI: true
- name: Test
run: |
pushd common
npm run test
popd
pushd policy-service
npm run test
popd
pushd guardian-service
npm run test
popd
Expand Down
6 changes: 6 additions & 0 deletions api-tests/test-suits/accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ function Accounts() {
delete result.data.id;
delete result.data.password;
delete result.data.walletToken;
delete result.data.createDate;
delete result.data.updateDate;
assert.deepEqual(result.data, {
role: 'STANDARD_REGISTRY',
username: 'StandardRegistry',
Expand All @@ -141,6 +143,8 @@ function Accounts() {
delete result.data.id;
delete result.data.password;
delete result.data.walletToken;
delete result.data.createDate;
delete result.data.updateDate;
assert.deepEqual(result.data, { username: 'Installer', role: 'USER' });
});

Expand All @@ -161,6 +165,8 @@ function Accounts() {
delete result.data._id;
delete result.data.parent;
delete result.data.walletToken
delete result.data.createDate;
delete result.data.updateDate;
assert.deepEqual(result.data, {
username: 'apiTest',
did: null,
Expand Down
4 changes: 2 additions & 2 deletions auth-service/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { fixtures } from '@helpers/fixtures';
import { AccountService } from '@api/account-service';
import { WalletService } from '@api/wallet-service';
import { ApplicationState, MessageBrokerChannel, Logger, DB_DI, Migration, COMMON_CONNECTION_CONFIG } from '@guardian/common';
import { ApplicationState, MessageBrokerChannel, Logger, DataBaseHelper, Migration, COMMON_CONNECTION_CONFIG } from '@guardian/common';
import { ApplicationStates } from '@guardian/interfaces';
import { MikroORM } from '@mikro-orm/core';
import { MongoDriver } from '@mikro-orm/mongodb';
Expand All @@ -26,7 +26,7 @@ Promise.all([
MessageBrokerChannel.connect('AUTH_SERVICE'),
InitializeVault(process.env.VAULT_PROVIDER)
]).then(async ([_, db, cn, vault]) => {
DB_DI.orm = db;
DataBaseHelper.orm = db;
const state = new ApplicationState();
await state.setServiceName('AUTH_SERVICE').setConnection(cn).init();
state.updateState(ApplicationStates.INITIALIZING);
Expand Down
22 changes: 21 additions & 1 deletion common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,29 @@
"author": "Envision Blockchain Solutions <info@envisionblockchain.com>",
"dependencies": {
"@guardian/interfaces": "^2.11.0",
"@mattrglobal/jsonld-signatures-bbs": "^1.1.2",
"@mikro-orm/core": "~5.3.0",
"@mikro-orm/migrations-mongodb": "~5.3.0",
"@mikro-orm/mongodb": "~5.3.0",
"@transmute/jsonld-schema": "^0.7.0-unstable.80",
"@transmute/credentials-context": "^0.7.0-unstable.80",
"@transmute/did-context": "^0.7.0-unstable.80",
"@transmute/ed25519-signature-2018": "^0.7.0-unstable.80",
"@transmute/json-web-signature": "^0.7.0-unstable.80",
"@transmute/security-context": "^0.7.0-unstable.80",
"@transmute/vc.js": "^0.7.0-unstable.80",
"@hashgraph/sdk": "^2.22.0",
"ajv": "^8.10.0",
"ajv-formats": "^2.1.1",
"axios": "^0.25.0",
"moment": "^2.29.2",
"bs58": "^4.0.1",
"js-base64": "^3.6.1",
"@meeco/cryppo": "^2.0.2",
"express": "^4.17.1",
"lodash.get": "^4.4.2",
"lodash.set": "^4.3.2",
"mongodb": "4.8.1",
"nats": "^2.6.1",
"reflect-metadata": "^0.1.13",
"winston": "^3.8.1",
Expand Down Expand Up @@ -34,7 +52,9 @@
"dev": "tsc -w",
"lint": "tslint --config ../tslint.json --project .",
"prepack": "npm run build:prod",
"test": "echo \"Error: no test specified\" && exit 1"
"test": "mocha tests/**/*.test.js --reporter mocha-junit-reporter --reporter-options mochaFile=../test_results/common.xml --exit",
"test:local": "mocha tests/**/*.test.js --exit",
"test:stability": "mocha tests/stability.test.js"
},
"version": "2.11.0"
}
Original file line number Diff line number Diff line change
@@ -1,30 +1,38 @@
import { BlockState } from '@entity/block-state';
import { VcDocument as VcDocumentCollection } from '@entity/vc-document';
import { VpDocument as VpDocumentCollection } from '@entity/vp-document';
import { DidDocument as DidDocumentCollection } from '@entity/did-document';
import { Schema as SchemaCollection } from '@entity/schema';
import { DocumentState } from '@entity/document-state';
import { Policy } from '@entity/policy';
import { AggregateVC } from '@entity/aggregate-documents';
import { ApprovalDocument as ApprovalDocumentCollection } from '@entity/approval-document';
import { Token as TokenCollection } from '@entity/token';
import { Topic as TopicCollection } from '@entity/topic';
import { Contract as ContractCollection } from '@entity/contract';
import { DryRun } from '@entity/dry-run';
import { PolicyRoles as PolicyRolesCollection } from '@entity/policy-roles';
import { GenerateUUIDv4, IVC, SchemaEntity, TopicType } from '@guardian/interfaces';
import { BaseEntity, DataBaseHelper } from '@guardian/common';
import { PolicyInvitations } from '@entity/policy-invitations';
import { MultiDocuments } from '@entity/multi-documents';
import { Artifact as ArtifactCollection } from '@entity/artifact';
import { ArtifactChunk as ArtifactChunkCollection } from '@entity/artifact-chunk';
import {
BlockState,
VcDocument as VcDocumentCollection,
VpDocument as VpDocumentCollection,
DidDocument as DidDocumentCollection,
Schema as SchemaCollection,
DocumentState,
Policy,
AggregateVC,
ApprovalDocument as ApprovalDocumentCollection,
Token as TokenCollection,
Topic as TopicCollection,
DryRun,
PolicyRoles as PolicyRolesCollection,
PolicyInvitations,
MultiDocuments,
Artifact as ArtifactCollection,
ArtifactChunk as ArtifactChunkCollection,
SplitDocuments,
MultiPolicy,
MultiPolicyTransaction,
PolicyModule,
Tag,
TagCache,
Contract as ContractCollection
} from '../entity';
import { Binary } from 'bson';
import { SplitDocuments } from '@entity/split-documents';
import { MultiPolicy } from '@entity/multi-policy';
import { MultiPolicyTransaction } from '@entity/multi-policy-transaction';
import { PolicyModule } from '@entity/module';
import { Tag } from '@entity/tag';
import { TagCache } from '@entity/tag-cache';
import {
GenerateUUIDv4,
IVC,
SchemaEntity,
TopicType,
} from '@guardian/interfaces';
import { BaseEntity } from '../models';
import { DataBaseHelper } from '../helpers';

/**
* Database server
Expand Down Expand Up @@ -66,6 +74,8 @@ export class DatabaseServer {
this.classMap.set(PolicyInvitations, 'PolicyInvitations');
this.classMap.set(MultiDocuments, 'MultiDocuments');
this.classMap.set(SplitDocuments, 'SplitDocuments');
this.classMap.set(Tag, 'Tag');
this.classMap.set(TagCache, 'TagCache');
}

/**
Expand Down Expand Up @@ -231,11 +241,11 @@ export class DatabaseServer {
* @param criteria
* @param row
*/
private async update<T extends BaseEntity>(entityClass: new () => T, criteria: any, row: T): Promise<void> {
private async update<T extends BaseEntity>(entityClass: new () => T, criteria: any, row: T): Promise<T> {
if (this.dryRun) {
await new DataBaseHelper(DryRun).update(row, criteria);
return await new DataBaseHelper(DryRun).update(row, criteria) as any;
} else {
await new DataBaseHelper(entityClass).update(row, criteria);
return await new DataBaseHelper(entityClass).update(row, criteria);
}
}

Expand Down Expand Up @@ -900,6 +910,14 @@ export class DatabaseServer {
return await this.find(TopicCollection, filters);
}

/**
* Get topic by id
* @param topicId
*/
public async getTopicById(topicId: string): Promise<TopicCollection> {
return await this.findOne(TopicCollection, { topicId });
}

/**
* Get Token
* @param tokenId
Expand Down Expand Up @@ -1326,6 +1344,73 @@ export class DatabaseServer {
});
}

/**
* Create tag
* @param tag
*/
public async createTag(tag: any): Promise<Tag> {
const item = this.create(Tag, tag);
return await this.save(Tag, item);
}

/**
* Get tags
* @param filters
* @param options
*/
public async getTags(filters?: any, options?: any): Promise<Tag[]> {
return await this.find(Tag, filters, options);
}

/**
* Get tags
* @param filters
* @param options
*/
public async getTagCache(filters?: any, options?: any): Promise<TagCache[]> {
return await this.find(TagCache, filters, options);
}

/**
* Delete tag
* @param tag
*/
public async removeTag(tag: Tag): Promise<void> {
return await this.remove(Tag, tag);
}

/**
* Update tags
* @param row
*/
public async updateTag(row: Tag): Promise<Tag> {
return await this.update(Tag, row.id, row);
}

/**
* Get tag By UUID
* @param uuid
*/
public async getTagById(uuid: string): Promise<Tag> {
return await this.findOne(Tag, { uuid });
}

/**
* Create tag cache
* @param tag
*/
public async createTagCache(tag: any): Promise<TagCache> {
const item = this.create(TagCache, tag);
return await this.save(TagCache, item);
}

/**
* Update tag cache
* @param row
*/
public async updateTagCache(row: TagCache): Promise<TagCache> {
return await this.update(TagCache, row.id, row);
}
//Static

/**
Expand Down Expand Up @@ -1625,7 +1710,7 @@ export class DatabaseServer {
* @param row
*/
public static async updateTopic(row: TopicCollection): Promise<void> {
await new DataBaseHelper(TopicCollection).update(row, { id: row.id });
await new DataBaseHelper(TopicCollection).update(row);
}

/**
Expand Down Expand Up @@ -2071,10 +2156,10 @@ export class DatabaseServer {

/**
* Update MultiPolicyTransaction
* @param row
* @param item
*/
public static async updateMultiPolicyTransactions(row: MultiPolicyTransaction): Promise<void> {
await new DataBaseHelper(MultiPolicyTransaction).update(row);
public static async updateMultiPolicyTransactions(item: MultiPolicyTransaction): Promise<void> {
await new DataBaseHelper(MultiPolicyTransaction).update(item);
}

/**
Expand Down Expand Up @@ -2219,4 +2304,4 @@ export class DatabaseServer {
public static async updateTagCache(row: TagCache): Promise<TagCache> {
return await new DataBaseHelper(TagCache).update(row);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Schema } from '@entity/schema';
import { DataBaseHelper } from '@guardian/common';
import { DataBaseHelper } from '../helpers';
import { ISchema } from '@guardian/interfaces';
import { DocumentLoader, IDocumentFormat } from '@hedera-modules';
import { Schema } from '../entity';
import { DocumentLoader, IDocumentFormat } from '../hedera-modules';

/**
* Schema Documents Loader.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DidDocument } from '@entity/did-document';
import { DataBaseHelper } from '@guardian/common';
import { DidRootKey, DocumentLoader, IDocumentFormat } from '@hedera-modules';
import { DataBaseHelper } from '../helpers';
import { DidDocument } from '../entity';
import { DidRootKey, DocumentLoader, IDocumentFormat } from '../hedera-modules';

/**
* DID Documents Loader
Expand Down
5 changes: 5 additions & 0 deletions common/src/document-loader/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from './context-loader';
export * from './did-document-loader';
export * from './schema-document-loader';
export * from './subject-schema-loader';
export * from './vc-schema-loader';
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Schema } from '@entity/schema';
import { DataBaseHelper } from '@guardian/common';
import { DocumentLoader, IDocumentFormat } from '@hedera-modules';
import { Schema } from '../entity';
import { DocumentLoader, IDocumentFormat } from '../hedera-modules';
import { DataBaseHelper } from '../helpers';

/**
* Schema Documents Loader
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Schema } from '@entity/schema';
import { DataBaseHelper } from '@guardian/common';
import { ISchema } from '@guardian/interfaces';
import { SchemaLoader } from '@hedera-modules';
import { Schema } from '../entity';
import { SchemaLoader } from '../hedera-modules';
import { DataBaseHelper } from '../helpers';

/**
* Subject schema loader
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Schema } from '@entity/schema';
import { DataBaseHelper } from '@guardian/common';
import { ISchema } from '@guardian/interfaces';
import { SchemaLoader } from '@hedera-modules';
import { Schema } from '../entity';
import { SchemaLoader } from '../hedera-modules';
import { DataBaseHelper } from '../helpers';

/**
* VC schema loader
Expand Down
Loading