import { parseKisAccountParts } from "@/lib/kis/account"; import { normalizeTradingEnv, type KisCredentialInput, } from "@/lib/kis/config"; /** * @description 요청 헤더에서 KIS 키를 읽어옵니다. * @param headers 요청 헤더 * @returns KIS 인증 입력값 * @see app/api/kis/domestic/balance/route.ts 대시보드 잔고 API 인증키 파싱 * @see app/api/kis/domestic/indices/route.ts 대시보드 지수 API 인증키 파싱 */ export function readKisCredentialsFromHeaders(headers: Headers): KisCredentialInput { const appKey = headers.get("x-kis-app-key")?.trim(); const appSecret = headers.get("x-kis-app-secret")?.trim(); const tradingEnv = normalizeTradingEnv( headers.get("x-kis-trading-env") ?? undefined, ); return { appKey, appSecret, tradingEnv, }; } /** * @description 요청 헤더에서 계좌번호(8-2)를 읽어옵니다. * @param headers 요청 헤더 * @returns 계좌번호 파트(8 + 2) 또는 null * @see app/api/kis/domestic/balance/route.ts 잔고 조회 시 필수 계좌정보 파싱 */ export function readKisAccountParts(headers: Headers) { const headerAccountNo = headers.get("x-kis-account-no"); const headerAccountProductCode = headers.get("x-kis-account-product-code"); return parseKisAccountParts(headerAccountNo, headerAccountProductCode); }