@teable/create-app 1.0.2 → 1.0.3

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,46 @@ 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
40
45
  ```
41
46
 
42
47
  `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.
48
+ installed, `npx @teable/next-cli <command>` runs it.
49
+
50
+ `bun run dev` stands in for Teable on your machine (`teable()` in
51
+ `vite.config.ts`): Vite serves the pages, the methods run in workerd on a
52
+ local database in `.teable/` and run again whenever `src/server` changes, and
53
+ the app's Worker runs too. Opening a page signs you in as whoever you pick:
54
+ an owner, an editor, a viewer, someone outside the app's space, or nobody.
55
+ Tests are still the loop for methods and pages; dev is for seeing it work.
47
56
 
48
57
  ## The rules, and why
49
58
 
@@ -95,6 +104,10 @@ Also:
95
104
  Keep each call small, and page through long lists (`limit`).
96
105
  - Teable has no secrets store for apps yet. Never put keys or tokens in code
97
106
  or git; ask the user.
107
+ - Pages are for the members of the app's space unless the app says
108
+ otherwise (`pages: { access }` in `createApp`): a visitor who is not one
109
+ is sent to sign in with Teable before any page loads. Data still comes only
110
+ from methods, each under its own `access`.
98
111
 
99
112
  ## How to
100
113
 
@@ -177,6 +190,61 @@ export const App = app.define({ listInvoices, markPaid });
177
190
  5. Test it next to it (`<page>.test.tsx`), with a client whose `fetch` the
178
191
  test answers, as `notes.test.tsx` does.
179
192
 
193
+ ### Sign people in
194
+
195
+ Pages are served at the app's own address, and people sign in there with
196
+ their Teable account; members of the app's space get their role in it.
197
+
198
+ - `createApp({ pages: { access } })` says who may open the pages: a role
199
+ (`viewer` by default: the space's members) or `"public"` (anyone). Below
200
+ it, a visitor's page loads only after they sign in.
201
+ - `client.session()` says who is signed in (`caller`, as methods see them);
202
+ `client.signIn()` signs in and comes back to the page; `client.signOut()`
203
+ signs out. A call that answers `UNAUTHENTICATED` after hours means the
204
+ session ended (12 hours): offer `client.signIn()`.
205
+ - Public pages call `public` methods for visitors who are signed out.
206
+ - Nothing on the page holds the session: the browser keeps it, for this app
207
+ only. The app's own code never sees it, nor any Teable token.
208
+
209
+ ### Handle HTTP: the app's Worker
210
+
211
+ For HTTP that is not a page (a webhook, a feed, a page rendered on the
212
+ server), write `src/worker/index.ts`; `bun run build` makes `dist/worker.js`
213
+ and publishing deploys it with the pages.
214
+
215
+ ```ts
216
+ import { appOf, type WorkerEnv } from "@teable/app/worker";
217
+ import type * as server from "../server";
218
+
219
+ export default {
220
+ async fetch(request, env, ctx) {
221
+ const app = appOf<typeof server>(ctx);
222
+ const url = new URL(request.url);
223
+ if (url.pathname === "/hooks/paid" && request.method === "POST") {
224
+ // Check the sender's signature first: the app acts as itself here.
225
+ await app.asApp.call("markPaid", await request.json());
226
+ return new Response(null, { status: 204 });
227
+ }
228
+ return env.ASSETS.fetch(request);
229
+ },
230
+ } satisfies ExportedHandler<WorkerEnv>;
231
+ ```
232
+
233
+ - The pages' files are served before it runs. It gets what no file answers
234
+ and is not a page's navigation (webhooks, fetches), and the paths
235
+ `public/_routes.json` lists (`{ "include": ["/report/*"] }`), before any
236
+ file. `env.ASSETS.fetch(request)` serves the pages.
237
+ - `app.caller` is who sent the request: the signed-in person for the app's
238
+ own pages' requests and for links followed to it, anonymous otherwise.
239
+ `app.asCaller.call(...)` calls a method as them, under its access;
240
+ `app.asApp.call(...)` calls one as the app itself, `internal` ones too.
241
+ Failures throw `MethodError`, as in pages. `app.files` is the `files`
242
+ capability, when declared.
243
+ - It keeps no data of its own: the app's data is reached through methods.
244
+ Never change data on a GET. It has the network (`fetch`), unmetered;
245
+ long or scheduled work stays in tasks.
246
+ - It imports the server code with `import type` only.
247
+
180
248
  ### Add a task or a schedule
181
249
 
182
250
  ```ts
@@ -264,6 +332,8 @@ the migrations.
264
332
  | `RATE_LIMITED` (HTTP 429) | Wait as long as `Retry-After` says, then try again. |
265
333
  | `Deploy rejected: built for app protocol N; this runtime speaks M` (publish) | `bun add @teable/app@latest`, then check, build and publish again. |
266
334
  | `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. |
335
+ | `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. |
336
+ | `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
337
 
268
338
  ## Publishing
269
339
 
@@ -276,13 +346,15 @@ user gets the change, and a publish that fails changes nothing. It takes the
276
346
  on a copy of the live data first, running its migrations, then on the live
277
347
  data, and makes it live only if both work; open pages read everything again.
278
348
  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,
349
+ Then tell the user what changed. The pages are live at the app's own address,
350
+ `https://<appId in lower case>.teable.uk` (publish prints it), with the
351
+ methods through the API (`/api/v4/apps/<appId>/methods/<name>`, described at
352
+ `.../openapi.json`) and MCP (`/api/v4/apps/<appId>/mcp`); the builder on
353
+ Teable previews the pages. A version is the server code and the pages
354
+ together: a rollback brings back both.
355
+
356
+ `teable-next rollback` deploys an earlier version's code and pages again, as
357
+ the next version. It cannot go back past a migration: the live database has run it,
286
358
  and code without it does not start, so the rollback is refused (`CONFLICT`);
287
359
  undo a schema change with a new migration. A rollback changes only what
288
360
  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.0",
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",
@@ -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.3",
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,13 @@ 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.
59
63
 
60
64
  `teable-next versions` lists published versions, with who published each and
61
65
  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.
66
+ version's code and pages again, as the next version; it is refused past a
67
+ migration (roll forward instead), and it leaves the repository as it is, so
68
+ fix or revert the code before the next publish.
66
69
 
67
70
  ## The rules
68
71
 
@@ -90,6 +93,8 @@ Each is explained, with why, in the app's `AGENTS.md` ("The rules, and why"):
90
93
  | Add a page | How to: Add a page |
91
94
  | Run work later, on a schedule, or against a service | How to: Add a task... |
92
95
  | Store files, call other services | How to: Use a capability |
96
+ | Say who may open the pages, sign people in | How to: Sign people in |
97
+ | Take a webhook, render a page on the server | How to: Handle HTTP... |
93
98
  | Write tests | How to: Test |
94
99
  | Understand an error from a check, a test or a publish | When something fails |
95
100
  | Know what publishing does | Publishing |