very-express 0.9.0-alpha → 0.9.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 (31) hide show
  1. package/AGENTS.md +24 -10
  2. package/dist/index.js +747 -969
  3. package/dist/templates/_middlewares/Authentication.ts +0 -3
  4. package/dist/templates/_middlewares/UserContext.ts +1 -18
  5. package/dist/templates/_projectSettings/env +13 -12
  6. package/dist/templates/_projectSettings/package.json +2 -2
  7. package/dist/templates/_routes/FirebaseAuthUI.gen.ts +20 -0
  8. package/dist/templates/_routes/LoginUI.ts +293 -242
  9. package/dist/templates/_services/TypeOrmRepositoryAdapter.ts +0 -6
  10. package/dist/templates/_services/VexDbConnector.ts +1 -26
  11. package/dist/templates/_services/auth/JWTService.ts +0 -15
  12. package/dist/templates/_types/auth.ts +12 -8
  13. package/dist/templates/_utils/hash.ts +0 -16
  14. package/dist/templates/root/public/js/deleteaccount.js +0 -54
  15. package/docs/appGenerated/auth.md +84 -0
  16. package/docs/architecture/authAndRouting.md +1 -1
  17. package/docs/architecture/databaseTargets.md +4 -2
  18. package/docs/features/accountDeletion.md +2 -3
  19. package/docs/features/auditFields.md +2 -2
  20. package/docs/releaseNote/v0-8-5.md +98 -0
  21. package/docs/releaseNote/v0-9-0.md +41 -47
  22. package/docs/superpowers/specs/2026-09-22-usercontext-audit-enforcement-design.md +9 -9
  23. package/docs/vexJsonSchema.md +17 -0
  24. package/package.json +1 -1
  25. package/vex.config.json +1 -6
  26. package/dist/templates/_routes/ExternalIdentityUI.gen.ts +0 -20
  27. package/dist/templates/root/public/js/externallogin.js +0 -133
  28. package/docs/features/auth.md +0 -34
  29. package/docs/features/externalIdentity.md +0 -163
  30. /package/docs/{ForeignKey.md → features/ForeignKey.md} +0 -0
  31. /package/docs/{apiUsage.md → features/apiUsage.md} +0 -0
@@ -25,8 +25,6 @@ class Authentication {
25
25
  };
26
26
 
