@teable/create-app 1.0.2 → 1.0.4

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.
@@ -2,9 +2,10 @@
2
2
 
3
3
  This repository is one Teable app: a Drizzle schema plus read, write and task
4
4
  methods, written with `@teable/app`. Teable runs it on Cloudflare in a Durable
5
- Object with its own SQLite database, and makes an HTTP API and MCP tools from
6
- its methods. Change it here, run the checks, and publish it with
7
- `teable-next publish`.
5
+ Object with its own SQLite database, makes an HTTP API and MCP tools from its
6
+ methods, and serves its pages at the app's own address,
7
+ `https://<appId in lower case>.teable.uk`. Change it here, run the checks,
8
+ and publish it with `teable-next publish`.
8
9
 
9
10
  It starts as an example (a `notes` table, `listNotes`, `addNote`, a page, a
10
11
  test at each level) that shows the whole shape. Replace it with the app the
@@ -12,38 +13,47 @@ user needs.
12
13
 
13
14
  ## Layout
14
15
 
15
- | Path | What it is |
16
- | ---------------------- | ------------------------------------------------------------------------------------------------------------------------- |
17
- | `src/server/schema.ts` | Tables, with their rules (Drizzle). drizzle-kit loads it in Node: it imports only `drizzle-orm` and `@teable/app/schema`. |
18
- | `src/server/index.ts` | Methods. `export const App = app.define({ ... })` names them; Teable runs this module. |
19
- | `drizzle/` | Migrations written by `bun run db:generate`, and `migrations.js`, which lists them. |
20
- | `src/web/` | Pages: React, TanStack Router and Query, shadcn's components. `app.ts` holds the client and the query cache. |
21
- | `src/components/ui/` | shadcn's components on UI SDK, as `bunx shadcn add <name>` writes them (`components.json`); the app's own. |
22
- | `test/` | Method tests. They run in workerd, against a real SQLite database. |
23
- | `src/**/*.test.tsx` | Page tests, in jsdom, against a stubbed client. |
24
- | `teable.json` | `appId`: which app on Teable this is. `teable-next` and the pages read it; leave it as it is. |
25
- | `dist/` | What `bun run build` writes: `server.js`, which publishing uploads, and `pages/`. Not committed. |
16
+ | Path | What it is |
17
+ | ---------------------- | -------------------------------------------------------------------------------------------------------------------------- |
18
+ | `src/server/schema.ts` | Tables, with their rules (Drizzle). drizzle-kit loads it in Node: it imports only `drizzle-orm` and `@teable/app/schema`. |
19
+ | `src/server/index.ts` | Methods. `export const App = app.define({ ... })` names them; Teable runs this module. |
20
+ | `drizzle/` | Migrations written by `bun run db:generate`, and `migrations.js`, which lists them. |
21
+ | `src/web/` | Pages: React, TanStack Router and Query, shadcn's components. `app.ts` holds the client and the query cache. |
22
+ | `src/worker/index.ts` | Optional: the app's own Worker, for HTTP the pages are not (webhooks, feeds, pages rendered on the server). |
23
+ | `public/` | Files served as they are; `_headers`, `_redirects` and `_routes.json` here are settings for the pages, not files. |
24
+ | `src/components/ui/` | shadcn's components on UI SDK, as `bunx shadcn add <name>` writes them (`components.json`); the app's own. |
25
+ | `test/` | Method tests. They run in workerd, against a real SQLite database. |
26
+ | `src/**/*.test.tsx` | Page tests, in jsdom, against a stubbed client. |
27
+ | `teable.json` | `appId`: which app on Teable this is. `teable-next` and the pages read it; leave it as it is. |
28
+ | `dist/` | What `bun run build` writes: `server.js`, `worker.js` (with `src/worker`) and `pages/`, which publishing deploys together. |
29
+ | `.teable/` | `bun run dev`'s local database and files. Not committed. |
26
30
 
27
31
  ## Commands
28
32
 
29
33
  ```sh
30
34
  bun install
35
+ bun run dev # the app on your machine: pages, methods on a local database, sign-in as anyone
31
36
  bun run check # typecheck, tests, migration checks; before every push
32
- bun run build # dist/server.js (what publish uploads) and dist/pages/
37
+ bun run build # dist/server.js, dist/worker.js (with src/worker) and dist/pages/
33
38
  bun run db:generate --name <change> # after changing schema.ts: the next migration
34
39
  bun run test [file] [-t <name>] # tests only, or some of them
35
40
  teable-next pull # before you start: the latest from Teable
36
41
  teable-next push -m "<what changed>" # commit, and save the source to Teable
37
- teable-next publish # check, build and deploy dist/server.js, with its commit, as the next version
42
+ teable-next publish # check, build and deploy dist/ (methods and pages), with its commit, as the next version
38
43
  teable-next versions # published versions, newest first: when, by whom, which commit
39
44
  teable-next rollback --version <n> # deploy version n's code again, as the next version
45
+ teable-next rename "<name>" # name the project after the app, if it has no name yet
40
46
  ```
