@redonvn/redai-tool 1.0.0 → 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 CHANGED
@@ -84,30 +84,83 @@ var GoogleSearchModule = class {
84
84
  constructor(http) {
85
85
  this.http = http;
86
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
+ }
87
118
  /**
88
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
89
121
  */
90
122
  async list(request, options) {
123
+ const payload = {
124
+ ...request,
125
+ limit: request.max_results || request.limit || 10
126
+ };
91
127
  const response = await this.http.post(
92
128
  "/api/google-search/list",
93
- request,
129
+ payload,
94
130
  options
95
131
  );
96
- return response.data;
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
+ };
97
143
  }
98
144
  /**
99
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
100
147
  */
101
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
+ };
102
154
  const response = await this.http.post(
103
- "/api/google-search/scrape",
104
- request,
155
+ "/api/google-search/search",
156
+ payload,
105
157
  options
106
158
  );
107
- return response.data;
159
+ return this.normalizeScrapeResponse(response.data, request.keyword);
108
160
  }
109
161
  /**
110
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
111
164
  */
112
165
  async scrapeDetails(request, options) {
113
166
  const response = await this.http.post(
@@ -115,15 +168,42 @@ var GoogleSearchModule = class {
115
168
  request,
116
169
  options
117
170
  );
118
- return response.data;
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
+ };
119
194
  }
120
195
  /**
121
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
122
198
  */
123
199
  async stream(request, handlers, options) {
124
200
  const params = new URLSearchParams();
125
201
  params.set("keyword", request.keyword);
126
- if (request.max_results) params.set("max_results", String(request.max_results));
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
+ }
127
207
  if (request.deep_crawl !== void 0) params.set("deep_crawl", String(request.deep_crawl));
128
208
  if (request.summary_mode) params.set("summary_mode", request.summary_mode);
129
209
  if (request.target_sites?.length) {
@@ -169,50 +249,40 @@ var GoogleSearchModule = class {
169
249
  handlers.onError?.(err);
170
250
  });
171
251
  }
