11import { IntegrationHookInjects } from '@app/definitions/definition'
22import { SingleIntegrationDefinition } from '@app/definitions/single-integration.definition'
3- import { UnauthorizedException } from '@nestjs/common'
3+ import { Logger , UnauthorizedException } from '@nestjs/common'
44import { IntegrationTrigger } from 'apps/api/src/integration-triggers/entities/integration-trigger'
55import { Integration } from 'apps/api/src/integrations/entities/integration'
66import { WorkflowTrigger } from 'apps/api/src/workflow-triggers/entities/workflow-trigger'
@@ -13,6 +13,8 @@ import { ProposalEnded } from './triggers/proposal-ended.trigger'
1313import { ProposalStarted } from './triggers/proposal-started.trigger'
1414
1515export class SnapshotDefinition extends SingleIntegrationDefinition {
16+ protected readonly logger = new Logger ( SnapshotDefinition . name )
17+
1618 integrationKey = 'snapshot'
1719 integrationVersion = '1'
1820
@@ -37,15 +39,20 @@ export class SnapshotDefinition extends SingleIntegrationDefinition {
3739 response : any
3840 runs : { workflowTrigger : WorkflowTrigger ; integrationTrigger : IntegrationTrigger ; outputs : Record < string , any > } [ ]
3941 } > {
42+ this . logger . debug ( `Received hook for space ${ req . body . space } - ${ JSON . stringify ( req . body ) } ` )
43+
4044 if ( req . headers . authentication !== process . env . SNAPSHOT_AUTHENTICATION_KEY ) {
45+ this . logger . error ( `Received proposal with invalid authentication key ${ req . headers . authentication } ` )
4146 throw new UnauthorizedException ( `Invalid authentication key` )
4247 }
4348
4449 const proposalId = req . body . id ?. split ( '/' ) [ 1 ]
4550 if ( ! proposalId || ! proposalId . startsWith ( '0x' ) ) {
51+ this . logger . error ( `Received proposal with invalid id ${ proposalId } ` )
4652 throw new Error ( `Invalid proposal id ${ proposalId } ` )
4753 }
4854 if ( ! req . body . space ) {
55+ this . logger . error ( `Received proposal without space ${ proposalId } ` )
4956 throw new Error ( `Space is required` )
5057 }
5158
@@ -65,22 +72,27 @@ export class SnapshotDefinition extends SingleIntegrationDefinition {
6572 break
6673 }
6774 if ( ! key ) {
75+ this . logger . error ( `Received proposal with invalid event ${ req . body . event } ` )
6876 throw new Error ( `Unknown snapshot event ${ req . body . event } ` )
6977 }
7078
7179 const integrationTrigger = await integrationTriggerService . findOne ( { key } )
7280 if ( ! integrationTrigger ) {
81+ this . logger . error ( `Integration trigger with key ${ key } not found for proposal ${ proposalId } ` )
7382 throw new Error ( `Integration trigger ${ key } not found` )
7483 }
7584
7685 // TODO find only triggers for the space using an indexed field
7786 let workflowTriggers = await workflowTriggerService . find ( {
7887 integrationTrigger : integrationTrigger . _id ,
88+ enabled : true ,
7989 } )
8090 workflowTriggers = workflowTriggers . filter (
8191 ( workflowTrigger ) => workflowTrigger . inputs ?. space ?. toLowerCase ( ) === req . body . space ?. toLowerCase ( ) ,
8292 )
8393
94+ this . logger . log ( `Found ${ workflowTriggers . length } workflow triggers for ${ key } on snapshot space ${ req . body . space } ` )
95+
8496 if ( ! workflowTriggers . length ) {
8597 return {
8698 response : { } ,
0 commit comments