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;
}