@8ms/helpers 2.4.23 → 2.4.25

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.
@@ -15,7 +15,10 @@ const deleteRequest = async (url, config = {}) => {
15
15
  throwHttpErrors: false,
16
16
  ...config
17
17
  }).then(async (response) => {
18
- const data = await response.json();
18
+ const isJson = (response.headers.get("content-type") || "").includes("application/json");
19
+ let data;
20
+ if (isJson) data = await response.json();
21
+ else data = await response.text();
19
22
  if (void 0 !== data.body && void 0 !== data.error && void 0 !== data.state) return new require_api_ApiResponseClass.ApiResponseClass(data);
20
23
  else if (response.status >= 200 && response.status <= 299) return new require_api_ApiResponseClass.ApiResponseClass().setToSuccess(data);
21
24
  return new require_api_ApiResponseClass.ApiResponseClass().setToError(data, response.statusText);
@@ -12,7 +12,10 @@ const deleteRequest = async (url, config = {}) => {
12
12
  throwHttpErrors: false,
13
13
  ...config
14
14
  }).then(async (response) => {
15
- const data = await response.json();
15
+ const isJson = (response.headers.get("content-type") || "").includes("application/json");
16
+ let data;
17
+ if (isJson) data = await response.json();
18
+ else data = await response.text();
16
19
  if (void 0 !== data.body && void 0 !== data.error && void 0 !== data.state) return new ApiResponseClass(data);
17
20
  else if (response.status >= 200 && response.status <= 299) return new ApiResponseClass().setToSuccess(data);
18
21
  return new ApiResponseClass().setToError(data, response.statusText);
package/dist/api/get.cjs CHANGED
@@ -14,7 +14,10 @@ const get = async (url, config = {}) => {
14
14
  throwHttpErrors: false,
15
15
  ...config
16
16
  }).then(async (response) => {
17
- const data = await response.json();
17
+ const isJson = (response.headers.get("content-type") || "").includes("application/json");
18
+ let data;
19
+ if (isJson) data = await response.json();
20
+ else data = await response.text();
18
21
  if (void 0 !== data.body && void 0 !== data.error && void 0 !== data.state) return new require_api_ApiResponseClass.ApiResponseClass(data);
19
22
  else if (response.status >= 200 && response.status <= 299) return new require_api_ApiResponseClass.ApiResponseClass().setToSuccess(data);
20
23
  return new require_api_ApiResponseClass.ApiResponseClass().setToError(data, response.statusText);
package/dist/api/get.mjs CHANGED
@@ -11,7 +11,10 @@ const get = async (url, config = {}) => {
11
11
  throwHttpErrors: false,
12
12
  ...config
13
13
  }).then(async (response) => {
14
- const data = await response.json();
14
+ const isJson = (response.headers.get("content-type") || "").includes("application/json");
15
+ let data;
16
+ if (isJson) data = await response.json();
17
+ else data = await response.text();
15
18
  if (void 0 !== data.body && void 0 !== data.error && void 0 !== data.state) return new ApiResponseClass(data);
16
19
  else if (response.status >= 200 && response.status <= 299) return new ApiResponseClass().setToSuccess(data);
17
20
  return new ApiResponseClass().setToError(data, response.statusText);
package/dist/api/post.cjs CHANGED
@@ -15,10 +15,13 @@ const post = async (url, data = {}, config = {}) => {
15
15
  throwHttpErrors: false,
16
16
  ...config
17
17
  }).then(async (response) => {
18
- const responseData = await response.json();
19
- if (void 0 !== responseData.body && void 0 !== responseData.error && void 0 !== responseData.state) return new require_api_ApiResponseClass.ApiResponseClass(responseData);
20
- else if (response.status >= 200 && response.status <= 299) return new require_api_ApiResponseClass.ApiResponseClass().setToSuccess(responseData);
21
- return new require_api_ApiResponseClass.ApiResponseClass().setToError(responseData, response.statusText);
18
+ const isJson = (response.headers.get("content-type") || "").includes("application/json");
19
+ let data;
20
+ if (isJson) data = await response.json();
21
+ else data = await response.text();
22
+ if (void 0 !== data.body && void 0 !== data.error && void 0 !== data.state) return new require_api_ApiResponseClass.ApiResponseClass(data);
23
+ else if (response.status >= 200 && response.status <= 299) return new require_api_ApiResponseClass.ApiResponseClass().setToSuccess(data);
24
+ return new require_api_ApiResponseClass.ApiResponseClass().setToError(data, response.statusText);
22
25
  }).catch((error) => {
23
26
  return new require_api_ApiResponseClass.ApiResponseClass().setToError(null, error.message);
24
27
  });
package/dist/api/post.mjs CHANGED
@@ -12,10 +12,13 @@ const post = async (url, data = {}, config = {}) => {
12
12
  throwHttpErrors: false,
13
13
  ...config
14
14
  }).then(async (response) => {
15
- const responseData = await response.json();
16
- if (void 0 !== responseData.body && void 0 !== responseData.error && void 0 !== responseData.state) return new ApiResponseClass(responseData);
17
- else if (response.status >= 200 && response.status <= 299) return new ApiResponseClass().setToSuccess(responseData);
18
- return new ApiResponseClass().setToError(responseData, response.statusText);
15
+ const isJson = (response.headers.get("content-type") || "").includes("application/json");
16
+ let data;
17
+ if (isJson) data = await response.json();
18
+ else data = await response.text();
19
+ if (void 0 !== data.body && void 0 !== data.error && void 0 !== data.state) return new ApiResponseClass(data);
20
+ else if (response.status >= 200 && response.status <= 299) return new ApiResponseClass().setToSuccess(data);
21
+ return new ApiResponseClass().setToError(data, response.statusText);
19
22
  }).catch((error) => {
20
23
  return new ApiResponseClass().setToError(null, error.message);
21
24
  });
@@ -7,12 +7,13 @@ const require_api_post = require("../../../api/post.cjs");
7
7
  * Make the request to trigger the scraper and let it do its job.
8
8
  */
9
9
  const getBatch = async (auth, scraperId, data = {}, isDev = false) => {
10
- let response = false;
10
+ let response = null;
11
11
  const requestUrl = new URL("https://api.brightdata.com/dca/trigger");
12
12
  requestUrl.searchParams.append("collector", scraperId);
13
13
  requestUrl.searchParams.append("queue_next", "1");
14
14
  if (isDev) requestUrl.searchParams.append("version", "dev");
15
- if ((await require_api_post.post(requestUrl.toString(), data, { headers: { Authorization: `Bearer ${auth.apiKey}` } })).isSuccess()) response = true;
15
+ const requestResponse = await require_api_post.post(requestUrl.toString(), data, { headers: { Authorization: `Bearer ${auth.apiKey}` } });
16
+ if (requestResponse.isSuccess()) response = requestResponse.getBody();
16
17
  return response;
17
18
  };
18
19
  //#endregion
@@ -1,11 +1,15 @@
1
1
  import { Auth } from "../../server/brightData.cjs";
2
2
 
3
3
  //#region src/brightData/webScraperIde/server/getBatch.d.ts
4
+ type Response = {
5
+ collection_id: string;
6
+ start_eta: string;
7
+ };
4
8
  /**
5
9
  * Depends on the Scraper setup!
6
10
  *
7
11
  * Make the request to trigger the scraper and let it do its job.
8
12
  */
9
- declare const getBatch: (auth: Auth, scraperId: string, data?: {}, isDev?: boolean) => Promise<boolean>;
13
+ declare const getBatch: (auth: Auth, scraperId: string, data?: {}, isDev?: boolean) => Promise<Response | null>;
10
14
  //#endregion
11
15
  export { getBatch };
@@ -1,11 +1,15 @@
1
1
  import { Auth } from "../../server/brightData.mjs";
2
2
 
3
3
  //#region src/brightData/webScraperIde/server/getBatch.d.ts
4
+ type Response = {
5
+ collection_id: string;
6
+ start_eta: string;
7
+ };
4
8
  /**
5
9
  * Depends on the Scraper setup!
6
10
  *
7
11
  * Make the request to trigger the scraper and let it do its job.
8
12
  */
9
- declare const getBatch: (auth: Auth, scraperId: string, data?: {}, isDev?: boolean) => Promise<boolean>;
13
+ declare const getBatch: (auth: Auth, scraperId: string, data?: {}, isDev?: boolean) => Promise<Response | null>;
10
14
  //#endregion
11
15
  export { getBatch };
@@ -6,12 +6,13 @@ import { post } from "../../../api/post.mjs";
6
6
  * Make the request to trigger the scraper and let it do its job.
7
7
  */
8
8
  const getBatch = async (auth, scraperId, data = {}, isDev = false) => {
9
- let response = false;
9
+ let response = null;
10
10
  const requestUrl = new URL("https://api.brightdata.com/dca/trigger");
11
11
  requestUrl.searchParams.append("collector", scraperId);
12
12
  requestUrl.searchParams.append("queue_next", "1");
13
13
  if (isDev) requestUrl.searchParams.append("version", "dev");
14
- if ((await post(requestUrl.toString(), data, { headers: { Authorization: `Bearer ${auth.apiKey}` } })).isSuccess()) response = true;
14
+ const requestResponse = await post(requestUrl.toString(), data, { headers: { Authorization: `Bearer ${auth.apiKey}` } });
15
+ if (requestResponse.isSuccess()) response = requestResponse.getBody();
15
16
  return response;
16
17
  };
17
18
  //#endregion
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@8ms/helpers",
3
3
  "license": "UNLICENSED",
4
- "version": "2.4.23",
4
+ "version": "2.4.25",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"
@@ -160,7 +160,7 @@
160
160
  "@aws-sdk/lib-storage": "^3.1028.0",
161
161
  "@aws-sdk/s3-request-presigner": "^3.1028.0",
162
162
  "@babel/core": "7.29.0",
163
- "@babel/preset-env": "7.29.2",
163
+ "@babel/preset-env": "7.29.5",
164
164
  "@babel/preset-flow": "7.27.1",
165
165
  "@babel/preset-typescript": "7.28.5",
166
166
  "@google-cloud/bigquery": "^8.1.1",
@@ -178,7 +178,7 @@
178
178
  "@types/luxon": "3.7.1",
179
179
  "@types/node": "^24.12.2",
180
180
  "@types/react": "^19.2.14",
181
- "babel-jest": "30.3.0",
181
+ "babel-jest": "30.4.1",
182
182
  "dotenv": "^17.4.1",
183
183
  "drizzle-orm": "beta",
184
184
  "fs-extra": "^11.3.4",