Open in Google Play Console deep-links the app: Play developer id per credential profile (accounts play-developer, desktop Accounts), shared playAppUrl builder for desktop, CLI and watch; developer chooser instead of the console root

This commit is contained in:
CRTkafa 2026-10-23 09:20:35 +08:00
parent 7c769c18f4
commit 4a74989a95
33 changed files with 311 additions and 40 deletions

View file

@ -14,7 +14,7 @@ export type Kind = 'apple' | 'play';
/** The store keys that move to a profile (one developer account's), never the app's own ones. */
export const STORE_KEYS = PROFILE_KEYS;
export interface Identity { appleKeyId: string | null; playEmail: string | null; vendor: boolean }
export interface Identity { appleKeyId: string | null; playEmail: string | null; vendor: boolean; playDeveloperId: string | null }
const PEM = /BEGIN PRIVATE KEY/;
const isJsonText = (v: string) => /^\s*\{/.test(v);
@ -32,15 +32,15 @@ export function serviceAccountEmail(v: string, base: string): string | null {
/** What a profile can reach: the Apple key id and the Play service account e-mail (for matching, never printed). */
export function profileIdentity(name: string): Identity {
const env = profileEnv(name);
return { appleKeyId: env.ASC_KEY_ID ?? null, playEmail: env.PLAY_SERVICE_ACCOUNT ? serviceAccountEmail(env.PLAY_SERVICE_ACCOUNT, profileDir()) : null, vendor: !!env.ASC_VENDOR_NUMBER };
return { appleKeyId: env.ASC_KEY_ID ?? null, playEmail: env.PLAY_SERVICE_ACCOUNT ? serviceAccountEmail(env.PLAY_SERVICE_ACCOUNT, profileDir()) : null, vendor: !!env.ASC_VENDOR_NUMBER, playDeveloperId: env.PLAY_DEVELOPER_ID ?? null };
}
/** One line per profile for `storebound accounts`: stores, masked Play e-mail. No key ids, no values. */
export function describeProfiles(): { profile: string; apple: boolean; play: boolean; playAccount: string | null; vendor: boolean; error?: string }[] {
export function describeProfiles(): { profile: string; apple: boolean; play: boolean; playAccount: string | null; vendor: boolean; playDeveloperId?: string | null; error?: string }[] {
return profileNames().map(profile => {
try {
const id = profileIdentity(profile);
return { profile, apple: !!id.appleKeyId, play: !!id.playEmail, playAccount: id.playEmail ? maskUser(id.playEmail) : null, vendor: id.vendor };
return { profile, apple: !!id.appleKeyId, play: !!id.playEmail, playAccount: id.playEmail ? maskUser(id.playEmail) : null, vendor: id.vendor, playDeveloperId: id.playDeveloperId };
} catch (e) { return { profile, apple: false, play: false, playAccount: null, vendor: false, error: (e as Error).message }; }
});
}
@ -205,3 +205,18 @@ export function useProfile(project: string, name: string): string {
atomic(file, JSON.stringify({ ...cur, account: name }, null, 2) + '\n', 0o600);
return file;
}
/** Sets (or clears with null) the Play developer account id of a profile: an account id, not a secret, used for Play
* Console deep links (play-ids.ts). The same field the desktop's Accounts screen writes. Returns the profile file. */
export function setPlayDeveloperId(name: string, id: string | null): string {
if (!PROFILE_RE.test(name)) throw new Error(`${name}: letters, digits, . _ - (max 64)`);
if (!profileNames().includes(name)) throw new Error(`no profile "${name}" in ${profileDir()}: \`storebound accounts\` lists them`);
const v = id?.trim() ?? null;
if (v !== null && !/^\d{1,25}$/.test(v)) throw new Error('the Play developer id is the digits in play.google.com/console/u/0/developers/<id>/...');
const file = join(profileDir(), `${name}.json`);
const cur = readJson(file);
const next: Json = { ...cur };
if (v === null) delete next.PLAY_DEVELOPER_ID; else next.PLAY_DEVELOPER_ID = v;
atomic(file, JSON.stringify(next, null, 2) + '\n', 0o600);
return file;
}

View file

@ -6,6 +6,7 @@ import { existsSync } from 'node:fs';
import { dirname, isAbsolute, join, resolve } from 'node:path';
import * as rt from './rt';
import { PROFILE_RE, setConfigAccount } from './credentials';
import { playIdsOf } from './play-ids';
import { validateCapture, validateRecord } from '../shots/devices';
import { featureBackgroundIssues, paletteIssues } from '../shots/palette';
import { type AppleDataTypeId, type AppleTypeAnswer, validateAppPrivacyTypes } from './app-privacy';
@ -1286,7 +1287,8 @@ export async function loadConfig(explicit?: string, start = process.cwd()): Prom
if (errors.length) throw new Error(`${path}:\n ` + errors.join('\n '));
const root = dirname(path);
setConfigAccount(root, config.account);
setConsoleIds(consoleIdsFromConfig(config));
const play = playIdsOf(config, root);
setConsoleIds({ ...consoleIdsFromConfig(config), playDeveloperId: play.developerId, playAppId: play.appId });
return { config, root, path, resolve: (p: string) => (isAbsolute(p) ? p : join(root, p)) };
}

View file

@ -9,6 +9,8 @@
export const ASC = 'https://appstoreconnect.apple.com';
export const PLAY_CONSOLE = 'https://play.google.com/console';
/** The developer account chooser: the fallback when no developer id is known (never the bare console root). */
export const PLAY_DEVELOPERS = `${PLAY_CONSOLE}/u/0/developers`;
export interface ConsoleIds { appleAppId?: string | null; playDeveloperId?: string | null; playAppId?: string | null }
@ -94,7 +96,7 @@ export function consoleUrl(page: ConsolePage, ids: ConsoleIds = current): string
return app ? `${ASC}/apps/${app}${p.path}` : `${ASC}/apps`;
}
const dev = id(ids.playDeveloperId ?? current.playDeveloperId), app = id(ids.playAppId ?? current.playAppId);
if (!dev) return PLAY_CONSOLE;
if (!dev) return PLAY_DEVELOPERS;
const base = `${PLAY_CONSOLE}/u/0/developers/${dev}`;
if (p.scope === 'developer') return `${base}/${p.path}`;
return app ? `${base}/app/${app}/${p.path}` : `${base}/app-list`;
@ -103,7 +105,22 @@ export function consoleUrl(page: ConsolePage, ids: ConsoleIds = current): string
/** True when the URL is the page itself (ids known), false when it is a fallback (app list, chooser). */
export function consoleUrlExact(page: ConsolePage, ids: ConsoleIds = current): boolean {
const u = consoleUrl(page, ids);
return u !== PLAY_CONSOLE && !(CONSOLE_PAGES[page].scope === 'app' && (u === `${ASC}/apps` || u.endsWith('/app-list')));
return u !== PLAY_DEVELOPERS && !(CONSOLE_PAGES[page].scope === 'app' && (u === `${ASC}/apps` || u.endsWith('/app-list')));
}
/**
* "Open in Google Play Console" for one app: its dashboard when the developer id and the console's app id are known,
* else that developer's app list (searchable, the package name finds the row), else the developer chooser. Every
* desktop / CLI / watch link to an app's Play page goes through here.
*/
export function playAppUrl(ids: { developerId?: string | null; appId?: string | null }): string {
return consoleUrl('play.dashboard', { playDeveloperId: ids.developerId ?? null, playAppId: ids.appId ?? null, appleAppId: null });
}
/** The first candidate that is a console id (digits); the order of the sources is in play-ids.ts. */
export function pickConsoleId(...candidates: (string | null | undefined)[]): string | null {
for (const c of candidates) if (c && /^\d{1,25}$/.test(c.trim())) return c.trim();
return null;
}
/** "Readable > path: https://..." (the path suffix, e.g. "> Copy Cloud Storage URI", is appended to the label). */

View file

@ -44,7 +44,7 @@ function fileStore(root: string): Store {
export function credentialValue(root: string, name: string): string | undefined { return value(root, name); }
/** The store credential names a profile holds (the same as the env names): per developer account, so the vendor number
* for reports too; an app's Android upload keystore stays in the project. */
export const PROFILE_KEYS = ['PLAY_SERVICE_ACCOUNT', 'ASC_KEY_ID', 'ASC_ISSUER_ID', 'ASC_P8', 'ASC_VENDOR_NUMBER'] as const;
export const PROFILE_KEYS = ['PLAY_SERVICE_ACCOUNT', 'ASC_KEY_ID', 'ASC_ISSUER_ID', 'ASC_P8', 'ASC_VENDOR_NUMBER', 'PLAY_DEVELOPER_ID'] as const;
export const PROFILE_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
export const profileDir = (): string => process.env.STOREBOUND_CREDENTIALS_DIR || join(homedir(), '.storebound', 'credentials');

View file

@ -122,7 +122,8 @@ export interface ProjectSummary {
config: string;
name: string;
languages: string[];
play: { packageName: string } | null;
/** developerId / appId: the Play Console ids for deep links (play-ids.ts), null when unknown. */
play: { packageName: string; developerId?: string | null; appId?: string | null } | null;
apple: { bundleId: string; appId: string | null } | null;
/** app.platforms (default: from the apple / play sections). */
platforms: ('ios' | 'android')[];
@ -155,7 +156,7 @@ export interface ProjectSummary {
export interface AppIdentity {
id: string;
name: string;
platforms: { ios: { bundleId: string; ascAppId: string | null } | null; android: { packageName: string } | null };
platforms: { ios: { bundleId: string; ascAppId: string | null } | null; android: { packageName: string; developerId?: string | null; appId?: string | null } | null };
}
/** Where a version is on one store. */

43
cli/lib/play-ids.ts Normal file
View file

@ -0,0 +1,43 @@
// The Play Console ids an app's links use, from every place this machine keeps them (first one wins):
// developer id: play.developerId (config) > STOREBOUND_PLAY_DEVELOPER_ID (a workspace account, `ws`) >
// PLAY_DEVELOPER_ID of the credential profile (`storebound accounts play-developer`, the desktop's
// Accounts screen) > the id `console fill` remembered for the package (~/.storebound/console-accounts.json)
// app id: play.appId (config) > the remembered app id for the package
// Never a guess: an id that is not digits is skipped. The links themselves: console-links.ts (playAppUrl).
import { existsSync, readFileSync } from 'node:fs';
import { homedir } from 'node:os';
import { join } from 'node:path';
import { pickConsoleId } from './console-links';
import { credentialValue } from './credentials';
const consoleAccountsFile = (): string => process.env.STOREBOUND_CONSOLE_ACCOUNTS || join(homedir(), '.storebound', 'console-accounts.json');
/** What `console fill` remembered for a package ({ developerId, appId? }); {} when nothing or unreadable. */
export function rememberedPlay(pkg: string | null | undefined, file = consoleAccountsFile()): { developerId?: string; appId?: string } {
if (!pkg || !existsSync(file)) return {};
try {
const e = (JSON.parse(readFileSync(file, 'utf8')) as { play?: Record<string, { developerId?: unknown; appId?: unknown }> }).play?.[pkg];
return { developerId: typeof e?.developerId === 'string' ? e.developerId : undefined, appId: typeof e?.appId === 'string' ? e.appId : undefined };
} catch { return {}; }
}
export interface PlayIdSources {
config?: { developerId?: string | null; appId?: string | null; packageName?: string | null } | null;
workspace?: string | null;
profile?: string | null;
remembered?: { developerId?: string | null; appId?: string | null };
}
export function resolvePlayIds(s: PlayIdSources): { developerId: string | null; appId: string | null } {
return {
developerId: pickConsoleId(s.config?.developerId, s.workspace, s.profile, s.remembered?.developerId),
appId: pickConsoleId(s.config?.appId, s.remembered?.appId),
};
}
/** The ids for a loaded config (every source above). */
export function playIdsOf(config: { play?: { developerId?: string; appId?: string; packageName?: string } }, root: string): { developerId: string | null; appId: string | null } {
let profile: string | null = null;
try { profile = credentialValue(root, 'PLAY_DEVELOPER_ID') ?? null; } catch { /* unreadable profile: no id from it */ }
return resolvePlayIds({ config: config.play ?? null, workspace: process.env.STOREBOUND_PLAY_DEVELOPER_ID, profile, remembered: rememberedPlay(config.play?.packageName) });
}

View file

@ -11,7 +11,7 @@ export function appIdentity(s: ProjectSummary): AppIdentity {
name: s.name,
platforms: {
ios: s.apple && s.platforms.includes('ios') ? { bundleId: s.apple.bundleId, ascAppId: s.apple.appId } : null,
android: s.play && s.platforms.includes('android') ? { packageName: s.play.packageName } : null,
android: s.play && s.platforms.includes('android') ? { packageName: s.play.packageName, developerId: s.play.developerId ?? null, appId: s.play.appId ?? null } : null,
},
};
}