1---2name: faasjs-api-jobs3description: 'Use when building or reviewing FaasJS backend APIs and jobs: .api.ts files, defineApi, zod params schemas, HttpError, HTTP helpers, middleware/staticHandler, .job.ts files, defineJob, typed job paths and params, enqueueJob including transaction-coupled enqueueing, cron schedulers, retries, leases, workers, discovery, and job tests.'4metadata:5 source: https://skillmd.com/skills/faasjs/faasjs-api-jobs6---78# FaasJS API And Jobs910## Default Workflow11121. Keep API and job files inside the feature slice that owns the behavior.132. Define external input schemas at the boundary and keep business input visible as `params.key`.143. Use `HttpError` with explicit status codes for expected API failures; reserve plain `Error` for internal failures.154. Use injected HTTP helpers for cookies, sessions, headers, status, body, and content type.165. Treat jobs as at-least-once execution, make enqueueing explicit, and keep generated paths aligned with runtime discovery.1718## Load These References1920- `.api.ts`, `defineApi`, schemas, `params`, errors, injected fields, and type generation: `references/guidelines/define-api.md`.21- Cookies, sessions, response helpers, and HTTP plugin config: `references/guidelines/http-plugin.md`.22- Static file serving and middleware: `references/guidelines/middleware.md`.23- `.job.ts`, `defineJob`, `enqueueJob`, process ownership, and transaction-coupled enqueueing: `references/guidelines/jobs.md`.24- Generated job paths, params types, typegen, duplicate paths, and discovery roots: `references/guidelines/job-types-and-paths.md`.25- Cron expressions, scheduler deduplication, retries, attempts, and lease expiry: `references/guidelines/job-scheduling-and-retries.md`.26- Direct handler, queue, worker, scheduler, transaction, type, and discovery tests: `references/guidelines/job-testing.md`.2728## Gotchas2930- Destructure only the top-level handler context, such as `handler({ params })`; do not destructure business fields from `params`.31- Run `npx faas types` after adding, renaming, moving, or removing `.api.ts` or `.job.ts` files; ordinary handler edits do not change path declarations.32- Do not cast dynamic strings to generated job paths or keep transaction clients after their callbacks.33- Check user, tenant, organization, project, role, or permission scope before reading or mutating data.34- Do not log secrets, tokens, passwords, cookies, full sensitive payloads, or unredacted third-party responses.3536## Validation3738- Run focused API or job tests with `vp test <pattern>`.39- Run `npx faas types` after API or job path topology changes.40- Run `vp check --fix` before handoff when backend files changed.