UNPKG

@accounter/server

Version:
42 lines (41 loc) 2.02 kB
import DataLoader from 'dataloader'; import { TenantAwareDBClient } from '../../app-providers/tenant-db-client.js'; import { AuthContextProvider } from '../../auth/providers/auth-context.provider.js'; import type { AdminContext, IGetAdminContextsResult, IUpdateAdminContextParams } from '../types.js'; export declare class AdminContextProvider { private authContextProvider; private db; private authContext; private authContextInitialized; private cachedContext; private cachedContextInitializing; constructor(authContextProvider: AuthContextProvider, db: TenantAwareDBClient); normalizeContext(rawContext: IGetAdminContextsResult): AdminContext; getAdminContext(): Promise<AdminContext | null>; getVerifiedAdminContext(): Promise<AdminContext>; updateAdminContext(params: IUpdateAdminContextParams): Promise<AdminContext | null>; /** * Write-through adapter for the legacy typed provider/authority business inputs: * upsert the matching admin_business_roles rows so the role-derived arrays stay * consistent when those inputs are used. Additive only (ON CONFLICT DO NOTHING) — * removals are owned by the Phase 2 data-source API. No-op (and no query) when * the update carries none of these inputs. */ private syncProviderBusinessRoles; private batchAdminContextsByOwnerIds; adminContextByOwnerIdLoader: DataLoader<string, AdminContext | null, string>; clearCache(): void; /** * Resolve the owner business for this request. * - Single-business read scope selects that business. * - Multi-business scope prefers the primary tenant business only when it is * part of the scope; otherwise the first scoped business is used. * - No scope falls back to the primary tenant business. */ private resolveOwnerIdForRequest; /** * Lazy initialization of auth context on first use. * This ensures the async provider is called only when needed. */ private ensureAuthContext; }