@redonvn/redai-tool 0.0.0-stage → 1.0.1

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/index.mjs ADDED
@@ -0,0 +1,902 @@
1
+ // src/client.ts
2
+ import axios from "axios";
3
+
4
+ // src/errors.ts
5
+ var RedaiToolError = class extends Error {
6
+ constructor(message) {
7
+ super(message);
8
+ this.name = "RedaiToolError";
9
+ Object.setPrototypeOf(this, new.target.prototype);
10
+ }
11
+ };
12
+ var RedaiToolApiError = class extends RedaiToolError {
13
+ constructor(message, status, responseData) {
14
+ super(message);
15
+ this.name = "RedaiToolApiError";
16
+ this.status = status;
17
+ this.responseData = responseData;
18
+ }
19
+ };
20
+ var RedaiToolAuthError = class extends RedaiToolApiError {
21
+ constructor(message = "X-API-Key is missing or invalid") {
22
+ super(message, 401);
23
+ this.name = "RedaiToolAuthError";
24
+ }
25
+ };
26
+ var RedaiToolTimeoutError = class extends RedaiToolError {
27
+ constructor(message = "Request to redai-tool timed out") {
28
+ super(message);
29
+ this.name = "RedaiToolTimeoutError";
30
+ }
31
+ };
32
+
33
+ // src/modules/google-search/index.ts
34
+ var GoogleSearchModule = class {
35
+ constructor(http) {
36
+ this.http = http;
37
+ }
38
+ /**
39
+ * Chuẩn hóa kết quả cào từ phản hồi DirectSearchResponse của FastAPI
40
+ */
41
+ normalizeScrapeResponse(data, keyword) {
42
+ const rawItems = data.results || data.data || [];
43
+ const normalizedItems = rawItems.map((item, idx) => {
44
+ const contacts = item.contacts || item.contact_info || {};
45
+ const contactInfo = item.contact_info || item.contacts || {};
46
+ return {
47
+ rank: item.rank ?? idx + 1,
48
+ title: item.title || "",
49
+ url: item.url || "",
50
+ domain: item.domain || "",
51
+ is_sponsored: item.is_sponsored ?? false,
52
+ contacts,
53
+ contact_info: contactInfo,
54
+ summary: item.summary || "",
55
+ crawled_pages: item.crawled_pages || [],
56
+ google_snippet: item.google_snippet || item.snippet || "",
57
+ error: item.error
58
+ };
59
+ });
60
+ return {
61
+ success: data.success ?? true,
62
+ keyword: data.keyword || keyword,
63
+ total_scraped: data.total_results ?? data.total_scraped ?? normalizedItems.length,
64
+ location: data.location,
65
+ results: normalizedItems,
66
+ timestamp: data.timestamp || (/* @__PURE__ */ new Date()).toISOString()
67
+ };
68
+ }
69
+ /**
70
+ * Tìm kiếm danh sách kết quả nhanh trên Google (không crawl sâu chi tiết)
71
+ * Chuẩn REST endpoint: POST /api/google-search/list
72
+ */
73
+ async list(request, options) {
74
+ const payload = {
75
+ ...request,
76
+ limit: request.max_results || request.limit || 10
77
+ };
78
+ const response = await this.http.post(
79
+ "/api/google-search/list",
80
+ payload,
81
+ options
82
+ );
83
+ const data = response.data;
84
+ const items = data.results || data.data || [];
85
+ return {
86
+ success: data.success ?? true,
87
+ keyword: data.keyword || request.keyword,
88
+ total_results: data.total_results ?? items.length,
89
+ target_sites: data.target_sites,
90
+ location: data.location,
91
+ results: items,
92
+ timestamp: data.timestamp || (/* @__PURE__ */ new Date()).toISOString()
93
+ };
94
+ }
95
+ /**
96
+ * Tìm kiếm Google và bóc tách thông tin liên hệ đa kênh (Hotline, Zalo, FB, Shopee, App, Bộ Công Thương...)
97
+ * Chuẩn REST endpoint: POST /api/google-search/search
98
+ */
99
+ async scrape(request, options) {
100
+ const payload = {
101
+ ...request,
102
+ limit: request.max_results || request.limit || 10,
103
+ deep_crawl: request.deep_crawl ?? true
104
+ };
105
+ const response = await this.http.post(
106
+ "/api/google-search/search",
107
+ payload,
108
+ options
109
+ );
110
+ return this.normalizeScrapeResponse(response.data, request.keyword);
111
+ }
112
+ /**
113
+ * Bóc tách thông tin liên hệ và tóm tắt AI trực tiếp từ một danh sách các URL website
114
+ * Chuẩn REST endpoint: POST /api/google-search/detail
115
+ */
116
+ async scrapeDetails(request, options) {
117
+ const response = await this.http.post(
118
+ "/api/google-search/detail",
119
+ request,
120
+ options
121
+ );
122
+ const data = response.data;
123
+ const items = data.results || data.data || [];
124
+ const normalizedItems = items.map((item, idx) => {
125
+ const contacts = item.contacts || item.contact_info || {};
126
+ const contactInfo = item.contact_info || item.contacts || {};
127
+ return {
128
+ rank: item.rank ?? idx + 1,
129
+ title: item.title || "",
130
+ url: item.url || "",
131
+ domain: item.domain || "",
132
+ contacts,
133
+ contact_info: contactInfo,
134
+ summary: item.summary || "",
135
+ crawled_pages: item.crawled_pages || [],
136
+ error: item.error
137
+ };
138
+ });
139
+ return {
140
+ success: data.success ?? true,
141
+ total_scraped: data.total_scraped ?? normalizedItems.length,
142
+ results: normalizedItems,
143
+ timestamp: data.timestamp || (/* @__PURE__ */ new Date()).toISOString()
144
+ };
145
+ }
146
+ /**
147
+ * Stream SSE kết quả tìm kiếm và bóc tách theo thời gian thực
148
+ * Chuẩn REST endpoint: GET /api/google-search/stream
149
+ */
150
+ async stream(request, handlers, options) {
151
+ const params = new URLSearchParams();
152
+ params.set("keyword", request.keyword);
153
+ const limit = request.max_results || request.limit;
154
+ if (limit) {
155
+ params.set("limit", String(limit));
156
+ params.set("max_results", String(limit));
157
+ }
158
+ if (request.deep_crawl !== void 0) params.set("deep_crawl", String(request.deep_crawl));
159
+ if (request.summary_mode) params.set("summary_mode", request.summary_mode);
160
+ if (request.target_sites?.length) {
161
+ request.target_sites.forEach((site) => params.append("target_sites", site));
162
+ }
163
+ const response = await this.http.get(
164
+ `/api/google-search/stream?${params.toString()}`,
165
+ {
166
+ ...options,
167
+ responseType: "stream",
168
+ headers: {
169
+ Accept: "text/event-stream",
170
+ ...options?.headers || {}
171
+ }
172
+ }
173
+ );
174
+ const stream = response.data;
175
+ let buffer = "";
176
+ stream.on("data", (chunk) => {
177
+ buffer += chunk.toString();
178
+ const lines = buffer.split("\n");
179
+ buffer = lines.pop() || "";
180
+ for (const line of lines) {
181
+ const trimmed = line.trim();
182
+ if (trimmed.startsWith("data:")) {
183
+ const jsonStr = trimmed.replace(/^data:\s*/, "").trim();
184
+ if (jsonStr === "[DONE]") {
185
+ handlers.onEnd?.();
186
+ return;
187
+ }
188
+ try {
189
+ const parsed = JSON.parse(jsonStr);
190
+ handlers.onData?.(parsed);
191
+ } catch (e) {
192
+ }
193
+ }
194
+ }
195
+ });
196
+ stream.on("end", () => {
197
+ handlers.onEnd?.();
198
+ });
199
+ stream.on("error", (err) => {
200
+ handlers.onError?.(err);
201
+ });
202
+ }
203
+ /**
204
+ * Tạo background job cào tìm kiếm Google
205
+ * Chuẩn REST endpoint: POST /api/google-search/jobs
206
+ */
207
+ async createJob(request, options) {
208
+ const payload = {
209
+ ...request,
210
+ limit: request.max_results || request.limit || 10
211
+ };
212
+ const response = await this.http.post(
213
+ "/api/google-search/jobs",
214
+ payload,
215
+ options
216
+ );
217
+ return response.data;
218
+ }
219
+ /**
220
+ * Kiểm tra trạng thái job cào tìm kiếm Google
221
+ * Chuẩn REST endpoint: GET /api/google-search/jobs/{job_id}
222
+ */
223
+ async getJobStatus(jobId, options) {
224
+ const response = await this.http.get(
225
+ `/api/google-search/jobs/${jobId}`,
226
+ options
227
+ );
228
+ return response.data;
229
+ }
230
+ /**
231
+ * Xuất file CSV/Excel kết quả cào tìm kiếm Google (trả về Buffer)
232
+ * Chuẩn REST endpoint: GET /api/google-search/jobs/{job_id}/export
233
+ */
234
+ async exportCsv(jobId, options) {
235
+ const response = await this.http.get(
236
+ `/api/google-search/jobs/${jobId}/export`,
237
+ {
238
+ ...options,
239
+ responseType: "arraybuffer"
240
+ }
241
+ );
242
+ return Buffer.from(response.data);
243
+ }
244
+ };
245
+
246
+ // src/modules/google-maps/index.ts
247
+ var GoogleMapsModule = class {
248
+ constructor(http) {
249
+ this.http = http;
250
+ }
251
+ /**
252
+ * Tạo background job cào dữ liệu Google Maps
253
+ * Chuẩn REST endpoint: POST /api/map/scrape/async
254
+ */
255
+ async createJob(payload, options) {
256
+ const response = await this.http.post(
257
+ "/api/map/scrape/async",
258
+ payload,
259
+ options
260
+ );
261
+ return response.data;
262
+ }
263
+ /**
264
+ * Kiểm tra trạng thái và tiến độ của job cào Google Maps
265
+ * Chuẩn REST endpoint: GET /api/map/scrape/status/{job_id}
266
+ */
267
+ async getJobStatus(jobId, options) {
268
+ const response = await this.http.get(
269
+ `/api/map/scrape/status/${jobId}`,
270
+ options
271
+ );
272
+ return response.data;
273
+ }
274
+ /**
275
+ * Lấy danh sách kết quả địa điểm thu thập được từ job
276
+ * Dữ liệu nằm trong trường `data` của job status
277
+ */
278
+ async getJobResults(jobId, options) {
279
+ const status = await this.getJobStatus(jobId, options);
280
+ const places = status.data || [];
281
+ return {
282
+ job_id: jobId,
283
+ status: status.status,
284
+ query: status.query,
285
+ total_found: status.total_found,
286
+ total_scraped: status.total_scraped,
287
+ total_filtered: status.total_filtered,
288
+ total_results: places.length,
289
+ places,
290
+ results: places
291
+ };
292
+ }
293
+ /**
294
+ * Stream SSE tiến độ cào Google Maps theo thời gian thực
295
+ * Chuẩn REST endpoint: POST /api/map/scrape/stream
296
+ */
297
+ async streamJob(payload, handlers, options) {
298
+ const response = await this.http.post(
299
+ "/api/map/scrape/stream",
300
+ payload,
301
+ {
302
+ ...options,
303
+ responseType: "stream",
304
+ headers: {
305
+ Accept: "text/event-stream",
306
+ ...options?.headers || {}
307
+ }
308
+ }
309
+ );
310
+ const stream = response.data;
311
+ let buffer = "";
312
+ stream.on("data", (chunk) => {
313
+ buffer += chunk.toString();
314
+ const lines = buffer.split("\n");
315
+ buffer = lines.pop() || "";
316
+ for (const line of lines) {
317
+ const trimmed = line.trim();
318
+ if (trimmed.startsWith("data:")) {
319
+ const jsonStr = trimmed.replace(/^data:\s*/, "").trim();
320
+ if (jsonStr === "[DONE]") {
321
+ handlers.onEnd?.();
322
+ return;
323
+ }
324
+ try {
325
+ const parsed = JSON.parse(jsonStr);
326
+ handlers.onData?.(parsed);
327
+ } catch (e) {
328
+ }
329
+ }
330
+ }
331
+ });
332
+ stream.on("end", () => {
333
+ handlers.onEnd?.();
334
+ });
335
+ stream.on("error", (err) => {
336
+ handlers.onError?.(err);
337
+ });
338
+ }
339
+ /**
340
+ * Tìm kiếm & gợi ý tối đa 3 địa chỉ chuẩn hóa (Search & Suggest)
341
+ * Chuẩn REST endpoint: POST /api/map/search
342
+ */
343
+ async search(req, options) {
344
+ const response = await this.http.post(
345
+ "/api/map/search",
346
+ req,
347
+ options
348
+ );
349
+ return response.data;
350
+ }
351
+ /**
352
+ * Giải mã tọa độ GPS sang địa chỉ Google & Goong Maps (Reverse Geocode)
353
+ * Chuẩn REST endpoint: POST /api/map/reverse
354
+ */
355
+ async reverse(req, options) {
356
+ const payload = {
357
+ lat: req.lat ?? req.latitude,
358
+ lng: req.lng ?? req.longitude,
359
+ origin: req.origin
360
+ };
361
+ const response = await this.http.post(
362
+ "/api/map/reverse",
363
+ payload,
364
+ options
365
+ );
366
+ return response.data;
367
+ }
368
+ /**
369
+ * Tra cứu chi tiết địa điểm Place Details
370
+ * Chuẩn REST endpoint: POST /api/map/lookup
371
+ */
372
+ async lookup(req, options) {
373
+ const response = await this.http.post(
374
+ "/api/map/lookup",
375
+ req,
376
+ options
377
+ );
378
+ return response.data;
379
+ }
380
+ /**
381
+ * Lấy chi tiết địa điểm Google Maps
382
+ * Chuẩn REST endpoint: POST /api/map/place/detail
383
+ */
384
+ async getPlaceDetail(req, options) {
385
+ const response = await this.http.post(
386
+ "/api/map/place/detail",
387
+ req,
388
+ options
389
+ );
390
+ return response.data;
391
+ }
392
+ /**
393
+ * Geocode địa chỉ văn bản thành tọa độ (Alias cho search)
394
+ */
395
+ async geocodeAddress(address, options) {
396
+ const payload = typeof address === "string" ? { address } : address;
397
+ const result = await this.search(payload, options);
398
+ return result;
399
+ }
400
+ /**
401
+ * Reverse geocode tọa độ ra địa chỉ Việt Nam (Alias cho reverse)
402
+ */
403
+ async reverseGeocode(req, options) {
404
+ const result = await this.reverse(req, options);
405
+ return result;
406
+ }
407
+ };
408
+
409
+ // src/modules/social-tracer/index.ts
410
+ var SocialTracerModule = class {
411
+ constructor(http) {
412
+ this.http = http;
413
+ }
414
+ /**
415
+ * Lấy danh sách hơn 400+ nền tảng mạng xã hội được hỗ trợ truy vết
416
+ * Chuẩn REST endpoint: GET /api/social-tracer/platforms
417
+ */
418
+ async getPlatforms(options) {
419
+ const response = await this.http.get(
420
+ "/api/social-tracer/platforms",
421
+ options
422
+ );
423
+ const data = response.data;
424
+ return {
425
+ count: data.total ?? data.count ?? (Array.isArray(data.platforms) ? data.platforms.length : 0),
426
+ platforms: data.platforms || []
427
+ };
428
+ }
429
+ /**
430
+ * Truy vết đồng bộ danh tính mạng xã hội theo username trên hàng trăm trang
431
+ * Chuẩn REST endpoint: POST /api/social-tracer/search
432
+ */
433
+ async traceSync(payload, options) {
434
+ const body = {
435
+ username: payload.username,
436
+ platforms: payload.platforms,
437
+ concurrency: payload.concurrency,
438
+ timeout: payload.timeout_per_site || payload.timeout || 8
439
+ };
440
+ const response = await this.http.post(
441
+ "/api/social-tracer/search",
442
+ body,
443
+ options
444
+ );
445
+ const data = response.data;
446
+ const rawProfiles = data.profiles || data.results || data.data || [];
447
+ const normalizedResults = rawProfiles.map((p) => {
448
+ const isClaimed = p.status === "claimed" || p.status === "FOUND";
449
+ const isAvailable = p.status === "available" || p.status === "NOT_FOUND";
450
+ return {
451
+ platform: p.platform || p.platform_id || "",
452
+ url: p.url_user || p.url || "",
453
+ status: isClaimed ? "FOUND" : isAvailable ? "NOT_FOUND" : String(p.status).toUpperCase(),
454
+ http_status: p.http_status,
455
+ response_time: p.response_time_ms ?? p.response_time,
456
+ category: p.context || p.category
457
+ };
458
+ });
459
+ const totalFound = data.total_found ?? data.found_count ?? normalizedResults.filter((r) => r.status === "FOUND").length;
460
+ const totalChecked = data.total_checked ?? normalizedResults.length;
461
+ return {
462
+ username: data.username || payload.username,
463
+ total_checked: totalChecked,
464
+ found_count: totalFound,
465
+ not_found_count: data.not_found_count ?? totalChecked - totalFound,
466
+ duration_seconds: data.duration_seconds ?? 0,
467
+ results: normalizedResults
468
+ };
469
+ }
470
+ /**
471
+ * Stream SSE quá trình truy vết mạng xã hội thời gian thực
472
+ * Chuẩn REST endpoint: GET /api/social-tracer/stream
473
+ */
474
+ async streamTrace(payload, handlers, options) {
475
+ const params = new URLSearchParams();
476
+ params.set("username", payload.username);
477
+ const timeout = payload.timeout_per_site || payload.timeout;
478
+ if (timeout) params.set("timeout", String(timeout));
479
+ if (payload.concurrency) params.set("concurrency", String(payload.concurrency));
480
+ if (payload.platforms?.length) {
481
+ params.set("platforms", payload.platforms.join(","));
482
+ }
483
+ const response = await this.http.get(
484
+ `/api/social-tracer/stream?${params.toString()}`,
485
+ {
486
+ ...options,
487
+ responseType: "stream",
488
+ headers: {
489
+ Accept: "text/event-stream",
490
+ ...options?.headers || {}
491
+ }
492
+ }
493
+ );
494
+ const stream = response.data;
495
+ let buffer = "";
496
+ stream.on("data", (chunk) => {
497
+ buffer += chunk.toString();
498
+ const lines = buffer.split("\n");
499
+ buffer = lines.pop() || "";
500
+ for (const line of lines) {
501
+ const trimmed = line.trim();
502
+ if (trimmed.startsWith("data:")) {
503
+ const jsonStr = trimmed.replace(/^data:\s*/, "").trim();
504
+ if (jsonStr === "[DONE]") {
505
+ handlers.onEnd?.();
506
+ return;
507
+ }
508
+ try {
509
+ const parsed = JSON.parse(jsonStr);
510
+ handlers.onData?.(parsed);
511
+ } catch (e) {
512
+ }
513
+ }
514
+ }
515
+ });
516
+ stream.on("end", () => {
517
+ handlers.onEnd?.();
518
+ });
519
+ stream.on("error", (err) => {
520
+ handlers.onError?.(err);
521
+ });
522
+ }
523
+ /**
524
+ * Tạo background job truy vết danh tính mạng xã hội
525
+ * Chuẩn REST endpoint: POST /api/social-tracer/jobs
526
+ */
527
+ async createJob(payload, options) {
528
+ const response = await this.http.post(
529
+ "/api/social-tracer/jobs",
530
+ payload,
531
+ options
532
+ );
533
+ return response.data;
534
+ }
535
+ /**
536
+ * Kiểm tra trạng thái job truy vết
537
+ * Chuẩn REST endpoint: GET /api/social-tracer/jobs/{job_id}
538
+ */
539
+ async getJobStatus(jobId, options) {
540
+ const response = await this.http.get(
541
+ `/api/social-tracer/jobs/${jobId}`,
542
+ options
543
+ );
544
+ return response.data;
545
+ }
546
+ /**
547
+ * Lấy kết quả truy vết từ job
548
+ */
549
+ async getJobResults(jobId, options) {
550
+ const response = await this.http.get(
551
+ `/api/social-tracer/jobs/${jobId}`,
552
+ options
553
+ );
554
+ const data = response.data;
555
+ const profiles = data.data || data.profiles || data.results || [];
556
+ return {
557
+ job_id: jobId,
558
+ status: data.status,
559
+ username: data.username || "",
560
+ total_results: data.total_results || profiles.length,
561
+ results: profiles
562
+ };
563
+ }
564
+ /**
565
+ * Xuất file CSV kết quả truy vết mạng xã hội (trả về Buffer)
566
+ * Chuẩn REST endpoint: GET /api/social-tracer/jobs/{job_id}/export
567
+ */
568
+ async exportCsv(jobId, options) {
569
+ const response = await this.http.get(
570
+ `/api/social-tracer/jobs/${jobId}/export`,
571
+ {
572
+ ...options,
573
+ params: { only_found: true, ...options?.params || {} },
574
+ responseType: "arraybuffer"
575
+ }
576
+ );
577
+ return Buffer.from(response.data);
578
+ }
579
+ };
580
+
581
+ // src/modules/ocr/index.ts
582
+ import FormData from "form-data";
583
+ var OcrModule = class {
584
+ constructor(http) {
585
+ this.http = http;
586
+ }
587
+ /**
588
+ * Bóc tách thông tin thẻ Căn cước công dân (CCCD) gắn chip/mã QR qua Base64 hoặc URL
589
+ */
590
+ async extractCccd(payload, options) {
591
+ const response = await this.http.post(
592
+ "/api/cccd/extract",
593
+ payload,
594
+ options
595
+ );
596
+ return response.data;
597
+ }
598
+ /**
599
+ * Upload file ảnh trực tiếp để bóc tách thông tin CCCD
600
+ */
601
+ async uploadAndExtractCccd(fileBuffer, filename = "cccd.jpg", options) {
602
+ const formData = new FormData();
603
+ formData.append("file", fileBuffer, filename);
604
+ const response = await this.http.post(
605
+ "/api/cccd/upload",
606
+ formData,
607
+ {
608
+ ...options,
609
+ headers: {
610
+ ...formData.getHeaders(),
611
+ ...options?.headers || {}
612
+ }
613
+ }
614
+ );
615
+ return response.data;
616
+ }
617
+ /**
618
+ * Thẩm định tính hợp pháp và các đặc trưng bảo an thẻ CCCD
619
+ */
620
+ async verifyCccd(payload, options) {
621
+ const response = await this.http.post(
622
+ "/api/cccd/verify",
623
+ payload,
624
+ options
625
+ );
626
+ return response.data;
627
+ }
628
+ /**
629
+ * Bóc tách Giấy chứng nhận đăng ký doanh nghiệp / hộ kinh doanh qua JSON (Base64 hoặc URL)
630
+ */
631
+ async extractBusinessLicense(payload, options) {
632
+ const response = await this.http.post(
633
+ "/api/business-license/extract",
634
+ payload,
635
+ options
636
+ );
637
+ return response.data;
638
+ }
639
+ /**
640
+ * Upload file ảnh/PDF trực tiếp để bóc tách Giấy phép ĐKKD
641
+ */
642
+ async uploadAndExtractBusinessLicense(fileBuffer, filename = "giay_phep_kinh_doanh.pdf", options) {
643
+ const formData = new FormData();
644
+ formData.append("file", fileBuffer, filename);
645
+ const response = await this.http.post(
646
+ "/api/business-license/upload",
647
+ formData,
648
+ {
649
+ ...options,
650
+ headers: {
651
+ ...formData.getHeaders(),
652
+ ...options?.headers || {}
653
+ }
654
+ }
655
+ );
656
+ return response.data;
657
+ }
658
+ /**
659
+ * Thẩm định 6 lớp bảo an Giấy phép kinh doanh (Chống cắt ghép, ELA, con dấu đỏ, chữ ký)
660
+ */
661
+ async verifyBusinessLicense(payload, options) {
662
+ const response = await this.http.post(
663
+ "/api/business-license/verify",
664
+ payload,
665
+ options
666
+ );
667
+ return response.data;
668
+ }
669
+ };
670
+
671
+ // src/modules/ip-geolocation/index.ts
672
+ var IpGeolocationModule = class {
673
+ constructor(http) {
674
+ this.http = http;
675
+ }
676
+ /**
677
+ * Tra cứu vị trí địa lý, tọa độ GPS (lat, lon) và nhà mạng ISP từ 1 hoặc nhiều IP
678
+ * Chuẩn REST endpoint: POST /api/ip-location/check
679
+ */
680
+ async lookup(request, options) {
681
+ let payload;
682
+ if (typeof request === "string") {
683
+ payload = { ip: request };
684
+ } else if (Array.isArray(request)) {
685
+ payload = { ips: request };
686
+ } else {
687
+ payload = request;
688
+ }
689
+ const response = await this.http.post(
690
+ "/api/ip-location/check",
691
+ payload,
692
+ options
693
+ );
694
+ return response.data;
695
+ }
696
+ /**
697
+ * Tự động lấy IP Public hiện tại của client / server và vị trí địa lý
698
+ * Chuẩn REST endpoint: GET /api/ip-location/my-ip
699
+ */
700
+ async getMyPublicIp(options) {
701
+ const response = await this.http.get(
702
+ "/api/ip-location/my-ip",
703
+ options
704
+ );
705
+ return response.data;
706
+ }
707
+ };
708
+
709
+ // src/modules/image-compare/index.ts
710
+ var ImageCompareModule = class {
711
+ constructor(http) {
712
+ this.http = http;
713
+ }
714
+ /**
715
+ * So sánh nội dung & độ tương đồng giữa 2 bức ảnh (qua URL hoặc Base64)
716
+ * Chuẩn REST endpoint: POST /api/image-compare/compare
717
+ */
718
+ async compare(request, options) {
719
+ const response = await this.http.post(
720
+ "/api/image-compare/compare",
721
+ request,
722
+ options
723
+ );
724
+ return response.data;
725
+ }
726
+ /**
727
+ * Chụp màn hình 2 trang web và so sánh độ lệch UI (Visual Regression Testing)
728
+ * Chuẩn REST endpoint: POST /api/image-compare/compare-webpages
729
+ */
730
+ async compareWebpages(request, options) {
731
+ const response = await this.http.post(
732
+ "/api/image-compare/compare-webpages",
733
+ request,
734
+ options
735
+ );
736
+ return response.data;
737
+ }
738
+ };
739
+
740
+ // src/modules/web-qa/index.ts
741
+ var WebQaModule = class {
742
+ constructor(http) {
743
+ this.http = http;
744
+ }
745
+ /**
746
+ * Chạy audit toàn diện 5 lớp chuẩn QA/Tester cho website (SEO, Accessibility, Console errors, Broken links)
747
+ * Chuẩn REST endpoint: POST /api/web-qa/audit
748
+ */
749
+ async audit(request, options) {
750
+ const response = await this.http.post(
751
+ "/api/web-qa/audit",
752
+ request,
753
+ options
754
+ );
755
+ return response.data;
756
+ }
757
+ /**
758
+ * Thực thi kịch bản tương tác E2E (Click, Fill, Hover, Scroll) & Giám sát lỗi
759
+ * Chuẩn REST endpoint: POST /api/web-qa/interact
760
+ */
761
+ async interact(request, options) {
762
+ const response = await this.http.post(
763
+ "/api/web-qa/interact",
764
+ request,
765
+ options
766
+ );
767
+ return response.data;
768
+ }
769
+ /**
770
+ * Chaos Auto-Fuzzing: Tự động quét và click thử các nút/tab an toàn
771
+ * Chuẩn REST endpoint: POST /api/web-qa/fuzz
772
+ */
773
+ async fuzz(request, options) {
774
+ const response = await this.http.post(
775
+ "/api/web-qa/fuzz",
776
+ request,
777
+ options
778
+ );
779
+ return response.data;
780
+ }
781
+ };
782
+
783
+ // src/modules/screenshot/index.ts
784
+ var ScreenshotModule = class {
785
+ constructor(http) {
786
+ this.http = http;
787
+ }
788
+ /**
789
+ * Chụp ảnh màn hình website / MiniApp
790
+ * Chuẩn REST endpoint: POST /api/screenshot/capture
791
+ */
792
+ async capture(request, options) {
793
+ const response = await this.http.post(
794
+ "/api/screenshot/capture",
795
+ request,
796
+ options
797
+ );
798
+ return response.data;
799
+ }
800
+ /**
801
+ * Chẩn đoán F12 console logs & network trang web
802
+ * Chuẩn REST endpoint: POST /api/screenshot/diagnose
803
+ */
804
+ async diagnose(request, options) {
805
+ const response = await this.http.post(
806
+ "/api/screenshot/diagnose",
807
+ request,
808
+ options
809
+ );
810
+ return response.data;
811
+ }
812
+ };
813
+
814
+ // src/client.ts
815
+ var RedaiToolClient = class {
816
+ constructor(config = {}) {
817
+ const defaultBaseUrl = typeof process !== "undefined" && process.env?.REDAI_TOOL_BASE_URL ? process.env.REDAI_TOOL_BASE_URL : "http://localhost:8000";
818
+ const defaultApiKey = typeof process !== "undefined" && process.env?.REDAI_TOOL_API_KEY ? process.env.REDAI_TOOL_API_KEY : "";
819
+ this.config = {
820
+ baseUrl: config.baseUrl || defaultBaseUrl,
821
+ apiKey: config.apiKey || defaultApiKey,
822
+ timeout: config.timeout ?? 6e4,
823
+ headers: config.headers ?? {}
824
+ };
825
+ const headers = {
826
+ Accept: "application/json",
827
+ "Content-Type": "application/json",
828
+ ...this.config.headers
829
+ };
830
+ if (this.config.apiKey) {
831
+ headers["X-API-Key"] = this.config.apiKey;
832
+ }
833
+ this.http = axios.create({
834
+ baseURL: this.config.baseUrl,
835
+ timeout: this.config.timeout,
836
+ headers
837
+ });
838
+ this.http.interceptors.response.use(
839
+ (response) => response,
840
+ (error) => {
841
+ if (error.code === "ECONNABORTED" || error.message.includes("timeout")) {
842
+ return Promise.reject(
843
+ new RedaiToolTimeoutError(
844
+ `Y\xEAu c\u1EA7u t\u1EDBi redai-tool (${error.config?.url}) \u0111\xE3 h\u1EBFt h\u1EA1n sau ${this.config.timeout}ms`
845
+ )
846
+ );
847
+ }
848
+ if (error.response?.status === 401 || error.response?.status === 403) {
849
+ return Promise.reject(
850
+ new RedaiToolAuthError(
851
+ `L\u1ED7i x\xE1c th\u1EF1c: X-API-Key kh\xF4ng h\u1EE3p l\u1EC7 ho\u1EB7c thi\u1EBFu khi g\u1ECDi ${error.config?.url}`
852
+ )
853
+ );
854
+ }
855
+ const data = error.response?.data;
856
+ const msg = data?.detail || data?.message || data?.error || error.message || "L\u1ED7i kh\xF4ng x\xE1c \u0111\u1ECBnh t\u1EEB redai-tool";
857
+ return Promise.reject(
858
+ new RedaiToolApiError(msg, error.response?.status, data)
859
+ );
860
+ }
861
+ );
862
+ this.googleSearch = new GoogleSearchModule(this.http);
863
+ this.googleMaps = new GoogleMapsModule(this.http);
864
+ this.socialTracer = new SocialTracerModule(this.http);
865
+ this.ocr = new OcrModule(this.http);
866
+ this.ip = new IpGeolocationModule(this.http);
867
+ this.imageCompare = new ImageCompareModule(this.http);
868
+ this.webQa = new WebQaModule(this.http);
869
+ this.screenshot = new ScreenshotModule(this.http);
870
+ }
871
+ /**
872
+ * Kiểm tra tình trạng kết nối tới service redai-tool
873
+ */
874
+ async healthCheck() {
875
+ try {
876
+ const resp = await this.http.get("/health");
877
+ return resp.data;
878
+ } catch {
879
+ return { status: "down" };
880
+ }
881
+ }
882
+ };
883
+
884
+ // src/index.ts
885
+ var index_default = RedaiToolClient;
886
+ export {
887
+ GoogleMapsModule,
888
+ GoogleSearchModule,
889
+ ImageCompareModule,
890
+ IpGeolocationModule,
891
+ OcrModule,
892
+ RedaiToolApiError,
893
+ RedaiToolAuthError,
894
+ RedaiToolClient,
895
+ RedaiToolError,
896
+ RedaiToolTimeoutError,
897
+ ScreenshotModule,
898
+ SocialTracerModule,
899
+ WebQaModule,
900
+ index_default as default
901
+ };
902
+ //# sourceMappingURL=index.mjs.map