Skip to content

Commit d63326f

Browse files
committed
chore: merge main into release for new releases
2 parents 11805e2 + 914c41a commit d63326f

File tree

34 files changed

+1751
-466
lines changed

34 files changed

+1751
-466
lines changed

apps/api/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
"prettier": "^3.5.3",
8383
"source-map-support": "^0.5.21",
8484
"supertest": "^7.0.0",
85+
"trigger.dev": "4.0.6",
8586
"ts-jest": "^29.2.5",
8687
"ts-loader": "^9.5.2",
8788
"ts-node": "^10.9.2",
@@ -111,9 +112,9 @@
111112
"db:getschema": "node ../../packages/db/scripts/combine-schemas.js && cp ../../packages/db/dist/schema.prisma prisma/schema.prisma",
112113
"db:migrate": "cd ../../packages/db && bunx prisma migrate dev && cd ../../apps/api",
113114
"deploy:trigger-prod": "npx trigger.dev@4.0.6 deploy",
114-
"dev": "bunx concurrently --kill-others --names \"nest,trigger\" --prefix-colors \"green,blue\" \"nest start --watch\" \"bunx trigger.dev@4.0.6 dev\"",
115+
"dev": "bunx concurrently --kill-others --names \"nest,trigger\" --prefix-colors \"green,blue\" \"nest start --watch\" \"trigger dev\"",
115116
"dev:nest": "nest start --watch",
116-
"dev:trigger": "bunx trigger.dev@4.0.6 dev",
117+
"dev:trigger": "trigger dev",
117118
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
118119
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
119120
"prebuild": "bun run db:generate",

apps/api/src/cloud-security/cloud-security.controller.ts

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
import {
22
Controller,
33
Post,
4+
Get,
45
Param,
6+
Query,
57
Headers,
68
Logger,
79
HttpException,
810
HttpStatus,
11+
UseGuards,
912
} from '@nestjs/common';
10-
import { CloudSecurityService } from './cloud-security.service';
13+
import { HybridAuthGuard } from '../auth/hybrid-auth.guard';
14+
import { OrganizationId } from '../auth/auth-context.decorator';
15+
import {
16+
CloudSecurityService,
17+
ConnectionNotFoundError,
18+
} from './cloud-security.service';
1119

1220
@Controller({ path: 'cloud-security', version: '1' })
1321
export class CloudSecurityController {
@@ -53,4 +61,57 @@ export class CloudSecurityController {
5361
scannedAt: result.scannedAt,
5462
};
5563
}
64+
65+
@Post('trigger/:connectionId')
66+
@UseGuards(HybridAuthGuard)
67+
async triggerScan(
68+
@Param('connectionId') connectionId: string,
69+
@OrganizationId() organizationId: string,
70+
) {
71+
this.logger.log(
72+
`Cloud security scan trigger requested for connection ${connectionId}`,
73+
);
74+
75+
try {
76+
const result = await this.cloudSecurityService.triggerScan(
77+
connectionId,
78+
organizationId,
79+
);
80+
return result;
81+
} catch (error) {
82+
const message =
83+
error instanceof Error ? error.message : 'Failed to trigger scan';
84+
throw new HttpException(message, HttpStatus.BAD_REQUEST);
85+
}
86+
}
87+
88+
@Get('runs/:runId')
89+
@UseGuards(HybridAuthGuard)
90+
async getRunStatus(
91+
@Param('runId') runId: string,
92+
@Query('connectionId') connectionId: string,
93+
@OrganizationId() organizationId: string,
94+
) {
95+
if (!connectionId) {
96+
throw new HttpException(
97+
'connectionId query parameter is required',
98+
HttpStatus.BAD_REQUEST,
99+
);
100+
}
101+
102+
try {
103+
return await this.cloudSecurityService.getRunStatus(
104+
runId,
105+
connectionId,
106+
organizationId,
107+
);
108+
} catch (error) {
109+
if (error instanceof ConnectionNotFoundError) {
110+
throw new HttpException('Connection not found', HttpStatus.NOT_FOUND);
111+
}
112+
const message =
113+
error instanceof Error ? error.message : 'Failed to get run status';
114+
throw new HttpException(message, HttpStatus.INTERNAL_SERVER_ERROR);
115+
}
116+
}
56117
}

apps/api/src/cloud-security/cloud-security.module.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import { GCPSecurityService } from './providers/gcp-security.service';
55
import { AWSSecurityService } from './providers/aws-security.service';
66
import { AzureSecurityService } from './providers/azure-security.service';
77
import { IntegrationPlatformModule } from '../integration-platform/integration-platform.module';
8+
import { AuthModule } from '../auth/auth.module';
89

