@protobase/cli 0.47.1 → 0.49.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/build/config-bundle.js +6 -1
- package/dist/build/entry-code.js +30 -17
- package/dist/cli/package.js +1 -1
- package/dist/config/build-project.js +70 -0
- package/dist/config/called-config.js +11 -0
- package/dist/config/config-defaults.js +30 -0
- package/dist/config/env-values.js +20 -0
- package/dist/config/lazy-imports.js +18 -0
- package/dist/config/merge-config.js +72 -0
- package/dist/config/project-files.js +48 -0
- package/dist/config/project-parts.js +201 -0
- package/dist/config/read-config.js +31 -0
- package/dist/config/source-config.js +37 -0
- package/dist/dev/api-child.js +2 -1
- package/dist/dev/api-process.d.ts +1 -0
- package/dist/dev/api-process.js +5 -2
- package/dist/dev/auth-drift-lines.js +8 -0
- package/dist/dev/create-db.js +2 -2
- package/dist/dev/entry.d.ts +5 -0
- package/dist/dev/entry.js +17 -12
- package/dist/dev/project.js +23 -47
- package/dist/dev/run.js +3 -2
- package/dist/main.js +3 -3
- package/dist/migration/load-project.js +34 -34
- package/dist/migration/parts.js +2 -2
- package/dist/migration/summary.js +2 -2
- package/dist/mobile/api-origin.js +4 -4
- package/dist/mobile/load-project.js +13 -12
- package/dist/mobile/register.js +1 -1
- package/dist/mobile/run.js +1 -1
- package/dist/organizations/register.js +1 -1
- package/dist/project/error-reporter.js +3 -3
- package/dist/project/import-project-file.js +4 -2
- package/dist/project/load-bundle-project.js +16 -25
- package/dist/project/load-data-config.js +2 -2
- package/dist/project/pg-db.js +10 -4
- package/dist/project/placeholder-secret.js +2 -2
- package/dist/project/project-admin.js +12 -11
- package/dist/scaffold/plan.js +7 -3
- package/dist/scaffold/protobase-tables.js +8 -13
- package/dist/scaffold/run.js +1 -1
- package/dist/serve/create-admin.js +9 -4
- package/dist/serve/host-module-ids.js +1 -0
- package/dist/serve/host-modules.js +3 -1
- package/dist/serve/lifecycle.js +19 -14
- package/dist/serve/load-bundle.js +41 -11
- package/dist/serve/mobile-release.js +1 -1
- package/dist/serve/serve-bundle.js +3 -3
- package/dist/supabase/auth-config.js +33 -28
- package/dist/supabase/config-jobs.js +28 -27
- package/dist/supabase/config-object.js +25 -0
- package/dist/supabase/cron-job-file.js +13 -14
- package/dist/supabase/cron-jobs-write.js +6 -12
- package/dist/supabase/cron-plan.js +3 -51
- package/dist/supabase/project-files.js +4 -9
- package/dist/supabase/report.js +3 -3
- package/dist/users/load-auth.js +16 -15
- package/dist/worker/start-worker.js +18 -15
- package/package.json +8 -6
- package/skills/protobase/SKILL.md +2 -1
- package/skills/protobase/references/features/notifications.md +1 -1
- package/skills/protobase/references/features/sign-in-and-accounts.md +1 -0
- package/skills/protobase/references/features/start-a-project.md +3 -0
- package/skills/protobase/references/getting-started.md +2 -2
- package/skills/protobase/references/guides/api-functions.md +4 -4
- package/skills/protobase/references/guides/deploy.md +8 -8
- package/skills/protobase/references/guides/existing-database.md +11 -31
- package/skills/protobase/references/guides/first-plugin.md +1 -1
- package/skills/protobase/references/guides/mobile-app.md +5 -3
- package/skills/protobase/references/guides/plugin-build.md +1 -1
- package/skills/protobase/references/guides/push-notifications.md +6 -7
- package/skills/protobase/references/guides/remote-resources.md +22 -31
- package/skills/protobase/references/reference/access.md +3 -3
- package/skills/protobase/references/reference/ai.md +1 -9
- package/skills/protobase/references/reference/api.md +15 -15
- package/skills/protobase/references/reference/app-identity.md +9 -10
- package/skills/protobase/references/reference/assistant.md +6 -6
- package/skills/protobase/references/reference/auth.md +126 -96
- package/skills/protobase/references/reference/bottom-bar.md +1 -1
- package/skills/protobase/references/reference/cli.md +36 -86
- package/skills/protobase/references/reference/comments.md +0 -8
- package/skills/protobase/references/reference/config.md +152 -0
- package/skills/protobase/references/reference/data-config.md +2 -2
- package/skills/protobase/references/reference/email.md +36 -37
- package/skills/protobase/references/reference/events.md +1 -1
- package/skills/protobase/references/reference/files.md +18 -23
- package/skills/protobase/references/reference/forms.md +5 -17
- package/skills/protobase/references/reference/history.md +2 -3
- package/skills/protobase/references/reference/installable-app.md +1 -1
- package/skills/protobase/references/reference/jobs.md +53 -56
- package/skills/protobase/references/reference/languages.md +4 -2
- package/skills/protobase/references/reference/mcp.md +11 -11
- package/skills/protobase/references/reference/notifications.md +26 -24
- package/skills/protobase/references/reference/plugins.md +11 -14
- package/skills/protobase/references/reference/remote-resources.md +18 -24
- package/skills/protobase/references/reference/supabase-realtime.md +1 -1
- package/skills/protobase/references/reference/supabase-rest.md +1 -1
- package/skills/protobase/references/reference/supabase-storage.md +1 -1
- package/skills/protobase/references/reference/ui-config.md +15 -17
- package/skills/protobase/references/reference/versioning.md +1 -1
- package/skills/protobase/references/reference/webhooks.md +6 -7
|
@@ -30,57 +30,11 @@ const utc = /* @__PURE__ */ new Set([
|
|
|
30
30
|
]);
|
|
31
31
|
/** A pg_cron job name as a Protobase job name: letters, digits, `_`, `-`, `.` and `/`, the rest made `-`. */
|
|
32
32
|
const jobName = (job) => (job.name ?? `cron-job-${job.id}`).replace(/[^\w.\-/]+/g, "-");
|
|
33
|
+
/** A job's name as Protobase declares it, which is also its file `jobs/<name>.ts`: lowercase words joined by `-`. */
|
|
33
34
|
const fileName = (name) => name.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "") || "cron-job";
|
|
34
|
-
/** Words a module's export may not be named, which a job named so gets `cron` before. */
|
|
35
|
-
const reserved = /* @__PURE__ */ new Set([
|
|
36
|
-
"await",
|
|
37
|
-
"break",
|
|
38
|
-
"case",
|
|
39
|
-
"catch",
|
|
40
|
-
"class",
|
|
41
|
-
"const",
|
|
42
|
-
"continue",
|
|
43
|
-
"debugger",
|
|
44
|
-
"default",
|
|
45
|
-
"delete",
|
|
46
|
-
"do",
|
|
47
|
-
"else",
|
|
48
|
-
"enum",
|
|
49
|
-
"export",
|
|
50
|
-
"extends",
|
|
51
|
-
"false",
|
|
52
|
-
"finally",
|
|
53
|
-
"for",
|
|
54
|
-
"function",
|
|
55
|
-
"if",
|
|
56
|
-
"import",
|
|
57
|
-
"in",
|
|
58
|
-
"instanceof",
|
|
59
|
-
"let",
|
|
60
|
-
"new",
|
|
61
|
-
"null",
|
|
62
|
-
"return",
|
|
63
|
-
"static",
|
|
64
|
-
"super",
|
|
65
|
-
"switch",
|
|
66
|
-
"this",
|
|
67
|
-
"throw",
|
|
68
|
-
"true",
|
|
69
|
-
"try",
|
|
70
|
-
"typeof",
|
|
71
|
-
"var",
|
|
72
|
-
"void",
|
|
73
|
-
"while",
|
|
74
|
-
"with",
|
|
75
|
-
"yield"
|
|
76
|
-
]);
|
|
77
|
-
const exportName = (file) => {
|
|
78
|
-
const camel = file.replace(/-([a-z0-9])/g, (_, letter) => letter.toUpperCase());
|
|
79
|
-
return /^[0-9]/.test(camel) || reserved.has(camel) ? `cron${camel[0].toUpperCase()}${camel.slice(1)}` : camel;
|
|
80
|
-
};
|
|
81
35
|
/** `wanted`, or with `-<id>` after it when `taken` has it already, which it then holds. */
|
|
82
|
-
const unique = (taken, wanted, id
|
|
83
|
-
const name = taken.has(wanted) ? `${wanted}
|
|
36
|
+
const unique = (taken, wanted, id) => {
|
|
37
|
+
const name = taken.has(wanted) ? `${wanted}-${id}` : wanted;
|
|
84
38
|
taken.add(name);
|
|
85
39
|
return name;
|
|
86
40
|
};
|
|
@@ -101,7 +55,6 @@ const leftReason = (job, options) => {
|
|
|
101
55
|
const cronPlan = (jobs, options) => {
|
|
102
56
|
const names = /* @__PURE__ */ new Set();
|
|
103
57
|
const files = /* @__PURE__ */ new Set();
|
|
104
|
-
const exports = /* @__PURE__ */ new Set();
|
|
105
58
|
return jobs.map((job) => {
|
|
106
59
|
if (!job.local) return {
|
|
107
60
|
...job,
|
|
@@ -130,7 +83,6 @@ const cronPlan = (jobs, options) => {
|
|
|
130
83
|
kind: "converted",
|
|
131
84
|
name,
|
|
132
85
|
file,
|
|
133
|
-
exportName: unique(exports, exportName(file), job.id, ""),
|
|
134
86
|
timezone: utc.has(options.timezone) ? void 0 : options.timezone
|
|
135
87
|
}
|
|
136
88
|
};
|
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import path from "node:path";
|
|
1
|
+
import { projectFiles } from "../config/project-parts.js";
|
|
2
|
+
import { loadSourceConfig } from "../config/source-config.js";
|
|
4
3
|
//#region src/supabase/project-files.ts
|
|
5
|
-
/**
|
|
6
|
-
const projectFilesOptions = async (projectDir) => {
|
|
7
|
-
const file = path.join(projectDir, "protobase.config.ts");
|
|
8
|
-
if (!existsSync(file)) return {};
|
|
9
|
-
return (await importProjectFile(file)).default?.files ?? {};
|
|
10
|
-
};
|
|
4
|
+
/** The files options of the project in `projectDir`, its providers made; none when its config has no `files`. */
|
|
5
|
+
const projectFilesOptions = async (projectDir) => await projectFiles(await loadSourceConfig(projectDir, { command: "tool" })) ?? {};
|
|
11
6
|
//#endregion
|
|
12
7
|
export { projectFilesOptions };
|
package/dist/supabase/report.js
CHANGED
|
@@ -21,7 +21,7 @@ const cronLeft = (jobs) => jobs?.flatMap((job) => job.outcome.kind === "left" ?
|
|
|
21
21
|
/** What a person does before the converted pg_cron jobs run, or nothing when the import converted none. */
|
|
22
22
|
const recurringJobs = (manifest, jobsWired) => {
|
|
23
23
|
if (convertedCronJobs(manifest.cronJobs).length === 0) return [];
|
|
24
|
-
return [`## Recurring jobs\n\nThe import wrote pg_cron's jobs it could convert in \`jobs/\`, each running its SQL as the app's database role, once per time and without retries, as pg_cron did. ${jobsWired ? "`protobase.config.ts`
|
|
24
|
+
return [`## Recurring jobs\n\nThe import wrote pg_cron's jobs it could convert in \`jobs/\`, each running its SQL as the app's database role, once per time and without retries, as pg_cron did. ${jobsWired ? "`protobase.config.ts` declares them in its `jobs`, each with its schedule." : "`protobase.config.ts` could not be changed: declare each of them in its `jobs`, by the name of its file, with its schedule and `maxAttempts: 1`."} They run once the database has the jobs schema: run \`protobase migration\` and apply it.\n`];
|
|
25
25
|
};
|
|
26
26
|
const tableName = (table) => `${table.schema}.${table.table}`;
|
|
27
27
|
/** The tables of the `supabase_realtime` publication the scaffold gave `.live()`, or nothing when it gave none. */
|
|
@@ -57,12 +57,12 @@ const providerLine = ({ provider, identities, unkeyed, unconfirmed }) => {
|
|
|
57
57
|
const signInSection = (providers) => [
|
|
58
58
|
"## Sign-in\n",
|
|
59
59
|
"Supabase's users sign in with their own passwords once the migrations the import wrote are applied; those who never confirmed their address sign in by code instead. Sessions do not carry over, so everyone signs in once; MFA factors and passkeys are set up again. No imported user has a role in the app yet: give the admins theirs with `protobase users set-role <email> admin`.\n",
|
|
60
|
-
providers.length === 0 ? "auth.identities is empty.\n" : `Each identity of a social provider became an account, which signs in once the provider is in \`
|
|
60
|
+
providers.length === 0 ? "auth.identities is empty.\n" : `Each identity of a social provider became an account, which signs in once the provider is in \`auth.socialProviders\` of protobase.config.ts, with the client id and secret the Supabase project used. By provider:\n\n${providers.map((provider) => `- ${providerLine(provider)}`).join("\n")}\n`
|
|
61
61
|
].join("\n");
|
|
62
62
|
/**
|
|
63
63
|
* The import's report: what it loaded, and what it could not carry over, for a person or their AI assistant to finish.
|
|
64
64
|
* `doctor` is `protobase doctor`'s output on the scaffolded config, or `undefined` when there was no config to check;
|
|
65
|
-
* `jobsWired` whether protobase.config.ts
|
|
65
|
+
* `jobsWired` whether protobase.config.ts declares the pg_cron jobs the load wrote in its `jobs`; `live` the tables, as
|
|
66
66
|
* `schema.table`, whose resources the scaffold gave `.live()`; `providers` counts the loaded auth.identities by
|
|
67
67
|
* provider.
|
|
68
68
|
*/
|
package/dist/users/load-auth.js
CHANGED
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
import { loadNearestEnvFile } from "../dev/env.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
2
|
+
import { projectNotifications } from "../config/project-parts.js";
|
|
3
|
+
import { projectAuth } from "../config/build-project.js";
|
|
4
|
+
import { loadSourceConfig } from "../config/source-config.js";
|
|
5
|
+
import { openAppDatabase } from "../project/pg-db.js";
|
|
6
|
+
import { removeDevicesWithUsers, removeHistoryWithUsers } from "@protobase/server";
|
|
7
|
+
import pg from "pg";
|
|
6
8
|
//#region src/users/load-auth.ts
|
|
7
9
|
/**
|
|
8
|
-
*
|
|
9
|
-
* store of the app's own (
|
|
10
|
-
* from it too; the built-in tables go with the user by their foreign
|
|
10
|
+
* The sign-in of the project in `projectDir`, built from its config's `auth` over DATABASE_URL, with only the plugins
|
|
11
|
+
* it turns on. With a device or history store of the app's own (notifications/store.ts, notifications/history-store.ts),
|
|
12
|
+
* deleting a user removes their devices or history from it too; the built-in tables go with the user by their foreign
|
|
13
|
+
* keys.
|
|
11
14
|
*/
|
|
12
15
|
const loadProjectAuth = async (projectDir) => {
|
|
13
16
|
loadNearestEnvFile(projectDir);
|
|
14
|
-
const
|
|
15
|
-
if (!
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
if (
|
|
20
|
-
if (project.notifications?.store) removeDevicesWithUsers(auth, project.notifications.store);
|
|
21
|
-
if (project.notifications?.historyStore) removeHistoryWithUsers(auth, project.notifications.historyStore);
|
|
17
|
+
const config = await loadSourceConfig(projectDir, { command: "tool" });
|
|
18
|
+
if (!config.auth) throw new Error("Sign-in is off (`auth: false` in the config), so the app has no users to manage");
|
|
19
|
+
if (!process.env.DATABASE_URL) throw new Error("No database: set DATABASE_URL");
|
|
20
|
+
const [auth, notifications] = await Promise.all([projectAuth(config, openAppDatabase(pg, process.env.DATABASE_URL)), projectNotifications(config)]);
|
|
21
|
+
if (notifications?.store) removeDevicesWithUsers(auth, notifications.store);
|
|
22
|
+
if (notifications?.historyStore) removeHistoryWithUsers(auth, notifications.historyStore);
|
|
22
23
|
return auth;
|
|
23
24
|
};
|
|
24
25
|
//#endregion
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { projectAdmin } from "../project/project-admin.js";
|
|
2
|
-
import {
|
|
2
|
+
import { buildProject } from "../config/build-project.js";
|
|
3
|
+
import { openAppDatabase } from "../project/pg-db.js";
|
|
3
4
|
import { readManifest } from "../bundle/manifest.js";
|
|
4
5
|
import { checkBundleManifest } from "../serve/bundle-manifest.js";
|
|
5
6
|
import { loadBundle } from "../serve/load-bundle.js";
|
|
6
7
|
import { statSync } from "node:fs";
|
|
7
8
|
import path from "node:path";
|
|
8
|
-
import { checkJobsSchema, configExports, isCaptured,
|
|
9
|
+
import { checkJobsSchema, configExports, isCaptured, startJobs } from "@protobase/server";
|
|
9
10
|
import pg from "pg";
|
|
10
11
|
//#region src/worker/start-worker.ts
|
|
11
12
|
const bundleConfigFile = async (bundle) => {
|
|
@@ -14,19 +15,21 @@ const bundleConfigFile = async (bundle) => {
|
|
|
14
15
|
};
|
|
15
16
|
/**
|
|
16
17
|
* Runs the project's jobs, and nothing else, until `stop`: the same handlers `protobase serve` runs, in a process of
|
|
17
|
-
* their own. It reads the jobs schema at start and refuses one that is missing or
|
|
18
|
+
* their own, built from the config the same way. It reads the jobs schema at start and refuses one that is missing or
|
|
19
|
+
* behind, like `serve`.
|
|
18
20
|
*/
|
|
19
|
-
const startWorker = async ({
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
});
|
|
24
|
-
if (jobDefinitions(project.jobs ?? {}).length === 0 && !builtIn) throw new Error("The bundle has no jobs: export them from protobase.config.ts as `jobs`, or give a resource events, history, comments or an AI field");
|
|
25
|
-
if (!project.db && !databaseUrl) throw new Error("No database: set DATABASE_URL or export `db` from protobase.config.ts");
|
|
26
|
-
const ownDb = project.db ? void 0 : createDb(databaseUrl);
|
|
27
|
-
const db = project.db ?? ownDb;
|
|
21
|
+
const startWorker = async ({ config, databaseUrl, openDb = (url) => openAppDatabase(pg, url) }) => {
|
|
22
|
+
if (!databaseUrl) throw new Error("No database: set DATABASE_URL");
|
|
23
|
+
const database = openDb(databaseUrl);
|
|
24
|
+
const { db } = database;
|
|
28
25
|
const start = async () => {
|
|
29
|
-
const
|
|
26
|
+
const project = await buildProject(config, database);
|
|
27
|
+
const builtIn = configExports(project.config).resources.some((resource) => {
|
|
28
|
+
const model = resource.toModel();
|
|
29
|
+
return isCaptured(model) || model.comments || Object.values(model.fields).some((field) => field.ai);
|
|
30
|
+
});
|
|
31
|
+
if (project.jobs.length === 0 && !builtIn) throw new Error("The bundle has no jobs: name their module in protobase.config.ts as `jobs`, or give a resource events, history, comments or an AI field");
|
|
32
|
+
const { jobs: definitions } = projectAdmin(project, db);
|
|
30
33
|
await checkJobsSchema(db);
|
|
31
34
|
return {
|
|
32
35
|
definitions,
|
|
@@ -38,14 +41,14 @@ const startWorker = async ({ project, databaseUrl, createDb = (url) => createPgD
|
|
|
38
41
|
};
|
|
39
42
|
};
|
|
40
43
|
const { definitions, runtime: jobs } = await start().catch(async (error) => {
|
|
41
|
-
await
|
|
44
|
+
await db.destroy();
|
|
42
45
|
throw error;
|
|
43
46
|
});
|
|
44
47
|
return {
|
|
45
48
|
jobs: definitions.length,
|
|
46
49
|
stop: async () => {
|
|
47
50
|
await jobs.stop();
|
|
48
|
-
await
|
|
51
|
+
await db.destroy();
|
|
49
52
|
}
|
|
50
53
|
};
|
|
51
54
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.49.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": {
|
|
@@ -39,11 +39,12 @@
|
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@better-auth/core": "^1.7.12",
|
|
41
41
|
"@hono/node-server": "^2.1.3",
|
|
42
|
-
"@protobase/
|
|
43
|
-
"@protobase/
|
|
44
|
-
"@protobase/
|
|
45
|
-
"@protobase/
|
|
46
|
-
"@protobase/
|
|
42
|
+
"@protobase/config": "0.49.0",
|
|
43
|
+
"@protobase/layout": "0.49.0",
|
|
44
|
+
"@protobase/query": "0.49.0",
|
|
45
|
+
"@protobase/schema": "0.49.0",
|
|
46
|
+
"@protobase/server": "0.49.0",
|
|
47
|
+
"@protobase/ui": "0.49.0",
|
|
47
48
|
"@react-email/render": "^2.1.0",
|
|
48
49
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
49
50
|
"@tailwindcss/vite": "^4.3.3",
|
|
@@ -60,6 +61,7 @@
|
|
|
60
61
|
"postcss": "^8.5.29",
|
|
61
62
|
"postgres": "^3.4.9",
|
|
62
63
|
"react": "^19.3.0",
|
|
64
|
+
"rolldown": "~1.2.11",
|
|
63
65
|
"semver": "^7.8.5",
|
|
64
66
|
"ts-morph": "^28.0.0",
|
|
65
67
|
"vite": "^8.3.3",
|
|
@@ -5,7 +5,7 @@ description: Build, check and ship a Protobase admin app on Postgres (data.ts, u
|
|
|
5
5
|
|
|
6
6
|
# Protobase
|
|
7
7
|
|
|
8
|
-
Protobase is a config-driven admin on an existing Postgres database. `config/index.ts` exports the resources, `config/<resource>/data.ts` describes a table and `ui.ts` its views, `functions/` holds the app's API functions, and `protobase.config.ts` in the project root
|
|
8
|
+
Protobase is a config-driven admin on an existing Postgres database. `config/index.ts` exports the resources, `config/<resource>/data.ts` describes a table and `ui.ts` its views, `functions/` holds the app's API functions, and `protobase.config.ts` in the project root describes the rest of the app as one object of data (sign-in, jobs, files, the API's settings), whose code Protobase finds by its path, such as `jobs/<name>.ts`. The app's own React code (components, field types, actions) is a plugin in `protobase.ui.tsx`.
|
|
9
9
|
|
|
10
10
|
Run the CLI as the project does: `npx protobase <command>`, or `bun run protobase <command>`. These pages describe the Protobase version installed in the project.
|
|
11
11
|
|
|
@@ -63,6 +63,7 @@ Guides:
|
|
|
63
63
|
|
|
64
64
|
Reference:
|
|
65
65
|
|
|
66
|
+
- When writing `protobase.config.ts`, or looking for where a job's, hook's or other piece of the app's code goes → read [protobase.config.ts](references/reference/config.md)
|
|
66
67
|
- When defining resources, fields, keys, relations, rollups, formulas and validation → read [Data config](references/reference/data-config.md)
|
|
67
68
|
- When defining views, columns, filters, charts, related records and actions → read [UI config](references/reference/ui-config.md)
|
|
68
69
|
- When asking how the packages fit together → read [Architecture](references/reference/architecture.md)
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
A bell in the top bar and push to browsers and phones, for what your app tells its users.
|
|
6
6
|
|
|
7
|
-
- [Notifications](../reference/notifications.md#turning-them-on) (beta): `
|
|
7
|
+
- [Notifications](../reference/notifications.md#turning-them-on) (beta): `notifications: {}` in the config gives every signed-in user a bell in the top bar and push to their browsers and phones; `ui: false` keeps only the backend.
|
|
8
8
|
- [Devices](../reference/notifications.md#devices) (beta): Each signed-in user registers their own browsers and phones to receive push, and a device gets it only while the sign-in it was registered in lasts.
|
|
9
9
|
- [Your own parts](../reference/notifications.md#your-own-parts) (beta): Senders, the device store, the history store and the bell can each be replaced by your own, such as a store outside the database.
|
|
10
10
|
- [Table names](../reference/notifications.md#table-names) (beta): The built-in stores' schema, tables and columns can be renamed, as auth's users table can.
|
|
@@ -6,6 +6,7 @@ Sign-in methods, users, roles, organizations and tokens.
|
|
|
6
6
|
|
|
7
7
|
- [Built-in sign-in](../reference/auth.md): Password sign-in, sessions and short-lived tokens, with no separate identity service.
|
|
8
8
|
- [First admin](../reference/auth.md#first-run): No account can be made over the web while the app has no users. You create the first admin from the terminal, and the last active admin cannot be deleted, demoted or blocked.
|
|
9
|
+
- [Versioned sign-in tables](../reference/auth.md#migrations): The sign-in tables come from numbered migrations that ship with Protobase, written as the project's own and recorded in the database, so a deploy checks them without comparing tables. Every feature has its tables from the start, so turning one on or off needs no migration.
|
|
9
10
|
- [Existing users table](../reference/auth.md#an-existing-users-table): Sign-in can use the users table another system keeps in the same database.
|
|
10
11
|
- [Users page](../reference/auth.md#users-page): Admins find people, set roles, block them, add accounts and invite people by email.
|
|
11
12
|
- [Password reset](../reference/auth.md#password-reset): People reset a forgotten password through an emailed link.
|
|
@@ -6,6 +6,9 @@ Start a new app, or an admin over an existing Postgres database, and keep the co
|
|
|
6
6
|
|
|
7
7
|
- [Project starter](../getting-started.md#start-an-app): `npm create protobase` (also `bun create` and `pnpm create`) starts a new app from the scratch, ERP or real estate preset, with its own Postgres in Docker for development, and prints the next steps. Each preset has an `AGENTS.md` with rules for coding agents.
|
|
8
8
|
- [Example apps](../getting-started.md#run-the-erp-example): Seeded example apps on Postgres: an ERP, real estate property management and a public property portal.
|
|
9
|
+
- [One config](../reference/config.md): The whole app is one object of data in `protobase.config.ts`, typed with `defineConfig`, with a sensible default for every key.
|
|
10
|
+
- [Code found by path](../reference/config.md#where-the-code-is): The config names jobs, hooks and providers, and Protobase finds their code by its path, such as `jobs/<name>.ts`.
|
|
11
|
+
- [JSON config](../reference/config.md#the-same-config-as-json): The same config works as `protobase.config.json`, with values from the environment written as `$env`.
|
|
9
12
|
- [Scaffold from a database](../reference/cli.md#scaffold): Reads your Postgres tables and writes the data config for them, with field types, keys, relations, enums, soft delete, tenants and search filled in, and with `--ui` a first view of each.
|
|
10
13
|
- [Safe re-scaffolding](../reference/cli.md#re-running): Running scaffold again adds only the columns that are not declared yet and leaves your own config code as it is.
|
|
11
14
|
- [Schema drift report](../reference/cli.md#drift-report): After each scaffold, lists declared fields whose column is gone, whose type changed or whose enum values differ, with a suggested fix.
|
|
@@ -17,7 +17,7 @@ npm create protobase my-app
|
|
|
17
17
|
npm create protobase my-app -- --preset real-estate
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
-
The project comes with its own Postgres for development: a `docker-compose.yml` with Postgres 18, started by `bun run db:up` and stopped by `bun run db:down`, on port 55432 or, when something listens there already, the next free one. Its `.env` points at that database and has a `
|
|
20
|
+
The project comes with its own Postgres for development: a `docker-compose.yml` with Postgres 18, started by `bun run db:up` and stopped by `bun run db:down`, on port 55432 or, when something listens there already, the next free one. Its `.env` points at that database and has a `PROTOBASE_SECRET` of its own. Without Docker, set `DATABASE_URL` in `.env` to a Postgres database of yours. The next steps install it with Bun, which runs the project's scripts, start the database, migrate it, load the preset's base data, if it has any, create a user and run `bun run dev`. For scratch:
|
|
21
21
|
|
|
22
22
|
```sh
|
|
23
23
|
cd my-app
|
|
@@ -56,7 +56,7 @@ bun run --cwd examples/erp protobase users create you@example.com --generate-pas
|
|
|
56
56
|
bun run --cwd examples/erp dev # http://localhost:5173
|
|
57
57
|
```
|
|
58
58
|
|
|
59
|
-
`
|
|
59
|
+
`PROTOBASE_SECRET` in `examples/erp/.env` signs the session cookies; see [Login with Better Auth](reference/auth.md). `protobase dev` serves the admin app and the API on one port and reloads both on every change ([CLI](reference/cli.md#dev)). Its startup message says how to sign in: while the database has no users, it prints the exact `users create` command for the first admin. It stops with a clear message when another server holds its port; pass `--port 5174` to run a second app beside it.
|
|
60
60
|
|
|
61
61
|
## Run the real estate example
|
|
62
62
|
|
|
@@ -38,7 +38,7 @@ The app's own `authenticate` checks the token, the same one that guards the REST
|
|
|
38
38
|
- **Not functions:** files and folders starting with `_` (shared code, such as `functions/_shared/`), dotfiles, `*.test.ts`, `*.spec.ts` and `*.d.ts`. A folder without an `index.ts` is an error that says so.
|
|
39
39
|
- **The default export** is `defineFunction(...)` from `@protobase/server`, a bare `(request, context)` handler, or a Hono app. The last two need a signed-in caller.
|
|
40
40
|
- **Any method** reaches the function, and so does any path below its name. The request's path is the part after `/api/functions/<name>`: `/` for the function itself, `/42/advance` for `/api/functions/workshop/42/advance`. The query string and the body are passed through unchanged.
|
|
41
|
-
- **
|
|
41
|
+
- **Only the folder:** `protobase.config.ts` names no functions; they are found in `functions/`. The functions of an [extension](../reference/config.md#extensions)'s `functions/` folder are kept, and a name used by two folders is an error that names both.
|
|
42
42
|
|
|
43
43
|
## The context
|
|
44
44
|
|
|
@@ -100,7 +100,7 @@ A refusal or a missing record rejects with the problem the REST API would answer
|
|
|
100
100
|
|
|
101
101
|
`defineFunction({ roles: ['mechanic', 'desk'] }, handler)` lets in callers with at least one of those roles. `defineFunction({ capability: 'vms.update' }, handler)` lets in callers whose roles hold all of that capability ([`roles.holds`](../reference/access.md#wildcards-in-has-can-and-holds)): `*`, `vms.*` or a plain `vms.update`, but not `vms.update.own` or a `vms.update` limited to fields or rows. A wildcard means all of it, so `vms.*` needs a role that holds `vms.*` or `*`. Anyone else gets a `403 function-forbidden` problem before the handler runs. Finer rules belong in the resources' [access rules](../reference/access.md), which `records` already applies.
|
|
102
102
|
|
|
103
|
-
In an app with [roles](../reference/access.md) (`
|
|
103
|
+
In an app with [roles](../reference/access.md) (`config/roles.ts`), a function with neither is closed like a resource without a rule: only callers whose roles hold `*`, such as `admin: ['*']`, may call it, unless `defaultAccess` is `allow`. A function for everyone signed in says so with its roles. In an app without roles, every signed-in caller may call it. A `capability` needs the app's roles, and a function takes `roles` or `capability`, not both: the server refuses to start otherwise.
|
|
104
104
|
|
|
105
105
|
## Public functions and webhooks
|
|
106
106
|
|
|
@@ -404,13 +404,13 @@ export default defineFunction({ longQueries: true }, async (request, { db }) =>
|
|
|
404
404
|
- **Up to 30 seconds** per query, the most any query of an app may run. Work longer than that belongs in steps, such as a [job](../reference/jobs.md) per batch, which takes `longQueries` too.
|
|
405
405
|
- **One connection kept for it.** Under `protobase dev` and `serve`, those queries run on a connection of their own, which asks for the longer timeout when it logs in, so long work never takes the connections pages need; a second long call waits for it. A PgBouncer of your own in front of the database must list `statement_timeout` in `track_extra_parameters` to pass that on; Protobase Cloud's does. With a `db` the project exports itself, the option changes nothing.
|
|
406
406
|
- **`records` keep the API's limit,** [`statementTimeoutMs`](../reference/api.md#safety).
|
|
407
|
-
- **A query past its limit** is stopped, and the call answers `504 statement-timeout` naming the call, its limit and the way out, such as `POST /api/functions/import ran a query longer than the database's statement timeout, so the database stopped it. Make the query faster, such as with an index or a narrower filter, or give it longQueries: true, whose queries may run up to 30 s.` It goes to `
|
|
407
|
+
- **A query past its limit** is stopped, and the call answers `504 statement-timeout` naming the call, its limit and the way out, such as `POST /api/functions/import ran a query longer than the database's statement timeout, so the database stopped it. Make the query faster, such as with an index or a narrower filter, or give it longQueries: true, whose queries may run up to 30 s.` It goes to the app's error hook, `hooks/error.ts`, and the [error tracker](../reference/api.md#error-reporting).
|
|
408
408
|
|
|
409
409
|
## Errors
|
|
410
410
|
|
|
411
411
|
- **Problems:** throw an `HttpProblem` (or `badRequest`, `unauthorized`, `forbidden`, `notFound` from `@protobase/server`) to answer with an [RFC 9457 problem](../reference/api.md#errors). Hono's `HTTPException` works too.
|
|
412
412
|
- **A query the database stopped** is a `504 statement-timeout` that names the call; see [Long queries](#long-queries).
|
|
413
|
-
- **Everything else:** any other error, or a handler that returns something other than a `Response`, becomes a `500 internal-error` problem without its message. The error goes to `
|
|
413
|
+
- **Everything else:** any other error, or a handler that returns something other than a `Response`, becomes a `500 internal-error` problem without its message. The error goes to the app's error hook, `hooks/error.ts`; without one, `protobase dev` and `serve` print it.
|
|
414
414
|
|
|
415
415
|
## Functions moved from Supabase
|
|
416
416
|
|
|
@@ -28,11 +28,11 @@ dist/
|
|
|
28
28
|
plugins and the app's version
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
-
The host serves `public/` itself and sends only the manifest's `api` paths to the runtime (`/api` and the two OAuth discovery documents of [MCP clients](../reference/auth.md#oauth-for-mcp-clients), and `/.well-known/webauthn`, for an app on [several origins](../reference/auth.md#several-origins)), so loading the UI never needs a running container. With the UI it sends `X-Frame-Options: DENY` and `Content-Security-Policy: frame-ancestors 'none'`, as `protobase serve` does, so no other site frames the app's pages. The runtime serves the API alone; `protobase serve dist` serves the whole folder the same way, to check a bundle locally. The host passes `DATABASE_URL`, `PORT` (default 8787) and optionally `PROTOBASE_DB_CONNECTIONS` (the connections the app may open, so its functions and jobs leave one to requests, see [`serve`](../reference/cli.md#serve)), `REQUEST_LOG`, `PROTOBASE_SMTP_URL` and `PROTOBASE_MAIL_FROM` (the mail server and sender for [password reset](../reference/auth.md#password-reset) and emailed sign-in codes) `PROTOBASE_APP_NAME` (the app's name in that mail, see [`appName`](../reference/auth.md#configuration)) `PROTOBASE_SIGN_IN_*` (a provider people with an account sign in with, the [platform sign-in provider](../reference/auth.md#platform-sign-in-provider)) `PROTOBASE_OPERATOR_*` (the provider its staff sign in with for [staff sign-in](../reference/auth.md#staff-sign-in)), `PROTOBASE_ORIGINS` and `PROTOBASE_PASSKEY_DOMAIN` (the app's [other origins](../reference/auth.md#several-origins) and its passkey domain) `PROTOBASE_CORS_ORIGINS` (the websites that may call its API, see [CORS](../reference/api.md#cors)), `PROTOBASE_TRUSTED_PROXIES` (the proxies in front of the runtime, whose `X-Forwarded-For` names the client the sign-in limits count, see [Client addresses](../reference/auth.md#client-addresses)) and `PROTOBASE_SENTRY_DSN` (the app's [error tracker](../reference/api.md#error-reporting)), plus the project's own settings
|
|
31
|
+
The host serves `public/` itself and sends only the manifest's `api` paths to the runtime (`/api` and the two OAuth discovery documents of [MCP clients](../reference/auth.md#oauth-for-mcp-clients), and `/.well-known/webauthn`, for an app on [several origins](../reference/auth.md#several-origins)), so loading the UI never needs a running container. With the UI it sends `X-Frame-Options: DENY` and `Content-Security-Policy: frame-ancestors 'none'`, as `protobase serve` does, so no other site frames the app's pages. The runtime serves the API alone; `protobase serve dist` serves the whole folder the same way, to check a bundle locally. The host passes `DATABASE_URL`, `PORT` (default 8787) and optionally `PROTOBASE_DB_CONNECTIONS` (the connections the app may open, so its functions and jobs leave one to requests, see [`serve`](../reference/cli.md#serve)), `REQUEST_LOG`, `PROTOBASE_SMTP_URL` and `PROTOBASE_MAIL_FROM` (the mail server and sender for [password reset](../reference/auth.md#password-reset) and emailed sign-in codes) `PROTOBASE_APP_NAME` (the app's name in that mail, see [`appName`](../reference/auth.md#configuration)) `PROTOBASE_SIGN_IN_*` (a provider people with an account sign in with, the [platform sign-in provider](../reference/auth.md#platform-sign-in-provider)) `PROTOBASE_OPERATOR_*` (the provider its staff sign in with for [staff sign-in](../reference/auth.md#staff-sign-in)), `PROTOBASE_ORIGINS` and `PROTOBASE_PASSKEY_DOMAIN` (the app's [other origins](../reference/auth.md#several-origins) and its passkey domain) `PROTOBASE_CORS_ORIGINS` (the websites that may call its API, see [CORS](../reference/api.md#cors)), `PROTOBASE_TRUSTED_PROXIES` (the proxies in front of the runtime, whose `X-Forwarded-For` names the client the sign-in limits count, see [Client addresses](../reference/auth.md#client-addresses)) and `PROTOBASE_SENTRY_DSN` (the app's [error tracker](../reference/api.md#error-reporting)), `PROTOBASE_URL` and `PROTOBASE_SECRET` (the app's address and secret, unless its config sets [`url` and `secret`](../reference/config.md#defaults)), plus the project's own settings, which its config reads where it serves. The runtime and the config module are plain JavaScript for Bun: no install, no TypeScript, no writes. The runtime supplies protobase and the dependencies it runs on the server (`pg`, `postgres`, `kysely`, `better-auth`, ...), so the config module carries only the project's code and the other packages it uses. The manifest's `protobase` is the version the project is pinned to, and the host serves the bundle on the runtime of that version (see [Versioning](../reference/versioning.md#bundles-and-runtimes)). The manifest format and the routing rules are in the CLI reference: [`build`](../reference/cli.md#build), [`build-serve`](../reference/cli.md#build-serve) and [`serve`](../reference/cli.md#serve).
|
|
32
32
|
|
|
33
33
|
## Migrations
|
|
34
34
|
|
|
35
|
-
Serving never changes the database: the bundle carries the project's `db/migrations` as `migrations/`, and the runtime's `migrate <bundle>` applies the pending ones, the app's and the auth schema's, before a new version serves, with no other writes while it runs. It applies them in one transaction behind a lock, recorded in `public.schema_migrations` as the presets' `db:migrate` does, so a database either script migrated is current for the other. A file that would end that transaction (`BEGIN`, `COMMIT`, `ROLLBACK`) or cannot run in one (`create index concurrently`) is refused, and a refused or failing file leaves the database unchanged. The runtime refuses to start while the auth
|
|
35
|
+
Serving never changes the database: the bundle carries the project's `db/migrations` as `migrations/`, and the runtime's `migrate <bundle>` applies the pending ones, the app's and the auth schema's, before a new version serves, with no other writes while it runs. It applies them in one transaction behind a lock, recorded in `public.schema_migrations` as the presets' `db:migrate` does, so a database either script migrated is current for the other. A file that would end that transaction (`BEGIN`, `COMMIT`, `ROLLBACK`) or cannot run in one (`create index concurrently`) is refused, and a refused or failing file leaves the database unchanged. The runtime refuses to start while the auth store has not applied every auth migration of the new version, which it reads from the store's `auth_migrations` table without comparing its tables (see [migrations](../reference/auth.md#migrations)). [`protobase migration`](../reference/cli.md#migration) writes the files the config's features need, such as the auth and jobs schemas, as the project's own migrations, and [a self-hosted image](#a-self-hosted-image) runs `migrate` as a step of its own before the app starts.
|
|
36
36
|
|
|
37
37
|
## Images
|
|
38
38
|
|
|
@@ -44,7 +44,7 @@ Every release pushes two public images to GitHub's registry, for `linux/amd64` a
|
|
|
44
44
|
| `ghcr.io/prototeamhq/protobase-dev:<version>` | Bun and the presets at `/opt/protobase/presets/<name>` (`erp`, `real-estate`, `scratch`), with the dependencies they share installed in `/workspace` and Bun's cache in `/opt/bun-cache`. It has no Node: the presets' scripts and the `protobase` command run on Bun. It runs as `bun` (1000) |
|
|
45
45
|
|
|
46
46
|
```sh
|
|
47
|
-
docker run -v "$PWD/dist:/app:ro" -p 127.0.0.1:8787:8787 -e DATABASE_URL -e
|
|
47
|
+
docker run -v "$PWD/dist:/app:ro" -p 127.0.0.1:8787:8787 -e DATABASE_URL -e PROTOBASE_URL -e PROTOBASE_SECRET ghcr.io/prototeamhq/protobase:0.2.0
|
|
48
48
|
```
|
|
49
49
|
|
|
50
50
|
In `protobase-dev`, copy a preset into `/workspace` and `bun install --frozen-lockfile` has nothing to do; installed anywhere else, it comes from the cache, without the network.
|
|
@@ -87,12 +87,12 @@ APP_DB_PASSWORD=... # openssl rand -hex 24
|
|
|
87
87
|
`app.env`, the app's own settings:
|
|
88
88
|
|
|
89
89
|
```sh
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
PROTOBASE_SECRET=... # openssl rand -base64 32
|
|
91
|
+
PROTOBASE_URL=http://localhost:8787
|
|
92
92
|
PROTOBASE_TRUSTED_PROXIES=172.30.87.1
|
|
93
93
|
```
|
|
94
94
|
|
|
95
|
-
`
|
|
95
|
+
`PROTOBASE_URL` is the address the browser opens, exactly: sign-in from `http://127.0.0.1:8787` is refused as another origin. `PROTOBASE_TRUSTED_PROXIES` is the compose network's gateway, which every connection through the published port comes from, a reverse proxy's included; trusting it lets the sign-in limits count each client by the proxy's `X-Forwarded-For` (see [Client addresses](../reference/auth.md#client-addresses)). Add the app's other variables to `app.env` too.
|
|
96
96
|
|
|
97
97
|
```yaml
|
|
98
98
|
services:
|
|
@@ -165,7 +165,7 @@ app.example.com {
|
|
|
165
165
|
}
|
|
166
166
|
```
|
|
167
167
|
|
|
168
|
-
Then set `
|
|
168
|
+
Then set `PROTOBASE_URL=https://app.example.com` in `app.env` and run `docker compose up -d` to apply it. Only then are the session cookies `Secure` and passwords and codes encrypted on the way. Another proxy must also append the client's address to `X-Forwarded-For` (see [Client addresses](../reference/auth.md#client-addresses)), or every visitor shares one sign-in limit. Do not change the port to `8787:8787`: that publishes plain HTTP on every interface, ahead of host firewall rules such as ufw. On Docker Engine older than 28.0, hosts on the same local network can still reach a port published to `127.0.0.1`, so use 28.0 or newer.
|
|
169
169
|
|
|
170
170
|
### First admin
|
|
171
171
|
|
|
@@ -173,7 +173,7 @@ Then set `BETTER_AUTH_URL=https://app.example.com` in `app.env` and run `docker
|
|
|
173
173
|
docker compose run --rm --no-deps app create-admin /app you@example.com --generate-password
|
|
174
174
|
```
|
|
175
175
|
|
|
176
|
-
Then open the address in `
|
|
176
|
+
Then open the address in `PROTOBASE_URL` and sign in with that email and the printed password: `https://app.example.com` once the proxy is in front, `http://localhost:8787` (or the SSH tunnel) only while `PROTOBASE_URL` is still `http://localhost:8787`, since sign-in from any other address is refused as another origin. `--no-deps` keeps compose from running `migrate` first, which during an upgrade would migrate under the old version while it serves; use it with every `docker compose run … app`. Where container logs leave the host, pass the password on stdin instead: `docker compose run --rm --no-deps -T app create-admin /app you@example.com --password-stdin < password.txt`.
|
|
177
177
|
|
|
178
178
|
### Upgrade
|
|
179
179
|
|
|
@@ -13,16 +13,16 @@ Protobase never changes your tables. Sign-in is the one thing it adds to the dat
|
|
|
13
13
|
In a new folder, next to the database's own code or anywhere else:
|
|
14
14
|
|
|
15
15
|
```sh
|
|
16
|
-
npm install @protobase/cli @protobase/schema @protobase/layout @protobase/server @protobase/ui pg kysely
|
|
16
|
+
npm install @protobase/cli @protobase/config @protobase/schema @protobase/layout @protobase/server @protobase/ui pg kysely
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
Then a `.env` beside it, which every `protobase` command reads:
|
|
20
20
|
|
|
21
21
|
```sh
|
|
22
22
|
DATABASE_URL=postgres://user:password@localhost:5432/shop
|
|
23
|
-
#
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
# The app's secret, which signs session cookies: generate your own with openssl rand -base64 32
|
|
24
|
+
PROTOBASE_SECRET=
|
|
25
|
+
PROTOBASE_URL=http://localhost:5173
|
|
26
26
|
```
|
|
27
27
|
|
|
28
28
|
Keep `.env` out of version control.
|
|
@@ -45,39 +45,19 @@ It checks the config against the database: each table and column exists, each ty
|
|
|
45
45
|
|
|
46
46
|
## 4. Add sign-in
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
Sign-in is on by default: it takes the app's address and secret from `PROTOBASE_URL` and `PROTOBASE_SECRET` in `.env`, and keeps users, sessions and signing keys in an `auth` schema of their own, next to your tables. `protobase.config.ts` says the rest; the resources in `config/` are found by that path:
|
|
49
49
|
|
|
50
50
|
```ts
|
|
51
|
-
import
|
|
52
|
-
import { auth, authenticate } from './auth/auth'
|
|
51
|
+
import { defineConfig } from '@protobase/config'
|
|
53
52
|
|
|
54
|
-
export default {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
```ts
|
|
60
|
-
import { PostgresDialect } from 'kysely'
|
|
61
|
-
import pg from 'pg'
|
|
62
|
-
import { appPool, betterAuthAuthenticator, createAuth } from '@protobase/server'
|
|
63
|
-
|
|
64
|
-
const secret = process.env.BETTER_AUTH_SECRET
|
|
65
|
-
if (!secret) throw new Error('BETTER_AUTH_SECRET is not set: put the output of `openssl rand -base64 32` in .env')
|
|
66
|
-
|
|
67
|
-
// The app's one pool on DATABASE_URL, which `protobase dev` and `serve` share.
|
|
68
|
-
const pool = appPool(pg, process.env.DATABASE_URL!)
|
|
69
|
-
|
|
70
|
-
export const auth = createAuth({
|
|
71
|
-
// Users, sessions and signing keys live in a schema of their own, next to your tables.
|
|
72
|
-
database: { dialect: new PostgresDialect({ pool }), type: 'postgres', schemaName: 'auth', transaction: true },
|
|
73
|
-
baseURL: process.env.BETTER_AUTH_URL ?? 'http://localhost:5173',
|
|
74
|
-
secret,
|
|
53
|
+
export default defineConfig({
|
|
54
|
+
auth: { roles: ['admin'] },
|
|
55
|
+
// Everyone works in tenant 1.
|
|
56
|
+
authenticate: { tenant: 1 },
|
|
75
57
|
})
|
|
76
|
-
|
|
77
|
-
export const authenticate = betterAuthAuthenticator({ auth, tenant: 1 })
|
|
78
58
|
```
|
|
79
59
|
|
|
80
|
-
The [
|
|
60
|
+
The [config reference](../reference/config.md) has every key, and the [auth reference](../reference/auth.md) the rest of sign-in: emailed codes, passkeys, two-factor, roles, and a users table the database already has.
|
|
81
61
|
|
|
82
62
|
## 5. Write and apply the auth tables
|
|
83
63
|
|
|
@@ -157,7 +157,7 @@ Reload the app. The card shows three orders, and the app was neither rebuilt nor
|
|
|
157
157
|
|
|
158
158
|
## 7. Ship it
|
|
159
159
|
|
|
160
|
-
Put `dist/` on a static host, and list its `plugin.json` in the deployed app's `PROTOBASE_PLUGINS`, or in `
|
|
160
|
+
Put `dist/` on a static host, and list its `plugin.json` in the deployed app's `PROTOBASE_PLUGINS`, or in the `plugins` of its `protobase.config.ts`, which can also give the plugin settings and limit it to some roles (see [loading](../reference/plugins.md#loading)). Serve `plugin.json` without caching, so a new build reaches the apps on their next load, and the files in `assets/`, whose names change with their content, as long as you like.
|
|
161
161
|
|
|
162
162
|
## When the app moves on
|
|
163
163
|
|
|
@@ -21,6 +21,8 @@ Set their variables, such as `ANDROID_HOME` and `JAVA_HOME`, in your shell, not
|
|
|
21
21
|
|
|
22
22
|
```ts
|
|
23
23
|
// protobase.config.ts
|
|
24
|
+
import { defineConfig } from '@protobase/config'
|
|
25
|
+
|
|
24
26
|
export default defineConfig({
|
|
25
27
|
// ...
|
|
26
28
|
mobile: {
|
|
@@ -33,7 +35,7 @@ export default defineConfig({
|
|
|
33
35
|
- `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
36
|
- `plugins`, optional, are extra native [Capacitor plugins](https://capacitorjs.com/docs/plugins), npm name to version. Capacitor itself, `@capacitor/app`, `@capacitor/keyboard`, `@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
37
|
|
|
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, `
|
|
38
|
+
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, the config's `name` or `PROTOBASE_APP_NAME` in its environment, and `build` stops.
|
|
37
39
|
|
|
38
40
|
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
41
|
|
|
@@ -59,7 +61,7 @@ The first run installs Capacitor into `.protobase/mobile/`, which ignores itself
|
|
|
59
61
|
|
|
60
62
|
In the app, the admin keeps clear of the status bar, the notch, the home indicator and Android's system bars, and it does not zoom: a focused input leaves the page at its scale, and so does a pinch. <gap>The status bar's text cannot follow the theme chosen in the app, only the phone's light or dark mode, because setting the status bar's style is not implemented.</gap>
|
|
61
63
|
|
|
62
|
-
The app calls the server at the
|
|
64
|
+
The app calls the server at the app's `url` (`PROTOBASE_URL` by default); pass `--api https://shop.example.com` for another one. Plain http is only for a server on this machine (`localhost`) or, on the Android emulator, its host `10.0.2.2`; any other server needs https. An Android phone on USB reaches a server on `localhost` through a forwarded port; an iPhone needs an https server. The app's UI plugins load from the device only when the server serves a built bundle (`protobase serve dist`): against `protobase dev`, use `--live`.
|
|
63
65
|
|
|
64
66
|
`--target <id>` picks the simulator, emulator or device; without it Capacitor asks.
|
|
65
67
|
|
|
@@ -98,7 +100,7 @@ protobase mobile build ios --app-version 1.2.3 --build-number 7 --api https://sh
|
|
|
98
100
|
makes a signed release binary: an `.aab` to upload to Google Play, an `.ipa` to upload to App Store Connect. It goes to `mobile-release/`, which ignores itself in git, named `<appId>-<version>-<build number>`; `--out <dir>` picks another folder.
|
|
99
101
|
|
|
100
102
|
- The binary carries the app's files, so it opens without a network and never downloads anything on its first launch; offline it says it cannot reach the server, as the web app does.
|
|
101
|
-
- A release calls its server over https, at `--api` or the
|
|
103
|
+
- A release calls its server over https, at `--api` or the app's `url`: plain http, `localhost` and `10.0.2.2` are refused.
|
|
102
104
|
- `--app-version` is the version the stores show, one to three numbers such as `1.2.3`. `--build-number` is a whole number that must rise with every upload, such as your CI's run number.
|
|
103
105
|
- Extra plugins run at build time with access to your signing key, so add only plugins you trust.
|
|
104
106
|
|
|
@@ -47,7 +47,7 @@ The project's Tailwind classes are built into the plugin's own stylesheet, `plug
|
|
|
47
47
|
|
|
48
48
|
## 4. Extensions
|
|
49
49
|
|
|
50
|
-
Each `--extend` folder's `protobase.ui.tsx` becomes a plugin of its own, `plugins/<name>/`, named by its `package.json`, else its folder, and merged before the project's, as before. Its
|
|
50
|
+
Each `--extend` folder's `protobase.ui.tsx` becomes a plugin of its own, `plugins/<name>/`, named by its `package.json`, else its folder, and merged before the project's, as before. Its config, with the code its paths find, goes into the config module and is merged before the project's when the bundle is served (see [Extensions](../reference/config.md#extensions)). Two extensions that would be plugins of one name fail the build: give one's `package.json` another `name`.
|
|
51
51
|
|
|
52
52
|
## 5. Hosts
|
|
53
53
|
|