@teable/app 7.0.4 → 7.0.6
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 +64 -4
- package/dist/build/cli.js +2 -2
- package/dist/build/index.js +2 -2
- package/dist/chunks/{UDRXJPLD.js → AZZIO5NR.js} +1 -1
- package/dist/chunks/{OXDV76VZ.js → KWMJ6RAV.js} +1 -1
- package/dist/chunks/{QHPLAVFD.js → OTMVSMPE.js} +2 -2
- package/dist/chunks/{QNWCYG6K.js → YVAP26TZ.js} +1 -1
- package/dist/chunks/{N6PYNICH.js → ZKTI2IGQ.js} +7 -0
- package/dist/client.js +2 -2
- package/dist/dev/host.js +1 -1
- package/dist/index.js +3 -3
- package/dist/protocol.d.ts +44 -0
- package/dist/protocol.js +5 -1
- package/dist/schema.js +2 -2
- package/dist/testing.js +4 -4
- package/dist/worker.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -93,8 +93,12 @@ The server module must export the class `define` returns as `App`.
|
|
|
93
93
|
a row (`.pick`, `.omit`, `.extend` as with any zod object). They carry the
|
|
94
94
|
column's kind, so callers know money from a number, and its currency.
|
|
95
95
|
- **Access** is a minimum space role (`viewer`, `commenter`, `editor`,
|
|
96
|
-
`creator`, `owner`), `
|
|
97
|
-
|
|
96
|
+
`creator`, `owner`), `account` (anyone signed in to the app: its accounts,
|
|
97
|
+
and members of its space), `public`, or `internal` (the app itself: tasks
|
|
98
|
+
and its Worker). Reads default to `viewer`, writes to `editor`. Write finer
|
|
99
|
+
rules in the handler with `ctx.caller`: a `user` (a Teable user, with
|
|
100
|
+
their `role` in the space, null outside it), an `account` of the app
|
|
101
|
+
(`accountId`, `email`), `anonymous`, or the app itself (`system`).
|
|
98
102
|
- **Errors**: `fail(code, message)` with `BAD_INPUT`, `FORBIDDEN`, `NOT_FOUND`
|
|
99
103
|
or `CONFLICT`, the only codes an app raises. SQLite constraint violations
|
|
100
104
|
surface as `CONSTRAINT`; anything else thrown is `INTERNAL`.
|
|
@@ -114,6 +118,8 @@ The server module must export the class `define` returns as `App`.
|
|
|
114
118
|
|
|
115
119
|
## Tasks
|
|
116
120
|
|
|
121
|
+
A write starts one with `enqueue(task, input)` once it commits, or later
|
|
122
|
+
with `{ delayMs }`.
|
|
117
123
|
A task's handler receives:
|
|
118
124
|
|
|
119
125
|
- `input`, parsed by its schema;
|
|
@@ -150,12 +156,65 @@ wait for a response (reads and writes are synchronous). The platform meters
|
|
|
150
156
|
every request for the app's space and refuses its own hosts. Without `http`,
|
|
151
157
|
`fetch()` fails with "This worker is not permitted to access the internet".
|
|
152
158
|
|
|
159
|
+
Secrets go with `http`: write `{{secret:STRIPE_KEY}}` where a key goes in a
|
|
160
|
+
request's URL, a header or a text body, and the platform fills it in as the
|
|
161
|
+
request leaves, only towards the hosts the secret allows. The app's code
|
|
162
|
+
never holds the value. The app's creators set secrets in the builder
|
|
163
|
+
(Settings › Secrets); locally and in tests the placeholder goes out as
|
|
164
|
+
written.
|
|
165
|
+
|
|
166
|
+
## Sign-in and pages
|
|
167
|
+
|
|
168
|
+
Pages are served at the app's own address, and people sign in there:
|
|
169
|
+
members of the app's space with their Teable account, people outside it
|
|
170
|
+
with an account of the app, by a code sent to their email, where the app's
|
|
171
|
+
sign-in setting lets them.
|
|
172
|
+
|
|
173
|
+
- `createApp({ pages: { access } })` says who may open the pages: a space
|
|
174
|
+
role (`viewer` by default), `"account"` (anyone signed in) or `"public"`.
|
|
175
|
+
- In pages, `client.session()` says who is signed in; `client.signIn()`
|
|
176
|
+
sends the visitor to the sign-in page and back, and `client.signOut()`
|
|
177
|
+
signs out. For a sign-in of the pages' own,
|
|
178
|
+
`client.sendSignInCode(email)` and `client.signInWithCode(email, code)`.
|
|
179
|
+
- `client.members()` lists the people of the app's space (`userId`, `name`,
|
|
180
|
+
`avatar`, `role`) and `client.accounts()` the app's accounts, both for
|
|
181
|
+
the space's members. Methods know people only by id: store
|
|
182
|
+
`caller.userId` or `caller.accountId`, never a name or an email.
|
|
183
|
+
|
|
184
|
+
## The app's Worker
|
|
185
|
+
|
|
186
|
+
For HTTP that is not a page (a webhook, a feed), write `src/worker/index.ts`:
|
|
187
|
+
|
|
188
|
+
```ts
|
|
189
|
+
import { appOf, type WorkerEnv } from "@teable/app/worker";
|
|
190
|
+
import type * as server from "../server";
|
|
191
|
+
|
|
192
|
+
export default {
|
|
193
|
+
async fetch(request, env, ctx) {
|
|
194
|
+
const app = appOf<typeof server>(ctx);
|
|
195
|
+
if (new URL(request.url).pathname === "/hooks/paid" && request.method === "POST") {
|
|
196
|
+
// Check the sender's signature first: the app acts as itself here.
|
|
197
|
+
await app.asApp.call("markPaid", await request.json());
|
|
198
|
+
return new Response(null, { status: 204 });
|
|
199
|
+
}
|
|
200
|
+
return env.ASSETS.fetch(request); // the pages
|
|
201
|
+
},
|
|
202
|
+
} satisfies ExportedHandler<WorkerEnv>;
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
It gets the requests no file answers that are not a page's navigation, and
|
|
206
|
+
the paths `public/_routes.json` lists, before any file. `app.caller` is who
|
|
207
|
+
sent the request; `app.asCaller.call()` calls a method as them, under its
|
|
208
|
+
access, and `app.asApp.call()` as the app itself, `internal` methods too. It
|
|
209
|
+
keeps no data of its own and imports the server code with `import type` only.
|
|
210
|
+
|
|
153
211
|
## Layout
|
|
154
212
|
|
|
155
213
|
```
|
|
156
214
|
src/server/schema.ts Drizzle tables (also loaded by drizzle-kit in Node)
|
|
157
215
|
src/server/index.ts methods; exports App
|
|
158
216
|
src/web/ pages (Vite + TanStack Router), in the browser
|
|
217
|
+
src/worker/index.ts the app's own Worker, if it has one
|
|
159
218
|
src/components/ registry components, e.g. `npx shadcn add @teable/grid`
|
|
160
219
|
drizzle/ generated migrations
|
|
161
220
|
test/ method tests, in workerd
|
|
@@ -224,5 +283,6 @@ it("sells", async () => {
|
|
|
224
283
|
- `runTasks(until?)` runs every task due by then (default: a year from now);
|
|
225
284
|
- `changes(since?)` reads the changefeed; `as(caller)` calls as someone else.
|
|
226
285
|
|
|
227
|
-
Build what the platform deploys with `teable-app build
|
|
228
|
-
one ES module exporting only `App`
|
|
286
|
+
Build what the platform deploys with `teable-app build`: `dist/server.js`,
|
|
287
|
+
one ES module exporting only `App`, and `dist/worker.js` from the app's own
|
|
288
|
+
Worker, when it has one.
|
package/dist/build/cli.js
CHANGED
package/dist/build/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
describeTables
|
|
3
|
-
} from "./
|
|
3
|
+
} from "./YVAP26TZ.js";
|
|
4
4
|
import {
|
|
5
5
|
CAPABILITIES,
|
|
6
6
|
PROTOCOL_VERSION,
|
|
7
7
|
admit,
|
|
8
8
|
isPageAccess
|
|
9
|
-
} from "./
|
|
9
|
+
} from "./ZKTI2IGQ.js";
|
|
10
10
|
|
|
11
11
|
// src/server/errors.ts
|
|
12
12
|
import { z } from "zod";
|
|
@@ -271,6 +271,11 @@ function fileKeyPath(key) {
|
|
|
271
271
|
var DEPLOY_HEADERS = { commit: "X-Teable-Commit", message: "X-Teable-Message" };
|
|
272
272
|
var DEPLOY_PARTS = { server: "server", worker: "worker", pages: "pages" };
|
|
273
273
|
var PAGES_APP_META = "teable-app";
|
|
274
|
+
var SECRET_FILE_PREFIXES = [".env", ".dev.vars"];
|
|
275
|
+
function isSecretFile(path) {
|
|
276
|
+
const name = path.slice(path.lastIndexOf("/") + 1);
|
|
277
|
+
return SECRET_FILE_PREFIXES.some((prefix) => name.startsWith(prefix));
|
|
278
|
+
}
|
|
274
279
|
var DOMAIN_NAME = /^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,63}$/;
|
|
275
280
|
function normalizeDomain(input) {
|
|
276
281
|
return input.trim().toLowerCase().replace(/^https?:\/\//, "").replace(/\/+$/, "").replace(/\.$/, "");
|
|
@@ -363,6 +368,8 @@ export {
|
|
|
363
368
|
DEPLOY_HEADERS,
|
|
364
369
|
DEPLOY_PARTS,
|
|
365
370
|
PAGES_APP_META,
|
|
371
|
+
SECRET_FILE_PREFIXES,
|
|
372
|
+
isSecretFile,
|
|
366
373
|
normalizeDomain,
|
|
367
374
|
isDomainName,
|
|
368
375
|
BADGE_RULES,
|
package/dist/client.js
CHANGED
package/dist/dev/host.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createApp,
|
|
3
3
|
fail
|
|
4
|
-
} from "./chunks/
|
|
5
|
-
import "./chunks/
|
|
6
|
-
import "./chunks/
|
|
4
|
+
} from "./chunks/OTMVSMPE.js";
|
|
5
|
+
import "./chunks/YVAP26TZ.js";
|
|
6
|
+
import "./chunks/ZKTI2IGQ.js";
|
|
7
7
|
|
|
8
8
|
// src/index.ts
|
|
9
9
|
import { z } from "zod";
|
package/dist/protocol.d.ts
CHANGED
|
@@ -701,6 +701,50 @@ export interface VersionInfo {
|
|
|
701
701
|
/** Whether it is the version that serves the app now. */
|
|
702
702
|
live: boolean;
|
|
703
703
|
}
|
|
704
|
+
/**
|
|
705
|
+
* An app's code is a git repository (ADR 0029): one in Cloudflare
|
|
706
|
+
* Artifacts, named after the app, which the runtime keeps. Those who may
|
|
707
|
+
* publish the app ask for credentials to it with `POST
|
|
708
|
+
* {APPS_PATH}/:appId/git/credentials` and `{ "ops": GitOps }`; git sends the
|
|
709
|
+
* token as `Authorization: Bearer <token>`.
|
|
710
|
+
*/
|
|
711
|
+
export type GitOps = "fetch" | "push";
|
|
712
|
+
export interface GitCredentials {
|
|
713
|
+
/** The repository's HTTPS address. */
|
|
714
|
+
gitUrl: string;
|
|
715
|
+
/** Secret: for git's header only, never stored or shown. */
|
|
716
|
+
token: string;
|
|
717
|
+
/** When the token stops working (ISO 8601). */
|
|
718
|
+
expiresAt: string;
|
|
719
|
+
/** What it allows: fetching, or fetching and pushing. */
|
|
720
|
+
ops: GitOps[];
|
|
721
|
+
}
|
|
722
|
+
/**
|
|
723
|
+
* What the app's repository holds on `main`, as `GET
|
|
724
|
+
* {APPS_PATH}/:appId/code` answers those who may publish the app.
|
|
725
|
+
*/
|
|
726
|
+
export interface AppCode {
|
|
727
|
+
/** `main`'s commit; null while nothing has been pushed. */
|
|
728
|
+
commit: string | null;
|
|
729
|
+
/** Every file but secret files (`isSecretFile`), by path. */
|
|
730
|
+
files: AppCodeFile[];
|
|
731
|
+
}
|
|
732
|
+
export interface AppCodeFile {
|
|
733
|
+
/** From the repository's root, separated by `/`. */
|
|
734
|
+
path: string;
|
|
735
|
+
/** In bytes. */
|
|
736
|
+
size: number;
|
|
737
|
+
/** The file as text; null for a binary file, or one too large to show. */
|
|
738
|
+
content: string | null;
|
|
739
|
+
}
|
|
740
|
+
/**
|
|
741
|
+
* Where secrets are kept, by how a file's name starts, anywhere in the tree:
|
|
742
|
+
* env files and wrangler's `.dev.vars`. Their values stay out of an app's
|
|
743
|
+
* repository: the CLI refuses to push one, and its code is never shown with one.
|
|
744
|
+
*/
|
|
745
|
+
export declare const SECRET_FILE_PREFIXES: readonly [".env", ".dev.vars"];
|
|
746
|
+
/** Whether the file at `path` (separated by `/`) is where secrets are kept. */
|
|
747
|
+
export declare function isSecretFile(path: string): boolean;
|
|
704
748
|
/**
|
|
705
749
|
* A failure of the app's own, as `GET {APPS_PATH}/:appId/failures` lists
|
|
706
750
|
* them for its creators: what broke in it lately, each failure once, with
|
package/dist/protocol.js
CHANGED
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
PAGES_APP_META,
|
|
16
16
|
PREVIEW_QUERY,
|
|
17
17
|
PROTOCOL_VERSION,
|
|
18
|
+
SECRET_FILE_PREFIXES,
|
|
18
19
|
SECRET_NAME,
|
|
19
20
|
SECRET_PLACEHOLDER,
|
|
20
21
|
SESSION_PATH,
|
|
@@ -31,6 +32,7 @@ import {
|
|
|
31
32
|
isExposed,
|
|
32
33
|
isMember,
|
|
33
34
|
isPageAccess,
|
|
35
|
+
isSecretFile,
|
|
34
36
|
normalizeDomain,
|
|
35
37
|
pagesBridge,
|
|
36
38
|
roleAsAsked,
|
|
@@ -38,7 +40,7 @@ import {
|
|
|
38
40
|
secretPlaceholder,
|
|
39
41
|
signedInAsAsked,
|
|
40
42
|
spaceRoleOf
|
|
41
|
-
} from "./chunks/
|
|
43
|
+
} from "./chunks/ZKTI2IGQ.js";
|
|
42
44
|
export {
|
|
43
45
|
APPS_PATH,
|
|
44
46
|
APP_COMPATIBILITY_DATE,
|
|
@@ -56,6 +58,7 @@ export {
|
|
|
56
58
|
PAGES_APP_META,
|
|
57
59
|
PREVIEW_QUERY,
|
|
58
60
|
PROTOCOL_VERSION,
|
|
61
|
+
SECRET_FILE_PREFIXES,
|
|
59
62
|
SECRET_NAME,
|
|
60
63
|
SECRET_PLACEHOLDER,
|
|
61
64
|
SESSION_PATH,
|
|
@@ -72,6 +75,7 @@ export {
|
|
|
72
75
|
isExposed,
|
|
73
76
|
isMember,
|
|
74
77
|
isPageAccess,
|
|
78
|
+
isSecretFile,
|
|
75
79
|
normalizeDomain,
|
|
76
80
|
pagesBridge,
|
|
77
81
|
roleAsAsked,
|
package/dist/schema.js
CHANGED
package/dist/testing.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
methodName
|
|
3
|
-
} from "./chunks/
|
|
4
|
-
import "./chunks/
|
|
3
|
+
} from "./chunks/OTMVSMPE.js";
|
|
4
|
+
import "./chunks/YVAP26TZ.js";
|
|
5
5
|
import {
|
|
6
6
|
MethodError
|
|
7
|
-
} from "./chunks/
|
|
7
|
+
} from "./chunks/KWMJ6RAV.js";
|
|
8
8
|
import {
|
|
9
9
|
ERROR_STATUS
|
|
10
|
-
} from "./chunks/
|
|
10
|
+
} from "./chunks/ZKTI2IGQ.js";
|
|
11
11
|
|
|
12
12
|
// src/testing.ts
|
|
13
13
|
var OWNER = { kind: "user", userId: "test-owner", role: "owner", via: "api" };
|
package/dist/worker.js
CHANGED