storebound api: every App Store Connect and Google Play operation
- specs/: Apple's App Store Connect OpenAPI 4.5.1 and the Google discovery docs for androidpublisher v3 and playdeveloperreporting v1beta1, pinned with URL, date and SHA-256 (specs/SOURCES.json) - tools/gen-api.ts: one row per operation (cli/api/apple.gen.ts 1303, cli/api/play.gen.ts 170), a scan of which operations the commands already call (cli/api/wrapped.gen.ts) and docs/api-coverage.md; CI checks freshness - cli/api/client.ts + types.ts: generic URL / parameter building, retries with Retry-After, pagination, types derived from the rows; auth reuses ascJwt and the Play service account - cli/api/gate.ts: GET runs, writes dry unless --yes in a TTY, owner-only operations need the id typed, nothing written under MCP or serve; MCP gets the read-only api_get - storebound api list | coverage | apple|play <op|METHOD path>; skill store-api, README, CHANGELOG, tests
This commit is contained in:
parent
02d90de77a
commit
1ed3f12eee
30 changed files with 281170 additions and 13 deletions
99
cli/api/gate.ts
Normal file
99
cli/api/gate.ts
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
// Write gating for `storebound api`: which operations read, which write, and which only the owner may run.
|
||||
//
|
||||
// read GET (and a few POSTs that only compute or query, listed below): runs right away.
|
||||
// write any other POST / PATCH / PUT / DELETE: prints the exact request; sent only with --yes in an interactive
|
||||
// terminal, never under MCP (`storebound mcp`) or the desktop app (`storebound serve`).
|
||||
// owner writes that submit, release, delete, cancel, change prices, invite or remove testers, send review replies,
|
||||
// start or stop experiments, refund or rotate keys (AGENTS.md rule 1): a write that also needs the operation id
|
||||
// typed at the prompt. Never reachable through MCP or serve.
|
||||
// Pure; tests/api.test.ts covers every rule.
|
||||
|
||||
export type Store = 'apple' | 'play';
|
||||
export type GateKind = 'read' | 'write' | 'owner';
|
||||
|
||||
/** POSTs that change nothing (vitals queries, price conversion, batch reads). */
|
||||
export const READ_POSTS: RegExp[] = [
|
||||
/^playdeveloperreporting\..*\.query$/,
|
||||
/^androidpublisher\.monetization\.convertRegionPrices$/,
|
||||
/^androidpublisher\.monetization\..*\.batchGet$/,
|
||||
];
|
||||
|
||||
/** [pattern over "METHOD operationId", why]: the curated owner-only list. */
|
||||
export const OWNER_ONLY: Record<Store, [RegExp, string][]> = {
|
||||
apple: [
|
||||
[/^DELETE /, 'deletes'],
|
||||
[/^(POST|PATCH) \w*Submissions?(V\d)?_(create|update)Instance$/, 'submits for review (or cancels a submission)'],
|
||||
[/^POST (?!appStoreVersionPhasedReleases)\w*(Releases|ReleaseRequests)_createInstance$/, 'releases'],
|
||||
[/^PATCH appStoreVersionPhasedReleases_updateInstance$/, 'pauses, resumes or completes a phased release'],
|
||||
[/^PATCH appStoreVersionExperiments(V2)?_updateInstance$/, 'starts or stops a product page test'],
|
||||
[/^POST (appPriceSchedules|inAppPurchasePriceSchedules|subscriptionPrices)_createInstance$/, 'changes prices'],
|
||||
[/^POST customerReviewResponses_createInstance$/, 'sends a public review reply'],
|
||||
[/^POST (betaTesterInvitations|betaTesters|userInvitations)_createInstance$/, 'invites testers or users'],
|
||||
[/^POST (betaGroups_betaTesters|betaTesters_betaGroups|betaTesters_builds|builds_individualTesters)_createToManyRelationship$/, 'adds testers'],
|
||||
[/^(POST|PATCH) users_(updateInstance|visibleApps_\w+)$/, 'changes a team member\'s access'],
|
||||
],
|
||||
play: [
|
||||
[/^DELETE /, 'deletes'],
|
||||
[/^POST \S+\.(batchDelete|deleteall)$/, 'deletes'],
|
||||
[/^POST androidpublisher\.edits\.commit$/, 'publishes the edit (releases, listing and graphics go live)'],
|
||||
[/^POST \S+\.(cancel|refund|refundexternaltransaction|reviewrefund|revoke)$/, 'cancels, refunds or revokes'],
|
||||
[/^POST androidpublisher\.apprecovery\.deploy$/, 'deploys an app recovery action'],
|
||||
[/^POST \S+\.(activate|deactivate|archive|batchUpdateStates)$/, 'makes products or offers live (or takes them down)'],
|
||||
[/^POST androidpublisher\.appstoreappsreview\.updateappstorehostedapppublishstatus$/, 'changes a publish status'],
|
||||
[/^POST \S+\.(migratePrices|batchMigratePrices)$/, 'changes prices for existing subscribers'],
|
||||
[/^POST androidpublisher\.reviews\.reply$/, 'sends a public review reply'],
|
||||
[/^(PUT|PATCH) androidpublisher\.edits\.testers\.(update|patch)$/, 'changes the testers of a track'],
|
||||
[/^(POST|PATCH) androidpublisher\.(users|grants)\.(create|patch)$/, 'invites users or changes their permissions'],
|
||||
[/^POST androidpublisher\.appsigning\.(enrollApp|rotateAppSigningKey)$/, 'changes app signing (irreversible)'],
|
||||
],
|
||||
};
|
||||
|
||||
/** Why an operation is owner-only, or null. */
|
||||
export function ownerReason(store: Store, id: string, method: string): string | null {
|
||||
const key = `${method.toUpperCase()} ${id}`;
|
||||
return OWNER_ONLY[store].find(([re]) => re.test(key))?.[1] ?? null;
|
||||
}
|
||||
|
||||
/** Resource of an operation, for counts: Apple's first path segment (/v1/<apps>/...), Google's id without the method. */
|
||||
export const resourceOf = (r: { store: Store; id: string; path: string }): string =>
|
||||
r.store === 'apple' ? r.path.split('/')[2]! : r.id.split('.').slice(0, -1).join('.');
|
||||
|
||||
export function gateOf(store: Store, id: string, method: string): GateKind {
|
||||
const m = method.toUpperCase();
|
||||
if (m === 'GET') return 'read';
|
||||
if (store === 'play' && m === 'POST' && READ_POSTS.some(re => re.test(id))) return 'read';
|
||||
return ownerReason(store, id, m) ? 'owner' : 'write';
|
||||
}
|
||||
|
||||
export interface GateInput {
|
||||
kind: GateKind;
|
||||
method: string;
|
||||
/** --dry */
|
||||
dry: boolean;
|
||||
/** --yes */
|
||||
yes: boolean;
|
||||
/** stdin and stdout are a terminal */
|
||||
tty: boolean;
|
||||
/** under `storebound mcp` or `storebound serve` (STOREBOUND_MCP / STOREBOUND_SERVE) */
|
||||
agent: boolean;
|
||||
/** `storebound api get` (the MCP api_get tool): plain GETs only */
|
||||
getOnly: boolean;
|
||||
}
|
||||
|
||||
export type Decision =
|
||||
| { action: 'send' }
|
||||
| { action: 'confirm'; typed: true }
|
||||
| { action: 'dry'; why: string }
|
||||
| { action: 'refuse'; why: string };
|
||||
|
||||
/** What to do with one call. Pure. */
|
||||
export function decide(g: GateInput): Decision {
|
||||
if (g.getOnly && g.method.toUpperCase() !== 'GET') return { action: 'refuse', why: 'api get runs GET operations only' };
|
||||
if (g.kind === 'read') return g.dry ? { action: 'dry', why: '--dry' } : { action: 'send' };
|
||||
if (g.agent) return { action: 'refuse', why: g.kind === 'owner'
|
||||
? 'owner-only operation: never through MCP or the desktop app; the owner runs it in a terminal'
|
||||
: 'writes through `storebound api` are not available to MCP or the desktop app; run it in a terminal' };
|
||||
if (g.dry || !g.yes) return { action: 'dry', why: g.dry ? '--dry' : 'writes are dry by default: add --yes (in a terminal) to send' };
|
||||
if (!g.tty) return { action: 'dry', why: 'not an interactive terminal: writes through `storebound api` are only sent from one' };
|
||||
return g.kind === 'owner' ? { action: 'confirm', typed: true } : { action: 'send' };
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue