@protobase/cli 0.45.4 → 0.45.6
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/app-id.js +14 -0
- package/dist/mobile/device-app-name.js +28 -0
- package/dist/mobile/mobile-config.js +2 -2
- package/dist/mobile/run.js +12 -4
- package/package.json +6 -6
- package/skills/protobase/references/guides/mobile-app.md +3 -1
- package/skills/protobase/references/reference/app-identity.md +1 -1
package/dist/cli/package.js
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/mobile/app-id.ts
|
|
2
|
+
const appIdPattern = /^[a-zA-Z][a-zA-Z0-9]*(?:\.[a-zA-Z][a-zA-Z0-9]*)+$/;
|
|
3
|
+
const suggestedAppId = (appId) => {
|
|
4
|
+
const suggestion = appId.split(".").map((segment) => segment.replace(/[^a-zA-Z0-9]/g, "").replace(/^[0-9]+/, "")).filter(Boolean).join(".");
|
|
5
|
+
return appIdPattern.test(suggestion) ? suggestion : "com.example.app";
|
|
6
|
+
};
|
|
7
|
+
/** Whether `appId` can be the app's id on both iOS and Android. */
|
|
8
|
+
const isAppId = (appId) => typeof appId === "string" && appIdPattern.test(appId);
|
|
9
|
+
/** Why `appId` cannot be the app's id on both iOS and Android, with a fixed id to use instead. */
|
|
10
|
+
const appIdProblem = (appId) => {
|
|
11
|
+
return `mobile.appId must be a reverse-DNS id that iOS and Android both accept: at least two parts separated by dots, each starting with a letter and holding only letters and digits (no underscores or hyphens), such as ${typeof appId === "string" ? suggestedAppId(appId) : "com.example.app"}, not ${JSON.stringify(appId)}`;
|
|
12
|
+
};
|
|
13
|
+
//#endregion
|
|
14
|
+
export { appIdProblem, isAppId };
|
|
@@ -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,8 +1,8 @@
|
|
|
1
1
|
import { pinnedProblem } from "./pinned-packages.js";
|
|
2
|
+
import { appIdProblem, isAppId } from "./app-id.js";
|
|
2
3
|
import { packageNameProblem } from "./package-name.js";
|
|
3
4
|
//#region src/mobile/mobile-config.ts
|
|
4
5
|
const noMobileSection = "This project has no mobile section: add `mobile: { appId: 'com.example.app' }` to the default export of protobase.config.ts";
|
|
5
|
-
const appIdPattern = /^[a-zA-Z][\w]*(?:\.[a-zA-Z][\w]*)+$/;
|
|
6
6
|
const unauthenticated = /^(?:http:|git:|git\+http:)/i;
|
|
7
7
|
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8
8
|
/** The project's `mobile` section, checked: an error says what to add or fix. */
|
|
@@ -10,7 +10,7 @@ const checkMobileConfig = (value) => {
|
|
|
10
10
|
if (value === void 0) throw new Error(noMobileSection);
|
|
11
11
|
if (!isRecord(value)) throw new Error("mobile in protobase.config.ts must be an object such as { appId: 'com.example.app' }");
|
|
12
12
|
const { appId, plugins } = value;
|
|
13
|
-
if (
|
|
13
|
+
if (!isAppId(appId)) throw new Error(appIdProblem(appId));
|
|
14
14
|
if (plugins === void 0) return { appId };
|
|
15
15
|
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
16
|
for (const [name, spec] of Object.entries(plugins)) {
|
package/dist/mobile/run.js
CHANGED
|
@@ -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
|
|
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.
|
|
3
|
+
"version": "0.45.6",
|
|
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.
|
|
40
|
-
"@protobase/query": "0.45.
|
|
41
|
-
"@protobase/schema": "0.45.
|
|
42
|
-
"@protobase/server": "0.45.
|
|
43
|
-
"@protobase/ui": "0.45.
|
|
39
|
+
"@protobase/layout": "0.45.6",
|
|
40
|
+
"@protobase/query": "0.45.6",
|
|
41
|
+
"@protobase/schema": "0.45.6",
|
|
42
|
+
"@protobase/server": "0.45.6",
|
|
43
|
+
"@protobase/ui": "0.45.6",
|
|
44
44
|
"@react-email/render": "^2.1.0",
|
|
45
45
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
46
46
|
"@tailwindcss/vite": "^4.3.3",
|
|
@@ -30,9 +30,11 @@ export default defineConfig({
|
|
|
30
30
|
})
|
|
31
31
|
```
|
|
32
32
|
|
|
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
|
|
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
|
+
|
|
36
38
|
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
39
|
|
|
38
40
|
Signing in works in the app as on the web, with nothing more to set up:
|
|
@@ -8,7 +8,7 @@ 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 |
|
|
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
12
|
| Icon | `protobase.favicon.svg` at the project's root | the browser tab, the sidebar's logo, the installed app's icon |
|
|
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 |
|