Skip to content

Commit

Permalink
fix: bump deps, fixed linting, specific retry approach
Browse files Browse the repository at this point in the history
  • Loading branch information
niftylettuce committed Aug 8, 2020
1 parent 44fadf9 commit d68907b
Show file tree
Hide file tree
Showing 62 changed files with 1,648 additions and 1,564 deletions.
6 changes: 4 additions & 2 deletions .dist.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"no-useless-escape": "off",
"no-cond-assign": "off",
"no-redeclare": "off",
"node/no-exports-assign": "off"
"node/no-exports-assign": "off",
"no-unsafe-finally": "off"
},
"globals": {
"regeneratorRuntime": "writable"
Expand All @@ -29,7 +30,8 @@
"Array.from",
"Symbol",
"Object.getOwnPropertySymbols",
"Object.setPrototypeOf"
"Object.setPrototypeOf",
"Set"
]
}
}
3 changes: 2 additions & 1 deletion .lib.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"no-global-assign": ["error", {"exceptions": ["exports"]}],
"no-fallthrough": "off",
"no-constant-condition": "off",
"node/no-exports-assign": "off"
"node/no-exports-assign": "off",
"no-unsafe-finally": "off"
},
"overrides": [
{
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<script>` tags everywhere!

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

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

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


## Plugins
Expand Down Expand Up @@ -212,6 +212,10 @@ For SuperAgent extensions such as couchdb and oauth visit the [wiki](https://git
Our breaking changes are mostly in rarely used functionality and from stricter error handling.
* [5.x to 6.x](https://github.com/visionmedia/superagent/releases/tag/v6.0.0):
* 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)
* A specific issue with Content-Type matching not being case-insensitive is fixed
* Set is now required for IE 9, see [Required Browser Features](#required-browser-features) for more insight
* [4.x to 5.x](https://github.com/visionmedia/superagent/releases/tag/v5.0.0):
* We've implemented the build setup of [Lass](https://lass.js.org) to simplify our stack and linting
* 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`)
Expand Down
26 changes: 26 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,32 @@ This method has two optional arguments: number of retries (default 1) and a call

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

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).

By default the following status codes are retried:

* `408`
* `413`
* `429`
* `500`
* `502`
* `503`
* `504`
* `521`
* `522`
* `524`

By default the following error codes are retried:

* `'ETIMEDOUT'`
* `'ECONNRESET'`
* `'EADDRINUSE'`
* `'ECONNREFUSED'`
* `'EPIPE'`
* `'ENOTFOUND'`
* `'ENETUNREACH'`
* `'EAI_AGAIN'`

