Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

stackverify-ui

@stackverify/ui is a standalone SDK for building and hosting your own StackVerify storefront frontend.

You describe the store in store.json. The CLI validates that JSON, resolves trusted blocks, writes a lock file, and generates a React app. You can run that app with Vite, Next.js, or a plain Node server, then host it on Vercel, Render.com, or another Node host.

The seller owns the generated frontend. StackVerify owns the store data, trusted UI blocks, checkout rules, and future platform APIs.

After install, the two files you own are simple:

store.json
.env.local

store.json describes the store. .env.local holds the StackVerify keys. Everything else is generated or managed by your package manager and host.

Current phase

Phase 2/3 wiring is present.

  • The CLI generates Vite React, Next.js, and Node projects.
  • init, sync, dev, and build use a real HTTP client for the additive /api/sdk/v1 API.
  • Contract, block registry, store context, search, and checkout responses are validated with zod.
  • Checkout uses a secret key on the server and sends an Idempotency-Key header.
  • Fixtures remain available with STACKVERIFY_FIXTURES=on or when no publishable key is present.
  • Generated browser code calls only same-origin API paths and never receives a secret key.
  • store.json remains the file you own. Change it, then run stackverify sync.

See PACKAGE_SPEC.md for the full architecture and API plan.

Packages

  • @stackverify/ui: the published npm package and the stackverify command.
  • packages/cli: internal CLI source bundled into the published package.
  • packages/adapters: internal target and host definitions bundled into the CLI.
  • packages/runtime: internal runtime contract bundled into the CLI and copied into generated frontends.

Publish from the repository root with npm publish. The root package is public and the internal packages are private.

Install and build from this repository

pnpm install
pnpm build
pnpm lint
pnpm typecheck
pnpm test

The built CLI entry is dist/bin.js.

Use the published package with:

npx @stackverify/ui init my-store --target vite-react
cd my-store
npx stackverify dev

CLI commands

stackverify init [directory] [--target vite-react|next|node]
stackverify sync [directory]
stackverify dev [directory]
stackverify build [directory]
stackverify start [directory]
  • init creates a project, writes the starter JSON, lock file, generated source, .env.example, and .gitignore.
  • sync validates store.json and regenerates the app from it.
  • dev syncs, then starts the target dev server.
  • build syncs, then builds the target app.
  • start checks lock integrity, then starts the built app.

The target is stored in stackverify.lock.json. Pass --target only when running init.

Generated project layout

my-store/
  store.json
  stackverify.lock.json
  package.json
  .env.example
  .env.local
  .gitignore
    src/
      generated/
        App.tsx
        context.json
        runtime.ts
        tokens.css
        server/
          platform.mjs
          platform.d.mts
        blocks/
  api/
    context.mjs
    checkout.mjs
  app/
    page.tsx
    api/stackverify/context/route.ts
    api/stackverify/checkout/route.ts
  server/
    index.mjs
  vercel.json
  render.yaml

Files under src/generated/ are generated output. Edit store.json, then run stackverify sync. Do not edit generated files by hand.

Commit these files:

store.json
stackverify.lock.json
src/generated/
package.json
pnpm-lock.yaml or package-lock.json

Do not commit .env.local.

Where the API keys go

Copy the example into the generated project root:

cp .env.example .env.local

.env.local should sit next to store.json.

STACKVERIFY_API_URL=https://stack-verify.com
STACKVERIFY_FIXTURES=off
STACKVERIFY_PUBLISHABLE_KEY=
STACKVERIFY_SECRET_KEY=
  • STACKVERIFY_PUBLISHABLE_KEY starts with svsdk_pub_ and is for read-only data.
  • STACKVERIFY_SECRET_KEY starts with svsdk_sec_ and is for checkout write calls.
  • STACKVERIFY_API_URL defaults to https://stack-verify.com and must be a valid http or https URL.
  • STACKVERIFY_API_KEY is also read as a write fallback when the secret key is absent.
  • STACKVERIFY_FIXTURES=on forces demo context and demo checkout without platform calls.

