@8ms/helpers 1.26.0 → 1.28.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.
@@ -14,6 +14,7 @@ type BuildGoogleSerpUrl = {
14
14
  searchType?: "images" | "jobs" | "news" | "shopping";
15
15
  query: string;
16
16
  googleDomain: string;
17
+ output?: "html" | "json";
17
18
  };
18
19
  /**
19
20
  * Construct the Google SERP url using Bright Data's API:
@@ -8,7 +8,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
8
8
  * https://developers.google.com/google-ads/api/data/geotargets
9
9
  */
10
10
  const buildGoogleSerpUrl = (props) => {
11
- let url = new URL(`https://www${props.googleDomain}/`);
11
+ let url = new URL(`https://www.${props.googleDomain}/search`);
12
12
  url.searchParams.append("q", props.query);
13
13
  // Two-letter country code used to define the country of search
14
14
  if (props?.country) {
@@ -73,8 +73,13 @@ const buildGoogleSerpUrl = (props) => {
73
73
  url.searchParams.append("num", props.pagination.perPage.toString());
74
74
  }
75
75
  }
76
- // Always return the JSON response with HTML field
77
- url.searchParams.append("brn_json", "html");
76
+ // Specify the output type
77
+ if ("json" === props.output) {
78
+ url.searchParams.append("brn_json", "1");
79
+ }
80
+ else {
81
+ url.searchParams.append("brn_json", "html");
82
+ }
78
83
  return url.toString();
79
84
  };
80
85
  exports.default = buildGoogleSerpUrl;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@8ms/helpers",
3
3
  "license": "UNLICENSED",
4
- "version": "1.26.0",
4
+ "version": "1.28.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"