very-express 0.9.0-alpha → 0.10.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.
- package/.tmp/als-proof.mjs +15 -0
- package/.tmp/als-proof2.mjs +9 -0
- package/.tmp/gen/out/.env +41 -0
- package/.tmp/gen/out/.vex/meta.json +381 -0
- package/.tmp/gen/out/Dockerfile +20 -0
- package/.tmp/gen/out/README.md +39 -0
- package/.tmp/gen/out/package.json +51 -0
- package/.tmp/gen/out/public/css/style.css +8 -0
- package/.tmp/gen/out/public/js/deleteaccount.js +80 -0
- package/.tmp/gen/out/public/js/login.js +59 -0
- package/.tmp/gen/out/public/js/logincallback.js +19 -0
- package/.tmp/gen/out/public/js/mytokens.js +11 -0
- package/.tmp/gen/out/public/js/refreshtokens.js +23 -0
- package/.tmp/gen/out/scripts/build.js +39 -0
- package/.tmp/gen/out/scripts/oacg-fix.js +83 -0
- package/.tmp/gen/out/tsconfig.json +30 -0
- package/.tmp/gen/out/tsoa.json +32 -0
- package/.tmp/gen/schemas/Project.json +50 -0
- package/.tmp/gen/schemas/Session.json +49 -0
- package/.tmp/gen/schemas/User.json +81 -0
- package/.tmp/gen/schemas/UserAuthProfiles.json +54 -0
- package/.tmp/gen/schemas/UserRole.json +40 -0
- package/.tmp/gen/schemas/UserTenant.json +39 -0
- package/.tmp/gen/vex.config.json +39 -0
- package/.tmp/gen0/out/.env +41 -0
- package/.tmp/gen0/out/.vex/meta.json +323 -0
- package/.tmp/gen0/out/Dockerfile +20 -0
- package/.tmp/gen0/out/README.md +39 -0
- package/.tmp/gen0/out/package.json +51 -0
- package/.tmp/gen0/out/public/css/style.css +8 -0
- package/.tmp/gen0/out/public/js/deleteaccount.js +80 -0
- package/.tmp/gen0/out/public/js/login.js +59 -0
- package/.tmp/gen0/out/public/js/logincallback.js +19 -0
- package/.tmp/gen0/out/public/js/mytokens.js +11 -0
- package/.tmp/gen0/out/public/js/refreshtokens.js +23 -0
- package/.tmp/gen0/out/scripts/build.js +39 -0
- package/.tmp/gen0/out/scripts/oacg-fix.js +83 -0
- package/.tmp/gen0/out/tsconfig.json +30 -0
- package/.tmp/gen0/out/tsoa.json +32 -0
- package/.tmp/gen0/schemas/Session.json +49 -0
- package/.tmp/gen0/schemas/User.json +81 -0
- package/.tmp/gen0/schemas/UserAuthProfiles.json +54 -0
- package/.tmp/gen0/schemas/UserRole.json +38 -0
- package/.tmp/gen0/vex.config.json +32 -0
- package/.tmp/gend/out/.env +41 -0
- package/.tmp/gend/out/.vex/meta.json +317 -0
- package/.tmp/gend/out/Dockerfile +20 -0
- package/.tmp/gend/out/README.md +39 -0
- package/.tmp/gend/out/package.json +51 -0
- package/.tmp/gend/out/public/css/style.css +8 -0
- package/.tmp/gend/out/public/js/deleteaccount.js +80 -0
- package/.tmp/gend/out/public/js/login.js +59 -0
- package/.tmp/gend/out/public/js/logincallback.js +19 -0
- package/.tmp/gend/out/public/js/mytokens.js +11 -0
- package/.tmp/gend/out/public/js/refreshtokens.js +23 -0
- package/.tmp/gend/out/scripts/build.js +39 -0
- package/.tmp/gend/out/scripts/oacg-fix.js +83 -0
- package/.tmp/gend/out/tsconfig.json +30 -0
- package/.tmp/gend/out/tsoa.json +32 -0
- package/.tmp/gend/schemas/Session.json +49 -0
- package/.tmp/gend/schemas/User.json +81 -0
- package/.tmp/gend/schemas/UserAuthProfiles.json +54 -0
- package/.tmp/gend/schemas/UserContact.json +40 -0
- package/.tmp/gend/schemas/UserNote.json +27 -0
- package/.tmp/gend/vex.config.json +33 -0
- package/.tmp/genh/out/.env +41 -0
- package/.tmp/genh/out/.vex/meta.json +323 -0
- package/.tmp/genh/out/Dockerfile +20 -0
- package/.tmp/genh/out/README.md +39 -0
- package/.tmp/genh/out/package.json +51 -0
- package/.tmp/genh/out/public/css/style.css +8 -0
- package/.tmp/genh/out/public/js/deleteaccount.js +80 -0
- package/.tmp/genh/out/public/js/login.js +59 -0
- package/.tmp/genh/out/public/js/logincallback.js +19 -0
- package/.tmp/genh/out/public/js/mytokens.js +11 -0
- package/.tmp/genh/out/public/js/refreshtokens.js +23 -0
- package/.tmp/genh/out/scripts/build.js +39 -0
- package/.tmp/genh/out/scripts/oacg-fix.js +83 -0
- package/.tmp/genh/out/tsconfig.json +30 -0
- package/.tmp/genh/out/tsoa.json +32 -0
- package/.tmp/genh/schemas/Project.json +41 -0
- package/.tmp/genh/schemas/Session.json +49 -0
- package/.tmp/genh/schemas/User.json +81 -0
- package/.tmp/genh/schemas/UserAuthProfiles.json +54 -0
- package/.tmp/genh/schemas/UserTenant.json +39 -0
- package/.tmp/genh/vex.config.json +31 -0
- package/.tmp/gens/out/.env +41 -0
- package/.tmp/gens/out/.vex/meta.json +335 -0
- package/.tmp/gens/out/Dockerfile +20 -0
- package/.tmp/gens/out/README.md +39 -0
- package/.tmp/gens/out/package.json +51 -0
- package/.tmp/gens/out/public/css/style.css +8 -0
- package/.tmp/gens/out/public/js/deleteaccount.js +80 -0
- package/.tmp/gens/out/public/js/login.js +59 -0
- package/.tmp/gens/out/public/js/logincallback.js +19 -0
- package/.tmp/gens/out/public/js/mytokens.js +11 -0
- package/.tmp/gens/out/public/js/refreshtokens.js +23 -0
- package/.tmp/gens/out/scripts/build.js +39 -0
- package/.tmp/gens/out/scripts/oacg-fix.js +83 -0
- package/.tmp/gens/out/tsconfig.json +30 -0
- package/.tmp/gens/out/tsoa.json +32 -0
- package/.tmp/gens/schemas/Session.json +49 -0
- package/.tmp/gens/schemas/User.json +81 -0
- package/.tmp/gens/schemas/UserAuthProfiles.json +54 -0
- package/.tmp/gens/schemas/UserRole.json +38 -0
- package/.tmp/gens/vex.config.json +32 -0
- package/.tmp/npmtest/package.json +1 -0
- package/.tmp/ro-test +0 -0
- package/AGENTS.md +26 -12
- package/README.md +1 -0
- package/dist/index.js +1108 -1037
- package/dist/templates/_middlewares/Authentication.ts +1 -4
- package/dist/templates/_middlewares/UserContext.ts +31 -22
- package/dist/templates/_projectSettings/env +13 -12
- package/dist/templates/_projectSettings/package.json +2 -2
- package/dist/templates/_routes/FirebaseAuthUI.gen.ts +20 -0
- package/dist/templates/_routes/LoginUI.ts +293 -242
- package/dist/templates/_services/MongooseRepositoryAdapter.ts +68 -4
- package/dist/templates/_services/TypeOrmRepositoryAdapter.ts +68 -24
- package/dist/templates/_services/VexDbConnector.ts +1 -26
- package/dist/templates/_services/auth/JWTService.ts +13 -17
- package/dist/templates/_tenant/TenantScopeContext.ts +56 -0
- package/dist/templates/_types/auth.ts +19 -9
- package/dist/templates/_types/vex/VexRepository.ts +2 -2
- package/dist/templates/_utils/hash.ts +0 -16
- package/dist/templates/root/public/js/deleteaccount.js +0 -54
- package/dist/templates/tenantJsonSchema/UserTenant.json +33 -0
- package/docs/appGenerated/auth.md +84 -0
- package/docs/architecture/authAndRouting.md +1 -1
- package/docs/architecture/databaseTargets.md +18 -8
- package/docs/architecture/generatorPipeline.md +2 -1
- package/docs/features/accountDeletion.md +63 -12
- package/docs/features/auditFields.md +2 -2
- package/docs/features/dataIsolation.md +58 -31
- package/docs/features/tenantIsolation.md +138 -0
- package/docs/releaseNote/v0-10-0.md +147 -0
- package/docs/releaseNote/v0-8-5.md +98 -0
- package/docs/releaseNote/v0-9-0.md +41 -47
- package/docs/superpowers/specs/2026-09-22-usercontext-audit-enforcement-design.md +9 -9
- package/docs/vexJsonSchema.md +39 -0
- package/package.json +1 -1
- package/vex.config.json +1 -6
- package/vitest.config.ts +3 -0
- package/dist/templates/_routes/ExternalIdentityUI.gen.ts +0 -20
- package/dist/templates/root/public/js/externallogin.js +0 -133
- package/docs/features/auth.md +0 -34
- package/docs/features/externalIdentity.md +0 -163
- /package/docs/{ForeignKey.md → features/ForeignKey.md} +0 -0
- /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
|
|
@@ -49,7 +46,7 @@ class Authentication {
|
|
|
49
46
|
}
|
|
50
47
|
|
|
51
48
|
req.user = tokenData;
|
|
52
|
-
UserContext.run(tokenData, () => next());
|
|
49
|
+
UserContext.run({ tokenData }, () => next());
|
|
53
50
|
}
|
|
54
51
|
|
|
55
52
|
private toVexErr(e: unknown): VexResErr {
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
// {{headerComment}}
|
|
2
2
|
import { AsyncLocalStorage } from "async_hooks";
|
|
3
3
|
|
|
4
|
-
/** Identity-bearing claims carried from the verified access token. */
|
|
4
|
+
/** Identity-bearing claims carried from the verified access token, plus request scope. */
|
|
5
5
|
export interface UserContextData {
|
|
6
|
-
tokenData
|
|
6
|
+
tokenData?: Record<string, unknown>;
|
|
7
|
+
/** Tenant the client asked for, captured from the request header before authentication. */
|
|
8
|
+
requestedTenantId?: string;
|
|
9
|
+
/** Tenant of this request. The DB layer reads only this value. */
|
|
10
|
+
tenantId?: string;
|
|
7
11
|
}
|
|
8
12
|
|
|
9
13
|
/**
|
|
@@ -19,36 +23,41 @@ export function userIdOfToken(tokenData: Record<string, unknown> | undefined): s
|
|
|
19
23
|
|
|
20
24
|
const als = new AsyncLocalStorage<UserContextData>();
|
|
21
25
|
|
|
26
|
+
/**
|
|
27
|
+
* Request-scoped values shared by middleware layers.
|
|
28
|
+
*
|
|
29
|
+
* `run` layers a patch onto whatever the enclosing layer established, so a later
|
|
30
|
+
* middleware (authentication) does not erase what an earlier one (tenant header) set.
|
|
31
|
+
* The store is replaced, never merged in place, so concurrent requests stay isolated.
|
|
32
|
+
*/
|
|
22
33
|
class UserContext {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
* scoping a new one, and leaks into whatever runs next on the same tick.
|
|
33
|
-
*/
|
|
34
|
-
run<T>(tokenData: Record<string, unknown>, fn: () => T): T {
|
|
35
|
-
return als.run({ tokenData }, fn);
|
|
34
|
+
run<T>(patch: Partial<UserContextData>, fn: () => T): T {
|
|
35
|
+
return als.run({ ...als.getStore(), ...patch }, fn);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Merge into the store of the enclosing `run`. Throws outside a request scope. */
|
|
39
|
+
set(patch: Partial<UserContextData>): void {
|
|
40
|
+
const store = als.getStore();
|
|
41
|
+
if (!store) throw new Error("UserContext.set called outside a request scope");
|
|
42
|
+
Object.assign(store, patch);
|
|
36
43
|
}
|
|
37
44
|
|
|
38
|
-
/** Current store from the per-request async context. */
|
|
39
45
|
getStore(): UserContextData | undefined {
|
|
40
46
|
return als.getStore();
|
|
41
47
|
}
|
|
42
48
|
|
|
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
|
-
*/
|
|
49
|
+
/** Normalized identity of the authenticated caller. */
|
|
49
50
|
get userId(): string | undefined {
|
|
50
51
|
return userIdOfToken(als.getStore()?.tokenData);
|
|
51
52
|
}
|
|
53
|
+
|
|
54
|
+
get requestedTenantId(): string | undefined {
|
|
55
|
+
return als.getStore()?.requestedTenantId;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
get tenantId(): string | undefined {
|
|
59
|
+
return als.getStore()?.tenantId;
|
|
60
|
+
}
|
|
52
61
|
}
|
|
53
62
|
|
|
54
63
|
export default new UserContext();
|
|
@@ -19,18 +19,19 @@ OAUTH_GITHUB_CLIENTSECRET=
|
|
|
19
19
|
# OAUTH_APPLE_CLIENTID=
|
|
20
20
|
# OAUTH_APPLE_CLIENTSECRET=
|
|
21
21
|
|
|
22
|
-
#
|
|
23
|
-
#
|
|
24
|
-
#
|
|
25
|
-
#
|
|
26
|
-
|
|
27
|
-
#
|
|
28
|
-
#
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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 --
|
|
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": "^
|
|
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
|
+
}
|