@daeryun/dr_components 0.6.46 → 0.6.48

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.
Files changed (28) hide show
  1. package/dist/cjs/tsconfig-cjs.tsbuildinfo +1 -1
  2. package/dist/components/Daeryuntalk/ChatButton.d.ts +1 -0
  3. package/dist/components/Daeryuntalk/ChatButton.jsx +13 -3
  4. package/dist/components/Daeryuntalk/ChatButton.tsx +17 -3
  5. package/dist/components/Daeryuntalk/ChatConversation.tsx +1 -1
  6. package/dist/components/Daeryuntalk/DaeryuntalkContext.d.ts +9 -0
  7. package/dist/components/Daeryuntalk/DaeryuntalkContext.jsx +127 -3
  8. package/dist/components/Daeryuntalk/DaeryuntalkContext.tsx +130 -3
  9. package/dist/components/Daeryuntalk/DaeryuntalkProvider.d.ts +11 -0
  10. package/dist/components/Daeryuntalk/DaeryuntalkProvider.jsx +59 -0
  11. package/dist/components/Daeryuntalk/DaeryuntalkProvider.tsx +68 -0
  12. package/dist/lib/api/daeryuntalk/chatInquiry.d.ts +23 -0
  13. package/dist/lib/api/daeryuntalk/chatInquiry.js +78 -0
  14. package/dist/lib/api/daeryuntalk/chatInquiry.ts +80 -0
  15. package/dist/lib/api/daeryuntalk/index.d.ts +88 -0
  16. package/dist/lib/api/daeryuntalk/index.js +317 -0
  17. package/dist/lib/api/daeryuntalk/index.ts +418 -0
  18. package/dist/lib/api/daeryuntalk/useDaeryuntalkApi.d.ts +23 -0
  19. package/dist/lib/api/daeryuntalk/useDaeryuntalkApi.js +140 -0
  20. package/dist/lib/api/daeryuntalk/useDaeryuntalkApi.ts +187 -0
  21. package/dist/lib/api/index.d.ts +8 -0
  22. package/dist/lib/api/index.js +8 -0
  23. package/dist/lib/api/index.ts +9 -0
  24. package/dist/lib/index.js +1 -0
  25. package/dist/lib/index.ts +1 -0
  26. package/dist/styles/globals.css +279 -279
  27. package/dist/tsconfig.tsbuildinfo +1 -1
  28. package/package.json +1 -1
