@protobase/server 0.63.2 → 0.63.4

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.
@@ -0,0 +1,15 @@
1
+ import { checkedUrl } from "../checked-url.js";
2
+ //#region src/better-auth/first-admin-url.ts
3
+ const firstAdminUrlVariable = "PROTOBASE_FIRST_ADMIN_URL";
4
+ /**
5
+ * Where the app's first user is added when the platform hosting it does that, such as its console's page for the app,
6
+ * from `PROTOBASE_FIRST_ADMIN_URL`. The no-users page then links there in place of the `protobase users create`
7
+ * command, which only someone on the host can run. A value that is no http(s) URL stops the server at startup.
8
+ */
9
+ const firstAdminUrl = (env) => {
10
+ const url = env[firstAdminUrlVariable]?.trim();
11
+ if (!url) return void 0;
12
+ return checkedUrl(url, firstAdminUrlVariable);
13
+ };
14
+ //#endregion
15
+ export { firstAdminUrl, firstAdminUrlVariable };
@@ -6,7 +6,8 @@ import { hasUsers } from "./users.js";
6
6
  import { Hono } from "hono";
7
7
  //#region src/better-auth/status-route.ts
8
8
  /**
9
- * `GET {authBase}/status`: `needsAdmin` while the admin store has no user, so a login page can say how to create one;
9
+ * `GET {authBase}/status`: `needsAdmin` while the admin store has no user, so a login page can say how to create one,
10
+ * with `firstAdminUrl` then, the platform's page where it is added, when the platform names one (see `firstAdminUrl`);
10
11
  * `signInMethods`, the ways to sign in the sign-in policy leaves on (`password`, `emailCode`, `passkey`), so it offers
11
12
  * only those; `passwordReset` when reset mail can be sent and passwords are on, so it offers "Forgot password?" only
12
13
  * then; `signInFirst: 'emailCode'` when the app has the sign-in page lead with an emailed code and the policy leaves both it and passwords on; `changeEmail` when mail can be sent, so the account page offers to change the address with an emailed code; `accountDeletion` when people may delete their own account, so the account page offers it; `signUp` when the app has open sign-up, so it offers "Create an account"; the ids of the `socialProviders` people can sign in with, so it offers "Continue with GitHub" when `github` is
@@ -18,7 +19,7 @@ import { Hono } from "hono";
18
19
  * `plugins`, those the app loads before sign-in (see `PluginOption`); and `locale`, the language `options.locale` puts
19
20
  * the screens in, so the sign-in screens and public forms, which come before `/meta`, are in it too.
20
21
  */
21
- const statusRoute = (auth, { anonymous = false, plugins = [], locale } = {}) => {
22
+ const statusRoute = (auth, { anonymous = false, plugins = [], locale, firstAdminUrl } = {}) => {
22
23
  const app = new Hono();
23
24
  app.get("/status", async (c) => {
24
25
  const context = await auth.$context;
@@ -33,8 +34,10 @@ const statusRoute = (auth, { anonymous = false, plugins = [], locale } = {}) =>
33
34
  const platformSignIn = platform && policy.platformSignIn === "allowed" && context.socialProviders.some((provider) => provider.id === platform.provider) ? platform : void 0;
34
35
  const socialProviders = [...auth.socialProviders, ...platformSignIn ? [platformSignIn.provider] : []];
35
36
  const passkeyDomains = signInMethods.includes("passkey") ? await signInPasskeyDomains(context.adapter, auth.passkeyDomain, auth.origins) : [];
37
+ const needsAdmin = !await hasUsers(auth);
36
38
  return c.json({
37
- needsAdmin: !await hasUsers(auth),
39
+ needsAdmin,
40
+ ...needsAdmin && firstAdminUrl && { firstAdminUrl },
38
41
  signInMethods,
39
42
  passwordReset: auth.passwordReset && policy.password === "allowed",
40
43
  ...auth.signInFirst === "emailCode" && signInMethods.includes("emailCode") && signInMethods.includes("password") && { signInFirst: "emailCode" },
@@ -111,6 +111,7 @@ import { faviconPath } from "./web-app/web-manifest.js";
111
111
  import { webManifestRoute } from "./web-app/web-manifest-route.js";
112
112
  import { mcpIcons } from "./web-app/mcp-icons.js";
113
113
  import { recordRoutes } from "./routes/record.js";
114
+ import { firstAdminUrl } from "./better-auth/first-admin-url.js";
114
115
  import { createScanGuard } from "./scan-guard.js";
115
116
  import { failedJobs, failedJobsView } from "./jobs/failed-jobs.js";
116
117
  import { Hono } from "hono";
@@ -181,6 +182,7 @@ const createAdmin = ({ resources: appResources, views: appViews = [], pages = []
181
182
  const systemPath = basePath.slice(0, basePath.lastIndexOf("/"));
182
183
  const assistant = assistantSettings(options.assistant, globalThis.process?.env ?? {});
183
184
  const runtime = runtimeUrl(options.runtime, globalThis.process?.env ?? {});
185
+ const firstAdmin = firstAdminUrl(globalThis.process?.env ?? {});
184
186
  const errorReporting = errorReportingSettings(options.errorReporting, globalThis.process?.env ?? {});
185
187
  const maps = mapSettings(options.maps, globalThis.process?.env ?? {});
186
188
  const senders = notifications ? notificationSenders(notifications) : [];
@@ -329,7 +331,8 @@ const createAdmin = ({ resources: appResources, views: appViews = [], pages = []
329
331
  app.route(authBasePath, statusRoute(auth, {
330
332
  anonymous: visitorsBrowse(options.roles),
331
333
  plugins: pluginsBeforeSignIn(plugins),
332
- ...locale && { locale }
334
+ ...locale && { locale },
335
+ ...firstAdmin && { firstAdminUrl: firstAdmin }
333
336
  }));
334
337
  if (auth.organizations) app.route(authBasePath, organizationRoutes({
335
338
  auth,
package/dist/package.js CHANGED
@@ -1,4 +1,4 @@
1
1
  //#region package.json
2
- var version = "0.63.2";
2
+ var version = "0.63.4";
3
3
  //#endregion
4
4
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/server",
3
- "version": "0.63.2",
3
+ "version": "0.63.4",
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": {
@@ -42,9 +42,9 @@
42
42
  "@better-auth/sso": "^1.7.12",
43
43
  "@livekit/protocol": "1.53.1",
44
44
  "@modelcontextprotocol/server": "^2.3.1",
45
- "@protobase/layout": "0.63.2",
46
- "@protobase/query": "0.63.2",
47
- "@protobase/schema": "0.63.2",
45
+ "@protobase/layout": "0.63.4",
46
+ "@protobase/query": "0.63.4",
47
+ "@protobase/schema": "0.63.4",
48
48
  "@react-email/render": "^2.1.0",
49
49
  "@scalar/hono-api-reference": "^0.12.10",
50
50
  "@sentry/core": "^11.7.0",