currentUserId
The authenticated caller's id.
function currentUserId(req: FastifyRequest): stringapps/api/src/lib/current-user.ts:11API Docs
The authenticated caller's id.
function currentUserId(req: FastifyRequest): stringapps/api/src/lib/current-user.ts:11Create a 400 error for invalid client input.
badRequest = (message: string, details?: unknown) => new HttpError(400, message, details)apps/api/src/lib/http-error.ts:18Create a 409 error for duplicate or conflicting state.
conflict = (message: string) => new HttpError(409, message)apps/api/src/lib/http-error.ts:27Create a 403 error for authenticated users without access.
forbidden = (message = 'Forbidden') => new HttpError(403, message)apps/api/src/lib/http-error.ts:23A thin error type carrying an HTTP status code. Thrown anywhere in a route and translated into a JSON `{ error }` body by the global error handler.
class HttpError extends Errorapps/api/src/lib/http-error.ts:5Create a 404 error when a requested record does not exist.
notFound = (message = 'Not found') => new HttpError(404, message)apps/api/src/lib/http-error.ts:25Create a 401 error for missing or invalid authentication.
unauthorized = (message = 'Unauthorized') => new HttpError(401, message)apps/api/src/lib/http-error.ts:21Launch headless Chromium for screenshot capture.
async function launchChromium(): Promise<Browser>apps/api/src/lib/launchChromium.ts:17Shared Winston logger used by the API, worker and supporting services.
logger = winston.createLogger(apps/api/src/lib/logger.ts:5No summary comment yet.
async function seedPreviewIfEmpty(): Promise<void>apps/api/src/lib/seedPreview.ts:9Extract the host-independent path (pathname + search) from a URL.
function pathFromUrl(url: string): stringapps/api/src/lib/url.ts:10Build a canonical URL on the suite's base origin for a given path.
function urlFromBase(baseUrl: string, path: string): stringapps/api/src/lib/url.ts:25Map a current Baseline pointer document to the shared Baseline DTO.
function toBaselineDTO(doc: any): Baselineapps/api/src/mappers/index.ts:206Map an immutable BaselineVersion document to the shared history DTO.
function toBaselineVersionDTO(doc: any): BaselineVersionapps/api/src/mappers/index.ts:221Map a GitHub App installation document to the linking UI DTO.
function toGitHubInstallationDTO(doc: any): GitHubInstallationapps/api/src/mappers/index.ts:244Map one PageResult document to the shared PageResult DTO.
function toPageResultDTO(doc: any): PageResultapps/api/src/mappers/index.ts:183Map a discovered SitePage document to the shared SitePage DTO.
function toSitePageDTO(doc: any): SitePageapps/api/src/mappers/index.ts:148Map stored crawl state to the shared SuiteCrawlState DTO.
function toSuiteCrawlStateDTO(crawl: any): SuiteCrawlStateapps/api/src/mappers/index.ts:138Map a minimal team reference to the shared TeamSummary DTO.
function toTeamSummaryDTO(doc: any): TeamSummary | nullapps/api/src/mappers/index.ts:108Map a TestRun document to the shared TestRun DTO.
function toTestRunDTO(doc: any): TestRunapps/api/src/mappers/index.ts:166Map a stored structured log line to the shared TestRunLog DTO.
function toTestRunLogDTO(doc: any): TestRunLogapps/api/src/mappers/index.ts:259Map a TestSuite document to the shared TestSuite DTO.
function toTestSuiteDTO(doc: any, extras?: TestSuiteDTOExtras): TestSuiteapps/api/src/mappers/index.ts:85Map a TestSuiteGrant document to the shared DTO.
function toTestSuiteGrantDTO( doc: any, resolved?:apps/api/src/mappers/index.ts:119Map a User document to the safe user DTO returned to browsers.
function toUserDTO(doc: any): Userapps/api/src/mappers/index.ts:42Map a user reference to a minimal summary. Handles both a populated user doc and a bare ObjectId/string (returns id-only in that case); null stays null.
function toUserSummaryDTO(doc: any): UserSummary | nullapps/api/src/mappers/index.ts:57Choose the job backend.
function resolveQueueBackend(): QueueBackendapps/api/src/queue/backend.ts:15Enqueue a site-discovery crawl.
async function enqueueCrawl(data: CrawlJobData): Promise<void>apps/api/src/queue/index.ts:62Enqueue a targeted page rerun. Retries are disabled conceptually — the UI can trigger again; automatic retry would risk double-seeding baselines.
async function enqueueRerunPage(data: RerunPageJobData): Promise<void>apps/api/src/queue/index.ts:74Enqueue a full visual-regression run.
async function enqueueTestRun(data: TestRunJobData): Promise<void>apps/api/src/queue/index.ts:53Recrawl schedule is no longer a Redis repeatable job. Suites store their interval on `config.recrawlInterval`; a Vercel Cron (or local timer) calls `enqueueDueRecrawls` to pick up suites that are due.
async function reconcileRecrawlSchedule( _testSuiteId: string, _interval?: string | null, _isActive = true ): Promise<void>apps/api/src/queue/index.ts:89No summary comment yet.
async function removeRecrawlSchedule(_testSuiteId: string): Promise<void>apps/api/src/queue/index.ts:97A Mongo filter selecting the suites a user may see, honouring `scope`. Compose it with other filters (kind, isActive, …) via `$and` or by spreading.
async function accessibleSuiteFilter( userId: string, scope: SuiteScope = SuiteScope.ALL ): Promise<Record<string, unknown>>apps/api/src/services/AccessService.ts:118Remove every grant on a suite — called when the suite is deleted.
async function deleteGrantsForSuite(testSuiteId: string): Promise<void>apps/api/src/services/AccessService.ts:319Resolve a caller's standing on a suite. Returns `role: null` when they have no access; throws only when the suite genuinely does not exist.
async function getSuiteAccess( userId: string, testSuiteId: string, preloadedSuite?: any ): Promise<SuiteAccess>apps/api/src/services/AccessService.ts:143Ids of every suite shared with the user (owned suites not included).
async function grantedSuiteIds(userId: string): Promise<Types.ObjectId[]>apps/api/src/services/AccessService.ts:106The run-scoped equivalent: resolve a run, then gate on its parent suite. Returns both so handlers don't re-read either document.
async function requireRunCapability( userId: string, testRunId: string, capability: SuiteCapability ): Promise<apps/api/src/services/AccessService.ts:210Gate a suite operation. Returns the suite plus the caller's resolved role.
async function requireSuiteCapability( userId: string, testSuiteId: string, capability: SuiteCapability, preloadedSuite?: any ): Promise<GrantedSuiteAccess>apps/api/src/services/AccessService.ts:186Expand a user into every principal they act as.
async function resolvePrincipals(userId: string): Promise<PrincipalRef[]>apps/api/src/services/AccessService.ts:87Grant counts per suite (owner excluded), for the "shared" badge in lists.
async function shareCountsForSuites( suiteIds: Types.ObjectId[] ): Promise<Map<string, number>>apps/api/src/services/AccessService.ts:303Build the viewer-access DTO attached to suite responses.
function toViewerAccess(access: SuiteAccess): TestSuiteViewerAccess | nullapps/api/src/services/AccessService.ts:233Batch version of `getSuiteAccess` for list endpoints: one grant query for every suite on the page instead of one per suite.
async function viewerAccessForSuites( userId: string, suites: any[] ): Promise<Map<string, TestSuiteViewerAccess>>apps/api/src/services/AccessService.ts:248Append a new BaselineVersion for a (suite, path, viewport) and repoint the Baseline doc at it. Idempotent enough for retries: the unique (suite,path,viewport,version) index rejects a duplicate version number, and we recompute `version` from the current max each call.
async function recordBaselineVersion( params: RecordBaselineVersionParams ): Promise<IBaselineVersion | null>apps/api/src/services/BaselineHistoryService.ts:55Promote a PR run's accepted screenshots to the suite's main baselines.
async function promoteRunBaselines(testRunId: string): Promise<PromotionResult>apps/api/src/services/PromotionService.ts:24Approve every changed (FAIL) result in a run at once. - MANUAL/BRANCH: write a baseline from each changed screenshot immediately. - PR: defer baselines to merge (PromotionService); just accept. In both cases the changed results become PASS/approved and the gate is recomputed (to APPROVED). The PR GitHub-check unblock stays in the route.
async function approveAllRunDiffs( testRunId: string, approvedBy?: string | null ): Promise<ApproveAllResult>apps/api/src/services/ReviewService.ts:144Pure: derive a run's review gate from its current page results. - any unresolved diff (status FAIL) still present -> PENDING - no diffs left but at least one was approved -> APPROVED - never had a diff -> NOT_REQUIRED
function computeReviewState(results: ResultGateInput[]): VisualReviewStateapps/api/src/services/ReviewService.ts:46Recompute a run's review gate from its page results and persist it. Returns the new state. Call this after any approval mutation.
async function recomputeRunReviewState(testRunId: string): Promise<VisualReviewState>apps/api/src/services/ReviewService.ts:56Promote one approved PageResult to the current baseline and append history.
async function upsertBaselineFromResult( suite: any, result: any, opts: UpsertBaselineOpts =apps/api/src/services/ReviewService.ts:84Recompute and persist a run's status/reviewState/metadata from its PageResults. Best-effort updates the PR GitHub check to match. Never throws on GitHub errors.
async function finalizeRunOutcome(testRunId: string): Promise<void>apps/api/src/services/RunOutcomeService.ts:26Validate that the suite has tracked pages, create a TestRun, and enqueue it. Throws `badRequest` (handled by the global error handler) when there's nothing to diff or the target URL is invalid.
async function startSuiteRun( testSuiteId: string, opts: StartSuiteRunOptions =apps/api/src/services/RunService.ts:38Discovers crawlable pages for one site using sitemap data, links and a Playwright fallback for client-rendered pages.
class SiteCrawlerapps/api/src/services/SiteCrawler.ts:58