130 lines
8.1 KiB
TypeScript
130 lines
8.1 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 } 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', 'uygula', '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}';
|
|
const FORBIDDEN = new RegExp(`(?<![${L}])(?:(?:${EN.map(esc).join('|')})(?![${L}])|(?:${TR.map(esc).join('|')}))`, '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; }
|
|
}
|