@protobase/cli 0.57.2 → 0.57.3

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.
@@ -86,6 +86,7 @@ const buildDeployBundle = async ({ projectDir, outDir, bun, extensions = [], sou
86
86
  const manifest = {
87
87
  version: 3,
88
88
  protobase,
89
+ builtAt: Date.now(),
89
90
  ...bundleLayout,
90
91
  api: [...bundleLayout.api],
91
92
  plugins,
@@ -38,7 +38,8 @@ const shellIdentity = async () => {
38
38
  return {
39
39
  protobase: ui.version,
40
40
  pluginApi: ui.protobase.pluginApi,
41
- paths: shellPaths
41
+ paths: shellPaths,
42
+ builtAt: Date.now()
42
43
  };
43
44
  };
44
45
  /**
@@ -18,16 +18,18 @@ const isStringList = (value) => Array.isArray(value) && value.every((item) => ty
18
18
  const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
19
19
  const isFieldTypes = (value) => isObject(value) && Object.values(value).every(isStringList);
20
20
  const isPlugin = (value) => isObject(value) && typeof value.name === "string" && typeof value.path === "string" && Number.isInteger(value.api) && typeof value.protobase === "string" && (value.fields === void 0 || isFieldTypes(value.fields));
21
- const isShell = (value) => isObject(value) && typeof value.protobase === "string" && Number.isInteger(value.pluginApi) && isStringList(value.paths);
21
+ const isShell = (value) => isObject(value) && typeof value.protobase === "string" && Number.isInteger(value.pluginApi) && isStringList(value.paths) && (value.builtAt === void 0 || isTime(value.builtAt));
22
+ const isTime = (value) => Number.isSafeInteger(value) && value >= 0;
22
23
  const isVersions = (value) => isObject(value) && Object.values(value).every((item) => typeof item === "string");
23
24
  const isIcons = (value) => isObject(value) && typeof value.favicon === "boolean" && isStringList(value.png) && value.png.every((icon) => icon in pngIcons);
24
25
  const parseManifest = (value, file) => {
25
26
  const manifest = value;
26
27
  if (manifest?.version !== 3) throw new Error(`${file} is not a version 3 bundle manifest; rebuild it with \`protobase build\``);
27
- const { server, public: publicDir, api, spa, plugins, theme, shell, icons, native, mobile, nodeModules, migrations } = manifest;
28
+ const { builtAt, server, public: publicDir, api, spa, plugins, theme, shell, icons, native, mobile, nodeModules, migrations } = manifest;
28
29
  if (typeof server !== "string" || typeof publicDir !== "string" || typeof spa !== "string" || typeof theme !== "string" || !isStringList(api)) throw new Error(`${file} needs server, public, spa and theme paths and an api list`);
29
30
  if (!Array.isArray(plugins) || !plugins.every(isPlugin)) throw new Error(`${file} needs a plugins list, each with a name, path, api and protobase`);
30
31
  if (!isShell(shell)) throw new Error(`${file} needs a shell with its protobase version, pluginApi and paths`);
32
+ if (builtAt !== void 0 && !isTime(builtAt)) throw new Error(`${file} has a builtAt that is no time in ms`);
31
33
  if (icons !== void 0 && !isIcons(icons)) throw new Error(`${file} has icons that are not a favicon flag and a list of PNG icons`);
32
34
  if (native !== void 0 && !isVersions(native)) throw new Error(`${file} has a native that is not a map of package names to versions`);
33
35
  if (mobile !== void 0 && !(isObject(mobile) && isVersions(mobile.plugins))) throw new Error(`${file} has a mobile that is not { plugins } with a map of package names to versions`);
@@ -35,6 +37,7 @@ const parseManifest = (value, file) => {
35
37
  if (migrations !== void 0 && typeof migrations !== "string") throw new Error(`${file} has a migrations that is no path`);
36
38
  return {
37
39
  version: 3,
40
+ ...builtAt !== void 0 && { builtAt },
38
41
  server,
39
42
  public: publicDir,
40
43
  api,
@@ -1,4 +1,4 @@
1
1
  //#region package.json
2
- var version = "0.57.2";
2
+ var version = "0.57.3";
3
3
  //#endregion
4
4
  export { version };
@@ -4,17 +4,19 @@ import { capacitorOrigin } from "@protobase/schema/internal";
4
4
  //#region src/mobile/capacitor-config.ts
5
5
  const protobasePlugin = "@protobase/mobile";
6
6
  const keyboardPlugin = "@capacitor/keyboard";
7
+ const liveUpdatePlugin = "@capawesome/capacitor-live-update";
7
8
  /**
8
9
  * The app's `capacitor.config.json`, every key it sets named here. It never sets `server.url`, the hostname or the
9
10
  * schemes (the API's CORS list names Capacitor's default origins), or WebView debugging (on in debug builds only).
10
- * `plugins` configures ProtobaseAuth and the keyboard plugin alone, so CapacitorHttp and CapacitorCookies stay off;
11
- * the keyboard plugin resizes natively, its default, and fills the space beside the keyboard's rounded corners with the
12
- * page's background instead of black. Protobase's plugin is compiled in last, so its stand-ins replace any plugin of
13
- * the same name. Service workers get nothing from the local server on Android, which they would reach past the
14
- * WebViewClient that guards it. The file ships outside the app's web part, so the fingerprint in the user agent and
15
- * ProtobaseAuth's origins are beyond page script and a live update.
11
+ * `plugins` configures ProtobaseAuth, the keyboard plugin and, with the live updater, the binary's fingerprint and shell
12
+ * version its guard takes a release only for, so CapacitorHttp and CapacitorCookies stay off; the keyboard plugin
13
+ * resizes natively, its default, and fills the space beside the keyboard's rounded corners with the page's background
14
+ * instead of black. Protobase's plugin is compiled in last, so its stand-ins replace any plugin of the same name.
15
+ * Service workers get nothing from the local server on Android, which they would reach past the WebViewClient that
16
+ * guards it. The file ships outside the app's web part, so the fingerprint in the user agent and ProtobaseAuth's
17
+ * origins are beyond page script and a live update.
16
18
  */
17
- const capacitorConfig = ({ appId, appName, fingerprint, plugins, allowances, apiOrigin, platform }) => ({
19
+ const capacitorConfig = ({ appId, appName, fingerprint, shellVersion, plugins, allowances, apiOrigin, platform }) => ({
18
20
  appId,
19
21
  appName,
20
22
  webDir: "web",
@@ -29,7 +31,11 @@ const capacitorConfig = ({ appId, appName, fingerprint, plugins, allowances, api
29
31
  apiOrigin,
30
32
  origin: capacitorOrigin[platform]
31
33
  },
32
- Keyboard: { autoBackdropColor: "dom" }
34
+ Keyboard: { autoBackdropColor: "dom" },
35
+ ...plugins.includes(liveUpdatePlugin) && { LiveUpdate: {
36
+ fingerprint,
37
+ shellVersion
38
+ } }
33
39
  },
34
40
  ...allowances.cleartext && { server: { cleartext: true } },
35
41
  android: {
@@ -1,6 +1,6 @@
1
1
  //#region ../mobile/package.json
2
2
  var name = "@protobase/mobile";
3
- var nativeContract = 5;
3
+ var nativeContract = 6;
4
4
  var dependencies = {
5
5
  "@capacitor/android": "8.5.3",
6
6
  "@capacitor/app": "8.1.2",
@@ -1,3 +1,4 @@
1
+ import { protobaseVersion } from "../version/version.js";
1
2
  import { checkInstalledPlugins, checkPinnedNative, pinnedNative } from "./pinned-packages.js";
2
3
  import { checkMobileConfig } from "./mobile-config.js";
3
4
  import { withoutAndroidSigning } from "./android-signing.js";
@@ -59,6 +60,7 @@ const prepare = async ({ projectDir, platform, api, extensions, live, release },
59
60
  appId: mobile.appId,
60
61
  appName,
61
62
  fingerprint,
63
+ shellVersion: protobaseVersion,
62
64
  plugins,
63
65
  allowances,
64
66
  apiOrigin: url.origin,
@@ -4,6 +4,7 @@ const bundleSite = (dir, manifest) => ({
4
4
  publicDir: path.resolve(dir, manifest.public),
5
5
  spa: manifest.spa,
6
6
  api: manifest.api,
7
+ ...manifest.builtAt !== void 0 && { builtAt: manifest.builtAt },
7
8
  ...manifest.native && { native: manifest.native }
8
9
  });
9
10
  //#endregion
@@ -55,7 +55,8 @@ const startServe = async ({ config, env, openDb = (url) => openAppDatabase(pg, u
55
55
  site,
56
56
  mobile: project.mobile,
57
57
  issuer: project.auth?.issuer,
58
- signingKey: env.mobileSigningKey
58
+ signingKey: env.mobileSigningKey,
59
+ serverVersion: protobaseVersion
59
60
  }) : void 0;
60
61
  const mobile = project.mobile && {
61
62
  ...release && { release },
@@ -17,23 +17,46 @@ 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
+ /**
20
30
  * The release of the app's files a server offers its mobile app: every file the site serves, its SPA page naming the
21
31
  * API origin as the app's own files do, for binaries of the fingerprint of the site's native packages and the project's
22
- * plugins. None without a mobile section, without the site's files (the API alone, whose files a host serves), a
23
- * site that names no native packages (a bundle built before them) or an API origin an app calls.
32
+ * plugins. Signed, its statement binds it to its order, the app id, that fingerprint and the server's Protobase version.
33
+ * None without a mobile section, without the site's files (the API alone, whose files a host serves), a site that
34
+ * names no native packages (a bundle built before them), an API origin an app calls, or, signed, an order.
24
35
  */
25
- const servedRelease = async ({ site, mobile, issuer, signingKey }) => {
36
+ const servedRelease = async ({ site, mobile, issuer, signingKey, serverVersion }) => {
26
37
  const origin = releaseOrigin(issuer);
27
38
  if (!mobile || !site?.native || !origin) return void 0;
39
+ const order = releaseOrder(site);
40
+ if (signingKey && !order) return void 0;
41
+ const fingerprint = nativeFingerprint(site.native, mobile.plugins);
28
42
  const files = await Promise.all((await siteFiles(site)).map(async ({ href, file }) => ({
29
43
  href,
30
44
  content: href === site.spa ? new TextEncoder().encode(withApiOrigin(await readFile(file, "utf8"), origin)) : new Uint8Array(await readFile(file))
31
45
  })));
46
+ const signing = signingKey && order && {
47
+ key: signingKey,
48
+ binding: {
49
+ order,
50
+ appId: mobile.appId,
51
+ fingerprint,
52
+ shellVersion: serverVersion
53
+ }
54
+ };
32
55
  return {
33
- ...composeRelease(files, signingKey),
34
- fingerprint: nativeFingerprint(site.native, mobile.plugins),
56
+ ...composeRelease(files, signing),
57
+ fingerprint,
35
58
  origin
36
59
  };
37
60
  };
38
61
  //#endregion
39
- export { releaseOrigin, servedRelease };
62
+ export { releaseOrder, releaseOrigin, servedRelease };
@@ -13,7 +13,8 @@ const servedShell = async (ownDir) => {
13
13
  return {
14
14
  shell: {
15
15
  dir: ownDir,
16
- paths: own.paths
16
+ paths: own.paths,
17
+ ...own.builtAt !== void 0 && { builtAt: own.builtAt }
17
18
  },
18
19
  ...own.native && { native: own.native },
19
20
  note: `the app of Protobase ${own.protobase} from ${ownDir}`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/cli",
3
- "version": "0.57.2",
3
+ "version": "0.57.3",
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.2",
46
- "@protobase/layout": "0.57.2",
47
- "@protobase/query": "0.57.2",
48
- "@protobase/schema": "0.57.2",
49
- "@protobase/server": "0.57.2",
50
- "@protobase/ui": "0.57.2",
45
+ "@protobase/config": "0.57.3",
46
+ "@protobase/layout": "0.57.3",
47
+ "@protobase/query": "0.57.3",
48
+ "@protobase/schema": "0.57.3",
49
+ "@protobase/server": "0.57.3",
50
+ "@protobase/ui": "0.57.3",
51
51
  "@react-email/render": "^2.1.0",
52
52
  "@scalar/hono-api-reference": "^0.12.10",
53
53
  "@tailwindcss/vite": "^4.3.3",
@@ -407,7 +407,7 @@ Serves the API of a bundle from `protobase build` and owns the process around it
407
407
  | `PROTOBASE_STARTUP_CHECKS` | `false` skips the startup reads of the auth, changes, computed columns, webhooks and jobs schemas, which make a start slower; default `true`. Set it only to restart a bundle that already started on this database, such as when a platform wakes a sleeping app, never for a new bundle or after its migrations ran |
408
408
  | `PROTOBASE_SHELL` | `protobase serve <bundle>` only: a shell folder, such as the `/opt/protobase/shell` of a protobase image or `@protobase/ui`'s `dist/shell`, to serve the bundle's app from (see [its own shell](#serve)) |
409
409
  | `PROTOBASE_TRUSTED_PROXIES` | the proxies in front of the server, addresses or CIDR ranges, comma separated: a request from one of them names its client in `X-Forwarded-For`; without it the client is the connection's address ([Client addresses](auth.md#client-addresses)) |
410
- | `PROTOBASE_MOBILE_SIGNING_KEY` | an RSA private key of at least 2048 bits, PEM, its newlines real or written `\n`, that signs every file of the [mobile release](#mobile-releases) in `X-Signature`, for an app whose updater checks signatures with the matching public key; another kind of key, or a shorter one, stops startup |
410
+ | `PROTOBASE_MOBILE_SIGNING_KEY` | an RSA private key of at least 2048 bits, PEM, its newlines real or written `\n`, that signs every file of the [mobile release](#mobile-releases) in `X-Signature` and its statement, for an app whose updater checks signatures with the matching public key; another kind of key, or a shorter one, stops startup |
411
411
  | `PROTOBASE_JOBS_DRAIN_TOKEN` | the operator's bearer token for `POST /api/jobs/drain`, which [runs the due jobs](jobs.md#hosts-that-sleep) of a host that lets the app sleep; without it there is no such endpoint |
412
412
 
413
413
  The app's address and secret are `PROTOBASE_URL` and `PROTOBASE_SECRET` unless its config sets `url` and `secret` (see [App options](config/app.md)); its other settings are the project's own variables, read by its config, which the runtime reads again at start with the host's environment. `protobase serve` also loads the nearest `.env`, like `dev`; the runtime takes the environment as it is.
@@ -427,16 +427,18 @@ The app's address and secret are `PROTOBASE_URL` and `PROTOBASE_SECRET` unless i
427
427
  <gap>The mobile app cannot install a release yet because its live updater is not implemented.</gap>
428
428
  :::
429
429
 
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`. 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.
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.
431
431
 
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
+ - 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 its built-in files after a reinstall, because recording the order of the binary's own files is not implemented.</gap> <gap>The iOS app cannot check a release's statement because its guarded live updater is not implemented.</gap>
434
436
 
435
437
  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.
436
438
 
437
439
  - `nativeFingerprint(native, plugins)`: the release's fingerprint, from the manifest's `native` (or that of the shell the host serves) and `mobile.plugins`. It is a contract across versions: a binary one Protobase release built is matched by a host that runs another.
438
440
  - `withApiOrigin(html, origin)`: the `spa` page naming the API origin, the app's `url`.
439
- - `composeRelease(files, signingKey?)`: the release of `{ href, content }` files, every file the host serves the web with the page above in place of `spa`, with its id and the signed checksums.
441
+ - `composeRelease(files, signing?)`: the release of `{ href, content }` files, every file the host serves the web with the page above in place of `spa`, with its id and, with `signing`, `{ key, binding: { order, appId, fingerprint, shellVersion } }`, the signed checksums and statement.
440
442
  - `readSigningKey(env)`: the signing key in `PROTOBASE_MOBILE_SIGNING_KEY` of the env object given, the app's own, never the process's.
441
443
  - `mobileReleaseApp({ release, serverVersion })`: a Hono app answering the two routes above for `{ ...release, fingerprint, origin }`.
442
444