@proteinjs/user 1.20.0 → 1.20.2

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.
@@ -22,24 +22,32 @@ export const getMachineAccounts = (): MachineAccount[] =>
22
22
  * A code-declared machine account: identity in source, credentials at runtime.
23
23
  *
24
24
  * Extend this (server-side — declarations name real operational emails and grants) to declare a
25
- * machine account into the `user` table. The boot sync inserts it on first boot of a fresh env,
26
- * ADOPTS an existing row by email in deployed envs (id kept — rows the account filed reference
27
- * it; password kept — the credential is runtime-owned), reverts the declared fields on every
28
- * boot (a runtime grant/revoke on a machine account is drift), and deactivates the account —
29
- * sessions killed, never deleted — when the declaration is removed. Re-declaring a removed
30
- * account reactivates it, even under a renamed email: the user table soft-removes (keeps rows),
31
- * so the sync re-adopts the kept row by its stable declared id and re-derives its state from
32
- * the declaration (id and minted credential survive; no stale grants resurrect). Git history of
33
- * the declaration is the machine-grant audit trail; the Roles service refuses machine targets.
25
+ * machine account into the `user` table. The boot sync inserts it on the first boot that
26
+ * carries the declaration, matches it by email on every boot after (an account an earlier build
27
+ * adopted keeps its environment's own id — rows the account filed reference it), reverts the
28
+ * declared fields on every boot (a runtime grant/revoke on a machine account is drift), and
29
+ * deactivates the account — sessions killed, never deleted — when the declaration is removed.
30
+ * Re-declaring a removed account reactivates it, even under a renamed email: the user table
31
+ * soft-removes (keeps rows), so the sync re-adopts the kept row by its stable declared id and
32
+ * re-derives its state from the declaration (id and minted credential survive; no stale grants
33
+ * resurrect). Git history of the declaration is the machine-grant audit trail; the Roles service
34
+ * refuses machine targets.
35
+ *
36
+ * A declared address held by a row the sync does not own — a person who registered it, or a row
37
+ * made by hand — is NEVER taken over: the boot refuses the declaration (the row untouched, the
38
+ * boot continuing, one warning naming the declaration), so no one inherits the declared roles
39
+ * with a password of their own. The machine-accounts list shows the refusal and the mint refuses;
40
+ * the account is created by the first boot after that row is gone. Signup refuses a declared
41
+ * address outright.
34
42
  *
35
43
  * A `password` is deliberately NOT declarable: a fresh machine row has a NULL password, which
36
44
  * `authenticate`'s verify treats as matching no password at all, so "account exists" can never
37
45
  * reach "account can log in" without the explicit credential mint (`MachineCredentialsService`).
38
46
  */
39
47
  export abstract class MachineAccount implements SourceRecordLoader<User> {
40
- /** Stable id, used ONLY when inserting into a fresh env — existing rows adopt by email. */
48
+ /** Stable id, used ONLY when the boot sync inserts the row — the sync matches rows by email. */
41
49
  abstract id: string;
42
- /** The account's email (lowercase — validated at boot). The natural key adoption matches on. */
50
+ /** The account's email (lowercase — validated at boot). The natural key the sync matches on. */
43
51
  abstract email: string;
44
52
  /** Display name shown wherever the account's actions surface. */
45
53
  abstract accountName: string;
@@ -69,9 +77,8 @@ export abstract class MachineAccount implements SourceRecordLoader<User> {
69
77
  // No mailbox ceremony for machines; forced so runtime flips get reverted.
70
78
  emailVerified: true,
71
79
  // The explicit machine marker (founder ruling 2026-09-02): the declaration IS the
72
- // stamp — inserts are born with it, adopted hand-made rows converge on the next boot
73
- // (ordinary drift reversion), and existing source-loaded accounts pick it up the same
74
- // way with no backfill migration.
80
+ // stamp — inserts are born with it, and existing source-loaded accounts converge on the
81
+ // next boot (ordinary drift reversion) with no backfill migration.
75
82
  machine: true,
76
83
  // Source-owned on purpose: re-declaring a removed (auto-deactivated) account is what
77
84
  // reactivates it, via normal drift reversion.
@@ -80,7 +87,7 @@ export abstract class MachineAccount implements SourceRecordLoader<User> {
80
87
  // `User.password` is a required column, but a machine declaration NEVER emits a password
81
88
  // key — the credential is runtime-owned, minted and stored as a hash by the credential
82
89
  // service. The loader only writes fields present on the record, so the column stays
83
- // untouched on adopted rows and NULL on fresh inserts (unloggable until minted).
90
+ // untouched on the account's row and NULL on fresh inserts (unloggable until minted).
84
91
  } as unknown as SourceRecordLoader<User>['record'];
85
92
  }
86
93
 
@@ -16,15 +16,26 @@ export type MintedMachineCredential = {
16
16
  note: string;
17
17
  };
18
18
 
19
+ /**
20
+ * Why the boot sync refused a machine-account declaration: a row it does not own holds the
21
+ * declared address, and the sync never takes such a row over.
22
+ */
23
+ export type MachineAccountRefusal = 'a person holds this address' | 'a hand-made machine row holds this address';
24
+
19
25
  /** A declared machine account joined with its row state — the admin surface renders these. */
20
26
  export type MachineAccountView = {
21
27
  email: string;
22
28
  accountName: string;
23
29
  roles: string[];
24
30
  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). */
31
+ /**
32
+ * 'pending first boot' until the boot sync has created the row; 'declaration refused' while a row
33
+ * the sync does not own holds the address (the sync never takes it over — `refusal` says whose).
34
+ */
35
+ status: 'active' | 'deactivated' | 'pending first boot' | 'declaration refused';
36
+ /** Why the declaration was refused — present exactly when `status` is 'declaration refused'. */
37
+ refusal?: MachineAccountRefusal;
38
+ /** Whether a credential has been minted for the account (hash present on its own row). */
28
39
  hasCredential: boolean;
29
40
  };
30
41
 
@@ -34,7 +45,8 @@ export type MachineAccountView = {
34
45
  * strong random password, stores its hash on the account row (no human-chosen passwords), kills
35
46
  * the account's sessions, and returns the plaintext once for pasting into the declaration's
36
47
  * Secret Manager secret. The same call rotates. Machine rows only — human credentials go
37
- * through the password-reset flow.
48
+ * through the password-reset flow, and a declaration the boot sync refused has no row to mint
49
+ * for (the mint says why).
38
50
  */
39
51
  export interface MachineCredentialsService extends Service {
40
52
  /** Every declared machine account with its row state, for the admin surface. */
@@ -57,9 +57,11 @@ export type User = SourceRecord & {
57
57
  * pre-existing human rows need no backfill (the `status`/opt-out null-default convention).
58
58
  * ONE owner for the question "is this a machine": every consumer (audience derivations,
59
59
  * people lists, purge walkers) reads THIS column — never `isLoadedFromSource`, which merely
60
- * says who SYNCS the row. Stamped true by the `MachineAccount` declaration on every boot
61
- * (insert and adopt alike), by provisioning migrations for hand-made machine rows, and by
62
- * the source-loaded backfill (user-server BackfillMachineFlagForSourceLoadedAccounts).
60
+ * says who SYNCS the row. Stamped true by the `MachineAccount` declaration (on insert and on
61
+ * every boot after), by provisioning migrations for hand-made machine rows, and by
62
+ * the source-loaded backfill (user-server BackfillMachineFlagForSourceLoadedAccounts). A
63
+ * hand-made row marked machine is still never taken over by a declaration (the sync refuses a
64
+ * row it does not own) — the marker only says what the row is.
63
65
  */
64
66
  machine?: boolean | null;
65
67
  /**
@@ -111,12 +113,13 @@ export class UserTable extends Table<User> {
111
113
  serviceProtectedColumns: ['roles', 'status', 'deleteRequestedAt', 'purgeAfter', 'isLoadedFromSource'],
112
114
  };
113
115
  /**
114
- * Machine accounts sync by EMAIL, not id: existing envs hold hand-made machine rows with
115
- * env-random ids that other rows reference — the boot sync adopts them in place (id kept,
116
- * declared fields reverted, runtime fields like `password` untouched). Removal from source
117
- * deactivates (the same status the staff toggle and account deletion write — the
118
- * UserStatusTableWatcher kills sessions on every deactivation write); re-declaring
119
- * reactivates via normal drift reversion.
116
+ * Machine accounts sync by EMAIL, not id: accounts adopted from hand-made rows before
117
+ * declarations existed keep their env-random ids, which other rows reference (declared fields
118
+ * reverted, runtime fields like `password` untouched). A row the sync does not own under a
119
+ * declared email — a person's signup, a hand-made row — is never taken over: the natural key
120
+ * refuses the declaration (@proteinjs/db). Removal from source deactivates (the same status the
121
+ * staff toggle and account deletion write — the UserStatusTableWatcher kills sessions on every
122
+ * deactivation write); re-declaring reactivates via normal drift reversion.
120
123
  */
121
124
  sourceRecordOptions: Table<User>['sourceRecordOptions'] = {
122
125
  naturalKey: 'email',