focusreactive

payload plugin netlify deploy

by focusreactive
payload-plugins
Publishing workflow
v3
^3.90.0
MIT

Overview

Summary generated from the README

Adds a Deploy button beside Save on chosen collections, and optionally in the admin top bar, to start Netlify builds from Payload. It shows site status, streams the build log, lets editors open a preview and publish it, and allows one build per site at a time. It requires Payload 3.90 or later, Node 22 or later, the companion guard plugin with an access policy, and a Netlify personal access token.

Features

  • Deploy button beside Save or in the admin top bar with status dot and pending change count
  • Live Netlify build log streamed into a drawer, with Netlify's failure reason shown
  • Preview a build on its own URL, then publish, rebuild or cancel it
  • One build at a time per site, including builds started outside Payload
  • Per-document Netlify site resolution for CMS setups feeding many sites
  • Five capabilities (view status, view log, build, discard, publish) granted through the access policy

Use cases

  • Let editors rebuild and publish a Netlify-hosted site without asking a developer
  • Review a built preview before it goes live on a site with locked auto-publishing
  • Run one CMS that feeds several Netlify sites, each built from its own documents

From the author

Publish button for Payload CMS sites on Netlify: build from the admin, stream the build log, preview a deploy and publish it, one build at a time per site

Installation

npm i @focus-reactive/payload-plugin-netlify-deploy

37

Stars

5

Forks

33

Open Issues

Today

Last Updated

19

Weekly Downloads

v2.0.1

npm Version

224.0 KB

Unpacked Size

1

Dependencies

Repository stars

37+22 since Sep 6

Show data
Repository stars by day (UTC)
DateStars
Dec 5, 202637
Dec 4, 202637
Dec 3, 202637
Dec 2, 202637
Dec 1, 202636
Nov 30, 202635
Nov 29, 202635
Nov 28, 202634
Nov 27, 202634
Nov 26, 202634
Nov 25, 202634
Nov 24, 202634
Nov 23, 202634
Nov 22, 202634
Nov 21, 202634
Nov 20, 202633
Nov 19, 202632
Nov 18, 202632
Nov 17, 202632
Nov 16, 202632
Nov 15, 202632
Nov 14, 202632
Nov 13, 202632
Nov 12, 202632
Nov 11, 202632
Nov 10, 202632
Nov 9, 202631
Nov 8, 202631
Nov 7, 202631
Nov 6, 202631
Nov 5, 202631
Nov 4, 202630
Nov 3, 202630
Nov 2, 202630
Nov 1, 202630
Oct 31, 202630
Oct 30, 202630
Oct 29, 202630
Oct 28, 202630
Oct 27, 202630
Oct 26, 202630
Oct 25, 202630
Oct 24, 202629
Oct 23, 202629
Oct 22, 202629
Oct 21, 202629
Oct 20, 202629
Oct 19, 202629
Oct 18, 202629
Oct 17, 202627
Oct 16, 202626
Oct 15, 202626
Oct 14, 202626
Oct 13, 202625
Oct 12, 202625
Oct 11, 202625
Oct 10, 202625
Oct 9, 202625
Oct 8, 202625
Oct 7, 202625
Oct 6, 202624
Oct 5, 202624
Oct 4, 202624
Oct 3, 202623
Oct 2, 202622
Oct 1, 202622
Sep 30, 202620
Sep 29, 202620
Sep 28, 202620
Sep 27, 202620
Sep 26, 202619
Sep 25, 202618
Sep 24, 202618
Sep 23, 202618
Sep 22, 202618
Sep 21, 202618
Sep 20, 202618
Sep 19, 202618
Sep 18, 202618
Sep 17, 202618
Sep 16, 202618
Sep 15, 202618
Sep 14, 202618
Sep 13, 202617
Sep 12, 202617
Sep 11, 202617
Sep 10, 202616
Sep 9, 202616
Sep 8, 202616
Sep 7, 202615
Sep 6, 202615

Shared by 15 plugins in focusreactive/payload-plugins.

npm weekly downloads

