storebound/cli/lib/console-forms.ts
CRT 1d2978d0bb console fill: opens the form itself and reuses the owner's Chrome sign-in
Navigation after sign-in (navPlan + navigate): App Store Connect Apps > + > New App
(EN/TR), App Privacy by /apps/<appId>/distribution/privacy or the app list, Play app
list by package name > Policy and programs > App content > Start / Manage. Every
navigation click goes through navClick: the click gate stays absolute, only a link
named exactly Start / Manage / Başla / Yönet passes. Each step is logged; a step not
found in time or two matching apps -> the printed steps and wait (no crash).
The TR gate now refuses "uygula" (apply) but not "uygulama" (app).

Browser (cli/console/session.ts): attach to a Chrome with remote debugging (--cdp or
DevToolsActivePort), else on macOS a temporary profile with only Local State and the
profile's Cookies filtered to the console hosts, opened in real Chrome and deleted at
the end, else storebound's own profile (--fresh-profile). Cookies are never printed.
Desktop: fresh_profile option, the dialog says it uses the Chrome sign-in.
Tests: navigation fixtures (ASC EN/TR, Play list, App content, missing step,
duplicates, deny-listed decoys), session file selection, host filter, cleanup, and a
real-Chrome copy-mode test on a throwaway profile and a local site.
2026-10-11 18:21:35 +00:00

217 lines
14 KiB
TypeScript

