Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
0d1d5b7
update
Dec 1, 2025
0451f40
Merge branch 'develop' into feat/4535
Dec 3, 2025
3415a2b
update
Dec 8, 2025
28634b8
update
Dec 12, 2025
5d06258
update
Dec 15, 2025
d976682
Merge branch 'develop' into feat/4535
Dec 16, 2025
eb68828
update
Dec 23, 2025
5b5428b
update
Dec 26, 2025
88cfd66
update
Dec 29, 2025
0eb51b2
update
Dec 30, 2025
a63ac6b
Merge branch 'develop' into feat/4535
Dec 30, 2025
4142f29
update
Jan 7, 2026
eff88f3
update
Jan 8, 2026
7c4de23
update
Jan 9, 2026
f4c1ffd
update
Jan 9, 2026
55964f7
fix
Jan 9, 2026
85c2c66
fix revoke
Jan 12, 2026
8b29780
update
Jan 12, 2026
5d1bdd5
update
Jan 13, 2026
8619648
fix
Jan 13, 2026
41d3ab7
update
Jan 14, 2026
38f3c7c
fix
Jan 15, 2026
d04b3f8
fix
Jan 15, 2026
2e14711
fix
Jan 15, 2026
01dbe17
update
Jan 19, 2026
ff06188
fix
Jan 19, 2026
1ce384d
fix
Jan 19, 2026
c3bd508
fix
Jan 20, 2026
7074028
fix scroll
Jan 20, 2026
eb444c2
fix color
Jan 20, 2026
91d75e7
fix color
Jan 20, 2026
400976f
fix
Jan 20, 2026
4f2ec55
fix color
Jan 20, 2026
60a7d23
Merge branch 'develop' into feat/4535
Jan 21, 2026
dab5692
fix
Jan 21, 2026
03785db
fix
Jan 21, 2026
6906f74
update
Jan 21, 2026
dc9b921
fix build
Jan 21, 2026
1d9716e
fix
Jan 22, 2026
c3900c9
Merge branch 'develop' into feat/4535
Jan 23, 2026
00dd174
update
Jan 26, 2026
aa2fdc7
fix
Jan 26, 2026
d81244e
update
Jan 26, 2026
bbc7073
update
Jan 27, 2026
8851d53
Merge branch 'develop' into feat/4535
Jan 27, 2026
7188527
update
Jan 28, 2026
588fb2e
Merge branch 'develop' into feat/4535
Jan 28, 2026
dcd853a
fix
Jan 28, 2026
36afc2c
update
Jan 28, 2026
33fc86b
update
Jan 28, 2026
e444130
fix
Jan 28, 2026
c0cc5b3
fix
Jan 28, 2026
6233250
fix
Jan 28, 2026
77d7077
Merge branch 'develop' into feat/4535
Jan 28, 2026
85242e7
update
Jan 29, 2026
d9362b6
Merge branch 'develop' into feat/4535
Jan 29, 2026
489db61
fix
Jan 29, 2026
b2db57a
[skip ci] Add swagger.yaml
envision-ci-agent Jan 29, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions common/src/entity/formula.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {AfterDelete, BeforeCreate, Entity, Property} from '@mikro-orm/core';
import { AfterDelete, BeforeCreate, Entity, Property } from '@mikro-orm/core';
import { BaseEntity } from '../models/index.js';
import { EntityStatus, GenerateUUIDv4, IFormula, IFormulaConfig } from '@guardian/interfaces';
import {ObjectId} from '@mikro-orm/mongodb';
import {DataBaseHelper} from '../helpers/index.js';
import { ObjectId } from '@mikro-orm/mongodb';
import { DataBaseHelper } from '../helpers/index.js';

/**
* Formula collection
Expand Down Expand Up @@ -93,6 +93,12 @@ export class Formula extends BaseEntity implements IFormula {
@Property({ nullable: true })
contentFileId?: ObjectId;

/**
* Auto Generated
*/
@Property({ nullable: true })
autoGenerated?: boolean;

