diff --git a/package-lock.json b/package-lock.json index b8ee15a6f86..6b07ce5d9b3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -116,8 +116,6 @@ "prom-client": "^15.1.3", "qs": "^6.14.0", "reflect-metadata": "^0.2.2", - "request-promise-core": "^1.1.4", - "request-promise-native": "^1.0.9", "response-time": "^2.3.3", "rimraf": "^6.0.1", "rss-parser": "^3.13.0", @@ -12693,19 +12691,6 @@ "uuid": "dist/bin/uuid" } }, - "node_modules/aws-sign2": { - "version": "0.7.0", - "license": "Apache-2.0", - "peer": true, - "engines": { - "node": "*" - } - }, - "node_modules/aws4": { - "version": "1.11.0", - "license": "MIT", - "peer": true - }, "node_modules/axe-core": { "version": "4.10.0", "resolved": "https://registry.npmjs.org/axe-core/-/axe-core-4.10.0.tgz", @@ -12939,14 +12924,6 @@ "node": ">=10.0.0" } }, - "node_modules/bcrypt-pbkdf": { - "version": "1.0.2", - "license": "BSD-3-Clause", - "peer": true, - "dependencies": { - "tweetnacl": "^0.14.3" - } - }, "node_modules/bcryptjs": { "version": "2.4.3", "license": "MIT" @@ -13370,11 +13347,6 @@ ], "license": "CC-BY-4.0" }, - "node_modules/caseless": { - "version": "0.12.0", - "license": "Apache-2.0", - "peer": true - }, "node_modules/chai": { "version": "4.3.6", "dev": true, @@ -14822,15 +14794,6 @@ "wcwidth": ">=1.0.1" } }, - "node_modules/ecc-jsbn": { - "version": "0.1.2", - "license": "MIT", - "peer": true, - "dependencies": { - "jsbn": "~0.1.0", - "safer-buffer": "^2.1.0" - } - }, "node_modules/ecdsa-sig-formatter": { "version": "1.0.11", "license": "Apache-2.0", @@ -16351,6 +16314,7 @@ }, "node_modules/extend": { "version": "3.0.2", + "dev": true, "license": "MIT" }, "node_modules/external-editor": { @@ -16825,14 +16789,6 @@ "node": ">=8.0.0" } }, - "node_modules/forever-agent": { - "version": "0.6.1", - "license": "Apache-2.0", - "peer": true, - "engines": { - "node": "*" - } - }, "node_modules/fork-ts-checker-webpack-plugin": { "version": "9.0.2", "resolved": "https://registry.npmjs.org/fork-ts-checker-webpack-plugin/-/fork-ts-checker-webpack-plugin-9.0.2.tgz", @@ -17192,14 +17148,6 @@ "resolved": "https://registry.npmjs.org/getopts/-/getopts-2.3.0.tgz", "integrity": "sha512-5eDf9fuSXwxBL6q5HX+dhDj+dslFGWzU5thZ9kNKUkcPtaPdatmUFKwHFrLb/uf/WpA4BHET+AX3Scl56cAjpA==" }, - "node_modules/getpass": { - "version": "0.1.7", - "license": "MIT", - "peer": true, - "dependencies": { - "assert-plus": "^1.0.0" - } - }, "node_modules/glob": { "version": "7.2.0", "license": "ISC", @@ -17385,46 +17333,6 @@ "node": "^12.22.0 || ^14.16.0 || ^16.0.0 || >=17.0.0" } }, - "node_modules/har-schema": { - "version": "2.0.0", - "license": "ISC", - "peer": true, - "engines": { - "node": ">=4" - } - }, - "node_modules/har-validator": { - "version": "5.1.5", - "license": "MIT", - "peer": true, - "dependencies": { - "ajv": "^6.12.3", - "har-schema": "^2.0.0" - }, - "engines": { - "node": ">=6" - } - }, - "node_modules/har-validator/node_modules/ajv": { - "version": "6.12.6", - "license": "MIT", - "peer": true, - "dependencies": { - "fast-deep-equal": "^3.1.1", - "fast-json-stable-stringify": "^2.0.0", - "json-schema-traverse": "^0.4.1", - "uri-js": "^4.2.2" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/epoberezkin" - } - }, - "node_modules/har-validator/node_modules/json-schema-traverse": { - "version": "0.4.1", - "license": "MIT", - "peer": true - }, "node_modules/has-ansi": { "version": "2.0.0", "dev": true, @@ -17694,20 +17602,6 @@ } } }, - "node_modules/http-signature": { - "version": "1.2.0", - "license": "MIT", - "peer": true, - "dependencies": { - "assert-plus": "^1.0.0", - "jsprim": "^1.2.2", - "sshpk": "^1.7.0" - }, - "engines": { - "node": ">=0.8", - "npm": ">=1.3.7" - } - }, "node_modules/https-proxy-agent": { "version": "5.0.1", "license": "MIT", @@ -18335,6 +18229,7 @@ }, "node_modules/is-typedarray": { "version": "1.0.0", + "dev": true, "license": "MIT" }, "node_modules/is-unicode-supported": { @@ -18384,11 +18279,6 @@ "ws": "*" } }, - "node_modules/isstream": { - "version": "0.1.2", - "license": "MIT", - "peer": true - }, "node_modules/istanbul-lib-coverage": { "version": "3.2.0", "dev": true, @@ -19256,11 +19146,6 @@ "js-yaml": "bin/js-yaml.js" } }, - "node_modules/jsbn": { - "version": "0.1.1", - "license": "MIT", - "peer": true - }, "node_modules/jsdom": { "version": "23.2.0", "resolved": "https://registry.npmjs.org/jsdom/-/jsdom-23.2.0.tgz", @@ -19372,11 +19257,6 @@ "dev": true, "license": "MIT" }, - "node_modules/json-schema": { - "version": "0.4.0", - "license": "(AFL-2.1 OR BSD-3-Clause)", - "peer": true - }, "node_modules/json-schema-to-ts": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/json-schema-to-ts/-/json-schema-to-ts-3.1.1.tgz", @@ -19399,11 +19279,6 @@ "dev": true, "license": "MIT" }, - "node_modules/json-stringify-safe": { - "version": "5.0.1", - "license": "ISC", - "peer": true - }, "node_modules/json5": { "version": "2.2.3", "license": "MIT", @@ -19472,38 +19347,6 @@ "npm": ">=6" } }, - "node_modules/jsprim": { - "version": "1.4.2", - "license": "MIT", - "peer": true, - "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/jsprim/node_modules/core-util-is": { - "version": "1.0.2", - "license": "MIT", - "peer": true - }, - "node_modules/jsprim/node_modules/verror": { - "version": "1.10.0", - "engines": [ - "node >=0.6.0" - ], - "license": "MIT", - "peer": true, - "dependencies": { - "assert-plus": "^1.0.0", - "core-util-is": "1.0.2", - "extsprintf": "^1.2.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", @@ -21521,14 +21364,6 @@ "version": "2.2.6", "license": "MIT" }, - "node_modules/oauth-sign": { - "version": "0.9.0", - "license": "Apache-2.0", - "peer": true, - "engines": { - "node": "*" - } - }, "node_modules/object-assign": { "version": "4.1.1", "license": "MIT", @@ -22251,11 +22086,6 @@ "version": "1.2.0", "license": "MIT" }, - "node_modules/performance-now": { - "version": "2.1.0", - "license": "MIT", - "peer": true - }, "node_modules/pg-connection-string": { "version": "2.5.0", "resolved": "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-2.5.0.tgz", @@ -23168,116 +22998,6 @@ "node": ">=0.10" } }, - "node_modules/request": { - "version": "2.88.2", - "license": "Apache-2.0", - "peer": true, - "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-promise-core": { - "version": "1.1.4", - "license": "ISC", - "dependencies": { - "lodash": "^4.17.19" - }, - "engines": { - "node": ">=0.10.0" - }, - "peerDependencies": { - "request": "^2.34" - } - }, - "node_modules/request-promise-native": { - "version": "1.0.9", - "license": "ISC", - "dependencies": { - "request-promise-core": "1.1.4", - "stealthy-require": "^1.1.1", - "tough-cookie": "^2.3.3" - }, - "engines": { - "node": ">=0.12.0" - }, - "peerDependencies": { - "request": "^2.34" - } - }, - "node_modules/request-promise-native/node_modules/tough-cookie": { - "version": "2.5.0", - "license": "BSD-3-Clause", - "dependencies": { - "psl": "^1.1.28", - "punycode": "^2.1.1" - }, - "engines": { - "node": ">=0.8" - } - }, - "node_modules/request/node_modules/form-data": { - "version": "2.3.3", - "license": "MIT", - "peer": true, - "dependencies": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.6", - "mime-types": "^2.1.12" - }, - "engines": { - "node": ">= 0.12" - } - }, - "node_modules/request/node_modules/qs": { - "version": "6.5.3", - "license": "BSD-3-Clause", - "peer": true, - "engines": { - "node": ">=0.6" - } - }, - "node_modules/request/node_modules/tough-cookie": { - "version": "2.5.0", - "license": "BSD-3-Clause", - "peer": true, - "dependencies": { - "psl": "^1.1.28", - "punycode": "^2.1.1" - }, - "engines": { - "node": ">=0.8" - } - }, - "node_modules/request/node_modules/uuid": { - "version": "3.4.0", - "license": "MIT", - "peer": true, - "bin": { - "uuid": "bin/uuid" - } - }, "node_modules/require-directory": { "version": "2.1.1", "license": "MIT", @@ -24411,30 +24131,6 @@ "node": ">= 0.6" } }, - "node_modules/sshpk": { - "version": "1.17.0", - "license": "MIT", - "peer": true, - "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/stable-hash": { "version": "0.0.4", "resolved": "https://registry.npmjs.org/stable-hash/-/stable-hash-0.0.4.tgz", @@ -24487,13 +24183,6 @@ "node": ">= 0.8" } }, - "node_modules/stealthy-require": { - "version": "1.1.1", - "license": "ISC", - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/stream-browserify": { "version": "3.0.0", "license": "MIT", @@ -25509,22 +25198,6 @@ "dev": true, "license": "0BSD" }, - "node_modules/tunnel-agent": { - "version": "0.6.0", - "license": "Apache-2.0", - "peer": true, - "dependencies": { - "safe-buffer": "^5.0.1" - }, - "engines": { - "node": "*" - } - }, - "node_modules/tweetnacl": { - "version": "0.14.5", - "license": "Unlicense", - "peer": true - }, "node_modules/type-check": { "version": "0.4.0", "dev": true, diff --git a/package.json b/package.json index fda00311c38..a8a322d1cbc 100644 --- a/package.json +++ b/package.json @@ -257,8 +257,6 @@ "prom-client": "^15.1.3", "qs": "^6.14.0", "reflect-metadata": "^0.2.2", - "request-promise-core": "^1.1.4", - "request-promise-native": "^1.0.9", "response-time": "^2.3.3", "rimraf": "^6.0.1", "rss-parser": "^3.13.0", diff --git a/src/services/edusharing/services/MerlinTokenGenerator.js b/src/services/edusharing/services/MerlinTokenGenerator.js index ccbe0d63653..6783ba20b7c 100644 --- a/src/services/edusharing/services/MerlinTokenGenerator.js +++ b/src/services/edusharing/services/MerlinTokenGenerator.js @@ -1,5 +1,5 @@ const { Configuration } = require('@hpi-schul-cloud/commons'); -const request = require('request-promise-native'); +const axios = require('axios'); const { getCounty } = require('../helpers'); class MerlinTokenGenerator { @@ -8,7 +8,9 @@ class MerlinTokenGenerator { } async post(options) { - return request.post(options); + const res = await axios(options); + + return res.data; } async getMerlinCredentials(county = null) { @@ -58,7 +60,7 @@ class MerlinTokenGenerator { headers: { 'Content-Type': 'application/x-www-form-urlencoded', }, - form: { + data: { username: credentials.username, password: credentials.password, }, diff --git a/src/services/etherpad/utils/EtherpadClient.js b/src/services/etherpad/utils/EtherpadClient.js index 95e5f83ada8..5b95c165463 100644 --- a/src/services/etherpad/utils/EtherpadClient.js +++ b/src/services/etherpad/utils/EtherpadClient.js @@ -1,5 +1,4 @@ -const rp = require('request-promise-native'); -const rpErrors = require('request-promise-core/errors'); +const axios = require('axios'); const { Configuration } = require('@hpi-schul-cloud/commons'); const { BadRequest, Conflict } = require('../../../errors'); @@ -40,48 +39,31 @@ class EtherpadClient { }; } - createSettings( - { - method = 'POST', - endpoint, - formDef = { - apikey: Configuration.get('ETHERPAD__API_KEY'), - }, - body, - }, - params = {} - ) { - const form = { ...formDef, ...params }; + createOptions(endpoint, params = {}) { + const apikey = Configuration.get('ETHERPAD__API_KEY'); + const data = { apikey, ...params }; return { - method, - uri: `${this.uri()}/${endpoint}`, - form, - body, - json: false, + method: 'POST', + url: `${this.uri()}/${endpoint}`, + data, }; } handleEtherpadResponse(res) { - const responseJSON = JSON.parse(res); + const responseJSON = res.data; switch (responseJSON.code) { case 0: return responseJSON; case 1: - throw new Conflict(responseJSON.message, rpErrors.RequestError(responseJSON.message, res)); + throw new Conflict(res); default: - throw new BadRequest(responseJSON.message, rpErrors.RequestError(responseJSON.message, res)); + throw new BadRequest(res); } } createOrGetAuthor(params) { - return rp( - this.createSettings( - { - endpoint: 'createAuthorIfNotExistsFor', - }, - params - ) - ) + const options = this.createOptions('createAuthorIfNotExistsFor', params); + return axios(options) .then((res) => this.handleEtherpadResponse(res)) .catch((err) => { throw new BadRequest(this.err.createOrGetAuthor, err); @@ -89,14 +71,8 @@ class EtherpadClient { } createOrGetGroup(params) { - return rp( - this.createSettings( - { - endpoint: 'createGroupIfNotExistsFor', - }, - params - ) - ) + const options = this.createOptions('createGroupIfNotExistsFor', params); + return axios(options) .then((res) => this.handleEtherpadResponse(res)) .catch((err) => { throw new BadRequest(this.err.createOrGetGroup, err); @@ -104,14 +80,8 @@ class EtherpadClient { } getActiveSessions(params) { - return rp( - this.createSettings( - { - endpoint: 'listSessionsOfAuthor', - }, - params - ) - ) + const options = this.createOptions('listSessionsOfAuthor', params); + return axios(options) .then((res) => this.handleEtherpadResponse(res)) .catch((err) => { throw new BadRequest(this.err.getActiveSessions, err); @@ -119,14 +89,8 @@ class EtherpadClient { } createSession(params) { - return rp( - this.createSettings( - { - endpoint: 'createSession', - }, - params - ) - ) + const options = this.createOptions('createSession', params); + return axios(options) .then((res) => this.handleEtherpadResponse(res)) .catch((err) => { throw new BadRequest(this.err.createSession, err); @@ -140,14 +104,8 @@ class EtherpadClient { sourceID: params.oldPadId, destinationID: newPadId, }; - return rp( - this.createSettings( - { - endpoint: 'copyPad', - }, - copyParams - ) - ) + const options = this.createOptions('copyPad', copyParams); + return axios(options) .then((res) => { const response = this.handleEtherpadResponse(res); response.data = { @@ -159,14 +117,8 @@ class EtherpadClient { throw new BadRequest(this.err.copyOldPadToGroupPad, err); }); } - return rp( - this.createSettings( - { - endpoint: 'createGroupPad', - }, - params - ) - ) + const options = this.createOptions('createGroupPad', params); + return axios(options) .then((res) => this.handleEtherpadResponse(res)) .catch((err) => { // pad is already there, just return the constructed pad path diff --git a/src/services/fileStorage/proxy-service.js b/src/services/fileStorage/proxy-service.js index fef6d96a1c7..66e3874afee 100644 --- a/src/services/fileStorage/proxy-service.js +++ b/src/services/fileStorage/proxy-service.js @@ -1,6 +1,6 @@ const fs = require('fs'); const url = require('url'); -const rp = require('request-promise-native'); +const axios = require('axios'); const { Configuration } = require('@hpi-schul-cloud/commons'); const { filesRepo } = require('../../components/fileStorage/repo'); @@ -29,10 +29,7 @@ const { sortRoles } = require('../role/utils/rolesHelper'); const { userModel } = require('../user/model'); const logger = require('../../logger'); const { equal: equalIds } = require('../../helper/compare').ObjectId; -const { - FILE_SECURITY_CHECK_MAX_FILE_SIZE, - SECURITY_CHECK_SERVICE_PATH, -} = require('../../../config/globals'); +const { FILE_SECURITY_CHECK_MAX_FILE_SIZE, SECURITY_CHECK_SERVICE_PATH } = require('../../../config/globals'); const AWSS3Strategy = require('./strategies/awsS3'); const sanitizeObj = (obj) => { @@ -110,20 +107,20 @@ const prepareSecurityCheck = async (file, userId, strategy) => { .then((signedUrl) => { const params = { url: Configuration.get('FILE_SECURITY_CHECK_SERVICE_URI'), + method: 'POST', auth: { user: Configuration.get('FILE_SECURITY_SERVICE_USERNAME'), pass: Configuration.get('FILE_SECURITY_SERVICE_PASSWORD'), }, - body: { + data: { download_uri: signedUrl, callback_uri: url.resolve( Configuration.get('API_HOST'), `${SECURITY_CHECK_SERVICE_PATH}${file.securityCheck.requestToken}` ), }, - json: true, }; - const send = rp.post(params); + const send = axios(params); return send; }); } @@ -775,10 +772,10 @@ const newFileService = { if (Configuration.get('REQUEST_OPTION__KEEP_ALIVE')) { headers.Connection = 'Keep-Alive'; } - return rp({ + return axios({ method: 'PUT', - uri: signedUrl.url, - body: buffer, + url: signedUrl.url, + data: buffer, headers, }); }) diff --git a/src/services/oauth2/hydra.js b/src/services/oauth2/hydra.js index 90feeaf526d..6565a1593eb 100644 --- a/src/services/oauth2/hydra.js +++ b/src/services/oauth2/hydra.js @@ -1,4 +1,4 @@ -const request = require('request-promise-native'); +const axios = require('axios'); const mockTlsTermination = { 'X-Forwarded-Proto': 'https', @@ -6,18 +6,19 @@ const mockTlsTermination = { module.exports = (hydraUrl) => { return { - introspectOAuth2Token: (token, scope) => { + introspectOAuth2Token: async (token, scope) => { const options = { - uri: `${hydraUrl}/oauth2/introspect`, + url: `${hydraUrl}/oauth2/introspect`, method: 'POST', - body: `token=${token}&scope=${scope}`, + data: `token=${token}&scope=${scope}`, headers: { ...mockTlsTermination, 'Content-Type': 'application/x-www-form-urlencoded', }, - json: true, }; - return request(options); + const res = await axios(options); + + return res.data; }, }; }; diff --git a/src/services/rocketChat/services/rocketChatChannel.js b/src/services/rocketChat/services/rocketChatChannel.js index bd74e4cd8fc..fda2c2adcd9 100644 --- a/src/services/rocketChat/services/rocketChatChannel.js +++ b/src/services/rocketChat/services/rocketChatChannel.js @@ -1,4 +1,3 @@ -const request = require('request-promise-native'); const { BadRequest } = require('../../../errors'); const { makeStringRCConform } = require('../helpers'); const { TEAM_FEATURES } = require('../../teams/model'); diff --git a/src/services/sync/strategies/TSP/TSP.js b/src/services/sync/strategies/TSP/TSP.js index d5af8097315..a0fb9177bea 100644 --- a/src/services/sync/strategies/TSP/TSP.js +++ b/src/services/sync/strategies/TSP/TSP.js @@ -1,4 +1,4 @@ -const rp = require('request-promise-native'); +const axios = require('axios'); const url = require('url'); const moment = require('moment'); const { JWE, JWK, JWS } = require('jose'); @@ -219,15 +219,16 @@ class TspApi { */ async request(path, lastChange = new Date(0)) { const lastChangeDate = moment(lastChange).format('YYYY-MM-DD HH:mm:ss.SSS'); - - const requestUrl = url.resolve(BASE_URL, path); - const response = await rp(requestUrl, { + const options = { + url: url.resolve(BASE_URL, path), headers: this.getHeaders(), - qs: { + params: { dtLetzteAenderung: lastChangeDate, }, - }); - return JSON.parse(response); + }; + const response = await axios(options); + + return response.data; } } diff --git a/src/services/wopi/index.js b/src/services/wopi/index.js index 880748b56a6..35c632f1845 100644 --- a/src/services/wopi/index.js +++ b/src/services/wopi/index.js @@ -2,7 +2,7 @@ /** * Provides a basic wopi - endpoint, https://wopirest.readthedocs.io/en/latest/index.html */ -const rp = require('request-promise-native'); +const axios = require('axios'); const { static: staticContent } = require('@feathersjs/express'); const path = require('path'); @@ -140,12 +140,14 @@ class WopiFilesContentsService { }) .then((signedUrl) => { const opt = { - uri: signedUrl.url, - encoding: null, + url: signedUrl.url, + responseType: 'arraybuffer', }; - return rp(opt).catch((err) => { - logger.warning(new Error(err)); - }); + return axios(opt) + .then((res) => res.data) + .catch((err) => { + logger.warning(new Error(err)); + }); }) .catch((err) => { logger.warning(new Error(err)); @@ -188,12 +190,11 @@ class WopiFilesContentsService { // put binary content directly to file in storage const options = { method: 'PUT', - uri: signedUrl.url, - contentType: file.type, - body: data, + url: signedUrl.url, + data, }; - return rp(options) + return axios(options) .then(() => FileModel.findOneAndUpdate( { _id: file._id },