Rules:

  • Put keys in .env.local locally.
  • On Vercel, Render.com, or another host, put keys in that host's environment settings.
  • Never put a secret key in store.json.
  • Never prefix a secret key with NEXT_PUBLIC_ or VITE_.
  • Never commit .env.local.
  • Generated browser code only calls same-origin paths: /api/stackverify/context and /api/stackverify/checkout.
  • Server routes are the intended place for the secret key. They must never expose it to the browser.

The CLI and generated server helper read process environment values first, then fall back to .env.local. Spawned dev and build servers inherit those values.

Checkout is retried safely with an idempotency key. The generated runtime sends Idempotency-Key to the same-origin checkout route. If the checkout block does not supply one, the runtime creates one with crypto.randomUUID(). The server helper forwards it to the platform and never sends the secret key to browser code.

If fixtures mode is active, hosted commands print a short warning. The demo checkout result has a fixed order id so local retries stay predictable.

Where the store JSON goes

Put the store design in store.json at the generated project root.

The file is a design descriptor, not application source code. An AI assistant should write or edit this file only. The CLI turns it into React source.

Starter shape:

{
  "version": 1,
  "store": {
    "slug": "zawadi"
  },
  "skin": {
    "version": 1,
    "tokens": {
      "background": "#fff5f7",
      "surface": "#ffffff",
      "text": "#2a121c",
      "mutedText": "#704255",
      "accent": "#db2777",
      "headingFont": "newsreader",
      "bodyFont": "inter",
      "radius": "md",
      "density": "comfortable"
    },
    "layout": {
      "sections": [
        "header",
        "search",
        "hero",
        "categories",
        "featured",
        "catalogue",
        "about",
        "footer"
      ],
      "header": "simple",
      "hero": "cover",
      "categories": "circles",
      "catalogue": "grid",
      "productCard": "photoFirst",
      "checkout": "sheet"
    },
    "visibility": {
      "search": true,
      "categories": true,
      "featured": true,
      "about": true,
      "reportLink": true
    }
  },
  "blocks": [
    { "id": "header.simple", "version": "1.0.0", "slot": "top", "props": {}, "data": {} },
    { "id": "search.bar", "version": "1.0.0", "slot": "top", "props": {}, "data": {} },
    { "id": "hero.cover", "version": "1.0.0", "slot": "main", "props": {}, "data": {} },
    { "id": "categories.circles", "version": "1.0.0", "slot": "main", "props": {}, "data": {} },
    { "id": "featured.grid", "version": "1.0.0", "slot": "main", "props": {}, "data": {} },
    { "id": "catalogue.grid", "version": "1.0.0", "slot": "main", "props": {}, "data": {} },
    { "id": "product.detail", "version": "1.0.0", "slot": "main", "props": {}, "data": {} },
    { "id": "about.card", "version": "1.0.0", "slot": "main", "props": {}, "data": {} },
    { "id": "footer.simple", "version": "1.0.0", "slot": "footer", "props": {}, "data": {} },
    { "id": "checkout.sheet", "version": "1.0.0", "slot": "overlay", "props": {}, "data": {} }
  ],
  "routing": {
    "home": "/",
    "product": "/product/:id",
    "search": "/search"
  }
}

Manifest rules

  • version must be 1.
  • store.slug must be lowercase with hyphens only, for example zawadi or demo-kitchen.
  • skin.version must be 1.
  • skin.tokens controls colors, fonts, radius, and density.
  • skin.layout selects trusted variants. It does not contain component source.
  • skin.visibility.reportLink must stay true.
  • blocks must use registered block ids and exact versions.
  • slot must be one of top, main, aside, footer, or overlay.
  • props and data are validated plain JSON values.
  • routing accepts internal paths only.
  • Raw HTML, CSS strings, JavaScript, scripts, iframes, event handlers, external URLs, and arbitrary imports are rejected.

Registered blocks:

header.simple
search.bar
hero.cover
categories.circles
featured.grid
catalogue.grid
product.detail
about.card
footer.simple
checkout.sheet

All registered block versions are 1.0.0. If an AI needs a block that is not in this list, it should stop and ask for a new trusted block rather than inventing one.

How an AI should use this SDK

Give the AI the existing store.json and this instruction:

Change only store.json.
Keep version 1.
Use only registered block ids and version 1.0.0.
Use plain JSON props and data.
Do not add HTML, CSS, JavaScript, scripts, iframes, external URLs, event handlers, or arbitrary imports.
Do not edit generated files, env files, package files, or the lock file.
Return the complete JSON file.

Recommended workflow:

  1. Create a project with stackverify init.
  2. Let the AI edit store.json.
  3. Write the AI result to store.json.
  4. Run stackverify sync.
  5. If validation fails, give the AI the exact error and ask it to fix only that JSON.
  6. Commit the JSON, lock file, and regenerated source.

The AI can safely change store identity, colors, fonts, section order, visibility, block order, slots, and simple props. It must not write application code. The SDK is deliberately designed so external AI output stays inside validated data over trusted templates.

Framework targets

Vite React, --target vite-react

This is the default target. It generates a React app with Vite and TypeScript.

stackverify init my-store --target vite-react
cd my-store
npm install
stackverify dev

Scripts:

npm run dev
npm run build
npm start

Generated files include index.html, vite.config.ts, src/main.tsx, server/index.mjs, Vercel functions in api/, vercel.json, and render.yaml.

Use it for:

  • Vercel with the generated api/ functions.
  • Any Node host with npm start.
  • Render.com with the generated render.yaml.

Next.js, --target next

This target generates a Next.js App Router app.

stackverify init my-store --target next
cd my-store
npm install
stackverify dev

Scripts:

npm run dev
npm run build
npm start

Generated files include app/page.tsx, app/globals.css, app/layout.tsx, and route handlers at app/api/stackverify/context/route.ts and app/api/stackverify/checkout/route.ts.

Use it for:

  • Vercel.
  • Render.com.
  • Any host that supports a Node process and npm start.

Node, --target node

This target uses the Vite React frontend plus a plain Node HTTP server.

stackverify init my-store --target node
cd my-store
npm install
npm run build
PORT=3000 npm start

It does not generate Vercel function files. Use it for Render.com or any Node host where you want an explicit server process.

Hosting

Vercel

Use either target:

  • vite-react uses generated functions in api/ and vercel.json.
  • next uses Next.js route handlers.

Set STACKVERIFY_PUBLISHABLE_KEY and STACKVERIFY_SECRET_KEY in the Vercel project settings. Do not add them to the repository.

Render.com

Use next or node. The generated render.yaml uses:

buildCommand: npm install && npm run build
startCommand: npm start

Set the StackVerify keys in Render environment settings. Do not commit them.

Other Node hosts

Use vite-react or node.

npm install
npm run build
PORT=3000 npm start

The server listens on PORT, default 3000.

Static-only hosting is not supported because checkout needs a server route. Do not bundle the secret key into static assets.

Security rules

  • The browser only talks to same-origin API routes.
  • The generated frontend never imports CLI code, database code, env values, admin helpers, or another store's data.
  • Prices are never trusted from the frontend. The platform server recalculates them from product ids and quantities.
  • Demo stores must never trigger real WhatsApp sends, M-Pesa requests, or customer emails.
  • Keep generated pages light, phone first, and readable. No dark pages, glass cards, frosted panels, heavy shadows, or gradients.
  • Do not change generated source by hand. Change the JSON and sync.

Repository checks

pnpm format
pnpm lint
pnpm typecheck
pnpm test
pnpm build

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages