// A store that could not be read, in one plain line: Google's typed errors (an API turned off in the Cloud project, no // access to the app, a revoked key, a used-up quota) with the button that fixes them, and the raw API text only in a // collapsed "Details" and the log (never a JSON dump in the window). import { useEffect } from 'react'; import { api, errorText } from '../api'; import { type GoogleFinding, parseGoogleError, plainError } from '../../../../cli/lib/google-errors'; import { t, type Key } from '../i18n'; import { useData } from '../store'; import { Icon } from './icons'; import { Notice } from './kit'; const WHAT: Record = { 'playdeveloperreporting.googleapis.com': 'gerr.what.reporting', 'androidpublisher.googleapis.com': 'gerr.what.publisher', 'storage.googleapis.com': 'gerr.what.storage', 'storage-api.googleapis.com': 'gerr.what.storage', }; /** The typed finding of a store read error (from the snapshot, else parsed from its text). */ export function findingOf(e: { error: string; finding?: GoogleFinding; detail?: string }, app?: string | null): GoogleFinding | null { return e.finding ?? parseGoogleError(e.detail ?? e.error, { app }); } /** The one line for a finding, in the window's language. */ export function findingLine(f: GoogleFinding): string { switch (f.kind) { case 'api-disabled': return t('gerr.apiDisabled', { what: t(WHAT[f.service] ?? 'gerr.what.other'), service: f.serviceTitle, project: f.projectId ?? t('gerr.projectUnknown') }); case 'no-app-access': return t('gerr.noAccess', { app: f.app ?? t('gerr.thisApp') }); case 'auth-revoked': return t('gerr.revoked'); case 'quota': return t('gerr.quota'); } } export function TurnOnButton({ url, primary = true }: { url: string; primary?: boolean }) { const d = useData(); return ( ); } /** One store's read error. `unreadable`: the sentence for an unknown error ({store} / {error}). */ export function StoreReadNotice({ store, e, app, onRetry, busy, unreadable }: { store: string; e: { error: string; finding?: GoogleFinding; detail?: string }; app?: string | null; onRetry?: () => void; busy?: boolean; unreadable: Key; }) { const d = useData(); const f = findingOf(e, app); const raw = e.detail ?? e.error; useEffect(() => { api.logWebview('warn', `${store} could not be read${f ? ` (${f.kind})` : ''}`, raw).catch(() => {}); }, [store, raw]); // eslint-disable-line react-hooks/exhaustive-deps const line = f ? findingLine(f) : t(unreadable, { store, error: plainError(raw) }); const retry = onRetry && ; const open = (url: string) => api.openExternal(url).catch(err => d.toast({ kind: 'bad', title: t('gerr.openFailed'), detail: errorText(err) })); return ( {f?.kind === 'api-disabled' && } {f?.kind === 'no-app-access' && } {retry} }>
{line} {raw !== line &&
{t('gerr.details')}
{raw}
}
); } export interface BlockedProject { projectId: string | null; service: string; serviceTitle: string; activationUrl: string; apps: string[] } /** api-disabled findings across apps, one entry per Cloud project and API (several apps share one service account). Pure. */ export function blockedProjects(items: { app: string; errors: ({ error: string; finding?: GoogleFinding; detail?: string } | string | undefined | null)[] }[]): BlockedProject[] { const out = new Map(); for (const it of items) for (const e of it.errors) { if (!e) continue; const f = typeof e === 'string' ? parseGoogleError(e) : findingOf(e); if (f?.kind !== 'api-disabled') continue; const k = `${f.projectId ?? '?'}|${f.service}`; const b = out.get(k) ?? { projectId: f.projectId, service: f.service, serviceTitle: f.serviceTitle, activationUrl: f.activationUrl, apps: [] }; if (!b.apps.includes(it.app)) b.apps.push(it.app); out.set(k, b); } return [...out.values()]; } /** The portfolio's one notice for Cloud projects that block reads of several apps. */ export function BlockedProjectsNotice({ blocked, onRetry, busy }: { blocked: BlockedProject[]; onRetry: () => void; busy: boolean }) { if (!blocked.length) return null; const apps = [...new Set(blocked.flatMap(b => b.apps))]; return ( {t('gerr.checkAgain')}}>
{t('gerr.portfolio', { count: blocked.length, apps: apps.join(', ') })} {blocked.map(b => (
{findingLine({ kind: 'api-disabled', ...b })}
))}
); }