22−231 since Oct 1

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 5, 202622
Dec 4, 202621
Dec 3, 202624
Dec 2, 202628
Dec 1, 202626
Nov 30, 202637
Nov 29, 202634
Nov 28, 202637
Nov 27, 202637
Nov 26, 202636
Nov 25, 202633
Nov 24, 202635
Nov 23, 202623
Nov 22, 202625
Nov 21, 202619
Nov 20, 202631
Nov 19, 202628
Nov 18, 202636
Nov 17, 202637
Nov 16, 202643
Nov 15, 202655
Nov 14, 2026117
Nov 13, 2026127
Nov 12, 2026140
Nov 11, 2026150
Nov 10, 2026172
Nov 9, 2026175
Nov 8, 2026166
Nov 7, 2026122
Nov 6, 2026284
Nov 5, 2026310
Nov 4, 2026295
Nov 3, 2026271
Nov 2, 2026269
Nov 1, 2026265
Oct 31, 2026248
Oct 30, 202663
Oct 29, 202621
Oct 28, 202616
Oct 27, 202620
Oct 26, 202613
Oct 25, 202615
Oct 24, 202640
Oct 23, 202639
Oct 22, 202642
Oct 21, 202649
Oct 20, 202644
Oct 19, 202652
Oct 18, 202660
Oct 17, 202639
Oct 16, 202651
Oct 15, 202661
Oct 14, 2026127
Oct 13, 2026146
Oct 12, 2026145
Oct 11, 2026153
Oct 10, 2026173
Oct 9, 2026205
Oct 8, 2026395
Oct 7, 2026575
Oct 6, 2026553
Oct 5, 2026545
Oct 4, 2026525
Oct 3, 2026500
Oct 2, 2026456
Oct 1, 2026253

Each point is npm's rolling 7-day download count.

Health Score

