// "Fill in console": the store forms without an API (App Store app record, age rating, App Privacy; Play Create app, // content rating, target audience). Click -> dry run of `console.fill` (the answers from the config, nothing opens) -> this // panel lists them, the uncertain ones marked for the owner, with the disclaimer -> "Open the browser" goes through // write_with_confirm (the host shows the answers again in a native dialog and mints the token only on its button) -> // a visible browser the owner signs in to; storebound fills the fields, moves through the pages and never submits or publishes. The run // lasts until the owner closes that browser; Cancel here stops the command, which closes it. import { failureText } from '../lib/results'; import { type KeyboardEvent, useEffect, useRef, useState } from 'react'; import { api, type ConsoleFillResult, type ConsoleForm, errorText, newJob, onProgress, type Project, type ToolResult } from '../api'; import { type Key, t } from '../i18n'; import { useData } from '../store'; import { Icon, StoreGlyph } from './icons'; import { Chip, Notice } from './kit'; export const CONSOLE_FORM_NAME: Record = { 'apple-app-record': 'cf.appleAppRecord', 'apple-age-rating': 'cf.appleAgeRating', 'apple-app-privacy': 'cf.appleAppPrivacy', 'play-app-record': 'cf.playAppRecord', 'play-content-rating': 'cf.playContentRating', 'play-target-audience': 'cf.playTargetAudience', }; type Stage = | { s: 'idle' } | { s: 'dry' } | { s: 'review'; data: ConsoleFillResult; note?: string } | { s: 'running'; data: ConsoleFillResult; job: string; lines: string[] } | { s: 'done'; data: ConsoleFillResult; result: ConsoleFillResult | null; ok: boolean; detail?: string }; const tail = (out: string): string => out.trim().split('\n').filter(Boolean).at(-1)?.replace(/^error:\s*/, '') ?? ''; export function ConsoleFillButton({ project, form, small = true, primary }: { project: Project; form: ConsoleForm; small?: boolean; primary?: boolean }) { const d = useData(); const [st, setSt] = useState({ s: 'idle' }); const name = t(CONSOLE_FORM_NAME[form]); const start = async () => { setSt({ s: 'dry' }); try { const r = await api.call('console.fill', project.id, { args: { form } }, newJob('console.fill-dry')); if (!r.ok || !r.data) { setSt({ s: 'idle' }); d.toast({ kind: 'bad', title: t('cf.dryFailed', { form: name }), detail: failureText(r) }); return; } setSt({ s: 'review', data: r.data }); } catch (e) { setSt({ s: 'idle' }); d.toast({ kind: 'bad', title: t('cf.dryFailed', { form: name }), detail: errorText(e) }); } }; const open = async (data: ConsoleFillResult) => { const job = newJob('console.fill'); setSt({ s: 'running', data, job, lines: [] }); const un = onProgress(p => { if (p.job !== job || !p.line?.trim()) return; setSt(x => (x.s === 'running' && x.job === job ? { ...x, lines: [...x.lines, p.line!].slice(-12) } : x)); }); try { const o = await api.writeWithConfirm('console.fill', project.id, { form }, job); if (o.stage === 'dialog') setSt({ s: 'review', data, note: t('cf.notOpened') }); else if (o.stage === 'dry-run') setSt({ s: 'done', data, result: null, ok: false, detail: tail(o.dryRun.output) }); else { const res = (o.result?.data ?? null) as ConsoleFillResult | null; setSt({ s: 'done', data, result: res, ok: !!o.result?.ok, detail: o.result?.ok ? undefined : o.result ? failureText(o.result) : undefined }); } } catch (e) { const msg = errorText(e); setSt({ s: 'done', data, result: null, ok: /cancel/i.test(msg), detail: /cancel/i.test(msg) ? t('cf.cancelled') : msg }); } finally { un.then(f => f()); } }; const busy = st.s === 'dry'; return ( <> {(st.s === 'review' || st.s === 'running' || st.s === 'done') && ( { open(st.data); }} onCancel={() => { if (st.s === 'running') api.cancel(st.job).catch(() => {}); }} onClose={() => setSt({ s: 'idle' })} /> )} ); } function FillPanel({ st, name, onOpen, onCancel, onClose }: { st: Extract; name: string; onOpen: () => void; onCancel: () => void; onClose: () => void; }) { const root = useRef(null); useEffect(() => { root.current?.focus(); }, []); const running = st.s === 'running'; const data = st.data; const onKey = (e: KeyboardEvent) => { if (e.key === 'Escape' && !running) { e.preventDefault(); onClose(); } }; return (
{ if (e.target === e.currentTarget && !running) onClose(); }}>

{t('cf.panelTitle', { form: data.title || name })}

{data.store === 'apple' ? 'App Store Connect' : 'Google Play Console'}
{t('cf.disclaimer')} {st.s === 'review' && st.note && {st.note}} {running && {t('cf.runningText')}} {st.s === 'done' && (st.ok ? {st.result ? t('cf.doneText', { filled: st.result.filled ?? 0, highlighted: st.result.highlighted ?? 0 }) : st.detail ?? t('cf.closed')} : {t('cf.failed')}{st.detail ? `: ${st.detail}` : ''})} {st.s === 'done' && st.result?.fallback ? {t('cf.fallback')} : null}
{t('cf.answers', { count: data.answers.length })}{data.uncertain > 0 && {t('cf.uncertain', { count: data.uncertain })}}
{!data.answers.length ? {t('cf.noAnswers')} : ( {data.answers.map(a => ( ))}
{a.label}
{(a.note || a.source) &&
{a.note ?? a.source}
}
{a.certain ? {a.value} : {t('cf.youAnswer')}}
)}
{data.guidance.length > 0 &&
    {data.guidance.map((g, i) =>
  • {g}
  • )}
} {running && st.lines.length > 0 &&
{st.lines.join('\n')}
}
{st.s === 'review' ? t('cf.foot') : null}
{running ? : } {st.s === 'review' && } {running && {t('cf.waiting')}}
); }