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.
Files changed (149) hide show
  1. package/.tmp/als-proof.mjs +15 -0
  2. package/.tmp/als-proof2.mjs +9 -0
  3. package/.tmp/gen/out/.env +41 -0
  4. package/.tmp/gen/out/.vex/meta.json +381 -0
  5. package/.tmp/gen/out/Dockerfile +20 -0
  6. package/.tmp/gen/out/README.md +39 -0
  7. package/.tmp/gen/out/package.json +51 -0
  8. package/.tmp/gen/out/public/css/style.css +8 -0
  9. package/.tmp/gen/out/public/js/deleteaccount.js +80 -0
  10. package/.tmp/gen/out/public/js/login.js +59 -0
  11. package/.tmp/gen/out/public/js/logincallback.js +19 -0
  12. package/.tmp/gen/out/public/js/mytokens.js +11 -0
  13. package/.tmp/gen/out/public/js/refreshtokens.js +23 -0
  14. package/.tmp/gen/out/scripts/build.js +39 -0
  15. package/.tmp/gen/out/scripts/oacg-fix.js +83 -0
  16. package/.tmp/gen/out/tsconfig.json +30 -0
  17. package/.tmp/gen/out/tsoa.json +32 -0
  18. package/.tmp/gen/schemas/Project.json +50 -0
  19. package/.tmp/gen/schemas/Session.json +49 -0
  20. package/.tmp/gen/schemas/User.json +81 -0
  21. package/.tmp/gen/schemas/UserAuthProfiles.json +54 -0
  22. package/.tmp/gen/schemas/UserRole.json +40 -0
  23. package/.tmp/gen/schemas/UserTenant.json +39 -0
  24. package/.tmp/gen/vex.config.json +39 -0
  25. package/.tmp/gen0/out/.env +41 -0
  26. package/.tmp/gen0/out/.vex/meta.json +323 -0
  27. package/.tmp/gen0/out/Dockerfile +20 -0
  28. package/.tmp/gen0/out/README.md +39 -0
  29. package/.tmp/gen0/out/package.json +51 -0
  30. package/.tmp/gen0/out/public/css/style.css +8 -0
  31. package/.tmp/gen0/out/public/js/deleteaccount.js +80 -0
  32. package/.tmp/gen0/out/public/js/login.js +59 -0
  33. package/.tmp/gen0/out/public/js/logincallback.js +19 -0
  34. package/.tmp/gen0/out/public/js/mytokens.js +11 -0
  35. package/.tmp/gen0/out/public/js/refreshtokens.js +23 -0
  36. package/.tmp/gen0/out/scripts/build.js +39 -0
  37. package/.tmp/gen0/out/scripts/oacg-fix.js +83 -0
  38. package/.tmp/gen0/out/tsconfig.json +30 -0
  39. package/.tmp/gen0/out/tsoa.json +32 -0
  40. package/.tmp/gen0/schemas/Session.json +49 -0
  41. package/.tmp/gen0/schemas/User.json +81 -0
  42. package/.tmp/gen0/schemas/UserAuthProfiles.json +54 -0
  43. package/.tmp/gen0/schemas/UserRole.json +38 -0
  44. package/.tmp/gen0/vex.config.json +32 -0
  45. package/.tmp/gend/out/.env +41 -0
  46. package/.tmp/gend/out/.vex/meta.json +317 -0
  47. package/.tmp/gend/out/Dockerfile +20 -0
  48. package/.tmp/gend/out/README.md +39 -0
  49. package/.tmp/gend/out/package.json +51 -0
  50. package/.tmp/gend/out/public/css/style.css +8 -0
  51. package/.tmp/gend/out/public/js/deleteaccount.js +80 -0
  52. package/.tmp/gend/out/public/js/login.js +59 -0
  53. package/.tmp/gend/out/public/js/logincallback.js +19 -0
  54. package/.tmp/gend/out/public/js/mytokens.js +11 -0
  55. package/.tmp/gend/out/public/js/refreshtokens.js +23 -0
  56. package/.tmp/gend/out/scripts/build.js +39 -0
  57. package/.tmp/gend/out/scripts/oacg-fix.js +83 -0
  58. package/.tmp/gend/out/tsconfig.json +30 -0
  59. package/.tmp/gend/out/tsoa.json +32 -0
  60. package/.tmp/gend/schemas/Session.json +49 -0
  61. package/.tmp/gend/schemas/User.json +81 -0
  62. package/.tmp/gend/schemas/UserAuthProfiles.json +54 -0
  63. package/.tmp/gend/schemas/UserContact.json +40 -0
  64. package/.tmp/gend/schemas/UserNote.json +27 -0
  65. package/.tmp/gend/vex.config.json +33 -0
  66. package/.tmp/genh/out/.env +41 -0
  67. package/.tmp/genh/out/.vex/meta.json +323 -0
  68. package/.tmp/genh/out/Dockerfile +20 -0
  69. package/.tmp/genh/out/README.md +39 -0
  70. package/.tmp/genh/out/package.json +51 -0
  71. package/.tmp/genh/out/public/css/style.css +8 -0
  72. package/.tmp/genh/out/public/js/deleteaccount.js +80 -0
  73. package/.tmp/genh/out/public/js/login.js +59 -0
  74. package/.tmp/genh/out/public/js/logincallback.js +19 -0
  75. package/.tmp/genh/out/public/js/mytokens.js +11 -0
  76. package/.tmp/genh/out/public/js/refreshtokens.js +23 -0
  77. package/.tmp/genh/out/scripts/build.js +39 -0
  78. package/.tmp/genh/out/scripts/oacg-fix.js +83 -0
  79. package/.tmp/genh/out/tsconfig.json +30 -0
  80. package/.tmp/genh/out/tsoa.json +32 -0
  81. package/.tmp/genh/schemas/Project.json +41 -0
  82. package/.tmp/genh/schemas/Session.json +49 -0
  83. package/.tmp/genh/schemas/User.json +81 -0
  84. package/.tmp/genh/schemas/UserAuthProfiles.json +54 -0
  85. package/.tmp/genh/schemas/UserTenant.json +39 -0
  86. package/.tmp/genh/vex.config.json +31 -0
  87. package/.tmp/gens/out/.env +41 -0
  88. package/.tmp/gens/out/.vex/meta.json +335 -0
  89. package/.tmp/gens/out/Dockerfile +20 -0
  90. package/.tmp/gens/out/README.md +39 -0
  91. package/.tmp/gens/out/package.json +51 -0
  92. package/.tmp/gens/out/public/css/style.css +8 -0
  93. package/.tmp/gens/out/public/js/deleteaccount.js +80 -0
  94. package/.tmp/gens/out/public/js/login.js +59 -0
  95. package/.tmp/gens/out/public/js/logincallback.js +19 -0
  96. package/.tmp/gens/out/public/js/mytokens.js +11 -0
  97. package/.tmp/gens/out/public/js/refreshtokens.js +23 -0
  98. package/.tmp/gens/out/scripts/build.js +39 -0
  99. package/.tmp/gens/out/scripts/oacg-fix.js +83 -0
  100. package/.tmp/gens/out/tsconfig.json +30 -0
  101. package/.tmp/gens/out/tsoa.json +32 -0
  102. package/.tmp/gens/schemas/Session.json +49 -0
  103. package/.tmp/gens/schemas/User.json +81 -0
  104. package/.tmp/gens/schemas/UserAuthProfiles.json +54 -0
  105. package/.tmp/gens/schemas/UserRole.json +38 -0
  106. package/.tmp/gens/vex.config.json +32 -0
  107. package/.tmp/npmtest/package.json +1 -0
  108. package/.tmp/ro-test +0 -0
  109. package/AGENTS.md +26 -12
  110. package/README.md +1 -0
  111. package/dist/index.js +1108 -1037
  112. package/dist/templates/_middlewares/Authentication.ts +1 -4
  113. package/dist/templates/_middlewares/UserContext.ts +31 -22
  114. package/dist/templates/_projectSettings/env +13 -12
  115. package/dist/templates/_projectSettings/package.json +2 -2
  116. package/dist/templates/_routes/FirebaseAuthUI.gen.ts +20 -0
  117. package/dist/templates/_routes/LoginUI.ts +293 -242
  118. package/dist/templates/_services/MongooseRepositoryAdapter.ts +68 -4
  119. package/dist/templates/_services/TypeOrmRepositoryAdapter.ts +68 -24
  120. package/dist/templates/_services/VexDbConnector.ts +1 -26
  121. package/dist/templates/_services/auth/JWTService.ts +13 -17
  122. package/dist/templates/_tenant/TenantScopeContext.ts +56 -0
  123. package/dist/templates/_types/auth.ts +19 -9
  124. package/dist/templates/_types/vex/VexRepository.ts +2 -2
  125. package/dist/templates/_utils/hash.ts +0 -16
  126. package/dist/templates/root/public/js/deleteaccount.js +0 -54
  127. package/dist/templates/tenantJsonSchema/UserTenant.json +33 -0
  128. package/docs/appGenerated/auth.md +84 -0
  129. package/docs/architecture/authAndRouting.md +1 -1
  130. package/docs/architecture/databaseTargets.md +18 -8
  131. package/docs/architecture/generatorPipeline.md +2 -1
  132. package/docs/features/accountDeletion.md +63 -12
  133. package/docs/features/auditFields.md +2 -2
  134. package/docs/features/dataIsolation.md +58 -31
  135. package/docs/features/tenantIsolation.md +138 -0
  136. package/docs/releaseNote/v0-10-0.md +147 -0
  137. package/docs/releaseNote/v0-8-5.md +98 -0
  138. package/docs/releaseNote/v0-9-0.md +41 -47
  139. package/docs/superpowers/specs/2026-09-22-usercontext-audit-enforcement-design.md +9 -9
  140. package/docs/vexJsonSchema.md +39 -0
  141. package/package.json +1 -1
  142. package/vex.config.json +1 -6
  143. package/vitest.config.ts +3 -0
  144. package/dist/templates/_routes/ExternalIdentityUI.gen.ts +0 -20
  145. package/dist/templates/root/public/js/externallogin.js +0 -133
  146. package/docs/features/auth.md +0 -34
  147. package/docs/features/externalIdentity.md +0 -163
  148. /package/docs/{ForeignKey.md → features/ForeignKey.md} +0 -0
  149. /package/docs/{apiUsage.md → features/apiUsage.md} +0 -0
