@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.
Files changed (60) hide show
  1. package/CHANGELOG.md +14 -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/services/AccountDeletionService.d.ts +27 -0
  18. package/dist/src/services/AccountDeletionService.d.ts.map +1 -0
  19. package/dist/src/services/AccountDeletionService.js +6 -0
  20. package/dist/src/services/AccountDeletionService.js.map +1 -0
  21. package/dist/src/services/MachineCredentialsService.d.ts +38 -0
  22. package/dist/src/services/MachineCredentialsService.d.ts.map +1 -0
  23. package/dist/src/services/MachineCredentialsService.js +6 -0
  24. package/dist/src/services/MachineCredentialsService.js.map +1 -0
  25. package/dist/src/services/SetUserStatusService.d.ts +15 -0
  26. package/dist/src/services/SetUserStatusService.d.ts.map +1 -0
  27. package/dist/src/services/SetUserStatusService.js +6 -0
  28. package/dist/src/services/SetUserStatusService.js.map +1 -0
  29. package/dist/src/tables/AccountDeletionTable.d.ts +85 -0
  30. package/dist/src/tables/AccountDeletionTable.d.ts.map +1 -0
  31. package/dist/src/tables/AccountDeletionTable.js +62 -0
  32. package/dist/src/tables/AccountDeletionTable.js.map +1 -0
  33. package/dist/src/tables/SessionTable.d.ts +1 -1
  34. package/dist/src/tables/UserStatusEventTable.d.ts +30 -0
  35. package/dist/src/tables/UserStatusEventTable.d.ts.map +1 -0
  36. package/dist/src/tables/UserStatusEventTable.js +43 -0
  37. package/dist/src/tables/UserStatusEventTable.js.map +1 -0
  38. package/dist/src/tables/UserTable.d.ts +36 -2
  39. package/dist/src/tables/UserTable.d.ts.map +1 -1
  40. package/dist/src/tables/UserTable.js +73 -4
  41. package/dist/src/tables/UserTable.js.map +1 -1
  42. package/dist/src/tables/tables.d.ts +4 -0
  43. package/dist/src/tables/tables.d.ts.map +1 -1
  44. package/dist/src/tables/tables.js +4 -0
  45. package/dist/src/tables/tables.js.map +1 -1
  46. package/dist/test/tablesAuth.test.js +20 -4
  47. package/dist/test/tablesAuth.test.js.map +1 -1
  48. package/generated/index.ts +7 -1
  49. package/index.ts +6 -0
  50. package/package.json +4 -4
  51. package/src/MachineAccount.ts +103 -0
  52. package/src/ScopedRecord.ts +11 -0
  53. package/src/services/AccountDeletionService.ts +28 -0
  54. package/src/services/MachineCredentialsService.ts +43 -0
  55. package/src/services/SetUserStatusService.ts +16 -0
  56. package/src/tables/AccountDeletionTable.ts +98 -0
  57. package/src/tables/UserStatusEventTable.ts +34 -0
  58. package/src/tables/UserTable.ts +57 -6
  59. package/src/tables/tables.ts +4 -0
  60. package/test/tablesAuth.test.ts +22 -4
@@ -1 +1 @@
1
- {"version":3,"file":"ScopedRecord.d.ts","sourceRoot":"","sources":["../../src/ScopedRecord.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EAEP,MAAM,EAGN,KAAK,EAGL,EAAE,EACH,MAAM,eAAe,CAAC;AAGvB,MAAM,WAAW,YAAa,SAAQ,MAAM;IAC1C,KAAK,EAAE,MAAM,CAAC;CACf;AAED,eAAO,MAAM,WAAW,wBAAsB,CAAC;AAE/C,eAAO,MAAM,mBAAmB,oDACkB,CAAC;AA+CnD,wBAAgB,eAAe,0BAE9B;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG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AC,GAAG,OAAO,CAEjE;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,SAAS,YAAY,EAC5D,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM,YAAY,CAAC,CAAC,EAC7C,gBAAgB,CAAC,EAAE,MAAM,EAAE,GAC1B,OAAO,CAAC,YAAY,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM,YAAY,CAAC,CAAC,CAK9D;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,YAAY,EAAE,IAAI,EAAE;IAC9D,OAAO,EAAE,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,GAAG;IAAE,OAAO,EAAE,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAAE,CAM5D"}
@@ -56,7 +56,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
56
56
  return to.concat(ar || Array.prototype.slice.call(from));
57
57
  };
58
58
  Object.defineProperty(exports, "__esModule", { value: true });
59
- exports.createScopedIndex = exports.withScopedRecordColumns = exports.isScopedTable = exports.getScopedTables = exports.getScopedDbAsSystem = exports.getScopedDb = void 0;
59
+ exports.createScopedIndex = exports.withScopedRecordColumns = exports.retainedOnAccountPurge = exports.isScopedTable = exports.getScopedTables = exports.getScopedDbAsSystem = exports.getScopedDb = void 0;
60
60
  var db_1 = require("@proteinjs/db");
61
61
  var UserRepo_1 = require("./UserRepo");
62
62
  exports.getScopedDb = (db_1.getDb);
@@ -120,6 +120,10 @@ function isScopedTable(table) {
120
120
  return !!scopeColumn;
121
121
  }
122
122
  exports.isScopedTable = isScopedTable;
123
+ function retainedOnAccountPurge(table) {
124
+ return table.retainOnAccountPurge === true;
125
+ }
126
+ exports.retainedOnAccountPurge = retainedOnAccountPurge;
123
127
  /**
124
128
  * Wrapper function to add default ScopedRecord columns to your table's columns.
125
129
  *
@@ -1 +1 @@
1
- {"version":3,"file":"ScopedRecord.js","sourceRoot":"","sources":["../../src/ScopedRecord.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oCAUuB;AACvB,uCAAsC;AAMzB,QAAA,WAAW,GAAG,CAAA,UAAmB,CAAA,CAAC;AAExC,IAAM,mBAAmB,GAAG;IACjC,OAAA,IAAI,OAAE,CAAI,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,IAAI,CAAC;AAAhD,CAAgD,CAAC;AADtC,QAAA,mBAAmB,uBACmB;AAEnD;;;;;;;;GAQG;AACH,IAAM,kBAAkB,GAAG,UAAC,SAAiB;IAC3C,IAAM,MAAM,GAAG,IAAI,mBAAQ,EAAE,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC;IAC3C,IAAI,CAAC,MAAM,EAAE;QACX,MAAM,IAAI,KAAK,CACb,gDAAyC,SAAS,+CAA4C;YAC5F,yFAAyF;YACzF,8DAA8D,CACjE,CAAC;KACH;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAEF,IAAM,sBAAsB,GAAG,UAAC,gBAA+B;IAA/B,iCAAA,EAAA,qBAA+B;IAC7D,OAAO;QACL,KAAK,EAAE,IAAI,iBAAY,CAAC,OAAO,EAAE;YAC/B,YAAY,EAAE;gBAAY,sBAAA,kBAAkB,CAAC,OAAO,CAAC,EAAA;qBAAA;YACrD,iBAAiB,EAAE,UAAC,WAAW,IAAK,OAAA,CAAC,WAAW,EAAZ,CAAY;YAChD,0FAA0F;YAC1F,4FAA4F;YAC5F,4FAA4F;YAC5F,uFAAuF;YACvF,SAAS,EAAE,UAAC,WAAW,IAAK,OAAA,CAAC,WAAW,EAAZ,CAAY;YACxC,UAAU,E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IAAI,CAAC,OAAO,SAAG,IAAI,EAAE,IAAI,CAAC,IAAI,IAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAG;AAC5G,CAAC;AAVD,8CAUC"}
@@ -0,0 +1,27 @@
1
+ import { Service } from '@proteinjs/service';
2
+ import { Moment } from 'moment';
3
+ export declare const getAccountDeletionService: () => AccountDeletionService;
4
+ /**
5
+ * In-app account deletion, archive-then-purge: the synchronous call deactivates the account
6
+ * ("gone right away" — shares revoked both directions, sessions killed), and the background
7
+ * purge walker erases everything after the grace window. Logging back in during grace cancels
8
+ * (full restore, including shares — the login route runs the cancel hook, not this service).
9
+ *
10
+ * Acts ONLY on the session user — no target parameter, so the only authz surface beyond the
11
+ * door is the password re-auth inside the call. Door: any authenticated user (`allUsers`,
12
+ * declared on the implementation's serviceMetadata).
13
+ */
14
+ export interface AccountDeletionService extends Service {
15
+ /**
16
+ * Deactivate the session user's account and schedule the purge. Idempotent: a re-call after a
17
+ * partial failure resumes from the stored deletion manifest (never re-enumerates). The
18
+ * caller's sessions are killed last — the response is the last authenticated exchange.
19
+ *
20
+ * @param password re-auth — must match the session user's password
21
+ * @returns the purge date, for the UI's confirmation copy
22
+ */
23
+ requestDeletion(password: string): Promise<{
24
+ purgeAfter: Moment;
25
+ }>;
26
+ }
27
+ //# sourceMappingURL=AccountDeletionService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AccountDeletionService.d.ts","sourceRoot":"","sources":["../../../src/services/AccountDeletionService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAkB,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,eAAO,MAAM,yBAAyB,8BAErC,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,WAAW,sBAAuB,SAAQ,OAAO;IACrD;;;;;;;OAOG;IACH,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACpE"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAccountDeletionService = void 0;
4
+ var service_1 = require("@proteinjs/service");
5
+ exports.getAccountDeletionService = (0, service_1.serviceFactory)('@proteinjs/user/AccountDeletionService');
6
+ //# sourceMappingURL=AccountDeletionService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AccountDeletionService.js","sourceRoot":"","sources":["../../../src/services/AccountDeletionService.ts"],"names":[],"mappings":";;;AAAA,8CAA6D;AAGhD,QAAA,yBAAyB,GAAG,IAAA,wBAAc,EACrD,wCAAwC,CACzC,CAAC"}
@@ -0,0 +1,38 @@
1
+ import { Service } from '@proteinjs/service';
2
+ export declare const getMachineCredentialsService: () => MachineCredentialsService;
3
+ /** The one-time view of a minted machine credential — the plaintext is never stored. */
4
+ export type MintedMachineCredential = {
5
+ /** The machine account the credential was minted for. */
6
+ email: string;
7
+ /** The generated password — shown exactly ONCE; only its hash is stored. */
8
+ password: string;
9
+ /** The Secret Manager secret the declaration names as the credential's home. */
10
+ secretName: string;
11
+ /** Operator instruction: where to paste the plaintext and what activates it. */
12
+ note: string;
13
+ };
14
+ /** A declared machine account joined with its row state — the admin surface renders these. */
15
+ export type MachineAccountView = {
16
+ email: string;
17
+ accountName: string;
18
+ roles: string[];
19
+ secretName: string;
20
+ /** 'pending first boot' until the boot sync has created/adopted the row. */
21
+ status: 'active' | 'deactivated' | 'pending first boot';
22
+ /** Whether a credential has ever been minted/provisioned (hash present on the row). */
23
+ hasCredential: boolean;
24
+ };
25
+ /**
26
+ * Credential minting for code-declared machine accounts (`MachineAccount`): identity and grants
27
+ * live in source; the credential is the ONLY runtime-provisioned piece. Minting generates a
28
+ * strong random password, stores its hash on the account row (no human-chosen passwords), kills
29
+ * the account's sessions, and returns the plaintext once for pasting into the declaration's
30
+ * Secret Manager secret. The same call rotates. Machine rows only — human credentials go
31
+ * through the password-reset flow.
32
+ */
33
+ export interface MachineCredentialsService extends Service {
34
+ /** Every declared machine account with its row state, for the admin surface. */
35
+ listMachineAccounts(): Promise<MachineAccountView[]>;
36
+ mintCredential(email: string): Promise<MintedMachineCredential>;
37
+ }
38
+ //# sourceMappingURL=MachineCredentialsService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MachineCredentialsService.d.ts","sourceRoot":"","sources":["../../../src/services/MachineCredentialsService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAkB,MAAM,oBAAoB,CAAC;AAE7D,eAAO,MAAM,4BAA4B,iCAExC,CAAC;AAEF,wFAAwF;AACxF,MAAM,MAAM,uBAAuB,GAAG;IACpC,yDAAyD;IACzD,KAAK,EAAE,MAAM,CAAC;IACd,4EAA4E;IAC5E,QAAQ,EAAE,MAAM,CAAC;IACjB,gFAAgF;IAChF,UAAU,EAAE,MAAM,CAAC;IACnB,gFAAgF;IAChF,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,8FAA8F;AAC9F,MAAM,MAAM,kBAAkB,GAAG;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,4EAA4E;IAC5E,MAAM,EAAE,QAAQ,GAAG,aAAa,GAAG,oBAAoB,CAAC;IACxD,uFAAuF;IACvF,aAAa,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,WAAW,yBAA0B,SAAQ,OAAO;IACxD,gFAAgF;IAChF,mBAAmB,IAAI,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAAC;IACrD,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAC;CACjE"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getMachineCredentialsService = void 0;
4
+ var service_1 = require("@proteinjs/service");
5
+ exports.getMachineCredentialsService = (0, service_1.serviceFactory)('@proteinjs/user/MachineCredentialsService');
6
+ //# sourceMappingURL=MachineCredentialsService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MachineCredentialsService.js","sourceRoot":"","sources":["../../../src/services/MachineCredentialsService.ts"],"names":[],"mappings":";;;AAAA,8CAA6D;AAEhD,QAAA,4BAA4B,GAAG,IAAA,wBAAc,EACxD,2CAA2C,CAC5C,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { Service } from '@proteinjs/service';
2
+ import { UserStatus } from '../tables/UserTable';
3
+ export declare const getSetUserStatusService: () => SetUserStatusService;
4
+ /**
5
+ * The ONE write path for a user's account standing. The `user.status` column is
6
+ * service-protected (generic record writes cannot touch it); every change lands here and writes
7
+ * a `user_status_event` audit row (actor, target, status; `created` is the timestamp).
8
+ * Admin-only: deactivation locks the target out of the product (login refused, live sessions
9
+ * stop resolving), so the door is the break-glass role, not a mapped permission.
10
+ */
11
+ export interface SetUserStatusService extends Service {
12
+ /** Set a user's standing. Already in that standing: no change, no audit row. */
13
+ setUserStatus(userId: string, status: UserStatus): Promise<void>;
14
+ }
15
+ //# sourceMappingURL=SetUserStatusService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SetUserStatusService.d.ts","sourceRoot":"","sources":["../../../src/services/SetUserStatusService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAkB,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjD,eAAO,MAAM,uBAAuB,4BAA+E,CAAC;AAEpH;;;;;;GAMG;AACH,MAAM,WAAW,oBAAqB,SAAQ,OAAO;IACnD,gFAAgF;IAChF,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAClE"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSetUserStatusService = void 0;
4
+ var service_1 = require("@proteinjs/service");
5
+ exports.getSetUserStatusService = (0, service_1.serviceFactory)('@proteinjs/user/SetUserStatusService');
6
+ //# sourceMappingURL=SetUserStatusService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SetUserStatusService.js","sourceRoot":"","sources":["../../../src/services/SetUserStatusService.ts"],"names":[],"mappings":";;;AAAA,8CAA6D;AAGhD,QAAA,uBAAuB,GAAG,IAAA,wBAAc,EAAuB,sCAAsC,CAAC,CAAC"}
@@ -0,0 +1,85 @@
1
+ import { Table, Record } from '@proteinjs/db';
2
+ import { Moment } from 'moment';
3
+ import { AccessGrant } from './AccessGrantTable';
4
+ /** Purge-machine phases. `grace` = cancelable window; `restoring` = a cancel-by-login claimed the
5
+ * row; `purging` = the walker claimed it; `purged` = rows erased, completion email pending. */
6
+ export declare const ACCOUNT_DELETION_PHASES: readonly ["grace", "restoring", "purging", "purged"];
7
+ export type AccountDeletionPhase = (typeof ACCOUNT_DELETION_PHASES)[number];
8
+ /**
9
+ * A revoked `access_grant` row serialized verbatim into the deletion manifest. The stored `id`
10
+ * lets revocation delete precisely and resume idempotently; cancel re-inserts WITHOUT ids
11
+ * (fresh rows), matched by `(principal, resource, accessLevel)`.
12
+ */
13
+ export type ManifestGrant = {
14
+ /** id of the revoked access_grant row */
15
+ id: string;
16
+ /** user id (the grant's principal) */
17
+ principal: string;
18
+ /** resource id (the grant's resource) */
19
+ resource: string;
20
+ resourceTable?: string;
21
+ accessLevel: AccessGrant['accessLevel'];
22
+ };
23
+ /**
24
+ * One row per in-flight account deletion: the deletion manifest plus the purge machine's own
25
+ * state. Deliberately a plain `Record`, NOT scoped — it must survive the purge walker's scope
26
+ * sweep and outlive the `user` row (the completion email sends after the user is gone).
27
+ */
28
+ export interface AccountDeletion extends Record {
29
+ /** unique — one in-flight deletion per account */
30
+ userId: string;
31
+ /** Completion-email addressee after the user row is gone; login-cancel lookup key. */
32
+ userEmail: string;
33
+ phase: AccountDeletionPhase;
34
+ /** Write-once copy of `user.purgeAfter` (same logical step; this row is the machine's own stamp). */
35
+ purgeAfter: Moment;
36
+ /**
37
+ * Revoked grants, BOTH directions (inbound: my non-owner grants on others' content; outbound:
38
+ * others' grants on my content), verbatim. Persisted BEFORE any mutation — after a partial
39
+ * revocation the live grants under-count, so resume must never re-enumerate.
40
+ */
41
+ manifestGrants: ManifestGrant[];
42
+ /**
43
+ * Owner-grant resource ids snapshotted at deactivation — the purge walker's thought-domain id
44
+ * source. LOAD-BEARING: ThoughtAccessGrantCleanupTableWatcher deletes a thought's grants the
45
+ * moment its row dies, so live re-enumeration after a mid-tree crash would strand orphan
46
+ * children forever.
47
+ */
48
+ ownedResourceIds: string[];
49
+ /** CAS token (RoutineTicker.tickSeq pattern), bumped on every claim. */
50
+ leaseSeq: number;
51
+ ownerNodeId?: string | null;
52
+ /** JS-compared (Spanner timestamp-condition house rule). */
53
+ heartbeatAt?: Moment | null;
54
+ }
55
+ /**
56
+ * Locked like `SessionTable`: readable behind the 'users' permission, and NO write doors — rows
57
+ * are system-written only (the deletion service and the purge walker ride system paths, which
58
+ * bypass TableAuth). The manifest holds cross-user grant data, so even break-glass admin gets
59
+ * no generic write surface.
60
+ */
61
+ export declare class AccountDeletionTable extends Table<AccountDeletion> {
62
+ name: string;
63
+ auth: Table<AccountDeletion>['auth'];
64
+ indexes: {
65
+ name: string;
66
+ columns: (keyof AccountDeletion)[];
67
+ unique: boolean;
68
+ }[];
69
+ columns: {
70
+ id: import("@proteinjs/db").Column<string, any>;
71
+ created: import("@proteinjs/db").Column<Moment, any>;
72
+ updated: import("@proteinjs/db").Column<Moment, any>;
73
+ } & {} & {
74
+ purgeAfter: import("@proteinjs/db").Column<Moment, any>;
75
+ userId: import("@proteinjs/db").Column<string, any>;
76
+ userEmail: import("@proteinjs/db").Column<string, any>;
77
+ phase: import("@proteinjs/db").Column<"grace" | "restoring" | "purging" | "purged", any>;
78
+ manifestGrants: import("@proteinjs/db").Column<ManifestGrant[], any>;
79
+ ownedResourceIds: import("@proteinjs/db").Column<string[], any>;
80
+ leaseSeq: import("@proteinjs/db").Column<number, any>;
81
+ ownerNodeId: import("@proteinjs/db").Column<string | null | undefined, any>;
82
+ heartbeatAt: import("@proteinjs/db").Column<Moment | null | undefined, any>;
83
+ } & {};
84
+ }
85
+ //# sourceMappingURL=AccountDeletionTable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AccountDeletionTable.d.ts","sourceRoot":"","sources":["../../../src/tables/AccountDeletionTable.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,EACL,MAAM,EAEP,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD;gGACgG;AAChG,eAAO,MAAM,uBAAuB,sDAAuD,CAAC;AAC5F,MAAM,MAAM,oBAAoB,GAAG,CAAC,OAAO,uBAAuB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE5E;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,yCAAyC;IACzC,EAAE,EAAE,MAAM,CAAC;IACX,sCAAsC;IACtC,SAAS,EAAE,MAAM,CAAC;IAClB,yCAAyC;IACzC,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,WAAW,CAAC,aAAa,CAAC,CAAC;CACzC,CAAC;AAEF;;;;GAIG;AACH,MAAM,WAAW,eAAgB,SAAQ,MAAM;IAC7C,kDAAkD;IAClD,MAAM,EAAE,MAAM,CAAC;IACf,sFAAsF;IACtF,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,oBAAoB,CAAC;IAC5B,qGAAqG;IACrG,UAAU,EAAE,MAAM,CAAC;IACnB;;;;OAIG;IACH,cAAc,EAAE,aAAa,EAAE,CAAC;IAChC;;;;;OAKG;IACH,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,wEAAwE;IACxE,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,4DAA4D;IAC5D,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAED;;;;;GAKG;AACH,qBAAa,oBAAqB,SAAQ,KAAK,CAAC,eAAe,CAAC;IAC9D,IAAI,SAAsB;IAC1B,IAAI,EAAE,KAAK,CAAC,eAAe,CAAC,CAAC,MAAM,CAAC,CAOlC;IACF,OAAO;;;;QAEL;IACF,OAAO;;;;;;;;;;;;;;WAUJ;CACJ"}
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.AccountDeletionTable = exports.ACCOUNT_DELETION_PHASES = void 0;
19
+ var db_1 = require("@proteinjs/db");
20
+ var permissions_1 = require("../permissions");
21
+ /** Purge-machine phases. `grace` = cancelable window; `restoring` = a cancel-by-login claimed the
22
+ * row; `purging` = the walker claimed it; `purged` = rows erased, completion email pending. */
23
+ exports.ACCOUNT_DELETION_PHASES = ['grace', 'restoring', 'purging', 'purged'];
24
+ /**
25
+ * Locked like `SessionTable`: readable behind the 'users' permission, and NO write doors — rows
26
+ * are system-written only (the deletion service and the purge walker ride system paths, which
27
+ * bypass TableAuth). The manifest holds cross-user grant data, so even break-glass admin gets
28
+ * no generic write surface.
29
+ */
30
+ var AccountDeletionTable = /** @class */ (function (_super) {
31
+ __extends(AccountDeletionTable, _super);
32
+ function AccountDeletionTable() {
33
+ var _this = _super !== null && _super.apply(this, arguments) || this;
34
+ _this.name = 'account_deletion';
35
+ _this.auth = {
36
+ db: {
37
+ query: { permission: permissions_1.USER_PERMISSIONS.users },
38
+ },
39
+ service: {
40
+ query: { permission: permissions_1.USER_PERMISSIONS.users },
41
+ },
42
+ };
43
+ _this.indexes = [
44
+ { name: 'idx_account_deletion_user_id_unique', columns: ['userId'], unique: true },
45
+ ];
46
+ _this.columns = (0, db_1.withRecordColumns)({
47
+ userId: new db_1.StringColumn('user_id', {}, 36),
48
+ userEmail: new db_1.StringColumn('user_email', {}, 250),
49
+ phase: new db_1.StringColumn('phase', {}, 16),
50
+ purgeAfter: new db_1.DateTimeColumn('purge_after'),
51
+ manifestGrants: new db_1.ObjectColumn('manifest_grants'),
52
+ ownedResourceIds: new db_1.ObjectColumn('owned_resource_ids'),
53
+ leaseSeq: new db_1.IntegerColumn('lease_seq'),
54
+ ownerNodeId: new db_1.StringColumn('owner_node_id'),
55
+ heartbeatAt: new db_1.DateTimeColumn('heartbeat_at'),
56
+ });
57
+ return _this;
58
+ }
59
+ return AccountDeletionTable;
60
+ }(db_1.Table));
61
+ exports.AccountDeletionTable = AccountDeletionTable;
62
+ //# sourceMappingURL=AccountDeletionTable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AccountDeletionTable.js","sourceRoot":"","sources":["../../../src/tables/AccountDeletionTable.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,oCAQuB;AAEvB,8CAAkD;AAGlD;gGACgG;AACnF,QAAA,uBAA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js/db").Column<import("moment").Moment, any>;
20
20
  updated: import("@proteinjs/db").Column<import("moment").Moment, any>;
