CLI: storebound apps list | check (apps on a store account, account health with fixes); serve apps.list, account.check and store-only apps through a generated config
This commit is contained in:
parent
1eb3f0768d
commit
dbde48d33c
6 changed files with 697 additions and 13 deletions
121
cli/serve.ts
121
cli/serve.ts
|
|
@ -9,13 +9,15 @@
|
|||
// - writes that are dry runs unless the host sends a confirm token (lib/confirm-token.ts) it minted after the owner
|
||||
// confirmed a native dialog showing that dry run.
|
||||
// Nothing here submits for review, releases or publishes: those methods do not exist (tests/serve.test.ts).
|
||||
import { existsSync, statSync } from 'node:fs';
|
||||
import { createHash } from 'node:crypto';
|
||||
import { existsSync, mkdirSync, mkdtempSync, statSync, writeFileSync } from 'node:fs';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { isAbsolute, join, resolve } from 'node:path';
|
||||
import pkg from '../package.json' with { type: 'json' };
|
||||
import { parseSecret, TokenGuard } from './lib/confirm-token';
|
||||
import { canonical, parseSecret, TokenGuard } from './lib/confirm-token';
|
||||
import { CONFIG_NAMES } from './lib/config';
|
||||
import {
|
||||
DESKTOP_PROTOCOL, ERR, type AppStatus, type MethodDescriptor, type PortfolioResult, type ProjectSummary, type ToolResult,
|
||||
DESKTOP_PROTOCOL, ERR, type AppStatus, type MethodDescriptor, type PortfolioResult, type ProjectSummary, type ToolResult, type VirtualProject,
|
||||
} from './lib/desktop-protocol';
|
||||
import { appIdentity, appleProductIds, appleReleases, catalogParity, playProductIds, playReleases, releaseTrains } from './lib/portfolio';
|
||||
import { detectTools } from './lib/tools';
|
||||
|
|
@ -86,10 +88,20 @@ const SYSTEM: MethodDescriptor[] = [
|
|||
{ method: 'system.tools', title: 'Local tools', description: 'Optional local tools with versions and where they come from (ffmpeg, ffprobe, Chrome, Xcode / simctl, adb, git); screenshot, video and capture features need them.', kind: 'system', network: false, destructive: false, json: true, args: obj({}) },
|
||||
{ method: 'project.inspect', title: 'Inspect a project', description: 'Offline summary of a folder\'s storebound.config.ts (name, store ids, languages, products).', kind: 'read', network: false, destructive: false, json: true,
|
||||
args: obj({ project: { type: 'string', description: 'Absolute folder path' } }, ['project']) },
|
||||
{ method: 'apps.list', title: 'Apps on a store account', description: 'Every app one store account can see (App Store Connect team: GET /v1/apps with platforms and the newest version; Google Play: Reporting API apps:search over every developer account that invited the service account), optional 128 px icons. Credentials of exactly one account in params.credentials. Read-only.', kind: 'account', network: true, destructive: false, json: true,
|
||||
args: obj({ credentials: { type: 'object' }, args: { type: 'object' } }, ['credentials']) },
|
||||
{ method: 'account.check', title: 'Check a store account', description: 'Does the key work, and can it see apps: ok, no-apps, permission (with the Play Console / App Store Connect fix), revoked, api-disabled. Read-only.', kind: 'account', network: true, destructive: false, json: true,
|
||||
args: obj({ credentials: { type: 'object' } }, ['credentials']) },
|
||||
{ method: 'portfolio.status', title: 'Portfolio status', description: 'Apps (one per project folder) across iOS and Android: identity, offline config check, catalog parity; with live, release trains (current / next version on both stores) and live catalog parity from App Store and Google Play status (read-only).', kind: 'portfolio', network: true, destructive: false, json: true,
|
||||
args: obj({ projects: { type: 'array' }, live: { type: 'boolean', default: false } }, ['projects']) },
|
||||
];
|
||||
|
||||
/** Read methods a store-only app (params.virtual, no app folder) may use: store reads that need only the store ids. */
|
||||
export const VIRTUAL_READS = new Set(['apple_status', 'play_status', 'health', 'reviews_list', 'apple_testflight_status', 'apple_ppo_status']);
|
||||
|
||||
const PKG_RE = /^[A-Za-z][A-Za-z0-9_]*(\.[A-Za-z0-9_]+)+$/;
|
||||
const BUNDLE_RE = /^[A-Za-z0-9][A-Za-z0-9.-]{0,154}$/;
|
||||
|
||||
export function describeMethods(): MethodDescriptor[] {
|
||||
return [...SYSTEM, ...DESKTOP_TOOLS.map(t => ({
|
||||
method: methodName(t.name), title: t.title, description: t.description, kind: t.write ? 'write' as const : 'read' as const,
|
||||
|
|
@ -113,6 +125,55 @@ export function checkProject(p: unknown): string {
|
|||
return dir;
|
||||
}
|
||||
|
||||
/** Checks a params.virtual object (store ids only). */
|
||||
export function checkVirtual(v: unknown): VirtualProject {
|
||||
if (typeof v !== 'object' || v === null || Array.isArray(v)) throw new RpcError(ERR.invalidParams, 'virtual: object expected');
|
||||
const o = v as Record<string, unknown>;
|
||||
for (const k of Object.keys(o)) if (!['name', 'apple', 'play'].includes(k)) throw new RpcError(ERR.invalidParams, `virtual.${k}: unknown`);
|
||||
const name = typeof o.name === 'string' && o.name.trim() && o.name.length <= 120 ? o.name.trim() : null;
|
||||
if (!name) throw new RpcError(ERR.invalidParams, 'virtual.name: 1-120 characters');
|
||||
const a = o.apple as Record<string, unknown> | null | undefined, p = o.play as Record<string, unknown> | null | undefined;
|
||||
if (!a && !p) throw new RpcError(ERR.invalidParams, 'virtual: apple and / or play');
|
||||
const out: VirtualProject = { name };
|
||||
if (a) {
|
||||
if (typeof a.bundleId !== 'string' || !BUNDLE_RE.test(a.bundleId) || !a.bundleId.includes('.')) throw new RpcError(ERR.invalidParams, 'virtual.apple.bundleId: a bundle id');
|
||||
if (a.appId !== undefined && a.appId !== null && (typeof a.appId !== 'string' || !/^\d{1,20}$/.test(a.appId))) throw new RpcError(ERR.invalidParams, 'virtual.apple.appId: digits');
|
||||
out.apple = { bundleId: a.bundleId, appId: (a.appId as string | null | undefined) ?? null };
|
||||
}
|
||||
if (p) {
|
||||
if (typeof p.packageName !== 'string' || !PKG_RE.test(p.packageName)) throw new RpcError(ERR.invalidParams, 'virtual.play.packageName: a package name');
|
||||
out.play = { packageName: p.packageName };
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/** The minimal config of a store-only app (store ids, placeholder links), as storebound.config.json. */
|
||||
export function virtualConfig(v: VirtualProject): Record<string, unknown> {
|
||||
return {
|
||||
app: { name: v.name, privacyPolicyUrl: 'https://example.com/privacy', supportUrl: 'https://example.com/support', website: 'https://example.com/',
|
||||
contactEmail: 'store-only@example.com', platforms: [...(v.apple ? ['ios'] : []), ...(v.play ? ['android'] : [])] },
|
||||
languages: [{ id: 'en', play: 'en-US', apple: 'en-US' }],
|
||||
...(v.apple ? { apple: { bundleId: v.apple.bundleId, ...(v.apple.appId ? { appId: v.apple.appId } : {}) } } : {}),
|
||||
...(v.play ? { play: { packageName: v.play.packageName } } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
let virtualRoot: string | null = null;
|
||||
/** A folder (in this session's temp folder) holding the generated config of a store-only app. */
|
||||
export function virtualDir(v: VirtualProject): string {
|
||||
virtualRoot ??= mkdtempSync(join(tmpdir(), 'storebound-virtual-'));
|
||||
const dir = join(virtualRoot, createHash('sha256').update(canonical(v as unknown as Record<string, unknown>)).digest('hex').slice(0, 20));
|
||||
if (!existsSync(join(dir, 'storebound.config.json'))) {
|
||||
mkdirSync(dir, { recursive: true });
|
||||
writeFileSync(join(dir, 'storebound.config.json'), JSON.stringify(virtualConfig(v), null, 2) + '\n');
|
||||
}
|
||||
return dir;
|
||||
}
|
||||
|
||||
/** An empty folder for commands that need no project (apps list / check): no stray .storebound/credentials.json. */
|
||||
let neutral: string | null = null;
|
||||
const neutralDir = (): string => (neutral ??= mkdtempSync(join(tmpdir(), 'storebound-account-')));
|
||||
|
||||
const cut = (s: string): string => (s.length > MAX_OUTPUT ? `[... first ${s.length - MAX_OUTPUT} characters cut ...]\n` + s.slice(-MAX_OUTPUT) : s);
|
||||
|
||||
function credentialsOf(v: unknown): Record<string, string> {
|
||||
|
|
@ -197,6 +258,8 @@ export class Session {
|
|||
case 'system.tools': return localTools();
|
||||
case 'project.inspect': return this.inspect(checkProject(params.project), {}, id);
|
||||
case 'portfolio.status': return this.portfolio(params, id);
|
||||
case 'apps.list': return this.account(['apps', 'list'], params, id, true);
|
||||
case 'account.check': return this.account(['apps', 'check'], params, id, false);
|
||||
}
|
||||
const tool = byMethod.get(method);
|
||||
if (!tool) throw new RpcError(ERR.methodNotFound, `Method not found: ${method}`);
|
||||
|
|
@ -204,8 +267,13 @@ export class Session {
|
|||
}
|
||||
|
||||
private async tool(method: string, t: ToolDef, params: Json, id: Id): Promise<ToolResult> {
|
||||
for (const k of Object.keys(params)) if (!['project', 'args', 'dryRun', 'confirmToken', 'credentials'].includes(k)) throw new RpcError(ERR.invalidParams, `unknown param: ${k}`);
|
||||
const project = NEW_PROJECT.has(t.name) ? checkNewProject(params.project) : checkProject(params.project);
|
||||
for (const k of Object.keys(params)) if (!['project', 'args', 'dryRun', 'confirmToken', 'credentials', 'virtual'].includes(k)) throw new RpcError(ERR.invalidParams, `unknown param: ${k}`);
|
||||
let project: string;
|
||||
if (params.virtual !== undefined) {
|
||||
if (params.project !== undefined) throw new RpcError(ERR.invalidParams, 'project or virtual, not both');
|
||||
if (t.write || !VIRTUAL_READS.has(t.name)) throw new RpcError(ERR.invalidParams, `${method}: needs an app folder (store-only apps have store reads only)`);
|
||||
project = virtualDir(checkVirtual(params.virtual));
|
||||
} else project = NEW_PROJECT.has(t.name) ? checkNewProject(params.project) : checkProject(params.project);
|
||||
const args = (params.args ?? {}) as Json;
|
||||
if (typeof args !== 'object' || args === null || Array.isArray(args)) throw new RpcError(ERR.invalidParams, 'args must be an object');
|
||||
if ('dry_run' in args) throw new RpcError(ERR.invalidParams, 'args.dry_run: use params.dryRun');
|
||||
|
|
@ -236,6 +304,23 @@ export class Session {
|
|||
};
|
||||
}
|
||||
|
||||
/** apps.list / account.check: one account's credentials, no project folder. */
|
||||
private async account(cmd: string[], params: Json, id: Id, list: boolean): Promise<unknown> {
|
||||
for (const k of Object.keys(params)) if (!['credentials', 'args'].includes(k)) throw new RpcError(ERR.invalidParams, `unknown param: ${k}`);
|
||||
const env = credentialsOf(params.credentials);
|
||||
const play = !!env.PLAY_SERVICE_ACCOUNT, apple = !!(env.ASC_KEY_ID || env.ASC_ISSUER_ID || env.ASC_P8);
|
||||
if (play === apple) throw new RpcError(ERR.invalidParams, 'credentials: exactly one store account (a Play service account, or an App Store Connect key)');
|
||||
const args = (params.args ?? {}) as Json;
|
||||
if (typeof args !== 'object' || args === null || Array.isArray(args)) throw new RpcError(ERR.invalidParams, 'args must be an object');
|
||||
for (const k of Object.keys(args)) if (!(list && k === 'icons')) throw new RpcError(ERR.invalidParams, `args.${k}: unknown`);
|
||||
if (args.icons !== undefined && typeof args.icons !== 'boolean') throw new RpcError(ERR.invalidParams, 'args.icons: boolean');
|
||||
const argv = [...cmd, '--store', play ? 'play' : 'apple', ...(args.icons === true ? ['--icons'] : []), '--json'];
|
||||
const r = await this.track(id, this.run(argv, { cwd: neutralDir(), env, machine: true, onLine: (line, stream) => this.progress(id, { line, stream }) })).result;
|
||||
if (r.cancelled || this.cancelled.has(id)) throw new RpcError(ERR.cancelled, 'Request cancelled');
|
||||
if (r.data === undefined) throw new RpcError(ERR.internal, lastLine(r.out) || `exit ${r.code}`);
|
||||
return r.data;
|
||||
}
|
||||
|
||||
private progress(id: Id, p: Json): void {
|
||||
this.send({ jsonrpc: '2.0', method: 'progress', params: { requestId: id, ...p } });
|
||||
}
|
||||
|
|
@ -255,18 +340,27 @@ export class Session {
|
|||
const out: AppStatus[] = new Array(list.length);
|
||||
let done = 0;
|
||||
const one = async (i: number): Promise<void> => {
|
||||
const raw = list[i];
|
||||
const e: AppStatus = { project: String(raw), ok: false, app: null, summary: null, check: null, release: { source: 'none', current: null, next: null }, catalog: null, storeErrors: {}, errors: [] };
|
||||
const raw = list[i] as unknown;
|
||||
// a store-only app: { key: "store:...", virtual: { name, apple?, play? } }
|
||||
const virt = typeof raw === 'object' && raw !== null && !Array.isArray(raw) ? raw as { key?: unknown; virtual?: unknown } : null;
|
||||
const e: AppStatus = { project: virt ? String(virt.key ?? '') : String(raw), ok: false, app: null, summary: null, check: null, release: { source: 'none', current: null, next: null }, catalog: null, storeErrors: {}, errors: [] };
|
||||
out[i] = e;
|
||||
try {
|
||||
const dir = checkProject(raw);
|
||||
e.project = dir;
|
||||
let dir: string;
|
||||
if (virt) {
|
||||
if (typeof virt.key !== 'string' || !STORE_KEY_RE.test(virt.key)) throw new RpcError(ERR.invalidParams, 'projects[].key: a store target key');
|
||||
dir = virtualDir(checkVirtual(virt.virtual));
|
||||
e.virtual = true;
|
||||
} else { dir = checkProject(raw); e.project = dir; }
|
||||
const summary = e.summary = await this.inspect(dir, env, id);
|
||||
e.app = appIdentity(summary);
|
||||
e.catalog = catalogParity(summary);
|
||||
const c = await this.track(id, this.run(['check', '--json'], { cwd: dir, env, machine: true })).result;
|
||||
const cd = c.data as { ok?: boolean; problems?: string[]; warnings?: string[] } | undefined;
|
||||
e.check = cd ? { ok: !!cd.ok, problems: cd.problems ?? [], warnings: cd.warnings ?? [] } : { ok: false, problems: [lastLine(c.out) || `check exit ${c.code}`], warnings: [] };
|
||||
if (virt) e.check = { ok: true, problems: [], warnings: [] };
|
||||
else {
|
||||
const c = await this.track(id, this.run(['check', '--json'], { cwd: dir, env, machine: true })).result;
|
||||
const cd = c.data as { ok?: boolean; problems?: string[]; warnings?: string[] } | undefined;
|
||||
e.check = cd ? { ok: !!cd.ok, problems: cd.problems ?? [], warnings: cd.warnings ?? [] } : { ok: false, problems: [lastLine(c.out) || `check exit ${c.code}`], warnings: [] };
|
||||
}
|
||||
if (live) {
|
||||
const store = async (argv: string[]): Promise<{ data?: unknown; error?: string }> => {
|
||||
const r = await this.track(id, this.run(argv, { cwd: dir, env, machine: true })).result;
|
||||
|
|
@ -294,6 +388,9 @@ export class Session {
|
|||
}
|
||||
}
|
||||
|
||||
/** Store target keys of store-only apps ("store:ios:<account>:<app id>:<bundle id>;android:<account>:<package>"). */
|
||||
export const STORE_KEY_RE = /^store:[A-Za-z0-9:;._-]{1,400}$/;
|
||||
|
||||
const lastLine = (s: string): string => s.trim().split('\n').filter(Boolean).at(-1)?.replace(/^error:\s*/, '') ?? '';
|
||||
|
||||
/** Optional local tools with versions; app-managed copies (STOREBOUND_TOOL_PATH / STOREBOUND_CHROME) included. */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue