Compare commits

...
6 Commits
24 changed files with 824 additions and 91 deletions
+3 -1
View File
@@ -194,7 +194,7 @@ Wpinaj w kolekcje gdzie dotyczy (patrz `hooks.md`):
- **buildSecurityHeaders** w next.config — HSTS, COOP, nosniff, Referrer-Policy (z automatu, uniwersalne).
- **buildCsp** — generator CSP z twardymi regułami (base-uri, object-src, frame-ancestors). Flagi: turnstile, analytics, youtube, r2Url. Wdrażaj przez `report-only` → sprawdź konsolę → `enforce`.
- **2FA WYMUSZONE** — `ipalKit({ twoFactor: { issuer: 'Nazwa Firmy' } })` + `pnpm add @clocklimited/payload-2fa@3.0.0-beta.7`. Wymuszone dla WSZYSTKICH użytkowników (forceSetup), bez opcji wyłączenia per user. NIE ustawiaj `twoFactor: false` (chyba że klient wprost odmawia). Bez zależności = błąd buildu. Patrz security.md.
- **2FA WYMUSZONE** — `pnpm add @clocklimited/payload-2fa@3.0.0-beta.7`, potem WSTRZYKNIJ: `import { payloadTotp } from '@clocklimited/payload-2fa'` + `ipalKit({ twoFactor: { issuer: 'Nazwa Firmy', plugin: payloadTotp } })`. Wstrzyknięcie obowiązkowe — bez niego plugin robi dynamiczny import, którego Next nie wbundluje → „Cannot find module" na froncie. (Ewentualnie zamiast wstrzyknięcia: `serverExternalPackages: ['@clocklimited/payload-2fa']` w next.config.) Wymuszone dla WSZYSTKICH (forceSetup), bez opcji per user. NIE `twoFactor: false` (chyba że klient wprost odmawia). Patrz security.md.
- **Ścieżka panelu** — `ipalKit({ adminRoute: '/its' })` ukrywa panel. WYMAGA przeniesienia folderu `app/(payload)/admin/` → `app/(payload)/its/`. To obscurity, nie security (2FA to prawdziwa ochrona).
- CSP zostaje w projekcie (domeny), ale skeleton z pluginu. NIE Trusted Types (psuje Turnstile/GA).
@@ -236,6 +236,8 @@ Ten plik to skondensowane reguły. Szczegóły w `node_modules/@intecion/ipal-ki
| Walidacja ENV na starcie (assertEnv) | `env.md` |
| Czytelność dla AI: Markdown per strona, llms-full, boty AI w robots | `content.md`, `seo.md` |
| Serwer MCP strony (Claude podłącza się do treści) | `mcp.md` |
| GTM + Meta Pixel — konfiguracja krok po kroku | `gtm-meta-pixel.md` |
| White-label panelu admina (logo/nazwa z SiteSettings) | `white-label.md` |
| Bezpieczeństwo, CSP, COOP | `security.md` |
| Formularze, Turnstile, submitForm, useForm/useContactForm | `forms.md`, `turnstile.md` |
| i18n, strona jednojęzyczna, ścieżki | `i18n.md` |
+8
View File
@@ -0,0 +1,8 @@
/**
* Entry point: @intecion/ipal-kit/admin
*
* Admin-panel UI components (white-label branding). Separate export so Payload's
* importMap can resolve them by a stable path when ipalKit injects
* admin.components.graphics.Logo/Icon.
*/
export { AdminIcon, AdminLogo, IntecionCredit } from '../modules/branding/index.js';
+9
View File
@@ -0,0 +1,9 @@
/**
* Entry point: @intecion/ipal-kit/admin
*
* Admin-panel UI components (white-label branding). Separate export so Payload's
* importMap can resolve them by a stable path when ipalKit injects
* admin.components.graphics.Logo/Icon.
*/ export { AdminIcon, AdminLogo, IntecionCredit } from '../modules/branding/index.js';
//# sourceMappingURL=admin.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"sources":["../../src/exports/admin.ts"],"sourcesContent":["/**\n * Entry point: @intecion/ipal-kit/admin\n *\n * Admin-panel UI components (white-label branding). Separate export so Payload's\n * importMap can resolve them by a stable path when ipalKit injects\n * admin.components.graphics.Logo/Icon.\n */\nexport { AdminIcon, AdminLogo, IntecionCredit } from '../modules/branding/index.js'\n"],"names":["AdminIcon","AdminLogo","IntecionCredit"],"mappings":"AAAA;;;;;;CAMC,GACD,SAASA,SAAS,EAAEC,SAAS,EAAEC,cAAc,QAAQ,+BAA8B"}
+52
View File
@@ -0,0 +1,52 @@
/**
* White-label admin branding: the Payload admin panel's logo (login + nav) and
* icon, pulled from the project's SiteSettings so each client sees THEIR brand,
* set by the editor in the panel — not hardcoded per project. Wired
* automatically by `ipalKit({ whiteLabel: true })` (it injects
* admin.components.graphics.Logo/Icon pointing here).
*
* Server Components — they read the SiteSettings global at render. Data access
* uses the project's `@payload-config` alias (universal in Payload 3 Next apps),
* loaded via a variable specifier so the PLUGIN's own typecheck doesn't try to
* resolve it (same pattern as the optional 2FA import). Everything is wrapped in
* try/catch: on the login screen before the DB is ready, or a build with no DB,
* the component falls back to the site name text, then to null (Payload's own
* default) — never throws, never blocks the panel.
*
* A0: no client brand in code. The logo/name come from the panel; if nothing is
* set, nothing is forced.
*/
type BrandingProps = {
/** Upload field to render as the image. Default 'logo' (Logo) / 'favicon' (Icon). */
imageField?: string;
/** Field holding the site name. Default 'siteName'. */
nameField?: string;
/** SiteSettings global slug. Default 'site-settings'. */
settingsSlug?: string;
};
/**
* Admin panel logo — this is the LARGE logo on the login / unauthorized screens
* (Payload uses `graphics.Icon` for the small nav glyph). SiteSettings `logo`,
* falls back to `siteName` text. Sized generously for the login screen.
*/
export declare function AdminLogo(props?: BrandingProps): Promise<import("react/jsx-runtime").JSX.Element | null>;
/** Admin panel icon (small nav glyph). SiteSettings `favicon`, falls back to initials. */
export declare function AdminIcon(props?: BrandingProps): Promise<import("react/jsx-runtime").JSX.Element | null>;
/**
* Discreet vendor credit: "Technology supported by Intecion.com". This is the
* PLUGIN VENDOR's credit (Intecion ships ipal-kit, the framework), not client
* data — a sensible default here is fine and A0-safe. The client's own brand
* still owns the logo/name; this is a small line stating who supports the tech.
* Text/URL overridable; turn it off with `whiteLabel: { credit: false }`.
*
* Wired by ipalKit into admin.components.afterNavLinks (nav) AND afterLogin
* (login screen footer). `variant` adjusts placement:
* - 'nav' → left-aligned line under the nav links
* - 'login' → centered line below the login form
*/
export declare function IntecionCredit(props?: {
text?: string;
url?: string;
variant?: 'login' | 'nav';
}): import("react/jsx-runtime").JSX.Element;
export {};
+124
View File
@@ -0,0 +1,124 @@
import { jsx as _jsx } from "react/jsx-runtime";
import { getPayload } from 'payload';
async function loadBranding(settingsSlug, nameField, imageField) {
try {
// Consumer alias — resolved in the project's build, hidden from plugin tsc.
const spec = '@payload-config';
const mod = await import(spec);
const payload = await getPayload({
config: mod.default
});
const settings = await payload.findGlobal({
slug: settingsSlug,
depth: 1
});
const name = typeof settings[nameField] === 'string' ? settings[nameField] : null;
const image = settings[imageField];
const url = image && typeof image === 'object' && typeof image.url === 'string' ? image.url : null;
return {
name,
url
};
} catch {
return {
name: null,
url: null
};
}
}
/**
* Admin panel logo — this is the LARGE logo on the login / unauthorized screens
* (Payload uses `graphics.Icon` for the small nav glyph). SiteSettings `logo`,
* falls back to `siteName` text. Sized generously for the login screen.
*/ export async function AdminLogo(props = {}) {
const { imageField = 'logo', nameField = 'siteName', settingsSlug = 'site-settings' } = props;
const { name, url } = await loadBranding(settingsSlug, nameField, imageField);
if (url) {
return /*#__PURE__*/ _jsx("img", {
alt: name ?? '',
src: url,
style: {
height: 'auto',
maxHeight: 120,
maxWidth: 420,
width: 'auto'
}
});
}
if (name) {
return /*#__PURE__*/ _jsx("div", {
style: {
fontSize: '2rem',
fontWeight: 600
},
children: name
});
}
return null // nothing configured → Payload's default
;
}
/** Admin panel icon (small nav glyph). SiteSettings `favicon`, falls back to initials. */ export async function AdminIcon(props = {}) {
const { imageField = 'favicon', nameField = 'siteName', settingsSlug = 'site-settings' } = props;
const { name, url } = await loadBranding(settingsSlug, nameField, imageField);
if (url) {
return /*#__PURE__*/ _jsx("img", {
alt: name ?? '',
src: url,
style: {
height: 'auto',
maxHeight: 28,
maxWidth: 28,
width: 'auto'
}
});
}
if (name) {
return /*#__PURE__*/ _jsx("div", {
style: {
fontWeight: 700
},
children: name.slice(0, 2).toUpperCase()
});
}
return null;
}
/**
* Discreet vendor credit: "Technology supported by Intecion.com". This is the
* PLUGIN VENDOR's credit (Intecion ships ipal-kit, the framework), not client
* data — a sensible default here is fine and A0-safe. The client's own brand
* still owns the logo/name; this is a small line stating who supports the tech.
* Text/URL overridable; turn it off with `whiteLabel: { credit: false }`.
*
* Wired by ipalKit into admin.components.afterNavLinks (nav) AND afterLogin
* (login screen footer). `variant` adjusts placement:
* - 'nav' → left-aligned line under the nav links
* - 'login' → centered line below the login form
*/ export function IntecionCredit(props = {}) {
const { text = 'Technology supported by Intecion.com', url = 'https://intecion.com', variant = 'nav' } = props;
const style = variant === 'login' ? {
color: 'inherit',
display: 'block',
fontSize: '0.75rem',
marginTop: '2rem',
opacity: 0.6,
padding: '0.5rem',
textAlign: 'center',
textDecoration: 'none'
} : {
color: 'inherit',
display: 'block',
fontSize: '0.75rem',
opacity: 0.6,
padding: '0.75rem 1rem',
textDecoration: 'none'
};
return /*#__PURE__*/ _jsx("a", {
href: url,
rel: "noopener noreferrer",
style: style,
target: "_blank",
children: text
});
}
//# sourceMappingURL=adminGraphics.js.map
File diff suppressed because one or more lines are too long
+1
View File
@@ -0,0 +1 @@
export { AdminIcon, AdminLogo, IntecionCredit } from './adminGraphics.js';
+3
View File
@@ -0,0 +1,3 @@
export { AdminIcon, AdminLogo, IntecionCredit } from './adminGraphics.js';
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/modules/branding/index.ts"],"sourcesContent":["export { AdminIcon, AdminLogo, IntecionCredit } from './adminGraphics.js'\n"],"names":["AdminIcon","AdminLogo","IntecionCredit"],"mappings":"AAAA,SAASA,SAAS,EAAEC,SAAS,EAAEC,cAAc,QAAQ,qBAAoB"}
+110 -21
View File
@@ -62,29 +62,118 @@ import { buildSeoPlugin, injectAutoFillMeta, injectSeoTabs } from './modules/seo
if (!tf?.issuer) {
throw new Error('[ipal] twoFactor.issuer is required (name shown in the authenticator ' + 'app). Pass twoFactor: { issuer: "Your Site" }, or twoFactor: false to ' + 'opt out (discouraged).');
}
try {
// Dynamic specifier via a variable so TS doesn't try to resolve this
// optional peer dependency at build time (it isn't in the plugin's own
// node_modules). Avoids TS2307 without @ts-expect-error; the module
// exists at runtime in projects that installed it.
// @ts-ignore
const mod = await import('@clocklimited/payload-2fa');
// The package exports `payloadTotp`; older/other builds may use
// `totpPlugin`. Accept either so a rename doesn't break us.
const totp = mod.payloadTotp ?? mod.totpPlugin;
if (typeof totp !== 'function') {
throw new Error('expected export payloadTotp (or totpPlugin) to be a function — ' + 'check the installed @clocklimited/payload-2fa version');
// Prefer the INJECTED plugin factory (recommended): the project imports
// payloadTotp from @clocklimited/payload-2fa and passes it in. Then the
// plugin never imports the optional peer itself — no dynamic import, so
// Next can't fail to bundle it (the cause of "Cannot find module
// '@clocklimited/payload-2fa'" crashing even public frontend pages).
let totp = tf.plugin;
if (!totp) {
// Fallback: dynamic import. Variable specifier dodges the plugin's own
// TS2307, but Next may NOT trace it into the server bundle — projects
// using this path MUST add '@clocklimited/payload-2fa' to
// serverExternalPackages in next.config (see docs/security.md).
try {
const pkg = '@clocklimited/payload-2fa';
const mod = await import(pkg);
totp = mod.payloadTotp ?? mod.totpPlugin;
} catch (err) {
throw new Error('[ipal] 2FA is enforced but @clocklimited/payload-2fa could not be loaded. ' + 'Best fix — inject it: `import { payloadTotp } from "@clocklimited/payload-2fa"` ' + 'then `twoFactor: { issuer, plugin: payloadTotp }`. Or install it AND add ' + "'@clocklimited/payload-2fa' to serverExternalPackages in next.config. Or set " + `twoFactor: false to opt out (discouraged). Original error: ${String(err)}`);
}
config = await totp({
collection: tf.collectionSlug ?? 'users',
forceSetup: true,
totp: {
issuer: tf.issuer
}
})(config);
} catch (err) {
throw new Error('[ipal] 2FA is enforced but @clocklimited/payload-2fa is not installed. ' + 'Run: pnpm add @clocklimited/payload-2fa — or set twoFactor: false to ' + `opt out (discouraged). Original error: ${String(err)}`);
}
if (typeof totp !== 'function') {
throw new Error('[ipal] 2FA: expected payloadTotp (or totpPlugin) to be a function — check the ' + 'injected `plugin` or the installed @clocklimited/payload-2fa version.');
}
config = await totp({
collection: tf.collectionSlug ?? 'users',
forceSetup: true,
totp: {
issuer: tf.issuer
}
})(config);
}
// --- white-label admin branding ---
// Inject admin.components.graphics.Logo/Icon pointing at the plugin's
// /admin export. The components read SiteSettings at render, so each client
// sees their own brand from the panel (no brand in code). Project must run
// `pnpm generate:importmap` so Payload resolves the component paths.
if (options.whiteLabel) {
const wl = options.whiteLabel === true ? {} : options.whiteLabel;
const serverProps = {};
if (wl.settingsSlug) {
serverProps.settingsSlug = wl.settingsSlug;
}
if (wl.nameField) {
serverProps.nameField = wl.nameField;
}
const logoProps = {
...serverProps,
...wl.logoField ? {
imageField: wl.logoField
} : {}
};
const iconProps = {
...serverProps,
...wl.iconField ? {
imageField: wl.iconField
} : {}
};
// Vendor credit ("Technology by Intecion.com") under the nav — on by
// default, hidden with credit:false, text/url overridable.
const creditOn = wl.credit !== false;
const creditProps = wl.credit && typeof wl.credit === 'object' ? {
...wl.credit.text ? {
text: wl.credit.text
} : {},
...wl.credit.url ? {
url: wl.credit.url
} : {}
} : {};
config.admin = {
...config.admin ?? {},
components: {
...config.admin?.components ?? {},
graphics: {
...config.admin?.components?.graphics ?? {},
Icon: {
path: '@intecion/ipal-kit/admin#AdminIcon',
serverProps: iconProps
},
Logo: {
path: '@intecion/ipal-kit/admin#AdminLogo',
serverProps: logoProps
}
},
...creditOn ? {
afterLogin: [
...config.admin?.components?.afterLogin ?? [],
{
path: '@intecion/ipal-kit/admin#IntecionCredit',
serverProps: {
...creditProps,
variant: 'login'
}
}
],
afterNavLinks: [
...config.admin?.components?.afterNavLinks ?? [],
{
path: '@intecion/ipal-kit/admin#IntecionCredit',
serverProps: {
...creditProps,
variant: 'nav'
}
}
]
} : {}
},
...wl.titleSuffix ? {
meta: {
...config.admin?.meta ?? {},
titleSuffix: wl.titleSuffix
}
} : {}
};
}
// --- i18n ---
config.localization = buildLocalizationConfig(options.i18n);
+1 -1
View File
File diff suppressed because one or more lines are too long
+55 -1
View File
@@ -1,4 +1,15 @@
import type { Field } from 'payload';
import type { Field, Plugin } from 'payload';
/**
* Factory shape of @clocklimited/payload-2fa's `payloadTotp` export — injected
* so the plugin never imports the optional peer itself.
*/
export type TotpPluginFactory = (options: {
collection: string;
forceSetup: boolean;
totp: {
issuer: string;
};
}) => Plugin;
import type { AccessOption } from './modules/access/types.js';
import type { ContentOption } from './modules/content/types.js';
import type { FormsOption } from './modules/forms/types.js';
@@ -71,5 +82,48 @@ export type IpalOptions = {
collectionSlug?: string;
/** Name shown in the authenticator app (e.g. company/site name). */
issuer: string;
/**
* The 2FA plugin factory, INJECTED from the project:
* `import { payloadTotp } from '@clocklimited/payload-2fa'`. Strongly
* recommended — injecting it (the same pattern as NextResponse /
* revalidatePath) means the plugin never dynamically imports the
* optional peer, which Next can fail to bundle into the server chunks
* ("Cannot find module '@clocklimited/payload-2fa'" at runtime, even on
* public frontend pages). If omitted, the plugin falls back to a dynamic
* import and you MUST add '@clocklimited/payload-2fa' to
* serverExternalPackages in next.config. See docs/security.md.
*/
plugin?: TotpPluginFactory;
} | false;
/**
* White-label the admin panel: show the CLIENT's brand (logo + name) in the
* admin — login screen and nav — pulled from SiteSettings, set by the editor
* in the panel (no brand hardcoded in code). `true` wires it with defaults
* (SiteSettings `logo`/`favicon`/`siteName`); the object form overrides the
* global slug, field names, or the browser-tab title suffix.
*
* Injects admin.components.graphics.Logo/Icon pointing at
* `@intecion/ipal-kit/admin`. After enabling, run `pnpm generate:importmap`
* so Payload can resolve the components. See docs/white-label.md.
*/
whiteLabel?: {
/**
* Vendor credit ("Technology by Intecion.com") at the bottom of the
* admin nav. Default on; `false` hides it, or override text/url.
*/
credit?: {
text?: string;
url?: string;
} | boolean;
/** Upload field for the small nav icon. Default 'favicon'. */
iconField?: string;
/** Upload field for the login/nav logo. Default 'logo'. */
logoField?: string;
/** Field with the site name. Default 'siteName'. */
nameField?: string;
/** SiteSettings global slug. Default 'site-settings'. */
settingsSlug?: string;
/** Static browser-tab title suffix (e.g. ' · Acme Admin'). */
titleSuffix?: string;
} | boolean;
};
+1 -1
View File
File diff suppressed because one or more lines are too long
+3 -1
View File
@@ -125,11 +125,13 @@ export default buildConfig({
| turnstile | Cloudflare Turnstile (widget + verify) | [turnstile.md](./turnstile.md) |
| email | Wysyłka: SMTP z panelu lub Microsoft Graph (M365) | [email.md](./email.md) |
| forms | Form-builder + submitForm + useForm/useContactForm (logika klienta) | [forms.md](./forms.md) |
| analytics | GA4 / GTM spięte z Consent Mode | [analytics.md](./analytics.md) |
| analytics | GA4 / GTM spięte z Consent Mode, pushDataLayer | [analytics.md](./analytics.md) |
| gtm-meta-pixel | Konfiguracja GTM + Meta Pixel krok po kroku (pod ten stack) | [gtm-meta-pixel.md](./gtm-meta-pixel.md) |
| slug | Auto-slug z tytułu, per locale | [slug.md](./slug.md) |
| notifications | Teksty wyników akcji (formularz) per język | [notifications.md](./notifications.md) |
| storage | Media na Cloudflare R2 (offload z .env) | [storage.md](./storage.md) |
| security | Nagłówki bezpieczeństwa HTTP (HSTS, X-Frame...) | [security.md](./security.md) |
| white-label | Branding panelu admina (logo + nazwa z SiteSettings) | [white-label.md](./white-label.md) |
| content | Blog/archiwa: kolekcje pod stroną-archiwum, listing, paginacja, redirecty (resolveRedirect) | [content.md](./content.md) |
Nowy projekt krok po kroku: [getting-started.md](./getting-started.md)
+3 -1
View File
@@ -210,7 +210,7 @@ Wpinaj w kolekcje gdzie dotyczy (patrz `hooks.md`):
- **buildSecurityHeaders** w next.config — HSTS, COOP, nosniff, Referrer-Policy (z automatu, uniwersalne).
- **buildCsp** — generator CSP z twardymi regułami (base-uri, object-src, frame-ancestors). Flagi: turnstile, analytics, youtube, r2Url. Wdrażaj przez `report-only` → sprawdź konsolę → `enforce`.
- **2FA WYMUSZONE** — `ipalKit({ twoFactor: { issuer: 'Nazwa Firmy' } })` + `pnpm add @clocklimited/payload-2fa@3.0.0-beta.7`. Wymuszone dla WSZYSTKICH użytkowników (forceSetup), bez opcji wyłączenia per user. NIE ustawiaj `twoFactor: false` (chyba że klient wprost odmawia). Bez zależności = błąd buildu. Patrz security.md.
- **2FA WYMUSZONE** — `pnpm add @clocklimited/payload-2fa@3.0.0-beta.7`, potem WSTRZYKNIJ: `import { payloadTotp } from '@clocklimited/payload-2fa'` + `ipalKit({ twoFactor: { issuer: 'Nazwa Firmy', plugin: payloadTotp } })`. Wstrzyknięcie obowiązkowe — bez niego plugin robi dynamiczny import, którego Next nie wbundluje → „Cannot find module" na froncie. (Ewentualnie: `serverExternalPackages: ['@clocklimited/payload-2fa']` w next.config.) Wymuszone dla WSZYSTKICH (forceSetup), bez opcji per user. NIE `twoFactor: false` (chyba że klient wprost odmawia). Patrz security.md.
- **Ścieżka panelu** — `ipalKit({ adminRoute: '/its' })` ukrywa panel. WYMAGA przeniesienia folderu `app/(payload)/admin/` → `app/(payload)/its/`. To obscurity, nie security (2FA to prawdziwa ochrona).
- CSP zostaje w projekcie (domeny), ale skeleton z pluginu. NIE Trusted Types (psuje Turnstile/GA).
@@ -252,6 +252,8 @@ Ten plik to skondensowane reguły. Szczegóły w `node_modules/@intecion/ipal-ki
| Walidacja ENV na starcie (assertEnv) | `env.md` |
| Czytelność dla AI: Markdown per strona, llms-full, boty AI w robots | `content.md`, `seo.md` |
| Serwer MCP strony (Claude podłącza się do treści) | `mcp.md` |
| GTM + Meta Pixel — konfiguracja krok po kroku | `gtm-meta-pixel.md` |
| White-label panelu admina (logo/nazwa z SiteSettings) | `white-label.md` |
| Bezpieczeństwo, CSP, COOP | `security.md` |
| Formularze, Turnstile, submitForm, useForm/useContactForm | `forms.md`, `turnstile.md` |
| i18n, strona jednojęzyczna, ścieżki | `i18n.md` |
+24 -6
View File
@@ -258,23 +258,41 @@ pnpm add @clocklimited/[email protected]
Uwaga: pakiet nie ma jeszcze stabilnego 3.0.0 — użyj konkretnej wersji beta
(albo `^3.0.0-0`, żeby dopuścić prereleasy). Sam `^3.0.0` da błąd
ERR_PNPM_NO_MATCHING_VERSION.
To PEER dependency — ipal-kit importuje ją dynamicznie tylko gdy 2FA włączone
(domyślnie). Bez niej i z włączonym 2FA plugin rzuci jasny błąd.
### Konfiguracja (payload.config.ts)
### Konfiguracja (payload.config.ts) — WSTRZYKNIJ plugin (zalecane)
```ts
import { payloadTotp } from '@clocklimited/payload-2fa'
ipalKit({
i18n: i18nConfig,
twoFactor: {
issuer: 'Nazwa Firmy', // pokazywane w aplikacji authenticator (Google Auth itp.)
// collectionSlug: 'users', // domyślnie 'users'
issuer: 'Nazwa Firmy', // pokazywane w aplikacji authenticator
plugin: payloadTotp, // ← WSTRZYKNIJ — patrz niżej dlaczego
// collectionSlug: 'users',
},
})
```
**Dlaczego `plugin: payloadTotp` (wstrzyknięcie):** to ten sam wzorzec co
`NextResponse`/`revalidatePath` — projekt podaje peer-dep, plugin go NIE
importuje. Bez tego plugin robi dynamiczny import, którego **Next potrafi nie
wbundlować** do server chunks → błąd runtime **„Cannot find module
'@clocklimited/payload-2fa'"** lecący nawet na publicznych stronach frontu.
Wstrzyknięcie eliminuje ten problem u źródła.
**Jeśli NIE wstrzykujesz** (zostawiasz dynamiczny import) — MUSISZ dodać pakiet do
`serverExternalPackages` w `next.config`, żeby Next nie próbował go bundlować:
```ts
// next.config.ts
const nextConfig = {
serverExternalPackages: ['@clocklimited/payload-2fa'],
}
```
Plugin ustawia `forceSetup: true` — każdy użytkownik MUSI skonfigurować TOTP po
zalogowaniu (przekierowanie na setup). Nie ma opcji „włącz/wyłącz" dla użytkownika.
zalogowaniu. Nie ma opcji „włącz/wyłącz" dla użytkownika.
### Wyłączenie (ODRADZANE)
+91
View File
@@ -0,0 +1,91 @@
# white-label — branding panelu admina z panelu
Panel admina pokazuje **markę klienta** (logo + nazwa) na ekranie logowania i w
nawigacji, pobraną z **SiteSettings** — czyli ustawioną przez redaktora w panelu,
nie zahardkodowaną w kodzie. Każdy klient loguje się do „swojego" panelu.
Powiązane: [security.md](./security.md) (adminRoute), [accessibility.md](./accessibility.md).
## Włączenie
```ts
// payload.config.ts
ipalKit({
i18n: { /* … */ },
whiteLabel: true,
})
```
`true` wpina branding z domyślnych pól SiteSettings: `logo` (logo panelu),
`favicon` (mała ikona nawigacji), `siteName` (nazwa / fallback tekstowy).
> **Po włączeniu uruchom `pnpm generate:importmap`.** Plugin wstrzykuje
> `admin.components.graphics.Logo/Icon` wskazujące na `@intecion/ipal-kit/admin`;
> Payload musi zregenerować import map, żeby je znaleźć. Bez tego kroku panel
> użyje domyślnego logo Payload.
## Konfiguracja (opcjonalnie)
```ts
whiteLabel: {
settingsSlug: 'site-settings', // globalny slug ustawień
nameField: 'siteName', // pole z nazwą
logoField: 'logo', // upload na logo (login + nav)
iconField: 'favicon', // upload na ikonę nav
titleSuffix: ' · Acme Admin', // sufiks tytułu w karcie przeglądarki (statyczny)
credit: true, // kredyt dostawcy pod nawigacją (domyślnie on)
}
```
## Kredyt dostawcy — „Technology supported by Intecion.com"
Dyskretny kredyt **„Technology supported by Intecion.com"** (link do
`https://intecion.com`) pojawia się w **dwóch miejscach**:
- **pod nawigacją** panelu (`afterNavLinks`, wariant `nav` — wyrównany do lewej),
- **na dole ekranu logowania** (`afterLogin`, wariant `login` — wyśrodkowany).
To kredyt DOSTAWCY technologii (Intecion dostarcza framework ipal-kit) — marka
klienta nadal rządzi logiem i nazwą; to tylko linijka „kto wspiera technologię".
Domyślnie włączony z `whiteLabel`. Sterowanie:
```ts
whiteLabel: { credit: false } // ukryj (oba miejsca)
whiteLabel: { credit: { text: 'Powered by Intecion', url: 'https://intecion.com' } } // własny tekst/url
```
## Logo na ekranie logowania
`AdminLogo` to DUŻE logo na ekranie logowania (Payload używa `graphics.Icon` do
małej ikony w nawigacji). Renderuje się sporo większe (`maxHeight 120 / maxWidth
420`), żeby marka klienta była wyraźna przy logowaniu. Mała ikona nav to `favicon`
przez `AdminIcon`.
## Jak to działa
- `AdminLogo` / `AdminIcon` to **Server Components** czytające SiteSettings przy
renderze (przez alias `@payload-config`, uniwersalny w projektach Payload 3 +
Next).
- **Bezpieczne fallbacki:** gdy baza jest niedostępna (ekran logowania zanim
wstanie DB, build bez bazy) albo logo nie jest ustawione → komponent pokazuje
nazwę (`siteName`), a gdy i jej brak → `null` (domyślne Payload). Nigdy nie
rzuca, nie blokuje panelu.
- **A0:** żadnej marki klienta w kodzie. Logo i nazwa pochodzą z panelu; jak nic
nie ustawiono, nic nie jest narzucane.
## Granice
- **`titleSuffix` jest statyczny** — tytuł karty przeglądarki ustawia się w
configu (build-time), więc nie czyta się z bazy. Logo i ikona (to, co widać) są
dynamiczne z SiteSettings; sufiks tytułu podajesz w opcji, jeśli chcesz.
- **To branding panelu, nie front** — wygląd strony publicznej robisz jak dotąd
(bloki, style projektu). White-label dotyczy wyłącznie panelu admina.
- Ścieżkę panelu (`/admin → /its`) ustawiasz osobno przez `adminRoute` — patrz
[security.md](./security.md).
## Checklist
- [ ] `ipalKit({ whiteLabel: true })`
- [ ] Redaktor wgrał `logo` i `favicon` w SiteSettings (+ `siteName`)
- [ ] `pnpm generate:importmap`
- [ ] Restart dev / rebuild → panel pokazuje markę klienta na loginie i w nav
+30 -31
View File
@@ -1,6 +1,6 @@
{
"name": "@intecion/ipal-kit",
"version": "1.7.1",
"version": "1.7.4",
"description": "Intecion Payload Advanced Library — a Payload CMS 3 plugin: i18n, SEO, forms, consent, analytics, blog/archives.",
"license": "MIT",
"repository": {
@@ -33,13 +33,17 @@
"import": "./dist/exports/next-middleware.js",
"types": "./dist/exports/next-middleware.d.ts",
"default": "./dist/exports/next-middleware.js"
},
"./admin": {
"import": "./dist/exports/admin.js",
"types": "./dist/exports/admin.d.ts",
"default": "./dist/exports/admin.js"
}
},
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"dist",
"docs"
"dist"
],
"scripts": {
"build": "pnpm copyfiles && pnpm build:types && pnpm build:swc",
@@ -60,59 +64,54 @@
"test:int": "vitest"
},
"dependencies": {
"@payloadcms/storage-s3": "^3.88.0",
"lucide-react": "^0.400.0",
"nodemailer": "^8.0.1",
"server-only": "^0.0.1",
"slugify": "^1.6.6"
},
"peerDependencies": {
"@clocklimited/payload-2fa": "^3.0.0",
"@payloadcms/next": "^3.88.0",
"@payloadcms/plugin-form-builder": "^3.88.0",
"@payloadcms/plugin-seo": "^3.88.0",
"@payloadcms/ui": "^3.88.0",
"@payloadcms/plugin-form-builder": "^3.90.2",
"@payloadcms/plugin-seo": "^3.90.2",
"next": ">=15",
"payload": "^3.88.0",
"react": "^19.0.0",
"react-dom": "^19.0.0"
"payload": "^3.90.2",
"react": "^19.0.0"
},
"devDependencies": {
"@eslint/eslintrc": "^3.2.0",
"@payloadcms/db-postgres": "3.88.0",
"@payloadcms/db-sqlite": "3.88.0",
"@payloadcms/db-postgres": "3.90.2",
"@payloadcms/db-sqlite": "3.90.2",
"@payloadcms/eslint-config": "3.28.0",
"@payloadcms/next": "3.88.0",
"@payloadcms/plugin-form-builder": "3.88.0",
"@payloadcms/plugin-seo": "3.88.0",
"@payloadcms/richtext-lexical": "3.88.0",
"@payloadcms/ui": "3.88.0",
"@playwright/test": "1.58.2",
"@payloadcms/next": "3.90.2",
"@payloadcms/plugin-form-builder": "3.90.2",
"@payloadcms/plugin-seo": "3.90.2",
"@payloadcms/richtext-lexical": "3.90.2",
"@payloadcms/ui": "3.90.2",
"@playwright/test": "1.64.0",
"@swc-node/register": "1.10.9",
"@swc/cli": "0.6.0",
"@types/node": "22.19.9",
"@types/node": "22.20.5",
"@types/nodemailer": "^8.0.1",
"@types/react": "19.2.14",
"@types/react-dom": "19.2.3",
"@types/react": "^19.2.14",
"@types/react-dom": "^19.2.3",
"copyfiles": "2.4.1",
"cross-env": "^7.0.3",
"eslint": "^9.23.0",
"eslint-config-next": "16.2.6",
"eslint-config-next": "16.4.0",
"graphql": "^16.8.1",
"mongodb-memory-server": "10.1.4",
"next": "16.2.6",
"next": "16.4.0",
"open": "^10.1.0",
"payload": "3.88.0",
"payload": "3.90.2",
"prettier": "^3.4.2",
"qs-esm": "8.0.1",
"react": "19.2.6",
"react-dom": "19.2.6",
"react": "19.3.0",
"react-dom": "19.3.0",
"rimraf": "3.0.2",
"sharp": "0.34.2",
"sharp": "0.34.5",
"sort-package-json": "^2.10.0",
"typescript": "5.7.3",
"typescript": "5.9.3",
"vite-tsconfig-paths": "6.0.5",
"vitest": "4.0.18"
"vitest": "5.0.4"
},
"engines": {
"node": "^18.20.2 || >=20.9.0",
+8
View File
@@ -0,0 +1,8 @@
/**
* Entry point: @intecion/ipal-kit/admin
*
* Admin-panel UI components (white-label branding). Separate export so Payload's
* importMap can resolve them by a stable path when ipalKit injects
* admin.components.graphics.Logo/Icon.
*/
export { AdminIcon, AdminLogo, IntecionCredit } from '../modules/branding/index.js'
+141
View File
@@ -0,0 +1,141 @@
import { getPayload } from 'payload'
/**
* White-label admin branding: the Payload admin panel's logo (login + nav) and
* icon, pulled from the project's SiteSettings so each client sees THEIR brand,
* set by the editor in the panel — not hardcoded per project. Wired
* automatically by `ipalKit({ whiteLabel: true })` (it injects
* admin.components.graphics.Logo/Icon pointing here).
*
* Server Components — they read the SiteSettings global at render. Data access
* uses the project's `@payload-config` alias (universal in Payload 3 Next apps),
* loaded via a variable specifier so the PLUGIN's own typecheck doesn't try to
* resolve it (same pattern as the optional 2FA import). Everything is wrapped in
* try/catch: on the login screen before the DB is ready, or a build with no DB,
* the component falls back to the site name text, then to null (Payload's own
* default) — never throws, never blocks the panel.
*
* A0: no client brand in code. The logo/name come from the panel; if nothing is
* set, nothing is forced.
*/
type BrandingProps = {
/** Upload field to render as the image. Default 'logo' (Logo) / 'favicon' (Icon). */
imageField?: string
/** Field holding the site name. Default 'siteName'. */
nameField?: string
/** SiteSettings global slug. Default 'site-settings'. */
settingsSlug?: string
}
type MediaLike = { url?: null | string } | null | undefined
async function loadBranding(
settingsSlug: string,
nameField: string,
imageField: string,
): Promise<{ name: null | string; url: null | string }> {
try {
// Consumer alias — resolved in the project's build, hidden from plugin tsc.
const spec = '@payload-config'
const mod = (await import(spec)) as { default: unknown }
const payload = await getPayload({ config: mod.default as never })
const settings = (await payload.findGlobal({
slug: settingsSlug as never,
depth: 1,
})) as Record<string, unknown>
const name = typeof settings[nameField] === 'string' ? (settings[nameField]) : null
const image = settings[imageField] as MediaLike
const url =
image && typeof image === 'object' && typeof image.url === 'string' ? image.url : null
return { name, url }
} catch {
return { name: null, url: null }
}
}
/**
* Admin panel logo — this is the LARGE logo on the login / unauthorized screens
* (Payload uses `graphics.Icon` for the small nav glyph). SiteSettings `logo`,
* falls back to `siteName` text. Sized generously for the login screen.
*/
export async function AdminLogo(props: BrandingProps = {}) {
const { imageField = 'logo', nameField = 'siteName', settingsSlug = 'site-settings' } = props
const { name, url } = await loadBranding(settingsSlug, nameField, imageField)
if (url) {
return (
<img
alt={name ?? ''}
src={url}
style={{ height: 'auto', maxHeight: 120, maxWidth: 420, width: 'auto' }}
/>
)
}
if (name) {return <div style={{ fontSize: '2rem', fontWeight: 600 }}>{name}</div>}
return null // nothing configured → Payload's default
}
/** Admin panel icon (small nav glyph). SiteSettings `favicon`, falls back to initials. */
export async function AdminIcon(props: BrandingProps = {}) {
const { imageField = 'favicon', nameField = 'siteName', settingsSlug = 'site-settings' } = props
const { name, url } = await loadBranding(settingsSlug, nameField, imageField)
if (url) {
return (
<img
alt={name ?? ''}
src={url}
style={{ height: 'auto', maxHeight: 28, maxWidth: 28, width: 'auto' }}
/>
)
}
if (name) {return <div style={{ fontWeight: 700 }}>{name.slice(0, 2).toUpperCase()}</div>}
return null
}
/**
* Discreet vendor credit: "Technology supported by Intecion.com". This is the
* PLUGIN VENDOR's credit (Intecion ships ipal-kit, the framework), not client
* data — a sensible default here is fine and A0-safe. The client's own brand
* still owns the logo/name; this is a small line stating who supports the tech.
* Text/URL overridable; turn it off with `whiteLabel: { credit: false }`.
*
* Wired by ipalKit into admin.components.afterNavLinks (nav) AND afterLogin
* (login screen footer). `variant` adjusts placement:
* - 'nav' → left-aligned line under the nav links
* - 'login' → centered line below the login form
*/
export function IntecionCredit(
props: { text?: string; url?: string; variant?: 'login' | 'nav' } = {},
) {
const {
text = 'Technology supported by Intecion.com',
url = 'https://intecion.com',
variant = 'nav',
} = props
const style =
variant === 'login'
? {
color: 'inherit' as const,
display: 'block',
fontSize: '0.75rem',
marginTop: '2rem',
opacity: 0.6,
padding: '0.5rem',
textAlign: 'center' as const,
textDecoration: 'none',
}
: {
color: 'inherit' as const,
display: 'block',
fontSize: '0.75rem',
opacity: 0.6,
padding: '0.75rem 1rem',
textDecoration: 'none',
}
return (
<a href={url} rel="noopener noreferrer" style={style} target="_blank">
{text}
</a>
)
}
+1
View File
@@ -0,0 +1 @@
export { AdminIcon, AdminLogo, IntecionCredit } from './adminGraphics.js'
+95 -26
View File
@@ -1,6 +1,6 @@
import type { Config, Plugin } from 'payload'
import type { IpalOptions } from './types.js'
import type { IpalOptions, TotpPluginFactory } from './types.js'
import { buildCookieSettings } from './globals/CookieSettings/index.js'
import { buildNotifications } from './globals/Notifications/index.js'
@@ -71,37 +71,106 @@ export const ipalKit = (options: IpalOptions): Plugin => {
'opt out (discouraged).',
)
}
try {
// Dynamic specifier via a variable so TS doesn't try to resolve this
// optional peer dependency at build time (it isn't in the plugin's own
// node_modules). Avoids TS2307 without @ts-expect-error; the module
// exists at runtime in projects that installed it.
// @ts-ignore
const mod = (await import('@clocklimited/payload-2fa')) as {
payloadTotp?: (opts: Record<string, unknown>) => Plugin
totpPlugin?: (opts: Record<string, unknown>) => Plugin
}
// The package exports `payloadTotp`; older/other builds may use
// `totpPlugin`. Accept either so a rename doesn't break us.
const totp = mod.payloadTotp ?? mod.totpPlugin
if (typeof totp !== 'function') {
// Prefer the INJECTED plugin factory (recommended): the project imports
// payloadTotp from @clocklimited/payload-2fa and passes it in. Then the
// plugin never imports the optional peer itself — no dynamic import, so
// Next can't fail to bundle it (the cause of "Cannot find module
// '@clocklimited/payload-2fa'" crashing even public frontend pages).
let totp: TotpPluginFactory | undefined = tf.plugin
if (!totp) {
// Fallback: dynamic import. Variable specifier dodges the plugin's own
// TS2307, but Next may NOT trace it into the server bundle — projects
// using this path MUST add '@clocklimited/payload-2fa' to
// serverExternalPackages in next.config (see docs/security.md).
try {
const pkg = '@clocklimited/payload-2fa'
const mod = (await import(pkg)) as {
payloadTotp?: TotpPluginFactory
totpPlugin?: TotpPluginFactory
}
totp = mod.payloadTotp ?? mod.totpPlugin
} catch (err) {
throw new Error(
'expected export payloadTotp (or totpPlugin) to be a function — ' +
'check the installed @clocklimited/payload-2fa version',
'[ipal] 2FA is enforced but @clocklimited/payload-2fa could not be loaded. ' +
'Best fix — inject it: `import { payloadTotp } from "@clocklimited/payload-2fa"` ' +
'then `twoFactor: { issuer, plugin: payloadTotp }`. Or install it AND add ' +
"'@clocklimited/payload-2fa' to serverExternalPackages in next.config. Or set " +
`twoFactor: false to opt out (discouraged). Original error: ${String(err)}`,
)
}
config = await totp({
collection: tf.collectionSlug ?? 'users',
forceSetup: true, // ENFORCED — every user must set up TOTP; no opt-out
totp: { issuer: tf.issuer },
})(config)
} catch (err) {
}
if (typeof totp !== 'function') {
throw new Error(
'[ipal] 2FA is enforced but @clocklimited/payload-2fa is not installed. ' +
'Run: pnpm add @clocklimited/payload-2fa — or set twoFactor: false to ' +
`opt out (discouraged). Original error: ${String(err)}`,
'[ipal] 2FA: expected payloadTotp (or totpPlugin) to be a function — check the ' +
'injected `plugin` or the installed @clocklimited/payload-2fa version.',
)
}
config = await totp({
collection: tf.collectionSlug ?? 'users',
forceSetup: true, // ENFORCED — every user must set up TOTP; no opt-out
totp: { issuer: tf.issuer },
})(config)
}
// --- white-label admin branding ---
// Inject admin.components.graphics.Logo/Icon pointing at the plugin's
// /admin export. The components read SiteSettings at render, so each client
// sees their own brand from the panel (no brand in code). Project must run
// `pnpm generate:importmap` so Payload resolves the component paths.
if (options.whiteLabel) {
const wl = options.whiteLabel === true ? {} : options.whiteLabel
const serverProps: Record<string, unknown> = {}
if (wl.settingsSlug) {serverProps.settingsSlug = wl.settingsSlug}
if (wl.nameField) {serverProps.nameField = wl.nameField}
const logoProps = { ...serverProps, ...(wl.logoField ? { imageField: wl.logoField } : {}) }
const iconProps = { ...serverProps, ...(wl.iconField ? { imageField: wl.iconField } : {}) }
// Vendor credit ("Technology by Intecion.com") under the nav — on by
// default, hidden with credit:false, text/url overridable.
const creditOn = wl.credit !== false
const creditProps =
wl.credit && typeof wl.credit === 'object'
? {
...(wl.credit.text ? { text: wl.credit.text } : {}),
...(wl.credit.url ? { url: wl.credit.url } : {}),
}
: {}
config.admin = {
...(config.admin ?? {}),
components: {
...(config.admin?.components ?? {}),
graphics: {
...(config.admin?.components?.graphics ?? {}),
Icon: { path: '@intecion/ipal-kit/admin#AdminIcon', serverProps: iconProps },
Logo: { path: '@intecion/ipal-kit/admin#AdminLogo', serverProps: logoProps },
},
...(creditOn
? {
afterLogin: [
...(config.admin?.components?.afterLogin ?? []),
{
path: '@intecion/ipal-kit/admin#IntecionCredit',
serverProps: { ...creditProps, variant: 'login' },
},
],
afterNavLinks: [
...(config.admin?.components?.afterNavLinks ?? []),
{
path: '@intecion/ipal-kit/admin#IntecionCredit',
serverProps: { ...creditProps, variant: 'nav' },
},
],
}
: {}),
},
...(wl.titleSuffix
? { meta: { ...(config.admin?.meta ?? {}), titleSuffix: wl.titleSuffix } }
: {}),
}
}
// --- i18n ---
+58 -1
View File
@@ -1,5 +1,14 @@
import type { Field } from 'payload'
import type { Field, Plugin } from 'payload'
/**
* Factory shape of @clocklimited/payload-2fa's `payloadTotp` export — injected
* so the plugin never imports the optional peer itself.
*/
export type TotpPluginFactory = (options: {
collection: string
forceSetup: boolean
totp: { issuer: string }
}) => Plugin
import type { AccessOption } from './modules/access/types.js'
import type { ContentOption } from './modules/content/types.js'
import type { FormsOption } from './modules/forms/types.js'
@@ -84,6 +93,54 @@ export type IpalOptions = {
collectionSlug?: string
/** Name shown in the authenticator app (e.g. company/site name). */
issuer: string
/**
* The 2FA plugin factory, INJECTED from the project:
* `import { payloadTotp } from '@clocklimited/payload-2fa'`. Strongly
* recommended — injecting it (the same pattern as NextResponse /
* revalidatePath) means the plugin never dynamically imports the
* optional peer, which Next can fail to bundle into the server chunks
* ("Cannot find module '@clocklimited/payload-2fa'" at runtime, even on
* public frontend pages). If omitted, the plugin falls back to a dynamic
* import and you MUST add '@clocklimited/payload-2fa' to
* serverExternalPackages in next.config. See docs/security.md.
*/
plugin?: TotpPluginFactory
}
| false
/**
* White-label the admin panel: show the CLIENT's brand (logo + name) in the
* admin — login screen and nav — pulled from SiteSettings, set by the editor
* in the panel (no brand hardcoded in code). `true` wires it with defaults
* (SiteSettings `logo`/`favicon`/`siteName`); the object form overrides the
* global slug, field names, or the browser-tab title suffix.
*
* Injects admin.components.graphics.Logo/Icon pointing at
* `@intecion/ipal-kit/admin`. After enabling, run `pnpm generate:importmap`
* so Payload can resolve the components. See docs/white-label.md.
*/
whiteLabel?:
| {
/**
* Vendor credit ("Technology by Intecion.com") at the bottom of the
* admin nav. Default on; `false` hides it, or override text/url.
*/
credit?:
| {
text?: string
url?: string
}
| boolean
/** Upload field for the small nav icon. Default 'favicon'. */
iconField?: string
/** Upload field for the login/nav logo. Default 'logo'. */
logoField?: string
/** Field with the site name. Default 'siteName'. */
nameField?: string
/** SiteSettings global slug. Default 'site-settings'. */
settingsSlug?: string
/** Static browser-tab title suffix (e.g. ' · Acme Admin'). */
titleSuffix?: string
}
| boolean
}