910
@Module({
10-
imports: [IntegrationPlatformModule],
11+
imports: [IntegrationPlatformModule, AuthModule],
1112
controllers: [CloudSecurityController],
1213
providers: [
1314
CloudSecurityService,

apps/api/src/cloud-security/cloud-security.service.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Injectable, Logger } from '@nestjs/common';
22
import { db } from '@db';
33
import { getManifest } from '@comp/integration-platform';
4+
import { runs, tasks } from '@trigger.dev/sdk';
45
import { CredentialVaultService } from '../integration-platform/services/credential-vault.service';
56
import { OAuthCredentialsService } from '../integration-platform/services/oauth-credentials.service';
67
import { GCPSecurityService } from './providers/gcp-security.service';
@@ -28,6 +29,12 @@ export interface ScanResult {
2829
error?: string;
2930
}
3031

32+
export class ConnectionNotFoundError extends Error {
33+
constructor() {
34+
super('Connection not found');
35+
}
36+
}
37+
3138
@Injectable()
3239
export class CloudSecurityService {
3340
private readonly logger = new Logger(CloudSecurityService.name);
@@ -220,6 +227,65 @@ export class CloudSecurityService {
220227
}
221228
}
222229

230+
async triggerScan(
231+
connectionId: string,
232+
organizationId: string,
233+
): Promise<{ runId: string }> {
234+
// Validate connection exists and is active
235+
const connection = await db.integrationConnection.findFirst({
236+
where: {
237+
id: connectionId,
238+
organizationId,
239+
status: 'active',
240+
},
241+
});
242+
243+
if (!connection) {
244+
throw new Error('Connection not found or inactive');
245+
}
246+
247+
const handle = await tasks.trigger('run-cloud-security-scan', {
248+
connectionId,
249+
organizationId,
250+
providerSlug: 'platform',
251+
connectionName: connectionId,
252+
});
253+
254+
this.logger.log(`Triggered cloud security scan task`, {
255+
connectionId,
256+
runId: handle.id,
257+
});
258+
259+
return { runId: handle.id };
260+
}
261+
262+
async getRunStatus(
263+
runId: string,
264+
connectionId: string,
265+
organizationId: string,
266+
): Promise<{ completed: boolean; success: boolean; output: unknown }> {
267+
// Verify the connection belongs to the caller's organization
268+
const connection = await db.integrationConnection.findFirst({
269+
where: {
270+
id: connectionId,
271+
organizationId,
272+
},
273+
select: { id: true },
274+
});
275+
276+
if (!connection) {
277+
throw new ConnectionNotFoundError();
278+
}
279+
280+
const run = await runs.retrieve(runId);
281+
282+
return {
283+
completed: run.isCompleted,
284+
success: run.isCompleted ? run.isSuccess : false,
285+
output: run.isCompleted ? run.output : null,
286+
};
287+
}
288+
223289
private async storeFindings(
224290
connectionId: string,
225291
provider: string,

apps/api/src/evidence-forms/evidence-form-type-map.ts

Lines changed: 0 additions & 43 deletions
This file was deleted.

apps/api/src/evidence-forms/evidence-forms.service.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { AttachmentsService } from '@/attachments/attachments.service';
22
import type { AuthContext } from '@/auth/types';
3-
import { db, type EvidenceFormType as DbEvidenceFormType } from '@trycompai/db';
3+
import { db, EvidenceFormType as DbEvidenceFormType } from '@trycompai/db';
4+
import {
5+
toDbEvidenceFormType,
6+
toExternalEvidenceFormType,
7+
} from '@comp/company';
48
import {
59
BadRequestException,
610
Injectable,
@@ -16,10 +20,6 @@ import {
1620
type EvidenceFormFieldDefinition,
1721
type EvidenceFormType,
1822
} from './evidence-forms.definitions';
19-
import {
20-
toDbEvidenceFormType,
21-
toExternalEvidenceFormType,
22-
} from './evidence-form-type-map';
2323

2424
const listQuerySchema = z.object({
2525
search: z.string().trim().optional(),

apps/api/src/findings/findings.service.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@ import {
77
} from '@nestjs/common';
88
import {
99
db,
10-
type EvidenceFormType as DbEvidenceFormType,
10+
EvidenceFormType as DbEvidenceFormType,
1111
FindingStatus,
1212
FindingType,
1313
} from '@trycompai/db';
14+
import {
15+
toDbEvidenceFormType,
16+
toExternalEvidenceFormType,
17+
} from '@comp/company';
1418
import { CreateFindingDto } from './dto/create-finding.dto';
1519
import { UpdateFindingDto } from './dto/update-finding.dto';
1620
import { FindingAuditService } from './finding-audit.service';
1721
import { FindingNotifierService } from './finding-notifier.service';
1822
import { type EvidenceFormType } from '@/evidence-forms/evidence-forms.definitions';
19-
import {
20-
toDbEvidenceFormType,
21-
toExternalEvidenceFormType,
22-
} from '@/evidence-forms/evidence-form-type-map';
2323

2424
@Injectable()
2525
export class FindingsService {

apps/app/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@
145145
"postcss": "^8.5.4",
146146
"raw-loader": "^4.0.2",
147147
"tailwindcss": "^4.1.8",
148+
"trigger.dev": "4.0.6",
148149
"typescript": "^5.8.3",
149150
"vite-tsconfig-paths": "^5.1.4",
150151
"vitest": "^3.2.4"
@@ -170,7 +171,7 @@
170171
"db:getschema": "node ../../packages/db/scripts/combine-schemas.js && cp ../../packages/db/dist/schema.prisma prisma/schema.prisma",
171172
"db:migrate": "cd ../../packages/db && bunx prisma migrate dev && cd ../../apps/app",
172173
"deploy:trigger-prod": "npx trigger.dev@4.0.6 deploy",
173-
"dev": "bun i && bunx concurrently --kill-others --names \"next,trigger\" --prefix-colors \"yellow,blue\" \"next dev --turbo -p 3000\" \"bunx trigger.dev@4.0.6 dev\"",
174+
"dev": "bun i && bunx concurrently --kill-others --names \"next,trigger\" --prefix-colors \"yellow,blue\" \"next dev --turbo -p 3000\" \"trigger dev\"",
174175
"lint": "eslint . && prettier --check .",
175176
"prebuild": "bun run db:generate",
176177
"postinstall": "prisma generate --schema=./prisma/schema.prisma || exit 0",

0 commit comments

Comments
 (0)