@protobase/cli 0.119.6 → 0.121.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/bundle-plugins.js +1 -1
- package/dist/build/plugin-build.js +15 -8
- package/dist/build/{plugin-fields.js → plugin-config.js} +28 -19
- package/dist/build/shared-imports.js +35 -0
- package/dist/bundle/manifest.js +2 -2
- package/dist/cli/package.js +1 -1
- package/dist/main.js +1 -1
- package/dist/supabase/auth-config.js +27 -4
- package/package.json +8 -8
- package/skills/protobase/references/features/sign-in-and-accounts.md +1 -0
- package/skills/protobase/references/features/your-own-code.md +2 -1
- package/skills/protobase/references/guides/first-plugin.md +5 -4
- package/skills/protobase/references/guides/plugin-build.md +1 -1
- package/skills/protobase/references/reference/auth.md +33 -4
- package/skills/protobase/references/reference/cli.md +4 -4
- package/skills/protobase/references/reference/config/sign-in.md +17 -4
- package/skills/protobase/references/reference/config.md +1 -1
- package/skills/protobase/references/reference/jobs.md +1 -1
- package/skills/protobase/references/reference/notifications.md +1 -1
- package/skills/protobase/references/reference/plugins.md +21 -12
- package/skills/protobase/references/reference/versioning.md +1 -1
|
@@ -56,7 +56,7 @@ const buildBundlePlugins = async ({ projectDir, publicDir, extensions, styles =
|
|
|
56
56
|
name: manifest.name,
|
|
57
57
|
path: `${folder}/${pluginManifestFile}`,
|
|
58
58
|
api: manifest.api,
|
|
59
|
-
protobase: manifest.protobase,
|
|
59
|
+
...manifest.protobase && { protobase: manifest.protobase },
|
|
60
60
|
...manifest.fields && { fields: manifest.fields }
|
|
61
61
|
});
|
|
62
62
|
}
|
|
@@ -4,7 +4,8 @@ import { uiPackageDir } from "../project/admin-app.js";
|
|
|
4
4
|
import { extensionImports } from "../project/extensions.js";
|
|
5
5
|
import { bundledImports } from "../project/bundled-imports.js";
|
|
6
6
|
import { sharedModules } from "../project/shared-modules.js";
|
|
7
|
-
import {
|
|
7
|
+
import { readPluginConfig } from "./plugin-config.js";
|
|
8
|
+
import { sharedImports } from "./shared-imports.js";
|
|
8
9
|
import { layerPluginUtilities } from "./plugin-styles.js";
|
|
9
10
|
import { firstPartyCode } from "./first-party-code.js";
|
|
10
11
|
import { createRequire } from "node:module";
|
|
@@ -26,9 +27,9 @@ const targetUiDir = (pluginDir, projectDir, bundled) => {
|
|
|
26
27
|
return findPackageDirSync("@protobase/ui", pluginDir) ?? (projectDir === void 0 ? void 0 : findPackageDirSync("@protobase/ui", projectDir)) ?? uiPackageDir;
|
|
27
28
|
};
|
|
28
29
|
/**
|
|
29
|
-
* What the plugin is built for, from its @protobase/ui (see `targetUiDir`): its plugin API, and Protobase
|
|
30
|
-
*
|
|
31
|
-
*
|
|
30
|
+
* What the plugin is built for, from its @protobase/ui (see `targetUiDir`): its plugin API, and the Protobase versions
|
|
31
|
+
* the plugin's package.json names in `engines.protobase`, if any. Also that version's theme, which the plugin's
|
|
32
|
+
* stylesheet draws with, and its folder.
|
|
32
33
|
*/
|
|
33
34
|
const pluginTarget = async (pluginDir, own, projectDir, bundled) => {
|
|
34
35
|
const uiDir = targetUiDir(pluginDir, projectDir, bundled);
|
|
@@ -36,8 +37,8 @@ const pluginTarget = async (pluginDir, own, projectDir, bundled) => {
|
|
|
36
37
|
const api = ui.protobase?.pluginApi;
|
|
37
38
|
const theme = ui.exports?.["./theme.css"];
|
|
38
39
|
if (api === void 0 || typeof theme !== "string") throw new Error(`@protobase/ui ${ui.version} loads no plugins; install a version that does`);
|
|
39
|
-
const protobase = own.engines?.protobase
|
|
40
|
-
if (inRange(ui.version ?? "", protobase) === void 0) throw new Error(`engines.protobase "${protobase}" is not a range the app reads; write comparators such as >=0.12.0 <1.0.0`);
|
|
40
|
+
const protobase = own.engines?.protobase;
|
|
41
|
+
if (protobase !== void 0 && inRange(ui.version ?? "", protobase) === void 0) throw new Error(`engines.protobase "${protobase}" is not a range the app reads; write comparators such as >=0.12.0 <1.0.0`);
|
|
41
42
|
return {
|
|
42
43
|
api,
|
|
43
44
|
protobase,
|
|
@@ -153,18 +154,24 @@ const buildPlugin = async ({ pluginDir, outDir, name, projectDir, ignore = [], s
|
|
|
153
154
|
const module = output.find((file) => file.type === "chunk" && file.isEntry && file.facadeModuleId === entry);
|
|
154
155
|
const css = output.find((file) => file.type === "asset" && file.fileName.endsWith(".css"));
|
|
155
156
|
if (!module || !css) throw new Error("The plugin build wrote no module or no stylesheet");
|
|
156
|
-
const fields = stylesOnly ? {
|
|
157
|
+
const { fields, extensionPoints } = stylesOnly ? {
|
|
158
|
+
fields: {},
|
|
159
|
+
extensionPoints: []
|
|
160
|
+
} : await readPluginConfig({
|
|
157
161
|
pluginDir,
|
|
158
162
|
entry,
|
|
159
163
|
uiDir: target.uiDir,
|
|
160
164
|
projectDir,
|
|
161
165
|
bundled
|
|
162
166
|
});
|
|
167
|
+
const chunks = output.flatMap((file) => file.type === "chunk" ? [file] : []);
|
|
163
168
|
const manifest = {
|
|
164
169
|
name: pluginName,
|
|
165
170
|
...own.version && { version: own.version },
|
|
166
171
|
api: target.api,
|
|
167
|
-
protobase: target.protobase,
|
|
172
|
+
...target.protobase !== void 0 && { protobase: target.protobase },
|
|
173
|
+
imports: sharedImports(chunks),
|
|
174
|
+
extensionPoints,
|
|
168
175
|
entry: module.fileName,
|
|
169
176
|
css: css.fileName,
|
|
170
177
|
...Object.keys(fields).length > 0 && { fields }
|
|
@@ -7,41 +7,46 @@ import path from "node:path";
|
|
|
7
7
|
import { pathToFileURL } from "node:url";
|
|
8
8
|
import { mkdtemp, rm } from "node:fs/promises";
|
|
9
9
|
import { tmpdir } from "node:os";
|
|
10
|
-
//#region src/build/plugin-
|
|
11
|
-
const
|
|
10
|
+
//#region src/build/plugin-config.ts
|
|
11
|
+
const configCode = (entry) => [
|
|
12
12
|
`import * as ui from ${JSON.stringify(entry)}`,
|
|
13
|
-
`import
|
|
14
|
-
"const
|
|
15
|
-
"
|
|
13
|
+
`import * as protobaseUi from '@protobase/ui'`,
|
|
14
|
+
"const merged = protobaseUi.mergeUi(protobaseUi.uiFromModule(ui))",
|
|
15
|
+
"const { fields = {} } = merged",
|
|
16
|
+
"export default {",
|
|
17
|
+
" fields: Object.fromEntries(Object.entries(fields).map(([name, type]) => [name, type.of])),",
|
|
18
|
+
" extensionPoints: protobaseUi.extensionPointsOf?.(merged),",
|
|
19
|
+
"}",
|
|
16
20
|
""
|
|
17
21
|
].join("\n");
|
|
18
|
-
const
|
|
19
|
-
name: "protobase-plugin-
|
|
22
|
+
const configEntry = (file, code) => ({
|
|
23
|
+
name: "protobase-plugin-config",
|
|
20
24
|
resolveId: (id) => id === file ? `\0${file}` : void 0,
|
|
21
25
|
load: (id) => id === `\0${file}` ? code : void 0
|
|
22
26
|
});
|
|
23
27
|
const sharedFromUi = (uiDir) => {
|
|
24
28
|
const require = createRequire(path.join(uiDir, "package.json"));
|
|
25
29
|
return {
|
|
26
|
-
name: "protobase-plugin-
|
|
30
|
+
name: "protobase-plugin-config-shared",
|
|
27
31
|
enforce: "pre",
|
|
28
32
|
resolveId: (id) => id === "@protobase/ui" || !sharedModules.includes(id) ? void 0 : require.resolve(id)
|
|
29
33
|
};
|
|
30
34
|
};
|
|
31
|
-
const
|
|
35
|
+
const isNames = (value) => Array.isArray(value) && value.every((item) => typeof item === "string");
|
|
32
36
|
/**
|
|
33
37
|
* The field types a plugin registers (`definePlugin({ fields })`), each with the storage types it shows (`of`), which
|
|
34
|
-
* the server checks the views against at startup
|
|
38
|
+
* the server checks the views against at startup, and the extension points it fills, which the app checks it has
|
|
39
|
+
* before it loads the plugin (see `extensionPointsOf` in @protobase/ui). The plugin's module is loaded once in Node, everything bundled into
|
|
35
40
|
* a scratch file, as `protobase build` loads a project's UI to check its names; nothing is rendered. A plugin of a
|
|
36
41
|
* bundled project imports the CLI's @protobase packages, as its build does.
|
|
37
42
|
*/
|
|
38
|
-
const
|
|
39
|
-
const file = path.join(pluginDir, "protobase-plugin-
|
|
40
|
-
const scratch = await mkdtemp(path.join(tmpdir(), "protobase-plugin-
|
|
41
|
-
const outFile = path.join(scratch, "
|
|
43
|
+
const readPluginConfig = async ({ pluginDir, entry, uiDir, projectDir, bundled = false }) => {
|
|
44
|
+
const file = path.join(pluginDir, "protobase-plugin-config.js");
|
|
45
|
+
const scratch = await mkdtemp(path.join(tmpdir(), "protobase-plugin-config-"));
|
|
46
|
+
const outFile = path.join(scratch, "config.mjs");
|
|
42
47
|
try {
|
|
43
48
|
const plugins = [
|
|
44
|
-
|
|
49
|
+
configEntry(file, configCode(entry)),
|
|
45
50
|
sharedFromUi(uiDir),
|
|
46
51
|
...bundled && projectDir !== void 0 ? [bundledImports([projectDir, pluginDir])] : [],
|
|
47
52
|
...projectDir === void 0 ? [] : [extensionImports(projectDir, [{ dir: pluginDir }])]
|
|
@@ -53,10 +58,14 @@ const pluginFieldTypes = async ({ pluginDir, entry, uiDir, projectDir, bundled =
|
|
|
53
58
|
plugins,
|
|
54
59
|
logLevel: "error"
|
|
55
60
|
});
|
|
56
|
-
const fields = (await import(pathToFileURL(outFile).href)).default;
|
|
57
|
-
const wrong = Object.entries(fields).find(([, of]) => !
|
|
61
|
+
const { fields, extensionPoints } = (await import(pathToFileURL(outFile).href)).default;
|
|
62
|
+
const wrong = Object.entries(fields).find(([, of]) => !isNames(of));
|
|
58
63
|
if (wrong) throw new Error(`The field type "${wrong[0]}" names no storage types it shows; give it of: ['integer'] or the like`);
|
|
59
|
-
|
|
64
|
+
if (!isNames(extensionPoints)) throw new Error(`The @protobase/ui in ${uiDir} does not name the extension points a plugin fills; install a version that does`);
|
|
65
|
+
return {
|
|
66
|
+
fields,
|
|
67
|
+
extensionPoints
|
|
68
|
+
};
|
|
60
69
|
} finally {
|
|
61
70
|
await rm(scratch, {
|
|
62
71
|
recursive: true,
|
|
@@ -65,4 +74,4 @@ const pluginFieldTypes = async ({ pluginDir, entry, uiDir, projectDir, bundled =
|
|
|
65
74
|
}
|
|
66
75
|
};
|
|
67
76
|
//#endregion
|
|
68
|
-
export {
|
|
77
|
+
export { readPluginConfig };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { sharedModules } from "../project/shared-modules.js";
|
|
2
|
+
import { parseAst } from "vite";
|
|
3
|
+
//#region src/build/shared-imports.ts
|
|
4
|
+
const isShared = (source) => typeof source === "string" && sharedModules.includes(source);
|
|
5
|
+
const takenName = (specifier) => {
|
|
6
|
+
if (specifier.type === "ImportDefaultSpecifier") return "default";
|
|
7
|
+
if (specifier.type === "ImportNamespaceSpecifier") return "*";
|
|
8
|
+
const taken = specifier.type === "ExportSpecifier" ? specifier.local : specifier.imported;
|
|
9
|
+
return taken?.name ?? taken?.value ?? "*";
|
|
10
|
+
};
|
|
11
|
+
const byNameOnly = "@protobase/ui";
|
|
12
|
+
/**
|
|
13
|
+
* The names a plugin's built chunks take from each module shared with plugins, sorted: what is left once the build
|
|
14
|
+
* has dropped unused code, from its imports, re-exports and `export *`, and `*` for a whole module it imports with
|
|
15
|
+
* `import * as` or `import()`. Taking @protobase/ui whole fails the build, since the app could not tell whether it
|
|
16
|
+
* has the names the plugin reads.
|
|
17
|
+
*/
|
|
18
|
+
const sharedImports = (chunks) => {
|
|
19
|
+
const taken = /* @__PURE__ */ new Map();
|
|
20
|
+
const take = (module, name) => taken.set(module, (taken.get(module) ?? /* @__PURE__ */ new Set()).add(name));
|
|
21
|
+
for (const chunk of chunks) {
|
|
22
|
+
for (const module of chunk.dynamicImports.filter(isShared)) take(module, "*");
|
|
23
|
+
for (const node of parseAst(chunk.code).body) {
|
|
24
|
+
if (node.type !== "ImportDeclaration" && node.type !== "ExportNamedDeclaration" && node.type !== "ExportAllDeclaration") continue;
|
|
25
|
+
const source = node.source?.value;
|
|
26
|
+
if (!isShared(source)) continue;
|
|
27
|
+
if (node.type === "ExportAllDeclaration") take(source, "*");
|
|
28
|
+
else for (const specifier of node.specifiers) take(source, takenName(specifier));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (taken.get(byNameOnly)?.has("*")) throw new Error(`The plugin takes all of ${byNameOnly} (import * as, export * or import()), so an app cannot check that it has what the plugin uses: import the names it uses instead, as in import { useList } from '${byNameOnly}'`);
|
|
32
|
+
return Object.fromEntries([...taken].sort(([a], [b]) => a < b ? -1 : 1).map(([module, names]) => [module, [...names].sort()]));
|
|
33
|
+
};
|
|
34
|
+
//#endregion
|
|
35
|
+
export { sharedImports };
|
package/dist/bundle/manifest.js
CHANGED
|
@@ -17,7 +17,7 @@ const bundleMigrations = "migrations";
|
|
|
17
17
|
const isStringList = (value) => Array.isArray(value) && value.every((item) => typeof item === "string");
|
|
18
18
|
const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
19
19
|
const isFieldTypes = (value) => isObject(value) && Object.values(value).every(isStringList);
|
|
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));
|
|
20
|
+
const isPlugin = (value) => isObject(value) && typeof value.name === "string" && typeof value.path === "string" && Number.isInteger(value.api) && (value.protobase === void 0 || 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) && (value.builtAt === void 0 || isTime(value.builtAt));
|
|
22
22
|
const isTime = (value) => Number.isSafeInteger(value) && value >= 0;
|
|
23
23
|
const isVersions = (value) => isObject(value) && Object.values(value).every((item) => typeof item === "string");
|
|
@@ -27,7 +27,7 @@ const parseManifest = (value, file) => {
|
|
|
27
27
|
if (manifest?.version !== 3) throw new Error(`${file} is not a version 3 bundle manifest; rebuild it with \`protobase build\``);
|
|
28
28
|
const { builtAt, server, public: publicDir, api, spa, plugins, theme, shell, icons, native, mobile, nodeModules, migrations } = manifest;
|
|
29
29
|
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`);
|
|
30
|
-
if (!Array.isArray(plugins) || !plugins.every(isPlugin)) throw new Error(`${file} needs a plugins list, each with a name, path
|
|
30
|
+
if (!Array.isArray(plugins) || !plugins.every(isPlugin)) throw new Error(`${file} needs a plugins list, each with a name, path and api`);
|
|
31
31
|
if (!isShell(shell)) throw new Error(`${file} needs a shell with its protobase version, pluginApi and paths`);
|
|
32
32
|
if (builtAt !== void 0 && !isTime(builtAt)) throw new Error(`${file} has a builtAt that is no time in ms`);
|
|
33
33
|
if (icons !== void 0 && !isIcons(icons)) throw new Error(`${file} has icons that are not a favicon flag and a list of PNG icons`);
|
package/dist/cli/package.js
CHANGED
package/dist/main.js
CHANGED
|
@@ -147,7 +147,7 @@ program.command("build-plugin").description("Build a plugin the admin app loads
|
|
|
147
147
|
...opts.name && { name: opts.name }
|
|
148
148
|
});
|
|
149
149
|
const shown = path.relative(process.cwd(), outDir);
|
|
150
|
-
out(`built ${shown.startsWith("..") ? outDir : shown || "."}: ${pluginManifestFile}, ${manifest.entry} and ${manifest.css} (${manifest.name}, plugin API ${manifest.api}
|
|
150
|
+
out(`built ${shown.startsWith("..") ? outDir : shown || "."}: ${pluginManifestFile}, ${manifest.entry} and ${manifest.css} (${manifest.name}, plugin API ${manifest.api}${manifest.protobase ? `, Protobase ${manifest.protobase}` : ""})\n`);
|
|
151
151
|
});
|
|
152
152
|
program.command("build-shell", { hidden: true }).description("Build the admin app every bundle shares, as @protobase/ui's package and the protobase image ship it").argument("<out>", "output folder").option("--source-maps <dir>", "end each script with a //# debugId= comment and write its source map, carrying the same id, to this folder").action(async (outDir, opts) => {
|
|
153
153
|
const { buildShell } = await import("./build/shell.js");
|
|
@@ -6,9 +6,11 @@ import { Node } from "ts-morph";
|
|
|
6
6
|
//#region src/supabase/auth-config.ts
|
|
7
7
|
/** The `auth` settings for Supabase's auth.users as the user table, on a copy of the database the import owns. */
|
|
8
8
|
const supabaseUsers = {
|
|
9
|
+
tables: { user: {
|
|
10
|
+
name: "users",
|
|
11
|
+
columns: { role: "app_role" }
|
|
12
|
+
} },
|
|
9
13
|
users: {
|
|
10
|
-
table: "users",
|
|
11
|
-
columns: { role: "app_role" },
|
|
12
14
|
metadata: "raw_user_meta_data",
|
|
13
15
|
guardedSchemas: ["auth"]
|
|
14
16
|
},
|
|
@@ -20,6 +22,7 @@ const sharedUsersSchema = "app_auth";
|
|
|
20
22
|
/** The `auth` settings for a view over Supabase's auth.users, on a Supabase database the app shares with Supabase Auth. */
|
|
21
23
|
const supabaseUsersView = {
|
|
22
24
|
schema: sharedUsersSchema,
|
|
25
|
+
tables: supabaseUsers.tables,
|
|
23
26
|
users: {
|
|
24
27
|
...supabaseUsers.users,
|
|
25
28
|
keyTable: {
|
|
@@ -58,7 +61,8 @@ const literal = (value) => {
|
|
|
58
61
|
const settingsText = ({ settings, comment }, indent) => [...comment.map((line) => `// ${line}`), ...Object.entries(settings).map(([key, value]) => `${key}: ${literal(value)},`)].map((line) => `${indent}${line}`).join("\n");
|
|
59
62
|
/**
|
|
60
63
|
* protobase.config.ts with the settings first in its `auth`, or with an `auth` of them when it has none, sign-in being
|
|
61
|
-
* on by default; fails, naming what to add, when it exports no object the import can see
|
|
64
|
+
* on by default; fails, naming what to add, when it exports no object the import can see, its `auth` is not one, or
|
|
65
|
+
* its `auth.tables` is not one or names a table the settings name.
|
|
62
66
|
*/
|
|
63
67
|
const withSupabaseUsers = (text, file, users) => {
|
|
64
68
|
const config = exportedConfigObject(text).object;
|
|
@@ -72,10 +76,29 @@ const withSupabaseUsers = (text, file, users) => {
|
|
|
72
76
|
}
|
|
73
77
|
const object = Node.isPropertyAssignment(auth) ? auth.getInitializer() : void 0;
|
|
74
78
|
if (!object || !Node.isObjectLiteralExpression(object)) throw refused();
|
|
79
|
+
const ownTables = ownTablesOf(object, users, refused);
|
|
80
|
+
const { tables: settingsTables, ...settings } = users.settings;
|
|
81
|
+
const merged = ownTables && settingsTables ? withTables(text, ownTables.getStart() + 1, settingsTables, ownTables.getProperties().length > 0) : text;
|
|
75
82
|
const first = object.getProperties()[0];
|
|
76
83
|
const indent = first ? " ".repeat(first.getStartLinePos() === first.getStart() ? 0 : first.getStart() - first.getStartLinePos()) : " ";
|
|
77
84
|
const at = object.getStart() + 1;
|
|
78
|
-
|
|
85
|
+
const written = {
|
|
86
|
+
...users,
|
|
87
|
+
settings: ownTables ? settings : users.settings
|
|
88
|
+
};
|
|
89
|
+
return `${merged.slice(0, at)}\n${settingsText(written, indent)}${first ? "" : "\n"}${merged.slice(at)}`;
|
|
90
|
+
};
|
|
91
|
+
const ownTablesOf = (auth, users, refused) => {
|
|
92
|
+
const tables = auth.getProperty("tables");
|
|
93
|
+
if (!tables) return;
|
|
94
|
+
const own = Node.isPropertyAssignment(tables) ? tables.getInitializer() : void 0;
|
|
95
|
+
if (!own || !Node.isObjectLiteralExpression(own)) throw refused();
|
|
96
|
+
if (Object.keys(users.settings.tables ?? {}).some((table) => own.getProperty(table))) throw refused();
|
|
97
|
+
return own;
|
|
98
|
+
};
|
|
99
|
+
const withTables = (text, at, tables, more) => {
|
|
100
|
+
const entries = Object.entries(tables).map(([table, names]) => `${table}: ${literal(names)}`).join(", ");
|
|
101
|
+
return `${text.slice(0, at)} ${entries}${more ? "," : " "}${text.slice(at)}`;
|
|
79
102
|
};
|
|
80
103
|
/** Where the app's Better Auth settings live, and what they become; fails before anything is written when it cannot. */
|
|
81
104
|
const planAuthConfig = async (projectDir, users) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.121.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": {
|
|
@@ -43,13 +43,13 @@
|
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@better-auth/core": "^1.7.12",
|
|
45
45
|
"@hono/node-server": "^2.1.3",
|
|
46
|
-
"@protobase/config": "0.
|
|
47
|
-
"@protobase/layout": "0.
|
|
48
|
-
"@protobase/query": "0.
|
|
49
|
-
"@protobase/schema": "0.
|
|
50
|
-
"@protobase/server": "0.
|
|
51
|
-
"@protobase/ui": "0.
|
|
52
|
-
"@protobase/workflows": "0.
|
|
46
|
+
"@protobase/config": "0.121.0",
|
|
47
|
+
"@protobase/layout": "0.121.0",
|
|
48
|
+
"@protobase/query": "0.121.0",
|
|
49
|
+
"@protobase/schema": "0.121.0",
|
|
50
|
+
"@protobase/server": "0.121.0",
|
|
51
|
+
"@protobase/ui": "0.121.0",
|
|
52
|
+
"@protobase/workflows": "0.121.0",
|
|
53
53
|
"@react-email/render": "^2.1.0",
|
|
54
54
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
55
55
|
"@sentry/vite-plugin": "^11.10.0",
|
|
@@ -9,6 +9,7 @@ Sign-in methods, users, roles, organizations and tokens.
|
|
|
9
9
|
- [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.
|
|
10
10
|
- [Users from a script](../reference/auth.md#first-run): A seed or another script of the project creates and lists users, and mints their tokens, on the app's own sign-in.
|
|
11
11
|
- [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.
|
|
12
|
+
- [Table and column names](../reference/auth.md#table-and-column-names): Every sign-in table can take another name or a prefix, and every column but `id` another name, from the config, and the migrations, sign-in and Protobase's own queries all use it.
|
|
12
13
|
- [Existing users table](../reference/auth.md#an-existing-users-table): Sign-in can use the users table another system keeps in the same database.
|
|
13
14
|
- [Users page](../reference/auth.md#users-page): Admins find people, set roles, block them, add accounts and invite people by email.
|
|
14
15
|
- [Account page](../reference/auth.md#account-page): Everyone signed in has an account page for their profile, sign-in and security, devices, connected apps and access tokens, and you add, hide or reorder its tabs.
|
|
@@ -23,7 +23,8 @@ React components, field types, pages and handlers of your own, loaded as plugins
|
|
|
23
23
|
- [Shell slots](../reference/custom-components.md#shell-slots): Your own components in the top bar, in a panel beside every page, or as the sidebar logo.
|
|
24
24
|
- [Plugins](../reference/plugins.md#how-a-plugin-stays-working): Your React code is a plugin that the app loads at start and that keeps working across Protobase releases without changes.
|
|
25
25
|
- [Plugin settings](../reference/plugins.md#loading): Plugins are loaded from the config, limited to roles and given settings.
|
|
26
|
-
- [
|
|
26
|
+
- [Plugins load where the app has what they use](../reference/plugins.md#versions): The plugin build records the Protobase exports and extension points a plugin needs, and an app turns a plugin off when one is missing, naming it, rather than for its version; the plugin API and a range the plugin names itself still count.
|
|
27
|
+
- [Plugin fallbacks](../reference/plugins.md#when-a-plugin-is-off): A plugin that fails or does not fit the app is turned off alone, and admins see why.
|
|
27
28
|
- [Before sign-in](../reference/plugins.md#before-sign-in): A plugin can run around the sign-in page, for example to sign someone in from a link.
|
|
28
29
|
- [Unstable modules](../reference/plugins.md#the-unstable-entry): UI with its own build imports any module of the app's UI, without a promise that it stays the same, instead of copying it.
|
|
29
30
|
- [Focus page parts](../reference/custom-components.md#focus-pages) (beta): Fill a focus page's bar, notice and side panels from your own surface or component, with the record's draft and Save from the framework.
|
|
@@ -77,17 +77,18 @@ bun run protobase build-plugin
|
|
|
77
77
|
```
|
|
78
78
|
|
|
79
79
|
```
|
|
80
|
-
built dist: plugin.json, assets/index-DDnoullN.js and assets/styles-CToS5pKa.css (sales-tools, plugin API 1
|
|
80
|
+
built dist: plugin.json, assets/index-DDnoullN.js and assets/styles-CToS5pKa.css (sales-tools, plugin API 1)
|
|
81
81
|
```
|
|
82
82
|
|
|
83
|
-
`dist/assets/index-<hash>.js` is the plugin's module: its own code, with `react`, `react/jsx-runtime`, `react-dom` and `@protobase/ui` left as imports for the app to supply. `styles-<hash>.css` holds the utilities its classes use, and nothing else. `plugin.json` names both, the plugin API they are built for and the
|
|
83
|
+
`dist/assets/index-<hash>.js` is the plugin's module: its own code, with `react`, `react/jsx-runtime`, `react-dom` and `@protobase/ui` left as imports for the app to supply. `styles-<hash>.css` holds the utilities its classes use, and nothing else. `plugin.json` names both, the plugin API they are built for and what the plugin uses from the app, which the app checks it has before it loads the plugin:
|
|
84
84
|
|
|
85
85
|
```json
|
|
86
86
|
{
|
|
87
87
|
"name": "sales-tools",
|
|
88
88
|
"version": "1.0.0",
|
|
89
89
|
"api": 1,
|
|
90
|
-
"protobase": "
|
|
90
|
+
"imports": { "@protobase/ui": ["RecordLink", "definePlugin", "useList", "usePlugin"], "react/jsx-runtime": ["jsx", "jsxs"] },
|
|
91
|
+
"extensionPoints": ["components"],
|
|
91
92
|
"entry": "assets/index-DDnoullN.js",
|
|
92
93
|
"css": "assets/styles-CToS5pKa.css"
|
|
93
94
|
}
|
|
@@ -163,4 +164,4 @@ Put `dist/` on a static host, and list its `plugin.json` in the deployed app's `
|
|
|
163
164
|
|
|
164
165
|
The app updates to a new release of Protobase. Nothing happens to the plugin: within plugin API 1, every release keeps what the plugin imports, and the plugin runs on the newer `@protobase/ui` it is handed, its fixes included.
|
|
165
166
|
|
|
166
|
-
If the app
|
|
167
|
+
If the app lacked something the plugin uses, such as an export of `@protobase/ui` from a newer release, it would not load the plugin at all. Its admins would see a notice below the top bar naming what is missing, such as "The plugin sales-tools is off: it uses what this app does not have: useList from @protobase/ui.", and the card would show a warning in place of the drafts, while the rest of the app works as before. [Versions](../reference/plugins.md#versions) has the rules.
|
|
@@ -62,4 +62,4 @@ Nothing changes: `protobase dev` builds `protobase.ui.tsx` into its page with ho
|
|
|
62
62
|
|
|
63
63
|
## After the move
|
|
64
64
|
|
|
65
|
-
From now on, a release of Protobase within the same minor needs no rebuild of the project's UI: the app it runs in is the release's, and the plugin keeps working within its [plugin API](../reference/plugins.md#versions). The server config runs on the runtime the project is pinned to (see [Bundles and runtimes](../reference/versioning.md#bundles-and-runtimes)), so moving the pin to a new minor below 1.0 is still a rebuild.
|
|
65
|
+
From now on, a release of Protobase within the same minor needs no rebuild of the project's UI: the app it runs in is the release's, and the plugin keeps working within its [plugin API](../reference/plugins.md#versions). A plugin built on a newer release also loads in an app on an older one, as long as that app is on the plugin's plugin API, has every export and extension point the plugin uses, and is in the `engines.protobase` range of the plugin's `package.json` when it names one. The server config runs on the runtime the project is pinned to (see [Bundles and runtimes](../reference/versioning.md#bundles-and-runtimes)), so moving the pin to a new minor below 1.0 is still a rebuild.
|
|
@@ -38,7 +38,7 @@ Each version's statements are followed by its row in `auth_migrations`. The file
|
|
|
38
38
|
|
|
39
39
|
Every store has the tables of every feature, whether the app turns the feature on or not: [passkeys](#passkeys), [two-factor authentication](#two-factor-authentication), [organizations](#organizations), the [OAuth provider for MCP](#oauth-for-mcp-clients) and [personal access tokens](personal-access-tokens.md). Turning a feature on or off needs no migration and drops nothing; the columns a feature adds to the user and session tables are empty until it is on. SAML providers and open sign-up keep nothing in the store.
|
|
40
40
|
|
|
41
|
-
The
|
|
41
|
+
The names the app configures, the store's schema ([`auth.schema`](config/sign-in.md#authschema)), its [tables and columns](#table-and-column-names), and uuid ids (`generateUserId: 'uuid'`), are the ones in effect when the file is written. Changing one later is a migration of the project's own, such as a rename. <gap>`protobase auth migration` cannot rename a table or column the store has already because writing a rename from a changed name is not implemented.</gap>
|
|
42
42
|
|
|
43
43
|
The server never changes the schema, and never compares it with what Better Auth needs. `protobase serve` and `protobase dev` read `auth_migrations` at startup and refuse to start while a version of this Protobase is not applied, naming it and `protobase auth migration`, or while the store has a version newer than this Protobase knows. The examples' `db:migrate` applies all pending files in one transaction, so a migration that fails leaves the database as the running version expects it. The host must guarantee the rest: nothing but the migrations writes while they run, and the new version serves only after they succeeded. Only [`protobase dev`](cli.md#dev), on the developer's machine, compares the store's tables with what the app's Better Auth needs, and warns at startup about each table, column or index that drifted, such as one changed by hand.
|
|
44
44
|
|
|
@@ -46,19 +46,47 @@ No resource may be over a table of the store, which holds password hashes, sessi
|
|
|
46
46
|
|
|
47
47
|
A store made before 0.48, when `protobase auth migration` compared the database with Better Auth's tables, has no `auth_migrations`. For it, `protobase auth migration` writes the step that adopts it, once: it runs each version in a scratch schema, in a transaction it rolls back, to find the tables and columns that version makes, records each version whose tables and columns the store has, with their types, as applied, and writes the versions whose tables it has none of, such as MCP's for an app that never turned MCP on. The file checks again, when it is applied, that the store has every table and column it adopts, and stops otherwise, naming them. A store that has only some of a version's tables and columns, or has them with other types, is refused, naming what differs: bring it to the schema of Protobase 0.47 first, with that version's `protobase auth migration`. A store set up by Protobase 0.6, with Better Auth's camelCase names, or by `auth:migrate` before it, goes through 0.47 the same way.
|
|
48
48
|
|
|
49
|
+
### Table and column names
|
|
50
|
+
|
|
51
|
+
Each module of the store declares its tables and columns once, under built-in names, snake_case like the app's (`sign_in_policy.platform_sign_in`, `session.user_id`); the code and the API keep Better Auth's camelCase names. The modules and their tables:
|
|
52
|
+
|
|
53
|
+
- `auth`: `user`, `session`, `account`, `verification`, `jwks` and `auth_migrations`.
|
|
54
|
+
- `two_factor`: `two_factor`, and the user's `two_factor_enabled`.
|
|
55
|
+
- `passkeys`: `passkey`.
|
|
56
|
+
- `sign_in_policy`: `sign_in_policy`.
|
|
57
|
+
- `staff_sign_in`: `staff_sign_in`.
|
|
58
|
+
- `organizations`: `organization`, `member` and `invitation`, whose rows each belong to one organization, and the user's `last_organization_id`, the session's `active_organization_id` and the personal access token's `organization_id`.
|
|
59
|
+
- `personal_access_tokens`: `personal_access_token`.
|
|
60
|
+
- `mcp`: the OAuth provider's `oauth_client`, `oauth_resource`, `oauth_client_resource`, `oauth_refresh_token`, `oauth_access_token`, `oauth_consent` and `oauth_client_assertion`.
|
|
61
|
+
- `mail_senders`: `mail_sender`.
|
|
62
|
+
- `platform_devices`: `refused_account` and `device_session`.
|
|
63
|
+
|
|
64
|
+
[`auth.tables`](config/sign-in.md#authtables) gives any of them another name in the database: `prefix` goes before the name of every table it does not name, and each table, by its built-in name, takes its own `name` and `columns`, each column by its built-in name. A name it leaves out stays built-in, and `id` always keeps its name. The migrations make the tables and columns under these names, and sign-in, sessions, tokens and Protobase's own queries of the store read and write them so.
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
auth: {
|
|
68
|
+
tables: { prefix: 'app_', user: { name: 'people', columns: { role: 'app_role' } }, session: { columns: { user_id: 'person_id' } } },
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Here the user table is `people`, with its roles in `app_role`, and every other table starts with `app_`, such as `app_session`, whose `person_id` holds its user.
|
|
73
|
+
|
|
74
|
+
Postgres keeps the first 63 bytes of a name and drops the rest, so the server refuses to start with a name `auth.tables` gives past 63 bytes, naming the setting and its length. It refuses a table or column the store does not have, `id`, and a name two tables, or two columns of one table, would share. Each index is named after its table, such as `app_session_user_id_idx` for `session_user_id_idx`; a prefixed table name or an index name past 63 bytes is cut to its start and `_` and the first 8 hex digits of its SHA-256, the same every time.
|
|
75
|
+
|
|
49
76
|
### An existing users table
|
|
50
77
|
|
|
51
78
|
The store can use a users table another system made, such as Supabase's `auth.users`, so its rows keep signing in and every foreign key, trigger and function that names the table keeps working:
|
|
52
79
|
|
|
53
80
|
```ts
|
|
54
81
|
auth: {
|
|
55
|
-
|
|
82
|
+
tables: { user: { name: 'users', columns: { role: 'app_role' } } },
|
|
83
|
+
users: { metadata: 'raw_user_meta_data', guardedSchemas: ['auth'] },
|
|
56
84
|
passwordHashes: ['bcrypt'],
|
|
57
85
|
generateUserId: 'uuid',
|
|
58
86
|
}
|
|
59
87
|
```
|
|
60
88
|
|
|
61
|
-
- `
|
|
89
|
+
- `tables.user.name` names the table, default `user`. `tables.user.columns` maps a column, by its built-in name (`name`, `email`, `email_verified`, `email_confirmed_at`, `image`, `created_at`, `updated_at`, `role`, `banned`, `ban_reason`, `ban_expires`, `two_factor_enabled`, `last_role`, `last_organization_id`), to the table's own; here the app's roles go to `app_role`, since Supabase's `role` holds the Postgres role. The other tables point at this one (see [Table and column names](#table-and-column-names)).
|
|
62
90
|
- `users.guardedSchemas` names the schemas where the other system keeps the rest of its sign-in data, such as Supabase Auth's `auth`, with its identities, sessions, refresh tokens and two-factor secrets. Every table in them, including one the other system adds later, counts among the store's tables: no resource may be over it and the assistant's queries never read it. Name only a schema that holds none of the app's own tables.
|
|
63
91
|
- `users.metadata` names a JSON column for each user's metadata, which the migrations add as `jsonb` when the table lacks it: `createUser(auth, { ..., metadata: { full_name: 'Carol' } })` writes it, so a trigger that reads `raw_user_meta_data->>'full_name'` sees it.
|
|
64
92
|
- `passwordHashes: ['bcrypt']` also verifies bcrypt hashes (`$2a$`, `$2b$`, `$2y$`), and stores the password again as Better Auth's own scrypt after its first sign-in. The 12-character minimum holds for new passwords only, so a shorter existing one still signs in.
|
|
@@ -73,7 +101,8 @@ Where the app may not change the other system's users table, as on a Supabase da
|
|
|
73
101
|
```ts
|
|
74
102
|
auth: {
|
|
75
103
|
schema: 'app_auth',
|
|
76
|
-
|
|
104
|
+
tables: { user: { name: 'users', columns: { role: 'app_role' } } },
|
|
105
|
+
users: { keyTable: { schema: 'auth', table: 'users' }, guardedSchemas: ['auth'], metadata: 'raw_user_meta_data' },
|
|
77
106
|
passwordHashes: ['bcrypt'],
|
|
78
107
|
generateUserId: 'uuid',
|
|
79
108
|
}
|
|
@@ -282,7 +282,7 @@ By default the bundle runs on Node and on Bun. `--bun` makes it a bundle for Bun
|
|
|
282
282
|
"api": ["/api", "/.well-known/oauth-authorization-server", "/.well-known/oauth-protected-resource", "/.well-known/openid-configuration"],
|
|
283
283
|
"theme": "protobase.theme.css",
|
|
284
284
|
"plugins": [
|
|
285
|
-
{ "name": "app", "path": "plugins/app/plugin.json", "api": 1, "
|
|
285
|
+
{ "name": "app", "path": "plugins/app/plugin.json", "api": 1, "fields": { "steps": ["enum"] } }
|
|
286
286
|
],
|
|
287
287
|
"shell": { "protobase": "0.12.0", "pluginApi": 1, "paths": ["/index.html", "/assets", "/protobase.sw.js"] },
|
|
288
288
|
"native": { "@capacitor/core": "8.5.3", "@capacitor/ios": "8.5.3" },
|
|
@@ -294,7 +294,7 @@ By default the bundle runs on Node and on Bun. `--bun` makes it a bundle for Bun
|
|
|
294
294
|
|
|
295
295
|
- `protobase` is the Protobase version of the copies the build used: the building CLI's own in a bundled project, and in a locked one the `@protobase` packages its lockfile installed, whichever CLI built the bundle. A host serves the bundle on the runtime of that version (see [Versioning](versioning.md#bundles-and-runtimes)). A bundled project needs nothing installed; a locked one fails without its `@protobase` packages installed.
|
|
296
296
|
- `server`, `public`, `nodeModules` and `migrations` are relative to the bundle folder; `spa`, `theme` and each plugin's `path` to `public`.
|
|
297
|
-
- `plugins` are the bundle's own plugins, in the order the app merges them: the extensions', then the project's (`app`). Each names its `plugin.json`, the plugin API
|
|
297
|
+
- `plugins` are the bundle's own plugins, in the order the app merges them: the extensions', then the project's (`app`). Each names its `plugin.json`, the plugin API it is built for, the Protobase versions it is limited to only when its `package.json` names some, and the [field types](plugins.md#field-types) it registers with the storage types each shows, which the serve runtime checks the views against at startup. `/api/meta` names them to everyone, before any other plugin.
|
|
298
298
|
- `shell` is the admin app `public/` holds a copy of: its Protobase version and plugin API, and its files as URL paths. A host with a shell of its own may serve its own for those paths instead (see [The UI](#the-ui)), so the app gets that release's fixes without a rebuild.
|
|
299
299
|
- `native` is the native code, name to version, that `shell` runs on in the [mobile app](../guides/mobile-app.md): the native packages `@protobase/mobile` pins, and `@protobase/mobile` itself at its native contract, such as `native-1`, which Protobase raises when its own native code changes. The fingerprint of the bundle's [mobile release](#mobile-releases) names them. A bundle built before it serves no mobile release.
|
|
300
300
|
- `mobile` is present only when the project's config has a `mobile` section, so a host learns that the app has a mobile build without running the config: the section's `appId`, which the statement of a signed mobile release binds, its `plugins`, name to the spec it gives, `{}` when it gives none, and `push`, whether the config has [`notifications()`](notifications.md), with which the binaries compile native push in; the fingerprint of the mobile release names both besides `native`. A bundle built before it names no `appId`, and one built before `push` none, which counts as `false`. The build checks the section as `protobase mobile` does.
|
|
@@ -422,7 +422,7 @@ dist/
|
|
|
422
422
|
- The output folder is emptied first, so it must not be the plugin's folder or hold it.
|
|
423
423
|
- The module is `protobase.ui.tsx` with everything it imports bundled, except the four modules the app shares (`react`, `react/jsx-runtime`, `react-dom`, `@protobase/ui`), which stay imports by those names. Any other module of those packages, such as `react-dom/client`, fails the build. React's production build and JSX runtime are used, whatever `NODE_ENV` says, and every export of `protobase.ui.tsx` is kept.
|
|
424
424
|
- The stylesheet is Tailwind's utilities for the classes in the plugin's folder: no reset, no theme values. Each utility reads the theme of the app that loads it, with Tailwind's default as the fallback (`text-sm` is `font-size: var(--text-sm, 0.875rem)`).
|
|
425
|
-
- `plugin.json` names the plugin (`--name`, else its `package.json`'s `name`, else its folder's), its own `version`, the plugin API (`api`) and the Protobase versions
|
|
425
|
+
- `plugin.json` names the plugin (`--name`, else its `package.json`'s `name`, else its folder's), its own `version`, the plugin API it is built for (`api`), what it uses (`imports` and `extensionPoints`), the Protobase versions its `package.json` names in `engines.protobase`, if any (`protobase`), the module (`entry`) and stylesheet (`css`), relative to it, and the [field types](plugins.md#field-types) it registers (`fields`), each with the storage types it shows. `api` and the extension points come from the `@protobase/ui` installed for the plugin, else for the project it extends, else the CLI's own (see [Plugins](plugins.md#versions)).
|
|
426
426
|
- `--source-maps` ends each script with a `//# debugId=<uuid>` comment, naming no map, and writes its source map, `<script>.js.map` carrying the same `debugId`, beside it, for an error tracker to read the browser's stack frames with.
|
|
427
427
|
|
|
428
428
|
To read its field types, the build loads the plugin's module once in Node, with everything bundled; nothing is rendered, but code at the top level of its modules runs, so keep browser-only work (`window`, `document`) inside components and handlers. The app loads it from wherever `plugin.json` is served, listed in `PROTOBASE_PLUGINS` or the config's `plugins` (see [loading](plugins.md#loading)).
|
|
@@ -663,7 +663,7 @@ protobase import supabase [<connection> | --source-env <variable>] [--env DATABA
|
|
|
663
663
|
|
|
664
664
|
Turns a Supabase project's database into the project in the current directory, in two runs with the project's migrations between them. It needs PostgreSQL's `pg_dump` and `psql` on `PATH`, of the Supabase database's major version or newer, and reads the `.env` nearest the current directory for the project's database (`--env`).
|
|
665
665
|
|
|
666
|
-
1. **The first run** takes the Supabase database's connection string, for its `postgres` role (the session pooler's or the direct one; the transaction pooler cannot hold the snapshot the dumps share). It fails unless the database has Supabase's `auth` and `storage` schemas and its `supabase_admin` role, and while `auth.users` has single sign-on (SAML) users, which Supabase opens only through their identity provider and Better Auth would find by email, so the import cannot carry them over. It then says how many share their address with another user and how many have one of their own, and prints `select id, email from auth.users where is_sso_user` to list them rather than their addresses. Deleting a user in Supabase deletes or breaks the app's rows that reference it, so what to do about these users is the developer's decision, made in Supabase before importing again. It notes the Supabase CLI's `supabase/config.toml`, `supabase/migrations/` and `supabase/functions/` when the checkout has them. It converts `supabase/functions` into the project's `functions/` (see [functions moved from Supabase](../guides/api-functions.md#functions-moved-from-supabase)): `Deno.serve(handler)` and std's `serve(handler)` become `export default defineFunction({ supabase: true }, { fetch: handler })`, an existing default export is wrapped the same way, so each function also answers at `/api/sb/functions/v1/<name>`, `npm:`, `jsr:` and esm.sh imports become bare imports of packages it adds to `package.json`, `Deno.env.get(name)` becomes `process.env[name]`, `EdgeRuntime.waitUntil` becomes `waitUntil` of `@protobase/server`, a function with `verify_jwt = false` in `config.toml` becomes public (`{ public: true, supabase: true }`), and `_shared` and the like are converted beside them. It stops before anything else when `functions/` already has one of their names. It dumps `auth`, `storage` and every schema the app made, schema and data apart, as of one snapshot, leaving out the platform's own migration tables, and writes the schemas as the project's next migration, `NNN_supabase_schema.sql`. It asks the project's database which of the app's extensions its role may create, by trying each in a transaction it rolls back: Postgres alone allows the trusted ones, Supabase's Postgres image all it allowlists, such as pg_net, pgmq and Vault. The migration creates those first, then, where pg_net is among them and the app has Database Webhooks, the `supabase_functions.http_request` function their triggers call, over pg_net; then the dump without what fails there, as comments: grants and default privileges for `dashboard_user`, `supabase_*`, `authenticator` and `postgres`, statements about the `public` schema, Realtime's publication, pgsodium's security labels, the views that decrypt with it and the triggers that encrypt with it, database webhooks without pg_net, functions in plv8, plls or plcoffee where the database has no such language, and a timescaledb hypertable's insert-blocking trigger. It then writes `NNN_supabase_users.sql`, the nullable columns Better Auth needs on `auth.users` (`name`, `email_verified`, `image`, `app_role`, `banned`, `ban_reason`, `ban_expires`) and GoTrue's `'authenticated'` as the default of `role` and `aud`. It writes `NNN_supabase_realtime.sql`, which makes `realtime.messages`, `realtime.topic()`, and Supabase's `realtime.send()` and `realtime.broadcast_changes()`, so the app's triggers and SQL keep [broadcasting from the database](supabase-realtime.md#broadcast-from-the-database), with the source's row security policies on `realtime.messages`, so its [private channels](supabase-realtime.md#private-channels) keep their access; a policy that names only Supabase's own roles is left out as a comment. It points the app at `auth.users`: the `auth` of `protobase.config.ts` gets `
|
|
666
|
+
1. **The first run** takes the Supabase database's connection string, for its `postgres` role (the session pooler's or the direct one; the transaction pooler cannot hold the snapshot the dumps share). It fails unless the database has Supabase's `auth` and `storage` schemas and its `supabase_admin` role, and while `auth.users` has single sign-on (SAML) users, which Supabase opens only through their identity provider and Better Auth would find by email, so the import cannot carry them over. It then says how many share their address with another user and how many have one of their own, and prints `select id, email from auth.users where is_sso_user` to list them rather than their addresses. Deleting a user in Supabase deletes or breaks the app's rows that reference it, so what to do about these users is the developer's decision, made in Supabase before importing again. It notes the Supabase CLI's `supabase/config.toml`, `supabase/migrations/` and `supabase/functions/` when the checkout has them. It converts `supabase/functions` into the project's `functions/` (see [functions moved from Supabase](../guides/api-functions.md#functions-moved-from-supabase)): `Deno.serve(handler)` and std's `serve(handler)` become `export default defineFunction({ supabase: true }, { fetch: handler })`, an existing default export is wrapped the same way, so each function also answers at `/api/sb/functions/v1/<name>`, `npm:`, `jsr:` and esm.sh imports become bare imports of packages it adds to `package.json`, `Deno.env.get(name)` becomes `process.env[name]`, `EdgeRuntime.waitUntil` becomes `waitUntil` of `@protobase/server`, a function with `verify_jwt = false` in `config.toml` becomes public (`{ public: true, supabase: true }`), and `_shared` and the like are converted beside them. It stops before anything else when `functions/` already has one of their names. It dumps `auth`, `storage` and every schema the app made, schema and data apart, as of one snapshot, leaving out the platform's own migration tables, and writes the schemas as the project's next migration, `NNN_supabase_schema.sql`. It asks the project's database which of the app's extensions its role may create, by trying each in a transaction it rolls back: Postgres alone allows the trusted ones, Supabase's Postgres image all it allowlists, such as pg_net, pgmq and Vault. The migration creates those first, then, where pg_net is among them and the app has Database Webhooks, the `supabase_functions.http_request` function their triggers call, over pg_net; then the dump without what fails there, as comments: grants and default privileges for `dashboard_user`, `supabase_*`, `authenticator` and `postgres`, statements about the `public` schema, Realtime's publication, pgsodium's security labels, the views that decrypt with it and the triggers that encrypt with it, database webhooks without pg_net, functions in plv8, plls or plcoffee where the database has no such language, and a timescaledb hypertable's insert-blocking trigger. It then writes `NNN_supabase_users.sql`, the nullable columns Better Auth needs on `auth.users` (`name`, `email_verified`, `image`, `app_role`, `banned`, `ban_reason`, `ban_expires`) and GoTrue's `'authenticated'` as the default of `role` and `aud`. It writes `NNN_supabase_realtime.sql`, which makes `realtime.messages`, `realtime.topic()`, and Supabase's `realtime.send()` and `realtime.broadcast_changes()`, so the app's triggers and SQL keep [broadcasting from the database](supabase-realtime.md#broadcast-from-the-database), with the source's row security policies on `realtime.messages`, so its [private channels](supabase-realtime.md#private-channels) keep their access; a policy that names only Supabase's own roles is left out as a comment. It points the app at `auth.users`: the `auth` of `protobase.config.ts` gets `tables: { user: { name: 'users', columns: { role: 'app_role' } } }`, `users: { metadata: 'raw_user_meta_data', guardedSchemas: ['auth'] }`, `passwordHashes: ['bcrypt']` and `generateUserId: 'uuid'`, or the config gets an `auth` of them when it has none (see [an existing users table](auth.md#an-existing-users-table)). It removes the migrations `protobase auth migration` or `protobase migration` wrote for Protobase's own user table, since `auth.users` replaces it, and stops before writing anything when the project has no `protobase.config.ts`, or one whose `auth` is not an object it can see, or when the project's database has a schema the dump creates already, such as the `auth` schema those migrations made. The project's database needs the roles `anon`, `authenticated` and `service_role` that the dump's grants and policies name; the command makes them when its role may, and otherwise stops, naming them. The data dump goes to `supabase-import/`, which it adds to `.gitignore`, since it holds every row and the users' password hashes. Where the project's database can create Vault, pgmq and pg_cron, `supabase-import/replay.sql` holds what a dump cannot carry: Vault's secrets with their values, read decrypted since only Supabase's key opens their ciphertext, pgmq's queues with their messages, since pgmq owns their tables, and pg_cron's jobs, which live in its own schema.
|
|
667
667
|
2. **Apply the migration** with the project's other migrations, such as `bun run db:migrate`.
|
|
668
668
|
3. **The second run**, without a connection string, loads the data in one transaction, with the app's triggers off so a sign-up trigger on `auth.users` does not run again for users who already have their rows, and fails the transaction unless every table holds the source's number of rows. In the same transaction it makes Vault's secrets and pgmq's queues again through `vault.create_secret`, `pgmq.create` and `pgmq.send`, each message with its headers and the time it becomes visible. Where the project's database has pg_cron, as Supabase's Postgres image does when it serves that database, it schedules pg_cron's jobs again there with `cron.schedule`, run by the importing role, an inactive one inactive. Elsewhere it writes each job of plain SQL as a [recurring job](jobs.md#recurring-jobs) of its own in `jobs/`, of the same name, schedule and `cron.timezone`, that runs its SQL as the app's database role, tried once each time as pg_cron did, and declares it in the `jobs` of `protobase.config.ts` (or writes one); they run once [`migration`](#migration) has added the jobs schema. Recurring jobs wake an app that sleeps, so they run where a host stops an idle app too. A job that calls what the database lacks, such as pg_net's `net.http_*`, `cron` or Vault, an inactive one and a schedule recurring jobs do not take, such as `30 seconds` or `$`, stay in the report, as does a job of another database. It loads only into empty tables, deletes the data dump and the replay, runs [`scaffold`](#scaffold) on the imported tables of the app's schemas (not `auth` or `storage`), giving the tables of the `supabase_realtime` publication [`.live()`](live.md) so [`/api/sb/realtime/v1`](supabase-realtime.md) keeps sending their `postgres_changes` once [`migration`](#migration) has written their capture triggers, writes Better Auth's other tables next to `auth.users` as [`auth migration`](#auth-migration) does (`NNN_auth.sql`), then `NNN_supabase_accounts.sql`, and writes `supabase-import/report.md`: the rows loaded, the API keys `/api/sb` needs and the `createClient` change to the app's `/api/sb` and its publishable key, the imported tables' size against the Starter plan's 500 MB, each sign-in provider's identities, what it made again, the tables it made live, and what needs a person: the pg_cron jobs it could not carry over, each with why, Realtime tables it made no resource of, Vault secrets by name and pgmq queues where the database has no such extension (and partitioned queues), the columns pgsodium encrypts, still holding Supabase's ciphertext, whose values to export decrypted in Supabase before declaring them [`.encrypted()`](data-config.md#encrypted-fields) and running [`encryption apply`](#encryption-apply), the extensions it cannot create, hypertables and plv8, plls or plcoffee functions to convert, triggers that call out over HTTP without pg_net, the converted Edge Functions with the packages to install and the code the conversion left (`deno.land/x` imports, Deno's file, KV and WebSocket APIs, `Supabase.ai`), and the indexes [`doctor`](#doctor) finds missing. `NNN_supabase_accounts.sql` fills the user columns from what Supabase Auth recorded and leaves them empty where it recorded nothing: the name from `raw_user_meta_data`'s `full_name` or `name`, the picture from its `avatar_url` or `picture`, `email_verified` from `email_confirmed_at`, and a ban from `banned_until`, which Better Auth lifts once it has passed. It gives each password of a confirmed address, as Supabase hashed it, a `credential` account (a user who never confirmed theirs signs in by code or resets the password, since GoTrue refused their password sign-in too), and each identity of a social provider an account under Better Auth's name for it (`azure` is `microsoft`, keyed on the `oid` claim; `linkedin_oidc` is `linkedin`, `slack_oidc` is `slack`, `x` is `twitter`), unless its user has an address they never confirmed, since GoTrue refused that sign-in too. Email, phone, anonymous and single sign-on identities and sessions do not carry over. <gap>The import cannot carry over MFA factors because that is not implemented.</gap> <gap>The import cannot carry over passkeys because that is not implemented.</gap>
|
|
669
669
|
4. **Apply the migrations** again. Supabase's users then sign in with their own passwords, and with a social provider once it is in the `socialProviders` of the config's `auth`; new users get a UUID in `auth.users`, so the app's triggers there run for them.
|
|
@@ -222,16 +222,29 @@ Lets the signed-in person delete their own account from the account page, as app
|
|
|
222
222
|
export default defineConfig({ auth: { accountDeletion: false } })
|
|
223
223
|
```
|
|
224
224
|
|
|
225
|
+
## auth.tables
|
|
226
|
+
|
|
227
|
+
- **Type:** `{ prefix?: string }`, and for each [built-in table](../auth.md#table-and-column-names), by its name, `{ name?: string; columns?: { [column]?: string } }` with its built-in columns as keys
|
|
228
|
+
- **Default:** the built-in names
|
|
229
|
+
|
|
230
|
+
The names of the auth store's tables and columns in the database, where the app wants others than the built-in ones: `prefix` goes before the name of every table it does not name, and each table, by its built-in name, takes its own `name` and `columns`, each column by its built-in name. `id` keeps its name. A name past Postgres's 63 bytes is refused. See [Table and column names](../auth.md#table-and-column-names).
|
|
231
|
+
|
|
232
|
+
```ts
|
|
233
|
+
export default defineConfig({
|
|
234
|
+
auth: { tables: { prefix: 'app_', user: { name: 'users', columns: { role: 'app_role' } } } },
|
|
235
|
+
})
|
|
236
|
+
```
|
|
237
|
+
|
|
225
238
|
## auth.users
|
|
226
239
|
|
|
227
|
-
- **Type:** `{
|
|
228
|
-
- **Default:**
|
|
240
|
+
- **Type:** `{ metadata?: string; keyTable?: { schema: string; table: string }; guardedSchemas?: string[] }`
|
|
241
|
+
- **Default:** none
|
|
229
242
|
|
|
230
|
-
The user table, when another system made it, such as Supabase's `auth.users`:
|
|
243
|
+
The user table, when another system made it, such as Supabase's `auth.users`: a JSON column for each user's metadata, and what else the store must know of it; [`auth.tables`](#authtables)`.user` names it and its columns. See [An existing users table](../auth.md#an-existing-users-table). `keyTable` makes the user table a view of the app's own over another system's, the table it names, which holds the user ids: the store's migrations leave the view to the app and point their foreign keys at that table. See [A view over another system's users](../auth.md#a-view-over-another-systems-users). `guardedSchemas` names the schemas the other system keeps the rest of its sign-in data in, such as Supabase Auth's `auth`: no resource may be over any table in them, and the assistant's queries never read one.
|
|
231
244
|
|
|
232
245
|
```ts
|
|
233
246
|
export default defineConfig({
|
|
234
|
-
auth: { schema: 'auth',
|
|
247
|
+
auth: { schema: 'auth', tables: { user: { name: 'users', columns: { role: 'app_role' } } }, users: { metadata: 'raw_user_meta_data', guardedSchemas: ['auth'] } },
|
|
235
248
|
})
|
|
236
249
|
```
|
|
237
250
|
|
|
@@ -106,7 +106,7 @@ The app's database is `DATABASE_URL`'s, with the pool size of `PROTOBASE_DB_CONN
|
|
|
106
106
|
}
|
|
107
107
|
```
|
|
108
108
|
|
|
109
|
-
JSON cannot branch on the command or compute a value; a config that needs to is written in TypeScript. `$schema` points the editor at the file's JSON Schema, which `@protobase/config` ships as `schema.json`, made from the same types as a TypeScript config: it completes and checks every key and value as it is typed, and takes an `$env` value wherever a
|
|
109
|
+
JSON cannot branch on the command or compute a value; a config that needs to is written in TypeScript. `$schema` points the editor at the file's JSON Schema, which `@protobase/config` ships as `schema.json`, made from the same types as a TypeScript config: it completes and checks every key and value as it is typed, and takes an `$env` value wherever text, a number or a list goes, but not for a boolean or an object, which `$env` text cannot be. Protobase itself leaves `$schema` out. Where a key holds the settings of a library underneath, such as `auth.socialProviders`, the schema takes any object, and the app checks it when it starts.
|
|
110
110
|
|
|
111
111
|
## One config per project
|
|
112
112
|
|
|
@@ -100,7 +100,7 @@ export default (async (event, trx) => {
|
|
|
100
100
|
| `key` and `mode` | One waiting job per key: with `mode: 'dedupe'` (the default) an enqueue while one waits returns that one's id and leaves it as it is; with `mode: 'replace'` the waiting job takes this payload and these options. A job that is running does not count, so a change made while it runs gets a job of its own. |
|
|
101
101
|
| `group` | The group of an [ordered](#ordered-groups) job: required there, refused elsewhere. |
|
|
102
102
|
|
|
103
|
-
A job
|
|
103
|
+
A job this process enqueues starts at once when this process runs its jobs, and one enqueued in a transaction starts once that transaction commits, never when it rolls back; a wake starts up to the job's `concurrency` of its due jobs. A job enqueued by another process, or from SQL, is picked up within the poll interval, 2 seconds, and so is one enqueued in a transaction of a Kysely instance the app built itself rather than its `db`.
|
|
104
104
|
|
|
105
105
|
Each worker takes one job per poll, so a queue that fills faster drains one job per worker every 2 seconds at first. Once the queue maintenance, about every minute, counts more jobs ready than the job's `concurrency`, a worker that found a job fetches the next one at once, until a fetch finds none: a backlog then drains as fast as its jobs run.
|
|
106
106
|
|
|
@@ -443,7 +443,7 @@ The default store keeps devices in the table `devices` of the schema `notificati
|
|
|
443
443
|
|
|
444
444
|
`protobase migration` adds `session_id` to a devices table written before devices kept their session.
|
|
445
445
|
|
|
446
|
-
You rename the schema, the table and each column, as auth takes `
|
|
446
|
+
You rename the schema, the table and each column, as auth takes `tables`, such as to keep devices in a table you already have:
|
|
447
447
|
|
|
448
448
|
```ts
|
|
449
449
|
notifications: {
|
|
@@ -25,7 +25,7 @@ Code built together with the app is frozen at the app it was built with: a newer
|
|
|
25
25
|
1. **The app is built once per release.** The admin app, the shell, is the same for every project. Each release of `@protobase/ui` ships it prebuilt, and `protobase build` copies it into the bundle beside the project's plugins and theme. A host that has the shell of a newer release can serve that one in its place (see [the shell](#the-shell)), so an app gets the release's fixes without a rebuild of its own code.
|
|
26
26
|
2. **The app shares its modules.** The admin app hands four modules to plugins: `react`, `react/jsx-runtime`, `react-dom` and `@protobase/ui`. Its `index.html` maps those names to the app's own files with an [import map](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/script/type/importmap), so a plugin's `import { useList } from '@protobase/ui'` runs on the app's copy: one React, one query cache, one signed-in session and the app's version of every hook and component. A plugin carries only its own code, and gets the fixes of every release the app moves to.
|
|
27
27
|
3. **The plugin API is a promise.** What a plugin can import, the four modules and every export of `@protobase/ui`, is the plugin API, numbered: `pluginApi` is 1. Releases add to it but never remove or change what is in it; only a new plugin API does, as for a new major version of React. So a plugin keeps working on every release of the plugin API it was built for, with no rebuild. Below 1.0 a minor release may change how a project's config is written, but not the plugin API.
|
|
28
|
-
4. **The app checks before it loads.** A plugin's `plugin.json` says which plugin API and
|
|
28
|
+
4. **The app checks before it loads.** A plugin's `plugin.json` says which plugin API it is built for and what it uses: the names it imports from the shared modules and the extension points it fills. The app loads a plugin only when it has that plugin API and everything the plugin uses, whichever release built the plugin; it never runs the code of one that does not fit.
|
|
29
29
|
5. **A plugin that does not fit is turned off, not the app.** Each place it would fill draws a fallback, the app's admins see why it is off, and everything else works as before. A component that throws while drawing shows its fallback in its own place.
|
|
30
30
|
6. **The look is values, not rules.** A project themes the app with a [`protobase.theme.css`](theme.md) that holds only values of the app's tokens, and a plugin's stylesheet holds only utilities that read those tokens. Neither reaches into the app's markup, so neither breaks when the app's markup changes.
|
|
31
31
|
|
|
@@ -72,7 +72,7 @@ export default definePlugin({ name: 'sales-tools', actions: { remindCustomer } }
|
|
|
72
72
|
|
|
73
73
|
It is written as a project's `protobase.ui.tsx` is: each component exported under the PascalCase name the config declares, from a file of its own, and the rest in the default export, `definePlugin({ name, actions, fields, shell, beforeSignIn, extends, ... })` (`defineUi` is the same function), with the keys of [Extension points](#extension-points). Its components use the hooks and components of `@protobase/ui`, which read the API as the signed-in user, under the same access rules as everything else.
|
|
74
74
|
|
|
75
|
-
**Imports.** `react`, `react/jsx-runtime` (the JSX), `react-dom` and `@protobase/ui`, by those names, come from the app. Everything else a plugin imports, its own files, icons or a chart library, is built into it. Other modules of those packages, such as `react-dom/client` or a file inside `@protobase/ui`, fail the build: a copy of its own would not work with the app's. Read data with `@protobase/ui`'s hooks (`useList`, `useRecord`, `useClient`), which share the app's cache: a data library of the plugin's own keeps a cache of its own. For anything else, such as another API's answer, `useQuery` and `useQueryClient` from `@protobase/ui` are TanStack Query's, on the app's own client, so their answers are kept in the [start cache](installable-app.md#starting-from-the-last-pages-seen) and draw on the next start before the network answers.
|
|
75
|
+
**Imports.** `react`, `react/jsx-runtime` (the JSX), `react-dom` and `@protobase/ui`, by those names, come from the app. Everything else a plugin imports, its own files, icons or a chart library, is built into it. Other modules of those packages, such as `react-dom/client` or a file inside `@protobase/ui`, fail the build: a copy of its own would not work with the app's. So does taking all of `@protobase/ui` at once (`import * as`, `export *` or `import()`), since the app could not check that it has the names the plugin reads: import them by name. Read data with `@protobase/ui`'s hooks (`useList`, `useRecord`, `useClient`), which share the app's cache: a data library of the plugin's own keeps a cache of its own. For anything else, such as another API's answer, `useQuery` and `useQueryClient` from `@protobase/ui` are TanStack Query's, on the app's own client, so their answers are kept in the [start cache](installable-app.md#starting-from-the-last-pages-seen) and draw on the next start before the network answers.
|
|
76
76
|
|
|
77
77
|
**Styling.** Use Tailwind classes, as the app's own code does. The plugin's stylesheet holds the utilities its files use and nothing else, no reset and no global style, and each reads the app's [tokens](theme.md): `bg-primary` is the app's primary color and `rounded-md` its radius, whatever the app's version and whatever its theme, and a token the app does not set falls back to Tailwind's default.
|
|
78
78
|
|
|
@@ -233,7 +233,8 @@ The output folder is emptied first, so it must not hold the plugin's own files.
|
|
|
233
233
|
"name": "sales-tools",
|
|
234
234
|
"version": "1.0.0",
|
|
235
235
|
"api": 1,
|
|
236
|
-
"protobase": "
|
|
236
|
+
"imports": { "@protobase/ui": ["definePlugin", "useList"], "react/jsx-runtime": ["jsx", "jsxs"] },
|
|
237
|
+
"extensionPoints": ["components", "fields"],
|
|
237
238
|
"entry": "assets/index-DDnoullN.js",
|
|
238
239
|
"css": "assets/styles-CToS5pKa.css",
|
|
239
240
|
"fields": { "steps": ["enum"] }
|
|
@@ -245,7 +246,9 @@ The output folder is emptied first, so it must not hold the plugin's own files.
|
|
|
245
246
|
| `name` | The plugin's name: `--name`, else its `package.json`'s `name`, else its folder's. A project's own is `app`. |
|
|
246
247
|
| `version` | Its `package.json`'s `version`, when it has one. |
|
|
247
248
|
| `api` | The plugin API of the `@protobase/ui` it is built with. |
|
|
248
|
-
| `
|
|
249
|
+
| `imports` | The names its built code imports from each module the app shares, `*` for a whole module of React (`import * as`, `import()`); code the build leaves out does not count (see [versions](#versions)). |
|
|
250
|
+
| `extensionPoints` | The [extension points](#extension-points) it fills, such as `components` or `shell.rightPanel`. |
|
|
251
|
+
| `protobase` | The Protobase versions its `package.json` names in `engines.protobase`, only when it names some (see [versions](#versions)). |
|
|
249
252
|
| `entry`, `css` | The module and the stylesheet, relative to `plugin.json`. |
|
|
250
253
|
| `fields` | The field types it registers, each with the storage types it shows. Only when it registers some. |
|
|
251
254
|
|
|
@@ -345,18 +348,23 @@ A host that keeps the shells of its releases can serve the shell of a newer one
|
|
|
345
348
|
|
|
346
349
|
## Versions
|
|
347
350
|
|
|
348
|
-
A plugin is built for one plugin API and
|
|
351
|
+
A plugin is built for one plugin API and records what it uses, both written by `build-plugin` into `plugin.json`:
|
|
349
352
|
|
|
350
353
|
- `api` is the plugin API of the `@protobase/ui` installed for the plugin, else the CLI's own (always the CLI's for the UI of a bundled project).
|
|
351
|
-
- `
|
|
354
|
+
- `imports` names what the plugin's built code imports from `react`, `react/jsx-runtime`, `react-dom` and `@protobase/ui`, read from the build's output, so an import only an unused file or a re-export nobody reads makes is not in it, and one its own files make is.
|
|
355
|
+
- `extensionPoints` names the extension points its config fills, as that `@protobase/ui` reads them.
|
|
352
356
|
|
|
353
|
-
|
|
354
|
-
{ "engines": { "protobase": ">=0.12.0" } }
|
|
355
|
-
```
|
|
357
|
+
The app loads a plugin when the plugin's `api` is its own and it has every name in `imports` and every extension point in `extensionPoints`, whatever its version; only a plugin that names a `protobase` range also needs the app's version in it. A plugin built with a newer `@protobase/ui` loads in an app on an older release that checks what plugins use, as long as the older release has what the plugin uses; when something is missing, the plugin stays off and its notice names what, such as "it uses what this app does not have: NewPicker from @protobase/ui, the extension point shell.bell". Releases from before that check compare versions only: they need a `protobase` range in `plugin.json`, turn off a plugin without one, and do not read `imports` or `extensionPoints`.
|
|
356
358
|
|
|
357
|
-
|
|
359
|
+
A plugin author who wants to limit the plugin to some releases anyway names a range in its `package.json`, which the build copies into `plugin.json` as `protobase`:
|
|
358
360
|
|
|
359
|
-
|
|
361
|
+
```json
|
|
362
|
+
{ "engines": { "protobase": ">=0.12.0 <2.0.0" } }
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
The app then also needs its version in that range. A range is comparators separated by spaces, all of which must hold: `>=`, `>`, `<=`, `<` or `=` and an `x.y.z` version. The build checks only the range's form; which versions it holds is the app's to compare when it loads the plugin, where a prerelease such as a build from main counts too, just before its own release: `0.94.4-main.4f8859dd` is in `>=0.12.9`, and `0.13.0-main.4f8859dd` is in `<0.13.0` but not in `>=0.13.0`.
|
|
366
|
+
|
|
367
|
+
Protobase keeps the plugin API through its releases and starts a new one only when a plugin built for the old one could break:
|
|
360
368
|
|
|
361
369
|
- an export of `@protobase/ui` removed, or changed in a way its users would notice;
|
|
362
370
|
- an extension point's props changed in a way a plugin would notice;
|
|
@@ -371,10 +379,11 @@ Nothing a plugin does stops the app. Each of these turns off that plugin alone:
|
|
|
371
379
|
|
|
372
380
|
- its `plugin.json` cannot be read, or is not one;
|
|
373
381
|
- it is built for another plugin API, or for a range without the app's version;
|
|
382
|
+
- it uses an export, a shared module or an extension point the app does not have;
|
|
374
383
|
- its module cannot be loaded, or does not link: it imports something the app's `@protobase/ui` does not have;
|
|
375
384
|
- it defines a name an earlier plugin defines.
|
|
376
385
|
|
|
377
|
-
Every place it would fill then draws its fallback (see [Extension points](#extension-points)). The app's admins (the `admin` role) see a notice below the top bar naming each plugin that is off and why, such as "The plugin sales-tools is off: it
|
|
386
|
+
Every place it would fill then draws its fallback (see [Extension points](#extension-points)). The app's admins (the `admin` role) see a notice below the top bar naming each plugin that is off and why, such as "The plugin sales-tools is off: it uses what this app does not have: NewPicker from @protobase/ui." Everyone else sees only the fallbacks. An action handler that throws shows its error in a toast, as a project's does, and a part that throws while drawing shows its fallback in its own place.
|
|
378
387
|
|
|
379
388
|
## API
|
|
380
389
|
|
|
@@ -87,7 +87,7 @@ Nothing else compares versions: not the build, not the serve runtime. `protobase
|
|
|
87
87
|
|
|
88
88
|
## Plugins
|
|
89
89
|
|
|
90
|
-
[Plugins](plugins.md) are versioned by a plugin API of their own: `@protobase/ui`'s `pluginApi`, 1 so far. A plugin's `plugin.json` names the plugin API it is built for and
|
|
90
|
+
[Plugins](plugins.md) are versioned by a plugin API of their own: `@protobase/ui`'s `pluginApi`, 1 so far. A plugin's `plugin.json` names the plugin API it is built for and what it uses: the names it imports from the modules the app shares and the extension points it fills. An app loads a plugin of its own plugin API when it has everything the plugin uses, whichever release built it, and turns off any other, telling its admins what is missing. A plugin whose author names a range of Protobase versions (`engines.protobase`) also needs the app's version in it (see [versions](plugins.md#versions)).
|
|
91
91
|
|
|
92
92
|
A project's own `protobase.ui.tsx` is a plugin of its bundle, so the same rule holds for it. The admin app it runs in, the shell, is prebuilt once per release; a host that serves a newer release's shell for a bundle whose plugins all load in it gives the app that release's fixes without a rebuild (see [the shell](plugins.md#the-shell)).
|
|
93
93
|
|