@proteinjs/user 1.24.0 → 1.25.1
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/CHANGELOG.md +22 -0
- package/dist/generated/index.js +1 -1
- package/dist/generated/index.js.map +1 -1
- package/dist/src/MachineAccount.d.ts +16 -8
- package/dist/src/MachineAccount.d.ts.map +1 -1
- package/dist/src/MachineAccount.js +13 -6
- package/dist/src/MachineAccount.js.map +1 -1
- package/dist/src/routes.d.ts +7 -0
- package/dist/src/routes.d.ts.map +1 -1
- package/dist/src/routes.js +15 -0
- package/dist/src/routes.js.map +1 -1
- package/dist/src/services/SignupService.d.ts +11 -0
- package/dist/src/services/SignupService.d.ts.map +1 -1
- package/dist/src/tables/UserTable.d.ts +17 -3
- package/dist/src/tables/UserTable.d.ts.map +1 -1
- package/dist/src/tables/UserTable.js +7 -1
- package/dist/src/tables/UserTable.js.map +1 -1
- package/generated/index.ts +1 -1
- package/package.json +10 -10
- package/src/MachineAccount.ts +17 -9
- package/src/routes.ts +15 -0
- package/src/services/SignupService.ts +12 -0
- package/src/tables/UserTable.ts +19 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@proteinjs/user",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.25.1",
|
|
4
4
|
"description": "User management",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -22,17 +22,17 @@
|
|
|
22
22
|
"test": "jest --runInBand --passWithNoTests"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@proteinjs/db": "^1.
|
|
26
|
-
"@proteinjs/logger": "^1.0
|
|
27
|
-
"@proteinjs/reflection": "^1.2.
|
|
28
|
-
"@proteinjs/server-api": "^3.0
|
|
29
|
-
"@proteinjs/service": "^1.
|
|
30
|
-
"@proteinjs/user-auth": "^1.3.
|
|
25
|
+
"@proteinjs/db": "^1.59.1",
|
|
26
|
+
"@proteinjs/logger": "^1.2.0",
|
|
27
|
+
"@proteinjs/reflection": "^1.2.2",
|
|
28
|
+
"@proteinjs/server-api": "^3.6.0",
|
|
29
|
+
"@proteinjs/service": "^1.10.0",
|
|
30
|
+
"@proteinjs/user-auth": "^1.3.6",
|
|
31
31
|
"moment": "2.29.4"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@proteinjs/db-driver-knex": "^1.
|
|
35
|
-
"@proteinjs/reflection-build": "^2.
|
|
34
|
+
"@proteinjs/db-driver-knex": "^1.16.12",
|
|
35
|
+
"@proteinjs/reflection-build": "^2.1.1",
|
|
36
36
|
"@types/jest": "29.5.5",
|
|
37
37
|
"@types/node": "14.0.13",
|
|
38
38
|
"@typescript-eslint/eslint-plugin": "7.8.0",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
},
|
|
47
47
|
"main": "./dist/generated/index.js",
|
|
48
48
|
"types": "./dist/generated/index.d.ts",
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "34db6948a57d4fc9c85734247efe6e0142c2ad36"
|
|
50
50
|
}
|
package/src/MachineAccount.ts
CHANGED
|
@@ -24,14 +24,21 @@ export const getMachineAccounts = (): MachineAccount[] =>
|
|
|
24
24
|
* Extend this (server-side — declarations name real operational emails and grants) to declare a
|
|
25
25
|
* machine account into the `user` table. The boot sync inserts it on the first boot that
|
|
26
26
|
* carries the declaration, matches it by email on every boot after (an account an earlier build
|
|
27
|
-
* adopted keeps its environment's own id — rows the account filed reference it),
|
|
28
|
-
* declared fields on every boot
|
|
27
|
+
* adopted keeps its environment's own id — rows the account filed reference it), brings the
|
|
28
|
+
* declared fields to the declaration on every boot while the row is as the sync left it, and
|
|
29
29
|
* deactivates the account — sessions killed, never deleted — when the declaration is removed.
|
|
30
|
+
* The sync stamps the declared columns it writes (@proteinjs/db's authorship precedence): a
|
|
31
|
+
* declared column written at runtime since — a hand edit of the roles, say; the Roles service
|
|
32
|
+
* refuses machine targets — makes the row the product's, left exactly as it is on every boot
|
|
33
|
+
* after (never brought back, never deactivated on removal, never a failed boot) until the
|
|
34
|
+
* declaration comes to equal it, which re-adopts it. Runtime-owned columns no declaration
|
|
35
|
+
* covers (the minted credential) never move a row's authorship.
|
|
30
36
|
* Re-declaring a removed account reactivates it, even under a renamed email: the user table
|
|
31
37
|
* soft-removes (keeps rows), so the sync re-adopts the kept row by its stable declared id and
|
|
32
|
-
* re-derives its state from the declaration (id and minted credential survive
|
|
33
|
-
*
|
|
34
|
-
*
|
|
38
|
+
* re-derives its state from the declaration (id and minted credential survive) — a kept row
|
|
39
|
+
* edited since on a declared column is the product's, and the renamed declaration a divergence
|
|
40
|
+
* that loads nothing. Git history of the declaration is the machine-grant audit trail; the Roles
|
|
41
|
+
* service refuses machine targets.
|
|
35
42
|
*
|
|
36
43
|
* A declared address held by a row the sync does not own — a person who registered it, or a row
|
|
37
44
|
* made by hand — is NEVER taken over: the boot refuses the declaration (the row untouched, the
|
|
@@ -52,9 +59,10 @@ export abstract class MachineAccount implements SourceRecordLoader<User> {
|
|
|
52
59
|
/** Display name shown wherever the account's actions surface. */
|
|
53
60
|
abstract accountName: string;
|
|
54
61
|
/**
|
|
55
|
-
* The account's role grants, declared —
|
|
56
|
-
*
|
|
57
|
-
*
|
|
62
|
+
* The account's role grants, declared — brought to exactly this set on every boot while the
|
|
63
|
+
* row is as the sync left it (a runtime edit makes the row the product's: the class doc). Each
|
|
64
|
+
* must be a catalog-known role; break-glass roles are refused (a machine account holding
|
|
65
|
+
* 'admin' is unrepresentable).
|
|
58
66
|
*/
|
|
59
67
|
abstract roles: string[];
|
|
60
68
|
/**
|
|
@@ -74,7 +82,7 @@ export abstract class MachineAccount implements SourceRecordLoader<User> {
|
|
|
74
82
|
email: this.email,
|
|
75
83
|
name: this.accountName,
|
|
76
84
|
roles: [...this.roles],
|
|
77
|
-
// No mailbox ceremony for machines;
|
|
85
|
+
// No mailbox ceremony for machines; the declaration owns the flag.
|
|
78
86
|
emailVerified: true,
|
|
79
87
|
// The explicit machine marker (founder ruling 2026-09-02): the declaration IS the
|
|
80
88
|
// stamp — inserts are born with it, and existing source-loaded accounts converge on the
|
package/src/routes.ts
CHANGED
|
@@ -4,6 +4,14 @@ export const routes: { [name: string]: { path: string; method: 'get' | 'post' |
|
|
|
4
4
|
initiatePasswordReset: { path: '/user/initiate-password-reset', method: 'post' },
|
|
5
5
|
executePasswordReset: { path: '/user/execute-password-reset', method: 'post' },
|
|
6
6
|
validateResetToken: { path: '/user/validate-reset-token', method: 'get' },
|
|
7
|
+
/**
|
|
8
|
+
* Confirms an account's email address from the token in its mailed link (`?token=`), answering
|
|
9
|
+
* `{ state }` as JSON for the page that calls it (user-server src/routes/verifyEmail.ts):
|
|
10
|
+
* 'confirmed' (the address is now verified, the token spent), 'expired' (the link lapsed — ask
|
|
11
|
+
* for a new one from the account page), or 'invalid' (unknown, malformed, or already spent).
|
|
12
|
+
* The answer never names an address.
|
|
13
|
+
*/
|
|
14
|
+
verifyEmail: { path: '/user/verify-email', method: 'get' },
|
|
7
15
|
logout: { path: '/user/logout', method: 'get' },
|
|
8
16
|
};
|
|
9
17
|
|
|
@@ -27,4 +35,11 @@ export const uiRoutes = {
|
|
|
27
35
|
passwordReset: 'login/password-reset',
|
|
28
36
|
signup: 'signup',
|
|
29
37
|
},
|
|
38
|
+
account: {
|
|
39
|
+
/**
|
|
40
|
+
* The page a mailed verify-email link lands on, carrying `?token=`; it calls
|
|
41
|
+
* `routes.verifyEmail` with the token and shows the state the route answers.
|
|
42
|
+
*/
|
|
43
|
+
verifyEmail: 'account/verify-email',
|
|
44
|
+
},
|
|
30
45
|
};
|
|
@@ -16,6 +16,11 @@ export type InitializeSignupResponse = {
|
|
|
16
16
|
invite?: Omit<Invite, 'token'>;
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
+
/** Whether a verification mail went out; `false` says nothing more (already verified, or too soon). */
|
|
20
|
+
export type ResendEmailVerificationResponse = {
|
|
21
|
+
sent: boolean;
|
|
22
|
+
};
|
|
23
|
+
|
|
19
24
|
/** The signup route's request body (`routes.signup`). `email` is required if no token is provided. */
|
|
20
25
|
export type UserSignup = Pick<User, 'name' | 'password'> & {
|
|
21
26
|
email?: User['email'];
|
|
@@ -41,6 +46,13 @@ export interface SignupService extends Service {
|
|
|
41
46
|
resendInvite(email: string): Promise<SendInviteResponse>;
|
|
42
47
|
/** Deletes invite record associated with the email. */
|
|
43
48
|
revokeInvite(email: string): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Mails the signed-in account a fresh link that confirms its email address (the welcome mail's
|
|
51
|
+
* shape, through the same config): the earlier link stops working. `{ sent: false }` when the
|
|
52
|
+
* address is already verified, when a link was minted within the last few minutes, or when
|
|
53
|
+
* the mail could not be sent — the caller is the account's own page, so nothing more is said.
|
|
54
|
+
*/
|
|
55
|
+
resendEmailVerification(): Promise<ResendEmailVerificationResponse>;
|
|
44
56
|
/**
|
|
45
57
|
* Initializes signup process, validating invite configuration and token if provided.
|
|
46
58
|
* Invite configuration defaults to invite optional.
|
package/src/tables/UserTable.ts
CHANGED
|
@@ -19,8 +19,10 @@ export type UserStatus = (typeof USER_STATUSES)[number];
|
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* A mixed-ownership source-record table: rows with `isLoadedFromSource = true` are CODE-DECLARED
|
|
22
|
-
* MACHINE ACCOUNTS (see `MachineAccount`) whose declared fields are
|
|
23
|
-
* boot
|
|
22
|
+
* MACHINE ACCOUNTS (see `MachineAccount`) whose declared fields are brought to the declaration on
|
|
23
|
+
* every boot while the row is as the sync left it (a declared column written at runtime makes the
|
|
24
|
+
* row the product's — @proteinjs/db's authorship precedence); human rows (flag null/false) are
|
|
25
|
+
* structurally untouchable by the boot sync. A machine
|
|
24
26
|
* account removed from source is deactivated — never deleted — so rows it is referenced from
|
|
25
27
|
* stay intact, and re-declaring it reactivates it. Whether a row IS a machine account is the
|
|
26
28
|
* explicit `machine` column (founder ruling 2026-09-02) — `isLoadedFromSource` is the sync's
|
|
@@ -33,6 +35,14 @@ export type User = SourceRecord & {
|
|
|
33
35
|
passwordResetToken?: string | null;
|
|
34
36
|
passwordResetTokenExpiration?: Moment | null;
|
|
35
37
|
emailVerified: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* The email-verification token outstanding on an unverified account (its digest, never the
|
|
40
|
+
* token — the same posture as the reset pair) and when it lapses. Minted at a no-invite sign-up
|
|
41
|
+
* and by `SignupService.resendEmailVerification`; cleared by the verify-email route when the
|
|
42
|
+
* link is tapped. An account created from an invite never carries one.
|
|
43
|
+
*/
|
|
44
|
+
emailVerificationToken?: string | null;
|
|
45
|
+
emailVerificationTokenExpiration?: Moment | null;
|
|
36
46
|
/** Role names from the roles catalog (see `RolesCatalog`). Written ONLY by the Roles service. */
|
|
37
47
|
roles: string[];
|
|
38
48
|
/**
|
|
@@ -115,7 +125,8 @@ export class UserTable extends Table<User> {
|
|
|
115
125
|
/**
|
|
116
126
|
* Machine accounts sync by EMAIL, not id: accounts adopted from hand-made rows before
|
|
117
127
|
* declarations existed keep their env-random ids, which other rows reference (declared fields
|
|
118
|
-
*
|
|
128
|
+
* brought to the declaration while the row is as the sync left it, runtime fields like
|
|
129
|
+
* `password` untouched). A row the sync does not own under a
|
|
119
130
|
* declared email — a person's signup, a hand-made row — is never taken over: the natural key
|
|
120
131
|
* refuses the declaration (@proteinjs/db). Removal from source deactivates (the same status the
|
|
121
132
|
* staff toggle and account deletion write — the UserStatusTableWatcher kills sessions on every
|
|
@@ -140,6 +151,11 @@ export class UserTable extends Table<User> {
|
|
|
140
151
|
passwordResetToken: new StringColumn('password_reset_token', { ui: { hidden: true } }),
|
|
141
152
|
passwordResetTokenExpiration: new DateTimeColumn('password_reset_token_expiration', { ui: { hidden: true } }),
|
|
142
153
|
emailVerified: new BooleanColumn('email_verified'),
|
|
154
|
+
// The verification pair hides like the reset pair: auth-internal, server write paths only.
|
|
155
|
+
emailVerificationToken: new StringColumn('email_verification_token', { ui: { hidden: true } }),
|
|
156
|
+
emailVerificationTokenExpiration: new DateTimeColumn('email_verification_token_expiration', {
|
|
157
|
+
ui: { hidden: true },
|
|
158
|
+
}),
|
|
143
159
|
/**
|
|
144
160
|
* Typed array in the `role_list` column. The legacy comma-string `roles` column (STRING(255))
|
|
145
161
|
* is still physically present on databases that predate the cutover — Spanner cannot retype
|