@protobase/cli 0.45.5 → 0.45.7

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.45.5";
2
+ var version = "0.45.7";
3
3
  //#endregion
4
4
  export { version };
@@ -0,0 +1,28 @@
1
+ import { shownAppName, webManifestPath } from "@protobase/server";
2
+ //#region src/mobile/device-app-name.ts
3
+ const manifestUrl = (url) => new URL(`/api${webManifestPath}`, url.origin);
4
+ const manifestName = async (url, fetchFn) => {
5
+ const response = await fetchFn(manifestUrl(url), { signal: AbortSignal.timeout(1e4) });
6
+ if (!response.ok || !response.headers.get("content-type")?.includes("json")) return void 0;
7
+ const { name } = await response.json();
8
+ return typeof name === "string" && name.trim() ? name : void 0;
9
+ };
10
+ const isUnreachable = (error) => error instanceof TypeError || error instanceof DOMException && error.name === "TimeoutError";
11
+ /**
12
+ * The name the installed app goes by on the device: the one its server names it with in the upper left, which the
13
+ * platform may set (`PROTOBASE_APP_NAME`) apart from the project. When the server answers no name or cannot be reached,
14
+ * a release stops, and any other build warns and takes the name the project gives itself.
15
+ */
16
+ const deviceAppName = async ({ url, auth, env, release, fetch: fetchFn = fetch, onWarning }) => {
17
+ const answered = await manifestName(url, fetchFn).catch((error) => {
18
+ if (!isUnreachable(error)) throw error;
19
+ });
20
+ if (answered) return answered;
21
+ const what = `${url.origin} answered no app name at ${manifestUrl(url).pathname}`;
22
+ if (release) throw new Error(`${what}, the name the release is installed under: build it against the app's running server`);
23
+ const own = shownAppName(auth, env);
24
+ onWarning(`${what}: the app is installed as "${own}", the name this project gives itself`);
25
+ return own;
26
+ };
27
+ //#endregion
28
+ export { deviceAppName };
@@ -1,11 +1,13 @@
1
1
  import { withLocalNetworking } from "./info-plist.js";
2
+ import { withProtobaseIcon } from "./native-icon.js";
2
3
  import path from "node:path";
3
4
  import { readFile, rm, writeFile } from "node:fs/promises";
4
5
  //#region src/mobile/generate.ts
5
6
  const infoPlist = (ws) => path.join(ws, "ios", "App", "App", "Info.plist");
6
7
  /**
7
8
  * Generates the platform's native project in the workspace from its capacitor.config.json and app files, replacing
8
- * the last one: it is never edited by hand. An iOS app calling the API over plain http may reach local addresses.
9
+ * the last one: it is never edited by hand. Its home-screen icon is Protobase's, and an iOS app calling the API over
10
+ * plain http may reach local addresses.
9
11
  */