@@ -0,0 +1,187 @@
1
+ /**
2
+ * useDaeryuntalkApi 훅 2025-04-23
3
+ *
4
+ * Daeryuntalk API 상호작용을 관리하는 커스텀 훅
5
+ * Daeryuntalk 전체 흐름을 처리하기 위한 상태와 함수 제공
6
+ */
7
+
8
+ import { useState, useEffect, useCallback } from 'react';
9
+ import {
10
+ authenticateUser,
11
+ initializeWebSocket,
12
+ connectWebSocket,
13
+ getChatInquiryMain,
14
+ createChatInquiry,
15
+ getChatInquiryDetail,
16
+ WebSocketInitResponse,
17
+ ChatInquiryMainResponse,
18
+ ChatInquiryCreateResponse,
19
+ ChatInquiryDetailResponse
20
+ } from './index';
21
+ import { handleChatInquiryFlow } from './chatInquiry';
22
+
23
+ interface UseDaeryuntalkApiReturn {
24
+ // 상태
25
+ isAuthenticated: boolean;
26
+ isSocketInitialized: boolean;
27
+ isSocketConnected: boolean;
28
+ isLoading: boolean;
29
+ error: Error | null;
30
+
31
+ // WebSocket 데이터
32
+ socket: WebSocket | null;
33
+ socketUrl: string | null;
34
+ socketToken: string | null;
35
+
36
+ // 문의 데이터
37
+ inquiryMainData: ChatInquiryMainResponse | null;
38
+ inquiryDetailData: ChatInquiryDetailResponse | null;
39
+
40
+ // 함수
41
+ initialize: (version?: string) => Promise<void>;
42
+ handleMessage: (event: MessageEvent) => void;
43
+ }
44
+
45
+ export function useDaeryuntalkApi(): UseDaeryuntalkApiReturn {
46
+ // API 흐름 단계 추적 상태
47
+ const [isAuthenticated, setIsAuthenticated] = useState<boolean>(false);
48
+ const [isSocketInitialized, setIsSocketInitialized] = useState<boolean>(false);
49
+ const [isSocketConnected, setIsSocketConnected] = useState<boolean>(false);
50
+ const [isLoading, setIsLoading] = useState<boolean>(false);
51
+ const [error, setError] = useState<Error | null>(null);
52
+
53
+ // WebSocket 상태
54
+ const [socket, setSocket] = useState<WebSocket | null>(null);
55
+ const [socketUrl, setSocketUrl] = useState<string | null>(null);
56
+ const [socketToken, setSocketToken] = useState<string | null>(null);
57
+
58
+ // 문의 데이터
59
+ const [inquiryMainData, setInquiryMainData] = useState<ChatInquiryMainResponse | null>(null);
60
+ const [inquiryDetailData, setInquiryDetailData] = useState<ChatInquiryDetailResponse | null>(null);
61
+
62
+ // WebSocket 메시지 처리
63
+ const handleMessage = useCallback((event: MessageEvent) => {
64
+ try {
65
+ const data = JSON.parse(event.data);
66
+ console.log('WebSocket 메시지 수신:', data);
67
+ // todo: trophy198 여기에서 다양한 메시지 유형 처리
68
+ } catch (error) {
69
+ console.error('WebSocket 메시지 파싱 오류:', error);
70
+ }
71
+ }, []);
72
+
73
+ // WebSocket 연결 처리
74
+ const handleSocketConnection = useCallback(
75
+ (wsUrl: string, token: string) => {
76
+ try {
77
+ const newSocket = connectWebSocket(
78
+ wsUrl,
79
+ token,
80
+ handleMessage, // 메시지 핸들러
81
+ () => {
82
+ console.log('WebSocket 연결됨');
83
+ setIsSocketConnected(true);
84
+ },
85
+ () => {
86
+ console.log('WebSocket 연결 해제됨');
87
+ setIsSocketConnected(false);
88
+ },
89
+ error => {
90
+ console.error('WebSocket 오류:', error);
91
+ setError(new Error('WebSocket 연결 오류'));
92
+ }
93
+ );
94
+
95
+ setSocket(newSocket);
96
+ } catch (error) {
97
+ console.error('WebSocket 연결 중 오류:', error);
98
+ setError(error instanceof Error ? error : new Error('WebSocket 연결 중 알 수 없는 오류'));
99
+ }
100
+ },
101
+ [handleMessage]
102
+ );
103
+
104
+ // Daeryuntalk 전체 흐름 초기화
105
+ const initialize = useCallback(
106
+ async (version?: string) => {
107
+ console.log('[useDaeryuntalkApi] 초기화 시작', version ? `버전: ${version}` : '기본 버전 사용');
108
+ setIsLoading(true);
109
+ setError(null);
110
+
111
+ try {
112
+ // 1단계: 사용자 인증
113
+ console.log('[useDaeryuntalkApi] 1단계: 사용자 인증 시작');
114
+ await authenticateUser(version);
115
+ console.log('[useDaeryuntalkApi] 1단계: 사용자 인증 완료');
116
+ setIsAuthenticated(true);
117
+
118
+ // 2단계: WebSocket 초기화
119
+ console.log('[useDaeryuntalkApi] 2단계: WebSocket 초기화 시작');
120
+ const wsInitData = await initializeWebSocket(version);
121
+ console.log('[useDaeryuntalkApi] 2단계: WebSocket 초기화 완료', {
122
+ url: wsInitData.data.cnnc_url,
123
+ token_일부: wsInitData.data.cnnc_token
124
+ ? wsInitData.data.cnnc_token.substring(0, 10) + '...'
125
+ : '없음'
126
+ });
127
+ setSocketUrl(wsInitData.data.cnnc_url);
128
+ setSocketToken(wsInitData.data.cnnc_token);
129
+ setIsSocketInitialized(true);
130
+
131
+ // 3단계: WebSocket 연결
132
+ console.log('[useDaeryuntalkApi] 3단계: WebSocket 연결 시작');
133
+ if (wsInitData.data.cnnc_url && wsInitData.data.cnnc_token) {
134
+ handleSocketConnection(wsInitData.data.cnnc_url, wsInitData.data.cnnc_token);
135
+ console.log('[useDaeryuntalkApi] 3단계: WebSocket 연결 요청됨');
136
+ } else {
137
+ console.error('[useDaeryuntalkApi] 3단계: WebSocket 연결 실패 - URL 또는 토큰 없음', wsInitData);
138
+ }
139
+
140
+ // 4단계: 채팅 문의 메인 조회
141
+ console.log('[useDaeryuntalkApi] 4단계: 채팅 문의 메인 조회 시작');
142
+ const mainData = await getChatInquiryMain(version);
143
+ console.log('[useDaeryuntalkApi] 4단계: 채팅 문의 메인 조회 완료', mainData);
144
+ setInquiryMainData(mainData);
145
+
146
+ // 5단계: 사용자 상태에 따른 문의 흐름 처리
147
+ console.log('[useDaeryuntalkApi] 5단계: 문의 흐름 처리 시작');
148
+ const detailData = await handleChatInquiryFlow(version);
149
+ console.log('[useDaeryuntalkApi] 5단계: 문의 흐름 처리 완료', detailData);
150
+ setInquiryDetailData(detailData);
151
+
152
+ console.log('[useDaeryuntalkApi] 초기화 완료 - 모든 단계 성공');
153
+ } catch (error) {
154
+ console.error('[useDaeryuntalkApi] 초기화 오류:', error);
155
+ setError(error instanceof Error ? error : new Error('Daeryuntalk 초기화 중 알 수 없는 오류'));
156
+ } finally {
157
+ console.log('[useDaeryuntalkApi] 로딩 상태 설정: false');
158
+ setIsLoading(false);
159
+ }
160
+ },
161
+ [handleSocketConnection]
162
+ );
163
+
164
+ // 컴포넌트 언마운트 시 WebSocket 연결 정리
165
+ useEffect(() => {
166
+ return () => {
167
+ if (socket) {
168
+ socket.close();
169
+ }
170
+ };
171
+ }, [socket]);
172
+
173
+ return {
174
+ isAuthenticated,
175
+ isSocketInitialized,
176
+ isSocketConnected,
177
+ isLoading,
178
+ error,
179
+ socket,
180
+ socketUrl,
181
+ socketToken,
182
+ inquiryMainData,
183
+ inquiryDetailData,
184
+ initialize,
185
+ handleMessage
186
+ };
187
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * API 모듈 인덱스 2025-04-23
3
+ *
4
+ * Daeryuntalk API 모듈 내보내기
5
+ */
6
+ export * from './daeryuntalk';
7
+ export * from './daeryuntalk/chatInquiry';
8
+ export { useDaeryuntalkApi } from './daeryuntalk/useDaeryuntalkApi';
@@ -0,0 +1,8 @@
1
+ /**
2
+ * API 모듈 인덱스 2025-04-23
3
+ *
4
+ * Daeryuntalk API 모듈 내보내기
5
+ */
6
+ export * from './daeryuntalk';
7
+ export * from './daeryuntalk/chatInquiry';
8
+ export { useDaeryuntalkApi } from './daeryuntalk/useDaeryuntalkApi';
@@ -0,0 +1,9 @@
1
+ /**
2
+ * API 모듈 인덱스 2025-04-23
3
+ *
4
+ * Daeryuntalk API 모듈 내보내기
5
+ */
6
+
7
+ export * from './daeryuntalk';
8
+ export * from './daeryuntalk/chatInquiry';
9
+ export { useDaeryuntalkApi } from './daeryuntalk/useDaeryuntalkApi';
package/dist/lib/index.js CHANGED
@@ -3,3 +3,4 @@ export * from './conversion';
3
3
  export * from './powerlink';
4
4
  export * from './utils';
5
5
  export * from './categoryMenuName';
6
+ export * from './api';
package/dist/lib/index.ts CHANGED
@@ -3,3 +3,4 @@ export * from './conversion';
3
3
  export * from './powerlink';
4
4
  export * from './utils';
5
5
  export * from './categoryMenuName';
6
+ export * from './api';