├── .gitignore ├── errors.js ├── .npmignore ├── test ├── .eslintrc.json ├── fixtures │ ├── require │ │ ├── afterwards.js │ │ ├── beforehand.js │ │ └── beforehandAndAfterwards.js │ └── server.js └── spec │ └── request-test.js ├── .publishrc ├── .editorconfig ├── .travis.yml ├── lib └── rp.js ├── LICENSE ├── package.json ├── gulpfile.js ├── .eslintrc.json └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | /.idea/ 2 | /coverage/ 3 | /node_modules/ 4 | 5 | .DS_Store 6 | npm-debug.log -------------------------------------------------------------------------------- /errors.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = require('request-promise-core/errors'); 4 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | /.idea/ 2 | /coverage/ 3 | /test/ 4 | 5 | /.editorconfig 6 | /.eslintrc.json 7 | /.gitignore 8 | /.publishrc 9 | /.travis.yml 10 | /gulpfile.js 11 | 12 | .DS_Store 13 | npm-debug.log -------------------------------------------------------------------------------- /test/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "mocha": true 4 | }, 5 | "globals": { 6 | "expect": true 7 | }, 8 | "rules": { 9 | 10 | // Node.js and CommonJS 11 | 12 | "no-process-env": 0, 13 | "no-sync": 0 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /.publishrc: -------------------------------------------------------------------------------- 1 | { 2 | "validations": { 3 | "vulnerableDependencies": false, 4 | "uncommittedChanges": true, 5 | "untrackedFiles": true, 6 | "sensitiveData": true, 7 | "branch": "master", 8 | "gitTag": true 9 | }, 10 | "confirm": true, 11 | "publishTag": "latest", 12 | "prePublishScript": "npm run test-publish" 13 | } -------------------------------------------------------------------------------- /test/fixtures/require/afterwards.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var rp = require('../../../'); 4 | var request = require('request'); 5 | 6 | var rpHasThen = rp('http://localhost:4000/200').then !== undefined; 7 | var requestHasNoThen = request('http://localhost:4000/200').then === undefined; 8 | 9 | console.log('rp: ' + rpHasThen + ', request: ' + requestHasNoThen); 10 | -------------------------------------------------------------------------------- /test/fixtures/require/beforehand.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var request = require('request'); 4 | var rp = require('../../../'); 5 | 6 | var requestHasNoThen = request('http://localhost:4000/200').then === undefined; 7 | var rpHasThen = rp('http://localhost:4000/200').then !== undefined; 8 | 9 | console.log('request: ' + requestHasNoThen + ', rp: ' + rpHasThen); 10 | -------------------------------------------------------------------------------- /test/fixtures/require/beforehandAndAfterwards.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var request1 = require('request'); 4 | var rp = require('../../../'); 5 | var request2 = require('request'); 6 | 7 | var request1HasNoThen = request1('http://localhost:4000/200').then === undefined; 8 | var rpHasThen = rp('http://localhost:4000/200').then !== undefined; 9 | var request2IsIdenticalToRequest1 = request2 === request1; 10 | 11 | console.log('request1: ' + request1HasNoThen + ', rp: ' + rpHasThen + ', request2: ' + request2IsIdenticalToRequest1); 12 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome: http://EditorConfig.org 2 | 3 | root = true 4 | 5 | [*] 6 | charset = utf-8 7 | end_of_line = lf 8 | 9 | [*.js] 10 | indent_style = space 11 | indent_size = 4 12 | trim_trailing_whitespace = true 13 | insert_final_newline = true 14 | 15 | [*.{json,xml}] 16 | indent_style = space 17 | indent_size = 2 18 | trim_trailing_whitespace = true 19 | insert_final_newline = true 20 | 21 | [*.{md,txt}] 22 | indent_style = space 23 | indent_size = 4 24 | trim_trailing_whitespace = false 25 | insert_final_newline = false -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | sudo: false 3 | 4 | matrix: 5 | include: 6 | - node_js: "0.10" 7 | env: V_REQUEST=2.76.0 8 | - node_js: "0.12" 9 | env: V_REQUEST=2.76.0 10 | - node_js: "iojs" 11 | env: V_REQUEST=2.76.0 12 | - node_js: "4" 13 | env: V_REQUEST=latest 14 | - node_js: "6" 15 | env: V_REQUEST=latest 16 | - node_js: "8" 17 | env: V_REQUEST=latest 18 | - node_js: "10" 19 | env: V_REQUEST=latest 20 | 21 | before_install: 22 | - npm install tough-cookie 23 | - npm install request@$V_REQUEST 24 | 25 | install: npm install 26 | -------------------------------------------------------------------------------- /lib/rp.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var AnyPromise = require('any-promise'), 4 | configure = require('request-promise-core/configure/request2'), 5 | stealthyRequire = require('stealthy-require'); 6 | 7 | // Load Request freshly - so that users can require an unaltered request instance! 8 | var request = stealthyRequire(require.cache, function () { 9 | return require('request'); 10 | }, 11 | function () { 12 | require('tough-cookie'); 13 | }, module); 14 | 15 | 16 | configure({ 17 | request: request, 18 | PromiseImpl: AnyPromise, 19 | expose: [ 20 | 'then', 21 | 'catch', 22 | 'promise' 23 | ] 24 | }); 25 | 26 | 27 | module.exports = request; 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | ISC License 2 | 3 | Copyright (c) 2020, Nicolai Kamenzky and contributors 4 | 5 | Permission to use, copy, modify, and/or distribute this software for any 6 | purpose with or without fee is hereby granted, provided that the above 7 | copyright notice and this permission notice appear in all copies. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -------------------------------------------------------------------------------- /test/fixtures/server.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var bodyParser = require('body-parser'); 4 | var http = require('http'); 5 | var url = require('url'); 6 | 7 | 8 | module.exports = function startServer(port, cb) { 9 | 10 | var server = http.createServer(function (req, res) { 11 | 12 | bodyParser.json()(req, res, function () { 13 | 14 | var path = url.parse(req.url).pathname; 15 | var status = Number(path.split('?')[0].split('/')[1]); 16 | 17 | switch (status) { 18 | case 301: 19 | res.writeHead(301, { Location: '/200' }); 20 | res.end(); 21 | break; 22 | default: 23 | res.writeHead(status, {'Content-Type': 'text/plain'}); 24 | var body = req.method === 'POST' ? ' - ' + JSON.stringify(req.body) : ''; 25 | res.end(req.method + ' ' + path + body); 26 | } 27 | 28 | }); 29 | 30 | }); 31 | 32 | server.listen(port, function () { 33 | 34 | cb(function stopServer(done) { 35 | // Wait for all requests to finish since they may produce unhandled errors for tests at the end that don't wait themselves. 36 | setTimeout(function () { 37 | server.close(); 38 | done(); 39 | }, 20); 40 | }); 41 | 42 | }); 43 | 44 | }; 45 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "request-promise-any", 3 | "version": "1.0.9", 4 | "description": "The simplified HTTP request client 'request' with Promise support. Powered by 'any-promise'.", 5 | "keywords": [ 6 | "xhr", 7 | "http", 8 | "https", 9 | "promise", 10 | "request", 11 | "then", 12 | "thenable", 13 | "any", 14 | "any-promise" 15 | ], 16 | "main": "./lib/rp.js", 17 | "scripts": { 18 | "test": "./node_modules/.bin/gulp ci", 19 | "test-publish": "./node_modules/.bin/gulp ci-no-cov", 20 | "publish-please": "publish-please", 21 | "prepublish": "publish-please guard" 22 | }, 23 | "repository": { 24 | "type": "git", 25 | "url": "git+https://github.com/request/request-promise-any.git" 26 | }, 27 | "author": "Nicolai Kamenzky (https://github.com/analog-nico)", 28 | "license": "ISC", 29 | "bugs": { 30 | "url": "https://github.com/request/request-promise-any/issues" 31 | }, 32 | "homepage": "https://github.com/request/request-promise-any#readme", 33 | "engines": { 34 | "node": ">=0.10.0" 35 | }, 36 | "dependencies": { 37 | "request-promise-core": "1.1.4", 38 | "any-promise": "^1.0.0", 39 | "stealthy-require": "^1.1.1", 40 | "tough-cookie": "^2.3.3" 41 | }, 42 | "peerDependencies": { 43 | "request": "^2.34" 44 | }, 45 | "devDependencies": { 46 | "body-parser": "~1.15.2", 47 | "chai": "~3.5.0", 48 | "chalk": "~1.1.3", 49 | "gulp": "~3.9.1", 50 | "gulp-coveralls": "~0.1.4", 51 | "gulp-eslint": "~2.1.0", 52 | "gulp-istanbul": "~1.0.0", 53 | "gulp-mocha": "~2.2.0", 54 | "lodash": "~4.13.1", 55 | "publish-please": "~2.1.4", 56 | "q": "~1.4.1", 57 | "request": "^2.34.0", 58 | "rimraf": "~2.5.3", 59 | "run-sequence": "~1.2.2" 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var gulp = require('gulp'); 4 | var runSequence = require('run-sequence'); 5 | var istanbul = require('gulp-istanbul'); 6 | var mocha = require('gulp-mocha'); 7 | var chalk = require('chalk'); 8 | var rimraf = require('rimraf'); 9 | var coveralls = require('gulp-coveralls'); 10 | var eslint = require('gulp-eslint'); 11 | var _ = require('lodash'); 12 | 13 | var chai = require('chai'); 14 | global.expect = chai.expect; 15 | 16 | 17 | var paths = { 18 | libJsFiles: ['./lib/**/*.js', './errors.js'], 19 | specFiles: './test/spec/**/*.js', 20 | fixtureFiles: './test/fixtures/**/*.js', 21 | gulpfile: './gulpfile.js', 22 | eslintrc: './.eslintrc.json' 23 | }; 24 | 25 | 26 | gulp.task('dev', ['watch', 'validate']); 27 | 28 | gulp.task('watch', function () { 29 | 30 | gulp.watch(_.flatten([ 31 | paths.libJsFiles, 32 | paths.specFiles, 33 | paths.fixtureFiles, 34 | paths.gulpfile 35 | ]), [ 36 | 'validate' 37 | ]); 38 | 39 | gulp.watch(_.flatten([ 40 | paths.eslintrc 41 | ]), [ 42 | 'lint' 43 | ]); 44 | 45 | }); 46 | 47 | gulp.task('validate', function (done) { 48 | runSequence('lint', 'test', done); 49 | }); 50 | 51 | gulp.task('lint', function () { 52 | 53 | return gulp.src(_.flatten([ 54 | paths.libJsFiles, 55 | paths.gulpfile, 56 | paths.specFiles, 57 | paths.fixtureFiles, 58 | paths.gulpfile 59 | ])) 60 | .pipe(eslint()) 61 | .pipe(eslint.format()) 62 | .pipe(eslint.failAfterError()); 63 | 64 | }); 65 | 66 | gulp.task('test', ['clean'], function (done) { 67 | 68 | var coverageVariable = '$$cov_' + new Date().getTime() + '$$'; 69 | 70 | gulp.src(paths.libJsFiles) 71 | .pipe(istanbul({ 72 | coverageVariable: coverageVariable 73 | })) 74 | .pipe(istanbul.hookRequire()) 75 | .on('finish', function () { 76 | 77 | gulp.src(paths.specFiles) 78 | .pipe(mocha()) 79 | .on('error', function (err) { 80 | console.error(String(err)); 81 | console.error(chalk.bold.bgRed(' TESTS FAILED ')); 82 | done(new Error(' TESTS FAILED ')); 83 | }) 84 | .pipe(istanbul.writeReports({ 85 | reporters: ['lcov'], 86 | coverageVariable: coverageVariable 87 | })) 88 | .on('end', done); 89 | 90 | }); 91 | 92 | }); 93 | 94 | gulp.task('test-without-coverage', function () { 95 | 96 | return gulp.src(paths.specFiles) 97 | .pipe(mocha()) 98 | .on('error', function () { 99 | console.log(chalk.bold.bgRed(' TESTS FAILED ')); 100 | }); 101 | 102 | }); 103 | 104 | gulp.task('clean', ['clean-coverage']); 105 | 106 | gulp.task('clean-coverage', function (done) { 107 | rimraf('./coverage', done); 108 | }); 109 | 110 | gulp.task('ci', function (done) { 111 | runSequence('validate', 'coveralls', 'test-without-coverage', done); 112 | }); 113 | 114 | gulp.task('ci-no-cov', function (done) { 115 | runSequence('validate', 'test-without-coverage', done); 116 | }); 117 | 118 | gulp.task('coveralls', function () { 119 | return gulp.src('coverage/**/lcov.info') 120 | .pipe(coveralls()); 121 | }); 122 | -------------------------------------------------------------------------------- /test/spec/request-test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | require('any-promise/register/q'); 4 | 5 | var childProcess = require('child_process'), 6 | errors = require('../../errors'), 7 | path = require('path'), 8 | Q = require('q'), 9 | rp = require('../../'), 10 | tough = require('tough-cookie'), 11 | startServer = require('../fixtures/server.js'); 12 | 13 | 14 | describe('Request-Promise-Any', function () { 15 | 16 | var stopServer = null; 17 | 18 | before(function (done) { 19 | 20 | startServer(4000, function (stop) { 21 | stopServer = stop; 22 | done(); 23 | }); 24 | 25 | }); 26 | 27 | after(function (done) { 28 | 29 | stopServer(done); 30 | 31 | }); 32 | 33 | describe('should expose', function () { 34 | 35 | it('.then(...)', function (done) { 36 | 37 | rp('http://localhost:4000/200') 38 | .then(function (body) { 39 | expect(body).to.eql('GET /200'); 40 | done(); 41 | }) 42 | .catch(function (err) { 43 | done(err); 44 | }); 45 | 46 | }); 47 | 48 | it('.catch(...) and the error types', function (done) { 49 | 50 | rp('http://localhost:4000/404') 51 | .catch(function (err) { 52 | expect(err instanceof errors.StatusCodeError).to.eql(true); 53 | return 'catch called'; 54 | }) 55 | .then(function (info) { 56 | expect(info).to.eql('catch called'); 57 | done(); 58 | }) 59 | .catch(function (err) { 60 | done(err); 61 | }); 62 | 63 | }); 64 | 65 | it('.promise() returning a Q promise', function () { 66 | 67 | var p = rp('http://localhost:4000/200').promise(); 68 | 69 | // expect(Q.isPromise(p)).to.eql(true); // <-- Fails. Whatever... 70 | expect(Q.isPromiseAlike(p)).to.eql(true); 71 | 72 | }); 73 | 74 | }); 75 | 76 | describe('should still allow to require Request independently', function () { 77 | 78 | it('by not interfering with Request required afterwards', function (done) { 79 | 80 | childProcess.exec('node ' + path.join(__dirname, '../fixtures/require/afterwards.js'), function (err, stdout, stderr) { 81 | 82 | if (err) { 83 | done(err); 84 | return; 85 | } 86 | 87 | try { 88 | expect(stdout, 'Actual stdout: ' + stdout).to.contain('rp: true, request: true'); 89 | done(); 90 | } catch (e) { 91 | done(e); 92 | } 93 | 94 | }); 95 | 96 | }); 97 | 98 | it('by not interfering with Request required beforehand', function (done) { 99 | 100 | childProcess.exec('node ' + path.join(__dirname, '../fixtures/require/beforehand.js'), function (err, stdout, stderr) { 101 | 102 | if (err) { 103 | done(err); 104 | return; 105 | } 106 | 107 | try { 108 | expect(stdout, 'Actual stdout: ' + stdout).to.contain('request: true, rp: true'); 109 | done(); 110 | } catch (e) { 111 | done(e); 112 | } 113 | 114 | }); 115 | 116 | }); 117 | 118 | it('by not interfering with Request required beforehand and afterwards being identical', function (done) { 119 | 120 | childProcess.exec('node ' + path.join(__dirname, '../fixtures/require/beforehandAndAfterwards.js'), function (err, stdout, stderr) { 121 | 122 | if (err) { 123 | done(err); 124 | return; 125 | } 126 | 127 | try { 128 | expect(stdout, 'Actual stdout: ' + stdout).to.contain('request1: true, rp: true, request2: true'); 129 | done(); 130 | } catch (e) { 131 | done(e); 132 | } 133 | 134 | }); 135 | 136 | }); 137 | 138 | }); 139 | 140 | it('should allow the use of tough-cookie - issue request-promise#183', function () { 141 | 142 | var sessionCookie = new tough.Cookie({ 143 | key: 'some_key', 144 | value: 'some_value', 145 | domain: 'api.mydomain.com', 146 | httpOnly: true, 147 | maxAge: 31536000 148 | }); 149 | 150 | var cookiejar = rp.jar(); 151 | 152 | expect(function () { 153 | cookiejar.setCookie(sessionCookie.toString(), 'https://api.mydomain.com'); 154 | }).to.not.throw(); 155 | 156 | }); 157 | 158 | }); 159 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | "parser": "espree", 4 | "parserOptions": { 5 | "ecmaVersion": 5, 6 | "sourceType": "script", 7 | "ecmaFeatures": {} 8 | }, 9 | "plugins": [], 10 | "env": { 11 | "node": true 12 | }, 13 | "globals": {}, 14 | "rules": { 15 | 16 | // Possible Errors (fully reviewed 2016-07-05) 17 | 18 | "no-cond-assign": 2, 19 | "no-console": 0, 20 | "no-constant-condition": 2, 21 | "no-control-regex": 2, 22 | "no-debugger": 2, 23 | "no-dupe-args": 2, 24 | "no-dupe-keys": 2, 25 | "no-duplicate-case": 2, 26 | "no-empty": [2, { "allowEmptyCatch": false }], 27 | "no-empty-character-class": 2, 28 | "no-ex-assign": 2, 29 | "no-extra-boolean-cast": 2, 30 | "no-extra-parens": [2, "all"], 31 | "no-extra-semi": 2, 32 | "no-func-assign": 2, 33 | "no-inner-declarations": [2, "functions"], 34 | "no-invalid-regexp": 2, 35 | "no-irregular-whitespace": [2, { "skipComments": false }], 36 | "no-negated-in-lhs": 2, 37 | "no-obj-calls": 2, 38 | "no-prototype-builtins": 2, 39 | "no-regex-spaces": 2, 40 | "no-sparse-arrays": 2, 41 | "no-unexpected-multiline": 2, 42 | "no-unreachable": 2, 43 | "no-unsafe-finally": 2, 44 | "use-isnan": 2, 45 | "valid-jsdoc": 0, 46 | "valid-typeof": 2, 47 | 48 | // Best Practices 49 | 50 | "accessor-pairs": 2, 51 | "curly": [2, "multi-line"], 52 | "dot-location": [2, "property"], 53 | "eqeqeq": 2, 54 | "no-caller": 2, 55 | "no-empty-pattern": 0, // for ES6 destructuring 56 | "no-eval": 2, 57 | "no-extend-native": 2, 58 | "no-extra-bind": 2, 59 | "no-fallthrough": 2, 60 | "no-floating-decimal": 2, 61 | "no-implied-eval": 2, 62 | "no-iterator": 2, 63 | "no-labels": 2, 64 | "no-lone-blocks": 2, 65 | "no-magic-numbers": 0, 66 | "no-multi-spaces": 2, 67 | "no-multi-str": 2, 68 | "no-native-reassign": 2, 69 | "no-new": 2, 70 | "no-new-func": 2, 71 | "no-new-wrappers": 2, 72 | "no-octal": 2, 73 | "no-octal-escape": 2, 74 | "no-proto": 2, 75 | "no-redeclare": 2, 76 | "no-return-assign": [2, "except-parens"], 77 | "no-self-assign": 2, 78 | "no-self-compare": 2, 79 | "no-sequences": 2, 80 | "no-throw-literal": 2, 81 | "no-unmodified-loop-condition": 2, 82 | "no-useless-call": 2, 83 | "no-useless-escape": 2, 84 | "no-with": 2, 85 | "wrap-iife": [2, "inside"], 86 | "yoda": 2, 87 | 88 | // Strict Mode (fully reviewed 2016-07-05) 89 | 90 | "strict": [2, "safe"], 91 | 92 | // Variables (fully reviewed 2016-07-05) 93 | 94 | "init-declarations": [2, "always"], 95 | "no-catch-shadow": 0, 96 | "no-delete-var": 2, 97 | "no-label-var": 2, 98 | "no-restricted-globals": 0, 99 | "no-shadow": [2, { "builtinGlobals": false, "hoist": "all", "allow": [] }], 100 | "no-shadow-restricted-names": 2, 101 | "no-undef": [2, { "typeof": true }], 102 | "no-undef-init": 2, 103 | "no-undefined": 0, 104 | "no-unused-vars": [2, { "vars": "local", "args": "none", "caughtErrors": "none" }], 105 | "no-use-before-define": [2, { "functions": false, "classes": true }], 106 | 107 | // Node.js and CommonJS (fully reviewed 2016-07-05) 108 | 109 | "callback-return": 0, 110 | "global-require": 0, 111 | "handle-callback-err": [2, "^(err|error)$" ], 112 | "no-mixed-requires": 0, 113 | "no-new-require": 2, 114 | "no-path-concat": 2, 115 | "no-process-env": 2, 116 | "no-process-exit": 2, 117 | "no-restricted-modules": 0, 118 | "no-sync": 2, 119 | 120 | // Stylistic Issues 121 | 122 | "block-spacing": 2, 123 | "brace-style": [2, "1tbs", { "allowSingleLine": true }], 124 | "camelcase": [2, { "properties": "never" }], 125 | "comma-dangle": [2, "never"], 126 | "comma-spacing": 2, 127 | "comma-style": 2, 128 | "eol-last": 2, 129 | "indent": [2, 4, { "SwitchCase": 1 }], 130 | "jsx-quotes": 0, 131 | "key-spacing": 2, 132 | "keyword-spacing": 2, 133 | "new-cap": 0, 134 | "new-parens": 2, 135 | "no-array-constructor": 2, 136 | "no-mixed-spaces-and-tabs": 2, 137 | "no-multiple-empty-lines": [2, { "max": 2, "maxBOF": 0, "maxEOF": 1 }], 138 | "no-new-object": 2, 139 | "no-plusplus": [2, { "allowForLoopAfterthoughts": false }], 140 | "no-spaced-func": 2, 141 | "no-trailing-spaces": 2, 142 | "no-unneeded-ternary": [2, { "defaultAssignment": false }], 143 | "no-whitespace-before-property": 2, 144 | "one-var": 0, 145 | "operator-linebreak": [2, "after", { "overrides": { "?": "before", ":": "before" } }], 146 | "padded-blocks": 0, 147 | "quotes": [2, "single", "avoid-escape"], 148 | "semi": [2, "always"], 149 | "semi-spacing": 2, 150 | "space-before-blocks": 2, 151 | "space-before-function-paren": [2, {"anonymous": "always", "named": "never"}], 152 | "space-in-parens": 0, 153 | "space-infix-ops": 0, 154 | "space-unary-ops": 2, 155 | "spaced-comment": 0 156 | 157 | } 158 | } 159 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | Promises/A+ logo 3 | 4 | 5 | # Request-Promise-Any 6 | 7 | [![Gitter](https://img.shields.io/badge/gitter-join_chat-blue.svg?style=flat-square&maxAge=2592000)](https://gitter.im/request/request-promise?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 8 | [![Build Status](https://img.shields.io/travis/request/request-promise-any/master.svg?style=flat-square&maxAge=2592000)](https://travis-ci.org/request/request-promise-any) 9 | [![Coverage Status](https://img.shields.io/coveralls/request/request-promise-any.svg?style=flat-square&maxAge=2592000)](https://coveralls.io/r/request/request-promise-any) 10 | [![Dependency Status](https://img.shields.io/david/request/request-promise-any.svg?style=flat-square&maxAge=2592000)](https://david-dm.org/request/request-promise-any) 11 | [![Known Vulnerabilities](https://snyk.io/test/npm/request-promise-any/badge.svg?style=flat-square&maxAge=2592000)](https://snyk.io/test/npm/request-promise-any) 12 | 13 | # Deprecated! 14 | 15 | As of Feb 11th 2020, [`request`](https://github.com/request/request) is fully deprecated. No new changes are expected to land. In fact, none have landed for some time. This package is also deprecated because it depends on `request`. 16 | 17 | Fyi, here is the [reasoning of `request`'s deprecation](https://github.com/request/request/issues/3142) and a [list of alternative libraries](https://github.com/request/request/issues/3143). 18 | 19 | --- 20 | 21 | This package is similar to [`request-promise`](https://www.npmjs.com/package/request-promise) but uses [`any-promise`](https://www.npmjs.com/package/any-promise) to let the user choose which Promise library to use. 22 | 23 | Please refer to the [`request-promise` documentation](https://www.npmjs.com/package/request-promise). Everything applies to `request-promise-any` except the following: 24 | - Instead of using Bluebird promises this library uses the Promise library chosen by the user. 25 | - This library has to work with the API that all supported Promise libraries have in common. And that is the API of native ES6 promises. Mind that they have less features than Bluebird promises. In particular, the `.finally(...)` method is not available. 26 | 27 | ## Installation 28 | 29 | This module is installed via npm: 30 | 31 | ``` 32 | npm install --save request 33 | npm install --save request-promise-any 34 | ``` 35 | 36 | `request` is defined as a peer-dependency and thus has to be installed separately. 37 | 38 | ## Registering Your Preferred Promise Library 39 | 40 | First, install your preferred Promise library. E.g. [Q](https://www.npmjs.com/package/q): 41 | 42 | ``` 43 | npm install --save q 44 | ``` 45 | 46 | Then, register the Promise library before you require `request-promise-any` for the first time: 47 | 48 | ``` js 49 | require('any-promise/register/q') 50 | 51 | var rp = require('request-promise-any') 52 | ``` 53 | 54 | For a list of supported Promise libraries and advanced registration features read the [documentation of `any-promise`](https://github.com/kevinbeaty/any-promise). 55 | 56 | ## Migration from `request-promise` to `request-promise-any` 57 | 58 | 1. Go through the [migration instructions](https://github.com/request/request-promise#migration-from-v3-to-v4) to upgrade to `request-promise` v4. 59 | 2. Ensure that you don't use Bluebird-specific features on the promise returned by your request calls. In particular, you can't use `.finally(...)` anymore. 60 | 3. Follow the registration instructions above. 61 | 4. You are done. 62 | 63 | ## Contributing 64 | 65 | To set up your development environment: 66 | 67 | 1. clone the repo to your desktop, 68 | 2. in the shell `cd` to the main folder, 69 | 3. hit `npm install`, 70 | 4. hit `npm install gulp -g` if you haven't installed gulp globally yet, and 71 | 5. run `gulp dev`. (Or run `node ./node_modules/.bin/gulp dev` if you don't want to install gulp globally.) 72 | 73 | `gulp dev` watches all source files and if you save some changes it will lint the code and execute all tests. The test coverage report can be viewed from `./coverage/lcov-report/index.html`. 74 | 75 | If you want to debug a test you should use `gulp test-without-coverage` to run all tests without obscuring the code by the test coverage instrumentation. 76 | 77 | ## Change History 78 | 79 | - v1.0.9 (2020-07-21) 80 | - Security fix: bumped `request-promise-core` which bumps `lodash` to `^4.17.19` following [this advisory](https://www.npmjs.com/advisories/1523). 81 | - v1.0.8 (2019-11-03) 82 | - Security fix: bumped `request-promise-core` which bumps `lodash` to `^4.17.15`. See [vulnerabilty reports](https://snyk.io/vuln/search?q=lodash&type=npm). 83 | *(Thanks to @aw-davidson for reporting this in issue [#49](https://github.com/request/request-promise-native/issues/49).)* 84 | - v1.0.7 (2019-02-14) 85 | - Corrected mistakenly set `tough-cookie` version, now `^2.3.3` 86 | *(Thanks to @evocateur for pointing this out.)* 87 | - If you installed `request-promise-any@1.0.6` please make sure after the upgrade that `request` and `request-promise-any` use the same physical copy of `tough-cookie`. 88 | - v1.0.6 (2019-02-14) 89 | - Using stricter `tough-cookie@~2.3.3` to avoid installing `tough-cookie@3` which introduces breaking changes 90 | - Security fix: bumped `lodash` to `^4.17.11`, see [vulnerabilty reports](https://snyk.io/vuln/search?q=lodash&type=npm) 91 | - v1.0.5 (2017-09-22) 92 | - Upgraded `tough-cookie` to a version without regex DoS vulnerability 93 | *(Thanks to @rouanw and @sophieklm for their pull requests [request-promise#226](https://github.com/request/request-promise/pull/226) and [request-promise-native#13](https://github.com/request/request-promise-native/pull/13))* 94 | - v1.0.4 (2017-05-07) 95 | - Fix that allows to use `tough-cookie` for [cookie creation](https://github.com/request/request-promise#include-a-cookie) 96 | - v1.0.3 (2016-08-08) 97 | - Renamed internally used package `@request/promise-core` to `request-promise-core` because there where [too](https://github.com/request/request-promise/issues/137) [many](https://github.com/request/request-promise/issues/141) issues with the scoped package name 98 | - v1.0.2 (2016-07-18) 99 | - Fix for using with module bundlers like Webpack and Browserify 100 | - v1.0.1 (2016-07-17) 101 | - Fixed `@request/promise-core` version for safer versioning 102 | - v1.0.0 (2016-07-15) 103 | - Initial version similar to [`request-promise`](https://www.npmjs.com/package/request-promise) v4 104 | 105 | ## License (ISC) 106 | 107 | In case you never heard about the [ISC license](http://en.wikipedia.org/wiki/ISC_license) it is functionally equivalent to the MIT license. 108 | 109 | See the [LICENSE file](LICENSE) for details. 110 | --------------------------------------------------------------------------------