diff options
| author | joonhoekim <26rote@gmail.com> | 2025-07-29 11:47:34 +0000 |
|---|---|---|
| committer | joonhoekim <26rote@gmail.com> | 2025-07-29 11:47:34 +0000 |
| commit | 792fb0c21136eededecf52b5b4aa1a252bdc4bfb (patch) | |
| tree | b372e3be7d5b09a8c533ae1f3766b3c49d36f106 /lib | |
| parent | 8ff20b58f595cc15319387b9641340fd3e8725d1 (diff) | |
(김준회) 파트너 Engineering 메뉴 수정, Knox 결재 로깅 추가
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/knox-api/approval/approval.ts | 72 | ||||
| -rw-r--r-- | lib/knox-api/common.ts | 4 | ||||
| -rw-r--r-- | lib/users/service.ts | 3 |
3 files changed, 62 insertions, 17 deletions
diff --git a/lib/knox-api/approval/approval.ts b/lib/knox-api/approval/approval.ts index 5e62382d..080867cd 100644 --- a/lib/knox-api/approval/approval.ts +++ b/lib/knox-api/approval/approval.ts @@ -3,6 +3,7 @@ import { getKnoxConfig, createJsonHeaders, createFormHeaders } from '../common'; import { randomUUID } from 'crypto'; import { saveApprovalToDatabase, deleteApprovalFromDatabase } from './service'; +import { debugLog, debugError } from '@/lib/debug-utils' // Knox API Approval 서버 액션들 // 가이드: lib/knox-api/approval/guide.html @@ -174,10 +175,28 @@ export async function submitApproval( }); if (!response.ok) { - throw new Error(`결재 상신 실패: ${response.status}`); + const errorText = await response.text(); + debugError('API Error Response', errorText); + throw new Error(`결재 상신 실패: ${response.status} - ${errorText}`); } - const result = await response.json(); + // 응답의 Content-Type 확인 및 charset 처리 + const contentType = response.headers.get('content-type'); + let result; + + if (contentType && contentType.includes('application/json')) { + result = await response.json(); + } else { + // JSON이 아닌 경우 텍스트로 읽고 JSON 파싱 시도 + const text = await response.text(); + debugLog('Raw response text', text); + try { + result = JSON.parse(text); + } catch (parseError) { + console.error('JSON parse error:', parseError); + throw new Error(`응답 파싱 실패: ${text}`); + } + } // Knox API 성공 시 데이터베이스에 저장 if (result.result === 'SUCCESS') { @@ -200,7 +219,7 @@ export async function submitApproval( return result; } catch (error) { - console.error('결재 상신 오류:', error); + debugError('결재 상신 오류', error); throw error; } } @@ -249,12 +268,32 @@ export async function submitSecurityApproval( }); if (!response.ok) { - throw new Error(`보안 결재 상신 실패: ${response.status}`); + const errorText = await response.text(); + debugError('Security API Error Response', errorText); + throw new Error(`보안 결재 상신 실패: ${response.status} - ${errorText}`); } - return await response.json(); + // 응답의 Content-Type 확인 및 charset 처리 + const contentType = response.headers.get('content-type'); + let result; + + if (contentType && contentType.includes('application/json')) { + result = await response.json(); + } else { + // JSON이 아닌 경우 텍스트로 읽고 JSON 파싱 시도 + const text = await response.text(); + debugLog('Raw security response text', text); + try { + result = JSON.parse(text); + } catch (parseError) { + console.error('Security JSON parse error:', parseError); + throw new Error(`보안 응답 파싱 실패: ${text}`); + } + } + + return result; } catch (error) { - console.error('보안 결재 상신 오류:', error); + debugError('보안 결재 상신 오류', error); throw error; } } @@ -562,22 +601,25 @@ export async function createSubmitApprovalRequest( // EVCP 접두어 뒤에 28자리 무작위 문자열을 붙여 32byte 고유 ID 생성 const apInfId = `EVCP${randomUUID().replace(/-/g, '').slice(0, 28)}`; - return { + const result = { contents, subject, aplns: approvalLines, - contentsType: 'TEXT', - docSecuType: 'PERSONAL', - notifyOption: '0', - urgYn: 'N', + contentsType: options.contentsType || 'TEXT', + docSecuType: options.docSecuType || 'PERSONAL', + notifyOption: options.notifyOption || '0', + urgYn: options.urgYn || 'N', sbmDt, - timeZone: 'GMT+9', - docMngSaveCode: '0', - sbmLang: 'ko', + timeZone: options.timeZone || 'GMT+9', + docMngSaveCode: options.docMngSaveCode || '0', + sbmLang: options.sbmLang || 'ko', apInfId, - importantYn: 'N', + importantYn: options.importantYn || 'N', ...options }; + + debugLog('Created Submit Request', result); + return result; } /** diff --git a/lib/knox-api/common.ts b/lib/knox-api/common.ts index db6910f2..5b13fc0a 100644 --- a/lib/knox-api/common.ts +++ b/lib/knox-api/common.ts @@ -31,7 +31,7 @@ export const createHeaders = async (contentType: string = 'application/json'): P // JSON 전용 헤더 export const createJsonHeaders = async (): Promise<Record<string, string>> => { - return await createHeaders('application/json'); + return await createHeaders('application/json; charset=utf-8'); }; // FormData 전용 헤더 (Content-Type 자동 설정) @@ -40,5 +40,7 @@ export const createFormHeaders = async (): Promise<Record<string, string>> => { return { 'System-ID': config.systemId, Authorization: `Bearer ${config.bearerToken}`, + 'Accept': 'application/json; charset=utf-8', + 'Accept-Charset': 'utf-8', }; };
\ No newline at end of file diff --git a/lib/users/service.ts b/lib/users/service.ts index 90ee170e..7019578f 100644 --- a/lib/users/service.ts +++ b/lib/users/service.ts @@ -222,7 +222,8 @@ export async function findEmailTemp(email: string) { imageUrl:userRecord.imageUrl, companyId:userRecord.companyId, techCompanyId:userRecord.techCompanyId, - domain:userRecord.domain + domain:userRecord.domain, + epId:userRecord.epId, // Knox 계정인 경우 // 기타 필요한 필드... } |
