@redonvn/redai-tool 0.0.0-stage → 1.0.0
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/README.md +172 -2
- package/dist/index.d.mts +761 -0
- package/dist/index.d.ts +761 -0
- package/dist/index.js +743 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +694 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +55 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,743 @@
|
|
|
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
|
+
* Tìm kiếm danh sách kết quả nhanh trên Google (không crawl sâu chi tiết)
|
|
89
|
+
*/
|
|
90
|
+
async list(request, options) {
|
|
91
|
+
const response = await this.http.post(
|
|
92
|
+
"/api/google-search/list",
|
|
93
|
+
request,
|
|
94
|
+
options
|
|
95
|
+
);
|
|
96
|
+
return response.data;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* 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...)
|
|
100
|
+
*/
|
|
101
|
+
async scrape(request, options) {
|
|
102
|
+
const response = await this.http.post(
|
|
103
|
+
"/api/google-search/scrape",
|
|
104
|
+
request,
|
|
105
|
+
options
|
|
106
|
+
);
|
|
107
|
+
return response.data;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* 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
|
|
111
|
+
*/
|
|
112
|
+
async scrapeDetails(request, options) {
|
|
113
|
+
const response = await this.http.post(
|
|
114
|
+
"/api/google-search/detail",
|
|
115
|
+
request,
|
|
116
|
+
options
|
|
117
|
+
);
|
|
118
|
+
return response.data;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Stream SSE kết quả tìm kiếm và bóc tách theo thời gian thực
|
|
122
|
+
*/
|
|
123
|
+
async stream(request, handlers, options) {
|
|
124
|
+
const params = new URLSearchParams();
|
|
125
|
+
params.set("keyword", request.keyword);
|
|
126
|
+
if (request.max_results) params.set("max_results", String(request.max_results));
|
|
127
|
+
if (request.deep_crawl !== void 0) params.set("deep_crawl", String(request.deep_crawl));
|
|
128
|
+
if (request.summary_mode) params.set("summary_mode", request.summary_mode);
|
|
129
|
+
if (request.target_sites?.length) {
|
|
130
|
+
request.target_sites.forEach((site) => params.append("target_sites", site));
|
|
131
|
+
}
|
|
132
|
+
const response = await this.http.get(
|
|
133
|
+
`/api/google-search/stream?${params.toString()}`,
|
|
134
|
+
{
|
|
135
|
+
...options,
|
|
136
|
+
responseType: "stream",
|
|
137
|
+
headers: {
|
|
138
|
+
Accept: "text/event-stream",
|
|
139
|
+
...options?.headers || {}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
);
|
|
143
|
+
const stream = response.data;
|
|
144
|
+
let buffer = "";
|
|
145
|
+
stream.on("data", (chunk) => {
|
|
146
|
+
buffer += chunk.toString();
|
|
147
|
+
const lines = buffer.split("\n");
|
|
148
|
+
buffer = lines.pop() || "";
|
|
149
|
+
for (const line of lines) {
|
|
150
|
+
const trimmed = line.trim();
|
|
151
|
+
if (trimmed.startsWith("data:")) {
|
|
152
|
+
const jsonStr = trimmed.replace(/^data:\s*/, "").trim();
|
|
153
|
+
if (jsonStr === "[DONE]") {
|
|
154
|
+
handlers.onEnd?.();
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
try {
|
|
158
|
+
const parsed = JSON.parse(jsonStr);
|
|
159
|
+
handlers.onData?.(parsed);
|
|
160
|
+
} catch (e) {
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
stream.on("end", () => {
|
|
166
|
+
handlers.onEnd?.();
|
|
167
|
+
});
|
|
168
|
+
stream.on("error", (err) => {
|
|
169
|
+
handlers.onError?.(err);
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
// src/modules/google-maps/index.ts
|
|
175
|
+
var GoogleMapsModule = class {
|
|
176
|
+
constructor(http) {
|
|
177
|
+
this.http = http;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Tạo background job cào dữ liệu Google Maps
|
|
181
|
+
*/
|
|
182
|
+
async createJob(payload, options) {
|
|
183
|
+
const response = await this.http.post(
|
|
184
|
+
"/api/map/jobs",
|
|
185
|
+
payload,
|
|
186
|
+
options
|
|
187
|
+
);
|
|
188
|
+
return response.data;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Kiểm tra trạng thái và tiến độ của job cào Google Maps
|
|
192
|
+
*/
|
|
193
|
+
async getJobStatus(jobId, options) {
|
|
194
|
+
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`,
|
|
206
|
+
options
|
|
207
|
+
);
|
|
208
|
+
return response.data;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Xuất kết quả cào Maps dạng file CSV (trả về Buffer)
|
|
212
|
+
*/
|
|
213
|
+
async exportCsv(jobId, options) {
|
|
214
|
+
const response = await this.http.get(
|
|
215
|
+
`/api/map/jobs/${jobId}/export/csv`,
|
|
216
|
+
{
|
|
217
|
+
...options,
|
|
218
|
+
responseType: "arraybuffer"
|
|
219
|
+
}
|
|
220
|
+
);
|
|
221
|
+
return Buffer.from(response.data);
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Xuất kết quả cào Maps dạng file Excel XLSX (trả về Buffer)
|
|
225
|
+
*/
|
|
226
|
+
async exportExcel(jobId, options) {
|
|
227
|
+
const response = await this.http.get(
|
|
228
|
+
`/api/map/jobs/${jobId}/export/excel`,
|
|
229
|
+
{
|
|
230
|
+
...options,
|
|
231
|
+
responseType: "arraybuffer"
|
|
232
|
+
}
|
|
233
|
+
);
|
|
234
|
+
return Buffer.from(response.data);
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Stream SSE tiến độ cào Google Maps theo thời gian thực
|
|
238
|
+
*/
|
|
239
|
+
async streamJob(jobId, handlers, options) {
|
|
240
|
+
const response = await this.http.get(
|
|
241
|
+
`/api/map/jobs/${jobId}/stream`,
|
|
242
|
+
{
|
|
243
|
+
...options,
|
|
244
|
+
responseType: "stream",
|
|
245
|
+
headers: {
|
|
246
|
+
Accept: "text/event-stream",
|
|
247
|
+
...options?.headers || {}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
);
|
|
251
|
+
const stream = response.data;
|
|
252
|
+
let buffer = "";
|
|
253
|
+
stream.on("data", (chunk) => {
|
|
254
|
+
buffer += chunk.toString();
|
|
255
|
+
const lines = buffer.split("\n");
|
|
256
|
+
buffer = lines.pop() || "";
|
|
257
|
+
for (const line of lines) {
|
|
258
|
+
const trimmed = line.trim();
|
|
259
|
+
if (trimmed.startsWith("data:")) {
|
|
260
|
+
const jsonStr = trimmed.replace(/^data:\s*/, "").trim();
|
|
261
|
+
if (jsonStr === "[DONE]") {
|
|
262
|
+
handlers.onEnd?.();
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
try {
|
|
266
|
+
const parsed = JSON.parse(jsonStr);
|
|
267
|
+
handlers.onData?.(parsed);
|
|
268
|
+
} catch (e) {
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
stream.on("end", () => {
|
|
274
|
+
handlers.onEnd?.();
|
|
275
|
+
});
|
|
276
|
+
stream.on("error", (err) => {
|
|
277
|
+
handlers.onError?.(err);
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Geocode địa chỉ văn bản thành tọa độ và các cấp hành chính Việt Nam
|
|
282
|
+
*/
|
|
283
|
+
async geocodeAddress(address, options) {
|
|
284
|
+
const payload = typeof address === "string" ? { address } : address;
|
|
285
|
+
const response = await this.http.post(
|
|
286
|
+
"/api/map/geocode/address",
|
|
287
|
+
payload,
|
|
288
|
+
options
|
|
289
|
+
);
|
|
290
|
+
return response.data;
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Reverse geocode tọa độ ra địa chỉ Việt Nam
|
|
294
|
+
*/
|
|
295
|
+
async reverseGeocode(req, options) {
|
|
296
|
+
const response = await this.http.post(
|
|
297
|
+
"/api/map/geocode/coordinates",
|
|
298
|
+
req,
|
|
299
|
+
options
|
|
300
|
+
);
|
|
301
|
+
return response.data;
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
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)
|
|
305
|
+
*/
|
|
306
|
+
async parseAddressUniversal(req, options) {
|
|
307
|
+
const response = await this.http.post(
|
|
308
|
+
"/api/map/address/universal-parse",
|
|
309
|
+
req,
|
|
310
|
+
options
|
|
311
|
+
);
|
|
312
|
+
return response.data;
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
// src/modules/social-tracer/index.ts
|
|
317
|
+
var SocialTracerModule = class {
|
|
318
|
+
constructor(http) {
|
|
319
|
+
this.http = http;
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Lấy danh sách hơn 400+ nền tảng mạng xã hội được hỗ trợ truy vết
|
|
323
|
+
*/
|
|
324
|
+
async getPlatforms(options) {
|
|
325
|
+
const response = await this.http.get(
|
|
326
|
+
"/api/social-tracer/platforms",
|
|
327
|
+
options
|
|
328
|
+
);
|
|
329
|
+
return response.data;
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Truy vết đồng bộ danh tính mạng xã hội theo username trên hàng trăm trang
|
|
333
|
+
*/
|
|
334
|
+
async traceSync(payload, options) {
|
|
335
|
+
const response = await this.http.post(
|
|
336
|
+
"/api/social-tracer/trace",
|
|
337
|
+
payload,
|
|
338
|
+
options
|
|
339
|
+
);
|
|
340
|
+
return response.data;
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Stream SSE quá trình truy vết mạng xã hội thời gian thực
|
|
344
|
+
*/
|
|
345
|
+
async streamTrace(payload, handlers, options) {
|
|
346
|
+
const params = new URLSearchParams();
|
|
347
|
+
params.set("username", payload.username);
|
|
348
|
+
if (payload.timeout_per_site) params.set("timeout_per_site", String(payload.timeout_per_site));
|
|
349
|
+
if (payload.concurrency) params.set("concurrency", String(payload.concurrency));
|
|
350
|
+
if (payload.platforms?.length) {
|
|
351
|
+
payload.platforms.forEach((p) => params.append("platforms", p));
|
|
352
|
+
}
|
|
353
|
+
const response = await this.http.get(
|
|
354
|
+
`/api/social-tracer/trace/stream?${params.toString()}`,
|
|
355
|
+
{
|
|
356
|
+
...options,
|
|
357
|
+
responseType: "stream",
|
|
358
|
+
headers: {
|
|
359
|
+
Accept: "text/event-stream",
|
|
360
|
+
...options?.headers || {}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
);
|
|
364
|
+
const stream = response.data;
|
|
365
|
+
let buffer = "";
|
|
366
|
+
stream.on("data", (chunk) => {
|
|
367
|
+
buffer += chunk.toString();
|
|
368
|
+
const lines = buffer.split("\n");
|
|
369
|
+
buffer = lines.pop() || "";
|
|
370
|
+
for (const line of lines) {
|
|
371
|
+
const trimmed = line.trim();
|
|
372
|
+
if (trimmed.startsWith("data:")) {
|
|
373
|
+
const jsonStr = trimmed.replace(/^data:\s*/, "").trim();
|
|
374
|
+
if (jsonStr === "[DONE]") {
|
|
375
|
+
handlers.onEnd?.();
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
try {
|
|
379
|
+
const parsed = JSON.parse(jsonStr);
|
|
380
|
+
handlers.onData?.(parsed);
|
|
381
|
+
} catch (e) {
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
});
|
|
386
|
+
stream.on("end", () => {
|
|
387
|
+
handlers.onEnd?.();
|
|
388
|
+
});
|
|
389
|
+
stream.on("error", (err) => {
|
|
390
|
+
handlers.onError?.(err);
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Tạo background job truy vết danh tính mạng xã hội
|
|
395
|
+
*/
|
|
396
|
+
async createJob(payload, options) {
|
|
397
|
+
const response = await this.http.post(
|
|
398
|
+
"/api/social-tracer/jobs",
|
|
399
|
+
payload,
|
|
400
|
+
options
|
|
401
|
+
);
|
|
402
|
+
return response.data;
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* Kiểm tra trạng thái job truy vết
|
|
406
|
+
*/
|
|
407
|
+
async getJobStatus(jobId, options) {
|
|
408
|
+
const response = await this.http.get(
|
|
409
|
+
`/api/social-tracer/jobs/${jobId}`,
|
|
410
|
+
options
|
|
411
|
+
);
|
|
412
|
+
return response.data;
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* Lấy kết quả truy vết từ job
|
|
416
|
+
*/
|
|
417
|
+
async getJobResults(jobId, options) {
|
|
418
|
+
const response = await this.http.get(
|
|
419
|
+
`/api/social-tracer/jobs/${jobId}/results`,
|
|
420
|
+
options
|
|
421
|
+
);
|
|
422
|
+
return response.data;
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Xuất file CSV kết quả truy vết mạng xã hội (trả về Buffer)
|
|
426
|
+
*/
|
|
427
|
+
async exportCsv(jobId, options) {
|
|
428
|
+
const response = await this.http.get(
|
|
429
|
+
`/api/social-tracer/jobs/${jobId}/export/csv`,
|
|
430
|
+
{
|
|
431
|
+
...options,
|
|
432
|
+
responseType: "arraybuffer"
|
|
433
|
+
}
|
|
434
|
+
);
|
|
435
|
+
return Buffer.from(response.data);
|
|
436
|
+
}
|
|
437
|
+
};
|
|
438
|
+
|
|
439
|
+
// src/modules/ocr/index.ts
|
|
440
|
+
var import_form_data = __toESM(require("form-data"));
|
|
441
|
+
var OcrModule = class {
|
|
442
|
+
constructor(http) {
|
|
443
|
+
this.http = http;
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* 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
|
|
447
|
+
*/
|
|
448
|
+
async extractCccd(payload, options) {
|
|
449
|
+
const response = await this.http.post(
|
|
450
|
+
"/api/cccd/extract",
|
|
451
|
+
payload,
|
|
452
|
+
options
|
|
453
|
+
);
|
|
454
|
+
return response.data;
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* Upload file ảnh trực tiếp để bóc tách thông tin CCCD
|
|
458
|
+
*/
|
|
459
|
+
async uploadAndExtractCccd(fileBuffer, filename = "cccd.jpg", options) {
|
|
460
|
+
const formData = new import_form_data.default();
|
|
461
|
+
formData.append("file", fileBuffer, filename);
|
|
462
|
+
const response = await this.http.post(
|
|
463
|
+
"/api/cccd/upload",
|
|
464
|
+
formData,
|
|
465
|
+
{
|
|
466
|
+
...options,
|
|
467
|
+
headers: {
|
|
468
|
+
...formData.getHeaders(),
|
|
469
|
+
...options?.headers || {}
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
);
|
|
473
|
+
return response.data;
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* Thẩm định tính hợp pháp và các đặc trưng bảo an thẻ CCCD
|
|
477
|
+
*/
|
|
478
|
+
async verifyCccd(payload, options) {
|
|
479
|
+
const response = await this.http.post(
|
|
480
|
+
"/api/cccd/verify",
|
|
481
|
+
payload,
|
|
482
|
+
options
|
|
483
|
+
);
|
|
484
|
+
return response.data;
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Bóc tách Giấy chứng nhận đăng ký doanh nghiệp / hộ kinh doanh qua JSON (Base64 hoặc URL)
|
|
488
|
+
*/
|
|
489
|
+
async extractBusinessLicense(payload, options) {
|
|
490
|
+
const response = await this.http.post(
|
|
491
|
+
"/api/business-license/extract",
|
|
492
|
+
payload,
|
|
493
|
+
options
|
|
494
|
+
);
|
|
495
|
+
return response.data;
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* Upload file ảnh/PDF trực tiếp để bóc tách Giấy phép ĐKKD
|
|
499
|
+
*/
|
|
500
|
+
async uploadAndExtractBusinessLicense(fileBuffer, filename = "giay_phep_kinh_doanh.pdf", options) {
|
|
501
|
+
const formData = new import_form_data.default();
|
|
502
|
+
formData.append("file", fileBuffer, filename);
|
|
503
|
+
const response = await this.http.post(
|
|
504
|
+
"/api/business-license/upload",
|
|
505
|
+
formData,
|
|
506
|
+
{
|
|
507
|
+
...options,
|
|
508
|
+
headers: {
|
|
509
|
+
...formData.getHeaders(),
|
|
510
|
+
...options?.headers || {}
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
);
|
|
514
|
+
return response.data;
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* 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ý)
|
|
518
|
+
*/
|
|
519
|
+
async verifyBusinessLicense(payload, options) {
|
|
520
|
+
const response = await this.http.post(
|
|
521
|
+
"/api/business-license/verify",
|
|
522
|
+
payload,
|
|
523
|
+
options
|
|
524
|
+
);
|
|
525
|
+
return response.data;
|
|
526
|
+
}
|
|
527
|
+
};
|
|
528
|
+
|
|
529
|
+
// src/modules/ip-geolocation/index.ts
|
|
530
|
+
var IpGeolocationModule = class {
|
|
531
|
+
constructor(http) {
|
|
532
|
+
this.http = http;
|
|
533
|
+
}
|
|
534
|
+
/**
|
|
535
|
+
* Tra cứu vị trí địa lý, tọa độ GPS (lat, lon) và nhà mạng ISP từ 1 hoặc nhiều IP
|
|
536
|
+
*/
|
|
537
|
+
async lookup(request, options) {
|
|
538
|
+
let payload;
|
|
539
|
+
if (typeof request === "string") {
|
|
540
|
+
payload = { ip: request };
|
|
541
|
+
} else if (Array.isArray(request)) {
|
|
542
|
+
payload = { ips: request };
|
|
543
|
+
} else {
|
|
544
|
+
payload = request;
|
|
545
|
+
}
|
|
546
|
+
const response = await this.http.post(
|
|
547
|
+
"/api/ip-location",
|
|
548
|
+
payload,
|
|
549
|
+
options
|
|
550
|
+
);
|
|
551
|
+
return response.data;
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Tự động lấy IP Public hiện tại của client / server và vị trí địa lý
|
|
555
|
+
*/
|
|
556
|
+
async getMyPublicIp(options) {
|
|
557
|
+
const response = await this.http.get(
|
|
558
|
+
"/api/ip-location/my-ip",
|
|
559
|
+
options
|
|
560
|
+
);
|
|
561
|
+
return response.data;
|
|
562
|
+
}
|
|
563
|
+
};
|
|
564
|
+
|
|
565
|
+
// src/modules/image-compare/index.ts
|
|
566
|
+
var ImageCompareModule = class {
|
|
567
|
+
constructor(http) {
|
|
568
|
+
this.http = http;
|
|
569
|
+
}
|
|
570
|
+
/**
|
|
571
|
+
* So sánh nội dung & độ tương đồng giữa 2 bức ảnh (qua URL hoặc Base64)
|
|
572
|
+
*/
|
|
573
|
+
async compare(request, options) {
|
|
574
|
+
const response = await this.http.post(
|
|
575
|
+
"/api/image-compare",
|
|
576
|
+
request,
|
|
577
|
+
options
|
|
578
|
+
);
|
|
579
|
+
return response.data;
|
|
580
|
+
}
|
|
581
|
+
/**
|
|
582
|
+
* Chụp màn hình 2 trang web và so sánh độ lệch UI (Visual Regression Testing)
|
|
583
|
+
*/
|
|
584
|
+
async compareWebpages(request, options) {
|
|
585
|
+
const response = await this.http.post(
|
|
586
|
+
"/api/image-compare/compare-webpages",
|
|
587
|
+
request,
|
|
588
|
+
options
|
|
589
|
+
);
|
|
590
|
+
return response.data;
|
|
591
|
+
}
|
|
592
|
+
};
|
|
593
|
+
|
|
594
|
+
// src/modules/web-qa/index.ts
|
|
595
|
+
var WebQaModule = class {
|
|
596
|
+
constructor(http) {
|
|
597
|
+
this.http = http;
|
|
598
|
+
}
|
|
599
|
+
/**
|
|
600
|
+
* Hỏi đáp AI dựa trên nội dung được cào trực tiếp từ URL website
|
|
601
|
+
*/
|
|
602
|
+
async ask(request, options) {
|
|
603
|
+
const response = await this.http.post(
|
|
604
|
+
"/api/web-qa/ask",
|
|
605
|
+
request,
|
|
606
|
+
options
|
|
607
|
+
);
|
|
608
|
+
return response.data;
|
|
609
|
+
}
|
|
610
|
+
/**
|
|
611
|
+
* Chạy audit toàn diện 5 lớp chuẩn QA/Tester cho website (SEO, Accessibility, Console errors, Broken links)
|
|
612
|
+
*/
|
|
613
|
+
async audit(request, options) {
|
|
614
|
+
const response = await this.http.post(
|
|
615
|
+
"/api/web-qa/audit",
|
|
616
|
+
request,
|
|
617
|
+
options
|
|
618
|
+
);
|
|
619
|
+
return response.data;
|
|
620
|
+
}
|
|
621
|
+
};
|
|
622
|
+
|
|
623
|
+
// src/modules/screenshot/index.ts
|
|
624
|
+
var ScreenshotModule = class {
|
|
625
|
+
constructor(http) {
|
|
626
|
+
this.http = http;
|
|
627
|
+
}
|
|
628
|
+
/**
|
|
629
|
+
* Chụp ảnh màn hình website (hỗ trợ full-page, kích thước tùy chỉnh)
|
|
630
|
+
*/
|
|
631
|
+
async capture(request, options) {
|
|
632
|
+
const response = await this.http.post(
|
|
633
|
+
"/api/screenshot/capture",
|
|
634
|
+
request,
|
|
635
|
+
options
|
|
636
|
+
);
|
|
637
|
+
return response.data;
|
|
638
|
+
}
|
|
639
|
+
/**
|
|
640
|
+
* Chụp ảnh màn hình và trả về trực tiếp binary Buffer ảnh
|
|
641
|
+
*/
|
|
642
|
+
async captureAsBuffer(request, options) {
|
|
643
|
+
const response = await this.http.post(
|
|
644
|
+
"/api/screenshot/render",
|
|
645
|
+
request,
|
|
646
|
+
{
|
|
647
|
+
...options,
|
|
648
|
+
responseType: "arraybuffer"
|
|
649
|
+
}
|
|
650
|
+
);
|
|
651
|
+
return Buffer.from(response.data);
|
|
652
|
+
}
|
|
653
|
+
};
|
|
654
|
+
|
|
655
|
+
// src/client.ts
|
|
656
|
+
var RedaiToolClient = class {
|
|
657
|
+
constructor(config = {}) {
|
|
658
|
+
const defaultBaseUrl = typeof process !== "undefined" && process.env?.REDAI_TOOL_BASE_URL ? process.env.REDAI_TOOL_BASE_URL : "http://localhost:8000";
|
|
659
|
+
const defaultApiKey = typeof process !== "undefined" && process.env?.REDAI_TOOL_API_KEY ? process.env.REDAI_TOOL_API_KEY : "";
|
|
660
|
+
this.config = {
|
|
661
|
+
baseUrl: config.baseUrl || defaultBaseUrl,
|
|
662
|
+
apiKey: config.apiKey || defaultApiKey,
|
|
663
|
+
timeout: config.timeout ?? 6e4,
|
|
664
|
+
headers: config.headers ?? {}
|
|
665
|
+
};
|
|
666
|
+
const headers = {
|
|
667
|
+
Accept: "application/json",
|
|
668
|
+
"Content-Type": "application/json",
|
|
669
|
+
...this.config.headers
|
|
670
|
+
};
|
|
671
|
+
if (this.config.apiKey) {
|
|
672
|
+
headers["X-API-Key"] = this.config.apiKey;
|
|
673
|
+
}
|
|
674
|
+
this.http = import_axios.default.create({
|
|
675
|
+
baseURL: this.config.baseUrl,
|
|
676
|
+
timeout: this.config.timeout,
|
|
677
|
+
headers
|
|
678
|
+
});
|
|
679
|
+
this.http.interceptors.response.use(
|
|
680
|
+
(response) => response,
|
|
681
|
+
(error) => {
|
|
682
|
+
if (error.code === "ECONNABORTED" || error.message.includes("timeout")) {
|
|
683
|
+
return Promise.reject(
|
|
684
|
+
new RedaiToolTimeoutError(
|
|
685
|
+
`Y\xEAu c\u1EA7u t\u1EDBi redai-tool (${error.config?.url}) \u0111\xE3 h\u1EBFt h\u1EA1n sau ${this.config.timeout}ms`
|
|
686
|
+
)
|
|
687
|
+
);
|
|
688
|
+
}
|
|
689
|
+
if (error.response?.status === 401 || error.response?.status === 403) {
|
|
690
|
+
return Promise.reject(
|
|
691
|
+
new RedaiToolAuthError(
|
|
692
|
+
`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}`
|
|
693
|
+
)
|
|
694
|
+
);
|
|
695
|
+
}
|
|
696
|
+
const data = error.response?.data;
|
|
697
|
+
const msg = data?.detail || data?.message || data?.error || error.message || "L\u1ED7i kh\xF4ng x\xE1c \u0111\u1ECBnh t\u1EEB redai-tool";
|
|
698
|
+
return Promise.reject(
|
|
699
|
+
new RedaiToolApiError(msg, error.response?.status, data)
|
|
700
|
+
);
|
|
701
|
+
}
|
|
702
|
+
);
|
|
703
|
+
this.googleSearch = new GoogleSearchModule(this.http);
|
|
704
|
+
this.googleMaps = new GoogleMapsModule(this.http);
|
|
705
|
+
this.socialTracer = new SocialTracerModule(this.http);
|
|
706
|
+
this.ocr = new OcrModule(this.http);
|
|
707
|
+
this.ip = new IpGeolocationModule(this.http);
|
|
708
|
+
this.imageCompare = new ImageCompareModule(this.http);
|
|
709
|
+
this.webQa = new WebQaModule(this.http);
|
|
710
|
+
this.screenshot = new ScreenshotModule(this.http);
|
|
711
|
+
}
|
|
712
|
+
/**
|
|
713
|
+
* Kiểm tra tình trạng kết nối tới service redai-tool
|
|
714
|
+
*/
|
|
715
|
+
async healthCheck() {
|
|
716
|
+
try {
|
|
717
|
+
const resp = await this.http.get("/health");
|
|
718
|
+
return resp.data;
|
|
719
|
+
} catch {
|
|
720
|
+
return { status: "down" };
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
};
|
|
724
|
+
|
|
725
|
+
// src/index.ts
|
|
726
|
+
var index_default = RedaiToolClient;
|
|
727
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
728
|
+
0 && (module.exports = {
|
|
729
|
+
GoogleMapsModule,
|
|
730
|
+
GoogleSearchModule,
|
|
731
|
+
ImageCompareModule,
|
|
732
|
+
IpGeolocationModule,
|
|
733
|
+
OcrModule,
|
|
734
|
+
RedaiToolApiError,
|
|
735
|
+
RedaiToolAuthError,
|
|
736
|
+
RedaiToolClient,
|
|
737
|
+
RedaiToolError,
|
|
738
|
+
RedaiToolTimeoutError,
|
|
739
|
+
ScreenshotModule,
|
|
740
|
+
SocialTracerModule,
|
|
741
|
+
WebQaModule
|
|
742
|
+
});
|
|
743
|
+
//# sourceMappingURL=index.js.map
|