From 650497bc957078610cea23f29438fcef338b3988 Mon Sep 17 00:00:00 2001 From: Justin Beckwith Date: Thu, 25 Apr 2019 20:41:40 -0700 Subject: [PATCH] fix(deps): upgrade to the latest version of gts (#83) --- .clang-format | 3 - browser-test/browser-test-runner.ts | 10 +- browser-test/test.browser.ts | 8 +- package-lock.json | 1005 +++++++++++++++------- package.json | 2 +- prettier.config.js | 4 + src/common.ts | 35 +- src/gaxios.ts | 60 +- src/index.ts | 14 +- src/isbrowser.ts | 2 +- src/retry.ts | 47 +- system-test/fixtures/sample/package.json | 2 +- system-test/test.install.ts | 27 +- test/test.getch.ts | 229 +++-- test/test.retry.ts | 139 +-- tslint.json | 6 +- 16 files changed, 1054 insertions(+), 539 deletions(-) delete mode 100644 .clang-format create mode 100644 prettier.config.js diff --git a/.clang-format b/.clang-format deleted file mode 100644 index 7d6cf97e..00000000 --- a/.clang-format +++ /dev/null @@ -1,3 +0,0 @@ -Language: JavaScript -BasedOnStyle: Google -ColumnLimit: 80 \ No newline at end of file diff --git a/browser-test/browser-test-runner.ts b/browser-test/browser-test-runner.ts index 900a00fc..5943a4cc 100644 --- a/browser-test/browser-test-runner.ts +++ b/browser-test/browser-test-runner.ts @@ -18,7 +18,9 @@ import http from 'http'; const port = 7172; async function listen( - app: express.Express, port: number): Promise { + app: express.Express, + port: number +): Promise { return new Promise((resolve, reject) => { const server = app.listen(port, (err: Error) => { if (err) { @@ -49,11 +51,11 @@ async function main() { const server = await listen(app, port); console.log(`[http server] I'm listening on port ${port}! Starting karma.`); - const result = await execa('karma', ['start'], {stdio: 'inherit'}); + const result = await execa('karma', ['start'], { stdio: 'inherit' }); server.close(); console.log( - `[http server] Karma has finished! I'm no longer listening on port ${ - port}!`); + `[http server] Karma has finished! I'm no longer listening on port ${port}!` + ); process.exit(result.failed ? 1 : 0); } diff --git a/browser-test/test.browser.ts b/browser-test/test.browser.ts index 8db0a53d..e90d0020 100644 --- a/browser-test/test.browser.ts +++ b/browser-test/test.browser.ts @@ -1,11 +1,11 @@ import assert from 'assert'; -import {request} from '../src/index'; -const port = 7172; // should match the port defined in `webserver.ts` +import { request } from '../src/index'; +const port = 7172; // should match the port defined in `webserver.ts` describe('💻 browser tests', () => { it('should just work from browser', async () => { - const result = await request({url: `http://localhost:${port}/path`}); + const result = await request({ url: `http://localhost:${port}/path` }); assert.strictEqual(result.status, 200); assert.strictEqual(result.data, 'response'); }); @@ -13,7 +13,7 @@ describe('💻 browser tests', () => { it('should pass querystring parameters from browser', async () => { const result = await request({ url: `http://localhost:${port}/querystring`, - params: {query: 'value'} + params: { query: 'value' }, }); assert.strictEqual(result.status, 200); assert.strictEqual(result.data, 'value'); diff --git a/package-lock.json b/package-lock.json index 8ebe0a5e..36e42302 100644 --- a/package-lock.json +++ b/package-lock.json @@ -282,49 +282,34 @@ } }, "@semantic-release/npm": { - "version": "5.1.4", - "resolved": "https://registry.npmjs.org/@semantic-release/npm/-/npm-5.1.4.tgz", - "integrity": "sha512-YRl8VTVwnRTl/sVRvTXs1ncYcuvuGrqPEXYy+lUK1YRLq25hkrhIdv3Ju0u1zGLqVCA8qRlF3NzWl7pULJXVog==", + "version": "5.1.7", + "resolved": "https://registry.npmjs.org/@semantic-release/npm/-/npm-5.1.7.tgz", + "integrity": "sha512-4THiFGp9APX1a+EJJsOYurJCR8TrRUgNCU9u46AkZekWfvtyzacfIBKCrmEljpYG8qDDnHLZwHSqyW4ID4iteA==", "dev": true, "requires": { "@semantic-release/error": "^2.2.0", - "aggregate-error": "^2.0.0", + "aggregate-error": "^3.0.0", "execa": "^1.0.0", "fs-extra": "^7.0.0", "lodash": "^4.17.4", "nerf-dart": "^1.0.0", "normalize-url": "^4.0.0", - "npm": "6.5.0", + "npm": "^6.8.0", "rc": "^1.2.8", - "read-pkg": "^4.0.0", + "read-pkg": "^5.0.0", "registry-auth-token": "^3.3.1" }, "dependencies": { - "aggregate-error": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/aggregate-error/-/aggregate-error-2.2.0.tgz", - "integrity": "sha512-E5n+IZkhh22/pFdUvHUU/o9z752lc+7tgHt+FXS/g6BjlbE9249dGmuS/SxIWMPhTljZJkFN+7OXE0+O5+WT8w==", - "dev": true, - "requires": { - "clean-stack": "^2.0.0", - "indent-string": "^3.0.0" - } - }, - "pify": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz", - "integrity": "sha1-5aSs0sEB/fPZpNB/DbxNtJ3SgXY=", - "dev": true - }, "read-pkg": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-4.0.1.tgz", - "integrity": "sha1-ljYlN48+HE1IyFhytabsfV0JMjc=", + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-5.1.0.tgz", + "integrity": "sha512-NjNkqf8hlMuSxh+p8h8x8sCIfEv/MoRs/nYDmSRSAk879F9C94ADq+kHUJ4LTy5Nn0PYSmMYsy1mD4+lcXiBKg==", "dev": true, "requires": { - "normalize-package-data": "^2.3.2", + "@types/normalize-package-data": "^2.4.0", + "normalize-package-data": "^2.5.0", "parse-json": "^4.0.0", - "pify": "^3.0.0" + "type-fest": "^0.4.1" } } } @@ -522,6 +507,12 @@ "@types/node": "*" } }, + "@types/normalize-package-data": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/@types/normalize-package-data/-/normalize-package-data-2.4.0.tgz", + "integrity": "sha512-f5j5b/Gf71L+dbqxIpQ4Z2WlmI/mPJ0fOkGGmFgtb6sAu97EPczzbS3/tJKxmcYDj55OX6ssqwDAWOHIYDRDGA==", + "dev": true + }, "@types/range-parser": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/@types/range-parser/-/range-parser-1.2.3.tgz", @@ -1755,17 +1746,6 @@ "safe-buffer": "^5.0.1" } }, - "clang-format": { - "version": "1.2.3", - "resolved": "https://registry.npmjs.org/clang-format/-/clang-format-1.2.3.tgz", - "integrity": "sha512-x90Hac4ERacGDcZSvHKK58Ga0STuMD+Doi5g0iG2zf7wlJef5Huvhs/3BvMRFxwRYyYSdl6mpQNrtfMxE8MQzw==", - "dev": true, - "requires": { - "async": "^1.5.2", - "glob": "^7.0.0", - "resolve": "^1.1.6" - } - }, "class-utils": { "version": "0.3.6", "resolved": "https://registry.npmjs.org/class-utils/-/class-utils-0.3.6.tgz", @@ -4474,22 +4454,30 @@ "dev": true }, "gts": { - "version": "0.9.0", - "resolved": "https://registry.npmjs.org/gts/-/gts-0.9.0.tgz", - "integrity": "sha512-Id2Vmg0xNU1FODc0AwmaFA1h0+h6V9/zBqu4NfT8FucVOVEP7pyJ16btyHfSH/UdzTCXjV1fq+fNBEgx/50EaA==", + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/gts/-/gts-1.0.0.tgz", + "integrity": "sha512-/CRhAi0/xkH1l9UveIlTxLLBcTzUNa2PHyBrllLuYtVXZc8NPh/hZmxO6JwxF6OD1GxJyAwyMt5+RjnBncI5jw==", "dev": true, "requires": { "chalk": "^2.4.1", - "clang-format": "1.2.3", - "diff": "^3.5.0", + "diff": "^4.0.1", "entities": "^1.1.1", "inquirer": "^6.0.0", "meow": "^5.0.0", "pify": "^4.0.0", + "prettier": "^1.15.3", "rimraf": "^2.6.2", - "tslint": "^5.9.1", + "tslint": "^5.12.0", "update-notifier": "^2.5.0", "write-file-atomic": "^2.3.0" + }, + "dependencies": { + "diff": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.1.tgz", + "integrity": "sha512-s2+XdvhPCOF01LRQBC8hf4vhbVmI2CGS5aZnxLJlT5FtdhPCDFq80q++zK2KlrVorVDdL5BOGZ/VfLrVtYNF+Q==", + "dev": true + } } }, "handlebars": { @@ -6672,26 +6660,26 @@ "dev": true }, "npm": { - "version": "6.5.0", - "resolved": "https://registry.npmjs.org/npm/-/npm-6.5.0.tgz", - "integrity": "sha512-SPq8zG2Kto+Xrq55E97O14Jla13PmQT5kSnvwBj88BmJZ5Nvw++OmlWfhjkB67pcgP5UEXljEtnGFKZtOgt6MQ==", + "version": "6.9.0", + "resolved": "https://registry.npmjs.org/npm/-/npm-6.9.0.tgz", + "integrity": "sha512-91V+zB5hDxO+Jyp2sUKS7juHlIM95dGQxTeQtmZI1nAI/7kjWXFipPrtwwKjhyKmV4GsS2LzJhrxRjGWsU9z/w==", "dev": true, "requires": { - "JSONStream": "^1.3.4", + "JSONStream": "^1.3.5", "abbrev": "~1.1.1", "ansicolors": "~0.3.2", "ansistyles": "~0.1.3", - "aproba": "~1.2.0", + "aproba": "^2.0.0", "archy": "~1.0.0", "bin-links": "^1.1.2", "bluebird": "^3.5.3", - "byte-size": "^4.0.3", - "cacache": "^11.2.0", + "byte-size": "^5.0.1", + "cacache": "^11.3.2", "call-limit": "~1.1.0", - "chownr": "~1.0.1", - "ci-info": "^1.6.0", + "chownr": "^1.1.1", + "ci-info": "^2.0.0", "cli-columns": "^3.1.2", - "cli-table3": "^0.5.0", + "cli-table3": "^0.5.1", "cmd-shim": "~2.0.2", "columnify": "~1.5.4", "config-chain": "^1.1.12", @@ -6715,13 +6703,18 @@ "inherits": "~2.0.3", "ini": "^1.3.5", "init-package-json": "^1.10.3", - "is-cidr": "^2.0.6", + "is-cidr": "^3.0.0", "json-parse-better-errors": "^1.0.2", "lazy-property": "~1.0.0", - "libcipm": "^2.0.2", - "libnpmhook": "^4.0.1", + "libcipm": "^3.0.3", + "libnpm": "^2.0.1", + "libnpmaccess": "*", + "libnpmhook": "^5.0.2", + "libnpmorg": "*", + "libnpmsearch": "*", + "libnpmteam": "*", "libnpx": "^10.2.0", - "lock-verify": "^2.0.2", + "lock-verify": "^2.1.0", "lockfile": "^1.0.4", "lodash._baseindexof": "*", "lodash._baseuniq": "~4.6.0", @@ -6734,47 +6727,46 @@ "lodash.union": "~4.6.0", "lodash.uniq": "~4.5.0", "lodash.without": "~4.4.0", - "lru-cache": "^4.1.3", + "lru-cache": "^4.1.5", "meant": "~1.0.1", "mississippi": "^3.0.0", "mkdirp": "~0.5.1", "move-concurrently": "^1.0.1", "node-gyp": "^3.8.0", "nopt": "~4.0.1", - "normalize-package-data": "~2.4.0", - "npm-audit-report": "^1.3.1", + "normalize-package-data": "^2.5.0", + "npm-audit-report": "^1.3.2", "npm-cache-filename": "~1.0.2", "npm-install-checks": "~3.0.0", "npm-lifecycle": "^2.1.0", "npm-package-arg": "^6.1.0", - "npm-packlist": "^1.1.12", - "npm-pick-manifest": "^2.1.0", - "npm-profile": "^3.0.2", - "npm-registry-client": "^8.6.0", - "npm-registry-fetch": "^1.1.0", + "npm-packlist": "^1.4.1", + "npm-pick-manifest": "^2.2.3", + "npm-profile": "*", + "npm-registry-fetch": "^3.9.0", "npm-user-validate": "~1.0.0", "npmlog": "~4.1.2", "once": "~1.4.0", "opener": "^1.5.1", "osenv": "^0.1.5", - "pacote": "^8.1.6", + "pacote": "^9.5.0", "path-is-inside": "~1.0.2", "promise-inflight": "~1.0.1", "qrcode-terminal": "^0.12.0", - "query-string": "^6.1.0", + "query-string": "^6.2.0", "qw": "~1.0.1", "read": "~1.0.7", "read-cmd-shim": "~1.0.1", "read-installed": "~4.0.3", "read-package-json": "^2.0.13", - "read-package-tree": "^5.2.1", - "readable-stream": "^2.3.6", + "read-package-tree": "^5.2.2", + "readable-stream": "^3.1.1", "readdir-scoped-modules": "*", "request": "^2.88.0", "retry": "^0.12.0", - "rimraf": "~2.6.2", + "rimraf": "^2.6.3", "safe-buffer": "^5.1.2", - "semver": "^5.5.1", + "semver": "^5.6.0", "sha": "~2.0.1", "slide": "~1.1.6", "sorted-object": "~2.0.1", @@ -6786,7 +6778,7 @@ "tiny-relative-date": "^1.3.0", "uid-number": "0.0.6", "umask": "~1.1.0", - "unique-filename": "~1.1.0", + "unique-filename": "^1.1.1", "unpipe": "~1.0.0", "update-notifier": "^2.5.0", "uuid": "^3.3.2", @@ -6794,11 +6786,11 @@ "validate-npm-package-name": "~3.0.0", "which": "^1.3.1", "worker-farm": "^1.6.0", - "write-file-atomic": "^2.3.0" + "write-file-atomic": "^2.4.2" }, "dependencies": { "JSONStream": { - "version": "1.3.4", + "version": "1.3.5", "bundled": true, "dev": true, "requires": { @@ -6812,7 +6804,7 @@ "dev": true }, "agent-base": { - "version": "4.2.0", + "version": "4.2.1", "bundled": true, "dev": true, "requires": { @@ -6870,7 +6862,7 @@ "dev": true }, "aproba": { - "version": "1.2.0", + "version": "2.0.0", "bundled": true, "dev": true }, @@ -6886,6 +6878,30 @@ "requires": { "delegates": "^1.0.0", "readable-stream": "^2.0.6" + }, + "dependencies": { + "readable-stream": { + "version": "2.3.6", + "bundled": true, + "dev": true, + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + } + }, + "string_decoder": { + "version": "1.1.1", + "bundled": true, + "dev": true, + "requires": { + "safe-buffer": "~5.1.0" + } + } } }, "asap": { @@ -6988,11 +7004,6 @@ "bundled": true, "dev": true }, - "builtin-modules": { - "version": "1.1.1", - "bundled": true, - "dev": true - }, "builtins": { "version": "1.0.3", "bundled": true, @@ -7004,29 +7015,57 @@ "dev": true }, "byte-size": { - "version": "4.0.3", + "version": "5.0.1", "bundled": true, "dev": true }, "cacache": { - "version": "11.2.0", + "version": "11.3.2", "bundled": true, "dev": true, "requires": { - "bluebird": "^3.5.1", - "chownr": "^1.0.1", - "figgy-pudding": "^3.1.0", - "glob": "^7.1.2", - "graceful-fs": "^4.1.11", - "lru-cache": "^4.1.3", + "bluebird": "^3.5.3", + "chownr": "^1.1.1", + "figgy-pudding": "^3.5.1", + "glob": "^7.1.3", + "graceful-fs": "^4.1.15", + "lru-cache": "^5.1.1", "mississippi": "^3.0.0", "mkdirp": "^0.5.1", "move-concurrently": "^1.0.1", "promise-inflight": "^1.0.1", "rimraf": "^2.6.2", - "ssri": "^6.0.0", - "unique-filename": "^1.1.0", + "ssri": "^6.0.1", + "unique-filename": "^1.1.1", "y18n": "^4.0.0" + }, + "dependencies": { + "chownr": { + "version": "1.1.1", + "bundled": true, + "dev": true + }, + "lru-cache": { + "version": "5.1.1", + "bundled": true, + "dev": true, + "requires": { + "yallist": "^3.0.2" + } + }, + "unique-filename": { + "version": "1.1.1", + "bundled": true, + "dev": true, + "requires": { + "unique-slug": "^2.0.0" + } + }, + "yallist": { + "version": "3.0.3", + "bundled": true, + "dev": true + } } }, "call-limit": { @@ -7060,17 +7099,17 @@ } }, "chownr": { - "version": "1.0.1", + "version": "1.1.1", "bundled": true, "dev": true }, "ci-info": { - "version": "1.6.0", + "version": "2.0.0", "bundled": true, "dev": true }, "cidr-regex": { - "version": "2.0.9", + "version": "2.0.10", "bundled": true, "dev": true, "requires": { @@ -7092,7 +7131,7 @@ } }, "cli-table3": { - "version": "0.5.0", + "version": "0.5.1", "bundled": true, "dev": true, "requires": { @@ -7164,7 +7203,7 @@ "dev": true }, "colors": { - "version": "1.1.2", + "version": "1.3.3", "bundled": true, "dev": true, "optional": true @@ -7200,6 +7239,30 @@ "inherits": "^2.0.3", "readable-stream": "^2.2.2", "typedarray": "^0.0.6" + }, + "dependencies": { + "readable-stream": { + "version": "2.3.6", + "bundled": true, + "dev": true, + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + } + }, + "string_decoder": { + "version": "1.1.1", + "bundled": true, + "dev": true, + "requires": { + "safe-buffer": "~5.1.0" + } + } } }, "config-chain": { @@ -7242,6 +7305,11 @@ "run-queue": "^1.0.0" }, "dependencies": { + "aproba": { + "version": "1.2.0", + "bundled": true, + "dev": true + }, "iferr": { "version": "0.1.5", "bundled": true, @@ -7389,6 +7457,30 @@ "inherits": "^2.0.1", "readable-stream": "^2.0.0", "stream-shift": "^1.0.0" + }, + "dependencies": { + "readable-stream": { + "version": "2.3.6", + "bundled": true, + "dev": true, + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + } + }, + "string_decoder": { + "version": "1.1.1", + "bundled": true, + "dev": true, + "requires": { + "safe-buffer": "~5.1.0" + } + } } }, "ecc-jsbn": { @@ -7436,7 +7528,7 @@ } }, "es6-promise": { - "version": "4.2.4", + "version": "4.2.6", "bundled": true, "dev": true }, @@ -7465,6 +7557,13 @@ "p-finally": "^1.0.0", "signal-exit": "^3.0.0", "strip-eof": "^1.0.0" + }, + "dependencies": { + "get-stream": { + "version": "3.0.0", + "bundled": true, + "dev": true + } } }, "extend": { @@ -7512,6 +7611,30 @@ "requires": { "inherits": "^2.0.1", "readable-stream": "^2.0.4" + }, + "dependencies": { + "readable-stream": { + "version": "2.3.6", + "bundled": true, + "dev": true, + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + } + }, + "string_decoder": { + "version": "1.1.1", + "bundled": true, + "dev": true, + "requires": { + "safe-buffer": "~5.1.0" + } + } } }, "forever-agent": { @@ -7536,6 +7659,30 @@ "requires": { "inherits": "^2.0.1", "readable-stream": "^2.0.0" + }, + "dependencies": { + "readable-stream": { + "version": "2.3.6", + "bundled": true, + "dev": true, + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + } + }, + "string_decoder": { + "version": "1.1.1", + "bundled": true, + "dev": true, + "requires": { + "safe-buffer": "~5.1.0" + } + } } }, "fs-minipass": { @@ -7571,6 +7718,28 @@ "version": "0.1.5", "bundled": true, "dev": true + }, + "readable-stream": { + "version": "2.3.6", + "bundled": true, + "dev": true, + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + } + }, + "string_decoder": { + "version": "1.1.1", + "bundled": true, + "dev": true, + "requires": { + "safe-buffer": "~5.1.0" + } } } }, @@ -7605,6 +7774,11 @@ "wide-align": "^1.1.0" }, "dependencies": { + "aproba": { + "version": "1.2.0", + "bundled": true, + "dev": true + }, "string-width": { "version": "1.0.2", "bundled": true, @@ -7618,7 +7792,7 @@ } }, "genfun": { - "version": "4.0.1", + "version": "5.0.0", "bundled": true, "dev": true }, @@ -7637,6 +7811,11 @@ "slide": "^1.1.6" }, "dependencies": { + "aproba": { + "version": "1.2.0", + "bundled": true, + "dev": true + }, "iferr": { "version": "0.1.5", "bundled": true, @@ -7650,9 +7829,12 @@ "dev": true }, "get-stream": { - "version": "3.0.0", + "version": "4.1.0", "bundled": true, - "dev": true + "dev": true, + "requires": { + "pump": "^3.0.0" + } }, "getpass": { "version": "0.1.7", @@ -7699,6 +7881,13 @@ "timed-out": "^4.0.0", "unzip-response": "^2.0.1", "url-parse-lax": "^1.0.0" + }, + "dependencies": { + "get-stream": { + "version": "3.0.0", + "bundled": true, + "dev": true + } } }, "graceful-fs": { @@ -7856,28 +8045,27 @@ "bundled": true, "dev": true }, - "is-builtin-module": { - "version": "1.0.0", - "bundled": true, - "dev": true, - "requires": { - "builtin-modules": "^1.0.0" - } - }, "is-ci": { "version": "1.1.0", "bundled": true, "dev": true, "requires": { "ci-info": "^1.0.0" + }, + "dependencies": { + "ci-info": { + "version": "1.6.0", + "bundled": true, + "dev": true + } } }, "is-cidr": { - "version": "2.0.6", + "version": "3.0.0", "bundled": true, "dev": true, "requires": { - "cidr-regex": "^2.0.8" + "cidr-regex": "^2.0.10" } }, "is-fullwidth-code-point": { @@ -8014,56 +8202,202 @@ } }, "libcipm": { - "version": "2.0.2", + "version": "3.0.3", "bundled": true, "dev": true, "requires": { "bin-links": "^1.1.2", "bluebird": "^3.5.1", + "figgy-pudding": "^3.5.1", "find-npm-prefix": "^1.0.2", "graceful-fs": "^4.1.11", + "ini": "^1.3.5", "lock-verify": "^2.0.2", "mkdirp": "^0.5.1", "npm-lifecycle": "^2.0.3", "npm-logical-tree": "^1.2.1", "npm-package-arg": "^6.1.0", - "pacote": "^8.1.6", - "protoduck": "^5.0.0", + "pacote": "^9.1.0", "read-package-json": "^2.0.13", "rimraf": "^2.6.2", "worker-farm": "^1.6.0" } }, - "libnpmhook": { - "version": "4.0.1", + "libnpm": { + "version": "2.0.1", + "bundled": true, + "dev": true, + "requires": { + "bin-links": "^1.1.2", + "bluebird": "^3.5.3", + "find-npm-prefix": "^1.0.2", + "libnpmaccess": "^3.0.1", + "libnpmconfig": "^1.2.1", + "libnpmhook": "^5.0.2", + "libnpmorg": "^1.0.0", + "libnpmpublish": "^1.1.0", + "libnpmsearch": "^2.0.0", + "libnpmteam": "^1.0.1", + "lock-verify": "^2.0.2", + "npm-lifecycle": "^2.1.0", + "npm-logical-tree": "^1.2.1", + "npm-package-arg": "^6.1.0", + "npm-profile": "^4.0.1", + "npm-registry-fetch": "^3.8.0", + "npmlog": "^4.1.2", + "pacote": "^9.2.3", + "read-package-json": "^2.0.13", + "stringify-package": "^1.0.0" + } + }, + "libnpmaccess": { + "version": "3.0.1", "bundled": true, "dev": true, "requires": { - "figgy-pudding": "^3.1.0", - "npm-registry-fetch": "^3.0.0" + "aproba": "^2.0.0", + "get-stream": "^4.0.0", + "npm-package-arg": "^6.1.0", + "npm-registry-fetch": "^3.8.0" }, "dependencies": { - "npm-registry-fetch": { - "version": "3.1.1", + "aproba": { + "version": "2.0.0", "bundled": true, - "dev": true, - "requires": { - "bluebird": "^3.5.1", - "figgy-pudding": "^3.1.0", - "lru-cache": "^4.1.2", - "make-fetch-happen": "^4.0.0", - "npm-package-arg": "^6.0.0" - } + "dev": true } } }, - "libnpx": { - "version": "10.2.0", + "libnpmconfig": { + "version": "1.2.1", "bundled": true, "dev": true, "requires": { - "dotenv": "^5.0.1", - "npm-package-arg": "^6.0.0", + "figgy-pudding": "^3.5.1", + "find-up": "^3.0.0", + "ini": "^1.3.5" + }, + "dependencies": { + "find-up": { + "version": "3.0.0", + "bundled": true, + "dev": true, + "requires": { + "locate-path": "^3.0.0" + } + }, + "locate-path": { + "version": "3.0.0", + "bundled": true, + "dev": true, + "requires": { + "p-locate": "^3.0.0", + "path-exists": "^3.0.0" + } + }, + "p-limit": { + "version": "2.1.0", + "bundled": true, + "dev": true, + "requires": { + "p-try": "^2.0.0" + } + }, + "p-locate": { + "version": "3.0.0", + "bundled": true, + "dev": true, + "requires": { + "p-limit": "^2.0.0" + } + }, + "p-try": { + "version": "2.0.0", + "bundled": true, + "dev": true + } + } + }, + "libnpmhook": { + "version": "5.0.2", + "bundled": true, + "dev": true, + "requires": { + "aproba": "^2.0.0", + "figgy-pudding": "^3.4.1", + "get-stream": "^4.0.0", + "npm-registry-fetch": "^3.8.0" + } + }, + "libnpmorg": { + "version": "1.0.0", + "bundled": true, + "dev": true, + "requires": { + "aproba": "^2.0.0", + "figgy-pudding": "^3.4.1", + "get-stream": "^4.0.0", + "npm-registry-fetch": "^3.8.0" + }, + "dependencies": { + "aproba": { + "version": "2.0.0", + "bundled": true, + "dev": true + } + } + }, + "libnpmpublish": { + "version": "1.1.1", + "bundled": true, + "dev": true, + "requires": { + "aproba": "^2.0.0", + "figgy-pudding": "^3.5.1", + "get-stream": "^4.0.0", + "lodash.clonedeep": "^4.5.0", + "normalize-package-data": "^2.4.0", + "npm-package-arg": "^6.1.0", + "npm-registry-fetch": "^3.8.0", + "semver": "^5.5.1", + "ssri": "^6.0.1" + } + }, + "libnpmsearch": { + "version": "2.0.0", + "bundled": true, + "dev": true, + "requires": { + "figgy-pudding": "^3.5.1", + "get-stream": "^4.0.0", + "npm-registry-fetch": "^3.8.0" + } + }, + "libnpmteam": { + "version": "1.0.1", + "bundled": true, + "dev": true, + "requires": { + "aproba": "^2.0.0", + "figgy-pudding": "^3.4.1", + "get-stream": "^4.0.0", + "npm-registry-fetch": "^3.8.0" + }, + "dependencies": { + "aproba": { + "version": "2.0.0", + "bundled": true, + "dev": true + } + } + }, + "libnpx": { + "version": "10.2.0", + "bundled": true, + "dev": true, + "requires": { + "dotenv": "^5.0.1", + "npm-package-arg": "^6.0.0", "rimraf": "^2.6.2", "safe-buffer": "^5.1.0", "update-notifier": "^2.3.0", @@ -8082,11 +8416,11 @@ } }, "lock-verify": { - "version": "2.0.2", + "version": "2.1.0", "bundled": true, "dev": true, "requires": { - "npm-package-arg": "^5.1.2 || 6", + "npm-package-arg": "^6.1.0", "semver": "^5.4.1" } }, @@ -8176,7 +8510,7 @@ "dev": true }, "lru-cache": { - "version": "4.1.3", + "version": "4.1.5", "bundled": true, "dev": true, "requires": { @@ -8314,6 +8648,13 @@ "mkdirp": "^0.5.1", "rimraf": "^2.5.4", "run-queue": "^1.0.3" + }, + "dependencies": { + "aproba": { + "version": "1.2.0", + "bundled": true, + "dev": true + } } }, "ms": { @@ -8390,18 +8731,28 @@ } }, "normalize-package-data": { - "version": "2.4.0", + "version": "2.5.0", "bundled": true, "dev": true, "requires": { "hosted-git-info": "^2.1.4", - "is-builtin-module": "^1.0.0", + "resolve": "^1.10.0", "semver": "2 || 3 || 4 || 5", "validate-npm-package-license": "^3.0.1" + }, + "dependencies": { + "resolve": { + "version": "1.10.0", + "bundled": true, + "dev": true, + "requires": { + "path-parse": "^1.0.6" + } + } } }, "npm-audit-report": { - "version": "1.3.1", + "version": "1.3.2", "bundled": true, "dev": true, "requires": { @@ -8410,7 +8761,7 @@ } }, "npm-bundled": { - "version": "1.0.5", + "version": "1.0.6", "bundled": true, "dev": true }, @@ -8459,7 +8810,7 @@ } }, "npm-packlist": { - "version": "1.1.12", + "version": "1.4.1", "bundled": true, "dev": true, "requires": { @@ -8468,172 +8819,36 @@ } }, "npm-pick-manifest": { - "version": "2.1.0", + "version": "2.2.3", "bundled": true, "dev": true, "requires": { + "figgy-pudding": "^3.5.1", "npm-package-arg": "^6.0.0", "semver": "^5.4.1" } }, "npm-profile": { - "version": "3.0.2", + "version": "4.0.1", "bundled": true, "dev": true, "requires": { "aproba": "^1.1.2 || 2", - "make-fetch-happen": "^2.5.0 || 3 || 4" - } - }, - "npm-registry-client": { - "version": "8.6.0", - "bundled": true, - "dev": true, - "requires": { - "concat-stream": "^1.5.2", - "graceful-fs": "^4.1.6", - "normalize-package-data": "~1.0.1 || ^2.0.0", - "npm-package-arg": "^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0", - "npmlog": "2 || ^3.1.0 || ^4.0.0", - "once": "^1.3.3", - "request": "^2.74.0", - "retry": "^0.10.0", - "safe-buffer": "^5.1.1", - "semver": "2 >=2.2.1 || 3.x || 4 || 5", - "slide": "^1.1.3", - "ssri": "^5.2.4" - }, - "dependencies": { - "retry": { - "version": "0.10.1", - "bundled": true, - "dev": true - }, - "ssri": { - "version": "5.3.0", - "bundled": true, - "dev": true, - "requires": { - "safe-buffer": "^5.1.1" - } - } + "figgy-pudding": "^3.4.1", + "npm-registry-fetch": "^3.8.0" } }, "npm-registry-fetch": { - "version": "1.1.0", + "version": "3.9.0", "bundled": true, "dev": true, "requires": { + "JSONStream": "^1.3.4", "bluebird": "^3.5.1", - "figgy-pudding": "^2.0.1", - "lru-cache": "^4.1.2", - "make-fetch-happen": "^3.0.0", - "npm-package-arg": "^6.0.0", - "safe-buffer": "^5.1.1" - }, - "dependencies": { - "cacache": { - "version": "10.0.4", - "bundled": true, - "dev": true, - "requires": { - "bluebird": "^3.5.1", - "chownr": "^1.0.1", - "glob": "^7.1.2", - "graceful-fs": "^4.1.11", - "lru-cache": "^4.1.1", - "mississippi": "^2.0.0", - "mkdirp": "^0.5.1", - "move-concurrently": "^1.0.1", - "promise-inflight": "^1.0.1", - "rimraf": "^2.6.2", - "ssri": "^5.2.4", - "unique-filename": "^1.1.0", - "y18n": "^4.0.0" - }, - "dependencies": { - "mississippi": { - "version": "2.0.0", - "bundled": true, - "dev": true, - "requires": { - "concat-stream": "^1.5.0", - "duplexify": "^3.4.2", - "end-of-stream": "^1.1.0", - "flush-write-stream": "^1.0.0", - "from2": "^2.1.0", - "parallel-transform": "^1.1.0", - "pump": "^2.0.1", - "pumpify": "^1.3.3", - "stream-each": "^1.1.0", - "through2": "^2.0.0" - } - } - } - }, - "figgy-pudding": { - "version": "2.0.1", - "bundled": true, - "dev": true - }, - "make-fetch-happen": { - "version": "3.0.0", - "bundled": true, - "dev": true, - "requires": { - "agentkeepalive": "^3.4.1", - "cacache": "^10.0.4", - "http-cache-semantics": "^3.8.1", - "http-proxy-agent": "^2.1.0", - "https-proxy-agent": "^2.2.0", - "lru-cache": "^4.1.2", - "mississippi": "^3.0.0", - "node-fetch-npm": "^2.0.2", - "promise-retry": "^1.1.1", - "socks-proxy-agent": "^3.0.1", - "ssri": "^5.2.4" - } - }, - "pump": { - "version": "2.0.1", - "bundled": true, - "dev": true, - "requires": { - "end-of-stream": "^1.1.0", - "once": "^1.3.1" - } - }, - "smart-buffer": { - "version": "1.1.15", - "bundled": true, - "dev": true - }, - "socks": { - "version": "1.1.10", - "bundled": true, - "dev": true, - "requires": { - "ip": "^1.1.4", - "smart-buffer": "^1.0.13" - } - }, - "socks-proxy-agent": { - "version": "3.0.1", - "bundled": true, - "dev": true, - "requires": { - "agent-base": "^4.1.0", - "socks": "^1.1.10" - } - }, - "ssri": { - "version": "5.3.0", - "bundled": true, - "dev": true, - "requires": { - "safe-buffer": "^5.1.1" - } - } + "figgy-pudding": "^3.4.1", + "lru-cache": "^4.1.3", + "make-fetch-happen": "^4.0.1", + "npm-package-arg": "^6.1.0" } }, "npm-run-path": { @@ -8755,35 +8970,61 @@ } }, "pacote": { - "version": "8.1.6", + "version": "9.5.0", "bundled": true, "dev": true, "requires": { - "bluebird": "^3.5.1", - "cacache": "^11.0.2", - "get-stream": "^3.0.0", - "glob": "^7.1.2", - "lru-cache": "^4.1.3", + "bluebird": "^3.5.3", + "cacache": "^11.3.2", + "figgy-pudding": "^3.5.1", + "get-stream": "^4.1.0", + "glob": "^7.1.3", + "lru-cache": "^5.1.1", "make-fetch-happen": "^4.0.1", "minimatch": "^3.0.4", - "minipass": "^2.3.3", + "minipass": "^2.3.5", "mississippi": "^3.0.0", "mkdirp": "^0.5.1", "normalize-package-data": "^2.4.0", "npm-package-arg": "^6.1.0", - "npm-packlist": "^1.1.10", - "npm-pick-manifest": "^2.1.0", + "npm-packlist": "^1.1.12", + "npm-pick-manifest": "^2.2.3", + "npm-registry-fetch": "^3.8.0", "osenv": "^0.1.5", "promise-inflight": "^1.0.1", "promise-retry": "^1.1.1", - "protoduck": "^5.0.0", + "protoduck": "^5.0.1", "rimraf": "^2.6.2", "safe-buffer": "^5.1.2", - "semver": "^5.5.0", - "ssri": "^6.0.0", - "tar": "^4.4.3", - "unique-filename": "^1.1.0", - "which": "^1.3.0" + "semver": "^5.6.0", + "ssri": "^6.0.1", + "tar": "^4.4.8", + "unique-filename": "^1.1.1", + "which": "^1.3.1" + }, + "dependencies": { + "lru-cache": { + "version": "5.1.1", + "bundled": true, + "dev": true, + "requires": { + "yallist": "^3.0.2" + } + }, + "minipass": { + "version": "2.3.5", + "bundled": true, + "dev": true, + "requires": { + "safe-buffer": "^5.1.2", + "yallist": "^3.0.0" + } + }, + "yallist": { + "version": "3.0.3", + "bundled": true, + "dev": true + } } }, "parallel-transform": { @@ -8794,6 +9035,30 @@ "cyclist": "~0.2.2", "inherits": "^2.0.3", "readable-stream": "^2.1.5" + }, + "dependencies": { + "readable-stream": { + "version": "2.3.6", + "bundled": true, + "dev": true, + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + } + }, + "string_decoder": { + "version": "1.1.1", + "bundled": true, + "dev": true, + "requires": { + "safe-buffer": "~5.1.0" + } + } } }, "path-exists": { @@ -8816,6 +9081,11 @@ "bundled": true, "dev": true }, + "path-parse": { + "version": "1.0.6", + "bundled": true, + "dev": true + }, "performance-now": { "version": "2.1.0", "bundled": true, @@ -8871,11 +9141,11 @@ "dev": true }, "protoduck": { - "version": "5.0.0", + "version": "5.0.1", "bundled": true, "dev": true, "requires": { - "genfun": "^4.0.1" + "genfun": "^5.0.0" } }, "prr": { @@ -8939,7 +9209,7 @@ "dev": true }, "query-string": { - "version": "6.1.0", + "version": "6.2.0", "bundled": true, "dev": true, "requires": { @@ -9013,7 +9283,7 @@ } }, "read-package-tree": { - "version": "5.2.1", + "version": "5.2.2", "bundled": true, "dev": true, "requires": { @@ -9025,17 +9295,13 @@ } }, "readable-stream": { - "version": "2.3.6", + "version": "3.1.1", "bundled": true, "dev": true, "requires": { - "core-util-is": "~1.0.0", - "inherits": "~2.0.3", - "isarray": "~1.0.0", - "process-nextick-args": "~2.0.0", - "safe-buffer": "~5.1.1", - "string_decoder": "~1.1.1", - "util-deprecate": "~1.0.1" + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" } }, "readdir-scoped-modules": { @@ -9114,11 +9380,11 @@ "dev": true }, "rimraf": { - "version": "2.6.2", + "version": "2.6.3", "bundled": true, "dev": true, "requires": { - "glob": "^7.0.5" + "glob": "^7.1.3" } }, "run-queue": { @@ -9127,6 +9393,13 @@ "dev": true, "requires": { "aproba": "^1.1.1" + }, + "dependencies": { + "aproba": { + "version": "1.2.0", + "bundled": true, + "dev": true + } } }, "safe-buffer": { @@ -9140,7 +9413,7 @@ "dev": true }, "semver": { - "version": "5.5.1", + "version": "5.6.0", "bundled": true, "dev": true }, @@ -9164,6 +9437,30 @@ "requires": { "graceful-fs": "^4.1.2", "readable-stream": "^2.0.2" + }, + "dependencies": { + "readable-stream": { + "version": "2.3.6", + "bundled": true, + "dev": true, + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + } + }, + "string_decoder": { + "version": "1.1.1", + "bundled": true, + "dev": true, + "requires": { + "safe-buffer": "~5.1.0" + } + } } }, "shebang-command": { @@ -9287,7 +9584,7 @@ } }, "spdx-license-ids": { - "version": "3.0.0", + "version": "3.0.3", "bundled": true, "dev": true }, @@ -9331,6 +9628,30 @@ "requires": { "readable-stream": "^2.1.5", "stream-shift": "^1.0.0" + }, + "dependencies": { + "readable-stream": { + "version": "2.3.6", + "bundled": true, + "dev": true, + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + } + }, + "string_decoder": { + "version": "1.1.1", + "bundled": true, + "dev": true, + "requires": { + "safe-buffer": "~5.1.0" + } + } } }, "stream-shift": { @@ -9373,7 +9694,7 @@ } }, "string_decoder": { - "version": "1.1.1", + "version": "1.2.0", "bundled": true, "dev": true, "requires": { @@ -9471,6 +9792,30 @@ "requires": { "readable-stream": "^2.1.5", "xtend": "~4.0.1" + }, + "dependencies": { + "readable-stream": { + "version": "2.3.6", + "bundled": true, + "dev": true, + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + } + }, + "string_decoder": { + "version": "1.1.1", + "bundled": true, + "dev": true, + "requires": { + "safe-buffer": "~5.1.0" + } + } } }, "timed-out": { @@ -9522,7 +9867,7 @@ "dev": true }, "unique-filename": { - "version": "1.1.0", + "version": "1.1.1", "bundled": true, "dev": true, "requires": { @@ -9706,7 +10051,7 @@ "dev": true }, "write-file-atomic": { - "version": "2.3.0", + "version": "2.4.2", "bundled": true, "dev": true, "requires": { @@ -9838,7 +10183,7 @@ }, "find-up": { "version": "3.0.0", - "resolved": "https://registry.npmjs.org/find-up/-/find-up-3.0.0.tgz", + "resolved": false, "integrity": "sha512-1yD6RmLI1XBfxugvORwlck6f75tYL+iR0jqwsOrOxMZyGYqUuDhJ0l4AXdO1iX/FTs9cBAMEk1gWSEx1kSbylg==", "dev": true, "requires": { @@ -9847,7 +10192,7 @@ }, "locate-path": { "version": "3.0.0", - "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-3.0.0.tgz", + "resolved": false, "integrity": "sha512-7AO748wWnIhNqAuaty2ZWHkQHRSNfPVIsPIfwEOWO22AmaoVrWavlOcMR5nzTLNYvp36X220/maaRsrec1G65A==", "dev": true, "requires": { @@ -9876,7 +10221,7 @@ }, "p-locate": { "version": "3.0.0", - "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-3.0.0.tgz", + "resolved": false, "integrity": "sha512-x+12w/To+4GFfgJhBEpiDcLozRJGegY+Ei7/z0tSLkMmxGZNybVMSfWj9aJn8Z5Fc7dBUNJOOVgPv2H7IwulSQ==", "dev": true, "requires": { @@ -10492,6 +10837,12 @@ "integrity": "sha1-1PRWKwzjaW5BrFLQ4ALlemNdxtw=", "dev": true }, + "prettier": { + "version": "1.17.0", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.17.0.tgz", + "integrity": "sha512-sXe5lSt2WQlCbydGETgfm1YBShgOX4HxQkFPvbxkcwgDvGDeqVau8h+12+lmSVlP3rHPz0oavfddSZg/q+Szjw==", + "dev": true + }, "process": { "version": "0.11.10", "resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz", @@ -12411,6 +12762,12 @@ "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==", "dev": true }, + "type-fest": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.4.1.tgz", + "integrity": "sha512-IwzA/LSfD2vC1/YDYMv/zHP4rDF1usCwllsDpbolT3D4fUepIO7f9K70jjmUewU/LmGUKJcwcVtDCpnKk4BPMw==", + "dev": true + }, "type-is": { "version": "1.6.16", "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.16.tgz", diff --git a/package.json b/package.json index ecd0c61d..76ea6fd0 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "codecov": "^3.2.0", "express": "^4.16.4", "execa": "^1.0.0", - "gts": "^0.9.0", + "gts": "^1.0.0", "is-docker": "^2.0.0", "karma": "^4.0.0", "karma-chrome-launcher": "^2.2.0", diff --git a/prettier.config.js b/prettier.config.js new file mode 100644 index 00000000..a425d3f7 --- /dev/null +++ b/prettier.config.js @@ -0,0 +1,4 @@ +module.exports = { + singleQuote: true, + trailingComma: 'es5', +}; diff --git a/src/common.ts b/src/common.ts index 1412dc8a..4d588fa1 100644 --- a/src/common.ts +++ b/src/common.ts @@ -11,15 +11,20 @@ // See the License for the specific language governing permissions and // limitations under the License. -import {AbortSignal} from 'abort-controller'; -import {Agent} from 'https'; +import { AbortSignal } from 'abort-controller'; +import { Agent } from 'https'; + +// tslint:disable no-any export class GaxiosError extends Error { code?: string; response?: GaxiosResponse; config: GaxiosOptions; constructor( - message: string, options: GaxiosOptions, response: GaxiosResponse) { + message: string, + options: GaxiosOptions, + response: GaxiosResponse + ) { super(message); this.response = response; this.config = options; @@ -27,9 +32,9 @@ export class GaxiosError extends Error { } } -export type Headers = { - [index: string]: any -}; +export interface Headers { + [index: string]: any; +} export type GaxiosPromise = Promise>; export interface GaxiosResponse { @@ -50,10 +55,18 @@ export interface GaxiosOptions { */ adapter?: (options: GaxiosOptions) => GaxiosPromise; url?: string; - baseUrl?: string; // deprecated + baseUrl?: string; // deprecated baseURL?: string; - method?: 'GET'|'HEAD'|'POST'|'DELETE'|'PUT'|'CONNECT'|'OPTIONS'|'TRACE'| - 'PATCH'; + method?: + | 'GET' + | 'HEAD' + | 'POST' + | 'DELETE' + | 'PUT' + | 'CONNECT' + | 'OPTIONS' + | 'TRACE' + | 'PATCH'; headers?: Headers; data?: any; body?: any; @@ -67,10 +80,10 @@ export interface GaxiosOptions { maxRedirects?: number; follow?: number; params?: any; - paramsSerializer?: (params: {[index: string]: string|number}) => string; + paramsSerializer?: (params: { [index: string]: string | number }) => string; timeout?: number; onUploadProgress?: (progressEvent: any) => void; - responseType?: 'arraybuffer'|'blob'|'json'|'text'|'stream'; + responseType?: 'arraybuffer' | 'blob' | 'json' | 'text' | 'stream'; agent?: Agent; validateStatus?: (status: number) => boolean; retryConfig?: RetryConfig; diff --git a/src/gaxios.ts b/src/gaxios.ts index e167c2fa..7b8c6653 100644 --- a/src/gaxios.ts +++ b/src/gaxios.ts @@ -12,27 +12,38 @@ // limitations under the License. import extend from 'extend'; -import {Agent} from 'https'; -import nodeFetch, {Response as NodeFetchResponse} from 'node-fetch'; +import { Agent } from 'https'; +import nodeFetch, { Response as NodeFetchResponse } from 'node-fetch'; import qs from 'querystring'; import stream from 'stream'; import url from 'url'; -import {GaxiosError, GaxiosOptions, GaxiosPromise, GaxiosResponse, Headers} from './common'; -import {isBrowser} from './isbrowser'; -import {getRetryConfig} from './retry'; +import { + GaxiosError, + GaxiosOptions, + GaxiosPromise, + GaxiosResponse, + Headers, +} from './common'; +import { isBrowser } from './isbrowser'; +import { getRetryConfig } from './retry'; + +// tslint:disable no-any const URL = isBrowser() ? window.URL : url.URL; const fetch = isBrowser() ? window.fetch : nodeFetch; -// tslint:disable-next-line variable-name no-any +// tslint:disable-next-line variable-name let HttpsProxyAgent: any; // Figure out if we should be using a proxy. Only if it's required, load // the https-proxy-agent module as it adds startup cost. function loadProxy() { - const proxy = process.env.HTTPS_PROXY || process.env.https_proxy || - process.env.HTTP_PROXY || process.env.http_proxy; + const proxy = + process.env.HTTPS_PROXY || + process.env.https_proxy || + process.env.HTTP_PROXY || + process.env.http_proxy; if (proxy) { HttpsProxyAgent = require('https-proxy-agent'); } @@ -73,17 +84,18 @@ export class Gaxios { } if (!opts.validateStatus!(translatedResponse.status)) { throw new GaxiosError( - `Request failed with status code ${translatedResponse.status}`, - opts, translatedResponse); + `Request failed with status code ${translatedResponse.status}`, + opts, + translatedResponse + ); } return translatedResponse; } catch (e) { const err = e as GaxiosError; err.config = opts; - const {shouldRetry, config} = await getRetryConfig(e); + const { shouldRetry, config } = await getRetryConfig(e); if (shouldRetry && config) { - err.config.retryConfig!.currentRetryAttempt = - config.retryConfig!.currentRetryAttempt; + err.config.retryConfig!.currentRetryAttempt = config.retryConfig!.currentRetryAttempt; return this.request(err.config); } throw err; @@ -91,7 +103,9 @@ export class Gaxios { } private async getResponseData( - opts: GaxiosOptions, res: Response|NodeFetchResponse): Promise { + opts: GaxiosOptions, + res: Response | NodeFetchResponse + ): Promise { switch (opts.responseType) { case 'stream': return res.body; @@ -99,8 +113,7 @@ export class Gaxios { let data = await res.text(); try { data = JSON.parse(data); - } catch (e) { - } + } catch (e) {} return data as {}; case 'arraybuffer': return res.arrayBuffer(); @@ -130,8 +143,9 @@ export class Gaxios { const parsedUrl = new URL(opts.url); opts.url = `${parsedUrl.origin}${parsedUrl.pathname}`; opts.params = extend( - qs.parse(parsedUrl.search.substr(1)), // removes leading ? - opts.params); + qs.parse(parsedUrl.search.substr(1)), // removes leading ? + opts.params + ); opts.paramsSerializer = opts.paramsSerializer || this.paramsSerializer; if (opts.params) { @@ -192,7 +206,7 @@ export class Gaxios { * Encode a set of key/value pars into a querystring format (?foo=bar&baz=boo) * @param params key value pars to encode */ - private paramsSerializer(params: {[index: string]: string|number}) { + private paramsSerializer(params: { [index: string]: string | number }) { return qs.stringify(params); } @@ -201,8 +215,10 @@ export class Gaxios { } private translateResponse( - opts: GaxiosOptions, res: Response|NodeFetchResponse, - data?: T): GaxiosResponse { + opts: GaxiosOptions, + res: Response | NodeFetchResponse, + data?: T + ): GaxiosResponse { // headers need to be converted from a map to an obj const headers = {} as Headers; res.headers.forEach((value, key) => { @@ -214,7 +230,7 @@ export class Gaxios { data: data as T, headers, status: res.status, - statusText: res.statusText + statusText: res.statusText, }; } } diff --git a/src/index.ts b/src/index.ts index f4265a28..f2d9fea3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -11,11 +11,17 @@ // See the License for the specific language governing permissions and // limitations under the License. -import {GaxiosOptions} from './common'; -import {Gaxios} from './gaxios'; +import { GaxiosOptions } from './common'; +import { Gaxios } from './gaxios'; -export {GaxiosError, GaxiosPromise, GaxiosResponse, Headers, RetryConfig} from './common'; -export {Gaxios, GaxiosOptions}; +export { + GaxiosError, + GaxiosPromise, + GaxiosResponse, + Headers, + RetryConfig, +} from './common'; +export { Gaxios, GaxiosOptions }; /** * The default instance used when the `request` method is directly diff --git a/src/isbrowser.ts b/src/isbrowser.ts index 5ded266e..44812f45 100644 --- a/src/isbrowser.ts +++ b/src/isbrowser.ts @@ -15,5 +15,5 @@ */ export function isBrowser(): boolean { - return typeof (window) !== 'undefined'; + return typeof window !== 'undefined'; } diff --git a/src/retry.ts b/src/retry.ts index 344c0845..08add0d0 100644 --- a/src/retry.ts +++ b/src/retry.ts @@ -11,24 +11,29 @@ // See the License for the specific language governing permissions and // limitations under the License. -import {GaxiosError} from './common'; +import { GaxiosError } from './common'; export async function getRetryConfig(err: GaxiosError) { let config = getConfig(err); - if ((!err || !err.config) || (!config && !err.config.retry)) { - return {shouldRetry: false}; + if (!err || !err.config || (!config && !err.config.retry)) { + return { shouldRetry: false }; } config = config || {}; config.currentRetryAttempt = config.currentRetryAttempt || 0; config.retry = - (config.retry === undefined || config.retry === null) ? 3 : config.retry; + config.retry === undefined || config.retry === null ? 3 : config.retry; config.retryDelay = config.retryDelay || 100; - config.httpMethodsToRetry = - config.httpMethodsToRetry || ['GET', 'HEAD', 'PUT', 'OPTIONS', 'DELETE']; - config.noResponseRetries = (config.noResponseRetries === undefined || - config.noResponseRetries === null) ? - 2 : - config.noResponseRetries; + config.httpMethodsToRetry = config.httpMethodsToRetry || [ + 'GET', + 'HEAD', + 'PUT', + 'OPTIONS', + 'DELETE', + ]; + config.noResponseRetries = + config.noResponseRetries === undefined || config.noResponseRetries === null + ? 2 + : config.noResponseRetries; // If this wasn't in the list of status codes where we want // to automatically retry, return. @@ -40,7 +45,9 @@ export async function getRetryConfig(err: GaxiosError) { // 4xx - Do not retry (Client errors) // 429 - Retry ("Too Many Requests") // 5xx - Retry (Server errors) - [100, 199], [429, 429], [500, 599] + [100, 199], + [429, 429], + [500, 599], ]; config.statusCodesToRetry = config.statusCodesToRetry || retryRanges; @@ -50,12 +57,12 @@ export async function getRetryConfig(err: GaxiosError) { // Determine if we should retry the request const shouldRetryFn = config.shouldRetry || shouldRetryRequest; if (!shouldRetryFn(err)) { - return {shouldRetry: false, config: err.config}; + return { shouldRetry: false, config: err.config }; } // Calculate time to wait with exponential backoff. // Formula: (2^c - 1 / 2) * 1000 - const delay = (Math.pow(2, config.currentRetryAttempt) - 1) / 2 * 1000; + const delay = ((Math.pow(2, config.currentRetryAttempt) - 1) / 2) * 1000; // We're going to retry! Incremenent the counter. err.config.retryConfig!.currentRetryAttempt! += 1; @@ -72,7 +79,7 @@ export async function getRetryConfig(err: GaxiosError) { // Return the promise in which recalls Gaxios to retry the request await backoff; - return {shouldRetry: true, config: err.config}; + return { shouldRetry: true, config: err.config }; } /** @@ -88,14 +95,18 @@ function shouldRetryRequest(err: GaxiosError) { } // Check if this error has no response (ETIMEDOUT, ENOTFOUND, etc) - if (!err.response && - ((config.currentRetryAttempt || 0) >= config.noResponseRetries!)) { + if ( + !err.response && + (config.currentRetryAttempt || 0) >= config.noResponseRetries! + ) { return false; } // Only retry with configured HttpMethods. - if (!err.config.method || - config.httpMethodsToRetry!.indexOf(err.config.method.toUpperCase()) < 0) { + if ( + !err.config.method || + config.httpMethodsToRetry!.indexOf(err.config.method.toUpperCase()) < 0 + ) { return false; } diff --git a/system-test/fixtures/sample/package.json b/system-test/fixtures/sample/package.json index e5b74322..7c544329 100644 --- a/system-test/fixtures/sample/package.json +++ b/system-test/fixtures/sample/package.json @@ -18,7 +18,7 @@ "devDependencies": { "@types/node": "^10.3.0", "typescript": "^3.0.0", - "gts": "^0.9.0", + "gts": "^1.0.0", "null-loader": "^0.1.1", "ts-loader": "^5.3.3", "webpack": "^4.29.3", diff --git a/system-test/test.install.ts b/system-test/test.install.ts index 4cab74a9..3d729a80 100644 --- a/system-test/test.install.ts +++ b/system-test/test.install.ts @@ -18,15 +18,15 @@ import assert from 'assert'; import execa from 'execa'; import fs from 'fs'; import mv from 'mv'; -import {ncp} from 'ncp'; +import { ncp } from 'ncp'; import path from 'path'; import tmp from 'tmp'; -import {promisify} from 'util'; +import { promisify } from 'util'; const keep = false; -const mvp = promisify(mv) as {} as (...args: string[]) => Promise; +const mvp = (promisify(mv) as {}) as (...args: string[]) => Promise; const ncpp = promisify(ncp); -const stagingDir = tmp.dirSync({keep, unsafeCleanup: true}); +const stagingDir = tmp.dirSync({ keep, unsafeCleanup: true }); const stagingPath = stagingDir.name; const pkg = require('../../package.json'); @@ -40,20 +40,25 @@ describe('📦 pack and install', () => { const tarball = `${pkg.name}-${pkg.version}.tgz`; await mvp(tarball, `${stagingPath}/gaxios.tgz`); await ncpp('system-test/fixtures/sample', `${stagingPath}/`); - await execa( - 'npm', ['install', '--unsafe-perm'], - {cwd: `${stagingPath}/`, stdio: 'inherit'}); + await execa('npm', ['install', '--unsafe-perm'], { + cwd: `${stagingPath}/`, + stdio: 'inherit', + }); }); it('should run the sample', async () => { - await execa( - 'node', ['--throw-deprecation', 'build/src/index.js'], - {cwd: `${stagingPath}/`, stdio: 'inherit'}); + await execa('node', ['--throw-deprecation', 'build/src/index.js'], { + cwd: `${stagingPath}/`, + stdio: 'inherit', + }); }); it('should be able to webpack the library', async () => { // we expect npm install is executed in the before hook - await execa('npx', ['webpack'], {cwd: `${stagingPath}/`, stdio: 'inherit'}); + await execa('npx', ['webpack'], { + cwd: `${stagingPath}/`, + stdio: 'inherit', + }); const bundle = path.join(stagingPath, 'dist', 'bundle.min.js'); const stat = fs.statSync(bundle); assert(stat.size < 256 * 1024); diff --git a/test/test.getch.ts b/test/test.getch.ts index cafb7b02..030076fa 100644 --- a/test/test.getch.ts +++ b/test/test.getch.ts @@ -18,10 +18,16 @@ import stream from 'stream'; const assertRejects = require('assert-rejects'); // tslint:disable-next-line variable-name const HttpsProxyAgent = require('https-proxy-agent'); -import {Gaxios, GaxiosError, request, GaxiosOptions, GaxiosResponse} from '../src'; +import { + Gaxios, + GaxiosError, + request, + GaxiosOptions, + GaxiosResponse, +} from '../src'; import qs from 'querystring'; import fs from 'fs'; -import {Blob} from 'node-fetch'; +import { Blob } from 'node-fetch'; nock.disableNetConnect(); @@ -41,8 +47,10 @@ describe('🦖 option validation', () => { describe('🚙 error handling', () => { it('should throw on non-2xx responses by default', async () => { - const scope = nock(url).get('/').reply(500); - await assertRejects(request({url}), (err: GaxiosError) => { + const scope = nock(url) + .get('/') + .reply(500); + await assertRejects(request({ url }), (err: GaxiosError) => { scope.done(); return err.code === '500'; }); @@ -51,82 +59,100 @@ describe('🚙 error handling', () => { describe('🥁 configuration options', () => { it('should use options passed into the constructor', async () => { - const scope = nock(url).head('/').reply(200); - const inst = new Gaxios({method: 'HEAD'}); - const res = await inst.request({url}); + const scope = nock(url) + .head('/') + .reply(200); + const inst = new Gaxios({ method: 'HEAD' }); + const res = await inst.request({ url }); scope.done(); assert.strictEqual(res.config.method, 'HEAD'); }); it('should handle nested options passed into the constructor', async () => { - const scope = nock(url).get('/').reply(200); - const inst = new Gaxios({headers: {apple: 'juice'}}); - const res = await inst.request({url, headers: {figgy: 'pudding'}}); + const scope = nock(url) + .get('/') + .reply(200); + const inst = new Gaxios({ headers: { apple: 'juice' } }); + const res = await inst.request({ url, headers: { figgy: 'pudding' } }); scope.done(); assert.strictEqual(res.config.headers!.apple, 'juice'); assert.strictEqual(res.config.headers!.figgy, 'pudding'); }); it('should allow setting a base url in the options', async () => { - const scope = nock(url).get('/v1/mango').reply(200, {}); - const inst = new Gaxios({baseURL: `${url}/v1`}); - const res = await inst.request({url: '/mango'}); + const scope = nock(url) + .get('/v1/mango') + .reply(200, {}); + const inst = new Gaxios({ baseURL: `${url}/v1` }); + const res = await inst.request({ url: '/mango' }); scope.done(); assert.deepStrictEqual(res.data, {}); }); it('should allow overriding valid status', async () => { - const scope = nock(url).get('/').reply(304); - const res = await request({url, validateStatus: () => true}); + const scope = nock(url) + .get('/') + .reply(304); + const res = await request({ url, validateStatus: () => true }); scope.done(); assert.strictEqual(res.status, 304); }); it('should allow setting maxContentLength', async () => { - const body = {hello: '🌎'}; - const scope = nock(url).get('/').reply(200, body); + const body = { hello: '🌎' }; + const scope = nock(url) + .get('/') + .reply(200, body); const maxContentLength = 1; - await assertRejects(request({url, maxContentLength}), /over limit/); + await assertRejects(request({ url, maxContentLength }), /over limit/); scope.done(); }); it('should support redirects by default', async () => { - const body = {hello: '🌎'}; + const body = { hello: '🌎' }; const scopes = [ - nock(url).get('/foo').reply(200, body), - nock(url).get('/').reply(302, null, {location: '/foo'}) + nock(url) + .get('/foo') + .reply(200, body), + nock(url) + .get('/') + .reply(302, null, { location: '/foo' }), ]; - const res = await request({url}); + const res = await request({ url }); scopes.forEach(x => x.done()); assert.deepStrictEqual(res.data, body); }); it('should support disabling redirects', async () => { - const scope = nock(url).get('/').reply(302, null, {location: '/foo'}); + const scope = nock(url) + .get('/') + .reply(302, null, { location: '/foo' }); const maxRedirects = 0; - await assertRejects(request({url, maxRedirects}), /maximum redirect/); + await assertRejects(request({ url, maxRedirects }), /maximum redirect/); scope.done(); }); it('should allow overriding the adapter', async () => { const response: GaxiosResponse = { - data: {hello: '🌎'}, + data: { hello: '🌎' }, config: {}, status: 200, statusText: 'OK', - headers: {} + headers: {}, }; const adapter = (options: GaxiosOptions) => { return Promise.resolve(response); }; - const res = await request({url, adapter}); + const res = await request({ url, adapter }); assert.strictEqual(response, res); }); it('should encode URL parameters', async () => { const path = '/?james=kirk&montgomery=scott'; - const opts = {url: `${url}${path}`}; - const scope = nock(url).get(path).reply(200, {}); + const opts = { url: `${url}${path}` }; + const scope = nock(url) + .get(path) + .reply(200, {}); const res = await request(opts); assert.strictEqual(res.status, 200); assert.strictEqual(res.config.url, url + path); @@ -134,9 +160,11 @@ describe('🥁 configuration options', () => { }); it('should encode parameters from the params option', async () => { - const opts = {url, params: {james: 'kirk', montgomery: 'scott'}}; + const opts = { url, params: { james: 'kirk', montgomery: 'scott' } }; const path = '/?james=kirk&montgomery=scott'; - const scope = nock(url).get(path).reply(200, {}); + const scope = nock(url) + .get(path) + .reply(200, {}); const res = await request(opts); assert.strictEqual(res.status, 200); assert.strictEqual(res.config.url, url + path); @@ -146,10 +174,12 @@ describe('🥁 configuration options', () => { it('should merge URL parameters with the params option', async () => { const opts = { url: `${url}/?james=beckwith&montgomery=scott`, - params: {james: 'kirk'} + params: { james: 'kirk' }, }; const path = '/?james=kirk&montgomery=scott'; - const scope = nock(url).get(path).reply(200, {}); + const scope = nock(url) + .get(path) + .reply(200, {}); const res = await request(opts); assert.strictEqual(res.status, 200); assert.strictEqual(res.config.url, url + path); @@ -158,16 +188,18 @@ describe('🥁 configuration options', () => { it('should allow overriding the param serializer', async () => { const qs = '?oh=HAI'; - const params = {james: 'kirk'}; + const params = { james: 'kirk' }; const opts: GaxiosOptions = { url, params, - paramsSerializer: (ps) => { - assert.deepEqual(params, ps); + paramsSerializer: ps => { + assert.strictEqual(JSON.stringify(params), JSON.stringify(ps)); return '?oh=HAI'; - } + }, }; - const scope = nock(url).get(`/${qs}`).reply(200, {}); + const scope = nock(url) + .get(`/${qs}`) + .reply(200, {}); const res = await request(opts); assert.strictEqual(res.status, 200); assert.strictEqual(res.config.url, `${url}/${qs}`); @@ -175,48 +207,57 @@ describe('🥁 configuration options', () => { }); it('should return json by default', async () => { - const body = {hello: '🌎'}; - const scope = nock(url).get('/').reply(200, body); - const res = await request({url}); + const body = { hello: '🌎' }; + const scope = nock(url) + .get('/') + .reply(200, body); + const res = await request({ url }); scope.done(); assert.deepStrictEqual(body, res.data); }); it('should send an application/json header by default', async () => { const scope = nock(url) - .matchHeader('accept', 'application/json') - .get('/') - .reply(200, {}); - const res = await request({url}); + .matchHeader('accept', 'application/json') + .get('/') + .reply(200, {}); + const res = await request({ url }); scope.done(); assert.deepStrictEqual(res.data, {}); }); it('should use an https proxy if asked nicely', async () => { - sandbox.stub(process, 'env').value({https_proxy: 'https://fake.proxy'}); - const body = {hello: '🌎'}; - const scope = nock(url).get('/').reply(200, body); - const res = await request({url}); + sandbox.stub(process, 'env').value({ https_proxy: 'https://fake.proxy' }); + const body = { hello: '🌎' }; + const scope = nock(url) + .get('/') + .reply(200, body); + const res = await request({ url }); scope.done(); assert.deepStrictEqual(res.data, body); assert.ok(res.config.agent instanceof HttpsProxyAgent); }); it('should load the proxy from the cache', async () => { - sandbox.stub(process, 'env').value({HTTPS_PROXY: 'https://fake.proxy'}); - const body = {hello: '🌎'}; - const scope = nock(url).get('/').twice().reply(200, body); - const res1 = await request({url}); + sandbox.stub(process, 'env').value({ HTTPS_PROXY: 'https://fake.proxy' }); + const body = { hello: '🌎' }; + const scope = nock(url) + .get('/') + .twice() + .reply(200, body); + const res1 = await request({ url }); const agent = res1.config.agent; - const res2 = await request({url}); + const res2 = await request({ url }); assert.strictEqual(agent, res2.config.agent); scope.done(); }); it('should include the request data in the response config', async () => { - const body = {hello: '🌎'}; - const scope = nock(url).post('/', body).reply(200); - const res = await request({url, method: 'POST', data: body}); + const body = { hello: '🌎' }; + const scope = nock(url) + .post('/', body) + .reply(200); + const res = await request({ url, method: 'POST', data: body }); scope.done(); assert.deepStrictEqual(res.config.data, body); }); @@ -226,68 +267,84 @@ describe('🎏 data handling', () => { it('should accpet a ReadableStream as request data', async () => { const body = fs.createReadStream('package.json'); const contents = require('../../package.json'); - const scope = nock(url).post('/', contents).reply(200, {}); - const res = await request({url, method: 'POST', data: body}); + const scope = nock(url) + .post('/', contents) + .reply(200, {}); + const res = await request({ url, method: 'POST', data: body }); scope.done(); assert.deepStrictEqual(res.data, {}); }); it('should accept a string in the request data', async () => { - const body = {hello: '🌎'}; + const body = { hello: '🌎' }; const encoded = qs.stringify(body); - const scope = - nock(url) - .matchHeader('content-type', 'application/x-www-form-urlencoded') - .post('/', encoded) - .reply(200, {}); + const scope = nock(url) + .matchHeader('content-type', 'application/x-www-form-urlencoded') + .post('/', encoded) + .reply(200, {}); const res = await request({ url, method: 'POST', data: encoded, - headers: {'content-type': 'application/x-www-form-urlencoded'} + headers: { 'content-type': 'application/x-www-form-urlencoded' }, }); scope.done(); assert.deepStrictEqual(res.data, {}); }); it('should return stream if asked nicely', async () => { - const body = {hello: '🌎'}; - const scope = nock(url).get('/').reply(200, body); - const res = await request({url, responseType: 'stream'}); + const body = { hello: '🌎' }; + const scope = nock(url) + .get('/') + .reply(200, body); + const res = await request({ url, responseType: 'stream' }); scope.done(); assert(res.data instanceof stream.Readable); }); it('should return an ArrayBuffer if asked nicely', async () => { - const body = {hello: '🌎'}; - const scope = nock(url).get('/').reply(200, body); - const res = await request({url, responseType: 'arraybuffer'}); + const body = { hello: '🌎' }; + const scope = nock(url) + .get('/') + .reply(200, body); + const res = await request({ + url, + responseType: 'arraybuffer', + }); scope.done(); assert(res.data instanceof ArrayBuffer); assert.deepStrictEqual( - Buffer.from(JSON.stringify(body)), Buffer.from(res.data)); + Buffer.from(JSON.stringify(body)), + Buffer.from(res.data) + ); }); it('should return a blob if asked nicely', async () => { - const body = {hello: '🌎'}; - const scope = nock(url).get('/').reply(200, body); - const res = await request({url, responseType: 'blob'}); + const body = { hello: '🌎' }; + const scope = nock(url) + .get('/') + .reply(200, body); + const res = await request({ url, responseType: 'blob' }); scope.done(); assert.ok(res.data); }); it('should return text if asked nicely', async () => { const body = 'hello 🌎'; - const scope = nock(url).get('/').reply(200, body); - const res = await request({url, responseType: 'text'}); + const scope = nock(url) + .get('/') + .reply(200, body); + const res = await request({ url, responseType: 'text' }); scope.done(); assert.strictEqual(res.data, body); }); it('should return status text', async () => { - const body = {hello: '🌎'}; - const scope = nock(url).get('/').reply(200, body); - const res = await request({url}); + const body = { hello: '🌎' }; + const scope = nock(url) + .get('/') + .reply(200, body); + const res = await request({ url }); scope.done(); assert.ok(res.data); assert.strictEqual(res.statusText, 'OK'); @@ -297,13 +354,15 @@ describe('🎏 data handling', () => { describe('🍂 defaults & instances', () => { it('should allow creating a new instance', () => { const requestInstance = new Gaxios(); - assert.equal(typeof requestInstance.request, 'function'); + assert.strictEqual(typeof requestInstance.request, 'function'); }); it('should allow passing empty options', async () => { - const body = {hello: '🌎'}; - const scope = nock(url).get('/').reply(200, body); - const gax = new Gaxios({url}); + const body = { hello: '🌎' }; + const scope = nock(url) + .get('/') + .reply(200, body); + const gax = new Gaxios({ url }); const res = await gax.request(); scope.done(); assert.deepStrictEqual(res.data, body); diff --git a/test/test.retry.ts b/test/test.retry.ts index 94daf0d3..b801b416 100644 --- a/test/test.retry.ts +++ b/test/test.retry.ts @@ -14,7 +14,7 @@ import assert from 'assert'; import nock from 'nock'; -import {GaxiosError, GaxiosOptions, request} from '../src'; +import { GaxiosError, GaxiosOptions, request } from '../src'; const assertRejects = require('assert-rejects'); @@ -36,17 +36,20 @@ afterEach(() => { describe('🛸 retry & exponential backoff', () => { it('should provide an expected set of defaults', async () => { - const scope = nock(url).get('/').times(4).reply(500); - await assertRejects(request({url, retry: true}), (e: Error) => { + const scope = nock(url) + .get('/') + .times(4) + .reply(500); + await assertRejects(request({ url, retry: true }), (e: Error) => { scope.done(); const config = getConfig(e); if (!config) { assert.fail('no config available'); } - assert.equal(config!.currentRetryAttempt, 3); - assert.equal(config!.retry, 3); - assert.equal(config!.noResponseRetries, 2); - assert.equal(config!.retryDelay, 100); + assert.strictEqual(config!.currentRetryAttempt, 3); + assert.strictEqual(config!.retry, 3); + assert.strictEqual(config!.noResponseRetries, 2); + assert.strictEqual(config!.retryDelay, 100); const expectedMethods = ['GET', 'HEAD', 'PUT', 'OPTIONS', 'DELETE']; for (const method of config!.httpMethodsToRetry!) { assert(expectedMethods.indexOf(method) > -1); @@ -56,17 +59,23 @@ describe('🛸 retry & exponential backoff', () => { for (let i = 0; i < statusCodesToRetry.length; i++) { const [min, max] = statusCodesToRetry[i]; const [expMin, expMax] = expectedStatusCodes[i]; - assert.equal(min, expMin); - assert.equal(max, expMax); + assert.strictEqual(min, expMin); + assert.strictEqual(max, expMax); } return true; }); }); it('should retry on 500 on the main export', async () => { - const body = {buttered: '🥖'}; - const scopes = - [nock(url).get('/').reply(500), nock(url).get('/').reply(200, body)]; + const body = { buttered: '🥖' }; + const scopes = [ + nock(url) + .get('/') + .reply(500), + nock(url) + .get('/') + .reply(200, body), + ]; const res = await request({ url, retry: true, @@ -76,30 +85,42 @@ describe('🛸 retry & exponential backoff', () => { }); it('should not retry on a post', async () => { - const scope = nock(url).post('/').reply(500); + const scope = nock(url) + .post('/') + .reply(500); await assertRejects( - request({url, method: 'POST', retry: true}), (e: Error) => { - const config = getConfig(e); - return config!.currentRetryAttempt === 0; - }); + request({ url, method: 'POST', retry: true }), + (e: Error) => { + const config = getConfig(e); + return config!.currentRetryAttempt === 0; + } + ); scope.done(); }); it('should retry at least the configured number of times', async () => { - const body = {dippy: '🥚'}; + const body = { dippy: '🥚' }; const scopes = [ - nock(url).get('/').times(3).reply(500), - nock(url).get('/').reply(200, body) + nock(url) + .get('/') + .times(3) + .reply(500), + nock(url) + .get('/') + .reply(200, body), ]; - const cfg = {url, retryConfig: {retry: 4}}; + const cfg = { url, retryConfig: { retry: 4 } }; const res = await request(cfg); assert.deepStrictEqual(res.data, body); scopes.forEach(s => s.done()); }); it('should not retry more than configured', async () => { - const scope = nock(url).get('/').twice().reply(500); - const cfg = {url, retryConfig: {retry: 1}}; + const scope = nock(url) + .get('/') + .twice() + .reply(500); + const cfg = { url, retryConfig: { retry: 1 } }; await assertRejects(request(cfg), (e: Error) => { return getConfig(e)!.currentRetryAttempt === 1; }); @@ -107,8 +128,10 @@ describe('🛸 retry & exponential backoff', () => { }); it('should not retry on 4xx errors', async () => { - const scope = nock(url).get('/').reply(404); - await assertRejects(request({url, retry: true}), (e: Error) => { + const scope = nock(url) + .get('/') + .reply(404); + await assertRejects(request({ url, retry: true }), (e: Error) => { const cfg = getConfig(e); return cfg!.currentRetryAttempt === 0; }); @@ -116,8 +139,10 @@ describe('🛸 retry & exponential backoff', () => { }); it('should not retry if retries set to 0', async () => { - const scope = nock(url).get('/').reply(500); - const cfg = {url, retryConfig: {retry: 0}}; + const scope = nock(url) + .get('/') + .reply(500); + const cfg = { url, retryConfig: { retry: 0 } }; await assertRejects(request(cfg), (e: Error) => { const cfg = getConfig(e); return cfg!.currentRetryAttempt === 0; @@ -126,34 +151,42 @@ describe('🛸 retry & exponential backoff', () => { }); it('should notify on retry attempts', async () => { - const body = {buttered: '🥖'}; - const scopes = - [nock(url).get('/').reply(500), nock(url).get('/').reply(200, body)]; + const body = { buttered: '🥖' }; + const scopes = [ + nock(url) + .get('/') + .reply(500), + nock(url) + .get('/') + .reply(200, body), + ]; let flipped = false; const config: GaxiosOptions = { url, retryConfig: { - onRetryAttempt: (err) => { + onRetryAttempt: err => { const cfg = getConfig(err); - assert.equal(cfg!.currentRetryAttempt, 1); + assert.strictEqual(cfg!.currentRetryAttempt, 1); flipped = true; - } - } + }, + }, }; await request(config); - assert.equal(flipped, true); + assert.strictEqual(flipped, true); scopes.forEach(s => s.done()); }); it('should support overriding the shouldRetry method', async () => { - const scope = nock(url).get('/').reply(500); + const scope = nock(url) + .get('/') + .reply(500); const config = { url, retryConfig: { shouldRetry: () => { return false; - } - } + }, + }, }; await assertRejects(request(config), (e: Error) => { const cfg = getConfig(e); @@ -163,30 +196,40 @@ describe('🛸 retry & exponential backoff', () => { }); it('should retry on ENOTFOUND', async () => { - const body = {spicy: '🌮'}; + const body = { spicy: '🌮' }; const scopes = [ - nock(url).get('/').replyWithError({code: 'ENOTFOUND'}), - nock(url).get('/').reply(200, body) + nock(url) + .get('/') + .replyWithError({ code: 'ENOTFOUND' }), + nock(url) + .get('/') + .reply(200, body), ]; - const res = await request({url, retry: true}); + const res = await request({ url, retry: true }); assert.deepStrictEqual(res.data, body); scopes.forEach(s => s.done()); }); it('should retry on ETIMEDOUT', async () => { - const body = {sizzling: '🥓'}; + const body = { sizzling: '🥓' }; const scopes = [ - nock(url).get('/').replyWithError({code: 'ETIMEDOUT'}), - nock(url).get('/').reply(200, body) + nock(url) + .get('/') + .replyWithError({ code: 'ETIMEDOUT' }), + nock(url) + .get('/') + .reply(200, body), ]; - const res = await request({url, retry: true}); + const res = await request({ url, retry: true }); assert.deepStrictEqual(res.data, body); scopes.forEach(s => s.done()); }); it('should allow configuring noResponseRetries', async () => { - const scope = nock(url).get('/').replyWithError({code: 'ETIMEDOUT'}); - const config = {url, retryConfig: {noResponseRetries: 0}}; + const scope = nock(url) + .get('/') + .replyWithError({ code: 'ETIMEDOUT' }); + const config = { url, retryConfig: { noResponseRetries: 0 } }; await assertRejects(request(config), (e: Error) => { const cfg = getConfig(e); return cfg!.currentRetryAttempt === 0; diff --git a/tslint.json b/tslint.json index e89730ca..27872a13 100644 --- a/tslint.json +++ b/tslint.json @@ -1,6 +1,8 @@ { "extends": "gts/tslint.json", - "rules": { - "no-any": false + "linterOptions": { + "exclude": [ + "**/*.json" + ] } }