@behavioral-agentic-design-system/core 0.42.0 → 0.45.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/package.json +25 -9
- package/scripts/a11y-lint.cjs +25 -1
- package/scripts/check-spec.mjs +73 -0
- package/scripts/deal-directions.mjs +186 -0
- package/scripts/health-report.mjs +20 -14
- package/scripts/lib/counted-lint.mjs +100 -0
- package/scripts/lib/marketing-library.mjs +129 -0
- package/scripts/lib/on-system.mjs +249 -0
- package/scripts/lib/random.mjs +22 -0
- package/scripts/lib/spec-parse.d.mts +25 -0
- package/scripts/lib/spec-parse.mjs +188 -0
- package/scripts/lib/tells.mjs +128 -0
- package/scripts/lint-css-vars.mjs +175 -0
- package/scripts/lint-html-nesting.mjs +116 -0
- package/scripts/lint-live-ctas.mjs +138 -0
- package/scripts/on-system-score.mjs +95 -0
- package/scripts/slop-rules.mjs +1 -1
- package/scripts/source-images.mjs +180 -0
- package/scripts/ux-tells.mjs +78 -0
- package/src/api/brand-colors.ts +3 -0
- package/src/api/brand-fonts.ts +3 -0
- package/src/api/brand-mark.ts +6 -1
- package/src/api/dev-write-guard.ts +53 -0
- package/src/api/layers/file.ts +7 -4
- package/src/api/onboarding-extract.ts +85 -30
- package/src/api/onboarding.ts +3 -0
- package/src/api/save-tokens.ts +3 -0
- package/src/app/layout.tsx +6 -0
- package/src/app/preview/canvas/page.tsx +12 -0
- package/src/app/preview/components/page.tsx +734 -0
- package/src/app/preview/studio/blank-screen.tsx +143 -0
- package/src/app/preview/studio/page.tsx +7 -0
- package/src/app/shell.tsx +160 -44
- package/src/components/canvas/canvas.tsx +458 -0
- package/src/components/canvas/layout.ts +72 -0
- package/src/components/canvas/parse-canvas.ts +32 -0
- package/src/components/canvas/sample.ts +90 -0
- package/src/components/canvas/spec-frame.tsx +43 -0
- package/src/components/canvas/types.ts +33 -0
- package/src/components/docs-tab.tsx +7 -7
- package/src/components/home-recent.tsx +73 -0
- package/src/components/home-tab.tsx +13 -13
- package/src/components/layers-tab.tsx +2 -2
- package/src/components/markdown-preview.tsx +60 -12
- package/src/components/studio/control-panel.tsx +299 -0
- package/src/components/studio/control-row.tsx +77 -0
- package/src/components/studio/preview-frame.tsx +165 -0
- package/src/components/studio/preview-pane.tsx +247 -0
- package/src/components/studio/studio.tsx +133 -128
- package/src/components/studio/types.ts +218 -0
- package/src/components/studio/use-studio-tweaks.ts +128 -0
- package/src/components/studio/use-studio-view-state.ts +72 -0
- package/src/components/ui/autocomplete.tsx +1 -1
- package/src/components/ui/color-picker.tsx +20 -4
- package/src/components/ui/data-table.tsx +64 -3
- package/src/components/ui/date-field.tsx +1 -1
- package/src/components/ui/editable.tsx +1 -0
- package/src/components/ui/faceted-filter.tsx +187 -0
- package/src/components/ui/gauge-chart.tsx +18 -4
- package/src/components/ui/inline-edit.tsx +175 -0
- package/src/components/ui/month-picker.tsx +1 -1
- package/src/components/ui/number-input.tsx +28 -5
- package/src/components/ui/otp-input.tsx +208 -0
- package/src/components/ui/phone-input.tsx +274 -0
- package/src/components/ui/search-input.tsx +1 -1
- package/src/components/ui/tags-input.tsx +1 -1
- package/src/components/ui/timer.tsx +1 -0
- package/src/components/ui/transfer-list.tsx +13 -26
- package/src/components/ui/week-picker.tsx +1 -1
- package/src/components/ui/year-picker.tsx +1 -1
- package/src/data/component-added.json +958 -0
- package/src/data/docs-index.ts +13 -1
- package/src/hooks/use-global-mono-font.ts +1 -0
- package/src/hooks/use-global-primary-color.ts +1 -0
- package/src/hooks/use-global-sans-font.ts +1 -0
- package/src/hooks/use-global-serif-font.ts +1 -0
- package/src/hooks/use-global-type-scale.ts +17 -2
- package/src/hooks/use-mobile.ts +2 -0
- package/src/hooks/use-sync-type-scale.ts +7 -11
- package/src/lib/spec-parse.ts +4 -0
- package/src/lib/svg-sanitize.ts +19 -9
- package/src/stories/Autocomplete.stories.tsx +2 -0
- package/src/stories/Canvas.stories.tsx +45 -0
- package/src/stories/ColorPicker.stories.tsx +40 -0
- package/src/stories/DataTable.stories.tsx +30 -0
- package/src/stories/DateField.stories.tsx +21 -0
- package/src/stories/Editable.stories.tsx +2 -0
- package/src/stories/FacetedFilter.stories.tsx +197 -0
- package/src/stories/GaugeChart.stories.tsx +9 -3
- package/src/stories/InlineEdit.stories.tsx +106 -0
- package/src/stories/MarkdownPreview.stories.tsx +53 -0
- package/src/stories/MonthPicker.stories.tsx +21 -0
- package/src/stories/NumberInput.stories.tsx +25 -0
- package/src/stories/OtpInput.stories.tsx +110 -0
- package/src/stories/PhoneInput.stories.tsx +127 -0
- package/src/stories/SearchInput.stories.tsx +2 -0
- package/src/stories/TagsInput.stories.tsx +2 -0
- package/src/stories/Timer.stories.tsx +26 -0
- package/src/stories/TransferList.stories.tsx +4 -0
- package/src/stories/WeekPicker.stories.tsx +21 -0
- package/src/stories/YearPicker.stories.tsx +21 -0
- package/src/stories/story-groups.json +22 -16
- package/src/tokens.json +82 -54
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* source-images — find real, openly licensed pictures of a client's world and
|
|
4
|
+
* record the credit that has to appear on the page.
|
|
5
|
+
*
|
|
6
|
+
* Why: the anti-defaults say stock or abstract imagery standing in for the
|
|
7
|
+
* product is placeholder content, but until now BADS had no way to find the
|
|
8
|
+
* real thing. A marketing page for a harbor cafe is better with the harbor than
|
|
9
|
+
* with a gradient. The approach, searching open archives with the credit kept
|
|
10
|
+
* beside the file, is from Leonxlnx/taste-skill (MIT). This is a separate,
|
|
11
|
+
* smaller implementation: three key-free sources, an explicit license allowlist,
|
|
12
|
+
* and a credits file that can't be skipped.
|
|
13
|
+
*
|
|
14
|
+
* Sources (no API keys):
|
|
15
|
+
* openverse api.openverse.org CC-licensed photographs
|
|
16
|
+
* met Metropolitan Museum Open Access, public domain only
|
|
17
|
+
* commons Wikimedia Commons license read from each file's metadata
|
|
18
|
+
*
|
|
19
|
+
* Licenses allowed by default: CC0, public domain, CC BY.
|
|
20
|
+
* --allow-sa also allows CC BY-SA. Its share-alike term applies to adaptations
|
|
21
|
+
* of the picture, so confirm with the client before using it.
|
|
22
|
+
* Never allowed: NonCommercial, NoDerivatives, or a license it can't identify.
|
|
23
|
+
*
|
|
24
|
+
* Usage (from the project root):
|
|
25
|
+
* bads-source-images --query "cork harbour ferry" search, print candidates
|
|
26
|
+
* bads-source-images --query "cork harbour ferry" --download also save them
|
|
27
|
+
* options: --source openverse,met,commons --count 6 --out public/images/sourced --allow-sa
|
|
28
|
+
*
|
|
29
|
+
* A downloaded picture is only usable with its credit. credits.json in the output
|
|
30
|
+
* folder holds it; put the attribution on the page near the image, and write real
|
|
31
|
+
* alt text. Check each picture yourself: an open license says nothing about who
|
|
32
|
+
* is in it or whether the scene is right for the client.
|
|
33
|
+
*
|
|
34
|
+
* Network: this needs internet. The hosts above must be reachable.
|
|
35
|
+
*/
|
|
36
|
+
import fs from "node:fs";
|
|
37
|
+
import path from "node:path";
|
|
38
|
+
import { fileURLToPath } from "node:url";
|
|
39
|
+
|
|
40
|
+
export const SOURCES = ["openverse", "met", "commons"];
|
|
41
|
+
export const MAX_BYTES = 15 * 1024 * 1024;
|
|
42
|
+
export const IMAGE_TYPES = { "image/jpeg": "jpg", "image/png": "png", "image/webp": "webp" };
|
|
43
|
+
const UA = "bads-source-images/1.0 (design-system tooling; contact: see the project's repository)";
|
|
44
|
+
|
|
45
|
+
/** Classify a license string from any source into one code. */
|
|
46
|
+
export function licenseCode(raw) {
|
|
47
|
+
const s = String(raw || "").toLowerCase().replace(/[_\s]+/g, "-");
|
|
48
|
+
if (!s) return "unknown";
|
|
49
|
+
if (/(^|-)nc(-|$)|noncommercial/.test(s)) return "nc";
|
|
50
|
+
if (/(^|-)nd(-|$)|noderiv/.test(s)) return "nd";
|
|
51
|
+
if (/cc0|cc-zero|zero|publicdomain\/zero/.test(s)) return "cc0";
|
|
52
|
+
if (/(^|-)pdm(-|$)|public-?domain/.test(s)) return "pdm";
|
|
53
|
+
if (/by-sa|sharealike/.test(s)) return "by-sa";
|
|
54
|
+
if (/(^|-)by(-|$)|attribution/.test(s)) return "by";
|
|
55
|
+
return "unknown";
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function isAllowed(code, { allowSa = false } = {}) {
|
|
59
|
+
return ["cc0", "pdm", "by"].includes(code) || (allowSa && code === "by-sa");
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const stripHtml = (s) => String(s || "").replace(/<[^>]*>/g, "").replace(/&/g, "&").replace(/"/g, '"').replace(/'/g, "'").replace(/\s+/g, " ").trim();
|
|
63
|
+
export const slugify = (s) => String(s || "image").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "").slice(0, 60) || "image";
|
|
64
|
+
|
|
65
|
+
/** The credit line a page should show next to the picture. */
|
|
66
|
+
export function attributionLine(c) {
|
|
67
|
+
if (c.license === "cc0" || c.license === "pdm") return `${c.title}${c.creator ? ` by ${c.creator}` : ""} (${c.sourceName}, public domain)`;
|
|
68
|
+
const lic = { by: "CC BY", "by-sa": "CC BY-SA" }[c.license] || c.license;
|
|
69
|
+
return `"${c.title}"${c.creator ? ` by ${c.creator}` : ""}, ${lic}${c.licenseUrl ? ` (${c.licenseUrl})` : ""}, via ${c.sourceName}`;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async function getJson(fetchFn, url) {
|
|
73
|
+
const res = await fetchFn(url, { headers: { "User-Agent": UA, Accept: "application/json" } });
|
|
74
|
+
if (!res.ok) throw new Error(`${new URL(url).host} answered ${res.status}`);
|
|
75
|
+
return res.json();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export async function searchOpenverse(q, { fetch: f = fetch, count = 6 } = {}) {
|
|
79
|
+
const url = `https://api.openverse.org/v1/images/?${new URLSearchParams({ q, license_type: "commercial", category: "photograph", page_size: String(Math.min(20, count * 3)) })}`;
|
|
80
|
+
const data = await getJson(f, url);
|
|
81
|
+
return (data.results || []).filter((r) => r.url).map((r) => ({
|
|
82
|
+
source: "openverse", sourceName: r.source || "Openverse", id: String(r.id), title: stripHtml(r.title) || "Untitled", creator: stripHtml(r.creator),
|
|
83
|
+
license: licenseCode(r.license), licenseUrl: r.license_url || "", landingUrl: r.foreign_landing_url || "", imageUrl: r.url, width: r.width, height: r.height,
|
|
84
|
+
}));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export async function searchMet(q, { fetch: f = fetch, count = 6 } = {}) {
|
|
88
|
+
const found = await getJson(f, `https://collectionapi.metmuseum.org/public/collection/v1/search?${new URLSearchParams({ q, hasImages: "true", isPublicDomain: "true" })}`);
|
|
89
|
+
const ids = (found.objectIDs || []).slice(0, count * 2);
|
|
90
|
+
const out = [];
|
|
91
|
+
for (const id of ids) {
|
|
92
|
+
try {
|
|
93
|
+
const o = await getJson(f, `https://collectionapi.metmuseum.org/public/collection/v1/objects/${id}`);
|
|
94
|
+
if (!o.isPublicDomain || !o.primaryImage) continue;
|
|
95
|
+
out.push({ source: "met", sourceName: "The Metropolitan Museum of Art", id: String(id), title: o.title || "Untitled", creator: o.artistDisplayName || "", license: "pdm", licenseUrl: "https://www.metmuseum.org/about-the-met/policies-and-documents/open-access", landingUrl: o.objectURL || "", imageUrl: o.primaryImage, width: undefined, height: undefined });
|
|
96
|
+
} catch { /* one bad object shouldn't sink the search */ }
|
|
97
|
+
}
|
|
98
|
+
return out;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export async function searchCommons(q, { fetch: f = fetch, count = 6 } = {}) {
|
|
102
|
+
const params = new URLSearchParams({ action: "query", generator: "search", gsrnamespace: "6", gsrsearch: `${q} filetype:bitmap`, gsrlimit: String(Math.min(30, count * 3)), prop: "imageinfo", iiprop: "url|extmetadata|size|mime", iiurlwidth: "1600", format: "json", origin: "*" });
|
|
103
|
+
const data = await getJson(f, `https://commons.wikimedia.org/w/api.php?${params}`);
|
|
104
|
+
return Object.values(data.query?.pages || {}).map((p) => {
|
|
105
|
+
const ii = p.imageinfo?.[0];
|
|
106
|
+
if (!ii || !(ii.mime in IMAGE_TYPES)) return null;
|
|
107
|
+
const m = ii.extmetadata || {};
|
|
108
|
+
const lic = m.LicenseShortName?.value || m.License?.value || "";
|
|
109
|
+
return { source: "commons", sourceName: "Wikimedia Commons", id: String(p.pageid), title: stripHtml(p.title).replace(/^File:/, "").replace(/\.[a-z]+$/i, ""), creator: stripHtml(m.Artist?.value), license: licenseCode(lic), licenseUrl: m.LicenseUrl?.value || "", landingUrl: ii.descriptionurl || "", imageUrl: ii.thumburl || ii.url, width: ii.thumbwidth || ii.width, height: ii.thumbheight || ii.height };
|
|
110
|
+
}).filter(Boolean);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const SEARCHERS = { openverse: searchOpenverse, met: searchMet, commons: searchCommons };
|
|
114
|
+
|
|
115
|
+
/** Search the chosen sources, drop anything the license rules reject, and report why. */
|
|
116
|
+
export async function search(q, { sources = SOURCES, count = 6, allowSa = false, fetch: f = fetch } = {}) {
|
|
117
|
+
const candidates = [], rejected = { license: 0 }, errors = [];
|
|
118
|
+
for (const s of sources) {
|
|
119
|
+
try {
|
|
120
|
+
for (const c of await SEARCHERS[s](q, { fetch: f, count })) {
|
|
121
|
+
if (isAllowed(c.license, { allowSa })) candidates.push(c);
|
|
122
|
+
else rejected.license += 1;
|
|
123
|
+
}
|
|
124
|
+
} catch (e) { errors.push(`${s}: ${e.message}`); }
|
|
125
|
+
}
|
|
126
|
+
// Spread across sources, so one source with many hits doesn't crowd out the rest.
|
|
127
|
+
const bySource = sources.map((s) => candidates.filter((c) => c.source === s));
|
|
128
|
+
const picked = [];
|
|
129
|
+
for (let i = 0; picked.length < count && bySource.some((l) => i < l.length); i++) for (const l of bySource) if (l[i] && picked.length < count) picked.push(l[i]);
|
|
130
|
+
return { candidates: picked, rejected, errors };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** Save one candidate. Throws on a wrong type or an oversize file, and never leaves a partial file. */
|
|
134
|
+
export async function download(c, dir, { fetch: f = fetch } = {}) {
|
|
135
|
+
const res = await f(c.imageUrl, { headers: { "User-Agent": UA } });
|
|
136
|
+
if (!res.ok) throw new Error(`download answered ${res.status}`);
|
|
137
|
+
const type = (res.headers.get("content-type") || "").split(";")[0].trim().toLowerCase();
|
|
138
|
+
if (!(type in IMAGE_TYPES)) throw new Error(`unexpected type "${type}", only jpeg, png and webp are saved`);
|
|
139
|
+
const buf = Buffer.from(await res.arrayBuffer());
|
|
140
|
+
if (buf.length > MAX_BYTES) throw new Error(`${(buf.length / 1048576).toFixed(1)} MB is over the ${MAX_BYTES / 1048576} MB limit`);
|
|
141
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
142
|
+
const file = path.join(dir, `${c.source}-${slugify(c.title)}-${slugify(c.id).slice(0, 12)}.${IMAGE_TYPES[type]}`);
|
|
143
|
+
fs.writeFileSync(file, buf);
|
|
144
|
+
return file;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** Add an entry to credits.json, replacing one for the same file. */
|
|
148
|
+
export function recordCredit(dir, c, file, now = new Date()) {
|
|
149
|
+
const p = path.join(dir, "credits.json");
|
|
150
|
+
const all = fs.existsSync(p) ? JSON.parse(fs.readFileSync(p, "utf8")) : [];
|
|
151
|
+
const entry = { file: path.basename(file), title: c.title, creator: c.creator, license: c.license, licenseUrl: c.licenseUrl, source: c.sourceName, landingUrl: c.landingUrl, attribution: attributionLine(c), retrievedAt: now.toISOString().slice(0, 10) };
|
|
152
|
+
fs.writeFileSync(p, JSON.stringify([...all.filter((e) => e.file !== entry.file), entry], null, 2) + "\n");
|
|
153
|
+
return entry;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
async function main(argv) {
|
|
157
|
+
const arg = (n, d) => { const i = argv.indexOf(n); return i >= 0 ? argv[i + 1] : d; };
|
|
158
|
+
const q = arg("--query");
|
|
159
|
+
if (!q) { console.error('usage: bads-source-images --query "..." [--download] [--source openverse,met,commons] [--count 6] [--out public/images/sourced] [--allow-sa]'); return 2; }
|
|
160
|
+
const sources = arg("--source", SOURCES.join(",")).split(",").map((s) => s.trim()).filter(Boolean);
|
|
161
|
+
const bad = sources.filter((s) => !SOURCES.includes(s));
|
|
162
|
+
if (bad.length) { console.error(`unknown source: ${bad.join(", ")}. Use ${SOURCES.join(", ")}.`); return 2; }
|
|
163
|
+
const count = Number(arg("--count", 6)), out = path.resolve(arg("--out", "public/images/sourced")), allowSa = argv.includes("--allow-sa");
|
|
164
|
+
const { candidates, rejected, errors } = await search(q, { sources, count, allowSa });
|
|
165
|
+
for (const e of errors) console.error(` ! ${e}`);
|
|
166
|
+
if (!candidates.length) { console.log(`No usable pictures for "${q}".${rejected.license ? ` ${rejected.license} found with a license that isn't allowed.` : ""}${errors.length ? " Some sources failed (above)." : ""}`); return errors.length === sources.length ? 1 : 0; }
|
|
167
|
+
console.log(`${candidates.length} candidate${candidates.length === 1 ? "" : "s"} for "${q}" (${rejected.license} skipped for license):\n`);
|
|
168
|
+
for (const [i, c] of candidates.entries()) {
|
|
169
|
+
console.log(`${i + 1}. ${c.title}${c.creator ? ` — ${c.creator}` : ""}\n ${c.sourceName} · ${c.license.toUpperCase()}${c.width ? ` · ${c.width}×${c.height}` : ""}\n ${c.landingUrl || c.imageUrl}`);
|
|
170
|
+
if (argv.includes("--download")) {
|
|
171
|
+
try { const file = await download(c, out); recordCredit(out, c, file); console.log(` saved ${path.relative(process.cwd(), file)}`); } catch (e) { console.log(` not saved: ${e.message}`); }
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
console.log(argv.includes("--download")
|
|
175
|
+
? `\nCredits are in ${path.relative(process.cwd(), path.join(out, "credits.json"))}. Show each credit near its picture, write real alt text, and check the picture fits the client.`
|
|
176
|
+
: "\nNothing saved. Add --download to save these with their credits.");
|
|
177
|
+
return 0;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (process.argv[1] && fileURLToPath(import.meta.url) === path.resolve(process.argv[1])) process.exit(await main(process.argv.slice(2)));
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* ux-tells — open a page in a real browser at three widths and fail it on the
|
|
4
|
+
* signals that make a page read as generated: gradient text, indigo gradients,
|
|
5
|
+
* stacks of glass panels, glows, the stock three-icon-card row, a pill above the
|
|
6
|
+
* headline, decorative emoji, pulsing dots, placeholder copy and images, and
|
|
7
|
+
* sideways scrolling. It saves a screenshot of each width so someone can look.
|
|
8
|
+
*
|
|
9
|
+
* It reads computed styles, so it catches what lint-slop's source scan can't:
|
|
10
|
+
* classes built at runtime and the effect of the cascade. It runs on any URL, so
|
|
11
|
+
* a client's marketing page, a preview route, or a deployed site all work.
|
|
12
|
+
* Reduced motion is emulated, so a reading doesn't depend on an animation frame.
|
|
13
|
+
*
|
|
14
|
+
* Usage:
|
|
15
|
+
* bads-ux-tells <url> [--widths 375,768,1280] [--out .ux-tells] [--json] [--warn]
|
|
16
|
+
*
|
|
17
|
+
* Exit 1 when any banned tell is found (0 with --warn). Warned tells are listed
|
|
18
|
+
* and need a reason, not a fix. Rules and rationale: lib/tells.mjs.
|
|
19
|
+
*
|
|
20
|
+
* Needs Playwright and a Chromium: `pnpm install` in the repo, or set PW_CHROMIUM.
|
|
21
|
+
*/
|
|
22
|
+
import fs from "node:fs";
|
|
23
|
+
import path from "node:path";
|
|
24
|
+
import { fileURLToPath } from "node:url";
|
|
25
|
+
import { WIDTHS, TELLS, probeSource, classify, merge } from "./lib/tells.mjs";
|
|
26
|
+
|
|
27
|
+
function chromiumExecutable() {
|
|
28
|
+
if (process.env.PW_CHROMIUM && fs.existsSync(process.env.PW_CHROMIUM)) return process.env.PW_CHROMIUM;
|
|
29
|
+
for (const c of ["/opt/pw-browsers/chromium-1194/chrome-linux/chrome", "/opt/pw-browsers/chromium/chrome-linux/chrome"]) if (fs.existsSync(c)) return c;
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Check one URL at each width. Returns { findings, screenshots }. */
|
|
34
|
+
export async function check(url, { widths = WIDTHS, out = ".ux-tells", chromium } = {}) {
|
|
35
|
+
if (!chromium) ({ chromium } = await import("playwright"));
|
|
36
|
+
fs.mkdirSync(out, { recursive: true });
|
|
37
|
+
const exe = chromiumExecutable();
|
|
38
|
+
const browser = await chromium.launch(exe ? { executablePath: exe } : {});
|
|
39
|
+
const perWidth = [], screenshots = [];
|
|
40
|
+
try {
|
|
41
|
+
for (const width of widths) {
|
|
42
|
+
const ctx = await browser.newContext({ viewport: { width, height: 900 }, reducedMotion: "reduce", deviceScaleFactor: 1 });
|
|
43
|
+
const page = await ctx.newPage();
|
|
44
|
+
const res = await page.goto(url, { waitUntil: "networkidle", timeout: 60000 }).catch(() => null);
|
|
45
|
+
if (!res || !res.ok()) { await ctx.close(); throw new Error(`could not load ${url} at ${width}px`); }
|
|
46
|
+
await page.evaluate(() => document.fonts && document.fonts.ready);
|
|
47
|
+
perWidth.push(classify(await page.evaluate(probeSource()), width));
|
|
48
|
+
for (const [kind, full] of [["fold", false], ["page", true]]) {
|
|
49
|
+
const file = path.join(out, `${width}-${kind}.jpg`);
|
|
50
|
+
await page.screenshot({ path: file, fullPage: full, type: "jpeg", quality: 80 });
|
|
51
|
+
screenshots.push(file);
|
|
52
|
+
}
|
|
53
|
+
await ctx.close();
|
|
54
|
+
}
|
|
55
|
+
} finally { await browser.close(); }
|
|
56
|
+
return { findings: merge(perWidth), screenshots };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async function main(argv) {
|
|
60
|
+
const url = argv.find((a) => /^https?:\/\/|^file:\/\//.test(a));
|
|
61
|
+
if (!url) { console.error("usage: bads-ux-tells <url> [--widths 375,768,1280] [--out .ux-tells] [--json] [--warn]"); return 2; }
|
|
62
|
+
const arg = (n, d) => { const i = argv.indexOf(n); return i >= 0 ? argv[i + 1] : d; };
|
|
63
|
+
const widths = arg("--widths", WIDTHS.join(",")).split(",").map(Number).filter((n) => n >= 280 && n <= 3000);
|
|
64
|
+
let result;
|
|
65
|
+
try { result = await check(url, { widths, out: arg("--out", ".ux-tells") }); } catch (e) { console.error(`ux-tells: ${e.message}`); return 2; }
|
|
66
|
+
const banned = result.findings.filter((f) => f.status === "banned"), warned = result.findings.filter((f) => f.status === "warned");
|
|
67
|
+
if (argv.includes("--json")) console.log(JSON.stringify(result, null, 2));
|
|
68
|
+
else {
|
|
69
|
+
console.log(`ux-tells ${url} (${widths.join(", ")}px)`);
|
|
70
|
+
for (const f of [...banned, ...warned]) console.log(` ${f.status === "banned" ? "✗ banned" : "⚠ warned"} ${f.name} [${f.code}] at ${f.widths.join("/")}px: ${f.detail}\n ${f.why}`);
|
|
71
|
+
console.log(banned.length || warned.length ? "" : " No tells found.");
|
|
72
|
+
console.log(`${banned.length} banned, ${warned.length} warned. ${TELLS.length} rules. Screenshots: ${path.dirname(result.screenshots[0])}`);
|
|
73
|
+
console.log("Look at the screenshots too. This finds the objective tells, and says nothing about whether the page is any good.");
|
|
74
|
+
}
|
|
75
|
+
return banned.length && !argv.includes("--warn") ? 1 : 0;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (process.argv[1] && fileURLToPath(import.meta.url) === path.resolve(process.argv[1])) process.exit(await main(process.argv.slice(2)));
|
package/src/api/brand-colors.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { NextResponse } from "next/server";
|
|
4
|
+
import { refuseUnsafeWrite } from "./dev-write-guard";
|
|
4
5
|
|
|
5
6
|
const COLORS_PATH = path.join(process.cwd(), "brand-colors.json");
|
|
6
7
|
|
|
@@ -63,6 +64,8 @@ export async function POST(request: Request) {
|
|
|
63
64
|
if (process.env.NODE_ENV !== "development") {
|
|
64
65
|
return NextResponse.json({ ok: false, error: "dev-only" }, { status: 403 });
|
|
65
66
|
}
|
|
67
|
+
const refused = refuseUnsafeWrite(request);
|
|
68
|
+
if (refused) return refused;
|
|
66
69
|
|
|
67
70
|
let op: Op;
|
|
68
71
|
try {
|
package/src/api/brand-fonts.ts
CHANGED
|
@@ -2,6 +2,7 @@ import fs from "node:fs/promises";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { spawn } from "node:child_process";
|
|
4
4
|
import { NextResponse } from "next/server";
|
|
5
|
+
import { refuseUnsafeWrite } from "./dev-write-guard";
|
|
5
6
|
|
|
6
7
|
const FONTS_PATH = path.join(process.cwd(), "brand-fonts.json");
|
|
7
8
|
// Canonical location — ships with the npm package via the `./fonts/*` export.
|
|
@@ -120,6 +121,8 @@ export async function POST(request: Request) {
|
|
|
120
121
|
if (process.env.NODE_ENV !== "development") {
|
|
121
122
|
return NextResponse.json({ ok: false, error: "dev-only" }, { status: 403 });
|
|
122
123
|
}
|
|
124
|
+
const refused = refuseUnsafeWrite(request);
|
|
125
|
+
if (refused) return refused;
|
|
123
126
|
|
|
124
127
|
const contentType = request.headers.get("content-type") ?? "";
|
|
125
128
|
|
package/src/api/brand-mark.ts
CHANGED
|
@@ -2,6 +2,7 @@ import fs from "node:fs/promises";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { NextResponse } from "next/server";
|
|
4
4
|
import { sanitizeSvg } from "@behavioral-agentic-design-system/core/lib/svg-sanitize";
|
|
5
|
+
import { refuseUnsafeWrite } from "./dev-write-guard";
|
|
5
6
|
|
|
6
7
|
const MARK_PATH = path.join(process.cwd(), "brand-mark.json");
|
|
7
8
|
const PUBLIC_PATH = path.join(process.cwd(), "public", "brand-mark.svg");
|
|
@@ -58,6 +59,8 @@ export async function POST(request: Request) {
|
|
|
58
59
|
if (process.env.NODE_ENV !== "development") {
|
|
59
60
|
return NextResponse.json({ ok: false, error: "dev-only" }, { status: 403 });
|
|
60
61
|
}
|
|
62
|
+
const refused = refuseUnsafeWrite(request);
|
|
63
|
+
if (refused) return refused;
|
|
61
64
|
|
|
62
65
|
let body: { svg?: string };
|
|
63
66
|
try {
|
|
@@ -116,10 +119,12 @@ export async function POST(request: Request) {
|
|
|
116
119
|
});
|
|
117
120
|
}
|
|
118
121
|
|
|
119
|
-
export async function DELETE() {
|
|
122
|
+
export async function DELETE(request: Request) {
|
|
120
123
|
if (process.env.NODE_ENV !== "development") {
|
|
121
124
|
return NextResponse.json({ ok: false, error: "dev-only" }, { status: 403 });
|
|
122
125
|
}
|
|
126
|
+
const refused = refuseUnsafeWrite(request);
|
|
127
|
+
if (refused) return refused;
|
|
123
128
|
|
|
124
129
|
let existing: MarkFile;
|
|
125
130
|
try {
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// Who may call a dev-only write route.
|
|
2
|
+
//
|
|
3
|
+
// WHY THIS EXISTS. These routes write files on your computer (tokens, docs, fonts, the brand mark) and one of
|
|
4
|
+
// them runs `git commit`. A page open in the same browser can send requests to localhost, and a hostile name
|
|
5
|
+
// that points at 127.0.0.1 (DNS rebinding) reaches the dev server as if it were local. The NODE_ENV check alone
|
|
6
|
+
// answers neither. This is the same Host / Origin / content-type reasoning as tools/comments/server/comments-guard.mjs,
|
|
7
|
+
// without that guard's custom header, so the app's own same-origin fetches keep working unchanged.
|
|
8
|
+
//
|
|
9
|
+
// 1. Host must be localhost, 127.0.0.1 or [::1]. A rebound name arrives with its own name here and is refused.
|
|
10
|
+
// 2. Origin when present (every request a web page makes carries one) must be the same origin as Host.
|
|
11
|
+
// 3. Fetch Sec-Fetch-Site, when present, must be same-origin or none.
|
|
12
|
+
// 4. Type a body must be application/json or multipart/form-data. A cross-site form post cannot send JSON.
|
|
13
|
+
//
|
|
14
|
+
// A request from curl has no Origin and passes gates 2 and 3, so local tools still work.
|
|
15
|
+
//
|
|
16
|
+
// KEEP IN SYNC with app/api/_lib/dev-write-guard.ts: app/api routes are inlined copies of these handlers
|
|
17
|
+
// (see app/api/layers/file/route.ts for why), so they cannot import across the workspace.
|
|
18
|
+
|
|
19
|
+
const LOCAL_HOST = /^(localhost|127\.0\.0\.1|\[::1\])(:\d{1,5})?$/;
|
|
20
|
+
const BODY_TYPE = /^(application\/json|multipart\/form-data)\s*(;|$)/i;
|
|
21
|
+
|
|
22
|
+
/** A 403/415 Response when the request may not write, or null when it may go on. */
|
|
23
|
+
export function refuseUnsafeWrite(request: Request): Response | null {
|
|
24
|
+
const h = request.headers;
|
|
25
|
+
const host = h.get("host") ?? "";
|
|
26
|
+
if (!LOCAL_HOST.test(host)) return deny(403, "This route only answers requests addressed to localhost.");
|
|
27
|
+
|
|
28
|
+
const origin = h.get("origin");
|
|
29
|
+
if (origin !== null) {
|
|
30
|
+
let originHost = "";
|
|
31
|
+
try {
|
|
32
|
+
originHost = new URL(origin).host;
|
|
33
|
+
} catch {
|
|
34
|
+
// An unparseable Origin (including the literal "null") is never a local page.
|
|
35
|
+
}
|
|
36
|
+
if (originHost !== host) return deny(403, "This route only answers pages served from this server.");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const site = h.get("sec-fetch-site");
|
|
40
|
+
if (site !== null && site !== "same-origin" && site !== "none") {
|
|
41
|
+
return deny(403, "This route only answers pages served from this server.");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const hasBody = request.method === "POST" || request.method === "PUT" || request.method === "PATCH";
|
|
45
|
+
if (hasBody && !BODY_TYPE.test(h.get("content-type") ?? "")) {
|
|
46
|
+
return deny(415, "Send application/json.");
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function deny(status: number, error: string): Response {
|
|
52
|
+
return Response.json({ ok: false, error }, { status });
|
|
53
|
+
}
|
package/src/api/layers/file.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
2
|
import fs from "node:fs";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { promisify } from "node:util";
|
|
5
|
+
import { refuseUnsafeWrite } from "../dev-write-guard";
|
|
5
6
|
|
|
6
|
-
const
|
|
7
|
+
const execFileAsync = promisify(execFile);
|
|
7
8
|
const ROOT = process.cwd();
|
|
8
9
|
|
|
9
10
|
// Read allowlist. Reads are public (open-source docs) so we expand freely to
|
|
@@ -78,6 +79,8 @@ export async function POST(request: Request) {
|
|
|
78
79
|
if (process.env.NODE_ENV !== "development") {
|
|
79
80
|
return Response.json({ error: "dev-only" }, { status: 403 });
|
|
80
81
|
}
|
|
82
|
+
const refused = refuseUnsafeWrite(request);
|
|
83
|
+
if (refused) return refused;
|
|
81
84
|
try {
|
|
82
85
|
const body = (await request.json()) as {
|
|
83
86
|
path: string;
|
|
@@ -93,10 +96,10 @@ export async function POST(request: Request) {
|
|
|
93
96
|
|
|
94
97
|
if (body.commit !== false) {
|
|
95
98
|
const message = body.message?.trim() || `docs: edit ${body.path}`;
|
|
96
|
-
await
|
|
99
|
+
await execFileAsync("git", ["add", "--", body.path], { cwd: ROOT });
|
|
97
100
|
// --allow-empty so saves with no diff don't error; precommit hook still runs.
|
|
98
101
|
try {
|
|
99
|
-
await
|
|
102
|
+
await execFileAsync("git", ["commit", "-m", message], { cwd: ROOT });
|
|
100
103
|
} catch (e) {
|
|
101
104
|
// No diff is fine. Anything else surfaces as an error.
|
|
102
105
|
const msg = e instanceof Error ? e.message : String(e);
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { NextResponse } from "next/server";
|
|
2
|
+
import { lookup } from "node:dns/promises";
|
|
3
|
+
import { isIP } from "node:net";
|
|
2
4
|
import { load, type CheerioAPI } from "cheerio";
|
|
5
|
+
import { refuseUnsafeWrite } from "./dev-write-guard";
|
|
6
|
+
import { sanitizeSvg } from "../lib/svg-sanitize";
|
|
3
7
|
|
|
4
8
|
const FETCH_TIMEOUT_MS = 12_000;
|
|
5
9
|
const USER_AGENT = "Mozilla/5.0 (compatible; BADS-Onboarding/1.0)";
|
|
@@ -40,39 +44,82 @@ export type ExtractResult = {
|
|
|
40
44
|
warnings: string[];
|
|
41
45
|
};
|
|
42
46
|
|
|
43
|
-
// SSRF
|
|
44
|
-
//
|
|
45
|
-
// services or the cloud metadata endpoint. This is hostname-literal checking
|
|
46
|
-
// only (it inspects the string the user typed) and is NOT full DNS-rebinding
|
|
47
|
-
// protection — a hostname that resolves to a private IP at fetch time still
|
|
48
|
-
// gets through. Strip the brackets IPv6 hosts arrive wrapped in before testing.
|
|
47
|
+
// SSRF defence: refuse private, internal and loopback targets, whether typed, resolved by DNS, or reached by a
|
|
48
|
+
// redirect. Literal IPv4/IPv6 forms are parsed with node:net rather than matched by prefix.
|
|
49
49
|
function isBlockedHost(hostname: string): boolean {
|
|
50
|
-
const host = hostname.trim().toLowerCase().replace(/^\[|\]$/g, "");
|
|
50
|
+
const host = hostname.trim().toLowerCase().replace(/^\[|\]$/g, "").replace(/\.$/, "");
|
|
51
51
|
if (!host) return true;
|
|
52
52
|
|
|
53
53
|
// localhost and internal-only TLD suffixes
|
|
54
|
-
if (host === "localhost") return true;
|
|
55
|
-
if (/\.local
|
|
54
|
+
if (host === "localhost" || host.endsWith(".localhost")) return true;
|
|
55
|
+
if (/\.(local|internal|localdomain|home\.arpa)$/.test(host)) return true;
|
|
56
56
|
|
|
57
|
-
|
|
58
|
-
if (
|
|
59
|
-
if (
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
// IPv4 unspecified, loopback 127.0.0.0/8, and link-local 169.254.0.0/16
|
|
63
|
-
// (covers the 169.254.169.254 cloud metadata IP)
|
|
64
|
-
if (host === "0.0.0.0") return true;
|
|
65
|
-
if (/^127\./.test(host)) return true;
|
|
66
|
-
if (/^169\.254\./.test(host)) return true;
|
|
57
|
+
const family = isIP(host);
|
|
58
|
+
if (family === 6) return isBlockedIPv6(host);
|
|
59
|
+
if (family === 4) return isBlockedIPv4(host);
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
67
62
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
if (
|
|
71
|
-
if (
|
|
63
|
+
function isBlockedIPv4(ip: string): boolean {
|
|
64
|
+
const [a, b] = ip.split(".").map(Number);
|
|
65
|
+
if (a === 0 || a === 10 || a === 127) return true; // this-network, private, loopback
|
|
66
|
+
if (a === 169 && b === 254) return true; // link-local, incl. the 169.254.169.254 metadata IP
|
|
67
|
+
if (a === 172 && b >= 16 && b <= 31) return true;
|
|
68
|
+
if (a === 192 && b === 168) return true;
|
|
69
|
+
if (a === 100 && b >= 64 && b <= 127) return true; // carrier-grade NAT, also used for internal clouds
|
|
70
|
+
if (a >= 224) return true; // multicast, reserved, broadcast
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
72
73
|
|
|
74
|
+
function isBlockedIPv6(ip: string): boolean {
|
|
75
|
+
if (ip === "::" || ip === "::1") return true;
|
|
76
|
+
if (/^f[cd]/.test(ip) || /^fe[89ab]/.test(ip)) return true; // unique-local fc00::/7, link-local fe80::/10
|
|
77
|
+
// IPv4-mapped (::ffff:a.b.c.d, or ::ffff:7f00:1 once the URL parser has normalized it) and other embeddings
|
|
78
|
+
// of an IPv4 address. Refuse them all rather than decode each form.
|
|
79
|
+
if (/^(0:){0,5}:?ffff:/.test(ip) || /^::ffff:/.test(ip) || /^64:ff9b:/.test(ip) || /^::\d+\.\d+/.test(ip)) return true;
|
|
73
80
|
return false;
|
|
74
81
|
}
|
|
75
82
|
|
|
83
|
+
// A public-looking name can resolve to a private address (an attacker-owned A record pointing at 127.0.0.1 or
|
|
84
|
+
// 169.254.169.254). Resolve first and refuse if ANY answer is private. A name that resolves between this check
|
|
85
|
+
// and the fetch (a rebinding race) is not covered; closing that needs a pinned-IP agent.
|
|
86
|
+
async function resolvesToPublicAddress(hostname: string): Promise<boolean> {
|
|
87
|
+
const host = hostname.replace(/^\[|\]$/g, "");
|
|
88
|
+
if (isIP(host)) return !isBlockedHost(host);
|
|
89
|
+
try {
|
|
90
|
+
const answers = await lookup(host, { all: true });
|
|
91
|
+
return answers.length > 0 && answers.every((a) => !isBlockedHost(a.address));
|
|
92
|
+
} catch {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const MAX_REDIRECTS = 5;
|
|
98
|
+
|
|
99
|
+
// fetch() that checks every hop. The default redirect: "follow" re-requests whatever Location says, so a public
|
|
100
|
+
// page could 302 to http://169.254.169.254/ and the first-URL check would never see it. Stylesheet and logo URLs
|
|
101
|
+
// come from the fetched page, so they go through here too.
|
|
102
|
+
async function safeFetch(
|
|
103
|
+
url: string,
|
|
104
|
+
init: RequestInit,
|
|
105
|
+
): Promise<{ res: Response; finalUrl: string }> {
|
|
106
|
+
let current = url;
|
|
107
|
+
for (let hop = 0; hop <= MAX_REDIRECTS; hop++) {
|
|
108
|
+
const u = new URL(current);
|
|
109
|
+
if (u.protocol !== "https:" && u.protocol !== "http:") throw new Error("Only http(s) URLs can be fetched");
|
|
110
|
+
if (isBlockedHost(u.hostname) || !(await resolvesToPublicAddress(u.hostname))) {
|
|
111
|
+
throw new Error("That address points at a private or internal network");
|
|
112
|
+
}
|
|
113
|
+
const res = await fetch(current, { ...init, redirect: "manual" });
|
|
114
|
+
if (res.status >= 300 && res.status < 400 && res.headers.get("location")) {
|
|
115
|
+
current = new URL(res.headers.get("location") as string, current).toString();
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
return { res, finalUrl: current };
|
|
119
|
+
}
|
|
120
|
+
throw new Error("Too many redirects");
|
|
121
|
+
}
|
|
122
|
+
|
|
76
123
|
function normalizeUrl(input: string): string | null {
|
|
77
124
|
const trimmed = input.trim();
|
|
78
125
|
if (!trimmed) return null;
|
|
@@ -91,20 +138,19 @@ async function fetchHtml(url: string): Promise<{ html: string; finalUrl: string
|
|
|
91
138
|
const controller = new AbortController();
|
|
92
139
|
const timer = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
|
|
93
140
|
try {
|
|
94
|
-
const res = await
|
|
141
|
+
const { res, finalUrl: resolvedUrl } = await safeFetch(url, {
|
|
95
142
|
headers: {
|
|
96
143
|
"User-Agent": USER_AGENT,
|
|
97
144
|
Accept: "text/html,application/xhtml+xml",
|
|
98
145
|
"Accept-Language": "en-US,en;q=0.9",
|
|
99
146
|
},
|
|
100
|
-
redirect: "follow",
|
|
101
147
|
signal: controller.signal,
|
|
102
148
|
});
|
|
103
149
|
if (!res.ok) {
|
|
104
150
|
throw new Error(`Fetch failed: ${res.status} ${res.statusText}`);
|
|
105
151
|
}
|
|
106
152
|
const html = await res.text();
|
|
107
|
-
return { html, finalUrl:
|
|
153
|
+
return { html, finalUrl: resolvedUrl };
|
|
108
154
|
} finally {
|
|
109
155
|
clearTimeout(timer);
|
|
110
156
|
}
|
|
@@ -117,7 +163,7 @@ async function fetchStylesheet(url: string): Promise<string | null> {
|
|
|
117
163
|
try {
|
|
118
164
|
const controller = new AbortController();
|
|
119
165
|
const timer = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
|
|
120
|
-
const res = await
|
|
166
|
+
const { res, finalUrl: resolvedUrl } = await safeFetch(url, {
|
|
121
167
|
headers: { "User-Agent": USER_AGENT, Accept: "text/css,*/*;q=0.1" },
|
|
122
168
|
signal: controller.signal,
|
|
123
169
|
});
|
|
@@ -302,7 +348,7 @@ async function fetchSvg(url: string): Promise<string | null> {
|
|
|
302
348
|
try {
|
|
303
349
|
const controller = new AbortController();
|
|
304
350
|
const timer = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
|
|
305
|
-
const res = await
|
|
351
|
+
const { res, finalUrl: resolvedUrl } = await safeFetch(url, {
|
|
306
352
|
headers: { "User-Agent": USER_AGENT },
|
|
307
353
|
signal: controller.signal,
|
|
308
354
|
});
|
|
@@ -324,7 +370,8 @@ async function extractLogo($: CheerioAPI, baseUrl: string): Promise<ExtractedLog
|
|
|
324
370
|
if (headerSvg.length) {
|
|
325
371
|
const html = $.html(headerSvg);
|
|
326
372
|
if (html && html.length < 16 * 1024) {
|
|
327
|
-
|
|
373
|
+
const clean = sanitizeSvg(html);
|
|
374
|
+
if (clean.ok) return { kind: "svg", svg: clean.svg };
|
|
328
375
|
}
|
|
329
376
|
}
|
|
330
377
|
|
|
@@ -337,7 +384,8 @@ async function extractLogo($: CheerioAPI, baseUrl: string): Promise<ExtractedLog
|
|
|
337
384
|
const abs = new URL(src, baseUrl).toString();
|
|
338
385
|
if (abs.endsWith(".svg")) {
|
|
339
386
|
const svg = await fetchSvg(abs);
|
|
340
|
-
|
|
387
|
+
const clean = svg ? sanitizeSvg(svg) : null;
|
|
388
|
+
if (clean?.ok) return { kind: "svg", svg: clean.svg };
|
|
341
389
|
}
|
|
342
390
|
return { kind: "image", url: abs };
|
|
343
391
|
} catch {}
|
|
@@ -403,6 +451,13 @@ function extractCopy($: CheerioAPI): {
|
|
|
403
451
|
}
|
|
404
452
|
|
|
405
453
|
export async function POST(request: Request) {
|
|
454
|
+
// Fetching an arbitrary URL from the server is only for the local onboarding wizard. On a deployed site it
|
|
455
|
+
// would be an open proxy.
|
|
456
|
+
if (process.env.NODE_ENV !== "development") {
|
|
457
|
+
return NextResponse.json({ ok: false, error: "dev-only" }, { status: 403 });
|
|
458
|
+
}
|
|
459
|
+
const refused = refuseUnsafeWrite(request);
|
|
460
|
+
if (refused) return refused;
|
|
406
461
|
let payload: { url?: string };
|
|
407
462
|
try {
|
|
408
463
|
payload = (await request.json()) as { url?: string };
|
package/src/api/onboarding.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { NextResponse } from "next/server";
|
|
4
|
+
import { refuseUnsafeWrite } from "./dev-write-guard";
|
|
4
5
|
|
|
5
6
|
const ONBOARDING_PATH = path.join(process.cwd(), "onboarding-brief.json");
|
|
6
7
|
|
|
@@ -38,6 +39,8 @@ export async function POST(request: Request) {
|
|
|
38
39
|
if (process.env.NODE_ENV !== "development") {
|
|
39
40
|
return NextResponse.json({ ok: false, error: "dev-only" }, { status: 403 });
|
|
40
41
|
}
|
|
42
|
+
const refused = refuseUnsafeWrite(request);
|
|
43
|
+
if (refused) return refused;
|
|
41
44
|
|
|
42
45
|
let payload: SavePayload;
|
|
43
46
|
try {
|
package/src/api/save-tokens.ts
CHANGED
|
@@ -3,6 +3,7 @@ import fs from "node:fs/promises";
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { promisify } from "node:util";
|
|
5
5
|
import { NextResponse } from "next/server";
|
|
6
|
+
import { refuseUnsafeWrite } from "./dev-write-guard";
|
|
6
7
|
|
|
7
8
|
const execAsync = promisify(exec);
|
|
8
9
|
const TOKENS_PATH = path.join(process.cwd(), "packages/core/src/tokens.json");
|
|
@@ -89,6 +90,8 @@ export async function POST(request: Request) {
|
|
|
89
90
|
{ status: 403 },
|
|
90
91
|
);
|
|
91
92
|
}
|
|
93
|
+
const refused = refuseUnsafeWrite(request);
|
|
94
|
+
if (refused) return refused;
|
|
92
95
|
|
|
93
96
|
let payload: SavePayload;
|
|
94
97
|
try {
|
package/src/app/layout.tsx
CHANGED
|
@@ -262,6 +262,12 @@ export default function RootLayout({
|
|
|
262
262
|
if (typeof t.ratio === "number") ratio = t.ratio;
|
|
263
263
|
} catch (e) {}
|
|
264
264
|
}
|
|
265
|
+
// Enforce the 14px text-xs floor (WCAG 1.4.4) on the persisted
|
|
266
|
+
// value too. Mirrors applyScale() in use-global-type-scale.ts;
|
|
267
|
+
// without it base 18 / ratio 1.4 booted text-xs at ~9.18px
|
|
268
|
+
// until a slider moved. Lower ratio first, then raise base.
|
|
269
|
+
ratio = Math.max(1.05, Math.min(ratio, 1.4, Math.sqrt(base / 14)));
|
|
270
|
+
base = Math.min(22, Math.max(base, 14 * ratio * ratio));
|
|
265
271
|
for (var name in STEPS) {
|
|
266
272
|
var step = STEPS[name];
|
|
267
273
|
var size = base * Math.pow(ratio, step);
|