@protobase/cli 0.44.5 → 0.45.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
1
  //#region package.json
2
- var version = "0.44.5";
2
+ var version = "0.45.1";
3
3
  //#endregion
4
4
  export { version };
@@ -1,20 +1,31 @@
1
1
  import path from "node:path";
2
2
  import { rm, writeFile } from "node:fs/promises";
3
+ import { capacitorOrigin } from "@protobase/schema/internal";
3
4
  //#region src/mobile/capacitor-config.ts
5
+ const protobasePlugin = "@protobase/mobile";
4
6
  /**
5
7
  * The app's `capacitor.config.json`, every key it sets named here. It never sets `server.url`, the hostname or the
6
- * schemes (the API's CORS list names Capacitor's default origins), `plugins` (so CapacitorHttp and CapacitorCookies
7
- * stay off) or WebView debugging (on in debug builds only). The fingerprint goes in the user agent, which a live
8
- * update cannot change.
8
+ * schemes (the API's CORS list names Capacitor's default origins), or WebView debugging (on in debug builds only).
9
+ * `plugins` configures ProtobaseAuth alone, so CapacitorHttp and CapacitorCookies stay off. Protobase's plugin is
10
+ * compiled in last, so its stand-ins replace any plugin of the same name. Service workers get nothing from the local
11
+ * server on Android, which they would reach past the WebViewClient that guards it. The file ships outside the app's web
12
+ * part, so the fingerprint in the user agent and ProtobaseAuth's origins are beyond page script and a live update.
9
13
  */
