1
1
import { IntegrationHookInjects } from '@app/definitions/definition'
2
2
import { SingleIntegrationDefinition } from '@app/definitions/single-integration.definition'
3
- import { UnauthorizedException } from '@nestjs/common'
3
+ import { Logger , UnauthorizedException } from '@nestjs/common'
4
4
import { IntegrationTrigger } from 'apps/api/src/integration-triggers/entities/integration-trigger'
5
5
import { Integration } from 'apps/api/src/integrations/entities/integration'
6
6
import { WorkflowTrigger } from 'apps/api/src/workflow-triggers/entities/workflow-trigger'
@@ -13,6 +13,8 @@ import { ProposalEnded } from './triggers/proposal-ended.trigger'
13
13
import { ProposalStarted } from './triggers/proposal-started.trigger'
14
14
15
15
export class SnapshotDefinition extends SingleIntegrationDefinition {
16
+ protected readonly logger = new Logger ( SnapshotDefinition . name )
17
+
16
18
integrationKey = 'snapshot'
17
19
integrationVersion = '1'
18
20
@@ -38,14 +40,17 @@ export class SnapshotDefinition extends SingleIntegrationDefinition {
38
40
runs : { workflowTrigger : WorkflowTrigger ; integrationTrigger : IntegrationTrigger ; outputs : Record < string , any > } [ ]
39
41
} > {
40
42
if ( req . headers . authentication !== process . env . SNAPSHOT_AUTHENTICATION_KEY ) {
43
+ this . logger . error ( `Received proposal with invalid authentication key ${ req . headers . authentication } ` )
41
44
throw new UnauthorizedException ( `Invalid authentication key` )
42
45
}
43
46
44
47
const proposalId = req . body . id ?. split ( '/' ) [ 1 ]
45
48
if ( ! proposalId || ! proposalId . startsWith ( '0x' ) ) {
49
+ this . logger . error ( `Received proposal with invalid id ${ proposalId } ` )
46
50
throw new Error ( `Invalid proposal id ${ proposalId } ` )
47
51
}
48
52
if ( ! req . body . space ) {
53
+ this . logger . error ( `Received proposal without space ${ proposalId } ` )
49
54
throw new Error ( `Space is required` )
50
55
}
51
56
@@ -65,17 +70,20 @@ export class SnapshotDefinition extends SingleIntegrationDefinition {
65
70
break
66
71
}
67
72
if ( ! key ) {
73
+ this . logger . error ( `Received proposal with invalid event ${ req . body . event } ` )
68
74
throw new Error ( `Unknown snapshot event ${ req . body . event } ` )
69
75
}
70
76
71
77
const integrationTrigger = await integrationTriggerService . findOne ( { key } )
72
78
if ( ! integrationTrigger ) {
79
+ this . logger . error ( `Integration trigger with key ${ key } not found for proposal ${ proposalId } ` )
73
80
throw new Error ( `Integration trigger ${ key } not found` )
74
81
}
75
82
76
83
// TODO find only triggers for the space using an indexed field
77
84
let workflowTriggers = await workflowTriggerService . find ( {
78
85
integrationTrigger : integrationTrigger . _id ,
86
+ enabled : true ,
79
87
} )
80
88
workflowTriggers = workflowTriggers . filter (
81
89
( workflowTrigger ) => workflowTrigger . inputs ?. space ?. toLowerCase ( ) === req . body . space ?. toLowerCase ( ) ,
@@ -88,6 +96,8 @@ export class SnapshotDefinition extends SingleIntegrationDefinition {
88
96
}
89
97
}
90
98
99
+ this . logger . log ( `Found ${ workflowTriggers . length } workflow triggers for ${ key } on snapshot space ${ req . body . space } ` )
100
+
91
101
let proposal : Record < string , any > = { }
92
102
if ( key !== this . proposalDeletedTrigger . key ) {
93
103
const url = `https://api.apireum.com/v1/snapshot/proposal/${ proposalId } ?key=${ process . env . APIREUM_API_KEY } `
0 commit comments