feat(scenarios): add step title, scenario credentials, and environment context in executor
- add nullable title column to scenario steps; exposed in create/edit forms and step table - add scenario-credential join (many-to-many with CredentialEntity) with CRUD endpoints - expose environment URLs in code executor helpers via helpers.env and helpers.getEnvUrl() - resolve and cache environment per run from the login step's environmentName in scheduler - add section spacing and step table title column to ScenarioDetailPage
This commit is contained in:
1 parent
1f3a604940
commit
1efbbb38a3
34 files changed
+1362
-14
No files matched your search
@@ -0,0 +1,66 @@
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
HttpCode,
|
||||
Param,
|
||||
ParseIntPipe,
|
||||
Patch,
|
||||
Post,
|
||||
Query,
|
||||
} from "@nestjs/common";
|
||||
import { ApiOperation, ApiResponse, ApiTags } from "@nestjs/swagger";
|
||||
import { CredentialService } from "./credential.service";
|
||||
import { CreateCredentialDto } from "./dto/create-credential.dto";
|
||||
import { UpdateCredentialDto } from "./dto/update-credential.dto";
|
||||
import { PaginationQueryDto } from "../common/dto/pagination.dto";
|
||||
import { CredentialOrderBy } from "./credential.service";
|
||||
|
||||
@ApiTags("credentials")
|
||||
@Controller("credentials")
|
||||
export class CredentialController {
|
||||
constructor(private readonly credentialService: CredentialService) {}
|
||||
|
||||
@Post()
|
||||
@ApiOperation({ summary: "Create a new credential" })
|
||||
@ApiResponse({ status: 201, description: "Credential created" })
|
||||
create(@Body() dto: CreateCredentialDto) {
|
||||
return this.credentialService.create(dto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
@ApiOperation({ summary: "List all credentials (paginated)" })
|
||||
@ApiResponse({ status: 200, description: "Paginated credentials" })
|
||||
findAll(@Query() query: PaginationQueryDto<CredentialOrderBy>) {
|
||||
return this.credentialService.findAll(query);
|
||||
}
|
||||
|
||||
@Get(":id")
|
||||
@ApiOperation({ summary: "Get credential by ID" })
|
||||
@ApiResponse({ status: 200, description: "Credential record" })
|
||||
@ApiResponse({ status: 404, description: "Credential not found" })
|
||||
findOne(@Param("id", ParseIntPipe) id: number) {
|
||||
return this.credentialService.findOne(id);
|
||||
}
|
||||
|
||||
@Patch(":id")
|
||||
@ApiOperation({ summary: "Update a credential" })
|
||||
@ApiResponse({ status: 200, description: "Credential updated" })
|
||||
@ApiResponse({ status: 404, description: "Credential not found" })
|
||||
update(
|
||||
@Param("id", ParseIntPipe) id: number,
|
||||
@Body() dto: UpdateCredentialDto,
|
||||
) {
|
||||
return this.credentialService.update(id, dto);
|
||||
}
|
||||
|
||||
@Delete(":id")
|
||||
@HttpCode(204)
|
||||
@ApiOperation({ summary: "Delete a credential" })
|
||||
@ApiResponse({ status: 204, description: "Credential deleted" })
|
||||
@ApiResponse({ status: 404, description: "Credential not found" })
|
||||
remove(@Param("id", ParseIntPipe) id: number) {
|
||||
return this.credentialService.remove(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import {
|
||||
Entity,
|
||||
PrimaryGeneratedColumn,
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
UpdateDateColumn,
|
||||
} from "typeorm";
|
||||
|
||||
@Entity("credentials")
|
||||
export class CredentialEntity {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
name: string;
|
||||
|
||||
@Column("text", { nullable: true })
|
||||
data: string | null;
|
||||
|
||||
@Column({ type: "datetime", nullable: true })
|
||||
lastUsedAt: Date | null;
|
||||
|
||||
@CreateDateColumn()
|
||||
createdAt: Date;
|
||||
|
||||
@UpdateDateColumn()
|
||||
updatedAt: Date;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { Module } from "@nestjs/common";
|
||||
import { TypeOrmModule } from "@nestjs/typeorm";
|
||||
import { CredentialEntity } from "./credential.entity";
|
||||
import { CredentialService } from "./credential.service";
|
||||
import { CredentialController } from "./credential.controller";
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([CredentialEntity])],
|
||||
controllers: [CredentialController],
|
||||
providers: [CredentialService],
|
||||
exports: [CredentialService],
|
||||
})
|
||||
export class CredentialModule {}
|
||||
@@ -0,0 +1,56 @@
|
||||
import { Injectable, NotFoundException } from "@nestjs/common";
|
||||
import { InjectRepository } from "@nestjs/typeorm";
|
||||
import { Repository } from "typeorm";
|
||||
import { CredentialEntity } from "./credential.entity";
|
||||
import { CreateCredentialDto } from "./dto/create-credential.dto";
|
||||
import { UpdateCredentialDto } from "./dto/update-credential.dto";
|
||||
import {
|
||||
PaginationQueryDto,
|
||||
PaginatedResult,
|
||||
} from "../common/dto/pagination.dto";
|
||||
|
||||
export type CredentialOrderBy = "id" | "name" | "lastUsedAt" | "createdAt" | "updatedAt";
|
||||
|
||||
@Injectable()
|
||||
export class CredentialService {
|
||||
constructor(
|
||||
@InjectRepository(CredentialEntity)
|
||||
private readonly repo: Repository<CredentialEntity>,
|
||||
) {}
|
||||
|
||||
async create(dto: CreateCredentialDto): Promise<CredentialEntity> {
|
||||
return this.repo.save(this.repo.create({ ...dto, data: dto.data ?? null }));
|
||||
}
|
||||
|
||||
async findAll(
|
||||
query: PaginationQueryDto<CredentialOrderBy> = {},
|
||||
): Promise<PaginatedResult<CredentialEntity>> {
|
||||
const page = query.page ?? 1;
|
||||
const limit = query.limit ?? 20;
|
||||
const orderBy = query.orderBy ?? "id";
|
||||
const orderDir = query.orderDir ?? "ASC";
|
||||
const [data, total] = await this.repo.findAndCount({
|
||||
order: { [orderBy]: orderDir },
|
||||
skip: (page - 1) * limit,
|
||||
take: limit,
|
||||
});
|
||||
return { data, total, page, limit };
|
||||
}
|
||||
|
||||
async findOne(id: number): Promise<CredentialEntity> {
|
||||
const credential = await this.repo.findOneBy({ id });
|
||||
if (!credential) throw new NotFoundException(`Credential ${id} not found`);
|
||||
return credential;
|
||||
}
|
||||
|
||||
async update(id: number, dto: UpdateCredentialDto): Promise<CredentialEntity> {
|
||||
const credential = await this.findOne(id);
|
||||
Object.assign(credential, dto);
|
||||
return this.repo.save(credential);
|
||||
}
|
||||
|
||||
async remove(id: number): Promise<void> {
|
||||
await this.findOne(id);
|
||||
await this.repo.delete(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import { ApiProperty, ApiPropertyOptional } from "@nestjs/swagger";
|
||||
import { IsNotEmpty, IsOptional, IsString } from "class-validator";
|
||||
|
||||
export class CreateCredentialDto {
|
||||
@ApiProperty({ example: "my-api-key" })
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
name: string;
|
||||
|
||||
@ApiPropertyOptional({
|
||||
description: "JSON-encoded credential payload",
|
||||
example: '{"token":"abc123","secret":"xyz"}',
|
||||
})
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
data?: string;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import { PartialType } from "@nestjs/swagger";
|
||||
import { CreateCredentialDto } from "./create-credential.dto";
|
||||
|
||||
export class UpdateCredentialDto extends PartialType(CreateCredentialDto) {}
|
||||
Reference in new issue
Block a user