@protobase/cli 0.74.0 → 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/guides/mobile-app.md +13 -1
- package/skills/protobase/references/reference/notifications.md +9 -9
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.
|
|
@@ -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).
|
|
@@ -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
|
| --- | --- |
|