Skip to content

Commit

Permalink
update packages fix bugs
Browse files Browse the repository at this point in the history
Signed-off-by: simvalery <valeriy.simonov@envisionblockchain.com>
  • Loading branch information
simvalery committed Jan 31, 2025
1 parent 9597509 commit c05251f
Show file tree
Hide file tree
Showing 31 changed files with 242 additions and 69 deletions.
2 changes: 1 addition & 1 deletion ai-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"@nestjs/common": "^9.4.1",
"@nestjs/core": "^9.4.1",
"@types/express": "^4.17.18",
"@types/node": "^20.8.0",
"@types/node": "^22.10.10",
"dotenv": "^16.3.1",
"module-alias": "^2.2.2",
"express": "^4.18.2",
Expand Down
2 changes: 1 addition & 1 deletion analytics-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"@types/gulp": "^4",
"@types/gulp-rename": "^2",
"@types/jszip": "^3.4.1",
"@types/node": "^18.16.0",
"@types/node": "^22.10.10",
"@types/ws": "^8.2.2",
"chai": "^4.3.4",
"cross-env": "^7.0.3",
Expand Down
4 changes: 2 additions & 2 deletions api-gateway/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "Envision Blockchain Solutions <info@envisionblockchain.com>",
"dependencies": {
"@fastify/formbody": "^7.4.0",
"@fastify/multipart": "^8.2.0",
"@fastify/multipart": "^8.3.1",
"@fastify/static": "^7.0.0",
"@guardian/common": "^3.0.0",
"@guardian/interfaces": "^3.0.0",
Expand Down Expand Up @@ -46,7 +46,7 @@
"@types/gulp": "^4",
"@types/gulp-rename": "^2",
"@types/jszip": "^3.4.1",
"@types/node": "^18.16.0",
"@types/node": "^22.10.10",
"@types/ws": "^8.2.2",
"chai": "^4.3.4",
"cross-env": "^7.0.3",
Expand Down
65 changes: 59 additions & 6 deletions api-gateway/src/api/service/policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2826,8 +2826,8 @@ export class PolicyApi {
// UserRole.STANDARD_REGISTRY,
)
@ApiOperation({
summary: 'Create dru-run savepoint.',
description: 'Create dru-run savepoint.' + ONLY_SR
summary: 'Create dry-run savepoint.',
description: 'Create dry-run savepoint.' + ONLY_SR
})
@ApiParam({
name: 'policyId',
Expand Down Expand Up @@ -2882,8 +2882,8 @@ export class PolicyApi {
// UserRole.STANDARD_REGISTRY,
)
@ApiOperation({
summary: 'Delete dru-run savepoint.',
description: 'Delete dru-run savepoint.' + ONLY_SR
summary: 'Delete dry-run savepoint.',
description: 'Delete dry-run savepoint.' + ONLY_SR
})
@ApiParam({
name: 'policyId',
Expand Down Expand Up @@ -2929,6 +2929,59 @@ export class PolicyApi {
}
}

/**
* Get savepoint state.
*/
@Get('/:policyId/savepoint/restore')
@Auth(
Permissions.POLICIES_POLICY_UPDATE
// UserRole.STANDARD_REGISTRY,
)
@ApiOperation({
summary: 'Get savepoint state.',
description: 'Get savepoint state.' + ONLY_SR
})
@ApiParam({
name: 'policyId',
type: String,
description: 'Policy Id',
required: true,
example: Examples.DB_ID
})
@ApiBody({
description: '.'
})
@ApiOkResponse({
description: '.'
})
@ApiInternalServerErrorResponse({
description: 'Internal server error.',
type: InternalServerErrorDTO
})
@ApiExtraModels(InternalServerErrorDTO)
@HttpCode(HttpStatus.OK)
async getSavepointState(
@AuthUser() user: IAuthUser,
@Param('policyId') policyId: string,
@Req() req
) {
const engineService = new PolicyEngine();
const owner = new EntityOwner(user);
const policy = await engineService.accessPolicy(policyId, owner, 'read');
if (!PolicyHelper.isDryRunMode(policy)) {
throw new HttpException('Invalid status.', HttpStatus.FORBIDDEN);
}

const invalidedCacheTags = [`${PREFIXES.POLICIES}${policyId}/navigation`, `${PREFIXES.POLICIES}${policyId}/groups`];
await this.cacheService.invalidate(getCacheKey([req.url, ...invalidedCacheTags], user));

try {
return await engineService.getSavepointState(owner, policyId);
} catch (error) {
await InternalException(error, this.logger);
}
}

/**
* Clear dry-run state.
*/
Expand All @@ -2938,8 +2991,8 @@ export class PolicyApi {
// UserRole.STANDARD_REGISTRY,
)
@ApiOperation({
summary: 'Restore dru-run savepoint.',
description: 'Restore dru-run savepoint.' + ONLY_SR
summary: 'Restore dry-run savepoint.',
description: 'Restore dry-run savepoint.' + ONLY_SR
})
@ApiParam({
name: 'policyId',
Expand Down
12 changes: 12 additions & 0 deletions api-gateway/src/helpers/policy-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,18 @@ export class PolicyEngine extends NatsService {
return await this.sendMessage(PolicyEngineEvents.RESTORE_SAVEPOINT, {model, owner, policyId});
}

/**
* Get savepoint state
* @param owner
* @param policyId
*/
public async getSavepointState(
owner: IOwner,
policyId: string
) {
return await this.sendMessage(PolicyEngineEvents.GET_SAVEPOINT, {owner, policyId});
}

/**
* Get Virtual Documents
* @param policyId
Expand Down
2 changes: 1 addition & 1 deletion application-events/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"@types/http-errors": "^2.0.1",
"@types/js-yaml": "^4.0.5",
"@types/mocha": "^10.0.1",
"@types/node": "^18.11.9",
"@types/node": "^22.10.10",
"@types/swagger-ui-express": "^4.1.3",
"chai": "^4.3.7",
"chai-http": "^4.3.0",
Expand Down
2 changes: 1 addition & 1 deletion auth-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"@types/gulp": "^4",
"@types/gulp-rename": "^2",
"@types/jsonwebtoken": "^8.5.4",
"@types/node": "^18.16.0",
"@types/node": "^22.10.10",
"@types/node-vault": "^0",
"chai": "^4.3.4",
"cross-env": "^7.0.3",
Expand Down
4 changes: 2 additions & 2 deletions common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@nestjs/common": "^9.4.1",
"@nestjs/core": "^9.4.1",
"@nestjs/microservices": "^9.4.1",
"jsonld-signatures": "7.0.0",
"jsonld-signatures": "11.5.0",
"@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",
Expand Down Expand Up @@ -60,7 +60,7 @@
"@types/gulp": "^4",
"@types/gulp-rename": "^2",
"@types/jszip": "^3.4.1",
"@types/node": "^18.16.0",
"@types/node": "^22.10.10",
"mocha-junit-reporter": "^2.0.2",
"tslint": "^6.1.3",
"typescript": "^4.5.5",
Expand Down
12 changes: 12 additions & 0 deletions common/src/database-modules/database-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,18 @@ export class DatabaseServer extends AbstractDatabaseServer {
// await new DataBaseHelper(DryRunFiles).remove(files);
}

/**
* Get savepoint state
* @param dryRunId
* @param systemMode
*/
public static async getSavepointSate(dryRunId: string): Promise<DryRun> {
return await new DataBaseHelper(DryRun).findOne({dryRunId, savepoint: true});

// const files = await new DataBaseHelper(DryRunFiles).find({ policyId: dryRunId });
// await new DataBaseHelper(DryRunFiles).remove(files);
}

/**
* Get schemas
* @param filters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<!-- <span>Delete Savepoint</span>-->
<!-- </div>-->

<div (click)="restoreSavepoint()" class="dry-run-action-btn">
<div (click)="restoreSavepoint()" [attr.disabled]="!savePointState" class="dry-run-action-btn">
<i class="pi pi-undo"></i>
<span>Restore</span>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { IStep } from '../../structures';
})
export class PolicyViewerComponent implements OnInit, OnDestroy {
private subscription = new Subscription();
public savePointState: boolean = false;
public policyId!: string;
public policy: any | null;
public policyInfo: any | null;
Expand Down Expand Up @@ -107,6 +108,15 @@ export class PolicyViewerComponent implements OnInit, OnDestroy {
return document;
}

private getSavepointState() {
this.policyEngineService.getSavepointState(this.policyInfo.id).subscribe((value) => {
this.savePointState = value.state;
console.log(value);
}, (e) => {
this.savePointState = false;
});
}

ngOnInit() {
this.loading = true;
this.subscription.add(
Expand Down Expand Up @@ -207,6 +217,7 @@ export class PolicyViewerComponent implements OnInit, OnDestroy {
}
})
})
this.getSavepointState();
}, (e) => {
this.loading = false;
});
Expand Down Expand Up @@ -289,7 +300,8 @@ export class PolicyViewerComponent implements OnInit, OnDestroy {
public createSavepoint() {
this.loading = true;
this.policyEngineService.createSavepoint(this.policyInfo.id).subscribe(() => {
this.loadPolicyById(this.policyId);
this.loadPolicyById(this.policyId);
this.getSavepointState();
}, (e) => {
this.loading = false;
}
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/app/services/policy-engine.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ export class PolicyEngineService {
return this.http.post<any>(`${this.url}/${policyId}/savepoint/restore`, null);
}

public getSavepointState(policyId: string): Observable<any> {
return this.http.get<any>(`${this.url}/${policyId}/savepoint/restore`);
}

public loadDocuments(
policyId: string,
documentType: string,
Expand Down
4 changes: 2 additions & 2 deletions guardian-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
"author": "IntellectEU <info@intellecteu.com>",
"license": "Apache-2.0",
"devDependencies": {
"@types/node": "^18.15.3",
"@types/node": "^22.10.10",
"typescript": "^5.0.2"
},
"dependencies": {
"@hashgraph/sdk": "^2.46.0",
"@hashgraph/sdk": "^2.52.0",
"axios": "^1.6.7",
"commander": "^10.0.0",
"solc": "0.8.11",
Expand Down
2 changes: 1 addition & 1 deletion guardian-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"@types/gulp": "^4",
"@types/gulp-rename": "^2",
"@types/jszip": "^3.4.1",
"@types/node": "^18.16.0",
"@types/node": "^22.10.10",
"chai": "4.3.4",
"gulp": "^4.0.2",
"gulp-copy": "^4.0.1",
Expand Down
26 changes: 26 additions & 0 deletions guardian-service/src/policy-engine/policy-engine.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1723,6 +1723,32 @@ export class PolicyEngineService {
}
});

this.channel.getMessages<any, any>(PolicyEngineEvents.GET_SAVEPOINT,
async (msg: {policyId: string, owner: IOwner}) => {
try {
const {policyId, owner} = msg;
const policy = await DatabaseServer.getPolicyById(policyId);
await this.policyEngine.accessPolicy(policy, owner, 'read');
if (!policy.config) {
throw new Error('The policy is empty');
}
if (!PolicyHelper.isDryRunMode(policy)) {
throw new Error(`Policy is not in Dry Run`);
}

const state = await DatabaseServer.getSavepointSate(policyId);
// const users = await DatabaseServer.getVirtualUsers(policyId);
// await DatabaseServer.setVirtualUser(policyId, users[0]?.did);
// const filters = await this.policyEngine.addAccessFilters({}, owner);
// const policies = (await DatabaseServer.getListOfPolicies(filters));
console.log('Restore savepoint');
return new MessageResponse({state});
} catch (error) {
await logger.error(error, ['GUARDIAN_SERVICE']);
return new MessageError(error);
}
});

this.channel.getMessages<any, any>(PolicyEngineEvents.GET_VIRTUAL_DOCUMENTS,
async (msg: {
policyId: string,
Expand Down
1 change: 0 additions & 1 deletion guardian-service/src/policy-engine/policy-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,6 @@ export class PolicyEngine extends NatsService {
root.did,
root.hederaAccountId,
root.hederaAccountKey,
true,
true
);

Expand Down
2 changes: 1 addition & 1 deletion indexer-api-gateway/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"@types/gulp": "^4",
"@types/gulp-rename": "^2",
"@types/jszip": "^3.4.1",
"@types/node": "^18.16.0",
"@types/node": "^22.10.10",
"@types/ws": "^8.2.2",
"chai": "^4.3.4",
"cross-env": "^7.0.3",
Expand Down
2 changes: 1 addition & 1 deletion indexer-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@types/gulp": "^4",
"@types/gulp-rename": "^2",
"@types/jszip": "^3.4.1",
"@types/node": "^18.16.0",
"@types/node": "^22.10.10",
"mocha-junit-reporter": "^2.0.2",
"tslint": "^6.1.3",
"typescript": "^4.5.5"
Expand Down
2 changes: 1 addition & 1 deletion indexer-interfaces/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"dependencies": {},
"description": "Indexer interfaces",
"devDependencies": {
"@types/node": "^18.16.0",
"@types/node": "^22.10.10",
"tslint": "^6.1.3",
"typescript": "^4.5.5"
},
Expand Down
2 changes: 1 addition & 1 deletion indexer-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"devDependencies": {
"@types/gulp": "^4",
"@types/gulp-rename": "^2",
"@types/node": "^18.16.0",
"@types/node": "^22.10.10",
"chai": "4.3.4",
"gulp": "^4.0.2",
"gulp-copy": "^4.0.1",
Expand Down
2 changes: 1 addition & 1 deletion indexer-worker-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"devDependencies": {
"@types/gulp": "^4",
"@types/gulp-rename": "^2",
"@types/node": "^18.16.0",
"@types/node": "^22.10.10",
"chai": "4.3.4",
"gulp": "^4.0.2",
"gulp-copy": "^4.0.1",
Expand Down
2 changes: 1 addition & 1 deletion interfaces/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"devDependencies": {
"@types/gulp": "^4",
"@types/gulp-rename": "^2",
"@types/node": "^18.16.0",
"@types/node": "^22.10.10",
"mocha-junit-reporter": "^2.0.2",
"tslint": "^6.1.3",
"typescript": "^4.5.5"
Expand Down
1 change: 1 addition & 0 deletions interfaces/src/type/messages/policy-engine-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,5 @@ export enum PolicyEngineEvents {
CREATE_SAVEPOINT = 'policy-engine-event-create-savepoint',
DELETE_SAVEPOINT = 'policy-engine-event-delete-savepoint',
RESTORE_SAVEPOINT = 'policy-engine-event-restore-savepoint',
GET_SAVEPOINT = 'policy-engine-event-get-savepoint'
}
2 changes: 1 addition & 1 deletion interfaces/src/type/messages/workers.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export enum WorkerTaskType {
GET_CONTRACT_EVENTS = 'get-contract-events',
GET_TRANSACTIONS = 'get-transaction',
ANALYTICS_SEARCH_POLICIES = 'analytics-search-policies',
ANALYTICS_GET_INDEXER_AVAILABILITY = "analytics-get-indexer-availability",
ANALYTICS_GET_INDEXER_AVAILABILITY = 'analytics-get-indexer-availability',
ANALYTICS_GET_RETIRE_DOCUMENTS = 'analytics-get-retire-documents'
}

Expand Down
Loading

0 comments on commit c05251f

Please sign in to comment.