@teable/app 6.1.10 → 7.0.0

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/dist/build/cli.js CHANGED
@@ -2,8 +2,8 @@
2
2
  import {
3
3
  buildServer,
4
4
  buildWorker
5
- } from "../chunks/V7JA24LQ.js";
6
- import "../chunks/ERQJZOEM.js";
5
+ } from "../chunks/DPGYFUG5.js";
6
+ import "../chunks/SY3BAXHH.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/V7JA24LQ.js";
7
- import "../chunks/ERQJZOEM.js";
6
+ } from "../chunks/DPGYFUG5.js";
7
+ import "../chunks/SY3BAXHH.js";
8
8
  export {
9
9
  buildServer,
10
10
  buildWorker,
@@ -4,7 +4,7 @@ import {
4
4
  FILE_NAME_HEADER,
5
5
  SESSION_PATH,
6
6
  fileKeyPath
7
- } from "./ERQJZOEM.js";
7
+ } from "./SY3BAXHH.js";
8
8
 
9
9
  // src/client.ts
10
10
  var MethodError = class extends Error {
@@ -96,6 +96,7 @@ function createClient(options) {
96
96
  call: ((method, input) => request(`/methods/${method}`, json(input))),
97
97
  manifest: async () => await request("/manifest"),
98
98
  members: async () => (await request("/members")).members,
99
+ accounts: async () => (await request("/accounts")).accounts,
99
100
  queryKey: (method, input) => [...dataKey, method, input ?? {}],
100
101
  subscribe,
101
102
  upload: async (file, name) => await request("/files", {
@@ -118,6 +119,10 @@ function createClient(options) {
118
119
  const back = returnTo ?? (page ? `${page.pathname}${page.search}${page.hash}` : "/");
119
120
  page?.assign(`${base()}${SESSION_PATH}/sign-in?return=${encodeURIComponent(back)}`);
120
121
  },
122
+ sendSignInCode: async (email) => {
123
+ await request("/sign-in/email", json({ email }), SESSION_PATH);
124
+ },
125
+ signInWithCode: async (email, code) => await request("/sign-in/code", json({ email, code }), SESSION_PATH),
121
126
  signOut: async () => {
122
127
  await request("/sign-out", { method: "POST" }, SESSION_PATH);
123
128
  }
@@ -10,7 +10,7 @@ import {
10
10
  isMember,
11
11
  pagesBridge,
12
12
  spaceRoleOf
13
- } from "./ERQJZOEM.js";
13
+ } from "./SY3BAXHH.js";
14
14
 
15
15
  // src/build/index.ts
16
16
  import { existsSync, readFileSync } from "node:fs";
@@ -375,7 +375,8 @@ function remoteMiddleware(remote, appId) {
375
375
  const session = {
376
376
  caller,
377
377
  expiresAt: null,
378
- member: await memberOf(req, caller)
378
+ member: await memberOf(req, caller),
379
+ account: null
379
380
  };
380
381
  res.writeHead(200, { "Content-Type": "application/json" });
381
382
  return res.end(JSON.stringify(session));
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  DEFAULT_CURRENCY,
3
3
  currencyDigits
4
- } from "./ERQJZOEM.js";
4
+ } from "./SY3BAXHH.js";
5
5
 
6
6
  // src/schema.ts
7
7
  import { getTableColumns, getTableName, is } from "drizzle-orm";
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  describeTables
3
- } from "./QPDT7M6Y.js";
3
+ } from "./MV7KRBHD.js";
4
4
  import {
5
5
  CAPABILITIES,
6
6
  PROTOCOL_VERSION,
7
7
  admit,
8
8
  isPageAccess
9
- } from "./ERQJZOEM.js";
9
+ } from "./SY3BAXHH.js";
10
10
 
11
11
  // src/server/errors.ts
12
12
  import { z } from "zod";
