fix: close competition cutover integrity gaps
This commit is contained in:
1 parent
7ea2002975
commit
683d602d63
57 files changed
+4805
-1582
No files matched your search
+87
-48
@@ -5,6 +5,9 @@ import type {
|
||||
CompetitionCommandResponse,
|
||||
CompetitionDetailResponse,
|
||||
CreateSeriesAdjudicationRequest,
|
||||
MatchDetailResponse,
|
||||
MatchLifecycleStatus,
|
||||
MatchListResponse,
|
||||
ReverseSeriesResultRequest,
|
||||
SeriesId,
|
||||
SeriesReversalPreviewRequest,
|
||||
@@ -18,6 +21,10 @@ import {
|
||||
MSAL_API_SCOPE,
|
||||
MSAL_SILENT_REDIRECT_URI,
|
||||
} from '../lib/auth/msal.config';
|
||||
import {
|
||||
executeAuthScopedQuery,
|
||||
resolveAuthQueryScope,
|
||||
} from './auth-query-scope';
|
||||
import type {
|
||||
ApiAuction,
|
||||
ApiAuctionHistoryEntry,
|
||||
@@ -31,7 +38,6 @@ import type {
|
||||
LegacyImportJobsResponse,
|
||||
LegacyImportMembersResponse,
|
||||
LegacyMatchListResponse,
|
||||
ApiMatch,
|
||||
ApiRecentMatchesResponse,
|
||||
ApiRecentSummaryResponse,
|
||||
ApiTeamInsightsResponse,
|
||||
@@ -41,9 +47,7 @@ import type {
|
||||
DdragonManifest,
|
||||
StartLegacyImportRequest,
|
||||
StartLegacyImportResponse,
|
||||
MatchStatus,
|
||||
MatchMutationRequest,
|
||||
MatchesResponse,
|
||||
ManualTournamentResultCollectResponse,
|
||||
MeResponse,
|
||||
RiotQueueGroup,
|
||||
@@ -59,7 +63,7 @@ import type {
|
||||
const DDRAGON_MANIFEST_STALE_MS = 24 * 60 * 60 * 1000;
|
||||
|
||||
interface MatchesQueryOptions {
|
||||
status?: MatchStatus;
|
||||
status?: MatchLifecycleStatus;
|
||||
limit?: number;
|
||||
page?: number;
|
||||
offset?: number;
|
||||
@@ -101,6 +105,45 @@ function createMatchesPath(
|
||||
return `/communities/${communityId}/matches${queryString ? `?${queryString}` : ''}`;
|
||||
}
|
||||
|
||||
function useOptionalAuthQueryScope() {
|
||||
const authUserId = useAuthUserId();
|
||||
const { accounts, inProgress, instance } = useMsal();
|
||||
const account = isMsalConfigured
|
||||
? (instance.getActiveAccount() ?? accounts[0] ?? null)
|
||||
: null;
|
||||
const scope = resolveAuthQueryScope({
|
||||
authUserId,
|
||||
accountKey: account?.homeAccountId ?? null,
|
||||
msalConfigured: isMsalConfigured,
|
||||
msalReady: inProgress === InteractionStatus.None,
|
||||
});
|
||||
|
||||
const fetch = <T>(path: string) =>
|
||||
executeAuthScopedQuery({
|
||||
accountKey: account?.homeAccountId ?? null,
|
||||
acquireAccessToken: async () => {
|
||||
if (!account) {
|
||||
throw new Error('MSAL account is unavailable.');
|
||||
}
|
||||
const response = await instance.acquireTokenSilent({
|
||||
account,
|
||||
scopes: [MSAL_API_SCOPE],
|
||||
redirectUri: MSAL_SILENT_REDIRECT_URI,
|
||||
});
|
||||
return response.accessToken;
|
||||
},
|
||||
request: (authorizationHeader) =>
|
||||
apiFetch<T>(
|
||||
path,
|
||||
authorizationHeader
|
||||
? { headers: { Authorization: authorizationHeader } }
|
||||
: undefined,
|
||||
),
|
||||
});
|
||||
|
||||
return { ...scope, fetch };
|
||||
}
|
||||
|
||||
export function useCommunity(communityId = DEFAULT_COMMUNITY_ID) {
|
||||
return useQuery({
|
||||
queryKey: ['community', communityId],
|
||||
@@ -114,10 +157,13 @@ export function useMatches(
|
||||
options: MatchesQueryOptions,
|
||||
communityId = DEFAULT_COMMUNITY_ID,
|
||||
) {
|
||||
const authScope = useOptionalAuthQueryScope();
|
||||
|
||||
return useQuery({
|
||||
queryKey: [
|
||||
'matches',
|
||||
communityId,
|
||||
...authScope.cacheKey,
|
||||
options.status ?? null,
|
||||
options.limit ?? null,
|
||||
options.page ?? null,
|
||||
@@ -127,13 +173,12 @@ export function useMatches(
|
||||
options.sort ?? null,
|
||||
],
|
||||
queryFn: async () => {
|
||||
const response = await apiFetch<MatchesResponse>(
|
||||
const response = await authScope.fetch<MatchListResponse>(
|
||||
createMatchesPath(communityId, options),
|
||||
{ auth: 'none' },
|
||||
);
|
||||
return response.matches;
|
||||
},
|
||||
enabled: Boolean(communityId),
|
||||
enabled: Boolean(communityId && authScope.ready),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -141,10 +186,13 @@ export function useMatchesPage(
|
||||
options: MatchesQueryOptions,
|
||||
communityId = DEFAULT_COMMUNITY_ID,
|
||||
) {
|
||||
const authScope = useOptionalAuthQueryScope();
|
||||
|
||||
return useQuery({
|
||||
queryKey: [
|
||||
'matches-page',
|
||||
communityId,
|
||||
...authScope.cacheKey,
|
||||
options.status ?? null,
|
||||
options.limit ?? null,
|
||||
options.page ?? null,
|
||||
@@ -154,10 +202,10 @@ export function useMatchesPage(
|
||||
options.sort ?? null,
|
||||
],
|
||||
queryFn: () =>
|
||||
apiFetch<MatchesResponse>(createMatchesPath(communityId, options), {
|
||||
auth: 'none',
|
||||
}),
|
||||
enabled: Boolean(communityId),
|
||||
authScope.fetch<MatchListResponse>(
|
||||
createMatchesPath(communityId, options),
|
||||
),
|
||||
enabled: Boolean(communityId && authScope.ready),
|
||||
placeholderData: (previousData) => previousData,
|
||||
});
|
||||
}
|
||||
@@ -166,15 +214,25 @@ export function useMatch(
|
||||
matchId: string | undefined,
|
||||
communityId = DEFAULT_COMMUNITY_ID,
|
||||
) {
|
||||
return useQuery({
|
||||
queryKey: ['match', communityId, matchId ?? null],
|
||||
const authScope = useOptionalAuthQueryScope();
|
||||
const queryKey = [
|
||||
'match',
|
||||
communityId,
|
||||
matchId ?? null,
|
||||
...authScope.cacheKey,
|
||||
] as const;
|
||||
|
||||
const query = useQuery({
|
||||
queryKey,
|
||||
queryFn: () =>
|
||||
apiFetch<ApiMatch>(`/communities/${communityId}/matches/${matchId}`, {
|
||||
auth: 'none',
|
||||
}),
|
||||
enabled: Boolean(communityId && matchId),
|
||||
authScope.fetch<MatchDetailResponse>(
|
||||
`/communities/${communityId}/matches/${matchId}`,
|
||||
),
|
||||
enabled: Boolean(communityId && matchId && authScope.ready),
|
||||
retry: false,
|
||||
});
|
||||
|
||||
return { ...query, queryKey };
|
||||
}
|
||||
|
||||
export function useCompetition(
|
||||
@@ -426,7 +484,7 @@ export function useResetAuction(communityId = DEFAULT_COMMUNITY_ID) {
|
||||
export function useCreateMatch(communityId = DEFAULT_COMMUNITY_ID) {
|
||||
return useMutation({
|
||||
mutationFn: (body: MatchMutationRequest) =>
|
||||
apiFetch<ApiMatch>(`/communities/${communityId}/matches`, {
|
||||
apiFetch<MatchDetailResponse>(`/communities/${communityId}/matches`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(body),
|
||||
}),
|
||||
@@ -442,10 +500,13 @@ export function useUpdateMatch(communityId = DEFAULT_COMMUNITY_ID) {
|
||||
matchId: string;
|
||||
body: Partial<MatchMutationRequest>;
|
||||
}) =>
|
||||
apiFetch<ApiMatch>(`/communities/${communityId}/matches/${matchId}`, {
|
||||
method: 'PATCH',
|
||||
body: JSON.stringify(body),
|
||||
}),
|
||||
apiFetch<MatchDetailResponse>(
|
||||
`/communities/${communityId}/matches/${matchId}`,
|
||||
{
|
||||
method: 'PATCH',
|
||||
body: JSON.stringify(body),
|
||||
},
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1028,34 +1089,12 @@ export function useRebuildLegacyMatches(communityId = DEFAULT_COMMUNITY_ID) {
|
||||
}
|
||||
|
||||
export function useMe() {
|
||||
const authUserId = useAuthUserId();
|
||||
const { accounts, inProgress, instance } = useMsal();
|
||||
const account = isMsalConfigured
|
||||
? (instance.getActiveAccount() ?? accounts[0] ?? null)
|
||||
: null;
|
||||
const accountKey = account?.homeAccountId ?? null;
|
||||
const isMsalReady =
|
||||
!isMsalConfigured || inProgress === InteractionStatus.None;
|
||||
const authScope = useOptionalAuthQueryScope();
|
||||
|
||||
return useQuery({
|
||||
queryKey: ['me', authUserId, accountKey],
|
||||
queryFn: async () => {
|
||||
if (!account) {
|
||||
return apiFetch<MeResponse>('/me');
|
||||
}
|
||||
|
||||
const response = await instance.acquireTokenSilent({
|
||||
account,
|
||||
scopes: [MSAL_API_SCOPE],
|
||||
redirectUri: MSAL_SILENT_REDIRECT_URI,
|
||||
});
|
||||
return apiFetch<MeResponse>('/me', {
|
||||
headers: {
|
||||
Authorization: `Bearer ${response.accessToken}`,
|
||||
},
|
||||
});
|
||||
},
|
||||
enabled: Boolean(authUserId || isMsalReady),
|
||||
queryKey: ['me', ...authScope.cacheKey],
|
||||
queryFn: () => authScope.fetch<MeResponse>('/me'),
|
||||
enabled: authScope.ready,
|
||||
retry: false,
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user