UNPKG

@capgo/cli

Version:
129 lines (128 loc) 4.83 kB
export declare const ANDROIDPUBLISHER_API = "androidpublisher.googleapis.com"; export declare const DEFAULT_SERVICE_ACCOUNT_ID = "capgo-native-build"; export declare const DEFAULT_SERVICE_ACCOUNT_DISPLAY_NAME = "Capgo Native Build"; export declare const DEFAULT_SERVICE_ACCOUNT_DESCRIPTION = "Allows Capgo to build and submit the app to the Google Play Store"; export interface GcpProject { projectId: string; projectNumber: string; name: string; lifecycleState: 'ACTIVE' | 'DELETE_REQUESTED' | 'DELETE_IN_PROGRESS' | string; } export interface GcpServiceAccount { name: string; email: string; projectId: string; uniqueId: string; displayName?: string; } export interface GcpServiceAccountKey { /** Full resource name — e.g. `projects/{p}/serviceAccounts/{sa}/keys/{keyId}`. */ name: string; /** Base64-encoded JSON key file — decode with `Buffer.from(..., 'base64')`. */ privateKeyDataBase64: string; } interface GcpOperation { name: string; done?: boolean; error?: { code: number; message: string; details?: unknown; }; response?: Record<string, unknown>; } /** * List GCP projects the user has access to. Only ACTIVE projects are returned * (pending-deletion projects are filtered out). */ export declare function listProjects(accessToken: string): Promise<GcpProject[]>; /** * Create a GCP project and wait for the operation to finish. * * Google enforces: * - projectId: 6–30 chars, lowercase letters / digits / hyphens, start with * a letter, globally unique across all GCP * - name: ≤30 chars */ export declare function createProject(accessToken: string, projectId: string, displayName: string, options?: { timeoutMs?: number; }): Promise<GcpProject>; /** * Enable an API on a project (idempotent — no-op if already enabled). */ export declare function enableService(accessToken: string, projectId: string, serviceName: string, options?: { timeoutMs?: number; }): Promise<void>; /** List all service accounts in a project. */ export declare function listServiceAccounts(accessToken: string, projectId: string): Promise<GcpServiceAccount[]>; /** Create a service account. accountId must match `[a-z]([-a-z0-9]*[a-z0-9])` and be 6–30 chars. */ export declare function createServiceAccount(args: { accessToken: string; projectId: string; accountId: string; displayName?: string; description?: string; }): Promise<GcpServiceAccount>; /** * Find an existing service account by email, or create it. * Idempotent convenience used during onboarding so re-runs don't error out on * "already exists". */ export declare function ensureServiceAccount(args: { accessToken: string; projectId: string; accountId: string; displayName?: string; description?: string; }): Promise<{ account: GcpServiceAccount; created: boolean; }>; /** * Create a new JSON key for a service account. The response contains the only * copy of the private key material — store it immediately. Google cannot * retrieve the key later. */ export declare function createServiceAccountKey(args: { accessToken: string; projectId: string; serviceAccountEmail: string; }): Promise<GcpServiceAccountKey>; interface PollOperationOptions { endpoint: string; timeoutMs: number; } /** * Poll a Google long-running Operation until `done: true` or the timeout * elapses. Different Google APIs host `operations.get` at different base URLs; * callers pass the endpoint used for the originating call. */ export declare function pollOperation(accessToken: string, operationName: string, options: PollOperationOptions): Promise<GcpOperation>; /** * Normalize a user-supplied or generated string into a valid GCP project * `displayName`. Google's rules (Cloud Resource Manager v1): * * - 4–30 characters * - allowed chars: letters, digits, space, hyphen (`-`), apostrophe (`'`), * exclamation (`!`), period (`.`) * - must start and end with a letter or digit * * We strip any disallowed character (including em-dashes — which break the * CLI's placeholder string literals if not handled here), collapse runs of * whitespace, and trim the ends. Falls back to `"Capgo Build"` when the * sanitized result would be shorter than 4 chars. */ export declare function sanitizeGcpProjectDisplayName(input: string): string; /** * Generate a candidate GCP project ID for Capgo onboarding. * * Rules: * - 6–30 chars * - lowercase letters, digits, hyphens * - must start with a letter, must not end with a hyphen * - globally unique (caller should retry on 409 with a fresh random suffix) * * We keep the slug short and append a random tail so collisions are rare. */ export declare function generateProjectId(appId: string): string; export {};