very-express 0.8.3 → 0.9.0-alpha
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/AGENTS.md +8 -1
- package/dist/index.js +1307 -592
- package/dist/templates/_middlewares/Authentication.ts +49 -32
- package/dist/templates/_projectSettings/env +13 -0
- package/dist/templates/_projectSettings/package.json +2 -1
- package/dist/templates/_routes/ExternalIdentityUI.gen.ts +20 -0
- package/dist/templates/_routes/LoginUI.ts +434 -5
- package/dist/templates/_services/MongooseRepositoryAdapter.ts +67 -5
- package/dist/templates/_services/TypeOrmRepositoryAdapter.ts +70 -4
- package/dist/templates/_services/oauth/OAuthProfileMap.ts +27 -8
- package/dist/templates/_services/oauth/OAuthStrategyService.ts +5 -5
- package/dist/templates/_types/auth.ts +24 -1
- package/dist/templates/_types/vex/VexRepository.ts +21 -0
- package/dist/templates/jsonSchema/User.json +8 -1
- package/dist/templates/jsonSchema/UserAuthProfiles.json +13 -5
- package/dist/templates/root/public/js/deleteaccount.js +134 -0
- package/dist/templates/root/public/js/externallogin.js +133 -0
- package/docs/architecture/authAndRouting.md +8 -1
- package/docs/features/accountDeletion.md +150 -0
- package/docs/features/auditFields.md +0 -30
- package/docs/features/auth.md +34 -0
- package/docs/features/externalIdentity.md +163 -0
- package/docs/releaseNote/v0-8-4.md +131 -0
- package/docs/releaseNote/v0-9-0.md +49 -0
- package/docs/vexJsonSchema.md +11 -1
- package/package.json +1 -1
- package/vex.config.json +9 -1
- package/docs/appGenerated/auth.md +0 -23
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# v0.8.4
|
|
2
|
+
|
|
3
|
+
## Account deletion (tombstone)
|
|
4
|
+
|
|
5
|
+
Generated apps now get self-service account deletion: `POST /api/auth/delete-account` and a
|
|
6
|
+
`/delete_account` page, on by default.
|
|
7
|
+
|
|
8
|
+
The account is **soft-deleted**, not erased. The row survives so business tables can keep their
|
|
9
|
+
required foreign keys — a hard delete would orphan every `Job`, `ChatMessage` and `UserReport`
|
|
10
|
+
pointing at it — while credentials and personal data are removed.
|
|
11
|
+
|
|
12
|
+
| Step | Effect |
|
|
13
|
+
|---|---|
|
|
14
|
+
| Clear credentials | `UserAuthProfiles`, `UserRole`, `Session` rows for the user are hard-deleted |
|
|
15
|
+
| Tombstone last | `deleted: true`, `email` → NULL, `name` → `"Deleted user"`, `locale` / `profileErrors` → NULL, `active` → false |
|
|
16
|
+
|
|
17
|
+
Credentials are removed **before** the tombstone on purpose. Tombstoning first would leave the OAuth
|
|
18
|
+
path able to resolve the account through `provider` / `oauthId`, i.e. a deleted user could log back
|
|
19
|
+
into their own tombstone. Marker last also means a mid-flight failure leaves a live account that can
|
|
20
|
+
simply be retried.
|
|
21
|
+
|
|
22
|
+
`email` becomes `NULL`, never `""`: `User` declares a unique index on it, so a second deletion would
|
|
23
|
+
collide on the empty string, and the same address must be able to register a fresh account
|
|
24
|
+
immediately.
|
|
25
|
+
|
|
26
|
+
Deletion is idempotent — a repeat call changes nothing.
|
|
27
|
+
|
|
28
|
+
## Soft delete: `x-vexData: "softDelete"`
|
|
29
|
+
|
|
30
|
+
Soft delete is a general, opt-in schema feature, not a hard-coded user concept. Tag one boolean
|
|
31
|
+
property:
|
|
32
|
+
|
|
33
|
+
```jsonc
|
|
34
|
+
"deleted": { "type": "boolean", "default": false, "x-vexData": "softDelete" }
|
|
35
|
+
// and list it in the root "required" array
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
- **Not client-writable.** The marker is omitted from the generated request body (`PayloadUser`), so
|
|
39
|
+
a client cannot soft-delete, resurrect or pre-tombstone a row through the CRUD API.
|
|
40
|
+
- **Hidden by default.** The adapters add `marker IS NOT TRUE` (`$ne: true` on Mongo) to every read
|
|
41
|
+
and write filter. No call-site changes.
|
|
42
|
+
- **No new columns.** `softDelete(id, data?)` writes the marker through the normal update-phase
|
|
43
|
+
machinery, so `updatedAt` / `updatedBy` record who deleted the row and when. There is no
|
|
44
|
+
`deletedAt` / `deletedBy`.
|
|
45
|
+
- **Required + defaulted.** The marker must be `boolean`, `default: false` and `required`, producing
|
|
46
|
+
`boolean NOT NULL DEFAULT false`. A nullable marker would make the hide-filter drop every row
|
|
47
|
+
written before the column existed.
|
|
48
|
+
|
|
49
|
+
Internal callers use dedicated repository methods, never a filter key:
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
softDelete(id, data?) // write the marker + redaction in one update
|
|
53
|
+
findOneWithDeleted(filter, join, select) // skip ONLY the soft-delete term; ownership still applies
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
A soft-delete key inside `Filter<T>` was rejected deliberately: `Filter` is the shape of every HTTP
|
|
57
|
+
`filter` body, so it would have been a client-side bypass.
|
|
58
|
+
|
|
59
|
+
The hide term is **not** applied to relation loading — which is why the marker is a plain column and
|
|
60
|
+
not TypeORM's `@DeleteDateColumn`, whose relation-nulling would break retained conversations
|
|
61
|
+
rendering "Deleted user".
|
|
62
|
+
|
|
63
|
+
## Tokens of deleted accounts are rejected
|
|
64
|
+
|
|
65
|
+
`Authentication.middleware` verified the JWT signature and nothing else, so a deleted user's
|
|
66
|
+
unexpired access token kept working for the rest of its lifetime. A generated `AccountStateGuard`
|
|
67
|
+
now closes that gap.
|
|
68
|
+
|
|
69
|
+
It reads the marker **value** rather than relying on the row being hidden, so the answer holds even
|
|
70
|
+
under `app.showSoftDeleted`, where a visibility-based check would call every tombstone alive. It
|
|
71
|
+
treats a missing marker as live (`!== true`), matching the adapters.
|
|
72
|
+
|
|
73
|
+
Every other auth path was already fail-closed: refresh and the OAuth exchange look the user up
|
|
74
|
+
through a soft-filtered read, local login compares an email that is now NULL, and the OAuth callback
|
|
75
|
+
cannot re-bind because the profile rows are gone.
|
|
76
|
+
|
|
77
|
+
## Config
|
|
78
|
+
|
|
79
|
+
```jsonc
|
|
80
|
+
{
|
|
81
|
+
"app": { "showSoftDeleted": false },
|
|
82
|
+
"auth": { "deleteAccount": true }
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
- `auth.deleteAccount` — **default true** (opt-out). Also requires auth to be enabled: a deletion
|
|
87
|
+
endpoint that cannot authenticate a caller could only delete the wrong account. When false, no
|
|
88
|
+
endpoint, no service, no page.
|
|
89
|
+
- `app.showSoftDeleted` — **default false**. Lifts the adapter filter app-wide, making tombstones
|
|
90
|
+
visible and writable again. It warns on every generation run, because it is a blunt instrument: it
|
|
91
|
+
applies to every entity, including ones added later.
|
|
92
|
+
|
|
93
|
+
Both are read with `??`, so an explicit `false` is never swallowed.
|
|
94
|
+
|
|
95
|
+
## The `/delete_account` page
|
|
96
|
+
|
|
97
|
+
Served from `LoginUI` rather than as a static file — `express.static("public")` would expose
|
|
98
|
+
`public/delete_account.html` at `/delete_account.html`, not at the route a store listing points at.
|
|
99
|
+
Linked from `/`.
|
|
100
|
+
|
|
101
|
+
`LoginUIConfig.deleteAccount` is optional and defaults to true, because an app's `server.ts` is
|
|
102
|
+
generated once and is not overwritten on later runs; a required field would stop such a project from
|
|
103
|
+
compiling.
|
|
104
|
+
|
|
105
|
+
The client clears its stored tokens on success — the account is gone the moment the tombstone is
|
|
106
|
+
written, so keeping a token the server now rejects would only produce confusing 401s.
|
|
107
|
+
|
|
108
|
+
## Behaviour changes
|
|
109
|
+
|
|
110
|
+
- **Every authenticated request costs one extra indexed read** of the identity row when the identity
|
|
111
|
+
document is soft-deletable. Projects with no soft-delete marker are unaffected — the guard is
|
|
112
|
+
emitted as a no-op there.
|
|
113
|
+
- **A request carrying a soft-delete marker is rejected with `400 Invalid Request Body`**, matching
|
|
114
|
+
the existing `throw-on-extras` contract for other server-managed fields.
|
|
115
|
+
|
|
116
|
+
## After upgrading
|
|
117
|
+
|
|
118
|
+
Re-run the generator. Then:
|
|
119
|
+
|
|
120
|
+
1. **Add the column.** `useUserSchema` apps get `User.deleted` merged in automatically.
|
|
121
|
+
`SQL_SYNCHRONIZE=true` covers development; production needs
|
|
122
|
+
`ALTER TABLE "user" ADD COLUMN "deleted" boolean NOT NULL DEFAULT false`.
|
|
123
|
+
2. **Check `allowOverwrite: false`.** An app that pinned `UserModel.gen.ts` / `User.gen.ts` must add
|
|
124
|
+
the column by hand, or clear those `.vex/meta.json` entries, or the SQL column will not exist.
|
|
125
|
+
3. **Business rows and uploaded objects are the app's job.** This release covers the identity domain
|
|
126
|
+
only. Third-party identities too: vex cannot delete a Firebase account — capture the provider uid
|
|
127
|
+
*before* calling the service.
|
|
128
|
+
4. **To disable it entirely:** `"auth": { "deleteAccount": false }`.
|
|
129
|
+
|
|
130
|
+
Guides: [`docs/features/accountDeletion.md`](../features/accountDeletion.md),
|
|
131
|
+
[`docs/vexJsonSchema.md`](../vexJsonSchema.md).
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# v0.9.0
|
|
2
|
+
|
|
3
|
+
## Breaking — `UserAuthProfiles.oauthId` → `providerUserId`
|
|
4
|
+
|
|
5
|
+
- `(provider, providerUserId)` is the account-linking key, and it now has a **composite unique index**;
|
|
6
|
+
nothing enforced it before.
|
|
7
|
+
- A schema migration renames the property; one `ALTER TABLE` renames the column.
|
|
8
|
+
|
|
9
|
+
## External identity (broker SSO) — Firebase
|
|
10
|
+
|
|
11
|
+
- `POST /api/auth/external` verifies a broker ID token against the issuer's JWKS and provisions the
|
|
12
|
+
matching vex identity. **Off by default.**
|
|
13
|
+
- Every token stays vex-issued: the broker's token is consumed at that one endpoint and never stored.
|
|
14
|
+
- No broker SDK on the server, no client secret, no new dependency.
|
|
15
|
+
- The generated login page renders the broker's buttons for you — configure it in `vex.config.json`,
|
|
16
|
+
then `npm install` (the `firebase` dependency is new).
|
|
17
|
+
- **Use a Web app's config**, all four values from the same registration.
|
|
18
|
+
- Configuration, identity rules, troubleshooting: [`docs/features/externalIdentity.md`](../features/externalIdentity.md).
|
|
19
|
+
|
|
20
|
+
## `sessionCode` is single-use
|
|
21
|
+
|
|
22
|
+
- `POST /api/auth/token` now consumes the code, instead of leaving it replayable for its whole TTL.
|
|
23
|
+
|
|
24
|
+
## Login and delete pages
|
|
25
|
+
|
|
26
|
+
- The home page shows the login link for broker-only apps, which previously had none.
|
|
27
|
+
- `/delete_account` states the sign-in prerequisite and links to `/login`.
|
|
28
|
+
- `public/js/deleteaccount.js` no longer sends an empty `Bearer ` — **new projects only**, that file is
|
|
29
|
+
copied once and not overwritten.
|
|
30
|
+
- The login page's CSP now allows the hosts a broker SDK injects at runtime.
|
|
31
|
+
|
|
32
|
+
## After upgrading
|
|
33
|
+
|
|
34
|
+
1. **`npm install`** — `firebase` is a new dependency.
|
|
35
|
+
2. **Re-run the generator**, so the schema migration renames the property.
|
|
36
|
+
3. **Rename the column and add the constraint:**
|
|
37
|
+
```sql
|
|
38
|
+
ALTER TABLE "userauthprofiles" RENAME COLUMN "oauthId" TO "providerUserId";
|
|
39
|
+
ALTER TABLE "userauthprofiles" ADD CONSTRAINT "unique_provider_providerUserId"
|
|
40
|
+
UNIQUE ("provider", "providerUserId");
|
|
41
|
+
```
|
|
42
|
+
`SQL_SYNCHRONIZE=true` covers development. If the old code let two rows claim one identity, find them
|
|
43
|
+
first: `SELECT provider, "providerUserId", COUNT(*) FROM "userauthprofiles" GROUP BY 1,2 HAVING COUNT(*) > 1;`
|
|
44
|
+
4. **Update app code** that reads `oauthId`.
|
|
45
|
+
5. **Keep `package.json` at `0.9.0` or later** — the migration runner compares the migration's label with
|
|
46
|
+
`.vex/meta.json`'s last generated version, so a lower version re-runs it on every generation.
|
|
47
|
+
|
|
48
|
+
Guides: [`docs/features/externalIdentity.md`](../features/externalIdentity.md),
|
|
49
|
+
[`docs/features/accountDeletion.md`](../features/accountDeletion.md).
|
package/docs/vexJsonSchema.md
CHANGED
|
@@ -77,6 +77,16 @@ Each `.json` file defines one REST resource. Filename must match `x-documentConf
|
|
|
77
77
|
| --- | --- |
|
|
78
78
|
| `role` | Marks this field as the RBAC role field. Required for role-based access control to work. |
|
|
79
79
|
| `userId` | Marks the field that holds the identity value. Declare it **exactly once**, on the account schema (`User._id`) — every `onXXUserId` audit field is filled from it. |
|
|
80
|
+
| `softDelete` | Marks the boolean field carrying this document's soft-delete state. **At most one per document.** The repository then hides rows whose marker is set, and the field is removed from generated request bodies. Requires `{ "type": "boolean", "default": false }` and must be `required`, which yields a `boolean NOT NULL DEFAULT false` column. Full reference: [`docs/features/accountDeletion.md`](features/accountDeletion.md). |
|
|
81
|
+
|
|
82
|
+
```jsonc
|
|
83
|
+
"deleted": { "type": "boolean", "default": false, "x-vexData": "softDelete" }
|
|
84
|
+
// and list it in the root "required" array
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
A nullable marker would break the hide-filter (`marker IS NOT TRUE` drops NULL rows), so generation
|
|
88
|
+
rejects it. There is no separate `deletedAt` / `deletedBy`: the existing `updatedAt` / `updatedBy`
|
|
89
|
+
audit fields record who deleted the row and when.
|
|
80
90
|
|
|
81
91
|
---
|
|
82
92
|
|
|
@@ -105,7 +115,7 @@ Works for both `sql` and `mongo` targets. Full reference:
|
|
|
105
115
|
|
|
106
116
|
Generation fails early on a contradiction: an unknown `x-vexData` value, an `onXXUserId` field whose
|
|
107
117
|
column type differs from the tagged identity field, a mismatched timestamp keyword, a missing identity
|
|
108
|
-
field,
|
|
118
|
+
field, an audit field marked `required`, or a malformed soft-delete marker.
|
|
109
119
|
|
|
110
120
|
Declaring a keyword also removes the field from the **request body**: the generator emits
|
|
111
121
|
`export type Payload{Doc} = Omit<{Doc}, "createdAt" | … >;` into `src/system/_types/{Doc}.gen.ts` and the
|
package/package.json
CHANGED
package/vex.config.json
CHANGED
|
@@ -9,14 +9,22 @@
|
|
|
9
9
|
"useUserSchema": true,
|
|
10
10
|
"useObjectID": true,
|
|
11
11
|
"allowApiCreateUpdate_id": false,
|
|
12
|
-
"useStatefulRedisAuth": false
|
|
12
|
+
"useStatefulRedisAuth": false,
|
|
13
|
+
"showSoftDeleted": false
|
|
13
14
|
},
|
|
14
15
|
"auth": {
|
|
15
16
|
"localAuth": true,
|
|
16
17
|
"useHttpOnlyCookieToken": true,
|
|
18
|
+
"deleteAccount": true,
|
|
17
19
|
"oauthProviders": {
|
|
18
20
|
"google": false,
|
|
19
21
|
"github": false
|
|
22
|
+
},
|
|
23
|
+
"externalIdentity": {
|
|
24
|
+
"enabled": true,
|
|
25
|
+
"preset": "firebase",
|
|
26
|
+
"projectId": "renomaster-c36d6",
|
|
27
|
+
"signInMethod": "redirect"
|
|
20
28
|
}
|
|
21
29
|
},
|
|
22
30
|
"useRBAC": {
|
|
@@ -1,23 +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
|
-
- Stated
|
|
23
|
-
- not yet implement
|