create-signet-app 0.2.2 → 0.4.1
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 +128 -7
- package/package.json +4 -3
- package/src/index.ts +338 -66
- package/template-api/_github/workflows/ci.yml +0 -3
- package/template-api/_mcp/test/mcp-off.test.ts +13 -0
- package/template-api/_mcp/test/mcp.test.ts +49 -0
- package/template-api/_targets/bun/Dockerfile +13 -0
- package/template-api/_targets/bun/_dockerignore +10 -0
- package/template-api/_targets/bun/src/server.ts +32 -0
- package/template-api/_targets/cloudflare/_github/workflows/ci.yml +24 -0
- package/template-api/_targets/cloudflare/src/index.ts +17 -0
- package/template-api/_targets/node/src/server.ts +55 -0
- package/template-api/_targets/vercel/index.ts +16 -0
- package/template-api/_targets/vercel/vercel.json +4 -0
- package/template-api/src/app.ts +77 -0
- package/template-api/src/env.ts +4 -0
- package/template-api/tsconfig.json +2 -1
- package/template-api/tsconfig.test.json +1 -1
- package/template-full/README.md +155 -0
- package/template-full/_github/workflows/ci.yml +22 -0
- package/template-full/_gitignore +9 -0
- package/template-full/_mcp/test/mcp.test.ts +55 -0
- package/template-full/api/app.ts +132 -0
- package/template-full/api/db/index.ts +10 -0
- package/template-full/api/db/kv.ts +54 -0
- package/template-full/api/db/open.ts +33 -0
- package/template-full/api/db/schema.ts +57 -0
- package/template-full/api/env.ts +44 -0
- package/template-full/api/plans.ts +23 -0
- package/template-full/api/routes/account.ts +63 -0
- package/template-full/api/routes/auth.ts +134 -0
- package/template-full/api/routes/billing.ts +44 -0
- package/template-full/api/routes/notifications.ts +59 -0
- package/template-full/api/routes/privacy.ts +52 -0
- package/template-full/api/server.ts +44 -0
- package/template-full/api/services.ts +185 -0
- package/template-full/biome.json +50 -0
- package/template-full/drizzle/0000_init.sql +155 -0
- package/template-full/drizzle/0001_orgs.sql +47 -0
- package/template-full/drizzle/meta/0000_snapshot.json +974 -0
- package/template-full/drizzle/meta/0001_snapshot.json +1270 -0
- package/template-full/drizzle/meta/_journal.json +20 -0
- package/template-full/drizzle.config.ts +9 -0
- package/template-full/e2e/smoke.spec.ts +152 -0
- package/template-full/index.html +17 -0
- package/template-full/playwright.config.ts +10 -0
- package/template-full/scripts/dev.ts +17 -0
- package/template-full/src/app.css +9 -0
- package/template-full/src/components/toaster.tsx +13 -0
- package/template-full/src/lib/api.ts +40 -0
- package/template-full/src/main.tsx +36 -0
- package/template-full/src/routeTree.gen.ts +297 -0
- package/template-full/src/router.test.ts +23 -0
- package/template-full/src/router.ts +17 -0
- package/template-full/src/routes/__root.tsx +9 -0
- package/template-full/src/routes/_app/account.tsx +64 -0
- package/template-full/src/routes/_app/admin.tsx +38 -0
- package/template-full/src/routes/_app/billing.tsx +40 -0
- package/template-full/src/routes/_app/index.tsx +33 -0
- package/template-full/src/routes/_app/notifications.tsx +72 -0
- package/template-full/src/routes/_app/org/index.tsx +38 -0
- package/template-full/src/routes/_app/org/members.tsx +86 -0
- package/template-full/src/routes/_app/org/new.tsx +45 -0
- package/template-full/src/routes/_app/privacy.tsx +48 -0
- package/template-full/src/routes/_app.tsx +88 -0
- package/template-full/src/routes/invite.$token.tsx +55 -0
- package/template-full/src/routes/login.tsx +36 -0
- package/template-full/test/api.test.ts +189 -0
- package/template-full/tsconfig.api.json +19 -0
- package/template-full/tsconfig.app.json +26 -0
- package/template-full/tsconfig.json +9 -0
- package/template-full/tsconfig.node.json +16 -0
- package/template-full/tsconfig.test.json +8 -0
- package/template-full/vite.config.ts +24 -0
- package/template-api/src/index.ts +0 -55
- /package/template-api/{wrangler.jsonc → _targets/cloudflare/wrangler.jsonc} +0 -0
package/README.md
CHANGED
|
@@ -8,7 +8,74 @@ bunx create-signet-app my-app --theme cinematic
|
|
|
8
8
|
cd my-app && bun install && bun dev
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
`--theme` takes `editorial` or `
|
|
11
|
+
`--theme` takes `editorial`, `cinematic` or `finance` (editorial plus the
|
|
12
|
+
spend-category and money tokens; default `editorial`).
|
|
13
|
+
|
|
14
|
+
`--pm bun|npm|pnpm` sets the commands printed after scaffolding, in the CI
|
|
15
|
+
workflow (setup, frozen install, `<pm> run`) and in the full template's README.
|
|
16
|
+
Default: the package manager that ran it (`npm create` / `pnpm create` say so
|
|
17
|
+
in `npm_config_user_agent`), else bun. With pnpm a `pnpm-workspace.yaml`
|
|
18
|
+
approves esbuild's and workerd's build scripts, which pnpm 10+ otherwise refuses
|
|
19
|
+
to install without. Tests stay on `bun test`, so CI sets up Bun too.
|
|
20
|
+
|
|
21
|
+
## `--template full`: web app + API in one project
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
bunx create-signet-app my-app --template full --theme finance
|
|
25
|
+
cd my-app && bun install && bun run dev
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
One package, two halves: `src/` (the web template's Vite app) and `api/` (Hono
|
|
29
|
+
on Bun), with `api/server.ts` serving the API under `/api` and the built app
|
|
30
|
+
for every other path, so one process deploys it and the session cookie stays
|
|
31
|
+
same-origin. In dev, Vite proxies `/api` to it. What a fresh app has:
|
|
32
|
+
|
|
33
|
+
- **Typed client.** `src/lib/api.ts` is `createRpcClient(hc<AppType>)` over
|
|
34
|
+
`import type { AppType } from "../../api/app.ts"`: paths, inputs
|
|
35
|
+
(`zValidator`) and responses typed from the routes, with the envelope and
|
|
36
|
+
401 redirect of the web template.
|
|
37
|
+
- **Database.** SQLite (bun:sqlite) through signet-db, the schema in
|
|
38
|
+
`api/db/schema.ts`: users with roles, the audit log, idempotency keys,
|
|
39
|
+
`entitlementTables()`, `growthTables()`, `privacyTables()`, and a `kv` table
|
|
40
|
+
that backs signet-server's stores (stored sessions, phone codes, API keys,
|
|
41
|
+
the notification inbox and prefs, rate limits). drizzle-kit migrations in
|
|
42
|
+
`drizzle/`, applied on start; signet-payments' tables from `paymentsSchema`.
|
|
43
|
+
- **Sign-in.** Phone one-time codes (`requestPhoneOtp`/`verifyPhoneOtp`,
|
|
44
|
+
rate-limited), stored sessions with fixation protection, sign-out. In
|
|
45
|
+
development `devSmsSender` prints the code; it refuses staging and production.
|
|
46
|
+
`ADMIN_PHONES` grants the admin role.
|
|
47
|
+
- **Screens wired to it.** `AuthScreen` (`/login`), `ProfileCard` +
|
|
48
|
+
`SessionsList` + `ApiKeysManager` (`/account`), `NotificationInbox` +
|
|
49
|
+
`NotificationPreferences` (`/notifications`, from `createNotifier`'s inbox),
|
|
50
|
+
`ConsentList` + `DataRequests` (`/privacy`, signet-db privacy), billing
|
|
51
|
+
(`/billing`: plans from `definePlans`, current plan from entitlements,
|
|
52
|
+
`BILLING=fake` upgrades at once and is refused outside development; Razorpay
|
|
53
|
+
webhooks go through signet-payments to `applyBillingEvent`), and admin
|
|
54
|
+
(`/admin`, signet-db `defineAdmin` over the schema via `adminRoutes`, by
|
|
55
|
+
role). Billing and admin are interim pages marked `TODO(billing-screen)` /
|
|
56
|
+
`TODO(admin-screen)` until signet-ui's billing and admin screens are
|
|
57
|
+
published.
|
|
58
|
+
- **Organisations.** Sign-up creates a personal org; an org switcher in the
|
|
59
|
+
header; `/org` (settings: name, theme, brand colour) and
|
|
60
|
+
`/org/members` (roles, remove, invite links) on signet-ui's org screens;
|
|
61
|
+
`/invite/$token` to accept. signet-server's `tenant()` resolves the org from
|
|
62
|
+
the switch cookie or `x-org` header, and in production from a custom domain
|
|
63
|
+
or `ORG_ROOT_DOMAIN` subdomain. `/admin` stays the platform operator's view
|
|
64
|
+
across orgs.
|
|
65
|
+
- **Env.** `api/env.ts` (`createEnv`), and a generated, gitignored env file
|
|
66
|
+
with fresh `SESSION_SECRET` / `OTP_SECRET`.
|
|
67
|
+
- **MCP** as in the api template (`--mcp` / `--no-mcp`).
|
|
68
|
+
- **Tests.** `test/api.test.ts` drives sign-in, plans, inbox, admin roles,
|
|
69
|
+
consent and sign-out against an in-memory database; `src/router.test.ts`
|
|
70
|
+
resolves every page; `e2e/smoke.spec.ts` (Playwright, `test:e2e`) starts the
|
|
71
|
+
server with a throwaway database, reads the code from its console and goes
|
|
72
|
+
sign-in → admin → billing → inbox → account → privacy in headless Chromium,
|
|
73
|
+
then a second org, an invite a second user accepts, and a 404 for an org
|
|
74
|
+
they are not in.
|
|
75
|
+
- **README.md**, a first-day guide: run, orgs, become admin, try billing, add a
|
|
76
|
+
table → route → page, check, deploy.
|
|
77
|
+
|
|
78
|
+
The API runs on Bun whichever package manager installs it.
|
|
12
79
|
|
|
13
80
|
## Why
|
|
14
81
|
|
|
@@ -48,9 +115,30 @@ copy-paste, not configuration.
|
|
|
48
115
|
paint — React mounts too late, and without it there is a visible flash
|
|
49
116
|
- `src/lib/api.ts` with a configured `createApiClient`
|
|
50
117
|
|
|
51
|
-
## `--template api`: a
|
|
118
|
+
## `--template api`: a Hono API on the runtime you pick
|
|
52
119
|
|
|
53
|
-
`bun create-signet-app my-api --template api
|
|
120
|
+
`bun create-signet-app my-api --template api [--target cloudflare|bun|node|vercel]`
|
|
121
|
+
scaffolds a Hono API. Every target shares `src/app.ts`, `src/env.ts`, the tests
|
|
122
|
+
and CI; `--target` decides the entry and its config, and only that target's
|
|
123
|
+
files are written:
|
|
124
|
+
|
|
125
|
+
| `--target` | Entry | Config | Rate limit store |
|
|
126
|
+
|---|---|---|---|
|
|
127
|
+
| `cloudflare` (default) | `src/index.ts` (Worker) | `wrangler.jsonc` | `RateLimitCounter` Durable Object: exact |
|
|
128
|
+
| `bun` | `src/server.ts` (`Bun.serve`) | `Dockerfile` | in-process: exact for one process |
|
|
129
|
+
| `node` | `src/server.ts` (`node:http`) | `engines.node >= 22.18` | in-process: exact for one process |
|
|
130
|
+
| `vercel` | `index.ts` (default export) | `vercel.json` (Hono preset) | in-process: per function instance |
|
|
131
|
+
|
|
132
|
+
`node` runs `src/server.ts` as is through Node's type stripping (on by default
|
|
133
|
+
from 22.18), so relative imports in the template carry `.ts`. It bridges
|
|
134
|
+
`node:http` to Hono's `fetch` in a few lines instead of adding
|
|
135
|
+
`@hono/node-server`. `vercel` follows [Hono on
|
|
136
|
+
Vercel](https://vercel.com/docs/frameworks/backend/hono); Vercel overwrites
|
|
137
|
+
`x-forwarded-for` with the client IP, so one forwarded hop is trusted. On Vercel
|
|
138
|
+
the in-memory count is per instance; share it through Redis (Vercel KV is
|
|
139
|
+
[Upstash](https://vercel.com/docs/redis)) when it must be exact.
|
|
140
|
+
|
|
141
|
+
The `cloudflare` target is a Hono Worker with:
|
|
54
142
|
|
|
55
143
|
- `requestId`, `errorHandler` and `parseBody` from `@dapplelight/signet-server`, so
|
|
56
144
|
every error is the envelope with a code and a request id
|
|
@@ -65,13 +153,39 @@ copy-paste, not configuration.
|
|
|
65
153
|
the schema, then read `env.KEY`
|
|
66
154
|
- `test/env.test.ts` (`bun test`) and `.github/workflows/ci.yml`: lint,
|
|
67
155
|
typecheck, test and `wrangler deploy --dry-run`
|
|
156
|
+
- MCP for agents, asked at scaffold time ("Add MCP for agents?", default
|
|
157
|
+
yes; `--mcp` / `--no-mcp` without a terminal, default `--mcp`). With it,
|
|
158
|
+
`/mcp` serves every route validated with `zValidator` as a tool (`appTools`
|
|
159
|
+
from `@dapplelight/signet-server/mcp`), run as the caller with their auth
|
|
160
|
+
header and cookie. GET routes are read tools; any other method asks the
|
|
161
|
+
person first (`requireApproval`), and without a way to ask does nothing.
|
|
162
|
+
`asTool(false)` on a route leaves it out; `MCP=off` in the env turns the
|
|
163
|
+
endpoint off (404). It adds `@modelcontextprotocol/server` and
|
|
164
|
+
`test/mcp.test.ts`. With `--no-mcp` none of that is written
|
|
165
|
+
|
|
166
|
+
- on `bun` and `node`, `bun run start` serves the app; rate limiting is
|
|
167
|
+
in-process, keyed by the socket address, or by `x-forwarded-for` when
|
|
168
|
+
`TRUSTED_PROXY_HOPS` is set. `bun` adds a `Dockerfile`
|
|
169
|
+
|
|
170
|
+
Chose `--no-mcp` and want it later? `bun add @modelcontextprotocol/server`,
|
|
171
|
+
then at the end of `createApp` in `src/app.ts`, after the routes:
|
|
172
|
+
|
|
173
|
+
```ts
|
|
174
|
+
import { appTools } from "@dapplelight/signet-server/mcp"
|
|
175
|
+
import { mountMcp } from "@dapplelight/signet-server/mcp/hono"
|
|
176
|
+
|
|
177
|
+
mountMcp(app, "/mcp", { name: "api", version: "0.0.0", tools: appTools(app) })
|
|
178
|
+
```
|
|
68
179
|
|
|
69
180
|
Append migration tags; never edit one that has been deployed. A Worker entry
|
|
70
181
|
may export only handlers and classes (workerd: "Incorrect type for map entry").
|
|
71
182
|
|
|
72
|
-
Its test scaffolds outside the monorepo, installs, typechecks
|
|
73
|
-
with wrangler, then
|
|
74
|
-
that exactly 60 requests pass before a 429.
|
|
183
|
+
Its test scaffolds each target outside the monorepo, installs, typechecks and
|
|
184
|
+
lints it. `cloudflare` is bundled with wrangler, then run under `wrangler dev`
|
|
185
|
+
to check the envelope and that exactly 60 requests pass before a 429. `bun` and
|
|
186
|
+
`node` are served under their runtime (the node check needs Node 22.18+ on
|
|
187
|
+
`PATH`) and must limit by socket address whatever `x-forwarded-for` says;
|
|
188
|
+
`vercel`'s default export is called in process, since a deploy needs an account. Removing the `RateLimitCounter`
|
|
75
189
|
export fails it: wrangler refuses to bundle a Worker whose Durable Object is
|
|
76
190
|
not exported.
|
|
77
191
|
|
|
@@ -95,7 +209,14 @@ config into anything new produces a crash.
|
|
|
95
209
|
|
|
96
210
|
## Test
|
|
97
211
|
|
|
98
|
-
|
|
212
|
+
`test/scaffold-full.ts` scaffolds the full template outside the monorepo with
|
|
213
|
+
`--theme finance`, installs packs of every Signet package it uses, then lints,
|
|
214
|
+
typechecks, runs the app's tests, builds, checks the finance tokens reached the
|
|
215
|
+
CSS, and runs the app's Playwright smoke test headless. A `--no-mcp --pm pnpm`
|
|
216
|
+
app is then installed with pnpm, typechecked, tested and built, and `--pm npm`
|
|
217
|
+
is checked to rewrite CI.
|
|
218
|
+
|
|
219
|
+
All templates ship `_gitignore` and `_github`, renamed to `.gitignore` and
|
|
99
220
|
`.github` on scaffold: npm strips `.gitignore` from a package and may drop
|
|
100
221
|
dot-directories.
|
|
101
222
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-signet-app",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Scaffold a Vite + React + Tailwind app wired to Signet.",
|
|
6
6
|
"keywords": [
|
|
@@ -29,11 +29,12 @@
|
|
|
29
29
|
"files": [
|
|
30
30
|
"src",
|
|
31
31
|
"template",
|
|
32
|
-
"template-api"
|
|
32
|
+
"template-api",
|
|
33
|
+
"template-full"
|
|
33
34
|
],
|
|
34
35
|
"scripts": {
|
|
35
36
|
"typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.test.json",
|
|
36
|
-
"test": "bun run test/scaffold.ts && bun run test/scaffold-api.ts"
|
|
37
|
+
"test": "bun run test/scaffold.ts && bun run test/scaffold-api.ts && bun run test/scaffold-full.ts"
|
|
37
38
|
},
|
|
38
39
|
"devDependencies": {
|
|
39
40
|
"@types/bun": "^1.4.2",
|