@protobase/cli 0.40.9 → 0.41.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.
Files changed (52) hide show
  1. package/dist/build/deploy-bundle.js +2 -0
  2. package/dist/bundle/manifest.js +4 -1
  3. package/dist/cli/package.js +1 -1
  4. package/dist/mobile/api-origin-page.js +11 -0
  5. package/dist/mobile/fingerprint.js +13 -7
  6. package/dist/mobile/pinned-packages.js +7 -2
  7. package/dist/mobile/run.js +3 -7
  8. package/dist/mobile/web-part.js +17 -10
  9. package/dist/serve/app.js +3 -2
  10. package/dist/serve/bundle-site.js +2 -1
  11. package/dist/serve/env.js +4 -1
  12. package/dist/serve/lifecycle.js +14 -1
  13. package/dist/serve/mobile-release.js +41 -0
  14. package/dist/serve/serve-dir.js +5 -1
  15. package/dist/serve/site-files.js +21 -0
  16. package/dist/serve/static-site.js +6 -3
  17. package/package.json +6 -6
  18. package/skills/protobase/SKILL.md +1 -0
  19. package/skills/protobase/references/features/access.md +17 -0
  20. package/skills/protobase/references/features/actions.md +11 -0
  21. package/skills/protobase/references/features/ai.md +14 -0
  22. package/skills/protobase/references/features/api-functions.md +13 -0
  23. package/skills/protobase/references/features/build-and-run.md +22 -0
  24. package/skills/protobase/references/features/compatibility.md +14 -0
  25. package/skills/protobase/references/features/composed-pages.md +18 -0
  26. package/skills/protobase/references/features/data-model.md +22 -0
  27. package/skills/protobase/references/features/email-and-public-forms.md +12 -0
  28. package/skills/protobase/references/features/events-webhooks-and-jobs.md +18 -0
  29. package/skills/protobase/references/features/files-and-images.md +16 -0
  30. package/skills/protobase/references/features/history-comments-and-live-updates.md +14 -0
  31. package/skills/protobase/references/features/list-displays.md +18 -0
  32. package/skills/protobase/references/features/lists.md +28 -0
  33. package/skills/protobase/references/features/look-and-language.md +13 -0
  34. package/skills/protobase/references/features/navigation.md +14 -0
  35. package/skills/protobase/references/features/record-pages.md +20 -0
  36. package/skills/protobase/references/features/releases.md +12 -0
  37. package/skills/protobase/references/features/rest-api.md +24 -0
  38. package/skills/protobase/references/features/several-apps.md +8 -0
  39. package/skills/protobase/references/features/sign-in-and-accounts.md +27 -0
  40. package/skills/protobase/references/features/start-a-project.md +15 -0
  41. package/skills/protobase/references/features/your-own-code.md +19 -0
  42. package/skills/protobase/references/features.md +39 -0
  43. package/skills/protobase/references/getting-started.md +6 -2
  44. package/skills/protobase/references/guides/deploy.md +5 -1
  45. package/skills/protobase/references/guides/mobile-app.md +4 -0
  46. package/skills/protobase/references/reference/access.md +2 -0
  47. package/skills/protobase/references/reference/api.md +1 -1
  48. package/skills/protobase/references/reference/cli.md +16 -2
  49. package/skills/protobase/references/reference/data-config.md +12 -4
  50. package/skills/protobase/references/reference/files.md +4 -0
  51. package/skills/protobase/references/reference/mcp.md +10 -2
  52. package/skills/protobase/references/reference/versioning.md +5 -1
@@ -10,6 +10,7 @@ import { buildIcons } from "./app-icons.js";
10
10
  import { checkUi } from "./ui-check.js";
11
11
  import { checkViews } from "./view-check.js";
12
12
  import { protobaseFolder } from "../project/protobase-folder.js";
13
+ import { pinnedNative } from "../mobile/pinned-packages.js";
13
14
  import { existsSync } from "node:fs";
14
15
  import path from "node:path";
15
16
  import { cp, readFile, rm, writeFile } from "node:fs/promises";
