@protobase/server 0.132.2 → 0.133.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/better-auth/organizations/host.js +5 -3
- package/dist/better-auth/store/adoption.js +16 -9
- package/dist/better-auth/users.d.ts +3 -1
- package/dist/better-auth/users.js +3 -1
- package/dist/package.js +1 -1
- package/dist/schema-modules/modules.d.ts +1 -1
- package/dist/view-conversation-page.js +4 -0
- package/package.json +6 -6
|
@@ -279,8 +279,8 @@ const organizationsPage = async (auth, scope, { after, size = 100 }) => {
|
|
|
279
279
|
};
|
|
280
280
|
/**
|
|
281
281
|
* Makes `userId` the owner, with the creator's app roles, of every organization without members, in one statement: for
|
|
282
|
-
* the first user of an app whose organizations were made before anyone could own them, such as by its seed.
|
|
283
|
-
* how many.
|
|
282
|
+
* the first user of an app whose organizations were made before anyone could own them, such as by its seed. The
|
|
283
|
+
* default organization is left out: the migration made it to stand in while organizations are off. Returns how many.
|
|
284
284
|
*/
|
|
285
285
|
const ownOrganizationsWithoutMembers = (auth, userId) => acrossOrganizations("the first user owns every organization without members", () => ownEmptyOrganizations(auth, userId));
|
|
286
286
|
const ownEmptyOrganizations = async (auth, userId) => {
|
|
@@ -288,9 +288,11 @@ const ownEmptyOrganizations = async (auth, userId) => {
|
|
|
288
288
|
const store = storeSqlOf(await contextOf(auth));
|
|
289
289
|
const member = store.table("member");
|
|
290
290
|
const m = member.columns;
|
|
291
|
+
const defaultId = settings.options.default?.id;
|
|
292
|
+
const notDefault = defaultId === void 0 ? sql`` : sql`and cast(o.id as text) <> ${defaultId}`;
|
|
291
293
|
const { rows } = await sql`insert into ${member} (id, ${m.organization_id}, ${m.user_id}, ${m.role}, ${m.app_roles}, ${m.created_at})
|
|
292
294
|
select ${store.newId}, o.id, ${userId}, 'owner', ${JSON.stringify(settings.creatorAppRoles)}::jsonb, ${/* @__PURE__ */ new Date()} from ${store.table("organization")} o
|
|
293
|
-
where not exists (select from ${member} m where m.${m.organization_id} = o.id)
|
|
295
|
+
where not exists (select from ${member} m where m.${m.organization_id} = o.id) ${notDefault}
|
|
294
296
|
returning id`.execute(store.db);
|
|
295
297
|
return rows.length;
|
|
296
298
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { allModules } from "../names/modules-on.js";
|
|
2
|
-
import { resolveNames } from "../names/resolve-names.js";
|
|
2
|
+
import { resolveNames, tableNameOf } from "../names/resolve-names.js";
|
|
3
3
|
import { ddl } from "./ddl.js";
|
|
4
4
|
import { migrationNames } from "./steps/step.js";
|
|
5
5
|
import { moduleSteps } from "./steps/index.js";
|
|
@@ -51,14 +51,21 @@ const madeColumns = async (db, names) => {
|
|
|
51
51
|
};
|
|
52
52
|
return run().finally(() => tx.rollback().execute());
|
|
53
53
|
};
|
|
54
|
-
/**
|
|
54
|
+
/**
|
|
55
|
+
* The names of the steps' tables, those of the modules that are off included, besides the user table, which may be
|
|
56
|
+
* another system's. Each is named on its own, so a table of a module that is off never clashes with one that is on,
|
|
57
|
+
* such as a user table named organization; the store's names already refused a name two tables that are on share.
|
|
58
|
+
*/
|
|
59
|
+
const stepTableNames = ({ names }) => {
|
|
60
|
+
const tables = names.input.tables ?? {};
|
|
61
|
+
const user = names.table("user").name;
|
|
62
|
+
const named = Object.values(moduleSteps).flatMap((steps) => steps.flatMap((step) => step.tables.map((table) => tableNameOf(tables, table))));
|
|
63
|
+
return new Set(named.filter((name) => name !== user));
|
|
64
|
+
};
|
|
65
|
+
/** Whether the store has any table of the steps besides the user table (`stepTableNames`). */
|
|
55
66
|
const storeHasTables = async (db, names) => {
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
...names.names.input,
|
|
59
|
-
modules: allModules
|
|
60
|
-
});
|
|
61
|
-
return Object.values(moduleSteps).some((steps) => steps.some((step) => step.tables.some((table) => tables.has(every.tables[table].name))));
|
|
67
|
+
const candidates = stepTableNames(names);
|
|
68
|
+
return (await columnsIn(db, names.schema)).some((column) => candidates.has(column.table));
|
|
62
69
|
};
|
|
63
70
|
/** Which versions the store matches and which it still needs; a version it matches only partly is an error. */
|
|
64
71
|
const planAdoption = async (db, names) => {
|
|
@@ -109,4 +116,4 @@ $adopt$`;
|
|
|
109
116
|
return `-- The auth store an earlier Protobase made, without a record of its migrations, adopted: ${adopted.map(({ migration }) => `${migration.version} ${migration.name}`).join(", ")}\n-- recorded as applied, once every table and column they make is there.\n${statementsSql([check, recordSteps(names, stepsOfVersions(adopted.map(({ migration }) => migration.version)))])}`;
|
|
110
117
|
};
|
|
111
118
|
//#endregion
|
|
112
|
-
export { adoptionSql, planAdoption, storeHasTables };
|
|
119
|
+
export { adoptionSql, planAdoption, stepTableNames, storeHasTables };
|
|
@@ -35,7 +35,9 @@ export declare const hasUsers: (auth: AdminAuth) => Promise<boolean>;
|
|
|
35
35
|
* the first user is always an `admin`, later ones get `role` (default `user`). The address counts as verified, so the
|
|
36
36
|
* user can also sign in with an emailed code. `accounts` link the user to sign-in providers up front, so a provider
|
|
37
37
|
* signs them in by its own id whatever address it reports; one that signs in another user already is refused. With
|
|
38
|
-
* organizations, the first user also owns every organization without members, such as those an app's seed made
|
|
38
|
+
* organizations, the first user also owns every organization without members, such as those an app's seed made,
|
|
39
|
+
* but not the default organization, which the migration made to stand in while organizations are off: on a fresh store
|
|
40
|
+
* they start in no organization and name their first one, where the app's setup for a new organization runs.
|
|
39
41
|
*/
|
|
40
42
|
export declare const createUser: (auth: AdminAuth, input: NewUser) => Promise<{
|
|
41
43
|
id: string;
|
|
@@ -34,7 +34,9 @@ const checkAccounts = async (auth, accounts) => {
|
|
|
34
34
|
* the first user is always an `admin`, later ones get `role` (default `user`). The address counts as verified, so the
|
|
35
35
|
* user can also sign in with an emailed code. `accounts` link the user to sign-in providers up front, so a provider
|
|
36
36
|
* signs them in by its own id whatever address it reports; one that signs in another user already is refused. With
|
|
37
|
-
* organizations, the first user also owns every organization without members, such as those an app's seed made
|
|
37
|
+
* organizations, the first user also owns every organization without members, such as those an app's seed made,
|
|
38
|
+
* but not the default organization, which the migration made to stand in while organizations are off: on a fresh store
|
|
39
|
+
* they start in no organization and name their first one, where the app's setup for a new organization runs.
|
|
38
40
|
*/
|
|
39
41
|
const createUser = async (auth, input) => {
|
|
40
42
|
const first = !await hasUsers(auth);
|
package/dist/package.js
CHANGED
|
@@ -31,7 +31,7 @@ export type ModulesModel = Partial<Record<SchemaModuleId, ModuleModel>>;
|
|
|
31
31
|
/** The schema modules an app needs, each with what it gives the module (`neededModules`), in their order. */
|
|
32
32
|
export type ModuleTargets = Partial<Record<SchemaModuleId, ModuleInput>>;
|
|
33
33
|
/** The modules of `targets`, in their order. */
|
|
34
|
-
export declare const targetIds: (targets: ModuleTargets) => ("status" | "query" | "
|
|
34
|
+
export declare const targetIds: (targets: ModuleTargets) => ("status" | "query" | "user_tables" | "history" | "comments" | "derived" | "jobs" | "changes" | "mail_feedback" | "calls" | "webhooks" | "webhook_delivery_log" | "workflows" | "workflow_custom_steps" | "computed" | "notices" | "workflow_storage" | "notification_devices" | "notification_history" | "relay" | "realtime_relay" | "channel_sends" | "unsubscribes")[];
|
|
35
35
|
/** The model of each module of `targets` this version of Protobase reads. */
|
|
36
36
|
export declare const latestModules: (targets: ModuleTargets) => ModulesModel;
|
|
37
37
|
//#endregion
|
|
@@ -6,8 +6,10 @@ import { deleteErrors, readsDeleteCondition } from "./view-conversation-delete.j
|
|
|
6
6
|
import { reactionsErrors, readsReactions } from "./view-conversation-reactions.js";
|
|
7
7
|
import { readsThreads, threadErrors } from "./view-conversation-thread.js";
|
|
8
8
|
import { messageFieldsProblems, messageTextProblems } from "@protobase/layout";
|
|
9
|
+
import { textPlaceholders } from "@protobase/schema/internal";
|
|
9
10
|
//#region src/view-conversation-page.ts
|
|
10
11
|
const datedTypes = ["date", "timestamp"];
|
|
12
|
+
const recordTextErrors = (prop, text, record) => textPlaceholders(text ?? "").filter((name) => !Object.hasOwn(record.fields, name)).map((name) => `${prop}: names field "${name}", which ${record.name} does not have`);
|
|
11
13
|
const authorErrors = (model) => {
|
|
12
14
|
if (model.author === void 0) return [`${model.name} has no .author(), so it cannot keep each reader's own position`];
|
|
13
15
|
return model.fields[model.author]?.filterable ? [] : [`"${model.author}" on ${model.name} is not filterable, so a reader's own position cannot be found`];
|
|
@@ -54,6 +56,8 @@ const conversationPageErrors = (page, resource, models) => {
|
|
|
54
56
|
...typedErrors(target, "mentions", page.mentions, ["json"], "mentions are a JSON field of user ids"),
|
|
55
57
|
...typedErrors(record, "subtitle", page.subtitle, ["text"], "a subtitle is a text field"),
|
|
56
58
|
...typedErrors(record, "members", page.members, ["json"], "members are a JSON field of user ids"),
|
|
59
|
+
...recordTextErrors("placeholder", page.placeholder, record),
|
|
60
|
+
...recordTextErrors("empty", page.empty, record),
|
|
57
61
|
...page.readPosition ? readPositionErrors(page.readPosition, resource, target, models).map((error) => `readPosition: ${error}`) : [],
|
|
58
62
|
...page.reactions ? reactionsErrors(page.reactions, page.resource, models).map((error) => `reactions: ${error}`) : [],
|
|
59
63
|
...page.attachments ? attachmentsErrors(page.attachments, page.resource, models).map((error) => `attachments: ${error}`) : [],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.133.0",
|
|
4
4
|
"description": "The Protobase REST API as a Hono app, with Better Auth sign-in.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -44,11 +44,11 @@
|
|
|
44
44
|
"@better-auth/sso": "^1.7.12",
|
|
45
45
|
"@livekit/protocol": "1.53.1",
|
|
46
46
|
"@modelcontextprotocol/server": "^2.3.1",
|
|
47
|
-
"@protobase/layout": "0.
|
|
48
|
-
"@protobase/query": "0.
|
|
49
|
-
"@protobase/schema": "0.
|
|
50
|
-
"@protobase/workflow-plugins": "0.
|
|
51
|
-
"@protobase/workflows": "0.
|
|
47
|
+
"@protobase/layout": "0.133.0",
|
|
48
|
+
"@protobase/query": "0.133.0",
|
|
49
|
+
"@protobase/schema": "0.133.0",
|
|
50
|
+
"@protobase/workflow-plugins": "0.133.0",
|
|
51
|
+
"@protobase/workflows": "0.133.0",
|
|
52
52
|
"@react-email/render": "^2.1.0",
|
|
53
53
|
"@react-pdf/primitives": "^4.4.0",
|
|
54
54
|
"@react-pdf/renderer": "^4.9.1",
|