@@ -1,34 +0,0 @@
1
- # Auth
2
- - Stateless JWT token
3
- - **Rolling Keys**
4
- define in `.env`,
5
- named `JWT_KEY{increment}`
6
- ```bash
7
- JWT_KEY1=aaaaa
8
- JWT_KEY2=bbbbb
9
- JWT_KEY3=ccccc
10
- ```
11
- - **OAuth2**
12
- Supported Providers:
13
- - Google
14
- - Github
15
-
16
- define in `.env`,
17
- named `OAUTH_{provider}_CLIENTID` & `OAUTH_{provider}_CLIENTSECRET`
18
- ```bash
19
- OAUTH_GOOGLE_CLIENTID=xxxxx
20
- OAUTH_GOOGLE_CLIENTSECRET=xxxxx
21
- ```
22
- - **External identity (broker SSO)** — off by default
23
- - `POST /auth/external` takes an ID token from a broker (Firebase), verifies it against the
24
- issuer's JWKS, and provisions the vex identity. The broker's token is consumed there and never
25
- stored; the reply is the usual session-code redirect, so `POST /auth/token` still mints every
26
- token.
27
- - The generated login page renders the broker's buttons; the broker's SDK comes from the npm
28
- package, served same-origin.
29
- - **Prefer a broker that exposes the upstream IdP's subject — Firebase or Cognito.** Those produce
30
- `("google", <Google sub>)`, the same key the passport flow writes. A broker that cannot (Keycloak,
31
- Okta) only yields one broker-labelled row, so the UI shows the broker's name instead of the
32
- provider the user actually picked.
33
- - Config, identity layers, `signInMethod`, troubleshooting:
34
- [`docs/features/externalIdentity.md`](../features/externalIdentity.md).
@@ -1,163 +0,0 @@
1
- # External identity (broker SSO)
2
-
3
- Sign in through an external identity broker — Firebase today — while **every token in the system stays
4
- vex-issued**. Off by default.
5
-
6
- ```
7
- Browser ──(SDK sign-in)──> Broker ──(ID token)──> POST /api/auth/external ──> vex JWT
8
- │
9
- verify JWKS, map claims,
10
- find-or-create the vex identity
11
- ```
12
-
13
- The broker's token is a **credential, not a session**: presented once, consumed at that endpoint, never
14
- stored, never echoed, and accepted nowhere else. Everything downstream is the existing vex flow — the
15
- endpoint answers with a session-code redirect, and `POST /api/auth/token` mints the access/refresh pair.
16
-
17
- The server holds **no broker SDK and no client secret**: the ID token is a standard OIDC JWT, verified
18
- with the `jsonwebtoken` the app already has, against keys fetched from the issuer's JWKS and imported
19
- with `node:crypto`.
20
-
21
- ## Configuration
22
-
23
- ```json
24
- "auth": {
25
- "externalIdentity": {
26
- "enabled": true,
27
- "preset": "firebase",
28
- "projectId": "your-firebase-project"
29
- }
30
- }
31
- ```
32
-
33
- A preset names a broker. Explicit keys override it, so you can start from a preset and adjust one field.
34
- Without a preset, `issuer` and the rest must be given explicitly.
35
-
36
- | Key | Default | Meaning |
37
- |---|---|---|
38
- | `enabled` | `false` | The feature gate. Auth must also be on. |
39
- | `preset` | — | `firebase`. Unknown names fail generation loudly. |
40
- | `projectId` | — | Preset variable: supplies the issuer and the audience. |
41
- | `identityLayer` | `auto` | `auto` / `broker` / `upstream` — see below. |
42
- | `signInMethod` | `popup` | `popup` / `redirect` — see below. |
43
- | `onMissingEmail` | `reject` | `reject` refuses a login with no email; `synthesize` writes `<subject>@<provider>.invalid`. |
44
- | `issuer`, `jwksUrl`, `discovery`, `audience`, `audienceClaim`, `algorithms`, `providerLabel`, `claims` | from the preset | For a broker with no preset. |
45
-
46
- Generation fails loudly rather than emitting a half-working verifier: unknown preset, a missing preset
47
- variable, a symmetric algorithm (`HS*`, an alg-confusion risk), `providerLabel: "local"` (reserved by
48
- vex's own password path), or `identityLayer: "upstream"` on a preset that cannot reach an upstream
49
- subject.
50
-
51
- ### Env
52
-
53
- ```
54
- FIREBASE_API_KEY=
55
- FIREBASE_AUTH_DOMAIN=
56
- FIREBASE_PROJECT_ID=
57
- FIREBASE_APP_ID=
58
- ```
59
-
60
- These are the broker's **public** browser values, served to the login page by design. `storageBucket`,
61
- `messagingSenderId` and `measurementId` are for other Firebase products and are not used.
62
-
63
- **`.env` is read once, at startup.** The dev watcher reloads on changes to it, but a process started by
64
- hand needs restarting — and `dotenv` never overrides a variable that is already set in the environment,
65
- so a value exported by your shell, IDE launch config or container silently wins. The server log names
66
- what it could not resolve and says when a value is being shadowed.
67
-
68
- Copy **all four** values from one app registration. Mixing an old `apiKey` with a new `appId` is a
69
- silent failure: the request is authenticated with the key.
70
-
71
- ## The identity that gets stored
72
-
73
- `provider` and `providerUserId` always come from the **same layer**, so the stored pair can never name a
74
- namespace its id does not belong to:
75
-
76
- | Layer | `provider` | `providerUserId` |
77
- |---|---|---|
78
- | `broker` | the broker (`firebase`) | the broker's own subject |
79
- | `upstream` | the upstream IdP (`google`) | the upstream subject |
80
-
81
- `auto` picks `upstream` when the login carries one and falls back to `broker` when it does not — a
82
- Firebase password or phone sign-in has no upstream provider.
83
-
84
- **Each login writes exactly one row**: the identity used. A user who signs in with Google through
85
- Firebase gets `("google", <Google sub>)` — the same key the passport flow writes, so both paths converge
86
- on one row. A second linked provider appears after the first login with it.
87
-
88
- The row set **is** the connected-accounts UI: there is no separate display field.
89
-
90
- Reading the token is deliberately conservative. Only `email_verified` addresses may be used for
91
- account linking — without that gate, any provider that does not verify addresses becomes an
92
- account-takeover path. And the issuer is pinned in configuration, never taken from the token: a verifier
93
- that fetched the JWKS URL named by an unvalidated `iss` claim would be an SSRF gadget.
94
-
95
- ## The login page
96
-
97
- The generated page renders one button per configured provider. The **preset** supplies the vendor
98
- parts — SDK location, provider list, public env names, a browser init snippet — so nothing here names a
99
- vendor and nothing needs editing in `server.ts`:
100
-
101
- | Supplied by | What |
102
- |---|---|
103
- | the preset, emitted into `ExternalIdentityUI.gen.ts` | the SDK, the provider list, the init snippet |
104
- | vex, in `LoginUI.gen.ts` | the buttons, the nonce'd script tags, the config carrier, and the glue that posts the ID token to `/api/auth/external` |
105
-
106
- **The SDK comes from npm, not a CDN.** `firebase` is a dependency, and the page loads it through a
107
- same-origin route (`/js/firebase/…`) whose file names are an allowlist. The version is npm's business,
108
- no CDN host needs a CSP allowance, and the page works offline. The route reads `node_modules` at request
109
- time because generation happens before `npm install` — run `npm install` after upgrading, or the login
110
- page reports the SDK as not installed.
111
-
112
- ### popup or redirect
113
-
114
- `popup` is the default and is what Google recommends on browsers that block third-party storage access —
115
- the pending sign-in state stays in the page's own first-party storage.
116
-
117
- `redirect` navigates the whole page. Reach for it when a popup is blocked, not to dodge the storage
118
- policy: redirect has its own form of that failure, which is why Google documents
119
- [best practices for `signInWithRedirect` on browsers that block third-party storage
120
- access](https://firebase.google.com/docs/auth/web/redirect-best-practices). Its remedy is to serve the
121
- broker's sign-in helper from your own domain; vex does not generate that proxy.
122
-
123
- ## When sign-in fails
124
-
125
- The page expands the broker error codes that carry a meaning — `auth/unauthorized-domain` (add this
126
- origin under Authentication → Settings → Authorized domains), `auth/operation-not-allowed` (enable the
127
- provider under Authentication → Sign-in method), `auth/popup-blocked`, and so on — in the alert and in
128
- the server log.
129
-
130
- `auth/internal-error` names no cause by design. Its message points at the usual ones: a restricted API
131
- key (Google Cloud console → APIs & Services → Credentials: the key must allow this origin under HTTP
132
- referrers), an extension blocking `firebaseapp.com` / `apis.google.com`, or blocked third-party cookies.
133
- For those, a request failing with `net::ERR_BLOCKED_BY_CLIENT` was never sent at all — an extension
134
- blocked it.
135
-
136
- A `GET /__/firebase/init.json 404` in the broker's own console output is expected: `/__/firebase/…` is a
137
- Hosting reserved URL, and an API-only project has no Hosting site. The handler falls back to the
138
- configuration in its own redirect URL.
139
-
140
- ### Works in a private window, fails in the normal profile
141
-
142
- That combination means the configuration is right and the profile is interfering — check it before
143
- touching any Firebase setting:
144
-
145
- 1. **An extension.** Private windows disable them. Look for `net::ERR_BLOCKED_BY_CLIENT`; then disable
146
- all extensions and add them back one at a time.
147
- 2. **Stale auth state for the origin.** The SDK caches sign-in and pending-redirect state in the origin's
148
- `IndexedDB` (`firebaseLocalStorageDb`), keyed by API key. After changing the key, or after a string of
149
- failed attempts, it can be inconsistent. Clear site data for the app origin and for
150
- `<project>.firebaseapp.com`.
151
- 3. **A profile-level cookie setting**, or an enterprise policy with a URL blocklist.
152
-
153
- ## Firebase: which values are used, and where
154
-
155
- | Console section | Used? |
156
- |---|---|
157
- | SDK setup → npm | no bundler here, but the SDK *package* is used — see the login page section |
158
- | SDK setup → CDN | no |
159
- | SDK setup → 配置 (the `firebaseConfig` object) | **yes** — `apiKey`, `authDomain`, `projectId`, `appId` |
160
-
161
- Also enable the providers you want (Authentication → Sign-in method) and keep your app's origin in the
162
- authorized domains list. The app's config must come from a **Web** app registration; a mobile `appId`
163
- (`…:android:…` / `…:ios:…`) is detected and reported rather than left to a network trace.
File without changes
File without changes