@proteinjs/user 1.8.0 → 1.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 (77) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/generated/index.d.ts.map +1 -1
  3. package/dist/generated/index.js +7 -1
  4. package/dist/generated/index.js.map +1 -1
  5. package/dist/index.d.ts +6 -0
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +6 -0
  8. package/dist/index.js.map +1 -1
  9. package/dist/src/MachineAccount.d.ts +47 -0
  10. package/dist/src/MachineAccount.d.ts.map +1 -0
  11. package/dist/src/MachineAccount.js +100 -0
  12. package/dist/src/MachineAccount.js.map +1 -0
  13. package/dist/src/ScopedRecord.d.ts +8 -0
  14. package/dist/src/ScopedRecord.d.ts.map +1 -1
  15. package/dist/src/ScopedRecord.js +5 -1
  16. package/dist/src/ScopedRecord.js.map +1 -1
  17. package/dist/src/SharedRecord.d.ts +1 -6
  18. package/dist/src/SharedRecord.d.ts.map +1 -1
  19. package/dist/src/SharedRecord.js +18 -5
  20. package/dist/src/SharedRecord.js.map +1 -1
  21. package/dist/src/routes.d.ts.map +1 -1
  22. package/dist/src/routes.js +1 -0
  23. package/dist/src/routes.js.map +1 -1
  24. package/dist/src/services/AccountDeletionService.d.ts +27 -0
  25. package/dist/src/services/AccountDeletionService.d.ts.map +1 -0
  26. package/dist/src/services/AccountDeletionService.js +6 -0
  27. package/dist/src/services/AccountDeletionService.js.map +1 -0
  28. package/dist/src/services/MachineCredentialsService.d.ts +38 -0
  29. package/dist/src/services/MachineCredentialsService.d.ts.map +1 -0
  30. package/dist/src/services/MachineCredentialsService.js +6 -0
  31. package/dist/src/services/MachineCredentialsService.js.map +1 -0
  32. package/dist/src/services/SetUserStatusService.d.ts +15 -0
  33. package/dist/src/services/SetUserStatusService.d.ts.map +1 -0
  34. package/dist/src/services/SetUserStatusService.js +6 -0
  35. package/dist/src/services/SetUserStatusService.js.map +1 -0
  36. package/dist/src/services/SignupService.d.ts +8 -7
  37. package/dist/src/services/SignupService.d.ts.map +1 -1
  38. package/dist/src/tables/AccountDeletionTable.d.ts +85 -0
  39. package/dist/src/tables/AccountDeletionTable.d.ts.map +1 -0
  40. package/dist/src/tables/AccountDeletionTable.js +62 -0
  41. package/dist/src/tables/AccountDeletionTable.js.map +1 -0
  42. package/dist/src/tables/SessionTable.d.ts +1 -1
  43. package/dist/src/tables/UserStatusEventTable.d.ts +30 -0
  44. package/dist/src/tables/UserStatusEventTable.d.ts.map +1 -0
  45. package/dist/src/tables/UserStatusEventTable.js +43 -0
  46. package/dist/src/tables/UserStatusEventTable.js.map +1 -0
  47. package/dist/src/tables/UserTable.d.ts +36 -2
  48. package/dist/src/tables/UserTable.d.ts.map +1 -1
  49. package/dist/src/tables/UserTable.js +73 -4
  50. package/dist/src/tables/UserTable.js.map +1 -1
  51. package/dist/src/tables/tables.d.ts +4 -0
  52. package/dist/src/tables/tables.d.ts.map +1 -1
  53. package/dist/src/tables/tables.js +4 -0
  54. package/dist/src/tables/tables.js.map +1 -1
  55. package/dist/test/SharedRecordDuplicateModuleState.test.d.ts +18 -0
  56. package/dist/test/SharedRecordDuplicateModuleState.test.d.ts.map +1 -0
  57. package/dist/test/SharedRecordDuplicateModuleState.test.js +50 -0
  58. package/dist/test/SharedRecordDuplicateModuleState.test.js.map +1 -0
  59. package/dist/test/tablesAuth.test.js +20 -4
  60. package/dist/test/tablesAuth.test.js.map +1 -1
  61. package/generated/index.ts +7 -1
  62. package/index.ts +6 -0
  63. package/package.json +4 -4
  64. package/src/MachineAccount.ts +103 -0
  65. package/src/ScopedRecord.ts +11 -0
  66. package/src/SharedRecord.ts +18 -4
  67. package/src/routes.ts +1 -0
  68. package/src/services/AccountDeletionService.ts +28 -0
  69. package/src/services/MachineCredentialsService.ts +43 -0
  70. package/src/services/SetUserStatusService.ts +16 -0
  71. package/src/services/SignupService.ts +8 -7
  72. package/src/tables/AccountDeletionTable.ts +98 -0
  73. package/src/tables/UserStatusEventTable.ts +34 -0
  74. package/src/tables/UserTable.ts +57 -6
  75. package/src/tables/tables.ts +4 -0
  76. package/test/SharedRecordDuplicateModuleState.test.ts +59 -0
  77. package/test/tablesAuth.test.ts +22 -4
