@proteinjs/user 1.7.2 → 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.
Files changed (75) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/generated/index.d.ts +0 -2
  3. package/dist/generated/index.d.ts.map +1 -1
  4. package/dist/generated/index.js +7 -3
  5. package/dist/generated/index.js.map +1 -1
  6. package/dist/index.d.ts +6 -0
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +6 -0
  9. package/dist/index.js.map +1 -1
  10. package/dist/src/MachineAccount.d.ts +47 -0
  11. package/dist/src/MachineAccount.d.ts.map +1 -0
  12. package/dist/src/MachineAccount.js +100 -0
  13. package/dist/src/MachineAccount.js.map +1 -0
  14. package/dist/src/ScopedRecord.d.ts +12 -1
  15. package/dist/src/ScopedRecord.d.ts.map +1 -1
  16. package/dist/src/ScopedRecord.js +19 -3
  17. package/dist/src/ScopedRecord.js.map +1 -1
  18. package/dist/src/UserRepo.d.ts +8 -0
  19. package/dist/src/UserRepo.d.ts.map +1 -1
  20. package/dist/src/UserRepo.js +22 -0
  21. package/dist/src/UserRepo.js.map +1 -1
  22. package/dist/src/routes.d.ts +11 -0
  23. package/dist/src/routes.d.ts.map +1 -1
  24. package/dist/src/routes.js +14 -1
  25. package/dist/src/routes.js.map +1 -1
  26. package/dist/src/services/AccountDeletionService.d.ts +27 -0
  27. package/dist/src/services/AccountDeletionService.d.ts.map +1 -0
  28. package/dist/src/services/AccountDeletionService.js +6 -0
  29. package/dist/src/services/AccountDeletionService.js.map +1 -0
  30. package/dist/src/services/MachineCredentialsService.d.ts +38 -0
  31. package/dist/src/services/MachineCredentialsService.d.ts.map +1 -0
  32. package/dist/src/services/MachineCredentialsService.js +6 -0
  33. package/dist/src/services/MachineCredentialsService.js.map +1 -0
  34. package/dist/src/services/SetUserStatusService.d.ts +15 -0
  35. package/dist/src/services/SetUserStatusService.d.ts.map +1 -0
  36. package/dist/src/services/SetUserStatusService.js +6 -0
  37. package/dist/src/services/SetUserStatusService.js.map +1 -0
  38. package/dist/src/services/UpdateUserInfoService.d.ts +16 -1
  39. package/dist/src/services/UpdateUserInfoService.d.ts.map +1 -1
  40. package/dist/src/services/UpdateUserInfoService.js.map +1 -1
  41. package/dist/src/tables/AccountDeletionTable.d.ts +85 -0
  42. package/dist/src/tables/AccountDeletionTable.d.ts.map +1 -0
  43. package/dist/src/tables/AccountDeletionTable.js +62 -0
  44. package/dist/src/tables/AccountDeletionTable.js.map +1 -0
  45. package/dist/src/tables/SessionTable.d.ts +1 -1
  46. package/dist/src/tables/UserStatusEventTable.d.ts +30 -0
  47. package/dist/src/tables/UserStatusEventTable.d.ts.map +1 -0
  48. package/dist/src/tables/UserStatusEventTable.js +43 -0
  49. package/dist/src/tables/UserStatusEventTable.js.map +1 -0
  50. package/dist/src/tables/UserTable.d.ts +48 -2
  51. package/dist/src/tables/UserTable.d.ts.map +1 -1
  52. package/dist/src/tables/UserTable.js +75 -4
  53. package/dist/src/tables/UserTable.js.map +1 -1
  54. package/dist/src/tables/tables.d.ts +4 -0
  55. package/dist/src/tables/tables.d.ts.map +1 -1
  56. package/dist/src/tables/tables.js +4 -0
  57. package/dist/src/tables/tables.js.map +1 -1
  58. package/dist/test/tablesAuth.test.js +20 -4
  59. package/dist/test/tablesAuth.test.js.map +1 -1
  60. package/generated/index.ts +7 -3
  61. package/index.ts +6 -0
  62. package/package.json +4 -4
  63. package/src/MachineAccount.ts +103 -0
  64. package/src/ScopedRecord.ts +16 -3
  65. package/src/UserRepo.ts +25 -0
  66. package/src/routes.ts +13 -0
  67. package/src/services/AccountDeletionService.ts +28 -0
  68. package/src/services/MachineCredentialsService.ts +43 -0
  69. package/src/services/SetUserStatusService.ts +16 -0
  70. package/src/services/UpdateUserInfoService.ts +17 -1
  71. package/src/tables/AccountDeletionTable.ts +98 -0
  72. package/src/tables/UserStatusEventTable.ts +34 -0
  73. package/src/tables/UserTable.ts +69 -6
  74. package/src/tables/tables.ts +4 -0
  75. package/test/tablesAuth.test.ts +22 -4
@@ -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
+ }
@@ -1,13 +1,29 @@
1
1
  import { Service, serviceFactory } from '@proteinjs/service';
2
+ import { User } from '../tables/UserTable';
2
3
 
3
4
  export const getUpdateUserInfoService = serviceFactory<UpdateUserInfoService>('@proteinjs/user/UpdateUserInfoService');
4
5
 
6
+ /** What user-info mutations return: the updated user record, never the password hash. */
7
+ export type UpdatedUser = Omit<User, 'password'>;
8
+
5
9
  export interface UpdatePasswordResponse {
6
10
  updated: boolean;
7
11
  error?: string;
8
12
  }
9
13
 
10
14
  export interface UpdateUserInfoService extends Service {
11
- updateName(name: string): Promise<void>;
15
+ updateName(name: string): Promise<UpdatedUser>;
12
16
  updatePassword(currentPassword: string, newPassword: string): Promise<UpdatePasswordResponse>;
17
+ /**
18
+ * Set a photo avatar: the image is re-encoded server-side to a 512x512 JPEG (EXIF stripped),
19
+ * stored via FileStorage, and any previous avatar photo is deleted. Nulls `avatarEmoji`
20
+ * (avatars are photo OR emoji, exactly one active).
21
+ * @param fileData base64-encoded image bytes (max 10MB decoded)
22
+ * @param mimeType one of image/jpeg, image/png, image/webp, image/heic, image/heif
23
+ */
24
+ updateAvatarPhoto(fileData: string, mimeType: string): Promise<UpdatedUser>;
25
+ /** Set an emoji avatar. Nulls `avatarFileId` and deletes any previous avatar photo file. */
26
+ updateAvatarEmoji(emoji: string): Promise<UpdatedUser>;
27
+ /** Remove the avatar entirely (both representations; deletes any stored photo file). */
28
+ clearAvatar(): Promise<UpdatedUser>;
13
29
  }
@@ -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
+ }
@@ -4,14 +4,25 @@ import {
4
4
  StringColumn,
5
5
  PasswordColumn,
6
6
  Table,
7
- Record,
8
- withRecordColumns,
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
- export type User = Record & {
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;
@@ -21,6 +32,27 @@ export type User = Record & {
21
32
  /** Role names from the roles catalog (see `RolesCatalog`). Written ONLY by the Roles service. */
22
33
  roles: string[];
23
34
  invitedBy?: string | null;
35
+ /**
36
+ * Emoji avatar. At most one of `avatarEmoji`/`avatarFileId` is set — the avatar mutations in
37
+ * UpdateUserInfo enforce it (every mutation assigns BOTH columns); nothing else writes these.
38
+ */
39
+ avatarEmoji?: string | null;
40
+ /**
41
+ * File id of the stored avatar photo (512x512 JPEG). A plain string, NOT a ReferenceColumn:
42
+ * @proteinjs/db-file depends on @proteinjs/user, so a user→file reference would be circular.
43
+ */
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;
24
56
  };
25
57
 
26
58
  export class UserTable extends Table<User> {
@@ -46,11 +78,37 @@ export class UserTable extends Table<User> {
46
78
  update: { permission: USER_PERMISSIONS.users },
47
79
  delete: { permission: USER_PERMISSIONS.users },
48
80
  },
49
- serviceProtectedColumns: ['roles'],
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'],
50
90
  };
51
- columns = withRecordColumns<User>({
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>({
52
104
  name: new StringColumn('name'),
53
- email: new StringColumn('email', {}, 250),
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),
54
112
  password: new PasswordColumn('password'),
55
113
  passwordResetToken: new StringColumn('password_reset_token'),
56
114
  passwordResetTokenExpiration: new DateTimeColumn('password_reset_token_expiration'),
@@ -62,5 +120,10 @@ export class UserTable extends Table<User> {
62
120
  */
63
121
  roles: new ArrayColumn<string>('role_list'),
64
122
  invitedBy: new StringColumn('invited_by'),
123
+ avatarEmoji: new StringColumn('avatar_emoji'),
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'),
65
128
  });
66
129
  }
@@ -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
  };
@@ -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 — the roles column is
8
- * service-protected (single write path: the Roles service).
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('service-protects the roles column (single write path: the Roles service)', () => {
38
- expect(tables.User.auth?.serviceProtectedColumns).toEqual(['roles']);
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 } });