@protobase/cli 0.73.5 → 0.75.0
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/mobile/capacitor-config.js +11 -2
- package/dist/mobile/generate.js +6 -3
- package/dist/mobile/google-services.js +28 -0
- package/dist/mobile/load-project.js +4 -2
- package/dist/mobile/package.js +2 -1
- package/dist/mobile/pinned-packages.js +4 -1
- package/dist/mobile/protobase-plugin.js +6 -2
- package/dist/mobile/run.js +10 -3
- package/dist/serve/lifecycle.js +2 -1
- package/dist/serve/mobile-release.js +4 -4
- package/package.json +8 -8
- package/skills/protobase/references/features/notifications.md +1 -1
- package/skills/protobase/references/features/workflows.md +1 -1
- package/skills/protobase/references/guides/mobile-app.md +13 -1
- package/skills/protobase/references/reference/api.md +1 -1
- package/skills/protobase/references/reference/mcp.md +2 -2
- package/skills/protobase/references/reference/notifications.md +9 -9
- package/skills/protobase/references/reference/workflows.md +4 -4
package/dist/cli/package.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { pushPlugin } from "./pinned-packages.js";
|
|
1
2
|
import path from "node:path";
|
|
2
3
|
import { rm, writeFile } from "node:fs/promises";
|
|
3
4
|
import { capacitorOrigin } from "@protobase/schema/internal";
|
|
@@ -5,6 +6,11 @@ import { capacitorOrigin } from "@protobase/schema/internal";
|
|
|
5
6
|
const protobasePlugin = "@protobase/mobile";
|
|
6
7
|
const keyboardPlugin = "@capacitor/keyboard";
|
|
7
8
|
const liveUpdatePlugin = "@capawesome/capacitor-live-update";
|
|
9
|
+
const pushPresentation = [
|
|
10
|
+
"badge",
|
|
11
|
+
"sound",
|
|
12
|
+
"alert"
|
|
13
|
+
];
|
|
8
14
|
const readyTimeout = 3e4;
|
|
9
15
|
/**
|
|
10
16
|
* The app's `capacitor.config.json`, every key it sets named here. It never sets `server.url`, the hostname or the
|
|
@@ -15,12 +21,13 @@ const readyTimeout = 3e4;
|
|
|
15
21
|
* files, background updates off, a rolled-back bundle blocked and `readyTimeout`, within which the shell must call
|
|
16
22
|
* ready() or the app goes back to its own files. CapacitorHttp and CapacitorCookies stay off; the keyboard plugin
|
|
17
23
|
* resizes natively, its default, and fills the space beside the keyboard's rounded corners with the page's background
|
|
18
|
-
* instead of black.
|
|
24
|
+
* instead of black. With `push`, Capacitor's push plugin is compiled in and shows a push while the app is open. It
|
|
25
|
+
* never sets `server.allowNavigation`, so no other host loads inside the WebView. Protobase's plugin is compiled in last, so its stand-ins replace any plugin of the same name.
|
|
19
26
|
* Service workers get nothing from the local server on Android, which they would reach past the WebViewClient that
|
|
20
27
|
* guards it. The file ships outside the app's web part, so the fingerprint in the user agent and ProtobaseAuth's
|
|
21
28
|
* origins are beyond page script and a live update.
|
|
22
29
|
*/
|
|
23
|
-
const capacitorConfig = ({ appId, appName, fingerprint, shellVersion, plugins, liveUpdate, allowances, apiOrigin, platform, release }) => ({
|
|
30
|
+
const capacitorConfig = ({ appId, appName, fingerprint, shellVersion, plugins, liveUpdate, allowances, apiOrigin, platform, release, push }) => ({
|
|
24
31
|
appId,
|
|
25
32
|
appName,
|
|
26
33
|
webDir: "web",
|
|
@@ -28,6 +35,7 @@ const capacitorConfig = ({ appId, appName, fingerprint, shellVersion, plugins, l
|
|
|
28
35
|
includePlugins: [
|
|
29
36
|
...plugins,
|
|
30
37
|
...liveUpdate ? [liveUpdatePlugin] : [],
|
|
38
|
+
...push ? [pushPlugin] : [],
|
|
31
39
|
keyboardPlugin,
|
|
32
40
|
protobasePlugin
|
|
33
41
|
],
|
|
@@ -37,6 +45,7 @@ const capacitorConfig = ({ appId, appName, fingerprint, shellVersion, plugins, l
|
|
|
37
45
|
origin: capacitorOrigin[platform]
|
|
38
46
|
},
|
|
39
47
|
Keyboard: { autoBackdropColor: "dom" },
|
|
48
|
+
...push && { PushNotifications: { presentationOptions: pushPresentation } },
|
|
40
49
|
...liveUpdate && { LiveUpdate: {
|
|
41
50
|
...liveUpdate,
|
|
42
51
|
readyTimeout,
|
package/dist/mobile/generate.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { copyGoogleServices } from "./google-services.js";
|
|
1
2
|
import { withLocalNetworking } from "./info-plist.js";
|
|
2
3
|
import { withProtobaseIcon } from "./native-icon.js";
|
|
3
4
|
import path from "node:path";
|
|
@@ -6,16 +7,18 @@ import { readFile, rm, writeFile } from "node:fs/promises";
|
|
|
6
7
|
const infoPlist = (ws) => path.join(ws, "ios", "App", "App", "Info.plist");
|
|
7
8
|
/**
|
|
8
9
|
* Generates the platform's native project in the workspace from its capacitor.config.json and app files, replacing
|
|
9
|
-
* the last one: it is never edited by hand. Its home-screen icon is Protobase's,
|
|
10
|
-
* plain http may reach
|
|
10
|
+
* the last one: it is never edited by hand. Its home-screen icon is Protobase's, an Android app with push gets the
|
|
11
|
+
* project's google-services.json from `googleServicesFrom`, and an iOS app calling the API over plain http may reach
|
|
12
|
+
* local addresses.
|
|
11
13
|
*/
|
|
12
|
-
const generatePlatform = async (ws, platform, { cleartext }, cap) => {
|
|
14
|
+
const generatePlatform = async (ws, platform, { cleartext, googleServicesFrom }, cap) => {
|
|
13
15
|
await rm(path.join(ws, platform), {
|
|
14
16
|
recursive: true,
|
|
15
17
|
force: true
|
|
16
18
|
});
|
|
17
19
|
await cap(["add", platform]);
|
|
18
20
|
await withProtobaseIcon(ws, platform);
|
|
21
|
+
if (platform === "android" && googleServicesFrom !== void 0) await copyGoogleServices(googleServicesFrom, ws);
|
|
19
22
|
if (platform !== "ios" || !cleartext) return;
|
|
20
23
|
await writeFile(infoPlist(ws), withLocalNetworking(await readFile(infoPlist(ws), "utf8")));
|
|
21
24
|
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { copyFile, lstat } from "node:fs/promises";
|
|
3
|
+
//#region src/mobile/google-services.ts
|
|
4
|
+
/** Where an Android app's Firebase file is kept: the project's root, next to protobase.config.ts. */
|
|
5
|
+
const googleServicesFile = (projectDir) => path.join(projectDir, "google-services.json");
|
|
6
|
+
/** Why an Android build with `notifications()` has no push, naming the file it looks for. */
|
|
7
|
+
const missingGoogleServices = (projectDir) => `${googleServicesFile(projectDir)} is missing: the Android app builds without push. Put your Firebase project's google-services.json there to turn it on`;
|
|
8
|
+
/**
|
|
9
|
+
* Whether the project has its Firebase file: a regular file, never a link, which the copy would follow out of the
|
|
10
|
+
* project. Anything else at that place stops the build.
|
|
11
|
+
*/
|
|
12
|
+
const hasGoogleServices = async (projectDir) => {
|
|
13
|
+
const file = googleServicesFile(projectDir);
|
|
14
|
+
const stats = await lstat(file).catch((error) => {
|
|
15
|
+
if (error.code === "ENOENT") return void 0;
|
|
16
|
+
throw error;
|
|
17
|
+
});
|
|
18
|
+
if (!stats) return false;
|
|
19
|
+
if (!stats.isFile()) throw new Error(`${file} is not a regular file: put the google-services.json of your Firebase project there`);
|
|
20
|
+
return true;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Copies the project's Firebase file into the generated Android app, where the template's build.gradle applies the
|
|
24
|
+
* google-services plugin only when the file is there.
|
|
25
|
+
*/
|
|
26
|
+
const copyGoogleServices = (projectDir, ws) => copyFile(googleServicesFile(projectDir), path.join(ws, "android", "app", "google-services.json"));
|
|
27
|
+
//#endregion
|
|
28
|
+
export { copyGoogleServices, googleServicesFile, hasGoogleServices, missingGoogleServices };
|
|
@@ -5,20 +5,22 @@ import { appNameOver } from "@protobase/server";
|
|
|
5
5
|
//#region src/mobile/load-project.ts
|
|
6
6
|
/**
|
|
7
7
|
* What a mobile build needs of the project in `dir`, merged as `protobase dev` merges it after the configs of
|
|
8
|
-
* `extensions`: its mobile section, unchecked, and with sign-in on the app's URL, its
|
|
8
|
+
* `extensions`: its mobile section, unchecked, whether it has `notifications()`, and with sign-in on the app's URL, its
|
|
9
|
+
* tokens' issuer, and its name.
|
|
9
10
|
* The project's .env is loaded first, as other commands do, and no `PROTOBASE_ANDROID_*` variable is left in the
|
|
10
11
|
* environment; nothing but the configs runs.
|
|
11
12
|
*/
|
|
12
13
|
const loadMobileProject = async (dir, extensions) => {
|
|
13
14
|
loadNearestEnvFile(dir);
|
|
14
15
|
dropAndroidSigning(process.env);
|
|
15
|
-
const { mobile, auth, url, name } = await loadSourceConfig(dir, {
|
|
16
|
+
const { mobile, auth, url, name, notifications } = await loadSourceConfig(dir, {
|
|
16
17
|
command: "tool",
|
|
17
18
|
extensions
|
|
18
19
|
});
|
|
19
20
|
const appName = appNameOver(process.env, name);
|
|
20
21
|
return {
|
|
21
22
|
mobile,
|
|
23
|
+
notifications: Boolean(notifications),
|
|
22
24
|
auth: auth && url ? {
|
|
23
25
|
issuer: url,
|
|
24
26
|
...appName && { appName }
|
package/dist/mobile/package.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
//#region ../mobile/package.json
|
|
2
2
|
var name = "@protobase/mobile";
|
|
3
|
-
var nativeContract =
|
|
3
|
+
var nativeContract = 9;
|
|
4
4
|
var dependencies = {
|
|
5
5
|
"@capacitor/android": "8.5.3",
|
|
6
6
|
"@capacitor/app": "8.1.2",
|
|
@@ -8,6 +8,7 @@ var dependencies = {
|
|
|
8
8
|
"@capacitor/core": "8.5.3",
|
|
9
9
|
"@capacitor/ios": "8.5.3",
|
|
10
10
|
"@capacitor/keyboard": "8.0.6",
|
|
11
|
+
"@capacitor/push-notifications": "8.1.3",
|
|
11
12
|
"@capacitor/splash-screen": "8.0.2",
|
|
12
13
|
"@capawesome/capacitor-live-update": "8.7.1"
|
|
13
14
|
};
|
|
@@ -20,9 +20,12 @@ const pinnedNative = {
|
|
|
20
20
|
[name]: `native-${nativeContract}`
|
|
21
21
|
};
|
|
22
22
|
const liveUpdate = "@capawesome/capacitor-live-update";
|
|
23
|
+
/** Capacitor's push plugin, which @protobase/mobile pins and an Android app with `notifications()` compiles in. */
|
|
24
|
+
const pushPlugin = "@capacitor/push-notifications";
|
|
23
25
|
/** Why the plugin `key`, a package that is or names `name`, may not be listed; `undefined` when it may. */
|
|
24
26
|
const pinnedProblem = (key, name = key) => {
|
|
25
27
|
if (name === liveUpdate) return `mobile.plugins lists ${key}, ${liveUpdate}: live updates come with Protobase's updater, which mobile.publicKey turns on; remove it from mobile.plugins`;
|
|
28
|
+
if (name === "@capacitor/push-notifications") return `mobile.plugins lists ${key}, ${pushPlugin}: native push comes with notifications(); remove it from mobile.plugins`;
|
|
26
29
|
if (pinnedPackages.has(name)) return `mobile.plugins lists ${key}, which ${name === key ? "comes" : `installs ${name}, which comes`} with Protobase at a fixed version: remove it from mobile.plugins`;
|
|
27
30
|
};
|
|
28
31
|
/**
|
|
@@ -46,4 +49,4 @@ const checkPinnedNative = (dir, pinned = nativeDependencies) => {
|
|
|
46
49
|
}
|
|
47
50
|
};
|
|
48
51
|
//#endregion
|
|
49
|
-
export { checkInstalledPlugins, checkPinnedNative, nativeDependencies, pinnedNative, pinnedPackages, pinnedProblem };
|
|
52
|
+
export { checkInstalledPlugins, checkPinnedNative, nativeDependencies, pinnedNative, pinnedPackages, pinnedProblem, pushPlugin };
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { readFile, writeFile } from "node:fs/promises";
|
|
3
3
|
//#region src/mobile/protobase-plugin.ts
|
|
4
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* The classes of Protobase's native plugin that keep page script away from the session, and ProtobaseExternal, which
|
|
6
|
+
* opens a url outside the app, by Java class name.
|
|
7
|
+
*/
|
|
5
8
|
const protobasePluginClasses = [
|
|
6
9
|
"ProtobaseAuth",
|
|
7
10
|
"RefusedHttp",
|
|
8
11
|
"RefusedCookies",
|
|
9
12
|
"RefusedWebView",
|
|
10
|
-
"LocalServerGuard"
|
|
13
|
+
"LocalServerGuard",
|
|
14
|
+
"ProtobaseExternal"
|
|
11
15
|
].map((name) => `net.protobase.mobile.${name}`);
|
|
12
16
|
const liveUpdatePackage = "@capawesome/capacitor-live-update";
|
|
13
17
|
const stockLiveUpdate = "io.capawesome.capacitorjs.plugins.liveupdate.LiveUpdatePlugin";
|
package/dist/mobile/run.js
CHANGED
|
@@ -10,6 +10,7 @@ import { buildWebPart, placeholderWebPart } from "./web-part.js";
|
|
|
10
10
|
import { capacitorConfig, writeCapacitorConfig } from "./capacitor-config.js";
|
|
11
11
|
import { childEnv, envFileKeys, projectEnvFiles } from "./child-env.js";
|
|
12
12
|
import { deviceAppName } from "./device-app-name.js";
|
|
13
|
+
import { hasGoogleServices, missingGoogleServices } from "./google-services.js";
|
|
13
14
|
import { generatePlatform } from "./generate.js";
|
|
14
15
|
import { liveUpdateSettings } from "./live-update-settings.js";
|
|
15
16
|
import { loadMobileProject } from "./load-project.js";
|
|
@@ -55,7 +56,9 @@ const prepare = async ({ projectDir, platform, api, extensions, live, release },
|
|
|
55
56
|
...build && { build },
|
|
56
57
|
onWarning
|
|
57
58
|
}) : await placeholderWebPart(ws);
|
|
58
|
-
const fingerprint = nativeFingerprint(pinnedNative, mobile.plugins);
|
|
59
|
+
const fingerprint = nativeFingerprint(pinnedNative, mobile.plugins, { push: project.notifications });
|
|
60
|
+
const push = project.notifications && platform === "android" && await hasGoogleServices(projectDir);
|
|
61
|
+
if (project.notifications && platform === "android" && !push) onWarning(missingGoogleServices(projectDir));
|
|
59
62
|
const liveUpdate = liveUpdateSettings({
|
|
60
63
|
...mobile.publicKey && { publicKey: mobile.publicKey },
|
|
61
64
|
...builtInOrder && { builtInOrder },
|
|
@@ -72,14 +75,18 @@ const prepare = async ({ projectDir, platform, api, extensions, live, release },
|
|
|
72
75
|
allowances,
|
|
73
76
|
apiOrigin: url.origin,
|
|
74
77
|
platform,
|
|
75
|
-
...release && { release }
|
|
78
|
+
...release && { release },
|
|
79
|
+
...push && { push }
|
|
76
80
|
};
|
|
77
81
|
await writeCapacitorConfig(ws, capacitorConfig({
|
|
78
82
|
...config,
|
|
79
83
|
...liveUpdate.settings && { liveUpdate: liveUpdate.settings }
|
|
80
84
|
}));
|
|
81
85
|
const cap = capacitorRunner(ws, env, run);
|
|
82
|
-
await generatePlatform(ws, platform,
|
|
86
|
+
await generatePlatform(ws, platform, {
|
|
87
|
+
...allowances,
|
|
88
|
+
...push && { googleServicesFrom: projectDir }
|
|
89
|
+
}, cap);
|
|
83
90
|
if (platform === "android") {
|
|
84
91
|
await guardLiveUpdate(ws);
|
|
85
92
|
await checkProtobasePlugin(ws);
|
package/dist/serve/lifecycle.js
CHANGED
|
@@ -65,7 +65,8 @@ const startServe = async ({ config, env, openDb = (url) => openAppDatabase(pg, u
|
|
|
65
65
|
mobile: project.mobile,
|
|
66
66
|
issuer: project.auth?.issuer,
|
|
67
67
|
signingKey: env.mobileSigningKey,
|
|
68
|
-
serverVersion: protobaseVersion
|
|
68
|
+
serverVersion: protobaseVersion,
|
|
69
|
+
push: Boolean(project.notifications)
|
|
69
70
|
}) : void 0;
|
|
70
71
|
const mobile = project.mobile && {
|
|
71
72
|
...release && { release },
|
|
@@ -18,17 +18,17 @@ const releaseOrigin = (issuer) => {
|
|
|
18
18
|
};
|
|
19
19
|
/**
|
|
20
20
|
* The release of the app's files a server offers its mobile app: every file the site serves, its SPA page naming the
|
|
21
|
-
* API origin as the app's own files do, for binaries of the fingerprint of the site's native packages
|
|
22
|
-
* plugins. Signed, its statement binds it to its order, the app id, that fingerprint and the server's Protobase version.
|
|
21
|
+
* API origin as the app's own files do, for binaries of the fingerprint of the site's native packages, the project's
|
|
22
|
+
* plugins and whether it has native push. Signed, its statement binds it to its order, the app id, that fingerprint and the server's Protobase version.
|
|
23
23
|
* None without a mobile section, without the site's files (the API alone, whose files a host serves), a site that
|
|
24
24
|
* names no native packages (a bundle built before them), an API origin an app calls, or, signed, an order.
|
|
25
25
|
*/
|
|
26
|
-
const servedRelease = async ({ site, mobile, issuer, signingKey, serverVersion }) => {
|
|
26
|
+
const servedRelease = async ({ site, mobile, issuer, signingKey, serverVersion, push = false }) => {
|
|
27
27
|
const origin = releaseOrigin(issuer);
|
|
28
28
|
if (!mobile || !site?.native || !origin) return void 0;
|
|
29
29
|
const order = releaseOrder(site);
|
|
30
30
|
if (signingKey && !order) return void 0;
|
|
31
|
-
const fingerprint = nativeFingerprint(site.native, mobile.plugins);
|
|
31
|
+
const fingerprint = nativeFingerprint(site.native, mobile.plugins, { push });
|
|
32
32
|
const files = await Promise.all((await siteFiles(site)).map(async ({ href, file }) => ({
|
|
33
33
|
href,
|
|
34
34
|
content: href === site.spa ? new TextEncoder().encode(withApiOrigin(await readFile(file, "utf8"), origin)) : new Uint8Array(await readFile(file))
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.75.0",
|
|
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.75.0",
|
|
47
|
+
"@protobase/layout": "0.75.0",
|
|
48
|
+
"@protobase/query": "0.75.0",
|
|
49
|
+
"@protobase/schema": "0.75.0",
|
|
50
|
+
"@protobase/server": "0.75.0",
|
|
51
|
+
"@protobase/ui": "0.75.0",
|
|
52
|
+
"@protobase/workflows": "0.75.0",
|
|
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",
|
|
@@ -11,7 +11,7 @@ A bell in the top bar and push to browsers and phones, for what your app tells i
|
|
|
11
11
|
- [Sending notifications](../reference/notifications.md#sending) (beta): Your code sends a notification to users or to devices as a background job, queued in the same transaction as a write, and says on each one whether it shows in the inbox.
|
|
12
12
|
- [Notification history](../reference/notifications.md#history) (beta): Each user's inbox notifications are kept with when they were read, and the API lists them, counts the unread ones and marks them read.
|
|
13
13
|
- [Web Push](../reference/notifications.md#web-push) (beta): Notifications reach desktop and Android browsers and home-screen web apps on iPhone through Web Push, with keys you generate.
|
|
14
|
-
- [Push on Android](../reference/notifications.md#android) (
|
|
14
|
+
- [Push on Android](../reference/notifications.md#android) (beta): The server sends notifications to Android devices through Firebase Cloud Messaging with the service account key in `PROTOBASE_FCM_SERVICE_ACCOUNT`, and the mobile app receives them, set up by `protobase mobile` from a `google-services.json` in the project.
|
|
15
15
|
- Push on iOS (coming soon): Notifications reach the iOS build of the app on a user's iPhones and iPads.
|
|
16
16
|
- [Do not disturb](../reference/status.md#do-not-disturb) (beta): While someone is on do not disturb, sends push nothing to their devices and keep inbox notifications in the bell for later.
|
|
17
17
|
- [Notification bell](../reference/notifications.md#the-bell) (beta): The top bar shows how many inbox notifications are unread; its panel opens each one, marks them read and turns push on or off for this device.
|
|
@@ -21,7 +21,7 @@ Graphs of steps the server runs along their edges, written in a language a model
|
|
|
21
21
|
- [Who may run workflows](../reference/workflows.md#who-may-do-what) (beta): Making, changing and running workflows and reading their runs are each granted by name, within the tenant.
|
|
22
22
|
- [Workflows over MCP](../reference/mcp.md#workflows) (beta): AI clients find, write, validate, change by a small edit and test-run workflows as the signed-in person, and read each step of a run to fix the one that failed and re-run it from there.
|
|
23
23
|
- [Record triggers](../reference/workflows.md#apprecord) (beta): A workflow starts once for each record that becomes ready, at once or when a time in it comes, read as the user who saved the enabled version.
|
|
24
|
-
- [Triggers turned on while the app runs](../reference/workflows.md#turning-a-trigger-on) (beta):
|
|
24
|
+
- [Triggers turned on while the app runs](../reference/workflows.md#turning-a-trigger-on) (beta): Publishing a saved version registers its trigger on every server process, and turning the workflow off stops it, with no restart; a save goes live only once it is published.
|
|
25
25
|
- [Workflow plugins](../reference/workflow-plugins.md) (beta): A file of the app or a package adds trigger and step types through the same public interface the built-in types use.
|
|
26
26
|
- [Step cache](../reference/workflow-plugins.md#caching-results) (beta): A plugin's step reuses the result of an identical earlier call from any run or workflow, as its plugin decides, while secrets always come in with their current value; a workflow can force it on, and the graph marks a step forced on against its plugin's advice.
|
|
27
27
|
- [Guarded requests for plugins](../reference/workflow-plugins.md#sending-requests) (beta): A plugin's requests reach only public addresses, follow no redirect and read at most 10 MiB.
|
|
@@ -148,7 +148,19 @@ Build the binary again. Each deploy of the app then reaches it: it downloads the
|
|
|
148
148
|
You submit the app under your own developer account, on both stores: Apple rejects apps from a template or app generation service unless the provider of the app's content submits them ([App Review Guidelines](https://developer.apple.com/app-store/review/guidelines/) 4.2.6).
|
|
149
149
|
|
|
150
150
|
- **What may change without a store release:** the app's files, which a later Protobase release can update over the air: the shell, UI plugins, theme, in-app logo and copy, and fixes and features within the app's purpose. Apple allows downloaded interpreted code that does not change the app's primary purpose ([Apple Developer Program License Agreement](https://developer.apple.com/support/terms/apple-developer-program-license-agreement/) 3.3.1(B)), and Google Play allows JavaScript in a WebView ([Device and Network Abuse](https://support.google.com/googleplay/android-developer/answer/9888379)).
|
|
151
|
-
- **What needs a store release:** native code, Capacitor or plugin changes (`mobile.plugins`), permissions, the app's name, its home-screen icon and its splash screen.
|
|
151
|
+
- **What needs a store release:** native code, Capacitor or plugin changes (`mobile.plugins`), turning [push](#9-push-notifications) on or off, permissions, the app's name, its home-screen icon and its splash screen.
|
|
152
152
|
- **Big new features** still go through Apple's review with a store release, even when they could ship over the air: Apple asks that an app's features be documented and reviewed, none hidden (App Review Guidelines 2.3.1 and 2.5.19).
|
|
153
153
|
- **Account deletion is built in:** Apple requires an app that lets people create an account to let them delete it in the app too (App Review Guidelines 5.1.1(v)). The account page's [Delete account](../reference/auth.md#deleting-the-account) does that, on by default; keep `auth.accountDeletion` on for an app you submit.
|
|
154
154
|
- **A plain WebView of an admin app risks rejection:** Apple expects an app to be more than a repackaged website (4.2). Native touches help, such as push notifications, sharing, the camera or biometric sign-in, through `mobile.plugins`.
|
|
155
|
+
|
|
156
|
+
## 9. Push notifications
|
|
157
|
+
|
|
158
|
+
With [`notifications()`](../reference/notifications.md) on, `protobase mobile` sets push up in the app itself: there is no push setting in the mobile section. Push on iOS is coming soon.
|
|
159
|
+
|
|
160
|
+
### Android
|
|
161
|
+
|
|
162
|
+
Put your Firebase project's `google-services.json` in the project folder, next to `protobase.config.ts`. You download it from the Firebase console (Project settings, Your apps, an Android app whose package name is the mobile section's `appId`). Every `protobase mobile` run and build copies it into the Android app. Without it, the Android app builds without push and every run says so, naming the path. The server sends through FCM once you set [`PROTOBASE_FCM_SERVICE_ACCOUNT`](../reference/notifications.md#android).
|
|
163
|
+
|
|
164
|
+
The user turns push on from the bell, or from your own button with [`usePushNotifications`](../reference/notifications.md#in-the-browser). Android 13 and later ask for the permission then. Signing out removes the phone's registration.
|
|
165
|
+
|
|
166
|
+
A tap on a notification whose `url` is on your app's server opens that page inside the app. Any other `http` or `https` url opens in the phone's browser, never inside the app, and any other url opens nothing. Turning push on or off changes the app's native code, so it ships in a store release, not a [live update](#7-live-updates).
|
|
@@ -99,7 +99,7 @@ Access is resolved once per request and resource ([`resolveAccess`](https://docs
|
|
|
99
99
|
- **Record-level rules** (a rule that needs the record, such as `status != 'locked'`) run in the write transaction with the stored record; a filter they return is checked in the database against the row as written, and a miss rolls the write back with `403`.
|
|
100
100
|
- **`.own` on create**: when the create rule is limited to rows, the owner field is set to the caller unless given, and a row owned by someone else is refused with `403`.
|
|
101
101
|
- **Seeking**: `:seek` resolves a row position to a page on the server, inside the caller's tenant, row filter and filter. No anchor value, column statistic or boundary token is ever returned (table-wide statistics include rows the caller may not see), only the page and the tokens of its own rows.
|
|
102
|
-
- **ETags**: with a read-only `version` or `updated_at` column the ETag is a hash of that column's exact text, so it never shows a hidden value yet moves on every change. Without one it is a hash of the fields the caller may read, sensitive ones excluded: a change to a field they cannot read, or to a sensitive field, does not change their ETag.
|
|
102
|
+
- **ETags**: with a read-only `version` or `updated_at` column the ETag is a hash of that column's exact text, so it never shows a hidden value yet moves on every change; `.etagFrom((r) => r.updated_at)` on a resource names the column, for a `version` that counts something else. Without one it is a hash of the fields the caller may read, sensitive ones excluded: a change to a field they cannot read, or to a sensitive field, does not change their ETag.
|
|
103
103
|
- **Errors** never contain values of fields the caller cannot read; database errors leave out constraint and column names.
|
|
104
104
|
|
|
105
105
|
The roles (the `roles` export of `config/roles.ts`, from `defineRoles`) make an operation without an explicit rule need the matching capability (`orders.update`), and limits each role to the [fields and rows](access.md#capabilities) its capabilities list; `defaultAccess: 'allow' | 'deny'` in the config overrides the capability check. Without either, operations without a rule are allowed (single-admin projects).
|
|
@@ -112,8 +112,8 @@ In an app with [workflows](workflows.md), the endpoint also offers tools to find
|
|
|
112
112
|
| `list_connections` | The person's own [connected accounts](workflows.md#connecting-an-account), by each connection the app's plugins declare: its key and label, and each account's `id`, scopes and `needs_sign_in`. A definition's `connections` binds an account by its `id`. It returns no token, and no one else's accounts. |
|
|
113
113
|
| `create_workflow` | Creates a workflow from its `name`, `description` and `definition`, and returns its `id`, `version` and ETag. |
|
|
114
114
|
| `update_workflow` | Changes a workflow's definition by an `edit` or whole, as `definition`, and its `name` or `description`, and returns its `id`, new `version` and ETag. With the `etag` that `get_workflow` gave, it fails when someone changed the workflow since; an edit without one is saved against the version it was applied to. |
|
|
115
|
-
| `run_workflow` | Starts a run of a workflow's
|
|
116
|
-
| `enable_workflow` |
|
|
115
|
+
| `run_workflow` | Starts a run of a workflow's version saved last, or of the `version` it names, with an `input`, and returns its `run_id` and `status`. With `rerun_of`, a failed run's id, it [re-runs](workflows.md#re-running-a-failed-run) that run from its failed step instead, on its input; with `replay: true` too, it [replays](workflows.md#replaying-a-run) any ended run of the workflow on its current version, with that run's input, sending none of its outside writes. |
|
|
116
|
+
| `enable_workflow` | Publishes the saved `version` it names (`enabled: true`), which puts the workflow's trigger on it, or turns the workflow off, and returns its `enabled_version`. A save never goes live by itself. One that uses a [connected account](workflows.md#connecting-an-account) is turned on only by the account's owner in the admin app: the tool answers `own-sign-in-only` and says so. |
|
|
117
117
|
| `new_webhook_url` | Issues a new URL and secret for a workflow that starts from a [webhook trigger](workflows.md#appwebhook), keeping a `secret` the sender makes when given one, and returns `{ url, secret }`, shown this once; the old URL stops. |
|
|
118
118
|
|
|
119
119
|
An `edit` is a [JSON Merge Patch](https://www.rfc-editor.org/rfc/rfc7396) of the saved definition: only what changes, at its place in the document. An object merges into the object there, `null` removes a member, and any other value, a list included, replaces it. Changing one argument of one state:
|
|
@@ -7,7 +7,7 @@ Turn on notifications, send them to users or devices, show each signed-in user t
|
|
|
7
7
|
## Turning them on
|
|
8
8
|
|
|
9
9
|
:::caution[Beta]
|
|
10
|
-
Push reaches browsers; push on
|
|
10
|
+
Push reaches browsers and the Android app; push on iOS is coming soon.
|
|
11
11
|
:::
|
|
12
12
|
|
|
13
13
|
Notifications tell a user about something in the app, in a bell in the top bar and as push on their devices. [Send notifications](../guides/push-notifications.md) walks through turning them on and sending the first one. You turn them on in `protobase.config.ts`:
|
|
@@ -22,12 +22,12 @@ export default defineConfig({
|
|
|
22
22
|
|
|
23
23
|
Then run `protobase migration`, which writes the [devices and history tables](#table-names), and the jobs schema that [sending](#sending) runs on, as a migration of the project's own, and apply it with the project's migrations. `protobase dev` and `protobase serve` refuse to start while a table is missing or lacks what notifications need, and name it. Without `notifications` there is none of it: no endpoints, no tables and no migration.
|
|
24
24
|
|
|
25
|
-
Every signed-in user gets [the bell](#the-bell),
|
|
25
|
+
Every signed-in user gets [the bell](#the-bell), browsers receive push through [Web Push](#web-push), and the Android app through [FCM](#android); push on iOS is coming soon. `notifications: { ui: false }` keeps only the backend, [without the bell](#without-the-bell).
|
|
26
26
|
|
|
27
27
|
## Devices
|
|
28
28
|
|
|
29
29
|
:::caution[Beta]
|
|
30
|
-
|
|
30
|
+
Browsers receive push through [Web Push](#web-push), and the Android app through [FCM](#android): push on iOS is coming soon.
|
|
31
31
|
:::
|
|
32
32
|
|
|
33
33
|
A device is where a user receives push: a browser's push subscription, or an Android or iOS app's push token. Each signed-in user registers and removes only their own, through the API:
|
|
@@ -67,7 +67,7 @@ The path comes from `devicesPath('/api', id)`, and the name of its id parameter
|
|
|
67
67
|
## Sending
|
|
68
68
|
|
|
69
69
|
:::caution[Beta]
|
|
70
|
-
Browsers
|
|
70
|
+
Browsers and the Android app receive push; push on iOS is coming soon. <gap>A send can reach a device twice, or keep an entry twice in a history store of your own, when a worker stops mid-send because saving the send's progress in the same step as the push is not implemented.</gap>
|
|
71
71
|
:::
|
|
72
72
|
|
|
73
73
|
[Send notifications](../guides/push-notifications.md) sends one from a record change, step by step. You send a notification from your server code, such as a job, a hook, an event subscription or an API function, with `sendNotification(db, to, message)` from `@protobase/server`. It is queued as a background job in `db`'s transaction when `db` is one, so it goes out only once your write commits, and nothing goes out when the transaction rolls back. A running job also has it as `sendNotification` in its context, beside `mail`, when the app has `notifications`.
|
|
@@ -189,7 +189,7 @@ Each message is encrypted for its browser and signed with the key. It goes only
|
|
|
189
189
|
|
|
190
190
|
### In the browser
|
|
191
191
|
|
|
192
|
-
`usePushNotifications()` from `@protobase/ui` turns push on and off for the signed-in user in this browser, for your own button or menu item. Its `state` tells whether push is `on`, `off`, `blocked` because the user refused notifications in the browser's settings, or `unsupported`, and `loading` until it knows. Hide the button while it is `unsupported`: the browser has no Web Push, the app has no VAPID keys, or it runs in the
|
|
192
|
+
`usePushNotifications()` from `@protobase/ui` turns push on and off for the signed-in user in this browser, or in the Android app, for your own button or menu item. Its `state` tells whether push is `on`, `off`, `blocked` because the user refused notifications in the browser's or the phone's settings, or `unsupported`, and `loading` until it knows. Hide the button while it is `unsupported`: the browser has no Web Push, the app has no VAPID keys, the Android app was built without `google-services.json`, or it runs in the iOS app.
|
|
193
193
|
|
|
194
194
|
```tsx
|
|
195
195
|
import { Button, usePushNotifications } from '@protobase/ui'
|
|
@@ -213,17 +213,17 @@ export const PushButton = () => {
|
|
|
213
213
|
|
|
214
214
|
## Android
|
|
215
215
|
|
|
216
|
-
:::caution[
|
|
217
|
-
|
|
216
|
+
:::caution[Beta]
|
|
217
|
+
Push on Android is new.
|
|
218
218
|
:::
|
|
219
219
|
|
|
220
|
-
Android devices receive push through Firebase Cloud Messaging's HTTP v1 API. You create a service account key in your Firebase project (Project settings, Service accounts, Generate new private key) and set its JSON as `PROTOBASE_FCM_SERVICE_ACCOUNT`. Without it, Android devices are skipped.
|
|
220
|
+
Android devices receive push through Firebase Cloud Messaging's HTTP v1 API. You create a service account key in your Firebase project (Project settings, Service accounts, Generate new private key) and set its JSON as `PROTOBASE_FCM_SERVICE_ACCOUNT`. Without it, Android devices are skipped. `protobase mobile` sets the app up from your `google-services.json`: see [Push notifications in the mobile app guide](../guides/mobile-app.md#9-push-notifications).
|
|
221
221
|
|
|
222
222
|
JSON that is not a service account key, a `project_id` that is not a Google project id, or a `private_key` that is not an RSA key of at least 2048 bits stops startup, naming the variable without its value. The key is a secret: keep it out of client code, `VITE_` variables and the repository. Anyone holding it can push to every Android device of the project.
|
|
223
223
|
|
|
224
224
|
The server signs in as the service account with a token scoped to sending through FCM only, and keeps one token until five minutes before it expires. When no token can be had before the first request, the send fails with nothing pushed and is retried; a token that fails later retries only the devices still waiting for one. Requests go only to Google's token endpoint and to FCM, for the key's own project, never through a redirect; the URLs in the key's JSON are not read. A device is removed only when FCM reports its token unregistered. Any other refusal, such as a key without access to the project, keeps the device and retries it. A device stored with a token that is not an FCM token is `refused`.
|
|
225
225
|
|
|
226
|
-
A message's title and body are the notification. Its `data` and `url` reach the app as FCM's data, each value a string (other JSON as its text), with `user`, the id of the user the device is registered for, over any `user` given. Its `ttl`, `urgency`, `tag`, `sound` and `badge` set the Android delivery and notification. A message's `platform.fcm` is merged over these, and may set only:
|
|
226
|
+
A message's title and body are the notification. Its `data` and `url` reach the app as FCM's data, the url under `url`, which the app opens on tap; a message whose `data` holds a `url` of its own is refused, each value a string (other JSON as its text), with `user`, the id of the user the device is registered for, over any `user` given. Its `ttl`, `urgency`, `tag`, `sound` and `badge` set the Android delivery and notification. A message's `platform.fcm` is merged over these, and may set only:
|
|
227
227
|
|
|
228
228
|
| Field | |
|
|
229
229
|
| --- | --- |
|
|
@@ -24,7 +24,7 @@ It adds five resources, over a `workflows` schema that [`protobase migration`](c
|
|
|
24
24
|
| --- | --- |
|
|
25
25
|
| `workflows` | A name, a description and the definition. Each save that changes the definition is checked, and kept as the workflow's next version, saved by the caller. |
|
|
26
26
|
| `workflow_versions` | Every version of every definition as it was saved, with who saved it and when. Read-only. |
|
|
27
|
-
| `workflow_runs` | A run, started by creating it with `workflow_id` and an `input`, or with `rerun_of` to [re-run a failed run](#re-running-a-failed-run), and `replay: true` too to [replay a run](#replaying-a-run); it runs the version its workflow had then, and a re-run or a replay the input of the run it names. Its status, output, error and timing are written by the runner. |
|
|
27
|
+
| `workflow_runs` | A run, started by creating it with `workflow_id` and an `input`, and a saved `version` to run another than the published one, or on a workflow that is off the one saved last, or with `rerun_of` to [re-run a failed run](#re-running-a-failed-run), and `replay: true` too to [replay a run](#replaying-a-run); it runs the version its workflow had then, and a re-run or a replay the input of the run it names. Its status, output, error and timing are written by the runner. |
|
|
28
28
|
| `workflow_steps` | Every step of every run. Read-only. |
|
|
29
29
|
| `workflow_triggers` | The trigger of each enabled workflow that has one besides `manual`: its type, status and last error. Read-only. |
|
|
30
30
|
|
|
@@ -35,7 +35,7 @@ It adds five resources, over a `workflows` schema that [`protobase migration`](c
|
|
|
35
35
|
| `allowPrivateAddresses` | Lets the `app:http` step, and every plugin's `fetch`, reach private, loopback and link-local addresses, for development and tests. Default false. |
|
|
36
36
|
| `plugins` | Packages of [workflow plugins](workflow-plugins.md) to run, by name, beside the app's own in `workflows/plugins/<name>.ts`. |
|
|
37
37
|
|
|
38
|
-
Records steps act as
|
|
38
|
+
Records steps act as the user who saved the run's version, with the roles the project's sign-in gives them now. A project that signs people in otherwise exports its own, `async ({ id, tenant }) => [...]`, as the default of `workflows/saved-by-roles.ts` (`createAdmin` takes it as `workflows.savedByRoles`); without either, startup stops.
|
|
39
39
|
|
|
40
40
|
## The document
|
|
41
41
|
|
|
@@ -98,7 +98,7 @@ A save checks a trigger's input against its type, and refuses a type the app doe
|
|
|
98
98
|
|
|
99
99
|
### Turning a trigger on
|
|
100
100
|
|
|
101
|
-
A trigger starts runs only while its workflow is
|
|
101
|
+
A trigger starts runs only while its workflow is published: set `enabled_version` to any saved version through the API, in the admin app or with `enable_workflow` over MCP, and clear it to turn the workflow off. The trigger is registered at once on every server process, with no restart, and its status, `active` or `failing` with its last error, is the workflow's `workflow_triggers` record. A save makes a new version and changes nothing that is live, so a change can be run and tested first; publishing it moves `enabled_version`, and publishing an older version goes back to it. A published version whose trigger has the same type and input as the one before keeps the running trigger as it is, and any other change stops it and starts the new one. Runs in progress stay on their version. A trigger's runs run the enabled version and act as the user who saved it, as any run acts as its version's saver.
|
|
102
102
|
|
|
103
103
|
### app:record
|
|
104
104
|
|
|
@@ -353,7 +353,7 @@ A replay given an `input` of its own is refused with `rerun-input`, and one with
|
|
|
353
353
|
|
|
354
354
|
### Test runs
|
|
355
355
|
|
|
356
|
-
A workflow's page offers *Test run*: the form for a new run of the workflow, whose `input` takes a sample input as JSON, which every state reads as `$states.context.Execution.Input`. Creating it opens the workflow's page with the run on the graph, followed as it runs. A test run is a run like any other: its steps do what they do, as
|
|
356
|
+
A workflow's page offers *Test run*: the form for a new run of the workflow, whose `input` takes a sample input as JSON, which every state reads as `$states.context.Execution.Input`. Creating it opens the workflow's page with the run on the graph, followed as it runs. A test run is a run like any other, of the version saved last, which need not be published: its steps do what they do, acting as that version's saver.
|
|
357
357
|
|
|
358
358
|
## Over MCP
|
|
359
359
|
|