@protobase/cli 0.124.2 → 0.125.1
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/bundle-relay.js +20 -0
- package/dist/build/config-bundle.js +3 -1
- package/dist/build/deploy-bundle.js +3 -2
- package/dist/bundle/manifest.js +5 -2
- package/dist/cli/package.js +1 -1
- package/dist/dev/dev-relay.js +10 -4
- package/dist/relay/app-entry.js +27 -12
- package/package.json +8 -8
- package/skills/protobase/references/features/email-and-public-forms.md +1 -1
- package/skills/protobase/references/features/history-comments-and-live-updates.md +1 -1
- package/skills/protobase/references/reference/auth.md +1 -0
- package/skills/protobase/references/reference/cli.md +9 -4
- package/skills/protobase/references/reference/email.md +49 -12
- package/skills/protobase/references/reference/realtime-relay.md +8 -3
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { projectResources } from "../config/project-parts.js";
|
|
2
|
+
import { relayAppPart } from "../relay/app-entry.js";
|
|
3
|
+
import { configExports } from "@protobase/server";
|
|
4
|
+
//#region src/build/bundle-relay.ts
|
|
5
|
+
/**
|
|
6
|
+
* What the manifest says of the config's `realtime.relay`: the app's part of its entry in the relay's apps file, from
|
|
7
|
+
* the config and its views, as `protobase relay app` prints it, without the address, id or keys a build does not hold.
|
|
8
|
+
* `undefined` without `realtime.relay`, so its presence means the app hands its connections to the relay.
|
|
9
|
+
*/
|
|
10
|
+
const bundleRelay = async (config) => {
|
|
11
|
+
const relay = config.realtime?.relay;
|
|
12
|
+
if (!relay) return;
|
|
13
|
+
const views = configExports(await projectResources(config)).views.map((view) => view.toModel());
|
|
14
|
+
return relayAppPart(relay, {
|
|
15
|
+
apiPath: config.apiPath,
|
|
16
|
+
views
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
//#endregion
|
|
20
|
+
export { bundleRelay };
|
|
@@ -7,6 +7,7 @@ import { layoutCheck } from "./layout-check.js";
|
|
|
7
7
|
import { extensionImports } from "../project/extensions.js";
|
|
8
8
|
import { viteBundle } from "./vite-bundle.js";
|
|
9
9
|
import { cliProtobaseIds, provideCliModules } from "../project/cli-modules.js";
|
|
10
|
+
import { bundleRelay } from "./bundle-relay.js";
|
|
10
11
|
import { collectComponents } from "./component-names.js";
|
|
11
12
|
import { bundleEntryCode } from "./entry-code.js";
|
|
12
13
|
import { hostPackages } from "./packages/host-packages.js";
|
|
@@ -100,7 +101,8 @@ const buildConfigBundle = async ({ projectDir, outFile, bun, extensions = [], co
|
|
|
100
101
|
return {
|
|
101
102
|
native: [...native.values()],
|
|
102
103
|
mobile: config.mobile,
|
|
103
|
-
notifications: Boolean(config.notifications)
|
|
104
|
+
notifications: Boolean(config.notifications),
|
|
105
|
+
relay: await bundleRelay(config)
|
|
104
106
|
};
|
|
105
107
|
};
|
|
106
108
|
//#endregion
|
|
@@ -53,7 +53,7 @@ const buildDeployBundle = async ({ projectDir, outDir, bun, extensions = [], sou
|
|
|
53
53
|
await removeOwnFolder(outDir, bundleNodeModules, "nodeModules");
|
|
54
54
|
await removeOwnFolder(outDir, bundleMigrations, "migrations");
|
|
55
55
|
const components = /* @__PURE__ */ new Set();
|
|
56
|
-
const { native, mobile, notifications } = await buildConfigBundle({
|
|
56
|
+
const { native, mobile, notifications, relay } = await buildConfigBundle({
|
|
57
57
|
projectDir,
|
|
58
58
|
outFile: path.join(outDir, bundleLayout.server),
|
|
59
59
|
bun,
|
|
@@ -103,7 +103,8 @@ const buildDeployBundle = async ({ projectDir, outDir, bun, extensions = [], sou
|
|
|
103
103
|
native: pinnedNative,
|
|
104
104
|
...mobileSection && { mobile: mobileSection },
|
|
105
105
|
...packages.length > 0 ? { nodeModules: bundleNodeModules } : {},
|
|
106
|
-
...migrations ? { migrations } : {}
|
|
106
|
+
...migrations ? { migrations } : {},
|
|
107
|
+
...relay && { relay }
|
|
107
108
|
};
|
|
108
109
|
await writeFile(path.join(outDir, manifestFile), `${JSON.stringify(manifest, null, 2)}\n`);
|
|
109
110
|
return manifest;
|
package/dist/bundle/manifest.js
CHANGED
|
@@ -21,11 +21,12 @@ const isPlugin = (value) => isObject(value) && typeof value.name === "string" &&
|
|
|
21
21
|
const isShell = (value) => isObject(value) && typeof value.protobase === "string" && Number.isInteger(value.pluginApi) && isStringList(value.paths) && (value.builtAt === void 0 || isTime(value.builtAt));
|
|
22
22
|
const isTime = (value) => Number.isSafeInteger(value) && value >= 0;
|
|
23
23
|
const isVersions = (value) => isObject(value) && Object.values(value).every((item) => typeof item === "string");
|
|
24
|
+
const isRelay = (value) => isObject(value) && (value.client_events === void 0 || isObject(value.client_events) && isObject(value.client_events.channels)) && (value.presence === void 0 || isObject(value.presence) && typeof value.presence.path === "string" && Number.isInteger(value.presence.grace_seconds));
|
|
24
25
|
const isIcons = (value) => isObject(value) && typeof value.favicon === "boolean" && isStringList(value.png) && value.png.every((icon) => icon in pngIcons);
|
|
25
26
|
const parseManifest = (value, file) => {
|
|
26
27
|
const manifest = value;
|
|
27
28
|
if (manifest?.version !== 3) throw new Error(`${file} is not a version 3 bundle manifest; rebuild it with \`protobase build\``);
|
|
28
|
-
const { builtAt, server, public: publicDir, api, spa, plugins, theme, shell, icons, native, mobile, nodeModules, migrations } = manifest;
|
|
29
|
+
const { builtAt, server, public: publicDir, api, spa, plugins, theme, shell, icons, native, mobile, nodeModules, migrations, relay } = manifest;
|
|
29
30
|
if (typeof server !== "string" || typeof publicDir !== "string" || typeof spa !== "string" || typeof theme !== "string" || !isStringList(api)) throw new Error(`${file} needs server, public, spa and theme paths and an api list`);
|
|
30
31
|
if (!Array.isArray(plugins) || !plugins.every(isPlugin)) throw new Error(`${file} needs a plugins list, each with a name, path and api`);
|
|
31
32
|
if (!isShell(shell)) throw new Error(`${file} needs a shell with its protobase version, pluginApi and paths`);
|
|
@@ -35,6 +36,7 @@ const parseManifest = (value, file) => {
|
|
|
35
36
|
if (mobile !== void 0 && !(isObject(mobile) && isVersions(mobile.plugins) && (mobile.appId === void 0 || typeof mobile.appId === "string") && (mobile.push === void 0 || typeof mobile.push === "boolean"))) throw new Error(`${file} has a mobile that is not { appId, plugins, push } with an app id, a map of package names to versions and true or false`);
|
|
36
37
|
if (nodeModules !== void 0 && typeof nodeModules !== "string") throw new Error(`${file} has a nodeModules that is no path`);
|
|
37
38
|
if (migrations !== void 0 && typeof migrations !== "string") throw new Error(`${file} has a migrations that is no path`);
|
|
39
|
+
if (relay !== void 0 && !isRelay(relay)) throw new Error(`${file} has a relay that is not { client_events, presence } with its channels and a presence path and grace`);
|
|
38
40
|
return {
|
|
39
41
|
version: 3,
|
|
40
42
|
...builtAt !== void 0 && { builtAt },
|
|
@@ -49,7 +51,8 @@ const parseManifest = (value, file) => {
|
|
|
49
51
|
...native && { native },
|
|
50
52
|
...mobile && { mobile },
|
|
51
53
|
...nodeModules === void 0 ? {} : { nodeModules },
|
|
52
|
-
...migrations === void 0 ? {} : { migrations }
|
|
54
|
+
...migrations === void 0 ? {} : { migrations },
|
|
55
|
+
...relay && { relay }
|
|
53
56
|
};
|
|
54
57
|
};
|
|
55
58
|
const readManifest = async (bundleDir) => {
|
package/dist/cli/package.js
CHANGED
package/dist/dev/dev-relay.js
CHANGED
|
@@ -10,9 +10,11 @@ const devLimits = {
|
|
|
10
10
|
channels_per_ticket: 200,
|
|
11
11
|
request_bytes: 1048576
|
|
12
12
|
};
|
|
13
|
+
const devKey = () => randomBytes(32).toString("base64url");
|
|
13
14
|
const devKeys = () => store.__protobaseDevRelayKeys ??= {
|
|
14
|
-
apiKey:
|
|
15
|
-
ticketKey:
|
|
15
|
+
apiKey: devKey(),
|
|
16
|
+
ticketKey: devKey(),
|
|
17
|
+
presenceKey: devKey()
|
|
16
18
|
};
|
|
17
19
|
const relayEnded = (code) => {
|
|
18
20
|
delete store.__protobaseDevRelay;
|
|
@@ -20,7 +22,7 @@ const relayEnded = (code) => {
|
|
|
20
22
|
};
|
|
21
23
|
/**
|
|
22
24
|
* The config with a relay of its own when `realtime.relay` names none: without a `url`, protobase dev runs the relay
|
|
23
|
-
* from its npm package for the app at `devUrl`, with keys it makes unless the config sets them, and gives the app its
|
|
25
|
+
* from its npm package for the app at `devUrl`, with keys it makes unless the config sets them, the presence key too, and gives the app its
|
|
24
26
|
* address and keys; its apps file declares the events of `views`' typing conversation pages too. It starts on the first load whose config has `realtime.relay`, and again when an edit changes the
|
|
25
27
|
* app's entry in its apps file; a config without `realtime.relay`, or one with a `url`, stops it.
|
|
26
28
|
*/
|
|
@@ -35,7 +37,11 @@ const withDevRelay = async (config, projectDir, devUrl, views) => {
|
|
|
35
37
|
...relay,
|
|
36
38
|
url: devUrl,
|
|
37
39
|
apiKey: relay.apiKey || keys.apiKey,
|
|
38
|
-
ticketKey: relay.ticketKey || keys.ticketKey
|
|
40
|
+
ticketKey: relay.ticketKey || keys.ticketKey,
|
|
41
|
+
...relay.presence && { presence: {
|
|
42
|
+
...relay.presence,
|
|
43
|
+
key: relay.presence.key || keys.presenceKey
|
|
44
|
+
} }
|
|
39
45
|
});
|
|
40
46
|
const entry = JSON.stringify({
|
|
41
47
|
...relayAppEntry(options, {
|
package/dist/relay/app-entry.js
CHANGED
|
@@ -3,29 +3,44 @@ import { relayClientEvents, relayPresencePath, typingResources } from "@protobas
|
|
|
3
3
|
/** How long a person who closed their last socket still counts as present, so a phone that reconnects never goes offline. */
|
|
4
4
|
const presenceGraceSeconds = 30;
|
|
5
5
|
const systemPath = (apiPath = "/api/v1") => apiPath.slice(0, apiPath.lastIndexOf("/"));
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* The part of the app's entry in the relay's apps file that its build decides, without its address, id or any key: the
|
|
8
|
+
* events its clients may send on each channel resource, typing included where a conversation page types, and, with
|
|
9
|
+
* presence, the path of the app's endpoint its reports go to and their grace. `protobase build` writes it into the
|
|
10
|
+
* bundle's manifest, and `relayAppEntry` builds on it.
|
|
11
|
+
*/
|
|
12
|
+
const relayAppPart = (relay, { apiPath, views }) => {
|
|
13
|
+
const clientEvents = relayClientEvents(relay.channels, typingResources(views));
|
|
14
|
+
return {
|
|
15
|
+
...clientEvents && { client_events: clientEvents },
|
|
16
|
+
...relay.presence && { presence: {
|
|
17
|
+
path: relayPresencePath(systemPath(apiPath)),
|
|
18
|
+
grace_seconds: presenceGraceSeconds
|
|
19
|
+
} }
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
const presenceEntry = ({ path, grace_seconds }, key, appUrl) => {
|
|
7
23
|
if (!appUrl) throw new Error("realtime.relay.presence needs the app's url (url or PROTOBASE_URL), where the relay posts its presence reports");
|
|
8
24
|
return {
|
|
9
|
-
url: new URL(
|
|
10
|
-
key
|
|
11
|
-
grace_seconds
|
|
25
|
+
url: new URL(path, appUrl).href,
|
|
26
|
+
key,
|
|
27
|
+
grace_seconds
|
|
12
28
|
};
|
|
13
29
|
};
|
|
14
30
|
/**
|
|
15
|
-
* The app's entry in the relay's apps file: its id, its keys, the browser origin of its URL,
|
|
16
|
-
*
|
|
17
|
-
* reports go.
|
|
31
|
+
* The app's entry in the relay's apps file: its id, its keys, the browser origin of its URL, and its part of the build
|
|
32
|
+
* (`relayAppPart`), with presence's endpoint at the app's URL and its key.
|
|
18
33
|
*/
|
|
19
|
-
const relayAppEntry = (relay, { url,
|
|
20
|
-
const
|
|
34
|
+
const relayAppEntry = (relay, { url, ...build }) => {
|
|
35
|
+
const { client_events, presence } = relayAppPart(relay, build);
|
|
21
36
|
return {
|
|
22
37
|
id: relay.app,
|
|
23
38
|
api_keys: [relay.apiKey],
|
|
24
39
|
ticket_keys: [relay.ticketKey],
|
|
25
40
|
origins: url ? [new URL(url).origin] : [],
|
|
26
|
-
...
|
|
27
|
-
...relay.presence && { presence: presenceEntry(relay.presence, url
|
|
41
|
+
...client_events && { client_events },
|
|
42
|
+
...presence && relay.presence && { presence: presenceEntry(presence, relay.presence.key, url) }
|
|
28
43
|
};
|
|
29
44
|
};
|
|
30
45
|
//#endregion
|
|
31
|
-
export { relayAppEntry };
|
|
46
|
+
export { relayAppEntry, relayAppPart };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.125.1",
|
|
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.
|
|
47
|
-
"@protobase/layout": "0.
|
|
48
|
-
"@protobase/query": "0.
|
|
49
|
-
"@protobase/schema": "0.
|
|
50
|
-
"@protobase/server": "0.
|
|
51
|
-
"@protobase/ui": "0.
|
|
52
|
-
"@protobase/workflows": "0.
|
|
46
|
+
"@protobase/config": "0.125.1",
|
|
47
|
+
"@protobase/layout": "0.125.1",
|
|
48
|
+
"@protobase/query": "0.125.1",
|
|
49
|
+
"@protobase/schema": "0.125.1",
|
|
50
|
+
"@protobase/server": "0.125.1",
|
|
51
|
+
"@protobase/ui": "0.125.1",
|
|
52
|
+
"@protobase/workflows": "0.125.1",
|
|
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",
|
|
@@ -16,7 +16,7 @@ Mail the app sends, the PDF documents it makes, and forms for people without an
|
|
|
16
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.
|
|
17
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.
|
|
18
18
|
- [From addresses](../reference/email.md#from-addresses): Each send-as address is a record on the person's mailbox, with a display name, a signature of its own and a state. With the optional `gmail.settings.basic` scope, Gmail lists them and says which it really sends from, and the app refuses to send from an address Gmail would replace. The app sends from the record it names, or the person's default.
|
|
19
|
-
- [
|
|
19
|
+
- [Verifying a From address](../reference/email.md#verifying-a-from-address) (beta): The app plugs in its own way to prove a From address its mailbox provider cannot vouch for, such as a hosting platform's test-mail check: a verifier sends one test message through the person's mailbox, and its proof makes the address verified until it runs out. Verifications wait, survive a restart and settle once, by the app's own check each minute or by a report carrying the verification's secret.
|
|
20
20
|
- [A From address on a record](../reference/email.md#a-from-address-on-a-record) (beta): A field such as a client's "Send from" is a dropdown of the person's addresses with their states, and an address a record holds cannot be removed.
|
|
21
21
|
- [Public forms](../reference/forms.md#what-the-visitor-sees): A form at its own address lets people without an account create a record, such as a contact request.
|
|
22
22
|
- [Bot check](../reference/forms.md#bot-check): Each submission passes a check in the browser, without a third-party service or a puzzle.
|
|
@@ -17,7 +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. `protobase dev` runs a relay for the app by itself. An app on a platform that runs the relay picks up its address and keys from PROTOBASE_RELAY_URL, PROTOBASE_RELAY_APP, PROTOBASE_RELAY_API_KEY and
|
|
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. `protobase dev` runs a relay for the app by itself. An app on a platform that runs the relay picks up its address and keys from PROTOBASE_RELAY_URL, PROTOBASE_RELAY_APP, PROTOBASE_RELAY_API_KEY, PROTOBASE_RELAY_TICKET_KEY and PROTOBASE_RELAY_PRESENCE_KEY; a value in the config wins. `protobase build` writes the app's events and presence for the relay's apps file into the bundle's manifest, and the platform's PROTOBASE_RELAY_ENABLED switch, true or false, says when it moves the app.
|
|
21
21
|
- [Relay presence](../reference/realtime-relay.md#presence) (in development): The relay reports who comes online, goes away and goes offline; the app keeps it in a resource of its own, raises that resource's events, so workflows can act when someone goes offline, and tells the people who share a conversation with them, whose sidebar and members page show them online, away or offline.
|
|
22
22
|
- [Relay in pages](../reference/realtime-relay.md#pages) (in development): Pages follow the relay on one socket: open views stay current from its notices and read again once after a reconnect, conversations show who types, sidebar groups say "typing…" and count unread messages without reading per message, also of a conversation the person was just added to, all by configuration; `client.relay` gives the same from code.
|
|
23
23
|
- [Relay client events](../reference/realtime-relay.md#client-events) (in development): Each channel resource declares in the config the events its clients may send each other, such as typing, with a schema, a size and a rate.
|
|
@@ -157,6 +157,7 @@ export const generateUserId: AuthHooks['generateUserId'] = async ({ db }) => {
|
|
|
157
157
|
| `onOrganizationCreated` | `({ organization, member }, { db })`, after an organization is created, with its owner's membership |
|
|
158
158
|
| `beforeOrganizationDeleted` | `(organization, { db })`, before an organization is deleted; throwing refuses it |
|
|
159
159
|
| `organizationHooks` | Better Auth's organization hooks by name, each with `{ db }` last, run after Protobase's own |
|
|
160
|
+
| `senderVerifiers` | `(add_verifier)`, once as the app starts: adds the app's ways to prove a From address; see [Verifying a From address](email.md#verifying-a-from-address) |
|
|
160
161
|
|
|
161
162
|
A mailer of the project's own, for sign-in's mail, is the default export of `auth/mailer.ts` (see [Password reset](#password-reset)). An authenticator of its own, in place of the one `authenticate` describes, is the default export of `auth/authenticate.ts` (see [Tokens and roles](#tokens-and-roles)).
|
|
162
163
|
|
|
@@ -289,7 +289,11 @@ By default the bundle runs on Node and on Bun. `--bun` makes it a bundle for Bun
|
|
|
289
289
|
"native": { "@capacitor/core": "8.5.3", "@capacitor/ios": "8.5.3" },
|
|
290
290
|
"mobile": { "appId": "com.example.shop", "plugins": { "@capacitor/camera": "^8.0.1" }, "push": true },
|
|
291
291
|
"nodeModules": "node_modules",
|
|
292
|
-
"migrations": "migrations"
|
|
292
|
+
"migrations": "migrations",
|
|
293
|
+
"relay": {
|
|
294
|
+
"client_events": { "channels": { "conversations": { "events": { "typing": { "schema": { "type": "object" }, "max_bytes": 256, "per_second": 2, "burst": 4 } } } } },
|
|
295
|
+
"presence": { "path": "/api/relay/presence", "grace_seconds": 30 }
|
|
296
|
+
}
|
|
293
297
|
}
|
|
294
298
|
```
|
|
295
299
|
|
|
@@ -302,6 +306,7 @@ By default the bundle runs on Node and on Bun. `--bun` makes it a bundle for Bun
|
|
|
302
306
|
- `theme` is the project's [theme](theme.md), which the app links at `/protobase.theme.css`. It is always there, empty when the project has none.
|
|
303
307
|
- `nodeModules` is present only when the config module imports [native packages](#native-packages). It is always the `node_modules` folder beside `server`, where Bun and Node resolve the module's imports from, and holds plain packages: JavaScript, `package.json` files and native binaries for linux x64 and arm64 (glibc), which the runtime loads with `dlopen`. A host keeps it next to the server module and must not mount it `noexec` (an add-on there then fails with `failed to map segment from shared object`). Its binaries link nothing but glibc, `libstdc++.so.6`, `libgcc_s.so.1` and libraries in the bundle itself, so the run image must have those three. Without `nodeModules`, the server module is the only file the runtime reads.
|
|
304
308
|
- `migrations` is present only when the project has a `db/migrations` folder: its `.sql` files, which the runtime's `migrate` applies (see [Deploy](../guides/deploy.md)). A host never serves it.
|
|
309
|
+
- `relay` is present only when the config has [`realtime.relay`](realtime-relay.md): the app's part of its entry in the relay's apps file, as [`relay app`](#relay-app) prints it, without the address, id or any key: `client_events`, when a channel resource has events, and with presence `presence`, the path of the app's presence endpoint and the reports' `grace_seconds`. A host that runs the relay completes it with the app's id, keys, origin and presence key, and the presence endpoint at the app's address.
|
|
305
310
|
- `api` lists the path prefixes the server answers. A path is under a prefix when it equals it or continues it with `/` (`/api` covers `/api/meta` and `/api/v1:batchWrite`, not `/apiary`). It is always `/api` and the two OAuth discovery documents [MCP clients](auth.md#oauth-for-mcp-clients) read, which answer 404 without MCP: a bundle assumes the API lives under `/api`, with the resources at the default `apiPath` `/api/v1`, `/api/meta`, the docs, the API functions and the built-in assistant beside them and Better Auth at `/api/auth`. A bundle built before them sends them to the UI: rebuild it. The serve runtime refuses a config that sets another `apiPath`.
|
|
306
311
|
- Every other path is the UI's. A `GET` or `HEAD` for a file in `public` gets that file; a folder gets its `index.html`. Otherwise a request whose `Accept` header contains `text/html` (a navigation) gets `spa` with status 200, so deep links such as `/orders/42` load the app; anything else gets 404. Other methods get 405.
|
|
307
312
|
- Files under an `assets/` folder, `public/assets/` and each plugin's, are named by their content hash and never change: serve them with `Cache-Control: public, max-age=31536000, immutable`, and everything else, `index.html`, each `plugin.json` and the theme, with `no-cache`.
|
|
@@ -481,9 +486,9 @@ Serves the API of a bundle from `protobase build` and owns the process around it
|
|
|
481
486
|
| `PROTOBASE_FIRST_ADMIN_URL` | the hosting platform's page where the app's first user is added, such as its console's; while the app has no users, the sign-in page links there in place of the `protobase users create` command ([the first admin](auth.md#first-run)) |
|
|
482
487
|
| `PROTOBASE_RUNS_ON_NOTE` | `true` ends the sign-in page on the [Runs on Protobase note](app-identity.md#runs-on-protobase-note), for a hosting platform; default `false`, and any value but `true` or `false` stops startup |
|
|
483
488
|
| `PROTOBASE_RUNTIME_URL` | the endpoint behind the top bar's [runtime update button](versioning.md#runtime-updates), such as a hosting platform's; without it there is no button |
|
|
484
|
-
| `PROTOBASE_MAIL_CHECK_URL` | the hosting platform's service that [checks a From address](email.md#checking-a-from-address), signed with a key derived from `PROTOBASE_SECRET`; without it the account page says addresses cannot be checked |
|
|
485
489
|
| `PROTOBASE_SENTRY_DSN` | the DSN of a Sentry-compatible error tracker the app's server and admin app send their errors to, after the config's `errorReporting` ([Error reporting](api.md#error-reporting)); without it nothing is sent |
|
|
486
|
-
| `PROTOBASE_RELAY_URL`, `PROTOBASE_RELAY_APP`, `PROTOBASE_RELAY_API_KEY`, `PROTOBASE_RELAY_TICKET_KEY` | the address, the app's id
|
|
490
|
+
| `PROTOBASE_RELAY_URL`, `PROTOBASE_RELAY_APP`, `PROTOBASE_RELAY_API_KEY`, `PROTOBASE_RELAY_TICKET_KEY`, `PROTOBASE_RELAY_PRESENCE_KEY` | the address, the app's id, its API and ticket keys and its presence key of the [realtime relay](realtime-relay.md#from-the-platform), each where the config's `realtime.relay` leaves it out; without `realtime.relay` the relay stays off |
|
|
491
|
+
| `PROTOBASE_RELAY_ENABLED` | `true` when the platform moves the app to the [realtime relay](realtime-relay.md#from-the-platform); `true` without `realtime.relay` in the config stops the server. Unset or empty is `false`; any other value stops the server |
|
|
487
492
|
| `PROTOBASE_MAP_STYLE_URL` | the URL of the MapLibre style the record page's [maps](ui-config.md#maps) are drawn with, after the config's `maps`; without it there are no maps |
|
|
488
493
|
| `PROTOBASE_SOURCES` | other Protobase APIs whose resources the app draws as its own, a JSON list of `{ "url", "label", "resources", "roles"? }` after the config's `remoteResources` ([Remote resources](remote-resources.md#declaring-a-source)) |
|
|
489
494
|
| `PROTOBASE_FILES_<NAME>`, `PROTOBASE_FILES_RETENTION`, `PROTOBASE_FILES_SECRET` | [file providers](files.md#providers) and their settings, over `files` in the config; a bucket's credentials in `PROTOBASE_FILES_<NAME>_ACCESS_KEY_ID` and `_SECRET_ACCESS_KEY` |
|
|
@@ -679,7 +684,7 @@ Recounts a [time rollup](data-config.md#keeping-it-up-to-date)'s buckets from th
|
|
|
679
684
|
protobase relay app
|
|
680
685
|
```
|
|
681
686
|
|
|
682
|
-
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`, or else `PROTOBASE_RELAY_APP`, `PROTOBASE_RELAY_API_KEY` and `PROTOBASE_RELAY_TICKET_KEY`, and in `origins` the origin of the app's `url` (or `PROTOBASE_URL`); in `client_events` each channel resource's [client events](realtime-relay.md#client-events), with `typing` on those whose conversation page types; with [presence](realtime-relay.md#presence), `presence` with the app's presence endpoint at that `url`, the presence key and a `grace_seconds` of 30. 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.
|
|
687
|
+
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`, or else `PROTOBASE_RELAY_APP`, `PROTOBASE_RELAY_API_KEY` and `PROTOBASE_RELAY_TICKET_KEY`, and in `origins` the origin of the app's `url` (or `PROTOBASE_URL`); in `client_events` each channel resource's [client events](realtime-relay.md#client-events), with `typing` on those whose conversation page types; with [presence](realtime-relay.md#presence), `presence` with the app's presence endpoint at that `url`, the presence key (or `PROTOBASE_RELAY_PRESENCE_KEY`) and a `grace_seconds` of 30. Its `client_events` and presence path and grace are the bundle manifest's [`relay`](#the-manifest). 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.
|
|
683
688
|
|
|
684
689
|
## `auth migration`
|
|
685
690
|
|
|
@@ -414,6 +414,8 @@ A mailbox may send as more than its own address, such as Gmail's send-as address
|
|
|
414
414
|
- `failed`: a complete listing since the address was added did not hold it, so Gmail would send from the account's own address instead.
|
|
415
415
|
- `unverified`: nothing says either way.
|
|
416
416
|
|
|
417
|
+
Where the provider says nothing, a [verifier](#verifying-a-from-address) of the app may prove the address `verified`.
|
|
418
|
+
|
|
417
419
|
The state is worked out each time it is read, from what typed the address and what the provider last listed. An address the listing leaves out keeps its record and its id: only its listed state goes.
|
|
418
420
|
- **Without the scope:** a Gmail link without `gmail.settings.basic` is told which scope it lacks. The account page then offers **Allow address checks**, which connects Gmail again asking for it, and sends the person back to the account page.
|
|
419
421
|
- **Name:** an address may carry a display name, which the From header shows beside it, such as `From: Shop billing <billing@shop.example>`, as mail sent by hand from a send-as address shows the name set up for it; a name that is not ASCII is encoded. Left empty, the header holds the bare address.
|
|
@@ -458,24 +460,59 @@ export default defineFunction(async (request, { personalMail }) => {
|
|
|
458
460
|
|
|
459
461
|
Each acts on the signed-in person's own addresses and connections only: any other id answers `404` before anything is done.
|
|
460
462
|
- **Upgrading:** an address entered before From addresses were records goes on its owner's Gmail connection when they had exactly one. With none or several it shows **No mailbox**, and the person removes it and adds it again.
|
|
461
|
-
- <gap>An address on a mailbox linked without `gmail.settings.basic` cannot be checked before each send because only the account page
|
|
463
|
+
- <gap>An address on a mailbox linked without `gmail.settings.basic` cannot be checked before each send because only a [verification](#verifying-a-from-address) started from the account page is implemented for it.</gap>
|
|
462
464
|
- <gap>An address cannot be shared with others who send mail because proving that the person owns the address is not implemented.</gap>
|
|
463
465
|
|
|
464
|
-
###
|
|
466
|
+
### Verifying a From address
|
|
465
467
|
|
|
466
|
-
:::
|
|
467
|
-
|
|
468
|
+
:::caution[Beta]
|
|
469
|
+
Protobase ships no verifier: an app, or the platform it runs on, plugs in its own.
|
|
468
470
|
:::
|
|
469
471
|
|
|
470
|
-
Gmail sends from the account's own address, without an error, when a From address is not one of its verified send-as addresses
|
|
472
|
+
Gmail sends from the account's own address, without an error, when a From address is not one of its verified send-as addresses, and a mailbox that cannot list its send-as addresses leaves an address `unverified`. A verifier proves such an address another way, such as by sending one test message from it and reading how it arrives. The app's trusted code adds verifiers with `add_verifier`, from the project's `auth/hooks.ts`:
|
|
473
|
+
|
|
474
|
+
```ts
|
|
475
|
+
import type { AuthHooks } from '@protobase/server'
|
|
476
|
+
|
|
477
|
+
export const senderVerifiers: AuthHooks['senderVerifiers'] = (add_verifier) => add_verifier(testMailVerifier)
|
|
478
|
+
```
|
|
479
|
+
|
|
480
|
+
A host's runtime can pass its own in `createAuth`'s `senderVerifiers`. A verifier is a `SenderAddressVerifier`:
|
|
471
481
|
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
482
|
+
```ts
|
|
483
|
+
const testMailVerifier: SenderAddressVerifier = {
|
|
484
|
+
id: 'test-mail',
|
|
485
|
+
verify: async ({ verification_id, address, secret, locale }, { send }) => {
|
|
486
|
+
const to = await checkService.issue({ verification_id, secret })
|
|
487
|
+
await send({ to, subject: `Test message for ${address}`, text: 'This message checks that your mailbox sends from this address.' })
|
|
488
|
+
return { state: 'pending', expires_at: new Date(Date.now() + 10 * 60_000) }
|
|
489
|
+
},
|
|
490
|
+
check: async ({ verification_id }) => checkService.result(verification_id),
|
|
491
|
+
}
|
|
492
|
+
```
|
|
493
|
+
|
|
494
|
+
- **`id`:** stored on each verification, so it stays the same across releases: lowercase letters, digits, `_`, `.` and `-`, starting with a letter, at most 64 characters. Two verifiers with one id, or a verifier without `auth.personalMail`, stop startup.
|
|
495
|
+
- **`verify(input, tools)`:** starts a verification of `address`. `tools.send({ to, subject, text, html? })` sends one test message through the address's own mailbox, From that address, to one recipient: a From, copies, headers or attachments it is given are left out, and a second send is refused.
|
|
496
|
+
- **`check(input)`:** optional. The app's sweep calls it each minute a pending verification is due, until it settles or expires.
|
|
497
|
+
- **Outcomes:** `verify` and `check` answer one of these.
|
|
498
|
+
- `{ state: 'pending', expires_at, check_after? }`: `verify` must name `expires_at`, which the app caps at 24 hours after the verification started. `check` cannot move it. The next check comes at `check_after`, else a minute on, and never sooner than a minute on.
|
|
499
|
+
- `{ state: 'verified', valid_until }`: `valid_until` is required, lies ahead, and is capped at 28 days.
|
|
500
|
+
- `{ state: 'failed', error_code, error? }`: `error_code` is a lowercase name, such as `from_rewritten`. `error` is plain text of at most 500 characters, with no control characters but line breaks and tabs, shown as text and never as markup.
|
|
501
|
+
|
|
502
|
+
An outcome that breaks these rules, or a `verify` that throws, fails the verification as `verifier_error`. The address's state does not change.
|
|
503
|
+
- **One at a time:** an address has at most one pending verification per verifier. It is stored before `verify` runs, so starting it again sends nothing while it is pending. A verification whose `verify` never returned expires after 5 minutes, and the next start takes its place.
|
|
504
|
+
- **Expiry:** a verification still pending at `expires_at` fails as `verification_expired`, from the sweep, `auth.mail-sender-verifications`, which runs each minute on the app's jobs.
|
|
505
|
+
- **Reports:** an outside service settles a verification with `POST /api/auth/mail-sender-verifications/report`, with this JSON body: `{ verifier, secret, state: 'verified', valid_until }` or `{ verifier, secret, state: 'failed', error_code, error? }`.
|
|
506
|
+
- `secret` is the one `verify` was given: 256 random bits, made for that verification alone. The app keeps only its SHA-256, so it is never handed out again. The verification's id is not a secret.
|
|
507
|
+
- The secret is read from the body only. Keep it out of URLs and logs.
|
|
508
|
+
- A report settles the verification only for the verifier that started it, while it is pending and before it expires, and once only. Whichever comes first wins: the report, the sweep or `verify`'s own outcome.
|
|
509
|
+
- Any report that settles nothing answers the same `403` with `code: "VERIFICATION_REFUSED"`, whatever the reason. A malformed outcome answers `400` before anything is looked up.
|
|
510
|
+
- **The address's state:** a verified verification makes an address the provider says nothing of `verified`, until its `valid_until`. It never outweighs what the provider says, such as a `failed` listing. It counts only while its verifier is registered, and only if it settled after the address was last removed. A failed verification shows on the account page and leaves the state as it was.
|
|
511
|
+
- **The account page:** adding an address verifies it at once. Its dialog, under **Edit**, verifies it again with **Verify address**, and after a result with **Verify again**. While a verification is pending, the dialog reads it again every 3 seconds for up to 2 minutes. Without a verifier, the dialog says the app cannot verify From addresses, and how to check one by hand.
|
|
512
|
+
- **The account page's calls:**
|
|
513
|
+
- `GET /api/auth/account/mail-senders` says `verifiers: true` when the app has any, and gives each address its latest `verifications`, one per verifier: `verifier`, `state`, `expiresAt` while pending, `settledAt`, `validUntil`, `errorCode` and `error`.
|
|
514
|
+
- `POST .../mail-senders/verify { id }` starts each verifier on one of the person's addresses on a connection they can send through, and answers its `verifications`.
|
|
515
|
+
- Staff signed in as the person cannot start one.
|
|
479
516
|
|
|
480
517
|
### A From address on a record
|
|
481
518
|
|
|
@@ -43,7 +43,7 @@ export default defineConfig(({ env }) => ({
|
|
|
43
43
|
| `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)). |
|
|
44
44
|
| `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. |
|
|
45
45
|
| `channels.<resource>.events` | The [events](#client-events) the channel's members may send each other, by name, each with its payload's `schema`, its `maxBytes` and the rate one person may send it at, `perSecond` in bursts of `burst`. |
|
|
46
|
-
| `presence` | Turns on [presence](#presence): the app's own resource it is kept in, its fields of the person's user id (`user`), the status (`status`) and when it began (`at`), and the bearer token of the relay's reports (`key`), at least 32 characters. |
|
|
46
|
+
| `presence` | Turns on [presence](#presence): the app's own resource it is kept in, its fields of the person's user id (`user`), the status (`status`) and when it began (`at`), and the bearer token of the relay's reports (`key`), at least 32 characters, which defaults to [`PROTOBASE_RELAY_PRESENCE_KEY`](#from-the-platform). |
|
|
47
47
|
|
|
48
48
|
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, after the auth store's steps when the same file writes them, so a new app's first migration sets up both; the server checks it at start.
|
|
49
49
|
|
|
@@ -59,9 +59,14 @@ An app on a platform that runs the relay picks up its address and keys from the
|
|
|
59
59
|
| `PROTOBASE_RELAY_APP` | `app` |
|
|
60
60
|
| `PROTOBASE_RELAY_API_KEY` | `apiKey` |
|
|
61
61
|
| `PROTOBASE_RELAY_TICKET_KEY` | `ticketKey` |
|
|
62
|
+
| `PROTOBASE_RELAY_PRESENCE_KEY` | `presence.key` |
|
|
62
63
|
|
|
63
64
|
Each is a default on its own: a value in the config wins, and a key that neither sets stops the server at start, naming the key and its variable. The relay stays off without `realtime.relay` in the config, however many of these are set: the app turns it on by declaring its channels.
|
|
64
65
|
|
|
66
|
+
`PROTOBASE_RELAY_ENABLED` is the platform's switch: `true` when its apps file carries the app's entry, `false`, or unset or empty, otherwise; any other value stops the server at start, naming it. A config with `realtime.relay` uses the relay whatever it says. `true` without `realtime.relay` stops the server at start, as the channels and their members come only from the config. <gap>An app without `realtime.relay` cannot move to the relay with `PROTOBASE_RELAY_ENABLED` because deriving its channels and their members from its conversation pages is not implemented.</gap>
|
|
67
|
+
|
|
68
|
+
[`protobase build`](cli.md#the-manifest) writes the app's part of its apps file entry into the bundle's manifest, as `relay`: its `client_events` and, with presence, the presence endpoint's path and `grace_seconds`, without the address, id or any key. A platform reads it from each build and completes the entry with the app's id, keys, origin and presence key, and the endpoint at the app's address.
|
|
69
|
+
|
|
65
70
|
```ts
|
|
66
71
|
export default defineConfig({
|
|
67
72
|
realtime: { relay: { channels: { conversations: { members: { resource: 'conversation_members', channel: 'conversation_id', user: 'user_id' } } } } },
|
|
@@ -78,7 +83,7 @@ npm install --save-dev @protobase/realtime
|
|
|
78
83
|
|
|
79
84
|
<gap>`protobase dev` cannot run the relay without the project installing `@protobase/realtime` because the CLI does not depend on it until the package is published.</gap>
|
|
80
85
|
|
|
81
|
-
It starts the relay on the first load of a config with `realtime.relay`, an edit that adds it included, on a free port of `127.0.0.1`, serving this one app with the dev server's origin, and gives the app its address. The keys are the config's when it sets them, and otherwise made anew for each `protobase dev`. An edit that changes the app's id or keys starts it again, one that removes `realtime.relay` or sets a `url` stops it, and it stops with `dev`. Its own messages, such as an apps file it refuses, show in the terminal. With a `url`, the app uses that relay and `dev` starts none. `dev` reads [the platform's variables](#from-the-platform) for neither: the app's id comes from the config.
|
|
86
|
+
It starts the relay on the first load of a config with `realtime.relay`, an edit that adds it included, on a free port of `127.0.0.1`, serving this one app with the dev server's origin, and gives the app its address. The keys, the presence key included, are the config's when it sets them, and otherwise made anew for each `protobase dev`. An edit that changes the app's id or keys starts it again, one that removes `realtime.relay` or sets a `url` stops it, and it stops with `dev`. Its own messages, such as an apps file it refuses, show in the terminal. With a `url`, the app uses that relay and `dev` starts none. `dev` reads [the platform's variables](#from-the-platform) for neither: the app's id comes from the config.
|
|
82
87
|
|
|
83
88
|
## Tickets
|
|
84
89
|
|
|
@@ -122,7 +127,7 @@ The resource is keyed by its user field, its status field is text or an enum of
|
|
|
122
127
|
|
|
123
128
|
Only the relay writes the records, so give no role `presences.create`, `presences.update` or `presences.delete`: whoever may write one can set anyone's presence and raise its events. A role that reads the resource reads the presence of everyone its rows allow, which can reach further than `people` does, so grant `presences.read` no wider than that.
|
|
124
129
|
|
|
125
|
-
The relay posts its reports to `POST /api/relay/presence` with the presence key as its bearer token, never a sign-in; the [apps file entry](cli.md#relay-app) names the address. A report holds at most 500 changes, each a person's status and when it began. The app writes them in one statement, which replaces a record's status only with one that began later, and answers `204`: a report the relay sends again, or one that arrives late, changes nothing. A report with a missing or wrong key is refused with `401` before its body is read. To change the key, change it in the config and in the apps file; the relay sends a refused report again, waiting up to a minute between tries, until the app takes it, so no change is lost. When the relay restarted, which a report says with its start time, everyone it has not reported since and who is not offline yet is set offline as of that start, once in each server process for each start; the relay sends no report until someone's status changes, so this waits for the first one.
|
|
130
|
+
The relay posts its reports to `POST /api/relay/presence` with the presence key as its bearer token, never a sign-in; the [apps file entry](cli.md#relay-app) names the address. A report holds at most 500 changes, each a person's status and when it began. The app writes them in one statement, which replaces a record's status only with one that began later, and answers `204`: a report the relay sends again, or one that arrives late, changes nothing. A report with a missing or wrong key is refused with `401` before its body is read. To change the key, change it in the config, or `PROTOBASE_RELAY_PRESENCE_KEY`, and in the apps file; the relay sends a refused report again, waiting up to a minute between tries, until the app takes it, so no change is lost. When the relay restarted, which a report says with its start time, everyone it has not reported since and who is not offline yet is set offline as of that start, once in each server process for each start; the relay sends no report until someone's status changes, so this waits for the first one.
|
|
126
131
|
|
|
127
132
|
Each write goes through the resource's table, so its changes raise the resource's [events](events.md), [webhooks](webhooks.md) and [workflows](workflows.md) as any other record's do, such as a workflow on `presences.wentOffline`. An offline report raises its event once.
|
|
128
133
|
|