very-express 0.10.3 → 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.
- package/.tmp/_body.txt +1 -0
- package/.tmp/_idx.txt +1 -0
- package/.tmp/_token.txt +1 -0
- package/.tmp/check-a/app/.vex/meta.json +216 -0
- package/.tmp/check-a/app/Dockerfile +20 -0
- package/.tmp/check-a/app/README.md +39 -0
- package/.tmp/check-a/app/public/css/style.css +8 -0
- package/.tmp/check-a/app/public/js/deleteaccount.js +80 -0
- package/.tmp/check-a/app/public/js/login.js +59 -0
- package/.tmp/check-a/app/public/js/logincallback.js +19 -0
- package/.tmp/check-a/app/public/js/mytokens.js +11 -0
- package/.tmp/check-a/app/public/js/refreshtokens.js +23 -0
- package/.tmp/check-a/app/scripts/build.js +39 -0
- package/.tmp/check-a/app/scripts/oacg-fix.js +83 -0
- package/.tmp/check-a/app/tsconfig.json +30 -0
- package/.tmp/check-a/schemas/Project.json +41 -0
- package/.tmp/check-a/schemas/Session.json +49 -0
- package/.tmp/check-a/schemas/UserAuthProfiles.json +54 -0
- package/.tmp/check-a/vex.config.json +26 -0
- package/.tmp/check-b/app/.env +41 -0
- package/.tmp/check-b/app/.vex/meta.json +219 -0
- package/.tmp/check-b/app/Dockerfile +20 -0
- package/.tmp/check-b/app/README.md +39 -0
- package/.tmp/check-b/app/package.json +51 -0
- package/.tmp/check-b/app/public/css/style.css +8 -0
- package/.tmp/check-b/app/public/js/deleteaccount.js +80 -0
- package/.tmp/check-b/app/public/js/login.js +59 -0
- package/.tmp/check-b/app/public/js/logincallback.js +19 -0
- package/.tmp/check-b/app/public/js/mytokens.js +11 -0
- package/.tmp/check-b/app/public/js/refreshtokens.js +23 -0
- package/.tmp/check-b/app/scripts/build.js +39 -0
- package/.tmp/check-b/app/scripts/oacg-fix.js +83 -0
- package/.tmp/check-b/app/tsconfig.json +30 -0
- package/.tmp/check-b/app/tsoa.json +32 -0
- package/.tmp/check-b/schemas/Project.json +41 -0
- package/.tmp/check-b/vex.config.json +30 -0
- package/.tmp/check-c/app/.env +41 -0
- package/.tmp/check-c/app/.vex/meta.json +231 -0
- package/.tmp/check-c/app/Dockerfile +20 -0
- package/.tmp/check-c/app/README.md +39 -0
- package/.tmp/check-c/app/package.json +51 -0
- package/.tmp/check-c/app/public/css/style.css +8 -0
- package/.tmp/check-c/app/public/js/deleteaccount.js +80 -0
- package/.tmp/check-c/app/public/js/login.js +59 -0
- package/.tmp/check-c/app/public/js/logincallback.js +19 -0
- package/.tmp/check-c/app/public/js/mytokens.js +11 -0
- package/.tmp/check-c/app/public/js/refreshtokens.js +23 -0
- package/.tmp/check-c/app/scripts/build.js +39 -0
- package/.tmp/check-c/app/scripts/oacg-fix.js +83 -0
- package/.tmp/check-c/app/tsconfig.json +30 -0
- package/.tmp/check-c/app/tsoa.json +32 -0
- package/.tmp/check-c/schemas/Project.json +41 -0
- package/.tmp/check-c/schemas/User.json +81 -0
- package/.tmp/check-c/vex.config.json +30 -0
- package/.tmp/demo-project/vex.config.json +43 -0
- package/.tmp/demo-project2/vex.config.json +43 -0
- package/.tmp/demo-schemas/Client.json +65 -0
- package/.tmp/demo-schemas/FnbOrder.json +33 -0
- package/.tmp/demo-schemas/Job.json +86 -0
- package/.tmp/demo-schemas/KernelEvent.json +29 -0
- package/.tmp/demo-schemas/Package.json +77 -0
- package/.tmp/demo-schemas/Session.json +49 -0
- package/.tmp/demo-schemas/Tenant.json +22 -0
- package/.tmp/demo-schemas/User.json +81 -0
- package/.tmp/demo-schemas/UserAuthProfiles.json +54 -0
- package/.tmp/demo-schemas/UserContact.json +76 -0
- package/.tmp/demo-schemas/UserRole.json +40 -0
- package/.tmp/demo-schemas/UserTenant.json +39 -0
- package/.tmp/demo-schemas2/Client.json +65 -0
- package/.tmp/demo-schemas2/FnbOrder.json +33 -0
- package/.tmp/demo-schemas2/Job.json +86 -0
- package/.tmp/demo-schemas2/KernelEvent.json +29 -0
- package/.tmp/demo-schemas2/Package.json +77 -0
- package/.tmp/demo-schemas2/Session.json +49 -0
- package/.tmp/demo-schemas2/Tenant.json +22 -0
- package/.tmp/demo-schemas2/User.json +81 -0
- package/.tmp/demo-schemas2/UserAuthProfiles.json +54 -0
- package/.tmp/demo-schemas2/UserContact.json +76 -0
- package/.tmp/demo-schemas2/UserRole.json +40 -0
- package/.tmp/demo-schemas2/UserTenant.json +39 -0
- package/.tmp/e2e-db.url +1 -0
- package/.tmp/nouser/out/.env +41 -0
- package/.tmp/nouser/out/.vex/meta.json +323 -0
- package/.tmp/nouser/out/Dockerfile +20 -0
- package/.tmp/nouser/out/README.md +39 -0
- package/.tmp/nouser/out/package.json +51 -0
- package/.tmp/nouser/out/public/css/style.css +8 -0
- package/.tmp/nouser/out/public/js/deleteaccount.js +80 -0
- package/.tmp/nouser/out/public/js/login.js +59 -0
- package/.tmp/nouser/out/public/js/logincallback.js +19 -0
- package/.tmp/nouser/out/public/js/mytokens.js +11 -0
- package/.tmp/nouser/out/public/js/refreshtokens.js +23 -0
- package/.tmp/nouser/out/scripts/build.js +39 -0
- package/.tmp/nouser/out/scripts/oacg-fix.js +83 -0
- package/.tmp/nouser/out/tsconfig.json +30 -0
- package/.tmp/nouser/out/tsoa.json +32 -0
- package/.tmp/nouser/schemas/Project.json +41 -0
- package/.tmp/nouser/schemas/Session.json +49 -0
- package/.tmp/nouser/schemas/User.json +81 -0
- package/.tmp/nouser/schemas/UserAuthProfiles.json +54 -0
- package/.tmp/nouser/schemas/UserTenant.json +39 -0
- package/.tmp/nouser/vex.config.json +34 -0
- package/.tmp/npm-test-after-fix.log +217 -0
- package/.tmp/npm-test-final.log +165 -0
- package/.tmp/npm-test-final2.log +163 -0
- package/.tmp/npm-test-recheck.log +192 -0
- package/.tmp/npm-test-update.log +164 -0
- package/.tmp/npm-test.log +166 -0
- package/.tmp/output-build-after-fix.log +8 -0
- package/.tmp/output-build-baseline.log +8 -0
- package/.tmp/output-build-canonical.log +8 -0
- package/.tmp/output-build-final2.log +8 -0
- package/.tmp/output-build-reapply.log +8 -0
- package/.tmp/output-build.log +8 -0
- package/.tmp/output.env.bak +34 -0
- package/.tmp/probe_body.txt +1 -0
- package/.tmp/provision-e2e-db.js +41 -0
- package/.tmp/retry-nodestroy.log +18 -0
- package/.tmp/retry-recovery-final2.log +8 -0
- package/.tmp/retry-recovery-reapply.log +8 -0
- package/.tmp/retry-recovery.js +38 -0
- package/.tmp/run-e2e-single.js +21 -0
- package/.tmp/run-e2e.js +18 -0
- package/.tmp/verify-noauth/app/.env +41 -0
- package/.tmp/verify-noauth/app/.vex/meta.json +333 -0
- package/.tmp/verify-noauth/app/Dockerfile +20 -0
- package/.tmp/verify-noauth/app/README.md +39 -0
- package/.tmp/verify-noauth/app/package.json +51 -0
- package/.tmp/verify-noauth/app/public/css/style.css +8 -0
- package/.tmp/verify-noauth/app/public/js/deleteaccount.js +80 -0
- package/.tmp/verify-noauth/app/public/js/login.js +59 -0
- package/.tmp/verify-noauth/app/public/js/logincallback.js +19 -0
- package/.tmp/verify-noauth/app/public/js/mytokens.js +11 -0
- package/.tmp/verify-noauth/app/public/js/refreshtokens.js +23 -0
- package/.tmp/verify-noauth/app/scripts/build.js +39 -0
- package/.tmp/verify-noauth/app/scripts/oacg-fix.js +83 -0
- package/.tmp/verify-noauth/app/tsconfig.json +30 -0
- package/.tmp/verify-noauth/app/tsoa.json +32 -0
- package/.tmp/verify-noauth/schemas/Project.json +41 -0
- package/.tmp/verify-noauth/schemas/Session.json +49 -0
- package/.tmp/verify-noauth/schemas/User.json +81 -0
- package/.tmp/verify-noauth/schemas/UserAuthProfiles.json +54 -0
- package/.tmp/verify-noauth/schemas/UserTenant.json +39 -0
- package/.tmp/verify-noauth/vex.config.json +33 -0
- package/.tmp/verify-noauth-rbac/app/.env +41 -0
- package/.tmp/verify-noauth-rbac/app/.vex/meta.json +273 -0
- package/.tmp/verify-noauth-rbac/app/Dockerfile +20 -0
- package/.tmp/verify-noauth-rbac/app/README.md +39 -0
- package/.tmp/verify-noauth-rbac/app/package.json +51 -0
- package/.tmp/verify-noauth-rbac/app/public/css/style.css +8 -0
- package/.tmp/verify-noauth-rbac/app/public/js/deleteaccount.js +80 -0
- package/.tmp/verify-noauth-rbac/app/public/js/login.js +59 -0
- package/.tmp/verify-noauth-rbac/app/public/js/logincallback.js +19 -0
- package/.tmp/verify-noauth-rbac/app/public/js/mytokens.js +11 -0
- package/.tmp/verify-noauth-rbac/app/public/js/refreshtokens.js +23 -0
- package/.tmp/verify-noauth-rbac/app/scripts/build.js +39 -0
- package/.tmp/verify-noauth-rbac/app/scripts/oacg-fix.js +83 -0
- package/.tmp/verify-noauth-rbac/app/tsconfig.json +30 -0
- package/.tmp/verify-noauth-rbac/app/tsoa.json +32 -0
- package/.tmp/verify-noauth-rbac/schemas/Project.json +41 -0
- package/.tmp/verify-noauth-rbac/schemas/User.json +81 -0
- package/.tmp/verify-noauth-rbac/schemas/UserRole.json +38 -0
- package/.tmp/verify-noauth-rbac/vex.config.json +36 -0
- package/.tmp/verify.sh +103 -0
- package/.tmp/verify2.sh +103 -0
- package/.tmp/vex-gen-after-fix.log +221 -0
- package/.tmp/vex-gen-baseline.log +221 -0
- package/.tmp/vex-gen-canonical.log +221 -0
- package/.tmp/vex-gen-final.log +220 -0
- package/.tmp/vex-gen-final2.log +221 -0
- package/.tmp/vex-gen-reapply.log +221 -0
- package/.tmp/vex-gen.log +220 -0
- package/.tmp/vex-run-after-fix.log +3 -0
- package/.tmp/vex-run-baseline.log +11 -0
- package/.tmp/vex-run-before-fix.log +11 -0
- package/.tmp/vex-run-canonical.log +3 -0
- package/.tmp/vex-run-final2.log +3 -0
- package/.tmp/vex-run.log +3 -0
- package/.tmp/vo/app/.env +41 -0
- package/.tmp/vo/app/.vex/meta.json +231 -0
- package/.tmp/vo/app/Dockerfile +20 -0
- package/.tmp/vo/app/README.md +39 -0
- package/.tmp/vo/app/package.json +51 -0
- package/.tmp/vo/app/public/css/style.css +8 -0
- package/.tmp/vo/app/public/js/deleteaccount.js +80 -0
- package/.tmp/vo/app/public/js/login.js +59 -0
- package/.tmp/vo/app/public/js/logincallback.js +19 -0
- package/.tmp/vo/app/public/js/mytokens.js +11 -0
- package/.tmp/vo/app/public/js/refreshtokens.js +23 -0
- package/.tmp/vo/app/scripts/build.js +39 -0
- package/.tmp/vo/app/scripts/oacg-fix.js +83 -0
- package/.tmp/vo/app/tsconfig.json +30 -0
- package/.tmp/vo/app/tsoa.json +32 -0
- package/.tmp/vo/schemas/Project.json +41 -0
- package/.tmp/vo/vex.config.json +33 -0
- package/.tmp/vo-bad1/app/.env +41 -0
- package/.tmp/vo-bad1/app/.vex/meta.json +237 -0
- package/.tmp/vo-bad1/app/Dockerfile +20 -0
- package/.tmp/vo-bad1/app/README.md +39 -0
- package/.tmp/vo-bad1/app/package.json +51 -0
- package/.tmp/vo-bad1/app/public/css/style.css +8 -0
- package/.tmp/vo-bad1/app/public/js/deleteaccount.js +80 -0
- package/.tmp/vo-bad1/app/public/js/login.js +59 -0
- package/.tmp/vo-bad1/app/public/js/logincallback.js +19 -0
- package/.tmp/vo-bad1/app/public/js/mytokens.js +11 -0
- package/.tmp/vo-bad1/app/public/js/refreshtokens.js +23 -0
- package/.tmp/vo-bad1/app/scripts/build.js +39 -0
- package/.tmp/vo-bad1/app/scripts/oacg-fix.js +83 -0
- package/.tmp/vo-bad1/app/tsconfig.json +30 -0
- package/.tmp/vo-bad1/app/tsoa.json +32 -0
- package/.tmp/vo-bad1/schemas/Project.json +41 -0
- package/.tmp/vo-bad1/vex.config.json +33 -0
- package/.tmp/vo-bad2/app/.env +41 -0
- package/.tmp/vo-bad2/app/.vex/meta.json +237 -0
- package/.tmp/vo-bad2/app/Dockerfile +20 -0
- package/.tmp/vo-bad2/app/README.md +39 -0
- package/.tmp/vo-bad2/app/package.json +51 -0
- package/.tmp/vo-bad2/app/public/css/style.css +8 -0
- package/.tmp/vo-bad2/app/public/js/deleteaccount.js +80 -0
- package/.tmp/vo-bad2/app/public/js/login.js +59 -0
- package/.tmp/vo-bad2/app/public/js/logincallback.js +19 -0
- package/.tmp/vo-bad2/app/public/js/mytokens.js +11 -0
- package/.tmp/vo-bad2/app/public/js/refreshtokens.js +23 -0
- package/.tmp/vo-bad2/app/scripts/build.js +39 -0
- package/.tmp/vo-bad2/app/scripts/oacg-fix.js +83 -0
- package/.tmp/vo-bad2/app/tsconfig.json +30 -0
- package/.tmp/vo-bad2/app/tsoa.json +32 -0
- package/.tmp/vo-bad2/schemas/Project.json +41 -0
- package/.tmp/vo-bad2/vex.config.json +39 -0
- package/.tmp/vo-bad3/app/.env +41 -0
- package/.tmp/vo-bad3/app/.vex/meta.json +237 -0
- package/.tmp/vo-bad3/app/Dockerfile +20 -0
- package/.tmp/vo-bad3/app/README.md +39 -0
- package/.tmp/vo-bad3/app/package.json +51 -0
- package/.tmp/vo-bad3/app/public/css/style.css +8 -0
- package/.tmp/vo-bad3/app/public/js/deleteaccount.js +80 -0
- package/.tmp/vo-bad3/app/public/js/login.js +59 -0
- package/.tmp/vo-bad3/app/public/js/logincallback.js +19 -0
- package/.tmp/vo-bad3/app/public/js/mytokens.js +11 -0
- package/.tmp/vo-bad3/app/public/js/refreshtokens.js +23 -0
- package/.tmp/vo-bad3/app/scripts/build.js +39 -0
- package/.tmp/vo-bad3/app/scripts/oacg-fix.js +83 -0
- package/.tmp/vo-bad3/app/tsconfig.json +30 -0
- package/.tmp/vo-bad3/app/tsoa.json +32 -0
- package/.tmp/vo-bad3/schemas/Project.json +41 -0
- package/.tmp/vo-bad3/vex.config.json +33 -0
- package/dist/index.js +1156 -698
- package/dist/templates/_middlewares/UserContext.ts +1 -1
- package/dist/templates/_routes/FirebaseAuthUI.gen.ts +2 -2
- package/dist/templates/_routes/{LoginUI.ts → StarterUI.ts} +122 -8
- package/dist/templates/_utils/hash.ts +9 -4
- package/dist/templates/tenantJsonSchema/Tenant.json +22 -0
- package/docs/appGenerated/auth.md +50 -0
- package/docs/architecture/databaseTargets.md +23 -2
- package/docs/architecture/templates.md +7 -0
- package/docs/features/accountDeletion.md +5 -4
- package/docs/features/auditFields.md +2 -2
- package/docs/features/tenantIsolation.md +108 -15
- package/docs/releaseNote/v0-10-4.md +102 -0
- package/docs/releaseNote/v0-11-0.md +82 -0
- package/docs/vexJsonSchema.md +33 -0
- package/package.json +1 -1
- package/vex.config.json +6 -1
- package/dist/templates/_services/VexDbConnector.ts +0 -188
- package/dist/templates/_tenant/TenantScopeContext.ts +0 -56
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# v0.10.4
|
|
2
|
+
|
|
3
|
+
## Auth templates follow the auth switch
|
|
4
|
+
|
|
5
|
+
An app with no auth method (`auth.localAuth`, every OAuth provider and `auth.firebase` off) used to
|
|
6
|
+
receive the whole auth stack anyway: `Authentication.middleware`, `JWTService`, the login page, the
|
|
7
|
+
OAuth runtime, and the `User` / `UserAuthProfiles` / `Session` schemas. None of it could run, and the
|
|
8
|
+
three schemas became tables the app never touched.
|
|
9
|
+
|
|
10
|
+
Those templates are now copied only when an auth method is on. `cleanupStaleFiles` removes them from
|
|
11
|
+
an app generated with auth on and re-generated with it off.
|
|
12
|
+
|
|
13
|
+
## `app.useUserSchema` owns the built-in `User` document
|
|
14
|
+
|
|
15
|
+
`User.json` is copied only when `app.useUserSchema` is `true` (the default). With `false` the
|
|
16
|
+
generator writes nothing:
|
|
17
|
+
|
|
18
|
+
- a `User.json` already in `jsonSchemaDir` stays untouched and is generated like any other document;
|
|
19
|
+
- a project without one emits no `User` table, no `/user` routes and no file that names
|
|
20
|
+
`UserModel`.
|
|
21
|
+
|
|
22
|
+
`app.useUserSchema` governs the template only. It never deletes or rewrites a file in
|
|
23
|
+
`jsonSchemaDir`.
|
|
24
|
+
|
|
25
|
+
## Auth and RBAC require a `User` document
|
|
26
|
+
|
|
27
|
+
Auth reads the account row through `UserModel`; `UserRole` declares a foreign key to it. A project
|
|
28
|
+
that enables either feature without a document named `User` now stops at generation time:
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
authentication needs a document named "User", and this project has none.
|
|
32
|
+
Set "app.useUserSchema" to true to generate the built-in one, or add your own User.json.
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
The check runs before foreign keys resolve, so the failure names the document instead of surfacing
|
|
36
|
+
as a relation builder error. `RBAC` is named in the message when `useRBAC` is the reason.
|
|
37
|
+
|
|
38
|
+
## `auth.verifyOnly`
|
|
39
|
+
|
|
40
|
+
New mode for a service that serves business routes and validates tokens minted by another vex app:
|
|
41
|
+
|
|
42
|
+
```jsonc
|
|
43
|
+
"auth": { "localAuth": false, "verifyOnly": true }
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
| | Sign-in app | Verify-only app |
|
|
47
|
+
| --- | --- | --- |
|
|
48
|
+
| `Authentication.gen.ts` | verifies the token, then reads the account row | verifies the token only |
|
|
49
|
+
| `JWTService.gen.ts` | mints and verifies, owns sessions | `verifyToken` only |
|
|
50
|
+
| `AuthController`, `/login`, OAuth routes | yes | no |
|
|
51
|
+
| `User`, `UserAuthProfiles`, `Session` | yes | no |
|
|
52
|
+
| `AccountStateGuard.gen.ts` | reads the identity row | constant `true` |
|
|
53
|
+
|
|
54
|
+
`JWT_SECRET0..9` and `JWT_ALGORITHM` must match the app that signs. Clients send `Authorization`
|
|
55
|
+
and `X-Auth-Index` as usual. Identity arrives as the `vexUserId` claim, so `onCreateUserId`,
|
|
56
|
+
`onUpdateUserId` and `source: "user._id"` isolation work.
|
|
57
|
+
|
|
58
|
+
Rejected combinations, each a config error that names the conflict:
|
|
59
|
+
|
|
60
|
+
| Combination | Reason |
|
|
61
|
+
| --- | --- |
|
|
62
|
+
| `verifyOnly` with a sign-in method | one app signs in, the other only verifies |
|
|
63
|
+
| `verifyOnly` with `useRBAC` | role assignments live in the local `UserRole` table |
|
|
64
|
+
| `verifyOnly` with `tenant.IsolationMode: "option"` | selecting a tenant mints a token |
|
|
65
|
+
|
|
66
|
+
Revocation is bounded by token lifetime: a verify-only app owns no account row to check.
|
|
67
|
+
|
|
68
|
+
## Tenant membership follows auth
|
|
69
|
+
|
|
70
|
+
`UserTenant`, `TenantService` and `TenantController` are emitted when the tenant module links
|
|
71
|
+
accounts, which requires an auth method. Isolation itself does not: `TenantScope`,
|
|
72
|
+
`TenantScopeContext` and every `user.tenantId` rule are emitted from `tenant.enable` alone, and work
|
|
73
|
+
with no auth and no account document.
|
|
74
|
+
|
|
75
|
+
## Generated output
|
|
76
|
+
|
|
77
|
+
| File | Change |
|
|
78
|
+
| --- | --- |
|
|
79
|
+
| `_middlewares/Authentication.gen.ts` | emitted with any auth method; verify-only variant reads no account row |
|
|
80
|
+
| `_services/auth/JWTService.gen.ts` | emitted with any auth method; verify-only variant has `verifyToken` only |
|
|
81
|
+
| `_services/auth/AccountStateGuard.gen.ts` | no-op in verify-only |
|
|
82
|
+
| `_middlewares/tsoaAuthentication.gen.ts` | unchanged |
|
|
83
|
+
| `_routes/LoginUI.gen.ts`, `_routes/oauth/*`, `_services/oauth/*`, `_types/auth.gen.ts` | emitted only with a sign-in method |
|
|
84
|
+
| `_controllers/{Document}Controller.gen.ts` | `@Security` and `Authentication.middleware` when a token is verified |
|
|
85
|
+
| `_utils/hash.gen.ts` | no longer imports the `User` type |
|
|
86
|
+
|
|
87
|
+
## Migration
|
|
88
|
+
|
|
89
|
+
1. Re-run the generator.
|
|
90
|
+
2. An app that keeps auth off and `app.useUserSchema: false` keeps any `User.json`, `Session.json`,
|
|
91
|
+
`UserAuthProfiles.json` or `UserTenant.json` already in `jsonSchemaDir`. Each one still produces a
|
|
92
|
+
document and a table; delete the unused files to drop them.
|
|
93
|
+
3. A project with auth or RBAC on and no `User.json` must set `app.useUserSchema: true` or add its
|
|
94
|
+
own schema before the first run of this version.
|
|
95
|
+
|
|
96
|
+
## Tests
|
|
97
|
+
|
|
98
|
+
New golden scenarios: `sql-tenant-header-nouser` (auth off, `useUserSchema: false`) and
|
|
99
|
+
`sql-verify-only` (verify-only with tenant `preSelect`). New unit tests: `test/unit/authDocuments.test.ts`
|
|
100
|
+
for the missing-`User` check and `test/unit/verifyOnly.test.ts` for the mode's predicates and config
|
|
101
|
+
validation. `test/e2e/compile.test.ts` adds `tenant-preSelect-auth-off-nouser` and
|
|
102
|
+
`tenant-preSelect-verify-only` to the compile matrix.
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# v0.11.0
|
|
2
|
+
|
|
3
|
+
## Changes
|
|
4
|
+
|
|
5
|
+
- Add `x-documentConfig.schema` to place one document's table in a named PostgreSQL schema.
|
|
6
|
+
- Generate `_types/SchemaName.gen.ts` with the union of the declared schemas and the same values as the runtime list `vexDbSchemas`.
|
|
7
|
+
- Create every declared schema at generated-app startup, before TypeORM synchronize builds the tables.
|
|
8
|
+
- Warn at generation time when a foreign key points at a document in another schema, and when a non-SQL target declares `schema`.
|
|
9
|
+
- Reject a `schema` value that is not a plain PostgreSQL identifier.
|
|
10
|
+
|
|
11
|
+
## Named schemas
|
|
12
|
+
|
|
13
|
+
A document puts its table in a named schema with one key:
|
|
14
|
+
|
|
15
|
+
```jsonc
|
|
16
|
+
"x-documentConfig": {
|
|
17
|
+
"documentName": "Task",
|
|
18
|
+
"schema": "kernel",
|
|
19
|
+
"methods": ["get", "getList"]
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
The entity carries both the schema and the table name:
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
@Entity({ schema: vexDbSchemas.kernel, name: "task" })
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Documents without the key stay in `public` and keep the bare decorator `@Entity("task")`.
|
|
30
|
+
|
|
31
|
+
`schema` accepts `^[A-Za-z_][A-Za-z0-9_]*$`. Generation stops on any other value: the name is
|
|
32
|
+
interpolated into `CREATE SCHEMA IF NOT EXISTS` in the generated app.
|
|
33
|
+
|
|
34
|
+
Two limits:
|
|
35
|
+
|
|
36
|
+
- Foreign keys across schemas are not supported. Generation warns when a relation resolves to a
|
|
37
|
+
document in a different schema.
|
|
38
|
+
- `dbType: "mongo"` ignores the key. Generation warns.
|
|
39
|
+
|
|
40
|
+
## Startup order
|
|
41
|
+
|
|
42
|
+
TypeORM `synchronize` creates tables but never a schema, so the generated connector creates the
|
|
43
|
+
declared schemas first:
|
|
44
|
+
|
|
45
|
+
1. connect and `initialize()` with `synchronize: false`
|
|
46
|
+
2. `CREATE SCHEMA IF NOT EXISTS` for every value in `vexDbSchemas`
|
|
47
|
+
3. `synchronize()` when `SQL_SYNCHRONIZE=true`
|
|
48
|
+
|
|
49
|
+
`public` is never created: PostgreSQL already has it. A project that declares no schema emits the
|
|
50
|
+
connector without steps 2 and 3, and synchronize keeps running inside `initialize()`.
|
|
51
|
+
|
|
52
|
+
## Generated output
|
|
53
|
+
|
|
54
|
+
| File | Change |
|
|
55
|
+
| --- | --- |
|
|
56
|
+
| `_models/{Document}Model.gen.ts` | `@Entity({ schema: vexDbSchemas.<schema>, name: "<table>" })` when the document declares one |
|
|
57
|
+
| `_types/SchemaName.gen.ts` | new; union type plus `vexDbSchemas`, written only when a document declares a schema |
|
|
58
|
+
| `_services/VexDbConnector.gen.ts` | schema creation and the explicit `synchronize()` call; emitted from a function template |
|
|
59
|
+
|
|
60
|
+
Every other generated file is unchanged, and so is the output of a project that declares no schema.
|
|
61
|
+
|
|
62
|
+
## Migration
|
|
63
|
+
|
|
64
|
+
1. Re-run the generator.
|
|
65
|
+
2. A fresh database needs nothing: the app creates the schemas at startup.
|
|
66
|
+
3. An existing database keeps the tables where they are. Adding `schema` to a document moves its
|
|
67
|
+
table, so copy the rows across before the first start with the new value:
|
|
68
|
+
|
|
69
|
+
```sql
|
|
70
|
+
CREATE SCHEMA IF NOT EXISTS "kernel";
|
|
71
|
+
ALTER TABLE "public"."task" SET SCHEMA "kernel";
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
4. Without `SQL_SYNCHRONIZE`, create the schemas yourself; the app never runs DDL in that mode.
|
|
75
|
+
|
|
76
|
+
## Tests
|
|
77
|
+
|
|
78
|
+
`npm test` covers the decorator branch, the schema list, the rejected names and the mongo warning.
|
|
79
|
+
The scenario `sql-schema-specified` pins three documents in `kernel`, `fnb` and `accounting`,
|
|
80
|
+
including the generated `SchemaName.gen.ts` and the connector that creates them.
|
|
81
|
+
|
|
82
|
+
Every other golden file is unchanged.
|
package/docs/vexJsonSchema.md
CHANGED
|
@@ -28,6 +28,7 @@ Each `.json` file defines one REST resource. Filename must match `x-documentConf
|
|
|
28
28
|
| `uniqueIndex` | `array<array<string>>` | no | Compound unique index definitions, e.g. `[["email"], ["userId","role"]]`. The SQL entity names the constraint `unique_<table>_<columns>`, so two documents may declare the same column set. |
|
|
29
29
|
| `isolation` | `array<object>` | no | Query terms the repository adds to every read and write. `{ field, source, onMissing }` — see [isolation rules](#isolation-rules). |
|
|
30
30
|
| `dataIsolation` | `object` | no | Legacy single-field form: `{ "field": "ownerId" }`. Normalized into `isolation`. |
|
|
31
|
+
| `schema` | `string` | no | PostgreSQL schema the table is created in. Defaults to `public`. SQL target only. See [named schemas](#named-schemas). |
|
|
31
32
|
|
|
32
33
|
### `methods` values
|
|
33
34
|
|
|
@@ -60,6 +61,38 @@ the request payload, stripped from caller data, and stamped from the request con
|
|
|
60
61
|
See [`docs/features/dataIsolation.md`](features/dataIsolation.md) and
|
|
61
62
|
[`docs/features/tenantIsolation.md`](features/tenantIsolation.md).
|
|
62
63
|
|
|
64
|
+
### Named schemas
|
|
65
|
+
|
|
66
|
+
`schema` places one document's table in a named PostgreSQL schema. The value is a plain
|
|
67
|
+
identifier (`^[A-Za-z_][A-Za-z0-9_]*$`); anything else stops generation.
|
|
68
|
+
|
|
69
|
+
```jsonc
|
|
70
|
+
"x-documentConfig": {
|
|
71
|
+
"documentName": "Task",
|
|
72
|
+
"schema": "kernel",
|
|
73
|
+
"methods": ["get", "getList"]
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
The generated entity carries both the schema and the table name:
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
@Entity({ schema: vexDbSchemas.kernel, name: "task" })
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Consequences:
|
|
84
|
+
|
|
85
|
+
- The generated app creates every declared schema at startup (`CREATE SCHEMA IF NOT EXISTS`) before
|
|
86
|
+
TypeORM synchronize builds tables, so a fresh database needs no manual step. `public` is never
|
|
87
|
+
created: PostgreSQL already has it.
|
|
88
|
+
- `_types/SchemaName.gen.ts` holds the union of every declared schema and the same values as the
|
|
89
|
+
runtime list `vexDbSchemas`. It is written only when at least one document declares one.
|
|
90
|
+
- A document without `schema` stays in `public`, and its entity keeps the bare table decorator
|
|
91
|
+
`@Entity("task")`.
|
|
92
|
+
- Foreign keys are not supported across schemas. Generation warns when a relation points at a
|
|
93
|
+
document in a different schema.
|
|
94
|
+
- `dbType: "mongo"` ignores the key; generation warns.
|
|
95
|
+
|
|
63
96
|
---
|
|
64
97
|
|
|
65
98
|
## Property fields
|
package/package.json
CHANGED
package/vex.config.json
CHANGED
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
"oauthProviders": {
|
|
21
21
|
"google": false,
|
|
22
22
|
"github": false
|
|
23
|
-
}
|
|
23
|
+
},
|
|
24
|
+
"verifyOnly": false
|
|
24
25
|
},
|
|
25
26
|
"useRBAC": {
|
|
26
27
|
"roles": [
|
|
@@ -30,6 +31,10 @@
|
|
|
30
31
|
],
|
|
31
32
|
"default": "admin"
|
|
32
33
|
},
|
|
34
|
+
"tenant": {
|
|
35
|
+
"enable": true,
|
|
36
|
+
"IsolationMode": "single"
|
|
37
|
+
},
|
|
33
38
|
"generator": {
|
|
34
39
|
"commitBeforeGenerate": false,
|
|
35
40
|
"disableVersionLabel": false
|
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
// {{headerComment}}
|
|
2
|
-
import { Request, Response, NextFunction } from "express";
|
|
3
|
-
import { AsyncLocalStorage } from "async_hooks";
|
|
4
|
-
import { DataSource, EntityTarget, ObjectLiteral } from "typeorm";
|
|
5
|
-
import mongoose from "mongoose";
|
|
6
|
-
import { VexRepository } from "../_types/vex";
|
|
7
|
-
import { TypeOrmRepositoryAdapter } from "./TypeOrmRepositoryAdapter.gen";
|
|
8
|
-
import utils from "./../_utils";
|
|
9
|
-
|
|
10
|
-
/** The only surface a transaction callback gets. It never exposes the TypeORM manager. */
|
|
11
|
-
export interface VexTransaction {
|
|
12
|
-
getRepository<T extends ObjectLiteral>(target: EntityTarget<T>): VexRepository<T>;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export class VexDbConnector {
|
|
16
|
-
private sqlUrl: string;
|
|
17
|
-
private sqlCa: string;
|
|
18
|
-
private mongoUrl: string;
|
|
19
|
-
private recordAccessLog: boolean = false;
|
|
20
|
-
|
|
21
|
-
private dataSource?: DataSource;
|
|
22
|
-
private transactionScope = new AsyncLocalStorage<boolean>();
|
|
23
|
-
|
|
24
|
-
constructor(options: {
|
|
25
|
-
sqlUrl?: string;
|
|
26
|
-
sqlCa?: string;
|
|
27
|
-
mongoUrl?: string;
|
|
28
|
-
recordAccessLog?: boolean;
|
|
29
|
-
}) {
|
|
30
|
-
this.sqlUrl = options.sqlUrl || "";
|
|
31
|
-
this.sqlCa = options.sqlCa || "";
|
|
32
|
-
this.mongoUrl = options.mongoUrl || "";
|
|
33
|
-
this.recordAccessLog = options.recordAccessLog || false;
|
|
34
|
-
this.middleware = this.middleware.bind(this);
|
|
35
|
-
this.transaction = this.transaction.bind(this);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Run `fn` in one database transaction. Throwing inside `fn` rolls everything back.
|
|
40
|
-
*
|
|
41
|
-
* Repositories come from the transaction's own manager, but the callback only receives
|
|
42
|
-
* `getRepository`: handing out the manager would let call sites take the raw repository and
|
|
43
|
-
* bypass isolation, audit stamping and fail-closed checks.
|
|
44
|
-
*
|
|
45
|
-
* Isolation reads `UserContext` from AsyncLocalStorage, so it applies inside the callback
|
|
46
|
-
* unchanged. Nested calls are rejected rather than silently opening a second transaction.
|
|
47
|
-
*/
|
|
48
|
-
async transaction<T>(fn: (tx: VexTransaction) => Promise<T>): Promise<T> {
|
|
49
|
-
if (!this.sqlUrl) {
|
|
50
|
-
throw new Error("VexDb.transaction is only available for the SQL target");
|
|
51
|
-
}
|
|
52
|
-
if (!this.dataSource) {
|
|
53
|
-
throw new Error("SQL DataSource not initialized");
|
|
54
|
-
}
|
|
55
|
-
if (this.transactionScope.getStore()) {
|
|
56
|
-
throw new Error("nested transaction is not supported");
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return this.dataSource.transaction((manager) => this.transactionScope.run(true, () => fn({
|
|
60
|
-
getRepository: <E extends ObjectLiteral>(target: EntityTarget<E>): VexRepository<E> =>
|
|
61
|
-
new TypeOrmRepositoryAdapter<E & ObjectLiteral>(manager.getRepository(target)),
|
|
62
|
-
})));
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
connect(): void {
|
|
66
|
-
if (this.sqlUrl) this.connectSql();
|
|
67
|
-
if (this.mongoUrl) this.connectMongo();
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
close(): void {
|
|
71
|
-
if (this.sqlUrl) this.closeSql();
|
|
72
|
-
if (this.mongoUrl) this.closeMongo();
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
connectSql(): void {
|
|
76
|
-
utils.log.infoSql("Connecting to SQL DB (TypeORM)...");
|
|
77
|
-
const sqlUrl = new URL(this.sqlUrl);
|
|
78
|
-
|
|
79
|
-
const ca = !this.sqlCa ? undefined : this.sqlCa.startsWith("-----BEGIN") ? this.sqlCa : Buffer.from(this.sqlCa, "base64").toString("utf8");
|
|
80
|
-
const insecure = (process.env.SQL_INSECURE_TLS || "").toLowerCase() === "true";
|
|
81
|
-
const sslRequired = sqlUrl.searchParams.get("sslmode") === "require";
|
|
82
|
-
const ssl = sslRequired ?
|
|
83
|
-
{
|
|
84
|
-
rejectUnauthorized: insecure ? false : true,
|
|
85
|
-
ca,
|
|
86
|
-
} :
|
|
87
|
-
undefined;
|
|
88
|
-
|
|
89
|
-
const ds = new DataSource({
|
|
90
|
-
type: "postgres",
|
|
91
|
-
host: sqlUrl.hostname,
|
|
92
|
-
port: Number(sqlUrl.port) || 5432,
|
|
93
|
-
username: sqlUrl.username,
|
|
94
|
-
password: sqlUrl.password,
|
|
95
|
-
database: sqlUrl.pathname.slice(1),
|
|
96
|
-
ssl,
|
|
97
|
-
synchronize: (process.env.SQL_SYNCHRONIZE || "").toLowerCase() === "true",
|
|
98
|
-
logging: false,
|
|
99
|
-
entities: [__dirname + "/../_models/*.gen.{ts,js}"],
|
|
100
|
-
migrations: [],
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
const connectWithRetry = (retryTime = 10): void => {
|
|
104
|
-
ds.initialize()
|
|
105
|
-
.then(() => {
|
|
106
|
-
this.dataSource = ds;
|
|
107
|
-
utils.log.infoSql("TypeORM DataSource initialized");
|
|
108
|
-
})
|
|
109
|
-
.catch((err) => {
|
|
110
|
-
utils.log.errorSql(`Failed to initialize TypeORM, retrying in ${retryTime}s`, err);
|
|
111
|
-
setTimeout(() => connectWithRetry(retryTime), retryTime * 1000);
|
|
112
|
-
});
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
connectWithRetry(10);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
closeSql(): void {
|
|
119
|
-
if (this.dataSource?.isInitialized) {
|
|
120
|
-
this.dataSource.destroy()
|
|
121
|
-
.then(() => utils.log.infoSql("TypeORM DataSource closed"))
|
|
122
|
-
.catch((err) => utils.log.errorSql("Error closing TypeORM DataSource", err));
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// TODO: complete mongoose support
|
|
127
|
-
connectMongo(): void {
|
|
128
|
-
console.warn("VeryExpress unified db adapter (MongooseRepositoryAdapter) for Mongodb are under development, use with caution. Contribute to \"https://github.com/Justin26l/VeryExpress\"");
|
|
129
|
-
utils.log.infoMongo("Connecting to MongoDB (Driver: Mongoose)...");
|
|
130
|
-
const connectWithRetry = (retryTime = 10): void => {
|
|
131
|
-
mongoose.connect(this.mongoUrl)
|
|
132
|
-
.then(() => utils.log.infoMongo("Mongoose connected"))
|
|
133
|
-
.catch((err) => {
|
|
134
|
-
utils.log.errorMongo(`Failed to connect Mongoose, retrying in ${retryTime}s`, err);
|
|
135
|
-
setTimeout(() => connectWithRetry(retryTime), retryTime * 1000);
|
|
136
|
-
});
|
|
137
|
-
};
|
|
138
|
-
connectWithRetry(10);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
closeMongo(): void {
|
|
142
|
-
console.warn("VeryExpress unified db adapter (MongooseRepositoryAdapter) for Mongodb are under development, use with caution. Contribute to \"https://github.com/Justin26l/VeryExpress\"");
|
|
143
|
-
mongoose.disconnect()
|
|
144
|
-
.then(() => utils.log.infoMongo("Mongoose disconnected"))
|
|
145
|
-
.catch((err) => utils.log.errorMongo("Error disconnecting Mongoose", err));
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
getRepository<T extends ObjectLiteral>(target: EntityTarget<T>): VexRepository<T>;
|
|
149
|
-
getRepository<T>(target: EntityTarget<ObjectLiteral> | any): VexRepository<T> {
|
|
150
|
-
if (target?.schema && target?.modelName) {
|
|
151
|
-
console.warn("VeryExpress unified db adapter (MongooseRepositoryAdapter) for Mongodb are under development, use with caution. Contribute to \"https://github.com/Justin26l/VeryExpress\"");
|
|
152
|
-
}
|
|
153
|
-
if (!this.dataSource) throw new Error("SQL DataSource not initialized");
|
|
154
|
-
return new TypeOrmRepositoryAdapter<T & ObjectLiteral>(this.dataSource.getRepository(target));
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
async middleware(req: Request, res: Response, next: NextFunction): Promise<void> {
|
|
158
|
-
try {
|
|
159
|
-
if (this.sqlUrl && (!this.dataSource || !this.dataSource.isInitialized)) {
|
|
160
|
-
utils.response.send(res, 503, { code: utils.response.code.DB_CONN_ERR });
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
if (this.recordAccessLog && this.dataSource?.isInitialized) {
|
|
165
|
-
const logEntry = {
|
|
166
|
-
timestamp: new Date().getTime(),
|
|
167
|
-
ipa: req.socket.remoteAddress || req.headers["x-forwarded-for"],
|
|
168
|
-
method: req.method,
|
|
169
|
-
url: req.url.split("?")[0],
|
|
170
|
-
headers: JSON.stringify(req.headers),
|
|
171
|
-
query: JSON.stringify(req.query),
|
|
172
|
-
};
|
|
173
|
-
try {
|
|
174
|
-
await this.dataSource.getRepository("AccessLog").save(logEntry);
|
|
175
|
-
}
|
|
176
|
-
catch { /* table may not exist */ }
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
next();
|
|
180
|
-
}
|
|
181
|
-
catch (err: unknown) {
|
|
182
|
-
utils.response.send(res, 500, { code: utils.response.code.DB_CONN_ERR });
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
export default VexDbConnector;
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
// {{headerComment}}
|
|
2
|
-
|
|
3
|
-
export type TenantIsolationMode = "preSelect" | "option";
|
|
4
|
-
|
|
5
|
-
export type TenantError =
|
|
6
|
-
| "missing-header"
|
|
7
|
-
| "invalid-tenant"
|
|
8
|
-
| "missing-claim"
|
|
9
|
-
| "invalid-claim";
|
|
10
|
-
|
|
11
|
-
export interface TenantDecision {
|
|
12
|
-
tenantId?: string;
|
|
13
|
-
error?: TenantError;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
17
|
-
|
|
18
|
-
/** Tenant ids are UUIDs everywhere: header, claim and the UserTenant table. */
|
|
19
|
-
export function isTenantId(value: unknown): value is string {
|
|
20
|
-
return typeof value === "string" && UUID_PATTERN.test(value);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Decide the tenant of a request.
|
|
25
|
-
*
|
|
26
|
-
* `preSelect` — the app build is bound to one tenant: the header is required and is the only
|
|
27
|
-
* source; a token claim is not used.
|
|
28
|
-
*
|
|
29
|
-
* `option` — the user logs in first and then selects a tenant. A token that carries the
|
|
30
|
-
* `tenantId` claim decides; a token without one is rejected. A request with no token is a
|
|
31
|
-
* guest, and the header identifies the tenant for public endpoints.
|
|
32
|
-
*
|
|
33
|
-
* `tokenData` is absent on the L0 pass because authentication has not run yet.
|
|
34
|
-
*/
|
|
35
|
-
export function resolveTenantContext(
|
|
36
|
-
mode: TenantIsolationMode,
|
|
37
|
-
tokenData: Record<string, unknown> | undefined,
|
|
38
|
-
headerTenantId: string | undefined,
|
|
39
|
-
): TenantDecision {
|
|
40
|
-
if (mode === "preSelect") {
|
|
41
|
-
if (!headerTenantId) return { error: "missing-header" };
|
|
42
|
-
if (!isTenantId(headerTenantId)) return { error: "invalid-tenant" };
|
|
43
|
-
return { tenantId: headerTenantId };
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (tokenData) {
|
|
47
|
-
const claimed = tokenData.tenantId;
|
|
48
|
-
if (claimed === undefined || claimed === "") return { error: "missing-claim" };
|
|
49
|
-
if (!isTenantId(claimed)) return { error: "invalid-claim" };
|
|
50
|
-
return { tenantId: claimed };
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (!headerTenantId) return {};
|
|
54
|
-
if (!isTenantId(headerTenantId)) return { error: "invalid-tenant" };
|
|
55
|
-
return { tenantId: headerTenantId };
|
|
56
|
-
}
|