- AGENT.md, skills, PROGRAMISTA, vibe, README and module pages checked against src/ and package.json; every mismatch fixed (consent/analytics loading, revalidation scope, generateStaticParams, construction gating, Turnstile fail modes, email/Graph, MCP, i18n, links, slug, hooks, ...) - New pages: frontend.md, media.md, integrations.md; docs/README.md now indexes every page - Main rule (plugin helps, never limits) at the top of AGENT.md, PROGRAMISTA.md, docs/README.md, README and the setup/plugin-gap skills; module pages gain a "Wyłączenie, nadpisanie, rozszerzenie" section - README/PROGRAMISTA: stop telling projects to install packages ipal-kit already depends on; peer table; publish flow matches prepublishOnly - ipal-skills: refuse --dest without a value or pointing at the project root (previously could delete ipal-* folders in cwd) - docsConsistency: option keys, IPAL_* env names, relative links, README index, AGENT.md section refs, skill frontmatter, frontend.md helper keys, no `pnpm add` of own dependencies Co-Authored-By: Claude Opus 5.5 <[email protected]>
85 lines
3.8 KiB
Markdown
85 lines
3.8 KiB
Markdown
# payload-helpers
|
|
|
|
Typowany dostęp do globali pluginu (SiteSettings, SiteIntegrations) przez
|
|
Local API. Zgodnie z zasadą: helpery przyjmują `payload` jako argument —
|
|
plugin nigdy nie woła `getPayload` sam.
|
|
|
|
## Config
|
|
|
|
Globale `site-settings` (`SITE_SETTINGS_SLUG`), `site-integrations` (`SITE_INTEGRATIONS_SLUG`),
|
|
`cookie-settings` i `notifications` są **obecnie zawsze dodawane** przez plugin (gdy
|
|
`enabled !== false`) — nie ma opcji, żeby je pominąć albo zmienić im slug.
|
|
|
|
| Opcja `ipalKit()` | Co robi |
|
|
|---|---|
|
|
| `siteSettingsFields?: Field[]` | dodatkowe pola SiteSettings w osobnym tabie **„Custom”** (dane płasko: `settings.mojePole`) |
|
|
| `integrationsFields?: Field[]` | dodatkowe pola SiteIntegrations w tabie „Custom” |
|
|
|
|
Taby SiteSettings (nienazwane — dane płaskie): **General** (`siteName`, `siteDescription`,
|
|
`titleOrder`, `titleSeparator`, `logo`, `defaultShareImage`, `sameAs`, `favicon`, …),
|
|
**Theme** (`defaultTheme`, `allowThemeToggle`, `themeToggleLabel`), **System Pages**
|
|
(z `pages` / `content`), **Emails** (z `forms.emailLayout`), **Under construction**
|
|
(z `pages`), **Custom** (z `siteSettingsFields`).
|
|
|
|
**Dostęp:** SiteSettings ma `read: () => true` — **cały global, także pola z
|
|
`siteSettingsFields`, jest publiczny** przez REST/GraphQL (`/api/globals/site-settings`).
|
|
Nie trzymaj tam niczego poufnego (do tego SiteIntegrations, `read`/`update` tylko admin).
|
|
SiteSettings nie ustawia `update` — obowiązuje domyślne Payloada (każdy zalogowany
|
|
użytkownik kolekcji auth).
|
|
|
|
## Front — odczyt globali
|
|
|
|
```ts
|
|
import { getSiteSettings, getSiteIntegrations } from '@intecion/ipal-kit'
|
|
import type { SiteSetting, SiteIntegration } from '@/payload-types'
|
|
|
|
const payload = await getPayload({ config })
|
|
|
|
// SiteSettings (publiczne — siteName, logo, favicon, theme, system pages)
|
|
const settings = await getSiteSettings<SiteSetting>(payload, { locale: 'pl' })
|
|
|
|
// SiteIntegrations (admin-only; Local API omija access control)
|
|
const integrations = await getSiteIntegrations<SiteIntegration>(payload)
|
|
```
|
|
|
|
Generyk `<T>` pozwala wstrzyknąć wygenerowany typ klienta. Bez niego zwraca
|
|
`Record<string, unknown>`.
|
|
|
|
Opcje (`GlobalQueryOptions`): `locale` (kod albo `'all'`; brak → domyślny Payloada),
|
|
`depth` (brak → domyślny Payloada). Helpery nie łapią błędów i nie cache'ują — w
|
|
Next używaj `getSettings(locale)` z `@/lib/content` (React `cache()`, `depth: 2`).
|
|
|
|
## ⚠️ SiteIntegrations zawiera sekrety
|
|
|
|
Local API domyślnie omija access control (`overrideAccess: true`), więc
|
|
`getSiteIntegrations` **zwróci sekrety** (SMTP password, Turnstile secret,
|
|
R2 keys) mimo bariery admin-only na globalu. To zamierzone — logika serwerowa
|
|
tego potrzebuje.
|
|
|
|
**Nigdy nie przekazuj surowego wyniku do przeglądarki.** Czytaj konkretne
|
|
wartości server-side, do klienta wysyłaj tylko bezpieczne (np. `turnstileSiteKey`,
|
|
nie `turnstileSecretKey`):
|
|
|
|
```ts
|
|
// ŹLE — wyciek sekretów do klienta
|
|
return <Form data={await getSiteIntegrations(payload)} />
|
|
|
|
// DOBRZE — tylko publiczna wartość
|
|
const { turnstileSiteKey } = await getSiteIntegrations(payload)
|
|
return <Form siteKey={turnstileSiteKey} />
|
|
```
|
|
|
|
## Niższy poziom: getGlobal
|
|
|
|
```ts
|
|
import { getGlobal } from '@intecion/ipal-kit'
|
|
const data = await getGlobal<MyType>(payload, 'moj-global', { locale: 'pl', depth: 1 })
|
|
```
|
|
|
|
## Wyłączenie, nadpisanie, rozszerzenie
|
|
|
|
- Globale pluginu są obecnie zawsze dodawane (brak opcji wyłączenia / zmiany slugów); `enabled: false` usuwa cały plugin, razem z nimi.
|
|
- Rozszerzenie: `siteSettingsFields` / `integrationsFields` (tab „Custom”); kształt istniejących tabów jest stały.
|
|
- Dostęp, hooki i pola globalu zmienisz tylko nadpisując go w configu po `ipalKit` (własny plugin mapujący `config.globals`, przykład w hooks.md).
|
|
- `getGlobal(payload, slug, { locale, depth })` działa z dowolnym globalem projektu.
|