Docs in English (part 1), seeding guide, Coolify deployment

- Translate to English every doc the code branches did not touch: AGENT.md,
  developer guide, vibe, CHANGELOG, docs index, module pages, all skills
  except ipal-seo-check (14 pages follow after the security/SEO merge).
  Placeholder marker is now [TO FILL: …]; skill resources renamed to
  section-code.md / nav-code.md. AGENT.md and the ipal-skills pointer
  block say the docs are in English.
- docs/seeding.md: create-only, natural keys, never delete, no users or
  secrets, empty-field globals, fallbackLocale: false, dry run, backup and
  restore, production update guard, seeds vs migrations, Coolify Terminal.
  Seed templates gain --dry-run, the SEED_UPDATE production guard
  (IPAL_SEED_ALLOW_PROD_UPDATE), skip of edited records and a summary.
  "Seeding on production" rule block in AGENT.md.
- Coolify is the single deployment path (deployment, env, developer guide,
  ipal-setup): build vs runtime env, migrations on container start
  (prodMigrations), health check and rolling updates, rollback, backups and
  restore, DNS/Let's Encrypt/CAA. R2: custom domain needs a Cloudflare zone;
  default is media served by the app (R2_PUBLIC_URL empty).
- docsConsistency: no Polish prose outside code/quoted data (pending pages
  listed); IPAL_* names may also be read by shipped skill templates.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-10-22 17:39:03 +02:00
