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

@@ -1,40 +1,42 @@
'use server';
import { cookies } from 'next/headers';
import { serverFetch } from '@/lib/api/fetch-wrapper';
import type { SubscriptionApiData, UsageApiData, SubscriptionInfo } from './types';
import { transformApiToFrontend } from './utils';
// ===== 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 || '',
};
}
// ===== 현재 활성 구독 조회 =====
export async function getCurrentSubscription(): Promise<{
success: boolean;
data: SubscriptionApiData | null;
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/subscriptions/current`,
{
method: 'GET',
headers,
cache: 'no-store',
}
);
if (error) {
return {
success: false,
data: null,
error: error.message,
__authError: error.code === 'UNAUTHORIZED',
};
}
if (!response) {
return {
success: false,
data: null,
error: '구독 정보를 불러오는데 실패했습니다.',
};
}
const result = await response.json();
if (!response.ok || !result.success) {
@@ -64,19 +66,34 @@ export async function getUsage(): Promise<{
success: boolean;
data: UsageApiData | null;
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/subscriptions/usage`,
{
method: 'GET',
headers,
cache: 'no-store',
}
);
if (error) {
return {
success: false,
data: null,
error: error.message,
__authError: error.code === 'UNAUTHORIZED',
};
}
if (!response) {
return {
success: false,
data: null,
error: '사용량 정보를 불러오는데 실패했습니다.',
};
}
const result = await response.json();
if (!response.ok || !result.success) {
@@ -108,19 +125,32 @@ export async function cancelSubscription(
): 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/subscriptions/${id}/cancel`,
{
method: 'POST',
headers,
body: JSON.stringify({ reason }),
}
);
if (error) {
return {
success: false,
error: error.message,
__authError: error.code === 'UNAUTHORIZED',
};
}
if (!response) {
return {
success: false,
error: '구독 취소에 실패했습니다.',
};
}
const result = await response.json();
if (!response.ok || !result.success) {
@@ -147,19 +177,32 @@ export async function requestDataExport(
success: boolean;
data?: { id: number; status: string };
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/subscriptions/export`,
{
method: 'POST',
headers,
body: JSON.stringify({ export_type: exportType }),
}
);
if (error) {
return {
success: false,
error: error.message,
__authError: error.code === 'UNAUTHORIZED',
};
}
if (!response) {
return {
success: false,
error: '내보내기 요청에 실패했습니다.',
};
}
const result = await response.json();
if (!response.ok || !result.success) {