@@ -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
+ }
@@ -16,18 +16,19 @@ export type InitializeSignupResponse = {
16
16
  invite?: Omit<Invite, 'token'>;
17
17
  };
18
18
 
19
+ /** The signup route's request body (`routes.signup`). `email` is required if no token is provided. */
19
20
  export type UserSignup = Pick<User, 'name' | 'password'> & {
20
21
  email?: User['email'];
21
22
  };
22
23
 
24
+ /**
25
+ * Account CREATION is not on this interface: signing up establishes a session in the same
26
+ * request (auto-login), and session establishment is a request-level concern services never
27
+ * see — it lives on the `routes.signup` route (user-server `src/routes/signup.ts`), beside
28
+ * login. This service owns the rest of the signup flow: pre-submit initialization and invite
29
+ * management.
30
+ */
23
31
  export interface SignupService extends Service {
24
- /**
25
- * Creates a new user account.
26
- * @param {UserSignup} user - User signup information. `user.email` is required if no token is provided.
27
- * @param {string} [token] - Optional invite token. If provided, the corresponding invite record will be used to get the user's email.
28
- * @returns {Promise<void>}
29
- */
30
- createUser(user: UserSignup, token?: string): Promise<void>;
31
32
  /** Creates invite record and sends email to the invited user.
32
33
  * If invite already exists for the email, it will update the existing record with a new token and send a new email.
33
34
  */
@@ -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;
@@ -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
- 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'],
60
90
  };
61
- 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>({
62
104
  name: new StringColumn('name'),
63
- 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),
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
  }
@@ -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
  };
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Duplicate-module-instance guard for the skip-access-grants toggle (task #36).
3
+ *
4
+ * Per-package installs can put two live copies of @proteinjs/user in one process (each sibling
5
+ * package's nested node_modules hosts its own registry copy; Node resolves through symlinked
6
+ * workspace packages to distinct real paths). A module-scoped toggle then splits per copy:
7
+ * the 2026-08-14 incident had a test toggling one copy's skipAccessGrants while the AccessGrant
8
+ * closures enforced from the other copy — the toggle was a silent no-op and a stranger's
9
+ * lock-room join was acked ok.
10
+ *
11
+ * `jest.isolateModules` reproduces the split semantics exactly: each isolated registry gets its
12
+ * own module instance with its own module scope, the same way two nested install paths do. The
13
+ * guard asserts the toggle set through one live copy is observed by another live copy — which
14
+ * only holds when the state is anchored on the process global, not in module scope.
15
+ */
16
+
17
+ type SharedRecordModule = typeof import('../src/SharedRecord');
18
+
19
+ const loadIsolatedCopy = (): SharedRecordModule => {
20
+ let copy: SharedRecordModule | undefined;
21
+ jest.isolateModules(() => {
22
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
23
+ copy = require('../src/SharedRecord');
24
+ });
25
+
26
+ if (!copy) {
27
+ throw new Error('Failed to load an isolated copy of SharedRecord');
28
+ }
29
+
30
+ return copy;
31
+ };
32
+
33
+ describe('SharedRecord skip-access-grants state under duplicate module instances', () => {
34
+ afterEach(() => {
35
+ delete (globalThis as any).__proteinjs_user_skipAccessGrants;
36
+ });
37
+
38
+ test('a toggle set through one live copy is enforced by every other live copy', () => {
39
+ const copyA = loadIsolatedCopy();
40
+ const copyB = loadIsolatedCopy();
41
+ expect(copyA).not.toBe(copyB); // two distinct module instances, as under per-package installs
42
+
43
+ // The incident shape: the test toggles copy A, the enforcing closures live in copy B.
44
+ copyA.setSkipAccessGrants(true);
45
+ expect(copyB.skipAccessGrantsEnabled()).toBe(true);
46
+
47
+ // And the reverse direction: resetting through B must reach A.
48
+ copyB.setSkipAccessGrants(false);
49
+ expect(copyA.skipAccessGrantsEnabled()).toBe(false);
50
+ });
51
+
52
+ test('a copy loaded after the toggle was set still observes it', () => {
53
+ const copyA = loadIsolatedCopy();
54
+ copyA.setSkipAccessGrants(true);
55
+
56
+ const lateCopy = loadIsolatedCopy();
57
+ expect(lateCopy.skipAccessGrantsEnabled()).toBe(true);
58
+ });
59
+ });
@@ -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 } });