Status: phase 1 foundation and phase 2/3 wiring are implemented in this SDK repository. The platform API is additive and is implemented separately.
@stackverify/ui is a standalone SDK and CLI that lets a seller define a storefront design in JSON, download approved UI blocks from StackVerify, and run that storefront anywhere while StackVerify remains the backend for store context, search and checkout.
The package lives in /home/jackal/stackverify-ui. The platform remains in /home/jackal/stack-verify.v2 and is treated as read-only for this phase.
The public command names are:
npx @stackverify/ui init
npx stackverify dev
npx stackverify build
npx stackverify startThe stackverify binary is exposed by @stackverify/ui, so after local install, npx stackverify dev works inside a generated storefront project.
The SDK must not assume endpoints that do not exist.
- The current storefront is server-rendered from
loadStorefrontinapps/web/src/server/commerce/storefront.ts:106. The public shape isStorefrontandStoreProductin the same file at:27and:43. - Checkout is a Next.js server action at
apps/web/src/app/[slug]/actions.ts:37. It prices the order on the server and returns a one-order HMAC token. - Dashboard APIs under
apps/web/src/app/api/dashboard/**use Better Auth cookies and active organization membership, guarded byapps/web/src/app/api/dashboard/_guard.ts:21. They are not public SDK APIs and have no general CORS support. - MCP at
apps/web/src/app/api/mcp/route.ts:60only supports four skin tools. Its tools are listed inapps/web/src/server/ai-mcp/mcp.ts:99. It cannot read products, orders, customers, payments or files. - There is no public catalog API, no public checkout REST API, no block registry endpoint and no general API-key auth today.
- The current composition contract maps sections to trusted React components in
apps/web/src/components/storefront/composed-storefront.tsx:361. There is no portable block source registry yet. - The current skin contract is strict and versioned in
packages/core/src/storefront-skin-contract.ts:4. It rejects raw HTML, CSS strings, scripts, iframes and arbitrary URLs. - Brand and storefront rules are in
docs/brand.md:185. The public store belongs to the business, not StackVerify. Storefronts keep the report link and do not carry StackVerify legal footer copy.
Because of these facts, the SDK does not call legacy dashboard or server action endpoints. It targets the additive /api/sdk/v1 contract below. The platform implementation lives in the separate platform repository and is not owned by this SDK.
- Do not modify
/home/jackal/stack-verify.v2in phase 1. - Do not change the existing skin contract, MCP tools, storefront renderer, checkout server action or dashboard APIs.
- Any future platform API is additive, versioned under
/api/sdk/v1, tenant scoped and approved through an ADR before implementation. - JSON contains descriptors and validated tokens only. It never contains raw HTML, CSS, JavaScript, scripts, iframes, unvalidated URLs or arbitrary imports.
- Blocks are platform-owned, versioned and reviewed. The SDK downloads only block ids present in the user's JSON and verifies locked hashes.
- The browser never receives the secret API key. Checkout and other write calls go through a server-side proxy generated by the SDK.
- Prices are never trusted from the generated frontend. The platform server prices every order from product ids and quantities.
- Demo stores must never trigger real WhatsApp sends, M-Pesa requests or customer emails. The platform continues to own that behavior.
Target repository: /home/jackal/stackverify-ui
Recommended monorepo shape:
/home/jackal/stackverify-ui
package.json
pnpm-workspace.yaml
tsconfig.base.json
packages/
cli/
package.json
src/
bin.ts
commands/
init.ts
dev.ts
build.ts
start.ts
sync.ts
config/
manifest.ts
lock.ts
env.ts
platform/
client.ts
blocks.ts
context.ts
checkout.ts
generator/
app.ts
routes.ts
imports.ts
test/
runtime/
package.json
src/
context-client.ts
checkout-client.ts
tokens.ts
types.ts
test/
adapters/
package.json
src/
vite-react.ts
next-app-router.ts
node.ts
vercel.ts
render.ts
templates/
vite-react-ts/
base files used by `init --target vite-react`
next-app-router/
base files used by `init --target next`
node/
Node.js server wrapper used by `init --target node`
Package boundaries:
@stackverify/uiis the published npm package name and CLI entry.packages/cliis internal source bundled into the published package.packages/runtimeis bundled into the CLI and copied into generated frontends.packages/adapterscontains small server proxy implementations for Vite React, Next.js App Router, Vercel, Node.js and Render.com, bundled into the CLI.- The generated app imports runtime helpers, never CLI code.
- A target describes the frontend framework. A host adapter describes where that target runs. Vite React and Next.js both run on Vercel. Node.js and Next.js both run on Render.com.
Initial file: store.json.
The manifest is a design descriptor. It is not a full application source file.
Recommended v1 shape:
{
"version": 1,
"store": {
"slug": "zawadi"
},
"skin": {
"version": 1,
"tokens": {},
"layout": {},
"composition": {},
"media": {},
"visibility": {}
},
"blocks": [
{
"id": "header.simple",
"version": "1.0.0",
"slot": "top",
"props": {},
"data": {}
},
{
"id": "product-grid.catalogue",
"version": "1.0.0",
"slot": "main",
"props": {},
"data": {
"source": "products",
"where": { "status": "active" },
"limit": 12
}
},
{
"id": "checkout.sheet",
"version": "1.0.0",
"slot": "overlay",
"props": {},
"data": {}
}
],
"routing": {
"home": "/",
"product": "/product/:id",
"search": "/search?q=:query"
}
}Manifest rules:
versionmust be1.store.slugidentifies the platform store. No business id or tenant id is accepted.skinuses the current public skin contract shape where applicable. The CLI revalidates it before any download.blockscontains platform block ids and semver versions only. The user cannot provide file paths, package names, URLs or source text.propsare validated against the block schema returned by the platform registry.datauses approved context queries only. It can ask for store details, products, categories, featured products or search results. It cannot ask for customers, orders, chats, payments, admin data or other tenants.routingcontains app paths only. It cannot set API endpoints or external URLs.
stackverify.lock.json is generated by dev and sync and should be committed.
It pins:
- Platform API contract version.
- Skin contract version.
- Every resolved block id, version, file list and SHA-256 digest.
- Resolved context query schemas.
- Generated app version.
Generated block source goes into .stackverify/blocks/ and is gitignored. start recreates it from the lock file when missing.
- Creates the project folder from
templates/vite-react-ts. - Writes
store.jsonwith a valid starter manifest. - Writes
.env.exampleonly. Never writes a real key into tracked files. - Adds
.gitignoreentries for.env*,.stackverify/and build output. - Does not call the platform unless the user passes
--slug.
- Loads
.env.local, thenstore.json. - Validates the manifest locally with strict zod schemas.
- Fetches the public platform contract and block metadata using the CLI API key.
- Downloads only blocks referenced by the manifest.
- Verifies every block against
stackverify.lock.json. - Generates React entry files, imports, token CSS and server proxy stubs.
- Starts a local Vite dev server and a local proxy for context and checkout calls.
- Watches the manifest. On change it validates, resolves new blocks and hot reloads.
- Runs the same validation and generation as
dev. - Builds static assets.
- Never embeds the secret API key in client bundles.
- Emits host adapter files according to
stackverify.config.json.
- Checks lock file integrity.
- Downloads missing blocks if allowed by env.
- Starts the generated frontend plus its server proxy.
- Fails clearly if a secret key is missing for endpoints that require it.
- Refreshes the contract and block metadata.
- Updates
stackverify.lock.json. - Reports breaking changes instead of silently rewriting user JSON.
These endpoints are the phase 2 platform contract. Phase 3 SDK wiring uses them exactly.
- Publishable keys start with
svsdk_pub_and secret keys start withsvsdk_sec_. - Keys are store scoped and scope limited:
blocks:readstorefront:readcheckout:writepayments:writelater if needed
- Store only the SHA-256 hash of each key.
- Rate limit by key hash and store id.
- No key creation by the CLI. Owners create keys in the dashboard after the dashboard feature is built.
- Local development may use a short-lived development key issued by an explicit dev-only script.
GET /api/sdk/v1/contract
GET /api/sdk/v1/blocks
GET /api/sdk/v1/blocks/:id@:version
A block response contains:
{
"id": "product-grid.catalogue",
"version": "1.0.0",
"entry": "index.tsx",
"files": [
{ "path": "index.tsx", "sha256": "...", "content": "..." }
],
"propsSchema": {},
"requiredContext": ["products"],
"capabilities": ["products", "links", "themeTokens"],
"sha256": "..."
}Registry rules:
- Blocks are authored and reviewed on the platform side.
- The SDK never downloads arbitrary source paths.
- Block source uses only generated imports and platform runtime helpers.
- A block cannot import server code, env, database helpers, admin helpers or another tenant's data.
- A block cannot render raw HTML strings or inline script.
GET /api/sdk/v1/storefronts/:slug/context
GET /api/sdk/v1/storefronts/:slug/search?q=...
Response data is the public storefront subset:
- Store name, slug, logo, cover, theme color, pickup and delivery settings.
- Active categories.
- Active products with server-authored display fields.
- Featured products.
- Search results by product name and category name.
- Available block metadata for design tools.
- Safe payment method flags.
No prices are trusted for checkout from these reads. Display prices may be returned for UI only, and checkout recalculates them.
POST /api/sdk/v1/storefronts/:slug/checkout
The request mirrors checkoutInputSchema in packages/core/src/commerce.ts:54:
- Items as
{ productId, quantity }with quantity from 1 to 99. - Customer name and phone.
fulfillmentaspickupordelivery, withaddressrequired for delivery.paymentChoiceaspay_noworon_delivery, defaultpay_now.- Optional note, booking, visitor, session and source fields.
- Required
Idempotency-Keyheader. The CLI and generated runtime generate one when absent.
The platform returns { ok, orderId, token, orderNumber, totalMinor, depositMinor, scheduledFor, whatsappUrl, message } on success. Failures return { ok: false, message, fieldErrors? }. The SDK validates every response with zod and maps field errors through the server proxy.
The platform:
- Validates with zod.
- Enforces rate limits.
- Prices on the server.
- Creates the order through existing tenant-scoped services.
- Returns the one-order token and next payment instructions.
- Uses fake adapters for demo businesses.
Payment claim and M-Pesa prompt endpoints are phase 3 and must reuse the existing guards in apps/web/src/app/[slug]/actions.ts:77 and :126.
Supported frontend targets:
vite-react: Vite + React + TypeScript. Small generated app, fast local dev, static assets plus a small Node API server for production.next: Next.js App Router + React + TypeScript. Route handlers provide the same-origin API proxy.node: Vite React frontend plus a plain Node.js HTTP server. This target is for Render.com and other Node hosts that want explicit control of the server.
All targets use the same manifest, lock file, downloaded blocks, runtime helpers and token CSS. The target only changes the app shell, build command and server proxy files.
The generated app has this shared shape:
src/
generated/
App.tsx generated from JSON
blocks/ downloaded from lock file
context.json generated initial store context
runtime.ts context and checkout helpers
server/
platform.mjs server-only platform proxy helper
platform.d.mts proxy helper types
tokens.css generated from validated skin tokens
main.tsx vite-react and node targets
server/
index.mjs node and vite-react production API server
api/
context.mjs Vercel function
checkout.mjs Vercel function
app/
page.tsx next target
api/stackverify/context/route.ts
api/stackverify/checkout/route.ts
.env.example
Browser behavior:
- Loads safe context from same-origin proxy routes.
- Renders only downloaded, locked, trusted blocks.
- Sends checkout input to same-origin proxy routes.
- Uses the skin token CSS variables.
- Keeps the report link and business-owned footer rules.
Server proxy behavior:
src/generated/server/platform.mjsreads the store slug fromstore.json.- It reads env from
process.envwith.env.localfallback. - It uses fixtures when
STACKVERIFY_FIXTURESis on or keys are missing. - It injects the secret API key only in the checkout call.
- It forwards only validated paths and bodies.
- It adds timeouts and error mapping.
- It never logs keys, raw customer phone numbers beyond normal platform logging rules, or full request bodies.
- Generated browser code never imports this helper.
Hosting matrix:
- Vercel:
vite-reacttarget with generatedapi/functions, ornexttarget with App Router route handlers. - Render.com:
nexttarget withnpm start, ornodetarget with the plain Node.js HTTP server. - Any Node host:
vite-reactandnodetargets both includeserver/index.mjs. - Static-only hosting: allowed only if the platform later provides a publishable read key and a host approved checkout proxy. Secret checkout key must never be bundled into static assets.
- The SDK never reads platform database tables directly.
- The SDK never imports platform source files from
/home/jackal/stack-verify.v2. - The generated frontend never receives cross-tenant data.
- API errors are shown as short owner-friendly messages. Internal paths, SQL, env names and stack traces are never exposed.
- Context queries cannot ask for admin data, chats, orders, customers, users, files or other businesses.
- Block props cannot use
dangerouslySetInnerHTML, raw style strings, remote CSS, arbitrary URLs or dynamic component construction. - Theme application uses tokens only. No hardcoded hex values in blocks.
- Keep layouts light, phone first and readable. No dark pages, glass cards, frosted panels, heavy shadows or gradients.
- Write this spec only.
- Do not touch the platform repo.
- Do not scaffold code until the spec is approved.
- Scaffold
/home/jackal/stackverify-ui. - Build manifest validation, lock file handling, API client interfaces and fake platform fixtures.
- Build
init --target vite-react,init --target nextandinit --target node. - Build
sync,dev,buildandstartagainst fixtures for each target. - Add Vercel function files for
vite-reactandnextroute handler files fornext. - Add a plain Node.js server for
nodeandvite-reactproduction hosting, suitable for Render.com. - Add tests for validation, lock integrity, generated imports, all three targets and secret key isolation.
- No platform API changes.
- Write an ADR in the platform repo before code changes.
- Add
/api/sdk/v1routes with zod validation, API-key auth, CORS only where needed and rate limits. - Add API key creation and revocation in the dashboard.
- Add docs and database schema updates for API keys if a new table is needed.
- Reuse existing tenant-scoped services. Do not duplicate business logic.
- SDK status: the client targets the exact contract in section 8 and validates every response.
- Point the SDK at real block and context endpoints.
- Add checkout through server proxy adapters.
- Add payment claim and M-Pesa prompt calls only if approved and covered by tests.
- Add end-to-end tests with a demo store.
- SDK status: contract, blocks, context, search and checkout are wired. Fixtures remain a documented fallback. Idempotency and server-only keys are covered by tests.
- Add and verify Node, Vercel, Netlify and Cloudflare Workers examples.
- Document static-only limits.
- Add release workflow for
npx @stackverify/ui.
- The repository exists only at
/home/jackal/stackverify-ui. git statusin/home/jackal/stack-verify.v2stays clean.- The CLI validates invalid manifests with clear errors.
- The CLI resolves blocks from a fake registry and writes a deterministic lock file.
- The generated app renders from JSON using downloaded fake blocks.
- Generated vite-react, next and node projects each contain the correct app shell and server proxy files.
- Generated projects include Vercel or Render.com deployment files where relevant.
- No secret key appears in generated browser bundles.
- Unit tests, typecheck and lint pass in the SDK repo.
- First generated app targets are
vite-react,nextandnode. - Key types are a publishable read key and a secret checkout key.
- First block set is header, search bar, hero, category strip, featured grid, catalogue grid, product detail, about, footer and checkout sheet.
- Phase 1 started with fixtures. Phase 3 adds the real platform API with a fixtures fallback.
- Generated block source is gitignored, with the lock file committed.
store.jsonremains the file users own. Generated files are rebuilt withstackverify sync.