41
47
 
42
48
  `teable-next <command> --help` lists every option; without the CLI
43
- installed, `npx @teable/next-cli <command>` runs it. There is no local server
44
- (`dev`): the runtime that hosts apps is not published. Tests are the loop:
45
- methods against a real database, pages against a stubbed client. Publish to
46
- see the app running.
49
+ installed, `npx @teable/next-cli <command>` runs it.
50
+
51
+ `bun run dev` stands in for Teable on your machine (`teable()` in
52
+ `vite.config.ts`): Vite serves the pages, the methods run in workerd on a
53
+ local database in `.teable/` and run again whenever `src/server` changes, and
54
+ the app's Worker runs too. Opening a page signs you in as whoever you pick:
55
+ an owner, an editor, a viewer, someone outside the app's space, or nobody.
56
+ Tests are still the loop for methods and pages; dev is for seeing it work.
47
57
 
48
58
  ## The rules, and why
49
59
 
@@ -95,6 +105,10 @@ Also:
95
105
  Keep each call small, and page through long lists (`limit`).
96
106
  - Teable has no secrets store for apps yet. Never put keys or tokens in code
97
107
  or git; ask the user.
108
+ - Pages are for the members of the app's space unless the app says
109
+ otherwise (`pages: { access }` in `createApp`): a visitor who is not one
110
+ is sent to sign in with Teable before any page loads. Data still comes only
111
+ from methods, each under its own `access`.
98
112
 
99
113
  ## How to
100
114
 
@@ -177,6 +191,61 @@ export const App = app.define({ listInvoices, markPaid });
177
191
  5. Test it next to it (`<page>.test.tsx`), with a client whose `fetch` the
178
192
  test answers, as `notes.test.tsx` does.
179
193
 
