Skip to content

Commit 779ed9b

Browse files
committed
fix: only trigger snapshot proposals for enabled workflows
1 parent b7eae60 commit 779ed9b

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

libs/definitions/src/integration-definitions/snapshot/snapshot.definition.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { IntegrationHookInjects } from '@app/definitions/definition'
22
import { SingleIntegrationDefinition } from '@app/definitions/single-integration.definition'
3-
import { UnauthorizedException } from '@nestjs/common'
3+
import { Logger, UnauthorizedException } from '@nestjs/common'
44
import { IntegrationTrigger } from 'apps/api/src/integration-triggers/entities/integration-trigger'
55
import { Integration } from 'apps/api/src/integrations/entities/integration'
66
import { WorkflowTrigger } from 'apps/api/src/workflow-triggers/entities/workflow-trigger'
@@ -13,6 +13,8 @@ import { ProposalEnded } from './triggers/proposal-ended.trigger'
1313
import { ProposalStarted } from './triggers/proposal-started.trigger'
1414

1515
export class SnapshotDefinition extends SingleIntegrationDefinition {
16+
protected readonly logger = new Logger(SnapshotDefinition.name)
17+
1618
integrationKey = 'snapshot'
1719
integrationVersion = '1'
1820

@@ -38,14 +40,17 @@ export class SnapshotDefinition extends SingleIntegrationDefinition {
3840
runs: { workflowTrigger: WorkflowTrigger; integrationTrigger: IntegrationTrigger; outputs: Record<string, any> }[]
3941
}> {
4042
if (req.headers.authentication !== process.env.SNAPSHOT_AUTHENTICATION_KEY) {
43+
this.logger.error(`Received proposal with invalid authentication key ${req.headers.authentication}`)
4144
throw new UnauthorizedException(`Invalid authentication key`)
4245
}
4346

4447
const proposalId = req.body.id?.split('/')[1]
4548
if (!proposalId || !proposalId.startsWith('0x')) {
49+
this.logger.error(`Received proposal with invalid id ${proposalId}`)
4650
throw new Error(`Invalid proposal id ${proposalId}`)
4751
}
4852
if (!req.body.space) {
53+
this.logger.error(`Received proposal without space ${proposalId}`)
4954
throw new Error(`Space is required`)
5055
}
5156

@@ -65,17 +70,20 @@ export class SnapshotDefinition extends SingleIntegrationDefinition {
6570
break
6671
}
6772
if (!key) {
73+
this.logger.error(`Received proposal with invalid event ${req.body.event}`)
6874
throw new Error(`Unknown snapshot event ${req.body.event}`)
6975
}
7076

7177
const integrationTrigger = await integrationTriggerService.findOne({ key })
7278
if (!integrationTrigger) {
79+
this.logger.error(`Integration trigger with key ${key} not found for proposal ${proposalId}`)
7380
throw new Error(`Integration trigger ${key} not found`)
7481
}
7582

7683
// TODO find only triggers for the space using an indexed field
7784
let workflowTriggers = await workflowTriggerService.find({
7885
integrationTrigger: integrationTrigger._id,
86+
enabled: true,
7987
})
8088
workflowTriggers = workflowTriggers.filter(
8189
(workflowTrigger) => workflowTrigger.inputs?.space?.toLowerCase() === req.body.space?.toLowerCase(),
@@ -88,6 +96,8 @@ export class SnapshotDefinition extends SingleIntegrationDefinition {
8896
}
8997
}
9098

99+
this.logger.log(`Found ${workflowTriggers.length} workflow triggers for ${key} on snapshot space ${req.body.space}`)
100+
91101
let proposal: Record<string, any> = {}
92102
if (key !== this.proposalDeletedTrigger.key) {
93103
const url = `https://api.apireum.com/v1/snapshot/proposal/${proposalId}?key=${process.env.APIREUM_API_KEY}`

0 commit comments

Comments
 (0)