feat: fetchWrapper 마이그레이션 및 토큰 리프레시 캐싱 구현

- 40+ actions.ts 파일을 fetchWrapper 패턴으로 마이그레이션
- 토큰 리프레시 캐싱 로직 추가 (refresh-token.ts)
- ApiErrorContext 추가로 전역 에러 처리 개선
- HR EmployeeForm 컴포넌트 개선
- 참조함(ReferenceBox) 기능 수정
- juil 테스트 URL 페이지 추가
- claudedocs 문서 업데이트

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
byeongcheolryu
2025-12-30 17:00:18 +09:00
parent 0e5307f7a3
commit d38b1242d7
82 changed files with 7434 additions and 4775 deletions

View File

@@ -12,7 +12,7 @@
'use server';
import { cookies } from 'next/headers';
import { serverFetch } from '@/lib/api/fetch-wrapper';
import type { DraftRecord, DocumentStatus, Approver } from './types';
// ============================================
@@ -85,21 +85,6 @@ interface ApprovalStepApiData {
// 헬퍼 함수
// ============================================
/**
* API 헤더 생성
*/
async function getApiHeaders(): Promise<HeadersInit> {
const cookieStore = await cookies();
const token = cookieStore.get('access_token')?.value;
return {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': token ? `Bearer ${token}` : '',
'X-API-KEY': process.env.API_KEY || '',
};
}
/**
* API 상태 → 프론트엔드 상태 변환
*/
@@ -193,9 +178,8 @@ export async function getDrafts(params?: {
status?: string;
sort_by?: string;
sort_dir?: 'asc' | 'desc';
}): Promise<{ data: DraftRecord[]; total: number; lastPage: number }> {
}): Promise<{ data: DraftRecord[]; total: number; lastPage: number; __authError?: boolean }> {
try {
const headers = await getApiHeaders();
const searchParams = new URLSearchParams();
if (params?.page) searchParams.set('page', String(params.page));
@@ -217,27 +201,20 @@ export async function getDrafts(params?: {
const url = `${process.env.NEXT_PUBLIC_API_URL}/api/v1/approvals/drafts?${searchParams.toString()}`;
console.log('[DraftBoxActions] Fetching:', url);
console.log('[DraftBoxActions] Headers:', JSON.stringify(headers, null, 2));
const { response, error } = await serverFetch(url, { method: 'GET' });
const response = await fetch(url, {
method: 'GET',
headers,
cache: 'no-store',
});
if (error?.__authError) {
return { data: [], total: 0, lastPage: 1, __authError: true };
}
console.log('[DraftBoxActions] Response status:', response.status);
if (!response.ok) {
const errorText = await response.text();
console.error('[DraftBoxActions] GET drafts error:', response.status, errorText);
if (!response) {
console.error('[DraftBoxActions] GET drafts error:', error?.message);
return { data: [], total: 0, lastPage: 1 };
}
const result: ApiResponse<PaginatedResponse<ApprovalApiData>> = await response.json();
console.log('[DraftBoxActions] Result:', JSON.stringify(result, null, 2).slice(0, 500));
if (!result.success || !result.data?.data) {
if (!response.ok || !result.success || !result.data?.data) {
console.warn('[DraftBoxActions] No data in response');
return { data: [], total: 0, lastPage: 1 };
}
@@ -258,25 +235,19 @@ export async function getDrafts(params?: {
*/
export async function getDraftsSummary(): Promise<DraftsSummary | null> {
try {
const headers = await getApiHeaders();
const response = await fetch(
const { response, error } = await serverFetch(
`${process.env.NEXT_PUBLIC_API_URL}/api/v1/approvals/drafts/summary`,
{
method: 'GET',
headers,
cache: 'no-store',
}
{ method: 'GET' }
);
if (!response.ok) {
console.error('[DraftBoxActions] GET summary error:', response.status);
if (error?.__authError || !response) {
console.error('[DraftBoxActions] GET summary error:', error?.message);
return null;
}
const result: ApiResponse<DraftsSummary> = await response.json();
if (!result.success || !result.data) {
if (!response.ok || !result.success || !result.data) {
return null;
}
@@ -292,25 +263,19 @@ export async function getDraftsSummary(): Promise<DraftsSummary | null> {
*/
export async function getDraftById(id: string): Promise<DraftRecord | null> {
try {
const headers = await getApiHeaders();
const response = await fetch(
const { response, error } = await serverFetch(
`${process.env.NEXT_PUBLIC_API_URL}/api/v1/approvals/${id}`,
{
method: 'GET',
headers,
cache: 'no-store',
}
{ method: 'GET' }
);
if (!response.ok) {
console.error('[DraftBoxActions] GET draft error:', response.status);
if (error?.__authError || !response) {
console.error('[DraftBoxActions] GET draft error:', error?.message);
return null;
}
const result: ApiResponse<ApprovalApiData> = await response.json();
if (!result.success || !result.data) {
if (!response.ok || !result.success || !result.data) {
return null;
}
@@ -324,18 +289,21 @@ export async function getDraftById(id: string): Promise<DraftRecord | null> {
/**
* 결재 문서 삭제 (임시저장 상태만)
*/
export async function deleteDraft(id: string): Promise<{ success: boolean; error?: string }> {
export async function deleteDraft(id: string): Promise<{ success: boolean; error?: string; __authError?: boolean }> {
try {
const headers = await getApiHeaders();
const response = await fetch(
const { response, error } = await serverFetch(
`${process.env.NEXT_PUBLIC_API_URL}/api/v1/approvals/${id}`,
{
method: 'DELETE',
headers,
}
{ method: 'DELETE' }
);
if (error?.__authError) {
return { success: false, __authError: true };
}
if (!response) {
return { success: false, error: error?.message || '결재 문서 삭제에 실패했습니다.' };
}
const result = await response.json();
if (!response.ok || !result.success) {
@@ -382,19 +350,24 @@ export async function deleteDrafts(ids: string[]): Promise<{ success: boolean; f
/**
* 결재 상신
*/
export async function submitDraft(id: string): Promise<{ success: boolean; error?: string }> {
export async function submitDraft(id: string): Promise<{ success: boolean; error?: string; __authError?: boolean }> {
try {
const headers = await getApiHeaders();
const response = await fetch(
const { response, error } = await serverFetch(
`${process.env.NEXT_PUBLIC_API_URL}/api/v1/approvals/${id}/submit`,
{
method: 'POST',
headers,
body: JSON.stringify({}),
}
);
if (error?.__authError) {
return { success: false, __authError: true };
}
if (!response) {
return { success: false, error: error?.message || '결재 상신에 실패했습니다.' };
}
const result = await response.json();
if (!response.ok || !result.success) {
@@ -441,19 +414,24 @@ export async function submitDrafts(ids: string[]): Promise<{ success: boolean; f
/**
* 결재 회수 (기안자만)
*/
export async function cancelDraft(id: string): Promise<{ success: boolean; error?: string }> {
export async function cancelDraft(id: string): Promise<{ success: boolean; error?: string; __authError?: boolean }> {
try {
const headers = await getApiHeaders();
const response = await fetch(
const { response, error } = await serverFetch(
`${process.env.NEXT_PUBLIC_API_URL}/api/v1/approvals/${id}/cancel`,
{
method: 'POST',
headers,
body: JSON.stringify({}),
}
);
if (error?.__authError) {
return { success: false, __authError: true };
}
if (!response) {
return { success: false, error: error?.message || '결재 회수에 실패했습니다.' };
}
const result = await response.json();
if (!response.ok || !result.success) {