10
12
  const generatePlatform = async (ws, platform, { cleartext }, cap) => {
11
13
  await rm(path.join(ws, platform), {
@@ -13,6 +15,7 @@ const generatePlatform = async (ws, platform, { cleartext }, cap) => {
13
15
  force: true
14
16
  });
15
17
  await cap(["add", platform]);
18
+ await withProtobaseIcon(ws, platform);
16
19
  if (platform !== "ios" || !cleartext) return;
17
20
  await writeFile(infoPlist(ws), withLocalNetworking(await readFile(infoPlist(ws), "utf8")));
18
21
  };
@@ -0,0 +1,39 @@
1
+ import { existsSync } from "node:fs";
2
+ import path from "node:path";
3
+ import { copyFile } from "node:fs/promises";
4
+ /**
5
+ * The template's home-screen icon files, by path in the platform's native project, which Protobase's icon replaces:
6
+ * iOS's one 1024 pixel icon; Android's legacy, round and adaptive foreground icons at each density, and the adaptive
7
+ * icon's background colour.
8
+ */
9
+ const nativeIconFiles = {
10
+ ios: ["App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-512@2x.png"],
11
+ android: [...[
12
+ "mdpi",
13
+ "hdpi",
14
+ "xhdpi",
15
+ "xxhdpi",
16
+ "xxxhdpi"
17
+ ].flatMap((density) => [
18
+ "ic_launcher",
19
+ "ic_launcher_round",
20
+ "ic_launcher_foreground"
21
+ ].map((icon) => `app/src/main/res/mipmap-${density}/${icon}.png`)), "app/src/main/res/values/ic_launcher_background.xml"]
22
+ };
23
+ /** Where @protobase/mobile, installed in the workspace `ws`, has Protobase's icon for the platform, by the same paths. */
24
+ const protobaseIconDir = (ws, platform) => path.join(ws, "node_modules", "@protobase", "mobile", "icon", platform);
25
+ /**
26
+ * Gives the platform's native project in the workspace Protobase's icon in place of Capacitor's. Each file must be one
27
+ * the template has, so a template that moves its icon fails here rather than leaving Capacitor's on the phone.
28
+ */
29
+ const withProtobaseIcon = async (ws, platform) => {
30
+ for (const file of nativeIconFiles[platform]) {
31
+ const from = path.join(protobaseIconDir(ws, platform), file);
32
+ const to = path.join(ws, platform, file);
33
+ if (!existsSync(from)) throw new Error(`@protobase/mobile has no ${path.join(platform, file)} of Protobase's icon`);
34
+ if (!existsSync(to)) throw new Error(`The generated ${platform} project has no ${file}, the icon Protobase's replaces`);
35
+ await copyFile(from, to);
36
+ }
37
+ };
38
+ //#endregion
39
+ export { nativeIconFiles, protobaseIconDir, withProtobaseIcon };
@@ -8,6 +8,7 @@ import { capacitorRunner } from "./capacitor.js";
8
8
  import { buildWebPart, placeholderWebPart } from "./web-part.js";
9
9
  import { capacitorConfig, writeCapacitorConfig } from "./capacitor-config.js";
10
10
  import { childEnv, envFileKeys, projectEnvFiles } from "./child-env.js";
11
+ import { deviceAppName } from "./device-app-name.js";
11
12
  import { generatePlatform } from "./generate.js";
12
13
  import { checkMobileConfig } from "./mobile-config.js";
13
14
  import { loadMobileProject } from "./load-project.js";
@@ -15,9 +16,8 @@ import { signForDevelopment } from "./development-signing.js";
15
16
  import { checkIosPlugins, checkProtobasePlugin, guardLiveUpdate } from "./protobase-plugin.js";
16
17
  import { mobileSpec, prepareWorkspace, workspaceDir, workspacePackageJson } from "./workspace.js";
17
18
  import path from "node:path";
18
- import { defaultAppName } from "@protobase/server";
19
19
  //#region src/mobile/run.ts
20
- const prepare = async ({ projectDir, platform, api, extensions, live, release }, { run = runChild, build }) => {
20
+ const prepare = async ({ projectDir, platform, api, extensions, live, release }, { run = runChild, build, fetch }) => {
21
21
  const env = withoutAndroidSigning(childEnv({ ...process.env }, envFileKeys(projectEnvFiles(projectDir))));
22
22
  if (live !== void 0 && api !== void 0) throw new Error("--live opens protobase dev, which serves the API itself: leave out --api");
23
23
  const project = await loadMobileProject(projectDir, extensions);
@@ -25,6 +25,15 @@ const prepare = async ({ projectDir, platform, api, extensions, live, release },
25
25
  const url = live === void 0 ? apiUrl(api, project.auth?.issuer, platform) : new URL(`http://localhost:${live}`);
26
26
  if (release) checkReleaseUrl(url);
27
27
  const allowances = httpAllowances(url);
28
+ const onWarning = (message) => void process.stderr.write(`warning: ${message}\n`);
29
+ const appName = await deviceAppName({
30
+ url,
31
+ auth: project.auth,
32
+ env: process.env,
33
+ ...release && { release },
34
+ ...fetch && { fetch },
35
+ onWarning
36
+ });
28
37
  const ws = workspaceDir(projectDir);
29
38
  const plugins = Object.keys(mobile.plugins ?? {});
30
39
  await prepareWorkspace(ws, workspacePackageJson({
@@ -42,11 +51,10 @@ const prepare = async ({ projectDir, platform, api, extensions, live, release },
42
51
  extensions,
43
52
  apiOrigin: url.origin,
44
53
  ...build && { build },
45
- onWarning: (message) => process.stderr.write(`warning: ${message}\n`)
54
+ onWarning
46
55
  });
47
56
  else await placeholderWebPart(ws);
48
57
  const fingerprint = nativeFingerprint(pinnedNative, mobile.plugins);
49
- const appName = project.auth?.appName ?? defaultAppName;
50
58
  await writeCapacitorConfig(ws, capacitorConfig({
51
59
  appId: mobile.appId,
52
60
  appName,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/cli",
3
- "version": "0.45.5",
3
+ "version": "0.45.7",
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.45.5",
40
- "@protobase/query": "0.45.5",
41
- "@protobase/schema": "0.45.5",
42
- "@protobase/server": "0.45.5",
43
- "@protobase/ui": "0.45.5",
39
+ "@protobase/layout": "0.45.7",
40
+ "@protobase/query": "0.45.7",
41
+ "@protobase/schema": "0.45.7",
42
+ "@protobase/server": "0.45.7",
43
+ "@protobase/ui": "0.45.7",
44
44
  "@react-email/render": "^2.1.0",
45
45
  "@scalar/hono-api-reference": "^0.12.10",
46
46
  "@tailwindcss/vite": "^4.3.3",
@@ -33,6 +33,10 @@ export default defineConfig({
33
33
  - `appId` is the app's id in reverse-DNS form, the same on iOS and Android: at least two parts separated by dots, each starting with a letter and holding only letters and digits. Underscores and hyphens are refused, as iOS rejects underscores and Android rejects hyphens; `protobase mobile` stops early on such an id and suggests one without them.
34
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
+ The app is installed under the name it shows in its upper left, on iOS and Android alike: `protobase mobile` reads it from the server the app calls (its web manifest), so a `PROTOBASE_APP_NAME` the server runs with names the app on the phone too. When that server cannot be reached, `run` and `open` warn and take the project's own name, `appName` or `PROTOBASE_APP_NAME` in its environment, and `build` stops.
37
+
38
+ On the home screen the app shows Protobase's icon, on iOS and Android alike. <gap>An app cannot show its own icon on the phone because setting the mobile app's icon is not implemented.</gap>
39
+
36
40
  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
41
 
38
42
  Signing in works in the app as on the web, with nothing more to set up:
@@ -8,8 +8,8 @@ An app looks like its own everywhere from three things in its project: its name,
8
8
 
9
9
  | What | Where | Used by |
10
10
  | --- | --- | --- |
11
- | Name | `appName` of `createAuth` ([auth configuration](auth.md#configuration)), overridden at run time by `PROTOBASE_APP_NAME` | the sidebar's logo, the end of every tab title, the installed app's name, passkey and authenticator prompts, auth mail and its sender's name |
12
- | Icon | `protobase.favicon.svg` at the project's root | the browser tab, the sidebar's logo, the installed app's icon |
11
+ | Name | `appName` of `createAuth` ([auth configuration](auth.md#configuration)), overridden at run time by `PROTOBASE_APP_NAME` | the sidebar's logo, the end of every tab title, the installed app's name, the [mobile app](../guides/mobile-app.md)'s name on the phone, passkey and authenticator prompts, auth mail and its sender's name |
12
+ | Icon | `protobase.favicon.svg` at the project's root | the browser tab, the sidebar's logo, the installed app's icon; the [mobile app](../guides/mobile-app.md) shows Protobase's icon instead |
13
13
  | Raster icons | optional PNGs beside the SVG, below | the iPhone home screen and Android launchers, which take no SVG |
14
14
  | Colours | `app` in `protobase.config.ts` | the installed app's title bar and its start screen |
15
15
 
@@ -599,7 +599,7 @@ export const repairsView = filtered
599
599
  | `l.section(title, fields, { help?, helpWhen?, presentation?, when? })` | A titled group of fields in the main column, editable where the user may write. `presentation: 'facts'` shows them on the read view as a row of [key facts](#key-facts). |
600
600
  | `l.group(title, items, { collapsed?, when? })` | A heading over sections and related tables, closed until opened with `collapsed: true`. `when` also takes a [condition](#form-and-read-view). See [Groups](#groups). |
601
601
  | `l.tab(title, items)` | A tab holding main-column items; a view's tabs show as one strip on the read view and the form. See [Tabs](#tabs). |
602
- | `l.sidebar(fields, { when? })` | A summary card beside it, read-only, each value on one line, cut off with an ellipsis when it does not fit and shown whole on hover. `when` also takes a [condition](#form-and-read-view). |
602
+ | `l.sidebar(fields, { when? })` | A summary card beside it, read-only, each value on one line, cut off with an ellipsis when it does not fit and shown whole on hover. The record's created and updated times show in a Details card below it, but for those the summary lists. `when` also takes a [condition](#form-and-read-view). |
603
603
  | `l.related(title, { ... })` | A table or cards of the records of another resource that point at this one, in the main column. See [Related records](#related-records). |
604
604
  | `l.custom(Component, { title?, props?, sidebar?, when? })` | A [custom component](custom-components.md#record-sections) where it is listed: in the main column under `title`, or with `sidebar: true` as a sidebar card. |
605
605
  | `l.map(title, { latitude, longitude, zoom?, sidebar?, when? })` | A map with a pin at the record's position, in the main column or with `sidebar: true` as a sidebar card. See [Maps](#maps). |