visang-tracker 0.9.0 → 0.9.2

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.
@@ -0,0 +1,9 @@
1
+ declare const _default: {
2
+ log: {
3
+ sendTraceLog: (param: any) => Promise<unknown>;
4
+ };
5
+ };
6
+ export default _default;
7
+ export declare const LogApiUtil: {
8
+ post: <Res>(endpoint: string, data: any) => Promise<Res | undefined>;
9
+ };
@@ -1,61 +1,33 @@
1
- import axios, { AxiosResponse } from 'axios';
1
+ import axios from 'axios';
2
2
  import log from './log';
3
3
  import qs from 'qs';
4
-
5
4
  export default {
6
5
  log,
7
6
  };
8
-
9
7
  const url = {
10
8
  logApi: () => {
11
9
  return process.env.AIDT_LOG_URL;
12
10
  },
13
11
  };
14
-
15
- const getBaseUrl = (apiServer: ApiServerType) => {
12
+ const getBaseUrl = (apiServer) => {
16
13
  switch (apiServer) {
17
14
  default:
18
15
  case 'log':
19
16
  return url.logApi();
20
17
  }
21
18
  };
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> => {
19
+ const log_request = async (apiServer, method, endpoint, data) => {
40
20
  // AxiosResponse.data 반환
41
- const res = await _log_request<Res>(apiServer, method, endpoint, data);
42
- return res ? (res.data as Res) : undefined;
21
+ const res = await _log_request(apiServer, method, endpoint, data);
22
+ return res ? res.data : undefined;
43
23
  };
44
-
45
- const _log_request = async <Res>(
46
- apiServer: ApiServerType,
47
- method: MethodType,
48
- endpoint: string,
49
- data: any,
50
- ): Promise<AxiosResponse<Res> | undefined> => {
24
+ const _log_request = async (apiServer, method, endpoint, data) => {
51
25
  // AxiosResponse 반환
52
26
  const baseURL = getBaseUrl(apiServer);
53
-
54
- let headers: any = {
27
+ let headers = {
55
28
  'Content-Type': method == 'multipart' ? 'multipart/form-data' : 'application/json',
56
29
  accept: 'application/json',
57
30
  };
58
-
59
31
  const instance = axios.create({
60
32
  baseURL,
61
33
  headers,
@@ -75,42 +47,37 @@ const _log_request = async <Res>(
75
47
  },
76
48
  },
77
49
  });
78
- let axiosResponse: AxiosResponse<Res>;
79
-
50
+ let axiosResponse;
80
51
  try {
81
52
  switch (method) {
82
53
  case 'get':
83
- axiosResponse = await instance.get<Res>(endpoint, { params: data });
54
+ axiosResponse = await instance.get(endpoint, { params: data });
84
55
  break;
85
56
  case 'post':
86
57
  case 'multipart':
87
- axiosResponse = await instance.post<Res>(endpoint, data);
58
+ axiosResponse = await instance.post(endpoint, data);
88
59
  break;
89
60
  case 'put':
90
- axiosResponse = await instance.put<Res>(endpoint, data);
61
+ axiosResponse = await instance.put(endpoint, data);
91
62
  break;
92
63
  case 'delete':
93
- axiosResponse = await instance.delete<Res>(endpoint, { params: data });
64
+ axiosResponse = await instance.delete(endpoint, { params: data });
94
65
  break;
95
66
  }
96
-
97
67
  return axiosResponse;
98
- } catch (e) {
68
+ }
69
+ catch (e) {
99
70
  // commonUtil.log('[NAVI] api response exception', e);
100
71
  }
101
72
  };
102
-
103
73
  // const sendTraceLogAck=(hash)=>{
104
74
  // if(hash){
105
75
  // commonStore.sendTraceLogAck(hash)
106
76
  // }
107
77
  // }
108
-
109
78
  export const LogApiUtil = {
110
- post: async <Res>(endpoint: string, data: any): Promise<Res | undefined> =>
111
- log_request<Res>('log', 'post', endpoint, data),
79
+ post: async (endpoint, data) => log_request('log', 'post', endpoint, data),
112
80
  };
113
-
114
81
  // export const KerisMockupApiUtil = {
115
82
  // get: async <Res>(endpoint: string, data: any): Promise<Res | undefined> => axios_request<Res>('vcloudapi', "get", endpoint, data),
116
83
  // post: async <Res>(endpoint: string, data: any): Promise<Res | undefined> => axios_request<Res>('vcloudapi', "post", endpoint, data),
@@ -0,0 +1,4 @@
1
+ declare const _default: {
2
+ sendTraceLog: (param: any) => Promise<unknown>;
3
+ };
4
+ export default _default;
@@ -1,7 +1,6 @@
1
1
  import { LogApiUtil } from '../index';
2
-
3
2
  export default {
4
- sendTraceLog: async (param: any) => {
3
+ sendTraceLog: async (param) => {
5
4
  return LogApiUtil.post('/logs/sendTraceLog', param);
6
5
  },
7
6
  };
@@ -0,0 +1,3 @@
1
+ declare const sendTraceLogDebug: (errorLog: any) => void;
2
+ declare const initLog: () => void;
3
+ export { sendTraceLogDebug, initLog };
@@ -1,15 +1,10 @@
1
1
  import api from '../src/api';
2
-
3
- type TraceLogItem = Record<string, any>;
4
-
5
2
  const LOG_BATCH_MAX = 20;
6
3
  const LOG_FLUSH_INTERVAL_MS = 10000;
7
4
  const LOG_STORAGE_KEY = 'aidt_trace_log_queue_v1';
8
-
9
- let logQueue: TraceLogItem[] = [];
10
- let flushTimerId: number | null = null;
5
+ let logQueue = [];
6
+ let flushTimerId = null;
11
7
  let isFlushing = false;
12
-
13
8
  try {
14
9
  const saved = localStorage.getItem(LOG_STORAGE_KEY);
15
10
  if (saved) {
@@ -18,31 +13,31 @@ try {
18
13
  logQueue = parsed;
19
14
  }
20
15
  }
21
- } catch (e) {
16
+ }
17
+ catch (e) {
22
18
  console.log(e);
23
19
  }
24
-
25
20
  const persistQueue = () => {
26
21
  try {
27
22
  localStorage.setItem(LOG_STORAGE_KEY, JSON.stringify(logQueue));
28
- } catch {
23
+ }
24
+ catch {
29
25
  /* storage may be full or unavailable */
30
26
  }
31
27
  };
32
-
33
- const transportBatch = async (batch: TraceLogItem[]) => {
28
+ const transportBatch = async (batch) => {
34
29
  // Prefer bulk endpoint if provided by api.log
35
- const maybeBulk = (api as any)?.log?.sendTraceLogs;
30
+ const maybeBulk = api?.log?.sendTraceLogs;
36
31
  if (typeof maybeBulk === 'function') {
37
32
  return maybeBulk(batch);
38
33
  }
39
34
  await api.log.sendTraceLog(batch);
40
35
  };
41
-
42
36
  const flushLogQueue = async () => {
43
- if (isFlushing) return;
44
- if (logQueue.length === 0) return;
45
-
37
+ if (isFlushing)
38
+ return;
39
+ if (logQueue.length === 0)
40
+ return;
46
41
  isFlushing = true;
47
42
  try {
48
43
  while (logQueue.length > 0) {
@@ -50,39 +45,35 @@ const flushLogQueue = async () => {
50
45
  await transportBatch(batch);
51
46
  persistQueue();
52
47
  }
53
- } finally {
48
+ }
49
+ finally {
54
50
  isFlushing = false;
55
51
  }
56
52
  };
57
-
58
53
  const scheduleFlush = () => {
59
- if (flushTimerId != null) return;
54
+ if (flushTimerId != null)
55
+ return;
60
56
  flushTimerId = window.setInterval(() => {
61
57
  if (document.visibilityState === 'visible') {
62
58
  flushLogQueue();
63
59
  }
64
60
  }, LOG_FLUSH_INTERVAL_MS);
65
61
  };
66
-
67
- const enqueueTraceLog = (item: TraceLogItem) => {
62
+ const enqueueTraceLog = (item) => {
68
63
  logQueue.push(item);
69
64
  persistQueue();
70
-
71
65
  if (logQueue.length >= LOG_BATCH_MAX) {
72
66
  flushLogQueue();
73
- } else {
67
+ }
68
+ else {
74
69
  scheduleFlush();
75
70
  }
76
71
  };
77
-
78
72
  window.addEventListener('visibilitychange', () => {
79
73
  flushLogQueue();
80
74
  });
81
-
82
- const sendTraceLogDebug = (errorLog: any) => {
75
+ const sendTraceLogDebug = (errorLog) => {
83
76
  enqueueTraceLog(errorLog);
84
77
  };
85
-
86
- const initLog = () => {};
87
-
78
+ const initLog = () => { };
88
79
  export { sendTraceLogDebug, initLog };
package/package.json CHANGED
@@ -1,8 +1,19 @@
1
1
  {
2
2
  "name": "visang-tracker",
3
- "version": "0.9.0",
3
+ "version": "0.9.2",
4
4
  "description": "Lightweight logging and tracking helper for Visang apps.",
5
- "main": "index.js",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "import": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
6
17
  "scripts": {
7
18
  "build": "tsc",
8
19
  "prepare": "npm run build"
package/.prettierignore DELETED
@@ -1 +0,0 @@
1
- *.css
package/.prettierrc DELETED
@@ -1,10 +0,0 @@
1
- {
2
- "singleQuote": true,
3
- "semi": true,
4
- "tabWidth": 4,
5
- "trailingComma": "all",
6
- "printWidth": 100,
7
- "arrowParens": "avoid",
8
- "endOfLine": "auto",
9
- "bracketSpacing": true
10
- }
package/tsconfig.json DELETED
@@ -1,13 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2020",
4
- "module": "ESNext",
5
- "declaration": true,
6
- "outDir": "dist",
7
- "strict": true,
8
- "esModuleInterop": true,
9
- "moduleResolution": "node",
10
- "skipLibCheck": true
11
- },
12
- "include": ["src"]
13
- }