@protobase/server 0.123.3 → 0.123.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/dist/create-admin.js +1 -1
- package/dist/meta.d.ts +10 -1
- package/dist/package.js +1 -1
- package/dist/relay/relay-runtime.js +10 -2
- package/dist/relay/relay-schema.d.ts +5 -2
- package/dist/relay/relay-schema.js +5 -2
- package/dist/relay/sessions-sql.js +14 -10
- package/package.json +6 -6
package/dist/create-admin.js
CHANGED
|
@@ -348,7 +348,7 @@ const createAdmin = ({ resources: appResources, views: appViews = [], userTables
|
|
|
348
348
|
if (auth) auth.mailSenderUse.set(mailSenderUse(db, registry.entries));
|
|
349
349
|
const appName = shownAppName(auth, globalThis.process?.env ?? {});
|
|
350
350
|
const appIcon = icons?.favicon ? faviconPath : void 0;
|
|
351
|
-
const meta = createMeta(deps, appName, appIcon, relay
|
|
351
|
+
const meta = createMeta(deps, appName, appIcon, relay?.meta);
|
|
352
352
|
const onError = createErrorHandler(options.onUnhandledError, deps.statementTimeoutMs);
|
|
353
353
|
const guarded = (routes, caller = authenticate) => {
|
|
354
354
|
const app = new Hono();
|
package/dist/meta.d.ts
CHANGED
|
@@ -63,9 +63,18 @@ export type CallerMeta = {
|
|
|
63
63
|
status?: true;
|
|
64
64
|
/** With `calls`: the app's calls ring people, on any page they have open, through the live stream. */
|
|
65
65
|
calls?: true;
|
|
66
|
-
/**
|
|
66
|
+
/**
|
|
67
|
+
* With `realtime.relay`: the resources whose changes the relay notices on its channels, which pages hear of from it,
|
|
68
|
+
* and, with its presence, the resource and fields pages read who is online, away or offline from.
|
|
69
|
+
*/
|
|
67
70
|
relay?: {
|
|
68
71
|
resources: string[];
|
|
72
|
+
presence?: {
|
|
73
|
+
resource: string;
|
|
74
|
+
user: string;
|
|
75
|
+
status: string;
|
|
76
|
+
at: string;
|
|
77
|
+
};
|
|
69
78
|
};
|
|
70
79
|
/** The language the admin app's screens are in, when the app sets one for everyone. */
|
|
71
80
|
locale?: Locale;
|
package/dist/package.js
CHANGED
|
@@ -46,11 +46,19 @@ const relayRuntime = (options, auth, deps) => {
|
|
|
46
46
|
}
|
|
47
47
|
});
|
|
48
48
|
};
|
|
49
|
-
const
|
|
49
|
+
const meta = {
|
|
50
|
+
resources: [...models.placements.keys()].sort(),
|
|
51
|
+
...models.presence && { presence: {
|
|
52
|
+
resource: models.presence.model.name,
|
|
53
|
+
user: models.presence.user,
|
|
54
|
+
status: models.presence.status,
|
|
55
|
+
at: models.presence.at
|
|
56
|
+
} }
|
|
57
|
+
};
|
|
50
58
|
return {
|
|
51
59
|
jobs: jobs.jobs,
|
|
52
60
|
onChanges,
|
|
53
|
-
|
|
61
|
+
meta,
|
|
54
62
|
routes: () => ticketRoutes({
|
|
55
63
|
deps,
|
|
56
64
|
options,
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { AdminAuth } from "../better-auth/create-auth.js";
|
|
2
2
|
import { Db } from "@protobase/query";
|
|
3
3
|
//#region src/relay/relay-schema.d.ts
|
|
4
|
-
/**
|
|
5
|
-
|
|
4
|
+
/**
|
|
5
|
+
* The SQL the relay needs of the app's database: the trigger that closes a deleted session's sockets; `undefined` when
|
|
6
|
+
* it is current. `authWritten`: the same migration writes the auth store's steps before it.
|
|
7
|
+
*/
|
|
8
|
+
export declare const relayMigration: (db: Db, auth: AdminAuth | undefined, authWritten: boolean) => Promise<string | undefined>;
|
|
6
9
|
/** Refuses to start while the relay's trigger is missing or out of date. */
|
|
7
10
|
export declare const checkRelaySchema: (db: Db, auth: AdminAuth | undefined) => Promise<void>;
|
|
8
11
|
//#endregion
|
|
@@ -5,8 +5,11 @@ const needsAuth = (auth) => {
|
|
|
5
5
|
if (!auth) throw new Error("relay needs the app's own sign-in (auth), whose sessions its tickets name and end");
|
|
6
6
|
return auth;
|
|
7
7
|
};
|
|
8
|
-
/**
|
|
9
|
-
|
|
8
|
+
/**
|
|
9
|
+
* The SQL the relay needs of the app's database: the trigger that closes a deleted session's sockets; `undefined` when
|
|
10
|
+
* it is current. `authWritten`: the same migration writes the auth store's steps before it.
|
|
11
|
+
*/
|
|
12
|
+
const relayMigration = (db, auth, authWritten) => relaySessionsMigration(db, sessionsTable(needsAuth(auth)), authWritten);
|
|
10
13
|
/** Refuses to start while the relay's trigger is missing or out of date. */
|
|
11
14
|
const checkRelaySchema = (db, auth) => checkRelaySessions(db, sessionsTable(needsAuth(auth)));
|
|
12
15
|
//#endregion
|
|
@@ -32,29 +32,33 @@ $$`,
|
|
|
32
32
|
`create trigger ${triggerName} after delete on ${sessions} referencing old table as ended for each statement execute function ${relaySchema}.session_ended()`
|
|
33
33
|
];
|
|
34
34
|
/**
|
|
35
|
-
* Refuses a sessions table the app's database does not have
|
|
36
|
-
* the
|
|
35
|
+
* Refuses a sessions table the app's database does not have, nor gets from the migration that writes the trigger
|
|
36
|
+
* after the auth store's steps (`written`): the trigger queues its job in the app's jobs queue, so the relay needs the
|
|
37
|
+
* auth store in the app's own database, as the `auth` config puts it.
|
|
37
38
|
*/
|
|
38
|
-
const refuseSessionsElsewhere = (table, sessions) => {
|
|
39
|
-
if (table) return;
|
|
39
|
+
const refuseSessionsElsewhere = (table, written, sessions) => {
|
|
40
|
+
if (table || written) return;
|
|
40
41
|
throw new Error(`The relay needs the sign-in sessions table ${sessions} in the app's own database, whose jobs queue closes ended sessions' sockets, but the app's database has no such table: keep the auth store in the app's database to use the relay.`);
|
|
41
42
|
};
|
|
42
|
-
const current = async (db, sessions) => {
|
|
43
|
+
const current = async (db, sessions, written) => {
|
|
43
44
|
const { rows } = await sql`select to_regclass(${sessions}) is not null as here, exists (
|
|
44
45
|
select from pg_trigger t join pg_proc p on p.oid = t.tgfoid
|
|
45
46
|
where t.tgrelid = to_regclass(${sessions}) and t.tgname = ${triggerName} and obj_description(p.oid, 'pg_proc') = ${sessionsComment}
|
|
46
47
|
) as found`.execute(db);
|
|
47
|
-
refuseSessionsElsewhere(rows[0].here, sessions);
|
|
48
|
+
refuseSessionsElsewhere(rows[0].here, written, sessions);
|
|
48
49
|
return rows[0].found;
|
|
49
50
|
};
|
|
50
|
-
/**
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
/**
|
|
52
|
+
* The SQL that ends deleted sessions' sockets on the relay (`sessionsSql`); `undefined` when it is current. `written`:
|
|
53
|
+
* the same migration writes the auth store's steps before it, which create the sessions table the database lacks yet.
|
|
54
|
+
*/
|
|
55
|
+
const relaySessionsMigration = async (db, sessions, written) => {
|
|
56
|
+
if (await current(db, sessions, written)) return;
|
|
53
57
|
return `${sessionsSql(sessions).join(";\n\n")};`;
|
|
54
58
|
};
|
|
55
59
|
/** Refuses to start while deleted sessions would keep their sockets on the relay. */
|
|
56
60
|
const checkRelaySessions = async (db, sessions) => {
|
|
57
|
-
if (await current(db, sessions)) return;
|
|
61
|
+
if (await current(db, sessions, false)) return;
|
|
58
62
|
throw new Error(`The trigger that closes a deleted session's sockets on the relay is missing or out of date on ${sessions}. Write it as a migration with \`${migrationCommand}\`, apply it with the project's migrations, then start again.`);
|
|
59
63
|
};
|
|
60
64
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/server",
|
|
3
|
-
"version": "0.123.
|
|
3
|
+
"version": "0.123.5",
|
|
4
4
|
"description": "The Protobase REST API as a Hono app, with Better Auth sign-in.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -44,11 +44,11 @@
|
|
|
44
44
|
"@better-auth/sso": "^1.7.12",
|
|
45
45
|
"@livekit/protocol": "1.53.1",
|
|
46
46
|
"@modelcontextprotocol/server": "^2.3.1",
|
|
47
|
-
"@protobase/layout": "0.123.
|
|
48
|
-
"@protobase/query": "0.123.
|
|
49
|
-
"@protobase/schema": "0.123.
|
|
50
|
-
"@protobase/workflow-plugins": "0.123.
|
|
51
|
-
"@protobase/workflows": "0.123.
|
|
47
|
+
"@protobase/layout": "0.123.5",
|
|
48
|
+
"@protobase/query": "0.123.5",
|
|
49
|
+
"@protobase/schema": "0.123.5",
|
|
50
|
+
"@protobase/workflow-plugins": "0.123.5",
|
|
51
|
+
"@protobase/workflows": "0.123.5",
|
|
52
52
|
"@react-email/render": "^2.1.0",
|
|
53
53
|
"@react-pdf/primitives": "^4.4.0",
|
|
54
54
|
"@react-pdf/renderer": "^4.9.0",
|