194
+ ### Sign people in
195
+
196
+ Pages are served at the app's own address, and people sign in there with
197
+ their Teable account; members of the app's space get their role in it.
198
+
199
+ - `createApp({ pages: { access } })` says who may open the pages: a role
200
+ (`viewer` by default: the space's members) or `"public"` (anyone). Below
201
+ it, a visitor's page loads only after they sign in.
202
+ - `client.session()` says who is signed in (`caller`, as methods see them);
203
+ `client.signIn()` signs in and comes back to the page; `client.signOut()`
204
+ signs out. A call that answers `UNAUTHENTICATED` after hours means the
205
+ session ended (12 hours): offer `client.signIn()`.
206
+ - Public pages call `public` methods for visitors who are signed out.
207
+ - Nothing on the page holds the session: the browser keeps it, for this app
208
+ only. The app's own code never sees it, nor any Teable token.
209
+
210
+ ### Handle HTTP: the app's Worker
211
+
212
+ For HTTP that is not a page (a webhook, a feed, a page rendered on the
213
+ server), write `src/worker/index.ts`; `bun run build` makes `dist/worker.js`
214
+ and publishing deploys it with the pages.
215
+
216
+ ```ts
217
+ import { appOf, type WorkerEnv } from "@teable/app/worker";
218
+ import type * as server from "../server";
219
+
220
+ export default {
221
+ async fetch(request, env, ctx) {
222
+ const app = appOf<typeof server>(ctx);
223
+ const url = new URL(request.url);
224
+ if (url.pathname === "/hooks/paid" && request.method === "POST") {
225
+ // Check the sender's signature first: the app acts as itself here.
226
+ await app.asApp.call("markPaid", await request.json());
227
+ return new Response(null, { status: 204 });
228
+ }
229
+ return env.ASSETS.fetch(request);
230
+ },
231
+ } satisfies ExportedHandler<WorkerEnv>;
232
+ ```
233
+
234
+ - The pages' files are served before it runs. It gets what no file answers
235
+ and is not a page's navigation (webhooks, fetches), and the paths
236
+ `public/_routes.json` lists (`{ "include": ["/report/*"] }`), before any
237
+ file. `env.ASSETS.fetch(request)` serves the pages.
238
+ - `app.caller` is who sent the request: the signed-in person for the app's
239
+ own pages' requests and for links followed to it, anonymous otherwise.
240
+ `app.asCaller.call(...)` calls a method as them, under its access;
241
+ `app.asApp.call(...)` calls one as the app itself, `internal` ones too.
242
+ Failures throw `MethodError`, as in pages. `app.files` is the `files`
243
+ capability, when declared.
244
+ - It keeps no data of its own: the app's data is reached through methods.
245
+ Never change data on a GET. It has the network (`fetch`), unmetered;
246
+ long or scheduled work stays in tasks.
247
+ - It imports the server code with `import type` only.
248
+
180
249
  ### Add a task or a schedule
181
250
 
182
251
  ```ts
@@ -264,6 +333,8 @@ the migrations.
264
333
  | `RATE_LIMITED` (HTTP 429) | Wait as long as `Retry-After` says, then try again. |
265
334
  | `Deploy rejected: built for app protocol N; this runtime speaks M` (publish) | `bun add @teable/app@latest`, then check, build and publish again. |
266
335
  | `Deploy rejected` with `Migration ... failed: ...` (publish) | The migration does not fit the live rows (a NOT NULL column without a default, a CHECK some rows break): make it handle them (a default, an `UPDATE` first). A rejected migration never ran: edit it. |
336
+ | `Cloudflare refused the pages: ...` (publish) | A setting among the pages (`_headers`, `_redirects`, `_routes.json`) or the Worker is wrong: the message says which. Nothing was deployed. |
337
+ | `teable: not started: ...` (`bun run dev`) | The server code did not build or start (the same reasons as a publish's). Fix it; dev runs it again when it changes. |
267
338
 
268
339
  ## Publishing
269
340
 
@@ -276,13 +347,21 @@ user gets the change, and a publish that fails changes nothing. It takes the
276
347
  on a copy of the live data first, running its migrations, then on the live
277
348
  data, and makes it live only if both work; open pages read everything again.
278
349
  Every version records when it was published, by whom, and from which commit.
279
- Then tell the user what changed. The methods are live at once through the API
280
- (`/api/v4/apps/<appId>/methods/<name>`, described at `.../openapi.json`), MCP
281
- (`/api/v4/apps/<appId>/mcp`) and the app on Teable; Teable does not serve
282
- `dist/pages` yet.
283
-
284
- `teable-next rollback` deploys an earlier version's code again, as the next
285
- version. It cannot go back past a migration: the live database has run it,
350
+ Then tell the user what changed. The pages are live at the app's own address,
351
+ `https://<appId in lower case>.teable.uk` (publish prints it), with the
352
+ methods through the API (`/api/v4/apps/<appId>/methods/<name>`, described at
353
+ `.../openapi.json`) and MCP (`/api/v4/apps/<appId>/mcp`); the builder on
354
+ Teable previews the pages. A version is the server code and the pages
355
+ together: a rollback brings back both.
356
+
357
+ A project nobody named has no name: `teable-next publish` prints its
358
+ `projectName` as null (so do `init` and `clone`), and Teable lists it as
359
+ untitled. Once you know what the app is, name it after the app, in the
360
+ user's language: `teable-next rename "<name>"`. Never rename a project that
361
+ has a name unless the user asks.
362
+
363
+ `teable-next rollback` deploys an earlier version's code and pages again, as
364
+ the next version. It cannot go back past a migration: the live database has run it,
286
365
  and code without it does not start, so the rollback is refused (`CONFLICT`);
287
366
  undo a schema change with a new migration. A rollback changes only what
288
367
  runs, not this repository: fix or revert the code here before publishing
@@ -1,6 +1,7 @@
1
1
  node_modules/
2
2
  dist/
3
3
  .wrangler/
4
+ .teable/
4
5
  .dev.vars
5
6
  .env
6
7
  .env.*
@@ -5,6 +5,7 @@
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "check": "bun run typecheck && bun run test && drizzle-kit check",
8
+ "dev": "vite",
8
9
  "build": "teable-app build && vite build",
9
10
  "db:generate": "drizzle-kit generate",
10
11
  "typecheck": "tsc -p . && tsc -p src/server",
@@ -14,7 +15,7 @@
14
15
  "@fontsource-variable/inter": "5.3.0",
15
16
  "@tanstack/react-query": "5.108.4",
16
17
  "@tanstack/react-router": "1.170.46",
17
- "@teable/app": "^5.0.2",
18
+ "@teable/app": "^6.0.1",
18
19
  "@ui-sdk/core": "0.1.0-beta.24",
19
20
  "@ui-sdk/react": "0.1.0-beta.24",
20
21
  "class-variance-authority": "0.7.1",
@@ -7,7 +7,8 @@
7
7
  * it at runtime (hiding closed parts); tw-animate-css (enter and exit
8
8
  * animations); shadcn/tailwind.css (the data-open: style variants that popups
9
9
  * use); the font; and the tokens. Registry components style themselves with
10
- * these.
10
+ * these. The `--choice-*` tokens are the ones the Teable grid's registry item
11
+ * adds (`cssVars`): the old Teable's single-select colours, light and dark.
11
12
  *
12
13
  * From this comment to the end, every Teable template's stylesheet and the
13
14
  * builder's are identical, so the builder looks like the apps it builds.
@@ -54,6 +55,17 @@
54
55
  --sidebar-accent-foreground: oklch(0.205 0 0);
55
56
  --sidebar-border: oklch(0.922 0 0);
56
57
  --sidebar-ring: oklch(0.708 0 0);
58
+ --choice-blue: rgb(194 212 255);
59
+ --choice-green: rgb(149 229 153);
60
+ --choice-orange: rgb(254 196 139);
61
+ --choice-purple: rgb(220 201 253);
62
+ --choice-red: rgb(253 198 196);
63
+ --choice-teal: rgb(111 232 216);
64
+ --choice-yellow: rgb(252 223 126);
65
+ --choice-pink: rgb(248 196 225);
66
+ --choice-cyan: rgb(151 220 252);
67
+ --choice-gray: rgb(229 230 235);
68
+ --choice-foreground: rgb(24 24 27);
57
69
  }
58
70
 
59
71
  .dark {
@@ -88,6 +100,17 @@
88
100
  --sidebar-accent-foreground: oklch(0.985 0 0);
89
101
  --sidebar-border: oklch(1 0 0 / 10%);
90
102
  --sidebar-ring: oklch(0.556 0 0);
103
+ --choice-blue: rgb(37 65 131);
104
+ --choice-green: rgb(30 78 38);
105
+ --choice-orange: rgb(106 54 16);
106
+ --choice-purple: rgb(80 53 128);
107
+ --choice-red: rgb(121 35 33);
108
+ --choice-teal: rgb(16 76 70);
109
+ --choice-yellow: rgb(96 71 15);
110
+ --choice-pink: rgb(110 40 81);
111
+ --choice-cyan: rgb(14 73 99);
112
+ --choice-gray: rgb(77 82 89);
113
+ --choice-foreground: rgb(255 255 255);
91
114
  }
92
115
 
93
116
  @theme inline {
@@ -131,6 +154,17 @@
131
154
  --color-sidebar-ring: var(--sidebar-ring);
132
155
  --font-heading: var(--font-sans);
133
156
  --font-sans: "Inter Variable", sans-serif;
157
+ --color-choice-blue: var(--choice-blue);
158
+ --color-choice-green: var(--choice-green);
159
+ --color-choice-orange: var(--choice-orange);
160
+ --color-choice-purple: var(--choice-purple);
161
+ --color-choice-red: var(--choice-red);
162
+ --color-choice-teal: var(--choice-teal);
163
+ --color-choice-yellow: var(--choice-yellow);
164
+ --color-choice-pink: var(--choice-pink);
165
+ --color-choice-cyan: var(--choice-cyan);
166
+ --color-choice-gray: var(--choice-gray);
167
+ --color-choice-foreground: var(--choice-foreground);
134
168
  }
135
169
 
136
170
  @layer base {
@@ -1,22 +1,19 @@
1
- import { readFileSync } from "node:fs";
2
1
  import { cloudflareTest } from "@cloudflare/vitest-plugin";
3
2
  import tailwindcss from "@tailwindcss/vite";
4
- import { sqlAsText } from "@teable/app/build";
3
+ import { sqlAsText, teable } from "@teable/app/build";
5
4
  import { APP_COMPATIBILITY_DATE } from "@teable/app/protocol";
6
5
  import react from "@vitejs/plugin-react";
7
6
  import { defineConfig } from "vitest/config";
8
7
 
9
- /** Which Teable app this is, as teable.json says; pages call its methods. */
10
- const { appId = "" } = JSON.parse(
11
- readFileSync(new URL("./teable.json", import.meta.url), "utf8"),
12
- ) as { appId?: string };
13
-
14
- /** The app's pages, and its tests. */
8
+ /**
9
+ * The app's pages, and its tests. `teable()` gives the pages the app's id
10
+ * (teable.json), and in `bun run dev` stands in for Teable: the app's
11
+ * methods run here on a local database, and you sign in as whoever you pick.
12
+ */
15
13
  export default defineConfig({
16
- plugins: [react(), tailwindcss()],
14
+ plugins: [react(), tailwindcss(), teable()],
17
15
  // `@/` is src/, as tsconfig.json's paths say.
18
16
  resolve: { tsconfigPaths: true },
19
- define: { "import.meta.env.VITE_TEABLE_APP_ID": JSON.stringify(appId) },
20
17
  build: { outDir: "dist/pages" },
21
18
  test: {
22
19
  projects: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teable/create-app",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Start a Teable app: a blank app, the instructions agents read in it, and the teable-next-app Agent Skill",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -8,9 +8,11 @@ description: Build, change, test and publish a Teable app (teable-next) — a Dr
8
8
  A Teable app is a repository: a Drizzle schema (`src/server/schema.ts`), read,
9
9
  write and task methods (`src/server/index.ts`, with `@teable/app`), migrations
10
10
  (`drizzle/`), pages (`src/web/`) and tests. Teable runs it on Cloudflare, one
11
- Durable Object with its own SQLite database per app, and makes an HTTP API
12
- and MCP tools from its methods. You build it in a shell, like any project,
13
- and publish it with `teable-next`, the CLI for Teable apps.
11
+ Durable Object with its own SQLite database per app, makes an HTTP API and
12
+ MCP tools from its methods, and serves its pages at the app's own address
13
+ (`https://<appId in lower case>.teable.uk`), where people sign in with their
14
+ Teable account. You build it in a shell, like any project, and publish it
15
+ with `teable-next`, the CLI for Teable apps.
14
16
 
15
17
  ## When to use it
16
18
 
@@ -47,7 +49,9 @@ instructions, current for the SDK the app uses.
47
49
  1. Edit: schema, methods, migrations, pages, tests.
48
50
  2. `bun run check`: typecheck, tests (methods in workerd against a real
49
51
  database, pages in jsdom), migration checks.
50
- 3. `bun run build`: `dist/server.js`, which publishing uploads.
52
+ 3. `bun run build`: `dist/server.js`, `dist/pages/` (and `dist/worker.js`
53
+ with `src/worker`), which publishing deploys together. `bun run dev`
54
+ shows the app on your machine, its methods on a local database.
51
55
  4. `teable-next push -m "<what changed>"`: commit and save the source to the
52
56
  app's repository on Teable.
53
57
  5. `teable-next publish`: the check and the build run again, then Teable
@@ -55,14 +59,19 @@ instructions, current for the SDK the app uses.
55
59
  live data, and makes it live only if both work. Publish as soon as the
56
60
  checks pass; do not wait to be asked. It takes the `creator` or `owner`
57
61
  role in the app's space. Then tell the user what changed, with the URLs
58
- it prints.
62
+ it prints: the pages' address first.
63
+
64
+ A project nobody named has no name: `init`, `clone` and `publish` print its
65
+ `projectName` as null, and Teable lists it as untitled. Once you know what
66
+ the app is, name it after the app, in the user's language:
67
+ `teable-next rename "<name>"`. Never rename a project that has a name unless
68
+ the user asks.
59
69
 
60
70
  `teable-next versions` lists published versions, with who published each and
61
71
  from which commit. `teable-next rollback --version <n>` deploys an earlier
62
- version's code again, as the next version; it is refused past a migration
63
- (roll forward instead), and it leaves the repository as it is, so fix or
64
- revert the code before the next publish. There is no local server: tests are
65
- the loop, publishing shows the running app.
72
+ version's code and pages again, as the next version; it is refused past a
73
+ migration (roll forward instead), and it leaves the repository as it is, so
74
+ fix or revert the code before the next publish.
66
75
 
67
76
  ## The rules
68
77
 
@@ -90,6 +99,8 @@ Each is explained, with why, in the app's `AGENTS.md` ("The rules, and why"):
90
99
  | Add a page | How to: Add a page |
91
100
  | Run work later, on a schedule, or against a service | How to: Add a task... |
92
101
  | Store files, call other services | How to: Use a capability |
102
+ | Say who may open the pages, sign people in | How to: Sign people in |
103
+ | Take a webhook, render a page on the server | How to: Handle HTTP... |
93
104
  | Write tests | How to: Test |
94
105
  | Understand an error from a check, a test or a publish | When something fails |
95
106
  | Know what publishing does | Publishing |