21
21
  } & {} & {
22
+ userEmail: import("@proteinjs/db").Column<string, any>;
22
23
  session: import("@proteinjs/db").Column<string, any>;
23
24
  sessionId: import("@proteinjs/db").Column<string, any>;
24
25
  expires: import("@proteinjs/db").Column<Date, any>;
25
- userEmail: import("@proteinjs/db").Column<string, any>;
26
26
  } & {};
27
27
  }
28
28
  //# sourceMappingURL=SessionTable.d.ts.map
@@ -0,0 +1,30 @@
1
+ import { Table, Record } from '@proteinjs/db';
2
+ import { UserStatus } from './UserTable';
3
+ /**
4
+ * Audit row written by the SetUserStatus service for EVERY status change. The base `created`
5
+ * column is the change timestamp. Rows are append-only: readable by admins (the same scope as
6
+ * the service that writes them), written only by the service's system path — no generic door
7
+ * grants writes, so the trail cannot be edited from the record surfaces.
8
+ */
9
+ export type UserStatusEvent = Record & {
10
+ /** id of the user who made the change */
11
+ actor: string;
12
+ /** id of the user whose status changed */
13
+ target: string;
14
+ /** the standing the target was set to */
15
+ status: UserStatus;
16
+ };
17
+ export declare class UserStatusEventTable extends Table<UserStatusEvent> {
18
+ name: string;
19
+ auth: Table<UserStatusEvent>['auth'];
20
+ columns: {
21
+ id: import("@proteinjs/db").Column<string, any>;
22
+ created: import("@proteinjs/db").Column<import("moment").Moment, any>;
23
+ updated: import("@proteinjs/db").Column<import("moment").Moment, any>;
24
+ } & {} & {
25
+ status: import("@proteinjs/db").Column<"active" | "deactivated", any>;
26
+ actor: import("@proteinjs/db").Column<string, any>;
27
+ target: import("@proteinjs/db").Column<string, any>;
28
+ } & {};
29
+ }
30
+ //# sourceMappingURL=UserStatusEventTable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UserStatusEventTable.d.ts","sourceRoot":"","sources":["../../../src/tables/UserStatusEventTable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,EAAE,MAAM,EAAqB,MAAM,eAAe,CAAC;AAC/E,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG;IACrC,yCAAyC;IACzC,KAAK,EAAE,MAAM,CAAC;IACd,0CAA0C;IAC1C,MAAM,EAAE,MAAM,CAAC;IACf,yCAAyC;IACzC,MAAM,EAAE,UAAU,CAAC;CACpB,CAAC;AAEF,qBAAa,oBAAqB,SAAQ,KAAK,CAAC,eAAe,CAAC;IAC9D,IAAI,SAAuB;IAC3B,IAAI,EAAE,KAAK,CAAC,eAAe,CAAC,CAAC,MAAM,CAAC,CAOlC;IACF,OAAO;;;;;;;;WAIJ;CACJ"}
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.UserStatusEventTable = void 0;
19
+ var db_1 = require("@proteinjs/db");
20
+ var UserStatusEventTable = /** @class */ (function (_super) {
21
+ __extends(UserStatusEventTable, _super);
22
+ function UserStatusEventTable() {
23
+ var _this = _super !== null && _super.apply(this, arguments) || this;
24
+ _this.name = 'user_status_event';
25
+ _this.auth = {
26
+ db: {
27
+ query: ['admin'],
28
+ },
29
+ service: {
30
+ query: ['admin'],
31
+ },
32
+ };
33
+ _this.columns = (0, db_1.withRecordColumns)({
34
+ actor: new db_1.StringColumn('actor', {}, 36),
35
+ target: new db_1.StringColumn('target', {}, 36),
36
+ status: new db_1.StringColumn('status', {}, 16),
37
+ });
38
+ return _this;
39
+ }
40
+ return UserStatusEventTable;
41
+ }(db_1.Table));
42
+ exports.UserStatusEventTable = UserStatusEventTable;
43
+ //# sourceMappingURL=UserStatusEventTable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UserStatusEventTable.js","sourceRoot":"","sources":["../../../src/tables/UserStatusEventTable.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,oCAA+E;AAkB/E;IAA0C,wCAAsB;IAAhE;QAAA,qEAeC;QAdC,UAAI,GAAG,mBAAmB,CAAC;QAC3B,UAAI,GAAmC;YACrC,EAAE,EAAE;gBACF,KAAK,EAAE,CAAC,OAAO,CAAC;aACjB;YACD,OAAO,EAAE;gBACP,KAAK,EAAE,CAAC,OAAO,CAAC;aACjB;SACF,CAAC;QACF,aAAO,GAAG,IAAA,sBAAiB,EAAkB;YAC3C,KAAK,EAAE,IAAI,iBAAY,CAAC,OAAO,EAAE,EAAE,EAAE,EAAE,CAAC;YACxC,MAAM,EAAE,IAAI,iBAAY,CAAC,QAAQ,EAAE,EAAE,EAAE,EAAE,CAAC;YAC1C,MAAM,EAAE,IAAI,iBAAY,CAAa,QAAQ,EAAE,EAAE,EAAE,EAAE,CAAC;SACvD,CAAC,CAAC;;IACL,CAAC;IAAD,2BAAC;AAAD,CAAC,AAfD,CAA0C,UAAK,GAe9C;AAfY,oDAAoB"}
@@ -1,6 +1,16 @@
1
- import { Table, Record } from '@proteinjs/db';
1
+ import { Table, SourceRecord } from '@proteinjs/db';
2
2
  import { Moment } from 'moment';
