node-csfd-api 3.0.0-next.5 → 3.0.0-next.8
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 +6 -6
- package/esm/fetchers/index.js +6 -6
- package/package.json +1 -1
package/cjs/fetchers/index.js
CHANGED
|
@@ -8,14 +8,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var _a;
|
|
12
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
12
|
exports.fetchPage = void 0;
|
|
14
|
-
// Check if `fetch` is available in global scope (nodejs 18+) or in window (browser)
|
|
15
|
-
// If not, use cross-fetch polyfill
|
|
13
|
+
// Check if `fetch` is available in global scope (nodejs 18+) or in window (browser). If not, use cross-fetch polyfill.
|
|
16
14
|
const cross_fetch_1 = require("cross-fetch");
|
|
17
|
-
const
|
|
18
|
-
(typeof
|
|
15
|
+
const fetchSafe = (typeof fetch === 'function' && fetch) || // ServiceWorker fetch (Cloud Functions + Chrome extension)
|
|
16
|
+
(typeof global === 'object' && global.fetch) || // Node.js 18+ fetch
|
|
17
|
+
(typeof window !== 'undefined' && window.fetch) || // Browser fetch
|
|
18
|
+
cross_fetch_1.fetch; // Polyfill fetch
|
|
19
19
|
const USER_AGENTS = [
|
|
20
20
|
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36',
|
|
21
21
|
'Mozilla/5.0 (iPhone; CPU iPhone OS 14_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/87.0.4280.77 Mobile/15E148 Safari/604.1',
|
|
@@ -27,7 +27,7 @@ const headers = {
|
|
|
27
27
|
};
|
|
28
28
|
const fetchPage = (url) => __awaiter(void 0, void 0, void 0, function* () {
|
|
29
29
|
try {
|
|
30
|
-
const response = yield
|
|
30
|
+
const response = yield fetchSafe(url, { headers });
|
|
31
31
|
if (response.status >= 400 && response.status < 600) {
|
|
32
32
|
throw new Error(`node-csfd-api: Bad response ${response.status} for url: ${url}`);
|
|
33
33
|
}
|
package/esm/fetchers/index.js
CHANGED
|
@@ -7,12 +7,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
|
|
11
|
-
// Check if `fetch` is available in global scope (nodejs 18+) or in window (browser)
|
|
12
|
-
// If not, use cross-fetch polyfill
|
|
10
|
+
// Check if `fetch` is available in global scope (nodejs 18+) or in window (browser). If not, use cross-fetch polyfill.
|
|
13
11
|
import { fetch as crossFetch } from 'cross-fetch';
|
|
14
|
-
const
|
|
15
|
-
(typeof
|
|
12
|
+
const fetchSafe = (typeof fetch === 'function' && fetch) || // ServiceWorker fetch (Cloud Functions + Chrome extension)
|
|
13
|
+
(typeof global === 'object' && global.fetch) || // Node.js 18+ fetch
|
|
14
|
+
(typeof window !== 'undefined' && window.fetch) || // Browser fetch
|
|
15
|
+
crossFetch; // Polyfill fetch
|
|
16
16
|
const USER_AGENTS = [
|
|
17
17
|
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36',
|
|
18
18
|
'Mozilla/5.0 (iPhone; CPU iPhone OS 14_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/87.0.4280.77 Mobile/15E148 Safari/604.1',
|
|
@@ -24,7 +24,7 @@ const headers = {
|
|
|
24
24
|
};
|
|
25
25
|
export const fetchPage = (url) => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
26
|
try {
|
|
27
|
-
const response = yield
|
|
27
|
+
const response = yield fetchSafe(url, { headers });
|
|
28
28
|
if (response.status >= 400 && response.status < 600) {
|
|
29
29
|
throw new Error(`node-csfd-api: Bad response ${response.status} for url: ${url}`);
|
|
30
30
|
}
|
package/package.json
CHANGED