diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cc472f17f..229a9dcd7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,11 +14,6 @@ jobs: strategy: matrix: include: - - node-version: 10.x - test-on-old-node: 1 - - node-version: 12.x - test-on-old-node: 1 - # test-on-brower: 1 - node-version: 14.x - node-version: 16.x - node-version: 18.x @@ -29,25 +24,18 @@ jobs: uses: actions/setup-node@v3 with: node-version: ${{ matrix.node-version }} - - name: Cache node modules - uses: actions/cache@v3 - env: - cache-name: cache-node-modules - with: - # npm cache files are stored in `~/.npm` on Linux/macOS - path: ~/.npm - key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/yarn.lock') }} - - name: Install Dependencies On Old Node ${{ matrix.node-version }} - if: ${{ matrix.test-on-old-node == '1' }} - run: node ci/remove-deps-4-old-node.js && yarn install --ignore-scripts - - name: Install Dependencies On Node ${{ matrix.node-version }} - if: ${{ matrix.test-on-old-node != '1' }} - run: yarn install + # - name: Cache node modules + # uses: actions/cache@v3 + # env: + # cache-name: cache-node-modules + # with: + # # npm cache files are stored in `~/.npm` on Linux/macOS + # path: ~/.npm + # key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/yarn.lock') }} + - name: Install dependencies + run: npm install - name: Build run: npm run build - - name: Build On Old Node - if: ${{ matrix.test-on-old-node == '1' }} - run: npm run build:test - name: Test On Node ${{ matrix.node-version }} env: BROWSER: ${{ matrix.test-on-brower }} diff --git a/.lib.babelrc b/.lib.babelrc index c8a1e7ddd..a151f4078 100644 --- a/.lib.babelrc +++ b/.lib.babelrc @@ -2,7 +2,7 @@ "presets": [ ["@babel/env", { "targets": { - "node": "6.4.0", + "node": "14.18.0", "browsers": [ "defaults, not ie 11" ] } }] diff --git a/.test.babelrc b/.test.babelrc index 073fd43ac..337b344be 100644 --- a/.test.babelrc +++ b/.test.babelrc @@ -2,7 +2,7 @@ "presets": [ ["@babel/env", { "targets": { - "node": "6.4.0", + "node": "14.18.0", "browsers": [ "defaults, not ie 11" ] } }] diff --git a/.travis.yml b/.travis.yml index 775cfc80b..7ad5293e9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,18 +4,9 @@ node_js: - '18' - '16' - '14' - - '12' after_success: npm run coverage env: global: - SAUCE_USERNAME='shtylman-superagent' - SAUCE_ACCESS_KEY='39a45464-cb1d-4b8d-aa1f-83c7c04fa673' - -matrix: - include: - - node_js: "10" - env: BROWSER=1 - include: - - node_js: "12" - env: HTTP2_TEST=1 diff --git a/README.md b/README.md index f347a498d..f0cf42bb7 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ Browser-ready versions of this module are available via [jsdelivr][], [unpkg][], This is the solution for you if you're just using ` + @@ -112,7 +112,7 @@ If you are using [browserify][], [webpack][], [rollup][], or another bundler, th ## Supported Platforms -* Node: v6.x+ +* Node: v14.18.0+ * Browsers (see [.browserslistrc](.browserslistrc)): ```sh @@ -155,10 +155,10 @@ If you are using [browserify][], [webpack][], [rollup][], or another bundler, th ### Required Browser Features -We recommend using (specifically with the bundle mentioned in [VanillaJS](#vanillajs) above): +We recommend using (specifically with the bundle mentioned in [VanillaJS](#vanillajs) above): ```html - + ``` * WeakRef is not supported in Opera 85, iOS Safari 12.2-12.5 @@ -202,6 +202,7 @@ Existing plugins: * [superagent-declare](https://github.com/damoclark/superagent-declare) - A simple [declarative](https://en.wikipedia.org/wiki/Declarative_programming) API for SuperAgent * [superagent-node-http-timings](https://github.com/webuniverseio/superagent-node-http-timings) - measure http timings in node.js * [superagent-cheerio](https://github.com/mmmmmrob/superagent-cheerio) - add [cheerio](https://www.npmjs.com/package/cheerio) to your response content automatically. Adds `res.$` for HTML and XML response bodies. +* [@certible/superagent-aws-sign](https://github.com/certible/superagent-aws-sign) - Sign AWS endpoint requests, it uses the aws4 to authenticate the SuperAgent requests Please prefix your plugin with `superagent-*` so that it can easily be found by others. diff --git a/docs/index.md b/docs/index.md index 7c85b2677..b148cee8e 100644 --- a/docs/index.md +++ b/docs/index.md @@ -868,10 +868,10 @@ Libraries like [co](https://github.com/tj/co) or a web framework like [koa](http Note that SuperAgent expects the global `Promise` object to be present. You'll need to use v7 and a polyfill to use promises in Internet Explorer or Node.js 0.10. -We have dropped support in v8 for IE. You must add a polyfill for WeakRef and BigInt if you wish to support Opera 85, iOS Safari 12.2-12.5, for example using : +We have dropped support in v8 for IE. You must add a polyfill for WeakRef and BigInt if you wish to support Opera 85, iOS Safari 12.2-12.5, for example using : ```html - + ``` ## Browser and node versions diff --git a/index.html b/index.html index ed2417ed4..42d3f3eb3 100644 --- a/index.html +++ b/index.html @@ -623,8 +623,8 @@

