@terreno/api 57.19.2 → 57.21.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 (259) hide show
  1. package/CHANGELOG.md +443 -0
  2. package/biome.jsonc +1 -0
  3. package/dist/accountSecurity/accessActions.d.ts +38 -0
  4. package/dist/accountSecurity/accessActions.js +157 -0
  5. package/dist/accountSecurity/accountSecurityApp.d.ts +219 -0
  6. package/dist/accountSecurity/accountSecurityApp.js +438 -0
  7. package/dist/accountSecurity/accountSecurityService.d.ts +200 -0
  8. package/dist/accountSecurity/accountSecurityService.js +481 -0
  9. package/dist/accountSecurity/credentialActions.d.ts +16 -0
  10. package/dist/accountSecurity/credentialActions.js +189 -0
  11. package/dist/accountSecurity/membershipActions.d.ts +15 -0
  12. package/dist/accountSecurity/membershipActions.js +81 -0
  13. package/dist/accountSecurity/orgSecurityRoutes.d.ts +50 -0
  14. package/dist/accountSecurity/orgSecurityRoutes.js +149 -0
  15. package/dist/accountSecurity/securityEventHooks.d.ts +44 -0
  16. package/dist/accountSecurity/securityEventHooks.js +223 -0
  17. package/dist/accountSecurity/securityEvents.d.ts +162 -0
  18. package/dist/accountSecurity/securityEvents.js +114 -0
  19. package/dist/accountSecurity/securityNotifications.d.ts +125 -0
  20. package/dist/accountSecurity/securityNotifications.js +333 -0
  21. package/dist/api.d.ts +3 -3
  22. package/dist/api.js +38 -6
  23. package/dist/audit/auditEventModel.d.ts +5 -3
  24. package/dist/audit/auditEventModel.js +8 -6
  25. package/dist/audit/processQueue.js +4 -2
  26. package/dist/audit/record.d.ts +2 -2
  27. package/dist/audit/record.js +3 -0
  28. package/dist/authRecovery.js +29 -1
  29. package/dist/betterAuth.d.ts +179 -10
  30. package/dist/betterAuthApp.d.ts +15 -0
  31. package/dist/betterAuthApp.js +23 -0
  32. package/dist/betterAuthChallengeHeaders.d.ts +37 -0
  33. package/dist/betterAuthChallengeHeaders.js +180 -0
  34. package/dist/betterAuthFeatures.d.ts +54 -0
  35. package/dist/betterAuthFeatures.js +239 -0
  36. package/dist/betterAuthMethods.d.ts +73 -0
  37. package/dist/betterAuthMethods.js +55 -0
  38. package/dist/betterAuthOAuthHandoff.d.ts +10 -2
  39. package/dist/betterAuthOAuthHandoff.js +222 -24
  40. package/dist/betterAuthSetPassword.d.ts +33 -0
  41. package/dist/betterAuthSetPassword.js +166 -0
  42. package/dist/betterAuthSetup.d.ts +57 -8
  43. package/dist/betterAuthSetup.js +327 -36
  44. package/dist/consentApp.d.ts +9 -4
  45. package/dist/consentApp.js +344 -28
  46. package/dist/consentStatus.d.ts +60 -0
  47. package/dist/consentStatus.js +111 -0
  48. package/dist/errors.d.ts +6 -0
  49. package/dist/errors.js +41 -2
  50. package/dist/expressServer.js +3 -2
  51. package/dist/frameworkModelNames.d.ts +4 -0
  52. package/dist/frameworkModelNames.js +4 -0
  53. package/dist/index.d.ts +18 -2
  54. package/dist/index.js +29 -3
  55. package/dist/mcp/adminTracking.d.ts +28 -0
  56. package/dist/mcp/adminTracking.js +80 -0
  57. package/dist/mcp/auth.d.ts +6 -0
  58. package/dist/mcp/auth.js +12 -2
  59. package/dist/mcp/oauth.js +151 -11
  60. package/dist/mcp/oauthMetadata.d.ts +2 -1
  61. package/dist/mcp/oauthMetadata.js +7 -4
  62. package/dist/mcp/server.d.ts +8 -0
  63. package/dist/mcp/server.js +48 -4
  64. package/dist/models/consentResponse.js +51 -0
  65. package/dist/models/mcpOAuthClient.js +78 -2
  66. package/dist/models/mcpOAuthToken.js +55 -4
  67. package/dist/models/mcpRequestLog.d.ts +2 -0
  68. package/dist/models/mcpRequestLog.js +73 -0
  69. package/dist/models/mcpServiceToken.js +4 -0
  70. package/dist/models/mcpToolSetting.d.ts +2 -0
  71. package/dist/models/mcpToolSetting.js +119 -0
  72. package/dist/models/versionConfig.d.ts +2 -0
  73. package/dist/orgs/membershipGuards.d.ts +7 -0
  74. package/dist/orgs/membershipGuards.js +32 -0
  75. package/dist/orgs/orgsApp.d.ts +19 -1
  76. package/dist/orgs/orgsApp.js +55 -24
  77. package/dist/rateLimit/policies.js +8 -0
  78. package/dist/rbac/access.js +2 -1
  79. package/dist/rbac/auditModel.d.ts +2 -1
  80. package/dist/rbac/resolve.d.ts +9 -1
  81. package/dist/rbac/resolve.js +21 -16
  82. package/dist/rbac/roleManager.d.ts +6 -0
  83. package/dist/rbac/roleManager.js +8 -7
  84. package/dist/rbac/roleModel.d.ts +1 -0
  85. package/dist/rbac/roleModel.js +45 -3
  86. package/dist/rbac/statements.d.ts +2 -2
  87. package/dist/rbac/statements.js +10 -1
  88. package/dist/rbac/types.d.ts +6 -0
  89. package/dist/rbac/userWriteGuards.js +2 -1
  90. package/dist/schemaMetadata.js +8 -1
  91. package/dist/seedRunner.js +7 -2
  92. package/dist/terrenoApp.d.ts +16 -0
  93. package/dist/terrenoApp.js +18 -0
  94. package/dist/tests/models.d.ts +22 -22
  95. package/dist/tests/models.js +15 -1
  96. package/dist/tests/testHelper.d.ts +6 -12
  97. package/dist/tests.d.ts +1 -0
  98. package/dist/tests.js +3 -1
  99. package/dist/types/consentResponse.d.ts +8 -0
  100. package/dist/types/mcpAdmin.d.ts +58 -0
  101. package/dist/types/mcpAdmin.js +2 -0
  102. package/dist/types/mcpOAuth.d.ts +37 -2
  103. package/dist/types/mcpServiceToken.d.ts +2 -0
  104. package/e2e/smoke.ts +193 -0
  105. package/package.json +10 -5
  106. package/src/__snapshots__/openApi.test.ts.snap +288 -0
  107. package/src/__snapshots__/openApiBuilder.test.ts.snap +96 -0
  108. package/src/accountSecurity/accessActions.test.ts +723 -0
  109. package/src/accountSecurity/accessActions.ts +173 -0
  110. package/src/accountSecurity/accountSecurity.test.ts +947 -0
  111. package/src/accountSecurity/accountSecurityApp.ts +720 -0
  112. package/src/accountSecurity/accountSecurityService.ts +826 -0
  113. package/src/accountSecurity/credentialActions.test.ts +867 -0
  114. package/src/accountSecurity/credentialActions.ts +260 -0
  115. package/src/accountSecurity/membershipActions.ts +89 -0
  116. package/src/accountSecurity/orgSecurityRoutes.test.ts +841 -0
  117. package/src/accountSecurity/orgSecurityRoutes.ts +232 -0
  118. package/src/accountSecurity/securityEventHooks.ts +294 -0
  119. package/src/accountSecurity/securityEvents.ts +165 -0
  120. package/src/accountSecurity/securityNotifications.test.ts +1323 -0
  121. package/src/accountSecurity/securityNotifications.ts +516 -0
  122. package/src/adminModelRouter.test.ts +8 -6
  123. package/src/api.arrayOperations.test.ts +102 -22
  124. package/src/api.hooks.test.ts +12 -11
  125. package/src/api.query.test.ts +2 -2
  126. package/src/api.test.ts +8 -7
  127. package/src/api.ts +41 -10
  128. package/src/audit/auditApp.test.ts +1 -1
  129. package/src/audit/auditEventModel.ts +10 -7
  130. package/src/audit/cloudTasksEnqueue.test.ts +19 -14
  131. package/src/audit/processQueue.ts +4 -2
  132. package/src/audit/record.test.ts +15 -0
  133. package/src/audit/record.ts +10 -2
  134. package/src/auth.test.ts +21 -7
  135. package/src/authRecovery.test.ts +33 -10
  136. package/src/authRecovery.ts +34 -1
  137. package/src/authRecoveryBetterAuth.test.ts +169 -0
  138. package/src/authVerification.test.ts +7 -7
  139. package/src/betterAuth.ts +194 -8
  140. package/src/betterAuthApp.ts +32 -0
  141. package/src/betterAuthChallengeHeaders.test.ts +476 -0
  142. package/src/betterAuthChallengeHeaders.ts +227 -0
  143. package/src/betterAuthFeatures.test.ts +490 -0
  144. package/src/betterAuthFeatures.ts +283 -0
  145. package/src/betterAuthLinking.test.ts +846 -0
  146. package/src/betterAuthMethods.test.ts +138 -0
  147. package/src/betterAuthMethods.ts +98 -0
  148. package/src/betterAuthOAuthHandoff.test.ts +482 -69
  149. package/src/betterAuthOAuthHandoff.ts +293 -33
  150. package/src/betterAuthOAuthProxy.test.ts +421 -0
  151. package/src/betterAuthPasswordReset.test.ts +190 -0
  152. package/src/betterAuthSetPassword.test.ts +378 -0
  153. package/src/betterAuthSetPassword.ts +213 -0
  154. package/src/betterAuthSetup.test.ts +115 -57
  155. package/src/betterAuthSetup.ts +457 -38
  156. package/src/collectionRegistry.test.ts +4 -4
  157. package/src/consentApp.test.ts +869 -2
  158. package/src/consentApp.ts +438 -36
  159. package/src/consentStatus.test.ts +226 -0
  160. package/src/consentStatus.ts +171 -0
  161. package/src/errors.test.ts +81 -0
  162. package/src/errors.ts +50 -1
  163. package/src/expressServer.test.ts +29 -0
  164. package/src/expressServer.ts +3 -2
  165. package/src/frameworkModelNames.test.ts +8 -0
  166. package/src/frameworkModelNames.ts +4 -0
  167. package/src/githubAuth.test.ts +11 -11
  168. package/src/index.ts +38 -0
  169. package/src/isolated/migrateCliConnect.isolated.ts +3 -2
  170. package/src/mcp/actionTools.test.ts +11 -5
  171. package/src/mcp/adminTracking.test.ts +272 -0
  172. package/src/mcp/adminTracking.ts +104 -0
  173. package/src/mcp/auth.ts +18 -2
  174. package/src/mcp/oauth.test.ts +463 -2
  175. package/src/mcp/oauth.ts +184 -13
  176. package/src/mcp/oauthMetadata.ts +5 -2
  177. package/src/mcp/server.ts +67 -4
  178. package/src/mcp/serviceTokens.test.ts +2 -1
  179. package/src/mcp/toolGenerator.test.ts +9 -5
  180. package/src/migrations/cli.test.ts +15 -14
  181. package/src/migrations/cli.ts +1 -1
  182. package/src/migrations/generate.test.ts +2 -2
  183. package/src/migrations/load.test.ts +1 -1
  184. package/src/migrations/lock.test.ts +8 -3
  185. package/src/migrations/runner.test.ts +16 -5
  186. package/src/migrations/schemaCatalog.test.ts +4 -1
  187. package/src/models/consentResponse.ts +53 -0
  188. package/src/models/mcpOAuthClient.ts +100 -3
  189. package/src/models/mcpOAuthToken.test.ts +42 -0
  190. package/src/models/mcpOAuthToken.ts +62 -5
  191. package/src/models/mcpRequestLog.ts +81 -0
  192. package/src/models/mcpServiceToken.test.ts +23 -0
  193. package/src/models/mcpServiceToken.ts +10 -0
  194. package/src/models/mcpToolSetting.test.ts +69 -0
  195. package/src/models/mcpToolSetting.ts +138 -0
  196. package/src/models/versionConfig.ts +2 -0
  197. package/src/notifications/notificationsApp.test.ts +5 -8
  198. package/src/notifiers/slackWebApi.test.ts +30 -8
  199. package/src/openApi.test.ts +4 -4
  200. package/src/openApiValidator.test.ts +3 -3
  201. package/src/orgs/membershipGuards.ts +39 -0
  202. package/src/orgs/orgPermissions.test.ts +2 -2
  203. package/src/orgs/orgPlugin.test.ts +4 -3
  204. package/src/orgs/orgRbac.test.ts +1 -1
  205. package/src/orgs/orgSecurityDefects.test.ts +3 -1
  206. package/src/orgs/organizationSettings.test.ts +1 -1
  207. package/src/orgs/orgsApp.test.ts +104 -3
  208. package/src/orgs/orgsApp.ts +69 -28
  209. package/src/permissions.test.ts +2 -2
  210. package/src/rateLimit/policies.test.ts +53 -0
  211. package/src/rateLimit/policies.ts +8 -0
  212. package/src/rateLimit/redisStore.ioredis.test.ts +3 -2
  213. package/src/rbac/access.ts +4 -1
  214. package/src/rbac/assertAllowed.test.ts +1 -1
  215. package/src/rbac/auditModel.ts +10 -2
  216. package/src/rbac/realtimeAccess.test.ts +3 -2
  217. package/src/rbac/resolve.test.ts +65 -0
  218. package/src/rbac/resolve.ts +37 -17
  219. package/src/rbac/roleManager.test.ts +64 -0
  220. package/src/rbac/roleManager.ts +15 -6
  221. package/src/rbac/roleModel.test.ts +174 -1
  222. package/src/rbac/roleModel.ts +66 -3
  223. package/src/rbac/routes.test.ts +58 -0
  224. package/src/rbac/statements.test.ts +4 -1
  225. package/src/rbac/statements.ts +11 -1
  226. package/src/rbac/types.ts +6 -1
  227. package/src/rbac/userWriteGuards.test.ts +56 -5
  228. package/src/rbac/userWriteGuards.ts +5 -2
  229. package/src/realtime/realtime.test.ts +35 -31
  230. package/src/schemaMetadata.test.ts +39 -0
  231. package/src/schemaMetadata.ts +11 -1
  232. package/src/scrubAdminFields.test.ts +1 -1
  233. package/src/seedRunner.test.ts +56 -0
  234. package/src/seedRunner.ts +7 -2
  235. package/src/sync/adminWindowMutation.test.ts +4 -3
  236. package/src/sync/executors.test.ts +1 -1
  237. package/src/sync/scripts/compactTombstones.test.ts +4 -3
  238. package/src/sync/sync.test.ts +1 -1
  239. package/src/sync/syncPhaseC.test.ts +14 -11
  240. package/src/sync/syncRoutes.test.ts +8 -8
  241. package/src/sync/syncSeqPlugin.test.ts +1 -2
  242. package/src/sync/syncSocket.test.ts +5 -4
  243. package/src/terrenoApp.mcpServiceTokens.test.ts +2 -2
  244. package/src/terrenoApp.migrations.test.ts +8 -7
  245. package/src/terrenoApp.ts +34 -0
  246. package/src/tests/accountSecurityTestApp.ts +290 -0
  247. package/src/tests/betterAuthStubs.ts +189 -0
  248. package/src/tests/bunSetup.ts +1 -1
  249. package/src/tests/mockOidcProvider.ts +105 -0
  250. package/src/tests/models.ts +23 -0
  251. package/src/tests/softwareAuthenticator.ts +183 -0
  252. package/src/tests/testEnv.ts +7 -0
  253. package/src/tests.ts +1 -0
  254. package/src/types/consentResponse.ts +8 -0
  255. package/src/types/mcpAdmin.ts +80 -0
  256. package/src/types/mcpOAuth.ts +44 -3
  257. package/src/types/mcpServiceToken.ts +5 -0
  258. package/src/webhooks/verifiers/hmac.test.ts +1 -1
  259. package/tsconfig.typecheck.json +14 -0
@@ -4,7 +4,8 @@
4
4
  * can serve the same metadata and challenge.
5
5
  */
6
6
  import type { Response } from "express";
7
- export declare const SUPPORTED_GRANT_TYPES: string[];
7
+ /** Grants a public PKCE client may register. Dynamic registration rejects anything else. */
8
+ export declare const PUBLIC_CLIENT_GRANT_TYPES: string[];
8
9
  export declare const SUPPORTED_RESPONSE_TYPES: string[];
9
10
  export declare const LOOPBACK_HOSTS: Set<string>;
10
11
  export interface McpOAuthOptions {
@@ -1,13 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sendMcpOAuthChallenge = exports.buildAuthorizationServerMetadata = exports.buildProtectedResourceMetadata = exports.sendProtocolJson = exports.resolveMcpOAuthOption = exports.protectedResourceMetadataPath = exports.LOOPBACK_HOSTS = exports.SUPPORTED_RESPONSE_TYPES = exports.SUPPORTED_GRANT_TYPES = void 0;
3
+ exports.sendMcpOAuthChallenge = exports.buildAuthorizationServerMetadata = exports.buildProtectedResourceMetadata = exports.sendProtocolJson = exports.resolveMcpOAuthOption = exports.protectedResourceMetadataPath = exports.LOOPBACK_HOSTS = exports.SUPPORTED_RESPONSE_TYPES = exports.PUBLIC_CLIENT_GRANT_TYPES = void 0;
4
4
  const errors_1 = require("../errors");
5
5
  const DEFAULT_ACCESS_TOKEN_TTL_SECONDS = 60 * 60;
6
6
  const DEFAULT_REFRESH_TOKEN_TTL_SECONDS = 30 * 24 * 60 * 60;
7
7
  const DEFAULT_AUTHORIZATION_REQUEST_TTL_SECONDS = 10 * 60;
8
8
  const DEFAULT_AUTHORIZATION_CODE_TTL_SECONDS = 60;
9
9
  const DEFAULT_SCOPES = ["mcp"];
10
- exports.SUPPORTED_GRANT_TYPES = ["authorization_code", "refresh_token"];
10
+ /** Grants a public PKCE client may register. Dynamic registration rejects anything else. */
11
+ exports.PUBLIC_CLIENT_GRANT_TYPES = ["authorization_code", "refresh_token"];
12
+ const SUPPORTED_GRANT_TYPES = [...exports.PUBLIC_CLIENT_GRANT_TYPES, "client_credentials"];
13
+ const SUPPORTED_TOKEN_ENDPOINT_AUTH_METHODS = ["none", "client_secret_basic", "client_secret_post"];
11
14
  exports.SUPPORTED_RESPONSE_TYPES = ["code"];
12
15
  exports.LOOPBACK_HOSTS = new Set(["localhost", "127.0.0.1", "[::1]"]);
13
16
  const misconfigured = (detail) => new errors_1.APIError({
@@ -107,14 +110,14 @@ const buildAuthorizationServerMetadata = (oauth) => ({
107
110
  authorization_endpoint: `${oauth.issuer}/oauth/authorize`,
108
111
  authorization_response_iss_parameter_supported: true,
109
112
  code_challenge_methods_supported: ["S256"],
110
- grant_types_supported: exports.SUPPORTED_GRANT_TYPES,
113
+ grant_types_supported: SUPPORTED_GRANT_TYPES,
111
114
  issuer: oauth.issuer,
112
115
  response_types_supported: exports.SUPPORTED_RESPONSE_TYPES,
113
116
  revocation_endpoint: `${oauth.issuer}/oauth/revoke`,
114
117
  revocation_endpoint_auth_methods_supported: ["none"],
115
118
  scopes_supported: oauth.scopesSupported,
116
119
  token_endpoint: `${oauth.issuer}/oauth/token`,
117
- token_endpoint_auth_methods_supported: ["none"],
120
+ token_endpoint_auth_methods_supported: SUPPORTED_TOKEN_ENDPOINT_AUTH_METHODS,
118
121
  });
119
122
  exports.buildAuthorizationServerMetadata = buildAuthorizationServerMetadata;
120
123
  /**
@@ -1,6 +1,7 @@
1
1
  import type { Application } from "express";
2
2
  import type { UserModel } from "../auth";
3
3
  import type { BetterAuthInstance } from "../betterAuthSetup";
4
+ import { type ResolvedMcpRequestLogOptions } from "./adminTracking";
4
5
  import { type ResolvedMcpOAuthOptions } from "./oauthMetadata";
5
6
  export interface MCPServerOptions {
6
7
  userModel: UserModel;
@@ -11,5 +12,12 @@ export interface MCPServerOptions {
11
12
  * request without valid credentials with a 401 RFC 9728 challenge.
12
13
  */
13
14
  mcpOAuth?: ResolvedMcpOAuthOptions;
15
+ /** When set, each tool call writes a metadata-only `McpRequestLog` row. */
16
+ requestLog?: ResolvedMcpRequestLogOptions;
17
+ /**
18
+ * When true, tools are registered in `McpToolSetting` on mount and tools an admin turned off
19
+ * are left out of `tools/list` and `tools/call`.
20
+ */
21
+ toolSettings?: boolean;
14
22
  }
15
23
  export declare const mountMCPServer: (app: Application, options: MCPServerOptions) => void;
@@ -6,6 +6,7 @@ const node_1 = require("@modelcontextprotocol/node");
6
6
  const server_1 = require("@modelcontextprotocol/server");
7
7
  const logger_1 = require("../logger");
8
8
  const requestContext_1 = require("../requestContext");
9
+ const adminTracking_1 = require("./adminTracking");
9
10
  const auth_1 = require("./auth");
10
11
  const oauthMetadata_1 = require("./oauthMetadata");
11
12
  const toolGenerator_1 = require("./toolGenerator");
@@ -24,12 +25,26 @@ const mountMCPServer = (app, options) => {
24
25
  userModel: options.userModel,
25
26
  };
26
27
  logger_1.logger.info(`Mounting MCP server with ${tools.length} tools at /mcp`);
28
+ if (options.toolSettings) {
29
+ void (0, adminTracking_1.syncMcpToolSettings)(tools).catch((error) => {
30
+ logger_1.logger.warn(`[mcp] Could not register tools in McpToolSetting: ${String(error)}`);
31
+ });
32
+ }
33
+ const buildServer = async (auth) => {
34
+ const served = options.toolSettings ? await (0, adminTracking_1.filterEnabledMcpTools)(tools) : tools;
35
+ const onToolCall = options.requestLog
36
+ ? (record) => {
37
+ (0, adminTracking_1.recordMcpToolCall)({ ...record, auth }, options.requestLog);
38
+ }
39
+ : undefined;
40
+ return createMcpServerInstance(served, auth?.user, onToolCall);
41
+ };
27
42
  // The 2026-07-28 handler is stateless: it creates one server per request and also serves
28
43
  // 2025-era clients through the SDK's stateless legacy fallback.
29
44
  const handler = (0, server_1.createMcpHandler)(async ({ requestInfo }) => {
30
45
  const stored = mcpAuthStorage.getStore();
31
46
  if (stored) {
32
- return createMcpServerInstance(tools, stored.auth?.user);
47
+ return buildServer(stored.auth);
33
48
  }
34
49
  const headers = {};
35
50
  requestInfo?.headers.forEach((value, key) => {
@@ -37,7 +52,7 @@ const mountMCPServer = (app, options) => {
37
52
  });
38
53
  const auth = await (0, auth_1.extractAuthFromHeaders)(headers, authContext);
39
54
  recordMcpAuth(auth);
40
- return createMcpServerInstance(tools, auth?.user);
55
+ return buildServer(auth);
41
56
  }, {
42
57
  legacy: "stateless",
43
58
  onerror: (error) => logger_1.logger.catch(error),
@@ -79,7 +94,13 @@ const recordMcpAuth = (auth) => {
79
94
  userId: auth.user.id,
80
95
  });
81
96
  };
82
- const createMcpServerInstance = (tools, user) => {
97
+ const errorName = (error) => {
98
+ if (error instanceof Error) {
99
+ return error.name;
100
+ }
101
+ return typeof error;
102
+ };
103
+ const createMcpServerInstance = (tools, user, onToolCall) => {
83
104
  const server = new server_1.McpServer({
84
105
  name: "terreno-api-mcp",
85
106
  version: "1.0.0",
@@ -93,7 +114,30 @@ const createMcpServerInstance = (tools, user) => {
93
114
  server.registerTool(tool.name, {
94
115
  description: tool.description,
95
116
  inputSchema: tool.zodSchema,
96
- }, async (args) => tool.handler(args, user));
117
+ }, async (args) => {
118
+ if (!onToolCall) {
119
+ return tool.handler(args, user);
120
+ }
121
+ const startedAt = performance.now();
122
+ try {
123
+ const result = await tool.handler(args, user);
124
+ onToolCall({
125
+ durationMs: performance.now() - startedAt,
126
+ outcome: result.isError ? "tool_error" : "ok",
127
+ toolName: tool.name,
128
+ });
129
+ return result;
130
+ }
131
+ catch (error) {
132
+ onToolCall({
133
+ durationMs: performance.now() - startedAt,
134
+ errorName: errorName(error),
135
+ outcome: "exception",
136
+ toolName: tool.name,
137
+ });
138
+ throw error;
139
+ }
140
+ });
97
141
  }
98
142
  return server;
99
143
  };
@@ -45,6 +45,42 @@ const consentResponseSchema = new mongoose_1.default.Schema({
45
45
  required: true,
46
46
  type: String,
47
47
  },
48
+ provisional: {
49
+ default: false,
50
+ description: "Whether another user recorded this agreement on the user's behalf. The user still sees the form and signs it themselves",
51
+ type: Boolean,
52
+ },
53
+ provisionalNote: {
54
+ description: "Required note from the provisional signer explaining how consent was obtained",
55
+ maxlength: 2000,
56
+ required: [
57
+ function () {
58
+ return this.provisional === true;
59
+ },
60
+ "provisionalNote is required for a provisional signature",
61
+ ],
62
+ trim: true,
63
+ type: String,
64
+ },
65
+ provisionalSignedBy: {
66
+ description: "The user who recorded this provisional signature",
67
+ ref: "User",
68
+ required: [
69
+ function () {
70
+ return this.provisional === true;
71
+ },
72
+ "provisionalSignedBy is required for a provisional signature",
73
+ ],
74
+ type: mongoose_1.default.Schema.Types.ObjectId,
75
+ },
76
+ provisionalSignerIp: {
77
+ description: "IP address of the provisional signer, captured for audit purposes",
78
+ type: String,
79
+ },
80
+ provisionalSignerUserAgent: {
81
+ description: "User-agent string of the provisional signer's browser or app",
82
+ type: String,
83
+ },
48
84
  signature: {
49
85
  description: "Base64-encoded signature image or typed signature text, if captured",
50
86
  type: String,
@@ -64,6 +100,21 @@ const consentResponseSchema = new mongoose_1.default.Schema({
64
100
  required: true,
65
101
  type: mongoose_1.default.Schema.Types.ObjectId,
66
102
  },
103
+ voidedAt: {
104
+ description: "When a provisional signature was voided. Voided signatures no longer count as consent",
105
+ type: Date,
106
+ },
107
+ voidedBy: {
108
+ description: "The user who voided this provisional signature",
109
+ ref: "User",
110
+ type: mongoose_1.default.Schema.Types.ObjectId,
111
+ },
112
+ voidReason: {
113
+ description: "Why the provisional signature was voided",
114
+ maxlength: 2000,
115
+ trim: true,
116
+ type: String,
117
+ },
67
118
  }, { strict: "throw", toJSON: { virtuals: true }, toObject: { virtuals: true } });
68
119
  consentResponseSchema.index({ consentFormId: 1, userId: 1 });
69
120
  consentResponseSchema.plugin(plugins_1.createdUpdatedPlugin);
@@ -4,11 +4,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.McpOAuthClient = void 0;
7
+ const node_crypto_1 = require("node:crypto");
8
+ const luxon_1 = require("luxon");
7
9
  const mongoose_1 = __importDefault(require("mongoose"));
8
10
  const plugins_1 = require("../plugins");
11
+ const mcpOAuthToken_1 = require("./mcpOAuthToken");
9
12
  const mcpOAuthClientSchema = new mongoose_1.default.Schema({
10
13
  clientId: {
11
- description: "Public OAuth client identifier issued by dynamic client registration",
14
+ description: "Public OAuth client identifier",
12
15
  required: true,
13
16
  type: String,
14
17
  unique: true,
@@ -18,25 +21,98 @@ const mcpOAuthClientSchema = new mongoose_1.default.Schema({
18
21
  trim: true,
19
22
  type: String,
20
23
  },
24
+ clientSecretHash: {
25
+ description: "SHA-256 hash of the confidential client secret. Unset for public clients",
26
+ type: String,
27
+ },
21
28
  grantTypes: {
22
29
  description: "OAuth grant types the client may use",
23
30
  type: [String],
24
31
  },
25
32
  redirectUris: {
26
- description: "Exact redirect URIs the client registered",
33
+ description: "Registered redirect URIs. Loopback hosts (localhost, 127.0.0.1, [::1]) match any port; every other URI must match exactly",
27
34
  type: [String],
28
35
  },
29
36
  responseTypes: {
30
37
  description: "OAuth response types the client may request",
31
38
  type: [String],
32
39
  },
40
+ revokedAt: {
41
+ description: "When the client was revoked. A revoked client cannot take new grants",
42
+ type: Date,
43
+ },
33
44
  scope: {
34
45
  description: "Space-separated scopes the client registered for",
35
46
  type: String,
36
47
  },
48
+ tokenEndpointAuthMethod: {
49
+ description: "How the client authenticates at the token endpoint. none is a public client; client_secret_basic and client_secret_post are confidential",
50
+ enum: ["none", "client_secret_basic", "client_secret_post"],
51
+ type: String,
52
+ },
53
+ userId: {
54
+ description: "User a client_credentials token acts as",
55
+ ref: "User",
56
+ type: mongoose_1.default.Schema.Types.ObjectId,
57
+ },
37
58
  }, { strict: "throw", toJSON: { virtuals: true }, toObject: { virtuals: true } });
38
59
  mcpOAuthClientSchema.plugin(plugins_1.createdUpdatedPlugin);
39
60
  mcpOAuthClientSchema.plugin(plugins_1.findOneOrNone);
40
61
  mcpOAuthClientSchema.plugin(plugins_1.findExactlyOne);
62
+ const revokeTokensForClient = async (clientId) => {
63
+ if (!clientId) {
64
+ return;
65
+ }
66
+ await mcpOAuthToken_1.McpOAuthToken.revokeClient(clientId);
67
+ };
68
+ mcpOAuthClientSchema.pre("deleteOne", { document: true, query: false }, async function () {
69
+ await revokeTokensForClient(this.clientId);
70
+ });
71
+ mcpOAuthClientSchema.pre("deleteOne", { document: false, query: true }, async function () {
72
+ // deleteOne removes one document. Pin that document so its tokens are the ones revoked.
73
+ const [existing] = await this.model.find(this.getFilter()).limit(1).select({ _id: 1, clientId: 1 });
74
+ if (!existing) {
75
+ return;
76
+ }
77
+ this.setQuery({ _id: existing._id });
78
+ await revokeTokensForClient(existing.clientId);
79
+ });
80
+ mcpOAuthClientSchema.pre("findOneAndDelete", async function () {
81
+ const [existing] = await this.model.find(this.getFilter()).limit(1).select({ _id: 1, clientId: 1 });
82
+ if (!existing) {
83
+ return;
84
+ }
85
+ this.setQuery({ _id: existing._id });
86
+ await revokeTokensForClient(existing.clientId);
87
+ });
88
+ mcpOAuthClientSchema.pre("deleteMany", async function () {
89
+ const clients = await this.model.find(this.getFilter()).select({ clientId: 1 });
90
+ for (const client of clients) {
91
+ await revokeTokensForClient(client.clientId);
92
+ }
93
+ });
94
+ mcpOAuthClientSchema.statics = {
95
+ ...mcpOAuthClientSchema.statics,
96
+ async issueConfidential(options) {
97
+ const clientSecret = (0, mcpOAuthToken_1.generateMcpOAuthSecret)("mcpcs_");
98
+ const client = await this.create({
99
+ clientId: options.clientId ?? (0, node_crypto_1.randomUUID)(),
100
+ clientName: options.clientName,
101
+ clientSecretHash: (0, mcpOAuthToken_1.hashMcpOAuthSecret)(clientSecret),
102
+ grantTypes: ["client_credentials"],
103
+ redirectUris: [],
104
+ responseTypes: [],
105
+ scope: options.scope,
106
+ tokenEndpointAuthMethod: options.tokenEndpointAuthMethod,
107
+ userId: new mongoose_1.default.Types.ObjectId(String(options.userId)),
108
+ });
109
+ return { client, clientSecret };
110
+ },
111
+ async revoke(clientId) {
112
+ await this.updateOne({ clientId, revokedAt: { $exists: false } }, { $set: { revokedAt: luxon_1.DateTime.now().toJSDate() } });
113
+ await mcpOAuthToken_1.McpOAuthToken.revokeClient(clientId);
114
+ return this.findOneOrNone({ clientId });
115
+ },
116
+ };
41
117
  exports.McpOAuthClient = mongoose_1.default.models.TerrenoMcpOAuthClient ??
42
118
  mongoose_1.default.model("TerrenoMcpOAuthClient", mcpOAuthClientSchema, "mcpoauthclients");
@@ -54,6 +54,10 @@ const mcpOAuthTokenSchema = new mongoose_1.default.Schema({
54
54
  required: true,
55
55
  type: String,
56
56
  },
57
+ hasRefreshToken: {
58
+ description: "False when this document is an access-only client_credentials token. The refresh hash is then of a discarded secret and cannot be exchanged",
59
+ type: Boolean,
60
+ },
57
61
  refreshExpiresAt: {
58
62
  description: "When the refresh token stops being exchangeable; the document is removed then",
59
63
  required: true,
@@ -104,16 +108,25 @@ mcpOAuthTokenSchema.statics = {
104
108
  if (await isFamilyRevoked(familyId)) {
105
109
  throw new McpOAuthFamilyRevokedError(familyId);
106
110
  }
111
+ const includeRefreshToken = options.includeRefreshToken !== false;
107
112
  const accessToken = (0, exports.generateMcpOAuthSecret)(exports.MCP_OAUTH_ACCESS_TOKEN_PREFIX);
108
- const refreshToken = (0, exports.generateMcpOAuthSecret)(MCP_OAUTH_REFRESH_TOKEN_PREFIX);
113
+ // Access-only grants still store a unique hash so the refreshTokenHash index stays unique.
114
+ // The preimage is discarded, and hasRefreshToken false makes it unusable for refresh.
115
+ const refreshSecret = includeRefreshToken
116
+ ? (0, exports.generateMcpOAuthSecret)(MCP_OAUTH_REFRESH_TOKEN_PREFIX)
117
+ : (0, exports.generateMcpOAuthSecret)("discarded_");
109
118
  const now = luxon_1.DateTime.now();
119
+ const refreshTtlSeconds = includeRefreshToken
120
+ ? options.refreshTokenTtlSeconds
121
+ : options.accessTokenTtlSeconds;
110
122
  const mcpOAuthToken = await this.create({
111
123
  accessExpiresAt: now.plus({ seconds: options.accessTokenTtlSeconds }).toJSDate(),
112
124
  accessTokenHash: (0, exports.hashMcpOAuthSecret)(accessToken),
113
125
  clientId: options.clientId,
114
126
  familyId,
115
- refreshExpiresAt: now.plus({ seconds: options.refreshTokenTtlSeconds }).toJSDate(),
116
- refreshTokenHash: (0, exports.hashMcpOAuthSecret)(refreshToken),
127
+ hasRefreshToken: includeRefreshToken,
128
+ refreshExpiresAt: now.plus({ seconds: refreshTtlSeconds }).toJSDate(),
129
+ refreshTokenHash: (0, exports.hashMcpOAuthSecret)(refreshSecret),
117
130
  resource: options.resource,
118
131
  scope: options.scope,
119
132
  tokenEpoch: options.tokenEpoch ?? 0,
@@ -125,7 +138,29 @@ mcpOAuthTokenSchema.statics = {
125
138
  await this.updateOne({ _id: mcpOAuthToken._id, revokedAt: { $exists: false } }, { $set: { revokedAt: luxon_1.DateTime.now().toJSDate() } });
126
139
  throw new McpOAuthFamilyRevokedError(familyId);
127
140
  }
128
- return { accessToken, mcpOAuthToken, refreshToken };
141
+ return {
142
+ accessToken,
143
+ mcpOAuthToken,
144
+ refreshToken: includeRefreshToken ? refreshSecret : undefined,
145
+ };
146
+ },
147
+ async revokeAllForUser(userId) {
148
+ const tokens = await this.find({
149
+ revokedAt: { $exists: false },
150
+ userId: new mongoose_1.default.Types.ObjectId(String(userId)),
151
+ }).select({ familyId: 1 });
152
+ const familyIds = new Set(tokens.map((token) => token.familyId));
153
+ for (const familyId of familyIds) {
154
+ await this.revokeFamily(familyId);
155
+ }
156
+ return familyIds.size;
157
+ },
158
+ async revokeClient(clientId) {
159
+ const tokens = await this.find({ clientId, revokedAt: { $exists: false } }).select({ familyId: 1 });
160
+ const familyIds = new Set(tokens.map((token) => token.familyId));
161
+ for (const familyId of familyIds) {
162
+ await this.revokeFamily(familyId);
163
+ }
129
164
  },
130
165
  async revokeFamily(familyId) {
131
166
  const now = luxon_1.DateTime.now();
@@ -155,5 +190,21 @@ mcpOAuthTokenSchema.statics = {
155
190
  });
156
191
  },
157
192
  };
193
+ // Deleting a token row (for example from the admin panel) revokes its whole rotation chain and
194
+ // keeps the rows, so the connection ends and its history stays visible.
195
+ mcpOAuthTokenSchema.methods = {
196
+ ...mcpOAuthTokenSchema.methods,
197
+ async deleteOne() {
198
+ await this.constructor.revokeFamily(this.familyId);
199
+ return this;
200
+ },
201
+ };
202
+ mcpOAuthTokenSchema.pre("deleteOne", { document: false, query: true }, async function () {
203
+ const [existing] = await this.model.find(this.getFilter()).limit(1).select({ familyId: 1 });
204
+ if (existing) {
205
+ await this.model.revokeFamily(existing.familyId);
206
+ }
207
+ this.setQuery({ _id: { $exists: false } });
208
+ });
158
209
  exports.McpOAuthToken = mongoose_1.default.models.TerrenoMcpOAuthToken ??
159
210
  mongoose_1.default.model("TerrenoMcpOAuthToken", mcpOAuthTokenSchema, "mcpoauthtokens");
@@ -0,0 +1,2 @@
1
+ import type { McpRequestLogModel } from "../types/mcpAdmin";
2
+ export declare const McpRequestLog: McpRequestLogModel;
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.McpRequestLog = void 0;
7
+ const mongoose_1 = __importDefault(require("mongoose"));
8
+ const plugins_1 = require("../plugins");
9
+ /**
10
+ * One row per MCP tool call when `mcpRequestLog` is on. Metadata only: tool arguments, results,
11
+ * and error messages are never stored. Rows expire at `expiresAt`.
12
+ */
13
+ const mcpRequestLogSchema = new mongoose_1.default.Schema({
14
+ credential: {
15
+ description: "Credential type that authenticated the call",
16
+ enum: ["jwt", "better-auth-session", "mcp-service-token", "oauth"],
17
+ type: String,
18
+ },
19
+ durationMs: {
20
+ description: "Time the tool handler took, in milliseconds",
21
+ required: true,
22
+ type: Number,
23
+ },
24
+ errorName: {
25
+ description: "Error class name when the tool threw; never the error message",
26
+ type: String,
27
+ },
28
+ expiresAt: {
29
+ description: "When this log row is removed",
30
+ required: true,
31
+ type: Date,
32
+ },
33
+ oauthClientId: {
34
+ description: "OAuth client id when the call used an MCP OAuth access token",
35
+ index: true,
36
+ type: String,
37
+ },
38
+ oauthFamilyId: {
39
+ description: "OAuth token family (one approved connection) when the call used OAuth",
40
+ type: String,
41
+ },
42
+ outcome: {
43
+ description: "ok, tool_error (the tool returned isError), or exception (the tool threw)",
44
+ enum: ["ok", "tool_error", "exception"],
45
+ required: true,
46
+ type: String,
47
+ },
48
+ serviceTokenId: {
49
+ description: "Service token used for the call, when the credential was a service token",
50
+ index: true,
51
+ ref: "TerrenoMcpServiceToken",
52
+ type: mongoose_1.default.Schema.Types.ObjectId,
53
+ },
54
+ toolName: {
55
+ description: "Name of the MCP tool that was called",
56
+ index: true,
57
+ required: true,
58
+ type: String,
59
+ },
60
+ userId: {
61
+ description: "User the call acted as",
62
+ index: true,
63
+ ref: "User",
64
+ type: mongoose_1.default.Schema.Types.ObjectId,
65
+ },
66
+ }, { strict: "throw", toJSON: { virtuals: true }, toObject: { virtuals: true } });
67
+ mcpRequestLogSchema.index({ expiresAt: 1 }, { expireAfterSeconds: 0 });
68
+ mcpRequestLogSchema.index({ created: -1 });
69
+ mcpRequestLogSchema.plugin(plugins_1.createdUpdatedPlugin);
70
+ mcpRequestLogSchema.plugin(plugins_1.findOneOrNone);
71
+ mcpRequestLogSchema.plugin(plugins_1.findExactlyOne);
72
+ exports.McpRequestLog = mongoose_1.default.models.TerrenoMcpRequestLog ??
73
+ mongoose_1.default.model("TerrenoMcpRequestLog", mcpRequestLogSchema, "mcprequestlogs");
@@ -103,6 +103,10 @@ mcpServiceTokenSchema.statics = {
103
103
  });
104
104
  return { mcpServiceToken, token };
105
105
  },
106
+ async revokeAllForUser(userId) {
107
+ const result = await this.updateMany({ revokedAt: { $exists: false }, userId: new mongoose_1.default.Types.ObjectId(String(userId)) }, { $set: { revokedAt: luxon_1.DateTime.now().toJSDate() } });
108
+ return result.modifiedCount;
109
+ },
106
110
  async revokeForUser(user, tokenId) {
107
111
  return this.findOneAndUpdate({
108
112
  _id: tokenId,
@@ -0,0 +1,2 @@
1
+ import type { McpToolSettingModel } from "../types/mcpAdmin";
2
+ export declare const McpToolSetting: McpToolSettingModel;
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.McpToolSetting = void 0;
7
+ const luxon_1 = require("luxon");
8
+ const mongoose_1 = __importDefault(require("mongoose"));
9
+ const logger_1 = require("../logger");
10
+ const plugins_1 = require("../plugins");
11
+ /**
12
+ * Registry of MCP tools with an admin on/off switch. Rows are written when the server mounts
13
+ * with `mcpToolSettings` on. A tool with no row, or with `enabled: true`, is served.
14
+ */
15
+ const mcpToolSettingSchema = new mongoose_1.default.Schema({
16
+ description: {
17
+ description: "Tool description as sent to MCP clients",
18
+ type: String,
19
+ },
20
+ enabled: {
21
+ default: true,
22
+ description: "When false, the tool is hidden from tools/list and tools/call rejects it",
23
+ type: Boolean,
24
+ },
25
+ lastRegisteredAt: {
26
+ description: "Last server start that registered this tool",
27
+ type: Date,
28
+ },
29
+ name: {
30
+ description: "MCP tool name",
31
+ required: true,
32
+ type: String,
33
+ unique: true,
34
+ },
35
+ registered: {
36
+ default: true,
37
+ description: "False when the running server no longer registers this tool",
38
+ type: Boolean,
39
+ },
40
+ source: {
41
+ description: "model (generated from a modelRouter) or custom (registerMCPTool)",
42
+ enum: ["model", "custom"],
43
+ required: true,
44
+ type: String,
45
+ },
46
+ }, { strict: "throw", toJSON: { virtuals: true }, toObject: { virtuals: true } });
47
+ /** How long one process reuses the disabled-tool set before reading it again. */
48
+ const DISABLED_NAMES_TTL_MS = 5000;
49
+ // Per-process cache so /mcp does not query Mongo on every request. Writes through this model
50
+ // clear it at once; other processes pick up a change within DISABLED_NAMES_TTL_MS.
51
+ const disabledNamesCache = { expiresAt: 0 };
52
+ const clearDisabledNamesCache = () => {
53
+ disabledNamesCache.expiresAt = 0;
54
+ disabledNamesCache.names = undefined;
55
+ };
56
+ for (const hook of [
57
+ "save",
58
+ "updateOne",
59
+ "updateMany",
60
+ "findOneAndUpdate",
61
+ "deleteOne",
62
+ "deleteMany",
63
+ "findOneAndDelete",
64
+ ]) {
65
+ mcpToolSettingSchema.post(hook, clearDisabledNamesCache);
66
+ }
67
+ mcpToolSettingSchema.post("bulkWrite", clearDisabledNamesCache);
68
+ mcpToolSettingSchema.plugin(plugins_1.createdUpdatedPlugin);
69
+ mcpToolSettingSchema.plugin(plugins_1.findOneOrNone);
70
+ mcpToolSettingSchema.plugin(plugins_1.findExactlyOne);
71
+ mcpToolSettingSchema.statics = {
72
+ ...mcpToolSettingSchema.statics,
73
+ async disabledNames() {
74
+ const now = luxon_1.DateTime.now().toMillis();
75
+ if (disabledNamesCache.names && now < disabledNamesCache.expiresAt) {
76
+ return disabledNamesCache.names;
77
+ }
78
+ try {
79
+ const rows = await this.find({ enabled: false }).select({ name: 1 }).lean();
80
+ const names = new Set(rows.map((row) => row.name));
81
+ disabledNamesCache.names = names;
82
+ disabledNamesCache.expiresAt = now + DISABLED_NAMES_TTL_MS;
83
+ return names;
84
+ }
85
+ catch (error) {
86
+ // Keep enforcing the last known switches rather than re-enabling every tool. With no
87
+ // known state, fail the request (closed) instead of serving tools an admin turned off.
88
+ if (disabledNamesCache.names) {
89
+ logger_1.logger.warn(`[mcp] Tool settings read failed; using last known: ${String(error)}`);
90
+ return disabledNamesCache.names;
91
+ }
92
+ throw error;
93
+ }
94
+ },
95
+ async syncRegistered(tools) {
96
+ const now = luxon_1.DateTime.now().toJSDate();
97
+ if (tools.length > 0) {
98
+ // `enabled` is only set on insert so a restart never undoes an admin's switch.
99
+ await this.bulkWrite(tools.map((tool) => ({
100
+ updateOne: {
101
+ filter: { name: tool.name },
102
+ update: {
103
+ $set: {
104
+ description: tool.description,
105
+ lastRegisteredAt: now,
106
+ registered: true,
107
+ source: tool.source,
108
+ },
109
+ $setOnInsert: { enabled: true },
110
+ },
111
+ upsert: true,
112
+ },
113
+ })));
114
+ }
115
+ await this.updateMany({ name: { $nin: tools.map((tool) => tool.name) }, registered: { $ne: false } }, { $set: { registered: false } });
116
+ },
117
+ };
118
+ exports.McpToolSetting = mongoose_1.default.models.TerrenoMcpToolSetting ??
119
+ mongoose_1.default.model("TerrenoMcpToolSetting", mcpToolSettingSchema, "mcptoolsettings");
@@ -10,6 +10,8 @@ export interface VersionConfigDocument extends mongoose.Document {
10
10
  updateUrl?: string;
11
11
  /** How often clients should poll for version updates, in minutes. Defaults to 1440 (24 hours). */
12
12
  pollingIntervalMinutes: number;
13
+ /** Singleton sentinel backing the unique index; not selected by default. */
14
+ _singleton?: "config";
13
15
  created?: Date;
14
16
  updated?: Date;
15
17
  }
@@ -0,0 +1,7 @@
1
+ import type { MembershipDocument } from "../types/membership";
2
+ export declare const LAST_ORG_ADMIN_TITLE = "Cannot remove the last org-admin";
3
+ /**
4
+ * Refuses (400) a membership change that would leave the organization with no active org-admin,
5
+ * so an org can never lose every administrator through a role change, suspension, or removal.
6
+ */
7
+ export declare const assertNotLastOrgAdmin: (membership: MembershipDocument, nextRoleName?: string, nextStatus?: string) => Promise<void>;