@protobase/cli 0.57.3 → 0.57.4
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 +13 -4
- package/dist/mobile/live-update-settings.js +31 -0
- package/dist/mobile/mobile-config.js +10 -3
- package/dist/mobile/package.js +1 -1
- package/dist/mobile/pinned-packages.js +1 -1
- package/dist/mobile/print-signing-keys.js +26 -0
- package/dist/mobile/public-key.js +31 -0
- package/dist/mobile/register.js +1 -0
- package/dist/mobile/run.js +16 -4
- package/dist/mobile/web-part.js +8 -3
- package/dist/serve/mobile-release.js +2 -12
- package/package.json +7 -7
- package/skills/protobase/references/features/build-and-run.md +1 -0
- package/skills/protobase/references/guides/mobile-app.md +22 -1
- package/skills/protobase/references/reference/cli.md +14 -2
- package/skills/protobase/references/reference/config/app.md +2 -1
- package/skills/protobase/references/reference/versioning.md +2 -2
package/dist/cli/package.js
CHANGED
|
@@ -5,24 +5,28 @@ import { capacitorOrigin } from "@protobase/schema/internal";
|
|
|
5
5
|
const protobasePlugin = "@protobase/mobile";
|
|
6
6
|
const keyboardPlugin = "@capacitor/keyboard";
|
|
7
7
|
const liveUpdatePlugin = "@capawesome/capacitor-live-update";
|
|
8
|
+
const readyTimeout = 3e4;
|
|
8
9
|
/**
|
|
9
10
|
* The app's `capacitor.config.json`, every key it sets named here. It never sets `server.url`, the hostname or the
|
|
10
11
|
* schemes (the API's CORS list names Capacitor's default origins), or WebView debugging (on in debug builds only).
|
|
11
|
-
* `plugins` configures ProtobaseAuth, the keyboard plugin and, with the live updater,
|
|
12
|
-
*
|
|
12
|
+
* `plugins` configures ProtobaseAuth, the keyboard plugin and, with the live updater, what its guard needs: the key
|
|
13
|
+
* releases are signed with, where they come from, the binary's fingerprint, shell version and the order of its own
|
|
14
|
+
* files, background updates off, a rolled-back bundle blocked and `readyTimeout`, within which the shell must call
|
|
15
|
+
* ready() or the app goes back to its own files. CapacitorHttp and CapacitorCookies stay off; the keyboard plugin
|
|
13
16
|
* resizes natively, its default, and fills the space beside the keyboard's rounded corners with the page's background
|
|
14
17
|
* instead of black. Protobase's plugin is compiled in last, so its stand-ins replace any plugin of the same name.
|
|
15
18
|
* Service workers get nothing from the local server on Android, which they would reach past the WebViewClient that
|
|
16
19
|
* guards it. The file ships outside the app's web part, so the fingerprint in the user agent and ProtobaseAuth's
|
|
17
20
|
* origins are beyond page script and a live update.
|
|
18
21
|
*/
|
|
19
|
-
const capacitorConfig = ({ appId, appName, fingerprint, shellVersion, plugins, allowances, apiOrigin, platform }) => ({
|
|
22
|
+
const capacitorConfig = ({ appId, appName, fingerprint, shellVersion, plugins, liveUpdate, allowances, apiOrigin, platform }) => ({
|
|
20
23
|
appId,
|
|
21
24
|
appName,
|
|
22
25
|
webDir: "web",
|
|
23
26
|
appendUserAgent: `ProtobaseNative/${fingerprint}`,
|
|
24
27
|
includePlugins: [
|
|
25
28
|
...plugins,
|
|
29
|
+
...liveUpdate ? [liveUpdatePlugin] : [],
|
|
26
30
|
keyboardPlugin,
|
|
27
31
|
protobasePlugin
|
|
28
32
|
],
|
|
@@ -32,7 +36,12 @@ const capacitorConfig = ({ appId, appName, fingerprint, shellVersion, plugins, a
|
|
|
32
36
|
origin: capacitorOrigin[platform]
|
|
33
37
|
},
|
|
34
38
|
Keyboard: { autoBackdropColor: "dom" },
|
|
35
|
-
...
|
|
39
|
+
...liveUpdate && { LiveUpdate: {
|
|
40
|
+
...liveUpdate,
|
|
41
|
+
readyTimeout,
|
|
42
|
+
autoUpdateStrategy: "none",
|
|
43
|
+
autoDeleteBundles: true,
|
|
44
|
+
autoBlockRolledBackBundles: true,
|
|
36
45
|
fingerprint,
|
|
37
46
|
shellVersion
|
|
38
47
|
} }
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { updaterPublicKey } from "./public-key.js";
|
|
2
|
+
import { mobileReleasesPath } from "@protobase/schema/internal";
|
|
3
|
+
import { formatReleaseOrder } from "@protobase/server/mobile-release";
|
|
4
|
+
//#region src/mobile/live-update-settings.ts
|
|
5
|
+
const loopback = [
|
|
6
|
+
"localhost",
|
|
7
|
+
"127.0.0.1",
|
|
8
|
+
"[::1]"
|
|
9
|
+
];
|
|
10
|
+
const ownOrigin = (origin) => {
|
|
11
|
+
const url = new URL(origin);
|
|
12
|
+
return url.protocol === "https:" || url.protocol === "http:" && loopback.includes(url.hostname);
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Whether the app gets the live updater: on Android only, with `mobile.publicKey`, the order of its own files and an
|
|
16
|
+
* API origin it may take releases from, never with `--live`. `note` says why not, when the project could change it.
|
|
17
|
+
*/
|
|
18
|
+
const liveUpdateSettings = ({ platform, publicKey, builtInOrder, apiOrigin, live }) => {
|
|
19
|
+
if (live) return {};
|
|
20
|
+
if (platform !== "android") return publicKey === void 0 ? {} : { note: "the iOS app does not update itself yet: its live updater is Android only" };
|
|
21
|
+
if (publicKey === void 0) return { note: "the app does not update itself: set mobile.publicKey to the public key protobase mobile keys prints" };
|
|
22
|
+
if (!builtInOrder) return { note: "the app does not update itself: its files name no build time, so it could not refuse a release older than them" };
|
|
23
|
+
if (!ownOrigin(apiOrigin)) return { note: `the app does not update itself: it takes releases over https only, or http to this device, not from ${apiOrigin}` };
|
|
24
|
+
return { settings: {
|
|
25
|
+
publicKey: updaterPublicKey(publicKey),
|
|
26
|
+
builtInOrder: formatReleaseOrder(builtInOrder),
|
|
27
|
+
releasesUrl: `${apiOrigin}${mobileReleasesPath}`
|
|
28
|
+
} };
|
|
29
|
+
};
|
|
30
|
+
//#endregion
|
|
31
|
+
export { liveUpdateSettings };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { appIdProblem, isAppId } from "./app-id.js";
|
|
2
2
|
import { packageNameProblem } from "./package-name.js";
|
|
3
3
|
import { pinnedProblem } from "./pinned-packages.js";
|
|
4
|
+
import { updaterPublicKey } from "./public-key.js";
|
|
4
5
|
//#region src/mobile/mobile-config.ts
|
|
5
6
|
const noMobileSection = "This project has no mobile section: add `mobile: { appId: 'com.example.app' }` to the default export of protobase.config.ts";
|
|
6
7
|
const unauthenticated = /^(?:http:|git:|git\+http:)/i;
|
|
@@ -9,9 +10,14 @@ const isRecord = (value) => typeof value === "object" && value !== null && !Arra
|
|
|
9
10
|
const checkMobileConfig = (value) => {
|
|
10
11
|
if (value === void 0) throw new Error(noMobileSection);
|
|
11
12
|
if (!isRecord(value)) throw new Error("mobile in protobase.config.ts must be an object such as { appId: 'com.example.app' }");
|
|
12
|
-
const { appId, plugins } = value;
|
|
13
|
+
const { appId, plugins, publicKey } = value;
|
|
13
14
|
if (!isAppId(appId)) throw new Error(appIdProblem(appId));
|
|
14
|
-
if (
|
|
15
|
+
if (publicKey !== void 0) updaterPublicKey(publicKey);
|
|
16
|
+
const key = publicKey === void 0 ? {} : { publicKey };
|
|
17
|
+
if (plugins === void 0) return {
|
|
18
|
+
appId,
|
|
19
|
+
...key
|
|
20
|
+
};
|
|
15
21
|
if (!isRecord(plugins) || Object.values(plugins).some((spec) => typeof spec !== "string")) throw new Error("mobile.plugins must map each plugin's npm name to a version range, such as { '@capacitor/camera': '^8.0.0' }");
|
|
16
22
|
for (const [name, spec] of Object.entries(plugins)) {
|
|
17
23
|
const problem = packageNameProblem(name) ?? pinnedProblem(name);
|
|
@@ -20,7 +26,8 @@ const checkMobileConfig = (value) => {
|
|
|
20
26
|
}
|
|
21
27
|
return {
|
|
22
28
|
appId,
|
|
23
|
-
plugins
|
|
29
|
+
plugins,
|
|
30
|
+
...key
|
|
24
31
|
};
|
|
25
32
|
};
|
|
26
33
|
//#endregion
|
package/dist/mobile/package.js
CHANGED
|
@@ -22,7 +22,7 @@ const pinnedNative = {
|
|
|
22
22
|
const liveUpdate = "@capawesome/capacitor-live-update";
|
|
23
23
|
/** Why the plugin `key`, a package that is or names `name`, may not be listed; `undefined` when it may. */
|
|
24
24
|
const pinnedProblem = (key, name = key) => {
|
|
25
|
-
if (name === liveUpdate) return `mobile.plugins lists ${key}, ${liveUpdate}: live updates come with Protobase's updater, which
|
|
25
|
+
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`;
|
|
26
26
|
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
27
|
};
|
|
28
28
|
/**
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { generateKeyPairSync } from "node:crypto";
|
|
2
|
+
import { mobileSigningKeyVariable } from "@protobase/server/mobile-release";
|
|
3
|
+
//#region src/mobile/print-signing-keys.ts
|
|
4
|
+
/**
|
|
5
|
+
* Prints a fresh RSA key pair for the live updater: the signing key as `PROTOBASE_MOBILE_SIGNING_KEY`, one line with
|
|
6
|
+
* its newlines written `\n` as an env file holds it, and the public key for `mobile.publicKey`, and on `note` where
|
|
7
|
+
* each goes. It reads no project, writes no file and makes no request.
|
|
8
|
+
*/
|
|
9
|
+
const printSigningKeys = (out, note) => {
|
|
10
|
+
const { publicKey, privateKey } = generateKeyPairSync("rsa", {
|
|
11
|
+
modulusLength: 3072,
|
|
12
|
+
publicKeyEncoding: {
|
|
13
|
+
format: "pem",
|
|
14
|
+
type: "spki"
|
|
15
|
+
},
|
|
16
|
+
privateKeyEncoding: {
|
|
17
|
+
format: "pem",
|
|
18
|
+
type: "pkcs8"
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
out(`${mobileSigningKeyVariable}=${privateKey.trim().replace(/\n/g, "\\n")}\n\n${publicKey}`);
|
|
22
|
+
note(`Set ${mobileSigningKeyVariable} on the server, a secret never committed, and the public key as mobile.publicKey in protobase.config.ts. A store release pins the public key: changing it needs a new one.
|
|
23
|
+
`);
|
|
24
|
+
};
|
|
25
|
+
//#endregion
|
|
26
|
+
export { printSigningKeys };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { createPublicKey } from "node:crypto";
|
|
2
|
+
//#region src/mobile/public-key.ts
|
|
3
|
+
const minimumBits = 2048;
|
|
4
|
+
const publicPem = /^-----BEGIN PUBLIC KEY-----\s+[A-Za-z0-9+/=\s]+-----END PUBLIC KEY-----$/;
|
|
5
|
+
const parse = (pem) => {
|
|
6
|
+
try {
|
|
7
|
+
return createPublicKey(pem);
|
|
8
|
+
} catch (error) {
|
|
9
|
+
if (error instanceof Error && String(error.code).startsWith("ERR_OSSL_")) return;
|
|
10
|
+
throw error;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* The live updater's key from `mobile.publicKey`, as the Android guard reads it: base64 SPKI DER. A PEM RSA public key
|
|
15
|
+
* of at least 2048 bits; anything else is an error naming what to set.
|
|
16
|
+
*/
|
|
17
|
+
const updaterPublicKey = (value) => {
|
|
18
|
+
const fix = "set mobile.publicKey to the public key protobase mobile keys prints";
|
|
19
|
+
if (typeof value !== "string" || !publicPem.test(value.trim())) throw new Error(`mobile.publicKey must be a PEM public key, from -----BEGIN PUBLIC KEY----- to its END line: ${fix}`);
|
|
20
|
+
const key = parse(value.trim());
|
|
21
|
+
if (!key) throw new Error(`mobile.publicKey is no public key: ${fix}`);
|
|
22
|
+
if (key.asymmetricKeyType !== "rsa") throw new Error(`mobile.publicKey must be an RSA key, not ${key.asymmetricKeyType ?? "another kind"}: ${fix}`);
|
|
23
|
+
const bits = key.asymmetricKeyDetails?.modulusLength ?? 0;
|
|
24
|
+
if (bits < minimumBits) throw new Error(`mobile.publicKey must be an RSA key of at least ${minimumBits} bits, not ${bits}: ${fix}`);
|
|
25
|
+
return key.export({
|
|
26
|
+
format: "der",
|
|
27
|
+
type: "spki"
|
|
28
|
+
}).toString("base64");
|
|
29
|
+
};
|
|
30
|
+
//#endregion
|
|
31
|
+
export { updaterPublicKey };
|
package/dist/mobile/register.js
CHANGED
|
@@ -29,6 +29,7 @@ const registerMobile = (program) => {
|
|
|
29
29
|
...opts.api !== void 0 && { api: opts.api }
|
|
30
30
|
}, out);
|
|
31
31
|
});
|
|
32
|
+
mobile.command("keys").description("Print a fresh key pair for live updates: PROTOBASE_MOBILE_SIGNING_KEY for the server, and the public key for mobile.publicKey").action(async () => (await import("./print-signing-keys.js")).printSigningKeys(out, (text) => void process.stderr.write(text)));
|
|
32
33
|
mobile.command("build").description("Generate the native project and build a signed release: an .aab for Google Play, an .ipa for the App Store").argument("<platform>", "ios or android", parsePlatform).requiredOption("--app-version <version>", "the version the stores show, such as 1.2.3", parseAppVersion).requiredOption("--build-number <number>", "the build number, higher with each upload", parseBuildNumber).option(api, `${apiHelp}; https only`).option("--out <dir>", "the folder the binary goes to", "mobile-release").option("--team <id>", "iOS: your Apple Developer team id", parseTeamId).option("--certificate <name>", "iOS, manual signing: the signing certificate", parseSigningName).option("--profile <name>", "iOS, manual signing: the provisioning profile", parseSigningName).option("--extend <dir>", extend, collect, []).action(async (chosen, opts) => {
|
|
33
34
|
if (chosen === "android" && (opts.team || opts.certificate || opts.profile)) throw new Error("--team, --certificate and --profile are for iOS: Android signs with the PROTOBASE_ANDROID_* variables");
|
|
34
35
|
if (Boolean(opts.certificate) !== Boolean(opts.profile)) throw new Error("Manual signing takes both --certificate and --profile");
|
package/dist/mobile/run.js
CHANGED
|
@@ -11,6 +11,7 @@ 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
13
|
import { generatePlatform } from "./generate.js";
|
|
14
|
+
import { liveUpdateSettings } from "./live-update-settings.js";
|
|
14
15
|
import { loadMobileProject } from "./load-project.js";
|
|
15
16
|
import { signForDevelopment } from "./development-signing.js";
|
|
16
17
|
import { checkIosPlugins, checkProtobasePlugin, guardIosLiveUpdate, guardLiveUpdate } from "./protobase-plugin.js";
|
|
@@ -46,17 +47,24 @@ const prepare = async ({ projectDir, platform, api, extensions, live, release },
|
|
|
46
47
|
}));
|
|
47
48
|
checkInstalledPlugins(ws, plugins);
|
|
48
49
|
checkPinnedNative(ws);
|
|
49
|
-
|
|
50
|
+
const { builtInOrder } = live === void 0 ? await buildWebPart({
|
|
50
51
|
projectDir,
|
|
51
52
|
ws,
|
|
52
53
|
extensions,
|
|
53
54
|
apiOrigin: url.origin,
|
|
54
55
|
...build && { build },
|
|
55
56
|
onWarning
|
|
56
|
-
});
|
|
57
|
-
else await placeholderWebPart(ws);
|
|
57
|
+
}) : await placeholderWebPart(ws);
|
|
58
58
|
const fingerprint = nativeFingerprint(pinnedNative, mobile.plugins);
|
|
59
|
-
|
|
59
|
+
const liveUpdate = liveUpdateSettings({
|
|
60
|
+
platform,
|
|
61
|
+
...mobile.publicKey && { publicKey: mobile.publicKey },
|
|
62
|
+
...builtInOrder && { builtInOrder },
|
|
63
|
+
apiOrigin: url.origin,
|
|
64
|
+
live: live !== void 0
|
|
65
|
+
});
|
|
66
|
+
if (liveUpdate.note) process.stderr.write(`note: ${liveUpdate.note}\n`);
|
|
67
|
+
const config = {
|
|
60
68
|
appId: mobile.appId,
|
|
61
69
|
appName,
|
|
62
70
|
fingerprint,
|
|
@@ -65,6 +73,10 @@ const prepare = async ({ projectDir, platform, api, extensions, live, release },
|
|
|
65
73
|
allowances,
|
|
66
74
|
apiOrigin: url.origin,
|
|
67
75
|
platform
|
|
76
|
+
};
|
|
77
|
+
await writeCapacitorConfig(ws, capacitorConfig({
|
|
78
|
+
...config,
|
|
79
|
+
...liveUpdate.settings && { liveUpdate: liveUpdate.settings }
|
|
68
80
|
}));
|
|
69
81
|
const cap = capacitorRunner(ws, env, run);
|
|
70
82
|
await generatePlatform(ws, platform, allowances, cap);
|
package/dist/mobile/web-part.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { bundleLayout } from "../bundle/manifest.js";
|
|
1
|
+
import { bundleLayout, readManifest } from "../bundle/manifest.js";
|
|
2
2
|
import { siteFiles } from "../serve/site-files.js";
|
|
3
3
|
import { buildDeployBundle } from "../build/deploy-bundle.js";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { cp, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
6
6
|
import { releaseManifestFile } from "@protobase/schema/internal";
|
|
7
|
-
import { releaseManifest, withApiOrigin } from "@protobase/server/mobile-release";
|
|
7
|
+
import { releaseManifest, releaseOrder, withApiOrigin } from "@protobase/server/mobile-release";
|
|
8
8
|
const writeReleaseManifest = async (web) => {
|
|
9
9
|
const files = await Promise.all((await siteFiles({
|
|
10
10
|
publicDir: web,
|
|
@@ -18,7 +18,9 @@ const writeReleaseManifest = async (web) => {
|
|
|
18
18
|
/**
|
|
19
19
|
* The app's files: the deploy bundle's `public/` (the shell, the project's UI plugins, theme and favicon), its
|
|
20
20
|
* index.html naming the API origin, and the updater's manifest of them. The bundle is built beside it and removed, so
|
|
21
|
-
* its server config module and packages never sit where Capacitor copies from.
|
|
21
|
+
* its server config module and packages never sit where Capacitor copies from. Gives the files' release order, as a
|
|
22
|
+
* server computes it for the same bundle with its own copy of the shell, `undefined` when the bundle names no build
|
|
23
|
+
* time: the live updater takes only a release above it.
|
|
22
24
|
*/
|
|
23
25
|
const buildWebPart = async ({ projectDir, ws, extensions, apiOrigin, build = buildDeployBundle, onWarning }) => {
|
|
24
26
|
const bundle = path.join(ws, "bundle");
|
|
@@ -33,6 +35,7 @@ const buildWebPart = async ({ projectDir, ws, extensions, apiOrigin, build = bui
|
|
|
33
35
|
extensions,
|
|
34
36
|
...onWarning && { onWarning }
|
|
35
37
|
});
|
|
38
|
+
const { builtAt } = await readManifest(bundle);
|
|
36
39
|
await rm(web, {
|
|
37
40
|
recursive: true,
|
|
38
41
|
force: true
|
|
@@ -45,6 +48,7 @@ const buildWebPart = async ({ projectDir, ws, extensions, apiOrigin, build = bui
|
|
|
45
48
|
const index = path.join(web, bundleLayout.spa);
|
|
46
49
|
await writeFile(index, withApiOrigin(await readFile(index, "utf8"), apiOrigin));
|
|
47
50
|
await writeReleaseManifest(web);
|
|
51
|
+
return { builtInOrder: releaseOrder(builtAt === void 0 ? {} : { builtAt }) };
|
|
48
52
|
};
|
|
49
53
|
/** A stand-in for the app's files with `--live`, where the app opens `protobase dev` and never shows them. */
|
|
50
54
|
const placeholderWebPart = async (ws) => {
|
|
@@ -55,6 +59,7 @@ const placeholderWebPart = async (ws) => {
|
|
|
55
59
|
});
|
|
56
60
|
await mkdir(web, { recursive: true });
|
|
57
61
|
await writeFile(path.join(web, bundleLayout.spa), "<!doctype html><title>protobase dev</title>\n");
|
|
62
|
+
return { builtInOrder: void 0 };
|
|
58
63
|
};
|
|
59
64
|
//#endregion
|
|
60
65
|
export { buildWebPart, placeholderWebPart };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { siteFiles } from "./site-files.js";
|
|
2
2
|
import { readFile } from "node:fs/promises";
|
|
3
|
-
import { composeRelease, nativeFingerprint, withApiOrigin } from "@protobase/server/mobile-release";
|
|
3
|
+
import { composeRelease, nativeFingerprint, releaseOrder, withApiOrigin } from "@protobase/server/mobile-release";
|
|
4
4
|
//#region src/serve/mobile-release.ts
|
|
5
5
|
const loopback = [
|
|
6
6
|
"localhost",
|
|
@@ -17,16 +17,6 @@ const releaseOrigin = (issuer) => {
|
|
|
17
17
|
if (url.protocol === "https:" || url.protocol === "http:" && loopback.includes(url.hostname)) return url.origin;
|
|
18
18
|
};
|
|
19
19
|
/**
|
|
20
|
-
* The order of the site's release: when its bundle was built, then when the server's own shell it serves instead of the
|
|
21
|
-
* bundle's copy was built, 0 with the copy. `undefined` when the bundle or that shell names no build time.
|
|
22
|
-
*/
|
|
23
|
-
const releaseOrder = (site) => {
|
|
24
|
-
if (site.builtAt === void 0) return;
|
|
25
|
-
if (!site.shell) return [site.builtAt, 0];
|
|
26
|
-
if (site.shell.builtAt === void 0) return;
|
|
27
|
-
return [site.builtAt, site.shell.builtAt];
|
|
28
|
-
};
|
|
29
|
-
/**
|
|
30
20
|
* The release of the app's files a server offers its mobile app: every file the site serves, its SPA page naming the
|
|
31
21
|
* API origin as the app's own files do, for binaries of the fingerprint of the site's native packages and the project's
|
|
32
22
|
* plugins. Signed, its statement binds it to its order, the app id, that fingerprint and the server's Protobase version.
|
|
@@ -59,4 +49,4 @@ const servedRelease = async ({ site, mobile, issuer, signingKey, serverVersion }
|
|
|
59
49
|
};
|
|
60
50
|
};
|
|
61
51
|
//#endregion
|
|
62
|
-
export {
|
|
52
|
+
export { releaseOrigin, servedRelease };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.57.
|
|
3
|
+
"version": "0.57.4",
|
|
4
4
|
"description": "The protobase command: scaffold, doctor, dev, build and serve a Protobase project.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -42,12 +42,12 @@
|
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@better-auth/core": "^1.7.12",
|
|
44
44
|
"@hono/node-server": "^2.1.3",
|
|
45
|
-
"@protobase/config": "0.57.
|
|
46
|
-
"@protobase/layout": "0.57.
|
|
47
|
-
"@protobase/query": "0.57.
|
|
48
|
-
"@protobase/schema": "0.57.
|
|
49
|
-
"@protobase/server": "0.57.
|
|
50
|
-
"@protobase/ui": "0.57.
|
|
45
|
+
"@protobase/config": "0.57.4",
|
|
46
|
+
"@protobase/layout": "0.57.4",
|
|
47
|
+
"@protobase/query": "0.57.4",
|
|
48
|
+
"@protobase/schema": "0.57.4",
|
|
49
|
+
"@protobase/server": "0.57.4",
|
|
50
|
+
"@protobase/ui": "0.57.4",
|
|
51
51
|
"@react-email/render": "^2.1.0",
|
|
52
52
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
53
53
|
"@tailwindcss/vite": "^4.3.3",
|
|
@@ -25,3 +25,4 @@ Develop, build and run an app, on servers, in containers and on phones.
|
|
|
25
25
|
- [Protobase Cloud deploys](../guides/deploy.md#protobase-cloud): A push to the app's GitHub branch builds it, migrates and checks its database in one transaction, and switches to the new version once it answers its health check.
|
|
26
26
|
- [Mobile apps](../guides/mobile-app.md) (beta): Runs an app on iOS and Android, also on your own iPhone, with sign-in, and builds signed store releases from a section in its config.
|
|
27
27
|
- [Mobile releases](../reference/cli.md#mobile-releases) (in development): The server offers the mobile app a newer copy of its files, signed, and any host that serves bundles can offer the same from the bundle's files without running its config.
|
|
28
|
+
- [Live updates](../reference/cli.md#the-live-updater) (in development): The Android app updates itself in the background to the server's release, downloading only the files that changed, and goes back to the files it was built with when a release fails to start.
|
|
@@ -120,7 +120,28 @@ Only Gradle gets them, for the length of the build: npm, its install scripts and
|
|
|
120
120
|
|
|
121
121
|
**iOS**, on a Mac with Xcode: `--team` is your Apple Developer team id, shown in your account's membership details. Xcode signs with the certificates and profiles of the account you added in its settings. For manual signing, pass `--certificate <name>` and `--profile <name>` too. If automatic signing finds no profile for a new app, run `protobase mobile open ios`, pick the team in Signing & Capabilities and archive once from Xcode (Product, Archive), which creates the profile; then build again.
|
|
122
122
|
|
|
123
|
-
## 7.
|
|
123
|
+
## 7. Live updates
|
|
124
|
+
|
|
125
|
+
An Android app updates its files itself from your server, so it gets UI changes without a store release. Make a key pair once:
|
|
126
|
+
|
|
127
|
+
```sh
|
|
128
|
+
protobase mobile keys
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Set `PROTOBASE_MOBILE_SIGNING_KEY` from its first line on the server, as a secret, and put the public key in the mobile section, which is safe to commit:
|
|
132
|
+
|
|
133
|
+
```ts
|
|
134
|
+
mobile: {
|
|
135
|
+
appId: 'com.example.shop',
|
|
136
|
+
publicKey: `-----BEGIN PUBLIC KEY-----
|
|
137
|
+
...
|
|
138
|
+
-----END PUBLIC KEY-----`,
|
|
139
|
+
},
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Build the binary again. Each deploy of the app then reaches it: it downloads the files that changed in the background and runs them at its next start, and a release that fails to start goes back to the files the binary carries. Releases come from a server of the same Protobase minor as the binary (below 1.0); a newer minor needs a store release. See [the live updater](../reference/cli.md#the-live-updater). <gap>The iOS app cannot update itself because its guarded live updater is not implemented.</gap>
|
|
143
|
+
|
|
144
|
+
## 8. What the stores accept
|
|
124
145
|
|
|
125
146
|
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).
|
|
126
147
|
|
|
@@ -424,7 +424,7 @@ The app's address and secret are `PROTOBASE_URL` and `PROTOBASE_SECRET` unless i
|
|
|
424
424
|
### Mobile releases
|
|
425
425
|
|
|
426
426
|
:::caution[In development]
|
|
427
|
-
<gap>The
|
|
427
|
+
<gap>The iOS app cannot install a release because its guarded live updater is not implemented.</gap>
|
|
428
428
|
:::
|
|
429
429
|
|
|
430
430
|
With a `mobile` section, the server serves the [mobile app](../guides/mobile-app.md) a newer copy of its files, for its live updater, so the app gets UI changes without a store release. The release is what the server serves the web, composed at startup: every file of `public/`, with the server's own shell where `protobase serve` uses it, and `index.html` naming the API origin, the app's `url` (https, or plain http to `localhost`, `127.0.0.1` or `[::1]`). There is none when the server serves the API alone, has no such `url`, or the bundle names no `native`, and with `PROTOBASE_MOBILE_SIGNING_KEY` none for a bundle that names no build time (one built before Protobase recorded it: build it again). Where `protobase serve` serves its own shell, the release's fingerprint names the `native` of that shell's `protobase.shell.json`, and there is none when it names none.
|
|
@@ -432,7 +432,16 @@ With a `mobile` section, the server serves the [mobile app](../guides/mobile-app
|
|
|
432
432
|
- `GET /api/mobile/release?fingerprint=<native fingerprint>&shell_version=<x.y.z>` answers `{ "bundleId", "url", "required" }`: the release's id, a hash of its files, and its absolute base URL, both `null` when the release does not run on the asking binary, whose native fingerprint must equal the release's. `required` is true when the shell the app runs no longer works with the server's API: below 1.0 another minor, from 1.0 another major. A missing fingerprint or a shell version that is no x.y.z version gets 400.
|
|
433
433
|
- `GET /api/mobile/releases/<bundleId>?href=<file>` serves the release's file `<file>`, such as `assets/index-abc123.js`, and with `href=capawesome-live-update-manifest.json` its manifest, a JSON array of `{ "href", "checksum", "sizeInBytes" }`. Each comes with its sha256 in hex in `X-Checksum` and, with `PROTOBASE_MOBILE_SIGNING_KEY`, its signature in `X-Signature`. Any other file, or another release's id, gets 404.
|
|
434
434
|
- Signed, a release also serves `href=protobase-release.json`, its statement: `{ "payload", "signature" }`, the payload the hex of the JSON `{ "manifest", "order", "appId", "fingerprint", "shellVersion" }` and the signature the hex of its SHA256withRSA over the line `protobase-mobile-release` and the payload. It binds the manifest's sha256 to the release's order, when the bundle was built and then when the server's own shell it serves was built (0 with the bundle's copy), to the app id and native fingerprint of the binaries it runs on, and to the server's Protobase version. Its id is then a hash of the statement and the public key, so the same files built again get another id. A file of the app may not be named like the statement or start with that line.
|
|
435
|
-
- On Android, the app downloads a release itself and takes it only when its statement is signed with the key the binary pins, names the release's id, this app, this binary and a server its shell works with, and its order is not below the highest it downloaded; then every file must hash to what the manifest lists, under a path inside the release, before any file is written. It runs a downloaded release only above the running one's order and holding nothing but the files its manifest lists. <gap>A phone cannot take a rollback of the bundle or of the server's shell before a later build, because ordering releases by an explicit release number is not implemented.</gap> <gap>An Android app cannot refuse a signed release older than
|
|
435
|
+
- On Android, the app downloads a release itself and takes it only when its statement is signed with the key the binary pins, names the release's id, this app, this binary and a server its shell works with, and its order is not below the highest it downloaded; then every file must hash to what the manifest lists, under a path inside the release, before any file is written. It runs a downloaded release only above the running one's order and holding nothing but the files its manifest lists. It never takes a release at or below the order of its own files, which `protobase mobile` records in the binary as the server would order the same bundle with its copy of the shell, so a reinstalled app is not taken below them, and a release built before the binary is not taken. <gap>A phone cannot take a rollback of the bundle or of the server's shell before a later build, because ordering releases by an explicit release number is not implemented.</gap> <gap>An Android app with no download recorded, such as after a reinstall, cannot refuse a genuine signed release older than the latest but newer than its own files, because a signed answer naming the latest release is not implemented.</gap> <gap>The iOS app cannot check a release's statement because its guarded live updater is not implemented.</gap>
|
|
436
|
+
|
|
437
|
+
#### The live updater
|
|
438
|
+
|
|
439
|
+
An Android app built with `mobile.publicKey` updates itself from the server it calls. The shell asks `GET /api/mobile/release` when the app starts and each time it comes back to the foreground, in the background, and downloads a release it does not run, only the files that changed, then runs it at the next cold start. The session stays in the device's cookie store, so the user stays signed in across the switch.
|
|
440
|
+
|
|
441
|
+
- Once the shell has drawn, it tells the updater the release started. A release that does not within 30 seconds goes back to the app's own files at once and is never taken again.
|
|
442
|
+
- No answer, any status but 200, a body that is not the answer, or an answer naming no release changes nothing: the app keeps the files it runs, and never goes back to its own files because of the answer, which is not signed.
|
|
443
|
+
- At launch, a required update holds the app with a notice while the release downloads, then reloads into it; a refused release, a failed download or a minute without one lets the app go on with the files it runs. <gap>A required update across a Protobase minor below 1.0, or a major, cannot reach a phone by live update because taking a release of another shell version than the binary's is not implemented, so such a fix, a security fix included, reaches it only through a store release.</gap>
|
|
444
|
+
- The binary pins the public key: a new key needs a new store release, and a server whose `PROTOBASE_MOBILE_SIGNING_KEY` is not its private half serves releases the app refuses.
|
|
436
445
|
|
|
437
446
|
A host that serves bundles without running their config, such as a router in front of many apps or a static host, serves the same release from the files it already serves with `@protobase/server/mobile-release`, which loads none of the rest of the server: `protobase serve` composes its own release with the same exports.
|
|
438
447
|
|
|
@@ -580,6 +589,7 @@ protobase mobile run <ios|android> [--api <url>] [--target <id>] [--team <id>] [
|
|
|
580
589
|
protobase mobile open <ios|android> [--api <url>] [--extend <dir>]
|
|
581
590
|
protobase mobile build <ios|android> --app-version <x.y.z> --build-number <n> [--api <url>] [--out mobile-release] [--extend <dir>]
|
|
582
591
|
[--team <id> [--certificate <name> --profile <name>]]
|
|
592
|
+
protobase mobile keys
|
|
583
593
|
```
|
|
584
594
|
|
|
585
595
|
Builds the project in the current directory as an iOS or Android app with Capacitor, from the `mobile` section of its `protobase.config.ts`; without one it stops and says what to add. `--extend <dir>` (repeatable) merges an [extension](config.md#extensions)'s `protobase.config.ts` and `protobase.ui.tsx` before the project's, as `build` does. See [A mobile app](../guides/mobile-app.md).
|
|
@@ -592,6 +602,8 @@ Builds the project in the current directory as an iOS or Android app with Capaci
|
|
|
592
602
|
- npm and Capacitor get the CLI's environment without any variable named in the current directory's `.env*` files, nor the four `PROTOBASE_ANDROID_*` signing variables, which only Gradle gets, and with `CI=true`, which keeps Capacitor's telemetry off.
|
|
593
603
|
- It prints the workspace, the API origin and the native fingerprint, which the app also sends in its user agent as `ProtobaseNative/<fingerprint>`: a hash of the native packages `@protobase/mobile` pins, at their versions, its own native contract, and the section's `plugins`, at the versions they give. A [mobile release](#mobile-releases) runs only on a binary of its own fingerprint. A Protobase release that pins the same native packages and keeps the same native contract keeps it; raise a plugin's version when the app's files start using a newer native feature of it, which changes it.
|
|
594
604
|
- The app's files carry the live updater's manifest of them, so an update downloads only the files that changed.
|
|
605
|
+
- With `mobile.publicKey`, the Android app gets the [live updater](#the-live-updater), unless `--live` is given, the app's files name no build time, or the API is neither https nor http to this machine; it prints a note why when it leaves it out. The iOS app gets none yet.
|
|
606
|
+
- `keys` prints a fresh RSA key pair: `PROTOBASE_MOBILE_SIGNING_KEY=<key>`, on one line with its newlines written `\n`, for the server's environment, a secret never to commit, and the public key, PEM, for `mobile.publicKey`. It reads no project and writes no file.
|
|
595
607
|
|
|
596
608
|
## `token`
|
|
597
609
|
|
|
@@ -98,12 +98,13 @@ export default defineConfig({ backgroundColor: '#ffffff' })
|
|
|
98
98
|
|
|
99
99
|
## mobile
|
|
100
100
|
|
|
101
|
-
- **Type:** `{ appId: string; plugins?: Record<string, string
|
|
101
|
+
- **Type:** `{ appId: string; plugins?: Record<string, string>; publicKey?: string }`
|
|
102
102
|
|
|
103
103
|
The app's iOS and Android build: with it, `protobase mobile` builds the app with Capacitor, and the API also allows the app's Capacitor origins (`capacitor://localhost`, `https://localhost`) for [CORS](api.md#cors). See [A mobile app](../../guides/mobile-app.md).
|
|
104
104
|
|
|
105
105
|
- `appId`: the app's id on both iOS and Android, such as `com.example.shop`: two or more dot-separated parts, each a letter then letters and digits.
|
|
106
106
|
- `plugins`: extra native Capacitor plugins, by npm name and version range. A range fetched over plain `http:` or `git:` is refused.
|
|
107
|
+
- `publicKey`: the public key, PEM, of the RSA key the server signs the app's [releases](../cli.md#the-live-updater) with, from [`protobase mobile keys`](../cli.md#mobile): with it the Android app updates itself. Anything but an RSA public key of at least 2048 bits stops the build.
|
|
107
108
|
|
|
108
109
|
```ts
|
|
109
110
|
export default defineConfig({
|
|
@@ -47,12 +47,12 @@ Every commit message follows [Conventional Commits](https://www.conventionalcomm
|
|
|
47
47
|
1. The checks of `ci.yml` (`bun run check`, the smoke test on Node, the docs build, the Storybook play tests and the docs check), of the tests and steps the changes since the last `v<version>` tag affect (see What a push checks in `CONTRIBUTING.md`), and commitlint over the pushed commits. The Postgres suite (`bun run test:postgres`, on Postgres and PgBouncer) runs in full as well, whatever changed, beside the other checks. They start at once, and the release waits for them all.
|
|
48
48
|
2. `bun run release` (`scripts/release.mjs`, with [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version)) computes the next version and its notes from the commits since the last `v<version>` tag, as above, and tags the pushed commit `v<version>`. It commits nothing and changes no file. Without a fix, feature or breaking change it tags nothing.
|
|
49
49
|
3. The tag is pushed, and the GitHub release of the tag gets the notes.
|
|
50
|
-
4. `scripts/stamp-version.mjs` writes
|
|
50
|
+
4. Beside the checks, a pack job takes the tag `bun run release --dry-run` predicts, and `scripts/stamp-version.mjs` writes its version into every `package.json` and `bun.lock` in the runner, never committed. `scripts/publish.mjs --pack --out` then builds every package to `dist` and packs it with Bun (the private `@protobase/presets` is not published). Once the tag is pushed, npm, under Node, publishes those tarballs with [trusted publishing](https://docs.npmjs.com/trusted-publishers) and provenance (`scripts/publish.mjs --from`); there is no npm token, and only the publish job holds the identity token it needs. A tag other than the version the tarballs were stamped with fails the publish before anything is uploaded, and a run that cut no release packs and publishes nothing.
|
|
51
51
|
5. Once npm serves the packages, the tag's version is written into the `package.json` files the same way, and `bun run images:context <image>` writes each image's build context at the tag from them, and the images are built natively for `linux/amd64` and `linux/arm64` and pushed to GitHub's registry as `ghcr.io/prototeamhq/protobase:<version>` and `ghcr.io/prototeamhq/protobase-dev:<version>` (see [Deploy](../guides/deploy.md#images)). A release whose publish failed has no images.
|
|
52
52
|
|
|
53
53
|
When `main` moved on while the checks ran, the run of the newer push releases both. `bun run release --dry-run` prints the next version and its notes without tagging anything.
|
|
54
54
|
|
|
55
|
-
Running the workflow by hand with a tag (`gh workflow run release.yml -f tag=v0.1.0`) only publishes: the packages at that tag and its version, skipping every version npm already has, and the images, which repeats a missed or half-done publish. `node scripts/publish.mjs --dry-run` packs the packages and shows what `npm publish` would send, and `node scripts/publish.mjs --pack`, which CI runs, packs every package without asking npm or publishing. Each package on npm trusts `release.yml` of `PrototeamHQ/protobase` as its publisher; a new package has to be published once by hand before that can be set up. The workflow pushes the images with its own token; a new image on GitHub's registry starts out private and is made public once in its package settings.
|
|
55
|
+
Running the workflow by hand with a tag (`gh workflow run release.yml -f tag=v0.1.0`) only packs and publishes: the packages at that tag and its version, skipping every version npm already has, and the images, which repeats a missed or half-done publish. `node scripts/publish.mjs --dry-run` packs the packages and shows what `npm publish` would send, and `node scripts/publish.mjs --pack`, which CI runs, packs every package without asking npm or publishing. Each package on npm trusts `release.yml` of `PrototeamHQ/protobase` as its publisher; a new package has to be published once by hand before that can be set up. The workflow pushes the images with its own token; a new image on GitHub's registry starts out private and is made public once in its package settings.
|
|
56
56
|
|
|
57
57
|
## Bundled and locked projects
|
|
58
58
|
|