@usethrottle/create-store 0.0.0-stage → 0.1.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 ADDED
@@ -0,0 +1,40 @@
1
+ # @usethrottle/create-store
2
+
3
+ `npx @usethrottle/create-store [dir] --catalog-key pc_pk_...` scaffolds a Next.js store on
4
+ `@usethrottle/storefront-react`. Build: `pnpm --filter @usethrottle/create-store build`; test:
5
+ `pnpm --filter @usethrottle/create-store test` (the CLI test runs `dist/`, so build first; turbo does).
6
+
7
+ ## Layout
8
+
9
+ - `src/`: the CLI. `args.ts` (flags), `pm.ts` (package manager), `catalog-key.ts` (key format and the
10
+ `GET /v1/storefront/config` check), `prompt.ts` (the one question), `scaffold.ts` (copy the template),
11
+ `versions.ts` (`TEMPLATE_VERSIONS`), `index.ts` (the binary).
12
+ - `template/`: what a new store contains. `*.tmpl` files lose the suffix (npm drops `.gitignore` and
13
+ rewrites `package.json`) and have `{{name}}` and `{{catalogKey}}` filled in. `package.json.tmpl` gets
14
+ `dependencies` from `TEMPLATE_VERSIONS`.
15
+ - `e2e/smoke.spec.ts`: a Playwright run against a store this CLI scaffolded, built and started by hand on
16
+ port 3048. Recipe: `pnpm pack` ui, auth, storefront-react and create-store; scaffold with
17
+ `--skip-install` and both keys (`--catalog-key` browser, `--server-key` server); add `pnpm.overrides`
18
+ pointing at the tarballs; `pnpm install --ignore-workspace`; build; `next start -p 3048` with
19
+ `THROTTLE_WEBHOOK_SECRET` set. Stop the server by
20
+ port, delete the scratch store by its literal path.
21
+
22
+ ## Invariants an agent must not break
23
+
24
+ - **ISR cost rules.** Every new store copies the template, and the owner was billed about $1k for ISR
25
+ writes. The template must keep: the cache policy of `createStorefrontServerClient`
26
+ (`STOREFRONT_CACHE_POLICY`), `createRevalidateHandler` and `createGenerationSyncHandler` (one coarse
27
+ tag, coalesced, signature-checked), `staticParams: 0`, a dynamic uncached search, a `generationWatch`
28
+ of 60 s or more, and no `revalidate` under 3600, no `revalidatePath`, no `next: { revalidate }`.
29
+ `src/isr-cost.test.ts` greps a fresh scaffold for these; do not weaken it. The template README has the
30
+ short explanation for merchants.
31
+ - **Keys.** A catalog has a browser key (`NEXT_PUBLIC_THROTTLE_CATALOG_KEY`) and a server key
32
+ (`THROTTLE_CATALOG_SERVER_KEY`); `src/keys.ts` detects which is which with `classifyCatalogKey` and never
33
+ writes a server key to a `NEXT_PUBLIC_` variable. Never a secret (`pc_sk_`) key.
34
+ - **Published** since 0.1.0: `private` is gone and the package is in the root `release` filter.
35
+ - **`TEMPLATE_VERSIONS`** takes the workspace versions of storefront-react, ui and auth at build (the
36
+ `package.json` files are imported and bundled). Do not hard-code them.
37
+ - `template-typecheck.test.ts` compiles the template against the workspace packages; the template's
38
+ imports must resolve from this package's devDependencies.
39
+ - **Docs.** `apps/web/src/pages/docs/product-catalog/storefront-components/create-store` documents the prompts and the options; a
40
+ change to a flag, a prompt or a template file updates it in the same PR.
package/README.md CHANGED
@@ -1,3 +1,30 @@
1
- # Temporary Holding Version
1
+ # @usethrottle/create-store
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Scaffold a complete Next.js storefront on [`@usethrottle/storefront-react`](https://www.npmjs.com/package/@usethrottle/storefront-react).
4
+
5
+ ```bash
6
+ npx @usethrottle/create-store my-store
7
+ # or: pnpm create @usethrottle/store my-store
8
+ ```
9
+
10
+ It asks for one thing, your catalog's publishable key (`pc_pk_...`), writes it to `.env.local`, and installs
11
+ dependencies. Pass it as a flag to skip the question:
12
+
13
+ ```bash
14
+ npx @usethrottle/create-store my-store --catalog-key pc_pk_... --yes
15
+ ```
16
+
17
+ | Option | |
18
+ |---|---|
19
+ | `[dir]` | Where to create the store (default `my-store`). Must be empty or missing. |
20
+ | `--catalog-key <key>` | The catalog's publishable key. |
21
+ | `--yes`, `-y` | Ask nothing (needs `--catalog-key`). |
22
+ | `--pm <pnpm\|npm\|yarn\|bun>` | Package manager (default: the one running the command). |
23
+ | `--skip-install` | Write the files and stop. |
24
+ | `--server-key <key>` | The catalog's server key, for your store's server. The CLI tells browser and server keys apart and asks for the other one. |
25
+ | `--offline` | Do not call the catalog to tell the keys apart; then pass both `--catalog-key` and `--server-key`. |
26
+
27
+ The store has the shop, collections, categories, tags, product, search and account pages, the cart drawer,
28
+ and the cache-safe webhook and sync routes. Its `README.md` explains how it keeps Vercel ISR costs down.
29
+
30
+ Documentation: <https://usethrottle.dev/docs/product-catalog/storefront-components/create-store/>.
package/dist/index.js ADDED
@@ -0,0 +1,408 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/index.ts
4
+ import { spawn } from "child_process";
5
+ import { relative as relative2, resolve as resolve2 } from "path";
6
+
7
+ // src/pm.ts
8
+ var MANAGERS = ["pnpm", "npm", "yarn", "bun"];
9
+ function detectPackageManager(userAgent) {
10
+ const name = userAgent?.trim().split(/[\s/]/u)[0];
11
+ return MANAGERS.find((pm) => pm === name) ?? "npm";
12
+ }
13
+ function isPackageManager(value) {
14
+ return MANAGERS.includes(value);
15
+ }
16
+ function installCommand(pm) {
17
+ return { command: pm, args: ["install"] };
18
+ }
19
+ function runScript(pm, script) {
20
+ return pm === "npm" ? `npm run ${script}` : `${pm} ${script}`;
21
+ }
22
+
23
+ // src/args.ts
24
+ var DEFAULT_DIR = "my-store";
25
+ var USAGE = `Usage: create-store [dir] [options]
26
+
27
+ dir Where to create the store (default: ${DEFAULT_DIR})
28
+ --catalog-key <key> The catalog's browser key (pc_pk_...); asked for when missing. A server key is detected
29
+ --server-key <key> The catalog's server key, for reads made by your store's server (asked for after the browser key)
30
+ --yes, -y Take every default and ask nothing
31
+ --pm <manager> pnpm, npm, yarn or bun (default: the one running this command)
32
+ --skip-install Write the files and stop before installing dependencies
33
+ --offline Do not call the catalog to tell the keys apart (then --catalog-key and --server-key are both needed)
34
+ --help, -h Show this text`;
35
+ function parseArgs(argv) {
36
+ const args = { dir: DEFAULT_DIR, yes: false, skipInstall: false, offline: false, help: false };
37
+ const positional = [];
38
+ const valueOf = (flag, inline, index) => {
39
+ if (inline !== void 0) return { value: inline, next: index };
40
+ const next = argv[index + 1];
41
+ if (next === void 0 || next.startsWith("-")) throw new Error(`${flag} needs a value.`);
42
+ return { value: next, next: index + 1 };
43
+ };
44
+ for (let i = 0; i < argv.length; i++) {
45
+ const raw = argv[i] ?? "";
46
+ if (raw === "--") {
47
+ positional.push(...argv.slice(i + 1));
48
+ break;
49
+ }
50
+ if (!raw.startsWith("-")) {
51
+ positional.push(raw);
52
+ continue;
53
+ }
54
+ const eq = raw.startsWith("--") ? raw.indexOf("=") : -1;
55
+ const flag = eq === -1 ? raw : raw.slice(0, eq);
56
+ const inline = eq === -1 ? void 0 : raw.slice(eq + 1);
57
+ switch (flag) {
58
+ case "--catalog-key": {
59
+ const { value, next } = valueOf(flag, inline, i);
60
+ args.catalogKey = value;
61
+ i = next;
62
+ break;
63
+ }
64
+ case "--server-key": {
65
+ const { value, next } = valueOf(flag, inline, i);
66
+ args.serverKey = value;
67
+ i = next;
68
+ break;
69
+ }
70
+ case "--pm": {
71
+ const { value, next } = valueOf(flag, inline, i);
72
+ if (!isPackageManager(value)) throw new Error(`--pm must be pnpm, npm, yarn or bun, not "${value}".`);
73
+ args.pm = value;
74
+ i = next;
75
+ break;
76
+ }
77
+ case "--yes":
78
+ case "-y":
79
+ args.yes = true;
80
+ break;
81
+ case "--skip-install":
82
+ args.skipInstall = true;
83
+ break;
84
+ case "--offline":
85
+ args.offline = true;
86
+ break;
87
+ case "--help":
88
+ case "-h":
89
+ args.help = true;
90
+ break;
91
+ default:
92
+ throw new Error(`Unknown option ${flag}.`);
93
+ }
94
+ }
95
+ if (positional.length > 1) throw new Error(`Give one directory, not ${positional.length} (${positional.join(", ")}).`);
96
+ if (positional[0]) args.dir = positional[0];
97
+ return args;
98
+ }
99
+
100
+ // src/catalog-key.ts
101
+ var DEFAULT_CATALOG_URL = "https://catalog.usethrottle.dev";
102
+ function validateCatalogKey(key) {
103
+ return /^pc_pk_[\x21-\x7e]{1,94}$/u.test(key);
104
+ }
105
+ function catalogKeyProblem(key) {
106
+ if (validateCatalogKey(key)) return void 0;
107
+ if (key.startsWith("pc_sk_")) return "That is a secret key (pc_sk_). A storefront takes the publishable key (pc_pk_).";
108
+ return "A catalog publishable key starts with pc_pk_ and has no spaces.";
109
+ }
110
+ var PROBE_ORIGIN = "https://create-store.invalid";
111
+ async function classifyCatalogKey(key, options = {}) {
112
+ const base = (options.baseUrl ?? DEFAULT_CATALOG_URL).replace(/\/+$/u, "");
113
+ const doFetch = options.fetch ?? fetch;
114
+ const ask = async (origin) => {
115
+ try {
116
+ const response = await doFetch(`${base}/v1/storefront/config`, {
117
+ headers: { "x-catalog-key": key, ...origin ? { origin } : {} },
118
+ signal: AbortSignal.timeout(options.timeoutMs ?? 8e3)
119
+ });
120
+ const text = response.ok ? "" : await response.text().catch(() => "");
121
+ const code = /"code"\s*:\s*"([A-Z_]+)"/u.exec(text)?.[1] ?? "";
122
+ return { status: response.status, code };
123
+ } catch {
124
+ return void 0;
125
+ }
126
+ };
127
+ const [server, browser] = [await ask(void 0), await ask(PROBE_ORIGIN)];
128
+ if (server?.status === 401 || browser?.status === 401) {
129
+ return { kind: "rejected", detail: "The catalog does not know this key (401)." };
130
+ }
131
+ if (server?.status === 200 || browser?.code === "SERVER_KEY_IN_BROWSER") {
132
+ return { kind: "server", detail: "This is a server key." };
133
+ }
134
+ if (server?.code === "ORIGIN_NOT_ALLOWED" || browser?.status === 200 || browser?.code === "ORIGIN_NOT_ALLOWED") {
135
+ return { kind: "browser", detail: "This is a browser key." };
136
+ }
137
+ return { kind: "unknown", detail: server || browser ? `The catalog answered ${(server ?? browser).status}.` : "The catalog did not answer." };
138
+ }
139
+
140
+ // src/keys.ts
141
+ var NEEDS_BOTH = "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>.";
142
+ var SERVER_NEEDS_BROWSER = "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.";
143
+ var ON_YOUR_WORD = "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.";
144
+ function assertBrowserKeyPlacement(p) {
145
+ if (p.browserKind === "browser") return;
146
+ if (p.browserKind !== "server" && p.named && p.hasServerKey) return;
147
+ throw new Error(NEEDS_BOTH);
148
+ }
149
+ async function resolveKeys(o, deps) {
150
+ const notes = [];
151
+ const classify = async (key) => {
152
+ const problem = catalogKeyProblem(key);
153
+ if (problem) throw new Error(problem);
154
+ if (o.offline) return "unchecked";
155
+ const result = await deps.classify(key);
156
+ if (result.kind === "rejected") throw new Error(`${result.detail} Check the key, or pass --offline to skip this check.`);
157
+ if (result.kind === "unknown") notes.push(`Could not tell what kind of key this is (${result.detail}).`);
158
+ return result.kind;
159
+ };
160
+ const askFor = async (role) => (await deps.ask(role))?.trim() || void 0;
161
+ let browser = o.catalogKey?.trim() || void 0;
162
+ let server = o.serverKey?.trim() || void 0;
163
+ let named = false;
164
+ let browserKind;
165
+ let serverChecked = false;
166
+ if (!browser && !server) {
167
+ if (o.yes) throw new Error("--yes needs --catalog-key <pc_pk_...>.");
168
+ browser = await askFor("browser");
169
+ if (!browser) throw new Error("Cancelled.");
170
+ named = true;
171
+ }
172
+ if (browser) {
173
+ browserKind = await classify(browser);
174
+ if (browserKind === "server") {
175
+ if (server) {
176
+ const other = await classify(server);
177
+ if (other === "server") throw new Error("--catalog-key and --server-key are both server keys. One of them has to be the browser key.");
178
+ if (other !== "browser") {
179
+ throw new Error(
180
+ `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.`
181
+ );
182
+ }
183
+ [browser, server] = [server, browser];
184
+ browserKind = "browser";
185
+ } else {
186
+ server = browser;
187
+ browser = void 0;
188
+ browserKind = void 0;
189
+ }
190
+ serverChecked = true;
191
+ } else if (server) {
192
+ named = true;
193
+ }
194
+ }
195
+ if (server && !serverChecked) {
196
+ 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.");
197
+ }
198
+ if (!browser) {
199
+ if (o.yes) throw new Error(SERVER_NEEDS_BROWSER);
200
+ browser = await askFor("browser");
201
+ if (!browser) throw new Error("A browser key is needed. Cancelled.");
202
+ named = true;
203
+ browserKind = await classify(browser);
204
+ 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.");
205
+ }
206
+ if (!server) {
207
+ if (browserKind !== "browser") {
208
+ if (o.yes) throw new Error(NEEDS_BOTH);
209
+ if (!named) {
210
+ notes.push("Could not tell what kind of key --catalog-key is, so both keys are asked for.");
211
+ browser = await askFor("browser");
212
+ if (!browser) throw new Error("A browser key is needed. Cancelled.");
213
+ named = true;
214
+ browserKind = await classify(browser);
215
+ 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.");
216
+ }
217
+ server = await askFor("server");
218
+ if (!server) throw new Error("A server key is needed when the keys cannot be told apart. Cancelled.");
219
+ if (await classify(server) === "browser") throw new Error("That is a browser key, not a server key.");
220
+ } else if (!o.yes) {
221
+ const given = await askFor("server");
222
+ if (given) {
223
+ if (await classify(given) === "browser") throw new Error("That is a browser key, not a server key.");
224
+ server = given;
225
+ }
226
+ }
227
+ }
228
+ assertBrowserKeyPlacement({ browserKind, named, hasServerKey: server !== void 0 });
229
+ if (browserKind !== "browser") notes.push(ON_YOUR_WORD);
230
+ if (!server) {
231
+ notes.push(
232
+ "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)."
233
+ );
234
+ }
235
+ return { browserKey: browser, ...server ? { serverKey: server } : {}, notes };
236
+ }
237
+
238
+ // src/prompt.ts
239
+ import prompts from "prompts";
240
+ var MESSAGES = {
241
+ browser: "Catalog publishable key (pc_pk_...)",
242
+ server: "Catalog server key, for your store's server (pc_pk_..., press enter to skip)"
243
+ };
244
+ async function askCatalogKey(role) {
245
+ const answer = await prompts(
246
+ {
247
+ type: "text",
248
+ name: "catalogKey",
249
+ message: MESSAGES[role],
250
+ validate: (value) => role === "server" && value.trim() === "" ? true : catalogKeyProblem(value.trim()) ?? true
251
+ },
252
+ { onCancel: () => false }
253
+ );
254
+ const key = answer.catalogKey;
255
+ return typeof key === "string" ? key.trim() : void 0;
256
+ }
257
+
258
+ // src/scaffold.ts
259
+ import { mkdir, readdir, readFile, stat, writeFile } from "fs/promises";
260
+ import { basename, dirname, join, relative, resolve } from "path";
261
+ import { fileURLToPath } from "url";
262
+ var TEMPLATE_DIR = resolve(dirname(fileURLToPath(import.meta.url)), "../template");
263
+ async function filesUnder(root, dir = root) {
264
+ const found = [];
265
+ for (const entry of await readdir(dir, { withFileTypes: true })) {
266
+ const path = join(dir, entry.name);
267
+ if (entry.isDirectory()) found.push(...await filesUnder(root, path));
268
+ else found.push(relative(root, path));
269
+ }
270
+ return found.sort();
271
+ }
272
+ function packageNameOf(dir) {
273
+ const cleaned = basename(resolve(dir)).toLowerCase().replace(/[^a-z0-9._-]+/gu, "-").replace(/^[._-]+|[-]+$/gu, "");
274
+ return cleaned || "throttle-store";
275
+ }
276
+ function render(text, values) {
277
+ return text.replace(/\{\{(\w+)\}\}/gu, (_all, name) => {
278
+ const value = values[name];
279
+ if (value === void 0) throw new Error(`The template uses {{${name}}}, which scaffold does not set.`);
280
+ return value;
281
+ });
282
+ }
283
+ async function scaffold(o) {
284
+ const problem = catalogKeyProblem(o.catalogKey);
285
+ if (problem) throw new Error(problem);
286
+ const serverProblem = o.serverKey === void 0 ? void 0 : catalogKeyProblem(o.serverKey);
287
+ if (serverProblem) throw new Error(serverProblem);
288
+ const target = resolve(o.dir);
289
+ const existing = await stat(target).then(
290
+ () => readdir(target),
291
+ () => null
292
+ );
293
+ if (existing && existing.length > 0) {
294
+ throw new Error(`${target} is not empty. Pick a new directory, or empty this one first.`);
295
+ }
296
+ const values = {
297
+ name: packageNameOf(target),
298
+ catalogKey: o.catalogKey,
299
+ serverKeyLine: o.serverKey ? `THROTTLE_CATALOG_SERVER_KEY=${o.serverKey}` : "# THROTTLE_CATALOG_SERVER_KEY= (the catalog's server key; see README.md)"
300
+ };
301
+ const written = [];
302
+ for (const file of await filesUnder(TEMPLATE_DIR)) {
303
+ const isTemplate = file.endsWith(".tmpl");
304
+ const out = join(target, isTemplate ? file.slice(0, -".tmpl".length) : file);
305
+ let text = await readFile(join(TEMPLATE_DIR, file), "utf8");
306
+ if (isTemplate) text = render(text, values);
307
+ if (basename(out) === "package.json") {
308
+ const manifest = JSON.parse(text);
309
+ const dependencies = { ...manifest.dependencies, ...o.versions };
310
+ manifest.dependencies = Object.fromEntries(Object.entries(dependencies).sort(([a], [b]) => a.localeCompare(b)));
311
+ text = `${JSON.stringify(manifest, null, 2)}
312
+ `;
313
+ }
314
+ await mkdir(dirname(out), { recursive: true });
315
+ await writeFile(out, text, "utf8");
316
+ written.push(out);
317
+ }
318
+ return written;
319
+ }
320
+
321
+ // ../auth-sdk/package.json
322
+ var version = "0.15.0";
323
+
324
+ // ../storefront-react/package.json
325
+ var version2 = "0.1.0";
326
+
327
+ // ../ui/package.json
328
+ var version3 = "0.1.2";
329
+
330
+ // src/versions.ts
331
+ var TEMPLATE_VERSIONS = {
332
+ "@usethrottle/storefront-react": `^${version2}`,
333
+ "@usethrottle/ui": `^${version3}`,
334
+ "@usethrottle/auth": `^${version}`,
335
+ "@usethrottle/catalog": "^1.4.1",
336
+ "@usethrottle/money": "^1.1.0"
337
+ };
338
+
339
+ // src/index.ts
340
+ var fail = (message) => {
341
+ console.error(`create-store: ${message}`);
342
+ process.exit(1);
343
+ };
344
+ function install(pm, cwd) {
345
+ const { command, args } = installCommand(pm);
346
+ return new Promise((done) => {
347
+ const child = spawn(command, args, { cwd, stdio: "inherit", shell: process.platform === "win32" });
348
+ child.on("error", () => done(false));
349
+ child.on("exit", (code) => done(code === 0));
350
+ });
351
+ }
352
+ async function main() {
353
+ let args;
354
+ try {
355
+ args = parseArgs(process.argv.slice(2));
356
+ } catch (error) {
357
+ console.error(`create-store: ${error instanceof Error ? error.message : "bad arguments"}
358
+
359
+ ${USAGE}`);
360
+ process.exit(1);
361
+ }
362
+ if (args.help) {
363
+ console.log(USAGE);
364
+ return;
365
+ }
366
+ let keys;
367
+ try {
368
+ keys = await resolveKeys(args, {
369
+ classify: (key) => classifyCatalogKey(key),
370
+ ask: askCatalogKey
371
+ });
372
+ } catch (error) {
373
+ return fail(error instanceof Error ? error.message : "Could not settle the catalog keys.");
374
+ }
375
+ for (const note of keys.notes) console.warn(`create-store: ${note}`);
376
+ let written;
377
+ try {
378
+ written = await scaffold({
379
+ dir: args.dir,
380
+ catalogKey: keys.browserKey,
381
+ ...keys.serverKey ? { serverKey: keys.serverKey } : {},
382
+ versions: TEMPLATE_VERSIONS
383
+ });
384
+ } catch (error) {
385
+ return fail(error instanceof Error ? error.message : "Could not write the store.");
386
+ }
387
+ const target = resolve2(args.dir);
388
+ console.log(`Created ${written.length} files in ${target}`);
389
+ const pm = args.pm ?? detectPackageManager(process.env.npm_config_user_agent);
390
+ if (!args.skipInstall) {
391
+ console.log(`Installing with ${pm}...`);
392
+ if (!await install(pm, target)) console.warn(`create-store: ${pm} install did not finish. Run it yourself in the folder.`);
393
+ }
394
+ const rel = relative2(process.cwd(), target) || ".";
395
+ const cd = rel.startsWith("..") ? target : rel;
396
+ console.log(`
397
+ Next:
398
+ cd ${cd}
399
+ ${args.skipInstall ? ` ${pm} install
400
+ ` : ""} ${runScript(pm, "dev")}
401
+
402
+ Read README.md for how the store stays cheap on Vercel before you deploy.`);
403
+ }
404
+ main().catch((error) => {
405
+ console.error(`create-store: ${error instanceof Error ? error.message : String(error)}`);
406
+ process.exit(1);
407
+ });
408
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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;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;;;ACTO,IAAM,cAAc;AAEpB,IAAM,QAAQ;AAAA;AAAA,6DAEwC,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUjE,SAAS,UAAU,MAAsB;AA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,CAAC;","names":["relative","resolve","version","version","version","resolve","relative"]}
package/package.json CHANGED
@@ -1,6 +1,48 @@
1
1
  {
2
2
  "name": "@usethrottle/create-store",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "Scaffold a complete Next.js storefront on @usethrottle/storefront-react.",
5
+ "type": "module",
6
+ "bin": {
7
+ "create-store": "dist/index.js"
8
+ },
9
+ "files": [
10
+ "dist",
11
+ "template",
12
+ "README.md",
13
+ "CLAUDE.md"
14
+ ],
15
+ "dependencies": {
16
+ "prompts": "^2.4.2"
17
+ },
18
+ "devDependencies": {
19
+ "@playwright/test": "1.62.1",
20
+ "@types/node": "^20.0.0",
21
+ "@types/prompts": "^2.4.0",
22
+ "@types/react": "^19.1.0",
23
+ "@types/react-dom": "^19.1.0",
24
+ "@usethrottle/catalog": "1.4.1",
25
+ "next": "16.3.5",
26
+ "react": "19.2.8",
27
+ "react-dom": "19.2.8",
28
+ "tsup": "^8.0.0",
29
+ "typescript": "^5.7.0",
30
+ "vitest": "^2.1.9",
31
+ "@usethrottle/auth": "0.15.0",
32
+ "@usethrottle/money": "1.1.0",
33
+ "@usethrottle/storefront-react": "0.1.0",
34
+ "@usethrottle/ui": "0.1.2"
35
+ },
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
39
+ "engines": {
40
+ "node": ">=20"
41
+ },
42
+ "scripts": {
43
+ "build": "tsup",
44
+ "dev": "tsup --watch",
45
+ "test": "vitest run",
46
+ "typecheck": "tsc --noEmit"
47
+ }
6
48
  }
@@ -0,0 +1,11 @@
1
+ # The catalog's browser key. It is sent to the browser (NEXT_PUBLIC_), so it must be a browser key, never a server key.
2
+ NEXT_PUBLIC_THROTTLE_CATALOG_KEY={{catalogKey}}
3
+
4
+ # The catalog's server key: your store's server reads with it (a browser key is only answered from an allowed website).
5
+ # Never put it in a NEXT_PUBLIC_ variable.
6
+ {{serverKeyLine}}
7
+
8
+ # Set these on your host, not here:
9
+ # NEXT_PUBLIC_SITE_URL the store's own origin (https://shop.example); canonical URLs are built from it
10
+ # THROTTLE_WEBHOOK_SECRET the signing secret of the catalog's storefront.changed webhook
11
+ # THROTTLE_PREVIEW set to 1 on a preview deployment only (see README.md)
@@ -0,0 +1,7 @@
1
+ node_modules
2
+ .next
3
+ out
4
+ .env*.local
5
+ .vercel
6
+ next-env.d.ts
7
+ *.tsbuildinfo
@@ -0,0 +1,25 @@
1
+ # Agent notes for this store
2
+
3
+ A Next.js App Router store on `@usethrottle/storefront-react`. The components read their display from the
4
+ catalog's storefront settings; change settings in the dashboard before you change code.
5
+
6
+ ## Cost rules (do not break these)
7
+
8
+ This store was set up so Vercel ISR writes stay low. A change that breaks one can cost real money.
9
+
10
+ - No `export const revalidate = N` below 3600, no `fetch(..., { next: { revalidate } })` below 3600, no
11
+ `revalidatePath`, no per-product tags. Cache invalidation is the one coarse tag `throttle-catalog`, through
12
+ `app/api/throttle/revalidate` (signed webhook) and `app/api/throttle/sync`.
13
+ - Keep `staticParams: 0` in `app/p/[handle]/page.tsx`, and keep `app/search/page.tsx` dynamic.
14
+ - Keep `generationWatch.intervalMs` at 60000 or more in `app/providers.tsx`.
15
+ - Use `createStorefrontServerClient` for server reads (it carries `STOREFRONT_CACHE_POLICY`); do not build a
16
+ catalog client with a short cache time.
17
+ - Do not pass `previewToken` to a route on production: it makes the route render per request.
18
+
19
+ ## Where things are
20
+
21
+ - `lib/store.ts`: the catalog key, the site origin and the preview switch every route reads.
22
+ - `app/*/page.tsx`: one route helper each (`createShopAllPage`, `createProductPage`, `createSearchPage`,
23
+ `createAccountPage`). Change a route's options there.
24
+ - `app/providers.tsx`: the provider and the page frame (header, footer, cart drawer).
25
+ - Never put a secret key (`pc_sk_`) in this project. Only the publishable key (`pc_pk_`) belongs here.
@@ -0,0 +1,79 @@
1
+ # Your Throttle store
2
+
3
+ A Next.js storefront on [`@usethrottle/storefront-react`](https://www.npmjs.com/package/@usethrottle/storefront-react).
4
+ Products, collections, search, the cart drawer and the account page are the package's components; what they
5
+ show (menus, filters, sorts, badges, theme, text) comes from your catalog's storefront settings, so most changes
6
+ are made in the Throttle dashboard, not in this code.
7
+
8
+ ## Run it
9
+
10
+ ```bash
11
+ pnpm dev # or npm run dev
12
+ ```
13
+
14
+ A catalog has two kinds of key. `.env.local` holds both:
15
+
16
+ - **Browser key**, `NEXT_PUBLIC_THROTTLE_CATALOG_KEY`. It is sent to the browser, and the catalog only answers it from
17
+ the websites you allowed: add your site's https origin to the key's allowed websites in the dashboard.
18
+ - **Server key**, `THROTTLE_CATALOG_SERVER_KEY`. Your store's server reads with it. A request from your own server
19
+ carries no website origin, so a browser key is refused there. The catalog refuses a server key in the browser too,
20
+ so never put it in a `NEXT_PUBLIC_` variable. It also works for local development.
21
+
22
+ If `THROTTLE_CATALOG_SERVER_KEY` is missing the server tries the browser key, and the catalog answers 403.
23
+
24
+ | Variable | Where | What |
25
+ |---|---|---|
26
+ | `NEXT_PUBLIC_THROTTLE_CATALOG_KEY` | `.env.local` | The catalog's browser key (`pc_pk_...`). |
27
+ | `THROTTLE_CATALOG_SERVER_KEY` | `.env.local` or your host | The catalog's server key, used for reads made by your server. Never `NEXT_PUBLIC_`. |
28
+ | `NEXT_PUBLIC_SITE_URL` | your host | The store's own origin, for canonical URLs and the share image. |
29
+ | `THROTTLE_WEBHOOK_SECRET` | your host | Signing secret of the catalog's `storefront.changed` webhook. |
30
+ | `THROTTLE_PREVIEW` | a preview deployment only | `1` turns on draft preview. Never on production. |
31
+
32
+ ## Keep hosting costs down (ISR)
33
+
34
+ A store that regenerates its pages too often is billed for it: on Vercel every regenerated page is an ISR write
35
+ (its HTML and its data), and a deploy writes every page again. This store is set up so its pages are
36
+ rendered per request from catalog data that is kept until your catalog changes, so it writes almost no ISR (only the
37
+ two static pages, `/account` and the not-found page, once per deploy). Keep it that way:
38
+
39
+ - **No short cache times.** Never set `revalidate` below 3600 seconds, on a route or in a `fetch`, and never call
40
+ `revalidatePath`. The catalog client is already on `STOREFRONT_CACHE_POLICY` (every read kept until the catalog
41
+ changes, search never cached). If you override a read's cache time, keep it at an hour or more.
42
+ - **One coarse tag.** A change clears the single tag `throttle-catalog`, not a tag per product, and at most once a
43
+ minute however many edits arrive. The signed webhook (`app/api/throttle/revalidate`) and the open tab's check
44
+ (`app/api/throttle/sync`) both go through that one limit. The webhook checks its signature first.
45
+ - **Set the webhook up.** Add `THROTTLE_WEBHOOK_SECRET` and point the catalog's `storefront.changed` webhook at
46
+ `https://your-store/api/throttle/revalidate`. Without it the store still updates, but only through open tabs
47
+ and the one-hour safety limit.
48
+ - **No prerendered products.** `app/p/[handle]/page.tsx` sets `staticParams: 0`. Product pages are rendered per
49
+ request from cached data: the page writes no ISR, and the catalog data behind it is kept until the catalog
50
+ changes. Prerendering 1,000 products would write 1,000 pages on every deploy.
51
+ - **Search stays dynamic.** `app/search/page.tsx` is `force-dynamic` and reads without a cache. Every query is a new
52
+ URL; caching them would write a page per query.
53
+ - **The open-tab check is 60 s or more.** `generationWatch` in `app/providers.tsx` is one cheap conditional read per
54
+ tab. 60 s is the package's floor; do not lower it, and raise it if your traffic is high.
55
+ - **Preview is for preview deployments.** `THROTTLE_PREVIEW=1` makes every route render per request. Leave it unset in
56
+ production.
57
+ - **Watch deploys.** Each production deploy starts with an empty page cache, so every visited page is written
58
+ again. Merge changes in batches rather than deploying a line at a time.
59
+
60
+ ## Pages
61
+
62
+ | Route | Page |
63
+ |---|---|
64
+ | `/` and `/shop` | All products |
65
+ | `/collections/[handle]`, `/c/[handle]`, `/tags/[tag]` | A collection, category or tag |
66
+ | `/p/[handle]` | A product |
67
+ | `/search` | Search results (`?q=`) |
68
+ | `/account` | Sign in, sign up and the account (needs the account key in your catalog's brand settings; until then the page says it is not set up) |
69
+
70
+ Content pages (a Builder-managed home, landing pages) come with a later release. Replace `app/page.tsx` with your
71
+ own page to change the home.
72
+
73
+ ## Make it yours
74
+
75
+ - Colours, fonts, shape: pick a preset and tokens in the dashboard, or pass `preset`, `theme` and `appearance` to
76
+ `StorefrontNextProvider` in `app/providers.tsx`.
77
+ - Every element carries `data-throttle-part="<part>"` and the class `tsf-<part>`, inside `@layer throttle`, so your own
78
+ CSS or Tailwind classes win without `!important`.
79
+ - Text: `localization` on the provider overrides any string.
@@ -0,0 +1,7 @@
1
+ import { createAccountPage } from '@usethrottle/storefront-react/next';
2
+ import { store } from '@/lib/store';
3
+
4
+ const route = createAccountPage(store);
5
+
6
+ export default route.Page;
7
+ export const generateMetadata = route.generateMetadata;
@@ -0,0 +1,5 @@
1
+ import { createRevalidateHandler } from '@usethrottle/storefront-react/next';
2
+
3
+ // The catalog's signed storefront.changed webhook. The signature is checked first (an unsigned request is a
4
+ // 401 and clears nothing). A verified notice clears one coarse tag, at most once a minute, however many arrive.
5
+ export const POST = createRevalidateHandler({ secret: process.env.THROTTLE_WEBHOOK_SECRET });
@@ -0,0 +1,9 @@
1
+ import { createGenerationSyncHandler } from '@usethrottle/storefront-react/next';
2
+ import { createStorefrontServerClient } from '@usethrottle/storefront-react/server';
3
+ import { store } from '@/lib/store';
4
+
5
+ // The open tab's backstop: when the tab sees the catalog's generation move it POSTs here before it refreshes.
6
+ // The cache is cleared only if the generation really moved, one coarse tag, at most once a minute.
7
+ export const { POST } = createGenerationSyncHandler({
8
+ client: createStorefrontServerClient({ catalogKey: store.catalogKey }),
9
+ });
@@ -0,0 +1,7 @@
1
+ import { createShopAllPage } from '@usethrottle/storefront-react/next';
2
+ import { store } from '@/lib/store';
3
+
4
+ const route = createShopAllPage({ ...store, source: 'category' });
5
+
6
+ export default route.Page;
7
+ export const generateMetadata = route.generateMetadata;
@@ -0,0 +1,7 @@
1
+ import { createShopAllPage } from '@usethrottle/storefront-react/next';
2
+ import { store } from '@/lib/store';
3
+
4
+ const route = createShopAllPage({ ...store, source: 'collection' });
5
+
6
+ export default route.Page;
7
+ export const generateMetadata = route.generateMetadata;
@@ -0,0 +1,16 @@
1
+ import '@usethrottle/storefront-react/styles.css';
2
+ import { createStorefrontServerClient, loadSettings } from '@usethrottle/storefront-react/server';
3
+ import type { ReactNode } from 'react';
4
+ import { store } from '@/lib/store';
5
+ import { Providers } from './providers';
6
+
7
+ export default async function RootLayout({ children }: { children: ReactNode }) {
8
+ const settings = await loadSettings({ client: createStorefrontServerClient({ catalogKey: store.catalogKey }) });
9
+ return (
10
+ <html lang="en">
11
+ <body style={{ margin: 0 }}>
12
+ <Providers settings={settings}>{children}</Providers>
13
+ </body>
14
+ </html>
15
+ );
16
+ }
@@ -0,0 +1,5 @@
1
+ import { NotFound } from '@usethrottle/storefront-react';
2
+
3
+ export default function NotFoundPage() {
4
+ return <NotFound />;
5
+ }
@@ -0,0 +1,11 @@
1
+ import { createProductPage } from '@usethrottle/storefront-react/next';
2
+ import { store } from '@/lib/store';
3
+
4
+ // staticParams: 0 prerenders no product at build (a deploy would write every prerendered page again).
5
+ // `generateStaticParams` is not exported on purpose: the page reads `?variant=` from the request, and Next
6
+ // refuses to serve a prerendered route that does. The product is rendered when asked for, from the catalog
7
+ // data cached until the catalog changes, so it costs no ISR write.
8
+ const route = createProductPage({ ...store, staticParams: 0 });
9
+
10
+ export default route.Page;
11
+ export const generateMetadata = route.generateMetadata;
@@ -0,0 +1,2 @@
1
+ // The home page is the shop. Replace this file with your own page when you have one.
2
+ export { default, generateMetadata } from './shop/page';
@@ -0,0 +1,22 @@
1
+ 'use client';
2
+ import { StoreFrame } from '@usethrottle/storefront-react';
3
+ import { StorefrontNextProvider, type StorefrontNextProviderProps } from '@usethrottle/storefront-react/next/client';
4
+ import type { ReactNode } from 'react';
5
+
6
+ /**
7
+ * The storefront provider and the page around every route (header, footer, cart drawer).
8
+ * `generationWatch` is the open tab's check for a catalog change: one cheap conditional read at this interval.
9
+ * 60 s is the least the package allows. Raise it if you like; do not lower it.
10
+ */
11
+ export function Providers({ settings, children }: { settings: StorefrontNextProviderProps['settings']; children: ReactNode }) {
12
+ return (
13
+ <StorefrontNextProvider
14
+ catalogKey={process.env.NEXT_PUBLIC_THROTTLE_CATALOG_KEY}
15
+ settings={settings}
16
+ generationWatch={{ intervalMs: 60_000 }}
17
+ injectStyles={false}
18
+ >
19
+ <StoreFrame>{children}</StoreFrame>
20
+ </StorefrontNextProvider>
21
+ );
22
+ }
@@ -0,0 +1,11 @@
1
+ import { createSearchPage } from '@usethrottle/storefront-react/next';
2
+ import { store } from '@/lib/store';
3
+
4
+ const route = createSearchPage(store);
5
+
6
+ // Search results are never cached or written as a static page: every query is a new URL, and caching them is
7
+ // what makes a store's hosting bill grow.
8
+ export const dynamic = 'force-dynamic';
9
+
10
+ export default route.Page;
11
+ export const generateMetadata = route.generateMetadata;
@@ -0,0 +1,7 @@
1
+ import { createShopAllPage } from '@usethrottle/storefront-react/next';
2
+ import { store } from '@/lib/store';
3
+
4
+ const route = createShopAllPage({ ...store, source: 'all' });
5
+
6
+ export default route.Page;
7
+ export const generateMetadata = route.generateMetadata;
@@ -0,0 +1,7 @@
1
+ import { createShopAllPage } from '@usethrottle/storefront-react/next';
2
+ import { store } from '@/lib/store';
3
+
4
+ const route = createShopAllPage({ ...store, source: 'tag' });
5
+
6
+ export default route.Page;
7
+ export const generateMetadata = route.generateMetadata;
@@ -0,0 +1,19 @@
1
+ import { getPreviewToken } from '@usethrottle/storefront-react/next';
2
+
3
+ // A browser key is checked against the website's origin, and a request from your server carries none, so the
4
+ // server reads with the server key (THROTTLE_CATALOG_SERVER_KEY). Without one it tries the browser key, which the
5
+ // catalog refuses (403 ORIGIN_NOT_ALLOWED).
6
+ const catalogKey = process.env.THROTTLE_CATALOG_SERVER_KEY || process.env.NEXT_PUBLIC_THROTTLE_CATALOG_KEY;
7
+ if (!catalogKey) throw new Error('Set NEXT_PUBLIC_THROTTLE_CATALOG_KEY (your catalog publishable key, pc_pk_...) in .env.local.');
8
+
9
+ /**
10
+ * What every route needs. Pass it to a route helper: `createShopAllPage({ ...store })`.
11
+ *
12
+ * `previewToken` is added only when THROTTLE_PREVIEW=1 (a preview deployment). It reads the request's
13
+ * cookies, which makes a route render on every request, so a production store must not set it.
14
+ */
15
+ export const store = {
16
+ catalogKey,
17
+ baseUrl: process.env.NEXT_PUBLIC_SITE_URL ?? 'http://localhost:3000',
18
+ ...(process.env.THROTTLE_PREVIEW === '1' ? { previewToken: getPreviewToken } : {}),
19
+ };
@@ -0,0 +1,9 @@
1
+ import type { NextConfig } from 'next';
2
+
3
+ // Nothing here sets a cache time. Pages are cached until the catalog changes and are cleared by the signed
4
+ // webhook (app/api/throttle/revalidate) and the open tab's check (app/api/throttle/sync). See README.md.
5
+ const nextConfig: NextConfig = {
6
+ poweredByHeader: false,
7
+ };
8
+
9
+ export default nextConfig;
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "{{name}}",
3
+ "version": "0.1.0",
4
+ "private": true,
5
+ "scripts": {
6
+ "dev": "next dev",
7
+ "build": "next build",
8
+ "start": "next start",
9
+ "typecheck": "tsc --noEmit"
10
+ },
11
+ "dependencies": {
12
+ "next": "^16.3.5",
13
+ "react": "^19.2.8",
14
+ "react-dom": "^19.2.8"
15
+ },
16
+ "devDependencies": {
17
+ "@types/node": "^20",
18
+ "@types/react": "^19",
19
+ "@types/react-dom": "^19",
20
+ "typescript": "^5"
21
+ }
22
+ }
@@ -0,0 +1,14 @@
1
+ import { previewMiddleware } from '@usethrottle/catalog/next';
2
+
3
+ /**
4
+ * Next 16's `proxy` (the former `middleware`). The dashboard's preview opens the store with
5
+ * ?throttle_preview=<token>. This moves the token into an HTTP-only cookie and redirects to the same URL
6
+ * without it. It runs only for a request that carries the token, so ordinary traffic never reaches it.
7
+ */
8
+ export function proxy(request: Request) {
9
+ return previewMiddleware(request) ?? undefined;
10
+ }
11
+
12
+ export const config = {
13
+ matcher: [{ source: '/((?!_next/|api/).*)', has: [{ type: 'query', key: 'throttle_preview' }] }],
14
+ };
@@ -0,0 +1,20 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "lib": ["dom", "dom.iterable", "esnext"],
5
+ "allowJs": false,
6
+ "skipLibCheck": true,
7
+ "strict": true,
8
+ "noEmit": true,
9
+ "esModuleInterop": true,
10
+ "module": "esnext",
11
+ "moduleResolution": "bundler",
12
+ "resolveJsonModule": true,
13
+ "isolatedModules": true,
14
+ "jsx": "react-jsx",
15
+ "plugins": [{ "name": "next" }],
16
+ "paths": { "@/*": ["./*"] }
17
+ },
18
+ "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
19
+ "exclude": ["node_modules"]
20
+ }