create-signet-app 0.4.7 → 0.5.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 +160 -28
- package/{template-full → base/api}/api/app.ts +93 -15
- package/base/api/api/db/open.ts +121 -0
- package/{template-full → base/api}/api/db/schema.ts +22 -7
- package/{template-full → base/api}/api/env.ts +13 -0
- package/base/api/api/server.ts +157 -0
- package/{template-full → base/api}/api/services.ts +77 -8
- package/base/api/test/api.test.ts +51 -0
- package/base/api/test/helpers.ts +51 -0
- package/base/both/scripts/dev.ts +44 -0
- package/base/shared/README.md +298 -0
- package/{template-full → base/shared}/_github/workflows/ci.yml +1 -1
- package/{template-full → base/shared}/biome.json +1 -1
- package/{template-full → base/web}/src/lib/api.ts +28 -1
- package/{template-full → base/web}/src/main.tsx +4 -1
- package/{template-full → base/web}/src/routeTree.gen.ts +130 -90
- package/{template-full → base/web}/src/router.test.ts +12 -9
- package/base/web/src/routes/_app/index.tsx +55 -0
- package/{template-full → base/web}/src/routes/_app.tsx +39 -16
- package/{template-full → base/web}/vite.config.ts +3 -1
- package/package.json +9 -5
- package/parts/account/api/test/account.test.ts +30 -0
- package/parts/account/part.ts +6 -0
- package/parts/admin/api/test/admin.test.ts +35 -0
- package/parts/admin/part.ts +6 -0
- package/{template-full → parts/admin/web}/src/routes/_app/admin.tsx +2 -1
- package/{template-full → parts/auth/api}/api/routes/account.ts +32 -3
- package/{template-full → parts/auth/api}/api/routes/auth.ts +5 -3
- package/parts/auth/api/test/auth.test.ts +28 -0
- package/{template-full → parts/auth/both}/e2e/smoke.spec.ts +21 -7
- package/parts/auth/part.ts +22 -0
- package/parts/growth/part.ts +7 -0
- package/{template-full/_mcp → parts/mcp/api}/test/mcp.test.ts +25 -16
- package/parts/mcp/part.ts +8 -0
- package/parts/notifications/api/test/notifications.test.ts +18 -0
- package/parts/notifications/part.ts +6 -0
- package/{template-full → parts/notifications/web}/src/routes/_app/notifications.tsx +1 -1
- package/parts/orgs/api/test/orgs.test.ts +56 -0
- package/parts/orgs/part.ts +7 -0
- package/{template-full → parts/payments/api}/api/routes/billing.ts +3 -2
- package/parts/payments/api/test/payments.test.ts +31 -0
- package/parts/payments/part.ts +12 -0
- package/{template-full → parts/payments/web}/src/routes/_app/billing.tsx +6 -3
- package/parts/privacy/api/test/privacy.test.ts +20 -0
- package/parts/privacy/part.ts +7 -0
- package/src/compose.ts +369 -0
- package/src/describe.ts +200 -0
- package/src/desktop.ts +10 -10
- package/src/index.ts +433 -159
- package/template/biome.json +1 -1
- package/template-api/_targets/deno/Dockerfile +12 -0
- package/template-api/_targets/deno/_dockerignore +10 -0
- package/template-api/_targets/deno/src/server.ts +43 -0
- package/template-api/biome.json +1 -1
- package/template-cli/biome.json +1 -1
- package/template-extension/biome.json +1 -1
- package/template-full/README.md +0 -155
- package/template-full/api/db/open.ts +0 -33
- package/template-full/api/server.ts +0 -44
- package/template-full/scripts/dev.ts +0 -17
- package/template-full/src/routes/_app/index.tsx +0 -33
- package/template-full/test/api.test.ts +0 -189
- package/template-full/tsconfig.json +0 -9
- /package/{template-full → base/api}/api/db/index.ts +0 -0
- /package/{template-full → base/api}/api/db/kv.ts +0 -0
- /package/{template-full → base/api}/drizzle/0000_init.sql +0 -0
- /package/{template-full → base/api}/drizzle/0001_orgs.sql +0 -0
- /package/{template-full → base/api}/drizzle/meta/0000_snapshot.json +0 -0
- /package/{template-full → base/api}/drizzle/meta/0001_snapshot.json +0 -0
- /package/{template-full → base/api}/drizzle/meta/_journal.json +0 -0
- /package/{template-full → base/api}/drizzle.config.ts +0 -0
- /package/{template-full → base/api}/tsconfig.api.json +0 -0
- /package/{template-full → base/shared}/_gitignore +0 -0
- /package/{template-full → base/web}/index.html +0 -0
- /package/{template-full → base/web}/src/app.css +0 -0
- /package/{template-full → base/web}/src/components/toaster.tsx +0 -0
- /package/{template-full → base/web}/src/router.ts +0 -0
- /package/{template-full → base/web}/src/routes/__root.tsx +0 -0
- /package/{template-full → base/web}/tsconfig.app.json +0 -0
- /package/{template-full → base/web}/tsconfig.node.json +0 -0
- /package/{template-full → base/web}/tsconfig.test.json +0 -0
- /package/{template-full → parts/account/web}/src/routes/_app/account.tsx +0 -0
- /package/{template-full → parts/auth/both}/playwright.config.ts +0 -0
- /package/{template-full → parts/auth/web}/src/routes/login.tsx +0 -0
- /package/{template-full → parts/notifications/api}/api/routes/notifications.ts +0 -0
- /package/{template-full → parts/orgs/web}/src/routes/_app/org/index.tsx +0 -0
- /package/{template-full → parts/orgs/web}/src/routes/_app/org/members.tsx +0 -0
- /package/{template-full → parts/orgs/web}/src/routes/_app/org/new.tsx +0 -0
- /package/{template-full → parts/orgs/web}/src/routes/invite.$token.tsx +0 -0
- /package/{template-full → parts/payments/api}/api/plans.ts +0 -0
- /package/{template-full → parts/privacy/api}/api/routes/privacy.ts +0 -0
- /package/{template-full → parts/privacy/web}/src/routes/_app/privacy.tsx +0 -0
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
# __APP_NAME__
|
|
2
|
+
|
|
3
|
+
<!-- web:begin -->
|
|
4
|
+
A web app and its API in one project, on Signet. <!-- @api -->
|
|
5
|
+
A web app on Signet. Its API lives elsewhere: point `VITE_API_URL` at it. <!-- @!api -->
|
|
6
|
+
<!-- web:end -->
|
|
7
|
+
An API on Signet: Hono on Bun, with SQLite. <!-- @!web -->
|
|
8
|
+
<!-- auth:begin -->
|
|
9
|
+
It has:
|
|
10
|
+
|
|
11
|
+
- phone sign-in
|
|
12
|
+
- organisations with members, roles and invite links <!-- @orgs -->
|
|
13
|
+
- an account page with devices and API keys <!-- @account -->
|
|
14
|
+
- an in-app inbox <!-- @notifications -->
|
|
15
|
+
- privacy (DPDP consent and data requests) <!-- @privacy -->
|
|
16
|
+
- plans and billing <!-- @payments -->
|
|
17
|
+
- an admin panel over the whole database <!-- @admin -->
|
|
18
|
+
- MCP for agents at `/mcp` <!-- @mcp -->
|
|
19
|
+
<!-- auth:end -->
|
|
20
|
+
<!-- !auth:begin -->
|
|
21
|
+
- MCP for agents at `/mcp` <!-- @mcp -->
|
|
22
|
+
<!-- !auth:end -->
|
|
23
|
+
<!-- api:begin -->
|
|
24
|
+
|
|
25
|
+
The API runs on [Bun](https://bun.sh), whichever package manager installed it.
|
|
26
|
+
<!-- api:end -->
|
|
27
|
+
|
|
28
|
+
## First day
|
|
29
|
+
|
|
30
|
+
### Run it (5 minutes)
|
|
31
|
+
|
|
32
|
+
```sh
|
|
33
|
+
__PM_INSTALL__
|
|
34
|
+
__PM_RUN__ dev
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
<!-- web:begin -->
|
|
38
|
+
<!-- api:begin -->
|
|
39
|
+
`dev` starts the API on port 3000 and Vite next to it; open the URL Vite
|
|
40
|
+
prints.
|
|
41
|
+
<!-- api:end -->
|
|
42
|
+
<!-- !api:begin -->
|
|
43
|
+
`dev` starts Vite; open the URL it prints. Put your API's origin in
|
|
44
|
+
`VITE_API_URL` (in `.env.local`); unset, the app calls its own origin.
|
|
45
|
+
|
|
46
|
+
The client in `src/lib/api.ts` is untyped until you give it your API's type.
|
|
47
|
+
To type it, replace its `api` line with:
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import type { AppType } from "<your api>/api/app.ts" // an app made with --api exports it
|
|
51
|
+
export const api = createRpcClient(hc<AppType>, { baseUrl }).api
|
|
52
|
+
```
|
|
53
|
+
<!-- !api:end -->
|
|
54
|
+
<!-- web:end -->
|
|
55
|
+
`dev` starts the API on port 3000 and restarts it on change. <!-- @!web -->
|
|
56
|
+
<!-- auth:begin -->
|
|
57
|
+
Sign in with any phone number. In development no SMS is sent: the
|
|
58
|
+
code is printed in the terminal running the API.
|
|
59
|
+
<!-- auth:end -->
|
|
60
|
+
<!-- api:begin -->
|
|
61
|
+
|
|
62
|
+
The env file at the project root was written for you with fresh <!-- @auth -->
|
|
63
|
+
`SESSION_SECRET` and `OTP_SECRET` values. It is gitignored. Every variable is <!-- @auth -->
|
|
64
|
+
The env file at the project root was written for you. It is gitignored. Every variable is <!-- @!auth -->
|
|
65
|
+
declared, with its default, in `api/env.ts`.
|
|
66
|
+
<!-- api:end -->
|
|
67
|
+
<!-- orgs:begin -->
|
|
68
|
+
|
|
69
|
+
### Organisations (5 minutes)
|
|
70
|
+
|
|
71
|
+
Signing up made you a **Personal** org, and you own it.
|
|
72
|
+
<!-- web:begin -->
|
|
73
|
+
The switcher in the
|
|
74
|
+
header lists your orgs; **New organisation** makes another and moves you into
|
|
75
|
+
it. **Org** has its settings (name, theme, brand colour) and
|
|
76
|
+
**Members and invites**: create an invite link, open it in a private window,
|
|
77
|
+
sign in as another number and accept. That person sees the orgs they belong
|
|
78
|
+
to and nothing else.
|
|
79
|
+
<!-- web:end -->
|
|
80
|
+
<!-- !web:begin -->
|
|
81
|
+
`/api/orgs` makes more, switches between them, and manages members and
|
|
82
|
+
invite links. A person sees the orgs they belong to and nothing else.
|
|
83
|
+
<!-- !web:end -->
|
|
84
|
+
|
|
85
|
+
- Roles are `owner` (everything), `admin` (settings, members, invites) and
|
|
86
|
+
`member` (sees the member list), from signet-db's `DEFAULT_ORG_ROLES`. No
|
|
87
|
+
one can hand out a role with more permissions than their own, and an org
|
|
88
|
+
always keeps an owner.
|
|
89
|
+
- Which org a request is for: in development, the `signet_org` cookie the
|
|
90
|
+
switcher sets, or an `x-org` header. In production, also the org's custom
|
|
91
|
+
domain, or `<slug>.<ORG_ROOT_DOMAIN>` when you set `ORG_ROOT_DOMAIN`.
|
|
92
|
+
- Every org write (create, settings, roles, members, invites) is in the
|
|
93
|
+
audit log.
|
|
94
|
+
<!-- orgs:end -->
|
|
95
|
+
<!-- admin:begin -->
|
|
96
|
+
|
|
97
|
+
### Make yourself platform admin (2 minutes)
|
|
98
|
+
|
|
99
|
+
Put your number in `ADMIN_PHONES` (E.164, comma-separated, e.g.
|
|
100
|
+
`+919876543210`) and sign in again. **Admin** appears in the header: the
|
|
101
|
+
operator's view of every table across every org, searchable and editable, with
|
|
102
|
+
each write in the audit log. Platform roles live in `users.role`: `admin` does
|
|
103
|
+
everything, `staff` all but delete, `readonly` looks. They are separate from
|
|
104
|
+
org roles: an org owner is not a platform admin.
|
|
105
|
+
<!-- admin:end -->
|
|
106
|
+
<!-- payments:begin -->
|
|
107
|
+
|
|
108
|
+
### Try billing (2 minutes)
|
|
109
|
+
|
|
110
|
+
<!-- web:begin -->
|
|
111
|
+
Open **Billing**, pick Pro and continue. `BILLING=fake` switches the plan at once, no
|
|
112
|
+
money moves, and the inbox gets a "Plan changed" notice. The API refuses to <!-- @notifications -->
|
|
113
|
+
money moves. The API refuses to <!-- @!notifications -->
|
|
114
|
+
start with `BILLING=fake` in staging or production.
|
|
115
|
+
<!-- web:end -->
|
|
116
|
+
<!-- !web:begin -->
|
|
117
|
+
`POST /api/billing/checkout` with `{ "plan": "pro" }`: `BILLING=fake` switches the
|
|
118
|
+
plan at once and no money moves. The API refuses to start with `BILLING=fake`
|
|
119
|
+
in staging or production.
|
|
120
|
+
<!-- !web:end -->
|
|
121
|
+
|
|
122
|
+
<!-- api:begin -->
|
|
123
|
+
Plans are in `api/plans.ts`: `definePlans` says what each plan allows,
|
|
124
|
+
`PLAN_DISPLAY` the name, description and price the page shows. Check a plan anywhere in the API:
|
|
125
|
+
|
|
126
|
+
```ts
|
|
127
|
+
await s.entitlements.can(userId, "export")
|
|
128
|
+
await s.entitlements.consume(userId, "projects", 1) // { ok, remaining }
|
|
129
|
+
```
|
|
130
|
+
<!-- api:end -->
|
|
131
|
+
<!-- !api:begin -->
|
|
132
|
+
Plans are in `src/lib/plans.ts`, a copy of your API's: `definePlans` says what
|
|
133
|
+
each plan allows, `PLAN_DISPLAY` the name, description and price the page shows.
|
|
134
|
+
Keep it in step with the API.
|
|
135
|
+
<!-- !api:end -->
|
|
136
|
+
<!-- payments:end -->
|
|
137
|
+
|
|
138
|
+
### Build your first feature (the rest of the day)
|
|
139
|
+
|
|
140
|
+
<!-- api:begin -->
|
|
141
|
+
1. **Table.** Add it to `api/db/schema.ts` (see `kv` for the shape, and <!-- @!auth -->
|
|
142
|
+
`@dapplelight/signet-db/columns/sqlite` for the column helpers). <!-- @!auth -->
|
|
143
|
+
1. **Table.** Add it to `api/db/schema.ts` (see `users` for the column <!-- @auth -->
|
|
144
|
+
helpers). <!-- @auth -->
|
|
145
|
+
If it belongs to an org, give it <!-- @orgs -->
|
|
146
|
+
`orgId: text("org_id").notNull()`. <!-- @orgs -->
|
|
147
|
+
Then run `__PM_RUN__ db:generate`. The migration lands in `drizzle/`;
|
|
148
|
+
the API applies it on its next start. `__PM_RUN__ db:check` flags migrations
|
|
149
|
+
that drop or rename data.
|
|
150
|
+
2. **Route.** Add a file in `api/routes/` and mount it in `api/app.ts`.
|
|
151
|
+
<!-- auth:begin -->
|
|
152
|
+
List its path in `SIGNED_IN` if it needs a user;
|
|
153
|
+
`c.get("user")` is then the signed-in user.
|
|
154
|
+
<!-- auth:end -->
|
|
155
|
+
<!-- orgs:begin -->
|
|
156
|
+
For org data, guard the route
|
|
157
|
+
with `orgGuards({ orgs: s.orgs, userId }).requirePermission("projects:write")`
|
|
158
|
+
and read and write through `scoped(s.db, { orgId: currentTenant(c).id })`.
|
|
159
|
+
Another org's rows are then unreachable, and a table without `orgId`
|
|
160
|
+
throws instead of leaking.
|
|
161
|
+
<!-- orgs:end -->
|
|
162
|
+
Validate input with `zValidator`: the route is
|
|
163
|
+
then also typed for the client and, with MCP on, a tool.
|
|
164
|
+
<!-- api:end -->
|
|
165
|
+
<!-- web:begin -->
|
|
166
|
+
3. **Page.** Add `src/routes/_app/<name>.tsx`. Call the route through `api` <!-- @api -->
|
|
167
|
+
from `src/lib/api.ts`: the path, input and response are typed from the <!-- @api -->
|
|
168
|
+
server, so a renamed field fails typecheck instead of production. <!-- @api -->
|
|
169
|
+
1. **Page.** Add `src/routes/_app/<name>.tsx` and call your API through `api` <!-- @!api -->
|
|
170
|
+
from `src/lib/api.ts`. Give it your API's `AppType` (see the file) and the <!-- @!api -->
|
|
171
|
+
calls are typed from the server. <!-- @!api -->
|
|
172
|
+
<!-- web:end -->
|
|
173
|
+
<!-- notifications:begin -->
|
|
174
|
+
<!-- api:begin -->
|
|
175
|
+
4. **Notify.** Add a template to `templates` in `api/services.ts` and call
|
|
176
|
+
`s.notifier.notify(userId, "your.event", data)`. In-app works now; add
|
|
177
|
+
`email`, `sms` or `whatsapp` variants and senders from
|
|
178
|
+
`@dapplelight/signet-server/notify/channels` when you have provider keys.
|
|
179
|
+
<!-- api:end -->
|
|
180
|
+
<!-- notifications:end -->
|
|
181
|
+
<!-- admin:begin -->
|
|
182
|
+
|
|
183
|
+
The admin panel picks up new tables by itself.
|
|
184
|
+
<!-- admin:end -->
|
|
185
|
+
|
|
186
|
+
### Check it
|
|
187
|
+
|
|
188
|
+
```sh
|
|
189
|
+
__PM_RUN__ lint && __PM_RUN__ typecheck && __PM_RUN__ test && __PM_RUN__ build <!-- @web -->
|
|
190
|
+
__PM_RUN__ lint && __PM_RUN__ typecheck && __PM_RUN__ test <!-- @!web -->
|
|
191
|
+
<!-- web:begin -->
|
|
192
|
+
<!-- api:begin -->
|
|
193
|
+
<!-- auth:begin -->
|
|
194
|
+
__PM_X__ playwright install chromium # once
|
|
195
|
+
__PM_RUN__ test:e2e # sign in, then each page
|
|
196
|
+
<!-- auth:end -->
|
|
197
|
+
<!-- api:end -->
|
|
198
|
+
<!-- web:end -->
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
CI (`.github/workflows/ci.yml`) runs the first line on every push. Commit
|
|
202
|
+
your lockfile.
|
|
203
|
+
|
|
204
|
+
## Layout
|
|
205
|
+
|
|
206
|
+
```
|
|
207
|
+
<!-- api:begin -->
|
|
208
|
+
api/
|
|
209
|
+
app.ts routes, the signed-in gate, MCP; exports AppType for the client
|
|
210
|
+
plans.ts plans and what the billing page shows (shared with the browser) <!-- @payments -->
|
|
211
|
+
services.ts what the routes use, built once per process
|
|
212
|
+
routes/ one file per area <!-- @auth -->
|
|
213
|
+
db/schema.ts every table; drizzle/ holds the migrations
|
|
214
|
+
db/kv.ts sessions, codes, API keys, inbox and rate limits live in the kv table
|
|
215
|
+
server.ts Bun entry: the API under /api, the built app for every other path <!-- @web -->
|
|
216
|
+
server.ts Bun entry: the API under /api <!-- @!web -->
|
|
217
|
+
<!-- api:end -->
|
|
218
|
+
<!-- web:begin -->
|
|
219
|
+
src/
|
|
220
|
+
routes/login.tsx sign-in <!-- @auth -->
|
|
221
|
+
routes/_app/ the signed-in pages, home first <!-- @auth -->
|
|
222
|
+
routes/_app/ the pages, home first <!-- @!auth -->
|
|
223
|
+
routes/invite.$token.tsx the invite link <!-- @orgs -->
|
|
224
|
+
lib/api.ts the API client
|
|
225
|
+
<!-- !api:begin -->
|
|
226
|
+
lib/plans.ts plans, a copy of your API's <!-- @payments -->
|
|
227
|
+
<!-- !api:end -->
|
|
228
|
+
<!-- web:end -->
|
|
229
|
+
<!-- api:begin -->
|
|
230
|
+
test/ API tests (in-memory database)
|
|
231
|
+
e2e/ the browser smoke test <!-- @auth -->
|
|
232
|
+
<!-- api:end -->
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
## Deploying
|
|
236
|
+
|
|
237
|
+
<!-- api:begin -->
|
|
238
|
+
`__PM_RUN__ build`, then `__PM_RUN__ start` serves the API and the built app from one <!-- @web -->
|
|
239
|
+
Bun process. <!-- @web -->
|
|
240
|
+
`__PM_RUN__ start` serves the API from one Bun process. <!-- @!web -->
|
|
241
|
+
Mount a volume for `DATABASE_PATH` (default `data/app.db`) and set
|
|
242
|
+
`APP_ENV=production` on the host,
|
|
243
|
+
and `SESSION_SECRET`, `OTP_SECRET` and `ADMIN_PHONES`, <!-- @auth -->
|
|
244
|
+
and `ORG_ROOT_DOMAIN` if orgs get subdomains. For an org's custom <!-- @orgs -->
|
|
245
|
+
domain, point its DNS at the host and serve TLS for it there. <!-- @orgs -->
|
|
246
|
+
SQLite wants one writer: run one instance.
|
|
247
|
+
<!-- auth:begin -->
|
|
248
|
+
|
|
249
|
+
Before production:
|
|
250
|
+
|
|
251
|
+
- **SMS.** `api/services.ts` uses `devSmsSender`, which refuses to run in
|
|
252
|
+
staging or production. Swap in a real sender, e.g. `smsSenderFor(msg91Sms(...))`
|
|
253
|
+
from `@dapplelight/signet-server/notify/channels` (Indian numbers need DLT
|
|
254
|
+
template ids).
|
|
255
|
+
<!-- payments:begin -->
|
|
256
|
+
- **Taking real payments.** Set `BILLING=razorpay` and the `RAZORPAY_*` keys.
|
|
257
|
+
Gateway webhooks arrive at `/api/webhooks/razorpay`; signet-payments verifies
|
|
258
|
+
them and each subscription event moves the user's plan through
|
|
259
|
+
`entitlements.applyBillingEvent`. Map your Razorpay plan ids to plans in
|
|
260
|
+
`billing.plans` (`api/services.ts`). Creating the subscription at checkout is
|
|
261
|
+
the one step left to you: see the `TODO(billing)` in `api/routes/billing.ts`
|
|
262
|
+
(pass the user id in the subscription's notes and read it back with
|
|
263
|
+
`billing.subjectOf`).
|
|
264
|
+
<!-- payments:end -->
|
|
265
|
+
<!-- privacy:begin -->
|
|
266
|
+
- **Privacy requests.** Users open export and erasure requests from Privacy.
|
|
267
|
+
Fulfil them with `privacy.fulfil(id, { actor })` (export returns the data to
|
|
268
|
+
send; erasure deletes the user's rows listed in `userTables`).
|
|
269
|
+
<!-- privacy:end -->
|
|
270
|
+
<!-- auth:end -->
|
|
271
|
+
<!-- api:end -->
|
|
272
|
+
<!-- !api:begin -->
|
|
273
|
+
`__PM_RUN__ build` writes the app to `dist/`. Serve it from any static host
|
|
274
|
+
that falls back to `index.html` for unknown paths, with `VITE_API_URL` set at
|
|
275
|
+
build time. The API must allow this origin (CORS, credentials) and set its
|
|
276
|
+
session cookie for it.
|
|
277
|
+
<!-- !api:end -->
|
|
278
|
+
<!-- api:begin -->
|
|
279
|
+
|
|
280
|
+
## Observability
|
|
281
|
+
|
|
282
|
+
Off by default. Set `OBSERVABILITY=on` and the API writes a JSON log line pair
|
|
283
|
+
per request (`request.started`, then `request.completed` or `request.failed`)
|
|
284
|
+
with the request id and trace id, opens an OpenTelemetry span per request, and
|
|
285
|
+
answers `/health/live` and `/health/ready` (the database). Probes are left out
|
|
286
|
+
of spans and logs. Spans are no-ops until you register an OpenTelemetry SDK or
|
|
287
|
+
turn on Cloudflare tracing; Signet adds no exporter. To put the trace id on
|
|
288
|
+
every log line, pass `mixin` in `api/server.ts`. Prompts, bodies, cookies and
|
|
289
|
+
headers are never recorded.
|
|
290
|
+
<!-- api:end -->
|
|
291
|
+
<!-- web:begin -->
|
|
292
|
+
|
|
293
|
+
## Themes
|
|
294
|
+
|
|
295
|
+
`src/app.css` imports the __THEME__ theme from `@dapplelight/signet-tokens`.
|
|
296
|
+
Swap the import (`editorial`, `cinematic`, `finance`) and every component
|
|
297
|
+
reshapes. No component changes.
|
|
298
|
+
<!-- web:end -->
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { createRpcClient } from "@dapplelight/signet-lib/api"
|
|
2
|
+
// api:begin
|
|
2
3
|
import { hc } from "hono/client"
|
|
3
4
|
// Types only: no server code reaches the browser bundle.
|
|
4
5
|
import type { AppType } from "../../api/app.ts"
|
|
6
|
+
// api:end
|
|
7
|
+
import { hc } from "hono/client" // @!api
|
|
5
8
|
|
|
9
|
+
// api:begin
|
|
6
10
|
/**
|
|
7
11
|
* The typed client for the API in api/. Paths, inputs and responses come from
|
|
8
12
|
* the server's routes, so a renamed route or field fails typecheck here.
|
|
@@ -12,12 +16,34 @@ import type { AppType } from "../../api/app.ts"
|
|
|
12
16
|
* const { user } = await (await api.account.me.$get()).json()
|
|
13
17
|
*/
|
|
14
18
|
export const api = createRpcClient(hc<AppType>, { baseUrl: "/" }).api
|
|
19
|
+
// api:end
|
|
20
|
+
// !api:begin
|
|
21
|
+
/**
|
|
22
|
+
* The client for your API, which lives outside this project. Set VITE_API_URL
|
|
23
|
+
* (e.g. in .env.local) to its origin; unset, it calls this origin. A 401
|
|
24
|
+
* throws AuthError, any other failure an ApiError with the envelope's message.
|
|
25
|
+
*
|
|
26
|
+
* Calls are untyped until you give the client your API's type (an app
|
|
27
|
+
* scaffolded with --api exports it); then a renamed route or field fails
|
|
28
|
+
* typecheck here:
|
|
29
|
+
*
|
|
30
|
+
* import type { AppType } from "<your api>/api/app.ts"
|
|
31
|
+
* export const api = createRpcClient(hc<AppType>, { baseUrl }).api
|
|
32
|
+
*/
|
|
33
|
+
const baseUrl = import.meta.env.VITE_API_URL ?? "/"
|
|
34
|
+
// biome-ignore lint/suspicious/noExplicitAny: untyped until it has your API's AppType (above)
|
|
35
|
+
export const api: any = (createRpcClient(hc, { baseUrl }) as any).api
|
|
36
|
+
// !api:end
|
|
37
|
+
// auth:begin
|
|
15
38
|
|
|
16
|
-
/** The signed-in user and their plan; shared by the shell and the pages. */
|
|
39
|
+
/** The signed-in user and their plan; shared by the shell and the pages. */ // @payments
|
|
40
|
+
/** The signed-in user; shared by the shell and the pages. */ // @!payments
|
|
17
41
|
export const meQuery = {
|
|
18
42
|
queryKey: ["me"],
|
|
19
43
|
queryFn: async () => (await api.account.me.$get()).json(),
|
|
20
44
|
}
|
|
45
|
+
// auth:end
|
|
46
|
+
// orgs:begin
|
|
21
47
|
|
|
22
48
|
/** The user's orgs with their role, for the switcher. */
|
|
23
49
|
export const orgsQuery = {
|
|
@@ -36,5 +62,6 @@ export async function switchOrg(orgId: string, to = "/") {
|
|
|
36
62
|
await api.orgs.switch.$post({ json: { orgId } })
|
|
37
63
|
window.location.assign(to)
|
|
38
64
|
}
|
|
65
|
+
// orgs:end
|
|
39
66
|
|
|
40
67
|
export { ApiError, AuthError } from "@dapplelight/signet-lib/api"
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { onAuthErrorRedirect, queryDefaults } from "@dapplelight/signet-lib/api/query-client"
|
|
1
|
+
import { onAuthErrorRedirect, queryDefaults } from "@dapplelight/signet-lib/api/query-client" // @auth
|
|
2
|
+
import { queryDefaults } from "@dapplelight/signet-lib/api/query-client" // @!auth
|
|
2
3
|
import { ThemeProvider } from "@dapplelight/signet-ui/components/theme-provider"
|
|
3
4
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"
|
|
4
5
|
import { RouterProvider } from "@tanstack/react-router"
|
|
@@ -10,6 +11,7 @@ import "./app.css"
|
|
|
10
11
|
|
|
11
12
|
const queryClient = new QueryClient({ defaultOptions: queryDefaults() })
|
|
12
13
|
const router = createAppRouter()
|
|
14
|
+
// auth:begin
|
|
13
15
|
|
|
14
16
|
// One redirect on session expiry, however many requests fail at once. A full
|
|
15
17
|
// page load, not router.navigate: it drops every cached query of the old
|
|
@@ -20,6 +22,7 @@ const router = createAppRouter()
|
|
|
20
22
|
onAuthErrorRedirect(queryClient, () => {
|
|
21
23
|
window.location.assign(router.buildLocation({ to: "/login" }).href)
|
|
22
24
|
})
|
|
25
|
+
// auth:end
|
|
23
26
|
|
|
24
27
|
const rootElement = document.getElementById("root")
|
|
25
28
|
if (!rootElement) throw new Error("Root element #root not found in index.html")
|