co-authored by Claude Opus 5.5
parent 6e3979bae6
commit 2d9f3e15d4
47 changed files with 6102 additions and 5355 deletions
+91 -73
View File
@@ -1,121 +1,127 @@
# env — walidacja zmiennych środowiskowych na starcie
# env — validating environment variables at startup
Łapie źle skonfigurowany deploy przy starcie, jednym czytelnym komunikatem ze
WSZYSTKIMI brakami naraz — zamiast kryptograficznego crashu gdzieś w połowie
builda (`getaddrinfo ENOTFOUND`) albo runtime'u. Fail fast.
Catches a misconfigured deploy at startup, with one readable message listing
ALL the gaps at once — instead of a cryptic crash somewhere halfway through the
build (`getaddrinfo ENOTFOUND`) or at runtime. Fail fast.
Powiązane: [PROGRAMISTA.md §3–4](./dev/PROGRAMISTA.md), [storage.md](./storage.md),
[forms.md](./forms.md).
Related: [PROGRAMISTA.md §3–4](./dev/PROGRAMISTA.md), [storage.md](./storage.md),
[forms.md](./forms.md), [deployment.md](./deployment.md).
## Dlaczego bez zod
**Where the values live:** dev → `.env` (never committed; `.env.example` without values is). Production → the
Coolify application → **Environment Variables**, each marked for build time and/or runtime: `NEXT_PUBLIC_*` at
build time (inlined by `next build`) and runtime; secrets (`PAYLOAD_SECRET`, `R2_*`, `GRAPH_*`, …) at runtime;
`DATABASE_URI` / `PAYLOAD_SECRET` also at build time only when the build prerenders from the database. Table and
details: [deployment.md §4.2](./deployment.md). A changed variable needs a redeploy.
Plugin świadomie NIE wciąga `zod`. Wymuszanie biblioteki walidacji na każdym z
projektów to narzucona zależność (łamie A0 „żadnych narzuconych zależności").
`assertEnv` to mały, zero-dependency walidator robiący dokładnie to, czego
potrzeba.
## Why no zod
## Integracja — jedna linia na starcie
The plugin deliberately does NOT pull in `zod`. Forcing a validation library on every
project is an imposed dependency (breaks A0 "no imposed dependencies").
`assertEnv` is a small, zero-dependency validator that does exactly what is
needed.
Najlepsze miejsce to `instrumentation.ts` (Next woła `register()` raz przy
starcie serwera):
## Integration — one line at startup
The best place is `instrumentation.ts` (Next calls `register()` once at
server startup):
```ts
// src/instrumentation.ts
import { assertEnv, ipalEnvRules } from '@intecion/ipal-kit/env'
export function register() {
if (process.env.NEXT_RUNTIME !== 'nodejs') return // Edge: brak process.env serwera
if (process.env.NEXT_RUNTIME !== 'nodejs') return // Edge: no server process.env
assertEnv(ipalEnvRules({ storage: true, emailGraph: true, turnstile: true }))
}
```
> **Import z `@intecion/ipal-kit/env`, nie z roota.** Next kompiluje
> `instrumentation.ts` także dla Edge. Root pakietu ciągnie Payload, `file-type`,
> `fs` — Turbopack pada (`Export fileTypeFromFile doesn't exist in target module`).
> `/env` to tylko walidator, zero zależności. Root nadal eksportuje `assertEnv`
> i `ipalEnvRules` (np. dla `payload.config.ts`).
> **Import from `@intecion/ipal-kit/env`, not from the root.** Next compiles
> `instrumentation.ts` for Edge too. The package root pulls in Payload, `file-type`,
> `fs` — Turbopack fails (`Export fileTypeFromFile doesn't exist in target module`).
> `/env` is only the validator, zero dependencies. The root still exports `assertEnv`
> and `ipalEnvRules` (e.g. for `payload.config.ts`).
**Wyłącz / nadpisz / rozszerz:** walidacja jest w pełni opt-in — plugin sam nigdy nie woła
`assertEnv`; bez tej linii nic nie jest sprawdzane. Każdą regułę z presetu zastąpisz, filtrując
tablicę (`ipalEnvRules(…).filter((r) => r.name !== 'X')`), dopiszesz własne (spread niżej) albo
napiszesz cały zestaw ręcznie.
**Turn off / override / extend:** validation is fully opt-in — the plugin never calls
`assertEnv` by itself; without this line nothing is checked. Replace any preset rule by filtering
the array (`ipalEnvRules(…).filter((r) => r.name !== 'X')`), add your own (spread below), or
write the whole set by hand.
Alternatywnie na górze `payload.config.ts` (ładuje się i w buildzie, i w
runtime). Działa tylko po stronie serwera (czyta `process.env`) — NIE importuj
do komponentu klienckiego.
Alternatively at the top of `payload.config.ts` (it loads both at build time and at
runtime). Server-side only (reads `process.env`) — do NOT import it
into a client component.
## ipalEnvRules — gotowy schemat dla stacku (opt-in)
## ipalEnvRules — ready-made schema for the stack (opt-in)
Składa zestaw reguł z funkcji, których projekt faktycznie używa — strona na
dysku lokalnym nie jest zmuszana do `R2_*`, strona bez formularzy do Turnstile.
To nie sztywny wymagany zestaw (A0: plugin nie żąda configu, którego nie
używasz).
Builds the rule set from the features the project actually uses — a site on
local disk is not forced to set `R2_*`, a site without forms is not forced to set Turnstile.
It is not a rigid required set (A0: the plugin does not demand config you do not
use).
```ts
ipalEnvRules({
storage?: boolean, // R2_* (R2_BUCKET, R2_ACCESS_KEY_ID, R2_SECRET_ACCESS_KEY, R2_ENDPOINT, R2_PUBLIC_URL)
emailGraph?: boolean, // GRAPH_* (GRAPH_TENANT_ID, GRAPH_CLIENT_ID, GRAPH_CLIENT_SECRET, GRAPH_SENDER — e-mail)
ipHeader?: boolean, // IPAL_IP_HEADER — wymagany w produkcji, poza nią opcjonalny (nazwa nagłówka [a-z0-9-])
ipHeader?: boolean, // IPAL_IP_HEADER — required in production, optional outside it (header name [a-z0-9-])
turnstile?: boolean | { siteKeyVar?: string; secretVar?: string }, // NEXT_PUBLIC_TURNSTILE_SITE_KEY, TURNSTILE_SECRET_KEY
serverUrlVar?: string, // domyślnie 'NEXT_PUBLIC_SERVER_URL'
secretVar?: string, // domyślnie 'PAYLOAD_SECRET'
databaseVar?: string, // domyślnie 'DATABASE_URI'
serverUrlVar?: string, // default 'NEXT_PUBLIC_SERVER_URL'
secretVar?: string, // default 'PAYLOAD_SECRET'
databaseVar?: string, // default 'DATABASE_URI'
})
```
Zawsze (rdzeń): `DATABASE_URI`, `PAYLOAD_SECRET`, `NEXT_PUBLIC_SERVER_URL` (URL),
`NODE_ENV` (opcjonalny, oneOf `development`/`production`/`test`). Nazwy `R2_*` / `GRAPH_*` /
`NEXT_PUBLIC_SERVER_URL` / `IPAL_IP_HEADER` / Turnstile odpowiadają temu, co czytają moduły
pluginu; DB/secret to zmienne Payloada — nazwy można nadpisać.
Always (core): `DATABASE_URI`, `PAYLOAD_SECRET`, `NEXT_PUBLIC_SERVER_URL` (URL),
`NODE_ENV` (optional, oneOf `development`/`production`/`test`). The names `R2_*` / `GRAPH_*` /
`NEXT_PUBLIC_SERVER_URL` / `IPAL_IP_HEADER` / Turnstile match what the plugin modules
read; DB/secret are Payload variables — their names can be overridden.
**`storage: true` — kiedy R2_* są wymagane** (liczone w chwili wywołania `ipalEnvRules`):
- `NODE_ENV=production` → wszystkie 5 (`R2_PUBLIC_URL` jako absolutny URL);
- poza produkcją, gdy ustawiony jest którykolwiek z 4 kluczy (`R2_BUCKET`, `R2_ACCESS_KEY_ID`,
`R2_SECRET_ACCESS_KEY`, `R2_ENDPOINT`) → wszystkie 5 (wszystkie albo żadne);
- poza produkcją bez kluczy → żaden wymagany (dysk lokalny); samo `R2_PUBLIC_URL` przechodzi
(tryb tylko do odczytu, storage.md).
**`storage: true` — when R2_* are required** (evaluated when `ipalEnvRules` is called):
- `NODE_ENV=production` → all 5 (`R2_PUBLIC_URL` as an absolute URL);
- outside production, when any of the 4 keys is set (`R2_BUCKET`, `R2_ACCESS_KEY_ID`,
`R2_SECRET_ACCESS_KEY`, `R2_ENDPOINT`) → all 5 (all or none);
- outside production without keys → none required (local disk); `R2_PUBLIC_URL` alone passes
(read-only mode, storage.md).
**`turnstile: true`** czyni obie zmienne Turnstile **wymaganymi**, choć plugin bierze klucze
najpierw z panelu (Site Integrations), a env jest tylko fallbackiem — włącz tylko, gdy klucze
trzymasz w env.
**`turnstile: true`** makes both Turnstile variables **required**, even though the plugin takes the keys
from the panel first (Site Integrations) and env is only a fallback — turn it on only when you keep the keys
in env.
Plugin czyta też (poza presetem — dopisz własne reguły, jeśli chcesz je walidować):
`INDEXNOW_KEY` (seo.md), `IPAL_NOINDEX` (`1`/`true`/`yes` — staging, seo.md). Pełna tabela:
The plugin also reads (outside the preset — add your own rules if you want to validate them):
`INDEXNOW_KEY` (seo.md), `IPAL_NOINDEX` (`1`/`true`/`yes` — staging, seo.md). Full table:
[deployment.md](./deployment.md).
Rozszerzenie o własne zmienne — spread:
Extending with your own variables — spread:
```ts
assertEnv([
...ipalEnvRules({ storage: true }),
{ name: 'MY_API_KEY', description: 'Klucz do integracji X' },
{ name: 'MY_API_KEY', description: 'Key for integration X' },
])
```
## assertEnv — walidator
## assertEnv — the validator
```ts
assertEnv(rules: EnvRule[], options?: { env?, label? }): void
```
Zbiera WSZYSTKIE problemy i rzuca jeden zagregowany `Error`. Przy braku
problemów nie robi nic. `options.env` (domyślnie `process.env`) ułatwia testy;
`options.label` zmienia prefiks (domyślnie `[ipal]`).
Collects ALL problems and throws one aggregated `Error`. With no
problems it does nothing. `options.env` (default `process.env`) makes testing easier;
`options.label` changes the prefix (default `[ipal]`).
### EnvRule
```ts
type EnvRule = {
name: string
required?: boolean // domyślnie true; false = waliduj tylko gdy obecne
kind?: 'string' | 'url' | 'number' | 'port' | 'boolean' | 'email' // domyślnie 'string'
required?: boolean // default true; false = validate only when present
kind?: 'string' | 'url' | 'number' | 'port' | 'boolean' | 'email' // default 'string'
oneOf?: readonly string[]
description?: string // pokazywane w błędzie — po co ta zmienna
validate?: (value: string) => string | true // własna reguła
description?: string // shown in the error — what this variable is for
validate?: (value: string) => string | true // custom rule
}
```
Ręcznie, bez presetu:
By hand, without the preset:
```ts
assertEnv([
@@ -126,7 +132,7 @@ assertEnv([
])
```
### Przykładowy komunikat (preset `ipalEnvRules()`)
### Sample message (preset `ipalEnvRules()`)
```
[ipal] Environment validation failed (3 problems):
@@ -136,21 +142,33 @@ assertEnv([
Set these in your environment (Coolify → Environment, or .env) and redeploy.
```
Wszystkie braki widzisz naraz — nie poprawiasz ich po jednym przez kilka
redeployów.
You see all the gaps at once — you do not fix them one by one over several
redeploys.
## Eksport
## Exports
```ts
import { assertEnv, ipalEnvRules } from '@intecion/ipal-kit/env'
import type { EnvRule, EnvKind, AssertEnvOptions, IpalEnvFeatures } from '@intecion/ipal-kit/env'
```
## `R2_PUBLIC_URL` — produkcja vs dev
## `R2_PUBLIC_URL` — production vs dev
`ipalEnvRules({ storage: true })` wymaga w **produkcji** pełnego URL-a
(`https://media.klient.pl`). Poza produkcją dopuszcza ścieżkę względną
(`/media`) — `buildR2Storage` dokleja do niej `NEXT_PUBLIC_SERVER_URL`, CSP jej nie
dodaje (to `'self'`), `MediaPreconnect` ją pomija. Dev bez bucketu: nie ustawiaj
`R2_*` wcale — `storage: true` może zostać (poza produkcją bez kluczy nic nie jest wymagane),
media lądują na dysku.
`ipalEnvRules({ storage: true })` requires a full URL in **production**
(`https://media.klient-media.com`). Our default, though, is media served through the app with
`R2_PUBLIC_URL` **empty** (the client zones are not on Cloudflare — storage.md, deployment.md §6) — then make the
rule optional (the URL format is still checked when set):
```ts
assertEnv(
ipalEnvRules({ storage: true, ipHeader: true }).map((r) =>
r.name === 'R2_PUBLIC_URL' ? { ...r, required: false } : r,
),
)
```
Outside production it allows a relative path
(`/media`) — `buildR2Storage` prepends `NEXT_PUBLIC_SERVER_URL` to it, CSP does not
add it (it is `'self'`), `MediaPreconnect` skips it. Dev without a bucket: do not set
`R2_*` at all — `storage: true` can stay (outside production without keys nothing is required),
media land on disk.