import { type AuthErrorPayload } from './errors.js'; import { type AuthDomainId } from './scopes.js'; export type { AuthDomainId } from './scopes.js'; export declare const GOOGLE_PROFILE_ID: RegExp; export declare function googleProfilePath(profile: string): string; /** Only safe metadata; never return tokens or OAuth client secrets to MCP callers. */ export declare function listGoogleProfiles(): { profile: string; connected: boolean; accountEmail: string | null; youtubeChannel: { id: string; title: string; } | null; }[]; export interface StoredTokens { youtubeChannel?: { id: string; title: string; }; access_token: string; refresh_token: string; token_type: string; expiry_date: number; /** 공백 구분 부여 스코프. 신규 도구(GA4 등) pre-flight 스코프 검사에 사용. 구 토큰은 undefined. */ scope?: string; /** * 이 토큰이 속한 Google 계정 이메일. 로그인 시 id_token 에서 기록하고, 기록 전 토큰은 * resolveAccountEmail() 이 tokeninfo 로 한 번 채운다. 표시·오류 안내용이며 인가 판단에 쓰지 않는다. */ accountEmail?: string; } /** * id_token(JWT) payload 의 email. 토큰 엔드포인트가 TLS 로 직접 준 값이라 서명 검증 없이 * 표시용으로만 읽는다. 형식이 다르거나 email 이 없으면 undefined. */ export declare function emailFromIdToken(idToken: string | null | undefined): string | undefined; export declare function getStoredCredentials(profile?: string): { clientId: string; clientSecret: string; } | null; export declare function saveCredentials(clientId: string, clientSecret: string): void; export declare function getStoredTokens(profile?: string): StoredTokens | null; /** * tokens.json mtime — 마지막 refresh 시각의 근사값. * (saveTokens 가 매번 writeFileSync 으로 갱신하므로 mtime ≈ 마지막 갱신/저장.) * Google refresh_token 은 7일(미인증 앱) ~ 6개월(인증 앱) 미사용 시 revoke 됨. * auth_status 응답 enrichment 에 사용. */ export declare function getTokensLastRefreshMs(profile?: string): number | null; /** OAuth 루프백 콜백. redirect URI 는 Google 콘솔에 등록된 값이라 호스트명을 바꾸면 안 된다. */ export declare const OAUTH_CALLBACK_PORT = 9876; export declare const OAUTH_REDIRECT_URI = "http://localhost:9876/callback"; /** `localhost` 가 풀릴 수 있는 두 루프백 주소 — 외부 인터페이스에는 열지 않는다. */ export declare const OAUTH_CALLBACK_HOSTS: readonly ["127.0.0.1", "::1"]; /** 콜백 포트가 한 루프백 주소에서 점유됐을 때의 안내 (한/영). */ export declare function callbackPortInUse(host: string, err: Error): AuthErrorPayload; export declare function createOAuth2Client(clientId: string, clientSecret: string): import("google-auth-library").OAuth2Client; /** * Get authenticated OAuth2 client. * Returns null if not authenticated yet. */ export declare function getAuthenticatedClient(profile?: string): ReturnType | null; export declare function getGoogleAuthAttempt(profile?: string): { status: "pending" | "succeeded" | "failed"; expectedChannelId?: string; } | null; /** * OAuth 플로우 시작. * URL과 대기 Promise를 즉시 반환. localhost:9876 콜백 서버는 백그라운드로 실행. * 호출자가 URL을 사용자에게 전달하거나 private 브라우저를 직접 연다. * `wait` Promise: 토큰 저장 시 resolve, 타임아웃/에러 시 reject. * 재호출 시 기존 세션 자동 정리. * * `domains` 로 권한 도메인 서브셋만 요청할 수 있다 (미지정 시 전체 — 기존 동작). * include_granted_scopes 덕에 재로그인은 기존 부여 스코프를 유지한 채 새 스코프만 * 얹는다(incremental authorization) — 토큰 응답의 scope 필드에도 누적 전체가 온다. */ export declare function startAuth(clientId: string, clientSecret: string, options?: { timeoutMs?: number; domains?: readonly AuthDomainId[]; profile?: string; expectedChannelId?: string; }): { url: string; wait: Promise; }; export type RefreshStatus = { status: 'fresh'; tokens: StoredTokens; msUntilExpiry: number; } | { status: 'refreshed'; tokens: StoredTokens; msUntilExpiry: number; } | { status: 'expired_refresh_failed'; tokens: StoredTokens; error: AuthErrorPayload; } | { status: 'unauthenticated'; error: AuthErrorPayload; }; export declare function ensureFreshAccessToken(marginMs?: number, profile?: string): Promise; /** * 저장된 로그인이 어느 Google 계정인지. 로그인 때 기록한 값을 우선 쓰고, 기록이 없는 구 토큰은 * tokeninfo 로 한 번 조회해 저장한다(다음부터 네트워크 없음). 조회 실패·email 스코프 미부여면 null — * 상태 표시가 이것 때문에 실패하면 안 되므로 절대 throw 하지 않는다. * * 호출 전에 ensureFreshAccessToken() 으로 access_token 을 갱신해 두는 것이 호출자 책임이다. */ export declare function resolveAccountEmail(profile?: string): Promise;