@uniai-fe/uds-templates 0.4.8 → 0.4.9
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/package.json
CHANGED
|
@@ -8,6 +8,10 @@ import {
|
|
|
8
8
|
useServiceInquiryUserContext,
|
|
9
9
|
} from "./hooks";
|
|
10
10
|
import { createServiceInquiryModal } from "./utils/modal-option";
|
|
11
|
+
import {
|
|
12
|
+
getServiceInquiryDebugHeaders,
|
|
13
|
+
parseResponseWithServiceInquiryDebug,
|
|
14
|
+
} from "./utils/network-debug";
|
|
11
15
|
|
|
12
16
|
/**
|
|
13
17
|
* Service Inquiry; 문의 form + modal option 엔트리
|
|
@@ -21,6 +25,8 @@ export const ServiceInquiry = {
|
|
|
21
25
|
useProvideContext: useProvideServiceInquiryContext,
|
|
22
26
|
useUserContext: useServiceInquiryUserContext,
|
|
23
27
|
createModal: createServiceInquiryModal,
|
|
28
|
+
getNetworkDebugHeaders: getServiceInquiryDebugHeaders,
|
|
29
|
+
parseResponseDebug: parseResponseWithServiceInquiryDebug,
|
|
24
30
|
};
|
|
25
31
|
|
|
26
32
|
export {
|
|
@@ -31,5 +37,7 @@ export {
|
|
|
31
37
|
useProvideServiceInquiryContext,
|
|
32
38
|
useServiceInquiryUserContext,
|
|
33
39
|
createServiceInquiryModal,
|
|
40
|
+
getServiceInquiryDebugHeaders,
|
|
41
|
+
parseResponseWithServiceInquiryDebug,
|
|
34
42
|
};
|
|
35
43
|
export type * from "./types";
|
|
@@ -19,12 +19,44 @@ export interface ServiceInquiryProvidedContext {
|
|
|
19
19
|
userContext?: ServiceInquiryUserContext | null;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Service Inquiry Hook; 네트워크 오류 헤더 요약
|
|
24
|
+
* @property {string} [uniai_native_domain] 응답 헤더 `Uniai-Native-Domain`
|
|
25
|
+
* @property {string} [uniai_native_path] 응답 헤더 `Uniai-Native-Path`
|
|
26
|
+
* @property {string} [uniai_native_url] 응답 헤더 `Uniai-Native-URL`
|
|
27
|
+
* @property {string} [content_type] 응답 헤더 `content-type`
|
|
28
|
+
* @property {boolean} [has_authorization] 요청 헤더에 Authorization 존재 여부
|
|
29
|
+
*/
|
|
30
|
+
export interface ServiceInquiryNetworkErrorHeaders {
|
|
31
|
+
/**
|
|
32
|
+
* 응답 헤더 `Uniai-Native-Domain`
|
|
33
|
+
*/
|
|
34
|
+
uniai_native_domain?: string;
|
|
35
|
+
/**
|
|
36
|
+
* 응답 헤더 `Uniai-Native-Path`
|
|
37
|
+
*/
|
|
38
|
+
uniai_native_path?: string;
|
|
39
|
+
/**
|
|
40
|
+
* 응답 헤더 `Uniai-Native-URL`
|
|
41
|
+
*/
|
|
42
|
+
uniai_native_url?: string;
|
|
43
|
+
/**
|
|
44
|
+
* 응답 헤더 `content-type`
|
|
45
|
+
*/
|
|
46
|
+
content_type?: string;
|
|
47
|
+
/**
|
|
48
|
+
* 요청 헤더에 Authorization 존재 여부
|
|
49
|
+
*/
|
|
50
|
+
has_authorization?: boolean;
|
|
51
|
+
}
|
|
52
|
+
|
|
22
53
|
/**
|
|
23
54
|
* Service Inquiry Hook; 네트워크 오류 기록
|
|
24
55
|
* @property {string} [route] 요청 route 또는 endpoint
|
|
25
56
|
* @property {number} [code] HTTP status code
|
|
26
57
|
* @property {string} [state] 서비스 레이어 상태 문자열
|
|
27
58
|
* @property {string} [message] 사용자/운영 확인용 오류 메시지
|
|
59
|
+
* @property {ServiceInquiryNetworkErrorHeaders} [headers] 선택 수집된 request/response 헤더 정보
|
|
28
60
|
* @property {string} [timestamp] 오류 기록 시각
|
|
29
61
|
*/
|
|
30
62
|
export interface ServiceInquiryNetworkError {
|
|
@@ -44,6 +76,10 @@ export interface ServiceInquiryNetworkError {
|
|
|
44
76
|
* 사용자/운영 확인용 오류 메시지
|
|
45
77
|
*/
|
|
46
78
|
message?: string;
|
|
79
|
+
/**
|
|
80
|
+
* 선택 수집된 request/response 헤더 정보
|
|
81
|
+
*/
|
|
82
|
+
headers?: ServiceInquiryNetworkErrorHeaders;
|
|
47
83
|
/**
|
|
48
84
|
* 오류 기록 시각
|
|
49
85
|
*/
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { ServiceInquiryNetworkErrorHeaders } from "../types";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Service Inquiry Utility; Authorization 헤더 존재 여부 판별
|
|
5
|
+
* @param {HeadersInit} [requestHeaders] 요청 헤더
|
|
6
|
+
* @returns {boolean} Authorization 헤더 존재 여부
|
|
7
|
+
* @example
|
|
8
|
+
* const hasAuthorization = resolveServiceInquiryHasAuthorization({
|
|
9
|
+
* Authorization: "Bearer token",
|
|
10
|
+
* });
|
|
11
|
+
*/
|
|
12
|
+
const resolveServiceInquiryHasAuthorization = (
|
|
13
|
+
requestHeaders?: HeadersInit,
|
|
14
|
+
): boolean => {
|
|
15
|
+
if (!requestHeaders) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return new Headers(requestHeaders).has("Authorization");
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Service Inquiry Utility; 선택 디버그 헤더 추출
|
|
24
|
+
* @param {Headers} responseHeaders 응답 헤더
|
|
25
|
+
* @param {HeadersInit} [requestHeaders] 요청 헤더
|
|
26
|
+
* @returns {ServiceInquiryNetworkErrorHeaders | undefined} service-inquiry에 기록할 최소 헤더 정보
|
|
27
|
+
* @example
|
|
28
|
+
* const headers = pickServiceInquiryDebugHeaders(response.headers, {
|
|
29
|
+
* Authorization: "Bearer token",
|
|
30
|
+
* });
|
|
31
|
+
*/
|
|
32
|
+
const pickServiceInquiryDebugHeaders = (
|
|
33
|
+
responseHeaders: Headers,
|
|
34
|
+
requestHeaders?: HeadersInit,
|
|
35
|
+
): ServiceInquiryNetworkErrorHeaders | undefined => {
|
|
36
|
+
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,
|
|
42
|
+
has_authorization: resolveServiceInquiryHasAuthorization(requestHeaders),
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
if (
|
|
46
|
+
!headers.uniai_native_domain &&
|
|
47
|
+
!headers.uniai_native_path &&
|
|
48
|
+
!headers.uniai_native_url &&
|
|
49
|
+
!headers.content_type &&
|
|
50
|
+
!headers.has_authorization
|
|
51
|
+
) {
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return headers;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Service Inquiry Utility; 응답 payload에 디버그 헤더 주입
|
|
60
|
+
* @param {Response} response fetch 응답 객체
|
|
61
|
+
* @param {HeadersInit} [requestHeaders] 요청 헤더
|
|
62
|
+
* @returns {Promise<ResponseData>} 선택 디버그 헤더가 포함된 응답 payload
|
|
63
|
+
* @example
|
|
64
|
+
* const payload = await parseResponseWithServiceInquiryDebug(response, {
|
|
65
|
+
* Authorization: "Bearer token",
|
|
66
|
+
* });
|
|
67
|
+
*/
|
|
68
|
+
export async function parseResponseWithServiceInquiryDebug<
|
|
69
|
+
ResponseData extends object,
|
|
70
|
+
>(response: Response, requestHeaders?: HeadersInit): Promise<ResponseData> {
|
|
71
|
+
const payload = (await response.json()) as ResponseData;
|
|
72
|
+
const headers = pickServiceInquiryDebugHeaders(
|
|
73
|
+
response.headers,
|
|
74
|
+
requestHeaders,
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
if (!headers) {
|
|
78
|
+
return payload;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// 변경 설명: service-inquiry 네트워크 기록에 필요한 최소 header 정보만 응답 payload에 숨겨서 전달한다.
|
|
82
|
+
return Object.assign(payload, {
|
|
83
|
+
_service_inquiry_debug: {
|
|
84
|
+
headers,
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Service Inquiry Utility; 응답 payload에서 디버그 헤더 읽기
|
|
91
|
+
* @param {unknown} response service 응답 payload
|
|
92
|
+
* @returns {ServiceInquiryNetworkErrorHeaders | undefined} 숨겨서 실은 디버그 헤더
|
|
93
|
+
* @example
|
|
94
|
+
* const headers = getServiceInquiryDebugHeaders(response);
|
|
95
|
+
*/
|
|
96
|
+
export function getServiceInquiryDebugHeaders(
|
|
97
|
+
response: unknown,
|
|
98
|
+
): ServiceInquiryNetworkErrorHeaders | undefined {
|
|
99
|
+
if (!response || typeof response !== "object") {
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const debugData = (
|
|
104
|
+
response as {
|
|
105
|
+
_service_inquiry_debug?: {
|
|
106
|
+
headers?: ServiceInquiryNetworkErrorHeaders;
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
)._service_inquiry_debug;
|
|
110
|
+
|
|
111
|
+
return debugData?.headers;
|
|
112
|
+
}
|