@sprid/release 1.3.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/README.md +67 -0
- package/package.json +1 -1
- package/src/annotate.ts +4 -1
- package/src/asc/age-rating.ts +86 -0
- package/src/asc/client.ts +14 -2
- package/src/asc/index.ts +6 -0
- package/src/asc/page-results.ts +218 -0
- package/src/asc/product-pages.ts +513 -0
- package/src/asc/submissions.ts +64 -0
- package/src/asc/submit.ts +6 -1
- package/src/cli.ts +65 -3
- package/src/config.ts +71 -0
|
@@ -0,0 +1,513 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom product pages and product page optimization tests (iOS).
|
|
3
|
+
*
|
|
4
|
+
* A custom product page is a second App Store page with its own screenshots,
|
|
5
|
+
* promotional text, deep link and search keywords, reached at its own URL
|
|
6
|
+
* (`?ppid=<page id>`). Traffic you send there (an ad, a link, a keyword) sees
|
|
7
|
+
* that page; Apple's analytics reports then split views and downloads by its name.
|
|
8
|
+
*
|
|
9
|
+
* A product page optimization test is Apple splitting the default page's own
|
|
10
|
+
* visitors between the original and up to three treatments (icon, screenshots).
|
|
11
|
+
* Apple measures it; its API returns no results, only the test's state and dates.
|
|
12
|
+
*
|
|
13
|
+
* pages: POST /appCustomProductPages (+ inline version and localizations)
|
|
14
|
+
* → promotional text, deep link, keywords, visibility
|
|
15
|
+
* → screenshots through Asset Library placements on each localization
|
|
16
|
+
* → `--submit` adds the page versions to a review submission
|
|
17
|
+
* page-test: POST /v2/appStoreVersionExperiments → treatments → localizations
|
|
18
|
+
* → screenshots on each treatment localization
|
|
19
|
+
* → `--start` sets started and adds the test to a review submission
|
|
20
|
+
*
|
|
21
|
+
* Screenshots go through Asset Library: the screenshot-set endpoints were
|
|
22
|
+
* deprecated at App Store Connect API 4.5. Every file is uploaded and processed
|
|
23
|
+
* before any existing placement is deleted.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import { readdirSync, readFileSync } from 'node:fs';
|
|
27
|
+
import { basename, dirname, extname, resolve } from 'node:path';
|
|
28
|
+
import { listingLocaleMap, releasePath, type AppReleaseConfig, type AscCustomProductPage, type AscPageScreenshots, type AscProductPageTest } from '../config.ts';
|
|
29
|
+
import { LIMITS } from '../copy.ts';
|
|
30
|
+
import { createAscClient, type AscClient } from './client.ts';
|
|
31
|
+
import { imageInfo, uploadLibraryAsset } from './creative.ts';
|
|
32
|
+
import { addToReview, type ReviewItem } from './submissions.ts';
|
|
33
|
+
|
|
34
|
+
export const DEFAULT_SCREENSHOT_PROFILE = 'IPHONE_DYNAMIC_ISLAND_LARGE_PROFILE';
|
|
35
|
+
const MAX_PAGES = 70;
|
|
36
|
+
const MAX_SCREENSHOTS = 10;
|
|
37
|
+
const MAX_TREATMENTS = 3;
|
|
38
|
+
/** Page versions that take edits. A version in review is locked until it is withdrawn. */
|
|
39
|
+
const EDITABLE_PAGE_STATES = new Set(['PREPARE_FOR_SUBMISSION', 'REJECTED']);
|
|
40
|
+
const EDITABLE_TEST_STATES = new Set(['PREPARE_FOR_SUBMISSION', 'REJECTED']);
|
|
41
|
+
const FINISHED_TEST_STATES = new Set(['COMPLETED', 'STOPPED']);
|
|
42
|
+
|
|
43
|
+
export interface ScreenshotSet { profile: string; files: string[] }
|
|
44
|
+
|
|
45
|
+
/** `<dir>/<glob>` with `{lang}` filled in, where the last segment holds the only `*`. */
|
|
46
|
+
function filesFor(config: AppReleaseConfig, set: AscPageScreenshots, lang: string): string[] {
|
|
47
|
+
const full = resolve(releasePath(config, set.dir), set.glob.replaceAll('{lang}', lang));
|
|
48
|
+
const rx = new RegExp('^' + basename(full).replace(/[.+?^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '.*') + '$');
|
|
49
|
+
try {
|
|
50
|
+
return readdirSync(dirname(full)).filter(n => rx.test(n)).sort().map(n => resolve(dirname(full), n));
|
|
51
|
+
} catch {
|
|
52
|
+
return [];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const asList = <T>(value: T | T[] | undefined): T[] => (value === undefined ? [] : Array.isArray(value) ? value : [value]);
|
|
57
|
+
|
|
58
|
+
/** Resolve one owner's screenshot sets for one locale and collect what is wrong with them. */
|
|
59
|
+
function resolveSets(config: AppReleaseConfig, sets: AscPageScreenshots[], lang: string, where: string, problems: string[]): ScreenshotSet[] {
|
|
60
|
+
const out: ScreenshotSet[] = [];
|
|
61
|
+
const profiles = new Set<string>();
|
|
62
|
+
for (const set of sets) {
|
|
63
|
+
const profile = set.profile ?? DEFAULT_SCREENSHOT_PROFILE;
|
|
64
|
+
if (profiles.has(profile)) problems.push(`${where}: two screenshot sets for ${profile}`);
|
|
65
|
+
profiles.add(profile);
|
|
66
|
+
const files = filesFor(config, set, lang);
|
|
67
|
+
if (!files.length) { problems.push(`${where}: no screenshots match ${set.glob.replaceAll('{lang}', lang)}`); continue; }
|
|
68
|
+
if (files.length > MAX_SCREENSHOTS) problems.push(`${where}: ${files.length} screenshots for ${profile}; the store takes ${MAX_SCREENSHOTS}`);
|
|
69
|
+
for (const file of files) {
|
|
70
|
+
if (!['.png', '.jpg', '.jpeg'].includes(extname(file).toLowerCase())) { problems.push(`${basename(file)}: screenshots are PNG or JPEG`); continue; }
|
|
71
|
+
try {
|
|
72
|
+
if (imageInfo(readFileSync(file)).alpha) problems.push(`${basename(file)}: has an alpha channel; App Store Connect refuses transparency`);
|
|
73
|
+
} catch (e) {
|
|
74
|
+
problems.push(`${basename(file)}: ${(e as Error).message}`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
out.push({ profile, files });
|
|
78
|
+
}
|
|
79
|
+
return out;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface PagePlan {
|
|
83
|
+
name: string;
|
|
84
|
+
deepLink?: string;
|
|
85
|
+
visible: boolean;
|
|
86
|
+
/** Keywords are managed only for a page that declares them; others keep what App Store Connect holds. */
|
|
87
|
+
manageKeywords: boolean;
|
|
88
|
+
locales: { locale: string; promotionalText?: string; keywords: string[]; screenshots: ScreenshotSet[] }[];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Check every page locally and resolve its files. Throws with every problem at once. */
|
|
92
|
+
export function planPages(config: AppReleaseConfig, localeMap: Record<string, string>): PagePlan[] {
|
|
93
|
+
const pages = config.ascCustomProductPages;
|
|
94
|
+
if (!pages?.length) throw new Error('release.config.ts needs `ascCustomProductPages` for the pages command.');
|
|
95
|
+
const problems: string[] = [];
|
|
96
|
+
if (pages.length > MAX_PAGES) problems.push(`${pages.length} pages; App Store Connect allows ${MAX_PAGES}`);
|
|
97
|
+
const names = new Set<string>();
|
|
98
|
+
const plans = pages.map((page: AscCustomProductPage) => {
|
|
99
|
+
const name = page.name?.trim();
|
|
100
|
+
if (!name) problems.push('every custom product page needs a name');
|
|
101
|
+
else if (names.has(name)) problems.push(`two pages are named "${name}"; analytics reports tell pages apart by name`);
|
|
102
|
+
names.add(name);
|
|
103
|
+
if (page.deepLink) {
|
|
104
|
+
try { new URL(page.deepLink); } catch { problems.push(`${name}: deepLink ${page.deepLink} is not a URL`); }
|
|
105
|
+
}
|
|
106
|
+
const sets = asList(page.screenshots);
|
|
107
|
+
if (!sets.length) problems.push(`${name}: a custom product page needs screenshots`);
|
|
108
|
+
const locales = Object.entries(localeMap).map(([locale, lang]) => {
|
|
109
|
+
const promotionalText = page.promotionalText?.[lang] ?? config.storeCopy?.[lang]?.promotionalText;
|
|
110
|
+
if (promotionalText && promotionalText.length > LIMITS.promotionalText) {
|
|
111
|
+
problems.push(`${name} [${locale}]: promotional text is ${promotionalText.length}/${LIMITS.promotionalText} characters`);
|
|
112
|
+
}
|
|
113
|
+
const keywords = (page.keywords?.[lang] ?? []).map(k => k.trim()).filter(Boolean);
|
|
114
|
+
const own = config.storeCopy?.[lang]?.keywords;
|
|
115
|
+
if (own !== undefined) {
|
|
116
|
+
const listed = new Set(own.split(',').map(k => k.trim().toLowerCase()));
|
|
117
|
+
for (const k of keywords) if (!listed.has(k.toLowerCase())) problems.push(`${name} [${locale}]: keyword "${k}" is not in storeCopy.${lang}.keywords; a page can only take the app's own keywords`);
|
|
118
|
+
}
|
|
119
|
+
return { locale, promotionalText, keywords, screenshots: resolveSets(config, sets, lang, `${name} [${locale}]`, problems) };
|
|
120
|
+
});
|
|
121
|
+
return { name, deepLink: page.deepLink, visible: page.visible ?? true, manageKeywords: page.keywords !== undefined, locales };
|
|
122
|
+
});
|
|
123
|
+
if (problems.length) throw new Error(`Custom product pages are not ready:\n ${problems.join('\n ')}`);
|
|
124
|
+
return plans;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export interface TestPlan {
|
|
128
|
+
name: string;
|
|
129
|
+
trafficProportion: number;
|
|
130
|
+
treatments: { name: string; appIconName?: string; locales: { locale: string; screenshots: ScreenshotSet[] }[] }[];
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export function planTest(config: AppReleaseConfig, localeMap: Record<string, string>): TestPlan {
|
|
134
|
+
const test: AscProductPageTest | undefined = config.ascProductPageTest;
|
|
135
|
+
if (!test) throw new Error('release.config.ts needs `ascProductPageTest` for the page-test command.');
|
|
136
|
+
const problems: string[] = [];
|
|
137
|
+
if (!test.name?.trim()) problems.push('the test needs a name');
|
|
138
|
+
if (!Number.isInteger(test.trafficProportion) || test.trafficProportion < 1 || test.trafficProportion > 100) {
|
|
139
|
+
problems.push(`trafficProportion ${test.trafficProportion}: a whole percent from 1 to 100`);
|
|
140
|
+
}
|
|
141
|
+
if (!test.treatments?.length || test.treatments.length > MAX_TREATMENTS) problems.push(`${test.treatments?.length ?? 0} treatments; a test takes 1 to ${MAX_TREATMENTS}`);
|
|
142
|
+
const names = new Set<string>();
|
|
143
|
+
const treatments = (test.treatments ?? []).map(t => {
|
|
144
|
+
if (!t.name?.trim()) problems.push('every treatment needs a name');
|
|
145
|
+
else if (names.has(t.name)) problems.push(`two treatments are named "${t.name}"`);
|
|
146
|
+
names.add(t.name);
|
|
147
|
+
const sets = asList(t.screenshots);
|
|
148
|
+
if (!sets.length && !t.appIconName) problems.push(`${t.name}: a treatment needs screenshots or an appIconName, or it shows the original`);
|
|
149
|
+
const locales = sets.length
|
|
150
|
+
? Object.entries(localeMap).map(([locale, lang]) => ({ locale, screenshots: resolveSets(config, sets, lang, `${t.name} [${locale}]`, problems) }))
|
|
151
|
+
: [];
|
|
152
|
+
return { name: t.name, appIconName: t.appIconName, locales };
|
|
153
|
+
});
|
|
154
|
+
if (problems.length) throw new Error(`The product page test is not ready:\n ${problems.join('\n ')}`);
|
|
155
|
+
return { name: test.name.trim(), trafficProportion: test.trafficProportion, treatments };
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** Every page of a list endpoint. Apple's `links.next` is absolute; the client accepts it. */
|
|
159
|
+
export async function listAll(client: AscClient, path: string): Promise<any[]> {
|
|
160
|
+
const out: any[] = [];
|
|
161
|
+
for (let next: string | undefined = path, pages = 0; next; pages++) {
|
|
162
|
+
if (pages >= 20) throw new Error(`${path}: more than 20 pages of results`);
|
|
163
|
+
const res = await client.api(next);
|
|
164
|
+
out.push(...(res?.data ?? []));
|
|
165
|
+
next = res?.links?.next;
|
|
166
|
+
}
|
|
167
|
+
return out;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
interface Owner { rel: 'appCustomProductPageLocalization' | 'appStoreVersionExperimentTreatmentLocalization'; type: string; id: string; label: string }
|
|
171
|
+
const ownerPath = (o: Owner) => `/${o.type}/${o.id}`;
|
|
172
|
+
|
|
173
|
+
/** Upload every distinct file once, before anything on the store is replaced. */
|
|
174
|
+
async function uploadAll(client: AscClient, appId: string, files: string[]): Promise<Map<string, { type: string; id: string }>> {
|
|
175
|
+
const uploaded = new Map<string, { type: string; id: string }>();
|
|
176
|
+
if (!files.length) return uploaded;
|
|
177
|
+
const { data: library } = await client.api(`/apps/${appId}/assetLibrary`);
|
|
178
|
+
for (const file of new Set(files)) {
|
|
179
|
+
uploaded.set(file, await uploadLibraryAsset(client, library.id, file, { category: 'APP_SCREENSHOTS_AND_PREVIEWS' }));
|
|
180
|
+
console.log(` uploaded ${basename(file)}`);
|
|
181
|
+
}
|
|
182
|
+
return uploaded;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** Replace the owner's screenshots in each given profile with the uploaded files, in order. */
|
|
186
|
+
async function placeScreenshots(client: AscClient, owner: Owner, sets: ScreenshotSet[], uploaded: Map<string, { type: string; id: string }>): Promise<void> {
|
|
187
|
+
if (!sets.length) return;
|
|
188
|
+
const profiles = new Set(sets.map(s => s.profile));
|
|
189
|
+
const existing = await listAll(client, `${ownerPath(owner)}/placements?limit=200`);
|
|
190
|
+
for (const p of existing) {
|
|
191
|
+
if (p.attributes?.placementType === 'APP_SCREENSHOT' && profiles.has(p.attributes.placementGroup)) {
|
|
192
|
+
await client.api(`/appAssetLibraryPlacements/${p.id}`, { method: 'DELETE' });
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
const link = { [owner.rel]: { data: { type: owner.type, id: owner.id } } };
|
|
196
|
+
for (const set of sets) {
|
|
197
|
+
const ids: string[] = [];
|
|
198
|
+
for (const file of set.files) {
|
|
199
|
+
const { data } = await client.api('/appAssetLibraryPlacements', { method: 'POST', body: JSON.stringify({ data: {
|
|
200
|
+
type: 'appAssetLibraryPlacements',
|
|
201
|
+
attributes: { placementType: 'APP_SCREENSHOT', placementGroup: set.profile },
|
|
202
|
+
relationships: { image: { data: uploaded.get(file)! }, ...link },
|
|
203
|
+
} }) });
|
|
204
|
+
ids.push(data.id);
|
|
205
|
+
}
|
|
206
|
+
if (ids.length > 1) {
|
|
207
|
+
await client.api('/appAssetLibraryPlacementOrderingRequests', { method: 'POST', body: JSON.stringify({ data: {
|
|
208
|
+
type: 'appAssetLibraryPlacementOrderingRequests',
|
|
209
|
+
attributes: { placementGroup: set.profile },
|
|
210
|
+
relationships: { orderedPlacements: { data: ids.map(id => ({ type: 'appAssetLibraryPlacements', id })) }, ...link },
|
|
211
|
+
} }) });
|
|
212
|
+
}
|
|
213
|
+
console.log(` [${owner.label}] ${set.profile} ← ${set.files.length} screenshot${set.files.length === 1 ? '' : 's'}`);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export interface PushedPage { id: string; name: string; url?: string; versionId: string; state: string }
|
|
218
|
+
|
|
219
|
+
export interface PushPagesOptions {
|
|
220
|
+
config: AppReleaseConfig;
|
|
221
|
+
localeMap?: Record<string, string>;
|
|
222
|
+
execute?: boolean;
|
|
223
|
+
/** Add every edited page version to a review submission and submit it. */
|
|
224
|
+
submit?: boolean;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export async function pushCustomProductPages({ config, localeMap, execute = false, submit = false }: PushPagesOptions): Promise<PushedPage[]> {
|
|
228
|
+
console.log(`App Store custom product pages ${execute ? '(EXECUTE)' : '(DRY RUN)'}`);
|
|
229
|
+
const plans = planPages(config, listingLocaleMap(config, 'apple', localeMap));
|
|
230
|
+
console.log(JSON.stringify(plans.map(p => ({ name: p.name, deepLink: p.deepLink, visible: p.visible,
|
|
231
|
+
locales: p.locales.map(l => ({ locale: l.locale, promotionalText: l.promotionalText, keywords: l.keywords.length ? l.keywords : undefined,
|
|
232
|
+
screenshots: l.screenshots.map(s => ({ profile: s.profile, files: s.files })) })) })), null, 2));
|
|
233
|
+
if (!execute) return [];
|
|
234
|
+
|
|
235
|
+
const client = createAscClient(config);
|
|
236
|
+
const app = await client.findApp();
|
|
237
|
+
const existing = await listAll(client, `/apps/${app.id}/appCustomProductPages?limit=200`);
|
|
238
|
+
|
|
239
|
+
// Keywords are checked against the app's live keywords before the first write.
|
|
240
|
+
const keywordLocales = new Set(plans.flatMap(p => p.locales.filter(l => l.keywords.length).map(l => l.locale)));
|
|
241
|
+
const available = new Map<string, Set<string>>();
|
|
242
|
+
for (const locale of keywordLocales) {
|
|
243
|
+
const rows = await listAll(client, `/apps/${app.id}/searchKeywords?filter[platform]=IOS&filter[locale]=${encodeURIComponent(locale)}&limit=200`);
|
|
244
|
+
available.set(locale, new Set(rows.map((k: any) => String(k.id))));
|
|
245
|
+
}
|
|
246
|
+
const missing = plans.flatMap(p => p.locales.flatMap(l => l.keywords.filter(k => !available.get(l.locale)?.has(k)).map(k => `${p.name} [${l.locale}]: "${k}"`)));
|
|
247
|
+
if (missing.length) throw new Error(`Not keywords of the live App Store version, so a page cannot take them:\n ${missing.join('\n ')}`);
|
|
248
|
+
|
|
249
|
+
// 1. Find or create each page, and the version that takes the edits.
|
|
250
|
+
const targets: { plan: PagePlan; page: any; live: boolean; versionId: string; state: string; localizations: Map<string, any> }[] = [];
|
|
251
|
+
for (const plan of plans) {
|
|
252
|
+
let page = existing.find((p: any) => p.attributes?.name === plan.name);
|
|
253
|
+
let version: any;
|
|
254
|
+
if (!page) {
|
|
255
|
+
const vRef = '${new-version}';
|
|
256
|
+
const included: any[] = [{ type: 'appCustomProductPageVersions', id: vRef, relationships: { appCustomProductPageLocalizations: {
|
|
257
|
+
data: plan.locales.map((_, i) => ({ type: 'appCustomProductPageLocalizations', id: `\${new-localization-${i}}` })) } } }];
|
|
258
|
+
plan.locales.forEach((l, i) => included.push({ type: 'appCustomProductPageLocalizations', id: `\${new-localization-${i}}`,
|
|
259
|
+
attributes: { locale: l.locale, ...(l.promotionalText ? { promotionalText: l.promotionalText } : {}) } }));
|
|
260
|
+
const created = await client.api('/appCustomProductPages', { method: 'POST', body: JSON.stringify({
|
|
261
|
+
data: { type: 'appCustomProductPages', attributes: { name: plan.name }, relationships: {
|
|
262
|
+
app: { data: { type: 'apps', id: app.id } },
|
|
263
|
+
appCustomProductPageVersions: { data: [{ type: 'appCustomProductPageVersions', id: vRef }] },
|
|
264
|
+
} },
|
|
265
|
+
included,
|
|
266
|
+
}) });
|
|
267
|
+
page = created.data;
|
|
268
|
+
console.log(`\n${plan.name}: created`);
|
|
269
|
+
} else {
|
|
270
|
+
console.log(`\n${plan.name}: found (${page.id})`);
|
|
271
|
+
}
|
|
272
|
+
const versions = await listAll(client, `/appCustomProductPages/${page.id}/appCustomProductPageVersions?limit=50`);
|
|
273
|
+
version = versions.find((v: any) => EDITABLE_PAGE_STATES.has(v.attributes?.state));
|
|
274
|
+
if (!version) {
|
|
275
|
+
const locked = versions.find((v: any) => ['READY_FOR_REVIEW', 'WAITING_FOR_REVIEW', 'IN_REVIEW'].includes(v.attributes?.state));
|
|
276
|
+
if (locked) throw new Error(`${plan.name}: version ${locked.attributes.version ?? locked.id} is ${locked.attributes.state} and cannot change until it is reviewed or withdrawn.`);
|
|
277
|
+
// An approved page changes through a new version; its URL stays the same.
|
|
278
|
+
const created = await client.api('/appCustomProductPageVersions', { method: 'POST', body: JSON.stringify({ data: {
|
|
279
|
+
type: 'appCustomProductPageVersions',
|
|
280
|
+
relationships: { appCustomProductPage: { data: { type: 'appCustomProductPages', id: page.id } } },
|
|
281
|
+
} }) });
|
|
282
|
+
version = created.data;
|
|
283
|
+
console.log(` new version ${version.id}; the live page stays as it is until this one is approved`);
|
|
284
|
+
}
|
|
285
|
+
const locs = await listAll(client, `/appCustomProductPageVersions/${version.id}/appCustomProductPageLocalizations?limit=200`);
|
|
286
|
+
targets.push({ plan, page, live: versions.some((v: any) => v.attributes?.state === 'APPROVED'), versionId: version.id, state: version.attributes?.state ?? 'PREPARE_FOR_SUBMISSION',
|
|
287
|
+
localizations: new Map(locs.map((l: any) => [l.attributes.locale, l])) });
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// 2. Copy, deep link, visibility and localizations.
|
|
291
|
+
for (const t of targets) {
|
|
292
|
+
if (t.plan.deepLink !== undefined) {
|
|
293
|
+
await client.api(`/appCustomProductPageVersions/${t.versionId}`, { method: 'PATCH', body: JSON.stringify({ data: {
|
|
294
|
+
type: 'appCustomProductPageVersions', id: t.versionId, attributes: { deepLink: t.plan.deepLink } } }) });
|
|
295
|
+
}
|
|
296
|
+
// Visibility is a switch on a live page; a page App Review has not approved yet has nothing to show or hide.
|
|
297
|
+
if (t.live && t.page.attributes?.visible !== t.plan.visible) {
|
|
298
|
+
await client.api(`/appCustomProductPages/${t.page.id}`, { method: 'PATCH', body: JSON.stringify({ data: {
|
|
299
|
+
type: 'appCustomProductPages', id: t.page.id, attributes: { visible: t.plan.visible } } }) });
|
|
300
|
+
}
|
|
301
|
+
for (const l of t.plan.locales) {
|
|
302
|
+
let loc = t.localizations.get(l.locale);
|
|
303
|
+
if (!loc) {
|
|
304
|
+
const created = await client.api('/appCustomProductPageLocalizations', { method: 'POST', body: JSON.stringify({ data: {
|
|
305
|
+
type: 'appCustomProductPageLocalizations',
|
|
306
|
+
attributes: { locale: l.locale, ...(l.promotionalText ? { promotionalText: l.promotionalText } : {}) },
|
|
307
|
+
relationships: { appCustomProductPageVersion: { data: { type: 'appCustomProductPageVersions', id: t.versionId } } },
|
|
308
|
+
} }) });
|
|
309
|
+
loc = created.data;
|
|
310
|
+
t.localizations.set(l.locale, loc);
|
|
311
|
+
} else if (l.promotionalText !== undefined && loc.attributes?.promotionalText !== l.promotionalText) {
|
|
312
|
+
await client.api(`/appCustomProductPageLocalizations/${loc.id}`, { method: 'PATCH', body: JSON.stringify({ data: {
|
|
313
|
+
type: 'appCustomProductPageLocalizations', id: loc.id, attributes: { promotionalText: l.promotionalText } } }) });
|
|
314
|
+
}
|
|
315
|
+
if (t.plan.manageKeywords) {
|
|
316
|
+
const current = await listAll(client, `/appCustomProductPageLocalizations/${loc.id}/relationships/searchKeywords?limit=200`);
|
|
317
|
+
const have = new Set(current.map((k: any) => String(k.id)));
|
|
318
|
+
const add = l.keywords.filter(k => !have.has(k));
|
|
319
|
+
const drop = [...have].filter(k => !l.keywords.includes(k));
|
|
320
|
+
const body = (ids: string[]) => JSON.stringify({ data: ids.map(id => ({ type: 'appKeywords', id })) });
|
|
321
|
+
if (add.length) await client.api(`/appCustomProductPageLocalizations/${loc.id}/relationships/searchKeywords`, { method: 'POST', body: body(add) });
|
|
322
|
+
if (drop.length) await client.api(`/appCustomProductPageLocalizations/${loc.id}/relationships/searchKeywords`, { method: 'DELETE', body: body(drop) });
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// 3. Screenshots: upload everything first, then replace placements.
|
|
328
|
+
const uploaded = await uploadAll(client, app.id, plans.flatMap(p => p.locales.flatMap(l => l.screenshots.flatMap(s => s.files))));
|
|
329
|
+
for (const t of targets) {
|
|
330
|
+
for (const l of t.plan.locales) {
|
|
331
|
+
const loc = t.localizations.get(l.locale)!;
|
|
332
|
+
await placeScreenshots(client, { rel: 'appCustomProductPageLocalization', type: 'appCustomProductPageLocalizations', id: loc.id,
|
|
333
|
+
label: `${t.plan.name} ${l.locale}` }, l.screenshots, uploaded);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// 4. URLs, the thing to link and tag with.
|
|
338
|
+
const pushed: PushedPage[] = [];
|
|
339
|
+
for (const t of targets) {
|
|
340
|
+
const { data } = await client.api(`/appCustomProductPages/${t.page.id}`);
|
|
341
|
+
pushed.push({ id: t.page.id, name: t.plan.name, url: data?.attributes?.url, versionId: t.versionId, state: t.state });
|
|
342
|
+
}
|
|
343
|
+
console.log('\nPage URLs (each carries ?ppid=<page id>; send traffic here to show the page):');
|
|
344
|
+
for (const p of pushed) console.log(` ${p.name}: ${p.url ?? '(App Store Connect returns the URL once the page exists)'}`);
|
|
345
|
+
|
|
346
|
+
if (submit) {
|
|
347
|
+
console.log('\n→ App Review');
|
|
348
|
+
const result = await addToReview(client, app.id, pushed.map(p => ({ rel: 'appCustomProductPageVersion', type: 'appCustomProductPageVersions', id: p.versionId, label: p.name })));
|
|
349
|
+
for (const p of pushed) p.state = result === 'submitted' ? 'WAITING_FOR_REVIEW' : p.state;
|
|
350
|
+
} else {
|
|
351
|
+
console.log('\nNot submitted. A page goes live after App Review: run again with --submit, or submit it in App Store Connect.');
|
|
352
|
+
}
|
|
353
|
+
return pushed;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
export interface TestStatus {
|
|
357
|
+
id: string;
|
|
358
|
+
name: string;
|
|
359
|
+
state: string;
|
|
360
|
+
trafficProportion?: number;
|
|
361
|
+
reviewRequired?: boolean;
|
|
362
|
+
startDate?: string;
|
|
363
|
+
endDate?: string;
|
|
364
|
+
treatments: { id: string; name: string }[];
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/** The configured test by name, preferring one that is not finished. */
|
|
368
|
+
export async function findTest(client: AscClient, appId: string, name: string): Promise<any | undefined> {
|
|
369
|
+
const tests = await listAll(client, `/apps/${appId}/appStoreVersionExperimentsV2?limit=50`);
|
|
370
|
+
const named = tests.filter((t: any) => t.attributes?.name === name);
|
|
371
|
+
return named.find((t: any) => !FINISHED_TEST_STATES.has(t.attributes?.state)) ?? named[0];
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
export async function testStatus(client: AscClient, test: any): Promise<TestStatus> {
|
|
375
|
+
const treatments = await listAll(client, `/v2/appStoreVersionExperiments/${test.id}/appStoreVersionExperimentTreatments?limit=10`);
|
|
376
|
+
const a = test.attributes ?? {};
|
|
377
|
+
return { id: test.id, name: a.name, state: a.state, trafficProportion: a.trafficProportion, reviewRequired: a.reviewRequired,
|
|
378
|
+
startDate: a.startDate ?? undefined, endDate: a.endDate ?? undefined,
|
|
379
|
+
treatments: treatments.map((t: any) => ({ id: t.id, name: t.attributes?.name })) };
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
export interface PushTestOptions {
|
|
383
|
+
config: AppReleaseConfig;
|
|
384
|
+
localeMap?: Record<string, string>;
|
|
385
|
+
execute?: boolean;
|
|
386
|
+
/** Start the test, and send it to App Review when its treatments need it. */
|
|
387
|
+
start?: boolean;
|
|
388
|
+
/** Stop a running test. A stopped test cannot restart. */
|
|
389
|
+
stop?: boolean;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
export async function pushProductPageTest({ config, localeMap, execute = false, start = false, stop = false }: PushTestOptions): Promise<TestStatus | undefined> {
|
|
393
|
+
if (start && stop) throw new Error('--start and --stop conflict.');
|
|
394
|
+
if (stop) {
|
|
395
|
+
const name = config.ascProductPageTest?.name;
|
|
396
|
+
if (!name) throw new Error('release.config.ts needs `ascProductPageTest.name` to find the test to stop.');
|
|
397
|
+
console.log(`Stop product page test "${name}" ${execute ? '(EXECUTE)' : '(DRY RUN)'}. A stopped test cannot restart.`);
|
|
398
|
+
if (!execute) return undefined;
|
|
399
|
+
const client = createAscClient(config);
|
|
400
|
+
const app = await client.findApp();
|
|
401
|
+
const test = await findTest(client, app.id, name);
|
|
402
|
+
if (!test) throw new Error(`No product page test named "${name}".`);
|
|
403
|
+
await client.api(`/v2/appStoreVersionExperiments/${test.id}`, { method: 'PATCH', body: JSON.stringify({ data: {
|
|
404
|
+
type: 'appStoreVersionExperiments', id: test.id, attributes: { started: false } } }) });
|
|
405
|
+
const { data } = await client.api(`/v2/appStoreVersionExperiments/${test.id}`);
|
|
406
|
+
const status = await testStatus(client, data);
|
|
407
|
+
console.log(` ${status.name}: ${status.state}`);
|
|
408
|
+
return status;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
console.log(`App Store product page test ${execute ? '(EXECUTE)' : '(DRY RUN)'}`);
|
|
412
|
+
const plan = planTest(config, listingLocaleMap(config, 'apple', localeMap));
|
|
413
|
+
console.log(JSON.stringify({ name: plan.name, trafficProportion: plan.trafficProportion, treatments: plan.treatments.map(t => ({
|
|
414
|
+
name: t.name, appIconName: t.appIconName, locales: t.locales.map(l => ({ locale: l.locale, screenshots: l.screenshots })) })) }, null, 2));
|
|
415
|
+
console.log(`${plan.trafficProportion}% of the default page's visitors see a treatment, split evenly; the rest see the original.`);
|
|
416
|
+
if (plan.treatments.some(t => t.appIconName)) console.log('An alternate icon must be in the live binary, or App Store Connect refuses the treatment.');
|
|
417
|
+
if (!execute) return undefined;
|
|
418
|
+
|
|
419
|
+
const client = createAscClient(config);
|
|
420
|
+
const app = await client.findApp();
|
|
421
|
+
let test = await findTest(client, app.id, plan.name);
|
|
422
|
+
if (test && FINISHED_TEST_STATES.has(test.attributes?.state)) {
|
|
423
|
+
throw new Error(`"${plan.name}" already ran (${test.attributes.state}). A finished test cannot restart; give the next one a new name.`);
|
|
424
|
+
}
|
|
425
|
+
if (!test) {
|
|
426
|
+
const created = await client.api('/v2/appStoreVersionExperiments', { method: 'POST', body: JSON.stringify({ data: {
|
|
427
|
+
type: 'appStoreVersionExperiments',
|
|
428
|
+
attributes: { name: plan.name, platform: 'IOS', trafficProportion: plan.trafficProportion },
|
|
429
|
+
relationships: { app: { data: { type: 'apps', id: app.id } } },
|
|
430
|
+
} }) });
|
|
431
|
+
test = created.data;
|
|
432
|
+
console.log(`\n${plan.name}: created (${test.id})`);
|
|
433
|
+
} else {
|
|
434
|
+
console.log(`\n${plan.name}: found (${test.id}, ${test.attributes?.state})`);
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
const editable = EDITABLE_TEST_STATES.has(test.attributes?.state ?? 'PREPARE_FOR_SUBMISSION');
|
|
438
|
+
if (editable) {
|
|
439
|
+
if (test.attributes?.trafficProportion !== undefined && test.attributes.trafficProportion !== plan.trafficProportion) {
|
|
440
|
+
await client.api(`/v2/appStoreVersionExperiments/${test.id}`, { method: 'PATCH', body: JSON.stringify({ data: {
|
|
441
|
+
type: 'appStoreVersionExperiments', id: test.id, attributes: { trafficProportion: plan.trafficProportion } } }) });
|
|
442
|
+
}
|
|
443
|
+
const current = await listAll(client, `/v2/appStoreVersionExperiments/${test.id}/appStoreVersionExperimentTreatments?limit=10`);
|
|
444
|
+
for (const t of current) {
|
|
445
|
+
if (!plan.treatments.some(p => p.name === t.attributes?.name)) {
|
|
446
|
+
await client.api(`/appStoreVersionExperimentTreatments/${t.id}`, { method: 'DELETE' });
|
|
447
|
+
console.log(` removed treatment "${t.attributes?.name}"`);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
const owners: { owner: Owner; sets: ScreenshotSet[] }[] = [];
|
|
451
|
+
for (const p of plan.treatments) {
|
|
452
|
+
let treatment = current.find((t: any) => t.attributes?.name === p.name);
|
|
453
|
+
if (!treatment) {
|
|
454
|
+
const created = await client.api('/appStoreVersionExperimentTreatments', { method: 'POST', body: JSON.stringify({ data: {
|
|
455
|
+
type: 'appStoreVersionExperimentTreatments',
|
|
456
|
+
attributes: { name: p.name, ...(p.appIconName ? { appIconName: p.appIconName } : {}) },
|
|
457
|
+
relationships: { appStoreVersionExperimentV2: { data: { type: 'appStoreVersionExperiments', id: test.id } } },
|
|
458
|
+
} }) });
|
|
459
|
+
treatment = created.data;
|
|
460
|
+
console.log(` treatment "${p.name}" created`);
|
|
461
|
+
} else if ((treatment.attributes?.appIconName ?? undefined) !== p.appIconName && p.appIconName !== undefined) {
|
|
462
|
+
await client.api(`/appStoreVersionExperimentTreatments/${treatment.id}`, { method: 'PATCH', body: JSON.stringify({ data: {
|
|
463
|
+
type: 'appStoreVersionExperimentTreatments', id: treatment.id, attributes: { appIconName: p.appIconName } } }) });
|
|
464
|
+
}
|
|
465
|
+
const locs = await listAll(client, `/appStoreVersionExperimentTreatments/${treatment.id}/appStoreVersionExperimentTreatmentLocalizations?limit=200`);
|
|
466
|
+
const byLocale = new Map(locs.map((l: any) => [l.attributes?.locale, l]));
|
|
467
|
+
for (const l of p.locales) {
|
|
468
|
+
let loc = byLocale.get(l.locale);
|
|
469
|
+
if (!loc) {
|
|
470
|
+
const created = await client.api('/appStoreVersionExperimentTreatmentLocalizations', { method: 'POST', body: JSON.stringify({ data: {
|
|
471
|
+
type: 'appStoreVersionExperimentTreatmentLocalizations',
|
|
472
|
+
attributes: { locale: l.locale },
|
|
473
|
+
relationships: { appStoreVersionExperimentTreatment: { data: { type: 'appStoreVersionExperimentTreatments', id: treatment.id } } },
|
|
474
|
+
} }) });
|
|
475
|
+
loc = created.data;
|
|
476
|
+
}
|
|
477
|
+
owners.push({ owner: { rel: 'appStoreVersionExperimentTreatmentLocalization', type: 'appStoreVersionExperimentTreatmentLocalizations',
|
|
478
|
+
id: loc.id, label: `${p.name} ${l.locale}` }, sets: l.screenshots });
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
const uploaded = await uploadAll(client, app.id, owners.flatMap(o => o.sets.flatMap(s => s.files)));
|
|
482
|
+
for (const o of owners) await placeScreenshots(client, o.owner, o.sets, uploaded);
|
|
483
|
+
} else {
|
|
484
|
+
console.log(` ${test.attributes?.state}: treatments are locked; nothing changed`);
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
if (start) {
|
|
488
|
+
console.log('\n→ Starting');
|
|
489
|
+
await client.api(`/v2/appStoreVersionExperiments/${test.id}`, { method: 'PATCH', body: JSON.stringify({ data: {
|
|
490
|
+
type: 'appStoreVersionExperiments', id: test.id, attributes: { started: true } } }) });
|
|
491
|
+
const { data } = await client.api(`/v2/appStoreVersionExperiments/${test.id}`);
|
|
492
|
+
test = data;
|
|
493
|
+
if (test.attributes?.reviewRequired) {
|
|
494
|
+
const item: ReviewItem = { rel: 'appStoreVersionExperimentV2', type: 'appStoreVersionExperiments', id: test.id, label: plan.name };
|
|
495
|
+
await addToReview(client, app.id, [item]);
|
|
496
|
+
console.log(' The test runs once App Review accepts its treatments.');
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
const status = await testStatus(client, test);
|
|
500
|
+
console.log(`\n${status.name}: ${status.state}${status.startDate ? `, started ${status.startDate}` : ''}`);
|
|
501
|
+
if (!start && editable) console.log('Not started. Run again with --start when the treatments look right.');
|
|
502
|
+
return status;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
/** The configured test's current status, or undefined when App Store Connect has none by that name. */
|
|
506
|
+
export async function readProductPageTest(config: AppReleaseConfig): Promise<TestStatus | undefined> {
|
|
507
|
+
const name = config.ascProductPageTest?.name;
|
|
508
|
+
if (!name) throw new Error('release.config.ts needs `ascProductPageTest.name`.');
|
|
509
|
+
const client = createAscClient(config);
|
|
510
|
+
const app = await client.findApp();
|
|
511
|
+
const test = await findTest(client, app.id, name);
|
|
512
|
+
return test ? testStatus(client, test) : undefined;
|
|
513
|
+
}
|
package/src/asc/submissions.ts
CHANGED
|
@@ -83,3 +83,67 @@ export async function cancelSubmission(
|
|
|
83
83
|
await sleep(15_000);
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
|
+
|
|
87
|
+
/** A page version or a test that goes to App Review through a review submission. */
|
|
88
|
+
export interface ReviewItem {
|
|
89
|
+
rel: 'appCustomProductPageVersion' | 'appStoreVersionExperimentV2';
|
|
90
|
+
/** The JSON:API type. A v2 experiment is still `appStoreVersionExperiments`. */
|
|
91
|
+
type: 'appCustomProductPageVersions' | 'appStoreVersionExperiments';
|
|
92
|
+
id: string;
|
|
93
|
+
label: string;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Put items on the app's draft review submission and submit it, without ever
|
|
98
|
+
* sending something else along. When the draft already holds other items (an
|
|
99
|
+
* app version being prepared, say), the items are added and the draft is left
|
|
100
|
+
* for whoever submits that, the same choice App Store Connect offers. A
|
|
101
|
+
* rejected submission is never cancelled from here: it may be someone's fix.
|
|
102
|
+
*/
|
|
103
|
+
export async function addToReview(client: AscClient, appId: string, items: ReviewItem[], submit = true): Promise<'submitted' | 'drafted'> {
|
|
104
|
+
const submissions = await listSubmissions(client, appId);
|
|
105
|
+
const rejected = submissions.find(s => s.state === REJECTED_SUBMISSION_STATE);
|
|
106
|
+
if (rejected) {
|
|
107
|
+
throw new Error(`A rejected review submission (${rejected.id}) holds the app's submission slot. Resolve it with asc-submit or in App Store Connect, then run this again.`);
|
|
108
|
+
}
|
|
109
|
+
let draft = submissions.find(s => OPEN_SUBMISSION_STATES.has(s.state));
|
|
110
|
+
let others = 0;
|
|
111
|
+
const present = new Set<string>();
|
|
112
|
+
if (draft) {
|
|
113
|
+
const res = await client.api(`/reviewSubmissions/${draft.id}/items?include=appStoreVersion,appCustomProductPageVersion,appStoreVersionExperimentV2&limit=50`);
|
|
114
|
+
for (const item of res.data ?? []) {
|
|
115
|
+
const linked = Object.values(item.relationships ?? {}).map((r: any) => r?.data?.id).filter(Boolean) as string[];
|
|
116
|
+
const ours = linked.filter(id => items.some(i => i.id === id));
|
|
117
|
+
ours.forEach(id => present.add(id));
|
|
118
|
+
if (!ours.length) others++;
|
|
119
|
+
}
|
|
120
|
+
console.log(` reusing draft review submission ${draft.id}${others ? ` (${others} other item${others === 1 ? '' : 's'})` : ''}`);
|
|
121
|
+
} else {
|
|
122
|
+
const created = await client.api('/reviewSubmissions', { method: 'POST', body: JSON.stringify({ data: {
|
|
123
|
+
type: 'reviewSubmissions', attributes: { platform: 'IOS' }, relationships: { app: { data: { type: 'apps', id: appId } } },
|
|
124
|
+
} }) });
|
|
125
|
+
draft = { id: created.data.id, state: created.data.attributes?.state ?? 'READY_FOR_REVIEW' };
|
|
126
|
+
console.log(` created review submission ${draft.id}`);
|
|
127
|
+
}
|
|
128
|
+
for (const item of items) {
|
|
129
|
+
if (present.has(item.id)) { console.log(` ${item.label}: already on the submission`); continue; }
|
|
130
|
+
await client.api('/reviewSubmissionItems', { method: 'POST', body: JSON.stringify({ data: {
|
|
131
|
+
type: 'reviewSubmissionItems',
|
|
132
|
+
relationships: {
|
|
133
|
+
reviewSubmission: { data: { type: 'reviewSubmissions', id: draft.id } },
|
|
134
|
+
[item.rel]: { data: { type: item.type, id: item.id } },
|
|
135
|
+
},
|
|
136
|
+
} }) });
|
|
137
|
+
console.log(` ${item.label}: added`);
|
|
138
|
+
}
|
|
139
|
+
if (others) {
|
|
140
|
+
console.log(' Not submitted: the draft holds other items. It goes to review when that submission is sent (asc-submit, ship, or App Store Connect).');
|
|
141
|
+
return 'drafted';
|
|
142
|
+
}
|
|
143
|
+
if (!submit) return 'drafted';
|
|
144
|
+
await client.api(`/reviewSubmissions/${draft.id}`, { method: 'PATCH', body: JSON.stringify({ data: {
|
|
145
|
+
type: 'reviewSubmissions', id: draft.id, attributes: { submitted: true },
|
|
146
|
+
} }) });
|
|
147
|
+
console.log(' submitted for review');
|
|
148
|
+
return 'submitted';
|
|
149
|
+
}
|
package/src/asc/submit.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/** Local build and store release support. All app settings come from the consuming configuration. */
|
|
2
2
|
import { listingLocaleMap } from '../config.ts';
|
|
3
3
|
import type { AppReleaseConfig } from '../config.ts';
|
|
4
|
+
import { ageRatingSubmissionError, ensureAgeRating } from './age-rating.ts';
|
|
4
5
|
import { createAscClient, type AscClient } from './client.ts';
|
|
5
6
|
import { pushAscMetadata } from './metadata.ts';
|
|
6
7
|
import { stage } from '../progress.ts';
|
|
@@ -152,6 +153,10 @@ export async function submitForReview(config: AppReleaseConfig, opts: SubmitOpti
|
|
|
152
153
|
// submits through the API.
|
|
153
154
|
await ensureReviewContact(client, versionId, config);
|
|
154
155
|
|
|
156
|
+
// 4e. Age rating. It lives on the app info, not the version, and Apple adds
|
|
157
|
+
// required questions between releases (`socialMedia`, October 2026).
|
|
158
|
+
await ensureAgeRating(client, app.id, config.ageRating);
|
|
159
|
+
|
|
155
160
|
if (opts.attachOnly) {
|
|
156
161
|
console.log('\n✓ Build attached + notes set. Stopped before submission (attach-only).');
|
|
157
162
|
return;
|
|
@@ -212,7 +217,7 @@ export async function submitForReview(config: AppReleaseConfig, opts: SubmitOpti
|
|
|
212
217
|
},
|
|
213
218
|
},
|
|
214
219
|
}),
|
|
215
|
-
});
|
|
220
|
+
}).catch((error: unknown) => { throw ageRatingSubmissionError(error) ?? error; });
|
|
216
221
|
console.log(' ✓ added version to submission');
|
|
217
222
|
}
|
|
218
223
|
|