diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 0f4e6ea68e..a422279dda 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -68,7 +68,6 @@ "prettyjson": "^1.2.5", "progress-stream": "^2.0.0", "reconfix": "^1.0.0-v0-1-0-fork-46760acff4d165f5238bfac5e464256ef1944476", - "request": "^2.88.2", "resin-cli-form": "^3.0.0", "resin-cli-visuals": "^2.0.0", "resin-doodles": "^0.2.0", @@ -130,7 +129,6 @@ "@types/parse-link-header": "^2.0.3", "@types/prettyjson": "^0.0.33", "@types/progress-stream": "^2.0.2", - "@types/request": "^2.48.7", "@types/rewire": "^2.5.30", "@types/rimraf": "^3.0.2", "@types/semver": "^7.3.9", @@ -164,7 +162,7 @@ "mkdirp": "^3.0.1", "mocha": "^10.6.0", "mock-require": "^3.0.3", - "nock": "^13.2.1", + "nock": "^14.0.0-beta.12", "oclif": "^4.14.0", "parse-link-header": "^2.0.0", "rewire": "^7.0.0", @@ -2229,6 +2227,23 @@ "resolved": "https://registry.npmjs.org/@leichtgewicht/ip-codec/-/ip-codec-2.0.5.tgz", "integrity": "sha512-Vo+PSpZG2/fmgmiNzYK9qWRh8h/CHrwD0mo1h1DzL4yzHNSfWYujGTYsWGreD000gcgmZ7K4Ys6Tx9TxtsKdDw==" }, + "node_modules/@mswjs/interceptors": { + "version": "0.35.0", + "resolved": "https://registry.npmjs.org/@mswjs/interceptors/-/interceptors-0.35.0.tgz", + "integrity": "sha512-f5cHyIvm4m4g1I5x9EH1etGx0puaU0OaX2szqGRVBVgUC6aMASlOI5hbpe7tJ9l4/VWjCUu5OMraCazLZGI24A==", + "dev": true, + "dependencies": { + "@open-draft/deferred-promise": "^2.2.0", + "@open-draft/logger": "^0.3.0", + "@open-draft/until": "^2.0.0", + "is-node-process": "^1.2.0", + "outvariant": "^1.4.3", + "strict-event-emitter": "^0.5.1" + }, + "engines": { + "node": ">=18" + } + }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", @@ -2546,6 +2561,28 @@ "@octokit/openapi-types": "^8.2.1" } }, + "node_modules/@open-draft/deferred-promise": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/@open-draft/deferred-promise/-/deferred-promise-2.2.0.tgz", + "integrity": "sha512-CecwLWx3rhxVQF6V4bAgPS5t+So2sTbPgAzafKkVizyi7tlwpcFpdFqq+wqF2OwNBmqFuu6tOyouTuxgpMfzmA==", + "dev": true + }, + "node_modules/@open-draft/logger": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/@open-draft/logger/-/logger-0.3.0.tgz", + "integrity": "sha512-X2g45fzhxH238HKO4xbSr7+wBS8Fvw6ixhTDuvLd5mqh6bJJCFAPwU9mPDxbcrRtfxv4u5IHCEH77BmxvXmmxQ==", + "dev": true, + "dependencies": { + "is-node-process": "^1.2.0", + "outvariant": "^1.4.0" + } + }, + "node_modules/@open-draft/until": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/@open-draft/until/-/until-2.1.0.tgz", + "integrity": "sha512-U69T3ItWHvLwGg5eJ0n3I62nWuE6ilHlmz7zM0npLBRvPRd7e6NYmg54vvRtP5mZG7kZqZCFVdsTWo7BPtBujg==", + "dev": true + }, "node_modules/@pkgjs/parseargs": { "version": "0.11.0", "resolved": "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz", @@ -3598,12 +3635,6 @@ "@types/responselike": "*" } }, - "node_modules/@types/caseless": { - "version": "0.12.2", - "resolved": "https://registry.npmjs.org/@types/caseless/-/caseless-0.12.2.tgz", - "integrity": "sha512-6ckxMjBBD8URvjB6J3NcnuAn5Pkl7t3TizAg+xdlzzQGSPSmBcXf8KoIH0ua/i+tio+ZRUHEXp0HEmvaR4kt0w==", - "dev": true - }, "node_modules/@types/chai": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.3.0.tgz", @@ -3961,32 +3992,6 @@ "@types/node": "*" } }, - "node_modules/@types/request": { - "version": "2.48.12", - "resolved": "https://registry.npmjs.org/@types/request/-/request-2.48.12.tgz", - "integrity": "sha512-G3sY+NpsA9jnwm0ixhAFQSJ3Q9JkpLZpJbI3GMv0mIAT0y3mRabYeINzal5WOChIiaTEGQYlHOKgkaM9EisWHw==", - "dev": true, - "dependencies": { - "@types/caseless": "*", - "@types/node": "*", - "@types/tough-cookie": "*", - "form-data": "^2.5.0" - } - }, - "node_modules/@types/request/node_modules/form-data": { - "version": "2.5.1", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.5.1.tgz", - "integrity": "sha512-m21N3WOmEEURgk6B9GLOE4RuWOFf28Lhh9qGYeNlGq4VDXUlJy2th2slBNU8Gp8EzloYZOibZJ7t5ecIrFSjVA==", - "dev": true, - "dependencies": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.6", - "mime-types": "^2.1.12" - }, - "engines": { - "node": ">= 0.12" - } - }, "node_modules/@types/responselike": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/@types/responselike/-/responselike-1.0.0.tgz", @@ -4116,12 +4121,6 @@ "integrity": "sha512-dDZH/tXzwjutnuk4UacGgFRwV+JSLaXL1ikvidfJprkb7L9Nx1njcRHHmi3Dsvt7pgqqTEeucQuOrWHPFgzVHA==", "dev": true }, - "node_modules/@types/tough-cookie": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/@types/tough-cookie/-/tough-cookie-4.0.1.tgz", - "integrity": "sha512-Y0K95ThC3esLEYD6ZuqNek29lNX2EM1qxV8y2FTLUB0ff5wWrk7az+mLrnNFUnaXcgKye22+sFBRXOgpPILZNg==", - "dev": true - }, "node_modules/@types/update-notifier": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/@types/update-notifier/-/update-notifier-4.1.1.tgz", @@ -5254,14 +5253,6 @@ "safer-buffer": "~2.1.0" } }, - "node_modules/assert-plus": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", - "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=", - "engines": { - "node": ">=0.8" - } - }, "node_modules/assertion-error": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz", @@ -5339,14 +5330,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/aws-sign2": { - "version": "0.7.0", - "resolved": "https://registry.npmjs.org/aws-sign2/-/aws-sign2-0.7.0.tgz", - "integrity": "sha1-tG6JCTSpWR8tL2+G1+ap8bP+dqg=", - "engines": { - "node": "*" - } - }, "node_modules/aws4": { "version": "1.12.0", "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.12.0.tgz", @@ -5865,9 +5848,9 @@ "integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==" }, "node_modules/body-parser": { - "version": "1.20.2", - "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.2.tgz", - "integrity": "sha512-ml9pReCu3M61kGlqoTm2umSXTlRTuGTx0bfYj+uIUKKYycG5NtSbeetV3faSU6R7ajOPw0g/J1PvK4qNy7s5bA==", + "version": "1.20.3", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.3.tgz", + "integrity": "sha512-7rAxByjUMqQ3/bHJy7D6OGXvx/MMc4IqBn/X0fcM1QUcAItpZrBEYhWGem+tzXH90c+G01ypMcYJBO9Y30203g==", "dependencies": { "bytes": "3.1.2", "content-type": "~1.0.5", @@ -5877,7 +5860,7 @@ "http-errors": "2.0.0", "iconv-lite": "0.4.24", "on-finished": "2.4.1", - "qs": "6.11.0", + "qs": "6.13.0", "raw-body": "2.5.2", "type-is": "~1.6.18", "unpipe": "1.0.0" @@ -5900,6 +5883,20 @@ "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==" }, + "node_modules/body-parser/node_modules/qs": { + "version": "6.13.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.13.0.tgz", + "integrity": "sha512-+38qI9SOr8tfZ4QmJNplMUxqjbe7LKvvZgWdExBOmd+egZTtjLB67Gu0HRX3u/XOq7UU2Nx6nsjvS16Z9uwfpg==", + "dependencies": { + "side-channel": "^1.0.6" + }, + "engines": { + "node": ">=0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/bonjour-service": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/bonjour-service/-/bonjour-service-1.2.1.tgz", @@ -6190,11 +6187,6 @@ "upper-case-first": "^2.0.2" } }, - "node_modules/caseless": { - "version": "0.12.0", - "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", - "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=" - }, "node_modules/catch-uncommitted": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/catch-uncommitted/-/catch-uncommitted-2.0.0.tgz", @@ -7098,17 +7090,6 @@ "type": "^1.0.1" } }, - "node_modules/dashdash": { - "version": "1.14.1", - "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", - "integrity": "sha1-hTz6D3y+L+1d4gMmuN1YEDX24vA=", - "dependencies": { - "assert-plus": "^1.0.0" - }, - "engines": { - "node": ">=0.10" - } - }, "node_modules/data-uri-to-buffer": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz", @@ -7698,15 +7679,6 @@ "resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz", "integrity": "sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==" }, - "node_modules/ecc-jsbn": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz", - "integrity": "sha1-OoOpBOVDUyh4dMVkt1SThoSamMk=", - "dependencies": { - "jsbn": "~0.1.0", - "safer-buffer": "^2.1.0" - } - }, "node_modules/ecdsa-sig-formatter": { "version": "1.0.11", "resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz", @@ -7743,7 +7715,7 @@ "node_modules/encodeurl": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", - "integrity": "sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k=", + "integrity": "sha512-TPJXq8JqFaVYm2CWmPvnP2Iyo4ZSM7/QKcSmuMLDObfpH5fi7RUGmd/rTDf+rut/saiDiQEeVTNgAmJEdAOx0w==", "engines": { "node": ">= 0.8" } @@ -8695,36 +8667,36 @@ } }, "node_modules/express": { - "version": "4.19.2", - "resolved": "https://registry.npmjs.org/express/-/express-4.19.2.tgz", - "integrity": "sha512-5T6nhjsT+EOMzuck8JjBHARTHfMht0POzlA60WV2pMD3gyXw2LZnZ+ueGdNxG+0calOJcWKbpFcuzLZ91YWq9Q==", + "version": "4.20.0", + "resolved": "https://registry.npmjs.org/express/-/express-4.20.0.tgz", + "integrity": "sha512-pLdae7I6QqShF5PnNTCVn4hI91Dx0Grkn2+IAsMTgMIKuQVte2dN9PeGSSAME2FR8anOhVA62QDIUaWVfEXVLw==", "dependencies": { "accepts": "~1.3.8", "array-flatten": "1.1.1", - "body-parser": "1.20.2", + "body-parser": "1.20.3", "content-disposition": "0.5.4", "content-type": "~1.0.4", "cookie": "0.6.0", "cookie-signature": "1.0.6", "debug": "2.6.9", "depd": "2.0.0", - "encodeurl": "~1.0.2", + "encodeurl": "~2.0.0", "escape-html": "~1.0.3", "etag": "~1.8.1", "finalhandler": "1.2.0", "fresh": "0.5.2", "http-errors": "2.0.0", - "merge-descriptors": "1.0.1", + "merge-descriptors": "1.0.3", "methods": "~1.1.2", "on-finished": "2.4.1", "parseurl": "~1.3.3", - "path-to-regexp": "0.1.7", + "path-to-regexp": "0.1.10", "proxy-addr": "~2.0.7", "qs": "6.11.0", "range-parser": "~1.2.1", "safe-buffer": "5.2.1", - "send": "0.18.0", - "serve-static": "1.15.0", + "send": "0.19.0", + "serve-static": "1.16.0", "setprototypeof": "1.2.0", "statuses": "2.0.1", "type-is": "~1.6.18", @@ -8756,6 +8728,14 @@ "ms": "2.0.0" } }, + "node_modules/express/node_modules/encodeurl": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-2.0.0.tgz", + "integrity": "sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg==", + "engines": { + "node": ">= 0.8" + } + }, "node_modules/express/node_modules/ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", @@ -8828,14 +8808,6 @@ "node": ">=0.4.0" } }, - "node_modules/extsprintf": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz", - "integrity": "sha1-lpGEQOMEGnpBT4xS48V06zw+HgU=", - "engines": [ - "node >=0.6.0" - ] - }, "node_modules/fast-boot2": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/fast-boot2/-/fast-boot2-1.1.0.tgz", @@ -9304,27 +9276,6 @@ "url": "https://github.com/sponsors/isaacs" } }, - "node_modules/forever-agent": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz", - "integrity": "sha1-+8cfDEGt6zf5bFd60e1C2P2sypE=", - "engines": { - "node": "*" - } - }, - "node_modules/form-data": { - "version": "2.3.3", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.3.3.tgz", - "integrity": "sha512-1lLKB2Mu3aGP1Q/2eCOx0fNbRMe7XdwktwOruhfqqd0rIJWwN4Dh+E3hrPSlDCXnSR7UtZ1N38rVXm+6+MEhJQ==", - "dependencies": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.6", - "mime-types": "^2.1.12" - }, - "engines": { - "node": ">= 0.12" - } - }, "node_modules/form-data-encoder": { "version": "1.7.2", "resolved": "https://registry.npmjs.org/form-data-encoder/-/form-data-encoder-1.7.2.tgz", @@ -9646,14 +9597,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/getpass": { - "version": "0.1.7", - "resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz", - "integrity": "sha1-Xv+OPmhNVprkyysSgmBOi6YhSfo=", - "dependencies": { - "assert-plus": "^1.0.0" - } - }, "node_modules/git-hooks-list": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/git-hooks-list/-/git-hooks-list-3.1.0.tgz", @@ -9936,27 +9879,6 @@ "uglify-js": "^3.1.4" } }, - "node_modules/har-schema": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/har-schema/-/har-schema-2.0.0.tgz", - "integrity": "sha1-qUwiJOvKwEeCoNkDVSHyRzW37JI=", - "engines": { - "node": ">=4" - } - }, - "node_modules/har-validator": { - "version": "5.1.5", - "resolved": "https://registry.npmjs.org/har-validator/-/har-validator-5.1.5.tgz", - "integrity": "sha512-nmT2T0lljbxdQZfspsno9hgrG3Uir6Ks5afism62poxqBM6sDnMEuPmzTq8XN0OEwqKLLdh1jQI3qyE66Nzb3w==", - "deprecated": "this library is no longer supported", - "dependencies": { - "ajv": "^6.12.3", - "har-schema": "^2.0.0" - }, - "engines": { - "node": ">=6" - } - }, "node_modules/has": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", @@ -10213,20 +10135,6 @@ "node": ">=8.0.0" } }, - "node_modules/http-signature": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.2.0.tgz", - "integrity": "sha1-muzZJRFHcvPZW2WmCruPfBj7rOE=", - "dependencies": { - "assert-plus": "^1.0.0", - "jsprim": "^1.2.2", - "sshpk": "^1.7.0" - }, - "engines": { - "node": ">=0.8", - "npm": ">=1.3.7" - } - }, "node_modules/http2-wrapper": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/http2-wrapper/-/http2-wrapper-1.0.3.tgz", @@ -11099,6 +11007,12 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/is-node-process": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/is-node-process/-/is-node-process-1.2.0.tgz", + "integrity": "sha512-Vg4o6/fqPxIjtxgUH5QLJhwZ7gW5diGCVlXpuUfELC62CuxM1iHcRe51f2W1FDy04Ai4KJkagKjx3XaqyfRKXw==", + "dev": true + }, "node_modules/is-npm": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/is-npm/-/is-npm-5.0.0.tgz", @@ -11365,11 +11279,6 @@ "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==" }, - "node_modules/isstream": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", - "integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=" - }, "node_modules/iterator.prototype": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/iterator.prototype/-/iterator.prototype-1.1.2.tgz", @@ -11479,11 +11388,6 @@ "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==" }, - "node_modules/jsbn": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", - "integrity": "sha512-UVU9dibq2JcFWxQPA6KCqj5O42VOmAY3zQUfEKxU0KpTGXwNoCjkX1e13eHNvw/xPynt6pU0rZ1htjWTNTSXsg==" - }, "node_modules/jsdoc-type-pratt-parser": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/jsdoc-type-pratt-parser/-/jsdoc-type-pratt-parser-4.0.0.tgz", @@ -11522,11 +11426,6 @@ "integrity": "sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w==", "dev": true }, - "node_modules/json-schema": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.4.0.tgz", - "integrity": "sha512-es94M3nTIfsEPisRafak+HDLfHXnKBhV3vU5eqPcS3flIWqcxJWgXHXiey3YrpaNsanY5ei1VoYEbOzijuq9BA==" - }, "node_modules/json-schema-traverse": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", @@ -11642,20 +11541,6 @@ "npm": ">=6" } }, - "node_modules/jsprim": { - "version": "1.4.2", - "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.2.tgz", - "integrity": "sha512-P2bSOMAc/ciLz6DzgjVlGJP9+BrJWu5UDGK70C2iweC5QBIeFf0ZXRvGjEj2uYgrY2MkAAhsSWHDWlFtEroZWw==", - "dependencies": { - "assert-plus": "1.0.0", - "extsprintf": "1.3.0", - "json-schema": "0.4.0", - "verror": "1.10.0" - }, - "engines": { - "node": ">=0.6.0" - } - }, "node_modules/jsx-ast-utils": { "version": "3.3.5", "resolved": "https://registry.npmjs.org/jsx-ast-utils/-/jsx-ast-utils-3.3.5.tgz", @@ -12425,9 +12310,12 @@ } }, "node_modules/merge-descriptors": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", - "integrity": "sha1-sAqqVW3YtEVoFQ7J0blT8/kMu2E=" + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.3.tgz", + "integrity": "sha512-gaNvAS7TZ897/rVaZ0nMtAyxNyi/pdbjbAwUpFQpN70GqnVfOiXpeUUMKRBmzXaSQ8DdTX4/0ms62r2K+hE6mQ==", + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } }, "node_modules/merge2": { "version": "1.4.1", @@ -13066,17 +12954,17 @@ } }, "node_modules/nock": { - "version": "13.5.4", - "resolved": "https://registry.npmjs.org/nock/-/nock-13.5.4.tgz", - "integrity": "sha512-yAyTfdeNJGGBFxWdzSKCBYxs5FxLbCg5X5Q4ets974hcQzG1+qCxvIyOo4j2Ry6MUlhWVMX4OoYDefAIIwupjw==", + "version": "14.0.0-beta.12", + "resolved": "https://registry.npmjs.org/nock/-/nock-14.0.0-beta.12.tgz", + "integrity": "sha512-O0rwesoqOBhCG/5A1ytWJKLGhmqWeOs7xJYsTVqePqywUdSYsOZ7dY4l0lN6w7dfvg2C11sqMuNKmRi8ktLs7A==", "dev": true, "dependencies": { - "debug": "^4.1.0", + "@mswjs/interceptors": "^0.35.0", "json-stringify-safe": "^5.0.1", "propagate": "^2.0.0" }, "engines": { - "node": ">= 10.13" + "node": ">= 18" } }, "node_modules/node-abi": { @@ -13292,14 +13180,6 @@ "node": ">=0.10.0" } }, - "node_modules/oauth-sign": { - "version": "0.9.0", - "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz", - "integrity": "sha512-fexhUFFPTGV8ybAtSIGbV6gOkSv8UtRbDBnAyLQw4QPKkgNlsH2ByPGtMUqdWkos6YCRmAqViwgZrJc/mRDzZQ==", - "engines": { - "node": "*" - } - }, "node_modules/object-assign": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", @@ -13774,6 +13654,12 @@ "resolved": "https://registry.npmjs.org/outdent/-/outdent-0.8.0.tgz", "integrity": "sha512-KiOAIsdpUTcAXuykya5fnVVT+/5uS0Q1mrkRHcF89tpieSmY33O/tmc54CqwA+bfhbtEfZUNLHaPUiB9X3jt1A==" }, + "node_modules/outvariant": { + "version": "1.4.3", + "resolved": "https://registry.npmjs.org/outvariant/-/outvariant-1.4.3.tgz", + "integrity": "sha512-+Sl2UErvtsoajRDKCE5/dBz4DIvHXQQnAxtQTF04OJxY0+DyZXSo5P5Bb7XYWOh81syohlYL24hbDwxedPUJCA==", + "dev": true + }, "node_modules/over": { "version": "0.0.5", "resolved": "https://registry.npmjs.org/over/-/over-0.0.5.tgz", @@ -14385,9 +14271,9 @@ } }, "node_modules/path-to-regexp": { - "version": "0.1.7", - "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", - "integrity": "sha512-5DFkuoqlv1uYQKxy8omFBeJPQcdoE07Kv2sferDCrAq1ohOU+MSDswDIbnx3YAM60qIOnYa53wBhXW0EbMonrQ==" + "version": "0.1.10", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.10.tgz", + "integrity": "sha512-7lf7qcQidTku0Gu3YDPc8DJ1q7OOucfa/BSsIwjuh56VU7katFvuM8hULfkwB3Fns/rsVF7PwPKVw1sl5KQS9w==" }, "node_modules/path-type": { "version": "4.0.0", @@ -14431,11 +14317,6 @@ "resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz", "integrity": "sha1-elfrVQpng/kRUzH89GY9XI4AelA=" }, - "node_modules/performance-now": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz", - "integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=" - }, "node_modules/picocolors": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz", @@ -14732,11 +14613,6 @@ "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" }, - "node_modules/psl": { - "version": "1.8.0", - "resolved": "https://registry.npmjs.org/psl/-/psl-1.8.0.tgz", - "integrity": "sha512-RIdOzyoavK+hA18OGGWDqUTsCLhtA7IcZ/6NCs4fFJaHBDab+pDDmDIByWFRQJq2Cd7r1OoQxBGKOaztq+hjIQ==" - }, "node_modules/pullstream": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/pullstream/-/pullstream-0.4.1.tgz", @@ -14770,9 +14646,9 @@ "integrity": "sha512-ev2QzSzWPYmy9GuqfIVildA4OdcGLeFZQrq5ys6RtiuF+RQQiZWr8TZNyAcuVXyQRYfEO+MsoB/1BuQVhOJuoQ==" }, "node_modules/pump": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz", - "integrity": "sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==", + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.1.tgz", + "integrity": "sha512-2ynnAmUu45oUSq51AQbeugLkMSKaz8FqVpZ6ykTqzOVkzXe8u/ezkGsYrFJqKZx+D9cVxoDrSbR7CeAwxFa5cQ==", "dependencies": { "end-of-stream": "^1.1.0", "once": "^1.3.1" @@ -15165,54 +15041,6 @@ "readable-stream": "^2.0.2" } }, - "node_modules/request": { - "version": "2.88.2", - "resolved": "https://registry.npmjs.org/request/-/request-2.88.2.tgz", - "integrity": "sha512-MsvtOrfG9ZcrOwAW+Qi+F6HbD0CWXEh9ou77uOb7FM2WPhwT7smM833PzanhJLsgXjN89Ir6V2PczXNnMpwKhw==", - "deprecated": "request has been deprecated, see https://github.com/request/request/issues/3142", - "dependencies": { - "aws-sign2": "~0.7.0", - "aws4": "^1.8.0", - "caseless": "~0.12.0", - "combined-stream": "~1.0.6", - "extend": "~3.0.2", - "forever-agent": "~0.6.1", - "form-data": "~2.3.2", - "har-validator": "~5.1.3", - "http-signature": "~1.2.0", - "is-typedarray": "~1.0.0", - "isstream": "~0.1.2", - "json-stringify-safe": "~5.0.1", - "mime-types": "~2.1.19", - "oauth-sign": "~0.9.0", - "performance-now": "^2.1.0", - "qs": "~6.5.2", - "safe-buffer": "^5.1.2", - "tough-cookie": "~2.5.0", - "tunnel-agent": "^0.6.0", - "uuid": "^3.3.2" - }, - "engines": { - "node": ">= 6" - } - }, - "node_modules/request/node_modules/qs": { - "version": "6.5.3", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.3.tgz", - "integrity": "sha512-qxXIEh4pCGfHICj1mAJQ2/2XVZkjCDTcEgfoSQxc/fYivUZxTkk7L3bDBJSoNrEzXI17oUO5Dp07ktqE5KzczA==", - "engines": { - "node": ">=0.6" - } - }, - "node_modules/request/node_modules/uuid": { - "version": "3.4.0", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz", - "integrity": "sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==", - "deprecated": "Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.", - "bin": { - "uuid": "bin/uuid" - } - }, "node_modules/require-directory": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", @@ -15748,9 +15576,9 @@ } }, "node_modules/send": { - "version": "0.18.0", - "resolved": "https://registry.npmjs.org/send/-/send-0.18.0.tgz", - "integrity": "sha512-qqWzuOjSFOuqPjFe4NOsMLafToQQwBSOEpS+FwEt3A2V3vKubTquT3vmLTQpFgMXp8AlFWFuP1qKaJZOtPpVXg==", + "version": "0.19.0", + "resolved": "https://registry.npmjs.org/send/-/send-0.19.0.tgz", + "integrity": "sha512-dW41u5VfLXu8SJh5bwRmyYUbAoSB3c9uQh6L8h/KtsFREPWpbX1lrljJo186Jc4nmci/sGUZ9a0a0J2zgfq2hw==", "dependencies": { "debug": "2.6.9", "depd": "2.0.0", @@ -15840,9 +15668,9 @@ } }, "node_modules/serve-static": { - "version": "1.15.0", - "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.15.0.tgz", - "integrity": "sha512-XGuRDNjXUijsUL0vl6nSD7cwURuzEgglbOaFuZM9g3kwDXOWVTck0jLzjPzGD+TazWbboZYu52/9/XPdUgne9g==", + "version": "1.16.0", + "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.16.0.tgz", + "integrity": "sha512-pDLK8zwl2eKaYrs8mrPZBJua4hMplRWJ1tIFksVC3FtBEBnl8dxgeHtsaMS8DhS9i4fLObaon6ABoc4/hQGdPA==", "dependencies": { "encodeurl": "~1.0.2", "escape-html": "~1.0.3", @@ -15853,6 +15681,53 @@ "node": ">= 0.8.0" } }, + "node_modules/serve-static/node_modules/debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "dependencies": { + "ms": "2.0.0" + } + }, + "node_modules/serve-static/node_modules/debug/node_modules/ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==" + }, + "node_modules/serve-static/node_modules/mime": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz", + "integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==", + "bin": { + "mime": "cli.js" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/serve-static/node_modules/send": { + "version": "0.18.0", + "resolved": "https://registry.npmjs.org/send/-/send-0.18.0.tgz", + "integrity": "sha512-qqWzuOjSFOuqPjFe4NOsMLafToQQwBSOEpS+FwEt3A2V3vKubTquT3vmLTQpFgMXp8AlFWFuP1qKaJZOtPpVXg==", + "dependencies": { + "debug": "2.6.9", + "depd": "2.0.0", + "destroy": "1.2.0", + "encodeurl": "~1.0.2", + "escape-html": "~1.0.3", + "etag": "~1.8.1", + "fresh": "0.5.2", + "http-errors": "2.0.0", + "mime": "1.6.0", + "ms": "2.1.3", + "on-finished": "2.4.1", + "range-parser": "~1.2.1", + "statuses": "2.0.1" + }, + "engines": { + "node": ">= 0.8.0" + } + }, "node_modules/set-blocking": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", @@ -16314,30 +16189,6 @@ "nan": "^2.18.0" } }, - "node_modules/sshpk": { - "version": "1.16.1", - "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.16.1.tgz", - "integrity": "sha512-HXXqVUq7+pcKeLqqZj6mHFUMvXtOJt1uoUx09pFW6011inTMxqI8BA8PM95myrIyyKwdnzjdFjLiE6KBPVtJIg==", - "dependencies": { - "asn1": "~0.2.3", - "assert-plus": "^1.0.0", - "bcrypt-pbkdf": "^1.0.0", - "dashdash": "^1.12.0", - "ecc-jsbn": "~0.1.1", - "getpass": "^0.1.1", - "jsbn": "~0.1.0", - "safer-buffer": "^2.0.2", - "tweetnacl": "~0.14.0" - }, - "bin": { - "sshpk-conv": "bin/sshpk-conv", - "sshpk-sign": "bin/sshpk-sign", - "sshpk-verify": "bin/sshpk-verify" - }, - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/statuses": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz", @@ -16412,6 +16263,12 @@ "queue-tick": "^1.0.1" } }, + "node_modules/strict-event-emitter": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/strict-event-emitter/-/strict-event-emitter-0.5.1.tgz", + "integrity": "sha512-vMgjE/GGEPEFnhFub6pa4FmJBRBVOLpIII2hvCZ8Kzb7K0hlHo7mQv6xYrBvCL2LtAIBwFUK8wvuJgTVSQ5MFQ==", + "dev": true + }, "node_modules/strict-event-emitter-types": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/strict-event-emitter-types/-/strict-event-emitter-types-2.0.0.tgz", @@ -16961,18 +16818,6 @@ "url": "https://github.com/sponsors/Borewit" } }, - "node_modules/tough-cookie": { - "version": "2.5.0", - "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.5.0.tgz", - "integrity": "sha512-nlLsUzgm1kfLXSXfRZMc1KLAugd4hqJHDTvc2hDIwS3mZAfMEuMbc03SujMF+GEcpaX/qboeycw6iO8JwVv2+g==", - "dependencies": { - "psl": "^1.1.28", - "punycode": "^2.1.1" - }, - "engines": { - "node": ">=0.8" - } - }, "node_modules/tr46": { "version": "0.0.3", "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", @@ -17575,19 +17420,6 @@ "node": ">= 0.8" } }, - "node_modules/verror": { - "version": "1.10.0", - "resolved": "https://registry.npmjs.org/verror/-/verror-1.10.0.tgz", - "integrity": "sha1-OhBcoXBTr1XW4nDB+CiGguGNpAA=", - "engines": [ - "node >=0.6.0" - ], - "dependencies": { - "assert-plus": "^1.0.0", - "core-util-is": "1.0.2", - "extsprintf": "^1.2.0" - } - }, "node_modules/vscode-languageserver-types": { "version": "3.17.3", "resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.17.3.tgz", diff --git a/package.json b/package.json index d9b75c20e9..5a52d6959f 100644 --- a/package.json +++ b/package.json @@ -148,7 +148,6 @@ "@types/parse-link-header": "^2.0.3", "@types/prettyjson": "^0.0.33", "@types/progress-stream": "^2.0.2", - "@types/request": "^2.48.7", "@types/rewire": "^2.5.30", "@types/rimraf": "^3.0.2", "@types/semver": "^7.3.9", @@ -182,7 +181,7 @@ "mkdirp": "^3.0.1", "mocha": "^10.6.0", "mock-require": "^3.0.3", - "nock": "^13.2.1", + "nock": "^14.0.0-beta.12", "oclif": "^4.14.0", "parse-link-header": "^2.0.0", "rewire": "^7.0.0", @@ -250,7 +249,6 @@ "prettyjson": "^1.2.5", "progress-stream": "^2.0.0", "reconfix": "^1.0.0-v0-1-0-fork-46760acff4d165f5238bfac5e464256ef1944476", - "request": "^2.88.2", "resin-cli-form": "^3.0.0", "resin-cli-visuals": "^2.0.0", "resin-doodles": "^0.2.0", diff --git a/src/utils/deploy-legacy.ts b/src/utils/deploy-legacy.ts index 074e9cf246..2750fbcb73 100644 --- a/src/utils/deploy-legacy.ts +++ b/src/utils/deploy-legacy.ts @@ -19,7 +19,7 @@ import { getVisuals } from './lazy'; import { promisify } from 'util'; import type * as Dockerode from 'dockerode'; import type Logger = require('./logger'); -import type { Request } from 'request'; +import type got from 'got'; const getBuilderPushEndpoint = function ( baseUrl: string, @@ -75,7 +75,10 @@ const showPushProgress = function (message: string) { return progressBar; }; -const uploadToPromise = (uploadRequest: Request, logger: Logger) => +const uploadToPromise = ( + uploadRequest: ReturnType, + logger: Logger, +) => new Promise<{ buildId: number }>(function (resolve, reject) { uploadRequest.on('error', reject).on('data', function handleMessage(data) { let obj; @@ -109,7 +112,7 @@ const uploadToPromise = (uploadRequest: Request, logger: Logger) => /** * @returns {Promise<{ buildId: number }>} */ -const uploadImage = function ( +const uploadImage = async function ( imageStream: NodeJS.ReadableStream & { length: number }, token: string, username: string, @@ -117,10 +120,9 @@ const uploadImage = function ( appName: string, logger: Logger, ): Promise<{ buildId: number }> { - const request = require('request') as typeof import('request'); - const progressStream = - require('progress-stream') as typeof import('progress-stream'); - const zlib = require('zlib') as typeof import('zlib'); + const { default: got } = await import('got'); + const progressStream = await import('progress-stream'); + const zlib = await import('zlib'); // Need to strip off the newline const progressMessage = logger @@ -141,25 +143,26 @@ const uploadImage = function ( ), ); - const uploadRequest = request.post({ - url: getBuilderPushEndpoint(url, username, appName), - headers: { - 'Content-Encoding': 'gzip', - }, - auth: { - bearer: token, + const uploadRequest = got.stream.post( + getBuilderPushEndpoint(url, username, appName), + { + headers: { + 'Content-Encoding': 'gzip', + Authorization: `Bearer ${token}`, + }, + body: streamWithProgress.pipe( + zlib.createGzip({ + level: 6, + }), + ), + throwHttpErrors: false, }, - body: streamWithProgress.pipe( - zlib.createGzip({ - level: 6, - }), - ), - }); + ); return uploadToPromise(uploadRequest, logger); }; -const uploadLogs = function ( +const uploadLogs = async function ( logs: string, token: string, url: string, @@ -167,14 +170,14 @@ const uploadLogs = function ( username: string, appName: string, ) { - const request = require('request') as typeof import('request'); - return request.post({ - json: true, - url: getBuilderLogPushEndpoint(url, buildId, username, appName), - auth: { - bearer: token, + const { default: got } = await import('got'); + return got.post(getBuilderLogPushEndpoint(url, buildId, username, appName), { + headers: { + Authorization: `Bearer ${token}`, }, body: Buffer.from(logs), + responseType: 'json', + throwHttpErrors: false, }); }; diff --git a/src/utils/device/api.ts b/src/utils/device/api.ts index 7687ed255f..0b77920cfe 100644 --- a/src/utils/device/api.ts +++ b/src/utils/device/api.ts @@ -15,12 +15,13 @@ * limitations under the License. */ import * as _ from 'lodash'; -import * as request from 'request'; import type * as Stream from 'stream'; import { retry } from '../helpers'; import Logger = require('../logger'); import * as ApiErrors from './errors'; +import { getBalenaSdk } from '../lazy'; +import type { BalenaSDK } from 'balena-sdk'; export interface DeviceResponse { [key: string]: any; @@ -82,7 +83,7 @@ export class DeviceAPI { // Either return nothing, or throw an error with the info public async setTargetState(state: any): Promise { const url = this.getUrlForAction('setTargetState'); - return DeviceAPI.promisifiedRequest( + return await DeviceAPI.sendRequest( { method: 'POST', url, @@ -96,7 +97,7 @@ export class DeviceAPI { public async getTargetState(): Promise { const url = this.getUrlForAction('getTargetState'); - return DeviceAPI.promisifiedRequest( + return await DeviceAPI.sendRequest( { method: 'GET', url, @@ -111,7 +112,7 @@ export class DeviceAPI { public async getDeviceInformation(): Promise { const url = this.getUrlForAction('getDeviceInformation'); - return DeviceAPI.promisifiedRequest( + return await DeviceAPI.sendRequest( { method: 'GET', url, @@ -126,7 +127,7 @@ export class DeviceAPI { public async getContainerId(serviceName: string): Promise { const url = this.getUrlForAction('containerId'); - const body = await DeviceAPI.promisifiedRequest( + const body = await await DeviceAPI.sendRequest( { method: 'GET', url, @@ -149,7 +150,7 @@ export class DeviceAPI { public async ping(): Promise { const url = this.getUrlForAction('ping'); - return DeviceAPI.promisifiedRequest( + return await DeviceAPI.sendRequest( { method: 'GET', url, @@ -158,10 +159,10 @@ export class DeviceAPI { ); } - public getVersion(): Promise { + public async getVersion(): Promise { const url = this.getUrlForAction('version'); - return DeviceAPI.promisifiedRequest({ + return await DeviceAPI.sendRequest({ method: 'GET', url, json: true, @@ -176,10 +177,10 @@ export class DeviceAPI { }); } - public getStatus(): Promise { + public async getStatus(): Promise { const url = this.getUrlForAction('status'); - return DeviceAPI.promisifiedRequest({ + return await DeviceAPI.sendRequest({ method: 'GET', url, json: true, @@ -196,28 +197,9 @@ export class DeviceAPI { public getLogStream(): Promise { const url = this.getUrlForAction('logs'); + const sdk = getBalenaSdk(); - // Don't use the promisified version here as we want to stream the output - return new Promise((resolve, reject) => { - const req = request.get(url); - - req.on('error', reject).on('response', async (res) => { - if (res.statusCode !== 200) { - reject( - new ApiErrors.DeviceAPIError( - 'Non-200 response from log streaming endpoint', - ), - ); - return; - } - try { - res.socket.setKeepAlive(true, 1000); - } catch (error) { - reject(error); - } - resolve(res); - }); - }); + return sdk.request.stream({ url }); } private getUrlForAction(action: keyof typeof deviceEndpoints): string { @@ -226,50 +208,33 @@ export class DeviceAPI { // A helper method for promisifying general (non-streaming) requests. Streaming // requests should use a seperate setup - private static async promisifiedRequest< - T extends Parameters[0], - >(opts: T, logger?: Logger): Promise { - interface ObjectWithUrl { - url?: string; + private static async sendRequest( + opts: Parameters[number], + logger?: Logger, + ): Promise { + if (logger != null && opts.url != null) { + logger.logDebug(`Sending request to ${opts.url}`); } - if (logger != null) { - let url: string | null = null; - if (_.isObject(opts) && (opts as ObjectWithUrl).url != null) { - // the `as string` shouldn't be necessary, but the type system - // is getting a little confused - url = (opts as ObjectWithUrl).url as string; - } else if (typeof opts === 'string') { - url = opts; - } - - if (url != null) { - logger.logDebug(`Sending request to ${url}`); - } - } + const sdk = getBalenaSdk(); const doRequest = async () => { - return await new Promise((resolve, reject) => { - return request(opts, (err, response, body) => { - if (err) { - return reject(err); - } - switch (response.statusCode) { - case 200: - return resolve(body); - case 400: - return reject( - new ApiErrors.BadRequestDeviceAPIError(body.message), - ); - case 503: - return reject( - new ApiErrors.ServiceUnavailableAPIError(body.message), - ); - default: - return reject(new ApiErrors.DeviceAPIError(body.message)); - } - }); - }); + const response = await sdk.request.send(opts); + + const bodyError = + typeof response.body === 'string' + ? response.body + : response.body.message; + switch (response.statusCode) { + case 200: + return response.body; + case 400: + throw new ApiErrors.BadRequestDeviceAPIError(bodyError); + case 503: + throw new ApiErrors.ServiceUnavailableAPIError(bodyError); + default: + new ApiErrors.DeviceAPIError(bodyError); + } }; return await retry({ diff --git a/src/utils/qemu.ts b/src/utils/qemu.ts index a9e379dc5b..04d5368118 100644 --- a/src/utils/qemu.ts +++ b/src/utils/qemu.ts @@ -94,7 +94,7 @@ async function installQemu(arch: string, qemuPath: string) { const urlVersion = encodeURIComponent(QEMU_VERSION); const qemuUrl = `https://github.com/balena-io/qemu/releases/download/${urlVersion}/${urlFile}`; - const request = await import('request'); + const { default: got } = await import('got'); const fs = await import('fs'); const zlib = await import('zlib'); const tar = await import('tar-stream'); @@ -117,7 +117,8 @@ async function installQemu(arch: string, qemuPath: string) { reject(err); } }); - request(qemuUrl) + got.stream + .get(qemuUrl, { throwHttpErrors: false }) .on('error', reject) .pipe(zlib.createGunzip()) .on('error', reject) diff --git a/src/utils/remote-build.ts b/src/utils/remote-build.ts index 353b653d51..335bd0a35e 100644 --- a/src/utils/remote-build.ts +++ b/src/utils/remote-build.ts @@ -16,7 +16,6 @@ limitations under the License. import type { BalenaSDK } from 'balena-sdk'; import * as JSONStream from 'JSONStream'; import * as readline from 'readline'; -import * as request from 'request'; import type { RegistrySecrets } from '@balena/compose/dist/multibuild'; import type * as Stream from 'stream'; import streamToPromise = require('stream-to-promise'); @@ -26,6 +25,8 @@ import { ExpectedError, SIGINTError } from '../errors'; import { tarDirectory } from './compose_ts'; import { getVisuals, stripIndent } from './lazy'; import Logger = require('./logger'); +import type { PlainResponse } from 'got'; +import type got from 'got'; const globalLogger = Logger.getLogger(); @@ -119,7 +120,7 @@ export async function startRemoteBuild( } catch (err) { console.error(err.message); } finally { - buildRequest.abort(); + buildRequest.destroy(); const sigintErr = new SIGINTError('Build aborted on SIGINT signal'); sigintErr.code = 'SIGINT'; stream.emit('error', sigintErr); @@ -343,25 +344,28 @@ async function getTarStream(build: RemoteBuild): Promise { * event and (2) calling request.pipe(): * https://github.com/request/request/issues/887 */ -function createRemoteBuildRequest( +async function createRemoteBuildRequest( build: RemoteBuild, tarStream: Stream.Readable, builderUrl: string, onError: (error: Error) => void, -): request.Request { - const zlib = require('zlib') as typeof import('zlib'); +) { + const { default: got } = await import('got'); + const zlib = await import('zlib'); if (DEBUG_MODE) { console.error(`[debug] Connecting to builder at ${builderUrl}`); } - return request - .post({ - url: builderUrl, - auth: { bearer: build.auth }, - headers: { 'Content-Encoding': 'gzip' }, + return got.stream + .post(builderUrl, { + headers: { + Authorization: `Bearer ${build.auth}`, + 'Content-Encoding': 'gzip', + }, body: tarStream.pipe(zlib.createGzip({ level: 6 })), + throwHttpErrors: false, }) .once('error', onError) // `.once` because the handler re-emits - .once('response', (response: request.RequestResponse) => { + .once('response', (response: PlainResponse) => { if (response.statusCode >= 100 && response.statusCode < 400) { if (DEBUG_MODE) { console.error( @@ -373,8 +377,8 @@ function createRemoteBuildRequest( 'Remote builder responded with HTTP error:', `${response.statusCode} ${response.statusMessage}`, ]; - if (response.body) { - msgArr.push(response.body); + if (response.rawBody) { + msgArr.push(response.rawBody.toString()); } onError(new ExpectedError(msgArr.join('\n'))); } @@ -383,7 +387,7 @@ function createRemoteBuildRequest( async function getRemoteBuildStream( build: RemoteBuild, -): Promise<[request.Request, Stream.Stream]> { +): Promise<[ReturnType, Stream.Stream]> { const builderUrl = await getBuilderEndpoint( build.baseUrl, build.appSlug, @@ -411,7 +415,7 @@ async function getRemoteBuildStream( } const tarStream = await getTarStream(build); - const buildRequest = createRemoteBuildRequest( + const buildRequest = await createRemoteBuildRequest( build, tarStream, builderUrl, diff --git a/tests/auth/server.spec.ts b/tests/auth/server.spec.ts index 2e3245abd3..987c2723bb 100644 --- a/tests/auth/server.spec.ts +++ b/tests/auth/server.spec.ts @@ -20,7 +20,7 @@ import * as chaiAsPromised from 'chai-as-promised'; import * as ejs from 'ejs'; import * as fs from 'fs'; import * as path from 'path'; -import * as request from 'request'; +import got from 'got'; import * as sinon from 'sinon'; import { LoginServer } from '../../build/auth/server'; @@ -67,32 +67,22 @@ describe('Login server:', function () { expectedStatusCode: number; expectedToken: string; urlPath?: string; - verb?: string; + verb?: 'get' | 'post'; }) { opt.urlPath = opt.urlPath ?? addr.urlPath; - const post = opt.verb - ? ((request as any)[opt.verb] as typeof request.post) - : request.post; - await new Promise((resolve, reject) => { - post( - `http://${addr.host}:${addr.port}${opt.urlPath}`, - { - form: { - token: opt.expectedToken, - }, + const request = opt.verb != null ? got[opt.verb] : got.post; + const res = await request( + `http://${addr.host}:${addr.port}${opt.urlPath}`, + { + form: { + token: opt.expectedToken, }, - function (error, response, body) { - try { - expect(error).to.not.exist; - expect(response.statusCode).to.equal(opt.expectedStatusCode); - expect(body).to.equal(opt.expectedBody); - resolve(); - } catch (err) { - reject(err); - } - }, - ); - }); + throwHttpErrors: false, + }, + ); + + expect(res.body).to.equal(opt.expectedBody); + expect(res.statusCode).to.equal(opt.expectedStatusCode); try { const token = await server.awaitForToken(); @@ -121,16 +111,6 @@ describe('Login server:', function () { }); }); - it('should get 404 if not using the correct verb', async () => { - await testLogin({ - expectedBody: 'Not found', - expectedStatusCode: 404, - expectedToken: tokens.johndoe.token, - expectedErrorMsg: 'Unknown path or verb', - verb: 'get', - }); - }); - describe('given the token authenticates with the server', function () { beforeEach(function () { this.loginIfTokenValidStub = sinon.stub(utils, 'loginIfTokenValid');