Hiring
Jobs and applications on a pipeline per job, candidates from config.recordTypes, scorecards per stage, interviews, and hire, reject and withdraw events for the app to act on.
hiring is an applicant tracking system on the pipelines foundation. A job is open or closed, each job has its own pipeline of stages, and an application moves a candidate through it, collecting interviews and scorecards on the way, until it ends hired, rejected or withdrawn. A candidate is any record in config.recordTypes, a parties person by default, so a candidate who applies twice is one record with two applications.
Reading needs hiring.read, moving applications, scheduling and scoring needs hiring.write, and jobs need hiring.manage. Admins get every permission and members none: give recruiters a role with hiring.read and hiring.write. An interviewer on an interview reads it and scores the application without those permissions.
Some actions take their own key when you set one, and fall back otherwise: permissions.create gates apply (the write key without it), permissions.score gates submitting a scorecard (the write key), and permissions.jobsCreate and permissions.jobsUpdate gate creating and changing a job in saveJob (the manage key).
better-supabase add hiringThe module needs tenant, access, subjects and pipelines. Installing it binds the application type in the pipelines module with one pipeline per job (scope: "job_id"):
| Category | Outcome | Default stages |
|---|---|---|
active | open | Applied, Screening, Interview, Offer |
hired | success | Hired |
rejected | failure | Rejected |
withdrawn | failure | Withdrawn |
Each job's first application seeds its pipeline; an admin adds or renames stages per job with the pipelines client. The category sets the application's state.
Server code calls the hiring instance on db, in the caller's organization. With gen.hooks set, better-supabase gen writes the hooks:
export const { useList: useHiring } = defineDataHooks(
"hiring",
(db: AppDb) => db.hiring,
);import { createHiring } from "better-supabase/blocks/hiring";
const job = await db.hiring
.saveJob(organizationId, {
title: "Backend engineer",
location: "Utrecht",
status: "open",
})
.orThrow();
const application = await db.hiring
.apply(job.id, { id: personId }, { source: "referral" })
.orThrow();
await db.hiring
.scheduleInterview(application.id, {
startsAt,
endsAt,
interviewerIds: [engineerId],
kind: "technical",
})
.orThrow();"use client";
import { useHiring } from "@/lib/supabase/hooks";
const rows = useHiring({ limit: 50 });Your own fields
Columns you add to jobs with alter table in your own schema files are fields of the block (details):,
keyed by column name with their SQL type. saveJob writes them from fields and returns them under fields; a not null column without a default goes into the insert that creates the job. Pass a
Standard Schema as fields to type them,
parse them on reads and validate them on writes; a bad value is a
validation error before anything reaches the database (see
extending blocks):
import { z } from "zod";
const hiring = createHiring({
transport,
fields: z.object({ region: z.enum(["emea", "amer", "apac"]) }),
});
await hiring.saveJob(organizationId, {
title: "Engineer",
fields: { region: "emea" },
});A column you add to the applications table does the same: apply writes them from fields in the insert that
creates the application, and every application the client returns carries
them under fields:
await hiring
.apply(job.id, { id: personId }, { fields: { referral: "Sam" } })
.orThrow();Applications
apply(jobId, candidate, { source, ownerId }) adds a candidate to an open job (JOB_OPENING_NOT_OPEN); applying again returns the same application. The candidate must be in the organization and readable by the caller (HIRING_CANDIDATE_FORBIDDEN). Move it between stages with a stage update or rank on a board, as any pipeline record.
hire(id), reject(id, reason) and withdraw(id) move the application to its job pipeline's first stage of that category. Hiring stamps hiredAt and records application.hired with the candidate: call employees.fromApplication from that event, which makes the employee once and links it with a created_from relation, or create your own from an after_application_hire hook in the same transaction.
The job board
hiring.board({ organizationId, jobId }) reads a job and its applications grouped by stage in one call, and returns not_found for a job the caller can't see. It runs jobs and pipeline together, so each keeps its own hooks and row level security.
const { job, stages } = await db.hiring
.board({ organizationId, jobId })
.orThrow();Lists and the pipeline
jobs({ organizationId, status }) returns the organization's jobs, newest first, and status keeps one of draft, open and closed. applications({ jobId, state }) returns a job's applications in board order. applicationsForJobs({ jobIds, state }) returns the applications of many jobs in one call, with the jobs in the order you give and each job's applications in board order; use it for a board of every open job instead of one applications call per job. pipeline({ jobId, state }) groups them by stage in the same order; it groups by stageId only, so read stage names and order from the pipelines block. Applications that have no stage yet come back in a group whose stageId is undefined.
close({ organizationId, jobId }) saves the job with status: "closed", which stamps closedAt and records job_opening.closed. Closing a closed job changes nothing.
Interviews and scorecards
scheduleInterview records an interview with its interviewers, who can then read it. score(id, { rating, recommendation, notes }) saves the caller's scorecard at the application's current stage: a rating from 1 to ratingMax (4 unless set) and a recommendation from strong_no to strong_yes. Scoring again at the same stage replaces it. detail(id) returns the application with its scorecards, its interviews and the average rating.
Over your own tables
Every option below is opt-in: a config without them renders the same SQL as before. Together they let the block run over an applicant tracker whose tables already exist (see your own schemas).
One candidate type with a typed id
Map columns.applications.candidateType to null when every application points at one record type through a typed column, such as a candidate_id uuid foreign key. The candidate type is then always options.candidate, which must be in config.recordTypes; apply refuses another type with HIRING_CANDIDATE_TYPE_UNSUPPORTED. The id is written and compared as the column's own type, and reads and event payloads still carry candidateType (the configured type) and candidateId as text. The block's own table drops the type column and keys applications on job and candidate.
Stages per job in your table
options.stages is "pipelines" by default: each job gets a pipeline in the pipelines module. Set it to your table of job stages instead and the job is the pipeline:
stages: {
table: "public.job_stages",
job: "job_id",
rank: "position",
hired: "is_hired",
rejected: { column: "system_key", value: "rejected" },
}id defaults to id, and archivedAt names a column whose non-null value hides a stage. hired, rejected and withdrawn each name a boolean column, or a column and the value that marks the stage. A new application starts on its job's first stage that marks none of them, a move to another job's stage fails with HIRING_STAGE_INVALID, and a move onto a marked stage sets the state (back on an unmarked stage it is active again, unless the state is one no stage marks, which stays), so application.hired follows a plain stage update too. hire, reject and withdraw move the application to the job's first marked stage when there is one and set the state either way. In this mode the block binds nothing in the pipelines module, columns.applications.pipeline can be null, and the board index is on job, stage and rank. Mapping pipeline to null without options.stages keeps applications off any pipeline: closing sets the state only.
The block keeps the pipelines module for the default mode rather than making its pipelines table optional with the job as the pipeline row: stage tables that apps already have mark outcomes with flags or keys, not with the pipelines module's categories and outcomes, and every pipelines function (boards, stats, history, transitions) assumes a pipeline row.
Interviewers in a junction table
Map tables.interviewers (interview, user, and an optional tenant) to keep interviewers as rows instead of an array, and map columns.interviews.interviewers to null when the interviews table has no array column. scheduleInterview writes one row per interviewer, and the interviews read policy, the interviewer check of score and detail read the table. Without either, scheduleInterview refuses interviewers with HIRING_INTERVIEWERS_UNSUPPORTED. The block creates the table under the name you map when your schema lacks it.
Scorecards
options.ratingMax sets the highest scorecard rating (default 4), so 5 scores from 1 to 5. options.scorecardKey: "application" keeps one scorecard per reviewer per application instead of one per stage; a scorecards table without a stage column works that way too. columns.scorecards.recommendation can be null, and then score refuses a recommendation with HIRING_RECOMMENDATION_UNSUPPORTED. Map tables.scorecardScores (scorecard, criterion, score, optional tenant and notes) to store a score per criterion: submit_scorecard takes an extra scores jsonb argument, a list of { criterion, score, notes } that replaces the card's scores (HIRING_SCORES_INVALID for a value the columns reject), and detail returns them as scores on each scorecard:
await hiring.score(applicationId, {
rating: 4,
scores: [
{ criterion: "craft", score: 5 },
{ criterion: "communication", score: 3 },
],
});Turning tables.scorecardScores off again leaves the five-argument submit_scorecard in the database: drop it in the same migration.
Hiring manager and typed columns
options.hiringManager: "employee" makes jobs.hiringManager an employee id: saveJob writes hiringManagerId as the column's type and, with the employees block installed, refuses an id that is no employee of the organization (HIRING_HIRING_MANAGER_INVALID). jobs.employmentType, applications.source and interviews.kind accept value maps like the state columns, so an enum column works once values.<table>.<column> has an entry ({} casts without renaming).
A full config
export default defineConfig({
records: {
candidate: {
table: "candidates",
tenant: "organization_id",
idType: "uuid",
},
},
blocks: {
hiring: {
options: {
candidate: "candidate",
stages: {
table: "public.job_stages",
job: "job_id",
rank: "position",
hired: "is_hired",
rejected: { column: "system_key", value: "rejected" },
},
scorecardKey: "application",
hiringManager: "employee",
},
tables: {
jobs: "public.jobs",
applications: "public.applications",
scorecards: "public.scorecards",
interviews: "public.interviews",
interviewers: "public.interview_interviewers",
scorecardScores: "public.scorecard_scores",
},
columns: {
jobs: { tenant: "organization_id", hiringManager: "hiring_manager_id" },
applications: {
tenant: "organization_id",
candidateType: null,
pipeline: null,
},
scorecards: {
tenant: "organization_id",
recommendation: null,
stage: null,
},
interviews: { tenant: "organization_id", interviewers: null },
interviewers: { tenant: null },
scorecardScores: { tenant: null, criterion: "criterion" },
},
values: {
jobs: { employmentType: {} },
applications: { source: {} },
interviews: { kind: {} },
},
},
},
});Events
| Event | Data |
|---|---|
job_opening.opened, job_opening.closed | organizationId, jobId, title |
application.created, application.hired, application.rejected, application.retracted | organizationId, applicationId, subjectType, subjectId, jobId, candidateType, candidateId, reason |
scorecard.submitted, interview.scheduled | the same, with reviewerId and recommendation, or interviewId and startsAt |
Wire it to ReUI
The ReUI Recruiting Pipeline board reads its columns from the job's pipeline board and moves cards with rank.move("application", id, { group: stageId }). Show a card's match score from detail(id).averageRating, and its interview date from interviews.
Errors
| Hint | Cause |
|---|---|
HIRING_FORBIDDEN | the caller lacks hiring.manage |
JOB_OPENING_INVALID | a job needs a title and a status of draft, open or closed |
JOB_OPENING_NOT_FOUND | no such job the caller can change |
JOB_OPENING_NOT_OPEN | the job isn't open |
HIRING_CANDIDATE_FORBIDDEN | the candidate is unknown or unreadable |
HIRING_APPLICATION_NOT_FOUND | no application the caller can change or review |
HIRING_OUTCOME_INVALID | close as hired, rejected or withdrawn |
HIRING_STAGE_MISSING | the job's pipeline has no stage of that category |
HIRING_SCORECARD_INVALID | a rating and a recommendation |
HIRING_INTERVIEW_INVALID | an interview starts before it ends |
HIRING_CANDIDATE_TYPE_UNSUPPORTED | applications take candidates of options.candidate only |
HIRING_STAGE_INVALID | the stage is not an active stage of the application's job |
HIRING_INTERVIEWERS_UNSUPPORTED | the interviews table keeps no interviewers |
HIRING_RECOMMENDATION_UNSUPPORTED | the scorecards table has no recommendation column |
HIRING_SCORES_INVALID | scores must be a list of distinct criteria with valid scores |
HIRING_HIRING_MANAGER_INVALID | the hiring manager is no employee of the organization |
Without the client
db.hiring is this client. Code that does not go through bsb.db() builds it with a transport and an organization id:
import { createHiring } from "better-supabase/blocks/hiring";
const hiring = createHiring({ transport });
const job = await hiring
.saveJob(organizationId, {
title: "Backend engineer",
location: "Utrecht",
status: "open",
})
.orThrow();
const application = await hiring
.apply(job.id, { id: personId }, { source: "referral" })
.orThrow();
await hiring
.scheduleInterview(application.id, {
startsAt,
endsAt,
interviewerIds: [engineerId],
kind: "technical",
})
.orThrow();Last updated on
Time tracking
Timers and logged time on any record, one running timer per member and no overlapping entries enforced by Postgres, weekly timesheets approved through the approvals module, locked weeks, and a weekly grid shape for a data grid.
Employees
Employees with or without an account, a manager, team and status, an org chart, offboarding, and private details and contracts behind employees.view_sensitive.