- storebound.workspace.json: app folders (globs), studios with accounts by credential profile, ignore list, the desktop's pairing overrides; ws init | list | status | check | validate | run | apps import | desktop export/import - credential profiles in ~/.storebound/credentials/<profile>.json or env, --account <profile> on any command - release status / release plan <version>, table or --json; MCP workspace_list, workspace_status, release_status, release_plan (read-only) - pairing rules (cli/lib/identity.ts), release lanes (cli/lib/train.ts) and the per-app status read (cli/lib/app-status.ts) shared with the desktop instead of copied - tests with sanitized fixtures, README, skills, CHANGELOG
130 lines
7.6 KiB
TypeScript
130 lines
7.6 KiB
TypeScript
// Credentials never live in storebound.config.ts or in git. Sources, first hit wins:
|
|
// 1. environment: PLAY_SERVICE_ACCOUNT (path to the JSON key, or the JSON itself), ASC_KEY_ID, ASC_ISSUER_ID,
|
|
// ASC_P8 (path to AuthKey_<id>.p8, or the PEM itself)
|
|
// 2. <project>/.storebound/credentials.json (gitignored), same names:
|
|
// { "PLAY_SERVICE_ACCOUNT": "...", "ASC_KEY_ID": "...", "ASC_ISSUER_ID": "...", "ASC_P8": "...",
|
|
// "reviewContact": { "firstName": "", "lastName": "", "phone": "", "email": "" },
|
|
// "reviewDemoAccount": { "username": "", "password": "" } }
|
|
// The demo account for App Review can also come from env: REVIEW_DEMO_USER, REVIEW_DEMO_PASSWORD.
|
|
// 3. ASC_P8 only: ~/.appstoreconnect/private_keys/AuthKey_<ASC_KEY_ID>.p8 (where Xcode / altool keep it)
|
|
// With a credential profile (`--profile <name>` or STOREBOUND_PROFILE), the profile comes before all of these:
|
|
// ~/.storebound/credentials/<name>.json (same four names; relative paths are relative to that file; folder:
|
|
// STOREBOUND_CREDENTIALS_DIR) or env STOREBOUND_PROFILE_<NAME>_<KEY> (NAME upper case, other characters as _).
|
|
// Many studios / store accounts from one machine: one profile per account; storebound.workspace.json names them.
|
|
import { existsSync, readFileSync } from 'node:fs';
|
|
import { homedir } from 'node:os';
|
|
import { isAbsolute, join, resolve } from 'node:path';
|
|
|
|
export interface ServiceAccount { client_email: string; private_key: string; token_uri?: string }
|
|
export interface AscKey { keyId: string; issuerId: string; pem: string }
|
|
export interface ReviewContact { firstName: string; lastName: string; phone: string; email: string }
|
|
|
|
type Store = Record<string, unknown>;
|
|
|
|
function fileStore(root: string): Store {
|
|
const p = join(root, '.storebound', 'credentials.json');
|
|
if (!existsSync(p)) return {};
|
|
try { return JSON.parse(readFileSync(p, 'utf8')) as Store; } catch (e) { throw new Error(`${p}: ${(e as Error).message}`); }
|
|
}
|
|
|
|
/** The store credential names a profile holds (the same as the env names). */
|
|
export const PROFILE_KEYS = ['PLAY_SERVICE_ACCOUNT', 'ASC_KEY_ID', 'ASC_ISSUER_ID', 'ASC_P8'] 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');
|
|
const profileEnvName = (profile: string, key: string): string => `STOREBOUND_PROFILE_${profile.toUpperCase().replace(/[^A-Z0-9]/g, '_')}_${key}`;
|
|
|
|
/**
|
|
* The credentials of one profile as env values (never printed). Env STOREBOUND_PROFILE_<NAME>_<KEY> wins over the
|
|
* profile file; a relative key path in the file is relative to the file. Throws on a bad name or an unreadable file.
|
|
*/
|
|
export function profileEnv(profile: string): Record<string, string> {
|
|
if (!PROFILE_RE.test(profile)) throw new Error(`credential profile "${profile}": letters, digits, . _ - (max 64)`);
|
|
const file = join(profileDir(), `${profile}.json`);
|
|
let stored: Store = {};
|
|
if (existsSync(file)) {
|
|
try { stored = JSON.parse(readFileSync(file, 'utf8')) as Store; } catch (e) { throw new Error(`credential profile ${profile}: ${file}: ${(e as Error).message}`); }
|
|
}
|
|
const out: Record<string, string> = {};
|
|
for (const k of PROFILE_KEYS) {
|
|
const env = process.env[profileEnvName(profile, k)];
|
|
const v = env || (typeof stored[k] === 'string' ? stored[k] as string : '');
|
|
if (!v) continue;
|
|
// a path in the file: relative to the profile folder (inline JSON / PEM stays as it is)
|
|
const isPath = !env && !/^\s*\{/.test(v) && !/BEGIN PRIVATE KEY/.test(v) && (k === 'PLAY_SERVICE_ACCOUNT' || k === 'ASC_P8');
|
|
out[k] = isPath && !isAbsolute(v) && !v.startsWith('~') ? resolve(profileDir(), v) : v;
|
|
}
|
|
return out;
|
|
}
|
|
|
|
/** Which stores a profile can reach, and where it comes from. No values. */
|
|
export function profileStatus(profile: string): { profile: string; source: 'file' | 'env' | 'missing' | 'invalid'; apple: boolean; play: boolean; error?: string } {
|
|
try {
|
|
const env = profileEnv(profile);
|
|
const fromEnv = PROFILE_KEYS.some(k => !!process.env[profileEnvName(profile, k)]);
|
|
const source = fromEnv ? 'env' : existsSync(join(profileDir(), `${profile}.json`)) ? 'file' : 'missing';
|
|
return { profile, source, apple: !!(env.ASC_KEY_ID && env.ASC_ISSUER_ID), play: !!env.PLAY_SERVICE_ACCOUNT };
|
|
} catch (e) {
|
|
return { profile, source: 'invalid', apple: false, play: false, error: (e as Error).message };
|
|
}
|
|
}
|
|
|
|
function value(root: string, name: string): string | undefined {
|
|
const profile = process.env.STOREBOUND_PROFILE;
|
|
if (profile) { const v = profileEnv(profile)[name]; if (v) return v; }
|
|
const env = process.env[name];
|
|
if (env) return env;
|
|
const v = fileStore(root)[name];
|
|
return typeof v === 'string' && v ? v : undefined;
|
|
}
|
|
|
|
/** A path or the inline content itself. */
|
|
const inline = (v: string, marker: RegExp): string => (marker.test(v) ? v : readFileSync(v.replace(/^~(?=\/)/, homedir()), 'utf8'));
|
|
|
|
export function parseServiceAccount(text: string): ServiceAccount {
|
|
const j = JSON.parse(text) as Partial<ServiceAccount>;
|
|
if (typeof j.client_email !== 'string' || typeof j.private_key !== 'string' || !j.private_key.includes('PRIVATE KEY'))
|
|
throw new Error('not a Google service account JSON key (client_email / private_key missing)');
|
|
return { client_email: j.client_email, private_key: j.private_key, token_uri: j.token_uri };
|
|
}
|
|
|
|
export function playServiceAccount(root: string): ServiceAccount {
|
|
const v = value(root, 'PLAY_SERVICE_ACCOUNT');
|
|
if (!v) throw new Error('PLAY_SERVICE_ACCOUNT is not set (env, or .storebound/credentials.json): path to the service account JSON key');
|
|
return parseServiceAccount(inline(v, /^\s*\{/));
|
|
}
|
|
|
|
export function ascKey(root: string): AscKey {
|
|
const keyId = value(root, 'ASC_KEY_ID');
|
|
const issuerId = value(root, 'ASC_ISSUER_ID');
|
|
if (!keyId || !issuerId) throw new Error('ASC_KEY_ID and ASC_ISSUER_ID are not set (env, or .storebound/credentials.json)');
|
|
const p8 = value(root, 'ASC_P8') ?? join(homedir(), '.appstoreconnect/private_keys', `AuthKey_${keyId}.p8`);
|
|
if (!/BEGIN PRIVATE KEY/.test(p8) && !existsSync(p8.replace(/^~(?=\/)/, homedir()))) throw new Error(`App Store Connect key not found: ${p8} (set ASC_P8)`);
|
|
return { keyId, issuerId, pem: inline(p8, /BEGIN PRIVATE KEY/) };
|
|
}
|
|
|
|
/** App Review contact from .storebound/credentials.json (personal data, so never in the config). */
|
|
export function reviewContact(root: string): ReviewContact | null {
|
|
const c = fileStore(root).reviewContact as Partial<ReviewContact> | undefined;
|
|
if (!c?.email) return null;
|
|
return { firstName: c.firstName ?? '', lastName: c.lastName ?? '', phone: c.phone ?? '', email: c.email };
|
|
}
|
|
|
|
export interface DemoAccount { username: string; password: string }
|
|
|
|
/** App Review demo account (sign-in for the reviewer): env REVIEW_DEMO_USER + REVIEW_DEMO_PASSWORD, else
|
|
* "reviewDemoAccount" in .storebound/credentials.json. Never in the config or the repo. */
|
|
export function reviewDemoAccount(root: string): DemoAccount | null {
|
|
const eu = process.env.REVIEW_DEMO_USER, ep = process.env.REVIEW_DEMO_PASSWORD;
|
|
if (eu && ep) return { username: eu, password: ep };
|
|
const d = fileStore(root).reviewDemoAccount as Partial<DemoAccount> | undefined;
|
|
if (typeof d?.username === 'string' && d.username && typeof d.password === 'string' && d.password) return { username: d.username, password: d.password };
|
|
return null;
|
|
}
|
|
|
|
/** For logs: "d***@example.com" / "d***"; a password is never shown, only its length class. */
|
|
export const maskUser = (u: string): string => {
|
|
const at = u.indexOf('@');
|
|
return at > 0 ? `${u[0]}***${u.slice(at)}` : `${u[0] ?? ''}***`;
|
|
};
|
|
export const maskSecret = (s: string): string => (s ? '********' : '(empty)');
|