@stackverify/ui 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/README.md +416 -2
- package/dist/bin.js +2187 -0
- package/package.json +47 -4
package/README.md
CHANGED
|
@@ -1,3 +1,417 @@
|
|
|
1
|
-
#
|
|
1
|
+
# stackverify-ui
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`@stackverify/ui` is a standalone SDK for building and hosting your own StackVerify storefront frontend.
|
|
4
|
+
|
|
5
|
+
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.
|
|
6
|
+
|
|
7
|
+
The seller owns the generated frontend. StackVerify owns the store data, trusted UI blocks, checkout rules, and future platform APIs.
|
|
8
|
+
|
|
9
|
+
After install, the two files you own are simple:
|
|
10
|
+
|
|
11
|
+
```text
|
|
12
|
+
store.json
|
|
13
|
+
.env.local
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
`store.json` describes the store. `.env.local` holds the StackVerify keys. Everything else is generated or managed by your package manager and host.
|
|
17
|
+
|
|
18
|
+
## Current phase
|
|
19
|
+
|
|
20
|
+
Phase 2/3 wiring is present.
|
|
21
|
+
|
|
22
|
+
- The CLI generates Vite React, Next.js, and Node projects.
|
|
23
|
+
- `init`, `sync`, `dev`, and `build` use a real HTTP client for the additive `/api/sdk/v1` API.
|
|
24
|
+
- Contract, block registry, store context, search, and checkout responses are validated with zod.
|
|
25
|
+
- Checkout uses a secret key on the server and sends an `Idempotency-Key` header.
|
|
26
|
+
- Fixtures remain available with `STACKVERIFY_FIXTURES=on` or when no publishable key is present.
|
|
27
|
+
- Generated browser code calls only same-origin API paths and never receives a secret key.
|
|
28
|
+
- `store.json` remains the file you own. Change it, then run `stackverify sync`.
|
|
29
|
+
|
|
30
|
+
See `PACKAGE_SPEC.md` for the full architecture and API plan.
|
|
31
|
+
|
|
32
|
+
## Packages
|
|
33
|
+
|
|
34
|
+
- `@stackverify/ui`: the published npm package and the `stackverify` command.
|
|
35
|
+
- `packages/cli`: internal CLI source bundled into the published package.
|
|
36
|
+
- `packages/adapters`: internal target and host definitions bundled into the CLI.
|
|
37
|
+
- `packages/runtime`: internal runtime contract bundled into the CLI and copied into generated frontends.
|
|
38
|
+
|
|
39
|
+
Publish from the repository root with `npm publish`. The root package is public and the internal packages are private.
|
|
40
|
+
|
|
41
|
+
## Install and build from this repository
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
pnpm install
|
|
45
|
+
pnpm build
|
|
46
|
+
pnpm lint
|
|
47
|
+
pnpm typecheck
|
|
48
|
+
pnpm test
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
The built CLI entry is `dist/bin.js`.
|
|
52
|
+
|
|
53
|
+
Use the published package with:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
npx @stackverify/ui init my-store --target vite-react
|
|
57
|
+
cd my-store
|
|
58
|
+
npx stackverify dev
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## CLI commands
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
stackverify init [directory] [--target vite-react|next|node]
|
|
65
|
+
stackverify sync [directory]
|
|
66
|
+
stackverify dev [directory]
|
|
67
|
+
stackverify build [directory]
|
|
68
|
+
stackverify start [directory]
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
- `init` creates a project, writes the starter JSON, lock file, generated source, `.env.example`, and `.gitignore`.
|
|
72
|
+
- `sync` validates `store.json` and regenerates the app from it.
|
|
73
|
+
- `dev` syncs, then starts the target dev server.
|
|
74
|
+
- `build` syncs, then builds the target app.
|
|
75
|
+
- `start` checks lock integrity, then starts the built app.
|
|
76
|
+
|
|
77
|
+
The target is stored in `stackverify.lock.json`. Pass `--target` only when running `init`.
|
|
78
|
+
|
|
79
|
+
## Generated project layout
|
|
80
|
+
|
|
81
|
+
```text
|
|
82
|
+
my-store/
|
|
83
|
+
store.json
|
|
84
|
+
stackverify.lock.json
|
|
85
|
+
package.json
|
|
86
|
+
.env.example
|
|
87
|
+
.env.local
|
|
88
|
+
.gitignore
|
|
89
|
+
src/
|
|
90
|
+
generated/
|
|
91
|
+
App.tsx
|
|
92
|
+
context.json
|
|
93
|
+
runtime.ts
|
|
94
|
+
tokens.css
|
|
95
|
+
server/
|
|
96
|
+
platform.mjs
|
|
97
|
+
platform.d.mts
|
|
98
|
+
blocks/
|
|
99
|
+
api/
|
|
100
|
+
context.mjs
|
|
101
|
+
checkout.mjs
|
|
102
|
+
app/
|
|
103
|
+
page.tsx
|
|
104
|
+
api/stackverify/context/route.ts
|
|
105
|
+
api/stackverify/checkout/route.ts
|
|
106
|
+
server/
|
|
107
|
+
index.mjs
|
|
108
|
+
vercel.json
|
|
109
|
+
render.yaml
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Files under `src/generated/` are generated output. Edit `store.json`, then run `stackverify sync`. Do not edit generated files by hand.
|
|
113
|
+
|
|
114
|
+
Commit these files:
|
|
115
|
+
|
|
116
|
+
```text
|
|
117
|
+
store.json
|
|
118
|
+
stackverify.lock.json
|
|
119
|
+
src/generated/
|
|
120
|
+
package.json
|
|
121
|
+
pnpm-lock.yaml or package-lock.json
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Do not commit `.env.local`.
|
|
125
|
+
|
|
126
|
+
## Where the API keys go
|
|
127
|
+
|
|
128
|
+
Copy the example into the generated project root:
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
cp .env.example .env.local
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
`.env.local` should sit next to `store.json`.
|
|
135
|
+
|
|
136
|
+
```dotenv
|
|
137
|
+
STACKVERIFY_API_URL=https://stack-verify.com
|
|
138
|
+
STACKVERIFY_FIXTURES=off
|
|
139
|
+
STACKVERIFY_PUBLISHABLE_KEY=
|
|
140
|
+
STACKVERIFY_SECRET_KEY=
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
- `STACKVERIFY_PUBLISHABLE_KEY` starts with `svsdk_pub_` and is for read-only data.
|
|
144
|
+
- `STACKVERIFY_SECRET_KEY` starts with `svsdk_sec_` and is for checkout write calls.
|
|
145
|
+
- `STACKVERIFY_API_URL` defaults to `https://stack-verify.com` and must be a valid http or https URL.
|
|
146
|
+
- `STACKVERIFY_API_KEY` is also read as a write fallback when the secret key is absent.
|
|
147
|
+
- `STACKVERIFY_FIXTURES=on` forces demo context and demo checkout without platform calls.
|
|
148
|
+
|
|
149
|
+
Rules:
|
|
150
|
+
|
|
151
|
+
- Put keys in `.env.local` locally.
|
|
152
|
+
- On Vercel, Render.com, or another host, put keys in that host's environment settings.
|
|
153
|
+
- Never put a secret key in `store.json`.
|
|
154
|
+
- Never prefix a secret key with `NEXT_PUBLIC_` or `VITE_`.
|
|
155
|
+
- Never commit `.env.local`.
|
|
156
|
+
- Generated browser code only calls same-origin paths: `/api/stackverify/context` and `/api/stackverify/checkout`.
|
|
157
|
+
- Server routes are the intended place for the secret key. They must never expose it to the browser.
|
|
158
|
+
|
|
159
|
+
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.
|
|
160
|
+
|
|
161
|
+
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.
|
|
162
|
+
|
|
163
|
+
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.
|
|
164
|
+
|
|
165
|
+
## Where the store JSON goes
|
|
166
|
+
|
|
167
|
+
Put the store design in `store.json` at the generated project root.
|
|
168
|
+
|
|
169
|
+
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.
|
|
170
|
+
|
|
171
|
+
Starter shape:
|
|
172
|
+
|
|
173
|
+
```json
|
|
174
|
+
{
|
|
175
|
+
"version": 1,
|
|
176
|
+
"store": {
|
|
177
|
+
"slug": "zawadi"
|
|
178
|
+
},
|
|
179
|
+
"skin": {
|
|
180
|
+
"version": 1,
|
|
181
|
+
"tokens": {
|
|
182
|
+
"background": "#fff5f7",
|
|
183
|
+
"surface": "#ffffff",
|
|
184
|
+
"text": "#2a121c",
|
|
185
|
+
"mutedText": "#704255",
|
|
186
|
+
"accent": "#db2777",
|
|
187
|
+
"headingFont": "newsreader",
|
|
188
|
+
"bodyFont": "inter",
|
|
189
|
+
"radius": "md",
|
|
190
|
+
"density": "comfortable"
|
|
191
|
+
},
|
|
192
|
+
"layout": {
|
|
193
|
+
"sections": [
|
|
194
|
+
"header",
|
|
195
|
+
"search",
|
|
196
|
+
"hero",
|
|
197
|
+
"categories",
|
|
198
|
+
"featured",
|
|
199
|
+
"catalogue",
|
|
200
|
+
"about",
|
|
201
|
+
"footer"
|
|
202
|
+
],
|
|
203
|
+
"header": "simple",
|
|
204
|
+
"hero": "cover",
|
|
205
|
+
"categories": "circles",
|
|
206
|
+
"catalogue": "grid",
|
|
207
|
+
"productCard": "photoFirst",
|
|
208
|
+
"checkout": "sheet"
|
|
209
|
+
},
|
|
210
|
+
"visibility": {
|
|
211
|
+
"search": true,
|
|
212
|
+
"categories": true,
|
|
213
|
+
"featured": true,
|
|
214
|
+
"about": true,
|
|
215
|
+
"reportLink": true
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
"blocks": [
|
|
219
|
+
{ "id": "header.simple", "version": "1.0.0", "slot": "top", "props": {}, "data": {} },
|
|
220
|
+
{ "id": "search.bar", "version": "1.0.0", "slot": "top", "props": {}, "data": {} },
|
|
221
|
+
{ "id": "hero.cover", "version": "1.0.0", "slot": "main", "props": {}, "data": {} },
|
|
222
|
+
{ "id": "categories.circles", "version": "1.0.0", "slot": "main", "props": {}, "data": {} },
|
|
223
|
+
{ "id": "featured.grid", "version": "1.0.0", "slot": "main", "props": {}, "data": {} },
|
|
224
|
+
{ "id": "catalogue.grid", "version": "1.0.0", "slot": "main", "props": {}, "data": {} },
|
|
225
|
+
{ "id": "product.detail", "version": "1.0.0", "slot": "main", "props": {}, "data": {} },
|
|
226
|
+
{ "id": "about.card", "version": "1.0.0", "slot": "main", "props": {}, "data": {} },
|
|
227
|
+
{ "id": "footer.simple", "version": "1.0.0", "slot": "footer", "props": {}, "data": {} },
|
|
228
|
+
{ "id": "checkout.sheet", "version": "1.0.0", "slot": "overlay", "props": {}, "data": {} }
|
|
229
|
+
],
|
|
230
|
+
"routing": {
|
|
231
|
+
"home": "/",
|
|
232
|
+
"product": "/product/:id",
|
|
233
|
+
"search": "/search"
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
### Manifest rules
|
|
239
|
+
|
|
240
|
+
- `version` must be `1`.
|
|
241
|
+
- `store.slug` must be lowercase with hyphens only, for example `zawadi` or `demo-kitchen`.
|
|
242
|
+
- `skin.version` must be `1`.
|
|
243
|
+
- `skin.tokens` controls colors, fonts, radius, and density.
|
|
244
|
+
- `skin.layout` selects trusted variants. It does not contain component source.
|
|
245
|
+
- `skin.visibility.reportLink` must stay `true`.
|
|
246
|
+
- `blocks` must use registered block ids and exact versions.
|
|
247
|
+
- `slot` must be one of `top`, `main`, `aside`, `footer`, or `overlay`.
|
|
248
|
+
- `props` and `data` are validated plain JSON values.
|
|
249
|
+
- `routing` accepts internal paths only.
|
|
250
|
+
- Raw HTML, CSS strings, JavaScript, scripts, iframes, event handlers, external URLs, and arbitrary imports are rejected.
|
|
251
|
+
|
|
252
|
+
Registered blocks:
|
|
253
|
+
|
|
254
|
+
```text
|
|
255
|
+
header.simple
|
|
256
|
+
search.bar
|
|
257
|
+
hero.cover
|
|
258
|
+
categories.circles
|
|
259
|
+
featured.grid
|
|
260
|
+
catalogue.grid
|
|
261
|
+
product.detail
|
|
262
|
+
about.card
|
|
263
|
+
footer.simple
|
|
264
|
+
checkout.sheet
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
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.
|
|
268
|
+
|
|
269
|
+
## How an AI should use this SDK
|
|
270
|
+
|
|
271
|
+
Give the AI the existing `store.json` and this instruction:
|
|
272
|
+
|
|
273
|
+
```text
|
|
274
|
+
Change only store.json.
|
|
275
|
+
Keep version 1.
|
|
276
|
+
Use only registered block ids and version 1.0.0.
|
|
277
|
+
Use plain JSON props and data.
|
|
278
|
+
Do not add HTML, CSS, JavaScript, scripts, iframes, external URLs, event handlers, or arbitrary imports.
|
|
279
|
+
Do not edit generated files, env files, package files, or the lock file.
|
|
280
|
+
Return the complete JSON file.
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
Recommended workflow:
|
|
284
|
+
|
|
285
|
+
1. Create a project with `stackverify init`.
|
|
286
|
+
2. Let the AI edit `store.json`.
|
|
287
|
+
3. Write the AI result to `store.json`.
|
|
288
|
+
4. Run `stackverify sync`.
|
|
289
|
+
5. If validation fails, give the AI the exact error and ask it to fix only that JSON.
|
|
290
|
+
6. Commit the JSON, lock file, and regenerated source.
|
|
291
|
+
|
|
292
|
+
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.
|
|
293
|
+
|
|
294
|
+
## Framework targets
|
|
295
|
+
|
|
296
|
+
### Vite React, `--target vite-react`
|
|
297
|
+
|
|
298
|
+
This is the default target. It generates a React app with Vite and TypeScript.
|
|
299
|
+
|
|
300
|
+
```bash
|
|
301
|
+
stackverify init my-store --target vite-react
|
|
302
|
+
cd my-store
|
|
303
|
+
npm install
|
|
304
|
+
stackverify dev
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
Scripts:
|
|
308
|
+
|
|
309
|
+
```bash
|
|
310
|
+
npm run dev
|
|
311
|
+
npm run build
|
|
312
|
+
npm start
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
Generated files include `index.html`, `vite.config.ts`, `src/main.tsx`, `server/index.mjs`, Vercel functions in `api/`, `vercel.json`, and `render.yaml`.
|
|
316
|
+
|
|
317
|
+
Use it for:
|
|
318
|
+
|
|
319
|
+
- Vercel with the generated `api/` functions.
|
|
320
|
+
- Any Node host with `npm start`.
|
|
321
|
+
- Render.com with the generated `render.yaml`.
|
|
322
|
+
|
|
323
|
+
### Next.js, `--target next`
|
|
324
|
+
|
|
325
|
+
This target generates a Next.js App Router app.
|
|
326
|
+
|
|
327
|
+
```bash
|
|
328
|
+
stackverify init my-store --target next
|
|
329
|
+
cd my-store
|
|
330
|
+
npm install
|
|
331
|
+
stackverify dev
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
Scripts:
|
|
335
|
+
|
|
336
|
+
```bash
|
|
337
|
+
npm run dev
|
|
338
|
+
npm run build
|
|
339
|
+
npm start
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
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`.
|
|
343
|
+
|
|
344
|
+
Use it for:
|
|
345
|
+
|
|
346
|
+
- Vercel.
|
|
347
|
+
- Render.com.
|
|
348
|
+
- Any host that supports a Node process and `npm start`.
|
|
349
|
+
|
|
350
|
+
### Node, `--target node`
|
|
351
|
+
|
|
352
|
+
This target uses the Vite React frontend plus a plain Node HTTP server.
|
|
353
|
+
|
|
354
|
+
```bash
|
|
355
|
+
stackverify init my-store --target node
|
|
356
|
+
cd my-store
|
|
357
|
+
npm install
|
|
358
|
+
npm run build
|
|
359
|
+
PORT=3000 npm start
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
It does not generate Vercel function files. Use it for Render.com or any Node host where you want an explicit server process.
|
|
363
|
+
|
|
364
|
+
## Hosting
|
|
365
|
+
|
|
366
|
+
### Vercel
|
|
367
|
+
|
|
368
|
+
Use either target:
|
|
369
|
+
|
|
370
|
+
- `vite-react` uses generated functions in `api/` and `vercel.json`.
|
|
371
|
+
- `next` uses Next.js route handlers.
|
|
372
|
+
|
|
373
|
+
Set `STACKVERIFY_PUBLISHABLE_KEY` and `STACKVERIFY_SECRET_KEY` in the Vercel project settings. Do not add them to the repository.
|
|
374
|
+
|
|
375
|
+
### Render.com
|
|
376
|
+
|
|
377
|
+
Use `next` or `node`. The generated `render.yaml` uses:
|
|
378
|
+
|
|
379
|
+
```text
|
|
380
|
+
buildCommand: npm install && npm run build
|
|
381
|
+
startCommand: npm start
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
Set the StackVerify keys in Render environment settings. Do not commit them.
|
|
385
|
+
|
|
386
|
+
### Other Node hosts
|
|
387
|
+
|
|
388
|
+
Use `vite-react` or `node`.
|
|
389
|
+
|
|
390
|
+
```bash
|
|
391
|
+
npm install
|
|
392
|
+
npm run build
|
|
393
|
+
PORT=3000 npm start
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
The server listens on `PORT`, default `3000`.
|
|
397
|
+
|
|
398
|
+
Static-only hosting is not supported because checkout needs a server route. Do not bundle the secret key into static assets.
|
|
399
|
+
|
|
400
|
+
## Security rules
|
|
401
|
+
|
|
402
|
+
- The browser only talks to same-origin API routes.
|
|
403
|
+
- The generated frontend never imports CLI code, database code, env values, admin helpers, or another store's data.
|
|
404
|
+
- Prices are never trusted from the frontend. The platform server recalculates them from product ids and quantities.
|
|
405
|
+
- Demo stores must never trigger real WhatsApp sends, M-Pesa requests, or customer emails.
|
|
406
|
+
- Keep generated pages light, phone first, and readable. No dark pages, glass cards, frosted panels, heavy shadows, or gradients.
|
|
407
|
+
- Do not change generated source by hand. Change the JSON and sync.
|
|
408
|
+
|
|
409
|
+
## Repository checks
|
|
410
|
+
|
|
411
|
+
```bash
|
|
412
|
+
pnpm format
|
|
413
|
+
pnpm lint
|
|
414
|
+
pnpm typecheck
|
|
415
|
+
pnpm test
|
|
416
|
+
pnpm build
|
|
417
|
+
```
|