172
- };
173
-
174
- // src/modules/google-maps/index.ts
175
- var GoogleMapsModule = class {
176
- constructor(http) {
177
- this.http = http;
178
- }
179
252
  /**
180
- * Tạo background job cào dữ liệu Google Maps
253
+ * Tạo background job cào tìm kiếm Google
254
+ * Chuẩn REST endpoint: POST /api/google-search/jobs
181
255
  */
182
- async createJob(payload, options) {
256
+ async createJob(request, options) {
257
+ const payload = {
258
+ ...request,
259
+ limit: request.max_results || request.limit || 10
260
+ };
183
261
  const response = await this.http.post(
184
- "/api/map/jobs",
262
+ "/api/google-search/jobs",
185
263
  payload,
186
264
  options
187
265
  );
188
266
  return response.data;
189
267
  }
190
268
  /**
191
- * Kiểm tra trạng thái và tiến độ của job cào Google Maps
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}
192
271
  */
193
272
  async getJobStatus(jobId, options) {
194
273
  const response = await this.http.get(
195
- `/api/map/jobs/${jobId}`,
196
- options
197
- );
198
- return response.data;
199
- }
200
- /**
201
- * Lấy danh sách kết quả địa điểm thu thập được từ job
202
- */
203
- async getJobResults(jobId, options) {
204
- const response = await this.http.get(
205
- `/api/map/jobs/${jobId}/results`,
274
+ `/api/google-search/jobs/${jobId}`,
206
275
  options
207
276
  );
208
277
  return response.data;
209
278
  }
210
279
  /**
211
- * Xuất kết quả cào Maps dạng file CSV (trả về Buffer)
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
212
282
  */
213
283
  async exportCsv(jobId, options) {
214
284
  const response = await this.http.get(
215
- `/api/map/jobs/${jobId}/export/csv`,
285
+ `/api/google-search/jobs/${jobId}/export`,
216
286
  {
217
287
  ...options,
218
288
  responseType: "arraybuffer"
@@ -220,25 +290,63 @@ var GoogleMapsModule = class {
220
290
  );
221
291
  return Buffer.from(response.data);
222
292
  }
293
+ };
294
+
295
+ // src/modules/google-maps/index.ts
296
+ var GoogleMapsModule = class {
297
+ constructor(http) {
298
+ this.http = http;
299
+ }
223
300
  /**
224
- * Xuất kết quả cào Maps dạng file Excel XLSX (trả về Buffer)
301
+ * Tạo background job cào dữ liệu Google Maps
302
+ * Chuẩn REST endpoint: POST /api/map/scrape/async
225
303
  */
226
- async exportExcel(jobId, options) {
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) {
227
317
  const response = await this.http.get(
228
- `/api/map/jobs/${jobId}/export/excel`,
229
- {
230
- ...options,
231
- responseType: "arraybuffer"
232
- }
318
+ `/api/map/scrape/status/${jobId}`,
319
+ options
233
320
  );
234
- return Buffer.from(response.data);
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
+ };
235
341
  }
236
342
  /**
237
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
238
345
  */
239
- async streamJob(jobId, handlers, options) {
240
- const response = await this.http.get(
241
- `/api/map/jobs/${jobId}/stream`,
346
+ async streamJob(payload, handlers, options) {
347
+ const response = await this.http.post(
348
+ "/api/map/scrape/stream",
349
+ payload,
242
350
  {
243
351
  ...options,
244
352
  responseType: "stream",
@@ -278,39 +386,73 @@ var GoogleMapsModule = class {
278
386
  });
279
387
  }
280
388
  /**
281
- * Geocode địa chỉ văn bản thành tọa độ và các cấp hành chính Việt Nam
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
282
391
  */
283
- async geocodeAddress(address, options) {
284
- const payload = typeof address === "string" ? { address } : address;
392
+ async search(req, options) {
285
393
  const response = await this.http.post(
286
- "/api/map/geocode/address",
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",
287
412
  payload,
288
413
  options
289
414
  );
290
415
  return response.data;
291
416
  }
292
417
  /**
293
- * Reverse geocode tọa độ ra địa chỉ Việt Nam
418
+ * Tra cứu chi tiết địa điểm Place Details
419
+ * Chuẩn REST endpoint: POST /api/map/lookup
294
420
  */
295
- async reverseGeocode(req, options) {
421
+ async lookup(req, options) {
296
422
  const response = await this.http.post(
297
- "/api/map/geocode/coordinates",
423
+ "/api/map/lookup",
298
424
  req,
299
425
  options
300
426
  );
301
427
  return response.data;
302
428
  }
303
429
  /**
304
- * Chuẩn hóa và bóc tách địa chỉ đa năng (Số nhà, đường, phường xã, quận huyện, tỉnh thành)
430
+ * Lấy chi tiết địa điểm Google Maps
431
+ * Chuẩn REST endpoint: POST /api/map/place/detail
305
432
  */
306
- async parseAddressUniversal(req, options) {
433
+ async getPlaceDetail(req, options) {
307
434
  const response = await this.http.post(
308
- "/api/map/address/universal-parse",
435
+ "/api/map/place/detail",
309
436
  req,
310
437
  options
311
438
  );
312
439
  return response.data;
313
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
+ }
314
456
  };
315
457
 
316
458
  // src/modules/social-tracer/index.ts
@@ -320,38 +462,75 @@ var SocialTracerModule = class {
320
462
  }
321
463
  /**
322
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
323
466
  */
324
467
  async getPlatforms(options) {
325
468
  const response = await this.http.get(
326
469
  "/api/social-tracer/platforms",
327
470
  options
328
471
  );
329
- return response.data;
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
+ };
330
477
  }
331
478
  /**
332
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
333
481
  */
334
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
+ };
335
489
  const response = await this.http.post(
336
- "/api/social-tracer/trace",
337
- payload,
490
+ "/api/social-tracer/search",
491
+ body,
338
492
  options
339
493
  );
340
- return response.data;
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
+ };
341
518
  }
342
519
  /**
343
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
344
522
  */
345
523
  async streamTrace(payload, handlers, options) {
346
524
  const params = new URLSearchParams();
347
525
  params.set("username", payload.username);
348
- if (payload.timeout_per_site) params.set("timeout_per_site", String(payload.timeout_per_site));
526
+ const timeout = payload.timeout_per_site || payload.timeout;
527
+ if (timeout) params.set("timeout", String(timeout));
349
528
  if (payload.concurrency) params.set("concurrency", String(payload.concurrency));
350
529
  if (payload.platforms?.length) {
351
- payload.platforms.forEach((p) => params.append("platforms", p));
530
+ params.set("platforms", payload.platforms.join(","));
352
531
  }
353
532
  const response = await this.http.get(
354
- `/api/social-tracer/trace/stream?${params.toString()}`,
533
+ `/api/social-tracer/stream?${params.toString()}`,
355
534
  {
356
535
  ...options,
357
536
  responseType: "stream",
@@ -392,6 +571,7 @@ var SocialTracerModule = class {
392
571
  }
393
572
  /**
394
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
395
575
  */
396
576
  async createJob(payload, options) {
397
577
  const response = await this.http.post(
@@ -403,6 +583,7 @@ var SocialTracerModule = class {
403
583
  }
404
584
  /**
405
585
  * Kiểm tra trạng thái job truy vết
586
+ * Chuẩn REST endpoint: GET /api/social-tracer/jobs/{job_id}
406
587
  */
407
588
  async getJobStatus(jobId, options) {
408
589
  const response = await this.http.get(
@@ -416,19 +597,29 @@ var SocialTracerModule = class {
416
597
  */
417
598
  async getJobResults(jobId, options) {
418
599
  const response = await this.http.get(
419
- `/api/social-tracer/jobs/${jobId}/results`,
600
+ `/api/social-tracer/jobs/${jobId}`,
420
601
  options
421
602
  );
422
- return response.data;
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
+ };
423
612
  }
424
613
  /**
425
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
426
616
  */
427
617
  async exportCsv(jobId, options) {
428
618
  const response = await this.http.get(
429
- `/api/social-tracer/jobs/${jobId}/export/csv`,
619
+ `/api/social-tracer/jobs/${jobId}/export`,
430
620
  {
431
621
  ...options,
622
+ params: { only_found: true, ...options?.params || {} },
432
623
  responseType: "arraybuffer"
433
624
  }
434
625
  );
@@ -533,6 +724,7 @@ var IpGeolocationModule = class {
533
724
  }
534
725
  /**
535
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
536
728
  */
537
729
  async lookup(request, options) {
538
730
  let payload;
@@ -544,7 +736,7 @@ var IpGeolocationModule = class {
544
736
  payload = request;
545
737
  }
546
738
  const response = await this.http.post(
547
- "/api/ip-location",
739
+ "/api/ip-location/check",
548
740
  payload,
549
741
  options
550
742
  );
@@ -552,6 +744,7 @@ var IpGeolocationModule = class {
552
744
  }
553
745
  /**
554
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
555
748
  */
556
749
  async getMyPublicIp(options) {
557
750
  const response = await this.http.get(
@@ -569,10 +762,11 @@ var ImageCompareModule = class {
569
762
  }
570
763
  /**
571
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
572
766
  */
573
767
  async compare(request, options) {
574
768
  const response = await this.http.post(
575
- "/api/image-compare",
769
+ "/api/image-compare/compare",
576
770
  request,
577
771
  options
578
772
  );
@@ -580,6 +774,7 @@ var ImageCompareModule = class {
580
774
  }
581
775
  /**
582
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
583
778
  */
584
779
  async compareWebpages(request, options) {
585
780
  const response = await this.http.post(
@@ -597,22 +792,36 @@ var WebQaModule = class {
597
792
  this.http = http;
598
793
  }
599
794
  /**
600
- * Hỏi đáp AI dựa trên nội dung được cào trực tiếp từ URL website
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
601
797
  */
602
- async ask(request, options) {
798
+ async audit(request, options) {
603
799
  const response = await this.http.post(
604
- "/api/web-qa/ask",
800
+ "/api/web-qa/audit",
605
801
  request,
606
802
  options
607
803
  );
608
804
  return response.data;
609
805
  }
610
806
  /**
611
- * Chạy audit toàn diện 5 lớp chuẩn QA/Tester cho website (SEO, Accessibility, Console errors, Broken links)
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
612
809
  */
613
- async audit(request, options) {
810
+ async interact(request, options) {
614
811
  const response = await this.http.post(
615
- "/api/web-qa/audit",
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",
616
825
  request,
617
826
  options
618
827
  );
@@ -626,7 +835,8 @@ var ScreenshotModule = class {
626
835
  this.http = http;
627
836
  }
628
837
  /**
629
- * Chụp ảnh màn hình website (hỗ trợ full-page, kích thước tùy chỉnh)
838
+ * Chụp ảnh màn hình website / MiniApp
839
+ * Chuẩn REST endpoint: POST /api/screenshot/capture
630
840
  */
631
841
  async capture(request, options) {
632
842
  const response = await this.http.post(
@@ -637,18 +847,16 @@ var ScreenshotModule = class {
637
847
  return response.data;
638
848
  }
639
849
  /**
640
- * Chụp ảnh màn hình và trả về trực tiếp binary Buffer ảnh
850
+ * Chẩn đoán F12 console logs & network trang web
851
+ * Chuẩn REST endpoint: POST /api/screenshot/diagnose
641
852
  */
642
- async captureAsBuffer(request, options) {
853
+ async diagnose(request, options) {
643
854
  const response = await this.http.post(
644
- "/api/screenshot/render",
855
+ "/api/screenshot/diagnose",
645
856
  request,
646
- {
647
- ...options,
648
- responseType: "arraybuffer"
649
- }
857
+ options
650
858
  );
651
- return Buffer.from(response.data);
859
+ return response.data;
652
860
  }
653
861
  };
654
862