@@ -87,6 +88,7 @@ const buildDeployBundle = async ({ projectDir, outDir, bun, extensions = [], sou
87
88
  plugins,
88
89
  shell,
89
90
  icons,
91
+ native: pinnedNative,
90
92
  ...packages.length > 0 ? { nodeModules: bundleNodeModules } : {},
91
93
  ...migrations ? { migrations } : {}
92
94
  };
@@ -19,15 +19,17 @@ const isObject = (value) => typeof value === "object" && value !== null && !Arra
19
19
  const isFieldTypes = (value) => isObject(value) && Object.values(value).every(isStringList);
20
20
  const isPlugin = (value) => isObject(value) && typeof value.name === "string" && typeof value.path === "string" && Number.isInteger(value.api) && typeof value.protobase === "string" && (value.fields === void 0 || isFieldTypes(value.fields));
21
21
  const isShell = (value) => isObject(value) && typeof value.protobase === "string" && Number.isInteger(value.pluginApi) && isStringList(value.paths);
22
+ const isVersions = (value) => isObject(value) && Object.values(value).every((item) => typeof item === "string");
22
23
  const isIcons = (value) => isObject(value) && typeof value.favicon === "boolean" && isStringList(value.png) && value.png.every((icon) => icon in pngIcons);
23
24
  const parseManifest = (value, file) => {
24
25
  const manifest = value;
25
26
  if (manifest?.version !== 3) throw new Error(`${file} is not a version 3 bundle manifest; rebuild it with \`protobase build\``);
26
- const { server, public: publicDir, api, spa, plugins, theme, shell, icons, nodeModules, migrations } = manifest;
27
+ const { server, public: publicDir, api, spa, plugins, theme, shell, icons, native, nodeModules, migrations } = manifest;
27
28
  if (typeof server !== "string" || typeof publicDir !== "string" || typeof spa !== "string" || typeof theme !== "string" || !isStringList(api)) throw new Error(`${file} needs server, public, spa and theme paths and an api list`);
28
29
  if (!Array.isArray(plugins) || !plugins.every(isPlugin)) throw new Error(`${file} needs a plugins list, each with a name, path, api and protobase`);
29
30
  if (!isShell(shell)) throw new Error(`${file} needs a shell with its protobase version, pluginApi and paths`);
30
31
  if (icons !== void 0 && !isIcons(icons)) throw new Error(`${file} has icons that are not a favicon flag and a list of PNG icons`);
32
+ if (native !== void 0 && !isVersions(native)) throw new Error(`${file} has a native that is not a map of package names to versions`);
31
33
  if (nodeModules !== void 0 && typeof nodeModules !== "string") throw new Error(`${file} has a nodeModules that is no path`);
32
34
  if (migrations !== void 0 && typeof migrations !== "string") throw new Error(`${file} has a migrations that is no path`);
33
35
  return {
@@ -40,6 +42,7 @@ const parseManifest = (value, file) => {
40
42
  theme,
41
43
  shell,
42
44
  ...icons && { icons },
45
+ ...native && { native },
43
46
  ...nodeModules === void 0 ? {} : { nodeModules },
44
47
  ...migrations === void 0 ? {} : { migrations }
45
48
  };
@@ -1,4 +1,4 @@
1
1
  //#region package.json
2
- var version = "0.40.9";
2
+ var version = "0.41.0";
3
3
  //#endregion
4
4
  export { version };
@@ -0,0 +1,11 @@
1
+ import { apiOriginMeta } from "@protobase/schema/internal";
2
+ //#region src/mobile/api-origin-page.ts
3
+ const escapeAttribute = (value) => value.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
4
+ /** The page naming the API origin the shell calls, in the `<meta>` tag the shell reads (see `apiOriginMeta`). */
5
+ const withApiOrigin = (html, origin) => {
6
+ const at = html.indexOf("</head>");
7
+ if (at < 0) throw new Error("The shell's index.html has no </head> to name the API origin in");
8
+ return `${html.slice(0, at)}<meta name="${apiOriginMeta}" content="${escapeAttribute(origin)}">${html.slice(at)}`;
9
+ };
10
+ //#endregion
11
+ export { withApiOrigin };
@@ -1,12 +1,18 @@
1
1
  import { createHash } from "node:crypto";
2
2
  //#region src/mobile/fingerprint.ts
3
- /** Names the app's native code: the same for two builds only when they compile in the same native packages. */
4
- const nativeFingerprint = ({ mobile, plugins }) => {
5
- const sorted = [...plugins].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
6
- return createHash("sha256").update(JSON.stringify({
7
- mobile,
8
- plugins: sorted
9
- })).digest("hex").slice(0, 16);
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.
9
+ */
10
+ const nativeFingerprint = (pinned, plugins = {}) => {
11
+ const entries = Object.entries({
12
+ ...pinned,
13
+ ...plugins
14
+ }).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
15
+ return createHash("sha256").update(JSON.stringify(entries)).digest("hex").slice(0, 16);
10
16
  };
11
17
  //#endregion
12
18
  export { nativeFingerprint };
@@ -1,5 +1,5 @@
1
- import { installedPackage } from "./installed-package.js";
2
1
  import { dependencies, name } from "./package.js";
2
+ import { installedPackage } from "./installed-package.js";
3
3
  //#region src/mobile/pinned-packages.ts
4
4
  /**
5
5
  * The packages @protobase/mobile pins, itself included, which `mobile.plugins` may neither pin again nor compile into
@@ -7,6 +7,11 @@ import { dependencies, name } from "./package.js";
7
7
  * @protobase/mobile of its own version, the one it installs.
8
8
  */
9
9
  const pinnedPackages = /* @__PURE__ */ new Set([name, ...Object.keys(dependencies)]);
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.
13
+ */
14
+ const pinnedNative = Object.fromEntries(Object.entries(dependencies).filter(([name]) => !name.startsWith("@protobase/")));
10
15
  const liveUpdate = "@capawesome/capacitor-live-update";
11
16
  /** Why the plugin `key`, a package that is or names `name`, may not be listed; `undefined` when it may. */
12
17
  const pinnedProblem = (key, name = key) => {
@@ -24,4 +29,4 @@ const checkInstalledPlugins = (dir, keys) => {
24
29
  }
25
30
  };
26
31
  //#endregion
27
- export { checkInstalledPlugins, pinnedPackages, pinnedProblem };
32
+ export { checkInstalledPlugins, pinnedNative, pinnedPackages, pinnedProblem };
@@ -1,15 +1,14 @@
1
+ import { checkInstalledPlugins, pinnedNative } from "./pinned-packages.js";
2
+ import { nativeFingerprint } from "./fingerprint.js";
1
3
  import { withoutAndroidSigning } from "./android-signing.js";
2
4
  import { runChild } from "./child-process.js";
3
5
  import { apiUrl, checkReleaseUrl, httpAllowances } from "./api-origin.js";
4
6
  import { capRunArgs } from "./cap-run-args.js";
5
- import { installedPackage } from "./installed-package.js";
6
7
  import { capacitorRunner } from "./capacitor.js";
7
8
  import { buildWebPart, placeholderWebPart } from "./web-part.js";
8
9
  import { capacitorConfig, writeCapacitorConfig } from "./capacitor-config.js";
9
10
  import { childEnv, envFileKeys, projectEnvFiles } from "./child-env.js";
10
- import { nativeFingerprint } from "./fingerprint.js";
11
11
  import { generatePlatform } from "./generate.js";
12
- import { checkInstalledPlugins } from "./pinned-packages.js";
13
12
  import { checkMobileConfig } from "./mobile-config.js";
14
13
  import { loadMobileProject } from "./load-project.js";
15
14
  import { mobileSpec, prepareWorkspace, workspaceDir, workspacePackageJson } from "./workspace.js";
@@ -43,10 +42,7 @@ const prepare = async ({ projectDir, platform, api, extensions, live, release },
43
42
  onWarning: (message) => process.stderr.write(`warning: ${message}\n`)
44
43
  });
45
44
  else await placeholderWebPart(ws);
46
- const fingerprint = nativeFingerprint({
47
- mobile: installedPackage(ws, "@protobase/mobile").version,
48
- plugins: plugins.map((key) => [key, installedPackage(ws, key).version])
49
- });
45
+ const fingerprint = nativeFingerprint(pinnedNative, mobile.plugins);
50
46
  const appName = project.auth?.appName ?? defaultAppName;
51
47
  await writeCapacitorConfig(ws, capacitorConfig({
52
48
  appId: mobile.appId,
@@ -1,19 +1,25 @@
1
1
  import { bundleLayout } from "../bundle/manifest.js";
2
2
  import { buildDeployBundle } from "../build/deploy-bundle.js";
3
+ import { withApiOrigin } from "./api-origin-page.js";
4
+ import { siteFiles } from "../serve/site-files.js";
3
5
  import path from "node:path";
4
6
  import { cp, mkdir, readFile, rm, writeFile } from "node:fs/promises";
5
- import { apiOriginMeta } from "@protobase/schema/internal";
6
- const escapeAttribute = (value) => value.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
7
- /** The page naming the API origin the shell calls, in the `<meta>` tag the shell reads (see `apiOriginMeta`). */
8
- const withApiOrigin = (html, origin) => {
9
- const at = html.indexOf("</head>");
10
- if (at < 0) throw new Error("The shell's index.html has no </head> to name the API origin in");
11
- return `${html.slice(0, at)}<meta name="${apiOriginMeta}" content="${escapeAttribute(origin)}">${html.slice(at)}`;
7
+ import { releaseManifest } from "@protobase/server";
8
+ import { releaseManifestFile } from "@protobase/schema/internal";
9
+ const writeReleaseManifest = async (web) => {
10
+ const files = await Promise.all((await siteFiles({
11
+ publicDir: web,
12
+ spa: bundleLayout.spa
13
+ })).map(async ({ href, file }) => ({
14
+ href,
15
+ content: new Uint8Array(await readFile(file))
16
+ })));
17
+ await writeFile(path.join(web, releaseManifestFile), JSON.stringify(releaseManifest(files)));
12
18
  };
13
19
  /**
14
20
  * The app's files: the deploy bundle's `public/` (the shell, the project's UI plugins, theme and favicon), its
15
- * index.html naming the API origin. The bundle is built beside it and removed, so its server config module and
16
- * packages never sit where Capacitor copies from.
21
+ * index.html naming the API origin, and the updater's manifest of them. The bundle is built beside it and removed, so
22
+ * its server config module and packages never sit where Capacitor copies from.
17
23
  */
18
24
  const buildWebPart = async ({ projectDir, ws, extensions, apiOrigin, build = buildDeployBundle, onWarning }) => {
19
25
  const bundle = path.join(ws, "bundle");
@@ -39,6 +45,7 @@ const buildWebPart = async ({ projectDir, ws, extensions, apiOrigin, build = bui
39
45
  });
40
46
  const index = path.join(web, bundleLayout.spa);
41
47
  await writeFile(index, withApiOrigin(await readFile(index, "utf8"), apiOrigin));
48
+ await writeReleaseManifest(web);
42
49
  };
43
50
  /** A stand-in for the app's files with `--live`, where the app opens `protobase dev` and never shows them. */
44
51
  const placeholderWebPart = async (ws) => {
@@ -51,4 +58,4 @@ const placeholderWebPart = async (ws) => {
51
58
  await writeFile(path.join(web, bundleLayout.spa), "<!doctype html><title>protobase dev</title>\n");
52
59
  };
53
60
  //#endregion
54
- export { buildWebPart, placeholderWebPart, withApiOrigin };
61
+ export { buildWebPart, placeholderWebPart };
package/dist/serve/app.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import { isApiPath } from "../bundle/manifest.js";
2
2
  import { serveStaticSite } from "./static-site.js";
3
- import { jobsDrainApp, webauthnPath } from "@protobase/server";
3
+ import { jobsDrainApp, mobileReleaseApp, webauthnPath } from "@protobase/server";
4
4
  import { Hono } from "hono";
5
5
  import { logger } from "hono/logger";
6
6
  //#region src/serve/app.ts
7
- const createServeApp = ({ admin, requestLog, site, jobs, drainToken }) => {
7
+ const createServeApp = ({ admin, requestLog, site, jobs, drainToken, mobile }) => {
8
8
  const app = new Hono();
9
9
  if (requestLog) app.use(logger());
10
10
  app.get("/health", (c) => c.json({ status: "ok" }));
@@ -13,6 +13,7 @@ const createServeApp = ({ admin, requestLog, site, jobs, drainToken }) => {
13
13
  runtime: jobs,
14
14
  token: drainToken
15
15
  }));
16
+ if (mobile) app.route("/", mobileReleaseApp(mobile));
16
17
  app.route("/", admin);
17
18
  return app;
18
19
  };
@@ -3,7 +3,8 @@ import path from "node:path";
3
3
  const bundleSite = (dir, manifest) => ({
4
4
  publicDir: path.resolve(dir, manifest.public),
5
5
  spa: manifest.spa,
6
- api: manifest.api
6
+ api: manifest.api,
7
+ ...manifest.native && { native: manifest.native }
7
8
  });
8
9
  //#endregion
9
10
  export { bundleSite };
package/dist/serve/env.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { readTrustedProxies } from "./client-address.js";
2
+ import { readSigningKey } from "@protobase/server";
2
3
  //#region src/serve/env.ts
3
4
  const defaultPort = 8787;
4
5
  const readBoolean = (env, name, fallback) => {
@@ -12,6 +13,7 @@ const readServeEnv = (env) => {
12
13
  if (!Number.isInteger(port) || port < 0 || port > 65535) throw new Error(`PORT must be a port number, not "${env.PORT}"`);
13
14
  const minutes = env.PROTOBASE_FILES_CLEANUP_MINUTES ? Number(env.PROTOBASE_FILES_CLEANUP_MINUTES) : 60;
14
15
  if (!Number.isInteger(minutes) || minutes < 0) throw new Error(`PROTOBASE_FILES_CLEANUP_MINUTES must be a whole number of minutes, not "${env.PROTOBASE_FILES_CLEANUP_MINUTES}"`);
16
+ const mobileSigningKey = readSigningKey(env);
15
17
  const connections = env.PROTOBASE_DB_CONNECTIONS ? Number(env.PROTOBASE_DB_CONNECTIONS) : void 0;
16
18
  if (connections !== void 0 && (!Number.isInteger(connections) || connections < 1)) throw new Error(`PROTOBASE_DB_CONNECTIONS must be a whole number of connections, at least 1, not "${env.PROTOBASE_DB_CONNECTIONS}"`);
17
19
  return {
@@ -23,7 +25,8 @@ const readServeEnv = (env) => {
23
25
  runJobs: readBoolean(env, "PROTOBASE_JOBS", true),
24
26
  startupChecks: readBoolean(env, "PROTOBASE_STARTUP_CHECKS", true),
25
27
  ...env.PROTOBASE_JOBS_DRAIN_TOKEN && { drainToken: env.PROTOBASE_JOBS_DRAIN_TOKEN },
26
- trustedProxies: readTrustedProxies(env.PROTOBASE_TRUSTED_PROXIES)
28
+ trustedProxies: readTrustedProxies(env.PROTOBASE_TRUSTED_PROXIES),
29
+ ...mobileSigningKey && { mobileSigningKey }
27
30
  };
28
31
  };
29
32
  //#endregion
@@ -1,3 +1,4 @@
1
+ import { protobaseVersion } from "../version/version.js";
1
2
  import { apiWebSocketServer } from "../project/api-websocket-server.js";
2
3
  import { withClientAddress } from "./client-address.js";
3
4
  import { projectAdmin } from "../project/project-admin.js";
@@ -5,6 +6,7 @@ import { createPgDb } from "../project/pg-db.js";
5
6
  import { createServeApp } from "./app.js";
6
7
  import { startCleanupTimer } from "./cleanup-timer.js";
7
8
  import { closeSockets } from "./close-sockets.js";
9
+ import { servedRelease } from "./mobile-release.js";
8
10
  import { assistantSettings, authStoreTables, backgroundSettled, checkAi, checkAuthSchema, checkChanges, checkComments, checkComputed, checkJobsSchema, checkQueryRunner, checkWebhooksSchema, configExports, createFileCleanup, startJobs } from "@protobase/server";
9
11
  import { createAdaptorServer, upgradeWebSocket } from "@hono/node-server";
10
12
  import pg from "pg";
@@ -43,12 +45,23 @@ const startServe = async ({ project, env, createDb = (url) => createPgDb(pg, url
43
45
  work: env.runJobs,
44
46
  onError: (error) => console.error(error)
45
47
  }) : void 0;
48
+ const release = project.mobile ? await servedRelease({
49
+ site,
50
+ mobile: project.mobile,
51
+ issuer: project.auth?.issuer,
52
+ signingKey: env.mobileSigningKey
53
+ }) : void 0;
54
+ const mobile = project.mobile && {
55
+ ...release && { release },
56
+ serverVersion: protobaseVersion
57
+ };
46
58
  const app = createServeApp({
47
59
  admin,
48
60
  requestLog: env.requestLog,
49
61
  site,
50
62
  ...jobs && { jobs },
51
- ...env.drainToken && { drainToken: env.drainToken }
63
+ ...env.drainToken && { drainToken: env.drainToken },
64
+ ...mobile && { mobile }
52
65
  });
53
66
  const sockets = apiWebSocketServer();
54
67
  const server = createAdaptorServer({
@@ -0,0 +1,41 @@
1
+ import { nativeFingerprint } from "../mobile/fingerprint.js";
2
+ import { withApiOrigin } from "../mobile/api-origin-page.js";
3
+ import { siteFiles } from "./site-files.js";
4
+ import { readFile } from "node:fs/promises";
5
+ import { composeRelease } from "@protobase/server";
6
+ //#region src/serve/mobile-release.ts
7
+ const loopback = [
8
+ "localhost",
9
+ "127.0.0.1",
10
+ "[::1]"
11
+ ];
12
+ /**
13
+ * The API origin a release names, the auth issuer's (`baseURL`), as the app's own files do by default: https, or plain
14
+ * http to this machine only, as `protobase mobile` allows it. `undefined` for any other, which no app calls.
15
+ */
16
+ const releaseOrigin = (issuer) => {
17
+ if (issuer === void 0 || !URL.canParse(issuer)) return void 0;
18
+ const url = new URL(issuer);
19
+ if (url.protocol === "https:" || url.protocol === "http:" && loopback.includes(url.hostname)) return url.origin;
20
+ };
21
+ /**
22
+ * The release of the app's files a server offers its mobile app: every file the site serves, its SPA page naming the
23
+ * API origin as the app's own files do, for binaries of the fingerprint of the site's native packages and the project's
24
+ * plugins. None without a mobile section, without the site's files (the API alone, whose files a host serves), a
25
+ * site that names no native packages (a bundle built before them) or an API origin an app calls.
26
+ */
27
+ const servedRelease = async ({ site, mobile, issuer, signingKey }) => {
28
+ const origin = releaseOrigin(issuer);
29
+ if (!mobile || !site?.native || !origin) return void 0;
30
+ const files = await Promise.all((await siteFiles(site)).map(async ({ href, file }) => ({
31
+ href,
32
+ content: href === site.spa ? new TextEncoder().encode(withApiOrigin(await readFile(file, "utf8"), origin)) : new Uint8Array(await readFile(file))
33
+ })));
34
+ return {
35
+ ...composeRelease(files, signingKey),
36
+ fingerprint: nativeFingerprint(site.native, mobile.plugins),
37
+ origin
38
+ };
39
+ };
40
+ //#endregion
41
+ export { releaseOrigin, servedRelease };
@@ -1,5 +1,6 @@
1
1
  import { readManifest } from "../bundle/manifest.js";
2
2
  import { installedShellDir } from "../build/shell.js";
3
+ import { pinnedNative } from "../mobile/pinned-packages.js";
3
4
  import { serveBundle } from "./serve-bundle.js";
4
5
  import { bundleSite } from "./bundle-site.js";
5
6
  import { servedShell, shellVariable } from "./served-shell.js";
@@ -11,7 +12,10 @@ const serveBundleDir = async (dir, env, out) => {
11
12
  const { shell, note } = await servedShell(manifest, own);
12
13
  const site = {
13
14
  ...bundleSite(dir, manifest),
14
- ...shell && { shell }
15
+ ...shell && {
16
+ shell,
17
+ native: pinnedNative
18
+ }
15
19
  };
16
20
  const server = await serveBundle(path.join(dir, manifest.server), env, out, site);
17
21
  out(` app ${note}\n`);
@@ -0,0 +1,21 @@
1
+ import { siteRoot } from "./static-site.js";
2
+ import path from "node:path";
3
+ import { readdir } from "node:fs/promises";
4
+ //#region src/serve/site-files.ts
5
+ const filesIn = async (dir) => (await readdir(dir, {
6
+ recursive: true,
7
+ withFileTypes: true
8
+ })).filter((entry) => entry.isFile()).map((entry) => path.relative(dir, path.join(entry.parentPath, entry.name)).split(path.sep).join("/"));
9
+ /**
10
+ * Every file the site serves: its path inside the app's files, such as `assets/index-abc123.js`, and the file on disk,
11
+ * from the folder `serveStaticSite` serves that path from, so a server of its own shell lists the shell's.
12
+ */
13
+ const siteFiles = async (site) => {
14
+ const roots = [site.publicDir, ...site.shell ? [site.shell.dir] : []];
15
+ return (await Promise.all(roots.map(async (root) => (await filesIn(root)).filter((href) => siteRoot(site, `/${href}`) === root).map((href) => ({
16
+ href,
17
+ file: path.join(root, href)
18
+ }))))).flat();
19
+ };
20
+ //#endregion
21
+ export { siteFiles };
@@ -42,18 +42,21 @@ const fileResponse = async (root, file) => new Response(await readFile(file), {
42
42
  } });
43
43
  const isNavigation = (request) => (request.headers.get("accept") ?? "").includes("text/html");
44
44
  const isUnder = (paths, pathname) => paths.some((prefix) => pathname === prefix || pathname.startsWith(`${prefix}/`));
45
- const serveStaticSite = async ({ publicDir, spa, shell }, request) => {
45
+ /** The folder the site serves the URL path `pathname` from: its own shell's, for the shell's paths and the root, else publicDir. */
46
+ const siteRoot = ({ publicDir, shell }, pathname) => shell && (pathname === "/" || isUnder(shell.paths, pathname)) ? shell.dir : publicDir;
47
+ const serveStaticSite = async (site, request) => {
48
+ const { publicDir, spa, shell } = site;
46
49
  if (request.method !== "GET" && request.method !== "HEAD") return new Response("Method Not Allowed", {
47
50
  status: 405,
48
51
  headers: { allow: "GET, HEAD" }
49
52
  });
50
53
  const pathname = new URL(request.url).pathname;
51
54
  const appDir = shell?.dir ?? publicDir;
52
- const root = shell && (pathname === "/" || isUnder(shell.paths, pathname)) ? shell.dir : publicDir;
55
+ const root = siteRoot(site, pathname);
53
56
  const file = await fileFor(root, pathname);
54
57
  if (file) return fileResponse(root, file);
55
58
  if (isNavigation(request)) return fileResponse(appDir, path.join(appDir, spa));
56
59
  return new Response("Not Found", { status: 404 });
57
60
  };
58
61
  //#endregion
59
- export { frameHeaders, serveStaticSite };
62
+ export { frameHeaders, serveStaticSite, siteRoot };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/cli",
3
- "version": "0.40.9",
3
+ "version": "0.41.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.9",
40
- "@protobase/query": "0.40.9",
41
- "@protobase/schema": "0.40.9",
42
- "@protobase/server": "0.40.9",
43
- "@protobase/ui": "0.40.9",
39
+ "@protobase/layout": "0.41.0",
40
+ "@protobase/query": "0.41.0",
41
+ "@protobase/schema": "0.41.0",
42
+ "@protobase/server": "0.41.0",
43
+ "@protobase/ui": "0.41.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",
@@ -41,6 +41,7 @@ A project moved from Supabase with `protobase import supabase` has what the impo
41
41
  Guides:
42
42
 
43
43
  - When setting up or running a project for the first time → read [Getting started](references/getting-started.md)
44
+ - When you need to know whether Protobase has a feature, what it is called or how stable it is → read [Features](references/features.md), which links a page per area
44
45
  - When shipping a project as a bundle and running it with the serve runtime → read [Deploy](references/guides/deploy.md)
45
46
  - When turning a table into an admin with fields, views and filters → read [From a table to an admin](references/guides/table-to-admin.md)
46
47
  - When building a page from layouts and blocks → read [Your first composed page](references/guides/first-composed-page.md)
@@ -0,0 +1,17 @@
1
+ <!-- Generated by scripts/protobase-skill.ts from website/src/content/docs/features/access.md: run `bun run docs:skill`, do not edit. -->
2
+
3
+ # Access
4
+
5
+ Decide who may read and change which records and fields.
6
+
7
+ - [Roles and capabilities](../reference/access.md#capabilities): Roles defined in code grant capabilities per resource and action. A project with roles denies anything not granted.
8
+ - [Field and row limits](../reference/access.md#capabilities): A role can be limited to listed fields and to rows that match a filter. A field added later stays hidden from that role until it is listed, and the server does not start with a limit on a field or resource that does not exist.
9
+ - [Capability checks](../reference/access.md#wildcards-in-has-can-and-holds): Your code asks whether a user holds one capability, or all of a wildcard such as `vms.*`, and a check that could pass by accident is refused.
10
+ - [Field rules](../reference/access.md#field-rules-or-field-lists): Single fields, such as a cost price, can be hidden from every role that lacks a given capability.
11
+ - [Owned records](../reference/data-config.md#access): Users can be limited to the records they own, or that their team owns, through an owner field. The server does not start when that field cannot hold the users' ids.
12
+ - [Rules on the stored record](../reference/data-config.md#access): A rule can read the record as it is stored, such as one that refuses changes to a locked invoice.
13
+ - [Write-only fields](../reference/access.md#write-only-fields): A role can set a field it can never read back, such as a secret only a worker reads. The admin app edits it only where the layout names it, with no stored value to reveal.
14
+ - [Access through a parent record](../reference/access.md#records-that-belong-to-another): Writing a child record can require access to the record it belongs to.
15
+ - [Anonymous access](../reference/access.md#anonymous-access): Visitors without an account can read listed fields of chosen records, such as a public product catalog, and send the public forms you open to them.
16
+ - [Public browsing](../reference/access.md#browsing-the-admin-app): With anonymous access on, visitors browse what they may read in the admin app without signing in, read-only, with a Sign in button.
17
+ - [Checked on every request](../reference/api.md#access): The server applies the caller's operations, fields and rows to every request, on lists, record pages, composed pages and the API alike. Each record says what the caller may change in it, so the admin app offers no edit the server would refuse.
@@ -0,0 +1,11 @@
1
+ <!-- Generated by scripts/protobase-skill.ts from website/src/content/docs/features/actions.md: run `bun run docs:skill`, do not edit. -->
2
+
3
+ # Actions
4
+
5
+ Buttons that change records, ask for input or run your own code, per role.
6
+
7
+ - [Record actions](../reference/ui-config.md#actions-and-views-per-role): Buttons that update fields, delete, open a link, run an AI action or call your own code.
8
+ - [Actions that ask for input](../reference/ui-config.md#actions-that-ask-for-input): An action opens a dialog for text, numbers, dates, choices or records before it runs.
9
+ - [Conditional and bulk actions](../reference/ui-config.md#where-an-action-applies): Actions show, or show disabled with a reason, only where a condition holds, and run on several selected rows at once.
10
+ - [Views per role](../reference/ui-config.md#actions-and-views-per-role): Each role can get its own view of a resource, with other columns, filters, layout and actions.
11
+ - [Named actions](../reference/layouts.md#named-actions): An action is declared once in a view and used as a button on lists, record pages and composed pages.
@@ -0,0 +1,14 @@
1
+ <!-- Generated by scripts/protobase-skill.ts from website/src/content/docs/features/ai.md: run `bun run docs:skill`, do not edit. -->
2
+
3
+ # AI
4
+
5
+ Fields and actions filled by a model, the assistant beside the admin, and MCP.
6
+
7
+ - [AI fields](../reference/ai.md#ai-fields): A model fills a field from a prompt that uses the record's other fields, after each change.
8
+ - [AI actions](../reference/ai.md#ai-actions): A button asks a model to write a field now, such as a suggested priority or a translation.
9
+ - [Assistant](../reference/assistant.md): A chat beside the admin that answers questions about the app, reads its data and proposes changes for approval.
10
+ - [Choice of model](../reference/assistant.md#which-backend): The assistant runs on OpenRouter or any OpenAI-compatible endpoint, also a local one.
11
+ - [Assistant tools](../reference/assistant.md#the-apps-own-tools): Your own tools for the assistant, acting on records as the user.
12
+ - [MCP server](../reference/mcp.md#the-tools): AI clients connect to the app over MCP as the signed-in person, and list, find and read records within that person's access.
13
+ - [MCP writes](../reference/mcp.md#writes): When turned on, for every resource or only those you list, AI clients create and update records after the person approves each write.
14
+ - [Connected apps](../reference/auth.md#oauth-for-mcp-clients): People allow an AI client to sign in, and disconnect it later.
@@ -0,0 +1,13 @@
1
+ <!-- Generated by scripts/protobase-skill.ts from website/src/content/docs/features/api-functions.md: run `bun run docs:skill`, do not edit. -->
2
+
3
+ # API functions
4
+
5
+ Endpoints of your own beside the REST API.
6
+
7
+ - [API functions](../guides/api-functions.md#a-first-function): Each file in `functions/` becomes an endpoint for signed-in callers, reloaded while you work.
8
+ - [Records as the caller](../guides/api-functions.md#reading-and-writing-records-as-the-caller): Functions read and write records with the caller's access, validation and hooks.
9
+ - [Input checks](../guides/api-functions.md#checking-input): Request bodies are checked with zod, Valibot or another Standard Schema validator.
10
+ - [Roles for functions](../guides/api-functions.md#roles): A function can be limited to roles or a capability.
11
+ - [Public functions and webhooks](../guides/api-functions.md#public-functions-and-webhooks): A function can be open to anyone, with helpers that check webhook signatures.
12
+ - [WebSockets](../guides/api-functions.md#websockets): A function can accept a WebSocket, and the caller is checked again every minute.
13
+ - [Hono apps](../guides/api-functions.md#hono-apps): A function with several routes can be a Hono app.
@@ -0,0 +1,22 @@
1
+ <!-- Generated by scripts/protobase-skill.ts from website/src/content/docs/features/build-and-run.md: run `bun run docs:skill`, do not edit. -->
2
+
3
+ # Build and run
4
+
5
+ Develop, build and run an app, on servers, in containers and on phones.
6
+
7
+ - [Node and Bun](../reference/cli.md#how-it-runs): The `protobase` command runs on Node 22.12 or later or on Bun, and a bundle runs on both unless it is built for Bun only.
8
+ - [Dev server](../reference/cli.md#dev): The admin app and the API on one port, with changes shown without a restart.
9
+ - [Migrations from config](../reference/cli.md#migration): Writes the SQL migrations for what the config turns on, as files of the project.
10
+ - [User and organization commands](../reference/cli.md#users): Create users, set roles and manage organizations from the terminal.
11
+ - [Encryption commands](../reference/cli.md#encryption-status): Report and fix plaintext or old-key values of encrypted fields.
12
+ - [One bundle](../reference/cli.md#build): `protobase build` writes one folder with everything the app needs, without a database or secrets. It fails on a view that filters, sorts or searches by a field its resource does not allow.
13
+ - [Source maps](../reference/cli.md#source-maps): The bundle and plugins can carry source maps with debug ids, for an error tracker to read browser stack frames.
14
+ - [Extensions](../reference/cli.md#extensions): A host adds its own tools and widgets to every app it builds.
15
+ - [Native packages](../reference/cli.md#native-packages): npm packages with native add-ons are bundled for Linux.
16
+ - [Serve runtime](../reference/cli.md#serve): Runs a bundle, set by environment variables, with a health check, startup checks, jobs and a clean shutdown.
17
+ - [Migrations at update time](../guides/deploy.md#migrations): The bundle carries the project's migrations, and the runtime applies them in one transaction before the new version serves.
18
+ - [Single-file runtime](../reference/cli.md#build-serve): The runtime as one file, so a host needs only Bun and that file.
19
+ - [Separate worker](../reference/cli.md#worker): Jobs and event delivery in their own process.
20
+ - [Container images](../guides/deploy.md#images): A runtime image for each release, for amd64 and arm64.
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.
@@ -0,0 +1,14 @@
1
+ <!-- Generated by scripts/protobase-skill.ts from website/src/content/docs/features/compatibility.md: run `bun run docs:skill`, do not edit. -->
2
+
3
+ # Compatibility and moving from other systems
4
+
5
+ Apps written for other systems that keep working on Protobase, and moving their data and code over.
6
+
7
+ ## Supabase
8
+
9
+ - [Supabase import](../reference/cli.md#import-supabase): Moves a Supabase project into Protobase, with schema, data, users, functions, storage and scheduled jobs.
10
+ - [Supabase client API](../reference/supabase-rest.md): supabase-js `from()` and `rpc()` calls keep working, under the tables' RLS policies.
11
+ - [Supabase Auth](../reference/auth.md#supabase-js-and-supabasessr): `supabase.auth` and `@supabase/ssr` calls keep working.
12
+ - [Supabase Storage](../reference/supabase-storage.md): supabase-js storage calls keep working, over the app's file storage.
13
+ - [Supabase Realtime](../reference/supabase-realtime.md): Database changes, broadcast and presence through supabase-js channels.
14
+ - [Edge Functions](../guides/api-functions.md#functions-moved-from-supabase): Functions moved from Supabase answer at their old addresses.
@@ -0,0 +1,18 @@
1
+ <!-- Generated by scripts/protobase-skill.ts from website/src/content/docs/features/composed-pages.md: run `bun run docs:skill`, do not edit. -->
2
+
3
+ # Composed pages
4
+
5
+ Pages of your own, built from blocks in a JSX layout.
6
+
7
+ - [Composed pages](../reference/layouts.md#setup): Pages built from a JSX layout, with their own address, sidebar entry and role limits, reading the API under the same access rules as the lists.
8
+ - [Layout checks](../reference/layouts.md#what-a-layout-may-hold): The build refuses a layout with code, unknown props or unknown fields, and names the file and place.
9
+ - [Conditions](../reference/layouts.md#conditions): Part of a page shows only while a condition on a record or a count holds.
10
+ - [App addresses](../reference/layouts.md#addresses): Links to lists, records, create forms and pages are typed addresses that can carry filters and prefilled values.
11
+ - [Per-user pages](../reference/layouts.md#access): Each user gets the page without the parts, fields and actions they cannot use.
12
+ - [Layout blocks](../reference/blocks.md#layout): Pages, responsive grids, cards and links.
13
+ - [Data blocks](../reference/blocks.md#data): Counts, tables, single records, rows of cards, field values and progress bars.
14
+ - [Record rows](../reference/blocks.md#recordrow): A sideways row of cards for a filter, favorites or saved searches, with a count and new-record marks.
15
+ - [Record cards](../reference/blocks.md#recordcards): Full-width cards with fields and buttons, stacked or in a carousel.
16
+ - [Chart block](../reference/blocks.md#chart): Counts, sums or averages by value or by date, as bars, lines or a donut.
17
+ - [Buttons and forms](../reference/blocks.md#behaviour): Buttons for named actions, and create or edit forms in a dialog.
18
+ - [Users block](../reference/blocks.md#users): User management on any page: find users, set roles, block them and invite by email.
@@ -0,0 +1,22 @@
1
+ <!-- Generated by scripts/protobase-skill.ts from website/src/content/docs/features/data-model.md: run `bun run docs:skill`, do not edit. -->
2
+
3
+ # Data model
4
+
5
+ Describe the tables of an existing Postgres database as resources, with their fields, keys and rules.
6
+
7
+ - [Resources](../reference/data-config.md#resource): Each table or view of an existing Postgres database is described as a resource in TypeScript, with its fields, key and rules. Nothing in the database changes.
8
+ - [Snake case names](../reference/data-config.md#resource): Scaffold names resources and fields after their tables and columns, such as `stock_moves` and `moved_at`, and the built-in resources are named the same way, so the names in URLs and the API match the database.
9
+ - [Field types](../reference/data-config.md#field-types): Text, numbers, exact decimals, booleans, dates, timestamps, UUIDs, enums, JSON, relations, currencies, countries and files, each mapped to Postgres column types and checked.
10
+ - [Field options](../reference/data-config.md#field-options): A field can be optional, read-only, given a default by the app or the database, filterable and sortable where an index serves it, known by other names, and read from a column of another name.
11
+ - [Composite keys and relations](../reference/data-config.md#keys-and-relations): Records can have keys of several columns, and relations can point at them. The admin shows a related record by its name and links to it.
12
+ - [Soft delete](../reference/data-config.md#resource): Deleting a record marks it with a timestamp instead of removing it. Lists leave it out, and it can be restored.
13
+ - [Tenants](../reference/data-config.md#resource): A tenant column keeps each organization's records apart. Every query is limited to the caller's tenant, and new records get it set.
14
+ - [Record search](../reference/data-config.md#resource): You choose which fields text search and the global search look in. Partial words match, and phone numbers match by their last digits.
15
+ - [Manual order](../reference/data-config.md#resource): Records can be kept in an order set by hand, also per parent record, such as the lines of an invoice.
16
+ - [Record validation](../reference/data-config.md#resource): A rule over the whole record runs on every create and update and reports each problem on the field it concerns.
17
+ - [Rollups and formulas](../reference/data-config.md#rollups-and-formulas) (beta): Fields that hold counts, sums, averages, minimums or maximums of related records, or values calculated from the record's own numbers, kept current by the database.
18
+ - [Sensitive fields](../reference/data-config.md#sensitive-fields): Values such as bank account numbers are left out of every response and shown masked. A permitted user reveals one value at a time, and each reveal is audited.
19
+ - [Encrypted fields](../reference/data-config.md#encrypted-fields): A sensitive text field is encrypted with the app's own key before it is stored, so dumps, backups and SQL readers see only ciphertext. A command encrypts the values a column already holds.
20
+ - [Encryption key rotation](../reference/data-config.md#the-key): The encryption key can be replaced without downtime. CLI commands re-encrypt stored values and report what is left.
21
+ - [Schema API reference](../reference/data-config.md#schema-api-reference): Every builder, option and type of `@protobase/schema` has a doc comment, shown in your editor and in the generated API reference, and the types the builders return are exported for helpers of your own.
22
+ - [Extending a config](../reference/cli.md#extending-a-config): A project can merge other configs and UI configs into its own. A name defined twice is an error, never a silent override.
@@ -0,0 +1,12 @@
1
+ <!-- Generated by scripts/protobase-skill.ts from website/src/content/docs/features/email-and-public-forms.md: run `bun run docs:skill`, do not edit. -->
2
+
3
+ # Email and public forms
4
+
5
+ Mail the app sends, and forms for people without an account.
6
+
7
+ - [Email](../reference/email.md#configuration): The app sends mail through one SMTP server or a mailer you supply.
8
+ - [Built-in emails](../reference/email.md#protobases-own-mail): Sign-in codes, password resets, invitations and mentions are sent in the app's name.
9
+ - [Email templates](../reference/email.md#templates): Your own emails are React components with typed data, sent from jobs, hooks or functions.
10
+ - [Public forms](../reference/forms.md#what-the-visitor-sees): A form at its own address lets people without an account create a record, such as a contact request.
11
+ - [Bot check](../reference/forms.md#bot-check): Each submission passes a check in the browser, without a third-party service or a puzzle.
12
+ - [Form rate limit](../reference/forms.md#rate-limit): Each client sends only a set number of submissions per minute.