Files
Johngreen 52386efb83
Build & Deploy to K8s / build-and-deploy (push) Has been cancelled
도메인 정리: invion.com → invyone.com 전체 일괄 치환 + 매핑 문서화
운영 도메인이 실제로는 v1.invyone.com / solution.invyone.com / api.invyone.com 인데
코드/문서 곳곳에 v1.invion.com / api.invion.com 등 미존재 도메인이 박혀 있어 정리.

변경 파일 (21):
- frontend lib/api/client.ts, lib/utils/apiUrl.ts: hostname 체크 endsWith(\".invyone.com\") 일반화
- frontend lib/api/dashboard.ts, file.ts, flow.ts, FileViewerModal*2.tsx: 도메인 치환
- frontend invion-layout-v5.html: 시안 내 placeholder 도메인 정리
- backend-spring SecurityConfig.java: CORS 주석 예시 정리
- docker/deploy/docker-compose.yml, k8s/traefik-dynamic.yaml: traefik Host 라벨 정리
- scripts/prod/deploy.sh: 안내 메시지 정리
- .cursor/rules/api-client-usage.mdc, project-conventions.mdc: AI 가이드 정리
- docs/* 4개: 아키텍처/플로우 문서 도메인 정리
- notes/gbpark/* 3개: 과거 메모 정리

신규:
- docs/DOMAIN_MAPPING.md: 운영/개발/폐기 도메인 영구 기록.
  AI 에이전트와 신규 개발자가 헷갈리지 않도록 단일 진실 출처.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-28 07:39:04 +09:00

354 lines
9.9 KiB
TypeScript

/**
* 대시보드 API 클라이언트
*/
import { DashboardElement } from "@/components/admin/dashboard/types";
// API URL 동적 설정
function getApiBaseUrl(): string {
// 클라이언트 사이드에서만 실행
if (typeof window !== "undefined") {
const hostname = window.location.hostname;
// 프로덕션: v1.invyone.com → https://api.invyone.com/api
if (hostname === "v1.invyone.com") {
return "https://api.invyone.com/api";
}
// 로컬 개발: localhost → http://localhost:8081/api
if (hostname === "localhost" || hostname === "127.0.0.1") {
return "http://localhost:8081/api";
}
}
// 서버 사이드 렌더링 시 기본값
return "/api";
}
// 토큰 가져오기 (실제 인증 시스템에 맞게 수정)
function getAuthToken(): string | null {
if (typeof window === "undefined") return null;
return localStorage.getItem("authToken") || sessionStorage.getItem("authToken");
}
// API 요청 헬퍼
async function apiRequest<T>(
endpoint: string,
options: RequestInit = {},
): Promise<{ success: boolean; data?: T; message?: string; pagination?: any }> {
const token = getAuthToken();
const API_BASE_URL = getApiBaseUrl();
const config: RequestInit = {
credentials: "include", // ⭐ 세션 쿠키 전송 필수
headers: {
"Content-Type": "application/json",
...(token && { Authorization: `Bearer ${token}` }),
...options.headers,
},
...options,
};
try {
const response = await fetch(`${API_BASE_URL}${endpoint}`, config);
// 응답이 JSON이 아닐 수도 있으므로 안전하게 처리
let result;
try {
result = await response.json();
} catch (jsonError) {
console.error("JSON Parse Error:", jsonError);
throw new Error(`서버 응답을 파싱할 수 없습니다. Status: ${response.status}`);
}
if (!response.ok) {
console.warn("[Dashboard API]", response.status, result?.message || response.statusText);
throw new Error(result.message || `HTTP ${response.status}: ${response.statusText}`);
}
return result;
} catch (error: any) {
console.warn("[Dashboard API] 요청 실패:", endpoint, error?.message || error);
throw error;
}
}
// 대시보드 타입 정의
export interface Dashboard {
id: string;
title: string;
description?: string;
thumbnail_url?: string;
is_public: boolean | string;
created_by: string;
created_by_name?: string;
created_date: number;
updated_date: number;
tags?: string[];
category?: string;
view_count: number;
elements_count?: number;
company_code?: string;
elements?: DashboardElement[];
settings?: {
resolution?: string;
backgroundColor?: string;
};
}
export interface CreateDashboardRequest {
title: string;
description?: string;
isPublic?: boolean;
elements: DashboardElement[];
tags?: string[];
category?: string;
settings?: {
resolution?: string;
backgroundColor?: string;
};
}
export interface DashboardListQuery {
page?: number;
limit?: number;
search?: string;
category?: string;
isPublic?: boolean;
}
// 대시보드 API 함수들
export const dashboardApi = {
/**
* 대시보드 생성
*/
async createDashboard(data: CreateDashboardRequest): Promise<Dashboard> {
console.log("🔍 [API createDashboard] 요청 데이터:", {
data,
settings: data.settings,
stringified: JSON.stringify(data),
});
const result = await apiRequest<Dashboard>("/dashboard", {
method: "POST",
body: JSON.stringify(data),
});
if (!result.success || !result.data) {
throw new Error(result.message || "대시보드 생성에 실패했습니다.");
}
console.log("🔍 [API createDashboard] 응답 데이터:", {
settings: result.data.settings,
});
return result.data;
},
/**
* 대시보드 목록 조회
*/
async getDashboards(query: DashboardListQuery = {}) {
const params = new URLSearchParams();
if (query.page) params.append("page", query.page.toString());
if (query.limit) params.append("limit", query.limit.toString());
if (query.search) params.append("search", query.search);
if (query.category) params.append("category", query.category);
if (typeof query.isPublic === "boolean") params.append("isPublic", query.isPublic.toString());
const queryString = params.toString();
const endpoint = `/dashboard${queryString ? `?${queryString}` : ""}`;
const result = await apiRequest<Dashboard[]>(endpoint);
if (!result.success) {
throw new Error(result.message || "대시보드 목록 조회에 실패했습니다.");
}
return {
dashboards: result.data || [],
pagination: result.pagination,
};
},
/**
* 내 대시보드 목록 조회
*
* 백엔드 DashboardController: GET /api/dashboards
* - user_id/company_code 는 request attribute 에서 자동 주입되므로 별도 파라미터 불필요
* - 응답 구조: { success, data: { list:[], total_count, limit, page, total_page } }
*/
async getMyDashboards(query: DashboardListQuery = {}) {
const params = new URLSearchParams();
if (query.page) params.append("page", query.page.toString());
if (query.limit) params.append("limit", query.limit.toString());
if (query.search) params.append("keyword", query.search);
const queryString = params.toString();
const endpoint = `/dashboards${queryString ? `?${queryString}` : ""}`;
const result = await apiRequest<{ list: Dashboard[]; total_count?: number; total_page?: number; page?: number; limit?: number }>(endpoint);
if (!result.success) {
throw new Error(result.message || "내 대시보드 목록 조회에 실패했습니다.");
}
return {
dashboards: result.data?.list || [],
pagination: {
total: result.data?.total_count,
totalPage: result.data?.total_page,
page: result.data?.page,
limit: result.data?.limit,
},
};
},
/**
* 대시보드 상세 조회
*/
async getDashboard(id: string): Promise<Dashboard> {
const result = await apiRequest<Dashboard>(`/dashboard/${id}`);
if (!result.success || !result.data) {
throw new Error(result.message || "대시보드 조회에 실패했습니다.");
}
return result.data;
},
/**
* 공개 대시보드 조회 (인증 불필요)
*/
async getPublicDashboard(id: string): Promise<Dashboard> {
const result = await apiRequest<Dashboard>(`/dashboard/public/${id}`);
if (!result.success || !result.data) {
throw new Error(result.message || "대시보드 조회에 실패했습니다.");
}
return result.data;
},
/**
* 대시보드 수정
*/
async updateDashboard(id: string, data: Partial<CreateDashboardRequest>): Promise<Dashboard> {
console.log("🔍 [API updateDashboard] 요청 데이터:", {
id,
data,
settings: data.settings,
stringified: JSON.stringify(data),
});
const result = await apiRequest<Dashboard>(`/dashboard/${id}`, {
method: "PUT",
body: JSON.stringify(data),
});
if (!result.success || !result.data) {
throw new Error(result.message || "대시보드 수정에 실패했습니다.");
}
console.log("🔍 [API updateDashboard] 응답 데이터:", {
settings: result.data.settings,
});
return result.data;
},
/**
* 대시보드 삭제
*/
async deleteDashboard(id: string): Promise<void> {
const result = await apiRequest(`/dashboard/${id}`, {
method: "DELETE",
});
if (!result.success) {
throw new Error(result.message || "대시보드 삭제에 실패했습니다.");
}
},
/**
* 공개 대시보드 목록 조회 (인증 불필요)
*/
async getPublicDashboards(query: DashboardListQuery = {}) {
const params = new URLSearchParams();
if (query.page) params.append("page", query.page.toString());
if (query.limit) params.append("limit", query.limit.toString());
if (query.search) params.append("search", query.search);
if (query.category) params.append("category", query.category);
const queryString = params.toString();
const endpoint = `/dashboard/public${queryString ? `?${queryString}` : ""}`;
const result = await apiRequest<Dashboard[]>(endpoint);
if (!result.success) {
throw new Error(result.message || "공개 대시보드 목록 조회에 실패했습니다.");
}
return {
dashboards: result.data || [],
pagination: result.pagination,
};
},
/**
* 쿼리 실행 (차트 데이터 조회)
*/
async executeQuery(query: string): Promise<{ columns: string[]; rows: any[]; rowCount: number }> {
const result = await apiRequest<{ columns: string[]; rows: any[]; rowCount: number }>("/dashboard/execute-query", {
method: "POST",
body: JSON.stringify({ query }),
});
if (!result.success || !result.data) {
throw new Error(result.message || "쿼리 실행에 실패했습니다.");
}
return result.data;
},
/**
* 테이블 스키마 조회 (날짜 컬럼 감지용)
*/
async getTableSchema(tableName: string): Promise<{
tableName: string;
columns: Array<{ name: string; type: string; udtName: string }>;
dateColumns: string[];
}> {
const result = await apiRequest<{
tableName: string;
columns: Array<{ name: string; type: string; udtName: string }>;
dateColumns: string[];
}>("/dashboard/table-schema", {
method: "POST",
body: JSON.stringify({ tableName }),
});
if (!result.success || !result.data) {
throw new Error(result.message || "테이블 스키마 조회에 실패했습니다.");
}
return result.data;
},
};
// 에러 처리 유틸리티
export function handleApiError(error: any): string {
if (error.message) {
return error.message;
}
if (typeof error === "string") {
return error;
}
return "알 수 없는 오류가 발생했습니다.";
}