fix: close competition cutover integrity gaps

This commit is contained in:
dahyeon committed 2026-07-12 21:22:22 +00:00
1 parent 7ea2002975
commit 683d602d63
57 files changed
+4805 -1582

No files matched your search

+35
View File
@@ -0,0 +1,35 @@
export interface AuthQueryScopeInput {
authUserId: string | null;
accountKey: string | null;
msalConfigured: boolean;
msalReady: boolean;
}
interface ExecuteAuthScopedQueryInput<T> {
accountKey: string | null;
acquireAccessToken: () => Promise<string>;
request: (authorizationHeader: string | null) => Promise<T>;
}
export function resolveAuthQueryScope({
authUserId,
accountKey,
msalConfigured,
msalReady,
}: AuthQueryScopeInput) {
return {
cacheKey: [authUserId, accountKey] as const,
ready: Boolean(authUserId || !msalConfigured || msalReady),
};
}
export async function executeAuthScopedQuery<T>({
accountKey,
acquireAccessToken,
request,
}: ExecuteAuthScopedQueryInput<T>): Promise<T> {
if (!accountKey) return request(null);
const accessToken = await acquireAccessToken();
return request(`Bearer ${accessToken}`);
}
+87 -48
View File
@@ -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,
});
}
+11 -7
View File
@@ -1,15 +1,17 @@
import type {
MatchDetailResponse,
MatchLifecycleStatus,
MatchParticipantView,
} from "@lolympus/contracts";
import type {
ApiAuction,
ApiAuctionPlayerSnapshot,
ApiAuctionTeam,
ApiMatch,
ApiMatchParticipant,
ApiPositionPreference,
ApiRiotLaneStats,
ApiRiotRecentStatsSummary,
ApiTierHistoryEntry,
ApiTierInfo,
MatchStatus,
Position,
RiotLane,
} from "./types";
@@ -46,7 +48,7 @@ export interface MatchDetailView {
title: string;
date: string;
time: string;
status: MatchStatus;
status: MatchLifecycleStatus;
description: string;
map: string;
maxParticipants: number;
@@ -180,7 +182,7 @@ function resolveMainAndSubPosition(
}
function mapMatchParticipantToView(
participant: ApiMatchParticipant,
participant: MatchParticipantView,
): ParticipantView {
const { mainPosition, subPosition } = resolveMainAndSubPosition(
participant.preferredPositions,
@@ -383,7 +385,9 @@ export function buildDefaultPreferredPositions() {
}));
}
export function mapApiMatchToMatchDetail(match: ApiMatch): MatchDetailView {
export function mapApiMatchToMatchDetail(
match: MatchDetailResponse,
): MatchDetailView {
const formattedDate = formatKoreanDate(match.scheduledAt);
const participants = match.participants.map(mapMatchParticipantToView);
const participantLookup = new Map(
@@ -439,7 +443,7 @@ export function mapApiMatchToMatchDetail(match: ApiMatch): MatchDetailView {
export function mapApiAuctionToAuctionState(
auction: ApiAuction,
match: ApiMatch,
match: MatchDetailResponse,
now = new Date(),
): AuctionStateView {
const participantLookup = new Map(
+12 -87
View File
@@ -1,15 +1,14 @@
export type Position = 'TOP' | 'JGL' | 'MID' | 'ADC' | 'SUP';
import type {
MatchGameMode,
MatchPosition,
MatchPositionPreferenceView,
MatchScheduleItemView,
MatchTierView,
} from '@lolympus/contracts';
export type Position = MatchPosition;
export type RiotLane = 'TOP' | 'JUNGLE' | 'MIDDLE' | 'BOTTOM' | 'UTILITY';
export type TeamSide = 'blue' | 'red';
export type MatchGameMode =
| 'pair'
| 'round-robin'
| 'double-elimination';
export type MatchStatus =
| 'recruiting'
| 'team-built'
| 'in-progress'
| 'finished';
export type AuctionPhase =
| 'waiting'
| 'presenting'
@@ -25,20 +24,8 @@ export type AuctionTopTierThreshold =
| 'MANUAL';
export type CommunityRole = 'owner' | 'admin' | 'member';
export interface ApiPositionPreference {
position: Position;
priority: number;
}
export interface ApiTierInfo {
queueType: string;
tier: string;
rank: string;
leaguePoints: number;
wins: number;
losses: number;
fetchedAt: string;
}
export type ApiPositionPreference = MatchPositionPreferenceView;
export type ApiTierInfo = MatchTierView;
export interface ApiChampionMasteryEntry {
puuid?: string;
@@ -142,36 +129,6 @@ export type TournamentCodeState =
| 'released'
| 'voided';
export interface ApiMatchParticipant {
userId: string;
puuid?: string;
gameName?: string;
tagLine?: string;
profileIconId?: number;
tier?: ApiTierInfo;
preferredPositions: ApiPositionPreference[];
joinedAt: string;
excluded?: boolean;
}
export interface ApiMatchTeamMember {
userId: string;
assignedPosition: Position;
cost?: number;
}
export interface ApiMatchTeam {
teamIndex: number;
name: string;
captainUserId?: string;
members: ApiMatchTeamMember[];
}
export interface ApiMatchScheduleItem {
time: string;
label: string;
}
export interface ManualTournamentResultCollectResponse {
scanned: number;
matched: number;
@@ -180,31 +137,6 @@ export interface ManualTournamentResultCollectResponse {
gameNumbers: number[];
}
export interface ApiMatch {
_id: string;
communityId: string;
shortCode?: string;
title: string;
description: string;
mapId: number;
status: MatchStatus;
scheduledAt: string;
maxParticipants: number;
gameCount: number;
gameMode: MatchGameMode;
roundRobinMaxRounds?: number;
doubleEliminationResetFinalEnabled?: boolean;
hostUserId?: string;
participants: ApiMatchParticipant[];
teams: ApiMatchTeam[];
prizes: string[];
notices: string[];
schedule: ApiMatchScheduleItem[];
joined?: boolean;
createdAt: string;
updatedAt: string;
}
export interface ApiAuctionPlayerSnapshot {
userId: string;
puuid: string;
@@ -336,13 +268,6 @@ export interface MeResponse {
memberships: ApiMembership[];
}
export interface MatchesResponse {
matches: ApiMatch[];
total: number;
page: number;
limit: number;
}
export interface MatchMutationRequest {
title: string;
description?: string;
@@ -355,7 +280,7 @@ export interface MatchMutationRequest {
doubleEliminationResetFinalEnabled?: boolean;
prizes?: string[];
notices?: string[];
schedule?: ApiMatchScheduleItem[];
schedule?: MatchScheduleItemView[];
}
export interface DdragonChampionEntry {