@teable/app 6.1.8 → 6.1.10
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 +1 -1
- package/dist/build/index.js +1 -1
- package/dist/chunks/{GMRE3ZBW.js → I2LWXWMY.js} +1 -0
- package/dist/chunks/{KOPAQ575.js → V7JA24LQ.js} +20 -3
- package/dist/client.d.ts +13 -3
- package/dist/client.js +1 -1
- package/dist/dev/host.js +12 -2
- package/dist/protocol.d.ts +38 -0
- package/dist/testing.js +1 -1
- package/dist/worker.js +1 -1
- package/package.json +1 -1
package/dist/build/cli.js
CHANGED
package/dist/build/index.js
CHANGED
|
@@ -95,6 +95,7 @@ function createClient(options) {
|
|
|
95
95
|
manifestKey: ["teable-manifest", options.appId],
|
|
96
96
|
call: ((method, input) => request(`/methods/${method}`, json(input))),
|
|
97
97
|
manifest: async () => await request("/manifest"),
|
|
98
|
+
members: async () => (await request("/members")).members,
|
|
98
99
|
queryKey: (method, input) => [...dataKey, method, input ?? {}],
|
|
99
100
|
subscribe,
|
|
100
101
|
upload: async (file, name) => await request("/files", {
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
PAGES_APP_META,
|
|
8
8
|
SESSION_PATH,
|
|
9
9
|
checkAccess,
|
|
10
|
+
isMember,
|
|
10
11
|
pagesBridge,
|
|
11
12
|
spaceRoleOf
|
|
12
13
|
} from "./ERQJZOEM.js";
|
|
@@ -319,13 +320,24 @@ function localRuntime(server, appId, workerd) {
|
|
|
319
320
|
}
|
|
320
321
|
function remoteMiddleware(remote, appId) {
|
|
321
322
|
const runtime = remote.url.replace(/\/$/, "");
|
|
322
|
-
const
|
|
323
|
+
const get = (req, path) => {
|
|
323
324
|
const token = signedOut(req) ? void 0 : remote.token;
|
|
324
|
-
|
|
325
|
+
return fetch(`${runtime}${APPS_PATH}/${appId}/${path}`, {
|
|
325
326
|
headers: token ? { Authorization: `Bearer ${token}` } : {}
|
|
326
327
|
});
|
|
328
|
+
};
|
|
329
|
+
const manifest = async (req) => {
|
|
330
|
+
const response = await get(req, "manifest");
|
|
327
331
|
return response.ok ? await response.json() : null;
|
|
328
332
|
};
|
|
333
|
+
const memberOf = async (req, caller) => {
|
|
334
|
+
if (caller.kind !== "user" || !isMember(caller)) return null;
|
|
335
|
+
const response = await get(req, "members");
|
|
336
|
+
if (!response.ok) return null;
|
|
337
|
+
const { members } = await response.json();
|
|
338
|
+
const member = members.find(({ userId }) => userId === caller.userId);
|
|
339
|
+
return member && caller.role ? { ...member, role: caller.role } : null;
|
|
340
|
+
};
|
|
329
341
|
const cookie = (who) => `${DEV_SESSION}=${who}; Path=/; HttpOnly; SameSite=Lax`;
|
|
330
342
|
const onHost = (path) => path?.startsWith("/") && !path.startsWith("//") ? path : "/";
|
|
331
343
|
return (req, res, next) => {
|
|
@@ -360,8 +372,13 @@ function remoteMiddleware(remote, appId) {
|
|
|
360
372
|
}
|
|
361
373
|
case `GET ${SESSION_PATH}/session`: {
|
|
362
374
|
const caller = (await manifest(req))?.caller ?? { kind: "anonymous", via: "web" };
|
|
375
|
+
const session = {
|
|
376
|
+
caller,
|
|
377
|
+
expiresAt: null,
|
|
378
|
+
member: await memberOf(req, caller)
|
|
379
|
+
};
|
|
363
380
|
res.writeHead(200, { "Content-Type": "application/json" });
|
|
364
|
-
return res.end(JSON.stringify(
|
|
381
|
+
return res.end(JSON.stringify(session));
|
|
365
382
|
}
|
|
366
383
|
case `POST ${SESSION_PATH}/sign-out`:
|
|
367
384
|
res.writeHead(204, { "Set-Cookie": cookie("anonymous") });
|
package/dist/client.d.ts
CHANGED
|
@@ -14,10 +14,11 @@
|
|
|
14
14
|
*
|
|
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
|
-
* `signIn()` and `signOut()` change it.
|
|
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
19
|
*/
|
|
19
20
|
import type { z } from "zod";
|
|
20
|
-
import { type AppErrorShape, type Attachment, type Jsonify, type JsonValue, type ManifestResponse, type PublicLink, type RealtimeMessage, type SessionResponse } from "./protocol.js";
|
|
21
|
+
import { type AppErrorShape, type AppMember, type Attachment, type Jsonify, type JsonValue, type ManifestResponse, type PublicLink, type RealtimeMessage, type SessionResponse } from "./protocol.js";
|
|
21
22
|
/** An app's server module as its pages see it: `App` is the class `define()` returned. */
|
|
22
23
|
export type ServerModule = {
|
|
23
24
|
App: {
|
|
@@ -91,6 +92,12 @@ export interface AppClient<S> {
|
|
|
91
92
|
call<K extends MethodName<S>>(method: K, input?: MethodInput<S, K>): Promise<MethodOutput<S, K>>;
|
|
92
93
|
/** The app's tables and methods as far as the caller may see them, its live version, and the caller. */
|
|
93
94
|
manifest(): Promise<ManifestResponse>;
|
|
95
|
+
/**
|
|
96
|
+
* The members of the app's space (ADR 0019): each person's id, as methods
|
|
97
|
+
* know callers (`ctx.caller.userId`), name, avatar and role. For its
|
|
98
|
+
* members; empty until Teable has said who they are.
|
|
99
|
+
*/
|
|
100
|
+
members(): Promise<AppMember[]>;
|
|
94
101
|
/** For TanStack Query: a key that includes the app, the method and the input. */
|
|
95
102
|
queryKey<K extends MethodName<S>>(method: K, input?: MethodInput<S, K>): readonly unknown[];
|
|
96
103
|
/** The prefix of every `queryKey`: what a change to the app's data makes stale (`subscribe`). */
|
|
@@ -107,7 +114,10 @@ export interface AppClient<S> {
|
|
|
107
114
|
share(file: Pick<Attachment, "key">, options?: {
|
|
108
115
|
expiresInSeconds?: number;
|
|
109
116
|
}): Promise<PublicLink>;
|
|
110
|
-
/**
|
|
117
|
+
/**
|
|
118
|
+
* 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.
|
|
120
|
+
*/
|
|
111
121
|
session(): Promise<SessionResponse>;
|
|
112
122
|
/**
|
|
113
123
|
* Sign in to the app's pages with Teable, on its own host: the browser goes
|
package/dist/client.js
CHANGED
package/dist/dev/host.js
CHANGED
|
@@ -24,6 +24,10 @@ var PICKS = [
|
|
|
24
24
|
{ who: "outsider", label: "Signed in, not a member of the app's space" },
|
|
25
25
|
{ who: "anonymous", label: "Signed out" }
|
|
26
26
|
];
|
|
27
|
+
var MEMBERS = PICKS.flatMap(({ who, label }) => {
|
|
28
|
+
const role = SPACE_ROLES.find((name) => name === who);
|
|
29
|
+
return role ? [{ userId: `dev-${who}`, name: label, avatar: null, role }] : [];
|
|
30
|
+
});
|
|
27
31
|
function callerOf(request) {
|
|
28
32
|
const cookie = request.headers.get("Cookie") ?? "";
|
|
29
33
|
const who = cookie.match(new RegExp(`(?:^|;\\s*)${DEV_SESSION}=([^;]+)`))?.[1];
|
|
@@ -263,8 +267,11 @@ async function session(request, url) {
|
|
|
263
267
|
headers: { Location: to, "Set-Cookie": cookie(pick) }
|
|
264
268
|
});
|
|
265
269
|
}
|
|
266
|
-
case "GET /session":
|
|
267
|
-
|
|
270
|
+
case "GET /session": {
|
|
271
|
+
const caller = callerOf(request);
|
|
272
|
+
const member = caller.kind === "user" ? MEMBERS.find((m) => m.userId === caller.userId) ?? null : null;
|
|
273
|
+
return Response.json({ caller, expiresAt: null, member });
|
|
274
|
+
}
|
|
268
275
|
case "POST /sign-out":
|
|
269
276
|
return new Response(null, { status: 204, headers: { "Set-Cookie": cookie("anonymous") } });
|
|
270
277
|
}
|
|
@@ -293,6 +300,9 @@ async function api(request, env, url) {
|
|
|
293
300
|
pagesUrl: env.PAGES
|
|
294
301
|
});
|
|
295
302
|
}
|
|
303
|
+
if (path === "members" && request.method === "GET") {
|
|
304
|
+
return needs("viewer") ?? Response.json({ members: MEMBERS });
|
|
305
|
+
}
|
|
296
306
|
const method = path.match(/^methods\/([A-Za-z][A-Za-z0-9_]*)$/)?.[1];
|
|
297
307
|
if (method) {
|
|
298
308
|
const raw = request.method === "GET" ? url.searchParams.get("input") : await request.text();
|
package/dist/protocol.d.ts
CHANGED
|
@@ -408,6 +408,33 @@ export declare const SESSION_PATH = "/.teable";
|
|
|
408
408
|
export interface SessionResponse {
|
|
409
409
|
caller: Caller;
|
|
410
410
|
expiresAt: number | null;
|
|
411
|
+
/**
|
|
412
|
+
* The person signed in, as the app's members list them (ADR 0019): their
|
|
413
|
+
* name and avatar. Null for anyone else, and until the old platform has
|
|
414
|
+
* said who the members are.
|
|
415
|
+
*/
|
|
416
|
+
member: AppMember | null;
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* A member of an app's space (ADR 0019), as the old platform says: someone
|
|
420
|
+
* who may sign in to its pages, with their role in the space (the highest of
|
|
421
|
+
* their own and their departments'). Methods know a caller by `userId`;
|
|
422
|
+
* pages show the person by these.
|
|
423
|
+
*/
|
|
424
|
+
export interface AppMember {
|
|
425
|
+
userId: string;
|
|
426
|
+
name: string;
|
|
427
|
+
/** Their avatar's public URL; null without one. */
|
|
428
|
+
avatar: string | null;
|
|
429
|
+
role: SpaceRole;
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* `GET {APPS_PATH}/:appId/members`: the members of the app's space, for its
|
|
433
|
+
* members (pages ask with their session), in the order the old platform
|
|
434
|
+
* sent them. Empty until it has said who they are.
|
|
435
|
+
*/
|
|
436
|
+
export interface MembersResponse {
|
|
437
|
+
members: AppMember[];
|
|
411
438
|
}
|
|
412
439
|
/**
|
|
413
440
|
* The bridge between the builder's Preview and an app's pages, in its frame:
|
|
@@ -621,6 +648,17 @@ export interface AppOffline {
|
|
|
621
648
|
by: string;
|
|
622
649
|
} | null;
|
|
623
650
|
}
|
|
651
|
+
/**
|
|
652
|
+
* The subdomain of an app's pages (ADR 0018), as `PUT
|
|
653
|
+
* {APPS_PATH}/:appId/subdomain` answers its creators: the one they chose, or
|
|
654
|
+
* null while its pages are at its id's host; and where its pages are with
|
|
655
|
+
* it, once it has them.
|
|
656
|
+
*/
|
|
657
|
+
export interface AppSubdomain {
|
|
658
|
+
subdomain: string | null;
|
|
659
|
+
/** `https://<subdomain>.teable.uk`, or its id's host; null when it has neither. */
|
|
660
|
+
url: string | null;
|
|
661
|
+
}
|
|
624
662
|
/**
|
|
625
663
|
* A secret of an app (ADR 0015), as `GET {APPS_PATH}/:appId/secrets` lists
|
|
626
664
|
* them for its creators: by name, never by value. The app's code writes
|
package/dist/testing.js
CHANGED
package/dist/worker.js
CHANGED