@protobase/cli 0.44.4 → 0.45.0
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 +17 -6
- package/dist/mobile/protobase-plugin.js +24 -0
- package/dist/mobile/run.js +5 -1
- package/package.json +6 -6
- package/skills/protobase/references/guides/mobile-app.md +2 -2
- package/skills/protobase/references/reference/auth.md +1 -1
package/dist/cli/package.js
CHANGED
|
@@ -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),
|
|
7
|
-
*
|
|
8
|
-
*
|
|
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
|
-
|
|
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) => {
|
|
@@ -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 };
|
package/dist/mobile/run.js
CHANGED
|
@@ -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.
|
|
3
|
+
"version": "0.45.0",
|
|
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.
|
|
40
|
-
"@protobase/query": "0.
|
|
41
|
-
"@protobase/schema": "0.
|
|
42
|
-
"@protobase/server": "0.
|
|
43
|
-
"@protobase/ui": "0.
|
|
39
|
+
"@protobase/layout": "0.45.0",
|
|
40
|
+
"@protobase/query": "0.45.0",
|
|
41
|
+
"@protobase/schema": "0.45.0",
|
|
42
|
+
"@protobase/server": "0.45.0",
|
|
43
|
+
"@protobase/ui": "0.45.0",
|
|
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
|
-
-
|
|
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
|
|
@@ -441,7 +441,7 @@ It is Better Auth's organization plugin, with its tables named in snake_case (`o
|
|
|
441
441
|
|
|
442
442
|
**The organization in the token.** A new session starts in the organization the person last worked in, else their oldest membership. `/api/auth/token` adds `org` (the organization), `org_role` and `app_roles` (the membership's, narrowed to the active role), read when the token is issued; a removed member's token, or one carrying an app role taken away, [stops working](#when-a-token-stops-working) on its next request. `betterAuthAuthenticator` makes `org` the tenant and `ctx.organization.id`, and adds `app_roles` to the global roles. `POST /api/auth/organization/switch` with `{ organizationId }` moves the session; the next token names the new organization, without signing in again. Someone with a global role may switch into any organization, without being a member, and sees there what those roles allow; each such entry is an `organization.entered` [audit event](api.md#audit-events). `GET /api/auth/organization/search?query=&offset=` lists every organization for them, ordered by slug, 20 at a time with the `total`, narrowed by text in the name or slug; the Organizations page shows it as All organizations. A list across organizations stays a resource without `.tenant`, readable by the global role.
|
|
443
443
|
|
|
444
|
-
**Invitations.** Better Auth's `POST /api/auth/organization/invite-member` with `{ organizationId, email, role, appRoles }`; inviting again replaces the earlier invitation, and it works for `invitationDays` (default 7). The email links to `{baseURL}/-/invitation?token=…` (`invitationUrl`), with a token signed with `secret`, since members can read invitation ids; without a mailer, the answer carries the `link` to pass on. The link page shows `GET /api/auth/invitation?token=`, accepts with `POST /api/auth/invitation/accept` for someone signed in as the invited address, and makes an account with `POST /api/auth/invitation/sign-up` (`{ token, name, password? }`) for an address without one. The link page and its sign-up serve [invitations to the app](#users-page) too. [Open sign-up](#open-sign-up) is not available with organizations: an invitation is the address someone vouched for.
|
|
444
|
+
**Invitations.** Better Auth's `POST /api/auth/organization/invite-member` with `{ organizationId, email, role, appRoles }`; inviting again replaces the earlier invitation, and it works for `invitationDays` (default 7). The email links to `{baseURL}/-/invitation?token=…` (`invitationUrl`), with a token signed with `secret`, since members can read invitation ids; without a mailer, the answer carries the `link` to pass on. The link page shows `GET /api/auth/invitation?token=`, accepts with `POST /api/auth/invitation/accept` for someone signed in as the invited address, and makes an account with `POST /api/auth/invitation/sign-up` (`{ token, name, password? }`) for an address without one. Someone signed in sees the invitations for their own address with Better Auth's `GET /api/auth/organization/list-user-invitations`, on the organizations page, and accepts one there with `POST /api/auth/invitation/accept-own` (`{ invitationId }`). The link page and its sign-up serve [invitations to the app](#users-page) too. [Open sign-up](#open-sign-up) is not available with organizations: an invitation is the address someone vouched for.
|
|
445
445
|
|
|
446
446
|
**Members.** Better Auth's `list-members`, `update-member-role`, `remove-member` and `leave`; `POST /api/auth/organization/set-app-roles` (`{ memberId, appRoles }`); `POST /api/auth/organization/transfer-ownership` (`{ memberId, keepAs? }`) makes a member owner and the caller an admin in one step. `GET /api/auth/organization/current` answers the organization a session works in with the caller's roles there.
|
|
447
447
|
|