very-express 0.10.2 → 0.11.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.

Potentially problematic release.


This version of very-express might be problematic. Click here for more details.

Files changed (266) hide show
  1. package/.tmp/_body.txt +1 -0
  2. package/.tmp/_idx.txt +1 -0
  3. package/.tmp/_token.txt +1 -0
  4. package/.tmp/check-a/app/.vex/meta.json +216 -0
  5. package/.tmp/check-a/app/Dockerfile +20 -0
  6. package/.tmp/check-a/app/README.md +39 -0
  7. package/.tmp/check-a/app/public/css/style.css +8 -0
  8. package/.tmp/check-a/app/public/js/deleteaccount.js +80 -0
  9. package/.tmp/check-a/app/public/js/login.js +59 -0
  10. package/.tmp/check-a/app/public/js/logincallback.js +19 -0
  11. package/.tmp/check-a/app/public/js/mytokens.js +11 -0
  12. package/.tmp/check-a/app/public/js/refreshtokens.js +23 -0
  13. package/.tmp/check-a/app/scripts/build.js +39 -0
  14. package/.tmp/check-a/app/scripts/oacg-fix.js +83 -0
  15. package/.tmp/check-a/app/tsconfig.json +30 -0
  16. package/.tmp/check-a/schemas/Project.json +41 -0
  17. package/.tmp/check-a/schemas/Session.json +49 -0
  18. package/.tmp/check-a/schemas/UserAuthProfiles.json +54 -0
  19. package/.tmp/check-a/vex.config.json +26 -0
  20. package/.tmp/check-b/app/.env +41 -0
  21. package/.tmp/check-b/app/.vex/meta.json +219 -0
  22. package/.tmp/check-b/app/Dockerfile +20 -0
  23. package/.tmp/check-b/app/README.md +39 -0
  24. package/.tmp/check-b/app/package.json +51 -0
  25. package/.tmp/check-b/app/public/css/style.css +8 -0
  26. package/.tmp/check-b/app/public/js/deleteaccount.js +80 -0
  27. package/.tmp/check-b/app/public/js/login.js +59 -0
  28. package/.tmp/check-b/app/public/js/logincallback.js +19 -0
  29. package/.tmp/check-b/app/public/js/mytokens.js +11 -0
  30. package/.tmp/check-b/app/public/js/refreshtokens.js +23 -0
  31. package/.tmp/check-b/app/scripts/build.js +39 -0
  32. package/.tmp/check-b/app/scripts/oacg-fix.js +83 -0
  33. package/.tmp/check-b/app/tsconfig.json +30 -0
  34. package/.tmp/check-b/app/tsoa.json +32 -0
  35. package/.tmp/check-b/schemas/Project.json +41 -0
  36. package/.tmp/check-b/vex.config.json +30 -0
  37. package/.tmp/check-c/app/.env +41 -0
  38. package/.tmp/check-c/app/.vex/meta.json +231 -0
  39. package/.tmp/check-c/app/Dockerfile +20 -0
  40. package/.tmp/check-c/app/README.md +39 -0
  41. package/.tmp/check-c/app/package.json +51 -0
  42. package/.tmp/check-c/app/public/css/style.css +8 -0
  43. package/.tmp/check-c/app/public/js/deleteaccount.js +80 -0
  44. package/.tmp/check-c/app/public/js/login.js +59 -0
  45. package/.tmp/check-c/app/public/js/logincallback.js +19 -0
  46. package/.tmp/check-c/app/public/js/mytokens.js +11 -0
  47. package/.tmp/check-c/app/public/js/refreshtokens.js +23 -0
  48. package/.tmp/check-c/app/scripts/build.js +39 -0
  49. package/.tmp/check-c/app/scripts/oacg-fix.js +83 -0
  50. package/.tmp/check-c/app/tsconfig.json +30 -0
  51. package/.tmp/check-c/app/tsoa.json +32 -0
  52. package/.tmp/check-c/schemas/Project.json +41 -0
  53. package/.tmp/check-c/schemas/User.json +81 -0
  54. package/.tmp/check-c/vex.config.json +30 -0
  55. package/.tmp/demo-project/vex.config.json +43 -0
  56. package/.tmp/demo-project2/vex.config.json +43 -0
  57. package/.tmp/demo-schemas/Client.json +65 -0
  58. package/.tmp/demo-schemas/FnbOrder.json +33 -0
  59. package/.tmp/demo-schemas/Job.json +86 -0
  60. package/.tmp/demo-schemas/KernelEvent.json +29 -0
  61. package/.tmp/demo-schemas/Package.json +77 -0
  62. package/.tmp/demo-schemas/Session.json +49 -0
  63. package/.tmp/demo-schemas/Tenant.json +22 -0
  64. package/.tmp/demo-schemas/User.json +81 -0
  65. package/.tmp/demo-schemas/UserAuthProfiles.json +54 -0
  66. package/.tmp/demo-schemas/UserContact.json +76 -0
  67. package/.tmp/demo-schemas/UserRole.json +40 -0
  68. package/.tmp/demo-schemas/UserTenant.json +39 -0
  69. package/.tmp/demo-schemas2/Client.json +65 -0
  70. package/.tmp/demo-schemas2/FnbOrder.json +33 -0
  71. package/.tmp/demo-schemas2/Job.json +86 -0
  72. package/.tmp/demo-schemas2/KernelEvent.json +29 -0
  73. package/.tmp/demo-schemas2/Package.json +77 -0
  74. package/.tmp/demo-schemas2/Session.json +49 -0
  75. package/.tmp/demo-schemas2/Tenant.json +22 -0
  76. package/.tmp/demo-schemas2/User.json +81 -0
  77. package/.tmp/demo-schemas2/UserAuthProfiles.json +54 -0
  78. package/.tmp/demo-schemas2/UserContact.json +76 -0
  79. package/.tmp/demo-schemas2/UserRole.json +40 -0
  80. package/.tmp/demo-schemas2/UserTenant.json +39 -0
  81. package/.tmp/e2e-db.url +1 -0
  82. package/.tmp/nouser/out/.env +41 -0
  83. package/.tmp/nouser/out/.vex/meta.json +323 -0
  84. package/.tmp/nouser/out/Dockerfile +20 -0
  85. package/.tmp/nouser/out/README.md +39 -0
  86. package/.tmp/nouser/out/package.json +51 -0
  87. package/.tmp/nouser/out/public/css/style.css +8 -0
  88. package/.tmp/nouser/out/public/js/deleteaccount.js +80 -0
  89. package/.tmp/nouser/out/public/js/login.js +59 -0
  90. package/.tmp/nouser/out/public/js/logincallback.js +19 -0
  91. package/.tmp/nouser/out/public/js/mytokens.js +11 -0
  92. package/.tmp/nouser/out/public/js/refreshtokens.js +23 -0
  93. package/.tmp/nouser/out/scripts/build.js +39 -0
  94. package/.tmp/nouser/out/scripts/oacg-fix.js +83 -0
  95. package/.tmp/nouser/out/tsconfig.json +30 -0
  96. package/.tmp/nouser/out/tsoa.json +32 -0
  97. package/.tmp/nouser/schemas/Project.json +41 -0
  98. package/.tmp/nouser/schemas/Session.json +49 -0
  99. package/.tmp/nouser/schemas/User.json +81 -0
  100. package/.tmp/nouser/schemas/UserAuthProfiles.json +54 -0
  101. package/.tmp/nouser/schemas/UserTenant.json +39 -0
  102. package/.tmp/nouser/vex.config.json +34 -0
  103. package/.tmp/npm-test-after-fix.log +217 -0
  104. package/.tmp/npm-test-final.log +165 -0
  105. package/.tmp/npm-test-final2.log +163 -0
  106. package/.tmp/npm-test-recheck.log +192 -0
  107. package/.tmp/npm-test-update.log +164 -0
  108. package/.tmp/npm-test.log +166 -0
  109. package/.tmp/output-build-after-fix.log +8 -0
  110. package/.tmp/output-build-baseline.log +8 -0
  111. package/.tmp/output-build-canonical.log +8 -0
  112. package/.tmp/output-build-final2.log +8 -0
  113. package/.tmp/output-build-reapply.log +8 -0
  114. package/.tmp/output-build.log +8 -0
  115. package/.tmp/output.env.bak +34 -0
  116. package/.tmp/probe_body.txt +1 -0
  117. package/.tmp/provision-e2e-db.js +41 -0
  118. package/.tmp/retry-nodestroy.log +18 -0
  119. package/.tmp/retry-recovery-final2.log +8 -0
  120. package/.tmp/retry-recovery-reapply.log +8 -0
  121. package/.tmp/retry-recovery.js +38 -0
  122. package/.tmp/run-e2e-single.js +21 -0
  123. package/.tmp/run-e2e.js +18 -0
  124. package/.tmp/verify-noauth/app/.env +41 -0
  125. package/.tmp/verify-noauth/app/.vex/meta.json +333 -0
  126. package/.tmp/verify-noauth/app/Dockerfile +20 -0
  127. package/.tmp/verify-noauth/app/README.md +39 -0
  128. package/.tmp/verify-noauth/app/package.json +51 -0
  129. package/.tmp/verify-noauth/app/public/css/style.css +8 -0
  130. package/.tmp/verify-noauth/app/public/js/deleteaccount.js +80 -0
  131. package/.tmp/verify-noauth/app/public/js/login.js +59 -0
  132. package/.tmp/verify-noauth/app/public/js/logincallback.js +19 -0
  133. package/.tmp/verify-noauth/app/public/js/mytokens.js +11 -0
  134. package/.tmp/verify-noauth/app/public/js/refreshtokens.js +23 -0
  135. package/.tmp/verify-noauth/app/scripts/build.js +39 -0
  136. package/.tmp/verify-noauth/app/scripts/oacg-fix.js +83 -0
  137. package/.tmp/verify-noauth/app/tsconfig.json +30 -0
  138. package/.tmp/verify-noauth/app/tsoa.json +32 -0
  139. package/.tmp/verify-noauth/schemas/Project.json +41 -0
  140. package/.tmp/verify-noauth/schemas/Session.json +49 -0
  141. package/.tmp/verify-noauth/schemas/User.json +81 -0
  142. package/.tmp/verify-noauth/schemas/UserAuthProfiles.json +54 -0
  143. package/.tmp/verify-noauth/schemas/UserTenant.json +39 -0
  144. package/.tmp/verify-noauth/vex.config.json +33 -0
  145. package/.tmp/verify-noauth-rbac/app/.env +41 -0
  146. package/.tmp/verify-noauth-rbac/app/.vex/meta.json +273 -0
  147. package/.tmp/verify-noauth-rbac/app/Dockerfile +20 -0
  148. package/.tmp/verify-noauth-rbac/app/README.md +39 -0
  149. package/.tmp/verify-noauth-rbac/app/package.json +51 -0
  150. package/.tmp/verify-noauth-rbac/app/public/css/style.css +8 -0
  151. package/.tmp/verify-noauth-rbac/app/public/js/deleteaccount.js +80 -0
  152. package/.tmp/verify-noauth-rbac/app/public/js/login.js +59 -0
  153. package/.tmp/verify-noauth-rbac/app/public/js/logincallback.js +19 -0
  154. package/.tmp/verify-noauth-rbac/app/public/js/mytokens.js +11 -0
  155. package/.tmp/verify-noauth-rbac/app/public/js/refreshtokens.js +23 -0
  156. package/.tmp/verify-noauth-rbac/app/scripts/build.js +39 -0
  157. package/.tmp/verify-noauth-rbac/app/scripts/oacg-fix.js +83 -0
  158. package/.tmp/verify-noauth-rbac/app/tsconfig.json +30 -0
  159. package/.tmp/verify-noauth-rbac/app/tsoa.json +32 -0
  160. package/.tmp/verify-noauth-rbac/schemas/Project.json +41 -0
  161. package/.tmp/verify-noauth-rbac/schemas/User.json +81 -0
  162. package/.tmp/verify-noauth-rbac/schemas/UserRole.json +38 -0
  163. package/.tmp/verify-noauth-rbac/vex.config.json +36 -0
  164. package/.tmp/verify.sh +103 -0
  165. package/.tmp/verify2.sh +103 -0
  166. package/.tmp/vex-gen-after-fix.log +221 -0
  167. package/.tmp/vex-gen-baseline.log +221 -0
  168. package/.tmp/vex-gen-canonical.log +221 -0
  169. package/.tmp/vex-gen-final.log +220 -0
  170. package/.tmp/vex-gen-final2.log +221 -0
  171. package/.tmp/vex-gen-reapply.log +221 -0
  172. package/.tmp/vex-gen.log +220 -0
  173. package/.tmp/vex-run-after-fix.log +3 -0
  174. package/.tmp/vex-run-baseline.log +11 -0
  175. package/.tmp/vex-run-before-fix.log +11 -0
  176. package/.tmp/vex-run-canonical.log +3 -0
  177. package/.tmp/vex-run-final2.log +3 -0
  178. package/.tmp/vex-run.log +3 -0
  179. package/.tmp/vo/app/.env +41 -0
  180. package/.tmp/vo/app/.vex/meta.json +231 -0
  181. package/.tmp/vo/app/Dockerfile +20 -0
  182. package/.tmp/vo/app/README.md +39 -0
  183. package/.tmp/vo/app/package.json +51 -0
  184. package/.tmp/vo/app/public/css/style.css +8 -0
  185. package/.tmp/vo/app/public/js/deleteaccount.js +80 -0
  186. package/.tmp/vo/app/public/js/login.js +59 -0
  187. package/.tmp/vo/app/public/js/logincallback.js +19 -0
  188. package/.tmp/vo/app/public/js/mytokens.js +11 -0
  189. package/.tmp/vo/app/public/js/refreshtokens.js +23 -0
  190. package/.tmp/vo/app/scripts/build.js +39 -0
  191. package/.tmp/vo/app/scripts/oacg-fix.js +83 -0
  192. package/.tmp/vo/app/tsconfig.json +30 -0
  193. package/.tmp/vo/app/tsoa.json +32 -0
  194. package/.tmp/vo/schemas/Project.json +41 -0
  195. package/.tmp/vo/vex.config.json +33 -0
  196. package/.tmp/vo-bad1/app/.env +41 -0
  197. package/.tmp/vo-bad1/app/.vex/meta.json +237 -0
  198. package/.tmp/vo-bad1/app/Dockerfile +20 -0
  199. package/.tmp/vo-bad1/app/README.md +39 -0
  200. package/.tmp/vo-bad1/app/package.json +51 -0
  201. package/.tmp/vo-bad1/app/public/css/style.css +8 -0
  202. package/.tmp/vo-bad1/app/public/js/deleteaccount.js +80 -0
  203. package/.tmp/vo-bad1/app/public/js/login.js +59 -0
  204. package/.tmp/vo-bad1/app/public/js/logincallback.js +19 -0
  205. package/.tmp/vo-bad1/app/public/js/mytokens.js +11 -0
  206. package/.tmp/vo-bad1/app/public/js/refreshtokens.js +23 -0
  207. package/.tmp/vo-bad1/app/scripts/build.js +39 -0
  208. package/.tmp/vo-bad1/app/scripts/oacg-fix.js +83 -0
  209. package/.tmp/vo-bad1/app/tsconfig.json +30 -0
  210. package/.tmp/vo-bad1/app/tsoa.json +32 -0
  211. package/.tmp/vo-bad1/schemas/Project.json +41 -0
  212. package/.tmp/vo-bad1/vex.config.json +33 -0
  213. package/.tmp/vo-bad2/app/.env +41 -0
  214. package/.tmp/vo-bad2/app/.vex/meta.json +237 -0
  215. package/.tmp/vo-bad2/app/Dockerfile +20 -0
  216. package/.tmp/vo-bad2/app/README.md +39 -0
  217. package/.tmp/vo-bad2/app/package.json +51 -0
  218. package/.tmp/vo-bad2/app/public/css/style.css +8 -0
  219. package/.tmp/vo-bad2/app/public/js/deleteaccount.js +80 -0
  220. package/.tmp/vo-bad2/app/public/js/login.js +59 -0
  221. package/.tmp/vo-bad2/app/public/js/logincallback.js +19 -0
  222. package/.tmp/vo-bad2/app/public/js/mytokens.js +11 -0
  223. package/.tmp/vo-bad2/app/public/js/refreshtokens.js +23 -0
  224. package/.tmp/vo-bad2/app/scripts/build.js +39 -0
  225. package/.tmp/vo-bad2/app/scripts/oacg-fix.js +83 -0
  226. package/.tmp/vo-bad2/app/tsconfig.json +30 -0
  227. package/.tmp/vo-bad2/app/tsoa.json +32 -0
  228. package/.tmp/vo-bad2/schemas/Project.json +41 -0
  229. package/.tmp/vo-bad2/vex.config.json +39 -0
  230. package/.tmp/vo-bad3/app/.env +41 -0
  231. package/.tmp/vo-bad3/app/.vex/meta.json +237 -0
  232. package/.tmp/vo-bad3/app/Dockerfile +20 -0
  233. package/.tmp/vo-bad3/app/README.md +39 -0
  234. package/.tmp/vo-bad3/app/package.json +51 -0
  235. package/.tmp/vo-bad3/app/public/css/style.css +8 -0
  236. package/.tmp/vo-bad3/app/public/js/deleteaccount.js +80 -0
  237. package/.tmp/vo-bad3/app/public/js/login.js +59 -0
  238. package/.tmp/vo-bad3/app/public/js/logincallback.js +19 -0
  239. package/.tmp/vo-bad3/app/public/js/mytokens.js +11 -0
  240. package/.tmp/vo-bad3/app/public/js/refreshtokens.js +23 -0
  241. package/.tmp/vo-bad3/app/scripts/build.js +39 -0
  242. package/.tmp/vo-bad3/app/scripts/oacg-fix.js +83 -0
  243. package/.tmp/vo-bad3/app/tsconfig.json +30 -0
  244. package/.tmp/vo-bad3/app/tsoa.json +32 -0
  245. package/.tmp/vo-bad3/schemas/Project.json +41 -0
  246. package/.tmp/vo-bad3/vex.config.json +33 -0
  247. package/dist/index.js +1156 -698
  248. package/dist/templates/_middlewares/UserContext.ts +1 -1
  249. package/dist/templates/_routes/FirebaseAuthUI.gen.ts +2 -2
  250. package/dist/templates/_routes/{LoginUI.ts → StarterUI.ts} +122 -8
  251. package/dist/templates/_utils/hash.ts +9 -4
  252. package/dist/templates/tenantJsonSchema/Tenant.json +22 -0
  253. package/docs/appGenerated/auth.md +50 -0
  254. package/docs/architecture/databaseTargets.md +23 -2
  255. package/docs/architecture/templates.md +7 -0
  256. package/docs/features/accountDeletion.md +5 -4
  257. package/docs/features/auditFields.md +2 -2
  258. package/docs/features/tenantIsolation.md +108 -15
  259. package/docs/releaseNote/v0-10-3.md +61 -0
  260. package/docs/releaseNote/v0-10-4.md +102 -0
  261. package/docs/releaseNote/v0-11-0.md +82 -0
  262. package/docs/vexJsonSchema.md +34 -1
  263. package/package.json +1 -1
  264. package/vex.config.json +6 -1
  265. package/dist/templates/_services/VexDbConnector.ts +0 -188
  266. package/dist/templates/_tenant/TenantScopeContext.ts +0 -56
