import type { Payload } from "payload"; import { PayloadJobQueue } from "../../jobs/payload-job-queue"; import { buildPurgeHandler, type PayloadPurgeApi } from "./retention-purge.job"; /** * Minimal shape of a Payload job-task definition — enough for * `payload.config.ts` `jobs.tasks` composition without dragging the full * generated TaskConfig generics through core-shared. */ export type RetentionPurgeTask = { slug: string; handler: (args: { req: { payload: Payload } }) => Promise<{ output: Record; }>; }; /** * Build the Payload job-task definition for one collection's retention purge * (audit finding A3): `registerRetentionPurgeJobs` enqueues * `retention-purge--` tasks at boot, and this definition is what makes * Payload able to RUN them. Everything the handler needs comes from the * running instance on `req.payload` (config, local API, job queue for the * self-re-enqueue), so the task can be declared at config-composition time * with no bootstrapping order problems. */ export function buildRetentionPurgeTask( collectionSlug: string, ): RetentionPurgeTask { return { slug: `retention-purge--${collectionSlug}`, handler: async ({ req }) => { const payload = req.payload; const run = buildPurgeHandler(collectionSlug, { queue: new PayloadJobQueue(payload), config: payload.config, getPayload: async () => payload as unknown as PayloadPurgeApi, }); await run(); return { output: {} }; }, }; }