10
- const capacitorConfig = ({ appId, appName, fingerprint, plugins, allowances }) => ({
14
+ const capacitorConfig = ({ appId, appName, fingerprint, plugins, allowances, apiOrigin, platform }) => ({
11
15
  appId,
12
16
  appName,
13
17
  webDir: "web",
14
18
  appendUserAgent: `ProtobaseNative/${fingerprint}`,
15
- includePlugins: plugins,
19
+ includePlugins: [...plugins, protobasePlugin],
20
+ plugins: { ProtobaseAuth: {
21
+ apiOrigin,
22
+ origin: capacitorOrigin[platform]
23
+ } },
16
24
  ...allowances.cleartext && { server: { cleartext: true } },
17
- ...allowances.mixedContent && { android: { allowMixedContent: true } }
25
+ android: {
26
+ resolveServiceWorkerRequests: false,
27
+ ...allowances.mixedContent && { allowMixedContent: true }
28
+ }
18
29
  });
19
30
  /** Writes the config into the workspace `dir`, removing the `.ts` and `.js` configs Capacitor would read instead. */
20
31
  const writeCapacitorConfig = async (dir, config) => {
@@ -1,11 +1,12 @@
1
1
  import { createHash } from "node:crypto";
2
2
  //#region src/mobile/fingerprint.ts
3
3
  /**
4
- * Names the app's native code: the native packages @protobase/mobile pins, name → version (`pinnedNative`), and the
5
- * project's `mobile.plugins`, name → the spec it gives. A release of the app's files runs only on a binary of the same
6
- * fingerprint. It holds no Protobase version, so a Protobase release that pins the same native packages keeps
7
- * binaries on live updates. A plugin's spec counts, not the version npm installed: its floor is what the app's files
8
- * need of it, so raise the floor when they start using a newer native feature, which changes the fingerprint.
4
+ * Names the app's native code: what @protobase/mobile carries, name → version (`pinnedNative`: the native packages it
5
+ * pins and its own native contract), and the project's `mobile.plugins`, name → the spec it gives. A release of the
6
+ * app's files runs only on a binary of the same fingerprint. It holds no Protobase version, so a Protobase release that
7
+ * pins the same native packages and native contract keeps binaries on live updates. A plugin's spec counts, not the
8
+ * version npm installed: its floor is what the app's files need of it, so raise the floor when they start using a
9
+ * newer native feature, which changes the fingerprint.
9
10
  */
10
11
  const nativeFingerprint = (pinned, plugins = {}) => {
11
12
  const entries = Object.entries({
@@ -1,5 +1,6 @@
1
1
  //#region ../mobile/package.json
2
2
  var name = "@protobase/mobile";
3
+ var nativeContract = 1;
3
4
  var dependencies = {
4
5
  "@capacitor/android": "8.5.3",
5
6
  "@capacitor/app": "8.1.2",
@@ -10,4 +11,4 @@ var dependencies = {
10
11
  "@capawesome/capacitor-live-update": "8.7.1"
11
12
  };
12
13
  //#endregion
13
- export { dependencies, name };
14
+ export { dependencies, name, nativeContract };
@@ -1,4 +1,4 @@
1
- import { dependencies, name } from "./package.js";
1
+ import { dependencies, name, nativeContract } from "./package.js";
2
2
  import { installedPackage } from "./installed-package.js";
3
3
  //#region src/mobile/pinned-packages.ts
4
4
  /**
@@ -8,10 +8,15 @@ import { installedPackage } from "./installed-package.js";
8
8
  */
9
9
  const pinnedPackages = /* @__PURE__ */ new Set([name, ...Object.keys(dependencies)]);
10
10
  /**
11
- * The native packages @protobase/mobile pins, name → exact version, which a native fingerprint names. Never its
12
- * @protobase/* packages, whose version is Protobase's: every Protobase release would cut the binaries off updates.
11
+ * The native code an app's binary carries from @protobase/mobile, name → version, which a native fingerprint names:
12
+ * the native packages it pins, at their versions, and its own native code by its `nativeContract`, `native-<n>`. Never
13
+ * its npm version, which is Protobase's: every Protobase release would cut the binaries off updates. Raise
14
+ * `nativeContract` whenever its Android (later iOS) sources change; its test fails until it is.
13
15
  */
14
- const pinnedNative = Object.fromEntries(Object.entries(dependencies).filter(([name]) => !name.startsWith("@protobase/")));
16
+ const pinnedNative = {
17
+ ...Object.fromEntries(Object.entries(dependencies).filter(([name]) => !name.startsWith("@protobase/"))),
18
+ [name]: `native-${nativeContract}`
19
+ };
15
20
  const liveUpdate = "@capawesome/capacitor-live-update";
16
21
  /** Why the plugin `key`, a package that is or names `name`, may not be listed; `undefined` when it may. */
17
22
  const pinnedProblem = (key, name = key) => {
@@ -0,0 +1,24 @@
1
+ import path from "node:path";
2
+ import { readFile } from "node:fs/promises";
3
+ //#region src/mobile/protobase-plugin.ts
4
+ /** The classes of Protobase's native plugin that keep page script away from the session, by Java class name. */
5
+ const protobasePluginClasses = [
6
+ "ProtobaseAuth",
7
+ "RefusedHttp",
8
+ "RefusedCookies",
9
+ "RefusedWebView",
10
+ "LocalServerGuard"
11
+ ].map((name) => `net.protobase.mobile.${name}`);
12
+ /**
13
+ * Checks that `cap add android` compiled Protobase's native plugin into the app, from the plugin list it writes: an
14
+ * installed @protobase/mobile older than the CLI's, as a workspace left from an earlier CLI may hold, has none.
15
+ */
16
+ const checkProtobasePlugin = async (ws) => {
17
+ const file = path.join(ws, "android", "app", "src", "main", "assets", "capacitor.plugins.json");
18
+ const listed = new Set(JSON.parse(await readFile(file, "utf8")).map(({ classpath }) => classpath));
19
+ const missing = protobasePluginClasses.filter((name) => !listed.has(name));
20
+ if (missing.length === 0) return;
21
+ throw new Error(`The Android app lacks Protobase's native plugin (${missing.join(", ")}): delete ${ws} and run the command again`);
22
+ };
23
+ //#endregion
24
+ export { checkProtobasePlugin, protobasePluginClasses };
@@ -12,6 +12,7 @@ import { generatePlatform } from "./generate.js";
12
12
  import { checkMobileConfig } from "./mobile-config.js";
13
13
  import { loadMobileProject } from "./load-project.js";
14
14
  import { signForDevelopment } from "./development-signing.js";
15
+ import { checkProtobasePlugin } from "./protobase-plugin.js";
15
16
  import { mobileSpec, prepareWorkspace, workspaceDir, workspacePackageJson } from "./workspace.js";
16
17
  import path from "node:path";
17
18
  import { defaultAppName } from "@protobase/server";
@@ -50,10 +51,13 @@ const prepare = async ({ projectDir, platform, api, extensions, live, release },
50
51
  appName,
51
52
  fingerprint,
52
53
  plugins,
53
- allowances
54
+ allowances,
55
+ apiOrigin: url.origin,
56
+ platform
54
57
  }));
55
58
  const cap = capacitorRunner(ws, env, run);
56
59
  await generatePlatform(ws, platform, allowances, cap);
60
+ if (platform === "android") await checkProtobasePlugin(ws);
57
61
  return {
58
62
  ws,
59
63
  url,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/cli",
3
- "version": "0.44.5",
3
+ "version": "0.45.1",
4
4
  "description": "The protobase command: scaffold, doctor, dev, build and serve a Protobase project.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -36,11 +36,11 @@
36
36
  "@better-auth/core": "^1.7.12",
37
37
  "@hono/node-server": "^2.1.3",
38
38
  "@hono/vite-dev-server": "^0.26.1",
39
- "@protobase/layout": "0.44.5",
40
- "@protobase/query": "0.44.5",
41
- "@protobase/schema": "0.44.5",
42
- "@protobase/server": "0.44.5",
43
- "@protobase/ui": "0.44.5",
39
+ "@protobase/layout": "0.45.1",
40
+ "@protobase/query": "0.45.1",
41
+ "@protobase/schema": "0.45.1",
42
+ "@protobase/server": "0.45.1",
43
+ "@protobase/ui": "0.45.1",
44
44
  "@react-email/render": "^2.1.0",
45
45
  "@scalar/hono-api-reference": "^0.12.10",
46
46
  "@tailwindcss/vite": "^4.3.3",
@@ -31,7 +31,7 @@ export default defineConfig({
31
31
  ```
32
32
 
33
33
  - `appId` is the app's id in reverse-DNS form: at least two parts separated by dots, each starting with a letter and holding only letters, digits and underscores.
34
- - `plugins`, optional, are extra native [Capacitor plugins](https://capacitorjs.com/docs/plugins), npm name to version. Capacitor itself, `@capacitor/app`, `@capacitor/splash-screen` and `@capawesome/capacitor-live-update` come with Protobase at fixed versions and cannot be listed. A plugin runs native code with the app's rights, and one that writes files, such as `@capacitor/filesystem`, lets a script that got into the page point the app at files it wrote (with Capacitor's own `WebView.setServerBasePath`), so list only plugins the app needs.
34
+ - `plugins`, optional, are extra native [Capacitor plugins](https://capacitorjs.com/docs/plugins), npm name to version. Capacitor itself, `@capacitor/app`, `@capacitor/splash-screen` and `@capawesome/capacitor-live-update` come with Protobase at fixed versions and cannot be listed. A plugin runs native code with the app's rights, and one that writes files, such as `@capacitor/filesystem`, lets a script that got into the page point the iOS app at files it wrote (with Capacitor's own `WebView.setServerBasePath`), so list only plugins the app needs. On Android a plugin's JavaScript cannot call `CapacitorHttp`, `CapacitorCookies` or `WebView`, and `Capacitor.convertFileSrc` URLs do not load: call those from the plugin's native code.
35
35
 
36
36
  With a mobile section, the API answers the app's origins, `capacitor://localhost` on iOS and `https://localhost` on Android, through [CORS](../reference/api.md#cors). Apps without one get no new dependency, and `protobase build` and `protobase dev` work as before.
37
37
 
@@ -41,7 +41,7 @@ Signing in works in the app as on the web, with nothing more to set up:
41
41
  - The app calls `/api/auth` through the device's native HTTP, naming its Capacitor origin. With a mobile section, sign-in trusts the Capacitor origin a request names, for that request only, without CORS.
42
42
  - The session lives in the device's cookie store, so it survives reloads, updates and relaunches. On iOS, signing in or out within about a second of killing the app may be lost.
43
43
  - <gap>"Forgot password?" is not offered in the app, as the emailed link cannot lead back into it.</gap>
44
- - In the app, page script can reach the session cookie through Capacitor's native plugins, so keep untrusted script out of UI plugins.
44
+ - On Android, page script cannot reach the session cookie: Capacitor's `CapacitorHttp`, `CapacitorCookies` and `WebView` plugins are refused to it, and so are the app's local file routes. A plugin that reads files for its JavaScript, such as `@capacitor/filesystem`, could still hand the cookie over. <gap>On iOS, page script can still reach the session cookie through Capacitor's native plugins, as Protobase's native plugin is not implemented for iOS yet.</gap> There, keep untrusted script out of UI plugins.
45
45
  - While you develop over plain `http://localhost` with a mobile section, a page served on `https://localhost` in the same browser can send sign-in requests that carry your dev session, as some browsers treat the two as the same site. Do not open untrusted pages on `https://localhost` while you develop.
46
46
 
47
47
  ## 3. Run it
@@ -234,7 +234,7 @@ By default the bundle runs on Node and on Bun. `--bun` makes it a bundle for Bun
234
234
  - `server`, `public`, `nodeModules` and `migrations` are relative to the bundle folder; `spa`, `theme` and each plugin's `path` to `public`.
235
235
  - `plugins` are the bundle's own plugins, in the order the app merges them: the extensions', then the project's (`app`). Each names its `plugin.json`, the plugin API and Protobase versions it is built for, and the [field types](plugins.md#field-types) it registers with the storage types each shows, which the serve runtime checks the views against at startup. `/api/meta` names them to everyone, before any other plugin.
236
236
  - `shell` is the admin app `public/` holds a copy of: its Protobase version and plugin API, and its files as URL paths. A host with a shell of its own, of a release every plugin of the bundle loads in, may serve its own for those paths instead (see [The UI](#the-ui)), so the app gets that release's fixes without a rebuild.
237
- - `native` is the native packages, name to version, that `shell` runs on in the [mobile app](../guides/mobile-app.md): those `@protobase/mobile` pins. The fingerprint of the bundle's [mobile release](#mobile-releases) names them. A bundle built before it serves no mobile release.
237
+ - `native` is the native code, name to version, that `shell` runs on in the [mobile app](../guides/mobile-app.md): the native packages `@protobase/mobile` pins, and `@protobase/mobile` itself at its native contract, such as `native-1`, which Protobase raises when its own native code changes. The fingerprint of the bundle's [mobile release](#mobile-releases) names them. A bundle built before it serves no mobile release.
238
238
  - `theme` is the project's [theme](theme.md), which the app links at `/protobase.theme.css`. It is always there, empty when the project has none.
239
239
  - `nodeModules` is present only when the config module imports [native packages](#native-packages). It is always the `node_modules` folder beside `server`, where Bun and Node resolve the module's imports from, and holds plain packages: JavaScript, `package.json` files and native binaries for linux x64 and arm64 (glibc), which the runtime loads with `dlopen`. A host keeps it next to the server module and must not mount it `noexec` (an add-on there then fails with `failed to map segment from shared object`). Its binaries link nothing but glibc, `libstdc++.so.6`, `libgcc_s.so.1` and libraries in the bundle itself, so the run image must have those three. Without `nodeModules`, the server module is the only file the runtime reads.
240
240
  - `migrations` is present only when the project has a `db/migrations` folder: its `.sql` files, which the runtime's `migrate` applies (see [Deploy](../guides/deploy.md)). A host never serves it.
@@ -551,7 +551,7 @@ Builds the project in the current directory as an iOS or Android app with Capaci
551
551
  - `build` makes a signed release, an `.aab` (Android) or `.ipa` (iOS), and copies it to `--out`, which ignores itself in git when the command creates it, as `<appId>-<version>-<build number>`. Android signs through Gradle with the keystore, alias and passwords in `PROTOBASE_ANDROID_KEYSTORE`, `PROTOBASE_ANDROID_KEY_ALIAS`, `PROTOBASE_ANDROID_KEYSTORE_PASSWORD` and `PROTOBASE_ANDROID_KEY_PASSWORD`; iOS runs Capacitor's build with `--team`, and `--certificate` with `--profile` for manual signing.
552
552
  - A release calls an https server that is not this machine, and `--app-version` (one to three numbers) and `--build-number` (1 to 2100000000) are required.
553
553
  - 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.
554
- - 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, 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 keeps it; raise a plugin's version when the app's files start using a newer native feature of it, which changes it.
554
+ - 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.
555
555
  - The app's files carry the live updater's manifest of them, so an update downloads only the files that changed.
556
556
 
557
557
  ## `token`