@@ -14,7 +14,7 @@ export interface UserContextData {
14
14
  * Pure: identity value carried by a verified access token.
15
15
  *
16
16
  * `vexUserId` is the schema-declared identity (the field tagged `x-vexData: "userId"`,
17
- * which JWTService copies into the token); `_id` keeps tokens issued before that claim
17
+ * which the auth module copies into the token); `_id` keeps tokens issued before that claim
18
18
  * existed working.
19
19
  */
20
20
  export function userIdOfToken(tokenData: Record<string, unknown> | undefined): string | undefined {
@@ -1,11 +1,11 @@
1
1
  // {{headerComment}}
2
- import type { FirebaseAuthUI } from "./LoginUI.gen";
2
+ import type { FirebaseAuthUI } from "./StarterUI.gen";
3
3
 
4
4
  /**
5
5
  * Test/compile-time stand-in for the generated login-page wiring.
6
6
  *
7
7
  * **In a generated app this file is overwritten by the generator**, which emits the Firebase wiring or
8
- * `undefined` when `auth.firebase` is off. It lives in the template directory so that `LoginUI.ts`'s
8
+ * `undefined` when `auth.firebase` is off. It lives in the template directory so that `StarterUI.ts`'s
9
9
  * unconditional import resolves in this repo — that import has to be unconditional, because the
10
10
  * generated default is how the configuration reaches the login page without editing the app-owned
11
11
  * `server.ts`.
@@ -46,13 +46,15 @@ export function diagnoseMissingEnv(
46
46
  return problems;
47
47
  }
48
48
 
49
- export interface LoginUIConfig {
49
+ export interface StarterUIConfig {
50
50
  localAuth: boolean;
51
51
  oauthProviders: string[];
52
52
  /** Serve the self-service deletion page at `/delete_account`. */
53
53
  deleteAccount?: boolean;
54
54
  /** Override the Firebase sign-in wiring. */
55
55
  firebase?: FirebaseAuthUI;
56
+ /** Link the create-tenant page from the home page. */
57
+ tenantPage?: boolean;
56
58
  }
57
59
 
58
60
  /** Everything the login page needs to drive Firebase, as emitted into `FirebaseAuthUI.gen.ts`. */
@@ -83,7 +85,7 @@ interface firebaseProvider {
83
85
  label: string;
84
86
  }
85
87
 
86
- export default class LoginUI {
88
+ export default class StarterUI {
87
89
 
88
90
  /** Last set of problems warned about, so a page render logs them once. */
89
91
  private static warnedEnvSignature = "";
@@ -92,9 +94,9 @@ export default class LoginUI {
92
94
  private static envFileCache: Record<string, string> | undefined;
93
95
 
94
96
  private router: Router = Router();
95
- private config: LoginUIConfig;
97
+ private config: StarterUIConfig;
96
98
 
97
- constructor(config: LoginUIConfig) {
99
+ constructor(config: StarterUIConfig) {
98
100
  this.config = config;
99
101
  this.registerRoutes();
100
102
  }
@@ -117,6 +119,9 @@ export default class LoginUI {
117
119
  if (this.deleteAccountEnabled) {
118
120
  this.router.get("/delete_account", this.deleteAccountPage.bind(this));
119
121
  }
122
+ if (this.config.tenantPage) {
123
+ this.router.get("/tenant", this.tenantPage.bind(this));
124
+ }
120
125
  }
121
126
 
122
127
  /** The Firebase wiring in force: an explicit app override, else the generated default. */
@@ -210,12 +215,17 @@ export default class LoginUI {
210
215
  ? `<li><a href="/delete_account">Delete account</a></li>`
211
216
  : "";
212
217
 
218
+ const tenantLink = this.config.tenantPage
219
+ ? `<li><a href="/tenant">Tenant</a></li>`
220
+ : "";
221
+
213
222
  res.send(`
214
223
  <div>
215
224
  <h1>Hello World</h1>
216
225
  <ul>
217
226
  ${authLinks}
218
227
  ${deleteAccountLink}
228
+ ${tenantLink}
219
229
  <li><a href="/swagger">Swagger UI</a></li>
220
230
  </ul>
221
231
  <h1>Others</h1>
@@ -226,6 +236,110 @@ export default class LoginUI {
226
236
  `);
227
237
  }
228
238
 
239
+ /**
240
+ * Create the caller's tenant.
241
+ *
242
+ * The claim lives in a token, so the endpoint returns new tokens and the page stores them in the
243
+ * same four keys the login page uses. `single` mode renders one button: a second create answers
244
+ * `409 tenant_exists`, so the page explains that instead of offering the action again.
245
+ */
246
+ private tenantPage(_req: Request, res: Response): void {
247
+ const nonce = this.nonce();
248
+ res.setHeader("Content-Security-Policy", `script-src 'self' 'nonce-${nonce}'`);
249
+
250
+ res.send(`
251
+ <link rel="stylesheet" href="/css/style.css">
252
+ <body>
253
+ <h1>Tenant</h1>
254
+ <p>Create a tenant. It becomes the active one for this session.</p>
255
+ <p>Name (optional):</p>
256
+ <input type="text" id="tenantName" maxlength="120"/>
257
+ <br/><br/>
258
+ <button id="createBtn">Create tenant</button>
259
+ <p id="status"></p>
260
+ <p><a href="/">back to home</a></p>
261
+ </body>
262
+ <script nonce="${nonce}">
263
+ (function () {
264
+ var createBtn = document.getElementById("createBtn");
265
+ var status = document.getElementById("status");
266
+
267
+ function storeTokens(result) {
268
+ localStorage.setItem("accessToken", result.accessToken);
269
+ localStorage.setItem("accessTokenIndex", result.accessTokenIndex);
270
+ localStorage.setItem("refreshToken", result.refreshToken);
271
+ localStorage.setItem("refreshTokenIndex", result.refreshTokenIndex);
272
+ }
273
+
274
+ function say(text, link) {
275
+ status.textContent = text;
276
+ if (!link) return;
277
+
278
+ var a = document.createElement("a");
279
+ a.href = link.href;
280
+ a.textContent = link.text;
281
+ status.appendChild(document.createElement("br"));
282
+ status.appendChild(a);
283
+ }
284
+
285
+ createBtn.addEventListener("click", function () {
286
+ var accessToken = localStorage.getItem("accessToken");
287
+ var accessTokenIndex = localStorage.getItem("accessTokenIndex");
288
+
289
+ if (!accessToken || !accessTokenIndex) {
290
+ say("Log in first.", { href: "/login", text: "Go to login" });
291
+ return;
292
+ }
293
+
294
+ var nameInput = document.getElementById("tenantName");
295
+ var name = nameInput && nameInput.value ? nameInput.value.trim() : "";
296
+
297
+ createBtn.disabled = true;
298
+ fetch("/api/tenant/create", {
299
+ method: "POST",
300
+ headers: {
301
+ "Authorization": "Bearer " + accessToken,
302
+ "X-Auth-Index": accessTokenIndex,
303
+ "Content-Type": "application/json",
304
+ },
305
+ body: JSON.stringify(name ? { name: name } : {}),
306
+ }).then(function (response) {
307
+ return response.text().then(function (text) {
308
+ var body;
309
+ try {
310
+ body = text ? JSON.parse(text) : {};
311
+ }
312
+ catch (e) {
313
+ body = { raw: text };
314
+ }
315
+ return { ok: response.ok, status: response.status, body: body };
316
+ });
317
+ }).then(function (outcome) {
318
+ var result = outcome.body && outcome.body.result;
319
+ if (outcome.ok && result && result.accessToken) {
320
+ storeTokens(result);
321
+ say("Tenant created. This session is now tenant-scoped.",
322
+ { href: "/mytokens", text: "Inspect the token" });
323
+ return;
324
+ }
325
+
326
+ createBtn.disabled = false;
327
+ if (outcome.status === 409) {
328
+ say("This account already belongs to a tenant.",
329
+ { href: "/mytokens", text: "Inspect the token" });
330
+ return;
331
+ }
332
+ say("Create failed (" + outcome.status + "): " + JSON.stringify(outcome.body));
333
+ }).catch(function (err) {
334
+ createBtn.disabled = false;
335
+ say("Create failed: " + String(err));
336
+ });
337
+ });
338
+ })();
339
+ </script>
340
+ `);
341
+ }
342
+
229
343
  private loginPage(_req: Request, res: Response): void {
230
344
  const nonce = this.nonce();
231
345
  res.setHeader("Content-Security-Policy", this.loginPageCsp(nonce));
@@ -324,7 +438,7 @@ export default class LoginUI {
324
438
  * A missing or unparseable file is not an error — plenty of deployments have no `.env` at all.
325
439
  */
326
440
  private envFileValues(): Record<string, string> {
327
- if (LoginUI.envFileCache) return LoginUI.envFileCache;
441
+ if (StarterUI.envFileCache) return StarterUI.envFileCache;
328
442
 
329
443
  let values: Record<string, string> = {};
330
444
  try {
@@ -334,7 +448,7 @@ export default class LoginUI {
334
448
  // no .env, or unreadable: every missing name is then simply unset
335
449
  }
336
450
 
337
- LoginUI.envFileCache = values;
451
+ StarterUI.envFileCache = values;
338
452
  return values;
339
453
  }
340
454
 
@@ -352,8 +466,8 @@ export default class LoginUI {
352
466
  if (problems.length === 0) return;
353
467
 
354
468
  const signature = problems.join("|");
355
- if (LoginUI.warnedEnvSignature === signature) return;
356
- LoginUI.warnedEnvSignature = signature;
469
+ if (StarterUI.warnedEnvSignature === signature) return;
470
+ StarterUI.warnedEnvSignature = signature;
357
471
 
358
472
  console.warn(
359
473
  `[vex] auth.firebase is enabled but its public browser config is not usable:\n - ` +
@@ -1,6 +1,11 @@
1
1
  // {{headerComment}}
2
2
  import crypto from "crypto";
3
- import { UserWithRelations } from "../_types/User.gen";
3
+
4
+ /** The identity fields this module reads — any row carrying them satisfies it. */
5
+ export interface PasswordHolder {
6
+ email?: string;
7
+ userAuthProfiles?: Array<{ provider?: string, password?: string }>;
8
+ }
4
9
 
5
10
  export function hashPassword(
6
11
  plainPassword: string,
@@ -11,14 +16,14 @@ export function hashPassword(
11
16
  }
12
17
 
13
18
  export function verifyPassword(
14
- user: UserWithRelations,
19
+ user: PasswordHolder,
15
20
  plainPassword: string,
16
21
  ): boolean {
17
22
  if(!user.email || !user.userAuthProfiles) {
18
23
  return false;
19
24
  }
20
25
 
21
- const hashedPassword = user.userAuthProfiles.find((profile:any) => profile.provider === "local")?.password;
26
+ const hashedPassword = user.userAuthProfiles.find(profile => profile.provider === "local")?.password;
22
27
  if(!hashedPassword) {
23
28
  return false;
24
29
  }
@@ -29,4 +34,4 @@ export function verifyPassword(
29
34
  export default {
30
35
  hashPassword,
31
36
  verifyPassword
32
- };
37
+ };
@@ -0,0 +1,22 @@
1
+ {
2
+ "type": "object",
3
+ "x-documentConfig": {
4
+ "documentName": "Tenant",
5
+ "restApi": {
6
+ "methods": [],
7
+ "joinWhitelist": []
8
+ }
9
+ },
10
+ "required": [],
11
+ "properties": {
12
+ "_id": {
13
+ "type": "string",
14
+ "x-format": "PrimaryUUID",
15
+ "index": true
16
+ },
17
+ "name": {
18
+ "type": "string",
19
+ "description": "Display name. Optional; the module never reads it."
20
+ }
21
+ }
22
+ }
@@ -36,6 +36,56 @@ OAUTH_GOOGLE_CLIENTSECRET=xxxxx
36
36
 
37
37
  `/login` renders a form or a button for whichever paths are enabled.
38
38
 
39
+ ## The built-in account model
40
+
41
+ Auth resolves every request against one document named `User`. `app.useUserSchema` decides whether
42
+ vex writes it:
43
+
44
+ - `true` (default) — `jsonSchema/User.json` is copied from the templates and kept in sync with them
45
+ (`email`, `name`, `active`, `deleted`, the audit fields).
46
+ - `false` — vex writes nothing. The project supplies its own `User.json`; without one, generation
47
+ stops with `authentication needs a document named "User"`.
48
+
49
+ RBAC needs the same document (`UserRole` declares a foreign key to it), so it carries the same
50
+ requirement and the same error.
51
+
52
+ A schema in `jsonSchemaDir` is the app's input. Nothing deletes or rewrites it when the flag is off:
53
+ a `User.json` that is there is generated like any other document. The flag governs the template, not
54
+ the directory.
55
+
56
+ ## Verify-only services
57
+
58
+ An app that serves business routes but never signs anyone in sets `auth.verifyOnly: true`. It
59
+ validates access tokens minted by another vex app and issues none:
60
+
61
+ ```jsonc
62
+ "auth": { "localAuth": false, "verifyOnly": true }
63
+ ```
64
+
65
+ What it generates, and what it does not:
66
+
67
+ | | Sign-in app | Verify-only app |
68
+ |---|---|---|
69
+ | `Authentication.middleware` | verifies the token, then checks the account row | verifies the token only |
70
+ | `JWTService` | mints and verifies, owns sessions | `verifyToken` only |
71
+ | `AuthController`, `/login`, OAuth routes | yes | no |
72
+ | `User`, `UserAuthProfiles`, `Session` schemas | yes | no |
73
+ | `AccountStateGuard` | reads the identity row | constant `true` |
74
+
75
+ `JWT_SECRET0..9` and `JWT_ALGORITHM` must match the app that signs. The client sends the key slot
76
+ in `X-Auth-Index`, the same header it sends to the signing app.
77
+
78
+ The identity travels in the token, so `onCreateUserId` / `onUpdateUserId` and ownership isolation
79
+ (`source: "user._id"`) work. The token carries it as `vexUserId`; when it is absent the middleware
80
+ falls back to `_id`.
81
+
82
+ Revocation is bounded by token lifetime: there is no account row here to check, so a deleted
83
+ account's unexpired access token stays valid until it expires.
84
+
85
+ Verify-only cannot be combined with a sign-in method, with `useRBAC` (role assignments live in the
86
+ local `UserRole` table) or with `tenant.IsolationMode: "option"` (selecting a tenant mints a token).
87
+ Generation stops with a config error naming the conflict.
88
+
39
89
  ## The identity row
40
90
 
41
91
  A sign-in writes one `UserAuthProfiles` row, keyed by `(provider, providerUserId)` — a composite unique
@@ -15,9 +15,30 @@ pins `type: "postgres"` and the app depends on `pg` only, so column types in the
15
15
 
16
16
  ### SQL schema creation
17
17
 
18
- Schemas come from TypeORM `synchronize` at generated-app startup, controlled by the `SQL_SYNCHRONIZE` env var and wired in `_services/VexDbConnector.ts`.
18
+ TypeORM `synchronize` builds tables, enums, indexes and constraints from the entity metadata at
19
+ generated-app startup. Table creation alone never creates a PostgreSQL schema: the emitted
20
+ `CREATE TABLE` names the schema (`"kernel"."task"`) and PostgreSQL rejects it with
21
+ `schema "kernel" does not exist` (SQLSTATE `3F000`) when the schema is absent.
19
22
 
20
- The Knex-based `src/generators/db/sqlMigration.generator.ts` is **legacy/disabled**. Both its import and its call in `src/index.ts` are commented out, along with the `sqlMigrations` runner in `VexDbConnector.ts`. Do not treat it as live code.
23
+ `x-documentConfig.schema` therefore gets two pieces of generated output:
24
+
25
+ | Output | Purpose |
26
+ |---|---|
27
+ | `_models/{Document}Model.gen.ts` | `@Entity({ schema: vexDbSchemas.kernel, name: "task" })` — metadata carries the schema into every DDL statement |
28
+ | `_services/VexDbConnector.gen.ts` | creates each declared schema (`CREATE SCHEMA IF NOT EXISTS`) after connecting and, when the project declares one, runs `synchronize()` explicitly after that |
29
+
30
+ `_types/SchemaName.gen.ts` holds the union of the declared schemas and the runtime list
31
+ `vexDbSchemas`, which the connector imports. `synchronize` stays controlled by the `SQL_SYNCHRONIZE`
32
+ env var; the connector turns the option off and calls `ds.synchronize()` itself only when a
33
+ document declares a schema, so the schema creation cannot be skipped. `public` is never created.
34
+
35
+ A project that declares no schema emits the connector without that step, and `synchronize` keeps
36
+ running inside `initialize()` as before.
37
+
38
+ `VexDbConnector` is a function template (`src/generators/services/vexDbConnector.template.ts`), not
39
+ a static copy: the schema step and the `SchemaName` import exist only in projects that declare one.
40
+
41
+ The Knex-based `src/generators/db/sqlMigration.generator.ts` is **legacy/disabled**. Both its import and its call in `src/index.ts` are commented out. Do not treat it as live code.
21
42
 
22
43
  ## Repository adapter pattern
23
44
 
@@ -17,6 +17,12 @@ Copied groups (from `src/index.ts`):
17
17
 
18
18
  Files get a `.ts` → `.gen.ts` rename on copy, except `index.ts`.
19
19
 
20
+ One file in `_services/` is not copied: `VexDbConnector.ts` is a function template
21
+ (`src/generators/services/vexDbConnector.template.ts`). Its body depends on whether a document
22
+ declares a PostgreSQL schema, so the copy filter skips it and
23
+ [`src/generators/services/vexDbConnector.generator.ts`](../generators/services/vexDbConnector.generator.ts)
24
+ writes `_services/VexDbConnector.gen.ts` after the schemas are read.
25
+
20
26
  **Hand-editing a `.gen.ts` file in `output/` does not survive.** Copies go through the same `writeFile()` as generated code:
21
27
 
22
28
  - content identical after normalization (header comments stripped) → skipped, edit survives
@@ -61,6 +67,7 @@ supported syntax.
61
67
  | Need | Use |
62
68
  |---|---|
63
69
  | Whole file that is mostly fixed boilerplate | static template in `src/templates/` |
70
+ | Boilerplate with one project-dependent section | function template, like `VexDbConnector` |
64
71
  | File whose body varies per document/schema | generator + `*.template.ts` |
65
72
  | Small snippet of fixed boilerplate inside a varied file | inline string in the template function |
66
73
  | Executable function inside generated output | `FUNC{{ }}` |
@@ -159,8 +159,9 @@ The account may belong to several tenants, so deletion removes only the current
159
159
  4. `deleteTables` runs.
160
160
  5. `TenantService.removeUserTenant(userId, tenantId)` removes the mapping.
161
161
 
162
- The `User` row is not tombstoned: the account keeps working for its other tenants. The response
163
- carries `tenantId` and `deleted.userTenants = 1`; `tombstonedAt` is empty.
162
+ The `User` row is not tombstoned: the account keeps working for its other tenants. The `Tenant` row
163
+ stays as well — other members may remain. The response carries `tenantId` and
164
+ `deleted.userTenants = 1`; `tombstonedAt` is empty.
164
165
 
165
166
  The endpoint attaches `TenantScope.middleware` after authentication in `option` mode, so the claim
166
167
  must be present. In `preSelect` mode the header already established the tenant at L0.
@@ -175,11 +176,11 @@ and audit / identity fields are skipped.
175
176
 
176
177
  ## The page
177
178
 
178
- `GET /delete_account`, served from `LoginUI` rather than as a static file — `express.static("public")`
179
+ `GET /delete_account`, served from `StarterUI` rather than as a static file — `express.static("public")`
179
180
  would expose `public/delete_account.html` at `/delete_account.html`, not at the route the store
180
181
  listing points people at.
181
182
 
182
- `LoginUIConfig.deleteAccount` is **optional and defaults to true**, because an app's `server.ts` is
183
+ `StarterUIConfig.deleteAccount` is **optional and defaults to true**, because an app's `server.ts` is
183
184
  generated once and is not overwritten on later runs; a required field would stop such a project from
184
185
  compiling.
185
186
 
@@ -252,6 +252,6 @@ schema — a keyword would otherwise become a literal string default.
252
252
  - Soft delete.
253
253
  - Backfilling existing NULL rows.
254
254
  - An app whose ownership column points at a profile row rather than at `User`.
255
- - Extending `useUserSchema: false` into a fully custom account model. Today `User.json` is copied from the
256
- templates unconditionally and `localAuth` requires `useUserSchema: true`, so a custom identity schema is
255
+ - Extending `useUserSchema: false` into a fully custom account model. `localAuth` requires
256
+ `useUserSchema: true`, and auth / RBAC require a document named `User`, so a custom identity schema is
257
257
  not reachable yet; `x-vexData: "userId"` is the forward-compatible hook for it.
@@ -7,7 +7,7 @@ UUID; the header (`x-tenant-id`) and the token claim (`tenantId`) are fixed.
7
7
  ```jsonc
8
8
  "tenant": {
9
9
  "enable": true,
10
- "IsolationMode": "preSelect", // or "option"; defaults to "preSelect"
10
+ "IsolationMode": "preSelect", // "preSelect" | "option" | "single"; defaults to "preSelect"
11
11
  "scope": ["/api"] // optional; omitted = every route
12
12
  }
13
13
  ```
@@ -18,6 +18,7 @@ UUID; the header (`x-tenant-id`) and the token claim (`tenantId`) are fixed.
18
18
  | --- | --- | --- |
19
19
  | `preSelect` | the app build / client (header) | one frontend per tenant, e.g. a branded app |
20
20
  | `option` | the logged-in user | one app, user logs in then picks an organization |
21
+ | `single` | login, from the account's one mapping | one app, one account belongs to one tenant |
21
22
 
22
23
  Documents opt in with an isolation rule:
23
24
 
@@ -45,16 +46,49 @@ Emitted only when the feature is enabled; turning it off removes them on the nex
45
46
 
46
47
  | File | When | Role |
47
48
  | --- | --- | --- |
48
- | `jsonSchema/UserTenant.json` | enabled, if absent | the user ↔ tenant mapping table |
49
49
  | `_middlewares/TenantScopeContext.gen.ts` | enabled | pure decision + UUID check |
50
50
  | `_middlewares/TenantScope.gen.ts` | enabled | the middleware |
51
- | `_services/TenantService.gen.ts` | enabled | link / unlink / list |
52
- | `_controllers/TenantController.gen.ts` | `option` | `GET /tenant`, `POST /tenant/select` |
53
- | `_types/Tenant.gen.ts` | `option` | response types |
51
+ | `jsonSchema/UserTenant.json` | enabled with an auth method, if absent | the user ↔ tenant mapping table |
52
+ | `jsonSchema/Tenant.json` | enabled with an auth method, if absent | the tenant record: `_id` plus an optional `name` |
53
+ | `_services/TenantService.gen.ts` | enabled with an auth method | link / unlink / list; `singleUserTenant` in `single` |
54
+ | `_controllers/TenantController.gen.ts` | `option` / `single` (implies auth) | `POST /tenant/create`; `option` adds `GET /tenant` and `POST /tenant/select` |
55
+ | `_types/TenantList.gen.ts` | `option` | chooser response types |
56
+ | `_routes/StarterUI.gen.ts` | auth on | serves `/tenant` (create page) and links it from `/`; also `/login`, `/logout`, `/delete_account` |
54
57
 
55
58
  `Authentication.middleware` and `JWTService` contain no tenant code. The generated auth controller
56
59
  uses `TenantService` in `preSelect` mode and `JWTService.generateAccessToken(user, index, { tenantId })`
57
- in `option` mode.
60
+ in `option` and `single` mode.
61
+
62
+ `IsolationMode` is fixed at generation time, so `TenantScopeContext.gen.ts` and `TenantScope.gen.ts`
63
+ hold one mode's code only: no mode constant, no branch for a mode the build cannot be in, and no
64
+ error case that mode cannot raise. Only "does the request carry a token yet" stays a runtime branch.
65
+ The source tables are below.
66
+
67
+ | Mode | Request tenant | Header | `TenantService` | Tenant endpoints |
68
+ | --- | --- | --- | --- | --- |
69
+ | `preSelect` | header, required | the only source | only with an auth method | none |
70
+ | `option` | token claim; header for guests | guest fallback | emitted | create, list, select |
71
+ | `single` | token claim | never read | emitted, plus `singleUserTenant` | create |
72
+
73
+ ## Header-only deployment
74
+
75
+ Membership is the only part of the module that needs an account. `preSelect` with no auth method
76
+ (`auth.localAuth`, every OAuth provider and `auth.firebase` off) reads the tenant from the header
77
+ alone: it links nobody, resolves no claim, and emits no `UserTenant` document, no `TenantService`
78
+ and no account table.
79
+
80
+ The account schemas follow `app.useUserSchema`: with `false` the generator copies neither `User.json`
81
+ nor the auth-only `Session.json` / `UserAuthProfiles.json`, and no template that imports them is
82
+ emitted. With `true` the project has the built-in `User` document, as the flag says.
83
+
84
+ `auth.verifyOnly: true` is the middle ground: tokens are verified (so a caller's identity exists),
85
+ but no account is signed in, so membership artifacts stay out. See
86
+ [`docs/appGenerated/auth.md`](../appGenerated/auth.md).
87
+
88
+ `jsonSchemaDir` is the app's input, not generator state. A schema already there is never deleted or
89
+ rewritten by this feature; it is generated like any other document. Turning `app.useUserSchema` off
90
+ does not remove a `User.json` left from an earlier run — it keeps producing a `User` table until the
91
+ app deletes the file.
58
92
 
59
93
  ## `preSelect`
60
94
 
@@ -86,9 +120,59 @@ route that bypasses the middleware.
86
120
  still list and select. Custom controllers that need a selected tenant must attach
87
121
  `TenantScope.middleware` after their authentication middleware.
88
122
 
89
- ## `UserTenant`
123
+ ## `single`
124
+
125
+ One account belongs to one tenant. The mode needs `tenant.enable` and a JWT sign-in method
126
+ (`auth.localAuth` or an OAuth provider): login is where the claim is minted.
127
+
128
+ 1. `TenantScope.middleware` never reads `x-tenant-id` in this mode: a token is the only source of a
129
+ tenant. A request with no token has no tenant, so a caller cannot pick one.
130
+ 2. `Authentication.middleware` verifies the token; the generated controllers then run
131
+ `TenantScope.middleware` again and the `tenantId` claim decides. A token without the claim → `401`.
132
+ 3. Every login path — `POST /auth/token` (local and OAuth) and `POST /auth/firebase` — looks up the
133
+ account's `UserTenant` rows:
134
+
135
+ | Rows | Result |
136
+ | --- | --- |
137
+ | 1 | access and refresh tokens carry `tenantId` |
138
+ | 0 | tokens carry no claim; login still succeeds, so the app can guide the account through creating its tenant |
139
+ | more than 1 | `409` `tenant_ambiguous` — one account one tenant is the mode's promise, so extra rows are a data error |
140
+
141
+ 4. No chooser is generated: there is no `GET /tenant` and no `POST /tenant/select`.
142
+ `POST /tenant/create` exists, because an account can start without a tenant: it writes a `Tenant`
143
+ row (optional body `{ name }`), links the membership, and returns tokens carrying the claim. It
144
+ answers `409 tenant_exists` when the account already has one.
145
+ 5. Refresh keeps a claim the refresh token already carries and re-validates the mapping (removed
146
+ mapping → `401`). A token without a claim is resolved again through the same 1 / 0 / more-than-1
147
+ rule.
148
+
149
+ `POST /auth/register` does not link a tenant in this mode: the request is not a source of one. The
150
+ account creates its tenant through `POST /tenant/create` (or the app's own endpoint) and receives a
151
+ token carrying the claim; the next login or refresh mints the same claim from the mapping.
152
+
153
+ ## `Tenant` and `UserTenant`
154
+
155
+ The module owns two tables, copied into `jsonSchemaDir` on first enable.
156
+
157
+ `Tenant` is the registry: one row per tenant, `_id` is the tenant id every other table stores, and
158
+ `name` is display-only. It carries no `restApi` methods — the module writes it, the app reads it
159
+ through `TenantService`.
160
+
161
+ ```jsonc
162
+ {
163
+ "documentName": "Tenant",
164
+ "restApi": { "methods": [] },
165
+ "properties": {
166
+ "_id": { "type": "string", "x-format": "PrimaryUUID", "index": true },
167
+ "name": { "type": "string" }
168
+ }
169
+ }
170
+ ```
171
+
172
+ A tenant created before this table existed has membership rows and no `Tenant` row; nothing reads the
173
+ row during login or isolation, so those deployments keep working.
90
174
 
91
- The module owns one table, copied into `jsonSchemaDir` on first enable:
175
+ `UserTenant` is the mapping:
92
176
 
93
177
  ```jsonc
94
178
  {
@@ -107,11 +191,15 @@ An existing `UserTenant.json` is left alone, so the app can extend it.
107
191
  `TenantService`:
108
192
 
109
193
  ```ts
194
+ createTenant(name?) // writes the Tenant row; returns it
195
+ findTenant(tenantId) // the Tenant row, or null
196
+ deleteTenant(tenantId) // removes the row; memberships are the caller's to clean up
110
197
  addUserTenant(tenantId) // userId from UserContext; idempotent
111
198
  linkUserTenant(userId, tenantId) // registration / provisioning
112
199
  hasUserTenant(userId, tenantId)
113
200
  removeUserTenant(userId, tenantId)
114
201
  listUserTenants(userId?)
202
+ singleUserTenant(userId) // single mode: the one tenant, or undefined; 409 on more than one
115
203
  ```
116
204
 
117
205
  The tenant system decides where tenant ids come from (invite, billing, admin console); it only has
@@ -120,8 +208,9 @@ to call `addUserTenant` or `linkUserTenant`.
120
208
  ## Account deletion
121
209
 
122
210
  `AccountDeletionService` keeps owning deletion. With tenant isolation enabled it removes the
123
- `UserTenant` mapping instead of tombstoning the shared account; `auth.deleteAccount.deleteTables`
124
- runs in both modes. See [`accountDeletion.md`](accountDeletion.md).
211
+ `UserTenant` mapping instead of tombstoning the shared account; the `Tenant` row stays, because other
212
+ members may remain. `auth.deleteAccount.deleteTables` runs in both modes. See
213
+ [`accountDeletion.md`](accountDeletion.md).
125
214
 
126
215
  ## Joins
127
216
 
@@ -139,10 +228,10 @@ legitimate. The Mongoose adapter does not implement joins, so this applies to th
139
228
  ## Limits
140
229
 
141
230
  - The claim is a snapshot. A revoked mapping stays usable until the access token expires; `refresh`
142
- and `select` re-check the database.
231
+ re-checks the database, and so does `select` in `option` mode.
143
232
  - `preSelect` trusts the header. A caller that knows a tenant UUID can send it; use it only where the
144
233
  client build is controlled and tenant ids are not secret.
145
- - Registration links the header tenant when one is present, in both modes. An open registration
234
+ - Registration links the header tenant when one is present, in all modes. An open registration
146
235
  endpoint therefore lets a caller pick a tenant; gate registration where tenants are private.
147
236
  - Unique indexes are not rewritten. Declare tenant-scoped uniqueness explicitly, e.g.
148
237
  `"uniqueIndex": [["tenantId", "email"]]`.
@@ -150,11 +239,15 @@ legitimate. The Mongoose adapter does not implement joins, so this applies to th
150
239
 
151
240
  ## Tests
152
241
 
153
- - `test/unit/tenantScopeContext.test.ts` — decision and UUID validation.
242
+ - `test/unit/tenantScopeContext.test.ts` — decision and UUID validation for every mode.
154
243
  - `test/unit/isolation.test.ts` — rule and `UserTenant` validation.
244
+ - `test/unit/tenantSingle.test.ts` — `single` config rules, claim resolution in every login path.
155
245
  - `test/e2e/tenant.test.ts` — `option`: login → list → select → scoped CRUD → account deletion.
246
+ - `test/e2e/tenantSingle.test.ts` — `single`: login claim with one mapping, no claim with none,
247
+ `409` with several, no tenant endpoint.
156
248
  - `test/e2e/tenantHeader.test.ts` — `preSelect` with no auth module.
157
- - `test/fixtures/scenarios/sql-tenant` / `sql-tenant-header` — golden output for both modes.
158
- - `test/e2e/compile.test.ts` — `tenant-option-rbac-off`, `tenant-preSelect-auth-off`.
249
+ - `test/fixtures/scenarios/sql-tenant` / `sql-tenant-header` / `sql-tenant-single` — golden output.
250
+ - `test/e2e/compile.test.ts` — `tenant-option-rbac-off`, `tenant-preSelect-auth-off`,
251
+ `tenant-single-auth-on`.
159
252
 
160
253
  The e2e suites are opt-in: `npm run test:e2e`.