@sbuilder/cli 0.9.0 → 0.11.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.
Files changed (51) hide show
  1. package/README.md +272 -12
  2. package/README.vi.md +265 -13
  3. package/dist/bin/sb.js +149 -6
  4. package/dist/bin/sb.js.map +1 -1
  5. package/dist/src/agentdocs.js +221 -0
  6. package/dist/src/agentdocs.js.map +1 -0
  7. package/dist/src/doctor.js +516 -0
  8. package/dist/src/doctor.js.map +1 -0
  9. package/dist/src/envtypes.gen.js +1748 -0
  10. package/dist/src/envtypes.gen.js.map +1 -0
  11. package/dist/src/host.js +414 -22
  12. package/dist/src/host.js.map +1 -1
  13. package/dist/src/hostlink.js +161 -0
  14. package/dist/src/hostlink.js.map +1 -0
  15. package/dist/src/init.js +19 -2
  16. package/dist/src/init.js.map +1 -1
  17. package/dist/src/login.js +1 -1
  18. package/dist/src/login.js.map +1 -1
  19. package/dist/src/next.js +82 -6
  20. package/dist/src/next.js.map +1 -1
  21. package/dist/src/repo.js +24 -2
  22. package/dist/src/repo.js.map +1 -1
  23. package/dist/src/roottsconfig.js +154 -0
  24. package/dist/src/roottsconfig.js.map +1 -0
  25. package/dist/src/route.js +16 -1
  26. package/dist/src/route.js.map +1 -1
  27. package/dist/src/scaffold.js +28 -0
  28. package/dist/src/scaffold.js.map +1 -1
  29. package/dist/src/site.js +616 -72
  30. package/dist/src/site.js.map +1 -1
  31. package/dist/src/sitedev.js +99 -0
  32. package/dist/src/sitedev.js.map +1 -0
  33. package/dist/src/siteinit.js +231 -33
  34. package/dist/src/siteinit.js.map +1 -1
  35. package/dist/src/sitekinds.js +1048 -0
  36. package/dist/src/sitekinds.js.map +1 -0
  37. package/dist/src/sitepaths.js +12 -0
  38. package/dist/src/sitepaths.js.map +1 -0
  39. package/dist/src/sitestatus.js +104 -0
  40. package/dist/src/sitestatus.js.map +1 -0
  41. package/dist/src/source/meta.js +118 -0
  42. package/dist/src/source/meta.js.map +1 -0
  43. package/dist/src/source/parse.js +21 -2
  44. package/dist/src/source/parse.js.map +1 -1
  45. package/dist/src/starter.js +61 -0
  46. package/dist/src/starter.js.map +1 -0
  47. package/dist/src/vercel.js +379 -0
  48. package/dist/src/vercel.js.map +1 -0
  49. package/package.json +9 -1
  50. package/dist/src/export.js +0 -167
  51. package/dist/src/export.js.map +0 -1
package/README.md CHANGED
@@ -16,6 +16,8 @@ Account
16
16
  that renews itself
17
17
  sb logout sign this machine out and forget that credential
18
18
  sb whoami which account (and platform) the CLI acts as
19
+ sb doctor [--json] check this machine, repo and Next.js app; every
20
+ problem names its fix; exit 1 on any failure
19
21
 
20
22
  Sites
21
23
  sb site new "<description>" [--dir <path>] [--github] [--editor]
@@ -24,9 +26,13 @@ Sites
24
26
  sb site init [dir] [--site <id>] [--github]
25
27
  a repo holding one site's pages, synced with
26
28
  GitHub both ways
27
- sb site pull | push [--force] [--dry-run]
28
- editor edits into design/pages, or your edits
29
- back as DRAFTS
29
+ sb site pull | push [--force] [--dry-run] [--prune] [--yes] [--theme]
30
+ editor edits into design/, or your edits back as
31
+ DRAFTS (--prune: delete what a gone file stood for;
32
+ --theme: also send the theme, which is live at once)
33
+ sb site status what differs from the last sync, and translations
34
+ whose source text changed (offline)
35
+ sb site dev [--theme] watch design/ and code/, push each save as a DRAFT
30
36
  sb site publish <file>… | --all
31
37
  make pages LIVE — named files, or every page
32
38
  sb site blocks the blocks your installed apps offer, with the line
@@ -38,6 +44,9 @@ Sites
38
44
  sb site code push [--site <id>] [--dir <path>] [--force] [--dry-run] [--delete]
39
45
  send local edits back; refuses a file changed
40
46
  in the Code Dock since your pull unless --force
47
+ sb site agents write the AI-agent files into this repo (never overwrites)
48
+ sb site types [--dir <path>] [--quiet]
49
+ write design/sbuilder-env.d.ts: types for the .page.tsx files
41
50
  sb site mcp the Store Builder MCP server, with this repo's key
42
51
 
