260506_01_fst: First Commit

This commit is contained in:
2026-05-06 17:00:45 +09:00
parent dd5cac3d78
commit 934a71e47a
76 changed files with 9488 additions and 222 deletions

View File

@@ -0,0 +1,128 @@
import { Security } from "@/lib/security";
import {clientEnv} from "@/lib/env.client";
type StorageValue = any; // 요청대로 any 유지
// --- 내부 헬퍼 함수들 ---
const getDecryptedValue = (value: string): StorageValue => {
try {
if (!value || value.trim() === "") {
return null;
}
const decryptValue = clientEnv.ENV ==="prod" ? Security.decryptBase64(value) : value;
if (!decryptValue || decryptValue.trim() === "") {
return null;
}
return JSON.parse(decryptValue);
} catch (error) {
// 손상된 데이터인 경우 null 반환
return null;
}
};
const getEncryptedValue = (value: StorageValue): string => {
const stringifyValue = JSON.stringify(value);
return clientEnv.ENV ==="prod" ? Security.encryptBase64(stringifyValue) : stringifyValue;
};
// --- LocalStorage 함수들 ---
export const setLocalStorage = (key: string, value: StorageValue): void => {
try {
const encryptValue = getEncryptedValue(value);
localStorage.setItem(key, encryptValue);
} catch (error) {
// 필요하면 로깅 추가
}
};
export const getLocalStorage = (key: string): StorageValue => {
try {
const encryptValue: string | null = localStorage.getItem(key);
if (encryptValue === null || encryptValue === "") {
return null;
}
let value: StorageValue = null;
try {
// 암호화된 값 복호화 시도
value = getDecryptedValue(encryptValue);
} catch (decryptError) {
// 복호화 실패 시 평문으로 파싱 시도 (fallback)
try {
value = JSON.parse(encryptValue);
} catch (fallbackError) {
// 완전히 실패한 경우 저장된 데이터 제거
localStorage.removeItem(key);
return null;
}
}
return value;
} catch (error) {
return null;
}
};
export const removeLocalStorage = (key: string): void => {
localStorage.removeItem(key);
};
export const clearLocalStorage = (): void => {
localStorage.clear();
};
// --- SessionStorage 함수들 ---
// 세션스토리지는 테스트/실제 서버 모두 암호화 없음
export const setSessionStorage = (key: string, value: StorageValue): void => {
try {
const encryptValue = getEncryptedValue(value);
sessionStorage.setItem(key, encryptValue);
} catch (error) {
// 필요하면 로깅 추가
}
};
export const getSessionStorage = (key: string): StorageValue => {
try {
const encryptValue: string | null = sessionStorage.getItem(key);
if (encryptValue === null || encryptValue === "") {
return null;
}
let value: StorageValue = null;
try {
// 암호화된 값 복호화 시도
value = getDecryptedValue(encryptValue);
} catch (decryptError) {
// 복호화 실패 시 평문으로 파싱 시도 (fallback)
try {
value = JSON.parse(encryptValue);
} catch (fallbackError) {
// 완전히 실패한 경우 저장된 데이터 제거
localStorage.removeItem(key);
return null;
}
}
return value;
} catch (error) {
return null;
}
};
export const removeSessionStorage = (key: string): void => {
sessionStorage.removeItem(key);
};
export const clearSessionStorage = (): void => {
sessionStorage.clear();
};