43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
|
|
import { normalizeTradingEnv, type KisCredentialInput } from "@/lib/kis/config";
|
||
|
|
import type { NextRequest } from "next/server";
|
||
|
|
|
||
|
|
interface KisCredentialRequestBody {
|
||
|
|
appKey?: string;
|
||
|
|
appSecret?: string;
|
||
|
|
tradingEnv?: string;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @description 요청 본문에서 KIS 인증 정보를 파싱합니다.
|
||
|
|
* @see app/api/kis/validate/route.ts
|
||
|
|
*/
|
||
|
|
export async function parseKisCredentialRequest(
|
||
|
|
request: NextRequest,
|
||
|
|
): Promise<KisCredentialInput> {
|
||
|
|
let body: KisCredentialRequestBody = {};
|
||
|
|
|
||
|
|
try {
|
||
|
|
body = (await request.json()) as KisCredentialRequestBody;
|
||
|
|
} catch {
|
||
|
|
// 빈 본문 또는 JSON 파싱 실패는 아래 필수값 검증에서 처리합니다.
|
||
|
|
}
|
||
|
|
|
||
|
|
return {
|
||
|
|
appKey: body.appKey?.trim(),
|
||
|
|
appSecret: body.appSecret?.trim(),
|
||
|
|
tradingEnv: normalizeTradingEnv(body.tradingEnv),
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @description 인증키 필수값을 검증합니다.
|
||
|
|
* @see app/api/kis/revoke/route.ts
|
||
|
|
*/
|
||
|
|
export function validateKisCredentialInput(credentials: KisCredentialInput) {
|
||
|
|
if (!credentials.appKey || !credentials.appSecret) {
|
||
|
|
return "앱 키와 앱 시크릿을 모두 입력해 주세요.";
|
||
|
|
}
|
||
|
|
|
||
|
|
return null;
|
||
|
|
}
|