@focus-reactive/payload-plugin-scheduling

中文文档
1.3.0发布于 2026/06/19MITTypeScriptES Module零依赖构建来源已验证近 30 天下载 2613

Schedule publication plugin for Payload CMS

原始使用文档
文档目录12 节
  1. AI Integration Prompt
  2. How It Works
  3. Installation
  4. Quick Start
  5. Step 1 — Register the plugin
  6. Step 2 — Set up a cron
  7. Configuration Reference
  8. Options
  9. The Run Endpoint
  10. Environment Variables
  11. Versioning & Drafts Behaviour
  12. Exports Reference

@focus-reactive/payload-plugin-schedule-publication

Scheduled publication plugin for Payload CMS v3. Set a future publish date on any draft document and it goes live automatically — no manual publishing required.

The plugin enables Payload's built-in schedulePublish drafts feature on selected collections and globals, routes the resulting jobs through an isolated queue, and exposes a Bearer-token-protected endpoint that your cron job pings to drain the queue.


AI Integration Prompt

Copy and paste this prompt into your AI assistant (Cursor, Claude, etc.) to integrate the plugin into an existing Payload project.

I want to add scheduled publication to my Payload CMS v3 project using @focus-reactive/payload-plugin-schedule-publication.

## How it works

The plugin:
1. Enables `drafts.schedulePublish: true` on every collection/global you configure — this makes Payload
   show a "Schedule Publish" date-time picker in the admin sidebar.
2. Routes all `schedulePublish` jobs to an isolated queue (default: "scheduled-publish") so they don't
   interfere with other background jobs.
3. Registers a GET /api/scheduled-publish/run endpoint that, when hit by a cron, calls
   payload.jobs.run({ queue }) to process all due scheduled-publish jobs.
4. The endpoint requires an Authorization: Bearer <secret> header to prevent unauthorized triggers.

## Installation

pnpm add @focus-reactive/payload-plugin-schedule-publication

## Step 1 — Register the plugin in payload.config.ts

import { schedulePublicationPlugin } from '@focus-reactive/payload-plugin-schedule-publication'

// Inside buildConfig({ plugins: [...] })
schedulePublicationPlugin({
  collections: ['pages', 'posts'],  // slugs of collections to enable scheduled publishing on
  globals: ['site-settings'],       // slugs of globals to enable scheduled publishing on (optional)
  secret: process.env.CRON_SECRET!, // any env var you choose — must match the Bearer token your cron sends
})

## Step 2 — Set up a cron to trigger the endpoint

The endpoint GET /api/scheduled-publish/run must be called at least as often as your finest
scheduling granularity (e.g. every minute for minute-level precision).

Pass the secret as a Bearer token:
  Authorization: Bearer <your-secret>

### Vercel (vercel.json)

{
  "crons": [
    {
      "path": "/api/scheduled-publish/run",
      "schedule": "* * * * *"
    }
  ]
}

Note: Set CRON_SECRET in your Vercel project environment variables. Vercel automatically sends
this value in the Authorization header when triggering your cron. Pass it directly to the
plugin's secret option: secret: process.env.CRON_SECRET!

### Any HTTP client / external cron service

curl -X GET https://your-cms.com/api/scheduled-publish/run \
  -H "Authorization: Bearer YOUR_SECRET"

## Important notes

- collections and globals receive `versions.drafts.schedulePublish: true` automatically.
  If a collection already has a versions/drafts config it is preserved and merged.
- The queue option (default: "scheduled-publish") isolates schedule jobs. Change it only if
  you have a naming conflict with other queues.
- Never expose the secret in client-side code. Store it in an environment variable.

How It Works

Editor sets "Schedule Publish" date in Payload Admin
              ↓
Payload creates a schedulePublish job in the jobs collection
              ↓
         [ queue: "scheduled-publish" ]
              ↓
Cron calls GET /api/scheduled-publish/run  (every minute)
              ↓
Plugin endpoint: payload.jobs.run({ queue: "scheduled-publish" })
              ↓
Due jobs are processed → documents are published

The plugin hooks into Payload's own schedulePublish task — it does not implement its own publish logic. It simply enables the feature on your chosen collections/globals, routes the jobs to a dedicated queue, and provides the HTTP trigger endpoint.


Installation

pnpm add @focus-reactive/payload-plugin-schedule-publication

Peer dependencies: payload ^3.0.0


Quick Start

Step 1 — Register the plugin

// payload.config.ts
import { buildConfig } from "payload";
import { schedulePublicationPlugin } from "@focus-reactive/payload-plugin-schedule-publication";

export default buildConfig({
  plugins: [
    schedulePublicationPlugin({
      collections: ["pages"],
      secret: process.env.CRON_SECRET!,
    }),
  ],
});

The plugin injects into every configured collection and global:

  • versions.drafts.schedulePublish: true — enables the "Schedule Publish" date picker in the admin sidebar
  • All schedulePublish jobs are routed to the "scheduled-publish" queue via a beforeChange hook on the jobs collection

