live read run fixes: Xcode-managed profiles in signing, TestFlight-only release trains, scan skips agent worktrees and takes an absolute --config, --all-pages paging meta, iap-submit json, report hints

This commit is contained in:
CRTkafa 2026-10-11 17:24:56 +00:00
parent 0856f2d1b2
commit 3a775f7808
15 changed files with 282 additions and 30 deletions

View file

@ -47,6 +47,14 @@ function save(dir: string, name: string, raw: string | Uint8Array, rows: Summary
return { raw: rawFile, summary };
}
/** What a failed Sales and Trends / finance download usually means. Seen live: a wrong vendor number gets a 500
* (after the retries) from salesReports and a 400 PARAMETER_ERROR.INVALID from financeReports. Pure. */
export function appleReportHint(msg: string): string | null {
if (/salesReports -> 500|financeReports -> 400 .*vendor number/i.test(msg)) return 'check the vendor number (App Store Connect > Payments and Financial Reports, the number next to the legal entity name); reports also need a team key with Sales or Finance access';
if (/-> 403/.test(msg)) return 'the API key may not read reports: it needs the Admin, Finance or Sales role (Users and Access > Integrations)';
return null;
}
export async function run(ctx: Ctx): Promise<void> {
const { config, root, resolve } = ctx.loaded;
const a = ctx.args;
@ -58,7 +66,7 @@ export async function run(ctx: Ctx): Promise<void> {
if (sub === 'apple-sales' || sub === 'apple-finance') {
const vendor = a.get('vendor') ?? ascVendorNumber(root);
if (!vendor || !/^\d{5,12}$/.test(vendor)) throw new Error('vendor number missing: ASC_VENDOR_NUMBER in env or .storebound/credentials.json, or --vendor (App Store Connect > Payments and Financial Reports)');
if (!vendor || !/^\d{5,12}$/.test(vendor)) throw new Error('vendor number missing: ASC_VENDOR_NUMBER in env, .storebound/credentials.json or the credential profile (--account), or --vendor (App Store Connect > Payments and Financial Reports)');
let path: string, name: string;
if (sub === 'apple-sales') {
const type = a.str('type', 'SALES').toUpperCase();
@ -76,7 +84,8 @@ export async function run(ctx: Ctx): Promise<void> {
if (dry) { if (a.has('json')) printJson({ dryRun: true, request: `GET ${shown}`, file: join(out, name) }); else log(TAG, `would GET ${shown} -> ${join(out, name)}`); return; }
const c = await ascClient(root, need(config.apple?.bundleId, 'apple.bundleId'), config.apple?.appId);
log(TAG, `GET ${shown}`);
const gz = await c.bytes(path);
let gz: Uint8Array | null;
try { gz = await c.bytes(path); } catch (e) { const hint = appleReportHint((e as Error).message); throw new Error(hint ? `${(e as Error).message}\n${hint}` : (e as Error).message); }
if (!gz) { done(TAG, 'no report for that date (no sales then, or not published yet: daily reports come out the next day, monthly ones about a week later)'); if (a.has('json')) printJson({ report: name, empty: true }); return; }
const text = new TextDecoder().decode(gz[0] === 0x1f && gz[1] === 0x8b ? Bun.gunzipSync(gz as Uint8Array<ArrayBuffer>) : gz);
const rows = parseTsv(text);