261027_01_ENH: 사내 연동 API에 url copy 추가

This commit is contained in:
2026-10-27 09:03:18 +09:00
parent d4747b0ea0
commit a1f39c74de
4 changed files with 118 additions and 56 deletions

98
package-lock.json generated
View File

@@ -41,7 +41,7 @@
"embla-carousel-react": "^8.6.0", "embla-carousel-react": "^8.6.0",
"jotai": "latest", "jotai": "latest",
"lucide-react": "latest", "lucide-react": "latest",
"next": "latest", "next": "~16.4.1",
"prettier": "^3.9.10", "prettier": "^3.9.10",
"radix-ui": "^1.8.0", "radix-ui": "^1.8.0",
"react": "latest", "react": "latest",
@@ -59,7 +59,7 @@
"@types/react-dom": "latest", "@types/react-dom": "latest",
"babel-plugin-react-compiler": "latest", "babel-plugin-react-compiler": "latest",
"eslint": "^9", "eslint": "^9",
"eslint-config-next": "latest", "eslint-config-next": "~16.4.1",
"playwright": "^1.64.1", "playwright": "^1.64.1",
"tailwindcss": "latest", "tailwindcss": "latest",
"tw-animate-css": "latest", "tw-animate-css": "latest",
@@ -1260,15 +1260,15 @@
} }
}, },
"node_modules/@next/env": { "node_modules/@next/env": {
"version": "16.4.0", "version": "16.4.3",
"resolved": "https://registry.npmjs.org/@next/env/-/env-16.4.0.tgz", "resolved": "https://registry.npmjs.org/@next/env/-/env-16.4.3.tgz",
"integrity": "sha512-pyLlT5oafGlX8X7xjgGNXz5dNIDSxREm+qD6i9VLSZiZFopA/XWl8NM/KPmLx/8EG/++c49iid3gNWSQW1+2dQ==", "integrity": "sha512-a7tz1QCcWWkwC/rPJcPMJk/UNRu9CFhDd3OHYE5hddbJrs8BqRTalxI6GlKCWEGzRLHN+S/B7a4PAHCtm25aBQ==",
"license": "MIT" "license": "MIT"
}, },
"node_modules/@next/eslint-plugin-next": { "node_modules/@next/eslint-plugin-next": {
"version": "16.4.0", "version": "16.4.3",
"resolved": "https://registry.npmjs.org/@next/eslint-plugin-next/-/eslint-plugin-next-16.4.0.tgz", "resolved": "https://registry.npmjs.org/@next/eslint-plugin-next/-/eslint-plugin-next-16.4.3.tgz",
"integrity": "sha512-ffeflB/dL8RrvWejQximw01pOpKHN692Y3FjDB82DCd0YVvXvBD6vY7mcZp27yvSVFVM6wA73xVodEKF4spizA==", "integrity": "sha512-oxuC06wt/71h6ACYCV9GbKOfnf5a7VlRe/p80YHTut15TNgDEmynDnaq8t/xhy5rlvk7dhItIPs6H3rvIM4kyw==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
@@ -1309,9 +1309,9 @@
} }
}, },
"node_modules/@next/swc-darwin-arm64": { "node_modules/@next/swc-darwin-arm64": {
"version": "16.4.0", "version": "16.4.3",
"resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-16.4.0.tgz", "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-16.4.3.tgz",
"integrity": "sha512-yyZ+9MgViAKLLb5l1gPBGjRwnq3teNLb5Zx6JEw8LzNSTjlsnp+baUHFxTgl7PpjCmKf48VQfyipG1eBflb48Q==", "integrity": "sha512-4yq5EXBt+VDtAZwTyfijaFp5D2C5oz3Ikw5a2kiX2K9nw72vrZX2q5UuAlkPtUMO1tQz6JTKpaKWjS7OOefTDQ==",
"cpu": [ "cpu": [
"arm64" "arm64"
], ],
@@ -1325,9 +1325,9 @@
} }
}, },
"node_modules/@next/swc-darwin-x64": { "node_modules/@next/swc-darwin-x64": {
"version": "16.4.0", "version": "16.4.3",
"resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-16.4.0.tgz", "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-16.4.3.tgz",
"integrity": "sha512-RePEEejEj1Auf5s9qEcG0JbcDP3ceNUS/ofNX8AhxzgIjTVlZIHMatlp16YplcSMpsVo/ZMQHJTjbMYJznjGUg==", "integrity": "sha512-1Rvkn/LUhnEF8WxnRkOrqGhbwXui1bkWFxONKIbN+r7C+9KHDSZ+iUoj4CzymVMWUyZIyx9szcb9+kbKhD500A==",
"cpu": [ "cpu": [
"x64" "x64"
], ],
@@ -1341,9 +1341,9 @@
} }
}, },
"node_modules/@next/swc-linux-arm64-gnu": { "node_modules/@next/swc-linux-arm64-gnu": {
"version": "16.4.0", "version": "16.4.3",
"resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-16.4.0.tgz", "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-16.4.3.tgz",
"integrity": "sha512-HhsyCqd+NpmvDDVY/LqkAN24f+QVvXh3ie+PfcwKinWL2Mu826JymQxJXGjAIfmJ4VlHjp4Pe/nZtXtUoEMAqw==", "integrity": "sha512-dCKpXErGg3abUM6t5JTJV/ottVBTStJB5lRJTbgdUdQaQ+jNHiK56Hsc0YAEg/rinSh42hYG3HWiYmEMdilnxg==",
"cpu": [ "cpu": [
"arm64" "arm64"
], ],
@@ -1357,9 +1357,9 @@
} }
}, },
"node_modules/@next/swc-linux-arm64-musl": { "node_modules/@next/swc-linux-arm64-musl": {
"version": "16.4.0", "version": "16.4.3",
"resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-16.4.0.tgz", "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-16.4.3.tgz",
"integrity": "sha512-sN9Pf+Zh+RpZAOmbR7d8KAA8T61CVhawtbEJ2Bk6QrRzx6Z/6haaF4UiwBzytM96GRRRWZh9/WALIEO3npMamA==", "integrity": "sha512-WwYbhWkhYBvBtib1K4W0kL8MW2snBD2A5b3SN4vPpqalZbZs5+bQ1yzAdepVoOqrFfEW3dmREy4Zs1MrWcrFbw==",
"cpu": [ "cpu": [
"arm64" "arm64"
], ],
@@ -1373,9 +1373,9 @@
} }
}, },
"node_modules/@next/swc-linux-x64-gnu": { "node_modules/@next/swc-linux-x64-gnu": {
"version": "16.4.0", "version": "16.4.3",
"resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-16.4.0.tgz", "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-16.4.3.tgz",
"integrity": "sha512-D5M5xLWQVd1CvR+L7BickM1weRfmM41x3L1NWcnKY/oyJJqr1qwaCgmu3dMAhLBOMdZwSuDCRV6DJRRpiUkbDQ==", "integrity": "sha512-QymWvfUwDEC5/lpJOsxX5VAbyoR2D13+2Jsjz4be7gT4LPqEgdpkeLIR/HFfCLgKzoMhpJbp6I/JnogyNZHcaA==",
"cpu": [ "cpu": [
"x64" "x64"
], ],
@@ -1389,9 +1389,9 @@
} }
}, },
"node_modules/@next/swc-linux-x64-musl": { "node_modules/@next/swc-linux-x64-musl": {
"version": "16.4.0", "version": "16.4.3",
"resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-16.4.0.tgz", "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-16.4.3.tgz",
"integrity": "sha512-8d5WLS6a9YalqpOgXdlbvonFu+sIgjA+CO6tGzetrpPVcUL56foa7B7664h41rAlbLi5fJwK4vWji3zf4QDy+w==", "integrity": "sha512-Vmjd9D7DpA4Vv3cUlr82QWgJD/BQZmns801vtC5VWHg6jCIA4a5vMKpQnfrM2pyCrp2eV0ENdUg4PlN3bAc2Yw==",
"cpu": [ "cpu": [
"x64" "x64"
], ],
@@ -1405,9 +1405,9 @@
} }
}, },
"node_modules/@next/swc-win32-arm64-msvc": { "node_modules/@next/swc-win32-arm64-msvc": {
"version": "16.4.0", "version": "16.4.3",
"resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-16.4.0.tgz", "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-16.4.3.tgz",
"integrity": "sha512-sQuOIiW3snb48UwrBcDMvFA/u03qtw2LeuSIxFIQ9AJuW9UG/4Ddsfo+eV73PnZwBhyncMtsKVh7PrzMol2/fA==", "integrity": "sha512-lG1pPdPLk7gTyGb00n5JIMLdBJgjb+UEhSdZvFbhUMg0DyC6z4B7RnpSKF9VCd4imkLObVbXOFA0kFCpw7yFow==",
"cpu": [ "cpu": [
"arm64" "arm64"
], ],
@@ -1421,9 +1421,9 @@
} }
}, },
"node_modules/@next/swc-win32-x64-msvc": { "node_modules/@next/swc-win32-x64-msvc": {
"version": "16.4.0", "version": "16.4.3",
"resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-16.4.0.tgz", "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-16.4.3.tgz",
"integrity": "sha512-6/33lCuxpdHUy27RegyGM/5uTpF7YZd3UR4D0gpkOA/tWY5YR7msbQjqPgCZmSmxrrTLGCXYA4A8vT2H5DPGTQ==", "integrity": "sha512-NmQC9RkJdnPXRaMxtkCzobB3teVjqF33oSOnwDfi+XYGWWYpt+xlGK3mtktSKLbdjwaWbJu2OkkMiRFGUUncKg==",
"cpu": [ "cpu": [
"x64" "x64"
], ],
@@ -5785,13 +5785,13 @@
} }
}, },
"node_modules/eslint-config-next": { "node_modules/eslint-config-next": {
"version": "16.4.0", "version": "16.4.3",
"resolved": "https://registry.npmjs.org/eslint-config-next/-/eslint-config-next-16.4.0.tgz", "resolved": "https://registry.npmjs.org/eslint-config-next/-/eslint-config-next-16.4.3.tgz",
"integrity": "sha512-2RHLYswzc+hNRktWAjIL6XAvwb1cKcjLawJ5KWywAxn/JivNHtG42ZigL1yobVXDqsimuuL2F9jcEcnHFzbppQ==", "integrity": "sha512-j9IqBma6abp800frdUURaizYMgXOK+jNGyq6CsYcM9AxpSJs5D/TgMNGeAmRUilZvA7g9V1Tr71gNg9/SVTuMQ==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@next/eslint-plugin-next": "16.4.0", "@next/eslint-plugin-next": "16.4.3",
"eslint-import-resolver-node": "^0.3.6", "eslint-import-resolver-node": "^0.3.6",
"eslint-import-resolver-typescript": "^3.5.2", "eslint-import-resolver-typescript": "^3.5.2",
"eslint-plugin-import": "^2.32.0", "eslint-plugin-import": "^2.32.0",
@@ -7723,12 +7723,12 @@
"license": "MIT" "license": "MIT"
}, },
"node_modules/next": { "node_modules/next": {
"version": "16.4.0", "version": "16.4.3",
"resolved": "https://registry.npmjs.org/next/-/next-16.4.0.tgz", "resolved": "https://registry.npmjs.org/next/-/next-16.4.3.tgz",
"integrity": "sha512-N2C+9q89Z/oLrsepSRS4jRMtwmUZAoZuAHU0e9T6+sAB5DdhADmrnOW+zjYijlrYFmVfmQhGVGy9eMFoB7UgKg==", "integrity": "sha512-OqxKTGi9u80FydydsMNYNjnuje9Au+kvHlt2GZ//ftdpDHm1dxKqAaENoOOTX5wKzn+9vaKUNIfZeyZUuLhCnA==",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@next/env": "16.4.0", "@next/env": "16.4.3",
"@swc/helpers": "0.5.23", "@swc/helpers": "0.5.23",
"baseline-browser-mapping": "^2.9.19", "baseline-browser-mapping": "^2.9.19",
"caniuse-lite": "^1.0.30001579", "caniuse-lite": "^1.0.30001579",
@@ -7742,15 +7742,15 @@
"node": ">=20.9.0" "node": ">=20.9.0"
}, },
"optionalDependencies": { "optionalDependencies": {
"@next/swc-darwin-arm64": "16.4.0", "@next/swc-darwin-arm64": "16.4.3",
"@next/swc-darwin-x64": "16.4.0", "@next/swc-darwin-x64": "16.4.3",
"@next/swc-linux-arm64-gnu": "16.4.0", "@next/swc-linux-arm64-gnu": "16.4.3",
"@next/swc-linux-arm64-musl": "16.4.0", "@next/swc-linux-arm64-musl": "16.4.3",
"@next/swc-linux-x64-gnu": "16.4.0", "@next/swc-linux-x64-gnu": "16.4.3",
"@next/swc-linux-x64-musl": "16.4.0", "@next/swc-linux-x64-musl": "16.4.3",
"@next/swc-win32-arm64-msvc": "16.4.0", "@next/swc-win32-arm64-msvc": "16.4.3",
"@next/swc-win32-x64-msvc": "16.4.0", "@next/swc-win32-x64-msvc": "16.4.3",
"sharp": "^0.35.4" "sharp": "^0.35.5"
}, },
"peerDependencies": { "peerDependencies": {
"@opentelemetry/api": "^1.1.0", "@opentelemetry/api": "^1.1.0",

View File

@@ -43,7 +43,7 @@
"embla-carousel-react": "^8.6.0", "embla-carousel-react": "^8.6.0",
"jotai": "latest", "jotai": "latest",
"lucide-react": "latest", "lucide-react": "latest",
"next": "latest", "next": "~16.4.1",
"prettier": "^3.9.10", "prettier": "^3.9.10",
"radix-ui": "^1.8.0", "radix-ui": "^1.8.0",
"react": "latest", "react": "latest",
@@ -61,7 +61,7 @@
"@types/react-dom": "latest", "@types/react-dom": "latest",
"babel-plugin-react-compiler": "latest", "babel-plugin-react-compiler": "latest",
"eslint": "^9", "eslint": "^9",
"eslint-config-next": "latest", "eslint-config-next": "~16.4.1",
"playwright": "^1.64.1", "playwright": "^1.64.1",
"tailwindcss": "latest", "tailwindcss": "latest",
"tw-animate-css": "latest", "tw-animate-css": "latest",

View File

@@ -5,8 +5,11 @@ import {
internalTarget, internalTarget,
readInternalQuotaRequest, readInternalQuotaRequest,
readInternalReportBatch, readInternalReportBatch,
readInternalShareRequest,
} from "@/lib/kric-internal-policy"; } from "@/lib/kric-internal-policy";
import { readExcelRequest } from "@/types/export"; import { readExcelRequest } from "@/types/export";
import { isRecord } from "@/types/kart";
import { isShareLink } from "@/types/share";
import type { RouteContext } from "@/types/common"; import type { RouteContext } from "@/types/common";
export const maxDuration = 660; export const maxDuration = 660;
@@ -22,7 +25,7 @@ async function handle(request: NextRequest, context: RouteContext) {
if (!apiKey) return jsonError("X-API-Key는 필수입니다.", 401); if (!apiKey) return jsonError("X-API-Key는 필수입니다.", 401);
let body: unknown; let body: unknown;
if (target.kind !== "list") { if (target.kind !== "list" && target.kind !== "respondent") {
try { try {
const input: unknown = await request.json(); const input: unknown = await request.json();
body = body =
@@ -30,7 +33,9 @@ async function handle(request: NextRequest, context: RouteContext) {
? readInternalReportBatch(input) ? readInternalReportBatch(input)
: target.kind === "quota" : target.kind === "quota"
? readInternalQuotaRequest(input) ? readInternalQuotaRequest(input)
: readExcelRequest(input); : target.kind === "share"
? readInternalShareRequest(input)
: readExcelRequest(input);
} catch (error) { } catch (error) {
return jsonError( return jsonError(
error instanceof SyntaxError error instanceof SyntaxError
@@ -46,11 +51,26 @@ async function handle(request: NextRequest, context: RouteContext) {
try { try {
const api = createServerApiWithApiKey(apiKey); const api = createServerApiWithApiKey(apiKey);
const options = { signal: request.signal, cache: "no-store" as const }; const options = { signal: request.signal, cache: "no-store" as const };
if (target.kind === "list" || target.kind === "quota") { if (
target.kind === "list" ||
target.kind === "quota" ||
target.kind === "respondent" ||
target.kind === "share"
) {
const result = const result =
target.kind === "list" target.kind === "list"
? await api.get<unknown>(target.path, options) ? await api.get<unknown>(target.path, options)
: await api.post<unknown>(target.path, body, options); : await api.post<unknown>(target.path, body, options);
if (
target.kind === "share" &&
(!isShareLink(result) ||
result.projectType !== Number(slug[1]) ||
result.pkey !== slug[2] ||
result.pageOnly ||
!isRecord(body) ||
result.realUrl !== body.realUrl)
)
return jsonError("공유 링크 응답을 확인해 주세요.", 502);
return NextResponse.json(result, { headers: noStore }); return NextResponse.json(result, { headers: noStore });
} }
const upstream = await api.streamPost(target.path, body, { const upstream = await api.streamPost(target.path, body, {

View File

@@ -3,12 +3,26 @@ import {
isQuotaListPath, isQuotaListPath,
isQuotaResultPath, isQuotaResultPath,
isReportStreamPath, isReportStreamPath,
isProjectReadPath,
} from "@/lib/project-proxy-policy"; } from "@/lib/project-proxy-policy";
import { isRecord, validDateRange } from "@/types/kart"; import { isRecord, validDateRange } from "@/types/kart";
import { readReportBatch } from "@/lib/report-contract"; import { readReportBatch } from "@/lib/report-contract";
import { parseFilterExpression } from "@/lib/filter-expression"; import { parseFilterExpression } from "@/lib/filter-expression";
import { reportUrl } from "@/types/share";
type Target = { path: string; kind: "list" | "quota" | "report" | "excel" }; type Target = {
path: string;
kind: "list" | "quota" | "report" | "excel" | "respondent" | "share";
};
/** URL Copy only: the server resolves the project from the authenticated path. */
export function readInternalShareRequest(value: unknown) {
if (!isRecord(value) || value.mode !== "U")
throw new Error("URL Copy 요청은 mode를 U로 지정해 주세요.");
const realUrl = reportUrl(value.realUrl);
if (!realUrl) throw new Error("공유할 보고서 화면 경로를 확인해 주세요.");
return { realUrl, mode: "U" as const };
}
/** Adapt integration input to the existing report contract without coupling the parser to HTTP. */ /** Adapt integration input to the existing report contract without coupling the parser to HTTP. */
export function readInternalReportBatch(value: unknown) { export function readInternalReportBatch(value: unknown) {
@@ -19,13 +33,41 @@ export function readInternalReportBatch(value: unknown) {
); );
} }
/** Only the five approved integration operations; no arbitrary upstream forwarding. */ /** Fixed integration operations only; no arbitrary upstream forwarding. */
export function internalTarget(method: string, slug: string[]): Target | null { export function internalTarget(method: string, slug: string[]): Target | null {
const [area, ...parts] = slug; const [area, ...parts] = slug;
const path = "/" + slug.map(encodeURIComponent).join("/"); const path = "/" + slug.map(encodeURIComponent).join("/");
if (method === "GET" && area === "quota" && isQuotaListPath(parts)) if (method === "GET" && area === "quota" && isQuotaListPath(parts))
return { path, kind: "list" }; return { path, kind: "list" };
if (method !== "POST") return null; if (method !== "POST") return null;
if (
area === "project" &&
parts.length === 3 &&
parts[2] === "share" &&
isProjectReadPath([parts[0], parts[1], "question", "list"])
)
return { path, kind: "share" };
if (
area === "project" &&
parts.length === 6 &&
parts[2] === "derived" &&
parts[3] === "respondent" &&
parts[5] === "recalculate" &&
isProjectReadPath([parts[0], parts[1], "question", "list"])
) {
const id = parts[4];
if (
id.trim() &&
id.length <= 512 &&
id !== "." &&
id !== ".." &&
!/[\/\\]/.test(id) &&
!Array.from(id).some(
(char) => char.charCodeAt(0) < 32 || char.charCodeAt(0) === 127,
)
)
return { path, kind: "respondent" };
}
if (area === "project" && isReportStreamPath(parts)) if (area === "project" && isReportStreamPath(parts))
return { path, kind: "report" }; return { path, kind: "report" };
if (area === "quota" && isQuotaResultPath(parts)) if (area === "quota" && isQuotaResultPath(parts))