/**
* Set defaults
*/
Expand Down
9 changes: 9 additions & 0 deletions common/src/hedera-modules/message/formula-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export class FormulaMessage extends Message {
* Policy Instance topic id
*/
public policyInstanceTopicId: string;
/**
* Auto Generated
*/
public autoGenerated: boolean;

/**
* Document
Expand All @@ -55,6 +59,7 @@ export class FormulaMessage extends Message {
this.uuid = item.uuid;
this.policyTopicId = item.policyTopicId;
this.policyInstanceTopicId = item.policyInstanceTopicId;
this.autoGenerated = !!item.autoGenerated;
this.config = toBuffer(zip);
}

Expand Down Expand Up @@ -82,6 +87,7 @@ export class FormulaMessage extends Message {
uuid: this.uuid,
policyTopicId: this.policyTopicId,
policyInstanceTopicId: this.policyInstanceTopicId,
autoGenerated: this.autoGenerated,
cid: this.getDocumentUrl(UrlType.cid),
uri: this.getDocumentUrl(UrlType.url),
};
Expand Down Expand Up @@ -140,6 +146,7 @@ export class FormulaMessage extends Message {
message.uuid = json.uuid;
message.policyTopicId = json.policyTopicId;
message.policyInstanceTopicId = json.policyInstanceTopicId;
message.autoGenerated = json.autoGenerated;
const urls = [
{
cid: json.cid,
Expand Down Expand Up @@ -191,6 +198,7 @@ export class FormulaMessage extends Message {
result.uuid = this.uuid;
result.policyTopicId = this.policyTopicId;
result.policyInstanceTopicId = this.policyInstanceTopicId;
result.autoGenerated = this.autoGenerated;
result.config = this.config;
}

Expand All @@ -206,6 +214,7 @@ export class FormulaMessage extends Message {
result.uuid = json.uuid;
result.policyTopicId = json.policyTopicId;
result.policyInstanceTopicId = json.policyInstanceTopicId;
result.autoGenerated = json.autoGenerated;
result.config = json.config;
return result;
}
Expand Down
8 changes: 8 additions & 0 deletions common/src/hedera-modules/message/message-body.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ export interface MessageBody {
* Revoke message
*/
revokeMessage?: string;
/**
* Revoke owner
*/
revokeOwner?: string;
/**
* Message reason
*/
Expand Down Expand Up @@ -762,6 +766,10 @@ export interface FormulaMessageBody extends MessageBody {
* Policy instance topic ID
*/
policyInstanceTopicId: string;
/**
* Auto Generated
*/
autoGenerated: boolean;
/**
* CID
*/
Expand Down
13 changes: 12 additions & 1 deletion common/src/hedera-modules/message/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ export abstract class Message {
* @protected
*/
protected _statusReason: string;
/**
* Revoke owner
* @protected
*/
protected _statusOwner: string;
/**
* Message action
*/
Expand Down Expand Up @@ -257,12 +262,17 @@ export abstract class Message {
* @param message
* @param parentIds
*/
public revoke(message: string, parentIds?: string[]): void {
public revoke(
message: string,
owner: string,
parentIds?: string[]
): void {
this._status = MessageStatus.REVOKE;
this._statusMessage = message;
this._statusReason = parentIds
? RevokeReason.ParentRevoked
: RevokeReason.DocumentRevoked;
this._statusOwner = owner
this._parentIds = parentIds;
this._action = MessageAction.RevokeDocument;
}
Expand Down Expand Up @@ -312,6 +322,7 @@ export abstract class Message {
lang: this.lang,
account: this.account,
revokeMessage: this._statusMessage,
revokeOwner: this._statusOwner,
reason: this._statusReason,
parentIds: this._parentIds
}
Expand Down
3 changes: 3 additions & 0 deletions common/src/hedera-modules/topic-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ export class TopicHelper {
rationale: string,
userId?: string
) {
if (!topic) {
throw new Error('Invalid topic');
}
const messageServer = new MessageServer({
operatorId: this.hederaAccountId,
operatorKey: this.hederaAccountKey,
Expand Down
28 changes: 28 additions & 0 deletions common/src/hedera-modules/vcjs/context-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ export class ContextHelper {
}

private static _clearContext(item: any, contexts: Set<string>) {
if (item === undefined || item === null) {
return;
}
if (typeof item === 'object') {
if (Array.isArray(item)) {
for (const i of item) {
Expand Down Expand Up @@ -105,6 +108,9 @@ export class ContextHelper {
}

private static _getItems(root: any, key: string, items: any[]) {
if (root === null || root === undefined) {
return items;
}
if (Array.isArray(root)) {
for (const item of root) {
ContextHelper._getItems(item, key, items);
Expand All @@ -121,4 +127,26 @@ export class ContextHelper {
return items;
}
}

public static clearEmptyProperties(vc: any): any {
if (vc === null || vc === undefined) {
return vc;
}
if (Array.isArray(vc)) {
for (const prop of vc) {
ContextHelper.clearEmptyProperties(prop);
}
} else if (typeof vc === 'object') {
for (const key of Object.keys(vc)) {
if (vc[key] === null || vc[key] === undefined) {
delete vc[key];
} else {
ContextHelper.clearEmptyProperties(vc[key]);
}
}
return vc;
} else {
return vc;
}
}
}
19 changes: 19 additions & 0 deletions common/src/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,3 +393,22 @@ export function stripPrefix(text: string, prefixes: string | string[]): string {
}
return text
}

export function findBlocks(tree: any, filter: (block: any) => boolean): any[] {
const result: any[] = [];
_findBlocks(tree, filter, result);
return result;
}

function _findBlocks(node: any, filter: (block: any) => boolean, result: any[]): void {
if (node) {
if (filter(node)) {
result.push(node);
}
if (Array.isArray(node.children)) {
for (const child of node.children) {
_findBlocks(child, filter, result);
}
}
}
}
112 changes: 111 additions & 1 deletion common/src/import-export/formula.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import JSZip from 'jszip';
import { Formula, Policy } from '../entity/index.js';
import { IFormulaConfig } from '@guardian/interfaces';
import { EntityStatus, GenerateUUIDv4, IFormulaConfig } from '@guardian/interfaces';
import { DatabaseServer } from '../database-modules/index.js';
import { ImportExportUtils } from './utils.js';
import { findBlocks } from '../helpers/utils.js';

interface ISchemaComponents {
iri: string;
Expand Down Expand Up @@ -199,4 +200,113 @@ export class FormulaImportExport {
}
return components;
}

public static generateByPolicy(policy: Policy): Formula | null {
const blocks = findBlocks(policy.config, (b) => b.blockType === 'mathBlock');
const formulas: any[] = [];
for (const block of blocks) {
FormulaImportExport.generateFormulaByBlock(block, formulas);
}
if (formulas.length) {
return {
uuid: GenerateUUIDv4(),
name: policy.name,
description: policy.description,
owner: policy.owner,
policyId: policy.id,
policyInstanceTopicId: policy.instanceTopicId,
policyTopicId: policy.topicId,
status: EntityStatus.DRAFT,
autoGenerated: true,
config: {
files: [],
formulas
}
} as any
} else {
return null;
}
}

private static generateFormulaByBlock(block: any, result: any[]) {
try {
const inputSchema = block.inputSchema;
const outputSchema = block.outputSchema || inputSchema;
const expression = block.expression;
const items: any[] = [];
// Variables
if (Array.isArray(expression?.variables)) {
for (const item of expression.variables) {
items.push({
uuid: GenerateUUIDv4(),
name: item.name,
description: item.description,
type: 'variable',
value: '',
link: {
entityId: inputSchema,
item: item.field,
type: 'schema'
}
})
}
}
// Formulas
if (Array.isArray(expression?.formulas)) {
for (const item of expression.formulas) {
items.push({
uuid: GenerateUUIDv4(),
name: item.name,
description: item.description,
type: 'formula',
value: item.body,
relationships: item.relationships
})
}
}
// Relationships
for (const item of items) {
const relationships: string[] = [];
if (Array.isArray(item.relationships)) {
for (const name of item.relationships) {
const link = items.find((e) => e.name === name);
if (link) {
relationships.push(link.uuid);
}
}
}
item.relationships = relationships;
}
// Outputs
if (Array.isArray(expression?.outputs)) {
for (const item of expression.outputs) {
let link = items.find((e) => e.name === item.name);
if (link.type === 'variable') {
const newTarget = {
uuid: GenerateUUIDv4(),
name: item.name,
description: block.tag,
type: 'formula',
value: item.name,
relationships: [link.uuid]
}
items.push(newTarget);
link = newTarget;
}
link.link = {
entityId: outputSchema,
item: item.field,
type: 'schema'
}
}
}

for (const item of items) {
result.push(item);
}
return result;
} catch (error) {
return;
}
}
}
4 changes: 3 additions & 1 deletion common/src/import-export/policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export class PolicyImportExport {
const allCategories = await DatabaseServer.getPolicyCategories();
policy.categoriesExport = policy.categories?.length ? PolicyImportExport.getPolicyCategoriesExport(policy, allCategories) : [];

const formulas = await dataBaseServer.find(Formula, { policyId: policy.id });
const formulas = await dataBaseServer.find(Formula, { policyId: policy.id, autoGenerated: { $ne: true } });

return {
policy,
Expand Down Expand Up @@ -672,6 +672,8 @@ export class PolicyImportExport {
item.id = (item.id || item._id)?.toString();
delete item._id;
delete item.status;
delete item.policyTopicId;
delete item.policyInstanceTopicId;
return item;
});

Expand Down
Loading