node-fetch
Advanced tools
Comparing version 3.0.0-beta.4 to 3.0.0-beta.5
@@ -12,4 +12,4 @@ // Prior contributors: Torsten Werner <https://github.com/torstenwerner> | ||
import { Agent } from 'http'; | ||
import { AbortSignal } from './externals'; | ||
import {URL, URLSearchParams} from 'url'; | ||
import {Agent} from 'http'; | ||
@@ -16,0 +16,0 @@ export class Request extends Body { |
260
package.json
{ | ||
"name": "node-fetch", | ||
"version": "3.0.0-beta.4", | ||
"description": "A light-weight module that brings window.fetch to node.js", | ||
"main": "./dist/dist-src", | ||
"files": [ | ||
"src", | ||
"dist", | ||
"*.d.ts" | ||
], | ||
"engines": { | ||
"node": ">=10.0.0" | ||
}, | ||
"scripts": { | ||
"build": "pika build --out dist/", | ||
"prepublishOnly": "npm run build", | ||
"test": "cross-env BABEL_ENV=test mocha --require @babel/register --throw-deprecation test/*.js", | ||
"report": "cross-env BABEL_ENV=coverage nyc --reporter lcov --reporter text mocha -R spec test/*.js", | ||
"coverage": "cross-env BABEL_ENV=coverage nyc --reporter json --reporter text mocha -R spec test/*.js && codecov -f coverage/coverage-final.json", | ||
"lint": "xo" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/node-fetch/node-fetch.git" | ||
}, | ||
"keywords": [ | ||
"fetch", | ||
"http", | ||
"promise" | ||
], | ||
"author": "David Frank", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/node-fetch/node-fetch/issues" | ||
}, | ||
"homepage": "https://github.com/node-fetch/node-fetch", | ||
"funding": { | ||
"type": "opencollective", | ||
"url": "https://opencollective.com/node-fetch" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.8.7", | ||
"@babel/preset-env": "^7.8.7", | ||
"@babel/register": "^7.8.6", | ||
"@pika/pack": "^0.5.0", | ||
"@pika/plugin-standard-pkg": "^0.9.2", | ||
"abort-controller": "^3.0.0", | ||
"abortcontroller-polyfill": "^1.4.0", | ||
"chai": "^4.2.0", | ||
"chai-as-promised": "^7.1.1", | ||
"chai-iterator": "^3.0.2", | ||
"chai-string": "^1.5.0", | ||
"codecov": "^3.6.5", | ||
"cross-env": "^7.0.2", | ||
"form-data": "^3.0.0", | ||
"mocha": "^7.1.0", | ||
"nyc": "^15.0.0", | ||
"parted": "^0.1.1", | ||
"promise": "^8.1.0", | ||
"resumer": "0.0.0", | ||
"string-to-arraybuffer": "^1.0.2", | ||
"xo": "^0.28.0" | ||
}, | ||
"dependencies": { | ||
"data-uri-to-buffer": "^3.0.0", | ||
"fetch-blob": "^1.0.5" | ||
}, | ||
"@pika/pack": { | ||
"pipeline": [ | ||
[ | ||
"@pika/plugin-standard-pkg" | ||
] | ||
] | ||
}, | ||
"xo": { | ||
"envs": [ | ||
"node", | ||
"browser" | ||
], | ||
"rules": { | ||
"complexity": 0, | ||
"promise/prefer-await-to-then": 0, | ||
"no-mixed-operators": 0, | ||
"no-negated-condition": 0, | ||
"unicorn/prevent-abbreviations": 0 | ||
}, | ||
"ignores": [ | ||
"dist" | ||
], | ||
"overrides": [ | ||
{ | ||
"files": "test/**/*.js", | ||
"envs": [ | ||
"node", | ||
"mocha" | ||
], | ||
"rules": { | ||
"max-nested-callbacks": 0, | ||
"no-unused-expressions": 0, | ||
"new-cap": 0, | ||
"guard-for-in": 0 | ||
} | ||
}, | ||
{ | ||
"files": "example.js", | ||
"rules": { | ||
"import/no-extraneous-dependencies": 0 | ||
} | ||
} | ||
] | ||
}, | ||
"babel": { | ||
"presets": [ | ||
[ | ||
"@babel/preset-env", | ||
{ | ||
"targets": { | ||
"node": true | ||
} | ||
} | ||
] | ||
] | ||
}, | ||
"nyc": { | ||
"require": [ | ||
"@babel/register" | ||
], | ||
"sourceMap": false, | ||
"instrument": false | ||
}, | ||
"runkitExampleFilename": "example.js" | ||
"name": "node-fetch", | ||
"version": "3.0.0-beta.5", | ||
"description": "A light-weight module that brings window.fetch to node.js", | ||
"main": "./dist/index.js", | ||
"module": "./src/index.js", | ||
"sideEffects": false, | ||
"exports": { | ||
"import": "./src/index.js", | ||
"require": "./dist/index.js" | ||
}, | ||
"files": [ | ||
"src", | ||
"dist", | ||
"*.d.ts" | ||
], | ||
"engines": { | ||
"node": ">=10" | ||
}, | ||
"scripts": { | ||
"build": "babel src --out-dir dist", | ||
"test": "nyc --reporter=html --reporter=text mocha --require @babel/register --throw-deprecation", | ||
"coverage": "nyc report --reporter=text-lcov | coveralls", | ||
"lint": "xo" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/node-fetch/node-fetch.git" | ||
}, | ||
"keywords": [ | ||
"fetch", | ||
"http", | ||
"promise" | ||
], | ||
"author": "David Frank", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/node-fetch/node-fetch/issues" | ||
}, | ||
"homepage": "https://github.com/node-fetch/node-fetch", | ||
"funding": { | ||
"type": "opencollective", | ||
"url": "https://opencollective.com/node-fetch" | ||
}, | ||
"devDependencies": { | ||
"@babel/cli": "^7.8.4", | ||
"@babel/core": "^7.9.0", | ||
"@babel/preset-env": "^7.9.5", | ||
"@babel/register": "^7.9.0", | ||
"@istanbuljs/nyc-config-babel": "^3.0.0", | ||
"abort-controller": "^3.0.0", | ||
"abortcontroller-polyfill": "^1.4.0", | ||
"babel-plugin-add-module-exports": "^1.0.2", | ||
"babel-plugin-istanbul": "^6.0.0", | ||
"chai": "^4.2.0", | ||
"chai-as-promised": "^7.1.1", | ||
"chai-iterator": "^3.0.2", | ||
"chai-string": "^1.5.0", | ||
"coveralls": "^3.0.13", | ||
"form-data": "^3.0.0", | ||
"mocha": "^7.1.1", | ||
"nyc": "^15.0.1", | ||
"parted": "^0.1.1", | ||
"promise": "^8.1.0", | ||
"resumer": "0.0.0", | ||
"string-to-arraybuffer": "^1.0.2", | ||
"xo": "^0.29.1" | ||
}, | ||
"dependencies": { | ||
"data-uri-to-buffer": "^3.0.0", | ||
"fetch-blob": "^1.0.5" | ||
}, | ||
"xo": { | ||
"envs": [ | ||
"node", | ||
"browser" | ||
], | ||
"rules": { | ||
"complexity": 0, | ||
"promise/prefer-await-to-then": 0, | ||
"no-mixed-operators": 0, | ||
"no-negated-condition": 0, | ||
"unicorn/prevent-abbreviations": 0, | ||
"@typescript-eslint/prefer-readonly-parameter-types": 0 | ||
}, | ||
"ignores": [ | ||
"dist", | ||
"index.d.ts" | ||
], | ||
"overrides": [ | ||
{ | ||
"files": "test/**/*.js", | ||
"envs": [ | ||
"node", | ||
"mocha" | ||
], | ||
"rules": { | ||
"max-nested-callbacks": 0, | ||
"no-unused-expressions": 0, | ||
"new-cap": 0, | ||
"guard-for-in": 0 | ||
} | ||
}, | ||
{ | ||
"files": "example.js", | ||
"rules": { | ||
"import/no-extraneous-dependencies": 0 | ||
} | ||
} | ||
] | ||
}, | ||
"babel": { | ||
"presets": [ | ||
[ | ||
"@babel/preset-env", | ||
{ | ||
"targets": { | ||
"node": true | ||
} | ||
} | ||
] | ||
], | ||
"plugins": [ | ||
"add-module-exports", | ||
"istanbul" | ||
] | ||
}, | ||
"nyc": { | ||
"extends": "@istanbuljs/nyc-config-babel" | ||
}, | ||
"runkitExampleFilename": "example.js" | ||
} |
@@ -6,3 +6,3 @@ <div align="center"> | ||
<a href="https://travis-ci.com/node-fetch/node-fetch"><img src="https://img.shields.io/travis/com/node-fetch/node-fetch/master?style=flat-square" alt="Build status"></a> | ||
<a href="https://codecov.io/gh/node-fetch/node-fetch"><img src="https://img.shields.io/codecov/c/gh/node-fetch/node-fetch/master?style=flat-square" alt="Coverage status"></a> | ||
<a href="https://coveralls.io/github/node-fetch/node-fetch"><img src="https://img.shields.io/coveralls/github/node-fetch/node-fetch?style=flat-square" alt="Coverage status"></a> | ||
<a href="https://packagephobia.now.sh/result?p=node-fetch"><img src="https://flat.badgen.net/packagephobia/install/node-fetch" alt="Current version"></a> | ||
@@ -38,2 +38,3 @@ <a href="https://www.npmjs.com/package/node-fetch"><img src="https://img.shields.io/npm/v/node-fetch?style=flat-square" alt="Install size"></a> | ||
- [Handling client and server errors](#handling-client-and-server-errors) | ||
- [Handling cookies](#handling-cookies) | ||
- [Advanced Usage](#advanced-usage) | ||
@@ -83,3 +84,3 @@ - [Streams](#streams) | ||
See Matt Andrews' [isomorphic-fetch](https://github.com/matthew-andrews/isomorphic-fetch) or Leonardo Quixada's [cross-fetch](https://github.com/lquixada/cross-fetch) for isomorphic usage (exports `node-fetch` for server-side, `whatwg-fetch` for client-side). | ||
See Jason Miller's [isomorphic-unfetch](https://www.npmjs.com/package/isomorphic-unfetch) or Leonardo Quixada's [cross-fetch](https://github.com/lquixada/cross-fetch) for isomorphic usage (exports `node-fetch` for server-side, `whatwg-fetch` for client-side). | ||
@@ -264,2 +265,6 @@ ## Features | ||
### Handling cookies | ||
Cookies are not stored by default. However, cookies can be extracted and passed by manipulating request and response headers. See [Extract Set-Cookie Header](#extract-set-cookie-header) for details. | ||
## Advanced Usage | ||
@@ -269,14 +274,17 @@ | ||
The "Node.js way" is to use streams when possible: | ||
The "Node.js way" is to use streams when possible. You can pipe `res.body` to another stream. This example uses [stream.pipeline](https://nodejs.org/api/stream.html#stream_stream_pipeline_streams_callback) to attach stream error handlers and wait for the download to complete. | ||
```js | ||
const {createWriteStream} = require('fs'); | ||
const fetch = require('node-fetch'); | ||
const util = require('util'); | ||
const fs = require('fs'); | ||
const streamPipeline = util.promisify(require('stream').pipeline); | ||
fetch( | ||
'https://octodex.github.com/images/Fintechtocat.png' | ||
).then(res => { | ||
const dest = fs.createWriteStream('./octocat.png'); | ||
res.body.pipe(dest); | ||
}); | ||
fetch('https://assets-cdn.github.com/images/modules/logos_page/Octocat.png') | ||
.then(res => { | ||
if (!res.ok) { | ||
throw new Error(`unexpected response ${res.statusText}`); | ||
} | ||
return streamPipeline(res.body, fs.createWriteStream('./octocat.png')); | ||
}); | ||
``` | ||
@@ -283,0 +291,0 @@ |
@@ -308,7 +308,5 @@ /** | ||
fetch.Promise = global.Promise; | ||
export { | ||
Headers, | ||
Request, | ||
Response, | ||
FetchError | ||
}; | ||
fetch.Headers = Headers; | ||
fetch.Request = Request; | ||
fetch.Response = Response; | ||
fetch.FetchError = FetchError; |
@@ -15,2 +15,3 @@ | ||
import {isAbortSignal} from './utils/is'; | ||
import {getSearch} from './utils/get-search'; | ||
@@ -262,5 +263,7 @@ const INTERNALS = Symbol('Request internals'); | ||
// manually spread the URL object instead of spread syntax | ||
const search = getSearch(parsedURL); | ||
// Manually spread the URL object instead of spread syntax | ||
const requestOptions = { | ||
path: parsedURL.pathname, | ||
path: parsedURL.pathname + search, | ||
pathname: parsedURL.pathname, | ||
@@ -267,0 +270,0 @@ hostname: parsedURL.hostname, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses eval() which is a dangerous function. This prevents the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
399367
18205
728
22
22
37