Files
liqa/server/src/scenario/dto/scenario-export.dto.ts
T
ars9 f268d0e3eb feat(scenarios): overhaul export/import with multi-entity YAML format
- export now accepts includeEnvironment and credentialIds query params
- output is a YAML stream with comment-delimited environment, credential, and scenario sections
- scenario entity includes credentials array with alias mappings
- import accepts both old single-object and new array format, upserts envs/creds before linking
- new ExportScenarioModal with env and per-credential checkboxes replaces direct download
2026-04-15 00:35:14 +03:00

139 lines
2.5 KiB
TypeScript

import { ApiProperty, ApiPropertyOptional } from "@nestjs/swagger";
import { Type } from "class-transformer";
import {
IsArray,
IsIn,
IsNotEmpty,
IsObject,
IsOptional,
IsString,
IsUUID,
ValidateNested,
} from "class-validator";
import { EnvironmentData } from "../../environment/environment.entity";
export class ScenarioStepExportDto {
@ApiPropertyOptional()
@IsOptional()
@IsString()
@IsNotEmpty()
title: string | null;
@ApiPropertyOptional()
@IsOptional()
@IsString()
@IsNotEmpty()
execCode: string | null;
}
export class CredentialExportDto {
@ApiPropertyOptional()
@IsOptional()
@IsIn(["credential"])
kind?: "credential";
@ApiPropertyOptional()
@IsOptional()
@IsUUID()
id?: string;
@ApiProperty()
@IsString()
@IsNotEmpty()
name: string;
@ApiPropertyOptional()
@IsOptional()
@IsString()
data?: string | null;
}
export class EnvironmentExportInlineDto {
@ApiPropertyOptional()
@IsOptional()
@IsIn(["environment"])
kind?: "environment";
@ApiPropertyOptional()
@IsOptional()
@IsUUID()
id?: string;
@ApiProperty()
@IsString()
@IsNotEmpty()
name: string;
@ApiPropertyOptional()
@IsOptional()
@IsString()
description?: string;
@ApiProperty()
@IsObject()
data: EnvironmentData;
}
export class ScenarioCredentialMappingDto {
@ApiProperty()
@IsUUID()
credentialId: string;
@ApiProperty()
@IsString()
@IsNotEmpty()
alias: string;
}
export class ScenarioExportDto {
@ApiPropertyOptional()
@IsOptional()
@IsIn(["scenario"])
kind?: "scenario";
@ApiPropertyOptional()
@IsOptional()
@IsUUID()
id?: string;
@ApiPropertyOptional()
@IsOptional()
@IsString()
@IsNotEmpty()
title?: string;
@ApiProperty()
@IsString()
@IsNotEmpty()
name: string;
@ApiPropertyOptional()
@IsOptional()
@IsString()
description?: string;
@ApiPropertyOptional()
@IsOptional()
@IsUUID()
environmentId?: string;
@ApiPropertyOptional({ type: [ScenarioCredentialMappingDto] })
@IsOptional()
@IsArray()
@ValidateNested({ each: true })
@Type(() => ScenarioCredentialMappingDto)
credentials?: ScenarioCredentialMappingDto[];
@ApiProperty({ type: [ScenarioStepExportDto] })
@IsArray()
@ValidateNested({ each: true })
@Type(() => ScenarioStepExportDto)
steps: ScenarioStepExportDto[];
}
/** Union type for multi-entity export array items */
export type ExportEntity =
| EnvironmentExportInlineDto
| CredentialExportDto
| ScenarioExportDto;