@protobase/server 0.48.0 → 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.
Files changed (69) hide show
  1. package/dist/admin-options.d.ts +2 -2
  2. package/dist/app-identity.d.ts +2 -2
  3. package/dist/app-name.d.ts +2 -0
  4. package/dist/better-auth/auth-settings.d.ts +8754 -0
  5. package/dist/better-auth/auth-settings.js +43 -0
  6. package/dist/better-auth/authenticate-settings.d.ts +15 -0
  7. package/dist/better-auth/authenticate-settings.js +12 -0
  8. package/dist/better-auth/create-auth.d.ts +23 -11
  9. package/dist/better-auth/create-auth.js +21 -9
  10. package/dist/better-auth/mcp/mcp-auth-plugins.d.ts +2719 -0
  11. package/dist/better-auth/mcp/mcp-auth-plugins.js +68 -0
  12. package/dist/better-auth/mcp/mcp-plugins.d.ts +7 -2
  13. package/dist/better-auth/mcp/mcp-plugins.js +3 -68
  14. package/dist/better-auth/mcp/mcp-token-claims.js +1 -1
  15. package/dist/better-auth/organizations/store.d.ts +1 -0
  16. package/dist/better-auth/saml-plugin.d.ts +993 -0
  17. package/dist/better-auth/saml-plugin.js +36 -0
  18. package/dist/better-auth/saml-sign-in.d.ts +27 -1
  19. package/dist/better-auth/saml-sign-in.js +1 -33
  20. package/dist/better-auth/user-table.js +1 -1
  21. package/dist/better-auth/users.d.ts +1 -1
  22. package/dist/create-admin.d.ts +5 -3
  23. package/dist/create-admin.js +3 -1
  24. package/dist/encryption/keyring.js +1 -1
  25. package/dist/files/options.d.ts +5 -8
  26. package/dist/files/provider-settings.d.ts +16 -0
  27. package/dist/files/provider-settings.js +17 -0
  28. package/dist/files/runtime.js +4 -4
  29. package/dist/forms/runtime.js +3 -3
  30. package/dist/index.d.ts +16 -15
  31. package/dist/index.js +8 -10
  32. package/dist/internal.d.ts +13 -0
  33. package/dist/internal.js +13 -0
  34. package/dist/jobs/declared-job.d.ts +24 -0
  35. package/dist/jobs/declared-job.js +26 -0
  36. package/dist/jobs/job-types.d.ts +1 -1
  37. package/dist/mcp/mcp-authenticator.js +3 -3
  38. package/dist/notifications/device-store-of.d.ts +1 -1
  39. package/dist/notifications/device-store-of.js +1 -1
  40. package/dist/notifications/device-store.d.ts +1 -1
  41. package/dist/notifications/device-store.js +1 -1
  42. package/dist/notifications/history-store-of.d.ts +1 -1
  43. package/dist/notifications/history-store-of.js +1 -1
  44. package/dist/notifications/history-store.d.ts +1 -1
  45. package/dist/notifications/history-store.js +1 -1
  46. package/dist/notifications/options.d.ts +3 -1
  47. package/dist/notifications/options.js +1 -1
  48. package/dist/notifications/schema.d.ts +2 -2
  49. package/dist/notifications/schema.js +7 -7
  50. package/dist/notifications/send-notification.js +1 -1
  51. package/dist/notifications/sender.d.ts +1 -1
  52. package/dist/notifications/sender.js +2 -2
  53. package/dist/notifications/senders-of.d.ts +1 -1
  54. package/dist/notifications/senders-of.js +1 -1
  55. package/dist/package.js +1 -1
  56. package/dist/webhooks/subscription.d.ts +1 -0
  57. package/dist/webhooks/table/options.d.ts +1 -1
  58. package/dist/webhooks/table/schema.d.ts +2 -2
  59. package/dist/webhooks/table/schema.js +2 -2
  60. package/dist/webhooks/table/webhook-table.js +2 -2
  61. package/dist/webhooks/table/webhooks-module.d.ts +108 -0
  62. package/dist/webhooks/table/webhooks-module.js +11 -0
  63. package/package.json +6 -5
  64. package/dist/notifications/plugin.d.ts +0 -13
  65. package/dist/notifications/plugin.js +0 -16
  66. package/dist/project-config.d.ts +0 -54
  67. package/dist/project-config.js +0 -182
  68. package/dist/webhooks/table/plugin.d.ts +0 -10
  69. package/dist/webhooks/table/plugin.js +0 -18
