@usethrottle/create-store 0.1.0 → 0.2.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/CLAUDE.md +8 -0
- package/dist/index.js +48 -11
- package/dist/index.js.map +1 -1
- package/package.json +6 -2
- package/template-builder-build/.env.local.tmpl.append +11 -0
- package/template-builder-build/.gitignore.tmpl.append +3 -0
- package/template-builder-build/AGENTS.md.append +16 -0
- package/template-builder-build/README.md.append +49 -0
- package/template-builder-build/app/layout.tsx +36 -0
- package/template-builder-build/app/pages/[handle]/page.tsx +26 -0
- package/template-builder-build/app/providers.tsx +31 -0
- package/template-builder-build/app/sitemap.ts +10 -0
- package/template-builder-build/lib/builder.ts +75 -0
- package/template-builder-build/lib/packs.ts +9 -0
- package/template-builder-build/next.config.ts +61 -0
package/CLAUDE.md
CHANGED
|
@@ -19,6 +19,14 @@
|
|
|
19
19
|
`THROTTLE_WEBHOOK_SECRET` set. Stop the server by
|
|
20
20
|
port, delete the scratch store by its literal path.
|
|
21
21
|
|
|
22
|
+
- `template-builder-build/`: `--builder-mode build` overlays it on `template/`: a file replaces the template's file of the
|
|
23
|
+
same path, `*.append` is added to the end of it, anything else is new. A live store never reads it, and a live scaffold
|
|
24
|
+
is byte-identical to before (`src/builder-mode.test.ts` compares it with a golden hash taken from `origin/main`). Its
|
|
25
|
+
`next.config.ts` reads the release once into `.builder/release.json` (traced into the output, `lib/builder.ts` renders
|
|
26
|
+
from it: no Builder request or key at run time, and the layout never downloads the bundle), and serves a renamed
|
|
27
|
+
page's redirect itself. Its layout reads the catalog settings with a one-year cache policy so the release pages are not
|
|
28
|
+
rendered again every hour; do not shorten it.
|
|
29
|
+
|
|
22
30
|
## Invariants an agent must not break
|
|
23
31
|
|
|
24
32
|
- **ISR cost rules.** Every new store copies the template, and the owner was billed about $1k for ISR
|
package/dist/index.js
CHANGED
|
@@ -21,6 +21,7 @@ function runScript(pm, script) {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
// src/args.ts
|
|
24
|
+
var BUILDER_MODES = ["live", "build"];
|
|
24
25
|
var DEFAULT_DIR = "my-store";
|
|
25
26
|
var USAGE = `Usage: create-store [dir] [options]
|
|
26
27
|
|
|
@@ -28,12 +29,13 @@ var USAGE = `Usage: create-store [dir] [options]
|
|
|
28
29
|
--catalog-key <key> The catalog's browser key (pc_pk_...); asked for when missing. A server key is detected
|
|
29
30
|
--server-key <key> The catalog's server key, for reads made by your store's server (asked for after the browser key)
|
|
30
31
|
--yes, -y Take every default and ask nothing
|
|
32
|
+
--builder-mode <m> live (default) or build. build adds a Throttle Builder site that is generated at build time from a frozen release, with no Builder reads while the store runs
|
|
31
33
|
--pm <manager> pnpm, npm, yarn or bun (default: the one running this command)
|
|
32
34
|
--skip-install Write the files and stop before installing dependencies
|
|
33
35
|
--offline Do not call the catalog to tell the keys apart (then --catalog-key and --server-key are both needed)
|
|
34
36
|
--help, -h Show this text`;
|
|
35
37
|
function parseArgs(argv) {
|
|
36
|
-
const args = { dir: DEFAULT_DIR, yes: false, skipInstall: false, offline: false, help: false };
|
|
38
|
+
const args = { dir: DEFAULT_DIR, builderMode: "live", yes: false, skipInstall: false, offline: false, help: false };
|
|
37
39
|
const positional = [];
|
|
38
40
|
const valueOf = (flag, inline, index) => {
|
|
39
41
|
if (inline !== void 0) return { value: inline, next: index };
|
|
@@ -67,6 +69,13 @@ function parseArgs(argv) {
|
|
|
67
69
|
i = next;
|
|
68
70
|
break;
|
|
69
71
|
}
|
|
72
|
+
case "--builder-mode": {
|
|
73
|
+
const { value, next } = valueOf(flag, inline, i);
|
|
74
|
+
if (!BUILDER_MODES.includes(value)) throw new Error(`--builder-mode must be live or build, not "${value}".`);
|
|
75
|
+
args.builderMode = value;
|
|
76
|
+
i = next;
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
70
79
|
case "--pm": {
|
|
71
80
|
const { value, next } = valueOf(flag, inline, i);
|
|
72
81
|
if (!isPackageManager(value)) throw new Error(`--pm must be pnpm, npm, yarn or bun, not "${value}".`);
|
|
@@ -260,6 +269,7 @@ import { mkdir, readdir, readFile, stat, writeFile } from "fs/promises";
|
|
|
260
269
|
import { basename, dirname, join, relative, resolve } from "path";
|
|
261
270
|
import { fileURLToPath } from "url";
|
|
262
271
|
var TEMPLATE_DIR = resolve(dirname(fileURLToPath(import.meta.url)), "../template");
|
|
272
|
+
var BUILD_TEMPLATE_DIR = resolve(dirname(fileURLToPath(import.meta.url)), "../template-builder-build");
|
|
263
273
|
async function filesUnder(root, dir = root) {
|
|
264
274
|
const found = [];
|
|
265
275
|
for (const entry of await readdir(dir, { withFileTypes: true })) {
|
|
@@ -298,12 +308,24 @@ async function scaffold(o) {
|
|
|
298
308
|
catalogKey: o.catalogKey,
|
|
299
309
|
serverKeyLine: o.serverKey ? `THROTTLE_CATALOG_SERVER_KEY=${o.serverKey}` : "# THROTTLE_CATALOG_SERVER_KEY= (the catalog's server key; see README.md)"
|
|
300
310
|
};
|
|
311
|
+
const files = /* @__PURE__ */ new Map();
|
|
312
|
+
const read = async (root, overlay) => {
|
|
313
|
+
for (const file of await filesUnder(root)) {
|
|
314
|
+
const append = overlay && file.endsWith(".append");
|
|
315
|
+
const name = append ? file.slice(0, -".append".length) : file;
|
|
316
|
+
const isTemplate = name.endsWith(".tmpl");
|
|
317
|
+
const out = isTemplate ? name.slice(0, -".tmpl".length) : name;
|
|
318
|
+
let text = await readFile(join(root, file), "utf8");
|
|
319
|
+
if (isTemplate) text = render(text, values);
|
|
320
|
+
files.set(out, append ? (files.get(out) ?? "") + text : text);
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
await read(TEMPLATE_DIR, false);
|
|
324
|
+
if (o.builderMode === "build") await read(BUILD_TEMPLATE_DIR, true);
|
|
301
325
|
const written = [];
|
|
302
|
-
for (const file of
|
|
303
|
-
const
|
|
304
|
-
|
|
305
|
-
let text = await readFile(join(TEMPLATE_DIR, file), "utf8");
|
|
306
|
-
if (isTemplate) text = render(text, values);
|
|
326
|
+
for (const [file, content] of files) {
|
|
327
|
+
const out = join(target, file);
|
|
328
|
+
let text = content;
|
|
307
329
|
if (basename(out) === "package.json") {
|
|
308
330
|
const manifest = JSON.parse(text);
|
|
309
331
|
const dependencies = { ...manifest.dependencies, ...o.versions };
|
|
@@ -321,20 +343,34 @@ async function scaffold(o) {
|
|
|
321
343
|
// ../auth-sdk/package.json
|
|
322
344
|
var version = "0.15.0";
|
|
323
345
|
|
|
346
|
+
// ../builder/package.json
|
|
347
|
+
var version2 = "0.2.0";
|
|
348
|
+
|
|
349
|
+
// ../builder-react/package.json
|
|
350
|
+
var version3 = "0.2.0";
|
|
351
|
+
|
|
352
|
+
// ../builder-schema/package.json
|
|
353
|
+
var version4 = "0.1.2";
|
|
354
|
+
|
|
324
355
|
// ../storefront-react/package.json
|
|
325
|
-
var
|
|
356
|
+
var version5 = "0.2.2";
|
|
326
357
|
|
|
327
358
|
// ../ui/package.json
|
|
328
|
-
var
|
|
359
|
+
var version6 = "0.1.2";
|
|
329
360
|
|
|
330
361
|
// src/versions.ts
|
|
331
362
|
var TEMPLATE_VERSIONS = {
|
|
332
|
-
"@usethrottle/storefront-react": `^${
|
|
333
|
-
"@usethrottle/ui": `^${
|
|
363
|
+
"@usethrottle/storefront-react": `^${version5}`,
|
|
364
|
+
"@usethrottle/ui": `^${version6}`,
|
|
334
365
|
"@usethrottle/auth": `^${version}`,
|
|
335
366
|
"@usethrottle/catalog": "^1.4.1",
|
|
336
367
|
"@usethrottle/money": "^1.1.0"
|
|
337
368
|
};
|
|
369
|
+
var BUILD_MODE_VERSIONS = {
|
|
370
|
+
"@usethrottle/builder": `^${version2}`,
|
|
371
|
+
"@usethrottle/builder-react": `^${version3}`,
|
|
372
|
+
"@usethrottle/builder-schema": `^${version4}`
|
|
373
|
+
};
|
|
338
374
|
|
|
339
375
|
// src/index.ts
|
|
340
376
|
var fail = (message) => {
|
|
@@ -379,7 +415,8 @@ ${USAGE}`);
|
|
|
379
415
|
dir: args.dir,
|
|
380
416
|
catalogKey: keys.browserKey,
|
|
381
417
|
...keys.serverKey ? { serverKey: keys.serverKey } : {},
|
|
382
|
-
|
|
418
|
+
builderMode: args.builderMode,
|
|
419
|
+
versions: args.builderMode === "build" ? { ...TEMPLATE_VERSIONS, ...BUILD_MODE_VERSIONS } : TEMPLATE_VERSIONS
|
|
383
420
|
});
|
|
384
421
|
} catch (error) {
|
|
385
422
|
return fail(error instanceof Error ? error.message : "Could not write the store.");
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/pm.ts","../src/args.ts","../src/catalog-key.ts","../src/keys.ts","../src/prompt.ts","../src/scaffold.ts","../../auth-sdk/package.json","../../storefront-react/package.json","../../ui/package.json","../src/versions.ts"],"sourcesContent":["/* eslint-disable no-console -- a CLI talks to the terminal */\nimport { spawn } from 'node:child_process';\nimport { relative, resolve } from 'node:path';\nimport { parseArgs, USAGE } from './args';\nimport { classifyCatalogKey } from './catalog-key';\nimport { resolveKeys } from './keys';\nimport { detectPackageManager, installCommand, runScript } from './pm';\nimport { askCatalogKey } from './prompt';\nimport { scaffold } from './scaffold';\nimport { TEMPLATE_VERSIONS } from './versions';\n\nconst fail = (message: string): never => {\n console.error(`create-store: ${message}`);\n process.exit(1);\n};\n\nfunction install(pm: ReturnType<typeof detectPackageManager>, cwd: string): Promise<boolean> {\n const { command, args } = installCommand(pm);\n return new Promise((done) => {\n const child = spawn(command, args, { cwd, stdio: 'inherit', shell: process.platform === 'win32' });\n child.on('error', () => done(false));\n child.on('exit', (code) => done(code === 0));\n });\n}\n\nasync function main(): Promise<void> {\n let args;\n try {\n args = parseArgs(process.argv.slice(2));\n } catch (error) {\n console.error(`create-store: ${error instanceof Error ? error.message : 'bad arguments'}\\n\\n${USAGE}`);\n process.exit(1);\n }\n if (args.help) {\n console.log(USAGE);\n return;\n }\n\n let keys;\n try {\n keys = await resolveKeys(args, {\n classify: (key) => classifyCatalogKey(key),\n ask: askCatalogKey,\n });\n } catch (error) {\n return fail(error instanceof Error ? error.message : 'Could not settle the catalog keys.');\n }\n for (const note of keys.notes) console.warn(`create-store: ${note}`);\n\n let written: string[];\n try {\n written = await scaffold({\n dir: args.dir,\n catalogKey: keys.browserKey,\n ...(keys.serverKey ? { serverKey: keys.serverKey } : {}),\n versions: TEMPLATE_VERSIONS,\n });\n } catch (error) {\n return fail(error instanceof Error ? error.message : 'Could not write the store.');\n }\n const target = resolve(args.dir);\n console.log(`Created ${written.length} files in ${target}`);\n\n const pm = args.pm ?? detectPackageManager(process.env.npm_config_user_agent);\n if (!args.skipInstall) {\n console.log(`Installing with ${pm}...`);\n if (!(await install(pm, target))) console.warn(`create-store: ${pm} install did not finish. Run it yourself in the folder.`);\n }\n\n const rel = relative(process.cwd(), target) || '.';\n const cd = rel.startsWith('..') ? target : rel;\n console.log(`\\nNext:\\n cd ${cd}\\n${args.skipInstall ? ` ${pm} install\\n` : ''} ${runScript(pm, 'dev')}\\n\\nRead README.md for how the store stays cheap on Vercel before you deploy.`);\n}\n\nmain().catch((error: unknown) => {\n console.error(`create-store: ${error instanceof Error ? error.message : String(error)}`);\n process.exit(1);\n});\n","export type PackageManager = 'pnpm' | 'npm' | 'yarn' | 'bun';\n\nconst MANAGERS: readonly PackageManager[] = ['pnpm', 'npm', 'yarn', 'bun'];\n\n/** The manager that ran `create-store`, from `npm_config_user_agent` (`'pnpm/9.15.4 npm/? node/v20'` is pnpm). Unknown: npm. */\nexport function detectPackageManager(userAgent: string | undefined): PackageManager {\n const name = userAgent?.trim().split(/[\\s/]/u)[0];\n return MANAGERS.find((pm) => pm === name) ?? 'npm';\n}\n\nexport function isPackageManager(value: string): value is PackageManager {\n return (MANAGERS as readonly string[]).includes(value);\n}\n\n/** The command and arguments that install a project's dependencies. */\nexport function installCommand(pm: PackageManager): { command: string; args: string[] } {\n return { command: pm, args: ['install'] };\n}\n\n/** The command a user types to run a package script (`dev`). */\nexport function runScript(pm: PackageManager, script: string): string {\n return pm === 'npm' ? `npm run ${script}` : `${pm} ${script}`;\n}\n","import { isPackageManager, type PackageManager } from './pm';\n\nexport type Args = {\n dir: string;\n catalogKey?: string;\n serverKey?: string;\n yes: boolean;\n pm?: PackageManager;\n skipInstall: boolean;\n offline: boolean;\n help: boolean;\n};\n\nexport const DEFAULT_DIR = 'my-store';\n\nexport const USAGE = `Usage: create-store [dir] [options]\n\n dir Where to create the store (default: ${DEFAULT_DIR})\n --catalog-key <key> The catalog's browser key (pc_pk_...); asked for when missing. A server key is detected\n --server-key <key> The catalog's server key, for reads made by your store's server (asked for after the browser key)\n --yes, -y Take every default and ask nothing\n --pm <manager> pnpm, npm, yarn or bun (default: the one running this command)\n --skip-install Write the files and stop before installing dependencies\n --offline Do not call the catalog to tell the keys apart (then --catalog-key and --server-key are both needed)\n --help, -h Show this text`;\n\n/** Reads the command line (without `node` and the script). Throws a readable error for a flag it does not know. */\nexport function parseArgs(argv: string[]): Args {\n const args: Args = { dir: DEFAULT_DIR, yes: false, skipInstall: false, offline: false, help: false };\n const positional: string[] = [];\n const valueOf = (flag: string, inline: string | undefined, index: number): { value: string; next: number } => {\n if (inline !== undefined) return { value: inline, next: index };\n const next = argv[index + 1];\n if (next === undefined || next.startsWith('-')) throw new Error(`${flag} needs a value.`);\n return { value: next, next: index + 1 };\n };\n for (let i = 0; i < argv.length; i++) {\n const raw = argv[i] ?? '';\n if (raw === '--') {\n positional.push(...argv.slice(i + 1));\n break;\n }\n if (!raw.startsWith('-')) {\n positional.push(raw);\n continue;\n }\n const eq = raw.startsWith('--') ? raw.indexOf('=') : -1;\n const flag = eq === -1 ? raw : raw.slice(0, eq);\n const inline = eq === -1 ? undefined : raw.slice(eq + 1);\n switch (flag) {\n case '--catalog-key': {\n const { value, next } = valueOf(flag, inline, i);\n args.catalogKey = value;\n i = next;\n break;\n }\n case '--server-key': {\n const { value, next } = valueOf(flag, inline, i);\n args.serverKey = value;\n i = next;\n break;\n }\n case '--pm': {\n const { value, next } = valueOf(flag, inline, i);\n if (!isPackageManager(value)) throw new Error(`--pm must be pnpm, npm, yarn or bun, not \"${value}\".`);\n args.pm = value;\n i = next;\n break;\n }\n case '--yes':\n case '-y':\n args.yes = true;\n break;\n case '--skip-install':\n args.skipInstall = true;\n break;\n case '--offline':\n args.offline = true;\n break;\n case '--help':\n case '-h':\n args.help = true;\n break;\n default:\n throw new Error(`Unknown option ${flag}.`);\n }\n }\n if (positional.length > 1) throw new Error(`Give one directory, not ${positional.length} (${positional.join(', ')}).`);\n if (positional[0]) args.dir = positional[0];\n return args;\n}\n","export const DEFAULT_CATALOG_URL = 'https://catalog.usethrottle.dev';\n\n/** A catalog publishable key: `pc_pk_` and up to 94 printable characters, no spaces (the catalog SDK's rule). */\nexport function validateCatalogKey(key: string): boolean {\n return /^pc_pk_[\\x21-\\x7e]{1,94}$/u.test(key);\n}\n\n/** Why a key is not accepted, in words for the terminal. */\nexport function catalogKeyProblem(key: string): string | undefined {\n if (validateCatalogKey(key)) return undefined;\n if (key.startsWith('pc_sk_')) return 'That is a secret key (pc_sk_). A storefront takes the publishable key (pc_pk_).';\n return 'A catalog publishable key starts with pc_pk_ and has no spaces.';\n}\n\n/** `unchecked` is only ever made by the caller, when it chose not to ask the catalog (`--offline`). */\nexport type KeyKind = 'server' | 'browser' | 'rejected' | 'unknown' | 'unchecked';\nexport type KeyClassification = { kind: KeyKind; detail: string };\n\n/** The origin of the second request. It is not a real site: a browser key is not allowed from it, a server key is refused from any origin. */\nexport const PROBE_ORIGIN = 'https://create-store.invalid';\n\n/**\n * Tells a catalog server key from a browser key by asking the catalog for its config (`GET /v1/storefront/config`)\n * twice: with no origin (what the store's server sends) and with an `Origin` header (what a browser sends).\n * - 401 on either: the catalog does not know the key (`rejected`).\n * - 200 with no origin, or `SERVER_KEY_IN_BROWSER` with one: a server key.\n * - `ORIGIN_NOT_ALLOWED` with no origin, or 200 or `ORIGIN_NOT_ALLOWED` with one: a browser key.\n * Anything else, or no answer, is `unknown`: the key is never refused for a reason the catalog did not give.\n */\nexport async function classifyCatalogKey(\n key: string,\n options: { baseUrl?: string; fetch?: typeof fetch; timeoutMs?: number } = {},\n): Promise<KeyClassification> {\n const base = (options.baseUrl ?? DEFAULT_CATALOG_URL).replace(/\\/+$/u, '');\n const doFetch = options.fetch ?? fetch;\n const ask = async (origin: string | undefined): Promise<{ status: number; code: string } | undefined> => {\n try {\n const response = await doFetch(`${base}/v1/storefront/config`, {\n headers: { 'x-catalog-key': key, ...(origin ? { origin } : {}) },\n signal: AbortSignal.timeout(options.timeoutMs ?? 8000),\n });\n const text = response.ok ? '' : await response.text().catch(() => '');\n const code = /\"code\"\\s*:\\s*\"([A-Z_]+)\"/u.exec(text)?.[1] ?? '';\n return { status: response.status, code };\n } catch {\n return undefined;\n }\n };\n const [server, browser] = [await ask(undefined), await ask(PROBE_ORIGIN)];\n if (server?.status === 401 || browser?.status === 401) {\n return { kind: 'rejected', detail: 'The catalog does not know this key (401).' };\n }\n if (server?.status === 200 || browser?.code === 'SERVER_KEY_IN_BROWSER') {\n return { kind: 'server', detail: 'This is a server key.' };\n }\n if (server?.code === 'ORIGIN_NOT_ALLOWED' || browser?.status === 200 || browser?.code === 'ORIGIN_NOT_ALLOWED') {\n return { kind: 'browser', detail: 'This is a browser key.' };\n }\n return { kind: 'unknown', detail: server || browser ? `The catalog answered ${(server ?? browser)!.status}.` : 'The catalog did not answer.' };\n}\n","import { catalogKeyProblem, type KeyClassification, type KeyKind } from './catalog-key';\n\nexport type KeyRole = 'browser' | 'server';\n\nexport type KeyDeps = {\n /** Asks the catalog what kind of key this is. */\n classify(key: string): Promise<KeyClassification>;\n /** Asks the user for a key. `undefined` or an empty string: the user skipped or cancelled. */\n ask(role: KeyRole): Promise<string | undefined>;\n};\n\nexport type KeyInput = {\n /** `--catalog-key`: the browser key, or a server key (it is detected). */\n catalogKey?: string;\n /** `--server-key`. */\n serverKey?: string;\n yes: boolean;\n offline: boolean;\n};\n\nexport type ResolvedKeys = {\n /** Goes to `NEXT_PUBLIC_THROTTLE_CATALOG_KEY`. Never a server key. */\n browserKey: string;\n /** Goes to `THROTTLE_CATALOG_SERVER_KEY`. Never a browser key. */\n serverKey?: string;\n /** Things to tell the user, none of them fatal. */\n notes: string[];\n};\n\nconst NEEDS_BOTH =\n 'Could not tell whether the key is a browser key or a server key, and a server key must never be written as the browser key. Pass both: --catalog-key <browser key> --server-key <server key>.';\n\nconst SERVER_NEEDS_BROWSER =\n 'That is a server key, and a store also needs a browser key for the open tab. Pass it with --catalog-key and the server key with --server-key.';\n\nconst ON_YOUR_WORD =\n 'The catalog did not check which key is which, so the roles are taken on your word: --catalog-key as the browser key and --server-key as the server key. If they are the wrong way round, the server key is published to every visitor in NEXT_PUBLIC_THROTTLE_CATALOG_KEY. Check .env.local.';\n\n/**\n * The one rule that keeps a server key out of `NEXT_PUBLIC_THROTTLE_CATALOG_KEY`: the key placed there is either\n * one the catalog said is a browser key, or one the user named as the browser key while also giving a server key\n * (typed at the browser prompt, or `--catalog-key` beside `--server-key`) and nothing contradicted it. A key the\n * catalog said is a server key is never allowed. Anything else is `NEEDS_BOTH`.\n */\nexport function assertBrowserKeyPlacement(p: { browserKind: KeyKind | undefined; named: boolean; hasServerKey: boolean }): void {\n if (p.browserKind === 'browser') return;\n if (p.browserKind !== 'server' && p.named && p.hasServerKey) return;\n throw new Error(NEEDS_BOTH);\n}\n\n/**\n * Settles which key is the store's browser key and which is its server key. A catalog browser key is only\n * answered from an allowed website, so the store's server reads with a server key and the browser with a\n * browser key. A key is never written under the wrong name: a server key is never a `NEXT_PUBLIC_` value.\n * - A browser key (the usual first key): the server key is asked for next, and may be skipped.\n * - A server key: the browser key is asked for next, and is required (an error with `--yes`).\n * - Flags in the wrong order (`--catalog-key` is a server key): put right only when the catalog says the\n * other one is a browser key. Any other answer is an error, never a guess.\n * - A key the catalog cannot place (`--offline`, or no answer) is not taken for the browser key. With both\n * `--catalog-key` and `--server-key` the roles are the ones the user named, with a note that says so;\n * otherwise both are asked for (an error with `--yes`).\n * `assertBrowserKeyPlacement` runs last, whatever path was taken.\n */\nexport async function resolveKeys(o: KeyInput, deps: KeyDeps): Promise<ResolvedKeys> {\n const notes: string[] = [];\n const classify = async (key: string): Promise<KeyKind> => {\n const problem = catalogKeyProblem(key);\n if (problem) throw new Error(problem);\n if (o.offline) return 'unchecked';\n const result = await deps.classify(key);\n if (result.kind === 'rejected') throw new Error(`${result.detail} Check the key, or pass --offline to skip this check.`);\n if (result.kind === 'unknown') notes.push(`Could not tell what kind of key this is (${result.detail}).`);\n return result.kind;\n };\n const askFor = async (role: KeyRole): Promise<string | undefined> => (await deps.ask(role))?.trim() || undefined;\n\n let browser = o.catalogKey?.trim() || undefined;\n let server = o.serverKey?.trim() || undefined;\n /** The user named `browser` as the browser key: typed at the browser prompt, or `--catalog-key` beside `--server-key`. */\n let named = false;\n let browserKind: KeyKind | undefined;\n let serverChecked = false;\n\n if (!browser && !server) {\n if (o.yes) throw new Error('--yes needs --catalog-key <pc_pk_...>.');\n browser = await askFor('browser');\n if (!browser) throw new Error('Cancelled.');\n named = true;\n }\n\n if (browser) {\n browserKind = await classify(browser);\n if (browserKind === 'server') {\n if (server) {\n const other = await classify(server);\n if (other === 'server') throw new Error('--catalog-key and --server-key are both server keys. One of them has to be the browser key.');\n if (other !== 'browser') {\n throw new Error(\n `The catalog says --catalog-key is a server key, but could not confirm that --server-key is a browser key (${other === 'unchecked' ? 'not checked' : 'no clear answer'}). The flags are not swapped on a guess: pass them the right way round, or check the keys in the catalog.`,\n );\n }\n // The flags were the wrong way round, and the catalog confirms it.\n [browser, server] = [server, browser];\n browserKind = 'browser';\n } else {\n server = browser;\n browser = undefined;\n browserKind = undefined;\n }\n serverChecked = true;\n } else if (server) {\n named = true;\n }\n }\n if (server && !serverChecked) {\n if ((await classify(server)) === 'browser') throw new Error('The key given as the server key is a browser key. A server key is made in the catalog under server keys.');\n }\n\n if (!browser) {\n if (o.yes) throw new Error(SERVER_NEEDS_BROWSER);\n browser = await askFor('browser');\n if (!browser) throw new Error('A browser key is needed. Cancelled.');\n named = true;\n browserKind = await classify(browser);\n if (browserKind === 'server') throw new Error('That is a server key too. The browser key is the one the catalog allows your website to use.');\n }\n\n if (!server) {\n if (browserKind !== 'browser') {\n // The catalog could not place the key: it is not put under a name on a guess.\n if (o.yes) throw new Error(NEEDS_BOTH);\n if (!named) {\n notes.push('Could not tell what kind of key --catalog-key is, so both keys are asked for.');\n browser = await askFor('browser');\n if (!browser) throw new Error('A browser key is needed. Cancelled.');\n named = true;\n browserKind = await classify(browser);\n if (browserKind === 'server') throw new Error('That is a server key too. The browser key is the one the catalog allows your website to use.');\n }\n server = await askFor('server');\n if (!server) throw new Error('A server key is needed when the keys cannot be told apart. Cancelled.');\n if ((await classify(server)) === 'browser') throw new Error('That is a browser key, not a server key.');\n } else if (!o.yes) {\n const given = await askFor('server');\n if (given) {\n if ((await classify(given)) === 'browser') throw new Error('That is a browser key, not a server key.');\n server = given;\n }\n }\n }\n\n assertBrowserKeyPlacement({ browserKind, named, hasServerKey: server !== undefined });\n if (browserKind !== 'browser') notes.push(ON_YOUR_WORD);\n if (!server) {\n notes.push(\n 'No server key. The browser key is only answered from an allowed website, so your store\\'s server cannot read with it: add the catalog\\'s server key as THROTTLE_CATALOG_SERVER_KEY in .env.local (see README.md).',\n );\n }\n return { browserKey: browser, ...(server ? { serverKey: server } : {}), notes };\n}\n","import prompts from 'prompts';\nimport { catalogKeyProblem } from './catalog-key';\nimport type { KeyRole } from './keys';\n\nconst MESSAGES: Record<KeyRole, string> = {\n browser: 'Catalog publishable key (pc_pk_...)',\n server: 'Catalog server key, for your store\\'s server (pc_pk_..., press enter to skip)',\n};\n\n/** Asks for a catalog key. Returns undefined when the user cancels, or skips the optional server key. */\nexport async function askCatalogKey(role: KeyRole): Promise<string | undefined> {\n const answer = await prompts(\n {\n type: 'text',\n name: 'catalogKey',\n message: MESSAGES[role],\n validate: (value: string) => (role === 'server' && value.trim() === '' ? true : (catalogKeyProblem(value.trim()) ?? true)),\n },\n { onCancel: () => false },\n );\n const key: unknown = answer.catalogKey;\n return typeof key === 'string' ? key.trim() : undefined;\n}\n","import { mkdir, readdir, readFile, stat, writeFile } from 'node:fs/promises';\nimport { basename, dirname, join, relative, resolve } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { catalogKeyProblem } from './catalog-key';\n\n/** `template/` sits beside `src/` and `dist/`, so one path reaches it from the source and from the build. */\nexport const TEMPLATE_DIR = resolve(dirname(fileURLToPath(import.meta.url)), '../template');\n\nexport type ScaffoldOptions = {\n /** Where to write the store. It may exist, but must be empty. */\n dir: string;\n /** The catalog's browser key, written to `.env.local` as `NEXT_PUBLIC_THROTTLE_CATALOG_KEY`. */\n catalogKey: string;\n /** The catalog's server key, written as `THROTTLE_CATALOG_SERVER_KEY` (never a `NEXT_PUBLIC_` value). Optional. */\n serverKey?: string;\n /** The Throttle package versions for the store's `dependencies` (`TEMPLATE_VERSIONS`). */\n versions: Record<string, string>;\n};\n\nasync function filesUnder(root: string, dir = root): Promise<string[]> {\n const found: string[] = [];\n for (const entry of await readdir(dir, { withFileTypes: true })) {\n const path = join(dir, entry.name);\n if (entry.isDirectory()) found.push(...(await filesUnder(root, path)));\n else found.push(relative(root, path));\n }\n return found.sort();\n}\n\n/** A valid npm package name from a folder name. */\nexport function packageNameOf(dir: string): string {\n const cleaned = basename(resolve(dir))\n .toLowerCase()\n .replace(/[^a-z0-9._-]+/gu, '-')\n .replace(/^[._-]+|[-]+$/gu, '');\n return cleaned || 'throttle-store';\n}\n\nfunction render(text: string, values: Record<string, string>): string {\n return text.replace(/\\{\\{(\\w+)\\}\\}/gu, (_all, name: string) => {\n const value = values[name];\n if (value === undefined) throw new Error(`The template uses {{${name}}}, which scaffold does not set.`);\n return value;\n });\n}\n\n/**\n * Writes the store template into `dir` and returns the absolute paths it wrote. A `.tmpl` file loses its\n * suffix (npm drops `.gitignore` and renames `package.json` files, so those travel as templates) and has its\n * `{{name}}`, `{{catalogKey}}` and `{{serverKeyLine}}` filled in. `package.json` also gets the Throttle packages' versions.\n * Refuses a directory that already holds anything, so it never overwrites a project.\n */\nexport async function scaffold(o: ScaffoldOptions): Promise<string[]> {\n const problem = catalogKeyProblem(o.catalogKey);\n if (problem) throw new Error(problem);\n const serverProblem = o.serverKey === undefined ? undefined : catalogKeyProblem(o.serverKey);\n if (serverProblem) throw new Error(serverProblem);\n const target = resolve(o.dir);\n const existing = await stat(target).then(\n () => readdir(target),\n () => null,\n );\n if (existing && existing.length > 0) {\n throw new Error(`${target} is not empty. Pick a new directory, or empty this one first.`);\n }\n const values = {\n name: packageNameOf(target),\n catalogKey: o.catalogKey,\n serverKeyLine: o.serverKey\n ? `THROTTLE_CATALOG_SERVER_KEY=${o.serverKey}`\n : '# THROTTLE_CATALOG_SERVER_KEY= (the catalog\\'s server key; see README.md)',\n };\n const written: string[] = [];\n for (const file of await filesUnder(TEMPLATE_DIR)) {\n const isTemplate = file.endsWith('.tmpl');\n const out = join(target, isTemplate ? file.slice(0, -'.tmpl'.length) : file);\n let text = await readFile(join(TEMPLATE_DIR, file), 'utf8');\n if (isTemplate) text = render(text, values);\n if (basename(out) === 'package.json') {\n const manifest = JSON.parse(text) as { dependencies?: Record<string, string> };\n const dependencies = { ...manifest.dependencies, ...o.versions };\n manifest.dependencies = Object.fromEntries(Object.entries(dependencies).sort(([a], [b]) => a.localeCompare(b)));\n text = `${JSON.stringify(manifest, null, 2)}\\n`;\n }\n await mkdir(dirname(out), { recursive: true });\n await writeFile(out, text, 'utf8');\n written.push(out);\n }\n return written;\n}\n","{\n \"name\": \"@usethrottle/auth\",\n \"version\": \"0.15.0\",\n \"description\": \"Buyer authentication for Throttle storefronts — headless core, React hooks, and drop-in forms.\",\n \"type\": \"module\",\n \"main\": \"./dist/index.cjs\",\n \"module\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"files\": [\n \"dist\",\n \"README.md\",\n \"CLAUDE.md\"\n ],\n \"sideEffects\": [\n \"**/*.css\"\n ],\n \"exports\": {\n \".\": {\n \"types\": \"./dist/index.d.ts\",\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\"\n },\n \"./react\": {\n \"types\": \"./dist/react/index.d.ts\",\n \"import\": \"./dist/react/index.js\",\n \"require\": \"./dist/react/index.cjs\"\n },\n \"./forms\": {\n \"types\": \"./dist/react/forms/index.d.ts\",\n \"import\": \"./dist/react/forms/index.js\",\n \"require\": \"./dist/react/forms/index.cjs\"\n },\n \"./components\": {\n \"types\": \"./dist/react/components/index.d.ts\",\n \"import\": \"./dist/react/components/index.js\",\n \"require\": \"./dist/react/components/index.cjs\"\n },\n \"./styles.css\": \"./dist/styles.css\",\n \"./package.json\": \"./package.json\"\n },\n \"scripts\": {\n \"build\": \"tsup\",\n \"dev\": \"tsup --watch\",\n \"test\": \"vitest run\",\n \"typecheck\": \"tsc --noEmit\"\n },\n \"dependencies\": {\n \"@usethrottle/money\": \"workspace:^\",\n \"@usethrottle/ui\": \"workspace:^\"\n },\n \"peerDependencies\": {\n \"react\": \">=18\",\n \"react-dom\": \">=18\"\n },\n \"peerDependenciesMeta\": {\n \"react\": {\n \"optional\": true\n },\n \"react-dom\": {\n \"optional\": true\n }\n },\n \"devDependencies\": {\n \"@core/cadence\": \"workspace:*\",\n \"@testing-library/react\": \"^16.1.0\",\n \"@types/react\": \"^19.1.0\",\n \"@types/react-dom\": \"^19.1.0\",\n \"@vitejs/plugin-react\": \"^4.3.4\",\n \"jsdom\": \"^25.0.1\",\n \"react\": \"^19.1.0\",\n \"react-dom\": \"^19.1.0\",\n \"tsup\": \"^8.0.0\",\n \"typescript\": \"^5.7.0\",\n \"vitest\": \"^2.1.9\"\n },\n \"publishConfig\": {\n \"access\": \"public\"\n },\n \"engines\": {\n \"node\": \">=20\"\n }\n}\n","{\n \"name\": \"@usethrottle/storefront-react\",\n \"version\": \"0.1.0\",\n \"description\": \"Drop-in, settings-driven React storefront components for Throttle catalogs.\",\n \"type\": \"module\",\n \"main\": \"./dist/index.cjs\",\n \"module\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"files\": [\n \"dist\",\n \"README.md\",\n \"CLAUDE.md\"\n ],\n \"sideEffects\": [\n \"**/*.css\"\n ],\n \"exports\": {\n \".\": {\n \"import\": {\n \"types\": \"./dist/index.d.ts\",\n \"default\": \"./dist/index.js\"\n },\n \"require\": {\n \"types\": \"./dist/index.d.cts\",\n \"default\": \"./dist/index.cjs\"\n }\n },\n \"./server\": {\n \"import\": {\n \"types\": \"./dist/server/index.d.ts\",\n \"default\": \"./dist/server/index.js\"\n },\n \"require\": {\n \"types\": \"./dist/server/index.d.cts\",\n \"default\": \"./dist/server/index.cjs\"\n }\n },\n \"./next\": {\n \"import\": {\n \"types\": \"./dist/next/index.d.ts\",\n \"default\": \"./dist/next/index.js\"\n },\n \"require\": {\n \"types\": \"./dist/next/index.d.cts\",\n \"default\": \"./dist/next/index.cjs\"\n }\n },\n \"./next/client\": {\n \"import\": {\n \"types\": \"./dist/next/client.d.ts\",\n \"default\": \"./dist/next/client.js\"\n },\n \"require\": {\n \"types\": \"./dist/next/client.d.cts\",\n \"default\": \"./dist/next/client.cjs\"\n }\n },\n \"./account\": {\n \"import\": {\n \"types\": \"./dist/account/index.d.ts\",\n \"default\": \"./dist/account/index.js\"\n },\n \"require\": {\n \"types\": \"./dist/account/index.d.cts\",\n \"default\": \"./dist/account/index.cjs\"\n }\n },\n \"./styles.css\": \"./dist/styles.css\",\n \"./package.json\": \"./package.json\"\n },\n \"scripts\": {\n \"build\": \"tsup\",\n \"dev\": \"tsup --watch\",\n \"test\": \"vitest run\",\n \"typecheck\": \"tsc --noEmit\"\n },\n \"dependencies\": {\n \"@usethrottle/ui\": \"workspace:^\"\n },\n \"peerDependencies\": {\n \"@usethrottle/auth\": \">=0.15.0\",\n \"@usethrottle/catalog\": \"^1.4.1\",\n \"@usethrottle/money\": \"^1.1.0\",\n \"@usethrottle/scripts\": \">=0.4.0\",\n \"next\": \">=15\",\n \"react\": \">=18\",\n \"react-dom\": \">=18\"\n },\n \"peerDependenciesMeta\": {\n \"@usethrottle/auth\": {\n \"optional\": true\n },\n \"@usethrottle/scripts\": {\n \"optional\": true\n },\n \"next\": {\n \"optional\": true\n }\n },\n \"devDependencies\": {\n \"@testing-library/react\": \"^16.1.0\",\n \"@types/node\": \"^20\",\n \"@types/react\": \"^19.1.0\",\n \"@types/react-dom\": \"^19.1.0\",\n \"@usethrottle/auth\": \"workspace:*\",\n \"@usethrottle/catalog\": \"1.4.1\",\n \"@usethrottle/money\": \"workspace:*\",\n \"@usethrottle/scripts\": \"workspace:*\",\n \"@vitejs/plugin-react\": \"^4.3.4\",\n \"jsdom\": \"^25.0.1\",\n \"next\": \"16.3.5\",\n \"react\": \"^19.1.0\",\n \"react-dom\": \"^19.1.0\",\n \"tsup\": \"^8.0.0\",\n \"typescript\": \"^5.7.0\",\n \"vitest\": \"^2.1.9\"\n },\n \"publishConfig\": {\n \"access\": \"public\"\n },\n \"engines\": {\n \"node\": \">=20\"\n }\n}\n","{\n \"name\": \"@usethrottle/ui\",\n \"version\": \"0.1.2\",\n \"description\": \"Shared theme, presets, primitives and icons for Throttle React components.\",\n \"type\": \"module\",\n \"main\": \"./dist/index.cjs\",\n \"module\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"files\": [\n \"dist\",\n \"CLAUDE.md\"\n ],\n \"sideEffects\": false,\n \"exports\": {\n \".\": {\n \"import\": {\n \"types\": \"./dist/index.d.ts\",\n \"default\": \"./dist/index.js\"\n },\n \"require\": {\n \"types\": \"./dist/index.d.cts\",\n \"default\": \"./dist/index.cjs\"\n }\n },\n \"./presets\": {\n \"import\": {\n \"types\": \"./dist/presets.d.ts\",\n \"default\": \"./dist/presets.js\"\n },\n \"require\": {\n \"types\": \"./dist/presets.d.cts\",\n \"default\": \"./dist/presets.cjs\"\n }\n },\n \"./package.json\": \"./package.json\"\n },\n \"scripts\": {\n \"build\": \"tsup\",\n \"dev\": \"tsup --watch\",\n \"test\": \"vitest run\",\n \"typecheck\": \"tsc --noEmit\"\n },\n \"peerDependencies\": {\n \"react\": \">=18\",\n \"react-dom\": \">=18\"\n },\n \"devDependencies\": {\n \"@testing-library/react\": \"^16.1.0\",\n \"@types/react\": \"^19.1.0\",\n \"@types/react-dom\": \"^19.1.0\",\n \"@vitejs/plugin-react\": \"^4.3.4\",\n \"jsdom\": \"^25.0.1\",\n \"react\": \"^19.1.0\",\n \"react-dom\": \"^19.1.0\",\n \"tsup\": \"^8.0.0\",\n \"typescript\": \"^5.7.0\",\n \"vitest\": \"^2.1.9\"\n },\n \"publishConfig\": {\n \"access\": \"public\"\n },\n \"engines\": {\n \"node\": \">=20\"\n }\n}\n","import { version as auth } from '../../auth-sdk/package.json';\nimport { version as storefrontReact } from '../../storefront-react/package.json';\nimport { version as ui } from '../../ui/package.json';\n\n/**\n * The versions a new store depends on. The three Throttle packages that ship with this CLI take the\n * version they have in this workspace when the CLI is built, so a store always gets the release this\n * CLI was published with. The catalog SDK and `@usethrottle/money` live elsewhere and are ranges: one\n * `@usethrottle/money` for the whole tree is what `@usethrottle/storefront-react` needs.\n */\nexport const TEMPLATE_VERSIONS: Record<string, string> = {\n '@usethrottle/storefront-react': `^${storefrontReact}`,\n '@usethrottle/ui': `^${ui}`,\n '@usethrottle/auth': `^${auth}`,\n '@usethrottle/catalog': '^1.4.1',\n '@usethrottle/money': '^1.1.0',\n};\n"],"mappings":";;;AACA,SAAS,aAAa;AACtB,SAAS,YAAAA,WAAU,WAAAC,gBAAe;;;ACAlC,IAAM,WAAsC,CAAC,QAAQ,OAAO,QAAQ,KAAK;AAGlE,SAAS,qBAAqB,WAA+C;AAClF,QAAM,OAAO,WAAW,KAAK,EAAE,MAAM,QAAQ,EAAE,CAAC;AAChD,SAAO,SAAS,KAAK,CAAC,OAAO,OAAO,IAAI,KAAK;AAC/C;AAEO,SAAS,iBAAiB,OAAwC;AACvE,SAAQ,SAA+B,SAAS,KAAK;AACvD;A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I,WAAW,IAAI,IAAI,SAAS;AAC3C,UAAQ,IAAI;AAAA;AAAA,OAAiB,EAAE;AAAA,EAAK,KAAK,cAAc,KAAK,EAAE;AAAA,IAAe,EAAE,KAAK,UAAU,IAAI,KAAK,CAAC;AAAA;AAAA,0EAA+E;AACzL;AAEA,KAAK,EAAE,MAAM,CAAC,UAAmB;AAC/B,UAAQ,MAAM,iBAAiB,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC,EAAE;AACvF,UAAQ,KAAK,CAAC;AAChB,CAAC;","names":["relative","resolve","version","version","version","resolve","relative"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/pm.ts","../src/args.ts","../src/catalog-key.ts","../src/keys.ts","../src/prompt.ts","../src/scaffold.ts","../../auth-sdk/package.json","../../builder/package.json","../../builder-react/package.json","../../builder-schema/package.json","../../storefront-react/package.json","../../ui/package.json","../src/versions.ts"],"sourcesContent":["/* eslint-disable no-console -- a CLI talks to the terminal */\nimport { spawn } from 'node:child_process';\nimport { relative, resolve } from 'node:path';\nimport { parseArgs, USAGE } from './args';\nimport { classifyCatalogKey } from './catalog-key';\nimport { resolveKeys } from './keys';\nimport { detectPackageManager, installCommand, runScript } from './pm';\nimport { askCatalogKey } from './prompt';\nimport { scaffold } from './scaffold';\nimport { BUILD_MODE_VERSIONS, TEMPLATE_VERSIONS } from './versions';\n\nconst fail = (message: string): never => {\n console.error(`create-store: ${message}`);\n process.exit(1);\n};\n\nfunction install(pm: ReturnType<typeof detectPackageManager>, cwd: string): Promise<boolean> {\n const { command, args } = installCommand(pm);\n return new Promise((done) => {\n const child = spawn(command, args, { cwd, stdio: 'inherit', shell: process.platform === 'win32' });\n child.on('error', () => done(false));\n child.on('exit', (code) => done(code === 0));\n });\n}\n\nasync function main(): Promise<void> {\n let args;\n try {\n args = parseArgs(process.argv.slice(2));\n } catch (error) {\n console.error(`create-store: ${error instanceof Error ? error.message : 'bad arguments'}\\n\\n${USAGE}`);\n process.exit(1);\n }\n if (args.help) {\n console.log(USAGE);\n return;\n }\n\n let keys;\n try {\n keys = await resolveKeys(args, {\n classify: (key) => classifyCatalogKey(key),\n ask: askCatalogKey,\n });\n } catch (error) {\n return fail(error instanceof Error ? error.message : 'Could not settle the catalog keys.');\n }\n for (const note of keys.notes) console.warn(`create-store: ${note}`);\n\n let written: string[];\n try {\n written = await scaffold({\n dir: args.dir,\n catalogKey: keys.browserKey,\n ...(keys.serverKey ? { serverKey: keys.serverKey } : {}),\n builderMode: args.builderMode,\n versions: args.builderMode === 'build' ? { ...TEMPLATE_VERSIONS, ...BUILD_MODE_VERSIONS } : TEMPLATE_VERSIONS,\n });\n } catch (error) {\n return fail(error instanceof Error ? error.message : 'Could not write the store.');\n }\n const target = resolve(args.dir);\n console.log(`Created ${written.length} files in ${target}`);\n\n const pm = args.pm ?? detectPackageManager(process.env.npm_config_user_agent);\n if (!args.skipInstall) {\n console.log(`Installing with ${pm}...`);\n if (!(await install(pm, target))) console.warn(`create-store: ${pm} install did not finish. Run it yourself in the folder.`);\n }\n\n const rel = relative(process.cwd(), target) || '.';\n const cd = rel.startsWith('..') ? target : rel;\n console.log(`\\nNext:\\n cd ${cd}\\n${args.skipInstall ? ` ${pm} install\\n` : ''} ${runScript(pm, 'dev')}\\n\\nRead README.md for how the store stays cheap on Vercel before you deploy.`);\n}\n\nmain().catch((error: unknown) => {\n console.error(`create-store: ${error instanceof Error ? error.message : String(error)}`);\n process.exit(1);\n});\n","export type PackageManager = 'pnpm' | 'npm' | 'yarn' | 'bun';\n\nconst MANAGERS: readonly PackageManager[] = ['pnpm', 'npm', 'yarn', 'bun'];\n\n/** The manager that ran `create-store`, from `npm_config_user_agent` (`'pnpm/9.15.4 npm/? node/v20'` is pnpm). Unknown: npm. */\nexport function detectPackageManager(userAgent: string | undefined): PackageManager {\n const name = userAgent?.trim().split(/[\\s/]/u)[0];\n return MANAGERS.find((pm) => pm === name) ?? 'npm';\n}\n\nexport function isPackageManager(value: string): value is PackageManager {\n return (MANAGERS as readonly string[]).includes(value);\n}\n\n/** The command and arguments that install a project's dependencies. */\nexport function installCommand(pm: PackageManager): { command: string; args: string[] } {\n return { command: pm, args: ['install'] };\n}\n\n/** The command a user types to run a package script (`dev`). */\nexport function runScript(pm: PackageManager, script: string): string {\n return pm === 'npm' ? `npm run ${script}` : `${pm} ${script}`;\n}\n","import { isPackageManager, type PackageManager } from './pm';\n\nexport const BUILDER_MODES = ['live', 'build'] as const;\nexport type BuilderMode = (typeof BUILDER_MODES)[number];\n\nexport type Args = {\n dir: string;\n catalogKey?: string;\n serverKey?: string;\n yes: boolean;\n pm?: PackageManager;\n builderMode: BuilderMode;\n skipInstall: boolean;\n offline: boolean;\n help: boolean;\n};\n\nexport const DEFAULT_DIR = 'my-store';\n\nexport const USAGE = `Usage: create-store [dir] [options]\n\n dir Where to create the store (default: ${DEFAULT_DIR})\n --catalog-key <key> The catalog's browser key (pc_pk_...); asked for when missing. A server key is detected\n --server-key <key> The catalog's server key, for reads made by your store's server (asked for after the browser key)\n --yes, -y Take every default and ask nothing\n --builder-mode <m> live (default) or build. build adds a Throttle Builder site that is generated at build time from a frozen release, with no Builder reads while the store runs\n --pm <manager> pnpm, npm, yarn or bun (default: the one running this command)\n --skip-install Write the files and stop before installing dependencies\n --offline Do not call the catalog to tell the keys apart (then --catalog-key and --server-key are both needed)\n --help, -h Show this text`;\n\n/** Reads the command line (without `node` and the script). Throws a readable error for a flag it does not know. */\nexport function parseArgs(argv: string[]): Args {\n const args: Args = { dir: DEFAULT_DIR, builderMode: 'live', yes: false, skipInstall: false, offline: false, help: false };\n const positional: string[] = [];\n const valueOf = (flag: string, inline: string | undefined, index: number): { value: string; next: number } => {\n if (inline !== undefined) return { value: inline, next: index };\n const next = argv[index + 1];\n if (next === undefined || next.startsWith('-')) throw new Error(`${flag} needs a value.`);\n return { value: next, next: index + 1 };\n };\n for (let i = 0; i < argv.length; i++) {\n const raw = argv[i] ?? '';\n if (raw === '--') {\n positional.push(...argv.slice(i + 1));\n break;\n }\n if (!raw.startsWith('-')) {\n positional.push(raw);\n continue;\n }\n const eq = raw.startsWith('--') ? raw.indexOf('=') : -1;\n const flag = eq === -1 ? raw : raw.slice(0, eq);\n const inline = eq === -1 ? undefined : raw.slice(eq + 1);\n switch (flag) {\n case '--catalog-key': {\n const { value, next } = valueOf(flag, inline, i);\n args.catalogKey = value;\n i = next;\n break;\n }\n case '--server-key': {\n const { value, next } = valueOf(flag, inline, i);\n args.serverKey = value;\n i = next;\n break;\n }\n case '--builder-mode': {\n const { value, next } = valueOf(flag, inline, i);\n if (!(BUILDER_MODES as readonly string[]).includes(value)) throw new Error(`--builder-mode must be live or build, not \"${value}\".`);\n args.builderMode = value as BuilderMode;\n i = next;\n break;\n }\n case '--pm': {\n const { value, next } = valueOf(flag, inline, i);\n if (!isPackageManager(value)) throw new Error(`--pm must be pnpm, npm, yarn or bun, not \"${value}\".`);\n args.pm = value;\n i = next;\n break;\n }\n case '--yes':\n case '-y':\n args.yes = true;\n break;\n case '--skip-install':\n args.skipInstall = true;\n break;\n case '--offline':\n args.offline = true;\n break;\n case '--help':\n case '-h':\n args.help = true;\n break;\n default:\n throw new Error(`Unknown option ${flag}.`);\n }\n }\n if (positional.length > 1) throw new Error(`Give one directory, not ${positional.length} (${positional.join(', ')}).`);\n if (positional[0]) args.dir = positional[0];\n return args;\n}\n","export const DEFAULT_CATALOG_URL = 'https://catalog.usethrottle.dev';\n\n/** A catalog publishable key: `pc_pk_` and up to 94 printable characters, no spaces (the catalog SDK's rule). */\nexport function validateCatalogKey(key: string): boolean {\n return /^pc_pk_[\\x21-\\x7e]{1,94}$/u.test(key);\n}\n\n/** Why a key is not accepted, in words for the terminal. */\nexport function catalogKeyProblem(key: string): string | undefined {\n if (validateCatalogKey(key)) return undefined;\n if (key.startsWith('pc_sk_')) return 'That is a secret key (pc_sk_). A storefront takes the publishable key (pc_pk_).';\n return 'A catalog publishable key starts with pc_pk_ and has no spaces.';\n}\n\n/** `unchecked` is only ever made by the caller, when it chose not to ask the catalog (`--offline`). */\nexport type KeyKind = 'server' | 'browser' | 'rejected' | 'unknown' | 'unchecked';\nexport type KeyClassification = { kind: KeyKind; detail: string };\n\n/** The origin of the second request. It is not a real site: a browser key is not allowed from it, a server key is refused from any origin. */\nexport const PROBE_ORIGIN = 'https://create-store.invalid';\n\n/**\n * Tells a catalog server key from a browser key by asking the catalog for its config (`GET /v1/storefront/config`)\n * twice: with no origin (what the store's server sends) and with an `Origin` header (what a browser sends).\n * - 401 on either: the catalog does not know the key (`rejected`).\n * - 200 with no origin, or `SERVER_KEY_IN_BROWSER` with one: a server key.\n * - `ORIGIN_NOT_ALLOWED` with no origin, or 200 or `ORIGIN_NOT_ALLOWED` with one: a browser key.\n * Anything else, or no answer, is `unknown`: the key is never refused for a reason the catalog did not give.\n */\nexport async function classifyCatalogKey(\n key: string,\n options: { baseUrl?: string; fetch?: typeof fetch; timeoutMs?: number } = {},\n): Promise<KeyClassification> {\n const base = (options.baseUrl ?? DEFAULT_CATALOG_URL).replace(/\\/+$/u, '');\n const doFetch = options.fetch ?? fetch;\n const ask = async (origin: string | undefined): Promise<{ status: number; code: string } | undefined> => {\n try {\n const response = await doFetch(`${base}/v1/storefront/config`, {\n headers: { 'x-catalog-key': key, ...(origin ? { origin } : {}) },\n signal: AbortSignal.timeout(options.timeoutMs ?? 8000),\n });\n const text = response.ok ? '' : await response.text().catch(() => '');\n const code = /\"code\"\\s*:\\s*\"([A-Z_]+)\"/u.exec(text)?.[1] ?? '';\n return { status: response.status, code };\n } catch {\n return undefined;\n }\n };\n const [server, browser] = [await ask(undefined), await ask(PROBE_ORIGIN)];\n if (server?.status === 401 || browser?.status === 401) {\n return { kind: 'rejected', detail: 'The catalog does not know this key (401).' };\n }\n if (server?.status === 200 || browser?.code === 'SERVER_KEY_IN_BROWSER') {\n return { kind: 'server', detail: 'This is a server key.' };\n }\n if (server?.code === 'ORIGIN_NOT_ALLOWED' || browser?.status === 200 || browser?.code === 'ORIGIN_NOT_ALLOWED') {\n return { kind: 'browser', detail: 'This is a browser key.' };\n }\n return { kind: 'unknown', detail: server || browser ? `The catalog answered ${(server ?? browser)!.status}.` : 'The catalog did not answer.' };\n}\n","import { catalogKeyProblem, type KeyClassification, type KeyKind } from './catalog-key';\n\nexport type KeyRole = 'browser' | 'server';\n\nexport type KeyDeps = {\n /** Asks the catalog what kind of key this is. */\n classify(key: string): Promise<KeyClassification>;\n /** Asks the user for a key. `undefined` or an empty string: the user skipped or cancelled. */\n ask(role: KeyRole): Promise<string | undefined>;\n};\n\nexport type KeyInput = {\n /** `--catalog-key`: the browser key, or a server key (it is detected). */\n catalogKey?: string;\n /** `--server-key`. */\n serverKey?: string;\n yes: boolean;\n offline: boolean;\n};\n\nexport type ResolvedKeys = {\n /** Goes to `NEXT_PUBLIC_THROTTLE_CATALOG_KEY`. Never a server key. */\n browserKey: string;\n /** Goes to `THROTTLE_CATALOG_SERVER_KEY`. Never a browser key. */\n serverKey?: string;\n /** Things to tell the user, none of them fatal. */\n notes: string[];\n};\n\nconst NEEDS_BOTH =\n 'Could not tell whether the key is a browser key or a server key, and a server key must never be written as the browser key. Pass both: --catalog-key <browser key> --server-key <server key>.';\n\nconst SERVER_NEEDS_BROWSER =\n 'That is a server key, and a store also needs a browser key for the open tab. Pass it with --catalog-key and the server key with --server-key.';\n\nconst ON_YOUR_WORD =\n 'The catalog did not check which key is which, so the roles are taken on your word: --catalog-key as the browser key and --server-key as the server key. If they are the wrong way round, the server key is published to every visitor in NEXT_PUBLIC_THROTTLE_CATALOG_KEY. Check .env.local.';\n\n/**\n * The one rule that keeps a server key out of `NEXT_PUBLIC_THROTTLE_CATALOG_KEY`: the key placed there is either\n * one the catalog said is a browser key, or one the user named as the browser key while also giving a server key\n * (typed at the browser prompt, or `--catalog-key` beside `--server-key`) and nothing contradicted it. A key the\n * catalog said is a server key is never allowed. Anything else is `NEEDS_BOTH`.\n */\nexport function assertBrowserKeyPlacement(p: { browserKind: KeyKind | undefined; named: boolean; hasServerKey: boolean }): void {\n if (p.browserKind === 'browser') return;\n if (p.browserKind !== 'server' && p.named && p.hasServerKey) return;\n throw new Error(NEEDS_BOTH);\n}\n\n/**\n * Settles which key is the store's browser key and which is its server key. A catalog browser key is only\n * answered from an allowed website, so the store's server reads with a server key and the browser with a\n * browser key. A key is never written under the wrong name: a server key is never a `NEXT_PUBLIC_` value.\n * - A browser key (the usual first key): the server key is asked for next, and may be skipped.\n * - A server key: the browser key is asked for next, and is required (an error with `--yes`).\n * - Flags in the wrong order (`--catalog-key` is a server key): put right only when the catalog says the\n * other one is a browser key. Any other answer is an error, never a guess.\n * - A key the catalog cannot place (`--offline`, or no answer) is not taken for the browser key. With both\n * `--catalog-key` and `--server-key` the roles are the ones the user named, with a note that says so;\n * otherwise both are asked for (an error with `--yes`).\n * `assertBrowserKeyPlacement` runs last, whatever path was taken.\n */\nexport async function resolveKeys(o: KeyInput, deps: KeyDeps): Promise<ResolvedKeys> {\n const notes: string[] = [];\n const classify = async (key: string): Promise<KeyKind> => {\n const problem = catalogKeyProblem(key);\n if (problem) throw new Error(problem);\n if (o.offline) return 'unchecked';\n const result = await deps.classify(key);\n if (result.kind === 'rejected') throw new Error(`${result.detail} Check the key, or pass --offline to skip this check.`);\n if (result.kind === 'unknown') notes.push(`Could not tell what kind of key this is (${result.detail}).`);\n return result.kind;\n };\n const askFor = async (role: KeyRole): Promise<string | undefined> => (await deps.ask(role))?.trim() || undefined;\n\n let browser = o.catalogKey?.trim() || undefined;\n let server = o.serverKey?.trim() || undefined;\n /** The user named `browser` as the browser key: typed at the browser prompt, or `--catalog-key` beside `--server-key`. */\n let named = false;\n let browserKind: KeyKind | undefined;\n let serverChecked = false;\n\n if (!browser && !server) {\n if (o.yes) throw new Error('--yes needs --catalog-key <pc_pk_...>.');\n browser = await askFor('browser');\n if (!browser) throw new Error('Cancelled.');\n named = true;\n }\n\n if (browser) {\n browserKind = await classify(browser);\n if (browserKind === 'server') {\n if (server) {\n const other = await classify(server);\n if (other === 'server') throw new Error('--catalog-key and --server-key are both server keys. One of them has to be the browser key.');\n if (other !== 'browser') {\n throw new Error(\n `The catalog says --catalog-key is a server key, but could not confirm that --server-key is a browser key (${other === 'unchecked' ? 'not checked' : 'no clear answer'}). The flags are not swapped on a guess: pass them the right way round, or check the keys in the catalog.`,\n );\n }\n // The flags were the wrong way round, and the catalog confirms it.\n [browser, server] = [server, browser];\n browserKind = 'browser';\n } else {\n server = browser;\n browser = undefined;\n browserKind = undefined;\n }\n serverChecked = true;\n } else if (server) {\n named = true;\n }\n }\n if (server && !serverChecked) {\n if ((await classify(server)) === 'browser') throw new Error('The key given as the server key is a browser key. A server key is made in the catalog under server keys.');\n }\n\n if (!browser) {\n if (o.yes) throw new Error(SERVER_NEEDS_BROWSER);\n browser = await askFor('browser');\n if (!browser) throw new Error('A browser key is needed. Cancelled.');\n named = true;\n browserKind = await classify(browser);\n if (browserKind === 'server') throw new Error('That is a server key too. The browser key is the one the catalog allows your website to use.');\n }\n\n if (!server) {\n if (browserKind !== 'browser') {\n // The catalog could not place the key: it is not put under a name on a guess.\n if (o.yes) throw new Error(NEEDS_BOTH);\n if (!named) {\n notes.push('Could not tell what kind of key --catalog-key is, so both keys are asked for.');\n browser = await askFor('browser');\n if (!browser) throw new Error('A browser key is needed. Cancelled.');\n named = true;\n browserKind = await classify(browser);\n if (browserKind === 'server') throw new Error('That is a server key too. The browser key is the one the catalog allows your website to use.');\n }\n server = await askFor('server');\n if (!server) throw new Error('A server key is needed when the keys cannot be told apart. Cancelled.');\n if ((await classify(server)) === 'browser') throw new Error('That is a browser key, not a server key.');\n } else if (!o.yes) {\n const given = await askFor('server');\n if (given) {\n if ((await classify(given)) === 'browser') throw new Error('That is a browser key, not a server key.');\n server = given;\n }\n }\n }\n\n assertBrowserKeyPlacement({ browserKind, named, hasServerKey: server !== undefined });\n if (browserKind !== 'browser') notes.push(ON_YOUR_WORD);\n if (!server) {\n notes.push(\n 'No server key. The browser key is only answered from an allowed website, so your store\\'s server cannot read with it: add the catalog\\'s server key as THROTTLE_CATALOG_SERVER_KEY in .env.local (see README.md).',\n );\n }\n return { browserKey: browser, ...(server ? { serverKey: server } : {}), notes };\n}\n","import prompts from 'prompts';\nimport { catalogKeyProblem } from './catalog-key';\nimport type { KeyRole } from './keys';\n\nconst MESSAGES: Record<KeyRole, string> = {\n browser: 'Catalog publishable key (pc_pk_...)',\n server: 'Catalog server key, for your store\\'s server (pc_pk_..., press enter to skip)',\n};\n\n/** Asks for a catalog key. Returns undefined when the user cancels, or skips the optional server key. */\nexport async function askCatalogKey(role: KeyRole): Promise<string | undefined> {\n const answer = await prompts(\n {\n type: 'text',\n name: 'catalogKey',\n message: MESSAGES[role],\n validate: (value: string) => (role === 'server' && value.trim() === '' ? true : (catalogKeyProblem(value.trim()) ?? true)),\n },\n { onCancel: () => false },\n );\n const key: unknown = answer.catalogKey;\n return typeof key === 'string' ? key.trim() : undefined;\n}\n","import { mkdir, readdir, readFile, stat, writeFile } from 'node:fs/promises';\nimport { basename, dirname, join, relative, resolve } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport type { BuilderMode } from './args';\nimport { catalogKeyProblem } from './catalog-key';\n\n/** `template/` sits beside `src/` and `dist/`, so one path reaches it from the source and from the build. */\nexport const TEMPLATE_DIR = resolve(dirname(fileURLToPath(import.meta.url)), '../template');\n\n/**\n * What `--builder-mode build` lays over the template: a file replaces the template's file of the same path, a\n * `.append` file is added to the end of it, anything else is new. A live store never reads this folder.\n */\nexport const BUILD_TEMPLATE_DIR = resolve(dirname(fileURLToPath(import.meta.url)), '../template-builder-build');\n\nexport type ScaffoldOptions = {\n /** Where to write the store. It may exist, but must be empty. */\n dir: string;\n /** The catalog's browser key, written to `.env.local` as `NEXT_PUBLIC_THROTTLE_CATALOG_KEY`. */\n catalogKey: string;\n /** The catalog's server key, written as `THROTTLE_CATALOG_SERVER_KEY` (never a `NEXT_PUBLIC_` value). Optional. */\n serverKey?: string;\n /** `build`: statically generate a Throttle Builder site from a frozen release. `live` (default) adds nothing. */\n builderMode?: BuilderMode;\n /** The Throttle package versions for the store's `dependencies` (`TEMPLATE_VERSIONS`). */\n versions: Record<string, string>;\n};\n\nasync function filesUnder(root: string, dir = root): Promise<string[]> {\n const found: string[] = [];\n for (const entry of await readdir(dir, { withFileTypes: true })) {\n const path = join(dir, entry.name);\n if (entry.isDirectory()) found.push(...(await filesUnder(root, path)));\n else found.push(relative(root, path));\n }\n return found.sort();\n}\n\n/** A valid npm package name from a folder name. */\nexport function packageNameOf(dir: string): string {\n const cleaned = basename(resolve(dir))\n .toLowerCase()\n .replace(/[^a-z0-9._-]+/gu, '-')\n .replace(/^[._-]+|[-]+$/gu, '');\n return cleaned || 'throttle-store';\n}\n\nfunction render(text: string, values: Record<string, string>): string {\n return text.replace(/\\{\\{(\\w+)\\}\\}/gu, (_all, name: string) => {\n const value = values[name];\n if (value === undefined) throw new Error(`The template uses {{${name}}}, which scaffold does not set.`);\n return value;\n });\n}\n\n/**\n * Writes the store template into `dir` and returns the absolute paths it wrote. A `.tmpl` file loses its\n * suffix (npm drops `.gitignore` and renames `package.json` files, so those travel as templates) and has its\n * `{{name}}`, `{{catalogKey}}` and `{{serverKeyLine}}` filled in. `package.json` also gets the Throttle packages' versions.\n * Refuses a directory that already holds anything, so it never overwrites a project.\n */\nexport async function scaffold(o: ScaffoldOptions): Promise<string[]> {\n const problem = catalogKeyProblem(o.catalogKey);\n if (problem) throw new Error(problem);\n const serverProblem = o.serverKey === undefined ? undefined : catalogKeyProblem(o.serverKey);\n if (serverProblem) throw new Error(serverProblem);\n const target = resolve(o.dir);\n const existing = await stat(target).then(\n () => readdir(target),\n () => null,\n );\n if (existing && existing.length > 0) {\n throw new Error(`${target} is not empty. Pick a new directory, or empty this one first.`);\n }\n const values = {\n name: packageNameOf(target),\n catalogKey: o.catalogKey,\n serverKeyLine: o.serverKey\n ? `THROTTLE_CATALOG_SERVER_KEY=${o.serverKey}`\n : '# THROTTLE_CATALOG_SERVER_KEY= (the catalog\\'s server key; see README.md)',\n };\n // The text of every file to write, by its path in the store. The overlay of a build-mode store lands on top.\n const files = new Map<string, string>();\n const read = async (root: string, overlay: boolean) => {\n for (const file of await filesUnder(root)) {\n const append = overlay && file.endsWith('.append');\n const name = append ? file.slice(0, -'.append'.length) : file;\n const isTemplate = name.endsWith('.tmpl');\n const out = isTemplate ? name.slice(0, -'.tmpl'.length) : name;\n let text = await readFile(join(root, file), 'utf8');\n if (isTemplate) text = render(text, values);\n files.set(out, append ? (files.get(out) ?? '') + text : text);\n }\n };\n await read(TEMPLATE_DIR, false);\n if (o.builderMode === 'build') await read(BUILD_TEMPLATE_DIR, true);\n\n const written: string[] = [];\n for (const [file, content] of files) {\n const out = join(target, file);\n let text = content;\n if (basename(out) === 'package.json') {\n const manifest = JSON.parse(text) as { dependencies?: Record<string, string> };\n const dependencies = { ...manifest.dependencies, ...o.versions };\n manifest.dependencies = Object.fromEntries(Object.entries(dependencies).sort(([a], [b]) => a.localeCompare(b)));\n text = `${JSON.stringify(manifest, null, 2)}\\n`;\n }\n await mkdir(dirname(out), { recursive: true });\n await writeFile(out, text, 'utf8');\n written.push(out);\n }\n return written;\n}\n","{\n \"name\": \"@usethrottle/auth\",\n \"version\": \"0.15.0\",\n \"description\": \"Buyer authentication for Throttle storefronts — headless core, React hooks, and drop-in forms.\",\n \"type\": \"module\",\n \"main\": \"./dist/index.cjs\",\n \"module\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"files\": [\n \"dist\",\n \"README.md\",\n \"CLAUDE.md\"\n ],\n \"sideEffects\": [\n \"**/*.css\"\n ],\n \"exports\": {\n \".\": {\n \"types\": \"./dist/index.d.ts\",\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\"\n },\n \"./react\": {\n \"types\": \"./dist/react/index.d.ts\",\n \"import\": \"./dist/react/index.js\",\n \"require\": \"./dist/react/index.cjs\"\n },\n \"./forms\": {\n \"types\": \"./dist/react/forms/index.d.ts\",\n \"import\": \"./dist/react/forms/index.js\",\n \"require\": \"./dist/react/forms/index.cjs\"\n },\n \"./components\": {\n \"types\": \"./dist/react/components/index.d.ts\",\n \"import\": \"./dist/react/components/index.js\",\n \"require\": \"./dist/react/components/index.cjs\"\n },\n \"./styles.css\": \"./dist/styles.css\",\n \"./package.json\": \"./package.json\"\n },\n \"scripts\": {\n \"build\": \"tsup\",\n \"dev\": \"tsup --watch\",\n \"test\": \"vitest run\",\n \"typecheck\": \"tsc --noEmit\"\n },\n \"dependencies\": {\n \"@usethrottle/money\": \"workspace:^\",\n \"@usethrottle/ui\": \"workspace:^\"\n },\n \"peerDependencies\": {\n \"react\": \">=18\",\n \"react-dom\": \">=18\"\n },\n \"peerDependenciesMeta\": {\n \"react\": {\n \"optional\": true\n },\n \"react-dom\": {\n \"optional\": true\n }\n },\n \"devDependencies\": {\n \"@core/cadence\": \"workspace:*\",\n \"@testing-library/react\": \"^16.1.0\",\n \"@types/react\": \"^19.1.0\",\n \"@types/react-dom\": \"^19.1.0\",\n \"@vitejs/plugin-react\": \"^4.3.4\",\n \"jsdom\": \"^25.0.1\",\n \"react\": \"^19.1.0\",\n \"react-dom\": \"^19.1.0\",\n \"tsup\": \"^8.0.0\",\n \"typescript\": \"^5.7.0\",\n \"vitest\": \"^2.1.9\"\n },\n \"publishConfig\": {\n \"access\": \"public\"\n },\n \"engines\": {\n \"node\": \">=20\"\n }\n}\n","{\n \"name\": \"@usethrottle/builder\",\n \"version\": \"0.2.0\",\n \"description\": \"Headless client for Throttle Builder: read published pages, parts, slots and site settings from a storefront, with Next.js cache, revalidation and preview helpers.\",\n \"license\": \"MIT\",\n \"type\": \"module\",\n \"main\": \"./dist/index.cjs\",\n \"module\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"exports\": {\n \".\": {\n \"import\": {\n \"types\": \"./dist/index.d.ts\",\n \"default\": \"./dist/index.js\"\n },\n \"require\": {\n \"types\": \"./dist/index.d.cts\",\n \"default\": \"./dist/index.cjs\"\n }\n },\n \"./next\": {\n \"import\": {\n \"types\": \"./dist/next.d.ts\",\n \"default\": \"./dist/next.js\"\n },\n \"require\": {\n \"types\": \"./dist/next.d.cts\",\n \"default\": \"./dist/next.cjs\"\n }\n },\n \"./watch\": {\n \"import\": {\n \"types\": \"./dist/watch.d.ts\",\n \"default\": \"./dist/watch.js\"\n },\n \"require\": {\n \"types\": \"./dist/watch.d.cts\",\n \"default\": \"./dist/watch.cjs\"\n }\n },\n \"./package.json\": \"./package.json\"\n },\n \"files\": [\n \"dist\"\n ],\n \"sideEffects\": [\n \"./dist/next.js\",\n \"./dist/next.cjs\"\n ],\n \"engines\": {\n \"node\": \">=20\"\n },\n \"scripts\": {\n \"build\": \"tsup\",\n \"test\": \"vitest run\",\n \"typecheck\": \"tsc --noEmit && tsc --noEmit -p tsconfig.test.json\"\n },\n \"keywords\": [\n \"throttle\",\n \"usethrottle\",\n \"builder\",\n \"page-builder\",\n \"nextjs\"\n ],\n \"dependencies\": {\n \"@usethrottle/builder-schema\": \"workspace:^\",\n \"server-only\": \"0.0.1\"\n },\n \"peerDependencies\": {\n \"next\": \">=14\",\n \"react\": \">=18\"\n },\n \"peerDependenciesMeta\": {\n \"next\": {\n \"optional\": true\n },\n \"react\": {\n \"optional\": true\n }\n },\n \"devDependencies\": {\n \"@testing-library/react\": \"^16.1.0\",\n \"@types/node\": \"^20.0.0\",\n \"@types/react\": \"^19.1.0\",\n \"@types/react-dom\": \"^19.1.0\",\n \"jsdom\": \"^25.0.1\",\n \"react\": \"^19.1.0\",\n \"react-dom\": \"^19.1.0\",\n \"tsup\": \"^8.0.0\",\n \"typescript\": \"^5.7.0\",\n \"vitest\": \"^2.1.9\"\n },\n \"publishConfig\": {\n \"access\": \"public\"\n }\n}\n","{\n \"name\": \"@usethrottle/builder-react\",\n \"version\": \"0.2.0\",\n \"description\": \"Renders a published Throttle Builder page document as React in a merchant's store: responsive CSS, header, footer, slots and the site design provider.\",\n \"license\": \"MIT\",\n \"type\": \"module\",\n \"main\": \"./dist/index.cjs\",\n \"module\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"exports\": {\n \".\": {\n \"import\": {\n \"types\": \"./dist/index.d.ts\",\n \"default\": \"./dist/index.js\"\n },\n \"require\": {\n \"types\": \"./dist/index.d.cts\",\n \"default\": \"./dist/index.cjs\"\n }\n },\n \"./server\": {\n \"import\": {\n \"types\": \"./dist/server.d.ts\",\n \"default\": \"./dist/server.js\"\n },\n \"require\": {\n \"types\": \"./dist/server.d.cts\",\n \"default\": \"./dist/server.cjs\"\n }\n },\n \"./next\": {\n \"import\": {\n \"types\": \"./dist/next.d.ts\",\n \"default\": \"./dist/next.js\"\n },\n \"require\": {\n \"types\": \"./dist/next.d.cts\",\n \"default\": \"./dist/next.cjs\"\n }\n },\n \"./package.json\": \"./package.json\"\n },\n \"files\": [\n \"dist\",\n \"CLAUDE.md\"\n ],\n \"sideEffects\": false,\n \"engines\": {\n \"node\": \">=20\"\n },\n \"scripts\": {\n \"build\": \"tsup\",\n \"dev\": \"node scripts/playground.mjs\",\n \"test\": \"vitest run\",\n \"typecheck\": \"tsc --noEmit && tsc --noEmit -p tsconfig.test.json\",\n \"size\": \"node scripts/size.mjs\",\n \"test:rsc\": \"node scripts/rsc-build.mjs\"\n },\n \"keywords\": [\n \"throttle\",\n \"usethrottle\",\n \"builder\",\n \"page-builder\",\n \"react\",\n \"nextjs\"\n ],\n \"dependencies\": {\n \"@usethrottle/builder\": \"workspace:^\",\n \"@usethrottle/builder-schema\": \"workspace:^\",\n \"@usethrottle/ui\": \"workspace:^\"\n },\n \"peerDependencies\": {\n \"next\": \">=15\",\n \"react\": \">=18\",\n \"react-dom\": \">=18\"\n },\n \"peerDependenciesMeta\": {\n \"next\": {\n \"optional\": true\n }\n },\n \"devDependencies\": {\n \"@testing-library/react\": \"^16.1.0\",\n \"@types/node\": \"^20.0.0\",\n \"@types/react\": \"^19.1.0\",\n \"@types/react-dom\": \"^19.1.0\",\n \"jsdom\": \"^25.0.1\",\n \"next\": \"15.5.15\",\n \"playwright\": \"^1.62.1\",\n \"react\": \"19.2.5\",\n \"react-dom\": \"19.2.5\",\n \"tsup\": \"^8.0.0\",\n \"typescript\": \"^5.7.0\",\n \"vitest\": \"^2.1.9\"\n },\n \"publishConfig\": {\n \"access\": \"public\"\n }\n}\n","{\n \"name\": \"@usethrottle/builder-schema\",\n \"version\": \"0.1.2\",\n \"description\": \"Throttle Builder page document, site settings, responsive rules, limits and basic widget definitions. Pure TypeScript plus zod, no React and no I/O.\",\n \"type\": \"module\",\n \"main\": \"./dist/index.cjs\",\n \"module\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"exports\": {\n \".\": {\n \"import\": {\n \"types\": \"./dist/index.d.ts\",\n \"default\": \"./dist/index.js\"\n },\n \"require\": {\n \"types\": \"./dist/index.d.cts\",\n \"default\": \"./dist/index.cjs\"\n }\n }\n },\n \"files\": [\n \"dist\",\n \"__tests__/fixtures/parity\"\n ],\n \"sideEffects\": [\n \"./dist/index.js\",\n \"./dist/index.cjs\",\n \"./src/jitless.ts\"\n ],\n \"scripts\": {\n \"build\": \"tsup\",\n \"test\": \"vitest run\",\n \"typecheck\": \"tsc --noEmit && tsc --noEmit -p tsconfig.test.json\"\n },\n \"keywords\": [\n \"throttle\",\n \"usethrottle\",\n \"builder\",\n \"page-builder\",\n \"schema\"\n ],\n \"dependencies\": {\n \"zod\": \"^4.4.3\"\n },\n \"devDependencies\": {\n \"@types/node\": \"^20.0.0\",\n \"fast-check\": \"^3.23.0\",\n \"tsup\": \"^8.0.0\",\n \"typescript\": \"^5.7.0\",\n \"vitest\": \"^2.1.9\"\n },\n \"publishConfig\": {\n \"access\": \"public\"\n }\n}\n","{\n \"name\": \"@usethrottle/storefront-react\",\n \"version\": \"0.2.2\",\n \"description\": \"Drop-in, settings-driven React storefront components for Throttle catalogs.\",\n \"type\": \"module\",\n \"main\": \"./dist/index.cjs\",\n \"module\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"files\": [\n \"dist\",\n \"builder-pack.json\",\n \"README.md\",\n \"CLAUDE.md\"\n ],\n \"sideEffects\": [\n \"**/*.css\"\n ],\n \"exports\": {\n \".\": {\n \"import\": {\n \"types\": \"./dist/index.d.ts\",\n \"default\": \"./dist/index.js\"\n },\n \"require\": {\n \"types\": \"./dist/index.d.cts\",\n \"default\": \"./dist/index.cjs\"\n }\n },\n \"./server\": {\n \"import\": {\n \"types\": \"./dist/server/index.d.ts\",\n \"default\": \"./dist/server/index.js\"\n },\n \"require\": {\n \"types\": \"./dist/server/index.d.cts\",\n \"default\": \"./dist/server/index.cjs\"\n }\n },\n \"./next\": {\n \"import\": {\n \"types\": \"./dist/next/index.d.ts\",\n \"default\": \"./dist/next/index.js\"\n },\n \"require\": {\n \"types\": \"./dist/next/index.d.cts\",\n \"default\": \"./dist/next/index.cjs\"\n }\n },\n \"./next/client\": {\n \"import\": {\n \"types\": \"./dist/next/client.d.ts\",\n \"default\": \"./dist/next/client.js\"\n },\n \"require\": {\n \"types\": \"./dist/next/client.d.cts\",\n \"default\": \"./dist/next/client.cjs\"\n }\n },\n \"./account\": {\n \"import\": {\n \"types\": \"./dist/account/index.d.ts\",\n \"default\": \"./dist/account/index.js\"\n },\n \"require\": {\n \"types\": \"./dist/account/index.d.cts\",\n \"default\": \"./dist/account/index.cjs\"\n }\n },\n \"./builder\": {\n \"import\": {\n \"types\": \"./dist/builder/index.d.ts\",\n \"default\": \"./dist/builder/index.js\"\n },\n \"require\": {\n \"types\": \"./dist/builder/index.d.cts\",\n \"default\": \"./dist/builder/index.cjs\"\n }\n },\n \"./builder-pack.json\": \"./builder-pack.json\",\n \"./styles.css\": \"./dist/styles.css\",\n \"./package.json\": \"./package.json\"\n },\n \"scripts\": {\n \"build\": \"tsup && node scripts/build-pack-manifest.mjs\",\n \"dev\": \"tsup --watch\",\n \"test\": \"vitest run\",\n \"typecheck\": \"tsc --noEmit\"\n },\n \"dependencies\": {\n \"@usethrottle/ui\": \"workspace:^\"\n },\n \"peerDependencies\": {\n \"@usethrottle/auth\": \">=0.15.0\",\n \"@usethrottle/builder-react\": \"^0.1.0 || ^0.2.0\",\n \"@usethrottle/builder-schema\": \"^0.1.2\",\n \"@usethrottle/catalog\": \"^1.4.1\",\n \"@usethrottle/money\": \"^1.1.0\",\n \"@usethrottle/scripts\": \">=0.4.0\",\n \"next\": \">=15\",\n \"react\": \">=18\",\n \"react-dom\": \">=18\"\n },\n \"peerDependenciesMeta\": {\n \"@usethrottle/auth\": {\n \"optional\": true\n },\n \"@usethrottle/builder-react\": {\n \"optional\": true\n },\n \"@usethrottle/builder-schema\": {\n \"optional\": true\n },\n \"@usethrottle/scripts\": {\n \"optional\": true\n },\n \"next\": {\n \"optional\": true\n }\n },\n \"devDependencies\": {\n \"@testing-library/react\": \"^16.1.0\",\n \"@types/node\": \"^20\",\n \"@types/react\": \"^19.1.0\",\n \"@types/react-dom\": \"^19.1.0\",\n \"@usethrottle/auth\": \"workspace:*\",\n \"@usethrottle/builder-react\": \"workspace:*\",\n \"@usethrottle/builder-schema\": \"workspace:*\",\n \"@usethrottle/catalog\": \"1.4.1\",\n \"@usethrottle/money\": \"workspace:*\",\n \"@usethrottle/scripts\": \"workspace:*\",\n \"@vitejs/plugin-react\": \"^4.3.4\",\n \"jsdom\": \"^25.0.1\",\n \"next\": \"16.3.5\",\n \"react\": \"^19.1.0\",\n \"react-dom\": \"^19.1.0\",\n \"tsup\": \"^8.0.0\",\n \"typescript\": \"^5.7.0\",\n \"vitest\": \"^2.1.9\"\n },\n \"publishConfig\": {\n \"access\": \"public\"\n },\n \"engines\": {\n \"node\": \">=20\"\n }\n}\n","{\n \"name\": \"@usethrottle/ui\",\n \"version\": \"0.1.2\",\n \"description\": \"Shared theme, presets, primitives and icons for Throttle React components.\",\n \"type\": \"module\",\n \"main\": \"./dist/index.cjs\",\n \"module\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"files\": [\n \"dist\",\n \"CLAUDE.md\"\n ],\n \"sideEffects\": false,\n \"exports\": {\n \".\": {\n \"import\": {\n \"types\": \"./dist/index.d.ts\",\n \"default\": \"./dist/index.js\"\n },\n \"require\": {\n \"types\": \"./dist/index.d.cts\",\n \"default\": \"./dist/index.cjs\"\n }\n },\n \"./presets\": {\n \"import\": {\n \"types\": \"./dist/presets.d.ts\",\n \"default\": \"./dist/presets.js\"\n },\n \"require\": {\n \"types\": \"./dist/presets.d.cts\",\n \"default\": \"./dist/presets.cjs\"\n }\n },\n \"./package.json\": \"./package.json\"\n },\n \"scripts\": {\n \"build\": \"tsup\",\n \"dev\": \"tsup --watch\",\n \"test\": \"vitest run\",\n \"typecheck\": \"tsc --noEmit\"\n },\n \"peerDependencies\": {\n \"react\": \">=18\",\n \"react-dom\": \">=18\"\n },\n \"devDependencies\": {\n \"@testing-library/react\": \"^16.1.0\",\n \"@types/react\": \"^19.1.0\",\n \"@types/react-dom\": \"^19.1.0\",\n \"@vitejs/plugin-react\": \"^4.3.4\",\n \"jsdom\": \"^25.0.1\",\n \"react\": \"^19.1.0\",\n \"react-dom\": \"^19.1.0\",\n \"tsup\": \"^8.0.0\",\n \"typescript\": \"^5.7.0\",\n \"vitest\": \"^2.1.9\"\n },\n \"publishConfig\": {\n \"access\": \"public\"\n },\n \"engines\": {\n \"node\": \">=20\"\n }\n}\n","import { version as auth } from '../../auth-sdk/package.json';\nimport { version as builder } from '../../builder/package.json';\nimport { version as builderReact } from '../../builder-react/package.json';\nimport { version as builderSchema } from '../../builder-schema/package.json';\nimport { version as storefrontReact } from '../../storefront-react/package.json';\nimport { version as ui } from '../../ui/package.json';\n\n/**\n * The versions a new store depends on. The three Throttle packages that ship with this CLI take the\n * version they have in this workspace when the CLI is built, so a store always gets the release this\n * CLI was published with. The catalog SDK and `@usethrottle/money` live elsewhere and are ranges: one\n * `@usethrottle/money` for the whole tree is what `@usethrottle/storefront-react` needs.\n */\nexport const TEMPLATE_VERSIONS: Record<string, string> = {\n '@usethrottle/storefront-react': `^${storefrontReact}`,\n '@usethrottle/ui': `^${ui}`,\n '@usethrottle/auth': `^${auth}`,\n '@usethrottle/catalog': '^1.4.1',\n '@usethrottle/money': '^1.1.0',\n};\n\n/** What `--builder-mode build` adds to a store's `dependencies`, from the workspace versions at build like the rest. */\nexport const BUILD_MODE_VERSIONS: Record<string, string> = {\n '@usethrottle/builder': `^${builder}`,\n '@usethrottle/builder-react': `^${builderReact}`,\n '@usethrottle/builder-schema': `^${builderSchema}`,\n};\n"],"mappings":";;;AACA,SAAS,aAAa;AACtB,SAAS,YAAAA,WAAU,WAAAC,gBAAe;;;ACAlC,IAAM,WAAsC,CAAC,QAAQ,OAAO,QAAQ,KAAK;AAGlE,SAAS,qBAAqB,WAA+C;AAClF,QAAM,OAAO,WAAW,KAAK,EAAE,MAAM,QAAQ,EAAE,CAAC;AAChD,SAAO,SAAS,KAAK,CAAC,OAAO,OAAO,IAAI,KAAK;AAC/C;AAEO,SAAS,iBAAiB,OAAwC;AACvE,SAAQ,SAA+B,SAAS,KAAK;AACvD;AAGO,SAAS,eAAe,IAAyD;AACtF,SAAO,EAAE,SAAS,IAAI,MAAM,CAAC,SAAS,EAAE;AAC1C;AAGO,SAAS,UAAU,IAAoB,QAAwB;AACpE,SAAO,OAAO,QAAQ,WAAW,MAAM,KAAK,GAAG,EAAE,IAAI,MAAM;AAC7D;;;ACpBO,IAAM,gBAAgB,CAAC,QAAQ,OAAO;AAetC,IAAM,cAAc;AAEpB,IAAM,QAAQ;AAAA;AAAA,6DAEwC,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWjE,SAAS,UAAU,MAAsB;AAC9C,QAAM,OAAa,EAAE,KAAK,aAAa,aAAa,QAAQ,KAAK,OAAO,aAAa,OAAO,SAAS,OAAO,MAAM,MAAM;AACxH,QAAM,aAAuB,CAAC;AAC9B,QAAM,UAAU,CAAC,MAAc,QAA4B,UAAmD;AAC5G,QAAI,WAAW,OAAW,QAAO,EAAE,OA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AAA,EACH,SAAS,OAAO;AACd,WAAO,KAAK,iBAAiB,QAAQ,MAAM,UAAU,4BAA4B;AAAA,EACnF;AACA,QAAM,SAASC,SAAQ,KAAK,GAAG;AAC/B,UAAQ,IAAI,WAAW,QAAQ,MAAM,aAAa,MAAM,EAAE;AAE1D,QAAM,KAAK,KAAK,MAAM,qBAAqB,QAAQ,IAAI,qBAAqB;AAC5E,MAAI,CAAC,KAAK,aAAa;AACrB,YAAQ,IAAI,mBAAmB,EAAE,KAAK;AACtC,QAAI,CAAE,MAAM,QAAQ,IAAI,MAAM,EAAI,SAAQ,KAAK,iBAAiB,EAAE,yDAAyD;AAAA,EAC7H;AAEA,QAAM,MAAMC,UAAS,QAAQ,IAAI,GAAG,MAAM,KAAK;AAC/C,QAAM,KAAK,IAAI,WAAW,IAAI,IAAI,SAAS;AAC3C,UAAQ,IAAI;AAAA;AAAA,OAAiB,EAAE;AAAA,EAAK,KAAK,cAAc,KAAK,EAAE;AAAA,IAAe,EAAE,KAAK,UAAU,IAAI,KAAK,CAAC;AAAA;AAAA,0EAA+E;AACzL;AAEA,KAAK,EAAE,MAAM,CAAC,UAAmB;AAC/B,UAAQ,MAAM,iBAAiB,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC,EAAE;AACvF,UAAQ,KAAK,CAAC;AAChB,CAAC;","names":["relative","resolve","version","version","version","version","version","version","resolve","relative"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usethrottle/create-store",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Scaffold a complete Next.js storefront on @usethrottle/storefront-react.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"files": [
|
|
10
10
|
"dist",
|
|
11
11
|
"template",
|
|
12
|
+
"template-builder-build",
|
|
12
13
|
"README.md",
|
|
13
14
|
"CLAUDE.md"
|
|
14
15
|
],
|
|
@@ -29,8 +30,11 @@
|
|
|
29
30
|
"typescript": "^5.7.0",
|
|
30
31
|
"vitest": "^2.1.9",
|
|
31
32
|
"@usethrottle/auth": "0.15.0",
|
|
33
|
+
"@usethrottle/builder-react": "0.2.0",
|
|
34
|
+
"@usethrottle/builder-schema": "0.1.2",
|
|
35
|
+
"@usethrottle/builder": "0.2.0",
|
|
36
|
+
"@usethrottle/storefront-react": "0.2.2",
|
|
32
37
|
"@usethrottle/money": "1.1.0",
|
|
33
|
-
"@usethrottle/storefront-react": "0.1.0",
|
|
34
38
|
"@usethrottle/ui": "0.1.2"
|
|
35
39
|
},
|
|
36
40
|
"publishConfig": {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
|
|
2
|
+
# Build mode (--builder-mode build). `next build` reads the Builder once and writes .builder/release.json; the running store never calls it.
|
|
3
|
+
# THROTTLE_BUILDER_KEY the Builder build key: the publishable key of a SERVER channel (tb_pk_...), or a secret key
|
|
4
|
+
# holding releases:read. Needed by `next build` only (set it here and on your host's build);
|
|
5
|
+
# never a NEXT_PUBLIC_ variable.
|
|
6
|
+
# THROTTLE_MEDIA_ORIGIN the https origin your Builder images are served from. Images on any other origin are not drawn,
|
|
7
|
+
# and a page has no og:image (share image) without it.
|
|
8
|
+
# NEXT_PUBLIC_SITE_URL (above) is also the origin of the canonical links and the sitemap of your Builder pages.
|
|
9
|
+
# BUILDER_RELEASE_ID optional: build this release instead of the newest (a rebuild of an older release)
|
|
10
|
+
# THROTTLE_BUILDER_KEY=
|
|
11
|
+
# THROTTLE_MEDIA_ORIGIN=
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
|
|
2
|
+
## Builder build mode (this store was created with `--builder-mode build`)
|
|
3
|
+
|
|
4
|
+
- The Builder is read once, by `next build` (`next.config.ts` writes `.builder/release.json`). Everything else, the pages, the
|
|
5
|
+
root layout and `app/sitemap.ts`, renders from that file through `lib/builder.ts` (`createBuilderClient({ mode: 'build' })`).
|
|
6
|
+
Do not call the Builder at request time, do not give `BuilderProvider` a `builderKey`, and do not use the live client
|
|
7
|
+
(`@usethrottle/builder` without `mode: 'build'`).
|
|
8
|
+
- Keep `outputFileTracingIncludes` in `next.config.ts`: without it the file is not in the deployed output and a cold
|
|
9
|
+
instance has no release to render, and a store with no release file fails on purpose instead of downloading the release.
|
|
10
|
+
An API route that renders pages or reads the Builder client must be added to it (the `/api` routes are left out).
|
|
11
|
+
- Keep `generateStaticParams` and `dynamicParams = false` in `app/pages/[handle]/page.tsx`: they are what makes a release
|
|
12
|
+
a single build with no Builder-driven ISR writes. The cap on prerendered pages that applies to catalog products does not apply
|
|
13
|
+
to a release. A renamed page's redirect lives in `next.config.ts`, because `dynamicParams = false` would 404 it first.
|
|
14
|
+
- `THROTTLE_BUILDER_KEY` is a build secret: never a `NEXT_PUBLIC_` variable.
|
|
15
|
+
- Keep `cachePolicy: { settings: '525600m' }` in `app/layout.tsx`: without it the layout's settings read is an hour, and Next
|
|
16
|
+
renders every release page again each hour.
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
|
|
2
|
+
## Builder build mode
|
|
3
|
+
|
|
4
|
+
This store was created with `--builder-mode build`: its Throttle Builder pages are **generated at build time from a
|
|
5
|
+
frozen release**, and the running store never calls the Builder.
|
|
6
|
+
|
|
7
|
+
- **One full build per release, zero Builder-driven ISR writes.** In the Builder, pending changes pile up until you press
|
|
8
|
+
**Release**. That freezes everything published at that moment (site settings, every page, header, footer, slots, frozen
|
|
9
|
+
custom widgets and assets) and calls your host's deploy hook once. The hook starts a build, and `next build` reads the
|
|
10
|
+
release and statically generates every page of it (`generateStaticParams` in `app/pages/[handle]/page.tsx`,
|
|
11
|
+
`dynamicParams = false`). Nothing on a timer regenerates them and nothing in the Builder does, so a release costs the one
|
|
12
|
+
build. Catalog changes still re-render pages through the signed `/api/throttle/revalidate` webhook, exactly as in a live
|
|
13
|
+
store. This is the one place the store generates every page on purpose: one build per release, not one write per visit.
|
|
14
|
+
- **The release is a file.** `next.config.ts` reads the release from the Builder once and writes it to
|
|
15
|
+
`.builder/release.json` (git-ignored); Next copies that file into the build output, and every page, the layout (header,
|
|
16
|
+
footer, slots) and the sitemap render from it. Nothing reads the Builder at run time, not even a cold instance rendering
|
|
17
|
+
`/search` or a product page, and the running store needs no Builder key. The build workers read the file too instead of
|
|
18
|
+
downloading the bundle again. The bundle is read into memory whole (up to 48 MB), so the build machine needs that much
|
|
19
|
+
headroom, and the file ships in every server function, so mind your host's function size limit.
|
|
20
|
+
- **A store with no release file fails on purpose.** If `.builder/release.json` is missing or corrupt at run time, the
|
|
21
|
+
page that needs it throws a clear error, even when `THROTTLE_BUILDER_KEY` is set on the host (a quiet fallback would
|
|
22
|
+
download the whole release on every cold start). Run `next build` again. Only `next dev` reads from the Builder: with
|
|
23
|
+
`THROTTLE_BUILDER_KEY` set it reads a fresh release and ignores the file, without it it uses the file of the last build;
|
|
24
|
+
it logs which one. A release over about 20 MB prints a warning at build, because the file is in every page's server
|
|
25
|
+
function (the `/api` routes are left out).
|
|
26
|
+
- **Why the layout reads settings for a year.** A page lives only as long as its shortest read, and the catalog settings read
|
|
27
|
+
in `app/layout.tsx` defaults to an hour, which would have Next render the release pages again every hour. `app/layout.tsx`
|
|
28
|
+
sets `cachePolicy: { settings: '525600m' }` (a year; never under an hour, the cost rule). A catalog change still reaches
|
|
29
|
+
the pages through the webhook, and a page rendered again reads the frozen release, never a newer one.
|
|
30
|
+
- **Set up the deploy hook.** Create a deploy hook on your host (Vercel: Project Settings, Git, Deploy Hooks), paste its
|
|
31
|
+
https URL in the Builder's release settings, and switch the store to build mode there.
|
|
32
|
+
- **The build reads the newest release**, or the one named by `BUILDER_RELEASE_ID`; a whole build is one release, even if
|
|
33
|
+
someone presses Release while it runs. Rolling back in the Builder makes a new release of an older snapshot and deploys it.
|
|
34
|
+
Set `BUILDER_RELEASE_ID` to rebuild a specific release by hand.
|
|
35
|
+
- **Keys.** `THROTTLE_BUILDER_KEY` is a build key (the publishable key of a server channel, or a secret key with
|
|
36
|
+
`releases:read`). It is for `next build` only; never put it in a `NEXT_PUBLIC_` variable. `THROTTLE_MEDIA_ORIGIN` is the
|
|
37
|
+
https origin your Builder images come from (and the only origin an og:image may be on).
|
|
38
|
+
- **Search and sharing.** Each Builder page's search title, description, share image and "hide from search engines" reach the
|
|
39
|
+
page's `<head>` (`generateMetadata` in `app/pages/[handle]/page.tsx`), and `app/sitemap.ts` leaves hidden pages out. The
|
|
40
|
+
canonical link and the sitemap are built from `NEXT_PUBLIC_SITE_URL` (your store's own origin); without it they point at
|
|
41
|
+
`http://localhost:3000`. The Builder emits no structured data (JSON-LD): add it in your own metadata if you want it.
|
|
42
|
+
- **The announcement bar** is switched on and off by its start and end time when a page is rendered. The Builder pages are
|
|
43
|
+
generated once, at build, so on them a start or end time that passes after the build only takes effect with the next
|
|
44
|
+
release. Catalog pages (shop, search, products) are rendered per request, and the bar changes on them at its times.
|
|
45
|
+
- **Pages** are at `/pages/<slug>`. The release's home page is at `/pages/home` (`/` stays the shop; point `app/page.tsx` at
|
|
46
|
+
the home page if you want it at `/`), and `app/sitemap.ts` lists it there. A renamed page answers its old
|
|
47
|
+
`/pages/<old-slug>` with a permanent redirect (`redirects()` in `next.config.ts`).
|
|
48
|
+
- Keep the cost rules above: no `revalidate` under 3600, no `revalidatePath`, and do not call the Builder from the
|
|
49
|
+
browser (`BuilderProvider` gets no key on purpose).
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import '@usethrottle/storefront-react/styles.css';
|
|
2
|
+
import { CATALOG_SLOT_POINTS } from '@usethrottle/storefront-react/builder';
|
|
3
|
+
import { createStorefrontServerClient, loadSettings } from '@usethrottle/storefront-react/server';
|
|
4
|
+
import { loadSite } from '@usethrottle/builder-react/server';
|
|
5
|
+
import type { ReactNode } from 'react';
|
|
6
|
+
import { builder, defaultLocale } from '@/lib/builder';
|
|
7
|
+
import { createPacks } from '@/lib/packs';
|
|
8
|
+
import { store } from '@/lib/store';
|
|
9
|
+
import { Providers } from './providers';
|
|
10
|
+
|
|
11
|
+
export default async function RootLayout({ children }: { children: ReactNode }) {
|
|
12
|
+
const locale = await defaultLocale();
|
|
13
|
+
const [settings, site] = await Promise.all([
|
|
14
|
+
// The settings read sits in every page's layout, and a page lives only as long as its shortest read. The default
|
|
15
|
+
// is an hour, which would make Next render the release pages again every hour. A year (525600 minutes) keeps them
|
|
16
|
+
// as built; a catalog change still reaches them through the signed revalidate webhook, as in a live store.
|
|
17
|
+
loadSettings({ client: createStorefrontServerClient({ catalogKey: store.catalogKey, cachePolicy: { settings: '525600m' } }) }),
|
|
18
|
+
// Read from the frozen release file: no request to the Builder, at build or at run time. mediaOrigin is the one origin Builder images may be on.
|
|
19
|
+
loadSite({
|
|
20
|
+
client: builder,
|
|
21
|
+
locale,
|
|
22
|
+
slots: CATALOG_SLOT_POINTS.map((slot) => slot.name),
|
|
23
|
+
packs: createPacks(),
|
|
24
|
+
mediaOrigin: process.env.THROTTLE_MEDIA_ORIGIN ?? '',
|
|
25
|
+
}),
|
|
26
|
+
]);
|
|
27
|
+
return (
|
|
28
|
+
<html lang={locale}>
|
|
29
|
+
<body style={{ margin: 0 }}>
|
|
30
|
+
<Providers settings={settings} site={site}>
|
|
31
|
+
{children}
|
|
32
|
+
</Providers>
|
|
33
|
+
</body>
|
|
34
|
+
</html>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { CATALOG_SLOT_POINTS } from '@usethrottle/storefront-react/builder';
|
|
2
|
+
import { createBuilderPage } from '@usethrottle/builder-react/next';
|
|
3
|
+
import { builderStaticParams } from '@usethrottle/builder-react/server';
|
|
4
|
+
import { builder, defaultLocale } from '@/lib/builder';
|
|
5
|
+
import { createPacks } from '@/lib/packs';
|
|
6
|
+
import { store } from '@/lib/store';
|
|
7
|
+
|
|
8
|
+
// Build mode: every page of the release is generated when you build and none is rendered again by time, so these pages
|
|
9
|
+
// cost no ISR write after the deploy (see the settings read in app/layout.tsx). A slug that is not in the release is a 404.
|
|
10
|
+
export const generateStaticParams = () => builderStaticParams({ client: builder });
|
|
11
|
+
export const dynamicParams = false;
|
|
12
|
+
|
|
13
|
+
const route = createBuilderPage({
|
|
14
|
+
fromParams: 'handle',
|
|
15
|
+
client: builder,
|
|
16
|
+
packs: createPacks(),
|
|
17
|
+
locale: defaultLocale,
|
|
18
|
+
slots: CATALOG_SLOT_POINTS.map((slot) => slot.name),
|
|
19
|
+
// The canonical link and the share image (og:image): your store's own origin (NEXT_PUBLIC_SITE_URL) and the origin
|
|
20
|
+
// your Builder images are served from (THROTTLE_MEDIA_ORIGIN). Without the media origin a page has no og:image.
|
|
21
|
+
storeUrl: store.baseUrl,
|
|
22
|
+
mediaOrigin: process.env.THROTTLE_MEDIA_ORIGIN ?? '',
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
export default route.Page;
|
|
26
|
+
export const generateMetadata = route.generateMetadata;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { BuilderProvider } from '@usethrottle/builder-react';
|
|
3
|
+
import type { LoadedSite } from '@usethrottle/builder-react';
|
|
4
|
+
import { StoreFrame } from '@usethrottle/storefront-react';
|
|
5
|
+
import { StorefrontNextProvider, type StorefrontNextProviderProps } from '@usethrottle/storefront-react/next/client';
|
|
6
|
+
import type { ReactNode } from 'react';
|
|
7
|
+
import { createPacks } from '@/lib/packs';
|
|
8
|
+
|
|
9
|
+
const packs = createPacks();
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The storefront provider, the Builder's site design (menus, brand, announcement, theme, slots) and the page around
|
|
13
|
+
* every route. `BuilderProvider` gets no key and no client: the site was read from the release at build time, so the
|
|
14
|
+
* browser never calls the Builder.
|
|
15
|
+
* `generationWatch` is the open tab's check for a catalog change: one cheap conditional read at this interval.
|
|
16
|
+
* 60 s is the least the package allows. Raise it if you like; do not lower it.
|
|
17
|
+
*/
|
|
18
|
+
export function Providers({ settings, site, children }: { settings: StorefrontNextProviderProps['settings']; site: LoadedSite; children: ReactNode }) {
|
|
19
|
+
return (
|
|
20
|
+
<StorefrontNextProvider
|
|
21
|
+
catalogKey={process.env.NEXT_PUBLIC_THROTTLE_CATALOG_KEY}
|
|
22
|
+
settings={settings}
|
|
23
|
+
generationWatch={{ intervalMs: 60_000 }}
|
|
24
|
+
injectStyles={false}
|
|
25
|
+
>
|
|
26
|
+
<BuilderProvider packs={packs} site={site}>
|
|
27
|
+
<StoreFrame>{children}</StoreFrame>
|
|
28
|
+
</BuilderProvider>
|
|
29
|
+
</StorefrontNextProvider>
|
|
30
|
+
);
|
|
31
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { MetadataRoute } from 'next';
|
|
2
|
+
import { builderSitemap } from '@usethrottle/builder-react/server';
|
|
3
|
+
import { builder, defaultLocale } from '@/lib/builder';
|
|
4
|
+
import { store } from '@/lib/store';
|
|
5
|
+
|
|
6
|
+
// The release's pages, read from the frozen release at build, without the pages set to noindex. The Builder's home page is
|
|
7
|
+
// served at /pages/home (`/` is the shop), and the sitemap lists it there, as its canonical link says.
|
|
8
|
+
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
|
|
9
|
+
return builderSitemap({ client: builder, storeUrl: store.baseUrl, locale: await defaultLocale() });
|
|
10
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { createBuilderClient, type ReleaseBundle } from '@usethrottle/builder';
|
|
4
|
+
|
|
5
|
+
// Build mode: the Builder is read ONCE, by `next build` (next.config.ts), and written to `.builder/release.json`. This
|
|
6
|
+
// client renders from that file, so pages, layouts and the sitemap make no Builder request at build or at run time, and
|
|
7
|
+
// a running store needs no Builder key.
|
|
8
|
+
//
|
|
9
|
+
// A built or running store with no readable release file FAILS, even when THROTTLE_BUILDER_KEY is set on the host: a
|
|
10
|
+
// quiet fallback would download the whole release (up to 48 MB) on every cold start. Only `next dev` reads from the
|
|
11
|
+
// Builder, and only when the key is set: the publishable key of a SERVER channel (tb_pk_...), or a secret key holding
|
|
12
|
+
// releases:read. Never a NEXT_PUBLIC_ variable.
|
|
13
|
+
const FROZEN = join(process.cwd(), '.builder', 'release.json');
|
|
14
|
+
const HELD = Symbol.for('throttle.builder.frozen-release');
|
|
15
|
+
const SAID = Symbol.for('throttle.builder.source-said');
|
|
16
|
+
const development = process.env.NODE_ENV === 'development';
|
|
17
|
+
const builderKey = process.env.THROTTLE_BUILDER_KEY;
|
|
18
|
+
|
|
19
|
+
/** The frozen release, or undefined when there is no file. A file that cannot be read or parsed throws. Parsed once per process (it can be tens of MB). */
|
|
20
|
+
function frozen(): ReleaseBundle | undefined {
|
|
21
|
+
const holder = globalThis as unknown as Record<symbol, ReleaseBundle | undefined>;
|
|
22
|
+
if (holder[HELD] !== undefined) return holder[HELD];
|
|
23
|
+
let text: string;
|
|
24
|
+
try {
|
|
25
|
+
text = readFileSync(FROZEN, 'utf8');
|
|
26
|
+
} catch (error) {
|
|
27
|
+
if ((error as { code?: string }).code === 'ENOENT') return undefined;
|
|
28
|
+
throw new Error(`Cannot read the frozen Builder release ${FROZEN}: ${(error as Error).message}. Run \`next build\` again.`, { cause: error });
|
|
29
|
+
}
|
|
30
|
+
let parsed: unknown;
|
|
31
|
+
try {
|
|
32
|
+
parsed = JSON.parse(text);
|
|
33
|
+
} catch (error) {
|
|
34
|
+
throw new Error(`The frozen Builder release ${FROZEN} is corrupt (it is not valid JSON). Delete the .builder folder and run \`next build\` again.`, { cause: error });
|
|
35
|
+
}
|
|
36
|
+
const bundle = parsed as Partial<ReleaseBundle> | null;
|
|
37
|
+
if (typeof bundle?.releaseId !== 'string' || !Array.isArray(bundle.pages))
|
|
38
|
+
throw new Error(`The frozen Builder release ${FROZEN} is not a release bundle. Delete the .builder folder and run \`next build\` again.`);
|
|
39
|
+
holder[HELD] = bundle as ReleaseBundle;
|
|
40
|
+
return holder[HELD];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** `next dev` with a key reads a fresh release, never a stale file. Say so, once, so nobody wonders which release they are looking at. */
|
|
44
|
+
function say(message: string): void {
|
|
45
|
+
const holder = globalThis as unknown as Record<symbol, boolean | undefined>;
|
|
46
|
+
if (holder[SAID]) return;
|
|
47
|
+
holder[SAID] = true;
|
|
48
|
+
console.warn(`[throttle builder] ${message}`);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const readsTheBuilder = development && builderKey !== undefined && builderKey !== '';
|
|
52
|
+
const releaseBundle = readsTheBuilder ? undefined : frozen();
|
|
53
|
+
|
|
54
|
+
if (releaseBundle === undefined && !readsTheBuilder)
|
|
55
|
+
throw new Error(
|
|
56
|
+
development
|
|
57
|
+
? 'No frozen Builder release (.builder/release.json) and no THROTTLE_BUILDER_KEY: set the key in .env.local for `next dev`, or run `next build` once.'
|
|
58
|
+
: 'No frozen Builder release (.builder/release.json). `next build` writes it from the Builder (it needs THROTTLE_BUILDER_KEY), and a running store never reads the Builder itself. Run `next build` again.',
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
if (development) {
|
|
62
|
+
say(
|
|
63
|
+
releaseBundle === undefined
|
|
64
|
+
? 'next dev: reading the release from the Builder (THROTTLE_BUILDER_KEY is set; the .builder/release.json of the last build is ignored).'
|
|
65
|
+
: `next dev: no THROTTLE_BUILDER_KEY, so rendering the release ${releaseBundle.releaseId} frozen by the last build (.builder/release.json), which may be stale.`,
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export const builder =
|
|
70
|
+
releaseBundle !== undefined
|
|
71
|
+
? createBuilderClient({ mode: 'build', releaseBundle })
|
|
72
|
+
: createBuilderClient({ mode: 'build', builderKey: builderKey!, release: process.env.BUILDER_RELEASE_ID });
|
|
73
|
+
|
|
74
|
+
/** The release's default locale: the store is generated in it. */
|
|
75
|
+
export const defaultLocale = async (): Promise<string> => (await builder.getReleaseBundle()).defaultLocale;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { catalogPack, commercePack } from '@usethrottle/storefront-react/builder';
|
|
2
|
+
|
|
3
|
+
// The widget packs the Builder's catalog and commerce widgets are drawn with. A plain module (no "use client"):
|
|
4
|
+
// the server passes the packs to loadSite() and the browser module of app/providers.tsx passes them to the provider.
|
|
5
|
+
// The server reads with the server key; in the browser that variable is empty and the browser key is used.
|
|
6
|
+
export const createPacks = () => [
|
|
7
|
+
catalogPack({ catalogKey: process.env.THROTTLE_CATALOG_SERVER_KEY || process.env.NEXT_PUBLIC_THROTTLE_CATALOG_KEY || '' }),
|
|
8
|
+
commercePack(),
|
|
9
|
+
];
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, statSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import type { NextConfig } from 'next';
|
|
4
|
+
import { PHASE_PRODUCTION_BUILD } from 'next/constants';
|
|
5
|
+
import { createBuilderClient } from '@usethrottle/builder';
|
|
6
|
+
|
|
7
|
+
// Nothing here sets a cache time. Build mode generates every page of one Builder release at build time. See README.md.
|
|
8
|
+
//
|
|
9
|
+
// The release is read ONCE, here, and written to `.builder/release.json`. Next copies that file into the build output
|
|
10
|
+
// (`outputFileTracingIncludes`), `lib/builder.ts` renders every page, layout and sitemap from it, and the running store
|
|
11
|
+
// never calls the Builder (and needs no Builder key). The build workers read the same file instead of downloading the
|
|
12
|
+
// bundle again.
|
|
13
|
+
const FROZEN = join(process.cwd(), '.builder', 'release.json');
|
|
14
|
+
const FROZEN_ID = join(process.cwd(), '.builder', 'release.id');
|
|
15
|
+
/** The file ships in every server function that renders a page, so a big release can outgrow a host's function size limit. */
|
|
16
|
+
const WARN_BYTES = 20 * 1024 * 1024;
|
|
17
|
+
|
|
18
|
+
/** Pin the release of this build: BUILDER_RELEASE_ID if set, else the newest. Runs in the build's main process; its workers find the file and skip. */
|
|
19
|
+
async function freeze(): Promise<void> {
|
|
20
|
+
const wanted = process.env.BUILDER_RELEASE_ID;
|
|
21
|
+
if (wanted && existsSync(FROZEN) && existsSync(FROZEN_ID) && readFileSync(FROZEN_ID, 'utf8') === wanted) return;
|
|
22
|
+
const builderKey = process.env.THROTTLE_BUILDER_KEY;
|
|
23
|
+
if (!builderKey) throw new Error('Set THROTTLE_BUILDER_KEY (your Throttle Builder build key) for `next build`: the build reads the release from the Builder once.');
|
|
24
|
+
const bundle = await createBuilderClient({ mode: 'build', builderKey }).getReleaseBundle(wanted ? { release: wanted } : undefined);
|
|
25
|
+
mkdirSync(join(process.cwd(), '.builder'), { recursive: true });
|
|
26
|
+
writeFileSync(`${FROZEN}.tmp`, JSON.stringify(bundle));
|
|
27
|
+
renameSync(`${FROZEN}.tmp`, FROZEN);
|
|
28
|
+
writeFileSync(FROZEN_ID, bundle.releaseId);
|
|
29
|
+
const bytes = statSync(FROZEN).size;
|
|
30
|
+
if (bytes > WARN_BYTES)
|
|
31
|
+
console.warn(
|
|
32
|
+
`[throttle builder] The frozen release is ${(bytes / 1024 / 1024).toFixed(1)} MB. It is copied into every server function that renders a page, so check your host's function size limit (and the build machine's memory). Fewer or lighter pages in the release keep it small.`,
|
|
33
|
+
);
|
|
34
|
+
// Before Next starts its build workers, so every page of this build comes from the same release even if someone
|
|
35
|
+
// presses Release while it runs.
|
|
36
|
+
process.env.BUILDER_RELEASE_ID = bundle.releaseId;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** A renamed page answers its old address with a permanent redirect. `dynamicParams = false` would 404 it first. */
|
|
40
|
+
function renamedPages(): { source: string; destination: string; permanent: true }[] {
|
|
41
|
+
if (!existsSync(FROZEN)) return [];
|
|
42
|
+
const { redirects } = JSON.parse(readFileSync(FROZEN, 'utf8')) as { redirects?: Record<string, string> };
|
|
43
|
+
return Object.entries(redirects ?? {})
|
|
44
|
+
// A path on this site only, as in createBuilderPage.
|
|
45
|
+
.filter(([, to]) => to.startsWith('/') && !to.startsWith('//'))
|
|
46
|
+
.map(([from, to]) => ({ source: `/pages/${from.replace(/[\\:()*+?{}[\]]/gu, '\\$&')}`, destination: to, permanent: true as const }));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export default async function config(phase: string): Promise<NextConfig> {
|
|
50
|
+
if (phase === PHASE_PRODUCTION_BUILD) await freeze();
|
|
51
|
+
return {
|
|
52
|
+
poweredByHeader: false,
|
|
53
|
+
// Next inlines this into the build, so a page it renders again later (see README.md) reads the release this build
|
|
54
|
+
// was made from, never a newer one.
|
|
55
|
+
env: { BUILDER_RELEASE_ID: process.env.BUILDER_RELEASE_ID ?? '' },
|
|
56
|
+
// Every route that renders a page needs the release (the root layout reads it); the signed webhook routes under
|
|
57
|
+
// /api do not, so they stay small. A new route outside /api that renders the layout is covered.
|
|
58
|
+
outputFileTracingIncludes: { '/!(api)/**': ['./.builder/release.json'] },
|
|
59
|
+
redirects: () => Promise.resolve(renamedPages()),
|
|
60
|
+
};
|
|
61
|
+
}
|