- add ScenarioRunLogEntity to persist step script output to DB - stepLogger dual-writes to NestJS logger and DB (fire-and-forget) - add GET /scenarios/:id/run/:runId returning run, stepRuns and logs - add POST /scenarios/:id/run/:runId/wait (polls until terminal state) - 9 new integration tests for the two endpoints (136 total) - add eslint with typescript-eslint and eslint-config-prettier - add npm scripts: format, lint, lint:fix - resolve all lint errors across src and test (no any types) - add CONTRIBUTING.md covering dev workflow
62 lines
2.1 KiB
TypeScript
62 lines
2.1 KiB
TypeScript
import { Body, Controller, Post } from "@nestjs/common";
|
|
import { ApiOperation, ApiResponse, ApiTags } from "@nestjs/swagger";
|
|
import { BrowserService, ExecResult, OpenResult } from "./browser.service";
|
|
import { CodeExecutorService } from "../code-executor/code-executor.service";
|
|
import { OpenDto } from "./dto/open.dto";
|
|
import { ExecDto } from "./dto/exec.dto";
|
|
|
|
@ApiTags("browser")
|
|
@Controller()
|
|
export class BrowserController {
|
|
constructor(
|
|
private readonly browserService: BrowserService,
|
|
private readonly codeExecutor: CodeExecutorService,
|
|
) {}
|
|
|
|
@Post("open")
|
|
@ApiOperation({
|
|
summary: "Open a URL with a stored session (cookies + localStorage)",
|
|
})
|
|
@ApiResponse({
|
|
status: 201,
|
|
description: "Page loaded successfully",
|
|
schema: {
|
|
properties: {
|
|
url: { type: "string" },
|
|
title: { type: "string" },
|
|
content: { type: "string" },
|
|
},
|
|
},
|
|
})
|
|
@ApiResponse({ status: 400, description: "Invalid input" })
|
|
@ApiResponse({ status: 404, description: "Session not found" })
|
|
@ApiResponse({ status: 500, description: "Browser automation failed" })
|
|
open(@Body() dto: OpenDto): Promise<OpenResult> {
|
|
return this.browserService.open(
|
|
dto.sessionName,
|
|
dto.url,
|
|
dto.readerMode ?? false,
|
|
dto.selector,
|
|
);
|
|
}
|
|
|
|
@Post("exec")
|
|
@ApiOperation({
|
|
summary: "Execute custom Playwright JavaScript within a stored session",
|
|
description:
|
|
"The `code` string is executed as an async function body with `page` (Playwright Page) and `context` (BrowserContext) in scope. The return value is serialised and returned as `result`.",
|
|
})
|
|
@ApiResponse({
|
|
status: 201,
|
|
description: "Code executed successfully",
|
|
schema: { properties: { result: {} } },
|
|
})
|
|
@ApiResponse({ status: 400, description: "Invalid input" })
|
|
@ApiResponse({ status: 404, description: "Session not found" })
|
|
@ApiResponse({ status: 500, description: "Execution failed" })
|
|
exec(@Body() dto: ExecDto): Promise<ExecResult> {
|
|
this.codeExecutor.validate(dto.code);
|
|
return this.browserService.exec(dto.sessionName, dto.code, dto.url);
|
|
}
|
|
}
|