@protobase/server 0.3.5 → 0.4.1

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,23 @@
1
+ import { twoFactor } from "better-auth/plugins";
2
+ //#region src/better-auth/two-factor-challenge.ts
3
+ /**
4
+ * Better Auth's two-factor plugin, whose second step also follows a sign-in with an emailed code: the plugin asks for
5
+ * it after a password only, and an inbox alone is one factor as well. A passkey is two factors already, so a passkey
6
+ * sign-in is not asked. The plugin's own hook does the work; only the paths it matches grow.
7
+ */
8
+ const twoFactorAfterPasswordOrCode = (options) => {
9
+ const plugin = twoFactor(options);
10
+ const after = plugin.hooks.after.map((hook) => ({
11
+ ...hook,
12
+ matcher: (context) => hook.matcher(context) || context.path === "/sign-in/email-otp"
13
+ }));
14
+ return {
15
+ ...plugin,
16
+ hooks: {
17
+ ...plugin.hooks,
18
+ after
19
+ }
20
+ };
21
+ };
22
+ //#endregion
23
+ export { twoFactorAfterPasswordOrCode };
@@ -1,4 +1,5 @@
1
1
  import { AdminAuth } from "./create-auth.js";
2
+ import { parseRoles } from "./parse-roles.js";
2
3
  //#region src/better-auth/users.d.ts
3
4
  /** The roles this auth instance allows, `admin` first. */
4
5
  export declare const roleChoices: (auth: AdminAuth) => string[];