## Setting Accept

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:
Expand Down
37 changes: 21 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,21 @@
"semver": "^7.3.2"
},
"devDependencies": {
"@babel/cli": "^7.10.3",
"@babel/core": "^7.10.3",
"@babel/plugin-transform-runtime": "^7.10.5",
"@babel/preset-env": "^7.10.3",
"@commitlint/cli": "^9.0.1",
"@commitlint/config-conventional": "^9.0.1",
"@babel/cli": "^7.10.5",
"@babel/core": "^7.11.1",
"@babel/plugin-transform-runtime": "^7.11.0",
"@babel/preset-env": "^7.11.0",
"@commitlint/cli": "^9.1.1",
"@commitlint/config-conventional": "^9.1.1",
"Base64": "^1.1.0",
"babelify": "^10.0.0",
"basic-auth-connect": "^1.0.0",
"body-parser": "^1.19.0",
"browserify": "^16.5.1",
"codecov": "^3.7.0",
"browserify": "^16.5.2",
"codecov": "^3.7.2",
"cookie-parser": "^1.4.5",
"cross-env": "^7.0.2",
"eslint": "^6.7.2",
"eslint": "^7.6.0",
"eslint-config-xo-lass": "^1.0.3",
"eslint-plugin-compat": "^3.8.0",
"eslint-plugin-node": "^11.1.0",
Expand All @@ -59,18 +59,17 @@
"fixpack": "^3.0.6",
"husky": "^4.2.5",
"lint-staged": "^10.2.11",
"marked": "^1.1.0",
"marked": "^1.1.1",
"mocha": "3.5.3",
"multer": "^1.4.2",
"nyc": "^15.1.0",
"remark-cli": "^8.0.0",
"remark-preset-github": "^2.0.0",
"remark-cli": "^8.0.1",
"remark-preset-github": "^3.0.0",
"rimraf": "^3.0.2",
"should": "^13.2.3",
"should-http": "^0.1.1",
"tinyify": "^2.5.2",
"uglify-js": "^3.10.0",
"xo": "0.25.3",
"tinyify": "^3.0.0",
"xo": "0.32.1",
"zuul": "^3.12.0"
},
"engines": {
Expand Down Expand Up @@ -212,10 +211,16 @@
"promise/prefer-await-to-then": "off",
"promise/valid-params": "off",
"unicorn/filename-case": "off",
"valid-jsdoc": "off"
"valid-jsdoc": "off",
"node/no-unsupported-features/node-builtins": "off",
"node/no-path-concat": "off"
}
}
],
"rules": {
"unicorn/prevent-abbreviations": "off",
"node/no-unsupported-features/es-syntax": "off"
},
"globals": [
"ActiveXObject"
]
Expand Down
8 changes: 4 additions & 4 deletions src/agent-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ function Agent() {
'pfx',
'cert',
'disableTLSCerts'
].forEach(fn => {
].forEach((fn) => {
// Default setting for all requests from this agent
Agent.prototype[fn] = function(...args) {
Agent.prototype[fn] = function (...args) {
this._defaults.push({ fn, args });
return this;
};
});

Agent.prototype._setDefaults = function(req) {
this._defaults.forEach(def => {
Agent.prototype._setDefaults = function (req) {
this._defaults.forEach((def) => {
req[def.fn](...def.args);
});
};
Expand Down
42 changes: 21 additions & 21 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function noop() {}
* Expose `request`.
*/

module.exports = function(method, url) {
module.exports = function (method, url) {
// callback
if (typeof url === 'function') {
return new exports.Request('GET', method).end(url);
Expand Down Expand Up @@ -95,7 +95,7 @@ request.getXHR = () => {
* @api private
*/

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

/**
* Serialize the given `obj`.
Expand Down Expand Up @@ -133,7 +133,7 @@ function pushEncodedKeyValuePair(pairs, key, val) {
}

if (Array.isArray(val)) {
val.forEach(v => {
val.forEach((v) => {
pushEncodedKeyValuePair(pairs, key, v);
});
} else if (isObject(val)) {
Expand Down Expand Up @@ -374,7 +374,7 @@ ResponseBase(Response.prototype);
* @api private
*/

Response.prototype._parseBody = function(str) {
Response.prototype._parseBody = function (str) {
let parse = request.parse[this.type];
if (this.req._parser) {
return this.req._parser(this, str);
Expand All @@ -396,7 +396,7 @@ Response.prototype._parseBody = function(str) {
* @api public
*/

Response.prototype.toError = function() {
Response.prototype.toError = function () {
const { req } = this;
const { method } = req;
const { url } = req;
Expand Down Expand Up @@ -515,7 +515,7 @@ RequestBase(Request.prototype);
* @api public
*/

Request.prototype.type = function(type) {
Request.prototype.type = function (type) {
this.set('Content-Type', request.types[type] || type);
return this;
};
Expand All @@ -540,7 +540,7 @@ Request.prototype.type = function(type) {
* @api public
*/

Request.prototype.accept = function(type) {
Request.prototype.accept = function (type) {
this.set('Accept', request.types[type] || type);
return this;
};
Expand All @@ -555,7 +555,7 @@ Request.prototype.accept = function(type) {
* @api public
*/

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

const encoder = string => {
const encoder = (string) => {
if (typeof btoa === 'function') {
return btoa(string);
}
Expand All @@ -594,7 +594,7 @@ Request.prototype.auth = function(user, pass, options) {
* @api public
*/

Request.prototype.query = function(val) {
Request.prototype.query = function (val) {
if (typeof val !== 'string') val = serialize(val);
if (val) this._query.push(val);
return this;
Expand All @@ -617,7 +617,7 @@ Request.prototype.query = function(val) {
* @api public
*/

Request.prototype.attach = function(field, file, options) {
Request.prototype.attach = function (field, file, options) {
if (file) {
if (this._data) {
throw new Error("superagent can't mix .send() and .attach()");
Expand All @@ -629,7 +629,7 @@ Request.prototype.attach = function(field, file, options) {
return this;
};

Request.prototype._getFormData = function() {
Request.prototype._getFormData = function () {
if (!this._formData) {
this._formData = new root.FormData();
}
Expand All @@ -646,7 +646,7 @@ Request.prototype._getFormData = function() {
* @api private
*/

Request.prototype.callback = function(err, res) {
Request.prototype.callback = function (err, res) {
if (this._shouldRetry(err, res)) {
return this._retry();
}
Expand All @@ -668,7 +668,7 @@ Request.prototype.callback = function(err, res) {
* @api private
*/

Request.prototype.crossDomainError = function() {
Request.prototype.crossDomainError = function () {
const err = new Error(
'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.'
);
Expand All @@ -682,7 +682,7 @@ Request.prototype.crossDomainError = function() {
};

// This only warns, because the request is still likely to work
Request.prototype.agent = function() {
Request.prototype.agent = function () {
console.warn('This is not supported in browser version of superagent');
return this;
};
Expand All @@ -707,7 +707,7 @@ Request.prototype.pipe = Request.prototype.write;
* @return {Boolean} is a host object
* @api private
*/
Request.prototype._isHost = function(obj) {
Request.prototype._isHost = function (obj) {
// Native objects stringify to [object File], [object Blob], [object FormData], etc.
return (
obj &&
Expand All @@ -726,7 +726,7 @@ Request.prototype._isHost = function(obj) {
* @api public
*/

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

Request.prototype._setUploadTimeout = function() {
Request.prototype._setUploadTimeout = function () {
const self = this;

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

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

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

['GET', 'POST', 'OPTIONS', 'PATCH', 'PUT', 'DELETE'].forEach(method => {
Agent.prototype[method.toLowerCase()] = function(url, fn) {
['GET', 'POST', 'OPTIONS', 'PATCH', 'PUT', 'DELETE'].forEach((method) => {
Agent.prototype[method.toLowerCase()] = function (url, fn) {
const req = new request.Request(method, url);
this._setDefaults(req);
if (fn) {
Expand Down
Loading

0 comments on commit d68907b

Please sign in to comment.