27
27
  private async handle(req: Request, next: NextFunction): Promise<void> {
28
- // gate keeper
29
- // log.info("Authentication.middleware", req.headers["x-auth-index"], req.headers.authorization);
30
28
  const token = req.headers.authorization?.split(" ")[1];
31
29
  const accessTokenIndex = req.headers["x-auth-index"]?.toString();
32
30
 
@@ -38,7 +36,6 @@ class Authentication {
38
36
  throw 401;
39
37
  }
40
38
 
41
- // verify token
42
39
  const tokenData = this.JWTService.verifyToken(token, accessTokenIndex);
43
40
 
44
41
  // The signature only proves the token was issued; it says nothing about the account still
@@ -20,32 +20,15 @@ export function userIdOfToken(tokenData: Record<string, unknown> | undefined): s
20
20
  const als = new AsyncLocalStorage<UserContextData>();
21
21
 
22
22
  class UserContext {
23
- /**
24
- * Enter the per-request identity context.
25
- *
26
- * Called ONLY by Authentication.middleware, after token verification succeeded — at
27
- * that point a verified token always exists, so this runs unconditionally. The store
28
- * is the request's context; whether it carries a usable identity is decided when it
29
- * is read (`userId`), not when it is created.
30
- *
31
- * Never use `enterWith()`: it mutates the current execution context instead of
32
- * scoping a new one, and leaks into whatever runs next on the same tick.
33
- */
34
23
  run<T>(tokenData: Record<string, unknown>, fn: () => T): T {
35
24
  return als.run({ tokenData }, fn);
36
25
  }
37
26
 
38
- /** Current store from the per-request async context. */
39
27
  getStore(): UserContextData | undefined {
40
28
  return als.getStore();
41
29
  }
42
30
 
43
- /**
44
- * Normalized identity of the authenticated caller.
45
- *
46
- * The data layer MUST read the identity through this accessor and never inspect the
47
- * token shape itself — that keeps the token → identity mapping in exactly one place.
48
- */
31
+ /** Normalized identity of the authenticated caller. */
49
32
  get userId(): string | undefined {
50
33
  return userIdOfToken(als.getStore()?.tokenData);
51
34
  }
@@ -19,18 +19,19 @@ OAUTH_GITHUB_CLIENTSECRET=
19
19
  # OAUTH_APPLE_CLIENTID=
20
20
  # OAUTH_APPLE_CLIENTSECRET=
21
21
 
22
- # EXTERNAL IDENTITY (broker SSO) — see auth.externalIdentity in vex.config.json
23
- # These are the broker's *public* browser config values: they are served to the login page by design,
24
- # and are not secrets. There is no client secret here — the ID token is verified against the issuer's
25
- # published JWKS, so the backend holds no broker credential at all.
26
- # NOTE: .env is read once at process start; the dev watcher reloads on changes to this file. But
27
- # dotenv never overrides a variable that is ALREADY set in the environment — if a name here is also
28
- # exported by your shell, IDE launch config or container, that value wins and this file is ignored for
29
- # it. The server logs which values it could not resolve, and says when one is being shadowed.
30
- FIREBASE_API_KEY=
31
- FIREBASE_AUTH_DOMAIN=
32
- FIREBASE_PROJECT_ID=
33
- FIREBASE_APP_ID=
22
+ # FIREBASE (auth.firebase in vex.config.json) — see docs/appGenerated/auth.md
23
+ # Server credential: firebase-admin verifies ID tokens, so the project's service account is required.
24
+ # The JSON itself, as one value — generate it in the Firebase console:
25
+ # Project settings > Service accounts > Generate new private key.
26
+ FIREBASE_SERVICE_ACCOUNT_JSON=
27
+ # Browser config: Firebase's *public* web app values, served to the login page by design. There is no
28
+ # secret among them, and no appId — Firebase Auth does not read one.
29
+ FIREBASE_WEB_API_KEY=
30
+ FIREBASE_WEB_AUTH_DOMAIN=
31
+ FIREBASE_WEB_PROJECT_ID=
32
+ # Optional: which sign-in methods the login page renders a button for, comma separated. Defaults to
33
+ # google. The server accepts any provider it knows regardless of this list.
34
+ # FIREBASE_PROVIDERS=google
34
35
 
35
36
  # JWT token
36
37
  ACCESS_TOKEN_EXPIRE_TIME='1h'
@@ -3,7 +3,7 @@
3
3
  "scripts": {
4
4
  "build": "npm run openapi && tsc -p . && node scripts/build.js",
5
5
  "start": "node dist/server.js",
6
- "dev": "nodemon --watch src --watch .env --ext ts,env --ignore src/system/_routes/tsoa_routes.ts --ignore src/openapi/ --exec \"tsoa spec-and-routes && ts-node src/server.ts\"",
6
+ "dev": "nodemon --watch src --ext ts --ignore src/system/_routes/tsoa_routes.ts --ignore src/openapi/ --exec \"tsoa spec-and-routes && ts-node src/server.ts\"",
7
7
  "openapi": "tsoa spec-and-routes",
8
8
  "docker-build": "docker build -t very-express .",
9
9
  "docker-start": "docker run -p 3000:3000 very-express"
@@ -13,7 +13,7 @@
13
13
  "cookie-parser": "^1.4.6",
14
14
  "dotenv": "^16.4.4",
15
15
  "express": "^4.18.2",
16
- "firebase": "^12.19.0",
16
+ "firebase-admin": "^14.1.0",
17
17
  "helmet": "^7.1.0",
18
18
  "js-yaml": "^4.1.0",
19
19
  "jsonwebtoken": "^9.0.2",
@@ -0,0 +1,20 @@
1
+ // {{headerComment}}
2
+ import type { FirebaseAuthUI } from "./LoginUI.gen";
3
+
4
+ /**
5
+ * Test/compile-time stand-in for the generated login-page wiring.
6
+ *
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
9
+ * unconditional import resolves in this repo — that import has to be unconditional, because the
10
+ * generated default is how the configuration reaches the login page without editing the app-owned
11
+ * `server.ts`.
12
+ *
13
+ * `let` plus a setter rather than a `const`, so the unit tests can vary what the generator "emitted".
14
+ * The generated version is a plain `const`; nothing in the app calls the setter.
15
+ */
16
+ export let firebaseAuthUI: FirebaseAuthUI | undefined = undefined;
17
+
18
+ export function setFirebaseAuthUI(ui: FirebaseAuthUI | undefined): void {
19
+ firebaseAuthUI = ui;
20
+ }