Skip to content

Commit 361581a

Browse files
committed
refactor(plugin-auth): move the organization plugin factory into auth-manager-organization-plugin.ts
The body of the arrow AuthManager.buildPluginList() hands addOptionalPlugin for 'organization' moves unedited into the module function buildOrganizationPlugin, re-indented two levels: the closed organization-role vocabulary and the roles map built from it, the options object (schema, teams, the invitation verification declaration, the organization and membership limits, the organization hooks with their refusal codes, the invitation e-mail), the vendor plugin and the rebuilt invitation listing. The arrow keeps its place in buildPluginList; it now builds one host of the ten AuthManager members the body reads (eight methods as late-bound closures, config as a getter, orgRolesMap as a get/set pair because the body stores the roles map on the manager) and returns buildOrganizationPlugin.call(host). The async moved from the arrow to the function. The eight top-level declarations of auth-manager.ts the body reads and the file did not export (five hook refusal codes, two read-fault answers and the placement gate's refusal test) are exported in place and imported by value, with readInvitationPlacementIntent; src/index.ts names its auth-manager.ts exports one by one, so nothing new is published. Fifteen imported names leave auth-manager.ts with the body. Readers that follow it: the api-error-code pin counts the module among the AuthManager files, the two plugin-factory scans read it, the population comments in auth-email-locale.test.ts name it, and the module gets its own ADR anchor entry carrying the ADR-0108 paragraph verbatim, since the body is the roles map that paragraph describes. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LSXBc2GCBwiAL7vV4kWkyr
1 parent ba9e0c3 commit 361581a

7 files changed

Lines changed: 734 additions & 608 deletions

‎packages/plugins/plugin-auth/src/api-error-code.pin.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ describe('every new APIError( in plugin-auth/src carries an ADR-0112 code (#2424
182182
'auth-manager-password-session-policy.ts',
183183
'auth-manager-email-sms-delivery.ts',
184184
'auth-manager-before-hook.ts',
185+
'auth-manager-organization-plugin.ts',
185186
];
186187
expect(sites.length).toBeGreaterThanOrEqual(30);
187188
expect(new Set(sites.map((s) => s.file)).size).toBeGreaterThanOrEqual(4);

‎packages/plugins/plugin-auth/src/auth-email-locale.test.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -859,8 +859,9 @@ describe("#14641 — an invitation reads the INVITEE's own sys_user.locale", ()
859859
* ⚠️ POPULATION of the class claim these blocks close, stated rather than
860860
* implied: the auth mail surface is the five `sendTemplate` call sites in
861861
* `auth-manager.ts`, `auth-manager-auth-instance.ts` (the body of
862-
* `createAuthInstance`) and `auth-manager-email-sms-delivery.ts` (the body of
863-
* the change-email notice) — `IEmailService` declares exactly two delivering
862+
* `createAuthInstance`), `auth-manager-organization-plugin.ts` (the body of
863+
* the organization plugin's factory) and `auth-manager-email-sms-delivery.ts`
864+
* (the body of the change-email notice) — `IEmailService` declares exactly two delivering
864865
* members (`send`, `sendTemplate`), plugin-auth's only `.send(` calls are the
865866
* SMS service's, and no other file under `plugin-auth/src` calls either.
866867
* Those five are the same five `driveAllFive` above drives and `TEMPLATES`
@@ -1124,8 +1125,8 @@ describe('#15106 — the CLASS claim: all five auth sends read the recipient col
11241125

11251126
it('every one of the five sends is written in the stored language of its own recipient', async () => {
11261127
// ⚠️ POPULATION: the five `sendTemplate` sites in `auth-manager.ts`,
1127-
// `auth-manager-auth-instance.ts` and `auth-manager-email-sms-delivery.ts`
1128-
// — the same five `driveAllFive` drives and `TEMPLATES` names, and the whole of
1128+
// `auth-manager-auth-instance.ts`, `auth-manager-organization-plugin.ts` and
1129+
// `auth-manager-email-sms-delivery.ts` — the same five `driveAllFive` drives and `TEMPLATES` names, and the whole of
11291130
// plugin-auth's mail surface (see this section's header). This is the pin
11301131
// that closes the class; the per-send pins above only cover one member.
11311132
//

‎packages/plugins/plugin-auth/src/auth-manager-organization-plugin.ts‎

Lines changed: 683 additions & 0 deletions
Large diffs are not rendered by default.

‎packages/plugins/plugin-auth/src/auth-manager.ts‎

Lines changed: 34 additions & 600 deletions
Large diffs are not rendered by default.

‎packages/plugins/plugin-auth/src/better-auth-schema-parity.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,8 @@ function betterAuthPluginSet(): unknown[] {
320320
*/
321321
function authManagerPluginFactories(): string[] {
322322
// [#25224] The auth manager's source: `auth-manager.ts` and the method
323-
// bodies moved out of it whole. A factory imported in either is one it loads.
324-
const source = ['auth-manager.ts', 'auth-manager-actor-guards.ts']
323+
// bodies moved out of it whole. A factory imported in any of them is one it loads.
324+
const source = ['auth-manager.ts', 'auth-manager-actor-guards.ts', 'auth-manager-organization-plugin.ts']
325325
.map((file) => readFileSync(join(PKG, 'src', file), 'utf8'))
326326
.join('\n');
327327
const found = new Set<string>();

‎packages/plugins/plugin-auth/src/managed-extension-fields.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,8 +630,8 @@ function findCollisions(
630630
*/
631631
function authManagerPluginFactories(): string[] {
632632
// [#25224] The auth manager's source: `auth-manager.ts` and the method
633-
// bodies moved out of it whole. A factory imported in either is one it loads.
634-
const source = ['auth-manager.ts', 'auth-manager-actor-guards.ts']
633+
// bodies moved out of it whole. A factory imported in any of them is one it loads.
634+
const source = ['auth-manager.ts', 'auth-manager-actor-guards.ts', 'auth-manager-organization-plugin.ts']
635635
.map((file) => readFileSync(join(HERE, file), 'utf8'))
636636
.join('\n');
637637
const found = new Set<string>();
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"file": "packages/plugins/plugin-auth/src/auth-manager-organization-plugin.ts",
3+
"adrs": [
4+
"ADR-0108"
5+
],
6+
"invariant": "ADR-0108 — better-auth's organization roles map registers the closed framework vocabulary ONLY. App-declared `position` / `permission` names are not organization roles — registering one makes it storable in `sys_member.role`, which `resolve-authz-context` projects into `current_user.positions`."
7+
}

0 commit comments

Comments
 (0)