@protobase/server 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/admin-options.d.ts +2 -2
- package/dist/app-identity.d.ts +2 -2
- package/dist/app-name.d.ts +2 -0
- package/dist/auth-store.d.ts +3 -0
- package/dist/auth-store.js +3 -0
- package/dist/better-auth/auth-schema.d.ts +7 -8
- package/dist/better-auth/auth-schema.js +40 -42
- package/dist/better-auth/auth-settings.d.ts +8754 -0
- package/dist/better-auth/auth-settings.js +43 -0
- package/dist/better-auth/auth-tables.d.ts +1 -1
- package/dist/better-auth/auth-tables.js +11 -9
- package/dist/better-auth/authenticate-settings.d.ts +15 -0
- package/dist/better-auth/authenticate-settings.js +12 -0
- package/dist/better-auth/authenticator.d.ts +1 -1
- package/dist/better-auth/create-auth.d.ts +34 -14
- package/dist/better-auth/create-auth.js +27 -10
- package/dist/better-auth/mcp/mcp-auth-plugins.d.ts +2719 -0
- package/dist/better-auth/mcp/mcp-auth-plugins.js +68 -0
- package/dist/better-auth/mcp/mcp-plugins.d.ts +7 -2
- package/dist/better-auth/mcp/mcp-plugins.js +3 -68
- package/dist/better-auth/mcp/mcp-token-claims.js +1 -1
- package/dist/better-auth/organizations/store.d.ts +1 -0
- package/dist/better-auth/saml-plugin.d.ts +993 -0
- package/dist/better-auth/saml-plugin.js +36 -0
- package/dist/better-auth/saml-sign-in.d.ts +27 -1
- package/dist/better-auth/saml-sign-in.js +1 -33
- package/dist/better-auth/store/adoption.js +87 -0
- package/dist/better-auth/store/ddl.js +18 -0
- package/dist/better-auth/store/drift.d.ts +9 -0
- package/dist/better-auth/store/drift.js +18 -0
- package/dist/better-auth/store/migration-sql.js +15 -0
- package/dist/better-auth/store/migrations/001-core.js +80 -0
- package/dist/better-auth/store/migrations/002-two-factor.js +25 -0
- package/dist/better-auth/store/migrations/003-passkeys.js +29 -0
- package/dist/better-auth/store/migrations/004-sign-in-policy.js +22 -0
- package/dist/better-auth/store/migrations/005-staff-sign-in.js +25 -0
- package/dist/better-auth/store/migrations/006-organizations.js +50 -0
- package/dist/better-auth/store/migrations/007-mcp.js +150 -0
- package/dist/better-auth/store/migrations/index.js +22 -0
- package/dist/better-auth/store/migrations/migration.d.ts +3 -0
- package/dist/better-auth/store/migrations/migration.js +14 -0
- package/dist/better-auth/store/migrations-table.d.ts +7 -0
- package/dist/better-auth/store/migrations-table.js +23 -0
- package/dist/better-auth/store/resources-outside.d.ts +7 -0
- package/dist/better-auth/store/resources-outside.js +20 -0
- package/dist/better-auth/store/store-db.js +13 -0
- package/dist/better-auth/store/store-names.d.ts +2 -0
- package/dist/better-auth/store/store-names.js +14 -0
- package/dist/better-auth/store/table-names.d.ts +7 -0
- package/dist/better-auth/store/table-names.js +10 -0
- package/dist/better-auth/user-table.js +1 -1
- package/dist/better-auth/users.d.ts +2 -2
- package/dist/comments/comment-users.d.ts +1 -1
- package/dist/config-exports.d.ts +2 -0
- package/dist/config-exports.js +2 -0
- package/dist/create-admin.d.ts +6 -4
- package/dist/create-admin.js +3 -1
- package/dist/encryption/keyring.js +1 -1
- package/dist/files/options.d.ts +5 -8
- package/dist/files/provider-settings.d.ts +16 -0
- package/dist/files/provider-settings.js +17 -0
- package/dist/files/runtime.js +4 -4
- package/dist/forms/runtime.js +3 -3
- package/dist/index.d.ts +22 -19
- package/dist/index.js +11 -11
- package/dist/internal.d.ts +13 -0
- package/dist/internal.js +13 -0
- package/dist/jobs/declared-job.d.ts +24 -0
- package/dist/jobs/declared-job.js +26 -0
- package/dist/jobs/job-types.d.ts +2 -2
- package/dist/mcp/mcp-authenticator.js +3 -3
- package/dist/notifications/device-store-of.d.ts +2 -2
- package/dist/notifications/device-store-of.js +1 -1
- package/dist/notifications/device-store.d.ts +1 -1
- package/dist/notifications/device-store.js +1 -1
- package/dist/notifications/history-store-of.d.ts +2 -2
- package/dist/notifications/history-store-of.js +1 -1
- package/dist/notifications/history-store.d.ts +1 -1
- package/dist/notifications/history-store.js +1 -1
- package/dist/notifications/options.d.ts +3 -1
- package/dist/notifications/options.js +1 -1
- package/dist/notifications/schema.d.ts +3 -3
- package/dist/notifications/schema.js +8 -8
- package/dist/notifications/send-notification.js +1 -1
- package/dist/notifications/sender.d.ts +1 -1
- package/dist/notifications/sender.js +2 -2
- package/dist/notifications/senders-of.d.ts +1 -1
- package/dist/notifications/senders-of.js +1 -1
- package/dist/package.js +1 -1
- package/dist/webhooks/subscription.d.ts +1 -0
- package/dist/webhooks/table/options.d.ts +1 -1
- package/dist/webhooks/table/schema.d.ts +2 -2
- package/dist/webhooks/table/schema.js +2 -2
- package/dist/webhooks/table/webhook-table.js +2 -2
- package/dist/webhooks/table/webhooks-module.d.ts +108 -0
- package/dist/webhooks/table/webhooks-module.js +11 -0
- package/package.json +8 -5
- package/dist/better-auth/mcp/mcp-tables.js +0 -32
- package/dist/better-auth/snake-case-migration.js +0 -122
- package/dist/notifications/plugin.d.ts +0 -13
- package/dist/notifications/plugin.js +0 -16
- package/dist/project-config.d.ts +0 -54
- package/dist/project-config.js +0 -182
- package/dist/webhooks/table/plugin.d.ts +0 -10
- package/dist/webhooks/table/plugin.js +0 -18
package/dist/admin-options.d.ts
CHANGED
|
@@ -67,7 +67,7 @@ export type AdminOptions = {
|
|
|
67
67
|
/** The assistant in the admin app's dock: a backend elsewhere or the built-in one (see `AssistantOptions`); `false` turns it off. */
|
|
68
68
|
assistant?: AssistantOptions | false;
|
|
69
69
|
/**
|
|
70
|
-
* The MCP endpoint, on with `
|
|
70
|
+
* The MCP endpoint, on with `auth.mcp`. `sql: true` also offers admins and the `ai` role
|
|
71
71
|
* `run_read_only_query`, which reads the whole database as the app's database role, outside the access rules.
|
|
72
72
|
* `writes: true` offers `create_record` and `update_record`, through the REST API's access rules, `validate` and write
|
|
73
73
|
* hooks; the person approves each write in their client, and a client that cannot ask is refused.
|
|
@@ -84,7 +84,7 @@ export type AdminOptions = {
|
|
|
84
84
|
} | false;
|
|
85
85
|
/**
|
|
86
86
|
* The websites whose browser code may call the API (`/api/*` but `/api/auth/*`) besides the app's own origins (see
|
|
87
|
-
* `
|
|
87
|
+
* `auth.origins`): a list of origins, or `*` for any. Defaults to the one the platform passes in
|
|
88
88
|
* `PROTOBASE_CORS_ORIGINS` (`*` or comma separated), when set. A `mobile` section adds the app's Capacitor origins
|
|
89
89
|
* (`capacitor://localhost`, `https://localhost`). With none of these nor other origins, the API sends no CORS headers.
|
|
90
90
|
*/
|
package/dist/app-identity.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
//#region src/app-identity.d.ts
|
|
2
2
|
/**
|
|
3
|
-
* The `app` section of `protobase.config.ts`: the colours the installed app shows, beside its name (`
|
|
4
|
-
*
|
|
3
|
+
* The `app` section of `protobase.config.ts`: the colours the installed app shows, beside its name (`auth.appName`)
|
|
4
|
+
* and its icons (`protobase.favicon.svg` and the PNGs beside it). Any CSS colour, such as `#0d9488`.
|
|
5
5
|
*/
|
|
6
6
|
export type AppIdentity = {
|
|
7
7
|
/** The colour of the installed app's title bar and of the browser's toolbar around it. */
|
package/dist/app-name.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
//#region src/app-name.d.ts
|
|
2
2
|
/** The app's name when neither the app nor the platform names it. */
|
|
3
3
|
export declare const defaultAppName = "Protobase";
|
|
4
|
+
/** The name the app goes by: the platform's `PROTOBASE_APP_NAME`, which deployments rename it with, over its own `own`. */
|
|
5
|
+
export declare const appNameOver: (env: Record<string, string | undefined>, own: string | undefined) => string | undefined;
|
|
4
6
|
/** The name the app shows, in its upper left and its tabs, and mails as: its auth's, else the platform's, else the default. */
|
|
5
7
|
export declare const shownAppName: (auth: {
|
|
6
8
|
appName?: string;
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import { AdminAuth } from "./create-auth.js";
|
|
2
2
|
//#region src/better-auth/auth-schema.d.ts
|
|
3
3
|
/**
|
|
4
|
-
* The SQL that brings the admin store
|
|
5
|
-
* for a store
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* column without a default on a table with rows, is an error.
|
|
4
|
+
* The SQL that brings the admin store to this version of Protobase: the migrations it has not applied, each followed by
|
|
5
|
+
* its row in `auth_migrations`; for a new store, that table first. A store an earlier Protobase made without the record
|
|
6
|
+
* is adopted: the migrations it matches are recorded as applied (`planAdoption`), the others follow. `undefined` when
|
|
7
|
+
* the store is current. The SQL never drops anything.
|
|
9
8
|
*/
|
|
10
9
|
export declare const authSchemaMigration: (auth: AdminAuth) => Promise<string | undefined>;
|
|
11
10
|
/**
|
|
12
|
-
* Refuses to go on while the admin store
|
|
13
|
-
*
|
|
14
|
-
*
|
|
11
|
+
* Refuses to go on while the admin store has not applied every migration of this version of Protobase, from its
|
|
12
|
+
* `auth_migrations` alone, since every sign-in would fail. The server never changes the schema itself: the project's
|
|
13
|
+
* migrations do, before the new version serves.
|
|
15
14
|
*/
|
|
16
15
|
export declare const checkAuthSchema: (auth: AdminAuth) => Promise<void>;
|
|
17
16
|
//#endregion
|
|
@@ -1,54 +1,52 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { storeNames } from "./store/store-names.js";
|
|
2
|
+
import { latestStoreVersion, storeMigrations } from "./store/migrations/index.js";
|
|
3
|
+
import { appliedVersions, migrationsTableName } from "./store/migrations-table.js";
|
|
4
|
+
import { migrationSql, migrationsTableSql } from "./store/migration-sql.js";
|
|
5
|
+
import { adoptionSql, planAdoption, storeHasTables } from "./store/adoption.js";
|
|
6
|
+
import { storeDb } from "./store/store-db.js";
|
|
5
7
|
//#region src/better-auth/auth-schema.ts
|
|
6
8
|
/** The command that writes the pending changes as a migration file of the project. */
|
|
7
9
|
const authMigrationCommand = "protobase auth migration";
|
|
10
|
+
const refuseNewer = (applied) => {
|
|
11
|
+
const newest = applied.at(-1);
|
|
12
|
+
if (newest !== void 0 && newest > latestStoreVersion) throw new Error(`The auth store is at migration ${newest}, newer than the ${latestStoreVersion} this version of Protobase knows; upgrade Protobase`);
|
|
13
|
+
};
|
|
8
14
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Better Auth adds `email_verified` to a `user` table that exists only when the table still has the camelCase names
|
|
15
|
-
* of Protobase 0.6, whose `emailVerified` it does not know: such a store is renamed, never given new columns beside
|
|
16
|
-
* the old ones.
|
|
17
|
-
*/
|
|
18
|
-
const hasCamelCaseNames = ({ toBeAdded }) => toBeAdded.some(({ table, fields }) => table === "user" && "email_verified" in fields);
|
|
19
|
-
/**
|
|
20
|
-
* The SQL that brings the admin store up to what this version of Protobase and the project's Better Auth plugins need:
|
|
21
|
-
* for a store with the camelCase names of Protobase 0.6, their rename to snake_case (`snakeCaseMigration`); otherwise
|
|
22
|
-
* new tables, columns and indexes, each skipped where it exists, and never a drop but of MCP's tables once MCP is off
|
|
23
|
-
* (`dropMcpTables`). `undefined` when the store is current. A change Better Auth cannot make safely, such as a required
|
|
24
|
-
* column without a default on a table with rows, is an error.
|
|
15
|
+
* The SQL that brings the admin store to this version of Protobase: the migrations it has not applied, each followed by
|
|
16
|
+
* its row in `auth_migrations`; for a new store, that table first. A store an earlier Protobase made without the record
|
|
17
|
+
* is adopted: the migrations it matches are recorded as applied (`planAdoption`), the others follow. `undefined` when
|
|
18
|
+
* the store is current. The SQL never drops anything.
|
|
25
19
|
*/
|
|
26
20
|
const authSchemaMigration = async (auth) => {
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
21
|
+
const names = storeNames(auth);
|
|
22
|
+
const db = storeDb(auth);
|
|
23
|
+
const applied = await appliedVersions(db, names);
|
|
24
|
+
if (applied !== void 0) {
|
|
25
|
+
refuseNewer(applied);
|
|
26
|
+
const pending = storeMigrations.filter((migration) => !applied.includes(migration.version));
|
|
27
|
+
return pending.length === 0 ? void 0 : pending.map((migration) => migrationSql(names, migration)).join("\n\n");
|
|
28
|
+
}
|
|
29
|
+
if (!await storeHasTables(db, names)) return [migrationsTableSql(names), ...storeMigrations.map((migration) => migrationSql(names, migration))].join("\n\n");
|
|
30
|
+
const { adopted, pending } = await planAdoption(db, names);
|
|
31
|
+
return [
|
|
32
|
+
migrationsTableSql(names),
|
|
33
|
+
adoptionSql(names, adopted),
|
|
34
|
+
...pending.map((migration) => migrationSql(names, migration))
|
|
35
|
+
].join("\n\n");
|
|
33
36
|
};
|
|
34
37
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
|
|
38
|
-
const missingTablesAndColumns = (auth, { toBeCreated, toBeAdded }) => [...toBeCreated.map(({ table }) => table).filter((table) => auth.mcp || !mcpTableNames.includes(table)), ...toBeAdded.flatMap(({ table, fields }) => Object.keys(fields).map((field) => `${table}.${field}`))];
|
|
39
|
-
/**
|
|
40
|
-
* Refuses to go on while the admin store lacks a table or column Better Auth needs, still has the camelCase names of
|
|
41
|
-
* Protobase 0.6, since every sign-in would fail, or still has MCP's tables with MCP off, since their grants would come
|
|
42
|
-
* back with MCP. The server never changes the schema itself: the project's migrations do, before the new version serves.
|
|
38
|
+
* Refuses to go on while the admin store has not applied every migration of this version of Protobase, from its
|
|
39
|
+
* `auth_migrations` alone, since every sign-in would fail. The server never changes the schema itself: the project's
|
|
40
|
+
* migrations do, before the new version serves.
|
|
43
41
|
*/
|
|
44
42
|
const checkAuthSchema = async (auth) => {
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
if (
|
|
51
|
-
throw new Error(`The auth schema
|
|
43
|
+
const applied = await appliedVersions(storeDb(auth), storeNames(auth));
|
|
44
|
+
const write = `Write it as a migration with \`${authMigrationCommand}\`, apply it with the project's migrations, then start again.`;
|
|
45
|
+
if (applied === void 0) throw new Error(`The auth store has no ${migrationsTableName} table: it is new, or an earlier Protobase made it. ${write}`);
|
|
46
|
+
refuseNewer(applied);
|
|
47
|
+
const missing = storeMigrations.filter((migration) => !applied.includes(migration.version));
|
|
48
|
+
if (missing.length === 0) return;
|
|
49
|
+
throw new Error(`The auth schema is behind this version of Protobase (missing migrations ${missing.map(({ version, name }) => `${version} ${name}`).join(", ")}). ${write}`);
|
|
52
50
|
};
|
|
53
51
|
//#endregion
|
|
54
|
-
export { authMigrationCommand, authSchemaMigration, checkAuthSchema
|
|
52
|
+
export { authMigrationCommand, authSchemaMigration, checkAuthSchema };
|