// Where each answer of a console form lives on the page, as accessible names only (role + name / label), never CSS
// paths: `storebound console fill` locates every field of a section first and falls back to printed guidance when one
// is missing or ambiguous (the console UI changed). Several candidate names per field absorb small wording drift.
// Also the click gate (no Save / Submit / Publish / Next ... ever) and the sign-in page detector. Pure.
// The names are modeled on Apple's and Google's public help pages (sources in console-answers.ts), not recorded from a
// signed-in console: the exact App Privacy dialog titles, the IARC question wording and the Play category names could
// not be verified without an account, which is why every field has candidates and the engine falls back on a miss.
import { AGE_GROUPS, type ShipConfig } from './config';
import { AGE_LABELS, type Answer, APPLE_PURPOSES, type FormId } from './console-answers';
/** An accessible name: a string matches exactly, a RegExp matches the name. */
export type Name = string | RegExp;
export interface FieldDef {
/** Answer id. */
id: string;
kind: 'text' | 'select' | 'checkbox' | 'radio';
/** text / select / checkbox: candidate names of the control. radio: candidate names of the radiogroup (optional). */
names?: Name[];
/** radio: answer value (String(value)) -> candidate names of that radio button. */
options?: Record<string, Name[]>;
}
export interface SectionDef {
/** Shown to the owner ("page 2/3: Questionnaire"). */
title: string;
/** Candidate names of the dialog the section lives in; it is present when that dialog is visible. */
dialog?: Name[];
fields: FieldDef[];
}
export interface FormDef { id: FormId; sections: SectionDef[] }
const esc = (s: string): string => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
const yesNo = (yes: Name[] = ['Yes'], no: Name[] = ['No']): Record<string, Name[]> => ({ true: yes, false: no });
/** IARC topics -> candidate radiogroup names (modeled; see the header). */
const IARC_NAMES: Record<string, Name[]> = {
violence: [/^Does the app contain (any )?violen/i, /violen/i],
fear: [/^Does the app contain .*(scary|fear|horror)/i, /(fear|horror)/i],
sexuality: [/^Does the app contain .*(sexual|nudity)/i, /(sexual|nudity)/i],
language: [/^Does the app contain .*(profan|language)/i, /profanit/i],
controlledSubstances: [/^Does the app contain .*(drug|alcohol|tobacco|controlled substance)/i, /controlled substance/i],
crudeHumor: [/crude humou?r/i],
gambling: [/^Does the app (allow|let) .*gambl.*real (money|currency)/i, /real[- ]money gambling/i],
simulatedGambling: [/simulated gambling/i],
lootBoxes: [/(random|randomi[sz]ed) (paid )?items/i, /loot box/i],
userInteraction: [/(users|players) .*(interact|communicate|exchange)/i],
sharesLocation: [/share .*(physical )?location/i],
digitalPurchases: [/digital (goods|purchases)/i, /purchase digital/i],
unrestrictedInternet: [/unrestricted (internet|web)/i, /web browser/i],
};
/** Field definitions for the answers of one form (App Privacy has one section per collected data type). */
export function formDef(id: FormId, answers: Answer[]): FormDef {
const has = (aid: string) => answers.some(a => a.id === aid);
switch (id) {
case 'apple-app-record': return { id, sections: [{ title: 'New App', fields: [
{ id: 'platform:ios', kind: 'checkbox', names: ['iOS'] },
{ id: 'name', kind: 'text', names: ['Name', 'App Name'] },
{ id: 'language', kind: 'select', names: ['Primary Language', 'Primary language'] },
{ id: 'bundleId', kind: 'select', names: ['Bundle ID', 'Bundle Id'] },
{ id: 'sku', kind: 'text', names: ['SKU'] },
{ id: 'access', kind: 'radio', names: ['User Access'], options: { limited: ['Limited Access'], full: ['Full Access'] } },
] }] };
case 'apple-age-rating': return { id, sections: [] };
case 'apple-app-privacy': {
const sections: SectionDef[] = [{ title: 'Data collection', fields: [
{ id: 'collects', kind: 'radio', options: yesNo([/^Yes, we collect data/i], [/^No, we do not collect data/i]) },
] }];
const types = answers.filter(a => a.id.startsWith('type:'));
if (types.length) sections.push({ title: 'Data types', fields: types.map(a => ({ id: a.id, kind: 'checkbox', names: [a.id.slice(5)] })) });
for (const a of types.filter(t => t.value === true && has(`linked:${t.id.slice(5)}`))) {
const n = a.id.slice(5);
sections.push({ title: n, dialog: [n, new RegExp(`^${esc(n)}\\b`, 'i')], fields: [
...APPLE_PURPOSES.map(p => ({ id: `purpose:${n}:${p}`, kind: 'checkbox' as const, names: [p] })),
{ id: `linked:${n}`, kind: 'radio', options: yesNo([/^Yes,.*\blinked to the user/i], [/^No,.*\blinked to the user/i]) },
{ id: `tracking:${n}`, kind: 'radio', options: yesNo([/^Yes,.*\btracking/i], [/^No,.*\btracking/i]) },
] });
}
return { id, sections };
}
case 'play-content-rating': return { id, sections: [
{ title: 'Email address and category', fields: [
{ id: 'email', kind: 'text', names: ['Email address', 'Email'] },
{ id: 'category', kind: 'radio', options: { 'Game': [/^Game\b/i], 'Social or communication': [/^Social/i], 'All other app types': [/^All other app types/i, /^Utility/i] } },
] },
{ title: 'Questionnaire', fields: answers.filter(a => a.id.startsWith('q:')).map(a => ({ id: a.id, kind: 'radio' as const, names: IARC_NAMES[a.id.slice(2)], options: yesNo() })) },
] };
case 'play-target-audience': return { id, sections: [
{ title: 'Target age', fields: AGE_GROUPS.map(g => ({ id: `age:${g}`, kind: 'checkbox' as const, names: [AGE_LABELS[g], AGE_LABELS[g].replace(/^Ages /, '')] })) },
...(has('appeal') ? [{ title: 'Appeal to children', fields: [{ id: 'appeal', kind: 'radio' as const, names: [/appeal to children/i], options: yesNo() }] }] : []),
{ title: 'Ads', fields: [{ id: 'ads', kind: 'radio', options: yesNo([/^Yes, my app contains ads/i], [/^No, my app does not contain ads/i]) }] },
] };
}
}
/**
* The click gate: a control whose name says save, submit, publish, next... is never clicked by storebound (English and
* Turkish console wording). English words match whole words; Turkish stems match word starts (agglutinative suffixes).
*/
const EN = ['save', 'saved', 'submit', 'publish', 'create', 'send', 'apply', 'confirm', 'done', 'release', 'rollout', 'roll out', 'start', 'delete',
'remove', 'next', 'continue', 'finish', 'agree', 'accept', 'upload', 'deploy', 'discard', 'update', 'add for review', 'review', 'sign', 'log in', 'login'];
const TR = ['kaydet', 'gönder', 'yayınla', 'yayımla', 'oluştur', 'onayla', 'tamam', 'bitti', 'bitir', 'sil', 'kaldır', 'başlat', 'sürüm',
'ileri', 'devam', 'sonraki', 'kabul', 'yükle', 'güncelle', 'incelemeye', 'giriş'];
const L = '\\p{L}\\p{N}';
// "uygula" (apply) is refused in every form, but not "uygulama" (app: Yeni Uygulama, Uygulama içeriği)
const FORBIDDEN = new RegExp(`(?<![${L}])(?:(?:${EN.map(esc).join('|')})(?![${L}])|(?:${TR.map(esc).join("|")}|uygula(?!ma)))`, 'iu');
/** true when storebound must not click a control with this accessible name. */
export const forbiddenControl = (name: string): boolean => FORBIDDEN.test(name.toLocaleLowerCase('tr').normalize('NFC')) || FORBIDDEN.test(name.toLowerCase());
const SIGN_IN_HOSTS = ['appleid.apple.com', 'idmsa.apple.com', 'accounts.google.com'];
/** A sign-in page (storebound never touches those; the owner signs in). */
export function isSignInUrl(url: string): boolean {
try {
const u = new URL(url);
return SIGN_IN_HOSTS.includes(u.hostname) || (u.hostname === 'appstoreconnect.apple.com' && u.pathname.startsWith('/login'));
} catch { return false; }
}
/** The console itself is open (signed in). `base` overrides the console origin (tests only, 127.0.0.1). */
export function consoleReached(store: 'apple' | 'play', url: string, base?: string): boolean {
try {
const u = new URL(url);
if (base) return u.origin === new URL(base).origin;
return store === 'apple' ? u.hostname === 'appstoreconnect.apple.com' && !u.pathname.startsWith('/login')
: u.hostname === 'play.google.com' && u.pathname.startsWith('/console') && !u.pathname.includes('signup');
} catch { return false; }
}
// ---- navigation to the form after sign-in (`storebound console fill` opens the form itself) ----
// Navigation clicks are allowed, saving / submitting / publishing never: every navigation click goes through navClick,
// which reads the element's real accessible name and checks it with navAllowed: the click gate above stays absolute.
// The one exception is FORM_OPENERS: a LINK whose whole name is exactly Start / Manage / Başla / Yönet (Play's App
// content entries), which only opens a form; a button named Start, or "Start rollout", stays refused.
// URLs (checked October 2026): App Store Connect app list /apps and an app's App Privacy page
// /apps/<appId>/distribution/privacy. Play Console has no deep link without the developer and app ids (the config has
// neither), so Play is navigated by role + name from the app list. A step not found in time -> the printed steps.
/** One navigation step. Steps are logged by `label`; a failed step is named in the fallback. */
export type NavStep =
| { kind: 'goto'; label: string; url: string }
/** Click the one visible control of one of `roles` named like one of `names`. `optional`: skipped when absent or when `unless` is already visible. */
| { kind: 'click'; label: string; roles: string[]; names: Name[]; optional?: boolean; unless?: { roles: string[]; names: Name[] } }
/** Pick the app from the list: rows / links whose name contains one of `tokens` (bundle id / package name) as a whole token, else whose name is `name`. */
| { kind: 'pickApp'; label: string; tokens: string[]; name?: string; search?: Name[] }
/** The Start / Manage link of the App content entry named like `entry`. */
| { kind: 'formLink'; label: string; entry: Name[] }
/** Wait for a visible element of one of `roles` named like `names` (the form is open); `level`: headings of that level only. */
| { kind: 'wait'; label: string; roles: string[]; names: Name[]; level?: number };
/** Link names that only open a form (whole name, links only): allowed although "start" is in the click gate. */
export const FORM_OPENERS = ['Start', 'Manage', 'Başla', 'Yönet'];
/** URL bases (tests point them at 127.0.0.1 fixtures). */
export interface NavBases { asc: string; play: string }
export const NAV_BASES: NavBases = { asc: 'https://appstoreconnect.apple.com', play: 'https://play.google.com/console' };
const APP_CONTENT: Name[] = ['App content', 'Uygulama içeriği', 'Uygulama İçeriği'];
const POLICY: Name[] = ['Policy and programs', 'Policy', 'Politika ve programlar', 'Politika'];
/**
* The steps that open a form after sign-in, built from the config only (apple.appId, apple.bundleId, play.packageName,
* app.name). The last step waits for the form itself. Pure.
*/
export function navPlan(id: FormId, config: ShipConfig, bases: NavBases = NAV_BASES): NavStep[] {
const asc = bases.asc.replace(/\/$/, ''), play = bases.play.replace(/\/$/, '');
const name = config.app?.name;
const named = name ? { name } : {};
switch (id) {
case 'apple-app-record': return [
{ kind: 'goto', label: 'open Apps', url: `${asc}/apps` },
{ kind: 'click', label: 'the add button (+)', roles: ['button'], names: ['+', 'Add Apps', 'Add App', 'New App', 'Uygulama Ekle', 'Uygulama ekle', 'Yeni Uygulama', /^add apps?$/i] },
{ kind: 'click', label: 'New App in the menu', roles: ['menuitem', 'menuitemradio', 'link', 'button'], names: ['New App', 'Yeni Uygulama', /^new app$/i, /^yeni uygulama$/iu] },
{ kind: 'wait', label: 'the New App dialog', roles: ['dialog'], names: ['New App', 'Yeni Uygulama', /^new app\b/i, /^yeni uygulama\b/iu] },
];
case 'apple-age-rating': return [];
case 'apple-app-privacy': {
const appId = config.apple?.appId;
const open: NavStep[] = appId ? [{ kind: 'goto', label: 'open App Privacy of the app (apple.appId)', url: `${asc}/apps/${encodeURIComponent(appId)}/distribution/privacy` }] : [
{ kind: 'goto', label: 'open Apps', url: `${asc}/apps` },
{ kind: 'pickApp', label: 'the app in the list', tokens: config.apple?.bundleId ? [config.apple.bundleId] : [], ...named },
{ kind: 'click', label: 'App Privacy in the sidebar', roles: ['link', 'tab'], names: ['App Privacy', 'Uygulama Gizliliği', /^app privacy$/i] },
];
return [...open, { kind: 'wait', label: 'the App Privacy page', roles: ['heading'], names: ['App Privacy', 'Uygulama Gizliliği', /^app privacy$/i] }];
}
case 'play-content-rating':
case 'play-target-audience': {
const [title, entry]: [string, Name[]] = id === 'play-content-rating'
? ['Content rating', ['Content rating', 'Content ratings', 'İçerik derecelendirmesi', /^content ratings?$/i]]
: ['Target audience and content', ['Target audience and content', 'Hedef kitle ve içerik', /^target audience\b/i, /^hedef kitle\b/iu]];
return [
{ kind: 'goto', label: 'open Play Console', url: play },
{ kind: 'pickApp', label: 'the app in the list', tokens: config.play?.packageName ? [config.play.packageName] : [], ...named, search: [/^search/i, 'Uygulama ara', /^ara$/iu] },
{ kind: 'click', label: 'Policy and programs (opens the menu)', roles: ['button', 'link'], names: POLICY, optional: true, unless: { roles: ['link'], names: APP_CONTENT } },
{ kind: 'click', label: 'App content', roles: ['link'], names: APP_CONTENT },
{ kind: 'formLink', label: `${title}: Start or Manage`, entry },
{ kind: 'wait', label: `the ${title} form`, roles: ['heading'], names: entry, level: 1 },
];
}
}
}
/**
* The navigation click gate: true when storebound may click a control with this accessible name and role while it
* opens a form. forbiddenControl stays absolute; the only exception is a FORM_OPENERS link (whole name).
*/
export function navAllowed(name: string, role: string): boolean {
const n = name.trim().replace(/\s+/g, ' ');
if (FORM_OPENERS.includes(n)) return role === 'link'; // a Start / Başla BUTTON may start something: never
return n.length > 0 && !forbiddenControl(n);
}
/** `id` as a whole token of `text` (com.example.game, not com.example.game2 or com.example.gamepro). */
export const hasToken = (text: string, id: string): boolean => new RegExp(`(?<![\\w.])${esc(id)}(?![\\w.])`).test(text);