Promise and Generator support

const res = yield req;

Note that SuperAgent expects the global Promise object to be present. You'll need to use v7 and a polyfill to use promises in Internet Explorer or Node.js 0.10.

-

We have dropped support in v8 for IE. You must add a polyfill for WeakRef and BigInt if you wish to support Opera 85, iOS Safari 12.2-12.5, for example using https://polyfill.io:

-
<script src="https://polyfill.io/v3/polyfill.min.js?features=WeakRef,BigInt"></script>
+

We have dropped support in v8 for IE. You must add a polyfill for WeakRef and BigInt if you wish to support Opera 85, iOS Safari 12.2-12.5, for example using https://cdnjs.cloudflare.com/polyfill/:

+
<script src="https://cdnjs.cloudflare.com/polyfill/v3/polyfill.min.js?features=WeakRef,BigInt"></script>
 

Browser and node versions

SuperAgent has two implementations: one for web browsers (using XHR) and one for Node.JS (using core http module). By default Browserify and WebPack will pick the browser version.

diff --git a/package.json b/package.json index 8ea210016..9a2fdb4d6 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "superagent", "description": "elegant & feature rich browser / node HTTP with a fluent API", - "version": "8.1.2", + "version": "9.0.0", "author": "TJ Holowaychuk ", "browser": { "./src/node/index.js": "./src/client.js", @@ -24,7 +24,7 @@ "debug": "^4.3.4", "fast-safe-stringify": "^2.1.1", "form-data": "^4.0.0", - "formidable": "^2.1.2", + "formidable": "^3.5.1", "methods": "^1.1.2", "mime": "2.6.0", "qs": "^6.11.0", @@ -38,8 +38,8 @@ "@babel/runtime": "^7.20.13", "@commitlint/cli": "17", "@commitlint/config-conventional": "17", - "Base64": "^1.1.0", "babelify": "^10.0.0", + "Base64": "^1.1.0", "basic-auth-connect": "^1.0.0", "body-parser": "^1.20.1", "browserify": "^17.0.0", @@ -69,7 +69,7 @@ "zuul": "^3.12.0" }, "engines": { - "node": ">=6.4.0 <13 || >=14" + "node": ">=14.18.0" }, "files": [ "dist/*.js", diff --git a/src/node/index.js b/src/node/index.js index e6dc73cc9..780b4f53a 100644 --- a/src/node/index.js +++ b/src/node/index.js @@ -469,7 +469,6 @@ Request.prototype._pipeContinue = function (stream, options) { res.pipe(stream, options); res.once('end', () => this.emit('end')); } - }); return stream; }; @@ -1093,7 +1092,7 @@ Request.prototype._end = function () { parser = exports.parse.image; // It's actually a generic Buffer buffer = true; } else if (multipart) { - const form = formidable(); + const form = formidable.formidable(); parser = form.parse.bind(form); buffer = true; } else if (isBinary(mime)) { @@ -1125,7 +1124,7 @@ Request.prototype._end = function () { let parserHandlesEnd = false; if (buffer) { // Protectiona against zip bombs and other nuisance - let responseBytesLeft = this._maxResponseSize || 200_000_000; + let responseBytesLeft = this._maxResponseSize || 200000000; res.on('data', (buf) => { responseBytesLeft -= buf.byteLength || buf.length > 0 ? buf.length : 0; if (responseBytesLeft < 0) { @@ -1162,6 +1161,31 @@ Request.prototype._end = function () { } if (parserHandlesEnd) { + if (multipart) { + // formidable v3 always returns an array with the value in it + // so we need to flatten it + if (object) { + for (const key in object) { + const value = object[key]; + if (Array.isArray(value) && value.length === 1) { + object[key] = value[0]; + } else { + object[key] = value; + } + } + } + + if (files) { + for (const key in files) { + const value = files[key]; + if (Array.isArray(value) && value.length === 1) { + files[key] = value[0]; + } else { + files[key] = value; + } + } + } + } this.emit('end'); this.callback(null, this._emitResponse(object, files)); }