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

View File

@@ -3,12 +3,26 @@ import {
isQuotaListPath,
isQuotaResultPath,
isReportStreamPath,
isProjectReadPath,
} from "@/lib/project-proxy-policy";
import { isRecord, validDateRange } from "@/types/kart";
import { readReportBatch } from "@/lib/report-contract";
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. */
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 {
const [area, ...parts] = slug;
const path = "/" + slug.map(encodeURIComponent).join("/");
if (method === "GET" && area === "quota" && isQuotaListPath(parts))
return { path, kind: "list" };
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))
return { path, kind: "report" };
if (area === "quota" && isQuotaResultPath(parts))