Play Developer Reporting API v1beta1 (crashRateMetricSet / anrRateMetricSet DAILY queries in America/Los_Angeles, user-perceived 28-day rates, worst device models, errorIssues:search) and App Store Connect perfPowerMetrics, diagnostic signatures and TestFlight crash submissions. Thresholds 1.09 % crash / 0.47 % ANR / 8 % per device (developer.android.com/topic/performance/vitals): over = blocker, from 80 % = warn, in validate too (--no-health). Weekly Markdown report with week-over-week change in .storebound/health/. MCP: health (read-only), health_report.
31 lines
1.7 KiB
TypeScript
31 lines
1.7 KiB
TypeScript
// Small client for the other Google APIs storebound reads with the same Play service account: the Play Developer
|
|
// Reporting API (vitals) and Cloud Storage (Play statistics exports). Read-only callers; retries 429 / 5xx.
|
|
import { playServiceAccount } from '../lib/credentials';
|
|
import { tokenSource } from '../lib/google-auth';
|
|
|
|
export const REPORTING_API = 'https://playdeveloperreporting.googleapis.com/v1beta1';
|
|
|
|
export function googleClient(root: string, scope: string) {
|
|
const token = tokenSource(playServiceAccount(root), scope);
|
|
async function send(method: string, url: string, body?: unknown): Promise<Response> {
|
|
for (let attempt = 0; ; attempt++) {
|
|
const r = await fetch(url, { method, headers: { Authorization: 'Bearer ' + (await token()), ...(body === undefined ? {} : { 'Content-Type': 'application/json' }) },
|
|
body: body === undefined ? undefined : JSON.stringify(body) });
|
|
if ((r.status === 429 || r.status >= 500) && attempt < 4) { await r.body?.cancel(); await Bun.sleep(2000 * (attempt + 1)); continue; }
|
|
return r;
|
|
}
|
|
}
|
|
return {
|
|
async json<T = unknown>(method: string, url: string, body?: unknown): Promise<T> {
|
|
const r = await send(method, url, body);
|
|
const t = await r.text();
|
|
if (!r.ok) throw new Error(`${method} ${url.replace(/^https:\/\/[^/]+/, '')} -> ${r.status} ${/^\s*</.test(t) ? '(HTML error page)' : t.slice(0, 800)}`);
|
|
return (t ? JSON.parse(t) : {}) as T;
|
|
},
|
|
async bytes(url: string): Promise<Uint8Array> {
|
|
const r = await send('GET', url);
|
|
if (!r.ok) throw new Error(`GET ${url.replace(/^https:\/\/[^/]+/, '')} -> ${r.status} ${(await r.text()).slice(0, 300)}`);
|
|
return new Uint8Array(await r.arrayBuffer());
|
|
},
|
|
};
|
|
}
|