diff --git a/cli/apple/iap-submit.ts b/cli/apple/iap-submit.ts index d7952cd..0985a44 100644 --- a/cli/apple/iap-submit.ts +++ b/cli/apple/iap-submit.ts @@ -21,13 +21,15 @@ import { allSubscriptions } from '../lib/subscriptions'; import { addAction, bindIds, chooseSubmission, EMPTY_DRAFT, labelOf, type ResolveScope, resolveHint, toResolve, latestVersion, NEW_VERSION_FROM, newVersionReq, type PIap, planIapSubmission, type PSub, type SubmitState, versionsOf, willSubmit } from '../lib/review-submit'; import { readJournal } from '../lib/upsert'; import { type Asc, ascClient, type J } from './asc'; +import type { ApplePlatform } from '../lib/apple-platform'; import { describeReq, execute } from './jsonapi'; import { addItem, draftJournalKey, ensureDraft, leaveUnusedDraft, openSubmissions, OtherSubmissionError, resolveRejected, submitWithRetry } from './submission'; const TAG = 'iap-submit'; -export async function readSubmitState(c: Asc, appId: string, want: string[], o: { appVersionId?: string; also?: string } = {}): Promise { - const appVersions = (await c.all(`/v1/apps/${appId}/appStoreVersions?filter[platform]=IOS&limit=50`)).map((v: J) => ({ id: v.id, versionString: v.attributes.versionString, +export async function readSubmitState(c: Asc, appId: string, want: string[], o: { appVersionId?: string; also?: string; platform?: ApplePlatform } = {}): Promise { + const platform = o.platform ?? 'IOS'; + const appVersions = (await c.all(`/v1/apps/${appId}/appStoreVersions?filter[platform]=${platform}&limit=50`)).map((v: J) => ({ id: v.id, versionString: v.attributes.versionString, state: v.attributes.appVersionState ?? v.attributes.appStoreState })); const iaps: PIap[] = []; for (const p of await c.all(`/v1/apps/${appId}/inAppPurchasesV2?limit=200`)) { @@ -45,10 +47,10 @@ export async function readSubmitState(c: Asc, appId: string, want: string[], o: versions: want.includes(s.attributes.productId) ? versionsOf(await c.all(`/v1/subscriptions/${s.id}/versions?limit=200`)) : [] }); } // every open review submission: a draft or one back from App Review is reused, never a second one next to it - const open = await openSubmissions(c, appId, o.also); + const open = await openSubmissions(c, appId, o.also, platform); const choice = chooseSubmission(open, { appVersionId: o.appVersionId ?? appVersions.find((v: { state: string }) => /REJECTED|INVALID_BINARY/.test(v.state))?.id }); const draft: SubmitState['draft'] = choice.action === 'reuse' ? { id: choice.sub.id, state: choice.sub.state, itemVersionIds: choice.sub.items.map(i => i.versionId) } : null; - return { appVersions, iaps, subs, groups, draft, open, choice }; + return { appVersions, iaps, subs, groups, draft, open, choice, platform }; } /** The requests a run would send: none when nothing is left to submit (seen live: every product already in review), @@ -155,7 +157,7 @@ export async function submitPlanned(ctx: Ctx, c: Asc, o: SubmitOpts): Promise { const { config, root } = ctx.loaded; @@ -23,15 +26,25 @@ export async function run(ctx: Ctx): Promise { const dry = a.has('dry'); const c = await ascClient(root, need(config.apple?.bundleId, 'apple.bundleId'), config.apple?.appId); const appId = await c.app(); - const versions = await c.all(`/v1/apps/${appId}/appStoreVersions?filter[platform]=IOS&limit=20`); + // every platform: --platform, else the only one with a version this action applies to (apple-platform.ts) + const all = await c.all(`/v1/apps/${appId}/appStoreVersions?limit=50`); const want = a.get('version'); const state = (v: J): string => v.attributes.appVersionState ?? v.attributes.appStoreState; + const LIVE = ['READY_FOR_DISTRIBUTION', 'READY_FOR_SALE']; + const fits = (x: J): boolean => manual ? state(x) === 'PENDING_DEVELOPER_RELEASE' + : phased === 'on' ? !['READY_FOR_DISTRIBUTION', 'READY_FOR_SALE', 'REPLACED_WITH_NEW_VERSION', 'REMOVED_FROM_SALE'].includes(state(x)) + : LIVE.includes(state(x)) || !!x.attributes.phasedRelease; + const what = manual ? 'a version waiting for developer release' : phased === 'on' ? 'a version not released yet' : 'a live version'; + const pick = pickPlatform(all, { flag: parsePlatform(a.get('platform')), version: want, want: fits, what }); + if (pick.note) log('apple', pick.note); + const versions = onPlatform(all, pick.platform); + const pname = platformName(pick.platform); const v: J | undefined = want ? versions.find(x => x.attributes.versionString === want) : manual ? versions.find(x => state(x) === 'PENDING_DEVELOPER_RELEASE') : phased === 'on' ? versions.find(x => !['READY_FOR_DISTRIBUTION', 'READY_FOR_SALE', 'REPLACED_WITH_NEW_VERSION', 'REMOVED_FROM_SALE'].includes(state(x))) - : versions.find(x => ['READY_FOR_DISTRIBUTION', 'READY_FOR_SALE'].includes(state(x))) ?? versions[0]; - if (!v) throw new Error(want ? `no version ${want}` : manual ? 'no version waiting for developer release (PENDING_DEVELOPER_RELEASE)' : 'no matching version'); - const tag = `${v.attributes.versionString} (${state(v)})`; + : versions.find(x => LIVE.includes(state(x))) ?? versions[0]; + if (!v) throw new Error(want ? `no ${pname} version ${want}` : manual ? `no ${pname} version waiting for developer release (PENDING_DEVELOPER_RELEASE)` : `no matching ${pname} version`); + const tag = `${pname} ${v.attributes.versionString} (${state(v)})`; if (manual) { if (state(v) !== 'PENDING_DEVELOPER_RELEASE') throw new Error(`${tag}: only an approved version waiting for developer release can be released`); diff --git a/cli/apple/resubmit.ts b/cli/apple/resubmit.ts index dcf634e..a1ef61a 100644 --- a/cli/apple/resubmit.ts +++ b/cli/apple/resubmit.ts @@ -1,5 +1,8 @@ // Resubmit an App Store version after a rejection (Invalid Binary, Guideline 2.1, ...) with a new build. -// storebound apple resubmit --build [--version 1.0.0] [--resolve-iaps] [--dry] [--yes] [--json] +// storebound apple resubmit --build [--version 1.0.0] [--platform ios|macos|tvos|visionos] [--resolve-iaps] [--dry] [--yes] [--json] +// The platform: --platform, else the only one the app has, else the one platform with a rejected version or a +// submission back from App Review (macOS, tvOS and visionOS versions are resubmitted like iOS ones); rejected +// versions on two platforms stop and ask for --platform. The build is looked up on that platform. // 1. The rejected version (--version, else the one in the submission back from App Review, else the one in a // rejected state) gets build n attached, by explicit number (never "the latest"); it must be VALID. // 2. The open review submission is reused: the one with UNRESOLVED_ISSUES (it holds the version and its in-app @@ -25,6 +28,7 @@ import { allSubscriptions } from '../lib/subscriptions'; import { ascClient, type J } from './asc'; import { readSubmitState, submitPlanned } from './iap-submit'; import { openSubmissions } from './submission'; +import { onPlatform, parsePlatform, pickPlatform, platformName, platformOf, platformSlug } from '../lib/apple-platform'; /** App Store version states a first submission may send: the editable version (Prepare for Submission, a rejected * one, or one already Ready for Review in a draft). */ @@ -38,28 +42,38 @@ export async function submitVersion(ctx: Ctx, mode: 'submit' | 'resubmit'): Prom const { config, root } = ctx.loaded; const a = ctx.args; const number = a.get('build'); - if (!number || !/^\d+(\.\d+)*$/.test(number)) throw new Error(`usage: apple ${mode} --build [--version x.y.z] [--dry] [--yes]: the build number you just uploaded (never "the latest")`); + if (!number || !/^\d+(\.\d+)*$/.test(number)) throw new Error(`usage: apple ${mode} --build [--version x.y.z] [--platform ios|macos] [--dry] [--yes]: the build number you just uploaded (never "the latest")`); const c = await ascClient(root, need(config.apple?.bundleId, 'apple.bundleId'), config.apple?.appId); const appId = await c.app(); const ids = [...(config.products ?? []).filter(p => sellsOn(config, p, 'apple')).map(p => p.id), ...allSubscriptions(config.subscriptions).filter(x => sellsOn(config, x.sub, 'apple')).map(x => x.sub.id)]; - // the version to resubmit - const versions = await c.all(`/v1/apps/${appId}/appStoreVersions?filter[platform]=IOS&limit=50`); + // the version to resubmit, on its platform: one app record holds iOS, macOS, tvOS and visionOS versions, each with + // its own review submission. Every platform is read; --platform picks one, else the one platform that has a version + // back from App Review (or, for submit, an editable one); two such platforms refuse and ask (apple-platform.ts) + const all = await c.all(`/v1/apps/${appId}/appStoreVersions?limit=50`); const stateOf = (v: J): string => v.attributes.appVersionState ?? v.attributes.appStoreState; - const open = await openSubmissions(c, appId); - const held = new Set(open.filter(s => s.state === 'UNRESOLVED_ISSUES').flatMap(s => s.items.filter(i => i.kind === 'appStoreVersion').map(i => i.versionId))); + const openAll = await openSubmissions(c, appId, undefined, 'all'); + const heldAll = new Set(openAll.filter(s => s.state === 'UNRESOLVED_ISSUES').flatMap(s => s.items.filter(i => i.kind === 'appStoreVersion').map(i => i.versionId))); const want = a.get('version'); + const wanted = (x: J): boolean => heldAll.has(x.id) || (mode === 'submit' ? SUBMITTABLE_APP : REJECTED_APP).has(stateOf(x)); + const pick = pickPlatform(all, { flag: parsePlatform(a.get('platform')), version: want, want: wanted, what: mode === 'submit' ? 'a version to submit' : 'a rejected version' }); + const platform = pick.platform; + const pname = platformName(platform); + if (pick.note && !a.has('json')) log(TAG, pick.note); + const versions = onPlatform(all, platform); + const held = new Set(openAll.filter(s => s.state === 'UNRESOLVED_ISSUES' && s.platform === platform).flatMap(s => s.items.filter(i => i.kind === 'appStoreVersion').map(i => i.versionId))); const v: J | undefined = want ? versions.find((x: J) => x.attributes.versionString === want) : versions.find((x: J) => held.has(x.id)) ?? versions.find((x: J) => (mode === 'submit' ? SUBMITTABLE_APP : REJECTED_APP).has(stateOf(x))); - if (!v) throw new Error(want ? `no App Store version ${want} on iOS` - : mode === 'submit' ? 'no App Store version to submit (none in Prepare for Submission or rejected): storebound apple listing --version x.y.z first' - : 'no rejected App Store version and no review submission with UNRESOLVED_ISSUES: nothing to resubmit (storebound apple status)'); - if (mode === 'submit' && !SUBMITTABLE_APP.has(stateOf(v)) && !held.has(v.id)) throw new Error(`App Store version ${String(v.attributes.versionString)} is ${stateOf(v)}: only a version in Prepare for Submission (or a rejected one) can be submitted`); + const seen = `App Store Connect has: ${all.length ? all.map((x: J) => `${String(x.attributes.versionString)} ${platformName(platformOf(x))} ${stateOf(x)}`).join(', ') : 'no version'}`; + if (!v) throw new Error(want ? `no App Store version ${want} on ${pname} (${seen})` + : mode === 'submit' ? `no ${pname} App Store version to submit (none in Prepare for Submission or rejected; ${seen}): storebound apple listing --version x.y.z${platform === 'IOS' ? '' : ` --platform ${platformSlug(platform)}`} first` + : `no rejected App Store version and no review submission with UNRESOLVED_ISSUES on any platform: nothing to resubmit (${seen}; storebound apple status)`); + if (mode === 'submit' && !SUBMITTABLE_APP.has(stateOf(v)) && !held.has(v.id)) throw new Error(`${pname} App Store version ${String(v.attributes.versionString)} is ${stateOf(v)}: only a version in Prepare for Submission (or a rejected one) can be submitted`); const versionString = String(v.attributes.versionString); - if (!a.has('json')) log(TAG, `app version ${versionString}: ${stateOf(v)}`); + if (!a.has('json')) log(TAG, `${pname} app version ${versionString}: ${stateOf(v)}`); // the build, by its number - const b = (await c.all(`/v1/builds?filter[app]=${appId}&filter[version]=${number}&filter[preReleaseVersion.version]=${versionString}&filter[preReleaseVersion.platform]=IOS`))[0]; + const b = (await c.all(`/v1/builds?filter[app]=${appId}&filter[version]=${number}&filter[preReleaseVersion.version]=${versionString}&filter[preReleaseVersion.platform]=${platform}`))[0]; const cur = (await c.maybe(`/v1/appStoreVersions/${v.id}/build`))?.data; const current = cur ? String(cur.attributes?.version ?? cur.id) : null; const build: BuildStep = !b ? { number, id: null, current, action: 'refuse', reason: `build ${versionString} (${number}) not found (still uploading or processing? storebound apple status)` } @@ -68,7 +82,7 @@ export async function submitVersion(ctx: Ctx, mode: 'submit' | 'resubmit'): Prom : { number, id: b.id, current, action: 'attach', reason: `attach build ${number}${current ? ` instead of ${current}` : ''}` }; if (b && b.attributes.usesNonExemptEncryption == null) warn(TAG, `build ${number} has no export compliance answer yet: storebound apple encryption (Apple refuses the submission without it)`); - const state = await readSubmitState(c, appId, ids, { appVersionId: v.id }); + const state = await readSubmitState(c, appId, ids, { appVersionId: v.id, platform }); const plan = planIapSubmission(state, ids, { withVersion: true, appVersionId: v.id }); // --build is a fixed build for the version: its REJECTED item is marked resolved; IAP items only on --resolve-iaps const resolve: ResolveScope = { version: true, iaps: a.has('resolve-iaps') }; @@ -77,7 +91,7 @@ export async function submitVersion(ctx: Ctx, mode: 'submit' | 'resubmit'): Prom const blockers = [...(build.action === 'refuse' ? [build.reason] : []), ...plan.blockers]; const dry = a.has('dry') || !a.has('yes'); if (a.has('json')) { - printJson({ dryRun: dry, version: { id: v.id, versionString, state: stateOf(v) }, build, submission: state.choice ?? null, resolve: marks, rows, skipped: plan.skipped, blockers }); + printJson({ dryRun: dry, platform, platformPick: pick, version: { id: v.id, versionString, state: stateOf(v), platform }, build, submission: state.choice ?? null, resolve: marks, rows, skipped: plan.skipped, blockers }); // the desktop's owner dialog shows the output text: the plan table goes with the result there if (process.env.STOREBOUND_MACHINE === '1') { console.log(formatRows(rows)); for (const x of blockers) warn(TAG, x); } if (blockers.length) process.exitCode = 1; diff --git a/cli/apple/status.ts b/cli/apple/status.ts index c4808c1..73a0b5a 100644 --- a/cli/apple/status.ts +++ b/cli/apple/status.ts @@ -7,7 +7,9 @@ // A submission back from App Review (UNRESOLVED_ISSUES) is shown with its items; resubmit it with // storebound apple resubmit --build // Wait for App Review (polls with backoff: 1 min, x1.5, max 15 min): -// storebound apple status --wait-review [--version 1.2.0] [--timeout 48h] +// storebound apple status --wait-review [--version 1.2.0] [--platform ios|macos] [--timeout 48h] +// Every version and review submission line names its platform (iOS, macOS, tvOS, visionOS): one app record holds them +// all, and a rejected macOS version must not read like the iOS one. // exit codes: 0 approved, 1 rejected, 7 timeout (2 = nothing in review) // Also compares the App ID's capabilities, apple.signing.capabilities and the iOS project's entitlements and warns, // naming what is missing where. @@ -23,20 +25,24 @@ import { type Asc, ascClient, type J } from './asc'; import { notCancellable, readItems, type SubItem } from './submission'; import { capabilityReport, type CapabilityReport, printCapabilityReport } from './signing'; import * as rt from '../lib/rt'; +import { type ApplePlatform, parsePlatform, platformName, platformOf, platformSlug } from '../lib/apple-platform'; async function waitReview(ctx: Ctx, c: Asc, appId: string): Promise { const want = ctx.args.get('version'); + // every platform unless --platform: a macOS version in review is waited for like an iOS one + const platform = parsePlatform(ctx.args.get('platform')); const deadline = Date.now() + parseDuration(ctx.args.str('timeout', '48h')); const state = (v: J): string => v.attributes.appVersionState ?? v.attributes.appStoreState; let delay: number | null = null; let last = ''; for (;;) { - const vs = await c.all(`/v1/apps/${appId}/appStoreVersions?filter[platform]=IOS&limit=10`); - const v = want ? vs.find(x => x.attributes.versionString === want) : vs.find(x => classifyReviewState(state(x)) === 'pending') ?? vs[0]; - if (!v) { log('apple', `no version ${want ?? ''} found`); process.exit(2); } + const vs = await c.all(`/v1/apps/${appId}/appStoreVersions?${platform ? `filter[platform]=${platform}&` : ''}limit=10`); + const pending = (x: J): boolean => classifyReviewState(state(x)) === 'pending'; + const v = want ? vs.find(x => x.attributes.versionString === want && pending(x)) ?? vs.find(x => x.attributes.versionString === want) : vs.find(pending) ?? vs[0]; + if (!v) { log('apple', `no version ${want ?? ''} found${platform ? ` on ${platformName(platform)}` : ''}`); process.exit(2); } const st = state(v); const outcome = classifyReviewState(st); - if (st !== last) { log('apple', `${v.attributes.versionString}: ${st}`); last = st; } + if (st !== last) { log('apple', `${v.attributes.versionString} (${platformName(platformOf(v))}): ${st}`); last = st; } if (outcome === 'approved') { log('apple', 'approved (release it yourself, or it goes out automatically if the release type says so)'); process.exit(WAIT_EXIT.approved); } if (outcome === 'rejected') { log('apple', `rejected: read the message in ${consoleLink('asc.app-review')}, then the review-rejections skill`); process.exit(WAIT_EXIT.rejected); } if (outcome === 'not-submitted') { log('apple', 'nothing is waiting for review'); process.exit(2); } @@ -77,8 +83,8 @@ export async function run(ctx: Ctx): Promise { let caps: CapabilityReport | { error: string }; try { caps = await capabilityReport(c, config, root); } catch (e) { caps = { error: (e as Error).message.slice(0, 300) }; } // a submission back from App Review: its items and their states, and how to resubmit it - const unresolved: { id: string; items: SubItem[] }[] = []; - for (const s of subs.filter((x: J) => x.attributes?.state === 'UNRESOLVED_ISSUES')) unresolved.push({ id: s.id, items: await readItems(c, s.id) }); + const unresolved: { id: string; platform: ApplePlatform; items: SubItem[] }[] = []; + for (const s of subs.filter((x: J) => x.attributes?.state === 'UNRESOLVED_ISSUES')) unresolved.push({ id: s.id, platform: platformOf(s), items: await readItems(c, s.id) }); // an empty draft: App Store Connect keeps it and refuses to cancel it; harmless const empty = new Set(); for (const s of subs.filter((x: J) => x.attributes?.state === 'READY_FOR_REVIEW')) if (!(await readItems(c, s.id)).length) empty.add(s.id); @@ -89,7 +95,7 @@ export async function run(ctx: Ctx): Promise { try { gaps = await firstProductReport(c, appId, { iaps, versionState: reviewed ? vstate(reviewed) : undefined }); } catch (e) { log('apple', `first in-app purchases not compared with the review: ${(e as Error).message.slice(0, 200)}`); } const itemLabel = (kind: string, id: string): string => { const v = versions.find((x: J) => x.id === id); - return v ? `app version ${v.attributes.versionString}` : `${kind} ${id}`; + return v ? `${platformName(platformOf(v))} app version ${v.attributes.versionString}` : `${kind} ${id}`; }; if (ctx.args.has('json')) { // phased release of the newest versions that are live or close to it (rollout share on the desktop timeline) @@ -115,16 +121,17 @@ export async function run(ctx: Ctx): Promise { } console.log(`${app.attributes.name} · ${app.attributes.bundleId} · Apple ID ${appId}`); - for (const v of versions) console.log(` version ${v.attributes.versionString.padEnd(8)} ${v.attributes.appVersionState ?? v.attributes.appStoreState}${v.relationships?.build?.data ? ' (build attached)' : ''}`); + // one app record holds iOS, macOS, tvOS and visionOS versions: every line names its platform + for (const v of versions) console.log(` version ${String(v.attributes.versionString).padEnd(8)} ${platformName(platformOf(v)).padEnd(8)} ${v.attributes.appVersionState ?? v.attributes.appStoreState}${v.relationships?.build?.data ? ' (build attached)' : ''}`); const pre = new Map((builds.included ?? []).map((p: { id: string; attributes: { version: string } }) => [p.id, p.attributes.version])); for (const b of builds.data) console.log(` build ${String(pre.get(b.relationships?.preReleaseVersion?.data?.id) ?? '?')} (${b.attributes.version}) ${b.attributes.processingState} ${b.attributes.uploadedDate?.slice(0, 10) ?? ''}`); for (const p of iaps) console.log(` iap ${p.attributes.productId.padEnd(40)} ${p.attributes.inAppPurchaseType} ${p.attributes.state}`); - for (const s of subs) console.log(` review submission ${s.id} ${s.attributes.state}${empty.has(s.id) ? `: ${EMPTY_DRAFT}` : ''} ${s.attributes.submittedDate?.slice(0, 10) ?? ''}`.trimEnd()); + for (const s of subs) console.log(` review submission ${s.id} ${platformName(platformOf(s))} ${s.attributes.state}${empty.has(s.id) ? `: ${EMPTY_DRAFT}` : ''} ${s.attributes.submittedDate?.slice(0, 10) ?? ''}`.trimEnd()); for (const u of unresolved) { - console.log(` review submission ${u.id} is back from App Review with UNRESOLVED_ISSUES; its items:`); + console.log(` review submission ${u.id} (${platformName(u.platform)}) is back from App Review with UNRESOLVED_ISSUES; its items:`); for (const it of u.items) console.log(` ${itemLabel(it.kind, it.versionId).padEnd(36)} ${it.state}${it.state === 'REJECTED' ? ' (not resolved: Apple takes no resubmit until it is; apple resubmit marks it resolved)' : ''}`); const newest = builds.data[0]?.attributes?.version; - console.log(` resubmit with: storebound apple resubmit --build ${newest ? ` (newest uploaded build: ${newest})` : ''}`); + console.log(` resubmit with: storebound apple resubmit --build ${u.platform === 'IOS' ? '' : ` --platform ${platformSlug(u.platform)}`}${newest ? ` (newest uploaded build: ${newest})` : ''}`); } for (const g of gaps) warn('apple', `${g.msg}; ${g.fix}`); if ('error' in caps) log('apple', `capabilities not compared: ${caps.error}`); diff --git a/cli/apple/submission.ts b/cli/apple/submission.ts index f182332..f82ba9c 100644 --- a/cli/apple/submission.ts +++ b/cli/apple/submission.ts @@ -7,11 +7,12 @@ import { createOnce, findOrCreate } from '../lib/upsert'; import { EMPTY_DRAFT, resolveHint, type ResolveScope, toResolve } from '../lib/review-submit'; import type { Asc, J } from './asc'; import { one } from './jsonapi'; +import { type ApplePlatform, platformName, platformOf } from '../lib/apple-platform'; import * as rt from '../lib/rt'; -/** The draft review submission of the app (READY_FOR_REVIEW, iOS), or null. */ -export async function findDraft(c: Asc, appId: string): Promise { - return (await c.all(`/v1/reviewSubmissions?filter[app]=${appId}&filter[platform]=IOS&filter[state]=READY_FOR_REVIEW&limit=10`))[0]?.id ?? null; +/** The draft review submission of the app on a platform (READY_FOR_REVIEW; default iOS), or null. */ +export async function findDraft(c: Asc, appId: string, platform: ApplePlatform = 'IOS'): Promise { + return (await c.all(`/v1/reviewSubmissions?filter[app]=${appId}&filter[platform]=${platform}&filter[state]=READY_FOR_REVIEW&limit=10`))[0]?.id ?? null; } /** The draft's id: the existing one, else a new draft created once. */ @@ -19,16 +20,16 @@ export async function draftSubmission(c: Asc, appId: string, root: string, tag: return (await ensureDraft(c, appId, root, tag)).id; } -/** The journal key of the draft storebound created (cli/lib/upsert.ts). */ -export const draftJournalKey = (appId: string): string => `apple:${appId}:reviewSubmission:draft`; +/** The journal key of the draft storebound created (cli/lib/upsert.ts); iOS keeps the key it always had. */ +export const draftJournalKey = (appId: string, platform: ApplePlatform = 'IOS'): string => `apple:${appId}:reviewSubmission:draft${platform === 'IOS' ? '' : `:${platform}`}`; /** Like draftSubmission, and says whether this run created the draft (an unused empty one is left: not cancellable). */ -export async function ensureDraft(c: Asc, appId: string, root: string, tag: string): Promise<{ id: string; created: boolean }> { - const r = await findOrCreate({ what: 'draft review submission', tag, unique: true, - find: () => findDraft(c, appId), - journal: { root, key: draftJournalKey(appId), idOf: id => id, +export async function ensureDraft(c: Asc, appId: string, root: string, tag: string, platform: ApplePlatform = 'IOS'): Promise<{ id: string; created: boolean }> { + const r = await findOrCreate({ what: `draft review submission${platform === 'IOS' ? '' : ` (${platformName(platform)})`}`, tag, unique: true, + find: () => findDraft(c, appId, platform), + journal: { root, key: draftJournalKey(appId, platform), idOf: id => id, byId: async id => { const d = (await c.maybe(`/v1/reviewSubmissions/${id}`))?.data; return d?.attributes?.state === 'READY_FOR_REVIEW' ? id : null; } }, - create: async () => (await c.asc('POST', '/v1/reviewSubmissions', { data: { type: 'reviewSubmissions', attributes: { platform: 'IOS' }, relationships: { app: one('apps', appId) } } })).data.id as string }); + create: async () => (await c.asc('POST', '/v1/reviewSubmissions', { data: { type: 'reviewSubmissions', attributes: { platform }, relationships: { app: one('apps', appId) } } })).data.id as string }); if (r.created) log(tag, `draft review submission ${r.value} created`); return { id: r.value, created: r.created }; } @@ -70,7 +71,7 @@ export async function addItem(c: Asc, sid: string, kind: string, id: string, lab export const OPEN_STATES = ['READY_FOR_REVIEW', 'UNRESOLVED_ISSUES', 'WAITING_FOR_REVIEW', 'IN_REVIEW'] as const; export interface SubItem { id: string; kind: string; versionId: string; state: string } -export interface OpenSubmission { id: string; state: string; submittedDate?: string; items: SubItem[] } +export interface OpenSubmission { id: string; state: string; platform: ApplePlatform; submittedDate?: string; items: SubItem[] } /** The items of a review submission: kind (appStoreVersion, inAppPurchaseVersion, ...), the version id, the item state. */ export async function readItems(c: Asc, sid: string): Promise { @@ -81,13 +82,14 @@ export async function readItems(c: Asc, sid: string): Promise { }); } -/** Every open review submission of the app on iOS (OPEN_STATES), each with its items. `also`: a submission id a 409 - * named, read directly (a list may lag behind, or its state may be outside the filter). */ -export async function openSubmissions(c: Asc, appId: string, also?: string): Promise { - const subs = await c.all(`/v1/apps/${appId}/reviewSubmissions?filter[platform]=IOS&filter[state]=${OPEN_STATES.join(',')}&include=items&limit=50`); +/** Every open review submission of the app (OPEN_STATES) on a platform (default iOS; 'all': every platform, each + * labelled), each with its items. `also`: a submission id a 409 named, read directly (a list may lag behind, or its + * state may be outside the filter). */ +export async function openSubmissions(c: Asc, appId: string, also?: string, platform: ApplePlatform | 'all' = 'IOS'): Promise { + const subs = await c.all(`/v1/apps/${appId}/reviewSubmissions?${platform === 'all' ? '' : `filter[platform]=${platform}&`}filter[state]=${OPEN_STATES.join(',')}&include=items&limit=50`); if (also && !subs.some((x: J) => x.id === also)) { const d = (await c.maybe(`/v1/reviewSubmissions/${also}`))?.data; if (d) subs.push(d); } const out: OpenSubmission[] = []; - for (const x of subs) out.push({ id: x.id, state: x.attributes?.state ?? '?', submittedDate: x.attributes?.submittedDate ?? undefined, items: await readItems(c, x.id) }); + for (const x of subs) out.push({ id: x.id, state: x.attributes?.state ?? '?', platform: platformOf(x), submittedDate: x.attributes?.submittedDate ?? undefined, items: await readItems(c, x.id) }); return out; } diff --git a/cli/apple/submit.ts b/cli/apple/submit.ts index 2ecc5af..67141f4 100644 --- a/cli/apple/submit.ts +++ b/cli/apple/submit.ts @@ -1,5 +1,5 @@ // Send an App Store version to App Review with a build picked by its number (the owner's step). -// storebound apple submit --build [--version 1.0.0] [--resolve-iaps] [--dry] [--yes] [--json] +// storebound apple submit --build [--version 1.0.0] [--platform ios|macos|tvos|visionos] [--resolve-iaps] [--dry] [--yes] [--json] // The version is --version, else the one an open review submission holds, else the editable one (Prepare for // Submission, or rejected). Build n (VALID) is attached, the open review submission is reused (a draft or one back // from App Review; a new draft only when none is open), the in-app purchases and subscriptions of the config that are diff --git a/cli/lib/apple-platform.ts b/cli/lib/apple-platform.ts new file mode 100644 index 0000000..110332c --- /dev/null +++ b/cli/lib/apple-platform.ts @@ -0,0 +1,71 @@ +// The platform of an App Store version: one app record can hold an iOS, a macOS, a tvOS and a visionOS version, each +// with its own version string, state, build and review submission. Commands that act on "the" version (listing, +// submit, resubmit, release, status --wait-review) pick the platform here: --platform when given, else the only +// platform the app has, else the one platform where the version the command needs is (a rejected one for resubmit, +// an editable one for listing), else iOS with a note. Two candidates refuse and ask for --platform: guessing between +// a rejected iOS and a rejected macOS version would act on the wrong one. Pure. +// +// Lesson (2026-10-20): `apple resubmit` read iOS versions only and said "nothing to resubmit" while a macOS version was +// REJECTED with an UNRESOLVED_ISSUES submission; `apple listing --version` refused because the iOS version with that +// number was READY_FOR_DISTRIBUTION while the macOS one was the rejected one to fix. + +export type ApplePlatform = 'IOS' | 'MAC_OS' | 'TV_OS' | 'VISION_OS'; +export const APPLE_PLATFORMS: readonly ApplePlatform[] = ['IOS', 'MAC_OS', 'TV_OS', 'VISION_OS']; + +const NAMES: Record = { IOS: 'iOS', MAC_OS: 'macOS', TV_OS: 'tvOS', VISION_OS: 'visionOS' }; +const SLUGS: Record = { IOS: 'ios', MAC_OS: 'macos', TV_OS: 'tvos', VISION_OS: 'visionos' }; + +/** "iOS", "macOS", ... (an unknown value as it is). */ +export const platformName = (p: string): string => NAMES[p as ApplePlatform] ?? p; +/** The --platform value of a platform: ios, macos, tvos, visionos. */ +export const platformSlug = (p: ApplePlatform): string => SLUGS[p]; + +/** --platform ios|macos|tvos|visionos (also IOS, MAC_OS, mac, ipados, xros, ...) -> the API value; undefined when not given. */ +export function parsePlatform(v: string | undefined): ApplePlatform | undefined { + if (v === undefined || v === '') return undefined; + const k = v.toLowerCase().replace(/[^a-z]/g, ''); + if (['ios', 'ipados', 'iphone', 'ipad'].includes(k)) return 'IOS'; + if (['macos', 'mac', 'osx', 'macosx'].includes(k)) return 'MAC_OS'; + if (['tvos', 'appletv', 'tv'].includes(k)) return 'TV_OS'; + if (['visionos', 'vision', 'xros', 'visionpro'].includes(k)) return 'VISION_OS'; + throw new Error(`--platform ${v}: one of ios, macos, tvos, visionos`); +} + +interface Row { id?: string; attributes: Record } +/** The platform of a version row (rows without one are iOS, as App Store Connect answered before it had others). */ +export const platformOf = (r: Row): ApplePlatform => (APPLE_PLATFORMS as readonly string[]).includes(String(r.attributes.platform)) ? r.attributes.platform as ApplePlatform : 'IOS'; +export const stateOfRow = (r: Row): string => String(r.attributes.appVersionState ?? r.attributes.appStoreState ?? ''); +const distinct = (rows: Row[]): ApplePlatform[] => APPLE_PLATFORMS.filter(p => rows.some(r => platformOf(r) === p)); + +export interface PlatformPick { + platform: ApplePlatform; + /** flag: --platform; only: the app has versions on one platform (or none); auto: the one platform with the wanted + * version; default: iOS while other platforms exist (said in `note`). */ + how: 'flag' | 'only' | 'auto' | 'default'; + note?: string; +} + +/** + * Picks the platform a command acts on. `want(row)`: the version the command needs (resubmit: rejected or held by a + * submission back from App Review; listing: editable; release: approved / live). `what` names it for the messages + * ("a rejected version"). Throws when the wanted version is on more than one platform and no --platform was given. Pure. + */ +export function pickPlatform(rows: Row[], o: { flag?: ApplePlatform; version?: string; want: (r: Row) => boolean; what: string }): PlatformPick { + if (o.flag) return { platform: o.flag, how: 'flag' }; + const present = distinct(rows); + if (present.length <= 1) return { platform: present[0] ?? 'IOS', how: 'only' }; + const scoped = o.version ? rows.filter(r => r.attributes.versionString === o.version) : rows; + const label = `${o.what}${o.version ? ` (${o.version})` : ''}`; + const hits = distinct(scoped.filter(o.want)); + if (hits.length > 1) + throw new Error(`${label} on ${hits.map(platformName).join(' and ')}: say which with --platform ${hits.map(platformSlug).join('|')} (storebound apple status lists every version with its platform)`); + if (hits.length === 1) return { platform: hits[0]!, how: 'auto', note: `${label} only on ${platformName(hits[0]!)}: acting on ${platformName(hits[0]!)} (--platform ${present.map(platformSlug).join('|')} to choose)` }; + if (o.version) { + const has = distinct(scoped); + if (has.length === 1) return { platform: has[0]!, how: 'auto', note: `version ${o.version} only on ${platformName(has[0]!)}: acting on ${platformName(has[0]!)} (--platform to choose)` }; + } + return { platform: 'IOS', how: 'default', note: `the app has versions on ${present.map(platformName).join(', ')}; acting on iOS (--platform ${present.filter(p => p !== 'IOS').map(platformSlug).join('|')} for the other)` }; +} + +/** Version rows of one platform. */ +export const onPlatform = (rows: T[], p: ApplePlatform): T[] => rows.filter(r => platformOf(r) === p); diff --git a/cli/lib/review-submit.ts b/cli/lib/review-submit.ts index 19df069..2d9d804 100644 --- a/cli/lib/review-submit.ts +++ b/cli/lib/review-submit.ts @@ -25,6 +25,7 @@ // https://developer.apple.com/help/app-store-connect/manage-submissions-to-app-review/submit-an-in-app-purchase import type { Req } from '../apple/jsonapi'; import { one } from '../apple/jsonapi'; +import type { ApplePlatform } from './apple-platform'; export const MAX_SUBMISSION_ITEMS = 200; @@ -66,6 +67,8 @@ export interface SubmitState { /** Every open review submission (chooseSubmission) and what was decided. */ open?: OpenSub[]; choice?: SubmissionChoice; + /** The App Store platform of the app versions and submissions (IOS when left out; apple-platform.ts). */ + platform?: ApplePlatform; } export interface OpenSub { id: string; state: string; items: { id?: string; kind: string; versionId: string; state: string }[] } @@ -212,7 +215,7 @@ export function planIapSubmission(s: SubmitState, want: string[], o: { withVersi } if (plan.items.length + (s.draft?.itemVersionIds.length ?? 0) > MAX_SUBMISSION_ITEMS) plan.blockers.push(`more than ${MAX_SUBMISSION_ITEMS} items in one submission: use --only for a part`); const sid = s.draft?.id ?? '${submission}'; - if (!s.draft && plan.items.length) plan.prepare.push({ method: 'POST', path: '/v1/reviewSubmissions', note: 'new draft review submission', body: { data: { type: 'reviewSubmissions', attributes: { platform: 'IOS' }, relationships: { app: one('apps', '${app}') } } } }); + if (!s.draft && plan.items.length) plan.prepare.push({ method: 'POST', path: '/v1/reviewSubmissions', note: 'new draft review submission', body: { data: { type: 'reviewSubmissions', attributes: { platform: s.platform ?? 'IOS' }, relationships: { app: one('apps', '${app}') } } } }); for (const it of plan.items) plan.prepare.push({ method: 'POST', path: '/v1/reviewSubmissionItems', note: it.label, body: { data: { type: 'reviewSubmissionItems', relationships: { reviewSubmission: one('reviewSubmissions', sid), [it.kind]: one(ITEM_TYPE[it.kind], it.versionId) } } } }); plan.submit = { method: 'PATCH', path: `/v1/reviewSubmissions/${sid}`, note: 'submit for App Review', body: { data: { type: 'reviewSubmissions', id: sid, attributes: { submitted: true } } } };