@@ -852,7 +852,7 @@ function methodName(method) {
852
852
  function defineApp(schema, migrations, methods, { capabilities, pages }) {
853
853
  if (!isPageAccess(pages.access)) {
854
854
  throw new Error(
855
- `Pages access "${pages.access}" must be a space role (owner, creator, editor, commenter, viewer) or "public"`
855
+ `Pages access "${pages.access}" must be a space role (owner, creator, editor, commenter, viewer), "account" or "public"`
856
856
  );
857
857
  }
858
858
  for (const capability of capabilities) {
@@ -1,5 +1,5 @@
1
1
  // src/protocol.ts
2
- var PROTOCOL_VERSION = 6;
2
+ var PROTOCOL_VERSION = 7;
3
3
  var APP_COMPATIBILITY_DATE = "2026-12-01";
4
4
  var SPACE_ROLES = ["owner", "creator", "editor", "commenter", "viewer"];
5
5
  var EVERY_CAPABILITY = { files: true, http: true };
@@ -60,7 +60,7 @@ var ERROR_STATUS = {
60
60
  INTERNAL: 500
61
61
  };
62
62
  function isPageAccess(access) {
63
- return access === "public" || SPACE_ROLES.includes(access);
63
+ return access === "public" || access === "account" || SPACE_ROLES.includes(access);
64
64
  }
65
65
  var DEV_PATHS = {
66
66
  deploy: "/__teable/deploy",
@@ -69,6 +69,7 @@ var DEV_PATHS = {
69
69
  };
70
70
  var ASSETS_HEADER = "X-Teable-Assets";
71
71
  var SESSION_PATH = "/.teable";
72
+ var SIGN_IN_ACCOUNTS = ["members", "anyone", "domains", "invited"];
72
73
  var BRIDGE_PATH = `${SESSION_PATH}/bridge.js`;
73
74
  function pagesBridge(origins) {
74
75
  return `(${BRIDGE})(window, ${JSON.stringify(origins)});
@@ -283,7 +284,9 @@ function checkAccess(caller, access) {
283
284
  if (access === "internal") return "FORBIDDEN";
284
285
  if (access === "public") return null;
285
286
  if (caller.kind === "anonymous") return "UNAUTHENTICATED";
287
+ if (caller.kind === "account") return access === "account" ? null : "FORBIDDEN";
286
288
  if (caller.role === null) return "FORBIDDEN";
289
+ if (access === "account") return null;
287
290
  return SPACE_ROLES.indexOf(caller.role) <= SPACE_ROLES.indexOf(access) ? null : "FORBIDDEN";
288
291
  }
289
292
  function admit(manifest, name, caller) {
@@ -332,6 +335,7 @@ export {
332
335
  DEV_PATHS,
333
336
  ASSETS_HEADER,
334
337
  SESSION_PATH,
338
+ SIGN_IN_ACCOUNTS,
335
339
  BRIDGE_PATH,
336
340
  pagesBridge,
337
341
  APPS_PATH,
package/dist/client.d.ts CHANGED
@@ -15,10 +15,13 @@
15
15
  * Pages are served at the app's own host, signed in with a session the
16
16
  * platform keeps there (ADR 0014): `session()` says who is signed in,
17
17
  * `signIn()` and `signOut()` change it. `members()` lists the people of the
18
- * app's space (ADR 0019), by the ids methods know callers by.
18
+ * app's space (ADR 0019), by the ids methods know callers by. People outside
19
+ * the space sign in with an account of the app (ADR 0021): the runtime's
20
+ * sign-in page asks for their email and a code, or the pages do, with
21
+ * `sendSignInCode()` and `signInWithCode()`; `accounts()` lists them.
19
22
  */
20
23
  import type { z } from "zod";
21
- import { type AppErrorShape, type AppMember, type Attachment, type Jsonify, type JsonValue, type ManifestResponse, type PublicLink, type RealtimeMessage, type SessionResponse } from "./protocol.js";
24
+ import { type AppAccount, type AppErrorShape, type AppMember, type Attachment, type Jsonify, type JsonValue, type ManifestResponse, type PublicLink, type RealtimeMessage, type SessionResponse } from "./protocol.js";
22
25
  /** An app's server module as its pages see it: `App` is the class `define()` returned. */
23
26
  export type ServerModule = {
24
27
  App: {
@@ -98,6 +101,12 @@ export interface AppClient<S> {
98
101
  * members; empty until Teable has said who they are.
99
102
  */
100
103
  members(): Promise<AppMember[]>;
104
+ /**
105
+ * The app's own accounts (ADR 0021): people outside its space who sign in
106
+ * by email, each with the id methods know them by (`ctx.caller.accountId`).
107
+ * For its members.
108
+ */
109
+ accounts(): Promise<AppAccount[]>;
101
110
  /** For TanStack Query: a key that includes the app, the method and the input. */
102
111
  queryKey<K extends MethodName<S>>(method: K, input?: MethodInput<S, K>): readonly unknown[];
103
112
  /** The prefix of every `queryKey`: what a change to the app's data makes stale (`subscribe`). */
@@ -116,14 +125,28 @@ export interface AppClient<S> {
116
125
  }): Promise<PublicLink>;
117
126
  /**
118
127
  * Who is signed in to the app's pages, on its own host, and until when; and
119
- * `member`, the person as `members()` lists them, for a member.
128
+ * `member`, the person as `members()` lists them, for a member, or
129
+ * `account`, for an account of the app.
120
130
  */
121
131
  session(): Promise<SessionResponse>;
122
132
  /**
123
- * Sign in to the app's pages with Teable, on its own host: the browser goes
124
- * there and comes back to `returnTo` (a path; this page by default).
133
+ * Sign in to the app's pages, on its own host: the browser goes to its
134
+ * sign-in page (an email and a code, for an app that lets people sign in
135
+ * with an account; Teable for members) and comes back to `returnTo` (a
136
+ * path; this page by default).
125
137
  */
126
138
  signIn(returnTo?: string): void;
139
+ /**
140
+ * Send a sign-in code to `email`, for a sign-in page of the app's own. It
141
+ * resolves the same whether the app lets that email sign in or not, so
142
+ * that nobody learns who may; RATE_LIMITED when it was asked too often.
143
+ */
144
+ sendSignInCode(email: string): Promise<void>;
145
+ /**
146
+ * Sign in with the code `sendSignInCode` sent: the session, signed in as
147
+ * the account. A wrong or expired code is UNAUTHENTICATED.
148
+ */
149
+ signInWithCode(email: string, code: string): Promise<SessionResponse>;
127
150
  /** Sign out of the app's pages, on its own host. Signing out of Teable is Teable's. */
128
151
  signOut(): Promise<void>;
129
152
  }
package/dist/client.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  MethodError,
3
3
  createClient
4
- } from "./chunks/I2LWXWMY.js";
5
- import "./chunks/ERQJZOEM.js";
4
+ } from "./chunks/CFKHMHDT.js";
5
+ import "./chunks/SY3BAXHH.js";
6
6
  export {
7
7
  MethodError,
8
8
  createClient
@@ -3,14 +3,15 @@
3
3
  * the developer's own host. `teable()`, the Vite plugin in
4
4
  * `@teable/app/build`, runs this Worker in workerd and sends it what the
5
5
  * runtime answers on an app's host: signing in (faked: the developer picks
6
- * who to be), the app's API, and the app's own Worker, with the props it
6
+ * who to be, a member of any role or an account of the app by email, ADR
7
+ * 0021), the app's API, and the app's own Worker, with the props it
7
8
  * gets on the platform. The app's server code runs as a facet of a host
8
9
  * Durable Object on a local database, as on the platform: calls are
9
10
  * admitted with the protocol's `admit`, tasks run from the host's alarm,
10
11
  * and realtime tells open pages what changed.
11
12
  */
12
13
  import { DurableObject, WorkerEntrypoint } from "cloudflare:workers";
13
- import { type AppManifest, type Attachment, type Caller, type FilesCapability, type JsonValue, type MethodValue, type PublicLink, type Result } from "../protocol.js";
14
+ import { type AppAccount, type AppManifest, type Attachment, type Caller, type FilesCapability, type JsonValue, type MethodValue, type PublicLink, type Result } from "../protocol.js";
14
15
  interface DevEnv {
15
16
  HOST: DurableObjectNamespace;
16
17
  LOADER: WorkerLoader;
@@ -35,6 +36,16 @@ export declare class DevHost extends DurableObject<DevEnv> {
35
36
  worker: string | null;
36
37
  } | null>;
37
38
  call(caller: Caller, method: string, input: JsonValue | undefined, readOnly?: boolean): Promise<Result<MethodValue>>;
39
+ /** The accounts the developer signed in as, the last signed in first. */
40
+ accounts(): Promise<AppAccount[]>;
41
+ /** An account, by its id; null for none. */
42
+ account(accountId: string): Promise<AppAccount | null>;
43
+ /** Sign in as the account with this email, made now if there is none: development needs no code. */
44
+ signIn(email: string): Promise<AppAccount>;
45
+ /** A code for the email: development prints it, sending no email. */
46
+ sendCode(email: string): Promise<void>;
47
+ /** Sign in with the code printed for the email, once; null for another code. */
48
+ redeem(email: string, code: string): Promise<AppAccount | null>;
38
49
  alarm(): Promise<void>;
39
50
  fetch(): Promise<Response>;
40
51
  }
package/dist/dev/host.js CHANGED
@@ -10,7 +10,7 @@ import {
10
10
  callableMethods,
11
11
  checkAccess,
12
12
  isMember
13
- } from "../chunks/ERQJZOEM.js";
13
+ } from "../chunks/SY3BAXHH.js";
14
14
 
15
15
  // src/dev/host.ts
16
16
  import { DurableObject, WorkerEntrypoint } from "cloudflare:workers";
@@ -28,9 +28,15 @@ var MEMBERS = PICKS.flatMap(({ who, label }) => {
28
28
  const role = SPACE_ROLES.find((name) => name === who);
29
29
  return role ? [{ userId: `dev-${who}`, name: label, avatar: null, role }] : [];
30
30
  });
31
+ var accountSession = (account) => `account.${account.accountId}.${encodeURIComponent(account.email)}`;
31
32
  function callerOf(request) {
32
33
  const cookie = request.headers.get("Cookie") ?? "";
33
34
  const who = cookie.match(new RegExp(`(?:^|;\\s*)${DEV_SESSION}=([^;]+)`))?.[1];
35
+ const account = who?.match(/^account\.(acc[0-9A-Za-z]+)\.(.+)$/);
36
+ if (account) {
37
+ const [, accountId = "", email = ""] = account;
38
+ return { kind: "account", accountId, email: decodeURIComponent(email), via: "web" };
39
+ }
34
40
  if (!PICKS.some((pick) => pick.who === who) || who === "anonymous") {
35
41
  return { kind: "anonymous", via: "web" };
36
42
  }
@@ -55,8 +61,13 @@ var KV = {
55
61
  codeId: "codeId",
56
62
  worker: "worker",
57
63
  manifest: "manifest",
58
- version: "version"
64
+ version: "version",
65
+ accounts: "accounts"
59
66
  };
67
+ function emailOf(value) {
68
+ const email = typeof value === "string" ? value.trim().toLowerCase() : "";
69
+ return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email) ? email : null;
70
+ }
60
71
  var DevHost = class extends DurableObject {
61
72
  /**
62
73
  * Run new code on the local database at once, its migrations with it (no
@@ -110,6 +121,47 @@ var DevHost = class extends DurableObject {
110
121
  await this.#apply(result.effects);
111
122
  return result.ok ? { ok: true, value: result.value } : { ok: false, error: result.error };
112
123
  }
124
+ /** The accounts the developer signed in as, the last signed in first. */
125
+ async accounts() {
126
+ const accounts = Object.values(this.#kv(KV.accounts) ?? {});
127
+ return accounts.sort((a, b) => (b.lastSignInAt ?? 0) - (a.lastSignInAt ?? 0));
128
+ }
129
+ /** An account, by its id; null for none. */
130
+ async account(accountId) {
131
+ return (await this.accounts()).find((account) => account.accountId === accountId) ?? null;
132
+ }
133
+ /** Sign in as the account with this email, made now if there is none: development needs no code. */
134
+ async signIn(email) {
135
+ const accounts = this.#kv(KV.accounts) ?? {};
136
+ const now = Date.now();
137
+ const random = crypto.getRandomValues(new Uint8Array(16));
138
+ const account = {
139
+ ...accounts[email] ?? {
140
+ accountId: `acc${[...random].map((byte) => (byte % 36).toString(36)).join("")}`,
141
+ email,
142
+ name: email.slice(0, email.indexOf("@")),
143
+ createdAt: now
144
+ },
145
+ lastSignInAt: now
146
+ };
147
+ this.ctx.storage.kv.put(KV.accounts, { ...accounts, [email]: account });
148
+ return account;
149
+ }
150
+ /** A code for the email: development prints it, sending no email. */
151
+ async sendCode(email) {
152
+ const code = String(crypto.getRandomValues(new Uint32Array(1))[0] ?? 0).slice(-6).padStart(6, "0");
153
+ this.#codes.set(email, code);
154
+ console.log(
155
+ `teable: the sign-in code for ${email} is ${code} (in development, no email is sent)`
156
+ );
157
+ }
158
+ /** Sign in with the code printed for the email, once; null for another code. */
159
+ async redeem(email, code) {
160
+ if (this.#codes.get(email) !== code) return null;
161
+ this.#codes.delete(email);
162
+ return this.signIn(email);
163
+ }
164
+ #codes = /* @__PURE__ */ new Map();
113
165
  async alarm() {
114
166
  if (this.#kv(KV.code) === void 0) return;
115
167
  const { failed, effects } = await this.#facet().wake(Date.now());
@@ -229,15 +281,17 @@ function html(body, status = 200) {
229
281
  return new Response(page, { status, headers: { "Content-Type": "text/html; charset=utf-8" } });
230
282
  }
231
283
  function picker(returnTo, current) {
232
- const now = current.kind === "user" ? current.role ?? "outsider" : "anonymous";
284
+ const now = current.kind === "user" ? current.role ?? "outsider" : current.kind;
233
285
  const buttons = PICKS.map(
234
286
  ({ who, label }) => `<button name="who" value="${who}"${who === now ? " aria-current=true" : ""}>${label}</button>`
235
287
  ).join("");
288
+ const back = `<input type="hidden" name="return" value="${escapeHtml(returnTo)}">`;
289
+ const email = current.kind === "account" ? escapeHtml(current.email) : "";
236
290
  return html(
237
- `<h1>Sign in to the app</h1><p>Development: pick who to be. On Teable, people sign in with their account, and have the role they have in the app's space.</p><form method="post"><input type="hidden" name="return" value="${escapeHtml(returnTo)}">${buttons}</form>`
291
+ `<h1>Sign in to the app</h1><p>Development: pick who to be. On Teable, the members of the app's space sign in with Teable, with the role they have there.</p><form method="post">${back}${buttons}</form><h2>An account of the app</h2><p>People outside its space sign in with an email code, where its sign-in setting lets them. Here, an email is enough.</p><form method="post">${back}<input type="hidden" name="who" value="account"><input name="email" type="email" required placeholder="someone@example.com" value="${email}"><button${now === "account" ? " aria-current=true" : ""}>Sign in as this account</button></form>`
238
292
  );
239
293
  }
240
- async function session(request, url) {
294
+ async function session(request, env, url) {
241
295
  const route = `${request.method} ${url.pathname.slice(SESSION_PATH.length)}`;
242
296
  const cookie = (who) => `${DEV_SESSION}=${who}; Path=/; HttpOnly; SameSite=Lax`;
243
297
  switch (route) {
@@ -253,24 +307,66 @@ async function session(request, url) {
253
307
  });
254
308
  }
255
309
  const caller = callerOf(request);
256
- if (caller.kind === "user" && !url.searchParams.has("choose")) {
310
+ if (caller.kind !== "anonymous" && !url.searchParams.has("choose")) {
257
311
  return new Response(null, { status: 302, headers: { Location: returnTo } });
258
312
  }
259
313
  return picker(returnTo, caller);
260
314
  }
261
315
  case "POST /sign-in": {
262
316
  const form = await request.formData();
263
- const pick = PICKS.find((p) => p.who === form.get("who"))?.who ?? "anonymous";
264
317
  const to = pathOnHost(String(form.get("return") ?? "/"));
318
+ const email = form.get("who") === "account" ? emailOf(form.get("email")) : null;
319
+ const pick = email ? accountSession(await host(env).signIn(email)) : PICKS.find((p) => p.who === form.get("who"))?.who ?? "anonymous";
265
320
  return new Response(null, {
266
321
  status: 303,
267
322
  headers: { Location: to, "Set-Cookie": cookie(pick) }
268
323
  });
269
324
  }
325
+ // A page's own sign-in for accounts (client.sendSignInCode, client.signInWithCode).
326
+ case "POST /sign-in/email":
327
+ case "POST /sign-in/code": {
328
+ const body = await request.json().catch(() => ({}));
329
+ const email = emailOf(body.email);
330
+ if (email === null) return errorBody("BAD_INPUT", "email must be an email address");
331
+ if (route === "POST /sign-in/email") {
332
+ await host(env).sendCode(email);
333
+ return new Response(null, { status: 204 });
334
+ }
335
+ const account = await host(env).redeem(email, String(body.code ?? "").trim());
336
+ if (account === null) {
337
+ return errorBody(
338
+ "UNAUTHENTICATED",
339
+ "That code is wrong, used or expired: ask for a new one"
340
+ );
341
+ }
342
+ const caller = { kind: "account", accountId: account.accountId, email, via: "web" };
343
+ return Response.json(
344
+ { caller, expiresAt: null, member: null, account },
345
+ {
346
+ headers: { "Set-Cookie": cookie(accountSession(account)) }
347
+ }
348
+ );
349
+ }
270
350
  case "GET /session": {
271
351
  const caller = callerOf(request);
352
+ if (caller.kind === "account") {
353
+ const account = await host(env).account(caller.accountId);
354
+ const signedIn = { caller, expiresAt: null, member: null, account };
355
+ const signedOut = {
356
+ caller: { kind: "anonymous", via: "web" },
357
+ expiresAt: null,
358
+ member: null,
359
+ account: null
360
+ };
361
+ return Response.json(account ? signedIn : signedOut);
362
+ }
272
363
  const member = caller.kind === "user" ? MEMBERS.find((m) => m.userId === caller.userId) ?? null : null;
273
- return Response.json({ caller, expiresAt: null, member });
364
+ return Response.json({
365
+ caller,
366
+ expiresAt: null,
367
+ member,
368
+ account: null
369
+ });
274
370
  }
275
371
  case "POST /sign-out":
276
372
  return new Response(null, { status: 204, headers: { "Set-Cookie": cookie("anonymous") } });
@@ -303,6 +399,10 @@ async function api(request, env, url) {
303
399
  if (path === "members" && request.method === "GET") {
304
400
  return needs("viewer") ?? Response.json({ members: MEMBERS });
305
401
  }
402
+ if (path === "accounts" && request.method === "GET") {
403
+ const accounts = await app.accounts();
404
+ return needs("viewer") ?? Response.json({ accounts });
405
+ }
306
406
  const method = path.match(/^methods\/([A-Za-z][A-Za-z0-9_]*)$/)?.[1];
307
407
  if (method) {
308
408
  const raw = request.method === "GET" ? url.searchParams.get("input") : await request.text();
@@ -392,7 +492,7 @@ var host_default = {
392
492
  if (url.pathname === DEV_PATHS.worker || url.pathname.startsWith(`${DEV_PATHS.worker}/`)) {
393
493
  return toWorker(request, env, ctx, url);
394
494
  }
395
- if (url.pathname.startsWith(`${SESSION_PATH}/`)) return session(request, url);
495
+ if (url.pathname.startsWith(`${SESSION_PATH}/`)) return session(request, env, url);
396
496
  if (url.pathname.startsWith(`${APPS_PATH}/`)) return api(request, env, url);
397
497
  return errorBody("NOT_FOUND", "Not found");
398
498
  }
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  createApp,
3
3
  fail
4
- } from "./chunks/K5LVABM3.js";
5
- import "./chunks/QPDT7M6Y.js";
6
- import "./chunks/ERQJZOEM.js";
4
+ } from "./chunks/O4WQUPBV.js";
5
+ import "./chunks/MV7KRBHD.js";
6
+ import "./chunks/SY3BAXHH.js";
7
7
 
8
8
  // src/index.ts
9
9
  import { z } from "zod";
@@ -13,7 +13,7 @@
13
13
  * and starts only apps built for its own version, so a change to the contract
14
14
  * comes with a new version, and every app is deployed again.
15
15
  */
16
- export declare const PROTOCOL_VERSION = 6;
16
+ export declare const PROTOCOL_VERSION = 7;
17
17
  /**
18
18
  * The workerd compatibility date every app runs with: the host loads app code
19
19
  * with it, and the SDK's and templates' tests run with it. Bump deliberately,
@@ -25,14 +25,22 @@ export declare const SPACE_ROLES: readonly ["owner", "creator", "editor", "comme
25
25
  export type SpaceRole = (typeof SPACE_ROLES)[number];
26
26
  /**
27
27
  * Who is calling a method. Identity is verified by the platform, never by the
28
- * app. The app itself calls as `system`: from a task, or from its own Worker
29
- * acting as the app (`asApp`, ADR 0014).
28
+ * app. A user is a Teable user, with their role in the app's space (null
29
+ * outside it); an account is one of the app's own (ADR 0021), someone its
30
+ * pages let sign in by email, never with a role. The app itself calls as
31
+ * `system`: from a task, or from its own Worker acting as the app (`asApp`,
32
+ * ADR 0014).
30
33
  */
31
34
  export type Caller = {
32
35
  kind: "user";
33
36
  userId: string;
34
37
  role: SpaceRole | null;
35
38
  via: ExternalChannel;
39
+ } | {
40
+ kind: "account";
41
+ accountId: string;
42
+ email: string;
43
+ via: ExternalChannel;
36
44
  } | {
37
45
  kind: "anonymous";
38
46
  via: ExternalChannel;
@@ -48,10 +56,11 @@ export type ExternalChannel = "web" | "api" | "mcp";
48
56
  /**
49
57
  * Who may call a method from outside the app.
50
58
  * - a role: members of the app's space with at least that role
59
+ * - "account": anyone signed in to the app: its accounts, and members of its space
51
60
  * - "public": anyone, including anonymous visitors
52
61
  * - "internal": only the app itself (tasks); never exposed
53
62
  */
54
- export type Access = SpaceRole | "public" | "internal";
63
+ export type Access = SpaceRole | "account" | "public" | "internal";
55
64
  export type MethodKind = "read" | "write" | "task";
56
65
  export interface MethodInfo {
57
66
  name: string;
@@ -143,11 +152,12 @@ export interface AppManifest {
143
152
  }
144
153
  /**
145
154
  * Who may open an app's pages: members of its space with at least that role,
146
- * or anyone (`public`). A browser's navigation by anyone below it is sent to
155
+ * anyone signed in to the app (`account`: its accounts and its members), or
156
+ * anyone (`public`). A browser's navigation by anyone below it is sent to
147
157
  * sign in, or told what it lacks, before the app's Worker runs; data still
148
158
  * comes only from methods, under their own access.
149
159
  */
150
- export type PageAccess = SpaceRole | "public";
160
+ export type PageAccess = SpaceRole | "account" | "public";
151
161
  /**
152
162
  * What the app's Worker gets with every request, as `ctx.props` (ADR 0014):
153
163
  * who sent the request, as methods see callers (`via: "web"`); the app's
@@ -374,7 +384,7 @@ export interface ManifestResponse extends AppManifest {
374
384
  caller: Caller;
375
385
  pagesUrl: string | null;
376
386
  }
377
- /** Whether a manifest's pages access is one there is: a space role, or `public`. */
387
+ /** Whether a manifest's pages access is one there is: a space role, `account` or `public`. */
378
388
  export declare function isPageAccess(access: unknown): access is PageAccess;
379
389
  /**
380
390
  * How `teable()`, the Vite plugin in `@teable/app/build`, and the runtime's
@@ -396,7 +406,9 @@ export declare const ASSETS_HEADER = "X-Teable-Assets";
396
406
  /**
397
407
  * Where the runtime answers on an app's own host before its Worker (ADR
398
408
  * 0014): `sign-in?return=<path>` (to Teable and back), `callback`,
399
- * `session` (`SessionResponse`) and `sign-out` (POST). With `${APPS_PATH}/`,
409
+ * `session` (`SessionResponse`) and `sign-out` (POST); for an app's accounts
410
+ * (ADR 0021), `sign-in/email` and `sign-in/code` (POST, `SignInCodeRequest`).
411
+ * With `${APPS_PATH}/`,
400
412
  * the app's own API there, the app's Worker never sees these paths.
401
413
  */
402
414
  export declare const SESSION_PATH = "/.teable";
@@ -414,6 +426,8 @@ export interface SessionResponse {
414
426
  * said who the members are.
415
427
  */
416
428
  member: AppMember | null;
429
+ /** The account signed in (ADR 0021); null for anyone else. */
430
+ account: AppAccount | null;
417
431
  }
418
432
  /**
419
433
  * A member of an app's space (ADR 0019), as the old platform says: someone
@@ -436,6 +450,49 @@ export interface AppMember {
436
450
  export interface MembersResponse {
437
451
  members: AppMember[];
438
452
  }
453
+ /**
454
+ * One of an app's own accounts (ADR 0021): someone its pages let sign in by
455
+ * email, outside its space. Times are epoch milliseconds; `lastSignInAt` is
456
+ * null for one added and not yet signed in.
457
+ */
458
+ export interface AppAccount {
459
+ accountId: string;
460
+ email: string;
461
+ name: string;
462
+ createdAt: number;
463
+ lastSignInAt: number | null;
464
+ }
465
+ /**
466
+ * Who may sign in to an app's pages with an account of the app (ADR 0021):
467
+ * nobody but the members of its space (`members`), anyone with an email
468
+ * address (`anyone`), emails at `domains` (`domains`), or only accounts that
469
+ * exist (`invited`: those its creators added, and any made before).
470
+ */
471
+ export type SignInSetting = {
472
+ accounts: "members" | "anyone" | "invited";
473
+ } | {
474
+ accounts: "domains";
475
+ domains: string[];
476
+ };
477
+ /** What a sign-in setting's `accounts` may be. */
478
+ export declare const SIGN_IN_ACCOUNTS: readonly ["members", "anyone", "domains", "invited"];
479
+ /**
480
+ * `GET {APPS_PATH}/:appId/accounts`: the app's accounts, the last signed in
481
+ * first, for the members of its space. `POST` (`{"email", "name"?}`, its
482
+ * creators) adds one; `DELETE …/accounts/:accountId` removes one.
483
+ */
484
+ export interface AccountsResponse {
485
+ accounts: AppAccount[];
486
+ }
487
+ /**
488
+ * `POST ${SESSION_PATH}/sign-in/email`, `{"email"}`, sends a code to the
489
+ * email when the app lets it sign in; `POST ${SESSION_PATH}/sign-in/code`,
490
+ * `{"email", "code"}`, signs it in with that code (`SessionResponse`).
491
+ */
492
+ export interface SignInCodeRequest {
493
+ email: string;
494
+ code?: string;
495
+ }
439
496
  /**
440
497
  * The bridge between the builder's Preview and an app's pages, in its frame:
441
498
  * a script the runtime serves on the app's host (`BRIDGE_PATH`) and adds to
package/dist/protocol.js CHANGED
@@ -16,6 +16,7 @@ import {
16
16
  SECRET_NAME,
17
17
  SECRET_PLACEHOLDER,
18
18
  SESSION_PATH,
19
+ SIGN_IN_ACCOUNTS,
19
20
  SPACE_ROLES,
20
21
  admit,
21
22
  callableMethods,
@@ -31,7 +32,7 @@ import {
31
32
  secretPlaceholder,
32
33
  signedInAsAsked,
33
34
  spaceRoleOf
34
- } from "./chunks/ERQJZOEM.js";
35
+ } from "./chunks/SY3BAXHH.js";
35
36
  export {
36
37
  APPS_PATH,
37
38
  APP_COMPATIBILITY_DATE,
@@ -50,6 +51,7 @@ export {
50
51
  SECRET_NAME,
51
52
  SECRET_PLACEHOLDER,
52
53
  SESSION_PATH,
54
+ SIGN_IN_ACCOUNTS,
53
55
  SPACE_ROLES,
54
56
  admit,
55
57
  callableMethods,
package/dist/schema.js CHANGED
@@ -3,8 +3,8 @@ import {
3
3
  col,
4
4
  describeTables,
5
5
  schemaOf
6
- } from "./chunks/QPDT7M6Y.js";
7
- import "./chunks/ERQJZOEM.js";
6
+ } from "./chunks/MV7KRBHD.js";
7
+ import "./chunks/SY3BAXHH.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/K5LVABM3.js";
4
- import "./chunks/QPDT7M6Y.js";
3
+ } from "./chunks/O4WQUPBV.js";
4
+ import "./chunks/MV7KRBHD.js";
5
5
  import {
6
6
  MethodError
7
- } from "./chunks/I2LWXWMY.js";
7
+ } from "./chunks/CFKHMHDT.js";
8
8
  import {
9
9
  ERROR_STATUS
10
- } from "./chunks/ERQJZOEM.js";
10
+ } from "./chunks/SY3BAXHH.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/I2LWXWMY.js";
3
+ } from "./chunks/CFKHMHDT.js";
4
4
  import {
5
5
  ERROR_STATUS
6
- } from "./chunks/ERQJZOEM.js";
6
+ } from "./chunks/SY3BAXHH.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": "6.1.10",
3
+ "version": "7.0.0",
4
4
  "description": "Write a Teable app as a Drizzle schema plus methods",
5
5
  "license": "MIT",
6
6
  "repository": {