ugly-app 0.1.949 → 0.1.950
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 +209 -211
- package/dist/cli/build.d.ts.map +1 -1
- package/dist/cli/build.js +28 -0
- package/dist/cli/build.js.map +1 -1
- package/dist/cli/version.d.ts +1 -1
- package/dist/cli/version.js +1 -1
- package/dist/client/audio/AudioPlayer.d.ts +1 -0
- package/dist/client/audio/AudioPlayer.d.ts.map +1 -1
- package/dist/client/audio/AudioPlayer.js +13 -5
- package/dist/client/audio/AudioPlayer.js.map +1 -1
- package/dist/client/audio/AudioRecorder.d.ts +1 -0
- package/dist/client/audio/AudioRecorder.d.ts.map +1 -1
- package/dist/client/audio/AudioRecorder.js +8 -2
- package/dist/client/audio/AudioRecorder.js.map +1 -1
- package/dist/client/audio/audioPlayer.worklet.js +30 -3
- package/dist/client/audio/audioPlayer.worklet.js.map +1 -1
- package/dist/client/audio/audioRecorder.worklet.js +7 -3
- package/dist/client/audio/audioRecorder.worklet.js.map +1 -1
- package/dist/client/audio/workletLoader.d.ts +16 -0
- package/dist/client/audio/workletLoader.d.ts.map +1 -0
- package/dist/client/audio/workletLoader.js +49 -0
- package/dist/client/audio/workletLoader.js.map +1 -0
- package/dist/server/App.d.ts.map +1 -1
- package/dist/server/App.js +7 -1
- package/dist/server/App.js.map +1 -1
- package/dist/vite/audioWorkletsPlugin.d.ts +36 -0
- package/dist/vite/audioWorkletsPlugin.d.ts.map +1 -0
- package/dist/vite/audioWorkletsPlugin.js +99 -0
- package/dist/vite/audioWorkletsPlugin.js.map +1 -0
- package/dist/vite/index.d.ts +1 -0
- package/dist/vite/index.d.ts.map +1 -1
- package/dist/vite/index.js +1 -0
- package/dist/vite/index.js.map +1 -1
- package/package.json +1 -1
- package/src/cli/build.ts +33 -0
- package/src/cli/version.ts +1 -1
- package/src/client/audio/AudioPlayer.ts +25 -5
- package/src/client/audio/AudioRecorder.ts +20 -2
- package/src/client/audio/audioPlayer.worklet.ts +33 -6
- package/src/client/audio/audioRecorder.worklet.ts +11 -7
- package/src/client/audio/workletLoader.test.ts +110 -0
- package/src/client/audio/workletLoader.ts +55 -0
- package/src/client/audio/workletSync.test.ts +43 -0
- package/src/server/App.ts +7 -1
- package/src/vite/audioWorkletsPlugin.test.ts +45 -0
- package/src/vite/audioWorkletsPlugin.ts +104 -0
- package/src/vite/index.ts +6 -0
- package/templates/vite.config.ts +11 -2
package/README.md
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
# ugly-app
|
|
2
2
|
|
|
3
|
-
A full-stack TypeScript framework for shipping production web apps.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
A full-stack TypeScript framework for shipping production web apps. Scaffold
|
|
4
|
+
with `npx ugly-app init my-app` and get an opinionated Node + React + Postgres
|
|
5
|
+
stack with type-safe RPC over WebSocket and HTTP, real-time doc subscriptions,
|
|
6
|
+
built-in auth, AI generation, storage, workers, cron, and a CLI for every
|
|
7
|
+
workflow.
|
|
8
8
|
|
|
9
9
|
ugly-app is designed to run against [ugly.bot](https://ugly.bot), which
|
|
10
|
-
provides auth, infra (Postgres, Qdrant, NATS, S3-compatible object
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
provides auth, infra (Postgres, Qdrant, NATS, S3-compatible object storage),
|
|
11
|
+
AI provider keys, push, email, and deployment. Your app talks to all of it
|
|
12
|
+
through the project's dev tunnel and its `UGLY_BOT_TOKEN`.
|
|
13
13
|
|
|
14
14
|
```bash
|
|
15
15
|
npx ugly-app init my-app
|
|
@@ -44,8 +44,8 @@ npm run dev
|
|
|
44
44
|
|
|
45
45
|
## Server — `createApp()`
|
|
46
46
|
|
|
47
|
-
Single server entry point. Returns an `App` that owns Express, the
|
|
48
|
-
|
|
47
|
+
Single server entry point. Returns an `App` that owns Express, the WebSocket
|
|
48
|
+
server, the typed DB, and the RPC dispatcher.
|
|
49
49
|
|
|
50
50
|
```ts
|
|
51
51
|
// server/index.ts
|
|
@@ -103,29 +103,31 @@ function createApp<
|
|
|
103
103
|
): App<CollectionMap<typeof BUILTIN_DEFS & Defs>, RegistryPages<R>>;
|
|
104
104
|
```
|
|
105
105
|
|
|
106
|
-
Passing `pages` in the registry (`{ requests, messages, pages }`)
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
106
|
+
Passing `pages` in the registry (`{ requests, messages, pages }`) upgrades
|
|
107
|
+
`app.pushSend()` to a per-route typed API. `pages` is optional; apps that only
|
|
108
|
+
call `configurator.setPages()` still work — they just get the loose
|
|
109
|
+
`PageRegistry` typing on `pushSend`.
|
|
110
110
|
|
|
111
111
|
### The returned `App`
|
|
112
112
|
|
|
113
|
-
|
|
114
|
-
|
|
113
|
+
`App` extends `AppRouter`, so `dispatch(name, input, userId)` is available for
|
|
114
|
+
in-process invocation of any registered handler.
|
|
115
|
+
|
|
116
|
+
| Member | Description |
|
|
117
|
+
|--------|-------------|
|
|
115
118
|
| `start(port?)` | Start the server (default 3000; templates use 4321). |
|
|
116
|
-
| `db` |
|
|
119
|
+
| `db` | `TypedDB<Map>` — map inferred from your collections + framework built-ins. |
|
|
117
120
|
| `httpServer` | The underlying Node `http.Server`. |
|
|
118
121
|
| `wss` | The main `WebSocketServer` (path set via `setWsPath`, default `/rpc`). |
|
|
119
|
-
| `dispatch(name, input, userId)` |
|
|
122
|
+
| `dispatch(name, input, userId)` | `Promise<unknown>` — invoke any registered RPC handler programmatically. |
|
|
120
123
|
| `registerRoutes(fn)` | Mount additional Express routes after creation. |
|
|
121
|
-
| `pushSend(input)` | Typed push whose click-through target is a route from this app's `pages`.
|
|
124
|
+
| `pushSend(input)` | Typed push whose click-through target is a route from this app's `pages`. Mints a `https://ugly.bot/l/<code>` short link so the URL is always absolute and dock-app-routable. |
|
|
122
125
|
|
|
123
|
-
Framework services start
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
`R2_BUCKET` doesn't pay their startup cost.
|
|
126
|
+
Framework services start inside `app.start()`: schema drift check, NATS
|
|
127
|
+
connection + KV buckets, data-proxy connection, event-counter flush, TTL
|
|
128
|
+
cleanup for log tables, console/error capture, and ugly.bot log forwarding.
|
|
129
|
+
Postgres, NATS, storage, and AI clients load **lazily** — a host without
|
|
130
|
+
`DATABASE_URL` / `NATS_URL` / `R2_BUCKET` doesn't pay their startup cost.
|
|
129
131
|
|
|
130
132
|
### `AppConfigurator`
|
|
131
133
|
|
|
@@ -156,8 +158,8 @@ Every method is optional; `setPages` is what mounts the SPA.
|
|
|
156
158
|
|
|
157
159
|
### Handler signatures
|
|
158
160
|
|
|
159
|
-
Handlers are plain async functions — no context object. Access state
|
|
160
|
-
|
|
161
|
+
Handlers are plain async functions — no context object. Access state via
|
|
162
|
+
captured imports (`app.db`, `storage`, `pgQuery`, `uglyBotRequest`, …).
|
|
161
163
|
|
|
162
164
|
```ts
|
|
163
165
|
// req() — public, userId may be null
|
|
@@ -169,30 +171,37 @@ getMe: async (userId: string, input) => { /* … */ }
|
|
|
169
171
|
|
|
170
172
|
### Built-in framework requests
|
|
171
173
|
|
|
172
|
-
`createApp` registers several framework handlers reachable from any
|
|
173
|
-
|
|
174
|
-
|
|
174
|
+
`createApp` registers several framework handlers reachable from any client via
|
|
175
|
+
the normal RPC pipeline. App-provided handlers with the same name override the
|
|
176
|
+
framework's defaults. Rate-limited handlers are marked below.
|
|
175
177
|
|
|
176
|
-
| Name |
|
|
177
|
-
|
|
178
|
+
| Name | Notes |
|
|
179
|
+
|------|-------|
|
|
178
180
|
| `userGet` | Returns `{ userId, name, avatarUri }` for the given user (or caller). |
|
|
179
181
|
| `initSession` / `captureEvent` | Session + event logging tagged with experiment branches (public — no auth). |
|
|
180
|
-
| `textGen`
|
|
181
|
-
| `
|
|
182
|
+
| `textGen` | AI text proxy — server-validated, billed through ugly.bot. Rate-limited 20/60s. |
|
|
183
|
+
| `imageGen` | AI image proxy. Rate-limited 10/60s. |
|
|
184
|
+
| `kagiSearch` / `kagiEnrichWeb` / `kagiEnrichNews` | Web search via ugly.bot. Rate-limited 20/60s. |
|
|
185
|
+
| `kagiSummarize` | URL / text summary. Rate-limited 10/60s. |
|
|
182
186
|
| `uploadUrl` | Issues a presigned PUT for the `temp` bucket. |
|
|
183
|
-
| `shareLink` | Mint a `https://ugly.bot/l/<code>` short link with OG metadata. |
|
|
184
|
-
| `feedbackReportCreateNoAuth`
|
|
185
|
-
| `
|
|
187
|
+
| `shareLink` | Mint a `https://ugly.bot/l/<code>` short link with OG metadata. Rate-limited 60/60s. |
|
|
188
|
+
| `feedbackReportCreateNoAuth` | Public, same-origin feedback endpoint used by browser telemetry. Rate-limited 10/60s. |
|
|
189
|
+
| `errorLogCaptureNoAuth` | Public error-log capture. |
|
|
190
|
+
| `perfSnapshotCaptureNoAuth` | Public perf snapshot capture. Rate-limited 60/60s. |
|
|
191
|
+
| `submitFeedbackBot` | Bot-persona feedback submission. |
|
|
192
|
+
| `feedbackReportResolve` | Admin resolve/decline. Rate-limited 120/60s. |
|
|
186
193
|
| `adminGetPerfLogs` | Admin-only perf telemetry read. |
|
|
187
194
|
| `adminCreateTestUser` / `adminListTestUsers` / `adminDeleteTestUser` | Admin-only synthetic-user management. Gated by `setIsAdmin()`. |
|
|
188
195
|
| `projectPlanList` / `projectPlanCreate` / `projectPlanUpdate` / `projectPlanDelete` | Project plan CRUD used by Studio. |
|
|
189
196
|
|
|
197
|
+
Add per-endpoint rate limits on your own handlers with `rateLimit: { max, window }` on the request definition (see below).
|
|
198
|
+
|
|
190
199
|
---
|
|
191
200
|
|
|
192
201
|
## Shared API definitions
|
|
193
202
|
|
|
194
|
-
`shared/` is consumed by both server and client. Keep all Zod schemas,
|
|
195
|
-
|
|
203
|
+
`shared/` is consumed by both server and client. Keep all Zod schemas, types,
|
|
204
|
+
collections, and route declarations here.
|
|
196
205
|
|
|
197
206
|
### Requests (`shared/api.ts`)
|
|
198
207
|
|
|
@@ -222,8 +231,8 @@ export const requests = defineRequests({
|
|
|
222
231
|
```
|
|
223
232
|
|
|
224
233
|
Every request is reachable as **both** `socket.request(name, input)`
|
|
225
|
-
(WebSocket) and `POST /api/:name { input }` (HTTP). `z` is re-exported
|
|
226
|
-
|
|
234
|
+
(WebSocket) and `POST /api/:name { input }` (HTTP). `z` is re-exported from
|
|
235
|
+
Zod for convenience.
|
|
227
236
|
|
|
228
237
|
### Collections (`shared/collections.ts`)
|
|
229
238
|
|
|
@@ -259,20 +268,19 @@ export const collections = defineCollections({
|
|
|
259
268
|
- `public` — allow unauthenticated client reads.
|
|
260
269
|
- `cascadeFrom` — parent collection: when the parent doc is deleted, docs in this collection are cascade-deleted.
|
|
261
270
|
- `trackKeys?` — fields usable as NATS routing keys for scoped `trackDocs` subscriptions.
|
|
262
|
-
- `getter?(ids)` — batch resolver for collections with no local table (
|
|
271
|
+
- `getter?(ids)` — batch resolver for collections with no local table (e.g. `userPublic` resolves via ugly.bot).
|
|
263
272
|
- `skipReadValidation?` — opt out of per-row zod validation on reads for very hot collections. Writes are always validated. Global kill-switch: `UGLY_DB_VALIDATE_READS=0`.
|
|
264
273
|
- `search?: { fields, language? }` — full-text index over the named JSONB paths (Neon: Postgres FTS; D1: SQLite FTS5, ranked by bm25).
|
|
265
274
|
- `vector?: { dimensions, metric?, filterable? }` — ANN index. Vector supplied out-of-band at write time (`setDoc(c, doc, { vec })`) — never stored in the doc JSON. Query with `getDocs(c, filter, { near })`.
|
|
266
275
|
|
|
267
276
|
All documents extend `DBObject`: `{ _id, version, created, updated }`.
|
|
268
|
-
Use `dbDefaults()` to stamp `version` / `created` / `updated` on
|
|
269
|
-
|
|
270
|
-
`
|
|
271
|
-
`CLAUDE.md`).
|
|
277
|
+
Use `dbDefaults()` to stamp `version` / `created` / `updated` on inserts.
|
|
278
|
+
**Always generate `_id` with `nanoid()`** — never `crypto.randomUUID()`,
|
|
279
|
+
`Date.now()`, or `Math.random()` (see `CLAUDE.md`).
|
|
272
280
|
|
|
273
|
-
After schema changes, run `npm run db:schema-gen` then `npm run
|
|
274
|
-
|
|
275
|
-
|
|
281
|
+
After schema changes, run `npm run db:schema-gen` then `npm run db:migrate`.
|
|
282
|
+
The app refuses to start when drift is detected (set `SCHEMA_CHECK_SKIP=true`
|
|
283
|
+
only as a last resort).
|
|
276
284
|
|
|
277
285
|
---
|
|
278
286
|
|
|
@@ -295,23 +303,20 @@ export const pages = definePages({
|
|
|
295
303
|
export type AppPages = typeof pages;
|
|
296
304
|
```
|
|
297
305
|
|
|
298
|
-
`definePage<Params>(options?)` returns a `PageDef<Params>` — a runtime
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
**Options** (all optional):
|
|
306
|
+
`definePage<Params>(options?)` returns a `PageDef<Params>` — a runtime object
|
|
307
|
+
carrying `PageMeta` plus a phantom `_params` used only for TypeScript
|
|
308
|
+
inference. `PageMeta` fields:
|
|
303
309
|
|
|
304
|
-
- `auth` (default `true`) — protected route. When `isAuthenticated()` returns false on this route, the router synchronously renders the framework's `<AuthRoot>` in place of the page (
|
|
305
|
-
- `ssr` (default `false`) — server-render the page for SEO. `{ auth: true, ssr: true }` is silently
|
|
310
|
+
- `auth` (default `true`) — protected route. When `isAuthenticated()` returns false on this route, the router synchronously renders the framework's `<AuthRoot>` in place of the page (Mode A → `<LoginPopup>`, Mode B → `<MagicLinkForm>` plus optional Google button). Apps cannot override this fallback.
|
|
311
|
+
- `ssr` (default `false`) — server-render the page for SEO. `{ auth: true, ssr: true }` is silently downgraded to `ssr: false` with a warning: the SSR document is served from a shared edge cache and must not depend on the viewer.
|
|
306
312
|
- `cacheQuery?: string[]` — query params that participate in the SSR edge-cache key. Anything NOT listed bypasses the cache instead of poisoning it (e.g. `cacheQuery: ['q']` on a search page).
|
|
307
|
-
- `ssrCacheTimeout?: number` — edge cache lifetime in seconds. Default is
|
|
313
|
+
- `ssrCacheTimeout?: number` — edge cache lifetime in seconds. Default is `DEFAULT_SSR_CACHE_TIMEOUT` (1 year) because the `buildId` is already part of the cache key. Override only for pages that drift between deploys.
|
|
308
314
|
|
|
309
315
|
Path syntax: `:param` matches a single path segment; `*param` is greedy
|
|
310
|
-
(captures slashes). Query-string params are declared in `Params` but
|
|
311
|
-
|
|
316
|
+
(captures slashes). Query-string params are declared in `Params` but never
|
|
317
|
+
appear in the path template.
|
|
312
318
|
|
|
313
|
-
`definePages<T>(p)` is a pass-through identity — use it to
|
|
314
|
-
registry a name.
|
|
319
|
+
`definePages<T>(p)` is a pass-through identity — use it to name the registry.
|
|
315
320
|
|
|
316
321
|
### `createRouter()` (`ugly-app/client`)
|
|
317
322
|
|
|
@@ -332,23 +337,23 @@ export const {
|
|
|
332
337
|
**Config:**
|
|
333
338
|
- `pages` (required) — the `PageRegistry` from `shared/pages.ts`.
|
|
334
339
|
- `allPages?` — the lazy route → element map (`PageMap<Pages>`). Prefer registering via `setAllPages()` from the browser entry when the app also server-renders — the Worker bundle has no code splitting, so a static import inlines every page (and its deps) into `worker.js`.
|
|
335
|
-
- `ssrPages
|
|
340
|
+
- `ssrPages?: SsrPageMap<Pages>` — `Partial<{ [K]: ComponentType<Params> }>` of statically-imported components for `ssr: true` routes. Used by both the Worker's `renderToString` and the client's first hydration render so the initial paint resolves synchronously and never mismatches the server output.
|
|
336
341
|
|
|
337
342
|
**Returns:**
|
|
338
343
|
|
|
339
|
-
- **`RouterProvider`** — props: `children`, `fallback?`, `isAuthenticated
|
|
340
|
-
- **`RouterView`** — renders the active page with animated transitions. Props: `durationMs?`, `easing
|
|
344
|
+
- **`RouterProvider`** — props: `children`, `fallback?`, `isAuthenticated?: () => boolean`, `initialUrl?: { pathname, search }` (required for SSR + hydration). Manages route state, browser history, and the popup layer. Runs the per-route auth check synchronously — apps cannot override the login fallback.
|
|
345
|
+
- **`RouterView`** — renders the active page with animated transitions. Props: `durationMs?`, `easing?: EasingFunction`, `transitionComponent?: React.ComponentType<RouterTransitionProps>` (replaces the default `ViewFlipper`), `renderPage?(state: RouterStateRaw) => ReactElement` (sync alternative to `allPages` loaders).
|
|
341
346
|
- **`useRouter()`** — returns `RouterContextValue<Pages>` (typed navigation + popup API). Throws if used outside `<RouterProvider>`.
|
|
342
347
|
- **`Link`** — typed SPA link bound to this router. Renders a real `<a>` (right-click / cmd-click / SEO keep working) but intercepts a plain left-click and routes through `push` / `replace`. Props: `to`, `params` (both type-checked against `pages`), `replace?`, `children`, plus common anchor attrs (`className`, `style`, `target`, `aria-label`, `data-id`, `onClick`).
|
|
343
348
|
- **`setAllPages(map)`** — register the lazy `PageMap<Pages>` after construction (typically from the browser entry, so the Worker's import graph stays free of every lazy page).
|
|
344
349
|
|
|
345
|
-
A standalone `Link` is also exported from `ugly-app/client` for code
|
|
346
|
-
|
|
347
|
-
|
|
350
|
+
A standalone `Link` is also exported from `ugly-app/client` for code that
|
|
351
|
+
can't easily reach the typed one; it accepts an optional `router` prop and
|
|
352
|
+
falls back to `<RouterProvider>` context.
|
|
348
353
|
|
|
349
|
-
**Never use a bare `<a href="/route">`** for internal navigation — it
|
|
350
|
-
|
|
351
|
-
|
|
354
|
+
**Never use a bare `<a href="/route">`** for internal navigation — it triggers
|
|
355
|
+
a full document reload (white flash + repaint). See the "client navigation"
|
|
356
|
+
rule in `CLAUDE.md`.
|
|
352
357
|
|
|
353
358
|
### Page map — `lazyPage` / `lazyPageLoader`
|
|
354
359
|
|
|
@@ -369,10 +374,9 @@ export const allPages = {
|
|
|
369
374
|
- **`lazyPageLoader(factory)`** — lazy-imports an async loader `(params) => Promise<ReactElement>`. Use when a route needs data fetching before render. The loader file is the chunk boundary, so it can statically import its page component.
|
|
370
375
|
|
|
371
376
|
Both wrappers recover from stale-deploy chunk 404s ("Failed to fetch
|
|
372
|
-
dynamically imported module"): on the first failure they trigger a
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
new chunk hashes.
|
|
377
|
+
dynamically imported module"): on the first failure they trigger a single
|
|
378
|
+
`window.location.reload()` (guarded by `sessionStorage` so a genuinely broken
|
|
379
|
+
chunk can't loop) to fetch fresh chunk hashes.
|
|
376
380
|
|
|
377
381
|
```ts
|
|
378
382
|
// pages/SlowPageLoader.tsx
|
|
@@ -402,15 +406,15 @@ replace('search', { q: 'hello' }); // → /search?q=hello
|
|
|
402
406
|
back(); // browser history back
|
|
403
407
|
```
|
|
404
408
|
|
|
405
|
-
Route names and params are fully typed against `pages`. `push` /
|
|
406
|
-
|
|
407
|
-
|
|
409
|
+
Route names and params are fully typed against `pages`. `push` / `replace`
|
|
410
|
+
no-op with a `console.error` when `buildUrl()` produces a URL that doesn't
|
|
411
|
+
match a registered route.
|
|
408
412
|
|
|
409
413
|
### Popups — `openPopup()`
|
|
410
414
|
|
|
411
|
-
`useRouter().openPopup()` is the canonical modal / sheet / menu API.
|
|
412
|
-
|
|
413
|
-
|
|
415
|
+
`useRouter().openPopup()` is the canonical modal / sheet / menu API. The
|
|
416
|
+
router owns the popup layer, drives a spring animation, and stacks popups
|
|
417
|
+
z-index-correctly above every page.
|
|
414
418
|
|
|
415
419
|
```tsx
|
|
416
420
|
const { openPopup } = useRouter();
|
|
@@ -435,20 +439,20 @@ handle.hide(); // dismiss programmatically — same as router.closePopup(handle.
|
|
|
435
439
|
- **`contextMenu`** — same as transient, intended for menus and pickers.
|
|
436
440
|
|
|
437
441
|
`renderLayer` receives `{ content, spring, hide }`: `spring` is a
|
|
438
|
-
`createAnimatedValue()` result driving 0 → 1; `hide` closes the popup.
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
+
`createAnimatedValue()` result driving 0 → 1; `hide` closes the popup. The
|
|
443
|
+
default layer animates open with `easeOut` (250 ms) and closed with `easeIn`
|
|
444
|
+
(200 ms). Popups render as siblings of the router's children (managed inside
|
|
445
|
+
`RouterProvider`), so they stack above every page.
|
|
442
446
|
|
|
443
447
|
### Scroll containers
|
|
444
448
|
|
|
445
449
|
`html, body, #root` are `overflow: hidden` — the document itself never
|
|
446
|
-
scrolls, so a page that just renders tall content is clipped. For pages
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
450
|
+
scrolls, so a page that just renders tall content is clipped. For pages that
|
|
451
|
+
own their scrolling (or render outside the normal authed chrome — e.g. a
|
|
452
|
+
public page special-cased before the auth gate), wrap the content in
|
|
453
|
+
`SimpleScrollView` (exported from `ugly-app/client`). For long / virtualized
|
|
454
|
+
lists with scroll-position persistence, use the richer `ScrollView`. See the
|
|
455
|
+
"page scrolling" rule in `CLAUDE.md`.
|
|
452
456
|
|
|
453
457
|
---
|
|
454
458
|
|
|
@@ -471,6 +475,9 @@ bootstrapApp({
|
|
|
471
475
|
});
|
|
472
476
|
```
|
|
473
477
|
|
|
478
|
+
`bootstrapApp(options): void` — returns nothing; it renders directly to the
|
|
479
|
+
DOM.
|
|
480
|
+
|
|
474
481
|
**`BootstrapAppOptions`:**
|
|
475
482
|
|
|
476
483
|
| Field | Description |
|
|
@@ -488,28 +495,28 @@ bootstrapApp({
|
|
|
488
495
|
| `silentSso?` | Apex-domain apps that use ugly.bot as their auth authority but don't share its cookie. When `true`, a logged-out boot attempts a top-level SSO redirect (once per tab) to adopt an existing ugly.bot session. Leave unset for `*.ugly.bot` subdomains and Mode B apps. |
|
|
489
496
|
| `testMode?` | Skip ugly.bot silent SSO and trust the auth cookie the fixture set. Only honored when `UGLY_APP_TEST_MODE=1`. |
|
|
490
497
|
|
|
491
|
-
`bootstrapApp` reads `window.__AUTH_TOKEN__` (injected by the server
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
498
|
+
`bootstrapApp` reads `window.__AUTH_TOKEN__` (injected by the server after
|
|
499
|
+
cookie verification). If absent, it renders unauthenticated immediately — the
|
|
500
|
+
router's per-route auth guard surfaces `<AuthRoot>` only when the user opens a
|
|
501
|
+
protected route. If the token is present, it connects the socket, mounts
|
|
502
|
+
`<AppProvider>`, and renders.
|
|
496
503
|
|
|
497
504
|
After render, a hidden iframe silently calls
|
|
498
|
-
`${UGLY_BOT_URL}/oauth/silent`: if it returns a fresh code, the cookie
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
505
|
+
`${UGLY_BOT_URL}/oauth/silent`: if it returns a fresh code, the cookie is
|
|
506
|
+
refreshed via `POST /auth/verify`; if the returned account differs from the
|
|
507
|
+
current session, the page reloads onto the live account (guarded once per
|
|
508
|
+
from→to pair to prevent loops). Any `?ugly_oauth_code=…` in the URL
|
|
509
|
+
(redirect-fallback OAuth code from ugly.bot) is redeemed at the top of
|
|
510
|
+
bootstrap before anything renders.
|
|
504
511
|
|
|
505
|
-
If `bootstrapApp` is loaded at `/auth/magic-link/verify` (Mode B), it
|
|
506
|
-
|
|
512
|
+
If `bootstrapApp` is loaded at `/auth/magic-link/verify` (Mode B), it renders
|
|
513
|
+
`<MagicLinkCallback>` instead of the regular app shell.
|
|
507
514
|
|
|
508
515
|
### `AppProvider` & `useApp()`
|
|
509
516
|
|
|
510
|
-
`bootstrapApp` mounts `<AppProvider>` automatically after socket
|
|
511
|
-
|
|
512
|
-
|
|
517
|
+
`bootstrapApp` mounts `<AppProvider>` automatically after socket connect. Use
|
|
518
|
+
`useApp()` inside any page to access the active user, socket, and app-scoped
|
|
519
|
+
services.
|
|
513
520
|
|
|
514
521
|
```ts
|
|
515
522
|
const {
|
|
@@ -517,28 +524,26 @@ const {
|
|
|
517
524
|
user, // UserBase doc
|
|
518
525
|
socket, // AppSocket — typed RPC client
|
|
519
526
|
uglyBotSocket, // UglyBotSocket | null — direct platform socket for STT/TTS
|
|
520
|
-
showPopup, // flat overlay layer (see note)
|
|
521
|
-
hidePopup,
|
|
522
|
-
hideAllPopups,
|
|
527
|
+
showPopup, // (content: ReactElement) => id — flat overlay layer (see note)
|
|
528
|
+
hidePopup, // (id: string) => void
|
|
529
|
+
hideAllPopups, // () => void
|
|
523
530
|
runAsync, // (label, async () => {…}, options?) — shows loading overlay
|
|
524
|
-
splashDone, // (step: string) — mark a splash-screen step complete
|
|
531
|
+
splashDone, // (step: string) => void — mark a splash-screen step complete
|
|
525
532
|
localizer, // (key, params?) => string — alias for useLocalizer()
|
|
526
533
|
} = useApp();
|
|
527
534
|
```
|
|
528
535
|
|
|
529
|
-
`useApp<TAsyncOptions>()` is generic in the async-options type so apps
|
|
530
|
-
|
|
531
|
-
`AppProvider` `cloneElement`s the overlay with
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
prop, and finally to identity.
|
|
536
|
+
`useApp<TAsyncOptions>()` is generic in the async-options type so apps can
|
|
537
|
+
pass a custom option through to a custom `loadingOverlay` element. When
|
|
538
|
+
`runAsync` is pending, `AppProvider` `cloneElement`s the overlay with
|
|
539
|
+
`{ label, asyncOptions }`. `useAppOptional()` returns `null` outside the
|
|
540
|
+
provider; `useLocalizer()` prefers `<StringsProvider>` data, falls back to
|
|
541
|
+
the `AppProvider` `localizer` prop, and finally to identity.
|
|
536
542
|
|
|
537
543
|
Two popup APIs coexist: `useRouter().openPopup()` (spring-animated,
|
|
538
|
-
dismissible, mode-aware — **the default choice**) and
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
router's.
|
|
544
|
+
dismissible, mode-aware — **the default choice**) and `useApp().showPopup()`
|
|
545
|
+
(a flat overlay layer returning a string id, for content that must sit
|
|
546
|
+
*outside* the router transition). Prefer the router's.
|
|
542
547
|
|
|
543
548
|
### Direct socket access
|
|
544
549
|
|
|
@@ -565,14 +570,14 @@ from `ugly-app/client`.
|
|
|
565
570
|
ugly-app uses HttpOnly cookies and server-side JWT injection — no
|
|
566
571
|
`localStorage`, no client-side token handling.
|
|
567
572
|
|
|
568
|
-
Two modes, picked from the `auth` block in the project's `.uglyapp`
|
|
569
|
-
config:
|
|
573
|
+
Two modes, picked from the `auth` block in the project's `.uglyapp` config:
|
|
570
574
|
|
|
571
575
|
- **Mode A — `mode: 'uglybot'`** (default when no `auth` block is present). Auth is delegated to ugly.bot OAuth. AI / email / push proxies bill the end user's ugly.bot credits.
|
|
572
576
|
- **Mode B — `mode: 'self'`**. The app issues its own sessions via magic-link email and/or Google OAuth. AI / email / push proxies bill the developer's ugly.bot account using the project's `AI_PROXY_TOKEN`.
|
|
573
577
|
|
|
574
|
-
`window.__UGLY_APP_AUTH_MODE__` is injected into every page so client
|
|
575
|
-
|
|
578
|
+
`window.__UGLY_APP_AUTH_MODE__` is injected into every page so client code
|
|
579
|
+
(incl. `<AuthRoot>`) can branch correctly. In Mode B with Google configured,
|
|
580
|
+
`window.__UGLY_APP_GOOGLE_CLIENT_ID__` is also injected.
|
|
576
581
|
|
|
577
582
|
### Mode A — ugly.bot OAuth (default)
|
|
578
583
|
|
|
@@ -584,9 +589,9 @@ code (incl. `<AuthRoot>`) can branch correctly.
|
|
|
584
589
|
|
|
585
590
|
### Mode B — self-issued sessions
|
|
586
591
|
|
|
587
|
-
When `.uglyapp` sets `auth.mode: 'self'`, `buildAuth()` wires the
|
|
588
|
-
|
|
589
|
-
|
|
592
|
+
When `.uglyapp` sets `auth.mode: 'self'`, `buildAuth()` wires the magic-link
|
|
593
|
+
provider as primary; if `providers.google.clientId` is configured it adds
|
|
594
|
+
Google as an extra provider on the same router.
|
|
590
595
|
|
|
591
596
|
- `<AuthRoot>` renders `<MagicLinkForm>` (plus the Google button when configured) instead of `<LoginPopup>`.
|
|
592
597
|
- Background ugly.bot silent SSO is a no-op.
|
|
@@ -596,9 +601,9 @@ configured it adds Google as an extra provider on the same router.
|
|
|
596
601
|
|
|
597
602
|
### Token-in-URL embed
|
|
598
603
|
|
|
599
|
-
Any GET request with `?token=<JWT>` will, if the token verifies, set
|
|
600
|
-
|
|
601
|
-
|
|
604
|
+
Any GET request with `?token=<JWT>` will, if the token verifies, set the
|
|
605
|
+
cookie and 302-redirect to the same URL without the token parameter — useful
|
|
606
|
+
for embedding any page in an iframe.
|
|
602
607
|
|
|
603
608
|
### Built-in auth routes
|
|
604
609
|
|
|
@@ -632,8 +637,8 @@ configurator.setAuth({
|
|
|
632
637
|
## Database — `TypedDB`
|
|
633
638
|
|
|
634
639
|
Access via `app.db`. All methods accept a `CollectionDef` (from
|
|
635
|
-
`defineCollections()`) or, on the `raw*` / `getQuery*` variants, a
|
|
636
|
-
|
|
640
|
+
`defineCollections()`) or, on the `raw*` / `getQuery*` variants, a plain
|
|
641
|
+
collection name string.
|
|
637
642
|
|
|
638
643
|
### Writing
|
|
639
644
|
|
|
@@ -658,10 +663,10 @@ await db.batch(async () => {
|
|
|
658
663
|
});
|
|
659
664
|
```
|
|
660
665
|
|
|
661
|
-
Supported update operators: `$inc`, `$addToSet`, `$pull`, `$unset`,
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
666
|
+
Supported update operators: `$inc`, `$addToSet`, `$pull`, `$unset`, `$set`.
|
|
667
|
+
All keys are dot-notation, fully typed against the collection's schema.
|
|
668
|
+
Partial updates go through optimistic concurrency to prevent lost updates
|
|
669
|
+
on concurrent writers.
|
|
665
670
|
|
|
666
671
|
### Reading
|
|
667
672
|
|
|
@@ -695,8 +700,8 @@ await db.deleteWhere(collections.note, { userId }); // typed bulk delete
|
|
|
695
700
|
await db.deleteQuery(collections.note, { userId }); // legacy untyped bulk delete
|
|
696
701
|
```
|
|
697
702
|
|
|
698
|
-
Pass `deleteHandlers` as the 5th argument to `createApp` to run
|
|
699
|
-
|
|
703
|
+
Pass `deleteHandlers` as the 5th argument to `createApp` to run per-collection
|
|
704
|
+
`onDelete` callbacks.
|
|
700
705
|
|
|
701
706
|
### Search
|
|
702
707
|
|
|
@@ -745,10 +750,9 @@ Imports available from `ugly-app`:
|
|
|
745
750
|
|
|
746
751
|
## AI providers
|
|
747
752
|
|
|
748
|
-
AI calls are proxied through ugly.bot — your app never holds a
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
billing.
|
|
753
|
+
AI calls are proxied through ugly.bot — your app never holds a provider key.
|
|
754
|
+
Pass `UGLY_BOT_TOKEN` in the environment and the framework handles routing,
|
|
755
|
+
balance tracking, retries, and per-user billing.
|
|
752
756
|
|
|
753
757
|
### Server-side text generation
|
|
754
758
|
|
|
@@ -770,9 +774,9 @@ const { message } = await uglyBotRequest<{ message: { content: string } }>('text
|
|
|
770
774
|
});
|
|
771
775
|
```
|
|
772
776
|
|
|
773
|
-
Available models are exposed via `textGenModels` / `textGenModelData`
|
|
774
|
-
|
|
775
|
-
|
|
777
|
+
Available models are exposed via `textGenModels` / `textGenModelData` from
|
|
778
|
+
`ugly-app` — the platform supports Claude, GPT, Gemini, Together, Groq,
|
|
779
|
+
Fireworks, Kimi, and Kie families.
|
|
776
780
|
|
|
777
781
|
### Server-side image generation
|
|
778
782
|
|
|
@@ -783,8 +787,8 @@ const imageGen = createImageGen(userId);
|
|
|
783
787
|
const url = await imageGen.generate('A red panda eating noodles', { model: 'flux_schnell' });
|
|
784
788
|
```
|
|
785
789
|
|
|
786
|
-
`imageGenModels` / `imageGenModelData` enumerate available models
|
|
787
|
-
|
|
790
|
+
`imageGenModels` / `imageGenModelData` enumerate available models (Together
|
|
791
|
+
FLUX, FAL, Google Imagen, Wavespeed, Kie Kolors).
|
|
788
792
|
|
|
789
793
|
### Embeddings
|
|
790
794
|
|
|
@@ -809,8 +813,8 @@ await search.enrichNews({ query: 'topic' });
|
|
|
809
813
|
|
|
810
814
|
### Client-side AI calls
|
|
811
815
|
|
|
812
|
-
Calls from React components go through the framework RPC pipeline — no
|
|
813
|
-
|
|
816
|
+
Calls from React components go through the framework RPC pipeline — no token
|
|
817
|
+
plumbing in the browser:
|
|
814
818
|
|
|
815
819
|
```ts
|
|
816
820
|
import { callTextGen, callJsonGen, callImageGen } from 'ugly-app/client';
|
|
@@ -822,9 +826,8 @@ const image = await callImageGen({ prompt: 'a corgi astronaut', model: 'flux_sch
|
|
|
822
826
|
|
|
823
827
|
### STT / TTS
|
|
824
828
|
|
|
825
|
-
Speech goes **directly** from the browser to ugly.bot — never proxied
|
|
826
|
-
|
|
827
|
-
`CLAUDE.md`).
|
|
829
|
+
Speech goes **directly** from the browser to ugly.bot — never proxied through
|
|
830
|
+
your app server (see the "STT/TTS routes to ugly.bot" rule in `CLAUDE.md`).
|
|
828
831
|
|
|
829
832
|
```ts
|
|
830
833
|
import { useSTT, useTTS, AudioPlayer, AudioRecorder } from 'ugly-app/client';
|
|
@@ -858,24 +861,23 @@ const { uploadUrl, resultUrl } = await storage.presignedPut('temp', key);
|
|
|
858
861
|
await storage.delete('public', destKey);
|
|
859
862
|
```
|
|
860
863
|
|
|
861
|
-
Client-side, use `socket.uploadFile(file, key)` — it requests a
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
864
|
+
Client-side, use `socket.uploadFile(file, key)` — it requests a presigned URL
|
|
865
|
+
via the built-in `uploadUrl` framework request and streams the upload. In
|
|
866
|
+
dev, uploads go through a same-origin `/_s3` proxy to avoid CORS with local
|
|
867
|
+
MinIO.
|
|
865
868
|
|
|
866
|
-
`STORAGE_KEY_PREFIX` (env) prefixes all keys — useful for
|
|
867
|
-
|
|
869
|
+
`STORAGE_KEY_PREFIX` (env) prefixes all keys — useful for per-environment
|
|
870
|
+
isolation.
|
|
868
871
|
|
|
869
|
-
On Cloudflare Workers, storage uses the R2 binding directly; presigned
|
|
870
|
-
|
|
871
|
-
endpoint).
|
|
872
|
+
On Cloudflare Workers, storage uses the R2 binding directly; presigned PUTs
|
|
873
|
+
are not exposed (browser uploads must go through a Worker endpoint).
|
|
872
874
|
|
|
873
875
|
### Static assets — `static/`
|
|
874
876
|
|
|
875
877
|
Large, rarely-changing files (3D models, textures, audio, fonts) go in the
|
|
876
878
|
project-root `static/` folder. `ugly-app build:static` hashes them and
|
|
877
|
-
generates `shared/StaticAssets.ts`; publish uploads only the files whose
|
|
878
|
-
changed.
|
|
879
|
+
generates `shared/StaticAssets.ts`; publish uploads only the files whose
|
|
880
|
+
bytes changed.
|
|
879
881
|
|
|
880
882
|
```ts
|
|
881
883
|
import { staticUrl } from '../shared/StaticAssets'
|
|
@@ -885,15 +887,14 @@ const url = staticUrl('models/char2.ugm')
|
|
|
885
887
|
```
|
|
886
888
|
|
|
887
889
|
The bucket gets its own custom domain, so **Cloudflare's CDN serves these
|
|
888
|
-
directly** — no Worker invocation per request, and R2 answers `Range`
|
|
889
|
-
for progressive loaders.
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
rule, without which COEP `require-corp` would silently block them.
|
|
890
|
+
directly** — no Worker invocation per request, and R2 answers `Range`
|
|
891
|
+
natively for progressive loaders. Publish also sets the bucket CORS policy
|
|
892
|
+
and a `Cross-Origin-Resource-Policy: cross-origin` response rule, without
|
|
893
|
+
which COEP `require-corp` would silently block them.
|
|
893
894
|
|
|
894
895
|
Unlike `/{buildId}/assets/*`, these URLs do not change when you deploy, so
|
|
895
|
-
returning users do not re-download unchanged files. Assets that no build
|
|
896
|
-
the last `retentionDays` (default 7) references are deleted from R2
|
|
896
|
+
returning users do not re-download unchanged files. Assets that no build
|
|
897
|
+
from the last `retentionDays` (default 7) references are deleted from R2
|
|
897
898
|
automatically, along with expired `builds/` prefixes.
|
|
898
899
|
|
|
899
900
|
Requires a provisioned app domain — publish fails rather than emitting URLs
|
|
@@ -903,8 +904,8 @@ nothing serves. Configure in `.uglyapp`:
|
|
|
903
904
|
"staticAssets": { "dir": "static", "retentionDays": 7 }
|
|
904
905
|
```
|
|
905
906
|
|
|
906
|
-
Dev serves the same files off disk at same-origin, so a newly added asset
|
|
907
|
-
before it has ever been published.
|
|
907
|
+
Dev serves the same files off disk at same-origin, so a newly added asset
|
|
908
|
+
works before it has ever been published.
|
|
908
909
|
|
|
909
910
|
### `hostBundle` — serve the vite bundle from the CDN too
|
|
910
911
|
|
|
@@ -919,19 +920,20 @@ prefixed, a byte-identical chunk keeps its URL across deploys — so returning
|
|
|
919
920
|
users re-download only what actually changed, and each deploy uploads a
|
|
920
921
|
handful of KB instead of the whole bundle.
|
|
921
922
|
|
|
922
|
-
The first deploy only provisions; the bundle moves to the CDN on the next
|
|
923
|
-
That is deliberate — a single pass would point the bundle at a hostname
|
|
924
|
-
TLS certificate may not have issued yet.
|
|
925
|
-
|
|
926
|
-
**Workers are handled for you, but know why.** The bundle is then
|
|
927
|
-
and `new Worker(url)` *rejects a cross-origin script URL
|
|
928
|
-
structural, and no CORS or CORP header lifts it.
|
|
929
|
-
shim that routes such URLs through a same-origin
|
|
930
|
-
script, so `new Worker(new URL('./x.worker.ts',
|
|
931
|
-
working. `SharedWorker` is **not** shimmed: every
|
|
932
|
-
same trick would give each caller a private
|
|
933
|
-
service workers by root-absolute path
|
|
934
|
-
against the document, so those stay
|
|
923
|
+
The first deploy only provisions; the bundle moves to the CDN on the next
|
|
924
|
+
one. That is deliberate — a single pass would point the bundle at a hostname
|
|
925
|
+
whose TLS certificate may not have issued yet.
|
|
926
|
+
|
|
927
|
+
**Workers are handled for you, but know why.** The bundle is then
|
|
928
|
+
cross-origin, and `new Worker(url)` *rejects a cross-origin script URL
|
|
929
|
+
outright* — that is structural, and no CORS or CORP header lifts it.
|
|
930
|
+
`bootstrapApp` installs a shim that routes such URLs through a same-origin
|
|
931
|
+
`blob:` importing the real script, so `new Worker(new URL('./x.worker.ts',
|
|
932
|
+
import.meta.url))` keeps working. `SharedWorker` is **not** shimmed: every
|
|
933
|
+
blob URL is unique, so the same trick would give each caller a private
|
|
934
|
+
worker and break sharing. Register service workers by root-absolute path
|
|
935
|
+
(`/sw.js`) — `register()` resolves against the document, so those stay
|
|
936
|
+
same-origin.
|
|
935
937
|
|
|
936
938
|
---
|
|
937
939
|
|
|
@@ -963,16 +965,15 @@ const cronHandlers: WorkerHandlers<typeof cronTasks> = {
|
|
|
963
965
|
configurator.setWorkers(cronTasks, cronHandlers);
|
|
964
966
|
```
|
|
965
967
|
|
|
966
|
-
Each worker can have `inputSchema`, `outputSchema`, `schedule`,
|
|
967
|
-
`
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
968
|
+
Each worker can have `inputSchema`, `outputSchema`, `schedule`, `timeout`,
|
|
969
|
+
`description`. Workers without a schedule are still invocable via
|
|
970
|
+
`POST /_workers/run` (auth: localhost in dev, `Authorization: Bearer $CRON_SECRET`
|
|
971
|
+
in prod). Scheduled workers also appear in `/_cron/manifest` for the deploy
|
|
972
|
+
orchestrator.
|
|
971
973
|
|
|
972
|
-
On the Workers adapter, scheduled workers dispatch through Cloudflare
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
queues only).
|
|
974
|
+
On the Workers adapter, scheduled workers dispatch through Cloudflare Cron
|
|
975
|
+
Triggers and durable queueing goes through Cloudflare Queues. On the Node
|
|
976
|
+
adapter, `enqueueWorker` runs the handler inline (in-process queues only).
|
|
976
977
|
|
|
977
978
|
---
|
|
978
979
|
|
|
@@ -987,9 +988,9 @@ configurator.setStrings({
|
|
|
987
988
|
});
|
|
988
989
|
```
|
|
989
990
|
|
|
990
|
-
The framework injects `window.__LANG__`, `window.__STRINGS_VERSION__`,
|
|
991
|
-
|
|
992
|
-
|
|
991
|
+
The framework injects `window.__LANG__`, `window.__STRINGS_VERSION__`, and
|
|
992
|
+
`window.__CRITICAL_STRINGS__` into SSR HTML. Use `useLocalizer()` /
|
|
993
|
+
`useStrings()` / `useLang()` / `useChangeLanguage()` on the client.
|
|
993
994
|
|
|
994
995
|
---
|
|
995
996
|
|
|
@@ -1014,10 +1015,9 @@ export const experiments: Experiment[] = [
|
|
|
1014
1015
|
configurator.setExperiments(experiments);
|
|
1015
1016
|
```
|
|
1016
1017
|
|
|
1017
|
-
Bucketing is deterministic: `hash(experimentId + userId)` (or
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
branch assignments.
|
|
1018
|
+
Bucketing is deterministic: `hash(experimentId + userId)` (or `sessionId`
|
|
1019
|
+
for unauthenticated users). The framework's `initSession` / `captureEvent`
|
|
1020
|
+
requests automatically tag events with the user's branch assignments.
|
|
1021
1021
|
|
|
1022
1022
|
---
|
|
1023
1023
|
|
|
@@ -1043,17 +1043,15 @@ branch assignments.
|
|
|
1043
1043
|
|
|
1044
1044
|
## Two-adapter architecture
|
|
1045
1045
|
|
|
1046
|
-
The same developer source compiles for two runtimes via
|
|
1047
|
-
`src/server/adapter/`:
|
|
1046
|
+
The same developer source compiles for two runtimes via `src/server/adapter/`:
|
|
1048
1047
|
|
|
1049
1048
|
- **Adapter A — Node + TCP** (`src/server/adapter/node/`): default for `npm run dev` and any non-Workers deploy. Wraps `pg.Pool`, `nats.js`, AWS S3 SDK.
|
|
1050
1049
|
- **Adapter B — Cloudflare Workers** (`src/server/adapter/workers/`): used when the Studio publish flow deploys to Cloudflare. Hono router + Durable Objects (one `CollectionDO` per project-collection, plus a `SessionDO` per user WS) + `@neondatabase/serverless` HTTP driver + R2 binding + Cloudflare Cron Triggers + Cloudflare Queues.
|
|
1051
1050
|
|
|
1052
|
-
Developer-facing APIs (`createTypedDB`, `subscribeDoc`,
|
|
1053
|
-
`
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
the Worker can talk to a real Postgres.
|
|
1051
|
+
Developer-facing APIs (`createTypedDB`, `subscribeDoc`, `createStorageClient`,
|
|
1052
|
+
`setCronTasks`, `setWorkers`) don't change between adapters. Local Workers dev
|
|
1053
|
+
boots via `npm run dev:workers`, which starts a small Node HTTP proxy speaking
|
|
1054
|
+
Neon's wire format so the Worker can talk to a real Postgres.
|
|
1057
1055
|
|
|
1058
1056
|
---
|
|
1059
1057
|
|
|
@@ -1108,8 +1106,8 @@ Browser-visible variables must be prefixed `VITE_` and consumed via
|
|
|
1108
1106
|
| `ugly-app feedback:dev` / `feedback:prod` | Query user feedback. |
|
|
1109
1107
|
| `ugly-app feedback:submit` / `feedback:resolve` | Manage feedback (run with `--help` for flags). |
|
|
1110
1108
|
|
|
1111
|
-
Inside a scaffolded project, the same commands are available via `npm
|
|
1112
|
-
|
|
1109
|
+
Inside a scaffolded project, the same commands are available via `npm run …`
|
|
1110
|
+
scripts — see `templates/CLAUDE.md`.
|
|
1113
1111
|
|
|
1114
1112
|
---
|
|
1115
1113
|
|