visang-tracker 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierignore +1 -0
- package/.prettierrc +10 -0
- package/README.md +3 -0
- package/package.json +31 -0
- package/src/api/index.ts +119 -0
- package/src/api/log/index.ts +7 -0
- package/src/index.ts +91 -0
- package/tsconfig.json +13 -0
package/.prettierignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
*.css
|
package/.prettierrc
ADDED
package/README.md
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "visang-tracker",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "tsc",
|
|
8
|
+
"prepare": "npm run build"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [],
|
|
11
|
+
"author": "",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"@types/node": "^22.14.1",
|
|
15
|
+
"@types/qs": "^6.14.0",
|
|
16
|
+
"@typescript-eslint/eslint-plugin": "^8.46.2",
|
|
17
|
+
"@typescript-eslint/parser": "^8.46.2",
|
|
18
|
+
"eslint": "^9.38.0",
|
|
19
|
+
"eslint-config-prettier": "^10.1.8",
|
|
20
|
+
"eslint-plugin-react": "^7.37.5",
|
|
21
|
+
"eslint-plugin-react-hooks": "^7.0.0",
|
|
22
|
+
"prettier": "^3.6.2",
|
|
23
|
+
"typescript": "^5.8.3"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"axios": "^1.12.2",
|
|
27
|
+
"googleapis": "^148.0.0",
|
|
28
|
+
"qs": "^6.14.0",
|
|
29
|
+
"url": "^0.11.4"
|
|
30
|
+
}
|
|
31
|
+
}
|
package/src/api/index.ts
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import axios, { AxiosResponse } from 'axios';
|
|
2
|
+
import log from './log';
|
|
3
|
+
import qs from 'qs';
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
log,
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const url = {
|
|
10
|
+
logApi: () => {
|
|
11
|
+
return process.env.AIDT_LOG_URL;
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const getBaseUrl = (apiServer: ApiServerType) => {
|
|
16
|
+
switch (apiServer) {
|
|
17
|
+
default:
|
|
18
|
+
case 'log':
|
|
19
|
+
return url.logApi();
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
type ApiServerType =
|
|
24
|
+
| 'vcloudapi'
|
|
25
|
+
| 'lcmsapi'
|
|
26
|
+
| 'medianaviapi'
|
|
27
|
+
| 'tutorus'
|
|
28
|
+
| 'keris'
|
|
29
|
+
| 'nats'
|
|
30
|
+
| 'aidtoperation'
|
|
31
|
+
| 'log';
|
|
32
|
+
type MethodType = 'get' | 'put' | 'post' | 'delete' | 'multipart';
|
|
33
|
+
|
|
34
|
+
const log_request = async <Res>(
|
|
35
|
+
apiServer: ApiServerType,
|
|
36
|
+
method: MethodType,
|
|
37
|
+
endpoint: string,
|
|
38
|
+
data: any,
|
|
39
|
+
): Promise<Res | undefined> => {
|
|
40
|
+
// AxiosResponse.data 반환
|
|
41
|
+
const res = await _log_request<Res>(apiServer, method, endpoint, data);
|
|
42
|
+
return res ? (res.data as Res) : undefined;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const _log_request = async <Res>(
|
|
46
|
+
apiServer: ApiServerType,
|
|
47
|
+
method: MethodType,
|
|
48
|
+
endpoint: string,
|
|
49
|
+
data: any,
|
|
50
|
+
): Promise<AxiosResponse<Res> | undefined> => {
|
|
51
|
+
// AxiosResponse 반환
|
|
52
|
+
const baseURL = getBaseUrl(apiServer);
|
|
53
|
+
|
|
54
|
+
let headers: any = {
|
|
55
|
+
'Content-Type': method == 'multipart' ? 'multipart/form-data' : 'application/json',
|
|
56
|
+
accept: 'application/json',
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const instance = axios.create({
|
|
60
|
+
baseURL,
|
|
61
|
+
headers,
|
|
62
|
+
paramsSerializer: {
|
|
63
|
+
encode: val => {
|
|
64
|
+
return encodeURIComponent(val)
|
|
65
|
+
.replace(/%40/gi, '@')
|
|
66
|
+
.replace(/%3A/gi, ':')
|
|
67
|
+
.replace(/%24/g, '$')
|
|
68
|
+
.replace(/%2C/gi, ',')
|
|
69
|
+
.replace(/%20/g, '+')
|
|
70
|
+
.replace(/%5B/gi, '[')
|
|
71
|
+
.replace(/%5D/gi, ']');
|
|
72
|
+
},
|
|
73
|
+
serialize: params => {
|
|
74
|
+
return qs.stringify(params, { arrayFormat: 'brackets' });
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
let axiosResponse: AxiosResponse<Res>;
|
|
79
|
+
|
|
80
|
+
try {
|
|
81
|
+
switch (method) {
|
|
82
|
+
case 'get':
|
|
83
|
+
axiosResponse = await instance.get<Res>(endpoint, { params: data });
|
|
84
|
+
break;
|
|
85
|
+
case 'post':
|
|
86
|
+
case 'multipart':
|
|
87
|
+
axiosResponse = await instance.post<Res>(endpoint, data);
|
|
88
|
+
break;
|
|
89
|
+
case 'put':
|
|
90
|
+
axiosResponse = await instance.put<Res>(endpoint, data);
|
|
91
|
+
break;
|
|
92
|
+
case 'delete':
|
|
93
|
+
axiosResponse = await instance.delete<Res>(endpoint, { params: data });
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return axiosResponse;
|
|
98
|
+
} catch (e) {
|
|
99
|
+
// commonUtil.log('[NAVI] api response exception', e);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
// const sendTraceLogAck=(hash)=>{
|
|
104
|
+
// if(hash){
|
|
105
|
+
// commonStore.sendTraceLogAck(hash)
|
|
106
|
+
// }
|
|
107
|
+
// }
|
|
108
|
+
|
|
109
|
+
export const LogApiUtil = {
|
|
110
|
+
post: async <Res>(endpoint: string, data: any): Promise<Res | undefined> =>
|
|
111
|
+
log_request<Res>('log', 'post', endpoint, data),
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
// export const KerisMockupApiUtil = {
|
|
115
|
+
// get: async <Res>(endpoint: string, data: any): Promise<Res | undefined> => axios_request<Res>('vcloudapi', "get", endpoint, data),
|
|
116
|
+
// post: async <Res>(endpoint: string, data: any): Promise<Res | undefined> => axios_request<Res>('vcloudapi', "post", endpoint, data),
|
|
117
|
+
// put: async <Res>(endpoint: string, data: any): Promise<Res | undefined> => axios_request<Res>('vcloudapi', "put", endpoint, data),
|
|
118
|
+
// delete: async <Res>(endpoint: string, data: any): Promise<Res | undefined> => axios_request<Res>('vcloudapi', "delete", endpoint, data),
|
|
119
|
+
// }
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import api from '../src/api';
|
|
2
|
+
|
|
3
|
+
type TraceLogItem = Record<string, any>;
|
|
4
|
+
|
|
5
|
+
const LOG_BATCH_MAX = 20;
|
|
6
|
+
const LOG_FLUSH_INTERVAL_MS = 10000;
|
|
7
|
+
const LOG_STORAGE_KEY = 'aidt_trace_log_queue_v1';
|
|
8
|
+
|
|
9
|
+
let logQueue: TraceLogItem[] = [];
|
|
10
|
+
let flushTimerId: number | null = null;
|
|
11
|
+
let isFlushing = false;
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
const saved = localStorage.getItem(LOG_STORAGE_KEY);
|
|
15
|
+
if (saved) {
|
|
16
|
+
const parsed = JSON.parse(saved);
|
|
17
|
+
if (Array.isArray(parsed)) {
|
|
18
|
+
logQueue = parsed;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
} catch (e) {
|
|
22
|
+
console.log(e);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function initLog() {}
|
|
26
|
+
|
|
27
|
+
const persistQueue = () => {
|
|
28
|
+
try {
|
|
29
|
+
localStorage.setItem(LOG_STORAGE_KEY, JSON.stringify(logQueue));
|
|
30
|
+
} catch {
|
|
31
|
+
/* storage may be full or unavailable */
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const transportBatch = async (batch: TraceLogItem[]) => {
|
|
36
|
+
// Prefer bulk endpoint if provided by api.log
|
|
37
|
+
const maybeBulk = (api as any)?.log?.sendTraceLogs;
|
|
38
|
+
if (typeof maybeBulk === 'function') {
|
|
39
|
+
return maybeBulk(batch);
|
|
40
|
+
}
|
|
41
|
+
await api.log.sendTraceLog(batch);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const flushLogQueue = async () => {
|
|
45
|
+
if (isFlushing) return;
|
|
46
|
+
if (logQueue.length === 0) return;
|
|
47
|
+
|
|
48
|
+
isFlushing = true;
|
|
49
|
+
try {
|
|
50
|
+
while (logQueue.length > 0) {
|
|
51
|
+
const batch = logQueue.splice(0, LOG_BATCH_MAX);
|
|
52
|
+
await transportBatch(batch);
|
|
53
|
+
persistQueue();
|
|
54
|
+
}
|
|
55
|
+
} finally {
|
|
56
|
+
isFlushing = false;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const scheduleFlush = () => {
|
|
61
|
+
if (flushTimerId != null) return;
|
|
62
|
+
flushTimerId = window.setInterval(() => {
|
|
63
|
+
if (document.visibilityState === 'visible') {
|
|
64
|
+
flushLogQueue();
|
|
65
|
+
}
|
|
66
|
+
}, LOG_FLUSH_INTERVAL_MS);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const enqueueTraceLog = (item: TraceLogItem) => {
|
|
70
|
+
logQueue.push(item);
|
|
71
|
+
persistQueue();
|
|
72
|
+
|
|
73
|
+
if (logQueue.length >= LOG_BATCH_MAX) {
|
|
74
|
+
flushLogQueue();
|
|
75
|
+
} else {
|
|
76
|
+
scheduleFlush();
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
window.addEventListener('visibilitychange', () => {
|
|
81
|
+
flushLogQueue();
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
const sendTraceLogDebug = (errorLog: any) => {
|
|
85
|
+
enqueueTraceLog(errorLog);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export default {
|
|
89
|
+
initLog,
|
|
90
|
+
sendTraceLogDebug,
|
|
91
|
+
};
|
package/tsconfig.json
ADDED