Step 2 — Set up a cron

The endpoint GET /api/scheduled-publish/run must be called periodically (at least as often as your finest scheduling granularity). It processes all due jobs in the queue and returns { ok: true }.

Vercel

Add a cron to vercel.json at the root of your project:

{
  "crons": [
    {
      "path": "/api/scheduled-publish/run",
      "schedule": "* * * * *"
    }
  ]
}

Vercel automatically sends CRON_SECRET as Authorization: Bearer $CRON_SECRET when triggering crons. Set CRON_SECRET in your Vercel project settings and pass it directly to the plugin's secret option.

External cron / curl

curl -X GET https://your-cms.com/api/scheduled-publish/run \
  -H "Authorization: Bearer YOUR_SECRET"

Node.js (node-cron)

import cron from "node-cron";

cron.schedule("* * * * *", async () => {
  await fetch("http://localhost:3000/api/scheduled-publish/run", {
    headers: {
      Authorization: `Bearer ${process.env.CRON_SECRET}`,
    },
  });
});

Configuration Reference

interface SchedulePublicationPluginConfig {
  /**
   * Collection slugs to enable scheduled publishing for.
   * @example ['pages', 'posts']
   */
  collections?: string[];

  /**
   * Global slugs to enable scheduled publishing for.
   * @example ['site-settings']
   */
  globals?: string[];

  /**
   * Queue name to isolate schedulePublish jobs.
   * When set, jobs are routed to this queue and the /scheduled-publish/run
   * endpoint will only process this queue.
   * @default "scheduled-publish"
   */
  queue?: string;

  /**
   * Bearer token used to authenticate calls to the
   * GET /api/scheduled-publish/run endpoint.
   */
  secret: string;
}

Options

OptionTypeRequiredDefaultDescription
collectionsstring[]No[]Collection slugs to enable scheduled publishing on
globalsstring[]No[]Global slugs to enable scheduled publishing on
queuestringNo"scheduled-publish"Queue name for isolating scheduled publish jobs
secretstringYes—Bearer token required to call the run endpoint

The Run Endpoint

GET /api/scheduled-publish/run

Triggers processing of all due jobs in the scheduled-publish queue.

Authentication: Authorization: Bearer <secret>

Success response:

{ "ok": true }

Error responses:

{ "error": "Unauthorized" }   // 401 — missing or wrong token
{ "error": "Internal server error" }  // 500 — jobs runner threw

Environment Variables

The plugin's secret option accepts any environment variable — use whatever name fits your platform. On Vercel, the natural choice is CRON_SECRET, which Vercel automatically sends as the Authorization: Bearer header when triggering crons.

// On Vercel
secret: process.env.CRON_SECRET!

// On any other platform
secret: process.env.MY_CRON_SECRET!

Versioning & Drafts Behaviour

The plugin calls injectSchedulePublishToVersions on each configured collection/global config:

  • If the collection has no versions config → adds { drafts: { schedulePublish: true } }
  • If versions is true or has drafts: true → replaces drafts with { schedulePublish: true }
  • If versions.drafts is an object → merges schedulePublish: true into it, preserving other draft options (e.g. autosave)

Your existing versions/drafts configuration is never discarded.


Exports Reference

Import pathExports
@focus-reactive/payload-plugin-schedule-publicationschedulePublicationPlugin, SchedulePublicationPluginConfig

版本与发布记录

@focus-reactive/payload-plugin-scheduling 共发布 5 个版本,首次发布于 2026/03/18;过去 12 个月发布了 5 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.3.0latest2026/06/194 个月前
1.2.02026/05/016 个月前
1.1.02026/03/317 个月前
1.0.12026/03/187 个月前
1.0.02026/03/187 个月前

关于 @focus-reactive/payload-plugin-scheduling 的常见问题

@focus-reactive/payload-plugin-scheduling 是什么?

Schedule publication plugin for Payload CMS

如何安装 @focus-reactive/payload-plugin-scheduling?

在项目目录运行 npm install @focus-reactive/payload-plugin-scheduling,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:payload(^3.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@focus-reactive/payload-plugin-scheduling 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@focus-reactive/payload-plugin-scheduling 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@focus-reactive/payload-plugin-scheduling 可以商用吗?

@focus-reactive/payload-plugin-scheduling 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@focus-reactive/payload-plugin-scheduling 的下载量有多少?

根据 npm 官方下载统计,@focus-reactive/payload-plugin-scheduling 在 2026/10/15 – 2026/11/13 这 30 天内被下载 2,613 次,日均约 87 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@focus-reactive/payload-plugin-scheduling 还在维护吗?

最新版本 1.3.0 发布于 2026/06/19(4 个月前);至今共发布 5 个版本,其中过去 12 个月发布了 5 个;首次发布于 2026/03/18。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。