@uniai-fe/uds-templates 0.6.17 → 0.6.19

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 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniai-fe/uds-templates",
3
- "version": "0.6.17",
3
+ "version": "0.6.19",
4
4
  "description": "UNIAI Design System; UI Templates Package",
5
5
  "type": "module",
6
6
  "private": false,
@@ -225,7 +225,8 @@ export async function getServerCctvToken({
225
225
  token: "",
226
226
  };
227
227
 
228
- const password = reqBody?.password || tokenPreset?.password || "";
228
+ const password =
229
+ reqBody?.password || tokenPreset?.password || reqBody?.username || "";
229
230
 
230
231
  if (
231
232
  !reqBody ||
@@ -298,7 +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
+ * @property {string} [password] 사용자 계정 비밀번호. 생략 시 서버 route에서 tokenPreset.password 또는 username fallback을 사용
302
302
  */
303
303
  export interface API_Req_CctvRtcToken {
304
304
  /**
@@ -315,7 +315,7 @@ export interface API_Req_CctvRtcToken {
315
315
  username: string;
316
316
  /**
317
317
  * 사용자 계정 비밀번호
318
- * - 서버 route에서 tokenPreset.password 주입하는 경우 생략 가능
318
+ * - 서버 route에서 tokenPreset.password 또는 username fallback을 사용하는 경우 생략 가능
319
319
  */
320
320
  password?: string;
321
321
  }
@@ -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") ?? undefined,
39
- uniai_native_path: responseHeaders.get("Uniai-Native-Path") ?? undefined,
40
- uniai_native_url: responseHeaders.get("Uniai-Native-URL") ?? undefined,
41
- content_type: responseHeaders.get("content-type") ?? undefined,
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
+ }