idempotency: WIP
This commit is contained in:
parent
96f3df443b
commit
81a48428f0
41 changed files with 1930 additions and 225 deletions
|
|
@ -18,6 +18,8 @@ import { numberedImages } from '../play/images';
|
|||
import { variantRoot } from '../shots/lib';
|
||||
import { type Asc, ascClient, type J } from './asc';
|
||||
import { describeReq, execute, one, type Req } from './jsonapi';
|
||||
import { addItem, draftSubmission, findDraft } from './submission';
|
||||
import { findOrCreate, getById } from '../lib/upsert';
|
||||
import { displaySets, syncScreenshotSet } from './screenshots';
|
||||
|
||||
const TAG = 'cpp';
|
||||
|
|
@ -35,11 +37,6 @@ async function pagesOf(c: Asc, appId: string): Promise<Page[]> {
|
|||
return out;
|
||||
}
|
||||
|
||||
/** A draft review submission of the app (READY_FOR_REVIEW), or the request that creates one. */
|
||||
async function draftSubmission(c: Asc, appId: string): Promise<string | null> {
|
||||
return (await c.all(`/v1/reviewSubmissions?filter[app]=${appId}&filter[platform]=IOS&filter[state]=READY_FOR_REVIEW&limit=10`))[0]?.id ?? null;
|
||||
}
|
||||
|
||||
export async function run(ctx: Ctx): Promise<void> {
|
||||
const { config, root, resolve } = ctx.loaded;
|
||||
const a = ctx.args;
|
||||
|
|
@ -82,7 +79,18 @@ export async function run(ctx: Ctx): Promise<void> {
|
|||
if (pages.length + reqs.filter(r => r.path === '/v1/appCustomProductPages').length > CPP_LIMITS.pages) throw new Error(`more than ${CPP_LIMITS.pages} custom product pages`);
|
||||
if (a.has('json')) printJson({ dryRun: dry, requests: reqs.map(r => describeReq(r)) });
|
||||
if (!reqs.length) { done(TAG, 'custom product pages up to date'); return; }
|
||||
await execute(c.asc, reqs, { dry, tag: TAG });
|
||||
if (dry) { await execute(c.asc, reqs, { dry, tag: TAG }); done(TAG, `dry run: ${reqs.length} change(s)`); return; }
|
||||
// page names are not known to be unique on Apple's side: each new page is looked up right before it is created
|
||||
// (fresh list, then the journal of recent creates for the list lag) and never sent twice
|
||||
for (const r of reqs) {
|
||||
if (r.path !== '/v1/appCustomProductPages') { await execute(c.asc, [r], { dry, tag: TAG }); continue; }
|
||||
const name = (r.body as J).data.attributes.name as string;
|
||||
const made = await findOrCreate<J>({ what: `custom product page "${name}"`, tag: TAG,
|
||||
find: async () => (await c.all(`/v1/apps/${appId}/appCustomProductPages?limit=200`)).find((p: J) => p.attributes.name === name) ?? null,
|
||||
journal: { root, key: `apple:${appId}:cpp:${name}`, byId: id => getById(c.asc, `/v1/appCustomProductPages/${id}`) as Promise<J | null>, idOf: v => v.id },
|
||||
create: async () => (await c.asc('POST', r.path, r.body)).data });
|
||||
log(TAG, `${describeReq(r)}: ${made.created ? 'done' : 'exists already'}`);
|
||||
}
|
||||
done(TAG, dry ? `dry run: ${reqs.length} change(s)` : `${reqs.length} change(s); next: storebound apple cpp upload --name "<page>"`);
|
||||
return;
|
||||
}
|
||||
|
|
@ -117,13 +125,13 @@ export async function run(ctx: Ctx): Promise<void> {
|
|||
const { def, page } = pick();
|
||||
if (!page?.version) throw new Error(`"${def.name}" is not on App Store Connect yet (storebound apple cpp create)`);
|
||||
if (!['PREPARE_FOR_SUBMISSION', 'REJECTED'].includes(page.version.state)) { done(TAG, `"${def.name}": version is ${page.version.state}, nothing to submit`); return; }
|
||||
const draft = await draftSubmission(c, appId);
|
||||
const draft = await findDraft(c, appId);
|
||||
const create: Req = { method: 'POST', path: '/v1/reviewSubmissions', note: 'new draft review submission', body: { data: { type: 'reviewSubmissions', attributes: { platform: 'IOS' }, relationships: { app: one('apps', appId) } } } };
|
||||
const item = reviewItemReq(draft ?? '${submission}', 'appCustomProductPageVersion', page.version.id, `custom product page "${def.name}"`);
|
||||
if (dry) { await execute(c.asc, [...(draft ? [] : [create]), item, { method: 'PATCH', path: `/v1/reviewSubmissions/${draft ?? '${submission}'}`, note: 'submit for App Review' }], { dry, tag: TAG }); return; }
|
||||
if (!(await confirm(ctx, `Send custom product page "${def.name}" to App Review now?`))) return;
|
||||
const sid = draft ?? ((await c.asc('POST', create.path, create.body)).data.id as string);
|
||||
await c.asc('POST', item.path, reviewItemReq(sid, 'appCustomProductPageVersion', page.version.id, '').body);
|
||||
const sid = draft ?? await draftSubmission(c, appId, root, TAG);
|
||||
await addItem(c, sid, 'appCustomProductPageVersion', page.version.id, `custom product page "${def.name}"`, TAG);
|
||||
await c.asc('PATCH', `/v1/reviewSubmissions/${sid}`, { data: { type: 'reviewSubmissions', id: sid, attributes: { submitted: true } } });
|
||||
done(TAG, `"${def.name}" submitted (review submission ${sid}); after approval: storebound apple cpp visible --name "${def.name}"`);
|
||||
return;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue