@uniai-fe/uds-templates 0.6.16 → 0.6.18
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/LICENSE +27 -0
- package/package.json +1 -1
- package/src/cctv/apis/server.ts +12 -4
- package/src/cctv/types/api.ts +8 -3
- package/src/service-inquiry/hooks/useNetworkError.ts +3 -2
- package/src/service-inquiry/utils/network-debug.ts +18 -5
- package/src/service-inquiry/utils/redaction.ts +113 -0
- package/src/weather/_legacy/types/api.ts +4 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 UNIAI
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
This project includes third-party software governed by additional licenses,
|
|
26
|
+
including Apache License 2.0. Refer to `THIRD_PARTY_NOTICES.md` for the full
|
|
27
|
+
text of those notices and any required attributions.
|
package/package.json
CHANGED
package/src/cctv/apis/server.ts
CHANGED
|
@@ -206,6 +206,7 @@ export async function getServerCctvToken({
|
|
|
206
206
|
queryUrl,
|
|
207
207
|
req,
|
|
208
208
|
headers,
|
|
209
|
+
tokenPreset,
|
|
209
210
|
}: API_Req_GetCctvTokenParams): Promise<{
|
|
210
211
|
res: API_Res_CctvRtcToken;
|
|
211
212
|
domain: string;
|
|
@@ -224,7 +225,15 @@ export async function getServerCctvToken({
|
|
|
224
225
|
token: "",
|
|
225
226
|
};
|
|
226
227
|
|
|
227
|
-
|
|
228
|
+
const password = reqBody?.password || tokenPreset?.password || "";
|
|
229
|
+
|
|
230
|
+
if (
|
|
231
|
+
!reqBody ||
|
|
232
|
+
!reqBody.username ||
|
|
233
|
+
!reqBody.company_id ||
|
|
234
|
+
!reqBody.cam_id ||
|
|
235
|
+
!password
|
|
236
|
+
) {
|
|
228
237
|
nextAPILog("POST", routeUrl, query_url, { reqBody });
|
|
229
238
|
return {
|
|
230
239
|
res: alternateResponse,
|
|
@@ -240,7 +249,6 @@ export async function getServerCctvToken({
|
|
|
240
249
|
? `farm${reqBody.company_id}`
|
|
241
250
|
: String(reqBody.company_id);
|
|
242
251
|
const username = reqBody.username;
|
|
243
|
-
const password = reqBody.password || reqBody.username;
|
|
244
252
|
const path = !isNaN(Number(reqBody.cam_id))
|
|
245
253
|
? `cam${reqBody.cam_id}`
|
|
246
254
|
: String(reqBody.cam_id);
|
|
@@ -252,8 +260,8 @@ export async function getServerCctvToken({
|
|
|
252
260
|
password,
|
|
253
261
|
action: "read",
|
|
254
262
|
path,
|
|
255
|
-
ttl_seconds: 3600,
|
|
256
|
-
kid: "streaming-auth-1",
|
|
263
|
+
ttl_seconds: tokenPreset?.ttl_seconds ?? 3600,
|
|
264
|
+
kid: tokenPreset?.kid ?? "streaming-auth-1",
|
|
257
265
|
};
|
|
258
266
|
|
|
259
267
|
nextAPILog("POST", routeUrl, query_url, { bodyData });
|
package/src/cctv/types/api.ts
CHANGED
|
@@ -298,6 +298,7 @@ export type API_Res_CctvCompany = API_Res_Base<API_Res_CctvCompanyData>;
|
|
|
298
298
|
* @property {string} company_id 업체 id코드
|
|
299
299
|
* @property {string} cam_id 카메라 id코드
|
|
300
300
|
* @property {string} username 사용자 계정 아이디
|
|
301
|
+
* @property {string} [password] 사용자 계정 비밀번호. 서버 route에서 tokenPreset.password를 주입하는 경우 생략 가능
|
|
301
302
|
*/
|
|
302
303
|
export interface API_Req_CctvRtcToken {
|
|
303
304
|
/**
|
|
@@ -314,6 +315,7 @@ export interface API_Req_CctvRtcToken {
|
|
|
314
315
|
username: string;
|
|
315
316
|
/**
|
|
316
317
|
* 사용자 계정 비밀번호
|
|
318
|
+
* - 서버 route에서 tokenPreset.password를 주입하는 경우 생략 가능
|
|
317
319
|
*/
|
|
318
320
|
password?: string;
|
|
319
321
|
}
|
|
@@ -322,7 +324,7 @@ export interface API_Req_CctvRtcToken {
|
|
|
322
324
|
* CCTV; 실시간 스트리밍 토큰 요청 (백엔드 요청)
|
|
323
325
|
* @property {string} site company_id 맵핑 (ex. farm102)
|
|
324
326
|
* @property {string} username 사용자 계정 아이디
|
|
325
|
-
* @property {string} password 사용자 계정 비밀번호
|
|
327
|
+
* @property {string} password 사용자 계정 비밀번호
|
|
326
328
|
* @property {string} action "read"
|
|
327
329
|
* @property {string} path cam_id 맵핑 (ex. cam3)
|
|
328
330
|
* @property {number} ttl_seconds 시간? (default 3600)
|
|
@@ -340,7 +342,6 @@ export interface API_Req_CctvRtcTokenOrigin {
|
|
|
340
342
|
username: string;
|
|
341
343
|
/**
|
|
342
344
|
* 사용자 계정 비밀번호
|
|
343
|
-
* - 대체로 계정 아이디 맵핑
|
|
344
345
|
*/
|
|
345
346
|
password: string;
|
|
346
347
|
/**
|
|
@@ -419,7 +420,7 @@ export interface API_Req_CctvStreamToken {
|
|
|
419
420
|
* @property {string} username 사용자 아이디
|
|
420
421
|
* @property {string} company_id 업체 id코드(site)
|
|
421
422
|
* @property {string} cam_id 카메라 id코드
|
|
422
|
-
* @property {string} [password]
|
|
423
|
+
* @property {string} [password] 서버 route에서 주입할 사용자 비밀번호
|
|
423
424
|
* @property {number} [ttl_seconds] 토큰 만료시간
|
|
424
425
|
* @property {string} [kid] 키 id
|
|
425
426
|
* @property {Record<string, string>} [headers] 추가 요청 헤더
|
|
@@ -449,4 +450,8 @@ export interface API_Req_GetCctvTokenParams {
|
|
|
449
450
|
* 추가 요청 헤더
|
|
450
451
|
*/
|
|
451
452
|
headers?: Record<string, string>;
|
|
453
|
+
/**
|
|
454
|
+
* 서버 route에서 주입할 CCTV 토큰 요청 preset
|
|
455
|
+
*/
|
|
456
|
+
tokenPreset?: API_Req_CctvTokenPreset;
|
|
452
457
|
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { useCallback } from "react";
|
|
4
4
|
import { useAtom } from "jotai";
|
|
5
5
|
import { serviceInquiryNetworkErrorsAtom } from "../jotai";
|
|
6
|
+
import { redactServiceInquiryNetworkError } from "../utils/redaction";
|
|
6
7
|
import type {
|
|
7
8
|
ServiceInquiryNetworkError,
|
|
8
9
|
UseServiceInquiryNetworkErrorReturn,
|
|
@@ -26,10 +27,10 @@ export function useServiceInquiryNetworkError(): UseServiceInquiryNetworkErrorRe
|
|
|
26
27
|
(nextError: ServiceInquiryNetworkError) => {
|
|
27
28
|
setNetworkErrors(currentErrors =>
|
|
28
29
|
[
|
|
29
|
-
{
|
|
30
|
+
redactServiceInquiryNetworkError({
|
|
30
31
|
...nextError,
|
|
31
32
|
timestamp: nextError.timestamp ?? new Date().toISOString(),
|
|
32
|
-
},
|
|
33
|
+
}),
|
|
33
34
|
...currentErrors,
|
|
34
35
|
].slice(0, 5),
|
|
35
36
|
);
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import type { ServiceInquiryNetworkErrorHeaders } from "../types";
|
|
2
|
+
import { redactServiceInquiryText } from "./redaction";
|
|
3
|
+
|
|
4
|
+
const redactServiceInquiryHeader = (
|
|
5
|
+
value: string | null,
|
|
6
|
+
): string | undefined =>
|
|
7
|
+
typeof value === "string" ? redactServiceInquiryText(value) : undefined;
|
|
2
8
|
|
|
3
9
|
/**
|
|
4
10
|
* Service Inquiry Utility; Authorization 헤더 존재 여부 판별
|
|
@@ -34,11 +40,18 @@ const pickServiceInquiryDebugHeaders = (
|
|
|
34
40
|
requestHeaders?: HeadersInit,
|
|
35
41
|
): ServiceInquiryNetworkErrorHeaders | undefined => {
|
|
36
42
|
const headers: ServiceInquiryNetworkErrorHeaders = {
|
|
37
|
-
uniai_native_domain:
|
|
38
|
-
responseHeaders.get("Uniai-Native-Domain")
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
43
|
+
uniai_native_domain: redactServiceInquiryHeader(
|
|
44
|
+
responseHeaders.get("Uniai-Native-Domain"),
|
|
45
|
+
),
|
|
46
|
+
uniai_native_path: redactServiceInquiryHeader(
|
|
47
|
+
responseHeaders.get("Uniai-Native-Path"),
|
|
48
|
+
),
|
|
49
|
+
uniai_native_url: redactServiceInquiryHeader(
|
|
50
|
+
responseHeaders.get("Uniai-Native-URL"),
|
|
51
|
+
),
|
|
52
|
+
content_type: redactServiceInquiryHeader(
|
|
53
|
+
responseHeaders.get("content-type"),
|
|
54
|
+
),
|
|
42
55
|
has_authorization: resolveServiceInquiryHasAuthorization(requestHeaders),
|
|
43
56
|
};
|
|
44
57
|
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import type { ServiceInquiryNetworkError } from "../types";
|
|
2
|
+
|
|
3
|
+
const REDACTED_SERVICE_INQUIRY_VALUE = "[REDACTED]";
|
|
4
|
+
const SERVICE_INQUIRY_SENSITIVE_KEY_PATTERN =
|
|
5
|
+
/authorization|cookie|token|password|passwd|pwd|secret|api[-_]?key|service[-_]?key|auth[-_]?key|request[-_]?body|response[-_]?body|bodydata|\bbody\b|contact|email|phone|farm[-_]?name|text|user[-_]?context/i;
|
|
6
|
+
const SERVICE_INQUIRY_SENSITIVE_QUERY_KEY_PATTERN =
|
|
7
|
+
/^(authorization|cookie|token|password|passwd|pwd|secret|api[-_]?key|service[-_]?key|auth[-_]?key|key|contact|email|phone)$/i;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Service Inquiry Utility; 문자열 내 민감 토큰 redaction
|
|
11
|
+
* @util
|
|
12
|
+
* @param {string} value redaction 대상 문자열
|
|
13
|
+
* @returns {string} 민감 query/token 값이 제거된 문자열
|
|
14
|
+
* @example
|
|
15
|
+
* redactServiceInquiryText("/api?token=abc");
|
|
16
|
+
*/
|
|
17
|
+
export function redactServiceInquiryText(value: string): string {
|
|
18
|
+
const redactedBearer = value.replace(
|
|
19
|
+
/(Bearer\s+)[^\s"',]+/gi,
|
|
20
|
+
`$1${REDACTED_SERVICE_INQUIRY_VALUE}`,
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
try {
|
|
24
|
+
const url = new URL(redactedBearer);
|
|
25
|
+
url.searchParams.forEach((_, key) => {
|
|
26
|
+
if (SERVICE_INQUIRY_SENSITIVE_QUERY_KEY_PATTERN.test(key)) {
|
|
27
|
+
url.searchParams.set(key, REDACTED_SERVICE_INQUIRY_VALUE);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
return url.toString();
|
|
31
|
+
} catch {
|
|
32
|
+
return redactedBearer.replace(
|
|
33
|
+
/([?&](?:authorization|cookie|token|password|passwd|pwd|secret|api[-_]?key|service[-_]?key|auth[-_]?key|key|contact|email|phone)=)[^&#\s"']+/gi,
|
|
34
|
+
`$1${REDACTED_SERVICE_INQUIRY_VALUE}`,
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Service Inquiry Utility; 객체/배열/Headers/Error redaction
|
|
41
|
+
* @util
|
|
42
|
+
* @param {unknown} value redaction 대상 값
|
|
43
|
+
* @param {string} [key] 현재 객체 key
|
|
44
|
+
* @returns {unknown} 민감 field가 제거된 값
|
|
45
|
+
* @example
|
|
46
|
+
* redactServiceInquiryValue({ request_body: { password: "secret" } });
|
|
47
|
+
*/
|
|
48
|
+
export function redactServiceInquiryValue(
|
|
49
|
+
value: unknown,
|
|
50
|
+
key?: string,
|
|
51
|
+
seen = new WeakSet<object>(),
|
|
52
|
+
): unknown {
|
|
53
|
+
if (
|
|
54
|
+
typeof key === "string" &&
|
|
55
|
+
SERVICE_INQUIRY_SENSITIVE_KEY_PATTERN.test(key)
|
|
56
|
+
) {
|
|
57
|
+
return REDACTED_SERVICE_INQUIRY_VALUE;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (typeof value === "string") return redactServiceInquiryText(value);
|
|
61
|
+
if (value === null || typeof value !== "object") return value;
|
|
62
|
+
|
|
63
|
+
if (value instanceof URLSearchParams) {
|
|
64
|
+
const params = new URLSearchParams(value);
|
|
65
|
+
params.forEach((_, paramKey) => {
|
|
66
|
+
if (SERVICE_INQUIRY_SENSITIVE_QUERY_KEY_PATTERN.test(paramKey)) {
|
|
67
|
+
params.set(paramKey, REDACTED_SERVICE_INQUIRY_VALUE);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
return Object.fromEntries(params.entries());
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (typeof Headers !== "undefined" && value instanceof Headers) {
|
|
74
|
+
return redactServiceInquiryValue(Object.fromEntries(value.entries()));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (value instanceof Error) {
|
|
78
|
+
return {
|
|
79
|
+
name: value.name,
|
|
80
|
+
message: redactServiceInquiryText(value.message),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (seen.has(value)) return "[Circular]";
|
|
85
|
+
seen.add(value);
|
|
86
|
+
|
|
87
|
+
if (Array.isArray(value)) {
|
|
88
|
+
return value.map(item => redactServiceInquiryValue(item, undefined, seen));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return Object.fromEntries(
|
|
92
|
+
Object.entries(value as Record<string, unknown>).map(
|
|
93
|
+
([entryKey, entry]) => [
|
|
94
|
+
entryKey,
|
|
95
|
+
redactServiceInquiryValue(entry, entryKey, seen),
|
|
96
|
+
],
|
|
97
|
+
),
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Service Inquiry Utility; 네트워크 오류 기록 redaction
|
|
103
|
+
* @util
|
|
104
|
+
* @param {ServiceInquiryNetworkError} error 네트워크 오류 기록
|
|
105
|
+
* @returns {ServiceInquiryNetworkError} 민감 payload가 제거된 네트워크 오류 기록
|
|
106
|
+
* @example
|
|
107
|
+
* redactServiceInquiryNetworkError({ route: "/api?token=abc" });
|
|
108
|
+
*/
|
|
109
|
+
export function redactServiceInquiryNetworkError(
|
|
110
|
+
error: ServiceInquiryNetworkError,
|
|
111
|
+
): ServiceInquiryNetworkError {
|
|
112
|
+
return redactServiceInquiryValue(error) as ServiceInquiryNetworkError;
|
|
113
|
+
}
|
|
@@ -31,22 +31,22 @@ export type API_Req_WeatherKoreaAlert = { farm_idx: number | null };
|
|
|
31
31
|
export type API_Res_WeatherKoreaAlertEach = {
|
|
32
32
|
/**
|
|
33
33
|
* 상위 지역 코드
|
|
34
|
-
* @see https://apihub.kma.go.kr/api/typ01/url/wrn_reg.php?tmfc=0
|
|
34
|
+
* @see https://apihub.kma.go.kr/api/typ01/url/wrn_reg.php?tmfc=0
|
|
35
35
|
*/
|
|
36
36
|
upper_region_code: string;
|
|
37
37
|
/**
|
|
38
38
|
* 상위 지역 이름
|
|
39
|
-
* @see https://apihub.kma.go.kr/api/typ01/url/wrn_reg.php?tmfc=0
|
|
39
|
+
* @see https://apihub.kma.go.kr/api/typ01/url/wrn_reg.php?tmfc=0
|
|
40
40
|
*/
|
|
41
41
|
upper_region_name: string;
|
|
42
42
|
/**
|
|
43
43
|
* 특보 지역 코드
|
|
44
|
-
* @see https://apihub.kma.go.kr/api/typ01/url/wrn_reg.php?tmfc=0
|
|
44
|
+
* @see https://apihub.kma.go.kr/api/typ01/url/wrn_reg.php?tmfc=0
|
|
45
45
|
*/
|
|
46
46
|
alert_region_code: string;
|
|
47
47
|
/**
|
|
48
48
|
* 특보 지역 이름
|
|
49
|
-
* @see https://apihub.kma.go.kr/api/typ01/url/wrn_reg.php?tmfc=0
|
|
49
|
+
* @see https://apihub.kma.go.kr/api/typ01/url/wrn_reg.php?tmfc=0
|
|
50
50
|
*/
|
|
51
51
|
alert_region_name: string;
|
|
52
52
|
/**
|