@@ -0,0 +1,68 @@
1
+ import { mcpConsentCheck } from "./consent-check.js";
2
+ import { mcpGrantRevocation } from "./revoke-grants.js";
3
+ import { pluginNames } from "../snake-case-names.js";
4
+ import { mcpConnectedApps } from "./connected-apps.js";
5
+ import { consentReference } from "./consent-reference.js";
6
+ import { mcpTokenClaims } from "./mcp-token-claims.js";
7
+ import { mcpRefreshReuse } from "./refresh-reuse.js";
8
+ import { mcpRequestDefaults } from "./request-defaults.js";
9
+ import { mcpSetupGate } from "./setup-gate.js";
10
+ import { mcpSignedQueryGuard } from "./signed-query-guard.js";
11
+ import { cimd } from "@better-auth/cimd";
12
+ import { fetchClientMetadataResource } from "@better-auth/cimd/node";
13
+ import { mcp } from "@better-auth/mcp";
14
+ //#region src/better-auth/mcp/mcp-auth-plugins.ts
15
+ /**
16
+ * The Better Auth plugins of an OAuth provider for MCP clients, after the `jwt` plugin, in this order: the guard on
17
+ * signed queries, the request defaults, the setup gate, the provider (`mcp()`), and client metadata documents
18
+ * (`cimd()`), the revocation when the account is secured (`mcpGrantRevocation`) or a refresh token is reused
19
+ * (`mcpRefreshReuse`), and the person's list of connected
20
+ * apps, where they disconnect one (`mcpConnectedApps`). A client registers itself, the person signs in on the app's own pages and allows it on the connect
21
+ * page, and the client gets 15-minute access tokens for the MCP resource only, with refresh tokens, carrying the role
22
+ * and organization the person worked in when they allowed it.
23
+ */
24
+ const mcpAuthPlugins = ({ mcp: resolved, organizations, mail, defaultPolicy, definitions, context }) => [
25
+ mcpSignedQueryGuard(),
26
+ mcpRequestDefaults(resolved.resource),
27
+ mcpSetupGate({
28
+ mail,
29
+ defaultPolicy,
30
+ connectPage: resolved.connectPage
31
+ }),
32
+ mcp({
33
+ resource: resolved.resource,
34
+ loginPage: resolved.connectPage,
35
+ consentPage: resolved.connectPage,
36
+ scopes: ["mcp", "offline_access"],
37
+ clientRegistrationDefaultScopes: ["mcp", "offline_access"],
38
+ grantTypes: ["authorization_code", "refresh_token"],
39
+ allowDynamicClientRegistration: true,
40
+ allowUnauthenticatedClientRegistration: true,
41
+ clientRegistrationDefaultApplicationType: "infer",
42
+ postLogin: {
43
+ page: resolved.connectPage,
44
+ shouldRedirect: () => false,
45
+ consentReferenceId: async ({ user, session }) => consentReference(await context(), {
46
+ user,
47
+ session
48
+ })
49
+ },
50
+ customAccessTokenClaims: async ({ user, referenceId }) => mcpTokenClaims(await context(), {
51
+ organizations,
52
+ mail,
53
+ defaultPolicy
54
+ }, user, referenceId),
55
+ accessTokenExpiresIn: 900,
56
+ extensions: [mcpConsentCheck()],
57
+ schema: pluginNames.mcp
58
+ }),
59
+ cimd({
60
+ fetchClientMetadataResource: resolved.fetchClientMetadata ?? fetchClientMetadataResource,
61
+ metadataProfile: "mcp-2026-07-28"
62
+ }),
63
+ mcpGrantRevocation(),
64
+ mcpRefreshReuse(),
65
+ mcpConnectedApps({ definitions })
66
+ ];
67
+ //#endregion
68
+ export { mcpAuthPlugins };
@@ -1,5 +1,3 @@
1
- import "../organizations/store.js";
2
- import "./connected-apps.js";
3
1
  import { ClientMetadataResourceFetch } from "@better-auth/oauth-provider";