65/100Good

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/1177993877-payload-plugin-netlify-deploy.svg)](https://payloaddirectory.dev/plugins/1177993877-payload-plugin-netlify-deploy)
HTML
<a href="https://payloaddirectory.dev/plugins/1177993877-payload-plugin-netlify-deploy"><img src="https://payloaddirectory.dev/badge/1177993877-payload-plugin-netlify-deploy.svg" alt="Payload Directory"></a>
Updated Dec 5, 2026Created Mar 10, 2026Published Dec 4, 2026

README

@focus-reactive/payload-plugin-netlify-deploy

npm

A Deploy button for Payload CMS sites hosted on Netlify: build the site from the admin, watch the build log, check a preview and publish it, without leaving the document you just saved.

A site on Netlify only shows what Payload holds after it is rebuilt. Editors usually have to ask a developer, trigger a build hook or run a Slack command, and then wait without seeing whether the build worked. This plugin puts that step where editors already are, and works for one site as well as for a CMS that feeds dozens.

The plugin is built on @focus-reactive/payload-plugin-guard. Your project's access policy file decides who may see the status, read build logs, start builds, discard previews and publish.

Requirements: Payload ^3.90.0, @focus-reactive/payload-plugin-guard, and a config wrapped in withAccessPolicy.


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 a Netlify deploy button to my Payload CMS v3 project using
@focus-reactive/payload-plugin-netlify-deploy. Follow these steps in order, and stop to ask me where a step says so.

## Rules you must follow

- Never write an access rule that admits every logged-in user: no `Boolean(req.user)`, no `() => true`,
  no `({ req }) => !!req.user`. A rule names a role, or it is `nobody`.
- Do not invent roles. Ask me which roles get each capability.
- Write every policy entry by hand in `src/access.policy.ts`, and grant each capability and each
  collection right explicitly to the roles I name. Nothing is open by default.
- When the boot or a request fails, fix the cause or ask me. Never use `anyone`, a looser gate,
  `overrideAccess` or a removed or disabled check to make an error go away.
- Do not add `overrideAccess: true` anywhere, and do not add `access` to the plugin's collections.
- The Netlify token goes only into the server's environment, never into a `NEXT_PUBLIC_` variable.

## How it works

The plugin adds a Deploy button beside Save on the collections I list, and optionally in the admin's
top bar. Its endpoints live under `/api/netlify-deploy/`. It declares five capabilities that the
project grants in its access policy, none with a default:
- `viewStatus`: see the site's state, its recent deploys and who started them.
- `viewLog`: read a build's log, which can contain whatever the build prints.
- `build`: start a build.
- `discard`: cancel a running build or delete a finished preview.
- `publish`: put a finished preview live.
On a document's button, every action also needs read access to that document.
The plugin owns two collections, `netlify-deploy-locks` and `netlify-deploy-builds`, that only it writes.

## Step 1: install

pnpm add @focus-reactive/payload-plugin-netlify-deploy @focus-reactive/payload-plugin-guard

Check that `payload` is 3.90 or later; if it is not, upgrade it first.

## Step 2: ask me about roles

Look at the auth collection named in `admin.user` and the roles it has.
Ask me, one question per capability: "Which roles may see the deploy status?", "Which roles may read
build logs?", "Which roles may start a build?", "Which roles may discard a preview or cancel a build?",
"Which roles may publish to production?".
Wait for my answers. Write each answer as a gate in the policy file in step 3.

## Step 3: the access policy file

Open `src/access.policy.ts`, or create it if the project has none, following the guard README
(`defineAccessPolicy`, `gate`, `filter`, `nobody`, checked with `satisfies AccessPolicy<Config>`).
If you create it, every collection and global of the config needs an entry: move each existing
`access` of the project into the file, and ask me for every rule you cannot read from the code.
Add these entries for this plugin:

collections: {
  "netlify-deploy-locks": { create: nobody, read: nobody, update: nobody, delete: nobody },
  "netlify-deploy-builds": { create: nobody, read: nobody, update: nobody, delete: nobody },
},
plugins: {
  "netlify-deploy": {
    viewStatus: <gate from my first answer>,
    viewLog: <gate from my second answer>,
    build: <gate from my third answer>,
    discard: <gate from my fourth answer>,
    publish: <gate from my fifth answer>,
  },
},

## Step 4: register the plugin and wrap the config

// payload.config.ts
import { buildConfig } from 'payload'
import { withAccessPolicy } from '@focus-reactive/payload-plugin-guard'
import { netlifyDeployPlugin } from '@focus-reactive/payload-plugin-netlify-deploy'
import { accessPolicy } from './access.policy'

export default withAccessPolicy(
  accessPolicy,
  buildConfig({
    // ...the existing config
    plugins: [
      netlifyDeployPlugin({
        token: process.env.NETLIFY_AUTH_TOKEN,
        site: '<the Netlify site id or domain>',
        collections: ['pages'],
        access: accessPolicy.plugins['netlify-deploy'],
      }),
    ],
  })
)

Ask me for the site and the collections. Add `NETLIFY_AUTH_TOKEN` to `.env` with a placeholder and
tell me to fill it in. Run `payload generate:types` and `payload generate:importmap`, then start the app.
A missing or wrong policy entry stops the boot with a list of what to fix.
Fix each item; never loosen a rule to make an error go away.

## Step 5: verify, and show me the output

With the app running, send each request and show me the status code.
Every one of them must be refused. If one succeeds, the policy is wrong: stop and tell me.

1. Anonymous status, expect 401:
   curl -i http://localhost:3000/api/netlify-deploy/status
2. Anonymous build, expect 401:
   curl -i -X POST http://localhost:3000/api/netlify-deploy/build -H 'Content-Type: application/json' -d '{}'
3. A build with the session cookie of a user whose role may not build, expect 403.
4. A publish with the session cookie of a user whose role may not publish, expect 403:
   curl -i -X POST http://localhost:3000/api/netlify-deploy/publish -H 'Content-Type: application/json' -H 'Cookie: <cookie>' -d '{"deployId":"000000000000000000000000"}'
5. An admin's write to the plugin's collection, expect 403:
   curl -i -X POST http://localhost:3000/api/netlify-deploy-builds -H 'Content-Type: application/json' -H 'Cookie: <admin cookie>' -d '{}'

Then, as a user who may build, open a document of a listed collection and check that the Deploy button appears.

What it does

  • Deploy button beside Save: on every document of the collections you list, or in the admin's top bar for a single site. It shows the state of the site at a glance: a coloured dot, a label and the number of saved changes waiting to go live.
  • Statuses: the button and its drawer always say where the site is: Live, Not deployed, In queue (waiting for a free Netlify builder), Building, Preview ready, Build failed, Deploying. They update by themselves, and a toast tells the editor when a build is ready, has failed or went live, wherever they are in the admin.
  • Live build log: the Netlify log streams into the drawer while the site builds, with warnings and errors highlighted, and stays there after a failure. When a build fails, Netlify's own reason is shown above the log, word for word.
  • Preview before it goes live: on a site whose auto-publishing is locked, a build becomes a preview first. Open preview opens the built site on its own Netlify URL, Deploy makes it live, Build again builds a fresh preview after more edits (the old one stays on Netlify, no longer offered), and Cancel deletes it so nothing goes live. On a site that auto-publishes, the button builds and publishes in one go.
  • What changed: optionally, the list of documents saved since the live site was built, and on a preview, what that preview includes. The count sits on the button.
  • One build at a time: while any build of the site runs, started from the admin, a git push, a build hook or the Netlify UI, the button is locked and says so. Different sites build in parallel.
  • Cancel and history: a build started in Payload can be cancelled while it runs, or its preview deleted once it is ready. The last deploys are listed with who started them in Payload (or outside Payload), their state, when they ran and how long they took.
  • Unsaved changes warning: a build uses what is saved, so the drawer warns when the document has unsaved edits.
  • Many sites: each document can resolve to its own Netlify site, with a note of its own ("One site serves 4 editions…").
  • Roles: each action is a capability that your access policy grants to the roles you choose.
  • Hooks: onBuild and onPublish run on the server after a build starts or a preview is published, to tell a Slack channel, for instance.

Requirements

  • Payload 3.90 or later, React 19, and @focus-reactive/payload-plugin-guard.
  • Node 22 or later on the server that runs Payload: the build log is read over a WebSocket.
  • A site that builds on Netlify: a build command in its Netlify settings. A site built in another CI and uploaded with netlify deploy has no Netlify build for the button to start.
  • A Netlify account with access to that site.

Setup

1. Create a Netlify token

  1. In Netlify, open User settings → Applications → Personal access tokens (app.netlify.com/user/applications).
  2. Choose New access token, name it after the CMS (payload-admin), pick an expiry and generate it.
  3. Copy the token: Netlify shows it only once.

A personal access token can do whatever its owner can do in Netlify; it cannot be limited to one site. Create it from an account with the Developer role on the team and access to the sites the CMS builds, rather than from a team owner, and give it an expiry you will remember to renew.

2. Give the token to the CMS server

Add it to the environment of the server that runs Payload, not to the frontend, and never as a NEXT_PUBLIC_ variable:

# .env
NETLIFY_AUTH_TOKEN=your-token

Do the same on the CMS's host. On Vercel: Project → Settings → Environment Variables, add NETLIFY_AUTH_TOKEN, mark it Sensitive, select the environments that should build (Production, and Preview if preview deployments of the CMS may build too) and redeploy. Without the token every endpoint answers 500 and the button shows an error.

3. Install

pnpm add @focus-reactive/payload-plugin-netlify-deploy @focus-reactive/payload-plugin-guard

4. Grant the capabilities in your access policy

Ask yourself which roles get each capability; there is no default. The gates below are examples from a project with admin and editor roles.

// src/access.policy.ts
import { defineAccessPolicy, gate, nobody, type AccessPolicy } from "@focus-reactive/payload-plugin-guard";
import type { PayloadRequest } from "payload";
import type { Config } from "./payload-types";

const roles = (req: PayloadRequest): string[] =>
  req.user?.collection === "users" ? (req.user.roles ?? []) : [];
const isAdmin = gate(({ req }) => roles(req).includes("admin"));
const isEditor = gate(({ req }) => roles(req).some((role) => ["admin", "editor"].includes(role)));

const pluginOnly = { create: nobody, read: nobody, update: nobody, delete: nobody };

export const accessPolicy = defineAccessPolicy({
  collections: {
    // ...your collections
    "netlify-deploy-locks": pluginOnly,
    "netlify-deploy-builds": pluginOnly,
  },
  plugins: {
    "netlify-deploy": {
      viewStatus: isEditor,
      viewLog: isEditor,
      build: isEditor,
      discard: isEditor,
      publish: isAdmin,
    },
  },
}) satisfies AccessPolicy<Config>;

5. Register the plugin and wrap the config

One site:

// payload.config.ts
import { withAccessPolicy } from "@focus-reactive/payload-plugin-guard";
import { netlifyDeployPlugin } from "@focus-reactive/payload-plugin-netlify-deploy";
import { buildConfig } from "payload";
import { accessPolicy } from "./access.policy";

export default withAccessPolicy(
  accessPolicy,
  buildConfig({
    plugins: [
      netlifyDeployPlugin({
        token: process.env.NETLIFY_AUTH_TOKEN,
        site: "my-site.netlify.app", // the site id, or any of its domains
        collections: ["pages", "posts"], // the button beside Save
        header: true, // and in the admin's top bar
        access: accessPolicy.plugins["netlify-deploy"],
      }),
    ],
  })
);

A site per document: when one CMS feeds many sites, site is a function. It gets the document the button sits on and returns that document's Netlify site, or null where there is none, which hides the button. The plugin calls it only after it has read the document as the caller, so a caller cannot reach the site of a document they may not read. Read with overrideAccess: false inside it too:

netlifyDeployPlugin({
  token: process.env.NETLIFY_AUTH_TOKEN,
  collections: ["pages", "brands"],
  access: accessPolicy.plugins["netlify-deploy"],
  site: async ({ req, collection, id }) => {
    if (!collection || !id) return null;
    const doc = await req.payload.findByID({ collection, id, depth: 1, req, overrideAccess: false });
    const brand = collection === "brands" ? doc : doc.brand;
    return brand?.url ? { site: new URL(brand.url).host, note: `Builds ${brand.title}.` } : null;
  },
  // What the next build carries: documents saved since the live site was built.
  changes: async ({ req, since }) => {
    const { docs } = await req.payload.find({
      collection: "pages",
      where: since ? { updatedAt: { greater_than: since.toISOString() } } : {},
      limit: 50,
      req,
      overrideAccess: false,
    });
    return docs.map((page) => ({ label: page.title, updatedAt: page.updatedAt }));
  },
});

6. Regenerate the types and the import map

pnpm payload generate:types
pnpm payload generate:importmap

7. Set up the site on Netlify (optional)

  • Preview before publishing: in the site's Deploys, open the published deploy and choose Lock to stop auto publishing. From then on a build from the admin waits as a preview until someone presses Deploy. Without the lock, the button reads Build and deploy and a finished build goes live at once.
  • Only the admin builds: to keep pushes to the production branch from deploying by themselves, set the site's builds to Stopped builds in its build settings. The plugin allows builds for the moment it queues one, then stops them again.

8. Try it

Open a document of a listed collection and press Deploy beside Save, then Start deploying. The log starts streaming; when the build is done, Open preview, check it, and Deploy.

Options

OptionTypeDefaultWhat it does
access{ viewStatus, viewLog, build, discard, publish }requiredThe gates from accessPolicy.plugins["netlify-deploy"]. See Access and capabilities
tokenstring | undefined-The Netlify personal access token. Server-side only
sitestring | (args) => SiteTarget | null—The site to build: its id or domain, or a function that returns { site, note? } for the document the button sits on. note is a line shown in the drawer; null hides the button
collectionsCollectionSlug[][]Collections whose edit view gets the button beside Save
headerbooleanfalseAlso put the button in the admin's top bar. Meant for a single site: there is no document there
changes(args) => DeployChange[]-The documents saved since since, when the live build started, so a save made during it still counts. Each is { label, updatedAt, url? }
onBuild(args) => void—Called on the server after a build starts, with { req, site, deployId }
onPublish(args) => void—Called on the server after a preview is published

site and changes get { req, collection, id }: the document the button sits on, or nulls for the top-bar button. Query with req and overrideAccess: false, so a caller only reaches what they may read.

Access and capabilities

CapabilityLets a userAlso needs, on the document the button sits on
viewStatussee the button, the site's state, recent deploys and who started themread
viewLogread a build's logread
buildstart a buildread
discardcancel a running build or delete a finished preview; never a published deployread
publishput a finished preview liveread

The capability says who may act at all; the document right comes from the policy entry you already wrote for the collection. A document only chooses which site is built, so reading it is the right that is checked; the top-bar button has no document and needs the capability alone.

  • Anonymous callers get 401; users of another auth collection and users without the capability get 403.
  • A document the caller may not read answers 404, as if it did not exist, before Netlify is asked.
  • A collection that is not in collections answers 400.
  • POST endpoints accept only Content-Type: application/json.
  • A deploy id must be a Netlify deploy id (24 hexadecimal characters) and belong to the site the document resolved to.
  • Requests go only to api.netlify.com and the Netlify build log socket.
  • Errors carry a generic message; Netlify's own answer goes to the server log.
  • GET /api/netlify-deploy/capabilities answers a logged-in admin user with one boolean per capability; the button uses it to hide what the user may not do, and the server still checks every request. The build log panel is shown only to users with viewLog. An action the server refuses (403) shows "You don't have permission to do this." instead of the bare status text.
  • Netlify is never sent anything about the user: every build started here is titled Payload.
  • The history names who started a build with the admin collection's useAsTitle field, and only when the reader may read that user. When that field is the email or the id, no name is shown.

What the plugin owns

SlugKindWritten byRead by
netlify-deploy-lockscollectionthe plugin onlyyour policy's read; nobody is recommended
netlify-deploy-buildscollectionthe plugin onlyyour policy's read; nobody is recommended

netlify-deploy-locks holds one short-lived lock per site while a build is being started. netlify-deploy-builds holds, per build started here, the Netlify deploy id and the id of the user who started it.

Troubleshooting

What you seeWhy
No buttonthe user lacks viewStatus; site returned null for this document; the collection is not in collections; the import map was not regenerated
"The Netlify token is not configured"NETLIFY_AUTH_TOKEN is not set on this server
"The request to Netlify failed"Netlify refused or did not answer; the server log has netlify-deploy: Netlify answered … with its status and body
401 or 403 from Netlify in the server logthe token expired or was revoked, or its owner has no access to the site
"Netlify has no such site or deploy"the site id or domain is not one this token's account can see
"A build of this site is already running"a build started elsewhere is still running; wait for it or cancel it on Netlify
"A build of this site is being started"someone started one less than 30 seconds ago and Netlify may not list it yet
The build starts, but no log panel appearsthe user lacks viewLog
The log panel stays on "Waiting for the build log…"the server runs Node older than 22
Build and deploy where you expected Start deployingthe site's auto-publishing is not locked (setup step 7)

How it works

  • Status: the plugin reads the site and its latest production deploys from the Netlify API. The newest deploy decides what the drawer shows. The admin asks every few seconds while a build runs, and rarely otherwise, only while the tab is visible.
  • Build: POST /sites/:site/builds. Netlify keeps no title for a build started this way, so the plugin records the deploy id and the user's id in netlify-deploy-builds, which is how the drawer knows its own builds. A site with stopped builds has them allowed just long enough to queue the build.
  • One build at a time: before it starts a build, the plugin inserts a lock for the site into netlify-deploy-locks, whose site column is unique, so of two simultaneous requests only one gets the lock; then it checks Netlify's list for a running build. The lock is kept for 30 seconds, the time Netlify may take to list a new build, and a lock older than that is replaced. What it cannot cover: a build started outside Payload between the list check and the build request, and a build that Netlify still does not list 30 seconds after it was queued.
  • Publish: restores the finished deploy, which is how a locked site is published.
  • Log: read from the WebSocket that netlify logs:deploy uses, a short read per request, so no connection outlives it; at most the last 500 lines are returned.
  • Security: the token never leaves the server. The site always comes from the configuration and a document the caller may read, never from the request, so the endpoints cannot be pointed at another site.

Endpoints

All under your API route. For a document's button, collection and id go in the query string of GET requests and in the JSON body of POST requests; the top-bar button sends neither.

Capability
GET /netlify-deploy/statusviewStatusthe site, its phase, the current deploy, recent deploys, changes
GET /netlify-deploy/log?deploy=<id>viewLogthe build log so far, and whether the build has ended
POST /netlify-deploy/buildbuildstart a build; 409 while one runs or is being started
POST /netlify-deploy/discarddiscard{ deployId }: cancel a running build, or delete a finished preview; never a published deploy
POST /netlify-deploy/publishpublish{ deployId }: publish a finished build
GET /netlify-deploy/capabilitiesany admin userone boolean per capability, for the user who asks

Migrating from 1.x

2.0 moves the plugin onto @focus-reactive/payload-plugin-guard; Upgrading to the guard explains the model all the plugins share, with a complete example. Every access rule is now written by hand in your project's src/access.policy.ts, and nothing is open by default: an entry you leave out stops the boot, and a capability you do not grant is refused for everyone.

What changes

  • Payload and every @payloadcms/* package 3.90 or later, with the React and Next versions Payload 3.90 requires, Node 22.22 or later, and @focus-reactive/payload-plugin-guard installed next to the plugin.
  • access: { build, publish } is replaced by five capabilities, with no default: 1.x let any signed-in user of any auth collection build, discard and publish, and showed the status and logs to anyone signed in. build no longer covers discarding.
  • Every action on a document's button also needs read access to that document.
  • The endpoint paths under /api/netlify-deploy/ are unchanged, but POST /netlify-deploy/discard and /publish take collection and id in the JSON body instead of the query string, and every POST needs Content-Type: application/json.
  • Error bodies are { "error": "<message>" } instead of { "errors": [{ "message": "…" }] }, and they no longer repeat Netlify's answer.
  • Who started a build is kept in the new netlify-deploy-builds collection instead of payload.kv, as a user id instead of a name or email, and the build title sent to Netlify no longer names the user. Builds started before the upgrade show as started outside Payload.
  • The status response no longer has a can field; read GET /netlify-deploy/capabilities instead.

Steps

  1. Upgrade payload and every @payloadcms/* package to 3.90 or later, run the server on Node 22.22 or later, and install the guard: pnpm add @focus-reactive/payload-plugin-guard @focus-reactive/payload-plugin-netlify-deploy.

  2. Add the plugin's entries to src/access.policy.ts, with gates for your own roles; if the project has no policy file yet, write it first as the guide describes.

    // src/access.policy.ts, inside defineAccessPolicy({ ... })
    collections: {
      "netlify-deploy-locks": { create: nobody, read: nobody, update: nobody, delete: nobody },
      "netlify-deploy-builds": { create: nobody, read: nobody, update: nobody, delete: nobody },
    },
    plugins: {
      "netlify-deploy": {
        viewStatus: isEditor,
        viewLog: isEditor,
        build: isEditor,
        discard: isEditor,
        publish: isAdmin,
      },
    },
    
    • viewStatus: see the button, the site's state, recent deploys and who started them.
    • viewLog: read a build's log, which contains whatever the build prints.
    • build: start a build.
    • discard: cancel a running build or delete a finished preview; never a published deploy.
    • publish: put a finished preview live.
    • Every capability also needs read access to the document the button sits on; the two collections are written and read only by the plugin, so every operation stays nobody.
  3. Pass access: accessPolicy.plugins["netlify-deploy"] to netlifyDeployPlugin, and export the config wrapped: export default withAccessPolicy(accessPolicy, buildConfig({ ... })).

  4. Database: netlify-deploy-locks and netlify-deploy-builds are new collections; on SQL databases without schema push, run payload migrate:create and then payload migrate.

  5. Re-test: an anonymous GET /api/netlify-deploy/status answers 401, a user without build gets 403 from POST /api/netlify-deploy/build, and GET /api/netlify-deploy-builds as an admin answers 403; then start a build, read its log, publish a preview and discard another as the roles you granted.

Good to know

  • Build minutes: a button makes builds easy to start. The lock stops parallel builds of a site, not frequent ones.
  • Stopped builds: for the few seconds a build is being queued on a site with stopped builds, a push to its production branch would build too. The same holds for any tool that builds such a site through the API.
  • A cancelled preview is deleted from Netlify, so nobody is offered it again. A preview older than what is live is not offered either.
  • The preview link is the deploy's own address (<deploy id>--<site>.netlify.app). master--<site>.netlify.app is the branch alias and shows what is live, not the preview.
  • Build logs contain whatever the build prints, including values a misconfigured build echoes; grant viewLog with that in mind.

License

MIT

Similar plugins