1.5 KiB
1.5 KiB
@repo/cms-client — Dual-Mode Payload Client
Provides typed access to Payload CMS via Local API (primary) or HTTP REST (fallback).
THIS PACKAGE IS STANDALONE
- NEVER import from:
@repo/cms-core,@repo/core,apps/* - The Payload instance is INJECTED, not imported
- Types are generated via
payload generate:types
Initialization
| Context | Mode | How |
|---|---|---|
| apps/cms server | Local | getPayload({config}) from @repo/cms-core |
| apps/web-next server | Local | getPayload({config}) from @repo/cms-core |
| apps/web-tanstack server | Local | getPayload({config}) from @repo/cms-core |
| Client-side (browser) | N/A | Goes through tRPC — server handles it |
| External services | HTTP | createPayloadClient({mode:"http",baseURL}) |
// In app startup (e.g., apps/web-next/src/lib/payload.ts):
import { getPayload } from "payload";
import { config } from "@repo/cms-core";
import { createPayloadClient } from "@repo/cms-client";
const payload = await getPayload({ config });
const client = createPayloadClient({ mode: "local", payload });
Available Methods
All methods support full Payload query capabilities (where, sort, limit, depth, page, populate):
find(collection, options)— paginated queryfindByID(collection, id, options)— single documentcreate(collection, data, options)— create documentupdate(collection, id, data, options)— update documentdelete(collection, id)— delete document