@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.
- package/dist/cjs/tsconfig-cjs.tsbuildinfo +1 -1
- package/dist/components/Daeryuntalk/ChatButton.d.ts +1 -0
- package/dist/components/Daeryuntalk/ChatButton.jsx +13 -3
- package/dist/components/Daeryuntalk/ChatButton.tsx +17 -3
- package/dist/components/Daeryuntalk/ChatConversation.tsx +1 -1
- package/dist/components/Daeryuntalk/DaeryuntalkContext.d.ts +9 -0
- package/dist/components/Daeryuntalk/DaeryuntalkContext.jsx +127 -3
- package/dist/components/Daeryuntalk/DaeryuntalkContext.tsx +130 -3
- package/dist/components/Daeryuntalk/DaeryuntalkProvider.d.ts +11 -0
- package/dist/components/Daeryuntalk/DaeryuntalkProvider.jsx +59 -0
- package/dist/components/Daeryuntalk/DaeryuntalkProvider.tsx +68 -0
- package/dist/lib/api/daeryuntalk/chatInquiry.d.ts +23 -0
- package/dist/lib/api/daeryuntalk/chatInquiry.js +78 -0
- package/dist/lib/api/daeryuntalk/chatInquiry.ts +80 -0
- package/dist/lib/api/daeryuntalk/index.d.ts +88 -0
- package/dist/lib/api/daeryuntalk/index.js +317 -0
- package/dist/lib/api/daeryuntalk/index.ts +418 -0
- package/dist/lib/api/daeryuntalk/useDaeryuntalkApi.d.ts +23 -0
- package/dist/lib/api/daeryuntalk/useDaeryuntalkApi.js +140 -0
- package/dist/lib/api/daeryuntalk/useDaeryuntalkApi.ts +187 -0
- package/dist/lib/api/index.d.ts +8 -0
- package/dist/lib/api/index.js +8 -0
- package/dist/lib/api/index.ts +9 -0
- package/dist/lib/index.js +1 -0
- package/dist/lib/index.ts +1 -0
- package/dist/styles/globals.css +279 -279
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Daeryuntalk API 클라이언트 모듈 2025-04-23
|
|
3
|
+
*
|
|
4
|
+
* 이 모듈은 Daeryuntalk 채팅 API와 상호작용하기 위한 함수를 제공
|
|
5
|
+
* 1. 고객 인증
|
|
6
|
+
* 2. 웹소켓 연결 초기화
|
|
7
|
+
* 3. 웹소켓 연결
|
|
8
|
+
* 4. 채팅 문의 관리
|
|
9
|
+
*/
|
|
10
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
11
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
12
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
13
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
14
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
15
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
16
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
// API 기본 URL
|
|
20
|
+
const API_BASE_URL = 'https://chat-client-api.lawmance.com';
|
|
21
|
+
// API 기본 버전
|
|
22
|
+
const DEFAULT_API_VERSION = '1.0.0';
|
|
23
|
+
// API 엔드포인트
|
|
24
|
+
const ENDPOINTS = {
|
|
25
|
+
AUTHENTICATE: '/chatctm/ctf/crtfica',
|
|
26
|
+
WEBSOCKET_INIT: '/chatctm/cmp/ws-init',
|
|
27
|
+
CHAT_INQUIRY_MAIN: '/chatctm/hom/chatinquirymainsearch',
|
|
28
|
+
CHAT_INQUIRY_CREATE: '/chatctm/hom/chatinquirycreate',
|
|
29
|
+
CHAT_INQUIRY_DETAIL: '/chatctm/hom/chatinquirydetailsearch'
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* 쿠키 지원이 포함된 기본 fetch 함수
|
|
33
|
+
*/
|
|
34
|
+
function fetchWithCookies(url_1) {
|
|
35
|
+
return __awaiter(this, arguments, void 0, function* (url, options = {}, version = DEFAULT_API_VERSION // 버전 매개변수 추가
|
|
36
|
+
) {
|
|
37
|
+
const headers = new Headers(options.headers || {});
|
|
38
|
+
// Content-Type 헤더가 없으면 추가
|
|
39
|
+
if (!headers.has('Content-Type')) {
|
|
40
|
+
headers.set('Content-Type', 'application/json');
|
|
41
|
+
}
|
|
42
|
+
// 버전 헤더 추가
|
|
43
|
+
headers.set('v', version);
|
|
44
|
+
const defaultOptions = {
|
|
45
|
+
credentials: 'include', // 요청에 쿠키 포함
|
|
46
|
+
headers
|
|
47
|
+
};
|
|
48
|
+
const mergedOptions = Object.assign(Object.assign(Object.assign({}, defaultOptions), options), { headers });
|
|
49
|
+
console.log(`[API 요청] ${options.method || 'GET'} ${url}`, {
|
|
50
|
+
옵션: mergedOptions,
|
|
51
|
+
본문: mergedOptions.body,
|
|
52
|
+
버전: version
|
|
53
|
+
});
|
|
54
|
+
try {
|
|
55
|
+
const response = yield fetch(url, mergedOptions);
|
|
56
|
+
if (!response.ok) {
|
|
57
|
+
// 400 에러 상세 정보 추출 시도
|
|
58
|
+
try {
|
|
59
|
+
const errorData = yield response.json();
|
|
60
|
+
console.error(`[API 오류] ${response.status} ${response.statusText}`, errorData);
|
|
61
|
+
throw new Error(`API 오류: ${response.status} - ${response.statusText} - ${JSON.stringify(errorData)}`);
|
|
62
|
+
}
|
|
63
|
+
catch (parseError) {
|
|
64
|
+
console.error(`[API 오류] ${response.status} ${response.statusText} - 응답 파싱 실패`, parseError);
|
|
65
|
+
throw new Error(`API 오류: ${response.status} - ${response.statusText}`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// 응답 본문이 비어 있는지 확인
|
|
69
|
+
const contentLength = response.headers.get('content-length');
|
|
70
|
+
const isEmpty = contentLength === '0';
|
|
71
|
+
let data;
|
|
72
|
+
if (isEmpty) {
|
|
73
|
+
console.log(`[API 응답 데이터] ${options.method || 'GET'} ${url} - 빈 응답 본문 (헤더 기반 확인)`);
|
|
74
|
+
// 빈 응답이면 빈 객체 반환
|
|
75
|
+
data = {};
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
try {
|
|
79
|
+
// 응답 텍스트를 먼저 확인하여 비어있는지 검사
|
|
80
|
+
const clonedResponse = response.clone();
|
|
81
|
+
const responseText = yield clonedResponse.text();
|
|
82
|
+
if (!responseText || responseText.trim() === '') {
|
|
83
|
+
console.log(`[API 응답 데이터] ${options.method || 'GET'} ${url} - 빈 응답 본문 (내용 기반 확인)`);
|
|
84
|
+
data = {};
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
// 유효한 JSON인 경우만 파싱
|
|
88
|
+
data = JSON.parse(responseText);
|
|
89
|
+
console.log(`[API 응답 데이터] ${options.method || 'GET'} ${url}`, data);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
console.error(`[API 응답 JSON 파싱 오류] ${options.method || 'GET'} ${url}`, error);
|
|
94
|
+
// JSON 파싱 오류가 발생해도 요청은 성공했으므로 빈 객체 반환
|
|
95
|
+
data = {};
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return data;
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
console.error(`[API 호출 실패] ${options.method || 'GET'} ${url}`, error);
|
|
102
|
+
throw error;
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* 사용자 인증
|
|
108
|
+
* @param version API 버전 (기본값: 1.0.0)
|
|
109
|
+
* @returns 인증 응답
|
|
110
|
+
*/
|
|
111
|
+
export function authenticateUser(version) {
|
|
112
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
console.log('[인증 시작] 사용자 인증 요청', version ? `버전: ${version}` : `기본 버전: ${DEFAULT_API_VERSION}`);
|
|
114
|
+
try {
|
|
115
|
+
// 인증 API 호출
|
|
116
|
+
const response = yield fetchWithCookies(`${API_BASE_URL}${ENDPOINTS.AUTHENTICATE}`, { method: 'GET' }, version);
|
|
117
|
+
// 빈 응답인 경우에도 성공으로 처리
|
|
118
|
+
if (Object.keys(response).length === 0) {
|
|
119
|
+
console.log('[인증 성공] 사용자 인증 완료 - 빈 응답 (쿠키만 설정됨)');
|
|
120
|
+
return { success: true, status: 'authenticated' };
|
|
121
|
+
}
|
|
122
|
+
console.log('[인증 성공] 사용자 인증 완료', response);
|
|
123
|
+
return response;
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
console.error('[인증 실패] 사용자 인증 오류:', error);
|
|
127
|
+
throw error;
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* 웹소켓 연결 초기화
|
|
133
|
+
* @param version API 버전 (기본값: 1.0.0)
|
|
134
|
+
* @returns 연결 URL과 토큰이 포함된 웹소켓 초기화 데이터
|
|
135
|
+
*/
|
|
136
|
+
export function initializeWebSocket(version) {
|
|
137
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
138
|
+
console.log('[웹소켓 초기화 시작] 웹소켓 연결 초기화 요청', version ? `버전: ${version}` : `기본 버전: ${DEFAULT_API_VERSION}`);
|
|
139
|
+
try {
|
|
140
|
+
const response = yield fetchWithCookies(`${API_BASE_URL}${ENDPOINTS.WEBSOCKET_INIT}`, { method: 'POST' }, version);
|
|
141
|
+
console.log('[웹소켓 초기화 성공] 웹소켓 연결 URL 및 토큰 수신', response);
|
|
142
|
+
return response;
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
console.error('[웹소켓 초기화 실패] 웹소켓 연결 초기화 오류:', error);
|
|
146
|
+
throw error;
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* 웹소켓 연결
|
|
152
|
+
* @param wsUrl 웹소켓 URL
|
|
153
|
+
* @param token 연결 토큰
|
|
154
|
+
* @param onMessage 메시지 핸들러
|
|
155
|
+
* @param onOpen 연결 열림 핸들러
|
|
156
|
+
* @param onClose 연결 닫힘 핸들러
|
|
157
|
+
* @param onError 오류 핸들러
|
|
158
|
+
* @returns 웹소켓 인스턴스
|
|
159
|
+
*/
|
|
160
|
+
export function connectWebSocket(wsUrl, token, onMessage, onOpen, onClose, onError) {
|
|
161
|
+
// URL에 토큰을 파라미터로 추가
|
|
162
|
+
const connectionUrl = `${wsUrl}?token=${token}`;
|
|
163
|
+
console.log('[웹소켓 연결 시작] 연결 URL:', connectionUrl);
|
|
164
|
+
try {
|
|
165
|
+
const socket = new WebSocket(connectionUrl);
|
|
166
|
+
socket.onopen = event => {
|
|
167
|
+
console.log('[웹소켓 연결 성공] 웹소켓 연결됨');
|
|
168
|
+
if (onOpen)
|
|
169
|
+
onOpen(event);
|
|
170
|
+
};
|
|
171
|
+
if (onMessage) {
|
|
172
|
+
socket.onmessage = event => {
|
|
173
|
+
console.log('[웹소켓 메시지 수신]', event.data);
|
|
174
|
+
onMessage(event);
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
if (onClose) {
|
|
178
|
+
socket.onclose = event => {
|
|
179
|
+
console.log('[웹소켓 연결 종료] 코드:', event.code, '사유:', event.reason);
|
|
180
|
+
onClose(event);
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
if (onError) {
|
|
184
|
+
socket.onerror = event => {
|
|
185
|
+
console.error('[웹소켓 오류]', event);
|
|
186
|
+
onError(event);
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
return socket;
|
|
190
|
+
}
|
|
191
|
+
catch (error) {
|
|
192
|
+
console.error('[웹소켓 연결 실패]', error);
|
|
193
|
+
throw error;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* 채팅 문의 메인 조회
|
|
198
|
+
* @param version API 버전 (기본값: 1.0.0)
|
|
199
|
+
* @returns 채팅 문의 메인 데이터
|
|
200
|
+
*/
|
|
201
|
+
export function getChatInquiryMain(version) {
|
|
202
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
203
|
+
const body = {
|
|
204
|
+
d: {
|
|
205
|
+
channel_number: 'CH123456789012345678' // 명시된 고정값
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
console.log('[채팅 문의 메인 조회 시작] 채널 번호:', body.d.channel_number, version ? `버전: ${version}` : `기본 버전: ${DEFAULT_API_VERSION}`);
|
|
209
|
+
try {
|
|
210
|
+
const response = yield fetchWithCookies(`${API_BASE_URL}${ENDPOINTS.CHAT_INQUIRY_MAIN}`, {
|
|
211
|
+
method: 'POST',
|
|
212
|
+
body: JSON.stringify(body)
|
|
213
|
+
}, version);
|
|
214
|
+
console.log('[채팅 문의 메인 조회 성공]', response);
|
|
215
|
+
return response;
|
|
216
|
+
}
|
|
217
|
+
catch (error) {
|
|
218
|
+
console.error('[채팅 문의 메인 조회 실패]', error);
|
|
219
|
+
throw error;
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* 새 채팅 문의 생성 (처음 방문자용)
|
|
225
|
+
* @param version API 버전 (기본값: 1.0.0)
|
|
226
|
+
* @returns 문의 번호가 포함된 생성된 채팅 문의 데이터
|
|
227
|
+
*/
|
|
228
|
+
export function createChatInquiry(version) {
|
|
229
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
230
|
+
console.log('[새 채팅 문의 생성 시작]', version ? `버전: ${version}` : `기본 버전: ${DEFAULT_API_VERSION}`);
|
|
231
|
+
try {
|
|
232
|
+
const response = yield fetchWithCookies(`${API_BASE_URL}${ENDPOINTS.CHAT_INQUIRY_CREATE}`, { method: 'POST' }, version);
|
|
233
|
+
console.log('[새 채팅 문의 생성 성공] 문의 번호:', response.chat_inquiry_number);
|
|
234
|
+
return response;
|
|
235
|
+
}
|
|
236
|
+
catch (error) {
|
|
237
|
+
console.error('[새 채팅 문의 생성 실패]', error);
|
|
238
|
+
throw error;
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* 채팅 문의 상세 조회
|
|
244
|
+
* @param inquiryNumber 채팅 문의 번호
|
|
245
|
+
* @param version API 버전 (기본값: 1.0.0)
|
|
246
|
+
* @returns 채팅 문의 상세 정보
|
|
247
|
+
*/
|
|
248
|
+
export function getChatInquiryDetail(inquiryNumber, version) {
|
|
249
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
250
|
+
const body = {
|
|
251
|
+
d: {
|
|
252
|
+
inquiry_number: inquiryNumber
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
console.log('[채팅 문의 상세 조회 시작] 문의 번호:', inquiryNumber, version ? `버전: ${version}` : `기본 버전: ${DEFAULT_API_VERSION}`);
|
|
256
|
+
try {
|
|
257
|
+
const response = yield fetchWithCookies(`${API_BASE_URL}${ENDPOINTS.CHAT_INQUIRY_DETAIL}`, {
|
|
258
|
+
method: 'POST',
|
|
259
|
+
body: JSON.stringify(body)
|
|
260
|
+
}, version);
|
|
261
|
+
console.log('[채팅 문의 상세 조회 성공]', response);
|
|
262
|
+
return response;
|
|
263
|
+
}
|
|
264
|
+
catch (error) {
|
|
265
|
+
console.error('[채팅 문의 상세 조회 실패]', error);
|
|
266
|
+
throw error;
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Daeryuntalk 초기화 완료 흐름
|
|
272
|
+
* 이 함수는 인증부터 웹소켓 연결까지 완전한 흐름을 처리
|
|
273
|
+
* @param onWebSocketConnected 웹소켓 연결 시 콜백
|
|
274
|
+
* @param onWebSocketMessage 메시지 핸들러
|
|
275
|
+
* @param version API 버전 (기본값: 1.0.0)
|
|
276
|
+
* @returns 웹소켓 인스턴스 및 문의 데이터
|
|
277
|
+
*/
|
|
278
|
+
export function initializeDaeryuntalk(onWebSocketConnected, onWebSocketMessage, version) {
|
|
279
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
280
|
+
console.log('[Daeryuntalk 초기화 시작] 전체 흐름 실행', version ? `버전: ${version}` : `기본 버전: ${DEFAULT_API_VERSION}`);
|
|
281
|
+
try {
|
|
282
|
+
// 1단계: 사용자 인증
|
|
283
|
+
console.log('[Daeryuntalk 초기화] 1단계: 사용자 인증 시작');
|
|
284
|
+
yield authenticateUser(version);
|
|
285
|
+
console.log('[Daeryuntalk 초기화] 1단계: 사용자 인증 완료');
|
|
286
|
+
// 2단계: 웹소켓 초기화
|
|
287
|
+
console.log('[Daeryuntalk 초기화] 2단계: 웹소켓 초기화 시작');
|
|
288
|
+
const wsInitData = yield initializeWebSocket(version);
|
|
289
|
+
console.log('[Daeryuntalk 초기화] 2단계: 웹소켓 초기화 완료', {
|
|
290
|
+
cnnc_url: wsInitData.data.cnnc_url,
|
|
291
|
+
token_일부: wsInitData.data.cnnc_token ? `${wsInitData.data.cnnc_token.substring(0, 10)}...` : '없음'
|
|
292
|
+
});
|
|
293
|
+
// 3단계: 웹소켓 연결
|
|
294
|
+
console.log('[Daeryuntalk 초기화] 3단계: 웹소켓 연결 시작');
|
|
295
|
+
const socket = connectWebSocket(wsInitData.data.cnnc_url, wsInitData.data.cnnc_token, onWebSocketMessage, onWebSocketConnected
|
|
296
|
+
? () => {
|
|
297
|
+
console.log('[Daeryuntalk 초기화] 3단계: 웹소켓 연결 콜백 실행');
|
|
298
|
+
onWebSocketConnected(socket);
|
|
299
|
+
}
|
|
300
|
+
: undefined);
|
|
301
|
+
console.log('[Daeryuntalk 초기화] 3단계: 웹소켓 연결 객체 생성됨');
|
|
302
|
+
// 4단계: 채팅 문의 메인 조회
|
|
303
|
+
console.log('[Daeryuntalk 초기화] 4단계: 채팅 문의 메인 조회 시작');
|
|
304
|
+
const chatInquiryData = yield getChatInquiryMain(version);
|
|
305
|
+
console.log('[Daeryuntalk 초기화] 4단계: 채팅 문의 메인 조회 완료', chatInquiryData);
|
|
306
|
+
console.log('[Daeryuntalk 초기화 완료] 모든 단계 성공');
|
|
307
|
+
return {
|
|
308
|
+
socket,
|
|
309
|
+
inquiryData: chatInquiryData
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
catch (error) {
|
|
313
|
+
console.error('[Daeryuntalk 초기화 실패] 오류 발생:', error);
|
|
314
|
+
throw error;
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
}
|