@sprid/release 0.1.1

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 ADDED
@@ -0,0 +1,10 @@
1
+ # Changelog
2
+
3
+ @sprid/release follows semver: a breaking change to a command's arguments, its
4
+ output shape or its exit codes is a major release.
5
+
6
+ ## 0.1.1 - 2026-09-22
7
+
8
+ - Install as `@sprid/cli`; the unscoped `sprid` name is refused by npm.
9
+ - Terms of Service in place of a licence text, so the rules live in one place
10
+ that can be updated.
package/LICENSE ADDED
@@ -0,0 +1,14 @@
1
+ Copyright (c) 2026 Väder AB. All rights reserved.
2
+
3
+ Use is subject to Sprid's Terms of Service at https://sprid.studio/terms,
4
+ which set out what you may do with these files.
5
+
6
+ Bundled third-party components keep their own licences, which are included
7
+ beside the files they cover.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
10
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
11
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
12
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
13
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
14
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,152 @@
1
+ # @sprid/release
2
+
3
+ The store listing as a file in your repo. Name, subtitle, keywords, description,
4
+ screenshots and Play graphics per locale live in `release.config.ts`, get reviewed
5
+ like code, and are pushed to App Store Connect and Google Play with one command.
6
+ Dry run by default.
7
+
8
+ Local builds, signing, binary uploads and review submission run through `ship`.
9
+ Use `build.framework: 'expo'` for Expo generation or `'native'` for an existing
10
+ native tree. Other toolchains supply argv-based build commands and artifact paths.
11
+ Listing commands and direct binary uploads need no Expo or native source tree.
12
+ Bun runs the CLI; the app can use any build system.
13
+
14
+ ```
15
+ sprid release metadata # dry run: prints every field it would send
16
+ sprid release metadata --execute # sends it
17
+ sprid release screenshots --asc # only App Store Connect
18
+ sprid release graphics --execute # Play feature graphic + icon
19
+ ```
20
+
21
+ Install the commands with `npm install -g @sprid/cli`; these local tools require Bun.
22
+ TS/JS configuration executes code, including during dry runs. Use trusted configs.
23
+
24
+ ## Config
25
+
26
+ Use `release.config.ts` at the repo root, or `--config <file>` for TS, JS, MJS or
27
+ plain JSON. Relative credential and asset paths resolve beside that file.
28
+ `--locale en-US,sv` selects exact store locale codes. Omit it to use the declared
29
+ map. Only configured stores run by default; `--asc` / `--play` selects one.
30
+ An iOS-only config can omit `play`, and a Play-only config can omit all Apple
31
+ fields. `listingLocales` alone is sufficient. `ascAppId` can replace `appId`.
32
+
33
+ ```sh
34
+ sprid release metadata --config ./store/listing.json --play --locale en-US
35
+ ```
36
+
37
+ ```ts
38
+ import { defineReleaseConfig } from "@sprid/release/config";
39
+
40
+ export default defineReleaseConfig({
41
+ appId: "app.example.ios", // independent iOS bundle id
42
+ asc: { keyId: "ABC123", issuer: "00000000-…", keyPath: "./.keys/AuthKey_ABC123.p8" },
43
+ play: { packageName: "app.example", keyPath: "./.keys/play-service-account.json" },
44
+ listingLocales: { apple: { "en-US": "en", "en-GB": "en", sv: "sv" }, play: { "en-US": "en", "sv-SE": "sv" } },
45
+ storeCopy: {
46
+ en: { name: "…", subtitle: "…", keywords: "…", description: "…", promotionalText: "…" },
47
+ sv: { name: "Example", description: "Localized app description" },
48
+ },
49
+ contact: { contactEmail: "support@example.com", contactWebsite: "https://example.com", defaultLanguage: "en-US" },
50
+ playGraphics: { icon: './store/icon-512.png', featureGraphic: './store/{lang}/feature-1024x500.png' },
51
+ });
52
+ ```
53
+
54
+ The Play icon is separate from the launcher icon inside the AAB. If `playGraphics.icon`
55
+ is omitted, execution verifies existing icons (including default-language fallback) before changing graphics.
56
+
57
+ ### Credentials
58
+
59
+ Never pasted into an agent conversation. Resolved in this order:
60
+
61
+ | Store | 1 | 2 |
62
+ |---|---|---|
63
+ | App Store Connect | `asc.keyPath` (+ `asc.keyId`, `asc.issuer`) | `$ASC_KEY_PATH`, `$ASC_KEY_ID`, `$ASC_ISSUER` |
64
+ | Google Play | `play.keyPath` | `$GOOGLE_SERVICE_ACCOUNT_KEY_PATH` |
65
+
66
+ A `credentialsDir` holding `ios/AuthKey_<id>_ASC_API.p8` and
67
+ `android/google-service-account.json` is also honoured, for teams that keep keys in
68
+ one mounted folder outside the repo.
69
+
70
+ ## Validation and execution
71
+
72
+ Dry runs validate selected local copy and assets, print the payload, and return
73
+ without credentials or store API calls. Remote permissions and editability are
74
+ checked only on `--execute`.
75
+
76
+ - Name 30, Apple subtitle 30, Apple keywords 100 characters. Keyword phrases may
77
+ contain spaces ([Apple guidance](https://developer.apple.com/app-store/product-page/)).
78
+ Only the selected store's fields and locales are validated.
79
+ - Locales are explicit. No localization is added automatically. To keep the old
80
+ English mirroring behavior, set `asc.englishUkFallback: true`; an explicit
81
+ `en-GB` map always wins. Existing configs already declaring `en-GB` need no change.
82
+ - Apple metadata requires editable app information/version records. The command
83
+ reports fields it cannot update. Screenshots replace the selected display type
84
+ and any explicitly deprecated types. Missing local replacement files fail
85
+ before deletion; a later upload failure can still leave a partial replacement.
86
+ - Play listing updates preserve omitted fields and never rewrite release tracks.
87
+ If Play rejects a draft app's edit, resolve its release state in your existing
88
+ publishing pipeline before retrying.
89
+
90
+ ### Credentials compatibility
91
+
92
+ `play.serviceAccountKeyPath` remains an alias for `play.keyPath`. Conflicting paths
93
+ are refused. ASC key id/issuer environment variables retain their existing
94
+ precedence over the config; explicit key file paths take precedence over env paths.
95
+
96
+ ## With Sprid
97
+
98
+ Add `--annotate` alongside `--execute` to record the change in Sprid using your
99
+ existing login or `SPRID_PAT`. Without `--annotate`, releases do not contact Sprid.
100
+ Annotations are best effort. Store publishing works independently of Sprid.
101
+
102
+ ## Library use
103
+
104
+ ```ts
105
+ import { pushAscMetadata, pushPlayMetadata, loadReleaseConfig } from "@sprid/release";
106
+ ```
107
+
108
+ Listing push functions take `{ config, execute }` and print their plan first.
109
+
110
+ ## Part of Sprid
111
+
112
+ This is one of the tools the free Sprid plugin drives (`/sprid:store-metadata`).
113
+ It works on its own. https://sprid.studio/agents
114
+
115
+ © 2026 Väder AB. All rights reserved. Use is subject to Sprid's [Terms of Service](https://sprid.studio/terms).
116
+
117
+ ## Build, upload and submit
118
+
119
+ ```sh
120
+ sprid release ship # local plan, no changes
121
+ sprid release ship --execute --patch # build, upload, submit
122
+ sprid release ship --execute --build-only # signed local artifacts
123
+ sprid release ship --execute --android-only --no-bump
124
+ sprid release asc-upload --ipa ./app.ipa --execute
125
+ sprid release play-upload --aab ./app.aab --version 1.2.3 --execute
126
+ sprid release asc-submit --version 1.2.3 --build 8 --execute
127
+ ```
128
+
129
+ `ship` needs `configFile` (version source), plus `build.appDir` and an explicit
130
+ `build.framework`. Native iOS signing also needs `appId`, `appleTeamId`,
131
+ `build.xcodeName` and signing credentials. Android can be configured alone.
132
+ The built-in version reader supports Expo JSON, plain JSON with `version`,
133
+ `ios.buildNumber`, `android.versionCode`, literal TS config, and split TS/JSON.
134
+
135
+ `build.credentialsJson` reads EAS-format signing files locally. Inner paths resolve
136
+ beside that file (`credentialsPathBase` overrides). `build.envFile: { path, keys }` loads an explicit
137
+ allowlist without printing values. `requiredProdEnv` rejects missing values and
138
+ local URLs. Gradle memory settings change only with `build.gradleJvmArgs`.
139
+
140
+ For another toolchain, `build.commands.ios` or `.android` replaces that platform's
141
+ native build and signing steps with `{ command: ['tool', 'arg'], artifact: 'path' }`.
142
+ Commands run in `appDir`; artifact paths resolve beside the release config. The
143
+ command must produce a correctly signed IPA or AAB. Direct upload commands bypass
144
+ all build/version assumptions.
145
+
146
+ `--submit-only` resumes an iOS build or uploads an existing AAB; `asc-upload` uploads an IPA. `--internal` targets internal testing.
147
+ If Google blocks a draft app, Sprid saves the uploaded bundle as a draft on the
148
+ requested track, finishes iOS, then exits with `PlayConsoleRequiredError`. Complete
149
+ the first release in Play Console. `finalizePlayRelease` can resume an upload edit.
150
+ Apple's first version skips the unavailable What's New field. Queued submissions
151
+ are replaced only with `--replace-submission`. Store copy needs `--push-store-copy`;
152
+ upload screenshots before submitting. Logs stay in `.sprid-release/logs/`.
package/SECURITY.md ADDED
@@ -0,0 +1,17 @@
1
+ # Security
2
+
3
+ Email hello@sprid.studio with `security` in the subject. Please do not open a
4
+ public issue for anything exploitable. Say what you did, what happened, and
5
+ the `@sprid/release` version. We reply within three working days. No bug
6
+ bounty.
7
+
8
+ **In scope:** anything that exposes a signing key or store credential (the App
9
+ Store Connect `.p8`, a Play service account, a value from the environment) in
10
+ output, a log, an error, or a request to anywhere but the store API it belongs
11
+ to. Also a path that sends a build or a metadata change to an app the config
12
+ did not name.
13
+
14
+ **Not a bug:** `release.config.ts` is executable code, run by the tool that
15
+ reads it. An untrusted repository runs its author's code.
16
+
17
+ Only the latest published version is patched.
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env node
2
+ // npm installs this bin under whatever runtime the person has, but the CLI it
3
+ // fronts is TypeScript run by Bun. Pointed straight at `cli.ts`, Node dies on
4
+ // the first type annotation with a syntax error, which reads as a broken
5
+ // package rather than a missing tool. This shim makes the requirement legible.
6
+ import { spawn } from "node:child_process";
7
+ import { fileURLToPath } from "node:url";
8
+
9
+ const entry = fileURLToPath(new URL("../src/cli.ts", import.meta.url));
10
+ const child = spawn("bun", [entry, ...process.argv.slice(2)], { stdio: "inherit" });
11
+ child.on("error", error => {
12
+ process.stderr.write(error.code === "ENOENT"
13
+ ? "\n ✗ Releases need Bun. Install it from https://bun.sh, then run the same command again.\n\n"
14
+ : `\n ✗ ${error.message}\n\n`);
15
+ process.exitCode = 1;
16
+ });
17
+ child.on("close", (code, signal) => {
18
+ if (signal) process.kill(process.pid, signal);
19
+ else process.exitCode = code ?? 1;
20
+ });
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@sprid/release",
3
+ "version": "0.1.1",
4
+ "description": "Build, sign and release mobile apps locally. Store copy, screenshots, binary uploads and review submissions from one app-owned configuration. Dry run by default.",
5
+ "license": "SEE LICENSE IN LICENSE",
6
+ "type": "module",
7
+ "homepage": "https://sprid.studio/agents",
8
+ "bugs": {
9
+ "email": "hello@sprid.studio"
10
+ },
11
+ "keywords": [
12
+ "aso",
13
+ "app-store-connect",
14
+ "google-play",
15
+ "metadata",
16
+ "keywords",
17
+ "screenshots",
18
+ "localization"
19
+ ],
20
+ "bin": {
21
+ "sprid-release": "./bin/release.mjs"
22
+ },
23
+ "exports": {
24
+ ".": {
25
+ "types": "./src/index.ts",
26
+ "import": "./src/index.ts"
27
+ },
28
+ "./config": {
29
+ "types": "./src/config.ts",
30
+ "import": "./src/config.ts"
31
+ },
32
+ "./copy": {
33
+ "types": "./src/copy.ts",
34
+ "import": "./src/copy.ts"
35
+ },
36
+ "./asc": {
37
+ "types": "./src/asc/index.ts",
38
+ "import": "./src/asc/index.ts"
39
+ },
40
+ "./play": {
41
+ "types": "./src/play/index.ts",
42
+ "import": "./src/play/index.ts"
43
+ },
44
+ "./cli": "./src/cli.ts"
45
+ },
46
+ "files": [
47
+ "src",
48
+ "README.md",
49
+ "LICENSE",
50
+ "bin",
51
+ "SECURITY.md",
52
+ "CHANGELOG.md"
53
+ ],
54
+ "engines": {
55
+ "node": ">=18",
56
+ "bun": ">=1.1"
57
+ },
58
+ "dependencies": {
59
+ "googleapis": "^171.4.0",
60
+ "jose": "^5.9.6"
61
+ },
62
+ "publishConfig": {
63
+ "access": "public"
64
+ }
65
+ }
@@ -0,0 +1,67 @@
1
+ // Release annotations. When a push actually happens (`--execute`), tell Sprid
2
+ // so the Monday mail can put "subtitle changed (Thu)" next to the week's store
3
+ // numbers. Best effort and silent: this package works without Sprid, and a
4
+ // failed annotation must never fail a metadata push that already landed.
5
+ //
6
+ // Credentials come from `sprid login` (~/.sprid/credentials.json) or SPRID_PAT +
7
+ // SPRID_URL, the same resolution the `sprid` CLI uses.
8
+
9
+ import { readFileSync } from 'node:fs';
10
+ import { homedir } from 'node:os';
11
+ import { join } from 'node:path';
12
+
13
+ interface Creds {
14
+ apiUrl: string;
15
+ token: string;
16
+ workspace?: { id: number } | null;
17
+ }
18
+
19
+ function loadCreds(): Creds | null {
20
+ const env = process.env.SPRID_PAT;
21
+ if (env) return { apiUrl: process.env.SPRID_URL ?? 'https://api.sprid.studio', token: env };
22
+ try {
23
+ const raw = JSON.parse(readFileSync(join(homedir(), '.sprid', 'credentials.json'), 'utf8'));
24
+ if (raw?.token && raw?.apiUrl) return raw as Creds;
25
+ } catch {
26
+ /* not logged in */
27
+ }
28
+ return null;
29
+ }
30
+
31
+ export async function annotate(input: {
32
+ kind: 'listing' | 'screenshots' | 'submission' | 'release';
33
+ label: string;
34
+ /** App Profile slug; the CLI's `.sprid/app.json` carries it. */
35
+ app?: string;
36
+ meta?: Record<string, unknown>;
37
+ }): Promise<boolean> {
38
+ const creds = loadCreds();
39
+ if (!creds) return false;
40
+ try {
41
+ const res = await fetch(`${creds.apiUrl.replace(/\/$/, '')}/api/events`, {
42
+ method: 'POST',
43
+ headers: { authorization: `Bearer ${creds.token}`, 'content-type': 'application/json' },
44
+ body: JSON.stringify({
45
+ workspaceId: creds.workspace?.id,
46
+ app: input.app,
47
+ kind: input.kind,
48
+ label: input.label,
49
+ meta: input.meta ?? {},
50
+ source: 'cli',
51
+ }),
52
+ });
53
+ return res.ok;
54
+ } catch {
55
+ return false;
56
+ }
57
+ }
58
+
59
+ /** The App Profile slug the plugin wrote for this repo, if any. */
60
+ export function appSlugFromRepo(cwd = process.cwd()): string | undefined {
61
+ try {
62
+ const raw = JSON.parse(readFileSync(join(cwd, '.sprid', 'app.json'), 'utf8'));
63
+ return typeof raw?.slug === 'string' ? raw.slug : undefined;
64
+ } catch {
65
+ return undefined;
66
+ }
67
+ }
@@ -0,0 +1,84 @@
1
+ /**
2
+ * App Store Connect API client. ES256 JWT signed with the `.p8` key, a thin
3
+ * `api()` fetch wrapper, and `findApp()` by bundle id. Config-driven.
4
+ */
5
+
6
+ import { SignJWT, importPKCS8 } from 'jose';
7
+ import { readFile } from 'node:fs/promises';
8
+ import type { AppReleaseConfig } from '../config.ts';
9
+ import { ascIssuer, ascKeyId, resolveAscKeyPath } from '../config.ts';
10
+
11
+ export const ASC_BASE = 'https://api.appstoreconnect.apple.com/v1';
12
+
13
+ export interface AscClient {
14
+ /** The app id this client targets (its bundle id). */
15
+ readonly bundleId: string;
16
+ api(path: string, init?: RequestInit): Promise<any>;
17
+ findApp(): Promise<{ id: string; name: string }>;
18
+ }
19
+
20
+ export function createAscClient(config: AppReleaseConfig): AscClient {
21
+ const keyId = ascKeyId(config);
22
+ const issuer = ascIssuer(config);
23
+ const keyPath = resolveAscKeyPath(config);
24
+ const bundleId = config.appId ?? '';
25
+ if (!bundleId && !config.ascAppId) throw new Error('Set appId (iOS bundle id) or ascAppId.');
26
+ if (!keyId || !issuer) throw new Error('Set asc.keyId and asc.issuer or ASC_KEY_ID and ASC_ISSUER.');
27
+
28
+ let cachedToken: string | undefined;
29
+ let refreshTokenAt = 0;
30
+
31
+ async function getToken(): Promise<string> {
32
+ if (cachedToken && Date.now() < refreshTokenAt) return cachedToken;
33
+ const pem = await readFile(keyPath, 'utf8');
34
+ const key = await importPKCS8(pem, 'ES256');
35
+ cachedToken = await new SignJWT({})
36
+ .setProtectedHeader({ alg: 'ES256', kid: keyId, typ: 'JWT' })
37
+ .setIssuer(issuer)
38
+ .setIssuedAt()
39
+ .setExpirationTime('20m')
40
+ .setAudience('appstoreconnect-v1')
41
+ .sign(key);
42
+ refreshTokenAt = Date.now() + 18 * 60_000;
43
+ return cachedToken;
44
+ }
45
+
46
+ async function api(path: string, init: RequestInit = {}): Promise<any> {
47
+ const method = init.method ?? 'GET';
48
+ // Reads and screenshot completion PATCHes are safe to repeat. Never retry
49
+ // resource creation or review submission automatically after an ambiguous 5xx.
50
+ const repeatable = method === 'GET' || (method === 'PATCH' && /^\/appScreenshots\/[^/]+$/.test(path));
51
+ for (let attempt = 0; ; attempt++) {
52
+ const res = await fetch(`${ASC_BASE}${path}`, {
53
+ ...init,
54
+ redirect: 'error',
55
+ signal: init.signal ?? AbortSignal.timeout(30000),
56
+ headers: { Authorization: `Bearer ${await getToken()}`, 'Content-Type': 'application/json', ...(init.headers || {}) },
57
+ });
58
+ if (res.ok) return res.status === 204 ? null : res.json();
59
+ const body = await res.text();
60
+ if (repeatable && attempt < 3 && [429, 500, 502, 503, 504].includes(res.status)) {
61
+ console.log(` ASC ${method} ${path}: ${res.status}, retrying (${attempt + 1}/3)`);
62
+ await new Promise(resolve => setTimeout(resolve, 1000 * 2 ** attempt));
63
+ continue;
64
+ }
65
+ throw new Error(`ASC ${method} ${path} → ${res.status}\n${body}`);
66
+ }
67
+ }
68
+
69
+ async function findApp(): Promise<{ id: string; name: string }> {
70
+ if (config.ascAppId) {
71
+ const { data: app } = await api(`/apps/${encodeURIComponent(config.ascAppId)}`);
72
+ if (bundleId && app.attributes.bundleId !== bundleId) throw new Error('ascAppId and appId refer to different apps.');
73
+ return { id: app.id, name: app.attributes.name };
74
+ }
75
+ const apps = await api(`/apps?filter[bundleId]=${encodeURIComponent(bundleId)}`);
76
+ if (!apps.data?.length) {
77
+ throw new Error(`No app found for bundleId=${bundleId}. Create it in App Store Connect first.`);
78
+ }
79
+ const app = apps.data[0];
80
+ return { id: app.id, name: app.attributes.name };
81
+ }
82
+
83
+ return { bundleId, api, findApp };
84
+ }
@@ -0,0 +1,8 @@
1
+ export { createAscClient, ASC_BASE } from './client.ts';
2
+ export type { AscClient } from './client.ts';
3
+ export { resolveVersion, EDITABLE_STATES, IN_FLIGHT_STATES } from './version.ts';
4
+ export { listSubmissions } from './submissions.ts';
5
+ export { pushAscMetadata } from './metadata.ts';
6
+ export type { PushAscMetadataOptions } from './metadata.ts';
7
+ export { pushAscScreenshots } from './screenshots.ts';
8
+ export type { PushAscScreenshotsOptions } from './screenshots.ts';
@@ -0,0 +1,120 @@
1
+ /**
2
+ * Push ASO text to App Store Connect: name/subtitle/privacy URL → appInfo
3
+ * localizations; description/keywords/promo/support+marketing URLs → the editable
4
+ * appStoreVersion's localizations. Config + copy driven. Does NOT push categories, screenshots, age rating, or
5
+ * the binary.
6
+ */
7
+
8
+ import { listingLocaleMap, type AppReleaseConfig } from '../config.ts';
9
+ import type { StoreCopy } from '../copy.ts';
10
+ import { selectedCopy } from '../copy.ts';
11
+ import { createAscClient } from './client.ts';
12
+ import { EDITABLE_STATES } from './version.ts';
13
+
14
+ export interface PushAscMetadataOptions {
15
+ config: AppReleaseConfig;
16
+ copy: Record<string, StoreCopy>;
17
+ /**
18
+ * ASC locale → copy-locale key. Defaults to `config.locales.apple`. Pass an
19
+ * explicit (e.g. en-only) map when listings ship fewer locales than the app
20
+ * itself — `config.locales` stays the full set for release notes.
21
+ */
22
+ localeMap?: Record<string, string>;
23
+ /** Actually push (default false = dry run). */
24
+ execute?: boolean;
25
+ }
26
+
27
+ export async function pushAscMetadata({ config, copy, localeMap, execute = false }: PushAscMetadataOptions): Promise<void> {
28
+ console.log(`App Store Connect metadata push ${execute ? '(EXECUTE)' : '(DRY RUN)'}`);
29
+ const locales = selectedCopy(copy, listingLocaleMap(config, 'apple', localeMap), 'apple');
30
+ const plan = locales.map(([locale, c]) => ({ locale,
31
+ appInfo: { name: c.name, subtitle: c.subtitle, privacyPolicyUrl: c.privacyPolicyUrl },
32
+ version: { description: c.description, keywords: c.keywords, promotionalText: c.promotionalText,
33
+ supportUrl: c.supportUrl, marketingUrl: c.marketingUrl },
34
+ }));
35
+ console.log(JSON.stringify({ store: 'apple', appId: config.appId, ascAppId: config.ascAppId, locales: plan }, null, 2));
36
+ if (!execute) return;
37
+ const client = createAscClient(config);
38
+
39
+ console.log(`\n→ Finding app with bundleId=${client.bundleId}`);
40
+ const app = await client.findApp();
41
+ console.log(` ✓ App: ${app.name} (id=${app.id})`);
42
+
43
+ // --- appInfo (name, subtitle, privacy URL) ---
44
+ console.log(`\n→ Fetching editable appInfo`);
45
+ const appInfos = await client.api(`/apps/${app.id}/appInfos`);
46
+ const editableAppInfo = appInfos.data.find((ai: any) => ai.attributes.state !== 'READY_FOR_DISTRIBUTION');
47
+ if (!editableAppInfo) {
48
+ console.log(' ⚠ No editable appInfo — skipping name/subtitle/privacy.');
49
+ } else {
50
+ console.log(` ✓ Editable appInfo id=${editableAppInfo.id} state=${editableAppInfo.attributes.state}`);
51
+ const locs = await client.api(`/appInfos/${editableAppInfo.id}/appInfoLocalizations`);
52
+ for (const [locale, c] of locales) {
53
+ const attrs = { name: c.name, subtitle: c.subtitle, privacyPolicyUrl: c.privacyPolicyUrl };
54
+ const existing = locs.data.find((l: any) => l.attributes.locale === locale);
55
+ console.log(` [${locale}] ${existing ? 'PATCH' : 'POST'} appInfoLocalizations`);
56
+ if (!execute) continue;
57
+ if (existing) {
58
+ await client.api(`/appInfoLocalizations/${existing.id}`, {
59
+ method: 'PATCH',
60
+ body: JSON.stringify({ data: { type: 'appInfoLocalizations', id: existing.id, attributes: attrs } }),
61
+ });
62
+ } else {
63
+ await client.api(`/appInfoLocalizations`, {
64
+ method: 'POST',
65
+ body: JSON.stringify({
66
+ data: {
67
+ type: 'appInfoLocalizations',
68
+ attributes: { locale, ...attrs },
69
+ relationships: { appInfo: { data: { type: 'appInfos', id: editableAppInfo.id } } },
70
+ },
71
+ }),
72
+ });
73
+ }
74
+ }
75
+ }
76
+
77
+ // --- appStoreVersion (description, keywords, promo, URLs) ---
78
+ console.log(`\n→ Fetching editable app store version`);
79
+ const versions = await client.api(`/apps/${app.id}/appStoreVersions?limit=5`);
80
+ const editableVersion = versions.data.find((v: any) =>
81
+ EDITABLE_STATES.has(v.attributes.appStoreState ?? v.attributes.appVersionState),
82
+ );
83
+ if (!editableVersion) {
84
+ console.log(' ⚠ No editable version — skipping description/keywords/promo. Create a version in ASC first.');
85
+ } else {
86
+ console.log(` ✓ Editable version: ${editableVersion.attributes.versionString} (id=${editableVersion.id})`);
87
+ const vLocs = await client.api(`/appStoreVersions/${editableVersion.id}/appStoreVersionLocalizations`);
88
+ for (const [locale, c] of locales) {
89
+ const attrs = {
90
+ description: c.description,
91
+ keywords: c.keywords,
92
+ promotionalText: c.promotionalText,
93
+ supportUrl: c.supportUrl,
94
+ marketingUrl: c.marketingUrl,
95
+ };
96
+ const existing = vLocs.data.find((l: any) => l.attributes.locale === locale);
97
+ console.log(` [${locale}] ${existing ? 'PATCH' : 'POST'} appStoreVersionLocalizations`);
98
+ if (!execute) continue;
99
+ if (existing) {
100
+ await client.api(`/appStoreVersionLocalizations/${existing.id}`, {
101
+ method: 'PATCH',
102
+ body: JSON.stringify({ data: { type: 'appStoreVersionLocalizations', id: existing.id, attributes: attrs } }),
103
+ });
104
+ } else {
105
+ await client.api(`/appStoreVersionLocalizations`, {
106
+ method: 'POST',
107
+ body: JSON.stringify({
108
+ data: {
109
+ type: 'appStoreVersionLocalizations',
110
+ attributes: { locale, ...attrs },
111
+ relationships: { appStoreVersion: { data: { type: 'appStoreVersions', id: editableVersion.id } } },
112
+ },
113
+ }),
114
+ });
115
+ }
116
+ }
117
+ }
118
+
119
+ console.log(`\n${execute ? '✓ Done' : '(dry run — pass execute:true to push)'}`);
120
+ }