3
- export type User = Record & {
3
+ /** Account standings. The vocabulary is owned here; every status write flows through the SetUserStatus service. */
4
+ export declare const USER_STATUSES: readonly ["active", "deactivated"];
5
+ export type UserStatus = (typeof USER_STATUSES)[number];
6
+ /**
7
+ * A mixed-ownership source-record table: rows with `isLoadedFromSource = true` are CODE-DECLARED
8
+ * MACHINE ACCOUNTS (see `MachineAccount`) whose declared fields are reverted to source on every
9
+ * boot; human rows (flag null/false) are structurally untouchable by the boot sync. A machine
10
+ * account removed from source is deactivated — never deleted — so rows it is referenced from
11
+ * stay intact, and re-declaring it reactivates it.
12
+ */
13
+ export type User = SourceRecord & {
4
14
  name: string;
5
15
  email: string;
6
16
  password: string;
@@ -20,6 +30,17 @@ export type User = Record & {
20
30
  * @proteinjs/db-file depends on @proteinjs/user, so a user→file reference would be circular.
21
31
  */
22
32
  avatarFileId?: string | null;
33
+ /**
34
+ * Account standing. Written ONLY by the SetUserStatus service (audited per change). New rows
35
+ * default to 'active'; rows predating the column read null, which every gate treats as active —
36
+ * only an explicit 'deactivated' is refused (authentication and session resolution both gate on
37
+ * it in @proteinjs/user-server).
38
+ */
39
+ status?: UserStatus | null;
40
+ /** When the user asked for their account to be deleted. Written by the account-deletion flow only. */
41
+ deleteRequestedAt?: Moment | null;
42
+ /** When the grace window ends and the purge walker may erase the account. Written by the account-deletion flow only. */
43
+ purgeAfter?: Moment | null;
23
44
  };
24
45
  export declare class UserTable extends Table<User> {
25
46
  name: string;
@@ -32,7 +53,17 @@ export declare class UserTable extends Table<User> {
32
53
  * system paths, which bypass TableAuth).
33
54
  */
34
55
  auth: Table<User>['auth'];
56
+ /**
57
+ * Machine accounts sync by EMAIL, not id: existing envs hold hand-made machine rows with
58
+ * env-random ids that other rows reference — the boot sync adopts them in place (id kept,
59
+ * declared fields reverted, runtime fields like `password` untouched). Removal from source
60
+ * deactivates (the same status the staff toggle and account deletion write — the
61
+ * UserStatusTableWatcher kills sessions on every deactivation write); re-declaring
62
+ * reactivates via normal drift reversion.
63
+ */
64
+ sourceRecordOptions: Table<User>['sourceRecordOptions'];
35
65
  columns: {
66
+ isLoadedFromSource: import("@proteinjs/db").Column<boolean | undefined, any>;
36
67
  id: import("@proteinjs/db").Column<string, any>;
37
68
  created: import("@proteinjs/db").Column<Moment, any>;
38
69
  updated: import("@proteinjs/db").Column<Moment, any>;
@@ -47,6 +78,9 @@ export declare class UserTable extends Table<User> {
47
78
  invitedBy: import("@proteinjs/db").Column<string | null | undefined, any>;
48
79
  avatarEmoji: import("@proteinjs/db").Column<string | null | undefined, any>;
49
80
  avatarFileId: import("@proteinjs/db").Column<string | null | undefined, any>;
81
+ status: import("@proteinjs/db").Column<"active" | "deactivated" | null | undefined, any>;
82
+ deleteRequestedAt: import("@proteinjs/db").Column<Moment | null | undefined, any>;
83
+ purgeAfter: import("@proteinjs/db").Column<Moment | null | undefined, any>;
50
84
  } & {};
51
85
  }
52
86
  //# sourceMappingURL=UserTable.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"UserTable.d.ts","sourceRoot":"","sources":["../../../src/tables/UserTable.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,EACL,MAAM,EAGP,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC,MAAM,MAAM,IAAI,GAAG,MAAM,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,kBAAkB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,4BAA4B,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7C,aAAa,EAAE,OAAO,CAAC;IACvB,iGAAiG;IACjG,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B,CAAC;AAEF,qBAAa,SAAU,SAAQ,KAAK,CAAC,IAAI,CAAC;IACxC,IAAI,SAAU;IACd;;;;;;;OAOG;IACH,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CA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AsBvB;IACF;;;;;;;OAOG;IACH,mBAAmB,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,qBAAqB,CAAC,CAGrD;IACF,OAAO;;;;;;;;;;;;;;;;;;;WAyBJ;CACJ"}
@@ -14,10 +14,48 @@ var __extends = (this && this.__extends) || (function () {
14
14
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
15
  };
16
16
  })();
17
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ var __generator = (this && this.__generator) || function (thisArg, body) {
27
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
+ function verb(n) { return function (v) { return step([n, v]); }; }
30
+ function step(op) {
31
+ if (f) throw new TypeError("Generator is already executing.");
32
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
33
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
+ if (y = 0, t) op = [op[0] & 2, t.value];
35
+ switch (op[0]) {
36
+ case 0: case 1: t = op; break;
37
+ case 4: _.label++; return { value: op[1], done: false };
38
+ case 5: _.label++; y = op[1]; op = [0]; continue;
39
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
+ default:
41
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
+ if (t[2]) _.ops.pop();
46
+ _.trys.pop(); continue;
47
+ }
48
+ op = body.call(thisArg, _);
49
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
+ }
52
+ };
17
53
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.UserTable = void 0;
54
+ exports.UserTable = exports.USER_STATUSES = void 0;
19
55
  var db_1 = require("@proteinjs/db");
20
56
  var permissions_1 = require("../permissions");
57
+ /** Account standings. The vocabulary is owned here; every status write flows through the SetUserStatus service. */
58
+ exports.USER_STATUSES = ['active', 'deactivated'];
21
59
  var UserTable = /** @class */ (function (_super) {
22
60
  __extends(UserTable, _super);
23
61
  function UserTable() {
@@ -44,11 +82,37 @@ var UserTable = /** @class */ (function (_super) {
44
82
  update: { permission: permissions_1.USER_PERMISSIONS.users },
45
83
  delete: { permission: permissions_1.USER_PERMISSIONS.users },
46
84
  },
47
- serviceProtectedColumns: ['roles'],
85
+ /**
86
+ * `roles` is written only by the Roles service; `status` only by the SetUserStatus service
87
+ * (both audited per change — a generic RPC write would let the stored state diverge from its
88
+ * audit trail). `deleteRequestedAt`/`purgeAfter` drive the account purge machinery and are
89
+ * written only by the server-side deletion flow — never through the generic RPC path.
90
+ * `isLoadedFromSource` is machine-account ownership — written only by the boot sync; an RPC
91
+ * write could hand a human row to source ownership (or unhook a machine row from it).
92
+ */
93
+ serviceProtectedColumns: ['roles', 'status', 'deleteRequestedAt', 'purgeAfter', 'isLoadedFromSource'],
94
+ };
95
+ /**
96
+ * Machine accounts sync by EMAIL, not id: existing envs hold hand-made machine rows with
97
+ * env-random ids that other rows reference — the boot sync adopts them in place (id kept,
98
+ * declared fields reverted, runtime fields like `password` untouched). Removal from source
99
+ * deactivates (the same status the staff toggle and account deletion write — the
100
+ * UserStatusTableWatcher kills sessions on every deactivation write); re-declaring
101
+ * reactivates via normal drift reversion.
102
+ */
103
+ _this.sourceRecordOptions = {
104
+ naturalKey: 'email',
105
+ onSourceRemoved: { update: { status: 'deactivated' } },
48
106
  };
49
- _this.columns = (0, db_1.withRecordColumns)({
107
+ _this.columns = (0, db_1.withSourceRecordColumns)({
50
108
  name: new db_1.StringColumn('name'),
51
- email: new db_1.StringColumn('email', {}, 250),
109
+ /**
110
+ * Unique — codifying the invariant authenticate/Signup always assumed (lowercased +
111
+ * existence-checked). Also the machine-account natural key: adoption requires unambiguous
112
+ * matching. The schema sync's duplicate preflight names offending values if a deployed env
113
+ * somehow holds dupes when the index first lands.
114
+ */
115
+ email: new db_1.StringColumn('email', { unique: { unique: true, indexName: 'user_email_unique' } }, 250),
52
116
  password: new db_1.PasswordColumn('password'),
53
117
  passwordResetToken: new db_1.StringColumn('password_reset_token'),
54
118
  passwordResetTokenExpiration: new db_1.DateTimeColumn('password_reset_token_expiration'),
@@ -62,6 +126,11 @@ var UserTable = /** @class */ (function (_super) {
62
126
  invitedBy: new db_1.StringColumn('invited_by'),
63
127
  avatarEmoji: new db_1.StringColumn('avatar_emoji'),
64
128
  avatarFileId: new db_1.StringColumn('avatar_file_id'),
129
+ status: new db_1.StringColumn('status', { defaultValue: function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
130
+ return [2 /*return*/, 'active'];
131
+ }); }); } }, 16),
132
+ deleteRequestedAt: new db_1.DateTimeColumn('delete_requested_at'),
133
+ purgeAfter: new db_1.DateTimeColumn('purge_after'),
65
134
  });
66
135
  return _this;
67
136
  }
@@ -1 +1 @@
1
- {"version":3,"file":"UserTable.js","sourceRoot":"","sources":["../../../src/tables/UserTable.ts"],"names":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