Initial commit
This commit is contained in:
15
node_modules/request-promise-core/LICENSE
generated
vendored
Normal file
15
node_modules/request-promise-core/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2016, Nicolai Kamenzky and contributors
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
67
node_modules/request-promise-core/configure/request-next.js
generated
vendored
Normal file
67
node_modules/request-promise-core/configure/request-next.js
generated
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
'use strict';
|
||||
|
||||
var core = require('../'),
|
||||
isArray = require('lodash/isArray'),
|
||||
isFunction = require('lodash/isFunction'),
|
||||
isObjectLike = require('lodash/isObjectLike');
|
||||
|
||||
|
||||
module.exports = function (options) {
|
||||
|
||||
var errorText = 'Please verify options'; // For better minification because this string is repeating
|
||||
|
||||
if (!isObjectLike(options)) {
|
||||
throw new TypeError(errorText);
|
||||
}
|
||||
|
||||
if (!isFunction(options.client)) {
|
||||
throw new TypeError(errorText + '.client');
|
||||
}
|
||||
|
||||
if (!isArray(options.expose) || options.expose.length === 0) {
|
||||
throw new TypeError(errorText + '.expose');
|
||||
}
|
||||
|
||||
var thenExposed = false;
|
||||
for ( var i = 0; i < options.expose.length; i+=1 ) {
|
||||
if (options.expose[i] === 'then') {
|
||||
thenExposed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!thenExposed) {
|
||||
throw new Error('Please expose "then"');
|
||||
}
|
||||
|
||||
|
||||
var plumbing = core({
|
||||
PromiseImpl: options.PromiseImpl,
|
||||
constructorMixin: options.constructorMixin
|
||||
});
|
||||
|
||||
return function (requestOptions) {
|
||||
|
||||
var self = {};
|
||||
|
||||
plumbing.init.call(self, requestOptions);
|
||||
|
||||
var request = options.client(requestOptions);
|
||||
|
||||
for ( var k = 0; k < options.expose.length; k+=1 ) {
|
||||
|
||||
var method = options.expose[k];
|
||||
|
||||
plumbing[ method === 'promise' ? 'exposePromise' : 'exposePromiseMethod' ](
|
||||
request,
|
||||
self,
|
||||
'_rp_promise',
|
||||
method
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
return request;
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
74
node_modules/request-promise-core/configure/request2.js
generated
vendored
Normal file
74
node_modules/request-promise-core/configure/request2.js
generated
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
'use strict';
|
||||
|
||||
var core = require('../'),
|
||||
isArray = require('lodash/isArray'),
|
||||
isFunction = require('lodash/isFunction'),
|
||||
isObjectLike = require('lodash/isObjectLike');
|
||||
|
||||
|
||||
module.exports = function (options) {
|
||||
|
||||
var errorText = 'Please verify options'; // For better minification because this string is repeating
|
||||
|
||||
if (!isObjectLike(options)) {
|
||||
throw new TypeError(errorText);
|
||||
}
|
||||
|
||||
if (!isFunction(options.request)) {
|
||||
throw new TypeError(errorText + '.request');
|
||||
}
|
||||
|
||||
if (!isArray(options.expose) || options.expose.length === 0) {
|
||||
throw new TypeError(errorText + '.expose');
|
||||
}
|
||||
|
||||
|
||||
var plumbing = core({
|
||||
PromiseImpl: options.PromiseImpl,
|
||||
constructorMixin: options.constructorMixin
|
||||
});
|
||||
|
||||
|
||||
// Intercepting Request's init method
|
||||
|
||||
var originalInit = options.request.Request.prototype.init;
|
||||
|
||||
options.request.Request.prototype.init = function RP$initInterceptor(requestOptions) {
|
||||
|
||||
// Init may be called again - currently in case of redirects
|
||||
if (isObjectLike(requestOptions) && !this._callback && !this._rp_promise) {
|
||||
|
||||
plumbing.init.call(this, requestOptions);
|
||||
|
||||
}
|
||||
|
||||
return originalInit.apply(this, arguments);
|
||||
|
||||
};
|
||||
|
||||
|
||||
// Exposing the Promise capabilities
|
||||
|
||||
var thenExposed = false;
|
||||
for ( var i = 0; i < options.expose.length; i+=1 ) {
|
||||
|
||||
var method = options.expose[i];
|
||||
|
||||
plumbing[ method === 'promise' ? 'exposePromise' : 'exposePromiseMethod' ](
|
||||
options.request.Request.prototype,
|
||||
null,
|
||||
'_rp_promise',
|
||||
method
|
||||
);
|
||||
|
||||
if (method === 'then') {
|
||||
thenExposed = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!thenExposed) {
|
||||
throw new Error('Please expose "then"');
|
||||
}
|
||||
|
||||
};
|
||||
3
node_modules/request-promise-core/errors.js
generated
vendored
Normal file
3
node_modules/request-promise-core/errors.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = require('./lib/errors.js');
|
||||
62
node_modules/request-promise-core/lib/errors.js
generated
vendored
Normal file
62
node_modules/request-promise-core/lib/errors.js
generated
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
'use strict';
|
||||
|
||||
|
||||
function RequestError(cause, options, response) {
|
||||
|
||||
this.name = 'RequestError';
|
||||
this.message = String(cause);
|
||||
this.cause = cause;
|
||||
this.error = cause; // legacy attribute
|
||||
this.options = options;
|
||||
this.response = response;
|
||||
|
||||
if (Error.captureStackTrace) { // required for non-V8 environments
|
||||
Error.captureStackTrace(this);
|
||||
}
|
||||
|
||||
}
|
||||
RequestError.prototype = Object.create(Error.prototype);
|
||||
RequestError.prototype.constructor = RequestError;
|
||||
|
||||
|
||||
function StatusCodeError(statusCode, body, options, response) {
|
||||
|
||||
this.name = 'StatusCodeError';
|
||||
this.statusCode = statusCode;
|
||||
this.message = statusCode + ' - ' + (JSON && JSON.stringify ? JSON.stringify(body) : body);
|
||||
this.error = body; // legacy attribute
|
||||
this.options = options;
|
||||
this.response = response;
|
||||
|
||||
if (Error.captureStackTrace) { // required for non-V8 environments
|
||||
Error.captureStackTrace(this);
|
||||
}
|
||||
|
||||
}
|
||||
StatusCodeError.prototype = Object.create(Error.prototype);
|
||||
StatusCodeError.prototype.constructor = StatusCodeError;
|
||||
|
||||
|
||||
function TransformError(cause, options, response) {
|
||||
|
||||
this.name = 'TransformError';
|
||||
this.message = String(cause);
|
||||
this.cause = cause;
|
||||
this.error = cause; // legacy attribute
|
||||
this.options = options;
|
||||
this.response = response;
|
||||
|
||||
if (Error.captureStackTrace) { // required for non-V8 environments
|
||||
Error.captureStackTrace(this);
|
||||
}
|
||||
|
||||
}
|
||||
TransformError.prototype = Object.create(Error.prototype);
|
||||
TransformError.prototype.constructor = TransformError;
|
||||
|
||||
|
||||
module.exports = {
|
||||
RequestError: RequestError,
|
||||
StatusCodeError: StatusCodeError,
|
||||
TransformError: TransformError
|
||||
};
|
||||
167
node_modules/request-promise-core/lib/plumbing.js
generated
vendored
Normal file
167
node_modules/request-promise-core/lib/plumbing.js
generated
vendored
Normal file
@@ -0,0 +1,167 @@
|
||||
'use strict';
|
||||
|
||||
var errors = require('./errors.js'),
|
||||
isFunction = require('lodash/isFunction'),
|
||||
isObjectLike = require('lodash/isObjectLike'),
|
||||
isString = require('lodash/isString'),
|
||||
isUndefined = require('lodash/isUndefined');
|
||||
|
||||
|
||||
module.exports = function (options) {
|
||||
|
||||
var errorText = 'Please verify options'; // For better minification because this string is repeating
|
||||
|
||||
if (!isObjectLike(options)) {
|
||||
throw new TypeError(errorText);
|
||||
}
|
||||
|
||||
if (!isFunction(options.PromiseImpl)) {
|
||||
throw new TypeError(errorText + '.PromiseImpl');
|
||||
}
|
||||
|
||||
if (!isUndefined(options.constructorMixin) && !isFunction(options.constructorMixin)) {
|
||||
throw new TypeError(errorText + '.PromiseImpl');
|
||||
}
|
||||
|
||||
var PromiseImpl = options.PromiseImpl;
|
||||
var constructorMixin = options.constructorMixin;
|
||||
|
||||
|
||||
var plumbing = {};
|
||||
|
||||
plumbing.init = function (requestOptions) {
|
||||
|
||||
var self = this;
|
||||
|
||||
self._rp_promise = new PromiseImpl(function (resolve, reject) {
|
||||
self._rp_resolve = resolve;
|
||||
self._rp_reject = reject;
|
||||
if (constructorMixin) {
|
||||
constructorMixin.apply(self, arguments); // Using arguments since specific Promise libraries may pass additional parameters
|
||||
}
|
||||
});
|
||||
|
||||
self._rp_callbackOrig = requestOptions.callback;
|
||||
requestOptions.callback = self.callback = function RP$callback(err, response, body) {
|
||||
plumbing.callback.call(self, err, response, body);
|
||||
};
|
||||
|
||||
if (isString(requestOptions.method)) {
|
||||
requestOptions.method = requestOptions.method.toUpperCase();
|
||||
}
|
||||
|
||||
requestOptions.transform = requestOptions.transform || plumbing.defaultTransformations[requestOptions.method];
|
||||
|
||||
self._rp_options = requestOptions;
|
||||
self._rp_options.simple = requestOptions.simple !== false;
|
||||
self._rp_options.resolveWithFullResponse = requestOptions.resolveWithFullResponse === true;
|
||||
self._rp_options.transform2xxOnly = requestOptions.transform2xxOnly === true;
|
||||
|
||||
};
|
||||
|
||||
plumbing.defaultTransformations = {
|
||||
HEAD: function (body, response, resolveWithFullResponse) {
|
||||
return resolveWithFullResponse ? response : response.headers;
|
||||
}
|
||||
};
|
||||
|
||||
plumbing.callback = function (err, response, body) {
|
||||
|
||||
var self = this;
|
||||
|
||||
var origCallbackThrewException = false, thrownException = null;
|
||||
|
||||
if (isFunction(self._rp_callbackOrig)) {
|
||||
try {
|
||||
self._rp_callbackOrig.apply(self, arguments); // TODO: Apply to self mimics behavior of request@2. Is that also right for request@next?
|
||||
} catch (e) {
|
||||
origCallbackThrewException = true;
|
||||
thrownException = e;
|
||||
}
|
||||
}
|
||||
|
||||
var is2xx = !err && /^2/.test('' + response.statusCode);
|
||||
|
||||
if (err) {
|
||||
|
||||
self._rp_reject(new errors.RequestError(err, self._rp_options, response));
|
||||
|
||||
} else if (self._rp_options.simple && !is2xx) {
|
||||
|
||||
if (isFunction(self._rp_options.transform) && self._rp_options.transform2xxOnly === false) {
|
||||
|
||||
(new PromiseImpl(function (resolve) {
|
||||
resolve(self._rp_options.transform(body, response, self._rp_options.resolveWithFullResponse)); // transform may return a Promise
|
||||
}))
|
||||
.then(function (transformedResponse) {
|
||||
self._rp_reject(new errors.StatusCodeError(response.statusCode, body, self._rp_options, transformedResponse));
|
||||
})
|
||||
.catch(function (transformErr) {
|
||||
self._rp_reject(new errors.TransformError(transformErr, self._rp_options, response));
|
||||
});
|
||||
|
||||
} else {
|
||||
self._rp_reject(new errors.StatusCodeError(response.statusCode, body, self._rp_options, response));
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if (isFunction(self._rp_options.transform) && (is2xx || self._rp_options.transform2xxOnly === false)) {
|
||||
|
||||
(new PromiseImpl(function (resolve) {
|
||||
resolve(self._rp_options.transform(body, response, self._rp_options.resolveWithFullResponse)); // transform may return a Promise
|
||||
}))
|
||||
.then(function (transformedResponse) {
|
||||
self._rp_resolve(transformedResponse);
|
||||
})
|
||||
.catch(function (transformErr) {
|
||||
self._rp_reject(new errors.TransformError(transformErr, self._rp_options, response));
|
||||
});
|
||||
|
||||
} else if (self._rp_options.resolveWithFullResponse) {
|
||||
self._rp_resolve(response);
|
||||
} else {
|
||||
self._rp_resolve(body);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (origCallbackThrewException) {
|
||||
throw thrownException;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
plumbing.exposePromiseMethod = function (exposeTo, bindTo, promisePropertyKey, methodToExpose, exposeAs) {
|
||||
|
||||
exposeAs = exposeAs || methodToExpose;
|
||||
|
||||
if (exposeAs in exposeTo) {
|
||||
throw new Error('Unable to expose method "' + exposeAs + '"');
|
||||
}
|
||||
|
||||
exposeTo[exposeAs] = function RP$exposed() {
|
||||
var self = bindTo || this;
|
||||
return self[promisePropertyKey][methodToExpose].apply(self[promisePropertyKey], arguments);
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
plumbing.exposePromise = function (exposeTo, bindTo, promisePropertyKey, exposeAs) {
|
||||
|
||||
exposeAs = exposeAs || 'promise';
|
||||
|
||||
if (exposeAs in exposeTo) {
|
||||
throw new Error('Unable to expose method "' + exposeAs + '"');
|
||||
}
|
||||
|
||||
exposeTo[exposeAs] = function RP$promise() {
|
||||
var self = bindTo || this;
|
||||
return self[promisePropertyKey];
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
return plumbing;
|
||||
|
||||
};
|
||||
41
node_modules/request-promise-core/package.json
generated
vendored
Normal file
41
node_modules/request-promise-core/package.json
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"name": "request-promise-core",
|
||||
"version": "1.1.1",
|
||||
"description": "Core Promise support implementation for the simplified HTTP request client 'request'.",
|
||||
"main": "./lib/plumbing.js",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/request/promise-core.git"
|
||||
},
|
||||
"author": "Nicolai Kamenzky (https://github.com/analog-nico)",
|
||||
"license": "ISC",
|
||||
"homepage": "https://github.com/request/promise-core#readme",
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"lodash": "^4.13.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"request": "^2.34"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@request/api": "^0.6.0",
|
||||
"@request/client": "^0.1.0",
|
||||
"bluebird": "~3.4.1",
|
||||
"body-parser": "~1.15.2",
|
||||
"chai": "~3.5.0",
|
||||
"chalk": "~1.1.3",
|
||||
"gulp": "~3.9.1",
|
||||
"gulp-coveralls": "~0.1.4",
|
||||
"gulp-eslint": "~2.1.0",
|
||||
"gulp-istanbul": "~1.0.0",
|
||||
"gulp-mocha": "~2.2.0",
|
||||
"node-version": "~1.0.0",
|
||||
"publish-please": "~2.1.4",
|
||||
"request": "^2.34.0",
|
||||
"rimraf": "~2.5.3",
|
||||
"run-sequence": "~1.2.2",
|
||||
"stealthy-require": "~1.0.0"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user