node-csfd-api 3.0.0-next.5 → 3.0.0-next.6
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/cjs/fetchers/index.js +3 -2
- package/esm/fetchers/index.js +3 -2
- package/package.json +1 -1
package/cjs/fetchers/index.js
CHANGED
|
@@ -14,7 +14,8 @@ exports.fetchPage = void 0;
|
|
|
14
14
|
// Check if `fetch` is available in global scope (nodejs 18+) or in window (browser)
|
|
15
15
|
// If not, use cross-fetch polyfill
|
|
16
16
|
const cross_fetch_1 = require("cross-fetch");
|
|
17
|
-
const
|
|
17
|
+
const fetchSafe = (_a = ((typeof fetch === 'function' && fetch) ||
|
|
18
|
+
(typeof global === 'object' && global.fetch) ||
|
|
18
19
|
(typeof window !== 'undefined' && window.fetch))) !== null && _a !== void 0 ? _a : cross_fetch_1.fetch;
|
|
19
20
|
const USER_AGENTS = [
|
|
20
21
|
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36',
|
|
@@ -27,7 +28,7 @@ const headers = {
|
|
|
27
28
|
};
|
|
28
29
|
const fetchPage = (url) => __awaiter(void 0, void 0, void 0, function* () {
|
|
29
30
|
try {
|
|
30
|
-
const response = yield
|
|
31
|
+
const response = yield fetchSafe(url, { headers });
|
|
31
32
|
if (response.status >= 400 && response.status < 600) {
|
|
32
33
|
throw new Error(`node-csfd-api: Bad response ${response.status} for url: ${url}`);
|
|
33
34
|
}
|
package/esm/fetchers/index.js
CHANGED
|
@@ -11,7 +11,8 @@ var _a;
|
|
|
11
11
|
// Check if `fetch` is available in global scope (nodejs 18+) or in window (browser)
|
|
12
12
|
// If not, use cross-fetch polyfill
|
|
13
13
|
import { fetch as crossFetch } from 'cross-fetch';
|
|
14
|
-
const
|
|
14
|
+
const fetchSafe = (_a = ((typeof fetch === 'function' && fetch) ||
|
|
15
|
+
(typeof global === 'object' && global.fetch) ||
|
|
15
16
|
(typeof window !== 'undefined' && window.fetch))) !== null && _a !== void 0 ? _a : crossFetch;
|
|
16
17
|
const USER_AGENTS = [
|
|
17
18
|
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36',
|
|
@@ -24,7 +25,7 @@ const headers = {
|
|
|
24
25
|
};
|
|
25
26
|
export const fetchPage = (url) => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
27
|
try {
|
|
27
|
-
const response = yield
|
|
28
|
+
const response = yield fetchSafe(url, { headers });
|
|
28
29
|
if (response.status >= 400 && response.status < 600) {
|
|
29
30
|
throw new Error(`node-csfd-api: Bad response ${response.status} for url: ${url}`);
|
|
30
31
|
}
|
package/package.json
CHANGED