4
2
  //#region src/better-auth/mcp/mcp-plugins.d.ts
5
3
  export type McpAuthOptions = {
@@ -10,4 +8,11 @@ export type McpAuthOptions = {
10
8
  /** Fetches a client's metadata document (a URL client id); default the CIMD plugin's Node transport, which refuses non-public addresses. */
11
9
  fetchClientMetadata?: ClientMetadataResourceFetch;
12
10
  };
11
+ /** `McpAuthOptions` with the defaults filled in and the resource worked out. */
12
+ export type ResolvedMcp = {
13
+ path: string;
14
+ connectPage: string;
15
+ resource: string;
16
+ fetchClientMetadata?: ClientMetadataResourceFetch;
17
+ };
13
18
  //#endregion
@@ -1,17 +1,4 @@
1
- import { mcpConsentCheck } from "./consent-check.js";
2
- import { mcpGrantRevocation } from "./revoke-grants.js";
3
- import { pluginNames } from "../snake-case-names.js";
4
- import { mcpConnectedApps } from "./connected-apps.js";
5
- import { consentReference } from "./consent-reference.js";
6
- import { mcpTokenClaims } from "./mcp-token-claims.js";
7
- import { mcpRefreshReuse } from "./refresh-reuse.js";
8
- import { mcpRequestDefaults } from "./request-defaults.js";
9
- import { mcpSetupGate } from "./setup-gate.js";
10
- import { mcpSignedQueryGuard } from "./signed-query-guard.js";
11
1
  import { connectRoute } from "@protobase/schema";
12
- import { cimd } from "@better-auth/cimd";
13
- import { fetchClientMetadataResource } from "@better-auth/cimd/node";
14
- import { mcp } from "@better-auth/mcp";
15
2
  //#region src/better-auth/mcp/mcp-plugins.ts
16
3
  /** The path of the app's MCP endpoint, below its origin, unless `mcp.path` names another. */
17
4
  const defaultMcpPath = "/api/mcp";
@@ -22,14 +9,14 @@ const mcpResource = (baseURL, path) => `${new URL(baseURL).origin}${path}`;
22
9
  * resource is never the issuer, in either of its forms, whose tokens the app's own API takes.
23
10
  */
24
11
  const resolveMcp = (baseURL, options) => {
25
- const { path = defaultMcpPath, connectPage = connectRoute, fetchClientMetadata = fetchClientMetadataResource } = options === true ? {} : options;
12
+ const { path = defaultMcpPath, connectPage = connectRoute, fetchClientMetadata } = options === true ? {} : options;
26
13
  if (!path.startsWith("/") || path.length < 2) throw new Error(`mcp.path "${path}" must be a path below the app's origin, such as ${defaultMcpPath}`);
27
14
  if (!connectPage.startsWith("/")) throw new Error(`mcp.connectPage "${connectPage}" must be a path on the app's origin, such as ${connectRoute}`);
28
15
  return {
29
16
  path,
30
17
  connectPage,
31
18
  resource: mcpResource(baseURL, path),
32
- fetchClientMetadata
19
+ ...fetchClientMetadata && { fetchClientMetadata }
33
20
  };
34
21
  };
35
22
  /**
@@ -54,57 +41,5 @@ const mcpUnusedPaths = [
54
41
  "/oauth2/update-consent",
55
42
  "/oauth2/delete-consent"
56
43
  ];
57
- /**
58
- * The Better Auth plugins of an OAuth provider for MCP clients, after the `jwt` plugin, in this order: the guard on
59
- * signed queries, the request defaults, the setup gate, the provider (`mcp()`), and client metadata documents
60
- * (`cimd()`), the revocation when the account is secured (`mcpGrantRevocation`) or a refresh token is reused
61
- * (`mcpRefreshReuse`), and the person's list of connected
62
- * apps, where they disconnect one (`mcpConnectedApps`). A client registers itself, the person signs in on the app's own pages and allows it on the connect
63
- * page, and the client gets 15-minute access tokens for the MCP resource only, with refresh tokens, carrying the role
64
- * and organization the person worked in when they allowed it.
65
- */
66
- const mcpAuthPlugins = ({ mcp: resolved, organizations, mail, defaultPolicy, definitions, context }) => [
67
- mcpSignedQueryGuard(),
68
- mcpRequestDefaults(resolved.resource),
69
- mcpSetupGate({
70
- mail,
71
- defaultPolicy,
72
- connectPage: resolved.connectPage
73
- }),
74
- mcp({
75
- resource: resolved.resource,
76
- loginPage: resolved.connectPage,
77
- consentPage: resolved.connectPage,
78
- scopes: ["mcp", "offline_access"],
79
- clientRegistrationDefaultScopes: ["mcp", "offline_access"],
80
- grantTypes: ["authorization_code", "refresh_token"],
81
- allowDynamicClientRegistration: true,
82
- allowUnauthenticatedClientRegistration: true,
83
- clientRegistrationDefaultApplicationType: "infer",
84
- postLogin: {
85
- page: resolved.connectPage,
86
- shouldRedirect: () => false,
87
- consentReferenceId: async ({ user, session }) => consentReference(await context(), {
88
- user,
89
- session
90
- })
91
- },
92
- customAccessTokenClaims: async ({ user, referenceId }) => mcpTokenClaims(await context(), {
93
- organizations,
94
- mail,
95
- defaultPolicy
96
- }, user, referenceId),
97
- accessTokenExpiresIn: 900,
98
- extensions: [mcpConsentCheck()],
99
- schema: pluginNames.mcp
100
- }),
101
- cimd({
102
- fetchClientMetadataResource: resolved.fetchClientMetadata,
103
- metadataProfile: "mcp-2026-07-28"
104
- }),
105
- mcpGrantRevocation(),
106
- mcpRefreshReuse(),
107
- mcpConnectedApps({ definitions })
108
- ];
109
44
  //#endregion
110
- export { defaultMcpPath, mcpAuthPlugins, mcpResource, mcpUnusedPaths, resolveMcp };
45
+ export { defaultMcpPath, mcpResource, mcpUnusedPaths, resolveMcp };
@@ -1,8 +1,8 @@
1
1
  import { missingSetup } from "../sign-in-setup.js";
2
2
  import { heldRoles } from "../roles/session-role.js";
3
- import { readGrantReference } from "./grant-reference.js";
4
3
  import { mayEnter } from "../organizations/session-organization.js";
5
4
  import { tokenClaims } from "../token-claims.js";
5
+ import { readGrantReference } from "./grant-reference.js";
6
6
  import { APIError } from "better-auth/api";
7
7
  //#region src/better-auth/mcp/mcp-token-claims.ts
8
8
  const refused = (description) => new APIError("BAD_REQUEST", {
@@ -1,5 +1,6 @@
1
1
  import { createAuthMiddleware } from "better-auth/api";
2
2
  //#region src/better-auth/organizations/store.d.ts
3
+ export type AuthContext = Parameters<Parameters<typeof createAuthMiddleware>[0]>[0]['context'];
3
4
  export type OrganizationRole = 'owner' | 'admin' | 'member';
4
5
  export type StoredMember = {
5
6
  id: string;