@8ms/helpers 1.29.0 → 1.30.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.
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Param } from "../param";
|
|
2
|
+
import ApiResponse from "../../api/ApiResponse";
|
|
2
3
|
type GetAsync = {
|
|
3
4
|
auth: Param;
|
|
4
5
|
requestId: string;
|
|
@@ -7,5 +8,5 @@ type GetAsync = {
|
|
|
7
8
|
* Using the request ID from getAsyncRequestId fetch to see if the data is available.
|
|
8
9
|
* https://docs.brightdata.com/scraping-automation/serp-api/asynchronous-requests
|
|
9
10
|
*/
|
|
10
|
-
declare const
|
|
11
|
-
export default
|
|
11
|
+
declare const getAsyncResults: (props: GetAsync) => Promise<ApiResponse>;
|
|
12
|
+
export default getAsyncResults;
|
|
@@ -6,12 +6,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const get_1 = __importDefault(require("../../axios/get"));
|
|
7
7
|
const getCustomerId_1 = __importDefault(require("../getCustomerId"));
|
|
8
8
|
const getZone_1 = __importDefault(require("../getZone"));
|
|
9
|
+
const ApiResponse_1 = __importDefault(require("../../api/ApiResponse"));
|
|
9
10
|
/**
|
|
10
11
|
* Using the request ID from getAsyncRequestId fetch to see if the data is available.
|
|
11
12
|
* https://docs.brightdata.com/scraping-automation/serp-api/asynchronous-requests
|
|
12
13
|
*/
|
|
13
|
-
const
|
|
14
|
-
let response =
|
|
14
|
+
const getAsyncResults = async (props) => {
|
|
15
|
+
let response = (new ApiResponse_1.default());
|
|
15
16
|
// Prevent auth requests getting blocked
|
|
16
17
|
process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = "0";
|
|
17
18
|
const customerId = (0, getCustomerId_1.default)({
|
|
@@ -29,8 +30,20 @@ const getAsync = async (props) => {
|
|
|
29
30
|
url: `https://api.brightdata.com/serp/get_result?customer=${customerId}&zone=${zone}&response_id=${props.requestId}`,
|
|
30
31
|
});
|
|
31
32
|
if (requestResponse.isSuccess()) {
|
|
32
|
-
|
|
33
|
+
if ("Request is pending" === requestResponse.getBody()) {
|
|
34
|
+
response.setToPending();
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
response.setToSuccess({
|
|
38
|
+
body: requestResponse.getBody(),
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
response.setToError({
|
|
44
|
+
error: "Error in request",
|
|
45
|
+
});
|
|
33
46
|
}
|
|
34
47
|
return response;
|
|
35
48
|
};
|
|
36
|
-
exports.default =
|
|
49
|
+
exports.default = getAsyncResults;
|
|
@@ -11,7 +11,12 @@ const post_1 = __importDefault(require("../../axios/post"));
|
|
|
11
11
|
*/
|
|
12
12
|
const getBatch = async (props) => {
|
|
13
13
|
let response = false;
|
|
14
|
-
const requestUrl =
|
|
14
|
+
const requestUrl = new URL('https://api.brightdata.com/dca/trigger');
|
|
15
|
+
requestUrl.searchParams.append('collector', props.scraperId);
|
|
16
|
+
requestUrl.searchParams.append('queue_next', '1');
|
|
17
|
+
if (props.isDev) {
|
|
18
|
+
requestUrl.searchParams.append('version', 'dev');
|
|
19
|
+
}
|
|
15
20
|
const requestResponse = await (0, post_1.default)({
|
|
16
21
|
config: {
|
|
17
22
|
headers: {
|
|
@@ -19,7 +24,7 @@ const getBatch = async (props) => {
|
|
|
19
24
|
},
|
|
20
25
|
},
|
|
21
26
|
data: props?.data || {},
|
|
22
|
-
url: requestUrl,
|
|
27
|
+
url: requestUrl.toString(),
|
|
23
28
|
});
|
|
24
29
|
if (requestResponse.isSuccess()) {
|
|
25
30
|
response = true;
|