apps / health / catalog / validate: fixes from a read-only run against live store accounts
- API error bodies on one line (errorBody): Google and App Store Connect pretty-print errors, which hid SERVICE_DISABLED from the Play account check (reported permission instead of api-disabled), broke tables and turned serve's apps.list error into a JSON fragment - apps list: failure says the reason and the fix (same words as apps check) - newest App Store version by createdDate, iOS first (the API groups versions by platform); all versions read so no platform is missed; per-app reads four at a time - apps check (apple): team app count from meta.paging.total with a one-app read - Play Money without units (prices under 1.00) read as 0.xx, not NaN (catalog diff, subscription diffs) - health: App Store Connect 404 for perfPowerMetrics / diagnosticSignatures means no field data yet; Play vitals behind a disabled Reporting API say so with the fix - validate: gracRatingClassificationNumber optional, socialMediaAgeRestricted only when socialMedia is yes, socialMedia unanswered is a warning - tests with sanitized recorded responses (tests/store-real-shapes.test.ts)
This commit is contained in:
parent
8bb28db45c
commit
b8da75e519
14 changed files with 342 additions and 34 deletions
19
cli/apps.ts
19
cli/apps.ts
|
|
@ -9,6 +9,7 @@ import type { Args } from './lib/args';
|
|||
import { ascKey, playServiceAccount } from './lib/credentials';
|
||||
import type { AccountCheck, AppsListResult } from './lib/desktop-protocol';
|
||||
import { PLAY_SCOPE, REPORTING_SCOPE, tokenSource } from './lib/google-auth';
|
||||
import { errorBody } from './lib/http';
|
||||
import { log, printJson, warn } from './lib/log';
|
||||
import { appleCheck, type Bytes, dataUrl, type Get, listAppleApps, listPlayApps, MAX_ICON_BYTES, playCheck } from './lib/store-apps';
|
||||
import { textTable } from './lib/table';
|
||||
|
|
@ -48,7 +49,7 @@ function googleGet(token: () => Promise<string>, base: string): Get {
|
|||
const r = await fetch(path.startsWith('http') ? path : base + path, { headers: { Authorization: 'Bearer ' + (await token()) } });
|
||||
const t = await r.text();
|
||||
if ((r.status === 429 || r.status >= 500) && attempt < 3) { await Bun.sleep(1500 * (attempt + 1)); continue; }
|
||||
if (!r.ok) throw new Error(`GET ${path.replace(/^https:\/\/[^/]+/, '')} -> ${r.status} ${/^\s*</.test(t) ? '(HTML error page)' : t.slice(0, 800)}`);
|
||||
if (!r.ok) throw new Error(`GET ${path.replace(/^https:\/\/[^/]+/, '')} -> ${r.status} ${errorBody(t, 800)}`);
|
||||
return t ? JSON.parse(t) : {};
|
||||
}
|
||||
};
|
||||
|
|
@ -61,7 +62,7 @@ function playIcon(root: string): (pkg: string) => Promise<string | null> {
|
|||
const call = async (method: string, url: string) => {
|
||||
const r = await fetch(url, { method, headers: { Authorization: 'Bearer ' + (await token()) } });
|
||||
const t = await r.text();
|
||||
if (!r.ok) throw new Error(`${method} -> ${r.status} ${t.slice(0, 300)}`);
|
||||
if (!r.ok) throw new Error(`${method} -> ${r.status} ${errorBody(t, 300)}`);
|
||||
return t ? JSON.parse(t) : {};
|
||||
};
|
||||
return async pkg => {
|
||||
|
|
@ -81,6 +82,8 @@ function playIcon(root: string): (pkg: string) => Promise<string | null> {
|
|||
};
|
||||
}
|
||||
|
||||
const principalOf = (root: string): string | null => { try { return playServiceAccount(root).client_email; } catch { return null; } };
|
||||
|
||||
export async function listApps(store: Store, root: string, icons: boolean): Promise<AppsListResult> {
|
||||
const at = new Date().toISOString();
|
||||
if (store === 'apple') {
|
||||
|
|
@ -95,8 +98,9 @@ export async function listApps(store: Store, root: string, icons: boolean): Prom
|
|||
export async function checkAccount(store: Store, root: string): Promise<AccountCheck> {
|
||||
if (store === 'apple') {
|
||||
try {
|
||||
const page = await (await appleGet(root))('/v1/apps?fields[apps]=bundleId&limit=200');
|
||||
return appleCheck({ apps: (page.data ?? []).length });
|
||||
// one app is enough to prove the key; the team's app count is meta.paging.total
|
||||
const page = await (await appleGet(root))('/v1/apps?fields[apps]=bundleId&limit=1');
|
||||
return appleCheck({ apps: Number(page.meta?.paging?.total ?? (page.data ?? []).length) });
|
||||
} catch (e) { return appleCheck({ error: e }); }
|
||||
}
|
||||
let principal: string | null = null;
|
||||
|
|
@ -116,8 +120,11 @@ export async function run(args: Args): Promise<void> {
|
|||
const out: AppsListResult[] = [];
|
||||
for (const s of stores(args, root)) {
|
||||
try { out.push(await listApps(s, root, args.has('icons'))); } catch (e) {
|
||||
if (args.get('store')) throw e;
|
||||
warn('apps', `${s}: ${(e as Error).message.split('\n')[0]}`);
|
||||
// say what is wrong and how to fix it (the same words as `apps check`), not the raw API error
|
||||
const c = s === 'apple' ? appleCheck({ error: e }) : playCheck(principalOf(root), { error: e });
|
||||
const why = `${c.message}${c.fix ? ` Fix: ${c.fix}` : ''}`;
|
||||
if (args.get('store')) throw new Error(why);
|
||||
warn('apps', `${s}: ${why}`);
|
||||
}
|
||||
}
|
||||
if (json) { printJson(args.get('store') ? out[0] : out); return; }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue