@protobase/cli 0.121.1 → 0.121.3
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/cli/package.js +1 -1
- package/dist/config/build-project.js +2 -0
- package/dist/config/mail-feedback-config.js +9 -0
- package/dist/dev/entry.js +2 -1
- package/dist/doctor/built-in-models.js +2 -1
- package/dist/main.js +2 -0
- package/dist/migration/load-project.js +2 -0
- package/dist/migration/parts.js +15 -3
- package/dist/project/project-admin.js +1 -0
- package/dist/relay/app-entry.js +10 -0
- package/dist/relay/register.js +18 -0
- package/dist/serve/startup-checks.js +5 -2
- package/package.json +8 -8
- package/skills/protobase/SKILL.md +1 -0
- package/skills/protobase/references/features/email-and-public-forms.md +1 -0
- package/skills/protobase/references/features/history-comments-and-live-updates.md +3 -0
- package/skills/protobase/references/reference/cli.md +9 -1
- package/skills/protobase/references/reference/config/api.md +2 -2
- package/skills/protobase/references/reference/config/jobs-and-events.md +11 -0
- package/skills/protobase/references/reference/config.md +1 -1
- package/skills/protobase/references/reference/email.md +32 -0
- package/skills/protobase/references/reference/realtime-relay.md +72 -0
- package/skills/protobase/references/reference/webhooks.md +1 -1
package/dist/cli/package.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { projectDerived, projectFiles, projectFunctions, projectJobs, projectNotifications, projectOptions, projectResources, projectWebhooks, projectWorkflows } from "./project-parts.js";
|
|
2
|
+
import { mailFeedbackOn } from "./mail-feedback-config.js";
|
|
2
3
|
import { projectUnsubscribe } from "./unsubscribe-config.js";
|
|
3
4
|
import { userTablesOn } from "./user-tables-config.js";
|
|
4
5
|
import { buildAppAuth, buildAuthenticator, checkCallsOptions, checkStatusOptions, isOverSignIn, workflowPlugins } from "@protobase/server/internal";
|
|
@@ -91,6 +92,7 @@ const buildProject = async (config, database) => {
|
|
|
91
92
|
...config.status && { status: checkStatusOptions(config.status) },
|
|
92
93
|
...config.calls && { calls: checkCallsOptions(config.calls) },
|
|
93
94
|
...unsubscribe && { unsubscribe },
|
|
95
|
+
...mailFeedbackOn(config) && { mailFeedback: true },
|
|
94
96
|
...mailer && { mailer },
|
|
95
97
|
...config.mobile && { mobile: config.mobile },
|
|
96
98
|
...config.secret && { secret: config.secret },
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/config/mail-feedback-config.ts
|
|
2
|
+
/** Whether the app takes its mail's bounces and complaints: the one reading of `mailFeedback`, which takes only true or false. */
|
|
3
|
+
const mailFeedbackOn = (config) => {
|
|
4
|
+
const value = config.mailFeedback;
|
|
5
|
+
if (value !== void 0 && typeof value !== "boolean") throw new Error(`mailFeedback is ${JSON.stringify(value)}; it takes true or false`);
|
|
6
|
+
return value === true;
|
|
7
|
+
};
|
|
8
|
+
//#endregion
|
|
9
|
+
export { mailFeedbackOn };
|
package/dist/dev/entry.js
CHANGED
|
@@ -7,7 +7,7 @@ import { devRealtimePrune } from "./dev-prune.js";
|
|
|
7
7
|
import { devDatabase, loadDevConfig } from "./project.js";
|
|
8
8
|
import { withDevServiceWorker } from "./service-worker-route.js";
|
|
9
9
|
import { setMissing, supabaseEnv } from "./supabase-env.js";
|
|
10
|
-
import { apiKeySettings, assistantSettings, authSchemaDrift, authStoreTables, checkAi, checkAuthSchema, checkCalls, checkChanges, checkChannelSends, checkComments, checkComputed, checkDerived, checkNotificationsSchema, checkQueryRunner, checkRealtimeRelay, checkResourcesOutsideAuthStore, checkStatusSchema, checkUserTablesSchema, checkWebhooksSchema, checkWorkflowsSchema, configExports, hasUsers, relayed, sqlSends } from "@protobase/server";
|
|
10
|
+
import { apiKeySettings, assistantSettings, authSchemaDrift, authStoreTables, checkAi, checkAuthSchema, checkCalls, checkChanges, checkChannelSends, checkComments, checkComputed, checkDerived, checkNotificationsSchema, checkQueryRunner, checkRealtimeRelay, checkRelaySchema, checkResourcesOutsideAuthStore, checkStatusSchema, checkUserTablesSchema, checkWebhooksSchema, checkWorkflowsSchema, configExports, hasUsers, relayed, sqlSends } from "@protobase/server";
|
|
11
11
|
import { upgradeWebSocket } from "@hono/node-server";
|
|
12
12
|
import { Hono } from "hono";
|
|
13
13
|
//#region src/dev/entry.ts
|
|
@@ -42,6 +42,7 @@ if (project.webhooks) await checkWebhooksSchema(db, project.webhooks);
|
|
|
42
42
|
if (project.workflows) await checkWorkflowsSchema(db, project.workflows);
|
|
43
43
|
if (relayed(project.realtime)) await checkRealtimeRelay(db);
|
|
44
44
|
if (sqlSends(project.realtime)) await checkChannelSends(db);
|
|
45
|
+
if (project.realtime?.relay) await checkRelaySchema(db, project.auth);
|
|
45
46
|
if (project.notifications) await checkNotificationsSchema(db, project.notifications, project.auth);
|
|
46
47
|
if (project.status) await checkStatusSchema(db, project.status, project.auth);
|
|
47
48
|
if (project.userTables) await checkUserTablesSchema(db);
|
|
@@ -2,7 +2,7 @@ import { builtInResources, configExports, webhooksModule, workflowsModule } from
|
|
|
2
2
|
//#region src/doctor/built-in-models.ts
|
|
3
3
|
/**
|
|
4
4
|
* The resources and views Protobase adds to an app by what its config enables, as the API serves them: the webhook ones
|
|
5
|
-
* of `webhooks` and the workflow ones of `workflows`, then Failed jobs, Activity and Comments by what the app's resources use, and
|
|
5
|
+
* of `webhooks` and the workflow ones of `workflows`, then Failed jobs, Activity and Comments by what the app's resources use, Unsubscribes with `unsubscribe` and Mail feedback with `mailFeedback`. Doctor checks them as it checks
|
|
6
6
|
* the app's own.
|
|
7
7
|
*/
|
|
8
8
|
const builtInModels = (config, models) => {
|
|
@@ -18,6 +18,7 @@ const builtInModels = (config, models) => {
|
|
|
18
18
|
jobs: Object.keys(config.jobs).length > 0,
|
|
19
19
|
notifications: config.notifications !== void 0,
|
|
20
20
|
unsubscribe: config.unsubscribe === true,
|
|
21
|
+
mailFeedback: config.mailFeedback === true,
|
|
21
22
|
...config.events && { events: config.events }
|
|
22
23
|
});
|
|
23
24
|
return {
|
package/dist/main.js
CHANGED
|
@@ -10,6 +10,7 @@ import { registerEncryption } from "./encryption/register.js";
|
|
|
10
10
|
import { registerMigration } from "./migration/register.js";
|
|
11
11
|
import { registerMobile } from "./mobile/register.js";
|
|
12
12
|
import { registerNotifications } from "./notifications/register.js";
|
|
13
|
+
import { registerRelay } from "./relay/register.js";
|
|
13
14
|
import { protobaseVersion } from "./version/version.js";
|
|
14
15
|
import { registerSkill } from "./skill/register.js";
|
|
15
16
|
import { registerImport } from "./supabase/register.js";
|
|
@@ -202,6 +203,7 @@ registerSkill(program);
|
|
|
202
203
|
registerImport(program);
|
|
203
204
|
registerMobile(program);
|
|
204
205
|
registerNotifications(program);
|
|
206
|
+
registerRelay(program);
|
|
205
207
|
const run = (argv) => program.parseAsync(argv).catch((error) => {
|
|
206
208
|
if (error instanceof ExitSignal) {
|
|
207
209
|
process.exitCode = error.code;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { loadNearestEnvFile } from "../dev/env.js";
|
|
2
2
|
import { projectJobs, projectNotifications, projectResources, projectWebhooks } from "../config/project-parts.js";
|
|
3
|
+
import { mailFeedbackOn } from "../config/mail-feedback-config.js";
|
|
3
4
|
import { unsubscribeOn } from "../config/unsubscribe-config.js";
|
|
4
5
|
import { userTablesOn } from "../config/user-tables-config.js";
|
|
5
6
|
import { projectAuth } from "../config/build-project.js";
|
|
@@ -49,6 +50,7 @@ const migrationProject = async (config, url) => {
|
|
|
49
50
|
jobs,
|
|
50
51
|
userTables: userTablesOn(config),
|
|
51
52
|
unsubscribe: unsubscribeOn(config),
|
|
53
|
+
mailFeedback: mailFeedbackOn(config),
|
|
52
54
|
readOnlyQueries: assistantSettings(config.assistant, process.env)?.kind === "built-in",
|
|
53
55
|
authTables: auth ? authStoreTables(auth) : {
|
|
54
56
|
tables: [],
|
package/dist/migration/parts.js
CHANGED
|
@@ -1,25 +1,32 @@
|
|
|
1
1
|
import { authMigrationTitle } from "../auth/migration-file.js";
|
|
2
|
-
import { authSchemaMigration, callsMigration, capturedBy, changesMigration, channelSendsMigration, commentsMigration, computedMigration, derivedMigration, jobsSchemaMigration, notificationsMigration, ownedDefinitionsMigration, queryRunnerMigration, realtimeRelayMigration, relayed, sqlSends, statusMigration, unsubscribesMigration, userTablesMigration, webhooksMigration, workflowsMigration } from "@protobase/server";
|
|
2
|
+
import { authSchemaMigration, callsMigration, capturedBy, changesMigration, channelSendsMigration, commentsMigration, computedMigration, derivedMigration, jobsSchemaMigration, mailFeedbackMigration, mailFeedbackResource, notificationsMigration, ownedDefinitionsMigration, queryRunnerMigration, realtimeRelayMigration, relayMigration, relayed, sqlSends, statusMigration, unsubscribesMigration, userTablesMigration, webhooksMigration, workflowsMigration } from "@protobase/server";
|
|
3
3
|
//#region src/migration/parts.ts
|
|
4
4
|
/** Every feature the project's config enables, in the order their files are written. */
|
|
5
5
|
const migrationParts = (project) => {
|
|
6
6
|
const comments = project.models.some((model) => model.comments);
|
|
7
7
|
const aiFields = project.models.some((model) => Object.values(model.fields).some((field) => field.ai));
|
|
8
|
+
const feedback = project.mailFeedback ? [mailFeedbackResource.toModel()] : [];
|
|
9
|
+
const captured = [...project.models, ...feedback];
|
|
8
10
|
return [
|
|
9
11
|
...project.auth ? [{
|
|
10
12
|
name: "auth",
|
|
11
13
|
title: authMigrationTitle,
|
|
12
14
|
sql: () => authSchemaMigration(project.auth)
|
|
13
15
|
}] : [],
|
|
14
|
-
...project.jobs.length > 0 ||
|
|
16
|
+
...project.jobs.length > 0 || captured.some(capturedBy(captured)) || comments || aiFields || project.webhooks || project.workflows || project.notifications || project.realtime?.relay ? [{
|
|
15
17
|
name: "jobs",
|
|
16
18
|
title: "The jobs schema this version of Protobase needs",
|
|
17
19
|
sql: () => jobsSchemaMigration(project.db)
|
|
18
20
|
}] : [],
|
|
21
|
+
...project.mailFeedback ? [{
|
|
22
|
+
name: "mail_feedback",
|
|
23
|
+
title: "The table of the bounces and complaints of the mail the app sends",
|
|
24
|
+
sql: () => mailFeedbackMigration(project.db)
|
|
25
|
+
}] : [],
|
|
19
26
|
{
|
|
20
27
|
name: "changes",
|
|
21
28
|
title: "The change capture the resources' events and history need",
|
|
22
|
-
sql: () => changesMigration(project.db, project.
|
|
29
|
+
sql: () => changesMigration(project.db, captured, project.events, feedback.map((model) => model.name))
|
|
23
30
|
},
|
|
24
31
|
{
|
|
25
32
|
name: "computed",
|
|
@@ -86,6 +93,11 @@ const migrationParts = (project) => {
|
|
|
86
93
|
title: "The delete of the definitions of user tables that resources in code own now",
|
|
87
94
|
sql: () => ownedDefinitionsMigration(project.db, project.models)
|
|
88
95
|
}] : [],
|
|
96
|
+
...project.realtime?.relay ? [{
|
|
97
|
+
name: "relay",
|
|
98
|
+
title: "The trigger that closes a deleted sign-in session's sockets on the realtime relay",
|
|
99
|
+
sql: () => relayMigration(project.db, project.auth)
|
|
100
|
+
}] : [],
|
|
89
101
|
...sqlSends(project.realtime) ? [{
|
|
90
102
|
name: "channel_sends",
|
|
91
103
|
title: "SQL's broadcasts to the record channels, channels.send()",
|
|
@@ -39,6 +39,7 @@ const projectAdmin = (project, db, ui, reporter, upgradeWebSocket, userTables) =
|
|
|
39
39
|
...project.notifications && { notifications: project.notifications },
|
|
40
40
|
...project.status && { status: project.status },
|
|
41
41
|
...project.unsubscribe && { unsubscribe: project.unsubscribe },
|
|
42
|
+
...project.mailFeedback && { mailFeedback: true },
|
|
42
43
|
...project.calls && { calls: project.calls },
|
|
43
44
|
...project.mobile && { mobile: project.mobile },
|
|
44
45
|
...project.app && { app: project.app },
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
//#region src/relay/app-entry.ts
|
|
2
|
+
/** The app's entry in the relay's apps file: its id, its keys and the browser origin of its URL. */
|
|
3
|
+
const relayAppEntry = (relay, appUrl) => ({
|
|
4
|
+
id: relay.app,
|
|
5
|
+
api_keys: [relay.apiKey],
|
|
6
|
+
ticket_keys: [relay.ticketKey],
|
|
7
|
+
origins: appUrl ? [new URL(appUrl).origin] : []
|
|
8
|
+
});
|
|
9
|
+
//#endregion
|
|
10
|
+
export { relayAppEntry };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/relay/register.ts
|
|
2
|
+
const registerRelay = (program) => {
|
|
3
|
+
program.command("relay").description("The realtime relay the app hands its connections to (realtime.relay)").command("app").description("Print the app's entry for the relay's apps file, from realtime.relay and url").action(async () => {
|
|
4
|
+
const [{ checkRelayOptions }, { loadSourceConfig }, { loadNearestEnvFile }, { relayAppEntry }] = await Promise.all([
|
|
5
|
+
import("@protobase/server"),
|
|
6
|
+
import("../config/source-config.js"),
|
|
7
|
+
import("../dev/env.js"),
|
|
8
|
+
import("./app-entry.js")
|
|
9
|
+
]);
|
|
10
|
+
loadNearestEnvFile(process.cwd());
|
|
11
|
+
const config = await loadSourceConfig(process.cwd(), { command: "tool" });
|
|
12
|
+
if (!config.realtime?.relay) throw new Error("The config has no realtime.relay");
|
|
13
|
+
const url = config.url ?? process.env.PROTOBASE_URL;
|
|
14
|
+
process.stdout.write(`${JSON.stringify(relayAppEntry(checkRelayOptions(config.realtime.relay), url), null, 2)}\n`);
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
//#endregion
|
|
18
|
+
export { registerRelay };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { assistantSettings, authStoreTables, checkAuthSchema, checkCalls, checkChanges, checkChannelSends, checkComments, checkComputed, checkDerived, checkNotificationsSchema, checkQueryRunner, checkRealtimeRelay, checkResourcesOutsideAuthStore, checkStatusSchema, checkUnsubscribesSchema, checkUserTablesSchema, checkWebhooksSchema, checkWorkflowsSchema, configExports, relayed, sqlSends } from "@protobase/server";
|
|
1
|
+
import { assistantSettings, authStoreTables, checkAuthSchema, checkCalls, checkChanges, checkChannelSends, checkComments, checkComputed, checkDerived, checkMailFeedbackSchema, checkNotificationsSchema, checkQueryRunner, checkRealtimeRelay, checkRelaySchema, checkResourcesOutsideAuthStore, checkStatusSchema, checkUnsubscribesSchema, checkUserTablesSchema, checkWebhooksSchema, checkWorkflowsSchema, configExports, mailFeedbackResource, relayed, sqlSends } from "@protobase/server";
|
|
2
2
|
//#region src/serve/startup-checks.ts
|
|
3
3
|
/**
|
|
4
4
|
* The server's startup checks of the database: each throws, with what to write as a migration, while a schema the
|
|
@@ -7,9 +7,11 @@ import { assistantSettings, authStoreTables, checkAuthSchema, checkCalls, checkC
|
|
|
7
7
|
*/
|
|
8
8
|
const checkStartup = async (project, db) => {
|
|
9
9
|
const models = configExports(project.config).resources.map((resource) => resource.toModel());
|
|
10
|
+
const captured = project.mailFeedback ? [...models, mailFeedbackResource.toModel()] : models;
|
|
10
11
|
if (project.auth) await checkAuthSchema(project.auth);
|
|
11
12
|
if (project.auth) await checkResourcesOutsideAuthStore(db, models, project.auth);
|
|
12
|
-
|
|
13
|
+
if (project.mailFeedback) await checkMailFeedbackSchema(db);
|
|
14
|
+
await checkChanges(db, captured, project.events);
|
|
13
15
|
await checkComments(db, models);
|
|
14
16
|
await checkDerived(db, models);
|
|
15
17
|
await checkCalls(db, project.calls, project.events);
|
|
@@ -22,6 +24,7 @@ const checkStartup = async (project, db) => {
|
|
|
22
24
|
if (project.workflows) await checkWorkflowsSchema(db, project.workflows);
|
|
23
25
|
if (relayed(project.realtime)) await checkRealtimeRelay(db);
|
|
24
26
|
if (sqlSends(project.realtime)) await checkChannelSends(db);
|
|
27
|
+
if (project.realtime?.relay) await checkRelaySchema(db, project.auth);
|
|
25
28
|
if (project.notifications) await checkNotificationsSchema(db, project.notifications, project.auth);
|
|
26
29
|
if (project.status) await checkStatusSchema(db, project.status, project.auth);
|
|
27
30
|
if (project.unsubscribe) await checkUnsubscribesSchema(db);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.121.
|
|
3
|
+
"version": "0.121.3",
|
|
4
4
|
"description": "The protobase command: scaffold, doctor, dev, build and serve a Protobase project.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -43,13 +43,13 @@
|
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@better-auth/core": "^1.7.12",
|
|
45
45
|
"@hono/node-server": "^2.1.3",
|
|
46
|
-
"@protobase/config": "0.121.
|
|
47
|
-
"@protobase/layout": "0.121.
|
|
48
|
-
"@protobase/query": "0.121.
|
|
49
|
-
"@protobase/schema": "0.121.
|
|
50
|
-
"@protobase/server": "0.121.
|
|
51
|
-
"@protobase/ui": "0.121.
|
|
52
|
-
"@protobase/workflows": "0.121.
|
|
46
|
+
"@protobase/config": "0.121.3",
|
|
47
|
+
"@protobase/layout": "0.121.3",
|
|
48
|
+
"@protobase/query": "0.121.3",
|
|
49
|
+
"@protobase/schema": "0.121.3",
|
|
50
|
+
"@protobase/server": "0.121.3",
|
|
51
|
+
"@protobase/ui": "0.121.3",
|
|
52
|
+
"@protobase/workflows": "0.121.3",
|
|
53
53
|
"@react-email/render": "^2.1.0",
|
|
54
54
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
55
55
|
"@sentry/vite-plugin": "^11.10.0",
|
|
@@ -84,6 +84,7 @@ Reference:
|
|
|
84
84
|
- When adding comments to records → read [Record comments](references/reference/comments.md)
|
|
85
85
|
- When open pages should refresh as records change → read [Live updates](references/reference/live.md)
|
|
86
86
|
- When pages on a record should see who else is there or send each other short-lived events (presence, broadcast) → read [Channels](references/reference/channels.md)
|
|
87
|
+
- When the app should hand its realtime connections to a relay, so it can sleep while people stay connected (tickets, channel members, change notices) → read [Realtime relay](references/reference/realtime-relay.md)
|
|
87
88
|
- When an app uses supabase-js Realtime (`postgres_changes` under RLS, broadcast, presence) → read [Supabase Realtime](references/reference/supabase-realtime.md)
|
|
88
89
|
- When filling fields with a model → read [AI fields and actions](references/reference/ai.md)
|
|
89
90
|
- When letting people without an account create records → read [Public forms](references/reference/forms.md)
|
|
@@ -11,6 +11,7 @@ Mail the app sends, the PDF documents it makes, and forms for people without an
|
|
|
11
11
|
- [Protobase's mail look](../reference/email.md#the-look-of-protobases-own-mail): Your emails use a layout, button, code and note with the look of Protobase's own mail.
|
|
12
12
|
- [Header fields](../reference/email.md#templates): Your emails carry header fields of their own.
|
|
13
13
|
- [One-click unsubscribe](../reference/email.md#unsubscribe) (beta): Mail you mark as bulk carries a one-click unsubscribe, and Protobase stops sending that kind of mail to whoever used it.
|
|
14
|
+
- [Bounces and complaints](../reference/email.md#bounces-and-complaints) (beta): Bounces and spam complaints that Amazon SES or Resend report arrive as Mail feedback records with `bounced` and `complained` events, so a workflow, webhook or your own code can act on them.
|
|
14
15
|
- [Attachments](../reference/email.md#attachments): A message carries files, such as an invoice's PDF, through the app's mail or someone's own mailbox.
|
|
15
16
|
- [PDF documents](../reference/pdf.md#documents): PDF files such as invoices and quotes are React components with typed data, rendered from jobs, hooks or functions and attached to mail as they are.
|
|
16
17
|
- [Mail from your own mailbox](../reference/email.md#from-someones-own-mailbox) (beta): People link their Gmail on the account page, and the app's functions send mail from it; an action offers to connect the mailbox right there when the link is missing or expired.
|
|
@@ -17,4 +17,7 @@ The changes of each record, comments on it, and pages that refresh as records ch
|
|
|
17
17
|
- [Change stream](../reference/live.md#the-stream): Apps follow record changes over a stream that catches up after a reconnect.
|
|
18
18
|
- [Polling, then a socket](../reference/live.md#polling-then-a-socket): Apps and Node scripts poll for changes first and switch to a WebSocket after 30 seconds, or at once, falling back to polling while the socket is down.
|
|
19
19
|
- [Presence](../reference/channels.md#presence) (beta): Apps see who else has a record open and what each of them tracks, such as online or away, for whoever may read the record.
|
|
20
|
+
- [Realtime relay](../reference/realtime-relay.md) (in development): Apps hand their realtime connections to a relay, so they and their database can sleep while people stay connected: the app issues connect tickets for signed-in people and visitors, keeps the relay's channel members in step with its members records, tells each channel's members of every change, and closes a session's sockets when it signs out or expires.
|
|
21
|
+
- Relay presence (coming soon): The relay reports who comes online, goes away and goes offline, and the app records it, raises its events and tells the right people.
|
|
22
|
+
- Relay client events (coming soon): Clients send each other events such as typing through the relay, as each channel resource declares them, with a schema, a size and a rate.
|
|
20
23
|
- [Broadcasts](../reference/channels.md#broadcasts) (beta): Apps on a record send each other short-lived events, such as typing, which are never stored, as JSON or as bytes, such as a chunk of audio or a drawing stroke; the app's own code sends them too, from an API function, over HTTP or [from SQL](../reference/channels.md#from-sql) with `channels.send()`.
|
|
@@ -634,7 +634,7 @@ Applies the project's `db/migrations/*.sql` that the database has not applied ye
|
|
|
634
634
|
protobase migration [--dir db/migrations] [--extend <dir>]
|
|
635
635
|
```
|
|
636
636
|
|
|
637
|
-
Writes what the database still needs for every feature the config enables, as the project's next migrations in `--dir`, one file per feature: the auth schema when sign-in is on (`NNN_auth.sql`, as [`auth migration`](#auth-migration) writes it), the [jobs schema](jobs.md#the-jobs-schema) when the config has jobs, `webhooks`, `workflows` or `
|
|
637
|
+
Writes what the database still needs for every feature the config enables, as the project's next migrations in `--dir`, one file per feature: the auth schema when sign-in is on (`NNN_auth.sql`, as [`auth migration`](#auth-migration) writes it), the [jobs schema](jobs.md#the-jobs-schema) when the config has jobs, `webhooks`, `workflows`, `notifications` or `mailFeedback`, or a resource has events, history, comments or an [AI field](ai.md) (`NNN_jobs.sql`), the table of the bounces and complaints of [`mailFeedback`](email.md#bounces-and-complaints) (`NNN_mail_feedback.sql`), the [capture of events](events.md#migrations-and-startup) and the [history table](history.md#the-table) (`NNN_changes.sql`), the columns of [rollup and formula fields](data-config.md#rollups-and-formulas), the triggers that keep the rollups, and the tables, indexes and refresh functions of [time rollups](data-config.md#time-rollups) (`NNN_computed.sql`), the role the [assistant's read-only queries](assistant.md#the-built-in-backend) run as, when it finds the built-in assistant's key (`NNN_query.sql`), the [comments table](comments.md#the-table) (`NNN_comments.sql`), the [webhook subscriptions](webhooks.md#subscriptions-in-the-admin-app) of `webhooks` (`NNN_webhooks.sql`), the [workflows, versions, runs and steps](workflows.md#turning-them-on) of `workflows` (`NNN_workflows.sql`), the [devices and history tables](notifications.md#table-names) of `notifications` (`NNN_notifications.sql`), the table of who unsubscribed from bulk mail of [`unsubscribe`](email.md#unsubscribe) (`NNN_unsubscribes.sql`), the `realtime_relay` schema of [`realtime: { processes: 'many' }`](supabase-realtime.md#several-processes) (`NNN_realtime_relay.sql`), the `channels` schema of [`realtime: { sqlSends: true }`](channels.md#from-sql) (`NNN_channel_sends.sql`), the trigger of [`realtime.relay`](realtime-relay.md#sessions) that ends a deleted session's sockets (`NNN_relay.sql`), and, with [`userTables`](user-tables.md#the-switch), the schemas of user tables (`NNN_user_tables.sql`) and the delete of the definitions of tables that resources in code [own now](user-tables.md#taking-a-table-over-as-code) (`NNN_owned_definitions.sql`). It compares the database, with the project's migrations applied, with the config (for the auth schema, it reads the store's record of the migrations it applied), merged with those of `--extend` as `dev` merges them, and writes nothing when the database is current. Apply the files with the project's other migrations. It reads the `.env` nearest the current directory and needs `DATABASE_URL`.
|
|
638
638
|
|
|
639
639
|
```sh
|
|
640
640
|
bun run db:migrate # the database at the project's current schema
|
|
@@ -642,6 +642,14 @@ bun run protobase migration # writes db/migrations/NNN_auth.sql, NNN_jobs.
|
|
|
642
642
|
bun run db:migrate # applies them
|
|
643
643
|
```
|
|
644
644
|
|
|
645
|
+
## `relay app`
|
|
646
|
+
|
|
647
|
+
```sh
|
|
648
|
+
protobase relay app
|
|
649
|
+
```
|
|
650
|
+
|
|
651
|
+
Prints the app's entry for the apps file of the [realtime relay](realtime-relay.md), as JSON: its `id`, `api_keys` and `ticket_keys` from `realtime.relay`, and in `origins` the origin of the app's `url` (or `PROTOBASE_URL`). Add the relay's limits and options to it there. It reads `protobase.config.ts` with `command: 'tool'` and the `.env` nearest the current directory.
|
|
652
|
+
|
|
645
653
|
## `auth migration`
|
|
646
654
|
|
|
647
655
|
```sh
|
|
@@ -151,10 +151,10 @@ export default defineConfig({ runtimeUpdates: false })
|
|
|
151
151
|
|
|
152
152
|
## realtime
|
|
153
153
|
|
|
154
|
-
- **Type:** `{ processes?: 'one' | 'many', sqlSends?: boolean }`
|
|
154
|
+
- **Type:** `{ processes?: 'one' | 'many', sqlSends?: boolean, relay?: { url, app, apiKey, ticketKey, channels } }`
|
|
155
155
|
- **Default:** `{ processes: 'one', sqlSends: false }`
|
|
156
156
|
|
|
157
|
-
How [channels](../channels.md) and [Supabase Realtime](../supabase-realtime.md) are served. With `'one'`, one process serves the app, and broadcasts and presence go between its channels in memory. Set `'many'` when several processes serve the app behind one address: broadcasts and presence then go between the processes through the `realtime_relay` schema of the app's database, which [`protobase migration`](../cli.md#migration) writes and the server checks at start. See [Several processes](../channels.md#several-processes). Set `sqlSends: true` to let SQL in the app's database broadcast to channels with `channels.send()`, from the `channels` schema that `protobase migration` writes and the server checks at start. See [From SQL](../channels.md#from-sql).
|
|
157
|
+
How [channels](../channels.md) and [Supabase Realtime](../supabase-realtime.md) are served. With `'one'`, one process serves the app, and broadcasts and presence go between its channels in memory. Set `'many'` when several processes serve the app behind one address: broadcasts and presence then go between the processes through the `realtime_relay` schema of the app's database, which [`protobase migration`](../cli.md#migration) writes and the server checks at start. See [Several processes](../channels.md#several-processes). Set `sqlSends: true` to let SQL in the app's database broadcast to channels with `channels.send()`, from the `channels` schema that `protobase migration` writes and the server checks at start. See [From SQL](../channels.md#from-sql). With `relay`, the app also hands its realtime connections to a relay, so it can sleep while people stay connected; see [Realtime relay](../realtime-relay.md).
|
|
158
158
|
|
|
159
159
|
```ts
|
|
160
160
|
export default defineConfig({ realtime: { processes: 'many', sqlSends: true } })
|
|
@@ -386,3 +386,14 @@ Gives bulk mail a one-click unsubscribe: mail a job sends with `bulk: true` and
|
|
|
386
386
|
```ts
|
|
387
387
|
export default defineConfig({ unsubscribe: true })
|
|
388
388
|
```
|
|
389
|
+
|
|
390
|
+
## mailFeedback
|
|
391
|
+
|
|
392
|
+
- **Type:** `boolean`
|
|
393
|
+
- **Default:** `false`
|
|
394
|
+
|
|
395
|
+
Takes the bounces and spam complaints of the mail the app sends as `mail_feedback` records, with the events `mail_feedback.bounced` and `mail_feedback.complained`, at `POST /api/mail/feedback/<provider>` for each provider whose variable is set. The table, `mail.feedback`, and the capture of its events are written by `protobase migration` as migrations of the project's own: apply them with the project's migrations, as `protobase serve` refuses to start while the table is missing. See [Bounces and complaints](../email.md#bounces-and-complaints).
|
|
396
|
+
|
|
397
|
+
```ts
|
|
398
|
+
export default defineConfig({ mailFeedback: true })
|
|
399
|
+
```
|
|
@@ -30,7 +30,7 @@ Each key is described with its type and default in the option pages:
|
|
|
30
30
|
| [Sign-in options](config/sign-in.md) | `auth`, `authenticate`, `signingKeyDays`, `signingKeyGraceDays` |
|
|
31
31
|
| [API options](config/api.md) | `apiPath`, `apiKeys`, `cors`, `defaultAccess`, `rowPermissions`, `statementTimeoutMs`, `scanGuard`, `errorReporting`, `writeHooks`, `mcpEndpoint`, `remoteResources`, `runtimeUpdates`, `realtime`, `calls`, `userTables` |
|
|
32
32
|
| [Admin app options](config/admin-app.md) | `assistant`, `maps`, `plugins` |
|
|
33
|
-
| [Jobs and events options](config/jobs-and-events.md) | `jobs`, `events`, `history`, `webhooks`, `workflows`, `notifications`, `status`, `unsubscribe` |
|
|
33
|
+
| [Jobs and events options](config/jobs-and-events.md) | `jobs`, `events`, `history`, `webhooks`, `workflows`, `notifications`, `status`, `unsubscribe`, `mailFeedback` |
|
|
34
34
|
| [Files options](config/files.md) | `files` |
|
|
35
35
|
|
|
36
36
|
## Config types
|
|
@@ -310,6 +310,37 @@ await mail.send({ to: member.email, subject: 'News', text: '...', bulk: true, to
|
|
|
310
310
|
- <gap>Bulk mail cannot be sent from an API function because only a job's `mail` adds the unsubscribe; enqueue a job instead.</gap>
|
|
311
311
|
- <gap>Email templates cannot be marked bulk because `defineTemplate` does not take `bulk` and `topic` yet.</gap>
|
|
312
312
|
|
|
313
|
+
## Bounces and complaints
|
|
314
|
+
|
|
315
|
+
:::caution[Beta]
|
|
316
|
+
Amazon SES (through SNS) and Resend report to their own endpoints so far, beside the `protobase` one a platform reports to.
|
|
317
|
+
:::
|
|
318
|
+
|
|
319
|
+
A mail provider tells the app when a message bounced or its recipient marked it as spam. With `mailFeedback` on, each report becomes a `mail_feedback` record, one per recipient, with the events `mail_feedback.bounced` and `mail_feedback.complained`, which [workflows](workflows.md), [subscriptions](webhooks.md) and your own code act on, such as marking a contact's address undeliverable. Protobase records and notifies only: it keeps sending to the address, and the app decides what a bounce means.
|
|
320
|
+
|
|
321
|
+
Turn it on in the config, then run `protobase migration`, which writes its table, `mail.feedback`, and the capture of its events as migrations of the project's own; apply them with the project's migrations, as `protobase serve` refuses to start while the table is missing:
|
|
322
|
+
|
|
323
|
+
```ts
|
|
324
|
+
export default defineConfig({ mailFeedback: true })
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
Each provider reports to `POST /api/mail/feedback/<provider>` with the default [`apiPath`](config/api.md#apipath), without sign-in, and has that endpoint only once its variable is set:
|
|
328
|
+
|
|
329
|
+
| Provider | Variable | |
|
|
330
|
+
| --- | --- | --- |
|
|
331
|
+
| `ses` | `PROTOBASE_MAIL_FEEDBACK_SES_TOPICS` | The ARNs of the SNS topics SES publishes bounces and complaints to, separated by commas. Subscribe the endpoint to each topic over HTTPS: the endpoint confirms the subscription itself. |
|
|
332
|
+
| `resend` | `PROTOBASE_MAIL_FEEDBACK_RESEND_SECRET` | The webhook's signing secret, `whsec_...`, of a webhook that sends `email.bounced` and `email.complained` to the endpoint. |
|
|
333
|
+
| `protobase` | `PROTOBASE_SECRET` | The platform secret, which a hosting platform reports bounces and complaints with. |
|
|
334
|
+
|
|
335
|
+
A value that is not a topic ARN or a signing secret stops startup, naming the variable.
|
|
336
|
+
|
|
337
|
+
- **Signatures:** a report writes nothing unless its signature checks out. `ses` takes SNS's signature, versions 1 and 2, with the signing certificate fetched from an SNS host over HTTPS and kept an hour, and only messages of the named topics, since anyone can sign with a topic of their own. `resend` and `protobase` take [Standard Webhooks](https://www.standardwebhooks.com) signatures, made at most five minutes before. A missing or wrong signature answers `401`, another topic `403`.
|
|
338
|
+
- **The record:** `type` is `bounce` or `complaint`; `bounce_type` `hard` (permanent) or `soft` (transient), and empty when the provider could not tell; `recipient`, lower-cased; `message_id`, the `Message-ID` header of the message it is about, when the report states it; `provider_message_id`, the provider's own id of that message; `reason`, as the provider gives it, such as the receiving server's diagnostic, a bounce subtype or a complaint's feedback type; `occurred_at`, when the provider says it happened; `provider`, `event_id`, the provider's id of the report, and `created_at`. A value the report does not state is empty, never guessed. Match it to the mail it answers by the [message id](#message-id) you stored.
|
|
339
|
+
- **Once:** a provider sends a report again when it got no answer in time; the same report writes nothing new. A report of another kind, such as a delivery, answers `204` and writes nothing.
|
|
340
|
+
- **Who sees it:** admins see the reports under **Mail feedback** in the admin app, and the app's code reads them as the `mail_feedback` resource, `GET /api/v1/mail_feedback?filter=recipient = "ada@example.com"`, filtered by `recipient`, `type`, `message_id` or `provider_message_id`. Nobody changes them but the endpoints.
|
|
341
|
+
- **The `protobase` endpoint:** its body is one record as above, without `provider`, `event_id` and `created_at`, such as `{ "type": "bounce", "bounce_type": "hard", "recipient": "ada@example.com", "message_id": "<...>", "reason": "smtp; 550 5.1.1 user unknown" }`, signed as Standard Webhooks with a key derived from `PROTOBASE_SECRET`, so the secret itself never travels: `mailFeedbackHeaders(secret, id, body)` of `@protobase/server` makes the headers. `webhook-id` names the report, and a retry keeps it.
|
|
342
|
+
- <gap>Other mail providers cannot report bounces and complaints because only the `ses`, `resend` and `protobase` endpoints are implemented.</gap>
|
|
343
|
+
|
|
313
344
|
## Attachments
|
|
314
345
|
|
|
315
346
|
A message takes files beside its body, such as an invoice's PDF: `attachments`, each a `filename`, its bytes as `content` (a `Uint8Array`, such as a `Buffer`) and, optionally, its `contentType`, else the one the name implies. A template's `send` takes them as its fourth argument:
|
|
@@ -366,6 +397,7 @@ export default defineFunction(async (request, { personalMail }) => {
|
|
|
366
397
|
- **Sign-in is not a mailbox:** under **Mailbox**, the account page says when someone signs in with Google without having allowed it to send mail, so a linked Google sign-in is not taken for a connected mailbox.
|
|
367
398
|
- <gap>The account page cannot show which account a mailbox is linked through or disconnect it because unlinking a mailbox is not implemented.</gap>
|
|
368
399
|
- <gap>Mailboxes other than Gmail cannot be linked because no other mail provider is implemented.</gap>
|
|
400
|
+
- **Bounces:** mail sent from someone's own mailbox bounces back to the sender, not to the app. It reaches none of the [mail feedback](#bounces-and-complaints) endpoints, so it makes no `mail_feedback` records and no `bounced` or `complained` events. Handling its bounces is the sender's own concern.
|
|
369
401
|
- <gap>A send through Gmail cannot return its [message id](#message-id) because Gmail sets its own and reading it back needs a scope that reads the mailbox, which the link does not ask for.</gap>
|
|
370
402
|
|
|
371
403
|
### From addresses
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
<!-- Generated by scripts/protobase-skill.ts from docs/website/src/content/docs/reference/realtime-relay.md: run `bun run docs:skill`, do not edit. -->
|
|
2
|
+
|
|
3
|
+
# Realtime relay
|
|
4
|
+
|
|
5
|
+
Hand the app's realtime connections to a relay, so the app and its database can sleep while people stay connected.
|
|
6
|
+
|
|
7
|
+
The app can hand its realtime connections to a relay, the open source [protobase-realtime](https://github.com/PrototeamHQ/protobase-realtime) server: the relay holds everyone's WebSocket, and the app talks to it only when something changes, so a quiet app and its database sleep while people stay connected. The relay keeps no data and never reads the app's database: the app tells it who is in which channel, what changed and for whom, and which sign-in sessions ended. It works beside the app's own [channels](channels.md) and [live updates](live.md), which stay as they are.
|
|
8
|
+
|
|
9
|
+
:::caution[In development]
|
|
10
|
+
The app's side is built: tickets, membership, change notices and session ends. <gap>Pages cannot connect to the relay from `@protobase/client` because its relay client is not implemented.</gap> <gap>The relay cannot report presence to the app because the app's presence endpoint is not implemented.</gap> <gap>Clients cannot send each other events such as typing through the relay because declaring client events per channel resource is not implemented.</gap>
|
|
11
|
+
:::
|
|
12
|
+
|
|
13
|
+
## Config
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
export default defineConfig(({ env }) => ({
|
|
17
|
+
realtime: {
|
|
18
|
+
relay: {
|
|
19
|
+
url: env.RELAY_URL!,
|
|
20
|
+
app: 'chat',
|
|
21
|
+
apiKey: env.RELAY_API_KEY!,
|
|
22
|
+
ticketKey: env.RELAY_TICKET_KEY!,
|
|
23
|
+
channels: {
|
|
24
|
+
conversations: {
|
|
25
|
+
members: { resource: 'conversation_members', channel: 'conversation_id', user: 'user_id' },
|
|
26
|
+
mentions: 'mentions',
|
|
27
|
+
},
|
|
28
|
+
rooms: {},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
}))
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
| Key | |
|
|
36
|
+
| --- | --- |
|
|
37
|
+
| `url` | The relay's address, `https://` or `http://`. The app sends its commands there, and clients connect to its `/socket`. |
|
|
38
|
+
| `app` | The app's id on the relay: 1 to 64 of `a-z`, `0-9`, `_` and `-`. |
|
|
39
|
+
| `apiKey`, `ticketKey` | One of the app's API keys and one of its ticket keys on the relay, each at least 32 characters. |
|
|
40
|
+
| `channels` | The channel resources, by name. Each record of one is a channel, `<resource>/<key>`, named as its [record channel](channels.md) is; the resource needs a key of one field. |
|
|
41
|
+
| `channels.<resource>.members` | Where the channel's members come from: a resource whose records each put one person in one channel, with its relation field to the channel resource (`channel`) and its field of the person's user id (`user`). Index both columns: tickets read by the user, notices by the channel. Without `members`, the channel is open: a channel of a public record, which tickets list when asked (see [Tickets](#tickets)). |
|
|
42
|
+
| `channels.<resource>.mentions` | A field of the records noticed on the channel that lists the user ids they mention, an array or one id, which [notices](#notices) carry. |
|
|
43
|
+
|
|
44
|
+
The relay needs the app's own [sign-in](auth.md), whose sessions its tickets name, with its store in the app's own database, as the `auth` config puts it: an auth store in another database is refused. A members resource's changes must be captured, so declare [`.live()`](live.md) on it; the relay hears of the changes of every resource whose changes are captured, such as a live one, that is a channel resource or has a relation field to one. [`protobase migration`](cli.md#migration) writes the trigger that ends a deleted session's sockets, in the `relay` schema, and the server checks it at start.
|
|
45
|
+
|
|
46
|
+
[`protobase relay app`](cli.md#relay-app) prints the app's entry for the relay's apps file, from this config and the app's `url`.
|
|
47
|
+
|
|
48
|
+
## Tickets
|
|
49
|
+
|
|
50
|
+
A client connects to the relay with a ticket from `POST /api/relay/ticket`, with `{ "channels": [...] }`, optional, as JSON. The answer is `{ ticket, url, expiresAt }`: the relay's socket address and a ticket that connects once, within a minute. Every connection, a reconnect too, takes a new ticket.
|
|
51
|
+
|
|
52
|
+
- **Signed in:** the ticket names the person and the sign-in session they called with, so a device that connects makes no new session, and lists every channel they are a member of, as the members resources hold it. A caller without a session of the app, such as an API key or an outside app acting for the user, is refused with `403`; a session that ended with `401`.
|
|
53
|
+
- **Visitors:** with an `anonymous` role, a caller without a token gets a ticket of an anonymous session of its own, which receives and never sends.
|
|
54
|
+
- **Open channels:** both list the channels they ask for in `channels` of resources without `members` whose records are public: the `anonymous` role may read them, as `GET /api/v1/<resource>/<key>` decides it for a visitor. Someone's own access to a record never makes its channel open, so no one's access to one can end while their socket stays open. A channel there is none of, one whose record is not public and one of a resource with members are refused alike with `404`; a record only some people may read takes `members`. A ticket lists at most 200 channels (`400`, or `422` when the memberships are more).
|
|
55
|
+
|
|
56
|
+
## Notices
|
|
57
|
+
|
|
58
|
+
The [dispatch](events.md) that turns each transaction's changes into events also hands them to the relay: in its own transaction it reads each change's audience once, from the members tables, and queues one `relay.send` job with the commands for the batch. A record of a channel resource is noticed on its own channel, and a record of a resource with a relation to one on the channel it points at, both where it was and where it moved. Each notice is one `change` event to the channel, the same bytes to every socket it reaches:
|
|
59
|
+
|
|
60
|
+
```json
|
|
61
|
+
{ "kind": "create", "resource": "messages", "key": "42", "channel": "conversations/7", "mentions": ["u2"] }
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
`kind` is `create`, `update`, `delete` or `undelete`; `mentions` is there with `mentions` set. A notice tells clients what changed, so they read only the records they show. On a channel with members it reaches its members as the database holds them at dispatch, and a person who joined or left with that change; on an open channel, everyone joined to it. The relay sends a notice once, however often the job sends it again.
|
|
65
|
+
|
|
66
|
+
A members record that is created or undeleted adds its person to the channel on the sockets they have open, before its notice, and one that is deleted or soft-deleted takes them out after it: they can join, or are closed out, without connecting again. Commands go in commit order, one job at a time; while the relay is down, they wait and try again, once a minute at most. A command the relay refuses, such as one over its size limit, goes to the app's error reporter and is passed over.
|
|
67
|
+
|
|
68
|
+
<gap>An open channel's notices still reach the sockets joined to it after its record stops being public, until they reconnect, because checking read access again on the relay is not implemented.</gap>
|
|
69
|
+
|
|
70
|
+
## Sessions
|
|
71
|
+
|
|
72
|
+
When a sign-in session ends, its sockets close: a trigger on the sessions table queues a `relay.close-sessions` job in the deleting transaction, for a sign-out, a revoke, a ban, a newer sign-in in the same browser or a delete in SQL alike, and the job tells the relay to close them. A ticket also queues a `relay.session-expiry` job for its session's expiry, once for each session: it closes the session's sockets once the session expired, and waits for the new expiry of one that was extended meanwhile. The person's other sessions stay connected. The relay itself keeps no timers.
|
|
@@ -90,7 +90,7 @@ A function target is called as the subscription's `as`, so `context.caller()` an
|
|
|
90
90
|
|
|
91
91
|
## Delivery and retries
|
|
92
92
|
|
|
93
|
-
- **Every delivery is a job of its own:** the dispatch job queues a `webhooks.deliver` job for each delivery, in the transaction that writes the change's history and live notices, and tries none itself, so a slow receiver never holds back a live update or another delivery. A
|
|
93
|
+
- **Every delivery is a job of its own:** the dispatch job queues a `webhooks.deliver` job for each delivery, in the transaction that writes the change's history and live notices, and tries none itself, so a slow receiver never holds back a live update or another delivery. A write through the API starts the dispatch at once, and a write from elsewhere at the dispatch's next poll. The first try then waits for a worker's next poll, since the delivery job is queued in a transaction: within about two seconds of an API write and about four of one from elsewhere, with the default [poll interval](jobs.md) of 2 seconds.
|
|
94
94
|
- **A failed try** queues the next `webhooks.deliver` job, retried on the Standard Webhooks schedule with up to 10% jitter: 5 s, 5 m, 30 m, 2 h, 5 h, 10 h, 14 h, 20 h and 24 h, 10 tries over about three days. A `Retry-After` header makes the wait longer, up to a day.
|
|
95
95
|
- **`410 Gone`** fails the delivery at once.
|
|
96
96
|
- **After the last try** the job is kept as failed, on the [failed jobs page](jobs.md#failed-jobs-page), where it can be retried.
|