Skip to content

Commit d68907b

Browse files
committed
fix: bump deps, fixed linting, specific retry approach
1 parent 44fadf9 commit d68907b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1648
-1564
lines changed

.dist.eslintrc

+4-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"no-useless-escape": "off",
1919
"no-cond-assign": "off",
2020
"no-redeclare": "off",
21-
"node/no-exports-assign": "off"
21+
"node/no-exports-assign": "off",
22+
"no-unsafe-finally": "off"
2223
},
2324
"globals": {
2425
"regeneratorRuntime": "writable"
@@ -29,7 +30,8 @@
2930
"Array.from",
3031
"Symbol",
3132
"Object.getOwnPropertySymbols",
32-
"Object.setPrototypeOf"
33+
"Object.setPrototypeOf",
34+
"Set"
3335
]
3436
}
3537
}

.lib.eslintrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"no-global-assign": ["error", {"exceptions": ["exports"]}],
1414
"no-fallthrough": "off",
1515
"no-constant-condition": "off",
16-
"node/no-exports-assign": "off"
16+
"node/no-exports-assign": "off",
17+
"no-unsafe-finally": "off"
1718
},
1819
"overrides": [
1920
{

README.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ Browser-ready versions of this module are available via [jsdelivr][], [unpkg][],
8383
This is the solution for you if you're just using `<script>` tags everywhere!
8484

8585
```html
86-
<script src="https://polyfill.io/v3/polyfill.min.js?features=Array.from,Promise,Symbol,Object.setPrototypeOf,Object.getOwnPropertySymbols"></script>
86+
<script src="https://polyfill.io/v3/polyfill.min.js?features=Array.from,Promise,Symbol,Object.setPrototypeOf,Object.getOwnPropertySymbols,Set"></script>
8787
<script src="https://cdn.jsdelivr.net/npm/superagent"></script>
8888
<!-- if you wish to use unpkg.com instead: -->
8989
<!-- <script src="https://unpkg.com/superagent"></script> -->
@@ -159,11 +159,11 @@ If you are using [browserify][], [webpack][], [rollup][], or another bundler, th
159159
We recommend using <https://polyfill.io> (specifically with the bundle mentioned in [VanillaJS](#vanillajs) above):
160160

161161
```html
162-
<script src="https://polyfill.io/v3/polyfill.min.js?features=Array.from,Promise,Symbol,Object.setPrototypeOf,Object.getOwnPropertySymbols"></script>
162+
<script src="https://polyfill.io/v3/polyfill.min.js?features=Array.from,Promise,Symbol,Object.setPrototypeOf,Object.getOwnPropertySymbols,Set"></script>
163163
```
164164

165165
* IE 9-10 requires a polyfill for `Promise`, `Array.from`, `Symbol`, `Object.getOwnPropertySymbols`, and `Object.setPrototypeOf`
166-
* IE 9 requires a polyfill for `window.FormData` (we recommend [formdata-polyfill][])
166+
* IE 9 requires a polyfill for `window.FormData` (we recommend [formdata-polyfill][]) and `Set`
167167

168168

169169
## Plugins
@@ -212,6 +212,10 @@ For SuperAgent extensions such as couchdb and oauth visit the [wiki](https://git
212212

213213
Our breaking changes are mostly in rarely used functionality and from stricter error handling.
214214

215+
* [5.x to 6.x](https://github.com/visionmedia/superagent/releases/tag/v6.0.0):
216+
* Retry behavior is still opt-in, however we now have a more fine-grained list of status codes and error codes that we retry against (see updated docs)
217+
* A specific issue with Content-Type matching not being case-insensitive is fixed
218+
* Set is now required for IE 9, see [Required Browser Features](#required-browser-features) for more insight
215219
* [4.x to 5.x](https://github.com/visionmedia/superagent/releases/tag/v5.0.0):
216220
* We've implemented the build setup of [Lass](https://lass.js.org) to simplify our stack and linting
217221
* Unminified browserified build size has been reduced from 48KB to 20KB (via `tinyify` and the latest version of Babel using `@babel/preset-env` and `.browserslistrc`)

docs/index.md

+26
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,32 @@ This method has two optional arguments: number of retries (default 1) and a call
248248

249249
Use `.retry()` only with requests that are *idempotent* (i.e. multiple requests reaching the server won't cause undesirable side effects like duplicate purchases).
250250

251+
All request methods are tried by default (which means if you do not want POST requests to be retried, you will need to pass a custom retry callback).
252+
253+
By default the following status codes are retried:
254+
255+
* `408`
256+
* `413`
257+
* `429`
258+
* `500`
259+
* `502`
260+
* `503`
261+
* `504`
262+
* `521`
263+
* `522`
264+
* `524`
265+
266+
By default the following error codes are retried:
267+
268+
* `'ETIMEDOUT'`
269+
* `'ECONNRESET'`
270+
* `'EADDRINUSE'`
271+
* `'ECONNREFUSED'`
272+
* `'EPIPE'`
273+
* `'ENOTFOUND'`
274+
* `'ENETUNREACH'`
275+
* `'EAI_AGAIN'`
276+
251277
## Setting Accept
252278

253279
In a similar fashion to the `.type()` method it is also possible to set the `Accept` header via the short hand method `.accept()`. Which references `request.types` as well allowing you to specify either the full canonicalized MIME type name as `type/subtype`, or the extension suffix form as "xml", "json", "png", etc. for convenience:

package.json

+21-16
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,21 @@
3636
"semver": "^7.3.2"
3737
},
3838
"devDependencies": {
39-
"@babel/cli": "^7.10.3",
40-
"@babel/core": "^7.10.3",
41-
"@babel/plugin-transform-runtime": "^7.10.5",
42-
"@babel/preset-env": "^7.10.3",
43-
"@commitlint/cli": "^9.0.1",
44-
"@commitlint/config-conventional": "^9.0.1",
39+
"@babel/cli": "^7.10.5",
40+
"@babel/core": "^7.11.1",
41+
"@babel/plugin-transform-runtime": "^7.11.0",
42+
"@babel/preset-env": "^7.11.0",
43+
"@commitlint/cli": "^9.1.1",
44+
"@commitlint/config-conventional": "^9.1.1",
4545
"Base64": "^1.1.0",
4646
"babelify": "^10.0.0",
4747
"basic-auth-connect": "^1.0.0",
4848
"body-parser": "^1.19.0",
49-
"browserify": "^16.5.1",
50-
"codecov": "^3.7.0",
49+
"browserify": "^16.5.2",
50+
"codecov": "^3.7.2",
5151
"cookie-parser": "^1.4.5",
5252
"cross-env": "^7.0.2",
53-
"eslint": "^6.7.2",
53+
"eslint": "^7.6.0",
5454
"eslint-config-xo-lass": "^1.0.3",
5555
"eslint-plugin-compat": "^3.8.0",
5656
"eslint-plugin-node": "^11.1.0",
@@ -59,18 +59,17 @@
5959
"fixpack": "^3.0.6",
6060
"husky": "^4.2.5",
6161
"lint-staged": "^10.2.11",
62-
"marked": "^1.1.0",
62+
"marked": "^1.1.1",
6363
"mocha": "3.5.3",
6464
"multer": "^1.4.2",
6565
"nyc": "^15.1.0",
66-
"remark-cli": "^8.0.0",
67-
"remark-preset-github": "^2.0.0",
66+
"remark-cli": "^8.0.1",
67+
"remark-preset-github": "^3.0.0",
6868
"rimraf": "^3.0.2",
6969
"should": "^13.2.3",
7070
"should-http": "^0.1.1",
71-
"tinyify": "^2.5.2",
72-
"uglify-js": "^3.10.0",
73-
"xo": "0.25.3",
71+
"tinyify": "^3.0.0",
72+
"xo": "0.32.1",
7473
"zuul": "^3.12.0"
7574
},
7675
"engines": {
@@ -212,10 +211,16 @@
212211
"promise/prefer-await-to-then": "off",
213212
"promise/valid-params": "off",
214213
"unicorn/filename-case": "off",
215-
"valid-jsdoc": "off"
214+
"valid-jsdoc": "off",
215+
"node/no-unsupported-features/node-builtins": "off",
216+
"node/no-path-concat": "off"
216217
}
217218
}
218219
],
220+
"rules": {
221+
"unicorn/prevent-abbreviations": "off",
222+
"node/no-unsupported-features/es-syntax": "off"
223+
},
219224
"globals": [
220225
"ActiveXObject"
221226
]

src/agent-base.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ function Agent() {
2525
'pfx',
2626
'cert',
2727
'disableTLSCerts'
28-
].forEach(fn => {
28+
].forEach((fn) => {
2929
// Default setting for all requests from this agent
30-
Agent.prototype[fn] = function(...args) {
30+
Agent.prototype[fn] = function (...args) {
3131
this._defaults.push({ fn, args });
3232
return this;
3333
};
3434
});
3535

36-
Agent.prototype._setDefaults = function(req) {
37-
this._defaults.forEach(def => {
36+
Agent.prototype._setDefaults = function (req) {
37+
this._defaults.forEach((def) => {
3838
req[def.fn](...def.args);
3939
});
4040
};

src/client.js

+21-21
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function noop() {}
3434
* Expose `request`.
3535
*/
3636

37-
module.exports = function(method, url) {
37+
module.exports = function (method, url) {
3838
// callback
3939
if (typeof url === 'function') {
4040
return new exports.Request('GET', method).end(url);
@@ -95,7 +95,7 @@ request.getXHR = () => {
9595
* @api private
9696
*/
9797

98-
const trim = ''.trim ? s => s.trim() : s => s.replace(/(^\s*|\s*$)/g, '');
98+
const trim = ''.trim ? (s) => s.trim() : (s) => s.replace(/(^\s*|\s*$)/g, '');
9999

100100
/**
101101
* Serialize the given `obj`.
@@ -133,7 +133,7 @@ function pushEncodedKeyValuePair(pairs, key, val) {
133133
}
134134

135135
if (Array.isArray(val)) {
136-
val.forEach(v => {
136+
val.forEach((v) => {
137137
pushEncodedKeyValuePair(pairs, key, v);
138138
});
139139
} else if (isObject(val)) {
@@ -374,7 +374,7 @@ ResponseBase(Response.prototype);
374374
* @api private
375375
*/
376376

377-
Response.prototype._parseBody = function(str) {
377+
Response.prototype._parseBody = function (str) {
378378
let parse = request.parse[this.type];
379379
if (this.req._parser) {
380380
return this.req._parser(this, str);
@@ -396,7 +396,7 @@ Response.prototype._parseBody = function(str) {
396396
* @api public
397397
*/
398398

399-
Response.prototype.toError = function() {
399+
Response.prototype.toError = function () {
400400
const { req } = this;
401401
const { method } = req;
402402
const { url } = req;
@@ -515,7 +515,7 @@ RequestBase(Request.prototype);
515515
* @api public
516516
*/
517517

518-
Request.prototype.type = function(type) {
518+
Request.prototype.type = function (type) {
519519
this.set('Content-Type', request.types[type] || type);
520520
return this;
521521
};
@@ -540,7 +540,7 @@ Request.prototype.type = function(type) {
540540
* @api public
541541
*/
542542

543-
Request.prototype.accept = function(type) {
543+
Request.prototype.accept = function (type) {
544544
this.set('Accept', request.types[type] || type);
545545
return this;
546546
};
@@ -555,7 +555,7 @@ Request.prototype.accept = function(type) {
555555
* @api public
556556
*/
557557

558-
Request.prototype.auth = function(user, pass, options) {
558+
Request.prototype.auth = function (user, pass, options) {
559559
if (arguments.length === 1) pass = '';
560560
if (typeof pass === 'object' && pass !== null) {
561561
// pass is optional and can be replaced with options
@@ -569,7 +569,7 @@ Request.prototype.auth = function(user, pass, options) {
569569
};
570570
}
571571

572-
const encoder = string => {
572+
const encoder = (string) => {
573573
if (typeof btoa === 'function') {
574574
return btoa(string);
575575
}
@@ -594,7 +594,7 @@ Request.prototype.auth = function(user, pass, options) {
594594
* @api public
595595
*/
596596

597-
Request.prototype.query = function(val) {
597+
Request.prototype.query = function (val) {
598598
if (typeof val !== 'string') val = serialize(val);
599599
if (val) this._query.push(val);
600600
return this;
@@ -617,7 +617,7 @@ Request.prototype.query = function(val) {
617617
* @api public
618618
*/
619619

620-
Request.prototype.attach = function(field, file, options) {
620+
Request.prototype.attach = function (field, file, options) {
621621
if (file) {
622622
if (this._data) {
623623
throw new Error("superagent can't mix .send() and .attach()");
@@ -629,7 +629,7 @@ Request.prototype.attach = function(field, file, options) {
629629
return this;
630630
};
631631

632-
Request.prototype._getFormData = function() {
632+
Request.prototype._getFormData = function () {
633633
if (!this._formData) {
634634
this._formData = new root.FormData();
635635
}
@@ -646,7 +646,7 @@ Request.prototype._getFormData = function() {
646646
* @api private
647647
*/
648648

649-
Request.prototype.callback = function(err, res) {
649+
Request.prototype.callback = function (err, res) {
650650
if (this._shouldRetry(err, res)) {
651651
return this._retry();
652652
}
@@ -668,7 +668,7 @@ Request.prototype.callback = function(err, res) {
668668
* @api private
669669
*/
670670

671-
Request.prototype.crossDomainError = function() {
671+
Request.prototype.crossDomainError = function () {
672672
const err = new Error(
673673
'Request has been terminated\nPossible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc.'
674674
);
@@ -682,7 +682,7 @@ Request.prototype.crossDomainError = function() {
682682
};
683683

684684
// This only warns, because the request is still likely to work
685-
Request.prototype.agent = function() {
685+
Request.prototype.agent = function () {
686686
console.warn('This is not supported in browser version of superagent');
687687
return this;
688688
};
@@ -707,7 +707,7 @@ Request.prototype.pipe = Request.prototype.write;
707707
* @return {Boolean} is a host object
708708
* @api private
709709
*/
710-
Request.prototype._isHost = function(obj) {
710+
Request.prototype._isHost = function (obj) {
711711
// Native objects stringify to [object File], [object Blob], [object FormData], etc.
712712
return (
713713
obj &&
@@ -726,7 +726,7 @@ Request.prototype._isHost = function(obj) {
726726
* @api public
727727
*/
728728

729-
Request.prototype.end = function(fn) {
729+
Request.prototype.end = function (fn) {
730730
if (this._endCalled) {
731731
console.warn(
732732
'Warning: .end() was called twice. This is not supported in superagent'
@@ -744,7 +744,7 @@ Request.prototype.end = function(fn) {
744744
this._end();
745745
};
746746

747-
Request.prototype._setUploadTimeout = function() {
747+
Request.prototype._setUploadTimeout = function () {
748748
const self = this;
749749

750750
// upload timeout it's wokrs only if deadline timeout is off
@@ -760,7 +760,7 @@ Request.prototype._setUploadTimeout = function() {
760760
};
761761

762762
// eslint-disable-next-line complexity
763-
Request.prototype._end = function() {
763+
Request.prototype._end = function () {
764764
if (this._aborted)
765765
return this.callback(
766766
new Error('The request has been aborted even before .end() was called')
@@ -892,8 +892,8 @@ Request.prototype._end = function() {
892892

893893
request.agent = () => new Agent();
894894

895-
['GET', 'POST', 'OPTIONS', 'PATCH', 'PUT', 'DELETE'].forEach(method => {
896-
Agent.prototype[method.toLowerCase()] = function(url, fn) {
895+
['GET', 'POST', 'OPTIONS', 'PATCH', 'PUT', 'DELETE'].forEach((method) => {
896+
Agent.prototype[method.toLowerCase()] = function (url, fn) {
897897
const req = new request.Request(method, url);
898898
this._setDefaults(req);
899899
if (fn) {

0 commit comments

Comments
 (0)