@teable/app 7.0.3 → 7.0.5

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
@@ -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`), `public`, or `internal`. Reads default to `viewer`,
97
- writes to `editor`. Write finer rules in the handler with `ctx.caller`.
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` (`dist/server.js`,
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
@@ -2,8 +2,8 @@
2
2
  import {
3
3
  buildServer,
4
4
  buildWorker
5
- } from "../chunks/WOZYDEVS.js";
6
- import "../chunks/UAHL536U.js";
5
+ } from "../chunks/UDRXJPLD.js";
6
+ import "../chunks/N6PYNICH.js";
7
7
 
8
8
  // src/build/cli.ts
9
9
  import { mkdirSync, rmSync, writeFileSync } from "node:fs";
@@ -3,8 +3,8 @@ import {
3
3
  buildWorker,
4
4
  sqlAsText,
5
5
  teable
6
- } from "../chunks/WOZYDEVS.js";
7
- import "../chunks/UAHL536U.js";
6
+ } from "../chunks/UDRXJPLD.js";
7
+ import "../chunks/N6PYNICH.js";
8
8
  export {
9
9
  buildServer,
10
10
  buildWorker,
@@ -271,6 +271,13 @@ 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 DOMAIN_NAME = /^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,63}$/;
275
+ function normalizeDomain(input) {
276
+ return input.trim().toLowerCase().replace(/^https?:\/\//, "").replace(/\/+$/, "").replace(/\.$/, "");
277
+ }
278
+ function isDomainName(domain) {
279
+ return domain.length <= 253 && DOMAIN_NAME.test(domain);
280
+ }
274
281
  var BADGE_RULES = ["required", "optional", "off"];
275
282
  var SITE_LIMITS = { title: 120, description: 500, iconBytes: 1024 * 1024 };
276
283
  var SITE_ICON_TYPES = [
@@ -356,6 +363,8 @@ export {
356
363
  DEPLOY_HEADERS,
357
364
  DEPLOY_PARTS,
358
365
  PAGES_APP_META,
366
+ normalizeDomain,
367
+ isDomainName,
359
368
  BADGE_RULES,
360
369
  SITE_LIMITS,
361
370
  SITE_ICON_TYPES,
@@ -5,7 +5,7 @@ import {
5
5
  PREVIEW_QUERY,
6
6
  SESSION_PATH,
7
7
  fileKeyPath
8
- } from "./UAHL536U.js";
8
+ } from "./N6PYNICH.js";
9
9
 
10
10
  // src/client.ts
11
11
  var MethodError = class extends Error {
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  describeTables
3
- } from "./VUAUTXE2.js";
3
+ } from "./QNWCYG6K.js";
4
4
  import {
5
5
  CAPABILITIES,
6
6
  PROTOCOL_VERSION,
7
7
  admit,
8
8
  isPageAccess
9
- } from "./UAHL536U.js";
9
+ } from "./N6PYNICH.js";
10
10
 
11
11
  // src/server/errors.ts
12
12
  import { z } from "zod";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  DEFAULT_CURRENCY,
3
3
  currencyDigits
4
- } from "./UAHL536U.js";
4
+ } from "./N6PYNICH.js";
5
5
 
6
6
  // src/schema.ts
7
7
  import { getTableColumns, getTableName, is } from "drizzle-orm";
@@ -10,7 +10,7 @@ import {
10
10
  isMember,
11
11
  pagesBridge,
12
12
  spaceRoleOf
13
- } from "./UAHL536U.js";
13
+ } from "./N6PYNICH.js";
14
14
 
15
15
  // src/build/index.ts
16
16
  import { existsSync, readFileSync } from "node:fs";
package/dist/client.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  MethodError,
3
3
  createClient
4
- } from "./chunks/C74GVJIJ.js";
5
- import "./chunks/UAHL536U.js";
4
+ } from "./chunks/OXDV76VZ.js";
5
+ import "./chunks/N6PYNICH.js";
6
6
  export {
7
7
  MethodError,
8
8
  createClient
package/dist/dev/host.js CHANGED
@@ -10,7 +10,7 @@ import {
10
10
  callableMethods,
11
11
  checkAccess,
12
12
  isMember
13
- } from "../chunks/UAHL536U.js";
13
+ } from "../chunks/N6PYNICH.js";
14
14
 
15
15
  // src/dev/host.ts
16
16
  import { DurableObject, WorkerEntrypoint } from "cloudflare:workers";
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  createApp,
3
3
  fail
4
- } from "./chunks/WVY4PINE.js";
5
- import "./chunks/VUAUTXE2.js";
6
- import "./chunks/UAHL536U.js";
4
+ } from "./chunks/QHPLAVFD.js";
5
+ import "./chunks/QNWCYG6K.js";
6
+ import "./chunks/N6PYNICH.js";
7
7
 
8
8
  // src/index.ts
9
9
  import { z } from "zod";
@@ -751,6 +751,45 @@ export interface AppSubdomain {
751
751
  /** `https://<subdomain>.teable.uk`, or its id's host; null when it has neither. */
752
752
  url: string | null;
753
753
  }
754
+ /**
755
+ * A DNS record people add at their DNS provider for an app's own domain
756
+ * (ADR 0024): its name within their zone (`@` for its root).
757
+ */
758
+ export interface DomainRecord {
759
+ type: "CNAME";
760
+ name: string;
761
+ value: string;
762
+ }
763
+ /**
764
+ * A domain as people type it, as the runtime takes it for an app's own
765
+ * (ADR 0024), and as the old platform did: trimmed, in lower case, without
766
+ * scheme, trailing slashes or a trailing dot.
767
+ */
768
+ export declare function normalizeDomain(input: string): string;
769
+ /** Whether `domain`, normalized, is a host name of two labels or more, 253 characters at most, ending in letters. */
770
+ export declare function isDomainName(domain: string): boolean;
771
+ /**
772
+ * An app's own domain (ADR 0024), as `{APPS_PATH}/:appId/domain` says it
773
+ * to its creators: the domain they bound, or null; `pending` until
774
+ * Cloudflare has validated it and issued its certificate, then `active`,
775
+ * while its pages are there; the record to add for it; and why it is not
776
+ * active yet, in Cloudflare's words. The space's plan decides whether the
777
+ * app may have one, and when a lapsed plan's domain is released.
778
+ */
779
+ export interface AppDomain {
780
+ domain: string | null;
781
+ status: "pending" | "active" | null;
782
+ records: DomainRecord[];
783
+ problem: string | null;
784
+ /** When Cloudflare was last asked about it (epoch milliseconds); null before. */
785
+ checkedAt: number | null;
786
+ /** Whether the space's plan includes own domains (Business and above). */
787
+ allowed: boolean;
788
+ /** When the domain is released, the plan no longer including it (epoch milliseconds); null while it does. */
789
+ releasesAt: number | null;
790
+ /** Where its pages are now: the domain while it is active, else its subdomain or its id's host. */
791
+ url: string | null;
792
+ }
754
793
  /**
755
794
  * Whether an app's pages show the "Build with Teable" badge (ADR 0023), as
756
795
  * the old platform decides from its space's plan: always (`required`),
package/dist/protocol.js CHANGED
@@ -27,16 +27,18 @@ import {
27
27
  checkAccess,
28
28
  currencyDigits,
29
29
  fileKeyPath,
30
+ isDomainName,
30
31
  isExposed,
31
32
  isMember,
32
33
  isPageAccess,
34
+ normalizeDomain,
33
35
  pagesBridge,
34
36
  roleAsAsked,
35
37
  rolesBelow,
36
38
  secretPlaceholder,
37
39
  signedInAsAsked,
38
40
  spaceRoleOf
39
- } from "./chunks/UAHL536U.js";
41
+ } from "./chunks/N6PYNICH.js";
40
42
  export {
41
43
  APPS_PATH,
42
44
  APP_COMPATIBILITY_DATE,
@@ -66,9 +68,11 @@ export {
66
68
  checkAccess,
67
69
  currencyDigits,
68
70
  fileKeyPath,
71
+ isDomainName,
69
72
  isExposed,
70
73
  isMember,
71
74
  isPageAccess,
75
+ normalizeDomain,
72
76
  pagesBridge,
73
77
  roleAsAsked,
74
78
  rolesBelow,
package/dist/schema.js CHANGED
@@ -3,8 +3,8 @@ import {
3
3
  col,
4
4
  describeTables,
5
5
  schemaOf
6
- } from "./chunks/VUAUTXE2.js";
7
- import "./chunks/UAHL536U.js";
6
+ } from "./chunks/QNWCYG6K.js";
7
+ import "./chunks/N6PYNICH.js";
8
8
  export {
9
9
  attachment,
10
10
  col,
package/dist/testing.js CHANGED
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  methodName
3
- } from "./chunks/WVY4PINE.js";
4
- import "./chunks/VUAUTXE2.js";
3
+ } from "./chunks/QHPLAVFD.js";
4
+ import "./chunks/QNWCYG6K.js";
5
5
  import {
6
6
  MethodError
7
- } from "./chunks/C74GVJIJ.js";
7
+ } from "./chunks/OXDV76VZ.js";
8
8
  import {
9
9
  ERROR_STATUS
10
- } from "./chunks/UAHL536U.js";
10
+ } from "./chunks/N6PYNICH.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
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  MethodError
3
- } from "./chunks/C74GVJIJ.js";
3
+ } from "./chunks/OXDV76VZ.js";
4
4
  import {
5
5
  ERROR_STATUS
6
- } from "./chunks/UAHL536U.js";
6
+ } from "./chunks/N6PYNICH.js";
7
7
 
8
8
  // src/worker.ts
9
9
  function thrower(caller) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teable/app",
3
- "version": "7.0.3",
3
+ "version": "7.0.5",
4
4
  "description": "Write a Teable app as a Drizzle schema plus methods",
5
5
  "license": "MIT",
6
6
  "repository": {