@protobase/cli 0.44.3 → 0.44.5

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.3";
2
+ var version = "0.44.5";
3
3
  //#endregion
4
4
  export { version };
@@ -0,0 +1,11 @@
1
+ import { execFile } from "node:child_process";
2
+ import { promisify } from "node:util";
3
+ //#region src/mobile/capture-child.ts
4
+ /** Runs `command` with `args` as given, never through a shell, in `cwd` with exactly `env`, and gives its stdout. */
5
+ const captureChild = async (command, args, { cwd, env }) => (await promisify(execFile)(command, args, {
6
+ cwd,
7
+ env,
8
+ encoding: "utf8"
9
+ })).stdout;
10
+ //#endregion
11
+ export { captureChild };
@@ -0,0 +1,24 @@
1
+ import { runChild } from "./child-process.js";
2
+ import { captureChild } from "./capture-child.js";
3
+ import { withDevelopmentTeam } from "./development-team.js";
4
+ import { connectedDevice, listIosTargets, provisioningBuildArgs } from "./ios-device.js";
5
+ import path from "node:path";
6
+ import { readFile, writeFile } from "node:fs/promises";
7
+ //#region src/mobile/development-signing.ts
8
+ /**
9
+ * Signs the iOS project `cap add` generated in `ws` for development by `team`, on every run since the project is
10
+ * generated anew, and builds it once for the target, the connected device without one, letting Xcode create the
11
+ * development profile. Gives the target for `cap run`.
12
+ */
13
+ const signForDevelopment = async ({ ws, env, team, target }, { run = runChild, capture = captureChild }) => {
14
+ const pbxproj = path.join(ws, "ios", "App", "App.xcodeproj", "project.pbxproj");
15
+ await writeFile(pbxproj, withDevelopmentTeam(await readFile(pbxproj, "utf8"), team));
16
+ const chosen = target ?? connectedDevice(await listIosTargets(ws, env, capture));
17
+ await run("xcrun", provisioningBuildArgs(ws, chosen), {
18
+ cwd: path.join(ws, "ios", "App"),
19
+ env
20
+ });
21
+ return chosen;
22
+ };
23
+ //#endregion
24
+ export { signForDevelopment };
@@ -0,0 +1,11 @@
1
+ //#region src/mobile/development-team.ts
2
+ const anchor = "CODE_SIGN_STYLE = Automatic;";
3
+ /** The project.pbxproj with `team` as the app target's DEVELOPMENT_TEAM, a team id `--team` checked. */
4
+ const withDevelopmentTeam = (pbxproj, team) => {
5
+ if (pbxproj.includes("DEVELOPMENT_TEAM")) throw new Error("project.pbxproj already names a DEVELOPMENT_TEAM, unlike Capacitor's template");
6
+ const parts = pbxproj.split(anchor);
7
+ if (parts.length !== 3) throw new Error(`project.pbxproj has \`${anchor}\` ${parts.length - 1} times, not 2 as in Capacitor's template`);
8
+ return parts.join(`${anchor}\n\t\t\t\tDEVELOPMENT_TEAM = ${team};`);
9
+ };
10
+ //#endregion
11
+ export { withDevelopmentTeam };
@@ -0,0 +1,47 @@
1
+ import { installedPackage } from "./installed-package.js";
2
+ import path from "node:path";
3
+ //#region src/mobile/ios-device.ts
4
+ /** The connected iPhone or iPad in native-run's `ios --list --json`, the list `cap run` picks its target from. */
5
+ const connectedDevice = (list) => {
6
+ const { devices } = JSON.parse(list);
7
+ const [device, ...more] = devices;
8
+ if (!device) throw new Error("--team signs the app for an iPhone, and none is connected: connect it and unlock it, or pass --target");
9
+ if (more.length > 0) throw new Error(`Several devices are connected: pass --target with one of ${devices.map(({ id, name }) => `${id} (${name ?? "unnamed"})`).join(", ")}`);
10
+ return device.id;
11
+ };
12
+ /** Lists the iOS targets with the workspace's own native-run, the one Capacitor runs. */
13
+ const listIosTargets = (ws, env, capture) => {
14
+ const { bin } = installedPackage(ws, "native-run");
15
+ if (!bin?.["native-run"]) throw new Error(`${path.join(ws, "node_modules", "native-run")} has no native-run command`);
16
+ return capture("node", [
17
+ path.join(ws, "node_modules", "native-run", bin["native-run"]),
18
+ "ios",
19
+ "--list",
20
+ "--json"
21
+ ], {
22
+ cwd: ws,
23
+ env
24
+ });
25
+ };
26
+ /**
27
+ * xcodebuild's arguments for the build `cap run ios --target <target>` makes, the same destination and derived data so
28
+ * Capacitor's own build after it has nothing left to do, but allowed to create the team's development profile and
29
+ * register the device with it, which Capacitor's build is not.
30
+ */
31
+ const provisioningBuildArgs = (ws, target) => [
32
+ "xcodebuild",
33
+ "-project",
34
+ "App.xcodeproj",
35
+ "-scheme",
36
+ "App",
37
+ "-configuration",
38
+ "Debug",
39
+ "-destination",
40
+ `id=${target}`,
41
+ "-derivedDataPath",
42
+ path.join(ws, "ios", "DerivedData", target),
43
+ "-allowProvisioningUpdates",
44
+ "-allowProvisioningDeviceRegistration"
45
+ ];
46
+ //#endregion
47
+ export { connectedDevice, listIosTargets, provisioningBuildArgs };
@@ -9,7 +9,7 @@ const registerMobile = (program) => {
9
9
  const api = "--api <url>";
10
10
  const apiHelp = "the server the app calls (default: the auth issuer, the project's baseURL)";
11
11
  const extend = "merge the protobase.config.ts and protobase.ui.tsx in this folder before the project's, repeatable";
12
- mobile.command("run").description("Generate the native project and run the app in a simulator, an emulator or on a device").argument("<platform>", "ios or android", parsePlatform).option(api, apiHelp).option("--target <id>", "the device or simulator to run on (default: Capacitor asks)").option("--live", "open the running protobase dev instead of the app's own files, reloading as you save", false).option("--port <port>", "the port of protobase dev, for --live", parsePort, 5173).option("--extend <dir>", extend, collect, []).action(async (chosen, opts) => {
12
+ mobile.command("run").description("Generate the native project and run the app in a simulator, an emulator or on a device").argument("<platform>", "ios or android", parsePlatform).option(api, apiHelp).option("--target <id>", "the device or simulator to run on (default: Capacitor asks)").option("--team <id>", "iOS: your Apple Developer team id, which signs the app to run on your iPhone", parseTeamId).option("--live", "open the running protobase dev instead of the app's own files, reloading as you save", false).option("--port <port>", "the port of protobase dev, for --live", parsePort, 5173).option("--extend <dir>", extend, collect, []).action(async (chosen, opts) => {
13
13
  const { mobileRun } = await import("./run.js");
14
14
  await mobileRun({
15
15
  projectDir: process.cwd(),
@@ -17,6 +17,7 @@ const registerMobile = (program) => {
17
17
  extensions: resolveExtensions(opts.extend),
18
18
  ...opts.api !== void 0 && { api: opts.api },
19
19
  ...opts.target && { target: opts.target },
20
+ ...opts.team && { team: opts.team },
20
21
  ...opts.live && { live: opts.port }
21
22
  }, out);
22
23
  });
@@ -11,6 +11,7 @@ import { childEnv, envFileKeys, projectEnvFiles } from "./child-env.js";
11
11
  import { generatePlatform } from "./generate.js";
12
12
  import { checkMobileConfig } from "./mobile-config.js";
13
13
  import { loadMobileProject } from "./load-project.js";
14
+ import { signForDevelopment } from "./development-signing.js";
14
15
  import { mobileSpec, prepareWorkspace, workspaceDir, workspacePackageJson } from "./workspace.js";
15
16
  import path from "node:path";
16
17
  import { defaultAppName } from "@protobase/server";
@@ -65,12 +66,19 @@ const prepare = async ({ projectDir, platform, api, extensions, live, release },
65
66
  const summary = (projectDir, { ws, url, fingerprint }) => `workspace ${path.relative(projectDir, ws)}, api ${url.origin}, native fingerprint ${fingerprint}\n`;
66
67
  /** `protobase mobile run`: generates the native project and runs the app on a simulator, emulator or device. */
67
68
  const mobileRun = async (input, out, deps = {}) => {
69
+ if (input.platform === "android" && input.team) throw new Error("--team is for iOS: Android runs the app signed with its debug key");
68
70
  const prepared = await prepare(input, deps);
69
71
  out(summary(input.projectDir, prepared));
72
+ const target = input.team ? await signForDevelopment({
73
+ ws: prepared.ws,
74
+ env: prepared.env,
75
+ team: input.team,
76
+ ...input.target && { target: input.target }
77
+ }, deps) : input.target;
70
78
  await prepared.cap(capRunArgs({
71
79
  platform: input.platform,
72
80
  url: prepared.url,
73
- ...input.target && { target: input.target },
81
+ ...target && { target },
74
82
  ...input.live !== void 0 && { live: input.live }
75
83
  }));
76
84
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/cli",
3
- "version": "0.44.3",
3
+ "version": "0.44.5",
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.3",
40
- "@protobase/query": "0.44.3",
41
- "@protobase/schema": "0.44.3",
42
- "@protobase/server": "0.44.3",
43
- "@protobase/ui": "0.44.3",
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",
44
44
  "@react-email/render": "^2.1.0",
45
45
  "@scalar/hono-api-reference": "^0.12.10",
46
46
  "@tailwindcss/vite": "^4.3.3",
@@ -19,4 +19,4 @@ Develop, build and run an app, on servers, in containers and on phones.
19
19
  - [Separate worker](../reference/cli.md#worker): Jobs and event delivery in their own process.
20
20
  - [Container images](../guides/deploy.md#images): A runtime image for each release, for amd64 and arm64.
21
21
  - [Self-hosted image](../guides/deploy.md#a-self-hosted-image): One image with the app inside that serves, migrates and creates the first admin.
22
- - [Mobile apps](../guides/mobile-app.md) (beta): Runs an app on iOS and Android, with sign-in, and builds signed store releases from a section in its config.
22
+ - [Mobile apps](../guides/mobile-app.md) (beta): Runs an app on iOS and Android, also on your own iPhone, with sign-in, and builds signed store releases from a section in its config.
@@ -59,6 +59,14 @@ The app calls the server at the project's auth `baseURL`; pass `--api https://sh
59
59
 
60
60
  `--target <id>` picks the simulator, emulator or device; without it Capacitor asks.
61
61
 
62
+ To run on your iPhone, connect it, turn on its Developer Mode and pass your Apple team id, from a paid Apple Developer membership or the free personal team of the Apple ID you added in Xcode's settings:
63
+
64
+ ```sh
65
+ protobase mobile run ios --team ABCDE12345
66
+ ```
67
+
68
+ Every run signs the app for development with that team, letting Xcode create the profile and register the phone, and installs it on the connected iPhone, or on `--target` when several are connected. The first time, trust your developer certificate on the phone in Settings, General, VPN & Device Management. A free team signs only an `appId` no one else has taken.
69
+
62
70
  ## 4. Live reload
63
71
 
64
72
  ```sh
@@ -74,7 +82,7 @@ With `--live` the app opens the running `protobase dev` instead of its own files
74
82
  protobase mobile open ios
75
83
  ```
76
84
 
77
- opens the generated project in Xcode, or Android Studio for `android`. To run on an iPhone, pick a signing team in Xcode's Signing & Capabilities.
85
+ opens the generated project in Xcode, or Android Studio for `android`. To run it from Xcode on an iPhone, pick a signing team in Signing & Capabilities, or use `protobase mobile run ios --team`.
78
86
 
79
87
  ## 6. Build a release
80
88
 
@@ -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
 
@@ -537,7 +537,7 @@ Remove `supabase-import/` to import again.
537
537
  ## `mobile`
538
538
 
539
539
  ```sh
540
- protobase mobile run <ios|android> [--api <url>] [--target <id>] [--live] [--port 5173] [--extend <dir>]
540
+ protobase mobile run <ios|android> [--api <url>] [--target <id>] [--team <id>] [--live] [--port 5173] [--extend <dir>]
541
541
  protobase mobile open <ios|android> [--api <url>] [--extend <dir>]
542
542
  protobase mobile build <ios|android> --app-version <x.y.z> --build-number <n> [--api <url>] [--out mobile-release] [--extend <dir>]
543
543
  [--team <id> [--certificate <name> --profile <name>]]
@@ -547,7 +547,7 @@ Builds the project in the current directory as an iOS or Android app with Capaci
547
547
 
548
548
  - It installs `@protobase/mobile`, of the CLI's version, which pins Capacitor and its plugins, with the section's `plugins` into `.protobase/mobile/` with npm, when that changed. It builds the app's files as [`build`](#build) does and keeps only `public/`, its `index.html` naming the API origin; writes `capacitor.config.json`, compiling in only the section's plugins; and generates the platform's native project again, replacing the last one.
549
549
  - `--api` is the server the app calls, the project's auth `baseURL` by default: an http or https origin, plain http only to `localhost`, `127.0.0.1` and, on iOS, `[::1]`, or on Android `10.0.2.2`. An Android app calling `localhost` gets the port forwarded.
550
- - `run` runs the app on `--target`, or asks for one. With `--live` it opens `protobase dev` on `localhost:--port` instead of its own files. `open` opens the native project in Xcode or Android Studio.
550
+ - `run` runs the app on `--target`, or asks for one. On iOS, `--team` writes the Apple team id into the generated project and builds it once with xcodebuild allowed to create the development profile and register the device, `--target` or the one connected device, before Capacitor runs it there. With `--live` it opens `protobase dev` on `localhost:--port` instead of its own files. `open` opens the native project in Xcode or Android Studio.
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.