@@ -80,6 +80,36 @@ interface GlobalVsNotification {
8080 label : 'Schema' ,
8181 title : 'Expected schema' ,
8282 type : PropertyType . Schemas
83+ } ,
84+ {
85+ name : 'messageTypes' ,
86+ label : 'Message types' ,
87+ title : 'Message type mappings' ,
88+ type : PropertyType . Array ,
89+ items : {
90+ label : 'Message type' ,
91+ value : '@filterField @filterValue @messageType' ,
92+ properties : [
93+ {
94+ name : 'filterField' ,
95+ label : 'Filter field' ,
96+ title : 'Filter field (VC path or @message.<field>)' ,
97+ type : PropertyType . Input
98+ } ,
99+ {
100+ name : 'filterValue' ,
101+ label : 'Filter value' ,
102+ title : 'Filter value' ,
103+ type : PropertyType . Input
104+ } ,
105+ {
106+ name : 'messageType' ,
107+ label : 'Message type' ,
108+ title : 'Message type name used in Events tab' ,
109+ type : PropertyType . Input
110+ }
111+ ]
112+ }
83113 }
84114 ]
85115 } ,
@@ -457,6 +487,30 @@ export class GlobalEventsReaderBlock {
457487 } ;
458488 }
459489
490+ private getFieldValue ( source : any , path : string ) : any {
491+ if ( ! source || typeof source !== 'object' ) {
492+ return undefined ;
493+ }
494+
495+ if ( ! path || typeof path !== 'string' ) {
496+ return undefined ;
497+ }
498+
499+ const segments = path . split ( '.' ) ;
500+
501+ let current : any = source ;
502+
503+ for ( const segment of segments ) {
504+ if ( current == null ) {
505+ return undefined ;
506+ }
507+
508+ current = current [ segment ] ;
509+ }
510+
511+ return current ;
512+ }
513+
460514 private async processNotification (
461515 ref : AnyBlockType ,
462516 user : PolicyUser ,
@@ -678,9 +732,55 @@ export class GlobalEventsReaderBlock {
678732 throw new BlockActionError ( error , ref . blockType , ref . uuid ) ;
679733 }
680734
681- ref . triggerEvents ( PolicyOutputEventType . RunEvent , user , state ) ;
735+ const options : any = ref . options || { } ;
736+ const messageTypesConfig : any [ ] = Array . isArray ( options . messageTypes )
737+ ? options . messageTypes
738+ : [ ] ;
739+
740+ let matchedMessageType : boolean = false ;
741+
742+ for ( const configItem of messageTypesConfig ) {
743+ if ( ! configItem ) {
744+ continue ;
745+ }
746+
747+ const filterField : string | undefined = configItem . filterField ;
748+ const filterValue : string | undefined = configItem . filterValue ;
749+ const messageType : string | undefined = configItem . messageType ;
750+
751+ if ( ! messageType ) {
752+ continue ;
753+ }
754+
755+ let actualValue : any = undefined ;
756+
757+ if ( filterField && typeof filterField === 'string' ) {
758+ if ( filterField . startsWith ( '@message.' ) ) {
759+ // read from payload (notification meta)
760+ const messagePath : string = filterField . slice ( '@message.' . length ) ;
761+ actualValue = this . getFieldValue ( payload as any , messagePath ) ;
762+ } else {
763+ // read from VC document
764+ actualValue = this . getFieldValue ( document , filterField ) ;
765+ }
766+ }
767+
768+ const isMatch : boolean = ! filterField || actualValue === filterValue ;
769+
770+ if ( isMatch ) {
771+ ref . triggerEvents ( messageType , user , state ) ;
772+ matchedMessageType = true ;
773+ }
774+ }
775+
776+ if ( ! matchedMessageType ) {
777+ // fallback to default behavior
778+ ref . triggerEvents ( PolicyOutputEventType . RunEvent , user , state ) ;
779+ }
780+
682781 ref . triggerEvents ( PolicyOutputEventType . ReleaseEvent , user , null ) ;
683782 ref . triggerEvents ( PolicyOutputEventType . RefreshEvent , user , state ) ;
783+
684784 PolicyComponentsUtils . ExternalEventFn ( new ExternalEvent ( ExternalEventType . Run , ref , user , {
685785 documents : ExternalDocuments ( policyDocument )
686786 } ) ) ;
0 commit comments