storebound/cli/lib/desktop-protocol.ts
CRT 9320d64f46 Desktop: adapt to 0.5.0 (app.platforms, subscriptions, catalog diff), Dependencies polish, ~ for the home folder
- inspect reports platforms, subscription ids and the catalog each store should sell; app identity
  and parity follow app.platforms and per-item platforms; catalog.diff joins the JSON methods
- Portfolio: one Platforms column, compact catalog, paths truncated and shown with ~; the confirm
  dialog and run logs show ~ instead of the home folder
2026-10-10 18:15:48 +00:00

154 lines
6.3 KiB
TypeScript

// Types of the `storebound serve --stdio` protocol (desktop profile). Type-only, no runtime code: the desktop app
// (apps/desktop) imports this file so both sides agree on shapes. Newline-delimited JSON-RPC 2.0 on stdio.
//
// Session: the first request must be `session.hello` with the per-session secret (hex, >= 32 bytes) the host
// generated. Every other method answers -32002 before that. One hello per process.
// Progress: notifications `progress` { requestId, line?, stream?, n?, total?, project? } while a request runs.
// Cancel: notification `$/cancelRequest` { id } (or MCP-style `notifications/cancelled` { requestId }); the request
// then answers -32800.
// Writes: every write method is a dry run unless `dryRun: false` comes with a `confirmToken` minted by the host for
// exactly (method, { project, args }) (cli/lib/confirm-token.ts). No method submits, releases or publishes anything.
export const DESKTOP_PROTOCOL = 'storebound-desktop/1';
export const ERR = {
parse: -32700,
invalidRequest: -32600,
methodNotFound: -32601,
invalidParams: -32602,
internal: -32603,
notInitialized: -32002,
confirmRequired: -32010,
confirmInvalid: -32011,
cancelled: -32800,
} as const;
export interface JsonSchemaLite { type: string; description?: string; enum?: (string | number)[]; default?: unknown; minimum?: number; maximum?: number; pattern?: string }
export interface MethodDescriptor {
method: string;
title: string;
description: string;
kind: 'read' | 'write' | 'session' | 'system' | 'portfolio';
/** Talks to a store API or the internet. */
network: boolean;
/** Replaces existing data on a store (screenshots, whole forms). */
destructive: boolean;
/** Result carries structured `data` (the command's --json output). */
json: boolean;
/** Schema of `params.args` (tool methods), or of `params` (other methods). */
args: { type: 'object'; properties: Record<string, JsonSchemaLite>; required?: string[]; additionalProperties: false };
}
export interface HelloParams { secret: string; client?: { name: string; version: string } }
export interface HelloResult { protocol: typeof DESKTOP_PROTOCOL; server: { name: 'storebound'; version: string; compiled: boolean }; methods: MethodDescriptor[] }
export interface Credentials { PLAY_SERVICE_ACCOUNT?: string; ASC_KEY_ID?: string; ASC_ISSUER_ID?: string; ASC_P8?: string }
export interface ToolParams {
/** Absolute path of a folder that contains storebound.config.ts. */
project: string;
args?: Record<string, unknown>;
/** Write methods: false runs for real and needs confirmToken. Default true. */
dryRun?: boolean;
confirmToken?: string;
/** Per-call credentials (kept in memory, passed to the command's env only). Not part of the token. */
credentials?: Credentials;
}
export interface ToolResult {
method: string;
ok: boolean;
exitCode: number;
dryRun: boolean;
/** The CLI line it ran, for logs ("storebound play listing --dry"). */
command: string;
/** Text output (log lines), trimmed to the last 60 000 characters. */
output: string;
/** Structured result of a --json capable command. */
data?: unknown;
}
export interface ProgressParams { requestId: string | number; line?: string; stream?: 'stdout' | 'stderr'; n?: number; total?: number; project?: string }
export interface ProjectSummary {
dir: string;
config: string;
name: string;
languages: string[];
play: { packageName: string } | null;
apple: { bundleId: string; appId: string | null } | null;
/** app.platforms (default: from the apple / play sections). */
platforms: ('ios' | 'android')[];
/** One-time in-app products in the config (one shared catalog). */
products: number;
productIds: string[];
/** Auto-renewable subscriptions in the config (all groups). */
subscriptions: number;
subscriptionIds: string[];
/** Product and subscription ids each store should sell (items may be limited to one platform). */
catalog: { ios: string[]; android: string[] };
shots: boolean;
testflightGroups: number;
}
// ---- App-centric model (one app = one product on up to two platforms; a workspace holds many apps) ----
/** One product across platforms. id = its project folder (one storebound.config.ts per app). */
export interface AppIdentity {
id: string;
name: string;
platforms: { ios: { bundleId: string; ascAppId: string | null } | null; android: { packageName: string } | null };
}
/** Where a version is on one store. */
export type ReleasePhase = 'live' | 'rollout' | 'halted' | 'approved' | 'review' | 'rejected' | 'testing' | 'draft' | 'other';
export interface StoreRelease {
store: 'ios' | 'android';
version: string | null;
/** iOS build number (CFBundleVersion) / highest Android versionCode. */
build: string | null;
/** The store's own state word (READY_FOR_SALE, inProgress ...). */
state: string;
phase: ReleasePhase;
/** Android staged rollout user fraction (0-1); iOS phased release percentage comes with D2. */
fraction: number | null;
/** Android track (production, beta, internal ...). */
track: string | null;
}
/** A release train: one version (e.g. 2.3.0) across both stores. */
export interface ReleaseTrain { version: string; ios: StoreRelease | null; android: StoreRelease | null }
/** In-app catalog parity between the config and both stores. */
export interface CatalogParity {
checked: 'config' | 'live';
products: number;
subscriptions: number;
/** Live: ids on one store only, and config ids missing on a store the app is on. */
onlyIos: string[];
onlyAndroid: string[];
missingIos: string[];
missingAndroid: string[];
ok: boolean;
}
export interface PortfolioParams { projects: string[]; live?: boolean; credentials?: Credentials }
export interface AppStatus {
/** Project folder as given. */
project: string;
ok: boolean;
app: AppIdentity | null;
summary: ProjectSummary | null;
check: { ok: boolean; problems: string[]; warnings: string[] } | null;
/** Release trains; `source: none` offline (no store data read). */
release: { source: 'none' | 'live'; current: ReleaseTrain | null; next: ReleaseTrain | null };
catalog: CatalogParity | null;
/** live only: per-platform read errors ("unknown, never false"). */
storeErrors: { ios?: string; android?: string };
errors: string[];
}
export interface PortfolioResult { apps: AppStatus[]; at: string }