Added fluid skills support

This commit is contained in:
2026-10-14 11:05:57 +02:00
parent 54c2d64cce
commit 0f073b963e
32 changed files with 280 additions and 42 deletions
+17
View File
@@ -0,0 +1,17 @@
/**
* Entry point: @intecion/ipal-kit/env
*
* Environment validation ONLY — zero imports beyond this module, no Payload,
* no Node built-ins, no React. Safe for Next's instrumentation.ts, which Next
* also compiles for the Edge runtime: importing the package root there drags in
* Payload / file-type / fs and crashes Turbopack ("Export fileTypeFromFile
* doesn't exist in target module").
*
* // src/instrumentation.ts
* import { assertEnv, ipalEnvRules } from '@intecion/ipal-kit/env'
* export function register() {
* if (process.env.NEXT_RUNTIME === 'nodejs') assertEnv(ipalEnvRules({ storage: true }))
* }
*/
export { assertEnv, ipalEnvRules } from '../modules/env/index.js'
export type { AssertEnvOptions, EnvKind, EnvRule, IpalEnvFeatures } from '../modules/env/index.js'
+1 -1
View File
@@ -43,7 +43,7 @@ function checkValue(rule: EnvRule, value: string): null | string {
switch (kind) {
case 'boolean':
if (!/^(true|false|1|0|yes|no)$/i.test(value)) {
if (!/^(?:true|false|1|0|yes|no)$/i.test(value)) {
return `${name} must be a boolean (true/false/1/0/yes/no, got "${value}")`
}
break
+15 -6
View File
@@ -53,11 +53,7 @@ export function ipalEnvRules(features: IpalEnvFeatures = {}): EnvRule[] {
const rules: EnvRule[] = [
{ name: databaseVar, description: 'Database connection string (e.g. MongoDB URI)' },
{ name: secretVar, description: 'Payload secret used to sign tokens' },
{
name: serverUrlVar,
description: 'Public site origin, e.g. https://example.com',
kind: 'url',
},
{ name: serverUrlVar, description: 'Public site origin, e.g. https://example.com', kind: 'url' },
{
name: 'NODE_ENV',
description: 'Node environment',
@@ -72,7 +68,20 @@ export function ipalEnvRules(features: IpalEnvFeatures = {}): EnvRule[] {
{ name: 'R2_ACCESS_KEY_ID', description: 'R2 access key id' },
{ name: 'R2_SECRET_ACCESS_KEY', description: 'R2 secret access key' },
{ name: 'R2_ENDPOINT', description: 'R2 S3 API endpoint URL', kind: 'url' },
{ name: 'R2_PUBLIC_URL', description: 'Public base URL media is served from', kind: 'url' },
{
name: 'R2_PUBLIC_URL',
description: 'Public base URL media is served from (custom domain of the bucket)',
// Production: absolute URL (https://media.example.com). Outside production a
// site-relative path ('/media') is accepted — buildR2Storage prefixes it with
// NEXT_PUBLIC_SERVER_URL (e.g. a dev rewrite /media → bucket).
validate: (v) => {
if (/^https?:\/\/[^/\s]+/i.test(v)) {return true}
if (v.startsWith('/') && process.env.NODE_ENV !== 'production') {return true}
return v.startsWith('/')
? `R2_PUBLIC_URL must be an absolute URL in production (got "${v}") — e.g. https://media.example.com`
: `R2_PUBLIC_URL must be an absolute URL (https://…) or, outside production, a path starting with "/" (got "${v}")`
},
},
)
}
+3 -3
View File
@@ -76,7 +76,8 @@ export function buildCsp(args: BuildCspArgs = {}): { key: string; value: string
'object-src': ["'none'"], // block <object>/<embed> (Flash-era attack surface)
}
if (r2Url) {src['img-src'].push(r2Url)}
// Site-relative R2_PUBLIC_URL ('/media', dev) is same-origin — already covered by 'self'.
if (r2Url && /^https?:\/\//i.test(r2Url)) {src['img-src'].push(r2Url)}
if (turnstile) {
src['script-src'].push('https://challenges.cloudflare.com')
@@ -110,7 +111,6 @@ export function buildCsp(args: BuildCspArgs = {}): { key: string; value: string
.map(([dir, values]) => `${dir} ${values.join(' ')}`)
.join('; ')
const key =
mode === 'report-only' ? 'Content-Security-Policy-Report-Only' : 'Content-Security-Policy'
const key = mode === 'report-only' ? 'Content-Security-Policy-Report-Only' : 'Content-Security-Policy'
return { key, value }
}
+7 -5
View File
@@ -89,13 +89,15 @@ export type SitemapRouteOptions = {
export function createSitemapRouteHandler(
sitemap: () => Promise<SitemapEntry[]>,
opts: SitemapRouteOptions = {},
): (req?: Request) => Promise<Response> {
): (req: Request) => Promise<Response> {
const style = opts.cssUrl ? false : opts.style === false ? false : (opts.style ?? {})
return async (req?: Request) => {
const url = req ? new URL(req.url) : null
// `req` is required: Next 16 type-checks the first argument of a route handler
// (`Request | undefined` fails the build). A zero-argument call is not supported.
return async (req: Request) => {
const url = new URL(req.url)
if (style && url?.searchParams.has(SITEMAP_STYLE_PARAM)) {
if (style && url.searchParams.has(SITEMAP_STYLE_PARAM)) {
let title: string | undefined
try {
title = typeof style.title === 'function' ? await style.title() : style.title
@@ -111,7 +113,7 @@ export function createSitemapRouteHandler(
})
}
const cssUrl = opts.cssUrl ?? (style ? `${url?.pathname ?? '/sitemap.xml'}?${SITEMAP_STYLE_PARAM}` : undefined)
const cssUrl = opts.cssUrl ?? (style ? `${url.pathname}?${SITEMAP_STYLE_PARAM}` : undefined)
try {
const entries = await sitemap()
const xml = buildSitemapXml(entries, { cssUrl })
+6 -1
View File
@@ -77,7 +77,12 @@ export const buildR2Storage = (
// (media.klient.pl → bucket) set R2_PUBLIC_URL so Payload generates URLs
// pointing there. Without it, uploads work but images don't display publicly.
// See docs/storage.md.
const publicUrl = process.env.R2_PUBLIC_URL?.replace(/\/$/, '') // strip trailing slash
// Site-relative value ('/media', dev only — ipalEnvRules rejects it in production)
// → prefixed with NEXT_PUBLIC_SERVER_URL so Payload still stores absolute URLs.
const rawPublicUrl = process.env.R2_PUBLIC_URL?.trim().replace(/\/$/, '') // strip trailing slash
const serverUrl = process.env.NEXT_PUBLIC_SERVER_URL?.trim().replace(/\/$/, '')
const publicUrl =
rawPublicUrl?.startsWith('/') && serverUrl ? `${serverUrl}${rawPublicUrl}` : rawPublicUrl
// generateFileURL is a PER-COLLECTION option in @payloadcms/storage-s3 (not a
// top-level one) — R2 needs it to point served URLs at the custom domain
+34
View File
@@ -0,0 +1,34 @@
/*
* @intecion/ipal-kit/fluid.css — fluid type & spacing scale (variables only, no classes).
* Scales smoothly from a 360px to a 1280px viewport; rem-based, so browser zoom and
* user font size still work (WCAG 1.4.4). Opt-in:
*
* @import "tailwindcss";
* @import "@intecion/ipal-kit/fluid.css";
* @theme inline {
* --text-display: var(--ipal-fs-display);
* --text-h1: var(--ipal-fs-h1);
* --text-h2: var(--ipal-fs-h2);
* --text-h3: var(--ipal-fs-h3);
* --text-lead: var(--ipal-fs-lg);
* --spacing-section: var(--ipal-space-section);
* --spacing-gutter: var(--ipal-space-gutter);
* --spacing-gap: var(--ipal-space-gap);
* }
* → text-h1, text-display, py-section, px-gutter, gap-gap
*
* The design (DESIGN.md) decides the numbers: override any variable in the project's
* :root — the plugin only removes the clamp() maths from every project.
*/
:root {
--ipal-fs-sm: clamp(0.875rem, 0.8505rem + 0.1087vw, 0.9375rem); /* 0.875→0.9375rem · small print, captions */
--ipal-fs-base: clamp(1rem, 0.9511rem + 0.2174vw, 1.125rem); /* 1→1.125rem · body text */
--ipal-fs-lg: clamp(1.125rem, 1.0272rem + 0.4348vw, 1.375rem); /* 1.125→1.375rem · lead / intro */
--ipal-fs-h3: clamp(1.25rem, 1.0543rem + 0.8696vw, 1.75rem); /* 1.25→1.75rem · h3 */
--ipal-fs-h2: clamp(1.5rem, 1.1087rem + 1.7391vw, 2.5rem); /* 1.5→2.5rem · h2 — section headings */
--ipal-fs-h1: clamp(2rem, 1.413rem + 2.6087vw, 3.5rem); /* 2→3.5rem · h1 — page heading */
--ipal-fs-display: clamp(2.5rem, 1.7174rem + 3.4783vw, 4.5rem); /* 2.5→4.5rem · hero / display */
--ipal-space-gap: clamp(1rem, 0.6087rem + 1.7391vw, 2rem); /* 1→2rem · gap between items in a section */
--ipal-space-gutter: clamp(1rem, 0.413rem + 2.6087vw, 2.5rem); /* 1→2.5rem · container side padding */
--ipal-space-section: clamp(3rem, 1.2391rem + 7.8261vw, 7.5rem); /* 3→7.5rem · vertical padding of a section */
}