From 6e03bbad660cf62c89e6a6fb798866f6666851cb Mon Sep 17 00:00:00 2001 From: hanna Date: Tue, 27 Feb 2024 15:43:55 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20version=20=ED=95=84=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20=EB=B0=8F=20Type=20=EB=B3=80=EA=B2=BD=20(#?= =?UTF-8?q?33)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .eslintrc.cjs | 1 + src/LogParamsProvider.ts | 3 --- src/Logger.ts | 45 ++++++++++++++---------------------- src/SetLocalStorage.ts | 6 +++-- src/apis/customedAxios.ts | 2 -- src/apis/postLog.ts | 6 ++--- src/components/LogClick.tsx | 4 ---- src/components/LogScreen.tsx | 4 ---- src/demo/Drawer.tsx | 15 ++++++++---- src/demo/Home.tsx | 15 ++++++++---- src/types/LogType.ts | 34 +++++++++++++-------------- 11 files changed, 61 insertions(+), 74 deletions(-) delete mode 100644 src/LogParamsProvider.ts diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 51ff6c1..6d7b0ef 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -21,6 +21,7 @@ module.exports = { 'react-refresh/only-export-components': ['warn', { allowConstantExport: true }], 'prettier/prettier': ['error', { endOfLine: 'auto' }], 'react/react-in-jsx-scope': 'off', + '@typescript-eslint/no-explicit-any': 'off', }, settings: { 'import/resolver': { diff --git a/src/LogParamsProvider.ts b/src/LogParamsProvider.ts deleted file mode 100644 index 32f9b3f..0000000 --- a/src/LogParamsProvider.ts +++ /dev/null @@ -1,3 +0,0 @@ -// import { createContext } from 'react'; - -// const LogParamsContext = createContext(null); diff --git a/src/Logger.ts b/src/Logger.ts index ab15452..eaceaf7 100644 --- a/src/Logger.ts +++ b/src/Logger.ts @@ -1,5 +1,5 @@ import { SetLocalStorage, SetLocalStorageClear } from './SetLocalStorage'; -import { LogPayloadParams, LogType, ServiceNameType } from './types/LogType'; +import { LogPayloadParams, LogType } from './types/LogType'; import CryptoJS from 'crypto-js'; import { postLog } from './apis/postLog'; @@ -17,7 +17,7 @@ const createRandomId = () => { return randomId; }; -const createHashedId = (userId: string) => { +const createHashedID = (userId: string) => { let hashedId = ''; let localHashedId = ''; const existLocalHashedId = window.localStorage.getItem('yls-web'); @@ -39,35 +39,25 @@ const createTimestamp = () => { return now.toISOString(); }; -const initialLog = ( - userId: string, - serviceName: ServiceNameType, - name: string, - path: string | undefined -) => { +const initialLog = (userId: string, version: number, event: LogPayloadParams['event']) => { const loggerType: LogPayloadParams = { userId: userId, - path: '/', - serviceName: serviceName, - name: '', - message: '', + version: version, + event: event, }; const logger = Logger(loggerType); - logger.event.name = name; - logger.event.path = path; - SetLocalStorage(logger); }; export const useYLSLogger = () => { - const screen = ({ userId, serviceName, name, path }: LogPayloadParams) => { - initialLog(userId, serviceName, name, path); + const screen = ({ userId, version, event }: LogPayloadParams) => { + initialLog(userId, version, event); }; - const click = ({ userId, serviceName, name, path }: LogPayloadParams) => { - initialLog(userId, serviceName, name, path); + const click = ({ userId, version, event }: LogPayloadParams) => { + initialLog(userId, version, event); }; return { @@ -76,17 +66,14 @@ export const useYLSLogger = () => { }; }; -export const Logger = ({ userId, serviceName, name, message, path, tags }: LogPayloadParams) => { +export const Logger = ({ userId, version, event }: LogPayloadParams) => { return { - hashedId: createHashedId(userId), + hashedID: createHashedID(userId), timestamp: createTimestamp(), + version: version, event: { platform: 'web', - serviceName, - name, - message, - path, - tags, + ...event, }, }; }; @@ -95,6 +82,8 @@ window.addEventListener('unload', async (event) => { event.preventDefault(); const logList: LogType[] = JSON.parse(localStorage.getItem('yls-web') as string) || []; - const res = await postLog(logList); - SetLocalStorageClear(); + const res = await postLog([{ logRequestList: logList }]); + if (res.success) { + SetLocalStorageClear(); + } }); diff --git a/src/SetLocalStorage.ts b/src/SetLocalStorage.ts index c020071..477acb7 100644 --- a/src/SetLocalStorage.ts +++ b/src/SetLocalStorage.ts @@ -17,8 +17,10 @@ export const SetLocalStorage = async (logger: LogType) => { const updateList = [...remainList, logger]; localStorage.setItem('yls-web', JSON.stringify(updateList)); } else { - SetLocalStorageClear(); - const res = await postLog(); + const res = await postLog(remainList); + if (res.success) { + SetLocalStorageClear(); + } } } }; diff --git a/src/apis/customedAxios.ts b/src/apis/customedAxios.ts index 362c3d2..2abdbe4 100644 --- a/src/apis/customedAxios.ts +++ b/src/apis/customedAxios.ts @@ -7,5 +7,3 @@ export const customedAxios = axios.create({ withCredentials: true, }, }); - -export default customedAxios; diff --git a/src/apis/postLog.ts b/src/apis/postLog.ts index 5092da0..1a097ce 100644 --- a/src/apis/postLog.ts +++ b/src/apis/postLog.ts @@ -1,7 +1,7 @@ -import { LogType } from '../types/LogType'; -import customedAxios from './customedAxios'; +import { LogRequestList, LogResponse } from '../types/LogType'; +import { customedAxios } from './customedAxios'; -export const postLog = async (data: LogType[]) => { +export const postLog = async (data: LogRequestList[]): Promise => { const res = await customedAxios.put('/log/list', data); return res.data; }; diff --git a/src/components/LogClick.tsx b/src/components/LogClick.tsx index 5a91dca..a2444c6 100644 --- a/src/components/LogClick.tsx +++ b/src/components/LogClick.tsx @@ -10,14 +10,10 @@ interface Props { export const LogClick = ({ children, params }: Props) => { const logger = useYLSLogger(); const child = Children.only(children); - let path = params.path; - - if (!params.path) path = window.location.pathname; return cloneElement(child, { onClick: (...args: any[]) => { logger.click({ - path: path, ...params, }); diff --git a/src/components/LogScreen.tsx b/src/components/LogScreen.tsx index 4cb45df..36ed645 100644 --- a/src/components/LogScreen.tsx +++ b/src/components/LogScreen.tsx @@ -9,13 +9,9 @@ interface Props { export const LogScreen = ({ children, params }: Props) => { const logger = useYLSLogger(); - let path = params.path; - - if (!params.path) path = window.location.pathname; useEffect(() => { logger.screen({ - path: path, ...params, }); }, []); diff --git a/src/demo/Drawer.tsx b/src/demo/Drawer.tsx index 08d1a45..44b96e6 100644 --- a/src/demo/Drawer.tsx +++ b/src/demo/Drawer.tsx @@ -13,17 +13,22 @@ export const Drawer = () => {
diff --git a/src/demo/Home.tsx b/src/demo/Home.tsx index fd0a75a..fbb419a 100644 --- a/src/demo/Home.tsx +++ b/src/demo/Home.tsx @@ -13,17 +13,22 @@ export const Home = () => {
diff --git a/src/types/LogType.ts b/src/types/LogType.ts index 218f37f..00df42f 100644 --- a/src/types/LogType.ts +++ b/src/types/LogType.ts @@ -1,25 +1,23 @@ -export type ServiceNameType = 'drawer' | 'home' | 'search'; +// LogPayloadParams: 사용처에서 넣어주는 값 +export interface LogPayloadParams { + userId: string; + version: number; + event: any; +} // LogType: 최종 Log 형태 export interface LogType { - hashedId: string; + hashedID: string; timestamp: string; - event: { - platform: string; - serviceName: ServiceNameType; - name: string; - message?: string; - path?: string; - tags?: string[]; - }; + version: number; + event: LogPayloadParams['event']; } -// LogPayloadParams: 사용처에서 넣어주는 값 -export interface LogPayloadParams { - userId: string; - name: string | ''; - serviceName: ServiceNameType; - message?: string; - path?: string; - tags?: string[]; +export interface LogRequestList { + logRequestList: LogType[]; +} + +export interface LogResponse { + success: boolean; + result: { [key: string]: any }; }