A live run where only the token exchange, edit insert / delete and Reporting :query were let through: - health / validate: errorIssues:search answered 400 "Unsupported timezone" for America/Los_Angeles (it takes hour-aligned UTC only); the failure dropped the crash and ANR rates and the reason was cut off in the query string. Issues are asked in UTC; a failing issues search is a vitals-issues warning; Reporting errors leave out the query. - play listing --dry / play images --dry wrote into the edit (PUT details and listings, image clears and uploads, :validate) before discarding it. Now one throwaway edit is read (details, listings, image sha256) and compared with the local copy, then deleted. - play.read(): one helper for read-only edits (status, next-version-code), always deleted, warns if the delete fails; next-version-code counts distinct codes. - tests on sanitized recorded answers (tests/play-post-reads.test.ts)
82 lines
5.4 KiB
TypeScript
82 lines
5.4 KiB
TypeScript
// Play store listing text + app details in one edit.
|
|
// storebound play listing [--dry] [--only en-US,de-DE]
|
|
// --dry is read-only: a throwaway edit is opened, the current details and listings are read and compared with the file,
|
|
// and the edit is deleted. Nothing is written, not even into that edit.
|
|
// App details: default language, contact email, website (must be the domain that serves app-ads.txt).
|
|
// Listings: title, short and full description of every `<!-- play: ... -->` section of the listing file, plus the promo
|
|
// video (play.video, a YouTube URL) on every language. Play has no video upload: make the video with
|
|
// `storebound shots video --target youtube`, upload it to YouTube (public or unlisted, ads off, embeddable), paste the URL.
|
|
import { readFileSync } from 'node:fs';
|
|
import { parsePlayListing } from '../lib/copy';
|
|
import type { Ctx } from '../lib/ctx';
|
|
import { need } from '../lib/ctx';
|
|
import { done, log, step } from '../lib/log';
|
|
import { playClient } from './client';
|
|
|
|
export function readPlayCopy(ctx: Ctx) {
|
|
const { config, resolve } = ctx.loaded;
|
|
const file = resolve(config.play?.listing ?? 'store/listing.md');
|
|
const only = ctx.args.list('only');
|
|
return parsePlayListing(readFileSync(file, 'utf8'), config.app.name).filter(c => !only.length || only.includes(c.lang));
|
|
}
|
|
|
|
/** Body of one Play listing PUT. The PUT replaces the whole listing, so a promo video set in Play Console is cleared
|
|
* unless its URL is in play.video. Pure. */
|
|
export function listingBody(c: { lang: string; title: string; short: string; full: string }, video?: string): Record<string, string> {
|
|
return { language: c.lang, title: c.title, shortDescription: c.short, fullDescription: c.full, ...(video ? { video } : {}) };
|
|
}
|
|
|
|
export interface PlayListing { language: string; title?: string; shortDescription?: string; fullDescription?: string; video?: string }
|
|
export interface ListingChange { lang: string; change: 'new' | 'update' | 'same'; fields: string[] }
|
|
const LISTING_FIELDS = ['title', 'shortDescription', 'fullDescription', 'video'] as const;
|
|
|
|
/** What a listing run would change, from the listings Play has now (GET edits/{id}/listings). An empty and a missing
|
|
* value are the same; a promo video on Play that play.video leaves out is cleared by the PUT. Pure. */
|
|
export function listingChanges(current: PlayListing[], wanted: Record<string, string>[]): ListingChange[] {
|
|
const now = new Map(current.map(l => [l.language, l]));
|
|
return wanted.map(w => {
|
|
const cur = now.get(w.language!);
|
|
if (!cur) return { lang: w.language!, change: 'new', fields: [] };
|
|
const fields = LISTING_FIELDS.filter(f => (cur[f] ?? '') !== (w[f] ?? '')).map(f => (f === 'video' && !w.video ? 'video (cleared)' : f));
|
|
return { lang: w.language!, change: fields.length ? 'update' : 'same', fields };
|
|
});
|
|
}
|
|
|
|
/** App details fields a run would change (defaultLanguage, contactEmail, contactWebsite). Pure. */
|
|
export function detailsChanges(current: Record<string, string | undefined>, wanted: Record<string, string | undefined>): string[] {
|
|
return Object.keys(wanted).filter(k => (current[k] ?? '') !== (wanted[k] ?? ''));
|
|
}
|
|
|
|
export async function run(ctx: Ctx): Promise<void> {
|
|
const { config, root } = ctx.loaded;
|
|
const pkg = need(config.play?.packageName, 'play.packageName');
|
|
const copy = readPlayCopy(ctx);
|
|
const details = { defaultLanguage: config.play?.defaultLanguage ?? 'en-US', contactEmail: config.app.contactEmail, contactWebsite: config.app.website };
|
|
if (!copy.some(c => c.lang === details.defaultLanguage) && !ctx.args.has('only')) throw new Error(`listing has no section for the default language ${details.defaultLanguage}`);
|
|
log('play', `${copy.length} listings: ${copy.map(c => c.lang).join(', ')}${config.play?.video ? ` · promo video ${config.play.video}` : ''}`);
|
|
const play = await playClient(root, pkg);
|
|
if (ctx.args.has('dry')) {
|
|
await play.read(async id => {
|
|
const cur = await play.call<Record<string, string>>('GET', `${play.API}/edits/${id}/details`);
|
|
const dc = detailsChanges(cur, details);
|
|
log('play', `details: ${dc.length ? 'would change ' + dc.join(', ') : 'unchanged'}`);
|
|
const now = (await play.call<{ listings?: PlayListing[] }>('GET', `${play.API}/edits/${id}/listings`)).listings ?? [];
|
|
const changes = listingChanges(now, copy.map(c => listingBody(c, config.play?.video)));
|
|
for (const c of changes) log('play', `${c.lang}: ${c.change === 'update' ? 'would update ' + c.fields.join(', ') : c.change === 'new' ? 'would add (new language)' : 'unchanged'}`);
|
|
const other = now.filter(l => !copy.some(c => c.lang === l.language)).map(l => l.language);
|
|
if (other.length && !ctx.args.has('only')) log('play', `${other.length} languages on Play not in the listing file (left as they are): ${other.join(', ')}`);
|
|
const n = changes.filter(c => c.change !== 'same').length + (dc.length ? 1 : 0);
|
|
done('play', `dry run: ${n ? n + ' change(s)' : 'nothing to change'}; read-only, nothing written`);
|
|
});
|
|
return;
|
|
}
|
|
await play.edit(async id => {
|
|
await play.call('PUT', `${play.API}/edits/${id}/details`, details);
|
|
log('play', `details: ${details.defaultLanguage} · ${details.contactEmail} · ${details.contactWebsite}`);
|
|
for (const [i, c] of copy.entries()) {
|
|
await play.call('PUT', `${play.API}/edits/${id}/listings/${c.lang}`, listingBody(c, config.play?.video));
|
|
log('play', step(i + 1, copy.length, c.lang));
|
|
}
|
|
});
|
|
done('play', 'listing done');
|
|
}
|