@teable/create-app 1.0.1 → 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.
package/README.md CHANGED
@@ -13,8 +13,10 @@ cd my-app && bun install && bun run check
13
13
  which must be absent or empty (a lone `.git` is fine), and `teable.json`
14
14
  naming the app on Teable; without `--app-id` it names none. The app's
15
15
  `AGENTS.md` (read by Claude Code through `CLAUDE.md`, and by other agents)
16
- holds its rules, commands and how to publish it with `teable app publish`.
17
- It needs [Bun](https://bun.sh).
16
+ holds its rules, commands and how to publish it with `teable-next publish`
17
+ ([`@teable/next-cli`](https://www.npmjs.com/package/@teable/next-cli), which
18
+ also starts an app in a project on Teable: `teable-next init <dir> --project
19
+ <projectId>`). It needs [Bun](https://bun.sh).
18
20
 
19
21
  ## The Agent Skill
20
22
 
@@ -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 app 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,36 +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. The `teable` CLI 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
- teable app push -m "<what changed>" # commit, and save the source to Teable
36
- teable app publish # deploy dist/server.js, with its commit, as the next version
37
- teable app versions # published versions, newest first: when, by whom, which commit
38
- teable app rollback --version <n> # deploy version n's code again, as the next version
40
+ teable-next pull # before you start: the latest from Teable
41
+ teable-next push -m "<what changed>" # commit, and save the source to Teable
42
+ teable-next publish # check, build and deploy dist/ (methods and pages), with its commit, as the next version
43
+ teable-next versions # published versions, newest first: when, by whom, which commit
44
+ teable-next rollback --version <n> # deploy version n's code again, as the next version
39
45
  ```
40
46
 
41
- `teable app <command> --help` lists every option. There is no local server
42
- (`dev`): the runtime that hosts apps is not published. Tests are the loop:
43
- methods against a real database, pages against a stubbed client. Publish to
44
- see the app running.
47
+ `teable-next <command> --help` lists every option; without the CLI
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.
45
56
 
46
57
  ## The rules, and why
47
58
 
@@ -93,6 +104,10 @@ Also:
93
104
  Keep each call small, and page through long lists (`limit`).
94
105
  - Teable has no secrets store for apps yet. Never put keys or tokens in code
95
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`.
96
111
 
97
112
  ## How to
98
113
 
@@ -175,6 +190,61 @@ export const App = app.define({ listInvoices, markPaid });
175
190
  5. Test it next to it (`<page>.test.tsx`), with a client whose `fetch` the
176
191
  test answers, as `notes.test.tsx` does.
177
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
+
178
248
  ### Add a task or a schedule
179
249
 
180
250
  ```ts
@@ -255,29 +325,36 @@ the migrations.
255
325
  | `Declare capabilities: [...] in createApp`, or `not permitted to access the internet` | Declare the capability; use it in a task. |
256
326
  | `must export the class from define() as "App"` (build) | `export const App = app.define({ ... })` in `src/server/index.ts`. |
257
327
  | `Stripping types is currently unsupported for files under node_modules` | Vite or Vitest ran on Node; run them through `bun run test` and `bun run build`. |
258
- | `FORBIDDEN` from `teable app publish` or `rollback` | Publishing takes the `creator` or `owner` role in the app's space; ask the user. |
259
- | `CONFLICT` from `teable app rollback` | That version lacks a migration the live database has run: roll forward with a new version instead. |
328
+ | `uncommitted changes` or `is not pushed yet` from `teable-next publish` | Publishing deploys only what is pushed: `teable-next push -m "<what changed>"`, then publish again. |
329
+ | `moved to ... since your last pull` from `teable-next push` | Someone else pushed: `teable-next pull` (rebase on `teable/main` if your commits diverged), then push again. |
330
+ | `FORBIDDEN` from `teable-next publish` or `rollback` | Publishing takes the `creator` or `owner` role in the app's space; ask the user. |
331
+ | `CONFLICT` from `teable-next rollback` | That version lacks a migration the live database has run: roll forward with a new version instead. |
260
332
  | `RATE_LIMITED` (HTTP 429) | Wait as long as `Retry-After` says, then try again. |
261
333
  | `Deploy rejected: built for app protocol N; this runtime speaks M` (publish) | `bun add @teable/app@latest`, then check, build and publish again. |
262
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. |
263
337
 
264
338
  ## Publishing
265
339
 
266
340
  Once `bun run check` and `bun run build` pass, push and publish:
267
- `teable app push -m "<what changed>"`, then `teable app publish`. Do not wait
268
- to be asked: publishing is how the user gets the change, and a publish that
269
- fails changes nothing. It takes the `creator` or `owner` role in the app's
270
- space. Teable starts the new version on a copy of the live data first,
271
- running its migrations, then on the live data, and makes it live only if both
272
- work; open pages read everything again. Every version records when it was
273
- published, by whom, and from which commit. Then tell the user what changed.
274
- The methods are live at once through the API
275
- (`/api/v4/apps/<appId>/methods/<name>`, described at `.../openapi.json`), MCP
276
- (`/api/v4/apps/<appId>/mcp`) and the app on Teable; Teable does not serve
277
- `dist/pages` yet.
278
-
279
- `teable app rollback` deploys an earlier version's code again, as the next
280
- version. It cannot go back past a migration: the live database has run it,
341
+ `teable-next push -m "<what changed>"`, then `teable-next publish`, which
342
+ deploys exactly the commit pushed: it runs the check and the build again,
343
+ and prints the app's URLs. Do not wait to be asked: publishing is how the
344
+ user gets the change, and a publish that fails changes nothing. It takes the
345
+ `creator` or `owner` role in the app's space. Teable starts the new version
346
+ on a copy of the live data first, running its migrations, then on the live
347
+ data, and makes it live only if both work; open pages read everything again.
348
+ Every version records when it was published, by whom, and from which commit.
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,
281
358
  and code without it does not start, so the rollback is refused (`CONFLICT`);
282
359
  undo a schema change with a new migration. A rollback changes only what
283
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.1",
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.1",
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 the `teable` CLI.
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
 
@@ -24,38 +26,46 @@ and publish it with the `teable` CLI.
24
26
 
25
27
  ## Start
26
28
 
29
+ An app is a project on Teable that runs in teable-next: the app's id is the
30
+ project's (`bseXXX`), the project the user is working in.
31
+
27
32
  ```sh
28
- teable app init --name "<app name>" # a new app: creates it on Teable, checks out its repository
29
- teable app clone --app-id <appId> # an app that exists: checks out its repository
30
- teable app pull # in a checkout you have: bring it up to date first
33
+ teable-next init <dir> --project <projectId> # a new app: writes it, pushes it to the project's repository
34
+ teable-next clone <projectId> [dir] # an app that has code: checks out its repository
35
+ teable-next pull # in a checkout you have: bring it up to date first
31
36
  ```
32
37
 
33
- Without the `teable` CLI (Claude Code on someone's own machine, say),
34
- `npx @teable/create-app <dir> --app-id <appId>` (or `bunx`) writes the same
35
- blank app; leave out `--app-id` to try one locally, and `git init` it. Then
36
- `bun install`, and read the app's `AGENTS.md` before changing anything: it is
37
- the app's own instructions, current for the SDK the app uses.
38
+ `teable-next` acts as the user, with their token: `TEABLE_TOKEN` (a Teable
39
+ sandbox sets it, and `TEABLE_ENDPOINT`), or the one `teable-next login
40
+ --token <token>` saved. Where it is not installed (Claude Code on someone's
41
+ own machine, say), `npx @teable/next-cli <command>` (or `bunx`) runs it. To
42
+ try an app with no project yet, `npx @teable/create-app <dir>` writes the
43
+ same blank app, without an app id; `git init` it. Then `bun install`, and
44
+ read the app's `AGENTS.md` before changing anything: it is the app's own
45
+ instructions, current for the SDK the app uses.
38
46
 
39
47
  ## The loop
40
48
 
41
49
  1. Edit: schema, methods, migrations, pages, tests.
42
50
  2. `bun run check`: typecheck, tests (methods in workerd against a real
43
51
  database, pages in jsdom), migration checks.
44
- 3. `bun run build`: `dist/server.js`, which publishing uploads.
45
- 4. `teable app push -m "<what changed>"`: commit and save the source to
46
- Teable as a new version.
47
- 5. `teable app publish`: Teable runs the new version's migrations on a copy
48
- of the live data, then on the live data, and makes it live only if both
49
- work. Publish as soon as the checks pass; do not wait to be asked. It
50
- takes the `creator` or `owner` role in the app's space. Then tell the user
51
- what changed.
52
-
53
- `teable app versions` lists published versions, with who published each and
54
- from which commit. `teable app rollback --version <n>` deploys an earlier
55
- version's code again, as the next version; it is refused past a migration
56
- (roll forward instead), and it leaves the repository as it is, so fix or
57
- revert the code before the next publish. There is no local server: tests are
58
- the loop, publishing shows the running app.
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.
55
+ 4. `teable-next push -m "<what changed>"`: commit and save the source to the
56
+ app's repository on Teable.
57
+ 5. `teable-next publish`: the check and the build run again, then Teable
58
+ runs the new version's migrations on a copy of the live data, then on the
59
+ live data, and makes it live only if both work. Publish as soon as the
60
+ checks pass; do not wait to be asked. It takes the `creator` or `owner`
61
+ role in the app's space. Then tell the user what changed, with the URLs
62
+ it prints: the pages' address first.
63
+
64
+ `teable-next versions` lists published versions, with who published each and
65
+ from which commit. `teable-next rollback --version <n>` deploys an earlier
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.
59
69
 
60
70
  ## The rules
61
71
 
@@ -83,6 +93,8 @@ Each is explained, with why, in the app's `AGENTS.md` ("The rules, and why"):
83
93
  | Add a page | How to: Add a page |
84
94
  | Run work later, on a schedule, or against a service | How to: Add a task... |
85
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... |
86
98
  | Write tests | How to: Test |
87
99
  | Understand an error from a check, a test or a publish | When something fails |
88
100
  | Know what publishing does | Publishing |