export declare const LOOK_SCHEMA_ID: "cartwright-composition-v1"; /** Fetch timeout — a slow look server must not hang the scaffold. */ export declare const LOOK_FETCH_TIMEOUT_MS = 10000; /** Cap on the response body — a look is a small JSON file, not a download. */ export declare const LOOK_MAX_BYTES = 1000000; /** The 6-token brand palette — same shape as the engine's themeJson. */ export type LookPalette = { accent: string; accentDeep: string; cream: string; sand: string; ink: string; muted: string; }; export declare const LOOK_PALETTE_KEYS: ReadonlyArray; /** * The public subset of cartwright-composition-v1 this flag consumes (mirror * of the engine's toPublicLook projection). voice/homepageLayout never travel * over the public endpoint and are deliberately not modelled here. */ export type PublicLook = { schema: typeof LOOK_SCHEMA_ID; /** Display name for the success line; falls back to the skin slug. */ name?: string; /** Design slug — the Skin. */ skin: string; palette?: LookPalette; scene?: string; chrome?: { headerKey?: string; footerKey?: string; }; }; export type ParseLookResult = { ok: true; look: PublicLook; } | { ok: false; error: string; }; /** * Minimal structural validation of a look JSON string — the CLI cannot check * registry membership (that knowledge lives in the engine), so it validates * shape only: `schema` must be the composition-v1 id, `skin` a design slug, * and the optional palette/scene/chrome parts must match the spec's shapes. * Invalid optional parts reject the WHOLE look (never half-apply a corrupt * artifact — same philosophy as the engine's applyComposition). Unknown extra * fields (voice, homepageLayout, description …) are ignored. */ export declare function parseLook(raw: string): ParseLookResult; export type FetchLookResult = { ok: true; look: PublicLook; } | { ok: false; error: string; }; /** * Fetch + validate a look URL. Built-in `fetch` only (no new dependency), * 10 s timeout, 1 MB body cap. `fetchImpl` is injectable for unit tests. */ export declare function fetchLook(url: string, fetchImpl?: typeof fetch): Promise; export type StageSkinResult = { /** true when brand.config.ts now carries the look's designSlug. */ applied: boolean; warnings: string[]; }; /** * Set the look's skin as the scaffold's designSlug — IF the scaffold ships * that design pack. `designs//` on disk is the ground truth for both * profiles (the light profile prunes non-curated packs; future templates may * add or remove packs). A missing pack warns + skips the skin while the rest * of the look (palette/scene/chrome) still applies — fail-soft default per * the profile contract, with the re-install hint. */ export declare function stageLookSkin(targetDir: string, look: PublicLook): StageSkinResult; /** True when the look carries DB-backed parts (anything beyond the skin). */ export declare function lookHasDbParts(look: PublicLook): boolean; /** * The temp script that writes the look's DB parts using the SCAFFOLD's own * node_modules (`@libsql/client` is a direct engine dependency — the same * client the engine's db:setup fallback uses). Static source — the look JSON * and store name travel via env vars, all SQL is parameterized, so no data is * ever interpolated into code or SQL. * * Field formats mirror the engine's applyComposition exactly: * - themeJson = JSON.stringify(palette) (6-color object) * - chromeJson = JSON.stringify({ headerKey?, footerKey? }) * - threeDConfigJson = JSON.stringify({ ...existing, scene }) (scene merged * over the current 3D config so intensity/paletteSource survive) * * Env resolution mirrors the scaffold's prisma.config.ts precedence: * .env.local (override) > process.env > .env; Turso when both TURSO_* vars are * set, else DATABASE_URL, else file:./dev.db. Postgres is skipped (libsql * client can't reach it) with a pointer to composition.apply. */ export declare const LOOK_DB_SCRIPT = "// Temp script written by create-cartwright --look; deleted after the run.\nimport { readFileSync, existsSync } from \"node:fs\";\nimport { createClient } from \"@libsql/client\";\n\nconst ERR = (msg) => {\n console.log(\"CARTWRIGHT_LOOK_DB_ERR \" + msg);\n process.exit(1);\n};\n\nconst look = JSON.parse(process.env.CARTWRIGHT_LOOK_JSON ?? \"{}\");\n\n// Same aggressive cleaning as the engine's lib/db.ts cleanEnv.\nconst cleanEnv = (raw) => {\n if (!raw) return undefined;\n const stripped = String(raw).replace(/[^\\x20-\\x7E]/g, \"\").trim();\n const unquoted = stripped.replace(/^[\"']|[\"']$/g, \"\");\n return unquoted || undefined;\n};\nconst parseEnvFile = (path) => {\n const out = {};\n if (!existsSync(path)) return out;\n for (const line of readFileSync(path, \"utf8\").split(\"\\n\")) {\n const m = line.match(/^\\s*([A-Za-z_][A-Za-z0-9_]*)\\s*=\\s*(.*)\\s*$/);\n if (m && !line.trimStart().startsWith(\"#\")) out[m[1]] = m[2];\n }\n return out;\n};\n// Precedence mirrors the scaffold's prisma.config.ts: .env, then .env.local\n// with override (so .env.local also beats process.env, like dotenv override).\nconst envFile = parseEnvFile(\".env\");\nconst envLocal = parseEnvFile(\".env.local\");\nconst get = (k) => cleanEnv(envLocal[k] ?? process.env[k] ?? envFile[k]);\n\nconst databaseUrl = get(\"DATABASE_URL\") ?? \"file:./dev.db\";\nif (get(\"DATABASE_DRIVER\") === \"postgres\" || /^postgres(ql)?:/i.test(databaseUrl)) {\n ERR(\"Postgres database \u2014 apply the look later via the composition.apply tool or /admin/designs.\");\n}\nconst tursoUrl = get(\"TURSO_DATABASE_URL\");\nconst tursoToken = get(\"TURSO_AUTH_TOKEN\");\nconst client = createClient(\n tursoUrl && tursoToken ? { url: tursoUrl, authToken: tursoToken } : { url: databaseUrl },\n);\n\ntry {\n const sets = [];\n const args = [];\n if (look.palette) {\n sets.push(\"themeJson = ?\");\n args.push(JSON.stringify(look.palette));\n }\n if (look.chrome && (look.chrome.headerKey || look.chrome.footerKey)) {\n sets.push(\"chromeJson = ?\");\n args.push(JSON.stringify(look.chrome));\n }\n if (look.scene) {\n // Merge the scene over the existing 3D config (fail-soft parse) so\n // intensity/paletteSource survive \u2014 mirror of applyComposition.\n let existing = {};\n try {\n const row = await client.execute(\"SELECT threeDConfigJson FROM BrandingSettings WHERE id = 1\");\n const raw = row.rows[0]?.threeDConfigJson;\n if (typeof raw === \"string\" && raw) {\n const parsed = JSON.parse(raw);\n if (parsed && typeof parsed === \"object\" && !Array.isArray(parsed)) existing = parsed;\n }\n } catch {\n /* fresh row or unreadable config \u2014 write { scene } alone */\n }\n sets.push(\"threeDConfigJson = ?\");\n args.push(JSON.stringify({ ...existing, scene: look.scene }));\n }\n\n if (sets.length > 0) {\n const updated = await client.execute({\n sql: \"UPDATE BrandingSettings SET \" + sets.join(\", \") + \" WHERE id = 1\",\n args,\n });\n if (Number(updated.rowsAffected) === 0) {\n // No row yet (seed skipped?) \u2014 create it with the engine's minimal\n // required fields, mirroring applyComposition's upsert-create.\n const cols = [\"id\", \"storeName\", \"heroImage\", \"announcement\"];\n const vals = [1, process.env.CARTWRIGHT_LOOK_STORE_NAME || \"Cartwright\", \"\", \"\"];\n for (let i = 0; i < sets.length; i++) {\n cols.push(sets[i].split(\" \")[0]);\n vals.push(args[i]);\n }\n await client.execute({\n sql:\n \"INSERT INTO BrandingSettings (\" + cols.join(\", \") + \") VALUES (\" +\n cols.map(() => \"?\").join(\", \") + \")\",\n args: vals,\n });\n }\n }\n console.log(\"CARTWRIGHT_LOOK_DB_OK\");\n} catch (err) {\n ERR(err instanceof Error ? err.message : String(err));\n} finally {\n client.close();\n}\n"; export type ApplyLookDbResult = { ok: boolean; warning?: string; }; /** * Write the look's palette/scene/chrome into the scaffold's seeded database. * Runs the temp script with `node` from the scaffold root (so its * node_modules + .env files resolve), passes the look via env, and always * deletes the script. Fail-soft: every failure path returns one warning. */ export declare function applyLookDbParts(targetDir: string, look: PublicLook, opts?: { storeName?: string; }): ApplyLookDbResult; /** What the apply run is summarized as — drives the success line + outro. */ export type LookSummary = { /** Display name for "Look applied: ". */ name: string; /** At least one part of the look landed. */ applied: boolean; warnings: string[]; };