43
52
  Apps (for developers building on the platform)
@@ -83,6 +92,7 @@ has no dependencies and nothing to build.
83
92
  - [Refusals, and what they mean](#refusals-and-what-they-mean)
84
93
  - [What it deliberately does not do](#what-it-deliberately-does-not-do)
85
94
  - [Troubleshooting](#troubleshooting)
95
+ - [`@sbuilder/sdk`](#sbuildersdk--the-same-platform-from-your-own-code)
86
96
  - [License](#license)
87
97
 
88
98
  ---
@@ -180,7 +190,7 @@ this flow.
180
190
 
181
191
  ### What it writes
182
192
 
183
- Five files, and nothing else:
193
+ Nine files, and nothing else:
184
194
 
185
195
  | File | What it is |
186
196
  | --- | --- |
@@ -189,6 +199,8 @@ Five files, and nothing else:
189
199
  | `.env.example` | `SB_CLIENT_ID`, `SB_CLIENT_SECRET`, `SB_API`, `SB_REDIRECT_URI` and `PORT` |
190
200
  | `README.md` | The same next steps the command prints, for when the terminal has scrolled |
191
201
  | `.gitignore` | `node_modules` and `.env` |
202
+ | `AGENTS.md`, `CLAUDE.md`, `GEMINI.md` | The rules for an AI coding agent in this repo (never commit `.env`, never submit unasked); `CLAUDE.md` and `GEMINI.md` just import `AGENTS.md` |
203
+ | `.claude/skills/sbuilder-app/SKILL.md` | The dev loop, the `sb.json` keys, the OAuth callback and embed, and the rules the platform enforces on a version. `AGENTS.md` points at it, so every agent reads the same text. There is no MCP config: the MCP server is a site's design tools, and an app repo holds no site key |
192
204
 
193
205
  Without `--with-block` there are deliberately **no blocks, no islands and no app
194
206
  data**. Each is a real feature with its own guide, and none is needed to watch an
@@ -230,6 +242,10 @@ refuses the lot and names what clashed:
230
242
  Pick an empty directory, or move those files aside.
231
243
  ```
232
244
 
245
+ The four agent files (`AGENTS.md`, `CLAUDE.md`, `GEMINI.md` and the skill) are the one exception:
246
+ if one is already there it is **kept**, with a note, so a fresh clone that has its own `AGENTS.md`
247
+ still scaffolds. A symbolic link in the way of any file is refused.
248
+
233
249
  A partial scaffold is worse than none, because it leaves a directory that looks
234
250
  initialised and is not. An *existing* directory is otherwise fine — running
235
251
  `sb app init` inside a fresh `git clone` is normal, and refusing it because `.git`
@@ -684,8 +700,17 @@ sb site new "a shop selling handmade candles" # the same, from the command lin
684
700
  sb site init my-shop --github # a repo for one of your sites, on a private GitHub repo
685
701
  sb site pull # take what was edited in the editor
686
702
  sb site push # save edited page files as DRAFTS
703
+ sb site push --prune --yes # also delete the pages whose file is gone (--yes off a terminal)
704
+ sb site push --theme # also send design/theme.json (a theme save is live at once)
705
+ sb site status # what differs from the last sync; stale translations
706
+ sb site dev # watch design/ and code/ and push each save as a DRAFT
687
707
  sb site publish --all # make pages live (or name files)
688
708
  sb site next # serve the pages from a Next.js app (npm run dev)
709
+ sb site next --link # mint the host secret into .env: a deployed host signs its requests
710
+ sb site deploy --vercel # one command to production on Vercel, with your own vercel CLI (--dry-run: the plan; --rotate replaces a link made elsewhere)
711
+ sb site agents # the AI-agent files, for a repo made by an older CLI
712
+ sb site types # design/sbuilder-env.d.ts: completion + checks for .page.tsx
713
+ sb site types --quiet # the same, silent: what a Next app's predev / prebuild run
689
714
  sb site mcp # the Store Builder MCP server, with this repo's key
690
715
  ```
691
716
 
@@ -695,6 +720,8 @@ description), writes the repo below into `./<name>` (`--dir` picks another folde
695
720
  offers to start it in that folder with your description. Signed out, it runs the
696
721
  `sb login` flow first. It is exactly what choice 1 of `sb init` does.
697
722
 
723
+ **The Next.js storefront starter** is choice 4 of `sb init` (the menu `npm create sbuilder-app` shows). It picks one of your sites, writes its repo like `sb site init`, runs `sb site next`, adds `@sbuilder/sdk` and one hand-written route, `app/api/featured/route.ts` (JSON), which lists the store's products through `@sbuilder/sdk/storefront` (no API key, so it also works on a deployed host). The page types (`design/sbuilder-env.d.ts`) come with the repo. Then `npm install && npm run dev`, and `sb site deploy --vercel` when you want it online.
724
+
698
725
  **`sb site new --editor "<description>"`** builds in the editor instead: it opens the
699
726
  editor, which creates the site and starts building it. If `sb agent` is already
700
727
  running it does the work; if not and Claude Code is installed, the command serves as
@@ -714,9 +741,11 @@ platform's key.
714
741
  **Building with AI.** Choice 1 of `sb init` (and `sb site new`) takes your description, creates
715
742
  the site, writes the repo below and — when Claude Code is installed — starts it in
716
743
  that folder with your description, so building starts right there. Any agent works:
717
- the repo carries `.mcp.json`, `.cursor/mcp.json` and `.vscode/mcp.json`, so Claude
718
- Code, Cursor and VS Code see the Store Builder tools as soon as the folder is opened
719
- (approve the `sbuilder` server once), and `AGENTS.md` (imported by `CLAUDE.md`) tells
744
+ the repo carries `.mcp.json`, `.cursor/mcp.json`, `.vscode/mcp.json`, `.gemini/settings.json` and
745
+ `.codex/config.toml`, so Claude
746
+ Code, Codex, Cursor, Gemini CLI and VS Code see the Store Builder tools as soon as the folder
747
+ is opened (approve the `sbuilder` server once; **Codex: trust the folder once**, or it does not
748
+ read `.codex/config.toml`), and `AGENTS.md` (imported by `CLAUDE.md` and `GEMINI.md`) tells
720
749
  the agent how to work: native elements first, look at every section on desktop and
721
750
  mobile, ask for real facts, pull the result into the repo, **never publish unasked**.
722
751
  The agent edits the site's drafts; you review what it did as a git diff.
@@ -730,9 +759,19 @@ takes `--site <id>`), and writes:
730
759
  | `code/` | The site's Code Dock files (`sb site code pull --dir code`) |
731
760
  | `.sb-site.json` | What was last synced — commit it |
732
761
  | `.env` | An API key minted for this repo, mode `0600`, git-ignored |
733
- | `.mcp.json`, `.cursor/mcp.json`, `.vscode/mcp.json` | The MCP server, started as `sb site mcp` |
734
- | `AGENTS.md`, `CLAUDE.md` | How an AI agent works in this repo |
762
+ | `.mcp.json`, `.cursor/mcp.json`, `.vscode/mcp.json`, `.gemini/settings.json`, `.codex/config.toml` | The MCP server, started as `sb site mcp`, for Claude Code, Cursor, VS Code, Gemini CLI and Codex |
763
+ | `AGENTS.md`, `CLAUDE.md`, `GEMINI.md` | How an AI agent works in this repo; the other two import `AGENTS.md` |
764
+ | `.claude/skills/sbuilder-page/SKILL.md` | The page syntax, the section-building loop with the tools, app-block rules and what pull / push / publish do — `AGENTS.md` points at it, so every agent reads the same text |
735
765
  | `.github/workflows/sbuilder.yml` | The GitHub half of the sync |
766
+ | `design/sbuilder-env.d.ts`, `design/tsconfig.json` | Types for the page files (see *Page types* below) — commit them; `sb site types` regenerates the first |
767
+
768
+ None of the agent files above is overwritten. One that is already there is kept — silently when it
769
+ is what init would write, otherwise with a note saying what it lacks and the exact text to add.
770
+ `sb site agents` writes just these files into a repo made by an older version of the CLI, with the same rule.
771
+ A symbolic link in the way of any file init writes (`.env`, `.github`, …) is refused before the
772
+ key is minted (an agent file behind a link is skipped with a note instead), and an existing
773
+ `.env` is never replaced. A folder's own `.gitignore` is kept — init only adds `node_modules` and
774
+ `.env` to it — and so is its own `README.md`.
736
775
 
737
776
  The key is named `AI agent · <folder>` and carries every content permission your
738
777
  account may delegate — never members, roles, site settings or export. Revoke it in
@@ -782,6 +821,111 @@ checkout, forms, the islands runtime) and any path with no page file go to the l
782
821
  (`SB_STOREFRONT` in `.env`). A route you add under `app/` wins over the page catch-all, so
783
822
  hand-written React pages live beside the builder's. Deploy it anywhere Next.js runs.
784
823
 
824
+ **Two modes.** The host renders only where it is safe to. In **preview** (`next dev`, or an
825
+ explicit `SB_MODE=preview`) a page file is rendered through `render-context` with the repo's
826
+ key, every response says `X-Robots-Tag: noindex`, and `/robots.txt` disallows everything — a
827
+ preview must never compete with the real site. A **Vercel preview deployment** is *not* this
828
+ mode: it passes the published pages through like a deployed host, needs no key, and is simply
829
+ never indexed (`noindex` on everything, `robots.txt` disallowing all, no origin check) — it follows the store's redirects as they are, so if the built-in address redirects to the primary domain a visitor leaves the preview for production (said once on stderr); the
830
+ generated `next.config.mjs` adds the header to your own routes too, read when Next *builds* (set
831
+ `SB_MODE=preview` for the build as well). In a **deployed** host (`next start`, `NODE_ENV=production`, `SB_MODE` unset) a builder page is served
832
+ from the store's **published** HTML, passed through: byte-identical by construction, cached by the
833
+ platform, and the host holds **no key** — `render-context` is a write-scoped, uncached endpoint that
834
+ must never have its key in a Vercel environment. Set `SB_STOREFRONT` to the store's built-in
835
+ address (not your own domain).
836
+
837
+ **The host link: no setting to flip.** The store redirects its built-in address to the primary
838
+ domain by default; the host forwards to the built-in address, so once the primary domain points at
839
+ the deployment that redirect would send every visitor back to the host, forever. `sb site next
840
+ --link` mints a per-site **host secret** (`sbh_…`; it is *not* an API key and has no scope: it reads
841
+ and writes nothing) into the repo's `.env` (mode 0600, never printed), together with `SB_SITE_ID`.
842
+ A deployed host that has both signs every request it forwards — pages, crawl files and `/_wb/*` —
843
+ with `X-SB-Host` (an HMAC over the time, method, path and visitor address) and `X-SB-Client-IP`; the
844
+ store, having verified it (the same site, within a minute), rate-limits the **visitor** instead of
845
+ treating every shopper as the host, and does not redirect that request. Put `SB_HOST_SECRET`,
846
+ `SB_SITE_ID`, `SB_PUBLIC_URL` and `SB_STOREFRONT` in the host's own environment (Vercel: Project →
847
+ Settings → Environment Variables). Rotating (`--link` again, with `--yes`) stops the old secret at
848
+ once. Rotate it any time with `sb site next --link --yes` (also when the site already has a link made elsewhere — another machine, CI — which `--link` asks about first: the deployed host's current secret dies at once). Revoke it with `DELETE /api/v1/host-link`, or in **Manage → Domains → Host link (Next.js)**: *Create link*, *Rotate* and *Revoke* are there too (a created or rotated secret is shown once — set it as `SB_HOST_SECRET` in your hosting provider).
849
+
850
+ The visitor's address is the **first** hop of `x-forwarded-for` on Vercel (`VERCEL=1`), which
851
+ overwrites that header with what it saw. Anywhere else the header is whatever the client sent, and a
852
+ proxy that appends puts the address it saw on the **right**, so the leftmost hop is visitor-controlled:
853
+ set `SB_TRUST_PROXY=N` — N proxies you control sit in front of the host, `1` being the usual case —
854
+ and the visitor is the Nth hop from the RIGHT (fewer hops than N and nothing is signed). With no
855
+ trustworthy address (or no secret) a request goes unsigned, the store sees the host, and the
856
+ fallback below applies.
857
+
858
+ **Without a host link** the host stops with a named error rather than loop (and refuses to start).
859
+ In **Manage → Domains → Default address** set *When someone visits this address* to **Serve this
860
+ site directly** (not *Redirect to …*).
861
+
862
+ **Deploy to Vercel: `sb site deploy --vercel`.** One command takes a repo set up with `sb site next` to a production deployment, using **your own `vercel` CLI**. It is detected; if it is not on your PATH the command prints the install and login steps and exits non-zero — `sb` never installs anything globally. In order: it makes sure `.vercelignore` lists `.env*` — `vercel deploy` reads `.vercelignore` alone and never the contents of `.gitignore`, so without it `.env` (the repo's API key) would be uploaded; `sb site next` writes the file, and here a missing line is added only after you say yes (or with `--yes`); it reuses the host link in `.env` (it mints one only when there is none; a link made elsewhere is replaced only with `--rotate`, which stops the old secret at once — `--yes` never rotates, and the addresses are validated before anything is minted); it checks that the site's primary domain **is** `SB_PUBLIC_URL`, the same check the deployed host makes at startup, and stops with the fix before changing anything on Vercel; it runs `vercel link` (once; off a terminal that needs `--yes`); it sets `SB_HOST_SECRET`, `SB_SITE_ID`, `SB_PUBLIC_URL` and `SB_STOREFRONT` for Production with `vercel env add`, each value on **stdin** (never in argv, never printed; the secret is masked even in a failing `vercel` message); and it runs `vercel deploy --prod` and prints the URL. `SB_PUBLIC_URL` and `SB_STOREFRONT` are read from the shell, else from `.env`. A variable Vercel already has is replaced only after you confirm (or pass `--yes`), so running it again is safe. **Preview deployments get `SB_STOREFRONT` only:** they pass published pages through with `noindex` and skip the origin check, so they need nothing else, and Vercel gives preview variables to every branch's build — the secret stays out of reach of a pull request's build script. (With no secret a preview follows the store's redirect from its built-in address, said once on stderr.) `--dry-run` prints the plan without running `vercel`, calling the platform or printing a value. The domain itself is added to the project with `vercel domains add <domain>`; the command reminds you. It names the Vercel project and organization before it sets anything, and refuses a `.vercel/project.json` that git tracks (a cloned repo could aim your deploy, and your secrets, at someone else's project) unless you pass `--yes` (which accepts that project). Before minting anything it checks the primary domain without the secret; when a link was replaced and a later step fails, it says the live host's old secret is already rejected, so the live site is degraded until the deploy finishes. If it fails after minting a host link it says so: production keeps the previous secret until a deploy finishes, and running the same command again reuses the new link.
863
+
864
+ **Addresses.** Besides an exact page path, a preview maps `/products/<slug>`, `/collections/<slug>`,
865
+ `/blog/<slug>` and `/courses/<slug>` to the page file of that type (the one marked
866
+ `defaultTemplate: true`, else the only one), and `/<locale>/…` — for each locale in
867
+ `design/translations/` — to the same file, including a translated page address
868
+ (`/en/about-us`). The request path is sent unchanged, so the store resolves the entity and the
869
+ translated slug. What the render could not carry is named on stderr and in
870
+ `x-sbuilder-unsupported`: `appIslands` (an app's island script is a relative URL), `entityRoutes`
871
+ (a Collections record address), `images` (an image outside the store's own media),
872
+ `translatedSlugs` (more translated addresses than one render verifies) and `gates` (a members-only
873
+ or course-gated page renders as an anonymous visitor sees it).
874
+
875
+ **One origin, and the crawl files.** `/sitemap.xml`, `/robots.txt`, `/llms.txt` and
876
+ `/<locale>/llms.txt` are **the store's own**, fetched — never regenerated here — so gates, noindex
877
+ and drafts are excluded exactly as on the store. Your own routes are merged in, each once, from
878
+ `app/sb-crawl.js` (`sitemap`: Next's sitemap entries; `robots`: extra lines; `llms`: extra lines);
879
+ do not add `app/sitemap.*` or `app/robots.*`, which would replace the store's part instead of
880
+ merging with it. Every absolute URL is on the site's one origin: a deployed host **refuses to
881
+ start** unless its public address (`SB_PUBLIC_URL`, or Vercel's `VERCEL_PROJECT_PRODUCTION_URL`)
882
+ is the site's primary domain, because canonicals, hreflang and the sitemap would otherwise point
883
+ elsewhere. Cookies the store sets come back host-only (no `Domain=`), and a redirect onto the
884
+ store's own address is rewritten to this one. Page SEO (title, description, `og*`, canonical,
885
+ `noIndex`, JSON-LD, `metaTags`) lives in `export const page`'s `settings`, merged **key by key** (an editor edit to `seo.title` and a file edit to `seo.description` both survive; the same key changed differently on both sides is named, e.g. `settings.seo.title changed here AND in the editor`, and a key removed in the file against the same key changed in the editor is a clash too); a
886
+ product's, article's or collection's SEO is catalogue data, edited in the dashboard or through
887
+ `/api/v1`, not in page files.
888
+
889
+ **On Vercel**, `sb site next` also writes a `.vercelignore` with `.env` and `.env*` (`vercel deploy` uploads `.env` otherwise: it never reads `.gitignore`'s contents), and writes `outputFileTracingIncludes` for the renderer's `.wasm`, the
890
+ page files and the manifest, so the deployed function contains what it reads at run time; the Edge
891
+ runtime is not supported (WebAssembly and the file system).
892
+
893
+ **Page types.** `design/sbuilder-env.d.ts` declares every element as a typed tag (`<Button text="…" tablet={{ style: {…} }} />`),
894
+ so VS Code, Cursor and an AI agent complete the props and flag a wrong one while you type: a
895
+ number where a text is expected, CSS written straight into `tablet={{ … }}` instead of under
896
+ `style`, a `bind` without its `field`, a typo in `<Ref id>`. It is
897
+ generated from the platform's element list, so **`sb site types`** (run it after upgrading `sb`)
898
+ rewrites it; `sb site init` and `sb site pull` write it, and a `tsconfig.json`, only where there is
899
+ none — an existing `design/tsconfig.json` is kept, with a note saying what to add. The types are data
900
+ only: they never change what a page file means or how it is read, and an unknown special is
901
+ accepted and kept (so a misspelt prop name is not flagged). An element type the editor has removed
902
+ but an old page still holds is reported as an unknown tag until
903
+ a newer `sb` lists it (run `sb site types` after upgrading).
904
+ The page types are their own TypeScript project (`design/tsconfig.json`: no DOM, `jsx: preserve`),
905
+ because the element names are globals that would clash with the DOM's (`Image`, `Text`, `Node`);
906
+ an editor uses the nearest tsconfig, so `design/` gets the page types and `app/` keeps Next's. The
907
+ app's own root `tsconfig.json` must therefore exclude `design`: `sb site next`, `sb site init`,
908
+ `sb site pull` and `sb site types` add it when the file exists (and say so when they cannot edit it),
909
+ a JS-only app gets no root tsconfig (it would make Next demand TypeScript), but once the app has a
910
+ `.ts` file of its own, `sb site types` writes one with Next's defaults plus the exclude, before Next
911
+ writes its own without it. The Next app `sb site next` writes runs `sb site types --quiet` as
912
+ `predev` and `prebuild`, so the first build never type-checks the page files with the DOM's names;
913
+ `sb doctor` checks it (`next:tsconfig`). A root tsconfig `sb` cannot edit is kept: with comments (and no `exclude` naming `design`), a
914
+ non-array `exclude` or a symlink, `sb site types` says what to add and exits 1, so `prebuild`
915
+ stops there instead of failing later inside `next build`.
916
+
917
+ ### Next.js compatibility
918
+
919
+ The host is plain `Request → Response` code (`@sbuilder/cli/host`) that **never imports `next`**
920
+ (a test fails if it does); a generated app uses only stable, public Next.js surfaces: route
921
+ handlers, `rewrites().beforeFiles`, `serverExternalPackages`, `outputFileTracingIncludes` and
922
+ `instrumentation.js`. Supported: `next` **>=15.0.0 <17** (the CLI's optional peer range; 15.0 is the
923
+ first release with all of those). `.github/workflows/next-compat.yml` builds and starts a generated
924
+ app on **15.0** (oldest), **latest** (both required) and **canary** (weekly, never blocking: a red
925
+ canary opens an issue) and checks the page route, a hand-written route, cookie filtering, noindex,
926
+ both modes and the refusal to start. A new Next.js major joins the range only after it is green
927
+ there; until then it is untested, not forbidden.
928
+
785
929
  **The workflow is the whole GitHub integration** — no GitHub App, no webhook. A push to
786
930
  `main` touching `design/` or `code/` saves drafts; every 30 minutes (and on demand) it
787
931
  pulls what changed in the editor and commits it. Running it by hand with *publish*
@@ -794,11 +938,103 @@ since. A page edited on both sides is named and skipped (exit 1); `--force` pick
794
938
  side — the editor's on pull, yours on push.
795
939
 
796
940
  **Push saves drafts; `sb site publish` is the only thing here that goes live**, and it
797
- publishes only the files you name or, with `--all`, every page. Pages are not created
798
- or deleted from files: create one in the editor (or let the agent), then pull; a page
799
- deleted on the platform keeps its file and is named. With an API key it uses
941
+ publishes only the files you name or, with `--all`, every page. With an API key it uses
800
942
  `/api/v1/pages/{id}/document` and needs no `--site`.
801
943
 
944
+ **`export const page` is authoritative.** The last export in a page file states the page's
945
+ own facts: `export const page = { name: "Pricing", slug: "pricing", type: "page",
946
+ isHomepage: false }` (plus `settings`, and `defaultTemplate: true` for an entity template).
947
+ A new `design/pages/*.page.tsx` with that export and no `id` **creates the page** on push;
948
+ changing `name`, `slug`, `type`, `isHomepage`, `settings` or `defaultTemplate` in a tracked
949
+ file renames or re-types it. `path` is derived and only informational. When the platform
950
+ settles on something other than what you asked (a slug is made unique) push says so, and
951
+ after every save the file is rewritten to what the platform stored — minted ids and the
952
+ facts it settled on — so the next `sb site pull` changes nothing. A file with no
953
+ `export const page` and no manifest entry is still only reported.
954
+
955
+ Facts are merged three ways like the document: what was last synced is the base. A fact only
956
+ your file changed is sent; one only the editor changed is left alone (the file takes it); both
957
+ changed to the same value is nothing; both changed differently refuses that page
958
+ (`name changed here AND in the editor — kept both`, exit 1, nothing sent) until you pull the
959
+ editor's or run `sb site push --force`, which picks the file. A pull keeps a file whose fact
960
+ changed on both sides and names it.
961
+
962
+ With an API key (`/api/v1`) the platform also fences the write itself: each fact a push changes is sent with the value this push read (`base`), and one the editor saved in between is refused and named (`name changed in the editor while pushing — nothing sent`; `--force` re-reads and retries once). A session login (`/api/sites/…`) has no such fence — the API-key surface is the fenced one.
963
+
964
+ **Nothing is deleted unless you say so.** A tracked page file that is gone is printed as
965
+ `missing` and the page stays on the platform (exit 1). `sb site push --prune` deletes those
966
+ pages: it lists them first, asks on a terminal, and off a terminal also needs `--yes`
967
+ (nothing is deleted otherwise). `--prune` refuses when `design/pages/` is absent, since
968
+ every page would then look deleted. A page deleted on the platform keeps its file, named
969
+ by pull.
970
+
971
+ ### The rest of the site as files
972
+
973
+ A repo made by `sb site init` also holds, next to `design/pages/`:
974
+
975
+ | Kind | Where | Facts at the end of the file |
976
+ | --- | --- | --- |
977
+ | Shared sections (header, footer, custom) | `design/globals/<name>.page.tsx` | `export const global = { id, name, kind }` |
978
+ | Overlays (cart, pop-ups, quick view) | `design/overlays/<name>.page.tsx` | `export const overlay = { id, name, kind, allPages, pages }`: `allPages` is "shown on every page" and `pages` the page ids it is attached to — two separate facts (a pop-up shown everywhere keeps its page list); a cart and a quick view have `allPages: false, pages: []` |
979
+ | The theme | `design/theme.json` | the theme document, keys sorted |
980
+ | Translations | `design/translations/<locale>.json` | nested `{ "<entityType>": { "<entityId>": { "<field>": { value, source, sourceHash } } } }` (an id or field may contain a `/`) |
981
+
982
+ These need the repo's API key (a session login skips them and says so). Every one follows the
983
+ rule the page files do: the last sync is the base, your file is ours, the platform now is
984
+ theirs; only your change is sent, only the editor's is left alone (the file takes it), the same
985
+ change on both sides is nothing, and a different change on both sides refuses that file by name
986
+ (exit 1, nothing sent) until you pull or run `sb site push --force`. A new global or overlay file
987
+ with `name` and `kind` and no `id` is created. A shared section reaches every page that shows it
988
+ at that page's next publish.
989
+
990
+ Nothing here is deleted by a missing file or a removed entry. `sb site push --prune` (and `--yes`
991
+ off a terminal) deletes a shared section or overlay whose file is gone, or translation entries
992
+ the file dropped, after listing them. A section still shown on pages comes back as `in_use`
993
+ with the page count and is kept: the CLI never forces it.
994
+
995
+ **The theme is live the moment it is saved** (there is no publish step), so `sb site push` sends
996
+ `design/theme.json` only with `--theme`; without it the file is named as withheld and nothing is
997
+ sent. Translations you add without a `source` are sent as `machine`; `sourceHash` is the editor's
998
+ fingerprint of the source text, and `sb site status` and `sb site pull` name every translation
999
+ whose source text has changed since it was translated as STALE.
1000
+
1001
+ `sb site dev` watches `design/` and `code/` and pushes each saved file as a DRAFT after 300 ms of
1002
+ quiet. It is `sb site push` per file: a parse error is printed as `file:line:col` and sends
1003
+ nothing, a file that got a 409 (the editor changed it) is stopped and named, and it never
1004
+ publishes or prunes, and it does not take `--force` (that would overwrite the editor on every save). A page whose repo has no record of the last sync (a manifest from an older CLI) names any fact the file states differently from the platform instead of sending it: `sb site pull` records them.
1005
+
1006
+ ## `sb doctor` — check the setup
1007
+
1008
+ ```
1009
+ sb doctor # check this machine, this repo and its Next.js app
1010
+ sb doctor --json # the same, as JSON for CI (exit 1 when a check fails)
1011
+ ```
1012
+
1013
+ Read-only: it reads files and sends GET requests, nothing else. Every check that does not pass
1014
+ names the exact command or Manage path that fixes it (`fix:`). `ok` and `skip` pass; a `warn`
1015
+ works but something you probably want is off; only a `fail` makes the exit code `1`.
1016
+
1017
+ | Check | What it looks at | Fails when |
1018
+ | --- | --- | --- |
1019
+ | `node` | Node.js version | older than 20 |
1020
+ | `auth` | the key (`SB_TOKEN`, the repo's `.env`) or your `sb login` | not signed in, key refused or revoked, a deploy key (`sbdk_…`), platform unreachable |
1021
+ | `scope:pages`, `scope:theme`, `scope:translations` | the read scopes of a key, and what each missing one disables | `pages.read` missing (a `warn` for the other two: they only switch off that kind of file) |
1022
+ | `scope:write` | the write scopes — **not probed** (a GET cannot test a write); it says what each one gates | never |
1023
+ | `site` | `sb.json` names a site this key or login reaches, and `.sb-site.json` is from the same one | no `siteId`, bad JSON, another site's manifest, a site you cannot read |
1024
+ | `manifest` | `.sb-site.json`: every path inside its kind's folder under `design/`, no symbolic links | a path outside `design/`, a symbolic link (a missing file is a `warn`) |
1025
+ | `files` | every file under `design/` parses | any does not: it prints `file:line:col` |
1026
+ | `domain` | the store's primary domain against `SB_PUBLIC_URL`, and the built-in address's redirect | they differ; the built-in address redirects to your deployment (the loop — fix: Manage → Domains → Default address → *Serve this site directly*) |
1027
+ | `host-secret` | the site's host link (asked with a GET), whether `SB_HOST_SECRET` / `SB_SITE_ID` are in this environment or `.env`, and — with `SB_STOREFRONT` — whether the store still accepts that secret (a signed and an unsigned GET of `robots.txt` are compared; a rotation elsewhere is a `fail`) | a secret is set but the site has no link (revoked) or no site id; a Next app with no link, or a link with no secret here, is a `warn` |
1028
+ | `next:version` | the installed `next` is in `>=15.0.0 <17` | it is outside the range |
1029
+ | `next:files` | the files `sb site next` wrote are present and as generated | one is missing (a modified file is a `warn`; `app/sb-crawl.js` is yours to edit) |
1030
+ | `next:tsconfig` | the app's root `tsconfig.json` (if there is one) excludes `design` | it does not: `next build` would type-check the page files with the DOM's names — `sb site types` fixes it |
1031
+ | `next:trace` | `.next` traces `renderpage.wasm` into the page route | built, and the wasm is not in the trace |
1032
+ | `next:noindex` | `next.config.mjs` sends noindex for a preview | never — a `warn` |
1033
+
1034
+ `--json` prints `{ "version": 1, "ok": boolean, "dir": string|null, "api": string, "checks":
1035
+ [{ "id", "title", "status": "ok"|"warn"|"fail"|"skip", "detail", "fix": string|null }] }`; the
1036
+ `id`s are stable, so a CI script can match on them.
1037
+
802
1038
  ## What changed in 0.9
803
1039
 
804
1040
  The commands moved into groups. **The old names still work in 0.9** and print one
@@ -906,6 +1142,11 @@ Three are read by the CLI itself:
906
1142
  | `SB_API` | every command but `sb app init` | `https://api.sbuilder.io.vn` — set `http://localhost:8080` for a local platform |
907
1143
  | `SB_NO_BROWSER` | `sb login` | unset — set it to stop `sb login` opening the `/device` page (CI and non-terminals never open it) |
908
1144
  | `SB_STOREFRONT` | the `sb site next` app | the live store's address (`sb site init` writes it into `.env`) — where `/_wb/*` and paths with no page file are forwarded |
1145
+ | `SB_MODE` | the `sb site next` app | `preview` renders page files with the repo's key and noindexes everything; `deployed` serves the store's published pages with no key — unset, `NODE_ENV=production` means deployed (a Vercel preview deployment is deployed, never indexed) |
1146
+ | `SB_PUBLIC_URL` | a deployed `sb site next` app | the host's public address; it must be the site's primary domain or the host refuses to start (`VERCEL_PROJECT_PRODUCTION_URL` stands in on Vercel) |
1147
+ | `SB_HOST_SECRET` | a deployed `sb site next` app | the host secret `sb site next --link` wrote into `.env`; the host signs every request it forwards with it (never logged, never in a URL) |
1148
+ | `SB_SITE_ID` | a deployed `sb site next` app | the site the host signs for (written beside the secret) |
1149
+ | `SB_TRUST_PROXY` | a `sb site next` app | `N` = the number of proxies you control in front of the host: the visitor is the Nth hop from the right of `x-forwarded-for` (on Vercel the first hop is used and this is not needed) |
909
1150
 
910
1151
  `SB_TOKEN` **overrides** the stored `sb login` credential when set. For `sb app dev`
911
1152
  and `sb app deploy` it is a token for the **organization that owns the app** — the
@@ -998,6 +1239,25 @@ Stated so you can plan around it rather than discover it.
998
1239
 
999
1240
  ---
1000
1241
 
1242
+ ## `@sbuilder/sdk` — the same platform from your own code
1243
+
1244
+ Not part of `sb`: a separate package for code that is not a terminal — your server, a
1245
+ webhook receiver, a hand-built storefront.
1246
+
1247
+ ```
1248
+ npm install @sbuilder/sdk
1249
+ ```
1250
+
1251
+ - `createClient({ apiKey })` — typed calls to `/api/v1` (products, orders, pages, …). Server-side
1252
+ only: it refuses to start where `window` exists, because an API key in a page is public.
1253
+ - `verifyWebhook(secret, headers, rawBody)` — checks a webhook delivery's signature and age.
1254
+ - `@sbuilder/sdk/storefront` — a shopper cart and the routes a front end on **another origin**
1255
+ may call; the ones that need the shopper's session cookie say so and name the proxy to mount.
1256
+
1257
+ Versioned on its own (`sdk-v*` tags); see [`sdk/README.md`](./sdk/README.md).
1258
+
1259
+ ---
1260
+
1001
1261
  ## License
1002
1262
 
1003
1263
  [MIT](./LICENSE) © Store Builder