@foundrykit/guides-plugin
v0.2.2
Published
CMS guides for Payload 3 client sites: a Guides page, Help buttons on edit pages and local search, synced read-only from the Umi guides hub, with site-specific guides written in place by Umi staff.
Maintainers
Readme
@foundrykit/guides-plugin
CMS guides for Payload 3 client sites, served from the Umi guides hub.
- Guides page at
/admin/guides(linked in the sidebar): browse by topic, search, read. - Help button on every edit page, listing the guides for that collection or global. Renders nothing when there are none.
<Help context="…" />for finer places, e.g.media.create.- Local read-only copy of the guides this site is entitled to, so help works when the hub is down. The hub pushes a signed ping on every change; a scheduled pull is the backstop.
- Site guides: Umi staff write guides for this site only. Publishing saves them straight to the hub (scoped to this site); if the hub can't be reached the editor shows an error and the draft is kept.
Extracted from the Turquoise CMS guides section. Spec: https://claude.ai/artifact/RXzSKWXUPBH1K5Gu77CzbJ
Install
import { guidesPlugin } from '@foundrykit/guides-plugin';
export default buildConfig({
plugins: [
guidesPlugin({
// Reported to the hub on each sync, to compare with the site's Sites record.
features: ['crm.inspiretec'],
// Who can write site guides here. Default: nobody.
canAuthor: user =>
(user as { role?: string } | null)?.role === 'super-admin',
}),
],
});Environment (from the site's record in the hub):
GUIDES_HUB_URL=https://guides.example.com
GUIDES_HUB_KEY=<the site's guides key>Then regenerate the import map (payload generate:importmap) and create a migration: the plugin adds the
guides and site-guides collections and a guidesSync job task.
Options
| Option | Default | |
| ---------------- | ---------------------------- | --------------------------------------------------------------------------------------- |
| hubURL | process.env.GUIDES_HUB_URL | The guides hub. |
| siteKey | process.env.GUIDES_HUB_KEY | This site's guides key. Also verifies the hub's webhook signature. |
| features | [] | Feature keys reported to the hub. |
| plugins | [] | Extra FoundryKit plugins to report as active (see below). |
| canAuthor | () => false | Who sees and writes Site guides. |
| schedule | '0 0 * * * *' (hourly) | Cron for the backstop pull (Payload's 6-field form), or false. |
| guidesSlug | 'guides' | Slug of the local copy of the hub's guides. Change it if the site has its own guides. |
| siteGuidesSlug | 'site-guides' | Slug of the Site guides collection. |
| disabled | false | |
Changing the slugs
For a site that already has a guides (or site-guides) collection, pick other slugs, e.g.
guidesPlugin({ guidesSlug: 'cms-guides', siteGuidesSlug: 'cms-site-guides' }). The Guides page stays at
/admin/guides. Then:
- Create a migration as usual; the tables follow the slugs. Changing the slugs on a site that already has the plugin installed renames the collections, so that migration drops the old tables; the local copy refills from the hub, but unpublished site-guide drafts would need copying across first.
- The webhook moves to
/api/<guidesSlug>/sync. The hub sends pings to/api/guides/sync, so until it can be told otherwise, such a site updates through the scheduled pull (and on first boot) only. - Pass the slug to any
Helpyou place yourself:clientProps: { context: 'media.create', guidesSlug: 'cms-guides' }. The plugin's own Help buttons get it automatically.
Plugin guides
The hub sends a site the guides for each FoundryKit plugin it runs. Every FoundryKit Payload plugin records its
npm name in config.custom.foundrykit.activePlugins when it is enabled (installed-but-disabled doesn't count),
and this plugin reports that list on every pull. Plugin order in plugins: [...] doesn't matter: the list is read
from the running config. Add a plugin to the plugins option only if its version predates self-reporting.
The scheduled pull
The plugin registers a guidesSync task scheduled on the default queue. Payload only runs schedules
when something runs the jobs: jobs.autoRun on a long-running server, or a cron hitting
/api/payload-jobs/run on serverless (e.g. a Vercel cron). Without either, the site still updates on every
hub ping and on first boot when the local copy is empty.
Help in other places
Add the client component wherever an admin component path is accepted:
{ path: '@foundrykit/guides-plugin/client#Help', clientProps: { context: 'media.create' } }A guide shows there when its help contexts (set in the hub, or on a site guide) include that key.
How it talks to the hub
| | |
| ----------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Pull | GET <hub>/api/sites/feed?pluginVersion=…&features=…&plugins=… with Authorization: sites API-Key <key> |
| Ping | The hub POSTs to /api/guides/sync (/api/<guidesSlug>/sync) with x-guides-signature: sha256=<HMAC of the body, keyed with the site key>. Anything else gets 401. |
| Site guides | Publish → POST/PATCH <hub>/api/guides[/:id]; delete → DELETE. |
Development
pnpm install
pnpm dev # dev app on :3000 (set GUIDES_HUB_URL / GUIDES_HUB_KEY to point at a hub)
pnpm test # unit + integration (SQLite in memory, hub stubbed)
pnpm buildReleasing
Run pnpm release on prod. It bumps the version, updates the changelog and pushes a v* tag.
The tag triggers .github/workflows/publish.yml, which publishes to npm through trusted
publishing, so no npm token is stored locally or in GitHub.
