@protobase/cli 0.111.1 → 0.111.2
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 +3 -0
- package/dist/config/unsubscribe-config.js +15 -0
- package/dist/dev/dev-jobs.js +3 -2
- package/dist/dev/entry.js +1 -1
- package/dist/doctor/built-in-models.js +2 -1
- package/dist/migration/load-project.js +2 -0
- package/dist/migration/parts.js +6 -1
- package/dist/project/project-admin.js +1 -0
- package/dist/serve/lifecycle.js +1 -0
- package/dist/serve/startup-checks.js +2 -1
- package/dist/worker/start-worker.js +1 -0
- package/package.json +8 -8
- package/skills/protobase/references/features/email-and-public-forms.md +2 -1
- package/skills/protobase/references/reference/cli.md +1 -1
- package/skills/protobase/references/reference/config/app.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 +41 -6
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 { projectUnsubscribe } from "./unsubscribe-config.js";
|
|
2
3
|
import { userTablesOn } from "./user-tables-config.js";
|
|
3
4
|
import { buildAppAuth, buildAuthenticator, checkCallsOptions, checkStatusOptions, isOverSignIn, workflowPlugins } from "@protobase/server/internal";
|
|
4
5
|
//#region src/config/build-project.ts
|
|
@@ -68,6 +69,7 @@ const buildProject = async (config, database) => {
|
|
|
68
69
|
]);
|
|
69
70
|
const jobs = projectJobs(config);
|
|
70
71
|
const derived = projectDerived(config);
|
|
72
|
+
const unsubscribe = projectUnsubscribe(config);
|
|
71
73
|
const identity = config.themeColor || config.backgroundColor ? {
|
|
72
74
|
...config.themeColor && { themeColor: config.themeColor },
|
|
73
75
|
...config.backgroundColor && { backgroundColor: config.backgroundColor }
|
|
@@ -88,6 +90,7 @@ const buildProject = async (config, database) => {
|
|
|
88
90
|
...notifications && { notifications },
|
|
89
91
|
...config.status && { status: checkStatusOptions(config.status) },
|
|
90
92
|
...config.calls && { calls: checkCallsOptions(config.calls) },
|
|
93
|
+
...unsubscribe && { unsubscribe },
|
|
91
94
|
...mailer && { mailer },
|
|
92
95
|
...config.mobile && { mobile: config.mobile },
|
|
93
96
|
...config.secret && { secret: config.secret },
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region src/config/unsubscribe-config.ts
|
|
2
|
+
/** Whether bulk mail carries a one-click unsubscribe: the one reading of `unsubscribe`, which takes only true or false. */
|
|
3
|
+
const unsubscribeOn = (config) => {
|
|
4
|
+
const value = config.unsubscribe;
|
|
5
|
+
if (value !== void 0 && typeof value !== "boolean") throw new Error(`unsubscribe is ${JSON.stringify(value)}; it takes true or false`);
|
|
6
|
+
return value === true;
|
|
7
|
+
};
|
|
8
|
+
/** The unsubscribe `createAdmin` takes: its links are on the app's public URL, which it needs. */
|
|
9
|
+
const projectUnsubscribe = (config) => {
|
|
10
|
+
if (!unsubscribeOn(config)) return;
|
|
11
|
+
if (!config.url) throw new Error("unsubscribe links bulk mail to the app's public URL: set PROTOBASE_URL, such as https://admin.example.com, or url in protobase.config.ts");
|
|
12
|
+
return { appUrl: config.url };
|
|
13
|
+
};
|
|
14
|
+
//#endregion
|
|
15
|
+
export { projectUnsubscribe, unsubscribeOn };
|
package/dist/dev/dev-jobs.js
CHANGED
|
@@ -3,10 +3,10 @@ import { checkJobsSchema, startJobs } from "@protobase/server";
|
|
|
3
3
|
const store = globalThis;
|
|
4
4
|
/**
|
|
5
5
|
* Runs the project's jobs in the dev server: started on the first load, once the jobs schema checks out, with the app's
|
|
6
|
-
* own mailer when it has one, and given the reloaded definitions and the rebuilt app's `decryptField` on every load
|
|
6
|
+
* own mailer when it has one and the links of its unsubscribe, and given the reloaded definitions and the rebuilt app's `decryptField` on every load
|
|
7
7
|
* after it, so an edited job runs its new code from the next job on. A mailer added or changed later is the jobs' from the next start.
|
|
8
8
|
*/
|
|
9
|
-
const devJobs = async (db, definitions, decryptField, mailer) => {
|
|
9
|
+
const devJobs = async (db, definitions, decryptField, mailer, unsubscribe) => {
|
|
10
10
|
if (store.__protobaseJobs) return store.__protobaseJobs.update(definitions, decryptField);
|
|
11
11
|
if (definitions.length === 0) return;
|
|
12
12
|
await checkJobsSchema(db);
|
|
@@ -15,6 +15,7 @@ const devJobs = async (db, definitions, decryptField, mailer) => {
|
|
|
15
15
|
jobs: definitions,
|
|
16
16
|
decryptField,
|
|
17
17
|
...mailer && { mailer },
|
|
18
|
+
...unsubscribe && { unsubscribe },
|
|
18
19
|
onError: (error) => console.error(error)
|
|
19
20
|
});
|
|
20
21
|
};
|
package/dist/dev/entry.js
CHANGED
|
@@ -58,7 +58,7 @@ const ui = {
|
|
|
58
58
|
icons: projectIcons(projectDir)
|
|
59
59
|
};
|
|
60
60
|
const { admin, jobs } = await servedAdmin(project, db, ui, reporter, upgradeWebSocket);
|
|
61
|
-
if (process.env.PROTOBASE_DEV_JOBS !== "false") await devJobs(db, jobs, admin.decryptField, project.mailer);
|
|
61
|
+
if (process.env.PROTOBASE_DEV_JOBS !== "false") await devJobs(db, jobs, admin.decryptField, project.mailer, admin.unsubscribe);
|
|
62
62
|
devRealtimePrune(admin);
|
|
63
63
|
var entry_default = withDevServiceWorker(new Hono(), Boolean(project.notifications)).route("/", admin);
|
|
64
64
|
/** Whether the auth store has a user yet, for the banner's sign-in line; undefined without one. */
|
|
@@ -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
|
|
5
|
+
* of `webhooks` and the workflow ones of `workflows`, then Failed jobs, Activity and Comments by what the app's resources use, and Unsubscribes with `unsubscribe`. Doctor checks them as it checks
|
|
6
6
|
* the app's own.
|
|
7
7
|
*/
|
|
8
8
|
const builtInModels = (config, models) => {
|
|
@@ -17,6 +17,7 @@ const builtInModels = (config, models) => {
|
|
|
17
17
|
models: [...moduleModels, ...models],
|
|
18
18
|
jobs: Object.keys(config.jobs).length > 0,
|
|
19
19
|
notifications: config.notifications !== void 0,
|
|
20
|
+
unsubscribe: config.unsubscribe === true,
|
|
20
21
|
...config.events && { events: config.events }
|
|
21
22
|
});
|
|
22
23
|
return {
|
|
@@ -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 { unsubscribeOn } from "../config/unsubscribe-config.js";
|
|
3
4
|
import { userTablesOn } from "../config/user-tables-config.js";
|
|
4
5
|
import { projectAuth } from "../config/build-project.js";
|
|
5
6
|
import { loadSourceConfig } from "../config/source-config.js";
|
|
@@ -47,6 +48,7 @@ const migrationProject = async (config, url) => {
|
|
|
47
48
|
...config.status && { status: checkStatusOptions(config.status) },
|
|
48
49
|
jobs,
|
|
49
50
|
userTables: userTablesOn(config),
|
|
51
|
+
unsubscribe: unsubscribeOn(config),
|
|
50
52
|
readOnlyQueries: assistantSettings(config.assistant, process.env)?.kind === "built-in",
|
|
51
53
|
authTables: auth ? authStoreTables(auth) : {
|
|
52
54
|
tables: [],
|
package/dist/migration/parts.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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, userTablesMigration, webhooksMigration, workflowsMigration } from "@protobase/server";
|
|
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";
|
|
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) => {
|
|
@@ -61,6 +61,11 @@ const migrationParts = (project) => {
|
|
|
61
61
|
title: "The statuses table of people's own status",
|
|
62
62
|
sql: () => statusMigration(project.db, project.status, project.auth)
|
|
63
63
|
}] : [],
|
|
64
|
+
...project.unsubscribe ? [{
|
|
65
|
+
name: "unsubscribes",
|
|
66
|
+
title: "The table of who unsubscribed from which topic of the bulk mail",
|
|
67
|
+
sql: () => unsubscribesMigration(project.db)
|
|
68
|
+
}] : [],
|
|
64
69
|
...project.calls ? [{
|
|
65
70
|
name: "calls",
|
|
66
71
|
title: "The calls on records, who is in them, whom they ring, their guests, and the signals between the processes serving the app",
|
|
@@ -38,6 +38,7 @@ const projectAdmin = (project, db, ui, reporter, upgradeWebSocket, userTables) =
|
|
|
38
38
|
...project.realtime && { realtime: project.realtime },
|
|
39
39
|
...project.notifications && { notifications: project.notifications },
|
|
40
40
|
...project.status && { status: project.status },
|
|
41
|
+
...project.unsubscribe && { unsubscribe: project.unsubscribe },
|
|
41
42
|
...project.calls && { calls: project.calls },
|
|
42
43
|
...project.mobile && { mobile: project.mobile },
|
|
43
44
|
...project.app && { app: project.app },
|
package/dist/serve/lifecycle.js
CHANGED
|
@@ -45,6 +45,7 @@ const startServe = async ({ config, env, openDb = (url) => openAppDatabase(pg, u
|
|
|
45
45
|
work: env.runJobs,
|
|
46
46
|
decryptField: admin.decryptField,
|
|
47
47
|
...project.mailer && { mailer: project.mailer },
|
|
48
|
+
...admin.unsubscribe && { unsubscribe: admin.unsubscribe },
|
|
48
49
|
onError: (error) => console.error(error)
|
|
49
50
|
}) : void 0;
|
|
50
51
|
const release = project.mobile ? await servedRelease({
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { assistantSettings, authStoreTables, checkAuthSchema, checkCalls, checkChanges, checkChannelSends, checkComments, checkComputed, checkDerived, checkNotificationsSchema, checkQueryRunner, checkRealtimeRelay, checkResourcesOutsideAuthStore, checkStatusSchema, checkUserTablesSchema, checkWebhooksSchema, checkWorkflowsSchema, configExports, relayed, sqlSends } from "@protobase/server";
|
|
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";
|
|
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
|
|
@@ -24,6 +24,7 @@ const checkStartup = async (project, db) => {
|
|
|
24
24
|
if (sqlSends(project.realtime)) await checkChannelSends(db);
|
|
25
25
|
if (project.notifications) await checkNotificationsSchema(db, project.notifications, project.auth);
|
|
26
26
|
if (project.status) await checkStatusSchema(db, project.status, project.auth);
|
|
27
|
+
if (project.unsubscribe) await checkUnsubscribesSchema(db);
|
|
27
28
|
if (project.userTables) await checkUserTablesSchema(db);
|
|
28
29
|
};
|
|
29
30
|
//#endregion
|
|
@@ -38,6 +38,7 @@ const startWorker = async ({ config, databaseUrl, openDb = (url) => openAppDatab
|
|
|
38
38
|
jobs: definitions,
|
|
39
39
|
decryptField: admin.decryptField,
|
|
40
40
|
...project.mailer && { mailer: project.mailer },
|
|
41
|
+
...admin.unsubscribe && { unsubscribe: admin.unsubscribe },
|
|
41
42
|
onError: (error) => console.error(error)
|
|
42
43
|
})
|
|
43
44
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.111.
|
|
3
|
+
"version": "0.111.2",
|
|
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.111.
|
|
47
|
-
"@protobase/layout": "0.111.
|
|
48
|
-
"@protobase/query": "0.111.
|
|
49
|
-
"@protobase/schema": "0.111.
|
|
50
|
-
"@protobase/server": "0.111.
|
|
51
|
-
"@protobase/ui": "0.111.
|
|
52
|
-
"@protobase/workflows": "0.111.
|
|
46
|
+
"@protobase/config": "0.111.2",
|
|
47
|
+
"@protobase/layout": "0.111.2",
|
|
48
|
+
"@protobase/query": "0.111.2",
|
|
49
|
+
"@protobase/schema": "0.111.2",
|
|
50
|
+
"@protobase/server": "0.111.2",
|
|
51
|
+
"@protobase/ui": "0.111.2",
|
|
52
|
+
"@protobase/workflows": "0.111.2",
|
|
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",
|
|
@@ -9,7 +9,8 @@ Mail the app sends, the PDF documents it makes, and forms for people without an
|
|
|
9
9
|
- [Email templates](../reference/email.md#templates) (beta): Your own emails are templates with typed data, written in mail blocks with their texts in each language they are sent in, checked by a schema of yours or the data they read, and sent from jobs, hooks, functions or a workflow's Send email step.
|
|
10
10
|
- [Emails in React](../reference/email.md#emails-in-react): An email can be a React component with typed data instead, for a layout the mail blocks cannot draw.
|
|
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
|
+
- [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.
|
|
13
14
|
- [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.
|
|
14
15
|
- [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.
|
|
15
16
|
- [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.
|
|
@@ -616,7 +616,7 @@ Applies the project's `db/migrations/*.sql` that the database has not applied ye
|
|
|
616
616
|
protobase migration [--dir db/migrations] [--extend <dir>]
|
|
617
617
|
```
|
|
618
618
|
|
|
619
|
-
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 `notifications`, or a resource has events, history, comments or an [AI field](ai.md) (`NNN_jobs.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 `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`), 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`.
|
|
619
|
+
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 `notifications`, or a resource has events, history, comments or an [AI field](ai.md) (`NNN_jobs.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`), 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`.
|
|
620
620
|
|
|
621
621
|
```sh
|
|
622
622
|
bun run db:migrate # the database at the project's current schema
|
|
@@ -24,7 +24,7 @@ export default defineConfig({ name: 'Property Finder' })
|
|
|
24
24
|
- **Default:** `PROTOBASE_URL`; in `protobase dev`, the dev server's own address
|
|
25
25
|
- **Environment variable:** `PROTOBASE_URL`
|
|
26
26
|
|
|
27
|
-
The app's public URL: the issuer and audience of its tokens, and where its emails link to. Sign-in
|
|
27
|
+
The app's public URL: the issuer and audience of its tokens, and where its emails link to. Sign-in and [`unsubscribe`](jobs-and-events.md#unsubscribe) need it. With `auth` on, `protobase dev`, `serve` and the commands that sign people in stop with a clear message when it is missing. With `unsubscribe: true`, `protobase serve` stops when it is missing too, auth on or off, and when it is not `https://`, but for `localhost` and `127.0.0.1`. Other origins the app is served on are [`auth.origins`](sign-in.md#authorigins).
|
|
28
28
|
|
|
29
29
|
```ts
|
|
30
30
|
export default defineConfig({ url: 'https://admin.example.com' })
|
|
@@ -36,7 +36,7 @@ export default defineConfig({ url: 'https://admin.example.com' })
|
|
|
36
36
|
- **Default:** `PROTOBASE_SECRET`
|
|
37
37
|
- **Environment variable:** `PROTOBASE_SECRET`
|
|
38
38
|
|
|
39
|
-
The app's secret, made with `openssl rand -base64 32`: it signs session cookies, upload tickets, download links
|
|
39
|
+
The app's secret, made with `openssl rand -base64 32`: it signs session cookies, upload tickets, download links, public forms' bot checks and unsubscribe links, and encrypts the token signing keys. Sign-in and `unsubscribe` need it, and file fields too unless [`files.secret`](files.md#filessecret) names another; public forms sign their bot checks with `PROTOBASE_FORMS_SECRET` instead when it is set. Keep it out of the config's source and read it from the environment, which the default does.
|
|
40
40
|
|
|
41
41
|
```ts
|
|
42
42
|
export default defineConfig(({ env }) => ({ secret: env.ADMIN_SECRET }))
|
|
@@ -375,3 +375,14 @@ The schema of the statuses table.
|
|
|
375
375
|
```ts
|
|
376
376
|
export default defineConfig({ status: { schema: 'presence' } })
|
|
377
377
|
```
|
|
378
|
+
|
|
379
|
+
## unsubscribe
|
|
380
|
+
|
|
381
|
+
- **Type:** `boolean`
|
|
382
|
+
- **Default:** `false`
|
|
383
|
+
|
|
384
|
+
Gives bulk mail a one-click unsubscribe: mail a job sends with `bulk: true` and a `topic` carries the recipient's own unsubscribe link, and is not sent to whoever unsubscribed from its topic. The links are on [`url`](app.md#url) and signed with [`secret`](app.md#secret), and the table of who unsubscribed, `mail.unsubscribes`, is written by `protobase migration` as a migration of the project's own: apply it with the project's migrations, as `protobase serve` refuses to start while the table is missing. See [Unsubscribe](../email.md#unsubscribe).
|
|
385
|
+
|
|
386
|
+
```ts
|
|
387
|
+
export default defineConfig({ unsubscribe: true })
|
|
388
|
+
```
|
|
@@ -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` |
|
|
33
|
+
| [Jobs and events options](config/jobs-and-events.md) | `jobs`, `events`, `history`, `webhooks`, `workflows`, `notifications`, `status`, `unsubscribe` |
|
|
34
34
|
| [Files options](config/files.md) | `files` |
|
|
35
35
|
|
|
36
36
|
## Config types
|
|
@@ -147,19 +147,17 @@ export const repairReady = defineEmail({
|
|
|
147
147
|
| `subject` | The subject line, or a function of the data that makes it. |
|
|
148
148
|
| `component` | The body, a React component of the data. It is rendered with React Email's `render` to the HTML part; the plain-text part is made from that HTML, leaving out what React Email marks to skip, such as `<Preview>`. |
|
|
149
149
|
| `headers` | Optional: more header fields, or a function of the data that makes them. A value is one line. |
|
|
150
|
+
| `bulk` | Optional: `true` marks bulk mail, which carries a one-click unsubscribe from its `topic` (see [Unsubscribe](#unsubscribe)). |
|
|
151
|
+
| `topic` | The kind of mail, such as `newsletter`, which a recipient unsubscribes from; required with `bulk`. |
|
|
150
152
|
|
|
151
153
|
The template that comes back has two methods, both typed by the component's props:
|
|
152
154
|
|
|
153
155
|
- `render(data)` gives `{ subject, html, text, headers }` without sending anything: for a test, or to look at the result.
|
|
154
|
-
- `send(to, data, mailer?)` renders and sends it, through `mailer` when given (a job's `mail`), otherwise through `PROTOBASE_SMTP_URL`. It rejects when mail is off or the server refuses the message
|
|
156
|
+
- `send(to, data, mailer?)` renders and sends it, through `mailer` when given (a job's `mail`), otherwise through `PROTOBASE_SMTP_URL`. It rejects when mail is off or the server refuses the message, and a bulk email without a job's `mail` as `mailer`.
|
|
155
157
|
|
|
156
158
|
React and React Email's renderer are loaded on the first email rendered, not when the app starts.
|
|
157
159
|
|
|
158
|
-
Mail an app sends in bulk, such as alerts or newsletters,
|
|
159
|
-
|
|
160
|
-
```ts
|
|
161
|
-
headers: ({ unsubscribeUrl }: Digest) => ({ 'List-Unsubscribe': `<${unsubscribeUrl}>`, 'List-Unsubscribe-Post': 'List-Unsubscribe=One-Click' }),
|
|
162
|
-
```
|
|
160
|
+
Mail an app sends in bulk, such as alerts or newsletters, is marked `bulk` with a `topic`, and Protobase gives it a one-click unsubscribe: see [Unsubscribe](#unsubscribe).
|
|
163
161
|
|
|
164
162
|
### The look of Protobase's own mail
|
|
165
163
|
|
|
@@ -275,6 +273,43 @@ await db.updateTable('invoices').set({ message_id: messageId ?? null }).where('i
|
|
|
275
273
|
|
|
276
274
|
Protobase gives every message through `PROTOBASE_SMTP_URL` a new id on the sender's domain before it goes out, in place of a `Message-ID` among the message's own `headers`. A relay that rewrites the `Message-ID` changes what the recipient sees, so check that yours keeps it. A mailer of the project's own resolves to the id it sends, or to `{}` without one; mail from someone's own mailbox resolves to `{}` (see below).
|
|
277
275
|
|
|
276
|
+
## Unsubscribe
|
|
277
|
+
|
|
278
|
+
:::caution[Beta]
|
|
279
|
+
There is no preferences page yet, and no way to subscribe again once unsubscribed.
|
|
280
|
+
:::
|
|
281
|
+
|
|
282
|
+
Mail you mark as bulk carries a one-click unsubscribe, as large mailbox providers expect of bulk senders ([RFC 8058](https://www.rfc-editor.org/rfc/rfc8058)): the mail client shows an unsubscribe button, and one click stops that kind of mail to that recipient. Protobase records who unsubscribed from which topic, and does not send that topic to them from the next send on.
|
|
283
|
+
|
|
284
|
+
**Bulk** is mail the recipient did not ask for by an action of their own: newsletters, digests, announcements and marketing. **Transactional** mail answers something the recipient did or needs to act on, such as a password reset, a sign-in code, a receipt or an invoice: it is not marked bulk and carries no unsubscribe. Protobase's own mail is transactional.
|
|
285
|
+
|
|
286
|
+
Turn it on in the config, then run `protobase migration`, which writes its table, `mail.unsubscribes`, as a migration of the project's own, and apply it with the project's migrations: `protobase serve` refuses to start while the table or its unique index is missing, and names the migration to write. Its links are on the app's [`url`](config/app.md#url), which must be `https://` but on `localhost`, and signed with its [`secret`](config/app.md#secret):
|
|
287
|
+
|
|
288
|
+
```ts
|
|
289
|
+
export default defineConfig({ unsubscribe: true })
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
Mark an email as bulk with a `topic`, the kind of mail someone unsubscribes from, such as `newsletter` or `weekly-digest`: a lowercase letter, then lowercase letters, digits, `_` and `-`. Send it from a job with the job's `mail`:
|
|
293
|
+
|
|
294
|
+
```ts
|
|
295
|
+
export const weeklyDigest = defineEmail({ name: 'weekly-digest', subject: 'This week', component: Digest, bulk: true, topic: 'weekly-digest' })
|
|
296
|
+
|
|
297
|
+
// jobs/send-digest.ts
|
|
298
|
+
const { skipped } = await weeklyDigest.send(member.email, digest, mail)
|
|
299
|
+
await mail.send({ to: member.email, subject: 'News', text: '...', bulk: true, topic: 'newsletter' })
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
- **The headers:** each message gets `List-Unsubscribe` with the recipient's own link, `https://<app>/api/unsubscribe/<token>` with the default [`apiPath`](config/api.md#apipath), and `List-Unsubscribe-Post: List-Unsubscribe=One-Click`, in place of such headers of its own. The token names the recipient and the topic, signed so that nobody can change either: a link cannot be made for someone else or for another topic. It is a bearer link, though: whoever holds it, such as someone the mail was forwarded to, can unsubscribe its recipient from its topic.
|
|
303
|
+
- **The button:** mail clients show their unsubscribe button only on mail whose DKIM signature covers both headers. Protobase sends the headers; the server that signs your mail must sign `List-Unsubscribe` and `List-Unsubscribe-Post` too, or the mail still goes out without a button.
|
|
304
|
+
- **A message per recipient:** `to` takes one plain address or several separated by commas, and each recipient gets a message of their own with their own link. A named address (`Ada <ada@example.com>`) is refused.
|
|
305
|
+
- **The click:** the mail client's `POST` with `List-Unsubscribe=One-Click` records the opt-out and answers `200`; doing it again changes nothing. Opening the link in a browser shows a page with an **Unsubscribe** button that sends that `POST`, so a scanner that follows links in mail unsubscribes no one. A link the app did not sign answers `400` and records nothing.
|
|
306
|
+
- **Skipped sends:** whoever unsubscribed from the topic is left out, found in one query, and the send resolves to them as `skipped` beside `sent`, each recipient it went to with its message id: `{ skipped: ['bob@example.com'], sent: [{ to: 'ada@example.com', messageId: '<…>' }], messageId: '<…>' }`, with `messageId` only when it went to exactly one. Other topics still reach them. Who unsubscribed is read once, before the first message goes out; one who unsubscribes while a send to several is going out is skipped from the next send on.
|
|
307
|
+
- **A refused message:** when the server refuses one recipient's message, the send rejects with a `BulkMailError` (exported by `@protobase/server`, its `code` `BULK_MAIL_FAILED`) after the messages before it went out. It fails the try, which is retried, and names the recipient it failed on as `to`, those it went to as `sent`, those skipped as `skipped`, and the server's error as `cause`. A retried try sends to everyone again, so catch it, record `error.sent`, rethrow, and leave those addresses out of the next try; or send to one recipient per call.
|
|
308
|
+
- **Who unsubscribed:** admins see each recipient, topic and time under **Unsubscribes** in the admin app, and the app's code reads them as the `mail_unsubscribes` resource, `GET /api/v1/mail_unsubscribes?filter=topic = "newsletter"`. Nobody changes them but the link.
|
|
309
|
+
- **Refused:** `bulk` without a `topic` is refused, as the email is defined or the message sent. Bulk mail without `unsubscribe: true`, or sent another way than a job's `mail`, such as through `PROTOBASE_SMTP_URL` directly or from someone's own mailbox, is refused before anything is sent. A mailer of the project's own (`auth/mailer.ts`) that is handed bulk mail directly, outside a job's `mail`, gets it without its unsubscribe: send it through the job's `mail` instead.
|
|
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
|
+
- <gap>Email templates cannot be marked bulk because `defineTemplate` does not take `bulk` and `topic` yet.</gap>
|
|
312
|
+
|
|
278
313
|
## Attachments
|
|
279
314
|
|
|
280
315
|
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:
|