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