export interface AuthQueryScopeInput { authUserId: string | null; accountKey: string | null; msalConfigured: boolean; msalReady: boolean; } interface ExecuteAuthScopedQueryInput { accountKey: string | null; acquireAccessToken: () => Promise; request: (authorizationHeader: string | null) => Promise; } export function resolveAuthQueryScope({ authUserId, accountKey, msalConfigured, msalReady, }: AuthQueryScopeInput) { return { cacheKey: [authUserId, accountKey] as const, ready: Boolean(authUserId || !msalConfigured || msalReady), }; } export async function executeAuthScopedQuery({ accountKey, acquireAccessToken, request, }: ExecuteAuthScopedQueryInput): Promise { if (!accountKey) return request(null); const accessToken = await acquireAccessToken(); return request(`Bearer ${accessToken}`); }