@terreno/api 57.19.2 → 57.20.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 (169) hide show
  1. package/CHANGELOG.md +393 -0
  2. package/dist/accountSecurity/accessActions.d.ts +38 -0
  3. package/dist/accountSecurity/accessActions.js +157 -0
  4. package/dist/accountSecurity/accountSecurityApp.d.ts +219 -0
  5. package/dist/accountSecurity/accountSecurityApp.js +438 -0
  6. package/dist/accountSecurity/accountSecurityService.d.ts +200 -0
  7. package/dist/accountSecurity/accountSecurityService.js +481 -0
  8. package/dist/accountSecurity/credentialActions.d.ts +16 -0
  9. package/dist/accountSecurity/credentialActions.js +189 -0
  10. package/dist/accountSecurity/membershipActions.d.ts +15 -0
  11. package/dist/accountSecurity/membershipActions.js +81 -0
  12. package/dist/accountSecurity/orgSecurityRoutes.d.ts +50 -0
  13. package/dist/accountSecurity/orgSecurityRoutes.js +149 -0
  14. package/dist/accountSecurity/securityEventHooks.d.ts +44 -0
  15. package/dist/accountSecurity/securityEventHooks.js +223 -0
  16. package/dist/accountSecurity/securityEvents.d.ts +162 -0
  17. package/dist/accountSecurity/securityEvents.js +114 -0
  18. package/dist/accountSecurity/securityNotifications.d.ts +125 -0
  19. package/dist/accountSecurity/securityNotifications.js +333 -0
  20. package/dist/api.js +38 -6
  21. package/dist/audit/auditEventModel.d.ts +5 -3
  22. package/dist/audit/auditEventModel.js +8 -6
  23. package/dist/audit/processQueue.js +4 -2
  24. package/dist/audit/record.d.ts +2 -2
  25. package/dist/audit/record.js +3 -0
  26. package/dist/authRecovery.js +29 -1
  27. package/dist/betterAuth.d.ts +179 -10
  28. package/dist/betterAuthApp.d.ts +15 -0
  29. package/dist/betterAuthApp.js +23 -0
  30. package/dist/betterAuthChallengeHeaders.d.ts +37 -0
  31. package/dist/betterAuthChallengeHeaders.js +180 -0
  32. package/dist/betterAuthFeatures.d.ts +54 -0
  33. package/dist/betterAuthFeatures.js +239 -0
  34. package/dist/betterAuthMethods.d.ts +73 -0
  35. package/dist/betterAuthMethods.js +55 -0
  36. package/dist/betterAuthOAuthHandoff.d.ts +10 -2
  37. package/dist/betterAuthOAuthHandoff.js +222 -24
  38. package/dist/betterAuthSetPassword.d.ts +33 -0
  39. package/dist/betterAuthSetPassword.js +166 -0
  40. package/dist/betterAuthSetup.d.ts +57 -8
  41. package/dist/betterAuthSetup.js +327 -36
  42. package/dist/consentApp.d.ts +9 -4
  43. package/dist/consentApp.js +344 -28
  44. package/dist/consentStatus.d.ts +60 -0
  45. package/dist/consentStatus.js +111 -0
  46. package/dist/errors.d.ts +6 -0
  47. package/dist/errors.js +41 -2
  48. package/dist/expressServer.js +3 -2
  49. package/dist/index.d.ts +14 -2
  50. package/dist/index.js +23 -3
  51. package/dist/mcp/oauth.js +151 -11
  52. package/dist/mcp/oauthMetadata.d.ts +2 -1
  53. package/dist/mcp/oauthMetadata.js +7 -4
  54. package/dist/models/consentResponse.js +51 -0
  55. package/dist/models/mcpOAuthClient.js +78 -2
  56. package/dist/models/mcpOAuthToken.js +28 -4
  57. package/dist/orgs/membershipGuards.d.ts +7 -0
  58. package/dist/orgs/membershipGuards.js +32 -0
  59. package/dist/orgs/orgsApp.d.ts +19 -1
  60. package/dist/orgs/orgsApp.js +55 -24
  61. package/dist/rateLimit/policies.js +8 -0
  62. package/dist/rbac/access.js +2 -1
  63. package/dist/rbac/resolve.d.ts +9 -1
  64. package/dist/rbac/resolve.js +21 -16
  65. package/dist/rbac/roleManager.d.ts +6 -0
  66. package/dist/rbac/roleManager.js +8 -7
  67. package/dist/rbac/roleModel.d.ts +1 -0
  68. package/dist/rbac/roleModel.js +45 -3
  69. package/dist/rbac/statements.d.ts +2 -2
  70. package/dist/rbac/statements.js +10 -1
  71. package/dist/rbac/types.d.ts +6 -0
  72. package/dist/rbac/userWriteGuards.js +2 -1
  73. package/dist/schemaMetadata.js +8 -1
  74. package/dist/seedRunner.js +7 -2
  75. package/dist/terrenoApp.d.ts +4 -0
  76. package/dist/terrenoApp.js +15 -0
  77. package/dist/tests/models.d.ts +5 -0
  78. package/dist/tests/models.js +8 -0
  79. package/dist/types/consentResponse.d.ts +8 -0
  80. package/dist/types/mcpOAuth.d.ts +35 -2
  81. package/package.json +6 -3
  82. package/src/__snapshots__/openApi.test.ts.snap +288 -0
  83. package/src/__snapshots__/openApiBuilder.test.ts.snap +96 -0
  84. package/src/accountSecurity/accessActions.test.ts +723 -0
  85. package/src/accountSecurity/accessActions.ts +173 -0
  86. package/src/accountSecurity/accountSecurity.test.ts +947 -0
  87. package/src/accountSecurity/accountSecurityApp.ts +720 -0
  88. package/src/accountSecurity/accountSecurityService.ts +826 -0
  89. package/src/accountSecurity/credentialActions.test.ts +867 -0
  90. package/src/accountSecurity/credentialActions.ts +260 -0
  91. package/src/accountSecurity/membershipActions.ts +89 -0
  92. package/src/accountSecurity/orgSecurityRoutes.test.ts +841 -0
  93. package/src/accountSecurity/orgSecurityRoutes.ts +232 -0
  94. package/src/accountSecurity/securityEventHooks.ts +294 -0
  95. package/src/accountSecurity/securityEvents.ts +165 -0
  96. package/src/accountSecurity/securityNotifications.test.ts +1323 -0
  97. package/src/accountSecurity/securityNotifications.ts +516 -0
  98. package/src/api.arrayOperations.test.ts +71 -0
  99. package/src/api.ts +38 -7
  100. package/src/audit/auditEventModel.ts +10 -7
  101. package/src/audit/processQueue.ts +4 -2
  102. package/src/audit/record.test.ts +15 -0
  103. package/src/audit/record.ts +10 -2
  104. package/src/authRecovery.test.ts +23 -0
  105. package/src/authRecovery.ts +34 -1
  106. package/src/authRecoveryBetterAuth.test.ts +169 -0
  107. package/src/betterAuth.ts +194 -8
  108. package/src/betterAuthApp.ts +32 -0
  109. package/src/betterAuthChallengeHeaders.test.ts +476 -0
  110. package/src/betterAuthChallengeHeaders.ts +227 -0
  111. package/src/betterAuthFeatures.test.ts +489 -0
  112. package/src/betterAuthFeatures.ts +283 -0
  113. package/src/betterAuthLinking.test.ts +844 -0
  114. package/src/betterAuthMethods.test.ts +138 -0
  115. package/src/betterAuthMethods.ts +98 -0
  116. package/src/betterAuthOAuthHandoff.test.ts +482 -69
  117. package/src/betterAuthOAuthHandoff.ts +293 -33
  118. package/src/betterAuthOAuthProxy.test.ts +421 -0
  119. package/src/betterAuthPasswordReset.test.ts +190 -0
  120. package/src/betterAuthSetPassword.test.ts +378 -0
  121. package/src/betterAuthSetPassword.ts +213 -0
  122. package/src/betterAuthSetup.test.ts +39 -7
  123. package/src/betterAuthSetup.ts +457 -38
  124. package/src/consentApp.test.ts +869 -2
  125. package/src/consentApp.ts +438 -36
  126. package/src/consentStatus.test.ts +226 -0
  127. package/src/consentStatus.ts +171 -0
  128. package/src/errors.test.ts +81 -0
  129. package/src/errors.ts +50 -1
  130. package/src/expressServer.test.ts +29 -0
  131. package/src/expressServer.ts +3 -2
  132. package/src/index.ts +30 -0
  133. package/src/mcp/oauth.test.ts +463 -2
  134. package/src/mcp/oauth.ts +184 -13
  135. package/src/mcp/oauthMetadata.ts +5 -2
  136. package/src/models/consentResponse.ts +53 -0
  137. package/src/models/mcpOAuthClient.ts +100 -3
  138. package/src/models/mcpOAuthToken.ts +30 -5
  139. package/src/orgs/membershipGuards.ts +39 -0
  140. package/src/orgs/orgRbac.test.ts +1 -1
  141. package/src/orgs/orgsApp.test.ts +101 -2
  142. package/src/orgs/orgsApp.ts +69 -28
  143. package/src/rateLimit/policies.test.ts +53 -0
  144. package/src/rateLimit/policies.ts +8 -0
  145. package/src/rbac/access.ts +4 -1
  146. package/src/rbac/resolve.test.ts +65 -0
  147. package/src/rbac/resolve.ts +37 -17
  148. package/src/rbac/roleManager.test.ts +64 -0
  149. package/src/rbac/roleManager.ts +15 -6
  150. package/src/rbac/roleModel.test.ts +174 -1
  151. package/src/rbac/roleModel.ts +66 -3
  152. package/src/rbac/routes.test.ts +58 -0
  153. package/src/rbac/statements.test.ts +4 -1
  154. package/src/rbac/statements.ts +11 -1
  155. package/src/rbac/types.ts +6 -1
  156. package/src/rbac/userWriteGuards.test.ts +48 -0
  157. package/src/rbac/userWriteGuards.ts +5 -2
  158. package/src/schemaMetadata.test.ts +39 -0
  159. package/src/schemaMetadata.ts +11 -1
  160. package/src/seedRunner.test.ts +56 -0
  161. package/src/seedRunner.ts +7 -2
  162. package/src/terrenoApp.ts +20 -0
  163. package/src/tests/accountSecurityTestApp.ts +290 -0
  164. package/src/tests/betterAuthStubs.ts +188 -0
  165. package/src/tests/mockOidcProvider.ts +105 -0
  166. package/src/tests/models.ts +13 -0
  167. package/src/tests/softwareAuthenticator.ts +183 -0
  168. package/src/types/consentResponse.ts +8 -0
  169. package/src/types/mcpOAuth.ts +39 -3
@@ -9,6 +9,8 @@ const plugins_1 = require("../plugins");
9
9
  const statements_1 = require("./statements");
10
10
  var statements_2 = require("./statements");
11
11
  Object.defineProperty(exports, "READ_ONLY_ROLE_PERMISSIONS", { enumerable: true, get: function () { return statements_2.READ_ONLY_ROLE_PERMISSIONS; } });
12
+ /** Resources whose default admin grants are added to existing unsealed admin roles on seed. */
13
+ const ADMIN_MERGED_RESOURCES = [...statements_1.OBSERVABILITY_RBAC_RESOURCES, "consentResponse"];
12
14
  const observabilityAdminPermissionSpec = () => ({
13
15
  aiDataset: [...statements_1.terrenoStatements.aiDataset],
14
16
  aiEvaluator: [...statements_1.terrenoStatements.aiEvaluator],
@@ -28,6 +30,28 @@ const observabilityReadOnlyPermissionSpec = (statements) => {
28
30
  }
29
31
  return defaults;
30
32
  };
33
+ /**
34
+ * Operator grants added after the role first shipped. Each is merged into an existing operator
35
+ * row once and then recorded in `appliedGrants`, so an admin who later revokes it keeps it
36
+ * revoked across restarts.
37
+ */
38
+ const OPERATOR_ADDED_GRANTS = [
39
+ { id: "user.manageSecurity", permissions: { user: ["manageSecurity"] } },
40
+ // An app that opts User into per-model admin access (`adminUser`) gates the admin User list
41
+ // and record on it instead of `user`. Operators find users there to reach their Security
42
+ // screen, so they need the same read they already hold on `user`.
43
+ { id: "adminUser.read", permissions: { adminUser: ["read"] } },
44
+ ];
45
+ /** Whether the app declares every resource and action a grant adds. */
46
+ const isGrantDeclared = (grant, statements) => Object.entries(grant.permissions).every(([resource, actions]) => actions.every((action) => statements[resource]?.includes(action)));
47
+ /**
48
+ * Grants added to a seeded role after it shipped. A grant on a resource the app does not declare
49
+ * is left out (and not recorded as applied), so it is merged once the app declares it.
50
+ */
51
+ const addedGrantsFor = (role, statements) => role === exports.organizationOperatorRole
52
+ ? OPERATOR_ADDED_GRANTS.filter((grant) => isGrantDeclared(grant, statements))
53
+ : [];
54
+ const mergeGrants = (permissions, grants) => grants.reduce((merged, grant) => (0, statements_1.mergeMissingResourcePermissions)(merged, grant.permissions, Object.keys(grant.permissions)), permissions);
31
55
  /**
32
56
  * Insert missing default roles. Existing unsealed roles are left unchanged so admin
33
57
  * customizations survive process restarts. Sealed roles are refreshed from code.
@@ -38,13 +62,22 @@ const upsertSeededRole = async (model, role, statements) => {
38
62
  if (existing) {
39
63
  if (!existing.isSealed) {
40
64
  if (role.name === "admin") {
41
- existing.permissions = (0, statements_1.mergeMissingResourcePermissions)(existing.permissions, permissions, statements_1.OBSERVABILITY_RBAC_RESOURCES);
65
+ existing.permissions = (0, statements_1.mergeMissingResourcePermissions)(existing.permissions, permissions, ADMIN_MERGED_RESOURCES);
42
66
  await existing.save();
43
67
  }
44
68
  else if (role.name === "auditor") {
45
69
  existing.permissions = (0, statements_1.mergeMissingResourcePermissions)(existing.permissions, observabilityReadOnlyPermissionSpec(statements), statements_1.OBSERVABILITY_RBAC_RESOURCES);
46
70
  await existing.save();
47
71
  }
72
+ else {
73
+ const applied = new Set(existing.appliedGrants ?? []);
74
+ const pending = addedGrantsFor(role, statements).filter((grant) => !applied.has(grant.id));
75
+ if (pending.length > 0) {
76
+ existing.permissions = mergeGrants(existing.permissions, pending);
77
+ existing.appliedGrants = [...applied, ...pending.map((grant) => grant.id)];
78
+ await existing.save();
79
+ }
80
+ }
48
81
  return;
49
82
  }
50
83
  existing.description = role.description;
@@ -56,14 +89,17 @@ const upsertSeededRole = async (model, role, statements) => {
56
89
  await existing.save();
57
90
  return;
58
91
  }
92
+ // A new row starts with every added grant, so none is merged in later.
93
+ const addedGrants = addedGrantsFor(role, statements);
59
94
  await model.create({
95
+ appliedGrants: addedGrants.map((grant) => grant.id),
60
96
  description: role.description,
61
97
  displayName: role.displayName,
62
98
  excludesRoles: role.excludesRoles ?? [],
63
99
  isLocked: role.isLocked ?? false,
64
100
  isSealed: role.isSealed ?? false,
65
101
  name: role.name,
66
- permissions,
102
+ permissions: mergeGrants(permissions, addedGrants),
67
103
  });
68
104
  };
69
105
  const expandRolePermissions = (spec, statements, readActions = statements_1.READ_ACTIONS) => (0, statements_1.expandRolePermissions)(spec, statements, readActions);
@@ -76,7 +112,7 @@ exports.organizationOperatorRole = {
76
112
  permissions: {
77
113
  admin: ["access"],
78
114
  organization: ["create", "list", "read", "update", "delete", "manageMembers", "disable"],
79
- user: ["list", "read", "update"],
115
+ user: ["list", "read", "update", "manageSecurity"],
80
116
  },
81
117
  };
82
118
  exports.terrenoDefaultRoles = [
@@ -98,6 +134,7 @@ exports.terrenoDefaultRoles = [
98
134
  adminAnnouncementClickEvent: ["read"],
99
135
  adminAnnouncementImpression: ["read"],
100
136
  configuration: ["read", "update"],
137
+ consentResponse: ["signOnBehalf"],
101
138
  user: ["create", "list", "read", "update", "updateIdentity"],
102
139
  ...observabilityAdminPermissionSpec(),
103
140
  },
@@ -116,6 +153,11 @@ exports.terrenoDefaultRoles = [
116
153
  },
117
154
  ];
118
155
  const rbacRoleSchema = new mongoose_1.default.Schema({
156
+ appliedGrants: {
157
+ default: [],
158
+ description: "Ids of grants added to a seeded role after it shipped that were already merged in, so a revoked grant is not re-added",
159
+ type: [String],
160
+ },
119
161
  description: {
120
162
  description: "Human-readable description of the role",
121
163
  type: String,
@@ -32,11 +32,11 @@ export declare const terrenoStatements: {
32
32
  readonly announcementImpression: readonly ["list", "read"];
33
33
  readonly configuration: readonly ["read", "update"];
34
34
  readonly consentForm: readonly ["create", "list", "read", "update", "delete"];
35
- readonly consentResponse: readonly ["list", "read"];
35
+ readonly consentResponse: readonly ["list", "read", "signOnBehalf"];
36
36
  readonly featureFlag: readonly ["create", "list", "read", "update", "delete"];
37
37
  readonly organization: readonly ["create", "list", "read", "update", "delete", "manageMembers", "disable"];
38
38
  readonly rbac: readonly ["read", "manageRoles", "assignRoles"];
39
- readonly user: readonly ["create", "list", "read", "update", "delete", "impersonate", "setPassword", "updateIdentity"];
39
+ readonly user: readonly ["create", "list", "read", "update", "delete", "impersonate", "setPassword", "updateIdentity", "manageSecurity", "issueSignInLink"];
40
40
  };
41
41
  export type Statements = Record<string, readonly string[]>;
42
42
  export type PermissionSet = {
@@ -57,7 +57,7 @@ exports.terrenoStatements = {
57
57
  announcementImpression: ["list", "read"],
58
58
  configuration: ["read", "update"],
59
59
  consentForm: MODEL_CRUD,
60
- consentResponse: ["list", "read"],
60
+ consentResponse: ["list", "read", "signOnBehalf"],
61
61
  featureFlag: MODEL_CRUD,
62
62
  organization: exports.ORGANIZATION_ACTIONS,
63
63
  rbac: ["read", "manageRoles", "assignRoles"],
@@ -70,6 +70,8 @@ exports.terrenoStatements = {
70
70
  "impersonate",
71
71
  "setPassword",
72
72
  "updateIdentity",
73
+ "manageSecurity",
74
+ "issueSignInLink",
73
75
  ],
74
76
  };
75
77
  exports.READ_ACTIONS = ["read", "list", "view"];
@@ -125,7 +127,14 @@ exports.terrenoStatementDescriptions = {
125
127
  list: "List traces and observability status",
126
128
  read: "View trace detail and run trace test helpers",
127
129
  },
130
+ consentResponse: {
131
+ list: "List consent responses",
132
+ read: "View consent responses",
133
+ signOnBehalf: "Record, view, and void provisional consent signatures for other users",
134
+ },
128
135
  user: {
136
+ issueSignInLink: "Create a sign-in account for a legacy user and hand them a set-password link (AccountSecurityApp)",
137
+ manageSecurity: "View any user's sign-in methods and run account recovery (AccountSecurityApp)",
129
138
  updateIdentity: "Change another user's email, disabled flag, email verification, or linked Better Auth and GitHub ids",
130
139
  },
131
140
  };
@@ -188,8 +188,14 @@ export interface TerrenoAccess<S extends Statements> {
188
188
  readonly statements: S;
189
189
  readonly ac: ReturnType<typeof createAccessControl<S>>;
190
190
  can: (args: AccessCheckArgs<S>) => Promise<AccessResult>;
191
+ /**
192
+ * The user's effective permissions. With `requireComplete`, a permission source that failed and
193
+ * whose grants are unknown throws 503 instead of leaving its grants out; use it for a user whose
194
+ * missing permissions would loosen a check (the target of "may the actor act on this user?").
195
+ */
191
196
  getPermissions: (args: {
192
197
  user: User;
198
+ requireComplete?: boolean;
193
199
  }) => Promise<PermissionSet>;
194
200
  queryFilter: (args: {
195
201
  user?: User;
@@ -73,7 +73,8 @@ const assertCanWriteTargetUser = async ({ accessControl, actor, modelName, targe
73
73
  return;
74
74
  }
75
75
  const actorPermissions = await getPermissions({ user: actor });
76
- const targetPermissions = await getPermissions({ user: target });
76
+ // A target missing a failed source's grants would look less privileged than it is.
77
+ const targetPermissions = await getPermissions({ requireComplete: true, user: target });
77
78
  if ((0, permissionUtils_1.isPermissionSubset)(actorPermissions, targetPermissions)) {
78
79
  return;
79
80
  }
@@ -65,6 +65,13 @@ const describeCaster = (caster) => {
65
65
  required: false,
66
66
  };
67
67
  };
68
+ /**
69
+ * Whether a path is required on every document. A conditional `required` (a function) only
70
+ * applies to some documents, so clients must not treat the field as always present.
71
+ */
72
+ const isAlwaysRequired = (schemaPath) => {
73
+ return Boolean(schemaPath.isRequired) && typeof schemaPath.originalRequiredValue !== "function";
74
+ };
68
75
  const describeSchemaPath = (path, schemaPath) => {
69
76
  const enumValues = schemaPath.enumValues?.length
70
77
  ? schemaPath.enumValues
@@ -75,7 +82,7 @@ const describeSchemaPath = (path, schemaPath) => {
75
82
  enum: enumValues?.length ? enumValues : undefined,
76
83
  kind: normalizeKind(schemaPath.instance),
77
84
  ref: schemaPath.options?.ref,
78
- required: Boolean(schemaPath.isRequired),
85
+ required: isAlwaysRequired(schemaPath),
79
86
  system: isSystemField(path),
80
87
  };
81
88
  if (schemaPath.instance === "Array") {
@@ -75,8 +75,13 @@ const seedBetterAuthUser = async ({ auth, user, userModel, }) => {
75
75
  });
76
76
  }
77
77
  // The seed created or signed in to this Better Auth account itself, so its email is trusted
78
- // for linking an existing app user (for example one seeded under the legacy JWT flow).
79
- return (0, betterAuthSetup_1.syncBetterAuthUser)(userModel, authUser, undefined, { trustEmail: true });
78
+ // for linking an existing app user (for example one seeded under the legacy JWT flow). With a
79
+ // `userModel` on `auth`, the sign-up itself is refused for a legacy User unless the seed
80
+ // password matches its passport hash, the same way a real sign-up is.
81
+ return (0, betterAuthSetup_1.syncBetterAuthUser)(userModel, authUser, undefined, {
82
+ password: user.password,
83
+ trustEmail: true,
84
+ });
80
85
  };
81
86
  exports.seedBetterAuthUser = seedBetterAuthUser;
82
87
  const selectSteps = (steps, only) => {
@@ -199,6 +199,10 @@ export declare class TerrenoApp {
199
199
  * Returns registered model routers and plugins in mount order.
200
200
  */
201
201
  getRegistrations(): readonly (ModelRouterRegistration | TerrenoPlugin)[];
202
+ /**
203
+ * The RBAC access control passed as `accessControl`, if any.
204
+ */
205
+ getAccessControl(): TerrenoAppOptions["accessControl"];
202
206
  /**
203
207
  * The application user model this app authenticates against.
204
208
  */
@@ -44,6 +44,7 @@ const cors_1 = __importDefault(require("cors"));
44
44
  const express_1 = __importDefault(require("express"));
45
45
  const mongoose_1 = __importDefault(require("mongoose"));
46
46
  const qs_1 = __importDefault(require("qs"));
47
+ const accountSecurityApp_1 = require("./accountSecurity/accountSecurityApp");
47
48
  const auth_1 = require("./auth");
48
49
  const betterAuthApp_1 = require("./betterAuthApp");
49
50
  const betterAuthSetup_1 = require("./betterAuthSetup");
@@ -178,6 +179,12 @@ class TerrenoApp {
178
179
  getRegistrations() {
179
180
  return this.registrations;
180
181
  }
182
+ /**
183
+ * The RBAC access control passed as `accessControl`, if any.
184
+ */
185
+ getAccessControl() {
186
+ return this.options.accessControl;
187
+ }
181
188
  /**
182
189
  * The application user model this app authenticates against.
183
190
  */
@@ -277,6 +284,9 @@ class TerrenoApp {
277
284
  (0, logger_1.setupLogging)(this.options.loggingOptions);
278
285
  const app = (0, express_1.default)();
279
286
  const options = this.options;
287
+ // A BetterAuthApp registered without its own userModel uses the app's, before its Better Auth
288
+ // instance exists, so the app User guard and sync are installed with it.
289
+ (0, betterAuthApp_1.findBetterAuthProvider)(this.registrations)?.adoptUserModel?.(options.userModel);
280
290
  // Resolve first so a misconfigured issuer or consent URL fails at boot.
281
291
  const mcpOAuth = (0, oauthMetadata_1.resolveMcpOAuthOption)(options.mcpOAuth);
282
292
  // Record mount paths on layers for Express 5 → OpenAPI compat
@@ -466,9 +476,14 @@ class TerrenoApp {
466
476
  const hasOrgsPlugin = this.registrations.some((registration) => !this.isModelRouterRegistration(registration) && registration instanceof orgsApp_1.OrgsApp);
467
477
  if (!hasOrgsPlugin) {
468
478
  const orgConfig = typeof this.options.organizations === "object" ? this.options.organizations : {};
479
+ // Org-admins get member recovery routes only when the app registered AccountSecurityApp.
480
+ const accountSecurity = orgConfig.accountSecurity ??
481
+ this.registrations.find((registration) => !this.isModelRouterRegistration(registration) &&
482
+ registration instanceof accountSecurityApp_1.AccountSecurityApp);
469
483
  this.register(new orgsApp_1.OrgsApp({
470
484
  ...orgConfig,
471
485
  access: this.options.accessControl,
486
+ accountSecurity,
472
487
  userModel: this.options.userModel,
473
488
  }));
474
489
  }
@@ -19,11 +19,15 @@ export interface StaffUser extends User {
19
19
  }
20
20
  export interface FoodCategory {
21
21
  _id?: string;
22
+ addendums?: FoodCategoryAddendum[];
22
23
  name: string;
23
24
  show: boolean;
24
25
  created: Date;
25
26
  updated: Date;
26
27
  }
28
+ interface FoodCategoryAddendum {
29
+ text: string;
30
+ }
27
31
  export interface Food {
28
32
  _id: string;
29
33
  name: string;
@@ -89,3 +93,4 @@ export declare const RequiredModel: mongoose.Model<RequiredField, {}, {}, {}, mo
89
93
  } & {
90
94
  id: string;
91
95
  }, any, RequiredField>;
96
+ export {};
@@ -60,6 +60,14 @@ const staffUserSchema = new mongoose_1.Schema({
60
60
  });
61
61
  exports.StaffUserModel = exports.UserModel.discriminator("Staff", staffUserSchema);
62
62
  const foodCategorySchema = new mongoose_1.Schema({
63
+ addendums: {
64
+ description: "Extra details about this food category",
65
+ type: [
66
+ new mongoose_1.Schema({
67
+ text: { description: "The additional category detail", type: String },
68
+ }),
69
+ ],
70
+ },
63
71
  name: { description: "The name of the food category", type: String },
64
72
  show: { description: "Whether this category is visible", type: Boolean },
65
73
  }, { timestamps: { createdAt: "created", updatedAt: "updated" } });
@@ -20,6 +20,14 @@ export interface ConsentResponseDocument extends mongoose.Document {
20
20
  userAgent?: string;
21
21
  contentSnapshot?: string;
22
22
  formVersionSnapshot?: number;
23
+ provisional: boolean;
24
+ provisionalSignedBy?: mongoose.Types.ObjectId;
25
+ provisionalNote?: string;
26
+ provisionalSignerIp?: string;
27
+ provisionalSignerUserAgent?: string;
28
+ voidedAt?: Date;
29
+ voidedBy?: mongoose.Types.ObjectId;
30
+ voidReason?: string;
23
31
  created: Date;
24
32
  updated: Date;
25
33
  deleted: boolean;
@@ -1,18 +1,42 @@
1
1
  import type mongoose from "mongoose";
2
2
  import type { FindExactlyOnePlugin, FindOneOrNonePlugin } from "../plugins";
3
- /** A client registered through dynamic client registration (RFC 7591). Public clients only. */
3
+ export type McpOAuthTokenEndpointAuthMethod = "none" | "client_secret_basic" | "client_secret_post";
4
+ /** Options for `McpOAuthClient.issueConfidential`. The secret is returned once. */
5
+ export interface McpOAuthConfidentialClientOptions {
6
+ clientId?: string;
7
+ clientName: string;
8
+ scope?: string;
9
+ tokenEndpointAuthMethod: Exclude<McpOAuthTokenEndpointAuthMethod, "none">;
10
+ userId: mongoose.Types.ObjectId | string;
11
+ }
12
+ /**
13
+ * A public authorization-code client, or a confidential `client_credentials` client bound to a
14
+ * user. Public clients leave `tokenEndpointAuthMethod` unset.
15
+ */
4
16
  export interface McpOAuthClientDocument extends mongoose.Document {
5
17
  _id: mongoose.Types.ObjectId;
6
18
  clientId: string;
7
19
  clientName?: string;
20
+ /** SHA-256 hash of the client secret. Set only for confidential clients. */
21
+ clientSecretHash?: string;
8
22
  created: Date;
9
23
  grantTypes: string[];
10
24
  redirectUris: string[];
11
25
  responseTypes: string[];
26
+ revokedAt?: Date;
12
27
  scope?: string;
28
+ tokenEndpointAuthMethod?: McpOAuthTokenEndpointAuthMethod;
13
29
  updated: Date;
30
+ /** User a `client_credentials` token acts as. */
31
+ userId?: mongoose.Types.ObjectId;
14
32
  }
15
33
  interface McpOAuthClientStatics extends FindExactlyOnePlugin<McpOAuthClientDocument>, FindOneOrNonePlugin<McpOAuthClientDocument> {
34
+ issueConfidential: (this: McpOAuthClientModel, options: McpOAuthConfidentialClientOptions) => Promise<{
35
+ client: McpOAuthClientDocument;
36
+ clientSecret: string;
37
+ }>;
38
+ /** Mark the client revoked and end every token it holds. */
39
+ revoke: (this: McpOAuthClientModel, clientId: string) => Promise<McpOAuthClientDocument | null>;
16
40
  }
17
41
  export interface McpOAuthClientModel extends mongoose.Model<McpOAuthClientDocument>, McpOAuthClientStatics {
18
42
  }
@@ -66,6 +90,11 @@ export interface McpOAuthTokenDocument extends mongoose.Document {
66
90
  clientId: string;
67
91
  created: Date;
68
92
  familyId: string;
93
+ /**
94
+ * False for an access-only `client_credentials` token. The stored refresh hash is then of a
95
+ * discarded secret and must not be exchanged.
96
+ */
97
+ hasRefreshToken?: boolean;
69
98
  refreshExpiresAt: Date;
70
99
  refreshTokenHash: string;
71
100
  resource?: string;
@@ -80,6 +109,8 @@ export interface McpOAuthTokenIssueOptions {
80
109
  accessTokenTtlSeconds: number;
81
110
  clientId: string;
82
111
  familyId?: string;
112
+ /** When false, issue an access token only and do not return a refresh token. Default true. */
113
+ includeRefreshToken?: boolean;
83
114
  refreshTokenTtlSeconds: number;
84
115
  resource?: string;
85
116
  scope?: string;
@@ -91,8 +122,10 @@ interface McpOAuthTokenStatics extends FindExactlyOnePlugin<McpOAuthTokenDocumen
91
122
  issue: (this: McpOAuthTokenModel, options: McpOAuthTokenIssueOptions) => Promise<{
92
123
  accessToken: string;
93
124
  mcpOAuthToken: McpOAuthTokenDocument;
94
- refreshToken: string;
125
+ refreshToken?: string;
95
126
  }>;
127
+ /** Revoke every family issued to this client. */
128
+ revokeClient: (this: McpOAuthTokenModel, clientId: string) => Promise<void>;
96
129
  revokeFamily: (this: McpOAuthTokenModel, familyId: string) => Promise<void>;
97
130
  verifyAccessToken: (this: McpOAuthTokenModel, token: string) => Promise<McpOAuthTokenDocument | null>;
98
131
  }
package/package.json CHANGED
@@ -8,10 +8,12 @@
8
8
  },
9
9
  "dependencies": {
10
10
  "@asteasolutions/zod-to-openapi": "^8.5.0",
11
+ "@better-auth/expo": "^1.6.25",
12
+ "@better-auth/passkey": "1.7.4",
11
13
  "@modelcontextprotocol/node": "^2.0.0",
12
14
  "@modelcontextprotocol/server": "^2.0.0",
13
15
  "@sentry/bun": "^10.39.0",
14
- "@terreno/test": "57.19.2",
16
+ "@terreno/test": "57.20.0",
15
17
  "@thream/socketio-jwt": "^3.1.4",
16
18
  "@types/qs": "^6.14.0",
17
19
  "ajv": "8.20.0",
@@ -36,6 +38,7 @@
36
38
  "passport-local": "^1.0.0",
37
39
  "path-to-regexp": "^8.4.2",
38
40
  "qs": "^6.15.0",
41
+ "reflect-metadata": "^0.2.2",
39
42
  "router": "^2.2.0",
40
43
  "serve-static": "^2.2.1",
41
44
  "socket.io": "^4.8.1",
@@ -48,7 +51,7 @@
48
51
  "devDependencies": {
49
52
  "@biomejs/biome": "^2.3.6",
50
53
  "@modelcontextprotocol/client": "^2.0.0",
51
- "@terreno/syncdb": "57.19.2",
54
+ "@terreno/syncdb": "57.20.0",
52
55
  "@types/bun": "^1.4.0",
53
56
  "@types/cors": "^2.8.17",
54
57
  "@types/express": "^5.0.6",
@@ -132,5 +135,5 @@
132
135
  "updateSnapshot": "bun test --update-snapshots"
133
136
  },
134
137
  "types": "dist/index.d.ts",
135
- "version": "57.19.2"
138
+ "version": "57.20.0"
136
139
  }