@@ -19,18 +20,14 @@ export type StoredUser = {
19
20
  export declare const hasUsers: (auth: AdminAuth) => Promise<boolean>;
20
21
  /**
21
22
  * Creates a user directly in the admin store. Host side only (no HTTP route creates accounts while the store is empty):
22
- * the first user is always an `admin`, later ones get `role` (default `user`).
23
+ * the first user is always an `admin`, later ones get `role` (default `user`). The address counts as verified, so the
24
+ * user can also sign in with an emailed code.
23
25
  */
24
26
  export declare const createUser: (auth: AdminAuth, input: NewUser) => Promise<{
25
27
  id: string;
26
28
  email: string;
27
29
  role: string;
28
30
  }>;
29
- /**
30
- * The admin plugin stores roles as a comma separated string. A value written as a JS array through a Postgres driver
31
- * comes back as an array literal (`{admin,sales}`); that is read too, and rewritten as a plain string on the next change.
32
- */
33
- export declare const parseRoles: (role: string | string[] | null | undefined) => string[];
34
31
  export declare const listUsers: (auth: AdminAuth) => Promise<StoredUser[]>;
35
32
  /** Deletes the user with their sessions and accounts; refuses to delete the last active admin. */
36
33
  export declare const deleteUser: (auth: AdminAuth, email: string) => Promise<void>;
@@ -47,4 +44,5 @@ export declare const setUserBanned: (auth: AdminAuth, input: {
47
44
  email: string;
48
45
  banned: boolean;
49
46
  }) => Promise<void>;
50
- //#endregion
47
+ //#endregion
48
+ export { parseRoles };
@@ -1,3 +1,4 @@
1
+ import { parseRoles } from "./parse-roles.js";
1
2
  //#region src/better-auth/users.ts
2
3
  /** The roles this auth instance allows, `admin` first. */
3
4
  const roleChoices = (auth) => [...auth.roles];
@@ -11,7 +12,8 @@ const checkRoles = (auth, role) => {
11
12
  const hasUsers = async (auth) => (await auth.$context).adapter.count({ model: "user" }).then((count) => count > 0);
12
13
  /**
13
14
  * Creates a user directly in the admin store. Host side only (no HTTP route creates accounts while the store is empty):
14
- * the first user is always an `admin`, later ones get `role` (default `user`).
15
+ * the first user is always an `admin`, later ones get `role` (default `user`). The address counts as verified, so the
16
+ * user can also sign in with an emailed code.
15
17
  */
16
18
  const createUser = async (auth, input) => {
17
19
  const first = !await hasUsers(auth);
@@ -30,15 +32,6 @@ const createUser = async (auth, input) => {
30
32
  role: String(user.role)
31
33
  };
32
34
  };
33
- /**
34
- * The admin plugin stores roles as a comma separated string. A value written as a JS array through a Postgres driver
35
- * comes back as an array literal (`{admin,sales}`); that is read too, and rewritten as a plain string on the next change.
36
- */
37
- const parseRoles = (role) => {
38
- if (Array.isArray(role)) return role;
39
- const text = (role ?? "user").trim();
40
- return (text.startsWith("{") && text.endsWith("}") ? text.slice(1, -1) : text).split(",").map((name) => name.trim().replace(/^"|"$/g, "")).filter(Boolean);
41
- };
42
35
  const allUsers = async (auth) => {
43
36
  const { adapter } = await auth.$context;
44
37
  return adapter.findMany({
package/dist/index.d.ts CHANGED
@@ -1,3 +1,6 @@
1
+ import { SignInPolicy, SignInRule, StaffAccessRule, defaultSignInPolicy, signInPolicyMethods } from "./better-auth/sign-in-policy.js";
2
+ import { StaffSignIn } from "./better-auth/staff-log.js";
3
+ import { OperatorProvider, readOperatorSettings } from "./better-auth/operator-provider.js";
1
4
  import { AdminAuth, CreateAuthOptions, UserCreatedHook, createAuth, normalizeRoles } from "./better-auth/create-auth.js";
2
5
  import { ResourceSource, configExports } from "./resource-source.js";
3
6
  import { AssistantOptions, AssistantSettings, ModelSettings, assistantRoles, assistantSettings, assistantVariables, seesAssistant } from "./assistant/assistant-settings.js";
@@ -8,7 +11,8 @@ import { consoleAuditQueue } from "./audit/console-queue.js";
8
11
  import { JwtOptions, jwtAuthenticator } from "./auth/jwt.js";
9
12
  import { HttpProblem, badRequest, forbidden, notFound, unauthorized } from "./problem.js";
10
13
  import { BetterAuthAuthenticatorOptions, betterAuthAuthenticator } from "./better-auth/authenticator.js";
11
- import { NewUser, StoredUser, createUser, deleteUser, hasUsers, listUsers, parseRoles, roleChoices, setUserBanned, setUserRole } from "./better-auth/users.js";
14
+ import { parseRoles } from "./better-auth/parse-roles.js";
15
+ import { NewUser, StoredUser, createUser, deleteUser, hasUsers, listUsers, roleChoices, setUserBanned, setUserRole } from "./better-auth/users.js";
12
16
  import { IssueTokenOptions, issueToken, maxTokenTtlSeconds } from "./better-auth/tokens.js";
13
17
  import { ChatMessage, ChatTextPart, Completion, CompletionOptions, ModelError, ReasoningDetail, ReasoningEffort, ToolCall, ToolSpec, streamChatCompletion } from "./assistant/chat-completions.js";
14
18
  import { ConversationRecord, ConversationStore } from "./assistant/conversation-store.js";
@@ -21,4 +25,4 @@ import { AssistantTool, ToolContext, defineTool } from "./assistant/tools.js";
21
25
  import { TurnOptions, runTurn } from "./assistant/turn.js";
22
26
  import { QueryOptions, QueryResult, runReadOnlyQuery, runReadWriteQuery } from "./assistant/run-query.js";
23
27
  import { readOnlyQueryTool, readWriteQueryTool } from "./assistant/query-tools.js";
24
- export { type Admin, type AdminAuth, type AdminOptions, type ApprovalAnswer, type ApprovalRequest, type AssistantBackend, type AssistantOptions, type AssistantSettings, type AssistantTool, type AuditEvent, type AuditQueue, type Authenticator, type BetterAuthAuthenticatorOptions, type ChatMessage, type ChatTextPart, type Completion, type CompletionOptions, type Conversation, type ConversationRecord, type ConversationStore, type ConversationsOptions, type CreateAdminInput, type CreateAuthOptions, HttpProblem, type IssueTokenOptions, type JwtOptions, ModelError, type ModelSettings, type NewUser, type PipelineHook, type QueryOptions, type QueryResult, type ReasoningDetail, type ReasoningEffort, type ResourceSource, type RuntimeOptions, type ScanGuardMode, type Session, type StoredUser, type TenantValue, type ToolCall, type ToolContext, type ToolSpec, type TurnOptions, type User, type UserCreatedHook, type ViewSource, type WriteEvent, type WriteOperation, assistantProtocolRoutes, assistantRoles, assistantSettings, assistantVariables, badRequest, betterAuthAuthenticator, configExports, consoleAuditQueue, conversationKey, createAdmin, createAuth, createConversations, createUser, defineTool, deleteUser, fileConversationStore, forbidden, hasUsers, issueToken, jwtAuthenticator, listUsers, maxTokenTtlSeconds, normalizeRoles, notFound, parseRoles, readOnlyQueryTool, readWriteQueryTool, requestApproval, roleChoices, runReadOnlyQuery, runReadWriteQuery, runTurn, runtimeUrl, runtimeVariable, seesAssistant, seesRuntime, setUserBanned, setUserRole, streamChatCompletion, unauthorized, withCacheBreakpoints };
28
+ export { type Admin, type AdminAuth, type AdminOptions, type ApprovalAnswer, type ApprovalRequest, type AssistantBackend, type AssistantOptions, type AssistantSettings, type AssistantTool, type AuditEvent, type AuditQueue, type Authenticator, type BetterAuthAuthenticatorOptions, type ChatMessage, type ChatTextPart, type Completion, type CompletionOptions, type Conversation, type ConversationRecord, type ConversationStore, type ConversationsOptions, type CreateAdminInput, type CreateAuthOptions, HttpProblem, type IssueTokenOptions, type JwtOptions, ModelError, type ModelSettings, type NewUser, type OperatorProvider, type PipelineHook, type QueryOptions, type QueryResult, type ReasoningDetail, type ReasoningEffort, type ResourceSource, type RuntimeOptions, type ScanGuardMode, type Session, type SignInPolicy, type SignInRule, type StaffAccessRule, type StaffSignIn, type StoredUser, type TenantValue, type ToolCall, type ToolContext, type ToolSpec, type TurnOptions, type User, type UserCreatedHook, type ViewSource, type WriteEvent, type WriteOperation, assistantProtocolRoutes, assistantRoles, assistantSettings, assistantVariables, badRequest, betterAuthAuthenticator, configExports, consoleAuditQueue, conversationKey, createAdmin, createAuth, createConversations, createUser, defaultSignInPolicy, defineTool, deleteUser, fileConversationStore, forbidden, hasUsers, issueToken, jwtAuthenticator, listUsers, maxTokenTtlSeconds, normalizeRoles, notFound, parseRoles, readOnlyQueryTool, readOperatorSettings, readWriteQueryTool, requestApproval, roleChoices, runReadOnlyQuery, runReadWriteQuery, runTurn, runtimeUrl, runtimeVariable, seesAssistant, seesRuntime, setUserBanned, setUserRole, signInPolicyMethods, streamChatCompletion, unauthorized, withCacheBreakpoints };
package/dist/index.js CHANGED
@@ -11,12 +11,15 @@ import { withCacheBreakpoints } from "./assistant/cache-breakpoints.js";
11
11
  import { ModelError, streamChatCompletion } from "./assistant/chat-completions.js";
12
12
  import { runTurn } from "./assistant/turn.js";
13
13
  import { consoleAuditQueue } from "./audit/console-queue.js";
14
+ import { readOperatorSettings } from "./better-auth/operator-provider.js";
15
+ import { defaultSignInPolicy, signInPolicyMethods } from "./better-auth/sign-in-policy.js";
16
+ import { parseRoles } from "./better-auth/parse-roles.js";
14
17
  import { createAuth, normalizeRoles } from "./better-auth/create-auth.js";
15
- import { createUser, deleteUser, hasUsers, listUsers, parseRoles, roleChoices, setUserBanned, setUserRole } from "./better-auth/users.js";
18
+ import { createUser, deleteUser, hasUsers, listUsers, roleChoices, setUserBanned, setUserRole } from "./better-auth/users.js";
16
19
  import { runtimeUrl, runtimeVariable, seesRuntime } from "./runtime/runtime-settings.js";
17
20
  import { createAdmin } from "./create-admin.js";
18
21
  import { configExports } from "./resource-source.js";
19
22
  import { jwtAuthenticator } from "./auth/jwt.js";
20
23
  import { betterAuthAuthenticator } from "./better-auth/authenticator.js";
21
24
  import { issueToken, maxTokenTtlSeconds } from "./better-auth/tokens.js";
22
- export { HttpProblem, ModelError, assistantProtocolRoutes, assistantRoles, assistantSettings, assistantVariables, badRequest, betterAuthAuthenticator, configExports, consoleAuditQueue, conversationKey, createAdmin, createAuth, createConversations, createUser, defineTool, deleteUser, fileConversationStore, forbidden, hasUsers, issueToken, jwtAuthenticator, listUsers, maxTokenTtlSeconds, normalizeRoles, notFound, parseRoles, readOnlyQueryTool, readWriteQueryTool, requestApproval, roleChoices, runReadOnlyQuery, runReadWriteQuery, runTurn, runtimeUrl, runtimeVariable, seesAssistant, seesRuntime, setUserBanned, setUserRole, streamChatCompletion, unauthorized, withCacheBreakpoints };
25
+ export { HttpProblem, ModelError, assistantProtocolRoutes, assistantRoles, assistantSettings, assistantVariables, badRequest, betterAuthAuthenticator, configExports, consoleAuditQueue, conversationKey, createAdmin, createAuth, createConversations, createUser, defaultSignInPolicy, defineTool, deleteUser, fileConversationStore, forbidden, hasUsers, issueToken, jwtAuthenticator, listUsers, maxTokenTtlSeconds, normalizeRoles, notFound, parseRoles, readOnlyQueryTool, readOperatorSettings, readWriteQueryTool, requestApproval, roleChoices, runReadOnlyQuery, runReadWriteQuery, runTurn, runtimeUrl, runtimeVariable, seesAssistant, seesRuntime, setUserBanned, setUserRole, signInPolicyMethods, streamChatCompletion, unauthorized, withCacheBreakpoints };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/server",
3
- "version": "0.3.5",
3
+ "version": "0.4.1",
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": {
@@ -29,10 +29,12 @@
29
29
  "access": "public"
30
30
  },
31
31
  "dependencies": {
32
- "@protobase/layout": "0.3.5",
33
- "@protobase/query": "0.3.5",
34
- "@protobase/schema": "0.3.5",
32
+ "@better-auth/passkey": "^1.7.7",
33
+ "@protobase/layout": "0.4.1",
34
+ "@protobase/query": "0.4.1",
35
+ "@protobase/schema": "0.4.1",
35
36
  "@scalar/hono-api-reference": "^0.12.10",
37
+ "@simplewebauthn/server": "^13.3.1",
36
38
  "better-auth": "^1.7.7",
37
39
  "hono": "^4.13.13",
38
40
  "jose": "^6.2.12",