first commit
This commit is contained in:
11
build/node_modules/node-rest-client/.npmignore
generated
vendored
Normal file
11
build/node_modules/node-rest-client/.npmignore
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
test/man-test.js
|
||||
|
||||
test/spec/test.js
|
||||
|
||||
node_modules
|
||||
*.log
|
||||
|
||||
test/multiple-clients-test.js
|
||||
|
||||
test/manual-test.js
|
||||
13
build/node_modules/node-rest-client/LICENSE
generated
vendored
Normal file
13
build/node_modules/node-rest-client/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
Copyright (c) 2013 Alejandro Alvarez Acero. All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
||||
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
|
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
|
||||
to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
|
||||
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
653
build/node_modules/node-rest-client/lib/node-rest-client.js
generated
vendored
Normal file
653
build/node_modules/node-rest-client/lib/node-rest-client.js
generated
vendored
Normal file
@@ -0,0 +1,653 @@
|
||||
var http = require('http'),
|
||||
https = require('https'),
|
||||
parseString = require('xml2js').parseString,
|
||||
urlParser = require('url'),
|
||||
util = require("util"),
|
||||
events = require("events"),
|
||||
zlib = require("zlib"),
|
||||
node_debug = require("debug")("NRC");
|
||||
|
||||
exports.Client = function (options){
|
||||
var self = this;
|
||||
|
||||
self.options = options || {},
|
||||
self.useProxy = (self.options.proxy || false)?true:false,
|
||||
self.useProxyTunnel = (!self.useProxy || self.options.proxy.tunnel===undefined)?false:self.options.proxy.tunnel,
|
||||
self.proxy = self.options.proxy,
|
||||
self.connection = self.options.connection || {},
|
||||
self.mimetypes = self.options.mimetypes || {};
|
||||
self.requestConfig = self.options.requestConfig || {};
|
||||
self.responseConfig = self.options.responseConfig || {};
|
||||
|
||||
this.methods={};
|
||||
|
||||
|
||||
// Client Request to be passed to ConnectManager and returned
|
||||
// for each REST method invocation
|
||||
var ClientRequest =function(){
|
||||
events.EventEmitter.call(this);
|
||||
};
|
||||
|
||||
|
||||
util.inherits(ClientRequest, events.EventEmitter);
|
||||
|
||||
|
||||
ClientRequest.prototype.end = function(){
|
||||
if(this._httpRequest) {
|
||||
this._httpRequest.end();
|
||||
}
|
||||
};
|
||||
|
||||
ClientRequest.prototype.setHttpRequest=function(req){
|
||||
this._httpRequest = req;
|
||||
};
|
||||
|
||||
var Util = {
|
||||
|
||||
createProxyPath:function(url){
|
||||
var result = url.host;
|
||||
// check url protocol to set path in request options
|
||||
if (url.protocol === "https:"){
|
||||
// port is set, leave it, otherwise use default https 443
|
||||
result = (url.host.indexOf(":") == -1?url.hostname + ":443":url.host);
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
createProxyHeaders:function(url){
|
||||
var result ={};
|
||||
// if proxy requires authentication, create Proxy-Authorization headers
|
||||
if (self.proxy.user && self.proxy.password){
|
||||
result["Proxy-Authorization"] = "Basic " + new Buffer([self.proxy.user,self.proxy.password].join(":")).toString("base64");
|
||||
}
|
||||
// no tunnel proxy connection, we add the host to the headers
|
||||
if(!self.useProxyTunnel)
|
||||
result["host"] = url.host;
|
||||
|
||||
return result;
|
||||
},
|
||||
createConnectOptions:function(connectURL, connectMethod){
|
||||
debug("connect URL = ", connectURL);
|
||||
var url = urlParser.parse(connectURL),
|
||||
path,
|
||||
result={},
|
||||
protocol = url.protocol.indexOf(":") == -1?url.protocol:url.protocol.substring(0,url.protocol.indexOf(":")),
|
||||
defaultPort = protocol === 'http'?80:443;
|
||||
|
||||
result ={
|
||||
host: url.host.indexOf(":") == -1?url.host:url.host.substring(0,url.host.indexOf(":")),
|
||||
port: url.port === undefined?defaultPort:url.port,
|
||||
path: url.path,
|
||||
protocol:protocol
|
||||
};
|
||||
|
||||
if (self.useProxy) result.agent = false; // cannot use default agent in proxy mode
|
||||
|
||||
if (self.options.user && self.options.password){
|
||||
result.auth = [self.options.user,self.options.password].join(":");
|
||||
|
||||
} else if (self.options.user && !self.options.password){
|
||||
// some sites only needs user with no password to authenticate
|
||||
result.auth = self.options.user;
|
||||
}
|
||||
|
||||
|
||||
// configure proxy connection to establish a tunnel
|
||||
if (self.useProxy){
|
||||
|
||||
result.proxy ={
|
||||
host: self.proxy.host,
|
||||
port: self.proxy.port,
|
||||
method: self.useProxyTunnel?'CONNECT':connectMethod,//if proxy tunnel use 'CONNECT' method, else get method from request,
|
||||
path: self.useProxyTunnel?this.createProxyPath(url):connectURL, // if proxy tunnel set proxy path else get request path,
|
||||
headers: this.createProxyHeaders(url) // createProxyHeaders add correct headers depending of proxy connection type
|
||||
};
|
||||
}
|
||||
|
||||
if(self.connection && typeof self.connection === 'object'){
|
||||
for(var option in self.connection){
|
||||
result[option] = self.connection[option];
|
||||
}
|
||||
}
|
||||
|
||||
// don't use tunnel to connect to proxy, direct request
|
||||
// and delete proxy options
|
||||
if (!self.useProxyTunnel){
|
||||
for (option in result.proxy){
|
||||
result[option] = result.proxy[option];
|
||||
}
|
||||
|
||||
delete result.proxy;
|
||||
}
|
||||
|
||||
// add general request and response config to connect options
|
||||
|
||||
result.requestConfig = self.requestConfig;
|
||||
result.responseConfig = self.responseConfig;
|
||||
|
||||
|
||||
return result;
|
||||
},
|
||||
decodeQueryFromURL: function(connectURL){
|
||||
var url = urlParser.parse(connectURL),
|
||||
query = url.query.substring(1).split("&"),
|
||||
keyValue,
|
||||
result={};
|
||||
|
||||
// create decoded args from key value elements in query+
|
||||
for (var i=0;i<query.length;i++){
|
||||
keyValue = query[i].split("=");
|
||||
result[keyValue[0]] = decodeURIComponent(keyValue[1]);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
},
|
||||
encodeQueryFromArgs: function(args){
|
||||
var result="?", counter = 1;
|
||||
// create enconded URL from args
|
||||
for (var key in args) {
|
||||
var keyValue = "";
|
||||
if ( args[key] instanceof Array ) {
|
||||
/*
|
||||
* We are dealing with an array in the query string ?key=Value0&key=Value1
|
||||
* That a REST application translates into key=[Value0, Value1]
|
||||
*/
|
||||
for ( var ii=0, sizeArray = args[key].length; ii < sizeArray; ii++ ) {
|
||||
result = result.concat((counter > 1 ? "&": "") + key + "=" + encodeURIComponent(args[key][ii]));
|
||||
counter++;
|
||||
}
|
||||
} else { //No array, just a single &key=value
|
||||
keyValue = key + "=" + encodeURIComponent(args[key]);
|
||||
result = result.concat((counter > 1 ? "&":"") + keyValue);
|
||||
}
|
||||
|
||||
counter++;
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
parsePathParameters:function(args,url){
|
||||
var result = url;
|
||||
if (!args || !args.path) return url;
|
||||
|
||||
for (var placeholder in args.path){
|
||||
var regex = new RegExp("\\$\\{" + placeholder + "\\}","i");
|
||||
result = result.replace(regex,args.path[placeholder]);
|
||||
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
},
|
||||
overrideClientConfig:function(connectOptions,methodOptions){
|
||||
function validateReqResOptions(reqResOption){
|
||||
return (reqResOption && typeof reqResOption === 'object');
|
||||
}
|
||||
// check if we have particular request or response config set on this method invocation
|
||||
// and override general request/response config
|
||||
if (validateReqResOptions(methodOptions.requestConfig)){
|
||||
util._extend(connectOptions.requestConfig,methodOptions.requestConfig);
|
||||
}
|
||||
|
||||
if (validateReqResOptions(methodOptions.responseConfig)){
|
||||
util._extend(connectOptions.responseConfig,methodOptions.responseConfig);
|
||||
}
|
||||
|
||||
|
||||
},
|
||||
connect : function(method, url, args, callback, clientRequest){
|
||||
// configure connect options based on url parameter parse
|
||||
var options = this.createConnectOptions(this.parsePathParameters(args,url), method);
|
||||
debug("options pre connect",options);
|
||||
options.method = method,
|
||||
options.clientRequest = clientRequest,
|
||||
options.headers= options.headers || {};
|
||||
|
||||
debug("args = ", args);
|
||||
debug("args.data = ", args !== undefined?args.data:undefined);
|
||||
// no args passed
|
||||
if (typeof args === 'function'){
|
||||
callback = args;
|
||||
//add Content-length to POST/PUT/DELETE/PATCH methods
|
||||
if (method === 'POST' || method === 'PUT' || method === 'DELETE' || method === 'PATCH'){
|
||||
options.headers['Content-Length'] = 0;
|
||||
}
|
||||
} else if (typeof args === 'object') {
|
||||
// add headers and POST/PUT/DELETE/PATCH data to connect options to be passed
|
||||
// with request, but without deleting other headers like non-tunnel proxy headers
|
||||
if (args.headers){
|
||||
for (var headerName in args.headers){
|
||||
options.headers[headerName] = args.headers[headerName];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//always set Content-length header
|
||||
//set Content lentgh for some servers to work (nginx, apache)
|
||||
if (args.data !== undefined){
|
||||
options.data = args.data;
|
||||
options.headers['Content-Length'] = Buffer.byteLength((typeof args.data === 'string' ? args.data:JSON.stringify(args.data)), 'utf8');
|
||||
}else{
|
||||
options.headers['Content-Length'] = 0;
|
||||
}
|
||||
// we have args, go and check if we have parameters
|
||||
if (args.parameters && Object.keys(args.parameters).length > 0){
|
||||
// validate URL consistency, and fix it
|
||||
options.path +=(options.path.charAt(url.length-1) === '?'?"?":"");
|
||||
options.path = options.path.concat(Util.encodeQueryFromArgs(args.parameters));
|
||||
debug("options.path after request parameters = ", options.path);
|
||||
}
|
||||
|
||||
// override client config, by the moment just for request response config
|
||||
this.overrideClientConfig(options,args);
|
||||
}
|
||||
|
||||
|
||||
debug("options post connect",options);
|
||||
debug("FINAL SELF object ====>", self);
|
||||
|
||||
if (self.useProxy && self.useProxyTunnel){
|
||||
ConnectManager.proxy(options,callback);
|
||||
}else{
|
||||
// normal connection and direct proxy connections (no tunneling)
|
||||
ConnectManager.normal(options,callback);
|
||||
}
|
||||
},
|
||||
mergeMimeTypes:function(mimetypes){
|
||||
// merge mime-types passed as options to client
|
||||
if (mimetypes && typeof mimetypes === "object"){
|
||||
if (mimetypes.json && mimetypes.json instanceof Array && mimetypes.json.length > 0){
|
||||
ConnectManager.jsonctype = mimetypes.json;
|
||||
}else if (mimetypes.xml && mimetypes.xml instanceof Array && mimetypes.xml.length > 0){
|
||||
ConnectManager.xmlctype = mimetypes.xml;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
Method = function(url, method){
|
||||
var httpMethod = self[method.toLowerCase()];
|
||||
|
||||
return function(args,callback){
|
||||
var completeURL = url;
|
||||
//no args
|
||||
if (typeof args === 'function'){
|
||||
callback = args;
|
||||
args = {};
|
||||
}else if (typeof args === 'object'){
|
||||
// we have args, go and check if we have parameters
|
||||
if (args.parameters && Object.keys(args.parameters).length > 0){
|
||||
// validate URL consistency, and fix it
|
||||
url +=(url.charAt(url.length-1) === '?'?"?":"");
|
||||
completeURL = url.concat(Util.encodeQueryFromArgs(args.parameters));
|
||||
//delete args parameters we don't need it anymore in registered
|
||||
// method invocation
|
||||
delete args.parameters;
|
||||
}
|
||||
}
|
||||
return httpMethod(completeURL, args , callback);
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
this.get = function(url, args, callback){
|
||||
var clientRequest = new ClientRequest();
|
||||
Util.connect('GET', url, args, callback, clientRequest);
|
||||
return clientRequest;
|
||||
};
|
||||
|
||||
this.post = function(url, args, callback){
|
||||
var clientRequest = new ClientRequest();
|
||||
Util.connect('POST', url, args, callback, clientRequest);
|
||||
return clientRequest;
|
||||
};
|
||||
|
||||
this.put = function(url, args, callback){
|
||||
var clientRequest = new ClientRequest();
|
||||
Util.connect('PUT', url, args, callback, clientRequest);
|
||||
return clientRequest;
|
||||
};
|
||||
|
||||
this.delete = function(url, args, callback){
|
||||
var clientRequest = new ClientRequest();
|
||||
Util.connect('DELETE', url, args, callback, clientRequest);
|
||||
return clientRequest;
|
||||
};
|
||||
|
||||
this.patch = function(url, args, callback){
|
||||
var clientRequest = new ClientRequest();
|
||||
Util.connect('PATCH', url, args, callback, clientRequest);
|
||||
return clientRequest;
|
||||
};
|
||||
|
||||
|
||||
this.registerMethod = function(name, url, method){
|
||||
// create method in method registry with preconfigured REST invocation
|
||||
// method
|
||||
this.methods[name] = new Method(url,method);
|
||||
};
|
||||
|
||||
this.unregisterMethod = function(name){
|
||||
delete this.methods[name];
|
||||
};
|
||||
|
||||
// handle ConnectManager events
|
||||
ConnectManager.on('error',function(err){
|
||||
self.emit('error',err);
|
||||
});
|
||||
|
||||
// merge mime types with connect manager
|
||||
Util.mergeMimeTypes(self.mimetypes);
|
||||
debug("ConnectManager", ConnectManager);
|
||||
|
||||
};
|
||||
|
||||
|
||||
var ConnectManager = {
|
||||
"xmlctype":["application/xml","application/xml;charset=utf-8"],
|
||||
"jsonctype":["application/json","application/json;charset=utf-8"],
|
||||
"isXML":function(content){
|
||||
var result = false;
|
||||
if (!content) return result;
|
||||
|
||||
for (var i=0; i<this.xmlctype.length;i++){
|
||||
result = this.xmlctype[i].toLowerCase() === content.toLowerCase();
|
||||
if (result) break;
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
"isJSON":function(content){
|
||||
var result = false;
|
||||
if (!content) return result;
|
||||
|
||||
for (var i=0; i<this.jsonctype.length;i++){
|
||||
result = this.jsonctype[i].toLowerCase() === content.toLowerCase();
|
||||
if (result) break;
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
"isValidData":function(data){
|
||||
return data !== undefined && (data.length !== undefined && data.length > 0);
|
||||
},
|
||||
"configureRequest":function(req, config, clientRequest){
|
||||
|
||||
if (config.timeout){
|
||||
req.setTimeout(config.timeout, function(){
|
||||
clientRequest.emit('requestTimeout',req);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
if(config.noDelay)
|
||||
req.setNoDelay(config.noDelay);
|
||||
|
||||
if(config.keepAlive)
|
||||
req.setSocketKeepAlive(config.noDelay,config.keepAliveDelay || 0);
|
||||
|
||||
},
|
||||
"configureResponse":function(res,config, clientRequest){
|
||||
if (config.timeout){
|
||||
res.setTimeout(config.timeout, function(){
|
||||
clientRequest.emit('responseTimeout',res);
|
||||
res.close();
|
||||
});
|
||||
}
|
||||
},
|
||||
"handleEnd":function(res,buffer,callback){
|
||||
|
||||
var self = this,
|
||||
content = res.headers["content-type"],
|
||||
encoding = res.headers["content-encoding"];
|
||||
|
||||
debug("content-type: ", content);
|
||||
debug("content-encoding: ",encoding);
|
||||
|
||||
if(encoding !== undefined && encoding.indexOf("gzip") >= 0){
|
||||
debug("gunzip");
|
||||
zlib.gunzip(Buffer.concat(buffer),function(er,gunzipped){
|
||||
self.handleResponse(res,gunzipped,callback);
|
||||
});
|
||||
}else if(encoding !== undefined && encoding.indexOf("deflate") >= 0){
|
||||
debug("inflate");
|
||||
zlib.inflate(Buffer.concat(buffer),function(er,inflated){
|
||||
self.handleResponse(res,inflated,callback);
|
||||
});
|
||||
}else {
|
||||
debug("not compressed");
|
||||
self.handleResponse(res,Buffer.concat(buffer),callback);
|
||||
}
|
||||
},
|
||||
"handleResponse":function(res,data,callback){
|
||||
var content = res.headers["content-type"] && res.headers["content-type"].replace(/ /g, '');
|
||||
|
||||
debug("response content is ",content);
|
||||
// XML data need to be parsed as JS object
|
||||
if (this.isXML(content)){
|
||||
parseString(data.toString(), function (err, result) {
|
||||
callback(result, res);
|
||||
});
|
||||
}else if (this.isJSON(content)){
|
||||
var jsonData,
|
||||
data = data.toString();
|
||||
try {
|
||||
jsonData = this.isValidData(data)?JSON.parse(data):data;
|
||||
} catch (err) {
|
||||
// Something went wrong when parsing json. This can happen
|
||||
// for many reasons, including a bad implementation on the
|
||||
// server.
|
||||
jsonData = 'Error parsing response. response: [' +
|
||||
data + '], error: [' + err + ']';
|
||||
|
||||
}
|
||||
callback(jsonData, res);
|
||||
}else{
|
||||
callback(data, res);
|
||||
}
|
||||
},
|
||||
"prepareData":function(data){
|
||||
var result;
|
||||
if ((data instanceof Buffer) || (typeof data !== 'object')){
|
||||
result = data;
|
||||
}else{
|
||||
result = JSON.stringify(data);
|
||||
}
|
||||
return result;
|
||||
},
|
||||
"proxy":function(options, callback){
|
||||
|
||||
debug("proxy options",options.proxy);
|
||||
|
||||
// creare a new proxy tunnel, and use to connect to API URL
|
||||
var proxyTunnel = http.request(options.proxy),
|
||||
self = this;
|
||||
|
||||
|
||||
proxyTunnel.on('connect',function(res, socket, head){
|
||||
debug("proxy connected",socket);
|
||||
|
||||
// set tunnel socket in request options, that's the tunnel itself
|
||||
options.socket = socket;
|
||||
|
||||
var buffer=[],
|
||||
protocol = (options.protocol =="http")?http:https,
|
||||
clientRequest = options.clientRequest,
|
||||
requestConfig = options.requestConfig,
|
||||
responseConfig = options.responseConfig;
|
||||
|
||||
//remove "protocol" and "clientRequest" option from options, cos is not allowed by http/hppts node objects
|
||||
delete options.protocol;
|
||||
delete options.clientRequest;
|
||||
delete options.requestConfig;
|
||||
delete options.responseConfig;
|
||||
|
||||
// add request options to request returned to calling method
|
||||
clientRequest.options = options;
|
||||
|
||||
var request = protocol.request(options, function(res){
|
||||
//configure response
|
||||
self.configureResponse(res,responseConfig, clientRequest);
|
||||
|
||||
// concurrent data chunk handler
|
||||
res.on('data',function(chunk){
|
||||
buffer.push(new Buffer(chunk));
|
||||
});
|
||||
|
||||
res.on('end',function(){
|
||||
self.handleEnd(res,buffer,callback);
|
||||
});
|
||||
|
||||
|
||||
// handler response errors
|
||||
res.on('error',function(err){
|
||||
if (clientRequest !== undefined && typeof clientRequest === 'object'){
|
||||
// add request as property of error
|
||||
err.request = clientRequest;
|
||||
err.response = res;
|
||||
// request error handler
|
||||
clientRequest.emit('error',err);
|
||||
}else{
|
||||
// general error handler
|
||||
self.emit('error',err);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
// configure request and add it to clientRequest
|
||||
// and add it to request returned
|
||||
self.configureRequest(request,requestConfig, clientRequest);
|
||||
clientRequest.setHttpRequest(request);
|
||||
|
||||
|
||||
// write POST/PUT data to request body;
|
||||
if(options.data) request.write(self.prepareData(options.data));
|
||||
|
||||
|
||||
// handle request errors and handle them by request or general error handler
|
||||
request.on('error',function(err){
|
||||
if (clientRequest !== undefined && typeof clientRequest === 'object'){
|
||||
// add request as property of error
|
||||
err.request = clientRequest;
|
||||
|
||||
// request error handler
|
||||
clientRequest.emit('error',err);
|
||||
}else{
|
||||
// general error handler
|
||||
self.emit('error',err);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
request.end();
|
||||
});
|
||||
|
||||
// proxy tunnel error are only handled by general error handler
|
||||
proxyTunnel.on('error',function(e){
|
||||
self.emit('error',e);
|
||||
});
|
||||
|
||||
proxyTunnel.end();
|
||||
|
||||
},
|
||||
"normal":function(options, callback){
|
||||
|
||||
var buffer = [],
|
||||
protocol = (options.protocol === "http")?http:https,
|
||||
clientRequest = options.clientRequest,
|
||||
requestConfig = options.requestConfig,
|
||||
responseConfig = options.responseConfig,
|
||||
self = this;
|
||||
|
||||
//remove "protocol" and "clientRequest" option from options, cos is not allowed by http/hppts node objects
|
||||
delete options.protocol;
|
||||
delete options.clientRequest;
|
||||
delete options.requestConfig;
|
||||
delete options.responseConfig;
|
||||
debug("options pre connect", options);
|
||||
|
||||
// add request options to request returned to calling method
|
||||
clientRequest.options = options;
|
||||
|
||||
var request = protocol.request(options, function(res){
|
||||
//configure response
|
||||
self.configureResponse(res,responseConfig, clientRequest);
|
||||
|
||||
// concurrent data chunk handler
|
||||
res.on('data',function(chunk){
|
||||
buffer.push(new Buffer(chunk));
|
||||
});
|
||||
|
||||
res.on('end',function(){
|
||||
|
||||
self.handleEnd(res,buffer,callback);
|
||||
|
||||
});
|
||||
|
||||
// handler response errors
|
||||
res.on('error',function(err){
|
||||
if (clientRequest !== undefined && typeof clientRequest === 'object'){
|
||||
// add request as property of error
|
||||
err.request = clientRequest;
|
||||
err.response = res;
|
||||
// request error handler
|
||||
clientRequest.emit('error',err);
|
||||
}else{
|
||||
// general error handler
|
||||
self.emit('error',err);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// configure request and add it to clientRequest
|
||||
// and add it to request returned
|
||||
self.configureRequest(request,requestConfig, clientRequest);
|
||||
debug("clientRequest",clientRequest);
|
||||
|
||||
clientRequest.setHttpRequest(request);
|
||||
|
||||
// handle request errors and handle them by request or general error handler
|
||||
request.on('error',function(err){
|
||||
debug('request error', clientRequest);
|
||||
if (clientRequest !== undefined && typeof clientRequest === 'object'){
|
||||
// add request as property of error
|
||||
err.request = clientRequest;
|
||||
// request error handler
|
||||
clientRequest.emit('error',err);
|
||||
}else{
|
||||
// general error handler
|
||||
self.emit('error',err);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
debug("options data", options.data);
|
||||
// write POST/PUT data to request body;
|
||||
if(options.data) request.write(this.prepareData(options.data));
|
||||
|
||||
request.end();
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// event handlers for client and ConnectManager
|
||||
util.inherits(exports.Client, events.EventEmitter);
|
||||
util._extend(ConnectManager,events.EventEmitter.prototype);
|
||||
|
||||
|
||||
var debug = function(){
|
||||
if (!process.env.DEBUG) return;
|
||||
|
||||
var now = new Date(),
|
||||
header =now.getHours() + ":" + now.getMinutes() + ":" + now.getSeconds() + " [NRC CLIENT]" + arguments.callee.caller.name + " -> ",
|
||||
args = Array.prototype.slice.call(arguments);
|
||||
args.splice(0,0,header);
|
||||
node_debug.apply(console,args);
|
||||
|
||||
|
||||
};
|
||||
3
build/node_modules/node-rest-client/node_modules/debug/.jshintrc
generated
vendored
Normal file
3
build/node_modules/node-rest-client/node_modules/debug/.jshintrc
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"laxbreak": true
|
||||
}
|
||||
6
build/node_modules/node-rest-client/node_modules/debug/.npmignore
generated
vendored
Normal file
6
build/node_modules/node-rest-client/node_modules/debug/.npmignore
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
support
|
||||
test
|
||||
examples
|
||||
example
|
||||
*.sock
|
||||
dist
|
||||
195
build/node_modules/node-rest-client/node_modules/debug/History.md
generated
vendored
Normal file
195
build/node_modules/node-rest-client/node_modules/debug/History.md
generated
vendored
Normal file
@@ -0,0 +1,195 @@
|
||||
|
||||
2.2.0 / 2015-05-09
|
||||
==================
|
||||
|
||||
* package: update "ms" to v0.7.1 (#202, @dougwilson)
|
||||
* README: add logging to file example (#193, @DanielOchoa)
|
||||
* README: fixed a typo (#191, @amir-s)
|
||||
* browser: expose `storage` (#190, @stephenmathieson)
|
||||
* Makefile: add a `distclean` target (#189, @stephenmathieson)
|
||||
|
||||
2.1.3 / 2015-03-13
|
||||
==================
|
||||
|
||||
* Updated stdout/stderr example (#186)
|
||||
* Updated example/stdout.js to match debug current behaviour
|
||||
* Renamed example/stderr.js to stdout.js
|
||||
* Update Readme.md (#184)
|
||||
* replace high intensity foreground color for bold (#182, #183)
|
||||
|
||||
2.1.2 / 2015-03-01
|
||||
==================
|
||||
|
||||
* dist: recompile
|
||||
* update "ms" to v0.7.0
|
||||
* package: update "browserify" to v9.0.3
|
||||
* component: fix "ms.js" repo location
|
||||
* changed bower package name
|
||||
* updated documentation about using debug in a browser
|
||||
* fix: security error on safari (#167, #168, @yields)
|
||||
|
||||
2.1.1 / 2014-12-29
|
||||
==================
|
||||
|
||||
* browser: use `typeof` to check for `console` existence
|
||||
* browser: check for `console.log` truthiness (fix IE 8/9)
|
||||
* browser: add support for Chrome apps
|
||||
* Readme: added Windows usage remarks
|
||||
* Add `bower.json` to properly support bower install
|
||||
|
||||
2.1.0 / 2014-10-15
|
||||
==================
|
||||
|
||||
* node: implement `DEBUG_FD` env variable support
|
||||
* package: update "browserify" to v6.1.0
|
||||
* package: add "license" field to package.json (#135, @panuhorsmalahti)
|
||||
|
||||
2.0.0 / 2014-09-01
|
||||
==================
|
||||
|
||||
* package: update "browserify" to v5.11.0
|
||||
* node: use stderr rather than stdout for logging (#29, @stephenmathieson)
|
||||
|
||||
1.0.4 / 2014-07-15
|
||||
==================
|
||||
|
||||
* dist: recompile
|
||||
* example: remove `console.info()` log usage
|
||||
* example: add "Content-Type" UTF-8 header to browser example
|
||||
* browser: place %c marker after the space character
|
||||
* browser: reset the "content" color via `color: inherit`
|
||||
* browser: add colors support for Firefox >= v31
|
||||
* debug: prefer an instance `log()` function over the global one (#119)
|
||||
* Readme: update documentation about styled console logs for FF v31 (#116, @wryk)
|
||||
|
||||
1.0.3 / 2014-07-09
|
||||
==================
|
||||
|
||||
* Add support for multiple wildcards in namespaces (#122, @seegno)
|
||||
* browser: fix lint
|
||||
|
||||
1.0.2 / 2014-06-10
|
||||
==================
|
||||
|
||||
* browser: update color palette (#113, @gscottolson)
|
||||
* common: make console logging function configurable (#108, @timoxley)
|
||||
* node: fix %o colors on old node <= 0.8.x
|
||||
* Makefile: find node path using shell/which (#109, @timoxley)
|
||||
|
||||
1.0.1 / 2014-06-06
|
||||
==================
|
||||
|
||||
* browser: use `removeItem()` to clear localStorage
|
||||
* browser, node: don't set DEBUG if namespaces is undefined (#107, @leedm777)
|
||||
* package: add "contributors" section
|
||||
* node: fix comment typo
|
||||
* README: list authors
|
||||
|
||||
1.0.0 / 2014-06-04
|
||||
==================
|
||||
|
||||
* make ms diff be global, not be scope
|
||||
* debug: ignore empty strings in enable()
|
||||
* node: make DEBUG_COLORS able to disable coloring
|
||||
* *: export the `colors` array
|
||||
* npmignore: don't publish the `dist` dir
|
||||
* Makefile: refactor to use browserify
|
||||
* package: add "browserify" as a dev dependency
|
||||
* Readme: add Web Inspector Colors section
|
||||
* node: reset terminal color for the debug content
|
||||
* node: map "%o" to `util.inspect()`
|
||||
* browser: map "%j" to `JSON.stringify()`
|
||||
* debug: add custom "formatters"
|
||||
* debug: use "ms" module for humanizing the diff
|
||||
* Readme: add "bash" syntax highlighting
|
||||
* browser: add Firebug color support
|
||||
* browser: add colors for WebKit browsers
|
||||
* node: apply log to `console`
|
||||
* rewrite: abstract common logic for Node & browsers
|
||||
* add .jshintrc file
|
||||
|
||||
0.8.1 / 2014-04-14
|
||||
==================
|
||||
|
||||
* package: re-add the "component" section
|
||||
|
||||
0.8.0 / 2014-03-30
|
||||
==================
|
||||
|
||||
* add `enable()` method for nodejs. Closes #27
|
||||
* change from stderr to stdout
|
||||
* remove unnecessary index.js file
|
||||
|
||||
0.7.4 / 2013-11-13
|
||||
==================
|
||||
|
||||
* remove "browserify" key from package.json (fixes something in browserify)
|
||||
|
||||
0.7.3 / 2013-10-30
|
||||
==================
|
||||
|
||||
* fix: catch localStorage security error when cookies are blocked (Chrome)
|
||||
* add debug(err) support. Closes #46
|
||||
* add .browser prop to package.json. Closes #42
|
||||
|
||||
0.7.2 / 2013-02-06
|
||||
==================
|
||||
|
||||
* fix package.json
|
||||
* fix: Mobile Safari (private mode) is broken with debug
|
||||
* fix: Use unicode to send escape character to shell instead of octal to work with strict mode javascript
|
||||
|
||||
0.7.1 / 2013-02-05
|
||||
==================
|
||||
|
||||
* add repository URL to package.json
|
||||
* add DEBUG_COLORED to force colored output
|
||||
* add browserify support
|
||||
* fix component. Closes #24
|
||||
|
||||
0.7.0 / 2012-05-04
|
||||
==================
|
||||
|
||||
* Added .component to package.json
|
||||
* Added debug.component.js build
|
||||
|
||||
0.6.0 / 2012-03-16
|
||||
==================
|
||||
|
||||
* Added support for "-" prefix in DEBUG [Vinay Pulim]
|
||||
* Added `.enabled` flag to the node version [TooTallNate]
|
||||
|
||||
0.5.0 / 2012-02-02
|
||||
==================
|
||||
|
||||
* Added: humanize diffs. Closes #8
|
||||
* Added `debug.disable()` to the CS variant
|
||||
* Removed padding. Closes #10
|
||||
* Fixed: persist client-side variant again. Closes #9
|
||||
|
||||
0.4.0 / 2012-02-01
|
||||
==================
|
||||
|
||||
* Added browser variant support for older browsers [TooTallNate]
|
||||
* Added `debug.enable('project:*')` to browser variant [TooTallNate]
|
||||
* Added padding to diff (moved it to the right)
|
||||
|
||||
0.3.0 / 2012-01-26
|
||||
==================
|
||||
|
||||
* Added millisecond diff when isatty, otherwise UTC string
|
||||
|
||||
0.2.0 / 2012-01-22
|
||||
==================
|
||||
|
||||
* Added wildcard support
|
||||
|
||||
0.1.0 / 2011-12-02
|
||||
==================
|
||||
|
||||
* Added: remove colors unless stderr isatty [TooTallNate]
|
||||
|
||||
0.0.1 / 2010-01-03
|
||||
==================
|
||||
|
||||
* Initial release
|
||||
36
build/node_modules/node-rest-client/node_modules/debug/Makefile
generated
vendored
Normal file
36
build/node_modules/node-rest-client/node_modules/debug/Makefile
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
|
||||
# get Makefile directory name: http://stackoverflow.com/a/5982798/376773
|
||||
THIS_MAKEFILE_PATH:=$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
|
||||
THIS_DIR:=$(shell cd $(dir $(THIS_MAKEFILE_PATH));pwd)
|
||||
|
||||
# BIN directory
|
||||
BIN := $(THIS_DIR)/node_modules/.bin
|
||||
|
||||
# applications
|
||||
NODE ?= $(shell which node)
|
||||
NPM ?= $(NODE) $(shell which npm)
|
||||
BROWSERIFY ?= $(NODE) $(BIN)/browserify
|
||||
|
||||
all: dist/debug.js
|
||||
|
||||
install: node_modules
|
||||
|
||||
clean:
|
||||
@rm -rf dist
|
||||
|
||||
dist:
|
||||
@mkdir -p $@
|
||||
|
||||
dist/debug.js: node_modules browser.js debug.js dist
|
||||
@$(BROWSERIFY) \
|
||||
--standalone debug \
|
||||
. > $@
|
||||
|
||||
distclean: clean
|
||||
@rm -rf node_modules
|
||||
|
||||
node_modules: package.json
|
||||
@NODE_ENV= $(NPM) install
|
||||
@touch node_modules
|
||||
|
||||
.PHONY: all install clean distclean
|
||||
188
build/node_modules/node-rest-client/node_modules/debug/Readme.md
generated
vendored
Normal file
188
build/node_modules/node-rest-client/node_modules/debug/Readme.md
generated
vendored
Normal file
@@ -0,0 +1,188 @@
|
||||
# debug
|
||||
|
||||
tiny node.js debugging utility modelled after node core's debugging technique.
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
$ npm install debug
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
With `debug` you simply invoke the exported function to generate your debug function, passing it a name which will determine if a noop function is returned, or a decorated `console.error`, so all of the `console` format string goodies you're used to work fine. A unique color is selected per-function for visibility.
|
||||
|
||||
Example _app.js_:
|
||||
|
||||
```js
|
||||
var debug = require('debug')('http')
|
||||
, http = require('http')
|
||||
, name = 'My App';
|
||||
|
||||
// fake app
|
||||
|
||||
debug('booting %s', name);
|
||||
|
||||
http.createServer(function(req, res){
|
||||
debug(req.method + ' ' + req.url);
|
||||
res.end('hello\n');
|
||||
}).listen(3000, function(){
|
||||
debug('listening');
|
||||
});
|
||||
|
||||
// fake worker of some kind
|
||||
|
||||
require('./worker');
|
||||
```
|
||||
|
||||
Example _worker.js_:
|
||||
|
||||
```js
|
||||
var debug = require('debug')('worker');
|
||||
|
||||
setInterval(function(){
|
||||
debug('doing some work');
|
||||
}, 1000);
|
||||
```
|
||||
|
||||
The __DEBUG__ environment variable is then used to enable these based on space or comma-delimited names. Here are some examples:
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
#### Windows note
|
||||
|
||||
On Windows the environment variable is set using the `set` command.
|
||||
|
||||
```cmd
|
||||
set DEBUG=*,-not_this
|
||||
```
|
||||
|
||||
Then, run the program to be debugged as usual.
|
||||
|
||||
## Millisecond diff
|
||||
|
||||
When actively developing an application it can be useful to see when the time spent between one `debug()` call and the next. Suppose for example you invoke `debug()` before requesting a resource, and after as well, the "+NNNms" will show you how much time was spent between calls.
|
||||
|
||||

|
||||
|
||||
When stdout is not a TTY, `Date#toUTCString()` is used, making it more useful for logging the debug information as shown below:
|
||||
|
||||

|
||||
|
||||
## Conventions
|
||||
|
||||
If you're using this in one or more of your libraries, you _should_ use the name of your library so that developers may toggle debugging as desired without guessing names. If you have more than one debuggers you _should_ prefix them with your library name and use ":" to separate features. For example "bodyParser" from Connect would then be "connect:bodyParser".
|
||||
|
||||
## Wildcards
|
||||
|
||||
The `*` character may be used as a wildcard. Suppose for example your library has debuggers named "connect:bodyParser", "connect:compress", "connect:session", instead of listing all three with `DEBUG=connect:bodyParser,connect:compress,connect:session`, you may simply do `DEBUG=connect:*`, or to run everything using this module simply use `DEBUG=*`.
|
||||
|
||||
You can also exclude specific debuggers by prefixing them with a "-" character. For example, `DEBUG=*,-connect:*` would include all debuggers except those starting with "connect:".
|
||||
|
||||
## Browser support
|
||||
|
||||
Debug works in the browser as well, currently persisted by `localStorage`. Consider the situation shown below where you have `worker:a` and `worker:b`, and wish to debug both. Somewhere in the code on your page, include:
|
||||
|
||||
```js
|
||||
window.myDebug = require("debug");
|
||||
```
|
||||
|
||||
("debug" is a global object in the browser so we give this object a different name.) When your page is open in the browser, type the following in the console:
|
||||
|
||||
```js
|
||||
myDebug.enable("worker:*")
|
||||
```
|
||||
|
||||
Refresh the page. Debug output will continue to be sent to the console until it is disabled by typing `myDebug.disable()` in the console.
|
||||
|
||||
```js
|
||||
a = debug('worker:a');
|
||||
b = debug('worker:b');
|
||||
|
||||
setInterval(function(){
|
||||
a('doing some work');
|
||||
}, 1000);
|
||||
|
||||
setInterval(function(){
|
||||
b('doing some work');
|
||||
}, 1200);
|
||||
```
|
||||
|
||||
#### Web Inspector Colors
|
||||
|
||||
Colors are also enabled on "Web Inspectors" that understand the `%c` formatting
|
||||
option. These are WebKit web inspectors, Firefox ([since version
|
||||
31](https://hacks.mozilla.org/2014/05/editable-box-model-multiple-selection-sublime-text-keys-much-more-firefox-developer-tools-episode-31/))
|
||||
and the Firebug plugin for Firefox (any version).
|
||||
|
||||
Colored output looks something like:
|
||||
|
||||

|
||||
|
||||
### stderr vs stdout
|
||||
|
||||
You can set an alternative logging method per-namespace by overriding the `log` method on a per-namespace or globally:
|
||||
|
||||
Example _stdout.js_:
|
||||
|
||||
```js
|
||||
var debug = require('debug');
|
||||
var error = debug('app:error');
|
||||
|
||||
// by default stderr is used
|
||||
error('goes to stderr!');
|
||||
|
||||
var log = debug('app:log');
|
||||
// set this namespace to log via console.log
|
||||
log.log = console.log.bind(console); // don't forget to bind to console!
|
||||
log('goes to stdout');
|
||||
error('still goes to stderr!');
|
||||
|
||||
// set all output to go via console.info
|
||||
// overrides all per-namespace log settings
|
||||
debug.log = console.info.bind(console);
|
||||
error('now goes to stdout via console.info');
|
||||
log('still goes to stdout, but via console.info now');
|
||||
```
|
||||
|
||||
### Save debug output to a file
|
||||
|
||||
You can save all debug statements to a file by piping them.
|
||||
|
||||
Example:
|
||||
|
||||
```bash
|
||||
$ DEBUG_FD=3 node your-app.js 3> whatever.log
|
||||
```
|
||||
|
||||
## Authors
|
||||
|
||||
- TJ Holowaychuk
|
||||
- Nathan Rajlich
|
||||
|
||||
## License
|
||||
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2014 TJ Holowaychuk <tj@vision-media.ca>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
'Software'), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
28
build/node_modules/node-rest-client/node_modules/debug/bower.json
generated
vendored
Normal file
28
build/node_modules/node-rest-client/node_modules/debug/bower.json
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"name": "visionmedia-debug",
|
||||
"main": "dist/debug.js",
|
||||
"version": "2.2.0",
|
||||
"homepage": "https://github.com/visionmedia/debug",
|
||||
"authors": [
|
||||
"TJ Holowaychuk <tj@vision-media.ca>"
|
||||
],
|
||||
"description": "visionmedia-debug",
|
||||
"moduleType": [
|
||||
"amd",
|
||||
"es6",
|
||||
"globals",
|
||||
"node"
|
||||
],
|
||||
"keywords": [
|
||||
"visionmedia",
|
||||
"debug"
|
||||
],
|
||||
"license": "MIT",
|
||||
"ignore": [
|
||||
"**/.*",
|
||||
"node_modules",
|
||||
"bower_components",
|
||||
"test",
|
||||
"tests"
|
||||
]
|
||||
}
|
||||
168
build/node_modules/node-rest-client/node_modules/debug/browser.js
generated
vendored
Normal file
168
build/node_modules/node-rest-client/node_modules/debug/browser.js
generated
vendored
Normal file
@@ -0,0 +1,168 @@
|
||||
|
||||
/**
|
||||
* This is the web browser implementation of `debug()`.
|
||||
*
|
||||
* Expose `debug()` as the module.
|
||||
*/
|
||||
|
||||
exports = module.exports = require('./debug');
|
||||
exports.log = log;
|
||||
exports.formatArgs = formatArgs;
|
||||
exports.save = save;
|
||||
exports.load = load;
|
||||
exports.useColors = useColors;
|
||||
exports.storage = 'undefined' != typeof chrome
|
||||
&& 'undefined' != typeof chrome.storage
|
||||
? chrome.storage.local
|
||||
: localstorage();
|
||||
|
||||
/**
|
||||
* Colors.
|
||||
*/
|
||||
|
||||
exports.colors = [
|
||||
'lightseagreen',
|
||||
'forestgreen',
|
||||
'goldenrod',
|
||||
'dodgerblue',
|
||||
'darkorchid',
|
||||
'crimson'
|
||||
];
|
||||
|
||||
/**
|
||||
* Currently only WebKit-based Web Inspectors, Firefox >= v31,
|
||||
* and the Firebug extension (any Firefox version) are known
|
||||
* to support "%c" CSS customizations.
|
||||
*
|
||||
* TODO: add a `localStorage` variable to explicitly enable/disable colors
|
||||
*/
|
||||
|
||||
function useColors() {
|
||||
// is webkit? http://stackoverflow.com/a/16459606/376773
|
||||
return ('WebkitAppearance' in document.documentElement.style) ||
|
||||
// is firebug? http://stackoverflow.com/a/398120/376773
|
||||
(window.console && (console.firebug || (console.exception && console.table))) ||
|
||||
// is firefox >= v31?
|
||||
// https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
|
||||
(navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31);
|
||||
}
|
||||
|
||||
/**
|
||||
* Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
|
||||
*/
|
||||
|
||||
exports.formatters.j = function(v) {
|
||||
return JSON.stringify(v);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Colorize log arguments if enabled.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function formatArgs() {
|
||||
var args = arguments;
|
||||
var useColors = this.useColors;
|
||||
|
||||
args[0] = (useColors ? '%c' : '')
|
||||
+ this.namespace
|
||||
+ (useColors ? ' %c' : ' ')
|
||||
+ args[0]
|
||||
+ (useColors ? '%c ' : ' ')
|
||||
+ '+' + exports.humanize(this.diff);
|
||||
|
||||
if (!useColors) return args;
|
||||
|
||||
var c = 'color: ' + this.color;
|
||||
args = [args[0], c, 'color: inherit'].concat(Array.prototype.slice.call(args, 1));
|
||||
|
||||
// the final "%c" is somewhat tricky, because there could be other
|
||||
// arguments passed either before or after the %c, so we need to
|
||||
// figure out the correct index to insert the CSS into
|
||||
var index = 0;
|
||||
var lastC = 0;
|
||||
args[0].replace(/%[a-z%]/g, function(match) {
|
||||
if ('%%' === match) return;
|
||||
index++;
|
||||
if ('%c' === match) {
|
||||
// we only are interested in the *last* %c
|
||||
// (the user may have provided their own)
|
||||
lastC = index;
|
||||
}
|
||||
});
|
||||
|
||||
args.splice(lastC, 0, c);
|
||||
return args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invokes `console.log()` when available.
|
||||
* No-op when `console.log` is not a "function".
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function log() {
|
||||
// this hackery is required for IE8/9, where
|
||||
// the `console.log` function doesn't have 'apply'
|
||||
return 'object' === typeof console
|
||||
&& console.log
|
||||
&& Function.prototype.apply.call(console.log, console, arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save `namespaces`.
|
||||
*
|
||||
* @param {String} namespaces
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function save(namespaces) {
|
||||
try {
|
||||
if (null == namespaces) {
|
||||
exports.storage.removeItem('debug');
|
||||
} else {
|
||||
exports.storage.debug = namespaces;
|
||||
}
|
||||
} catch(e) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load `namespaces`.
|
||||
*
|
||||
* @return {String} returns the previously persisted debug modes
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function load() {
|
||||
var r;
|
||||
try {
|
||||
r = exports.storage.debug;
|
||||
} catch(e) {}
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable namespaces listed in `localStorage.debug` initially.
|
||||
*/
|
||||
|
||||
exports.enable(load());
|
||||
|
||||
/**
|
||||
* Localstorage attempts to return the localstorage.
|
||||
*
|
||||
* This is necessary because safari throws
|
||||
* when a user disables cookies/localstorage
|
||||
* and you attempt to access it.
|
||||
*
|
||||
* @return {LocalStorage}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function localstorage(){
|
||||
try {
|
||||
return window.localStorage;
|
||||
} catch (e) {}
|
||||
}
|
||||
19
build/node_modules/node-rest-client/node_modules/debug/component.json
generated
vendored
Normal file
19
build/node_modules/node-rest-client/node_modules/debug/component.json
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "debug",
|
||||
"repo": "visionmedia/debug",
|
||||
"description": "small debugging utility",
|
||||
"version": "2.2.0",
|
||||
"keywords": [
|
||||
"debug",
|
||||
"log",
|
||||
"debugger"
|
||||
],
|
||||
"main": "browser.js",
|
||||
"scripts": [
|
||||
"browser.js",
|
||||
"debug.js"
|
||||
],
|
||||
"dependencies": {
|
||||
"rauchg/ms.js": "0.7.1"
|
||||
}
|
||||
}
|
||||
197
build/node_modules/node-rest-client/node_modules/debug/debug.js
generated
vendored
Normal file
197
build/node_modules/node-rest-client/node_modules/debug/debug.js
generated
vendored
Normal file
@@ -0,0 +1,197 @@
|
||||
|
||||
/**
|
||||
* This is the common logic for both the Node.js and web browser
|
||||
* implementations of `debug()`.
|
||||
*
|
||||
* Expose `debug()` as the module.
|
||||
*/
|
||||
|
||||
exports = module.exports = debug;
|
||||
exports.coerce = coerce;
|
||||
exports.disable = disable;
|
||||
exports.enable = enable;
|
||||
exports.enabled = enabled;
|
||||
exports.humanize = require('ms');
|
||||
|
||||
/**
|
||||
* The currently active debug mode names, and names to skip.
|
||||
*/
|
||||
|
||||
exports.names = [];
|
||||
exports.skips = [];
|
||||
|
||||
/**
|
||||
* Map of special "%n" handling functions, for the debug "format" argument.
|
||||
*
|
||||
* Valid key names are a single, lowercased letter, i.e. "n".
|
||||
*/
|
||||
|
||||
exports.formatters = {};
|
||||
|
||||
/**
|
||||
* Previously assigned color.
|
||||
*/
|
||||
|
||||
var prevColor = 0;
|
||||
|
||||
/**
|
||||
* Previous log timestamp.
|
||||
*/
|
||||
|
||||
var prevTime;
|
||||
|
||||
/**
|
||||
* Select a color.
|
||||
*
|
||||
* @return {Number}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function selectColor() {
|
||||
return exports.colors[prevColor++ % exports.colors.length];
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a debugger with the given `namespace`.
|
||||
*
|
||||
* @param {String} namespace
|
||||
* @return {Function}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function debug(namespace) {
|
||||
|
||||
// define the `disabled` version
|
||||
function disabled() {
|
||||
}
|
||||
disabled.enabled = false;
|
||||
|
||||
// define the `enabled` version
|
||||
function enabled() {
|
||||
|
||||
var self = enabled;
|
||||
|
||||
// set `diff` timestamp
|
||||
var curr = +new Date();
|
||||
var ms = curr - (prevTime || curr);
|
||||
self.diff = ms;
|
||||
self.prev = prevTime;
|
||||
self.curr = curr;
|
||||
prevTime = curr;
|
||||
|
||||
// add the `color` if not set
|
||||
if (null == self.useColors) self.useColors = exports.useColors();
|
||||
if (null == self.color && self.useColors) self.color = selectColor();
|
||||
|
||||
var args = Array.prototype.slice.call(arguments);
|
||||
|
||||
args[0] = exports.coerce(args[0]);
|
||||
|
||||
if ('string' !== typeof args[0]) {
|
||||
// anything else let's inspect with %o
|
||||
args = ['%o'].concat(args);
|
||||
}
|
||||
|
||||
// apply any `formatters` transformations
|
||||
var index = 0;
|
||||
args[0] = args[0].replace(/%([a-z%])/g, function(match, format) {
|
||||
// if we encounter an escaped % then don't increase the array index
|
||||
if (match === '%%') return match;
|
||||
index++;
|
||||
var formatter = exports.formatters[format];
|
||||
if ('function' === typeof formatter) {
|
||||
var val = args[index];
|
||||
match = formatter.call(self, val);
|
||||
|
||||
// now we need to remove `args[index]` since it's inlined in the `format`
|
||||
args.splice(index, 1);
|
||||
index--;
|
||||
}
|
||||
return match;
|
||||
});
|
||||
|
||||
if ('function' === typeof exports.formatArgs) {
|
||||
args = exports.formatArgs.apply(self, args);
|
||||
}
|
||||
var logFn = enabled.log || exports.log || console.log.bind(console);
|
||||
logFn.apply(self, args);
|
||||
}
|
||||
enabled.enabled = true;
|
||||
|
||||
var fn = exports.enabled(namespace) ? enabled : disabled;
|
||||
|
||||
fn.namespace = namespace;
|
||||
|
||||
return fn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables a debug mode by namespaces. This can include modes
|
||||
* separated by a colon and wildcards.
|
||||
*
|
||||
* @param {String} namespaces
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function enable(namespaces) {
|
||||
exports.save(namespaces);
|
||||
|
||||
var split = (namespaces || '').split(/[\s,]+/);
|
||||
var len = split.length;
|
||||
|
||||
for (var i = 0; i < len; i++) {
|
||||
if (!split[i]) continue; // ignore empty strings
|
||||
namespaces = split[i].replace(/\*/g, '.*?');
|
||||
if (namespaces[0] === '-') {
|
||||
exports.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
|
||||
} else {
|
||||
exports.names.push(new RegExp('^' + namespaces + '$'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable debug output.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function disable() {
|
||||
exports.enable('');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given mode name is enabled, false otherwise.
|
||||
*
|
||||
* @param {String} name
|
||||
* @return {Boolean}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function enabled(name) {
|
||||
var i, len;
|
||||
for (i = 0, len = exports.skips.length; i < len; i++) {
|
||||
if (exports.skips[i].test(name)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for (i = 0, len = exports.names.length; i < len; i++) {
|
||||
if (exports.names[i].test(name)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Coerce `val`.
|
||||
*
|
||||
* @param {Mixed} val
|
||||
* @return {Mixed}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function coerce(val) {
|
||||
if (val instanceof Error) return val.stack || val.message;
|
||||
return val;
|
||||
}
|
||||
209
build/node_modules/node-rest-client/node_modules/debug/node.js
generated
vendored
Normal file
209
build/node_modules/node-rest-client/node_modules/debug/node.js
generated
vendored
Normal file
@@ -0,0 +1,209 @@
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var tty = require('tty');
|
||||
var util = require('util');
|
||||
|
||||
/**
|
||||
* This is the Node.js implementation of `debug()`.
|
||||
*
|
||||
* Expose `debug()` as the module.
|
||||
*/
|
||||
|
||||
exports = module.exports = require('./debug');
|
||||
exports.log = log;
|
||||
exports.formatArgs = formatArgs;
|
||||
exports.save = save;
|
||||
exports.load = load;
|
||||
exports.useColors = useColors;
|
||||
|
||||
/**
|
||||
* Colors.
|
||||
*/
|
||||
|
||||
exports.colors = [6, 2, 3, 4, 5, 1];
|
||||
|
||||
/**
|
||||
* The file descriptor to write the `debug()` calls to.
|
||||
* Set the `DEBUG_FD` env variable to override with another value. i.e.:
|
||||
*
|
||||
* $ DEBUG_FD=3 node script.js 3>debug.log
|
||||
*/
|
||||
|
||||
var fd = parseInt(process.env.DEBUG_FD, 10) || 2;
|
||||
var stream = 1 === fd ? process.stdout :
|
||||
2 === fd ? process.stderr :
|
||||
createWritableStdioStream(fd);
|
||||
|
||||
/**
|
||||
* Is stdout a TTY? Colored output is enabled when `true`.
|
||||
*/
|
||||
|
||||
function useColors() {
|
||||
var debugColors = (process.env.DEBUG_COLORS || '').trim().toLowerCase();
|
||||
if (0 === debugColors.length) {
|
||||
return tty.isatty(fd);
|
||||
} else {
|
||||
return '0' !== debugColors
|
||||
&& 'no' !== debugColors
|
||||
&& 'false' !== debugColors
|
||||
&& 'disabled' !== debugColors;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Map %o to `util.inspect()`, since Node doesn't do that out of the box.
|
||||
*/
|
||||
|
||||
var inspect = (4 === util.inspect.length ?
|
||||
// node <= 0.8.x
|
||||
function (v, colors) {
|
||||
return util.inspect(v, void 0, void 0, colors);
|
||||
} :
|
||||
// node > 0.8.x
|
||||
function (v, colors) {
|
||||
return util.inspect(v, { colors: colors });
|
||||
}
|
||||
);
|
||||
|
||||
exports.formatters.o = function(v) {
|
||||
return inspect(v, this.useColors)
|
||||
.replace(/\s*\n\s*/g, ' ');
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds ANSI color escape codes if enabled.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function formatArgs() {
|
||||
var args = arguments;
|
||||
var useColors = this.useColors;
|
||||
var name = this.namespace;
|
||||
|
||||
if (useColors) {
|
||||
var c = this.color;
|
||||
|
||||
args[0] = ' \u001b[3' + c + ';1m' + name + ' '
|
||||
+ '\u001b[0m'
|
||||
+ args[0] + '\u001b[3' + c + 'm'
|
||||
+ ' +' + exports.humanize(this.diff) + '\u001b[0m';
|
||||
} else {
|
||||
args[0] = new Date().toUTCString()
|
||||
+ ' ' + name + ' ' + args[0];
|
||||
}
|
||||
return args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invokes `console.error()` with the specified arguments.
|
||||
*/
|
||||
|
||||
function log() {
|
||||
return stream.write(util.format.apply(this, arguments) + '\n');
|
||||
}
|
||||
|
||||
/**
|
||||
* Save `namespaces`.
|
||||
*
|
||||
* @param {String} namespaces
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function save(namespaces) {
|
||||
if (null == namespaces) {
|
||||
// If you set a process.env field to null or undefined, it gets cast to the
|
||||
// string 'null' or 'undefined'. Just delete instead.
|
||||
delete process.env.DEBUG;
|
||||
} else {
|
||||
process.env.DEBUG = namespaces;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load `namespaces`.
|
||||
*
|
||||
* @return {String} returns the previously persisted debug modes
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function load() {
|
||||
return process.env.DEBUG;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copied from `node/src/node.js`.
|
||||
*
|
||||
* XXX: It's lame that node doesn't expose this API out-of-the-box. It also
|
||||
* relies on the undocumented `tty_wrap.guessHandleType()` which is also lame.
|
||||
*/
|
||||
|
||||
function createWritableStdioStream (fd) {
|
||||
var stream;
|
||||
var tty_wrap = process.binding('tty_wrap');
|
||||
|
||||
// Note stream._type is used for test-module-load-list.js
|
||||
|
||||
switch (tty_wrap.guessHandleType(fd)) {
|
||||
case 'TTY':
|
||||
stream = new tty.WriteStream(fd);
|
||||
stream._type = 'tty';
|
||||
|
||||
// Hack to have stream not keep the event loop alive.
|
||||
// See https://github.com/joyent/node/issues/1726
|
||||
if (stream._handle && stream._handle.unref) {
|
||||
stream._handle.unref();
|
||||
}
|
||||
break;
|
||||
|
||||
case 'FILE':
|
||||
var fs = require('fs');
|
||||
stream = new fs.SyncWriteStream(fd, { autoClose: false });
|
||||
stream._type = 'fs';
|
||||
break;
|
||||
|
||||
case 'PIPE':
|
||||
case 'TCP':
|
||||
var net = require('net');
|
||||
stream = new net.Socket({
|
||||
fd: fd,
|
||||
readable: false,
|
||||
writable: true
|
||||
});
|
||||
|
||||
// FIXME Should probably have an option in net.Socket to create a
|
||||
// stream from an existing fd which is writable only. But for now
|
||||
// we'll just add this hack and set the `readable` member to false.
|
||||
// Test: ./node test/fixtures/echo.js < /etc/passwd
|
||||
stream.readable = false;
|
||||
stream.read = null;
|
||||
stream._type = 'pipe';
|
||||
|
||||
// FIXME Hack to have stream not keep the event loop alive.
|
||||
// See https://github.com/joyent/node/issues/1726
|
||||
if (stream._handle && stream._handle.unref) {
|
||||
stream._handle.unref();
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
// Probably an error on in uv_guess_handle()
|
||||
throw new Error('Implement me. Unknown stream file type!');
|
||||
}
|
||||
|
||||
// For supporting legacy API we put the FD here.
|
||||
stream.fd = fd;
|
||||
|
||||
stream._isStdio = true;
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable namespaces listed in `process.env.DEBUG` initially.
|
||||
*/
|
||||
|
||||
exports.enable(load());
|
||||
70
build/node_modules/node-rest-client/node_modules/debug/package.json
generated
vendored
Normal file
70
build/node_modules/node-rest-client/node_modules/debug/package.json
generated
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
{
|
||||
"_from": "debug@~2.2.0",
|
||||
"_id": "debug@2.2.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-+HBX6ZWxofauaklgZkE3vFbwOdo=",
|
||||
"_location": "/node-rest-client/debug",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "debug@~2.2.0",
|
||||
"name": "debug",
|
||||
"escapedName": "debug",
|
||||
"rawSpec": "~2.2.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "~2.2.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/node-rest-client"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/debug/-/debug-2.2.0.tgz",
|
||||
"_shasum": "f87057e995b1a1f6ae6a4960664137bc56f039da",
|
||||
"_spec": "debug@~2.2.0",
|
||||
"_where": "/Users/asciidisco/Desktop/asciidisco.com/build/node_modules/node-rest-client",
|
||||
"author": {
|
||||
"name": "TJ Holowaychuk",
|
||||
"email": "tj@vision-media.ca"
|
||||
},
|
||||
"browser": "./browser.js",
|
||||
"bugs": {
|
||||
"url": "https://github.com/visionmedia/debug/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"component": {
|
||||
"scripts": {
|
||||
"debug/index.js": "browser.js",
|
||||
"debug/debug.js": "debug.js"
|
||||
}
|
||||
},
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Nathan Rajlich",
|
||||
"email": "nathan@tootallnate.net",
|
||||
"url": "http://n8.io"
|
||||
}
|
||||
],
|
||||
"dependencies": {
|
||||
"ms": "0.7.1"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "small debugging utility",
|
||||
"devDependencies": {
|
||||
"browserify": "9.0.3",
|
||||
"mocha": "*"
|
||||
},
|
||||
"homepage": "https://github.com/visionmedia/debug#readme",
|
||||
"keywords": [
|
||||
"debug",
|
||||
"log",
|
||||
"debugger"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "./node.js",
|
||||
"name": "debug",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/visionmedia/debug.git"
|
||||
},
|
||||
"version": "2.2.0"
|
||||
}
|
||||
5
build/node_modules/node-rest-client/node_modules/ms/.npmignore
generated
vendored
Normal file
5
build/node_modules/node-rest-client/node_modules/ms/.npmignore
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
node_modules
|
||||
test
|
||||
History.md
|
||||
Makefile
|
||||
component.json
|
||||
66
build/node_modules/node-rest-client/node_modules/ms/History.md
generated
vendored
Normal file
66
build/node_modules/node-rest-client/node_modules/ms/History.md
generated
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
|
||||
0.7.1 / 2015-04-20
|
||||
==================
|
||||
|
||||
* prevent extraordinary long inputs (@evilpacket)
|
||||
* Fixed broken readme link
|
||||
|
||||
0.7.0 / 2014-11-24
|
||||
==================
|
||||
|
||||
* add time abbreviations, updated tests and readme for the new units
|
||||
* fix example in the readme.
|
||||
* add LICENSE file
|
||||
|
||||
0.6.2 / 2013-12-05
|
||||
==================
|
||||
|
||||
* Adding repository section to package.json to suppress warning from NPM.
|
||||
|
||||
0.6.1 / 2013-05-10
|
||||
==================
|
||||
|
||||
* fix singularization [visionmedia]
|
||||
|
||||
0.6.0 / 2013-03-15
|
||||
==================
|
||||
|
||||
* fix minutes
|
||||
|
||||
0.5.1 / 2013-02-24
|
||||
==================
|
||||
|
||||
* add component namespace
|
||||
|
||||
0.5.0 / 2012-11-09
|
||||
==================
|
||||
|
||||
* add short formatting as default and .long option
|
||||
* add .license property to component.json
|
||||
* add version to component.json
|
||||
|
||||
0.4.0 / 2012-10-22
|
||||
==================
|
||||
|
||||
* add rounding to fix crazy decimals
|
||||
|
||||
0.3.0 / 2012-09-07
|
||||
==================
|
||||
|
||||
* fix `ms(<String>)` [visionmedia]
|
||||
|
||||
0.2.0 / 2012-09-03
|
||||
==================
|
||||
|
||||
* add component.json [visionmedia]
|
||||
* add days support [visionmedia]
|
||||
* add hours support [visionmedia]
|
||||
* add minutes support [visionmedia]
|
||||
* add seconds support [visionmedia]
|
||||
* add ms string support [visionmedia]
|
||||
* refactor tests to facilitate ms(number) [visionmedia]
|
||||
|
||||
0.1.0 / 2012-03-07
|
||||
==================
|
||||
|
||||
* Initial release
|
||||
20
build/node_modules/node-rest-client/node_modules/ms/LICENSE
generated
vendored
Normal file
20
build/node_modules/node-rest-client/node_modules/ms/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2014 Guillermo Rauch <rauchg@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
35
build/node_modules/node-rest-client/node_modules/ms/README.md
generated
vendored
Normal file
35
build/node_modules/node-rest-client/node_modules/ms/README.md
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
# ms.js: miliseconds conversion utility
|
||||
|
||||
```js
|
||||
ms('2 days') // 172800000
|
||||
ms('1d') // 86400000
|
||||
ms('10h') // 36000000
|
||||
ms('2.5 hrs') // 9000000
|
||||
ms('2h') // 7200000
|
||||
ms('1m') // 60000
|
||||
ms('5s') // 5000
|
||||
ms('100') // 100
|
||||
```
|
||||
|
||||
```js
|
||||
ms(60000) // "1m"
|
||||
ms(2 * 60000) // "2m"
|
||||
ms(ms('10 hours')) // "10h"
|
||||
```
|
||||
|
||||
```js
|
||||
ms(60000, { long: true }) // "1 minute"
|
||||
ms(2 * 60000, { long: true }) // "2 minutes"
|
||||
ms(ms('10 hours'), { long: true }) // "10 hours"
|
||||
```
|
||||
|
||||
- Node/Browser compatible. Published as [`ms`](https://www.npmjs.org/package/ms) in [NPM](http://nodejs.org/download).
|
||||
- If a number is supplied to `ms`, a string with a unit is returned.
|
||||
- If a string that contains the number is supplied, it returns it as
|
||||
a number (e.g: it returns `100` for `'100'`).
|
||||
- If you pass a string with a number and a valid unit, the number of
|
||||
equivalent ms is returned.
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
125
build/node_modules/node-rest-client/node_modules/ms/index.js
generated
vendored
Normal file
125
build/node_modules/node-rest-client/node_modules/ms/index.js
generated
vendored
Normal file
@@ -0,0 +1,125 @@
|
||||
/**
|
||||
* Helpers.
|
||||
*/
|
||||
|
||||
var s = 1000;
|
||||
var m = s * 60;
|
||||
var h = m * 60;
|
||||
var d = h * 24;
|
||||
var y = d * 365.25;
|
||||
|
||||
/**
|
||||
* Parse or format the given `val`.
|
||||
*
|
||||
* Options:
|
||||
*
|
||||
* - `long` verbose formatting [false]
|
||||
*
|
||||
* @param {String|Number} val
|
||||
* @param {Object} options
|
||||
* @return {String|Number}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
module.exports = function(val, options){
|
||||
options = options || {};
|
||||
if ('string' == typeof val) return parse(val);
|
||||
return options.long
|
||||
? long(val)
|
||||
: short(val);
|
||||
};
|
||||
|
||||
/**
|
||||
* Parse the given `str` and return milliseconds.
|
||||
*
|
||||
* @param {String} str
|
||||
* @return {Number}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function parse(str) {
|
||||
str = '' + str;
|
||||
if (str.length > 10000) return;
|
||||
var match = /^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(str);
|
||||
if (!match) return;
|
||||
var n = parseFloat(match[1]);
|
||||
var type = (match[2] || 'ms').toLowerCase();
|
||||
switch (type) {
|
||||
case 'years':
|
||||
case 'year':
|
||||
case 'yrs':
|
||||
case 'yr':
|
||||
case 'y':
|
||||
return n * y;
|
||||
case 'days':
|
||||
case 'day':
|
||||
case 'd':
|
||||
return n * d;
|
||||
case 'hours':
|
||||
case 'hour':
|
||||
case 'hrs':
|
||||
case 'hr':
|
||||
case 'h':
|
||||
return n * h;
|
||||
case 'minutes':
|
||||
case 'minute':
|
||||
case 'mins':
|
||||
case 'min':
|
||||
case 'm':
|
||||
return n * m;
|
||||
case 'seconds':
|
||||
case 'second':
|
||||
case 'secs':
|
||||
case 'sec':
|
||||
case 's':
|
||||
return n * s;
|
||||
case 'milliseconds':
|
||||
case 'millisecond':
|
||||
case 'msecs':
|
||||
case 'msec':
|
||||
case 'ms':
|
||||
return n;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Short format for `ms`.
|
||||
*
|
||||
* @param {Number} ms
|
||||
* @return {String}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function short(ms) {
|
||||
if (ms >= d) return Math.round(ms / d) + 'd';
|
||||
if (ms >= h) return Math.round(ms / h) + 'h';
|
||||
if (ms >= m) return Math.round(ms / m) + 'm';
|
||||
if (ms >= s) return Math.round(ms / s) + 's';
|
||||
return ms + 'ms';
|
||||
}
|
||||
|
||||
/**
|
||||
* Long format for `ms`.
|
||||
*
|
||||
* @param {Number} ms
|
||||
* @return {String}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function long(ms) {
|
||||
return plural(ms, d, 'day')
|
||||
|| plural(ms, h, 'hour')
|
||||
|| plural(ms, m, 'minute')
|
||||
|| plural(ms, s, 'second')
|
||||
|| ms + ' ms';
|
||||
}
|
||||
|
||||
/**
|
||||
* Pluralization helper.
|
||||
*/
|
||||
|
||||
function plural(ms, n, name) {
|
||||
if (ms < n) return;
|
||||
if (ms < n * 1.5) return Math.floor(ms / n) + ' ' + name;
|
||||
return Math.ceil(ms / n) + ' ' + name + 's';
|
||||
}
|
||||
49
build/node_modules/node-rest-client/node_modules/ms/package.json
generated
vendored
Normal file
49
build/node_modules/node-rest-client/node_modules/ms/package.json
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
{
|
||||
"_from": "ms@0.7.1",
|
||||
"_id": "ms@0.7.1",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-nNE8A62/8ltl7/3nzoZO6VIBcJg=",
|
||||
"_location": "/node-rest-client/ms",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "ms@0.7.1",
|
||||
"name": "ms",
|
||||
"escapedName": "ms",
|
||||
"rawSpec": "0.7.1",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "0.7.1"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/node-rest-client/debug"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/ms/-/ms-0.7.1.tgz",
|
||||
"_shasum": "9cd13c03adbff25b65effde7ce864ee952017098",
|
||||
"_spec": "ms@0.7.1",
|
||||
"_where": "/Users/asciidisco/Desktop/asciidisco.com/build/node_modules/node-rest-client/node_modules/debug",
|
||||
"bugs": {
|
||||
"url": "https://github.com/guille/ms.js/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"component": {
|
||||
"scripts": {
|
||||
"ms/index.js": "index.js"
|
||||
}
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "Tiny ms conversion utility",
|
||||
"devDependencies": {
|
||||
"expect.js": "*",
|
||||
"mocha": "*",
|
||||
"serve": "*"
|
||||
},
|
||||
"homepage": "https://github.com/guille/ms.js#readme",
|
||||
"main": "./index",
|
||||
"name": "ms",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/guille/ms.js.git"
|
||||
},
|
||||
"version": "0.7.1"
|
||||
}
|
||||
54
build/node_modules/node-rest-client/package.json
generated
vendored
Normal file
54
build/node_modules/node-rest-client/package.json
generated
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
{
|
||||
"_from": "node-rest-client@^1.5.1",
|
||||
"_id": "node-rest-client@1.8.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-jTxWa4F+JzlMtyc3g6Qcrv4+WVU=",
|
||||
"_location": "/node-rest-client",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "node-rest-client@^1.5.1",
|
||||
"name": "node-rest-client",
|
||||
"escapedName": "node-rest-client",
|
||||
"rawSpec": "^1.5.1",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^1.5.1"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/favicons"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/node-rest-client/-/node-rest-client-1.8.0.tgz",
|
||||
"_shasum": "8d3c566b817e27394cb7273783a41caefe3e5955",
|
||||
"_spec": "node-rest-client@^1.5.1",
|
||||
"_where": "/Users/asciidisco/Desktop/asciidisco.com/build/node_modules/favicons",
|
||||
"author": {
|
||||
"name": "Alejandro Alvarez Acero"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/aacerox/node-rest-client/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"debug": "~2.2.0",
|
||||
"xml2js": ">=0.2.4"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "node API REST client",
|
||||
"devDependencies": {
|
||||
"jasmine-node": ">=1.2.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": "*"
|
||||
},
|
||||
"homepage": "https://github.com/aacerox/node-rest-client#readme",
|
||||
"license": "MIT",
|
||||
"main": "./lib/node-rest-client",
|
||||
"name": "node-rest-client",
|
||||
"optionalDependencies": {},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/aacerox/node-rest-client.git"
|
||||
},
|
||||
"version": "1.8.0"
|
||||
}
|
||||
462
build/node_modules/node-rest-client/readme.md
generated
vendored
Normal file
462
build/node_modules/node-rest-client/readme.md
generated
vendored
Normal file
@@ -0,0 +1,462 @@
|
||||
# REST Client for Node.js
|
||||
|
||||
**NOTE:** _Since version 0.8.0 node does not contain node-waf anymore. The node-zlib package which node-rest-client make use of, depends on node-waf.Fortunately since version 0.8.0 zlib is a core dependency of node, so since version 1.0 of node-rest-client the explicit dependency to "zlib" has been removed from package.json. therefore if you are using a version below 0.8.0 of node please use a versión below 1.0.0 of "node-rest-client". _
|
||||
|
||||
Allows connecting to any API REST and get results as js Object. The client has the following features:
|
||||
|
||||
- Transparent HTTP/HTTPS connection to remote API sites.
|
||||
- Allows simple HTTP basic authentication.
|
||||
- Allows most common HTTP operations: GET, POST, PUT, DELETE, PATCH.
|
||||
- Direct or through proxy connection to remote API sites.
|
||||
- Register remote API operations as client own methods, simplifying reuse.
|
||||
- Automatic parsing of XML and JSON response documents as js objects.
|
||||
- Dynamic path and query parameters and request headers.
|
||||
- Improved Error handling mechanism (client or specific request)
|
||||
- Added support for compressed responses: gzip and deflate
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
$ npm install node-rest-client
|
||||
|
||||
## Usages
|
||||
|
||||
### Simple HTTP GET
|
||||
|
||||
Client has 2 ways to call a REST service: direct or using registered methods
|
||||
|
||||
```javascript
|
||||
var Client = require('node-rest-client').Client;
|
||||
|
||||
var client = new Client();
|
||||
|
||||
// direct way
|
||||
client.get("http://remote.site/rest/xml/method", function (data, response) {
|
||||
// parsed response body as js object
|
||||
console.log(data);
|
||||
// raw response
|
||||
console.log(response);
|
||||
});
|
||||
|
||||
// registering remote methods
|
||||
client.registerMethod("jsonMethod", "http://remote.site/rest/json/method", "GET");
|
||||
|
||||
client.methods.jsonMethod(function (data, response) {
|
||||
// parsed response body as js object
|
||||
console.log(data);
|
||||
// raw response
|
||||
console.log(response);
|
||||
});
|
||||
```
|
||||
|
||||
### HTTP POST
|
||||
|
||||
POST, PUT or PATCH method invocation are configured like GET calls with the difference that you have to set "Content-Type" header in args passed to client method invocation:
|
||||
|
||||
```javascript
|
||||
//Example POST method invocation
|
||||
var Client = require('node-rest-client').Client;
|
||||
|
||||
var client = new Client();
|
||||
|
||||
// set content-type header and data as json in args parameter
|
||||
var args = {
|
||||
data: { test: "hello" },
|
||||
headers: { "Content-Type": "application/json" }
|
||||
};
|
||||
|
||||
client.post("http://remote.site/rest/xml/method", args, function (data, response) {
|
||||
// parsed response body as js object
|
||||
console.log(data);
|
||||
// raw response
|
||||
console.log(response);
|
||||
});
|
||||
|
||||
// registering remote methods
|
||||
client.registerMethod("postMethod", "http://remote.site/rest/json/method", "POST");
|
||||
|
||||
client.methods.postMethod(args, function (data, response) {
|
||||
// parsed response body as js object
|
||||
console.log(data);
|
||||
// raw response
|
||||
console.log(response);
|
||||
});
|
||||
```
|
||||
If no "Content-Type" header is set as client arg POST,PUT and PATCH methods will not work properly.
|
||||
|
||||
|
||||
### Passing args to registered methods
|
||||
|
||||
You can pass diferents args to registered methods, simplifying reuse: path replace parameters, query parameters, custom headers
|
||||
|
||||
```javascript
|
||||
var Client = require('node-rest-client').Client;
|
||||
|
||||
// direct way
|
||||
var client = new Client();
|
||||
|
||||
var args = {
|
||||
data: { test: "hello" }, // data passed to REST method (only useful in POST, PUT or PATCH methods)
|
||||
path: { "id": 120 }, // path substitution var
|
||||
parameters: { arg1: "hello", arg2: "world" }, // query parameter substitution vars
|
||||
headers: { "test-header": "client-api" } // request headers
|
||||
};
|
||||
|
||||
|
||||
client.get("http://remote.site/rest/json/${id}/method?arg1=hello&arg2=world", args,
|
||||
function (data, response) {
|
||||
// parsed response body as js object
|
||||
console.log(data);
|
||||
// raw response
|
||||
console.log(response);
|
||||
});
|
||||
|
||||
|
||||
// registering remote methods
|
||||
client.registerMethod("jsonMethod", "http://remote.site/rest/json/${id}/method", "GET");
|
||||
|
||||
|
||||
/* this would construct the following URL before invocation
|
||||
*
|
||||
* http://remote.site/rest/json/120/method?arg1=hello&arg2=world
|
||||
*
|
||||
*/
|
||||
client.methods.jsonMethod(args, function (data, response) {
|
||||
// parsed response body as js object
|
||||
console.log(data);
|
||||
// raw response
|
||||
console.log(response);
|
||||
});
|
||||
```
|
||||
|
||||
You can even use path placeholders in query string in direct connection:
|
||||
|
||||
```javascript
|
||||
var Client = require('node-rest-client').Client;
|
||||
|
||||
// direct way
|
||||
var client = new Client();
|
||||
|
||||
var args = {
|
||||
path: { "id": 120, "arg1": "hello", "arg2": "world" },
|
||||
parameters: { arg1: "hello", arg2: "world" },
|
||||
headers: { "test-header": "client-api" }
|
||||
};
|
||||
|
||||
client.get("http://remote.site/rest/json/${id}/method?arg1=${arg1}&arg2=${arg2}", args,
|
||||
function (data, response) {
|
||||
// parsed response body as js object
|
||||
console.log(data);
|
||||
// raw response
|
||||
console.log(response);
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
|
||||
### HTTP POST and PUT methods
|
||||
|
||||
To send data to remote site using POST or PUT methods, just add a data attribute to args object:
|
||||
|
||||
```javascript
|
||||
var Client = require('node-rest-client').Client;
|
||||
|
||||
// direct way
|
||||
var client = new Client();
|
||||
|
||||
var args = {
|
||||
path: { "id": 120 },
|
||||
parameters: { arg1: "hello", arg2: "world" },
|
||||
headers: { "test-header": "client-api" },
|
||||
data: "<xml><arg1>hello</arg1><arg2>world</arg2></xml>"
|
||||
};
|
||||
|
||||
client.post("http://remote.site/rest/xml/${id}/method?arg1=hello&arg2=world", args, function (data, response) {
|
||||
// parsed response body as js object
|
||||
console.log(data);
|
||||
// raw response
|
||||
console.log(response);
|
||||
});
|
||||
|
||||
// registering remote methods
|
||||
client.registerMethod("xmlMethod", "http://remote.site/rest/xml/${id}/method", "POST");
|
||||
|
||||
|
||||
client.methods.xmlMethod(args, function (data, response) {
|
||||
// parsed response body as js object
|
||||
console.log(data);
|
||||
// raw response
|
||||
console.log(response);
|
||||
});
|
||||
|
||||
// posted data can be js object
|
||||
var args_js = {
|
||||
path: { "id": 120 },
|
||||
parameters: { arg1: "hello", arg2: "world" },
|
||||
headers: { "test-header": "client-api" },
|
||||
data: { "arg1": "hello", "arg2": 123 }
|
||||
};
|
||||
|
||||
client.methods.xmlMethod(args_js, function (data, response) {
|
||||
// parsed response body as js object
|
||||
console.log(data);
|
||||
// raw response
|
||||
console.log(response);
|
||||
});
|
||||
```
|
||||
|
||||
### Request/Response configuration
|
||||
|
||||
It's also possible to configure each request and response, passing its configuration as an
|
||||
additional argument in method call.
|
||||
|
||||
```javascript
|
||||
var client = new Client();
|
||||
|
||||
// request and response additional configuration
|
||||
var args = {
|
||||
path: { "id": 120 },
|
||||
parameters: { arg1: "hello", arg2: "world" },
|
||||
headers: { "test-header": "client-api" },
|
||||
data: "<xml><arg1>hello</arg1><arg2>world</arg2></xml>",
|
||||
requestConfig: {
|
||||
timeout: 1000, //request timeout in milliseconds
|
||||
noDelay: true, //Enable/disable the Nagle algorithm
|
||||
keepAlive: true, //Enable/disable keep-alive functionalityidle socket.
|
||||
keepAliveDelay: 1000 //and optionally set the initial delay before the first keepalive probe is sent
|
||||
},
|
||||
responseConfig: {
|
||||
timeout: 1000 //response timeout
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
client.post("http://remote.site/rest/xml/${id}/method?arg1=hello&arg2=world", args, function (data, response) {
|
||||
// parsed response body as js object
|
||||
console.log(data);
|
||||
// raw response
|
||||
console.log(response);
|
||||
});
|
||||
```
|
||||
If you want to handle timeout events both in the request and in the response just add a new "requestTimeout"
|
||||
or "responseTimeout" event handler to clientRequest returned by method call.
|
||||
|
||||
```javascript
|
||||
var client = new Client();
|
||||
|
||||
// request and response additional configuration
|
||||
var args = {
|
||||
path: { "id": 120 },
|
||||
parameters: { arg1: "hello", arg2: "world" },
|
||||
headers: { "test-header": "client-api" },
|
||||
data: "<xml><arg1>hello</arg1><arg2>world</arg2></xml>",
|
||||
requestConfig: {
|
||||
timeout: 1000, //request timeout in milliseconds
|
||||
noDelay: true, //Enable/disable the Nagle algorithm
|
||||
keepAlive: true, //Enable/disable keep-alive functionalityidle socket.
|
||||
keepAliveDelay: 1000 //and optionally set the initial delay before the first keepalive probe is sent
|
||||
},
|
||||
responseConfig: {
|
||||
timeout: 1000 //response timeout
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
var req = client.post("http://remote.site/rest/xml/${id}/method?arg1=hello&arg2=world", args, function (data, response) {
|
||||
// parsed response body as js object
|
||||
console.log(data);
|
||||
// raw response
|
||||
console.log(response);
|
||||
});
|
||||
|
||||
req.on('requestTimeout', function (req) {
|
||||
console.log('request has expired');
|
||||
req.abort();
|
||||
});
|
||||
|
||||
req.on('responseTimeout', function (res) {
|
||||
console.log('response has expired');
|
||||
|
||||
});
|
||||
|
||||
//it's usefull to handle request errors to avoid, for example, socket hang up errors on request timeouts
|
||||
req.on('error', function (err) {
|
||||
console.log('request error', err);
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
### Connect through proxy
|
||||
|
||||
Just pass proxy configuration as option to client.
|
||||
|
||||
|
||||
```javascript
|
||||
var Client = require('node-rest-client').Client;
|
||||
|
||||
// configure proxy
|
||||
var options_proxy = {
|
||||
proxy: {
|
||||
host: "proxy.foo.com",
|
||||
port: 8080,
|
||||
user: "proxyuser",
|
||||
password: "123",
|
||||
tunnel: true
|
||||
}
|
||||
};
|
||||
|
||||
var client = new Client(options_proxy);
|
||||
```
|
||||
|
||||
client has 2 ways to connect to target site through a proxy server: tunnel or direct request, the first one is the default option
|
||||
so if you want to use direct request you must set tunnel off.
|
||||
|
||||
```javascript
|
||||
var Client = require('node-rest-client').Client;
|
||||
|
||||
// configure proxy
|
||||
var options_proxy = {
|
||||
proxy: {
|
||||
host: "proxy.foo.com",
|
||||
port: 8080,
|
||||
user: "proxyuser",
|
||||
password: "123",
|
||||
tunnel: false // use direct request to proxy
|
||||
}
|
||||
};
|
||||
|
||||
var client = new Client(options_proxy);
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Basic HTTP auth
|
||||
|
||||
Just pass username and password or just username, if no password is required by remote site, as option to client. Every request done with the client will pass username and password or just username if no password is required as basic authorization header.
|
||||
|
||||
```javascript
|
||||
var Client = require('node-rest-client').Client;
|
||||
|
||||
// configure basic http auth for every request
|
||||
var options_auth = { user: "admin", password: "123" };
|
||||
|
||||
var client = new Client(options_auth);
|
||||
```
|
||||
|
||||
### Options parameters
|
||||
|
||||
You can pass the following args when creating a new client:
|
||||
|
||||
```javascript
|
||||
var options = {
|
||||
// proxy configuration
|
||||
proxy: {
|
||||
host: "proxy.foo.com", // proxy host
|
||||
port: 8080, // proxy port
|
||||
user: "ellen", // proxy username if required
|
||||
password: "ripley" // proxy pass if required
|
||||
},
|
||||
// aditional connection options passed to node http.request y https.request methods
|
||||
// (ie: options to connect to IIS with SSL)
|
||||
connection: {
|
||||
secureOptions: constants.SSL_OP_NO_TLSv1_2,
|
||||
ciphers: 'ECDHE-RSA-AES256-SHA:AES256-SHA:RC4-SHA:RC4:HIGH:!MD5:!aNULL:!EDH:!AESGCM',
|
||||
honorCipherOrder: true
|
||||
},
|
||||
// customize mime types for json or xml connections
|
||||
mimetypes: {
|
||||
json: ["application/json", "application/json;charset=utf-8"],
|
||||
xml: ["application/xml", "application/xml;charset=utf-8"]
|
||||
},
|
||||
user: "admin", // basic http auth username if required
|
||||
password: "123", // basic http auth password if required
|
||||
requestConfig: {
|
||||
timeout: 1000, //request timeout in milliseconds
|
||||
noDelay: true, //Enable/disable the Nagle algorithm
|
||||
keepAlive: true, //Enable/disable keep-alive functionalityidle socket.
|
||||
keepAliveDelay: 1000 //and optionally set the initial delay before the first keepalive probe is sent
|
||||
},
|
||||
responseConfig: {
|
||||
timeout: 1000 //response timeout
|
||||
}
|
||||
};
|
||||
```
|
||||
Note that requestConfig and responseConfig options if set on client instantiation apply to all of its requests/responses
|
||||
and is only overriden by request or reponse configs passed as args in method calls.
|
||||
|
||||
|
||||
### Managing Requests
|
||||
|
||||
Each REST method invocation returns a request object with specific request options and error, requestTimeout and responseTimeout event handlers.
|
||||
|
||||
```javascript
|
||||
var Client = require('node-rest-client').Client;
|
||||
|
||||
var client = new Client();
|
||||
|
||||
var args = {
|
||||
requesConfig: { timeout: 1000 },
|
||||
responseConfig: { timeout: 2000 }
|
||||
};
|
||||
|
||||
// direct way
|
||||
var req1 = client.get("http://remote.site/rest/xml/method", args, function (data, response) {
|
||||
// parsed response body as js object
|
||||
console.log(data);
|
||||
// raw response
|
||||
console.log(response);
|
||||
});
|
||||
|
||||
// view req1 options
|
||||
console.log(req1.options);
|
||||
|
||||
|
||||
req1.on('requestTimeout', function (req) {
|
||||
console.log("request has expired");
|
||||
req.abort();
|
||||
});
|
||||
|
||||
req1.on('responseTimeout', function (res) {
|
||||
console.log("response has expired");
|
||||
|
||||
});
|
||||
|
||||
|
||||
// registering remote methods
|
||||
client.registerMethod("jsonMethod", "http://remote.site/rest/json/method", "GET");
|
||||
|
||||
var req2 = client.methods.jsonMethod(function (data, response) {
|
||||
// parsed response body as js object
|
||||
console.log(data);
|
||||
// raw response
|
||||
console.log(response);
|
||||
});
|
||||
|
||||
// handling specific req2 errors
|
||||
req2.on('error', function (err) {
|
||||
console.log('something went wrong on req2!!', err.request.options);
|
||||
});
|
||||
```
|
||||
|
||||
### Error Handling
|
||||
|
||||
Now you can handle error events in two places: on client or on each request.
|
||||
|
||||
```javascript
|
||||
var client = new Client(options_auth);
|
||||
|
||||
// handling request error events
|
||||
client.get("http://remote.site/rest/xml/method", function (data, response) {
|
||||
// parsed response body as js object
|
||||
console.log(data);
|
||||
// raw response
|
||||
console.log(response);
|
||||
}).on('error', function (err) {
|
||||
console.log('something went wrong on the request', err.request.options);
|
||||
});
|
||||
|
||||
// handling client error events
|
||||
client.on('error', function (err) {
|
||||
console.error('Something went wrong on the client', err);
|
||||
});
|
||||
```
|
||||
34
build/node_modules/node-rest-client/test/message.json
generated
vendored
Normal file
34
build/node_modules/node-rest-client/test/message.json
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
{"catalog":{
|
||||
"books":[{
|
||||
"id":"bk101",
|
||||
"author":"Gambardella, Matthew",
|
||||
"title":"XML Developer's Guide",
|
||||
"genre":"Computer",
|
||||
"price":44.95,
|
||||
"publish_date":"2000-10-10",
|
||||
"description":"An in-depth look at creating applications with XML."
|
||||
},
|
||||
{
|
||||
"id":"bk102",
|
||||
"author":"Gambardella, Matthew",
|
||||
"title":"JAVA Developer's Guide",
|
||||
"genre":"Computer",
|
||||
"price":188.95,
|
||||
"publish_date":"2000-10-10",
|
||||
"description":"An in-depth look at creating applications with JAVA."
|
||||
},
|
||||
{
|
||||
"id":"bk103",
|
||||
"author":"Gambardella, Matthew",
|
||||
"title":"JSON Developer's Guide",
|
||||
"genre":"Computer",
|
||||
"price":422.95,
|
||||
"publish_date":"2000-10-10",
|
||||
"description":"An in-depth look at creating applications with JSON."
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
43
build/node_modules/node-rest-client/test/message.xml
generated
vendored
Normal file
43
build/node_modules/node-rest-client/test/message.xml
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
<?xml version="1.0"?>
|
||||
<catalog>
|
||||
<book id="bk101">
|
||||
<author>Gambardella, Matthew</author>
|
||||
<title>XML Developer's Guide</title>
|
||||
<genre>Computer</genre>
|
||||
<price>44.95</price>
|
||||
<publish_date>2000-10-01</publish_date>
|
||||
<description>An in-depth look at creating applications
|
||||
with XML.</description>
|
||||
</book>
|
||||
<book id="bk102">
|
||||
<author>Ralls, Kim</author>
|
||||
<title>Midnight Rain</title>
|
||||
<genre>Fantasy</genre>
|
||||
<price>5.95</price>
|
||||
<publish_date>2000-12-16</publish_date>
|
||||
<description>A former architect battles corporate zombies,
|
||||
an evil sorceress, and her own childhood to become queen
|
||||
of the world.</description>
|
||||
</book>
|
||||
<book id="bk103">
|
||||
<author>Corets, Eva</author>
|
||||
<title>Maeve Ascendant</title>
|
||||
<genre>Fantasy</genre>
|
||||
<price>5.95</price>
|
||||
<publish_date>2000-11-17</publish_date>
|
||||
<description>After the collapse of a nanotechnology
|
||||
society in England, the young survivors lay the
|
||||
foundation for a new society.</description>
|
||||
</book>
|
||||
<book id="bk104">
|
||||
<author>Corets, Eva</author>
|
||||
<title>Oberon's Legacy</title>
|
||||
<genre>Fantasy</genre>
|
||||
<price>5.95</price>
|
||||
<publish_date>2001-03-10</publish_date>
|
||||
<description>In post-apocalypse England, the mysterious
|
||||
agent known only as Oberon helps to create a new life
|
||||
for the inhabitants of London. Sequel to Maeve
|
||||
Ascendant.</description>
|
||||
</book>
|
||||
</catalog>
|
||||
32
build/node_modules/node-rest-client/test/specs.js
generated
vendored
Normal file
32
build/node_modules/node-rest-client/test/specs.js
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
var jasmine = require('jasmine-node');
|
||||
var sys = require('sys');
|
||||
|
||||
for(var key in jasmine) {
|
||||
global[key] = jasmine[key];
|
||||
}
|
||||
|
||||
var isVerbose = true;
|
||||
var showColors = true;
|
||||
|
||||
process.argv.forEach(function(arg){
|
||||
switch(arg) {
|
||||
case '--color': showColors = true; break;
|
||||
case '--noColor': showColors = false; break;
|
||||
case '--verbose': isVerbose = true; break;
|
||||
}
|
||||
});
|
||||
|
||||
var options = {"specFolder":__dirname.concat("\\spec"),
|
||||
"onComplete": function(runner, log){
|
||||
if (runner.results().failedCount == 0) {
|
||||
process.exit(0);
|
||||
}
|
||||
else {
|
||||
process.exit(1);
|
||||
}
|
||||
},
|
||||
"isVerbose": isVerbose,
|
||||
"showColors": showColors};
|
||||
|
||||
jasmine.executeSpecsInFolder(options);
|
||||
|
||||
85
build/node_modules/node-rest-client/test/test-proxy.js
generated
vendored
Normal file
85
build/node_modules/node-rest-client/test/test-proxy.js
generated
vendored
Normal file
@@ -0,0 +1,85 @@
|
||||
var http = require('http');
|
||||
var sys = require('sys');
|
||||
var fs = require('fs');
|
||||
|
||||
var blacklist = [];
|
||||
var iplist = [];
|
||||
|
||||
fs.watchFile('./blacklist', function(c,p) { update_blacklist(); });
|
||||
fs.watchFile('./iplist', function(c,p) { update_iplist(); });
|
||||
|
||||
function update_blacklist() {
|
||||
sys.log("Updating blacklist.");
|
||||
blacklist = fs.readFileSync('./blacklist').split('\n')
|
||||
.filter(function(rx) { return rx.length })
|
||||
.map(function(rx) { return RegExp(rx) });
|
||||
}
|
||||
|
||||
function update_iplist() {
|
||||
sys.log("Updating iplist.");
|
||||
iplist = fs.readFileSync('./iplist').split('\n')
|
||||
.filter(function(rx) { return rx.length });
|
||||
}
|
||||
|
||||
function ip_allowed(ip) {
|
||||
for (i in iplist) {
|
||||
if (iplist[i] == ip) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function host_allowed(host) {
|
||||
for (i in blacklist) {
|
||||
if (blacklist[i].test(host)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function deny(response, msg) {
|
||||
response.writeHead(401);
|
||||
response.write(msg);
|
||||
response.end();
|
||||
}
|
||||
|
||||
http.createServer(function(request, response) {
|
||||
var ip = request.connection.remoteAddress;
|
||||
if (!ip_allowed(ip)) {
|
||||
msg = "IP " + ip + " is not allowed to use this proxy";
|
||||
deny(response, msg);
|
||||
sys.log(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!host_allowed(request.url)) {
|
||||
msg = "Host " + request.url + " has been denied by proxy configuration";
|
||||
deny(response, msg);
|
||||
sys.log(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
sys.log(ip + ": " + request.method + " " + request.url);
|
||||
var proxy = http.createClient(80, request.headers['host']);
|
||||
var proxy_request = proxy.request(request.method, request.url, request.headers);
|
||||
proxy_request.addListener('response', function(proxy_response) {
|
||||
proxy_response.addListener('data', function(chunk) {
|
||||
response.write(chunk, 'binary');
|
||||
});
|
||||
proxy_response.addListener('end', function() {
|
||||
response.end();
|
||||
});
|
||||
response.writeHead(proxy_response.statusCode, proxy_response.headers);
|
||||
});
|
||||
request.addListener('data', function(chunk) {
|
||||
proxy_request.write(chunk, 'binary');
|
||||
});
|
||||
request.addListener('end', function() {
|
||||
proxy_request.end();
|
||||
});
|
||||
}).listen(8080);
|
||||
|
||||
update_blacklist();
|
||||
update_iplist();
|
||||
81
build/node_modules/node-rest-client/test/test-servers.js
generated
vendored
Normal file
81
build/node_modules/node-rest-client/test/test-servers.js
generated
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
var http = require('http'),
|
||||
fs = require('fs');
|
||||
|
||||
// Create an HTTP server
|
||||
var httpSrv = http.createServer(function (req, res) {
|
||||
console.log("req.url", req.url);
|
||||
RouteManager.findRoute(req,res);
|
||||
});
|
||||
|
||||
var RouteManager ={
|
||||
"findRoute":function(req,res){
|
||||
var handler = this.routes[req.url];
|
||||
if (!handler) throw "cannot find route " + req.url;
|
||||
handler.call(this,req,res);
|
||||
},
|
||||
"routes":{
|
||||
"/json":function(req,res){
|
||||
//this.sleep(5000);
|
||||
var message = fs.readFileSync('./message.json','utf8');
|
||||
res.writeHead(200, {'Content-Type': 'application/json'});
|
||||
res.write(message.toString());
|
||||
res.end();
|
||||
},
|
||||
"/xml":function(req,res){
|
||||
var message = fs.readFileSync('./message.xml','utf8');
|
||||
res.writeHead(200, {'Content-Type': 'application/xml'});
|
||||
res.write(message.toString());
|
||||
res.end();
|
||||
},
|
||||
"/120/json?arg1=hello&arg2=world":function(req,res){
|
||||
if (!req.headers["test-header"]) throw "no test-header found!!";
|
||||
res.setHeader("test-response-header",req.headers["test-header"]);
|
||||
this.routes["/json"](req,res);
|
||||
},
|
||||
"/json?post":function(req,res){
|
||||
req.on('data',function(data){
|
||||
console.log("[SERVER] data = ", data);
|
||||
res.writeHead(200, {'Content-Type': 'application/json'});
|
||||
//res.writeHead(200, {'Content-Type': 'text/plain'});
|
||||
res.write(data.toString());
|
||||
res.end();
|
||||
});
|
||||
|
||||
},
|
||||
"/json/empty":function(req,res){
|
||||
res.writeHead(204, {'Content-Type': 'application/json'});
|
||||
res.end();
|
||||
},
|
||||
"/xml/empty":function(req,res){
|
||||
res.writeHead(204, {'Content-Type': 'application/xml'});
|
||||
res.end();
|
||||
},
|
||||
"/json/contenttypewithspace":function(req,res){
|
||||
var message = fs.readFileSync('./message.json','utf8');
|
||||
res.writeHead(200, {'Content-Type': 'application/json; charset=utf-8'});
|
||||
res.write(message.toString());
|
||||
res.end();
|
||||
}
|
||||
},
|
||||
"sleep":function(ms){
|
||||
|
||||
var stop = new Date().getTime();
|
||||
while(new Date().getTime() < stop + ms) {
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
httpSrv.on('error',function(err){
|
||||
console.error('error starting http test server',err);
|
||||
});
|
||||
|
||||
httpSrv.listen(4444);
|
||||
|
||||
console.log('http server Listening on port ' + 4444);
|
||||
Reference in New Issue
Block a user