@proteinjs/user 1.8.0 → 1.9.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/CHANGELOG.md +14 -0
- package/dist/generated/index.d.ts.map +1 -1
- package/dist/generated/index.js +7 -1
- package/dist/generated/index.js.map +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/src/MachineAccount.d.ts +47 -0
- package/dist/src/MachineAccount.d.ts.map +1 -0
- package/dist/src/MachineAccount.js +100 -0
- package/dist/src/MachineAccount.js.map +1 -0
- package/dist/src/ScopedRecord.d.ts +8 -0
- package/dist/src/ScopedRecord.d.ts.map +1 -1
- package/dist/src/ScopedRecord.js +5 -1
- package/dist/src/ScopedRecord.js.map +1 -1
- package/dist/src/services/AccountDeletionService.d.ts +27 -0
- package/dist/src/services/AccountDeletionService.d.ts.map +1 -0
- package/dist/src/services/AccountDeletionService.js +6 -0
- package/dist/src/services/AccountDeletionService.js.map +1 -0
- package/dist/src/services/MachineCredentialsService.d.ts +38 -0
- package/dist/src/services/MachineCredentialsService.d.ts.map +1 -0
- package/dist/src/services/MachineCredentialsService.js +6 -0
- package/dist/src/services/MachineCredentialsService.js.map +1 -0
- package/dist/src/services/SetUserStatusService.d.ts +15 -0
- package/dist/src/services/SetUserStatusService.d.ts.map +1 -0
- package/dist/src/services/SetUserStatusService.js +6 -0
- package/dist/src/services/SetUserStatusService.js.map +1 -0
- package/dist/src/tables/AccountDeletionTable.d.ts +85 -0
- package/dist/src/tables/AccountDeletionTable.d.ts.map +1 -0
- package/dist/src/tables/AccountDeletionTable.js +62 -0
- package/dist/src/tables/AccountDeletionTable.js.map +1 -0
- package/dist/src/tables/SessionTable.d.ts +1 -1
- package/dist/src/tables/UserStatusEventTable.d.ts +30 -0
- package/dist/src/tables/UserStatusEventTable.d.ts.map +1 -0
- package/dist/src/tables/UserStatusEventTable.js +43 -0
- package/dist/src/tables/UserStatusEventTable.js.map +1 -0
- package/dist/src/tables/UserTable.d.ts +36 -2
- package/dist/src/tables/UserTable.d.ts.map +1 -1
- package/dist/src/tables/UserTable.js +73 -4
- package/dist/src/tables/UserTable.js.map +1 -1
- package/dist/src/tables/tables.d.ts +4 -0
- package/dist/src/tables/tables.d.ts.map +1 -1
- package/dist/src/tables/tables.js +4 -0
- package/dist/src/tables/tables.js.map +1 -1
- package/dist/test/tablesAuth.test.js +20 -4
- package/dist/test/tablesAuth.test.js.map +1 -1
- package/generated/index.ts +7 -1
- package/index.ts +6 -0
- package/package.json +4 -4
- package/src/MachineAccount.ts +103 -0
- package/src/ScopedRecord.ts +11 -0
- package/src/services/AccountDeletionService.ts +28 -0
- package/src/services/MachineCredentialsService.ts +43 -0
- package/src/services/SetUserStatusService.ts +16 -0
- package/src/tables/AccountDeletionTable.ts +98 -0
- package/src/tables/UserStatusEventTable.ts +34 -0
- package/src/tables/UserTable.ts +57 -6
- package/src/tables/tables.ts +4 -0
- package/test/tablesAuth.test.ts +22 -4
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Service, serviceFactory } from '@proteinjs/service';
|
|
2
|
+
import { Moment } from 'moment';
|
|
3
|
+
|
|
4
|
+
export const getAccountDeletionService = serviceFactory<AccountDeletionService>(
|
|
5
|
+
'@proteinjs/user/AccountDeletionService'
|
|
6
|
+
);
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* In-app account deletion, archive-then-purge: the synchronous call deactivates the account
|
|
10
|
+
* ("gone right away" — shares revoked both directions, sessions killed), and the background
|
|
11
|
+
* purge walker erases everything after the grace window. Logging back in during grace cancels
|
|
12
|
+
* (full restore, including shares — the login route runs the cancel hook, not this service).
|
|
13
|
+
*
|
|
14
|
+
* Acts ONLY on the session user — no target parameter, so the only authz surface beyond the
|
|
15
|
+
* door is the password re-auth inside the call. Door: any authenticated user (`allUsers`,
|
|
16
|
+
* declared on the implementation's serviceMetadata).
|
|
17
|
+
*/
|
|
18
|
+
export interface AccountDeletionService extends Service {
|
|
19
|
+
/**
|
|
20
|
+
* Deactivate the session user's account and schedule the purge. Idempotent: a re-call after a
|
|
21
|
+
* partial failure resumes from the stored deletion manifest (never re-enumerates). The
|
|
22
|
+
* caller's sessions are killed last — the response is the last authenticated exchange.
|
|
23
|
+
*
|
|
24
|
+
* @param password re-auth — must match the session user's password
|
|
25
|
+
* @returns the purge date, for the UI's confirmation copy
|
|
26
|
+
*/
|
|
27
|
+
requestDeletion(password: string): Promise<{ purgeAfter: Moment }>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Service, serviceFactory } from '@proteinjs/service';
|
|
2
|
+
|
|
3
|
+
export const getMachineCredentialsService = serviceFactory<MachineCredentialsService>(
|
|
4
|
+
'@proteinjs/user/MachineCredentialsService'
|
|
5
|
+
);
|
|
6
|
+
|
|
7
|
+
/** The one-time view of a minted machine credential — the plaintext is never stored. */
|
|
8
|
+
export type MintedMachineCredential = {
|
|
9
|
+
/** The machine account the credential was minted for. */
|
|
10
|
+
email: string;
|
|
11
|
+
/** The generated password — shown exactly ONCE; only its hash is stored. */
|
|
12
|
+
password: string;
|
|
13
|
+
/** The Secret Manager secret the declaration names as the credential's home. */
|
|
14
|
+
secretName: string;
|
|
15
|
+
/** Operator instruction: where to paste the plaintext and what activates it. */
|
|
16
|
+
note: string;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/** A declared machine account joined with its row state — the admin surface renders these. */
|
|
20
|
+
export type MachineAccountView = {
|
|
21
|
+
email: string;
|
|
22
|
+
accountName: string;
|
|
23
|
+
roles: string[];
|
|
24
|
+
secretName: string;
|
|
25
|
+
/** 'pending first boot' until the boot sync has created/adopted the row. */
|
|
26
|
+
status: 'active' | 'deactivated' | 'pending first boot';
|
|
27
|
+
/** Whether a credential has ever been minted/provisioned (hash present on the row). */
|
|
28
|
+
hasCredential: boolean;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Credential minting for code-declared machine accounts (`MachineAccount`): identity and grants
|
|
33
|
+
* live in source; the credential is the ONLY runtime-provisioned piece. Minting generates a
|
|
34
|
+
* strong random password, stores its hash on the account row (no human-chosen passwords), kills
|
|
35
|
+
* the account's sessions, and returns the plaintext once for pasting into the declaration's
|
|
36
|
+
* Secret Manager secret. The same call rotates. Machine rows only — human credentials go
|
|
37
|
+
* through the password-reset flow.
|
|
38
|
+
*/
|
|
39
|
+
export interface MachineCredentialsService extends Service {
|
|
40
|
+
/** Every declared machine account with its row state, for the admin surface. */
|
|
41
|
+
listMachineAccounts(): Promise<MachineAccountView[]>;
|
|
42
|
+
mintCredential(email: string): Promise<MintedMachineCredential>;
|
|
43
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Service, serviceFactory } from '@proteinjs/service';
|
|
2
|
+
import { UserStatus } from '../tables/UserTable';
|
|
3
|
+
|
|
4
|
+
export const getSetUserStatusService = serviceFactory<SetUserStatusService>('@proteinjs/user/SetUserStatusService');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The ONE write path for a user's account standing. The `user.status` column is
|
|
8
|
+
* service-protected (generic record writes cannot touch it); every change lands here and writes
|
|
9
|
+
* a `user_status_event` audit row (actor, target, status; `created` is the timestamp).
|
|
10
|
+
* Admin-only: deactivation locks the target out of the product (login refused, live sessions
|
|
11
|
+
* stop resolving), so the door is the break-glass role, not a mapped permission.
|
|
12
|
+
*/
|
|
13
|
+
export interface SetUserStatusService extends Service {
|
|
14
|
+
/** Set a user's standing. Already in that standing: no change, no audit row. */
|
|
15
|
+
setUserStatus(userId: string, status: UserStatus): Promise<void>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DateTimeColumn,
|
|
3
|
+
IntegerColumn,
|
|
4
|
+
ObjectColumn,
|
|
5
|
+
StringColumn,
|
|
6
|
+
Table,
|
|
7
|
+
Record,
|
|
8
|
+
withRecordColumns,
|
|
9
|
+
} from '@proteinjs/db';
|
|
10
|
+
import { Moment } from 'moment';
|
|
11
|
+
import { USER_PERMISSIONS } from '../permissions';
|
|
12
|
+
import { AccessGrant } from './AccessGrantTable';
|
|
13
|
+
|
|
14
|
+
/** Purge-machine phases. `grace` = cancelable window; `restoring` = a cancel-by-login claimed the
|
|
15
|
+
* row; `purging` = the walker claimed it; `purged` = rows erased, completion email pending. */
|
|
16
|
+
export const ACCOUNT_DELETION_PHASES = ['grace', 'restoring', 'purging', 'purged'] as const;
|
|
17
|
+
export type AccountDeletionPhase = (typeof ACCOUNT_DELETION_PHASES)[number];
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A revoked `access_grant` row serialized verbatim into the deletion manifest. The stored `id`
|
|
21
|
+
* lets revocation delete precisely and resume idempotently; cancel re-inserts WITHOUT ids
|
|
22
|
+
* (fresh rows), matched by `(principal, resource, accessLevel)`.
|
|
23
|
+
*/
|
|
24
|
+
export type ManifestGrant = {
|
|
25
|
+
/** id of the revoked access_grant row */
|
|
26
|
+
id: string;
|
|
27
|
+
/** user id (the grant's principal) */
|
|
28
|
+
principal: string;
|
|
29
|
+
/** resource id (the grant's resource) */
|
|
30
|
+
resource: string;
|
|
31
|
+
resourceTable?: string;
|
|
32
|
+
accessLevel: AccessGrant['accessLevel'];
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* One row per in-flight account deletion: the deletion manifest plus the purge machine's own
|
|
37
|
+
* state. Deliberately a plain `Record`, NOT scoped — it must survive the purge walker's scope
|
|
38
|
+
* sweep and outlive the `user` row (the completion email sends after the user is gone).
|
|
39
|
+
*/
|
|
40
|
+
export interface AccountDeletion extends Record {
|
|
41
|
+
/** unique — one in-flight deletion per account */
|
|
42
|
+
userId: string;
|
|
43
|
+
/** Completion-email addressee after the user row is gone; login-cancel lookup key. */
|
|
44
|
+
userEmail: string;
|
|
45
|
+
phase: AccountDeletionPhase;
|
|
46
|
+
/** Write-once copy of `user.purgeAfter` (same logical step; this row is the machine's own stamp). */
|
|
47
|
+
purgeAfter: Moment;
|
|
48
|
+
/**
|
|
49
|
+
* Revoked grants, BOTH directions (inbound: my non-owner grants on others' content; outbound:
|
|
50
|
+
* others' grants on my content), verbatim. Persisted BEFORE any mutation — after a partial
|
|
51
|
+
* revocation the live grants under-count, so resume must never re-enumerate.
|
|
52
|
+
*/
|
|
53
|
+
manifestGrants: ManifestGrant[];
|
|
54
|
+
/**
|
|
55
|
+
* Owner-grant resource ids snapshotted at deactivation — the purge walker's thought-domain id
|
|
56
|
+
* source. LOAD-BEARING: ThoughtAccessGrantCleanupTableWatcher deletes a thought's grants the
|
|
57
|
+
* moment its row dies, so live re-enumeration after a mid-tree crash would strand orphan
|
|
58
|
+
* children forever.
|
|
59
|
+
*/
|
|
60
|
+
ownedResourceIds: string[];
|
|
61
|
+
/** CAS token (RoutineTicker.tickSeq pattern), bumped on every claim. */
|
|
62
|
+
leaseSeq: number;
|
|
63
|
+
ownerNodeId?: string | null;
|
|
64
|
+
/** JS-compared (Spanner timestamp-condition house rule). */
|
|
65
|
+
heartbeatAt?: Moment | null;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Locked like `SessionTable`: readable behind the 'users' permission, and NO write doors — rows
|
|
70
|
+
* are system-written only (the deletion service and the purge walker ride system paths, which
|
|
71
|
+
* bypass TableAuth). The manifest holds cross-user grant data, so even break-glass admin gets
|
|
72
|
+
* no generic write surface.
|
|
73
|
+
*/
|
|
74
|
+
export class AccountDeletionTable extends Table<AccountDeletion> {
|
|
75
|
+
name = 'account_deletion';
|
|
76
|
+
auth: Table<AccountDeletion>['auth'] = {
|
|
77
|
+
db: {
|
|
78
|
+
query: { permission: USER_PERMISSIONS.users },
|
|
79
|
+
},
|
|
80
|
+
service: {
|
|
81
|
+
query: { permission: USER_PERMISSIONS.users },
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
indexes = [
|
|
85
|
+
{ name: 'idx_account_deletion_user_id_unique', columns: ['userId'] as (keyof AccountDeletion)[], unique: true },
|
|
86
|
+
];
|
|
87
|
+
columns = withRecordColumns<AccountDeletion>({
|
|
88
|
+
userId: new StringColumn('user_id', {}, 36),
|
|
89
|
+
userEmail: new StringColumn('user_email', {}, 250),
|
|
90
|
+
phase: new StringColumn<AccountDeletionPhase>('phase', {}, 16),
|
|
91
|
+
purgeAfter: new DateTimeColumn('purge_after'),
|
|
92
|
+
manifestGrants: new ObjectColumn<ManifestGrant[]>('manifest_grants'),
|
|
93
|
+
ownedResourceIds: new ObjectColumn<string[]>('owned_resource_ids'),
|
|
94
|
+
leaseSeq: new IntegerColumn('lease_seq'),
|
|
95
|
+
ownerNodeId: new StringColumn('owner_node_id'),
|
|
96
|
+
heartbeatAt: new DateTimeColumn('heartbeat_at'),
|
|
97
|
+
});
|
|
98
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { StringColumn, Table, Record, withRecordColumns } from '@proteinjs/db';
|
|
2
|
+
import { UserStatus } from './UserTable';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Audit row written by the SetUserStatus service for EVERY status change. The base `created`
|
|
6
|
+
* column is the change timestamp. Rows are append-only: readable by admins (the same scope as
|
|
7
|
+
* the service that writes them), written only by the service's system path — no generic door
|
|
8
|
+
* grants writes, so the trail cannot be edited from the record surfaces.
|
|
9
|
+
*/
|
|
10
|
+
export type UserStatusEvent = Record & {
|
|
11
|
+
/** id of the user who made the change */
|
|
12
|
+
actor: string;
|
|
13
|
+
/** id of the user whose status changed */
|
|
14
|
+
target: string;
|
|
15
|
+
/** the standing the target was set to */
|
|
16
|
+
status: UserStatus;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export class UserStatusEventTable extends Table<UserStatusEvent> {
|
|
20
|
+
name = 'user_status_event';
|
|
21
|
+
auth: Table<UserStatusEvent>['auth'] = {
|
|
22
|
+
db: {
|
|
23
|
+
query: ['admin'],
|
|
24
|
+
},
|
|
25
|
+
service: {
|
|
26
|
+
query: ['admin'],
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
columns = withRecordColumns<UserStatusEvent>({
|
|
30
|
+
actor: new StringColumn('actor', {}, 36),
|
|
31
|
+
target: new StringColumn('target', {}, 36),
|
|
32
|
+
status: new StringColumn<UserStatus>('status', {}, 16),
|
|
33
|
+
});
|
|
34
|
+
}
|
package/src/tables/UserTable.ts
CHANGED
|
@@ -4,14 +4,25 @@ import {
|
|
|
4
4
|
StringColumn,
|
|
5
5
|
PasswordColumn,
|
|
6
6
|
Table,
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
SourceRecord,
|
|
8
|
+
withSourceRecordColumns,
|
|
9
9
|
DateTimeColumn,
|
|
10
10
|
} from '@proteinjs/db';
|
|
11
11
|
import { Moment } from 'moment';
|
|
12
12
|
import { USER_PERMISSIONS } from '../permissions';
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
/** Account standings. The vocabulary is owned here; every status write flows through the SetUserStatus service. */
|
|
15
|
+
export const USER_STATUSES = ['active', 'deactivated'] as const;
|
|
16
|
+
export type UserStatus = (typeof USER_STATUSES)[number];
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* A mixed-ownership source-record table: rows with `isLoadedFromSource = true` are CODE-DECLARED
|
|
20
|
+
* MACHINE ACCOUNTS (see `MachineAccount`) whose declared fields are reverted to source on every
|
|
21
|
+
* boot; human rows (flag null/false) are structurally untouchable by the boot sync. A machine
|
|
22
|
+
* account removed from source is deactivated — never deleted — so rows it is referenced from
|
|
23
|
+
* stay intact, and re-declaring it reactivates it.
|
|
24
|
+
*/
|
|
25
|
+
export type User = SourceRecord & {
|
|
15
26
|
name: string;
|
|
16
27
|
email: string;
|
|
17
28
|
password: string;
|
|
@@ -31,6 +42,17 @@ export type User = Record & {
|
|
|
31
42
|
* @proteinjs/db-file depends on @proteinjs/user, so a user→file reference would be circular.
|
|
32
43
|
*/
|
|
33
44
|
avatarFileId?: string | null;
|
|
45
|
+
/**
|
|
46
|
+
* Account standing. Written ONLY by the SetUserStatus service (audited per change). New rows
|
|
47
|
+
* default to 'active'; rows predating the column read null, which every gate treats as active —
|
|
48
|
+
* only an explicit 'deactivated' is refused (authentication and session resolution both gate on
|
|
49
|
+
* it in @proteinjs/user-server).
|
|
50
|
+
*/
|
|
51
|
+
status?: UserStatus | null;
|
|
52
|
+
/** When the user asked for their account to be deleted. Written by the account-deletion flow only. */
|
|
53
|
+
deleteRequestedAt?: Moment | null;
|
|
54
|
+
/** When the grace window ends and the purge walker may erase the account. Written by the account-deletion flow only. */
|
|
55
|
+
purgeAfter?: Moment | null;
|
|
34
56
|
};
|
|
35
57
|
|
|
36
58
|
export class UserTable extends Table<User> {
|
|
@@ -56,11 +78,37 @@ export class UserTable extends Table<User> {
|
|
|
56
78
|
update: { permission: USER_PERMISSIONS.users },
|
|
57
79
|
delete: { permission: USER_PERMISSIONS.users },
|
|
58
80
|
},
|
|
59
|
-
|
|
81
|
+
/**
|
|
82
|
+
* `roles` is written only by the Roles service; `status` only by the SetUserStatus service
|
|
83
|
+
* (both audited per change — a generic RPC write would let the stored state diverge from its
|
|
84
|
+
* audit trail). `deleteRequestedAt`/`purgeAfter` drive the account purge machinery and are
|
|
85
|
+
* written only by the server-side deletion flow — never through the generic RPC path.
|
|
86
|
+
* `isLoadedFromSource` is machine-account ownership — written only by the boot sync; an RPC
|
|
87
|
+
* write could hand a human row to source ownership (or unhook a machine row from it).
|
|
88
|
+
*/
|
|
89
|
+
serviceProtectedColumns: ['roles', 'status', 'deleteRequestedAt', 'purgeAfter', 'isLoadedFromSource'],
|
|
60
90
|
};
|
|
61
|
-
|
|
91
|
+
/**
|
|
92
|
+
* Machine accounts sync by EMAIL, not id: existing envs hold hand-made machine rows with
|
|
93
|
+
* env-random ids that other rows reference — the boot sync adopts them in place (id kept,
|
|
94
|
+
* declared fields reverted, runtime fields like `password` untouched). Removal from source
|
|
95
|
+
* deactivates (the same status the staff toggle and account deletion write — the
|
|
96
|
+
* UserStatusTableWatcher kills sessions on every deactivation write); re-declaring
|
|
97
|
+
* reactivates via normal drift reversion.
|
|
98
|
+
*/
|
|
99
|
+
sourceRecordOptions: Table<User>['sourceRecordOptions'] = {
|
|
100
|
+
naturalKey: 'email',
|
|
101
|
+
onSourceRemoved: { update: { status: 'deactivated' } },
|
|
102
|
+
};
|
|
103
|
+
columns = withSourceRecordColumns<User>({
|
|
62
104
|
name: new StringColumn('name'),
|
|
63
|
-
|
|
105
|
+
/**
|
|
106
|
+
* Unique — codifying the invariant authenticate/Signup always assumed (lowercased +
|
|
107
|
+
* existence-checked). Also the machine-account natural key: adoption requires unambiguous
|
|
108
|
+
* matching. The schema sync's duplicate preflight names offending values if a deployed env
|
|
109
|
+
* somehow holds dupes when the index first lands.
|
|
110
|
+
*/
|
|
111
|
+
email: new StringColumn('email', { unique: { unique: true, indexName: 'user_email_unique' } }, 250),
|
|
64
112
|
password: new PasswordColumn('password'),
|
|
65
113
|
passwordResetToken: new StringColumn('password_reset_token'),
|
|
66
114
|
passwordResetTokenExpiration: new DateTimeColumn('password_reset_token_expiration'),
|
|
@@ -74,5 +122,8 @@ export class UserTable extends Table<User> {
|
|
|
74
122
|
invitedBy: new StringColumn('invited_by'),
|
|
75
123
|
avatarEmoji: new StringColumn('avatar_emoji'),
|
|
76
124
|
avatarFileId: new StringColumn('avatar_file_id'),
|
|
125
|
+
status: new StringColumn<UserStatus>('status', { defaultValue: async () => 'active' }, 16),
|
|
126
|
+
deleteRequestedAt: new DateTimeColumn('delete_requested_at'),
|
|
127
|
+
purgeAfter: new DateTimeColumn('purge_after'),
|
|
77
128
|
});
|
|
78
129
|
}
|
package/src/tables/tables.ts
CHANGED
|
@@ -2,15 +2,19 @@ import { AccessGrant, AccessGrantTable } from './AccessGrantTable';
|
|
|
2
2
|
import { UserTable, User } from './UserTable';
|
|
3
3
|
import { SessionTable, Session } from './SessionTable';
|
|
4
4
|
import { Table } from '@proteinjs/db';
|
|
5
|
+
import { AccountDeletion, AccountDeletionTable } from './AccountDeletionTable';
|
|
5
6
|
import { Invite, InviteTable } from './InviteTable';
|
|
6
7
|
import { AccessInvite, AccessInviteTable } from './AccessInviteTable';
|
|
7
8
|
import { RoleGrantEvent, RoleGrantEventTable } from './RoleGrantEventTable';
|
|
9
|
+
import { UserStatusEvent, UserStatusEventTable } from './UserStatusEventTable';
|
|
8
10
|
|
|
9
11
|
export const tables = {
|
|
10
12
|
AccessGrant: new AccessGrantTable() as Table<AccessGrant>,
|
|
11
13
|
AccessInvite: new AccessInviteTable() as Table<AccessInvite>,
|
|
14
|
+
AccountDeletion: new AccountDeletionTable() as Table<AccountDeletion>,
|
|
12
15
|
Invite: new InviteTable() as Table<Invite>,
|
|
13
16
|
RoleGrantEvent: new RoleGrantEventTable() as Table<RoleGrantEvent>,
|
|
14
17
|
User: new UserTable() as Table<User>,
|
|
18
|
+
UserStatusEvent: new UserStatusEventTable() as Table<UserStatusEvent>,
|
|
15
19
|
Session: new SessionTable() as Table<Session>,
|
|
16
20
|
};
|
package/test/tablesAuth.test.ts
CHANGED
|
@@ -4,10 +4,13 @@ import { USER_PERMISSIONS } from '../src/permissions';
|
|
|
4
4
|
/**
|
|
5
5
|
* The users/roles split lives in these table schemas — invariants worth pinning so a drive-by
|
|
6
6
|
* edit cannot silently reopen a door:
|
|
7
|
-
* - user: 'users' permission covers viewing/managing records, EXCEPT roles
|
|
8
|
-
* service-protected (single write
|
|
7
|
+
* - user: 'users' permission covers viewing/managing records, EXCEPT roles and status — those
|
|
8
|
+
* columns are service-protected (single write paths: the Roles and SetUserStatus services),
|
|
9
|
+
* and the deletion-machinery datetimes are written only by the server-side deletion flow.
|
|
9
10
|
* - role_grant_event: the audit trail is readable by 'roles' holders and has NO generic write
|
|
10
11
|
* door — an explicit auth block with no write grants is a lock, not an admin default.
|
|
12
|
+
* - user_status_event: the standing audit trail is admin-read (the same scope as the
|
|
13
|
+
* SetUserStatus service that writes it) with NO generic write door.
|
|
11
14
|
* - session: 'sessions' holders read (a different trust than 'users' — rows carry auth
|
|
12
15
|
* material); writes are system-written, so there is NO generic write door.
|
|
13
16
|
* - invite: 'users' holders read and delete; creating rides SignupService only.
|
|
@@ -34,8 +37,16 @@ describe('user table auth shape', () => {
|
|
|
34
37
|
});
|
|
35
38
|
});
|
|
36
39
|
|
|
37
|
-
it(
|
|
38
|
-
|
|
40
|
+
it(`service-protects roles and status (single write paths: the Roles and SetUserStatus
|
|
41
|
+
services), the deletion-machinery datetimes (written only by the server-side
|
|
42
|
+
deletion flow), and machine-account ownership (written only by the boot sync)`, () => {
|
|
43
|
+
expect(tables.User.auth?.serviceProtectedColumns).toEqual([
|
|
44
|
+
'roles',
|
|
45
|
+
'status',
|
|
46
|
+
'deleteRequestedAt',
|
|
47
|
+
'purgeAfter',
|
|
48
|
+
'isLoadedFromSource',
|
|
49
|
+
]);
|
|
39
50
|
});
|
|
40
51
|
});
|
|
41
52
|
|
|
@@ -46,6 +57,13 @@ describe('role_grant_event table auth shape', () => {
|
|
|
46
57
|
});
|
|
47
58
|
});
|
|
48
59
|
|
|
60
|
+
describe('user_status_event table auth shape', () => {
|
|
61
|
+
it('is admin-read only and has no generic write door', () => {
|
|
62
|
+
expect(tables.UserStatusEvent.auth?.db).toEqual({ query: ['admin'] });
|
|
63
|
+
expect(tables.UserStatusEvent.auth?.service).toEqual({ query: ['admin'] });
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
49
67
|
describe('session table auth shape', () => {
|
|
50
68
|
it('is readable by sessions holders and has no generic write door (writes are system-written)', () => {
|
|
51
69
|
expect(tables.Session.auth?.db).toEqual({ query: { permission: USER_PERMISSIONS.sessions } });
|